diff --git a/.idea/editor.xml b/.idea/editor.xml
index 2f7424b..907ea1b 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -287,5 +287,7 @@
+
+
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 628e9ca..a0943e0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.25)
-project(gpu-particles VERSION 0.0.8)
+project(gpu-particles VERSION 0.0.9)
option(ENABLE_ADDRSAN "Enable the address sanitizer" OFF)
option(ENABLE_UBSAN "Enable the ub sanitizer" OFF)
diff --git a/src/main.cpp b/src/main.cpp
index 46e4c01..4d37469 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -34,8 +34,35 @@ blt::gfx::first_person_camera camera;
// use types for state that way you are not confused about what is happening?
+class unique_vbo_t;
+
+namespace detail
+{
+ class vbo_context_t
+ {
+ public:
+ explicit vbo_context_t(unique_vbo_t& vbo): vbo(vbo)
+ {
+ bind();
+ }
+
+ /**
+ * By default, the VBO is bound when this class is constructed (this class should only be constructed through the VBO bind() method)
+ * This function is provided in case you need to rebind the VBO
+ */
+ vbo_context_t& bind();
+
+ vbo_context_t& unbind();
+
+ private:
+ unique_vbo_t& vbo;
+ };
+}
+
class unique_vbo_t
{
+ friend class detail::vbo_context_t;
+
public:
explicit unique_vbo_t(const GLuint type): type(type)
{
@@ -47,8 +74,7 @@ public:
unique_vbo_t& operator=(const unique_vbo_t&) = delete;
unique_vbo_t(unique_vbo_t&& other) noexcept: vboID(std::exchange(other.vboID, std::nullopt)), type(other.type)
- {
- }
+ {}
unique_vbo_t& operator=(unique_vbo_t&& other) noexcept
{
@@ -57,6 +83,16 @@ public:
return *this;
}
+ GLuint change_type(const GLuint type)
+ {
+ return std::exchange(this->type, type);
+ }
+
+ [[nodiscard]] auto bind()
+ {
+ return detail::vbo_context_t{*this};
+ }
+
~unique_vbo_t()
{
if (vboID)
@@ -68,6 +104,21 @@ private:
GLuint type;
};
+namespace detail
+{
+ vbo_context_t& vbo_context_t::bind()
+ {
+ glBindBuffer(vbo.type, *vbo.vboID);
+ return *this;
+ }
+
+ vbo_context_t& vbo_context_t::unbind()
+ {
+ glBindBuffer(vbo.type, 0);
+ return *this;
+ }
+}
+
class unique_vao_t
{
public:
@@ -81,8 +132,7 @@ public:
unique_vao_t& operator=(const unique_vao_t&) = delete;
unique_vao_t(unique_vao_t&& other) noexcept: vaoID(std::exchange(other.vaoID, std::nullopt))
- {
- }
+ {}
unique_vao_t& operator=(unique_vao_t&& other) noexcept
{