OpenSubdiv: refine OpenGL version & extension checks
authorMike Erwin <significant.bit@gmail.com>
Sun, 6 Dec 2015 23:47:58 +0000 (18:47 -0500)
committerMike Erwin <significant.bit@gmail.com>
Sun, 6 Dec 2015 23:47:58 +0000 (18:47 -0500)
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.

intern/opensubdiv/gpu_shader_opensubd_display.glsl
intern/opensubdiv/opensubdiv_capi.cc
intern/opensubdiv/opensubdiv_capi.h
intern/opensubdiv/opensubdiv_gpu_capi.cc

index 57bbfa89714c848cdeba96f2b763f92aabda8095..51e8ed46c340719ea6220cfb417667d00128ac10 100644 (file)
@@ -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;
index f715bf325654a2e53ab1c2576123b3cd36aeccd4..6c226d6cf6b263c9196f2ef3749b9b858f99b914 100644 (file)
@@ -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? */
 }
index 8010c39647d62fc1105320fd8b6718b224293a70..9d1c1b3795cb8725da3bc027658700034c5b9107 100644 (file)
@@ -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
index fc46ad05f5326f7acb323ec5ad5b4a69bec79501..cbde06b9082ac9ec98a2b51ff74e50264eb2d52b 100644 (file)
@@ -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);