1
0
Fork 0

vertex-array: Adds data arg for _vertex_array_new()

This adds an optional data argument for cogl_vertex_array_new() since it
seems that mostly every case where we use this API we follow up with a
cogl_buffer_set_data() matching the size of the new array. This
simplifies all those cases and whenever we want to delay uploading of
data then NULL can simply be passed.
This commit is contained in:
Robert Bragg 2010-11-16 08:49:55 +00:00
parent 60daaff724
commit 982f1b4bd0
7 changed files with 33 additions and 50 deletions

View file

@ -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);

View file

@ -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",

View file

@ -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,

View file

@ -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

View file

@ -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:

View file

@ -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);

View file

@ -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);
}