From 161b59ee17baf809b4266500cc49f2a69a217eb3 Mon Sep 17 00:00:00 2001 From: themancalledjakob Date: Tue, 27 Jun 2023 20:05:56 +0200 Subject: [PATCH] globalTransform in VBO --- src/MsdfAtlasLayerCombo.cpp | 9 +++++++++ src/MsdfLayer.cpp | 24 ++++++++++++++++-------- src/MsdfLayer.h | 9 +++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/MsdfAtlasLayerCombo.cpp b/src/MsdfAtlasLayerCombo.cpp index 9be529c..f8d29e4 100644 --- a/src/MsdfAtlasLayerCombo.cpp +++ b/src/MsdfAtlasLayerCombo.cpp @@ -2,6 +2,7 @@ #include "AtlasLayerCombo.h" #include "MsdfLayer.h" #include "Utils.h" +#include "fwd.hpp" #include "of3dGraphics.h" #include "ofFileUtils.h" #include "ofGraphics.h" @@ -56,6 +57,14 @@ void MsdfAtlasLayerCombo::setup(const ComboIdentifier & layerIdentifier, glVertexAttribPointer(3, 4, GL_FLOAT, false, sizeof(BufferVertex), (void *)offsetof(BufferVertex, color)); glEnableVertexAttribArray(4); glVertexAttribPointer(4, 1, GL_FLOAT, false, sizeof(BufferVertex), (void *)offsetof(BufferVertex, mix)); + glEnableVertexAttribArray(5); + glVertexAttribPointer(5, 4, GL_FLOAT, false, sizeof(BufferVertex), (void *)offsetof(BufferVertex, globalTransform)); + glEnableVertexAttribArray(6); + glVertexAttribPointer(6, 4, GL_FLOAT, false, sizeof(BufferVertex), (void *)(offsetof(BufferVertex, globalTransform) + sizeof(glm::float32) * 4)); + glEnableVertexAttribArray(7); + glVertexAttribPointer(7, 4, GL_FLOAT, false, sizeof(BufferVertex), (void *)(offsetof(BufferVertex, globalTransform) + sizeof(glm::float32) * 4 * 2)); + glEnableVertexAttribArray(8); + glVertexAttribPointer(8, 4, GL_FLOAT, false, sizeof(BufferVertex), (void *)(offsetof(BufferVertex, globalTransform) + sizeof(glm::float32) * 4 * 3)); glBindVertexArray(0); } diff --git a/src/MsdfLayer.cpp b/src/MsdfLayer.cpp index 624f8f2..6b7bd40 100644 --- a/src/MsdfLayer.cpp +++ b/src/MsdfLayer.cpp @@ -371,13 +371,21 @@ bool MsdfLayer::collectCharacter(const char character, glm::vec2 uv3_a = glm::vec2(scale_a.x, 0) + translation_a; glm::vec2 uv3_b = glm::vec2(scale_b.x, 0) + translation_b; + glm::vec4 p0 = glm::vec4(0, 0, 0, 1); + glm::vec4 p1 = glm::vec4(0, h, 0, 1); + glm::vec4 p2 = glm::vec4(w, h, 0, 1); + glm::vec4 p3 = glm::vec4(w, 0, 0, 1); + + vertices.reserve(nodes.size() * 4); + indices.reserve(nodes.size() * 6); for(int i = 0; i < nodes.size(); i++){ const glm::vec4 & color = colors[i]; ofNode & node = nodes[i]; - glm::vec4 p0 = node.getGlobalTransformMatrix() * glm::vec4(0, 0, 0, 1); - glm::vec4 p1 = node.getGlobalTransformMatrix() * glm::vec4(0, h, 0, 1); - glm::vec4 p2 = node.getGlobalTransformMatrix() * glm::vec4(w, h, 0, 1); - glm::vec4 p3 = node.getGlobalTransformMatrix() * glm::vec4(w, 0, 0, 1); + //glm::vec4 p0 = node.getGlobalTransformMatrix() * glm::vec4(0, 0, 0, 1); + //glm::vec4 p1 = node.getGlobalTransformMatrix() * glm::vec4(0, h, 0, 1); + //glm::vec4 p2 = node.getGlobalTransformMatrix() * glm::vec4(w, h, 0, 1); + //glm::vec4 p3 = node.getGlobalTransformMatrix() * glm::vec4(w, 0, 0, 1); + glm::mat4 globalTransform = node.getGlobalTransformMatrix(); int32_t base = static_cast (vertices.size()); vertices.push_back(BufferVertex{ @@ -385,28 +393,28 @@ bool MsdfLayer::collectCharacter(const char character, {uv0_a.x, uv0_a.y}, {uv0_b.x, uv0_b.y}, {color.r, color.g, color.b, color.a}, - mix + mix, globalTransform }); vertices.push_back(BufferVertex{ {p1.x, p1.y, p1.z, p1.w}, {uv1_a.x, uv1_a.y}, {uv1_b.x, uv1_b.y}, {color.r, color.g, color.b, color.a}, - mix + mix, globalTransform }); vertices.push_back(BufferVertex{ {p2.x, p2.y, p2.z, p2.w}, {uv2_a.x, uv2_a.y}, {uv2_b.x, uv2_b.y}, {color.r, color.g, color.b, color.a}, - mix + mix, globalTransform }); vertices.push_back(BufferVertex{ {p3.x, p3.y, p3.z, p3.w}, {uv3_a.x, uv3_a.y}, {uv3_b.x, uv3_b.y}, {color.r, color.g, color.b, color.a}, - mix + mix, globalTransform }); indices.insert(indices.end(), {base, base + 1, base + 2, base + 2, base + 3, base}); nElements++; diff --git a/src/MsdfLayer.h b/src/MsdfLayer.h index e51a3b6..5bae77c 100644 --- a/src/MsdfLayer.h +++ b/src/MsdfLayer.h @@ -27,6 +27,15 @@ class MsdfLayer : public Layer { GLfloat uv_b[2]; GLfloat color[4]; GLfloat mix; + glm::mat4 globalTransform; + }; + struct BufferBufferPrimitive { + float w; + float h; + glm::vec2 translation_a; + glm::vec2 scale_a; + glm::vec2 translation_b; + glm::vec2 scale_b; }; void setup(const LayerSettings & settings = LayerSettings()) override; void update() override;