cogl-blend-string: Don't split combined blend statements into two

When a single statement is used to specify the factors for both the
RGB and alpha parts it previously split up the statement into
two. This works but it ends up unnecessarily using glBlendFuncSeparate
when glBlendFunc would suffice.

For example, the blend statement

 RGBA = ADD(SRC_COLOR*(SRC_COLOR), DST_COLOR*(1-SRC_COLOR))

would get split into the two statements

 RGBA = ADD(SRC_COLOR*(SRC_COLOR[RGB]), DST_COLOR*(1-SRC_COLOR[RGB]))
 A    = ADD(SRC_COLOR*(SRC_COLOR[A]), DST_COLOR*(1-SRC_COLOR[A]))

That translates to:

 glBlendFuncSeparate (GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR,
                      GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

This patch makes it so that arg_to_gl_blend_factor can handle the
combined RGBA mask instead. That way the single statement gets
translated to the equivalent call:

 glBlendFunc (GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
This commit is contained in:
Neil Roberts 2010-05-12 17:56:25 +01:00
parent 47d5493016
commit 502446ed8d

View File

@ -563,7 +563,7 @@ arg_to_gl_blend_factor (CoglBlendStringArgument *arg)
else if (arg->factor.source.info->type == else if (arg->factor.source.info->type ==
COGL_BLEND_STRING_COLOR_SOURCE_SRC_COLOR) COGL_BLEND_STRING_COLOR_SOURCE_SRC_COLOR)
{ {
if (arg->factor.source.mask == COGL_BLEND_STRING_CHANNEL_MASK_RGB) if (arg->factor.source.mask != COGL_BLEND_STRING_CHANNEL_MASK_ALPHA)
{ {
if (arg->factor.source.one_minus) if (arg->factor.source.one_minus)
return GL_ONE_MINUS_SRC_COLOR; return GL_ONE_MINUS_SRC_COLOR;
@ -581,7 +581,7 @@ arg_to_gl_blend_factor (CoglBlendStringArgument *arg)
else if (arg->factor.source.info->type == else if (arg->factor.source.info->type ==
COGL_BLEND_STRING_COLOR_SOURCE_DST_COLOR) COGL_BLEND_STRING_COLOR_SOURCE_DST_COLOR)
{ {
if (arg->factor.source.mask == COGL_BLEND_STRING_CHANNEL_MASK_RGB) if (arg->factor.source.mask != COGL_BLEND_STRING_CHANNEL_MASK_ALPHA)
{ {
if (arg->factor.source.one_minus) if (arg->factor.source.one_minus)
return GL_ONE_MINUS_DST_COLOR; return GL_ONE_MINUS_DST_COLOR;
@ -600,7 +600,7 @@ arg_to_gl_blend_factor (CoglBlendStringArgument *arg)
else if (arg->factor.source.info->type == else if (arg->factor.source.info->type ==
COGL_BLEND_STRING_COLOR_SOURCE_CONSTANT) COGL_BLEND_STRING_COLOR_SOURCE_CONSTANT)
{ {
if (arg->factor.source.mask == COGL_BLEND_STRING_CHANNEL_MASK_RGB) if (arg->factor.source.mask != COGL_BLEND_STRING_CHANNEL_MASK_ALPHA)
{ {
if (arg->factor.source.one_minus) if (arg->factor.source.one_minus)
return GL_ONE_MINUS_CONSTANT_COLOR; return GL_ONE_MINUS_CONSTANT_COLOR;
@ -651,7 +651,6 @@ cogl_material_set_blend (CoglHandle handle,
{ {
CoglMaterial *material; CoglMaterial *material;
CoglBlendStringStatement statements[2]; CoglBlendStringStatement statements[2];
CoglBlendStringStatement split[2];
CoglBlendStringStatement *rgb; CoglBlendStringStatement *rgb;
CoglBlendStringStatement *a; CoglBlendStringStatement *a;
GError *internal_error = NULL; GError *internal_error = NULL;
@ -679,13 +678,8 @@ cogl_material_set_blend (CoglHandle handle,
return FALSE; return FALSE;
} }
if (statements[0].mask == COGL_BLEND_STRING_CHANNEL_MASK_RGBA) if (count == 1)
{ rgb = a = statements;
_cogl_blend_string_split_rgba_statement (statements,
&split[0], &split[1]);
rgb = &split[0];
a = &split[1];
}
else else
{ {
rgb = &statements[0]; rgb = &statements[0];