diff --git a/cogl/cogl-journal.c b/cogl/cogl-journal.c index 584726623..9d8ea572e 100644 --- a/cogl/cogl-journal.c +++ b/cogl/cogl-journal.c @@ -655,7 +655,7 @@ upload_vertices (GArray *vertices, CoglJournalFlushState *state) needed_vbo_len = vertices->len * sizeof (float); g_assert (needed_vbo_len); - array = cogl_vertex_array_new (needed_vbo_len); + array = cogl_vertex_array_new (needed_vbo_len, NULL); buffer = COGL_BUFFER (array); cogl_buffer_set_update_hint (buffer, COGL_BUFFER_UPDATE_HINT_STATIC); cogl_buffer_set_data (buffer, 0, vertices->data, needed_vbo_len); diff --git a/cogl/cogl-primitive.c b/cogl/cogl-primitive.c index 62857c292..2edac5f85 100644 --- a/cogl/cogl-primitive.c +++ b/cogl/cogl-primitive.c @@ -126,12 +126,9 @@ cogl_primitive_new_p2 (CoglVerticesMode mode, const CoglP2Vertex *data) { CoglVertexArray *array = - cogl_vertex_array_new (n_vertices * sizeof (CoglP2Vertex)); - CoglBuffer *buffer = COGL_BUFFER (array); + cogl_vertex_array_new (n_vertices * sizeof (CoglP2Vertex), data); CoglVertexAttribute *attributes[2]; - cogl_buffer_set_data (buffer, 0, data, - n_vertices * sizeof (CoglP2Vertex)); attributes[0] = cogl_vertex_attribute_new (array, "cogl_position_in", @@ -153,12 +150,9 @@ cogl_primitive_new_p3 (CoglVerticesMode mode, const CoglP3Vertex *data) { CoglVertexArray *array = - cogl_vertex_array_new (n_vertices * sizeof (CoglP3Vertex)); - CoglBuffer *buffer = COGL_BUFFER (array); + cogl_vertex_array_new (n_vertices * sizeof (CoglP3Vertex), data); CoglVertexAttribute *attributes[2]; - cogl_buffer_set_data (buffer, 0, data, - n_vertices * sizeof (CoglP3Vertex)); attributes[0] = cogl_vertex_attribute_new (array, "cogl_position_in", @@ -180,12 +174,9 @@ cogl_primitive_new_p2c4 (CoglVerticesMode mode, const CoglP2C4Vertex *data) { CoglVertexArray *array = - cogl_vertex_array_new (n_vertices * sizeof (CoglP2C4Vertex)); - CoglBuffer *buffer = COGL_BUFFER (array); + cogl_vertex_array_new (n_vertices * sizeof (CoglP2C4Vertex), data); CoglVertexAttribute *attributes[3]; - cogl_buffer_set_data (buffer, 0, data, - n_vertices * sizeof (CoglP2C4Vertex)); attributes[0] = cogl_vertex_attribute_new (array, "cogl_position_in", @@ -214,12 +205,9 @@ cogl_primitive_new_p3c4 (CoglVerticesMode mode, const CoglP3C4Vertex *data) { CoglVertexArray *array = - cogl_vertex_array_new (n_vertices * sizeof (CoglP3C4Vertex)); - CoglBuffer *buffer = COGL_BUFFER (array); + cogl_vertex_array_new (n_vertices * sizeof (CoglP3C4Vertex), data); CoglVertexAttribute *attributes[3]; - cogl_buffer_set_data (buffer, 0, data, - n_vertices * sizeof (CoglP3C4Vertex)); attributes[0] = cogl_vertex_attribute_new (array, "cogl_position_in", @@ -248,12 +236,9 @@ cogl_primitive_new_p2t2 (CoglVerticesMode mode, const CoglP2T2Vertex *data) { CoglVertexArray *array = - cogl_vertex_array_new (n_vertices * sizeof (CoglP2T2Vertex)); - CoglBuffer *buffer = COGL_BUFFER (array); + cogl_vertex_array_new (n_vertices * sizeof (CoglP2T2Vertex), data); CoglVertexAttribute *attributes[3]; - cogl_buffer_set_data (buffer, 0, data, - n_vertices * sizeof (CoglP2T2Vertex)); attributes[0] = cogl_vertex_attribute_new (array, "cogl_position_in", @@ -282,12 +267,9 @@ cogl_primitive_new_p3t2 (CoglVerticesMode mode, const CoglP3T2Vertex *data) { CoglVertexArray *array = - cogl_vertex_array_new (n_vertices * sizeof (CoglP3T2Vertex)); - CoglBuffer *buffer = COGL_BUFFER (array); + cogl_vertex_array_new (n_vertices * sizeof (CoglP3T2Vertex), data); CoglVertexAttribute *attributes[3]; - cogl_buffer_set_data (buffer, 0, data, - n_vertices * sizeof (CoglP3T2Vertex)); attributes[0] = cogl_vertex_attribute_new (array, "cogl_position_in", @@ -316,12 +298,9 @@ cogl_primitive_new_p2t2c4 (CoglVerticesMode mode, const CoglP2T2C4Vertex *data) { CoglVertexArray *array = - cogl_vertex_array_new (n_vertices * sizeof (CoglP2T2C4Vertex)); - CoglBuffer *buffer = COGL_BUFFER (array); + cogl_vertex_array_new (n_vertices * sizeof (CoglP2T2C4Vertex), data); CoglVertexAttribute *attributes[4]; - cogl_buffer_set_data (buffer, 0, data, - n_vertices * sizeof (CoglP2T2C4Vertex)); attributes[0] = cogl_vertex_attribute_new (array, "cogl_position_in", @@ -357,12 +336,9 @@ cogl_primitive_new_p3t2c4 (CoglVerticesMode mode, const CoglP3T2C4Vertex *data) { CoglVertexArray *array = - cogl_vertex_array_new (n_vertices * sizeof (CoglP3T2C4Vertex)); - CoglBuffer *buffer = COGL_BUFFER (array); + cogl_vertex_array_new (n_vertices * sizeof (CoglP3T2C4Vertex), data); CoglVertexAttribute *attributes[4]; - cogl_buffer_set_data (buffer, 0, data, - n_vertices * sizeof (CoglP3T2C4Vertex)); attributes[0] = cogl_vertex_attribute_new (array, "cogl_position_in", diff --git a/cogl/cogl-primitives.c b/cogl/cogl-primitives.c index 0c548009b..c7c8ae60c 100644 --- a/cogl/cogl-primitives.c +++ b/cogl/cogl-primitives.c @@ -911,9 +911,7 @@ _cogl_rectangle_immediate (float x_1, CoglVertexArray *vertex_array; CoglVertexAttribute *attributes[2]; - vertex_array = cogl_vertex_array_new (sizeof (vertices)); - cogl_buffer_set_data (COGL_BUFFER (vertex_array), 0, - (guint8 *) vertices, sizeof (vertices)); + vertex_array = cogl_vertex_array_new (sizeof (vertices), vertices); attributes[0] = cogl_vertex_attribute_new (vertex_array, "cogl_position_in", sizeof (float) * 2, /* stride */ @@ -1053,7 +1051,7 @@ cogl_polygon (const CoglTextureVertex *vertices, * but still support any number of vertices */ g_array_set_size (ctx->polygon_vertices, n_vertices * stride); - vertex_array = cogl_vertex_array_new (n_vertices * stride_bytes); + vertex_array = cogl_vertex_array_new (n_vertices * stride_bytes, NULL); attributes[0] = cogl_vertex_attribute_new (vertex_array, diff --git a/cogl/cogl-vertex-array.c b/cogl/cogl-vertex-array.c index 23e010e26..965135cb0 100644 --- a/cogl/cogl-vertex-array.c +++ b/cogl/cogl-vertex-array.c @@ -38,7 +38,7 @@ static void _cogl_vertex_array_free (CoglVertexArray *array); COGL_BUFFER_DEFINE (VertexArray, vertex_array); CoglVertexArray * -cogl_vertex_array_new (gsize bytes) +cogl_vertex_array_new (gsize bytes, const void *data) { CoglVertexArray *array = g_slice_new (CoglVertexArray); gboolean use_malloc; @@ -56,7 +56,14 @@ cogl_vertex_array_new (gsize bytes) COGL_BUFFER_USAGE_HINT_VERTEX_ARRAY, COGL_BUFFER_UPDATE_HINT_STATIC); - return _cogl_vertex_array_object_new (array); + _cogl_vertex_array_object_new (array); + + if (data) + cogl_buffer_set_data (COGL_BUFFER (array), + 0, + data, + bytes); + return array; } static void diff --git a/cogl/cogl-vertex-array.h b/cogl/cogl-vertex-array.h index a27e627de..afcd6dad1 100644 --- a/cogl/cogl-vertex-array.h +++ b/cogl/cogl-vertex-array.h @@ -35,7 +35,7 @@ G_BEGIN_DECLS /** * SECTION:cogl-vertex-array - * @short_description: Fuctions for creating and manipulating vertex arrays + * @short_description: Functions for creating and manipulating vertex arrays * * FIXME */ @@ -45,16 +45,21 @@ typedef struct _CoglVertexArray CoglVertexArray; /** * cogl_vertex_array_new: * @size: The number of bytes to allocate for vertex attribute data. + * @data: An optional pointer to vertex data to upload immediately. * * Declares a new #CoglVertexArray of @size bytes to contain arrays of vertex * attribute data. Once declared, data can be set using cogl_buffer_set_data() * or by mapping it into the application's address space using cogl_buffer_map(). * + * If @data isn't %NULL then @size bytes will be read from @data and + * immediately copied into the new buffer. + * * Since: 1.4 * Stability: Unstable */ CoglVertexArray * -cogl_vertex_array_new (gsize bytes); +cogl_vertex_array_new (gsize bytes, + const void *data); /** * cogl_is_vertex_array: diff --git a/cogl/cogl-vertex-buffer.c b/cogl/cogl-vertex-buffer.c index 47ac93a37..dee14f4c7 100644 --- a/cogl/cogl-vertex-buffer.c +++ b/cogl/cogl-vertex-buffer.c @@ -1132,7 +1132,8 @@ cogl_vertex_buffer_vbo_resolve (CoglVertexBuffer *buffer, if (!found_target_vbo) { - new_cogl_vbo->array = cogl_vertex_array_new (new_cogl_vbo->array_bytes); + new_cogl_vbo->array = cogl_vertex_array_new (new_cogl_vbo->array_bytes, + NULL); upload_attributes (new_cogl_vbo); *final_vbos = g_list_prepend (*final_vbos, new_cogl_vbo); diff --git a/cogl/cogl2-path.c b/cogl/cogl2-path.c index 20fb8d2e5..1241f969d 100644 --- a/cogl/cogl2-path.c +++ b/cogl/cogl2-path.c @@ -1432,7 +1432,10 @@ _cogl_path_build_vbo (CoglPath *path) gluDeleteTess (tess.glu_tess); data->vbo = cogl_vertex_array_new (sizeof (CoglPathTesselatorVertex) * - tess.vertices->len); + tess.vertices->len, + tess.vertices->data); + g_array_free (tess.vertices, TRUE); + data->vbo_attributes[0] = cogl_vertex_attribute_new (data->vbo, "cogl_position_in", @@ -1454,13 +1457,6 @@ _cogl_path_build_vbo (CoglPath *path) tess.indices->data, tess.indices->len); data->vbo_n_indices = tess.indices->len; - - cogl_buffer_set_data (COGL_BUFFER (data->vbo), - 0, /* offset */ - tess.vertices->data, - sizeof (CoglPathTesselatorVertex) * tess.vertices->len); - - g_array_free (tess.vertices, TRUE); g_array_free (tess.indices, TRUE); }