From ff157d7ebadc39cd027cbc75e67267d78cf1c80a Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 20 Oct 2022 10:09:32 +0200 Subject: 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. --- source/blender/gpu/opengl/gl_shader.cc | 5 ----- source/blender/gpu/opengl/gl_shader_interface.cc | 10 ++++++++++ 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'source/blender') 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() -- cgit v1.2.3