mirror of
https://github.com/love2d/love.git
synced 2026-08-18 03:34:23 +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:
@@ -27,6 +27,7 @@
|
||||
// LOVE
|
||||
#include "GLBuffer.h"
|
||||
#include "graphics/Texture.h"
|
||||
#include "graphics/Graphics.h"
|
||||
|
||||
// C++
|
||||
#include <algorithm>
|
||||
@@ -240,21 +241,22 @@ bool SpriteBatch::getDrawRange(int &start, int &count) const
|
||||
return true;
|
||||
}
|
||||
|
||||
void SpriteBatch::draw(const Matrix4 &m)
|
||||
void SpriteBatch::draw(Graphics *gfx, const Matrix4 &m)
|
||||
{
|
||||
const size_t pos_offset = offsetof(Vertex, x);
|
||||
const size_t texel_offset = offsetof(Vertex, s);
|
||||
const size_t color_offset = offsetof(Vertex, r);
|
||||
const size_t color_offset = offsetof(Vertex, color.r);
|
||||
|
||||
if (next == 0)
|
||||
return;
|
||||
|
||||
gfx->flushStreamDraws();
|
||||
|
||||
OpenGL::TempDebugGroup debuggroup("SpriteBatch draw");
|
||||
|
||||
OpenGL::TempTransform transform(gl);
|
||||
transform.get() *= m;
|
||||
Graphics::TempTransform transform(gfx, m);
|
||||
|
||||
gl.bindTextureToUnit(*(GLuint *) texture->getHandle(), 0, false);
|
||||
gl.bindTextureToUnit(texture, 0, false);
|
||||
|
||||
uint32 enabledattribs = ATTRIBFLAG_POS | ATTRIBFLAG_TEXCOORD;
|
||||
|
||||
@@ -315,8 +317,11 @@ void SpriteBatch::addv(const Vertex *v, const Matrix4 &m, int index)
|
||||
|
||||
m.transform(sprite, sprite, 4);
|
||||
|
||||
if (color)
|
||||
setColorv(sprite, *color);
|
||||
if (color != nullptr)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
sprite[i].color = *color;
|
||||
}
|
||||
|
||||
// Always keep the VBO mapped when adding data for now (it'll be unmapped
|
||||
// on draw.)
|
||||
@@ -325,17 +330,6 @@ void SpriteBatch::addv(const Vertex *v, const Matrix4 &m, int index)
|
||||
array_buf->fill(index * sprite_size, sprite_size, sprite);
|
||||
}
|
||||
|
||||
void SpriteBatch::setColorv(Vertex *v, const Color &color)
|
||||
{
|
||||
for (size_t i = 0; i < 4; ++i)
|
||||
{
|
||||
v[i].r = color.r;
|
||||
v[i].g = color.g;
|
||||
v[i].b = color.b;
|
||||
v[i].a = color.a;
|
||||
}
|
||||
}
|
||||
|
||||
} // opengl
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
Reference in New Issue
Block a user