Browse Source

Eliminate redundant glActiveTexture calls when shaders are used.

The redundant calls were introduced with the previous commit.
Alex Szpakowski 5 years ago
parent
commit
8fac08809a

+ 4 - 4
src/modules/graphics/opengl/OpenGL.cpp

@@ -977,7 +977,7 @@ void OpenGL::setTextureUnit(int textureunit)
 	state.curTextureUnit = 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])
 	if (texture != state.boundTextures[target][textureunit])
 	{
 	{
@@ -993,14 +993,14 @@ void OpenGL::bindTextureToUnit(TextureType target, GLuint texture, int textureun
 		else
 		else
 			state.curTextureUnit = textureunit;
 			state.curTextureUnit = textureunit;
 	}
 	}
-	else if (!restoreprev && textureunit != state.curTextureUnit)
+	else if (bindforedit && !restoreprev && textureunit != state.curTextureUnit)
 	{
 	{
 		glActiveTexture(GL_TEXTURE0 + textureunit);
 		glActiveTexture(GL_TEXTURE0 + textureunit);
 		state.curTextureUnit = 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;
 	TextureType textype = TEXTURE_2D;
 	GLuint handle = 0;
 	GLuint handle = 0;
@@ -1022,7 +1022,7 @@ void OpenGL::bindTextureToUnit(Texture *texture, int textureunit, bool restorepr
 		handle = getDefaultTexture(textype);
 		handle = getDefaultTexture(textype);
 	}
 	}
 
 
-	bindTextureToUnit(textype, handle, textureunit, restoreprev);
+	bindTextureToUnit(textype, handle, textureunit, restoreprev, bindforedit);
 }
 }
 
 
 void OpenGL::deleteTexture(GLuint texture)
 void OpenGL::deleteTexture(GLuint texture)

+ 3 - 2
src/modules/graphics/opengl/OpenGL.h

@@ -324,9 +324,10 @@ public:
 	 *
 	 *
 	 * @param textureunit Index in the range of [0, maxtextureunits-1]
 	 * @param textureunit Index in the range of [0, maxtextureunits-1]
 	 * @param restoreprev Restore previously bound texture unit when done.
 	 * @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.
 	 * Helper for deleting an OpenGL texture.

+ 2 - 2
src/modules/graphics/opengl/Shader.cpp

@@ -451,7 +451,7 @@ void Shader::attach()
 		{
 		{
 			const TextureUnit &unit = textureUnits[i];
 			const TextureUnit &unit = textureUnits[i];
 			if (unit.active)
 			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.
 		// send any pending uniforms to the shader program.
@@ -647,7 +647,7 @@ void Shader::sendTextures(const UniformInfo *info, Texture **textures, int count
 		int texunit = info->ints[i];
 		int texunit = info->ints[i];
 
 
 		if (shaderactive)
 		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.
 		// Store texture id so it can be re-bound to the texture unit later.
 		textureUnits[texunit].texture = gltex;
 		textureUnits[texunit].texture = gltex;