From f2d701c80908ad936e61f70338d93285f6ff694e Mon Sep 17 00:00:00 2001 From: Ivan Leben Date: Mon, 19 May 2008 15:02:27 +0000 Subject: [PATCH] * clutter/cogl/gl(es)/cogl.c: New internal function cogl_blend_func caches blending setup much like cogl_enable does with the enable flags. This separates blending factors setup from the enable/disable operation in preparation of the texture image retrieval fix for alpha channel on GLES. (cogl_enable:) Does not modify blending factors anymore. * clutter/cogl/gl(es)/cogl-context.h: CoglContext holds two new variables to cache blending src and dst factors. * clutter/cogl/gl(es)/cogl-context.c: (cogl_create_context:) Initialize blending factors. * clutter/cogl/gles/cogl-texture.c: (cogl_texture_download_from_gl:) Set blending factors to CGL_ONE, CGL_ZERO which fixes the slighlty improper behavior where source colour was actually multiplied with its alpha value in the result (not noticable on current tests). --- ChangeLog | 21 +++++++++++ clutter/cogl/gl/cogl-context.c | 8 +++- clutter/cogl/gl/cogl-context.h | 2 + clutter/cogl/gl/cogl.c | 65 +++++++------------------------- clutter/cogl/gles/cogl-context.c | 8 +++- clutter/cogl/gles/cogl-context.h | 2 + clutter/cogl/gles/cogl-texture.c | 2 + clutter/cogl/gles/cogl.c | 26 ++++++++++--- 8 files changed, 72 insertions(+), 62 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb2906fb3..847c8ccbf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2008-05-19 Ivan Leben + + * clutter/cogl/gl(es)/cogl.c: New internal function + cogl_blend_func caches blending setup much like cogl_enable + does with the enable flags. This separates blending factors + setup from the enable/disable operation in preparation of + the texture image retrieval fix for alpha channel on GLES. + (cogl_enable:) Does not modify blending factors anymore. + + * clutter/cogl/gl(es)/cogl-context.h: CoglContext holds two + new variables to cache blending src and dst factors. + + * clutter/cogl/gl(es)/cogl-context.c: + (cogl_create_context:) Initialize blending factors. + + * clutter/cogl/gles/cogl-texture.c: + (cogl_texture_download_from_gl:) Set blending factors to + CGL_ONE, CGL_ZERO which fixes the slighlty improper behavior + where source colour was actually multiplied with its alpha + value in the result (not noticable on current tests). + 2008-05-19 Emmanuele Bassi * clutter/eglx/Makefile.am: Fix the INCLUDE directives to diff --git a/clutter/cogl/gl/cogl-context.c b/clutter/cogl/gl/cogl-context.c index 50196a7dc..ce5b792c9 100644 --- a/clutter/cogl/gl/cogl-context.c +++ b/clutter/cogl/gl/cogl-context.c @@ -60,6 +60,9 @@ cogl_create_context () _context->fbo_handles = NULL; _context->draw_buffer = COGL_WINDOW_BUFFER; + + _context->blend_src_factor = CGL_SRC_ALPHA; + _context->blend_dst_factor = CGL_ONE_MINUS_SRC_ALPHA; _context->shader_handles = NULL; @@ -91,8 +94,9 @@ cogl_create_context () _context->pf_glUniform1fARB = NULL; /* Init OpenGL state */ - glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glColorMask (TRUE, TRUE, TRUE, FALSE); + GE( glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) ); + GE( glColorMask (TRUE, TRUE, TRUE, FALSE) ); + GE( glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ); cogl_enable (0); return TRUE; diff --git a/clutter/cogl/gl/cogl-context.h b/clutter/cogl/gl/cogl-context.h index 1704e8f4c..26c090ac5 100644 --- a/clutter/cogl/gl/cogl-context.h +++ b/clutter/cogl/gl/cogl-context.h @@ -37,6 +37,8 @@ typedef struct /* Enable cache */ gulong enable_flags; guint8 color_alpha; + COGLenum blend_src_factor; + COGLenum blend_dst_factor; /* Primitives */ CoglFixedVec2 path_start; diff --git a/clutter/cogl/gl/cogl.c b/clutter/cogl/gl/cogl.c index 8b0e27cf7..2104e175c 100644 --- a/clutter/cogl/gl/cogl.c +++ b/clutter/cogl/gl/cogl.c @@ -306,12 +306,9 @@ cogl_enable (gulong flags) */ _COGL_GET_CONTEXT (ctx, NO_RETVAL); - if (cogl_toggle_flag (ctx, flags, - COGL_ENABLE_BLEND, - GL_BLEND)) - { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } + cogl_toggle_flag (ctx, flags, + COGL_ENABLE_BLEND, + GL_BLEND); cogl_toggle_flag (ctx, flags, COGL_ENABLE_TEXTURE_2D, @@ -340,59 +337,23 @@ cogl_get_enable () return ctx->enable_flags; } -/* void -cogl_enable (gulong flags) +cogl_blend_func (COGLenum src_factor, COGLenum dst_factor) { + /* This function caches the blending setup in the + * hope of lessening GL traffic. + */ _COGL_GET_CONTEXT (ctx, NO_RETVAL); - if (flags & COGL_ENABLE_BLEND) + if (ctx->blend_src_factor != src_factor || + ctx->blend_dst_factor != dst_factor) { - if (!(ctx->enable_flags & COGL_ENABLE_BLEND)) - { - glEnable (GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - ctx->enable_flags |= COGL_ENABLE_BLEND; - } + glBlendFunc (src_factor, dst_factor); + ctx->blend_src_factor = src_factor; + ctx->blend_dst_factor = dst_factor; } - else if (ctx->enable_flags & COGL_ENABLE_BLEND) - { - glDisable (GL_BLEND); - ctx->enable_flags &= ~COGL_ENABLE_BLEND; - } - - if (flags & COGL_ENABLE_TEXTURE_2D) - { - if (!(ctx->enable_flags & COGL_ENABLE_TEXTURE_2D)) - { - glEnable (GL_TEXTURE_2D); - ctx->enable_flags |= COGL_ENABLE_TEXTURE_2D; - } - } - else if (ctx->enable_flags & COGL_ENABLE_TEXTURE_2D) - { - glDisable (GL_TEXTURE_2D); - ctx->enable_flags &= ~COGL_ENABLE_TEXTURE_2D; - } - -#ifdef GL_TEXTURE_RECTANGLE_ARB - if (flags & COGL_ENABLE_TEXTURE_RECT) - { - if (!(ctx->enable_flags & COGL_ENABLE_TEXTURE_RECT)) - { - glEnable (GL_TEXTURE_RECTANGLE_ARB); - ctx->enable_flags |= COGL_ENABLE_TEXTURE_RECT; - } - } - else if (ctx->enable_flags & COGL_ENABLE_TEXTURE_RECT) - { - glDisable (GL_TEXTURE_RECTANGLE_ARB); - ctx->enable_flags &= ~COGL_ENABLE_TEXTURE_RECT; - } -#endif } -*/ + void cogl_enable_depth_test (gboolean setting) { diff --git a/clutter/cogl/gles/cogl-context.c b/clutter/cogl/gles/cogl-context.c index 0027e96df..a2e5c9ee6 100644 --- a/clutter/cogl/gles/cogl-context.c +++ b/clutter/cogl/gles/cogl-context.c @@ -65,9 +65,13 @@ cogl_create_context () _context->fbo_handles = NULL; _context->draw_buffer = COGL_WINDOW_BUFFER; + _context->blend_src_factor = CGL_SRC_ALPHA; + _context->blend_dst_factor = CGL_ONE_MINUS_SRC_ALPHA; + /* Init OpenGL state */ - glTexEnvx (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - glColorMask (TRUE, TRUE, TRUE, FALSE); + GE( glTexEnvx (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) ); + GE( glColorMask (TRUE, TRUE, TRUE, FALSE) ); + GE( glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ); cogl_enable (0); return TRUE; diff --git a/clutter/cogl/gles/cogl-context.h b/clutter/cogl/gles/cogl-context.h index c5117a9f5..f9654600c 100644 --- a/clutter/cogl/gles/cogl-context.h +++ b/clutter/cogl/gles/cogl-context.h @@ -44,6 +44,8 @@ typedef struct /* Enable cache */ gulong enable_flags; guint8 color_alpha; + COGLenum blend_src_factor; + COGLenum blend_dst_factor; /* Primitives */ CoglFixedVec2 path_start; diff --git a/clutter/cogl/gles/cogl-texture.c b/clutter/cogl/gles/cogl-texture.c index 1dcb882fe..992f1b6d6 100644 --- a/clutter/cogl/gles/cogl-texture.c +++ b/clutter/cogl/gles/cogl-texture.c @@ -297,6 +297,7 @@ _cogl_texture_download_from_gl (CoglTexture *tex, for direct copy to framebuffer */ cogl_paint_init (&cback); cogl_color (&cwhite); + cogl_blend_func (CGL_ONE, CGL_ZERO); /* Draw the texture image */ cogl_texture_rectangle (handle, @@ -349,6 +350,7 @@ _cogl_texture_download_from_gl (CoglTexture *tex, for direct copy to framebuffer */ cogl_paint_init (&cback); cogl_color (&cwhite); + cogl_blend_func (CGL_ONE, CGL_ZERO); /* Draw a portion of texture */ cogl_texture_rectangle (handle, diff --git a/clutter/cogl/gles/cogl.c b/clutter/cogl/gles/cogl.c index 15889b9b4..bcbf4a06a 100644 --- a/clutter/cogl/gles/cogl.c +++ b/clutter/cogl/gles/cogl.c @@ -214,12 +214,9 @@ cogl_enable (gulong flags) */ _COGL_GET_CONTEXT (ctx, NO_RETVAL); - if (cogl_toggle_flag (ctx, flags, - COGL_ENABLE_BLEND, - GL_BLEND)) - { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } + cogl_toggle_flag (ctx, flags, + COGL_ENABLE_BLEND, + GL_BLEND); cogl_toggle_flag (ctx, flags, COGL_ENABLE_TEXTURE_2D, @@ -246,6 +243,23 @@ cogl_get_enable () return ctx->enable_flags; } +void +cogl_blend_func (COGLenum src_factor, COGLenum dst_factor) +{ + /* This function caches the blending setup in the + * hope of lessening GL traffic. + */ + _COGL_GET_CONTEXT (ctx, NO_RETVAL); + + if (ctx->blend_src_factor != src_factor || + ctx->blend_dst_factor != dst_factor) + { + glBlendFunc (src_factor, dst_factor); + ctx->blend_src_factor = src_factor; + ctx->blend_dst_factor = dst_factor; + } +} + void cogl_enable_depth_test (gboolean setting) {