From db0cfb8e8bac705a2dfa6780b2799905cce16d38 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 19 Mar 2018 17:20:49 -0400 Subject: gl_resource_manager: Sync latest version with Citra. --- .../renderer_opengl/gl_resource_manager.h | 85 ++++++++++++++++++++-- 1 file changed, 77 insertions(+), 8 deletions(-) diff --git a/src/video_core/renderer_opengl/gl_resource_manager.h b/src/video_core/renderer_opengl/gl_resource_manager.h index 13301ec9f..7da5e74d1 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.h +++ b/src/video_core/renderer_opengl/gl_resource_manager.h @@ -36,7 +36,7 @@ public: if (handle == 0) return; glDeleteTextures(1, &handle); - OpenGLState::ResetTexture(handle); + OpenGLState::GetCurState().ResetTexture(handle).Apply(); handle = 0; } @@ -69,7 +69,7 @@ public: if (handle == 0) return; glDeleteSamplers(1, &handle); - OpenGLState::ResetSampler(handle); + OpenGLState::GetCurState().ResetSampler(handle).Apply(); handle = 0; } @@ -91,10 +91,13 @@ public: } /// Creates a new internal OpenGL resource and stores the handle - void Create(const char* vert_shader, const char* frag_shader) { + void Create(const char* vert_shader, const char* geo_shader, const char* frag_shader, + const std::vector& feedback_vars = {}, + bool separable_program = false) { if (handle != 0) return; - handle = GLShader::LoadProgram(vert_shader, frag_shader); + handle = GLShader::LoadProgram(vert_shader, geo_shader, frag_shader, feedback_vars, + separable_program); } /// Deletes the internal OpenGL resource @@ -102,7 +105,40 @@ public: if (handle == 0) return; glDeleteProgram(handle); - OpenGLState::ResetProgram(handle); + OpenGLState::GetCurState().ResetProgram(handle).Apply(); + handle = 0; + } + + GLuint handle = 0; +}; + +class OGLPipeline : private NonCopyable { +public: + OGLPipeline() = default; + OGLPipeline(OGLPipeline&& o) { + handle = std::exchange(o.handle, 0); + } + ~OGLPipeline() { + Release(); + } + OGLPipeline& operator=(OGLPipeline&& o) { + handle = std::exchange(o.handle, 0); + return *this; + } + + /// Creates a new internal OpenGL resource and stores the handle + void Create() { + if (handle != 0) + return; + glGenProgramPipelines(1, &handle); + } + + /// Deletes the internal OpenGL resource + void Release() { + if (handle == 0) + return; + glDeleteProgramPipelines(1, &handle); + OpenGLState::GetCurState().ResetPipeline(handle).Apply(); handle = 0; } @@ -135,13 +171,46 @@ public: if (handle == 0) return; glDeleteBuffers(1, &handle); - OpenGLState::ResetBuffer(handle); + OpenGLState::GetCurState().ResetBuffer(handle).Apply(); handle = 0; } GLuint handle = 0; }; +class OGLSync : private NonCopyable { +public: + OGLSync() = default; + + OGLSync(OGLSync&& o) : handle(std::exchange(o.handle, nullptr)) {} + + ~OGLSync() { + Release(); + } + OGLSync& operator=(OGLSync&& o) { + Release(); + handle = std::exchange(o.handle, nullptr); + return *this; + } + + /// Creates a new internal OpenGL resource and stores the handle + void Create() { + if (handle != 0) + return; + handle = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + } + + /// Deletes the internal OpenGL resource + void Release() { + if (handle == 0) + return; + glDeleteSync(handle); + handle = 0; + } + + GLsync handle = 0; +}; + class OGLVertexArray : private NonCopyable { public: OGLVertexArray() = default; @@ -168,7 +237,7 @@ public: if (handle == 0) return; glDeleteVertexArrays(1, &handle); - OpenGLState::ResetVertexArray(handle); + OpenGLState::GetCurState().ResetVertexArray(handle).Apply(); handle = 0; } @@ -201,7 +270,7 @@ public: if (handle == 0) return; glDeleteFramebuffers(1, &handle); - OpenGLState::ResetFramebuffer(handle); + OpenGLState::GetCurState().ResetFramebuffer(handle).Apply(); handle = 0; } -- cgit v1.2.3