[Bf-blender-cvs] [4b0c2de] opensubdiv-modifier: OpenSubdiv: Use some hacks in order to make it easier to glue with GPU_material

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


Commit: 4b0c2def080af765e752e117634bed020f50b043
Author: Sergey Sharybin
Date:   Thu Jul 17 17:19:14 2014 +0600
https://developer.blender.org/rB4b0c2def080af765e752e117634bed020f50b043

OpenSubdiv: Use some hacks in order to make it easier to glue with GPU_material

The idea is to use older glsl version (namely 1.3, the same as used for bump
mapping) and require some extensions from newer GLSL in order to use geometry
shader.

This all should make it easier to glue up OpenSubdiv shaders with shaders from
GPU_material.

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

M	intern/opensubdiv/gpu_shader_opensubd_display.glsl
M	intern/opensubdiv/opensubdiv_gpu_capi.cc

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

diff --git a/intern/opensubdiv/gpu_shader_opensubd_display.glsl b/intern/opensubdiv/gpu_shader_opensubd_display.glsl
index 2d71d7a..631857e 100644
--- a/intern/opensubdiv/gpu_shader_opensubd_display.glsl
+++ b/intern/opensubdiv/gpu_shader_opensubd_display.glsl
@@ -25,7 +25,10 @@
 
 /* ***** Vertex shader ***** */
 
-#version 150
+#version 130
+#extension GL_EXT_geometry_shader4 : enable
+#extension GL_ARB_gpu_shader5 : enable
+#extension GL_ARB_explicit_attrib_location : require
 
 struct VertexData {
 	vec4 position;
@@ -56,12 +59,14 @@ void main()
 /* ***** geometry shader ***** */
 #ifdef GEOMETRY_SHADER
 
+#ifndef GLSL_COMPAT_WORKAROUND
 layout(lines_adjacency) in;
 #ifndef WIREFRAME
 layout(triangle_strip, max_vertices = 4) out;
 #else
 layout(line_strip, max_vertices = 8) out;
 #endif
+#endif
 
 uniform mat4 modelViewMatrix;
 uniform mat4 projectionMatrix;
diff --git a/intern/opensubdiv/opensubdiv_gpu_capi.cc b/intern/opensubdiv/opensubdiv_gpu_capi.cc
index d350f54..fe812e6 100644
--- a/intern/opensubdiv/opensubdiv_gpu_capi.cc
+++ b/intern/opensubdiv/opensubdiv_gpu_capi.cc
@@ -29,6 +29,11 @@
  *
  */
 
+/* Do some compatibility hacks in order to make
+ * the code working with GPU_material pipeline.
+ */
+#define GLSL_COMPAT_WORKAROUND
+
 #include "opensubdiv_capi.h"
 
 #ifdef _MSC_VER
@@ -187,7 +192,7 @@ GLuint compileShader(GLenum shaderType,
 {
 	const char *sources[3];
 	char sdefine[64];
-	sprintf(sdefine, "#define %s\n", section);
+	sprintf(sdefine, "#define %s\n#define GLSL_COMPAT_WORKAROUND\n", section);
 
 	sources[0] = define;
 	sources[1] = sdefine;
@@ -233,6 +238,31 @@ GLuint linkProgram(const char *define)
 	glBindAttribLocation(program, 0, "position");
 	glBindAttribLocation(program, 1, "normal");
 
+	glProgramParameteriEXT(program,
+	                       GL_GEOMETRY_INPUT_TYPE_EXT,
+	                       GL_LINES_ADJACENCY_EXT);
+
+#ifdef GLSL_COMPAT_WORKAROUND
+	if (strstr(define, "WIREFRAME") == NULL) {
+		glProgramParameteriEXT(program,
+		                       GL_GEOMETRY_OUTPUT_TYPE_EXT,
+		                       GL_TRIANGLE_STRIP);
+
+		glProgramParameteriEXT(program,
+		                       GL_GEOMETRY_VERTICES_OUT_EXT,
+		                       4);
+	}
+	else {
+		glProgramParameteriEXT(program,
+		                       GL_GEOMETRY_OUTPUT_TYPE_EXT,
+		                       GL_LINE_STRIP);
+
+		glProgramParameteriEXT(program,
+		                       GL_GEOMETRY_VERTICES_OUT_EXT,
+		                       8);
+	}
+#endif
+
 	glLinkProgram(program);
 
 	glDeleteShader(vertexShader);




More information about the Bf-blender-cvs mailing list