Max FPS when writing to a Texture?
Blitz3D Forums/Blitz3D Programming/Max FPS when writing to a Texture?
| ||
| Has anyone written anything that does some serious dynamic texture updates on the fly? I've seen the code examples that write to an image buffer and then copy the buffer to the texture, but the FPS is terrible. Is it feasable to write a game in Blitz that would write say 100 pixels per frame to a texture? The key point is that the textures are originally loaded in, but then modified on the fly - not animated. Just as a test this code draws a line across a texture, but takes 4 seconds on my PC:
Graphics3D 800, 600
SetBuffer BackBuffer()
Global texture = CreateTexture(256,256,4+256)
Global xPos = 0
; Setup the camera, light and create a cube
camera = CreateCamera()
light = CreateLight()
cube = CreateCube()
; Position the camera and cube. Point the camera at the cube
PositionEntity(camera, 10, 10, 5)
PositionEntity(cube, 10, 10, 10)
PointEntity(camera, cube)
; Texture the cube
EntityTexture(cube, texture)
While Not KeyDown( 1 )
If xPos < 255 Then xPos = xPos + 1
; Green with alpha
rgb = $FF0000FF
; Draw a pixel on the texture
WritePixel(xPos, 40, rgb, TextureBuffer(texture))
RenderWorld
Flip
Wend
|
| ||
| Obviously it's quicker with "Flip False", but it's still takes a second or two. Is this just a no go area in Blitz? |
| ||
| Try using LockBuffer, WritePixelFast, UnlockBuffer |
| ||
| In your example, if the main while..wend is executed 50 times each second (by the way, you should use a timer to make it running at your choosen fps), it means that each second, 50 pixels are drawn. So, to draw a line of 255 pixels, it will take about 5 seconds. (5secs * 50pixels per frame = 250 pixels in 5 secs) I think, it is completely normal. If you want more speed, then you have different alternatives, for example: - use a timer with more than 50 frames per seconds, OR: - plot more pixels at each frame ! What are you trying to do here ? If you want 'super fast pixel drawing' on a texture, then you should draw all the pixels you need to be drawn in just one frame, instead of draw one pixel per frame. If you plot one pixel at each frame, you will end with a 'super slow pixel drawing' for sure, LOL !!! (no offence !) Also, the line: If xPos < 255 Then xPos = xPos + 1 does not take into account, when xPos reaches (and override) 255.. it should be reset or, at least, the y coordinate (fixed to 40 in your example) should change. Or am I missing something ? Sergio. |
| ||
| Erm... You don't need to RenderWorld/Flip every time a pixel is plotted, do you? That's really what's slowing it down, not the texture-drawing itself. The process itself is actually pretty fast: Graphics3D 800, 600
start = MilliSecs()
SetBuffer BackBuffer()
Global texture = CreateTexture(256,256,4+256)
Global xPos = 0
; Setup the camera, light and create a cube
camera = CreateCamera()
light = CreateLight()
cube = CreateCube()
; Position the camera and cube. Point the camera at the cube
PositionEntity(camera, 10, 10, 5)
PositionEntity(cube, 10, 10, 10)
PointEntity(camera, cube)
; Texture the cube
EntityTexture(cube, texture)
While cycles < 500
cycles = cycles + 1
DrawLine(Rnd(0,255))
RenderWorld
Flip False
Wend
Text 0,0,"128,000 pixels written in: " + (MilliSecs()-Start) + "ms"
Flip
WaitKey
End
Function DrawLine(y)
xpos = 0
While xpos < 255
xPos = xPos + 1
; Green with alpha
rgb = $FF0FF000
; Draw a pixel on the texture
LockBuffer TextureBuffer(texture)
WritePixelFast(xPos, y, rgb, TextureBuffer(texture))
UnlockBuffer TextureBuffer(texture)
Wend
End Function |
| ||
| Precisely. And could be even faster by changing this:
Function DrawLine(y)
xpos = 0
While xpos < 255
xPos = xPos + 1
; Green with alpha
rgb = $FF0FF000
; Draw a pixel on the texture
LockBuffer TextureBuffer(texture)
WritePixelFast(xPos, y, rgb, TextureBuffer(texture))
UnlockBuffer TextureBuffer(texture)
Wend
End Function
Into this:
Function DrawLine(y)
LockBuffer TextureBuffer(texture)
xpos = 0
; Green with alpha
rgb = $FF0FF000
While xpos < 255
xPos = xPos + 1
; Draw a pixel on the texture
WritePixelFast(xPos, y, rgb, TextureBuffer(texture))
Wend
UnlockBuffer TextureBuffer(texture)
End Function
And, guess what ? Even super-faster using a timer... Sergio. |
| ||
| I see your point(s). I guess I just expected 255 pixels to be drawn in less than a second with "flip false". Anyway thanks guys |