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

📄 s_aatritemp.h

📁 mesa-6.5-minigui源码
💻 H
📖 第 1 页 / 共 2 页
字号:
/* * Mesa 3-D graphics library * Version:  6.5 * * Copyright (C) 1999-2005  Brian Paul   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 * 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 * BRIAN PAUL 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. *//* * Antialiased Triangle Rasterizer Template * * This file is #include'd to generate custom AA triangle rasterizers. * NOTE: this code hasn't been optimized yet.  That'll come after it * works correctly. * * The following macros may be defined to indicate what auxillary information * must be copmuted across the triangle: *    DO_Z         - if defined, compute Z values *    DO_RGBA      - if defined, compute RGBA values *    DO_INDEX     - if defined, compute color index values *    DO_SPEC      - if defined, compute specular RGB values *    DO_TEX       - if defined, compute unit 0 STRQ texcoords *    DO_MULTITEX  - if defined, compute all unit's STRQ texcoords *//*void triangle( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint pv )*/{   const GLfloat *p0 = v0->win;   const GLfloat *p1 = v1->win;   const GLfloat *p2 = v2->win;   const SWvertex *vMin, *vMid, *vMax;   GLint iyMin, iyMax;   GLfloat yMin, yMax;   GLboolean ltor;   GLfloat majDx, majDy;  /* major (i.e. long) edge dx and dy */      struct sw_span span;   #ifdef DO_Z   GLfloat zPlane[4];#endif#ifdef DO_FOG   GLfloat fogPlane[4];#else   GLfloat *fog = NULL;#endif#ifdef DO_RGBA   GLfloat rPlane[4], gPlane[4], bPlane[4], aPlane[4];#endif#ifdef DO_INDEX   GLfloat iPlane[4];#endif#ifdef DO_SPEC   GLfloat srPlane[4], sgPlane[4], sbPlane[4];#endif#ifdef DO_TEX   GLfloat sPlane[4], tPlane[4], uPlane[4], vPlane[4];   GLfloat texWidth, texHeight;#elif defined(DO_MULTITEX)   GLfloat sPlane[MAX_TEXTURE_COORD_UNITS][4];  /* texture S */   GLfloat tPlane[MAX_TEXTURE_COORD_UNITS][4];  /* texture T */   GLfloat uPlane[MAX_TEXTURE_COORD_UNITS][4];  /* texture R */   GLfloat vPlane[MAX_TEXTURE_COORD_UNITS][4];  /* texture Q */   GLfloat texWidth[MAX_TEXTURE_COORD_UNITS];   GLfloat texHeight[MAX_TEXTURE_COORD_UNITS];#endif   GLfloat bf = SWRAST_CONTEXT(ctx)->_BackfaceSign;         INIT_SPAN(span, GL_POLYGON, 0, 0, SPAN_COVERAGE);   /* determine bottom to top order of vertices */   {      GLfloat y0 = v0->win[1];      GLfloat y1 = v1->win[1];      GLfloat y2 = v2->win[1];      if (y0 <= y1) {	 if (y1 <= y2) {	    vMin = v0;   vMid = v1;   vMax = v2;   /* y0<=y1<=y2 */	 }	 else if (y2 <= y0) {	    vMin = v2;   vMid = v0;   vMax = v1;   /* y2<=y0<=y1 */	 }	 else {	    vMin = v0;   vMid = v2;   vMax = v1;  bf = -bf; /* y0<=y2<=y1 */	 }      }      else {	 if (y0 <= y2) {	    vMin = v1;   vMid = v0;   vMax = v2;  bf = -bf; /* y1<=y0<=y2 */	 }	 else if (y2 <= y1) {	    vMin = v2;   vMid = v1;   vMax = v0;  bf = -bf; /* y2<=y1<=y0 */	 }	 else {	    vMin = v1;   vMid = v2;   vMax = v0;   /* y1<=y2<=y0 */	 }      }   }   majDx = vMax->win[0] - vMin->win[0];   majDy = vMax->win[1] - vMin->win[1];   {      const GLfloat botDx = vMid->win[0] - vMin->win[0];      const GLfloat botDy = vMid->win[1] - vMin->win[1];      const GLfloat area = majDx * botDy - botDx * majDy;      /* Do backface culling */      if (area * bf < 0 || area == 0 || IS_INF_OR_NAN(area))	 return;      ltor = (GLboolean) (area < 0.0F);   }   /* Plane equation setup:    * We evaluate plane equations at window (x,y) coordinates in order    * to compute color, Z, fog, texcoords, etc.  This isn't terribly    * efficient but it's easy and reliable.    */#ifdef DO_Z   compute_plane(p0, p1, p2, p0[2], p1[2], p2[2], zPlane);   span.arrayMask |= SPAN_Z;#endif#ifdef DO_FOG   compute_plane(p0, p1, p2, v0->fog, v1->fog, v2->fog, fogPlane);   span.arrayMask |= SPAN_FOG;#endif#ifdef DO_RGBA   if (ctx->Light.ShadeModel == GL_SMOOTH) {      compute_plane(p0, p1, p2, v0->color[RCOMP], v1->color[RCOMP], v2->color[RCOMP], rPlane);      compute_plane(p0, p1, p2, v0->color[GCOMP], v1->color[GCOMP], v2->color[GCOMP], gPlane);      compute_plane(p0, p1, p2, v0->color[BCOMP], v1->color[BCOMP], v2->color[BCOMP], bPlane);      compute_plane(p0, p1, p2, v0->color[ACOMP], v1->color[ACOMP], v2->color[ACOMP], aPlane);   }   else {      constant_plane(v2->color[RCOMP], rPlane);      constant_plane(v2->color[GCOMP], gPlane);      constant_plane(v2->color[BCOMP], bPlane);      constant_plane(v2->color[ACOMP], aPlane);   }   span.arrayMask |= SPAN_RGBA;#endif#ifdef DO_INDEX   if (ctx->Light.ShadeModel == GL_SMOOTH) {      compute_plane(p0, p1, p2, (GLfloat) v0->index,                    v1->index, v2->index, iPlane);   }   else {      constant_plane(v2->index, iPlane);   }   span.arrayMask |= SPAN_INDEX;#endif#ifdef DO_SPEC   if (ctx->Light.ShadeModel == GL_SMOOTH) {      compute_plane(p0, p1, p2, v0->specular[RCOMP], v1->specular[RCOMP], v2->specular[RCOMP], srPlane);      compute_plane(p0, p1, p2, v0->specular[GCOMP], v1->specular[GCOMP], v2->specular[GCOMP], sgPlane);      compute_plane(p0, p1, p2, v0->specular[BCOMP], v1->specular[BCOMP], v2->specular[BCOMP], sbPlane);   }   else {      constant_plane(v2->specular[RCOMP], srPlane);      constant_plane(v2->specular[GCOMP], sgPlane);      constant_plane(v2->specular[BCOMP], sbPlane);   }   span.arrayMask |= SPAN_SPEC;#endif#ifdef DO_TEX   {      const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current;      const struct gl_texture_image *texImage = obj->Image[0][obj->BaseLevel];      const GLfloat invW0 = v0->win[3];      const GLfloat invW1 = v1->win[3];      const GLfloat invW2 = v2->win[3];      const GLfloat s0 = v0->texcoord[0][0] * invW0;      const GLfloat s1 = v1->texcoord[0][0] * invW1;      const GLfloat s2 = v2->texcoord[0][0] * invW2;      const GLfloat t0 = v0->texcoord[0][1] * invW0;      const GLfloat t1 = v1->texcoord[0][1] * invW1;      const GLfloat t2 = v2->texcoord[0][1] * invW2;      const GLfloat r0 = v0->texcoord[0][2] * invW0;      const GLfloat r1 = v1->texcoord[0][2] * invW1;      const GLfloat r2 = v2->texcoord[0][2] * invW2;      const GLfloat q0 = v0->texcoord[0][3] * invW0;      const GLfloat q1 = v1->texcoord[0][3] * invW1;      const GLfloat q2 = v2->texcoord[0][3] * invW2;      compute_plane(p0, p1, p2, s0, s1, s2, sPlane);      compute_plane(p0, p1, p2, t0, t1, t2, tPlane);      compute_plane(p0, p1, p2, r0, r1, r2, uPlane);      compute_plane(p0, p1, p2, q0, q1, q2, vPlane);      texWidth = (GLfloat) texImage->Width;      texHeight = (GLfloat) texImage->Height;   }   span.arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA);#elif defined(DO_MULTITEX)   {      GLuint u;      for (u = 0; u < ctx->Const.MaxTextureUnits; u++) {         if (ctx->Texture.Unit[u]._ReallyEnabled) {            const struct gl_texture_object *obj = ctx->Texture.Unit[u]._Current;            const struct gl_texture_image *texImage = obj->Image[0][obj->BaseLevel];            const GLfloat invW0 = v0->win[3];            const GLfloat invW1 = v1->win[3];            const GLfloat invW2 = v2->win[3];            const GLfloat s0 = v0->texcoord[u][0] * invW0;            const GLfloat s1 = v1->texcoord[u][0] * invW1;            const GLfloat s2 = v2->texcoord[u][0] * invW2;            const GLfloat t0 = v0->texcoord[u][1] * invW0;            const GLfloat t1 = v1->texcoord[u][1] * invW1;            const GLfloat t2 = v2->texcoord[u][1] * invW2;            const GLfloat r0 = v0->texcoord[u][2] * invW0;            const GLfloat r1 = v1->texcoord[u][2] * invW1;            const GLfloat r2 = v2->texcoord[u][2] * invW2;            const GLfloat q0 = v0->texcoord[u][3] * invW0;            const GLfloat q1 = v1->texcoord[u][3] * invW1;            const GLfloat q2 = v2->texcoord[u][3] * invW2;            compute_plane(p0, p1, p2, s0, s1, s2, sPlane[u]);            compute_plane(p0, p1, p2, t0, t1, t2, tPlane[u]);            compute_plane(p0, p1, p2, r0, r1, r2, uPlane[u]);            compute_plane(p0, p1, p2, q0, q1, q2, vPlane[u]);            texWidth[u]  = (GLfloat) texImage->Width;            texHeight[u] = (GLfloat) texImage->Height;         }      }   }   span.arrayMask |= (SPAN_TEXTURE | SPAN_LAMBDA);#endif   /* Begin bottom-to-top scan over the triangle.    * The long edge will either be on the left or right side of the    * triangle.  We always scan from the long edge toward the shorter    * edges, stopping when we find that coverage = 0.  If the long edge    * is on the left we scan left-to-right.  Else, we scan right-to-left.    */   yMin = vMin->win[1];   yMax = vMax->win[1];   iyMin = (GLint) yMin;   iyMax = (GLint) yMax + 1;   if (ltor) {      /* scan left to right */      const GLfloat *pMin = vMin->win;      const GLfloat *pMid = vMid->win;      const GLfloat *pMax = vMax->win;      const GLfloat dxdy = majDx / majDy;      const GLfloat xAdj = dxdy < 0.0F ? -dxdy : 0.0F;      GLfloat x = pMin[0] - (yMin - iyMin) * dxdy;      GLint iy;      for (iy = iyMin; iy < iyMax; iy++, x += dxdy) {         GLint ix, startX = (GLint) (x - xAdj);         GLuint count;         GLfloat coverage = 0.0F;         /* skip over fragments with zero coverage */         while (startX < MAX_WIDTH) {            coverage = compute_coveragef(pMin, pMid, pMax, startX, iy);            if (coverage > 0.0F)               break;            startX++;

⌨️ 快捷键说明

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