Some initial RGB and RGBA floating point texture formats.
[mesa.git] / src / mesa / main / texformat.c
1 /**
2 * \file texformat.c
3 * Texture formats.
4 *
5 * \author Gareth Hughes
6 */
7
8 /*
9 * Mesa 3-D graphics library
10 * Version: 5.1
11 *
12 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be included
22 * in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
28 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 */
31
32
33 #include "glheader.h"
34 #include "colormac.h"
35 #include "context.h"
36 #include "image.h"
37 #include "imports.h"
38 #include "mtypes.h"
39 #include "texformat.h"
40 #include "teximage.h"
41 #include "texstate.h"
42
43
44 /* Texel fetch routines for all supported formats
45 */
46 #define DIM 1
47 #include "texformat_tmp.h"
48
49 #define DIM 2
50 #include "texformat_tmp.h"
51
52 #define DIM 3
53 #include "texformat_tmp.h"
54
55 /**
56 * Null texel fetch function.
57 *
58 * Have to have this so the FetchTexel function pointer is never NULL.
59 */
60 static void fetch_null_texel( const struct gl_texture_image *texImage,
61 GLint i, GLint j, GLint k, GLchan *texel )
62 {
63 texel[RCOMP] = 0;
64 texel[GCOMP] = 0;
65 texel[BCOMP] = 0;
66 texel[ACOMP] = 0;
67 _mesa_warning(NULL, "fetch_null_texel() called!");
68 }
69
70 static void fetch_null_texelf( const struct gl_texture_image *texImage,
71 GLint i, GLint j, GLint k, GLfloat *texel )
72 {
73 texel[RCOMP] = 0.0;
74 texel[GCOMP] = 0.0;
75 texel[BCOMP] = 0.0;
76 texel[ACOMP] = 0.0;
77 _mesa_warning(NULL, "fetch_null_texelf() called!");
78 }
79
80
81 /***************************************************************/
82 /** \name Default GLchan-based formats */
83 /*@{*/
84
85 const struct gl_texture_format _mesa_texformat_rgba = {
86 MESA_FORMAT_RGBA, /* MesaFormat */
87 GL_RGBA, /* BaseFormat */
88 CHAN_BITS, /* RedBits */
89 CHAN_BITS, /* GreenBits */
90 CHAN_BITS, /* BlueBits */
91 CHAN_BITS, /* AlphaBits */
92 0, /* LuminanceBits */
93 0, /* IntensityBits */
94 0, /* IndexBits */
95 0, /* DepthBits */
96 4 * CHAN_BITS / 8, /* TexelBytes */
97 fetch_texel_1d_rgba, /* FetchTexel1D */
98 fetch_texel_2d_rgba, /* FetchTexel2D */
99 fetch_texel_3d_rgba, /* FetchTexel3D */
100 fetch_texel_1d_f_rgba, /* FetchTexel1Df */
101 fetch_texel_2d_f_rgba, /* FetchTexel2Df */
102 fetch_texel_3d_f_rgba, /* FetchTexel3Df */
103 };
104
105 const struct gl_texture_format _mesa_texformat_rgb = {
106 MESA_FORMAT_RGB, /* MesaFormat */
107 GL_RGB, /* BaseFormat */
108 CHAN_BITS, /* RedBits */
109 CHAN_BITS, /* GreenBits */
110 CHAN_BITS, /* BlueBits */
111 0, /* AlphaBits */
112 0, /* LuminanceBits */
113 0, /* IntensityBits */
114 0, /* IndexBits */
115 0, /* DepthBits */
116 3 * CHAN_BITS / 8, /* TexelBytes */
117 fetch_texel_1d_rgb, /* FetchTexel1D */
118 fetch_texel_2d_rgb, /* FetchTexel2D */
119 fetch_texel_3d_rgb, /* FetchTexel3D */
120 fetch_texel_1d_f_rgb, /* FetchTexel1Df */
121 fetch_texel_2d_f_rgb, /* FetchTexel2Df */
122 fetch_texel_3d_f_rgb, /* FetchTexel3Df */
123 };
124
125 const struct gl_texture_format _mesa_texformat_alpha = {
126 MESA_FORMAT_ALPHA, /* MesaFormat */
127 GL_ALPHA, /* BaseFormat */
128 0, /* RedBits */
129 0, /* GreenBits */
130 0, /* BlueBits */
131 CHAN_BITS, /* AlphaBits */
132 0, /* LuminanceBits */
133 0, /* IntensityBits */
134 0, /* IndexBits */
135 0, /* DepthBits */
136 CHAN_BITS / 8, /* TexelBytes */
137 fetch_texel_1d_alpha, /* FetchTexel1D */
138 fetch_texel_2d_alpha, /* FetchTexel2D */
139 fetch_texel_3d_alpha, /* FetchTexel3D */
140 fetch_texel_1d_f_alpha, /* FetchTexel1Df */
141 fetch_texel_2d_f_alpha, /* FetchTexel2Df */
142 fetch_texel_3d_f_alpha, /* FetchTexel3Df */
143 };
144
145 const struct gl_texture_format _mesa_texformat_luminance = {
146 MESA_FORMAT_LUMINANCE, /* MesaFormat */
147 GL_LUMINANCE, /* BaseFormat */
148 0, /* RedBits */
149 0, /* GreenBits */
150 0, /* BlueBits */
151 0, /* AlphaBits */
152 CHAN_BITS, /* LuminanceBits */
153 0, /* IntensityBits */
154 0, /* IndexBits */
155 0, /* DepthBits */
156 CHAN_BITS / 8, /* TexelBytes */
157 fetch_texel_1d_luminance, /* FetchTexel1D */
158 fetch_texel_2d_luminance, /* FetchTexel2D */
159 fetch_texel_3d_luminance, /* FetchTexel3D */
160 fetch_texel_1d_f_luminance, /* FetchTexel1Df */
161 fetch_texel_2d_f_luminance, /* FetchTexel2Df */
162 fetch_texel_3d_f_luminance, /* FetchTexel3Df */
163 };
164
165 const struct gl_texture_format _mesa_texformat_luminance_alpha = {
166 MESA_FORMAT_LUMINANCE_ALPHA, /* MesaFormat */
167 GL_LUMINANCE_ALPHA, /* BaseFormat */
168 0, /* RedBits */
169 0, /* GreenBits */
170 0, /* BlueBits */
171 CHAN_BITS, /* AlphaBits */
172 CHAN_BITS, /* LuminanceBits */
173 0, /* IntensityBits */
174 0, /* IndexBits */
175 0, /* DepthBits */
176 2 * CHAN_BITS / 8, /* TexelBytes */
177 fetch_texel_1d_luminance_alpha, /* FetchTexel1D */
178 fetch_texel_2d_luminance_alpha, /* FetchTexel2D */
179 fetch_texel_3d_luminance_alpha, /* FetchTexel3D */
180 fetch_texel_1d_f_luminance_alpha, /* FetchTexel1Df */
181 fetch_texel_2d_f_luminance_alpha, /* FetchTexel2Df */
182 fetch_texel_3d_f_luminance_alpha, /* FetchTexel3Df */
183 };
184
185 const struct gl_texture_format _mesa_texformat_intensity = {
186 MESA_FORMAT_INTENSITY, /* MesaFormat */
187 GL_INTENSITY, /* BaseFormat */
188 0, /* RedBits */
189 0, /* GreenBits */
190 0, /* BlueBits */
191 0, /* AlphaBits */
192 0, /* LuminanceBits */
193 CHAN_BITS, /* IntensityBits */
194 0, /* IndexBits */
195 0, /* DepthBits */
196 CHAN_BITS / 8, /* TexelBytes */
197 fetch_texel_1d_intensity, /* FetchTexel1D */
198 fetch_texel_2d_intensity, /* FetchTexel2D */
199 fetch_texel_3d_intensity, /* FetchTexel3D */
200 fetch_texel_1d_f_intensity, /* FetchTexel1Df */
201 fetch_texel_2d_f_intensity, /* FetchTexel2Df */
202 fetch_texel_3d_f_intensity, /* FetchTexel3Df */
203 };
204
205 const struct gl_texture_format _mesa_texformat_color_index = {
206 MESA_FORMAT_COLOR_INDEX, /* MesaFormat */
207 GL_COLOR_INDEX, /* BaseFormat */
208 0, /* RedBits */
209 0, /* GreenBits */
210 0, /* BlueBits */
211 0, /* AlphaBits */
212 0, /* LuminanceBits */
213 0, /* IntensityBits */
214 CHAN_BITS, /* IndexBits */
215 0, /* DepthBits */
216 CHAN_BITS / 8, /* TexelBytes */
217 fetch_texel_1d_color_index, /* FetchTexel1D */
218 fetch_texel_2d_color_index, /* FetchTexel2D */
219 fetch_texel_3d_color_index, /* FetchTexel3D */
220 fetch_texel_1d_f_color_index, /* FetchTexel1Df */
221 fetch_texel_2d_f_color_index, /* FetchTexel2Df */
222 fetch_texel_3d_f_color_index, /* FetchTexel3Df */
223 };
224
225 /* XXX someday implement 16, 24 and 32-bit integer depth images */
226 const struct gl_texture_format _mesa_texformat_depth_component = {
227 MESA_FORMAT_DEPTH_COMPONENT, /* MesaFormat */
228 GL_DEPTH_COMPONENT, /* BaseFormat */
229 0, /* RedBits */
230 0, /* GreenBits */
231 0, /* BlueBits */
232 0, /* AlphaBits */
233 0, /* LuminanceBits */
234 0, /* IntensityBits */
235 0, /* IndexBits */
236 sizeof(GLfloat) * 8, /* DepthBits */
237 sizeof(GLfloat), /* TexelBytes */
238 fetch_null_texel, /* FetchTexel1D */
239 fetch_null_texel, /* FetchTexel1D */
240 fetch_null_texel, /* FetchTexel1D */
241 fetch_texel_1d_f_depth_component, /* FetchTexel1Df */
242 fetch_texel_2d_f_depth_component, /* FetchTexel2Df */
243 fetch_texel_3d_f_depth_component, /* FetchTexel3Df */
244 };
245
246 const struct gl_texture_format _mesa_texformat_rgba_float32 = {
247 MESA_FORMAT_RGBA_FLOAT32, /* MesaFormat */
248 GL_RGBA, /* BaseFormat */
249 8 * sizeof(GLfloat), /* RedBits */
250 8 * sizeof(GLfloat), /* GreenBits */
251 8 * sizeof(GLfloat), /* BlueBits */
252 8 * sizeof(GLfloat), /* AlphaBits */
253 0, /* LuminanceBits */
254 0, /* IntensityBits */
255 0, /* IndexBits */
256 0, /* DepthBits */
257 4 * sizeof(GLfloat), /* TexelBytes */
258 fetch_null_texel, /* FetchTexel1D */
259 fetch_null_texel, /* FetchTexel1D */
260 fetch_null_texel, /* FetchTexel1D */
261 fetch_texel_1d_f_rgba_f32, /* FetchTexel1Df */
262 fetch_texel_2d_f_rgba_f32, /* FetchTexel2Df */
263 fetch_texel_3d_f_rgba_f32, /* FetchTexel3Df */
264 };
265
266 const struct gl_texture_format _mesa_texformat_rgba_float16 = {
267 MESA_FORMAT_RGBA_FLOAT16, /* MesaFormat */
268 GL_RGBA, /* BaseFormat */
269 8 * sizeof(GLhalfNV), /* RedBits */
270 8 * sizeof(GLhalfNV), /* GreenBits */
271 8 * sizeof(GLhalfNV), /* BlueBits */
272 8 * sizeof(GLhalfNV), /* AlphaBits */
273 0, /* LuminanceBits */
274 0, /* IntensityBits */
275 0, /* IndexBits */
276 0, /* DepthBits */
277 4 * sizeof(GLhalfNV), /* TexelBytes */
278 fetch_null_texel, /* FetchTexel1D */
279 fetch_null_texel, /* FetchTexel1D */
280 fetch_null_texel, /* FetchTexel1D */
281 fetch_texel_1d_f_rgba_f16, /* FetchTexel1Df */
282 fetch_texel_2d_f_rgba_f16, /* FetchTexel2Df */
283 fetch_texel_3d_f_rgba_f16, /* FetchTexel3Df */
284 };
285
286 const struct gl_texture_format _mesa_texformat_rgb_float32 = {
287 MESA_FORMAT_RGB_FLOAT32, /* MesaFormat */
288 GL_RGB, /* BaseFormat */
289 8 * sizeof(GLfloat), /* RedBits */
290 8 * sizeof(GLfloat), /* GreenBits */
291 8 * sizeof(GLfloat), /* BlueBits */
292 0, /* AlphaBits */
293 0, /* LuminanceBits */
294 0, /* IntensityBits */
295 0, /* IndexBits */
296 0, /* DepthBits */
297 4 * sizeof(GLfloat), /* TexelBytes */
298 fetch_null_texel, /* FetchTexel1D */
299 fetch_null_texel, /* FetchTexel1D */
300 fetch_null_texel, /* FetchTexel1D */
301 fetch_texel_1d_f_rgb_f32, /* FetchTexel1Df */
302 fetch_texel_2d_f_rgb_f32, /* FetchTexel2Df */
303 fetch_texel_3d_f_rgb_f32, /* FetchTexel3Df */
304 };
305
306 const struct gl_texture_format _mesa_texformat_rgb_float16 = {
307 MESA_FORMAT_RGB_FLOAT16, /* MesaFormat */
308 GL_RGB, /* BaseFormat */
309 8 * sizeof(GLhalfNV), /* RedBits */
310 8 * sizeof(GLhalfNV), /* GreenBits */
311 8 * sizeof(GLhalfNV), /* BlueBits */
312 0, /* AlphaBits */
313 0, /* LuminanceBits */
314 0, /* IntensityBits */
315 0, /* IndexBits */
316 0, /* DepthBits */
317 4 * sizeof(GLhalfNV), /* TexelBytes */
318 fetch_null_texel, /* FetchTexel1D */
319 fetch_null_texel, /* FetchTexel1D */
320 fetch_null_texel, /* FetchTexel1D */
321 fetch_texel_1d_f_rgb_f16, /* FetchTexel1Df */
322 fetch_texel_2d_f_rgb_f16, /* FetchTexel2Df */
323 fetch_texel_3d_f_rgb_f16, /* FetchTexel3Df */
324 };
325
326
327 /*@}*/
328
329
330 /***************************************************************/
331 /** \name Hardware formats */
332 /*@{*/
333
334 const struct gl_texture_format _mesa_texformat_rgba8888 = {
335 MESA_FORMAT_RGBA8888, /* MesaFormat */
336 GL_RGBA, /* BaseFormat */
337 8, /* RedBits */
338 8, /* GreenBits */
339 8, /* BlueBits */
340 8, /* AlphaBits */
341 0, /* LuminanceBits */
342 0, /* IntensityBits */
343 0, /* IndexBits */
344 0, /* DepthBits */
345 4, /* TexelBytes */
346 fetch_texel_1d_rgba8888, /* FetchTexel1D */
347 fetch_texel_2d_rgba8888, /* FetchTexel2D */
348 fetch_texel_3d_rgba8888, /* FetchTexel3D */
349 fetch_texel_1d_f_rgba8888, /* FetchTexel1Df */
350 fetch_texel_2d_f_rgba8888, /* FetchTexel2Df */
351 fetch_texel_3d_f_rgba8888, /* FetchTexel3Df */
352 };
353
354 const struct gl_texture_format _mesa_texformat_argb8888 = {
355 MESA_FORMAT_ARGB8888, /* MesaFormat */
356 GL_RGBA, /* BaseFormat */
357 8, /* RedBits */
358 8, /* GreenBits */
359 8, /* BlueBits */
360 8, /* AlphaBits */
361 0, /* LuminanceBits */
362 0, /* IntensityBits */
363 0, /* IndexBits */
364 0, /* DepthBits */
365 4, /* TexelBytes */
366 fetch_texel_1d_argb8888, /* FetchTexel1D */
367 fetch_texel_2d_argb8888, /* FetchTexel2D */
368 fetch_texel_3d_argb8888, /* FetchTexel3D */
369 fetch_texel_1d_f_argb8888, /* FetchTexel1Df */
370 fetch_texel_2d_f_argb8888, /* FetchTexel2Df */
371 fetch_texel_3d_f_argb8888, /* FetchTexel3Df */
372 };
373
374 const struct gl_texture_format _mesa_texformat_rgb888 = {
375 MESA_FORMAT_RGB888, /* MesaFormat */
376 GL_RGB, /* BaseFormat */
377 8, /* RedBits */
378 8, /* GreenBits */
379 8, /* BlueBits */
380 0, /* AlphaBits */
381 0, /* LuminanceBits */
382 0, /* IntensityBits */
383 0, /* IndexBits */
384 0, /* DepthBits */
385 3, /* TexelBytes */
386 fetch_texel_1d_rgb888, /* FetchTexel1D */
387 fetch_texel_2d_rgb888, /* FetchTexel2D */
388 fetch_texel_3d_rgb888, /* FetchTexel3D */
389 fetch_texel_1d_f_rgb888, /* FetchTexel1Df */
390 fetch_texel_2d_f_rgb888, /* FetchTexel2Df */
391 fetch_texel_3d_f_rgb888, /* FetchTexel3Df */
392 };
393
394 const struct gl_texture_format _mesa_texformat_rgb565 = {
395 MESA_FORMAT_RGB565, /* MesaFormat */
396 GL_RGB, /* BaseFormat */
397 5, /* RedBits */
398 6, /* GreenBits */
399 5, /* BlueBits */
400 0, /* AlphaBits */
401 0, /* LuminanceBits */
402 0, /* IntensityBits */
403 0, /* IndexBits */
404 0, /* DepthBits */
405 2, /* TexelBytes */
406 fetch_texel_1d_rgb565, /* FetchTexel1D */
407 fetch_texel_2d_rgb565, /* FetchTexel2D */
408 fetch_texel_3d_rgb565, /* FetchTexel3D */
409 fetch_texel_1d_f_rgb565, /* FetchTexel1Df */
410 fetch_texel_2d_f_rgb565, /* FetchTexel2Df */
411 fetch_texel_3d_f_rgb565, /* FetchTexel3Df */
412 };
413
414 const struct gl_texture_format _mesa_texformat_argb4444 = {
415 MESA_FORMAT_ARGB4444, /* MesaFormat */
416 GL_RGBA, /* BaseFormat */
417 4, /* RedBits */
418 4, /* GreenBits */
419 4, /* BlueBits */
420 4, /* AlphaBits */
421 0, /* LuminanceBits */
422 0, /* IntensityBits */
423 0, /* IndexBits */
424 0, /* DepthBits */
425 2, /* TexelBytes */
426 fetch_texel_1d_argb4444, /* FetchTexel1D */
427 fetch_texel_2d_argb4444, /* FetchTexel2D */
428 fetch_texel_3d_argb4444, /* FetchTexel3D */
429 fetch_texel_1d_f_argb4444, /* FetchTexel1Df */
430 fetch_texel_2d_f_argb4444, /* FetchTexel2Df */
431 fetch_texel_3d_f_argb4444, /* FetchTexel3Df */
432 };
433
434 const struct gl_texture_format _mesa_texformat_argb1555 = {
435 MESA_FORMAT_ARGB1555, /* MesaFormat */
436 GL_RGBA, /* BaseFormat */
437 5, /* RedBits */
438 5, /* GreenBits */
439 5, /* BlueBits */
440 1, /* AlphaBits */
441 0, /* LuminanceBits */
442 0, /* IntensityBits */
443 0, /* IndexBits */
444 0, /* DepthBits */
445 2, /* TexelBytes */
446 fetch_texel_1d_argb1555, /* FetchTexel1D */
447 fetch_texel_2d_argb1555, /* FetchTexel2D */
448 fetch_texel_3d_argb1555, /* FetchTexel3D */
449 fetch_texel_1d_f_argb1555, /* FetchTexel1Df */
450 fetch_texel_2d_f_argb1555, /* FetchTexel2Df */
451 fetch_texel_3d_f_argb1555, /* FetchTexel3Df */
452 };
453
454 const struct gl_texture_format _mesa_texformat_al88 = {
455 MESA_FORMAT_AL88, /* MesaFormat */
456 GL_LUMINANCE_ALPHA, /* BaseFormat */
457 0, /* RedBits */
458 0, /* GreenBits */
459 0, /* BlueBits */
460 8, /* AlphaBits */
461 8, /* LuminanceBits */
462 0, /* IntensityBits */
463 0, /* IndexBits */
464 0, /* DepthBits */
465 2, /* TexelBytes */
466 fetch_texel_1d_al88, /* FetchTexel1D */
467 fetch_texel_2d_al88, /* FetchTexel2D */
468 fetch_texel_3d_al88, /* FetchTexel3D */
469 fetch_texel_1d_f_al88, /* FetchTexel1Df */
470 fetch_texel_2d_f_al88, /* FetchTexel2Df */
471 fetch_texel_3d_f_al88, /* FetchTexel3Df */
472 };
473
474 const struct gl_texture_format _mesa_texformat_rgb332 = {
475 MESA_FORMAT_RGB332, /* MesaFormat */
476 GL_RGB, /* BaseFormat */
477 3, /* RedBits */
478 3, /* GreenBits */
479 2, /* BlueBits */
480 0, /* AlphaBits */
481 0, /* LuminanceBits */
482 0, /* IntensityBits */
483 0, /* IndexBits */
484 0, /* DepthBits */
485 1, /* TexelBytes */
486 fetch_texel_1d_rgb332, /* FetchTexel1D */
487 fetch_texel_2d_rgb332, /* FetchTexel2D */
488 fetch_texel_3d_rgb332, /* FetchTexel3D */
489 fetch_texel_1d_f_rgb332, /* FetchTexel1Df */
490 fetch_texel_2d_f_rgb332, /* FetchTexel2Df */
491 fetch_texel_3d_f_rgb332, /* FetchTexel3Df */
492 };
493
494 const struct gl_texture_format _mesa_texformat_a8 = {
495 MESA_FORMAT_A8, /* MesaFormat */
496 GL_ALPHA, /* BaseFormat */
497 0, /* RedBits */
498 0, /* GreenBits */
499 0, /* BlueBits */
500 8, /* AlphaBits */
501 0, /* LuminanceBits */
502 0, /* IntensityBits */
503 0, /* IndexBits */
504 0, /* DepthBits */
505 1, /* TexelBytes */
506 fetch_texel_1d_a8, /* FetchTexel1D */
507 fetch_texel_2d_a8, /* FetchTexel2D */
508 fetch_texel_3d_a8, /* FetchTexel3D */
509 fetch_texel_1d_f_a8, /* FetchTexel1Df */
510 fetch_texel_2d_f_a8, /* FetchTexel2Df */
511 fetch_texel_3d_f_a8, /* FetchTexel3Df */
512 };
513
514 const struct gl_texture_format _mesa_texformat_l8 = {
515 MESA_FORMAT_L8, /* MesaFormat */
516 GL_LUMINANCE, /* BaseFormat */
517 0, /* RedBits */
518 0, /* GreenBits */
519 0, /* BlueBits */
520 0, /* AlphaBits */
521 8, /* LuminanceBits */
522 0, /* IntensityBits */
523 0, /* IndexBits */
524 0, /* DepthBits */
525 1, /* TexelBytes */
526 fetch_texel_1d_l8, /* FetchTexel1D */
527 fetch_texel_2d_l8, /* FetchTexel2D */
528 fetch_texel_3d_l8, /* FetchTexel3D */
529 fetch_texel_1d_f_l8, /* FetchTexel1Df */
530 fetch_texel_2d_f_l8, /* FetchTexel2Df */
531 fetch_texel_3d_f_l8, /* FetchTexel3Df */
532 };
533
534 const struct gl_texture_format _mesa_texformat_i8 = {
535 MESA_FORMAT_I8, /* MesaFormat */
536 GL_INTENSITY, /* BaseFormat */
537 0, /* RedBits */
538 0, /* GreenBits */
539 0, /* BlueBits */
540 0, /* AlphaBits */
541 0, /* LuminanceBits */
542 8, /* IntensityBits */
543 0, /* IndexBits */
544 0, /* DepthBits */
545 1, /* TexelBytes */
546 fetch_texel_1d_i8, /* FetchTexel1D */
547 fetch_texel_2d_i8, /* FetchTexel2D */
548 fetch_texel_3d_i8, /* FetchTexel3D */
549 fetch_texel_1d_f_i8, /* FetchTexel1Df */
550 fetch_texel_2d_f_i8, /* FetchTexel2Df */
551 fetch_texel_3d_f_i8, /* FetchTexel3Df */
552 };
553
554 const struct gl_texture_format _mesa_texformat_ci8 = {
555 MESA_FORMAT_CI8, /* MesaFormat */
556 GL_COLOR_INDEX, /* BaseFormat */
557 0, /* RedBits */
558 0, /* GreenBits */
559 0, /* BlueBits */
560 0, /* AlphaBits */
561 0, /* LuminanceBits */
562 0, /* IntensityBits */
563 8, /* IndexBits */
564 0, /* DepthBits */
565 1, /* TexelBytes */
566 fetch_texel_1d_ci8, /* FetchTexel1D */
567 fetch_texel_2d_ci8, /* FetchTexel2D */
568 fetch_texel_3d_ci8, /* FetchTexel3D */
569 fetch_texel_1d_f_ci8, /* FetchTexel1Df */
570 fetch_texel_2d_f_ci8, /* FetchTexel2Df */
571 fetch_texel_3d_f_ci8, /* FetchTexel3Df */
572 };
573
574 const struct gl_texture_format _mesa_texformat_ycbcr = {
575 MESA_FORMAT_YCBCR, /* MesaFormat */
576 GL_YCBCR_MESA, /* BaseFormat */
577 0, /* RedBits */
578 0, /* GreenBits */
579 0, /* BlueBits */
580 0, /* AlphaBits */
581 0, /* LuminanceBits */
582 0, /* IntensityBits */
583 0, /* IndexBits */
584 0, /* DepthBits */
585 2, /* TexelBytes */
586 fetch_texel_1d_ycbcr, /* FetchTexel1D */
587 fetch_texel_2d_ycbcr, /* FetchTexel2D */
588 fetch_texel_3d_ycbcr, /* FetchTexel3D */
589 fetch_texel_1d_f_ycbcr, /* FetchTexel1Df */
590 fetch_texel_2d_f_ycbcr, /* FetchTexel2Df */
591 fetch_texel_3d_f_ycbcr, /* FetchTexel3Df */
592 };
593
594 const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
595 MESA_FORMAT_YCBCR_REV, /* MesaFormat */
596 GL_YCBCR_MESA, /* BaseFormat */
597 0, /* RedBits */
598 0, /* GreenBits */
599 0, /* BlueBits */
600 0, /* AlphaBits */
601 0, /* LuminanceBits */
602 0, /* IntensityBits */
603 0, /* IndexBits */
604 0, /* DepthBits */
605 2, /* TexelBytes */
606 fetch_texel_1d_ycbcr_rev, /* FetchTexel1D */
607 fetch_texel_2d_ycbcr_rev, /* FetchTexel2D */
608 fetch_texel_3d_ycbcr_rev, /* FetchTexel3D */
609 fetch_texel_1d_f_ycbcr_rev, /* FetchTexel1Df */
610 fetch_texel_2d_f_ycbcr_rev, /* FetchTexel2Df */
611 fetch_texel_3d_f_ycbcr_rev, /* FetchTexel3Df */
612 };
613
614 const struct gl_texture_format _mesa_texformat_rgb_fxt1 = {
615 MESA_FORMAT_RGB_FXT1, /* MesaFormat */
616 GL_RGB, /* BaseFormat */
617 4, /*approx*/ /* RedBits */
618 4, /*approx*/ /* GreenBits */
619 4, /*approx*/ /* BlueBits */
620 0, /* AlphaBits */
621 0, /* LuminanceBits */
622 0, /* IntensityBits */
623 0, /* IndexBits */
624 0, /* DepthBits */
625 0, /* TexelBytes */
626 NULL, /*impossible*/ /* FetchTexel1D */
627 fetch_texel_2d_rgb_fxt1, /* FetchTexel2D */
628 NULL, /*impossible*/ /* FetchTexel3D */
629 NULL, /*impossible*/ /* FetchTexel1Df */
630 fetch_texel_2d_f_rgb_fxt1, /* FetchTexel2Df */
631 NULL, /*impossible*/ /* FetchTexel3Df */
632 };
633
634 const struct gl_texture_format _mesa_texformat_rgba_fxt1 = {
635 MESA_FORMAT_RGBA_FXT1, /* MesaFormat */
636 GL_RGBA, /* BaseFormat */
637 4, /*approx*/ /* RedBits */
638 4, /*approx*/ /* GreenBits */
639 4, /*approx*/ /* BlueBits */
640 1, /*approx*/ /* AlphaBits */
641 0, /* LuminanceBits */
642 0, /* IntensityBits */
643 0, /* IndexBits */
644 0, /* DepthBits */
645 0, /* TexelBytes */
646 NULL, /*impossible*/ /* FetchTexel1D */
647 fetch_texel_2d_rgba_fxt1, /* FetchTexel2D */
648 NULL, /*impossible*/ /* FetchTexel3D */
649 NULL, /*impossible*/ /* FetchTexel1Df */
650 fetch_texel_2d_f_rgba_fxt1, /* FetchTexel2Df */
651 NULL, /*impossible*/ /* FetchTexel3Df */
652 };
653
654 const struct gl_texture_format _mesa_texformat_rgb_dxt1 = {
655 MESA_FORMAT_RGB_DXT1, /* MesaFormat */
656 GL_RGB, /* BaseFormat */
657 4, /*approx*/ /* RedBits */
658 4, /*approx*/ /* GreenBits */
659 4, /*approx*/ /* BlueBits */
660 0, /* AlphaBits */
661 0, /* LuminanceBits */
662 0, /* IntensityBits */
663 0, /* IndexBits */
664 0, /* DepthBits */
665 0, /* TexelBytes */
666 NULL, /*impossible*/ /* FetchTexel1D */
667 fetch_texel_2d_rgb_dxt1, /* FetchTexel2D */
668 NULL, /*impossible*/ /* FetchTexel3D */
669 NULL, /*impossible*/ /* FetchTexel1Df */
670 fetch_texel_2d_f_rgb_dxt1, /* FetchTexel2Df */
671 NULL, /*impossible*/ /* FetchTexel3Df */
672 };
673
674 const struct gl_texture_format _mesa_texformat_rgba_dxt1 = {
675 MESA_FORMAT_RGBA_DXT1, /* MesaFormat */
676 GL_RGBA, /* BaseFormat */
677 4, /*approx*/ /* RedBits */
678 4, /*approx*/ /* GreenBits */
679 4, /*approx*/ /* BlueBits */
680 1, /*approx*/ /* AlphaBits */
681 0, /* LuminanceBits */
682 0, /* IntensityBits */
683 0, /* IndexBits */
684 0, /* DepthBits */
685 0, /* TexelBytes */
686 NULL, /*impossible*/ /* FetchTexel1D */
687 fetch_texel_2d_rgba_dxt1, /* FetchTexel2D */
688 NULL, /*impossible*/ /* FetchTexel3D */
689 NULL, /*impossible*/ /* FetchTexel1Df */
690 fetch_texel_2d_f_rgba_dxt1, /* FetchTexel2Df */
691 NULL, /*impossible*/ /* FetchTexel3Df */
692 };
693
694 const struct gl_texture_format _mesa_texformat_rgba_dxt3 = {
695 MESA_FORMAT_RGBA_DXT3, /* MesaFormat */
696 GL_RGBA, /* BaseFormat */
697 4, /*approx*/ /* RedBits */
698 4, /*approx*/ /* GreenBits */
699 4, /*approx*/ /* BlueBits */
700 4, /*approx*/ /* AlphaBits */
701 0, /* LuminanceBits */
702 0, /* IntensityBits */
703 0, /* IndexBits */
704 0, /* DepthBits */
705 0, /* TexelBytes */
706 NULL, /*impossible*/ /* FetchTexel1D */
707 fetch_texel_2d_rgba_dxt3, /* FetchTexel2D */
708 NULL, /*impossible*/ /* FetchTexel3D */
709 NULL, /*impossible*/ /* FetchTexel1Df */
710 fetch_texel_2d_f_rgba_dxt3, /* FetchTexel2Df */
711 NULL, /*impossible*/ /* FetchTexel3Df */
712 };
713
714 const struct gl_texture_format _mesa_texformat_rgba_dxt5 = {
715 MESA_FORMAT_RGBA_DXT5, /* MesaFormat */
716 GL_RGBA, /* BaseFormat */
717 4,/*approx*/ /* RedBits */
718 4,/*approx*/ /* GreenBits */
719 4,/*approx*/ /* BlueBits */
720 4,/*approx*/ /* AlphaBits */
721 0, /* LuminanceBits */
722 0, /* IntensityBits */
723 0, /* IndexBits */
724 0, /* DepthBits */
725 0, /* TexelBytes */
726 NULL, /*impossible*/ /* FetchTexel1D */
727 fetch_texel_2d_rgba_dxt5, /* FetchTexel2D */
728 NULL, /*impossible*/ /* FetchTexel3D */
729 NULL, /*impossible*/ /* FetchTexel1Df */
730 fetch_texel_2d_f_rgba_dxt5, /* FetchTexel2Df */
731 NULL, /*impossible*/ /* FetchTexel3Df */
732 };
733
734
735 /* Big-endian */
736 #if 0
737 const struct gl_texture_format _mesa_texformat_abgr8888 = {
738 MESA_FORMAT_ABGR8888, /* MesaFormat */
739 GL_RGBA, /* BaseFormat */
740 GL_UNSIGNED_INT_8_8_8_8, /* Type */
741 8, /* RedBits */
742 8, /* GreenBits */
743 8, /* BlueBits */
744 8, /* AlphaBits */
745 0, /* LuminanceBits */
746 0, /* IntensityBits */
747 0, /* IndexBits */
748 0, /* DepthBits */
749 4, /* TexelBytes */
750 fetch_texel_1d_abgr8888, /* FetchTexel1D */
751 fetch_texel_2d_abgr8888, /* FetchTexel2D */
752 fetch_texel_3d_abgr8888, /* FetchTexel3D */
753 /* XXX float fetchers */
754 };
755
756 const struct gl_texture_format _mesa_texformat_bgra8888 = {
757 MESA_FORMAT_BGRA8888, /* MesaFormat */
758 GL_RGBA, /* BaseFormat */
759 GL_UNSIGNED_INT_8_8_8_8, /* Type */
760 8, /* RedBits */
761 8, /* GreenBits */
762 8, /* BlueBits */
763 8, /* AlphaBits */
764 0, /* LuminanceBits */
765 0, /* IntensityBits */
766 0, /* IndexBits */
767 0, /* DepthBits */
768 4, /* TexelBytes */
769 fetch_texel_1d_bgra8888, /* FetchTexel1D */
770 fetch_texel_2d_bgra8888, /* FetchTexel2D */
771 fetch_texel_3d_bgra8888, /* FetchTexel3D */
772 /* XXX float fetchers */
773 };
774
775 const struct gl_texture_format _mesa_texformat_bgr888 = {
776 MESA_FORMAT_BGR888, /* MesaFormat */
777 GL_RGB, /* BaseFormat */
778 GL_UNSIGNED_BYTE, /* Type */
779 8, /* RedBits */
780 8, /* GreenBits */
781 8, /* BlueBits */
782 0, /* AlphaBits */
783 0, /* LuminanceBits */
784 0, /* IntensityBits */
785 0, /* IndexBits */
786 0, /* DepthBits */
787 3, /* TexelBytes */
788 fetch_texel_1d_bgr888, /* FetchTexel1D */
789 fetch_texel_2d_bgr888, /* FetchTexel2D */
790 fetch_texel_3d_bgr888, /* FetchTexel3D */
791 /* XXX float fetchers */
792 };
793
794 const struct gl_texture_format _mesa_texformat_bgr565 = {
795 MESA_FORMAT_BGR565, /* MesaFormat */
796 GL_RGB, /* BaseFormat */
797 GL_UNSIGNED_SHORT_5_6_5, /* Type */
798 5, /* RedBits */
799 6, /* GreenBits */
800 5, /* BlueBits */
801 0, /* AlphaBits */
802 0, /* LuminanceBits */
803 0, /* IntensityBits */
804 0, /* IndexBits */
805 0, /* DepthBits */
806 2, /* TexelBytes */
807 fetch_texel_1d_bgr565, /* FetchTexel1D */
808 fetch_texel_2d_bgr565, /* FetchTexel2D */
809 fetch_texel_3d_bgr565, /* FetchTexel3D */
810 /* XXX float fetchers */
811 };
812
813 const struct gl_texture_format _mesa_texformat_bgra4444 = {
814 MESA_FORMAT_BGRA4444, /* MesaFormat */
815 GL_RGBA, /* BaseFormat */
816 GL_UNSIGNED_SHORT_4_4_4_4_REV, /* Type */
817 4, /* RedBits */
818 4, /* GreenBits */
819 4, /* BlueBits */
820 4, /* AlphaBits */
821 0, /* LuminanceBits */
822 0, /* IntensityBits */
823 0, /* IndexBits */
824 0, /* DepthBits */
825 2, /* TexelBytes */
826 fetch_texel_1d_bgra4444, /* FetchTexel1D */
827 fetch_texel_2d_bgra4444, /* FetchTexel2D */
828 fetch_texel_3d_bgra4444, /* FetchTexel3D */
829 /* XXX float fetchers */
830 };
831
832 const struct gl_texture_format _mesa_texformat_bgra5551 = {
833 MESA_FORMAT_BGRA5551, /* MesaFormat */
834 GL_RGBA, /* BaseFormat */
835 GL_UNSIGNED_SHORT_1_5_5_5_REV, /* Type */
836 5, /* RedBits */
837 5, /* GreenBits */
838 5, /* BlueBits */
839 1, /* AlphaBits */
840 0, /* LuminanceBits */
841 0, /* IntensityBits */
842 0, /* IndexBits */
843 0, /* DepthBits */
844 2, /* TexelBytes */
845 fetch_texel_1d_bgra1555, /* FetchTexel1D */
846 fetch_texel_2d_bgra1555, /* FetchTexel2D */
847 fetch_texel_3d_bgra1555, /* FetchTexel3D */
848 /* XXX float fetchers */
849 };
850
851 const struct gl_texture_format _mesa_texformat_la88 = {
852 MESA_FORMAT_LA88, /* MesaFormat */
853 GL_LUMINANCE_ALPHA, /* BaseFormat */
854 GL_UNSIGNED_BYTE, /* Type */
855 0, /* RedBits */
856 0, /* GreenBits */
857 0, /* BlueBits */
858 8, /* AlphaBits */
859 8, /* LuminanceBits */
860 0, /* IntensityBits */
861 0, /* IndexBits */
862 0, /* DepthBits */
863 2, /* TexelBytes */
864 fetch_texel_1d_la88, /* FetchTexel1D */
865 fetch_texel_2d_la88, /* FetchTexel2D */
866 fetch_texel_3d_la88, /* FetchTexel3D */
867 /* XXX float fetchers */
868 };
869
870 const struct gl_texture_format _mesa_texformat_bgr233 = {
871 MESA_FORMAT_BGR233, /* MesaFormat */
872 GL_RGB, /* BaseFormat */
873 GL_UNSIGNED_BYTE_3_3_2, /* Type */
874 3, /* RedBits */
875 3, /* GreenBits */
876 2, /* BlueBits */
877 0, /* AlphaBits */
878 0, /* LuminanceBits */
879 0, /* IntensityBits */
880 0, /* IndexBits */
881 0, /* DepthBits */
882 1, /* TexelBytes */
883 fetch_texel_1d_bgr233, /* FetchTexel1D */
884 fetch_texel_2d_bgr233, /* FetchTexel2D */
885 fetch_texel_3d_bgr233, /* FetchTexel3D */
886 /* XXX float fetchers */
887 };
888 #endif
889
890 /*@}*/
891
892
893 /***************************************************************/
894 /** \name Null format (useful for proxy textures) */
895 /*@{*/
896
897 const struct gl_texture_format _mesa_null_texformat = {
898 -1, /* MesaFormat */
899 0, /* BaseFormat */
900 0, /* RedBits */
901 0, /* GreenBits */
902 0, /* BlueBits */
903 0, /* AlphaBits */
904 0, /* LuminanceBits */
905 0, /* IntensityBits */
906 0, /* IndexBits */
907 0, /* DepthBits */
908 0, /* TexelBytes */
909 fetch_null_texel, /* FetchTexel1D */
910 fetch_null_texel, /* FetchTexel2D */
911 fetch_null_texel, /* FetchTexel3D */
912 fetch_null_texelf, /* FetchTexel1Df */
913 fetch_null_texelf, /* FetchTexel2Df */
914 fetch_null_texelf, /* FetchTexel3Df */
915 };
916
917 /*@}*/
918
919
920 /**
921 * Determine whether a given texture format is a hardware texture
922 * format.
923 *
924 * \param format texture format.
925 *
926 * \return GL_TRUE if \p format is a hardware texture format, or GL_FALSE
927 * otherwise.
928 *
929 * \p format is a hardware texture format if gl_texture_format::MesaFormat is
930 * lower than _format::MESA_FORMAT_RGBA.
931 */
932 GLboolean
933 _mesa_is_hardware_tex_format( const struct gl_texture_format *format )
934 {
935 return (format->MesaFormat < MESA_FORMAT_RGBA);
936 }
937
938
939 /**
940 * Choose an appropriate texture format given the format, type and
941 * internalFormat parameters passed to glTexImage().
942 *
943 * \param ctx the GL context.
944 * \param internalFormat user's prefered internal texture format.
945 * \param format incoming image pixel format.
946 * \param type incoming image data type.
947 *
948 * \return a pointer to a gl_texture_format object which describes the
949 * choosen texture format, or NULL on failure.
950 *
951 * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
952 * typically override this function with a specialized version.
953 */
954 const struct gl_texture_format *
955 _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
956 GLenum format, GLenum type )
957 {
958 (void) format;
959 (void) type;
960
961 switch ( internalFormat ) {
962 /* GH: Bias towards GL_RGB, GL_RGBA texture formats. This has
963 * got to be better than sticking them way down the end of this
964 * huge list.
965 */
966 case 4: /* Quake3 uses this... */
967 case GL_RGBA:
968 return &_mesa_texformat_rgba;
969
970 case 3: /* ... and this. */
971 case GL_RGB:
972 return &_mesa_texformat_rgb;
973
974 /* GH: Okay, keep checking as normal. Still test for GL_RGB,
975 * GL_RGBA formats first.
976 */
977 case GL_RGBA2:
978 case GL_RGBA4:
979 case GL_RGB5_A1:
980 case GL_RGBA8:
981 case GL_RGB10_A2:
982 case GL_RGBA12:
983 case GL_RGBA16:
984 return &_mesa_texformat_rgba;
985
986 case GL_R3_G3_B2:
987 case GL_RGB4:
988 case GL_RGB5:
989 case GL_RGB8:
990 case GL_RGB10:
991 case GL_RGB12:
992 case GL_RGB16:
993 return &_mesa_texformat_rgb;
994
995 case GL_ALPHA:
996 case GL_ALPHA4:
997 case GL_ALPHA8:
998 case GL_ALPHA12:
999 case GL_ALPHA16:
1000 return &_mesa_texformat_alpha;
1001
1002 case 1:
1003 case GL_LUMINANCE:
1004 case GL_LUMINANCE4:
1005 case GL_LUMINANCE8:
1006 case GL_LUMINANCE12:
1007 case GL_LUMINANCE16:
1008 return &_mesa_texformat_luminance;
1009
1010 case 2:
1011 case GL_LUMINANCE_ALPHA:
1012 case GL_LUMINANCE4_ALPHA4:
1013 case GL_LUMINANCE6_ALPHA2:
1014 case GL_LUMINANCE8_ALPHA8:
1015 case GL_LUMINANCE12_ALPHA4:
1016 case GL_LUMINANCE12_ALPHA12:
1017 case GL_LUMINANCE16_ALPHA16:
1018 return &_mesa_texformat_luminance_alpha;
1019
1020 case GL_INTENSITY:
1021 case GL_INTENSITY4:
1022 case GL_INTENSITY8:
1023 case GL_INTENSITY12:
1024 case GL_INTENSITY16:
1025 return &_mesa_texformat_intensity;
1026
1027 case GL_COLOR_INDEX:
1028 case GL_COLOR_INDEX1_EXT:
1029 case GL_COLOR_INDEX2_EXT:
1030 case GL_COLOR_INDEX4_EXT:
1031 case GL_COLOR_INDEX8_EXT:
1032 case GL_COLOR_INDEX12_EXT:
1033 case GL_COLOR_INDEX16_EXT:
1034 return &_mesa_texformat_color_index;
1035
1036 case GL_DEPTH_COMPONENT:
1037 case GL_DEPTH_COMPONENT16_SGIX:
1038 case GL_DEPTH_COMPONENT24_SGIX:
1039 case GL_DEPTH_COMPONENT32_SGIX:
1040 if (!ctx->Extensions.SGIX_depth_texture)
1041 _mesa_problem(ctx, "depth format without GL_SGIX_depth_texture");
1042 return &_mesa_texformat_depth_component;
1043
1044 case GL_COMPRESSED_ALPHA_ARB:
1045 if (!ctx->Extensions.ARB_texture_compression)
1046 _mesa_problem(ctx, "texture compression extension not enabled");
1047 return &_mesa_texformat_alpha;
1048 case GL_COMPRESSED_LUMINANCE_ARB:
1049 if (!ctx->Extensions.ARB_texture_compression)
1050 _mesa_problem(ctx, "texture compression extension not enabled");
1051 return &_mesa_texformat_luminance;
1052 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
1053 if (!ctx->Extensions.ARB_texture_compression)
1054 _mesa_problem(ctx, "texture compression extension not enabled");
1055 return &_mesa_texformat_luminance_alpha;
1056 case GL_COMPRESSED_INTENSITY_ARB:
1057 if (!ctx->Extensions.ARB_texture_compression)
1058 _mesa_problem(ctx, "texture compression extension not enabled");
1059 return &_mesa_texformat_intensity;
1060 case GL_COMPRESSED_RGB_ARB:
1061 if (!ctx->Extensions.ARB_texture_compression)
1062 _mesa_problem(ctx, "texture compression extension not enabled");
1063 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1064 return &_mesa_texformat_rgb_fxt1;
1065 else if (ctx->Extensions.EXT_texture_compression_s3tc || ctx->Extensions.S3_s3tc)
1066 return &_mesa_texformat_rgb_dxt1;
1067 return &_mesa_texformat_rgb;
1068 case GL_COMPRESSED_RGBA_ARB:
1069 if (!ctx->Extensions.ARB_texture_compression)
1070 _mesa_problem(ctx, "texture compression extension not enabled");
1071 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1072 return &_mesa_texformat_rgba_fxt1;
1073 else if (ctx->Extensions.EXT_texture_compression_s3tc || ctx->Extensions.S3_s3tc)
1074 return &_mesa_texformat_rgba_dxt3; /* Not rgba_dxt1! See the spec */
1075 return &_mesa_texformat_rgba;
1076
1077 /* GL_MESA_ycrcr_texture */
1078 case GL_YCBCR_MESA:
1079 if (type == GL_UNSIGNED_SHORT_8_8_MESA)
1080 return &_mesa_texformat_ycbcr;
1081 else
1082 return &_mesa_texformat_ycbcr_rev;
1083
1084 /* GL_3DFX_texture_compression_FXT1 */
1085 case GL_COMPRESSED_RGB_FXT1_3DFX:
1086 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1087 return &_mesa_texformat_rgb_fxt1;
1088 else
1089 return NULL;
1090 case GL_COMPRESSED_RGBA_FXT1_3DFX:
1091 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1092 return &_mesa_texformat_rgba_fxt1;
1093 else
1094 return NULL;
1095
1096 /* GL_EXT_texture_compression_s3tc */
1097 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1098 if (ctx->Extensions.EXT_texture_compression_s3tc)
1099 return &_mesa_texformat_rgb_dxt1;
1100 else
1101 return NULL;
1102 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1103 if (ctx->Extensions.EXT_texture_compression_s3tc)
1104 return &_mesa_texformat_rgba_dxt1;
1105 else
1106 return NULL;
1107 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1108 if (ctx->Extensions.EXT_texture_compression_s3tc)
1109 return &_mesa_texformat_rgba_dxt3;
1110 else
1111 return NULL;
1112 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1113 if (ctx->Extensions.EXT_texture_compression_s3tc)
1114 return &_mesa_texformat_rgba_dxt5;
1115 else
1116 return NULL;
1117
1118 /* GL_S3_s3tc */
1119 case GL_RGB_S3TC:
1120 case GL_RGB4_S3TC:
1121 if (ctx->Extensions.S3_s3tc)
1122 return &_mesa_texformat_rgb_dxt1;
1123 else
1124 return NULL;
1125 case GL_RGBA_S3TC:
1126 case GL_RGBA4_S3TC:
1127 if (ctx->Extensions.S3_s3tc)
1128 return &_mesa_texformat_rgba_dxt3;
1129 else
1130 return NULL;
1131
1132 /* XXX prototype/example code */
1133 /* GL_ATI_texture_float or GL_NV_float_buffer */
1134 case GL_RGBA_FLOAT32_ATI:
1135 return &_mesa_texformat_rgba_float32;
1136 case GL_RGBA_FLOAT16_ATI:
1137 return &_mesa_texformat_rgba_float16;
1138 case GL_RGB_FLOAT32_ATI:
1139 return &_mesa_texformat_rgb_float32;
1140 case GL_RGB_FLOAT16_ATI:
1141 return &_mesa_texformat_rgb_float16;
1142
1143 default:
1144 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
1145 return NULL;
1146 }
1147 }
1148
1149
1150 /**
1151 * Return the base texture format for the given compressed format
1152 *
1153 * Called via dd_function_table::Driver.BaseCompressedTexFormat.
1154 * This function is used by software rasterizers. Hardware drivers
1155 * which support texture compression should not use this function but
1156 * a specialized function instead.
1157 */
1158 GLint
1159 _mesa_base_compressed_texformat(GLcontext *ctx, GLint intFormat)
1160 {
1161 switch (intFormat) {
1162 case GL_COMPRESSED_ALPHA_ARB:
1163 return GL_ALPHA;
1164 case GL_COMPRESSED_LUMINANCE_ARB:
1165 return GL_LUMINANCE;
1166 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
1167 return GL_LUMINANCE_ALPHA;
1168 case GL_COMPRESSED_INTENSITY_ARB:
1169 return GL_INTENSITY;
1170 case GL_COMPRESSED_RGB_ARB:
1171 return GL_RGB;
1172 case GL_COMPRESSED_RGBA_ARB:
1173 return GL_RGBA;
1174 default:
1175 return -1; /* not a recognized compressed format */
1176 }
1177 }