mesa: add ASTC 2D LDR decoder
[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, const char *caller);
54
55 extern struct gl_vertex_array_object *
56 _mesa_new_vao(struct gl_context *ctx, GLuint name);
57
58 extern void
59 _mesa_delete_vao(struct gl_context *ctx, struct gl_vertex_array_object *obj);
60
61 extern void
62 _mesa_reference_vao_(struct gl_context *ctx,
63 struct gl_vertex_array_object **ptr,
64 struct gl_vertex_array_object *vao);
65
66 static inline void
67 _mesa_reference_vao(struct gl_context *ctx,
68 struct gl_vertex_array_object **ptr,
69 struct gl_vertex_array_object *vao)
70 {
71 if (*ptr != vao)
72 _mesa_reference_vao_(ctx, ptr, vao);
73 }
74
75
76 extern void
77 _mesa_initialize_vao(struct gl_context *ctx,
78 struct gl_vertex_array_object *obj, GLuint name);
79
80
81 extern void
82 _mesa_update_vao_derived_arrays(struct gl_context *ctx,
83 struct gl_vertex_array_object *vao);
84
85
86 /**
87 * Mark the vao as shared and immutable, do remaining updates.
88 */
89 extern void
90 _mesa_set_vao_immutable(struct gl_context *ctx,
91 struct gl_vertex_array_object *vao);
92
93
94 /* Returns true if all varying arrays reside in vbos */
95 extern bool
96 _mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao);
97
98 /* Returns true if all vbos are unmapped */
99 extern bool
100 _mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao);
101
102
103 /**
104 * Array to apply the position/generic0 aliasing map to
105 * an attribute value used in vertex processing inputs to an attribute
106 * as they appear in the vao.
107 */
108 extern const GLubyte
109 _mesa_vao_attribute_map[ATTRIBUTE_MAP_MODE_MAX][VERT_ATTRIB_MAX];
110
111
112 /**
113 * Apply the position/generic0 aliasing map to a bitfield from the vao.
114 * Use for example to convert gl_vertex_array_object::_Enabled
115 * or gl_vertex_buffer_binding::_VertexBinding from the vao numbering to
116 * the numbering used with vertex processing inputs.
117 */
118 static inline GLbitfield
119 _mesa_vao_enable_to_vp_inputs(gl_attribute_map_mode mode, GLbitfield enabled)
120 {
121 switch (mode) {
122 case ATTRIBUTE_MAP_MODE_IDENTITY:
123 return enabled;
124 case ATTRIBUTE_MAP_MODE_POSITION:
125 /* Copy VERT_ATTRIB_POS enable bit into GENERIC0 position */
126 return (enabled & ~VERT_BIT_GENERIC0)
127 | ((enabled & VERT_BIT_POS) << VERT_ATTRIB_GENERIC0);
128 case ATTRIBUTE_MAP_MODE_GENERIC0:
129 /* Copy VERT_ATTRIB_GENERIC0 enable bit into POS position */
130 return (enabled & ~VERT_BIT_POS)
131 | ((enabled & VERT_BIT_GENERIC0) >> VERT_ATTRIB_GENERIC0);
132 default:
133 return 0;
134 }
135 }
136
137
138 /**
139 * Return the vp_inputs enabled bitmask after application of
140 * the position/generic0 aliasing map.
141 */
142 static inline GLbitfield
143 _mesa_get_vao_vp_inputs(const struct gl_vertex_array_object *vao)
144 {
145 const gl_attribute_map_mode mode = vao->_AttributeMapMode;
146 return _mesa_vao_enable_to_vp_inputs(mode, vao->_Enabled);
147 }
148
149
150 /**
151 * Helper functions for consuming backends to walk the
152 * ctx->Array._DrawVAO for driver side array setup.
153 * Note that mesa provides preprocessed minimal binding information
154 * in the VAO. See _mesa_update_vao_derived_arrays for documentation.
155 */
156
157 /**
158 * Return enabled vertex attribute bits for draw.
159 */
160 static inline GLbitfield
161 _mesa_draw_array_bits(const struct gl_context *ctx)
162 {
163 return ctx->Array._DrawVAOEnabledAttribs;
164 }
165
166
167 /**
168 * Return enabled buffer object vertex attribute bits for draw.
169 *
170 * Needs the a fully updated VAO ready for draw.
171 */
172 static inline GLbitfield
173 _mesa_draw_vbo_array_bits(const struct gl_context *ctx)
174 {
175 const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO;
176 assert(vao->NewArrays == 0);
177 return vao->_EffEnabledVBO & ctx->Array._DrawVAOEnabledAttribs;
178 }
179
180
181 /**
182 * Return enabled user space vertex attribute bits for draw.
183 *
184 * Needs the a fully updated VAO ready for draw.
185 */
186 static inline GLbitfield
187 _mesa_draw_user_array_bits(const struct gl_context *ctx)
188 {
189 const struct gl_vertex_array_object *const vao = ctx->Array._DrawVAO;
190 assert(vao->NewArrays == 0);
191 return ~vao->_EffEnabledVBO & ctx->Array._DrawVAOEnabledAttribs;
192 }
193
194
195 /**
196 * Return enabled current values attribute bits for draw.
197 */
198 static inline GLbitfield
199 _mesa_draw_current_bits(const struct gl_context *ctx)
200 {
201 return ~ctx->Array._DrawVAOEnabledAttribs & VERT_BIT_ALL;
202 }
203
204
205 /**
206 * Return vertex buffer binding provided the attribute struct.
207 *
208 * Needs the a fully updated VAO ready for draw.
209 */
210 static inline const struct gl_vertex_buffer_binding*
211 _mesa_draw_buffer_binding_from_attrib(const struct gl_vertex_array_object *vao,
212 const struct gl_array_attributes *attrib)
213 {
214 assert(vao->NewArrays == 0);
215 return &vao->BufferBinding[attrib->_EffBufferBindingIndex];
216 }
217
218
219 /**
220 * Return vertex array attribute provided the attribute number.
221 */
222 static inline const struct gl_array_attributes*
223 _mesa_draw_array_attrib(const struct gl_vertex_array_object *vao,
224 gl_vert_attrib attr)
225 {
226 assert(vao->NewArrays == 0);
227 const gl_attribute_map_mode map_mode = vao->_AttributeMapMode;
228 return &vao->VertexAttrib[_mesa_vao_attribute_map[map_mode][attr]];
229 }
230
231
232 /**
233 * Return vertex buffer binding provided an attribute number.
234 */
235 static inline const struct gl_vertex_buffer_binding*
236 _mesa_draw_buffer_binding(const struct gl_vertex_array_object *vao,
237 gl_vert_attrib attr)
238 {
239 const struct gl_array_attributes *const attrib
240 = _mesa_draw_array_attrib(vao, attr);
241 return _mesa_draw_buffer_binding_from_attrib(vao, attrib);
242 }
243
244
245 /**
246 * Return vertex attribute bits bound at the provided binding.
247 *
248 * Needs the a fully updated VAO ready for draw.
249 */
250 static inline GLbitfield
251 _mesa_draw_bound_attrib_bits(const struct gl_vertex_buffer_binding *binding)
252 {
253 return binding->_EffBoundArrays;
254 }
255
256
257 /**
258 * Return the vertex offset bound at the provided binding.
259 *
260 * Needs the a fully updated VAO ready for draw.
261 */
262 static inline GLintptr
263 _mesa_draw_binding_offset(const struct gl_vertex_buffer_binding *binding)
264 {
265 return binding->_EffOffset;
266 }
267
268
269 /**
270 * Return the relative offset of the provided attrib.
271 *
272 * Needs the a fully updated VAO ready for draw.
273 */
274 static inline GLushort
275 _mesa_draw_attributes_relative_offset(const struct gl_array_attributes *attrib)
276 {
277 return attrib->_EffRelativeOffset;
278 }
279
280
281 /**
282 * Return a current value vertex array attribute provided the attribute number.
283 */
284 static inline const struct gl_array_attributes*
285 _mesa_draw_current_attrib(const struct gl_context *ctx, gl_vert_attrib attr)
286 {
287 return _vbo_current_attrib(ctx, attr);
288 }
289
290
291 /**
292 * Return true if we have the VERT_ATTRIB_EDGEFLAG array enabled.
293 */
294 static inline bool
295 _mesa_draw_edge_flag_array_enabled(const struct gl_context *ctx)
296 {
297 return ctx->Array._DrawVAOEnabledAttribs & VERT_BIT_EDGEFLAG;
298 }
299
300
301 /**
302 * Return the attrib for the given attribute.
303 */
304 static inline const struct gl_array_attributes*
305 _mesa_draw_attrib(const struct gl_context *ctx, gl_vert_attrib attr)
306 {
307 if (ctx->Array._DrawVAOEnabledAttribs & VERT_BIT(attr)) {
308 const struct gl_vertex_array_object *vao = ctx->Array._DrawVAO;
309 return _mesa_draw_array_attrib(vao, attr);
310 } else {
311 return _vbo_current_attrib(ctx, attr);
312 }
313 }
314
315
316 /**
317 * Return the attrib, binding pair for the given attribute.
318 */
319 static inline void
320 _mesa_draw_attrib_and_binding(const struct gl_context *ctx, gl_vert_attrib attr,
321 const struct gl_array_attributes **attrib,
322 const struct gl_vertex_buffer_binding **binding)
323 {
324 if (ctx->Array._DrawVAOEnabledAttribs & VERT_BIT(attr)) {
325 const struct gl_vertex_array_object *vao = ctx->Array._DrawVAO;
326 *attrib = _mesa_draw_array_attrib(vao, attr);
327 *binding = _mesa_draw_buffer_binding_from_attrib(vao, *attrib);
328 } else {
329 *attrib = _vbo_current_attrib(ctx, attr);
330 *binding = _vbo_current_binding(ctx);
331 }
332 }
333
334
335 /*
336 * API functions
337 */
338
339
340 void GLAPIENTRY
341 _mesa_BindVertexArray_no_error(GLuint id);
342
343 void GLAPIENTRY _mesa_BindVertexArray( GLuint id );
344
345 void GLAPIENTRY
346 _mesa_DeleteVertexArrays_no_error(GLsizei n, const GLuint *ids);
347
348 void GLAPIENTRY _mesa_DeleteVertexArrays(GLsizei n, const GLuint *ids);
349
350 void GLAPIENTRY
351 _mesa_GenVertexArrays_no_error(GLsizei n, GLuint *arrays);
352
353 void GLAPIENTRY _mesa_GenVertexArrays(GLsizei n, GLuint *arrays);
354
355 void GLAPIENTRY
356 _mesa_CreateVertexArrays_no_error(GLsizei n, GLuint *arrays);
357
358 void GLAPIENTRY _mesa_CreateVertexArrays(GLsizei n, GLuint *arrays);
359
360 GLboolean GLAPIENTRY _mesa_IsVertexArray( GLuint id );
361
362 void GLAPIENTRY
363 _mesa_VertexArrayElementBuffer_no_error(GLuint vaobj, GLuint buffer);
364
365 void GLAPIENTRY _mesa_VertexArrayElementBuffer(GLuint vaobj, GLuint buffer);
366
367 void GLAPIENTRY _mesa_GetVertexArrayiv(GLuint vaobj, GLenum pname, GLint *param);
368
369 #endif /* ARRAYOBJ_H */