📄 s3v_tris.c
字号:
/* * Author: Max Lingua <sunmax@libero.it> */#include <stdio.h>#include <stdlib.h>#include <sys/ioctl.h>#include "s3v_context.h"#include "s3v_vb.h"#include "s3v_tris.h"#include "glheader.h"#include "mtypes.h"#include "macros.h"#include "colormac.h"#include "swrast/swrast.h"#include "swrast_setup/swrast_setup.h"#include "tnl/tnl.h"#include "tnl/t_context.h"#include "tnl/t_pipeline.h"/*********************************************************************** * Build hardware rasterization functions * ***********************************************************************/#define DO_TRI 1#define HAVE_RGBA 1#define HAVE_SPEC 0#define HAVE_BACK_COLORS 0#define HAVE_HW_FLATSHADE 1#define VERTEX s3vVertex#define TAB rast_tab#define VERT_SET_RGBA( v, c ) \do { \ UNCLAMPED_FLOAT_TO_RGBA_CHAN( v->ub4[4], c); \/* *(v->ub4[4]) = c; \ */ \} while (0)#define VERT_COPY_RGBA( v0, v1 ) v0->ui[4] = v1->ui[4]/*#define VERT_COPY_RGBA1( v0, v1 ) v0->ui[4] = v1->ui[4]*/#define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[4]#define VERT_RESTORE_RGBA( idx ) v[idx]->ui[4] = color[idx]#define S3V_OFFSET_BIT 0x01#define S3V_TWOSIDE_BIT 0x02#define S3V_UNFILLED_BIT 0x04#define S3V_FALLBACK_BIT 0x08#define S3V_MAX_TRIFUNC 0x10static struct { tnl_points_func points; tnl_line_func line; tnl_triangle_func triangle; tnl_quad_func quad;} rast_tab[S3V_MAX_TRIFUNC];#define S3V_RAST_CULL_BIT 0x01#define S3V_RAST_FLAT_BIT 0x02#define S3V_RAST_TEX_BIT 0x04static s3v_point_func s3v_point_tab[0x8];static s3v_line_func s3v_line_tab[0x8];static s3v_tri_func s3v_tri_tab[0x8];static s3v_quad_func s3v_quad_tab[0x8];#define IND (0)#define TAG(x) x#include "s3v_tritmp.h"#define IND (S3V_RAST_CULL_BIT)#define TAG(x) x##_cull#include "s3v_tritmp.h"#define IND (S3V_RAST_FLAT_BIT)#define TAG(x) x##_flat#include "s3v_tritmp.h"#define IND (S3V_RAST_CULL_BIT|S3V_RAST_FLAT_BIT)#define TAG(x) x##_cull_flat#include "s3v_tritmp.h"#define IND (S3V_RAST_TEX_BIT)#define TAG(x) x##_tex#include "s3v_tritmp.h"#define IND (S3V_RAST_CULL_BIT|S3V_RAST_TEX_BIT)#define TAG(x) x##_cull_tex#include "s3v_tritmp.h"#define IND (S3V_RAST_FLAT_BIT|S3V_RAST_TEX_BIT)#define TAG(x) x##_flat_tex#include "s3v_tritmp.h"#define IND (S3V_RAST_CULL_BIT|S3V_RAST_FLAT_BIT|S3V_RAST_TEX_BIT)#define TAG(x) x##_cull_flat_tex#include "s3v_tritmp.h"static void init_rast_tab( void ){ DEBUG(("*** init_rast_tab ***\n")); s3v_init(); s3v_init_cull(); s3v_init_flat(); s3v_init_cull_flat(); s3v_init_tex(); s3v_init_cull_tex(); s3v_init_flat_tex(); s3v_init_cull_flat_tex();}/*********************************************************************** * 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. */#if 0static void s3v_fallback_quad( s3vContextPtr vmesa, const s3vVertex *v0, const s3vVertex *v1, const s3vVertex *v2, const s3vVertex *v3 ){ GLcontext *ctx = vmesa->glCtx; SWvertex v[4]; s3v_translate_vertex( ctx, v0, &v[0] ); s3v_translate_vertex( ctx, v1, &v[1] ); s3v_translate_vertex( ctx, v2, &v[2] ); s3v_translate_vertex( ctx, v3, &v[3] ); DEBUG(("s3v_fallback_quad\n"));/* _swrast_Quad( ctx, &v[0], &v[1], &v[2], &v[3] ); */}static void s3v_fallback_tri( s3vContextPtr vmesa, const s3vVertex *v0, const s3vVertex *v1, const s3vVertex *v2 ){ GLcontext *ctx = vmesa->glCtx; SWvertex v[3]; s3v_translate_vertex( ctx, v0, &v[0] ); s3v_translate_vertex( ctx, v1, &v[1] ); s3v_translate_vertex( ctx, v2, &v[2] ); DEBUG(("s3v_fallback_tri\n"));/* _swrast_Triangle( ctx, &v[0], &v[1], &v[2] ); */}static voids3v_fallback_line( s3vContextPtr vmesa, const s3vVertex *v0, const s3vVertex *v1 ){ GLcontext *ctx = vmesa->glCtx; SWvertex v[2]; s3v_translate_vertex( ctx, v0, &v[0] ); s3v_translate_vertex( ctx, v1, &v[1] ); DEBUG(("s3v_fallback_line\n")); _swrast_Line( ctx, &v[0], &v[1] );}/*static void s3v_fallback_point( s3vContextPtr vmesa, const s3vVertex *v0 ){ GLcontext *ctx = vmesa->glCtx; SWvertex v[1]; s3v_translate_vertex( ctx, v0, &v[0] ); _swrast_Point( ctx, &v[0] );}*/#endif/*********************************************************************** * Choose rasterization functions * ***********************************************************************/#define _S3V_NEW_RASTER_STATE (_NEW_FOG | \ _NEW_TEXTURE | \ _DD_NEW_TRI_SMOOTH | \ _DD_NEW_LINE_SMOOTH | \ _DD_NEW_POINT_SMOOTH | \ _DD_NEW_TRI_STIPPLE | \ _DD_NEW_LINE_STIPPLE)#define LINE_FALLBACK (0)#define TRI_FALLBACK (0)static void s3v_nodraw_triangle(GLcontext *ctx, s3vVertex *v0, s3vVertex *v1, s3vVertex *v2){ (void) (ctx && v0 && v1 && v2);}static void s3v_nodraw_quad(GLcontext *ctx, s3vVertex *v0, s3vVertex *v1, s3vVertex *v2, s3vVertex *v3){ (void) (ctx && v0 && v1 && v2 && v3);}void s3vChooseRasterState(GLcontext *ctx);void s3vChooseRasterState(GLcontext *ctx){ s3vContextPtr vmesa = S3V_CONTEXT(ctx); GLuint flags = ctx->_TriangleCaps; GLuint ind = 0; DEBUG(("*** s3vChooseRasterState ***\n")); if (ctx->Polygon.CullFlag) { if (ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) { vmesa->draw_tri = (s3v_tri_func)s3v_nodraw_triangle; vmesa->draw_quad = (s3v_quad_func)s3v_nodraw_quad; return; } ind |= S3V_RAST_CULL_BIT; /* s3v_update_cullsign(ctx); */ } /* else vmesa->backface_sign = 0; */ if ( flags & DD_FLATSHADE ) ind |= S3V_RAST_FLAT_BIT; if ( ctx->Texture.Unit[0]._ReallyEnabled ) { ind |= S3V_RAST_TEX_BIT; } DEBUG(("ind = %i\n", ind)); vmesa->draw_line = s3v_line_tab[ind]; vmesa->draw_tri = s3v_tri_tab[ind]; vmesa->draw_quad = s3v_quad_tab[ind]; vmesa->draw_point = s3v_point_tab[ind];#if 0 /* Hook in fallbacks for specific primitives. CURRENTLY DISABLED */ if (flags & LINE_FALLBACK) vmesa->draw_line = s3v_fallback_line; if (flags & TRI_FALLBACK) { DEBUG(("TRI_FALLBACK\n")); vmesa->draw_tri = s3v_fallback_tri; vmesa->draw_quad = s3v_fallback_quad; }#endif}/*********************************************************************** * Macros for t_dd_tritmp.h to draw basic primitives * ***********************************************************************/#define TRI( v0, v1, v2 ) \do { \ /* if (DO_FALLBACK) \ vmesa->draw_tri( vmesa, v0, v1, v2 ); \ else */ \ DEBUG(("TRI: max was here\n")); /* \ s3v_draw_tex_triangle( vmesa, v0, v1, v2 ); */ \ vmesa->draw_tri( vmesa, v0, v1, v2 ); \} while (0)#define QUAD( v0, v1, v2, v3 ) \do { \ DEBUG(("QUAD: max was here\n")); \ vmesa->draw_quad( vmesa, v0, v1, v2, v3 ); \} while (0)#define LINE( v0, v1 ) \do { \ DEBUG(("LINE: max was here\n")); \ vmesa->draw_line( vmesa, v0, v1 ); \} while (0)#define POINT( v0 ) \do { \ vmesa->draw_point( vmesa, v0 ); \} while (0)/*********************************************************************** * Build render functions from dd templates * ***********************************************************************//*#define S3V_OFFSET_BIT 0x01#define S3V_TWOSIDE_BIT 0x02#define S3V_UNFILLED_BIT 0x04#define S3V_FALLBACK_BIT 0x08#define S3V_MAX_TRIFUNC 0x10static struct { points_func points; line_func line; triangle_func triangle; quad_func quad;} rast_tab[S3V_MAX_TRIFUNC];*/#define DO_FALLBACK (IND & S3V_FALLBACK_BIT)#define DO_OFFSET (IND & S3V_OFFSET_BIT)#define DO_UNFILLED (IND & S3V_UNFILLED_BIT)#define DO_TWOSIDE (IND & S3V_TWOSIDE_BIT)#define DO_FLAT 0#define DO_TRI 1#define DO_QUAD 1#define DO_LINE 1#define DO_POINTS 1#define DO_FULL_QUAD 1#define HAVE_RGBA 1#define HAVE_SPEC 0#define HAVE_BACK_COLORS 0#define HAVE_HW_FLATSHADE 1#define VERTEX s3vVertex#define TAB rast_tab#define DEPTH_SCALE 1.0#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) (vmesa->verts + (e<<vmesa->vertex_stride_shift))#if 0#define VERT_SET_RGBA( v, c ) \do { \/* UNCLAMPED_FLOAT_TO_RGBA_CHAN( v->ub4[4], c) */ \} while (0)#define VERT_COPY_RGBA( v0, v1 ) v0->ui[4] = v1->ui[4]/*#define VERT_COPY_RGBA1( v0, v1 ) v0->ui[4] = v1->ui[4]*/#define VERT_SAVE_RGBA( idx ) color[idx] = v[idx]->ui[4]#define VERT_RESTORE_RGBA( idx ) v[idx]->ui[4] = color[idx] #endif#define LOCAL_VARS(n) \ s3vContextPtr vmesa = S3V_CONTEXT(ctx); \ GLuint color[n]; \ (void) color;/*********************************************************************** * Helpers for rendering unfilled primitives * ***********************************************************************/static const GLuint hw_prim[GL_POLYGON+1] = { PrimType_Points, PrimType_Lines, PrimType_Lines, PrimType_Lines, PrimType_Triangles, PrimType_Triangles, PrimType_Triangles, PrimType_Triangles, PrimType_Triangles, PrimType_Triangles};static void s3vResetLineStipple( GLcontext *ctx );static void s3vRasterPrimitive( GLcontext *ctx, GLuint hwprim );static void s3vRenderPrimitive( GLcontext *ctx, GLenum prim );/*extern static void s3v_lines_emit(GLcontext *ctx, GLuint start, GLuint end);extern static void s3v_tris_emit(GLcontext *ctx, GLuint start, GLuint end);*/#define RASTERIZE(x) if (vmesa->hw_primitive != hw_prim[x]) \ s3vRasterPrimitive( ctx, hw_prim[x] )#define RENDER_PRIMITIVE vmesa->render_primitive#define TAG(x) x#define IND S3V_FALLBACK_BIT#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 (S3V_OFFSET_BIT)#define TAG(x) x##_offset#include "tnl_dd/t_dd_tritmp.h"#define IND (S3V_TWOSIDE_BIT)#define TAG(x) x##_twoside#include "tnl_dd/t_dd_tritmp.h"#define IND (S3V_TWOSIDE_BIT|S3V_OFFSET_BIT)#define TAG(x) x##_twoside_offset#include "tnl_dd/t_dd_tritmp.h"#define IND (S3V_UNFILLED_BIT)#define TAG(x) x##_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (S3V_OFFSET_BIT|S3V_UNFILLED_BIT)#define TAG(x) x##_offset_unfilled#include "tnl_dd/t_dd_tritmp.h"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -