From af49769b33a4596208cc5496883051ffbba0c0f9 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Tue, 7 Jul 2009 16:16:56 +0100 Subject: [PATCH] [cogl] Fix more brokeness with _cogl_material_equal commit e2c4a2a9f83 fixed one thing but broke many others things :-/ hopfully this fixes that. It turned out that the journal was mistakenly setting the OVERRIDE_LAYER0 flush option for all entries, but some other logic errors were also uncovered in _cogl_material_equal. --- common/cogl-material.c | 73 +++++++++++++++++++++++++++++----------- common/cogl-primitives.c | 7 ++-- 2 files changed, 58 insertions(+), 22 deletions(-) diff --git a/common/cogl-material.c b/common/cogl-material.c index 7ca3c5242..49688d4f4 100644 --- a/common/cogl-material.c +++ b/common/cogl-material.c @@ -1630,6 +1630,29 @@ _cogl_material_flush_gl_state (CoglHandle handle, 0, sizeof (CoglMaterialFlushOptions)); } +static gboolean +_cogl_material_layer_equal (CoglMaterialLayer *material0_layer, + CoglHandle material0_layer_texture, + CoglMaterialLayer *material1_layer, + CoglHandle material1_layer_texture) +{ + if (material0_layer_texture != material1_layer_texture) + return FALSE; + + if ((material0_layer->flags & COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE) != + (material1_layer->flags & COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE)) + return FALSE; + +#if 0 /* TODO */ + if (!_deep_are_layer_combines_equal ()) + return FALSE; +#else + if (!(material0_layer->flags & COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE)) + return FALSE; +#endif + + return TRUE; +} /* This is used by the Cogl journal to compare materials so that it * can split up geometry that needs different OpenGL state. @@ -1781,11 +1804,17 @@ _cogl_material_equal (CoglHandle material0_handle, i = 0; /* NB: At this point we know if COGL_MATERIAL_FLUSH_LAYER0_OVERRIDE is being - * used then both materials are overriding with the same texture so we can - * simply skip over layer 0 */ - if (material0_flush_options->flags & COGL_MATERIAL_FLUSH_LAYER0_OVERRIDE && + * used then both materials are overriding with the same texture. */ + if (flush_flags0 & COGL_MATERIAL_FLUSH_LAYER0_OVERRIDE && l0 && l1) { + /* We still need to check if the combine modes etc are equal, but we + * simply pass COGL_INVALID_HANDLE for both texture handles so they will + * be considered equal */ + if (!_cogl_material_layer_equal (l0->data, COGL_INVALID_HANDLE, + l1->data, COGL_INVALID_HANDLE)) + return FALSE; + l0 = l0->next; l1 = l1->next; i++; @@ -1801,28 +1830,32 @@ _cogl_material_equal (CoglHandle material0_handle, return FALSE; /* NB: At this point we know that the fallback and disable masks for - * both materials are equal */ - if ((disable_layers0 & (1<data; m1_layer = l1->data; - if (m0_layer->texture != m1_layer->texture) - return FALSE; - - if ((m0_layer->flags & COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE) != - (m1_layer->flags & COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE)) - return FALSE; - -#if 0 /* TODO */ - if (!_deep_are_layer_combines_equal ()) - return FALSE; -#else - if (!(m0_layer->flags & COGL_MATERIAL_LAYER_FLAG_DEFAULT_COMBINE)) - return FALSE; -#endif + /* NB: The use of a fallback texture doesn't imply that the combine + * modes etc are the same. + */ + if ((disable_layers0 & (1<texture, + m1_layer, m1_layer->texture)) + return FALSE; + } +next_layer: l0 = l0->next; l1 = l1->next; i++; diff --git a/common/cogl-primitives.c b/common/cogl-primitives.c index e6aa70472..b1a40dfc8 100644 --- a/common/cogl-primitives.c +++ b/common/cogl-primitives.c @@ -732,11 +732,14 @@ _cogl_journal_log_quad (float x_1, entry->flush_options.flags = COGL_MATERIAL_FLUSH_FALLBACK_MASK | COGL_MATERIAL_FLUSH_DISABLE_MASK | - COGL_MATERIAL_FLUSH_LAYER0_OVERRIDE | COGL_MATERIAL_FLUSH_SKIP_GL_COLOR; entry->flush_options.fallback_layers = fallback_layers; entry->flush_options.disable_layers = disable_layers; - entry->flush_options.layer0_override_texture = layer0_override_texture; + if (layer0_override_texture) + { + entry->flush_options.flags |= COGL_MATERIAL_FLUSH_LAYER0_OVERRIDE; + entry->flush_options.layer0_override_texture = layer0_override_texture; + } if (G_UNLIKELY (cogl_debug_flags & COGL_DEBUG_DISABLE_SOFTWARE_TRANSFORM)) cogl_get_modelview_matrix (&entry->model_view);