util: rename PIPE_ARCH_*_ENDIAN to UTIL_ARCH_*_ENDIAN
[mesa.git] / src / mesa / main / arrayobj.h
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
5 * (C) Copyright IBM Corporation 2006
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27 #ifndef ARRAYOBJ_H
28 #define ARRAYOBJ_H
29
30 #include "glheader.h"
31 #include "mtypes.h"
32 #include "glformats.h"
33 #include "vbo/vbo.h"
34
35 struct gl_context;
36
37 /**
38 * \file arrayobj.h
39 * Functions for the GL_ARB_vertex_array_object extension.
40 *
41 * \author Ian Romanick <idr@us.ibm.com>
42 * \author Brian Paul
43 */
44
45 /*
46 * Internal functions
47 */
48
49 extern struct gl_vertex_array_object *
50 _mesa_lookup_vao(struct gl_context *ctx, GLuint id);
51
52 extern struct gl_vertex_array_object *
53 _mesa_lookup_vao_err(struct gl_context *ctx, GLuint id,
54 bool is_ext_dsa, const char *caller);
55
56 extern struct gl_vertex_array_object *
57 _mesa_new_vao(struct gl_context *ctx, GLuint name);
58
59 extern void
60 _mesa_delete_vao(struct gl_context *ctx, struct gl_vertex_array_object *obj);
61
62 extern void
63 _mesa_reference_vao_(struct gl_context *ctx,
64 struct gl_vertex_array_object **ptr,
65 struct gl_vertex_array_object *vao);
66
67 static inline void
68 _mesa_reference_vao(struct gl_context *ctx,
69 struct gl_vertex_array_object **ptr,
70 struct gl_vertex_array_object *vao)
71 {
72 if (*ptr != vao)
73 _mesa_reference_vao_(ctx, ptr, vao);
74 }
75
76
77 extern void
78 _mesa_initialize_vao(struct gl_context *ctx,
79 struct gl_vertex_array_object *obj, GLuint name);
80
81
82 extern void
83 _mesa_update_vao_derived_arrays(struct gl_context *ctx,
84 struct gl_vertex_array_object *vao);
85
86
87 /**
88 * Mark the vao as shared and immutable, do remaining updates.
89 */
90 extern void
91 _mesa_set_vao_immutable(struct gl_context *ctx,
92 struct gl_vertex_array_object *vao);
93
94
95 /* Returns true if all varying arrays reside in vbos */
96 extern bool
97 _mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao);
98
99 /* Returns true if all vbos are unmapped */
100 extern bool
101 _mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao);
102
103
104 extern void
105 _mesa_vao_map_arrays(struct gl_context *ctx, struct gl_vertex_array_object *vao,
106 GLbitfield access);
107
108 extern void
109 _mesa_vao_map(struct gl_context *ctx, struct gl_vertex_array_object *vao,
110 GLbitfield access);
111
112
113 extern void
114 _mesa_vao_unmap_arrays(struct gl_context *ctx,
115 struct gl_vertex_array_object *vao);
116
117 extern void
118 _mesa_vao_unmap(struct gl_context *ctx,
119 struct gl_vertex_array_object *vao);
120
121
122 /**
123 * Array to apply the position/generic0 aliasing map to
124 * an attribute value used in vertex processing inputs to an attribute
125 * as they appear in the vao.
126 */
127 extern const GLubyte
128 _mesa_vao_attribute_map[ATTRIBUTE_MAP_MODE_MAX][VERT_ATTRIB_MAX];
129
130
131 /**
132 * Apply the position/generic0 aliasing map to a bitfield from the vao.
133 * Use for example to convert gl_vertex_array_object::Enabled
134 * or gl_vertex_buffer_binding::_VertexBinding from the vao numbering to
135 * the numbering used with vertex processing inputs.
136 */
137 static inline GLbitfield
138 _mesa_vao_enable_to_vp_inputs(gl_attribute_map_mode mode, GLbitfield enabled)
139 {
140 switch (mode) {
141 case ATTRIBUTE_MAP_MODE_IDENTITY:
142 return enabled;
143 case ATTRIBUTE_MAP_MODE_POSITION:
144 /* Copy VERT_ATTRIB_POS enable bit into GENERIC0 position */
145 return (enabled & ~VERT_BIT_GENERIC0)
146 | ((enabled & VERT_BIT_POS) << VERT_ATTRIB_GENERIC0);
147 case ATTRIBUTE_MAP_MODE_GENERIC0:
148 /* Copy VERT_ATTRIB_GENERIC0 enable bit into POS position */
149 return (enabled & ~VERT_BIT_POS)
150 | ((enabled & VERT_BIT_GENERIC0) >> VERT_ATTRIB_GENERIC0);
151 default:
152 return 0;
153 }
154 }
155
156
157 /**
158 * Return the vp_inputs enabled bitmask after application of
159 * the position/generic0 aliasing map.
160 */
161 static inline GLbitfield
162 _mesa_get_vao_vp_inputs(const struct gl_vertex_array_object *vao)
163 {
164 const gl_attribute_map_mode mode = vao->_AttributeMapMode;
165 return _mesa_vao_enable_to_vp_inputs(mode, vao->Enabled);
166 }
167
168
169 /**
170 * Helper functions for consuming backends to walk the
171 * ctx->Array._DrawVAO for driver side array setup.
172 * Note that mesa provides preprocessed minimal binding information
173 * in the VAO. See _mesa_update_vao_derived_arrays for documentation.
174 */
175
176 /**
177 * Return enabled vertex attribute bits for draw.
178 */
179 static inline GLbitfield
180 _mesa_draw_array_bits(const struct gl_context *ctx)
181 {
182 return ctx->Array._DrawVAOEnabledAttribs;
183 }
184
185
186 /**
187 * Return enabled buffer object vertex attribute bits for draw.
188 *
189 * Needs the a fully updated VAO ready for draw.
190 */
191 static inline GLbitfield
192 _mesa_draw_vbo_array_bits(const struct gl_context *ctx)
193 {
194 const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO;
195 assert(vao->NewArrays == 0);
196 return vao->_EffEnabledVBO & ctx->Array._DrawVAOEnabledAttribs;
197 }
198
199
200 /**
201 * Return enabled user space vertex attribute bits for draw.
202 *
203 * Needs the a fully updated VAO ready for draw.
204 */
205 static inline GLbitfield
206 _mesa_draw_user_array_bits(const struct gl_context *ctx)
207 {
208 const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO;
209 assert(vao->NewArrays == 0);
210 return ~vao->_EffEnabledVBO & ctx->Array._DrawVAOEnabledAttribs;
211 }
212
213
214 /**
215 * Return enabled current values attribute bits for draw.
216 */
217 static inline GLbitfield
218 _mesa_draw_current_bits(const struct gl_context *ctx)
219 {
220 return ~ctx->Array._DrawVAOEnabledAttribs & VERT_BIT_ALL;
221 }
222
223
224 /**
225 * Return vertex buffer binding provided the attribute struct.
226 *
227 * Needs the a fully updated VAO ready for draw.
228 */
229 static inline const struct gl_vertex_buffer_binding*
230 _mesa_draw_buffer_binding_from_attrib(const struct gl_vertex_array_object *vao,
231 const struct gl_array_attributes *attrib)
232 {
233 assert(vao->NewArrays == 0);
234 return &vao->BufferBinding[attrib->_EffBufferBindingIndex];
235 }
236
237
238 /**
239 * Return vertex array attribute provided the attribute number.
240 */
241 static inline const struct gl_array_attributes*
242 _mesa_draw_array_attrib(const struct gl_vertex_array_object *vao,
243 gl_vert_attrib attr)
244 {
245 assert(vao->NewArrays == 0);
246 const gl_attribute_map_mode map_mode = vao->_AttributeMapMode;
247 return &vao->VertexAttrib[_mesa_vao_attribute_map[map_mode][attr]];
248 }
249
250
251 /**
252 * Return vertex buffer binding provided an attribute number.
253 */
254 static inline const struct gl_vertex_buffer_binding*
255 _mesa_draw_buffer_binding(const struct gl_vertex_array_object *vao,
256 gl_vert_attrib attr)
257 {
258 const struct gl_array_attributes *const attrib
259 = _mesa_draw_array_attrib(vao, attr);
260 return _mesa_draw_buffer_binding_from_attrib(vao, attrib);
261 }
262
263
264 /**
265 * Return vertex attribute bits bound at the provided binding.
266 *
267 * Needs the a fully updated VAO ready for draw.
268 */
269 static inline GLbitfield
270 _mesa_draw_bound_attrib_bits(const struct gl_vertex_buffer_binding *binding)
271 {
272 return binding->_EffBoundArrays;
273 }
274
275
276 /**
277 * Return the vertex offset bound at the provided binding.
278 *
279 * Needs the a fully updated VAO ready for draw.
280 */
281 static inline GLintptr
282 _mesa_draw_binding_offset(const struct gl_vertex_buffer_binding *binding)
283 {
284 return binding->_EffOffset;
285 }
286
287
288 /**
289 * Return the relative offset of the provided attrib.
290 *
291 * Needs the a fully updated VAO ready for draw.
292 */
293 static inline GLushort
294 _mesa_draw_attributes_relative_offset(const struct gl_array_attributes *attrib)
295 {
296 return attrib->_EffRelativeOffset;
297 }
298
299
300 /**
301 * Return a current value vertex array attribute provided the attribute number.
302 */
303 static inline const struct gl_array_attributes*
304 _mesa_draw_current_attrib(const struct gl_context *ctx, gl_vert_attrib attr)
305 {
306 return _vbo_current_attrib(ctx, attr);
307 }
308
309
310 /**
311 * Return true if we have the VERT_ATTRIB_EDGEFLAG array enabled.
312 */
313 static inline bool
314 _mesa_draw_edge_flag_array_enabled(const struct gl_context *ctx)
315 {
316 return ctx->Array._DrawVAOEnabledAttribs & VERT_BIT_EDGEFLAG;
317 }
318
319
320 /**
321 * Return the attrib for the given attribute.
322 */
323 static inline const struct gl_array_attributes*
324 _mesa_draw_attrib(const struct gl_context *ctx, gl_vert_attrib attr)
325 {
326 if (ctx->Array._DrawVAOEnabledAttribs & VERT_BIT(attr)) {
327 const struct gl_vertex_array_object *vao = ctx->Array._DrawVAO;
328 return _mesa_draw_array_attrib(vao, attr);
329 } else {
330 return _vbo_current_attrib(ctx, attr);
331 }
332 }
333
334
335 /**
336 * Return the attrib, binding pair for the given attribute.
337 */
338 static inline void
339 _mesa_draw_attrib_and_binding(const struct gl_context *ctx, gl_vert_attrib attr,
340 const struct gl_array_attributes **attrib,
341 const struct gl_vertex_buffer_binding **binding)
342 {
343 if (ctx->Array._DrawVAOEnabledAttribs & VERT_BIT(attr)) {
344 const struct gl_vertex_array_object *vao = ctx->Array._DrawVAO;
345 *attrib = _mesa_draw_array_attrib(vao, attr);
346 *binding = _mesa_draw_buffer_binding_from_attrib(vao, *attrib);
347 } else {
348 *attrib = _vbo_current_attrib(ctx, attr);
349 *binding = _vbo_current_binding(ctx);
350 }
351 }
352
353
354 /*
355 * API functions
356 */
357
358
359 void GLAPIENTRY
360 _mesa_BindVertexArray_no_error(GLuint id);
361
362 void GLAPIENTRY _mesa_BindVertexArray( GLuint id );
363
364 void GLAPIENTRY
365 _mesa_DeleteVertexArrays_no_error(GLsizei n, const GLuint *ids);
366
367 void GLAPIENTRY _mesa_DeleteVertexArrays(GLsizei n, const GLuint *ids);
368
369 void GLAPIENTRY
370 _mesa_GenVertexArrays_no_error(GLsizei n, GLuint *arrays);
371
372 void GLAPIENTRY _mesa_GenVertexArrays(GLsizei n, GLuint *arrays);
373
374 void GLAPIENTRY
375 _mesa_CreateVertexArrays_no_error(GLsizei n, GLuint *arrays);
376
377 void GLAPIENTRY _mesa_CreateVertexArrays(GLsizei n, GLuint *arrays);
378
379 GLboolean GLAPIENTRY _mesa_IsVertexArray( GLuint id );
380
381 void GLAPIENTRY
382 _mesa_VertexArrayElementBuffer_no_error(GLuint vaobj, GLuint buffer);
383
384 void GLAPIENTRY _mesa_VertexArrayElementBuffer(GLuint vaobj, GLuint buffer);
385
386 void GLAPIENTRY _mesa_GetVertexArrayiv(GLuint vaobj, GLenum pname, GLint *param);
387
388 #endif /* ARRAYOBJ_H */