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 License
19 * along with this library. If not, see <http://www.gnu.org/licenses/>.
24 * Robert Bragg <robert@linux.intel.com>
27 #if !defined(__COGL_H_INSIDE__) && !defined(CLUTTER_COMPILATION)
28 #error "Only <cogl/cogl.h> can be included directly."
31 #ifndef __COGL_INDICES_H__
32 #define __COGL_INDICES_H__
34 /* We forward declare the CoglIndices type here to avoid some circular
35 * dependency issues with the following headers.
37 typedef struct _CoglIndices CoglIndices;
39 #include <cogl/cogl-index-buffer.h>
44 * SECTION:cogl-index-range
45 * @short_description: Fuctions for declaring a range of vertex indices
46 * stored in a #CoglIndexBuffer.
48 * Indices allow you to avoid duplicating vertices in your vertex data
49 * by virtualizing your data and instead providing a sequence of index
50 * values that tell the GPU which data should be used for each vertex.
52 * If the GPU is given a squence of indices it doesn't simply walk
53 * through each vertex of your data in order it will instead walk
54 * through the indices which can provide random access to the
57 * Since it's very common to have duplicate vertices when describing a
58 * shape as a list of triangles it can often be a significant space
59 * saving to describe geometry using indices. Reducing the size of
60 * your models can make it cheaper to map them into the GPU by
61 * reducing the demand on memory bandwidth and may help to make better
62 * use of your GPUs internal vertex caching.
64 * For example, to describe a quadrilateral as 2 triangles for the GPU
65 * you could either provide data with 6 vertices or instead with
66 * indices you can provide vertex data for just 4 vertices and an
67 * index buffer that specfies the 6 vertices by indexing the shared
68 * vertices multiple times.
71 * CoglVertex2f quad_vertices[] = {
72 * {x0, y0}, //0 = top left
73 * {x1, y1}, //1 = bottom left
74 * {x2, y2}, //2 = bottom right
75 * {x3, y3}, //3 = top right
77 * //tell the gpu how to interpret the quad as 2 triangles...
78 * unsigned char indices[] = {0, 1, 2, 0, 2, 3};
81 * Even in the above illustration we see a saving of 10bytes for one
82 * quad compared to having data for 6 vertices and no indices but if
83 * you need to draw 100s or 1000s of quads then its really quite
86 * Something else to consider is that often indices can be defined
87 * once and remain static while the vertex data may change for
88 * animations perhaps. That means you may be able to ignore the
89 * negligable cost of mapping your indices into the GPU if they don't
92 * The above illustration is actually a good example of static indices
93 * because it's really common that developers have quad mesh data that
94 * they need to display and we know exactly what that indices array
95 * needs to look like depending on the number of quads that need to be
96 * drawn. It doesn't matter how the quads might be animated and
97 * changed the indices will remain the same. Cogl even has a utility
98 * (cogl_get_rectangle_indices()) to get access to re-useable indices
99 * for drawing quads as above.
103 cogl_indices_new (CoglContext *context,
104 CoglIndicesType type,
105 const void *indices_data,
109 cogl_indices_new_for_buffer (CoglIndicesType type,
110 CoglIndexBuffer *buffer,
114 cogl_indices_get_buffer (CoglIndices *indices);
117 cogl_indices_get_type (CoglIndices *indices);
120 cogl_indices_get_offset (CoglIndices *indices);
123 cogl_indices_set_offset (CoglIndices *indices,
127 cogl_get_rectangle_indices (CoglContext *context, int n_rectangles);
131 * @object: A #CoglObject pointer
133 * Gets whether the given object references a #CoglIndices.
135 * Return value: %TRUE if the object references a #CoglIndices
136 * and %FALSE otherwise.
138 * Stability: unstable
141 cogl_is_indices (void *object);
145 #endif /* __COGL_INDICES_H__ */