Compute attenuated point size in a new pipeline stage.
[mesa.git] / src / mesa / tnl / t_context.h
1
2 /* $Id: t_context.h,v 1.6 2000/12/08 00:18:39 brianp Exp $ */
3
4 /*
5 * Mesa 3-D graphics library
6 * Version: 3.5
7 *
8 * Copyright (C) 1999 Brian Paul All Rights Reserved.
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
24 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 */
27
28 #ifndef _T_CONTEXT_H
29 #define _T_CONTEXT_H
30
31 #include "glheader.h"
32 #include "mtypes.h"
33
34 #include "math/m_matrix.h"
35 #include "math/m_vector.h"
36 #include "math/m_xform.h"
37
38 #include "t_trans_elt.h"
39
40
41
42 /*
43 * Bits to indicate which faces a vertex participates in,
44 * what facing the primitive provoked by that vertex has,
45 * and some misc. flags.
46 */
47 #define VERT_FACE_FRONT 0x1 /* is in a front-color primitive */
48 #define VERT_FACE_REAR 0x2 /* is in a rear-color primitive */
49 #define PRIM_FACE_FRONT 0x4 /* use front color */
50 #define PRIM_FACE_REAR 0x8 /* use rear color */
51 #define PRIM_CLIPPED 0x10 /* needs clipping */
52 #define PRIM_USER_CLIPPED CLIP_USER_BIT /* 0x40 */
53
54
55 #define PRIM_FLAG_SHIFT 2
56 #define PRIM_FACE_FLAGS (PRIM_FACE_FRONT|PRIM_FACE_REAR)
57 #define VERT_FACE_FLAGS (VERT_FACE_FRONT|VERT_FACE_REAR)
58
59 #define PRIM_ANY_CLIP (PRIM_CLIPPED|PRIM_USER_CLIPPED)
60 #define PRIM_NOT_CULLED (PRIM_ANY_CLIP|PRIM_FACE_FLAGS)
61
62 /* Flags for VB->CullMode.
63 */
64 #define CULL_MASK_ACTIVE 0x1
65 #define COMPACTED_NORMALS 0x2
66 #define CLIP_MASK_ACTIVE 0x4
67
68 /* Flags for selecting a shading function. The first two bits are
69 * shared with the cull mode (ie. cull_mask_active and
70 * compacted_normals.)
71 */
72 #define SHADE_TWOSIDE 0x4
73
74
75 /* KW: Flags that describe the current vertex state, and the contents
76 * of a vertex in a vertex-cassette.
77 *
78 * For really major expansion, consider a 'VERT_ADDITIONAL_FLAGS' flag,
79 * which means there is data in another flags array (eg, extra_flags[]).
80 */
81
82 #define VERT_OBJ_2 0x1 /* glVertex2 */
83 #define VERT_OBJ_3 0x2 /* glVertex3 */
84 #define VERT_OBJ_4 0x4 /* glVertex4 */
85 #define VERT_BEGIN 0x8 /* glBegin */
86 #define VERT_END 0x10 /* glEnd */
87 #define VERT_ELT 0x20 /* glArrayElement */
88 #define VERT_RGBA 0x40 /* glColor */
89 #define VERT_NORM 0x80 /* glNormal */
90 #define VERT_INDEX 0x100 /* glIndex */
91 #define VERT_EDGE 0x200 /* glEdgeFlag */
92 #define VERT_MATERIAL 0x400 /* glMaterial */
93 #define VERT_END_VB 0x800 /* end vb marker */
94 #define VERT_TEX0 0x1000
95 #define VERT_TEX1 0x2000
96 #define VERT_TEX2 0x3000
97 #define VERT_TEX3 0x4000
98 #define VERT_TEX4 0x10000
99 #define VERT_TEX5 0x20000
100 #define VERT_TEX6 0x30000
101 #define VERT_TEX7 0x40000
102 #define VERT_TEX8 0x100000
103 #define VERT_TEX9 0x200000
104 #define VERT_TEX10 0x300000
105 #define VERT_TEX11 0x400000
106 #define VERT_EVAL_C1 0x1000000 /* could reuse OBJ bits for this? */
107 #define VERT_EVAL_C2 0x2000000 /* - or just use 3 bits */
108 #define VERT_EVAL_P1 0x4000000 /* */
109 #define VERT_EVAL_P2 0x8000000 /* */
110 #define VERT_SPEC_RGB 0x10000000
111 #define VERT_FOG_COORD 0x20000000
112 #define VERT_POINT_SIZE 0x40000000
113
114 #define VERT_EYE VERT_BEGIN /* reuse */
115 #define VERT_WIN VERT_END /* reuse */
116 #define VERT_SETUP_FULL VERT_EVAL_P1 /* Rastersetup has been done */
117 #define VERT_PRECALC_DATA VERT_END_VB /* reuse */
118
119 /* Shorthands.
120 */
121
122 #define VERT_EVAL_ANY (VERT_EVAL_C1|VERT_EVAL_P1| \
123 VERT_EVAL_C2|VERT_EVAL_P2)
124
125 #define VERT_OBJ_23 (VERT_OBJ_3|VERT_OBJ_2)
126 #define VERT_OBJ_234 (VERT_OBJ_4|VERT_OBJ_23)
127 #define VERT_OBJ_ANY VERT_OBJ_2
128
129 #define VERT_TEX0_SHIFT 11
130 #define VERT_TEX(i) (VERT_TEX0 << i)
131 #define VERT_TEX_ANY (VERT_TEX0 | \
132 VERT_TEX1 | \
133 VERT_TEX2 | \
134 VERT_TEX3 | \
135 VERT_TEX4 | \
136 VERT_TEX5 | \
137 VERT_TEX6 | \
138 VERT_TEX7 | \
139 VERT_TEX8 | \
140 VERT_TEX9 | \
141 VERT_TEX10 | \
142 VERT_TEX11)
143
144 #define VERT_FIXUP (VERT_TEX_ANY | \
145 VERT_RGBA | \
146 VERT_SPEC_RGB | \
147 VERT_FOG_COORD | \
148 VERT_INDEX | \
149 VERT_EDGE | \
150 VERT_NORM)
151
152 #define VERT_DATA (VERT_TEX_ANY | \
153 VERT_RGBA | \
154 VERT_SPEC_RGB | \
155 VERT_FOG_COORD | \
156 VERT_INDEX | \
157 VERT_EDGE | \
158 VERT_NORM | \
159 VERT_OBJ_ANY | \
160 VERT_MATERIAL | \
161 VERT_ELT | \
162 VERT_EVAL_ANY | \
163 VERT_FOG_COORD)
164
165
166
167
168 struct gl_pipeline;
169 struct tnl_context;
170
171 /**
172 ** Vertex buffer/array structures
173 **/
174
175 struct vertex_data
176 {
177 GLfloat (*Obj)[4];
178 GLfloat (*Normal)[3];
179 GLchan (*Color)[4];
180 GLuint *Index;
181 GLubyte *EdgeFlag;
182 GLfloat (*TexCoord[MAX_TEXTURE_UNITS])[4];
183 GLuint *Elt;
184 GLfloat *FogCoord;
185 GLubyte (*SecondaryColor)[4];
186 };
187
188 struct vertex_arrays
189 {
190 GLvector4f Obj;
191 GLvector3f Normal;
192 GLvector4ub Color;
193 GLvector1ui Index;
194 GLvector1ub EdgeFlag;
195 GLvector4f TexCoord[MAX_TEXTURE_UNITS];
196 GLvector1ui Elt;
197 GLvector4ub SecondaryColor;
198 GLvector1f FogCoord;
199 };
200
201 struct vertex_array_pointers
202 {
203 GLvector4f *Obj;
204 GLvector3f *Normal;
205 GLvector4ub *Color;
206 GLvector1ui *Index;
207 GLvector1ub *EdgeFlag;
208 GLvector4f *TexCoord[MAX_TEXTURE_UNITS];
209 GLvector1ui *Elt;
210 GLvector4ub *SecondaryColor;
211 GLvector1f *FogCoord;
212 };
213
214 /* Values for VB->Type */
215 enum {
216 VB_IMMEDIATE,
217 VB_CVA_PRECALC
218 };
219
220
221 /* Values for immediate->BeginState */
222 #define VERT_BEGIN_0 0x1 /* glBegin (if initially inside beg/end) */
223 #define VERT_BEGIN_1 0x2 /* glBegin (if initially outside beg/end) */
224 #define VERT_ERROR_0 0x4 /* invalid_operation in initial state 0 */
225 #define VERT_ERROR_1 0x8 /* invalid_operation in initial state 1 */
226
227 /* KW: Represents everything that can take place between a begin and
228 * end, and can represent multiple begin/end pairs. This plus *any*
229 * state variable (GLcontext) should be all you need to replay the
230 * represented begin/end pairs as if they took place in that state.
231 *
232 * Thus this is sufficient for both immediate and compiled modes, but
233 * we could/should throw some elements away for compiled mode if we
234 * know they were empty.
235 */
236 struct immediate
237 {
238 struct immediate *next; /* for cache of free IM's */
239 GLuint id, ref_count;
240
241 /* This must be saved when immediates are shared in display lists.
242 */
243 GLuint Start, Count;
244 GLuint LastData; /* count or count+1 */
245 GLuint AndFlag, OrFlag;
246 GLuint Tex3Flag, Tex4Flag; /* keep track of texcoord sizes */
247 GLuint BeginState, SavedBeginState;
248 GLuint LastPrimitive;
249
250 GLuint ArrayAndFlags; /* precalc'ed for glArrayElt */
251 GLuint ArrayIncr;
252 GLuint ArrayEltFlush;
253 GLuint FlushElt;
254
255 GLuint Primitive[VB_SIZE]; /* GLubyte would do... */
256 GLuint NextPrimitive[VB_SIZE];
257
258 /* allocate storage for these on demand:
259 */
260 struct gl_material (*Material)[2];
261 GLuint *MaterialMask;
262
263 GLfloat (*TexCoordPtr[MAX_TEXTURE_UNITS])[4];
264
265 struct vertex_arrays v;
266
267 struct __GLcontextRec *backref;
268
269 /* Normal lengths, zero if not available.
270 */
271 GLfloat *NormalLengths;
272 GLuint LastCalcedLength;
273
274 GLuint Flag[VB_SIZE]; /* bitwise-OR of VERT_ flags */
275 GLchan Color[VB_SIZE][4];
276 GLfloat Obj[VB_SIZE][4];
277 GLfloat Normal[VB_SIZE][3];
278 GLfloat TexCoord[MAX_TEXTURE_UNITS][VB_SIZE][4];
279 GLuint Elt[VB_SIZE];
280 GLubyte EdgeFlag[VB_SIZE];
281 GLuint Index[VB_SIZE];
282 GLubyte SecondaryColor[VB_SIZE][4];
283 GLfloat FogCoord[VB_SIZE];
284 };
285
286
287 /* Not so big on storage these days, although still has pointers to
288 * arrays used for temporary results.
289 */
290 typedef struct vertex_buffer
291 {
292 /* Backpointers.
293 */
294 struct __GLcontextRec *ctx;
295 struct tnl_context *tnlctx;
296
297 /* Driver_data is allocated in Driver.RegisterVB(), if required.
298 */
299 void *driver_data;
300
301 /* List of operations to process vertices in current state.
302 */
303 struct gl_pipeline *pipeline;
304
305 /* Temporary storage used by immediate mode functions and various
306 * operations in the pipeline.
307 */
308 struct immediate *IM;
309 struct vertex_array_pointers store;
310
311 /* Where to find outstanding untransformed vertices.
312 */
313 struct immediate *prev_buffer;
314
315 GLuint Type; /* Either VB_IMMEDIATE or VB_CVA_PRECALC */
316
317 GLuint Size, Start, Count;
318 GLuint Free, FirstFree;
319 GLuint CopyStart;
320 GLuint Parity, Ovf;
321 GLuint PurgeFlags;
322 GLuint IndirectCount; /* defaults to count */
323 GLuint OrFlag, SavedOrFlag;
324 GLuint Tex3Flag, Tex4Flag;
325 GLuint SavedTex3Flag, SavedTex4Flag;
326 GLuint EarlyCull;
327 GLuint Culled, CullDone;
328
329 /* Pointers to input data - default to buffers in 'im' above.
330 */
331 GLvector4f *ObjPtr;
332 GLvector3f *NormalPtr;
333 GLvector4ub *ColorPtr;
334 GLvector1ui *IndexPtr;
335 GLvector1ub *EdgeFlagPtr;
336 GLvector4f *TexCoordPtr[MAX_TEXTURE_UNITS];
337 GLvector1ui *EltPtr;
338 GLvector4ub *SecondaryColorPtr;
339 GLvector1f *FogCoordPtr;
340 GLuint *Flag, FlagMax;
341 struct gl_material (*Material)[2];
342 GLuint *MaterialMask;
343
344 GLuint *NextPrimitive;
345 GLuint *Primitive;
346 GLuint LastPrimitive;
347
348 GLfloat (*BoundsPtr)[3]; /* Bounds for cull check */
349 GLfloat *NormalLengthPtr; /* Array of precomputed inv. normal lengths */
350
351 /* Holds malloced storage for pipeline data not supplied by
352 * the immediate struct.
353 */
354 GLvector4f Eye;
355 GLvector4f Clip;
356 GLvector4f Win;
357 GLvector1f PointSize;
358 GLvector4ub BColor; /* not used in cva vb's */
359 GLvector1ui BIndex; /* not used in cva vb's */
360 GLvector4ub BSecondary; /* not used in cva vb's */
361
362 /* Temporary storage - may point into IM, or be dynamically
363 * allocated (for cva).
364 */
365 GLubyte *ClipMask;
366 GLubyte *UserClipMask;
367
368 /* Internal values. Where these point depends on whether
369 * there were any identity matrices defined as transformations
370 * in the pipeline.
371 */
372 GLvector4f *EyePtr;
373 GLvector4f *ClipPtr;
374 GLvector4f *Unprojected;
375 GLvector4f *Projected;
376 GLvector4f *CurrentTexCoord;
377 GLuint *Indirect; /* For eval rescue and cva render */
378
379 /* Currently active colors
380 */
381 GLvector4ub *Color[2];
382 GLvector1ui *Index[2];
383 GLvector4ub *SecondaryColor[2];
384
385 /* Storage for colors which have been lit but not yet fogged.
386 * Required for CVA, just point into store for normal VB's.
387 */
388 GLvector4ub *LitColor[2];
389 GLvector1ui *LitIndex[2];
390 GLvector4ub *LitSecondary[2];
391
392 /* Temporary values used in texgen.
393 */
394 GLfloat (*tmp_f)[3];
395 GLfloat *tmp_m;
396
397 /* Temporary values used in eval.
398 */
399 GLuint *EvaluatedFlags;
400
401 /* Not used for cva:
402 */
403 GLubyte *NormCullStart;
404 GLubyte *CullMask; /* Results of vertex culling */
405 GLubyte *NormCullMask; /* Compressed onto shared normals */
406
407 GLubyte ClipOrMask; /* bitwise-OR of all ClipMask[] values */
408 GLubyte ClipAndMask; /* bitwise-AND of all ClipMask[] values */
409 GLubyte CullFlag[2];
410 GLubyte CullMode; /* see flags below */
411
412 GLuint CopyCount; /* max 3 vertices to copy after transform */
413 GLuint Copy[3];
414 GLfloat CopyProj[3][4]; /* temporary store for projected clip coords */
415
416 /* Hooks for module private data
417 */
418 void *swsetup_vb;
419
420 } TNLvertexbuffer;
421
422
423 typedef void (*shade_func)( struct vertex_buffer *VB );
424
425 typedef void (*clip_interp_func)( struct vertex_buffer *VB, GLuint dst,
426 GLfloat t, GLuint in, GLuint out );
427
428 typedef GLuint (*clip_line_func)( struct vertex_buffer *VB,
429 GLuint *i, GLuint *j,
430 GLubyte mask);
431
432 typedef GLuint (*clip_poly_func)( struct vertex_buffer *VB,
433 GLuint n, GLuint vlist[],
434 GLubyte mask );
435
436
437 #define MAX_PIPELINE_STAGES 30
438
439 #define PIPE_IMMEDIATE 0x1
440 #define PIPE_PRECALC 0x2
441
442 #define PIPE_OP_VERT_XFORM 0x1
443 #define PIPE_OP_NORM_XFORM 0x2
444 #define PIPE_OP_LIGHT 0x4
445 #define PIPE_OP_FOG 0x8
446 #define PIPE_OP_TEX 0x10
447 #define PIPE_OP_RAST_SETUP_0 0x100
448 #define PIPE_OP_RAST_SETUP_1 0x200
449 #define PIPE_OP_RENDER 0x400
450 #define PIPE_OP_CVA_PREPARE 0x800
451 #define PIPE_OP_POINT_SIZE 0x1000
452
453
454 struct gl_pipeline_stage {
455 const char *name;
456 GLuint ops; /* PIPE_OP flags */
457 GLuint type; /* VERT flags */
458 GLuint special; /* VERT flags - force update_inputs() */
459 GLuint state_change; /* state flags - trigger update_inputs() */
460 GLuint cva_state_change; /* state flags - recalc cva buffer */
461 GLuint elt_forbidden_inputs; /* VERT flags - force a pipeline recalc */
462 GLuint pre_forbidden_inputs; /* VERT flags - force a pipeline recalc */
463 GLuint active; /* VERT flags */
464 GLuint inputs; /* VERT flags */
465 GLuint outputs; /* VERT flags */
466 void (*check)( GLcontext *ctx, struct gl_pipeline_stage * );
467 void (*run)( struct vertex_buffer *VB );
468 };
469
470
471 struct gl_pipeline {
472 GLuint state_change; /* state changes which require recalc */
473 GLuint cva_state_change; /* ... which require re-run */
474 GLuint forbidden_inputs; /* inputs which require recalc */
475 GLuint ops; /* what gets done in this pipe */
476 GLuint changed_ops;
477 GLuint inputs;
478 GLuint outputs;
479 GLuint new_inputs;
480 GLuint new_outputs;
481 GLuint fallback;
482 GLuint type;
483 GLuint pipeline_valid:1;
484 GLuint data_valid:1;
485 GLuint copy_transformed_data:1;
486 GLuint replay_copied_vertices:1;
487 GLuint new_state; /* state changes since last recalc */
488 struct gl_pipeline_stage *stages[MAX_PIPELINE_STAGES];
489 };
490
491
492
493 /* All fields are derived.
494 */
495 struct gl_cva {
496 struct gl_pipeline pre;
497 struct gl_pipeline elt;
498
499 struct gl_client_array Elt;
500 trans_1ui_func EltFunc;
501
502 struct vertex_buffer *VB;
503 struct vertex_arrays v;
504 struct vertex_data store;
505
506 GLuint elt_count;
507 GLenum elt_mode;
508 GLuint elt_size;
509
510 GLuint forbidden_inputs;
511 GLuint orflag;
512 GLuint merge;
513
514 GLuint locked;
515 GLuint lock_changed;
516 GLuint last_orflag;
517 GLuint last_array_flags;
518 GLuint last_array_new_state;
519 };
520
521 /* These are used to make the ctx->Current values look like
522 * arrays (with zero StrideB).
523 */
524 struct gl_fallback_arrays {
525 struct gl_client_array Normal;
526 struct gl_client_array Color;
527 struct gl_client_array SecondaryColor;
528 struct gl_client_array FogCoord;
529 struct gl_client_array Index;
530 struct gl_client_array TexCoord[MAX_TEXTURE_UNITS];
531 struct gl_client_array EdgeFlag;
532 };
533
534
535
536 typedef void (*texgen_func)( struct vertex_buffer *VB,
537 GLuint textureSet);
538
539
540
541 typedef struct tnl_context {
542
543 GLuint _ArrayFlag[VB_SIZE]; /* crock */
544 GLuint _ArrayFlags;
545 GLuint _ArraySummary; /* Like flags, but no size information */
546 GLuint _ArrayNewState; /* Tracks which arrays have been changed. */
547 GLuint _ArrayTex3Flag;
548 GLuint _ArrayTex4Flag;
549
550
551 /* Pipeline stages - shared between the two pipelines,
552 * which live in CVA.
553 */
554 struct gl_pipeline_stage PipelineStage[MAX_PIPELINE_STAGES];
555 GLuint NrPipelineStages;
556
557 /* Per-texunit derived state.
558 */
559 GLuint _TexgenSize[MAX_TEXTURE_UNITS];
560 GLuint _TexgenHoles[MAX_TEXTURE_UNITS];
561 texgen_func *_TexgenFunc[MAX_TEXTURE_UNITS];
562
563
564 /* Display list extensions
565 */
566 GLuint opcode_vertex_cassette;
567
568 /* Cva
569 */
570 struct gl_cva CVA;
571 GLboolean CompileCVAFlag;
572
573 clip_poly_func *_poly_clip_tab;
574 clip_line_func *_line_clip_tab;
575 clip_interp_func _ClipInterpFunc; /* Clip interpolation function */
576 normal_func *_NormalTransform;
577 shade_func *_shade_func_tab; /* Current shading function table */
578
579 GLenum _CurrentPrimitive; /* Prim or GL_POLYGON+1 */
580 GLuint _CurrentTex3Flag;
581 GLuint _CurrentTex4Flag;
582
583 GLboolean _ReplayHardBeginEnd; /* Display list execution of rect, etc */
584
585 GLuint _RenderFlags; /* Active inputs to render stage */
586
587 /* Cache of unused immediate structs */
588 struct immediate *freed_im_queue;
589 GLuint nr_im_queued;
590
591 struct gl_fallback_arrays Fallback;
592
593 GLvertexformat vtxfmt;
594
595 } TNLcontext;
596
597
598
599 #define TNL_CONTEXT(ctx) ((TNLcontext *)(ctx->swtnl_context))
600 #define TNL_CURRENT_IM(ctx) ((struct immediate *)(ctx->swtnl_im))
601 #define TNL_VB(ctx) ((struct vertex_buffer *)(ctx->swtnl_vb))
602
603 extern GLboolean _tnl_flush_vertices( GLcontext *ctx, GLuint flush_flags );
604
605
606 extern void
607 _tnl_MakeCurrent( GLcontext *ctx,
608 GLframebuffer *drawBuffer,
609 GLframebuffer *readBuffer );
610
611
612 extern void
613 _tnl_LightingSpaceChange( GLcontext *ctx );
614
615 /*
616 * Macros for fetching current input buffer.
617 */
618 #ifdef THREADS
619 #define GET_IMMEDIATE struct immediate *IM = TNL_CURRENT_IM(((GLcontext *) (_glapi_Context ? _glapi_Context : _glapi_get_context())))
620 #define SET_IMMEDIATE(ctx, im) ctx->swtnl_im = (void *)im
621 #else
622 extern struct immediate *_tnl_CurrentInput;
623 #define GET_IMMEDIATE struct immediate *IM = _tnl_CurrentInput
624 #define SET_IMMEDIATE(ctx, im) \
625 do { \
626 ctx->swtnl_im = (void *)im; \
627 _tnl_CurrentInput = im; \
628 } while (0)
629 #endif
630
631 #endif