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