source: trunk/src/opengl/mesa/vb.h@ 3721

Last change on this file since 3721 was 3597, checked in by jeroen, 25 years ago

* empty log message *

File size: 9.1 KB
Line 
1/* $Id: vb.h,v 1.2 2000-05-23 20:34:59 jeroen Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28
29
30
31/* OVERVIEW:
32 *
33 * The vertices between glBegin() and glEnd() are accumulated in the
34 * vertex buffer. When either the vertex buffer becomes filled or a
35 * state change outside the glBegin()/glEnd() is made, we must flush
36 * the buffer.
37 *
38 * That is, we apply the vertex transformations, compute lighting,
39 * fog, texture coordinates etc. Then, we can render the vertices as
40 * points, lines or polygons by calling the gl_render_vb() function in
41 * render.c
42 *
43 * When we're outside of a glBegin/glEnd pair the information in this
44 * structure is retained pending either of the flushing events
45 * described above.
46 */
47
48#ifndef VB_H
49#define VB_H
50
51
52#ifdef HAVE_CONFIG_H
53#include "conf.h"
54#endif
55
56#include "vector.h"
57#include "matrix.h"
58#include "config.h"
59
60
61enum {
62 VB_IMMEDIATE,
63 VB_CVA_PRECALC
64};
65
66
67
68/*
69 */
70struct vertex_data
71{
72 GLfloat (*Obj)[4];
73 GLfloat (*Normal)[3];
74 GLubyte (*Color)[4];
75 GLuint *Index;
76 GLubyte *EdgeFlag;
77 GLfloat (*TexCoord[MAX_TEXTURE_UNITS])[4];
78 GLuint *Elt;
79};
80
81struct vertex_arrays
82{
83 GLvector4f Obj;
84 GLvector3f Normal;
85 GLvector4ub Color;
86 GLvector1ui Index;
87 GLvector1ub EdgeFlag;
88 GLvector4f TexCoord[MAX_TEXTURE_UNITS];
89 GLvector1ui Elt;
90};
91
92struct vertex_array_pointers
93{
94 GLvector4f *Obj;
95 GLvector3f *Normal;
96 GLvector4ub *Color;
97 GLvector1ui *Index;
98 GLvector1ub *EdgeFlag;
99 GLvector4f *TexCoord[MAX_TEXTURE_UNITS];
100 GLvector1ui *Elt;
101};
102
103
104/* Move to using pointers to this struct in the immediate structs -
105 * this is too big to keep 94 unused copies (7K) lying around in
106 * display lists.
107 */
108struct gl_material
109{
110 GLfloat Ambient[4];
111 GLfloat Diffuse[4];
112 GLfloat Specular[4];
113 GLfloat Emission[4];
114 GLfloat Shininess;
115 GLfloat AmbientIndex; /* for color index lighting */
116 GLfloat DiffuseIndex; /* for color index lighting */
117 GLfloat SpecularIndex; /* for color index lighting */
118};
119
120
121/* KW: Represents everything that can take place between a begin and
122 * end, and can represent multiple begin/end pairs. This plus *any*
123 * state variable (GLcontext) should be all you need to replay the
124 * represented begin/end pairs as if they took place in that state.
125 *
126 * Thus this is sufficient for both immediate and compiled modes, but
127 * we could/should throw some elements away for compiled mode if we
128 * know they were empty.
129 */
130struct immediate
131{
132 struct immediate *next; /* for cache of free IM's */
133 GLuint id, ref_count;
134
135 /* This must be saved when immediates are shared in display lists.
136 */
137 GLuint Start, Count;
138 GLuint LastData; /* count or count+1 */
139 GLuint AndFlag, OrFlag, BeginState;
140 GLuint LastPrimitive;
141
142 GLuint ArrayAndFlags; /* precalc'ed for glArrayElt */
143 GLuint ArrayIncr;
144 GLuint ArrayEltFlush;
145 GLuint FlushElt;
146
147 GLuint TF1[2]; /* precalc'ed for glTexCoord */
148 GLuint TF2[2];
149 GLuint TF3[2];
150 GLuint TF4[2];
151
152 GLuint Primitive[VB_SIZE]; /* GLubyte would do... */
153 GLuint NextPrimitive[VB_SIZE];
154
155 /* allocate storage for these on demand:
156 */
157 struct gl_material (*Material)[2];
158 GLuint *MaterialMask;
159
160 GLfloat (*TexCoordPtr[MAX_TEXTURE_UNITS])[4];
161
162 struct vertex_arrays v;
163
164 struct gl_context *backref;
165 void (*maybe_transform_vb)( struct immediate * );
166
167 /* Normal lengths, zero if not available.
168 */
169 GLfloat *NormalLengths;
170 GLuint LastCalcedLength;
171
172 GLuint Flag[VB_SIZE];
173 GLubyte Color[VB_SIZE][4];
174 GLfloat Obj[VB_SIZE][4];
175 GLfloat Normal[VB_SIZE][3];
176 GLfloat TexCoord[MAX_TEXTURE_UNITS][VB_SIZE][4];
177 GLuint Elt[VB_SIZE];
178 GLubyte EdgeFlag[VB_SIZE];
179 GLuint Index[VB_SIZE];
180};
181
182
183
184
185/* Not so big on storage these days, although still has pointers to
186 * arrays used for temporary results.
187 */
188struct vertex_buffer
189{
190 /* Pointers to enable multiple vertex_buffers - required for
191 * CVA, should also be useful for the PMesa people.
192 *
193 * Driver_data is alloc'ed in Driver.RegisterVB(), if required.
194 */
195 struct gl_context *ctx;
196 struct gl_pipeline *pipeline;
197 void *driver_data;
198
199
200 /* Data easily accessible by immediate mode fuctions: There is no
201 * guarentee on the driver side that processed data will end up or
202 * even pass through here. Use the GLvector pointers below.
203 *
204 * If we are not compiling, ctx->input points to this struct, in which
205 * case the values will be scribbled during transform_vb.
206 */
207 struct immediate *IM;
208 struct vertex_array_pointers store;
209
210 /* Where to find outstanding untransformed vertices.
211 */
212 struct immediate *prev_buffer;
213
214
215 GLuint Type;
216 GLuint Size, Start, Count;
217 GLuint Free, FirstFree;
218 GLuint CopyStart;
219 GLuint Parity, Ovf;
220 GLuint PurgeFlags;
221 GLuint IndirectCount; /* defaults to count */
222 GLuint OrFlag, SavedOrFlag;
223 GLuint EarlyCull;
224 GLuint Culled, CullDone;
225
226 /* Pointers to input data - default to buffers in 'im' above.
227 */
228 GLvector4f *ObjPtr;
229 GLvector3f *NormalPtr;
230 GLvector4ub *ColorPtr;
231 GLvector1ui *IndexPtr;
232 GLvector1ub *EdgeFlagPtr;
233 GLvector4f *TexCoordPtr[MAX_TEXTURE_UNITS];
234 GLvector1ui *EltPtr;
235 GLuint *Flag, FlagMax;
236 struct gl_material (*Material)[2];
237 GLuint *MaterialMask;
238
239 GLuint *NextPrimitive;
240 GLuint *Primitive;
241 GLuint LastPrimitive;
242
243 GLfloat (*BoundsPtr)[3]; /* Bounds for cull check */
244 GLfloat *NormalLengthPtr; /* Array of precomputed inv. normal lengths */
245
246
247 /* Holds malloced storage for pipeline data not supplied by
248 * the immediate struct.
249 */
250 GLvector4f Eye;
251 GLvector4f Clip;
252 GLvector4f Win;
253 GLvector4ub BColor; /* not used in cva */
254 GLvector1ui BIndex; /* not used in cva */
255 GLubyte (*Specular)[4];
256 GLubyte (*Spec[2])[4];
257
258 /* Temporary storage - may point into IM, or be dynamically
259 * allocated (for cva).
260 */
261 GLubyte *ClipMask;
262 GLubyte *UserClipMask;
263
264 /* Internal values. Where these point depends on whether
265 * there were any identity matrices defined as transformations
266 * in the pipeline.
267 */
268 GLvector4f *EyePtr;
269 GLvector4f *ClipPtr;
270 GLvector4f *Unprojected;
271 GLvector4f *Projected;
272 GLvector4f *CurrentTexCoord;
273 GLuint *Indirect; /* For eval rescue and cva render */
274
275
276 /* Currently active colors
277 */
278 GLvector4ub *Color[2];
279 GLvector1ui *Index[2];
280
281 /* Storage for colors which have been lit but not yet fogged.
282 * Required for CVA, just point into store for normal VB's.
283 */
284 GLvector4ub *LitColor[2];
285 GLvector1ui *LitIndex[2];
286 GLvector4ub *FoggedColor[2];
287 GLvector1ui *FoggedIndex[2];
288
289
290 /* Temporary values used in texgen.
291 */
292 GLfloat (*tmp_f)[3];
293 GLfloat *tmp_m;
294
295 /* Temporary values used in eval.
296 */
297 GLuint *EvaluatedFlags;
298
299 /* Not used for cva:
300 */
301 GLubyte *NormCullStart;
302 GLubyte *CullMask; /* Results of vertex culling */
303 GLubyte *NormCullMask; /* Compressed onto shared normals */
304
305
306 GLubyte ClipOrMask; /* bitwise-OR of all ClipMask[] values */
307 GLubyte ClipAndMask; /* bitwise-AND of all ClipMask[] values */
308 GLubyte CullFlag[2];
309 GLubyte CullMode; /* see flags below */
310
311 GLuint CopyCount; /* max 3 vertices to copy after transform */
312 GLuint Copy[3];
313 GLfloat CopyProj[3][4]; /* temporary store for projected clip coords */
314};
315
316
317extern struct vertex_buffer *gl_alloc_vb( GLcontext *ctx );
318extern struct immediate *gl_alloc_immediate( GLcontext *ctx );
319extern void gl_free_immediate( struct immediate *im );
320
321extern struct vertex_buffer *gl_vb_create_for_immediate( GLcontext *ctx );
322extern struct vertex_buffer *gl_vb_create_for_cva( GLcontext *ctx,
323 GLuint size );
324extern void gl_vb_free( struct vertex_buffer * );
325extern struct immediate *gl_immediate_alloc( GLcontext *ctx );
326extern void gl_immediate_free( struct immediate *im );
327
328
329#endif
330
Note: See TracBrowser for help on using the repository browser.