summaryrefslogtreecommitdiffstats
path: root/src/video_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp26
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp24
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.h12
3 files changed, 29 insertions, 33 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index e5fc6e8f5..0f8227f7b 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -885,18 +885,14 @@ u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader,
void RasterizerOpenGL::SetupAlphaTesting(Shader& shader) {
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
- glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingEnableLocation(),
- regs.alpha_test_enabled);
- glProgramUniform1f(shader->GetProgramHandle(), shader->GetAlphaTestingRefLocation(),
- regs.alpha_test_ref);
-
u32 func = static_cast<u32>(regs.alpha_test_func);
// Normalize the gl variants of opCompare to be the same as the normal variants
- if (func >= 0x200) {
- func = func - 0x200 + 1U;
+ u32 op = static_cast<u32>(Tegra::Engines::Maxwell3D::Regs::ComparisonOp::Never);
+ if (func >= op) {
+ func = func - op + 1U;
}
- glProgramUniform1ui(shader->GetProgramHandle(), shader->GetAlphaTestingFuncLocation(), func);
+ shader->SetAlphaTesting(regs.alpha_test_enabled == 1, regs.alpha_test_ref, func);
}
void RasterizerOpenGL::SyncViewport() {
@@ -1026,18 +1022,6 @@ void RasterizerOpenGL::SyncLogicOpState() {
state.logic_op.operation = MaxwellToGL::LogicOp(regs.logic_op.operation);
}
-<<<<<<< HEAD
-void RasterizerOpenGL::SyncAlphaTest() {
- const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
-
- // TODO(Rodrigo): Alpha testing is a legacy OpenGL feature, but it can be
- // implemented with a test+discard in fragment shaders.
- if (regs.alpha_test_enabled != 0) {
- LOG_CRITICAL(Render_OpenGL, "Alpha testing is not implemented");
- UNREACHABLE();
- }
-}
-
void RasterizerOpenGL::SyncScissorTest() {
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
@@ -1054,8 +1038,6 @@ void RasterizerOpenGL::SyncScissorTest() {
}
}
-=======
->>>>>>> Remove SyncAlphaTest and clang format
void RasterizerOpenGL::SyncTransformFeedback() {
const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs;
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index f4e99e5f4..ccb8b4805 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -94,6 +94,10 @@ CachedShader::CachedShader(VAddr addr, Maxwell::ShaderProgram program_type)
// Store shader's code to lazily build it on draw
geometry_programs.code = program_result.first;
}
+
+ if (program_type == Maxwell::ShaderProgram::Fragment) {
+ SaveAlphaTestingLocations();
+ }
}
GLuint CachedShader::GetProgramResourceIndex(const GLShader::ConstBufferEntry& buffer) {
@@ -134,16 +138,20 @@ GLuint CachedShader::LazyGeometryProgram(OGLProgram& target_program,
return target_program.handle;
};
-GLint CachedShader::GetAlphaTestingEnableLocation() {
- return glGetUniformLocation(program.handle, "alpha_testing_enable");
-}
-
-GLint CachedShader::GetAlphaTestingFuncLocation() {
- return glGetUniformLocation(program.handle, "alpha_testing_func");
+void CachedShader::SetAlphaTesting(const bool enable, const float ref, const u32 func) {
+ if (program_type == Maxwell::ShaderProgram::Fragment) {
+ glProgramUniform1ui(program.handle, alpha_test.enable_loc,
+ (enable ? 1 : 0));
+ glProgramUniform1f(program.handle, alpha_test.ref_loc,
+ ref);
+ glProgramUniform1ui(program.handle, alpha_test.func_loc, func);
+ }
}
-GLint CachedShader::GetAlphaTestingRefLocation() {
- return glGetUniformLocation(program.handle, "alpha_testing_ref");
+void CachedShader::SaveAlphaTestingLocations() {
+ alpha_test.enable_loc = glGetUniformLocation(program.handle, "alpha_testing_enable");
+ alpha_test.ref_loc = glGetUniformLocation(program.handle, "alpha_testing_ref");
+ alpha_test.func_loc = glGetUniformLocation(program.handle, "alpha_testing_func");
}
Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) {
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.h b/src/video_core/renderer_opengl/gl_shader_cache.h
index 2eaa63804..7c80ee86b 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.h
+++ b/src/video_core/renderer_opengl/gl_shader_cache.h
@@ -73,15 +73,15 @@ public:
/// Gets the GL uniform location for the specified resource, caching as needed
GLint GetUniformLocation(const GLShader::SamplerEntry& sampler);
- GLint GetAlphaTestingEnableLocation();
- GLint GetAlphaTestingFuncLocation();
- GLint GetAlphaTestingRefLocation();
+ void SetAlphaTesting(const bool enable, const float ref, const u32 func);
private:
/// Generates a geometry shader or returns one that already exists.
GLuint LazyGeometryProgram(OGLProgram& target_program, const std::string& glsl_topology,
const std::string& debug_name);
+ void SaveAlphaTestingLocations();
+
VAddr addr;
Maxwell::ShaderProgram program_type;
GLShader::ShaderSetup setup;
@@ -102,6 +102,12 @@ private:
OGLProgram triangles_adjacency;
} geometry_programs;
+ struct {
+ GLint enable_loc;
+ GLint ref_loc;
+ GLint func_loc;
+ } alpha_test;
+
std::map<u32, GLuint> resource_cache;
std::map<u32, GLint> uniform_cache;
};