summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl
diff options
context:
space:
mode:
authorSubv <subv2112@gmail.com>2015-12-02 19:23:51 +0100
committerYuri Kunde Schlesner <yuriks@yuriks.net>2016-06-28 06:14:13 +0200
commitf9be06b15f08cb559580e1d19b43158640a37d67 (patch)
tree9b20e75d7ef02e0feac2be0cb96843ebbb6814f8 /src/video_core/renderer_opengl
parentMerge pull request #1930 from scurest/superfluous-moves (diff)
downloadyuzu-f9be06b15f08cb559580e1d19b43158640a37d67.tar
yuzu-f9be06b15f08cb559580e1d19b43158640a37d67.tar.gz
yuzu-f9be06b15f08cb559580e1d19b43158640a37d67.tar.bz2
yuzu-f9be06b15f08cb559580e1d19b43158640a37d67.tar.lz
yuzu-f9be06b15f08cb559580e1d19b43158640a37d67.tar.xz
yuzu-f9be06b15f08cb559580e1d19b43158640a37d67.tar.zst
yuzu-f9be06b15f08cb559580e1d19b43158640a37d67.zip
Diffstat (limited to 'src/video_core/renderer_opengl')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp26
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h12
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp16
3 files changed, 53 insertions, 1 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 328a4f66b..14ee97d57 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -353,6 +353,15 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) {
SyncColorWriteMask();
break;
+ // Scissor test
+ case PICA_REG_INDEX(scissor_test.mode):
+ shader_dirty = true;
+ break;
+ case PICA_REG_INDEX(scissor_test.right):
+ case PICA_REG_INDEX(scissor_test.left_minus_1):
+ SyncScissorTest();
+ break;
+
// Logic op
case PICA_REG_INDEX(output_merger.logic_op):
SyncLogicOp();
@@ -1002,6 +1011,7 @@ void RasterizerOpenGL::SetShader() {
SyncDepthOffset();
SyncAlphaTest();
SyncCombinerColor();
+ SyncScissorTest();
auto& tev_stages = Pica::g_state.regs.GetTevStages();
for (int index = 0; index < tev_stages.size(); ++index)
SyncTevConstColor(index, tev_stages[index]);
@@ -1166,6 +1176,22 @@ void RasterizerOpenGL::SyncDepthTest() {
PicaToGL::CompareFunc(regs.output_merger.depth_test_func) : GL_ALWAYS;
}
+void RasterizerOpenGL::SyncScissorTest() {
+ const auto& regs = Pica::g_state.regs;
+
+ if (uniform_block_data.data.scissor_right != regs.scissor_test.right ||
+ uniform_block_data.data.scissor_bottom != regs.scissor_test.bottom ||
+ uniform_block_data.data.scissor_left != regs.scissor_test.GetLeft() ||
+ uniform_block_data.data.scissor_top != regs.scissor_test.GetTop()) {
+
+ uniform_block_data.data.scissor_right = regs.scissor_test.right;
+ uniform_block_data.data.scissor_bottom = regs.scissor_test.bottom;
+ uniform_block_data.data.scissor_left = regs.scissor_test.GetLeft();
+ uniform_block_data.data.scissor_top = regs.scissor_test.GetTop();
+ uniform_block_data.dirty = true;
+ }
+}
+
void RasterizerOpenGL::SyncCombinerColor() {
auto combiner_color = PicaToGL::ColorRGBA8(Pica::g_state.regs.tev_combiner_buffer_color.raw);
if (combiner_color != uniform_block_data.data.tev_combiner_buffer_color) {
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 42482df4b..193c10291 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -56,6 +56,8 @@ union PicaShaderConfig {
const auto& regs = Pica::g_state.regs;
+ state.scissor_test_mode = regs.scissor_test.mode;
+
state.depthmap_enable = regs.depthmap_enable;
state.alpha_test_func = regs.output_merger.alpha_test.enable ?
@@ -172,6 +174,7 @@ union PicaShaderConfig {
struct State {
Pica::Regs::CompareFunc alpha_test_func;
+ Pica::Regs::ScissorMode scissor_test_mode;
Pica::Regs::TextureConfig::TextureType texture0_type;
std::array<TevStageConfigRaw, 6> tev_stages;
u8 combiner_buffer_input;
@@ -328,6 +331,10 @@ private:
GLint alphatest_ref;
GLfloat depth_scale;
GLfloat depth_offset;
+ GLint scissor_right;
+ GLint scissor_bottom;
+ GLint scissor_left;
+ GLint scissor_top;
alignas(16) GLvec3 fog_color;
alignas(16) GLvec3 lighting_global_ambient;
LightSrc light_src[8];
@@ -335,7 +342,7 @@ private:
alignas(16) GLvec4 tev_combiner_buffer_color;
};
- static_assert(sizeof(UniformData) == 0x3A0, "The size of the UniformData structure has changed, update the structure in the shader");
+ static_assert(sizeof(UniformData) == 0x3B0, "The size of the UniformData structure has changed, update the structure in the shader");
static_assert(sizeof(UniformData) < 16384, "UniformData structure must be less than 16kb as per the OpenGL spec");
/// Sets the OpenGL shader in accordance with the current PICA register state
@@ -384,6 +391,9 @@ private:
/// Syncs the depth test states to match the PICA register
void SyncDepthTest();
+ /// Syncs the scissor test state to match the PICA register
+ void SyncScissorTest();
+
/// Syncs the TEV combiner color buffer to match the PICA register
void SyncCombinerColor();
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index 3bace7f01..10bb44210 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -539,6 +539,8 @@ in float texcoord0_w;
in vec4 normquat;
in vec3 view;
+in vec4 gl_FragCoord;
+
out vec4 color;
struct LightSrc {
@@ -555,6 +557,10 @@ layout (std140) uniform shader_data {
int alphatest_ref;
float depth_scale;
float depth_offset;
+ int scissor_right;
+ int scissor_bottom;
+ int scissor_left;
+ int scissor_top;
vec3 fog_color;
vec3 lighting_global_ambient;
LightSrc light_src[NUM_LIGHTS];
@@ -582,6 +588,16 @@ vec4 secondary_fragment_color = vec4(0.0);
return out;
}
+ // Append the scissor test
+ if (state.scissor_test_mode == Regs::ScissorMode::Include || state.scissor_test_mode == Regs::ScissorMode::Exclude) {
+ out += "if (scissor_left <= scissor_right || scissor_top <= scissor_bottom) discard;\n";
+ out += "if (";
+ // Negate the condition if we have to keep only the pixels outside the scissor box
+ if (state.scissor_test_mode == Regs::ScissorMode::Include)
+ out += "!";
+ out += "(gl_FragCoord.x >= scissor_right && gl_FragCoord.x <= scissor_left && gl_FragCoord.y >= scissor_bottom && gl_FragCoord.y <= scissor_top)) discard;\n";
+ }
+
out += "float z_over_w = 1.0 - gl_FragCoord.z * 2.0;\n";
out += "float depth = z_over_w * depth_scale + depth_offset;\n";
if (state.depthmap_enable == Pica::Regs::DepthBuffering::WBuffering) {