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 "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<vec3*>(store);
this->normal = reinterpret_cast<vec3*>(reinterpret_cast<char*>(store) + (16 * 1));
this->tangent = reinterpret_cast<vec3*>(reinterpret_cast<char*>(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<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++) {
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() {
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;
}

View file

@ -18,30 +18,30 @@
*/
#pragma once
#include "gs-limits.h"
#include <inttypes.h>
#include <cinttypes>
#include <xmmintrin.h>
#include "gs-limits.h"
extern "C" {
#pragma warning( push )
#pragma warning( disable: 4201 )
#include <graphics/vec3.h>
#pragma warning( pop )
#pragma warning(push)
#pragma warning(disable : 4201)
#include <graphics/vec3.h>
#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