diff options
author | Sergey Sharybin <sergey@blender.org> | 2022-10-20 11:09:32 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2022-10-20 11:09:32 +0300 |
commit | ff157d7ebadc39cd027cbc75e67267d78cf1c80a (patch) | |
tree | 4847f446fe4d509f4287b1779168b8dbf1b39977 /source/blender | |
parent | 90686ff6f47ef14e96d94b7ad32f63a7015ca1c8 (diff) |
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.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/gpu/opengl/gl_shader.cc | 5 | ||||
-rw-r--r-- | source/blender/gpu/opengl/gl_shader_interface.cc | 10 |
2 files changed, 10 insertions, 5 deletions
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() |