Merge commit 'origin/gallium-master-merge'
[mesa.git] / src / mesa / main / texcompress_s3tc.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.3
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008 VMware, Inc.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 /**
28 * \file texcompress_s3tc.c
29 * GL_EXT_texture_compression_s3tc support.
30 */
31
32 #ifndef USE_EXTERNAL_DXTN_LIB
33 #define USE_EXTERNAL_DXTN_LIB 1
34 #endif
35
36 #include "glheader.h"
37 #include "imports.h"
38 #include "colormac.h"
39 #include "context.h"
40 #include "convolve.h"
41 #include "dlopen.h"
42 #include "image.h"
43 #include "texcompress.h"
44 #include "texformat.h"
45 #include "texstore.h"
46
47 #ifdef __MINGW32__
48 #define DXTN_LIBNAME "dxtn.dll"
49 #define RTLD_LAZY 0
50 #define RTLD_GLOBAL 0
51 #elif defined(__DJGPP__)
52 #define DXTN_LIBNAME "dxtn.dxe"
53 #else
54 #define DXTN_LIBNAME "libtxc_dxtn.so"
55 #endif
56
57 #if FEATURE_EXT_texture_sRGB
58 /**
59 * Convert an 8-bit sRGB value from non-linear space to a
60 * linear RGB value in [0, 1].
61 * Implemented with a 256-entry lookup table.
62 */
63 static INLINE GLfloat
64 nonlinear_to_linear(GLubyte cs8)
65 {
66 static GLfloat table[256];
67 static GLboolean tableReady = GL_FALSE;
68 if (!tableReady) {
69 /* compute lookup table now */
70 GLuint i;
71 for (i = 0; i < 256; i++) {
72 const GLfloat cs = UBYTE_TO_FLOAT(i);
73 if (cs <= 0.04045) {
74 table[i] = cs / 12.92f;
75 }
76 else {
77 table[i] = (GLfloat) _mesa_pow((cs + 0.055) / 1.055, 2.4);
78 }
79 }
80 tableReady = GL_TRUE;
81 }
82 return table[cs8];
83 }
84 #endif /* FEATURE_EXT_texture_sRGB */
85
86 typedef void (*dxtFetchTexelFuncExt)( GLint srcRowstride, GLubyte *pixdata, GLint col, GLint row, GLvoid *texelOut );
87
88 dxtFetchTexelFuncExt fetch_ext_rgb_dxt1 = NULL;
89 dxtFetchTexelFuncExt fetch_ext_rgba_dxt1 = NULL;
90 dxtFetchTexelFuncExt fetch_ext_rgba_dxt3 = NULL;
91 dxtFetchTexelFuncExt fetch_ext_rgba_dxt5 = NULL;
92
93 typedef void (*dxtCompressTexFuncExt)(GLint srccomps, GLint width,
94 GLint height, const GLchan *srcPixData,
95 GLenum destformat, GLubyte *dest,
96 GLint dstRowStride);
97
98 static dxtCompressTexFuncExt ext_tx_compress_dxtn = NULL;
99
100 static void *dxtlibhandle = NULL;
101
102
103 void
104 _mesa_init_texture_s3tc( GLcontext *ctx )
105 {
106 /* called during context initialization */
107 ctx->Mesa_DXTn = GL_FALSE;
108 #if USE_EXTERNAL_DXTN_LIB
109 if (!dxtlibhandle) {
110 dxtlibhandle = _mesa_dlopen(DXTN_LIBNAME, 0);
111 if (!dxtlibhandle) {
112 _mesa_warning(ctx, "couldn't open " DXTN_LIBNAME ", software DXTn "
113 "compression/decompression unavailable");
114 }
115 else {
116 /* the fetch functions are not per context! Might be problematic... */
117 fetch_ext_rgb_dxt1 = (dxtFetchTexelFuncExt)
118 _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgb_dxt1");
119 fetch_ext_rgba_dxt1 = (dxtFetchTexelFuncExt)
120 _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt1");
121 fetch_ext_rgba_dxt3 = (dxtFetchTexelFuncExt)
122 _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt3");
123 fetch_ext_rgba_dxt5 = (dxtFetchTexelFuncExt)
124 _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt5");
125 ext_tx_compress_dxtn = (dxtCompressTexFuncExt)
126 _mesa_dlsym(dxtlibhandle, "tx_compress_dxtn");
127
128 if (!fetch_ext_rgb_dxt1 ||
129 !fetch_ext_rgba_dxt1 ||
130 !fetch_ext_rgba_dxt3 ||
131 !fetch_ext_rgba_dxt5 ||
132 !ext_tx_compress_dxtn) {
133 _mesa_warning(ctx, "couldn't reference all symbols in "
134 DXTN_LIBNAME ", software DXTn compression/decompression "
135 "unavailable");
136 fetch_ext_rgb_dxt1 = NULL;
137 fetch_ext_rgba_dxt1 = NULL;
138 fetch_ext_rgba_dxt3 = NULL;
139 fetch_ext_rgba_dxt5 = NULL;
140 ext_tx_compress_dxtn = NULL;
141 _mesa_dlclose(dxtlibhandle);
142 dxtlibhandle = NULL;
143 }
144 }
145 }
146 if (dxtlibhandle) {
147 ctx->Mesa_DXTn = GL_TRUE;
148 _mesa_warning(ctx, "software DXTn compression/decompression available");
149 }
150 #else
151 (void) ctx;
152 #endif
153 }
154
155 /**
156 * Called via TexFormat->StoreImage to store an RGB_DXT1 texture.
157 */
158 static GLboolean
159 texstore_rgb_dxt1(TEXSTORE_PARAMS)
160 {
161 const GLchan *pixels;
162 GLint srcRowStride;
163 GLubyte *dst;
164 const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
165 const GLchan *tempImage = NULL;
166
167 ASSERT(dstFormat == &_mesa_texformat_rgb_dxt1);
168 ASSERT(dstXoffset % 4 == 0);
169 ASSERT(dstYoffset % 4 == 0);
170 ASSERT(dstZoffset % 4 == 0);
171 (void) dstZoffset;
172 (void) dstImageOffsets;
173
174 if (srcFormat != GL_RGB ||
175 srcType != CHAN_TYPE ||
176 ctx->_ImageTransferState ||
177 srcPacking->SwapBytes) {
178 /* convert image to RGB/GLchan */
179 tempImage = _mesa_make_temp_chan_image(ctx, dims,
180 baseInternalFormat,
181 dstFormat->BaseFormat,
182 srcWidth, srcHeight, srcDepth,
183 srcFormat, srcType, srcAddr,
184 srcPacking);
185 if (!tempImage)
186 return GL_FALSE; /* out of memory */
187 _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
188 pixels = tempImage;
189 srcRowStride = 3 * srcWidth;
190 srcFormat = GL_RGB;
191 }
192 else {
193 pixels = (const GLchan *) srcAddr;
194 srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
195 srcType) / sizeof(GLchan);
196 }
197
198 dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
199 dstFormat->MesaFormat,
200 texWidth, (GLubyte *) dstAddr);
201
202 if (ext_tx_compress_dxtn) {
203 (*ext_tx_compress_dxtn)(3, srcWidth, srcHeight, pixels,
204 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
205 dst, dstRowStride);
206 }
207 else {
208 _mesa_warning(ctx, "external dxt library not available");
209 }
210
211 if (tempImage)
212 _mesa_free((void *) tempImage);
213
214 return GL_TRUE;
215 }
216
217
218 /**
219 * Called via TexFormat->StoreImage to store an RGBA_DXT1 texture.
220 */
221 static GLboolean
222 texstore_rgba_dxt1(TEXSTORE_PARAMS)
223 {
224 const GLchan *pixels;
225 GLint srcRowStride;
226 GLubyte *dst;
227 const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
228 const GLchan *tempImage = NULL;
229
230 ASSERT(dstFormat == &_mesa_texformat_rgba_dxt1);
231 ASSERT(dstXoffset % 4 == 0);
232 ASSERT(dstYoffset % 4 == 0);
233 ASSERT(dstZoffset % 4 == 0);
234 (void) dstZoffset;
235 (void) dstImageOffsets;
236
237 if (srcFormat != GL_RGBA ||
238 srcType != CHAN_TYPE ||
239 ctx->_ImageTransferState ||
240 srcPacking->SwapBytes) {
241 /* convert image to RGBA/GLchan */
242 tempImage = _mesa_make_temp_chan_image(ctx, dims,
243 baseInternalFormat,
244 dstFormat->BaseFormat,
245 srcWidth, srcHeight, srcDepth,
246 srcFormat, srcType, srcAddr,
247 srcPacking);
248 if (!tempImage)
249 return GL_FALSE; /* out of memory */
250 _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
251 pixels = tempImage;
252 srcRowStride = 4 * srcWidth;
253 srcFormat = GL_RGBA;
254 }
255 else {
256 pixels = (const GLchan *) srcAddr;
257 srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
258 srcType) / sizeof(GLchan);
259 }
260
261 dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
262 dstFormat->MesaFormat,
263 texWidth, (GLubyte *) dstAddr);
264 if (ext_tx_compress_dxtn) {
265 (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
266 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
267 dst, dstRowStride);
268 }
269 else {
270 _mesa_warning(ctx, "external dxt library not available");
271 }
272
273 if (tempImage)
274 _mesa_free((void*) tempImage);
275
276 return GL_TRUE;
277 }
278
279
280 /**
281 * Called via TexFormat->StoreImage to store an RGBA_DXT3 texture.
282 */
283 static GLboolean
284 texstore_rgba_dxt3(TEXSTORE_PARAMS)
285 {
286 const GLchan *pixels;
287 GLint srcRowStride;
288 GLubyte *dst;
289 const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
290 const GLchan *tempImage = NULL;
291
292 ASSERT(dstFormat == &_mesa_texformat_rgba_dxt3);
293 ASSERT(dstXoffset % 4 == 0);
294 ASSERT(dstYoffset % 4 == 0);
295 ASSERT(dstZoffset % 4 == 0);
296 (void) dstZoffset;
297 (void) dstImageOffsets;
298
299 if (srcFormat != GL_RGBA ||
300 srcType != CHAN_TYPE ||
301 ctx->_ImageTransferState ||
302 srcPacking->SwapBytes) {
303 /* convert image to RGBA/GLchan */
304 tempImage = _mesa_make_temp_chan_image(ctx, dims,
305 baseInternalFormat,
306 dstFormat->BaseFormat,
307 srcWidth, srcHeight, srcDepth,
308 srcFormat, srcType, srcAddr,
309 srcPacking);
310 if (!tempImage)
311 return GL_FALSE; /* out of memory */
312 _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
313 pixels = tempImage;
314 srcRowStride = 4 * srcWidth;
315 }
316 else {
317 pixels = (const GLchan *) srcAddr;
318 srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
319 srcType) / sizeof(GLchan);
320 }
321
322 dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
323 dstFormat->MesaFormat,
324 texWidth, (GLubyte *) dstAddr);
325 if (ext_tx_compress_dxtn) {
326 (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
327 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
328 dst, dstRowStride);
329 }
330 else {
331 _mesa_warning(ctx, "external dxt library not available");
332 }
333
334 if (tempImage)
335 _mesa_free((void *) tempImage);
336
337 return GL_TRUE;
338 }
339
340
341 /**
342 * Called via TexFormat->StoreImage to store an RGBA_DXT5 texture.
343 */
344 static GLboolean
345 texstore_rgba_dxt5(TEXSTORE_PARAMS)
346 {
347 const GLchan *pixels;
348 GLint srcRowStride;
349 GLubyte *dst;
350 const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
351 const GLchan *tempImage = NULL;
352
353 ASSERT(dstFormat == &_mesa_texformat_rgba_dxt5);
354 ASSERT(dstXoffset % 4 == 0);
355 ASSERT(dstYoffset % 4 == 0);
356 ASSERT(dstZoffset % 4 == 0);
357 (void) dstZoffset;
358 (void) dstImageOffsets;
359
360 if (srcFormat != GL_RGBA ||
361 srcType != CHAN_TYPE ||
362 ctx->_ImageTransferState ||
363 srcPacking->SwapBytes) {
364 /* convert image to RGBA/GLchan */
365 tempImage = _mesa_make_temp_chan_image(ctx, dims,
366 baseInternalFormat,
367 dstFormat->BaseFormat,
368 srcWidth, srcHeight, srcDepth,
369 srcFormat, srcType, srcAddr,
370 srcPacking);
371 if (!tempImage)
372 return GL_FALSE; /* out of memory */
373 _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
374 pixels = tempImage;
375 srcRowStride = 4 * srcWidth;
376 }
377 else {
378 pixels = (const GLchan *) srcAddr;
379 srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
380 srcType) / sizeof(GLchan);
381 }
382
383 dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
384 dstFormat->MesaFormat,
385 texWidth, (GLubyte *) dstAddr);
386 if (ext_tx_compress_dxtn) {
387 (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
388 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
389 dst, dstRowStride);
390 }
391 else {
392 _mesa_warning(ctx, "external dxt library not available");
393 }
394
395 if (tempImage)
396 _mesa_free((void *) tempImage);
397
398 return GL_TRUE;
399 }
400
401
402 static void
403 fetch_texel_2d_rgb_dxt1( const struct gl_texture_image *texImage,
404 GLint i, GLint j, GLint k, GLchan *texel )
405 {
406 (void) k;
407 if (fetch_ext_rgb_dxt1) {
408 ASSERT (sizeof(GLchan) == sizeof(GLubyte));
409 fetch_ext_rgb_dxt1(texImage->RowStride,
410 (GLubyte *)(texImage)->Data, i, j, texel);
411 }
412 else
413 _mesa_debug(NULL, "attempted to decode s3tc texture without library available\n");
414 }
415
416
417 static void
418 fetch_texel_2d_f_rgb_dxt1( const struct gl_texture_image *texImage,
419 GLint i, GLint j, GLint k, GLfloat *texel )
420 {
421 /* just sample as GLchan and convert to float here */
422 GLchan rgba[4];
423 fetch_texel_2d_rgb_dxt1(texImage, i, j, k, rgba);
424 texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
425 texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
426 texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
427 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
428 }
429
430
431 static void
432 fetch_texel_2d_rgba_dxt1( const struct gl_texture_image *texImage,
433 GLint i, GLint j, GLint k, GLchan *texel )
434 {
435 (void) k;
436 if (fetch_ext_rgba_dxt1) {
437 fetch_ext_rgba_dxt1(texImage->RowStride,
438 (GLubyte *)(texImage)->Data, i, j, texel);
439 }
440 else
441 _mesa_debug(NULL, "attempted to decode s3tc texture without library available\n");
442 }
443
444
445 static void
446 fetch_texel_2d_f_rgba_dxt1( const struct gl_texture_image *texImage,
447 GLint i, GLint j, GLint k, GLfloat *texel )
448 {
449 /* just sample as GLchan and convert to float here */
450 GLchan rgba[4];
451 fetch_texel_2d_rgba_dxt1(texImage, i, j, k, rgba);
452 texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
453 texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
454 texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
455 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
456 }
457
458
459 static void
460 fetch_texel_2d_rgba_dxt3( const struct gl_texture_image *texImage,
461 GLint i, GLint j, GLint k, GLchan *texel )
462 {
463 (void) k;
464 if (fetch_ext_rgba_dxt3) {
465 ASSERT (sizeof(GLchan) == sizeof(GLubyte));
466 fetch_ext_rgba_dxt3(texImage->RowStride, (GLubyte *)(texImage)->Data,
467 i, j, texel);
468 }
469 else
470 _mesa_debug(NULL, "attempted to decode s3tc texture without library available\n");
471 }
472
473
474 static void
475 fetch_texel_2d_f_rgba_dxt3( const struct gl_texture_image *texImage,
476 GLint i, GLint j, GLint k, GLfloat *texel )
477 {
478 /* just sample as GLchan and convert to float here */
479 GLchan rgba[4];
480 fetch_texel_2d_rgba_dxt3(texImage, i, j, k, rgba);
481 texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
482 texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
483 texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
484 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
485 }
486
487
488 static void
489 fetch_texel_2d_rgba_dxt5( const struct gl_texture_image *texImage,
490 GLint i, GLint j, GLint k, GLchan *texel )
491 {
492 (void) k;
493 if (fetch_ext_rgba_dxt5) {
494 fetch_ext_rgba_dxt5(texImage->RowStride, (GLubyte *)(texImage)->Data,
495 i, j, texel);
496 }
497 else
498 _mesa_debug(NULL, "attempted to decode s3tc texture without library available\n");
499 }
500
501
502 static void
503 fetch_texel_2d_f_rgba_dxt5( const struct gl_texture_image *texImage,
504 GLint i, GLint j, GLint k, GLfloat *texel )
505 {
506 /* just sample as GLchan and convert to float here */
507 GLchan rgba[4];
508 fetch_texel_2d_rgba_dxt5(texImage, i, j, k, rgba);
509 texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
510 texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
511 texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
512 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
513 }
514
515 #if FEATURE_EXT_texture_sRGB
516 static void
517 fetch_texel_2d_f_srgb_dxt1( const struct gl_texture_image *texImage,
518 GLint i, GLint j, GLint k, GLfloat *texel )
519 {
520 /* just sample as GLchan and convert to float here */
521 GLchan rgba[4];
522 fetch_texel_2d_rgb_dxt1(texImage, i, j, k, rgba);
523 texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
524 texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
525 texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
526 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
527 }
528
529 static void
530 fetch_texel_2d_f_srgba_dxt1( const struct gl_texture_image *texImage,
531 GLint i, GLint j, GLint k, GLfloat *texel )
532 {
533 /* just sample as GLchan and convert to float here */
534 GLchan rgba[4];
535 fetch_texel_2d_rgba_dxt1(texImage, i, j, k, rgba);
536 texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
537 texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
538 texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
539 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
540 }
541
542 static void
543 fetch_texel_2d_f_srgba_dxt3( const struct gl_texture_image *texImage,
544 GLint i, GLint j, GLint k, GLfloat *texel )
545 {
546 /* just sample as GLchan and convert to float here */
547 GLchan rgba[4];
548 fetch_texel_2d_rgba_dxt3(texImage, i, j, k, rgba);
549 texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
550 texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
551 texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
552 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
553 }
554
555 static void
556 fetch_texel_2d_f_srgba_dxt5( const struct gl_texture_image *texImage,
557 GLint i, GLint j, GLint k, GLfloat *texel )
558 {
559 /* just sample as GLchan and convert to float here */
560 GLchan rgba[4];
561 fetch_texel_2d_rgba_dxt5(texImage, i, j, k, rgba);
562 texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
563 texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
564 texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
565 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
566 }
567 #endif
568
569 const struct gl_texture_format _mesa_texformat_rgb_dxt1 = {
570 MESA_FORMAT_RGB_DXT1, /* MesaFormat */
571 GL_RGB, /* BaseFormat */
572 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
573 4, /*approx*/ /* RedBits */
574 4, /*approx*/ /* GreenBits */
575 4, /*approx*/ /* BlueBits */
576 0, /* AlphaBits */
577 0, /* LuminanceBits */
578 0, /* IntensityBits */
579 0, /* IndexBits */
580 0, /* DepthBits */
581 0, /* StencilBits */
582 0, /* TexelBytes */
583 texstore_rgb_dxt1, /* StoreTexImageFunc */
584 NULL, /*impossible*/ /* FetchTexel1D */
585 fetch_texel_2d_rgb_dxt1, /* FetchTexel2D */
586 NULL, /*impossible*/ /* FetchTexel3D */
587 NULL, /*impossible*/ /* FetchTexel1Df */
588 fetch_texel_2d_f_rgb_dxt1, /* FetchTexel2Df */
589 NULL, /*impossible*/ /* FetchTexel3Df */
590 NULL /* StoreTexel */
591 };
592
593 const struct gl_texture_format _mesa_texformat_rgba_dxt1 = {
594 MESA_FORMAT_RGBA_DXT1, /* MesaFormat */
595 GL_RGBA, /* BaseFormat */
596 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
597 4, /*approx*/ /* RedBits */
598 4, /*approx*/ /* GreenBits */
599 4, /*approx*/ /* BlueBits */
600 1, /*approx*/ /* AlphaBits */
601 0, /* LuminanceBits */
602 0, /* IntensityBits */
603 0, /* IndexBits */
604 0, /* DepthBits */
605 0, /* StencilBits */
606 0, /* TexelBytes */
607 texstore_rgba_dxt1, /* StoreTexImageFunc */
608 NULL, /*impossible*/ /* FetchTexel1D */
609 fetch_texel_2d_rgba_dxt1, /* FetchTexel2D */
610 NULL, /*impossible*/ /* FetchTexel3D */
611 NULL, /*impossible*/ /* FetchTexel1Df */
612 fetch_texel_2d_f_rgba_dxt1, /* FetchTexel2Df */
613 NULL, /*impossible*/ /* FetchTexel3Df */
614 NULL /* StoreTexel */
615 };
616
617 const struct gl_texture_format _mesa_texformat_rgba_dxt3 = {
618 MESA_FORMAT_RGBA_DXT3, /* MesaFormat */
619 GL_RGBA, /* BaseFormat */
620 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
621 4, /*approx*/ /* RedBits */
622 4, /*approx*/ /* GreenBits */
623 4, /*approx*/ /* BlueBits */
624 4, /*approx*/ /* AlphaBits */
625 0, /* LuminanceBits */
626 0, /* IntensityBits */
627 0, /* IndexBits */
628 0, /* DepthBits */
629 0, /* StencilBits */
630 0, /* TexelBytes */
631 texstore_rgba_dxt3, /* StoreTexImageFunc */
632 NULL, /*impossible*/ /* FetchTexel1D */
633 fetch_texel_2d_rgba_dxt3, /* FetchTexel2D */
634 NULL, /*impossible*/ /* FetchTexel3D */
635 NULL, /*impossible*/ /* FetchTexel1Df */
636 fetch_texel_2d_f_rgba_dxt3, /* FetchTexel2Df */
637 NULL, /*impossible*/ /* FetchTexel3Df */
638 NULL /* StoreTexel */
639 };
640
641 const struct gl_texture_format _mesa_texformat_rgba_dxt5 = {
642 MESA_FORMAT_RGBA_DXT5, /* MesaFormat */
643 GL_RGBA, /* BaseFormat */
644 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
645 4,/*approx*/ /* RedBits */
646 4,/*approx*/ /* GreenBits */
647 4,/*approx*/ /* BlueBits */
648 4,/*approx*/ /* AlphaBits */
649 0, /* LuminanceBits */
650 0, /* IntensityBits */
651 0, /* IndexBits */
652 0, /* DepthBits */
653 0, /* StencilBits */
654 0, /* TexelBytes */
655 texstore_rgba_dxt5, /* StoreTexImageFunc */
656 NULL, /*impossible*/ /* FetchTexel1D */
657 fetch_texel_2d_rgba_dxt5, /* FetchTexel2D */
658 NULL, /*impossible*/ /* FetchTexel3D */
659 NULL, /*impossible*/ /* FetchTexel1Df */
660 fetch_texel_2d_f_rgba_dxt5, /* FetchTexel2Df */
661 NULL, /*impossible*/ /* FetchTexel3Df */
662 NULL /* StoreTexel */
663 };
664
665 #if FEATURE_EXT_texture_sRGB
666 const struct gl_texture_format _mesa_texformat_srgb_dxt1 = {
667 MESA_FORMAT_SRGB_DXT1, /* MesaFormat */
668 GL_RGB, /* BaseFormat */
669 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
670 4, /*approx*/ /* RedBits */
671 4, /*approx*/ /* GreenBits */
672 4, /*approx*/ /* BlueBits */
673 0, /* AlphaBits */
674 0, /* LuminanceBits */
675 0, /* IntensityBits */
676 0, /* IndexBits */
677 0, /* DepthBits */
678 0, /* StencilBits */
679 0, /* TexelBytes */
680 texstore_rgb_dxt1, /* StoreTexImageFunc */
681 NULL, /*impossible*/ /* FetchTexel1D */
682 NULL, /* FetchTexel2D */
683 NULL, /*impossible*/ /* FetchTexel3D */
684 NULL, /*impossible*/ /* FetchTexel1Df */
685 fetch_texel_2d_f_srgb_dxt1, /* FetchTexel2Df */
686 NULL, /*impossible*/ /* FetchTexel3Df */
687 NULL /* StoreTexel */
688 };
689
690 const struct gl_texture_format _mesa_texformat_srgba_dxt1 = {
691 MESA_FORMAT_SRGBA_DXT1, /* MesaFormat */
692 GL_RGBA, /* BaseFormat */
693 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
694 4, /*approx*/ /* RedBits */
695 4, /*approx*/ /* GreenBits */
696 4, /*approx*/ /* BlueBits */
697 1, /*approx*/ /* AlphaBits */
698 0, /* LuminanceBits */
699 0, /* IntensityBits */
700 0, /* IndexBits */
701 0, /* DepthBits */
702 0, /* StencilBits */
703 0, /* TexelBytes */
704 texstore_rgba_dxt1, /* StoreTexImageFunc */
705 NULL, /*impossible*/ /* FetchTexel1D */
706 NULL, /* FetchTexel2D */
707 NULL, /*impossible*/ /* FetchTexel3D */
708 NULL, /*impossible*/ /* FetchTexel1Df */
709 fetch_texel_2d_f_srgba_dxt1, /* FetchTexel2Df */
710 NULL, /*impossible*/ /* FetchTexel3Df */
711 NULL /* StoreTexel */
712 };
713
714 const struct gl_texture_format _mesa_texformat_srgba_dxt3 = {
715 MESA_FORMAT_SRGBA_DXT3, /* MesaFormat */
716 GL_RGBA, /* BaseFormat */
717 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
718 4, /*approx*/ /* RedBits */
719 4, /*approx*/ /* GreenBits */
720 4, /*approx*/ /* BlueBits */
721 4, /*approx*/ /* AlphaBits */
722 0, /* LuminanceBits */
723 0, /* IntensityBits */
724 0, /* IndexBits */
725 0, /* DepthBits */
726 0, /* StencilBits */
727 0, /* TexelBytes */
728 texstore_rgba_dxt3, /* StoreTexImageFunc */
729 NULL, /*impossible*/ /* FetchTexel1D */
730 NULL, /* FetchTexel2D */
731 NULL, /*impossible*/ /* FetchTexel3D */
732 NULL, /*impossible*/ /* FetchTexel1Df */
733 fetch_texel_2d_f_srgba_dxt3, /* FetchTexel2Df */
734 NULL, /*impossible*/ /* FetchTexel3Df */
735 NULL /* StoreTexel */
736 };
737
738 const struct gl_texture_format _mesa_texformat_srgba_dxt5 = {
739 MESA_FORMAT_SRGBA_DXT5, /* MesaFormat */
740 GL_RGBA, /* BaseFormat */
741 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
742 4,/*approx*/ /* RedBits */
743 4,/*approx*/ /* GreenBits */
744 4,/*approx*/ /* BlueBits */
745 4,/*approx*/ /* AlphaBits */
746 0, /* LuminanceBits */
747 0, /* IntensityBits */
748 0, /* IndexBits */
749 0, /* DepthBits */
750 0, /* StencilBits */
751 0, /* TexelBytes */
752 texstore_rgba_dxt5, /* StoreTexImageFunc */
753 NULL, /*impossible*/ /* FetchTexel1D */
754 NULL, /* FetchTexel2D */
755 NULL, /*impossible*/ /* FetchTexel3D */
756 NULL, /*impossible*/ /* FetchTexel1Df */
757 fetch_texel_2d_f_srgba_dxt5, /* FetchTexel2Df */
758 NULL, /*impossible*/ /* FetchTexel3Df */
759 NULL /* StoreTexel */
760 };
761 #endif