mirror of
https://github.com/love2d/love.git
synced 2026-08-19 12:14:20 +02:00
Simplified some code by removing an unnecessary/useless optimization.
This commit is contained in:
@@ -398,7 +398,7 @@ float Font::getHeight() const
|
|||||||
return (float) height;
|
return (float) height;
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::DrawCommands Font::generateVertices(const ColoredCodepoints &codepoints, std::vector<GlyphVertex> &vertices, float extra_spacing, Vector offset, TextInfo *info)
|
std::vector<Font::DrawCommand> Font::generateVertices(const ColoredCodepoints &codepoints, std::vector<GlyphVertex> &vertices, float extra_spacing, Vector offset, TextInfo *info)
|
||||||
{
|
{
|
||||||
// Spacing counter and newline handling.
|
// Spacing counter and newline handling.
|
||||||
float dx = offset.x;
|
float dx = offset.x;
|
||||||
@@ -408,7 +408,7 @@ Font::DrawCommands Font::generateVertices(const ColoredCodepoints &codepoints, s
|
|||||||
int maxwidth = 0;
|
int maxwidth = 0;
|
||||||
|
|
||||||
// Keeps track of when we need to switch textures in our vertex array.
|
// Keeps track of when we need to switch textures in our vertex array.
|
||||||
DrawCommands drawcmds;
|
std::vector<DrawCommand> commands;
|
||||||
|
|
||||||
// Pre-allocate space for the maximum possible number of vertices.
|
// Pre-allocate space for the maximum possible number of vertices.
|
||||||
size_t vertstartsize = vertices.size();
|
size_t vertstartsize = vertices.size();
|
||||||
@@ -420,11 +420,6 @@ Font::DrawCommands Font::generateVertices(const ColoredCodepoints &codepoints, s
|
|||||||
int curcolori = -1;
|
int curcolori = -1;
|
||||||
int ncolors = (int) codepoints.colors.size();
|
int ncolors = (int) codepoints.colors.size();
|
||||||
|
|
||||||
if (ncolors == 0 || (ncolors == 1 && codepoints.colors[0].color == curcolor))
|
|
||||||
drawcmds.usecolors = false;
|
|
||||||
else
|
|
||||||
drawcmds.usecolors = true;
|
|
||||||
|
|
||||||
for (int i = 0; i < (int) codepoints.cps.size(); i++)
|
for (int i = 0; i < (int) codepoints.cps.size(); i++)
|
||||||
{
|
{
|
||||||
uint32 g = codepoints.cps[i];
|
uint32 g = codepoints.cps[i];
|
||||||
@@ -454,7 +449,7 @@ Font::DrawCommands Font::generateVertices(const ColoredCodepoints &codepoints, s
|
|||||||
maxwidth = 0;
|
maxwidth = 0;
|
||||||
dx = offset.x;
|
dx = offset.x;
|
||||||
dy = offset.y;
|
dy = offset.y;
|
||||||
drawcmds.commands.clear();
|
commands.clear();
|
||||||
vertices.resize(vertstartsize);
|
vertices.resize(vertstartsize);
|
||||||
prevglyph = 0;
|
prevglyph = 0;
|
||||||
curcolori = -1;
|
curcolori = -1;
|
||||||
@@ -477,17 +472,17 @@ Font::DrawCommands Font::generateVertices(const ColoredCodepoints &codepoints, s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if glyph texture has changed since the last iteration.
|
// Check if glyph texture has changed since the last iteration.
|
||||||
if (drawcmds.commands.empty() || drawcmds.commands.back().texture != glyph.texture)
|
if (commands.empty() || commands.back().texture != glyph.texture)
|
||||||
{
|
{
|
||||||
// Add a new draw command if the texture has changed.
|
// Add a new draw command if the texture has changed.
|
||||||
DrawCommand cmd;
|
DrawCommand cmd;
|
||||||
cmd.startvertex = (int) vertices.size() - 4;
|
cmd.startvertex = (int) vertices.size() - 4;
|
||||||
cmd.vertexcount = 0;
|
cmd.vertexcount = 0;
|
||||||
cmd.texture = glyph.texture;
|
cmd.texture = glyph.texture;
|
||||||
drawcmds.commands.push_back(cmd);
|
commands.push_back(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
drawcmds.commands.back().vertexcount += 4;
|
commands.back().vertexcount += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Advance the x position for the next glyph.
|
// Advance the x position for the next glyph.
|
||||||
@@ -510,7 +505,7 @@ Font::DrawCommands Font::generateVertices(const ColoredCodepoints &codepoints, s
|
|||||||
return a.startvertex < b.startvertex;
|
return a.startvertex < b.startvertex;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::sort(drawcmds.commands.begin(), drawcmds.commands.end(), drawsort);
|
std::sort(commands.begin(), commands.end(), drawsort);
|
||||||
|
|
||||||
if (dx > maxwidth)
|
if (dx > maxwidth)
|
||||||
maxwidth = (int) dx;
|
maxwidth = (int) dx;
|
||||||
@@ -521,24 +516,24 @@ Font::DrawCommands Font::generateVertices(const ColoredCodepoints &codepoints, s
|
|||||||
info->height = (int) dy + (dx > 0.0f ? floorf(getHeight() * getLineHeight() + 0.5f) : 0) - offset.y;
|
info->height = (int) dy + (dx > 0.0f ? floorf(getHeight() * getLineHeight() + 0.5f) : 0) - offset.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
return drawcmds;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::DrawCommands Font::generateVertices(const std::string &text, std::vector<GlyphVertex> &vertices, float extra_spacing, Vector offset, TextInfo *info)
|
std::vector<Font::DrawCommand> Font::generateVertices(const std::string &text, std::vector<GlyphVertex> &vertices, float extra_spacing, Vector offset, TextInfo *info)
|
||||||
{
|
{
|
||||||
ColoredCodepoints codepoints;
|
ColoredCodepoints codepoints;
|
||||||
getCodepointsFromString(text, codepoints.cps);
|
getCodepointsFromString(text, codepoints.cps);
|
||||||
return generateVertices(codepoints, vertices, extra_spacing, offset, info);
|
return generateVertices(codepoints, vertices, extra_spacing, offset, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
Font::DrawCommands Font::generateVerticesFormatted(const ColoredCodepoints &text, float wrap, AlignMode align, std::vector<GlyphVertex> &vertices, TextInfo *info)
|
std::vector<Font::DrawCommand> Font::generateVerticesFormatted(const ColoredCodepoints &text, float wrap, AlignMode align, std::vector<GlyphVertex> &vertices, TextInfo *info)
|
||||||
{
|
{
|
||||||
|
|
||||||
wrap = std::max(wrap, 0.0f);
|
wrap = std::max(wrap, 0.0f);
|
||||||
|
|
||||||
uint32 cacheid = textureCacheID;
|
uint32 cacheid = textureCacheID;
|
||||||
|
|
||||||
DrawCommands drawcmds;
|
std::vector<DrawCommand> drawcommands;
|
||||||
vertices.reserve(text.cps.size() * 4);
|
vertices.reserve(text.cps.size() * 4);
|
||||||
|
|
||||||
std::vector<int> widths;
|
std::vector<int> widths;
|
||||||
@@ -581,29 +576,27 @@ Font::DrawCommands Font::generateVerticesFormatted(const ColoredCodepoints &text
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawCommands cmds = generateVertices(line, vertices, extraspacing, offset);
|
std::vector<DrawCommand> newcommands = generateVertices(line, vertices, extraspacing, offset);
|
||||||
|
|
||||||
if (!cmds.commands.empty())
|
if (!newcommands.empty())
|
||||||
{
|
{
|
||||||
auto firstcmd = cmds.commands.begin();
|
auto firstcmd = newcommands.begin();
|
||||||
|
|
||||||
// If the first draw command in the new list has the same texture
|
// 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
|
// 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.)
|
// vertices are in-order, we can combine them (saving a draw call.)
|
||||||
if (!drawcmds.commands.empty())
|
if (!drawcommands.empty())
|
||||||
{
|
{
|
||||||
auto prevcmd = drawcmds.commands.back();
|
auto prevcmd = drawcommands.back();
|
||||||
if (prevcmd.texture == firstcmd->texture && (prevcmd.startvertex + prevcmd.vertexcount) == firstcmd->startvertex)
|
if (prevcmd.texture == firstcmd->texture && (prevcmd.startvertex + prevcmd.vertexcount) == firstcmd->startvertex)
|
||||||
{
|
{
|
||||||
drawcmds.commands.back().vertexcount += firstcmd->vertexcount;
|
drawcommands.back().vertexcount += firstcmd->vertexcount;
|
||||||
++firstcmd;
|
++firstcmd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append the new draw commands to the list we're building.
|
// Append the new draw commands to the list we're building.
|
||||||
drawcmds.commands.insert(drawcmds.commands.end(), firstcmd, cmds.commands.end());
|
drawcommands.insert(drawcommands.end(), firstcmd, newcommands.end());
|
||||||
|
|
||||||
drawcmds.usecolors = drawcmds.usecolors || cmds.usecolors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
y += getHeight() * getLineHeight();
|
y += getHeight() * getLineHeight();
|
||||||
@@ -618,19 +611,19 @@ Font::DrawCommands Font::generateVerticesFormatted(const ColoredCodepoints &text
|
|||||||
if (cacheid != textureCacheID)
|
if (cacheid != textureCacheID)
|
||||||
{
|
{
|
||||||
vertices.clear();
|
vertices.clear();
|
||||||
drawcmds = generateVerticesFormatted(text, wrap, align, vertices);
|
drawcommands = generateVerticesFormatted(text, wrap, align, vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
return drawcmds;
|
return drawcommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Font::drawVertices(const DrawCommands &drawcommands)
|
void Font::drawVertices(const std::vector<DrawCommand> &drawcommands)
|
||||||
{
|
{
|
||||||
// Vertex attribute pointers need to be set before calling this function.
|
// Vertex attribute pointers need to be set before calling this function.
|
||||||
// This assumes that the attribute pointers are constant for all vertices.
|
// This assumes that the attribute pointers are constant for all vertices.
|
||||||
|
|
||||||
int totalverts = 0;
|
int totalverts = 0;
|
||||||
for (const DrawCommand &cmd : drawcommands.commands)
|
for (const DrawCommand &cmd : drawcommands)
|
||||||
totalverts = std::max(cmd.startvertex + cmd.vertexcount, totalverts);
|
totalverts = std::max(cmd.startvertex + cmd.vertexcount, totalverts);
|
||||||
|
|
||||||
if ((size_t) totalverts / 4 > quadIndices.getSize())
|
if ((size_t) totalverts / 4 > quadIndices.getSize())
|
||||||
@@ -645,7 +638,7 @@ void Font::drawVertices(const DrawCommands &drawcommands)
|
|||||||
|
|
||||||
// We need a separate draw call for every section of the text which uses a
|
// We need a separate draw call for every section of the text which uses a
|
||||||
// different texture than the previous section.
|
// different texture than the previous section.
|
||||||
for (const DrawCommand &cmd : drawcommands.commands)
|
for (const DrawCommand &cmd : drawcommands)
|
||||||
{
|
{
|
||||||
GLsizei count = (cmd.vertexcount / 4) * 6;
|
GLsizei count = (cmd.vertexcount / 4) * 6;
|
||||||
size_t offset = (cmd.startvertex / 4) * 6 * elemsize;
|
size_t offset = (cmd.startvertex / 4) * 6 * elemsize;
|
||||||
@@ -656,9 +649,9 @@ void Font::drawVertices(const DrawCommands &drawcommands)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Font::printv(const Matrix4 &t, const DrawCommands &drawcommands, const std::vector<GlyphVertex> &vertices)
|
void Font::printv(const Matrix4 &t, const std::vector<DrawCommand> &drawcommands, const std::vector<GlyphVertex> &vertices)
|
||||||
{
|
{
|
||||||
if (vertices.empty() || drawcommands.commands.empty())
|
if (vertices.empty() || drawcommands.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OpenGL::TempDebugGroup debuggroup("Font print");
|
OpenGL::TempDebugGroup debuggroup("Font print");
|
||||||
@@ -668,16 +661,9 @@ void Font::printv(const Matrix4 &t, const DrawCommands &drawcommands, const std:
|
|||||||
|
|
||||||
glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, sizeof(GlyphVertex), &vertices[0].x);
|
glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, sizeof(GlyphVertex), &vertices[0].x);
|
||||||
glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_UNSIGNED_SHORT, GL_TRUE, sizeof(GlyphVertex), &vertices[0].s);
|
glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_UNSIGNED_SHORT, GL_TRUE, sizeof(GlyphVertex), &vertices[0].s);
|
||||||
|
glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(GlyphVertex), &vertices[0].color.r);
|
||||||
|
|
||||||
uint32 enabledattribs = ATTRIBFLAG_POS | ATTRIBFLAG_TEXCOORD;
|
gl.useVertexAttribArrays(ATTRIBFLAG_POS | ATTRIBFLAG_TEXCOORD | ATTRIBFLAG_COLOR);
|
||||||
|
|
||||||
if (drawcommands.usecolors)
|
|
||||||
{
|
|
||||||
glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(GlyphVertex), &vertices[0].color.r);
|
|
||||||
enabledattribs |= ATTRIBFLAG_COLOR;
|
|
||||||
}
|
|
||||||
|
|
||||||
gl.useVertexAttribArrays(enabledattribs);
|
|
||||||
|
|
||||||
drawVertices(drawcommands);
|
drawVertices(drawcommands);
|
||||||
}
|
}
|
||||||
@@ -688,7 +674,7 @@ void Font::print(const std::vector<ColoredString> &text, float x, float y, float
|
|||||||
getCodepointsFromString(text, codepoints);
|
getCodepointsFromString(text, codepoints);
|
||||||
|
|
||||||
std::vector<GlyphVertex> vertices;
|
std::vector<GlyphVertex> vertices;
|
||||||
DrawCommands drawcommands = generateVertices(codepoints, vertices);
|
std::vector<DrawCommand> drawcommands = generateVertices(codepoints, vertices);
|
||||||
|
|
||||||
Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky);
|
Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||||
|
|
||||||
@@ -701,7 +687,7 @@ void Font::printf(const std::vector<ColoredString> &text, float x, float y, floa
|
|||||||
getCodepointsFromString(text, codepoints);
|
getCodepointsFromString(text, codepoints);
|
||||||
|
|
||||||
std::vector<GlyphVertex> vertices;
|
std::vector<GlyphVertex> vertices;
|
||||||
DrawCommands drawcommands = generateVerticesFormatted(codepoints, wrap, align, vertices);
|
std::vector<DrawCommand> drawcommands = generateVerticesFormatted(codepoints, wrap, align, vertices);
|
||||||
|
|
||||||
Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky);
|
Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky);
|
||||||
|
|
||||||
|
|||||||
@@ -100,22 +100,16 @@ public:
|
|||||||
int vertexcount;
|
int vertexcount;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct DrawCommands
|
|
||||||
{
|
|
||||||
std::vector<DrawCommand> commands;
|
|
||||||
bool usecolors;
|
|
||||||
};
|
|
||||||
|
|
||||||
Font(love::font::Rasterizer *r, const Texture::Filter &filter = Texture::getDefaultFilter());
|
Font(love::font::Rasterizer *r, const Texture::Filter &filter = Texture::getDefaultFilter());
|
||||||
|
|
||||||
virtual ~Font();
|
virtual ~Font();
|
||||||
|
|
||||||
DrawCommands generateVertices(const ColoredCodepoints &codepoints, std::vector<GlyphVertex> &vertices, float extra_spacing = 0.0f, Vector offset = {}, TextInfo *info = nullptr);
|
std::vector<DrawCommand> generateVertices(const ColoredCodepoints &codepoints, std::vector<GlyphVertex> &vertices, float extra_spacing = 0.0f, Vector offset = {}, TextInfo *info = nullptr);
|
||||||
DrawCommands generateVertices(const std::string &text, std::vector<GlyphVertex> &vertices, float extra_spacing = 0.0f, Vector offset = Vector(), TextInfo *info = nullptr);
|
std::vector<DrawCommand> generateVertices(const std::string &text, std::vector<GlyphVertex> &vertices, float extra_spacing = 0.0f, Vector offset = Vector(), TextInfo *info = nullptr);
|
||||||
|
|
||||||
DrawCommands generateVerticesFormatted(const ColoredCodepoints &text, float wrap, AlignMode align, std::vector<GlyphVertex> &vertices, TextInfo *info = nullptr);
|
std::vector<DrawCommand> generateVerticesFormatted(const ColoredCodepoints &text, float wrap, AlignMode align, std::vector<GlyphVertex> &vertices, TextInfo *info = nullptr);
|
||||||
|
|
||||||
void drawVertices(const DrawCommands &drawcommands);
|
void drawVertices(const std::vector<DrawCommand> &drawcommands);
|
||||||
|
|
||||||
static void getCodepointsFromString(const std::string &str, Codepoints &codepoints);
|
static void getCodepointsFromString(const std::string &str, Codepoints &codepoints);
|
||||||
static void getCodepointsFromString(const std::vector<ColoredString> &strs, ColoredCodepoints &codepoints);
|
static void getCodepointsFromString(const std::vector<ColoredString> &strs, ColoredCodepoints &codepoints);
|
||||||
@@ -233,7 +227,7 @@ private:
|
|||||||
const Glyph &addGlyph(uint32 glyph);
|
const Glyph &addGlyph(uint32 glyph);
|
||||||
const Glyph &findGlyph(uint32 glyph);
|
const Glyph &findGlyph(uint32 glyph);
|
||||||
float getKerning(uint32 leftglyph, uint32 rightglyph);
|
float getKerning(uint32 leftglyph, uint32 rightglyph);
|
||||||
void printv(const Matrix4 &t, const DrawCommands &drawcommands, const std::vector<GlyphVertex> &vertices);
|
void printv(const Matrix4 &t, const std::vector<DrawCommand> &drawcommands, const std::vector<GlyphVertex> &vertices);
|
||||||
|
|
||||||
std::vector<StrongRef<love::font::Rasterizer>> rasterizers;
|
std::vector<StrongRef<love::font::Rasterizer>> rasterizers;
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ void Text::regenerateVertices()
|
|||||||
void Text::addTextData(const TextData &t)
|
void Text::addTextData(const TextData &t)
|
||||||
{
|
{
|
||||||
std::vector<Font::GlyphVertex> vertices;
|
std::vector<Font::GlyphVertex> vertices;
|
||||||
Font::DrawCommands new_commands;
|
std::vector<Font::DrawCommand> new_commands;
|
||||||
|
|
||||||
// We only have formatted text if the align mode is valid.
|
// We only have formatted text if the align mode is valid.
|
||||||
if (t.align == Font::ALIGN_MAX_ENUM)
|
if (t.align == Font::ALIGN_MAX_ENUM)
|
||||||
@@ -127,37 +127,34 @@ void Text::addTextData(const TextData &t)
|
|||||||
if (!t.append_vertices)
|
if (!t.append_vertices)
|
||||||
{
|
{
|
||||||
voffset = 0;
|
voffset = 0;
|
||||||
draw_commands.commands.clear();
|
draw_commands.clear();
|
||||||
draw_commands.usecolors = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadVertices(vertices, voffset);
|
uploadVertices(vertices, voffset);
|
||||||
|
|
||||||
if (!new_commands.commands.empty())
|
if (!new_commands.empty())
|
||||||
{
|
{
|
||||||
// The start vertex should be adjusted to account for the vertex offset.
|
// The start vertex should be adjusted to account for the vertex offset.
|
||||||
for (Font::DrawCommand &cmd : new_commands.commands)
|
for (Font::DrawCommand &cmd : new_commands)
|
||||||
cmd.startvertex += (int) voffset;
|
cmd.startvertex += (int) voffset;
|
||||||
|
|
||||||
auto firstcmd = new_commands.commands.begin();
|
auto firstcmd = new_commands.begin();
|
||||||
|
|
||||||
// If the first draw command in the new list has the same texture as the
|
// 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
|
// last one in the existing list we're building and its vertices are
|
||||||
// in-order, we can combine them (saving a draw call.)
|
// in-order, we can combine them (saving a draw call.)
|
||||||
if (!draw_commands.commands.empty())
|
if (!draw_commands.empty())
|
||||||
{
|
{
|
||||||
auto prevcmd = draw_commands.commands.back();
|
auto prevcmd = draw_commands.back();
|
||||||
if (prevcmd.texture == firstcmd->texture && (prevcmd.startvertex + prevcmd.vertexcount) == firstcmd->startvertex)
|
if (prevcmd.texture == firstcmd->texture && (prevcmd.startvertex + prevcmd.vertexcount) == firstcmd->startvertex)
|
||||||
{
|
{
|
||||||
draw_commands.commands.back().vertexcount += firstcmd->vertexcount;
|
draw_commands.back().vertexcount += firstcmd->vertexcount;
|
||||||
++firstcmd;
|
++firstcmd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append the new draw commands to the list we're building.
|
// Append the new draw commands to the list we're building.
|
||||||
draw_commands.commands.insert(draw_commands.commands.end(), firstcmd, new_commands.commands.end());
|
draw_commands.insert(draw_commands.end(), firstcmd, new_commands.end());
|
||||||
|
|
||||||
draw_commands.usecolors = draw_commands.usecolors || new_commands.usecolors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vert_offset = voffset + vertices.size();
|
vert_offset = voffset + vertices.size();
|
||||||
@@ -210,8 +207,7 @@ void Text::addf(const std::vector<Font::ColoredString> &text, float wrap, Font::
|
|||||||
void Text::clear()
|
void Text::clear()
|
||||||
{
|
{
|
||||||
text_data.clear();
|
text_data.clear();
|
||||||
draw_commands.commands.clear();
|
draw_commands.clear();
|
||||||
draw_commands.usecolors = false;
|
|
||||||
texture_cache_id = font->getTextureCacheID();
|
texture_cache_id = font->getTextureCacheID();
|
||||||
text_info = {};
|
text_info = {};
|
||||||
vert_offset = 0;
|
vert_offset = 0;
|
||||||
@@ -219,7 +215,7 @@ void Text::clear()
|
|||||||
|
|
||||||
void Text::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
|
void Text::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
|
||||||
{
|
{
|
||||||
if (vbo == nullptr || draw_commands.commands.empty())
|
if (vbo == nullptr || draw_commands.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
OpenGL::TempDebugGroup debuggroup("Text object draw");
|
OpenGL::TempDebugGroup debuggroup("Text object draw");
|
||||||
@@ -243,17 +239,10 @@ void Text::draw(float x, float y, float angle, float sx, float sy, float ox, flo
|
|||||||
// Font::drawVertices expects AttribPointer calls to be done already.
|
// Font::drawVertices expects AttribPointer calls to be done already.
|
||||||
glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, stride, vbo->getPointer(pos_offset));
|
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_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));
|
||||||
if (draw_commands.usecolors)
|
|
||||||
glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, stride, vbo->getPointer(color_offset));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 enabledattribs = ATTRIBFLAG_POS | ATTRIBFLAG_TEXCOORD;
|
gl.useVertexAttribArrays(ATTRIBFLAG_POS | ATTRIBFLAG_TEXCOORD | ATTRIBFLAG_COLOR);
|
||||||
|
|
||||||
if (draw_commands.usecolors)
|
|
||||||
enabledattribs |= ATTRIBFLAG_COLOR;
|
|
||||||
|
|
||||||
gl.useVertexAttribArrays(enabledattribs);
|
|
||||||
|
|
||||||
font->drawVertices(draw_commands);
|
font->drawVertices(draw_commands);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ private:
|
|||||||
StrongRef<Font> font;
|
StrongRef<Font> font;
|
||||||
GLBuffer *vbo;
|
GLBuffer *vbo;
|
||||||
|
|
||||||
Font::DrawCommands draw_commands;
|
std::vector<Font::DrawCommand> draw_commands;
|
||||||
|
|
||||||
std::vector<TextData> text_data;
|
std::vector<TextData> text_data;
|
||||||
Font::TextInfo text_info;
|
Font::TextInfo text_info;
|
||||||
|
|||||||
Reference in New Issue
Block a user