diff options
author | Jesse Talavera-Greenberg <jesse@jesse.tg> | 2023-11-09 15:54:51 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-09 21:54:51 +0100 |
commit | 4558be0d8eb79d276c89392b9410e6edb649db95 (patch) | |
tree | 3e2b37e31b38337adec64c5391e57ddf45af5d23 /src/GPU_OpenGL.cpp | |
parent | 88072a02c523e26390af6bd726608b3e567f996f (diff) |
Refactor the GPU to be object-oriented (#1873)
* Refactor GPU3D to be an object
- Who has two thumbs and is the sworn enemy of global state? This guy!
* Refactor GPU itself to be an object
- Wow, it's used in a lot of places
- Also introduce a new `Melon` namespace for a few classes
- I expect other classes will be moved into `Melon` over time
* Change signature of Renderer3D::SetRenderSettings
- Make it noexcept, and its argument const
* Remove some stray whitespace
Diffstat (limited to 'src/GPU_OpenGL.cpp')
-rw-r--r-- | src/GPU_OpenGL.cpp | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/GPU_OpenGL.cpp b/src/GPU_OpenGL.cpp index 32633a7..d0649bb 100644 --- a/src/GPU_OpenGL.cpp +++ b/src/GPU_OpenGL.cpp @@ -28,12 +28,12 @@ #include "OpenGLSupport.h" #include "GPU_OpenGL_shaders.h" -namespace GPU +namespace Melon { using namespace OpenGL; -std::unique_ptr<GLCompositor> GLCompositor::New() noexcept +std::unique_ptr<GLCompositor> GLCompositor::New(Melon::GPU& gpu) noexcept { assert(glBindAttribLocation != nullptr); @@ -50,10 +50,10 @@ std::unique_ptr<GLCompositor> GLCompositor::New() noexcept // if linking the shaders together failed. return nullptr; - return std::unique_ptr<GLCompositor>(new GLCompositor(CompShader)); + return std::unique_ptr<GLCompositor>(new GLCompositor(CompShader, gpu)); } -GLCompositor::GLCompositor(std::array<GLuint, 3> compShader) noexcept : CompShader(compShader) +GLCompositor::GLCompositor(std::array<GLuint, 3> compShader, Melon::GPU& gpu) noexcept : CompShader(compShader), GPU(gpu) { CompScaleLoc = glGetUniformLocation(CompShader[2], "u3DScale"); Comp3DXPosLoc = glGetUniformLocation(CompShader[2], "u3DXPos"); @@ -144,7 +144,7 @@ void GLCompositor::Reset() } -void GLCompositor::SetRenderSettings(RenderSettings& settings) +void GLCompositor::SetRenderSettings(const RenderSettings& settings) noexcept { int scale = settings.GL_ScaleFactor; @@ -174,7 +174,7 @@ void GLCompositor::Stop() { for (int i = 0; i < 2; i++) { - int frontbuf = GPU::FrontBuffer; + int frontbuf = GPU.FrontBuffer; glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, CompScreenOutputFB[frontbuf]); @@ -186,7 +186,7 @@ void GLCompositor::Stop() void GLCompositor::RenderFrame() { - int frontbuf = GPU::FrontBuffer; + int frontbuf = GPU.FrontBuffer; glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, CompScreenOutputFB[frontbuf]); @@ -204,21 +204,21 @@ void GLCompositor::RenderFrame() glUniform1ui(CompScaleLoc, Scale); // TODO: support setting this midframe, if ever needed - glUniform1i(Comp3DXPosLoc, ((int)GPU3D::RenderXPos << 23) >> 23); + glUniform1i(Comp3DXPosLoc, ((int)GPU.GPU3D.GetRenderXPos() << 23) >> 23); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, CompScreenInputTex); - if (GPU::Framebuffer[frontbuf][0] && GPU::Framebuffer[frontbuf][1]) + if (GPU.Framebuffer[frontbuf][0] && GPU.Framebuffer[frontbuf][1]) { glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256*3 + 1, 192, GL_RGBA_INTEGER, - GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][0]); + GL_UNSIGNED_BYTE, GPU.Framebuffer[frontbuf][0]); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 192, 256*3 + 1, 192, GL_RGBA_INTEGER, - GL_UNSIGNED_BYTE, GPU::Framebuffer[frontbuf][1]); + GL_UNSIGNED_BYTE, GPU.Framebuffer[frontbuf][1]); } glActiveTexture(GL_TEXTURE1); - reinterpret_cast<GPU3D::GLRenderer*>(GPU3D::CurrentRenderer.get())->SetupAccelFrame(); + reinterpret_cast<GPU3D::GLRenderer*>(GPU.GPU3D.GetCurrentRenderer())->SetupAccelFrame(); glBindBuffer(GL_ARRAY_BUFFER, CompVertexBufferID); glBindVertexArray(CompVertexArrayID); |