From 6027aa04a4bd1943ffd98db1f258e948198a0926 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Thu, 4 Nov 2010 16:01:23 +0000 Subject: [PATCH] cogl-buffer: Use void* instead of guint8* for map and set_data Unless the CoglBuffer is being used for texture data then it's relatively unlikely that the data will contain an array of bytes. For example if it's used as a vertex array then it's more likely to be floats or some vertex struct. In that case it's much more convenient if set_data and map use void* pointers so that we can avoid a cast. --- cogl/cogl-buffer-private.h | 8 ++++---- cogl/cogl-buffer.c | 12 ++++++------ cogl/cogl-buffer.h | 4 ++-- cogl/cogl-journal.c | 2 +- cogl/cogl-primitive.c | 16 ++++++++-------- cogl/cogl-primitives.c | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cogl/cogl-buffer-private.h b/cogl/cogl-buffer-private.h index 3f4686c71..28d1a25d6 100644 --- a/cogl/cogl-buffer-private.h +++ b/cogl/cogl-buffer-private.h @@ -42,15 +42,15 @@ typedef struct _CoglBufferVtable CoglBufferVtable; struct _CoglBufferVtable { - guint8 * (* map) (CoglBuffer *buffer, - CoglBufferAccess access, - CoglBufferMapHint hints); + void * (* map) (CoglBuffer *buffer, + CoglBufferAccess access, + CoglBufferMapHint hints); void (* unmap) (CoglBuffer *buffer); gboolean (* set_data) (CoglBuffer *buffer, unsigned int offset, - const guint8 *data, + const void *data, unsigned int size); }; diff --git a/cogl/cogl-buffer.c b/cogl/cogl-buffer.c index 7e73ba96f..a63e171f9 100644 --- a/cogl/cogl-buffer.c +++ b/cogl/cogl-buffer.c @@ -130,7 +130,7 @@ convert_bind_target_to_gl_target (CoglBufferBindTarget target) } } -static guint8 * +static void * bo_map (CoglBuffer *buffer, CoglBufferAccess access, CoglBufferMapHint hints) @@ -196,7 +196,7 @@ bo_unmap (CoglBuffer *buffer) static gboolean bo_set_data (CoglBuffer *buffer, unsigned int offset, - const guint8 *data, + const void *data, unsigned int size) { CoglBufferBindTarget target; @@ -233,7 +233,7 @@ bo_set_data (CoglBuffer *buffer, * Fallback path, buffer->data points to a malloc'ed buffer. */ -static guint8 * +static void * malloc_map (CoglBuffer *buffer, CoglBufferAccess access, CoglBufferMapHint hints) @@ -251,7 +251,7 @@ malloc_unmap (CoglBuffer *buffer) static gboolean malloc_set_data (CoglBuffer *buffer, unsigned int offset, - const guint8 *data, + const void *data, unsigned int size) { memcpy (buffer->data + offset, data, size); @@ -442,7 +442,7 @@ warn_about_midscene_changes (void) } } -guint8 * +void * cogl_buffer_map (CoglBuffer *buffer, CoglBufferAccess access, CoglBufferMapHint hints) @@ -474,7 +474,7 @@ cogl_buffer_unmap (CoglBuffer *buffer) gboolean cogl_buffer_set_data (CoglBuffer *buffer, gsize offset, - const guint8 *data, + const void *data, gsize size) { g_return_val_if_fail (cogl_is_buffer (buffer), FALSE); diff --git a/cogl/cogl-buffer.h b/cogl/cogl-buffer.h index f7b954930..50c5d10bf 100644 --- a/cogl/cogl-buffer.h +++ b/cogl/cogl-buffer.h @@ -198,7 +198,7 @@ typedef enum { /*< prefix=COGL_BUFFER_MAP_HINT >*/ * Since: 1.2 * Stability: Unstable */ -guint8 * +void * cogl_buffer_map (CoglBuffer *buffer, CoglBufferAccess access, CoglBufferMapHint hints); @@ -234,7 +234,7 @@ cogl_buffer_unmap (CoglBuffer *buffer); gboolean cogl_buffer_set_data (CoglBuffer *buffer, gsize offset, - const guint8 *data, + const void *data, gsize size); G_END_DECLS diff --git a/cogl/cogl-journal.c b/cogl/cogl-journal.c index a68a30a9f..e320ebf56 100644 --- a/cogl/cogl-journal.c +++ b/cogl/cogl-journal.c @@ -595,7 +595,7 @@ upload_vertices (GArray *vertices, CoglJournalFlushState *state) array = cogl_vertex_array_new (needed_vbo_len); buffer = COGL_BUFFER (array); cogl_buffer_set_update_hint (buffer, COGL_BUFFER_UPDATE_HINT_STATIC); - cogl_buffer_set_data (buffer, 0, (guint8 *)vertices->data, needed_vbo_len); + cogl_buffer_set_data (buffer, 0, vertices->data, needed_vbo_len); /* As we flush the journal entries in batches we walk forward through the * above VBO starting at offset 0... */ diff --git a/cogl/cogl-primitive.c b/cogl/cogl-primitive.c index 61d1077da..62857c292 100644 --- a/cogl/cogl-primitive.c +++ b/cogl/cogl-primitive.c @@ -130,7 +130,7 @@ cogl_primitive_new_p2 (CoglVerticesMode mode, CoglBuffer *buffer = COGL_BUFFER (array); CoglVertexAttribute *attributes[2]; - cogl_buffer_set_data (buffer, 0, (guint8 *)data, + cogl_buffer_set_data (buffer, 0, data, n_vertices * sizeof (CoglP2Vertex)); attributes[0] = cogl_vertex_attribute_new (array, @@ -157,7 +157,7 @@ cogl_primitive_new_p3 (CoglVerticesMode mode, CoglBuffer *buffer = COGL_BUFFER (array); CoglVertexAttribute *attributes[2]; - cogl_buffer_set_data (buffer, 0, (guint8 *)data, + cogl_buffer_set_data (buffer, 0, data, n_vertices * sizeof (CoglP3Vertex)); attributes[0] = cogl_vertex_attribute_new (array, @@ -184,7 +184,7 @@ cogl_primitive_new_p2c4 (CoglVerticesMode mode, CoglBuffer *buffer = COGL_BUFFER (array); CoglVertexAttribute *attributes[3]; - cogl_buffer_set_data (buffer, 0, (guint8 *)data, + cogl_buffer_set_data (buffer, 0, data, n_vertices * sizeof (CoglP2C4Vertex)); attributes[0] = cogl_vertex_attribute_new (array, @@ -218,7 +218,7 @@ cogl_primitive_new_p3c4 (CoglVerticesMode mode, CoglBuffer *buffer = COGL_BUFFER (array); CoglVertexAttribute *attributes[3]; - cogl_buffer_set_data (buffer, 0, (guint8 *)data, + cogl_buffer_set_data (buffer, 0, data, n_vertices * sizeof (CoglP3C4Vertex)); attributes[0] = cogl_vertex_attribute_new (array, @@ -252,7 +252,7 @@ cogl_primitive_new_p2t2 (CoglVerticesMode mode, CoglBuffer *buffer = COGL_BUFFER (array); CoglVertexAttribute *attributes[3]; - cogl_buffer_set_data (buffer, 0, (guint8 *)data, + cogl_buffer_set_data (buffer, 0, data, n_vertices * sizeof (CoglP2T2Vertex)); attributes[0] = cogl_vertex_attribute_new (array, @@ -286,7 +286,7 @@ cogl_primitive_new_p3t2 (CoglVerticesMode mode, CoglBuffer *buffer = COGL_BUFFER (array); CoglVertexAttribute *attributes[3]; - cogl_buffer_set_data (buffer, 0, (guint8 *)data, + cogl_buffer_set_data (buffer, 0, data, n_vertices * sizeof (CoglP3T2Vertex)); attributes[0] = cogl_vertex_attribute_new (array, @@ -320,7 +320,7 @@ cogl_primitive_new_p2t2c4 (CoglVerticesMode mode, CoglBuffer *buffer = COGL_BUFFER (array); CoglVertexAttribute *attributes[4]; - cogl_buffer_set_data (buffer, 0, (guint8 *)data, + cogl_buffer_set_data (buffer, 0, data, n_vertices * sizeof (CoglP2T2C4Vertex)); attributes[0] = cogl_vertex_attribute_new (array, @@ -361,7 +361,7 @@ cogl_primitive_new_p3t2c4 (CoglVerticesMode mode, CoglBuffer *buffer = COGL_BUFFER (array); CoglVertexAttribute *attributes[4]; - cogl_buffer_set_data (buffer, 0, (guint8 *)data, + cogl_buffer_set_data (buffer, 0, data, n_vertices * sizeof (CoglP3T2C4Vertex)); attributes[0] = cogl_vertex_attribute_new (array, diff --git a/cogl/cogl-primitives.c b/cogl/cogl-primitives.c index 466402a92..63bd8d474 100644 --- a/cogl/cogl-primitives.c +++ b/cogl/cogl-primitives.c @@ -1024,7 +1024,7 @@ cogl_polygon (const CoglTextureVertex *vertices, v = (float *)ctx->polygon_vertices->data; cogl_buffer_set_data (COGL_BUFFER (vertex_array), 0, - (const guint8 *)v, + v, ctx->polygon_vertices->len * sizeof (float)); cogl_push_source (pipeline);