summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2018-07-04 01:34:34 +0200
committerGitHub <noreply@github.com>2018-07-04 01:34:34 +0200
commitc996787d8433f8bd3603957594ac15b0f075fd86 (patch)
treedaf350f31f619f5321f73a262f1936c92b01d7dd /src/video_core/renderer_opengl
parentMerge pull request #616 from bunnei/s8z24 (diff)
parentGPU: Factor out the framebuffer configuration code for both Clear and Draw commands. (diff)
downloadyuzu-c996787d8433f8bd3603957594ac15b0f075fd86.tar
yuzu-c996787d8433f8bd3603957594ac15b0f075fd86.tar.gz
yuzu-c996787d8433f8bd3603957594ac15b0f075fd86.tar.bz2
yuzu-c996787d8433f8bd3603957594ac15b0f075fd86.tar.lz
yuzu-c996787d8433f8bd3603957594ac15b0f075fd86.tar.xz
yuzu-c996787d8433f8bd3603957594ac15b0f075fd86.tar.zst
yuzu-c996787d8433f8bd3603957594ac15b0f075fd86.zip
Diffstat (limited to 'src/video_core/renderer_opengl')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp71
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h6
2 files changed, 63 insertions, 14 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index c7b7a5817..43dbf4da9 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -297,11 +297,7 @@ bool RasterizerOpenGL::AccelerateDrawBatch(bool is_indexed) {
return true;
}
-void RasterizerOpenGL::DrawArrays() {
- if (accelerate_draw == AccelDraw::Disabled)
- return;
-
- MICROPROFILE_SCOPE(OpenGL_Drawing);
+std::pair<Surface, Surface> RasterizerOpenGL::ConfigureFramebuffers() {
const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs;
// Sync the depth test state before configuring the framebuffer surfaces.
@@ -344,11 +340,6 @@ void RasterizerOpenGL::DrawArrays() {
BindFramebufferSurfaces(color_surface, depth_surface, has_stencil);
SyncViewport(surfaces_rect);
- SyncBlendState();
- SyncCullMode();
-
- // TODO(bunnei): Sync framebuffer_scale uniform here
- // TODO(bunnei): Sync scissorbox uniform(s) here
// Viewport can have negative offsets or larger dimensions than our framebuffer sub-rect. Enable
// scissor test to prevent drawing outside of the framebuffer region
@@ -359,6 +350,58 @@ void RasterizerOpenGL::DrawArrays() {
state.scissor.height = draw_rect.GetHeight();
state.Apply();
+ // Only return the surface to be marked as dirty if writing to it is enabled.
+ return std::make_pair(write_color_fb ? color_surface : nullptr,
+ write_depth_fb ? depth_surface : nullptr);
+}
+
+void RasterizerOpenGL::Clear() {
+ const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs;
+
+ GLbitfield clear_mask = 0;
+ if (regs.clear_buffers.R && regs.clear_buffers.G && regs.clear_buffers.B &&
+ regs.clear_buffers.A) {
+ clear_mask |= GL_COLOR_BUFFER_BIT;
+ }
+ if (regs.clear_buffers.Z)
+ clear_mask |= GL_DEPTH_BUFFER_BIT;
+
+ if (clear_mask == 0)
+ return;
+
+ auto [dirty_color_surface, dirty_depth_surface] = ConfigureFramebuffers();
+
+ // TODO(Subv): Support clearing only partial colors.
+ glClearColor(regs.clear_color[0], regs.clear_color[1], regs.clear_color[2],
+ regs.clear_color[3]);
+ glClearDepth(regs.clear_depth);
+
+ glClear(clear_mask);
+
+ // Mark framebuffer surfaces as dirty
+ if (dirty_color_surface != nullptr) {
+ res_cache.MarkSurfaceAsDirty(dirty_color_surface);
+ }
+ if (dirty_depth_surface != nullptr) {
+ res_cache.MarkSurfaceAsDirty(dirty_depth_surface);
+ }
+}
+
+void RasterizerOpenGL::DrawArrays() {
+ if (accelerate_draw == AccelDraw::Disabled)
+ return;
+
+ MICROPROFILE_SCOPE(OpenGL_Drawing);
+ const auto& regs = Core::System().GetInstance().GPU().Maxwell3D().regs;
+
+ auto [dirty_color_surface, dirty_depth_surface] = ConfigureFramebuffers();
+
+ SyncBlendState();
+ SyncCullMode();
+
+ // TODO(bunnei): Sync framebuffer_scale uniform here
+ // TODO(bunnei): Sync scissorbox uniform(s) here
+
// Draw the vertex batch
const bool is_indexed = accelerate_draw == AccelDraw::Indexed;
const u64 index_buffer_size{regs.index_array.count * regs.index_array.FormatSizeInBytes()};
@@ -439,11 +482,11 @@ void RasterizerOpenGL::DrawArrays() {
state.Apply();
// Mark framebuffer surfaces as dirty
- if (color_surface != nullptr && write_color_fb) {
- res_cache.MarkSurfaceAsDirty(color_surface);
+ if (dirty_color_surface != nullptr) {
+ res_cache.MarkSurfaceAsDirty(dirty_color_surface);
}
- if (depth_surface != nullptr && write_depth_fb) {
- res_cache.MarkSurfaceAsDirty(depth_surface);
+ if (dirty_depth_surface != nullptr) {
+ res_cache.MarkSurfaceAsDirty(dirty_depth_surface);
}
}
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 493aa39e5..7738f40b1 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -7,6 +7,7 @@
#include <array>
#include <cstddef>
#include <memory>
+#include <utility>
#include <vector>
#include <glad/glad.h>
#include "common/common_types.h"
@@ -28,6 +29,7 @@ public:
~RasterizerOpenGL() override;
void DrawArrays() override;
+ void Clear() override;
void NotifyMaxwellRegisterChanged(u32 method) override;
void FlushAll() override;
void FlushRegion(Tegra::GPUVAddr addr, u64 size) override;
@@ -81,6 +83,10 @@ private:
u32 border_color_a;
};
+ /// Configures the color and depth framebuffer states and returns the dirty <Color, Depth>
+ /// surfaces if writing was enabled.
+ std::pair<Surface, Surface> ConfigureFramebuffers();
+
/// Binds the framebuffer color and depth surface
void BindFramebufferSurfaces(const Surface& color_surface, const Surface& depth_surface,
bool has_stencil);