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

📄 sis_tris.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 3 页
字号:
#define DEPTH_SCALE smesa->depth_scale#define UNFILLED_TRI unfilled_tri#define UNFILLED_QUAD unfilled_quad#define VERT_X(_v) _v->v.x#define VERT_Y(_v) _v->v.y#define VERT_Z(_v) _v->v.z#define AREA_IS_CCW( a ) (a > 0)#define GET_VERTEX(e) (smesa->verts + (e * smesa->vertex_size * sizeof(int)))#define VERT_SET_RGBA( v, c )  					\do {								\   sis_color_t *color = (sis_color_t *)&((v)->ui[coloroffset]);	\   UNCLAMPED_FLOAT_TO_UBYTE(color->red, (c)[0]);		\   UNCLAMPED_FLOAT_TO_UBYTE(color->green, (c)[1]);		\   UNCLAMPED_FLOAT_TO_UBYTE(color->blue, (c)[2]);		\   UNCLAMPED_FLOAT_TO_UBYTE(color->alpha, (c)[3]);		\} while (0)#define VERT_COPY_RGBA( v0, v1 ) v0->ui[coloroffset] = v1->ui[coloroffset]#define VERT_SET_SPEC( v, c )					\do {								\   if (specoffset != 0) {					\      sis_color_t *spec = (sis_color_t *)&((v)->ui[specoffset]); \      UNCLAMPED_FLOAT_TO_UBYTE(spec->red, (c)[0]);		\      UNCLAMPED_FLOAT_TO_UBYTE(spec->green, (c)[1]);		\      UNCLAMPED_FLOAT_TO_UBYTE(spec->blue, (c)[2]);		\   }								\} while (0)#define VERT_COPY_SPEC( v0, v1 )				\do {								\   if (specoffset != 0) {					\      sis_color_t *spec0 = (sis_color_t *)&((v0)->ui[specoffset]); \      sis_color_t *spec1 = (sis_color_t *)&((v1)->ui[specoffset]); \      spec0->red   = spec1->red;				\      spec0->green = spec1->green;				\      spec0->blue  = spec1->blue; 				\   }								\} while (0)#define VERT_SAVE_RGBA( idx )    color[idx] = v[idx]->ui[coloroffset]#define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]#define VERT_SAVE_SPEC( idx )    if (specoffset != 0) spec[idx] = v[idx]->ui[specoffset]#define VERT_RESTORE_SPEC( idx ) if (specoffset != 0) v[idx]->ui[specoffset] = spec[idx]#define LOCAL_VARS(n)						\   sisContextPtr smesa = SIS_CONTEXT(ctx);			\   GLuint color[n], spec[n];					\   GLuint coloroffset = smesa->coloroffset;			\   GLuint specoffset = smesa->specoffset;			\   (void) color; (void) spec; (void) coloroffset; (void) specoffset;/*********************************************************************** *                Helpers for rendering unfilled primitives            * ***********************************************************************/#define RASTERIZE(x) if (smesa->hw_primitive != hw_prim[x]) \                        sisRasterPrimitive( ctx, hw_prim[x] )#define RENDER_PRIMITIVE smesa->render_primitive#define IND SIS_FALLBACK_BIT#define TAG(x) x#include "tnl_dd/t_dd_unfilled.h"#undef IND/*********************************************************************** *                      Generate GL render functions                   * ***********************************************************************/#define IND (0)#define TAG(x) x#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_OFFSET_BIT)#define TAG(x) x##_offset#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_TWOSIDE_BIT)#define TAG(x) x##_twoside#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_TWOSIDE_BIT|SIS_OFFSET_BIT)#define TAG(x) x##_twoside_offset#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_UNFILLED_BIT)#define TAG(x) x##_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_OFFSET_BIT|SIS_UNFILLED_BIT)#define TAG(x) x##_offset_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_TWOSIDE_BIT|SIS_UNFILLED_BIT)#define TAG(x) x##_twoside_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_TWOSIDE_BIT|SIS_OFFSET_BIT|SIS_UNFILLED_BIT)#define TAG(x) x##_twoside_offset_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_FALLBACK_BIT)#define TAG(x) x##_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_OFFSET_BIT|SIS_FALLBACK_BIT)#define TAG(x) x##_offset_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_TWOSIDE_BIT|SIS_FALLBACK_BIT)#define TAG(x) x##_twoside_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_TWOSIDE_BIT|SIS_OFFSET_BIT|SIS_FALLBACK_BIT)#define TAG(x) x##_twoside_offset_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_UNFILLED_BIT|SIS_FALLBACK_BIT)#define TAG(x) x##_unfilled_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_OFFSET_BIT|SIS_UNFILLED_BIT|SIS_FALLBACK_BIT)#define TAG(x) x##_offset_unfilled_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_TWOSIDE_BIT|SIS_UNFILLED_BIT|SIS_FALLBACK_BIT)#define TAG(x) x##_twoside_unfilled_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (SIS_TWOSIDE_BIT|SIS_OFFSET_BIT|SIS_UNFILLED_BIT| \	     SIS_FALLBACK_BIT)#define TAG(x) x##_twoside_offset_unfilled_fallback#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();}/*********************************************************************** *                    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 voidsis_fallback_tri( sisContextPtr smesa,		  sisVertex *v0,		  sisVertex *v1,		  sisVertex *v2 ){   GLcontext *ctx = smesa->glCtx;   SWvertex v[3];   _swsetup_Translate( ctx, v0, &v[0] );   _swsetup_Translate( ctx, v1, &v[1] );   _swsetup_Translate( ctx, v2, &v[2] );   sisSpanRenderStart( ctx );   _swrast_Triangle( ctx, &v[0], &v[1], &v[2] );   sisSpanRenderFinish( ctx );   _swrast_flush( ctx );}static voidsis_fallback_line( sisContextPtr smesa,		   sisVertex *v0,		   sisVertex *v1 ){   GLcontext *ctx = smesa->glCtx;   SWvertex v[2];   _swsetup_Translate( ctx, v0, &v[0] );   _swsetup_Translate( ctx, v1, &v[1] );   sisSpanRenderStart( ctx );   _swrast_Line( ctx, &v[0], &v[1] );   sisSpanRenderFinish( ctx );   _swrast_flush( ctx );}static voidsis_fallback_point( sisContextPtr smesa,		    sisVertex *v0 ){   GLcontext *ctx = smesa->glCtx;   SWvertex v[1];   _swsetup_Translate( ctx, v0, &v[0] );   sisSpanRenderStart( ctx );   _swrast_Point( ctx, &v[0] );   sisSpanRenderFinish( ctx );   _swrast_flush( ctx );}/**********************************************************************//*               Render unclipped begin/end objects                   *//**********************************************************************/#define IND 0#define V(x) (sisVertex *)(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) sisRenderPrimitive( ctx, x )#undef LOCAL_VARS#define LOCAL_VARS				\    sisContextPtr smesa = SIS_CONTEXT(ctx);	\    const GLuint vertsize = smesa->vertex_size;		\    const char *vertptr = (char *)smesa->verts;		\    const GLuint * const elt = TNL_CONTEXT(ctx)->vb.Elts;	\    (void) elt;#define RESET_STIPPLE#define RESET_OCCLUSION#define PRESERVE_VB_DEFS#define ELT(x) (x)#define TAG(x) sis_##x##_verts#include "tnl/t_vb_rendertmp.h"#undef ELT#undef TAG#define TAG(x) sis_##x##_elts#define ELT(x) elt[x]#include "tnl/t_vb_rendertmp.h"/**********************************************************************//*                    Choose render functions                         *//**********************************************************************/#define POINT_FALLBACK (DD_POINT_SMOOTH)#define LINE_FALLBACK (DD_LINE_STIPPLE|DD_LINE_SMOOTH)#define TRI_FALLBACK (DD_TRI_STIPPLE|DD_TRI_SMOOTH)#define ANY_FALLBACK_FLAGS (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)#define ANY_RASTER_FLAGS (DD_TRI_LIGHT_TWOSIDE|DD_TRI_OFFSET|DD_TRI_UNFILLED)#define _SIS_NEW_RENDER_STATE (ANY_RASTER_FLAGS | ANY_FALLBACK_FLAGS)static void sisChooseRenderState(GLcontext *ctx){   TNLcontext *tnl = TNL_CONTEXT(ctx);   sisContextPtr smesa = SIS_CONTEXT( ctx );   GLuint flags = ctx->_TriangleCaps;   GLuint index = 0;   if (smesa->Fallback)      return;   if (flags & (ANY_RASTER_FLAGS|ANY_FALLBACK_FLAGS)) {      if (flags & ANY_RASTER_FLAGS) {	 if (flags & DD_TRI_LIGHT_TWOSIDE) index |= SIS_TWOSIDE_BIT;	 if (flags & DD_TRI_OFFSET)        index |= SIS_OFFSET_BIT;	 if (flags & DD_TRI_UNFILLED)      index |= SIS_UNFILLED_BIT;      }      smesa->draw_point = sis_point;      smesa->draw_line = sis_line;      smesa->draw_tri = sis_triangle;      /* Hook in fallbacks for specific primitives.       */      if (flags & ANY_FALLBACK_FLAGS) {	 if (flags & POINT_FALLBACK)            smesa->draw_point = sis_fallback_point;	 if (flags & LINE_FALLBACK)            smesa->draw_line = sis_fallback_line;	 if (flags & TRI_FALLBACK)            smesa->draw_tri = sis_fallback_tri;	 index |= SIS_FALLBACK_BIT;      }   }   if (index != smesa->RenderIndex) {      smesa->RenderIndex = index;      tnl->Driver.Render.Points = rast_tab[index].points;      tnl->Driver.Render.Line = rast_tab[index].line;      tnl->Driver.Render.ClippedLine = 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 = sis_render_tab_verts;	 tnl->Driver.Render.PrimTabElts = sis_render_tab_elts;	 tnl->Driver.Render.ClippedPolygon = sis_fast_clipped_poly;      } else {	 tnl->Driver.Render.PrimTabVerts = _tnl_render_tab_verts;	 tnl->Driver.Render.PrimTabElts = _tnl_render_tab_elts;	 tnl->Driver.Render.ClippedPolygon = _tnl_RenderClippedPolygon;      }   }}/**********************************************************************//*                Multipass rendering for front buffering             *//**********************************************************************/static GLboolean multipass_cliprect( GLcontext *ctx, GLuint pass ){   sisContextPtr smesa = SIS_CONTEXT( ctx );   if (pass >= smesa->driDrawable->numClipRects) {      return GL_FALSE;   } else {      GLint x1, y1, x2, y2;      x1 = smesa->driDrawable->pClipRects[pass].x1 - smesa->driDrawable->x;      y1 = smesa->driDrawable->pClipRects[pass].y1 - smesa->driDrawable->y;      x2 = smesa->driDrawable->pClipRects[pass].x2 - smesa->driDrawable->x;      y2 = smesa->driDrawable->pClipRects[pass].y2 - smesa->driDrawable->y;      if (ctx->Scissor.Enabled) {         GLint scisy1 = Y_FLIP(ctx->Scissor.Y + ctx->Scissor.Height - 1);         GLint scisy2 = Y_FLIP(ctx->Scissor.Y);         if (ctx->Scissor.X > x1)            x1 = ctx->Scissor.X;         if (scisy1 > y1)            y1 = scisy1;         if (ctx->Scissor.X + ctx->Scissor.Width - 1 < x2)            x2 = ctx->Scissor.X + ctx->Scissor.Width - 1;         if (scisy2 < y2)            y2 = scisy2;      }      MMIO(REG_3D_ClipTopBottom, y1 << 13 | y2);      MMIO(REG_3D_ClipLeftRight, x1 << 13 | x2);      /* Mark that we clobbered these registers */      smesa->GlobalFlag |= GFLAG_CLIPPING;      return GL_TRUE;   }}/**********************************************************************//*                 Validate state at pipeline start                   *//**********************************************************************/static void sisRunPipeline( GLcontext *ctx ){   sisContextPtr smesa = SIS_CONTEXT( ctx );   if (smesa->NewGLState) {      SIS_FIREVERTICES(smesa);      if (smesa->NewGLState & _NEW_TEXTURE) {	 sisUpdateTextureState(ctx);      }      if (smesa->NewGLState & _SIS_NEW_RENDER_STATE)	 sisChooseRenderState( ctx );      smesa->NewGLState = 0;   }   _tnl_run_pipeline( ctx );   /* XXX: If we put flushing in sis_state.c and friends, we can avoid this.    * Is it worth it?    */   SIS_FIREVERTICES(smesa);}

⌨️ 快捷键说明

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