"Initial commit to Gerrit"
[profile/ivi/cogl.git] / cogl / cogl-index-buffer.c
1 /*
2  * Cogl
3  *
4  * An object oriented GL/GLES Abstraction/Utility Layer
5  *
6  * Copyright (C) 2010 Intel Corporation.
7  *
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.
12  *
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.
17  *
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/>.
21  *
22  *
23  *
24  * Authors:
25  *   Robert Bragg <robert@linux.intel.com>
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include "cogl-object-private.h"
33 #include "cogl-indices.h"
34 #include "cogl-indices-private.h"
35 #include "cogl-context-private.h"
36
37 static void _cogl_index_buffer_free (CoglIndexBuffer *indices);
38
39 COGL_BUFFER_DEFINE (IndexBuffer, index_buffer);
40
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. */
44 CoglIndexBuffer *
45 cogl_index_buffer_new (CoglContext *context, gsize bytes)
46 {
47   CoglIndexBuffer *indices = g_slice_new (CoglIndexBuffer);
48   gboolean use_malloc;
49
50   if (!(context->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
51     use_malloc = TRUE;
52   else
53     use_malloc = FALSE;
54
55   /* parent's constructor */
56   _cogl_buffer_initialize (COGL_BUFFER (indices),
57                            context,
58                            bytes,
59                            use_malloc,
60                            COGL_BUFFER_BIND_TARGET_INDEX_BUFFER,
61                            COGL_BUFFER_USAGE_HINT_INDEX_BUFFER,
62                            COGL_BUFFER_UPDATE_HINT_STATIC);
63
64   return _cogl_index_buffer_object_new (indices);
65 }
66
67 static void
68 _cogl_index_buffer_free (CoglIndexBuffer *indices)
69 {
70   /* parent's destructor */
71   _cogl_buffer_fini (COGL_BUFFER (indices));
72
73   g_slice_free (CoglIndexBuffer, indices);
74 }
75
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
83  * data.
84  *
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.
92  */
93 #if 0
94 void
95 cogl_index_buffer_set_data (CoglIndexBuffer *indices,
96                             CoglIndicesType type,
97                             int max_index_value,
98                             gsize write_offset,
99                             void *user_indices,
100                             int n_indices)
101 {
102   GList *l;
103
104   for (l = indices->ranges; l; l = l->next)
105     {
106
107     }
108   cogl_buffer_set
109 }
110 #endif
111