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.
This commit is contained in:
Mike Erwin 2015-12-06 18:47:58 -05:00
parent 50df05c35c
commit a048d5f945
4 changed files with 39 additions and 24 deletions

@ -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;

@ -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? */
}

@ -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

@ -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);