s_triangle.c revision 09da0b8e6621a831e3eeb9381430f2bed18a22ad
1e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
2e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Mesa 3-D graphics library
3230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul * Version:  6.1
422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
5230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
7e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a
8e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * copy of this software and associated documentation files (the "Software"),
9e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * to deal in the Software without restriction, including without limitation
10e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * and/or sell copies of the Software, and to permit persons to whom the
12e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Software is furnished to do so, subject to the following conditions:
1322144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
14e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * The above copyright notice and this permission notice shall be included
15e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * in all copies or substantial portions of the Software.
1622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
17e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
24e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
25e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
26e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
27709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell * When the device driver doesn't implement triangle rasterization it
28709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell * can hook in _swrast_Triangle, which eventually calls one of these
2938f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes * functions to draw triangles.
30e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
31e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
32e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "glheader.h"
33e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "context.h"
3446b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell#include "colormac.h"
353c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul#include "imports.h"
36e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "macros.h"
3738e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul#include "texformat.h"
38e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "teximage.h"
39e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "texstate.h"
40e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
41e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_aatriangle.h"
42cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell#include "s_context.h"
43e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_depth.h"
44cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell#include "s_feedback.h"
45e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_span.h"
46cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell#include "s_triangle.h"
479bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
489bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
4977df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul/*
5077df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul * Just used for feedback mode.
5177df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul */
52230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian PaulGLboolean
53230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul_swrast_culltriangle( GLcontext *ctx,
54230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul                      const SWvertex *v0,
55230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul                      const SWvertex *v1,
56230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul                      const SWvertex *v2 )
57e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{
58cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell   GLfloat ex = v1->win[0] - v0->win[0];
59cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell   GLfloat ey = v1->win[1] - v0->win[1];
60cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell   GLfloat fx = v2->win[0] - v0->win[0];
61cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell   GLfloat fy = v2->win[1] - v0->win[1];
62e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   GLfloat c = ex*fy-ey*fx;
63e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
6487f858dd7cbca2280c983c77a239013a187c3e9aBrian Paul   if (c * SWRAST_CONTEXT(ctx)->_BackfaceSign > 0)
65e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      return 0;
6622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes
67e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   return 1;
68e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell}
69e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
70e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
7195e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul
72e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
73e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render a flat-shaded color index triangle.
74e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
75cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME flat_ci_triangle
76e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
7795e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1
78cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define SETUP_CODE			\
79cdf2da368d180205df3573697b51b8764048ad6eBrian Paul   span.interpMask |= SPAN_INDEX;	\
80cdf2da368d180205df3573697b51b8764048ad6eBrian Paul   span.index = IntToFixed(v2->index);	\
8177df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.indexStep = 0;
8245bc887da226403f2c41077e40ca38b6f60f1359Brian Paul#define RENDER_SPAN( span )  _swrast_write_index_span(ctx, &span);
8322144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes#include "s_tritemp.h"
84e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
85e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
86e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
87e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
88e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render a smooth-shaded color index triangle.
89e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
90cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME smooth_ci_triangle
91e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
9295e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1
93e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_INDEX 1
9445bc887da226403f2c41077e40ca38b6f60f1359Brian Paul#define RENDER_SPAN( span )  _swrast_write_index_span(ctx, &span);
95e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
96e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
97e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
98e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
99e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
100e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render a flat-shaded RGBA triangle.
101e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
102cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME flat_rgba_triangle
103e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
10495e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1
105e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
106f1e236987829393c81dc86ea19cb49eefe190317Brian Paul#define SETUP_CODE				\
10736a0a3252e1e20df69b53f70ba93bc74c4a4bf0eBrian Paul   ASSERT(ctx->Texture._EnabledCoordUnits == 0);\
1087956292a765910077f50352d7cd0174e1e66d26cBrian Paul   ASSERT(ctx->Light.ShadeModel==GL_FLAT);	\
10977df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.interpMask |= SPAN_RGBA;		\
11077df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.red = ChanToFixed(v2->color[0]);	\
11177df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.green = ChanToFixed(v2->color[1]);	\
11277df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.blue = ChanToFixed(v2->color[2]);	\
11377df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.alpha = ChanToFixed(v2->color[3]);	\
11477df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.redStep = 0;				\
11577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.greenStep = 0;				\
11677df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.blueStep = 0;				\
11777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.alphaStep = 0;
11845bc887da226403f2c41077e40ca38b6f60f1359Brian Paul#define RENDER_SPAN( span )  _swrast_write_rgba_span(ctx, &span);
119e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
120e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
121e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
122e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
123e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
124e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render a smooth-shaded RGBA triangle.
125e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
126cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME smooth_rgba_triangle
127e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
12895e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1
129e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
130e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_RGB 1
131e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_ALPHA 1
132733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul#define SETUP_CODE				\
133733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul   {						\
134733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul      /* texturing must be off */		\
13536a0a3252e1e20df69b53f70ba93bc74c4a4bf0eBrian Paul      ASSERT(ctx->Texture._EnabledCoordUnits == 0);	\
136733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul      ASSERT(ctx->Light.ShadeModel==GL_SMOOTH);	\
137733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul   }
13845bc887da226403f2c41077e40ca38b6f60f1359Brian Paul#define RENDER_SPAN( span )  _swrast_write_rgba_span(ctx, &span);
139e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
140e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
141e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
142e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
143e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
144e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render an RGB, GL_DECAL, textured triangle.
145e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Interpolate S,T only w/out mipmapping or perspective correction.
146e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell *
147e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * No fog.
148e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
149cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME simple_textured_triangle
150e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_INT_TEX 1
151e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define S_SCALE twidth
152e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define T_SCALE theight
1539bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
154e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define SETUP_CODE							\
155709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell   SWcontext *swrast = SWRAST_CONTEXT(ctx);                             \
156a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul   struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D;	\
1572ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul   const GLint b = obj->BaseLevel;					\
15818fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;		\
15918fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLfloat theight = (GLfloat) obj->Image[0][b]->Height;		\
160230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   const GLint twidth_log2 = obj->Image[0][b]->WidthLog2;		\
16118fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLchan *texture = (const GLchan *) obj->Image[0][b]->Data;	\
16218fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLint smask = obj->Image[0][b]->Width - 1;			\
16318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLint tmask = obj->Image[0][b]->Height - 1;			\
164e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   if (!texture) {							\
1658e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      /* this shouldn't happen */					\
1668e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      return;								\
167e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
168e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
1699bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define RENDER_SPAN( span  )						\
1709bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLuint i;								\
17177df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.intTex[0] -= FIXED_HALF; /* off-by-one error? */		\
17277df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.intTex[1] -= FIXED_HALF;					\
17377df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   for (i = 0; i < span.end; i++) {					\
17477df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      GLint s = FixedToInt(span.intTex[0]) & smask;			\
17577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      GLint t = FixedToInt(span.intTex[1]) & tmask;			\
1769bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      GLint pos = (t << twidth_log2) + s;				\
1779bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      pos = pos + pos + pos;  /* multiply by 3 */			\
17877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.array->rgb[i][RCOMP] = texture[pos];				\
17977df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.array->rgb[i][GCOMP] = texture[pos+1];			\
18077df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.array->rgb[i][BCOMP] = texture[pos+2];			\
18177df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.intTex[0] += span.intTexStep[0];				\
18277df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.intTex[1] += span.intTexStep[1];				\
1839bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   }									\
18477df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   (*swrast->Driver.WriteRGBSpan)(ctx, span.end, span.x, span.y,	\
18577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul                                  (CONST GLchan (*)[3]) span.array->rgb,\
1862ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul                                  NULL );
187e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
188cdf2da368d180205df3573697b51b8764048ad6eBrian Paul
189e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
190e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
191e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
192e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render an RGB, GL_DECAL, textured triangle.
193e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Interpolate S,T, GL_LESS depth test, w/out mipmapping or
194e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * perspective correction.
19522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
196e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * No fog.
197e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
198cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME simple_z_textured_triangle
199e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
200e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
201e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_INT_TEX 1
202e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define S_SCALE twidth
203e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define T_SCALE theight
2049bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
205e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define SETUP_CODE							\
206709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell   SWcontext *swrast = SWRAST_CONTEXT(ctx);                             \
207a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul   struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D;	\
2082ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul   const GLint b = obj->BaseLevel;					\
20918fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;		\
21018fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLfloat theight = (GLfloat) obj->Image[0][b]->Height;		\
211230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   const GLint twidth_log2 = obj->Image[0][b]->WidthLog2;		\
21218fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLchan *texture = (const GLchan *) obj->Image[0][b]->Data;	\
21318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLint smask = obj->Image[0][b]->Width - 1;			\
21418fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLint tmask = obj->Image[0][b]->Height - 1;			\
215e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   if (!texture) {							\
2168e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      /* this shouldn't happen */					\
2178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      return;								\
218e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
219e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
2209bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define RENDER_SPAN( span )						\
2219bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLuint i;				    				\
22277df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.intTex[0] -= FIXED_HALF; /* off-by-one error? */		\
22377df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.intTex[1] -= FIXED_HALF;					\
22477df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   for (i = 0; i < span.end; i++) {					\
22577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      const GLdepth z = FixedToDepth(span.z);				\
2269bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      if (z < zRow[i]) {						\
22777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         GLint s = FixedToInt(span.intTex[0]) & smask;			\
22877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         GLint t = FixedToInt(span.intTex[1]) & tmask;			\
2299bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         GLint pos = (t << twidth_log2) + s;				\
2309bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         pos = pos + pos + pos;  /* multiply by 3 */			\
23177df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         span.array->rgb[i][RCOMP] = texture[pos];			\
23277df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         span.array->rgb[i][GCOMP] = texture[pos+1];			\
23377df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         span.array->rgb[i][BCOMP] = texture[pos+2];			\
2349bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         zRow[i] = z;							\
23577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         span.array->mask[i] = 1;					\
2369bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      }									\
2379bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      else {								\
23877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         span.array->mask[i] = 0;					\
2399bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      }									\
24077df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.intTex[0] += span.intTexStep[0];				\
24177df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.intTex[1] += span.intTexStep[1];				\
24277df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.z += span.zStep;						\
2439bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   }									\
24477df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   (*swrast->Driver.WriteRGBSpan)(ctx, span.end, span.x, span.y,	\
24577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul                                  (CONST GLchan (*)[3]) span.array->rgb,\
24677df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul                                  span.array->mask );
247e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
248cdf2da368d180205df3573697b51b8764048ad6eBrian Paul
249e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
250e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
251f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#if CHAN_TYPE != GL_FLOAT
252e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
2539bf68ad963ba92b5d1e725f965979042495a5313Brian Paulstruct affine_info
254e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{
2559bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLenum filter;
2569bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLenum format;
2579bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLenum envmode;
2589bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLint smask, tmask;
2599bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLint twidth_log2;
2609bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   const GLchan *texture;
261fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul   GLfixed er, eg, eb, ea;
2629bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLint tbytesline, tsize;
2639bf68ad963ba92b5d1e725f965979042495a5313Brian Paul};
264cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell
2657152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul
2667152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul/* This function can handle GL_NEAREST or GL_LINEAR sampling of 2D RGB or RGBA
2677152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul * textures with GL_REPLACE, GL_MODULATE, GL_BLEND, GL_DECAL or GL_ADD
2687152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul * texture env modes.
2697152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul */
27071340e861edf35bfdeb536718cd230fc33c41ee2Brian Paulstatic INLINE void
27157d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paulaffine_span(GLcontext *ctx, struct sw_span *span,
2729bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            struct affine_info *info)
2739bf68ad963ba92b5d1e725f965979042495a5313Brian Paul{
2747152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   GLchan sample[4];  /* the filtered texture sample */
275e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
276fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul   /* Instead of defining a function for each mode, a test is done
277fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul    * between the outer and inner loops. This is to reduce code size
278fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul    * and complexity. Observe that an optimizing compiler kills
279fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul    * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST).
280fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul    */
281e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
282bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul#define NEAREST_RGB			\
2837152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[RCOMP] = tex00[RCOMP];	\
2847152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[GCOMP] = tex00[GCOMP];	\
2857152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[BCOMP] = tex00[BCOMP];	\
2867152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[ACOMP] = CHAN_MAX
287e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
2889bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define LINEAR_RGB							\
2897152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[RCOMP] = (ti * (si * tex00[0] + sf * tex01[0]) +		\
290bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul             tf * (si * tex10[0] + sf * tex11[0])) >> 2 * FIXED_SHIFT;	\
2917152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[GCOMP] = (ti * (si * tex00[1] + sf * tex01[1]) +		\
292bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul             tf * (si * tex10[1] + sf * tex11[1])) >> 2 * FIXED_SHIFT;	\
2937152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[BCOMP] = (ti * (si * tex00[2] + sf * tex01[2]) +		\
294bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul             tf * (si * tex10[2] + sf * tex11[2])) >> 2 * FIXED_SHIFT;	\
2957152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[ACOMP] = CHAN_MAX
296bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul
2977152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul#define NEAREST_RGBA  COPY_CHAN4(sample, tex00)
298e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
2999bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define LINEAR_RGBA							\
3007152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[RCOMP] = (ti * (si * tex00[0] + sf * tex01[0]) +		\
301bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               tf * (si * tex10[0] + sf * tex11[0])) >> 2 * FIXED_SHIFT;\
3027152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[GCOMP] = (ti * (si * tex00[1] + sf * tex01[1]) +		\
303bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               tf * (si * tex10[1] + sf * tex11[1])) >> 2 * FIXED_SHIFT;\
3047152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[BCOMP] = (ti * (si * tex00[2] + sf * tex01[2]) +		\
305bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               tf * (si * tex10[2] + sf * tex11[2])) >> 2 * FIXED_SHIFT;\
3067152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[ACOMP] = (ti * (si * tex00[3] + sf * tex01[3]) +		\
307bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               tf * (si * tex10[3] + sf * tex11[3])) >> 2 * FIXED_SHIFT
308bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul
309fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul#define MODULATE							  \
3107152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[RCOMP] = span->red   * (sample[RCOMP] + 1u) >> (FIXED_SHIFT + 8); \
3117152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[GCOMP] = span->green * (sample[GCOMP] + 1u) >> (FIXED_SHIFT + 8); \
3127152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[BCOMP] = span->blue  * (sample[BCOMP] + 1u) >> (FIXED_SHIFT + 8); \
3137152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[ACOMP] = span->alpha * (sample[ACOMP] + 1u) >> (FIXED_SHIFT + 8)
3149bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
3159bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define DECAL								\
3167152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[RCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->red +		\
3177152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul               ((sample[ACOMP] + 1) * sample[RCOMP] << FIXED_SHIFT))	\
318bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               >> (FIXED_SHIFT + 8);					\
3197152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[GCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->green +		\
3207152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul               ((sample[ACOMP] + 1) * sample[GCOMP] << FIXED_SHIFT))	\
321bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               >> (FIXED_SHIFT + 8);					\
3227152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[BCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->blue +		\
3237152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul               ((sample[ACOMP] + 1) * sample[BCOMP] << FIXED_SHIFT))	\
324bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               >> (FIXED_SHIFT + 8);					\
325bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul   dest[ACOMP] = FixedToInt(span->alpha)
3269bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
3279bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define BLEND								\
3287152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[RCOMP] = ((CHAN_MAX - sample[RCOMP]) * span->red		\
3297152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul               + (sample[RCOMP] + 1) * info->er) >> (FIXED_SHIFT + 8);	\
3307152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[GCOMP] = ((CHAN_MAX - sample[GCOMP]) * span->green		\
3317152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul               + (sample[GCOMP] + 1) * info->eg) >> (FIXED_SHIFT + 8);	\
3327152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[BCOMP] = ((CHAN_MAX - sample[BCOMP]) * span->blue		\
3337152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul               + (sample[BCOMP] + 1) * info->eb) >> (FIXED_SHIFT + 8);	\
3347152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[ACOMP] = span->alpha * (sample[ACOMP] + 1) >> (FIXED_SHIFT + 8)
335bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul
3367152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul#define REPLACE  COPY_CHAN4(dest, sample)
337e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
3389bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define ADD								\
3397152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   {									\
3407152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      GLint rSum = FixedToInt(span->red)   + (GLint) sample[RCOMP];	\
3417152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      GLint gSum = FixedToInt(span->green) + (GLint) sample[GCOMP];	\
3427152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      GLint bSum = FixedToInt(span->blue)  + (GLint) sample[BCOMP];	\
3437152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      dest[RCOMP] = MIN2(rSum, CHAN_MAX);				\
3447152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      dest[GCOMP] = MIN2(gSum, CHAN_MAX);				\
3457152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      dest[BCOMP] = MIN2(bSum, CHAN_MAX);				\
3467152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      dest[ACOMP] = span->alpha * (sample[ACOMP] + 1) >> (FIXED_SHIFT + 8); \
3477152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul  }
348e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
349e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* shortcuts */
350e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
35135e5e89f5614ebb032479b02dec888563f829b30Brian Paul#define NEAREST_RGB_REPLACE		\
35235e5e89f5614ebb032479b02dec888563f829b30Brian Paul   NEAREST_RGB;				\
35335e5e89f5614ebb032479b02dec888563f829b30Brian Paul   dest[0] = sample[0];			\
35435e5e89f5614ebb032479b02dec888563f829b30Brian Paul   dest[1] = sample[1];			\
35535e5e89f5614ebb032479b02dec888563f829b30Brian Paul   dest[2] = sample[2];			\
35635e5e89f5614ebb032479b02dec888563f829b30Brian Paul   dest[3] = FixedToInt(span->alpha);
357e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
358bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul#define NEAREST_RGBA_REPLACE  COPY_CHAN4(dest, tex00)
359e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
36033170eeb185f5fe766374a749464497cdfab6931Brian Paul#define SPAN_NEAREST(DO_TEX,COMP)					\
36157d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul	for (i = 0; i < span->end; i++) {				\
36233170eeb185f5fe766374a749464497cdfab6931Brian Paul           /* Isn't it necessary to use FixedFloor below?? */		\
3639bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           GLint s = FixedToInt(span->intTex[0]) & info->smask;		\
3649bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           GLint t = FixedToInt(span->intTex[1]) & info->tmask;		\
3659bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           GLint pos = (t << info->twidth_log2) + s;			\
3669bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           const GLchan *tex00 = info->texture + COMP * pos;		\
3679bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           DO_TEX;							\
3689bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           span->red += span->redStep;					\
3699bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->green += span->greenStep;				\
3709bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           span->blue += span->blueStep;				\
3719bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->alpha += span->alphaStep;				\
3729bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->intTex[0] += span->intTexStep[0];			\
3739bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->intTex[1] += span->intTexStep[1];			\
3749bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           dest += 4;							\
375e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	}
376e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
37733170eeb185f5fe766374a749464497cdfab6931Brian Paul#define SPAN_LINEAR(DO_TEX,COMP)					\
37857d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul	for (i = 0; i < span->end; i++) {				\
37933170eeb185f5fe766374a749464497cdfab6931Brian Paul           /* Isn't it necessary to use FixedFloor below?? */		\
3809bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           GLint s = FixedToInt(span->intTex[0]) & info->smask;		\
3819bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           GLint t = FixedToInt(span->intTex[1]) & info->tmask;		\
38233170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLfixed sf = span->intTex[0] & FIXED_FRAC_MASK;		\
38333170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLfixed tf = span->intTex[1] & FIXED_FRAC_MASK;		\
38433170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLfixed si = FIXED_FRAC_MASK - sf;				\
38533170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLfixed ti = FIXED_FRAC_MASK - tf;				\
3869bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           GLint pos = (t << info->twidth_log2) + s;			\
3879bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           const GLchan *tex00 = info->texture + COMP * pos;		\
3889bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           const GLchan *tex10 = tex00 + info->tbytesline;		\
3899bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           const GLchan *tex01 = tex00 + COMP;				\
3909bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           const GLchan *tex11 = tex10 + COMP;				\
3919bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           (void) ti;							\
3929bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           (void) si;							\
3939bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           if (t == info->tmask) {					\
3949bf68ad963ba92b5d1e725f965979042495a5313Brian Paul              tex10 -= info->tsize;					\
3959bf68ad963ba92b5d1e725f965979042495a5313Brian Paul              tex11 -= info->tsize;					\
3969bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           }								\
3979bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           if (s == info->smask) {					\
3989bf68ad963ba92b5d1e725f965979042495a5313Brian Paul              tex01 -= info->tbytesline;				\
3999bf68ad963ba92b5d1e725f965979042495a5313Brian Paul              tex11 -= info->tbytesline;				\
4009bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           }								\
4019bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           DO_TEX;							\
4029bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           span->red += span->redStep;					\
4039bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->green += span->greenStep;				\
4049bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           span->blue += span->blueStep;				\
4059bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->alpha += span->alphaStep;				\
4069bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->intTex[0] += span->intTexStep[0];			\
4079bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->intTex[1] += span->intTexStep[1];			\
4089bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           dest += 4;							\
409e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	}
410e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
4119bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
4129bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLuint i;
41377df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   GLchan *dest = span->array->rgba[0];
41457d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul
4159bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   span->intTex[0] -= FIXED_HALF;
4169bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   span->intTex[1] -= FIXED_HALF;
4179bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   switch (info->filter) {
4189bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_NEAREST:
4199bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      switch (info->format) {
4209bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      case GL_RGB:
4219bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         switch (info->envmode) {
4229bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_MODULATE:
42333170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB;MODULATE,3);
4249bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4259bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_DECAL:
4269bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_REPLACE:
42733170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB_REPLACE,3);
4289bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4299bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_BLEND:
43033170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB;BLEND,3);
4319bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4329bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_ADD:
43333170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB;ADD,3);
4349bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4359bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         default:
4364663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode in SPAN_LINEAR");
4374663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
4389bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         }
4399bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         break;
4409bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      case GL_RGBA:
4419bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         switch(info->envmode) {
4429bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_MODULATE:
44333170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;MODULATE,4);
4449bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4459bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_DECAL:
44633170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;DECAL,4);
4479bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4489bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_BLEND:
44933170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;BLEND,4);
4509bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4519bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_ADD:
45233170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;ADD,4);
4539bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4549bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_REPLACE:
45533170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA_REPLACE,4);
4569bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4579bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         default:
4584663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (2) in SPAN_LINEAR");
4594663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
4609bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         }
4619bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         break;
4629bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      }
4639bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      break;
4649bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
4659bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_LINEAR:
4669bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      span->intTex[0] -= FIXED_HALF;
4679bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      span->intTex[1] -= FIXED_HALF;
4689bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      switch (info->format) {
4699bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      case GL_RGB:
4709bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         switch (info->envmode) {
4719bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_MODULATE:
47233170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;MODULATE,3);
4739bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4749bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_DECAL:
4759bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_REPLACE:
47633170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;REPLACE,3);
4779bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4789bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_BLEND:
47933170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;BLEND,3);
4809bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4819bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_ADD:
48233170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;ADD,3);
4839bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4849bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         default:
4854663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (3) in SPAN_LINEAR");
4864663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
4879bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         }
4889bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         break;
4899bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      case GL_RGBA:
4909bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         switch (info->envmode) {
4919bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_MODULATE:
49233170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;MODULATE,4);
4939bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4949bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_DECAL:
49533170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;DECAL,4);
4969bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4979bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_BLEND:
49833170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;BLEND,4);
4999bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
5009bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_ADD:
50133170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;ADD,4);
5029bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
5039bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_REPLACE:
50433170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;REPLACE,4);
5059bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
5069bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         default:
5074663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (4) in SPAN_LINEAR");
5084663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
5094663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul         }
5104663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul         break;
5119bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      }
5129bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      break;
5139bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   }
514733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul   span->interpMask &= ~SPAN_RGBA;
5152a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul   ASSERT(span->arrayMask & SPAN_RGBA);
51645bc887da226403f2c41077e40ca38b6f60f1359Brian Paul   _swrast_write_rgba_span(ctx, span);
517e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
51833170eeb185f5fe766374a749464497cdfab6931Brian Paul#undef SPAN_NEAREST
51933170eeb185f5fe766374a749464497cdfab6931Brian Paul#undef SPAN_LINEAR
520e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell}
521e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
522e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
523e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
524e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
5259bf68ad963ba92b5d1e725f965979042495a5313Brian Paul * Render an RGB/RGBA textured triangle without perspective correction.
5269bf68ad963ba92b5d1e725f965979042495a5313Brian Paul */
527cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME affine_textured_triangle
5289bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_Z 1
5299bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_FOG 1
5309bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
5319bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_RGB 1
5329bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_ALPHA 1
5339bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_INT_TEX 1
5349bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define S_SCALE twidth
5359bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define T_SCALE theight
5369bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
537571c8ecc8f9442fb8bbaa1f29b1d0d4f8e5b3cadBrian Paul#define SETUP_CODE							\
538571c8ecc8f9442fb8bbaa1f29b1d0d4f8e5b3cadBrian Paul   struct affine_info info;						\
5399bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   struct gl_texture_unit *unit = ctx->Texture.Unit+0;			\
5409bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   struct gl_texture_object *obj = unit->Current2D;			\
5412ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul   const GLint b = obj->BaseLevel;					\
54218fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;		\
54318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLfloat theight = (GLfloat) obj->Image[0][b]->Height;		\
544230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   info.texture = (const GLchan *) obj->Image[0][b]->Data;		\
545230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   info.twidth_log2 = obj->Image[0][b]->WidthLog2;			\
54618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   info.smask = obj->Image[0][b]->Width - 1;				\
54718fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   info.tmask = obj->Image[0][b]->Height - 1;				\
548230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   info.format = obj->Image[0][b]->Format;				\
5499bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   info.filter = obj->MinFilter;					\
5509bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   info.envmode = unit->EnvMode;					\
55177df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.arrayMask |= SPAN_RGBA;						\
5529bf68ad963ba92b5d1e725f965979042495a5313Brian Paul									\
5539bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   if (info.envmode == GL_BLEND) {					\
5549bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      /* potential off-by-one error here? (1.0f -> 2048 -> 0) */	\
555fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.er = FloatToFixed(unit->EnvColor[RCOMP] * CHAN_MAXF);	\
556fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.eg = FloatToFixed(unit->EnvColor[GCOMP] * CHAN_MAXF);	\
557fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.eb = FloatToFixed(unit->EnvColor[BCOMP] * CHAN_MAXF);	\
558fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.ea = FloatToFixed(unit->EnvColor[ACOMP] * CHAN_MAXF);	\
5599bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   }									\
5609bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   if (!info.texture) {							\
5619bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      /* this shouldn't happen */					\
5629bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      return;								\
5639bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   }									\
5649bf68ad963ba92b5d1e725f965979042495a5313Brian Paul									\
5659bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   switch (info.format) {						\
5669bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_ALPHA:							\
5679bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_LUMINANCE:							\
5689bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_INTENSITY:							\
569230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul      info.tbytesline = obj->Image[0][b]->Width;			\
5709bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      break;								\
5719bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_LUMINANCE_ALPHA:						\
57218fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell      info.tbytesline = obj->Image[0][b]->Width * 2;			\
5739bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      break;								\
5749bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_RGB:								\
57518fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell      info.tbytesline = obj->Image[0][b]->Width * 3;			\
5769bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      break;								\
5779bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_RGBA:							\
57818fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell      info.tbytesline = obj->Image[0][b]->Width * 4;			\
5799bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      break;								\
5809bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   default:								\
5819bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      _mesa_problem(NULL, "Bad texture format in affine_texture_triangle");\
5829bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      return;								\
5839bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   }									\
58418fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   info.tsize = obj->Image[0][b]->Height * info.tbytesline;
5859bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
58677df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul#define RENDER_SPAN( span )   affine_span(ctx, &span, &info);
5879bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
5889bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#include "s_tritemp.h"
5899bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
590f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul
5919bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
59233170eeb185f5fe766374a749464497cdfab6931Brian Paulstruct persp_info
593e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{
59433170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLenum filter;
59533170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLenum format;
59633170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLenum envmode;
59733170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLint smask, tmask;
59833170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLint twidth_log2;
59933170eeb185f5fe766374a749464497cdfab6931Brian Paul   const GLchan *texture;
600fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul   GLfixed er, eg, eb, ea;   /* texture env color */
60133170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLint tbytesline, tsize;
60233170eeb185f5fe766374a749464497cdfab6931Brian Paul};
603e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
604f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul
60571340e861edf35bfdeb536718cd230fc33c41ee2Brian Paulstatic INLINE void
60657d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paulfast_persp_span(GLcontext *ctx, struct sw_span *span,
60733170eeb185f5fe766374a749464497cdfab6931Brian Paul		struct persp_info *info)
60833170eeb185f5fe766374a749464497cdfab6931Brian Paul{
6097152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   GLchan sample[4];  /* the filtered texture sample */
6109bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
61133170eeb185f5fe766374a749464497cdfab6931Brian Paul  /* Instead of defining a function for each mode, a test is done
61233170eeb185f5fe766374a749464497cdfab6931Brian Paul   * between the outer and inner loops. This is to reduce code size
61333170eeb185f5fe766374a749464497cdfab6931Brian Paul   * and complexity. Observe that an optimizing compiler kills
61433170eeb185f5fe766374a749464497cdfab6931Brian Paul   * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST).
61533170eeb185f5fe766374a749464497cdfab6931Brian Paul   */
61633170eeb185f5fe766374a749464497cdfab6931Brian Paul#define SPAN_NEAREST(DO_TEX,COMP)					\
61757d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul	for (i = 0; i < span->end; i++) {				\
61833170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLdouble invQ = tex_coord[2] ?				\
61933170eeb185f5fe766374a749464497cdfab6931Brian Paul                                 (1.0 / tex_coord[2]) : 1.0;            \
6207c4268176eaaeb45003db4d5042a518b84c9f6dcKarl Schultz           GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ);		\
6217c4268176eaaeb45003db4d5042a518b84c9f6dcKarl Schultz           GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ);		\
62233170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLint s = IFLOOR(s_tmp) & info->smask;	        	\
62333170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLint t = IFLOOR(t_tmp) & info->tmask;	        	\
62433170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLint pos = (t << info->twidth_log2) + s;			\
62533170eeb185f5fe766374a749464497cdfab6931Brian Paul           const GLchan *tex00 = info->texture + COMP * pos;		\
62633170eeb185f5fe766374a749464497cdfab6931Brian Paul           DO_TEX;							\
62733170eeb185f5fe766374a749464497cdfab6931Brian Paul           span->red += span->redStep;					\
62833170eeb185f5fe766374a749464497cdfab6931Brian Paul	   span->green += span->greenStep;				\
62933170eeb185f5fe766374a749464497cdfab6931Brian Paul           span->blue += span->blueStep;				\
63033170eeb185f5fe766374a749464497cdfab6931Brian Paul	   span->alpha += span->alphaStep;				\
63133170eeb185f5fe766374a749464497cdfab6931Brian Paul	   tex_coord[0] += tex_step[0];					\
63233170eeb185f5fe766374a749464497cdfab6931Brian Paul	   tex_coord[1] += tex_step[1];					\
63333170eeb185f5fe766374a749464497cdfab6931Brian Paul	   tex_coord[2] += tex_step[2];					\
63433170eeb185f5fe766374a749464497cdfab6931Brian Paul           dest += 4;							\
63533170eeb185f5fe766374a749464497cdfab6931Brian Paul	}
636e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
63733170eeb185f5fe766374a749464497cdfab6931Brian Paul#define SPAN_LINEAR(DO_TEX,COMP)					\
63857d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul	for (i = 0; i < span->end; i++) {				\
63933170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLdouble invQ = tex_coord[2] ?				\
64033170eeb185f5fe766374a749464497cdfab6931Brian Paul                                 (1.0 / tex_coord[2]) : 1.0;            \
6417c4268176eaaeb45003db4d5042a518b84c9f6dcKarl Schultz           GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ);		\
6427c4268176eaaeb45003db4d5042a518b84c9f6dcKarl Schultz           GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ);		\
643bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul           GLfixed s_fix = FloatToFixed(s_tmp) - FIXED_HALF;		\
644bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul           GLfixed t_fix = FloatToFixed(t_tmp) - FIXED_HALF;        	\
64533170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLint s = FixedToInt(FixedFloor(s_fix)) & info->smask;	\
64633170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLint t = FixedToInt(FixedFloor(t_fix)) & info->tmask;	\
647fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul           GLfixed sf = s_fix & FIXED_FRAC_MASK;			\
648fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul           GLfixed tf = t_fix & FIXED_FRAC_MASK;			\
64933170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLfixed si = FIXED_FRAC_MASK - sf;				\
65033170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLfixed ti = FIXED_FRAC_MASK - tf;				\
65133170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLint pos = (t << info->twidth_log2) + s;			\
65233170eeb185f5fe766374a749464497cdfab6931Brian Paul           const GLchan *tex00 = info->texture + COMP * pos;		\
65333170eeb185f5fe766374a749464497cdfab6931Brian Paul           const GLchan *tex10 = tex00 + info->tbytesline;		\
65433170eeb185f5fe766374a749464497cdfab6931Brian Paul           const GLchan *tex01 = tex00 + COMP;				\
65533170eeb185f5fe766374a749464497cdfab6931Brian Paul           const GLchan *tex11 = tex10 + COMP;				\
65633170eeb185f5fe766374a749464497cdfab6931Brian Paul           (void) ti;							\
65733170eeb185f5fe766374a749464497cdfab6931Brian Paul           (void) si;							\
65833170eeb185f5fe766374a749464497cdfab6931Brian Paul           if (t == info->tmask) {					\
65933170eeb185f5fe766374a749464497cdfab6931Brian Paul              tex10 -= info->tsize;					\
66033170eeb185f5fe766374a749464497cdfab6931Brian Paul              tex11 -= info->tsize;					\
66133170eeb185f5fe766374a749464497cdfab6931Brian Paul           }								\
66233170eeb185f5fe766374a749464497cdfab6931Brian Paul           if (s == info->smask) {					\
66333170eeb185f5fe766374a749464497cdfab6931Brian Paul              tex01 -= info->tbytesline;				\
66433170eeb185f5fe766374a749464497cdfab6931Brian Paul              tex11 -= info->tbytesline;				\
66533170eeb185f5fe766374a749464497cdfab6931Brian Paul           }								\
66633170eeb185f5fe766374a749464497cdfab6931Brian Paul           DO_TEX;							\
66733170eeb185f5fe766374a749464497cdfab6931Brian Paul           span->red   += span->redStep;				\
66833170eeb185f5fe766374a749464497cdfab6931Brian Paul	   span->green += span->greenStep;				\
66933170eeb185f5fe766374a749464497cdfab6931Brian Paul           span->blue  += span->blueStep;				\
67033170eeb185f5fe766374a749464497cdfab6931Brian Paul	   span->alpha += span->alphaStep;				\
67133170eeb185f5fe766374a749464497cdfab6931Brian Paul	   tex_coord[0] += tex_step[0];					\
67233170eeb185f5fe766374a749464497cdfab6931Brian Paul	   tex_coord[1] += tex_step[1];					\
67333170eeb185f5fe766374a749464497cdfab6931Brian Paul	   tex_coord[2] += tex_step[2];					\
67433170eeb185f5fe766374a749464497cdfab6931Brian Paul           dest += 4;							\
67533170eeb185f5fe766374a749464497cdfab6931Brian Paul	}
676e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
67733170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLuint i;
67833170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLfloat tex_coord[3], tex_step[3];
67977df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   GLchan *dest = span->array->rgba[0];
68057d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul
68131f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul   tex_coord[0] = span->tex[0][0]  * (info->smask + 1);
68231f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul   tex_step[0] = span->texStepX[0][0] * (info->smask + 1);
68331f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul   tex_coord[1] = span->tex[0][1] * (info->tmask + 1);
68431f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul   tex_step[1] = span->texStepX[0][1] * (info->tmask + 1);
68533170eeb185f5fe766374a749464497cdfab6931Brian Paul   /* span->tex[0][2] only if 3D-texturing, here only 2D */
68631f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul   tex_coord[2] = span->tex[0][3];
68731f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul   tex_step[2] = span->texStepX[0][3];
688e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
68933170eeb185f5fe766374a749464497cdfab6931Brian Paul   switch (info->filter) {
69033170eeb185f5fe766374a749464497cdfab6931Brian Paul   case GL_NEAREST:
69133170eeb185f5fe766374a749464497cdfab6931Brian Paul      switch (info->format) {
69233170eeb185f5fe766374a749464497cdfab6931Brian Paul      case GL_RGB:
69333170eeb185f5fe766374a749464497cdfab6931Brian Paul         switch (info->envmode) {
69433170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_MODULATE:
69533170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB;MODULATE,3);
69633170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
69733170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_DECAL:
69833170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_REPLACE:
69933170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB_REPLACE,3);
70033170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
70133170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_BLEND:
70233170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB;BLEND,3);
70333170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
70433170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_ADD:
70533170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB;ADD,3);
70633170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
70733170eeb185f5fe766374a749464497cdfab6931Brian Paul         default:
7084663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (5) in SPAN_LINEAR");
7094663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
71033170eeb185f5fe766374a749464497cdfab6931Brian Paul         }
71133170eeb185f5fe766374a749464497cdfab6931Brian Paul         break;
71233170eeb185f5fe766374a749464497cdfab6931Brian Paul      case GL_RGBA:
71333170eeb185f5fe766374a749464497cdfab6931Brian Paul         switch(info->envmode) {
71433170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_MODULATE:
71533170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;MODULATE,4);
71633170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
71733170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_DECAL:
71833170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;DECAL,4);
71933170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
72033170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_BLEND:
72133170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;BLEND,4);
72233170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
72333170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_ADD:
72433170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;ADD,4);
72533170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
72633170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_REPLACE:
72733170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA_REPLACE,4);
72833170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
72933170eeb185f5fe766374a749464497cdfab6931Brian Paul         default:
7304663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (6) in SPAN_LINEAR");
7314663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
73233170eeb185f5fe766374a749464497cdfab6931Brian Paul         }
73333170eeb185f5fe766374a749464497cdfab6931Brian Paul         break;
73433170eeb185f5fe766374a749464497cdfab6931Brian Paul      }
73533170eeb185f5fe766374a749464497cdfab6931Brian Paul      break;
73633170eeb185f5fe766374a749464497cdfab6931Brian Paul
73733170eeb185f5fe766374a749464497cdfab6931Brian Paul   case GL_LINEAR:
73833170eeb185f5fe766374a749464497cdfab6931Brian Paul      switch (info->format) {
73933170eeb185f5fe766374a749464497cdfab6931Brian Paul      case GL_RGB:
74033170eeb185f5fe766374a749464497cdfab6931Brian Paul         switch (info->envmode) {
74133170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_MODULATE:
74233170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;MODULATE,3);
74333170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
74433170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_DECAL:
74533170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_REPLACE:
74633170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;REPLACE,3);
74733170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
74833170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_BLEND:
74933170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;BLEND,3);
75033170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
75133170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_ADD:
75233170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;ADD,3);
75333170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
75433170eeb185f5fe766374a749464497cdfab6931Brian Paul         default:
7554663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (7) in SPAN_LINEAR");
7564663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
75733170eeb185f5fe766374a749464497cdfab6931Brian Paul         }
75833170eeb185f5fe766374a749464497cdfab6931Brian Paul         break;
75933170eeb185f5fe766374a749464497cdfab6931Brian Paul      case GL_RGBA:
76033170eeb185f5fe766374a749464497cdfab6931Brian Paul         switch (info->envmode) {
76133170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_MODULATE:
76233170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;MODULATE,4);
76333170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
76433170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_DECAL:
76533170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;DECAL,4);
76633170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
76733170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_BLEND:
76833170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;BLEND,4);
76933170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
77033170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_ADD:
77133170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;ADD,4);
77233170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
77333170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_REPLACE:
77433170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;REPLACE,4);
77533170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
77633170eeb185f5fe766374a749464497cdfab6931Brian Paul         default:
7774663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (8) in SPAN_LINEAR");
7784663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
77933170eeb185f5fe766374a749464497cdfab6931Brian Paul         }
78033170eeb185f5fe766374a749464497cdfab6931Brian Paul         break;
78133170eeb185f5fe766374a749464497cdfab6931Brian Paul      }
78233170eeb185f5fe766374a749464497cdfab6931Brian Paul      break;
783e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
78433170eeb185f5fe766374a749464497cdfab6931Brian Paul
7852a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul   ASSERT(span->arrayMask & SPAN_RGBA);
78645bc887da226403f2c41077e40ca38b6f60f1359Brian Paul   _swrast_write_rgba_span(ctx, span);
787e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
78833170eeb185f5fe766374a749464497cdfab6931Brian Paul#undef SPAN_NEAREST
78933170eeb185f5fe766374a749464497cdfab6931Brian Paul#undef SPAN_LINEAR
790e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell}
791e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
792e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
793e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
794e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render an perspective corrected RGB/RGBA textured triangle.
795e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * The Q (aka V in Mesa) coordinate must be zero such that the divide
796e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * by interpolated Q/W comes out right.
797e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell *
798e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
799cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME persp_textured_triangle
800e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
80109da0b8e6621a831e3eeb9381430f2bed18a22adBrian Paul#define INTERP_W 1
80295e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1
803e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
804e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_RGB 1
805e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_ALPHA 1
806e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_TEX 1
8079bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
808571c8ecc8f9442fb8bbaa1f29b1d0d4f8e5b3cadBrian Paul#define SETUP_CODE							\
809571c8ecc8f9442fb8bbaa1f29b1d0d4f8e5b3cadBrian Paul   struct persp_info info;						\
8102ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul   const struct gl_texture_unit *unit = ctx->Texture.Unit+0;		\
8112ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul   const struct gl_texture_object *obj = unit->Current2D;		\
8122ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul   const GLint b = obj->BaseLevel;					\
813230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   info.texture = (const GLchan *) obj->Image[0][b]->Data;		\
814230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   info.twidth_log2 = obj->Image[0][b]->WidthLog2;			\
81518fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   info.smask = obj->Image[0][b]->Width - 1;				\
81618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   info.tmask = obj->Image[0][b]->Height - 1;				\
817230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   info.format = obj->Image[0][b]->Format;				\
81833170eeb185f5fe766374a749464497cdfab6931Brian Paul   info.filter = obj->MinFilter;					\
81933170eeb185f5fe766374a749464497cdfab6931Brian Paul   info.envmode = unit->EnvMode;					\
82033170eeb185f5fe766374a749464497cdfab6931Brian Paul									\
82133170eeb185f5fe766374a749464497cdfab6931Brian Paul   if (info.envmode == GL_BLEND) {					\
82233170eeb185f5fe766374a749464497cdfab6931Brian Paul      /* potential off-by-one error here? (1.0f -> 2048 -> 0) */	\
823fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.er = FloatToFixed(unit->EnvColor[RCOMP] * CHAN_MAXF);	\
824fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.eg = FloatToFixed(unit->EnvColor[GCOMP] * CHAN_MAXF);	\
825fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.eb = FloatToFixed(unit->EnvColor[BCOMP] * CHAN_MAXF);	\
826fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.ea = FloatToFixed(unit->EnvColor[ACOMP] * CHAN_MAXF);	\
82733170eeb185f5fe766374a749464497cdfab6931Brian Paul   }									\
82833170eeb185f5fe766374a749464497cdfab6931Brian Paul   if (!info.texture) {							\
82933170eeb185f5fe766374a749464497cdfab6931Brian Paul      /* this shouldn't happen */					\
8308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      return;								\
831e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }									\
83233170eeb185f5fe766374a749464497cdfab6931Brian Paul									\
83333170eeb185f5fe766374a749464497cdfab6931Brian Paul   switch (info.format) {						\
834e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   case GL_ALPHA:							\
835e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   case GL_LUMINANCE:							\
836e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   case GL_INTENSITY:							\
837230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul      info.tbytesline = obj->Image[0][b]->Width;			\
83833170eeb185f5fe766374a749464497cdfab6931Brian Paul      break;								\
839e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   case GL_LUMINANCE_ALPHA:						\
84018fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell      info.tbytesline = obj->Image[0][b]->Width * 2;			\
84133170eeb185f5fe766374a749464497cdfab6931Brian Paul      break;								\
842e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   case GL_RGB:								\
84318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell      info.tbytesline = obj->Image[0][b]->Width * 3;			\
84433170eeb185f5fe766374a749464497cdfab6931Brian Paul      break;								\
845e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   case GL_RGBA:							\
84618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell      info.tbytesline = obj->Image[0][b]->Width * 4;			\
84733170eeb185f5fe766374a749464497cdfab6931Brian Paul      break;								\
848e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   default:								\
849fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul      _mesa_problem(NULL, "Bad texture format in persp_textured_triangle");\
85033170eeb185f5fe766374a749464497cdfab6931Brian Paul      return;								\
85133170eeb185f5fe766374a749464497cdfab6931Brian Paul   }									\
85218fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   info.tsize = obj->Image[0][b]->Height * info.tbytesline;
853e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
8547956292a765910077f50352d7cd0174e1e66d26cBrian Paul#define RENDER_SPAN( span )			\
85577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.interpMask &= ~SPAN_RGBA;		\
85677df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.arrayMask |= SPAN_RGBA;			\
85777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   fast_persp_span(ctx, &span, &info);
858e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
859e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
860e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
861fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul
86296385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul#endif /* CHAN_BITS != GL_FLOAT */
86396385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul
8649bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
8659bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
8669bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
8679bf68ad963ba92b5d1e725f965979042495a5313Brian Paul/*
868e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render a smooth-shaded, textured, RGBA triangle.
8699bf68ad963ba92b5d1e725f965979042495a5313Brian Paul * Interpolate S,T,R with perspective correction, w/out mipmapping.
870e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
871cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME general_textured_triangle
872e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
87354e92e8420a028f07b0971ee8aa93be9b4214579Brian Paul#define INTERP_W 1
87495e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1
875e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
876e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_RGB 1
877e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_SPEC 1
878e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_ALPHA 1
879e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_TEX 1
88045bc887da226403f2c41077e40ca38b6f60f1359Brian Paul#define RENDER_SPAN( span )   _swrast_write_texture_span(ctx, &span);
881e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
882e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
883e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
884f1e236987829393c81dc86ea19cb49eefe190317Brian Paul
885e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
886e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * This is the big one!
88731f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul * Interpolate Z, RGB, Alpha, specular, fog, and N sets of texture coordinates.
888e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Yup, it's slow.
889e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
890cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME multitextured_triangle
891e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
89254e92e8420a028f07b0971ee8aa93be9b4214579Brian Paul#define INTERP_W 1
89395e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1
894e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
895e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_RGB 1
896e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_ALPHA 1
8979bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_SPEC 1
898e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_MULTITEX 1
89945bc887da226403f2c41077e40ca38b6f60f1359Brian Paul#define RENDER_SPAN( span )   _swrast_write_texture_span(ctx, &span);
900e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
901e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
902e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
903e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
904b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul/*
905b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul * Special tri function for occlusion testing
906b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul */
907cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME occlusion_zless_triangle
908e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DO_OCCLUSION_TEST
909e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
910e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
911b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul#define SETUP_CODE						\
912b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul   if (ctx->OcclusionResult && !ctx->Occlusion.Active) {	\
913b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul      return;							\
914cdf2da368d180205df3573697b51b8764048ad6eBrian Paul   }
9159bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define RENDER_SPAN( span )				\
9169bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLuint i;						\
91777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   for (i = 0; i < span.end; i++) {			\
91877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      GLdepth z = FixedToDepth(span.z);			\
9199bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      if (z < zRow[i]) {				\
9209bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         ctx->OcclusionResult = GL_TRUE;		\
921b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul         ctx->Occlusion.PassedCounter++;		\
9229bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      }							\
92377df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.z += span.zStep;				\
924e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
925e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
926e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
927cdf2da368d180205df3573697b51b8764048ad6eBrian Paul
928cdf2da368d180205df3573697b51b8764048ad6eBrian Paul
929cdf2da368d180205df3573697b51b8764048ad6eBrian Paulstatic void
930cdf2da368d180205df3573697b51b8764048ad6eBrian Paulnodraw_triangle( GLcontext *ctx,
931cdf2da368d180205df3573697b51b8764048ad6eBrian Paul                 const SWvertex *v0,
932cdf2da368d180205df3573697b51b8764048ad6eBrian Paul                 const SWvertex *v1,
933cdf2da368d180205df3573697b51b8764048ad6eBrian Paul                 const SWvertex *v2 )
93447489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell{
93547489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell   (void) (ctx && v0 && v1 && v2);
93647489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell}
937e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
938f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul
939f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul/*
940f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul * This is used when separate specular color is enabled, but not
941fa6b2fba7ad0504a63ab262f602c6f50f336ca1bBrian Paul * texturing.  We add the specular color to the primary color,
942f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul * draw the triangle, then restore the original primary color.
943f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul * Inefficient, but seldom needed.
944f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul */
94546b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwellvoid _swrast_add_spec_terms_triangle( GLcontext *ctx,
94646b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell				      const SWvertex *v0,
94746b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell				      const SWvertex *v1,
94846b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell				      const SWvertex *v2 )
94946b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell{
95046b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   SWvertex *ncv0 = (SWvertex *)v0; /* drop const qualifier */
95146b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   SWvertex *ncv1 = (SWvertex *)v1;
95246b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   SWvertex *ncv2 = (SWvertex *)v2;
953f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul#if CHAN_TYPE == GL_FLOAT
954f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   GLfloat rSum, gSum, bSum;
955f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul#else
956f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   GLint rSum, gSum, bSum;
957f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul#endif
95846b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   GLchan c[3][4];
959f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   /* save original colors */
96046b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   COPY_CHAN4( c[0], ncv0->color );
96146b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   COPY_CHAN4( c[1], ncv1->color );
96246b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   COPY_CHAN4( c[2], ncv2->color );
963f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   /* sum v0 */
964f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   rSum = ncv0->color[0] + ncv0->specular[0];
965f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   gSum = ncv0->color[1] + ncv0->specular[1];
966f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   bSum = ncv0->color[2] + ncv0->specular[2];
967f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv0->color[0] = MIN2(rSum, CHAN_MAX);
968f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv0->color[1] = MIN2(gSum, CHAN_MAX);
969f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv0->color[2] = MIN2(bSum, CHAN_MAX);
970f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   /* sum v1 */
971f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   rSum = ncv1->color[0] + ncv1->specular[0];
972f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   gSum = ncv1->color[1] + ncv1->specular[1];
973f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   bSum = ncv1->color[2] + ncv1->specular[2];
974f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv1->color[0] = MIN2(rSum, CHAN_MAX);
975f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv1->color[1] = MIN2(gSum, CHAN_MAX);
976f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv1->color[2] = MIN2(bSum, CHAN_MAX);
977f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   /* sum v2 */
978f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   rSum = ncv2->color[0] + ncv2->specular[0];
979f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   gSum = ncv2->color[1] + ncv2->specular[1];
980f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   bSum = ncv2->color[2] + ncv2->specular[2];
981f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv2->color[0] = MIN2(rSum, CHAN_MAX);
982f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv2->color[1] = MIN2(gSum, CHAN_MAX);
983f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv2->color[2] = MIN2(bSum, CHAN_MAX);
984f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   /* draw */
98546b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   SWRAST_CONTEXT(ctx)->SpecTriangle( ctx, ncv0, ncv1, ncv2 );
986f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   /* restore original colors */
98746b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   COPY_CHAN4( ncv0->color, c[0] );
98846b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   COPY_CHAN4( ncv1->color, c[1] );
98922144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes   COPY_CHAN4( ncv2->color, c[2] );
99046b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell}
99146b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell
992e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
993e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
994e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul#ifdef DEBUG
995e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
996e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul/* record the current triangle function name */
997fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paulconst char *_mesa_triFuncName = NULL;
998e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
9992a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul#define USE(triFunc)				\
10002a182a98973edc9ecf2936b1288485bb2b3fa722Brian Pauldo {						\
10012a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul    _mesa_triFuncName = #triFunc;		\
10022a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul    /*printf("%s\n", _mesa_triFuncName);*/	\
10032a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul    swrast->Triangle = triFunc;			\
1004e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul} while (0)
1005e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
1006e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#else
1007e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
1008e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul#define USE(triFunc)  swrast->Triangle = triFunc;
1009e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
1010e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#endif
1011e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
1012e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
1013e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
1014e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
1015e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
1016e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Determine which triangle rendering function to use given the current
1017e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * rendering context.
1018e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell *
1019e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Please update the summary flag _SWRAST_NEW_TRIANGLE if you add or
1020e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * remove tests to this code.
1021e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
102222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughesvoid
1023cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell_swrast_choose_triangle( GLcontext *ctx )
1024e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{
1025cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell   SWcontext *swrast = SWRAST_CONTEXT(ctx);
1026b6bcae5698df88f7730d40004ce7ce0462e97a20Brian Paul   const GLboolean rgbmode = ctx->Visual.rgbMode;
1027e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
102838f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes   if (ctx->Polygon.CullFlag &&
102947489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell       ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) {
1030e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul      USE(nodraw_triangle);
103147489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell      return;
103247489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell   }
103347489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell
1034e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   if (ctx->RenderMode==GL_RENDER) {
1035e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
1036e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      if (ctx->Polygon.SmoothFlag) {
103745bc887da226403f2c41077e40ca38b6f60f1359Brian Paul         _swrast_set_aa_triangle_function(ctx);
1038cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell         ASSERT(swrast->Triangle);
1039e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell         return;
1040e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      }
1041e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
1042b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul      /* special case for occlusion testing */
1043b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul      if ((ctx->Depth.OcclusionTest || ctx->Occlusion.Active) &&
1044e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell          ctx->Depth.Test &&
1045e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell          ctx->Depth.Mask == GL_FALSE &&
1046e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell          ctx->Depth.Func == GL_LESS &&
1047e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell          !ctx->Stencil.Enabled) {
1048e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell         if ((rgbmode &&
104922144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes              ctx->Color.ColorMask[0] == 0 &&
105022144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes              ctx->Color.ColorMask[1] == 0 &&
1051e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell              ctx->Color.ColorMask[2] == 0 &&
1052e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell              ctx->Color.ColorMask[3] == 0)
1053e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell             ||
1054e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell             (!rgbmode && ctx->Color.IndexMask == 0)) {
1055e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul            USE(occlusion_zless_triangle);
1056e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            return;
1057e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell         }
1058e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      }
1059e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
1060853bda3e7c4dfa7d8cc462729f6a3dce89e44963Brian Paul      if (ctx->Texture._EnabledCoordUnits || ctx->FragmentProgram.Enabled) {
1061e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell         /* Ugh, we do a _lot_ of tests to pick the best textured tri func */
1062e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	 const struct gl_texture_object *texObj2D;
1063e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul         const struct gl_texture_image *texImg;
106438e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul         GLenum minFilter, magFilter, envMode;
106538e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul         GLint format;
1066e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul         texObj2D = ctx->Texture.Unit[0].Current2D;
106718fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell         texImg = texObj2D ? texObj2D->Image[0][texObj2D->BaseLevel] : NULL;
106838e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul         format = texImg ? texImg->TexFormat->MesaFormat : -1;
1069e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul         minFilter = texObj2D ? texObj2D->MinFilter : (GLenum) 0;
1070e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul         magFilter = texObj2D ? texObj2D->MagFilter : (GLenum) 0;
1071e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul         envMode = ctx->Texture.Unit[0].EnvMode;
1072e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
1073c0fc0d4e5f5c246fc2459348a3d114b232d0c545Brian Paul         /* First see if we can use an optimized 2-D texture function */
107436a0a3252e1e20df69b53f70ba93bc74c4a4bf0eBrian Paul         if (ctx->Texture._EnabledCoordUnits == 1
1075f386f73f9e4054a750d453fa2f5449c2f1d2e242Brian Paul             && !ctx->FragmentProgram.Enabled
10768afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul             && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT
1077e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul             && texObj2D->WrapS==GL_REPEAT
1078e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	     && texObj2D->WrapT==GL_REPEAT
1079887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul             && texObj2D->_IsPowerOfTwo
1080e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul             && texImg->Border==0
1081681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul             && texImg->Width == texImg->RowStride
108238e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul             && (format == MESA_FORMAT_RGB || format == MESA_FORMAT_RGBA)
1083e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	     && minFilter == magFilter
1084e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	     && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR
1085e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	     && ctx->Texture.Unit[0].EnvMode != GL_COMBINE_EXT) {
1086e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	    if (ctx->Hint.PerspectiveCorrection==GL_FASTEST) {
1087e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	       if (minFilter == GL_NEAREST
10889bf68ad963ba92b5d1e725f965979042495a5313Brian Paul		   && format == MESA_FORMAT_RGB
1089e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul		   && (envMode == GL_REPLACE || envMode == GL_DECAL)
10909bf68ad963ba92b5d1e725f965979042495a5313Brian Paul		   && ((swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT)
1091e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul			&& ctx->Depth.Func == GL_LESS
1092e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul			&& ctx->Depth.Mask == GL_TRUE)
10939bf68ad963ba92b5d1e725f965979042495a5313Brian Paul		       || swrast->_RasterMask == TEXTURE_BIT)
1094e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul		   && ctx->Polygon.StippleFlag == GL_FALSE) {
10959bf68ad963ba92b5d1e725f965979042495a5313Brian Paul		  if (swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT)) {
1096e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul		     USE(simple_z_textured_triangle);
1097e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell		  }
1098e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell		  else {
1099e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul		     USE(simple_textured_triangle);
1100e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell		  }
1101e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	       }
1102e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	       else {
1103e0bafefd7ac911ec101876f4ea0d201309e841f2Brian Paul#if (CHAN_BITS == 16 || CHAN_BITS == 32)
110496385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul                  USE(general_textured_triangle);
110596385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul#else
110696385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul                  USE(affine_textured_triangle);
1107f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#endif
1108e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	       }
1109e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	    }
1110e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	    else {
1111e0bafefd7ac911ec101876f4ea0d201309e841f2Brian Paul#if (CHAN_BITS == 16 || CHAN_BITS == 32)
111296385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul               USE(general_textured_triangle);
111396385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul#else
111496385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul               USE(persp_textured_triangle);
111596385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul#endif
1116e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	    }
1117e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	 }
1118e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell         else {
111931f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul            /* general case textured triangles */
112036a0a3252e1e20df69b53f70ba93bc74c4a4bf0eBrian Paul            if (ctx->Texture._EnabledCoordUnits > 1) {
112131f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul               USE(multitextured_triangle);
1122e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            }
1123e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            else {
112431f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul               USE(general_textured_triangle);
1125e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            }
1126e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell         }
1127e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      }
1128e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      else {
112936a0a3252e1e20df69b53f70ba93bc74c4a4bf0eBrian Paul         ASSERT(!ctx->Texture._EnabledCoordUnits);
1130e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	 if (ctx->Light.ShadeModel==GL_SMOOTH) {
1131e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	    /* smooth shaded, no texturing, stippled or some raster ops */
1132e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            if (rgbmode) {
1133e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	       USE(smooth_rgba_triangle);
1134e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            }
1135e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            else {
1136e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul               USE(smooth_ci_triangle);
1137e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            }
1138e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	 }
1139e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	 else {
1140e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	    /* flat shaded, no texturing, stippled or some raster ops */
1141e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            if (rgbmode) {
1142e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	       USE(flat_rgba_triangle);
1143e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            }
1144e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            else {
1145e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul               USE(flat_ci_triangle);
1146e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            }
1147e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	 }
1148e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      }
1149e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
1150e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   else if (ctx->RenderMode==GL_FEEDBACK) {
115145bc887da226403f2c41077e40ca38b6f60f1359Brian Paul      USE(_swrast_feedback_triangle);
1152e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
1153e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   else {
1154e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      /* GL_SELECT mode */
115545bc887da226403f2c41077e40ca38b6f60f1359Brian Paul      USE(_swrast_select_triangle);
1156e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
1157e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell}
1158