gs-vertex: Formatting and fix constructors

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2018-09-27 03:07:13 +02:00
parent 431fee7b9b
commit 8a897c8898
2 changed files with 39 additions and 24 deletions

View file

@ -20,29 +20,44 @@
#include "gs-vertex.h" #include "gs-vertex.h"
#include "util-memory.h" #include "util-memory.h"
gs::vertex::vertex() { gs::vertex::vertex()
this->hasStore = true; : hasStore(true), store(nullptr), position(nullptr), normal(nullptr), tangent(nullptr), color(nullptr)
this->store = util::malloc_aligned(16, sizeof(vec3) * 3 + sizeof(uint32_t) + sizeof(vec4)*MAXIMUM_UVW_LAYERS); {
this->position = reinterpret_cast<vec3*>(store); store = util::malloc_aligned(16, sizeof(vec3) * 3 + sizeof(uint32_t) + sizeof(vec4) * MAXIMUM_UVW_LAYERS);
this->normal = reinterpret_cast<vec3*>(reinterpret_cast<char*>(store) + (16 * 1));
this->tangent = reinterpret_cast<vec3*>(reinterpret_cast<char*>(store) + (16 * 2)); size_t offset = 0;
position = reinterpret_cast<vec3*>(reinterpret_cast<char*>(store) + offset);
offset += sizeof(vec3);
normal = reinterpret_cast<vec3*>(reinterpret_cast<char*>(store) + offset);
offset += sizeof(vec3);
tangent = reinterpret_cast<vec3*>(reinterpret_cast<char*>(store) + offset);
offset += sizeof(vec3);
color = reinterpret_cast<uint32_t*>(reinterpret_cast<char*>(store) + offset);
offset += sizeof(uint32_t);
for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) { for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) {
this->uv[n] = reinterpret_cast<vec4*>(reinterpret_cast<char*>(store) + (16 * (2 + n))); uv[n] = reinterpret_cast<vec4*>(reinterpret_cast<char*>(store) + offset);
offset += sizeof(vec4);
} }
this->color = reinterpret_cast<uint32_t*>(reinterpret_cast<char*>(store) + (16 * (3 + MAXIMUM_UVW_LAYERS)));
} }
gs::vertex::~vertex() { gs::vertex::~vertex()
if (hasStore) {
if (hasStore) {
util::free_aligned(store); util::free_aligned(store);
}
} }
gs::vertex::vertex(vec3* p, vec3* n, vec3* t, uint32_t* col, vec4* uvs[MAXIMUM_UVW_LAYERS]) 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) { if (uvs != nullptr) {
for (size_t idx = 0; idx < MAXIMUM_UVW_LAYERS; idx++) { for (size_t idx = 0; idx < MAXIMUM_UVW_LAYERS; idx++) {
this->uv[idx] = uvs[idx]; this->uv[idx] = uvs[idx];
} }
} }
this->hasStore = false;
} }

View file

@ -18,30 +18,30 @@
*/ */
#pragma once #pragma once
#include "gs-limits.h" #include <cinttypes>
#include <inttypes.h>
#include <xmmintrin.h> #include <xmmintrin.h>
#include "gs-limits.h"
extern "C" { extern "C" {
#pragma warning( push ) #pragma warning(push)
#pragma warning( disable: 4201 ) #pragma warning(disable : 4201)
#include <graphics/vec3.h> #include <graphics/vec3.h>
#pragma warning( pop ) #pragma warning(pop)
} }
namespace gs { namespace gs {
struct vertex { struct vertex {
vec3* position; vec3* position;
vec3* normal; vec3* normal;
vec3* tangent; vec3* tangent;
uint32_t* color; uint32_t* color;
vec4* uv[MAXIMUM_UVW_LAYERS]; vec4* uv[MAXIMUM_UVW_LAYERS];
vertex(); vertex();
vertex(vec3* p, vec3* n, vec3* t, uint32_t* col, vec4* uv[MAXIMUM_UVW_LAYERS]); vertex(vec3* p, vec3* n, vec3* t, uint32_t* col, vec4* uv[MAXIMUM_UVW_LAYERS]);
~vertex(); ~vertex();
private: private:
bool hasStore; bool hasStore;
void* store; void* store;
}; };
} } // namespace gs