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