Rename CoglIndexArray to CoglIndexBuffer

This is part of a broader cleanup of some of the experimental Cogl API.
One of the reasons for this particular rename is to switch away from
using the term "Array" which implies a regular, indexable layout which
isn't the case. We also want to strongly imply a relationship between
CoglBuffers and CoglIndexBuffers and be consistent with the
CoglAttributeBuffer and CoglPixelBuffer APIs.
This commit is contained in:
Robert Bragg 2011-03-02 23:31:19 +00:00
parent c328e0608f
commit bf7653ac93
12 changed files with 86 additions and 102 deletions

View File

@ -76,7 +76,7 @@ cogl_public_h = \
$(srcdir)/cogl-texture-3d.h \
$(srcdir)/cogl-types.h \
$(srcdir)/cogl-vertex-buffer.h \
$(srcdir)/cogl-index-array.h \
$(srcdir)/cogl-index-buffer.h \
$(srcdir)/cogl-attribute-buffer.h \
$(srcdir)/cogl-indices.h \
$(srcdir)/cogl-attribute.h \
@ -220,8 +220,8 @@ cogl_sources_c = \
$(srcdir)/cogl-pixel-buffer.c \
$(srcdir)/cogl-vertex-buffer-private.h \
$(srcdir)/cogl-vertex-buffer.c \
$(srcdir)/cogl-index-array-private.h \
$(srcdir)/cogl-index-array.c \
$(srcdir)/cogl-index-buffer-private.h \
$(srcdir)/cogl-index-buffer.c \
$(srcdir)/cogl-attribute-buffer-private.h \
$(srcdir)/cogl-attribute-buffer.c \
$(srcdir)/cogl-indices-private.h \

View File

