Page 2 of 3
Re: Drawing a large number of individual pixels per frame
Posted: Thu Aug 11, 2011 10:55 pm
by kraftman
kefka wrote:kikito wrote:Are you generating the framebuffer on every frame, by any chance?
I am, because I'm looking for a solution where I can dynamically display the map. However I suppose what I can do is only call newPoint on the framebuffer when a tile's data changes.
Thanks for all the suggestions, I will profile this method against the ImageData method and post my results.
What changes about the map?
Re: Drawing a large number of individual pixels per frame
Posted: Fri Aug 12, 2011 5:33 pm
by kefka
kraftman wrote:kefka wrote:kikito wrote:Are you generating the framebuffer on every frame, by any chance?
I am, because I'm looking for a solution where I can dynamically display the map. However I suppose what I can do is only call newPoint on the framebuffer when a tile's data changes.
Thanks for all the suggestions, I will profile this method against the ImageData method and post my results.
What changes about the map?
Good question. The map is randomly generated by a cave-digging algorithm. I'd like to provide an interface to modify parameters of the algorithm and display the generation realtime.
Re: Drawing a large number of individual pixels per frame
Posted: Fri Aug 12, 2011 7:58 pm
by kraftman
In that case I would recommend frame buffers. Using image data, you would need to create a new image to display each time new terrain is generated, while using frame buffers you can add extra info to the same frame buffer. I haven't used spritebatches yet, but I think you could do something similar with them.
Re: Drawing a large number of individual pixels per frame
Posted: Fri Aug 12, 2011 11:02 pm
by Taehl
If he used the ImageData method, he could use
ImageData:setPixel to add the changes to the map. He wouldn't have to re-generate the whole map every frame.
I wouldn't recommend spritebatches for this, as you WOULD need to re-generate it all the time (you can only add more and more to a spritebatch, not change or remove graphics from it).
Re: Drawing a large number of individual pixels per frame
Posted: Sat Aug 13, 2011 12:20 am
by slime
Taehl wrote:If he used the ImageData method, he could use
ImageData:setPixel to add the changes to the map. He wouldn't have to re-generate the whole map every frame.
I wouldn't recommend spritebatches for this, as you WOULD need to re-generate it all the time (you can only add more and more to a spritebatch, not change or remove graphics from it).
You do have to call love.graphics.newImage(imagedata) every time you change it, which creates a whole new image from the imagedata. This will create huge amounts of RAM if you aren't careful, AFAIK.
Regenerating spritebatches is generally pretty efficient, comparatively. Doing a streaming spritebatch (re-creating every frame) can be faster than drawing each image individually, and an infrequently-updated (less than once per frame) spritebatch is pretty much always faster than drawing individual images.
Re: Drawing a large number of individual pixels per frame
Posted: Sat Aug 13, 2011 8:37 am
by T-Bone
slime wrote:Taehl wrote:If he used the ImageData method, he could use
ImageData:setPixel to add the changes to the map. He wouldn't have to re-generate the whole map every frame.
I wouldn't recommend spritebatches for this, as you WOULD need to re-generate it all the time (you can only add more and more to a spritebatch, not change or remove graphics from it).
You do have to call love.graphics.newImage(imagedata) every time you change it,
which creates a whole new image from the imagedata. This will create huge amounts of RAM if you aren't careful, AFAIK.
Regenerating spritebatches is generally pretty efficient, comparatively. Doing a streaming spritebatch (re-creating every frame) can be faster than drawing each image individually, and an infrequently-updated (less than once per frame) spritebatch is pretty much always faster than drawing individual images.
Well, it shouldn't be using all that much RAM unless you're storing all the images. It will make the garbage collector go nuts, though, which is never a good thing. I'm not sure how good the GC is in Lua (if it were Android, it would've made the app unusable (although I think they improved the GC in Android 2.3))
Re: Drawing a large number of individual pixels per frame
Posted: Sat Aug 13, 2011 11:43 am
by Taehl
slime wrote:This will create huge amounts of RAM if you aren't careful, AFAIK.
I did a test, setting a pixel / newImage-ing / drawing a 256x256 image at about a thousand times per second, and didn't see Love's RAM usage go over 26 megs.
Re: Drawing a large number of individual pixels per frame
Posted: Sat Aug 13, 2011 2:28 pm
by kraftman
It's still less efficient to create a new image each time than to just add the extra data to the same framebuffer
Re: Drawing a large number of individual pixels per frame
Posted: Sat Aug 13, 2011 7:01 pm
by benloran
kraftman wrote:It's still less efficient to create a new image each time than to just add the extra data to the same framebuffer
Unless I'm misunderstanding you, I don't think you can do this in Love 0.7.2, since framebuffers are cleared automatically each time you draw to them. (Though I believe this is fixed in 0.8.0).
Re: Drawing a large number of individual pixels per frame
Posted: Mon Aug 15, 2011 5:44 am
by adrix89
What about the Sonic solution?
Tile with hightmap info?