mesa: add const qualifiers to vertex array helper functions
[mesa.git] / src / mesa / main / varray.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 #ifndef VARRAY_H
28 #define VARRAY_H
29
30
31 #include "glheader.h"
32 #include "bufferobj.h"
33
34 struct gl_client_array;
35 struct gl_context;
36
37
38 /**
39 * Compute the index of the last array element that can be safely accessed in
40 * a vertex array. We can really only do this when the array lives in a VBO.
41 * The array->_MaxElement field will be updated.
42 * Later in glDrawArrays/Elements/etc we can do some bounds checking.
43 */
44 static inline void
45 _mesa_update_array_max_element(struct gl_client_array *array)
46 {
47 assert(array->Enabled);
48
49 if (array->BufferObj->Name) {
50 GLsizeiptrARB offset = (GLsizeiptrARB) array->Ptr;
51 GLsizeiptrARB bufSize = (GLsizeiptrARB) array->BufferObj->Size;
52
53 if (offset < bufSize) {
54 const GLuint stride = array->StrideB ?
55 array->StrideB : array->_ElementSize;
56 array->_MaxElement = (bufSize - offset + stride
57 - array->_ElementSize) / stride;
58 }
59 else {
60 array->_MaxElement = 0;
61 }
62 }
63 else {
64 /* user-space array, no idea how big it is */
65 array->_MaxElement = 2 * 1000 * 1000 * 1000; /* just a big number */
66 }
67 }
68
69
70 /**
71 * Returns a pointer to the vertex attribute data in a client array,
72 * or the offset into the vertex buffer for an array that resides in
73 * a vertex buffer.
74 */
75 static inline const GLubyte *
76 _mesa_vertex_attrib_address(const struct gl_vertex_attrib_array *array,
77 const struct gl_vertex_buffer_binding *binding)
78 {
79 return (binding->BufferObj->Name == 0 ?
80 array->Ptr :
81 (const GLubyte *)(binding->Offset + array->RelativeOffset));
82 }
83
84 /**
85 * Sets the fields in a gl_client_array to values derived from a
86 * gl_vertex_attrib_array and a gl_vertex_buffer_binding.
87 */
88 static inline void
89 _mesa_update_client_array(struct gl_context *ctx,
90 struct gl_client_array *dst,
91 const struct gl_vertex_attrib_array *src,
92 const struct gl_vertex_buffer_binding *binding)
93 {
94 dst->Size = src->Size;
95 dst->Type = src->Type;
96 dst->Format = src->Format;
97 dst->Stride = src->Stride;
98 dst->StrideB = binding->Stride;
99 dst->Ptr = _mesa_vertex_attrib_address(src, binding);
100 dst->Enabled = src->Enabled;
101 dst->Normalized = src->Normalized;
102 dst->Integer = src->Integer;
103 dst->InstanceDivisor = binding->InstanceDivisor;
104 dst->_ElementSize = src->_ElementSize;
105 _mesa_reference_buffer_object(ctx, &dst->BufferObj, binding->BufferObj);
106 }
107
108 extern void GLAPIENTRY
109 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride,
110 const GLvoid *ptr);
111
112 extern void GLAPIENTRY
113 _mesa_UnlockArraysEXT( void );
114
115 extern void GLAPIENTRY
116 _mesa_LockArraysEXT(GLint first, GLsizei count);
117
118
119 extern void GLAPIENTRY
120 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr);
121
122
123 extern void GLAPIENTRY
124 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
125
126
127 extern void GLAPIENTRY
128 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr);
129
130
131 extern void GLAPIENTRY
132 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
133 const GLvoid *ptr);
134
135
136 extern void GLAPIENTRY
137 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr);
138
139
140 extern void GLAPIENTRY
141 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
142 GLsizei count, const GLvoid *ptr);
143
144
145 extern void GLAPIENTRY
146 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
147 const GLvoid *ptr);
148
149
150 extern void GLAPIENTRY
151 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
152 const GLvoid *ptr);
153
154
155 extern void GLAPIENTRY
156 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
157 const GLvoid *ptr);
158
159
160 extern void GLAPIENTRY
161 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
162 GLsizei count, const GLvoid *ptr);
163
164
165 extern void GLAPIENTRY
166 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr);
167
168
169 extern void GLAPIENTRY
170 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr);
171
172
173 extern void GLAPIENTRY
174 _mesa_SecondaryColorPointer(GLint size, GLenum type,
175 GLsizei stride, const GLvoid *ptr);
176
177
178 extern void GLAPIENTRY
179 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr);
180
181
182 extern void GLAPIENTRY
183 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
184 GLboolean normalized, GLsizei stride,
185 const GLvoid *pointer);
186
187 void GLAPIENTRY
188 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
189 GLsizei stride, const GLvoid *ptr);
190
191
192 extern void GLAPIENTRY
193 _mesa_EnableVertexAttribArray(GLuint index);
194
195
196 extern void GLAPIENTRY
197 _mesa_DisableVertexAttribArray(GLuint index);
198
199
200 extern void GLAPIENTRY
201 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params);
202
203
204 extern void GLAPIENTRY
205 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params);
206
207
208 extern void GLAPIENTRY
209 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params);
210
211
212 extern void GLAPIENTRY
213 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params);
214
215
216 extern void GLAPIENTRY
217 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params);
218
219
220 extern void GLAPIENTRY
221 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer);
222
223
224 extern void GLAPIENTRY
225 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer);
226
227
228 extern void GLAPIENTRY
229 _mesa_MultiDrawArrays( GLenum mode, const GLint *first,
230 const GLsizei *count, GLsizei primcount );
231
232 extern void GLAPIENTRY
233 _mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type,
234 const GLvoid **indices, GLsizei primcount );
235
236 extern void GLAPIENTRY
237 _mesa_MultiDrawElementsBaseVertex( GLenum mode,
238 const GLsizei *count, GLenum type,
239 const GLvoid **indices, GLsizei primcount,
240 const GLint *basevertex);
241
242 extern void GLAPIENTRY
243 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
244 const GLsizei * count,
245 GLsizei primcount, GLint modestride );
246
247
248 extern void GLAPIENTRY
249 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
250 GLenum type, const GLvoid * const * indices,
251 GLsizei primcount, GLint modestride );
252
253 extern void GLAPIENTRY
254 _mesa_LockArraysEXT(GLint first, GLsizei count);
255
256 extern void GLAPIENTRY
257 _mesa_UnlockArraysEXT( void );
258
259
260 extern void GLAPIENTRY
261 _mesa_DrawArrays(GLenum mode, GLint first, GLsizei count);
262
263 extern void GLAPIENTRY
264 _mesa_DrawElements(GLenum mode, GLsizei count, GLenum type,
265 const GLvoid *indices);
266
267 extern void GLAPIENTRY
268 _mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
269 GLenum type, const GLvoid *indices);
270
271 extern void GLAPIENTRY
272 _mesa_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
273 const GLvoid *indices, GLint basevertex);
274
275 extern void GLAPIENTRY
276 _mesa_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end,
277 GLsizei count, GLenum type,
278 const GLvoid *indices,
279 GLint basevertex);
280
281 extern void GLAPIENTRY
282 _mesa_DrawTransformFeedback(GLenum mode, GLuint name);
283
284 extern void GLAPIENTRY
285 _mesa_PrimitiveRestartIndex(GLuint index);
286
287
288 extern void GLAPIENTRY
289 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor);
290
291 extern unsigned
292 _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type);
293
294 extern void GLAPIENTRY
295 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
296 GLsizei stride);
297
298 extern void GLAPIENTRY
299 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
300 GLboolean normalized, GLuint relativeOffset);
301
302 extern void GLAPIENTRY
303 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
304 GLuint relativeOffset);
305
306 extern void GLAPIENTRY
307 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
308 GLuint relativeOffset);
309
310 extern void GLAPIENTRY
311 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex);
312
313 extern void GLAPIENTRY
314 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor);
315
316
317 extern void
318 _mesa_copy_client_array(struct gl_context *ctx,
319 struct gl_client_array *dst,
320 struct gl_client_array *src);
321
322 extern void
323 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
324 struct gl_vertex_attrib_array *dst,
325 const struct gl_vertex_attrib_array *src);
326
327 extern void
328 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
329 struct gl_vertex_buffer_binding *dst,
330 const struct gl_vertex_buffer_binding *src);
331
332 extern void
333 _mesa_print_arrays(struct gl_context *ctx);
334
335 extern void
336 _mesa_init_varray( struct gl_context * ctx );
337
338 extern void
339 _mesa_free_varray_data(struct gl_context *ctx);
340
341 #endif