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:
@@ -23,6 +23,7 @@
|
||||
#include "common/Matrix.h"
|
||||
#include "common/Exception.h"
|
||||
#include "Shader.h"
|
||||
#include "graphics/Graphics.h"
|
||||
|
||||
// C++
|
||||
#include <algorithm>
|
||||
@@ -44,7 +45,7 @@ static const char *getBuiltinAttribName(VertexAttribID attribid)
|
||||
|
||||
static_assert(offsetof(Vertex, x) == sizeof(float) * 0, "Incorrect position offset in Vertex struct");
|
||||
static_assert(offsetof(Vertex, s) == sizeof(float) * 2, "Incorrect texture coordinate offset in Vertex struct");
|
||||
static_assert(offsetof(Vertex, r) == sizeof(float) * 4, "Incorrect color offset in Vertex struct");
|
||||
static_assert(offsetof(Vertex, color.r) == sizeof(float) * 4, "Incorrect color offset in Vertex struct");
|
||||
|
||||
static std::vector<Mesh::AttribFormat> getDefaultVertexFormat()
|
||||
{
|
||||
@@ -574,11 +575,13 @@ int Mesh::bindAttributeToShaderInput(int attributeindex, const std::string &inpu
|
||||
return attriblocation;
|
||||
}
|
||||
|
||||
void Mesh::draw(const Matrix4 &m)
|
||||
void Mesh::draw(Graphics *gfx, const Matrix4 &m)
|
||||
{
|
||||
if (vertexCount <= 0)
|
||||
return;
|
||||
|
||||
gfx->flushStreamDraws();
|
||||
|
||||
OpenGL::TempDebugGroup debuggroup("Mesh draw");
|
||||
|
||||
uint32 enabledattribs = 0;
|
||||
@@ -601,13 +604,9 @@ void Mesh::draw(const Matrix4 &m)
|
||||
|
||||
gl.useVertexAttribArrays(enabledattribs);
|
||||
|
||||
if (texture.get())
|
||||
gl.bindTextureToUnit(*(GLuint *) texture->getHandle(), 0, false);
|
||||
else
|
||||
gl.bindTextureToUnit(gl.getDefaultTexture(), 0, false);
|
||||
gl.bindTextureToUnit(texture, 0, false);
|
||||
|
||||
OpenGL::TempTransform transform(gl);
|
||||
transform.get() *= m;
|
||||
Graphics::TempTransform transform(gfx, m);
|
||||
|
||||
gl.prepareDraw();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user