diff --git a/src/modules/graphics/opengl/Font.cpp b/src/modules/graphics/opengl/Font.cpp index 0bee40958..46d212c55 100644 --- a/src/modules/graphics/opengl/Font.cpp +++ b/src/modules/graphics/opengl/Font.cpp @@ -472,16 +472,19 @@ std::vector Font::generateVerticesFormatted(const std::string if (!commands.empty()) { + auto firstcmd = commands.begin(); + // If the first draw command in the new list has the same texture // as the last one in the existing list we're building and its // vertices are in-order, we can combine them (saving a draw call.) - auto firstcmd = commands.begin(); - auto prevcmd = drawcommands.back(); - if (!drawcommands.empty() && prevcmd.texture == firstcmd->texture - && (prevcmd.startvertex + prevcmd.vertexcount) == firstcmd->startvertex) + if (!drawcommands.empty()) { - drawcommands.back().vertexcount += firstcmd->vertexcount; - ++firstcmd; + auto prevcmd = drawcommands.back(); + if (prevcmd.texture == firstcmd->texture && (prevcmd.startvertex + prevcmd.vertexcount) == firstcmd->startvertex) + { + drawcommands.back().vertexcount += firstcmd->vertexcount; + ++firstcmd; + } } // Append the new draw commands to the list we're building. diff --git a/src/modules/graphics/opengl/Text.cpp b/src/modules/graphics/opengl/Text.cpp index 4085b6e3f..47606ef55 100644 --- a/src/modules/graphics/opengl/Text.cpp +++ b/src/modules/graphics/opengl/Text.cpp @@ -138,16 +138,19 @@ void Text::addTextData(const TextData &t) for (Font::DrawCommand &cmd : new_commands) cmd.startvertex += (int) voffset; + auto firstcmd = new_commands.begin(); + // If the first draw command in the new list has the same texture as the // last one in the existing list we're building and its vertices are // in-order, we can combine them (saving a draw call.) - auto firstcmd = new_commands.begin(); - auto prevcmd = draw_commands.back(); - if (!draw_commands.empty() && prevcmd.texture == firstcmd->texture - && (prevcmd.startvertex + prevcmd.vertexcount) == firstcmd->startvertex) + if (!draw_commands.empty()) { - draw_commands.back().vertexcount += firstcmd->vertexcount; - ++firstcmd; + auto prevcmd = draw_commands.back(); + if (prevcmd.texture == firstcmd->texture && (prevcmd.startvertex + prevcmd.vertexcount) == firstcmd->startvertex) + { + draw_commands.back().vertexcount += firstcmd->vertexcount; + ++firstcmd; + } } // Append the new draw commands to the list we're building.