how fast is getpixel and setpixel?
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: how fast is getpixel and setpixel?
As long as you keep the imageData, you can keep modifying the imageData and creating and displaying a new image every frame. Or you can do the table of pixels and just modify those as separate points like previously stated.
Re: how fast is getpixel and setpixel?
I had to keep two sets of texture data in memory.
I use get/set pixel to randomly generate my maps. I recreate these 256x256 textures every few seconds and it does not seem to affect rendering speed greatly. Doing it every frame is intensive but serviceable (30 fps on a powerful machine with 9x256x256 textures being updated each frame).
However, modifying the textures with get/setpixel is very slow in batches. Around 20,000 pixels will take almost half a second.
I believe the limitation is more to do with openGL, and for operations like this, you would normally use render to texture or shaders; anything else is far too slow during runtime. Without these, OpenGL is worse than the super nintendo for pixel manipulation; its particularly disappointing in my project.
I think a worms game would work, but it would never outclass liero or gusanos without moving to C.
I use get/set pixel to randomly generate my maps. I recreate these 256x256 textures every few seconds and it does not seem to affect rendering speed greatly. Doing it every frame is intensive but serviceable (30 fps on a powerful machine with 9x256x256 textures being updated each frame).
However, modifying the textures with get/setpixel is very slow in batches. Around 20,000 pixels will take almost half a second.
I believe the limitation is more to do with openGL, and for operations like this, you would normally use render to texture or shaders; anything else is far too slow during runtime. Without these, OpenGL is worse than the super nintendo for pixel manipulation; its particularly disappointing in my project.
I think a worms game would work, but it would never outclass liero or gusanos without moving to C.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: how fast is getpixel and setpixel?
Of course this is not OpenGLs fault, lua just has bad performance in loops.
Re: how fast is getpixel and setpixel?
consider regenerating the textures separately, for instance dedicating each update to doing a separate texture, rather than doing them all at once and getting a .5s hang. depending on how optimised your loop is you're very likely doing a stupid amount of calculations for your 20kpx batch, which logically should hurt your framerate.
you could also, i suppose, write a program in C/language of choice to run as you run your love project and write pixel data with it to a file that love can access with IO functions, if it's Lua's handling of loops that's killing your framerate.
you could also, i suppose, write a program in C/language of choice to run as you run your love project and write pixel data with it to a file that love can access with IO functions, if it's Lua's handling of loops that's killing your framerate.
Re: how fast is getpixel and setpixel?
I've been looking at the Ruby equivalent of Love2d called Gosu. Gosu itself doesn't allow manipulation of images (same as love2d) but it _does_ have a neat plugin library called TexPlay that does provide some pretty nice functionality like get_pixel and the drawing of lines, rectangles, polygons, circles, bezier curves, flood fills, image compositing and so on. It is apparently quite fast too.
Could something like this be made for Love2d? it would be really useful and i think a lot of people would appreciate it, here's the texplay link http://banisterfiend.wordpress.com/2008 ... -and-gosu/
Could something like this be made for Love2d? it would be really useful and i think a lot of people would appreciate it, here's the texplay link http://banisterfiend.wordpress.com/2008 ... -and-gosu/
Who is online
Users browsing this forum: aikusuuta, Semrush [Bot] and 6 guests