2294fdca73c4b7b88acfb2922885a3056a2a6333
[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 "texcompress_s3tc.h"
45 #include "texformat.h"
46 #include "texstore.h"
47
48 #ifdef __MINGW32__
49 #define DXTN_LIBNAME "dxtn.dll"
50 #define RTLD_LAZY 0
51 #define RTLD_GLOBAL 0
52 #elif defined(__DJGPP__)
53 #define DXTN_LIBNAME "dxtn.dxe"
54 #else
55 #define DXTN_LIBNAME "libtxc_dxtn.so"
56 #endif
57
58 #if FEATURE_EXT_texture_sRGB
59 /**
60 * Convert an 8-bit sRGB value from non-linear space to a
61 * linear RGB value in [0, 1].
62 * Implemented with a 256-entry lookup table.
63 */
64 static INLINE GLfloat
65 nonlinear_to_linear(GLubyte cs8)
66 {
67 static GLfloat table[256];
68 static GLboolean tableReady = GL_FALSE;
69 if (!tableReady) {
70 /* compute lookup table now */
71 GLuint i;
72 for (i = 0; i < 256; i++) {
73 const GLfloat cs = UBYTE_TO_FLOAT(i);
74 if (cs <= 0.04045) {
75 table[i] = cs / 12.92f;
76 }
77 else {
78 table[i] = (GLfloat) _mesa_pow((cs + 0.055) / 1.055, 2.4);
79 }
80 }
81 tableReady = GL_TRUE;
82 }
83 return table[cs8];
84 }
85 #endif /* FEATURE_EXT_texture_sRGB */
86
87 typedef void (*dxtFetchTexelFuncExt)( GLint srcRowstride, GLubyte *pixdata, GLint col, GLint row, GLvoid *texelOut );
88
89 dxtFetchTexelFuncExt fetch_ext_rgb_dxt1 = NULL;
90 dxtFetchTexelFuncExt fetch_ext_rgba_dxt1 = NULL;
91 dxtFetchTexelFuncExt fetch_ext_rgba_dxt3 = NULL;
92 dxtFetchTexelFuncExt fetch_ext_rgba_dxt5 = NULL;
93
94 typedef void (*dxtCompressTexFuncExt)(GLint srccomps, GLint width,
95 GLint height, const GLchan *srcPixData,
96 GLenum destformat, GLubyte *dest,
97 GLint dstRowStride);
98
99 static dxtCompressTexFuncExt ext_tx_compress_dxtn = NULL;
100
101 static void *dxtlibhandle = NULL;
102
103
104 void
105 _mesa_init_texture_s3tc( GLcontext *ctx )
106 {
107 /* called during context initialization */
108 ctx->Mesa_DXTn = GL_FALSE;
109 #if USE_EXTERNAL_DXTN_LIB
110 if (!dxtlibhandle) {
111 dxtlibhandle = _mesa_dlopen(DXTN_LIBNAME, 0);
112 if (!dxtlibhandle) {
113 _mesa_warning(ctx, "couldn't open " DXTN_LIBNAME ", software DXTn "
114 "compression/decompression unavailable");
115 }
116 else {
117 /* the fetch functions are not per context! Might be problematic... */
118 fetch_ext_rgb_dxt1 = (dxtFetchTexelFuncExt)
119 _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgb_dxt1");
120 fetch_ext_rgba_dxt1 = (dxtFetchTexelFuncExt)
121 _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt1");
122 fetch_ext_rgba_dxt3 = (dxtFetchTexelFuncExt)
123 _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt3");
124 fetch_ext_rgba_dxt5 = (dxtFetchTexelFuncExt)
125 _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt5");
126 ext_tx_compress_dxtn = (dxtCompressTexFuncExt)
127 _mesa_dlsym(dxtlibhandle, "tx_compress_dxtn");
128
129 if (!fetch_ext_rgb_dxt1 ||
130 !fetch_ext_rgba_dxt1 ||
131 !fetch_ext_rgba_dxt3 ||
132 !fetch_ext_rgba_dxt5 ||
133 !ext_tx_compress_dxtn) {
134 _mesa_warning(ctx, "couldn't reference all symbols in "
135 DXTN_LIBNAME ", software DXTn compression/decompression "
136 "unavailable");
137 fetch_ext_rgb_dxt1 = NULL;
138 fetch_ext_rgba_dxt1 = NULL;
139 fetch_ext_rgba_dxt3 = NULL;
140 fetch_ext_rgba_dxt5 = NULL;
141 ext_tx_compress_dxtn = NULL;
142 _mesa_dlclose(dxtlibhandle);
143 dxtlibhandle = NULL;
144 }
145 }
146 }
147 if (dxtlibhandle) {
148 ctx->Mesa_DXTn = GL_TRUE;
149 _mesa_warning(ctx, "software DXTn compression/decompression available");
150 }
151 #else
152 (void) ctx;
153 #endif
154 }
155
156 /**
157 * Store user's image in rgb_dxt1 format.
158 */
159 GLboolean
160 _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
161 {
162 const GLchan *pixels;
163 GLint srcRowStride;
164 GLubyte *dst;
165 const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
166 const GLchan *tempImage = NULL;
167
168 ASSERT(dstFormat == &_mesa_texformat_rgb_dxt1);
169 ASSERT(dstXoffset % 4 == 0);
170 ASSERT(dstYoffset % 4 == 0);
171 ASSERT(dstZoffset % 4 == 0);
172 (void) dstZoffset;
173 (void) dstImageOffsets;
174
175 if (srcFormat != GL_RGB ||
176 srcType != CHAN_TYPE ||
177 ctx->_ImageTransferState ||
178 srcPacking->SwapBytes) {
179 /* convert image to RGB/GLchan */
180 tempImage = _mesa_make_temp_chan_image(ctx, dims,
181 baseInternalFormat,
182 dstFormat->BaseFormat,
183 srcWidth, srcHeight, srcDepth,
184 srcFormat, srcType, srcAddr,
185 srcPacking);
186 if (!tempImage)
187 return GL_FALSE; /* out of memory */
188 _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
189 pixels = tempImage;
190 srcRowStride = 3 * srcWidth;
191 srcFormat = GL_RGB;
192 }
193 else {
194 pixels = (const GLchan *) srcAddr;
195 srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
196 srcType) / sizeof(GLchan);
197 }
198
199 dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
200 dstFormat->MesaFormat,
201 texWidth, (GLubyte *) dstAddr);
202
203 if (ext_tx_compress_dxtn) {
204 (*ext_tx_compress_dxtn)(3, srcWidth, srcHeight, pixels,
205 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
206 dst, dstRowStride);
207 }
208 else {
209 _mesa_warning(ctx, "external dxt library not available: texstore_rgb_dxt1");
210 }
211
212 if (tempImage)
213 _mesa_free((void *) tempImage);
214
215 return GL_TRUE;
216 }
217
218
219 /**
220 * Store user's image in rgba_dxt1 format.
221 */
222 GLboolean
223 _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
224 {
225 const GLchan *pixels;
226 GLint srcRowStride;
227 GLubyte *dst;
228 const GLint texWidth = dstRowStride * 4 / 8; /* a bit of a hack */
229 const GLchan *tempImage = NULL;
230
231 ASSERT(dstFormat == &_mesa_texformat_rgba_dxt1);
232 ASSERT(dstXoffset % 4 == 0);
233 ASSERT(dstYoffset % 4 == 0);
234 ASSERT(dstZoffset % 4 == 0);
235 (void) dstZoffset;
236 (void) dstImageOffsets;
237
238 if (srcFormat != GL_RGBA ||
239 srcType != CHAN_TYPE ||
240 ctx->_ImageTransferState ||
241 srcPacking->SwapBytes) {
242 /* convert image to RGBA/GLchan */
243 tempImage = _mesa_make_temp_chan_image(ctx, dims,
244 baseInternalFormat,
245 dstFormat->BaseFormat,
246 srcWidth, srcHeight, srcDepth,
247 srcFormat, srcType, srcAddr,
248 srcPacking);
249 if (!tempImage)
250 return GL_FALSE; /* out of memory */
251 _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
252 pixels = tempImage;
253 srcRowStride = 4 * srcWidth;
254 srcFormat = GL_RGBA;
255 }
256 else {
257 pixels = (const GLchan *) srcAddr;
258 srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
259 srcType) / sizeof(GLchan);
260 }
261
262 dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
263 dstFormat->MesaFormat,
264 texWidth, (GLubyte *) dstAddr);
265 if (ext_tx_compress_dxtn) {
266 (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
267 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
268 dst, dstRowStride);
269 }
270 else {
271 _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt1");
272 }
273
274 if (tempImage)
275 _mesa_free((void*) tempImage);
276
277 return GL_TRUE;
278 }
279
280
281 /**
282 * Store user's image in rgba_dxt3 format.
283 */
284 GLboolean
285 _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
286 {
287 const GLchan *pixels;
288 GLint srcRowStride;
289 GLubyte *dst;
290 const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
291 const GLchan *tempImage = NULL;
292
293 ASSERT(dstFormat == &_mesa_texformat_rgba_dxt3);
294 ASSERT(dstXoffset % 4 == 0);
295 ASSERT(dstYoffset % 4 == 0);
296 ASSERT(dstZoffset % 4 == 0);
297 (void) dstZoffset;
298 (void) dstImageOffsets;
299
300 if (srcFormat != GL_RGBA ||
301 srcType != CHAN_TYPE ||
302 ctx->_ImageTransferState ||
303 srcPacking->SwapBytes) {
304 /* convert image to RGBA/GLchan */
305 tempImage = _mesa_make_temp_chan_image(ctx, dims,
306 baseInternalFormat,
307 dstFormat->BaseFormat,
308 srcWidth, srcHeight, srcDepth,
309 srcFormat, srcType, srcAddr,
310 srcPacking);
311 if (!tempImage)
312 return GL_FALSE; /* out of memory */
313 _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
314 pixels = tempImage;
315 srcRowStride = 4 * srcWidth;
316 }
317 else {
318 pixels = (const GLchan *) srcAddr;
319 srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
320 srcType) / sizeof(GLchan);
321 }
322
323 dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
324 dstFormat->MesaFormat,
325 texWidth, (GLubyte *) dstAddr);
326 if (ext_tx_compress_dxtn) {
327 (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
328 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
329 dst, dstRowStride);
330 }
331 else {
332 _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt3");
333 }
334
335 if (tempImage)
336 _mesa_free((void *) tempImage);
337
338 return GL_TRUE;
339 }
340
341
342 /**
343 * Store user's image in rgba_dxt5 format.
344 */
345 GLboolean
346 _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
347 {
348 const GLchan *pixels;
349 GLint srcRowStride;
350 GLubyte *dst;
351 const GLint texWidth = dstRowStride * 4 / 16; /* a bit of a hack */
352 const GLchan *tempImage = NULL;
353
354 ASSERT(dstFormat == &_mesa_texformat_rgba_dxt5);
355 ASSERT(dstXoffset % 4 == 0);
356 ASSERT(dstYoffset % 4 == 0);
357 ASSERT(dstZoffset % 4 == 0);
358 (void) dstZoffset;
359 (void) dstImageOffsets;
360
361 if (srcFormat != GL_RGBA ||
362 srcType != CHAN_TYPE ||
363 ctx->_ImageTransferState ||
364 srcPacking->SwapBytes) {
365 /* convert image to RGBA/GLchan */
366 tempImage = _mesa_make_temp_chan_image(ctx, dims,
367 baseInternalFormat,
368 dstFormat->BaseFormat,
369 srcWidth, srcHeight, srcDepth,
370 srcFormat, srcType, srcAddr,
371 srcPacking);
372 if (!tempImage)
373 return GL_FALSE; /* out of memory */
374 _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);
375 pixels = tempImage;
376 srcRowStride = 4 * srcWidth;
377 }
378 else {
379 pixels = (const GLchan *) srcAddr;
380 srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat,
381 srcType) / sizeof(GLchan);
382 }
383
384 dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0,
385 dstFormat->MesaFormat,
386 texWidth, (GLubyte *) dstAddr);
387 if (ext_tx_compress_dxtn) {
388 (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
389 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
390 dst, dstRowStride);
391 }
392 else {
393 _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt5");
394 }
395
396 if (tempImage)
397 _mesa_free((void *) tempImage);
398
399 return GL_TRUE;
400 }
401
402
403 static void
404 fetch_texel_2d_rgb_dxt1( const struct gl_texture_image *texImage,
405 GLint i, GLint j, GLint k, GLchan *texel )
406 {
407 (void) k;
408 if (fetch_ext_rgb_dxt1) {
409 ASSERT (sizeof(GLchan) == sizeof(GLubyte));
410 fetch_ext_rgb_dxt1(texImage->RowStride,
411 (GLubyte *)(texImage)->Data, i, j, texel);
412 }
413 else
414 _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgb_dxt1");
415 }
416
417
418 void
419 _mesa_fetch_texel_2d_f_rgb_dxt1(const struct gl_texture_image *texImage,
420 GLint i, GLint j, GLint k, GLfloat *texel)
421 {
422 /* just sample as GLchan and convert to float here */
423 GLchan rgba[4];
424 fetch_texel_2d_rgb_dxt1(texImage, i, j, k, rgba);
425 texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
426 texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
427 texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
428 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
429 }
430
431
432 static void
433 fetch_texel_2d_rgba_dxt1( const struct gl_texture_image *texImage,
434 GLint i, GLint j, GLint k, GLchan *texel )
435 {
436 (void) k;
437 if (fetch_ext_rgba_dxt1) {
438 fetch_ext_rgba_dxt1(texImage->RowStride,
439 (GLubyte *)(texImage)->Data, i, j, texel);
440 }
441 else
442 _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt1\n");
443 }
444
445
446 void
447 _mesa_fetch_texel_2d_f_rgba_dxt1(const struct gl_texture_image *texImage,
448 GLint i, GLint j, GLint k, GLfloat *texel)
449 {
450 /* just sample as GLchan and convert to float here */
451 GLchan rgba[4];
452 fetch_texel_2d_rgba_dxt1(texImage, i, j, k, rgba);
453 texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
454 texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
455 texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
456 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
457 }
458
459
460 static void
461 fetch_texel_2d_rgba_dxt3( const struct gl_texture_image *texImage,
462 GLint i, GLint j, GLint k, GLchan *texel )
463 {
464 (void) k;
465 if (fetch_ext_rgba_dxt3) {
466 ASSERT (sizeof(GLchan) == sizeof(GLubyte));
467 fetch_ext_rgba_dxt3(texImage->RowStride, (GLubyte *)(texImage)->Data,
468 i, j, texel);
469 }
470 else
471 _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt3\n");
472 }
473
474
475 void
476 _mesa_fetch_texel_2d_f_rgba_dxt3(const struct gl_texture_image *texImage,
477 GLint i, GLint j, GLint k, GLfloat *texel)
478 {
479 /* just sample as GLchan and convert to float here */
480 GLchan rgba[4];
481 fetch_texel_2d_rgba_dxt3(texImage, i, j, k, rgba);
482 texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
483 texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
484 texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
485 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
486 }
487
488
489 static void
490 fetch_texel_2d_rgba_dxt5( const struct gl_texture_image *texImage,
491 GLint i, GLint j, GLint k, GLchan *texel )
492 {
493 (void) k;
494 if (fetch_ext_rgba_dxt5) {
495 fetch_ext_rgba_dxt5(texImage->RowStride, (GLubyte *)(texImage)->Data,
496 i, j, texel);
497 }
498 else
499 _mesa_debug(NULL, "attempted to decode s3tc texture without library available: fetch_texel_2d_rgba_dxt5\n");
500 }
501
502
503 void
504 _mesa_fetch_texel_2d_f_rgba_dxt5(const struct gl_texture_image *texImage,
505 GLint i, GLint j, GLint k, GLfloat *texel)
506 {
507 /* just sample as GLchan and convert to float here */
508 GLchan rgba[4];
509 fetch_texel_2d_rgba_dxt5(texImage, i, j, k, rgba);
510 texel[RCOMP] = CHAN_TO_FLOAT(rgba[RCOMP]);
511 texel[GCOMP] = CHAN_TO_FLOAT(rgba[GCOMP]);
512 texel[BCOMP] = CHAN_TO_FLOAT(rgba[BCOMP]);
513 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
514 }
515
516 #if FEATURE_EXT_texture_sRGB
517 void
518 _mesa_fetch_texel_2d_f_srgb_dxt1( const struct gl_texture_image *texImage,
519 GLint i, GLint j, GLint k, GLfloat *texel )
520 {
521 /* just sample as GLchan and convert to float here */
522 GLchan rgba[4];
523 fetch_texel_2d_rgb_dxt1(texImage, i, j, k, rgba);
524 texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
525 texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
526 texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
527 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
528 }
529
530 void
531 _mesa_fetch_texel_2d_f_srgba_dxt1(const struct gl_texture_image *texImage,
532 GLint i, GLint j, GLint k, GLfloat *texel)
533 {
534 /* just sample as GLchan and convert to float here */
535 GLchan rgba[4];
536 fetch_texel_2d_rgba_dxt1(texImage, i, j, k, rgba);
537 texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
538 texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
539 texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
540 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
541 }
542
543 void
544 _mesa_fetch_texel_2d_f_srgba_dxt3(const struct gl_texture_image *texImage,
545 GLint i, GLint j, GLint k, GLfloat *texel)
546 {
547 /* just sample as GLchan and convert to float here */
548 GLchan rgba[4];
549 fetch_texel_2d_rgba_dxt3(texImage, i, j, k, rgba);
550 texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
551 texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
552 texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
553 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
554 }
555
556 void
557 _mesa_fetch_texel_2d_f_srgba_dxt5(const struct gl_texture_image *texImage,
558 GLint i, GLint j, GLint k, GLfloat *texel)
559 {
560 /* just sample as GLchan and convert to float here */
561 GLchan rgba[4];
562 fetch_texel_2d_rgba_dxt5(texImage, i, j, k, rgba);
563 texel[RCOMP] = nonlinear_to_linear(rgba[RCOMP]);
564 texel[GCOMP] = nonlinear_to_linear(rgba[GCOMP]);
565 texel[BCOMP] = nonlinear_to_linear(rgba[BCOMP]);
566 texel[ACOMP] = CHAN_TO_FLOAT(rgba[ACOMP]);
567 }
568 #endif
569
570 const struct gl_texture_format _mesa_texformat_rgb_dxt1 = {
571 MESA_FORMAT_RGB_DXT1, /* MesaFormat */
572 GL_RGB, /* BaseFormat */
573 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
574 4, /*approx*/ /* RedBits */
575 4, /*approx*/ /* GreenBits */
576 4, /*approx*/ /* BlueBits */
577 0, /* AlphaBits */
578 0, /* LuminanceBits */
579 0, /* IntensityBits */
580 0, /* IndexBits */
581 0, /* DepthBits */
582 0, /* StencilBits */
583 0, /* TexelBytes */
584 };
585
586 const struct gl_texture_format _mesa_texformat_rgba_dxt1 = {
587 MESA_FORMAT_RGBA_DXT1, /* MesaFormat */
588 GL_RGBA, /* BaseFormat */
589 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
590 4, /*approx*/ /* RedBits */
591 4, /*approx*/ /* GreenBits */
592 4, /*approx*/ /* BlueBits */
593 1, /*approx*/ /* AlphaBits */
594 0, /* LuminanceBits */
595 0, /* IntensityBits */
596 0, /* IndexBits */
597 0, /* DepthBits */
598 0, /* StencilBits */
599 0, /* TexelBytes */
600 };
601
602 const struct gl_texture_format _mesa_texformat_rgba_dxt3 = {
603 MESA_FORMAT_RGBA_DXT3, /* MesaFormat */
604 GL_RGBA, /* BaseFormat */
605 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
606 4, /*approx*/ /* RedBits */
607 4, /*approx*/ /* GreenBits */
608 4, /*approx*/ /* BlueBits */
609 4, /*approx*/ /* AlphaBits */
610 0, /* LuminanceBits */
611 0, /* IntensityBits */
612 0, /* IndexBits */
613 0, /* DepthBits */
614 0, /* StencilBits */
615 0, /* TexelBytes */
616 };
617
618 const struct gl_texture_format _mesa_texformat_rgba_dxt5 = {
619 MESA_FORMAT_RGBA_DXT5, /* MesaFormat */
620 GL_RGBA, /* BaseFormat */
621 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
622 4,/*approx*/ /* RedBits */
623 4,/*approx*/ /* GreenBits */
624 4,/*approx*/ /* BlueBits */
625 4,/*approx*/ /* AlphaBits */
626 0, /* LuminanceBits */
627 0, /* IntensityBits */
628 0, /* IndexBits */
629 0, /* DepthBits */
630 0, /* StencilBits */
631 0, /* TexelBytes */
632 };
633
634 #if FEATURE_EXT_texture_sRGB
635 const struct gl_texture_format _mesa_texformat_srgb_dxt1 = {
636 MESA_FORMAT_SRGB_DXT1, /* MesaFormat */
637 GL_RGB, /* BaseFormat */
638 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
639 4, /*approx*/ /* RedBits */
640 4, /*approx*/ /* GreenBits */
641 4, /*approx*/ /* BlueBits */
642 0, /* AlphaBits */
643 0, /* LuminanceBits */
644 0, /* IntensityBits */
645 0, /* IndexBits */
646 0, /* DepthBits */
647 0, /* StencilBits */
648 0, /* TexelBytes */
649 };
650
651 const struct gl_texture_format _mesa_texformat_srgba_dxt1 = {
652 MESA_FORMAT_SRGBA_DXT1, /* MesaFormat */
653 GL_RGBA, /* BaseFormat */
654 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
655 4, /*approx*/ /* RedBits */
656 4, /*approx*/ /* GreenBits */
657 4, /*approx*/ /* BlueBits */
658 1, /*approx*/ /* AlphaBits */
659 0, /* LuminanceBits */
660 0, /* IntensityBits */
661 0, /* IndexBits */
662 0, /* DepthBits */
663 0, /* StencilBits */
664 0, /* TexelBytes */
665 };
666
667 const struct gl_texture_format _mesa_texformat_srgba_dxt3 = {
668 MESA_FORMAT_SRGBA_DXT3, /* MesaFormat */
669 GL_RGBA, /* BaseFormat */
670 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
671 4, /*approx*/ /* RedBits */
672 4, /*approx*/ /* GreenBits */
673 4, /*approx*/ /* BlueBits */
674 4, /*approx*/ /* AlphaBits */
675 0, /* LuminanceBits */
676 0, /* IntensityBits */
677 0, /* IndexBits */
678 0, /* DepthBits */
679 0, /* StencilBits */
680 0, /* TexelBytes */
681 };
682
683 const struct gl_texture_format _mesa_texformat_srgba_dxt5 = {
684 MESA_FORMAT_SRGBA_DXT5, /* MesaFormat */
685 GL_RGBA, /* BaseFormat */
686 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
687 4,/*approx*/ /* RedBits */
688 4,/*approx*/ /* GreenBits */
689 4,/*approx*/ /* BlueBits */
690 4,/*approx*/ /* AlphaBits */
691 0, /* LuminanceBits */
692 0, /* IntensityBits */
693 0, /* IndexBits */
694 0, /* DepthBits */
695 0, /* StencilBits */
696 0, /* TexelBytes */
697 };
698 #endif