Changeset 3598 for trunk/src/opengl/mesa/texture.c
- Timestamp:
- May 23, 2000, 10:41:28 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/opengl/mesa/texture.c
r2962 r3598 1 /* $Id: texture.c,v 1. 2 2000-03-01 18:49:37 jeroen Exp $ */1 /* $Id: texture.c,v 1.3 2000-05-23 20:40:57 jeroen Exp $ */ 2 2 3 3 /* 4 4 * Mesa 3-D graphics library 5 * Version: 3. 15 * Version: 3.3 6 6 * 7 7 * Copyright (C) 1999 Brian Paul All Rights Reserved. … … 29 29 #include "all.h" 30 30 #else 31 #ifndef XFree86Server 32 #include <math.h> 33 #include <stdlib.h> 34 #include <stdio.h> 35 #else 36 #include "GL/xf86glx.h" 37 #endif 31 #include "glheader.h" 38 32 #include "types.h" 39 33 #include "context.h" … … 141 135 } 142 136 137 138 /* 139 * After state changes to texturing we call this function to update 140 * intermediate and derived state. 141 * Called by gl_update_state(). 142 */ 143 void gl_update_texture_unit( GLcontext *ctx, struct gl_texture_unit *texUnit ) 144 { 145 (void) ctx; 146 147 if ((texUnit->Enabled & TEXTURE0_3D) && texUnit->CurrentD[3]->Complete) { 148 texUnit->ReallyEnabled = TEXTURE0_3D; 149 texUnit->Current = texUnit->CurrentD[3]; 150 texUnit->CurrentDimension = 3; 151 goto utex_cont; 152 } 153 if ((texUnit->Enabled & TEXTURE0_2D) && texUnit->CurrentD[2]->Complete) { 154 texUnit->ReallyEnabled = TEXTURE0_2D; 155 texUnit->Current = texUnit->CurrentD[2]; 156 texUnit->CurrentDimension = 2; 157 goto utex_cont; 158 } 159 if ((texUnit->Enabled & TEXTURE0_1D) && texUnit->CurrentD[1]->Complete) { 160 texUnit->ReallyEnabled = TEXTURE0_1D; 161 texUnit->Current = texUnit->CurrentD[1]; 162 texUnit->CurrentDimension = 1; 163 goto utex_cont; 164 } 165 { 166 /* if (MESA_VERBOSE & VERBOSE_TEXTURE) { 167 switch (texUnit->Enabled) { 168 case TEXTURE0_3D: 169 fprintf(stderr, "Using incomplete 3d texture %u\n", 170 texUnit->CurrentD[3]->Name); 171 break; 172 case TEXTURE0_2D: 173 fprintf(stderr, "Using incomplete 2d texture %u\n", 174 texUnit->CurrentD[2]->Name); 175 break; 176 case TEXTURE0_1D: 177 fprintf(stderr, "Using incomplete 1d texture %u\n", 178 texUnit->CurrentD[1]->Name); 179 break; 180 default: 181 fprintf(stderr, "Bad value for texUnit->Enabled %x\n", 182 texUnit->Enabled); 183 break; 184 } 185 } */ 186 187 texUnit->ReallyEnabled = 0; 188 texUnit->Current = NULL; 189 texUnit->CurrentDimension = 0; 190 return; 191 } 192 193 utex_cont: 194 195 texUnit->GenFlags = 0; 196 197 if (texUnit->TexGenEnabled) { 198 GLuint sz = 0; 199 200 if (texUnit->TexGenEnabled & S_BIT) { 201 sz = 1; 202 texUnit->GenFlags |= texUnit->GenBitS; 203 } 204 if (texUnit->TexGenEnabled & T_BIT) { 205 sz = 2; 206 texUnit->GenFlags |= texUnit->GenBitT; 207 } 208 if (texUnit->TexGenEnabled & Q_BIT) { 209 sz = 3; 210 texUnit->GenFlags |= texUnit->GenBitQ; 211 } 212 if (texUnit->TexGenEnabled & R_BIT) { 213 sz = 4; 214 texUnit->GenFlags |= texUnit->GenBitR; 215 } 216 217 texUnit->TexgenSize = sz; 218 texUnit->Holes = (GLubyte) (all_bits[sz] & ~texUnit->TexGenEnabled); 219 texUnit->func = texgen_generic_tab; 220 221 if (texUnit->TexGenEnabled == (S_BIT|T_BIT|R_BIT)) { 222 if (texUnit->GenFlags == TEXGEN_REFLECTION_MAP_NV) { 223 texUnit->func = texgen_reflection_map_nv_tab; 224 } 225 else if (texUnit->GenFlags == TEXGEN_NORMAL_MAP_NV) { 226 texUnit->func = texgen_normal_map_nv_tab; 227 } 228 } 229 else if (texUnit->TexGenEnabled == (S_BIT|T_BIT) && 230 texUnit->GenFlags == TEXGEN_SPHERE_MAP) { 231 texUnit->func = texgen_sphere_map_tab; 232 } 233 } 234 } 235 236 237 143 238 /* 144 239 * Paletted texture sampling. … … 150 245 GLubyte index, GLubyte rgba[4] ) 151 246 { 152 GLcontext *ctx = gl_get_current_context(); /* THIS IS A HACK*/247 GLcontext *ctx = gl_get_current_context(); /* THIS IS A HACK*/ 153 248 GLint i = index; 154 249 const GLubyte *palette; 250 GLenum format; 155 251 156 252 if (ctx->Texture.SharedPalette) { 157 palette = ctx->Texture.Palette; 253 palette = ctx->Texture.Palette.Table; 254 format = ctx->Texture.Palette.Format; 158 255 } 159 256 else { 160 palette = tObj->Palette; 161 } 162 163 switch (tObj->PaletteFormat) { 257 palette = tObj->Palette.Table; 258 format = tObj->Palette.Format; 259 } 260 261 switch (format) { 164 262 case GL_ALPHA: 165 rgba[ACOMP] = tObj->Palette[index];263 rgba[ACOMP] = palette[index]; 166 264 return; 167 265 case GL_LUMINANCE: … … 314 412 #ifdef DEBUG 315 413 GLint width = img->Width; 316 assert(i >= 0);317 assert(i < width);414 ASSERT(i >= 0); 415 ASSERT(i < width); 318 416 #endif 319 417 … … 448 546 449 547 if (useBorderColor & I0BIT) { 450 t0[RCOMP] = tObj->BorderColor[0]; 451 t0[GCOMP] = tObj->BorderColor[1]; 452 t0[BCOMP] = tObj->BorderColor[2]; 453 t0[ACOMP] = tObj->BorderColor[3]; 548 COPY_4UBV(t0, tObj->BorderColor); 454 549 } 455 550 else { … … 457 552 } 458 553 if (useBorderColor & I1BIT) { 459 t1[RCOMP] = tObj->BorderColor[0]; 460 t1[GCOMP] = tObj->BorderColor[1]; 461 t1[BCOMP] = tObj->BorderColor[2]; 462 t1[ACOMP] = tObj->BorderColor[3]; 554 COPY_4UBV(t1, tObj->BorderColor); 463 555 } 464 556 else { … … 682 774 #ifdef DEBUG 683 775 const GLint height = img->Height; /* includes border */ 684 assert(i >= 0);685 assert(i < width);686 assert(j >= 0);687 assert(j < height);776 ASSERT(i >= 0); 777 ASSERT(i < width); 778 ASSERT(j >= 0); 779 ASSERT(j < height); 688 780 #endif 689 781 … … 833 925 834 926 if (useBorderColor & (I0BIT | J0BIT)) { 835 t00[RCOMP] = tObj->BorderColor[0]; 836 t00[GCOMP] = tObj->BorderColor[1]; 837 t00[BCOMP] = tObj->BorderColor[2]; 838 t00[ACOMP] = tObj->BorderColor[3]; 927 COPY_4UBV(t00, tObj->BorderColor); 839 928 } 840 929 else { … … 842 931 } 843 932 if (useBorderColor & (I1BIT | J0BIT)) { 844 t10[RCOMP] = tObj->BorderColor[0]; 845 t10[GCOMP] = tObj->BorderColor[1]; 846 t10[BCOMP] = tObj->BorderColor[2]; 847 t10[ACOMP] = tObj->BorderColor[3]; 933 COPY_4UBV(t10, tObj->BorderColor); 848 934 } 849 935 else { … … 851 937 } 852 938 if (useBorderColor & (I0BIT | J1BIT)) { 853 t01[RCOMP] = tObj->BorderColor[0]; 854 t01[GCOMP] = tObj->BorderColor[1]; 855 t01[BCOMP] = tObj->BorderColor[2]; 856 t01[ACOMP] = tObj->BorderColor[3]; 939 COPY_4UBV(t01, tObj->BorderColor); 857 940 } 858 941 else { … … 860 943 } 861 944 if (useBorderColor & (I1BIT | J1BIT)) { 862 t11[RCOMP] = tObj->BorderColor[0]; 863 t11[GCOMP] = tObj->BorderColor[1]; 864 t11[BCOMP] = tObj->BorderColor[2]; 865 t11[ACOMP] = tObj->BorderColor[3]; 945 COPY_4UBV(t11, tObj->BorderColor); 866 946 } 867 947 else { … … 1166 1246 #ifdef DEBUG 1167 1247 const GLint depth = img->Depth; /* includes border */ 1168 assert(i >= 0);1169 assert(i < width);1170 assert(j >= 0);1171 assert(j < height);1172 assert(k >= 0);1173 assert(k < depth);1248 ASSERT(i >= 0); 1249 ASSERT(i < width); 1250 ASSERT(j >= 0); 1251 ASSERT(j < height); 1252 ASSERT(k >= 0); 1253 ASSERT(k < depth); 1174 1254 #endif 1175 1255 … … 1328 1408 1329 1409 if (useBorderColor & (I0BIT | J0BIT | K0BIT)) { 1330 t000[RCOMP] = tObj->BorderColor[0]; 1331 t000[GCOMP] = tObj->BorderColor[1]; 1332 t000[BCOMP] = tObj->BorderColor[2]; 1333 t000[ACOMP] = tObj->BorderColor[3]; 1410 COPY_4UBV(t000, tObj->BorderColor); 1334 1411 } 1335 1412 else { … … 1337 1414 } 1338 1415 if (useBorderColor & (I1BIT | J0BIT | K0BIT)) { 1339 t100[RCOMP] = tObj->BorderColor[0]; 1340 t100[GCOMP] = tObj->BorderColor[1]; 1341 t100[BCOMP] = tObj->BorderColor[2]; 1342 t100[ACOMP] = tObj->BorderColor[3]; 1416 COPY_4UBV(t100, tObj->BorderColor); 1343 1417 } 1344 1418 else { … … 1346 1420 } 1347 1421 if (useBorderColor & (I0BIT | J1BIT | K0BIT)) { 1348 t010[RCOMP] = tObj->BorderColor[0]; 1349 t010[GCOMP] = tObj->BorderColor[1]; 1350 t010[BCOMP] = tObj->BorderColor[2]; 1351 t010[ACOMP] = tObj->BorderColor[3]; 1422 COPY_4UBV(t010, tObj->BorderColor); 1352 1423 } 1353 1424 else { … … 1355 1426 } 1356 1427 if (useBorderColor & (I1BIT | J1BIT | K0BIT)) { 1357 t110[RCOMP] = tObj->BorderColor[0]; 1358 t110[GCOMP] = tObj->BorderColor[1]; 1359 t110[BCOMP] = tObj->BorderColor[2]; 1360 t110[ACOMP] = tObj->BorderColor[3]; 1428 COPY_4UBV(t110, tObj->BorderColor); 1361 1429 } 1362 1430 else { … … 1365 1433 1366 1434 if (useBorderColor & (I0BIT | J0BIT | K1BIT)) { 1367 t001[RCOMP] = tObj->BorderColor[0]; 1368 t001[GCOMP] = tObj->BorderColor[1]; 1369 t001[BCOMP] = tObj->BorderColor[2]; 1370 t001[ACOMP] = tObj->BorderColor[3]; 1435 COPY_4UBV(t001, tObj->BorderColor); 1371 1436 } 1372 1437 else { … … 1374 1439 } 1375 1440 if (useBorderColor & (I1BIT | J0BIT | K1BIT)) { 1376 t101[RCOMP] = tObj->BorderColor[0]; 1377 t101[GCOMP] = tObj->BorderColor[1]; 1378 t101[BCOMP] = tObj->BorderColor[2]; 1379 t101[ACOMP] = tObj->BorderColor[3]; 1441 COPY_4UBV(t101, tObj->BorderColor); 1380 1442 } 1381 1443 else { … … 1383 1445 } 1384 1446 if (useBorderColor & (I0BIT | J1BIT | K1BIT)) { 1385 t011[RCOMP] = tObj->BorderColor[0]; 1386 t011[GCOMP] = tObj->BorderColor[1]; 1387 t011[BCOMP] = tObj->BorderColor[2]; 1388 t011[ACOMP] = tObj->BorderColor[3]; 1447 COPY_4UBV(t011, tObj->BorderColor); 1389 1448 } 1390 1449 else { … … 1392 1451 } 1393 1452 if (useBorderColor & (I1BIT | J1BIT | K1BIT)) { 1394 t111[RCOMP] = tObj->BorderColor[0]; 1395 t111[GCOMP] = tObj->BorderColor[1]; 1396 t111[BCOMP] = tObj->BorderColor[2]; 1397 t111[ACOMP] = tObj->BorderColor[3]; 1453 COPY_4UBV(t111, tObj->BorderColor); 1398 1454 } 1399 1455 else { … … 1695 1751 * according to the texture environment mode. 1696 1752 */ 1697 1698 1699 1753 static void apply_texture( const GLcontext *ctx, 1700 1754 const struct gl_texture_unit *texUnit, … … 1706 1760 GLenum format; 1707 1761 1708 /*1709 * Use (A*(B+1)) >> 8 as a fast approximation of (A*B)/255 for A1710 * and B in [0,255]1711 */1712 1713 #define PROD(A,B) ( (GLubyte) (((GLint)(A) * ((GLint)(B)+1)) >> 8) )1714 1715 1762 ASSERT(texUnit); 1716 1763 ASSERT(texUnit->Current); … … 1718 1765 1719 1766 format = texUnit->Current->Image[0]->Format; 1767 1768 /* 1769 * Use (A*(B+1)) >> 8 as a fast approximation of (A*B)/255 for A 1770 * and B in [0,255] 1771 */ 1772 #define PROD(A,B) ( (GLubyte) (((GLint)(A) * ((GLint)(B)+1)) >> 8) ) 1720 1773 1721 1774 if (format==GL_COLOR_INDEX) { … … 1779 1832 break; 1780 1833 default: 1781 gl_problem(ctx, "Bad format in apply_texture");1834 gl_problem(ctx, "Bad format (GL_REPLACE) in apply_texture"); 1782 1835 return; 1783 1836 } … … 1845 1898 break; 1846 1899 default: 1847 gl_problem(ctx, "Bad format ( 2) in apply_texture");1900 gl_problem(ctx, "Bad format (GL_MODULATE) in apply_texture"); 1848 1901 return; 1849 1902 } … … 1878 1931 break; 1879 1932 default: 1880 gl_problem(ctx, "Bad format ( 3) in apply_texture");1933 gl_problem(ctx, "Bad format (GL_DECAL) in apply_texture"); 1881 1934 return; 1882 1935 } … … 1948 2001 break; 1949 2002 default: 1950 gl_problem(ctx, "Bad format (4) in apply_texture"); 2003 gl_problem(ctx, "Bad format (GL_BLEND) in apply_texture"); 2004 return; 2005 } 2006 break; 2007 2008 case GL_ADD: /* GL_EXT_texture_add_env */ 2009 switch (format) { 2010 case GL_ALPHA: 2011 for (i=0;i<n;i++) { 2012 /* Rv = Rf */ 2013 /* Gv = Gf */ 2014 /* Bv = Bf */ 2015 rgba[i][ACOMP] = PROD(rgba[i][ACOMP], texel[i][ACOMP]); 2016 } 2017 break; 2018 case GL_LUMINANCE: 2019 for (i=0;i<n;i++) { 2020 GLuint Lt = texel[i][RCOMP]; 2021 GLuint r = rgba[i][RCOMP] + Lt; 2022 GLuint g = rgba[i][GCOMP] + Lt; 2023 GLuint b = rgba[i][BCOMP] + Lt; 2024 rgba[i][RCOMP] = r < 256 ? (GLubyte) r : 255; 2025 rgba[i][GCOMP] = g < 256 ? (GLubyte) g : 255; 2026 rgba[i][BCOMP] = b < 256 ? (GLubyte) b : 255; 2027 /* Av = Af */ 2028 } 2029 break; 2030 case GL_LUMINANCE_ALPHA: 2031 for (i=0;i<n;i++) { 2032 GLuint Lt = texel[i][RCOMP]; 2033 GLuint r = rgba[i][RCOMP] + Lt; 2034 GLuint g = rgba[i][GCOMP] + Lt; 2035 GLuint b = rgba[i][BCOMP] + Lt; 2036 rgba[i][RCOMP] = r < 256 ? (GLubyte) r : 255; 2037 rgba[i][GCOMP] = g < 256 ? (GLubyte) g : 255; 2038 rgba[i][BCOMP] = b < 256 ? (GLubyte) b : 255; 2039 rgba[i][ACOMP] = PROD(rgba[i][ACOMP], texel[i][ACOMP]); 2040 } 2041 break; 2042 case GL_INTENSITY: 2043 for (i=0;i<n;i++) { 2044 GLubyte It = texel[i][RCOMP]; 2045 GLuint r = rgba[i][RCOMP] + It; 2046 GLuint g = rgba[i][GCOMP] + It; 2047 GLuint b = rgba[i][BCOMP] + It; 2048 GLuint a = rgba[i][ACOMP] + It; 2049 rgba[i][RCOMP] = r < 256 ? (GLubyte) r : 255; 2050 rgba[i][GCOMP] = g < 256 ? (GLubyte) g : 255; 2051 rgba[i][BCOMP] = b < 256 ? (GLubyte) b : 255; 2052 rgba[i][ACOMP] = a < 256 ? (GLubyte) a : 255; 2053 } 2054 break; 2055 case GL_RGB: 2056 for (i=0;i<n;i++) { 2057 GLuint r = rgba[i][RCOMP] + texel[i][RCOMP]; 2058 GLuint g = rgba[i][GCOMP] + texel[i][GCOMP]; 2059 GLuint b = rgba[i][BCOMP] + texel[i][BCOMP]; 2060 rgba[i][RCOMP] = r < 256 ? (GLubyte) r : 255; 2061 rgba[i][GCOMP] = g < 256 ? (GLubyte) g : 255; 2062 rgba[i][BCOMP] = b < 256 ? (GLubyte) b : 255; 2063 /* Av = Af */ 2064 } 2065 break; 2066 case GL_RGBA: 2067 for (i=0;i<n;i++) { 2068 GLuint r = rgba[i][RCOMP] + texel[i][RCOMP]; 2069 GLuint g = rgba[i][GCOMP] + texel[i][GCOMP]; 2070 GLuint b = rgba[i][BCOMP] + texel[i][BCOMP]; 2071 rgba[i][RCOMP] = r < 256 ? (GLubyte) r : 255; 2072 rgba[i][GCOMP] = g < 256 ? (GLubyte) g : 255; 2073 rgba[i][BCOMP] = b < 256 ? (GLubyte) b : 255; 2074 rgba[i][ACOMP] = PROD(rgba[i][ACOMP], texel[i][ACOMP]); 2075 } 2076 break; 2077 default: 2078 gl_problem(ctx, "Bad format (GL_ADD) in apply_texture"); 1951 2079 return; 1952 2080 } … … 1974 2102 const struct gl_texture_unit *textureUnit = &ctx->Texture.Unit[texUnit]; 1975 2103 if (textureUnit->Current && textureUnit->Current->SampleFunc) { 1976 1977 2104 GLubyte texel[PB_SIZE][4]; 2105 2106 if (textureUnit->LodBias != 0.0F) { 2107 /* apply LOD bias, but don't clamp yet */ 2108 GLuint i; 2109 for (i=0;i<n;i++) { 2110 lambda[i] += textureUnit->LodBias; 2111 } 2112 } 1978 2113 1979 2114 if (textureUnit->Current->MinLod != -1000.0 … … 1998 2133 } 1999 2134 } 2000 2001 /*2002 * After state changes to texturing we call this function to update2003 * intermediate and derived state.2004 * Called by gl_update_state().2005 */2006 void gl_update_texture_unit( GLcontext *ctx, struct gl_texture_unit *texUnit )2007 {2008 (void) ctx;2009 2010 if ((texUnit->Enabled & TEXTURE0_3D) && texUnit->CurrentD[3]->Complete) {2011 texUnit->ReallyEnabled = TEXTURE0_3D;2012 texUnit->Current = texUnit->CurrentD[3];2013 texUnit->CurrentDimension = 3;2014 }2015 else if ((texUnit->Enabled & TEXTURE0_2D) && texUnit->CurrentD[2]->Complete) {2016 texUnit->ReallyEnabled = TEXTURE0_2D;2017 texUnit->Current = texUnit->CurrentD[2];2018 texUnit->CurrentDimension = 2;2019 }2020 else if ((texUnit->Enabled & TEXTURE0_1D) && texUnit->CurrentD[1]->Complete) {2021 texUnit->ReallyEnabled = TEXTURE0_1D;2022 texUnit->Current = texUnit->CurrentD[1];2023 texUnit->CurrentDimension = 1;2024 }2025 else {2026 /* if (MESA_VERBOSE & VERBOSE_TEXTURE) {2027 switch (texUnit->Enabled) {2028 case TEXTURE0_3D:2029 fprintf(stderr, "Using incomplete 3d texture %u\n",2030 texUnit->CurrentD[3]->Name);2031 break;2032 case TEXTURE0_2D:2033 fprintf(stderr, "Using incomplete 2d texture %u\n",2034 texUnit->CurrentD[2]->Name);2035 break;2036 case TEXTURE0_1D:2037 fprintf(stderr, "Using incomplete 1d texture %u\n",2038 texUnit->CurrentD[1]->Name);2039 break;2040 default:2041 fprintf(stderr, "Bad value for texUnit->Enabled %x\n",2042 texUnit->Enabled);2043 break;2044 }2045 }*/2046 2047 texUnit->ReallyEnabled = 0;2048 texUnit->Current = NULL;2049 texUnit->CurrentDimension = 0;2050 return;2051 }2052 2053 texUnit->GenFlags = 0;2054 2055 if (texUnit->TexGenEnabled) {2056 GLuint sz = 0;2057 2058 if (texUnit->TexGenEnabled & S_BIT) {2059 sz = 1;2060 texUnit->GenFlags |= texUnit->GenBitS;2061 }2062 if (texUnit->TexGenEnabled & T_BIT) {2063 sz = 2;2064 texUnit->GenFlags |= texUnit->GenBitT;2065 }2066 if (texUnit->TexGenEnabled & Q_BIT) {2067 sz = 3;2068 texUnit->GenFlags |= texUnit->GenBitQ;2069 }2070 if (texUnit->TexGenEnabled & R_BIT) {2071 sz = 4;2072 texUnit->GenFlags |= texUnit->GenBitR;2073 }2074 2075 texUnit->TexgenSize = sz;2076 texUnit->Holes = (GLubyte) (all_bits[sz] & ~texUnit->TexGenEnabled);2077 texUnit->func = texgen_generic_tab;2078 2079 if (texUnit->TexGenEnabled == (S_BIT|T_BIT|R_BIT)) {2080 if (texUnit->GenFlags == TEXGEN_REFLECTION_MAP_NV) {2081 texUnit->func = texgen_reflection_map_nv_tab;2082 }2083 else if (texUnit->GenFlags == TEXGEN_NORMAL_MAP_NV) {2084 texUnit->func = texgen_normal_map_nv_tab;2085 }2086 }2087 else if (texUnit->TexGenEnabled == (S_BIT|T_BIT) &&2088 texUnit->GenFlags == TEXGEN_SPHERE_MAP) {2089 texUnit->func = texgen_sphere_map_tab;2090 }2091 }2092 }
Note:
See TracChangeset
for help on using the changeset viewer.