[Bf-blender-cvs] [26f25b1b27b] blender2.8: OpenGL: use ShaderInterface to look up uniforms

Mike Erwin noreply at git.blender.org
Fri Apr 14 01:18:18 CEST 2017


Commit: 26f25b1b27bd850b0e6cd1bfc045fcfd41f1ba3b
Author: Mike Erwin
Date:   Thu Apr 13 18:37:26 2017 -0400
Branches: blender2.8
https://developer.blender.org/rB26f25b1b27bd850b0e6cd1bfc045fcfd41f1ba3b

OpenGL: use ShaderInterface to look up uniforms

These were the last few glGetUniformLocation calls in source/blender.

The new system gets uniform information once when a shader is created, then uses this cached info every time after that.

===================================================================

M	source/blender/gpu/intern/gpu_shader.c

===================================================================

diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index fa63dff1458..2a0e434537f 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -467,21 +467,21 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
 		return NULL;
 	}
 
+	shader->interface = ShaderInterface_create(shader->program);
+
 #ifdef WITH_OPENSUBDIV
 	/* TODO(sergey): Find a better place for this. */
 	if (use_opensubdiv && GLEW_VERSION_4_1) {
 		glProgramUniform1i(shader->program,
-		                   glGetUniformLocation(shader->program, "FVarDataOffsetBuffer"),
+		                   ShaderInterface_uniform(shader->interface, "FVarDataOffsetBuffer")->location,
 		                   30);  /* GL_TEXTURE30 */
 
 		glProgramUniform1i(shader->program,
-		                   glGetUniformLocation(shader->program, "FVarDataBuffer"),
+		                   ShaderInterface_uniform(shader->interface, "FVarDataBuffer")->location,
 		                   31);  /* GL_TEXTURE31 */
 	}
 #endif
 
-	shader->interface = ShaderInterface_create(shader->program);
-
 	return shader;
 }
 
@@ -523,8 +523,8 @@ void GPU_shader_free(GPUShader *shader)
 int GPU_shader_get_uniform(GPUShader *shader, const char *name)
 {
 	BLI_assert(shader && shader->program);
-
-	return glGetUniformLocation(shader->program, name);
+	const ShaderInput *uniform = ShaderInterface_uniform(shader->interface, name);
+	return uniform ? uniform->location : -1;
 }
 
 int GPU_shader_get_uniform_block(GPUShader *shader, const char *name)




More information about the Bf-blender-cvs mailing list