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