bring in active_sz mechanism from i965 driver. Fixes bug 8410
[mesa.git] / src / mesa / tnl / t_context.h
1 /*
2 * mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2006 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 /* The bit space exhaustion is a fact now, done by _TNL_ATTRIB_ATTRIBUTE* for
96 * GLSL vertex shader which cannot be aliased with conventional vertex attribs.
97 * Compacting _TNL_ATTRIB_MAT_* attribs would not work, they would not give
98 * as many free bits (11 plus already 1 free bit) as _TNL_ATTRIB_ATTRIBUTE*
99 * attribs want (16).
100 */
101 enum {
102 _TNL_ATTRIB_POS = 0,
103 _TNL_ATTRIB_WEIGHT = 1,
104 _TNL_ATTRIB_NORMAL = 2,
105 _TNL_ATTRIB_COLOR0 = 3,
106 _TNL_ATTRIB_COLOR1 = 4,
107 _TNL_ATTRIB_FOG = 5,
108 _TNL_ATTRIB_COLOR_INDEX = 6,
109 _TNL_ATTRIB_SEVEN = 7,
110 _TNL_ATTRIB_TEX0 = 8,
111 _TNL_ATTRIB_TEX1 = 9,
112 _TNL_ATTRIB_TEX2 = 10,
113 _TNL_ATTRIB_TEX3 = 11,
114 _TNL_ATTRIB_TEX4 = 12,
115 _TNL_ATTRIB_TEX5 = 13,
116 _TNL_ATTRIB_TEX6 = 14,
117 _TNL_ATTRIB_TEX7 = 15,
118 _TNL_ATTRIB_GENERIC0 = 16,
119 _TNL_ATTRIB_GENERIC1 = 17,
120 _TNL_ATTRIB_GENERIC2 = 18,
121 _TNL_ATTRIB_GENERIC3 = 19,
122 _TNL_ATTRIB_GENERIC4 = 20,
123 _TNL_ATTRIB_GENERIC5 = 21,
124 _TNL_ATTRIB_GENERIC6 = 22,
125 _TNL_ATTRIB_GENERIC7 = 23,
126 _TNL_ATTRIB_GENERIC8 = 24,
127 _TNL_ATTRIB_GENERIC9 = 25,
128 _TNL_ATTRIB_GENERIC10 = 26,
129 _TNL_ATTRIB_GENERIC11 = 27,
130 _TNL_ATTRIB_GENERIC12 = 28,
131 _TNL_ATTRIB_GENERIC13 = 29,
132 _TNL_ATTRIB_GENERIC14 = 30,
133 _TNL_ATTRIB_GENERIC15 = 31,
134 _TNL_ATTRIB_MAT_FRONT_AMBIENT = 32,
135 _TNL_ATTRIB_MAT_BACK_AMBIENT = 33,
136 _TNL_ATTRIB_MAT_FRONT_DIFFUSE = 34,
137 _TNL_ATTRIB_MAT_BACK_DIFFUSE = 35,
138 _TNL_ATTRIB_MAT_FRONT_SPECULAR = 36,
139 _TNL_ATTRIB_MAT_BACK_SPECULAR = 37,
140 _TNL_ATTRIB_MAT_FRONT_EMISSION = 38,
141 _TNL_ATTRIB_MAT_BACK_EMISSION = 39,
142 _TNL_ATTRIB_MAT_FRONT_SHININESS = 40,
143 _TNL_ATTRIB_MAT_BACK_SHININESS = 41,
144 _TNL_ATTRIB_MAT_FRONT_INDEXES = 42,
145 _TNL_ATTRIB_MAT_BACK_INDEXES = 43,
146 _TNL_ATTRIB_EDGEFLAG = 44,
147 _TNL_ATTRIB_POINTSIZE = 45,
148 _TNL_ATTRIB_MAX = 46
149 } ;
150
151 #define _TNL_ATTRIB_TEX(u) (_TNL_ATTRIB_TEX0 + (u))
152 #define _TNL_ATTRIB_GENERIC(n) (_TNL_ATTRIB_GENERIC0 + (n))
153
154 /* special index used for handing invalid glVertexAttribute() indices */
155 #define _TNL_ATTRIB_ERROR (_TNL_ATTRIB_GENERIC15 + 1)
156
157 /**
158 * Handy attribute ranges:
159 */
160 #define _TNL_FIRST_PROG _TNL_ATTRIB_WEIGHT
161 #define _TNL_LAST_PROG _TNL_ATTRIB_TEX7
162
163 #define _TNL_FIRST_TEX _TNL_ATTRIB_TEX0
164 #define _TNL_LAST_TEX _TNL_ATTRIB_TEX7
165
166 #define _TNL_FIRST_GENERIC _TNL_ATTRIB_GENERIC0
167 #define _TNL_LAST_GENERIC _TNL_ATTRIB_GENERIC15
168
169 #define _TNL_FIRST_MAT _TNL_ATTRIB_MAT_FRONT_AMBIENT
170 #define _TNL_LAST_MAT _TNL_ATTRIB_MAT_BACK_INDEXES
171
172 /* Number of available generic attributes */
173 #define _TNL_NUM_GENERIC 16
174
175 /* Number of attributes used for evaluators */
176 #define _TNL_NUM_EVAL 16
177
178 #define PRIM_BEGIN 0x10
179 #define PRIM_END 0x20
180 #define PRIM_WEAK 0x40
181 #define PRIM_MODE_MASK 0x0f
182
183 /*
184 */
185 struct tnl_prim {
186 GLuint mode;
187 GLuint start;
188 GLuint count;
189 };
190
191
192
193 struct tnl_eval1_map {
194 struct gl_1d_map *map;
195 GLuint sz;
196 };
197
198 struct tnl_eval2_map {
199 struct gl_2d_map *map;
200 GLuint sz;
201 };
202
203 struct tnl_eval {
204 GLuint new_state;
205 struct tnl_eval1_map map1[_TNL_NUM_EVAL];
206 struct tnl_eval2_map map2[_TNL_NUM_EVAL];
207 };
208
209
210 #define TNL_MAX_PRIM 16
211 #define TNL_MAX_COPIED_VERTS 3
212
213 struct tnl_copied_vtx {
214 GLfloat buffer[_TNL_ATTRIB_MAX * 4 * TNL_MAX_COPIED_VERTS];
215 GLuint nr;
216 };
217
218 #define VERT_BUFFER_SIZE 2048 /* 8kbytes */
219
220
221 typedef void (*tnl_attrfv_func)( const GLfloat * );
222
223 struct _tnl_dynfn {
224 struct _tnl_dynfn *next, *prev;
225 GLuint key;
226 char *code;
227 };
228
229 struct _tnl_dynfn_lists {
230 struct _tnl_dynfn Vertex[4];
231 struct _tnl_dynfn Attribute[4];
232 };
233
234 struct _tnl_dynfn_generators {
235 struct _tnl_dynfn *(*Vertex[4])( GLcontext *ctx, int key );
236 struct _tnl_dynfn *(*Attribute[4])( GLcontext *ctx, int key );
237 };
238
239 #define _TNL_MAX_ATTR_CODEGEN 32
240
241
242 /**
243 * The assembly of vertices in immediate mode is separated from
244 * display list compilation. This allows a simpler immediate mode
245 * treatment and a display list compiler better suited to
246 * hardware-acceleration.
247 */
248 struct tnl_vtx {
249 GLfloat buffer[VERT_BUFFER_SIZE];
250 GLubyte attrsz[_TNL_ATTRIB_MAX];
251 GLubyte active_sz[_TNL_ATTRIB_MAX];
252 GLuint vertex_size;
253 struct tnl_prim prim[TNL_MAX_PRIM];
254 GLuint prim_count;
255 GLfloat *vbptr; /* cursor, points into buffer */
256 GLfloat vertex[_TNL_ATTRIB_MAX*4]; /* current vertex */
257 GLfloat *attrptr[_TNL_ATTRIB_MAX]; /* points into vertex */
258 GLfloat *current[_TNL_ATTRIB_MAX]; /* points into ctx->Current, etc */
259 GLfloat CurrentFloatEdgeFlag;
260 GLuint counter, initial_counter;
261 struct tnl_copied_vtx copied;
262
263 /** Note extra space for error handler: */
264 tnl_attrfv_func tabfv[_TNL_ATTRIB_ERROR+1][4];
265
266 struct _tnl_dynfn_lists cache;
267 struct _tnl_dynfn_generators gen;
268
269 struct tnl_eval eval;
270 GLboolean *edgeflag_tmp;
271 GLboolean have_materials;
272 };
273
274
275
276
277 /* For display lists, this structure holds a run of vertices of the
278 * same format, and a strictly well-formed set of begin/end pairs,
279 * starting on the first vertex and ending at the last. Vertex
280 * copying on buffer breaks is precomputed according to these
281 * primitives, though there are situations where the copying will need
282 * correction at execute-time, perhaps by replaying the list as
283 * immediate mode commands.
284 *
285 * On executing this list, the 'current' values may be updated with
286 * the values of the final vertex, and often no fixup of the start of
287 * the vertex list is required.
288 *
289 * Eval and other commands that don't fit into these vertex lists are
290 * compiled using the fallback opcode mechanism provided by dlist.c.
291 */
292 struct tnl_vertex_list {
293 GLubyte attrsz[_TNL_ATTRIB_MAX];
294 GLuint vertex_size;
295
296 GLfloat *buffer;
297 GLuint count;
298 GLuint wrap_count; /* number of copied vertices at start */
299 GLboolean have_materials; /* bit of a hack - quick check for materials */
300 GLboolean dangling_attr_ref; /* current attr implicitly referenced
301 outside the list */
302
303 GLfloat *normal_lengths;
304 struct tnl_prim *prim;
305 GLuint prim_count;
306
307 struct tnl_vertex_store *vertex_store;
308 struct tnl_primitive_store *prim_store;
309 };
310
311 /* These buffers should be a reasonable size to support upload to
312 * hardware? Maybe drivers should stitch them back together, or
313 * specify a desired size?
314 */
315 #define SAVE_BUFFER_SIZE (16*1024)
316 #define SAVE_PRIM_SIZE 128
317
318 /* Storage to be shared among several vertex_lists.
319 */
320 struct tnl_vertex_store {
321 GLfloat buffer[SAVE_BUFFER_SIZE];
322 GLuint used;
323 GLuint refcount;
324 };
325
326 struct tnl_primitive_store {
327 struct tnl_prim buffer[SAVE_PRIM_SIZE];
328 GLuint used;
329 GLuint refcount;
330 };
331
332
333 struct tnl_save {
334 GLubyte attrsz[_TNL_ATTRIB_MAX];
335 GLuint vertex_size;
336
337 GLfloat *buffer;
338 GLuint count;
339 GLuint wrap_count;
340 GLuint replay_flags;
341
342 struct tnl_prim *prim;
343 GLuint prim_count, prim_max;
344
345 struct tnl_vertex_store *vertex_store;
346 struct tnl_primitive_store *prim_store;
347
348 GLfloat *vbptr; /* cursor, points into buffer */
349 GLfloat vertex[_TNL_ATTRIB_MAX*4]; /* current values */
350 GLfloat *attrptr[_TNL_ATTRIB_MAX];
351 GLuint counter, initial_counter;
352 GLboolean dangling_attr_ref;
353 GLboolean have_materials;
354
355 GLuint opcode_vertex_list;
356
357 struct tnl_copied_vtx copied;
358
359 GLfloat CurrentFloatEdgeFlag;
360
361 GLfloat *current[_TNL_ATTRIB_MAX]; /* points into ctx->ListState */
362 GLubyte *currentsz[_TNL_ATTRIB_MAX];
363
364 void (*tabfv[_TNL_ATTRIB_MAX][4])( const GLfloat * );
365 };
366
367
368 /**
369 * A collection of vertex arrays.
370 */
371 struct tnl_vertex_arrays
372 {
373 /* Conventional vertex attribute arrays */
374 GLvector4f Obj;
375 GLvector4f Normal;
376 GLvector4f Color;
377 GLvector4f SecondaryColor;
378 GLvector4f FogCoord;
379 GLvector4f TexCoord[MAX_TEXTURE_COORD_UNITS];
380 GLvector4f Index;
381
382 GLubyte *EdgeFlag;
383 GLuint *Elt;
384
385 /* These attributes don't alias with the conventional attributes.
386 * The GL_NV_vertex_program extension defines 16 extra sets of vertex
387 * arrays which have precedent over the conventional arrays when enabled.
388 */
389 /* XXX I think the array size is wronge (47 vs. 16) */
390 GLvector4f Attribs[_TNL_ATTRIB_MAX];
391 };
392
393
394 /**
395 * Contains the current state of a running pipeline.
396 */
397 struct vertex_buffer
398 {
399 GLuint Size; /**< Max vertices per vertex buffer, constant */
400
401 /* Constant over the pipeline.
402 */
403 GLuint Count; /**< Number of vertices currently in buffer */
404
405 /* Pointers to current data.
406 * XXX some of these fields alias AttribPtr below and should be removed
407 * such as NormalPtr, TexCoordPtr, FogCoordPtr, etc.
408 */
409 GLuint *Elts;
410 GLvector4f *ObjPtr; /* _TNL_BIT_POS */
411 GLvector4f *EyePtr; /* _TNL_BIT_POS */
412 GLvector4f *ClipPtr; /* _TNL_BIT_POS */
413 GLvector4f *NdcPtr; /* _TNL_BIT_POS */
414 GLubyte ClipOrMask; /* _TNL_BIT_POS */
415 GLubyte ClipAndMask; /* _TNL_BIT_POS */
416 GLubyte *ClipMask; /* _TNL_BIT_POS */
417 GLvector4f *NormalPtr; /* _TNL_BIT_NORMAL */
418 GLfloat *NormalLengthPtr; /* _TNL_BIT_NORMAL */
419 GLboolean *EdgeFlag; /* _TNL_BIT_EDGEFLAG */
420 GLvector4f *TexCoordPtr[MAX_TEXTURE_COORD_UNITS]; /* VERT_TEX_0..n */
421 GLvector4f *IndexPtr[2]; /* _TNL_BIT_INDEX */
422 GLvector4f *ColorPtr[2]; /* _TNL_BIT_COLOR0 */
423 GLvector4f *SecondaryColorPtr[2]; /* _TNL_BIT_COLOR1 */
424 GLvector4f *FogCoordPtr; /* _TNL_BIT_FOG */
425 GLvector4f *VaryingPtr[MAX_VARYING_VECTORS];
426
427 struct tnl_prim *Primitive;
428 GLuint PrimitiveCount;
429
430 /* Inputs to the vertex program stage */
431 /* XXX This array may be too large (47 vs. 16) */
432 GLvector4f *AttribPtr[_TNL_ATTRIB_MAX]; /* GL_NV_vertex_program */
433 };
434
435
436 /**
437 * Describes an individual operation on the pipeline.
438 */
439 struct tnl_pipeline_stage
440 {
441 const char *name;
442
443 /* Private data for the pipeline stage:
444 */
445 void *privatePtr;
446
447 /* Allocate private data
448 */
449 GLboolean (*create)( GLcontext *ctx, struct tnl_pipeline_stage * );
450
451 /* Free private data.
452 */
453 void (*destroy)( struct tnl_pipeline_stage * );
454
455 /* Called on any statechange or input array size change or
456 * input array change to/from zero stride.
457 */
458 void (*validate)( GLcontext *ctx, struct tnl_pipeline_stage * );
459
460 /* Called from _tnl_run_pipeline(). The stage.changed_inputs value
461 * encodes all inputs to thee struct which have changed. If
462 * non-zero, recompute all affected outputs of the stage, otherwise
463 * execute any 'sideeffects' of the stage.
464 *
465 * Return value: GL_TRUE - keep going
466 * GL_FALSE - finished pipeline
467 */
468 GLboolean (*run)( GLcontext *ctx, struct tnl_pipeline_stage * );
469 };
470
471
472
473 /** Contains the array of all pipeline stages.
474 * The default values are defined at the end of t_pipeline.c
475 */
476 struct tnl_pipeline {
477
478 GLuint last_attrib_stride[_TNL_ATTRIB_MAX];
479 GLuint last_attrib_size[_TNL_ATTRIB_MAX];
480 GLuint input_changes;
481 GLuint new_state;
482
483 struct tnl_pipeline_stage stages[MAX_PIPELINE_STAGES+1];
484 GLuint nr_stages;
485 };
486
487 struct tnl_clipspace;
488 struct tnl_clipspace_attr;
489
490 typedef void (*tnl_extract_func)( const struct tnl_clipspace_attr *a,
491 GLfloat *out,
492 const GLubyte *v );
493
494 typedef void (*tnl_insert_func)( const struct tnl_clipspace_attr *a,
495 GLubyte *v,
496 const GLfloat *in );
497
498 typedef void (*tnl_emit_func)( GLcontext *ctx,
499 GLuint count,
500 GLubyte *dest );
501
502
503 /**
504 * Describes how to convert/move a vertex attribute from a vertex array
505 * to a vertex structure.
506 */
507 struct tnl_clipspace_attr
508 {
509 GLuint attrib; /* which vertex attrib (0=position, etc) */
510 GLuint format;
511 GLuint vertoffset; /* position of the attrib in the vertex struct */
512 GLuint vertattrsize; /* size of the attribute in bytes */
513 GLubyte *inputptr;
514 GLuint inputstride;
515 GLuint inputsize;
516 const tnl_insert_func *insert;
517 tnl_insert_func emit;
518 tnl_extract_func extract;
519 const GLfloat *vp; /* NDC->Viewport mapping matrix */
520 };
521
522
523
524
525 typedef void (*tnl_points_func)( GLcontext *ctx, GLuint first, GLuint last );
526 typedef void (*tnl_line_func)( GLcontext *ctx, GLuint v1, GLuint v2 );
527 typedef void (*tnl_triangle_func)( GLcontext *ctx,
528 GLuint v1, GLuint v2, GLuint v3 );
529 typedef void (*tnl_quad_func)( GLcontext *ctx, GLuint v1, GLuint v2,
530 GLuint v3, GLuint v4 );
531 typedef void (*tnl_render_func)( GLcontext *ctx, GLuint start, GLuint count,
532 GLuint flags );
533 typedef void (*tnl_interp_func)( GLcontext *ctx,
534 GLfloat t, GLuint dst, GLuint out, GLuint in,
535 GLboolean force_boundary );
536 typedef void (*tnl_copy_pv_func)( GLcontext *ctx, GLuint dst, GLuint src );
537 typedef void (*tnl_setup_func)( GLcontext *ctx,
538 GLuint start, GLuint end,
539 GLuint new_inputs);
540
541
542 struct tnl_attr_type {
543 GLuint format;
544 GLuint size;
545 GLuint stride;
546 GLuint offset;
547 };
548
549 struct tnl_clipspace_fastpath {
550 GLuint vertex_size;
551 GLuint attr_count;
552 GLboolean match_strides;
553
554 struct tnl_attr_type *attr;
555
556 tnl_emit_func func;
557 struct tnl_clipspace_fastpath *next;
558 };
559
560 /**
561 * Used to describe conversion of vertex arrays to vertex structures.
562 * I.e. Structure of arrays to arrays of structs.
563 */
564 struct tnl_clipspace
565 {
566 GLboolean need_extras;
567
568 GLuint new_inputs;
569
570 GLubyte *vertex_buf;
571 GLuint vertex_size;
572 GLuint max_vertex_size;
573
574 struct tnl_clipspace_attr attr[_TNL_ATTRIB_MAX];
575 GLuint attr_count;
576
577 tnl_emit_func emit;
578 tnl_interp_func interp;
579 tnl_copy_pv_func copy_pv;
580
581 /* Parameters and constants for codegen:
582 */
583 GLboolean need_viewport;
584 GLfloat vp_scale[4];
585 GLfloat vp_xlate[4];
586 GLfloat chan_scale[4];
587 GLfloat identity[4];
588
589 struct tnl_clipspace_fastpath *fastpath;
590
591 void (*codegen_emit)( GLcontext *ctx );
592 };
593
594
595 struct tnl_cache_item {
596 GLuint hash;
597 void *key;
598 void *data;
599 struct tnl_cache_item *next;
600 };
601
602 struct tnl_cache {
603 struct tnl_cache_item **items;
604 GLuint size, n_items;
605 };
606
607
608 struct tnl_device_driver
609 {
610 /***
611 *** TNL Pipeline
612 ***/
613
614 void (*RunPipeline)(GLcontext *ctx);
615 /* Replaces PipelineStart/PipelineFinish -- intended to allow
616 * drivers to wrap _tnl_run_pipeline() with code to validate state
617 * and grab/release hardware locks.
618 */
619
620 void (*NotifyMaterialChange)(GLcontext *ctx);
621 /* Alert tnl-aware drivers of changes to material.
622 */
623
624 void (*NotifyInputChanges)(GLcontext *ctx, GLuint bitmask);
625 /* Alert tnl-aware drivers of changes to size and stride of input
626 * arrays.
627 */
628
629 GLboolean (*NotifyBegin)(GLcontext *ctx, GLenum p);
630 /* Allow drivers to hook in optimized begin/end engines.
631 * Return value: GL_TRUE - driver handled the begin
632 * GL_FALSE - driver didn't handle the begin
633 */
634
635 /***
636 *** Rendering -- These functions called only from t_vb_render.c
637 ***/
638 struct
639 {
640 void (*Start)(GLcontext *ctx);
641 void (*Finish)(GLcontext *ctx);
642 /* Called before and after all rendering operations, including DrawPixels,
643 * ReadPixels, Bitmap, span functions, and CopyTexImage, etc commands.
644 * These are a suitable place for grabbing/releasing hardware locks.
645 */
646
647 void (*PrimitiveNotify)(GLcontext *ctx, GLenum mode);
648 /* Called between RenderStart() and RenderFinish() to indicate the
649 * type of primitive we're about to draw. Mode will be one of the
650 * modes accepted by glBegin().
651 */
652
653 tnl_interp_func Interp;
654 /* The interp function is called by the clipping routines when we need
655 * to generate an interpolated vertex. All pertinant vertex ancilliary
656 * data should be computed by interpolating between the 'in' and 'out'
657 * vertices.
658 */
659
660 tnl_copy_pv_func CopyPV;
661 /* The copy function is used to make a copy of a vertex. All pertinant
662 * vertex attributes should be copied.
663 */
664
665 void (*ClippedPolygon)( GLcontext *ctx, const GLuint *elts, GLuint n );
666 /* Render a polygon with <n> vertices whose indexes are in the <elts>
667 * array.
668 */
669
670 void (*ClippedLine)( GLcontext *ctx, GLuint v0, GLuint v1 );
671 /* Render a line between the two vertices given by indexes v0 and v1. */
672
673 tnl_points_func Points; /* must now respect vb->elts */
674 tnl_line_func Line;
675 tnl_triangle_func Triangle;
676 tnl_quad_func Quad;
677 /* These functions are called in order to render points, lines,
678 * triangles and quads. These are only called via the T&L module.
679 */
680
681 tnl_render_func *PrimTabVerts;
682 tnl_render_func *PrimTabElts;
683 /* Render whole unclipped primitives (points, lines, linestrips,
684 * lineloops, etc). The tables are indexed by the GL enum of the
685 * primitive to be rendered. RenderTabVerts is used for non-indexed
686 * arrays of vertices. RenderTabElts is used for indexed arrays of
687 * vertices.
688 */
689
690 void (*ResetLineStipple)( GLcontext *ctx );
691 /* Reset the hardware's line stipple counter.
692 */
693
694 tnl_setup_func BuildVertices;
695 /* This function is called whenever new vertices are required for
696 * rendering. The vertices in question are those n such that start
697 * <= n < end. The new_inputs parameter indicates those fields of
698 * the vertex which need to be updated, if only a partial repair of
699 * the vertex is required.
700 *
701 * This function is called only from _tnl_render_stage in tnl/t_render.c.
702 */
703
704
705 GLboolean (*Multipass)( GLcontext *ctx, GLuint passno );
706 /* Driver may request additional render passes by returning GL_TRUE
707 * when this function is called. This function will be called
708 * after the first pass, and passes will be made until the function
709 * returns GL_FALSE. If no function is registered, only one pass
710 * is made.
711 *
712 * This function will be first invoked with passno == 1.
713 */
714 } Render;
715 };
716
717
718 #define DECLARE_RENDERINPUTS(name) BITSET64_DECLARE(name, _TNL_ATTRIB_MAX)
719 #define RENDERINPUTS_COPY BITSET64_COPY
720 #define RENDERINPUTS_EQUAL BITSET64_EQUAL
721 #define RENDERINPUTS_ZERO BITSET64_ZERO
722 #define RENDERINPUTS_ONES BITSET64_ONES
723 #define RENDERINPUTS_TEST BITSET64_TEST
724 #define RENDERINPUTS_SET BITSET64_SET
725 #define RENDERINPUTS_CLEAR BITSET64_CLEAR
726 #define RENDERINPUTS_TEST_RANGE BITSET64_TEST_RANGE
727 #define RENDERINPUTS_SET_RANGE BITSET64_SET_RANGE
728 #define RENDERINPUTS_CLEAR_RANGE BITSET64_CLEAR_RANGE
729
730
731 /**
732 * Context state for T&L context.
733 */
734 typedef struct
735 {
736 /* Driver interface.
737 */
738 struct tnl_device_driver Driver;
739
740 /* Execute:
741 */
742 struct tnl_vtx vtx;
743
744 /* Compile:
745 */
746 struct tnl_save save;
747
748 /* Pipeline
749 */
750 struct tnl_pipeline pipeline;
751 struct vertex_buffer vb;
752
753 /* GLvectors for binding to vb:
754 */
755 struct tnl_vertex_arrays vtx_inputs;
756 struct tnl_vertex_arrays save_inputs;
757 struct tnl_vertex_arrays current;
758 struct tnl_vertex_arrays array_inputs;
759
760 /* Clipspace/ndc/window vertex managment:
761 */
762 struct tnl_clipspace clipspace;
763
764 /* Probably need a better configuration mechanism:
765 */
766 GLboolean NeedNdcCoords;
767 GLboolean LoopbackDListCassettes;
768 GLboolean CalcDListNormalLengths;
769 GLboolean IsolateMaterials;
770 GLboolean AllowVertexFog;
771 GLboolean AllowPixelFog;
772 GLboolean AllowCodegen;
773
774 GLboolean _DoVertexFog; /* eval fog function at each vertex? */
775
776 /* If True, it means we started a glBegin/End primtive with an invalid
777 * vertex/fragment program or incomplete framebuffer. In that case,
778 * discard any buffered vertex data.
779 */
780 GLboolean DiscardPrimitive;
781
782 DECLARE_RENDERINPUTS(render_inputs_bitset);
783
784 GLvertexformat exec_vtxfmt;
785 GLvertexformat save_vtxfmt;
786
787 struct tnl_cache *vp_cache;
788
789 } TNLcontext;
790
791
792
793 #define TNL_CONTEXT(ctx) ((TNLcontext *)((ctx)->swtnl_context))
794
795
796 #define TYPE_IDX(t) ((t) & 0xf)
797 #define MAX_TYPES TYPE_IDX(GL_DOUBLE)+1 /* 0xa + 1 */
798
799
800 #endif