diff --git a/source/gs-vertex.cpp b/source/gs-vertex.cpp index 271e79a3..82463256 100644 --- a/source/gs-vertex.cpp +++ b/source/gs-vertex.cpp @@ -18,3 +18,31 @@ */ #include "gs-vertex.h" +#include "util-memory.h" + +GS::Vertex::Vertex() { + this->hasStore = true; + this->store = util::malloc_aligned(16, sizeof(vec3) * 3 + sizeof(uint32_t) + sizeof(vec4)*MAXIMUM_UVW_LAYERS); + this->position = reinterpret_cast(store); + this->normal = reinterpret_cast(reinterpret_cast(store) + (16 * 1)); + this->tangent = reinterpret_cast(reinterpret_cast(store) + (16 * 2)); + for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) { + this->uv[n] = reinterpret_cast(reinterpret_cast(store) + (16 * (2 + n))); + } + this->color = reinterpret_cast(reinterpret_cast(store) + (16 * (3 + MAXIMUM_UVW_LAYERS))); +} + +GS::Vertex::~Vertex() { + if (hasStore) + util::free_aligned(store); +} + +GS::Vertex::Vertex(vec3* p, vec3* n, vec3* t, uint32_t* col, vec4* uvs[MAXIMUM_UVW_LAYERS]) + : position(p), normal(n), tangent(t), color(col) { + if (uvs != nullptr) { + for (size_t idx = 0; idx < MAXIMUM_UVW_LAYERS; idx++) { + this->uv[idx] = uvs[idx]; + } + } + this->hasStore = false; +} diff --git a/source/gs-vertex.h b/source/gs-vertex.h index 88c7ea97..77e37834 100644 --- a/source/gs-vertex.h +++ b/source/gs-vertex.h @@ -35,5 +35,13 @@ namespace GS { vec3* tangent; uint32_t* color; vec4* uv[MAXIMUM_UVW_LAYERS]; + + Vertex(); + Vertex(vec3* p, vec3* n, vec3* t, uint32_t* col, vec4* uv[MAXIMUM_UVW_LAYERS]); + ~Vertex(); + + private: + bool hasStore; + void* store; }; }