Use the old GLSL extensions if GL 2.0 is not available

Some drivers have good support for GLSL but don't have the complete
set of features needed to advertise GL 2.0 support. We should accept
the three old GLSL extensions (GL_ARB_shader_objects,
GL_ARB_vertex_shader and GL_ARB_fragment_shader) to support shaders on
these drivers.

This patch splits the shader functions into four sections :- those
that are provided only in GL 2.0, those that have the same name in the
shader objects extension, those that are provided by the vertex
shader extension (they all share the same name) and those that have a
different name in the shader objects extension.

If GL 2.0 is not supported but all three of the extensions are then
the pointers to the GL2-only functions will be replaced to point to
the equivalent functions from the extensions. That way the rest of the
Cogl source doesn't have to worry about the name differences.

https://bugzilla.gnome.org/show_bug.cgi?id=677078

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 71ecb51bd20dc3053b4221961b57e5a2b1029bdf)
This commit is contained in:
Neil Roberts 2012-05-30 12:02:07 +01:00 committed by Robert Bragg
parent a3989d035e
commit 763c1de2ab
3 changed files with 136 additions and 69 deletions

View File

@ -424,6 +424,33 @@ _cogl_driver_update_features (CoglContext *ctx,
flags |= COGL_FEATURE_SHADERS_GLSL; flags |= COGL_FEATURE_SHADERS_GLSL;
COGL_FLAGS_SET (ctx->features, COGL_FEATURE_ID_GLSL, TRUE); COGL_FLAGS_SET (ctx->features, COGL_FEATURE_ID_GLSL, TRUE);
} }
/* If all of the old GLSL extensions are available then we can fake
* the GL 2.0 GLSL support by diverting to the old function names */
else if (ctx->glCreateProgramObject && /* GL_ARB_shader_objects */
ctx->glVertexAttribPointer && /* GL_ARB_vertex_shader */
_cogl_check_extension ("GL_ARB_fragment_shader", gl_extensions))
{
ctx->glCreateShader = ctx->glCreateShaderObject;
ctx->glCreateProgram = ctx->glCreateProgramObject;
ctx->glDeleteShader = ctx->glDeleteObject;
ctx->glDeleteProgram = ctx->glDeleteObject;
ctx->glAttachShader = ctx->glAttachObject;
ctx->glUseProgram = ctx->glUseProgramObject;
ctx->glGetProgramInfoLog = ctx->glGetInfoLog;
ctx->glGetShaderInfoLog = ctx->glGetInfoLog;
ctx->glGetShaderiv = ctx->glGetObjectParameteriv;
ctx->glGetProgramiv = ctx->glGetObjectParameteriv;
ctx->glDetachShader = ctx->glDetachObject;
ctx->glGetAttachedShaders = ctx->glGetAttachedObjects;
/* FIXME: there doesn't seem to be an equivalent for glIsShader
* and glIsProgram. This doesn't matter for now because Cogl
* doesn't use these but if we add support for simulating a
* GLES2 context on top of regular GL then we'll need to do
* something here */
flags |= COGL_FEATURE_SHADERS_GLSL;
COGL_FLAGS_SET (ctx->features, COGL_FEATURE_ID_GLSL, TRUE);
}
if (ctx->glGenBuffers) if (ctx->glGenBuffers)
{ {

View File

@ -229,3 +229,38 @@ COGL_EXT_FUNCTION (void, glSamplerParameteri,
GLenum pname, GLenum pname,
GLint param)) GLint param))
COGL_EXT_END () COGL_EXT_END ()
/* These only list functions that come from the old GLSL extensions.
* Functions that are common to the extensions and GLSL 2.0 should
* instead be listed in cogl-glsl-functions.h */
COGL_EXT_BEGIN (shader_objects, 255, 255,
0, /* not in either GLES */
"ARB\0",
"shader_objects")
COGL_EXT_FUNCTION (GLuint, glCreateProgramObject,
(void))
COGL_EXT_FUNCTION (GLuint, glCreateShaderObject,
(GLenum shaderType))
COGL_EXT_FUNCTION (void, glDeleteObject,
(GLuint obj))
COGL_EXT_FUNCTION (void, glAttachObject,
(GLuint container, GLuint obj))
COGL_EXT_FUNCTION (void, glUseProgramObject,
(GLuint programObj))
COGL_EXT_FUNCTION (void, glGetInfoLog,
(GLuint obj,
GLsizei maxLength,
GLsizei *length,
char *infoLog))
COGL_EXT_FUNCTION (void, glGetObjectParameteriv,
(GLuint obj,
GLenum pname,
GLint *params))
COGL_EXT_FUNCTION (void, glDetachObject,
(GLuint container, GLuint obj))
COGL_EXT_FUNCTION (void, glGetAttachedObjects,
(GLuint program,
GLsizei maxcount,
GLsizei* count,
GLuint* shaders))
COGL_EXT_END ()

