Performance - custom draw

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
midnightjack
Prole
Posts: 2
Joined: Mon Mar 13, 2017 1:36 am

Performance - custom draw

Post 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 !
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Performance - custom draw

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
midnightjack
Prole
Posts: 2
Joined: Mon Mar 13, 2017 1:36 am

Re: Performance - custom draw

Post 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!
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Performance - custom draw

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 9 guests