[Bf-blender-cvs] [e9ae6bd] opensubdiv-modifier: OpenSubdiv: Add bits needed for UV mapping support in GLSL shading

Sergey Sharybin noreply at git.blender.org
Thu Jul 17 20:11:44 CEST 2014


Commit: e9ae6bd19eb1e0c43c11cd788fc7cd97e9cb1ebd
Author: Sergey Sharybin
Date:   Fri Jul 18 00:04:45 2014 +0600
https://developer.blender.org/rBe9ae6bd19eb1e0c43c11cd788fc7cd97e9cb1ebd

OpenSubdiv: Add bits needed for UV mapping support in GLSL shading

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

M	intern/opensubdiv/opensubdiv_gpu_capi.cc
M	source/blender/gpu/intern/gpu_extensions.c

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

diff --git a/intern/opensubdiv/opensubdiv_gpu_capi.cc b/intern/opensubdiv/opensubdiv_gpu_capi.cc
index fe1e99d..2620489 100644
--- a/intern/opensubdiv/opensubdiv_gpu_capi.cc
+++ b/intern/opensubdiv/opensubdiv_gpu_capi.cc
@@ -291,7 +291,7 @@ GLuint linkProgram(const char *define)
 
 	glProgramUniform1i(program,
 	                   glGetUniformLocation(program, "FVarDataBuffer"),
-	                   4);  /* GL_TEXTURE4 */
+	                   31);  /* GL_TEXTURE31 */
 
 	return program;
 }
@@ -341,11 +341,12 @@ void bindProgram(PartitionedGLMeshInterface *mesh,
 		glUniform4fv(glGetUniformLocation(program, "diffuse"), 1, color);
 	}
 
-	/* Face-fertex data */
+	/* Face-vertex data */
 	if (mesh->GetDrawContext()->GetFvarDataTextureBuffer()) {
-		glActiveTexture(GL_TEXTURE4);
+		glActiveTexture(GL_TEXTURE31);
 		glBindTexture(GL_TEXTURE_BUFFER,
 		              mesh->GetDrawContext()->GetFvarDataTextureBuffer());
+		glActiveTexture(GL_TEXTURE0);
 	}
 }
 
@@ -420,8 +421,8 @@ void openSubdiv_osdGLMeshDisplayPrepare(int use_osd_glsl)
 static GLuint preapre_patchDraw(PartitionedGLMeshInterface *mesh,
                                 bool fill_quads)
 {
+	GLint program = 0;
 	if (!g_use_osd_glsl) {
-		GLint program;
 		glGetIntegerv(GL_CURRENT_PROGRAM, &program);
 		if (program) {
 			GLint model;
@@ -431,12 +432,19 @@ static GLuint preapre_patchDraw(PartitionedGLMeshInterface *mesh,
 			if (location != -1) {
 				glUniform1i(location, model == GL_FLAT);
 			}
+
+			/* Face-vertex data */
+			if (mesh->GetDrawContext()->GetFvarDataTextureBuffer()) {
+				glActiveTexture(GL_TEXTURE31);
+				glBindTexture(GL_TEXTURE_BUFFER,
+				              mesh->GetDrawContext()->GetFvarDataTextureBuffer());
+				glActiveTexture(GL_TEXTURE0);
+			}
+
 		}
 		return program;
 	}
 
-	GLuint program = 0;
-
 	program = g_smooth_fill_program;
 	if (fill_quads) {
 		int model;
@@ -485,7 +493,6 @@ static void finish_patchDraw(bool fill_quads)
 	glBindVertexArray(0);
 
 	if (g_use_osd_glsl) {
-		glActiveTexture(GL_TEXTURE0);
 		/* TODO(sergey): Store previously used program and roll back to it? */
 		glUseProgram(0);
 	}
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index 0d114a0..5b0db67 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -1410,7 +1410,6 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *geometrycode,
 		glProgramParameteriEXT(shader->object,
 		                       GL_GEOMETRY_VERTICES_OUT_EXT,
 		                       4);
-
 	}
 #endif
 
@@ -1426,6 +1425,15 @@ GPUShader *GPU_shader_create(const char *vertexcode, const char *geometrycode,
 		return NULL;
 	}
 
+#ifdef WITH_OPENSUBDIV
+	/* TODO(sergey): Find a better place for this. */
+	{
+		glProgramUniform1i(shader->object,
+		                   glGetUniformLocation(shader->object, "FVarDataBuffer"),
+		                   31);  /* GL_TEXTURE31 */
+	}
+#endif
+
 	return shader;
 }




More information about the Bf-blender-cvs mailing list