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

Last change on this file since 2961 was 2938, checked in by sandervl, 25 years ago

created

File size: 8.9 KB
Line 
1/* $Id: vb.h,v 1.1 2000-02-29 00:48:42 sandervl Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.1
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 "gl.h"
57#include "vector.h"
58#include "matrix.h"
59#include "config.h"
60
61
62enum {
63 VB_IMMEDIATE,
64 VB_CVA_PRECALC
65};
66
67
68
69/*
70 */
71struct vertex_data
72{
73 GLfloat (*Obj)[4];
74 GLfloat (*Normal)[3];
75 GLubyte (*Color)[4];
76 GLuint *Index;
77 GLubyte *EdgeFlag;
78 GLfloat (*TexCoord[MAX_TEXTURE_UNITS])[4];
79 GLuint *Elt;
80};
81
82struct vertex_arrays
83{
84 GLvector4f Obj;
85 GLvector3f Normal;
86 GLvector4ub Color;
87 GLvector1ui Index;
88 GLvector1ub EdgeFlag;
89 GLvector4f TexCoord[MAX_TEXTURE_UNITS];
90 GLvector1ui Elt;
91};
92
93struct vertex_array_pointers
94{
95 GLvector4f *Obj;
96 GLvector3f *Normal;
97 GLvector4ub *Color;
98 GLvector1ui *Index;
99 GLvector1ub *EdgeFlag;
100 GLvector4f *TexCoord[MAX_TEXTURE_UNITS];
101 GLvector1ui *Elt;
102};
103
104
105/* Move to using pointers to this struct in the immediate structs -
106 * this is too big to keep 94 unused copies (7K) lying around in
107 * display lists.
108 */
109struct gl_material
110{
111 GLfloat Ambient[4];
112 GLfloat Diffuse[4];
113 GLfloat Specular[4];
114 GLfloat Emission[4];
115 GLfloat Shininess;
116 GLfloat AmbientIndex; /* for color index lighting */
117 GLfloat DiffuseIndex; /* for color index lighting */
118 GLfloat SpecularIndex; /* for color index lighting */
119};
120
121
122/* KW: Represents everything that can take place between a begin and
123 * end, and can represent multiple begin/end pairs. This plus *any*
124 * state variable (GLcontext) should be all you need to replay the
125 * represented begin/end pairs as if they took place in that state.
126 *
127 * Thus this is sufficient for both immediate and compiled modes, but
128 * we could/should throw some elements away for compiled mode if we
129 * know they were empty.
130 */
131struct immediate
132{
133 struct immediate *next; /* for cache of free IM's */
134 GLuint id, ref_count;
135
136 /* This must be saved when immediates are shared in display lists.
137 */
138 GLuint Start, Count;
139 GLuint LastData; /* count or count+1 */
140 GLuint AndFlag, OrFlag, BeginState;
141 GLuint LastPrimitive;
142
143 GLuint ArrayAndFlags; /* precalc'ed for glArrayElt */
144 GLuint ArrayIncr;
145 GLuint ArrayEltFlush;
146 GLuint FlushElt;
147
148 GLuint TF1[2]; /* precalc'ed for glTexCoord */
149 GLuint TF2[2];
150 GLuint TF3[2];
151 GLuint TF4[2];
152
153 GLuint Primitive[VB_SIZE]; /* GLubyte would do... */
154 GLuint NextPrimitive[VB_SIZE];
155
156 /* allocate storage for these on demand:
157 */
158 struct gl_material (*Material)[2];
159 GLuint *MaterialMask;
160
161 GLfloat (*TexCoordPtr[MAX_TEXTURE_UNITS])[4];
162
163 struct vertex_arrays v;
164
165 struct gl_context *backref;
166 void (*maybe_transform_vb)( struct immediate * );
167
168 /* Normal lengths, zero if not available.
169 */
170 GLfloat *NormalLengths;
171 GLuint LastCalcedLength;
172
173 GLuint Flag[VB_SIZE];
174 GLubyte Color[VB_SIZE][4];
175 GLfloat Obj[VB_SIZE][4];
176 GLfloat Normal[VB_SIZE][3];
177 GLfloat TexCoord[MAX_TEXTURE_UNITS][VB_SIZE][4];
178 GLuint Elt[VB_SIZE];
179 GLubyte EdgeFlag[VB_SIZE];
180 GLuint Index[VB_SIZE];
181};
182
183
184
185
186/* Not so big on storage these days, although still has pointers to
187 * arrays used for temporary results.
188 */
189struct vertex_buffer
190{
191 /* Pointers to enable multiple vertex_buffers - required for
192 * CVA, should also be useful for the PMesa people.
193 *
194 * Driver_data is alloc'ed in Driver.RegisterVB(), if required.
195 */
196 struct gl_context *ctx;
197 struct gl_pipeline *pipeline;
198 void *driver_data;
199
200
201 /* Data easily accessible by immediate mode fuctions: There is no
202 * guarentee on the driver side that processed data will end up or
203 * even pass through here. Use the GLvector pointers below.
204 *
205 * If we are not compiling, ctx->input points to this struct, in which
206 * case the values will be scribbled during transform_vb.
207 */
208 struct immediate *IM;
209 struct vertex_array_pointers store;
210
211 /* Where to find outstanding untransformed vertices.
212 */
213 struct immediate *prev_buffer;
214
215
216 GLuint Type;
217 GLuint Size, Start, Count;
218 GLuint Free, FirstFree;
219 GLuint CopyStart;
220 GLuint Parity, Ovf;
221 GLuint PurgeFlags;
222 GLuint IndirectCount; /* defaults to count */
223 GLuint OrFlag, SavedOrFlag;
224 GLuint EarlyCull;
225 GLuint Culled, CullDone;
226
227 /* Pointers to input data - default to buffers in 'im' above.
228 */
229 GLvector4f *ObjPtr;
230 GLvector3f *NormalPtr;
231 GLvector4ub *ColorPtr;
232 GLvector1ui *IndexPtr;
233 GLvector1ub *EdgeFlagPtr;
234 GLvector4f *TexCoordPtr[MAX_TEXTURE_UNITS];
235 GLvector1ui *EltPtr;
236 GLuint *Flag, FlagMax;
237 struct gl_material (*Material)[2];
238 GLuint *MaterialMask;
239
240 GLuint *NextPrimitive;
241 GLuint *Primitive;
242 GLuint LastPrimitive;
243
244 GLfloat (*BoundsPtr)[3]; /* Bounds for cull check */
245 GLfloat *NormalLengthPtr; /* Array of precomputed inv. normal lengths */
246
247
248 /* Holds malloced storage for pipeline data not supplied by
249 * the immediate struct.
250 */
251 GLvector4f Eye;
252 GLvector4f Clip;
253 GLvector4f Win;
254 GLvector4ub BColor; /* not used in cva */
255 GLvector1ui BIndex; /* not used in cva */
256 GLubyte (*Specular)[4];
257 GLubyte (*Spec[2])[4];
258
259 /* Temporary storage - may point into IM, or be dynamically
260 * allocated (for cva).
261 */
262 GLubyte *ClipMask;
263 GLubyte *UserClipMask;
264
265 /* Internal values. Where these point depends on whether
266 * there were any identity matrices defined as transformations
267 * in the pipeline.
268 */
269 GLvector4f *EyePtr;
270 GLvector4f *ClipPtr;
271 GLvector4f *Unprojected;
272 GLvector4f *Projected;
273 GLvector4f *CurrentTexCoord;
274 GLuint *Indirect; /* For eval rescue and cva render */
275
276
277 /* Currently active colors
278 */
279 GLvector4ub *Color[2];
280 GLvector1ui *Index[2];
281
282 /* Storage for colors which have been lit but not yet fogged.
283 * Required for CVA, just point into store for normal VB's.
284 */
285 GLvector4ub *LitColor[2];
286 GLvector1ui *LitIndex[2];
287 GLvector4ub *FoggedColor[2];
288 GLvector1ui *FoggedIndex[2];
289
290
291 /* Temporary values used in texgen.
292 */
293 GLfloat (*tmp_f)[3];
294 GLfloat *tmp_m;
295
296 /* Temporary values used in eval.
297 */
298 GLuint *EvaluatedFlags;
299
300 /* Not used for cva:
301 */
302 GLubyte *NormCullStart;
303 GLubyte *CullMask; /* Results of vertex culling */
304 GLubyte *NormCullMask; /* Compressed onto shared normals */
305
306
307 GLubyte ClipOrMask; /* bitwise-OR of all ClipMask[] values */
308 GLubyte ClipAndMask; /* bitwise-AND of all ClipMask[] values */
309 GLubyte CullFlag[2];
310 GLubyte CullMode; /* see flags below */
311
312 GLuint CopyCount; /* max 3 vertices to copy after transform */
313 GLuint Copy[3];
314 GLfloat CopyProj[3][4]; /* temporary store for projected clip coords */
315};
316
317
318extern struct vertex_buffer *gl_alloc_vb( GLcontext *ctx );
319extern struct immediate *gl_alloc_immediate( GLcontext *ctx );
320extern void gl_free_immediate( struct immediate *im );
321
322extern struct vertex_buffer *gl_vb_create_for_immediate( GLcontext *ctx );
323extern struct vertex_buffer *gl_vb_create_for_cva( GLcontext *ctx,
324 GLuint size );
325extern void gl_vb_free( struct vertex_buffer * );
326extern struct immediate *gl_immediate_alloc( GLcontext *ctx );
327extern void gl_immediate_free( struct immediate *im );
328
329
330#endif
331
Note: See TracBrowser for help on using the repository browser.