diff options
Diffstat (limited to '')
-rw-r--r-- | src/video_core/rasterizer.cpp | 13 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 9 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 7 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 26 |
4 files changed, 27 insertions, 28 deletions
diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp index 226fad783..ecfdbc9e8 100644 --- a/src/video_core/rasterizer.cpp +++ b/src/video_core/rasterizer.cpp @@ -498,7 +498,8 @@ static void ProcessTriangleInternal(const Shader::OutputVertex& v0, // with some basic arithmetic. Alpha combiners can be configured separately but work // analogously. Math::Vec4<u8> combiner_output; - Math::Vec4<u8> combiner_buffer = { + Math::Vec4<u8> combiner_buffer = {0, 0, 0, 0}; + Math::Vec4<u8> next_combiner_buffer = { regs.tev_combiner_buffer_color.r, regs.tev_combiner_buffer_color.g, regs.tev_combiner_buffer_color.b, regs.tev_combiner_buffer_color.a }; @@ -747,14 +748,16 @@ static void ProcessTriangleInternal(const Shader::OutputVertex& v0, combiner_output[2] = std::min((unsigned)255, color_output.b() * tev_stage.GetColorMultiplier()); combiner_output[3] = std::min((unsigned)255, alpha_output * tev_stage.GetAlphaMultiplier()); + combiner_buffer = next_combiner_buffer; + if (regs.tev_combiner_buffer_input.TevStageUpdatesCombinerBufferColor(tev_stage_index)) { - combiner_buffer.r() = combiner_output.r(); - combiner_buffer.g() = combiner_output.g(); - combiner_buffer.b() = combiner_output.b(); + next_combiner_buffer.r() = combiner_output.r(); + next_combiner_buffer.g() = combiner_output.g(); + next_combiner_buffer.b() = combiner_output.b(); } if (regs.tev_combiner_buffer_input.TevStageUpdatesCombinerBufferAlpha(tev_stage_index)) { - combiner_buffer.a() = combiner_output.a(); + next_combiner_buffer.a() = combiner_output.a(); } } diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 9b4bddabd..822739088 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -492,9 +492,12 @@ void RasterizerOpenGL::SetShader() { state.Apply(); // Set the texture samplers to correspond to different texture units - glUniform1i(PicaShader::Uniform::Texture0, 0); - glUniform1i(PicaShader::Uniform::Texture1, 1); - glUniform1i(PicaShader::Uniform::Texture2, 2); + GLuint uniform_tex = glGetUniformLocation(shader->shader.handle, "tex[0]"); + if (uniform_tex != -1) { glUniform1i(uniform_tex, 0); } + uniform_tex = glGetUniformLocation(shader->shader.handle, "tex[1]"); + if (uniform_tex != -1) { glUniform1i(uniform_tex, 1); } + uniform_tex = glGetUniformLocation(shader->shader.handle, "tex[2]"); + if (uniform_tex != -1) { glUniform1i(uniform_tex, 2); } current_shader = shader_cache.emplace(config, std::move(shader)).first->second.get(); diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 071051dbc..5ba898189 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -138,13 +138,6 @@ public: struct PicaShader { /// OpenGL shader resource OGLShader shader; - - /// Fragment shader uniforms - enum Uniform : GLuint { - Texture0 = 0, - Texture1 = 1, - Texture2 = 2, - }; }; private: diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 3f1cf7a6f..498c506e7 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -311,18 +311,18 @@ static void WriteTevStage(std::string& out, const PicaShaderConfig& config, unsi "clamp(alpha_output_" + index_name + " * " + std::to_string(stage.GetAlphaMultiplier()) + ".0, 0.0, 1.0));\n"; } + out += "combiner_buffer = next_combiner_buffer;\n"; + if (config.TevStageUpdatesCombinerBufferColor(index)) - out += "combiner_buffer.rgb = last_tex_env_out.rgb;\n"; + out += "next_combiner_buffer.rgb = last_tex_env_out.rgb;\n"; if (config.TevStageUpdatesCombinerBufferAlpha(index)) - out += "combiner_buffer.a = last_tex_env_out.a;\n"; + out += "next_combiner_buffer.a = last_tex_env_out.a;\n"; } std::string GenerateFragmentShader(const PicaShaderConfig& config) { std::string out = R"( -#version 330 -#extension GL_ARB_explicit_uniform_location : require - +#version 330 core #define NUM_TEV_STAGES 6 in vec4 primary_color; @@ -336,14 +336,10 @@ layout (std140) uniform shader_data { int alphatest_ref; }; -)"; +uniform sampler2D tex[3]; - using Uniform = RasterizerOpenGL::PicaShader::Uniform; - out += "layout(location = " + std::to_string((int)Uniform::Texture0) + ") uniform sampler2D tex[3];\n"; - - out += "void main() {\n"; - out += "vec4 combiner_buffer = tev_combiner_buffer_color;\n"; - out += "vec4 last_tex_env_out = vec4(0.0);\n"; +void main() { +)"; // Do not do any sort of processing if it's obvious we're not going to pass the alpha test if (config.alpha_test_func == Regs::CompareFunc::Never) { @@ -351,6 +347,10 @@ layout (std140) uniform shader_data { return out; } + out += "vec4 combiner_buffer = vec4(0.0);\n"; + out += "vec4 next_combiner_buffer = tev_combiner_buffer_color;\n"; + out += "vec4 last_tex_env_out = vec4(0.0);\n"; + for (size_t index = 0; index < config.tev_stages.size(); ++index) WriteTevStage(out, config, (unsigned)index); @@ -366,7 +366,7 @@ layout (std140) uniform shader_data { } std::string GenerateVertexShader() { - std::string out = "#version 330\n"; + std::string out = "#version 330 core\n"; out += "layout(location = " + std::to_string((int)ATTRIBUTE_POSITION) + ") in vec4 vert_position;\n"; out += "layout(location = " + std::to_string((int)ATTRIBUTE_COLOR) + ") in vec4 vert_color;\n"; out += "layout(location = " + std::to_string((int)ATTRIBUTE_TEXCOORD0) + ") in vec2 vert_texcoord0;\n"; |