st: Adapt the mutter implementation for create_texture_material

This is the new API that uses set_null_texture instead of a dummy texture.
This commit is contained in:
Jasper St. Pierre 2014-08-07 14:06:40 -04:00
parent 3df7ef6ce6
commit 05f9f991d8

View File

@ -171,38 +171,32 @@ _st_set_text_from_style (ClutterText *text,
CoglHandle CoglHandle
_st_create_texture_material (CoglHandle src_texture) _st_create_texture_material (CoglHandle src_texture)
{ {
static CoglHandle texture_material_template = COGL_INVALID_HANDLE; static CoglPipeline *texture_pipeline_template = NULL;
CoglHandle material; CoglPipeline *pipeline;
g_return_val_if_fail (src_texture != COGL_INVALID_HANDLE, /* The only state used in the pipeline that would affect the shader
COGL_INVALID_HANDLE); generation is the texture type on the layer. Therefore we create
a template pipeline which sets this state and all texture
/* We use a material that has a dummy texture as a base for all pipelines are created as a copy of this. That way Cogl can find
texture materials. The idea is that only the Cogl texture object the shader state for the pipeline more quickly by looking at the
would be different in the children so it is likely that Cogl will pipeline ancestry instead of resorting to the shader cache. */
be able to share GL programs between all the textures. */ if (G_UNLIKELY (texture_pipeline_template == NULL))
if (G_UNLIKELY (texture_material_template == COGL_INVALID_HANDLE))
{ {
static const guint8 white_pixel[] = { 0xff, 0xff, 0xff, 0xff }; CoglContext *ctx =
CoglHandle dummy_texture; clutter_backend_get_cogl_context (clutter_get_default_backend ());
dummy_texture = texture_pipeline_template = cogl_pipeline_new (ctx);
cogl_texture_new_from_data (1, 1, cogl_pipeline_set_layer_null_texture (texture_pipeline_template,
COGL_TEXTURE_NONE, 0, /* layer */
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_TEXTURE_TYPE_2D);
COGL_PIXEL_FORMAT_ANY,
4, white_pixel);
texture_material_template = cogl_material_new ();
cogl_material_set_layer (texture_material_template, 0, dummy_texture);
cogl_handle_unref (dummy_texture);
} }
material = cogl_material_copy (texture_material_template); pipeline = cogl_pipeline_copy (texture_pipeline_template);
cogl_material_set_layer (material, 0, src_texture); if (src_texture != NULL)
cogl_pipeline_set_layer_texture (pipeline, 0, src_texture);
return material; return pipeline;
} }
/***** /*****