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:
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "Text.h"
|
||||
#include "common/Matrix.h"
|
||||
#include "graphics/Graphics.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@@ -207,11 +208,13 @@ void Text::clear()
|
||||
vert_offset = 0;
|
||||
}
|
||||
|
||||
void Text::draw(const Matrix4 &m)
|
||||
void Text::draw(Graphics *gfx, const Matrix4 &m)
|
||||
{
|
||||
if (vbo == nullptr || draw_commands.empty())
|
||||
return;
|
||||
|
||||
gfx->flushStreamDraws();
|
||||
|
||||
OpenGL::TempDebugGroup debuggroup("Text object draw");
|
||||
|
||||
// Re-generate the text if the Font's texture cache was invalidated.
|
||||
@@ -223,18 +226,15 @@ void Text::draw(const Matrix4 &m)
|
||||
const size_t color_offset = offsetof(Font::GlyphVertex, color.r);
|
||||
const size_t stride = sizeof(Font::GlyphVertex);
|
||||
|
||||
OpenGL::TempTransform transform(gl);
|
||||
transform.get() *= m;
|
||||
Graphics::TempTransform transform(gfx, m);
|
||||
|
||||
{
|
||||
vbo->bind();
|
||||
vbo->unmap(); // Make sure all pending data is flushed to the GPU.
|
||||
vbo->bind();
|
||||
vbo->unmap(); // Make sure all pending data is flushed to the GPU.
|
||||
|
||||
// Font::drawVertices expects AttribPointer calls to be done already.
|
||||
glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, stride, vbo->getPointer(pos_offset));
|
||||
glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_UNSIGNED_SHORT, GL_TRUE, stride, vbo->getPointer(tex_offset));
|
||||
glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, vbo->getPointer(color_offset));
|
||||
}
|
||||
// Font::drawVertices expects AttribPointer calls to be done already.
|
||||
glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, stride, vbo->getPointer(pos_offset));
|
||||
glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_UNSIGNED_SHORT, GL_TRUE, stride, vbo->getPointer(tex_offset));
|
||||
glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, vbo->getPointer(color_offset));
|
||||
|
||||
gl.useVertexAttribArrays(ATTRIBFLAG_POS | ATTRIBFLAG_TEXCOORD | ATTRIBFLAG_COLOR);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user