[Bf-blender-cvs] [a048d5f] master: OpenSubdiv: refine OpenGL version & extension checks

Mike Erwin noreply at git.blender.org
Mon Dec 7 00:59:13 CET 2015


Commit: a048d5f945be217c0c3e90cb716bf6bb7c267097
Author: Mike Erwin
Date:   Sun Dec 6 18:47:58 2015 -0500
Branches: master
https://developer.blender.org/rBa048d5f945be217c0c3e90cb716bf6bb7c267097

OpenSubdiv: refine OpenGL version & extension checks

Use new GPU_legacy_support() function.

Determine GLSL version once instead of per shader.

For Texture Buffers, allow ARB or EXT version of the extension. Either
one will do.

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

M	intern/opensubdiv/gpu_shader_opensubd_display.glsl
M	intern/opensubdiv/opensubdiv_capi.cc
M	intern/opensubdiv/opensubdiv_capi.h
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 57bbfa8..51e8ed4 100644
--- a/intern/opensubdiv/gpu_shader_opensubd_display.glsl
+++ b/intern/opensubdiv/gpu_shader_opensubd_display.glsl
@@ -70,7 +70,8 @@ void main()
 
 #if __VERSION__ < 140
   #extension GL_ARB_uniform_buffer_object: require
-  #extension GL_ARB_texture_buffer_object: require
+  #extension GL_ARB_texture_buffer_object: enable
+  #extension GL_EXT_texture_buffer_object: enable
 #endif
 
 uniform mat4 modelViewMatrix;
diff --git a/intern/opensubdiv/opensubdiv_capi.cc b/intern/opensubdiv/opensubdiv_capi.cc
index f715bf3..6c226d6 100644
--- a/intern/opensubdiv/opensubdiv_capi.cc
+++ b/intern/opensubdiv/opensubdiv_capi.cc
@@ -296,8 +296,9 @@ const struct OpenSubdiv_TopologyRefinerDescr *openSubdiv_getGLMeshTopologyRefine
 int openSubdiv_supportGPUDisplay(void)
 {
 	// TODO: simplify extension check once Blender adopts GL 3.2
-	return (GLEW_VERSION_3_2 && GLEW_ARB_compatibility) ||
-	       (GLEW_VERSION_3_1 && GLEW_ARB_compatibility && GLEW_EXT_geometry_shader4) ||
-	       (GLEW_VERSION_3_0 && GLEW_EXT_geometry_shader4 && GLEW_ARB_uniform_buffer_object && GLEW_ARB_texture_buffer_object);
+	return GPU_legacy_support() &&
+	       (GLEW_VERSION_3_2 ||
+	       (GLEW_VERSION_3_1 && GLEW_EXT_geometry_shader4) ||
+	       (GLEW_VERSION_3_0 && GLEW_EXT_geometry_shader4 && GLEW_ARB_uniform_buffer_object && (GLEW_ARB_texture_buffer_object || GLEW_EXT_texture_buffer_object)));
 	/* also ARB_explicit_attrib_location? */
 }
diff --git a/intern/opensubdiv/opensubdiv_capi.h b/intern/opensubdiv/opensubdiv_capi.h
index 8010c39..9d1c1b3 100644
--- a/intern/opensubdiv/opensubdiv_capi.h
+++ b/intern/opensubdiv/opensubdiv_capi.h
@@ -144,6 +144,8 @@ int openSubdiv_getAvailableEvaluators(void);
 void openSubdiv_init(void);
 void openSubdiv_cleanup(void);
 
