mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 18:11:05 -05:00
primitive: Adds convenience constructors
This adds convenience primitive constructors named like: cogl_primitive_new_p3 or cogl_primitive_new_p3c4 or cogl_primitive_new_p3t2c4 where the letters correspond to the interleved vertex attributes layouts such as CoglP3Vertex which is a struct with 3 float x,y,z members for the [p]osition, or CoglP3T2C4Vertex which is a struct with 3 float x,y,z members for the [p]osition, 2 float s,t members for the [t]exture coordinates and 4 unsigned byte r,g,b,a members for the [c]olor. The hope is that people will find these convenient enough to replace cogl_polygon.
This commit is contained in:
parent
9498d505dd
commit
a03a5814e7
@ -96,6 +96,252 @@ cogl_primitive_new (CoglVerticesMode mode,
|
|||||||
attributes);
|
attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_p3 (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP3Vertex *data)
|
||||||
|
{
|
||||||
|
CoglVertexArray *array =
|
||||||
|
cogl_vertex_array_new (n_vertices * sizeof (CoglP3Vertex));
|
||||||
|
CoglBuffer *buffer = COGL_BUFFER (array);
|
||||||
|
CoglVertexAttribute *attributes[2];
|
||||||
|
CoglPrimitive *prim;
|
||||||
|
|
||||||
|
cogl_buffer_set_data (buffer, 0, (guint8 *)data,
|
||||||
|
n_vertices * sizeof (CoglP3Vertex));
|
||||||
|
attributes[0] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_position_in",
|
||||||
|
sizeof (CoglP3Vertex),
|
||||||
|
offsetof (CoglP3Vertex, x),
|
||||||
|
3,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
|
attributes[1] = NULL;
|
||||||
|
prim = cogl_primitive_new_with_attributes_array (mode, n_vertices,
|
||||||
|
attributes);
|
||||||
|
cogl_object_unref (prim);
|
||||||
|
return prim;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_p2c4 (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP2C4Vertex *data)
|
||||||
|
{
|
||||||
|
CoglVertexArray *array =
|
||||||
|
cogl_vertex_array_new (n_vertices * sizeof (CoglP2C4Vertex));
|
||||||
|
CoglBuffer *buffer = COGL_BUFFER (array);
|
||||||
|
CoglVertexAttribute *attributes[3];
|
||||||
|
CoglPrimitive *prim;
|
||||||
|
|
||||||
|
cogl_buffer_set_data (buffer, 0, (guint8 *)data,
|
||||||
|
n_vertices * sizeof (CoglP2C4Vertex));
|
||||||
|
attributes[0] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_position_in",
|
||||||
|
sizeof (CoglP2C4Vertex),
|
||||||
|
offsetof (CoglP2C4Vertex, x),
|
||||||
|
2,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
|
attributes[1] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_color_in",
|
||||||
|
sizeof (CoglP2C4Vertex),
|
||||||
|
offsetof (CoglP2C4Vertex, r),
|
||||||
|
4,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
|
||||||
|
attributes[2] = NULL;
|
||||||
|
prim = cogl_primitive_new_with_attributes_array (mode, n_vertices,
|
||||||
|
attributes);
|
||||||
|
cogl_object_unref (prim);
|
||||||
|
return prim;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_p3c4 (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP3C4Vertex *data)
|
||||||
|
{
|
||||||
|
CoglVertexArray *array =
|
||||||
|
cogl_vertex_array_new (n_vertices * sizeof (CoglP3C4Vertex));
|
||||||
|
CoglBuffer *buffer = COGL_BUFFER (array);
|
||||||
|
CoglVertexAttribute *attributes[3];
|
||||||
|
CoglPrimitive *prim;
|
||||||
|
|
||||||
|
cogl_buffer_set_data (buffer, 0, (guint8 *)data,
|
||||||
|
n_vertices * sizeof (CoglP3C4Vertex));
|
||||||
|
attributes[0] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_position_in",
|
||||||
|
sizeof (CoglP3C4Vertex),
|
||||||
|
offsetof (CoglP3C4Vertex, x),
|
||||||
|
3,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
|
attributes[1] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_color_in",
|
||||||
|
sizeof (CoglP3C4Vertex),
|
||||||
|
offsetof (CoglP3C4Vertex, r),
|
||||||
|
4,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
|
||||||
|
attributes[2] = NULL;
|
||||||
|
prim = cogl_primitive_new_with_attributes_array (mode, n_vertices,
|
||||||
|
attributes);
|
||||||
|
cogl_object_unref (prim);
|
||||||
|
return prim;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_p2t2 (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP2T2Vertex *data)
|
||||||
|
{
|
||||||
|
CoglVertexArray *array =
|
||||||
|
cogl_vertex_array_new (n_vertices * sizeof (CoglP2T2Vertex));
|
||||||
|
CoglBuffer *buffer = COGL_BUFFER (array);
|
||||||
|
CoglVertexAttribute *attributes[3];
|
||||||
|
CoglPrimitive *prim;
|
||||||
|
|
||||||
|
cogl_buffer_set_data (buffer, 0, (guint8 *)data,
|
||||||
|
n_vertices * sizeof (CoglP2T2Vertex));
|
||||||
|
attributes[0] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_position_in",
|
||||||
|
sizeof (CoglP2T2Vertex),
|
||||||
|
offsetof (CoglP2T2Vertex, x),
|
||||||
|
2,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
|
attributes[1] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_tex_coord0_in",
|
||||||
|
sizeof (CoglP2T2Vertex),
|
||||||
|
offsetof (CoglP2T2Vertex, x),
|
||||||
|
2,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
|
attributes[2] = NULL;
|
||||||
|
prim = cogl_primitive_new_with_attributes_array (mode, n_vertices,
|
||||||
|
attributes);
|
||||||
|
cogl_object_unref (array);
|
||||||
|
return prim;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_p3t2 (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP3T2Vertex *data)
|
||||||
|
{
|
||||||
|
CoglVertexArray *array =
|
||||||
|
cogl_vertex_array_new (n_vertices * sizeof (CoglP3T2Vertex));
|
||||||
|
CoglBuffer *buffer = COGL_BUFFER (array);
|
||||||
|
CoglVertexAttribute *attributes[3];
|
||||||
|
CoglPrimitive *prim;
|
||||||
|
|
||||||
|
cogl_buffer_set_data (buffer, 0, (guint8 *)data,
|
||||||
|
n_vertices * sizeof (CoglP3T2Vertex));
|
||||||
|
attributes[0] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_position_in",
|
||||||
|
sizeof (CoglP3T2Vertex),
|
||||||
|
offsetof (CoglP3T2Vertex, x),
|
||||||
|
3,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
|
attributes[1] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_tex_coord0_in",
|
||||||
|
sizeof (CoglP3T2Vertex),
|
||||||
|
offsetof (CoglP3T2Vertex, x),
|
||||||
|
2,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
|
attributes[2] = NULL;
|
||||||
|
prim = cogl_primitive_new_with_attributes_array (mode, n_vertices,
|
||||||
|
attributes);
|
||||||
|
cogl_object_unref (prim);
|
||||||
|
return prim;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_p2t2c4 (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP2T2C4Vertex *data)
|
||||||
|
{
|
||||||
|
CoglVertexArray *array =
|
||||||
|
cogl_vertex_array_new (n_vertices * sizeof (CoglP2T2C4Vertex));
|
||||||
|
CoglBuffer *buffer = COGL_BUFFER (array);
|
||||||
|
CoglVertexAttribute *attributes[4];
|
||||||
|
CoglPrimitive *prim;
|
||||||
|
|
||||||
|
cogl_buffer_set_data (buffer, 0, (guint8 *)data,
|
||||||
|
n_vertices * sizeof (CoglP2T2C4Vertex));
|
||||||
|
attributes[0] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_position_in",
|
||||||
|
sizeof (CoglP2T2C4Vertex),
|
||||||
|
offsetof (CoglP2T2C4Vertex, x),
|
||||||
|
2,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
|
attributes[1] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_tex_coord0_in",
|
||||||
|
sizeof (CoglP2T2C4Vertex),
|
||||||
|
offsetof (CoglP2T2C4Vertex, x),
|
||||||
|
2,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
|
attributes[2] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_color_in",
|
||||||
|
sizeof (CoglP2T2C4Vertex),
|
||||||
|
offsetof (CoglP2T2C4Vertex, r),
|
||||||
|
4,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
|
||||||
|
attributes[3] = NULL;
|
||||||
|
prim = cogl_primitive_new_with_attributes_array (mode, n_vertices,
|
||||||
|
attributes);
|
||||||
|
cogl_object_unref (prim);
|
||||||
|
return prim;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_p3t2c4 (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP3T2C4Vertex *data)
|
||||||
|
{
|
||||||
|
CoglVertexArray *array =
|
||||||
|
cogl_vertex_array_new (n_vertices * sizeof (CoglP3T2C4Vertex));
|
||||||
|
CoglBuffer *buffer = COGL_BUFFER (array);
|
||||||
|
CoglVertexAttribute *attributes[4];
|
||||||
|
CoglPrimitive *prim;
|
||||||
|
|
||||||
|
cogl_buffer_set_data (buffer, 0, (guint8 *)data,
|
||||||
|
n_vertices * sizeof (CoglP3T2C4Vertex));
|
||||||
|
attributes[0] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_position_in",
|
||||||
|
sizeof (CoglP3T2C4Vertex),
|
||||||
|
offsetof (CoglP3T2C4Vertex, x),
|
||||||
|
3,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
|
attributes[1] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_tex_coord0_in",
|
||||||
|
sizeof (CoglP3T2C4Vertex),
|
||||||
|
offsetof (CoglP3T2C4Vertex, x),
|
||||||
|
2,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT);
|
||||||
|
attributes[2] =
|
||||||
|
cogl_vertex_attribute_new (array,
|
||||||
|
"cogl_color_in",
|
||||||
|
sizeof (CoglP3T2C4Vertex),
|
||||||
|
offsetof (CoglP3T2C4Vertex, r),
|
||||||
|
4,
|
||||||
|
COGL_VERTEX_ATTRIBUTE_TYPE_UNSIGNED_BYTE);
|
||||||
|
attributes[3] = NULL;
|
||||||
|
prim = cogl_primitive_new_with_attributes_array (mode, n_vertices,
|
||||||
|
attributes);
|
||||||
|
cogl_object_unref (prim);
|
||||||
|
return prim;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_attributes_list (CoglPrimitive *primitive)
|
free_attributes_list (CoglPrimitive *primitive)
|
||||||
{
|
{
|
||||||
|
@ -47,7 +47,7 @@ G_BEGIN_DECLS
|
|||||||
typedef struct _CoglPrimitive CoglPrimitive;
|
typedef struct _CoglPrimitive CoglPrimitive;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CoglV2Vertex:
|
* CoglP2Vertex:
|
||||||
* @x: The x component of a position attribute
|
* @x: The x component of a position attribute
|
||||||
* @y: The y component of a position attribute
|
* @y: The y component of a position attribute
|
||||||
*
|
*
|
||||||
@ -60,10 +60,10 @@ typedef struct _CoglPrimitive CoglPrimitive;
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
} CoglV2Vertex;
|
} CoglP2Vertex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CoglV3Vertex:
|
* CoglP3Vertex:
|
||||||
* @x: The x component of a position attribute
|
* @x: The x component of a position attribute
|
||||||
* @y: The y component of a position attribute
|
* @y: The y component of a position attribute
|
||||||
* @z: The z component of a position attribute
|
* @z: The z component of a position attribute
|
||||||
@ -77,10 +77,10 @@ typedef struct
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
} CoglV3Vertex;
|
} CoglP3Vertex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CoglV2C4Vertex:
|
* CoglP2C4Vertex:
|
||||||
* @x: The x component of a position attribute
|
* @x: The x component of a position attribute
|
||||||
* @y: The y component of a position attribute
|
* @y: The y component of a position attribute
|
||||||
* @r: The red component of a color attribute
|
* @r: The red component of a color attribute
|
||||||
@ -98,10 +98,10 @@ typedef struct
|
|||||||
{
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
guint8 r, g, b, a;
|
guint8 r, g, b, a;
|
||||||
} CoglV2C4Vertex;
|
} CoglP2C4Vertex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CoglV3C4Vertex:
|
* CoglP3C4Vertex:
|
||||||
* @x: The x component of a position attribute
|
* @x: The x component of a position attribute
|
||||||
* @y: The y component of a position attribute
|
* @y: The y component of a position attribute
|
||||||
* @z: The z component of a position attribute
|
* @z: The z component of a position attribute
|
||||||
@ -120,10 +120,10 @@ typedef struct
|
|||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
guint8 r, g, b, a;
|
guint8 r, g, b, a;
|
||||||
} CoglV3C4Vertex;
|
} CoglP3C4Vertex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CoglV2T2Vertex:
|
* CoglP2T2Vertex:
|
||||||
* @x: The x component of a position attribute
|
* @x: The x component of a position attribute
|
||||||
* @y: The y component of a position attribute
|
* @y: The y component of a position attribute
|
||||||
* @s: The s component of a texture coordinate attribute
|
* @s: The s component of a texture coordinate attribute
|
||||||
@ -139,10 +139,10 @@ typedef struct
|
|||||||
{
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
float s, t;
|
float s, t;
|
||||||
} CoglV2T2Vertex;
|
} CoglP2T2Vertex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CoglV3T2Vertex:
|
* CoglP3T2Vertex:
|
||||||
* @x: The x component of a position attribute
|
* @x: The x component of a position attribute
|
||||||
* @y: The y component of a position attribute
|
* @y: The y component of a position attribute
|
||||||
* @z: The z component of a position attribute
|
* @z: The z component of a position attribute
|
||||||
@ -159,11 +159,11 @@ typedef struct
|
|||||||
{
|
{
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
float s, t;
|
float s, t;
|
||||||
} CoglV3T2Vertex;
|
} CoglP3T2Vertex;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CoglV2T2C4Vertex:
|
* CoglP2T2C4Vertex:
|
||||||
* @x: The x component of a position attribute
|
* @x: The x component of a position attribute
|
||||||
* @y: The y component of a position attribute
|
* @y: The y component of a position attribute
|
||||||
* @s: The s component of a texture coordinate attribute
|
* @s: The s component of a texture coordinate attribute
|
||||||
@ -184,10 +184,10 @@ typedef struct
|
|||||||
float x, y;
|
float x, y;
|
||||||
float s, t;
|
float s, t;
|
||||||
guint8 r, g, b, a;
|
guint8 r, g, b, a;
|
||||||
} CoglV2T2C4Vertex;
|
} CoglP2T2C4Vertex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CoglV3T2C4Vertex:
|
* CoglP3T2C4Vertex:
|
||||||
* @x: The x component of a position attribute
|
* @x: The x component of a position attribute
|
||||||
* @y: The y component of a position attribute
|
* @y: The y component of a position attribute
|
||||||
* @z: The z component of a position attribute
|
* @z: The z component of a position attribute
|
||||||
@ -209,7 +209,7 @@ typedef struct
|
|||||||
float x, y, z;
|
float x, y, z;
|
||||||
float s, t;
|
float s, t;
|
||||||
guint8 r, g, b, a;
|
guint8 r, g, b, a;
|
||||||
} CoglV3T2C4Vertex;
|
} CoglP3T2C4Vertex;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* cogl_primitive_new:
|
* cogl_primitive_new:
|
||||||
@ -237,6 +237,40 @@ cogl_primitive_new_with_attributes_array (CoglVerticesMode mode,
|
|||||||
int n_vertices,
|
int n_vertices,
|
||||||
CoglVertexAttribute **attributes);
|
CoglVertexAttribute **attributes);
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_with_v3_attributes (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP3Vertex *data);
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_with_v2c4_attributes (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP2C4Vertex *data);
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_with_v3c4_attributes (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP3C4Vertex *data);
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_with_v2t2_attributes (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP2T2Vertex *data);
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_with_v3t2_attributes (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP3T2Vertex *data);
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_with_v2t2c4_attributes (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP2T2C4Vertex *data);
|
||||||
|
|
||||||
|
CoglPrimitive *
|
||||||
|
cogl_primitive_new_with_v3t2c4_attributes (CoglVerticesMode mode,
|
||||||
|
int n_vertices,
|
||||||
|
const CoglP3T2C4Vertex *data);
|
||||||
int
|
int
|
||||||
cogl_primitive_get_first_vertex (CoglPrimitive *primitive);
|
cogl_primitive_get_first_vertex (CoglPrimitive *primitive);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user