From b6eaab812be51ceeab023b4556f23e3b9e8a9ec5 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Thu, 4 Nov 2010 16:42:11 +0000 Subject: [PATCH] cogl-primitive: Add the missing cogl_primitive_new_p2 function There was a struct defined for CoglP2Vertex but there was no constructor function to use it. --- clutter/cogl/cogl/cogl-primitive.c | 27 ++++++++++++++++++ clutter/cogl/cogl/cogl-primitive.h | 44 ++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/clutter/cogl/cogl/cogl-primitive.c b/clutter/cogl/cogl/cogl-primitive.c index 31f94358e..145c03d8b 100644 --- a/clutter/cogl/cogl/cogl-primitive.c +++ b/clutter/cogl/cogl/cogl-primitive.c @@ -120,6 +120,33 @@ cogl_primitive_new (CoglVerticesMode mode, attributes); } +CoglPrimitive * +cogl_primitive_new_p2 (CoglVerticesMode mode, + int n_vertices, + const CoglP2Vertex *data) +{ + CoglVertexArray *array = + cogl_vertex_array_new (n_vertices * sizeof (CoglP2Vertex)); + CoglBuffer *buffer = COGL_BUFFER (array); + CoglVertexAttribute *attributes[2]; + + cogl_buffer_set_data (buffer, 0, (guint8 *)data, + n_vertices * sizeof (CoglP2Vertex)); + attributes[0] = + cogl_vertex_attribute_new (array, + "cogl_position_in", + sizeof (CoglP2Vertex), + offsetof (CoglP2Vertex, x), + 2, + COGL_VERTEX_ATTRIBUTE_TYPE_FLOAT); + attributes[1] = NULL; + + cogl_object_unref (array); + + return _cogl_primitive_new_with_attributes_array_unref (mode, n_vertices, + attributes); +} + CoglPrimitive * cogl_primitive_new_p3 (CoglVerticesMode mode, int n_vertices, diff --git a/clutter/cogl/cogl/cogl-primitive.h b/clutter/cogl/cogl/cogl-primitive.h index 98ff0719d..d2eaa53c9 100644 --- a/clutter/cogl/cogl/cogl-primitive.h +++ b/clutter/cogl/cogl/cogl-primitive.h @@ -237,6 +237,50 @@ cogl_primitive_new_with_attributes_array (CoglVerticesMode mode, int n_vertices, CoglVertexAttribute **attributes); +/** + * cogl_primitive_new_p2: + * @mode: A #CoglVerticesMode defining how to draw the vertices + * @n_vertices: The number of vertices to process when drawing + * @data: An array of #CoglP2Vertex 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 #CoglVertexArray storage, describe the position + * attribute with a #CoglVertexAttribute and upload your data. + * + * For example to draw a convex polygon you can do: + * |[ + * CoglP2Vertex triangle[] = + * { + * { 0, 300 }, + * { 150, 0, }, + * { 300, 300 } + * }; + * prim = cogl_primitive_new_p2 (COGL_VERTICES_MODE_TRIANGLE_FAN, + * 3, triangle); + * cogl_primitive_draw (prim); + * ]| + * + * 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). You + * should pass the %COGL_TEXTURE_NO_SLICING flag to all textures that + * might be used while drawing with this API. 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: A newly allocated #CoglPrimitive with a reference of + * 1. This can be freed using cogl_object_unref(). + * + * Since: 1.6 + * Stability: Unstable + */ +CoglPrimitive * +cogl_primitive_new_p2 (CoglVerticesMode mode, + int n_vertices, + const CoglP2Vertex *data); + /** * cogl_primitive_new_p3: * @mode: A #CoglVerticesMode defining how to draw the vertices