From de114dead76af8e8cccf872dd87aeee838e9e7e8 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Thu, 27 Nov 2008 16:44:39 +0000 Subject: [PATCH] Fix GLES 2 after the multiple-texture-rectangle branch merge The GLES 2 wrapper needs to set up some state before each draw. Previously this was acheived by wrapping glDrawArrays. Since the multiple-texture-rectangle branch merge, glDrawElements is used instead so we also need a wrapper for that. It was also directly calling glBindTexture. GLES 2 uses a wrapper for this function so that it can cope with GL_ALPHA format textures. The format of the current texture needs to be stored as well as the target and object number for this to work. --- clutter/cogl/gles/cogl-context.h | 1 + clutter/cogl/gles/cogl-gles2-wrapper.c | 20 ++++++++++++++++++-- clutter/cogl/gles/cogl-gles2-wrapper.h | 4 +++- clutter/cogl/gles/cogl-texture.c | 7 ++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/clutter/cogl/gles/cogl-context.h b/clutter/cogl/gles/cogl-context.h index 5d83571..92b8b96 100644 --- a/clutter/cogl/gles/cogl-context.h +++ b/clutter/cogl/gles/cogl-context.h @@ -72,6 +72,7 @@ typedef struct can be flushed */ GLuint texture_current; GLenum texture_target; + GLenum texture_format; /* Framebuffer objects */ GArray *fbo_handles; diff --git a/clutter/cogl/gles/cogl-gles2-wrapper.c b/clutter/cogl/gles/cogl-gles2-wrapper.c index fea7650..d43ad21 100644 --- a/clutter/cogl/gles/cogl-gles2-wrapper.c +++ b/clutter/cogl/gles/cogl-gles2-wrapper.c @@ -891,8 +891,8 @@ cogl_gles2_do_set_uniform (GLint location, CoglBoxedValue *value) } } -void -cogl_wrap_glDrawArrays (GLenum mode, GLint first, GLsizei count) +static void +cogl_wrap_prepare_for_draw (void) { CoglGles2WrapperProgram *program; @@ -999,10 +999,26 @@ cogl_wrap_glDrawArrays (GLenum mode, GLint first, GLsizei count) w->dirty_custom_uniforms = 0; } +} + +void +cogl_wrap_glDrawArrays (GLenum mode, GLint first, GLsizei count) +{ + cogl_wrap_prepare_for_draw (); + glDrawArrays (mode, first, count); } void +cogl_wrap_glDrawElements (GLenum mode, GLsizei count, GLenum type, + const GLvoid *indices) +{ + cogl_wrap_prepare_for_draw (); + + glDrawElements (mode, count, type, indices); +} + +void cogl_gles2_wrapper_bind_texture (GLenum target, GLuint texture, GLenum internal_format) { diff --git a/clutter/cogl/gles/cogl-gles2-wrapper.h b/clutter/cogl/gles/cogl-gles2-wrapper.h index ddf181e..7e7472c 100644 --- a/clutter/cogl/gles/cogl-gles2-wrapper.h +++ b/clutter/cogl/gles/cogl-gles2-wrapper.h @@ -250,7 +250,8 @@ void cogl_wrap_glFogx (GLenum pname, GLfixed param); void cogl_wrap_glFogxv (GLenum pname, const GLfixed *params); void cogl_wrap_glDrawArrays (GLenum mode, GLint first, GLsizei count); - +void cogl_wrap_glDrawElements (GLenum mode, GLsizei count, GLenum type, + const GLvoid *indices); void cogl_wrap_glTexParameteri (GLenum target, GLenum pname, GLfloat param); void cogl_gles2_wrapper_bind_texture (GLenum target, GLuint texture, @@ -274,6 +275,7 @@ void _cogl_gles2_clear_cache_for_program (CoglHandle program); #define cogl_wrap_glClearColorx glClearColorx #define cogl_wrap_glDrawArrays glDrawArrays +#define cogl_wrap_glDrawElements glDrawElements #define cogl_wrap_glPushMatrix glPushMatrix #define cogl_wrap_glPopMatrix glPopMatrix #define cogl_wrap_glMatrixMode glMatrixMode diff --git a/clutter/cogl/gles/cogl-texture.c b/clutter/cogl/gles/cogl-texture.c index 915e82b..4949afa 100644 --- a/clutter/cogl/gles/cogl-texture.c +++ b/clutter/cogl/gles/cogl-texture.c @@ -44,6 +44,7 @@ #define glTexCoordPointer cogl_wrap_glTexCoordPointer #define glColorPointer cogl_wrap_glColorPointer #define glDrawArrays cogl_wrap_glDrawArrays +#define glDrawElements cogl_wrap_glDrawElements #define glTexParameteri cogl_wrap_glTexParameteri /* @@ -2094,7 +2095,9 @@ _cogl_texture_flush_vertices (void) GE( glTexCoordPointer (2, GL_FLOAT, sizeof (CoglTextureGLVertex), p->t ) ); - GE( glBindTexture (ctx->texture_target, ctx->texture_current) ); + GE( cogl_gles2_wrapper_bind_texture (ctx->texture_target, + ctx->texture_current, + ctx->texture_format) ); GE( glDrawElements (GL_TRIANGLES, needed_indices, GL_UNSIGNED_SHORT, @@ -2284,6 +2287,7 @@ _cogl_texture_quad_sw (CoglTexture *tex, _cogl_texture_flush_vertices (); ctx->texture_target = tex->gl_target; ctx->texture_current = gl_handle; + ctx->texture_format = tex->gl_intformat; _cogl_texture_add_quad_vertices (COGL_FIXED_TO_FLOAT (slice_qx1), COGL_FIXED_TO_FLOAT (slice_qy1), @@ -2328,6 +2332,7 @@ _cogl_texture_quad_hw (CoglTexture *tex, _cogl_texture_flush_vertices (); ctx->texture_target = tex->gl_target; ctx->texture_current = gl_handle; + ctx->texture_format = tex->gl_intformat; /* Don't include the waste in the texture coordinates */ x_span = &g_array_index (tex->slice_x_spans, CoglTexSliceSpan, 0); -- 2.7.4