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.
This commit is contained in:
Sergey Sharybin 2022-10-20 10:09:32 +02:00
parent 90686ff6f4
commit ff157d7eba
2 changed files with 10 additions and 5 deletions

View File

@ -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;
}

View File

@ -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()