[Bf-blender-cvs] [81653fa] opensubdiv-modifier: OpenSubdiv: Disable normals hack for legacy drawing

Sergey Sharybin noreply at git.blender.org
Tue Jul 8 12:13:10 CEST 2014


Commit: 81653fa1bc4359090fbf15ecdbc8887cc4f4a271
Author: Sergey Sharybin
Date:   Mon Jul 7 21:47:11 2014 +0600
https://developer.blender.org/rB81653fa1bc4359090fbf15ecdbc8887cc4f4a271

OpenSubdiv: Disable normals hack for legacy drawing

Such a mix of GLSL and legacy drawing was rather a huge PITA
to experiment with the new functionality. Since this only
gives wrong shading with flat shading (which isn't so common
and only really visible with simple subdivisions which are
to be redone anyway) let's do a clear separation for now.

We might end up bumping GLSL requirement for GPU tessellation
because of the some specific of how UV attributes are handled
by the OpenSubdiv. This is to be evaluated later.

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

M	intern/opensubdiv/opensubdiv_gpu_capi.cc

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

diff --git a/intern/opensubdiv/opensubdiv_gpu_capi.cc b/intern/opensubdiv/opensubdiv_gpu_capi.cc
index bd79ce2..ec8a2b5 100644
--- a/intern/opensubdiv/opensubdiv_gpu_capi.cc
+++ b/intern/opensubdiv/opensubdiv_gpu_capi.cc
@@ -47,6 +47,7 @@ using OpenSubdiv::OsdGLMeshInterface;
 
 extern "C" char datatoc_gpu_shader_opensubd_display_glsl[];
 
+#ifndef OPENSUBDIV_LEGACY_DRAW
 static GLuint compileShader(GLenum shaderType,
                             const char *section,
                             const char *define)
@@ -80,8 +81,12 @@ static GLuint compileShader(GLenum shaderType,
 
 static GLuint linkProgram(const char *define)
 {
-	GLuint vertexShader = compileShader(GL_VERTEX_SHADER, "VERTEX_SHADER", define);
-	GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER, "FRAGMENT_SHADER", define);
+	GLuint vertexShader = compileShader(GL_VERTEX_SHADER,
+	                                    "VERTEX_SHADER",
+	                                    define);
+	GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER,
+	                                      "FRAGMENT_SHADER",
+	                                      define);
 
 	GLuint program = glCreateProgram();
 
@@ -108,24 +113,23 @@ static GLuint linkProgram(const char *define)
 
 	return program;
 }
+#endif
 
 void openSubdiv_osdGLMeshDisplay(OpenSubdiv_GLMesh *gl_mesh, int fill_quads)
 {
-	static GLuint flat_fill_program;
 #ifndef OPENSUBDIV_LEGACY_DRAW
+	static GLuint flat_fill_program;
 	static GLuint smooth_fill_program;
 	static GLuint wireframe_program;
-#endif
 	static bool need_init = true;
 
 	if (need_init) {
 		flat_fill_program = linkProgram("#define FLAT_SHADING\n");
-#ifndef OPENSUBDIV_LEGACY_DRAW
 		smooth_fill_program = linkProgram("#define SMOOTH_SHADING\n");
 		wireframe_program = linkProgram("#define WIREFRAME\n");
-#endif
 		need_init = false;
 	}
+#endif
 
 	OsdGLMeshInterface *mesh = (OsdGLMeshInterface *) gl_mesh->descriptor;
 
@@ -135,33 +139,30 @@ void openSubdiv_osdGLMeshDisplay(OpenSubdiv_GLMesh *gl_mesh, int fill_quads)
 	const OsdDrawContext::PatchArrayVector &patches =
 		mesh->GetDrawContext()->patchArrays;
 
-	if (!fill_quads) {
-		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
 #ifndef OPENSUBDIV_LEGACY_DRAW
-		/* TODO(sergey): For some reason this doesn't work on
-		 * my Intel card and gives random color instead of the
-		 * one set by glColor().
-		 */
-		glUseProgram(wireframe_program);
-#endif
-	}
-	else {
+	if (fill_quads) {
 		int model;
 		glGetIntegerv(GL_SHADE_MODEL, &model);
 		if (model == GL_FLAT) {
-			/* TODO(sergey): This is rather just to make stuff committable,
-			 * for sure either we'll find a proper solution for flat shading
-			 * without using GLSL or we'll always use GLSL and try to hook it
-			 * up to the GPU_material pipeline.
-			 */
 			glUseProgram(flat_fill_program);
 		}
-#ifndef OPENSUBDIV_LEGACY_DRAW
 		else {
 			glUseProgram(smooth_fill_program);
 		}
-#endif
 	}
+	else {
+		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+		/* TODO(sergey): For some reason this doesn't work on
+		 * my Intel card and gives random color instead of the
+		 * one set by glColor().
+		 */
+		glUseProgram(wireframe_program);
+	}
+#else
+	if (!fill_quads) {
+		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+	}
+#endif
 
 	for (int i = 0; i < (int)patches.size(); ++i) {
 		OpenSubdiv::OsdDrawContext::PatchArray const &patch = patches[i];




More information about the Bf-blender-cvs mailing list