cogl-journal: Avoid enabling blending if possible

The vertex attribute API assumes that if there is a color array
enabled then we can't determine if the colors are opaque so we have to
enable blending. The journal always uses a color array to avoid
switching color state between rectangles. Since the journal switched
to using vertex attributes this means we effectively always enable
blending from the journal. To fix this there is now a new flag for
_cogl_draw_vertex_attributes to specify that the color array is known
to only contain opaque colors which causes the draw function not to
copy the pipeline. If the pipeline has blending disabled then the
journal passes this flag.

http://bugzilla.clutter-project.org/show_bug.cgi?id=2481
This commit is contained in:
Neil Roberts 2010-12-14 14:44:45 +00:00
parent 159cd6ddc0
commit d648de7d14
3 changed files with 20 additions and 8 deletions

View File

@ -233,9 +233,9 @@ _cogl_journal_flush_modelview_and_entries (CoglJournalEntry *batch_start,
{
CoglJournalFlushState *state = data;
CoglVertexAttribute **attributes;
static const CoglDrawFlags draw_flags = (COGL_DRAW_SKIP_JOURNAL_FLUSH |
COGL_DRAW_SKIP_PIPELINE_VALIDATION |
COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH);
CoglDrawFlags draw_flags = (COGL_DRAW_SKIP_JOURNAL_FLUSH |
COGL_DRAW_SKIP_PIPELINE_VALIDATION |
COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH);
COGL_STATIC_TIMER (time_flush_modelview_and_entries,
"flush: pipeline+entries", /* parent */
@ -261,6 +261,9 @@ _cogl_journal_flush_modelview_and_entries (CoglJournalEntry *batch_start,
attributes = (CoglVertexAttribute **)state->attributes->data;
cogl_push_source (state->source);
if (!_cogl_pipeline_get_real_blend_enabled (state->source))
draw_flags |= COGL_DRAW_COLOR_ATTRIBUTE_IS_OPAQUE;
#ifdef HAVE_COGL_GL
/* XXX: it's rather evil that we sneak in the GL_QUADS enum here... */

View File

@ -61,7 +61,14 @@ typedef enum
{
COGL_DRAW_SKIP_JOURNAL_FLUSH = 1 << 0,
COGL_DRAW_SKIP_PIPELINE_VALIDATION = 1 << 1,
COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH = 1 << 2
COGL_DRAW_SKIP_FRAMEBUFFER_FLUSH = 1 << 2,
/* By default the vertex attribute drawing code will assume that if
there is a color attribute array enabled then we can't determine
if the colors will be opaque so we need to enabling
blending. However when drawing from the journal we know what the
contents of the color array is so we can override this by passing
this flag. */
COGL_DRAW_COLOR_ATTRIBUTE_IS_OPAQUE = 1 << 3
} CoglDrawFlags;
CoglVertexAttribute *

View File

@ -474,7 +474,8 @@ set_enabled_arrays (CoglBitmask *value_cache,
}
static CoglHandle
enable_gl_state (CoglVertexAttribute **attributes,
enable_gl_state (CoglDrawFlags flags,
CoglVertexAttribute **attributes,
ValidateLayerState *state)
{
int i;
@ -498,7 +499,8 @@ enable_gl_state (CoglVertexAttribute **attributes,
switch (attributes[i]->name_id)
{
case COGL_VERTEX_ATTRIBUTE_NAME_ID_COLOR_ARRAY:
if (!_cogl_pipeline_get_real_blend_enabled (source))
if ((flags & COGL_DRAW_COLOR_ATTRIBUTE_IS_OPAQUE) == 0 &&
!_cogl_pipeline_get_real_blend_enabled (source))
{
CoglPipelineBlendEnable blend_enable =
COGL_PIPELINE_BLEND_ENABLE_ENABLED;
@ -1082,7 +1084,7 @@ _cogl_draw_vertex_attributes_array (CoglVerticesMode mode,
flush_state (flags, &state);
source = enable_gl_state (attributes, &state);
source = enable_gl_state (flags, attributes, &state);
GE (glDrawArrays ((GLenum)mode, first_vertex, n_vertices));
@ -1171,7 +1173,7 @@ _cogl_draw_indexed_vertex_attributes_array (CoglVerticesMode mode,
flush_state (flags, &state);
source = enable_gl_state (attributes, &state);
source = enable_gl_state (flags, attributes, &state);
buffer = COGL_BUFFER (cogl_indices_get_array (indices));
base = _cogl_buffer_bind (buffer, COGL_BUFFER_BIND_TARGET_INDEX_ARRAY);