[cogl/cogl-1.10] Use the old GLSL extensions if GL 2.0 is not available
- From: Neil Roberts <nroberts src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/cogl-1.10] Use the old GLSL extensions if GL 2.0 is not available
- Date: Wed, 20 Jun 2012 11:57:27 +0000 (UTC)
commit 6bc94f9fa0231acb5723f8293e47503d50b1330d
Author: Neil Roberts <neil linux intel com>
Date: Wed May 30 12:02:07 2012 +0100
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)
cogl/driver/gl/cogl-gl.c | 27 ++++++
cogl/gl-prototypes/cogl-all-functions.h | 35 +++++++
cogl/gl-prototypes/cogl-glsl-functions.h | 143 +++++++++++++++--------------
3 files changed, 136 insertions(+), 69 deletions(-)
---
diff --git a/cogl/driver/gl/cogl-gl.c b/cogl/driver/gl/cogl-gl.c
index ebba3bf..b0100be 100644
--- a/cogl/driver/gl/cogl-gl.c
+++ b/cogl/driver/gl/cogl-gl.c
@@ -240,6 +240,33 @@ _cogl_gl_update_features (CoglContext *context,
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 (context->glCreateProgramObject && /* GL_ARB_shader_objects */
+ context->glVertexAttribPointer && /* GL_ARB_vertex_shader */
+ _cogl_check_extension ("GL_ARB_fragment_shader", gl_extensions))
+ {
+ context->glCreateShader = context->glCreateShaderObject;
+ context->glCreateProgram = context->glCreateProgramObject;
+ context->glDeleteShader = context->glDeleteObject;
+ context->glDeleteProgram = context->glDeleteObject;
+ context->glAttachShader = context->glAttachObject;
+ context->glUseProgram = context->glUseProgramObject;
+ context->glGetProgramInfoLog = context->glGetInfoLog;
+ context->glGetShaderInfoLog = context->glGetInfoLog;
+ context->glGetShaderiv = context->glGetObjectParameteriv;
+ context->glGetProgramiv = context->glGetObjectParameteriv;
+ context->glDetachShader = context->glDetachObject;
+ context->glGetAttachedShaders = context->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 (context->glGenBuffers)
{
diff --git a/cogl/gl-prototypes/cogl-all-functions.h b/cogl/gl-prototypes/cogl-all-functions.h
index d58b41f..2ab98da 100644
--- a/cogl/gl-prototypes/cogl-all-functions.h
+++ b/cogl/gl-prototypes/cogl-all-functions.h
@@ -210,3 +210,38 @@ COGL_EXT_FUNCTION (void, glFramebufferTexture2DMultisampleIMG,
GLint level,
GLsizei samples))
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 ()
diff --git a/cogl/gl-prototypes/cogl-glsl-functions.h b/cogl/gl-prototypes/cogl-glsl-functions.h
index a2b7abc..a5bad7e 100644
--- a/cogl/gl-prototypes/cogl-glsl-functions.h
+++ b/cogl/gl-prototypes/cogl-glsl-functions.h
@@ -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 **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 **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, 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,
- (GLuint program,
- GLenum pname,
- GLint *params))
-
-COGL_EXT_FUNCTION (void, glGetProgramInfoLog,
- (GLuint program,
- GLsizei bufSize,
- GLsizei *length,
- char *infoLog))
-
+/* 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 ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]