1848b8605Smrg/*
2848b8605Smrg * (C) Copyright IBM Corporation 2004, 2005
3848b8605Smrg * All Rights Reserved.
4848b8605Smrg *
5848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6848b8605Smrg * copy of this software and associated documentation files (the "Software"),
7848b8605Smrg * to deal in the Software without restriction, including without limitation
8848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sub license,
9848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
10848b8605Smrg * Software is furnished to do so, subject to the following conditions:
11848b8605Smrg *
12848b8605Smrg * The above copyright notice and this permission notice (including the next
13848b8605Smrg * paragraph) shall be included in all copies or substantial portions of the
14848b8605Smrg * Software.
15848b8605Smrg *
16848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17848b8605Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19848b8605Smrg * IBM,
20848b8605Smrg * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21848b8605Smrg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22848b8605Smrg * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23848b8605Smrg * SOFTWARE.
24848b8605Smrg */
25848b8605Smrg
26848b8605Smrg#ifndef _INDIRECT_VA_PRIVATE_
27848b8605Smrg#define _INDIRECT_VA_PRIVATE_
28848b8605Smrg
29848b8605Smrg/**
30848b8605Smrg * \file indirect_va_private.h
31848b8605Smrg *
32848b8605Smrg * \author Ian Romanick <idr@us.ibm.com>
33848b8605Smrg */
34848b8605Smrg
35848b8605Smrg#include <inttypes.h>
36848b8605Smrg
37848b8605Smrg#include "glxclient.h"
38848b8605Smrg#include "indirect.h"
39848b8605Smrg#include <GL/glxproto.h>
40848b8605Smrg
41848b8605Smrg
42848b8605Smrg/**
43848b8605Smrg * State descriptor for a single array of vertex data.
44848b8605Smrg */
45848b8605Smrgstruct array_state
46848b8605Smrg{
47848b8605Smrg    /**
48848b8605Smrg     * Pointer to the application supplied data.
49848b8605Smrg     */
50848b8605Smrg   const void *data;
51848b8605Smrg
52848b8605Smrg    /**
53848b8605Smrg     * Enum representing the type of the application supplied data.
54848b8605Smrg     */
55848b8605Smrg   GLenum data_type;
56848b8605Smrg
57848b8605Smrg    /**
58848b8605Smrg     * Stride value supplied by the application.  This value is not used
59848b8605Smrg     * internally.  It is only kept so that it can be queried by the
60848b8605Smrg     * application using glGet*v.
61848b8605Smrg     */
62848b8605Smrg   GLsizei user_stride;
63848b8605Smrg
64848b8605Smrg    /**
65848b8605Smrg     * Calculated size, in bytes, of a single element in the array.  This
66848b8605Smrg     * is calculated based on \c count and the size of the data type
67848b8605Smrg     * represented by \c data_type.
68848b8605Smrg     */
69848b8605Smrg   GLsizei element_size;
70848b8605Smrg
71848b8605Smrg    /**
72848b8605Smrg     * Actual byte-stride from one element to the next.  This value will
73848b8605Smrg     * be equal to either \c user_stride or \c element_stride.
74848b8605Smrg     */
75848b8605Smrg   GLsizei true_stride;
76848b8605Smrg
77848b8605Smrg    /**
78848b8605Smrg     * Number of data values in each element.
79848b8605Smrg     */
80848b8605Smrg   GLint count;
81848b8605Smrg
82848b8605Smrg    /**
83848b8605Smrg     * "Normalized" data is on the range [0,1] (unsigned) or [-1,1] (signed).
84848b8605Smrg     * This is used for mapping integral types to floating point types.
85848b8605Smrg     */
86848b8605Smrg   GLboolean normalized;
87848b8605Smrg
88848b8605Smrg    /**
89848b8605Smrg     * Pre-calculated GLX protocol command header.
90b8e80941Smrg     * This contains two 16-bit words: the command length and the command
91b8e80941Smrg     * opcode.
92848b8605Smrg     */
93b8e80941Smrg   uint16_t header[2];
94848b8605Smrg
95848b8605Smrg    /**
96848b8605Smrg     * Set to \c GL_TRUE if this array is enabled.  Otherwise, it is set
97848b8605Smrg     * to \c GL_FALSE.
98848b8605Smrg     */
99848b8605Smrg   GLboolean enabled;
100848b8605Smrg
101848b8605Smrg    /**
102848b8605Smrg     * For multi-arrayed data (e.g., texture coordinates, generic vertex
103848b8605Smrg     * program attributes, etc.), this specifies which array this is.
104848b8605Smrg     */
105848b8605Smrg   unsigned index;
106848b8605Smrg
107848b8605Smrg    /**
108848b8605Smrg     * Per-array-type key.  For most arrays, this will be the GL enum for
109848b8605Smrg     * that array (e.g., GL_VERTEX_ARRAY for vertex data, GL_NORMAL_ARRAY
110848b8605Smrg     * for normal data, GL_TEXTURE_COORD_ARRAY for texture coordinate data,
111848b8605Smrg     * etc.).
112848b8605Smrg     */
113848b8605Smrg   GLenum key;
114848b8605Smrg
115848b8605Smrg    /**
116848b8605Smrg     * If this array can be used with the "classic" \c glDrawArrays protocol,
117848b8605Smrg     * this is set to \c GL_TRUE.  Otherwise, it is set to \c GL_FALSE.
118848b8605Smrg     */
119848b8605Smrg   GLboolean old_DrawArrays_possible;
120848b8605Smrg};
121848b8605Smrg
122848b8605Smrg
123848b8605Smrg/**
124848b8605Smrg * Array state that is pushed / poped by \c glPushClientAttrib and
125848b8605Smrg * \c glPopClientAttrib.
126848b8605Smrg */
127848b8605Smrgstruct array_stack_state
128848b8605Smrg{
129848b8605Smrg    /**
130848b8605Smrg     * Pointer to the application supplied data.
131848b8605Smrg     */
132848b8605Smrg   const void *data;
133848b8605Smrg
134848b8605Smrg    /**
135848b8605Smrg     * Enum representing the type of the application supplied data.
136848b8605Smrg     */
137848b8605Smrg   GLenum data_type;
138848b8605Smrg
139848b8605Smrg    /**
140848b8605Smrg     * Stride value supplied by the application.  This value is not used
141848b8605Smrg     * internally.  It is only kept so that it can be queried by the
142848b8605Smrg     * application using glGet*v.
143848b8605Smrg     */
144848b8605Smrg   GLsizei user_stride;
145848b8605Smrg
146848b8605Smrg    /**
147848b8605Smrg     * Number of data values in each element.
148848b8605Smrg     */
149848b8605Smrg   GLint count;
150848b8605Smrg
151848b8605Smrg    /**
152848b8605Smrg     * Per-array-type key.  For most arrays, this will be the GL enum for
153848b8605Smrg     * that array (e.g., GL_VERTEX_ARRAY for vertex data, GL_NORMAL_ARRAY
154848b8605Smrg     * for normal data, GL_TEXTURE_COORD_ARRAY for texture coordinate data,
155848b8605Smrg     * etc.).
156848b8605Smrg     */
157848b8605Smrg   GLenum key;
158848b8605Smrg
159848b8605Smrg    /**
160848b8605Smrg     * For multi-arrayed data (e.g., texture coordinates, generic vertex
161848b8605Smrg     * program attributes, etc.), this specifies which array this is.
162848b8605Smrg     */
163848b8605Smrg   unsigned index;
164848b8605Smrg
165848b8605Smrg    /**
166848b8605Smrg     * Set to \c GL_TRUE if this array is enabled.  Otherwise, it is set
167848b8605Smrg     * to \c GL_FALSE.
168848b8605Smrg     */
169848b8605Smrg   GLboolean enabled;
170848b8605Smrg};
171848b8605Smrg
172848b8605Smrg
173848b8605Smrg/**
174848b8605Smrg * Collection of all the vertex array state.
175848b8605Smrg */
176848b8605Smrgstruct array_state_vector
177848b8605Smrg{
178848b8605Smrg    /**
179848b8605Smrg     * Number of arrays tracked by \c ::arrays.
180848b8605Smrg     */
181848b8605Smrg   size_t num_arrays;
182848b8605Smrg
183848b8605Smrg    /**
184848b8605Smrg     * Array of vertex array state.  This array contains all of the valid
185848b8605Smrg     * vertex arrays.  If a vertex array isn't in this array, then it isn't
186848b8605Smrg     * valid.  For example, if an implementation does not support
187848b8605Smrg     * EXT_fog_coord, there won't be a GL_FOG_COORD_ARRAY entry in this
188848b8605Smrg     * array.
189848b8605Smrg     */
190848b8605Smrg   struct array_state *arrays;
191848b8605Smrg
192848b8605Smrg    /**
193848b8605Smrg     * Number of currently enabled client-side arrays.  The value of this
194848b8605Smrg     * field is only valid if \c array_info_cache_valid is true.
195848b8605Smrg     */
196848b8605Smrg   size_t enabled_client_array_count;
197848b8605Smrg
198848b8605Smrg    /**
199848b8605Smrg     * \name ARRAY_INFO cache.
200848b8605Smrg     *
201848b8605Smrg     * These fields track the state of the ARRAY_INFO cache.  The
202848b8605Smrg     * \c array_info_cache_size is the size of the actual data stored in
203848b8605Smrg     * \c array_info_cache.  \c array_info_cache_buffer_size is the size of
204848b8605Smrg     * the buffer.  This will always be greater than or equal to
205848b8605Smrg     * \c array_info_cache_size.
206848b8605Smrg     *
207848b8605Smrg     * \note
208848b8605Smrg     * There are some bytes of extra data before \c array_info_cache that is
209848b8605Smrg     * used to hold the header for RenderLarge commands.  This is
210848b8605Smrg     * \b not included in \c array_info_cache_size or
211848b8605Smrg     * \c array_info_cache_buffer_size.  \c array_info_cache_base stores a
212848b8605Smrg     * pointer to the true start of the buffer (i.e., what malloc returned).
213848b8605Smrg     */
214848b8605Smrg   /*@{ */
215848b8605Smrg   size_t array_info_cache_size;
216848b8605Smrg   size_t array_info_cache_buffer_size;
217848b8605Smrg   void *array_info_cache;
218848b8605Smrg   void *array_info_cache_base;
219848b8605Smrg   /*@} */
220848b8605Smrg
221848b8605Smrg
222848b8605Smrg    /**
223848b8605Smrg     * Is the cache of ARRAY_INFO data valid?  The cache can become invalid
224848b8605Smrg     * when one of several state changes occur.  Among these chages are
225848b8605Smrg     * modifying the array settings for an enabled array and enabling /
226848b8605Smrg     * disabling an array.
227848b8605Smrg     */
228848b8605Smrg   GLboolean array_info_cache_valid;
229848b8605Smrg
230848b8605Smrg    /**
231848b8605Smrg     * Is it possible to use the GL 1.1 / EXT_vertex_arrays protocol?  Use
232848b8605Smrg     * of this protocol is disabled with really old servers (i.e., servers
233848b8605Smrg     * that don't support GL 1.1 or EXT_vertex_arrays) or when an environment
234848b8605Smrg     * variable is set.
235848b8605Smrg     *
236848b8605Smrg     * \todo
237848b8605Smrg     * GL 1.1 and EXT_vertex_arrays use identical protocol, but have different
238848b8605Smrg     * opcodes for \c glDrawArrays.  For servers that advertise one or the
239848b8605Smrg     * other, there should be a way to select which opcode to use.
240848b8605Smrg     */
241848b8605Smrg   GLboolean old_DrawArrays_possible;
242848b8605Smrg
243848b8605Smrg    /**
244848b8605Smrg     * Is it possible to use the new GL X.X / ARB_vertex_buffer_object
245848b8605Smrg     * protocol?
246848b8605Smrg     *
247848b8605Smrg     * \todo
248848b8605Smrg     * This protocol has not yet been defined by the ARB, but is currently a
249848b8605Smrg     * work in progress.  This field is a place-holder.
250848b8605Smrg     */
251848b8605Smrg   GLboolean new_DrawArrays_possible;
252848b8605Smrg
253848b8605Smrg    /**
254848b8605Smrg     * Active texture unit set by \c glClientActiveTexture.
255848b8605Smrg     *
256848b8605Smrg     * \sa __glXGetActiveTextureUnit
257848b8605Smrg     */
258848b8605Smrg   unsigned active_texture_unit;
259848b8605Smrg
260848b8605Smrg    /**
261848b8605Smrg     * Number of supported texture units.  Even if ARB_multitexture /
262848b8605Smrg     * GL 1.3 are not supported, this will be at least 1.  When multitexture
263848b8605Smrg     * is supported, this will be the value queried by calling
264848b8605Smrg     * \c glGetIntegerv with \c GL_MAX_TEXTURE_UNITS.
265848b8605Smrg     *
266848b8605Smrg     * \todo
267848b8605Smrg     * Investigate if this should be the value of \c GL_MAX_TEXTURE_COORDS
268848b8605Smrg     * instead (if GL 2.0 / ARB_fragment_shader / ARB_fragment_program /
269848b8605Smrg     * NV_fragment_program are supported).
270848b8605Smrg     */
271848b8605Smrg   unsigned num_texture_units;
272848b8605Smrg
273848b8605Smrg    /**
274848b8605Smrg     * Number of generic vertex program attribs.  If GL_ARB_vertex_program
275848b8605Smrg     * is not supported, this will be zero.  Otherwise it will be the value
276848b8605Smrg     * queries by calling \c glGetProgramiv with \c GL_VERTEX_PROGRAM_ARB
277848b8605Smrg     * and \c GL_MAX_PROGRAM_ATTRIBS_ARB.
278848b8605Smrg     */
279848b8605Smrg   unsigned num_vertex_program_attribs;
280848b8605Smrg
281848b8605Smrg    /**
282848b8605Smrg     * \n Methods for implementing various GL functions.
283848b8605Smrg     *
284848b8605Smrg     * These method pointers are only valid \c array_info_cache_valid is set.
285848b8605Smrg     * When each function starts, it much check \c array_info_cache_valid.
286848b8605Smrg     * If it is not set, it must call \c fill_array_info_cache and call
287848b8605Smrg     * the new method.
288848b8605Smrg     *
289848b8605Smrg     * \sa fill_array_info_cache
290848b8605Smrg     *
291848b8605Smrg     * \todo
292848b8605Smrg     * Write code to plug these functions directly into the dispatch table.
293848b8605Smrg     */
294848b8605Smrg   /*@{ */
295848b8605Smrg   void (*DrawArrays) (GLenum, GLint, GLsizei);
296848b8605Smrg   void (*DrawElements) (GLenum mode, GLsizei count, GLenum type,
297848b8605Smrg                         const GLvoid * indices);
298848b8605Smrg   /*@} */
299848b8605Smrg
300848b8605Smrg   struct array_stack_state *stack;
301848b8605Smrg   unsigned active_texture_unit_stack[__GL_CLIENT_ATTRIB_STACK_DEPTH];
302848b8605Smrg   unsigned stack_index;
303848b8605Smrg};
304848b8605Smrg
305848b8605Smrg#endif /* _INDIRECT_VA_PRIVATE_ */
306