diff --git a/source/gs-vertex.cpp b/source/gs-vertex.cpp index 69a59c79..4b94ea0a 100644 --- a/source/gs-vertex.cpp +++ b/source/gs-vertex.cpp @@ -18,3 +18,48 @@ */ #include "gs-vertexbuffer.h" +#include "util-memory.h" + +GS::Vertex& GS::Vertex::operator=(const Vertex& r) { + vec3_copy(&this->position, &r.position); + vec3_copy(&this->normal, &r.normal); + vec3_copy(&this->tangent, &r.tangent); + for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) { + vec4_copy(&this->uv[n], &r.uv[n]); + } + return *this; +} + +GS::Vertex* GS::Vertex::operator=(const Vertex* r) { + vec3_copy(&this->position, &r->position); + vec3_copy(&this->normal, &r->normal); + vec3_copy(&this->tangent, &r->tangent); + for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) { + vec4_copy(&this->uv[n], &r->uv[n]); + } + return this; +} + +void* GS::Vertex::operator new(size_t count) { + return util::malloc_aligned(16, count); +} + +void* GS::Vertex::operator new(size_t count, void* d){ + return d; +} + +void* GS::Vertex::operator new[](size_t count) { + return util::malloc_aligned(16, count); +} + +void* GS::Vertex::operator new[](size_t count, void* d) { + return d; +} + +void GS::Vertex::operator delete(void* p) { + return util::free_aligned(p); +} + +void GS::Vertex::operator delete[](void* p) { + return util::free_aligned(p); +} diff --git a/source/gs-vertex.h b/source/gs-vertex.h index 06c2d193..979f19e7 100644 --- a/source/gs-vertex.h +++ b/source/gs-vertex.h @@ -29,11 +29,27 @@ extern "C" { namespace GS { const uint32_t MAXIMUM_UVW_LAYERS = 8u; // ToDo: Optimize for use with GS::VertexBuffer so that it doesn't require in-memory copy. - struct Vertex { + __declspec(align(16)) struct Vertex { vec3 position; vec3 normal; vec3 tangent; vec4 uv[MAXIMUM_UVW_LAYERS]; uint32_t color; + + // Operators + static void* Vertex::operator new(size_t count); + static void* Vertex::operator new[](size_t count); + static void* Vertex::operator new(size_t count, void* d); + static void* Vertex::operator new[](size_t count, void* d); + static void Vertex::operator delete(void* p); + static void Vertex::operator delete[](void* p); + + //Vertex& Vertex::operator =(Vertex r); + Vertex& Vertex::operator =(const Vertex& r); + Vertex* Vertex::operator =(const Vertex* r); + + private: + uint32_t padding[3]; }; + }