VERY experimental Nintendo Switch 2 emulator
C++
gl_rasterizer: Move code to bind framebuffer surfaces before draw to its own function.
bunnei12a6c7b11b0a
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cppindex d83c38cf8b..911890f16c 100644--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp@@ -263,28 +263,7 @@ void RasterizerOpenGL::DrawArrays() {surfaces_rect.bottom, surfaces_rect.top))}; // Bottom// Bind the framebuffer surfaces- state.draw.draw_framebuffer = framebuffer.handle;- state.Apply();-- glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,- color_surface != nullptr ? color_surface->texture.handle : 0, 0);- if (depth_surface != nullptr) {- if (has_stencil) {- // attach both depth and stencil- glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D,- depth_surface->texture.handle, 0);- } else {- // attach depth- glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,- depth_surface->texture.handle, 0);- // clear stencil attachment- glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);- }- } else {- // clear both depth and stencil attachment- glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0,- 0);- }+ BindFramebufferSurfaces(color_surface, depth_surface, has_stencil);// Sync the viewportSyncViewport(surfaces_rect, res_scale);@@ -530,6 +509,32 @@ void main() {}}+void RasterizerOpenGL::BindFramebufferSurfaces(const Surface& color_surface,+ const Surface& depth_surface, bool has_stencil) {+ state.draw.draw_framebuffer = framebuffer.handle;+ state.Apply();++ glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,+ color_surface != nullptr ? color_surface->texture.handle : 0, 0);+ if (depth_surface != nullptr) {+ if (has_stencil) {+ // attach both depth and stencil+ glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D,+ depth_surface->texture.handle, 0);+ } else {+ // attach depth+ glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D,+ depth_surface->texture.handle, 0);+ // clear stencil attachment+ glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);+ }+ } else {+ // clear both depth and stencil attachment+ glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0,+ 0);+ }+}+void RasterizerOpenGL::SyncViewport(const MathUtil::Rectangle<u32>& surfaces_rect, u16 res_scale) {const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs;const MathUtil::Rectangle<s32> viewport_rect{regs.viewport[0].GetRect()};diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.hindex 1cd46c96a2..fd53e94cdd 100644--- a/src/video_core/renderer_opengl/gl_rasterizer.h+++ b/src/video_core/renderer_opengl/gl_rasterizer.h@@ -87,6 +87,10 @@ public:private:struct SamplerInfo {};+ /// Binds the framebuffer color and depth surface+ void BindFramebufferSurfaces(const Surface& color_surface, const Surface& depth_surface,+ bool has_stencil);+/// Syncs the viewport to match the guest statevoid SyncViewport(const MathUtil::Rectangle<u32>& surfaces_rect, u16 res_scale);