3b9f39a61df9b974051479e8174ed40e74635f58
[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 if (_mesa_is_bufferobj(binding->BufferObj))
80 return (const GLubyte *) (binding->Offset + array->RelativeOffset);
81 else
82 return array->Ptr;
83 }
84
85 /**
86 * Sets the fields in a gl_client_array to values derived from a
87 * gl_vertex_attrib_array and a gl_vertex_buffer_binding.
88 */
89 static inline void
90 _mesa_update_client_array(struct gl_context *ctx,
91 struct gl_client_array *dst,
92 const struct gl_vertex_attrib_array *src,
93 const struct gl_vertex_buffer_binding *binding)
94 {
95 dst->Size = src->Size;
96 dst->Type = src->Type;
97 dst->Format = src->Format;
98 dst->Stride = src->Stride;
99 dst->StrideB = binding->Stride;
100 dst->Ptr = _mesa_vertex_attrib_address(src, binding);
101 dst->Enabled = src->Enabled;
102 dst->Normalized = src->Normalized;
103 dst->Integer = src->Integer;
104 dst->InstanceDivisor = binding->InstanceDivisor;
105 dst->_ElementSize = src->_ElementSize;
106 _mesa_reference_buffer_object(ctx, &dst->BufferObj, binding->BufferObj);
107 }
108
109 extern void GLAPIENTRY
110 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride,
111 const GLvoid *ptr);
112
113 extern void GLAPIENTRY
114 _mesa_UnlockArraysEXT( void );
115
116 extern void GLAPIENTRY
117 _mesa_LockArraysEXT(GLint first, GLsizei count);
118
119
120 extern void GLAPIENTRY
121 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr);
122
123
124 extern void GLAPIENTRY
125 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
126
127
128 extern void GLAPIENTRY
129 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr);
130
131
132 extern void GLAPIENTRY
133 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
134 const GLvoid *ptr);
135
136
137 extern void GLAPIENTRY
138 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr);
139
140
141 extern void GLAPIENTRY
142 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
143 GLsizei count, const GLvoid *ptr);
144
145
146 extern void GLAPIENTRY
147 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
148 const GLvoid *ptr);
149
150
151 extern void GLAPIENTRY
152 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
153 const GLvoid *ptr);
154
155
156 extern void GLAPIENTRY
157 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
158 const GLvoid *ptr);
159
160
161 extern void GLAPIENTRY
162 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
163 GLsizei count, const GLvoid *ptr);
164
165
166 extern void GLAPIENTRY
167 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr);
168
169
170 extern void GLAPIENTRY
171 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr);
172
173
174 extern void GLAPIENTRY
175 _mesa_SecondaryColorPointer(GLint size, GLenum type,
176 GLsizei stride, const GLvoid *ptr);
177
178
179 extern void GLAPIENTRY
180 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr);
181
182
183 extern void GLAPIENTRY
184 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
185 GLboolean normalized, GLsizei stride,
186 const GLvoid *pointer);
187
188 void GLAPIENTRY
189 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
190 GLsizei stride, const GLvoid *ptr);
191
192
193 extern void GLAPIENTRY
194 _mesa_EnableVertexAttribArray(GLuint index);
195
196
197 extern void GLAPIENTRY
198 _mesa_DisableVertexAttribArray(GLuint index);
199
200
201 extern void GLAPIENTRY
202 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params);
203
204
205 extern void GLAPIENTRY
206 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params);
207
208
209 extern void GLAPIENTRY
210 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params);
211
212
213 extern void GLAPIENTRY
214 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params);
215
216
217 extern void GLAPIENTRY
218 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params);
219
220
221 extern void GLAPIENTRY
222 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer);
223
224
225 extern void GLAPIENTRY
226 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer);
227
228
229 extern void GLAPIENTRY
230 _mesa_MultiDrawArrays( GLenum mode, const GLint *first,
231 const GLsizei *count, GLsizei primcount );
232
233 extern void GLAPIENTRY
234 _mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type,
235 const GLvoid **indices, GLsizei primcount );
236
237 extern void GLAPIENTRY
238 _mesa_MultiDrawElementsBaseVertex( GLenum mode,
239 const GLsizei *count, GLenum type,
240 const GLvoid **indices, GLsizei primcount,
241 const GLint *basevertex);
242
243 extern void GLAPIENTRY
244 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
245 const GLsizei * count,
246 GLsizei primcount, GLint modestride );
247
248
249 extern void GLAPIENTRY
250 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
251 GLenum type, const GLvoid * const * indices,
252 GLsizei primcount, GLint modestride );
253
254 extern void GLAPIENTRY
255 _mesa_LockArraysEXT(GLint first, GLsizei count);
256
257 extern void GLAPIENTRY
258 _mesa_UnlockArraysEXT( void );
259
260
261 extern void GLAPIENTRY
262 _mesa_DrawArrays(GLenum mode, GLint first, GLsizei count);
263
264 extern void GLAPIENTRY
265 _mesa_DrawElements(GLenum mode, GLsizei count, GLenum type,
266 const GLvoid *indices);
267
268 extern void GLAPIENTRY
269 _mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
270 GLenum type, const GLvoid *indices);
271
272 extern void GLAPIENTRY
273 _mesa_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
274 const GLvoid *indices, GLint basevertex);
275
276 extern void GLAPIENTRY
277 _mesa_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end,
278 GLsizei count, GLenum type,
279 const GLvoid *indices,
280 GLint basevertex);
281
282 extern void GLAPIENTRY
283 _mesa_DrawTransformFeedback(GLenum mode, GLuint name);
284
285 extern void GLAPIENTRY
286 _mesa_PrimitiveRestartIndex(GLuint index);
287
288
289 extern void GLAPIENTRY
290 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor);
291
292 extern unsigned
293 _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type);
294
295 extern void GLAPIENTRY
296 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
297 GLsizei stride);
298
299 extern void GLAPIENTRY
300 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
301 GLboolean normalized, GLuint relativeOffset);
302
303 extern void GLAPIENTRY
304 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
305 GLuint relativeOffset);
306
307 extern void GLAPIENTRY
308 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
309 GLuint relativeOffset);
310
311 extern void GLAPIENTRY
312 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex);
313
314 extern void GLAPIENTRY
315 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor);
316
317
318 extern void
319 _mesa_copy_client_array(struct gl_context *ctx,
320 struct gl_client_array *dst,
321 struct gl_client_array *src);
322
323 extern void
324 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
325 struct gl_vertex_attrib_array *dst,
326 const struct gl_vertex_attrib_array *src);
327
328 extern void
329 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
330 struct gl_vertex_buffer_binding *dst,
331 const struct gl_vertex_buffer_binding *src);
332
333 extern void
334 _mesa_print_arrays(struct gl_context *ctx);
335
336 extern void
337 _mesa_init_varray( struct gl_context * ctx );
338
339 extern void
340 _mesa_free_varray_data(struct gl_context *ctx);
341
342 #endif