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