mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-10 22:05:06 +00:00
gs-vertex: Allocate memory if none is assigned
Allows code to directly use GS::Vertex for their own purposes without having to rely on GS::VertexBuffer, which comes with the added overhead of allocating GPU memory.
This commit is contained in:
parent
823bac9b13
commit
b4d63e919e
2 changed files with 36 additions and 0 deletions
|
@ -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<vec3*>(store);
|
||||
this->normal = reinterpret_cast<vec3*>(reinterpret_cast<char*>(store) + (16 * 1));
|
||||
this->tangent = reinterpret_cast<vec3*>(reinterpret_cast<char*>(store) + (16 * 2));
|
||||
for (size_t n = 0; n < MAXIMUM_UVW_LAYERS; n++) {
|
||||
this->uv[n] = reinterpret_cast<vec4*>(reinterpret_cast<char*>(store) + (16 * (2 + n)));
|
||||
}
|
||||
this->color = reinterpret_cast<uint32_t*>(reinterpret_cast<char*>(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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue