Clean up clipping somewhat
[mesa.git] / src / mesa / tnl / t_context.h
1 /*
2 * mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file t_context.h
27 * \brief TnL module datatypes and definitions.
28 * \author Keith Whitwell
29 */
30
31
32 /**
33 * \mainpage The TNL-module
34 *
35 * TNL stands for "transform and lighting", i.e. this module implements
36 * a pipeline that receives as input a buffer of vertices and does all
37 * necessary transformations (rotations, clipping, vertex shader etc.)
38 * and passes then the output to the rasterizer.
39 *
40 * The tnl_pipeline contains the array of all stages, which should be
41 * applied. Each stage is a black-box, which is described by an
42 * tnl_pipeline_stage. The function ::_tnl_run_pipeline applies all the
43 * stages to the vertex_buffer TNLcontext::vb, where the vertex data
44 * is stored. The last stage in the pipeline is the rasterizer.
45 *
46 * The initial vertex_buffer data may either come from an ::immediate
47 * structure or client vertex_arrays or display lists:
48 *
49 *
50 * - The ::immediate structure records all the GL commands issued between
51 * glBegin and glEnd. \n
52 * The structure accumulates data, until it is either full or it is
53 * flushed (usually by a state change). Before starting then the pipeline,
54 * the collected vertex data in ::immediate has to be pushed into
55 * TNLcontext::vb.
56 * This happens in ::_tnl_vb_bind_immediate. The pipeline is then run by
57 * calling tnl_device_driver::RunPipeline = ::_tnl_run_pipeline, which
58 * is stored in TNLcontext::Driver. \n
59 * An ::immediate does (for performance reasons) usually not finish with a
60 * glEnd, and hence it also does not need to start with a glBegin.
61 * This means that the last vertices of one ::immediate may need to be
62 * saved for the next one.
63 *
64 *
65 * - NOT SURE ABOUT THIS: The vertex_arrays structure is used to handle
66 * glDrawArrays etc. \n
67 * Here, the data of the vertex_arrays is copied by ::_tnl_vb_bind_arrays
68 * into TNLcontext::vb, so that the pipeline can be started.
69 */
70
71
72 #ifndef _T_CONTEXT_H
73 #define _T_CONTEXT_H
74
75 #include "glheader.h"
76 #include "mtypes.h"
77
78 #include "math/m_matrix.h"
79 #include "math/m_vector.h"
80 #include "math/m_xform.h"
81
82
83 #define MAX_PIPELINE_STAGES 30
84
85 /*
86 * Note: The first attributes match the VERT_ATTRIB_* definitions
87 * in mtypes.h. However, the tnl module has additional attributes
88 * for materials, color indexes, edge flags, etc.
89 */
90 /* Although it's nice to use these as bit indexes in a DWORD flag, we
91 * could manage without if necessary. Another limit currently is the
92 * number of bits allocated for these numbers in places like vertex
93 * program instruction formats and register layouts.
94 */
95 enum {
96 _TNL_ATTRIB_POS = 0,
97 _TNL_ATTRIB_WEIGHT = 1,
98 _TNL_ATTRIB_NORMAL = 2,
99 _TNL_ATTRIB_COLOR0 = 3,
100 _TNL_ATTRIB_COLOR1 = 4,
101 _TNL_ATTRIB_FOG = 5,
102 _TNL_ATTRIB_SIX = 6,
103 _TNL_ATTRIB_SEVEN = 7,
104 _TNL_ATTRIB_TEX0 = 8,
105 _TNL_ATTRIB_TEX1 = 9,
106 _TNL_ATTRIB_TEX2 = 10,
107 _TNL_ATTRIB_TEX3 = 11,
108 _TNL_ATTRIB_TEX4 = 12,
109 _TNL_ATTRIB_TEX5 = 13,
110 _TNL_ATTRIB_TEX6 = 14,
111 _TNL_ATTRIB_TEX7 = 15,
112 _TNL_ATTRIB_MAT_FRONT_AMBIENT = 16,
113 _TNL_ATTRIB_MAT_BACK_AMBIENT = 17,
114 _TNL_ATTRIB_MAT_FRONT_DIFFUSE = 18,
115 _TNL_ATTRIB_MAT_BACK_DIFFUSE = 19,
116 _TNL_ATTRIB_MAT_FRONT_SPECULAR = 20,
117 _TNL_ATTRIB_MAT_BACK_SPECULAR = 21,
118 _TNL_ATTRIB_MAT_FRONT_EMISSION = 22,
119 _TNL_ATTRIB_MAT_BACK_EMISSION = 23,
120 _TNL_ATTRIB_MAT_FRONT_SHININESS = 24,
121 _TNL_ATTRIB_MAT_BACK_SHININESS = 25,
122 _TNL_ATTRIB_MAT_FRONT_INDEXES = 26,
123 _TNL_ATTRIB_MAT_BACK_INDEXES = 27,
124 _TNL_ATTRIB_INDEX = 28,
125 _TNL_ATTRIB_EDGEFLAG = 29,
126 _TNL_ATTRIB_POINTSIZE = 30,
127 _TNL_ATTRIB_MAX = 31
128 } ;
129
130 /* Will probably have to revise this scheme fairly shortly, eg. by
131 * compacting all the MAT flags down to one bit, or by using two
132 * dwords to store the flags.
133 */
134 #define _TNL_BIT_POS (1<<0)
135 #define _TNL_BIT_WEIGHT (1<<1)
136 #define _TNL_BIT_NORMAL (1<<2)
137 #define _TNL_BIT_COLOR0 (1<<3)
138 #define _TNL_BIT_COLOR1 (1<<4)
139 #define _TNL_BIT_FOG (1<<5)
140 #define _TNL_BIT_SIX (1<<6)
141 #define _TNL_BIT_SEVEN (1<<7)
142 #define _TNL_BIT_TEX0 (1<<8)
143 #define _TNL_BIT_TEX1 (1<<9)
144 #define _TNL_BIT_TEX2 (1<<10)
145 #define _TNL_BIT_TEX3 (1<<11)
146 #define _TNL_BIT_TEX4 (1<<12)
147 #define _TNL_BIT_TEX5 (1<<13)
148 #define _TNL_BIT_TEX6 (1<<14)
149 #define _TNL_BIT_TEX7 (1<<15)
150 #define _TNL_BIT_MAT_FRONT_AMBIENT (1<<16)
151 #define _TNL_BIT_MAT_BACK_AMBIENT (1<<17)
152 #define _TNL_BIT_MAT_FRONT_DIFFUSE (1<<18)
153 #define _TNL_BIT_MAT_BACK_DIFFUSE (1<<19)
154 #define _TNL_BIT_MAT_FRONT_SPECULAR (1<<20)
155 #define _TNL_BIT_MAT_BACK_SPECULAR (1<<21)
156 #define _TNL_BIT_MAT_FRONT_EMISSION (1<<22)
157 #define _TNL_BIT_MAT_BACK_EMISSION (1<<23)
158 #define _TNL_BIT_MAT_FRONT_SHININESS (1<<24)
159 #define _TNL_BIT_MAT_BACK_SHININESS (1<<25)
160 #define _TNL_BIT_MAT_FRONT_INDEXES (1<<26)
161 #define _TNL_BIT_MAT_BACK_INDEXES (1<<27)
162 #define _TNL_BIT_INDEX (1<<28)
163 #define _TNL_BIT_EDGEFLAG (1<<29)
164 #define _TNL_BIT_POINTSIZE (1<<30)
165
166 #define _TNL_BIT_TEX(u) (1 << (_TNL_ATTRIB_TEX0 + (u)))
167
168
169
170 #define _TNL_BITS_MAT_ANY (_TNL_BIT_MAT_FRONT_AMBIENT | \
171 _TNL_BIT_MAT_BACK_AMBIENT | \
172 _TNL_BIT_MAT_FRONT_DIFFUSE | \
173 _TNL_BIT_MAT_BACK_DIFFUSE | \
174 _TNL_BIT_MAT_FRONT_SPECULAR | \
175 _TNL_BIT_MAT_BACK_SPECULAR | \
176 _TNL_BIT_MAT_FRONT_EMISSION | \
177 _TNL_BIT_MAT_BACK_EMISSION | \
178 _TNL_BIT_MAT_FRONT_SHININESS | \
179 _TNL_BIT_MAT_BACK_SHININESS | \
180 _TNL_BIT_MAT_FRONT_INDEXES | \
181 _TNL_BIT_MAT_BACK_INDEXES)
182
183
184 #define _TNL_BITS_TEX_ANY (_TNL_BIT_TEX0 | \
185 _TNL_BIT_TEX1 | \
186 _TNL_BIT_TEX2 | \
187 _TNL_BIT_TEX3 | \
188 _TNL_BIT_TEX4 | \
189 _TNL_BIT_TEX5 | \
190 _TNL_BIT_TEX6 | \
191 _TNL_BIT_TEX7)
192
193
194 #define _TNL_BITS_PROG_ANY (_TNL_BIT_POS | \
195 _TNL_BIT_WEIGHT | \
196 _TNL_BIT_NORMAL | \
197 _TNL_BIT_COLOR0 | \
198 _TNL_BIT_COLOR1 | \
199 _TNL_BIT_FOG | \
200 _TNL_BIT_SIX | \
201 _TNL_BIT_SEVEN | \
202 _TNL_BITS_TEX_ANY)
203
204
205
206 #define PRIM_BEGIN 0x10
207 #define PRIM_END 0x20
208 #define PRIM_WEAK 0x40
209 #define PRIM_MODE_MASK 0x0f
210
211 /*
212 */
213 struct tnl_prim {
214 GLuint mode;
215 GLuint start;
216 GLuint count;
217 };
218
219
220
221 struct tnl_eval1_map {
222 struct gl_1d_map *map;
223 GLuint sz;
224 };
225
226 struct tnl_eval2_map {
227 struct gl_2d_map *map;
228 GLuint sz;
229 };
230
231 struct tnl_eval {
232 GLuint new_state;
233 struct tnl_eval1_map map1[_TNL_ATTRIB_INDEX + 1];
234 struct tnl_eval2_map map2[_TNL_ATTRIB_INDEX + 1];
235 };
236
237
238 #define TNL_MAX_PRIM 16
239 #define TNL_MAX_COPIED_VERTS 3
240
241 struct tnl_copied_vtx {
242 GLfloat buffer[_TNL_ATTRIB_MAX * 4 * TNL_MAX_COPIED_VERTS];
243 GLuint nr;
244 };
245
246 #define VERT_BUFFER_SIZE 2048 /* 8kbytes */
247
248
249 typedef void (*tnl_attrfv_func)( const GLfloat * );
250
251 struct _tnl_dynfn {
252 struct _tnl_dynfn *next, *prev;
253 GLuint key;
254 char *code;
255 };
256
257 struct _tnl_dynfn_lists {
258 struct _tnl_dynfn Vertex[4];
259 struct _tnl_dynfn Attribute[4];
260 };
261
262 struct _tnl_dynfn_generators {
263 struct _tnl_dynfn *(*Vertex[4])( GLcontext *ctx, int key );
264 struct _tnl_dynfn *(*Attribute[4])( GLcontext *ctx, int key );
265 };
266
267 #define _TNL_MAX_ATTR_CODEGEN 16
268
269
270 /* The assembly of vertices in immediate mode is separated from
271 * display list compilation. This allows a simpler immediate mode
272 * treatment and a display list compiler better suited to
273 * hardware-acceleration.
274 */
275 struct tnl_vtx {
276 GLfloat buffer[VERT_BUFFER_SIZE];
277 GLubyte attrsz[_TNL_ATTRIB_MAX];
278 GLuint vertex_size;
279 struct tnl_prim prim[TNL_MAX_PRIM];
280 GLuint prim_count;
281 GLfloat *vbptr; /* cursor, points into buffer */
282 GLfloat vertex[_TNL_ATTRIB_MAX*4]; /* current vertex */
283 GLfloat *attrptr[_TNL_ATTRIB_MAX]; /* points into vertex */
284 GLfloat *current[_TNL_ATTRIB_MAX]; /* points into ctx->Current, etc */
285 GLfloat CurrentFloatEdgeFlag;
286 GLuint counter, initial_counter;
287 struct tnl_copied_vtx copied;
288
289 tnl_attrfv_func tabfv[_TNL_MAX_ATTR_CODEGEN+1][4]; /* plus 1 for ERROR_ATTRIB */
290
291 struct _tnl_dynfn_lists cache;
292 struct _tnl_dynfn_generators gen;
293
294 struct tnl_eval eval;
295 GLboolean *edgeflag_tmp;
296 GLboolean have_materials;
297 };
298
299
300
301
302 /* For display lists, this structure holds a run of vertices of the
303 * same format, and a strictly well-formed set of begin/end pairs,
304 * starting on the first vertex and ending at the last. Vertex
305 * copying on buffer breaks is precomputed according to these
306 * primitives, though there are situations where the copying will need
307 * correction at execute-time, perhaps by replaying the list as
308 * immediate mode commands.
309 *
310 * On executing this list, the 'current' values may be updated with
311 * the values of the final vertex, and often no fixup of the start of
312 * the vertex list is required.
313 *
314 * Eval and other commands that don't fit into these vertex lists are
315 * compiled using the fallback opcode mechanism provided by dlist.c.
316 */
317 struct tnl_vertex_list {
318 GLubyte attrsz[_TNL_ATTRIB_MAX];
319 GLuint vertex_size;
320
321 GLfloat *buffer;
322 GLuint count;
323 GLuint wrap_count; /* number of copied vertices at start */
324 GLboolean have_materials; /* bit of a hack - quick check for materials */
325 GLboolean dangling_attr_ref; /* current attr implicitly referenced
326 outside the list */
327
328 GLfloat *normal_lengths;
329 struct tnl_prim *prim;
330 GLuint prim_count;
331
332 struct tnl_vertex_store *vertex_store;
333 struct tnl_primitive_store *prim_store;
334 };
335
336 /* These buffers should be a reasonable size to support upload to
337 * hardware? Maybe drivers should stitch them back together, or
338 * specify a desired size?
339 */
340 #define SAVE_BUFFER_SIZE (16*1024)
341 #define SAVE_PRIM_SIZE 128
342
343 /* Storage to be shared among several vertex_lists.
344 */
345 struct tnl_vertex_store {
346 GLfloat buffer[SAVE_BUFFER_SIZE];
347 GLuint used;
348 GLuint refcount;
349 };
350
351 struct tnl_primitive_store {
352 struct tnl_prim buffer[SAVE_PRIM_SIZE];
353 GLuint used;
354 GLuint refcount;
355 };
356
357
358 struct tnl_save {
359 GLubyte attrsz[_TNL_ATTRIB_MAX];
360 GLuint vertex_size;
361
362 GLfloat *buffer;
363 GLuint count;
364 GLuint wrap_count;
365 GLuint replay_flags;
366
367 struct tnl_prim *prim;
368 GLuint prim_count, prim_max;
369
370 struct tnl_vertex_store *vertex_store;
371 struct tnl_primitive_store *prim_store;
372
373 GLfloat *vbptr; /* cursor, points into buffer */
374 GLfloat vertex[_TNL_ATTRIB_MAX*4]; /* current values */
375 GLfloat *attrptr[_TNL_ATTRIB_MAX];
376 GLuint counter, initial_counter;
377 GLboolean dangling_attr_ref;
378 GLboolean have_materials;
379
380 GLuint opcode_vertex_list;
381
382 struct tnl_copied_vtx copied;
383
384 GLfloat CurrentFloatEdgeFlag;
385
386 GLfloat *current[_TNL_ATTRIB_MAX]; /* points into ctx->ListState */
387 GLubyte *currentsz[_TNL_ATTRIB_MAX];
388
389 void (*tabfv[_TNL_ATTRIB_MAX][4])( const GLfloat * );
390 };
391
392
393 struct tnl_vertex_arrays
394 {
395 /* Conventional vertex attribute arrays */
396 GLvector4f Obj;
397 GLvector4f Normal;
398 GLvector4f Color;
399 GLvector4f SecondaryColor;
400 GLvector4f FogCoord;
401 GLvector4f TexCoord[MAX_TEXTURE_COORD_UNITS];
402 GLvector4f Index;
403
404 GLubyte *EdgeFlag;
405 GLuint *Elt;
406
407 /* These attributes don't alias with the conventional attributes.
408 * The GL_NV_vertex_program extension defines 16 extra sets of vertex
409 * arrays which have precedent over the conventional arrays when enabled.
410 */
411 GLvector4f Attribs[_TNL_ATTRIB_MAX];
412 };
413
414
415 /**
416 * Contains the current state of a running pipeline.
417 */
418 struct vertex_buffer
419 {
420 /* Constant over life of the vertex_buffer.
421 */
422 GLuint Size;
423
424 /* Constant over the pipeline.
425 */
426 GLuint Count; /* for everything except Elts */
427
428 /* Pointers to current data.
429 */
430 GLuint *Elts;
431 GLvector4f *ObjPtr; /* _TNL_BIT_POS */
432 GLvector4f *EyePtr; /* _TNL_BIT_POS */
433 GLvector4f *ClipPtr; /* _TNL_BIT_POS */
434 GLvector4f *NdcPtr; /* _TNL_BIT_POS */
435 GLubyte ClipOrMask; /* _TNL_BIT_POS */
436 GLubyte ClipAndMask; /* _TNL_BIT_POS */
437 GLubyte *ClipMask; /* _TNL_BIT_POS */
438 GLvector4f *NormalPtr; /* _TNL_BIT_NORMAL */
439 GLfloat *NormalLengthPtr; /* _TNL_BIT_NORMAL */
440 GLboolean *EdgeFlag; /* _TNL_BIT_EDGEFLAG */
441 GLvector4f *TexCoordPtr[MAX_TEXTURE_COORD_UNITS]; /* VERT_TEX_0..n */
442 GLvector4f *IndexPtr[2]; /* _TNL_BIT_INDEX */
443 GLvector4f *ColorPtr[2]; /* _TNL_BIT_COLOR0 */
444 GLvector4f *SecondaryColorPtr[2]; /* _TNL_BIT_COLOR1 */
445 GLvector4f *PointSizePtr; /* _TNL_BIT_POS */
446 GLvector4f *FogCoordPtr; /* _TNL_BIT_FOG */
447
448 struct tnl_prim *Primitive;
449 GLuint PrimitiveCount;
450
451 /* Inputs to the vertex program stage */
452 GLvector4f *AttribPtr[_TNL_ATTRIB_MAX]; /* GL_NV_vertex_program */
453 };
454
455
456 /** Describes an individual operation on the pipeline.
457 */
458 struct tnl_pipeline_stage
459 {
460 const char *name;
461
462 /* Private data for the pipeline stage:
463 */
464 void *privatePtr;
465
466 /* Allocate private data
467 */
468 GLboolean (*create)( GLcontext *ctx, struct tnl_pipeline_stage * );
469
470 /* Free private data.
471 */
472 void (*destroy)( struct tnl_pipeline_stage * );
473
474 /* Called on any statechange or input array size change or
475 * input array change to/from zero stride.
476 */
477 void (*validate)( GLcontext *ctx, struct tnl_pipeline_stage * );
478
479 /* Called from _tnl_run_pipeline(). The stage.changed_inputs value
480 * encodes all inputs to thee struct which have changed. If
481 * non-zero, recompute all affected outputs of the stage, otherwise
482 * execute any 'sideeffects' of the stage.
483 *
484 * Return value: GL_TRUE - keep going
485 * GL_FALSE - finished pipeline
486 */
487 GLboolean (*run)( GLcontext *ctx, struct tnl_pipeline_stage * );
488 };
489
490
491
492 /** Contains the array of all pipeline stages.
493 * The default values are defined at the end of t_pipeline.c
494 */
495 struct tnl_pipeline {
496
497 GLuint last_attrib_stride[_TNL_ATTRIB_MAX];
498 GLuint last_attrib_size[_TNL_ATTRIB_MAX];
499 GLuint input_changes;
500 GLuint new_state;
501
502 struct tnl_pipeline_stage stages[MAX_PIPELINE_STAGES+1];
503 GLuint nr_stages;
504 };
505
506 struct tnl_clipspace;
507 struct tnl_clipspace_attr;
508
509 typedef void (*tnl_extract_func)( const struct tnl_clipspace_attr *a,
510 GLfloat *out,
511 const GLubyte *v );
512
513 typedef void (*tnl_insert_func)( const struct tnl_clipspace_attr *a,
514 GLubyte *v,
515 const GLfloat *in );
516
517 typedef void (*tnl_emit_func)( GLcontext *ctx,
518 GLuint count,
519 GLubyte *dest );
520
521
522 /**
523 * Describes how to convert/move a vertex attribute from a vertex array
524 * to a vertex structure.
525 */
526 struct tnl_clipspace_attr
527 {
528 GLuint attrib; /* which vertex attrib (0=position, etc) */
529 GLuint format;
530 GLuint vertoffset; /* position of the attrib in the vertex struct */
531 GLuint vertattrsize; /* size of the attribute in bytes */
532 GLubyte *inputptr;
533 GLuint inputstride;
534 GLuint inputsize;
535 const tnl_insert_func *insert;
536 tnl_insert_func emit;
537 tnl_extract_func extract;
538 const GLfloat *vp; /* NDC->Viewport mapping matrix */
539 };
540
541
542
543
544 typedef void (*tnl_points_func)( GLcontext *ctx, GLuint first, GLuint last );
545 typedef void (*tnl_line_func)( GLcontext *ctx, GLuint v1, GLuint v2 );
546 typedef void (*tnl_triangle_func)( GLcontext *ctx,
547 GLuint v1, GLuint v2, GLuint v3 );
548 typedef void (*tnl_quad_func)( GLcontext *ctx, GLuint v1, GLuint v2,
549 GLuint v3, GLuint v4 );
550 typedef void (*tnl_render_func)( GLcontext *ctx, GLuint start, GLuint count,
551 GLuint flags );
552 typedef void (*tnl_interp_func)( GLcontext *ctx,
553 GLfloat t, GLuint dst, GLuint out, GLuint in,
554 GLboolean force_boundary );
555 typedef void (*tnl_copy_pv_func)( GLcontext *ctx, GLuint dst, GLuint src );
556 typedef void (*tnl_setup_func)( GLcontext *ctx,
557 GLuint start, GLuint end,
558 GLuint new_inputs);
559
560
561 struct tnl_clipspace_fastpath {
562 GLuint vertex_size;
563 GLuint attr_count;
564 GLboolean match_strides;
565
566 struct {
567 GLuint format;
568 GLuint size;
569 GLuint stride;
570 GLuint offset;
571 } *attr;
572
573 tnl_emit_func func;
574 struct tnl_clipspace_fastpath *next;
575 };
576
577 /**
578 * Used to describe conversion of vertex arrays to vertex structures.
579 * I.e. Structure of arrays to arrays of structs.
580 */
581 struct tnl_clipspace
582 {
583 GLboolean need_extras;
584
585 GLuint new_inputs;
586
587 GLubyte *vertex_buf;
588 GLuint vertex_size;
589 GLuint max_vertex_size;
590
591 struct tnl_clipspace_attr attr[_TNL_ATTRIB_MAX];
592 GLuint attr_count;
593
594 tnl_emit_func emit;
595 tnl_interp_func interp;
596 tnl_copy_pv_func copy_pv;
597
598 /* Parameters and constants for codegen:
599 */
600 GLboolean need_viewport;
601 GLfloat vp_scale[4];
602 GLfloat vp_xlate[4];
603 GLfloat chan_scale[4];
604 GLfloat identity[4];
605
606 struct tnl_clipspace_fastpath *fastpath;
607
608 void (*codegen_emit)( GLcontext *ctx );
609 };
610
611
612 struct tnl_cache_item {
613 GLuint hash;
614 void *key;
615 void *data;
616 struct tnl_cache_item *next;
617 };
618
619 struct tnl_cache {
620 struct tnl_cache_item **items;
621 GLuint size, n_items;
622 };
623
624
625 struct tnl_device_driver
626 {
627 /***
628 *** TNL Pipeline
629 ***/
630
631 void (*RunPipeline)(GLcontext *ctx);
632 /* Replaces PipelineStart/PipelineFinish -- intended to allow
633 * drivers to wrap _tnl_run_pipeline() with code to validate state
634 * and grab/release hardware locks.
635 */
636
637 void (*NotifyMaterialChange)(GLcontext *ctx);
638 /* Alert tnl-aware drivers of changes to material.
639 */
640
641 void (*NotifyInputChanges)(GLcontext *ctx, GLuint bitmask);
642 /* Alert tnl-aware drivers of changes to size and stride of input
643 * arrays.
644 */
645
646 GLboolean (*NotifyBegin)(GLcontext *ctx, GLenum p);
647 /* Allow drivers to hook in optimized begin/end engines.
648 * Return value: GL_TRUE - driver handled the begin
649 * GL_FALSE - driver didn't handle the begin
650 */
651
652 /***
653 *** Rendering -- These functions called only from t_vb_render.c
654 ***/
655 struct
656 {
657 void (*Start)(GLcontext *ctx);
658 void (*Finish)(GLcontext *ctx);
659 /* Called before and after all rendering operations, including DrawPixels,
660 * ReadPixels, Bitmap, span functions, and CopyTexImage, etc commands.
661 * These are a suitable place for grabbing/releasing hardware locks.
662 */
663
664 void (*PrimitiveNotify)(GLcontext *ctx, GLenum mode);
665 /* Called between RenderStart() and RenderFinish() to indicate the
666 * type of primitive we're about to draw. Mode will be one of the
667 * modes accepted by glBegin().
668 */
669
670 tnl_interp_func Interp;
671 /* The interp function is called by the clipping routines when we need
672 * to generate an interpolated vertex. All pertinant vertex ancilliary
673 * data should be computed by interpolating between the 'in' and 'out'
674 * vertices.
675 */
676
677 tnl_copy_pv_func CopyPV;
678 /* The copy function is used to make a copy of a vertex. All pertinant
679 * vertex attributes should be copied.
680 */
681
682 void (*ClippedPolygon)( GLcontext *ctx, const GLuint *elts, GLuint n );
683 /* Render a polygon with <n> vertices whose indexes are in the <elts>
684 * array.
685 */
686
687 void (*ClippedLine)( GLcontext *ctx, GLuint v0, GLuint v1 );
688 /* Render a line between the two vertices given by indexes v0 and v1. */
689
690 tnl_points_func Points; /* must now respect vb->elts */
691 tnl_line_func Line;
692 tnl_triangle_func Triangle;
693 tnl_quad_func Quad;
694 /* These functions are called in order to render points, lines,
695 * triangles and quads. These are only called via the T&L module.
696 */
697
698 tnl_render_func *PrimTabVerts;
699 tnl_render_func *PrimTabElts;
700 /* Render whole unclipped primitives (points, lines, linestrips,
701 * lineloops, etc). The tables are indexed by the GL enum of the
702 * primitive to be rendered. RenderTabVerts is used for non-indexed
703 * arrays of vertices. RenderTabElts is used for indexed arrays of
704 * vertices.
705 */
706
707 void (*ResetLineStipple)( GLcontext *ctx );
708 /* Reset the hardware's line stipple counter.
709 */
710
711 tnl_setup_func BuildVertices;
712 /* This function is called whenever new vertices are required for
713 * rendering. The vertices in question are those n such that start
714 * <= n < end. The new_inputs parameter indicates those fields of
715 * the vertex which need to be updated, if only a partial repair of
716 * the vertex is required.
717 *
718 * This function is called only from _tnl_render_stage in tnl/t_render.c.
719 */
720
721
722 GLboolean (*Multipass)( GLcontext *ctx, GLuint passno );
723 /* Driver may request additional render passes by returning GL_TRUE
724 * when this function is called. This function will be called
725 * after the first pass, and passes will be made until the function
726 * returns GL_FALSE. If no function is registered, only one pass
727 * is made.
728 *
729 * This function will be first invoked with passno == 1.
730 */
731 } Render;
732 };
733
734
735 /**
736 * Context state for T&L context.
737 */
738 typedef struct
739 {
740 /* Driver interface.
741 */
742 struct tnl_device_driver Driver;
743
744 /* Execute:
745 */
746 struct tnl_vtx vtx;
747
748 /* Compile:
749 */
750 struct tnl_save save;
751
752 /* Pipeline
753 */
754 struct tnl_pipeline pipeline;
755 struct vertex_buffer vb;
756
757 /* GLvectors for binding to vb:
758 */
759 struct tnl_vertex_arrays vtx_inputs;
760 struct tnl_vertex_arrays save_inputs;
761 struct tnl_vertex_arrays current;
762 struct tnl_vertex_arrays array_inputs;
763
764 /* Clipspace/ndc/window vertex managment:
765 */
766 struct tnl_clipspace clipspace;
767
768 /* Probably need a better configuration mechanism:
769 */
770 GLboolean NeedNdcCoords;
771 GLboolean LoopbackDListCassettes;
772 GLboolean CalcDListNormalLengths;
773 GLboolean IsolateMaterials;
774 GLboolean AllowVertexFog;
775 GLboolean AllowPixelFog;
776 GLboolean AllowCodegen;
777
778 GLboolean _DoVertexFog; /* eval fog function at each vertex? */
779
780 /* If True, it means we started a glBegin/End primtive with an invalid
781 * vertex/fragment program or incomplete framebuffer. In that case,
782 * discard any buffered vertex data.
783 */
784 GLboolean DiscardPrimitive;
785
786 GLuint render_inputs;
787
788 GLvertexformat exec_vtxfmt;
789 GLvertexformat save_vtxfmt;
790
791 struct tnl_cache *vp_cache;
792
793 } TNLcontext;
794
795
796
797 #define TNL_CONTEXT(ctx) ((TNLcontext *)((ctx)->swtnl_context))
798
799
800 #define TYPE_IDX(t) ((t) & 0xf)
801 #define MAX_TYPES TYPE_IDX(GL_DOUBLE)+1 /* 0xa + 1 */
802
803
804 #endif