Implement automatic batching for points, lines, shapes, and images/quads.

The above are batched together into a single draw call when called without other drawing calls in between, as long as the following criteria are met:

- The texture is the same.
- The primitive type is the same (points cannot be batched with non-points).
- The love.graphics state is the same (aside from the current color - i.e. setColor - and the transform state).
- The active shader’s uniform values are the same.

You can examine the ‘drawcalls’ field of love.graphics.getStats() to help determine if your code is allowing for optimum batching.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-12-27 21:02:58 -04:00
parent f98b7ce1ed
commit 0d2e08baff
43 changed files with 1245 additions and 511 deletions
+3 -6
View File
@@ -738,7 +738,7 @@ function love.nogame()
local SIZE_Y = math.floor(wh / 32 + 2)
local SIZE = SIZE_X * SIZE_Y
self.batch = love.graphics.newSpriteBatch(mosaic_image, SIZE, "stream")
self.image = mosaic_image
self.pieces = {}
self.color_t = 1
self.generation = 1
@@ -915,8 +915,6 @@ function love.nogame()
end
function Mosaic:draw()
self.batch:clear()
love.graphics.setColor(1, 1, 1, 0.25)
for idx,piece in ipairs(self.pieces) do
local ct = 1 - self.color_t
local c0 = piece.color.prev
@@ -925,11 +923,10 @@ function love.nogame()
local g = easeOut(ct, c0[2], c1[2] - c0[2], 1)
local b = easeOut(ct, c0[3], c1[3] - c0[3], 1)
self.batch:setColor(r, g, b)
self.batch:add(piece.quad, piece.x, piece.y, piece.r, 1, 1, 16, 16)
love.graphics.setColor(r, g, b)
love.graphics.draw(self.image, piece.quad, piece.x, piece.y, piece.r, 1, 1, 16, 16)
end
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(self.batch, 0, 0)
end
function love.load()