dri3: Don't fail on version mismatch
[mesa.git] / src / glx / indirect_vertex_array_priv.h
1 /*
2 * (C) Copyright IBM Corporation 2004, 2005
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sub license,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * IBM,
20 * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26 #ifndef _INDIRECT_VA_PRIVATE_
27 #define _INDIRECT_VA_PRIVATE_
28
29 /**
30 * \file indirect_va_private.h
31 *
32 * \author Ian Romanick <idr@us.ibm.com>
33 */
34
35 #include <inttypes.h>
36
37 #include "glxclient.h"
38 #include "indirect.h"
39 #include <GL/glxproto.h>
40
41
42 /**
43 * State descriptor for a single array of vertex data.
44 */
45 struct array_state
46 {
47 /**
48 * Pointer to the application supplied data.
49 */
50 const void *data;
51
52 /**
53 * Enum representing the type of the application supplied data.
54 */
55 GLenum data_type;
56
57 /**
58 * Stride value supplied by the application. This value is not used
59 * internally. It is only kept so that it can be queried by the
60 * application using glGet*v.
61 */
62 GLsizei user_stride;
63
64 /**
65 * Calculated size, in bytes, of a single element in the array. This
66 * is calculated based on \c count and the size of the data type
67 * represented by \c data_type.
68 */
69 GLsizei element_size;
70
71 /**
72 * Actual byte-stride from one element to the next. This value will
73 * be equal to either \c user_stride or \c element_stride.
74 */
75 GLsizei true_stride;
76
77 /**
78 * Number of data values in each element.
79 */
80 GLint count;
81
82 /**
83 * "Normalized" data is on the range [0,1] (unsigned) or [-1,1] (signed).
84 * This is used for mapping integral types to floating point types.
85 */
86 GLboolean normalized;
87
88 /**
89 * Pre-calculated GLX protocol command header.
90 * This contains two 16-bit words: the command length and the command
91 * opcode.
92 */
93 uint16_t header[2];
94
95 /**
96 * Set to \c GL_TRUE if this array is enabled. Otherwise, it is set
97 * to \c GL_FALSE.
98 */
99 GLboolean enabled;
100
101 /**
102 * For multi-arrayed data (e.g., texture coordinates, generic vertex
103 * program attributes, etc.), this specifies which array this is.
104 */
105 unsigned index;
106
107 /**
108 * Per-array-type key. For most arrays, this will be the GL enum for
109 * that array (e.g., GL_VERTEX_ARRAY for vertex data, GL_NORMAL_ARRAY
110 * for normal data, GL_TEXTURE_COORD_ARRAY for texture coordinate data,
111 * etc.).
112 */
113 GLenum key;
114
115 /**
116 * If this array can be used with the "classic" \c glDrawArrays protocol,
117 * this is set to \c GL_TRUE. Otherwise, it is set to \c GL_FALSE.
118 */
119 GLboolean old_DrawArrays_possible;
120 };
121
122
123 /**
124 * Array state that is pushed / poped by \c glPushClientAttrib and
125 * \c glPopClientAttrib.
126 */
127 struct array_stack_state
128 {
129 /**
130 * Pointer to the application supplied data.
131 */
132 const void *data;
133
134 /**
135 * Enum representing the type of the application supplied data.
136 */
137 GLenum data_type;
138
139 /**
140 * Stride value supplied by the application. This value is not used
141 * internally. It is only kept so that it can be queried by the
142 * application using glGet*v.
143 */
144 GLsizei user_stride;
145
146 /**
147 * Number of data values in each element.
148 */
149 GLint count;
150
151 /**
152 * Per-array-type key. For most arrays, this will be the GL enum for
153 * that array (e.g., GL_VERTEX_ARRAY for vertex data, GL_NORMAL_ARRAY
154 * for normal data, GL_TEXTURE_COORD_ARRAY for texture coordinate data,
155 * etc.).
156 */
157 GLenum key;
158
159 /**
160 * For multi-arrayed data (e.g., texture coordinates, generic vertex
161 * program attributes, etc.), this specifies which array this is.
162 */
163 unsigned index;
164
165 /**
166 * Set to \c GL_TRUE if this array is enabled. Otherwise, it is set
167 * to \c GL_FALSE.
168 */
169 GLboolean enabled;
170 };
171
172
173 /**
174 * Collection of all the vertex array state.
175 */
176 struct array_state_vector
177 {
178 /**
179 * Number of arrays tracked by \c ::arrays.
180 */
181 size_t num_arrays;
182
183 /**
184 * Array of vertex array state. This array contains all of the valid
185 * vertex arrays. If a vertex array isn't in this array, then it isn't
186 * valid. For example, if an implementation does not support
187 * EXT_fog_coord, there won't be a GL_FOG_COORD_ARRAY entry in this
188 * array.
189 */
190 struct array_state *arrays;
191
192 /**
193 * Number of currently enabled client-side arrays. The value of this
194 * field is only valid if \c array_info_cache_valid is true.
195 */
196 size_t enabled_client_array_count;
197
198 /**
199 * \name ARRAY_INFO cache.
200 *
201 * These fields track the state of the ARRAY_INFO cache. The
202 * \c array_info_cache_size is the size of the actual data stored in
203 * \c array_info_cache. \c array_info_cache_buffer_size is the size of
204 * the buffer. This will always be greater than or equal to
205 * \c array_info_cache_size.
206 *
207 * \note
208 * There are some bytes of extra data before \c array_info_cache that is
209 * used to hold the header for RenderLarge commands. This is
210 * \b not included in \c array_info_cache_size or
211 * \c array_info_cache_buffer_size. \c array_info_cache_base stores a
212 * pointer to the true start of the buffer (i.e., what malloc returned).
213 */
214 /*@{ */
215 size_t array_info_cache_size;
216 size_t array_info_cache_buffer_size;
217 void *array_info_cache;
218 void *array_info_cache_base;
219 /*@} */
220
221
222 /**
223 * Is the cache of ARRAY_INFO data valid? The cache can become invalid
224 * when one of several state changes occur. Among these chages are
225 * modifying the array settings for an enabled array and enabling /
226 * disabling an array.
227 */
228 GLboolean array_info_cache_valid;
229
230 /**
231 * Is it possible to use the GL 1.1 / EXT_vertex_arrays protocol? Use
232 * of this protocol is disabled with really old servers (i.e., servers
233 * that don't support GL 1.1 or EXT_vertex_arrays) or when an environment
234 * variable is set.
235 *
236 * \todo
237 * GL 1.1 and EXT_vertex_arrays use identical protocol, but have different
238 * opcodes for \c glDrawArrays. For servers that advertise one or the
239 * other, there should be a way to select which opcode to use.
240 */
241 GLboolean old_DrawArrays_possible;
242
243 /**
244 * Is it possible to use the new GL X.X / ARB_vertex_buffer_object
245 * protocol?
246 *
247 * \todo
248 * This protocol has not yet been defined by the ARB, but is currently a
249 * work in progress. This field is a place-holder.
250 */
251 GLboolean new_DrawArrays_possible;
252
253 /**
254 * Active texture unit set by \c glClientActiveTexture.
255 *
256 * \sa __glXGetActiveTextureUnit
257 */
258 unsigned active_texture_unit;
259
260 /**
261 * Number of supported texture units. Even if ARB_multitexture /
262 * GL 1.3 are not supported, this will be at least 1. When multitexture
263 * is supported, this will be the value queried by calling
264 * \c glGetIntegerv with \c GL_MAX_TEXTURE_UNITS.
265 *
266 * \todo
267 * Investigate if this should be the value of \c GL_MAX_TEXTURE_COORDS
268 * instead (if GL 2.0 / ARB_fragment_shader / ARB_fragment_program /
269 * NV_fragment_program are supported).
270 */
271 unsigned num_texture_units;
272
273 /**
274 * Number of generic vertex program attribs. If GL_ARB_vertex_program
275 * is not supported, this will be zero. Otherwise it will be the value
276 * queries by calling \c glGetProgramiv with \c GL_VERTEX_PROGRAM_ARB
277 * and \c GL_MAX_PROGRAM_ATTRIBS_ARB.
278 */
279 unsigned num_vertex_program_attribs;
280
281 /**
282 * \n Methods for implementing various GL functions.
283 *
284 * These method pointers are only valid \c array_info_cache_valid is set.
285 * When each function starts, it much check \c array_info_cache_valid.
286 * If it is not set, it must call \c fill_array_info_cache and call
287 * the new method.
288 *
289 * \sa fill_array_info_cache
290 *
291 * \todo
292 * Write code to plug these functions directly into the dispatch table.
293 */
294 /*@{ */
295 void (*DrawArrays) (GLenum, GLint, GLsizei);
296 void (*DrawElements) (GLenum mode, GLsizei count, GLenum type,
297 const GLvoid * indices);
298 /*@} */
299
300 struct array_stack_state *stack;
301 unsigned active_texture_unit_stack[__GL_CLIENT_ATTRIB_STACK_DEPTH];
302 unsigned stack_index;
303 };
304
305 #endif /* _INDIRECT_VA_PRIVATE_ */