globalTransform in VBO

This commit is contained in:
jrkb 2023-06-27 20:05:56 +02:00
parent 6946f49b34
commit 161b59ee17
3 changed files with 34 additions and 8 deletions

View file

@ -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);
}

View file

@ -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 <int32_t>(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++;

View file

@ -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;