コード例 #1
0
ファイル: clutter-colorize-effect.c プロジェクト: rib/clutter
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);
}
コード例 #2
0
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);
}
コード例 #3
0
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);
}
コード例 #4
0
static void
clutter_shader_effect_paint_target (ClutterOffscreenEffect *effect)
{
  ClutterShaderEffectPrivate *priv = CLUTTER_SHADER_EFFECT (effect)->priv;
  ClutterOffscreenEffectClass *parent;
  CoglHandle material;

  /* we haven't been prepared or we don't have support for
   * GLSL shaders in Clutter
   */
  if (priv->program == COGL_INVALID_HANDLE ||
      priv->shader == COGL_INVALID_HANDLE)
    goto out;

  if (!priv->source_set)
    goto out;

  if (!priv->is_compiled)
    {
      CLUTTER_NOTE (SHADER, "Compiling shader effect");

      cogl_shader_compile (priv->shader);
      if (!cogl_shader_is_compiled (priv->shader))
        {
          gchar *log_buf = cogl_shader_get_info_log (priv->shader);

          g_warning ("Unable to compile the GLSL shader: %s", log_buf);
          g_free (log_buf);

          cogl_handle_unref (priv->shader);
          priv->shader = COGL_INVALID_HANDLE;

          cogl_handle_unref (priv->program);
          priv->shader = COGL_INVALID_HANDLE;

          goto out;
        }

      cogl_program_attach_shader (priv->program, priv->shader);
      cogl_handle_unref (priv->shader);

      cogl_program_link (priv->program);

      priv->is_compiled = TRUE;
    }

  CLUTTER_NOTE (SHADER, "Applying the shader effect of type '%s'",
                G_OBJECT_TYPE_NAME (effect));

  clutter_shader_effect_update_uniforms (CLUTTER_SHADER_EFFECT (effect));

  /* associate the program to the offscreen target material */
  material = clutter_offscreen_effect_get_target (effect);
  cogl_material_set_user_program (material, priv->program);

out:
  /* paint the offscreen buffer */
  parent = CLUTTER_OFFSCREEN_EFFECT_CLASS (clutter_shader_effect_parent_class);
  parent->paint_target (effect);

}
コード例 #5
0
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);
}