From 8a897c889865d479d580b70fdbe1e740c8584047 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Thu, 27 Sep 2018 03:07:13 +0200 Subject: [PATCH] gs-vertex: Formatting and fix constructors --- source/gs-vertex.cpp | 39 +++++++++++++++++++++++++++------------ source/gs-vertex.h | 24 ++++++++++++------------ 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/source/gs-vertex.cpp b/source/gs-vertex.cpp index 43ad9ba..744e0ea 100644 --- a/source/gs-vertex.cpp +++ b/source/gs-vertex.cpp @@ -20,29 +20,44 @@ #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)); +gs::vertex::vertex() + : hasStore(true), store(nullptr), position(nullptr), normal(nullptr), tangent(nullptr), color(nullptr) +{ + store = util::malloc_aligned(16, sizeof(vec3) * 3 + sizeof(uint32_t) + sizeof(vec4) * MAXIMUM_UVW_LAYERS); + + size_t offset = 0; + + position = reinterpret_cast(reinterpret_cast(store) + offset); + offset += sizeof(vec3); + + normal = reinterpret_cast(reinterpret_cast(store) + offset); + offset += sizeof(vec3); + + tangent = reinterpret_cast(reinterpret_cast(store) + offset); + offset += sizeof(vec3); + + color = reinterpret_cast(reinterpret_cast(store) + offset); + offset += sizeof(uint32_t); + for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) { - this->uv[n] = reinterpret_cast(reinterpret_cast(store) + (16 * (2 + n))); + uv[n] = reinterpret_cast(reinterpret_cast(store) + offset); + offset += sizeof(vec4); } - this->color = reinterpret_cast(reinterpret_cast(store) + (16 * (3 + MAXIMUM_UVW_LAYERS))); } -gs::vertex::~vertex() { - if (hasStore) +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) { + : hasStore(false), 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 463e8c7..8c21db3 100644 --- a/source/gs-vertex.h +++ b/source/gs-vertex.h @@ -18,30 +18,30 @@ */ #pragma once -#include "gs-limits.h" -#include +#include #include +#include "gs-limits.h" extern "C" { - #pragma warning( push ) - #pragma warning( disable: 4201 ) - #include - #pragma warning( pop ) +#pragma warning(push) +#pragma warning(disable : 4201) +#include +#pragma warning(pop) } namespace gs { struct vertex { - vec3* position; - vec3* normal; - vec3* tangent; + vec3* position; + vec3* normal; + vec3* tangent; uint32_t* color; - vec4* uv[MAXIMUM_UVW_LAYERS]; + 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; + bool hasStore; void* store; }; -} +} // namespace gs