4 * An object oriented GL/GLES Abstraction/Utility Layer
6 * Copyright (C) 2010 Intel Corporation.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library. If not, see
20 * <http://www.gnu.org/licenses/>.
25 * Robert Bragg <robert@linux.intel.com>
32 #include "cogl-object-private.h"
33 #include "cogl-indices.h"
34 #include "cogl-indices-private.h"
35 #include "cogl-context-private.h"
37 static void _cogl_index_buffer_free (CoglIndexBuffer *indices);
39 COGL_BUFFER_DEFINE (IndexBuffer, index_buffer);
41 /* XXX: Unlike the wiki design this just takes a size. A single
42 * indices buffer should be able to contain multiple ranges of indices
43 * which the wiki design doesn't currently consider. */
45 cogl_index_buffer_new (CoglContext *context, gsize bytes)
47 CoglIndexBuffer *indices = g_slice_new (CoglIndexBuffer);
50 if (!(context->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
55 /* parent's constructor */
56 _cogl_buffer_initialize (COGL_BUFFER (indices),
60 COGL_BUFFER_BIND_TARGET_INDEX_BUFFER,
61 COGL_BUFFER_USAGE_HINT_INDEX_BUFFER,
62 COGL_BUFFER_UPDATE_HINT_STATIC);
64 return _cogl_index_buffer_object_new (indices);
68 _cogl_index_buffer_free (CoglIndexBuffer *indices)
70 /* parent's destructor */
71 _cogl_buffer_fini (COGL_BUFFER (indices));
73 g_slice_free (CoglIndexBuffer, indices);
76 /* XXX: do we want a convenience function like this as an alternative
77 * to using cogl_buffer_set_data? The advantage of this is that we can
78 * track meta data such as the indices type and max_index_value for a
79 * range as part of the indices buffer. If we just leave people to use
80 * cogl_buffer_set_data then we either need a way to specify the type
81 * and max index value at draw time or we'll want a separate way to
82 * declare the type and max value for a range after uploading the
85 * XXX: I think in the end it'll be that CoglIndices are to
86 * CoglIndexBuffers as CoglAttributes are to CoglAttributeBuffers. I.e
87 * a CoglIndexBuffer is a lite subclass of CoglBuffer that simply
88 * implies that the buffer will later be bound as indices but doesn't
89 * track more detailed meta data. CoglIndices build on a
90 * CoglIndexBuffer and define the type and max_index_value for some
91 * sub-range of a CoglIndexBuffer.
95 cogl_index_buffer_set_data (CoglIndexBuffer *indices,
104 for (l = indices->ranges; l; l = l->next)