[nostalgia/core/userland] Cleanup shader cleanup with unique_ptr-like GLobject type

This commit is contained in:
2021-03-20 15:31:13 -05:00
parent 896a7a0a96
commit 47a43fecb1
3 changed files with 64 additions and 22 deletions
+50 -1
View File
@@ -15,9 +15,58 @@
#endif
#include <ox/std/error.hpp>
#include <ox/std/trace.hpp>
namespace nostalgia::core::renderer {
template<auto del>
struct GLobject {
GLuint id = 0;
constexpr GLobject() = default;
explicit constexpr GLobject(GLuint id) {
this->id = id;
}
constexpr GLobject(GLobject &&o) {
id = o.id;
o.id = 0;
}
~GLobject() {
oxDebugf("Deleting {}", id);
del(id);
}
GLobject &operator=(GLobject &&o) {
id = o.id;
o.id = 0;
return *this;
}
constexpr GLuint release() noexcept {
auto out = id;
id = 0;
return out;
}
constexpr operator GLuint&() noexcept {
return id;
}
constexpr operator const GLuint&() const noexcept {
return id;
}
};
extern template struct GLobject<glDeleteProgram>;
extern template struct GLobject<glDeleteShader>;
using Shader = GLobject<glDeleteShader>;
using Program = GLobject<glDeleteProgram>;
struct Texture {
GLuint texId = 0;
@@ -43,7 +92,7 @@ struct Bufferset {
};
[[nodiscard]]
ox::Result<GLuint> buildShaderProgram(const GLchar *vert, const GLchar *frag);
ox::Result<Program> buildShaderProgram(const GLchar *vert, const GLchar *frag);
void destroy(const Bufferset &bufferset);