Updates use of Cogl in line with api changes

Some of Cogl's experimental apis have changed so that the buffer apis
now need to be passed a context argument and some drawing apis have been
replaced with cogl_framebuffer_ drawing apis that take explicit
framebuffer and pipeline arguments.

These changes were made as part of Cogl moving towards a more stateless
api that doesn't rely on a global context.

This patch updates Clutter to work with the latest Cogl api and bumps
the required Cogl version to 1.9.5.

Reviewed-by: Emmanuele Bassi <ebassi@linux.intel.com>
Reviewed-by: Neil Roberts <neil@linux.intel.com>
This commit is contained in:
Robert Bragg 2012-02-09 16:04:19 +00:00
parent d0e945fb70
commit bace07c0a0
5 changed files with 75 additions and 44 deletions

View File

@ -323,6 +323,7 @@
#include "cogl/cogl.h"
#define CLUTTER_DISABLE_DEPRECATION_WARNINGS
#define CLUTTER_ENABLE_EXPERIMENTAL_API
#include "clutter-actor-private.h"
@ -2681,13 +2682,18 @@ _clutter_actor_draw_paint_volume_full (ClutterActor *self,
const char *label,
const CoglColor *color)
{
static CoglMaterial *outline = NULL;
static CoglPipeline *outline = NULL;
CoglPrimitive *prim;
ClutterVertex line_ends[12 * 2];
int n_vertices;
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
/* XXX: at some point we'll query this from the stage but we can't
* do that until the osx backend uses Cogl natively. */
CoglFramebuffer *fb = cogl_get_draw_framebuffer ();
if (outline == NULL)
outline = cogl_material_new ();
outline = cogl_pipeline_new ();
_clutter_paint_volume_complete (pv);
@ -2714,12 +2720,12 @@ _clutter_actor_draw_paint_volume_full (ClutterActor *self,
line_ends[22] = pv->vertices[3]; line_ends[23] = pv->vertices[7];
}
prim = cogl_primitive_new_p3 (COGL_VERTICES_MODE_LINES, n_vertices,
prim = cogl_primitive_new_p3 (ctx, COGL_VERTICES_MODE_LINES, n_vertices,
(CoglVertexP3 *)line_ends);
cogl_material_set_color (outline, color);
cogl_set_source (outline);
cogl_primitive_draw (prim);
cogl_pipeline_set_color (outline, color);
cogl_framebuffer_draw_primitive (fb, outline, prim);
cogl_object_unref (outline);
cogl_object_unref (prim);
if (label)

View File

@ -56,6 +56,7 @@
#include "config.h"
#endif
#define CLUTTER_ENABLE_EXPERIMENTAL_API
#include "clutter-deform-effect.h"
#include <cogl/cogl.h>
@ -175,6 +176,7 @@ clutter_deform_effect_paint_target (ClutterOffscreenEffect *effect)
CoglHandle material;
CoglPipeline *pipeline;
CoglDepthState depth_state;
CoglFramebuffer *fb = cogl_get_draw_framebuffer ();
if (priv->is_dirty)
{
@ -286,11 +288,7 @@ clutter_deform_effect_paint_target (ClutterOffscreenEffect *effect)
/* draw the front */
if (material != COGL_INVALID_HANDLE)
{
cogl_push_source (pipeline);
cogl_primitive_draw (priv->primitive);
cogl_pop_source ();
}
cogl_framebuffer_draw_primitive (fb, pipeline, priv->primitive);
/* draw the back */
if (priv->back_material != COGL_INVALID_HANDLE)
@ -304,17 +302,18 @@ clutter_deform_effect_paint_target (ClutterOffscreenEffect *effect)
cogl_pipeline_set_cull_face_mode (pipeline,
COGL_PIPELINE_CULL_FACE_MODE_FRONT);
cogl_push_source (back_pipeline);
cogl_primitive_draw (priv->primitive);
cogl_pop_source ();
cogl_framebuffer_draw_primitive (fb, back_pipeline, priv->primitive);
cogl_object_unref (back_pipeline);
}
if (G_UNLIKELY (priv->lines_primitive != NULL))
{
cogl_set_source_color4f (1.0, 0, 0, 1.0);
cogl_primitive_draw (priv->lines_primitive);
CoglPipeline *lines_pipeline = cogl_pipeline_new ();
cogl_pipeline_set_color4f (lines_pipeline, 1.0, 0, 0, 1.0);
cogl_framebuffer_draw_primitive (fb, lines_pipeline,
priv->lines_primitive);
cogl_object_unref (lines_pipeline);
}
}
@ -349,6 +348,8 @@ clutter_deform_effect_init_arrays (ClutterDeformEffect *self)
gint x, y, direction, n_indices;
CoglAttribute *attributes[3];
guint16 *static_indices;
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
CoglIndices *indices;
guint16 *idx;
int i;
@ -412,7 +413,8 @@ clutter_deform_effect_init_arrays (ClutterDeformEffect *self)
#undef MESH_INDEX
indices = cogl_indices_new (COGL_INDICES_TYPE_UNSIGNED_SHORT,
indices = cogl_indices_new (ctx,
COGL_INDICES_TYPE_UNSIGNED_SHORT,
static_indices,
n_indices);
@ -421,7 +423,8 @@ clutter_deform_effect_init_arrays (ClutterDeformEffect *self)
priv->n_vertices = (priv->x_tiles + 1) * (priv->y_tiles + 1);
priv->buffer =
cogl_attribute_buffer_new (sizeof (CoglVertexP3T2C4) *
cogl_attribute_buffer_new (ctx,
sizeof (CoglVertexP3T2C4) *
priv->n_vertices,
NULL);

View File

@ -130,7 +130,7 @@ AC_HEADER_STDC
# required versions for dependencies
m4_define([glib_req_version], [2.31.10])
m4_define([cogl_req_version], [1.9.4])
m4_define([cogl_req_version], [1.9.5])
m4_define([json_glib_req_version], [0.12.0])
m4_define([atk_req_version], [2.1.5])
m4_define([cairo_req_version], [1.10])

View File

@ -1,3 +1,5 @@
#define COGL_ENABLE_EXPERIMENTAL_2_0_API
#define CLUTTER_ENABLE_EXPERIMENTAL_API
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include <string.h>
@ -59,8 +61,11 @@ create_map_tile (TestTile *tile)
guint i;
unsigned int stride = 0;
guint8 *line;
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
buffer = cogl_pixel_buffer_new_with_size (TILE_SIZE,
buffer = cogl_pixel_buffer_new_with_size (ctx,
TILE_SIZE,
TILE_SIZE,
COGL_PIXEL_FORMAT_RGBA_8888,
&stride);
@ -143,13 +148,16 @@ create_set_region_tile (TestTile *tile)
static void
create_set_data_tile (TestTile *tile)
{
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
CoglHandle buffer;
guint rowstride = 0;
gboolean res;
guchar *data;
guint i;
buffer = cogl_pixel_buffer_new_with_size (TILE_SIZE,
buffer = cogl_pixel_buffer_new_with_size (ctx,
TILE_SIZE,
TILE_SIZE,
COGL_PIXEL_FORMAT_RGBA_8888,
&rowstride);

View File

@ -1,3 +1,5 @@
#define COGL_ENABLE_EXPERIMENTAL_2_0_API
#define CLUTTER_ENABLE_EXPERIMENTAL_API
#include <clutter/clutter.h>
#include <string.h>
@ -7,32 +9,35 @@ static const ClutterColor stage_color = { 0x00, 0xff, 0x00, 0xff };
static const ClutterColor prim_color = { 0xff, 0x00, 0xff, 0xff };
static const ClutterColor tex_color = { 0x00, 0x00, 0xff, 0xff };
typedef CoglPrimitive * (* TestPrimFunc) (ClutterColor *expected_color);
typedef CoglPrimitive * (* TestPrimFunc) (CoglContext *ctx,
ClutterColor *expected_color);
static CoglPrimitive *
test_prim_p2 (ClutterColor *expected_color)
test_prim_p2 (CoglContext *ctx, ClutterColor *expected_color)
{
static const CoglVertexP2 verts[] =
{ { 0, 0 }, { 0, 10 }, { 10, 0 } };
return cogl_primitive_new_p2 (COGL_VERTICES_MODE_TRIANGLES,
return cogl_primitive_new_p2 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */
verts);
}
static CoglPrimitive *
test_prim_p3 (ClutterColor *expected_color)
test_prim_p3 (CoglContext *ctx, ClutterColor *expected_color)
{
static const CoglVertexP3 verts[] =
{ { 0, 0, 0 }, { 0, 10, 0 }, { 10, 0, 0 } };
return cogl_primitive_new_p3 (COGL_VERTICES_MODE_TRIANGLES,
return cogl_primitive_new_p3 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */
verts);
}
static CoglPrimitive *
test_prim_p2c4 (ClutterColor *expected_color)
test_prim_p2c4 (CoglContext *ctx, ClutterColor *expected_color)
{
static const CoglVertexP2C4 verts[] =
{ { 0, 0, 255, 255, 0, 255 },
@ -43,13 +48,14 @@ test_prim_p2c4 (ClutterColor *expected_color)
expected_color->green = 255;
expected_color->blue = 0;
return cogl_primitive_new_p2c4 (COGL_VERTICES_MODE_TRIANGLES,
return cogl_primitive_new_p2c4 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */
verts);
}
static CoglPrimitive *
test_prim_p3c4 (ClutterColor *expected_color)
test_prim_p3c4 (CoglContext *ctx, ClutterColor *expected_color)
{
static const CoglVertexP3C4 verts[] =
{ { 0, 0, 0, 255, 255, 0, 255 },
@ -60,13 +66,14 @@ test_prim_p3c4 (ClutterColor *expected_color)
expected_color->green = 255;
expected_color->blue = 0;
return cogl_primitive_new_p3c4 (COGL_VERTICES_MODE_TRIANGLES,
return cogl_primitive_new_p3c4 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */
verts);
}
static CoglPrimitive *
test_prim_p2t2 (ClutterColor *expected_color)
test_prim_p2t2 (CoglContext *ctx, ClutterColor *expected_color)
{
static const CoglVertexP2T2 verts[] =
{ { 0, 0, 1, 0 },
@ -75,13 +82,14 @@ test_prim_p2t2 (ClutterColor *expected_color)
*expected_color = tex_color;
return cogl_primitive_new_p2t2 (COGL_VERTICES_MODE_TRIANGLES,
return cogl_primitive_new_p2t2 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */
verts);
}
static CoglPrimitive *
test_prim_p3t2 (ClutterColor *expected_color)
test_prim_p3t2 (CoglContext *ctx, ClutterColor *expected_color)
{
static const CoglVertexP3T2 verts[] =
{ { 0, 0, 0, 1, 0 },
@ -90,13 +98,14 @@ test_prim_p3t2 (ClutterColor *expected_color)
*expected_color = tex_color;
return cogl_primitive_new_p3t2 (COGL_VERTICES_MODE_TRIANGLES,
return cogl_primitive_new_p3t2 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */
verts);
}
static CoglPrimitive *
test_prim_p2t2c4 (ClutterColor *expected_color)
test_prim_p2t2c4 (CoglContext *ctx, ClutterColor *expected_color)
{
static const CoglVertexP2T2C4 verts[] =
{ { 0, 0, 1, 0, 0xff, 0xff, 0xf0, 0xff },
@ -106,13 +115,14 @@ test_prim_p2t2c4 (ClutterColor *expected_color)
*expected_color = tex_color;
expected_color->blue = 0xf0;
return cogl_primitive_new_p2t2c4 (COGL_VERTICES_MODE_TRIANGLES,
return cogl_primitive_new_p2t2c4 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */
verts);
}
static CoglPrimitive *
test_prim_p3t2c4 (ClutterColor *expected_color)
test_prim_p3t2c4 (CoglContext *ctx, ClutterColor *expected_color)
{
static const CoglVertexP3T2C4 verts[] =
{ { 0, 0, 0, 1, 0, 0xff, 0xff, 0xf0, 0xff },
@ -122,7 +132,8 @@ test_prim_p3t2c4 (ClutterColor *expected_color)
*expected_color = tex_color;
expected_color->blue = 0xf0;
return cogl_primitive_new_p3t2c4 (COGL_VERTICES_MODE_TRIANGLES,
return cogl_primitive_new_p3t2c4 (ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */
verts);
}
@ -143,8 +154,11 @@ test_prim_funcs[] =
static void
paint_cb (void)
{
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
CoglFramebuffer *fb = cogl_get_draw_framebuffer ();
CoglPipeline *pipeline;
CoglHandle tex;
CoglTexture *tex;
guint8 tex_data[6];
int i;
@ -171,9 +185,7 @@ paint_cb (void)
prim_color.blue,
prim_color.alpha);
cogl_pipeline_set_layer_texture (pipeline, 0, tex);
cogl_handle_unref (tex);
cogl_set_source (pipeline);
cogl_object_unref (pipeline);
cogl_object_unref (tex);
for (i = 0; i < G_N_ELEMENTS (test_prim_funcs); i++)
{
@ -181,11 +193,11 @@ paint_cb (void)
ClutterColor expected_color = prim_color;
guint8 pixel[4];
prim = test_prim_funcs[i] (&expected_color);
prim = test_prim_funcs[i] (ctx, &expected_color);
cogl_push_matrix ();
cogl_translate (i * 10, 0, 0);
cogl_primitive_draw (prim);
cogl_framebuffer_draw_primitive (fb, pipeline, prim);
cogl_pop_matrix ();
cogl_read_pixels (i * 10 + 2, 2, 1, 1,
@ -200,6 +212,8 @@ paint_cb (void)
cogl_object_unref (prim);
}
cogl_object_unref (pipeline);
/* Comment this out to see what the test paints */
clutter_main_quit ();
}