mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 16:10:41 -05:00
[vbo indices] tweak add_indices api to return an id and add delete_indices api
Originally cogl_vertex_buffer_add_indices let the user pass in their own unique ID for the indices; now the Id is generated internally and returned to the caller.
This commit is contained in:
parent
d51faed660
commit
59bd824404
@ -305,8 +305,6 @@ typedef enum _CoglIndicesType
|
||||
/**
|
||||
* cogl_vertex_buffer_add_indices:
|
||||
* @handle: A vertex buffer handle
|
||||
* @id: Any unique number. It's used to identify the indices when you later
|
||||
* call cogl_vertex_buffer_draw_elements()
|
||||
* @min_index: Specifies the minimum vertex index contained in indices
|
||||
* @max_index: Specifies the maximum vertex index contained in indices
|
||||
* @indices_type: a #CoglIndicesType specifying the data type used for
|
||||
@ -319,20 +317,36 @@ typedef enum _CoglIndicesType
|
||||
* array allows you to reference vertices multiple times, for example
|
||||
* during triangle strips.
|
||||
*
|
||||
* You should aim to use the COGL_INDICES_TYPE_UNSIGNED_SHORT when possible
|
||||
* and correctly reflect the range of index values in the {min,max}_index
|
||||
* arguments. This allows Cogl to optimize the internal storage used for
|
||||
* the indices and reduce the demand for memory bandwidth.
|
||||
* You should aim to use the smallest data type possible and correctly reflect
|
||||
* the range of index values in the {min,max}_index arguments. This allows Cogl
|
||||
* to optimize the internal storage used for the indices and reduce the demand
|
||||
* for memory bandwidth.
|
||||
*
|
||||
* Returns: An identifier (greater than 0) for the indices which you can
|
||||
* pass to cogl_vertex_buffer_draw_elements().
|
||||
*/
|
||||
void
|
||||
int
|
||||
cogl_vertex_buffer_add_indices (CoglHandle handle,
|
||||
int id,
|
||||
int min_index,
|
||||
int max_index,
|
||||
CoglIndicesType indices_type,
|
||||
const void *indices_array,
|
||||
int indices_len);
|
||||
|
||||
/**
|
||||
* cogl_vertex_buffer_delete_indices:
|
||||
* @handle: A vertex buffer handle
|
||||
* @indices_id: The identifier for a an array of indices previously added to
|
||||
* the given Cogl vertex buffer using
|
||||
* cogl_vertex_buffer_add_indices().
|
||||
*
|
||||
* Frees the resources associated with a previously added array of vertex
|
||||
* indices.
|
||||
*/
|
||||
void
|
||||
cogl_vertex_buffer_delete_indices (CoglHandle handle,
|
||||
int indices_id);
|
||||
|
||||
/**
|
||||
* cogl_vertex_buffer_draw_elements:
|
||||
* @handle: A vertex buffer handle
|
||||
|
@ -1771,9 +1771,8 @@ get_indices_type_size (GLuint indices_type)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
int
|
||||
cogl_vertex_buffer_add_indices (CoglHandle handle,
|
||||
int id,
|
||||
int min_index,
|
||||
int max_index,
|
||||
CoglIndicesType indices_type,
|
||||
@ -1781,32 +1780,23 @@ cogl_vertex_buffer_add_indices (CoglHandle handle,
|
||||
int indices_len)
|
||||
{
|
||||
CoglVertexBuffer *buffer;
|
||||
GList *l;
|
||||
gboolean fallback =
|
||||
(cogl_get_features () & COGL_FEATURE_VBOS) ? FALSE : TRUE;
|
||||
size_t indices_bytes;
|
||||
CoglVertexBufferIndices *indices;
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
||||
static int next_indices_id = 1;
|
||||
|
||||
|
||||
_COGL_GET_CONTEXT (ctx, 0);
|
||||
|
||||
if (!cogl_is_vertex_buffer (handle))
|
||||
return;
|
||||
return 0;
|
||||
|
||||
buffer = _cogl_vertex_buffer_pointer_from_handle (handle);
|
||||
|
||||
for (l = buffer->indices; l; l = l->next)
|
||||
{
|
||||
CoglVertexBufferIndices *current_indices = l->data;
|
||||
if (current_indices->id == id)
|
||||
{
|
||||
free_vertex_buffer_indices (l->data);
|
||||
buffer->indices = g_list_delete_link (buffer->indices, l);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
indices = g_slice_alloc (sizeof (CoglVertexBufferIndices));
|
||||
indices->id = id;
|
||||
indices->id = next_indices_id;
|
||||
indices->min_index = min_index;
|
||||
indices->max_index = max_index;
|
||||
|
||||
@ -1818,7 +1808,7 @@ cogl_vertex_buffer_add_indices (CoglHandle handle,
|
||||
{
|
||||
g_critical ("unknown indices type %d", indices_type);
|
||||
g_slice_free (CoglVertexBufferIndices, indices);
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
indices_bytes = get_indices_type_size (indices->type) * indices_len;
|
||||
@ -1840,6 +1830,32 @@ cogl_vertex_buffer_add_indices (CoglHandle handle,
|
||||
}
|
||||
|
||||
buffer->indices = g_list_prepend (buffer->indices, indices);
|
||||
|
||||
return next_indices_id++;
|
||||
}
|
||||
|
||||
void
|
||||
cogl_vertex_buffer_delete_indices (CoglHandle handle,
|
||||
int indices_id)
|
||||
{
|
||||
CoglVertexBuffer *buffer;
|
||||
GList *l;
|
||||
|
||||
if (!cogl_is_vertex_buffer (handle))
|
||||
return;
|
||||
|
||||
buffer = _cogl_vertex_buffer_pointer_from_handle (handle);
|
||||
|
||||
for (l = buffer->indices; l; l = l->next)
|
||||
{
|
||||
CoglVertexBufferIndices *current_indices = l->data;
|
||||
if (current_indices->id == indices_id)
|
||||
{
|
||||
free_vertex_buffer_indices (l->data);
|
||||
buffer->indices = g_list_delete_link (buffer->indices, l);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -309,6 +309,7 @@ cogl_vertex_buffer_enable
|
||||
cogl_vertex_buffer_draw
|
||||
CoglIndicesType
|
||||
cogl_vertex_buffer_add_indices
|
||||
cogl_vertex_buffer_delete_indices
|
||||
cogl_vertex_buffer_draw_elements
|
||||
<SUBSECTION Private>
|
||||
CoglVertexBufferAttribFlags
|
||||
|
@ -49,6 +49,7 @@ typedef struct _TestState
|
||||
GLubyte *quad_mesh_colors;
|
||||
GLushort *static_indices;
|
||||
guint n_static_indices;
|
||||
int indices_id;
|
||||
ClutterTimeline *timeline;
|
||||
} TestState;
|
||||
|
||||
@ -140,7 +141,7 @@ on_paint (ClutterActor *actor, TestState *state)
|
||||
cogl_set_source_color4ub (0xff, 0x00, 0x00, 0xff);
|
||||
cogl_vertex_buffer_draw_elements (state->buffer,
|
||||
COGL_VERTICES_MODE_TRIANGLE_STRIP,
|
||||
0, /* indices identifier */
|
||||
state->indices_id,
|
||||
0, /* indices offset */
|
||||
state->n_static_indices);
|
||||
}
|
||||
@ -219,14 +220,14 @@ init_static_index_arrays (TestState *state)
|
||||
|
||||
#undef MESH_INDEX
|
||||
|
||||
cogl_vertex_buffer_add_indices (state->buffer,
|
||||
0, /* identifier */
|
||||
0, /* min index */
|
||||
(MESH_WIDTH + 1) *
|
||||
(MESH_HEIGHT + 1), /* max index */
|
||||
COGL_INDICES_TYPE_UNSIGNED_SHORT,
|
||||
state->static_indices,
|
||||
state->n_static_indices);
|
||||
state->indices_id =
|
||||
cogl_vertex_buffer_add_indices (state->buffer,
|
||||
0, /* min index */
|
||||
(MESH_WIDTH + 1) *
|
||||
(MESH_HEIGHT + 1), /* max index */
|
||||
COGL_INDICES_TYPE_UNSIGNED_SHORT,
|
||||
state->static_indices,
|
||||
state->n_static_indices);
|
||||
}
|
||||
|
||||
static float
|
||||
|
Loading…
Reference in New Issue
Block a user