static void st_scroll_view_fade_paint_target (ClutterOffscreenEffect *effect) { StScrollViewFade *self = ST_SCROLL_VIEW_FADE (effect); ClutterOffscreenEffectClass *parent; CoglHandle material; gdouble value, lower, upper, page_size; ClutterActor *vscroll = st_scroll_view_get_vscroll_bar (ST_SCROLL_VIEW (self->actor)); ClutterActor *hscroll = st_scroll_view_get_hscroll_bar (ST_SCROLL_VIEW (self->actor)); gboolean h_scroll_visible, v_scroll_visible; g_object_get (ST_SCROLL_VIEW (self->actor), "hscrollbar-visible", &h_scroll_visible, "vscrollbar-visible", &v_scroll_visible, NULL); if (self->program == COGL_INVALID_HANDLE) goto out; st_adjustment_get_values (self->vadjustment, &value, &lower, &upper, NULL, NULL, &page_size); if (self->offset_top_uniform > -1) { if (value > lower + 0.1) cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, self->fade_offset); else cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, 0.0f); } if (self->offset_bottom_uniform > -1) { if (value < upper - page_size - 0.1) cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, self->fade_offset); else cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, 0.0f); } if (self->tex_uniform > -1) cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0); if (self->height_uniform > -1) cogl_program_set_uniform_1f (self->program, self->height_uniform, clutter_actor_get_height (self->actor)); if (self->width_uniform > -1) cogl_program_set_uniform_1f (self->program, self->width_uniform, clutter_actor_get_width (self->actor)); if (self->scrollbar_width_uniform > -1) cogl_program_set_uniform_1f (self->program, self->scrollbar_width_uniform, v_scroll_visible ? clutter_actor_get_width (vscroll) : 0); if (self->scrollbar_height_uniform > -1) cogl_program_set_uniform_1f (self->program, self->scrollbar_height_uniform, h_scroll_visible ? clutter_actor_get_height (hscroll) : 0); if (self->rtl_uniform > -1) cogl_program_set_uniform_1i (self->program, self->rtl_uniform, (st_widget_get_direction (ST_WIDGET (self->actor)) == ST_TEXT_DIRECTION_RTL)); material = clutter_offscreen_effect_get_target (effect); cogl_material_set_user_program (material, self->program); out: parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (st_scroll_view_fade_parent_class); parent->paint_target (effect); }
static void clutter_colorize_effect_paint_target (ClutterOffscreenEffect *effect) { ClutterColorizeEffect *self = CLUTTER_COLORIZE_EFFECT (effect); ClutterOffscreenEffectClass *parent; CoglHandle material; if (self->program == COGL_INVALID_HANDLE) goto out; if (self->tex_uniform > -1) cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0); if (self->tint_uniform > -1) { float tint[3] = { self->tint.red / 255.0, self->tint.green / 255.0, self->tint.blue / 255.0 }; cogl_program_set_uniform_float (self->program, self->tint_uniform, 3, 1, tint); } material = clutter_offscreen_effect_get_target (effect); cogl_material_set_user_program (material, self->program); out: parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (clutter_colorize_effect_parent_class); parent->paint_target (effect); }
static void st_scroll_view_fade_paint_target (ClutterOffscreenEffect *effect) { StScrollViewFade *self = ST_SCROLL_VIEW_FADE (effect); ClutterOffscreenEffectClass *parent; CoglHandle material; gdouble value, lower, upper, page_size; ClutterActor *vscroll = st_scroll_view_get_vscroll_bar (ST_SCROLL_VIEW (self->actor)); ClutterActor *hscroll = st_scroll_view_get_hscroll_bar (ST_SCROLL_VIEW (self->actor)); gboolean h_scroll_visible, v_scroll_visible; ClutterActorBox allocation, content_box, paint_box; /* * Used to pass the fade area to the shader * * [0][0] = x1 * [0][1] = y1 * [1][0] = x2 * [1][1] = y2 * */ float fade_area[2][2]; ClutterVertex verts[4]; if (self->program == COGL_INVALID_HANDLE) goto out; clutter_actor_get_paint_box (self->actor, &paint_box); clutter_actor_get_abs_allocation_vertices (self->actor, verts); clutter_actor_get_allocation_box (self->actor, &allocation); st_theme_node_get_content_box (st_widget_get_theme_node (ST_WIDGET (self->actor)), (const ClutterActorBox *)&allocation, &content_box); /* * The FBO is based on the paint_volume's size which can be larger then the actual * allocation, so we have to account for that when passing the positions */ fade_area[0][0] = content_box.x1 + (verts[0].x - paint_box.x1); fade_area[0][1] = content_box.y1 + (verts[0].y - paint_box.y1); fade_area[1][0] = content_box.x2 + (verts[3].x - paint_box.x2); fade_area[1][1] = content_box.y2 + (verts[3].y - paint_box.y2); g_object_get (ST_SCROLL_VIEW (self->actor), "hscrollbar-visible", &h_scroll_visible, "vscrollbar-visible", &v_scroll_visible, NULL); if (v_scroll_visible) { if (st_widget_get_direction (ST_WIDGET (self->actor)) == ST_TEXT_DIRECTION_RTL) fade_area[0][0] += clutter_actor_get_width (vscroll); fade_area[1][0] -= clutter_actor_get_width (vscroll); } if (h_scroll_visible) fade_area[1][1] -= clutter_actor_get_height (hscroll); st_adjustment_get_values (self->vadjustment, &value, &lower, &upper, NULL, NULL, &page_size); if (self->offset_top_uniform > -1) { if (value > lower + 0.1) cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, self->fade_offset); else cogl_program_set_uniform_1f (self->program, self->offset_top_uniform, 0.0f); } if (self->offset_bottom_uniform > -1) { if (value < upper - page_size - 0.1) cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, self->fade_offset); else cogl_program_set_uniform_1f (self->program, self->offset_bottom_uniform, 0.0f); } if (self->tex_uniform > -1) cogl_program_set_uniform_1i (self->program, self->tex_uniform, 0); if (self->height_uniform > -1) cogl_program_set_uniform_1f (self->program, self->height_uniform, clutter_actor_get_height (self->actor)); if (self->width_uniform > -1) cogl_program_set_uniform_1f (self->program, self->width_uniform, clutter_actor_get_width (self->actor)); if (self->fade_area_uniform > -1) cogl_program_set_uniform_matrix (self->program, self->fade_area_uniform, 2, 1, FALSE, (const float *)fade_area); material = clutter_offscreen_effect_get_target (effect); cogl_material_set_user_program (material, self->program); out: parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (st_scroll_view_fade_parent_class); parent->paint_target (effect); }
static void rc_set_shader(CoglHandle material, const RendererClutterShaderInfo *shaderInfo) { CoglHandle shader; CoglHandle program; gint uniform_no; shader = cogl_create_shader (COGL_SHADER_TYPE_FRAGMENT); cogl_shader_source (shader, "vec3 checker(vec2 texc, vec3 color0, vec3 color1) \n" "{ \n" " if (mod(floor(texc.x) + floor(texc.y), 2.0) == 0.0) \n" " return color0; \n" " else \n" " return color1; \n" "} \n" " \n" "uniform sampler2D tex; \n" "uniform sampler3D clut; \n" "uniform float scale; \n" "uniform float offset; \n" "uniform float checkersize; \n" "uniform vec3 color0; \n" "uniform vec3 color1; \n" " \n" "void main(void) \n" "{ \n" " vec3 bg = checker(gl_FragCoord.xy / checkersize, color0, color1); \n" " vec4 img4 = texture2D(tex, gl_TexCoord[0].xy); \n" " vec3 img3 = img4.bgr; \n" " img3 = img3 * scale + offset; \n" " img3 = texture3D(clut, img3).rgb; \n" " \n" " gl_FragColor = vec4(img3 * img4.a + bg * (1.0 - img4.a), 1.0); \n" "} \n" ); cogl_shader_compile(shader); gchar *err = cogl_shader_get_info_log(shader); DEBUG_3("%s\n",err); g_free(err); program = cogl_create_program (); cogl_program_attach_shader (program, shader); cogl_handle_unref (shader); cogl_program_link (program); uniform_no = cogl_program_get_uniform_location (program, "tex"); cogl_program_set_uniform_1i (program, uniform_no, 0); uniform_no = cogl_program_get_uniform_location (program, "clut"); cogl_program_set_uniform_1i (program, uniform_no, 1); uniform_no = cogl_program_get_uniform_location (program, "scale"); cogl_program_set_uniform_1f (program, uniform_no, (double) (CLUT_SIZE - 1) / CLUT_SIZE); uniform_no = cogl_program_get_uniform_location (program, "offset"); cogl_program_set_uniform_1f (program, uniform_no, 1.0 / (2 * CLUT_SIZE)); uniform_no = cogl_program_get_uniform_location (program, "checkersize"); cogl_program_set_uniform_1f (program, uniform_no, shaderInfo->checkersize); uniform_no = cogl_program_get_uniform_location (program, "color0"); cogl_program_set_uniform_float (program, uniform_no, 3, 1, shaderInfo->checkercolor0); uniform_no = cogl_program_get_uniform_location (program, "color1"); cogl_program_set_uniform_float (program, uniform_no, 3, 1, shaderInfo->checkercolor1); cogl_material_set_user_program (material, program); cogl_handle_unref (program); }
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); }