diff options
Diffstat (limited to 'src/GFX/Mesh.hpp')
| -rw-r--r-- | src/GFX/Mesh.hpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/GFX/Mesh.hpp b/src/GFX/Mesh.hpp index 9d640b6..36a7dac 100644 --- a/src/GFX/Mesh.hpp +++ b/src/GFX/Mesh.hpp @@ -12,11 +12,25 @@ public: struct Attribute { template<size_t S = 3, typename T = float> Attribute( - std::vector<Vector<S, T>> data - ) : data((T*) data.data()), - data_size(data.size()), + std::vector<Vector<S, T>> v + ) : data_size(v.size()), attribute_size(S), - type_size(sizeof(T)) {}; + type_size(sizeof(T)) { + data = copy(v.data(), v.size() * S * type_size); + }; + + Attribute( + const Attribute& other + ) : data(copy(other.data, other.data_size * other.attribute_size * other.type_size)), + data_size(other.data_size), + attribute_size(other.attribute_size), + type_size(other.type_size) {}; + + static void* copy(void* ptr, uint32_t size) { + auto* buffer = new uint8_t[size]; + std::copy((uint8_t*)ptr, (uint8_t*)ptr + size, buffer); + return buffer; + } void* data; long data_size; |
