s_triangle.c revision 57d705d5a939180bd992cad2f24d95c329b5b28c
1e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* 2e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Mesa 3-D graphics library 357d705d5a939180bd992cad2f24d95c329b5b28cBrian Paul * Version: 6.5.2 422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * 5920023240c2fc42675f318732b43bdc6f339113cBrian Paul * Copyright (C) 1999-2006 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 39e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_aatriangle.h" 40cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell#include "s_context.h" 41cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell#include "s_feedback.h" 42e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_span.h" 43cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell#include "s_triangle.h" 449bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 459bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 4677df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul/* 4777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul * Just used for feedback mode. 4877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul */ 49230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian PaulGLboolean 50230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul_swrast_culltriangle( GLcontext *ctx, 51230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul const SWvertex *v0, 52230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul const SWvertex *v1, 53230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul const SWvertex *v2 ) 54e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{ 55cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell GLfloat ex = v1->win[0] - v0->win[0]; 56cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell GLfloat ey = v1->win[1] - v0->win[1]; 57cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell GLfloat fx = v2->win[0] - v0->win[0]; 58cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell GLfloat fy = v2->win[1] - v0->win[1]; 59e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell GLfloat c = ex*fy-ey*fx; 60e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 6187f858dd7cbca2280c983c77a239013a187c3e9aBrian Paul if (c * SWRAST_CONTEXT(ctx)->_BackfaceSign > 0) 62e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell return 0; 6322144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes 64e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell return 1; 65e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell} 66e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 67e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 6895e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul 69e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* 70e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render a flat-shaded color index triangle. 71e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */ 72cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME flat_ci_triangle 73e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1 7495e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1 75cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define SETUP_CODE \ 76cdf2da368d180205df3573697b51b8764048ad6eBrian Paul span.interpMask |= SPAN_INDEX; \ 771e4731f6443a6efdfc4e425977490ddd5387caa3Brian Paul span.index = FloatToFixed(v2->index);\ 7877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.indexStep = 0; 7945bc887da226403f2c41077e40ca38b6f60f1359Brian Paul#define RENDER_SPAN( span ) _swrast_write_index_span(ctx, &span); 8022144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes#include "s_tritemp.h" 81e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 82e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 83e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 84e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* 85e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render a smooth-shaded color index triangle. 86e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */ 87cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME smooth_ci_triangle 88e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1 8995e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1 90e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_INDEX 1 9145bc887da226403f2c41077e40ca38b6f60f1359Brian Paul#define RENDER_SPAN( span ) _swrast_write_index_span(ctx, &span); 92e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h" 93e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 94e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 95e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 96e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* 97e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render a flat-shaded RGBA triangle. 98e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */ 99cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME flat_rgba_triangle 100e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1 10195e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1 102f1e236987829393c81dc86ea19cb49eefe190317Brian Paul#define SETUP_CODE \ 10336a0a3252e1e20df69b53f70ba93bc74c4a4bf0eBrian Paul ASSERT(ctx->Texture._EnabledCoordUnits == 0);\ 1047956292a765910077f50352d7cd0174e1e66d26cBrian Paul ASSERT(ctx->Light.ShadeModel==GL_FLAT); \ 10577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.interpMask |= SPAN_RGBA; \ 10677df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.red = ChanToFixed(v2->color[0]); \ 10777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.green = ChanToFixed(v2->color[1]); \ 10877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.blue = ChanToFixed(v2->color[2]); \ 10977df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.alpha = ChanToFixed(v2->color[3]); \ 11077df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.redStep = 0; \ 11177df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.greenStep = 0; \ 11277df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.blueStep = 0; \ 11377df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.alphaStep = 0; 11445bc887da226403f2c41077e40ca38b6f60f1359Brian Paul#define RENDER_SPAN( span ) _swrast_write_rgba_span(ctx, &span); 115e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h" 116e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 117e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 118e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 119e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* 120e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render a smooth-shaded RGBA triangle. 121e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */ 122cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME smooth_rgba_triangle 123e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1 12495e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1 125e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_RGB 1 126e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_ALPHA 1 127733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul#define SETUP_CODE \ 128733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul { \ 129733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul /* texturing must be off */ \ 13036a0a3252e1e20df69b53f70ba93bc74c4a4bf0eBrian Paul ASSERT(ctx->Texture._EnabledCoordUnits == 0); \ 131733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul ASSERT(ctx->Light.ShadeModel==GL_SMOOTH); \ 132733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul } 13345bc887da226403f2c41077e40ca38b6f60f1359Brian Paul#define RENDER_SPAN( span ) _swrast_write_rgba_span(ctx, &span); 134e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h" 135e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 136e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 137e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 138e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* 139e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render an RGB, GL_DECAL, textured triangle. 140e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Interpolate S,T only w/out mipmapping or perspective correction. 141e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * 142e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * No fog. 143e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */ 144cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME simple_textured_triangle 145e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_INT_TEX 1 146e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define S_SCALE twidth 147e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define T_SCALE theight 1489bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 149e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define SETUP_CODE \ 150e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0][0];\ 151a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D; \ 1522ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul const GLint b = obj->BaseLevel; \ 15318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width; \ 15418fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell const GLfloat theight = (GLfloat) obj->Image[0][b]->Height; \ 155230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul const GLint twidth_log2 = obj->Image[0][b]->WidthLog2; \ 15618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell const GLchan *texture = (const GLchan *) obj->Image[0][b]->Data; \ 15718fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell const GLint smask = obj->Image[0][b]->Width - 1; \ 15818fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell const GLint tmask = obj->Image[0][b]->Height - 1; \ 159e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell if (!texture) { \ 1608e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* this shouldn't happen */ \ 1618e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; \ 162e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 163e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 164920023240c2fc42675f318732b43bdc6f339113cBrian Paul#define RENDER_SPAN( span ) \ 1659bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLuint i; \ 16657d705d5a939180bd992cad2f24d95c329b5b28cBrian Paul GLchan rgb[MAX_WIDTH][3]; \ 16777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.intTex[0] -= FIXED_HALF; /* off-by-one error? */ \ 16877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.intTex[1] -= FIXED_HALF; \ 16977df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul for (i = 0; i < span.end; i++) { \ 17077df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul GLint s = FixedToInt(span.intTex[0]) & smask; \ 17177df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul GLint t = FixedToInt(span.intTex[1]) & tmask; \ 1729bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLint pos = (t << twidth_log2) + s; \ 1739bf68ad963ba92b5d1e725f965979042495a5313Brian Paul pos = pos + pos + pos; /* multiply by 3 */ \ 17457d705d5a939180bd992cad2f24d95c329b5b28cBrian Paul rgb[i][RCOMP] = texture[pos]; \ 17557d705d5a939180bd992cad2f24d95c329b5b28cBrian Paul rgb[i][GCOMP] = texture[pos+1]; \ 17657d705d5a939180bd992cad2f24d95c329b5b28cBrian Paul rgb[i][BCOMP] = texture[pos+2]; \ 17777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.intTex[0] += span.intTexStep[0]; \ 17877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.intTex[1] += span.intTexStep[1]; \ 1799bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } \ 18057d705d5a939180bd992cad2f24d95c329b5b28cBrian Paul rb->PutRowRGB(ctx, rb, span.end, span.x, span.y, rgb, NULL); 181e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul 182e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h" 183cdf2da368d180205df3573697b51b8764048ad6eBrian Paul 184e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 185e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 186e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* 187e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render an RGB, GL_DECAL, textured triangle. 188e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Interpolate S,T, GL_LESS depth test, w/out mipmapping or 189e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * perspective correction. 190e6e0ba781b0a6a1b8747cae49ca622a6a61b1bf8Brian Paul * Depth buffer bits must be <= sizeof(DEFAULT_SOFTWARE_DEPTH_TYPE) 19122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * 192e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * No fog. 193e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */ 194cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME simple_z_textured_triangle 195e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1 196e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE 197e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_INT_TEX 1 198e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define S_SCALE twidth 199e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define T_SCALE theight 2009bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 201e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define SETUP_CODE \ 202e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0][0];\ 203a852378a6289d154364dde440f89a39bbfc33e2dBrian Paul struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D; \ 2042ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul const GLint b = obj->BaseLevel; \ 20518fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width; \ 20618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell const GLfloat theight = (GLfloat) obj->Image[0][b]->Height; \ 207230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul const GLint twidth_log2 = obj->Image[0][b]->WidthLog2; \ 20818fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell const GLchan *texture = (const GLchan *) obj->Image[0][b]->Data; \ 20918fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell const GLint smask = obj->Image[0][b]->Width - 1; \ 21018fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell const GLint tmask = obj->Image[0][b]->Height - 1; \ 211e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell if (!texture) { \ 2128e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul /* this shouldn't happen */ \ 2138e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; \ 214e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 215e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 216920023240c2fc42675f318732b43bdc6f339113cBrian Paul#define RENDER_SPAN( span ) \ 2179bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLuint i; \ 21857d705d5a939180bd992cad2f24d95c329b5b28cBrian Paul GLchan rgb[MAX_WIDTH][3]; \ 21977df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.intTex[0] -= FIXED_HALF; /* off-by-one error? */ \ 22077df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.intTex[1] -= FIXED_HALF; \ 22177df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul for (i = 0; i < span.end; i++) { \ 2223e37bafab0a339021354b9c78f983d05d433d735Brian Paul const GLuint z = FixedToDepth(span.z); \ 2239bf68ad963ba92b5d1e725f965979042495a5313Brian Paul if (z < zRow[i]) { \ 22477df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul GLint s = FixedToInt(span.intTex[0]) & smask; \ 22577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul GLint t = FixedToInt(span.intTex[1]) & tmask; \ 2269bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLint pos = (t << twidth_log2) + s; \ 2279bf68ad963ba92b5d1e725f965979042495a5313Brian Paul pos = pos + pos + pos; /* multiply by 3 */ \ 22857d705d5a939180bd992cad2f24d95c329b5b28cBrian Paul rgb[i][RCOMP] = texture[pos]; \ 22957d705d5a939180bd992cad2f24d95c329b5b28cBrian Paul rgb[i][GCOMP] = texture[pos+1]; \ 23057d705d5a939180bd992cad2f24d95c329b5b28cBrian Paul rgb[i][BCOMP] = texture[pos+2]; \ 2319bf68ad963ba92b5d1e725f965979042495a5313Brian Paul zRow[i] = z; \ 23277df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.array->mask[i] = 1; \ 2339bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } \ 2349bf68ad963ba92b5d1e725f965979042495a5313Brian Paul else { \ 23577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.array->mask[i] = 0; \ 2369bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } \ 23777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.intTex[0] += span.intTexStep[0]; \ 23877df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.intTex[1] += span.intTexStep[1]; \ 23977df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.z += span.zStep; \ 2409bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } \ 24157d705d5a939180bd992cad2f24d95c329b5b28cBrian Paul rb->PutRowRGB(ctx, rb, span.end, span.x, span.y, rgb, span.array->mask); 242e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul 243e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h" 244cdf2da368d180205df3573697b51b8764048ad6eBrian Paul 245e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 246e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 247f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#if CHAN_TYPE != GL_FLOAT 248e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 2499bf68ad963ba92b5d1e725f965979042495a5313Brian Paulstruct affine_info 250e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{ 2519bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLenum filter; 2529bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLenum format; 2539bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLenum envmode; 2549bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLint smask, tmask; 2559bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLint twidth_log2; 2569bf68ad963ba92b5d1e725f965979042495a5313Brian Paul const GLchan *texture; 257fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul GLfixed er, eg, eb, ea; 2589bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLint tbytesline, tsize; 2599bf68ad963ba92b5d1e725f965979042495a5313Brian Paul}; 260cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell 2617152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul 262f138b977d09327445a8e9c8126c493c4487c1630Brian Paulstatic INLINE GLint 263f138b977d09327445a8e9c8126c493c4487c1630Brian Paulilerp(GLint t, GLint a, GLint b) 264f138b977d09327445a8e9c8126c493c4487c1630Brian Paul{ 265f138b977d09327445a8e9c8126c493c4487c1630Brian Paul return a + ((t * (b - a)) >> FIXED_SHIFT); 266f138b977d09327445a8e9c8126c493c4487c1630Brian Paul} 267f138b977d09327445a8e9c8126c493c4487c1630Brian Paul 268f138b977d09327445a8e9c8126c493c4487c1630Brian Paulstatic INLINE GLint 269f138b977d09327445a8e9c8126c493c4487c1630Brian Paulilerp_2d(GLint ia, GLint ib, GLint v00, GLint v10, GLint v01, GLint v11) 270f138b977d09327445a8e9c8126c493c4487c1630Brian Paul{ 271f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLint temp0 = ilerp(ia, v00, v10); 272f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLint temp1 = ilerp(ia, v01, v11); 273f138b977d09327445a8e9c8126c493c4487c1630Brian Paul return ilerp(ib, temp0, temp1); 274f138b977d09327445a8e9c8126c493c4487c1630Brian Paul} 275f138b977d09327445a8e9c8126c493c4487c1630Brian Paul 276f138b977d09327445a8e9c8126c493c4487c1630Brian Paul 2777152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul/* This function can handle GL_NEAREST or GL_LINEAR sampling of 2D RGB or RGBA 2787152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul * textures with GL_REPLACE, GL_MODULATE, GL_BLEND, GL_DECAL or GL_ADD 2797152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul * texture env modes. 2807152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul */ 28171340e861edf35bfdeb536718cd230fc33c41ee2Brian Paulstatic INLINE void 28257d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paulaffine_span(GLcontext *ctx, struct sw_span *span, 2839bf68ad963ba92b5d1e725f965979042495a5313Brian Paul struct affine_info *info) 2849bf68ad963ba92b5d1e725f965979042495a5313Brian Paul{ 2857152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul GLchan sample[4]; /* the filtered texture sample */ 286e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 287fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul /* Instead of defining a function for each mode, a test is done 288fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul * between the outer and inner loops. This is to reduce code size 289fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul * and complexity. Observe that an optimizing compiler kills 290fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST). 291fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul */ 292e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 293bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul#define NEAREST_RGB \ 2947152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul sample[RCOMP] = tex00[RCOMP]; \ 2957152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul sample[GCOMP] = tex00[GCOMP]; \ 2967152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul sample[BCOMP] = tex00[BCOMP]; \ 2977152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul sample[ACOMP] = CHAN_MAX 298e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 2999bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define LINEAR_RGB \ 300f138b977d09327445a8e9c8126c493c4487c1630Brian Paul sample[RCOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0]);\ 301f138b977d09327445a8e9c8126c493c4487c1630Brian Paul sample[GCOMP] = ilerp_2d(sf, tf, tex00[1], tex01[1], tex10[1], tex11[1]);\ 302f138b977d09327445a8e9c8126c493c4487c1630Brian Paul sample[BCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\ 303f138b977d09327445a8e9c8126c493c4487c1630Brian Paul sample[ACOMP] = CHAN_MAX; 304bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul 3057152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul#define NEAREST_RGBA COPY_CHAN4(sample, tex00) 306e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 3079bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define LINEAR_RGBA \ 308f138b977d09327445a8e9c8126c493c4487c1630Brian Paul sample[RCOMP] = ilerp_2d(sf, tf, tex00[0], tex01[0], tex10[0], tex11[0]);\ 309f138b977d09327445a8e9c8126c493c4487c1630Brian Paul sample[GCOMP] = ilerp_2d(sf, tf, tex00[1], tex01[1], tex10[1], tex11[1]);\ 310f138b977d09327445a8e9c8126c493c4487c1630Brian Paul sample[BCOMP] = ilerp_2d(sf, tf, tex00[2], tex01[2], tex10[2], tex11[2]);\ 311f138b977d09327445a8e9c8126c493c4487c1630Brian Paul sample[ACOMP] = ilerp_2d(sf, tf, tex00[3], tex01[3], tex10[3], tex11[3]) 312bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul 313fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul#define MODULATE \ 3147152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[RCOMP] = span->red * (sample[RCOMP] + 1u) >> (FIXED_SHIFT + 8); \ 3157152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[GCOMP] = span->green * (sample[GCOMP] + 1u) >> (FIXED_SHIFT + 8); \ 3167152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[BCOMP] = span->blue * (sample[BCOMP] + 1u) >> (FIXED_SHIFT + 8); \ 3177152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[ACOMP] = span->alpha * (sample[ACOMP] + 1u) >> (FIXED_SHIFT + 8) 3189bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 3199bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define DECAL \ 3207152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[RCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->red + \ 3217152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul ((sample[ACOMP] + 1) * sample[RCOMP] << FIXED_SHIFT)) \ 322bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul >> (FIXED_SHIFT + 8); \ 3237152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[GCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->green + \ 3247152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul ((sample[ACOMP] + 1) * sample[GCOMP] << FIXED_SHIFT)) \ 325bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul >> (FIXED_SHIFT + 8); \ 3267152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[BCOMP] = ((CHAN_MAX - sample[ACOMP]) * span->blue + \ 3277152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul ((sample[ACOMP] + 1) * sample[BCOMP] << FIXED_SHIFT)) \ 328bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul >> (FIXED_SHIFT + 8); \ 329bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul dest[ACOMP] = FixedToInt(span->alpha) 3309bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 3319bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define BLEND \ 3327152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[RCOMP] = ((CHAN_MAX - sample[RCOMP]) * span->red \ 3337152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul + (sample[RCOMP] + 1) * info->er) >> (FIXED_SHIFT + 8); \ 3347152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[GCOMP] = ((CHAN_MAX - sample[GCOMP]) * span->green \ 3357152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul + (sample[GCOMP] + 1) * info->eg) >> (FIXED_SHIFT + 8); \ 3367152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[BCOMP] = ((CHAN_MAX - sample[BCOMP]) * span->blue \ 3377152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul + (sample[BCOMP] + 1) * info->eb) >> (FIXED_SHIFT + 8); \ 3387152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[ACOMP] = span->alpha * (sample[ACOMP] + 1) >> (FIXED_SHIFT + 8) 339bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul 3407152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul#define REPLACE COPY_CHAN4(dest, sample) 341e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 3429bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define ADD \ 3437152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul { \ 3447152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul GLint rSum = FixedToInt(span->red) + (GLint) sample[RCOMP]; \ 3457152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul GLint gSum = FixedToInt(span->green) + (GLint) sample[GCOMP]; \ 3467152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul GLint bSum = FixedToInt(span->blue) + (GLint) sample[BCOMP]; \ 3477152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[RCOMP] = MIN2(rSum, CHAN_MAX); \ 3487152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[GCOMP] = MIN2(gSum, CHAN_MAX); \ 3497152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[BCOMP] = MIN2(bSum, CHAN_MAX); \ 3507152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul dest[ACOMP] = span->alpha * (sample[ACOMP] + 1) >> (FIXED_SHIFT + 8); \ 3517152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul } 352e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 353e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* shortcuts */ 354e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 35535e5e89f5614ebb032479b02dec888563f829b30Brian Paul#define NEAREST_RGB_REPLACE \ 35635e5e89f5614ebb032479b02dec888563f829b30Brian Paul NEAREST_RGB; \ 35735e5e89f5614ebb032479b02dec888563f829b30Brian Paul dest[0] = sample[0]; \ 35835e5e89f5614ebb032479b02dec888563f829b30Brian Paul dest[1] = sample[1]; \ 35935e5e89f5614ebb032479b02dec888563f829b30Brian Paul dest[2] = sample[2]; \ 36035e5e89f5614ebb032479b02dec888563f829b30Brian Paul dest[3] = FixedToInt(span->alpha); 361e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 362bbf6a41d2fd4a3d54e6b5dea50bba24768c01eceBrian Paul#define NEAREST_RGBA_REPLACE COPY_CHAN4(dest, tex00) 363e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 364f138b977d09327445a8e9c8126c493c4487c1630Brian Paul#define SPAN_NEAREST(DO_TEX, COMPS) \ 36557d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul for (i = 0; i < span->end; i++) { \ 36633170eeb185f5fe766374a749464497cdfab6931Brian Paul /* Isn't it necessary to use FixedFloor below?? */ \ 3679bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLint s = FixedToInt(span->intTex[0]) & info->smask; \ 3689bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLint t = FixedToInt(span->intTex[1]) & info->tmask; \ 3699bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLint pos = (t << info->twidth_log2) + s; \ 370f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLchan *tex00 = info->texture + COMPS * pos; \ 3719bf68ad963ba92b5d1e725f965979042495a5313Brian Paul DO_TEX; \ 3729bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->red += span->redStep; \ 3739bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->green += span->greenStep; \ 3749bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->blue += span->blueStep; \ 3759bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->alpha += span->alphaStep; \ 3769bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->intTex[0] += span->intTexStep[0]; \ 3779bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->intTex[1] += span->intTexStep[1]; \ 3789bf68ad963ba92b5d1e725f965979042495a5313Brian Paul dest += 4; \ 379e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 380e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 381f138b977d09327445a8e9c8126c493c4487c1630Brian Paul#define SPAN_LINEAR(DO_TEX, COMPS) \ 38257d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul for (i = 0; i < span->end; i++) { \ 38333170eeb185f5fe766374a749464497cdfab6931Brian Paul /* Isn't it necessary to use FixedFloor below?? */ \ 384f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLint s = FixedToInt(span->intTex[0]) & info->smask; \ 385f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLint t = FixedToInt(span->intTex[1]) & info->tmask; \ 386f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLfixed sf = span->intTex[0] & FIXED_FRAC_MASK; \ 387f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLfixed tf = span->intTex[1] & FIXED_FRAC_MASK; \ 388f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLint pos = (t << info->twidth_log2) + s; \ 389f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLchan *tex00 = info->texture + COMPS * pos; \ 3909bf68ad963ba92b5d1e725f965979042495a5313Brian Paul const GLchan *tex10 = tex00 + info->tbytesline; \ 391f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLchan *tex01 = tex00 + COMPS; \ 392f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLchan *tex11 = tex10 + COMPS; \ 3939bf68ad963ba92b5d1e725f965979042495a5313Brian Paul if (t == info->tmask) { \ 3949bf68ad963ba92b5d1e725f965979042495a5313Brian Paul tex10 -= info->tsize; \ 3959bf68ad963ba92b5d1e725f965979042495a5313Brian Paul tex11 -= info->tsize; \ 3969bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } \ 3979bf68ad963ba92b5d1e725f965979042495a5313Brian Paul if (s == info->smask) { \ 3989bf68ad963ba92b5d1e725f965979042495a5313Brian Paul tex01 -= info->tbytesline; \ 3999bf68ad963ba92b5d1e725f965979042495a5313Brian Paul tex11 -= info->tbytesline; \ 4009bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } \ 4019bf68ad963ba92b5d1e725f965979042495a5313Brian Paul DO_TEX; \ 4029bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->red += span->redStep; \ 4039bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->green += span->greenStep; \ 4049bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->blue += span->blueStep; \ 4059bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->alpha += span->alphaStep; \ 4069bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->intTex[0] += span->intTexStep[0]; \ 4079bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->intTex[1] += span->intTexStep[1]; \ 4089bf68ad963ba92b5d1e725f965979042495a5313Brian Paul dest += 4; \ 409e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 410e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 4119bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 4129bf68ad963ba92b5d1e725f965979042495a5313Brian Paul GLuint i; 41377df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul GLchan *dest = span->array->rgba[0]; 41457d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul 4159bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->intTex[0] -= FIXED_HALF; 4169bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->intTex[1] -= FIXED_HALF; 4179bf68ad963ba92b5d1e725f965979042495a5313Brian Paul switch (info->filter) { 4189bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_NEAREST: 4199bf68ad963ba92b5d1e725f965979042495a5313Brian Paul switch (info->format) { 4209bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_RGB: 4219bf68ad963ba92b5d1e725f965979042495a5313Brian Paul switch (info->envmode) { 4229bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_MODULATE: 42333170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGB;MODULATE,3); 4249bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4259bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_DECAL: 4269bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_REPLACE: 42733170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGB_REPLACE,3); 4289bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4299bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_BLEND: 43033170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGB;BLEND,3); 4319bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4329bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_ADD: 43333170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGB;ADD,3); 4349bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4359bf68ad963ba92b5d1e725f965979042495a5313Brian Paul default: 4364663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul _mesa_problem(ctx, "bad tex env mode in SPAN_LINEAR"); 4374663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul return; 4389bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } 4399bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4409bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_RGBA: 4419bf68ad963ba92b5d1e725f965979042495a5313Brian Paul switch(info->envmode) { 4429bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_MODULATE: 44333170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGBA;MODULATE,4); 4449bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4459bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_DECAL: 44633170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGBA;DECAL,4); 4479bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4489bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_BLEND: 44933170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGBA;BLEND,4); 4509bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4519bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_ADD: 45233170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGBA;ADD,4); 4539bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4549bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_REPLACE: 45533170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGBA_REPLACE,4); 4569bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4579bf68ad963ba92b5d1e725f965979042495a5313Brian Paul default: 4584663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul _mesa_problem(ctx, "bad tex env mode (2) in SPAN_LINEAR"); 4594663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul return; 4609bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } 4619bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4629bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } 4639bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4649bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 4659bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_LINEAR: 4669bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->intTex[0] -= FIXED_HALF; 4679bf68ad963ba92b5d1e725f965979042495a5313Brian Paul span->intTex[1] -= FIXED_HALF; 4689bf68ad963ba92b5d1e725f965979042495a5313Brian Paul switch (info->format) { 4699bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_RGB: 4709bf68ad963ba92b5d1e725f965979042495a5313Brian Paul switch (info->envmode) { 4719bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_MODULATE: 47233170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGB;MODULATE,3); 4739bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4749bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_DECAL: 4759bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_REPLACE: 47633170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGB;REPLACE,3); 4779bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4789bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_BLEND: 47933170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGB;BLEND,3); 4809bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4819bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_ADD: 48233170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGB;ADD,3); 4839bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4849bf68ad963ba92b5d1e725f965979042495a5313Brian Paul default: 4854663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul _mesa_problem(ctx, "bad tex env mode (3) in SPAN_LINEAR"); 4864663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul return; 4879bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } 4889bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4899bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_RGBA: 4909bf68ad963ba92b5d1e725f965979042495a5313Brian Paul switch (info->envmode) { 4919bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_MODULATE: 49233170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGBA;MODULATE,4); 4939bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4949bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_DECAL: 49533170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGBA;DECAL,4); 4969bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 4979bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_BLEND: 49833170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGBA;BLEND,4); 4999bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 5009bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_ADD: 50133170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGBA;ADD,4); 5029bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 5039bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_REPLACE: 50433170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGBA;REPLACE,4); 5059bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 5069bf68ad963ba92b5d1e725f965979042495a5313Brian Paul default: 5074663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul _mesa_problem(ctx, "bad tex env mode (4) in SPAN_LINEAR"); 5084663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul return; 5094663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul } 5104663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul break; 5119bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } 5129bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; 5139bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } 514733a4b602bbbfda83ee03b7ae4f3737bbe659034Brian Paul span->interpMask &= ~SPAN_RGBA; 5152a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul ASSERT(span->arrayMask & SPAN_RGBA); 51645bc887da226403f2c41077e40ca38b6f60f1359Brian Paul _swrast_write_rgba_span(ctx, span); 517e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 51833170eeb185f5fe766374a749464497cdfab6931Brian Paul#undef SPAN_NEAREST 51933170eeb185f5fe766374a749464497cdfab6931Brian Paul#undef SPAN_LINEAR 520e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell} 521e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 522e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 523e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 524e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* 5259bf68ad963ba92b5d1e725f965979042495a5313Brian Paul * Render an RGB/RGBA textured triangle without perspective correction. 5269bf68ad963ba92b5d1e725f965979042495a5313Brian Paul */ 527cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME affine_textured_triangle 5289bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_Z 1 5299bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_FOG 1 5309bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_RGB 1 5319bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_ALPHA 1 5329bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_INT_TEX 1 5339bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define S_SCALE twidth 5349bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define T_SCALE theight 5359bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 536571c8ecc8f9442fb8bbaa1f29b1d0d4f8e5b3cadBrian Paul#define SETUP_CODE \ 537571c8ecc8f9442fb8bbaa1f29b1d0d4f8e5b3cadBrian Paul struct affine_info info; \ 5389bf68ad963ba92b5d1e725f965979042495a5313Brian Paul struct gl_texture_unit *unit = ctx->Texture.Unit+0; \ 5399bf68ad963ba92b5d1e725f965979042495a5313Brian Paul struct gl_texture_object *obj = unit->Current2D; \ 5402ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul const GLint b = obj->BaseLevel; \ 54118fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell const GLfloat twidth = (GLfloat) obj->Image[0][b]->Width; \ 54218fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell const GLfloat theight = (GLfloat) obj->Image[0][b]->Height; \ 543230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul info.texture = (const GLchan *) obj->Image[0][b]->Data; \ 544230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul info.twidth_log2 = obj->Image[0][b]->WidthLog2; \ 54518fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell info.smask = obj->Image[0][b]->Width - 1; \ 54618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell info.tmask = obj->Image[0][b]->Height - 1; \ 547a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul info.format = obj->Image[0][b]->_BaseFormat; \ 5489bf68ad963ba92b5d1e725f965979042495a5313Brian Paul info.filter = obj->MinFilter; \ 5499bf68ad963ba92b5d1e725f965979042495a5313Brian Paul info.envmode = unit->EnvMode; \ 55077df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.arrayMask |= SPAN_RGBA; \ 5519bf68ad963ba92b5d1e725f965979042495a5313Brian Paul \ 5529bf68ad963ba92b5d1e725f965979042495a5313Brian Paul if (info.envmode == GL_BLEND) { \ 5539bf68ad963ba92b5d1e725f965979042495a5313Brian Paul /* potential off-by-one error here? (1.0f -> 2048 -> 0) */ \ 554fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul info.er = FloatToFixed(unit->EnvColor[RCOMP] * CHAN_MAXF); \ 555fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul info.eg = FloatToFixed(unit->EnvColor[GCOMP] * CHAN_MAXF); \ 556fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul info.eb = FloatToFixed(unit->EnvColor[BCOMP] * CHAN_MAXF); \ 557fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul info.ea = FloatToFixed(unit->EnvColor[ACOMP] * CHAN_MAXF); \ 5589bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } \ 5599bf68ad963ba92b5d1e725f965979042495a5313Brian Paul if (!info.texture) { \ 5609bf68ad963ba92b5d1e725f965979042495a5313Brian Paul /* this shouldn't happen */ \ 5619bf68ad963ba92b5d1e725f965979042495a5313Brian Paul return; \ 5629bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } \ 5639bf68ad963ba92b5d1e725f965979042495a5313Brian Paul \ 5649bf68ad963ba92b5d1e725f965979042495a5313Brian Paul switch (info.format) { \ 5659bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_ALPHA: \ 5669bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_LUMINANCE: \ 5679bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_INTENSITY: \ 568230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul info.tbytesline = obj->Image[0][b]->Width; \ 5699bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; \ 5709bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_LUMINANCE_ALPHA: \ 57118fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell info.tbytesline = obj->Image[0][b]->Width * 2; \ 5729bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; \ 5739bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_RGB: \ 57418fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell info.tbytesline = obj->Image[0][b]->Width * 3; \ 5759bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; \ 5769bf68ad963ba92b5d1e725f965979042495a5313Brian Paul case GL_RGBA: \ 57718fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell info.tbytesline = obj->Image[0][b]->Width * 4; \ 5789bf68ad963ba92b5d1e725f965979042495a5313Brian Paul break; \ 5799bf68ad963ba92b5d1e725f965979042495a5313Brian Paul default: \ 5809bf68ad963ba92b5d1e725f965979042495a5313Brian Paul _mesa_problem(NULL, "Bad texture format in affine_texture_triangle");\ 5819bf68ad963ba92b5d1e725f965979042495a5313Brian Paul return; \ 5829bf68ad963ba92b5d1e725f965979042495a5313Brian Paul } \ 58318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell info.tsize = obj->Image[0][b]->Height * info.tbytesline; 5849bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 58577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul#define RENDER_SPAN( span ) affine_span(ctx, &span, &info); 5869bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 5879bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#include "s_tritemp.h" 5889bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 589f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul 5909bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 59133170eeb185f5fe766374a749464497cdfab6931Brian Paulstruct persp_info 592e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{ 59333170eeb185f5fe766374a749464497cdfab6931Brian Paul GLenum filter; 59433170eeb185f5fe766374a749464497cdfab6931Brian Paul GLenum format; 59533170eeb185f5fe766374a749464497cdfab6931Brian Paul GLenum envmode; 59633170eeb185f5fe766374a749464497cdfab6931Brian Paul GLint smask, tmask; 59733170eeb185f5fe766374a749464497cdfab6931Brian Paul GLint twidth_log2; 59833170eeb185f5fe766374a749464497cdfab6931Brian Paul const GLchan *texture; 599fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul GLfixed er, eg, eb, ea; /* texture env color */ 60033170eeb185f5fe766374a749464497cdfab6931Brian Paul GLint tbytesline, tsize; 60133170eeb185f5fe766374a749464497cdfab6931Brian Paul}; 602e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 603f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul 60471340e861edf35bfdeb536718cd230fc33c41ee2Brian Paulstatic INLINE void 60557d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paulfast_persp_span(GLcontext *ctx, struct sw_span *span, 60633170eeb185f5fe766374a749464497cdfab6931Brian Paul struct persp_info *info) 60733170eeb185f5fe766374a749464497cdfab6931Brian Paul{ 6087152305e0a7d963f49c05bc530e495dc3ad82e3bBrian Paul GLchan sample[4]; /* the filtered texture sample */ 6099bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 61033170eeb185f5fe766374a749464497cdfab6931Brian Paul /* Instead of defining a function for each mode, a test is done 61133170eeb185f5fe766374a749464497cdfab6931Brian Paul * between the outer and inner loops. This is to reduce code size 61233170eeb185f5fe766374a749464497cdfab6931Brian Paul * and complexity. Observe that an optimizing compiler kills 61333170eeb185f5fe766374a749464497cdfab6931Brian Paul * unused variables (for instance tf,sf,ti,si in case of GL_NEAREST). 61433170eeb185f5fe766374a749464497cdfab6931Brian Paul */ 61533170eeb185f5fe766374a749464497cdfab6931Brian Paul#define SPAN_NEAREST(DO_TEX,COMP) \ 61657d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul for (i = 0; i < span->end; i++) { \ 61733170eeb185f5fe766374a749464497cdfab6931Brian Paul GLdouble invQ = tex_coord[2] ? \ 61833170eeb185f5fe766374a749464497cdfab6931Brian Paul (1.0 / tex_coord[2]) : 1.0; \ 6197c4268176eaaeb45003db4d5042a518b84c9f6dcKarl Schultz GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ); \ 6207c4268176eaaeb45003db4d5042a518b84c9f6dcKarl Schultz GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ); \ 62133170eeb185f5fe766374a749464497cdfab6931Brian Paul GLint s = IFLOOR(s_tmp) & info->smask; \ 62233170eeb185f5fe766374a749464497cdfab6931Brian Paul GLint t = IFLOOR(t_tmp) & info->tmask; \ 62333170eeb185f5fe766374a749464497cdfab6931Brian Paul GLint pos = (t << info->twidth_log2) + s; \ 62433170eeb185f5fe766374a749464497cdfab6931Brian Paul const GLchan *tex00 = info->texture + COMP * pos; \ 62533170eeb185f5fe766374a749464497cdfab6931Brian Paul DO_TEX; \ 62633170eeb185f5fe766374a749464497cdfab6931Brian Paul span->red += span->redStep; \ 62733170eeb185f5fe766374a749464497cdfab6931Brian Paul span->green += span->greenStep; \ 62833170eeb185f5fe766374a749464497cdfab6931Brian Paul span->blue += span->blueStep; \ 62933170eeb185f5fe766374a749464497cdfab6931Brian Paul span->alpha += span->alphaStep; \ 63033170eeb185f5fe766374a749464497cdfab6931Brian Paul tex_coord[0] += tex_step[0]; \ 63133170eeb185f5fe766374a749464497cdfab6931Brian Paul tex_coord[1] += tex_step[1]; \ 63233170eeb185f5fe766374a749464497cdfab6931Brian Paul tex_coord[2] += tex_step[2]; \ 63333170eeb185f5fe766374a749464497cdfab6931Brian Paul dest += 4; \ 63433170eeb185f5fe766374a749464497cdfab6931Brian Paul } 635e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 63633170eeb185f5fe766374a749464497cdfab6931Brian Paul#define SPAN_LINEAR(DO_TEX,COMP) \ 63757d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul for (i = 0; i < span->end; i++) { \ 63833170eeb185f5fe766374a749464497cdfab6931Brian Paul GLdouble invQ = tex_coord[2] ? \ 63933170eeb185f5fe766374a749464497cdfab6931Brian Paul (1.0 / tex_coord[2]) : 1.0; \ 640f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLfloat s_tmp = (GLfloat) (tex_coord[0] * invQ); \ 641f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLfloat t_tmp = (GLfloat) (tex_coord[1] * invQ); \ 642f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLfixed s_fix = FloatToFixed(s_tmp) - FIXED_HALF; \ 643f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLfixed t_fix = FloatToFixed(t_tmp) - FIXED_HALF; \ 644f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLint s = FixedToInt(FixedFloor(s_fix)) & info->smask; \ 645f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLint t = FixedToInt(FixedFloor(t_fix)) & info->tmask; \ 646f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLfixed sf = s_fix & FIXED_FRAC_MASK; \ 647f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLfixed tf = t_fix & FIXED_FRAC_MASK; \ 648f138b977d09327445a8e9c8126c493c4487c1630Brian Paul const GLint pos = (t << info->twidth_log2) + s; \ 64933170eeb185f5fe766374a749464497cdfab6931Brian Paul const GLchan *tex00 = info->texture + COMP * pos; \ 65033170eeb185f5fe766374a749464497cdfab6931Brian Paul const GLchan *tex10 = tex00 + info->tbytesline; \ 65133170eeb185f5fe766374a749464497cdfab6931Brian Paul const GLchan *tex01 = tex00 + COMP; \ 65233170eeb185f5fe766374a749464497cdfab6931Brian Paul const GLchan *tex11 = tex10 + COMP; \ 65333170eeb185f5fe766374a749464497cdfab6931Brian Paul if (t == info->tmask) { \ 65433170eeb185f5fe766374a749464497cdfab6931Brian Paul tex10 -= info->tsize; \ 65533170eeb185f5fe766374a749464497cdfab6931Brian Paul tex11 -= info->tsize; \ 65633170eeb185f5fe766374a749464497cdfab6931Brian Paul } \ 65733170eeb185f5fe766374a749464497cdfab6931Brian Paul if (s == info->smask) { \ 65833170eeb185f5fe766374a749464497cdfab6931Brian Paul tex01 -= info->tbytesline; \ 65933170eeb185f5fe766374a749464497cdfab6931Brian Paul tex11 -= info->tbytesline; \ 66033170eeb185f5fe766374a749464497cdfab6931Brian Paul } \ 66133170eeb185f5fe766374a749464497cdfab6931Brian Paul DO_TEX; \ 66233170eeb185f5fe766374a749464497cdfab6931Brian Paul span->red += span->redStep; \ 66333170eeb185f5fe766374a749464497cdfab6931Brian Paul span->green += span->greenStep; \ 66433170eeb185f5fe766374a749464497cdfab6931Brian Paul span->blue += span->blueStep; \ 66533170eeb185f5fe766374a749464497cdfab6931Brian Paul span->alpha += span->alphaStep; \ 66633170eeb185f5fe766374a749464497cdfab6931Brian Paul tex_coord[0] += tex_step[0]; \ 66733170eeb185f5fe766374a749464497cdfab6931Brian Paul tex_coord[1] += tex_step[1]; \ 66833170eeb185f5fe766374a749464497cdfab6931Brian Paul tex_coord[2] += tex_step[2]; \ 66933170eeb185f5fe766374a749464497cdfab6931Brian Paul dest += 4; \ 67033170eeb185f5fe766374a749464497cdfab6931Brian Paul } 671e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 67233170eeb185f5fe766374a749464497cdfab6931Brian Paul GLuint i; 67333170eeb185f5fe766374a749464497cdfab6931Brian Paul GLfloat tex_coord[3], tex_step[3]; 67477df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul GLchan *dest = span->array->rgba[0]; 67557d6e1aebf1f850686a2c8d3a246fb388ec23979Brian Paul 676a803b0c891404dcd7c376e91f6a033cd4e42abc3Brian Paul const GLuint savedTexEnable = ctx->Texture._EnabledUnits; 677a803b0c891404dcd7c376e91f6a033cd4e42abc3Brian Paul ctx->Texture._EnabledUnits = 0; 678a803b0c891404dcd7c376e91f6a033cd4e42abc3Brian Paul 67931f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul tex_coord[0] = span->tex[0][0] * (info->smask + 1); 68031f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul tex_step[0] = span->texStepX[0][0] * (info->smask + 1); 68131f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul tex_coord[1] = span->tex[0][1] * (info->tmask + 1); 68231f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul tex_step[1] = span->texStepX[0][1] * (info->tmask + 1); 68333170eeb185f5fe766374a749464497cdfab6931Brian Paul /* span->tex[0][2] only if 3D-texturing, here only 2D */ 68431f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul tex_coord[2] = span->tex[0][3]; 68531f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul tex_step[2] = span->texStepX[0][3]; 686e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 68733170eeb185f5fe766374a749464497cdfab6931Brian Paul switch (info->filter) { 68833170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_NEAREST: 68933170eeb185f5fe766374a749464497cdfab6931Brian Paul switch (info->format) { 69033170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_RGB: 69133170eeb185f5fe766374a749464497cdfab6931Brian Paul switch (info->envmode) { 69233170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_MODULATE: 69333170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGB;MODULATE,3); 69433170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 69533170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_DECAL: 69633170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_REPLACE: 69733170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGB_REPLACE,3); 69833170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 69933170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_BLEND: 70033170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGB;BLEND,3); 70133170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 70233170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_ADD: 70333170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGB;ADD,3); 70433170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 70533170eeb185f5fe766374a749464497cdfab6931Brian Paul default: 7064663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul _mesa_problem(ctx, "bad tex env mode (5) in SPAN_LINEAR"); 7074663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul return; 70833170eeb185f5fe766374a749464497cdfab6931Brian Paul } 70933170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 71033170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_RGBA: 71133170eeb185f5fe766374a749464497cdfab6931Brian Paul switch(info->envmode) { 71233170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_MODULATE: 71333170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGBA;MODULATE,4); 71433170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 71533170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_DECAL: 71633170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGBA;DECAL,4); 71733170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 71833170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_BLEND: 71933170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGBA;BLEND,4); 72033170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 72133170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_ADD: 72233170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGBA;ADD,4); 72333170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 72433170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_REPLACE: 72533170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_NEAREST(NEAREST_RGBA_REPLACE,4); 72633170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 72733170eeb185f5fe766374a749464497cdfab6931Brian Paul default: 7284663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul _mesa_problem(ctx, "bad tex env mode (6) in SPAN_LINEAR"); 7294663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul return; 73033170eeb185f5fe766374a749464497cdfab6931Brian Paul } 73133170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 73233170eeb185f5fe766374a749464497cdfab6931Brian Paul } 73333170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 73433170eeb185f5fe766374a749464497cdfab6931Brian Paul 73533170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_LINEAR: 73633170eeb185f5fe766374a749464497cdfab6931Brian Paul switch (info->format) { 73733170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_RGB: 73833170eeb185f5fe766374a749464497cdfab6931Brian Paul switch (info->envmode) { 73933170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_MODULATE: 74033170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGB;MODULATE,3); 74133170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 74233170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_DECAL: 74333170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_REPLACE: 74433170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGB;REPLACE,3); 74533170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 74633170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_BLEND: 74733170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGB;BLEND,3); 74833170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 74933170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_ADD: 75033170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGB;ADD,3); 75133170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 75233170eeb185f5fe766374a749464497cdfab6931Brian Paul default: 7534663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul _mesa_problem(ctx, "bad tex env mode (7) in SPAN_LINEAR"); 7544663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul return; 75533170eeb185f5fe766374a749464497cdfab6931Brian Paul } 75633170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 75733170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_RGBA: 75833170eeb185f5fe766374a749464497cdfab6931Brian Paul switch (info->envmode) { 75933170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_MODULATE: 76033170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGBA;MODULATE,4); 76133170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 76233170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_DECAL: 76333170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGBA;DECAL,4); 76433170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 76533170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_BLEND: 76633170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGBA;BLEND,4); 76733170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 76833170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_ADD: 76933170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGBA;ADD,4); 77033170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 77133170eeb185f5fe766374a749464497cdfab6931Brian Paul case GL_REPLACE: 77233170eeb185f5fe766374a749464497cdfab6931Brian Paul SPAN_LINEAR(LINEAR_RGBA;REPLACE,4); 77333170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 77433170eeb185f5fe766374a749464497cdfab6931Brian Paul default: 7754663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul _mesa_problem(ctx, "bad tex env mode (8) in SPAN_LINEAR"); 7764663bd50f1e2f219bd1b2a4d902b11b936512398Brian Paul return; 77733170eeb185f5fe766374a749464497cdfab6931Brian Paul } 77833170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 77933170eeb185f5fe766374a749464497cdfab6931Brian Paul } 78033170eeb185f5fe766374a749464497cdfab6931Brian Paul break; 781e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 78233170eeb185f5fe766374a749464497cdfab6931Brian Paul 7832a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul ASSERT(span->arrayMask & SPAN_RGBA); 78445bc887da226403f2c41077e40ca38b6f60f1359Brian Paul _swrast_write_rgba_span(ctx, span); 785e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 78633170eeb185f5fe766374a749464497cdfab6931Brian Paul#undef SPAN_NEAREST 78733170eeb185f5fe766374a749464497cdfab6931Brian Paul#undef SPAN_LINEAR 788a803b0c891404dcd7c376e91f6a033cd4e42abc3Brian Paul 789a803b0c891404dcd7c376e91f6a033cd4e42abc3Brian Paul /* restore state */ 790a803b0c891404dcd7c376e91f6a033cd4e42abc3Brian Paul ctx->Texture._EnabledUnits = savedTexEnable; 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 INTERP_RGB 1 805e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_ALPHA 1 806e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_TEX 1 8079bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 808571c8ecc8f9442fb8bbaa1f29b1d0d4f8e5b3cadBrian Paul#define SETUP_CODE \ 809571c8ecc8f9442fb8bbaa1f29b1d0d4f8e5b3cadBrian Paul struct persp_info info; \ 8102ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul const struct gl_texture_unit *unit = ctx->Texture.Unit+0; \ 8112ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul const struct gl_texture_object *obj = unit->Current2D; \ 8122ef866d1fc0a5cc5ef8543d65744dfd4da4dbbafBrian Paul const GLint b = obj->BaseLevel; \ 813230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul info.texture = (const GLchan *) obj->Image[0][b]->Data; \ 814230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul info.twidth_log2 = obj->Image[0][b]->WidthLog2; \ 81518fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell info.smask = obj->Image[0][b]->Width - 1; \ 81618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell info.tmask = obj->Image[0][b]->Height - 1; \ 817a9fc8ba756dd25a07dc19058fe60f65bda82a055Brian Paul info.format = obj->Image[0][b]->_BaseFormat; \ 81833170eeb185f5fe766374a749464497cdfab6931Brian Paul info.filter = obj->MinFilter; \ 81933170eeb185f5fe766374a749464497cdfab6931Brian Paul info.envmode = unit->EnvMode; \ 82033170eeb185f5fe766374a749464497cdfab6931Brian Paul \ 82133170eeb185f5fe766374a749464497cdfab6931Brian Paul if (info.envmode == GL_BLEND) { \ 82233170eeb185f5fe766374a749464497cdfab6931Brian Paul /* potential off-by-one error here? (1.0f -> 2048 -> 0) */ \ 823fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul info.er = FloatToFixed(unit->EnvColor[RCOMP] * CHAN_MAXF); \ 824fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul info.eg = FloatToFixed(unit->EnvColor[GCOMP] * CHAN_MAXF); \ 825fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul info.eb = FloatToFixed(unit->EnvColor[BCOMP] * CHAN_MAXF); \ 826fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paul info.ea = FloatToFixed(unit->EnvColor[ACOMP] * CHAN_MAXF); \ 82733170eeb185f5fe766374a749464497cdfab6931Brian Paul } \ 82833170eeb185f5fe766374a749464497cdfab6931Brian Paul if (!info.texture) { \ 82933170eeb185f5fe766374a749464497cdfab6931Brian Paul /* this shouldn't happen */ \ 8308e39ad2cd67d49be40ff0822f3269affdf83d601Brian Paul return; \ 831e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } \ 83233170eeb185f5fe766374a749464497cdfab6931Brian Paul \ 83333170eeb185f5fe766374a749464497cdfab6931Brian Paul switch (info.format) { \ 834e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell case GL_ALPHA: \ 835e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell case GL_LUMINANCE: \ 836e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell case GL_INTENSITY: \ 837230ebaff2aecdd9f2bf667889d54bfc3dd032bbeBrian Paul info.tbytesline = obj->Image[0][b]->Width; \ 83833170eeb185f5fe766374a749464497cdfab6931Brian Paul break; \ 839e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell case GL_LUMINANCE_ALPHA: \ 84018fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell info.tbytesline = obj->Image[0][b]->Width * 2; \ 84133170eeb185f5fe766374a749464497cdfab6931Brian Paul break; \ 842e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell case GL_RGB: \ 84318fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell info.tbytesline = obj->Image[0][b]->Width * 3; \ 84433170eeb185f5fe766374a749464497cdfab6931Brian Paul break; \ 845e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell case GL_RGBA: \ 84618fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell info.tbytesline = obj->Image[0][b]->Width * 4; \ 84733170eeb185f5fe766374a749464497cdfab6931Brian Paul break; \ 848e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell default: \ 849fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul _mesa_problem(NULL, "Bad texture format in persp_textured_triangle");\ 85033170eeb185f5fe766374a749464497cdfab6931Brian Paul return; \ 85133170eeb185f5fe766374a749464497cdfab6931Brian Paul } \ 85218fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell info.tsize = obj->Image[0][b]->Height * info.tbytesline; 853e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 8547956292a765910077f50352d7cd0174e1e66d26cBrian Paul#define RENDER_SPAN( span ) \ 85577df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.interpMask &= ~SPAN_RGBA; \ 85677df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul span.arrayMask |= SPAN_RGBA; \ 85777df88727cb0a423dd5cb41498c2302d9df4fce7Brian Paul fast_persp_span(ctx, &span, &info); 858e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 859e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h" 860e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 861fae7b778b81b686ef419f971064b5fe12fb4ead3Brian Paul 86296385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul#endif /* CHAN_BITS != GL_FLOAT */ 86396385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul 8649bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 8659bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 8669bf68ad963ba92b5d1e725f965979042495a5313Brian Paul 8679bf68ad963ba92b5d1e725f965979042495a5313Brian Paul/* 868e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Render a smooth-shaded, textured, RGBA triangle. 8699bf68ad963ba92b5d1e725f965979042495a5313Brian Paul * Interpolate S,T,R with perspective correction, w/out mipmapping. 870e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */ 871cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME general_textured_triangle 872e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1 87354e92e8420a028f07b0971ee8aa93be9b4214579Brian Paul#define INTERP_W 1 87495e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1 875e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_RGB 1 876e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_SPEC 1 877e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_ALPHA 1 878e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_TEX 1 879a803b0c891404dcd7c376e91f6a033cd4e42abc3Brian Paul#define RENDER_SPAN( span ) _swrast_write_rgba_span(ctx, &span); 880e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h" 881e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 882e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 883f1e236987829393c81dc86ea19cb49eefe190317Brian Paul 884e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* 885e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * This is the big one! 886b7339d70237ffb460f158c61860ca225fec02e81Michal Krol * Interpolate Z, RGB, Alpha, specular, fog, N sets of texture coordinates, and varying floats. 887e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Yup, it's slow. 888e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */ 889cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME multitextured_triangle 890e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1 89154e92e8420a028f07b0971ee8aa93be9b4214579Brian Paul#define INTERP_W 1 89295e02a210ed339ad20b0c16284dcdcf9af2dc755Brian Paul#define INTERP_FOG 1 893e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_RGB 1 894e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_ALPHA 1 8959bf68ad963ba92b5d1e725f965979042495a5313Brian Paul#define INTERP_SPEC 1 8966acf1e93a291511cfb20b0e2aeda6e71ceb62a62Michal Krol#define INTERP_MULTITEX 1 897b7339d70237ffb460f158c61860ca225fec02e81Michal Krol#define INTERP_VARYING 1 898a803b0c891404dcd7c376e91f6a033cd4e42abc3Brian Paul#define RENDER_SPAN( span ) _swrast_write_rgba_span(ctx, &span); 899e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h" 900e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 901e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 902e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 903b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul/* 904b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul * Special tri function for occlusion testing 905b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul */ 906cdf2da368d180205df3573697b51b8764048ad6eBrian Paul#define NAME occlusion_zless_triangle 907e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#define INTERP_Z 1 90823ffc3a85d6172f8a98d17d7f23610bab808d84eBrian Paul#define SETUP_CODE \ 9091a5f1bdb428ea3ded1e77796590014f89fe78f77Brian Paul struct gl_renderbuffer *rb = ctx->DrawBuffer->_DepthBuffer; \ 91023ffc3a85d6172f8a98d17d7f23610bab808d84eBrian Paul struct gl_query_object *q = ctx->Query.CurrentOcclusionObject; \ 91123ffc3a85d6172f8a98d17d7f23610bab808d84eBrian Paul ASSERT(ctx->Depth.Test); \ 91223ffc3a85d6172f8a98d17d7f23610bab808d84eBrian Paul ASSERT(!ctx->Depth.Mask); \ 91323ffc3a85d6172f8a98d17d7f23610bab808d84eBrian Paul ASSERT(ctx->Depth.Func == GL_LESS); \ 91423ffc3a85d6172f8a98d17d7f23610bab808d84eBrian Paul if (!q) { \ 91523ffc3a85d6172f8a98d17d7f23610bab808d84eBrian Paul return; \ 916cdf2da368d180205df3573697b51b8764048ad6eBrian Paul } 9170349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul#define RENDER_SPAN( span ) \ 9189c4fd26bcab7e4a5bd97a56deff89b8ea0ae5f1dBrian Paul if (rb->DepthBits <= 16) { \ 9190349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul GLuint i; \ 9200349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul const GLushort *zRow = (const GLushort *) \ 921e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul rb->GetPointer(ctx, rb, span.x, span.y); \ 9220349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul for (i = 0; i < span.end; i++) { \ 9233e37bafab0a339021354b9c78f983d05d433d735Brian Paul GLuint z = FixedToDepth(span.z); \ 9240349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul if (z < zRow[i]) { \ 92523ffc3a85d6172f8a98d17d7f23610bab808d84eBrian Paul q->Result++; \ 9260349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul } \ 9270349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul span.z += span.zStep; \ 9280349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul } \ 9290349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul } \ 9300349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul else { \ 9310349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul GLuint i; \ 9320349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul const GLuint *zRow = (const GLuint *) \ 933e4b2356c07d31fbeeabb13b2fb47db703b473080Brian Paul rb->GetPointer(ctx, rb, span.x, span.y); \ 9340349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul for (i = 0; i < span.end; i++) { \ 935a6c423d95663cfd8601cf84e10e8e1b12fa6ef15Brian Paul if ((GLuint)span.z < zRow[i]) { \ 93623ffc3a85d6172f8a98d17d7f23610bab808d84eBrian Paul q->Result++; \ 9370349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul } \ 9380349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul span.z += span.zStep; \ 9390349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul } \ 940e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 941e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#include "s_tritemp.h" 942e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 943cdf2da368d180205df3573697b51b8764048ad6eBrian Paul 944cdf2da368d180205df3573697b51b8764048ad6eBrian Paul 945cdf2da368d180205df3573697b51b8764048ad6eBrian Paulstatic void 946cdf2da368d180205df3573697b51b8764048ad6eBrian Paulnodraw_triangle( GLcontext *ctx, 947cdf2da368d180205df3573697b51b8764048ad6eBrian Paul const SWvertex *v0, 948cdf2da368d180205df3573697b51b8764048ad6eBrian Paul const SWvertex *v1, 949cdf2da368d180205df3573697b51b8764048ad6eBrian Paul const SWvertex *v2 ) 95047489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell{ 95147489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell (void) (ctx && v0 && v1 && v2); 95247489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell} 953e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 954f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul 955f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul/* 956f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul * This is used when separate specular color is enabled, but not 957fa6b2fba7ad0504a63ab262f602c6f50f336ca1bBrian Paul * texturing. We add the specular color to the primary color, 958f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul * draw the triangle, then restore the original primary color. 959f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul * Inefficient, but seldom needed. 960f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul */ 96146b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwellvoid _swrast_add_spec_terms_triangle( GLcontext *ctx, 96246b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell const SWvertex *v0, 96346b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell const SWvertex *v1, 96446b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell const SWvertex *v2 ) 96546b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell{ 96646b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell SWvertex *ncv0 = (SWvertex *)v0; /* drop const qualifier */ 96746b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell SWvertex *ncv1 = (SWvertex *)v1; 96846b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell SWvertex *ncv2 = (SWvertex *)v2; 969f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul#if CHAN_TYPE == GL_FLOAT 970f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul GLfloat rSum, gSum, bSum; 971f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul#else 972f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul GLint rSum, gSum, bSum; 973f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul#endif 97446b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell GLchan c[3][4]; 975f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul /* save original colors */ 97646b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell COPY_CHAN4( c[0], ncv0->color ); 97746b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell COPY_CHAN4( c[1], ncv1->color ); 97846b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell COPY_CHAN4( c[2], ncv2->color ); 979f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul /* sum v0 */ 980f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul rSum = ncv0->color[0] + ncv0->specular[0]; 981f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul gSum = ncv0->color[1] + ncv0->specular[1]; 982f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul bSum = ncv0->color[2] + ncv0->specular[2]; 983f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul ncv0->color[0] = MIN2(rSum, CHAN_MAX); 984f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul ncv0->color[1] = MIN2(gSum, CHAN_MAX); 985f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul ncv0->color[2] = MIN2(bSum, CHAN_MAX); 986f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul /* sum v1 */ 987f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul rSum = ncv1->color[0] + ncv1->specular[0]; 988f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul gSum = ncv1->color[1] + ncv1->specular[1]; 989f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul bSum = ncv1->color[2] + ncv1->specular[2]; 990f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul ncv1->color[0] = MIN2(rSum, CHAN_MAX); 991f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul ncv1->color[1] = MIN2(gSum, CHAN_MAX); 992f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul ncv1->color[2] = MIN2(bSum, CHAN_MAX); 993f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul /* sum v2 */ 994f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul rSum = ncv2->color[0] + ncv2->specular[0]; 995f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul gSum = ncv2->color[1] + ncv2->specular[1]; 996f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul bSum = ncv2->color[2] + ncv2->specular[2]; 997f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul ncv2->color[0] = MIN2(rSum, CHAN_MAX); 998f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul ncv2->color[1] = MIN2(gSum, CHAN_MAX); 999f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul ncv2->color[2] = MIN2(bSum, CHAN_MAX); 1000f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul /* draw */ 100146b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell SWRAST_CONTEXT(ctx)->SpecTriangle( ctx, ncv0, ncv1, ncv2 ); 1002f47efb5ab32534fc5c42b5bc88a6b24cb514ce53Brian Paul /* restore original colors */ 100346b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell COPY_CHAN4( ncv0->color, c[0] ); 100446b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell COPY_CHAN4( ncv1->color, c[1] ); 100522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes COPY_CHAN4( ncv2->color, c[2] ); 100646b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell} 100746b0988c673b28e072fd0cbf477632a9ab6f9f18Keith Whitwell 1008e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 1009e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 1010e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul#ifdef DEBUG 1011e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul 1012e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul/* record the current triangle function name */ 1013fd1727bd1064ee2323c924cb4002d4d9a89780bfBrian Paulconst char *_mesa_triFuncName = NULL; 1014e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul 10152a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul#define USE(triFunc) \ 10162a182a98973edc9ecf2936b1288485bb2b3fa722Brian Pauldo { \ 10172a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul _mesa_triFuncName = #triFunc; \ 10182a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul /*printf("%s\n", _mesa_triFuncName);*/ \ 10192a182a98973edc9ecf2936b1288485bb2b3fa722Brian Paul swrast->Triangle = triFunc; \ 1020e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul} while (0) 1021e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul 1022e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#else 1023e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul 1024e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul#define USE(triFunc) swrast->Triangle = triFunc; 1025e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul 1026e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell#endif 1027e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 1028e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 1029e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 1030e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul 1031e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell/* 1032e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Determine which triangle rendering function to use given the current 1033e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * rendering context. 1034e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * 1035e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * Please update the summary flag _SWRAST_NEW_TRIANGLE if you add or 1036e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell * remove tests to this code. 1037e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell */ 103822144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughesvoid 1039cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell_swrast_choose_triangle( GLcontext *ctx ) 1040e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell{ 1041cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell SWcontext *swrast = SWRAST_CONTEXT(ctx); 1042b6bcae5698df88f7730d40004ce7ce0462e97a20Brian Paul const GLboolean rgbmode = ctx->Visual.rgbMode; 1043e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 104438f28665bf9fb5b2464738ca5074848ec2777ae1Gareth Hughes if (ctx->Polygon.CullFlag && 104547489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) { 1046e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul USE(nodraw_triangle); 104747489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell return; 104847489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell } 104947489c0721348d8f5e5f17b4af63b1c601045116Keith Whitwell 1050e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell if (ctx->RenderMode==GL_RENDER) { 1051e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 1052e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell if (ctx->Polygon.SmoothFlag) { 105345bc887da226403f2c41077e40ca38b6f60f1359Brian Paul _swrast_set_aa_triangle_function(ctx); 1054cd03ed4f54444d96e4e47cdb118a3dfd94d92bb0Keith Whitwell ASSERT(swrast->Triangle); 1055e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell return; 1056e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1057e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 1058b17a722ca3989e8563ee04cb2939f4835f8a171eBrian Paul /* special case for occlusion testing */ 105923ffc3a85d6172f8a98d17d7f23610bab808d84eBrian Paul if (ctx->Query.CurrentOcclusionObject && 1060e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell ctx->Depth.Test && 1061e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell ctx->Depth.Mask == GL_FALSE && 1062e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell ctx->Depth.Func == GL_LESS && 1063e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell !ctx->Stencil.Enabled) { 1064e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell if ((rgbmode && 106522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes ctx->Color.ColorMask[0] == 0 && 106622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes ctx->Color.ColorMask[1] == 0 && 1067e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell ctx->Color.ColorMask[2] == 0 && 1068e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell ctx->Color.ColorMask[3] == 0) 1069e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell || 1070e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell (!rgbmode && ctx->Color.IndexMask == 0)) { 1071e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul USE(occlusion_zless_triangle); 1072e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell return; 1073e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1074e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1075e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell 10766acf1e93a291511cfb20b0e2aeda6e71ceb62a62Michal Krol if (ctx->Texture._EnabledCoordUnits || ctx->FragmentProgram._Active || 1077b7339d70237ffb460f158c61860ca225fec02e81Michal Krol ctx->ATIFragmentShader._Enabled || ctx->ShaderObjects._FragmentShaderPresent) { 1078e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell /* Ugh, we do a _lot_ of tests to pick the best textured tri func */ 1079b7339d70237ffb460f158c61860ca225fec02e81Michal Krol const struct gl_texture_object *texObj2D; 1080e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul const struct gl_texture_image *texImg; 108138e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul GLenum minFilter, magFilter, envMode; 108238e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul GLint format; 1083e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul texObj2D = ctx->Texture.Unit[0].Current2D; 108418fa367ac6e035341f5eb86ecc4231124b2921e3Keith Whitwell texImg = texObj2D ? texObj2D->Image[0][texObj2D->BaseLevel] : NULL; 108538e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul format = texImg ? texImg->TexFormat->MesaFormat : -1; 1086e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul minFilter = texObj2D ? texObj2D->MinFilter : (GLenum) 0; 1087e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul magFilter = texObj2D ? texObj2D->MagFilter : (GLenum) 0; 1088e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul envMode = ctx->Texture.Unit[0].EnvMode; 1089e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul 1090c0fc0d4e5f5c246fc2459348a3d114b232d0c545Brian Paul /* First see if we can use an optimized 2-D texture function */ 10910349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul if (ctx->Texture._EnabledCoordUnits == 0x1 109247b29f511a8e917c65536fde90397d54d2ad23d3Keith Whitwell && !ctx->FragmentProgram._Active 10936acf1e93a291511cfb20b0e2aeda6e71ceb62a62Michal Krol && !ctx->ATIFragmentShader._Enabled 1094b7339d70237ffb460f158c61860ca225fec02e81Michal Krol && !ctx->ShaderObjects._FragmentShaderPresent 10958afe7de8deaf3c9613fd68b344de8c52b02b1879Brian Paul && ctx->Texture.Unit[0]._ReallyEnabled == TEXTURE_2D_BIT 10960349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul && texObj2D->WrapS == GL_REPEAT 1097b7339d70237ffb460f158c61860ca225fec02e81Michal Krol && texObj2D->WrapT == GL_REPEAT 109806f606ce5761e673fca3f6b1f7dd40dace8a9906Brian Paul && texImg->_IsPowerOfTwo 10990349b4b2abac65f67a638a9f8bb5d1a3d48ddf95Brian Paul && texImg->Border == 0 1100681b8c9d1ba06c8c82e687a5ced369b72e6b1eb9Brian Paul && texImg->Width == texImg->RowStride 110138e3675d7dc6c373366e576e3ca1a1eb966e4dacBrian Paul && (format == MESA_FORMAT_RGB || format == MESA_FORMAT_RGBA) 1102b7339d70237ffb460f158c61860ca225fec02e81Michal Krol && minFilter == magFilter 1103b7339d70237ffb460f158c61860ca225fec02e81Michal Krol && ctx->Light.Model.ColorControl == GL_SINGLE_COLOR 1104b7339d70237ffb460f158c61860ca225fec02e81Michal Krol && ctx->Texture.Unit[0].EnvMode != GL_COMBINE_EXT) { 1105e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell if (ctx->Hint.PerspectiveCorrection==GL_FASTEST) { 1106e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul if (minFilter == GL_NEAREST 11079bf68ad963ba92b5d1e725f965979042495a5313Brian Paul && format == MESA_FORMAT_RGB 1108e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul && (envMode == GL_REPLACE || envMode == GL_DECAL) 11099bf68ad963ba92b5d1e725f965979042495a5313Brian Paul && ((swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT) 1110e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul && ctx->Depth.Func == GL_LESS 1111e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul && ctx->Depth.Mask == GL_TRUE) 11129bf68ad963ba92b5d1e725f965979042495a5313Brian Paul || swrast->_RasterMask == TEXTURE_BIT) 1113e6e0ba781b0a6a1b8747cae49ca622a6a61b1bf8Brian Paul && ctx->Polygon.StippleFlag == GL_FALSE 11149c4fd26bcab7e4a5bd97a56deff89b8ea0ae5f1dBrian Paul && ctx->DrawBuffer->Visual.depthBits <= 16) { 11159bf68ad963ba92b5d1e725f965979042495a5313Brian Paul if (swrast->_RasterMask == (DEPTH_BIT | TEXTURE_BIT)) { 1116e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul USE(simple_z_textured_triangle); 1117e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1118e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell else { 1119e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul USE(simple_textured_triangle); 1120e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1121e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1122e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell else { 1123e0bafefd7ac911ec101876f4ea0d201309e841f2Brian Paul#if (CHAN_BITS == 16 || CHAN_BITS == 32) 112496385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul USE(general_textured_triangle); 112596385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul#else 112696385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul USE(affine_textured_triangle); 1127f431a3fb4dc1bf860203d79e54657e3a62bc50dfBrian Paul#endif 1128e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1129e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1130e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell else { 1131e0bafefd7ac911ec101876f4ea0d201309e841f2Brian Paul#if (CHAN_BITS == 16 || CHAN_BITS == 32) 113296385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul USE(general_textured_triangle); 113396385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul#else 113496385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul USE(persp_textured_triangle); 113596385fa15569e25cd0977e678c0ff3bdab6ef316Brian Paul#endif 1136e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1137e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1138e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell else { 113931f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul /* general case textured triangles */ 114036a0a3252e1e20df69b53f70ba93bc74c4a4bf0eBrian Paul if (ctx->Texture._EnabledCoordUnits > 1) { 114131f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul USE(multitextured_triangle); 1142e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1143e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell else { 114431f12f504e61cb2ad65b8890a68eb7154edcb64bBrian Paul USE(general_textured_triangle); 1145e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1146e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1147e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1148e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell else { 114936a0a3252e1e20df69b53f70ba93bc74c4a4bf0eBrian Paul ASSERT(!ctx->Texture._EnabledCoordUnits); 1150e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell if (ctx->Light.ShadeModel==GL_SMOOTH) { 1151e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell /* smooth shaded, no texturing, stippled or some raster ops */ 1152e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell if (rgbmode) { 1153e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul USE(smooth_rgba_triangle); 1154e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1155e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell else { 1156e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul USE(smooth_ci_triangle); 1157e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1158e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1159e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell else { 1160e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell /* flat shaded, no texturing, stippled or some raster ops */ 1161e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell if (rgbmode) { 1162e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul USE(flat_rgba_triangle); 1163e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1164e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell else { 1165e9313a64c182701d22a5c6d2a82863c658e7424fBrian Paul USE(flat_ci_triangle); 1166e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1167e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1168e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1169e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1170e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell else if (ctx->RenderMode==GL_FEEDBACK) { 117145bc887da226403f2c41077e40ca38b6f60f1359Brian Paul USE(_swrast_feedback_triangle); 1172e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1173e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell else { 1174e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell /* GL_SELECT mode */ 117545bc887da226403f2c41077e40ca38b6f60f1359Brian Paul USE(_swrast_select_triangle); 1176e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell } 1177e3a051e0538a605551f4d58294c94f5eb00ed07fKeith Whitwell} 1178