OpenSubdiv: support OpenGL 3.x

GLSL 130, 140, 150 with extensions as needed.

Similar logic to my recent gpu_extensions changes.

Partially fixes T46706. Matcaps now work with OpenSubdiv, as do basic
materials. Anything with UV coordinates is still broken.
This commit is contained in:
Mike Erwin 2015-11-23 03:33:49 -05:00
parent 8d47dbccbe
commit f997449f84
Notes: blender-bot 2023-02-14 10:29:30 +01:00
Referenced by issue #46706, Blender Render Texture and Material Views Show Large Wireframes when viewing OpenSubDiv Objects
3 changed files with 55 additions and 55 deletions

View File

@ -23,20 +23,13 @@
* ***** END GPL LICENSE BLOCK *****
*/
/* ***** Vertex shader ***** */
#extension GL_EXT_geometry_shader4 : enable
#extension GL_ARB_gpu_shader5 : enable
#extension GL_ARB_explicit_attrib_location : require
#extension GL_ARB_uniform_buffer_object : require
struct VertexData {
vec4 position;
vec3 normal;
vec2 uv;
};
#ifdef VERTEX_SHADER
#ifdef VERTEX_SHADER // ---------------------
in vec3 normal;
in vec4 position;
@ -52,24 +45,32 @@ void main()
{
outpt.v.position = modelViewMatrix * position;
outpt.v.normal = normalize(normalMatrix * normal);
#if __VERSION__ < 140
/* Some compilers expects gl_Position to be written.
* It's not needed once we explicitly switch to GLSL 1.40 or above.
*/
gl_Position = outpt.v.position;
#endif
}
#endif /* VERTEX_SHADER */
#elif defined GEOMETRY_SHADER // ---------------------
/* ***** geometry shader ***** */
#ifdef GEOMETRY_SHADER
#ifndef GLSL_COMPAT_WORKAROUND
layout(lines_adjacency) in;
#ifndef WIREFRAME
layout(triangle_strip, max_vertices = 4) out;
#if __VERSION__ >= 150
layout(lines_adjacency) in;
#ifdef WIREFRAME
layout(line_strip, max_vertices = 8) out;
#else
layout(triangle_strip, max_vertices = 4) out;
#endif
#else
layout(line_strip, max_vertices = 8) out;
#extension GL_EXT_geometry_shader4: require
/* application provides input/output layout info */
#endif
#if __VERSION__ < 140
#extension GL_ARB_uniform_buffer_object: require
#extension GL_ARB_texture_buffer_object: require
#endif
uniform mat4 modelViewMatrix;
@ -188,10 +189,7 @@ void main()
EndPrimitive();
}
#endif /* GEOMETRY_SHADER */
/* ***** Fragment shader ***** */
#ifdef FRAGMENT_SHADER
#elif defined FRAGMENT_SHADER // ---------------------
#define MAX_LIGHTS 8
#define NUM_SOLID_LIGHTS 3
@ -330,4 +328,4 @@ void main()
#endif
}
#endif // FRAGMENT_SHADER
#endif // ---------------------

View File

@ -296,9 +296,8 @@ const struct OpenSubdiv_TopologyRefinerDescr *openSubdiv_getGLMeshTopologyRefine
int openSubdiv_supportGPUDisplay(void)
{
// TODO: simplify extension check once Blender adopts GL 3.2
return GLEW_VERSION_4_0 || (
GLEW_EXT_geometry_shader4 && // ARB version core in 3.2
GLEW_ARB_gpu_shader5 && // written against 3.2, core in 4.0
GLEW_ARB_uniform_buffer_object // core in 3.1
);
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);
/* also ARB_explicit_attrib_location? */
}

View File

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