Always use a 16 bit index array for quad indices, with multiple draws when necessary. See issue #1356.

This commit is contained in:
Alex Szpakowski
2017-12-24 15:54:03 -04:00
parent 0b7cb4a353
commit 3fb621af95
8 changed files with 97 additions and 231 deletions
+2 -14
View File
@@ -34,7 +34,7 @@ Text::Text(Graphics *gfx, Font *font, const std::vector<Font::ColoredString> &te
: font(font)
, vertexAttributes(Font::vertexFormat, 0)
, vbo(nullptr)
, quadIndices(gfx, 20)
, quadIndices(gfx)
, vert_offset(0)
, texture_cache_id((uint32) -1)
{
@@ -259,24 +259,12 @@ void Text::draw(Graphics *gfx, const Matrix4 &m)
for (const Font::DrawCommand &cmd : draw_commands)
totalverts = std::max(cmd.startvertex + cmd.vertexcount, totalverts);
if ((size_t) totalverts / 4 > quadIndices.getSize())
quadIndices = QuadIndices(gfx, (size_t) totalverts / 4);
vbo->unmap(); // Make sure all pending data is flushed to the GPU.
Graphics::TempTransform transform(gfx, m);
Graphics::DrawIndexedCommand drawcmd(&vertexAttributes, &vertexBuffers, quadIndices.getBuffer());
drawcmd.indexType = quadIndices.getType();
size_t elemsize = quadIndices.getElementSize();
for (const Font::DrawCommand &cmd : draw_commands)
{
drawcmd.indexCount = (cmd.vertexcount / 4) * 6;
drawcmd.indexBufferOffset = (cmd.startvertex / 4) * 6 * elemsize;
drawcmd.texture = cmd.texture;
gfx->draw(drawcmd);
}
quadIndices.draw(gfx, cmd.startvertex / 4, cmd.vertexcount / 4, vertexAttributes, vertexBuffers, cmd.texture);
}
} // graphics