コード例 #1
0
ファイル: meta-texture-tower.c プロジェクト: darkxst/mtest
static void
texture_tower_revalidate_fbo (MetaTextureTower *tower,
                              int               level)
{
  CoglTexture *source_texture = tower->textures[level - 1];
  int source_texture_width = cogl_texture_get_width (source_texture);
  int source_texture_height = cogl_texture_get_height (source_texture);
  CoglTexture *dest_texture = tower->textures[level];
  int dest_texture_width = cogl_texture_get_width (dest_texture);
  int dest_texture_height = cogl_texture_get_height (dest_texture);
  Box *invalid = &tower->invalid[level];
  CoglFramebuffer *fb;
  CoglError *catch_error = NULL;
  CoglPipeline *pipeline;

  if (tower->fbos[level] == NULL)
    tower->fbos[level] = cogl_offscreen_new_with_texture (dest_texture);

  fb = COGL_FRAMEBUFFER (tower->fbos[level]);

  if (!cogl_framebuffer_allocate (fb, &catch_error))
    {
      cogl_error_free (catch_error);
      return;
    }

  cogl_framebuffer_orthographic (fb, 0, 0, dest_texture_width, dest_texture_height, -1., 1.);

  if (!tower->pipeline_template)
    {
      CoglContext *ctx =
        clutter_backend_get_cogl_context (clutter_get_default_backend ());
      tower->pipeline_template = cogl_pipeline_new (ctx);
      cogl_pipeline_set_blend (tower->pipeline_template, "RGBA = ADD (SRC_COLOR, 0)", NULL);
    }

  pipeline = cogl_pipeline_copy (tower->pipeline_template);
  cogl_pipeline_set_layer_texture (pipeline, 0, tower->textures[level - 1]);

  cogl_framebuffer_draw_textured_rectangle (fb, pipeline,
                                            invalid->x1, invalid->y1,
                                            invalid->x2, invalid->y2,
                                            (2. * invalid->x1) / source_texture_width,
                                            (2. * invalid->y1) / source_texture_height,
                                            (2. * invalid->x2) / source_texture_width,
                                            (2. * invalid->y2) / source_texture_height);

  cogl_object_unref (pipeline);
}
コード例 #2
0
static void init()
{
    CoglError *error = NULL;
    CoglDisplay *display;
    CoglRenderer *renderer;
    CoglBool missing_requirement;

    //g_setenv ("COGL_X11_SYNC", "1", 0);

    test_ctx = cogl_context_new (NULL, &error);
    if (!test_ctx) {
        g_message ("Failed to create a CoglContext: %s", error->message);
        exit(1);
    }

    display = cogl_context_get_display (test_ctx);
    renderer = cogl_display_get_renderer (display);

    if (!check_flags (renderer)) {
        g_message ("WARNING: Missing required feature[s] for this test\n");
        exit(1);
    }

    {
        //TODO: get all monitors size to test
        CoglOffscreen *offscreen;
        CoglTexture2D *tex = cogl_texture_2d_new_with_size (test_ctx,
                FB_WIDTH, FB_HEIGHT);
        offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex));
        test_fb = COGL_FRAMEBUFFER (offscreen);
    }

    if (!cogl_framebuffer_allocate (test_fb, &error)) {
        g_message ("Failed to allocate framebuffer: %s", error->message);
        exit(1);
    }

    cogl_framebuffer_clear4f (test_fb,
            COGL_BUFFER_BIT_COLOR |
            COGL_BUFFER_BIT_DEPTH |
            COGL_BUFFER_BIT_STENCIL,
            0, 0, 0, 1);
}
コード例 #3
0
ファイル: st-private.c プロジェクト: meetparikh7/gnome-shell
CoglPipeline *
_st_create_shadow_pipeline_from_actor (StShadow     *shadow_spec,
                                       ClutterActor *actor)
{
    CoglPipeline *shadow_pipeline = NULL;

    if (CLUTTER_IS_TEXTURE (actor))
    {
        CoglTexture *texture;

        texture = clutter_texture_get_cogl_texture (CLUTTER_TEXTURE (actor));
        shadow_pipeline = _st_create_shadow_pipeline (shadow_spec, texture);
    }
    else
    {
        CoglTexture *buffer;
        CoglOffscreen *offscreen;
        CoglFramebuffer *fb;
        ClutterActorBox box;
        CoglColor clear_color;
        float width, height;
        CoglError *catch_error = NULL;

        clutter_actor_get_allocation_box (actor, &box);
        clutter_actor_box_get_size (&box, &width, &height);

        if (width == 0 || height == 0)
            return NULL;

        buffer = cogl_texture_new_with_size (width,
                                             height,
                                             COGL_TEXTURE_NO_SLICING,
                                             COGL_PIXEL_FORMAT_ANY);

        if (buffer == NULL)
            return NULL;

        offscreen = cogl_offscreen_new_with_texture (buffer);
        fb = COGL_FRAMEBUFFER (offscreen);

        if (!cogl_framebuffer_allocate (fb, &catch_error))
        {
            cogl_error_free (catch_error);
            cogl_object_unref (buffer);
            return NULL;
        }

        cogl_color_init_from_4ub (&clear_color, 0, 0, 0, 0);

        /* XXX: There's no way to render a ClutterActor to an offscreen
         * as it uses the implicit API. */
        G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
        cogl_push_framebuffer (fb);
        G_GNUC_END_IGNORE_DEPRECATIONS;

        cogl_framebuffer_clear (fb, COGL_BUFFER_BIT_COLOR, &clear_color);
        cogl_framebuffer_translate (fb, -box.x1, -box.y1, 0);
        cogl_framebuffer_orthographic (fb, 0, 0, width, height, 0, 1.0);

        clutter_actor_set_opacity_override (actor, 255);
        clutter_actor_paint (actor);
        clutter_actor_set_opacity_override (actor, -1);

        G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
        cogl_pop_framebuffer ();
        G_GNUC_END_IGNORE_DEPRECATIONS;

        cogl_object_unref (fb);

        shadow_pipeline = _st_create_shadow_pipeline (shadow_spec, buffer);

        cogl_object_unref (buffer);
    }

    return shadow_pipeline;
}
コード例 #4
0
static CoglHandle
data_to_cogl_handle (const guchar *data,
                     gboolean      has_alpha,
                     int           width,
                     int           height,
                     int           rowstride,
                     gboolean      add_padding)
{
  CoglHandle texture, offscreen;
  CoglColor clear_color;
  guint size;
  GError *error;

  size = MAX (width, height);

  if (!add_padding || width == height)
    return cogl_texture_new_from_data (width,
                                       height,
                                       COGL_TEXTURE_NONE,
                                       has_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
                                       COGL_PIXEL_FORMAT_ANY,
                                       rowstride,
                                       data);

  texture = cogl_texture_new_with_size (size, size,
                                        COGL_TEXTURE_NO_SLICING,
                                        COGL_PIXEL_FORMAT_ANY);

  offscreen = cogl_offscreen_new_with_texture (texture);

  error = NULL;
  if (!cogl_framebuffer_allocate (offscreen, &error))
    {
      g_warning ("Failed to allocate FBO (sized %d): %s", size, error->message);

      cogl_object_unref (texture);
      cogl_object_unref (offscreen);
      g_clear_error (&error);

      return cogl_texture_new_from_data (width,
                                         height,
                                         COGL_TEXTURE_NONE,
                                         has_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
                                         COGL_PIXEL_FORMAT_ANY,
                                         rowstride,
                                         data);
  }

  cogl_color_set_from_4ub (&clear_color, 0, 0, 0, 0);
  cogl_push_framebuffer (offscreen);
  cogl_clear (&clear_color, COGL_BUFFER_BIT_COLOR);
  cogl_pop_framebuffer ();
  cogl_handle_unref (offscreen);

  cogl_texture_set_region (texture,
                           0, 0,
                           (size - width) / 2, (size - height) / 2,
                           width, height,
                           width, height,
                           has_alpha ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
                           rowstride,
                           data);
  return texture;
}