Page 1 of 1

Performance - custom draw

Posted: Mon Mar 13, 2017 1:50 am
by midnightjack
Hey,

I'm new to LÖVE, but out of all engines I've tried so far, i LOVE(couldn't resist, sorry) this one the most. I have an issue however, I'm starting development of a 2.5D game where Im doing whole projection math myself and therefore I have to draw all the polygons myself too.
Currently Im doing over a 1000 love.graphics.polygon calls (fill mode, convex) per DRAW cycle and so far it's all smooth. However I'll have to render more stuff eventually, and when I artificially inflate that number to 10k to test things out - FPS starts to fall.

So the question really - maybe there's a more optimal way to draw a lot of shapes than doing thousands of love.graphics.polygon calls per frame ?

Thank you all in advance !

Re: Performance - custom draw

Posted: Mon Mar 13, 2017 2:16 am
by s-ol
midnightjack wrote: Mon Mar 13, 2017 1:50 am Hey,

I'm new to LÖVE, but out of all engines I've tried so far, i LOVE(couldn't resist, sorry) this one the most. I have an issue however, I'm starting development of a 2.5D game where Im doing whole projection math myself and therefore I have to draw all the polygons myself too.
Currently Im doing over a 1000 love.graphics.polygon calls (fill mode, convex) per DRAW cycle and so far it's all smooth. However I'll have to render more stuff eventually, and when I artificially inflate that number to 10k to test things out - FPS starts to fall.

So the question really - maybe there's a more optimal way to draw a lot of shapes than doing thousands of love.graphics.polygon calls per frame ?

Thank you all in advance !
every love.graphics.polygon assembles a new shape in a buffer and sends it, each frame (I would presume). A Mesh should help:
https://love2d.org/wiki/love.graphics.newMesh
https://love2d.org/wiki/Mesh

you can set the usage hint if you plan to update it each frame and its still gonna be faster than polygon, but really you want to use transform and get away with using the mesh static.

On the other hand though, if you do the projection math yourself, why not draw regularily and handle that in a vertex shader? That's exactly what it's designed for and you get full hardware acceleration.

Re: Performance - custom draw

Posted: Mon Mar 13, 2017 2:27 am
by midnightjack
s-ol wrote: Mon Mar 13, 2017 2:16 am On the other hand though, if you do the projection math yourself, why not draw regularily and handle that in a vertex shader? That's exactly what it's designed for and you get full hardware acceleration.
Hey! Thanks so much for the response. To answer your question - that's because I never really programmed anything that would use hardware acceleration before, so I even didn't think of that. But that's probably what I'll go with, since I want maximum performance.

If you (or anyone reading this) have any links for beginners on using vertex shaders in LOVE - that'd be greatly appreciated! Thanks again!

Re: Performance - custom draw

Posted: Mon Mar 13, 2017 2:42 am
by s-ol
midnightjack wrote: Mon Mar 13, 2017 2:27 am
s-ol wrote: Mon Mar 13, 2017 2:16 am On the other hand though, if you do the projection math yourself, why not draw regularily and handle that in a vertex shader? That's exactly what it's designed for and you get full hardware acceleration.
Hey! Thanks so much for the response. To answer your question - that's because I never really programmed anything that would use hardware acceleration before, so I even didn't think of that. But that's probably what I'll go with, since I want maximum performance.

If you (or anyone reading this) have any links for beginners on using vertex shaders in LOVE - that'd be greatly appreciated! Thanks again!
so what you are writing is a vertex shader, for OpenGL, written in GLSL, googling this should give you a lot.

you can find the default vertex shader for love here and work off that:
https://love2d.org/wiki/love.graphics.newShader

Code: Select all

vec4 position(mat4 transform_projection, vec4 vertex_position)
{
    // The order of operations matters when doing matrix multiplication.
    return transform_projection * vertex_position;
}
you can add parameters with 'extern Number ' etc, calculate the final vertex position and return it.