diff --git a/gl/cogl-context.c b/gl/cogl-context.c index 50196a7dc..ce5b792c9 100644 --- a/gl/cogl-context.c +++ b/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/gl/cogl-context.h b/gl/cogl-context.h index 1704e8f4c..26c090ac5 100644 --- a/gl/cogl-context.h +++ b/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/gl/cogl.c b/gl/cogl.c index 8b0e27cf7..2104e175c 100644 --- a/gl/cogl.c +++ b/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/gles/cogl-context.c b/gles/cogl-context.c index 0027e96df..a2e5c9ee6 100644 --- a/gles/cogl-context.c +++ b/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/gles/cogl-context.h b/gles/cogl-context.h index c5117a9f5..f9654600c 100644 --- a/gles/cogl-context.h +++ b/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/gles/cogl-texture.c b/gles/cogl-texture.c index 1dcb882fe..992f1b6d6 100644 --- a/gles/cogl-texture.c +++ b/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/gles/cogl.c b/gles/cogl.c index 15889b9b4..bcbf4a06a 100644 --- a/gles/cogl.c +++ b/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) {