From f53dbafdae6b6ca8ab718d2299437df469441389 Mon Sep 17 00:00:00 2001 From: tfarley Date: Sun, 3 Jan 2016 15:46:54 -0800 Subject: hwrasterizer: Use depth offset --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 16 ++++++++++++++++ src/video_core/renderer_opengl/gl_rasterizer.h | 6 +++++- src/video_core/renderer_opengl/gl_shader_gen.cpp | 4 +++- 3 files changed, 24 insertions(+), 2 deletions(-) (limited to 'src/video_core') diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 092351dce..291ef737d 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -126,6 +126,7 @@ void RasterizerOpenGL::InitObjects() { void RasterizerOpenGL::Reset() { SyncCullMode(); + SyncDepthModifiers(); SyncBlendEnabled(); SyncBlendFuncs(); SyncBlendColor(); @@ -194,6 +195,12 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) { SyncCullMode(); break; + // Depth modifiers + case PICA_REG_INDEX(viewport_depth_range): + case PICA_REG_INDEX(viewport_depth_far_plane): + SyncDepthModifiers(); + break; + // Blending case PICA_REG_INDEX(output_merger.alphablend_enable): SyncBlendEnabled(); @@ -602,6 +609,15 @@ void RasterizerOpenGL::SyncCullMode() { } } +void RasterizerOpenGL::SyncDepthModifiers() { + float depth_scale = -Pica::float24::FromRawFloat24(Pica::g_state.regs.viewport_depth_range).ToFloat32(); + float depth_offset = Pica::float24::FromRawFloat24(Pica::g_state.regs.viewport_depth_far_plane).ToFloat32() / 2.0f; + + // TODO: Implement scale modifier + uniform_block_data.data.depth_offset = depth_offset; + uniform_block_data.dirty = true; +} + void RasterizerOpenGL::SyncBlendEnabled() { state.blend.enabled = (Pica::g_state.regs.output_merger.alphablend_enable == 1); } diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 92b1f812e..c8a2d8f16 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -197,7 +197,8 @@ private: std::array const_color[6]; std::array tev_combiner_buffer_color; GLint alphatest_ref; - INSERT_PADDING_BYTES(12); + GLfloat depth_offset; + INSERT_PADDING_BYTES(8); }; static_assert(sizeof(UniformData) == 0x80, "The size of the UniformData structure has changed, update the structure in the shader"); @@ -218,6 +219,9 @@ private: /// Syncs the cull mode to match the PICA register void SyncCullMode(); + /// Syncs the depth scale and offset to match the PICA registers + void SyncDepthModifiers(); + /// Syncs the blend enabled status to match the PICA register void SyncBlendEnabled(); diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 38de5d469..22022f7f4 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -334,6 +334,7 @@ layout (std140) uniform shader_data { vec4 const_color[NUM_TEV_STAGES]; vec4 tev_combiner_buffer_color; int alphatest_ref; + float depth_offset; }; uniform sampler2D tex[3]; @@ -360,7 +361,8 @@ void main() { out += ") discard;\n"; } - out += "color = last_tex_env_out;\n}"; + out += "color = last_tex_env_out;\n"; + out += "gl_FragDepth = gl_FragCoord.z + depth_offset;\n}"; return out; } -- cgit v1.2.3