Lines 28-33
Link Here
|
28 |
* GL_EXT_texture_compression_s3tc support. |
28 |
* GL_EXT_texture_compression_s3tc support. |
29 |
*/ |
29 |
*/ |
30 |
|
30 |
|
|
|
31 |
#if defined(XFree86LOADER) && defined(IN_MODULE) |
32 |
#define USE_EXTERNAL_DXTN_LIB 0 |
33 |
#else |
34 |
#define USE_EXTERNAL_DXTN_LIB 1 |
35 |
#endif |
31 |
|
36 |
|
32 |
#include "glheader.h" |
37 |
#include "glheader.h" |
33 |
#include "imports.h" |
38 |
#include "imports.h" |
Lines 39-50
Link Here
|
39 |
#include "texformat.h" |
44 |
#include "texformat.h" |
40 |
#include "texstore.h" |
45 |
#include "texstore.h" |
41 |
|
46 |
|
|
|
47 |
#if USE_EXTERNAL_DXTN_LIB |
48 |
#include <dlfcn.h> |
49 |
#endif |
50 |
|
51 |
typedef void (*dxtFetchTexelFuncExt)( GLint srcRowstride, GLubyte *pixdata, GLint col, GLint row, GLvoid *texelOut ); |
52 |
dxtFetchTexelFuncExt fetch_ext_rgb_dxt1; |
53 |
dxtFetchTexelFuncExt fetch_ext_rgba_dxt1; |
54 |
dxtFetchTexelFuncExt fetch_ext_rgba_dxt3; |
55 |
dxtFetchTexelFuncExt fetch_ext_rgba_dxt5; |
42 |
|
56 |
|
|
|
57 |
typedef void (*dxtCompressTexFuncExt)(GLint srccomps, GLint width, GLint height, const GLubyte *srcPixData, GLenum destformat, GLubyte *dest); |
58 |
dxtCompressTexFuncExt ext_tx_compress_dxtn; |
59 |
|
60 |
void *dxtlibhandle = NULL; |
43 |
|
61 |
|
44 |
void |
62 |
void |
45 |
_mesa_init_texture_s3tc( GLcontext *ctx ) |
63 |
_mesa_init_texture_s3tc( GLcontext *ctx ) |
46 |
{ |
64 |
{ |
47 |
/* called during context initialization */ |
65 |
/* called during context initialization */ |
|
|
66 |
ctx->Mesa_DXTn = GL_FALSE; |
67 |
#if USE_EXTERNAL_DXTN_LIB |
68 |
if (!dxtlibhandle) { |
69 |
char *error; |
70 |
|
71 |
dxtlibhandle = dlopen ("libtxc_dxtn.so", RTLD_LAZY | RTLD_GLOBAL); |
72 |
if (!dxtlibhandle) { |
73 |
_mesa_debug(ctx, "couldn't open libtxc_dxtn.so, " |
74 |
"software DXTn compression/decompression unavailable\n"); |
75 |
} |
76 |
else { |
77 |
/* the fetch functions are not per context! Might be problematic... */ |
78 |
fetch_ext_rgb_dxt1 = dlsym(dxtlibhandle, "fetch_2d_texel_rgb_dxt1"); |
79 |
error = dlerror(); |
80 |
if (error == NULL) { |
81 |
fetch_ext_rgba_dxt1 = dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt1"); |
82 |
error = dlerror(); |
83 |
} |
84 |
if (error == NULL) { |
85 |
fetch_ext_rgba_dxt3 = dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt3"); |
86 |
error = dlerror(); |
87 |
} |
88 |
if (error == NULL) { |
89 |
fetch_ext_rgba_dxt5 = dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt5"); |
90 |
error = dlerror(); |
91 |
} |
92 |
if (error == NULL) { |
93 |
ext_tx_compress_dxtn = dlsym(dxtlibhandle, "tx_compress_dxtn"); |
94 |
error = dlerror(); |
95 |
} |
96 |
|
97 |
if (error) { |
98 |
_mesa_debug(ctx, "couldn't reference all symbols in libtxc_dxtn.so, " |
99 |
"software DXTn compression/decompression unavailable\n"); |
100 |
fetch_ext_rgb_dxt1 = NULL; |
101 |
fetch_ext_rgba_dxt1 = NULL; |
102 |
fetch_ext_rgba_dxt3 = NULL; |
103 |
fetch_ext_rgba_dxt5 = NULL; |
104 |
ext_tx_compress_dxtn = NULL; |
105 |
dlclose(dxtlibhandle); |
106 |
dxtlibhandle = NULL; |
107 |
} |
108 |
} |
109 |
} |
110 |
if (dxtlibhandle) { |
111 |
ctx->Mesa_DXTn = GL_TRUE; |
112 |
_mesa_debug(ctx, "software DXTn compression/decompression available\n"); |
113 |
} |
114 |
#else |
115 |
(void) ctx; |
116 |
#endif |
48 |
} |
117 |
} |
49 |
|
118 |
|
50 |
|
119 |
|
Lines 93-102
Link Here
|
93 |
GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
162 |
GL_COMPRESSED_RGB_S3TC_DXT1_EXT, |
94 |
texWidth, (GLubyte *) dstAddr); |
163 |
texWidth, (GLubyte *) dstAddr); |
95 |
|
164 |
|
96 |
#if 0 |
165 |
if (ext_tx_compress_dxtn) { |
97 |
compress_dxt1(ctx, srcWidth, srcHeight, srcFormat, pixels, srcRowStride, |
166 |
(*ext_tx_compress_dxtn)(3, srcWidth, srcHeight, pixels, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, dst); |
98 |
dst, dstRowStride); |
167 |
} |
99 |
#endif |
168 |
else { |
|
|
169 |
_mesa_problem(ctx, "external dxt library not available"); |
170 |
} |
100 |
|
171 |
|
101 |
if (tempImage) |
172 |
if (tempImage) |
102 |
_mesa_free((void *) tempImage); |
173 |
_mesa_free((void *) tempImage); |
Lines 149-158
Link Here
|
149 |
dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, |
220 |
dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, |
150 |
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, |
221 |
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, |
151 |
texWidth, (GLubyte *) dstAddr); |
222 |
texWidth, (GLubyte *) dstAddr); |
152 |
#if 0 |
223 |
if (ext_tx_compress_dxtn) { |
153 |
compress_dxt1(ctx, srcWidth, srcHeight, srcFormat, pixels, srcRowStride, |
224 |
(*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, dst); |
154 |
dst, dstRowStride); |
225 |
} |
155 |
#endif |
226 |
else { |
|
|
227 |
_mesa_problem(ctx, "external dxt library not available"); |
228 |
} |
229 |
|
156 |
if (tempImage) |
230 |
if (tempImage) |
157 |
_mesa_free((void*) tempImage); |
231 |
_mesa_free((void*) tempImage); |
158 |
|
232 |
|
Lines 203-212
Link Here
|
203 |
dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, |
277 |
dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, |
204 |
GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, |
278 |
GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, |
205 |
texWidth, (GLubyte *) dstAddr); |
279 |
texWidth, (GLubyte *) dstAddr); |
206 |
#if 0 |
280 |
if (ext_tx_compress_dxtn) { |
207 |
compress_rgba_dxt3(ctx, srcWidth, srcHeight, pixels, |
281 |
(*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, dst); |
208 |
srcRowStride, dst, dstRowStride); |
282 |
} |
209 |
#endif |
283 |
else { |
|
|
284 |
_mesa_problem(ctx, "external dxt library not available"); |
285 |
} |
286 |
|
210 |
if (tempImage) |
287 |
if (tempImage) |
211 |
_mesa_free((void *) tempImage); |
288 |
_mesa_free((void *) tempImage); |
212 |
|
289 |
|
Lines 257-266
Link Here
|
257 |
dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, |
334 |
dst = _mesa_compressed_image_address(dstXoffset, dstYoffset, 0, |
258 |
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, |
335 |
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, |
259 |
texWidth, (GLubyte *) dstAddr); |
336 |
texWidth, (GLubyte *) dstAddr); |
260 |
#if 0 |
337 |
if (ext_tx_compress_dxtn) { |
261 |
compress_rgba_dxt5(ctx, srcWidth, srcHeight, pixels, |
338 |
(*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, dst); |
262 |
srcRowStride, dst, dstRowStride); |
339 |
} |
263 |
#endif |
340 |
else { |
|
|
341 |
_mesa_problem(ctx, "external dxt library not available"); |
342 |
} |
343 |
|
264 |
if (tempImage) |
344 |
if (tempImage) |
265 |
_mesa_free((void *) tempImage); |
345 |
_mesa_free((void *) tempImage); |
266 |
|
346 |
|
Lines 272-277
Link Here
|
272 |
fetch_texel_2d_rgb_dxt1( const struct gl_texture_image *texImage, |
352 |
fetch_texel_2d_rgb_dxt1( const struct gl_texture_image *texImage, |
273 |
GLint i, GLint j, GLint k, GLchan *texel ) |
353 |
GLint i, GLint j, GLint k, GLchan *texel ) |
274 |
{ |
354 |
{ |
|
|
355 |
(void) k; |
356 |
if (fetch_ext_rgb_dxt1) { |
357 |
ASSERT (sizeof(GLchan) == sizeof(GLubyte)); |
358 |
(*fetch_ext_rgb_dxt1)((texImage)->RowStride, (GLubyte *)(texImage)->Data, i, j, texel); |
359 |
} |
360 |
else _mesa_debug(NULL, "attempted to decode s3tc texture without library available\n"); |
275 |
} |
361 |
} |
276 |
|
362 |
|
277 |
|
363 |
|
Lines 293-298
Link Here
|
293 |
fetch_texel_2d_rgba_dxt1( const struct gl_texture_image *texImage, |
379 |
fetch_texel_2d_rgba_dxt1( const struct gl_texture_image *texImage, |
294 |
GLint i, GLint j, GLint k, GLchan *texel ) |
380 |
GLint i, GLint j, GLint k, GLchan *texel ) |
295 |
{ |
381 |
{ |
|
|
382 |
(void) k; |
383 |
if (fetch_ext_rgba_dxt1) { |
384 |
(*fetch_ext_rgba_dxt1)((texImage)->RowStride, (GLubyte *)(texImage)->Data, i, j, texel); |
385 |
} |
386 |
else _mesa_debug(NULL, "attempted to decode s3tc texture without library available\n"); |
296 |
} |
387 |
} |
297 |
|
388 |
|
298 |
|
389 |
|
Lines 314-319
Link Here
|
314 |
fetch_texel_2d_rgba_dxt3( const struct gl_texture_image *texImage, |
405 |
fetch_texel_2d_rgba_dxt3( const struct gl_texture_image *texImage, |
315 |
GLint i, GLint j, GLint k, GLchan *texel ) |
406 |
GLint i, GLint j, GLint k, GLchan *texel ) |
316 |
{ |
407 |
{ |
|
|
408 |
(void) k; |
409 |
if (fetch_ext_rgba_dxt3) { |
410 |
ASSERT (sizeof(GLchan) == sizeof(GLubyte)); |
411 |
(*fetch_ext_rgba_dxt3)((texImage)->RowStride, (GLubyte *)(texImage)->Data, i, j, texel); |
412 |
} |
413 |
else _mesa_debug(NULL, "attempted to decode s3tc texture without library available\n"); |
317 |
} |
414 |
} |
318 |
|
415 |
|
319 |
|
416 |
|
Lines 335-340
Link Here
|
335 |
fetch_texel_2d_rgba_dxt5( const struct gl_texture_image *texImage, |
432 |
fetch_texel_2d_rgba_dxt5( const struct gl_texture_image *texImage, |
336 |
GLint i, GLint j, GLint k, GLchan *texel ) |
433 |
GLint i, GLint j, GLint k, GLchan *texel ) |
337 |
{ |
434 |
{ |
|
|
435 |
(void) k; |
436 |
if (fetch_ext_rgba_dxt5) { |
437 |
(*fetch_ext_rgba_dxt5)((texImage)->RowStride, (GLubyte *)(texImage)->Data, i, j, texel); |
438 |
} |
439 |
else _mesa_debug(NULL, "attempted to decode s3tc texture without library available\n"); |
338 |
} |
440 |
} |
339 |
|
441 |
|
340 |
|
442 |
|