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.
This commit is contained in:
Neil Roberts 2010-10-27 15:07:03 +01:00
parent 89cedc7800
commit 65d7a113ee
3 changed files with 7 additions and 10 deletions

View File

@ -130,6 +130,7 @@ cogl_create_context (void)
_context->legacy_fog_state.enabled = FALSE; _context->legacy_fog_state.enabled = FALSE;
_context->simple_material = cogl_material_new (); _context->simple_material = cogl_material_new ();
_context->texture_material = cogl_material_new ();
_context->arbfp_source_buffer = g_string_new (""); _context->arbfp_source_buffer = g_string_new ("");
_context->source_stack = NULL; _context->source_stack = NULL;
@ -268,6 +269,8 @@ _cogl_destroy_context (void)
if (_context->simple_material) if (_context->simple_material)
cogl_handle_unref (_context->simple_material); cogl_handle_unref (_context->simple_material);
if (_context->texture_material)
cogl_handle_unref (_context->texture_material);
if (_context->journal) if (_context->journal)
g_array_free (_context->journal, TRUE); g_array_free (_context->journal, TRUE);

View File

@ -83,7 +83,8 @@ typedef struct
CoglMaterialFogState legacy_fog_state; CoglMaterialFogState legacy_fog_state;
/* Materials */ /* Materials */
CoglMaterial *simple_material; CoglMaterial *simple_material; /* used for set_source_color */
CoglMaterial *texture_material; /* used for set_source_texture */
GString *arbfp_source_buffer; GString *arbfp_source_buffer;
GList *source_stack; GList *source_stack;

View File

@ -373,9 +373,6 @@ cogl_set_source_color (const CoglColor *color)
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _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; premultiplied = *color;
cogl_color_premultiply (&premultiplied); cogl_color_premultiply (&premultiplied);
cogl_material_set_color (ctx->simple_material, &premultiplied); cogl_material_set_color (ctx->simple_material, &premultiplied);
@ -1058,16 +1055,12 @@ cogl_set_source (CoglMaterial *material)
void void
cogl_set_source_texture (CoglHandle texture_handle) cogl_set_source_texture (CoglHandle texture_handle)
{ {
CoglColor white;
_COGL_GET_CONTEXT (ctx, NO_RETVAL); _COGL_GET_CONTEXT (ctx, NO_RETVAL);
g_return_if_fail (texture_handle != NULL); g_return_if_fail (texture_handle != NULL);
cogl_material_set_layer (ctx->simple_material, 0, texture_handle); cogl_material_set_layer (ctx->texture_material, 0, texture_handle);
cogl_color_init_from_4ub (&white, 0xff, 0xff, 0xff, 0xff); cogl_set_source (ctx->texture_material);
cogl_material_set_color (ctx->simple_material, &white);
cogl_set_source (ctx->simple_material);
} }
void void