1/* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 5 * Copyright (c) 2009 VMware, Inc. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included 15 * in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 * OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 26 27/** 28 * \file s_texfetch.c 29 * 30 * Texel fetch/store functions 31 * 32 * \author Gareth Hughes 33 */ 34 35 36#include "main/errors.h" 37#include "main/macros.h" 38#include "main/texcompress.h" 39#include "main/texcompress_fxt1.h" 40#include "main/texcompress_s3tc.h" 41#include "main/texcompress_rgtc.h" 42#include "main/texcompress_etc.h" 43#include "main/teximage.h" 44#include "main/samplerobj.h" 45#include "s_context.h" 46#include "s_texfetch.h" 47#include "util/format_rgb9e5.h" 48#include "util/format_r11g11b10f.h" 49#include "util/format_srgb.h" 50 51 52/* Texel fetch routines for all supported formats 53 */ 54#define DIM 1 55#include "s_texfetch_tmp.h" 56 57#define DIM 2 58#include "s_texfetch_tmp.h" 59 60#define DIM 3 61#include "s_texfetch_tmp.h" 62 63 64/** 65 * All compressed texture texel fetching is done though this function. 66 * Basically just call a core-Mesa texel fetch function. 67 */ 68static void 69fetch_compressed(const struct swrast_texture_image *swImage, 70 GLint i, GLint j, GLint k, GLfloat *texel) 71{ 72 /* The FetchCompressedTexel function takes an integer pixel rowstride, 73 * while the image's rowstride is bytes per row of blocks. 74 */ 75 GLuint bw, bh; 76 GLuint texelBytes = _mesa_get_format_bytes(swImage->Base.TexFormat); 77 _mesa_get_format_block_size(swImage->Base.TexFormat, &bw, &bh); 78 assert(swImage->RowStride * bw % texelBytes == 0); 79 80 swImage->FetchCompressedTexel(swImage->ImageSlices[k], 81 swImage->RowStride * bw / texelBytes, 82 i, j, texel); 83} 84 85 86 87/** 88 * Null texel fetch function. 89 * 90 * Have to have this so the FetchTexel function pointer is never NULL. 91 */ 92static void fetch_null_texelf( const struct swrast_texture_image *texImage, 93 GLint i, GLint j, GLint k, GLfloat *texel ) 94{ 95 (void) texImage; (void) i; (void) j; (void) k; 96 texel[RCOMP] = 0.0; 97 texel[GCOMP] = 0.0; 98 texel[BCOMP] = 0.0; 99 texel[ACOMP] = 0.0; 100 _mesa_warning(NULL, "fetch_null_texelf() called!"); 101} 102 103 104#define FETCH_FUNCS(NAME) \ 105 { \ 106 MESA_FORMAT_ ## NAME, \ 107 fetch_texel_1d_ ## NAME, \ 108 fetch_texel_2d_ ## NAME, \ 109 fetch_texel_3d_ ## NAME, \ 110 } 111 112#define FETCH_NULL(NAME) \ 113 { \ 114 MESA_FORMAT_ ## NAME, \ 115 NULL, \ 116 NULL, \ 117 NULL \ 118 } 119 120#define FETCH_COMPRESSED(NAME) \ 121 { \ 122 MESA_FORMAT_ ## NAME, \ 123 fetch_compressed, \ 124 fetch_compressed, \ 125 fetch_compressed \ 126 } 127 128/** 129 * Table to map MESA_FORMAT_ to texel fetch/store funcs. 130 */ 131static struct { 132 mesa_format Name; 133 FetchTexelFunc Fetch1D; 134 FetchTexelFunc Fetch2D; 135 FetchTexelFunc Fetch3D; 136} 137texfetch_funcs[] = 138{ 139 { 140 MESA_FORMAT_NONE, 141 fetch_null_texelf, 142 fetch_null_texelf, 143 fetch_null_texelf 144 }, 145 146 /* Packed unorm formats */ 147 FETCH_FUNCS(A8B8G8R8_UNORM), 148 FETCH_FUNCS(X8B8G8R8_UNORM), 149 FETCH_FUNCS(R8G8B8A8_UNORM), 150 FETCH_FUNCS(R8G8B8X8_UNORM), 151 FETCH_FUNCS(B8G8R8A8_UNORM), 152 FETCH_FUNCS(B8G8R8X8_UNORM), 153 FETCH_FUNCS(A8R8G8B8_UNORM), 154 FETCH_FUNCS(X8R8G8B8_UNORM), 155 FETCH_FUNCS(L16A16_UNORM), 156 FETCH_FUNCS(A16L16_UNORM), 157 FETCH_FUNCS(B5G6R5_UNORM), 158 FETCH_FUNCS(R5G6B5_UNORM), 159 FETCH_FUNCS(B4G4R4A4_UNORM), 160 FETCH_NULL(B4G4R4X4_UNORM), 161 FETCH_FUNCS(A4R4G4B4_UNORM), 162 FETCH_FUNCS(A1B5G5R5_UNORM), 163 FETCH_NULL(X1B5G5R5_UNORM), 164 FETCH_FUNCS(B5G5R5A1_UNORM), 165 FETCH_NULL(B5G5R5X1_UNORM), 166 FETCH_FUNCS(A1R5G5B5_UNORM), 167 FETCH_FUNCS(L8A8_UNORM), 168 FETCH_FUNCS(A8L8_UNORM), 169 FETCH_FUNCS(R8G8_UNORM), 170 FETCH_FUNCS(G8R8_UNORM), 171 FETCH_FUNCS(L4A4_UNORM), 172 FETCH_FUNCS(B2G3R3_UNORM), 173 FETCH_FUNCS(R16G16_UNORM), 174 FETCH_FUNCS(G16R16_UNORM), 175 FETCH_FUNCS(B10G10R10A2_UNORM), 176 FETCH_NULL(B10G10R10X2_UNORM), 177 FETCH_FUNCS(R10G10B10A2_UNORM), 178 FETCH_NULL(R10G10B10X2_UNORM), 179 180 FETCH_FUNCS(S8_UINT_Z24_UNORM), 181 { 182 MESA_FORMAT_X8_UINT_Z24_UNORM, 183 fetch_texel_1d_S8_UINT_Z24_UNORM, 184 fetch_texel_2d_S8_UINT_Z24_UNORM, 185 fetch_texel_3d_S8_UINT_Z24_UNORM 186 }, 187 FETCH_FUNCS(Z24_UNORM_S8_UINT), 188 { 189 MESA_FORMAT_Z24_UNORM_X8_UINT, 190 fetch_texel_1d_Z24_UNORM_S8_UINT, 191 fetch_texel_2d_Z24_UNORM_S8_UINT, 192 fetch_texel_3d_Z24_UNORM_S8_UINT 193 }, 194 FETCH_NULL(R3G3B2_UNORM), 195 FETCH_NULL(A4B4G4R4_UNORM), 196 FETCH_NULL(R4G4B4A4_UNORM), 197 FETCH_NULL(R5G5B5A1_UNORM), 198 FETCH_NULL(A2B10G10R10_UNORM), 199 FETCH_NULL(A2R10G10B10_UNORM), 200 201 FETCH_FUNCS(YCBCR), 202 FETCH_FUNCS(YCBCR_REV), 203 204 /* Array unorm formats */ 205 FETCH_FUNCS(A_UNORM8), 206 FETCH_FUNCS(A_UNORM16), 207 FETCH_FUNCS(L_UNORM8), 208 FETCH_FUNCS(L_UNORM16), 209 FETCH_FUNCS(I_UNORM8), 210 FETCH_FUNCS(I_UNORM16), 211 FETCH_FUNCS(R_UNORM8), 212 FETCH_FUNCS(R_UNORM16), 213 FETCH_FUNCS(BGR_UNORM8), 214 FETCH_FUNCS(RGB_UNORM8), 215 FETCH_FUNCS(RGBA_UNORM16), 216 FETCH_FUNCS(RGBX_UNORM16), 217 FETCH_FUNCS(Z_UNORM16), 218 FETCH_FUNCS(Z_UNORM32), 219 FETCH_NULL(S_UINT8), 220 221 /* Packed signed/normalized formats */ 222 FETCH_FUNCS(A8B8G8R8_SNORM), 223 FETCH_FUNCS(X8B8G8R8_SNORM), 224 FETCH_FUNCS(R8G8B8A8_SNORM), 225 FETCH_NULL(R8G8B8X8_SNORM), 226 FETCH_FUNCS(R16G16_SNORM), 227 FETCH_NULL(G16R16_SNORM), 228 FETCH_FUNCS(R8G8_SNORM), 229 FETCH_NULL(G8R8_SNORM), 230 FETCH_FUNCS(L8A8_SNORM), 231 FETCH_FUNCS(A8L8_SNORM), 232 233 /* Array signed/normalized formats */ 234 FETCH_FUNCS(A_SNORM8), 235 FETCH_FUNCS(A_SNORM16), 236 FETCH_FUNCS(L_SNORM8), 237 FETCH_FUNCS(L_SNORM16), 238 FETCH_FUNCS(I_SNORM8), 239 FETCH_FUNCS(I_SNORM16), 240 FETCH_FUNCS(R_SNORM8), 241 FETCH_FUNCS(R_SNORM16), 242 FETCH_FUNCS(LA_SNORM16), 243 FETCH_FUNCS(RGB_SNORM16), 244 FETCH_FUNCS(RGBA_SNORM16), 245 FETCH_NULL(RGBX_SNORM16), 246 247 /* Packed sRGB formats */ 248 FETCH_FUNCS(A8B8G8R8_SRGB), 249 FETCH_FUNCS(B8G8R8A8_SRGB), 250 FETCH_FUNCS(A8R8G8B8_SRGB), 251 FETCH_NULL(B8G8R8X8_SRGB), 252 FETCH_NULL(X8R8G8B8_SRGB), 253 FETCH_FUNCS(R8G8B8A8_SRGB), 254 FETCH_FUNCS(R8G8B8X8_SRGB), 255 FETCH_FUNCS(X8B8G8R8_SRGB), 256 FETCH_FUNCS(L8A8_SRGB), 257 FETCH_FUNCS(A8L8_SRGB), 258 259 /* Array sRGB formats */ 260 FETCH_FUNCS(R_SRGB8), 261 FETCH_FUNCS(L_SRGB8), 262 FETCH_FUNCS(BGR_SRGB8), 263 264 /* Packed float formats */ 265 FETCH_FUNCS(R9G9B9E5_FLOAT), 266 FETCH_FUNCS(R11G11B10_FLOAT), 267 FETCH_FUNCS(Z32_FLOAT_S8X24_UINT), 268 269 /* Array float formats */ 270 FETCH_FUNCS(A_FLOAT16), 271 FETCH_FUNCS(A_FLOAT32), 272 FETCH_FUNCS(L_FLOAT16), 273 FETCH_FUNCS(L_FLOAT32), 274 FETCH_FUNCS(LA_FLOAT16), 275 FETCH_FUNCS(LA_FLOAT32), 276 FETCH_FUNCS(I_FLOAT16), 277 FETCH_FUNCS(I_FLOAT32), 278 FETCH_FUNCS(R_FLOAT16), 279 FETCH_FUNCS(R_FLOAT32), 280 FETCH_FUNCS(RG_FLOAT16), 281 FETCH_FUNCS(RG_FLOAT32), 282 FETCH_FUNCS(RGB_FLOAT16), 283 FETCH_FUNCS(RGB_FLOAT32), 284 FETCH_FUNCS(RGBA_FLOAT16), 285 FETCH_FUNCS(RGBA_FLOAT32), 286 FETCH_FUNCS(RGBX_FLOAT16), 287 FETCH_FUNCS(RGBX_FLOAT32), 288 { 289 MESA_FORMAT_Z_FLOAT32, 290 fetch_texel_1d_R_FLOAT32, /* Reuse the R32F functions. */ 291 fetch_texel_2d_R_FLOAT32, 292 fetch_texel_3d_R_FLOAT32 293 }, 294 295 /* Packed signed/unsigned non-normalized integer formats */ 296 FETCH_NULL(A8B8G8R8_UINT), 297 FETCH_NULL(A8R8G8B8_UINT), 298 FETCH_NULL(R8G8B8A8_UINT), 299 FETCH_NULL(B8G8R8A8_UINT), 300 FETCH_NULL(B10G10R10A2_UINT), 301 FETCH_NULL(R10G10B10A2_UINT), 302 FETCH_NULL(A2B10G10R10_UINT), 303 FETCH_NULL(A2R10G10B10_UINT), 304 FETCH_NULL(B5G6R5_UINT), 305 FETCH_NULL(R5G6B5_UINT), 306 FETCH_NULL(B2G3R3_UINT), 307 FETCH_NULL(R3G3B2_UINT), 308 FETCH_NULL(A4B4G4R4_UINT), 309 FETCH_NULL(R4G4B4A4_UINT), 310 FETCH_NULL(B4G4R4A4_UINT), 311 FETCH_NULL(A4R4G4B4_UINT), 312 FETCH_NULL(A1B5G5R5_UINT), 313 FETCH_NULL(B5G5R5A1_UINT), 314 FETCH_NULL(A1R5G5B5_UINT), 315 FETCH_NULL(R5G5B5A1_UINT), 316 317 /* Array signed/unsigned non-normalized integer formats */ 318 FETCH_NULL(A_UINT8), 319 FETCH_NULL(A_UINT16), 320 FETCH_NULL(A_UINT32), 321 FETCH_NULL(A_SINT8), 322 FETCH_NULL(A_SINT16), 323 FETCH_NULL(A_SINT32), 324 FETCH_NULL(I_UINT8), 325 FETCH_NULL(I_UINT16), 326 FETCH_NULL(I_UINT32), 327 FETCH_NULL(I_SINT8), 328 FETCH_NULL(I_SINT16), 329 FETCH_NULL(I_SINT32), 330 FETCH_NULL(L_UINT8), 331 FETCH_NULL(L_UINT16), 332 FETCH_NULL(L_UINT32), 333 FETCH_NULL(L_SINT8), 334 FETCH_NULL(L_SINT16), 335 FETCH_NULL(L_SINT32), 336 FETCH_NULL(LA_UINT8), 337 FETCH_NULL(LA_UINT16), 338 FETCH_NULL(LA_UINT32), 339 FETCH_NULL(LA_SINT8), 340 FETCH_NULL(LA_SINT16), 341 FETCH_NULL(LA_SINT32), 342 FETCH_NULL(R_UINT8), 343 FETCH_NULL(R_UINT16), 344 FETCH_NULL(R_UINT32), 345 FETCH_NULL(R_SINT8), 346 FETCH_NULL(R_SINT16), 347 FETCH_NULL(R_SINT32), 348 FETCH_NULL(RG_UINT8), 349 FETCH_NULL(RG_UINT16), 350 FETCH_NULL(RG_UINT32), 351 FETCH_NULL(RG_SINT8), 352 FETCH_NULL(RG_SINT16), 353 FETCH_NULL(RG_SINT32), 354 FETCH_NULL(RGB_UINT8), 355 FETCH_NULL(RGB_UINT16), 356 FETCH_NULL(RGB_UINT32), 357 FETCH_NULL(RGB_SINT8), 358 FETCH_NULL(RGB_SINT16), 359 FETCH_NULL(RGB_SINT32), 360 FETCH_FUNCS(RGBA_UINT8), 361 FETCH_FUNCS(RGBA_UINT16), 362 FETCH_FUNCS(RGBA_UINT32), 363 FETCH_FUNCS(RGBA_SINT8), 364 FETCH_FUNCS(RGBA_SINT16), 365 FETCH_FUNCS(RGBA_SINT32), 366 FETCH_NULL(RGBX_UINT8), 367 FETCH_NULL(RGBX_UINT16), 368 FETCH_NULL(RGBX_UINT32), 369 FETCH_NULL(RGBX_SINT8), 370 FETCH_NULL(RGBX_SINT16), 371 FETCH_NULL(RGBX_SINT32), 372 373 /* DXT compressed formats */ 374 FETCH_COMPRESSED(RGB_DXT1), 375 FETCH_COMPRESSED(RGBA_DXT1), 376 FETCH_COMPRESSED(RGBA_DXT3), 377 FETCH_COMPRESSED(RGBA_DXT5), 378 379 /* DXT sRGB compressed formats */ 380 FETCH_COMPRESSED(SRGB_DXT1), 381 FETCH_COMPRESSED(SRGBA_DXT1), 382 FETCH_COMPRESSED(SRGBA_DXT3), 383 FETCH_COMPRESSED(SRGBA_DXT5), 384 385 /* FXT1 compressed formats */ 386 FETCH_COMPRESSED(RGB_FXT1), 387 FETCH_COMPRESSED(RGBA_FXT1), 388 389 /* RGTC compressed formats */ 390 FETCH_COMPRESSED(R_RGTC1_UNORM), 391 FETCH_COMPRESSED(R_RGTC1_SNORM), 392 FETCH_COMPRESSED(RG_RGTC2_UNORM), 393 FETCH_COMPRESSED(RG_RGTC2_SNORM), 394 395 /* LATC1/2 compressed formats */ 396 FETCH_COMPRESSED(L_LATC1_UNORM), 397 FETCH_COMPRESSED(L_LATC1_SNORM), 398 FETCH_COMPRESSED(LA_LATC2_UNORM), 399 FETCH_COMPRESSED(LA_LATC2_SNORM), 400 401 /* ETC1/2 compressed formats */ 402 FETCH_COMPRESSED(ETC1_RGB8), 403 FETCH_COMPRESSED(ETC2_RGB8), 404 FETCH_COMPRESSED(ETC2_SRGB8), 405 FETCH_COMPRESSED(ETC2_RGBA8_EAC), 406 FETCH_COMPRESSED(ETC2_SRGB8_ALPHA8_EAC), 407 FETCH_COMPRESSED(ETC2_R11_EAC), 408 FETCH_COMPRESSED(ETC2_RG11_EAC), 409 FETCH_COMPRESSED(ETC2_SIGNED_R11_EAC), 410 FETCH_COMPRESSED(ETC2_SIGNED_RG11_EAC), 411 FETCH_COMPRESSED(ETC2_RGB8_PUNCHTHROUGH_ALPHA1), 412 FETCH_COMPRESSED(ETC2_SRGB8_PUNCHTHROUGH_ALPHA1), 413 FETCH_COMPRESSED(BPTC_RGBA_UNORM), 414 FETCH_COMPRESSED(BPTC_SRGB_ALPHA_UNORM), 415 FETCH_COMPRESSED(BPTC_RGB_SIGNED_FLOAT), 416 FETCH_COMPRESSED(BPTC_RGB_UNSIGNED_FLOAT), 417 418 /* ASTC compressed formats */ 419 FETCH_NULL(RGBA_ASTC_4x4), 420 FETCH_NULL(RGBA_ASTC_5x4), 421 FETCH_NULL(RGBA_ASTC_5x5), 422 FETCH_NULL(RGBA_ASTC_6x5), 423 FETCH_NULL(RGBA_ASTC_6x6), 424 FETCH_NULL(RGBA_ASTC_8x5), 425 FETCH_NULL(RGBA_ASTC_8x6), 426 FETCH_NULL(RGBA_ASTC_8x8), 427 FETCH_NULL(RGBA_ASTC_10x5), 428 FETCH_NULL(RGBA_ASTC_10x6), 429 FETCH_NULL(RGBA_ASTC_10x8), 430 FETCH_NULL(RGBA_ASTC_10x10), 431 FETCH_NULL(RGBA_ASTC_12x10), 432 FETCH_NULL(RGBA_ASTC_12x12), 433 FETCH_NULL(SRGB8_ALPHA8_ASTC_4x4), 434 FETCH_NULL(SRGB8_ALPHA8_ASTC_5x4), 435 FETCH_NULL(SRGB8_ALPHA8_ASTC_5x5), 436 FETCH_NULL(SRGB8_ALPHA8_ASTC_6x5), 437 FETCH_NULL(SRGB8_ALPHA8_ASTC_6x6), 438 FETCH_NULL(SRGB8_ALPHA8_ASTC_8x5), 439 FETCH_NULL(SRGB8_ALPHA8_ASTC_8x6), 440 FETCH_NULL(SRGB8_ALPHA8_ASTC_8x8), 441 FETCH_NULL(SRGB8_ALPHA8_ASTC_10x5), 442 FETCH_NULL(SRGB8_ALPHA8_ASTC_10x6), 443 FETCH_NULL(SRGB8_ALPHA8_ASTC_10x8), 444 FETCH_NULL(SRGB8_ALPHA8_ASTC_10x10), 445 FETCH_NULL(SRGB8_ALPHA8_ASTC_12x10), 446 FETCH_NULL(SRGB8_ALPHA8_ASTC_12x12), 447 448 FETCH_NULL(RGBA_ASTC_3x3x3), 449 FETCH_NULL(RGBA_ASTC_4x3x3), 450 FETCH_NULL(RGBA_ASTC_4x4x3), 451 FETCH_NULL(RGBA_ASTC_4x4x4), 452 FETCH_NULL(RGBA_ASTC_5x4x4), 453 FETCH_NULL(RGBA_ASTC_5x5x4), 454 FETCH_NULL(RGBA_ASTC_5x5x5), 455 FETCH_NULL(RGBA_ASTC_6x5x5), 456 FETCH_NULL(RGBA_ASTC_6x6x5), 457 FETCH_NULL(RGBA_ASTC_6x6x6), 458 FETCH_NULL(SRGB8_ALPHA8_ASTC_3x3x3), 459 FETCH_NULL(SRGB8_ALPHA8_ASTC_4x3x3), 460 FETCH_NULL(SRGB8_ALPHA8_ASTC_4x4x3), 461 FETCH_NULL(SRGB8_ALPHA8_ASTC_4x4x4), 462 FETCH_NULL(SRGB8_ALPHA8_ASTC_5x4x4), 463 FETCH_NULL(SRGB8_ALPHA8_ASTC_5x5x4), 464 FETCH_NULL(SRGB8_ALPHA8_ASTC_5x5x5), 465 FETCH_NULL(SRGB8_ALPHA8_ASTC_6x5x5), 466 FETCH_NULL(SRGB8_ALPHA8_ASTC_6x6x5), 467 FETCH_NULL(SRGB8_ALPHA8_ASTC_6x6x6), 468 469 FETCH_NULL(ATC_RGB), 470 FETCH_NULL(ATC_RGBA_EXPLICIT), 471 FETCH_NULL(ATC_RGBA_INTERPOLATED) 472}; 473 474 475/** 476 * Initialize the texture image's FetchTexel methods. 477 */ 478static void 479set_fetch_functions(const struct gl_sampler_object *samp, 480 struct swrast_texture_image *texImage, GLuint dims) 481{ 482 mesa_format format = texImage->Base.TexFormat; 483 484#ifdef DEBUG 485 /* check that the table entries are sorted by format name */ 486 mesa_format fmt; 487 for (fmt = 0; fmt < MESA_FORMAT_COUNT; fmt++) { 488 assert(texfetch_funcs[fmt].Name == fmt); 489 } 490#endif 491 492 STATIC_ASSERT(ARRAY_SIZE(texfetch_funcs) == MESA_FORMAT_COUNT); 493 494 if (samp->sRGBDecode == GL_SKIP_DECODE_EXT && 495 _mesa_get_format_color_encoding(format) == GL_SRGB) { 496 format = _mesa_get_srgb_format_linear(format); 497 } 498 499 assert(format < MESA_FORMAT_COUNT); 500 501 switch (dims) { 502 case 1: 503 texImage->FetchTexel = texfetch_funcs[format].Fetch1D; 504 break; 505 case 2: 506 texImage->FetchTexel = texfetch_funcs[format].Fetch2D; 507 break; 508 case 3: 509 texImage->FetchTexel = texfetch_funcs[format].Fetch3D; 510 break; 511 default: 512 assert(!"Bad dims in set_fetch_functions()"); 513 } 514 515 texImage->FetchCompressedTexel = _mesa_get_compressed_fetch_func(format); 516 517 assert(texImage->FetchTexel); 518} 519 520void 521_mesa_update_fetch_functions(struct gl_context *ctx, GLuint unit) 522{ 523 struct gl_texture_object *texObj = ctx->Texture.Unit[unit]._Current; 524 struct gl_sampler_object *samp; 525 GLuint face, i; 526 GLuint dims; 527 528 if (!texObj) 529 return; 530 531 samp = _mesa_get_samplerobj(ctx, unit); 532 533 dims = _mesa_get_texture_dimensions(texObj->Target); 534 535 for (face = 0; face < 6; face++) { 536 for (i = 0; i < MAX_TEXTURE_LEVELS; i++) { 537 if (texObj->Image[face][i]) { 538 set_fetch_functions(samp, 539 swrast_texture_image(texObj->Image[face][i]), 540 dims); 541 } 542 } 543 } 544} 545