View File

@ -49,9 +49,9 @@
* extensions match then it will be used. * extensions match then it will be used.
*/ */
/* The function names in OpenGL 2.0 are different so we can't easily /* This lists functions that are unique to GL 2.0 or GLES 2.0 and are
just check for GL 2.0 */ * not in the old GLSL extensions */
COGL_EXT_BEGIN (shaders_glsl, 2, 0, COGL_EXT_BEGIN (shaders_glsl_2_only, 2, 0,
COGL_EXT_IN_GLES2, COGL_EXT_IN_GLES2,
"\0", "\0",
"\0") "\0")
@ -59,25 +59,13 @@ COGL_EXT_FUNCTION (GLuint, glCreateProgram,
(void)) (void))
COGL_EXT_FUNCTION (GLuint, glCreateShader, COGL_EXT_FUNCTION (GLuint, glCreateShader,
(GLenum shaderType)) (GLenum shaderType))
COGL_EXT_FUNCTION (void, glShaderSource,
(GLuint shader,
GLsizei count,
const char * const *string,
const GLint *length))
COGL_EXT_FUNCTION (void, glCompileShader,
(GLuint shader))
COGL_EXT_FUNCTION (void, glDeleteShader, COGL_EXT_FUNCTION (void, glDeleteShader,
(GLuint shader)) (GLuint shader))
COGL_EXT_FUNCTION (void, glAttachShader, COGL_EXT_FUNCTION (void, glAttachShader,
(GLuint program, (GLuint program,
GLuint shader)) GLuint shader))
COGL_EXT_FUNCTION (void, glLinkProgram,
(GLuint program))
COGL_EXT_FUNCTION (void, glUseProgram, COGL_EXT_FUNCTION (void, glUseProgram,
(GLuint program)) (GLuint program))
COGL_EXT_FUNCTION (GLint, glGetUniformLocation,
(GLuint program,
const char *name))
COGL_EXT_FUNCTION (void, glDeleteProgram, COGL_EXT_FUNCTION (void, glDeleteProgram,
(GLuint program)) (GLuint program))
COGL_EXT_FUNCTION (void, glGetShaderInfoLog, COGL_EXT_FUNCTION (void, glGetShaderInfoLog,
@ -85,23 +73,50 @@ COGL_EXT_FUNCTION (void, glGetShaderInfoLog,
GLsizei maxLength, GLsizei maxLength,
GLsizei *length, GLsizei *length,
char *infoLog)) char *infoLog))
COGL_EXT_FUNCTION (void, glGetProgramInfoLog,
(GLuint program,
GLsizei bufSize,
GLsizei *length,
char *infoLog))
COGL_EXT_FUNCTION (void, glGetShaderiv, COGL_EXT_FUNCTION (void, glGetShaderiv,
(GLuint shader, (GLuint shader,
GLenum pname, GLenum pname,
GLint *params)) GLint *params))
COGL_EXT_FUNCTION (void, glGetProgramiv,
(GLuint program,
GLenum pname,
GLint *params))
COGL_EXT_FUNCTION (void, glDetachShader,
(GLuint program, GLuint shader))
COGL_EXT_FUNCTION (void, glGetAttachedShaders,
(GLuint program,
GLsizei maxcount,
GLsizei* count,
GLuint* shaders))
COGL_EXT_FUNCTION (GLboolean, glIsShader,
(GLuint shader))
COGL_EXT_FUNCTION (GLboolean, glIsProgram,
(GLuint program))
COGL_EXT_END ()
COGL_EXT_FUNCTION (void, glVertexAttribPointer, /* These functions are provided by GL_ARB_shader_objects or are in GL
(GLuint index, * 2.0 core */
GLint size, COGL_EXT_BEGIN (shader_objects_or_gl2, 2, 0,
GLenum type, COGL_EXT_IN_GLES2,
GLboolean normalized, "ARB\0",
GLsizei stride, "shader_objects\0")
const GLvoid *pointer)) COGL_EXT_FUNCTION (void, glShaderSource,
COGL_EXT_FUNCTION (void, glEnableVertexAttribArray, (GLuint shader,
(GLuint index)) GLsizei count,
COGL_EXT_FUNCTION (void, glDisableVertexAttribArray, const char * const *string,
(GLuint index)) const GLint *length))
COGL_EXT_FUNCTION (void, glCompileShader,
(GLuint shader))
COGL_EXT_FUNCTION (void, glLinkProgram,
(GLuint program))
COGL_EXT_FUNCTION (GLint, glGetUniformLocation,
(GLuint program,
const char *name))
COGL_EXT_FUNCTION (void, glUniform1f, COGL_EXT_FUNCTION (void, glUniform1f,
(GLint location, (GLint location,
GLfloat v0)) GLfloat v0))
@ -194,18 +209,39 @@ COGL_EXT_FUNCTION (void, glGetUniformiv,
(GLuint program, (GLuint program,
GLint location, GLint location,
GLint *params)) GLint *params))
COGL_EXT_FUNCTION (void, glGetActiveUniform,
(GLuint program,
GLuint index,
GLsizei bufsize,
GLsizei* length,
GLint* size,
GLenum* type,
GLchar* name))
COGL_EXT_FUNCTION (void, glGetShaderSource,
(GLuint shader,
GLsizei bufsize,
GLsizei* length,
GLchar* source))
COGL_EXT_FUNCTION (void, glValidateProgram, (GLuint program))
COGL_EXT_END ()
COGL_EXT_FUNCTION (void, glGetProgramiv, /* These functions are provided by GL_ARB_vertex_shader or are in GL
(GLuint program, * 2.0 core */
GLenum pname, COGL_EXT_BEGIN (vertex_shaders, 2, 0,
GLint *params)) COGL_EXT_IN_GLES2,
"ARB\0",
COGL_EXT_FUNCTION (void, glGetProgramInfoLog, "vertex_shader\0")
(GLuint program, COGL_EXT_FUNCTION (void, glVertexAttribPointer,
GLsizei bufSize, (GLuint index,
GLsizei *length, GLint size,
char *infoLog)) GLenum type,
GLboolean normalized,
GLsizei stride,
const GLvoid *pointer))
COGL_EXT_FUNCTION (void, glEnableVertexAttribArray,
(GLuint index))
COGL_EXT_FUNCTION (void, glDisableVertexAttribArray,
(GLuint index))
COGL_EXT_FUNCTION (void, glVertexAttrib1f, (GLuint indx, GLfloat x)) COGL_EXT_FUNCTION (void, glVertexAttrib1f, (GLuint indx, GLfloat x))
COGL_EXT_FUNCTION (void, glVertexAttrib1fv, COGL_EXT_FUNCTION (void, glVertexAttrib1fv,
(GLuint indx, const GLfloat* values)) (GLuint indx, const GLfloat* values))
@ -220,17 +256,14 @@ COGL_EXT_FUNCTION (void, glVertexAttrib4f,
(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)) (GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w))
COGL_EXT_FUNCTION (void, glVertexAttrib4fv, COGL_EXT_FUNCTION (void, glVertexAttrib4fv,
(GLuint indx, const GLfloat* values)) (GLuint indx, const GLfloat* values))
COGL_EXT_FUNCTION (void, glGetVertexAttribfv, COGL_EXT_FUNCTION (void, glGetVertexAttribfv,
(GLuint index, GLenum pname, GLfloat* params)) (GLuint index, GLenum pname, GLfloat* params))
COGL_EXT_FUNCTION (void, glGetVertexAttribiv, COGL_EXT_FUNCTION (void, glGetVertexAttribiv,
(GLuint index, GLenum pname, GLint* params)) (GLuint index, GLenum pname, GLint* params))
COGL_EXT_FUNCTION (void, glGetVertexAttribPointerv, COGL_EXT_FUNCTION (void, glGetVertexAttribPointerv,
(GLuint index, GLenum pname, GLvoid** pointer)) (GLuint index, GLenum pname, GLvoid** pointer))
COGL_EXT_FUNCTION (GLint, glGetAttribLocation, COGL_EXT_FUNCTION (GLint, glGetAttribLocation,
(GLuint program, const char *name)) (GLuint program, const char *name))
COGL_EXT_FUNCTION (void, glBindAttribLocation, COGL_EXT_FUNCTION (void, glBindAttribLocation,
(GLuint program, (GLuint program,
GLuint index, GLuint index,
@ -243,32 +276,4 @@ COGL_EXT_FUNCTION (void, glGetActiveAttrib,
GLint* size, GLint* size,
GLenum* type, GLenum* type,
GLchar* name)) GLchar* name))
COGL_EXT_FUNCTION (void, glGetActiveUniform,
(GLuint program,
GLuint index,
GLsizei bufsize,
GLsizei* length,
GLint* size,
GLenum* type,
GLchar* name))
COGL_EXT_FUNCTION (void, glDetachShader,
(GLuint program, GLuint shader))
COGL_EXT_FUNCTION (void, glGetAttachedShaders,
(GLuint program,
GLsizei maxcount,
GLsizei* count,
GLuint* shaders))
COGL_EXT_FUNCTION (void, glGetShaderSource,
(GLuint shader,
GLsizei bufsize,
GLsizei* length,
GLchar* source))
COGL_EXT_FUNCTION (GLboolean, glIsShader,
(GLuint shader))
COGL_EXT_FUNCTION (GLboolean, glIsProgram,
(GLuint program))
COGL_EXT_FUNCTION (void, glValidateProgram, (GLuint program))
COGL_EXT_END () COGL_EXT_END ()