Performance drop after drawing a lot of rectangles?

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
User avatar
slmjkdbtl
Prole
Posts: 14
Joined: Sat Feb 25, 2017 8:36 am
Location: New York
Contact:

Performance drop after drawing a lot of rectangles?

Post by slmjkdbtl »

I add rectangles (tried circles too) to arrays and draw them on screen (for bleeding effect) but FPS drops to half after certain amount of rectangles are added and drawn. Why is this happening? Is there any alternative way of doing similar thing?

My code is like

Code: Select all


Timer.every(0.1, function()
    self.pixels[#self.pixels + 1] = Pixel(x, y, w, h) -- Pixel returns a table that has position, size and a draw function
end
	
嗡嗡嗡
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: Performance drop after drawing a lot of rectangles?

Post by Tjakka5 »

Every rectangle is one draw call, and each draw call takes (relatively) long to process.
When you have lots of them, your framerate will suffer.

There's 2 ways to go about solving this:
1. Use a spritebatch. It's a buffer which takes a texture. Then you tell it where you want to "put" all the images, and then you render it with only one draw call.
2. Use a particlesystem. This seems to be more fit for your situation. It works similairly to the spritebatch. But instead of telling where you want to put the images, you instead define a "emitter" which spawns them, and define some rules for the transformation.

https://love2d.org/wiki/SpriteBatch
https://love2d.org/wiki/ParticleSystem
User avatar
slmjkdbtl
Prole
Posts: 14
Joined: Sat Feb 25, 2017 8:36 am
Location: New York
Contact:

Re: Performance drop after drawing a lot of rectangles?

Post by slmjkdbtl »

Tjakka5 wrote: Tue Oct 24, 2017 9:31 pm Every rectangle is one draw call, and each draw call takes (relatively) long to process.
When you have lots of them, your framerate will suffer.

There's 2 ways to go about solving this:
1. Use a spritebatch. It's a buffer which takes a texture. Then you tell it where you want to "put" all the images, and then you render it with only one draw call.
2. Use a particlesystem. This seems to be more fit for your situation. It works similairly to the spritebatch. But instead of telling where you want to put the images, you instead define a "emitter" which spawns them, and define some rules for the transformation.

https://love2d.org/wiki/SpriteBatch
https://love2d.org/wiki/ParticleSystem
Thanks, the performance increased dramatically after using SpriteBatch.
嗡嗡嗡
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest