diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index 273131ff3..792523234 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -988,7 +988,7 @@ void OpenGL::setTextureUnit(int textureunit) state.curTextureUnit = textureunit; } -void OpenGL::bindTextureToUnit(TextureType target, GLuint texture, int textureunit, bool restoreprev) +void OpenGL::bindTextureToUnit(TextureType target, GLuint texture, int textureunit, bool restoreprev, bool bindforedit) { if (texture != state.boundTextures[target][textureunit]) { @@ -1004,14 +1004,14 @@ void OpenGL::bindTextureToUnit(TextureType target, GLuint texture, int textureun else state.curTextureUnit = textureunit; } - else if (!restoreprev && textureunit != state.curTextureUnit) + else if (bindforedit && !restoreprev && textureunit != state.curTextureUnit) { glActiveTexture(GL_TEXTURE0 + textureunit); state.curTextureUnit = textureunit; } } -void OpenGL::bindTextureToUnit(Texture *texture, int textureunit, bool restoreprev) +void OpenGL::bindTextureToUnit(Texture *texture, int textureunit, bool restoreprev, bool bindforedit) { TextureType textype = TEXTURE_2D; GLuint handle = 0; @@ -1033,7 +1033,7 @@ void OpenGL::bindTextureToUnit(Texture *texture, int textureunit, bool restorepr handle = getDefaultTexture(textype); } - bindTextureToUnit(textype, handle, textureunit, restoreprev); + bindTextureToUnit(textype, handle, textureunit, restoreprev, bindforedit); } void OpenGL::deleteTexture(GLuint texture) diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index ad02098ff..13afd9c92 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -318,9 +318,10 @@ public: * * @param textureunit Index in the range of [0, maxtextureunits-1] * @param restoreprev Restore previously bound texture unit when done. + * @param bindforedit If false, the active texture unit may be left alone. **/ - void bindTextureToUnit(TextureType target, GLuint texture, int textureunit, bool restoreprev); - void bindTextureToUnit(Texture *texture, int textureunit, bool restoreprev); + void bindTextureToUnit(TextureType target, GLuint texture, int textureunit, bool restoreprev, bool bindforedit = true); + void bindTextureToUnit(Texture *texture, int textureunit, bool restoreprev, bool bindforedit = true); /** * Helper for deleting an OpenGL texture. diff --git a/src/modules/graphics/opengl/Shader.cpp b/src/modules/graphics/opengl/Shader.cpp index 84cef6f69..67a459d7b 100644 --- a/src/modules/graphics/opengl/Shader.cpp +++ b/src/modules/graphics/opengl/Shader.cpp @@ -439,7 +439,7 @@ void Shader::attach() { const TextureUnit &unit = textureUnits[i]; if (unit.active) - gl.bindTextureToUnit(unit.type, unit.texture, i, false); + gl.bindTextureToUnit(unit.type, unit.texture, i, false, false); } // send any pending uniforms to the shader program. @@ -636,7 +636,7 @@ void Shader::sendTextures(const UniformInfo *info, love::graphics::Texture **tex int texunit = info->ints[i]; if (shaderactive) - gl.bindTextureToUnit(info->textureType, gltex, texunit, false); + gl.bindTextureToUnit(info->textureType, gltex, texunit, false, false); // Store texture id so it can be re-bound to the texture unit later. textureUnits[texunit].texture = gltex;