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:
parent
a3989d035e
commit
763c1de2ab
@ -424,6 +424,33 @@ _cogl_driver_update_features (CoglContext *ctx,
|
||||
flags |= COGL_FEATURE_SHADERS_GLSL;
|
||||
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)
|
||||
{
|
||||
|
@ -229,3 +229,38 @@ COGL_EXT_FUNCTION (void, glSamplerParameteri,
|
||||
GLenum pname,
|
||||
GLint param))
|
||||
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 ()
|
||||
|
@ -49,9 +49,9 @@
|
||||
* extensions match then it will be used.
|
||||
*/
|
||||
|
||||
/* The function names in OpenGL 2.0 are different so we can't easily
|
||||
just check for GL 2.0 */
|
||||
COGL_EXT_BEGIN (shaders_glsl, 2, 0,
|
||||
/* This lists functions that are unique to GL 2.0 or GLES 2.0 and are
|
||||
* not in the old GLSL extensions */
|
||||
COGL_EXT_BEGIN (shaders_glsl_2_only, 2, 0,
|
||||
COGL_EXT_IN_GLES2,
|
||||
"\0",
|
||||
"\0")
|
||||
@ -59,25 +59,13 @@ COGL_EXT_FUNCTION (GLuint, glCreateProgram,
|
||||
(void))
|
||||
COGL_EXT_FUNCTION (GLuint, glCreateShader,
|
||||
(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,
|
||||
(GLuint shader))
|
||||
COGL_EXT_FUNCTION (void, glAttachShader,
|
||||
(GLuint program,
|
||||
GLuint shader))
|
||||
COGL_EXT_FUNCTION (void, glLinkProgram,
|
||||
(GLuint program))
|
||||
COGL_EXT_FUNCTION (void, glUseProgram,
|
||||
(GLuint program))
|
||||
COGL_EXT_FUNCTION (GLint, glGetUniformLocation,
|
||||
(GLuint program,
|
||||
const char *name))
|
||||
COGL_EXT_FUNCTION (void, glDeleteProgram,
|
||||
(GLuint program))
|
||||
COGL_EXT_FUNCTION (void, glGetShaderInfoLog,
|
||||
@ -85,23 +73,50 @@ COGL_EXT_FUNCTION (void, glGetShaderInfoLog,
|
||||
GLsizei maxLength,
|
||||
GLsizei *length,
|
||||
char *infoLog))
|
||||
COGL_EXT_FUNCTION (void, glGetProgramInfoLog,
|
||||
(GLuint program,
|
||||
GLsizei bufSize,
|
||||
GLsizei *length,
|
||||
char *infoLog))
|
||||
COGL_EXT_FUNCTION (void, glGetShaderiv,
|
||||
(GLuint shader,
|
||||
GLenum pname,
|
||||
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,
|
||||
(GLuint index,
|
||||
GLint size,
|
||||
GLenum type,
|
||||
GLboolean normalized,
|
||||
GLsizei stride,
|
||||
const GLvoid *pointer))
|
||||
COGL_EXT_FUNCTION (void, glEnableVertexAttribArray,
|
||||
(GLuint index))
|
||||
COGL_EXT_FUNCTION (void, glDisableVertexAttribArray,
|
||||
(GLuint index))
|
||||
|
||||
/* These functions are provided by GL_ARB_shader_objects or are in GL
|
||||
* 2.0 core */
|
||||
COGL_EXT_BEGIN (shader_objects_or_gl2, 2, 0,
|
||||
COGL_EXT_IN_GLES2,
|
||||
"ARB\0",
|
||||
"shader_objects\0")
|
||||
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, glLinkProgram,
|
||||
(GLuint program))
|
||||
COGL_EXT_FUNCTION (GLint, glGetUniformLocation,
|
||||
(GLuint program,
|
||||
const char *name))
|
||||
COGL_EXT_FUNCTION (void, glUniform1f,
|
||||
(GLint location,
|
||||
GLfloat v0))
|
||||
@ -194,18 +209,39 @@ COGL_EXT_FUNCTION (void, glGetUniformiv,
|
||||
(GLuint program,
|
||||
GLint location,
|
||||
GLint *params))
|
||||
|
||||
COGL_EXT_FUNCTION (void, glGetProgramiv,
|
||||
COGL_EXT_FUNCTION (void, glGetActiveUniform,
|
||||
(GLuint program,
|
||||
GLenum pname,
|
||||
GLint *params))
|
||||
|
||||
COGL_EXT_FUNCTION (void, glGetProgramInfoLog,
|
||||
(GLuint program,
|
||||
GLsizei bufSize,
|
||||
GLsizei *length,
|
||||
char *infoLog))
|
||||
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 ()
|
||||
|
||||
/* These functions are provided by GL_ARB_vertex_shader or are in GL
|
||||
* 2.0 core */
|
||||
COGL_EXT_BEGIN (vertex_shaders, 2, 0,
|
||||
COGL_EXT_IN_GLES2,
|
||||
"ARB\0",
|
||||
"vertex_shader\0")
|
||||
COGL_EXT_FUNCTION (void, glVertexAttribPointer,
|
||||
(GLuint index,
|
||||
GLint size,
|
||||
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, glVertexAttrib1fv,
|
||||
(GLuint indx, const GLfloat* values))
|
||||
@ -220,17 +256,14 @@ COGL_EXT_FUNCTION (void, glVertexAttrib4f,
|
||||
(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w))
|
||||
COGL_EXT_FUNCTION (void, glVertexAttrib4fv,
|
||||
(GLuint indx, const GLfloat* values))
|
||||
|
||||
COGL_EXT_FUNCTION (void, glGetVertexAttribfv,
|
||||
(GLuint index, GLenum pname, GLfloat* params))
|
||||
COGL_EXT_FUNCTION (void, glGetVertexAttribiv,
|
||||
(GLuint index, GLenum pname, GLint* params))
|
||||
COGL_EXT_FUNCTION (void, glGetVertexAttribPointerv,
|
||||
(GLuint index, GLenum pname, GLvoid** pointer))
|
||||
|
||||
COGL_EXT_FUNCTION (GLint, glGetAttribLocation,
|
||||
(GLuint program, const char *name))
|
||||
|
||||
COGL_EXT_FUNCTION (void, glBindAttribLocation,
|
||||
(GLuint program,
|
||||
GLuint index,
|
||||
@ -243,32 +276,4 @@ COGL_EXT_FUNCTION (void, glGetActiveAttrib,
|
||||
GLint* size,
|
||||
GLenum* type,
|
||||
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 ()
|
||||
|
Loading…
Reference in New Issue
Block a user