how fast is getpixel and setpixel?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: how fast is getpixel and setpixel?

Post by TechnoCat »

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.
Magitek
Prole
Posts: 48
Joined: Sun Dec 13, 2009 2:23 am

Re: how fast is getpixel and setpixel?

Post by Magitek »

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.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: how fast is getpixel and setpixel?

Post by bartbes »

Of course this is not OpenGLs fault, lua just has bad performance in loops.
Geti
Party member
Posts: 112
Joined: Tue Oct 20, 2009 6:38 am

Re: how fast is getpixel and setpixel?

Post by Geti »

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.
plymouth
Prole
Posts: 6
Joined: Tue Dec 29, 2009 10:43 am

Re: how fast is getpixel and setpixel?

Post by plymouth »

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/
Post Reply

Who is online

Users browsing this forum: No registered users and 105 guests