+extern bool GPU_legacy_support(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/intern/opensubdiv/opensubdiv_gpu_capi.cc b/intern/opensubdiv/opensubdiv_gpu_capi.cc
index fc46ad0..cbde06b 100644
--- a/intern/opensubdiv/opensubdiv_gpu_capi.cc
+++ b/intern/opensubdiv/opensubdiv_gpu_capi.cc
@@ -186,24 +186,12 @@ void transpose_m3(float mat[3][3])
 
 GLuint compileShader(GLenum shaderType,
                      const char *section,
+                     const char *version,
                      const char *define)
 {
 	char sdefine[64];
 	sprintf(sdefine, "#define %s\n", section);
 
-	const char *version;
-	if (GLEW_VERSION_3_2 && GLEW_ARB_compatibility) {
-		version = "#version 150 compatibility\n";
-	}
-	else if (GLEW_VERSION_3_1 && GLEW_ARB_compatibility) {
-		version = "#version 140\n"
-		          "#extension GL_ARB_compatibility: enable\n";
-	}
-	else if (GLEW_VERSION_3_0) {
-		version = "#version 130\n";
-		/* minimum supported for OpenSubdiv */
-	}
-
 	const char *sources[] = {
 		version,
 		define,
@@ -230,22 +218,25 @@ GLuint compileShader(GLenum shaderType,
 	return shader;
 }
 
-GLuint linkProgram(const char *define)
+GLuint linkProgram(const char *version, const char *define)
 {
 	GLuint vertexShader = compileShader(GL_VERTEX_SHADER,
 	                                    "VERTEX_SHADER",
+	                                    version,
 	                                    define);
 	if (vertexShader == 0) {
 		return 0;
 	}
 	GLuint geometryShader = compileShader(GL_GEOMETRY_SHADER,
 	                                      "GEOMETRY_SHADER",
+	                                      version,
 	                                      define);
 	if (geometryShader == 0) {
 		return 0;
 	}
 	GLuint fragmentShader = compileShader(GL_FRAGMENT_SHADER,
 	                                      "FRAGMENT_SHADER",
+	                                      version,
 	                                      define);
 	if (fragmentShader == 0) {
 		return 0;
@@ -261,7 +252,7 @@ GLuint linkProgram(const char *define)
 	glBindAttribLocation(program, 1, "normal");
 
 
-	if (!(GLEW_VERSION_3_2 && GLEW_ARB_compatibility)) {
+	if (!GLEW_VERSION_3_2) {
 		/* provide input/output layout info */
 		glProgramParameteriEXT(program,
 		                       GL_GEOMETRY_INPUT_TYPE_EXT,
@@ -381,11 +372,31 @@ bool openSubdiv_osdGLDisplayInit(void)
 	static bool need_init = true;
 	static bool init_success = false;
 	if (need_init) {
-		g_flat_fill_solid_program = linkProgram("#define FLAT_SHADING\n");
-		g_flat_fill_texture2d_program = linkProgram("#define USE_TEXTURE_2D\n#define FLAT_SHADING\n");
-		g_smooth_fill_solid_program = linkProgram("#define SMOOTH_SHADING\n");
-		g_smooth_fill_texture2d_program = linkProgram("#define USE_TEXTURE_2D\n#define SMOOTH_SHADING\n");
-		g_wireframe_program = linkProgram("#define WIREFRAME\n");
+
+		if (!openSubdiv_supportGPUDisplay()) {
+			return false;
+		}
+
+		const char *version = "";
+		if (GLEW_VERSION_3_2) {
+			version = "#version 150 compatibility\n";
+		}
+		else if (GLEW_VERSION_3_1) {
+			version = "#version 140\n"
+			          "#extension GL_ARB_compatibility: enable\n";
+		}
+		else {
+			version = "#version 130\n";
+			/* minimum supported for OpenSubdiv */
+		}
+
+		fprintf(stderr, version);
+
+		g_flat_fill_solid_program = linkProgram(version, "#define FLAT_SHADING\n");
+		g_flat_fill_texture2d_program = linkProgram(version, "#define USE_TEXTURE_2D\n#define FLAT_SHADING\n");
+		g_smooth_fill_solid_program = linkProgram(version, "#define SMOOTH_SHADING\n");
+		g_smooth_fill_texture2d_program = linkProgram(version, "#define USE_TEXTURE_2D\n#define SMOOTH_SHADING\n");
+		g_wireframe_program = linkProgram(version, "#define WIREFRAME\n");
 
 		glGenBuffers(1, &g_lighting_ub);
 		glBindBuffer(GL_UNIFORM_BUFFER, g_lighting_ub);




More information about the Bf-blender-cvs mailing list