[Bf-blender-cvs] [ff157d7ebad] master: Fix incorrect shader state after shader interface creation
Sergey Sharybin
noreply at git.blender.org
Thu Oct 20 10:13:59 CEST 2022
Commit: ff157d7ebadc39cd027cbc75e67267d78cf1c80a
Author: Sergey Sharybin
Date: Thu Oct 20 10:09:32 2022 +0200
Branches: master
https://developer.blender.org/rBff157d7ebadc39cd027cbc75e67267d78cf1c80a
Fix incorrect shader state after shader interface creation
Use store-current-and-restore-previous OpenGL program in the OpenGL
Shader Interface. This is a better fix for the initial error, which
additionally solves interface artifacts when opening non-default
startyp files on macOS with AMD GPU.
===================================================================
M source/blender/gpu/opengl/gl_shader.cc
M source/blender/gpu/opengl/gl_shader_interface.cc
===================================================================
diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc
index f6f14932de7..dafcf4dbf33 100644
--- a/source/blender/gpu/opengl/gl_shader.cc
+++ b/source/blender/gpu/opengl/gl_shader.cc
@@ -1004,11 +1004,6 @@ bool GLShader::finalize(const shader::ShaderCreateInfo *info)
else {
interface = new GLShaderInterface(shader_program_);
}
- /**
- * WORKAROUND: Creating the shader interface changes the active program.
- * Make sure to update the context, otherwise we might have a missing bind.
- */
- Context::get()->shader = this;
return true;
}
diff --git a/source/blender/gpu/opengl/gl_shader_interface.cc b/source/blender/gpu/opengl/gl_shader_interface.cc
index c9432fca561..ef97d74bf81 100644
--- a/source/blender/gpu/opengl/gl_shader_interface.cc
+++ b/source/blender/gpu/opengl/gl_shader_interface.cc
@@ -200,6 +200,9 @@ static Type gpu_type_from_gl_type(int gl_type)
GLShaderInterface::GLShaderInterface(GLuint program)
{
+ GLuint last_program;
+ glGetIntegerv(GL_CURRENT_PROGRAM, (GLint *)&last_program);
+
/* Necessary to make #glUniform works. */
glUseProgram(program);
@@ -385,6 +388,8 @@ GLShaderInterface::GLShaderInterface(GLuint program)
// this->debug_print();
this->sort_inputs();
+
+ glUseProgram(last_program);
}
GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateInfo &info)
@@ -442,6 +447,9 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI
uint32_t name_buffer_offset = 0;
/* Necessary to make #glUniform works. TODO(fclem) Remove. */
+ GLuint last_program;
+ glGetIntegerv(GL_CURRENT_PROGRAM, (GLint *)&last_program);
+
glUseProgram(program);
/* Attributes */
@@ -552,6 +560,8 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI
this->sort_inputs();
// this->debug_print();
+
+ glUseProgram(last_program);
}
GLShaderInterface::~GLShaderInterface()
More information about the Bf-blender-cvs
mailing list