diff options
Diffstat (limited to 'intern/opensubdiv/opensubdiv_gpu_capi.cc')
-rw-r--r-- | intern/opensubdiv/opensubdiv_gpu_capi.cc | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/intern/opensubdiv/opensubdiv_gpu_capi.cc b/intern/opensubdiv/opensubdiv_gpu_capi.cc index 27c6d107a98..fc46ad05f53 100644 --- a/intern/opensubdiv/opensubdiv_gpu_capi.cc +++ b/intern/opensubdiv/opensubdiv_gpu_capi.cc @@ -23,11 +23,6 @@ * ***** END GPL LICENSE BLOCK ***** */ -/* 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 @@ -193,16 +188,31 @@ GLuint compileShader(GLenum shaderType, const char *section, const char *define) { - const char *sources[3]; char sdefine[64]; - sprintf(sdefine, "#define %s\n#define GLSL_COMPAT_WORKAROUND\n", section); + sprintf(sdefine, "#define %s\n", section); - sources[0] = define; - sources[1] = sdefine; - sources[2] = datatoc_gpu_shader_opensubd_display_glsl; + 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, + sdefine, + datatoc_gpu_shader_opensubd_display_glsl + }; GLuint shader = glCreateShader(shaderType); - glShaderSource(shader, 3, sources, NULL); + glShaderSource(shader, 4, sources, NULL); glCompileShader(shader); GLint status; @@ -210,10 +220,10 @@ GLuint compileShader(GLenum shaderType, if (status == GL_FALSE) { GLchar emsg[1024]; glGetShaderInfoLog(shader, sizeof(emsg), 0, emsg); - fprintf(stderr, "Error compiling GLSL shader (%s): %s\n", section, emsg); - fprintf(stderr, "Section: %s\n", sdefine); + fprintf(stderr, "Error compiling GLSL %s: %s\n", section, emsg); + fprintf(stderr, "Version: %s\n", version); fprintf(stderr, "Defines: %s\n", define); - fprintf(stderr, "Source: %s\n", sources[2]); + fprintf(stderr, "Source: %s\n", datatoc_gpu_shader_opensubd_display_glsl); return 0; } @@ -250,30 +260,23 @@ GLuint linkProgram(const char *define) glBindAttribLocation(program, 0, "position"); glBindAttribLocation(program, 1, "normal"); -#ifdef GLSL_COMPAT_WORKAROUND - glProgramParameteriEXT(program, - GL_GEOMETRY_INPUT_TYPE_EXT, - GL_LINES_ADJACENCY_EXT); - if (strstr(define, "WIREFRAME") == NULL) { + if (!(GLEW_VERSION_3_2 && GLEW_ARB_compatibility)) { + /* provide input/output layout info */ glProgramParameteriEXT(program, - GL_GEOMETRY_OUTPUT_TYPE_EXT, - GL_TRIANGLE_STRIP); + GL_GEOMETRY_INPUT_TYPE_EXT, + GL_LINES_ADJACENCY_EXT); + + bool wireframe = strstr(define, "WIREFRAME") != NULL; - glProgramParameteriEXT(program, - GL_GEOMETRY_VERTICES_OUT_EXT, - 4); - } - else { glProgramParameteriEXT(program, GL_GEOMETRY_OUTPUT_TYPE_EXT, - GL_LINE_STRIP); + wireframe ? GL_LINE_STRIP : GL_TRIANGLE_STRIP); glProgramParameteriEXT(program, GL_GEOMETRY_VERTICES_OUT_EXT, 8); } -#endif glLinkProgram(program); |