diff options
author | LaG1924 <lag1924@gmail.com> | 2021-12-07 12:38:36 +0100 |
---|---|---|
committer | LaG1924 <lag1924@gmail.com> | 2021-12-07 12:38:36 +0100 |
commit | a27bfe76545822eb4ef2798c8200096ec9b6963c (patch) | |
tree | 6ac7ac3eee37574425c149740e88188767be36da | |
parent | Added optional forward rendering (diff) | |
download | AltCraft-a27bfe76545822eb4ef2798c8200096ec9b6963c.tar AltCraft-a27bfe76545822eb4ef2798c8200096ec9b6963c.tar.gz AltCraft-a27bfe76545822eb4ef2798c8200096ec9b6963c.tar.bz2 AltCraft-a27bfe76545822eb4ef2798c8200096ec9b6963c.tar.lz AltCraft-a27bfe76545822eb4ef2798c8200096ec9b6963c.tar.xz AltCraft-a27bfe76545822eb4ef2798c8200096ec9b6963c.tar.zst AltCraft-a27bfe76545822eb4ef2798c8200096ec9b6963c.zip |
Diffstat (limited to '')
-rw-r--r-- | src/GalOgl.cpp | 162 |
1 files changed, 98 insertions, 64 deletions
diff --git a/src/GalOgl.cpp b/src/GalOgl.cpp index 4ac6c84..6452a44 100644 --- a/src/GalOgl.cpp +++ b/src/GalOgl.cpp @@ -7,70 +7,6 @@ #include "Utility.hpp" -enum class GlResourceType { - Vbo, - Vao, - Texture, - Fbo, - Program, - None, -}; - -class GlResource { - GlResourceType type = GlResourceType::None; - GLuint res = 0; -public: - GlResource() = default; - - GlResource(GLuint resource, GlResourceType resType) noexcept : res(resource), type(resType) {} - - GlResource(const GlResource&) = delete; - - GlResource(GlResource&& rhs) noexcept { - std::swap(this->res, rhs.res); - std::swap(this->type, rhs.type); - } - - GlResource& operator=(const GlResource&) = delete; - - GlResource& operator=(GlResource&& rhs) noexcept { - std::swap(this->res, rhs.res); - std::swap(this->type, rhs.type); - return *this; - } - - ~GlResource() { - switch (type) { - case GlResourceType::Vbo: - glDeleteBuffers(1, &res); - break; - case GlResourceType::Vao: - glDeleteVertexArrays(1, &res); - break; - case GlResourceType::Texture: - glDeleteTextures(1, &res); - break; - case GlResourceType::Fbo: - glDeleteFramebuffers(1, &res); - break; - case GlResourceType::Program: - glDeleteProgram(res); - break; - case GlResourceType::None: - default: - break; - } - } - - operator GLuint() const noexcept { - return res; - } - - GLuint Get() const noexcept { - return res; - } -}; - using namespace Gal; @@ -173,8 +109,106 @@ public: } } + void ReleaseFbo(GLuint vao) { + if (activeVao == vao) + activeVao = 0; + } + + void ReleaseVao(GLuint fbo) { + if (activeFbo == fbo) + activeEbo = 0; + } + + void ReleaseVbo(GLuint vbo) { + if (activeVbo == vbo) + activeVbo = 0; + if (activeEbo == vbo) + activeEbo = 0; + } + + void ReleaseProgram(GLuint program) { + if (activeProgram == program) + activeProgram = 0; + } + + void ReleaseTexture(GLuint texture) { + for (auto& activeTex : activeTexture) { + if (activeTex == texture) + activeTex = 0; + } + } + } oglState; +enum class GlResourceType { + Vbo, + Vao, + Texture, + Fbo, + Program, + None, +}; + +class GlResource { + GlResourceType type = GlResourceType::None; + GLuint res = 0; +public: + GlResource() = default; + + GlResource(GLuint resource, GlResourceType resType) noexcept : res(resource), type(resType) {} + + GlResource(const GlResource&) = delete; + + GlResource(GlResource&& rhs) noexcept { + std::swap(this->res, rhs.res); + std::swap(this->type, rhs.type); + } + + GlResource& operator=(const GlResource&) = delete; + + GlResource& operator=(GlResource&& rhs) noexcept { + std::swap(this->res, rhs.res); + std::swap(this->type, rhs.type); + return *this; + } + + ~GlResource() { + switch (type) { + case GlResourceType::Vbo: + oglState.ReleaseVbo(res); + glDeleteBuffers(1, &res); + break; + case GlResourceType::Vao: + oglState.ReleaseVao(res); + glDeleteVertexArrays(1, &res); + break; + case GlResourceType::Texture: + oglState.ReleaseTexture(res); + glDeleteTextures(1, &res); + break; + case GlResourceType::Fbo: + oglState.ReleaseFbo(res); + glDeleteFramebuffers(1, &res); + break; + case GlResourceType::Program: + oglState.ReleaseProgram(res); + glDeleteProgram(res); + break; + case GlResourceType::None: + default: + break; + } + } + + operator GLuint() const noexcept { + return res; + } + + GLuint Get() const noexcept { + return res; + } +}; + std::unique_ptr<ImplOgl> impl; std::shared_ptr<FramebufferOgl> fbDefault; std::shared_ptr<ShaderParametersBufferOgl> spbDefault; |