Page 1 of 1

Is drawing a quad faster than an image?

Posted: Fri Oct 02, 2015 7:21 pm
by rougan
Hi there!
I am trying to draw a large isometric tilemap as effeciently as possible. I previously tried using spritebatches but discovered this impractical as I had a camera function that would change the x,y position of each quad/tile every time wasd was pressed.

So, I was wondering whether drawing large numbers of tiles using l.g.draw(texture,quad) was more effecient/faster than just using l.g.draw(image)?

Alternatively, would only running the l.g.draw() function on images that are within the confines of the users screen increase the performance? For example, instead of

Code: Select all

for i=0,1000,1 do 
love.graphics.draw(image,x,y) end 
would

Code: Select all

for i=0,1000,1 do
if x and y are within the screen then 
love.graphics.draw(image,x,y) end end 
be any more effecient, or does the computer/gpu just ignore drawing images that aren't on the screen anyway?

Thanks so much for your time and any advice you may have! :)

Re: Is drawing a quad faster than an image?

Posted: Fri Oct 02, 2015 7:51 pm
by Nixola
I don't know if drawing a quad is faster than drawing an image; probably not but it could depend on the size of both. But that's the (maybe) right answer to the wrong question. Drawing each tile is EXTREMELY inefficient; can't you change the camera function so that it just changes some values (cameraX and cameraY or whatever) and draw the spritebatch in a different position based on that?

Re: Is drawing a quad faster than an image?

Posted: Fri Oct 02, 2015 8:37 pm
by slime
Even if you do end up needing to clear and re-add everything to a SpriteBatch every time it's drawn (which you might not need to, as Nixola says), it will still be more efficient than calling love.graphics.draw for each tile individually.

Re: Is drawing a quad faster than an image?

Posted: Sun Oct 04, 2015 3:20 am
by Karai17
STI supports Isometric maps. You could check out the code I have in there. I use sprite batches and draw range to speed up drawing significantly without any need to update the batches every frame.

Instead of changing where the tiles are being drawn, you should change where the viewport/camera is looking by using love.graphics.translate. This will make your life a whole lot easier.

Re: Is drawing a quad faster than an image?

Posted: Sun Oct 04, 2015 5:27 pm
by rougan
Nixola wrote:I don't know if drawing a quad is faster than drawing an image; probably not but it could depend on the size of both. But that's the (maybe) right answer to the wrong question. Drawing each tile is EXTREMELY inefficient; can't you change the camera function so that it just changes some values (cameraX and cameraY or whatever) and draw the spritebatch in a different position based on that?
I have read that spritebatches only give a significant performance increase on static images otherwise you need to set the x,y of each sprite in the batch every time the camera moves.. but I suppose this is what i'm doing with the images normally! I didn't want to spend time optimising with spritebatches if they weren't going to make much of a difference as I have 100+ images in a spritesheet to load as quads! :death: Thank you for the fast reply!!

Re: Is drawing a quad faster than an image?

Posted: Sun Oct 04, 2015 5:43 pm
by Nixola
You don't have to change every single tile in the spritebatch; just draw the spritebatch in a different position. Anyway, a spritebatch is still more efficient than a lot of draw calls, as slime said.