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