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

📄 ffb_tris.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/* $XFree86: xc/lib/GL/mesa/src/drv/ffb/ffb_tris.c,v 1.3 2002/10/30 12:51:28 alanh Exp $ * * GLX Hardware Device Driver for Sun Creator/Creator3D * Copyright (C) 2000, 2001 David S. Miller * * 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 * DAVID MILLER, OR ANY OTHER CONTRIBUTORS 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. * * *    David S. Miller <davem@redhat.com> */#include "glheader.h"#include "mtypes.h"#include "macros.h"#include "swrast/swrast.h"#include "swrast_setup/swrast_setup.h"#include "swrast/s_context.h"#include "tnl/t_context.h"#include "tnl/t_pipeline.h"#include "ffb_context.h"#include "ffb_tris.h"#include "ffb_lines.h"#include "ffb_lock.h"#include "ffb_points.h"#include "ffb_state.h"#include "ffb_vb.h"#undef TRI_DEBUG#undef FFB_RENDER_TRACE#undef STATE_TRACE#ifdef TRI_DEBUGstatic void ffb_print_vertex(const ffb_vertex *v){	fprintf(stderr, "Vertex @(%p): "		"X[%f] Y[%f] Z[%f]\n",		v, v->x, v->y, v->z);	fprintf(stderr, "Vertex @(%p): "		"A[%f] R[%f] G[%f] B[%f]\n",		v,		v->color[0].alpha,		v->color[0].red,		v->color[0].green,		v->color[0].blue);}#define FFB_DUMP_VERTEX(V)	ffb_print_vertex(V)#else#define FFB_DUMP_VERTEX(V)	do { } while(0)#endif#define FFB_ALPHA_BIT		0x01#define FFB_FLAT_BIT		0x02#define FFB_TRI_CULL_BIT	0x04#define MAX_FFB_RENDER_FUNCS	0x08/*********************************************************************** *         Build low-level triangle/quad rasterize functions           * ***********************************************************************/#define FFB_TRI_FLAT_BIT	0x01#define FFB_TRI_ALPHA_BIT	0x02/*#define FFB_TRI_CULL_BIT	0x04*/static ffb_tri_func ffb_tri_tab[0x8];static ffb_quad_func ffb_quad_tab[0x8];#define IND (0)#define TAG(x) x#include "ffb_tritmp.h"#define IND (FFB_TRI_FLAT_BIT)#define TAG(x) x##_flat#include "ffb_tritmp.h"#define IND (FFB_TRI_CULL_BIT)#define TAG(x) x##_cull#include "ffb_tritmp.h"#define IND (FFB_TRI_CULL_BIT|FFB_TRI_FLAT_BIT)#define TAG(x) x##_cull_flat#include "ffb_tritmp.h"#define IND (FFB_TRI_ALPHA_BIT)#define TAG(x) x##_alpha#include "ffb_tritmp.h"#define IND (FFB_TRI_ALPHA_BIT|FFB_TRI_FLAT_BIT)#define TAG(x) x##_alpha_flat#include "ffb_tritmp.h"#define IND (FFB_TRI_ALPHA_BIT|FFB_TRI_CULL_BIT)#define TAG(x) x##_alpha_cull#include "ffb_tritmp.h"#define IND (FFB_TRI_ALPHA_BIT|FFB_TRI_CULL_BIT|FFB_TRI_FLAT_BIT)#define TAG(x) x##_alpha_cull_flat#include "ffb_tritmp.h"static void init_tri_tab(void){	ffb_init();	ffb_init_flat();	ffb_init_cull();	ffb_init_cull_flat();	ffb_init_alpha();	ffb_init_alpha_flat();	ffb_init_alpha_cull();	ffb_init_alpha_cull_flat();}/* Build a SWvertex from a hardware vertex. */static void ffb_translate_vertex(GLcontext *ctx, const ffb_vertex *src,				 SWvertex *dst){	ffbContextPtr fmesa = FFB_CONTEXT(ctx);	GLfloat *m = ctx->Viewport._WindowMap.m;	const GLfloat sx = m[0];	const GLfloat sy = m[5];	const GLfloat sz = m[10];	const GLfloat tx = m[12];	const GLfloat ty = m[13];	const GLfloat tz = m[14];	dst->attrib[FRAG_ATTRIB_WPOS][0] = sx * src->x + tx;	dst->attrib[FRAG_ATTRIB_WPOS][1] = sy * src->y + ty;	dst->attrib[FRAG_ATTRIB_WPOS][2] = sz * src->z + tz;	dst->attrib[FRAG_ATTRIB_WPOS][3] = 1.0;      	dst->color[0] = FFB_UBYTE_FROM_COLOR(src->color[0].red);	dst->color[1] = FFB_UBYTE_FROM_COLOR(src->color[0].green);	dst->color[2] = FFB_UBYTE_FROM_COLOR(src->color[0].blue);	dst->color[3] = FFB_UBYTE_FROM_COLOR(src->color[0].alpha);}/*********************************************************************** *          Build fallback triangle/quad rasterize functions           * ***********************************************************************/static void ffb_fallback_triangle(GLcontext *ctx, ffb_vertex *v0,				  ffb_vertex *v1, ffb_vertex *v2){	SWvertex v[3];	ffb_translate_vertex(ctx, v0, &v[0]);	ffb_translate_vertex(ctx, v1, &v[1]);	ffb_translate_vertex(ctx, v2, &v[2]);	_swrast_Triangle(ctx, &v[0], &v[1], &v[2]);}static void ffb_fallback_quad(GLcontext *ctx,			      ffb_vertex *v0, ffb_vertex *v1, 			      ffb_vertex *v2, ffb_vertex *v3){	SWvertex v[4];	ffb_translate_vertex(ctx, v0, &v[0]);	ffb_translate_vertex(ctx, v1, &v[1]);	ffb_translate_vertex(ctx, v2, &v[2]);	ffb_translate_vertex(ctx, v3, &v[3]);	_swrast_Quad(ctx, &v[0], &v[1], &v[2], &v[3]);}void ffb_fallback_line(GLcontext *ctx, ffb_vertex *v0, ffb_vertex *v1){	SWvertex v[2];	ffb_translate_vertex(ctx, v0, &v[0]);	ffb_translate_vertex(ctx, v1, &v[1]);	_swrast_Line(ctx, &v[0], &v[1]);}void ffb_fallback_point(GLcontext *ctx, ffb_vertex *v0){	SWvertex v[1];	ffb_translate_vertex(ctx, v0, &v[0]);	_swrast_Point(ctx, &v[0]);}/*********************************************************************** *             Rasterization functions for culled tris/quads           * ***********************************************************************/static void ffb_nodraw_triangle(GLcontext *ctx, ffb_vertex *v0,				ffb_vertex *v1, ffb_vertex *v2){	(void) (ctx && v0 && v1 && v2);}static void ffb_nodraw_quad(GLcontext *ctx,			    ffb_vertex *v0, ffb_vertex *v1, 			    ffb_vertex *v2, ffb_vertex *v3){	(void) (ctx && v0 && v1 && v2 && v3);}static void ffb_update_cullsign(GLcontext *ctx){	GLfloat backface_sign = 1;	switch (ctx->Polygon.CullFaceMode) {	case GL_BACK:		if (ctx->Polygon.FrontFace==GL_CCW)			backface_sign = -1;		break;	case GL_FRONT:		if (ctx->Polygon.FrontFace!=GL_CCW)			backface_sign = -1;		break;	default:		break;	};	FFB_CONTEXT(ctx)->backface_sign = backface_sign;}/*********************************************************************** *               Choose triangle/quad rasterize functions              * ***********************************************************************/void ffbChooseTriangleState(GLcontext *ctx){	ffbContextPtr fmesa = FFB_CONTEXT(ctx);	GLuint flags = ctx->_TriangleCaps;	GLuint ind = 0;	if (flags & DD_TRI_SMOOTH) {		fmesa->draw_tri = ffb_fallback_triangle;		fmesa->draw_quad = ffb_fallback_quad;		return;	}	if (flags & DD_FLATSHADE)		ind |= FFB_TRI_FLAT_BIT;	if (ctx->Polygon.CullFlag) {		if (ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) {			fmesa->draw_tri = ffb_nodraw_triangle;			fmesa->draw_quad = ffb_nodraw_quad;			return;		}		ind |= FFB_TRI_CULL_BIT;		ffb_update_cullsign(ctx);	} else		FFB_CONTEXT(ctx)->backface_sign = 0;			/* If blending or the alpha test is enabled we need to	 * provide alpha components to the chip, else we can	 * do without it and thus feed vertex data to the chip	 * more efficiently.	 */	if (ctx->Color.BlendEnabled || ctx->Color.AlphaEnabled)		ind |= FFB_TRI_ALPHA_BIT;	fmesa->draw_tri = ffb_tri_tab[ind];	fmesa->draw_quad = ffb_quad_tab[ind];}static const GLenum reduced_prim[GL_POLYGON+1] = {   GL_POINTS,   GL_LINES,   GL_LINES,   GL_LINES,   GL_TRIANGLES,   GL_TRIANGLES,   GL_TRIANGLES,   GL_TRIANGLES,   GL_TRIANGLES,   GL_TRIANGLES};static void ffbRenderPrimitive(GLcontext *ctx, GLenum prim);static void ffbRasterPrimitive(GLcontext *ctx, GLenum rprim);/*********************************************************************** *              Build render functions from dd templates               * ***********************************************************************/#define FFB_OFFSET_BIT  	0x01#define FFB_TWOSIDE_BIT 	0x02#define FFB_UNFILLED_BIT	0x04#define FFB_MAX_TRIFUNC 	0x08static struct {	tnl_triangle_func triangle;	tnl_quad_func quad;} rast_tab[FFB_MAX_TRIFUNC];#define DO_OFFSET   (IND & FFB_OFFSET_BIT)#define DO_UNFILLED (IND & FFB_UNFILLED_BIT)#define DO_TWOSIDE  (IND & FFB_TWOSIDE_BIT)#define DO_FLAT      0#define DO_QUAD      1#define DO_FULL_QUAD 1#define DO_TRI       1#define DO_LINE      0#define DO_POINTS    0#define QUAD( a, b, c, d ) fmesa->draw_quad( ctx, a, b, c, d )#define TRI( a, b, c )     fmesa->draw_tri( ctx, a, b, c )#define LINE( a, b )       fmesa->draw_line( ctx, a, b )#define POINT( a )         fmesa->draw_point( ctx, a )#define HAVE_BACK_COLORS  1#define HAVE_RGBA         1#define HAVE_SPEC         0#define HAVE_HW_FLATSHADE 1#define VERTEX            ffb_vertex#define TAB               rast_tab#define UNFILLED_TRI      unfilled_tri#define UNFILLED_QUAD     unfilled_quad#define DEPTH_SCALE       (fmesa->depth_scale)#define VERT_X(_v)        (_v->x)#define VERT_Y(_v)        (_v->y)#define VERT_Z(_v)	  (_v->z)#define AREA_IS_CCW( a )  (a < fmesa->ffb_zero)#define GET_VERTEX(e)     (&fmesa->verts[e])#define INSANE_VERTICES#define VERT_SET_Z(v,val) ((v)->z = (val))#define VERT_Z_ADD(v,val) ((v)->z += (val))#define VERT_COPY_RGBA1( _v )     _v->color[0] = _v->color[1]#define VERT_COPY_RGBA( v0, v1 )  v0->color[0] = v1->color[0] #define VERT_SAVE_RGBA( idx )     color[idx] = v[idx]->color[0]#define VERT_RESTORE_RGBA( idx )  v[idx]->color[0] = color[idx]   #define LOCAL_VARS(n)				\   ffbContextPtr fmesa = FFB_CONTEXT(ctx);	\   __DRIdrawablePrivate *dPriv = fmesa->driDrawable; \   ffb_color color[n];				\   (void) color; (void) dPriv;/*********************************************************************** *                Helpers for rendering unfilled primitives            * ***********************************************************************/#define RASTERIZE(x) if (fmesa->raster_primitive != reduced_prim[x]) \                        ffbRasterPrimitive( ctx, reduced_prim[x] )#define RENDER_PRIMITIVE fmesa->render_primitive#define TAG(x) x#include "tnl_dd/t_dd_unfilled.h"/*********************************************************************** *                      Generate GL render functions                   * ***********************************************************************/#define IND (0)#define TAG(x) x#include "tnl_dd/t_dd_tritmp.h"#define IND (FFB_OFFSET_BIT)#define TAG(x) x##_offset#include "tnl_dd/t_dd_tritmp.h"#define IND (FFB_TWOSIDE_BIT)#define TAG(x) x##_twoside#include "tnl_dd/t_dd_tritmp.h"#define IND (FFB_TWOSIDE_BIT|FFB_OFFSET_BIT)#define TAG(x) x##_twoside_offset#include "tnl_dd/t_dd_tritmp.h"#define IND (FFB_UNFILLED_BIT)#define TAG(x) x##_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (FFB_OFFSET_BIT|FFB_UNFILLED_BIT)#define TAG(x) x##_offset_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (FFB_TWOSIDE_BIT|FFB_UNFILLED_BIT)#define TAG(x) x##_twoside_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (FFB_TWOSIDE_BIT|FFB_OFFSET_BIT|FFB_UNFILLED_BIT)#define TAG(x) x##_twoside_offset_unfilled#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();}/**********************************************************************//*                   Render clipped primitives                        *//**********************************************************************/static void ffbRenderClippedPolygon(GLcontext *ctx, const GLuint *elts, GLuint n){	ffbContextPtr fmesa = FFB_CONTEXT(ctx);	TNLcontext *tnl = TNL_CONTEXT(ctx);	struct vertex_buffer *VB = &tnl->vb;	GLuint prim = fmesa->render_primitive;	/* 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)		tnl->Driver.Render.PrimitiveNotify(ctx, prim);}static void ffbRenderClippedLine(GLcontext *ctx, GLuint ii, GLuint jj){	TNLcontext *tnl = TNL_CONTEXT(ctx);	tnl->Driver.Render.Line(ctx, ii, jj);}/**********************************************************************//*               Render unclipped begin/end objects                   *//**********************************************************************/static void ffb_vb_noop(GLcontext *ctx, GLuint start, GLuint count, GLuint flags){	(void)(ctx && start && count && flags);}#define ELT(x)	x#define IND	0#define TAG(x)	x#include "ffb_rendertmp.h"#define IND	(FFB_FLAT_BIT)#define TAG(x)	x##_flat#include "ffb_rendertmp.h"#define IND	(FFB_ALPHA_BIT)#define TAG(x)	x##_alpha#include "ffb_rendertmp.h"#define IND	(FFB_FLAT_BIT | FFB_ALPHA_BIT)#define TAG(x)	x##_flat_alpha#include "ffb_rendertmp.h"#define IND	(FFB_TRI_CULL_BIT)

⌨️ 快捷键说明

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