GRAPHICS: Disable extra attributes bound by a previous shader [OpenGLS]
When switching between shaders, the previous shader might have Y attributes, while the current shader only has X, with X < Y. The extra attributes will not be used by the shader, but the driver might attempt to read from the bound FBOs anyway. OSX's OpenGL profiler stumbles over this.
This commit is contained in:
parent
11ca8cca47
commit
a051070b78
1 changed files with 11 additions and 1 deletions
|
@ -161,10 +161,20 @@ Shader *Shader::fromFiles(const char *vertex, const char *fragment, const char *
|
|||
}
|
||||
|
||||
void Shader::use(bool forceReload) {
|
||||
static Shader *previousShader = NULL;
|
||||
static Shader *previousShader = nullptr;
|
||||
static uint32 previousNumAttributes = 0;
|
||||
if (this == previousShader && !forceReload)
|
||||
return;
|
||||
|
||||
// The previous shader might have had more attributes. Disable any extra ones.
|
||||
if (_attributes.size() < previousNumAttributes) {
|
||||
for (uint32 i = _attributes.size(); i < previousNumAttributes; ++i) {
|
||||
glDisableVertexAttribArray(i);
|
||||
}
|
||||
}
|
||||
|
||||
previousShader = this;
|
||||
previousNumAttributes = _attributes.size();
|
||||
|
||||
glUseProgram(*_shaderNo);
|
||||
for (uint32 i = 0; i < _attributes.size(); ++i) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue