cogl: add separate material for blended source_colors

When using cogl_set_source_color4ub there is a notable difference
between colors that require blending and those that dont. When trying to
modify the color of pipeline referenced by the journal we don't force a
flush of the journal unless the color change will also change the
blending state. By using two separate pipeline objects for handing
opaque or transparent colors we can avoid ever flushing the journal when
repeatedly using cogl_set_source_color and jumping between opaque and
transparent colors.
This commit is contained in:
Robert Bragg 2010-11-01 20:27:32 +00:00
parent d05ce7cd26
commit eaee5dd604
3 changed files with 25 additions and 12 deletions

View File

@ -129,7 +129,8 @@ cogl_create_context (void)
_context->legacy_fog_state.enabled = FALSE;
_context->simple_pipeline = cogl_pipeline_new ();
_context->opaque_color_pipeline = cogl_pipeline_new ();
_context->blended_color_pipeline = cogl_pipeline_new ();
_context->texture_pipeline = cogl_pipeline_new ();
_context->arbfp_source_buffer = g_string_new ("");
_context->source_stack = NULL;
@ -237,8 +238,8 @@ cogl_create_context (void)
0, /* auto calc row stride */
default_texture_data);
cogl_push_source (_context->simple_pipeline);
_cogl_pipeline_flush_gl_state (_context->simple_pipeline, FALSE);
cogl_push_source (_context->opaque_color_pipeline);
_cogl_pipeline_flush_gl_state (_context->opaque_color_pipeline, FALSE);
_cogl_enable (enable_flags);
_cogl_flush_face_winding ();
@ -277,8 +278,10 @@ _cogl_destroy_context (void)
if (_context->default_gl_texture_rect_tex)
cogl_handle_unref (_context->default_gl_texture_rect_tex);
if (_context->simple_pipeline)
cogl_handle_unref (_context->simple_pipeline);
if (_context->opaque_color_pipeline)
cogl_handle_unref (_context->opaque_color_pipeline);
if (_context->blended_color_pipeline)
cogl_handle_unref (_context->blended_color_pipeline);
if (_context->texture_pipeline)
cogl_handle_unref (_context->texture_pipeline);

View File

@ -82,8 +82,9 @@ typedef struct
CoglPipelineFogState legacy_fog_state;
/* Materials */
CoglPipeline *simple_pipeline; /* used for set_source_color */
/* Pipelines */
CoglPipeline *opaque_color_pipeline; /* used for set_source_color */
CoglPipeline *blended_color_pipeline; /* used for set_source_color */
CoglPipeline *texture_pipeline; /* used for set_source_texture */
GString *arbfp_source_buffer;
GList *source_stack;

View File

@ -379,15 +379,24 @@ _cogl_flush_face_winding (void)
void
cogl_set_source_color (const CoglColor *color)
{
CoglColor premultiplied;
CoglPipeline *pipeline;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
premultiplied = *color;
if (cogl_color_get_alpha_byte (color) == 0xff)
{
cogl_pipeline_set_color (ctx->opaque_color_pipeline, color);
pipeline = ctx->opaque_color_pipeline;
}
else
{
CoglColor premultiplied = *color;
cogl_color_premultiply (&premultiplied);
cogl_pipeline_set_color (ctx->simple_pipeline, &premultiplied);
cogl_pipeline_set_color (ctx->blended_color_pipeline, &premultiplied);
pipeline = ctx->blended_color_pipeline;
}
cogl_set_source (ctx->simple_pipeline);
cogl_set_source (pipeline);
}
void