From 8ae02decb4617896e05d46cbacadc42c88b5ba0c Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Thu, 13 Nov 2008 14:28:16 +0000 Subject: [PATCH] Gets the mesh API working with GLES2 * clutter/cogl/common/cogl-mesh.c: Make sure we use the appropriate cogl_wrap_gl* funcs as appropriate * clutter/cogl/gles/cogl-gles2-wrapper.c * clutter/cogl/gles/cogl-gles2-wrapper.h: In our glColorPointer wrapper we needed to mark our color attribute as normalized. * tests/conform/Makefile.am: When creating unit test symlinks we use the -l gtester option to list tests, but when using the PVR SDK the test binary also spews out some extra info that caused lots of random symlinks to be created. We now grep for lines starting with a '/' * tests/conform/test-mesh-contiguous.c * tests/conform/test-mesh-mutability.c: Use cogl_set_source_color instead of directly calling glColor4ub --- common/cogl-mesh.c | 27 +++++++++++++++++++++------ gles/cogl-gles2-wrapper.c | 16 ++++++++++++++++ gles/cogl-gles2-wrapper.h | 4 ++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/common/cogl-mesh.c b/common/cogl-mesh.c index 281b374c1..c5e4bafec 100644 --- a/common/cogl-mesh.c +++ b/common/cogl-mesh.c @@ -140,7 +140,7 @@ * GL/GLES compatability defines for VBO thingies: */ -#if HAVE_COGL_GL +#if defined (HAVE_COGL_GL) #define glGenBuffers ctx->pf_glGenBuffersARB #define glBindBuffer ctx->pf_glBindBufferARB @@ -153,7 +153,7 @@ #define GL_ARRAY_BUFFER GL_ARRAY_BUFFER_ARB #endif -#else +#elif defined (HAVE_COGL_GLES) /* NB: GLES has had VBOs/GLSL since 1.1, so we don't need any defines in * this case except for glBufferSubData which, just for the fun of it, has a @@ -161,27 +161,42 @@ */ #define glBufferDataSub glBufferSubData +#elif defined (HAVE_COGL_GLES2) + +#define glVertexPointer cogl_wrap_glVertexPointer +#define glNormalPointer cogl_wrap_glNormalPointer +#define glTexCoordPointer cogl_wrap_glTexCoordPointer +#define glColorPointer cogl_wrap_glColorPointer +#define glDrawArrays cogl_wrap_glDrawArrays + +#define glEnableClientState cogl_wrap_glEnableClientState +#define glDisableClientState cogl_wrap_glDisableClientState + +#define glBufferDataSub glBufferSubData + #endif /* * GL/GLES compatability defines for shader things: */ -#ifdef HAVE_COGL_GL +#if defined (HAVE_COGL_GL) + #define glVertexAttribPointer ctx->pf_glVertexAttribPointerARB #define glEnableVertexAttribArray ctx->pf_glEnableVertexAttribArrayARB #define glDisableVertexAttribArray ctx->pf_glEnableVertexAttribArrayARB #define MAY_HAVE_PROGRAMABLE_GL -#endif -#ifdef HAVE_COGL_GLES2 +#elif defined (HAVE_COGL_GLES2) + /* NB: GLES2 had shaders in core since day one so again we don't need * defines in this case: */ #define MAY_HAVE_PROGRAMABLE_GL + #endif #ifndef HAVE_COGL_GL -/* GLES doesn't glDrawRangeElements, so we simply pretend it does +/* GLES doesn't have glDrawRangeElements, so we simply pretend it does * but that it makes no use of the start, end constraints: */ #define glDrawRangeElements(mode, start, end, count, type, indices) \ glDrawElements (mode, count, type, indices) diff --git a/gles/cogl-gles2-wrapper.c b/gles/cogl-gles2-wrapper.c index 969783c0c..a1629d559 100644 --- a/gles/cogl-gles2-wrapper.c +++ b/gles/cogl-gles2-wrapper.c @@ -68,6 +68,7 @@ #define COGL_GLES2_WRAPPER_VERTEX_ATTRIB 0 #define COGL_GLES2_WRAPPER_TEX_COORD_ATTRIB 1 #define COGL_GLES2_WRAPPER_COLOR_ATTRIB 2 +#define COGL_GLES2_WRAPPER_NORMAL_ATTRIB 3 static GLuint cogl_gles2_wrapper_create_shader (GLenum type, const char *source) @@ -424,6 +425,8 @@ cogl_gles2_wrapper_bind_attributes (GLuint program) "tex_coord_attrib"); glBindAttribLocation (program, COGL_GLES2_WRAPPER_COLOR_ATTRIB, "color_attrib"); + glBindAttribLocation (program, COGL_GLES2_WRAPPER_NORMAL_ATTRIB, + "normal_attrib"); } void @@ -798,6 +801,13 @@ cogl_wrap_glColorPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) { glVertexAttribPointer (COGL_GLES2_WRAPPER_COLOR_ATTRIB, size, type, + GL_TRUE, stride, pointer); +} + +void +cogl_wrap_glNormalPointer (GLenum type, GLsizei stride, const GLvoid *pointer) +{ + glVertexAttribPointer (COGL_GLES2_WRAPPER_NORMAL_ATTRIB, 1, type, GL_FALSE, stride, pointer); } @@ -992,6 +1002,9 @@ cogl_wrap_glEnableClientState (GLenum array) case GL_COLOR_ARRAY: glEnableVertexAttribArray (COGL_GLES2_WRAPPER_COLOR_ATTRIB); break; + case GL_NORMAL_ARRAY: + glEnableVertexAttribArray (COGL_GLES2_WRAPPER_NORMAL_ATTRIB); + break; } } @@ -1009,6 +1022,9 @@ cogl_wrap_glDisableClientState (GLenum array) case GL_COLOR_ARRAY: glDisableVertexAttribArray (COGL_GLES2_WRAPPER_COLOR_ATTRIB); break; + case GL_NORMAL_ARRAY: + glDisableVertexAttribArray (COGL_GLES2_WRAPPER_NORMAL_ATTRIB); + break; } } diff --git a/gles/cogl-gles2-wrapper.h b/gles/cogl-gles2-wrapper.h index 9531a486e..119168625 100644 --- a/gles/cogl-gles2-wrapper.h +++ b/gles/cogl-gles2-wrapper.h @@ -162,6 +162,7 @@ struct _CoglGles2WrapperShader #define GL_VERTEX_ARRAY 0x8074 #define GL_TEXTURE_COORD_ARRAY 0x8078 #define GL_COLOR_ARRAY 0x8076 +#define GL_NORMAL_ARRAY 0x8075 #define GL_LIGHTING 0x0B50 #define GL_ALPHA_TEST 0x0BC0 @@ -223,6 +224,8 @@ void cogl_wrap_glVertexPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); void cogl_wrap_glColorPointer (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer); +void cogl_wrap_glNormalPointer (GLenum type, GLsizei stride, + const GLvoid *pointer); void cogl_wrap_glTexEnvx (GLenum target, GLenum pname, GLfixed param); @@ -281,6 +284,7 @@ void _cogl_gles2_clear_cache_for_program (CoglHandle program); #define cogl_wrap_glTexCoordPointer glTexCoordPointer #define cogl_wrap_glVertexPointer glVertexPointer #define cogl_wrap_glColorPointer glColorPointer +#define cogl_wrap_glNormalPointer glNormalPointer #define cogl_wrap_glTexEnvx glTexEnvx #define cogl_wrap_glEnableClientState glEnableClientState #define cogl_wrap_glDisableClientState glDisableClientState