Exemplo n.º 1
0
static void
paint_test_backface_culling (TestState *state)
{
  int draw_num;
  CoglPipeline *base_pipeline = cogl_pipeline_new ();
  CoglColor clear_color;

  cogl_ortho (0, state->width, /* left, right */
              state->height, 0, /* bottom, top */
              -1, 100 /* z near, far */);

  cogl_color_init_from_4ub (&clear_color, 0x00, 0x00, 0x00, 0xff);
  cogl_clear (&clear_color, COGL_BUFFER_BIT_COLOR | COGL_BUFFER_BIT_STENCIL);

  cogl_pipeline_set_layer_texture (base_pipeline, 0, state->texture);

  cogl_pipeline_set_layer_filters (base_pipeline, 0,
                                   COGL_PIPELINE_FILTER_NEAREST,
                                   COGL_PIPELINE_FILTER_NEAREST);

  /* Render the scene sixteen times to test all of the combinations of
     cull face mode, legacy state and winding orders */
  for (draw_num = 0; draw_num < 16; draw_num++)
    {
      float x1 = 0, x2, y1 = 0, y2 = (float)(TEXTURE_RENDER_SIZE);
      CoglTextureVertex verts[4];
      CoglPipeline *pipeline;

      cogl_push_matrix ();
      cogl_translate (0, TEXTURE_RENDER_SIZE * draw_num, 0);

      pipeline = cogl_pipeline_copy (base_pipeline);

      cogl_set_backface_culling_enabled (USE_LEGACY_STATE (draw_num));
      cogl_pipeline_set_front_face_winding (pipeline, FRONT_WINDING (draw_num));
      cogl_pipeline_set_cull_face_mode (pipeline, CULL_FACE_MODE (draw_num));

      cogl_push_source (pipeline);

      memset (verts, 0, sizeof (verts));

      x2 = x1 + (float)(TEXTURE_RENDER_SIZE);

      /* Draw a front-facing texture */
      cogl_rectangle (x1, y1, x2, y2);

      x1 = x2;
      x2 = x1 + (float)(TEXTURE_RENDER_SIZE);

      /* Draw a front-facing texture with flipped texcoords */
      cogl_rectangle_with_texture_coords (x1, y1, x2, y2,
                                          1.0, 0.0, 0.0, 1.0);

      x1 = x2;
      x2 = x1 + (float)(TEXTURE_RENDER_SIZE);

      /* Draw a back-facing texture */
      cogl_rectangle (x2, y1, x1, y2);

      x1 = x2;
      x2 = x1 + (float)(TEXTURE_RENDER_SIZE);

      /* If the texture is sliced then cogl_polygon doesn't work so
         we'll just use a solid color instead */
      if (cogl_texture_is_sliced (state->texture))
        cogl_set_source_color4ub (255, 0, 0, 255);

      /* Draw a front-facing polygon */
      verts[0].x = x1;    verts[0].y = y2;
      verts[1].x = x2;    verts[1].y = y2;
      verts[2].x = x2;    verts[2].y = y1;
      verts[3].x = x1;    verts[3].y = y1;
      verts[0].tx = 0;    verts[0].ty = 0;
      verts[1].tx = 1.0;  verts[1].ty = 0;
      verts[2].tx = 1.0;  verts[2].ty = 1.0;
      verts[3].tx = 0;    verts[3].ty = 1.0;
      cogl_polygon (verts, 4, FALSE);

      x1 = x2;
      x2 = x1 + (float)(TEXTURE_RENDER_SIZE);

      /* Draw a back-facing polygon */
      verts[0].x = x1;    verts[0].y = y1;
      verts[1].x = x2;    verts[1].y = y1;
      verts[2].x = x2;    verts[2].y = y2;
      verts[3].x = x1;    verts[3].y = y2;
      verts[0].tx = 0;    verts[0].ty = 0;
      verts[1].tx = 1.0;  verts[1].ty = 0;
      verts[2].tx = 1.0;  verts[2].ty = 1.0;
      verts[3].tx = 0;    verts[3].ty = 1.0;
      cogl_polygon (verts, 4, FALSE);

      x1 = x2;
      x2 = x1 + (float)(TEXTURE_RENDER_SIZE);

      cogl_pop_matrix ();

      cogl_pop_source ();
      cogl_object_unref (pipeline);
    }

  cogl_object_unref (base_pipeline);
}
Exemplo n.º 2
0
static void
mx_scroll_view_paint (ClutterActor *actor)
{
  ClutterActorBox box;
  gfloat w, h;
  MxAdjustment *vadjustment = NULL, *hadjustment = NULL;
  MxScrollViewPrivate *priv = MX_SCROLL_VIEW (actor)->priv;
  ClutterColor *color;

  guint8 r, g, b;
  const gint shadow = 15;

  mx_stylable_get (MX_STYLABLE (actor), "background-color", &color, NULL);

  r = color->red;
  g = color->green;
  b = color->blue;
  clutter_color_free (color);

  /* MxBin will paint the child */
  CLUTTER_ACTOR_CLASS (mx_scroll_view_parent_class)->paint (actor);


  clutter_actor_get_allocation_box (actor, &box);

  w = box.x2 - box.x1;
  h = box.y2 - box.y1;

  /* paint our custom children */
  if (CLUTTER_ACTOR_IS_VISIBLE (priv->hscroll))
    {
      clutter_actor_paint (priv->hscroll);
      clutter_actor_get_allocation_box (priv->hscroll, &box);
      h -= (box.y2 - box.y1);

      hadjustment = mx_scroll_bar_get_adjustment (MX_SCROLL_BAR(priv->hscroll));
    }
  if (CLUTTER_ACTOR_IS_VISIBLE (priv->vscroll))
    {
      clutter_actor_paint (priv->vscroll);
      clutter_actor_get_allocation_box (priv->vscroll, &box);
      w -= (box.x2 - box.x1);
      vadjustment = mx_scroll_bar_get_adjustment (MX_SCROLL_BAR(priv->vscroll));
    }

  /* set up the matrial using dummy set source call */
  cogl_set_source_color4ub (0, 0, 0, 0);

  if (vadjustment)
    {
      gdouble len;
      if ((len = mx_adjustment_get_value (vadjustment)) > 0)
        {
          CoglTextureVertex top[4] = { { 0,}, };

          if (len > shadow)
            len = shadow;

          top[1].x = w;
          top[2].x = w;
          top[2].y = len;
          top[3].y = len;

          cogl_color_set_from_4ub (&top[0].color, r, g, b, 0xff);
          cogl_color_set_from_4ub (&top[1].color, r, g, b, 0xff);
          cogl_color_set_from_4ub (&top[2].color, 0, 0, 0, 0);
          cogl_color_set_from_4ub (&top[3].color, 0, 0, 0, 0);
          cogl_polygon (top, 4, TRUE);
        }

      if ((len = (mx_adjustment_get_upper (vadjustment)
                 - mx_adjustment_get_page_size (vadjustment))
         - mx_adjustment_get_value (vadjustment)) > 0)
        {
          CoglTextureVertex bottom[4] = { {0, }, };

          if (len > shadow)
            len = shadow;

          bottom[0].x = w;
          bottom[0].y = h;
          bottom[1].y = h;
          bottom[2].y = h - len;
          bottom[3].x = w;
          bottom[3].y = h - len;

          cogl_color_set_from_4ub (&bottom[0].color, r, g, b, 0xff);
          cogl_color_set_from_4ub (&bottom[1].color, r, g, b, 0xff);
          cogl_color_set_from_4ub (&bottom[2].color, 0, 0, 0, 0);
          cogl_color_set_from_4ub (&bottom[3].color, 0, 0, 0, 0);
          cogl_polygon (bottom, 4, TRUE);
        }
    }


  if (hadjustment)
    {
      gdouble len;

      if ((len = mx_adjustment_get_value (hadjustment)) > 0)
        {

          CoglTextureVertex left[4] = { { 0, }, };

          if (len > shadow)
            len = shadow;

          left[0].y = h;
          left[2].x = len;
          left[3].x = len;
          left[3].y = h;

          cogl_color_set_from_4ub (&left[0].color, r, g, b, 0xff);
          cogl_color_set_from_4ub (&left[1].color, r, g, b, 0xff);
          cogl_color_set_from_4ub (&left[2].color, 0, 0, 0, 0);
          cogl_color_set_from_4ub (&left[3].color, 0, 0, 0, 0);
          cogl_polygon (left, 4, TRUE);
        }


      if ((len = (mx_adjustment_get_upper (hadjustment)
                 - mx_adjustment_get_page_size (hadjustment))
         - mx_adjustment_get_value (hadjustment)) > 0)
        {
          CoglTextureVertex right[4] = { { 0, }, };

          if (len > shadow)
            len = shadow;

          right[0].x = w;
          right[1].x = w;
          right[1].y = h;
          right[2].x = w - len;
          right[2].y = h;
          right[3].x = w - len;


          cogl_color_set_from_4ub (&right[0].color, r, g, b, 0xff);
          cogl_color_set_from_4ub (&right[1].color, r, g, b, 0xff);
          cogl_color_set_from_4ub (&right[2].color, 0, 0, 0, 0);
          cogl_color_set_from_4ub (&right[3].color, 0, 0, 0, 0);
          cogl_polygon (right, 4, TRUE);
        }
    }


}
Exemplo n.º 3
0
static void _clone_paint_cb (ClutterActor *actor) {
    ClutterActor *source;
    ClutterActorBox box;
    CoglHandle material;
    gfloat width, height;
    guint8 opacity;
    CoglColor color_1, color_2;
    CoglTextureVertex vertices[4];

    /* if we don't have a source actor, don't paint */
    source = clutter_clone_get_source (CLUTTER_CLONE (actor));
    if (source == NULL)
        goto out;

    /* if the source texture does not have any content, don't paint */
    material = clutter_texture_get_cogl_material (CLUTTER_TEXTURE (source));
    if (material == NULL)
        goto out;

    /* get the size of the reflection */
    clutter_actor_get_allocation_box (actor, &box);
    clutter_actor_box_get_size (&box, &width, &height);

    /* get the composite opacity of the actor */
    opacity = clutter_actor_get_paint_opacity (actor);

    /* figure out the two colors for the reflection: the first is
     * full color and the second is the same, but at 0 opacity
     */
    cogl_color_init_from_4f (&color_1, 1.0, 1.0, 1.0, opacity / 255.0);
    cogl_color_premultiply (&color_1);
    cogl_color_init_from_4f (&color_2, 1.0, 1.0, 1.0, 0.0);
    cogl_color_premultiply (&color_2);

    /* now describe the four vertices of the quad; since it has
     * to be a reflection, we need to invert it as well
     */
    vertices[0].x = 0; vertices[0].y = 0; vertices[0].z = 0;
    vertices[0].tx = 0.0; vertices[0].ty = 1.0;
    vertices[0].color = color_1;

    vertices[1].x = width; vertices[1].y = 0; vertices[1].z = 0;
    vertices[1].tx = 1.0; vertices[1].ty = 1.0;
    vertices[1].color = color_1;

    vertices[2].x = width; vertices[2].y = height; vertices[2].z = 0;
    vertices[2].tx = 1.0; vertices[2].ty = 0.0;
    vertices[2].color = color_2;

    vertices[3].x = 0; vertices[3].y = height; vertices[3].z = 0;
    vertices[3].tx = 0.0; vertices[3].ty = 0.0;
    vertices[3].color = color_2;

    /* paint the same texture but with a different geometry */
    cogl_set_source (material);
    cogl_polygon (vertices, 4, TRUE);

    out:
      /* prevent the default clone handler from running */
      g_signal_stop_emission_by_name (actor, "paint");
}