diff options
| author | 2015-07-26 16:37:33 -0400 | |
|---|---|---|
| committer | 2015-07-26 16:37:33 -0400 | |
| commit | e1a3fed6ff81a671132d7f009eff7ea46b707615 (patch) | |
| tree | 27c1c38f8aabb48976d84890b818d8baadfd0750 /src | |
| parent | Merge pull request #992 from yuriks/hot-path-debug (diff) | |
| parent | OpenGL: Make OpenGL object resource wrappers fully inline (diff) | |
| download | yuzu-e1a3fed6ff81a671132d7f009eff7ea46b707615.tar.gz yuzu-e1a3fed6ff81a671132d7f009eff7ea46b707615.tar.xz yuzu-e1a3fed6ff81a671132d7f009eff7ea46b707615.zip | |
Merge pull request #991 from yuriks/globjects
OpenGL: Make OpenGL object resource wrappers fully inline
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_resource_manager.cpp | 111 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_resource_manager.h | 110 |
3 files changed, 79 insertions, 143 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 5c7f4ae18..162108301 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt | |||
| @@ -2,7 +2,6 @@ set(SRCS | |||
| 2 | renderer_opengl/generated/gl_3_2_core.c | 2 | renderer_opengl/generated/gl_3_2_core.c |
| 3 | renderer_opengl/gl_rasterizer.cpp | 3 | renderer_opengl/gl_rasterizer.cpp |
| 4 | renderer_opengl/gl_rasterizer_cache.cpp | 4 | renderer_opengl/gl_rasterizer_cache.cpp |
| 5 | renderer_opengl/gl_resource_manager.cpp | ||
| 6 | renderer_opengl/gl_shader_util.cpp | 5 | renderer_opengl/gl_shader_util.cpp |
| 7 | renderer_opengl/gl_state.cpp | 6 | renderer_opengl/gl_state.cpp |
| 8 | renderer_opengl/renderer_opengl.cpp | 7 | renderer_opengl/renderer_opengl.cpp |
diff --git a/src/video_core/renderer_opengl/gl_resource_manager.cpp b/src/video_core/renderer_opengl/gl_resource_manager.cpp deleted file mode 100644 index 8f4ae28a4..000000000 --- a/src/video_core/renderer_opengl/gl_resource_manager.cpp +++ /dev/null | |||
| @@ -1,111 +0,0 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "video_core/renderer_opengl/gl_resource_manager.h" | ||
| 6 | #include "video_core/renderer_opengl/gl_shader_util.h" | ||
| 7 | |||
| 8 | // Textures | ||
| 9 | OGLTexture::OGLTexture() : handle(0) { | ||
| 10 | } | ||
| 11 | |||
| 12 | OGLTexture::~OGLTexture() { | ||
| 13 | Release(); | ||
| 14 | } | ||
| 15 | |||
| 16 | void OGLTexture::Create() { | ||
| 17 | if (handle != 0) { | ||
| 18 | return; | ||
| 19 | } | ||
| 20 | |||
| 21 | glGenTextures(1, &handle); | ||
| 22 | } | ||
| 23 | |||
| 24 | void OGLTexture::Release() { | ||
| 25 | glDeleteTextures(1, &handle); | ||
| 26 | handle = 0; | ||
| 27 | } | ||
| 28 | |||
| 29 | // Shaders | ||
| 30 | OGLShader::OGLShader() : handle(0) { | ||
| 31 | } | ||
| 32 | |||
| 33 | OGLShader::~OGLShader() { | ||
| 34 | Release(); | ||
| 35 | } | ||
| 36 | |||
| 37 | void OGLShader::Create(const char* vert_shader, const char* frag_shader) { | ||
| 38 | if (handle != 0) { | ||
| 39 | return; | ||
| 40 | } | ||
| 41 | |||
| 42 | handle = ShaderUtil::LoadShaders(vert_shader, frag_shader); | ||
| 43 | } | ||
| 44 | |||
| 45 | void OGLShader::Release() { | ||
| 46 | glDeleteProgram(handle); | ||
| 47 | handle = 0; | ||
| 48 | } | ||
| 49 | |||
| 50 | // Buffer objects | ||
| 51 | OGLBuffer::OGLBuffer() : handle(0) { | ||
| 52 | } | ||
| 53 | |||
| 54 | OGLBuffer::~OGLBuffer() { | ||
| 55 | Release(); | ||
| 56 | } | ||
| 57 | |||
| 58 | void OGLBuffer::Create() { | ||
| 59 | if (handle != 0) { | ||
| 60 | return; | ||
| 61 | } | ||
| 62 | |||
| 63 | glGenBuffers(1, &handle); | ||
| 64 | } | ||
| 65 | |||
| 66 | void OGLBuffer::Release() { | ||
| 67 | glDeleteBuffers(1, &handle); | ||
| 68 | handle = 0; | ||
| 69 | } | ||
| 70 | |||
| 71 | // Vertex array objects | ||
| 72 | OGLVertexArray::OGLVertexArray() : handle(0) { | ||
| 73 | } | ||
| 74 | |||
| 75 | OGLVertexArray::~OGLVertexArray() { | ||
| 76 | Release(); | ||
| 77 | } | ||
| 78 | |||
| 79 | void OGLVertexArray::Create() { | ||
| 80 | if (handle != 0) { | ||
| 81 | return; | ||
| 82 | } | ||
| 83 | |||
| 84 | glGenVertexArrays(1, &handle); | ||
| 85 | } | ||
| 86 | |||
| 87 | void OGLVertexArray::Release() { | ||
| 88 | glDeleteVertexArrays(1, &handle); | ||
| 89 | handle = 0; | ||
| 90 | } | ||
| 91 | |||
| 92 | // Framebuffers | ||
| 93 | OGLFramebuffer::OGLFramebuffer() : handle(0) { | ||
| 94 | } | ||
| 95 | |||
| 96 | OGLFramebuffer::~OGLFramebuffer() { | ||
| 97 | Release(); | ||
| 98 | } | ||
| 99 | |||
| 100 | void OGLFramebuffer::Create() { | ||
| 101 | if (handle != 0) { | ||
| 102 | return; | ||
| 103 | } | ||
| 104 | |||
| 105 | glGenFramebuffers(1, &handle); | ||
| 106 | } | ||
| 107 | |||
| 108 | void OGLFramebuffer::Release() { | ||
| 109 | glDeleteFramebuffers(1, &handle); | ||
| 110 | handle = 0; | ||
| 111 | } | ||
diff --git a/src/video_core/renderer_opengl/gl_resource_manager.h b/src/video_core/renderer_opengl/gl_resource_manager.h index 975720d0a..6f9dc012d 100644 --- a/src/video_core/renderer_opengl/gl_resource_manager.h +++ b/src/video_core/renderer_opengl/gl_resource_manager.h | |||
| @@ -4,76 +4,124 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <utility> | ||
| 8 | |||
| 7 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 8 | 10 | ||
| 9 | #include "generated/gl_3_2_core.h" | 11 | #include "video_core/renderer_opengl/generated/gl_3_2_core.h" |
| 12 | #include "video_core/renderer_opengl/gl_shader_util.h" | ||
| 10 | 13 | ||
| 11 | class OGLTexture : public NonCopyable { | 14 | class OGLTexture : private NonCopyable { |
| 12 | public: | 15 | public: |
| 13 | OGLTexture(); | 16 | OGLTexture() = default; |
| 14 | ~OGLTexture(); | 17 | OGLTexture(OGLTexture&& o) { std::swap(handle, o.handle); } |
| 18 | ~OGLTexture() { Release(); } | ||
| 19 | OGLTexture& operator=(OGLTexture&& o) { std::swap(handle, o.handle); return *this; } | ||
| 15 | 20 | ||
| 16 | /// Creates a new internal OpenGL resource and stores the handle | 21 | /// Creates a new internal OpenGL resource and stores the handle |
| 17 | void Create(); | 22 | void Create() { |
| 23 | if (handle != 0) return; | ||
| 24 | glGenTextures(1, &handle); | ||
| 25 | } | ||
| 18 | 26 | ||
| 19 | /// Deletes the internal OpenGL resource | 27 | /// Deletes the internal OpenGL resource |
| 20 | void Release(); | 28 | void Release() { |
| 29 | if (handle == 0) return; | ||
| 30 | glDeleteTextures(1, &handle); | ||
| 31 | handle = 0; | ||
| 32 | } | ||
| 21 | 33 | ||
| 22 | GLuint handle; | 34 | GLuint handle = 0; |
| 23 | }; | 35 | }; |
| 24 | 36 | ||
| 25 | class OGLShader : public NonCopyable { | 37 | class OGLShader : private NonCopyable { |
| 26 | public: | 38 | public: |
| 27 | OGLShader(); | 39 | OGLShader() = default; |
| 28 | ~OGLShader(); | 40 | OGLShader(OGLShader&& o) { std::swap(handle, o.handle); } |
| 41 | ~OGLShader() { Release(); } | ||
| 42 | OGLShader& operator=(OGLShader&& o) { std::swap(handle, o.handle); return *this; } | ||
| 29 | 43 | ||
| 30 | /// Creates a new internal OpenGL resource and stores the handle | 44 | /// Creates a new internal OpenGL resource and stores the handle |
| 31 | void Create(const char* vert_shader, const char* frag_shader); | 45 | void Create(const char* vert_shader, const char* frag_shader) { |
| 46 | if (handle != 0) return; | ||
| 47 | handle = ShaderUtil::LoadShaders(vert_shader, frag_shader); | ||
| 48 | } | ||
| 32 | 49 | ||
| 33 | /// Deletes the internal OpenGL resource | 50 | /// Deletes the internal OpenGL resource |
| 34 | void Release(); | 51 | void Release() { |
| 52 | if (handle == 0) return; | ||
| 53 | glDeleteProgram(handle); | ||
| 54 | handle = 0; | ||
| 55 | } | ||
| 35 | 56 | ||
| 36 | GLuint handle; | 57 | GLuint handle = 0; |
| 37 | }; | 58 | }; |
| 38 | 59 | ||
| 39 | class OGLBuffer : public NonCopyable { | 60 | class OGLBuffer : private NonCopyable { |
| 40 | public: | 61 | public: |
| 41 | OGLBuffer(); | 62 | OGLBuffer() = default; |
| 42 | ~OGLBuffer(); | 63 | OGLBuffer(OGLBuffer&& o) { std::swap(handle, o.handle); } |
| 64 | ~OGLBuffer() { Release(); } | ||
| 65 | OGLBuffer& operator=(OGLBuffer&& o) { std::swap(handle, o.handle); return *this; } | ||
| 43 | 66 | ||
| 44 | /// Creates a new internal OpenGL resource and stores the handle | 67 | /// Creates a new internal OpenGL resource and stores the handle |
| 45 | void Create(); | 68 | void Create() { |
| 69 | if (handle != 0) return; | ||
| 70 | glGenBuffers(1, &handle); | ||
| 71 | } | ||
| 46 | 72 | ||
| 47 | /// Deletes the internal OpenGL resource | 73 | /// Deletes the internal OpenGL resource |
| 48 | void Release(); | 74 | void Release() { |
| 75 | if (handle == 0) return; | ||
| 76 | glDeleteBuffers(1, &handle); | ||
| 77 | handle = 0; | ||
| 78 | } | ||
| 49 | 79 | ||
| 50 | GLuint handle; | 80 | GLuint handle = 0; |
| 51 | }; | 81 | }; |
| 52 | 82 | ||
| 53 | class OGLVertexArray : public NonCopyable { | 83 | class OGLVertexArray : private NonCopyable { |
| 54 | public: | 84 | public: |
| 55 | OGLVertexArray(); | 85 | OGLVertexArray() = default; |
| 56 | ~OGLVertexArray(); | 86 | OGLVertexArray(OGLVertexArray&& o) { std::swap(handle, o.handle); } |
| 87 | ~OGLVertexArray() { Release(); } | ||
| 88 | OGLVertexArray& operator=(OGLVertexArray&& o) { std::swap(handle, o.handle); return *this; } | ||
| 57 | 89 | ||
| 58 | /// Creates a new internal OpenGL resource and stores the handle | 90 | /// Creates a new internal OpenGL resource and stores the handle |
| 59 | void Create(); | 91 | void Create() { |
| 92 | if (handle != 0) return; | ||
| 93 | glGenVertexArrays(1, &handle); | ||
| 94 | } | ||
| 60 | 95 | ||
| 61 | /// Deletes the internal OpenGL resource | 96 | /// Deletes the internal OpenGL resource |
| 62 | void Release(); | 97 | void Release() { |
| 98 | if (handle == 0) return; | ||
| 99 | glDeleteVertexArrays(1, &handle); | ||
| 100 | handle = 0; | ||
| 101 | } | ||
| 63 | 102 | ||
| 64 | GLuint handle; | 103 | GLuint handle = 0; |
| 65 | }; | 104 | }; |
| 66 | 105 | ||
| 67 | class OGLFramebuffer : public NonCopyable { | 106 | class OGLFramebuffer : private NonCopyable { |
| 68 | public: | 107 | public: |
| 69 | OGLFramebuffer(); | 108 | OGLFramebuffer() = default; |
| 70 | ~OGLFramebuffer(); | 109 | OGLFramebuffer(OGLFramebuffer&& o) { std::swap(handle, o.handle); } |
| 110 | ~OGLFramebuffer() { Release(); } | ||
| 111 | OGLFramebuffer& operator=(OGLFramebuffer&& o) { std::swap(handle, o.handle); return *this; } | ||
| 71 | 112 | ||
| 72 | /// Creates a new internal OpenGL resource and stores the handle | 113 | /// Creates a new internal OpenGL resource and stores the handle |
| 73 | void Create(); | 114 | void Create() { |
| 115 | if (handle != 0) return; | ||
| 116 | glGenFramebuffers(1, &handle); | ||
| 117 | } | ||
| 74 | 118 | ||
| 75 | /// Deletes the internal OpenGL resource | 119 | /// Deletes the internal OpenGL resource |
| 76 | void Release(); | 120 | void Release() { |
| 121 | if (handle == 0) return; | ||
| 122 | glDeleteFramebuffers(1, &handle); | ||
| 123 | handle = 0; | ||
| 124 | } | ||
| 77 | 125 | ||
| 78 | GLuint handle; | 126 | GLuint handle = 0; |
| 79 | }; | 127 | }; |