⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 via_tris.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 3 页
字号:
#define TAG(x) x##_twoside_offset_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (VIA_FALLBACK_BIT)#define TAG(x) x##_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (VIA_OFFSET_BIT|VIA_FALLBACK_BIT)#define TAG(x) x##_offset_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (VIA_TWOSIDE_BIT|VIA_FALLBACK_BIT)#define TAG(x) x##_twoside_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT|VIA_FALLBACK_BIT)#define TAG(x) x##_twoside_offset_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)#define TAG(x) x##_unfilled_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (VIA_OFFSET_BIT|VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)#define TAG(x) x##_offset_unfilled_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (VIA_TWOSIDE_BIT|VIA_UNFILLED_BIT|VIA_FALLBACK_BIT)#define TAG(x) x##_twoside_unfilled_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (VIA_TWOSIDE_BIT|VIA_OFFSET_BIT|VIA_UNFILLED_BIT| \             VIA_FALLBACK_BIT)#define TAG(x) x##_twoside_offset_unfilled_fallback#include "tnl_dd/t_dd_tritmp.h"/* Catchall case for flat, separate specular triangles (via has flat * diffuse shading, but always does specular color with gouraud). */#undef  DO_FALLBACK#undef  DO_OFFSET#undef  DO_UNFILLED#undef  DO_TWOSIDE#undef  DO_FLAT#define DO_FALLBACK (0)#define DO_OFFSET   (ctx->_TriangleCaps & DD_TRI_OFFSET)#define DO_UNFILLED (ctx->_TriangleCaps & DD_TRI_UNFILLED)#define DO_TWOSIDE  (ctx->_TriangleCaps & DD_TRI_LIGHT_TWOSIDE)#define DO_FLAT     1#define TAG(x) x##_flat_specular#define IND VIA_MAX_TRIFUNC#include "tnl_dd/t_dd_tritmp.h"static void init_rast_tab(void){    init();    init_offset();    init_twoside();    init_twoside_offset();    init_unfilled();    init_offset_unfilled();    init_twoside_unfilled();    init_twoside_offset_unfilled();    init_fallback();    init_offset_fallback();    init_twoside_fallback();    init_twoside_offset_fallback();    init_unfilled_fallback();    init_offset_unfilled_fallback();    init_twoside_unfilled_fallback();    init_twoside_offset_unfilled_fallback();    init_flat_specular();	/* special! */}/*********************************************************************** *                    Rasterization fallback helpers                   * ***********************************************************************//* This code is hit only when a mix of accelerated and unaccelerated * primitives are being drawn, and only for the unaccelerated * primitives. */static voidvia_fallback_tri(struct via_context *vmesa,                 viaVertex *v0,                 viaVertex *v1,                 viaVertex *v2){        GLcontext *ctx = vmesa->glCtx;    SWvertex v[3];    _swsetup_Translate(ctx, v0, &v[0]);    _swsetup_Translate(ctx, v1, &v[1]);    _swsetup_Translate(ctx, v2, &v[2]);    viaSpanRenderStart( ctx );    _swrast_Triangle(ctx, &v[0], &v[1], &v[2]);    viaSpanRenderFinish( ctx );}static voidvia_fallback_line(struct via_context *vmesa,                  viaVertex *v0,                  viaVertex *v1){    GLcontext *ctx = vmesa->glCtx;    SWvertex v[2];    _swsetup_Translate(ctx, v0, &v[0]);    _swsetup_Translate(ctx, v1, &v[1]);    viaSpanRenderStart( ctx );    _swrast_Line(ctx, &v[0], &v[1]);    viaSpanRenderFinish( ctx );}static voidvia_fallback_point(struct via_context *vmesa,                   viaVertex *v0){    GLcontext *ctx = vmesa->glCtx;    SWvertex v[1];    _swsetup_Translate(ctx, v0, &v[0]);    viaSpanRenderStart( ctx );    _swrast_Point(ctx, &v[0]);    viaSpanRenderFinish( ctx );}static void viaResetLineStipple( GLcontext *ctx ){   struct via_context *vmesa = VIA_CONTEXT(ctx);   vmesa->regCmdB |= HC_HLPrst_MASK;}/**********************************************************************//*               Render unclipped begin/end objects                   *//**********************************************************************/#define IND 0#define V(x) (viaVertex *)(vertptr + ((x) * vertsize * sizeof(int)))#define RENDER_POINTS(start, count)   \    for (; start < count; start++) POINT(V(ELT(start)));#define RENDER_LINE(v0, v1)         LINE(V(v0), V(v1))#define RENDER_TRI( v0, v1, v2)     TRI( V(v0), V(v1), V(v2))#define RENDER_QUAD(v0, v1, v2, v3) QUAD(V(v0), V(v1), V(v2), V(v3))#define INIT(x) viaRasterPrimitive(ctx, x, hwPrim[x])#undef LOCAL_VARS#define LOCAL_VARS                                              \    struct via_context *vmesa = VIA_CONTEXT(ctx);                     \    GLubyte *vertptr = (GLubyte *)vmesa->verts;                 \    const GLuint vertsize = vmesa->vertexSize;          \    const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts;       \   const GLboolean stipple = ctx->Line.StippleFlag;		\   (void) elt; (void) stipple;#define RESET_STIPPLE	if ( stipple ) viaResetLineStipple( ctx );#define RESET_OCCLUSION#define PRESERVE_VB_DEFS#define ELT(x) x#define TAG(x) via_##x##_verts#include "tnl/t_vb_rendertmp.h"#undef ELT#undef TAG#define TAG(x) via_##x##_elts#define ELT(x) elt[x]#include "tnl/t_vb_rendertmp.h"#undef ELT#undef TAG#undef NEED_EDGEFLAG_SETUP#undef EDGEFLAG_GET#undef EDGEFLAG_SET#undef RESET_OCCLUSION/**********************************************************************//*                   Render clipped primitives                        *//**********************************************************************/static void viaRenderClippedPoly(GLcontext *ctx, const GLuint *elts,                                 GLuint n){    TNLcontext *tnl = TNL_CONTEXT(ctx);    struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb;    GLuint prim = VIA_CONTEXT(ctx)->renderPrimitive;    /* Render the new vertices as an unclipped polygon.     */    {        GLuint *tmp = VB->Elts;        VB->Elts = (GLuint *)elts;        tnl->Driver.Render.PrimTabElts[GL_POLYGON](ctx, 0, n,                                                   PRIM_BEGIN|PRIM_END);        VB->Elts = tmp;    }    /* Restore the render primitive     */    if (prim != GL_POLYGON &&	prim != GL_POLYGON + 1)       tnl->Driver.Render.PrimitiveNotify( ctx, prim );}static void viaRenderClippedLine(GLcontext *ctx, GLuint ii, GLuint jj){    TNLcontext *tnl = TNL_CONTEXT(ctx);    tnl->Driver.Render.Line(ctx, ii, jj);}static void viaFastRenderClippedPoly(GLcontext *ctx, const GLuint *elts,                                     GLuint n){    struct via_context *vmesa = VIA_CONTEXT(ctx);    GLuint vertsize = vmesa->vertexSize;    GLuint *vb = viaExtendPrimitive(vmesa, (n - 2) * 3 * 4 * vertsize);    GLubyte *vertptr = (GLubyte *)vmesa->verts;    const GLuint *start = (const GLuint *)V(elts[0]);    int i;    for (i = 2; i < n; i++) {	COPY_DWORDS(vb, vertsize, V(elts[i - 1]));        COPY_DWORDS(vb, vertsize, V(elts[i]));	COPY_DWORDS(vb, vertsize, start);	    }}/**********************************************************************//*                    Choose render functions                         *//**********************************************************************/#define _VIA_NEW_VERTEX (_NEW_TEXTURE |                         \                         _DD_NEW_SEPARATE_SPECULAR |            \                         _DD_NEW_TRI_UNFILLED |                 \                         _DD_NEW_TRI_LIGHT_TWOSIDE |            \                         _NEW_FOG)#define _VIA_NEW_RENDERSTATE (_DD_NEW_LINE_STIPPLE |            \                              _DD_NEW_TRI_UNFILLED |            \                              _DD_NEW_TRI_LIGHT_TWOSIDE |       \                              _DD_NEW_TRI_OFFSET |              \                              _DD_NEW_TRI_STIPPLE |             \                              _NEW_POLYGONSTIPPLE)static void viaChooseRenderState(GLcontext *ctx){   TNLcontext *tnl = TNL_CONTEXT(ctx);   struct via_context *vmesa = VIA_CONTEXT(ctx);   GLuint flags = ctx->_TriangleCaps;   GLuint index = 0;   if (vmesa->ptexHack) {      vmesa->drawPoint = via_ptex_point;      vmesa->drawLine = via_ptex_line;      vmesa->drawTri = via_ptex_tri;      index |= VIA_FALLBACK_BIT;   }   else {      vmesa->drawPoint = via_draw_point;      vmesa->drawLine = via_draw_line;      vmesa->drawTri = via_draw_triangle;   }   if (flags & (ANY_FALLBACK_FLAGS | ANY_RASTER_FLAGS)) {      if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)         index |= VIA_TWOSIDE_BIT;      if (ctx->Polygon.FrontMode != GL_FILL || ctx->Polygon.BackMode != GL_FILL)         index |= VIA_UNFILLED_BIT;      if (flags & DD_TRI_OFFSET)         index |= VIA_OFFSET_BIT;      if (flags & ANY_FALLBACK_FLAGS)         index |= VIA_FALLBACK_BIT;      /* Hook in fallbacks for specific primitives. */      if (flags & POINT_FALLBACK)	 vmesa->drawPoint = via_fallback_point;            if (flags & LINE_FALLBACK)	 vmesa->drawLine = via_fallback_line;      if (flags & TRI_FALLBACK)	 vmesa->drawTri = via_fallback_tri;   }   if ((flags & DD_SEPARATE_SPECULAR) && ctx->Light.ShadeModel == GL_FLAT)      index = VIA_MAX_TRIFUNC;	/* flat specular */   if (vmesa->renderIndex != index) {      vmesa->renderIndex = index;      tnl->Driver.Render.Points = rast_tab[index].points;      tnl->Driver.Render.Line = rast_tab[index].line;      tnl->Driver.Render.Triangle = rast_tab[index].triangle;      tnl->Driver.Render.Quad = rast_tab[index].quad;      if (index == 0) {	 tnl->Driver.Render.PrimTabVerts = via_render_tab_verts;	 tnl->Driver.Render.PrimTabElts = via_render_tab_elts;	 tnl->Driver.Render.ClippedLine = line; /* from tritmp.h */	 tnl->Driver.Render.ClippedPolygon = viaFastRenderClippedPoly;      }      else {	 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;	 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;	 tnl->Driver.Render.ClippedLine = viaRenderClippedLine;	 tnl->Driver.Render.ClippedPolygon = viaRenderClippedPoly;      }   }}#define VIA_EMIT_TEX1	0x01#define VIA_EMIT_TEX0	0x02#define VIA_EMIT_PTEX0	0x04#define VIA_EMIT_RGBA	0x08#define VIA_EMIT_SPEC	0x10#define VIA_EMIT_FOG	0x20#define VIA_EMIT_W	0x40#define EMIT_ATTR( ATTR, STYLE, INDEX, REGB )				\do {									\   vmesa->vertex_attrs[vmesa->vertex_attr_count].attrib = (ATTR);	\   vmesa->vertex_attrs[vmesa->vertex_attr_count].format = (STYLE);	\   vmesa->vertex_attr_count++;						\   setupIndex |= (INDEX);						\   regCmdB |= (REGB);							\} while (0)#define EMIT_PAD( N )							\do {									\   vmesa->vertex_attrs[vmesa->vertex_attr_count].attrib = 0;		\   vmesa->vertex_attrs[vmesa->vertex_attr_count].format = EMIT_PAD;	\   vmesa->vertex_attrs[vmesa->vertex_attr_count].offset = (N);		\   vmesa->vertex_attr_count++;						\} while (0)static void viaChooseVertexState( GLcontext *ctx ){   struct via_context *vmesa = VIA_CONTEXT(ctx);   TNLcontext *tnl = TNL_CONTEXT(ctx);   DECLARE_RENDERINPUTS(index_bitset);   GLuint regCmdB = HC_HVPMSK_X | HC_HVPMSK_Y | HC_HVPMSK_Z;   GLuint setupIndex = 0;   RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset );   vmesa->vertex_attr_count = 0;    /* EMIT_ATTR's must be in order as they tell t_vertex.c how to    * build up a hardware vertex.    */   if (RENDERINPUTS_TEST_RANGE( index_bitset, _TNL_FIRST_TEX, _TNL_LAST_TEX ) ||       RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {      EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, VIA_EMIT_W, HC_HVPMSK_W );      vmesa->coloroffset = 4;   }   else {      EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_3F_VIEWPORT, 0, 0 );      vmesa->coloroffset = 3;   }   /* t_context.c always includes a diffuse color */   EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, VIA_EMIT_RGBA, 	      HC_HVPMSK_Cd );         vmesa->specoffset = 0;   if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ) ||       RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {      if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) {	 vmesa->specoffset = vmesa->coloroffset + 1;	 EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, VIA_EMIT_SPEC, 		    HC_HVPMSK_Cs );      }      else	 EMIT_PAD( 3 );      if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG ))	 EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, VIA_EMIT_FOG, HC_HVPMSK_Cs );      else	 EMIT_PAD( 1 );   }   if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX0 )) {      if (vmesa->ptexHack)	 EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_3F_XYW, VIA_EMIT_PTEX0, 		    (HC_HVPMSK_S | HC_HVPMSK_T) );      else 	 EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_2F, VIA_EMIT_TEX0, 		    (HC_HVPMSK_S | HC_HVPMSK_T) );   }   if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX1 )) {      EMIT_ATTR( _TNL_ATTRIB_TEX1, EMIT_2F, VIA_EMIT_TEX1, 		 (HC_HVPMSK_S | HC_HVPMSK_T) );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -