1

Is there an efficient way in Love2d to print a big (like, 800 x 600) table of color values on the screen? I've tried things like creating lots of rectangles (which is horribly slow) or creating an imageData and drawing that (which would be fine if the table-values didn't change at every frame, but they do). Thanks!

1 Answer 1

1

If you can compute the values without (much) extra data, you could try writing a shader and letting that compute stuff as things are being drawn.

If that doesn't work, using an ImageData can usually be made a lot faster than it is by default. First, you should ensure that you're not calling g = love.graphics.newImage( image_data ) per frame but create it once and then only call g:refresh( ).

The next thing is that :mapPixel is really slow because it's constantly calling from C into Lua (once per pixel) and that's quite a bit of overhead. It's faster to rewrite that in Lua or just use a plain loop with :setPixel (and maybe :getPixel).

If that's still too slow, the last problem is the following: LuaJIT cannot JIT-compile calls to C functions provided via the normal Lua API. But these can be replaced if you describe the data structure via the ffi and then let LuaJIT do the accesses directly. Slime has done this for love-0.9 (code on github). Just require that file and it will replace the slow functions, and everything should be a lot faster. I'm not 100% sure but I think I already used this with the current version (0.10) and it still works. (If the internal format of the ImageData ever changes, it will break, but it should be relatively easy to fix – and it's likely that someone else will update the code and post it somewhere.)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.