X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Ftnl%2Ft_context.h;h=c19eb3df3cbc799678ffa5df476a8c2a626ef5c7;hb=882cd6c839e56a3eceb8edf62f83893f6b531d35;hp=c375a5670bce1da6f1a86be0ec906186ab005752;hpb=ff56908e09c0351179478deb19677cf56eec1f64;p=mesa.git diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h index c375a5670bc..c19eb3df3cb 100644 --- a/src/mesa/tnl/t_context.h +++ b/src/mesa/tnl/t_context.h @@ -1,8 +1,8 @@ /* - * Mesa 3-D graphics library - * Version: 5.1 + * mesa 3-D graphics library + * Version: 6.5 * - * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -37,340 +37,219 @@ * necessary transformations (rotations, clipping, vertex shader etc.) * and passes then the output to the rasterizer. * - * The gl_pipeline contains the array of all stages, which should be + * The tnl_pipeline contains the array of all stages, which should be * applied. Each stage is a black-box, which is described by an - * gl_pipeline_stage. The function ::_tnl_run_pipeline applies all the + * tnl_pipeline_stage. The function ::_tnl_run_pipeline applies all the * stages to the vertex_buffer TNLcontext::vb, where the vertex data * is stored. The last stage in the pipeline is the rasterizer. * - * The initial vertex_buffer data may either come from an ::immediate - * structure or client vertex_arrays or display lists: - * - * - * - The ::immediate structure records all the GL commands issued between - * glBegin and glEnd. \n - * The structure accumulates data, until it is either full or it is - * flushed (usually by a state change). Before starting then the pipeline, - * the collected vertex data in ::immediate has to be pushed into - * TNLcontext::vb. - * This happens in ::_tnl_vb_bind_immediate. The pipeline is then run by - * calling tnl_device_driver::RunPipeline = ::_tnl_run_pipeline, which - * is stored in TNLcontext::Driver. \n - * An ::immediate does (for performance reasons) usually not finish with a - * glEnd, and hence it also does not need to start with a glBegin. - * This means that the last vertices of one ::immediate may need to be - * saved for the next one. - * - * - * - NOT SURE ABOUT THIS: The vertex_arrays structure is used to handle - * glDrawArrays etc. \n - * Here, the data of the vertex_arrays is copied by ::_tnl_vb_bind_arrays - * into TNLcontext::vb, so that the pipeline can be started. */ -/* What is ELT? */ #ifndef _T_CONTEXT_H #define _T_CONTEXT_H -#include "glheader.h" -#include "mtypes.h" +#include "main/glheader.h" +#include "main/bitset.h" +#include "main/mtypes.h" #include "math/m_matrix.h" #include "math/m_vector.h" #include "math/m_xform.h" +#include "vbo/vbo.h" #define MAX_PIPELINE_STAGES 30 - -/* Numbers for sizing immediate structs. +/* + * Note: The first attributes match the VERT_ATTRIB_* definitions + * in mtypes.h. However, the tnl module has additional attributes + * for materials, color indexes, edge flags, etc. */ -#define IMM_MAX_COPIED_VERTS 3 -#define IMM_MAXDATA (216 + IMM_MAX_COPIED_VERTS) -#define IMM_SIZE (IMM_MAXDATA + MAX_CLIPPED_VERTICES) - - -/* Values for IM->BeginState +/* Although it's nice to use these as bit indexes in a DWORD flag, we + * could manage without if necessary. Another limit currently is the + * number of bits allocated for these numbers in places like vertex + * program instruction formats and register layouts. */ -#define VERT_BEGIN_0 0x1 /* glBegin (if initially inside beg/end) */ -#define VERT_BEGIN_1 0x2 /* glBegin (if initially outside beg/end) */ -#define VERT_ERROR_0 0x4 /* invalid_operation in initial state 0 */ -#define VERT_ERROR_1 0x8 /* invalid_operation in initial state 1 */ - - -/* Flags to be added to the primitive enum in VB->Primitive. +/* The bit space exhaustion is a fact now, done by _TNL_ATTRIB_ATTRIBUTE* for + * GLSL vertex shader which cannot be aliased with conventional vertex attribs. + * Compacting _TNL_ATTRIB_MAT_* attribs would not work, they would not give + * as many free bits (11 plus already 1 free bit) as _TNL_ATTRIB_ATTRIBUTE* + * attribs want (16). */ -#define PRIM_MODE_MASK 0xff /* Extract the actual primitive */ -#define PRIM_BEGIN 0x100 /* The prim starts here (not wrapped) */ -#define PRIM_END 0x200 /* The prim ends in this VB (does not wrap) */ -#define PRIM_PARITY 0x400 /* The prim wrapped on an odd number of verts */ -#define PRIM_LAST 0x800 /* No more prims in the VB */ - +enum { + _TNL_ATTRIB_POS = 0, + _TNL_ATTRIB_WEIGHT = 1, + _TNL_ATTRIB_NORMAL = 2, + _TNL_ATTRIB_COLOR0 = 3, + _TNL_ATTRIB_COLOR1 = 4, + _TNL_ATTRIB_FOG = 5, + _TNL_ATTRIB_COLOR_INDEX = 6, + _TNL_ATTRIB_EDGEFLAG = 7, + _TNL_ATTRIB_TEX0 = 8, + _TNL_ATTRIB_TEX1 = 9, + _TNL_ATTRIB_TEX2 = 10, + _TNL_ATTRIB_TEX3 = 11, + _TNL_ATTRIB_TEX4 = 12, + _TNL_ATTRIB_TEX5 = 13, + _TNL_ATTRIB_TEX6 = 14, + _TNL_ATTRIB_TEX7 = 15, + + _TNL_ATTRIB_GENERIC0 = 16, /* doesn't really exist! */ + _TNL_ATTRIB_GENERIC1 = 17, + _TNL_ATTRIB_GENERIC2 = 18, + _TNL_ATTRIB_GENERIC3 = 19, + _TNL_ATTRIB_GENERIC4 = 20, + _TNL_ATTRIB_GENERIC5 = 21, + _TNL_ATTRIB_GENERIC6 = 22, + _TNL_ATTRIB_GENERIC7 = 23, + _TNL_ATTRIB_GENERIC8 = 24, + _TNL_ATTRIB_GENERIC9 = 25, + _TNL_ATTRIB_GENERIC10 = 26, + _TNL_ATTRIB_GENERIC11 = 27, + _TNL_ATTRIB_GENERIC12 = 28, + _TNL_ATTRIB_GENERIC13 = 29, + _TNL_ATTRIB_GENERIC14 = 30, + _TNL_ATTRIB_GENERIC15 = 31, + + /* These alias with the generics, but they are not active + * concurrently, so it's not a problem. The TNL module + * doesn't have to do anything about this as this is how they + * are passed into the _draw_prims callback. + * + * When we generate fixed-function replacement programs (in + * t_vp_build.c currently), they refer to the appropriate + * generic attribute in order to pick up per-vertex material + * data. + */ + _TNL_ATTRIB_MAT_FRONT_AMBIENT = 16, + _TNL_ATTRIB_MAT_BACK_AMBIENT = 17, + _TNL_ATTRIB_MAT_FRONT_DIFFUSE = 18, + _TNL_ATTRIB_MAT_BACK_DIFFUSE = 19, + _TNL_ATTRIB_MAT_FRONT_SPECULAR = 20, + _TNL_ATTRIB_MAT_BACK_SPECULAR = 21, + _TNL_ATTRIB_MAT_FRONT_EMISSION = 22, + _TNL_ATTRIB_MAT_BACK_EMISSION = 23, + _TNL_ATTRIB_MAT_FRONT_SHININESS = 24, + _TNL_ATTRIB_MAT_BACK_SHININESS = 25, + _TNL_ATTRIB_MAT_FRONT_INDEXES = 26, + _TNL_ATTRIB_MAT_BACK_INDEXES = 27, + + /* This is really a VERT_RESULT, not an attrib. Need to fix + * tnl to understand the difference. + */ + _TNL_ATTRIB_POINTSIZE = 16, + + _TNL_ATTRIB_MAX = 32 +} ; + +#define _TNL_ATTRIB_TEX(u) (_TNL_ATTRIB_TEX0 + (u)) +#define _TNL_ATTRIB_GENERIC(n) (_TNL_ATTRIB_GENERIC0 + (n)) + +/* special index used for handing invalid glVertexAttribute() indices */ +#define _TNL_ATTRIB_ERROR (_TNL_ATTRIB_GENERIC15 + 1) /** - * Flags that describe the inputs and outputs of pipeline stages, and - * the contents of a vertex-cassette. We reuse the VERT_BIT_* flags - * defined in mtypes.h and add a bunch of new ones. - */ -/* bits 0..5 defined in mtypes.h */ -#define VERT_BIT_INDEX VERT_BIT_SIX /* a free vertex attrib bit */ -#define VERT_BIT_EDGEFLAG VERT_BIT_SEVEN /* a free vertex attrib bit */ -/* bits 8..15 defined in mtypes.h */ -#define VERT_BIT_EVAL_C1 (1 << 16) /* imm only */ -#define VERT_BIT_EVAL_C2 (1 << 17) /* imm only */ -#define VERT_BIT_EVAL_P1 (1 << 18) /* imm only */ -#define VERT_BIT_EVAL_P2 (1 << 19) /* imm only */ -#define VERT_BIT_OBJ_3 (1 << 20) /* imm only */ -#define VERT_BIT_OBJ_4 (1 << 21) /* imm only */ -#define VERT_BIT_MATERIAL (1 << 22) /* imm only, but tested in vb code */ -#define VERT_BIT_ELT (1 << 23) /* imm only */ -#define VERT_BIT_BEGIN (1 << 24) /* imm only, but tested in vb code */ -#define VERT_BIT_END (1 << 25) /* imm only, but tested in vb code */ -#define VERT_BIT_END_VB (1 << 26) /* imm only, but tested in vb code */ -#define VERT_BIT_POINT_SIZE (1 << 27) /* vb only, could reuse a bit */ -#define VERT_BIT_EYE VERT_BIT_BEGIN /* vb only, reuse imm bit */ -#define VERT_BIT_CLIP VERT_BIT_END /* vb only, reuse imm bit*/ - - -/* Flags for IM->TexCoordSize. Enough flags for 16 units. - */ -#define TEX_0_SIZE_3 (unsigned)0x1 -#define TEX_0_SIZE_4 (unsigned)0x10001 -#define TEX_SIZE_3(unit) (TEX_0_SIZE_3 << (unit)) -#define TEX_SIZE_4(unit) (TEX_0_SIZE_4 << (unit)) - - -/* Shorthands. + * Handy attribute ranges: */ -#define VERT_BITS_OBJ_23 (VERT_BIT_POS | VERT_BIT_OBJ_3) -#define VERT_BITS_OBJ_234 (VERT_BIT_POS | VERT_BIT_OBJ_3 | VERT_BIT_OBJ_4) - -#define VERT_BITS_TEX_ANY (VERT_BIT_TEX0 | \ - VERT_BIT_TEX1 | \ - VERT_BIT_TEX2 | \ - VERT_BIT_TEX3 | \ - VERT_BIT_TEX4 | \ - VERT_BIT_TEX5 | \ - VERT_BIT_TEX6 | \ - VERT_BIT_TEX7) - -#define VERT_BITS_EVAL_ANY (VERT_BIT_EVAL_C1 | VERT_BIT_EVAL_P1 | \ - VERT_BIT_EVAL_C2 | VERT_BIT_EVAL_P2) - -#define VERT_BITS_FIXUP (VERT_BITS_TEX_ANY | \ - VERT_BIT_COLOR0 | \ - VERT_BIT_COLOR1 | \ - VERT_BIT_FOG | \ - VERT_BIT_INDEX | \ - VERT_BIT_EDGEFLAG | \ - VERT_BIT_NORMAL) - -#define VERT_BITS_CURRENT_DATA (VERT_BITS_FIXUP | \ - VERT_BIT_MATERIAL) - -#define VERT_BITS_DATA (VERT_BITS_TEX_ANY | \ - VERT_BIT_COLOR0 | \ - VERT_BIT_COLOR1 | \ - VERT_BIT_FOG | \ - VERT_BIT_INDEX | \ - VERT_BIT_EDGEFLAG | \ - VERT_BIT_NORMAL | \ - VERT_BIT_POS | \ - VERT_BIT_MATERIAL | \ - VERT_BIT_ELT | \ - VERT_BITS_EVAL_ANY) +#define _TNL_FIRST_PROG _TNL_ATTRIB_WEIGHT +#define _TNL_LAST_PROG _TNL_ATTRIB_TEX7 +#define _TNL_FIRST_TEX _TNL_ATTRIB_TEX0 +#define _TNL_LAST_TEX _TNL_ATTRIB_TEX7 -/** - * \struct immediate - * Stores everything that can take place between a glBegin and glEnd. - * Adjacent glBegin/glEnd pairs are stored back-to-back when there's no - * state changes between them. - * Used for immediate mode rendering and display lists. - */ -struct immediate -{ - GLuint id, ref_count; +#define _TNL_FIRST_GENERIC _TNL_ATTRIB_GENERIC0 +#define _TNL_LAST_GENERIC _TNL_ATTRIB_GENERIC15 - /* This must be saved when immediates are shared in display lists. - */ - GLuint CopyStart, Start, Count; - GLuint LastData; /* count or count+1 */ - GLuint AndFlag, OrFlag; - GLuint TexSize; /* keep track of texcoord sizes */ - GLuint BeginState, SavedBeginState; - GLuint LastPrimitive; - - GLuint ArrayEltFlags; /* precalc'ed for glArrayElt */ - GLuint ArrayEltIncr; - GLuint ArrayEltFlush; +#define _TNL_FIRST_MAT _TNL_ATTRIB_MAT_FRONT_AMBIENT /* GENERIC0 */ +#define _TNL_LAST_MAT _TNL_ATTRIB_MAT_BACK_INDEXES /* GENERIC11 */ -#define FLUSH_ELT_EAGER 0x1 -#define FLUSH_ELT_LAZY 0x2 - GLuint FlushElt; +/* Number of available generic attributes */ +#define _TNL_NUM_GENERIC 16 - GLuint MaxTextureUnits; /* precalc'ed for glMultiTexCoordARB */ +/* Number of attributes used for evaluators */ +#define _TNL_NUM_EVAL 16 - /* Temporary values created when vertices are copied into the - * first 3 slots of the struct: - */ - GLuint CopyOrFlag; - GLuint CopyAndFlag; - GLuint CopyTexSize; - GLuint Evaluated; +#define PRIM_BEGIN 0x10 +#define PRIM_END 0x20 +#define PRIM_MODE_MASK 0x0f - /* allocate storage for these on demand: - */ - struct gl_material *Material; - GLuint *MaterialMask; - GLuint LastMaterial; - GLuint MaterialOrMask; - GLuint MaterialAndMask; - - GLuint Primitive[IMM_SIZE]; /* BEGIN/END */ - GLuint PrimitiveLength[IMM_SIZE]; /* BEGIN/END */ - GLuint Flag[IMM_SIZE]; /* VERT_BIT_* flags */ - - /* Attrib is an array [MAX_VERT_ATTRIBS] of pointer to array [][4] - * of GLfloat. - * We only pre-allocate the vertex position array. The other vertex - * attribute arrays are only allocated when needed to save memory. - */ - GLfloat (*Attrib[VERT_ATTRIB_MAX])[4]; +static INLINE GLuint _tnl_translate_prim( const struct _mesa_prim *prim ) +{ + GLuint flag; + flag = prim->mode; + if (prim->begin) flag |= PRIM_BEGIN; + if (prim->end) flag |= PRIM_END; + return flag; +} - GLfloat *NormalLengthPtr; /* length of normal vectors (display list only) */ - GLuint Elt[IMM_SIZE]; - GLubyte EdgeFlag[IMM_SIZE]; - GLuint Index[IMM_SIZE]; -}; - - -struct vertex_arrays -{ - /* Conventional vertex attribute arrays */ - GLvector4f Obj; - GLvector4f Normal; - struct gl_client_array Color; - struct gl_client_array SecondaryColor; - GLvector4f FogCoord; - GLvector4f TexCoord[MAX_TEXTURE_COORD_UNITS]; - GLvector1ub EdgeFlag; - GLvector1ui Index; - GLvector1ui Elt; - - /* These attributes don't alias with the conventional attributes. - * The GL_NV_vertex_program extension defines 16 extra sets of vertex - * arrays which have precedent over the conventional arrays when enabled. - */ - GLvector4f Attribs[VERT_ATTRIB_MAX]; -}; /** * Contains the current state of a running pipeline. */ -typedef struct vertex_buffer +struct vertex_buffer { - /* Constant over life of the vertex_buffer. - */ - GLuint Size; + GLuint Size; /**< Max vertices per vertex buffer, constant */ /* Constant over the pipeline. */ - GLuint Count; /* for everything except Elts */ - GLuint FirstClipped; /* temp verts for clipping */ - GLuint FirstPrimitive; /* usually zero */ + GLuint Count; /**< Number of vertices currently in buffer */ /* Pointers to current data. + * XXX some of these fields alias AttribPtr below and should be removed + * such as NormalPtr, TexCoordPtr, FogCoordPtr, etc. */ - GLuint *Elts; /* VERT_BIT_ELT */ - GLvector4f *ObjPtr; /* VERT_BIT_POS */ - GLvector4f *EyePtr; /* VERT_BIT_EYE */ - GLvector4f *ClipPtr; /* VERT_BIT_CLIP */ - GLvector4f *NdcPtr; /* VERT_BIT_CLIP (2) */ - GLubyte ClipOrMask; /* VERT_BIT_CLIP (3) */ - GLubyte *ClipMask; /* VERT_BIT_CLIP (4) */ - GLvector4f *NormalPtr; /* VERT_BIT_NORMAL */ - GLfloat *NormalLengthPtr; /* VERT_BIT_NORMAL */ - GLboolean *EdgeFlag; /* VERT_BIT_EDGEFLAG */ + GLuint *Elts; + GLvector4f *ObjPtr; /* _TNL_BIT_POS */ + GLvector4f *EyePtr; /* _TNL_BIT_POS */ + GLvector4f *ClipPtr; /* _TNL_BIT_POS */ + GLvector4f *NdcPtr; /* _TNL_BIT_POS */ + GLubyte ClipOrMask; /* _TNL_BIT_POS */ + GLubyte ClipAndMask; /* _TNL_BIT_POS */ + GLubyte *ClipMask; /* _TNL_BIT_POS */ + GLvector4f *NormalPtr; /* _TNL_BIT_NORMAL */ + GLfloat *NormalLengthPtr; /* _TNL_BIT_NORMAL */ + GLboolean *EdgeFlag; /* _TNL_BIT_EDGEFLAG */ GLvector4f *TexCoordPtr[MAX_TEXTURE_COORD_UNITS]; /* VERT_TEX_0..n */ - GLvector1ui *IndexPtr[2]; /* VERT_BIT_INDEX */ - struct gl_client_array *ColorPtr[2]; /* VERT_BIT_COLOR0 */ - struct gl_client_array *SecondaryColorPtr[2];/* VERT_BIT_COLOR1 */ - GLvector4f *PointSizePtr; /* VERT_BIT_POINT_SIZE */ - GLvector4f *FogCoordPtr; /* VERT_BIT_FOG */ - struct gl_material *Material; /* VERT_BIT_MATERIAL, optional */ - GLuint *MaterialMask; /* VERT_BIT_MATERIAL, optional */ - GLuint *Flag; /* VERT_BIT_* flags, optional */ - GLuint *Primitive; /* GL_(mode)|PRIM_* flags */ - GLuint *PrimitiveLength; /* integers */ - - /* Inputs to the vertex program stage */ - GLvector4f *AttribPtr[VERT_ATTRIB_MAX]; /* GL_NV_vertex_program */ - - GLuint importable_data; - void *import_source; - void (*import_data)( GLcontext *ctx, GLuint flags, GLuint vecflags ); - /* Callback to the provider of the untransformed input for the - * render stage (or other stages) to call if they need to write into - * write-protected arrays, or fixup the stride on input arrays. - * - * This is currently only necessary for client arrays that make it - * as far down the pipeline as the render stage. - */ + GLvector4f *IndexPtr[2]; /* _TNL_BIT_INDEX */ + GLvector4f *ColorPtr[2]; /* _TNL_BIT_COLOR0 */ + GLvector4f *SecondaryColorPtr[2]; /* _TNL_BIT_COLOR1 */ + GLvector4f *FogCoordPtr; /* _TNL_BIT_FOG */ - GLuint LastClipped; - /* Private data from _tnl_render_stage that has no business being - * in this struct. - */ - -} TNLvertexbuffer; + const struct _mesa_prim *Primitive; + GLuint PrimitiveCount; + /* Inputs to the vertex program stage */ + GLvector4f *AttribPtr[_TNL_ATTRIB_MAX]; /* GL_NV_vertex_program */ +}; -/** Describes an individual operation on the pipeline. +/** + * Describes an individual operation on the pipeline. */ -struct gl_pipeline_stage { +struct tnl_pipeline_stage +{ const char *name; - GLuint check_state; /* All state referenced in check() -- - * When is the pipeline_stage struct - * itself invalidated? Must be - * constant. - */ - - /* Usually constant or set by the 'check' callback: - */ - GLuint run_state; /* All state referenced in run() -- - * When is the cached output of the - * stage invalidated? - */ - - GLboolean active; /* True if runnable in current state */ - GLuint inputs; /* VERT_* inputs to the stage */ - GLuint outputs; /* VERT_* outputs of the stage */ - - /* Set in _tnl_run_pipeline(): - */ - GLuint changed_inputs; /* Generated value -- inputs to the - * stage that have changed since last - * call to 'run'. - */ /* Private data for the pipeline stage: */ void *privatePtr; - /* Free private data. May not be null. + /* Allocate private data */ - void (*destroy)( struct gl_pipeline_stage * ); + GLboolean (*create)( GLcontext *ctx, struct tnl_pipeline_stage * ); - /* Called from _tnl_validate_pipeline(). Must update all fields in - * the pipeline_stage struct for the current state. + /* Free private data. */ - void (*check)( GLcontext *ctx, struct gl_pipeline_stage * ); + void (*destroy)( struct tnl_pipeline_stage * ); + + /* Called on any statechange or input array size change or + * input array change to/from zero stride. + */ + void (*validate)( GLcontext *ctx, struct tnl_pipeline_stage * ); /* Called from _tnl_run_pipeline(). The stage.changed_inputs value * encodes all inputs to thee struct which have changed. If @@ -380,51 +259,135 @@ struct gl_pipeline_stage { * Return value: GL_TRUE - keep going * GL_FALSE - finished pipeline */ - GLboolean (*run)( GLcontext *ctx, struct gl_pipeline_stage * ); + GLboolean (*run)( GLcontext *ctx, struct tnl_pipeline_stage * ); }; + + /** Contains the array of all pipeline stages. - * The default values are defined at the end of t_pipeline.c */ -struct gl_pipeline { - GLuint build_state_trigger; /**< state changes which require build */ - GLuint build_state_changes; /**< state changes since last build */ - GLuint run_state_changes; /**< state changes since last run */ - GLuint run_input_changes; /**< VERT_* changes since last run */ - GLuint inputs; /**< VERT_* inputs to pipeline */ - /** This array has to end with a NULL-pointer. */ - struct gl_pipeline_stage stages[MAX_PIPELINE_STAGES+1]; + * The default values are defined at the end of t_pipeline.c + */ +struct tnl_pipeline { + + GLuint last_attrib_stride[_TNL_ATTRIB_MAX]; + GLuint last_attrib_size[_TNL_ATTRIB_MAX]; + GLuint input_changes; + GLuint new_state; + + struct tnl_pipeline_stage stages[MAX_PIPELINE_STAGES+1]; GLuint nr_stages; }; +struct tnl_clipspace; +struct tnl_clipspace_attr; + +typedef void (*tnl_extract_func)( const struct tnl_clipspace_attr *a, + GLfloat *out, + const GLubyte *v ); + +typedef void (*tnl_insert_func)( const struct tnl_clipspace_attr *a, + GLubyte *v, + const GLfloat *in ); -struct tnl_eval_store { - GLuint EvalMap1Flags; - GLuint EvalMap2Flags; - GLuint EvalMap1AttribFlags; /* GL_NV_vertex_program */ - GLuint EvalMap2AttribFlags; /* GL_NV_vertex_program */ - GLuint EvalNewState; - struct immediate *im; /* used for temporary data */ +typedef void (*tnl_emit_func)( GLcontext *ctx, + GLuint count, + GLubyte *dest ); + + +/** + * Describes how to convert/move a vertex attribute from a vertex array + * to a vertex structure. + */ +struct tnl_clipspace_attr +{ + GLuint attrib; /* which vertex attrib (0=position, etc) */ + GLuint format; + GLuint vertoffset; /* position of the attrib in the vertex struct */ + GLuint vertattrsize; /* size of the attribute in bytes */ + GLubyte *inputptr; + GLuint inputstride; + GLuint inputsize; + const tnl_insert_func *insert; + tnl_insert_func emit; + tnl_extract_func extract; + const GLfloat *vp; /* NDC->Viewport mapping matrix */ +}; + + + + +typedef void (*tnl_points_func)( GLcontext *ctx, GLuint first, GLuint last ); +typedef void (*tnl_line_func)( GLcontext *ctx, GLuint v1, GLuint v2 ); +typedef void (*tnl_triangle_func)( GLcontext *ctx, + GLuint v1, GLuint v2, GLuint v3 ); +typedef void (*tnl_quad_func)( GLcontext *ctx, GLuint v1, GLuint v2, + GLuint v3, GLuint v4 ); +typedef void (*tnl_render_func)( GLcontext *ctx, GLuint start, GLuint count, + GLuint flags ); +typedef void (*tnl_interp_func)( GLcontext *ctx, + GLfloat t, GLuint dst, GLuint out, GLuint in, + GLboolean force_boundary ); +typedef void (*tnl_copy_pv_func)( GLcontext *ctx, GLuint dst, GLuint src ); +typedef void (*tnl_setup_func)( GLcontext *ctx, + GLuint start, GLuint end, + GLuint new_inputs); + + +struct tnl_attr_type { + GLuint format; + GLuint size; + GLuint stride; + GLuint offset; +}; + +struct tnl_clipspace_fastpath { + GLuint vertex_size; + GLuint attr_count; + GLboolean match_strides; + + struct tnl_attr_type *attr; + + tnl_emit_func func; + struct tnl_clipspace_fastpath *next; +}; + +/** + * Used to describe conversion of vertex arrays to vertex structures. + * I.e. Structure of arrays to arrays of structs. + */ +struct tnl_clipspace +{ + GLboolean need_extras; + + GLuint new_inputs; + + GLubyte *vertex_buf; + GLuint vertex_size; + GLuint max_vertex_size; + + struct tnl_clipspace_attr attr[_TNL_ATTRIB_MAX]; + GLuint attr_count; + + tnl_emit_func emit; + tnl_interp_func interp; + tnl_copy_pv_func copy_pv; + + /* Parameters and constants for codegen: + */ + GLboolean need_viewport; + GLfloat vp_scale[4]; + GLfloat vp_xlate[4]; + GLfloat chan_scale[4]; + GLfloat identity[4]; + + struct tnl_clipspace_fastpath *fastpath; + + void (*codegen_emit)( GLcontext *ctx ); }; -typedef void (*points_func)( GLcontext *ctx, GLuint first, GLuint last ); -typedef void (*line_func)( GLcontext *ctx, GLuint v1, GLuint v2 ); -typedef void (*triangle_func)( GLcontext *ctx, - GLuint v1, GLuint v2, GLuint v3 ); -typedef void (*quad_func)( GLcontext *ctx, GLuint v1, GLuint v2, - GLuint v3, GLuint v4 ); -typedef void (*render_func)( GLcontext *ctx, GLuint start, GLuint count, - GLuint flags ); -typedef void (*interp_func)( GLcontext *ctx, - GLfloat t, GLuint dst, GLuint out, GLuint in, - GLboolean force_boundary ); -typedef void (*copy_pv_func)( GLcontext *ctx, GLuint dst, GLuint src ); -typedef void (*setup_func)( GLcontext *ctx, - GLuint start, GLuint end, - GLuint new_inputs); - - -struct tnl_device_driver { +struct tnl_device_driver +{ /*** *** TNL Pipeline ***/ @@ -439,16 +402,16 @@ struct tnl_device_driver { /* Alert tnl-aware drivers of changes to material. */ - GLboolean (*NotifyBegin)(GLcontext *ctx, GLenum p); - /* Allow drivers to hook in optimized begin/end engines. - * Return value: GL_TRUE - driver handled the begin - * GL_FALSE - driver didn't handle the begin + void (*NotifyInputChanges)(GLcontext *ctx, GLuint bitmask); + /* Alert tnl-aware drivers of changes to size and stride of input + * arrays. */ /*** *** Rendering -- These functions called only from t_vb_render.c ***/ - struct { + struct + { void (*Start)(GLcontext *ctx); void (*Finish)(GLcontext *ctx); /* Called before and after all rendering operations, including DrawPixels, @@ -462,14 +425,14 @@ struct tnl_device_driver { * modes accepted by glBegin(). */ - interp_func Interp; + tnl_interp_func Interp; /* The interp function is called by the clipping routines when we need * to generate an interpolated vertex. All pertinant vertex ancilliary * data should be computed by interpolating between the 'in' and 'out' * vertices. */ - copy_pv_func CopyPV; + tnl_copy_pv_func CopyPV; /* The copy function is used to make a copy of a vertex. All pertinant * vertex attributes should be copied. */ @@ -482,16 +445,16 @@ struct tnl_device_driver { void (*ClippedLine)( GLcontext *ctx, GLuint v0, GLuint v1 ); /* Render a line between the two vertices given by indexes v0 and v1. */ - points_func Points; /* must now respect vb->elts */ - line_func Line; - triangle_func Triangle; - quad_func Quad; + tnl_points_func Points; /* must now respect vb->elts */ + tnl_line_func Line; + tnl_triangle_func Triangle; + tnl_quad_func Quad; /* These functions are called in order to render points, lines, * triangles and quads. These are only called via the T&L module. */ - render_func *PrimTabVerts; - render_func *PrimTabElts; + tnl_render_func *PrimTabVerts; + tnl_render_func *PrimTabElts; /* Render whole unclipped primitives (points, lines, linestrips, * lineloops, etc). The tables are indexed by the GL enum of the * primitive to be rendered. RenderTabVerts is used for non-indexed @@ -503,7 +466,7 @@ struct tnl_device_driver { /* Reset the hardware's line stipple counter. */ - setup_func BuildVertices; + tnl_setup_func BuildVertices; /* This function is called whenever new vertices are required for * rendering. The vertices in question are those n such that start * <= n < end. The new_inputs parameter indicates those fields of @@ -525,106 +488,64 @@ struct tnl_device_driver { */ } Render; }; - -typedef struct { - /* Driver interface. - */ - struct tnl_device_driver Driver; +#define DECLARE_RENDERINPUTS(name) BITSET64_DECLARE(name, _TNL_ATTRIB_MAX) +#define RENDERINPUTS_COPY BITSET64_COPY +#define RENDERINPUTS_EQUAL BITSET64_EQUAL +#define RENDERINPUTS_ZERO BITSET64_ZERO +#define RENDERINPUTS_ONES BITSET64_ONES +#define RENDERINPUTS_TEST BITSET64_TEST +#define RENDERINPUTS_SET BITSET64_SET +#define RENDERINPUTS_CLEAR BITSET64_CLEAR +#define RENDERINPUTS_TEST_RANGE BITSET64_TEST_RANGE +#define RENDERINPUTS_SET_RANGE BITSET64_SET_RANGE +#define RENDERINPUTS_CLEAR_RANGE BITSET64_CLEAR_RANGE - /* Track whether the module is active. - */ - GLboolean bound_exec; - /* Display list extensions +/** + * Context state for T&L context. + */ +typedef struct +{ + /* Driver interface. */ - GLuint opcode_vertex_cassette; + struct tnl_device_driver Driver; /* Pipeline */ - struct gl_pipeline pipeline; + struct tnl_pipeline pipeline; struct vertex_buffer vb; - /* GLvectors for binding to vb: - */ - struct vertex_arrays imm_inputs; - struct vertex_arrays array_inputs; - GLuint *tmp_primitive; - GLuint *tmp_primitive_length; - - /* Set when executing an internally generated begin/end object. If - * such an object is encountered in a display list, it will be - * replayed only if the list is outside any existing begin/end - * objects. + /* Clipspace/ndc/window vertex managment: */ - GLboolean ReplayHardBeginEnd; - - /* Note which vertices need copying over succesive immediates. - * Will add save versions to precompute vertex copying where - * possible. - */ - struct immediate *ExecCopySource; - GLuint ExecCopyCount; - GLuint ExecCopyElts[IMM_MAX_COPIED_VERTS]; - GLuint ExecCopyTexSize; - GLuint ExecParity; - - GLuint DlistPrimitive; - GLuint DlistPrimitiveLength; - GLuint DlistLastPrimitive; - - /* Cache a single free immediate (refcount == 0) - */ - struct immediate *freed_immediate; + struct tnl_clipspace clipspace; /* Probably need a better configuration mechanism: */ GLboolean NeedNdcCoords; - GLboolean LoopbackDListCassettes; - GLboolean CalcDListNormalLengths; - GLboolean IsolateMaterials; + GLboolean AllowVertexFog; + GLboolean AllowPixelFog; + GLboolean _DoVertexFog; /* eval fog function at each vertex? */ - /* Derived state and storage for _tnl_eval_vb: - */ - struct tnl_eval_store eval; + DECLARE_RENDERINPUTS(render_inputs_bitset); + + GLvector4f tmp_inputs[VERT_ATTRIB_MAX]; - /* Functions to be plugged into dispatch when tnl is active. + /* Temp storage for t_draw.c: */ - GLvertexformat vtxfmt; - GLvertexformat save_vtxfmt; + GLubyte *block[VERT_ATTRIB_MAX]; + GLuint nr_blocks; } TNLcontext; -#define TNL_CONTEXT(ctx) ((TNLcontext *)(ctx->swtnl_context)) -#define TNL_CURRENT_IM(ctx) ((struct immediate *)(ctx->swtnl_im)) +#define TNL_CONTEXT(ctx) ((TNLcontext *)((ctx)->swtnl_context)) #define TYPE_IDX(t) ((t) & 0xf) #define MAX_TYPES TYPE_IDX(GL_DOUBLE)+1 /* 0xa + 1 */ -extern void _tnl_MakeCurrent( GLcontext *ctx, - GLframebuffer *drawBuffer, - GLframebuffer *readBuffer ); - - -/* - * Macros for fetching current input buffer. - */ -#ifdef THREADS -#define GET_IMMEDIATE struct immediate *IM = TNL_CURRENT_IM(((GLcontext *) (_glapi_Context ? _glapi_Context : _glapi_get_context()))) -#define SET_IMMEDIATE(ctx, im) ctx->swtnl_im = (void *)im -#else -extern struct immediate *_tnl_CurrentInput; -#define GET_IMMEDIATE struct immediate *IM = _tnl_CurrentInput -#define SET_IMMEDIATE(ctx, im) \ -do { \ - ctx->swtnl_im = (void *)im; \ - _tnl_CurrentInput = im; \ -} while (0) -#endif - #endif