s_triangle.c revision e6e0ba781b0a6a1b8747cae49ca622a6a61b1bf8
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;	\
801e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul   span.index = FloatToFixed(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.
195e6e0ba781b0a6a1b8747cae49ca622a6a61b1bf8Brian Paul * Depth buffer bits must be <= sizeof(DEFAULT_SOFTWARE_DEPTH_TYPE)
19622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes *
197e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * No fog.
198e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
199cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME simple_z_textured_triangle
200e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
201e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
202e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_INT_TEX 1
203e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define S_SCALE twidth
204e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define T_SCALE theight
2059bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
206e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define SETUP_CODE							\
207709892459922a32096fe9dd8261d0d92337bb02fKeith Whitwell   SWcontext *swrast = SWRAST_CONTEXT(ctx);                             \
208a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul   struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D;	\
2092ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul   const GLint b = obj->BaseLevel;					\
21018fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;		\
21118fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLfloat theight = (GLfloat) obj->Image[0][b]->Height;		\
212230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   const GLint twidth_log2 = obj->Image[0][b]->WidthLog2;		\
21318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLchan *texture = (const GLchan *) obj->Image[0][b]->Data;	\
21418fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLint smask = obj->Image[0][b]->Width - 1;			\
21518fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLint tmask = obj->Image[0][b]->Height - 1;			\
216e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   if (!texture) {							\
2178e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      /* this shouldn't happen */					\
2188e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      return;								\
219e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
220e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
2219bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define RENDER_SPAN( span )						\
2229bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLuint i;				    				\
22377df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.intTex[0] -= FIXED_HALF; /* off-by-one error? */		\
22477df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.intTex[1] -= FIXED_HALF;					\
22577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   for (i = 0; i < span.end; i++) {					\
22677df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      const GLdepth z = FixedToDepth(span.z);				\
2279bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      if (z < zRow[i]) {						\
22877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         GLint s = FixedToInt(span.intTex[0]) & smask;			\
22977df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         GLint t = FixedToInt(span.intTex[1]) & tmask;			\
2309bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         GLint pos = (t << twidth_log2) + s;				\
2319bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         pos = pos + pos + pos;  /* multiply by 3 */			\
23277df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         span.array->rgb[i][RCOMP] = texture[pos];			\
23377df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         span.array->rgb[i][GCOMP] = texture[pos+1];			\
23477df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         span.array->rgb[i][BCOMP] = texture[pos+2];			\
2359bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         zRow[i] = z;							\
23677df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         span.array->mask[i] = 1;					\
2379bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      }									\
2389bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      else {								\
23977df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul         span.array->mask[i] = 0;					\
2409bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      }									\
24177df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.intTex[0] += span.intTexStep[0];				\
24277df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.intTex[1] += span.intTexStep[1];				\
24377df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.z += span.zStep;						\
2449bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   }									\
24577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   (*swrast->Driver.WriteRGBSpan)(ctx, span.end, span.x, span.y,	\
24677df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul                                  (CONST GLchan (*)[3]) span.array->rgb,\
24777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul                                  span.array->mask );
248e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
249cdf2da368d180205df3573697b51b8764048ad6eBrian Paul
250e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
251e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
252f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#if CHAN_TYPE != GL_FLOAT
253e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
2549bf68ad963ba92b5d1e725f965979042495a5313Brian Paulstruct affine_info
255e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{
2569bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLenum filter;
2579bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLenum format;
2589bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLenum envmode;
2599bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLint smask, tmask;
2609bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLint twidth_log2;
2619bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   const GLchan *texture;
262fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul   GLfixed er, eg, eb, ea;
2639bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLint tbytesline, tsize;
2649bf68ad963ba92b5d1e725f965979042495a5313Brian Paul};
265cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell
2667152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul
2677152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul/* This function can handle GL_NEAREST or GL_LINEAR sampling of 2D RGB or RGBA
2687152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul * textures with GL_REPLACE, GL_MODULATE, GL_BLEND, GL_DECAL or GL_ADD
2697152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul * texture env modes.
2707152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul */
27171340e861edf35bfdeb536718cd230fc33c41ee2Brian Paulstatic INLINE void
27257d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paulaffine_span(GLcontext *ctx, struct sw_span *span,
2739bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            struct affine_info *info)
2749bf68ad963ba92b5d1e725f965979042495a5313Brian Paul{
2757152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   GLchan sample[4];  /* the filtered texture sample */
276e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
277fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul   /* Instead of defining a function for each mode, a test is done
278fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul    * between the outer and inner loops. This is to reduce code size
279fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul    * and complexity. Observe that an optimizing compiler kills
280fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul    * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST).
281fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul    */
282e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
283bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul#define NEAREST_RGB			\
2847152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[RCOMP] = tex00[RCOMP];	\
2857152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[GCOMP] = tex00[GCOMP];	\
2867152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[BCOMP] = tex00[BCOMP];	\
2877152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[ACOMP] = CHAN_MAX
288e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
2899bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define LINEAR_RGB							\
2907152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[RCOMP] = (ti * (si * tex00[0] + sf * tex01[0]) +		\
291bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul             tf * (si * tex10[0] + sf * tex11[0])) >> 2 * FIXED_SHIFT;	\
2927152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[GCOMP] = (ti * (si * tex00[1] + sf * tex01[1]) +		\
293bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul             tf * (si * tex10[1] + sf * tex11[1])) >> 2 * FIXED_SHIFT;	\
2947152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[BCOMP] = (ti * (si * tex00[2] + sf * tex01[2]) +		\
295bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul             tf * (si * tex10[2] + sf * tex11[2])) >> 2 * FIXED_SHIFT;	\
2967152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[ACOMP] = CHAN_MAX
297bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul
2987152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul#define NEAREST_RGBA  COPY_CHAN4(sample, tex00)
299e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
3009bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define LINEAR_RGBA							\
3017152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[RCOMP] = (ti * (si * tex00[0] + sf * tex01[0]) +		\
302bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               tf * (si * tex10[0] + sf * tex11[0])) >> 2 * FIXED_SHIFT;\
3037152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[GCOMP] = (ti * (si * tex00[1] + sf * tex01[1]) +		\
304bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               tf * (si * tex10[1] + sf * tex11[1])) >> 2 * FIXED_SHIFT;\
3057152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[BCOMP] = (ti * (si * tex00[2] + sf * tex01[2]) +		\
306bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               tf * (si * tex10[2] + sf * tex11[2])) >> 2 * FIXED_SHIFT;\
3077152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   sample[ACOMP] = (ti * (si * tex00[3] + sf * tex01[3]) +		\
308bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               tf * (si * tex10[3] + sf * tex11[3])) >> 2 * FIXED_SHIFT
309bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul
310fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul#define MODULATE							  \
3117152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[RCOMP] = span->red   * (sample[RCOMP] + 1u) >> (FIXED_SHIFT + 8); \
3127152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[GCOMP] = span->green * (sample[GCOMP] + 1u) >> (FIXED_SHIFT + 8); \
3137152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[BCOMP] = span->blue  * (sample[BCOMP] + 1u) >> (FIXED_SHIFT + 8); \
3147152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[ACOMP] = span->alpha * (sample[ACOMP] + 1u) >> (FIXED_SHIFT + 8)
3159bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
3169bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define DECAL								\
3177152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[RCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->red +		\
3187152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul               ((sample[ACOMP] + 1) * sample[RCOMP] << FIXED_SHIFT))	\
319bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               >> (FIXED_SHIFT + 8);					\
3207152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[GCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->green +		\
3217152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul               ((sample[ACOMP] + 1) * sample[GCOMP] << FIXED_SHIFT))	\
322bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               >> (FIXED_SHIFT + 8);					\
3237152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[BCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->blue +		\
3247152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul               ((sample[ACOMP] + 1) * sample[BCOMP] << FIXED_SHIFT))	\
325bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul               >> (FIXED_SHIFT + 8);					\
326bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul   dest[ACOMP] = FixedToInt(span->alpha)
3279bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
3289bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define BLEND								\
3297152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[RCOMP] = ((CHAN_MAX - sample[RCOMP]) * span->red		\
3307152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul               + (sample[RCOMP] + 1) * info->er) >> (FIXED_SHIFT + 8);	\
3317152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[GCOMP] = ((CHAN_MAX - sample[GCOMP]) * span->green		\
3327152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul               + (sample[GCOMP] + 1) * info->eg) >> (FIXED_SHIFT + 8);	\
3337152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[BCOMP] = ((CHAN_MAX - sample[BCOMP]) * span->blue		\
3347152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul               + (sample[BCOMP] + 1) * info->eb) >> (FIXED_SHIFT + 8);	\
3357152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   dest[ACOMP] = span->alpha * (sample[ACOMP] + 1) >> (FIXED_SHIFT + 8)
336bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul
3377152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul#define REPLACE  COPY_CHAN4(dest, sample)
338e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
3399bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define ADD								\
3407152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   {									\
3417152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      GLint rSum = FixedToInt(span->red)   + (GLint) sample[RCOMP];	\
3427152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      GLint gSum = FixedToInt(span->green) + (GLint) sample[GCOMP];	\
3437152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      GLint bSum = FixedToInt(span->blue)  + (GLint) sample[BCOMP];	\
3447152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      dest[RCOMP] = MIN2(rSum, CHAN_MAX);				\
3457152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      dest[GCOMP] = MIN2(gSum, CHAN_MAX);				\
3467152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      dest[BCOMP] = MIN2(bSum, CHAN_MAX);				\
3477152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul      dest[ACOMP] = span->alpha * (sample[ACOMP] + 1) >> (FIXED_SHIFT + 8); \
3487152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul  }
349e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
350e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* shortcuts */
351e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
35235e5e89f5614ebb032479b02dec888563f829b30Brian Paul#define NEAREST_RGB_REPLACE		\
35335e5e89f5614ebb032479b02dec888563f829b30Brian Paul   NEAREST_RGB;				\
35435e5e89f5614ebb032479b02dec888563f829b30Brian Paul   dest[0] = sample[0];			\
35535e5e89f5614ebb032479b02dec888563f829b30Brian Paul   dest[1] = sample[1];			\
35635e5e89f5614ebb032479b02dec888563f829b30Brian Paul   dest[2] = sample[2];			\
35735e5e89f5614ebb032479b02dec888563f829b30Brian Paul   dest[3] = FixedToInt(span->alpha);
358e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
359bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul#define NEAREST_RGBA_REPLACE  COPY_CHAN4(dest, tex00)
360e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
36133170eeb185f5fe766374a749464497cdfab6931Brian Paul#define SPAN_NEAREST(DO_TEX,COMP)					\
36257d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul	for (i = 0; i < span->end; i++) {				\
36333170eeb185f5fe766374a749464497cdfab6931Brian Paul           /* Isn't it necessary to use FixedFloor below?? */		\
3649bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           GLint s = FixedToInt(span->intTex[0]) & info->smask;		\
3659bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           GLint t = FixedToInt(span->intTex[1]) & info->tmask;		\
3669bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           GLint pos = (t << info->twidth_log2) + s;			\
3679bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           const GLchan *tex00 = info->texture + COMP * pos;		\
3689bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           DO_TEX;							\
3699bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           span->red += span->redStep;					\
3709bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->green += span->greenStep;				\
3719bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           span->blue += span->blueStep;				\
3729bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->alpha += span->alphaStep;				\
3739bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->intTex[0] += span->intTexStep[0];			\
3749bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->intTex[1] += span->intTexStep[1];			\
3759bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           dest += 4;							\
376e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	}
377e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
37833170eeb185f5fe766374a749464497cdfab6931Brian Paul#define SPAN_LINEAR(DO_TEX,COMP)					\
37957d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul	for (i = 0; i < span->end; i++) {				\
38033170eeb185f5fe766374a749464497cdfab6931Brian Paul           /* Isn't it necessary to use FixedFloor below?? */		\
3819bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           GLint s = FixedToInt(span->intTex[0]) & info->smask;		\
3829bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           GLint t = FixedToInt(span->intTex[1]) & info->tmask;		\
38333170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLfixed sf = span->intTex[0] & FIXED_FRAC_MASK;		\
38433170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLfixed tf = span->intTex[1] & FIXED_FRAC_MASK;		\
38533170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLfixed si = FIXED_FRAC_MASK - sf;				\
38633170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLfixed ti = FIXED_FRAC_MASK - tf;				\
3879bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           GLint pos = (t << info->twidth_log2) + s;			\
3889bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           const GLchan *tex00 = info->texture + COMP * pos;		\
3899bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           const GLchan *tex10 = tex00 + info->tbytesline;		\
3909bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           const GLchan *tex01 = tex00 + COMP;				\
3919bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           const GLchan *tex11 = tex10 + COMP;				\
3929bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           (void) ti;							\
3939bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           (void) si;							\
3949bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           if (t == info->tmask) {					\
3959bf68ad963ba92b5d1e725f965979042495a5313Brian Paul              tex10 -= info->tsize;					\
3969bf68ad963ba92b5d1e725f965979042495a5313Brian Paul              tex11 -= info->tsize;					\
3979bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           }								\
3989bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           if (s == info->smask) {					\
3999bf68ad963ba92b5d1e725f965979042495a5313Brian Paul              tex01 -= info->tbytesline;				\
4009bf68ad963ba92b5d1e725f965979042495a5313Brian Paul              tex11 -= info->tbytesline;				\
4019bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           }								\
4029bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           DO_TEX;							\
4039bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           span->red += span->redStep;					\
4049bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->green += span->greenStep;				\
4059bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           span->blue += span->blueStep;				\
4069bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->alpha += span->alphaStep;				\
4079bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->intTex[0] += span->intTexStep[0];			\
4089bf68ad963ba92b5d1e725f965979042495a5313Brian Paul	   span->intTex[1] += span->intTexStep[1];			\
4099bf68ad963ba92b5d1e725f965979042495a5313Brian Paul           dest += 4;							\
410e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	}
411e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
4129bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
4139bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLuint i;
41477df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   GLchan *dest = span->array->rgba[0];
41557d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul
4169bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   span->intTex[0] -= FIXED_HALF;
4179bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   span->intTex[1] -= FIXED_HALF;
4189bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   switch (info->filter) {
4199bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_NEAREST:
4209bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      switch (info->format) {
4219bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      case GL_RGB:
4229bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         switch (info->envmode) {
4239bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_MODULATE:
42433170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB;MODULATE,3);
4259bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4269bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_DECAL:
4279bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_REPLACE:
42833170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB_REPLACE,3);
4299bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4309bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_BLEND:
43133170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB;BLEND,3);
4329bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4339bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_ADD:
43433170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB;ADD,3);
4359bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4369bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         default:
4374663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode in SPAN_LINEAR");
4384663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
4399bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         }
4409bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         break;
4419bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      case GL_RGBA:
4429bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         switch(info->envmode) {
4439bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_MODULATE:
44433170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;MODULATE,4);
4459bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4469bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_DECAL:
44733170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;DECAL,4);
4489bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4499bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_BLEND:
45033170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;BLEND,4);
4519bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4529bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_ADD:
45333170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;ADD,4);
4549bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4559bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_REPLACE:
45633170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA_REPLACE,4);
4579bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4589bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         default:
4594663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (2) in SPAN_LINEAR");
4604663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
4619bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         }
4629bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         break;
4639bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      }
4649bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      break;
4659bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
4669bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_LINEAR:
4679bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      span->intTex[0] -= FIXED_HALF;
4689bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      span->intTex[1] -= FIXED_HALF;
4699bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      switch (info->format) {
4709bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      case GL_RGB:
4719bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         switch (info->envmode) {
4729bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_MODULATE:
47333170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;MODULATE,3);
4749bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4759bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_DECAL:
4769bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_REPLACE:
47733170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;REPLACE,3);
4789bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4799bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_BLEND:
48033170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;BLEND,3);
4819bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4829bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_ADD:
48333170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;ADD,3);
4849bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4859bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         default:
4864663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (3) in SPAN_LINEAR");
4874663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
4889bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         }
4899bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         break;
4909bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      case GL_RGBA:
4919bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         switch (info->envmode) {
4929bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_MODULATE:
49333170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;MODULATE,4);
4949bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4959bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_DECAL:
49633170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;DECAL,4);
4979bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
4989bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_BLEND:
49933170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;BLEND,4);
5009bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
5019bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_ADD:
50233170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;ADD,4);
5039bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
5049bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         case GL_REPLACE:
50533170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;REPLACE,4);
5069bf68ad963ba92b5d1e725f965979042495a5313Brian Paul            break;
5079bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         default:
5084663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (4) in SPAN_LINEAR");
5094663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
5104663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul         }
5114663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul         break;
5129bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      }
5139bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      break;
5149bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   }
515733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul   span->interpMask &= ~SPAN_RGBA;
5162a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul   ASSERT(span->arrayMask & SPAN_RGBA);
51745bc887da226403f2c41077e40ca38b6f60f1359Brian Paul   _swrast_write_rgba_span(ctx, span);
518e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
51933170eeb185f5fe766374a749464497cdfab6931Brian Paul#undef SPAN_NEAREST
52033170eeb185f5fe766374a749464497cdfab6931Brian Paul#undef SPAN_LINEAR
521e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell}
522e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
523e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
524e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
525e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
5269bf68ad963ba92b5d1e725f965979042495a5313Brian Paul * Render an RGB/RGBA textured triangle without perspective correction.
5279bf68ad963ba92b5d1e725f965979042495a5313Brian Paul */
528cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME affine_textured_triangle
5299bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_Z 1
5309bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_FOG 1
5319bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
5329bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_RGB 1
5339bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_ALPHA 1
5349bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_INT_TEX 1
5359bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define S_SCALE twidth
5369bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define T_SCALE theight
5379bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
538571c8ecc8f9442fb8bbaa1f29b1d0d4f8e5b3cadBrian Paul#define SETUP_CODE							\
539571c8ecc8f9442fb8bbaa1f29b1d0d4f8e5b3cadBrian Paul   struct affine_info info;						\
5409bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   struct gl_texture_unit *unit = ctx->Texture.Unit+0;			\
5419bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   struct gl_texture_object *obj = unit->Current2D;			\
5422ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul   const GLint b = obj->BaseLevel;					\
54318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width;		\
54418fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   const GLfloat theight = (GLfloat) obj->Image[0][b]->Height;		\
545230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   info.texture = (const GLchan *) obj->Image[0][b]->Data;		\
546230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   info.twidth_log2 = obj->Image[0][b]->WidthLog2;			\
54718fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   info.smask = obj->Image[0][b]->Width - 1;				\
54818fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   info.tmask = obj->Image[0][b]->Height - 1;				\
549230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   info.format = obj->Image[0][b]->Format;				\
5509bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   info.filter = obj->MinFilter;					\
5519bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   info.envmode = unit->EnvMode;					\
55277df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.arrayMask |= SPAN_RGBA;						\
5539bf68ad963ba92b5d1e725f965979042495a5313Brian Paul									\
5549bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   if (info.envmode == GL_BLEND) {					\
5559bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      /* potential off-by-one error here? (1.0f -> 2048 -> 0) */	\
556fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.er = FloatToFixed(unit->EnvColor[RCOMP] * CHAN_MAXF);	\
557fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.eg = FloatToFixed(unit->EnvColor[GCOMP] * CHAN_MAXF);	\
558fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.eb = FloatToFixed(unit->EnvColor[BCOMP] * CHAN_MAXF);	\
559fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.ea = FloatToFixed(unit->EnvColor[ACOMP] * CHAN_MAXF);	\
5609bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   }									\
5619bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   if (!info.texture) {							\
5629bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      /* this shouldn't happen */					\
5639bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      return;								\
5649bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   }									\
5659bf68ad963ba92b5d1e725f965979042495a5313Brian Paul									\
5669bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   switch (info.format) {						\
5679bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_ALPHA:							\
5689bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_LUMINANCE:							\
5699bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_INTENSITY:							\
570230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul      info.tbytesline = obj->Image[0][b]->Width;			\
5719bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      break;								\
5729bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_LUMINANCE_ALPHA:						\
57318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell      info.tbytesline = obj->Image[0][b]->Width * 2;			\
5749bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      break;								\
5759bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_RGB:								\
57618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell      info.tbytesline = obj->Image[0][b]->Width * 3;			\
5779bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      break;								\
5789bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   case GL_RGBA:							\
57918fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell      info.tbytesline = obj->Image[0][b]->Width * 4;			\
5809bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      break;								\
5819bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   default:								\
5829bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      _mesa_problem(NULL, "Bad texture format in affine_texture_triangle");\
5839bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      return;								\
5849bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   }									\
58518fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   info.tsize = obj->Image[0][b]->Height * info.tbytesline;
5869bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
58777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul#define RENDER_SPAN( span )   affine_span(ctx, &span, &info);
5889bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
5899bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#include "s_tritemp.h"
5909bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
591f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul
5929bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
59333170eeb185f5fe766374a749464497cdfab6931Brian Paulstruct persp_info
594e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{
59533170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLenum filter;
59633170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLenum format;
59733170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLenum envmode;
59833170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLint smask, tmask;
59933170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLint twidth_log2;
60033170eeb185f5fe766374a749464497cdfab6931Brian Paul   const GLchan *texture;
601fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul   GLfixed er, eg, eb, ea;   /* texture env color */
60233170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLint tbytesline, tsize;
60333170eeb185f5fe766374a749464497cdfab6931Brian Paul};
604e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
605f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul
60671340e861edf35bfdeb536718cd230fc33c41ee2Brian Paulstatic INLINE void
60757d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paulfast_persp_span(GLcontext *ctx, struct sw_span *span,
60833170eeb185f5fe766374a749464497cdfab6931Brian Paul		struct persp_info *info)
60933170eeb185f5fe766374a749464497cdfab6931Brian Paul{
6107152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul   GLchan sample[4];  /* the filtered texture sample */
6119bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
61233170eeb185f5fe766374a749464497cdfab6931Brian Paul  /* Instead of defining a function for each mode, a test is done
61333170eeb185f5fe766374a749464497cdfab6931Brian Paul   * between the outer and inner loops. This is to reduce code size
61433170eeb185f5fe766374a749464497cdfab6931Brian Paul   * and complexity. Observe that an optimizing compiler kills
61533170eeb185f5fe766374a749464497cdfab6931Brian Paul   * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST).
61633170eeb185f5fe766374a749464497cdfab6931Brian Paul   */
61733170eeb185f5fe766374a749464497cdfab6931Brian Paul#define SPAN_NEAREST(DO_TEX,COMP)					\
61857d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul	for (i = 0; i < span->end; i++) {				\
61933170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLdouble invQ = tex_coord[2] ?				\
62033170eeb185f5fe766374a749464497cdfab6931Brian Paul                                 (1.0 / tex_coord[2]) : 1.0;            \
6217c4268176eaaeb45003db4d5042a518b84c9f6dcKarl Schultz           GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ);		\
6227c4268176eaaeb45003db4d5042a518b84c9f6dcKarl Schultz           GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ);		\
62333170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLint s = IFLOOR(s_tmp) & info->smask;	        	\
62433170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLint t = IFLOOR(t_tmp) & info->tmask;	        	\
62533170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLint pos = (t << info->twidth_log2) + s;			\
62633170eeb185f5fe766374a749464497cdfab6931Brian Paul           const GLchan *tex00 = info->texture + COMP * pos;		\
62733170eeb185f5fe766374a749464497cdfab6931Brian Paul           DO_TEX;							\
62833170eeb185f5fe766374a749464497cdfab6931Brian Paul           span->red += span->redStep;					\
62933170eeb185f5fe766374a749464497cdfab6931Brian Paul	   span->green += span->greenStep;				\
63033170eeb185f5fe766374a749464497cdfab6931Brian Paul           span->blue += span->blueStep;				\
63133170eeb185f5fe766374a749464497cdfab6931Brian Paul	   span->alpha += span->alphaStep;				\
63233170eeb185f5fe766374a749464497cdfab6931Brian Paul	   tex_coord[0] += tex_step[0];					\
63333170eeb185f5fe766374a749464497cdfab6931Brian Paul	   tex_coord[1] += tex_step[1];					\
63433170eeb185f5fe766374a749464497cdfab6931Brian Paul	   tex_coord[2] += tex_step[2];					\
63533170eeb185f5fe766374a749464497cdfab6931Brian Paul           dest += 4;							\
63633170eeb185f5fe766374a749464497cdfab6931Brian Paul	}
637e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
63833170eeb185f5fe766374a749464497cdfab6931Brian Paul#define SPAN_LINEAR(DO_TEX,COMP)					\
63957d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul	for (i = 0; i < span->end; i++) {				\
64033170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLdouble invQ = tex_coord[2] ?				\
64133170eeb185f5fe766374a749464497cdfab6931Brian Paul                                 (1.0 / tex_coord[2]) : 1.0;            \
6427c4268176eaaeb45003db4d5042a518b84c9f6dcKarl Schultz           GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ);		\
6437c4268176eaaeb45003db4d5042a518b84c9f6dcKarl Schultz           GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ);		\
644bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul           GLfixed s_fix = FloatToFixed(s_tmp) - FIXED_HALF;		\
645bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul           GLfixed t_fix = FloatToFixed(t_tmp) - FIXED_HALF;        	\
64633170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLint s = FixedToInt(FixedFloor(s_fix)) & info->smask;	\
64733170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLint t = FixedToInt(FixedFloor(t_fix)) & info->tmask;	\
648fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul           GLfixed sf = s_fix & FIXED_FRAC_MASK;			\
649fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul           GLfixed tf = t_fix & FIXED_FRAC_MASK;			\
65033170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLfixed si = FIXED_FRAC_MASK - sf;				\
65133170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLfixed ti = FIXED_FRAC_MASK - tf;				\
65233170eeb185f5fe766374a749464497cdfab6931Brian Paul           GLint pos = (t << info->twidth_log2) + s;			\
65333170eeb185f5fe766374a749464497cdfab6931Brian Paul           const GLchan *tex00 = info->texture + COMP * pos;		\
65433170eeb185f5fe766374a749464497cdfab6931Brian Paul           const GLchan *tex10 = tex00 + info->tbytesline;		\
65533170eeb185f5fe766374a749464497cdfab6931Brian Paul           const GLchan *tex01 = tex00 + COMP;				\
65633170eeb185f5fe766374a749464497cdfab6931Brian Paul           const GLchan *tex11 = tex10 + COMP;				\
65733170eeb185f5fe766374a749464497cdfab6931Brian Paul           (void) ti;							\
65833170eeb185f5fe766374a749464497cdfab6931Brian Paul           (void) si;							\
65933170eeb185f5fe766374a749464497cdfab6931Brian Paul           if (t == info->tmask) {					\
66033170eeb185f5fe766374a749464497cdfab6931Brian Paul              tex10 -= info->tsize;					\
66133170eeb185f5fe766374a749464497cdfab6931Brian Paul              tex11 -= info->tsize;					\
66233170eeb185f5fe766374a749464497cdfab6931Brian Paul           }								\
66333170eeb185f5fe766374a749464497cdfab6931Brian Paul           if (s == info->smask) {					\
66433170eeb185f5fe766374a749464497cdfab6931Brian Paul              tex01 -= info->tbytesline;				\
66533170eeb185f5fe766374a749464497cdfab6931Brian Paul              tex11 -= info->tbytesline;				\
66633170eeb185f5fe766374a749464497cdfab6931Brian Paul           }								\
66733170eeb185f5fe766374a749464497cdfab6931Brian Paul           DO_TEX;							\
66833170eeb185f5fe766374a749464497cdfab6931Brian Paul           span->red   += span->redStep;				\
66933170eeb185f5fe766374a749464497cdfab6931Brian Paul	   span->green += span->greenStep;				\
67033170eeb185f5fe766374a749464497cdfab6931Brian Paul           span->blue  += span->blueStep;				\
67133170eeb185f5fe766374a749464497cdfab6931Brian Paul	   span->alpha += span->alphaStep;				\
67233170eeb185f5fe766374a749464497cdfab6931Brian Paul	   tex_coord[0] += tex_step[0];					\
67333170eeb185f5fe766374a749464497cdfab6931Brian Paul	   tex_coord[1] += tex_step[1];					\
67433170eeb185f5fe766374a749464497cdfab6931Brian Paul	   tex_coord[2] += tex_step[2];					\
67533170eeb185f5fe766374a749464497cdfab6931Brian Paul           dest += 4;							\
67633170eeb185f5fe766374a749464497cdfab6931Brian Paul	}
677e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
67833170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLuint i;
67933170eeb185f5fe766374a749464497cdfab6931Brian Paul   GLfloat tex_coord[3], tex_step[3];
68077df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   GLchan *dest = span->array->rgba[0];
68157d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul
68231f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul   tex_coord[0] = span->tex[0][0]  * (info->smask + 1);
68331f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul   tex_step[0] = span->texStepX[0][0] * (info->smask + 1);
68431f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul   tex_coord[1] = span->tex[0][1] * (info->tmask + 1);
68531f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul   tex_step[1] = span->texStepX[0][1] * (info->tmask + 1);
68633170eeb185f5fe766374a749464497cdfab6931Brian Paul   /* span->tex[0][2] only if 3D-texturing, here only 2D */
68731f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul   tex_coord[2] = span->tex[0][3];
68831f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul   tex_step[2] = span->texStepX[0][3];
689e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
69033170eeb185f5fe766374a749464497cdfab6931Brian Paul   switch (info->filter) {
69133170eeb185f5fe766374a749464497cdfab6931Brian Paul   case GL_NEAREST:
69233170eeb185f5fe766374a749464497cdfab6931Brian Paul      switch (info->format) {
69333170eeb185f5fe766374a749464497cdfab6931Brian Paul      case GL_RGB:
69433170eeb185f5fe766374a749464497cdfab6931Brian Paul         switch (info->envmode) {
69533170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_MODULATE:
69633170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB;MODULATE,3);
69733170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
69833170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_DECAL:
69933170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_REPLACE:
70033170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB_REPLACE,3);
70133170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
70233170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_BLEND:
70333170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB;BLEND,3);
70433170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
70533170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_ADD:
70633170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGB;ADD,3);
70733170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
70833170eeb185f5fe766374a749464497cdfab6931Brian Paul         default:
7094663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (5) in SPAN_LINEAR");
7104663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
71133170eeb185f5fe766374a749464497cdfab6931Brian Paul         }
71233170eeb185f5fe766374a749464497cdfab6931Brian Paul         break;
71333170eeb185f5fe766374a749464497cdfab6931Brian Paul      case GL_RGBA:
71433170eeb185f5fe766374a749464497cdfab6931Brian Paul         switch(info->envmode) {
71533170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_MODULATE:
71633170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;MODULATE,4);
71733170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
71833170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_DECAL:
71933170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;DECAL,4);
72033170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
72133170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_BLEND:
72233170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;BLEND,4);
72333170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
72433170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_ADD:
72533170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA;ADD,4);
72633170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
72733170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_REPLACE:
72833170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_NEAREST(NEAREST_RGBA_REPLACE,4);
72933170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
73033170eeb185f5fe766374a749464497cdfab6931Brian Paul         default:
7314663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (6) in SPAN_LINEAR");
7324663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
73333170eeb185f5fe766374a749464497cdfab6931Brian Paul         }
73433170eeb185f5fe766374a749464497cdfab6931Brian Paul         break;
73533170eeb185f5fe766374a749464497cdfab6931Brian Paul      }
73633170eeb185f5fe766374a749464497cdfab6931Brian Paul      break;
73733170eeb185f5fe766374a749464497cdfab6931Brian Paul
73833170eeb185f5fe766374a749464497cdfab6931Brian Paul   case GL_LINEAR:
73933170eeb185f5fe766374a749464497cdfab6931Brian Paul      switch (info->format) {
74033170eeb185f5fe766374a749464497cdfab6931Brian Paul      case GL_RGB:
74133170eeb185f5fe766374a749464497cdfab6931Brian Paul         switch (info->envmode) {
74233170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_MODULATE:
74333170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;MODULATE,3);
74433170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
74533170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_DECAL:
74633170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_REPLACE:
74733170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;REPLACE,3);
74833170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
74933170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_BLEND:
75033170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;BLEND,3);
75133170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
75233170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_ADD:
75333170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGB;ADD,3);
75433170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
75533170eeb185f5fe766374a749464497cdfab6931Brian Paul         default:
7564663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (7) in SPAN_LINEAR");
7574663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
75833170eeb185f5fe766374a749464497cdfab6931Brian Paul         }
75933170eeb185f5fe766374a749464497cdfab6931Brian Paul         break;
76033170eeb185f5fe766374a749464497cdfab6931Brian Paul      case GL_RGBA:
76133170eeb185f5fe766374a749464497cdfab6931Brian Paul         switch (info->envmode) {
76233170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_MODULATE:
76333170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;MODULATE,4);
76433170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
76533170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_DECAL:
76633170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;DECAL,4);
76733170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
76833170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_BLEND:
76933170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;BLEND,4);
77033170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
77133170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_ADD:
77233170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;ADD,4);
77333170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
77433170eeb185f5fe766374a749464497cdfab6931Brian Paul         case GL_REPLACE:
77533170eeb185f5fe766374a749464497cdfab6931Brian Paul            SPAN_LINEAR(LINEAR_RGBA;REPLACE,4);
77633170eeb185f5fe766374a749464497cdfab6931Brian Paul            break;
77733170eeb185f5fe766374a749464497cdfab6931Brian Paul         default:
7784663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            _mesa_problem(ctx, "bad tex env mode (8) in SPAN_LINEAR");
7794663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul            return;
78033170eeb185f5fe766374a749464497cdfab6931Brian Paul         }
78133170eeb185f5fe766374a749464497cdfab6931Brian Paul         break;
78233170eeb185f5fe766374a749464497cdfab6931Brian Paul      }
78333170eeb185f5fe766374a749464497cdfab6931Brian Paul      break;
784e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
78533170eeb185f5fe766374a749464497cdfab6931Brian Paul
7862a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul   ASSERT(span->arrayMask & SPAN_RGBA);
78745bc887da226403f2c41077e40ca38b6f60f1359Brian Paul   _swrast_write_rgba_span(ctx, span);
788e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
78933170eeb185f5fe766374a749464497cdfab6931Brian Paul#undef SPAN_NEAREST
79033170eeb185f5fe766374a749464497cdfab6931Brian Paul#undef SPAN_LINEAR
791e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell}
792e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
793e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
794e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
795e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render an perspective corrected RGB/RGBA textured triangle.
796e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * The Q (aka V in Mesa) coordinate must be zero such that the divide
797e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * by interpolated Q/W comes out right.
798e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell *
799e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
800cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME persp_textured_triangle
801e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
80209da0b8e6621a831e3eeb9381430f2bed18a22adBrian Paul#define INTERP_W 1
80395e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1
804e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
805e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_RGB 1
806e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_ALPHA 1
807e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_TEX 1
8089bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
809571c8ecc8f9442fb8bbaa1f29b1d0d4f8e5b3cadBrian Paul#define SETUP_CODE							\
810571c8ecc8f9442fb8bbaa1f29b1d0d4f8e5b3cadBrian Paul   struct persp_info info;						\
8112ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul   const struct gl_texture_unit *unit = ctx->Texture.Unit+0;		\
8122ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul   const struct gl_texture_object *obj = unit->Current2D;		\
8132ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul   const GLint b = obj->BaseLevel;					\
814230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   info.texture = (const GLchan *) obj->Image[0][b]->Data;		\
815230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   info.twidth_log2 = obj->Image[0][b]->WidthLog2;			\
81618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   info.smask = obj->Image[0][b]->Width - 1;				\
81718fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   info.tmask = obj->Image[0][b]->Height - 1;				\
818230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul   info.format = obj->Image[0][b]->Format;				\
81933170eeb185f5fe766374a749464497cdfab6931Brian Paul   info.filter = obj->MinFilter;					\
82033170eeb185f5fe766374a749464497cdfab6931Brian Paul   info.envmode = unit->EnvMode;					\
82133170eeb185f5fe766374a749464497cdfab6931Brian Paul									\
82233170eeb185f5fe766374a749464497cdfab6931Brian Paul   if (info.envmode == GL_BLEND) {					\
82333170eeb185f5fe766374a749464497cdfab6931Brian Paul      /* potential off-by-one error here? (1.0f -> 2048 -> 0) */	\
824fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.er = FloatToFixed(unit->EnvColor[RCOMP] * CHAN_MAXF);	\
825fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.eg = FloatToFixed(unit->EnvColor[GCOMP] * CHAN_MAXF);	\
826fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.eb = FloatToFixed(unit->EnvColor[BCOMP] * CHAN_MAXF);	\
827fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul      info.ea = FloatToFixed(unit->EnvColor[ACOMP] * CHAN_MAXF);	\
82833170eeb185f5fe766374a749464497cdfab6931Brian Paul   }									\
82933170eeb185f5fe766374a749464497cdfab6931Brian Paul   if (!info.texture) {							\
83033170eeb185f5fe766374a749464497cdfab6931Brian Paul      /* this shouldn't happen */					\
8318e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul      return;								\
832e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }									\
83333170eeb185f5fe766374a749464497cdfab6931Brian Paul									\
83433170eeb185f5fe766374a749464497cdfab6931Brian Paul   switch (info.format) {						\
835e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   case GL_ALPHA:							\
836e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   case GL_LUMINANCE:							\
837e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   case GL_INTENSITY:							\
838230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul      info.tbytesline = obj->Image[0][b]->Width;			\
83933170eeb185f5fe766374a749464497cdfab6931Brian Paul      break;								\
840e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   case GL_LUMINANCE_ALPHA:						\
84118fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell      info.tbytesline = obj->Image[0][b]->Width * 2;			\
84233170eeb185f5fe766374a749464497cdfab6931Brian Paul      break;								\
843e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   case GL_RGB:								\
84418fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell      info.tbytesline = obj->Image[0][b]->Width * 3;			\
84533170eeb185f5fe766374a749464497cdfab6931Brian Paul      break;								\
846e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   case GL_RGBA:							\
84718fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell      info.tbytesline = obj->Image[0][b]->Width * 4;			\
84833170eeb185f5fe766374a749464497cdfab6931Brian Paul      break;								\
849e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   default:								\
850fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul      _mesa_problem(NULL, "Bad texture format in persp_textured_triangle");\
85133170eeb185f5fe766374a749464497cdfab6931Brian Paul      return;								\
85233170eeb185f5fe766374a749464497cdfab6931Brian Paul   }									\
85318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell   info.tsize = obj->Image[0][b]->Height * info.tbytesline;
854e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
8557956292a765910077f50352d7cd0174e1e66d26cBrian Paul#define RENDER_SPAN( span )			\
85677df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.interpMask &= ~SPAN_RGBA;		\
85777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   span.arrayMask |= SPAN_RGBA;			\
85877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   fast_persp_span(ctx, &span, &info);
859e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
860e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
861e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
862fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul
86396385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul#endif /* CHAN_BITS != GL_FLOAT */
86496385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul
8659bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
8669bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
8679bf68ad963ba92b5d1e725f965979042495a5313Brian Paul
8689bf68ad963ba92b5d1e725f965979042495a5313Brian Paul/*
869e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render a smooth-shaded, textured, RGBA triangle.
8709bf68ad963ba92b5d1e725f965979042495a5313Brian Paul * Interpolate S,T,R with perspective correction, w/out mipmapping.
871e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
872cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME general_textured_triangle
873e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
87454e92e8420a028f07b0971ee8aa93be9b4214579Brian Paul#define INTERP_W 1
87595e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1
876e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
877e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_RGB 1
878e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_SPEC 1
879e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_ALPHA 1
880e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_TEX 1
88145bc887da226403f2c41077e40ca38b6f60f1359Brian Paul#define RENDER_SPAN( span )   _swrast_write_texture_span(ctx, &span);
882e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
883e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
884e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
885f1e236987829393c81dc86ea19cb49eefe190317Brian Paul
886e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
887e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * This is the big one!
88831f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul * Interpolate Z, RGB, Alpha, specular, fog, and N sets of texture coordinates.
889e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Yup, it's slow.
890e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
891cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME multitextured_triangle
892e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
89354e92e8420a028f07b0971ee8aa93be9b4214579Brian Paul#define INTERP_W 1
89495e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1
895e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
896e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_RGB 1
897e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_ALPHA 1
8989bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_SPEC 1
899e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_MULTITEX 1
90045bc887da226403f2c41077e40ca38b6f60f1359Brian Paul#define RENDER_SPAN( span )   _swrast_write_texture_span(ctx, &span);
901e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
902e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
903e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
904e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
905b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul/*
906b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul * Special tri function for occlusion testing
907b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul */
908cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME occlusion_zless_triangle
909e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DO_OCCLUSION_TEST
910e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1
911e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
912b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul#define SETUP_CODE						\
913b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul   if (ctx->OcclusionResult && !ctx->Occlusion.Active) {	\
914b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul      return;							\
915cdf2da368d180205df3573697b51b8764048ad6eBrian Paul   }
9169bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define RENDER_SPAN( span )				\
9179bf68ad963ba92b5d1e725f965979042495a5313Brian Paul   GLuint i;						\
91877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul   for (i = 0; i < span.end; i++) {			\
91977df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      GLdepth z = FixedToDepth(span.z);			\
9209bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      if (z < zRow[i]) {				\
9219bf68ad963ba92b5d1e725f965979042495a5313Brian Paul         ctx->OcclusionResult = GL_TRUE;		\
922b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul         ctx->Occlusion.PassedCounter++;		\
9239bf68ad963ba92b5d1e725f965979042495a5313Brian Paul      }							\
92477df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul      span.z += span.zStep;				\
925e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
926e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h"
927e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
928cdf2da368d180205df3573697b51b8764048ad6eBrian Paul
929cdf2da368d180205df3573697b51b8764048ad6eBrian Paul
930cdf2da368d180205df3573697b51b8764048ad6eBrian Paulstatic void
931cdf2da368d180205df3573697b51b8764048ad6eBrian Paulnodraw_triangle( GLcontext *ctx,
932cdf2da368d180205df3573697b51b8764048ad6eBrian Paul                 const SWvertex *v0,
933cdf2da368d180205df3573697b51b8764048ad6eBrian Paul                 const SWvertex *v1,
934cdf2da368d180205df3573697b51b8764048ad6eBrian Paul                 const SWvertex *v2 )
93547489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell{
93647489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell   (void) (ctx && v0 && v1 && v2);
93747489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell}
938e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
939f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul
940f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul/*
941f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul * This is used when separate specular color is enabled, but not
942fa6b2fba7ad0504a63ab262f602c6f50f336ca1bBrian Paul * texturing.  We add the specular color to the primary color,
943f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul * draw the triangle, then restore the original primary color.
944f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul * Inefficient, but seldom needed.
945f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul */
94646b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwellvoid _swrast_add_spec_terms_triangle( GLcontext *ctx,
94746b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell				      const SWvertex *v0,
94846b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell				      const SWvertex *v1,
94946b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell				      const SWvertex *v2 )
95046b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell{
95146b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   SWvertex *ncv0 = (SWvertex *)v0; /* drop const qualifier */
95246b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   SWvertex *ncv1 = (SWvertex *)v1;
95346b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   SWvertex *ncv2 = (SWvertex *)v2;
954f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul#if CHAN_TYPE == GL_FLOAT
955f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   GLfloat rSum, gSum, bSum;
956f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul#else
957f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   GLint rSum, gSum, bSum;
958f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul#endif
95946b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   GLchan c[3][4];
960f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   /* save original colors */
96146b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   COPY_CHAN4( c[0], ncv0->color );
96246b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   COPY_CHAN4( c[1], ncv1->color );
96346b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   COPY_CHAN4( c[2], ncv2->color );
964f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   /* sum v0 */
965f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   rSum = ncv0->color[0] + ncv0->specular[0];
966f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   gSum = ncv0->color[1] + ncv0->specular[1];
967f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   bSum = ncv0->color[2] + ncv0->specular[2];
968f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv0->color[0] = MIN2(rSum, CHAN_MAX);
969f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv0->color[1] = MIN2(gSum, CHAN_MAX);
970f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv0->color[2] = MIN2(bSum, CHAN_MAX);
971f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   /* sum v1 */
972f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   rSum = ncv1->color[0] + ncv1->specular[0];
973f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   gSum = ncv1->color[1] + ncv1->specular[1];
974f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   bSum = ncv1->color[2] + ncv1->specular[2];
975f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv1->color[0] = MIN2(rSum, CHAN_MAX);
976f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv1->color[1] = MIN2(gSum, CHAN_MAX);
977f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv1->color[2] = MIN2(bSum, CHAN_MAX);
978f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   /* sum v2 */
979f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   rSum = ncv2->color[0] + ncv2->specular[0];
980f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   gSum = ncv2->color[1] + ncv2->specular[1];
981f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   bSum = ncv2->color[2] + ncv2->specular[2];
982f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv2->color[0] = MIN2(rSum, CHAN_MAX);
983f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv2->color[1] = MIN2(gSum, CHAN_MAX);
984f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   ncv2->color[2] = MIN2(bSum, CHAN_MAX);
985f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   /* draw */
98646b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   SWRAST_CONTEXT(ctx)->SpecTriangle( ctx, ncv0, ncv1, ncv2 );
987f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul   /* restore original colors */
98846b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   COPY_CHAN4( ncv0->color, c[0] );
98946b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell   COPY_CHAN4( ncv1->color, c[1] );
99022144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes   COPY_CHAN4( ncv2->color, c[2] );
99146b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell}
99246b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell
993e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
994e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
995e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul#ifdef DEBUG
996e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
997e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul/* record the current triangle function name */
998fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paulconst char *_mesa_triFuncName = NULL;
999e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
10002a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul#define USE(triFunc)				\
10012a182a98973edc9ecf2936b1288485bb2b3fa722Brian Pauldo {						\
10022a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul    _mesa_triFuncName = #triFunc;		\
10032a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul    /*printf("%s\n", _mesa_triFuncName);*/	\
10042a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul    swrast->Triangle = triFunc;			\
1005e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul} while (0)
1006e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
1007e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#else
1008e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
1009e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul#define USE(triFunc)  swrast->Triangle = triFunc;
1010e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
1011e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#endif
1012e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
1013e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
1014e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
1015e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
1016e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/*
1017e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Determine which triangle rendering function to use given the current
1018e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * rendering context.
1019e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell *
1020e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Please update the summary flag _SWRAST_NEW_TRIANGLE if you add or
1021e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * remove tests to this code.
1022e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */
102322144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughesvoid
1024cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell_swrast_choose_triangle( GLcontext *ctx )
1025e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{
1026cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell   SWcontext *swrast = SWRAST_CONTEXT(ctx);
1027b6bcae5698df88f7730d40004ce7ce0462e97a20Brian Paul   const GLboolean rgbmode = ctx->Visual.rgbMode;
1028e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
102938f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes   if (ctx->Polygon.CullFlag &&
103047489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell       ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) {
1031e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul      USE(nodraw_triangle);
103247489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell      return;
103347489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell   }
103447489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell
1035e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   if (ctx->RenderMode==GL_RENDER) {
1036e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
1037e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      if (ctx->Polygon.SmoothFlag) {
103845bc887da226403f2c41077e40ca38b6f60f1359Brian Paul         _swrast_set_aa_triangle_function(ctx);
1039cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell         ASSERT(swrast->Triangle);
1040e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell         return;
1041e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      }
1042e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
1043b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul      /* special case for occlusion testing */
1044b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul      if ((ctx->Depth.OcclusionTest || ctx->Occlusion.Active) &&
1045e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell          ctx->Depth.Test &&
1046e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell          ctx->Depth.Mask == GL_FALSE &&
1047e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell          ctx->Depth.Func == GL_LESS &&
1048e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell          !ctx->Stencil.Enabled) {
1049e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell         if ((rgbmode &&
105022144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes              ctx->Color.ColorMask[0] == 0 &&
105122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes              ctx->Color.ColorMask[1] == 0 &&
1052e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell              ctx->Color.ColorMask[2] == 0 &&
1053e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell              ctx->Color.ColorMask[3] == 0)
1054e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell             ||
1055e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell             (!rgbmode && ctx->Color.IndexMask == 0)) {
1056e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul            USE(occlusion_zless_triangle);
1057e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            return;
1058e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell         }
1059e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      }
1060e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell
10616d460af6af77a0d5a5b568bcd6094b98e249ba93Brian Paul      if (ctx->Texture._EnabledCoordUnits || ctx->FragmentProgram._Enabled) {
1062e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell         /* Ugh, we do a _lot_ of tests to pick the best textured tri func */
1063e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	 const struct gl_texture_object *texObj2D;
1064e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul         const struct gl_texture_image *texImg;
106538e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul         GLenum minFilter, magFilter, envMode;
106638e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul         GLint format;
1067e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul         texObj2D = ctx->Texture.Unit[0].Current2D;
106818fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell         texImg = texObj2D ? texObj2D->Image[0][texObj2D->BaseLevel] : NULL;
106938e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul         format = texImg ? texImg->TexFormat->MesaFormat : -1;
1070e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul         minFilter = texObj2D ? texObj2D->MinFilter : (GLenum) 0;
1071e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul         magFilter = texObj2D ? texObj2D->MagFilter : (GLenum) 0;
1072e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul         envMode = ctx->Texture.Unit[0].EnvMode;
1073e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul
1074c0fc0d4e5f5c246fc2459348a3d114b232d0c545Brian Paul         /* First see if we can use an optimized 2-D texture function */
107536a0a3252e1e20df69b53f70ba93bc74c4a4bf0eBrian Paul         if (ctx->Texture._EnabledCoordUnits == 1
10766d460af6af77a0d5a5b568bcd6094b98e249ba93Brian Paul             && !ctx->FragmentProgram._Enabled
10778afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul             && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT
1078e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul             && texObj2D->WrapS==GL_REPEAT
1079e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	     && texObj2D->WrapT==GL_REPEAT
1080887e2cf01a99f7fe1b7c94320b7bdbbf0d6ad2f8Brian Paul             && texObj2D->_IsPowerOfTwo
1081e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul             && texImg->Border==0
1082681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul             && texImg->Width == texImg->RowStride
108338e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul             && (format == MESA_FORMAT_RGB || format == MESA_FORMAT_RGBA)
1084e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	     && minFilter == magFilter
1085e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	     && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR
1086e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	     && ctx->Texture.Unit[0].EnvMode != GL_COMBINE_EXT) {
1087e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	    if (ctx->Hint.PerspectiveCorrection==GL_FASTEST) {
1088e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	       if (minFilter == GL_NEAREST
10899bf68ad963ba92b5d1e725f965979042495a5313Brian Paul		   && format == MESA_FORMAT_RGB
1090e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul		   && (envMode == GL_REPLACE || envMode == GL_DECAL)
10919bf68ad963ba92b5d1e725f965979042495a5313Brian Paul		   && ((swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT)
1092e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul			&& ctx->Depth.Func == GL_LESS
1093e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul			&& ctx->Depth.Mask == GL_TRUE)
10949bf68ad963ba92b5d1e725f965979042495a5313Brian Paul		       || swrast->_RasterMask == TEXTURE_BIT)
1095e6e0ba781b0a6a1b8747cae49ca622a6a61b1bf8Brian Paul		   && ctx->Polygon.StippleFlag == GL_FALSE
1096e6e0ba781b0a6a1b8747cae49ca622a6a61b1bf8Brian Paul                   && ctx->Visual.depthBits <= 16) {
10979bf68ad963ba92b5d1e725f965979042495a5313Brian Paul		  if (swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT)) {
1098e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul		     USE(simple_z_textured_triangle);
1099e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell		  }
1100e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell		  else {
1101e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul		     USE(simple_textured_triangle);
1102e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell		  }
1103e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	       }
1104e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	       else {
1105e0bafefd7ac911ec101876f4ea0d201309e841f2Brian Paul#if (CHAN_BITS == 16 || CHAN_BITS == 32)
110696385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul                  USE(general_textured_triangle);
110796385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul#else
110896385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul                  USE(affine_textured_triangle);
1109f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#endif
1110e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	       }
1111e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	    }
1112e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	    else {
1113e0bafefd7ac911ec101876f4ea0d201309e841f2Brian Paul#if (CHAN_BITS == 16 || CHAN_BITS == 32)
111496385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul               USE(general_textured_triangle);
111596385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul#else
111696385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul               USE(persp_textured_triangle);
111796385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul#endif
1118e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	    }
1119e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	 }
1120e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell         else {
112131f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul            /* general case textured triangles */
112236a0a3252e1e20df69b53f70ba93bc74c4a4bf0eBrian Paul            if (ctx->Texture._EnabledCoordUnits > 1) {
112331f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul               USE(multitextured_triangle);
1124e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            }
1125e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            else {
112631f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul               USE(general_textured_triangle);
1127e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            }
1128e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell         }
1129e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      }
1130e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      else {
113136a0a3252e1e20df69b53f70ba93bc74c4a4bf0eBrian Paul         ASSERT(!ctx->Texture._EnabledCoordUnits);
1132e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	 if (ctx->Light.ShadeModel==GL_SMOOTH) {
1133e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	    /* smooth shaded, no texturing, stippled or some raster ops */
1134e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            if (rgbmode) {
1135e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	       USE(smooth_rgba_triangle);
1136e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            }
1137e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            else {
1138e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul               USE(smooth_ci_triangle);
1139e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            }
1140e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	 }
1141e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	 else {
1142e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	    /* flat shaded, no texturing, stippled or some raster ops */
1143e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            if (rgbmode) {
1144e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul	       USE(flat_rgba_triangle);
1145e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            }
1146e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            else {
1147e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul               USE(flat_ci_triangle);
1148e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell            }
1149e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell	 }
1150e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      }
1151e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
1152e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   else if (ctx->RenderMode==GL_FEEDBACK) {
115345bc887da226403f2c41077e40ca38b6f60f1359Brian Paul      USE(_swrast_feedback_triangle);
1154e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
1155e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   else {
1156e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell      /* GL_SELECT mode */
115745bc887da226403f2c41077e40ca38b6f60f1359Brian Paul      USE(_swrast_select_triangle);
1158e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell   }
1159e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell}
1160