Is drawing a quad faster than an image?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
rougan
Citizen
Posts: 58
Joined: Wed Aug 12, 2015 10:30 am

Is drawing a quad faster than an image?

Post 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! :)
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Is drawing a quad faster than an image?

Post 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?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
slime
Solid Snayke
Posts: 3172
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Is drawing a quad faster than an image?

Post 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.
User avatar
Karai17
Party member
Posts: 930
Joined: Sun Sep 02, 2012 10:46 pm

Re: Is drawing a quad faster than an image?

Post 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.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé
User avatar
rougan
Citizen
Posts: 58
Joined: Wed Aug 12, 2015 10:30 am

Re: Is drawing a quad faster than an image?

Post 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!!
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Is drawing a quad faster than an image?

Post 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.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 4 guests