Upload changes to an AnimTexture
Blitz3D Forums/Blitz3D Programming/Upload changes to an AnimTexture
| ||
I'm looking for the fastest way to upload changes to an AnimTexture which resides in GDDR memory. Since you can't peek and poke GDDR, what do you suggest? I've tought of keeping a copy of the Animtexture but in RAM, and maybe poking there, and then upload the changes. Other solutions welcome! We're still talking about rather big textures to upload, 1024x1024 in 32bits every frame is rather heavy on a system IMHO (240 megs data transfer each second, heh). |
| ||
Toms DX7Test.dll and render to texture usage Alternatively make sure that the texture is loaded with flag 256 and use the draw commands. Of what kind of changes are we talking here? stuff that needs writepixelfast or something that could be done by copyrect as well? If you store the "anim data" in RAM you will most likely hit the indie RAM - VRAM borders, so I would consider as well a usage of 512x512 where 1024x1024 isn't needed (for example at 1024x768 resolution and lower) 240megs each second or each frame? (each second would mean a single 1024x1024 @ 32bit updated 60 times) |
| ||
Yea, 240megs each second for a 1024x1024 pixel anim texture, which represent in actual fact a 256 character font of 64x64 pixels each character. Actually this would the the worst case scenario, where the font is updated each frame on a 60 fps basis. But, I could be dealing with 15 FPS updates on one 1024x1024 anim texture and it could probably be well enough. The methods I used in order to create fonts from crude data are too slow right now, just from a creation standpoint, so realtime updating to me is impossible, specially, not even at 10 fps or 15 fps, so you can imagine 60fps. That is why I plea for some help here. I'll post my font creation routine here (which also has the rem'd out code that I wished worked properly): http://www.blitzbasic.com/Community/posts.php?topic=30480 (reference) Function term_build_font(font_id%) If term\font[font_id]\name$ <> "" Or term\font[font_id]\texture <> 0 Or term\font[font_id]\image <> 0 Then Return TRMRC_already_initialized EndIf Select font_id% Case 0 : Restore font_atascii Case 1 : Restore font_ascii Case 2 : Return TRMRC_invalid_font_id Case 3 : Return TRMRC_invalid_font_id Case 4 : Restore font_gridscii Case 5 : Restore font_petscii Case 6 : Restore font_slimscii Case 7 : Return TRMRC_invalid_font_id Default : Return TRMRC_invalid_font_id End Select Read term\font[font_id]\name$ term\font[font_id]\bitwidth = 8 Read term\font[font_id]\bitheight term\font[font_id]\width = TRM_font_char_default_width term\font[font_id]\height = TRM_font_char_default_height term\font[font_id]\texture = CreateTexture (term\font[font_id]\width, term\font[font_id]\height, 2+256, 256) term\font[font_id]\image = CreateImageEx_(term\font[font_id]\texture, term\font[font_id]\width, term\font[font_id]\height, 1+2+256) ; X And Y multiplication factor mx% = term\font[font_id]\width / term\font[font_id]\bitwidth my% = Ceil (term\font[font_id]\height / term\font[font_id]\bitheight) my_float# = term\font[font_id]\height / term\font[font_id]\bitheight stepsize% = (Float (term\font[font_id]\bitwidth * term\font[font_id]\bitheight) / 32) term\font[font_id]\bitdata = CreateBank (stepsize * 256 * 4) bank% = term\font[font_id]\bitdata For char% = 0 To 255 For ints% = 0 To (stepsize - 1) Read value% disp% = (char * stepsize + ints) * 4 PokeInt (bank, disp, value) Next Next font% = term\font[font_id]\bitdata font_width% = term\font[font_id]\bitwidth font_height% = term\font[font_id]\bitheight ; image_bank% = CreateBank(4) ; transit_bank% = CreateBank(8) ;new ; StoreBankInfo(image_bank, transit_bank) ;new ; For char% = 0 To 255 ; img% = term\font[font_id]\texture ; ActivateTextureBuffer(img) ; PointBankToTexturebuffer(image_bank, img) ; datachar_disp% = stepsize * char * 4 ; For y% = 0 To (font_height - 1) ; y_start% = Float y * my_float ; byte% = PeekByte(font, datachar_disp + y) ; For x% = 0 To (font_width - 1) ; x_start% = x * mx ; bit% = byte And (1 Shl x) ; If bit = False Then ; term_plot_pixel_block(x_start, y_start, mx, my, TRM_mask_false, image_bank, 64) ; Else ; term_plot_pixel_block(x_start, y_start, mx, my, TRM_mask_true, image_bank, 64) ; EndIf ; Next ; Next ; RestoreBankInfo(image_bank, transit_bank) ;new ; Next ; FreeBank image_bank ;new ; FreeBank transit_bank ;new For char% = 0 To 255 img% = term\font[font_id]\texture buffer% = TextureBuffer(img, char) LockBuffer buffer datachar_disp% = stepsize * char * 4 For y% = 0 To (font_height - 1) y_start% = Float y * my_float byte% = PeekByte(font, datachar_disp + y) For x% = 0 To (font_width - 1) x_start% = x * mx bit% = byte And (1 Shl x) If bit > False Then term_write_pixel_block(x_start, y_start, mx, my, TRM_mask_true, buffer) Else term_write_pixel_block(x_start, y_start, mx, my, TRM_mask_false, buffer) EndIf Next Next UnlockBuffer buffer Next Return TRMRC_successful End Function Function term_plot_pixel_block(px%, py%, sx%, sy%, value%, buffer%, width%) For x% = px To (px + sx - 1) For y% = py To (py + sy - 1) PlotInBuffer(buffer, x, y, value, width) Next Next End Function Function term_write_pixel_block(px%, py%, sx%, sy%, value%, buffer%) For x% = px To (px + sx - 1) For y% = py To (py + sy - 1) WritePixelFast x, y, value, buffer Next Next End Function |