mesa: Use location VERT_ATTRIB_GENERIC0 for vertex attribute 0
[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 static inline bool
110 _mesa_attr_zero_aliases_vertex(struct gl_context *ctx)
111 {
112 const bool is_forward_compatible_context =
113 ctx->Const.ContextFlags & GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;
114
115 /* In OpenGL 3.1 attribute 0 becomes non-magic, just like in OpenGL ES
116 * 2.0. Note that we cannot just check for API_OPENGL_COMPAT here because
117 * that will erroneously allow this usage in a 3.0 forward-compatible
118 * context too.
119 */
120 return (ctx->API == API_OPENGLES
121 || (ctx->API == API_OPENGL_COMPAT
122 && !is_forward_compatible_context));
123 }
124
125 extern void GLAPIENTRY
126 _mesa_VertexPointer(GLint size, GLenum type, GLsizei stride,
127 const GLvoid *ptr);
128
129
130 extern void GLAPIENTRY
131 _mesa_NormalPointer(GLenum type, GLsizei stride, const GLvoid *ptr);
132
133
134 extern void GLAPIENTRY
135 _mesa_ColorPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *ptr);
136
137
138 extern void GLAPIENTRY
139 _mesa_IndexPointer(GLenum type, GLsizei stride, const GLvoid *ptr);
140
141
142 extern void GLAPIENTRY
143 _mesa_TexCoordPointer(GLint size, GLenum type, GLsizei stride,
144 const GLvoid *ptr);
145
146
147 extern void GLAPIENTRY
148 _mesa_EdgeFlagPointer(GLsizei stride, const GLvoid *ptr);
149
150
151 extern void GLAPIENTRY
152 _mesa_VertexPointerEXT(GLint size, GLenum type, GLsizei stride,
153 GLsizei count, const GLvoid *ptr);
154
155
156 extern void GLAPIENTRY
157 _mesa_NormalPointerEXT(GLenum type, GLsizei stride, GLsizei count,
158 const GLvoid *ptr);
159
160
161 extern void GLAPIENTRY
162 _mesa_ColorPointerEXT(GLint size, GLenum type, GLsizei stride, GLsizei count,
163 const GLvoid *ptr);
164
165
166 extern void GLAPIENTRY
167 _mesa_IndexPointerEXT(GLenum type, GLsizei stride, GLsizei count,
168 const GLvoid *ptr);
169
170
171 extern void GLAPIENTRY
172 _mesa_TexCoordPointerEXT(GLint size, GLenum type, GLsizei stride,
173 GLsizei count, const GLvoid *ptr);
174
175
176 extern void GLAPIENTRY
177 _mesa_EdgeFlagPointerEXT(GLsizei stride, GLsizei count, const GLboolean *ptr);
178
179
180 extern void GLAPIENTRY
181 _mesa_FogCoordPointer(GLenum type, GLsizei stride, const GLvoid *ptr);
182
183
184 extern void GLAPIENTRY
185 _mesa_SecondaryColorPointer(GLint size, GLenum type,
186 GLsizei stride, const GLvoid *ptr);
187
188
189 extern void GLAPIENTRY
190 _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr);
191
192
193 extern void GLAPIENTRY
194 _mesa_VertexAttribPointer(GLuint index, GLint size, GLenum type,
195 GLboolean normalized, GLsizei stride,
196 const GLvoid *pointer);
197
198 void GLAPIENTRY
199 _mesa_VertexAttribIPointer(GLuint index, GLint size, GLenum type,
200 GLsizei stride, const GLvoid *ptr);
201
202
203 extern void GLAPIENTRY
204 _mesa_EnableVertexAttribArray(GLuint index);
205
206
207 extern void GLAPIENTRY
208 _mesa_DisableVertexAttribArray(GLuint index);
209
210
211 extern void GLAPIENTRY
212 _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params);
213
214
215 extern void GLAPIENTRY
216 _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params);
217
218
219 extern void GLAPIENTRY
220 _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params);
221
222
223 extern void GLAPIENTRY
224 _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params);
225
226
227 extern void GLAPIENTRY
228 _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params);
229
230
231 extern void GLAPIENTRY
232 _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer);
233
234
235 extern void GLAPIENTRY
236 _mesa_InterleavedArrays(GLenum format, GLsizei stride, const GLvoid *pointer);
237
238
239 extern void GLAPIENTRY
240 _mesa_MultiDrawArrays( GLenum mode, const GLint *first,
241 const GLsizei *count, GLsizei primcount );
242
243 extern void GLAPIENTRY
244 _mesa_MultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type,
245 const GLvoid **indices, GLsizei primcount );
246
247 extern void GLAPIENTRY
248 _mesa_MultiDrawElementsBaseVertex( GLenum mode,
249 const GLsizei *count, GLenum type,
250 const GLvoid **indices, GLsizei primcount,
251 const GLint *basevertex);
252
253 extern void GLAPIENTRY
254 _mesa_MultiModeDrawArraysIBM( const GLenum * mode, const GLint * first,
255 const GLsizei * count,
256 GLsizei primcount, GLint modestride );
257
258
259 extern void GLAPIENTRY
260 _mesa_MultiModeDrawElementsIBM( const GLenum * mode, const GLsizei * count,
261 GLenum type, const GLvoid * const * indices,
262 GLsizei primcount, GLint modestride );
263
264 extern void GLAPIENTRY
265 _mesa_LockArraysEXT(GLint first, GLsizei count);
266
267 extern void GLAPIENTRY
268 _mesa_UnlockArraysEXT( void );
269
270
271 extern void GLAPIENTRY
272 _mesa_DrawArrays(GLenum mode, GLint first, GLsizei count);
273
274 extern void GLAPIENTRY
275 _mesa_DrawElements(GLenum mode, GLsizei count, GLenum type,
276 const GLvoid *indices);
277
278 extern void GLAPIENTRY
279 _mesa_DrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count,
280 GLenum type, const GLvoid *indices);
281
282 extern void GLAPIENTRY
283 _mesa_DrawElementsBaseVertex(GLenum mode, GLsizei count, GLenum type,
284 const GLvoid *indices, GLint basevertex);
285
286 extern void GLAPIENTRY
287 _mesa_DrawRangeElementsBaseVertex(GLenum mode, GLuint start, GLuint end,
288 GLsizei count, GLenum type,
289 const GLvoid *indices,
290 GLint basevertex);
291
292 extern void GLAPIENTRY
293 _mesa_DrawTransformFeedback(GLenum mode, GLuint name);
294
295 extern void GLAPIENTRY
296 _mesa_PrimitiveRestartIndex(GLuint index);
297
298
299 extern void GLAPIENTRY
300 _mesa_VertexAttribDivisor(GLuint index, GLuint divisor);
301
302 extern unsigned
303 _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type);
304
305 extern void GLAPIENTRY
306 _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset,
307 GLsizei stride);
308
309 extern void GLAPIENTRY
310 _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type,
311 GLboolean normalized, GLuint relativeOffset);
312
313 extern void GLAPIENTRY
314 _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type,
315 GLuint relativeOffset);
316
317 extern void GLAPIENTRY
318 _mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type,
319 GLuint relativeOffset);
320
321 extern void GLAPIENTRY
322 _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex);
323
324 extern void GLAPIENTRY
325 _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor);
326
327
328 extern void
329 _mesa_copy_client_array(struct gl_context *ctx,
330 struct gl_client_array *dst,
331 struct gl_client_array *src);
332
333 extern void
334 _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
335 struct gl_vertex_attrib_array *dst,
336 const struct gl_vertex_attrib_array *src);
337
338 extern void
339 _mesa_copy_vertex_buffer_binding(struct gl_context *ctx,
340 struct gl_vertex_buffer_binding *dst,
341 const struct gl_vertex_buffer_binding *src);
342
343 extern void
344 _mesa_print_arrays(struct gl_context *ctx);
345
346 extern void
347 _mesa_init_varray( struct gl_context * ctx );
348
349 extern void
350 _mesa_free_varray_data(struct gl_context *ctx);
351
352 #endif