From 406d0c4a289a1388f9fc1aeb0b6938309b625218 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Tue, 26 Oct 2010 19:02:04 +0100 Subject: [PATCH] material: Bail out faster if re-flushing unchanged material This allows _cogl_material_flush_gl_state to bail out faster if repeatedly asked to flush the same material and we can see the material hasn't changed. Since we can rely on the material age incrementing when any material property changes or any associated layer property changes then we can track the age of the material after flushing so it can be compared with the age of the material if it is subsequently re-flushed. If the age is the same we only have to re-assert the texture object state. --- cogl/cogl-context.h | 1 + cogl/cogl-material-opengl.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cogl/cogl-context.h b/cogl/cogl-context.h index 134b21097..da09fdc39 100644 --- a/cogl/cogl-context.h +++ b/cogl/cogl-context.h @@ -106,6 +106,7 @@ typedef struct CoglMaterial *current_material; unsigned long current_material_changes_since_flush; gboolean current_material_skip_gl_color; + unsigned long current_material_age; GArray *material0_nodes; GArray *material1_nodes; diff --git a/cogl/cogl-material-opengl.c b/cogl/cogl-material-opengl.c index 70d759214..7b7f85baa 100644 --- a/cogl/cogl-material-opengl.c +++ b/cogl/cogl-material-opengl.c @@ -1040,7 +1040,7 @@ _cogl_material_flush_gl_state (CoglMaterial *material, { unsigned long materials_difference; int n_layers; - unsigned long *layer_differences = NULL; + unsigned long *layer_differences; int i; CoglTextureUnit *unit1; @@ -1055,7 +1055,14 @@ _cogl_material_flush_gl_state (CoglMaterial *material, COGL_TIMER_START (_cogl_uprof_context, material_flush_timer); if (ctx->current_material == material) - materials_difference = ctx->current_material_changes_since_flush; + { + /* Bail out asap if we've been asked to re-flush the already current + * material and we can see the material hasn't changed */ + if (ctx->current_material_age == material->age) + goto done; + + materials_difference = ctx->current_material_changes_since_flush; + } else if (ctx->current_material) { materials_difference = ctx->current_material_changes_since_flush; @@ -1079,6 +1086,8 @@ _cogl_material_flush_gl_state (CoglMaterial *material, compare_layer_differences_cb, &state); } + else + layer_differences = NULL; /* First flush everything that's the same regardless of which * material backend is being used... @@ -1174,6 +1183,9 @@ _cogl_material_flush_gl_state (CoglMaterial *material, ctx->current_material = material; ctx->current_material_changes_since_flush = 0; ctx->current_material_skip_gl_color = skip_gl_color; + ctx->current_material_age = material->age; + +done: /* Handle the fact that OpenGL associates texture filter and wrap * modes with the texture objects not the texture units... */