/[packages]/cauldron/mesa/current/SOURCES/0001-mesa-Squash-merge-of-S3TC-support.patch
ViewVC logotype

Contents of /cauldron/mesa/current/SOURCES/0001-mesa-Squash-merge-of-S3TC-support.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1173701 - (show annotations) (download)
Wed Oct 25 15:46:40 2017 UTC (6 years, 5 months ago) by tv
File size: 100064 byte(s)
always enable S3TC
1 From aff9c0e3d29983f90438dd4006e6f2654c878fd4 Mon Sep 17 00:00:00 2001
2 From: Matt Turner <mattst88@gmail.com>
3 Date: Wed, 27 Sep 2017 19:58:28 -0700
4 Subject: [PATCH] mesa: Squash merge of S3TC support
5
6 (cherry picked from commit 04396a134f003aece573df593acfa1ab4418ffe8)
7 (cherry picked from commit f7daa737d17df6d0a847e5c61e48d25e598671f4)
8 (cherry picked from commit 7ce9999166f24996d24d56d3effcae181d401111)
9 (cherry picked from commit 82c54c4fdc8495d7522c782141c080314459690a)
10 (cherry picked from commit fb5338c4b77db70ea26b0745cff1cb3e330a5139)
11 (cherry picked from commit 34cf3c43beed2fafb4512e921f39c818478f86d7)
12 (cherry picked from commit 78c6221f18ab451f2e57bc61852595a60f82e3cb)
13 (cherry picked from commit c5d508028454f42923aee1ea1ab876f01f680ae7)
14 (cherry picked from commit f6c56e07fc5a8e81fd90688c9fee239f18c3480e)
15 (cherry picked from commit 3a8a5e77e8f992aaa3539e060885138c2fcddad1)
16 (cherry picked from commit dc546a7bb3fae1d597e5a22d9527540ec4f072c8)
17 (cherry picked from commit c17c47207b96172ca9c85a16f7fb7f1d3ea959d8)
18 (cherry picked from commit 8d02abd0feaaef28a35d89903bd534a7f27c38d7)
19 (cherry picked from commit 74b5568978968f580b9809135198db1015bc55b7)
20 ---
21 configure.ac | 4 +-
22 src/gallium/auxiliary/util/u_format.c | 2 +-
23 src/gallium/auxiliary/util/u_format_s3tc.c | 133 +--
24 src/gallium/auxiliary/util/u_format_s3tc.h | 6 -
25 src/gallium/drivers/freedreno/freedreno_screen.c | 2 -
26 src/gallium/drivers/i915/i915_screen.c | 2 -
27 src/gallium/drivers/llvmpipe/lp_screen.c | 6 -
28 src/gallium/drivers/llvmpipe/lp_test_format.c | 7 -
29 src/gallium/drivers/nouveau/nouveau_screen.c | 2 -
30 src/gallium/drivers/r300/r300_screen.c | 3 +-
31 src/gallium/drivers/r300/r300_texture.c | 4 -
32 src/gallium/drivers/r600/r600_state_common.c | 4 -
33 src/gallium/drivers/radeon/r600_pipe_common.c | 1 -
34 src/gallium/drivers/radeonsi/si_state.c | 4 -
35 src/gallium/drivers/softpipe/sp_screen.c | 6 -
36 src/gallium/drivers/swr/swr_screen.cpp | 6 -
37 src/gallium/drivers/virgl/virgl_screen.c | 5 +-
38 src/gallium/include/state_tracker/st_api.h | 1 -
39 src/gallium/state_trackers/dri/dri_screen.c | 16 -
40 src/gallium/state_trackers/osmesa/osmesa.c | 1 -
41 src/gallium/tests/unit/u_format_test.c | 7 -
42 src/mesa/Makefile.sources | 1 -
43 src/mesa/SConscript | 4 -
44 src/mesa/drivers/dri/common/xmlpool/t_options.h | 5 -
45 src/mesa/drivers/dri/i915/intel_extensions.c | 5 +-
46 src/mesa/drivers/dri/i915/intel_screen.c | 1 -
47 src/mesa/drivers/dri/i965/intel_extensions.c | 4 +-
48 src/mesa/drivers/dri/i965/intel_screen.c | 2 -
49 src/mesa/drivers/dri/nouveau/nv10_context.c | 6 +-
50 src/mesa/drivers/dri/nouveau/nv20_context.c | 6 +-
51 src/mesa/drivers/dri/r200/r200_context.c | 10 +-
52 src/mesa/drivers/dri/radeon/radeon_context.c | 10 +-
53 src/mesa/drivers/dri/radeon/radeon_screen.c | 2 -
54 src/mesa/main/context.c | 2 -
55 src/mesa/main/dlopen.h | 97 ---
56 src/mesa/main/extensions.c | 6 +-
57 src/mesa/main/mtypes.h | 3 -
58 src/mesa/main/texcompress_s3tc.c | 269 ++----
59 src/mesa/main/texcompress_s3tc.h | 3 -
60 src/mesa/main/texcompress_s3tc_tmp.h | 989 +++++++++++++++++++++++
61 src/mesa/main/texformat.c | 14 +-
62 src/mesa/main/teximage.c | 32 -
63 src/mesa/state_tracker/st_context.c | 2 +-
64 src/mesa/state_tracker/st_extensions.c | 8 +-
65 src/mesa/state_tracker/st_extensions.h | 3 +-
66 src/mesa/state_tracker/st_format.c | 4 +-
67 src/mesa/state_tracker/st_manager.c | 2 +-
68 47 files changed, 1083 insertions(+), 629 deletions(-)
69 delete mode 100644 src/mesa/main/dlopen.h
70 create mode 100644 src/mesa/main/texcompress_s3tc_tmp.h
71
72 diff --git a/configure.ac b/configure.ac
73 index 49dd002502..cdce1ea8b1 100644
74 --- a/configure.ac
75 +++ b/configure.ac
76 @@ -862,9 +862,9 @@ AC_LINK_IFELSE([AC_LANG_SOURCE([[
77
78 dnl Check to see if dlopen is in default libraries (like Solaris, which
79 dnl has it in libc), or if libdl is needed to get it.
80 -AC_CHECK_FUNC([dlopen], [DEFINES="$DEFINES -DHAVE_DLOPEN"],
81 +AC_CHECK_FUNC([dlopen], [],
82 [AC_CHECK_LIB([dl], [dlopen],
83 - [DEFINES="$DEFINES -DHAVE_DLOPEN"; DLOPEN_LIBS="-ldl"])])
84 + [DLOPEN_LIBS="-ldl"])])
85 AC_SUBST([DLOPEN_LIBS])
86
87 dnl Check if that library also has dladdr
88 diff --git a/src/gallium/auxiliary/util/u_format.c b/src/gallium/auxiliary/util/u_format.c
89 index 3d281905ce..0fc3231654 100644
90 --- a/src/gallium/auxiliary/util/u_format.c
91 +++ b/src/gallium/auxiliary/util/u_format.c
92 @@ -238,7 +238,7 @@ util_format_is_subsampled_422(enum pipe_format format)
93 boolean
94 util_format_is_supported(enum pipe_format format, unsigned bind)
95 {
96 - if (util_format_is_s3tc(format) && !util_format_s3tc_enabled) {
97 + if (format >= PIPE_FORMAT_COUNT) {
98 return FALSE;
99 }
100
101 diff --git a/src/gallium/auxiliary/util/u_format_s3tc.c b/src/gallium/auxiliary/util/u_format_s3tc.c
102 index 8c4f2150be..3f755e5363 100644
103 --- a/src/gallium/auxiliary/util/u_format_s3tc.c
104 +++ b/src/gallium/auxiliary/util/u_format_s3tc.c
105 @@ -28,136 +28,15 @@
106 #include "u_format.h"
107 #include "u_format_s3tc.h"
108 #include "util/format_srgb.h"
109 +#include "../../../mesa/main/texcompress_s3tc_tmp.h"
110
111
112 -#if defined(_WIN32) || defined(WIN32)
113 -#define DXTN_LIBNAME "dxtn.dll"
114 -#elif defined(__CYGWIN__)
115 -#define DXTN_LIBNAME "cygtxc_dxtn.dll"
116 -#elif defined(__APPLE__)
117 -#define DXTN_LIBNAME "libtxc_dxtn.dylib"
118 -#else
119 -#define DXTN_LIBNAME "libtxc_dxtn.so"
120 -#endif
121 +util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgb_dxt1;
122 +util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt1;
123 +util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt3;
124 +util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt5;
125
126 -
127 -static void
128 -util_format_dxt1_rgb_fetch_stub(int src_stride,
129 - const uint8_t *src,
130 - int col, int row,
131 - uint8_t *dst)
132 -{
133 - assert(0);
134 -}
135 -
136 -
137 -static void
138 -util_format_dxt1_rgba_fetch_stub(int src_stride,
139 - const uint8_t *src,
140 - int col, int row,
141 - uint8_t *dst )
142 -{
143 - assert(0);
144 -}
145 -
146 -
147 -static void
148 -util_format_dxt3_rgba_fetch_stub(int src_stride,
149 - const uint8_t *src,
150 - int col, int row,
151 - uint8_t *dst )
152 -{
153 - assert(0);
154 -}
155 -
156 -
157 -static void
158 -util_format_dxt5_rgba_fetch_stub(int src_stride,
159 - const uint8_t *src,
160 - int col, int row,
161 - uint8_t *dst )
162 -{
163 - assert(0);
164 -}
165 -
166 -
167 -static void
168 -util_format_dxtn_pack_stub(int src_comps,
169 - int width, int height,
170 - const uint8_t *src,
171 - enum util_format_dxtn dst_format,
172 - uint8_t *dst,
173 - int dst_stride)
174 -{
175 - assert(0);
176 -}
177 -
178 -
179 -boolean util_format_s3tc_enabled = FALSE;
180 -
181 -util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch = util_format_dxt1_rgb_fetch_stub;
182 -util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch = util_format_dxt1_rgba_fetch_stub;
183 -util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch = util_format_dxt3_rgba_fetch_stub;
184 -util_format_dxtn_fetch_t util_format_dxt5_rgba_fetch = util_format_dxt5_rgba_fetch_stub;
185 -
186 -util_format_dxtn_pack_t util_format_dxtn_pack = util_format_dxtn_pack_stub;
187 -
188 -
189 -void
190 -util_format_s3tc_init(void)
191 -{
192 - static boolean first_time = TRUE;
193 - struct util_dl_library *library = NULL;
194 - util_dl_proc fetch_2d_texel_rgb_dxt1;
195 - util_dl_proc fetch_2d_texel_rgba_dxt1;
196 - util_dl_proc fetch_2d_texel_rgba_dxt3;
197 - util_dl_proc fetch_2d_texel_rgba_dxt5;
198 - util_dl_proc tx_compress_dxtn;
199 -
200 - if (!first_time)
201 - return;
202 - first_time = FALSE;
203 -
204 - if (util_format_s3tc_enabled)
205 - return;
206 -
207 - library = util_dl_open(DXTN_LIBNAME);
208 - if (!library) {
209 - debug_printf("couldn't open " DXTN_LIBNAME ", software DXTn "
210 - "compression/decompression unavailable\n");
211 - return;
212 - }
213 -
214 - fetch_2d_texel_rgb_dxt1 =
215 - util_dl_get_proc_address(library, "fetch_2d_texel_rgb_dxt1");
216 - fetch_2d_texel_rgba_dxt1 =
217 - util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt1");
218 - fetch_2d_texel_rgba_dxt3 =
219 - util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt3");
220 - fetch_2d_texel_rgba_dxt5 =
221 - util_dl_get_proc_address(library, "fetch_2d_texel_rgba_dxt5");
222 - tx_compress_dxtn =
223 - util_dl_get_proc_address(library, "tx_compress_dxtn");
224 -
225 - if (!util_format_dxt1_rgb_fetch ||
226 - !util_format_dxt1_rgba_fetch ||
227 - !util_format_dxt3_rgba_fetch ||
228 - !util_format_dxt5_rgba_fetch ||
229 - !util_format_dxtn_pack) {
230 - debug_printf("couldn't reference all symbols in " DXTN_LIBNAME
231 - ", software DXTn compression/decompression "
232 - "unavailable\n");
233 - util_dl_close(library);
234 - return;
235 - }
236 -
237 - util_format_dxt1_rgb_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgb_dxt1;
238 - util_format_dxt1_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt1;
239 - util_format_dxt3_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt3;
240 - util_format_dxt5_rgba_fetch = (util_format_dxtn_fetch_t)fetch_2d_texel_rgba_dxt5;
241 - util_format_dxtn_pack = (util_format_dxtn_pack_t)tx_compress_dxtn;
242 - util_format_s3tc_enabled = TRUE;
243 -}
244 +util_format_dxtn_pack_t util_format_dxtn_pack = (util_format_dxtn_pack_t)tx_compress_dxtn;
245
246
247 /*
248 diff --git a/src/gallium/auxiliary/util/u_format_s3tc.h b/src/gallium/auxiliary/util/u_format_s3tc.h
249 index ae20010cdf..6f188c67f9 100644
250 --- a/src/gallium/auxiliary/util/u_format_s3tc.h
251 +++ b/src/gallium/auxiliary/util/u_format_s3tc.h
252 @@ -58,8 +58,6 @@ typedef void
253 uint8_t *dst,
254 int dst_stride);
255
256 -extern boolean util_format_s3tc_enabled;
257 -
258 extern util_format_dxtn_fetch_t util_format_dxt1_rgb_fetch;
259 extern util_format_dxtn_fetch_t util_format_dxt1_rgba_fetch;
260 extern util_format_dxtn_fetch_t util_format_dxt3_rgba_fetch;
261 @@ -69,10 +67,6 @@ extern util_format_dxtn_pack_t util_format_dxtn_pack;
262
263
264 void
265 -util_format_s3tc_init(void);
266 -
267 -
268 -void
269 util_format_dxt1_rgb_unpack_rgba_8unorm(uint8_t *dst_row, unsigned dst_stride, const uint8_t *src_row, unsigned src_stride, unsigned width, unsigned height);
270
271 void
272 diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c b/src/gallium/drivers/freedreno/freedreno_screen.c
273 index a915d65ee0..59402ef3f6 100644
274 --- a/src/gallium/drivers/freedreno/freedreno_screen.c
275 +++ b/src/gallium/drivers/freedreno/freedreno_screen.c
276 @@ -875,8 +875,6 @@ fd_screen_create(struct fd_device *dev)
277
278 slab_create_parent(&screen->transfer_pool, sizeof(struct fd_transfer), 16);
279
280 - util_format_s3tc_init();
281 -
282 return pscreen;
283
284 fail:
285 diff --git a/src/gallium/drivers/i915/i915_screen.c b/src/gallium/drivers/i915/i915_screen.c
286 index 4ad98e2a08..b5675e417c 100644
287 --- a/src/gallium/drivers/i915/i915_screen.c
288 +++ b/src/gallium/drivers/i915/i915_screen.c
289 @@ -621,7 +621,5 @@ i915_screen_create(struct i915_winsys *iws)
290
291 i915_debug_init(is);
292
293 - util_format_s3tc_init();
294 -
295 return &is->base;
296 }
297 diff --git a/src/gallium/drivers/llvmpipe/lp_screen.c b/src/gallium/drivers/llvmpipe/lp_screen.c
298 index e98e30d50a..3ec68a5771 100644
299 --- a/src/gallium/drivers/llvmpipe/lp_screen.c
300 +++ b/src/gallium/drivers/llvmpipe/lp_screen.c
301 @@ -528,10 +528,6 @@ llvmpipe_is_format_supported( struct pipe_screen *_screen,
302 format != PIPE_FORMAT_ETC1_RGB8)
303 return FALSE;
304
305 - if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
306 - return util_format_s3tc_enabled;
307 - }
308 -
309 /*
310 * Everything can be supported by u_format
311 * (those without fetch_rgba_float might be not but shouldn't hit that)
312 @@ -682,7 +678,5 @@ llvmpipe_create_screen(struct sw_winsys *winsys)
313 }
314 (void) mtx_init(&screen->rast_mutex, mtx_plain);
315
316 - util_format_s3tc_init();
317 -
318 return &screen->base;
319 }
320 diff --git a/src/gallium/drivers/llvmpipe/lp_test_format.c b/src/gallium/drivers/llvmpipe/lp_test_format.c
321 index 9b16162131..e9a6e01fdc 100644
322 --- a/src/gallium/drivers/llvmpipe/lp_test_format.c
323 +++ b/src/gallium/drivers/llvmpipe/lp_test_format.c
324 @@ -357,8 +357,6 @@ test_all(unsigned verbose, FILE *fp)
325 enum pipe_format format;
326 boolean success = TRUE;
327
328 - util_format_s3tc_init();
329 -
330 #if USE_TEXTURE_CACHE
331 cache_ptr = align_malloc(sizeof(struct lp_build_format_cache), 16);
332 #endif
333 @@ -383,11 +381,6 @@ test_all(unsigned verbose, FILE *fp)
334 if (util_format_is_pure_integer(format))
335 continue;
336
337 - if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC &&
338 - !util_format_s3tc_enabled) {
339 - continue;
340 - }
341 -
342 /* only have util fetch func for etc1 */
343 if (format_desc->layout == UTIL_FORMAT_LAYOUT_ETC &&
344 format != PIPE_FORMAT_ETC1_RGB8) {
345 diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c
346 index 13b76d7681..ea68809c6e 100644
347 --- a/src/gallium/drivers/nouveau/nouveau_screen.c
348 +++ b/src/gallium/drivers/nouveau/nouveau_screen.c
349 @@ -242,8 +242,6 @@ nouveau_screen_init(struct nouveau_screen *screen, struct nouveau_device *dev)
350
351 nouveau_disk_cache_create(screen);
352
353 - util_format_s3tc_init();
354 -
355 screen->lowmem_bindings = PIPE_BIND_GLOBAL; /* gallium limit */
356 screen->vidmem_bindings =
357 PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL |
358 diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c
359 index 5cdb24871c..82d7183b9e 100644
360 --- a/src/gallium/drivers/r300/r300_screen.c
361 +++ b/src/gallium/drivers/r300/r300_screen.c
362 @@ -127,7 +127,7 @@ static int r300_get_param(struct pipe_screen* pscreen, enum pipe_cap param)
363
364 /* r300 cannot do swizzling of compressed textures. Supported otherwise. */
365 case PIPE_CAP_TEXTURE_SWIZZLE:
366 - return util_format_s3tc_enabled ? r300screen->caps.dxtc_swizzle : 1;
367 + return r300screen->caps.dxtc_swizzle;
368
369 /* We don't support color clamping on r500, so that we can use color
370 * intepolators for generic varyings. */
371 @@ -762,7 +762,6 @@ struct pipe_screen* r300_screen_create(struct radeon_winsys *rws, unsigned flags
372
373 slab_create_parent(&r300screen->pool_transfers, sizeof(struct pipe_transfer), 64);
374
375 - util_format_s3tc_init();
376 (void) mtx_init(&r300screen->cmask_mutex, mtx_plain);
377
378 return &r300screen->screen;
379 diff --git a/src/gallium/drivers/r300/r300_texture.c b/src/gallium/drivers/r300/r300_texture.c
380 index cdf9ccb973..87632fcbb4 100644
381 --- a/src/gallium/drivers/r300/r300_texture.c
382 +++ b/src/gallium/drivers/r300/r300_texture.c
383 @@ -251,10 +251,6 @@ uint32_t r300_translate_texformat(enum pipe_format format,
384
385 /* S3TC formats. */
386 if (desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
387 - if (!util_format_s3tc_enabled) {
388 - return ~0; /* Unsupported. */
389 - }
390 -
391 switch (format) {
392 case PIPE_FORMAT_DXT1_RGB:
393 case PIPE_FORMAT_DXT1_RGBA:
394 diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
395 index 4c97efa73b..306b3c0abb 100644
396 --- a/src/gallium/drivers/r600/r600_state_common.c
397 +++ b/src/gallium/drivers/r600/r600_state_common.c
398 @@ -2403,10 +2403,6 @@ uint32_t r600_translate_texformat(struct pipe_screen *screen,
399 }
400
401 if (desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
402 - if (!util_format_s3tc_enabled) {
403 - goto out_unknown;
404 - }
405 -
406 switch (format) {
407 case PIPE_FORMAT_DXT1_RGB:
408 case PIPE_FORMAT_DXT1_RGBA:
409 diff --git a/src/gallium/drivers/radeon/r600_pipe_common.c b/src/gallium/drivers/radeon/r600_pipe_common.c
410 index b02203c3c1..a3c6ed0a22 100644
411 --- a/src/gallium/drivers/radeon/r600_pipe_common.c
412 +++ b/src/gallium/drivers/radeon/r600_pipe_common.c
413 @@ -1408,7 +1408,6 @@ bool r600_common_screen_init(struct r600_common_screen *rscreen,
414 1 << util_logbase2(rscreen->force_aniso));
415 }
416
417 - util_format_s3tc_init();
418 (void) mtx_init(&rscreen->aux_context_lock, mtx_plain);
419 (void) mtx_init(&rscreen->gpu_load_mutex, mtx_plain);
420
421 diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c
422 index c610103032..931c326b49 100644
423 --- a/src/gallium/drivers/radeonsi/si_state.c
424 +++ b/src/gallium/drivers/radeonsi/si_state.c
425 @@ -1525,10 +1525,6 @@ static uint32_t si_translate_texformat(struct pipe_screen *screen,
426 if (!enable_compressed_formats)
427 goto out_unknown;
428
429 - if (!util_format_s3tc_enabled) {
430 - goto out_unknown;
431 - }
432 -
433 switch (format) {
434 case PIPE_FORMAT_DXT1_RGB:
435 case PIPE_FORMAT_DXT1_RGBA:
436 diff --git a/src/gallium/drivers/softpipe/sp_screen.c b/src/gallium/drivers/softpipe/sp_screen.c
437 index 5c96a14c80..6aa6beb1ad 100644
438 --- a/src/gallium/drivers/softpipe/sp_screen.c
439 +++ b/src/gallium/drivers/softpipe/sp_screen.c
440 @@ -455,10 +455,6 @@ softpipe_is_format_supported( struct pipe_screen *screen,
441 * All other operations (sampling, transfer, etc).
442 */
443
444 - if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
445 - return util_format_s3tc_enabled;
446 - }
447 -
448 /*
449 * Everything else should be supported by u_format.
450 */
451 @@ -585,8 +581,6 @@ softpipe_create_screen(struct sw_winsys *winsys)
452 screen->base.get_compute_param = softpipe_get_compute_param;
453 screen->use_llvm = debug_get_option_use_llvm();
454
455 - util_format_s3tc_init();
456 -
457 softpipe_init_screen_texture_funcs(&screen->base);
458 softpipe_init_screen_fence_funcs(&screen->base);
459
460 diff --git a/src/gallium/drivers/swr/swr_screen.cpp b/src/gallium/drivers/swr/swr_screen.cpp
461 index 952ae0c77a..d4f4ee8da1 100644
462 --- a/src/gallium/drivers/swr/swr_screen.cpp
463 +++ b/src/gallium/drivers/swr/swr_screen.cpp
464 @@ -147,10 +147,6 @@ swr_is_format_supported(struct pipe_screen *_screen,
465 return FALSE;
466 }
467
468 - if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
469 - return util_format_s3tc_enabled;
470 - }
471 -
472 return TRUE;
473 }
474
475 @@ -1140,8 +1136,6 @@ swr_create_screen_internal(struct sw_winsys *winsys)
476
477 swr_fence_init(&screen->base);
478
479 - util_format_s3tc_init();
480 -
481 swr_validate_env_options(screen);
482
483 return &screen->base;
484 diff --git a/src/gallium/drivers/virgl/virgl_screen.c b/src/gallium/drivers/virgl/virgl_screen.c
485 index 5df08407d7..c8c29d0812 100644
486 --- a/src/gallium/drivers/virgl/virgl_screen.c
487 +++ b/src/gallium/drivers/virgl/virgl_screen.c
488 @@ -480,9 +480,7 @@ virgl_is_format_supported( struct pipe_screen *screen,
489 */
490
491 if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
492 - if (util_format_s3tc_enabled)
493 - goto out_lookup;
494 - return FALSE;
495 + goto out_lookup;
496 }
497 if (format_desc->layout == UTIL_FORMAT_LAYOUT_RGTC) {
498 goto out_lookup;
499 @@ -606,6 +604,5 @@ virgl_create_screen(struct virgl_winsys *vws)
500
501 slab_create_parent(&screen->texture_transfer_pool, sizeof(struct virgl_transfer), 16);
502
503 - util_format_s3tc_init();
504 return &screen->base;
505 }
506 diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h
507 index bc62a69da3..fe9fb1816a 100644
508 --- a/src/gallium/include/state_tracker/st_api.h
509 +++ b/src/gallium/include/state_tracker/st_api.h
510 @@ -246,7 +246,6 @@ struct st_config_options
511 boolean disable_shader_bit_encoding;
512 boolean force_glsl_extensions_warn;
513 unsigned force_glsl_version;
514 - boolean force_s3tc_enable;
515 boolean allow_glsl_extension_directive_midshader;
516 boolean allow_glsl_builtin_variable_redeclaration;
517 boolean allow_higher_compat_version;
518 diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c
519 index 6bd479074f..09af6a6234 100644
520 --- a/src/gallium/state_trackers/dri/dri_screen.c
521 +++ b/src/gallium/state_trackers/dri/dri_screen.c
522 @@ -62,7 +62,6 @@ const __DRIconfigOptionsExtension gallium_config_options = {
523 DRI_CONF_SECTION_END
524
525 DRI_CONF_SECTION_QUALITY
526 - DRI_CONF_FORCE_S3TC_ENABLE("false")
527 DRI_CONF_PP_CELSHADE(0)
528 DRI_CONF_PP_NORED(0)
529 DRI_CONF_PP_NOGREEN(0)
530 @@ -109,8 +108,6 @@ dri_fill_st_options(struct dri_screen *screen)
531 driQueryOptionb(optionCache, "force_glsl_extensions_warn");
532 options->force_glsl_version =
533 driQueryOptioni(optionCache, "force_glsl_version");
534 - options->force_s3tc_enable =
535 - driQueryOptionb(optionCache, "force_s3tc_enable");
536 options->allow_glsl_extension_directive_midshader =
537 driQueryOptionb(optionCache, "allow_glsl_extension_directive_midshader");
538 options->allow_glsl_builtin_variable_redeclaration =
539 @@ -564,19 +561,6 @@ dri_init_screen_helper(struct dri_screen *screen,
540 else
541 screen->target = PIPE_TEXTURE_RECT;
542
543 - /* Handle force_s3tc_enable. */
544 - if (!util_format_s3tc_enabled && screen->options.force_s3tc_enable) {
545 - /* Ensure libtxc_dxtn has been loaded if available.
546 - * Forcing S3TC on before calling this would prevent loading
547 - * the library.
548 - * This is just a precaution, the driver should have called it
549 - * already.
550 - */
551 - util_format_s3tc_init();
552 -
553 - util_format_s3tc_enabled = TRUE;
554 - }
555 -
556 dri_postprocessing_init(screen);
557
558 screen->st_api->query_versions(screen->st_api, &screen->base,
559 diff --git a/src/gallium/state_trackers/osmesa/osmesa.c b/src/gallium/state_trackers/osmesa/osmesa.c
560 index 751d255c54..2f9558db31 100644
561 --- a/src/gallium/state_trackers/osmesa/osmesa.c
562 +++ b/src/gallium/state_trackers/osmesa/osmesa.c
563 @@ -688,7 +688,6 @@ OSMesaCreateContextAttribs(const int *attribList, OSMesaContext sharelist)
564 attribs.options.disable_blend_func_extended = FALSE;
565 attribs.options.disable_glsl_line_continuations = FALSE;
566 attribs.options.disable_shader_bit_encoding = FALSE;
567 - attribs.options.force_s3tc_enable = FALSE;
568 attribs.options.force_glsl_version = 0;
569
570 osmesa_init_st_visual(&attribs.visual,
571 diff --git a/src/gallium/tests/unit/u_format_test.c b/src/gallium/tests/unit/u_format_test.c
572 index 69d6c7dd3a..6de581fd04 100644
573 --- a/src/gallium/tests/unit/u_format_test.c
574 +++ b/src/gallium/tests/unit/u_format_test.c
575 @@ -722,11 +722,6 @@ test_all(void)
576 assert(format_desc->block.height <= UTIL_FORMAT_MAX_UNPACKED_HEIGHT);
577 assert(format_desc->block.width <= UTIL_FORMAT_MAX_UNPACKED_WIDTH);
578
579 - if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC &&
580 - !util_format_s3tc_enabled) {
581 - continue;
582 - }
583 -
584 # define TEST_ONE_FUNC(name) \
585 if (format_desc->name) { \
586 if (!test_one_func(format_desc, &test_format_##name, #name)) { \
587 @@ -758,8 +753,6 @@ int main(int argc, char **argv)
588 {
589 boolean success;
590
591 - util_format_s3tc_init();
592 -
593 success = test_all();
594
595 return success ? 0 : 1;
596 diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
597 index 86fbf3974e..bc93ded3db 100644
598 --- a/src/mesa/Makefile.sources
599 +++ b/src/mesa/Makefile.sources
600 @@ -67,7 +67,6 @@ MAIN_FILES = \
601 main/depth.h \
602 main/dlist.c \
603 main/dlist.h \
604 - main/dlopen.h \
605 main/drawpix.c \
606 main/drawpix.h \
607 main/drawtex.c \
608 diff --git a/src/mesa/SConscript b/src/mesa/SConscript
609 index b63e15a3f0..ba98ad4323 100644
610 --- a/src/mesa/SConscript
611 +++ b/src/mesa/SConscript
612 @@ -31,10 +31,6 @@ if env['platform'] == 'windows':
613 if not env['gles']:
614 # prevent _glapi_* from being declared __declspec(dllimport)
615 env.Append(CPPDEFINES = ['_GLAPI_NO_EXPORTS'])
616 -else:
617 - env.Append(CPPDEFINES = [
618 - ('HAVE_DLOPEN', '1'),
619 - ])
620
621 # parse Makefile.sources
622 source_lists = env.ParseSourceList('Makefile.sources')
623 diff --git a/src/mesa/drivers/dri/common/xmlpool/t_options.h b/src/mesa/drivers/dri/common/xmlpool/t_options.h
624 index e308839aa7..afe342df07 100644
625 --- a/src/mesa/drivers/dri/common/xmlpool/t_options.h
626 +++ b/src/mesa/drivers/dri/common/xmlpool/t_options.h
627 @@ -172,11 +172,6 @@ DRI_CONF_OPT_BEGIN_B(no_neg_lod_bias, def) \
628 DRI_CONF_DESC(en,gettext("Forbid negative texture LOD bias")) \
629 DRI_CONF_OPT_END
630
631 -#define DRI_CONF_FORCE_S3TC_ENABLE(def) \
632 -DRI_CONF_OPT_BEGIN_B(force_s3tc_enable, def) \
633 - DRI_CONF_DESC(en,gettext("Enable S3TC texture compression even if software support is not available")) \
634 -DRI_CONF_OPT_END
635 -
636 #define DRI_CONF_PRECISE_TRIG(def) \
637 DRI_CONF_OPT_BEGIN_B(precise_trig, def) \
638 DRI_CONF_DESC(en,gettext("Prefer accuracy over performance in trig functions")) \
639 diff --git a/src/mesa/drivers/dri/i915/intel_extensions.c b/src/mesa/drivers/dri/i915/intel_extensions.c
640 index 4f2c6fa34e..c85bd787fe 100644
641 --- a/src/mesa/drivers/dri/i915/intel_extensions.c
642 +++ b/src/mesa/drivers/dri/i915/intel_extensions.c
643 @@ -100,9 +100,6 @@ intelInitExtensions(struct gl_context *ctx)
644 ctx->Extensions.ARB_occlusion_query = true;
645 }
646
647 - if (intel->ctx.Mesa_DXTn
648 - || driQueryOptionb(&intel->optionCache, "force_s3tc_enable"))
649 - ctx->Extensions.EXT_texture_compression_s3tc = true;
650 -
651 + ctx->Extensions.EXT_texture_compression_s3tc = true;
652 ctx->Extensions.ANGLE_texture_compression_dxt = true;
653 }
654 diff --git a/src/mesa/drivers/dri/i915/intel_screen.c b/src/mesa/drivers/dri/i915/intel_screen.c
655 index 863f6ef7ec..c223133363 100644
656 --- a/src/mesa/drivers/dri/i915/intel_screen.c
657 +++ b/src/mesa/drivers/dri/i915/intel_screen.c
658 @@ -67,7 +67,6 @@ DRI_CONF_BEGIN
659
660 DRI_CONF_SECTION_END
661 DRI_CONF_SECTION_QUALITY
662 - DRI_CONF_FORCE_S3TC_ENABLE("false")
663 DRI_CONF_SECTION_END
664 DRI_CONF_SECTION_DEBUG
665 DRI_CONF_NO_RAST("false")
666 diff --git a/src/mesa/drivers/dri/i965/intel_extensions.c b/src/mesa/drivers/dri/i965/intel_extensions.c
667 index b91bbdc8d9..4fe97a0ce7 100644
668 --- a/src/mesa/drivers/dri/i965/intel_extensions.c
669 +++ b/src/mesa/drivers/dri/i965/intel_extensions.c
670 @@ -297,8 +297,6 @@ intelInitExtensions(struct gl_context *ctx)
671 if (ctx->API != API_OPENGL_CORE)
672 ctx->Extensions.ARB_color_buffer_float = true;
673
674 - if (ctx->Mesa_DXTn || driQueryOptionb(&brw->optionCache, "force_s3tc_enable"))
675 - ctx->Extensions.EXT_texture_compression_s3tc = true;
676 -
677 + ctx->Extensions.EXT_texture_compression_s3tc = true;
678 ctx->Extensions.ANGLE_texture_compression_dxt = true;
679 }
680 diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
681 index 5adb8ef1f6..e60f9fb10a 100644
682 --- a/src/mesa/drivers/dri/i965/intel_screen.c
683 +++ b/src/mesa/drivers/dri/i965/intel_screen.c
684 @@ -69,8 +69,6 @@ DRI_CONF_BEGIN
685 DRI_CONF_SECTION_END
686
687 DRI_CONF_SECTION_QUALITY
688 - DRI_CONF_FORCE_S3TC_ENABLE("false")
689 -
690 DRI_CONF_PRECISE_TRIG("false")
691
692 DRI_CONF_OPT_BEGIN(clamp_max_samples, int, -1)
693 diff --git a/src/mesa/drivers/dri/nouveau/nv10_context.c b/src/mesa/drivers/dri/nouveau/nv10_context.c
694 index 7a86ba2358..be2178fb79 100644
695 --- a/src/mesa/drivers/dri/nouveau/nv10_context.c
696 +++ b/src/mesa/drivers/dri/nouveau/nv10_context.c
697 @@ -451,10 +451,8 @@ nv10_context_create(struct nouveau_screen *screen, gl_api api,
698 ctx->Extensions.EXT_texture_env_dot3 = true;
699 ctx->Extensions.NV_fog_distance = true;
700 ctx->Extensions.NV_texture_rectangle = true;
701 - if (ctx->Mesa_DXTn) {
702 - ctx->Extensions.EXT_texture_compression_s3tc = true;
703 - ctx->Extensions.ANGLE_texture_compression_dxt = true;
704 - }
705 + ctx->Extensions.EXT_texture_compression_s3tc = true;
706 + ctx->Extensions.ANGLE_texture_compression_dxt = true;
707
708 /* GL constants. */
709 ctx->Const.MaxTextureLevels = 12;
710 diff --git a/src/mesa/drivers/dri/nouveau/nv20_context.c b/src/mesa/drivers/dri/nouveau/nv20_context.c
711 index ec638c036b..0ab2db0b08 100644
712 --- a/src/mesa/drivers/dri/nouveau/nv20_context.c
713 +++ b/src/mesa/drivers/dri/nouveau/nv20_context.c
714 @@ -462,10 +462,8 @@ nv20_context_create(struct nouveau_screen *screen, gl_api api,
715 ctx->Extensions.EXT_texture_env_dot3 = true;
716 ctx->Extensions.NV_fog_distance = true;
717 ctx->Extensions.NV_texture_rectangle = true;
718 - if (ctx->Mesa_DXTn) {
719 - ctx->Extensions.EXT_texture_compression_s3tc = true;
720 - ctx->Extensions.ANGLE_texture_compression_dxt = true;
721 - }
722 + ctx->Extensions.EXT_texture_compression_s3tc = true;
723 + ctx->Extensions.ANGLE_texture_compression_dxt = true;
724
725 /* GL constants. */
726 ctx->Const.MaxTextureCoordUnits = NV20_TEXTURE_UNITS;
727 diff --git a/src/mesa/drivers/dri/r200/r200_context.c b/src/mesa/drivers/dri/r200/r200_context.c
728 index 5a7f33499b..de15d520fe 100644
729 --- a/src/mesa/drivers/dri/r200/r200_context.c
730 +++ b/src/mesa/drivers/dri/r200/r200_context.c
731 @@ -362,14 +362,8 @@ GLboolean r200CreateContext( gl_api api,
732 others get the bit ordering right but don't actually do YUV-RGB conversion */
733 ctx->Extensions.MESA_ycbcr_texture = true;
734 }
735 - if (rmesa->radeon.glCtx.Mesa_DXTn) {
736 - ctx->Extensions.EXT_texture_compression_s3tc = true;
737 - ctx->Extensions.ANGLE_texture_compression_dxt = true;
738 - }
739 - else if (driQueryOptionb (&rmesa->radeon.optionCache, "force_s3tc_enable")) {
740 - ctx->Extensions.EXT_texture_compression_s3tc = true;
741 - ctx->Extensions.ANGLE_texture_compression_dxt = true;
742 - }
743 + ctx->Extensions.EXT_texture_compression_s3tc = true;
744 + ctx->Extensions.ANGLE_texture_compression_dxt = true;
745
746 #if 0
747 r200InitDriverFuncs( ctx );
748 diff --git a/src/mesa/drivers/dri/radeon/radeon_context.c b/src/mesa/drivers/dri/radeon/radeon_context.c
749 index 5ef3467ac1..e84b544c19 100644
750 --- a/src/mesa/drivers/dri/radeon/radeon_context.c
751 +++ b/src/mesa/drivers/dri/radeon/radeon_context.c
752 @@ -310,14 +310,8 @@ r100CreateContext( gl_api api,
753 ctx->Extensions.NV_texture_rectangle = true;
754 ctx->Extensions.OES_EGL_image = true;
755
756 - if (rmesa->radeon.glCtx.Mesa_DXTn) {
757 - ctx->Extensions.EXT_texture_compression_s3tc = true;
758 - ctx->Extensions.ANGLE_texture_compression_dxt = true;
759 - }
760 - else if (driQueryOptionb (&rmesa->radeon.optionCache, "force_s3tc_enable")) {
761 - ctx->Extensions.EXT_texture_compression_s3tc = true;
762 - ctx->Extensions.ANGLE_texture_compression_dxt = true;
763 - }
764 + ctx->Extensions.EXT_texture_compression_s3tc = true;
765 + ctx->Extensions.ANGLE_texture_compression_dxt = true;
766
767 /* XXX these should really go right after _mesa_init_driver_functions() */
768 radeon_fbo_init(&rmesa->radeon);
769 diff --git a/src/mesa/drivers/dri/radeon/radeon_screen.c b/src/mesa/drivers/dri/radeon/radeon_screen.c
770 index 0f072aff20..4192283fee 100644
771 --- a/src/mesa/drivers/dri/radeon/radeon_screen.c
772 +++ b/src/mesa/drivers/dri/radeon/radeon_screen.c
773 @@ -86,7 +86,6 @@ DRI_CONF_BEGIN
774 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB)
775 DRI_CONF_DEF_MAX_ANISOTROPY(1.0,"1.0,2.0,4.0,8.0,16.0")
776 DRI_CONF_NO_NEG_LOD_BIAS("false")
777 - DRI_CONF_FORCE_S3TC_ENABLE("false")
778 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER)
779 DRI_CONF_ROUND_MODE(DRI_CONF_ROUND_TRUNC)
780 DRI_CONF_DITHER_MODE(DRI_CONF_DITHER_XERRORDIFF)
781 @@ -113,7 +112,6 @@ DRI_CONF_BEGIN
782 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB)
783 DRI_CONF_DEF_MAX_ANISOTROPY(1.0,"1.0,2.0,4.0,8.0,16.0")
784 DRI_CONF_NO_NEG_LOD_BIAS("false")
785 - DRI_CONF_FORCE_S3TC_ENABLE("false")
786 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER)
787 DRI_CONF_ROUND_MODE(DRI_CONF_ROUND_TRUNC)
788 DRI_CONF_DITHER_MODE(DRI_CONF_DITHER_XERRORDIFF)
789 diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
790 index 3aabdc92bb..1a15016e7a 100644
791 --- a/src/mesa/main/context.c
792 +++ b/src/mesa/main/context.c
793 @@ -861,8 +861,6 @@ init_attrib_groups(struct gl_context *ctx)
794 if (!_mesa_init_texture( ctx ))
795 return GL_FALSE;
796
797 - _mesa_init_texture_s3tc( ctx );
798 -
799 /* Miscellaneous */
800 ctx->NewState = _NEW_ALL;
801 ctx->NewDriverState = ~0;
802 diff --git a/src/mesa/main/dlopen.h b/src/mesa/main/dlopen.h
803 deleted file mode 100644
804 index 4d20ff2c7c..0000000000
805 --- a/src/mesa/main/dlopen.h
806 +++ /dev/null
807 @@ -1,97 +0,0 @@
808 -/*
809 - * Mesa 3-D graphics library
810 - *
811 - * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
812 - *
813 - * Permission is hereby granted, free of charge, to any person obtaining a
814 - * copy of this software and associated documentation files (the "Software"),
815 - * to deal in the Software without restriction, including without limitation
816 - * the rights to use, copy, modify, merge, publish, distribute, sublicense,
817 - * and/or sell copies of the Software, and to permit persons to whom the
818 - * Software is furnished to do so, subject to the following conditions:
819 - *
820 - * The above copyright notice and this permission notice shall be included
821 - * in all copies or substantial portions of the Software.
822 - *
823 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
824 - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
825 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
826 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
827 - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
828 - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
829 - * OTHER DEALINGS IN THE SOFTWARE.
830 - */
831 -
832 -
833 -#ifndef DLOPEN_H
834 -#define DLOPEN_H
835 -
836 -/**
837 - * Wrapper functions for dlopen(), dlsym(), dlclose().
838 - * Note that the #ifdef tests for various environments should be expanded.
839 - */
840 -
841 -#if defined(HAVE_DLOPEN)
842 -#include <dlfcn.h>
843 -#endif
844 -#if defined(_WIN32)
845 -#include <windows.h>
846 -#endif
847 -
848 -typedef void (*GenericFunc)(void);
849 -
850 -/**
851 - * Wrapper for dlopen().
852 - * Note that 'flags' isn't used at this time.
853 - */
854 -static inline void *
855 -_mesa_dlopen(const char *libname, int flags)
856 -{
857 -#if defined(HAVE_DLOPEN)
858 - flags = RTLD_LAZY | RTLD_GLOBAL; /* Overriding flags at this time */
859 - return dlopen(libname, flags);
860 -#elif defined(_WIN32)
861 - return LoadLibraryA(libname);
862 -#else
863 - return NULL;
864 -#endif
865 -}
866 -
867 -/**
868 - * Wrapper for dlsym() that does a cast to a generic function type,
869 - * rather than a void *. This reduces the number of warnings that are
870 - * generated.
871 - */
872 -static inline GenericFunc
873 -_mesa_dlsym(void *handle, const char *fname)
874 -{
875 - union {
876 - void *v;
877 - GenericFunc f;
878 - } u;
879 -#if defined(HAVE_DLOPEN)
880 - u.v = dlsym(handle, fname);
881 -#elif defined(_WIN32)
882 - u.v = (void *) GetProcAddress(handle, fname);
883 -#else
884 - u.v = NULL;
885 -#endif
886 - return u.f;
887 -}
888 -
889 -/**
890 - * Wrapper for dlclose().
891 - */
892 -static inline void
893 -_mesa_dlclose(void *handle)
894 -{
895 -#if defined(HAVE_DLOPEN)
896 - dlclose(handle);
897 -#elif defined(_WIN32)
898 - FreeLibrary(handle);
899 -#else
900 - (void) handle;
901 -#endif
902 -}
903 -
904 -#endif
905 diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
906 index 62a731675d..46083001d2 100644
907 --- a/src/mesa/main/extensions.c
908 +++ b/src/mesa/main/extensions.c
909 @@ -176,10 +176,8 @@ _mesa_enable_sw_extensions(struct gl_context *ctx)
910 ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
911 ctx->Extensions.OES_standard_derivatives = GL_TRUE;
912 ctx->Extensions.TDFX_texture_compression_FXT1 = GL_TRUE;
913 - if (ctx->Mesa_DXTn) {
914 - ctx->Extensions.ANGLE_texture_compression_dxt = GL_TRUE;
915 - ctx->Extensions.EXT_texture_compression_s3tc = GL_TRUE;
916 - }
917 + ctx->Extensions.ANGLE_texture_compression_dxt = GL_TRUE;
918 + ctx->Extensions.EXT_texture_compression_s3tc = GL_TRUE;
919 }
920
921 /**
922 diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
923 index 0cb002469b..f4641b9c68 100644
924 --- a/src/mesa/main/mtypes.h
925 +++ b/src/mesa/main/mtypes.h
926 @@ -4958,9 +4958,6 @@ struct gl_context
927 */
928 GLboolean HasConfig;
929
930 - /** software compression/decompression supported or not */
931 - GLboolean Mesa_DXTn;
932 -
933 GLboolean TextureFormatSupported[MESA_FORMAT_COUNT];
934
935 GLboolean RasterDiscard; /**< GL_RASTERIZER_DISCARD */
936 diff --git a/src/mesa/main/texcompress_s3tc.c b/src/mesa/main/texcompress_s3tc.c
937 index 992ad058bf..1c6cbba892 100644
938 --- a/src/mesa/main/texcompress_s3tc.c
939 +++ b/src/mesa/main/texcompress_s3tc.c
940 @@ -31,91 +31,17 @@
941
942 #include "glheader.h"
943 #include "imports.h"
944 -#include "dlopen.h"
945 #include "image.h"
946 #include "macros.h"
947 #include "mtypes.h"
948 #include "texcompress.h"
949 #include "texcompress_s3tc.h"
950 +#include "texcompress_s3tc_tmp.h"
951 #include "texstore.h"
952 #include "format_unpack.h"
953 #include "util/format_srgb.h"
954
955
956 -#if defined(_WIN32) || defined(WIN32)
957 -#define DXTN_LIBNAME "dxtn.dll"
958 -#define RTLD_LAZY 0
959 -#define RTLD_GLOBAL 0
960 -#elif defined(__CYGWIN__)
961 -#define DXTN_LIBNAME "cygtxc_dxtn.dll"
962 -#else
963 -#define DXTN_LIBNAME "libtxc_dxtn.so"
964 -#endif
965 -
966 -typedef void (*dxtFetchTexelFuncExt)( GLint srcRowstride, const GLubyte *pixdata, GLint col, GLint row, GLvoid *texelOut );
967 -
968 -static dxtFetchTexelFuncExt fetch_ext_rgb_dxt1 = NULL;
969 -static dxtFetchTexelFuncExt fetch_ext_rgba_dxt1 = NULL;
970 -static dxtFetchTexelFuncExt fetch_ext_rgba_dxt3 = NULL;
971 -static dxtFetchTexelFuncExt fetch_ext_rgba_dxt5 = NULL;
972 -
973 -typedef void (*dxtCompressTexFuncExt)(GLint srccomps, GLint width,
974 - GLint height, const GLubyte *srcPixData,
975 - GLenum destformat, GLubyte *dest,
976 - GLint dstRowStride);
977 -
978 -static dxtCompressTexFuncExt ext_tx_compress_dxtn = NULL;
979 -
980 -static void *dxtlibhandle = NULL;
981 -
982 -
983 -void
984 -_mesa_init_texture_s3tc( struct gl_context *ctx )
985 -{
986 - /* called during context initialization */
987 - ctx->Mesa_DXTn = GL_FALSE;
988 - if (!dxtlibhandle) {
989 - dxtlibhandle = _mesa_dlopen(DXTN_LIBNAME, 0);
990 - if (!dxtlibhandle) {
991 - _mesa_warning(ctx, "couldn't open " DXTN_LIBNAME ", software DXTn "
992 - "compression/decompression unavailable");
993 - }
994 - else {
995 - /* the fetch functions are not per context! Might be problematic... */
996 - fetch_ext_rgb_dxt1 = (dxtFetchTexelFuncExt)
997 - _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgb_dxt1");
998 - fetch_ext_rgba_dxt1 = (dxtFetchTexelFuncExt)
999 - _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt1");
1000 - fetch_ext_rgba_dxt3 = (dxtFetchTexelFuncExt)
1001 - _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt3");
1002 - fetch_ext_rgba_dxt5 = (dxtFetchTexelFuncExt)
1003 - _mesa_dlsym(dxtlibhandle, "fetch_2d_texel_rgba_dxt5");
1004 - ext_tx_compress_dxtn = (dxtCompressTexFuncExt)
1005 - _mesa_dlsym(dxtlibhandle, "tx_compress_dxtn");
1006 -
1007 - if (!fetch_ext_rgb_dxt1 ||
1008 - !fetch_ext_rgba_dxt1 ||
1009 - !fetch_ext_rgba_dxt3 ||
1010 - !fetch_ext_rgba_dxt5 ||
1011 - !ext_tx_compress_dxtn) {
1012 - _mesa_warning(ctx, "couldn't reference all symbols in "
1013 - DXTN_LIBNAME ", software DXTn compression/decompression "
1014 - "unavailable");
1015 - fetch_ext_rgb_dxt1 = NULL;
1016 - fetch_ext_rgba_dxt1 = NULL;
1017 - fetch_ext_rgba_dxt3 = NULL;
1018 - fetch_ext_rgba_dxt5 = NULL;
1019 - ext_tx_compress_dxtn = NULL;
1020 - _mesa_dlclose(dxtlibhandle);
1021 - dxtlibhandle = NULL;
1022 - }
1023 - }
1024 - }
1025 - if (dxtlibhandle) {
1026 - ctx->Mesa_DXTn = GL_TRUE;
1027 - }
1028 -}
1029 -
1030 /**
1031 * Store user's image in rgb_dxt1 format.
1032 */
1033 @@ -158,14 +84,9 @@ _mesa_texstore_rgb_dxt1(TEXSTORE_PARAMS)
1034
1035 dst = dstSlices[0];
1036
1037 - if (ext_tx_compress_dxtn) {
1038 - (*ext_tx_compress_dxtn)(3, srcWidth, srcHeight, pixels,
1039 - GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1040 - dst, dstRowStride);
1041 - }
1042 - else {
1043 - _mesa_warning(ctx, "external dxt library not available: texstore_rgb_dxt1");
1044 - }
1045 + tx_compress_dxtn(3, srcWidth, srcHeight, pixels,
1046 + GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1047 + dst, dstRowStride);
1048
1049 free((void *) tempImage);
1050
1051 @@ -216,14 +137,9 @@ _mesa_texstore_rgba_dxt1(TEXSTORE_PARAMS)
1052
1053 dst = dstSlices[0];
1054
1055 - if (ext_tx_compress_dxtn) {
1056 - (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
1057 - GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
1058 - dst, dstRowStride);
1059 - }
1060 - else {
1061 - _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt1");
1062 - }
1063 + tx_compress_dxtn(4, srcWidth, srcHeight, pixels,
1064 + GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
1065 + dst, dstRowStride);
1066
1067 free((void*) tempImage);
1068
1069 @@ -273,14 +189,9 @@ _mesa_texstore_rgba_dxt3(TEXSTORE_PARAMS)
1070
1071 dst = dstSlices[0];
1072
1073 - if (ext_tx_compress_dxtn) {
1074 - (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
1075 - GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
1076 - dst, dstRowStride);
1077 - }
1078 - else {
1079 - _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt3");
1080 - }
1081 + tx_compress_dxtn(4, srcWidth, srcHeight, pixels,
1082 + GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
1083 + dst, dstRowStride);
1084
1085 free((void *) tempImage);
1086
1087 @@ -330,14 +241,9 @@ _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
1088
1089 dst = dstSlices[0];
1090
1091 - if (ext_tx_compress_dxtn) {
1092 - (*ext_tx_compress_dxtn)(4, srcWidth, srcHeight, pixels,
1093 - GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
1094 - dst, dstRowStride);
1095 - }
1096 - else {
1097 - _mesa_warning(ctx, "external dxt library not available: texstore_rgba_dxt5");
1098 - }
1099 + tx_compress_dxtn(4, srcWidth, srcHeight, pixels,
1100 + GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
1101 + dst, dstRowStride);
1102
1103 free((void *) tempImage);
1104
1105 @@ -345,85 +251,52 @@ _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS)
1106 }
1107
1108
1109 -/** Report problem with dxt texture decompression, once */
1110 -static void
1111 -problem(const char *func)
1112 -{
1113 - static GLboolean warned = GL_FALSE;
1114 - if (!warned) {
1115 - _mesa_debug(NULL, "attempted to decode DXT texture without "
1116 - "library available: %s\n", func);
1117 - warned = GL_TRUE;
1118 - }
1119 -}
1120 -
1121 -
1122 static void
1123 fetch_rgb_dxt1(const GLubyte *map,
1124 GLint rowStride, GLint i, GLint j, GLfloat *texel)
1125 {
1126 - if (fetch_ext_rgb_dxt1) {
1127 - GLubyte tex[4];
1128 - fetch_ext_rgb_dxt1(rowStride, map, i, j, tex);
1129 - texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]);
1130 - texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]);
1131 - texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]);
1132 - texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1133 - }
1134 - else {
1135 - problem("rgb_dxt1");
1136 - }
1137 + GLubyte tex[4];
1138 + fetch_2d_texel_rgb_dxt1(rowStride, map, i, j, tex);
1139 + texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]);
1140 + texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]);
1141 + texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]);
1142 + texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1143 }
1144
1145 static void
1146 fetch_rgba_dxt1(const GLubyte *map,
1147 GLint rowStride, GLint i, GLint j, GLfloat *texel)
1148 {
1149 - if (fetch_ext_rgba_dxt1) {
1150 - GLubyte tex[4];
1151 - fetch_ext_rgba_dxt1(rowStride, map, i, j, tex);
1152 - texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]);
1153 - texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]);
1154 - texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]);
1155 - texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1156 - }
1157 - else {
1158 - problem("rgba_dxt1");
1159 - }
1160 + GLubyte tex[4];
1161 + fetch_2d_texel_rgba_dxt1(rowStride, map, i, j, tex);
1162 + texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]);
1163 + texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]);
1164 + texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]);
1165 + texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1166 }
1167
1168 static void
1169 fetch_rgba_dxt3(const GLubyte *map,
1170 GLint rowStride, GLint i, GLint j, GLfloat *texel)
1171 {
1172 - if (fetch_ext_rgba_dxt3) {
1173 - GLubyte tex[4];
1174 - fetch_ext_rgba_dxt3(rowStride, map, i, j, tex);
1175 - texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]);
1176 - texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]);
1177 - texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]);
1178 - texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1179 - }
1180 - else {
1181 - problem("rgba_dxt3");
1182 - }
1183 + GLubyte tex[4];
1184 + fetch_2d_texel_rgba_dxt3(rowStride, map, i, j, tex);
1185 + texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]);
1186 + texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]);
1187 + texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]);
1188 + texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1189 }
1190
1191 static void
1192 fetch_rgba_dxt5(const GLubyte *map,
1193 GLint rowStride, GLint i, GLint j, GLfloat *texel)
1194 {
1195 - if (fetch_ext_rgba_dxt5) {
1196 - GLubyte tex[4];
1197 - fetch_ext_rgba_dxt5(rowStride, map, i, j, tex);
1198 - texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]);
1199 - texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]);
1200 - texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]);
1201 - texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1202 - }
1203 - else {
1204 - problem("rgba_dxt5");
1205 - }
1206 + GLubyte tex[4];
1207 + fetch_2d_texel_rgba_dxt5(rowStride, map, i, j, tex);
1208 + texel[RCOMP] = UBYTE_TO_FLOAT(tex[RCOMP]);
1209 + texel[GCOMP] = UBYTE_TO_FLOAT(tex[GCOMP]);
1210 + texel[BCOMP] = UBYTE_TO_FLOAT(tex[BCOMP]);
1211 + texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1212 }
1213
1214
1215 @@ -431,68 +304,48 @@ static void
1216 fetch_srgb_dxt1(const GLubyte *map,
1217 GLint rowStride, GLint i, GLint j, GLfloat *texel)
1218 {
1219 - if (fetch_ext_rgb_dxt1) {
1220 - GLubyte tex[4];
1221 - fetch_ext_rgb_dxt1(rowStride, map, i, j, tex);
1222 - texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]);
1223 - texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]);
1224 - texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]);
1225 - texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1226 - }
1227 - else {
1228 - problem("srgb_dxt1");
1229 - }
1230 + GLubyte tex[4];
1231 + fetch_2d_texel_rgb_dxt1(rowStride, map, i, j, tex);
1232 + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]);
1233 + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]);
1234 + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]);
1235 + texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1236 }
1237
1238 static void
1239 fetch_srgba_dxt1(const GLubyte *map,
1240 GLint rowStride, GLint i, GLint j, GLfloat *texel)
1241 {
1242 - if (fetch_ext_rgba_dxt1) {
1243 - GLubyte tex[4];
1244 - fetch_ext_rgba_dxt1(rowStride, map, i, j, tex);
1245 - texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]);
1246 - texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]);
1247 - texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]);
1248 - texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1249 - }
1250 - else {
1251 - problem("srgba_dxt1");
1252 - }
1253 + GLubyte tex[4];
1254 + fetch_2d_texel_rgba_dxt1(rowStride, map, i, j, tex);
1255 + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]);
1256 + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]);
1257 + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]);
1258 + texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1259 }
1260
1261 static void
1262 fetch_srgba_dxt3(const GLubyte *map,
1263 GLint rowStride, GLint i, GLint j, GLfloat *texel)
1264 {
1265 - if (fetch_ext_rgba_dxt3) {
1266 - GLubyte tex[4];
1267 - fetch_ext_rgba_dxt3(rowStride, map, i, j, tex);
1268 - texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]);
1269 - texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]);
1270 - texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]);
1271 - texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1272 - }
1273 - else {
1274 - problem("srgba_dxt3");
1275 - }
1276 + GLubyte tex[4];
1277 + fetch_2d_texel_rgba_dxt3(rowStride, map, i, j, tex);
1278 + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]);
1279 + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]);
1280 + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]);
1281 + texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1282 }
1283
1284 static void
1285 fetch_srgba_dxt5(const GLubyte *map,
1286 GLint rowStride, GLint i, GLint j, GLfloat *texel)
1287 {
1288 - if (fetch_ext_rgba_dxt5) {
1289 - GLubyte tex[4];
1290 - fetch_ext_rgba_dxt5(rowStride, map, i, j, tex);
1291 - texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]);
1292 - texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]);
1293 - texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]);
1294 - texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1295 - }
1296 - else {
1297 - problem("srgba_dxt5");
1298 - }
1299 + GLubyte tex[4];
1300 + fetch_2d_texel_rgba_dxt5(rowStride, map, i, j, tex);
1301 + texel[RCOMP] = util_format_srgb_8unorm_to_linear_float(tex[RCOMP]);
1302 + texel[GCOMP] = util_format_srgb_8unorm_to_linear_float(tex[GCOMP]);
1303 + texel[BCOMP] = util_format_srgb_8unorm_to_linear_float(tex[BCOMP]);
1304 + texel[ACOMP] = UBYTE_TO_FLOAT(tex[ACOMP]);
1305 }
1306
1307
1308 diff --git a/src/mesa/main/texcompress_s3tc.h b/src/mesa/main/texcompress_s3tc.h
1309 index 438b71fe33..0dbb5fc537 100644
1310 --- a/src/mesa/main/texcompress_s3tc.h
1311 +++ b/src/mesa/main/texcompress_s3tc.h
1312 @@ -44,9 +44,6 @@ extern GLboolean
1313 _mesa_texstore_rgba_dxt5(TEXSTORE_PARAMS);
1314
1315
1316 -extern void
1317 -_mesa_init_texture_s3tc(struct gl_context *ctx);
1318 -
1319 extern compressed_fetch_func
1320 _mesa_get_dxt_fetch_func(mesa_format format);
1321
1322 diff --git a/src/mesa/main/texcompress_s3tc_tmp.h b/src/mesa/main/texcompress_s3tc_tmp.h
1323 new file mode 100644
1324 index 0000000000..61630f2475
1325 --- /dev/null
1326 +++ b/src/mesa/main/texcompress_s3tc_tmp.h
1327 @@ -0,0 +1,989 @@
1328 +/*
1329 + * libtxc_dxtn
1330 + * Version: 1.0
1331 + *
1332 + * Copyright (C) 2004 Roland Scheidegger All Rights Reserved.
1333 + *
1334 + * Permission is hereby granted, free of charge, to any person obtaining a
1335 + * copy of this software and associated documentation files (the "Software"),
1336 + * to deal in the Software without restriction, including without limitation
1337 + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1338 + * and/or sell copies of the Software, and to permit persons to whom the
1339 + * Software is furnished to do so, subject to the following conditions:
1340 + *
1341 + * The above copyright notice and this permission notice shall be included
1342 + * in all copies or substantial portions of the Software.
1343 + *
1344 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1345 + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1346 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1347 + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
1348 + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
1349 + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1350 + */
1351 +
1352 +#ifdef __APPLE__
1353 +#include <OpenGL/gl.h>
1354 +#else
1355 +#include <GL/gl.h>
1356 +#endif
1357 +
1358 +typedef GLubyte GLchan;
1359 +#define UBYTE_TO_CHAN(b) (b)
1360 +#define CHAN_MAX 255
1361 +#define RCOMP 0
1362 +#define GCOMP 1
1363 +#define BCOMP 2
1364 +#define ACOMP 3
1365 +
1366 +#define EXP5TO8R(packedcol) \
1367 + ((((packedcol) >> 8) & 0xf8) | (((packedcol) >> 13) & 0x7))
1368 +
1369 +#define EXP6TO8G(packedcol) \
1370 + ((((packedcol) >> 3) & 0xfc) | (((packedcol) >> 9) & 0x3))
1371 +
1372 +#define EXP5TO8B(packedcol) \
1373 + ((((packedcol) << 3) & 0xf8) | (((packedcol) >> 2) & 0x7))
1374 +
1375 +#define EXP4TO8(col) \
1376 + ((col) | ((col) << 4))
1377 +
1378 +/* inefficient. To be efficient, it would be necessary to decode 16 pixels at once */
1379 +
1380 +static void dxt135_decode_imageblock ( const GLubyte *img_block_src,
1381 + GLint i, GLint j, GLuint dxt_type, GLvoid *texel ) {
1382 + GLchan *rgba = (GLchan *) texel;
1383 + const GLushort color0 = img_block_src[0] | (img_block_src[1] << 8);
1384 + const GLushort color1 = img_block_src[2] | (img_block_src[3] << 8);
1385 + const GLuint bits = img_block_src[4] | (img_block_src[5] << 8) |
1386 + (img_block_src[6] << 16) | (img_block_src[7] << 24);
1387 + /* What about big/little endian? */
1388 + GLubyte bit_pos = 2 * (j * 4 + i) ;
1389 + GLubyte code = (GLubyte) ((bits >> bit_pos) & 3);
1390 +
1391 + rgba[ACOMP] = CHAN_MAX;
1392 + switch (code) {
1393 + case 0:
1394 + rgba[RCOMP] = UBYTE_TO_CHAN( EXP5TO8R(color0) );
1395 + rgba[GCOMP] = UBYTE_TO_CHAN( EXP6TO8G(color0) );
1396 + rgba[BCOMP] = UBYTE_TO_CHAN( EXP5TO8B(color0) );
1397 + break;
1398 + case 1:
1399 + rgba[RCOMP] = UBYTE_TO_CHAN( EXP5TO8R(color1) );
1400 + rgba[GCOMP] = UBYTE_TO_CHAN( EXP6TO8G(color1) );
1401 + rgba[BCOMP] = UBYTE_TO_CHAN( EXP5TO8B(color1) );
1402 + break;
1403 + case 2:
1404 + if ((dxt_type > 1) || (color0 > color1)) {
1405 + rgba[RCOMP] = UBYTE_TO_CHAN( ((EXP5TO8R(color0) * 2 + EXP5TO8R(color1)) / 3) );
1406 + rgba[GCOMP] = UBYTE_TO_CHAN( ((EXP6TO8G(color0) * 2 + EXP6TO8G(color1)) / 3) );
1407 + rgba[BCOMP] = UBYTE_TO_CHAN( ((EXP5TO8B(color0) * 2 + EXP5TO8B(color1)) / 3) );
1408 + }
1409 + else {
1410 + rgba[RCOMP] = UBYTE_TO_CHAN( ((EXP5TO8R(color0) + EXP5TO8R(color1)) / 2) );
1411 + rgba[GCOMP] = UBYTE_TO_CHAN( ((EXP6TO8G(color0) + EXP6TO8G(color1)) / 2) );
1412 + rgba[BCOMP] = UBYTE_TO_CHAN( ((EXP5TO8B(color0) + EXP5TO8B(color1)) / 2) );
1413 + }
1414 + break;
1415 + case 3:
1416 + if ((dxt_type > 1) || (color0 > color1)) {
1417 + rgba[RCOMP] = UBYTE_TO_CHAN( ((EXP5TO8R(color0) + EXP5TO8R(color1) * 2) / 3) );
1418 + rgba[GCOMP] = UBYTE_TO_CHAN( ((EXP6TO8G(color0) + EXP6TO8G(color1) * 2) / 3) );
1419 + rgba[BCOMP] = UBYTE_TO_CHAN( ((EXP5TO8B(color0) + EXP5TO8B(color1) * 2) / 3) );
1420 + }
1421 + else {
1422 + rgba[RCOMP] = 0;
1423 + rgba[GCOMP] = 0;
1424 + rgba[BCOMP] = 0;
1425 + if (dxt_type == 1) rgba[ACOMP] = UBYTE_TO_CHAN(0);
1426 + }
1427 + break;
1428 + default:
1429 + /* CANNOT happen (I hope) */
1430 + break;
1431 + }
1432 +}
1433 +
1434 +
1435 +static void fetch_2d_texel_rgb_dxt1(GLint srcRowStride, const GLubyte *pixdata,
1436 + GLint i, GLint j, GLvoid *texel)
1437 +{
1438 + /* Extract the (i,j) pixel from pixdata and return it
1439 + * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
1440 + */
1441 +
1442 + const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8);
1443 + dxt135_decode_imageblock(blksrc, (i&3), (j&3), 0, texel);
1444 +}
1445 +
1446 +
1447 +static void fetch_2d_texel_rgba_dxt1(GLint srcRowStride, const GLubyte *pixdata,
1448 + GLint i, GLint j, GLvoid *texel)
1449 +{
1450 + /* Extract the (i,j) pixel from pixdata and return it
1451 + * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
1452 + */
1453 +
1454 + const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 8);
1455 + dxt135_decode_imageblock(blksrc, (i&3), (j&3), 1, texel);
1456 +}
1457 +
1458 +static void fetch_2d_texel_rgba_dxt3(GLint srcRowStride, const GLubyte *pixdata,
1459 + GLint i, GLint j, GLvoid *texel) {
1460 +
1461 + /* Extract the (i,j) pixel from pixdata and return it
1462 + * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
1463 + */
1464 +
1465 + GLchan *rgba = (GLchan *) texel;
1466 + const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 16);
1467 + const GLubyte anibble = (blksrc[((j&3) * 4 + (i&3)) / 2] >> (4 * (i&1))) & 0xf;
1468 + dxt135_decode_imageblock(blksrc + 8, (i&3), (j&3), 2, texel);
1469 + rgba[ACOMP] = UBYTE_TO_CHAN( (GLubyte)(EXP4TO8(anibble)) );
1470 +}
1471 +
1472 +static void fetch_2d_texel_rgba_dxt5(GLint srcRowStride, const GLubyte *pixdata,
1473 + GLint i, GLint j, GLvoid *texel) {
1474 +
1475 + /* Extract the (i,j) pixel from pixdata and return it
1476 + * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
1477 + */
1478 +
1479 + GLchan *rgba = (GLchan *) texel;
1480 + const GLubyte *blksrc = (pixdata + ((srcRowStride + 3) / 4 * (j / 4) + (i / 4)) * 16);
1481 + const GLubyte alpha0 = blksrc[0];
1482 + const GLubyte alpha1 = blksrc[1];
1483 + const GLubyte bit_pos = ((j&3) * 4 + (i&3)) * 3;
1484 + const GLubyte acodelow = blksrc[2 + bit_pos / 8];
1485 + const GLubyte acodehigh = blksrc[3 + bit_pos / 8];
1486 + const GLubyte code = (acodelow >> (bit_pos & 0x7) |
1487 + (acodehigh << (8 - (bit_pos & 0x7)))) & 0x7;
1488 + dxt135_decode_imageblock(blksrc + 8, (i&3), (j&3), 2, texel);
1489 + if (code == 0)
1490 + rgba[ACOMP] = UBYTE_TO_CHAN( alpha0 );
1491 + else if (code == 1)
1492 + rgba[ACOMP] = UBYTE_TO_CHAN( alpha1 );
1493 + else if (alpha0 > alpha1)
1494 + rgba[ACOMP] = UBYTE_TO_CHAN( ((alpha0 * (8 - code) + (alpha1 * (code - 1))) / 7) );
1495 + else if (code < 6)
1496 + rgba[ACOMP] = UBYTE_TO_CHAN( ((alpha0 * (6 - code) + (alpha1 * (code - 1))) / 5) );
1497 + else if (code == 6)
1498 + rgba[ACOMP] = 0;
1499 + else
1500 + rgba[ACOMP] = CHAN_MAX;
1501 +}
1502 +
1503 +
1504 +/* weights used for error function, basically weights (unsquared 2/4/1) according to rgb->luminance conversion
1505 + not sure if this really reflects visual perception */
1506 +#define REDWEIGHT 4
1507 +#define GREENWEIGHT 16
1508 +#define BLUEWEIGHT 1
1509 +
1510 +#define ALPHACUT 127
1511 +
1512 +static void fancybasecolorsearch( GLubyte *blkaddr, GLubyte srccolors[4][4][4], GLubyte *bestcolor[2],
1513 + GLint numxpixels, GLint numypixels, GLint type, GLboolean haveAlpha)
1514 +{
1515 + /* use same luminance-weighted distance metric to determine encoding as for finding the base colors */
1516 +
1517 + /* TODO could also try to find a better encoding for the 3-color-encoding type, this really should be done
1518 + if it's rgba_dxt1 and we have alpha in the block, currently even values which will be mapped to black
1519 + due to their alpha value will influence the result */
1520 + GLint i, j, colors, z;
1521 + GLuint pixerror, pixerrorred, pixerrorgreen, pixerrorblue, pixerrorbest;
1522 + GLint colordist, blockerrlin[2][3];
1523 + GLubyte nrcolor[2];
1524 + GLint pixerrorcolorbest[3];
1525 + GLubyte enc = 0;
1526 + GLubyte cv[4][4];
1527 + GLubyte testcolor[2][3];
1528 +
1529 +/* fprintf(stderr, "color begin 0 r/g/b %d/%d/%d, 1 r/g/b %d/%d/%d\n",
1530 + bestcolor[0][0], bestcolor[0][1], bestcolor[0][2], bestcolor[1][0], bestcolor[1][1], bestcolor[1][2]);*/
1531 + if (((bestcolor[0][0] & 0xf8) << 8 | (bestcolor[0][1] & 0xfc) << 3 | bestcolor[0][2] >> 3) <
1532 + ((bestcolor[1][0] & 0xf8) << 8 | (bestcolor[1][1] & 0xfc) << 3 | bestcolor[1][2] >> 3)) {
1533 + testcolor[0][0] = bestcolor[0][0];
1534 + testcolor[0][1] = bestcolor[0][1];
1535 + testcolor[0][2] = bestcolor[0][2];
1536 + testcolor[1][0] = bestcolor[1][0];
1537 + testcolor[1][1] = bestcolor[1][1];
1538 + testcolor[1][2] = bestcolor[1][2];
1539 + }
1540 + else {
1541 + testcolor[1][0] = bestcolor[0][0];
1542 + testcolor[1][1] = bestcolor[0][1];
1543 + testcolor[1][2] = bestcolor[0][2];
1544 + testcolor[0][0] = bestcolor[1][0];
1545 + testcolor[0][1] = bestcolor[1][1];
1546 + testcolor[0][2] = bestcolor[1][2];
1547 + }
1548 +
1549 + for (i = 0; i < 3; i ++) {
1550 + cv[0][i] = testcolor[0][i];
1551 + cv[1][i] = testcolor[1][i];
1552 + cv[2][i] = (testcolor[0][i] * 2 + testcolor[1][i]) / 3;
1553 + cv[3][i] = (testcolor[0][i] + testcolor[1][i] * 2) / 3;
1554 + }
1555 +
1556 + blockerrlin[0][0] = 0;
1557 + blockerrlin[0][1] = 0;
1558 + blockerrlin[0][2] = 0;
1559 + blockerrlin[1][0] = 0;
1560 + blockerrlin[1][1] = 0;
1561 + blockerrlin[1][2] = 0;
1562 +
1563 + nrcolor[0] = 0;
1564 + nrcolor[1] = 0;
1565 +
1566 + for (j = 0; j < numypixels; j++) {
1567 + for (i = 0; i < numxpixels; i++) {
1568 + pixerrorbest = 0xffffffff;
1569 + for (colors = 0; colors < 4; colors++) {
1570 + colordist = srccolors[j][i][0] - (cv[colors][0]);
1571 + pixerror = colordist * colordist * REDWEIGHT;
1572 + pixerrorred = colordist;
1573 + colordist = srccolors[j][i][1] - (cv[colors][1]);
1574 + pixerror += colordist * colordist * GREENWEIGHT;
1575 + pixerrorgreen = colordist;
1576 + colordist = srccolors[j][i][2] - (cv[colors][2]);
1577 + pixerror += colordist * colordist * BLUEWEIGHT;
1578 + pixerrorblue = colordist;
1579 + if (pixerror < pixerrorbest) {
1580 + enc = colors;
1581 + pixerrorbest = pixerror;
1582 + pixerrorcolorbest[0] = pixerrorred;
1583 + pixerrorcolorbest[1] = pixerrorgreen;
1584 + pixerrorcolorbest[2] = pixerrorblue;
1585 + }
1586 + }
1587 + if (enc == 0) {
1588 + for (z = 0; z < 3; z++) {
1589 + blockerrlin[0][z] += 3 * pixerrorcolorbest[z];
1590 + }
1591 + nrcolor[0] += 3;
1592 + }
1593 + else if (enc == 2) {
1594 + for (z = 0; z < 3; z++) {
1595 + blockerrlin[0][z] += 2 * pixerrorcolorbest[z];
1596 + }
1597 + nrcolor[0] += 2;
1598 + for (z = 0; z < 3; z++) {
1599 + blockerrlin[1][z] += 1 * pixerrorcolorbest[z];
1600 + }
1601 + nrcolor[1] += 1;
1602 + }
1603 + else if (enc == 3) {
1604 + for (z = 0; z < 3; z++) {
1605 + blockerrlin[0][z] += 1 * pixerrorcolorbest[z];
1606 + }
1607 + nrcolor[0] += 1;
1608 + for (z = 0; z < 3; z++) {
1609 + blockerrlin[1][z] += 2 * pixerrorcolorbest[z];
1610 + }
1611 + nrcolor[1] += 2;
1612 + }
1613 + else if (enc == 1) {
1614 + for (z = 0; z < 3; z++) {
1615 + blockerrlin[1][z] += 3 * pixerrorcolorbest[z];
1616 + }
1617 + nrcolor[1] += 3;
1618 + }
1619 + }
1620 + }
1621 + if (nrcolor[0] == 0) nrcolor[0] = 1;
1622 + if (nrcolor[1] == 0) nrcolor[1] = 1;
1623 + for (j = 0; j < 2; j++) {
1624 + for (i = 0; i < 3; i++) {
1625 + GLint newvalue = testcolor[j][i] + blockerrlin[j][i] / nrcolor[j];
1626 + if (newvalue <= 0)
1627 + testcolor[j][i] = 0;
1628 + else if (newvalue >= 255)
1629 + testcolor[j][i] = 255;
1630 + else testcolor[j][i] = newvalue;
1631 + }
1632 + }
1633 +
1634 + if ((abs(testcolor[0][0] - testcolor[1][0]) < 8) &&
1635 + (abs(testcolor[0][1] - testcolor[1][1]) < 4) &&
1636 + (abs(testcolor[0][2] - testcolor[1][2]) < 8)) {
1637 + /* both colors are so close they might get encoded as the same 16bit values */
1638 + GLubyte coldiffred, coldiffgreen, coldiffblue, coldiffmax, factor, ind0, ind1;
1639 +
1640 + coldiffred = abs(testcolor[0][0] - testcolor[1][0]);
1641 + coldiffgreen = 2 * abs(testcolor[0][1] - testcolor[1][1]);
1642 + coldiffblue = abs(testcolor[0][2] - testcolor[1][2]);
1643 + coldiffmax = coldiffred;
1644 + if (coldiffmax < coldiffgreen) coldiffmax = coldiffgreen;
1645 + if (coldiffmax < coldiffblue) coldiffmax = coldiffblue;
1646 + if (coldiffmax > 0) {
1647 + if (coldiffmax > 4) factor = 2;
1648 + else if (coldiffmax > 2) factor = 3;
1649 + else factor = 4;
1650 + /* Won't do much if the color value is near 255... */
1651 + /* argh so many ifs */
1652 + if (testcolor[1][1] >= testcolor[0][1]) {
1653 + ind1 = 1; ind0 = 0;
1654 + }
1655 + else {
1656 + ind1 = 0; ind0 = 1;
1657 + }
1658 + if ((testcolor[ind1][1] + factor * coldiffgreen) <= 255)
1659 + testcolor[ind1][1] += factor * coldiffgreen;
1660 + else testcolor[ind1][1] = 255;
1661 + if ((testcolor[ind1][0] - testcolor[ind0][1]) > 0) {
1662 + if ((testcolor[ind1][0] + factor * coldiffred) <= 255)
1663 + testcolor[ind1][0] += factor * coldiffred;
1664 + else testcolor[ind1][0] = 255;
1665 + }
1666 + else {
1667 + if ((testcolor[ind0][0] + factor * coldiffred) <= 255)
1668 + testcolor[ind0][0] += factor * coldiffred;
1669 + else testcolor[ind0][0] = 255;
1670 + }
1671 + if ((testcolor[ind1][2] - testcolor[ind0][2]) > 0) {
1672 + if ((testcolor[ind1][2] + factor * coldiffblue) <= 255)
1673 + testcolor[ind1][2] += factor * coldiffblue;
1674 + else testcolor[ind1][2] = 255;
1675 + }
1676 + else {
1677 + if ((testcolor[ind0][2] + factor * coldiffblue) <= 255)
1678 + testcolor[ind0][2] += factor * coldiffblue;
1679 + else testcolor[ind0][2] = 255;
1680 + }
1681 + }
1682 + }
1683 +
1684 + if (((testcolor[0][0] & 0xf8) << 8 | (testcolor[0][1] & 0xfc) << 3 | testcolor[0][2] >> 3) <
1685 + ((testcolor[1][0] & 0xf8) << 8 | (testcolor[1][1] & 0xfc) << 3 | testcolor[1][2]) >> 3) {
1686 + for (i = 0; i < 3; i++) {
1687 + bestcolor[0][i] = testcolor[0][i];
1688 + bestcolor[1][i] = testcolor[1][i];
1689 + }
1690 + }
1691 + else {
1692 + for (i = 0; i < 3; i++) {
1693 + bestcolor[0][i] = testcolor[1][i];
1694 + bestcolor[1][i] = testcolor[0][i];
1695 + }
1696 + }
1697 +
1698 +/* fprintf(stderr, "color end 0 r/g/b %d/%d/%d, 1 r/g/b %d/%d/%d\n",
1699 + bestcolor[0][0], bestcolor[0][1], bestcolor[0][2], bestcolor[1][0], bestcolor[1][1], bestcolor[1][2]);*/
1700 +}
1701 +
1702 +
1703 +
1704 +static void storedxtencodedblock( GLubyte *blkaddr, GLubyte srccolors[4][4][4], GLubyte *bestcolor[2],
1705 + GLint numxpixels, GLint numypixels, GLuint type, GLboolean haveAlpha)
1706 +{
1707 + /* use same luminance-weighted distance metric to determine encoding as for finding the base colors */
1708 +
1709 + GLint i, j, colors;
1710 + GLuint testerror, testerror2, pixerror, pixerrorbest;
1711 + GLint colordist;
1712 + GLushort color0, color1, tempcolor;
1713 + GLuint bits = 0, bits2 = 0;
1714 + GLubyte *colorptr;
1715 + GLubyte enc = 0;
1716 + GLubyte cv[4][4];
1717 +
1718 + bestcolor[0][0] = bestcolor[0][0] & 0xf8;
1719 + bestcolor[0][1] = bestcolor[0][1] & 0xfc;
1720 + bestcolor[0][2] = bestcolor[0][2] & 0xf8;
1721 + bestcolor[1][0] = bestcolor[1][0] & 0xf8;
1722 + bestcolor[1][1] = bestcolor[1][1] & 0xfc;
1723 + bestcolor[1][2] = bestcolor[1][2] & 0xf8;
1724 +
1725 + color0 = bestcolor[0][0] << 8 | bestcolor[0][1] << 3 | bestcolor[0][2] >> 3;
1726 + color1 = bestcolor[1][0] << 8 | bestcolor[1][1] << 3 | bestcolor[1][2] >> 3;
1727 + if (color0 < color1) {
1728 + tempcolor = color0; color0 = color1; color1 = tempcolor;
1729 + colorptr = bestcolor[0]; bestcolor[0] = bestcolor[1]; bestcolor[1] = colorptr;
1730 + }
1731 +
1732 +
1733 + for (i = 0; i < 3; i++) {
1734 + cv[0][i] = bestcolor[0][i];
1735 + cv[1][i] = bestcolor[1][i];
1736 + cv[2][i] = (bestcolor[0][i] * 2 + bestcolor[1][i]) / 3;
1737 + cv[3][i] = (bestcolor[0][i] + bestcolor[1][i] * 2) / 3;
1738 + }
1739 +
1740 + testerror = 0;
1741 + for (j = 0; j < numypixels; j++) {
1742 + for (i = 0; i < numxpixels; i++) {
1743 + pixerrorbest = 0xffffffff;
1744 + for (colors = 0; colors < 4; colors++) {
1745 + colordist = srccolors[j][i][0] - cv[colors][0];
1746 + pixerror = colordist * colordist * REDWEIGHT;
1747 + colordist = srccolors[j][i][1] - cv[colors][1];
1748 + pixerror += colordist * colordist * GREENWEIGHT;
1749 + colordist = srccolors[j][i][2] - cv[colors][2];
1750 + pixerror += colordist * colordist * BLUEWEIGHT;
1751 + if (pixerror < pixerrorbest) {
1752 + pixerrorbest = pixerror;
1753 + enc = colors;
1754 + }
1755 + }
1756 + testerror += pixerrorbest;
1757 + bits |= enc << (2 * (j * 4 + i));
1758 + }
1759 + }
1760 + /* some hw might disagree but actually decoding should always use 4-color encoding
1761 + for non-dxt1 formats */
1762 + if (type == GL_COMPRESSED_RGB_S3TC_DXT1_EXT || type == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
1763 + for (i = 0; i < 3; i++) {
1764 + cv[2][i] = (bestcolor[0][i] + bestcolor[1][i]) / 2;
1765 + /* this isn't used. Looks like the black color constant can only be used
1766 + with RGB_DXT1 if I read the spec correctly (note though that the radeon gpu disagrees,
1767 + it will decode 3 to black even with DXT3/5), and due to how the color searching works
1768 + it won't get used even then */
1769 + cv[3][i] = 0;
1770 + }
1771 + testerror2 = 0;
1772 + for (j = 0; j < numypixels; j++) {
1773 + for (i = 0; i < numxpixels; i++) {
1774 + pixerrorbest = 0xffffffff;
1775 + if ((type == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) && (srccolors[j][i][3] <= ALPHACUT)) {
1776 + enc = 3;
1777 + pixerrorbest = 0; /* don't calculate error */
1778 + }
1779 + else {
1780 + /* we're calculating the same what we have done already for colors 0-1 above... */
1781 + for (colors = 0; colors < 3; colors++) {
1782 + colordist = srccolors[j][i][0] - cv[colors][0];
1783 + pixerror = colordist * colordist * REDWEIGHT;
1784 + colordist = srccolors[j][i][1] - cv[colors][1];
1785 + pixerror += colordist * colordist * GREENWEIGHT;
1786 + colordist = srccolors[j][i][2] - cv[colors][2];
1787 + pixerror += colordist * colordist * BLUEWEIGHT;
1788 + if (pixerror < pixerrorbest) {
1789 + pixerrorbest = pixerror;
1790 + /* need to exchange colors later */
1791 + if (colors > 1) enc = colors;
1792 + else enc = colors ^ 1;
1793 + }
1794 + }
1795 + }
1796 + testerror2 += pixerrorbest;
1797 + bits2 |= enc << (2 * (j * 4 + i));
1798 + }
1799 + }
1800 + } else {
1801 + testerror2 = 0xffffffff;
1802 + }
1803 +
1804 + /* finally we're finished, write back colors and bits */
1805 + if ((testerror > testerror2) || (haveAlpha)) {
1806 + *blkaddr++ = color1 & 0xff;
1807 + *blkaddr++ = color1 >> 8;
1808 + *blkaddr++ = color0 & 0xff;
1809 + *blkaddr++ = color0 >> 8;
1810 + *blkaddr++ = bits2 & 0xff;
1811 + *blkaddr++ = ( bits2 >> 8) & 0xff;
1812 + *blkaddr++ = ( bits2 >> 16) & 0xff;
1813 + *blkaddr = bits2 >> 24;
1814 + }
1815 + else {
1816 + *blkaddr++ = color0 & 0xff;
1817 + *blkaddr++ = color0 >> 8;
1818 + *blkaddr++ = color1 & 0xff;
1819 + *blkaddr++ = color1 >> 8;
1820 + *blkaddr++ = bits & 0xff;
1821 + *blkaddr++ = ( bits >> 8) & 0xff;
1822 + *blkaddr++ = ( bits >> 16) & 0xff;
1823 + *blkaddr = bits >> 24;
1824 + }
1825 +}
1826 +
1827 +static void encodedxtcolorblockfaster( GLubyte *blkaddr, GLubyte srccolors[4][4][4],
1828 + GLint numxpixels, GLint numypixels, GLuint type )
1829 +{
1830 +/* simplistic approach. We need two base colors, simply use the "highest" and the "lowest" color
1831 + present in the picture as base colors */
1832 +
1833 + /* define lowest and highest color as shortest and longest vector to 0/0/0, though the
1834 + vectors are weighted similar to their importance in rgb-luminance conversion
1835 + doesn't work too well though...
1836 + This seems to be a rather difficult problem */
1837 +
1838 + GLubyte *bestcolor[2];
1839 + GLubyte basecolors[2][3];
1840 + GLubyte i, j;
1841 + GLuint lowcv, highcv, testcv;
1842 + GLboolean haveAlpha = GL_FALSE;
1843 +
1844 + lowcv = highcv = srccolors[0][0][0] * srccolors[0][0][0] * REDWEIGHT +
1845 + srccolors[0][0][1] * srccolors[0][0][1] * GREENWEIGHT +
1846 + srccolors[0][0][2] * srccolors[0][0][2] * BLUEWEIGHT;
1847 + bestcolor[0] = bestcolor[1] = srccolors[0][0];
1848 + for (j = 0; j < numypixels; j++) {
1849 + for (i = 0; i < numxpixels; i++) {
1850 + /* don't use this as a base color if the pixel will get black/transparent anyway */
1851 + if ((type != GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) || (srccolors[j][i][3] > ALPHACUT)) {
1852 + testcv = srccolors[j][i][0] * srccolors[j][i][0] * REDWEIGHT +
1853 + srccolors[j][i][1] * srccolors[j][i][1] * GREENWEIGHT +
1854 + srccolors[j][i][2] * srccolors[j][i][2] * BLUEWEIGHT;
1855 + if (testcv > highcv) {
1856 + highcv = testcv;
1857 + bestcolor[1] = srccolors[j][i];
1858 + }
1859 + else if (testcv < lowcv) {
1860 + lowcv = testcv;
1861 + bestcolor[0] = srccolors[j][i];
1862 + }
1863 + }
1864 + else haveAlpha = GL_TRUE;
1865 + }
1866 + }
1867 + /* make sure the original color values won't get touched... */
1868 + for (j = 0; j < 2; j++) {
1869 + for (i = 0; i < 3; i++) {
1870 + basecolors[j][i] = bestcolor[j][i];
1871 + }
1872 + }
1873 + bestcolor[0] = basecolors[0];
1874 + bestcolor[1] = basecolors[1];
1875 +
1876 + /* try to find better base colors */
1877 + fancybasecolorsearch(blkaddr, srccolors, bestcolor, numxpixels, numypixels, type, haveAlpha);
1878 + /* find the best encoding for these colors, and store the result */
1879 + storedxtencodedblock(blkaddr, srccolors, bestcolor, numxpixels, numypixels, type, haveAlpha);
1880 +}
1881 +
1882 +static void writedxt5encodedalphablock( GLubyte *blkaddr, GLubyte alphabase1, GLubyte alphabase2,
1883 + GLubyte alphaenc[16])
1884 +{
1885 + *blkaddr++ = alphabase1;
1886 + *blkaddr++ = alphabase2;
1887 + *blkaddr++ = alphaenc[0] | (alphaenc[1] << 3) | ((alphaenc[2] & 3) << 6);
1888 + *blkaddr++ = (alphaenc[2] >> 2) | (alphaenc[3] << 1) | (alphaenc[4] << 4) | ((alphaenc[5] & 1) << 7);
1889 + *blkaddr++ = (alphaenc[5] >> 1) | (alphaenc[6] << 2) | (alphaenc[7] << 5);
1890 + *blkaddr++ = alphaenc[8] | (alphaenc[9] << 3) | ((alphaenc[10] & 3) << 6);
1891 + *blkaddr++ = (alphaenc[10] >> 2) | (alphaenc[11] << 1) | (alphaenc[12] << 4) | ((alphaenc[13] & 1) << 7);
1892 + *blkaddr++ = (alphaenc[13] >> 1) | (alphaenc[14] << 2) | (alphaenc[15] << 5);
1893 +}
1894 +
1895 +static void encodedxt5alpha(GLubyte *blkaddr, GLubyte srccolors[4][4][4],
1896 + GLint numxpixels, GLint numypixels)
1897 +{
1898 + GLubyte alphabase[2], alphause[2];
1899 + GLshort alphatest[2];
1900 + GLuint alphablockerror1, alphablockerror2, alphablockerror3;
1901 + GLubyte i, j, aindex, acutValues[7];
1902 + GLubyte alphaenc1[16], alphaenc2[16], alphaenc3[16];
1903 + GLboolean alphaabsmin = GL_FALSE;
1904 + GLboolean alphaabsmax = GL_FALSE;
1905 + GLshort alphadist;
1906 +
1907 + /* find lowest and highest alpha value in block, alphabase[0] lowest, alphabase[1] highest */
1908 + alphabase[0] = 0xff; alphabase[1] = 0x0;
1909 + for (j = 0; j < numypixels; j++) {
1910 + for (i = 0; i < numxpixels; i++) {
1911 + if (srccolors[j][i][3] == 0)
1912 + alphaabsmin = GL_TRUE;
1913 + else if (srccolors[j][i][3] == 255)
1914 + alphaabsmax = GL_TRUE;
1915 + else {
1916 + if (srccolors[j][i][3] > alphabase[1])
1917 + alphabase[1] = srccolors[j][i][3];
1918 + if (srccolors[j][i][3] < alphabase[0])
1919 + alphabase[0] = srccolors[j][i][3];
1920 + }
1921 + }
1922 + }
1923 +
1924 +
1925 + if ((alphabase[0] > alphabase[1]) && !(alphaabsmin && alphaabsmax)) { /* one color, either max or min */
1926 + /* shortcut here since it is a very common case (and also avoids later problems) */
1927 + /* || (alphabase[0] == alphabase[1] && !alphaabsmin && !alphaabsmax) */
1928 + /* could also thest for alpha0 == alpha1 (and not min/max), but probably not common, so don't bother */
1929 +
1930 + *blkaddr++ = srccolors[0][0][3];
1931 + blkaddr++;
1932 + *blkaddr++ = 0;
1933 + *blkaddr++ = 0;
1934 + *blkaddr++ = 0;
1935 + *blkaddr++ = 0;
1936 + *blkaddr++ = 0;
1937 + *blkaddr++ = 0;
1938 +/* fprintf(stderr, "enc0 used\n");*/
1939 + return;
1940 + }
1941 +
1942 + /* find best encoding for alpha0 > alpha1 */
1943 + /* it's possible this encoding is better even if both alphaabsmin and alphaabsmax are true */
1944 + alphablockerror1 = 0x0;
1945 + alphablockerror2 = 0xffffffff;
1946 + alphablockerror3 = 0xffffffff;
1947 + if (alphaabsmin) alphause[0] = 0;
1948 + else alphause[0] = alphabase[0];
1949 + if (alphaabsmax) alphause[1] = 255;
1950 + else alphause[1] = alphabase[1];
1951 + /* calculate the 7 cut values, just the middle between 2 of the computed alpha values */
1952 + for (aindex = 0; aindex < 7; aindex++) {
1953 + /* don't forget here is always rounded down */
1954 + acutValues[aindex] = (alphause[0] * (2*aindex + 1) + alphause[1] * (14 - (2*aindex + 1))) / 14;
1955 + }
1956 +
1957 + for (j = 0; j < numypixels; j++) {
1958 + for (i = 0; i < numxpixels; i++) {
1959 + /* maybe it's overkill to have the most complicated calculation just for the error
1960 + calculation which we only need to figure out if encoding1 or encoding2 is better... */
1961 + if (srccolors[j][i][3] > acutValues[0]) {
1962 + alphaenc1[4*j + i] = 0;
1963 + alphadist = srccolors[j][i][3] - alphause[1];
1964 + }
1965 + else if (srccolors[j][i][3] > acutValues[1]) {
1966 + alphaenc1[4*j + i] = 2;
1967 + alphadist = srccolors[j][i][3] - (alphause[1] * 6 + alphause[0] * 1) / 7;
1968 + }
1969 + else if (srccolors[j][i][3] > acutValues[2]) {
1970 + alphaenc1[4*j + i] = 3;
1971 + alphadist = srccolors[j][i][3] - (alphause[1] * 5 + alphause[0] * 2) / 7;
1972 + }
1973 + else if (srccolors[j][i][3] > acutValues[3]) {
1974 + alphaenc1[4*j + i] = 4;
1975 + alphadist = srccolors[j][i][3] - (alphause[1] * 4 + alphause[0] * 3) / 7;
1976 + }
1977 + else if (srccolors[j][i][3] > acutValues[4]) {
1978 + alphaenc1[4*j + i] = 5;
1979 + alphadist = srccolors[j][i][3] - (alphause[1] * 3 + alphause[0] * 4) / 7;
1980 + }
1981 + else if (srccolors[j][i][3] > acutValues[5]) {
1982 + alphaenc1[4*j + i] = 6;
1983 + alphadist = srccolors[j][i][3] - (alphause[1] * 2 + alphause[0] * 5) / 7;
1984 + }
1985 + else if (srccolors[j][i][3] > acutValues[6]) {
1986 + alphaenc1[4*j + i] = 7;
1987 + alphadist = srccolors[j][i][3] - (alphause[1] * 1 + alphause[0] * 6) / 7;
1988 + }
1989 + else {
1990 + alphaenc1[4*j + i] = 1;
1991 + alphadist = srccolors[j][i][3] - alphause[0];
1992 + }
1993 + alphablockerror1 += alphadist * alphadist;
1994 + }
1995 + }
1996 +/* for (i = 0; i < 16; i++) {
1997 + fprintf(stderr, "%d ", alphaenc1[i]);
1998 + }
1999 + fprintf(stderr, "cutVals ");
2000 + for (i = 0; i < 8; i++) {
2001 + fprintf(stderr, "%d ", acutValues[i]);
2002 + }
2003 + fprintf(stderr, "srcVals ");
2004 + for (j = 0; j < numypixels; j++)
2005 + for (i = 0; i < numxpixels; i++) {
2006 + fprintf(stderr, "%d ", srccolors[j][i][3]);
2007 + }
2008 +
2009 + fprintf(stderr, "\n");
2010 + }*/
2011 + /* it's not very likely this encoding is better if both alphaabsmin and alphaabsmax
2012 + are false but try it anyway */
2013 + if (alphablockerror1 >= 32) {
2014 +
2015 + /* don't bother if encoding is already very good, this condition should also imply
2016 + we have valid alphabase colors which we absolutely need (alphabase[0] <= alphabase[1]) */
2017 + alphablockerror2 = 0;
2018 + for (aindex = 0; aindex < 5; aindex++) {
2019 + /* don't forget here is always rounded down */
2020 + acutValues[aindex] = (alphabase[0] * (10 - (2*aindex + 1)) + alphabase[1] * (2*aindex + 1)) / 10;
2021 + }
2022 + for (j = 0; j < numypixels; j++) {
2023 + for (i = 0; i < numxpixels; i++) {
2024 + /* maybe it's overkill to have the most complicated calculation just for the error
2025 + calculation which we only need to figure out if encoding1 or encoding2 is better... */
2026 + if (srccolors[j][i][3] == 0) {
2027 + alphaenc2[4*j + i] = 6;
2028 + alphadist = 0;
2029 + }
2030 + else if (srccolors[j][i][3] == 255) {
2031 + alphaenc2[4*j + i] = 7;
2032 + alphadist = 0;
2033 + }
2034 + else if (srccolors[j][i][3] <= acutValues[0]) {
2035 + alphaenc2[4*j + i] = 0;
2036 + alphadist = srccolors[j][i][3] - alphabase[0];
2037 + }
2038 + else if (srccolors[j][i][3] <= acutValues[1]) {
2039 + alphaenc2[4*j + i] = 2;
2040 + alphadist = srccolors[j][i][3] - (alphabase[0] * 4 + alphabase[1] * 1) / 5;
2041 + }
2042 + else if (srccolors[j][i][3] <= acutValues[2]) {
2043 + alphaenc2[4*j + i] = 3;
2044 + alphadist = srccolors[j][i][3] - (alphabase[0] * 3 + alphabase[1] * 2) / 5;
2045 + }
2046 + else if (srccolors[j][i][3] <= acutValues[3]) {
2047 + alphaenc2[4*j + i] = 4;
2048 + alphadist = srccolors[j][i][3] - (alphabase[0] * 2 + alphabase[1] * 3) / 5;
2049 + }
2050 + else if (srccolors[j][i][3] <= acutValues[4]) {
2051 + alphaenc2[4*j + i] = 5;
2052 + alphadist = srccolors[j][i][3] - (alphabase[0] * 1 + alphabase[1] * 4) / 5;
2053 + }
2054 + else {
2055 + alphaenc2[4*j + i] = 1;
2056 + alphadist = srccolors[j][i][3] - alphabase[1];
2057 + }
2058 + alphablockerror2 += alphadist * alphadist;
2059 + }
2060 + }
2061 +
2062 +
2063 + /* skip this if the error is already very small
2064 + this encoding is MUCH better on average than #2 though, but expensive! */
2065 + if ((alphablockerror2 > 96) && (alphablockerror1 > 96)) {
2066 + GLshort blockerrlin1 = 0;
2067 + GLshort blockerrlin2 = 0;
2068 + GLubyte nralphainrangelow = 0;
2069 + GLubyte nralphainrangehigh = 0;
2070 + alphatest[0] = 0xff;
2071 + alphatest[1] = 0x0;
2072 + /* if we have large range it's likely there are values close to 0/255, try to map them to 0/255 */
2073 + for (j = 0; j < numypixels; j++) {
2074 + for (i = 0; i < numxpixels; i++) {
2075 + if ((srccolors[j][i][3] > alphatest[1]) && (srccolors[j][i][3] < (255 -(alphabase[1] - alphabase[0]) / 28)))
2076 + alphatest[1] = srccolors[j][i][3];
2077 + if ((srccolors[j][i][3] < alphatest[0]) && (srccolors[j][i][3] > (alphabase[1] - alphabase[0]) / 28))
2078 + alphatest[0] = srccolors[j][i][3];
2079 + }
2080 + }
2081 + /* shouldn't happen too often, don't really care about those degenerated cases */
2082 + if (alphatest[1] <= alphatest[0]) {
2083 + alphatest[0] = 1;
2084 + alphatest[1] = 254;
2085 +/* fprintf(stderr, "only 1 or 0 colors for encoding!\n");*/
2086 + }
2087 + for (aindex = 0; aindex < 5; aindex++) {
2088 + /* don't forget here is always rounded down */
2089 + acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10;
2090 + }
2091 +
2092 + /* find the "average" difference between the alpha values and the next encoded value.
2093 + This is then used to calculate new base values.
2094 + Should there be some weighting, i.e. those values closer to alphatest[x] have more weight,
2095 + since they will see more improvement, and also because the values in the middle are somewhat
2096 + likely to get no improvement at all (because the base values might move in different directions)?
2097 + OTOH it would mean the values in the middle are even less likely to get an improvement
2098 + */
2099 + for (j = 0; j < numypixels; j++) {
2100 + for (i = 0; i < numxpixels; i++) {
2101 + if (srccolors[j][i][3] <= alphatest[0] / 2) {
2102 + }
2103 + else if (srccolors[j][i][3] > ((255 + alphatest[1]) / 2)) {
2104 + }
2105 + else if (srccolors[j][i][3] <= acutValues[0]) {
2106 + blockerrlin1 += (srccolors[j][i][3] - alphatest[0]);
2107 + nralphainrangelow += 1;
2108 + }
2109 + else if (srccolors[j][i][3] <= acutValues[1]) {
2110 + blockerrlin1 += (srccolors[j][i][3] - (alphatest[0] * 4 + alphatest[1] * 1) / 5);
2111 + blockerrlin2 += (srccolors[j][i][3] - (alphatest[0] * 4 + alphatest[1] * 1) / 5);
2112 + nralphainrangelow += 1;
2113 + nralphainrangehigh += 1;
2114 + }
2115 + else if (srccolors[j][i][3] <= acutValues[2]) {
2116 + blockerrlin1 += (srccolors[j][i][3] - (alphatest[0] * 3 + alphatest[1] * 2) / 5);
2117 + blockerrlin2 += (srccolors[j][i][3] - (alphatest[0] * 3 + alphatest[1] * 2) / 5);
2118 + nralphainrangelow += 1;
2119 + nralphainrangehigh += 1;
2120 + }
2121 + else if (srccolors[j][i][3] <= acutValues[3]) {
2122 + blockerrlin1 += (srccolors[j][i][3] - (alphatest[0] * 2 + alphatest[1] * 3) / 5);
2123 + blockerrlin2 += (srccolors[j][i][3] - (alphatest[0] * 2 + alphatest[1] * 3) / 5);
2124 + nralphainrangelow += 1;
2125 + nralphainrangehigh += 1;
2126 + }
2127 + else if (srccolors[j][i][3] <= acutValues[4]) {
2128 + blockerrlin1 += (srccolors[j][i][3] - (alphatest[0] * 1 + alphatest[1] * 4) / 5);
2129 + blockerrlin2 += (srccolors[j][i][3] - (alphatest[0] * 1 + alphatest[1] * 4) / 5);
2130 + nralphainrangelow += 1;
2131 + nralphainrangehigh += 1;
2132 + }
2133 + else {
2134 + blockerrlin2 += (srccolors[j][i][3] - alphatest[1]);
2135 + nralphainrangehigh += 1;
2136 + }
2137 + }
2138 + }
2139 + /* shouldn't happen often, needed to avoid div by zero */
2140 + if (nralphainrangelow == 0) nralphainrangelow = 1;
2141 + if (nralphainrangehigh == 0) nralphainrangehigh = 1;
2142 + alphatest[0] = alphatest[0] + (blockerrlin1 / nralphainrangelow);
2143 +/* fprintf(stderr, "block err lin low %d, nr %d\n", blockerrlin1, nralphainrangelow);
2144 + fprintf(stderr, "block err lin high %d, nr %d\n", blockerrlin2, nralphainrangehigh);*/
2145 + /* again shouldn't really happen often... */
2146 + if (alphatest[0] < 0) {
2147 + alphatest[0] = 0;
2148 +/* fprintf(stderr, "adj alpha base val to 0\n");*/
2149 + }
2150 + alphatest[1] = alphatest[1] + (blockerrlin2 / nralphainrangehigh);
2151 + if (alphatest[1] > 255) {
2152 + alphatest[1] = 255;
2153 +/* fprintf(stderr, "adj alpha base val to 255\n");*/
2154 + }
2155 +
2156 + alphablockerror3 = 0;
2157 + for (aindex = 0; aindex < 5; aindex++) {
2158 + /* don't forget here is always rounded down */
2159 + acutValues[aindex] = (alphatest[0] * (10 - (2*aindex + 1)) + alphatest[1] * (2*aindex + 1)) / 10;
2160 + }
2161 + for (j = 0; j < numypixels; j++) {
2162 + for (i = 0; i < numxpixels; i++) {
2163 + /* maybe it's overkill to have the most complicated calculation just for the error
2164 + calculation which we only need to figure out if encoding1 or encoding2 is better... */
2165 + if (srccolors[j][i][3] <= alphatest[0] / 2) {
2166 + alphaenc3[4*j + i] = 6;
2167 + alphadist = srccolors[j][i][3];
2168 + }
2169 + else if (srccolors[j][i][3] > ((255 + alphatest[1]) / 2)) {
2170 + alphaenc3[4*j + i] = 7;
2171 + alphadist = 255 - srccolors[j][i][3];
2172 + }
2173 + else if (srccolors[j][i][3] <= acutValues[0]) {
2174 + alphaenc3[4*j + i] = 0;
2175 + alphadist = srccolors[j][i][3] - alphatest[0];
2176 + }
2177 + else if (srccolors[j][i][3] <= acutValues[1]) {
2178 + alphaenc3[4*j + i] = 2;
2179 + alphadist = srccolors[j][i][3] - (alphatest[0] * 4 + alphatest[1] * 1) / 5;
2180 + }
2181 + else if (srccolors[j][i][3] <= acutValues[2]) {
2182 + alphaenc3[4*j + i] = 3;
2183 + alphadist = srccolors[j][i][3] - (alphatest[0] * 3 + alphatest[1] * 2) / 5;
2184 + }
2185 + else if (srccolors[j][i][3] <= acutValues[3]) {
2186 + alphaenc3[4*j + i] = 4;
2187 + alphadist = srccolors[j][i][3] - (alphatest[0] * 2 + alphatest[1] * 3) / 5;
2188 + }
2189 + else if (srccolors[j][i][3] <= acutValues[4]) {
2190 + alphaenc3[4*j + i] = 5;
2191 + alphadist = srccolors[j][i][3] - (alphatest[0] * 1 + alphatest[1] * 4) / 5;
2192 + }
2193 + else {
2194 + alphaenc3[4*j + i] = 1;
2195 + alphadist = srccolors[j][i][3] - alphatest[1];
2196 + }
2197 + alphablockerror3 += alphadist * alphadist;
2198 + }
2199 + }
2200 + }
2201 + }
2202 + /* write the alpha values and encoding back. */
2203 + if ((alphablockerror1 <= alphablockerror2) && (alphablockerror1 <= alphablockerror3)) {
2204 +/* if (alphablockerror1 > 96) fprintf(stderr, "enc1 used, error %d\n", alphablockerror1);*/
2205 + writedxt5encodedalphablock( blkaddr, alphause[1], alphause[0], alphaenc1 );
2206 + }
2207 + else if (alphablockerror2 <= alphablockerror3) {
2208 +/* if (alphablockerror2 > 96) fprintf(stderr, "enc2 used, error %d\n", alphablockerror2);*/
2209 + writedxt5encodedalphablock( blkaddr, alphabase[0], alphabase[1], alphaenc2 );
2210 + }
2211 + else {
2212 +/* fprintf(stderr, "enc3 used, error %d\n", alphablockerror3);*/
2213 + writedxt5encodedalphablock( blkaddr, (GLubyte)alphatest[0], (GLubyte)alphatest[1], alphaenc3 );
2214 + }
2215 +}
2216 +
2217 +static void extractsrccolors( GLubyte srcpixels[4][4][4], const GLchan *srcaddr,
2218 + GLint srcRowStride, GLint numxpixels, GLint numypixels, GLint comps)
2219 +{
2220 + GLubyte i, j, c;
2221 + const GLchan *curaddr;
2222 + for (j = 0; j < numypixels; j++) {
2223 + curaddr = srcaddr + j * srcRowStride * comps;
2224 + for (i = 0; i < numxpixels; i++) {
2225 + for (c = 0; c < comps; c++) {
2226 + srcpixels[j][i][c] = *curaddr++ / (CHAN_MAX / 255);
2227 + }
2228 + }
2229 + }
2230 +}
2231 +
2232 +
2233 +static void tx_compress_dxtn(GLint srccomps, GLint width, GLint height, const GLubyte *srcPixData,
2234 + GLenum destFormat, GLubyte *dest, GLint dstRowStride)
2235 +{
2236 + GLubyte *blkaddr = dest;
2237 + GLubyte srcpixels[4][4][4];
2238 + const GLchan *srcaddr = srcPixData;
2239 + GLint numxpixels, numypixels;
2240 + GLint i, j;
2241 + GLint dstRowDiff;
2242 +
2243 + switch (destFormat) {
2244 + case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
2245 + case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
2246 + /* hmm we used to get called without dstRowStride... */
2247 + dstRowDiff = dstRowStride >= (width * 2) ? dstRowStride - (((width + 3) & ~3) * 2) : 0;
2248 +/* fprintf(stderr, "dxt1 tex width %d tex height %d dstRowStride %d\n",
2249 + width, height, dstRowStride); */
2250 + for (j = 0; j < height; j += 4) {
2251 + if (height > j + 3) numypixels = 4;
2252 + else numypixels = height - j;
2253 + srcaddr = srcPixData + j * width * srccomps;
2254 + for (i = 0; i < width; i += 4) {
2255 + if (width > i + 3) numxpixels = 4;
2256 + else numxpixels = width - i;
2257 + extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps);
2258 + encodedxtcolorblockfaster(blkaddr, srcpixels, numxpixels, numypixels, destFormat);
2259 + srcaddr += srccomps * numxpixels;
2260 + blkaddr += 8;
2261 + }
2262 + blkaddr += dstRowDiff;
2263 + }
2264 + break;
2265 + case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
2266 + dstRowDiff = dstRowStride >= (width * 4) ? dstRowStride - (((width + 3) & ~3) * 4) : 0;
2267 +/* fprintf(stderr, "dxt3 tex width %d tex height %d dstRowStride %d\n",
2268 + width, height, dstRowStride); */
2269 + for (j = 0; j < height; j += 4) {
2270 + if (height > j + 3) numypixels = 4;
2271 + else numypixels = height - j;
2272 + srcaddr = srcPixData + j * width * srccomps;
2273 + for (i = 0; i < width; i += 4) {
2274 + if (width > i + 3) numxpixels = 4;
2275 + else numxpixels = width - i;
2276 + extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps);
2277 + *blkaddr++ = (srcpixels[0][0][3] >> 4) | (srcpixels[0][1][3] & 0xf0);
2278 + *blkaddr++ = (srcpixels[0][2][3] >> 4) | (srcpixels[0][3][3] & 0xf0);
2279 + *blkaddr++ = (srcpixels[1][0][3] >> 4) | (srcpixels[1][1][3] & 0xf0);
2280 + *blkaddr++ = (srcpixels[1][2][3] >> 4) | (srcpixels[1][3][3] & 0xf0);
2281 + *blkaddr++ = (srcpixels[2][0][3] >> 4) | (srcpixels[2][1][3] & 0xf0);
2282 + *blkaddr++ = (srcpixels[2][2][3] >> 4) | (srcpixels[2][3][3] & 0xf0);
2283 + *blkaddr++ = (srcpixels[3][0][3] >> 4) | (srcpixels[3][1][3] & 0xf0);
2284 + *blkaddr++ = (srcpixels[3][2][3] >> 4) | (srcpixels[3][3][3] & 0xf0);
2285 + encodedxtcolorblockfaster(blkaddr, srcpixels, numxpixels, numypixels, destFormat);
2286 + srcaddr += srccomps * numxpixels;
2287 + blkaddr += 8;
2288 + }
2289 + blkaddr += dstRowDiff;
2290 + }
2291 + break;
2292 + case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
2293 + dstRowDiff = dstRowStride >= (width * 4) ? dstRowStride - (((width + 3) & ~3) * 4) : 0;
2294 +/* fprintf(stderr, "dxt5 tex width %d tex height %d dstRowStride %d\n",
2295 + width, height, dstRowStride); */
2296 + for (j = 0; j < height; j += 4) {
2297 + if (height > j + 3) numypixels = 4;
2298 + else numypixels = height - j;
2299 + srcaddr = srcPixData + j * width * srccomps;
2300 + for (i = 0; i < width; i += 4) {
2301 + if (width > i + 3) numxpixels = 4;
2302 + else numxpixels = width - i;
2303 + extractsrccolors(srcpixels, srcaddr, width, numxpixels, numypixels, srccomps);
2304 + encodedxt5alpha(blkaddr, srcpixels, numxpixels, numypixels);
2305 + encodedxtcolorblockfaster(blkaddr + 8, srcpixels, numxpixels, numypixels, destFormat);
2306 + srcaddr += srccomps * numxpixels;
2307 + blkaddr += 16;
2308 + }
2309 + blkaddr += dstRowDiff;
2310 + }
2311 + break;
2312 + default:
2313 + assert(false);
2314 + return;
2315 + }
2316 +}
2317 diff --git a/src/mesa/main/texformat.c b/src/mesa/main/texformat.c
2318 index baa3988f0a..3f8e7a49a2 100644
2319 --- a/src/mesa/main/texformat.c
2320 +++ b/src/mesa/main/texformat.c
2321 @@ -249,9 +249,7 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
2322 * 1D ARRAY textures in S3TC format.
2323 */
2324 if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) {
2325 - if (ctx->Mesa_DXTn)
2326 - RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
2327 - RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FXT1);
2328 + RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
2329 }
2330 RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_UNORM8);
2331 RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8X8_UNORM);
2332 @@ -260,9 +258,7 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
2333 case GL_COMPRESSED_RGBA_ARB:
2334 /* We don't use texture compression for 1D and 1D array textures. */
2335 if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) {
2336 - if (ctx->Mesa_DXTn)
2337 - RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3); /* Not rgba_dxt1, see spec */
2338 - RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FXT1);
2339 + RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3); /* Not rgba_dxt1, see spec */
2340 }
2341 RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_UNORM);
2342 RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
2343 @@ -502,15 +498,13 @@ _mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
2344 RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB);
2345 break;
2346 case GL_COMPRESSED_SRGB_EXT:
2347 - if (ctx->Mesa_DXTn)
2348 - RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1);
2349 + RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1);
2350 RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_SRGB8);
2351 RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
2352 RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB);
2353 break;
2354 case GL_COMPRESSED_SRGB_ALPHA_EXT:
2355 - if (ctx->Mesa_DXTn)
2356 - RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3); /* Not srgba_dxt1, see spec */
2357 + RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3); /* Not srgba_dxt1, see spec */
2358 RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SRGB);
2359 RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
2360 RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB);
2361 diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
2362 index 5509d808cd..1d6da393c2 100644
2363 --- a/src/mesa/main/teximage.c
2364 +++ b/src/mesa/main/teximage.c
2365 @@ -2765,38 +2765,6 @@ _mesa_choose_texture_format(struct gl_context *ctx,
2366 }
2367 }
2368
2369 - /* If the application requested compression to an S3TC format but we don't
2370 - * have the DXTn library, force a generic compressed format instead.
2371 - */
2372 - if (internalFormat != format && format != GL_NONE) {
2373 - const GLenum before = internalFormat;
2374 -
2375 - switch (internalFormat) {
2376 - case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
2377 - if (!ctx->Mesa_DXTn)
2378 - internalFormat = GL_COMPRESSED_RGB;
2379 - break;
2380 - case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
2381 - case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
2382 - case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
2383 - if (!ctx->Mesa_DXTn)
2384 - internalFormat = GL_COMPRESSED_RGBA;
2385 - break;
2386 - default:
2387 - break;
2388 - }
2389 -
2390 - if (before != internalFormat) {
2391 - _mesa_warning(ctx,
2392 - "DXT compression requested (%s), "
2393 - "but libtxc_dxtn library not installed. Using %s "
2394 - "instead.",
2395 - _mesa_enum_to_string(before),
2396 - _mesa_enum_to_string(internalFormat));
2397 - }
2398 - }
2399 -
2400 - /* choose format from scratch */
2401 f = ctx->Driver.ChooseTextureFormat(ctx, target, internalFormat,
2402 format, type);
2403 assert(f != MESA_FORMAT_NONE);
2404 diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
2405 index 381ff9dae0..b96313e2aa 100644
2406 --- a/src/mesa/state_tracker/st_context.c
2407 +++ b/src/mesa/state_tracker/st_context.c
2408 @@ -405,7 +405,7 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
2409 /* GL limits and extensions */
2410 st_init_limits(pipe->screen, &ctx->Const, &ctx->Extensions);
2411 st_init_extensions(pipe->screen, &ctx->Const,
2412 - &ctx->Extensions, &st->options, ctx->Mesa_DXTn);
2413 + &ctx->Extensions, &st->options);
2414
2415 if (st_have_perfmon(st)) {
2416 ctx->Extensions.AMD_performance_monitor = GL_TRUE;
2417 diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
2418 index 74193cc492..65b6bd34aa 100644
2419 --- a/src/mesa/state_tracker/st_extensions.c
2420 +++ b/src/mesa/state_tracker/st_extensions.c
2421 @@ -569,8 +569,7 @@ get_max_samples_for_formats(struct pipe_screen *screen,
2422 void st_init_extensions(struct pipe_screen *screen,
2423 struct gl_constants *consts,
2424 struct gl_extensions *extensions,
2425 - struct st_config_options *options,
2426 - boolean has_lib_dxtc)
2427 + struct st_config_options *options)
2428 {
2429 unsigned i;
2430 GLboolean *extension_table = (GLboolean *) extensions;
2431 @@ -960,11 +959,6 @@ void st_init_extensions(struct pipe_screen *screen,
2432
2433 /* Below are the cases which cannot be moved into tables easily. */
2434
2435 - if (!has_lib_dxtc && !options->force_s3tc_enable) {
2436 - extensions->EXT_texture_compression_s3tc = GL_FALSE;
2437 - extensions->ANGLE_texture_compression_dxt = GL_FALSE;
2438 - }
2439 -
2440 if (screen->get_shader_param(screen, PIPE_SHADER_TESS_CTRL,
2441 PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
2442 extensions->ARB_tessellation_shader = GL_TRUE;
2443 diff --git a/src/mesa/state_tracker/st_extensions.h b/src/mesa/state_tracker/st_extensions.h
2444 index faff11fd5d..951185caa3 100644
2445 --- a/src/mesa/state_tracker/st_extensions.h
2446 +++ b/src/mesa/state_tracker/st_extensions.h
2447 @@ -40,8 +40,7 @@ extern void st_init_limits(struct pipe_screen *screen,
2448 extern void st_init_extensions(struct pipe_screen *screen,
2449 struct gl_constants *consts,
2450 struct gl_extensions *extensions,
2451 - struct st_config_options *options,
2452 - boolean has_lib_dxtc);
2453 + struct st_config_options *options);
2454
2455
2456 #endif /* ST_EXTENSIONS_H */
2457 diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
2458 index 012f1a4015..4d0b4265b7 100644
2459 --- a/src/mesa/state_tracker/st_format.c
2460 +++ b/src/mesa/state_tracker/st_format.c
2461 @@ -2275,13 +2275,13 @@ st_ChooseTextureFormat(struct gl_context *ctx, GLenum target,
2462 }
2463
2464 pFormat = st_choose_format(st, internalFormat, format, type,
2465 - pTarget, 0, bindings, ctx->Mesa_DXTn);
2466 + pTarget, 0, bindings, GL_TRUE);
2467
2468 if (pFormat == PIPE_FORMAT_NONE && !is_renderbuffer) {
2469 /* try choosing format again, this time without render target bindings */
2470 pFormat = st_choose_format(st, internalFormat, format, type,
2471 pTarget, 0, PIPE_BIND_SAMPLER_VIEW,
2472 - ctx->Mesa_DXTn);
2473 + GL_TRUE);
2474 }
2475
2476 if (pFormat == PIPE_FORMAT_NONE) {
2477 diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
2478 index 5ad0816184..999e1230cb 100644
2479 --- a/src/mesa/state_tracker/st_manager.c
2480 +++ b/src/mesa/state_tracker/st_manager.c
2481 @@ -1137,7 +1137,7 @@ get_version(struct pipe_screen *screen,
2482 _mesa_init_extensions(&extensions);
2483
2484 st_init_limits(screen, &consts, &extensions);
2485 - st_init_extensions(screen, &consts, &extensions, options, GL_TRUE);
2486 + st_init_extensions(screen, &consts, &extensions, options);
2487
2488 return _mesa_get_version(&extensions, &consts, api);
2489 }
2490 --
2491 2.13.5
2492

  ViewVC Help
Powered by ViewVC 1.1.30