1
0
Fork 0

cogl: Remove unused Primitive APIs

This also removes a clutter interactive test, but as those
tests don't serve that much any more for being no longer executed..

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3910>
This commit is contained in:
Bilal Elmoussaoui 2024-07-25 19:21:10 +02:00 committed by Marge Bot
parent a71166618d
commit 5f1ffb5304
7 changed files with 40 additions and 1055 deletions

View file

@ -61,6 +61,24 @@
#define DEFAULT_N_TILES 32
/**
* ClutterVertexP3T2C4:
* @x: The x component of a position attribute
* @y: The y component of a position attribute
* @z: The z component of a position attribute
* @s: The s component of a texture coordinate attribute
* @t: The t component of a texture coordinate attribute
* @r: The red component of a color attribute
* @b: The green component of a color attribute
* @g: The blue component of a color attribute
* @a: The alpha component of a color attribute
*/
typedef struct {
float x, y, z;
float s, t;
uint8_t r, g, b, a;
} ClutterVertexP3T2C4;
typedef struct _ClutterDeformEffectPrivate
{
CoglPipeline *back_pipeline;
@ -179,7 +197,7 @@ clutter_deform_effect_paint_target (ClutterOffscreenEffect *effect,
if (priv->is_dirty)
{
gboolean mapped_buffer;
CoglVertexP3T2C4 *verts;
ClutterVertexP3T2C4 *verts;
ClutterActor *actor;
gfloat width, height;
guint opacity;
@ -217,7 +235,7 @@ clutter_deform_effect_paint_target (ClutterOffscreenEffect *effect,
{
for (j = 0; j < priv->x_tiles + 1; j++)
{
CoglVertexP3T2C4 *vertex_out;
ClutterVertexP3T2C4 *vertex_out;
ClutterTextureVertex vertex;
/* CoglTextureVertex isn't an ideal structure to use for
@ -431,7 +449,7 @@ clutter_deform_effect_init_arrays (ClutterDeformEffect *self)
priv->buffer =
cogl_attribute_buffer_new (ctx,
sizeof (CoglVertexP3T2C4) *
sizeof (ClutterVertexP3T2C4) *
priv->n_vertices,
NULL);
@ -442,20 +460,20 @@ clutter_deform_effect_init_arrays (ClutterDeformEffect *self)
attributes[0] = cogl_attribute_new (priv->buffer,
"cogl_position_in",
sizeof (CoglVertexP3T2C4),
G_STRUCT_OFFSET (CoglVertexP3T2C4, x),
sizeof (ClutterVertexP3T2C4),
G_STRUCT_OFFSET (ClutterVertexP3T2C4, x),
3, /* n_components */
COGL_ATTRIBUTE_TYPE_FLOAT);
attributes[1] = cogl_attribute_new (priv->buffer,
"cogl_tex_coord0_in",
sizeof (CoglVertexP3T2C4),
G_STRUCT_OFFSET (CoglVertexP3T2C4, s),
sizeof (ClutterVertexP3T2C4),
G_STRUCT_OFFSET (ClutterVertexP3T2C4, s),
2, /* n_components */
COGL_ATTRIBUTE_TYPE_FLOAT);
attributes[2] = cogl_attribute_new (priv->buffer,
"cogl_color_in",
sizeof (CoglVertexP3T2C4),
G_STRUCT_OFFSET (CoglVertexP3T2C4, r),
sizeof (ClutterVertexP3T2C4),
G_STRUCT_OFFSET (ClutterVertexP3T2C4, r),
4, /* n_components */
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);

View file

@ -229,36 +229,6 @@ cogl_primitive_new_p2c4 (CoglContext *ctx,
2);
}
CoglPrimitive *
cogl_primitive_new_p3c4 (CoglContext *ctx,
CoglVerticesMode mode,
int n_vertices,
const CoglVertexP3C4 *data)
{
CoglAttributeBuffer *attribute_buffer =
cogl_attribute_buffer_new (ctx, n_vertices * sizeof (CoglVertexP3C4), data);
CoglAttribute *attributes[2];
attributes[0] = cogl_attribute_new (attribute_buffer,
"cogl_position_in",
sizeof (CoglVertexP3C4),
offsetof (CoglVertexP3C4, x),
3,
COGL_ATTRIBUTE_TYPE_FLOAT);
attributes[1] = cogl_attribute_new (attribute_buffer,
"cogl_color_in",
sizeof (CoglVertexP3C4),
offsetof (CoglVertexP3C4, r),
4,
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
g_object_unref (attribute_buffer);
return _cogl_primitive_new_with_attributes_unref (mode, n_vertices,
attributes,
2);
}
CoglPrimitive *
cogl_primitive_new_p2t2 (CoglContext *ctx,
CoglVerticesMode mode,
@ -319,88 +289,6 @@ cogl_primitive_new_p3t2 (CoglContext *ctx,
2);
}
CoglPrimitive *
cogl_primitive_new_p2t2c4 (CoglContext *ctx,
CoglVerticesMode mode,
int n_vertices,
const CoglVertexP2T2C4 *data)
{
CoglAttributeBuffer *attribute_buffer =
cogl_attribute_buffer_new (ctx,
n_vertices * sizeof (CoglVertexP2T2C4), data);
CoglAttribute *attributes[3];
attributes[0] = cogl_attribute_new (attribute_buffer,
"cogl_position_in",
sizeof (CoglVertexP2T2C4),
offsetof (CoglVertexP2T2C4, x),
2,
COGL_ATTRIBUTE_TYPE_FLOAT);
attributes[1] = cogl_attribute_new (attribute_buffer,
"cogl_tex_coord0_in",
sizeof (CoglVertexP2T2C4),
offsetof (CoglVertexP2T2C4, s),
2,
COGL_ATTRIBUTE_TYPE_FLOAT);
attributes[2] = cogl_attribute_new (attribute_buffer,
"cogl_color_in",
sizeof (CoglVertexP2T2C4),
offsetof (CoglVertexP2T2C4, r),
4,
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
g_object_unref (attribute_buffer);
return _cogl_primitive_new_with_attributes_unref (mode, n_vertices,
attributes,
3);
}
CoglPrimitive *
cogl_primitive_new_p3t2c4 (CoglContext *ctx,
CoglVerticesMode mode,
int n_vertices,
const CoglVertexP3T2C4 *data)
{
CoglAttributeBuffer *attribute_buffer =
cogl_attribute_buffer_new (ctx,
n_vertices * sizeof (CoglVertexP3T2C4), data);
CoglAttribute *attributes[3];
attributes[0] = cogl_attribute_new (attribute_buffer,
"cogl_position_in",
sizeof (CoglVertexP3T2C4),
offsetof (CoglVertexP3T2C4, x),
3,
COGL_ATTRIBUTE_TYPE_FLOAT);
attributes[1] = cogl_attribute_new (attribute_buffer,
"cogl_tex_coord0_in",
sizeof (CoglVertexP3T2C4),
offsetof (CoglVertexP3T2C4, s),
2,
COGL_ATTRIBUTE_TYPE_FLOAT);
attributes[2] = cogl_attribute_new (attribute_buffer,
"cogl_color_in",
sizeof (CoglVertexP3T2C4),
offsetof (CoglVertexP3T2C4, r),
4,
COGL_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
g_object_unref (attribute_buffer);
return _cogl_primitive_new_with_attributes_unref (mode, n_vertices,
attributes,
3);
}
int
cogl_primitive_get_first_vertex (CoglPrimitive *primitive)
{
g_return_val_if_fail (COGL_IS_PRIMITIVE (primitive), 0);
return primitive->first_vertex;
}
void
cogl_primitive_set_first_vertex (CoglPrimitive *primitive,
int first_vertex)
@ -410,14 +298,6 @@ cogl_primitive_set_first_vertex (CoglPrimitive *primitive,
primitive->first_vertex = first_vertex;
}
int
cogl_primitive_get_n_vertices (CoglPrimitive *primitive)
{
g_return_val_if_fail (COGL_IS_PRIMITIVE (primitive), 0);
return primitive->n_vertices;
}
void
cogl_primitive_set_n_vertices (CoglPrimitive *primitive,
int n_vertices)
@ -427,23 +307,6 @@ cogl_primitive_set_n_vertices (CoglPrimitive *primitive,
primitive->n_vertices = n_vertices;
}
CoglVerticesMode
cogl_primitive_get_mode (CoglPrimitive *primitive)
{
g_return_val_if_fail (COGL_IS_PRIMITIVE (primitive), 0);
return primitive->mode;
}
void
cogl_primitive_set_mode (CoglPrimitive *primitive,
CoglVerticesMode mode)
{
g_return_if_fail (COGL_IS_PRIMITIVE (primitive));
primitive->mode = mode;
}
void
cogl_primitive_set_indices (CoglPrimitive *primitive,
CoglIndices *indices,
@ -459,44 +322,10 @@ cogl_primitive_set_indices (CoglPrimitive *primitive,
primitive->n_vertices = n_indices;
}
CoglIndices *
cogl_primitive_get_indices (CoglPrimitive *primitive)
{
return primitive->indices;
}
CoglPrimitive *
cogl_primitive_copy (CoglPrimitive *primitive)
{
CoglPrimitive *copy;
copy = cogl_primitive_new_with_attributes (primitive->mode,
primitive->n_vertices,
(CoglAttribute **)primitive->attributes->pdata,
primitive->n_attributes);
cogl_primitive_set_indices (copy, primitive->indices, primitive->n_vertices);
cogl_primitive_set_first_vertex (copy, primitive->first_vertex);
return copy;
}
void
cogl_primitive_foreach_attribute (CoglPrimitive *primitive,
CoglPrimitiveAttributeCallback callback,
void *user_data)
{
int i;
for (i = 0; i < primitive->n_attributes; i++)
if (!callback (primitive, primitive->attributes->pdata[i], user_data))
break;
}
void
_cogl_primitive_draw (CoglPrimitive *primitive,
cogl_primitive_draw (CoglPrimitive *primitive,
CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
CoglDrawFlags flags)
CoglPipeline *pipeline)
{
if (primitive->indices)
_cogl_framebuffer_draw_indexed_attributes (framebuffer,
@ -507,7 +336,7 @@ _cogl_primitive_draw (CoglPrimitive *primitive,
primitive->indices,
(CoglAttribute **) primitive->attributes->pdata,
primitive->n_attributes,
flags);
0);
else
_cogl_framebuffer_draw_attributes (framebuffer,
pipeline,
@ -516,13 +345,5 @@ _cogl_primitive_draw (CoglPrimitive *primitive,
primitive->n_vertices,
(CoglAttribute **) primitive->attributes->pdata,
primitive->n_attributes,
flags);
}
void
cogl_primitive_draw (CoglPrimitive *primitive,
CoglFramebuffer *framebuffer,
CoglPipeline *pipeline)
{
_cogl_primitive_draw (primitive, framebuffer, pipeline, 0 /* flags */);
0);
}

View file

@ -106,24 +106,6 @@ typedef struct {
uint8_t r, g, b, a;
} CoglVertexP2C4;
/**
* CoglVertexP3C4:
* @x: The x component of a position attribute
* @y: The y component of a position attribute
* @z: The z component of a position attribute
* @r: The red component of a color attribute
* @b: The green component of a color attribute
* @g: The blue component of a color attribute
* @a: The alpha component of a color attribute
*
* A convenience vertex definition that can be used with
* cogl_primitive_new_p3c4().
*/
typedef struct {
float x, y, z;
uint8_t r, g, b, a;
} CoglVertexP3C4;
/**
* CoglVertexP2T2:
* @x: The x component of a position attribute
@ -155,48 +137,6 @@ typedef struct {
float s, t;
} CoglVertexP3T2;
/**
* CoglVertexP2T2C4:
* @x: The x component of a position attribute
* @y: The y component of a position attribute
* @s: The s component of a texture coordinate attribute
* @t: The t component of a texture coordinate attribute
* @r: The red component of a color attribute
* @b: The green component of a color attribute
* @g: The blue component of a color attribute
* @a: The alpha component of a color attribute
*
* A convenience vertex definition that can be used with
* cogl_primitive_new_p3t2c4().
*/
typedef struct {
float x, y;
float s, t;
uint8_t r, g, b, a;
} CoglVertexP2T2C4;
/**
* CoglVertexP3T2C4:
* @x: The x component of a position attribute
* @y: The y component of a position attribute
* @z: The z component of a position attribute
* @s: The s component of a texture coordinate attribute
* @t: The t component of a texture coordinate attribute
* @r: The red component of a color attribute
* @b: The green component of a color attribute
* @g: The blue component of a color attribute
* @a: The alpha component of a color attribute
*
* A convenience vertex definition that can be used with
* cogl_primitive_new_p3t2c4().
*/
typedef struct {
float x, y, z;
float s, t;
uint8_t r, g, b, a;
} CoglVertexP3T2C4;
/**
* cogl_primitive_new:
* @mode: A #CoglVerticesMode defining how to draw the vertices
@ -395,58 +335,6 @@ cogl_primitive_new_p2c4 (CoglContext *context,
int n_vertices,
const CoglVertexP2C4 *data);
/**
* cogl_primitive_new_p3c4:
* @context: A #CoglContext
* @mode: A #CoglVerticesMode defining how to draw the vertices
* @n_vertices: The number of vertices to read from @data and also
* the number of vertices to read when later drawing.
* @data: (array length=n_vertices) (element-type Cogl.VertexP3C4): An array
* of #CoglVertexP3C4 vertices
*
* Provides a convenient way to describe a primitive, such as a single
* triangle strip or a triangle fan, that will internally allocate the
* necessary #CoglAttributeBuffer storage, describe the position
* and color attributes with `CoglAttribute`s and upload
* your data.
*
* For example to draw a convex polygon with a linear gradient you
* can do:
* ```c
* CoglVertexP3C4 triangle[] =
* {
* { 0, 300, 0, 0xff, 0x00, 0x00, 0xff },
* { 150, 0, 0, 0x00, 0xff, 0x00, 0xff },
* { 300, 300, 0, 0xff, 0x00, 0x00, 0xff }
* };
* prim = cogl_primitive_new_p3c4 (COGL_VERTICES_MODE_TRIANGLE_FAN,
* 3, triangle);
* cogl_primitive_draw (prim);
* ```
*
* The value passed as @n_vertices is initially used to determine how
* much can be read from @data but it will also be used to update the
* #CoglPrimitive `n_vertices` property as if
* cogl_primitive_set_n_vertices() were called. This property defines
* the number of vertices to read when drawing.
* The primitive API doesn't support drawing with sliced
* textures (since switching between slices implies changing state and
* so that implies multiple primitives need to be submitted). If your
* hardware doesn't support non-power of two textures (For example you
* are using GLES 1.1) then you will need to make sure your assets are
* resized to a power-of-two size (though they don't have to be square)
*
*
* Return value: (transfer full): A newly allocated #CoglPrimitive
* with a reference of 1. This can be freed using g_object_unref().
*/
COGL_EXPORT CoglPrimitive *
cogl_primitive_new_p3c4 (CoglContext *context,
CoglVerticesMode mode,
int n_vertices,
const CoglVertexP3C4 *data);
/**
* cogl_primitive_new_p2t2:
* @context: A #CoglContext
@ -551,138 +439,10 @@ cogl_primitive_new_p3t2 (CoglContext *context,
int n_vertices,
const CoglVertexP3T2 *data);
/**
* cogl_primitive_new_p2t2c4:
* @context: A #CoglContext
* @mode: A #CoglVerticesMode defining how to draw the vertices
* @n_vertices: The number of vertices to read from @data and also
* the number of vertices to read when later drawing.
* @data: (array length=n_vertices) (element-type Cogl.VertexP2T2C4): An
* array of #CoglVertexP2T2C4 vertices
*
* Provides a convenient way to describe a primitive, such as a single
* triangle strip or a triangle fan, that will internally allocate the
* necessary #CoglAttributeBuffer storage, describe the position, texture
* coordinate and color attributes with `CoglAttribute`s and
* upload your data.
*
* For example to draw a convex polygon with texture mapping and a
* linear gradient you can do:
* ```c
* CoglVertexP2T2C4 triangle[] =
* {
* { 0, 300, 0.0, 1.0, 0xff, 0x00, 0x00, 0xff},
* { 150, 0, 0.5, 0.0, 0x00, 0xff, 0x00, 0xff},
* { 300, 300, 1.0, 1.0, 0xff, 0x00, 0x00, 0xff}
* };
* prim = cogl_primitive_new_p2t2c4 (COGL_VERTICES_MODE_TRIANGLE_FAN,
* 3, triangle);
* cogl_primitive_draw (prim);
* ```
*
* The value passed as @n_vertices is initially used to determine how
* much can be read from @data but it will also be used to update the
* #CoglPrimitive `n_vertices` property as if
* cogl_primitive_set_n_vertices() were called. This property defines
* the number of vertices to read when drawing.
* The primitive API doesn't support drawing with sliced
* textures (since switching between slices implies changing state and
* so that implies multiple primitives need to be submitted). If your
* hardware doesn't support non-power of two textures (For example you
* are using GLES 1.1) then you will need to make sure your assets are
* resized to a power-of-two size (though they don't have to be square)
*
*
* Return value: (transfer full): A newly allocated #CoglPrimitive
* with a reference of 1. This can be freed using g_object_unref().
*/
COGL_EXPORT CoglPrimitive *
cogl_primitive_new_p2t2c4 (CoglContext *context,
CoglVerticesMode mode,
int n_vertices,
const CoglVertexP2T2C4 *data);
/**
* cogl_primitive_new_p3t2c4:
* @context: A #CoglContext
* @mode: A #CoglVerticesMode defining how to draw the vertices
* @n_vertices: The number of vertices to read from @data and also
* the number of vertices to read when later drawing.
* @data: (array length=n_vertices) (element-type Cogl.VertexP3T2C4): An
* array of #CoglVertexP3T2C4 vertices
*
* Provides a convenient way to describe a primitive, such as a single
* triangle strip or a triangle fan, that will internally allocate the
* necessary #CoglAttributeBuffer storage, describe the position, texture
* coordinate and color attributes with `CoglAttribute`s and
* upload your data.
*
* For example to draw a convex polygon with texture mapping and a
* linear gradient you can do:
* ```c
* CoglVertexP3T2C4 triangle[] =
* {
* { 0, 300, 0, 0.0, 1.0, 0xff, 0x00, 0x00, 0xff},
* { 150, 0, 0, 0.5, 0.0, 0x00, 0xff, 0x00, 0xff},
* { 300, 300, 0, 1.0, 1.0, 0xff, 0x00, 0x00, 0xff}
* };
* prim = cogl_primitive_new_p3t2c4 (COGL_VERTICES_MODE_TRIANGLE_FAN,
* 3, triangle);
* cogl_primitive_draw (prim);
* ```
*
* The value passed as @n_vertices is initially used to determine how
* much can be read from @data but it will also be used to update the
* #CoglPrimitive `n_vertices` property as if
* cogl_primitive_set_n_vertices() were called. This property defines
* the number of vertices to read when drawing.
* The primitive API doesn't support drawing with sliced
* textures (since switching between slices implies changing state and
* so that implies multiple primitives need to be submitted). If your
* hardware doesn't support non-power of two textures (For example you
* are using GLES 1.1) then you will need to make sure your assets are
* resized to a power-of-two size (though they don't have to be square)
*
*
* Return value: (transfer full): A newly allocated #CoglPrimitive
* with a reference of 1. This can be freed using g_object_unref().
*/
COGL_EXPORT CoglPrimitive *
cogl_primitive_new_p3t2c4 (CoglContext *context,
CoglVerticesMode mode,
int n_vertices,
const CoglVertexP3T2C4 *data);
COGL_EXPORT int
cogl_primitive_get_first_vertex (CoglPrimitive *primitive);
COGL_EXPORT void
cogl_primitive_set_first_vertex (CoglPrimitive *primitive,
int first_vertex);
/**
* cogl_primitive_get_n_vertices:
* @primitive: A #CoglPrimitive object
*
* Queries the number of vertices to read when drawing the given
* @primitive. Usually this value is implicitly set when associating
* vertex data or indices with a #CoglPrimitive.
*
* If cogl_primitive_set_indices() has been used to associate a
* sequence of #CoglIndices with the given @primitive then the
* number of vertices to read can also be phrased as the number
* of indices to read.
*
* To be clear; it doesn't refer to the number of vertices - in
* terms of data - associated with the primitive it's just the number
* of vertices to read and draw.
*
* Returns: The number of vertices to read when drawing.
*/
COGL_EXPORT int
cogl_primitive_get_n_vertices (CoglPrimitive *primitive);
/**
* cogl_primitive_set_n_vertices:
* @primitive: A #CoglPrimitive object
@ -702,12 +462,6 @@ COGL_EXPORT void
cogl_primitive_set_n_vertices (CoglPrimitive *primitive,
int n_vertices);
COGL_EXPORT CoglVerticesMode
cogl_primitive_get_mode (CoglPrimitive *primitive);
COGL_EXPORT void
cogl_primitive_set_mode (CoglPrimitive *primitive,
CoglVerticesMode mode);
/**
* cogl_primitive_set_indices:
@ -739,60 +493,6 @@ cogl_primitive_set_indices (CoglPrimitive *primitive,
CoglIndices *indices,
int n_indices);
/**
* cogl_primitive_get_indices:
* @primitive: A #CoglPrimitive
*
* Return value: (transfer none) (nullable) (array): the indices that were set
* with cogl_primitive_set_indices() or %NULL if no indices were set.
*/
COGL_EXPORT CoglIndices *
cogl_primitive_get_indices (CoglPrimitive *primitive);
/**
* cogl_primitive_copy:
* @primitive: A primitive copy
*
* Makes a copy of an existing #CoglPrimitive. Note that the primitive
* is a shallow copy which means it will use the same attributes and
* attribute buffers as the original primitive.
*
* Return value: (transfer full): the new primitive
*/
COGL_EXPORT CoglPrimitive *
cogl_primitive_copy (CoglPrimitive *primitive);
/**
* CoglPrimitiveAttributeCallback:
* @primitive: The #CoglPrimitive whose attributes are being iterated
* @attribute: The #CoglAttribute
* @user_data: The private data passed to cogl_primitive_foreach_attribute()
*
* The callback prototype used with cogl_primitive_foreach_attribute()
* for iterating all the attributes of a #CoglPrimitive.
*
* The function should return TRUE to continue iteration or FALSE to
* stop.
*/
typedef gboolean (* CoglPrimitiveAttributeCallback) (CoglPrimitive *primitive,
CoglAttribute *attribute,
void *user_data);
/**
* cogl_primitive_foreach_attribute:
* @primitive: A #CoglPrimitive object
* @callback: (scope call): A #CoglPrimitiveAttributeCallback to be
* called for each attribute
* @user_data: (closure): Private data that will be passed to the
* callback
*
* Iterates all the attributes of the given #CoglPrimitive.
*/
COGL_EXPORT void
cogl_primitive_foreach_attribute (CoglPrimitive *primitive,
CoglPrimitiveAttributeCallback callback,
void *user_data);
/**
* cogl_primitive_draw:
* @primitive: A #CoglPrimitive geometry object

View file

@ -19,7 +19,6 @@ clutter_tests_interactive_test_sources = [
'test-cogl-shader-glsl.c',
'test-cogl-tex-tile.c',
'test-cogl-offscreen.c',
'test-cogl-tex-polygon.c',
'test-animation.c',
'test-binding-pool.c',
'test-text.c',

View file

@ -1,396 +0,0 @@
#include <glib.h>
#include <gmodule.h>
#include <stdlib.h>
#include <clutter/clutter.h>
#include <cogl/cogl.h>
#include "clutter/test-utils.h"
#include "tests/clutter-test-utils.h"
/* Coglbox declaration
*--------------------------------------------------*/
G_BEGIN_DECLS
#define TEST_TYPE_COGLBOX test_coglbox_get_type()
static
G_DECLARE_FINAL_TYPE (TestCoglbox, test_coglbox, TEST, COGLBOX, ClutterActor)
struct _TestCoglbox
{
ClutterActor parent;
CoglTexture *sliced_tex;
CoglTexture *not_sliced_tex;
gint frame;
gboolean use_sliced;
gboolean use_linear_filtering;
};
G_DEFINE_TYPE (TestCoglbox, test_coglbox, CLUTTER_TYPE_ACTOR);
int
test_cogl_tex_polygon_main (int argc, char *argv[]);
const char *
test_cogl_tex_polygon_describe (void);
G_END_DECLS
/* Coglbox implementation
*--------------------------------------------------*/
static void
test_coglbox_fade_texture (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
float x1,
float y1,
float x2,
float y2,
float tx1,
float ty1,
float tx2,
float ty2)
{
CoglVertexP3T2C4 vertices[4];
CoglPrimitive *primitive;
int i;
vertices[0].x = x1;
vertices[0].y = y1;
vertices[0].z = 0;
vertices[0].s = tx1;
vertices[0].t = ty1;
vertices[1].x = x1;
vertices[1].y = y2;
vertices[1].z = 0;
vertices[1].s = tx1;
vertices[1].t = ty2;
vertices[2].x = x2;
vertices[2].y = y2;
vertices[2].z = 0;
vertices[2].s = tx2;
vertices[2].t = ty2;
vertices[3].x = x2;
vertices[3].y = y1;
vertices[3].z = 0;
vertices[3].s = tx2;
vertices[3].t = ty1;
for (i = 0; i < 4; i++)
{
CoglColor cogl_color;
cogl_color_init_from_4f (&cogl_color,
1.0f,
1.0f,
1.0f,
((i ^ (i >> 1)) & 1) ? 0.0 : 128.0f / 255.0f);
cogl_color_premultiply (&cogl_color);
vertices[i].r = (uint8_t) (cogl_color_get_red (&cogl_color) * 255.0);
vertices[i].g = (uint8_t) (cogl_color_get_green (&cogl_color) * 255.0);
vertices[i].b = (uint8_t) (cogl_color_get_blue (&cogl_color) * 255.0);
vertices[i].a = (uint8_t) (cogl_color_get_alpha (&cogl_color) * 255.0);
}
primitive =
cogl_primitive_new_p3t2c4 (cogl_framebuffer_get_context (framebuffer),
COGL_VERTICES_MODE_TRIANGLE_FAN,
4,
vertices);
cogl_primitive_draw (primitive, framebuffer, pipeline);
g_object_unref (primitive);
}
static void
test_coglbox_triangle_texture (CoglFramebuffer *framebuffer,
CoglPipeline *pipeline,
int tex_width,
int tex_height,
float x,
float y,
float tx1,
float ty1,
float tx2,
float ty2,
float tx3,
float ty3)
{
CoglVertexP3T2 vertices[3];
CoglPrimitive *primitive;
vertices[0].x = x + tx1 * tex_width;
vertices[0].y = y + ty1 * tex_height;
vertices[0].z = 0;
vertices[0].s = tx1;
vertices[0].t = ty1;
vertices[1].x = x + tx2 * tex_width;
vertices[1].y = y + ty2 * tex_height;
vertices[1].z = 0;
vertices[1].s = tx2;
vertices[1].t = ty2;
vertices[2].x = x + tx3 * tex_width;
vertices[2].y = y + ty3 * tex_height;
vertices[2].z = 0;
vertices[2].s = tx3;
vertices[2].t = ty3;
primitive = cogl_primitive_new_p3t2 (cogl_framebuffer_get_context (framebuffer),
COGL_VERTICES_MODE_TRIANGLE_FAN,
3,
vertices);
cogl_primitive_draw (primitive, framebuffer, pipeline);
g_object_unref (primitive);
}
static void
test_coglbox_paint (ClutterActor *self,
ClutterPaintContext *paint_context)
{
TestCoglbox *coglbox = TEST_COGLBOX (self);
CoglTexture *tex_handle = coglbox->use_sliced ? coglbox->sliced_tex
: coglbox->not_sliced_tex;
int tex_width = cogl_texture_get_width (tex_handle);
int tex_height = cogl_texture_get_height (tex_handle);
CoglPipeline *pipeline;
CoglFramebuffer *framebuffer =
clutter_paint_context_get_framebuffer (paint_context);
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
pipeline = cogl_pipeline_new (ctx);
cogl_pipeline_set_layer_texture (pipeline, 0, tex_handle);
cogl_pipeline_set_layer_filters (pipeline, 0,
coglbox->use_linear_filtering
? COGL_PIPELINE_FILTER_LINEAR :
COGL_PIPELINE_FILTER_NEAREST,
coglbox->use_linear_filtering
? COGL_PIPELINE_FILTER_LINEAR :
COGL_PIPELINE_FILTER_NEAREST);
cogl_framebuffer_push_matrix (framebuffer);
cogl_framebuffer_translate (framebuffer, tex_width / 2, 0, 0);
cogl_framebuffer_rotate (framebuffer, coglbox->frame, 0, 1, 0);
cogl_framebuffer_translate (framebuffer, -tex_width / 2, 0, 0);
/* Draw a hand and reflect it */
cogl_framebuffer_draw_textured_rectangle (framebuffer, pipeline,
0, 0, tex_width, tex_height,
0, 0, 1, 1);
test_coglbox_fade_texture (framebuffer, pipeline,
0, tex_height,
tex_width, (tex_height * 3 / 2),
0.0, 1.0,
1.0, 0.5);
cogl_framebuffer_pop_matrix (framebuffer);
cogl_framebuffer_push_matrix (framebuffer);
cogl_framebuffer_translate (framebuffer, tex_width * 3 / 2 + 60, 0, 0);
cogl_framebuffer_rotate (framebuffer, coglbox->frame, 0, 1, 0);
cogl_framebuffer_translate (framebuffer, -tex_width / 2 - 10, 0, 0);
/* Draw the texture split into two triangles */
test_coglbox_triangle_texture (framebuffer, pipeline,
tex_width, tex_height,
0, 0,
0, 0,
0, 1,
1, 1);
test_coglbox_triangle_texture (framebuffer, pipeline,
tex_width, tex_height,
20, 0,
0, 0,
1, 0,
1, 1);
cogl_framebuffer_pop_matrix (framebuffer);
g_object_unref (pipeline);
}
static void
test_coglbox_dispose (GObject *object)
{
TestCoglbox *coglbox = TEST_COGLBOX (object);
g_object_unref (coglbox->not_sliced_tex);
g_object_unref (coglbox->sliced_tex);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);
}
static void
test_coglbox_init (TestCoglbox *self)
{
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
GError *error = NULL;
gchar *file;
self->use_linear_filtering = FALSE;
self->use_sliced = FALSE;
file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
self->sliced_tex =
clutter_test_texture_2d_sliced_new_from_file (ctx, file,
&error);
if (self->sliced_tex == NULL)
{
if (error)
{
g_warning ("Texture loading failed: %s", error->message);
g_error_free (error);
error = NULL;
}
else
g_warning ("Texture loading failed: <unknown>");
}
self->not_sliced_tex = clutter_test_texture_2d_new_from_file (ctx, file, &error);
if (self->not_sliced_tex == NULL)
{
if (error)
{
g_warning ("Texture loading failed: %s", error->message);
g_error_free (error);
}
else
g_warning ("Texture loading failed: <unknown>");
}
g_free (file);
}
static void
test_coglbox_class_init (TestCoglboxClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
gobject_class->dispose = test_coglbox_dispose;
actor_class->paint = test_coglbox_paint;
}
static ClutterActor*
test_coglbox_new (void)
{
return g_object_new (TEST_TYPE_COGLBOX, NULL);
}
static void
frame_cb (ClutterTimeline *timeline,
int elapsed_msecs,
gpointer data)
{
TestCoglbox *coglbox = TEST_COGLBOX (data);
gdouble progress = clutter_timeline_get_progress (timeline);
coglbox->frame = (int) (360.0 * progress);
clutter_actor_queue_redraw (CLUTTER_ACTOR (data));
}
static void
update_toggle_text (ClutterText *button, gboolean val)
{
clutter_text_set_text (button, val ? "Enabled" : "Disabled");
}
static gboolean
on_toggle_click (ClutterActor *button, ClutterEvent *event,
gboolean *toggle_val)
{
update_toggle_text (CLUTTER_TEXT (button), *toggle_val = !*toggle_val);
return TRUE;
}
static ClutterActor *
make_toggle (const char *label_text, gboolean *toggle_val)
{
ClutterActor *group = clutter_actor_new ();
ClutterActor *label = clutter_text_new_with_text ("Sans 14", label_text);
ClutterActor *button = clutter_text_new_with_text ("Sans 14", "");
clutter_actor_set_reactive (button, TRUE);
update_toggle_text (CLUTTER_TEXT (button), *toggle_val);
clutter_actor_set_position (button, clutter_actor_get_width (label) + 10, 0);
clutter_actor_add_child (group, label);
clutter_actor_add_child (group, button);
g_signal_connect (button, "button-press-event", G_CALLBACK (on_toggle_click),
toggle_val);
return group;
}
G_MODULE_EXPORT int
test_cogl_tex_polygon_main (int argc, char *argv[])
{
ClutterActor *stage;
TestCoglbox *coglbox;
ClutterActor *filtering_toggle;
ClutterActor *slicing_toggle;
ClutterActor *note;
ClutterTimeline *timeline;
CoglColor blue = { 0x30, 0x30, 0xff, 0xff };
clutter_test_init (&argc, &argv);
/* Stage */
stage = clutter_test_get_stage ();
clutter_actor_set_background_color (CLUTTER_ACTOR (stage), &blue);
clutter_actor_set_size (stage, 640, 480);
clutter_stage_set_title (CLUTTER_STAGE (stage), "Cogl Texture Polygon");
g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL);
/* Cogl Box */
coglbox = TEST_COGLBOX (test_coglbox_new ());
clutter_actor_add_child (stage, CLUTTER_ACTOR (coglbox));
/* Timeline for animation */
timeline = clutter_timeline_new_for_actor (stage, 6000);
clutter_timeline_set_repeat_count (timeline, -1);
g_signal_connect (timeline, "new-frame", G_CALLBACK (frame_cb), coglbox);
clutter_timeline_start (timeline);
/* Labels for toggling settings */
slicing_toggle = make_toggle ("Texture slicing: ", &coglbox->use_sliced);
clutter_actor_set_position (slicing_toggle, 0,
clutter_actor_get_height (stage)
- clutter_actor_get_height (slicing_toggle));
filtering_toggle = make_toggle ("Linear filtering: ",
&coglbox->use_linear_filtering);
clutter_actor_set_position (filtering_toggle, 0,
clutter_actor_get_y (slicing_toggle)
- clutter_actor_get_height (filtering_toggle));
note = clutter_text_new_with_text ("Sans 10", "<- Click to change");
clutter_actor_set_position (note,
clutter_actor_get_width (filtering_toggle) + 10,
(clutter_actor_get_height (stage)
+ clutter_actor_get_y (filtering_toggle)) / 2
- clutter_actor_get_height (note) / 2);
clutter_actor_add_child (stage, slicing_toggle);
clutter_actor_add_child (stage, filtering_toggle);
clutter_actor_add_child (stage, note);
clutter_actor_show (stage);
clutter_test_main ();
return 0;
}
G_MODULE_EXPORT const char *
test_cogl_tex_polygon_describe (void)
{
return "Texture polygon primitive.";
}

View file

@ -47,7 +47,10 @@ create_primitives (CoglPrimitive *primitives[2])
vertex_data);
cogl_primitive_set_n_vertices (primitives[0], 4);
primitives[1] = cogl_primitive_copy (primitives[0]);
primitives[1] = cogl_primitive_new_p2c4 (test_ctx,
COGL_VERTICES_MODE_TRIANGLE_STRIP,
G_N_ELEMENTS (vertex_data),
vertex_data);
cogl_primitive_set_first_vertex (primitives[1], 4);
cogl_primitive_set_n_vertices (primitives[1], 4);
}

View file

@ -57,22 +57,6 @@ test_prim_p2c4 (CoglContext *ctx, uint32_t *expected_color)
verts);
}
static CoglPrimitive *
test_prim_p3c4 (CoglContext *ctx, uint32_t *expected_color)
{
static const CoglVertexP3C4 verts[] =
{ { 0, 0, 0, 255, 255, 0, 255 },
{ 0, 10, 0, 255, 255, 0, 255 },
{ 10, 0, 0, 255, 255, 0, 255 } };
*expected_color = 0xffff00ff;
return cogl_primitive_new_p3c4 (test_ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */
verts);
}
static CoglPrimitive *
test_prim_p2t2 (CoglContext *ctx, uint32_t *expected_color)
{
@ -105,51 +89,14 @@ test_prim_p3t2 (CoglContext *ctx, uint32_t *expected_color)
verts);
}
static CoglPrimitive *
test_prim_p2t2c4 (CoglContext *ctx, uint32_t *expected_color)
{
static const CoglVertexP2T2C4 verts[] =
{ { 0, 0, 1, 0, 0xff, 0xff, 0xf0, 0xff },
{ 0, 10, 1, 0, 0xff, 0xff, 0xf0, 0xff },
{ 10, 0, 1, 0, 0xff, 0xff, 0xf0, 0xff } };
/* The blue component of the texture color should be replaced with 0xf0 */
*expected_color = (TEX_COLOR & 0xffff00ff) | 0x0000f000;
return cogl_primitive_new_p2t2c4 (test_ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */
verts);
}
static CoglPrimitive *
test_prim_p3t2c4 (CoglContext *ctx, uint32_t *expected_color)
{
static const CoglVertexP3T2C4 verts[] =
{ { 0, 0, 0, 1, 0, 0xff, 0xff, 0xf0, 0xff },
{ 0, 10, 0, 1, 0, 0xff, 0xff, 0xf0, 0xff },
{ 10, 0, 0, 1, 0, 0xff, 0xff, 0xf0, 0xff } };
/* The blue component of the texture color should be replaced with 0xf0 */
*expected_color = (TEX_COLOR & 0xffff00ff) | 0x0000f000;
return cogl_primitive_new_p3t2c4 (test_ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, /* n_vertices */
verts);
}
static const TestPrimFunc
test_prim_funcs[] =
{
test_prim_p2,
test_prim_p3,
test_prim_p2c4,
test_prim_p3c4,
test_prim_p2t2,
test_prim_p3t2,
test_prim_p2t2c4,
test_prim_p3t2c4
};
static void
@ -207,112 +154,6 @@ test_paint (TestState *state)
g_object_unref (pipeline);
}
static gboolean
get_attributes_cb (CoglPrimitive *prim,
CoglAttribute *attrib,
void *user_data)
{
CoglAttribute ***p = user_data;
*((* p)++) = attrib;
return TRUE;
}
static int
compare_pointers (const void *a, const void *b)
{
CoglAttribute *pa = *(CoglAttribute **) a;
CoglAttribute *pb = *(CoglAttribute **) b;
if (pa < pb)
return -1;
else if (pa > pb)
return 1;
else
return 0;
}
static void
test_copy (TestState *state)
{
static const uint16_t indices_data[2] = { 1, 2 };
CoglAttributeBuffer *buffer =
cogl_attribute_buffer_new (test_ctx, 100, NULL);
CoglAttribute *attributes[N_ATTRIBS];
CoglAttribute *attributes_a[N_ATTRIBS], *attributes_b[N_ATTRIBS];
CoglAttribute **p;
CoglPrimitive *prim_a, *prim_b;
CoglIndices *indices;
int i;
for (i = 0; i < N_ATTRIBS; i++)
{
char *name = g_strdup_printf ("foo_%i", i);
attributes[i] = cogl_attribute_new (buffer,
name,
16, /* stride */
16, /* offset */
2, /* components */
COGL_ATTRIBUTE_TYPE_FLOAT);
g_free (name);
}
prim_a = cogl_primitive_new_with_attributes (COGL_VERTICES_MODE_TRIANGLES,
8, /* n_vertices */
attributes,
N_ATTRIBS);
indices = cogl_indices_new (test_ctx,
COGL_INDICES_TYPE_UNSIGNED_SHORT,
indices_data,
2 /* n_indices */);
cogl_primitive_set_first_vertex (prim_a, 12);
cogl_primitive_set_indices (prim_a, indices, 2);
prim_b = cogl_primitive_copy (prim_a);
p = attributes_a;
cogl_primitive_foreach_attribute (prim_a,
get_attributes_cb,
&p);
g_assert_cmpint (p - attributes_a, ==, N_ATTRIBS);
p = attributes_b;
cogl_primitive_foreach_attribute (prim_b,
get_attributes_cb,
&p);
g_assert_cmpint (p - attributes_b, ==, N_ATTRIBS);
qsort (attributes_a, N_ATTRIBS, sizeof (CoglAttribute *), compare_pointers);
qsort (attributes_b, N_ATTRIBS, sizeof (CoglAttribute *), compare_pointers);
g_assert (memcmp (attributes_a, attributes_b, sizeof (attributes_a)) == 0);
g_assert_cmpint (cogl_primitive_get_first_vertex (prim_a),
==,
cogl_primitive_get_first_vertex (prim_b));
g_assert_cmpint (cogl_primitive_get_n_vertices (prim_a),
==,
cogl_primitive_get_n_vertices (prim_b));
g_assert_cmpint (cogl_primitive_get_mode (prim_a),
==,
cogl_primitive_get_mode (prim_b));
g_assert (cogl_primitive_get_indices (prim_a) ==
cogl_primitive_get_indices (prim_b));
g_object_unref (prim_a);
g_object_unref (prim_b);
g_object_unref (indices);
for (i = 0; i < N_ATTRIBS; i++)
g_object_unref (attributes[i]);
g_object_unref (buffer);
}
static void
test_primitive (void)
{
@ -329,7 +170,6 @@ test_primitive (void)
100);
test_paint (&state);
test_copy (&state);
if (cogl_test_verbose ())
g_print ("OK\n");