mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user