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

📄 mgatris.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright 2000-2001 VA Linux Systems, Inc. * All Rights Reserved. * * 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 * on the rights to use, copy, modify, merge, publish, distribute, sub * license, 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 (including the next * paragraph) 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 NON-INFRINGEMENT.  IN NO EVENT SHALL * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS 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. * * Authors: *    Keith Whitwell <keith@tungstengraphics.com> *//* $XFree86: xc/lib/GL/mesa/src/drv/mga/mgatris.c,v 1.10 2002/10/30 12:51:36 alanh Exp $ */#include "mtypes.h"#include "macros.h"#include "colormac.h"#include "swrast/swrast.h"#include "swrast_setup/swrast_setup.h"#include "tnl/t_context.h"#include "tnl/t_pipeline.h"#include "mm.h"#include "mgacontext.h"#include "mgaioctl.h"#include "mgatris.h"#include "mgavb.h"#include "mgastate.h"static void mgaRenderPrimitive( GLcontext *ctx, GLenum prim );/*********************************************************************** *                 Functions to draw basic primitives                  * ***********************************************************************/#if defined (USE_X86_ASM)#define EMIT_VERT( j, vb, vertex_size, v )		\do {	int __tmp;					\	__asm__ __volatile__( "rep ; movsl"		\			 : "=%c" (j), "=D" (vb), "=S" (__tmp)		\			 : "0" (vertex_size), 		\			   "D" ((long)vb), 		\			   "S" ((long)v));		\} while (0)#else#define EMIT_VERT( j, vb, vertex_size, v )	\do {						\   for ( j = 0 ; j < vertex_size ; j++ )	\      vb[j] = (v)->ui[j];			\   vb += vertex_size;				\} while (0)#endifstatic void INLINE mga_draw_triangle( mgaContextPtr mmesa,					   mgaVertexPtr v0,					   mgaVertexPtr v1,					   mgaVertexPtr v2 ){   GLuint vertex_size = mmesa->vertex_size;   GLuint *vb = mgaAllocDmaLow( mmesa, 3 * 4 * vertex_size );   int j;   EMIT_VERT( j, vb, vertex_size, v0 );   EMIT_VERT( j, vb, vertex_size, v1 );   EMIT_VERT( j, vb, vertex_size, v2 );}static void INLINE mga_draw_quad( mgaContextPtr mmesa,				       mgaVertexPtr v0,				       mgaVertexPtr v1,				       mgaVertexPtr v2,				       mgaVertexPtr v3 ){   GLuint vertex_size = mmesa->vertex_size;   GLuint *vb = mgaAllocDmaLow( mmesa, 6 * 4 * vertex_size );   int j;   EMIT_VERT( j, vb, vertex_size, v0 );   EMIT_VERT( j, vb, vertex_size, v1 );   EMIT_VERT( j, vb, vertex_size, v3 );   EMIT_VERT( j, vb, vertex_size, v1 );   EMIT_VERT( j, vb, vertex_size, v2 );   EMIT_VERT( j, vb, vertex_size, v3 );}static INLINE void mga_draw_point( mgaContextPtr mmesa,					mgaVertexPtr tmp ){   const GLfloat sz = 0.5 * CLAMP(mmesa->glCtx->Point.Size,                                  mmesa->glCtx->Const.MinPointSize,                                  mmesa->glCtx->Const.MaxPointSize);   const int vertex_size = mmesa->vertex_size;   GLuint *vb = mgaAllocDmaLow( mmesa, 6 * 4 * vertex_size );   int j;   #if 0   v0->v.x += PNT_X_OFFSET - TRI_X_OFFSET;   v0->v.y += PNT_Y_OFFSET - TRI_Y_OFFSET;#endif   /* Draw a point as two triangles.    */   *(float *)&vb[0] = tmp->v.x - sz;   *(float *)&vb[1] = tmp->v.y - sz;   for (j = 2 ; j < vertex_size ; j++)       vb[j] = tmp->ui[j];   vb += vertex_size;   *(float *)&vb[0] = tmp->v.x + sz;   *(float *)&vb[1] = tmp->v.y - sz;   for (j = 2 ; j < vertex_size ; j++)       vb[j] = tmp->ui[j];   vb += vertex_size;   *(float *)&vb[0] = tmp->v.x + sz;   *(float *)&vb[1] = tmp->v.y + sz;   for (j = 2 ; j < vertex_size ; j++)       vb[j] = tmp->ui[j];   vb += vertex_size;   *(float *)&vb[0] = tmp->v.x + sz;   *(float *)&vb[1] = tmp->v.y + sz;   for (j = 2 ; j < vertex_size ; j++)       vb[j] = tmp->ui[j];   vb += vertex_size;   *(float *)&vb[0] = tmp->v.x - sz;   *(float *)&vb[1] = tmp->v.y + sz;   for (j = 2 ; j < vertex_size ; j++)       vb[j] = tmp->ui[j];   vb += vertex_size;   *(float *)&vb[0] = tmp->v.x - sz;   *(float *)&vb[1] = tmp->v.y - sz;   for (j = 2 ; j < vertex_size ; j++)       vb[j] = tmp->ui[j];#if 0   v0->v.x -= PNT_X_OFFSET - TRI_X_OFFSET;   v0->v.y -= PNT_Y_OFFSET - TRI_Y_OFFSET;#endif}static INLINE void mga_draw_line( mgaContextPtr mmesa,				      mgaVertexPtr v0,				      mgaVertexPtr v1 ){   GLuint vertex_size = mmesa->vertex_size;   GLuint *vb = mgaAllocDmaLow( mmesa, 6 * 4 * vertex_size );   GLfloat dx, dy, ix, iy;   const GLfloat width = CLAMP(mmesa->glCtx->Line.Width,                               mmesa->glCtx->Const.MinLineWidth,                               mmesa->glCtx->Const.MaxLineWidth);   GLint j;#if 0   v0->v.x += LINE_X_OFFSET - TRI_X_OFFSET;   v0->v.y += LINE_Y_OFFSET - TRI_Y_OFFSET;   v1->v.x += LINE_X_OFFSET - TRI_X_OFFSET;   v1->v.y += LINE_Y_OFFSET - TRI_Y_OFFSET;#endif   dx = v0->v.x - v1->v.x;   dy = v0->v.y - v1->v.y;      ix = width * .5; iy = 0;   if (dx * dx > dy * dy) {      iy = ix; ix = 0;   }   *(float *)&vb[0] = v0->v.x - ix;   *(float *)&vb[1] = v0->v.y - iy;   for (j = 2 ; j < vertex_size ; j++)       vb[j] = v0->ui[j];   vb += vertex_size;   *(float *)&vb[0] = v1->v.x + ix;   *(float *)&vb[1] = v1->v.y + iy;   for (j = 2 ; j < vertex_size ; j++)       vb[j] = v1->ui[j];   vb += vertex_size;   *(float *)&vb[0] = v0->v.x + ix;   *(float *)&vb[1] = v0->v.y + iy;   for (j = 2 ; j < vertex_size ; j++)       vb[j] = v0->ui[j];   vb += vertex_size;	    *(float *)&vb[0] = v0->v.x - ix;   *(float *)&vb[1] = v0->v.y - iy;   for (j = 2 ; j < vertex_size ; j++)       vb[j] = v0->ui[j];   vb += vertex_size;   *(float *)&vb[0] = v1->v.x - ix;   *(float *)&vb[1] = v1->v.y - iy;   for (j = 2 ; j < vertex_size ; j++)       vb[j] = v1->ui[j];   vb += vertex_size;   *(float *)&vb[0] = v1->v.x + ix;   *(float *)&vb[1] = v1->v.y + iy;   for (j = 2 ; j < vertex_size ; j++)       vb[j] = v1->ui[j];   vb += vertex_size;#if 0   v0->v.x -= LINE_X_OFFSET - TRI_X_OFFSET;   v0->v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET;   v1->v.x -= LINE_X_OFFSET - TRI_X_OFFSET;   v1->v.y -= LINE_Y_OFFSET - TRI_Y_OFFSET;#endif}/*********************************************************************** *          Macros for t_dd_tritmp.h to draw basic primitives          * ***********************************************************************/#define TRI( a, b, c )				\do {						\   if (DO_FALLBACK)				\      mmesa->draw_tri( mmesa, a, b, c );	\   else						\      mga_draw_triangle( mmesa, a, b, c );	\} while (0)#define QUAD( a, b, c, d )			\do {						\   if (DO_FALLBACK) {				\      mmesa->draw_tri( mmesa, a, b, d );	\      mmesa->draw_tri( mmesa, b, c, d );	\   } else {					\      mga_draw_quad( mmesa, a, b, c, d );	\   }						\} while (0)#define LINE( v0, v1 )				\do {						\   if (DO_FALLBACK)				\      mmesa->draw_line( mmesa, v0, v1 );	\   else {					\      mga_draw_line( mmesa, v0, v1 );		\   }						\} while (0)#define POINT( v0 )				\do {						\   if (DO_FALLBACK)				\      mmesa->draw_point( mmesa, v0 );		\   else {					\      mga_draw_point( mmesa, v0 );		\   }						\} while (0)/*********************************************************************** *              Fallback to swrast for basic primitives                * ***********************************************************************//* This code is hit only when a mix of accelerated and unaccelerated * primitives are being drawn, and only for the unaccelerated * primitives.   */static void mga_fallback_tri( mgaContextPtr mmesa, 		   mgaVertex *v0, 		   mgaVertex *v1, 		   mgaVertex *v2 ){   GLcontext *ctx = mmesa->glCtx;   SWvertex v[3];   mga_translate_vertex( ctx, v0, &v[0] );   mga_translate_vertex( ctx, v1, &v[1] );   mga_translate_vertex( ctx, v2, &v[2] );   _swrast_Triangle( ctx, &v[0], &v[1], &v[2] );}static void mga_fallback_line( mgaContextPtr mmesa,		    mgaVertex *v0,		    mgaVertex *v1 ){   GLcontext *ctx = mmesa->glCtx;   SWvertex v[2];   mga_translate_vertex( ctx, v0, &v[0] );   mga_translate_vertex( ctx, v1, &v[1] );   _swrast_Line( ctx, &v[0], &v[1] );}static void mga_fallback_point( mgaContextPtr mmesa, 		     mgaVertex *v0 ){   GLcontext *ctx = mmesa->glCtx;   SWvertex v[1];   mga_translate_vertex( ctx, v0, &v[0] );   _swrast_Point( ctx, &v[0] );}/*********************************************************************** *              Build render functions from dd templates               * ***********************************************************************/#define MGA_UNFILLED_BIT    0x1#define MGA_OFFSET_BIT	    0x2#define MGA_TWOSIDE_BIT     0x4#define MGA_FLAT_BIT        0x8	/* mga can't flatshade? */#define MGA_FALLBACK_BIT    0x10#define MGA_MAX_TRIFUNC     0x20static struct {   tnl_points_func	        points;   tnl_line_func		line;   tnl_triangle_func	triangle;   tnl_quad_func		quad;} rast_tab[MGA_MAX_TRIFUNC];#define DO_FALLBACK (IND & MGA_FALLBACK_BIT)#define DO_OFFSET   (IND & MGA_OFFSET_BIT)#define DO_UNFILLED (IND & MGA_UNFILLED_BIT)#define DO_TWOSIDE  (IND & MGA_TWOSIDE_BIT)#define DO_FLAT     (IND & MGA_FLAT_BIT)#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_BACK_COLORS  0#define HAVE_SPEC         1#define HAVE_HW_FLATSHADE 0#define VERTEX mgaVertex#define TAB rast_tab#define DEPTH_SCALE mmesa->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) (mmesa->verts + (e * mmesa->vertex_size * sizeof(int)))#define VERT_SET_RGBA( v, c )  					\do {								\   mga_color_t *color = (mga_color_t *)&((v)->ui[4]);	\   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[4] = v1->ui[4]#define VERT_SET_SPEC( v0, c )					\do {								\   UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.red, (c)[0]);	\   UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.green, (c)[1]);	\   UNCLAMPED_FLOAT_TO_UBYTE(v0->v.specular.blue, (c)[2]);	\} while (0)#define VERT_COPY_SPEC( v0, v1 )		\do {						\   v0->v.specular.red   = v1->v.specular.red;	\   v0->v.specular.green = v1->v.specular.green;	\   v0->v.specular.blue  = v1->v.specular.blue;	\} while (0)#define VERT_SAVE_RGBA( idx )    color[idx] = v[idx]->ui[4]#define VERT_RESTORE_RGBA( idx ) v[idx]->ui[4] = color[idx]#define VERT_SAVE_SPEC( idx )    spec[idx] = v[idx]->ui[5]#define VERT_RESTORE_SPEC( idx ) v[idx]->ui[5] = spec[idx]#define LOCAL_VARS(n)					\   mgaContextPtr mmesa = MGA_CONTEXT(ctx);		\   GLuint color[n], spec[n];				\   (void) color; (void) spec;/*********************************************************************** *            Functions to draw basic unfilled primitives              * ***********************************************************************/#define RASTERIZE(x) if (mmesa->raster_primitive != x) \                        mgaRasterPrimitive( ctx, x, MGA_WA_TRIANGLES )#define RENDER_PRIMITIVE mmesa->render_primitive#define IND MGA_FALLBACK_BIT#define TAG(x) x#include "tnl_dd/t_dd_unfilled.h"#undef IND/*********************************************************************** *                 Functions to draw GL primitives                     * ***********************************************************************/#define IND (0)#define TAG(x) x#include "tnl_dd/t_dd_tritmp.h"#define IND (MGA_OFFSET_BIT)#define TAG(x) x##_offset#include "tnl_dd/t_dd_tritmp.h"#define IND (MGA_TWOSIDE_BIT)#define TAG(x) x##_twoside#include "tnl_dd/t_dd_tritmp.h"#define IND (MGA_TWOSIDE_BIT|MGA_OFFSET_BIT)#define TAG(x) x##_twoside_offset#include "tnl_dd/t_dd_tritmp.h"#define IND (MGA_UNFILLED_BIT)#define TAG(x) x##_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (MGA_OFFSET_BIT|MGA_UNFILLED_BIT)#define TAG(x) x##_offset_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (MGA_TWOSIDE_BIT|MGA_UNFILLED_BIT)#define TAG(x) x##_twoside_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (MGA_TWOSIDE_BIT|MGA_OFFSET_BIT|MGA_UNFILLED_BIT)#define TAG(x) x##_twoside_offset_unfilled#include "tnl_dd/t_dd_tritmp.h"#define IND (MGA_FALLBACK_BIT)#define TAG(x) x##_fallback#include "tnl_dd/t_dd_tritmp.h"#define IND (MGA_OFFSET_BIT|MGA_FALLBACK_BIT)#define TAG(x) x##_offset_fallback

⌨️ 快捷键说明

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