t_context.h
来自「mesa-6.5-minigui源码」· C头文件 代码 · 共 805 行 · 第 1/2 页
H
805 行
/* * mesa 3-D graphics library * Version: 6.5 * * Copyright (C) 1999-2005 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"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *//** * \file t_context.h * \brief TnL module datatypes and definitions. * \author Keith Whitwell *//** * \mainpage The TNL-module * * TNL stands for "transform and lighting", i.e. this module implements * a pipeline that receives as input a buffer of vertices and does all * necessary transformations (rotations, clipping, vertex shader etc.) * and passes then the output to the rasterizer. * * The tnl_pipeline contains the array of all stages, which should be * applied. Each stage is a black-box, which is described by an * 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. */#ifndef _T_CONTEXT_H#define _T_CONTEXT_H#include "glheader.h"#include "mtypes.h"#include "math/m_matrix.h"#include "math/m_vector.h"#include "math/m_xform.h"#define MAX_PIPELINE_STAGES 30/* * 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. *//* 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. */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_SIX = 6, _TNL_ATTRIB_SEVEN = 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_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, _TNL_ATTRIB_INDEX = 28, _TNL_ATTRIB_EDGEFLAG = 29, _TNL_ATTRIB_POINTSIZE = 30, _TNL_ATTRIB_MAX = 31} ;/* Will probably have to revise this scheme fairly shortly, eg. by * compacting all the MAT flags down to one bit, or by using two * dwords to store the flags. */#define _TNL_BIT_POS (1<<0)#define _TNL_BIT_WEIGHT (1<<1)#define _TNL_BIT_NORMAL (1<<2)#define _TNL_BIT_COLOR0 (1<<3)#define _TNL_BIT_COLOR1 (1<<4)#define _TNL_BIT_FOG (1<<5)#define _TNL_BIT_SIX (1<<6)#define _TNL_BIT_SEVEN (1<<7)#define _TNL_BIT_TEX0 (1<<8)#define _TNL_BIT_TEX1 (1<<9)#define _TNL_BIT_TEX2 (1<<10)#define _TNL_BIT_TEX3 (1<<11)#define _TNL_BIT_TEX4 (1<<12)#define _TNL_BIT_TEX5 (1<<13)#define _TNL_BIT_TEX6 (1<<14)#define _TNL_BIT_TEX7 (1<<15)#define _TNL_BIT_MAT_FRONT_AMBIENT (1<<16)#define _TNL_BIT_MAT_BACK_AMBIENT (1<<17)#define _TNL_BIT_MAT_FRONT_DIFFUSE (1<<18)#define _TNL_BIT_MAT_BACK_DIFFUSE (1<<19)#define _TNL_BIT_MAT_FRONT_SPECULAR (1<<20)#define _TNL_BIT_MAT_BACK_SPECULAR (1<<21)#define _TNL_BIT_MAT_FRONT_EMISSION (1<<22)#define _TNL_BIT_MAT_BACK_EMISSION (1<<23)#define _TNL_BIT_MAT_FRONT_SHININESS (1<<24)#define _TNL_BIT_MAT_BACK_SHININESS (1<<25)#define _TNL_BIT_MAT_FRONT_INDEXES (1<<26)#define _TNL_BIT_MAT_BACK_INDEXES (1<<27)#define _TNL_BIT_INDEX (1<<28)#define _TNL_BIT_EDGEFLAG (1<<29)#define _TNL_BIT_POINTSIZE (1<<30)#define _TNL_BIT_TEX(u) (1 << (_TNL_ATTRIB_TEX0 + (u)))#define _TNL_BITS_MAT_ANY (_TNL_BIT_MAT_FRONT_AMBIENT | \ _TNL_BIT_MAT_BACK_AMBIENT | \ _TNL_BIT_MAT_FRONT_DIFFUSE | \ _TNL_BIT_MAT_BACK_DIFFUSE | \ _TNL_BIT_MAT_FRONT_SPECULAR | \ _TNL_BIT_MAT_BACK_SPECULAR | \ _TNL_BIT_MAT_FRONT_EMISSION | \ _TNL_BIT_MAT_BACK_EMISSION | \ _TNL_BIT_MAT_FRONT_SHININESS | \ _TNL_BIT_MAT_BACK_SHININESS | \ _TNL_BIT_MAT_FRONT_INDEXES | \ _TNL_BIT_MAT_BACK_INDEXES)#define _TNL_BITS_TEX_ANY (_TNL_BIT_TEX0 | \ _TNL_BIT_TEX1 | \ _TNL_BIT_TEX2 | \ _TNL_BIT_TEX3 | \ _TNL_BIT_TEX4 | \ _TNL_BIT_TEX5 | \ _TNL_BIT_TEX6 | \ _TNL_BIT_TEX7)#define _TNL_BITS_PROG_ANY (_TNL_BIT_POS | \ _TNL_BIT_WEIGHT | \ _TNL_BIT_NORMAL | \ _TNL_BIT_COLOR0 | \ _TNL_BIT_COLOR1 | \ _TNL_BIT_FOG | \ _TNL_BIT_SIX | \ _TNL_BIT_SEVEN | \ _TNL_BITS_TEX_ANY)#define PRIM_BEGIN 0x10#define PRIM_END 0x20#define PRIM_WEAK 0x40#define PRIM_MODE_MASK 0x0f/* */struct tnl_prim { GLuint mode; GLuint start; GLuint count;};struct tnl_eval1_map { struct gl_1d_map *map; GLuint sz;};struct tnl_eval2_map { struct gl_2d_map *map; GLuint sz;};struct tnl_eval { GLuint new_state; struct tnl_eval1_map map1[_TNL_ATTRIB_INDEX + 1]; struct tnl_eval2_map map2[_TNL_ATTRIB_INDEX + 1];};#define TNL_MAX_PRIM 16#define TNL_MAX_COPIED_VERTS 3struct tnl_copied_vtx { GLfloat buffer[_TNL_ATTRIB_MAX * 4 * TNL_MAX_COPIED_VERTS]; GLuint nr;};#define VERT_BUFFER_SIZE 2048 /* 8kbytes */typedef void (*tnl_attrfv_func)( const GLfloat * );struct _tnl_dynfn { struct _tnl_dynfn *next, *prev; GLuint key; char *code;};struct _tnl_dynfn_lists { struct _tnl_dynfn Vertex[4]; struct _tnl_dynfn Attribute[4];};struct _tnl_dynfn_generators { struct _tnl_dynfn *(*Vertex[4])( GLcontext *ctx, int key ); struct _tnl_dynfn *(*Attribute[4])( GLcontext *ctx, int key );};#define _TNL_MAX_ATTR_CODEGEN 16 /* The assembly of vertices in immediate mode is separated from * display list compilation. This allows a simpler immediate mode * treatment and a display list compiler better suited to * hardware-acceleration. */struct tnl_vtx { GLfloat buffer[VERT_BUFFER_SIZE]; GLubyte attrsz[_TNL_ATTRIB_MAX]; GLuint vertex_size; struct tnl_prim prim[TNL_MAX_PRIM]; GLuint prim_count; GLfloat *vbptr; /* cursor, points into buffer */ GLfloat vertex[_TNL_ATTRIB_MAX*4]; /* current vertex */ GLfloat *attrptr[_TNL_ATTRIB_MAX]; /* points into vertex */ GLfloat *current[_TNL_ATTRIB_MAX]; /* points into ctx->Current, etc */ GLfloat CurrentFloatEdgeFlag; GLuint counter, initial_counter; struct tnl_copied_vtx copied; tnl_attrfv_func tabfv[_TNL_MAX_ATTR_CODEGEN+1][4]; /* plus 1 for ERROR_ATTRIB */ struct _tnl_dynfn_lists cache; struct _tnl_dynfn_generators gen; struct tnl_eval eval; GLboolean *edgeflag_tmp; GLboolean have_materials;};/* For display lists, this structure holds a run of vertices of the * same format, and a strictly well-formed set of begin/end pairs, * starting on the first vertex and ending at the last. Vertex * copying on buffer breaks is precomputed according to these * primitives, though there are situations where the copying will need * correction at execute-time, perhaps by replaying the list as * immediate mode commands. * * On executing this list, the 'current' values may be updated with * the values of the final vertex, and often no fixup of the start of * the vertex list is required. * * Eval and other commands that don't fit into these vertex lists are * compiled using the fallback opcode mechanism provided by dlist.c. */struct tnl_vertex_list { GLubyte attrsz[_TNL_ATTRIB_MAX]; GLuint vertex_size; GLfloat *buffer; GLuint count; GLuint wrap_count; /* number of copied vertices at start */ GLboolean have_materials; /* bit of a hack - quick check for materials */ GLboolean dangling_attr_ref; /* current attr implicitly referenced outside the list */ GLfloat *normal_lengths; struct tnl_prim *prim; GLuint prim_count; struct tnl_vertex_store *vertex_store; struct tnl_primitive_store *prim_store;};/* These buffers should be a reasonable size to support upload to * hardware? Maybe drivers should stitch them back together, or * specify a desired size? */#define SAVE_BUFFER_SIZE (16*1024)#define SAVE_PRIM_SIZE 128/* Storage to be shared among several vertex_lists. */struct tnl_vertex_store { GLfloat buffer[SAVE_BUFFER_SIZE]; GLuint used; GLuint refcount;};struct tnl_primitive_store { struct tnl_prim buffer[SAVE_PRIM_SIZE]; GLuint used; GLuint refcount;};struct tnl_save { GLubyte attrsz[_TNL_ATTRIB_MAX]; GLuint vertex_size; GLfloat *buffer; GLuint count; GLuint wrap_count; GLuint replay_flags; struct tnl_prim *prim; GLuint prim_count, prim_max; struct tnl_vertex_store *vertex_store; struct tnl_primitive_store *prim_store; GLfloat *vbptr; /* cursor, points into buffer */ GLfloat vertex[_TNL_ATTRIB_MAX*4]; /* current values */ GLfloat *attrptr[_TNL_ATTRIB_MAX]; GLuint counter, initial_counter; GLboolean dangling_attr_ref; GLboolean have_materials; GLuint opcode_vertex_list; struct tnl_copied_vtx copied; GLfloat CurrentFloatEdgeFlag; GLfloat *current[_TNL_ATTRIB_MAX]; /* points into ctx->ListState */ GLubyte *currentsz[_TNL_ATTRIB_MAX]; void (*tabfv[_TNL_ATTRIB_MAX][4])( const GLfloat * );};struct tnl_vertex_arrays{ /* Conventional vertex attribute arrays */ GLvector4f Obj; GLvector4f Normal; GLvector4f Color; GLvector4f SecondaryColor; GLvector4f FogCoord; GLvector4f TexCoord[MAX_TEXTURE_COORD_UNITS]; GLvector4f Index;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?