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