mesa: add packing support for setting uniforms
[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
34 struct gl_context;
35
36 /**
37 * \file arrayobj.h
38 * Functions for the GL_ARB_vertex_array_object extension.
39 *
40 * \author Ian Romanick <idr@us.ibm.com>
41 * \author Brian Paul
42 */
43
44 /*
45 * Internal functions
46 */
47
48 extern struct gl_vertex_array_object *
49 _mesa_lookup_vao(struct gl_context *ctx, GLuint id);
50
51 extern struct gl_vertex_array_object *
52 _mesa_lookup_vao_err(struct gl_context *ctx, GLuint id, const char *caller);
53
54 extern struct gl_vertex_array_object *
55 _mesa_new_vao(struct gl_context *ctx, GLuint name);
56
57 extern void
58 _mesa_delete_vao(struct gl_context *ctx, struct gl_vertex_array_object *obj);
59
60 extern void
61 _mesa_reference_vao_(struct gl_context *ctx,
62 struct gl_vertex_array_object **ptr,
63 struct gl_vertex_array_object *vao);
64
65 static inline void
66 _mesa_reference_vao(struct gl_context *ctx,
67 struct gl_vertex_array_object **ptr,
68 struct gl_vertex_array_object *vao)
69 {
70 if (*ptr != vao)
71 _mesa_reference_vao_(ctx, ptr, vao);
72 }
73
74
75 extern void
76 _mesa_initialize_vao(struct gl_context *ctx,
77 struct gl_vertex_array_object *obj, GLuint name);
78
79
80 extern void
81 _mesa_update_vao_derived_arrays(struct gl_context *ctx,
82 struct gl_vertex_array_object *vao);
83
84
85 /**
86 * Mark the vao as shared and immutable, do remaining updates.
87 */
88 extern void
89 _mesa_set_vao_immutable(struct gl_context *ctx,
90 struct gl_vertex_array_object *vao);
91
92
93 /* Returns true if all varying arrays reside in vbos */
94 extern bool
95 _mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao);
96
97 /* Returns true if all vbos are unmapped */
98 extern bool
99 _mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao);
100
101
102 /**
103 * Array to apply the position/generic0 aliasing map to
104 * an attribute value used in vertex processing inputs to an attribute
105 * as they appear in the vao.
106 */
107 extern const GLubyte
108 _mesa_vao_attribute_map[ATTRIBUTE_MAP_MODE_MAX][VERT_ATTRIB_MAX];
109
110
111 /**
112 * Apply the position/generic0 aliasing map to a bitfield from the vao.
113 * Use for example to convert gl_vertex_array_object::_Enabled
114 * or gl_vertex_buffer_binding::_VertexBinding from the vao numbering to
115 * the numbering used with vertex processing inputs.
116 */
117 static inline GLbitfield
118 _mesa_vao_enable_to_vp_inputs(gl_attribute_map_mode mode, GLbitfield enabled)
119 {
120 switch (mode) {
121 case ATTRIBUTE_MAP_MODE_IDENTITY:
122 return enabled;
123 case ATTRIBUTE_MAP_MODE_POSITION:
124 /* Copy VERT_ATTRIB_POS enable bit into GENERIC0 position */
125 return (enabled & ~VERT_BIT_GENERIC0)
126 | ((enabled & VERT_BIT_POS) << VERT_ATTRIB_GENERIC0);
127 case ATTRIBUTE_MAP_MODE_GENERIC0:
128 /* Copy VERT_ATTRIB_GENERIC0 enable bit into POS position */
129 return (enabled & ~VERT_BIT_POS)
130 | ((enabled & VERT_BIT_GENERIC0) >> VERT_ATTRIB_GENERIC0);
131 default:
132 return 0;
133 }
134 }
135
136
137 /**
138 * Return the vp_inputs enabled bitmask after application of
139 * the position/generic0 aliasing map.
140 */
141 static inline GLbitfield
142 _mesa_get_vao_vp_inputs(const struct gl_vertex_array_object *vao)
143 {
144 const gl_attribute_map_mode mode = vao->_AttributeMapMode;
145 return _mesa_vao_enable_to_vp_inputs(mode, vao->_Enabled);
146 }
147
148
149 /*
150 * API functions
151 */
152
153
154 void GLAPIENTRY
155 _mesa_BindVertexArray_no_error(GLuint id);
156
157 void GLAPIENTRY _mesa_BindVertexArray( GLuint id );
158
159 void GLAPIENTRY
160 _mesa_DeleteVertexArrays_no_error(GLsizei n, const GLuint *ids);
161
162 void GLAPIENTRY _mesa_DeleteVertexArrays(GLsizei n, const GLuint *ids);
163
164 void GLAPIENTRY
165 _mesa_GenVertexArrays_no_error(GLsizei n, GLuint *arrays);
166
167 void GLAPIENTRY _mesa_GenVertexArrays(GLsizei n, GLuint *arrays);
168
169 void GLAPIENTRY
170 _mesa_CreateVertexArrays_no_error(GLsizei n, GLuint *arrays);
171
172 void GLAPIENTRY _mesa_CreateVertexArrays(GLsizei n, GLuint *arrays);
173
174 GLboolean GLAPIENTRY _mesa_IsVertexArray( GLuint id );
175
176 void GLAPIENTRY
177 _mesa_VertexArrayElementBuffer_no_error(GLuint vaobj, GLuint buffer);
178
179 void GLAPIENTRY _mesa_VertexArrayElementBuffer(GLuint vaobj, GLuint buffer);
180
181 void GLAPIENTRY _mesa_GetVertexArrayiv(GLuint vaobj, GLenum pname, GLint *param);
182
183 #endif /* ARRAYOBJ_H */