static void glide_image_init (GlideImage *self) { self->priv = GLIDE_IMAGE_GET_PRIVATE (self); self->priv->material = cogl_material_new (); cogl_material_set_layer_filters (self->priv->material, 0, COGL_MATERIAL_FILTER_LINEAR_MIPMAP_LINEAR, COGL_MATERIAL_FILTER_LINEAR); }
static void on_paint (ClutterActor *actor, TestState *state) { CoglHandle tex0, tex1; CoglHandle material; gboolean status; GError *error = NULL; float tex_coords[] = { 0, 0, 0.5, 0.5, /* tex0 */ 0.5, 0.5, 1, 1 /* tex1 */ }; tex0 = make_texture (0x00); tex1 = make_texture (0x11); material = cogl_material_new (); /* An arbitrary color which should be replaced by the first texture layer */ cogl_material_set_color4ub (material, 0x80, 0x80, 0x80, 0x80); cogl_material_set_blend (material, "RGBA = ADD (SRC_COLOR, 0)", NULL); cogl_material_set_layer (material, 0, tex0); cogl_material_set_layer_combine (material, 0, "RGBA = REPLACE (TEXTURE)", NULL); /* We'll use nearest filtering mode on the textures, otherwise the edge of the quad can pull in texels from the neighbouring quarters of the texture due to imprecision */ cogl_material_set_layer_filters (material, 0, COGL_MATERIAL_FILTER_NEAREST, COGL_MATERIAL_FILTER_NEAREST); cogl_material_set_layer (material, 1, tex1); cogl_material_set_layer_filters (material, 1, COGL_MATERIAL_FILTER_NEAREST, COGL_MATERIAL_FILTER_NEAREST); status = cogl_material_set_layer_combine (material, 1, "RGBA = ADD (PREVIOUS, TEXTURE)", &error); if (!status) { /* It's not strictly a test failure; you need a more capable GPU or * driver to test this texture combine string. */ g_debug ("Failed to setup texture combine string " "RGBA = ADD (PREVIOUS, TEXTURE): %s", error->message); } cogl_set_source (material); cogl_rectangle_with_multitexture_coords (0, 0, QUAD_WIDTH, QUAD_WIDTH, tex_coords, 8); cogl_handle_unref (material); cogl_handle_unref (tex0); cogl_handle_unref (tex1); /* See what we got... */ assert_region_color (0, 0, QUAD_WIDTH, QUAD_WIDTH, 0x55, 0x55, 0x55, 0x55); /* Comment this out if you want visual feedback for what this test paints */ #if 1 clutter_main_quit (); #endif }
static void cd_icc_effect_paint_target (ClutterOffscreenEffect *effect) { CdIccEffect *self = CD_ICC_EFFECT (effect); ClutterOffscreenEffectClass *parent; CoglHandle material; CoglHandle color_data; CoglHandle indirect_texture; GError *error = NULL; if (self->program == COGL_INVALID_HANDLE) goto out; if (self->main_texture_uniform > -1) cogl_program_set_uniform_1i (self->program, self->main_texture_uniform, 0); if (self->color_data1_uniform > -1) cogl_program_set_uniform_1i (self->program, self->color_data1_uniform, 1); /* not the layer number, just co-incidence */ if (self->color_data2_uniform > -1) cogl_program_set_uniform_1i (self->program, self->color_data2_uniform, 2); if (self->indirect_texture_uniform > -1) cogl_program_set_uniform_1i (self->program, self->indirect_texture_uniform, 3); material = clutter_offscreen_effect_get_target (effect); /* get the color textures */ color_data = cd_icc_effect_generate_cogl_color_data ("/usr/share/color/icc/FakeBRG.icc", &error); if (color_data == COGL_INVALID_HANDLE) { g_warning ("Error creating lookup texture: %s", error->message); g_error_free (error); goto out; } /* add the texture into the second layer of the material */ cogl_material_set_layer (material, GCM_FSCM_LAYER_COLOR1, color_data); /* we want to use linear interpolation for the texture */ cogl_material_set_layer_filters (material, GCM_FSCM_LAYER_COLOR1, COGL_MATERIAL_FILTER_LINEAR, COGL_MATERIAL_FILTER_LINEAR); /* clamp to the maximum values */ cogl_material_set_layer_wrap_mode (material, GCM_FSCM_LAYER_COLOR1, COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE); cogl_handle_unref (color_data); /* get the color textures */ color_data = cd_icc_effect_generate_cogl_color_data ("/usr/share/color/icc/FakeRBG.icc", &error); if (color_data == COGL_INVALID_HANDLE) { g_warning ("Error creating lookup texture: %s", error->message); g_error_free (error); goto out; } /* add the texture into the second layer of the material */ cogl_material_set_layer (material, GCM_FSCM_LAYER_COLOR2, color_data); /* we want to use linear interpolation for the texture */ cogl_material_set_layer_filters (material, GCM_FSCM_LAYER_COLOR2, COGL_MATERIAL_FILTER_LINEAR, COGL_MATERIAL_FILTER_LINEAR); /* clamp to the maximum values */ cogl_material_set_layer_wrap_mode (material, GCM_FSCM_LAYER_COLOR2, COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE); cogl_handle_unref (color_data); /* get the indirect texture */ indirect_texture = cd_icc_effect_generate_indirect_data (self, &error); if (indirect_texture == COGL_INVALID_HANDLE) { g_warning ("Error creating indirect texture: %s", error->message); g_error_free (error); goto out; } /* add the texture into the second layer of the material */ cogl_material_set_layer (material, GCM_FSCM_LAYER_INDIRECT, indirect_texture); /* we want to use linear interpolation for the texture */ cogl_material_set_layer_filters (material, GCM_FSCM_LAYER_INDIRECT, COGL_MATERIAL_FILTER_LINEAR, COGL_MATERIAL_FILTER_LINEAR); /* clamp to the maximum values */ cogl_material_set_layer_wrap_mode (material, GCM_FSCM_LAYER_INDIRECT, COGL_MATERIAL_WRAP_MODE_CLAMP_TO_EDGE); cogl_handle_unref (indirect_texture); cogl_material_set_user_program (material, self->program); out: parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (cd_icc_effect_parent_class); parent->paint_target (effect); }
/* * Paints the provided texture frame trimming to the area indicated by padding. * * (Basically, we have one asset that gets split into two parts: an border area * that matches the padding, and the inside; MplPanelBackground paints the * latter, while the border is painted by the compositor as the window shadow.) */ static void mpl_panel_background_paint_border_image (CoglHandle *frame, MxPadding *padding) { CoglHandle cogl_texture = COGL_INVALID_HANDLE; CoglHandle cogl_material = COGL_INVALID_HANDLE; ClutterActorBox box = { 0, }; gfloat width, height; gfloat tex_width, tex_height; gfloat ex, ey; gfloat tx1, ty1, tx2, ty2; gfloat left = 4, right = 4 , top = 4, bottom =4; guint8 opacity; ClutterTexture *parent_texture; gfloat margin_l, margin_r, margin_t, margin_b; parent_texture = mx_texture_frame_get_parent_texture (frame); mx_texture_frame_get_border_values (frame, &top, &right, &bottom, &left); /* no need to paint stuff if we don't have a texture */ if (G_UNLIKELY (parent_texture == NULL)) return; /* parent texture may have been hidden, so need to make sure it gets * realized */ if (!CLUTTER_ACTOR_IS_REALIZED (parent_texture)) clutter_actor_realize (CLUTTER_ACTOR (parent_texture)); cogl_texture = clutter_texture_get_cogl_texture (parent_texture); if (cogl_texture == COGL_INVALID_HANDLE) return; cogl_material = clutter_texture_get_cogl_material (parent_texture); if (cogl_material == COGL_INVALID_HANDLE) return; tex_width = cogl_texture_get_width (cogl_texture); tex_height = cogl_texture_get_height (cogl_texture); clutter_actor_get_allocation_box ((ClutterActor*) frame, &box); width = box.x2 - box.x1; height = box.y2 - box.y1; /* * These are the margins we are to trim expressed in texture coordinates. */ margin_l = padding->left / tex_width; margin_r = padding->right / tex_width; margin_t = padding->top / tex_height; margin_b = padding->bottom / tex_height; tx1 = left / tex_width; tx2 = (tex_width - right) / tex_width; ty1 = top / tex_height; ty2 = (tex_height - bottom) / tex_height; ex = width - right; if (ex < 0) ex = right; ey = height - bottom; if (ey < 0) ey = bottom; opacity = clutter_actor_get_paint_opacity ((ClutterActor*)frame); cogl_material_set_color4ub (cogl_material, opacity, opacity, opacity, opacity); cogl_set_source (cogl_material); cogl_material_set_layer_filters (cogl_material, 0, COGL_MATERIAL_FILTER_NEAREST, COGL_MATERIAL_FILTER_NEAREST); { GLfloat rectangles[] = { /* top left corner */ 0.0, 0.0, left, top, margin_l, margin_t, tx1, ty1, /* top middle */ left, 0.0, ex, top, tx1, margin_t, tx2, ty1, /* top right */ ex, 0.0, width, top, tx2, margin_t, 1.0 - margin_r, ty1, /* mid left */ 0.0, top, left, ey, margin_l, ty1, tx1, ty2, /* center */ left, top, ex, ey, tx1, ty1, tx2, ty2, /* mid right */ ex, top, width, ey, tx2, ty1, 1.0 - margin_r, ty2, /* bottom left */ 0.0, ey, left, height, margin_l, ty2, tx1, 1.0 - margin_b, /* bottom center */ left, ey, ex, height, tx1, ty2, tx2, 1.0 - margin_b, /* bottom right */ ex, ey, width, height, tx2, ty2, 1.0 - margin_r, 1.0 - margin_b }; cogl_rectangles_with_texture_coords (rectangles, 9); } }