libGL: Consolidate DRI initialization in dri_glx.c
[mesa.git] / src / glx / x11 / indirect_va_private.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 * Pointer to the application supplied data.
48 */
49 const void * data;
50
51 /**
52 * Enum representing the type of the application supplied data.
53 */
54 GLenum data_type;
55
56 /**
57 * Stride value supplied by the application. This value is not used
58 * internally. It is only kept so that it can be queried by the
59 * application using glGet*v.
60 */
61 GLsizei user_stride;
62
63 /**
64 * Calculated size, in bytes, of a single element in the array. This
65 * is calculated based on \c count and the size of the data type
66 * represented by \c data_type.
67 */
68 GLsizei element_size;
69
70 /**
71 * Actual byte-stride from one element to the next. This value will
72 * be equal to either \c user_stride or \c element_stride.
73 */
74 GLsizei true_stride;
75
76 /**
77 * Number of data values in each element.
78 */
79 GLint count;
80
81 /**
82 * "Normalized" data is on the range [0,1] (unsigned) or [-1,1] (signed).
83 * This is used for mapping integral types to floating point types.
84 */
85 GLboolean normalized;
86
87 /**
88 * Pre-calculated GLX protocol command header.
89 */
90 uint32_t header[2];
91
92 /**
93 * Size of the header data. For simple data, like glColorPointerfv,
94 * this is 4. For complex data that requires either a count (e.g.,
95 * glWeightfvARB), an index (e.g., glVertexAttrib1fvARB), or a
96 * selector enum (e.g., glMultiTexCoord2fv) this is 8.
97 */
98 unsigned header_size;
99
100 /**
101 * Set to \c GL_TRUE if this array is enabled. Otherwise, it is set
102 * to \c GL_FALSE.
103 */
104 GLboolean enabled;
105
106 /**
107 * For multi-arrayed data (e.g., texture coordinates, generic vertex
108 * program attributes, etc.), this specifies which array this is.
109 */
110 unsigned index;
111
112 /**
113 * Per-array-type key. For most arrays, this will be the GL enum for
114 * that array (e.g., GL_VERTEX_ARRAY for vertex data, GL_NORMAL_ARRAY
115 * for normal data, GL_TEXTURE_COORD_ARRAY for texture coordinate data,
116 * etc.).
117 */
118 GLenum key;
119
120 /**
121 * If this array can be used with the "classic" \c glDrawArrays protocol,
122 * this is set to \c GL_TRUE. Otherwise, it is set to \c GL_FALSE.
123 */
124 GLboolean old_DrawArrays_possible;
125 };
126
127
128 /**
129 * Array state that is pushed / poped by \c glPushClientAttrib and
130 * \c glPopClientAttrib.
131 */
132 struct array_stack_state {
133 /**
134 * Pointer to the application supplied data.
135 */
136 const void * data;
137
138 /**
139 * Enum representing the type of the application supplied data.
140 */
141 GLenum data_type;
142
143 /**
144 * Stride value supplied by the application. This value is not used
145 * internally. It is only kept so that it can be queried by the
146 * application using glGet*v.
147 */
148 GLsizei user_stride;
149
150 /**
151 * Number of data values in each element.
152 */
153 GLint count;
154
155 /**
156 * Per-array-type key. For most arrays, this will be the GL enum for
157 * that array (e.g., GL_VERTEX_ARRAY for vertex data, GL_NORMAL_ARRAY
158 * for normal data, GL_TEXTURE_COORD_ARRAY for texture coordinate data,
159 * etc.).
160 */
161 GLenum key;
162
163 /**
164 * For multi-arrayed data (e.g., texture coordinates, generic vertex
165 * program attributes, etc.), this specifies which array this is.
166 */
167 unsigned index;
168
169 /**
170 * Set to \c GL_TRUE if this array is enabled. Otherwise, it is set
171 * to \c GL_FALSE.
172 */
173 GLboolean enabled;
174 };
175
176
177 /**
178 * Collection of all the vertex array state.
179 */
180 struct array_state_vector {
181 /**
182 * Number of arrays tracked by \c ::arrays.
183 */
184 size_t num_arrays;
185
186 /**
187 * Array of vertex array state. This array contains all of the valid
188 * vertex arrays. If a vertex array isn't in this array, then it isn't
189 * valid. For example, if an implementation does not support
190 * EXT_fog_coord, there won't be a GL_FOG_COORD_ARRAY entry in this
191 * array.
192 */
193 struct array_state * arrays;
194
195 /**
196 * Number of currently enabled client-side arrays. The value of this
197 * field is only valid if \c array_info_cache_valid is true.
198 */
199 size_t enabled_client_array_count;
200
201 /**
202 * \name ARRAY_INFO cache.
203 *
204 * These fields track the state of the ARRAY_INFO cache. The
205 * \c array_info_cache_size is the size of the actual data stored in
206 * \c array_info_cache. \c array_info_cache_buffer_size is the size of
207 * the buffer. This will always be greater than or equal to
208 * \c array_info_cache_size.
209 *
210 * \note
211 * There are some bytes of extra data before \c array_info_cache that is
212 * used to hold the header for RenderLarge commands. This is
213 * \b not included in \c array_info_cache_size or
214 * \c array_info_cache_buffer_size. \c array_info_cache_base stores a
215 * pointer to the true start of the buffer (i.e., what malloc returned).
216 */
217 /*@{*/
218 size_t array_info_cache_size;
219 size_t array_info_cache_buffer_size;
220 void * array_info_cache;
221 void * array_info_cache_base;
222 /*@}*/
223
224
225 /**
226 * Is the cache of ARRAY_INFO data valid? The cache can become invalid
227 * when one of several state changes occur. Among these chages are
228 * modifying the array settings for an enabled array and enabling /
229 * disabling an array.
230 */
231 GLboolean array_info_cache_valid;
232
233 /**
234 * Is it possible to use the GL 1.1 / EXT_vertex_arrays protocol? Use
235 * of this protocol is disabled with really old servers (i.e., servers
236 * that don't support GL 1.1 or EXT_vertex_arrays) or when an environment
237 * variable is set.
238 *
239 * \todo
240 * GL 1.1 and EXT_vertex_arrays use identical protocol, but have different
241 * opcodes for \c glDrawArrays. For servers that advertise one or the
242 * other, there should be a way to select which opcode to use.
243 */
244 GLboolean old_DrawArrays_possible;
245
246 /**
247 * Is it possible to use the new GL X.X / ARB_vertex_buffer_object
248 * protocol?
249 *
250 * \todo
251 * This protocol has not yet been defined by the ARB, but is currently a
252 * work in progress. This field is a place-holder.
253 */
254 GLboolean new_DrawArrays_possible;
255
256 /**
257 * Active texture unit set by \c glClientActiveTexture.
258 *
259 * \sa __glXGetActiveTextureUnit
260 */
261 unsigned active_texture_unit;
262
263 /**
264 * Number of supported texture units. Even if ARB_multitexture /
265 * GL 1.3 are not supported, this will be at least 1. When multitexture
266 * is supported, this will be the value queried by calling
267 * \c glGetIntegerv with \c GL_MAX_TEXTURE_UNITS.
268 *
269 * \todo
270 * Investigate if this should be the value of \c GL_MAX_TEXTURE_COORDS
271 * instead (if GL 2.0 / ARB_fragment_shader / ARB_fragment_program /
272 * NV_fragment_program are supported).
273 */
274 unsigned num_texture_units;
275
276 /**
277 * Number of generic vertex program attribs. If GL_ARB_vertex_program
278 * is not supported, this will be zero. Otherwise it will be the value
279 * queries by calling \c glGetProgramiv with \c GL_VERTEX_PROGRAM_ARB
280 * and \c GL_MAX_PROGRAM_ATTRIBS_ARB.
281 */
282 unsigned num_vertex_program_attribs;
283
284 /**
285 * \n Methods for implementing various GL functions.
286 *
287 * These method pointers are only valid \c array_info_cache_valid is set.
288 * When each function starts, it much check \c array_info_cache_valid.
289 * If it is not set, it must call \c fill_array_info_cache and call
290 * the new method.
291 *
292 * \sa fill_array_info_cache
293 *
294 * \todo
295 * Write code to plug these functions directly into the dispatch table.
296 */
297 /*@{*/
298 void (*DrawArrays)( GLenum, GLint, GLsizei );
299 void (*DrawElements)( GLenum mode, GLsizei count, GLenum type,
300 const GLvoid *indices );
301 /*@}*/
302
303 struct array_stack_state * stack;
304 unsigned active_texture_unit_stack[ __GL_CLIENT_ATTRIB_STACK_DEPTH ];
305 unsigned stack_index;
306 };
307
308 #endif /* _INDIRECT_VA_PRIVATE_ */