From 7ab928a4e015fb0df5507c5482b83e113be43396 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Wed, 27 Oct 2010 15:07:03 +0100 Subject: [PATCH] cogl: Use separate materials for set_source_color and texture Previously cogl_set_source_color and cogl_set_source_texture modified a single global material. If an application then mixes using cogl_set_source_color and texture then the material will constantly need a new ARBfp program because the numbers of layers alternates between 0 and 1. This patch just adds a second global material that is only used for cogl_set_source_texture. I think it would still end up flushing the journal if cogl_set_source_texture is used with multiple different textures but at least it should avoid a recompile unless the texture target also changes. It might be nice to somehow attach a material to the CoglTexture for use with cogl_set_source_texture but it would be difficult to implement this without creating a circular reference. --- cogl/cogl-context.c | 3 +++ cogl/cogl-context.h | 3 ++- cogl/cogl.c | 11 ++--------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c index 38954caf6..25aaf1016 100644 --- a/cogl/cogl-context.c +++ b/cogl/cogl-context.c @@ -130,6 +130,7 @@ cogl_create_context (void) _context->legacy_fog_state.enabled = FALSE; _context->simple_material = cogl_material_new (); + _context->texture_material = cogl_material_new (); _context->arbfp_source_buffer = g_string_new (""); _context->source_stack = NULL; @@ -268,6 +269,8 @@ _cogl_destroy_context (void) if (_context->simple_material) cogl_handle_unref (_context->simple_material); + if (_context->texture_material) + cogl_handle_unref (_context->texture_material); if (_context->journal) g_array_free (_context->journal, TRUE); diff --git a/cogl/cogl-context.h b/cogl/cogl-context.h index 50eef3556..134b21097 100644 --- a/cogl/cogl-context.h +++ b/cogl/cogl-context.h @@ -83,7 +83,8 @@ typedef struct CoglMaterialFogState legacy_fog_state; /* Materials */ - CoglMaterial *simple_material; + CoglMaterial *simple_material; /* used for set_source_color */ + CoglMaterial *texture_material; /* used for set_source_texture */ GString *arbfp_source_buffer; GList *source_stack; diff --git a/cogl/cogl.c b/cogl/cogl.c index 8392caf91..f740173ca 100644 --- a/cogl/cogl.c +++ b/cogl/cogl.c @@ -373,9 +373,6 @@ cogl_set_source_color (const CoglColor *color) _COGL_GET_CONTEXT (ctx, NO_RETVAL); - /* In case cogl_set_source_texture was previously used... */ - cogl_material_remove_layer (ctx->simple_material, 0); - premultiplied = *color; cogl_color_premultiply (&premultiplied); cogl_material_set_color (ctx->simple_material, &premultiplied); @@ -1058,16 +1055,12 @@ cogl_set_source (CoglMaterial *material) void cogl_set_source_texture (CoglHandle texture_handle) { - CoglColor white; - _COGL_GET_CONTEXT (ctx, NO_RETVAL); g_return_if_fail (texture_handle != NULL); - cogl_material_set_layer (ctx->simple_material, 0, texture_handle); - cogl_color_init_from_4ub (&white, 0xff, 0xff, 0xff, 0xff); - cogl_material_set_color (ctx->simple_material, &white); - cogl_set_source (ctx->simple_material); + cogl_material_set_layer (ctx->texture_material, 0, texture_handle); + cogl_set_source (ctx->texture_material); } void