summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-07-06 13:33:30 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-07-06 13:33:30 +0100
commit16392a2dab40317db620ef846469faadaa994e9f (patch)
treec8d28c4db1830f4f16bd7400fb69faad2138c4eb
parentAdd an InstanceVertices partition perf test (diff)
downloadilt-16392a2dab40317db620ef846469faadaa994e9f.tar.bz2
ilt-16392a2dab40317db620ef846469faadaa994e9f.tar.xz
ilt-16392a2dab40317db620ef846469faadaa994e9f.zip
Replace deprecated GL_QUADS usage in text rendering
-rw-r--r--ui/text.cpp19
-rw-r--r--ui/text.h7
2 files changed, 19 insertions, 7 deletions
diff --git a/ui/text.cpp b/ui/text.cpp
index 5675061..bdaaba5 100644
--- a/ui/text.cpp
+++ b/ui/text.cpp
@@ -27,13 +27,20 @@ Text::operator=(const std::string_view s)
return init += q.second.size();
});
quads.resize(glyphCount);
- GLint current = 0;
+ GLushort current = 0;
auto model = models.begin();
auto quad = quads.begin();
for (const auto & [texture, fquads] : tquads) {
- model->first = texture;
- model->second = {fquads.size() * 4, current * 4};
- current += static_cast<GLint>(fquads.size());
+ model->textureId = texture;
+ model->range.resize(fquads.size() * 6);
+ for (auto out = model->range.begin(); const auto & q [[maybe_unused]] : fquads) {
+ static constexpr std::array<GLushort, 6> quadIndices {0, 1, 2, 2, 3, 0};
+ std::transform(quadIndices.begin(), quadIndices.end(), out, [current](auto x) {
+ return current + x;
+ });
+ current += 4;
+ out += 6;
+ }
model++;
quad = std::transform(fquads.begin(), fquads.end(), quad, [this](const Font::Quad & q) {
return q * [this](const glm::vec4 & corner) {
@@ -52,8 +59,8 @@ Text::render(const UIShader & shader, const Position &) const
glActiveTexture(GL_TEXTURE0);
glBindVertexArray(vao);
for (const auto & m : models) {
- glBindTexture(GL_TEXTURE_2D, m.first);
- glDrawArrays(GL_QUADS, m.second.second, m.second.first);
+ glBindTexture(GL_TEXTURE_2D, m.textureId);
+ glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(m.range.size()), GL_UNSIGNED_SHORT, m.range.data());
}
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
diff --git a/ui/text.h b/ui/text.h
index 31ed9a5..a367456 100644
--- a/ui/text.h
+++ b/ui/text.h
@@ -21,7 +21,12 @@ public:
Text & operator=(const std::string_view s);
private:
- std::vector<std::pair<GLuint, std::pair<GLsizei, GLint>>> models;
+ struct TextData {
+ GLuint textureId;
+ std::vector<unsigned short> range;
+ };
+
+ std::vector<TextData> models;
glContainer<Font::Quad> quads;
glVertexArray vao;
glm::vec3 colour;