/** * meta_create_texture_material: * @src_texture: (allow-none): texture to use initially for the layer * * Creates a material with a single layer. Using a common template * allows sharing a shader for different uses in Muffin. To share the same * shader with all other materials that are just texture plus opacity * would require Cogl fixes. * (See http://bugzilla.clutter-project.org/show_bug.cgi?id=2425) * * Return value: (transfer full): a newly created Cogl material */ CoglHandle meta_create_texture_material (CoglHandle src_texture) { static CoglHandle texture_material_template = COGL_INVALID_HANDLE; CoglHandle material; /* We use a material that has a dummy texture as a base for all texture materials. The idea is that only the Cogl texture object would be different in the children so it is likely that Cogl will be able to share GL programs between all the textures. */ if (G_UNLIKELY (texture_material_template == COGL_INVALID_HANDLE)) { CoglHandle dummy_texture; dummy_texture = meta_create_color_texture_4ub (0xff, 0xff, 0xff, 0xff, COGL_TEXTURE_NONE); 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); if (src_texture != COGL_INVALID_HANDLE) cogl_material_set_layer (material, 0, src_texture); return material; }
/** * _st_create_texture_material: * @src_texture: The CoglTexture for the material * * Creates a simple material which contains the given texture as a * single layer. */ CoglHandle _st_create_texture_material (CoglHandle src_texture) { static CoglHandle texture_material_template = COGL_INVALID_HANDLE; CoglHandle material; g_return_val_if_fail (src_texture != COGL_INVALID_HANDLE, COGL_INVALID_HANDLE); /* We use a material that has a dummy texture as a base for all texture materials. The idea is that only the Cogl texture object would be different in the children so it is likely that Cogl will be able to share GL programs between all the textures. */ if (G_UNLIKELY (texture_material_template == COGL_INVALID_HANDLE)) { static const guint8 white_pixel[] = { 0xff, 0xff, 0xff, 0xff }; CoglHandle dummy_texture; dummy_texture = st_cogl_texture_new_from_data_wrapper (1, 1, COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_RGBA_8888_PRE, 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); cogl_material_set_layer (material, 0, src_texture); return material; }
CoglHandle _st_create_shadow_material (StShadow *shadow_spec, CoglHandle src_texture) { static CoglHandle shadow_material_template = COGL_INVALID_HANDLE; CoglHandle material; CoglHandle texture; guchar *pixels_in, *pixels_out; gint width_in, height_in, rowstride_in; gint width_out, height_out, rowstride_out; g_return_val_if_fail (shadow_spec != NULL, COGL_INVALID_HANDLE); g_return_val_if_fail (src_texture != COGL_INVALID_HANDLE, COGL_INVALID_HANDLE); width_in = cogl_texture_get_width (src_texture); height_in = cogl_texture_get_height (src_texture); rowstride_in = (width_in + 3) & ~3; pixels_in = g_malloc0 (rowstride_in * height_in); cogl_texture_get_data (src_texture, COGL_PIXEL_FORMAT_A_8, rowstride_in, pixels_in); pixels_out = blur_pixels (pixels_in, width_in, height_in, rowstride_in, shadow_spec->blur, &width_out, &height_out, &rowstride_out); g_free (pixels_in); texture = cogl_texture_new_from_data (width_out, height_out, COGL_TEXTURE_NONE, COGL_PIXEL_FORMAT_A_8, COGL_PIXEL_FORMAT_A_8, rowstride_out, pixels_out); g_free (pixels_out); if (G_UNLIKELY (shadow_material_template == COGL_INVALID_HANDLE)) { shadow_material_template = cogl_material_new (); /* We set up the material to blend the shadow texture with the combine * constant, but defer setting the latter until painting, so that we can * take the actor's overall opacity into account. */ cogl_material_set_layer_combine (shadow_material_template, 0, "RGBA = MODULATE (CONSTANT, TEXTURE[A])", NULL); } material = cogl_material_copy (shadow_material_template); cogl_material_set_layer (material, 0, texture); cogl_handle_unref (texture); return material; }
void mx_texture_frame_paint_texture (CoglHandle texture, guint8 opacity, gfloat top, gfloat right, gfloat bottom, gfloat left, gfloat width, gfloat height) { CoglHandle material; /* setup the template material */ if (!template_material) template_material = cogl_material_new (); /* create the material and apply opacity */ material = cogl_material_copy (template_material); mx_texture_frame_paint_texture_internal (material, texture, opacity, top, right, bottom, left, width, height); cogl_handle_unref (material); }
static void mex_tile_init (MexTile *self) { MexTilePrivate *priv = self->priv = TILE_PRIVATE (self); const ClutterColor opaque = { 0x00, 0x00, 0x00, 0x00 }; ClutterEffect *fade; /* create a template material for the header background from which cheap * copies can be made for each instance */ if (G_UNLIKELY (!template_material)) template_material = cogl_material_new (); priv->material = cogl_material_copy (template_material); /* layout for primary and secondary labels */ priv->box_layout = mx_box_layout_new (); mx_box_layout_set_spacing (MX_BOX_LAYOUT (priv->box_layout), 12); /* add fade effect to the box layout */ fade = (ClutterEffect*) mx_fade_effect_new (); mx_fade_effect_set_border (MX_FADE_EFFECT (fade), 0, 50, 0, 0); mx_fade_effect_set_color (MX_FADE_EFFECT (fade), &opaque); clutter_actor_add_effect_with_name (priv->box_layout, "fade", fade); clutter_actor_meta_set_enabled (CLUTTER_ACTOR_META (fade), TRUE); clutter_actor_push_internal (CLUTTER_ACTOR (self)); clutter_actor_set_parent (priv->box_layout, CLUTTER_ACTOR (self)); clutter_actor_pop_internal (CLUTTER_ACTOR (self)); priv->label = clutter_text_new (); priv->secondary_label = clutter_text_new (); clutter_actor_set_opacity (priv->secondary_label, 128); clutter_container_add (CLUTTER_CONTAINER (priv->box_layout), priv->label, priv->secondary_label, NULL); priv->header_visible = TRUE; priv->timeline = clutter_timeline_new (DURATION); priv->important_alpha = clutter_alpha_new_full (priv->timeline, CLUTTER_EASE_OUT_QUAD); g_signal_connect_object (priv->timeline, "new-frame", G_CALLBACK (mex_tile_important_new_frame_cb), self, 0); g_signal_connect_object (priv->timeline, "completed", G_CALLBACK (mex_tile_timeline_completed_cb), self, 0); g_signal_connect (self, "style-changed", G_CALLBACK (mex_tile_style_changed_cb), NULL); g_signal_connect (self, "actor-added", G_CALLBACK (mex_tile_actor_added), NULL); g_signal_connect (self, "actor-removed", G_CALLBACK (mex_tile_actor_removed), NULL); }
static gboolean setup_framebuffers (StThemeNodeTransition *transition, const ClutterActorBox *allocation) { StThemeNodeTransitionPrivate *priv = transition->priv; CoglColor clear_color = { 0, 0, 0, 0 }; guint width, height; /* template material to avoid unnecessary shader compilation */ static CoglHandle material_template = COGL_INVALID_HANDLE; width = priv->offscreen_box.x2 - priv->offscreen_box.x1; height = priv->offscreen_box.y2 - priv->offscreen_box.y1; g_return_val_if_fail (width > 0, FALSE); g_return_val_if_fail (height > 0, FALSE); if (priv->old_texture) cogl_handle_unref (priv->old_texture); priv->old_texture = cogl_texture_new_with_size (width, height, COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_ANY); if (priv->new_texture) cogl_handle_unref (priv->new_texture); priv->new_texture = cogl_texture_new_with_size (width, height, COGL_TEXTURE_NO_SLICING, COGL_PIXEL_FORMAT_ANY); g_return_val_if_fail (priv->old_texture != COGL_INVALID_HANDLE, FALSE); g_return_val_if_fail (priv->new_texture != COGL_INVALID_HANDLE, FALSE); if (priv->old_offscreen) cogl_handle_unref (priv->old_offscreen); priv->old_offscreen = cogl_offscreen_new_to_texture (priv->old_texture); if (priv->new_offscreen) cogl_handle_unref (priv->new_offscreen); priv->new_offscreen = cogl_offscreen_new_to_texture (priv->new_texture); g_return_val_if_fail (priv->old_offscreen != COGL_INVALID_HANDLE, FALSE); g_return_val_if_fail (priv->new_offscreen != COGL_INVALID_HANDLE, FALSE); if (priv->material == NULL) { if (G_UNLIKELY (material_template == COGL_INVALID_HANDLE)) { material_template = cogl_material_new (); cogl_material_set_layer_combine (material_template, 0, "RGBA = REPLACE (TEXTURE)", NULL); cogl_material_set_layer_combine (material_template, 1, "RGBA = INTERPOLATE (PREVIOUS, " "TEXTURE, " "CONSTANT[A])", NULL); cogl_material_set_layer_combine (material_template, 2, "RGBA = MODULATE (PREVIOUS, " "PRIMARY)", NULL); } priv->material = cogl_material_copy (material_template); } cogl_material_set_layer (priv->material, 0, priv->new_texture); cogl_material_set_layer (priv->material, 1, priv->old_texture); cogl_push_framebuffer (priv->old_offscreen); cogl_clear (&clear_color, COGL_BUFFER_BIT_COLOR); cogl_ortho (priv->offscreen_box.x1, priv->offscreen_box.x2, priv->offscreen_box.y2, priv->offscreen_box.y1, 0.0, 1.0); st_theme_node_paint (priv->old_theme_node, allocation, 255); cogl_pop_framebuffer (); cogl_push_framebuffer (priv->new_offscreen); cogl_clear (&clear_color, COGL_BUFFER_BIT_COLOR); cogl_ortho (priv->offscreen_box.x1, priv->offscreen_box.x2, priv->offscreen_box.y2, priv->offscreen_box.y1, 0.0, 1.0); st_theme_node_paint (priv->new_theme_node, allocation, 255); cogl_pop_framebuffer (); return TRUE; }