@ -321,8 +321,8 @@ cogl_attribute_get_buffer (CoglAttribute *attribute)
}
void
cogl_attribute_set_array (CoglAttribute *attribute,
CoglAttributeBuffer *attribute_buffer)
cogl_attribute_set_buffer (CoglAttribute *attribute,
CoglAttributeBuffer *attribute_buffer)
{
g_return_if_fail (cogl_is_attribute (attribute));
@ -877,7 +877,7 @@ get_wire_lines (CoglAttribute *attribute,
{
CoglAttributeBuffer *attribute_buffer = cogl_attribute_get_buffer (attribute);
void *vertices;
CoglIndexArray *index_array;
CoglIndexBuffer *index_buffer;
void *indices;
CoglIndicesType indices_type;
int i;
@ -888,14 +888,14 @@ get_wire_lines (CoglAttribute *attribute,
COGL_BUFFER_ACCESS_READ, 0);
if (_indices)
{
index_array = cogl_indices_get_array (_indices);
indices = cogl_buffer_map (COGL_BUFFER (index_array),
index_buffer = cogl_indices_get_buffer (_indices);
indices = cogl_buffer_map (COGL_BUFFER (index_buffer),
COGL_BUFFER_ACCESS_READ, 0);
indices_type = cogl_indices_get_type (_indices);
}
else
{
index_array = NULL;
index_buffer = NULL;
indices = NULL;
indices_type = COGL_INDICES_TYPE_UNSIGNED_BYTE;
}
@ -985,7 +985,7 @@ get_wire_lines (CoglAttribute *attribute,
cogl_buffer_unmap (COGL_BUFFER (attribute_buffer));
if (indices != NULL)
cogl_buffer_unmap (COGL_BUFFER (index_array));
cogl_buffer_unmap (COGL_BUFFER (index_buffer));
return out;
}
@ -1188,7 +1188,7 @@ _cogl_draw_indexed_attributes_array (CoglVerticesMode mode,
CoglPipeline *source;
CoglBuffer *buffer;
guint8 *base;
size_t array_offset;
size_t buffer_offset;
size_t index_size;
GLenum indices_gl_type = 0;
@ -1198,9 +1198,9 @@ _cogl_draw_indexed_attributes_array (CoglVerticesMode mode,
source = enable_gl_state (flags, attributes, &state);
buffer = COGL_BUFFER (cogl_indices_get_array (indices));
base = _cogl_buffer_bind (buffer, COGL_BUFFER_BIND_TARGET_INDEX_ARRAY);
array_offset = cogl_indices_get_offset (indices);
buffer = COGL_BUFFER (cogl_indices_get_buffer (indices));
base = _cogl_buffer_bind (buffer, COGL_BUFFER_BIND_TARGET_INDEX_BUFFER);
buffer_offset = cogl_indices_get_offset (indices);
index_size = sizeof_index_type (cogl_indices_get_type (indices));
switch (cogl_indices_get_type (indices))
@ -1219,7 +1219,7 @@ _cogl_draw_indexed_attributes_array (CoglVerticesMode mode,
GE (glDrawElements ((GLenum)mode,
n_vertices,
indices_gl_type,
base + array_offset + index_size * first_vertex));
base + buffer_offset + index_size * first_vertex));
_cogl_buffer_unbind (buffer);

View File

@ -65,14 +65,14 @@ typedef enum _CoglBufferFlags
typedef enum {
COGL_BUFFER_USAGE_HINT_TEXTURE,
COGL_BUFFER_USAGE_HINT_ATTRIBUTE_BUFFER,
COGL_BUFFER_USAGE_HINT_INDEX_ARRAY
COGL_BUFFER_USAGE_HINT_INDEX_BUFFER
} CoglBufferUsageHint;
typedef enum {
COGL_BUFFER_BIND_TARGET_PIXEL_PACK,
COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK,
COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER,
COGL_BUFFER_BIND_TARGET_INDEX_ARRAY,
COGL_BUFFER_BIND_TARGET_INDEX_BUFFER,
COGL_BUFFER_BIND_TARGET_COUNT
} CoglBufferBindTarget;

View File

@ -130,7 +130,7 @@ convert_bind_target_to_gl_target (CoglBufferBindTarget target)
return GL_PIXEL_UNPACK_BUFFER;
case COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER:
return GL_ARRAY_BUFFER;
case COGL_BUFFER_BIND_TARGET_INDEX_ARRAY:
case COGL_BUFFER_BIND_TARGET_INDEX_BUFFER:
return GL_ELEMENT_ARRAY_BUFFER;
default:
g_return_val_if_reached (COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK);

View File

@ -25,15 +25,14 @@
* Robert Bragg <robert@linux.intel.com>
*/
#ifndef __COGL_INDEX_ARRAY_PRIVATE_H
#define __COGL_INDEX_ARRAY_PRIVATE_H
#ifndef __COGL_INDEX_BUFFER_PRIVATE_H
#define __COGL_INDEX_BUFFER_PRIVATE_H
#include "cogl-buffer-private.h"
struct _CoglIndexArray
struct _CoglIndexBuffer
{
CoglBuffer _parent;
};
#endif /* __COGL_INDEX_ARRAY_PRIVATE_H */
#endif /* __COGL_INDEX_BUFFER_PRIVATE_H */

View File

@ -33,17 +33,17 @@
#include "cogl-indices.h"
#include "cogl-indices-private.h"
static void _cogl_index_array_free (CoglIndexArray *indices);
static void _cogl_index_buffer_free (CoglIndexBuffer *indices);
COGL_BUFFER_DEFINE (IndexArray, index_array);
COGL_BUFFER_DEFINE (IndexBuffer, index_buffer);
/* XXX: Unlike the wiki design this just takes a size. A single
* indices buffer should be able to contain multiple ranges of indices
* which the wiki design doesn't currently consider. */
CoglIndexArray *
cogl_index_array_new (gsize bytes)
CoglIndexBuffer *
cogl_index_buffer_new (gsize bytes)
{
CoglIndexArray *indices = g_slice_new (CoglIndexArray);
CoglIndexBuffer *indices = g_slice_new (CoglIndexBuffer);
gboolean use_malloc;
if (!cogl_features_available (COGL_FEATURE_VBOS))
@ -55,25 +55,25 @@ cogl_index_array_new (gsize bytes)
_cogl_buffer_initialize (COGL_BUFFER (indices),
bytes,
use_malloc,
COGL_BUFFER_BIND_TARGET_INDEX_ARRAY,
COGL_BUFFER_USAGE_HINT_INDEX_ARRAY,
COGL_BUFFER_BIND_TARGET_INDEX_BUFFER,
COGL_BUFFER_USAGE_HINT_INDEX_BUFFER,
COGL_BUFFER_UPDATE_HINT_STATIC);
return _cogl_index_array_object_new (indices);
return _cogl_index_buffer_object_new (indices);
}
static void
_cogl_index_array_free (CoglIndexArray *indices)
_cogl_index_buffer_free (CoglIndexBuffer *indices)
{
/* parent's destructor */
_cogl_buffer_fini (COGL_BUFFER (indices));
g_slice_free (CoglIndexArray, indices);
g_slice_free (CoglIndexBuffer, indices);
}
gboolean
cogl_index_array_allocate (CoglIndexArray *indices,
GError *error)
cogl_index_buffer_allocate (CoglIndexBuffer *indices,
GError *error)
{
/* TODO */
return TRUE;
@ -82,43 +82,28 @@ cogl_index_array_allocate (CoglIndexArray *indices,
/* XXX: do we want a convenience function like this as an alternative
* to using cogl_buffer_set_data? The advantage of this is that we can
* track meta data such as the indices type and max_index_value for a
* range as part of the indices array. If we just leave people to use
* range as part of the indices buffer. If we just leave people to use
* cogl_buffer_set_data then we either need a way to specify the type
* and max index value at draw time or we'll want a separate way to
* declare the type and max value for a range after uploading the
* data.
*
* XXX: I think in the end it'll be that CoglIndices are to
* CoglIndexArrays as CoglAttributes are to CoglVertices. I.e
* a CoglIndexArray is a lite subclass of CoglBuffer that simply
* CoglIndexBuffers as CoglAttributes are to CoglAttributeBuffers. I.e
* a CoglIndexBuffer is a lite subclass of CoglBuffer that simply
* implies that the buffer will later be bound as indices but doesn't
* track more detailed meta data. CoglIndices build on a
* CoglIndexArray and define the type and max_index_value for some
* sub-range of a CoglIndexArray.
*
* XXX: The double plurel form that "Indices" "Array" implies could be
* a bit confusing. Also to be a bit more consistent with
* CoglAttributeBuffer vs CoglAttribute it might be best to rename so
* we have CoglIndexArray vs CoglIndices? maybe even
* CoglIndexRange :-/ ?
*
* CoglBuffer
* CoglAttributeBuffer (buffer sub-class)
* CoglAttribute (defines meta data for sub-region of buffer)
* CoglPrimitive (object encapsulating a set of attributes)
* CoglPixelBuffer (buffer sub-class)
* CoglIndexArray (buffer sub-class)
* CoglIndices (defines meta data for sub-region of array)
*
* CoglIndexBuffer and define the type and max_index_value for some
* sub-range of a CoglIndexBuffer.
*/
#if 0
void
cogl_index_array_set_data (CoglIndexArray *indices,
CoglIndicesType type,
int max_index_value,
gsize write_offset,
void *user_indices,
int n_indices)
cogl_index_buffer_set_data (CoglIndexBuffer *indices,
CoglIndicesType type,
int max_index_value,
gsize write_offset,
void *user_indices,
int n_indices)
{
GList *l;

View File

@ -28,26 +28,26 @@
#error "Only <cogl/cogl.h> can be included directly."
#endif
#ifndef __COGL_INDEX_ARRAY_H__
#define __COGL_INDEX_ARRAY_H__
#ifndef __COGL_INDEX_BUFFER_H__
#define __COGL_INDEX_BUFFER_H__
G_BEGIN_DECLS
/**
* SECTION:cogl-vertex-indices
* SECTION:cogl-index-buffer
* @short_description: Functions for creating and manipulating vertex
* indices.
*
* FIXME
*/
typedef struct _CoglIndexArray CoglIndexArray;
typedef struct _CoglIndexBuffer CoglIndexBuffer;
/**
* cogl_index_array_new:
* cogl_index_buffer_new:
* @bytes: The number of bytes to allocate for vertex attribute data.
*
* Declares a new #CoglIndexArray of @size bytes to contain vertex
* Declares a new #CoglIndexBuffer of @size bytes to contain vertex
* indices. 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().
@ -55,25 +55,25 @@ typedef struct _CoglIndexArray CoglIndexArray;
* Since: 1.4
* Stability: Unstable
*/
CoglIndexArray *
cogl_index_array_new (gsize bytes);
CoglIndexBuffer *
cogl_index_buffer_new (gsize bytes);
/**
* cogl_is_indices_array:
* cogl_is_index_buffer:
* @object: A #CoglObject
*
* Gets whether the given object references a #CoglIndexArray.
* Gets whether the given object references a #CoglIndexBuffer.
*
* Returns: %TRUE if the handle references a #CoglIndexArray,
* Returns: %TRUE if the handle references a #CoglIndexBuffer,
* %FALSE otherwise
*
* Since: 1.4
* Stability: Unstable
*/
gboolean
cogl_is_indices_array (void *object);
cogl_is_index_buffer (void *object);
G_END_DECLS
#endif /* __COGL_INDEX_ARRAY_H__ */
#endif /* __COGL_INDEX_BUFFER_H__ */

View File

@ -29,14 +29,14 @@
#define __COGL_INDICES_PRIVATE_H
#include "cogl-object-private.h"
#include "cogl-index-array-private.h"
#include "cogl-index-buffer-private.h"
#include "cogl-types.h"
struct _CoglIndices
{
CoglObject _parent;
CoglIndexArray *array;
CoglIndexBuffer *buffer;
size_t offset;
CoglIndicesType type;

View File

@ -34,7 +34,7 @@
#include "cogl-context-private.h"
#include "cogl-indices.h"
#include "cogl-indices-private.h"
#include "cogl-index-array.h"
#include "cogl-index-buffer.h"
#include <stdarg.h>
@ -58,13 +58,13 @@ sizeof_indices_type (CoglIndicesType type)
}
CoglIndices *
cogl_indices_new_for_array (CoglIndicesType type,
CoglIndexArray *array,
gsize offset)
cogl_indices_new_for_buffer (CoglIndicesType type,
CoglIndexBuffer *buffer,
gsize offset)
{
CoglIndices *indices = g_slice_new (CoglIndices);
indices->array = cogl_object_ref (array);
indices->buffer = cogl_object_ref (buffer);
indices->offset = offset;
indices->type = type;
@ -79,26 +79,26 @@ cogl_indices_new (CoglIndicesType type,
const void *indices_data,
int n_indices)
{
size_t array_bytes = sizeof_indices_type (type) * n_indices;
CoglIndexArray *array = cogl_index_array_new (array_bytes);
CoglBuffer *buffer = COGL_BUFFER (array);
size_t buffer_bytes = sizeof_indices_type (type) * n_indices;
CoglIndexBuffer *index_buffer = cogl_index_buffer_new (buffer_bytes);
CoglBuffer *buffer = COGL_BUFFER (index_buffer);
CoglIndices *indices;
cogl_buffer_set_data (buffer,
0,
indices_data,
array_bytes);
buffer_bytes);
indices = cogl_indices_new_for_array (type, array, 0);
cogl_object_unref (array);
indices = cogl_indices_new_for_buffer (type, index_buffer, 0);
cogl_object_unref (index_buffer);
return indices;
}
CoglIndexArray *
cogl_indices_get_array (CoglIndices *indices)
CoglIndexBuffer *
cogl_indices_get_buffer (CoglIndices *indices)
{
return indices->array;
return indices->buffer;
}
CoglIndicesType
@ -144,7 +144,7 @@ cogl_indices_set_offset (CoglIndices *indices,
static void
_cogl_indices_free (CoglIndices *indices)
{
cogl_object_unref (indices->array);
cogl_object_unref (indices->buffer);
g_slice_free (CoglIndices, indices);
}
@ -154,7 +154,7 @@ _cogl_indices_immutable_ref (CoglIndices *indices)
g_return_val_if_fail (cogl_is_indices (indices), NULL);
indices->immutable_ref++;
_cogl_buffer_immutable_ref (COGL_BUFFER (indices->array));
_cogl_buffer_immutable_ref (COGL_BUFFER (indices->buffer));
return indices;
}
@ -165,7 +165,7 @@ _cogl_indices_immutable_unref (CoglIndices *indices)
g_return_if_fail (indices->immutable_ref > 0);
indices->immutable_ref--;
_cogl_buffer_immutable_unref (COGL_BUFFER (indices->array));
_cogl_buffer_immutable_unref (COGL_BUFFER (indices->buffer));
}
CoglIndices *

View File

@ -31,14 +31,14 @@
#ifndef __COGL_INDICES_H__
#define __COGL_INDICES_H__
#include <cogl/cogl-index-array.h>
#include <cogl/cogl-index-buffer.h>
G_BEGIN_DECLS
/**
* SECTION:cogl-index-range
* @short_description: Fuctions for declaring a range of vertex indices
* stored in a #CoglIndexArray.
* stored in a #CoglIndexBuffer.
*
* FIXME
*/
@ -51,12 +51,12 @@ cogl_indices_new (CoglIndicesType type,
int n_indices);
CoglIndices *
cogl_indices_new_for_array (CoglIndicesType type,
CoglIndexArray *array,
gsize offset);
cogl_indices_new_for_buffer (CoglIndicesType type,
CoglIndexBuffer *buffer,
gsize offset);
CoglIndexArray *
cogl_indices_get_array (CoglIndices *indices);
CoglIndexBuffer *
cogl_indices_get_buffer (CoglIndices *indices);
CoglIndicesType
cogl_indices_get_type (CoglIndices *indices);

View File

@ -80,7 +80,7 @@ typedef struct _CoglFramebuffer CoglFramebuffer;
#include <cogl/cogl-euler.h>
#include <cogl/cogl-quaternion.h>
#include <cogl/cogl-texture-3d.h>
#include <cogl/cogl-index-array.h>
#include <cogl/cogl-index-buffer.h>
#include <cogl/cogl-attribute-buffer.h>
#include <cogl/cogl-indices.h>
#include <cogl/cogl-attribute.h>

View File

@ -60,7 +60,7 @@ IGNORE_HFILES=\
cogl-feature-private.h \
cogl-framebuffer-private.h \
cogl-gtype-private.h \
cogl-index-array-private.h \
cogl-index-buffer-private.h \
cogl-indices-private.h \
cogl-journal-private.h \
cogl-matrix-private.h \