* 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).
This commit is contained in:
Ivan Leben 2008-05-19 15:02:27 +00:00
parent aec03912b8
commit f2d701c809
8 changed files with 72 additions and 62 deletions

View File

@ -1,3 +1,24 @@
2008-05-19 Ivan Leben <ivan@o-hand.com>
* 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 <ebassi@openedhand.com> 2008-05-19 Emmanuele Bassi <ebassi@openedhand.com>
* clutter/eglx/Makefile.am: Fix the INCLUDE directives to * clutter/eglx/Makefile.am: Fix the INCLUDE directives to

View File

@ -60,6 +60,9 @@ cogl_create_context ()
_context->fbo_handles = NULL; _context->fbo_handles = NULL;
_context->draw_buffer = COGL_WINDOW_BUFFER; _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; _context->shader_handles = NULL;
@ -91,8 +94,9 @@ cogl_create_context ()
_context->pf_glUniform1fARB = NULL; _context->pf_glUniform1fARB = NULL;
/* Init OpenGL state */ /* Init OpenGL state */
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); GE( glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) );
glColorMask (TRUE, TRUE, TRUE, FALSE); GE( glColorMask (TRUE, TRUE, TRUE, FALSE) );
GE( glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) );
cogl_enable (0); cogl_enable (0);
return TRUE; return TRUE;

View File

@ -37,6 +37,8 @@ typedef struct
/* Enable cache */ /* Enable cache */
gulong enable_flags; gulong enable_flags;
guint8 color_alpha; guint8 color_alpha;
COGLenum blend_src_factor;
COGLenum blend_dst_factor;
/* Primitives */ /* Primitives */
CoglFixedVec2 path_start; CoglFixedVec2 path_start;

View File

@ -306,12 +306,9 @@ cogl_enable (gulong flags)
*/ */
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
if (cogl_toggle_flag (ctx, flags, cogl_toggle_flag (ctx, flags,
COGL_ENABLE_BLEND, COGL_ENABLE_BLEND,
GL_BLEND)) GL_BLEND);
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
cogl_toggle_flag (ctx, flags, cogl_toggle_flag (ctx, flags,
COGL_ENABLE_TEXTURE_2D, COGL_ENABLE_TEXTURE_2D,
@ -340,59 +337,23 @@ cogl_get_enable ()
return ctx->enable_flags; return ctx->enable_flags;
} }
/*
void 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); _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)) glBlendFunc (src_factor, dst_factor);
{ ctx->blend_src_factor = src_factor;
glEnable (GL_BLEND); ctx->blend_dst_factor = dst_factor;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
ctx->enable_flags |= COGL_ENABLE_BLEND;
}
} }
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 void
cogl_enable_depth_test (gboolean setting) cogl_enable_depth_test (gboolean setting)
{ {

View File

@ -65,9 +65,13 @@ cogl_create_context ()
_context->fbo_handles = NULL; _context->fbo_handles = NULL;
_context->draw_buffer = COGL_WINDOW_BUFFER; _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 */ /* Init OpenGL state */
glTexEnvx (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); GE( glTexEnvx (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) );
glColorMask (TRUE, TRUE, TRUE, FALSE); GE( glColorMask (TRUE, TRUE, TRUE, FALSE) );
GE( glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) );
cogl_enable (0); cogl_enable (0);
return TRUE; return TRUE;

View File

@ -44,6 +44,8 @@ typedef struct
/* Enable cache */ /* Enable cache */
gulong enable_flags; gulong enable_flags;
guint8 color_alpha; guint8 color_alpha;
COGLenum blend_src_factor;
COGLenum blend_dst_factor;
/* Primitives */ /* Primitives */
CoglFixedVec2 path_start; CoglFixedVec2 path_start;

View File

@ -297,6 +297,7 @@ _cogl_texture_download_from_gl (CoglTexture *tex,
for direct copy to framebuffer */ for direct copy to framebuffer */
cogl_paint_init (&cback); cogl_paint_init (&cback);
cogl_color (&cwhite); cogl_color (&cwhite);
cogl_blend_func (CGL_ONE, CGL_ZERO);
/* Draw the texture image */ /* Draw the texture image */
cogl_texture_rectangle (handle, cogl_texture_rectangle (handle,
@ -349,6 +350,7 @@ _cogl_texture_download_from_gl (CoglTexture *tex,
for direct copy to framebuffer */ for direct copy to framebuffer */
cogl_paint_init (&cback); cogl_paint_init (&cback);
cogl_color (&cwhite); cogl_color (&cwhite);
cogl_blend_func (CGL_ONE, CGL_ZERO);
/* Draw a portion of texture */ /* Draw a portion of texture */
cogl_texture_rectangle (handle, cogl_texture_rectangle (handle,

View File

@ -214,12 +214,9 @@ cogl_enable (gulong flags)
*/ */
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
if (cogl_toggle_flag (ctx, flags, cogl_toggle_flag (ctx, flags,
COGL_ENABLE_BLEND, COGL_ENABLE_BLEND,
GL_BLEND)) GL_BLEND);
{
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
cogl_toggle_flag (ctx, flags, cogl_toggle_flag (ctx, flags,
COGL_ENABLE_TEXTURE_2D, COGL_ENABLE_TEXTURE_2D,
@ -246,6 +243,23 @@ cogl_get_enable ()
return ctx->enable_flags; 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 void
cogl_enable_depth_test (gboolean setting) cogl_enable_depth_test (gboolean setting)
{ {