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

📄 savagetris.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 3 页
字号:
/* $XFree86$ */ /* -*- c-basic-offset: 3 -*- *//**************************************************************************Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and                     VA Linux Systems Inc., Fremont, California.All Rights Reserved.Permission is hereby granted, free of charge, to any person obtaining acopy of this software and associated documentation files (the "Software"),to deal in the Software without restriction, including without limitationon the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whomthe Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice (including the nextparagraph) shall be included in all copies or substantial portions of theSoftware.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALLATI, VA LINUX SYSTEMS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OROTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THEUSE OR OTHER DEALINGS IN THE SOFTWARE.**************************************************************************//* * Authors: *   Keith Whitwell <keithw@valinux.com> *   Felix Kuehling <fxkuehl@gmx.de> * */#include <stdio.h>#include <math.h>#include "glheader.h"#include "mtypes.h"#include "colormac.h"#include "macros.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"#include "savagetris.h"#include "savagestate.h"#include "savagetex.h"#include "savageioctl.h"#include "savage_bci.h"static void savageRasterPrimitive( GLcontext *ctx, GLuint prim );static void savageRenderPrimitive( GLcontext *ctx, GLenum prim );static 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}; /*********************************************************************** *                    Emit primitives                                  * ***********************************************************************/#if defined (USE_X86_ASM)#define EMIT_VERT( j, vb, vertex_size, start, v )		\do {	int __tmp;						\	 vb += start;						\	__asm__ __volatile__( "rep ; movsl"			\			 : "=%c" (j), "=D" (vb), "=S" (__tmp)	\			 : "0" (vertex_size-start),		\			   "D" ((long)vb),			\			   "S" ((long)&(v)->ui[start]));	\} while (0)#else#define EMIT_VERT( j, vb, vertex_size, start, v )	\do {						\   for ( j = start ; j < vertex_size ; j++ )	\      vb[j] = (v)->ui[j];			\   vb += vertex_size;				\} while (0)#endifstatic void INLINE savage_draw_triangle (savageContextPtr imesa,					     savageVertexPtr v0,					     savageVertexPtr v1,					     savageVertexPtr v2) {   GLuint vertsize = imesa->HwVertexSize;   u_int32_t *vb = savageAllocVtxBuf (imesa, 3*vertsize);   GLuint j;   EMIT_VERT (j, vb, vertsize, 0, v0);   EMIT_VERT (j, vb, vertsize, 0, v1);   EMIT_VERT (j, vb, vertsize, 0, v2);}static void INLINE savage_draw_quad (savageContextPtr imesa,					 savageVertexPtr v0,					 savageVertexPtr v1,					 savageVertexPtr v2,					 savageVertexPtr v3) {   GLuint vertsize = imesa->HwVertexSize;   u_int32_t *vb = savageAllocVtxBuf (imesa, 6*vertsize);   GLuint j;   EMIT_VERT (j, vb, vertsize, 0, v0);   EMIT_VERT (j, vb, vertsize, 0, v1);   EMIT_VERT (j, vb, vertsize, 0, v3);   EMIT_VERT (j, vb, vertsize, 0, v1);   EMIT_VERT (j, vb, vertsize, 0, v2);   EMIT_VERT (j, vb, vertsize, 0, v3);}static INLINE void savage_draw_point (savageContextPtr imesa,					  savageVertexPtr tmp) {   GLuint vertsize = imesa->HwVertexSize;   u_int32_t *vb = savageAllocVtxBuf (imesa, 6*vertsize);   const GLfloat x = tmp->v.x;   const GLfloat y = tmp->v.y;   const GLfloat sz = 0.5 * CLAMP(imesa->glCtx->Point.Size,                                  imesa->glCtx->Const.MinPointSize,                                  imesa->glCtx->Const.MaxPointSize);   GLuint j;   *(float *)&vb[0] = x - sz;   *(float *)&vb[1] = y - sz;   EMIT_VERT (j, vb, vertsize, 2, tmp);   *(float *)&vb[0] = x + sz;   *(float *)&vb[1] = y - sz;   EMIT_VERT (j, vb, vertsize, 2, tmp);   *(float *)&vb[0] = x + sz;   *(float *)&vb[1] = y + sz;   EMIT_VERT (j, vb, vertsize, 2, tmp);   *(float *)&vb[0] = x + sz;   *(float *)&vb[1] = y + sz;   EMIT_VERT (j, vb, vertsize, 2, tmp);   *(float *)&vb[0] = x - sz;   *(float *)&vb[1] = y + sz;   EMIT_VERT (j, vb, vertsize, 2, tmp);   *(float *)&vb[0] = x - sz;   *(float *)&vb[1] = y - sz;   EMIT_VERT (j, vb, vertsize, 2, tmp);}static INLINE void savage_draw_line (savageContextPtr imesa,					 savageVertexPtr v0,					 savageVertexPtr v1 ) {   GLuint vertsize = imesa->HwVertexSize;   u_int32_t *vb = savageAllocVtxBuf (imesa, 6*vertsize);   const GLfloat width = CLAMP(imesa->glCtx->Line.Width,                               imesa->glCtx->Const.MinLineWidth,                               imesa->glCtx->Const.MaxLineWidth);   GLfloat dx, dy, ix, iy;   GLuint j;   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;   EMIT_VERT (j, vb, vertsize, 2, v0);   *(float *)&vb[0] = v1->v.x + ix;   *(float *)&vb[1] = v1->v.y + iy;   EMIT_VERT (j, vb, vertsize, 2, v1);   *(float *)&vb[0] = v0->v.x + ix;   *(float *)&vb[1] = v0->v.y + iy;   EMIT_VERT (j, vb, vertsize, 2, v0);   *(float *)&vb[0] = v0->v.x - ix;   *(float *)&vb[1] = v0->v.y - iy;   EMIT_VERT (j, vb, vertsize, 2, v0);   *(float *)&vb[0] = v1->v.x - ix;   *(float *)&vb[1] = v1->v.y - iy;   EMIT_VERT (j, vb, vertsize, 2, v1);   *(float *)&vb[0] = v1->v.x + ix;   *(float *)&vb[1] = v1->v.y + iy;   EMIT_VERT (j, vb, vertsize, 2, v1);} /* Fallback drawing functions for the ptex hack. Code duplication * (especially lines and points) isn't beautiful, but I didn't feel * like inventing yet another template. :-/ */#define PTEX_VERTEX( j, tmp, vertex_size, start, v)	\do {							\   GLfloat rhw = 1.0 / v->f[vertex_size];		\   for ( j = start ; j < vertex_size ; j++ )		\      tmp.f[j] = v->f[j];				\   tmp.f[3] *= v->f[vertex_size];			\   tmp.f[vertex_size-2] *= rhw;				\   tmp.f[vertex_size-1] *= rhw;				\} while (0)static void INLINE savage_ptex_tri (savageContextPtr imesa,					savageVertexPtr v0,					savageVertexPtr v1,					savageVertexPtr v2) {   GLuint vertsize = imesa->HwVertexSize;   u_int32_t *vb = savageAllocVtxBuf (imesa, 3*vertsize);   savageVertex tmp;   GLuint j;   PTEX_VERTEX (j, tmp, vertsize, 0, v0); EMIT_VERT (j, vb, vertsize, 0, &tmp);   PTEX_VERTEX (j, tmp, vertsize, 0, v1); EMIT_VERT (j, vb, vertsize, 0, &tmp);   PTEX_VERTEX (j, tmp, vertsize, 0, v2); EMIT_VERT (j, vb, vertsize, 0, &tmp);}static INLINE void savage_ptex_line (savageContextPtr imesa,					 savageVertexPtr v0,					 savageVertexPtr v1 ) {   GLuint vertsize = imesa->HwVertexSize;   u_int32_t *vb = savageAllocVtxBuf (imesa, 6*vertsize);   const GLfloat width = CLAMP(imesa->glCtx->Line.Width,                               imesa->glCtx->Const.MinLineWidth,                               imesa->glCtx->Const.MaxLineWidth);   GLfloat dx, dy, ix, iy;   savageVertex tmp0, tmp1;   GLuint j;   PTEX_VERTEX (j, tmp0, vertsize, 2, v0);   PTEX_VERTEX (j, tmp1, vertsize, 2, v1);   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;   EMIT_VERT (j, vb, vertsize, 2, &tmp0);   *(float *)&vb[0] = v1->v.x + ix;   *(float *)&vb[1] = v1->v.y + iy;   EMIT_VERT (j, vb, vertsize, 2, &tmp1);   *(float *)&vb[0] = v0->v.x + ix;   *(float *)&vb[1] = v0->v.y + iy;   EMIT_VERT (j, vb, vertsize, 2, &tmp0);   *(float *)&vb[0] = v0->v.x - ix;   *(float *)&vb[1] = v0->v.y - iy;   EMIT_VERT (j, vb, vertsize, 2, &tmp0);   *(float *)&vb[0] = v1->v.x - ix;   *(float *)&vb[1] = v1->v.y - iy;   EMIT_VERT (j, vb, vertsize, 2, &tmp1);   *(float *)&vb[0] = v1->v.x + ix;   *(float *)&vb[1] = v1->v.y + iy;   EMIT_VERT (j, vb, vertsize, 2, &tmp1);} static INLINE void savage_ptex_point (savageContextPtr imesa,					  savageVertexPtr v0) {   GLuint vertsize = imesa->HwVertexSize;   u_int32_t *vb = savageAllocVtxBuf (imesa, 6*vertsize);   const GLfloat x = v0->v.x;   const GLfloat y = v0->v.y;   const GLfloat sz = 0.5 * CLAMP(imesa->glCtx->Point.Size,                                  imesa->glCtx->Const.MinPointSize,                                  imesa->glCtx->Const.MaxPointSize);   savageVertex tmp;   GLuint j;   PTEX_VERTEX (j, tmp, vertsize, 2, v0);   *(float *)&vb[0] = x - sz;   *(float *)&vb[1] = y - sz;   EMIT_VERT (j, vb, vertsize, 2, &tmp);   *(float *)&vb[0] = x + sz;   *(float *)&vb[1] = y - sz;   EMIT_VERT (j, vb, vertsize, 2, &tmp);   *(float *)&vb[0] = x + sz;   *(float *)&vb[1] = y + sz;   EMIT_VERT (j, vb, vertsize, 2, &tmp);   *(float *)&vb[0] = x + sz;   *(float *)&vb[1] = y + sz;   EMIT_VERT (j, vb, vertsize, 2, &tmp);   *(float *)&vb[0] = x - sz;   *(float *)&vb[1] = y + sz;   EMIT_VERT (j, vb, vertsize, 2, &tmp);   *(float *)&vb[0] = x - sz;   *(float *)&vb[1] = y - sz;   EMIT_VERT (j, vb, vertsize, 2, &tmp);} /*********************************************************************** *          Macros for t_dd_tritmp.h to draw basic primitives          * ***********************************************************************/#define TRI( a, b, c )				\do {						\   if (DO_FALLBACK)				\      imesa->draw_tri( imesa, a, b, c );	\   else						\      savage_draw_triangle( imesa, a, b, c );	\} while (0)#define QUAD( a, b, c, d )			\do {						\   if (DO_FALLBACK) {				\      imesa->draw_tri( imesa, a, b, d );	\      imesa->draw_tri( imesa, b, c, d );	\   } else 					\      savage_draw_quad( imesa, a, b, c, d );	\} while (0)#define LINE( v0, v1 )				\do {						\   if (DO_FALLBACK)				\      imesa->draw_line( imesa, v0, v1 );	\   else 					\      savage_draw_line( imesa, v0, v1 );	\} while (0)#define POINT( v0 )				\do {						\   if (DO_FALLBACK)				\      imesa->draw_point( imesa, v0 );		\   else 					\      savage_draw_point( imesa, v0 );		\} while (0)/*********************************************************************** *              Build render functions from dd templates               * ***********************************************************************/#define SAVAGE_OFFSET_BIT	 0x1#define SAVAGE_TWOSIDE_BIT       0x2#define SAVAGE_UNFILLED_BIT      0x4#define SAVAGE_FALLBACK_BIT      0x8#define SAVAGE_MAX_TRIFUNC       0x10static struct {   tnl_points_func	        points;   tnl_line_func		line;   tnl_triangle_func	triangle;   tnl_quad_func		quad;} rast_tab[SAVAGE_MAX_TRIFUNC];#define DO_FALLBACK (IND & SAVAGE_FALLBACK_BIT)#define DO_OFFSET   (IND & SAVAGE_OFFSET_BIT)#define DO_UNFILLED (IND & SAVAGE_UNFILLED_BIT)#define DO_TWOSIDE  (IND & SAVAGE_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   1#define HAVE_BACK_COLORS  0#define HAVE_HW_FLATSHADE 1#define VERTEX savageVertex#define TAB rast_tab#define DEPTH_SCALE imesa->depth_scale#define REVERSE_DEPTH 1#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) (imesa->verts + (e * imesa->vertex_size * sizeof(int)))#define VERT_SET_RGBA( v, c )					\do {								\   savage_color_t *color = (savage_color_t *)&((v)->ub4[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_SAVE_RGBA( idx )    color[idx] = v[idx]->ui[coloroffset]#define VERT_RESTORE_RGBA( idx ) v[idx]->ui[coloroffset] = color[idx]#define VERT_SET_SPEC( v, c )					\do {								\   if (specoffset) {						\      savage_color_t *spec = (savage_color_t *)&((v)->ub4[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 )					\   if (specoffset) COPY_3V(v0->ub4[specoffset], v1->ub4[specoffset])#define VERT_SAVE_SPEC( idx )						\   if (specoffset) spec[idx] = v[idx]->ui[specoffset]#define VERT_RESTORE_SPEC( idx )					\   if (specoffset) v[idx]->ui[specoffset] = spec[idx]#define LOCAL_VARS(n)						\

⌨️ 快捷键说明

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