📄 r128_tris.c
字号:
r128ContextPtr rmesa = R128_CONTEXT(ctx); \ const GLuint vertsize = rmesa->vertex_size; \ const char *vertptr = (char *)rmesa->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) r128_##x##_verts#include "tnl/t_vb_rendertmp.h"#undef ELT#undef TAG#define TAG(x) r128_##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)#define TRI_FALLBACK (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 _R128_NEW_RENDER_STATE (ANY_FALLBACK_FLAGS | ANY_RASTER_FLAGS)static void r128ChooseRenderState(GLcontext *ctx){ r128ContextPtr rmesa = R128_CONTEXT(ctx); GLuint flags = ctx->_TriangleCaps; GLuint index = 0; if (flags & (ANY_RASTER_FLAGS|ANY_FALLBACK_FLAGS)) { rmesa->draw_point = r128_point; rmesa->draw_line = r128_line; rmesa->draw_tri = r128_triangle; if (flags & ANY_RASTER_FLAGS) { if (flags & DD_TRI_LIGHT_TWOSIDE) index |= R128_TWOSIDE_BIT; if (flags & DD_TRI_OFFSET) index |= R128_OFFSET_BIT; if (flags & DD_TRI_UNFILLED) index |= R128_UNFILLED_BIT; } /* Hook in fallbacks for specific primitives. */ if (flags & (POINT_FALLBACK|LINE_FALLBACK|TRI_FALLBACK)) { if (flags & POINT_FALLBACK) rmesa->draw_point = r128_fallback_point; if (flags & LINE_FALLBACK) rmesa->draw_line = r128_fallback_line; if (flags & TRI_FALLBACK) rmesa->draw_tri = r128_fallback_tri; index |= R128_FALLBACK_BIT; } } if (index != rmesa->RenderIndex) { TNLcontext *tnl = TNL_CONTEXT(ctx); 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 = r128_render_tab_verts; tnl->Driver.Render.PrimTabElts = r128_render_tab_elts; tnl->Driver.Render.ClippedPolygon = r128_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; } rmesa->RenderIndex = index; }}/**********************************************************************//* Validate state at pipeline start *//**********************************************************************/static void r128RunPipeline( GLcontext *ctx ){ r128ContextPtr rmesa = R128_CONTEXT(ctx); if (rmesa->new_state || rmesa->NewGLState & _NEW_TEXTURE) r128DDUpdateHWState( ctx ); if (!rmesa->Fallback && rmesa->NewGLState) { if (rmesa->NewGLState & _R128_NEW_RENDER_STATE) r128ChooseRenderState( ctx ); rmesa->NewGLState = 0; } _tnl_run_pipeline( ctx );}/**********************************************************************//* High level hooks for t_vb_render.c *//**********************************************************************//* This is called when Mesa switches between rendering triangle * primitives (such as GL_POLYGON, GL_QUADS, GL_TRIANGLE_STRIP, etc), * and lines, points and bitmaps. * * As the r128 uses triangles to render lines and points, it is * necessary to turn off hardware culling when rendering these * primitives. */static void r128RasterPrimitive( GLcontext *ctx, GLuint hwprim ){ r128ContextPtr rmesa = R128_CONTEXT(ctx); rmesa->setup.dp_gui_master_cntl_c &= ~R128_GMC_BRUSH_NONE; if ( ctx->Polygon.StippleFlag && hwprim == GL_TRIANGLES ) { rmesa->setup.dp_gui_master_cntl_c |= R128_GMC_BRUSH_32x32_MONO_FG_LA; } else { rmesa->setup.dp_gui_master_cntl_c |= R128_GMC_BRUSH_SOLID_COLOR; } rmesa->new_state |= R128_NEW_CONTEXT; rmesa->dirty |= R128_UPLOAD_CONTEXT; if (rmesa->hw_primitive != hwprim) { FLUSH_BATCH( rmesa ); rmesa->hw_primitive = hwprim; }}static void r128SetupAntialias( GLcontext *ctx, GLenum prim ){ r128ContextPtr rmesa = R128_CONTEXT(ctx); GLuint currAA, wantAA; currAA = (rmesa->setup.pm4_vc_fpu_setup & R128_EDGE_ANTIALIAS) != 0; if( prim >= GL_TRIANGLES ) wantAA = ctx->Polygon.SmoothFlag; else if( prim >= GL_LINES ) wantAA = ctx->Line.SmoothFlag; else wantAA = 0; if( wantAA != currAA ) { FLUSH_BATCH( rmesa ); rmesa->setup.pm4_vc_fpu_setup ^= R128_EDGE_ANTIALIAS; rmesa->dirty |= R128_UPLOAD_SETUP; }}static void r128RenderPrimitive( GLcontext *ctx, GLenum prim ){ r128ContextPtr rmesa = R128_CONTEXT(ctx); GLuint hw = hw_prim[prim]; rmesa->render_primitive = prim; r128SetupAntialias( ctx, prim ); if (prim >= GL_TRIANGLES && (ctx->_TriangleCaps & DD_TRI_UNFILLED)) return; r128RasterPrimitive( ctx, hw );}#define EMIT_ATTR( ATTR, STYLE, VF, SIZE ) \do { \ rmesa->vertex_attrs[rmesa->vertex_attr_count].attrib = (ATTR); \ rmesa->vertex_attrs[rmesa->vertex_attr_count].format = (STYLE); \ rmesa->vertex_attr_count++; \ vc_frmt |= (VF); \ offset += (SIZE); \} while (0)#define EMIT_PAD( SIZE ) \do { \ rmesa->vertex_attrs[rmesa->vertex_attr_count].attrib = 0; \ rmesa->vertex_attrs[rmesa->vertex_attr_count].format = EMIT_PAD; \ rmesa->vertex_attrs[rmesa->vertex_attr_count].offset = (SIZE); \ rmesa->vertex_attr_count++; \ offset += (SIZE); \} while (0)static void r128RenderStart( GLcontext *ctx ){ r128ContextPtr rmesa = R128_CONTEXT(ctx); TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; DECLARE_RENDERINPUTS(index_bitset); GLuint vc_frmt = 0; GLboolean fallback_projtex = GL_FALSE; GLuint offset = 0; RENDERINPUTS_COPY( index_bitset, tnl->render_inputs_bitset ); /* Important: */ VB->AttribPtr[VERT_ATTRIB_POS] = VB->NdcPtr; rmesa->vertex_attr_count = 0; rmesa->specoffset = 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 )) EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_4F_VIEWPORT, R128_CCE_VC_FRMT_RHW, 4 ); else EMIT_ATTR( _TNL_ATTRIB_POS, EMIT_3F_VIEWPORT, 0, 3 ); rmesa->coloroffset = offset;#if MESA_LITTLE_ENDIAN EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_BGRA, R128_CCE_VC_FRMT_DIFFUSE_ARGB, 4 );#else EMIT_ATTR( _TNL_ATTRIB_COLOR0, EMIT_4UB_4F_ARGB, R128_CCE_VC_FRMT_DIFFUSE_ARGB, 4 );#endif if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 ) || RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) {#if MESA_LITTLE_ENDIAN if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) { rmesa->specoffset = offset; EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_BGR, R128_CCE_VC_FRMT_SPEC_FRGB, 3 ); } else EMIT_PAD( 3 ); if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, R128_CCE_VC_FRMT_SPEC_FRGB, 1 ); else EMIT_PAD( 1 );#else if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_FOG )) EMIT_ATTR( _TNL_ATTRIB_FOG, EMIT_1UB_1F, R128_CCE_VC_FRMT_SPEC_FRGB, 1 ); else EMIT_PAD( 1 ); if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_COLOR1 )) { rmesa->specoffset = offset; EMIT_ATTR( _TNL_ATTRIB_COLOR1, EMIT_3UB_3F_RGB, R128_CCE_VC_FRMT_SPEC_FRGB, 3 ); } else EMIT_PAD( 3 );#endif } if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(rmesa->tmu_source[0]) )) { if ( VB->TexCoordPtr[rmesa->tmu_source[0]]->size > 2 ) fallback_projtex = GL_TRUE; EMIT_ATTR( _TNL_ATTRIB_TEX0, EMIT_2F, R128_CCE_VC_FRMT_S_T, 8 ); } if (RENDERINPUTS_TEST( index_bitset, _TNL_ATTRIB_TEX(rmesa->tmu_source[1]) )) { if ( VB->TexCoordPtr[rmesa->tmu_source[1]]->size > 2 ) fallback_projtex = GL_TRUE; EMIT_ATTR( _TNL_ATTRIB_TEX1, EMIT_2F, R128_CCE_VC_FRMT_S2_T2, 8 ); } /* projective textures are not supported by the hardware */ FALLBACK( rmesa, R128_FALLBACK_PROJTEX, fallback_projtex ); /* Only need to change the vertex emit code if there has been a * statechange to a TNL index. */ if (!RENDERINPUTS_EQUAL( index_bitset, rmesa->tnl_state_bitset )) { FLUSH_BATCH( rmesa ); rmesa->dirty |= R128_UPLOAD_CONTEXT; rmesa->vertex_size = _tnl_install_attrs( ctx, rmesa->vertex_attrs, rmesa->vertex_attr_count, rmesa->hw_viewport, 0 ); rmesa->vertex_size >>= 2; rmesa->vertex_format = vc_frmt; }}static void r128RenderFinish( GLcontext *ctx ){ if (R128_CONTEXT(ctx)->RenderIndex & R128_FALLBACK_BIT) _swrast_flush( ctx );}/**********************************************************************//* Transition to/from hardware rasterization. *//**********************************************************************/static const char * const fallbackStrings[] = { "Texture mode", "glDrawBuffer(GL_FRONT_AND_BACK)", "glReadBuffer", "glEnable(GL_STENCIL) without hw stencil buffer", "glRenderMode(selection or feedback)", "glLogicOp (mode != GL_COPY)", "GL_SEPARATE_SPECULAR_COLOR", "glBlendEquation(mode != ADD)", "glBlendFunc", "Projective texture", "Rasterization disable",};static const char *getFallbackString(GLuint bit){ int i = 0; while (bit > 1) { i++; bit >>= 1; } return fallbackStrings[i];}void r128Fallback( GLcontext *ctx, GLuint bit, GLboolean mode ){ TNLcontext *tnl = TNL_CONTEXT(ctx); r128ContextPtr rmesa = R128_CONTEXT(ctx); GLuint oldfallback = rmesa->Fallback; if (mode) { rmesa->Fallback |= bit; if (oldfallback == 0) { FLUSH_BATCH( rmesa ); _swsetup_Wakeup( ctx ); rmesa->RenderIndex = ~0; if ( R128_DEBUG & DEBUG_VERBOSE_FALL ) { fprintf(stderr, "R128 begin rasterization fallback: 0x%x %s\n", bit, getFallbackString(bit)); } } } else { rmesa->Fallback &= ~bit; if (oldfallback == bit) { _swrast_flush( ctx ); tnl->Driver.Render.Start = r128RenderStart; tnl->Driver.Render.PrimitiveNotify = r128RenderPrimitive; tnl->Driver.Render.Finish = r128RenderFinish; tnl->Driver.Render.BuildVertices = _tnl_build_vertices; tnl->Driver.Render.CopyPV = _tnl_copy_pv; tnl->Driver.Render.Interp = _tnl_interp; _tnl_invalidate_vertex_state( ctx, ~0 ); _tnl_invalidate_vertices( ctx, ~0 ); _tnl_install_attrs( ctx, rmesa->vertex_attrs, rmesa->vertex_attr_count, rmesa->hw_viewport, 0 ); rmesa->NewGLState |= _R128_NEW_RENDER_STATE; if ( R128_DEBUG & DEBUG_VERBOSE_FALL ) { fprintf(stderr, "R128 end rasterization fallback: 0x%x %s\n", bit, getFallbackString(bit)); } } }}/**********************************************************************//* Initialization. *//**********************************************************************/void r128InitTriFuncs( GLcontext *ctx ){ r128ContextPtr rmesa = R128_CONTEXT(ctx); TNLcontext *tnl = TNL_CONTEXT(ctx); static int firsttime = 1; if (firsttime) { init_rast_tab(); firsttime = 0; } tnl->Driver.RunPipeline = r128RunPipeline; tnl->Driver.Render.Start = r128RenderStart; tnl->Driver.Render.Finish = r128RenderFinish; tnl->Driver.Render.PrimitiveNotify = r128RenderPrimitive; tnl->Driver.Render.ResetLineStipple = _swrast_ResetLineStipple; tnl->Driver.Render.BuildVertices = _tnl_build_vertices; tnl->Driver.Render.CopyPV = _tnl_copy_pv; tnl->Driver.Render.Interp = _tnl_interp; _tnl_init_vertices( ctx, ctx->Const.MaxArrayLockSize + 12, (6 + 2 * ctx->Const.MaxTextureUnits) * sizeof(GLfloat) ); rmesa->verts = (char *)tnl->clipspace.vertex_buf; RENDERINPUTS_ONES( rmesa->tnl_state_bitset ); rmesa->NewGLState |= _R128_NEW_RENDER_STATE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -