diff options
| author | 2015-08-30 08:41:28 -0300 | |
|---|---|---|
| committer | 2015-09-03 15:09:50 -0300 | |
| commit | ec28f037e6cfe42c3285866572af075e1e72b3e9 (patch) | |
| tree | 861ec1bf3da3a500b1e4ea7158aa0c59576884c3 /src | |
| parent | citra-qt: Move system shutdown to run inside EmuThread (diff) | |
| download | yuzu-ec28f037e6cfe42c3285866572af075e1e72b3e9.tar.gz yuzu-ec28f037e6cfe42c3285866572af075e1e72b3e9.tar.xz yuzu-ec28f037e6cfe42c3285866572af075e1e72b3e9.zip | |
OpenGL: Add support for Sampler Objects to state tracker
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_resource_manager.h | 24 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_state.cpp | 20 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_state.h | 2 |
3 files changed, 42 insertions, 4 deletions
diff --git a/src/video_core/renderer_opengl/gl_resource_manager.h b/src/video_core/renderer_opengl/gl_resource_manager.h index 68fc1e6d3..65034d40d 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.h +++ b/src/video_core/renderer_opengl/gl_resource_manager.h | |||
| @@ -37,6 +37,30 @@ public: | |||
| 37 | GLuint handle = 0; | 37 | GLuint handle = 0; |
| 38 | }; | 38 | }; |
| 39 | 39 | ||
| 40 | class OGLSampler : private NonCopyable { | ||
| 41 | public: | ||
| 42 | OGLSampler() = default; | ||
| 43 | OGLSampler(OGLSampler&& o) { std::swap(handle, o.handle); } | ||
| 44 | ~OGLSampler() { Release(); } | ||
| 45 | OGLSampler& operator=(OGLSampler&& o) { std::swap(handle, o.handle); return *this; } | ||
| 46 | |||
| 47 | /// Creates a new internal OpenGL resource and stores the handle | ||
| 48 | void Create() { | ||
| 49 | if (handle != 0) return; | ||
| 50 | glGenSamplers(1, &handle); | ||
| 51 | } | ||
| 52 | |||
| 53 | /// Deletes the internal OpenGL resource | ||
| 54 | void Release() { | ||
| 55 | if (handle == 0) return; | ||
| 56 | glDeleteSamplers(1, &handle); | ||
| 57 | OpenGLState::ResetSampler(handle); | ||
| 58 | handle = 0; | ||
| 59 | } | ||
| 60 | |||
| 61 | GLuint handle = 0; | ||
| 62 | }; | ||
| 63 | |||
| 40 | class OGLShader : private NonCopyable { | 64 | class OGLShader : private NonCopyable { |
| 41 | public: | 65 | public: |
| 42 | OGLShader() = default; | 66 | OGLShader() = default; |
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index ba47ce8b8..e02c27fbf 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp | |||
| @@ -44,6 +44,7 @@ OpenGLState::OpenGLState() { | |||
| 44 | 44 | ||
| 45 | for (auto& texture_unit : texture_units) { | 45 | for (auto& texture_unit : texture_units) { |
| 46 | texture_unit.texture_2d = 0; | 46 | texture_unit.texture_2d = 0; |
| 47 | texture_unit.sampler = 0; | ||
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | draw.framebuffer = 0; | 50 | draw.framebuffer = 0; |
| @@ -154,10 +155,13 @@ void OpenGLState::Apply() { | |||
| 154 | } | 155 | } |
| 155 | 156 | ||
| 156 | // Textures | 157 | // Textures |
| 157 | for (unsigned texture_index = 0; texture_index < ARRAY_SIZE(texture_units); ++texture_index) { | 158 | for (unsigned i = 0; i < ARRAY_SIZE(texture_units); ++i) { |
| 158 | if (texture_units[texture_index].texture_2d != cur_state.texture_units[texture_index].texture_2d) { | 159 | if (texture_units[i].texture_2d != cur_state.texture_units[i].texture_2d) { |
| 159 | glActiveTexture(GL_TEXTURE0 + texture_index); | 160 | glActiveTexture(GL_TEXTURE0 + i); |
| 160 | glBindTexture(GL_TEXTURE_2D, texture_units[texture_index].texture_2d); | 161 | glBindTexture(GL_TEXTURE_2D, texture_units[i].texture_2d); |
| 162 | } | ||
| 163 | if (texture_units[i].sampler != cur_state.texture_units[i].sampler) { | ||
| 164 | glBindSampler(i, texture_units[i].sampler); | ||
| 161 | } | 165 | } |
| 162 | } | 166 | } |
| 163 | 167 | ||
| @@ -192,6 +196,14 @@ void OpenGLState::ResetTexture(GLuint id) { | |||
| 192 | } | 196 | } |
| 193 | } | 197 | } |
| 194 | 198 | ||
| 199 | void OpenGLState::ResetSampler(GLuint id) { | ||
| 200 | for (auto& unit : cur_state.texture_units) { | ||
| 201 | if (unit.sampler == id) { | ||
| 202 | unit.sampler = 0; | ||
| 203 | } | ||
| 204 | } | ||
| 205 | } | ||
| 206 | |||
| 195 | void OpenGLState::ResetProgram(GLuint id) { | 207 | void OpenGLState::ResetProgram(GLuint id) { |
| 196 | if (cur_state.draw.shader_program == id) { | 208 | if (cur_state.draw.shader_program == id) { |
| 197 | cur_state.draw.shader_program = 0; | 209 | cur_state.draw.shader_program = 0; |
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index 43aa29a81..6ecbedbb4 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h | |||
| @@ -57,6 +57,7 @@ public: | |||
| 57 | // 3 texture units - one for each that is used in PICA fragment shader emulation | 57 | // 3 texture units - one for each that is used in PICA fragment shader emulation |
| 58 | struct { | 58 | struct { |
| 59 | GLuint texture_2d; // GL_TEXTURE_BINDING_2D | 59 | GLuint texture_2d; // GL_TEXTURE_BINDING_2D |
| 60 | GLuint sampler; // GL_SAMPLER_BINDING | ||
| 60 | } texture_units[3]; | 61 | } texture_units[3]; |
| 61 | 62 | ||
| 62 | struct { | 63 | struct { |
| @@ -77,6 +78,7 @@ public: | |||
| 77 | void Apply(); | 78 | void Apply(); |
| 78 | 79 | ||
| 79 | static void ResetTexture(GLuint id); | 80 | static void ResetTexture(GLuint id); |
| 81 | static void ResetSampler(GLuint id); | ||
| 80 | static void ResetProgram(GLuint id); | 82 | static void ResetProgram(GLuint id); |
| 81 | static void ResetBuffer(GLuint id); | 83 | static void ResetBuffer(GLuint id); |
| 82 | static void ResetVertexArray(GLuint id); | 84 | static void ResetVertexArray(GLuint id); |