diff --git a/include/JGL/types/VRamList.h b/include/JGL/types/VRamList.h index 1e63eef..0667cba 100644 --- a/include/JGL/types/VRamList.h +++ b/include/JGL/types/VRamList.h @@ -21,12 +21,17 @@ private: void SetData(void* data, const long& length); void UpdateData(void* data, const long& offset, const long& length); public: - VRamList() = default; VRamList(const GLuint* data, const long& length); VRamList(const GLfloat* data, const long& length); VRamList(Vector2* data, const long& length); VRamList(Vector3* data, const long& length); VRamList(Vector4* data, const long& length); + + ~VRamList(); + /** Copying around the VBO data to a new VBO like this is slow. + * Pass to function by const reference or pointer always. */ + VRamList(const VRamList& rhs); + public: [[nodiscard]] GLuint GetHandle() const; /// Returns the number of elements in the list. diff --git a/src/types/VRamList.cpp b/src/types/VRamList.cpp index 31871e0..1444c4a 100644 --- a/src/types/VRamList.cpp +++ b/src/types/VRamList.cpp @@ -40,6 +40,7 @@ void JGL::VRamList::Erase() { JGL::Logger::Warning("Erasing an array buffer while it's in use?"); glDeleteBuffers(1, &list_handle); + list_handle = 0; } GLuint JGL::VRamList::GetHandle() const { @@ -250,3 +251,18 @@ void JGL::VRamList::UpdateData(const GLuint* data, const long& offset, const lon void JGL::VRamList::UpdateData(const Vector2i* data, const long& offset, const long& length) { UpdateData((void*) data, offset, length * 2); } + +JGL::VRamList::~VRamList() { + Erase(); +} + +JGL::VRamList::VRamList(const JGL::VRamList& rhs) { + if (rhs.element_array_buffer) { + auto data_array = rhs.GetDataUI(); + this->load(data_array.data(), data_array.size()); + return; + } + + auto data_array = rhs.GetDataF(); + this->load(data_array.data(), data_array.size()); +}