Fix hardware ROP state handling (Roland Scheidegger)
[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 const struct gl_texture_format _mesa_texformat_depth_component = {
226 MESA_FORMAT_DEPTH_COMPONENT, /* MesaFormat */
227 GL_DEPTH_COMPONENT, /* BaseFormat */
228 0, /* RedBits */
229 0, /* GreenBits */
230 0, /* BlueBits */
231 0, /* AlphaBits */
232 0, /* LuminanceBits */
233 0, /* IntensityBits */
234 0, /* IndexBits */
235 sizeof(GLfloat) * 8, /* DepthBits */
236 sizeof(GLfloat), /* TexelBytes */
237 fetch_null_texel, /* FetchTexel1D */
238 fetch_null_texel, /* FetchTexel1D */
239 fetch_null_texel, /* FetchTexel1D */
240 fetch_texel_1d_f_depth_component, /* FetchTexel1Df */
241 fetch_texel_2d_f_depth_component, /* FetchTexel2Df */
242 fetch_texel_3d_f_depth_component, /* FetchTexel3Df */
243 };
244
245 /*@}*/
246
247
248 /***************************************************************/
249 /** \name Hardware formats */
250 /*@{*/
251
252 const struct gl_texture_format _mesa_texformat_rgba8888 = {
253 MESA_FORMAT_RGBA8888, /* MesaFormat */
254 GL_RGBA, /* BaseFormat */
255 8, /* RedBits */
256 8, /* GreenBits */
257 8, /* BlueBits */
258 8, /* AlphaBits */
259 0, /* LuminanceBits */
260 0, /* IntensityBits */
261 0, /* IndexBits */
262 0, /* DepthBits */
263 4, /* TexelBytes */
264 fetch_texel_1d_rgba8888, /* FetchTexel1D */
265 fetch_texel_2d_rgba8888, /* FetchTexel2D */
266 fetch_texel_3d_rgba8888, /* FetchTexel3D */
267 fetch_texel_1d_f_rgba8888, /* FetchTexel1Df */
268 fetch_texel_2d_f_rgba8888, /* FetchTexel2Df */
269 fetch_texel_3d_f_rgba8888, /* FetchTexel3Df */
270 };
271
272 const struct gl_texture_format _mesa_texformat_argb8888 = {
273 MESA_FORMAT_ARGB8888, /* MesaFormat */
274 GL_RGBA, /* BaseFormat */
275 8, /* RedBits */
276 8, /* GreenBits */
277 8, /* BlueBits */
278 8, /* AlphaBits */
279 0, /* LuminanceBits */
280 0, /* IntensityBits */
281 0, /* IndexBits */
282 0, /* DepthBits */
283 4, /* TexelBytes */
284 fetch_texel_1d_argb8888, /* FetchTexel1D */
285 fetch_texel_2d_argb8888, /* FetchTexel2D */
286 fetch_texel_3d_argb8888, /* FetchTexel3D */
287 fetch_texel_1d_f_argb8888, /* FetchTexel1Df */
288 fetch_texel_2d_f_argb8888, /* FetchTexel2Df */
289 fetch_texel_3d_f_argb8888, /* FetchTexel3Df */
290 };
291
292 const struct gl_texture_format _mesa_texformat_rgb888 = {
293 MESA_FORMAT_RGB888, /* MesaFormat */
294 GL_RGB, /* BaseFormat */
295 8, /* RedBits */
296 8, /* GreenBits */
297 8, /* BlueBits */
298 0, /* AlphaBits */
299 0, /* LuminanceBits */
300 0, /* IntensityBits */
301 0, /* IndexBits */
302 0, /* DepthBits */
303 3, /* TexelBytes */
304 fetch_texel_1d_rgb888, /* FetchTexel1D */
305 fetch_texel_2d_rgb888, /* FetchTexel2D */
306 fetch_texel_3d_rgb888, /* FetchTexel3D */
307 fetch_texel_1d_f_rgb888, /* FetchTexel1Df */
308 fetch_texel_2d_f_rgb888, /* FetchTexel2Df */
309 fetch_texel_3d_f_rgb888, /* FetchTexel3Df */
310 };
311
312 const struct gl_texture_format _mesa_texformat_rgb565 = {
313 MESA_FORMAT_RGB565, /* MesaFormat */
314 GL_RGB, /* BaseFormat */
315 5, /* RedBits */
316 6, /* GreenBits */
317 5, /* BlueBits */
318 0, /* AlphaBits */
319 0, /* LuminanceBits */
320 0, /* IntensityBits */
321 0, /* IndexBits */
322 0, /* DepthBits */
323 2, /* TexelBytes */
324 fetch_texel_1d_rgb565, /* FetchTexel1D */
325 fetch_texel_2d_rgb565, /* FetchTexel2D */
326 fetch_texel_3d_rgb565, /* FetchTexel3D */
327 fetch_texel_1d_f_rgb565, /* FetchTexel1Df */
328 fetch_texel_2d_f_rgb565, /* FetchTexel2Df */
329 fetch_texel_3d_f_rgb565, /* FetchTexel3Df */
330 };
331
332 const struct gl_texture_format _mesa_texformat_argb4444 = {
333 MESA_FORMAT_ARGB4444, /* MesaFormat */
334 GL_RGBA, /* BaseFormat */
335 4, /* RedBits */
336 4, /* GreenBits */
337 4, /* BlueBits */
338 4, /* AlphaBits */
339 0, /* LuminanceBits */
340 0, /* IntensityBits */
341 0, /* IndexBits */
342 0, /* DepthBits */
343 2, /* TexelBytes */
344 fetch_texel_1d_argb4444, /* FetchTexel1D */
345 fetch_texel_2d_argb4444, /* FetchTexel2D */
346 fetch_texel_3d_argb4444, /* FetchTexel3D */
347 fetch_texel_1d_f_argb4444, /* FetchTexel1Df */
348 fetch_texel_2d_f_argb4444, /* FetchTexel2Df */
349 fetch_texel_3d_f_argb4444, /* FetchTexel3Df */
350 };
351
352 const struct gl_texture_format _mesa_texformat_argb1555 = {
353 MESA_FORMAT_ARGB1555, /* MesaFormat */
354 GL_RGBA, /* BaseFormat */
355 5, /* RedBits */
356 5, /* GreenBits */
357 5, /* BlueBits */
358 1, /* AlphaBits */
359 0, /* LuminanceBits */
360 0, /* IntensityBits */
361 0, /* IndexBits */
362 0, /* DepthBits */
363 2, /* TexelBytes */
364 fetch_texel_1d_argb1555, /* FetchTexel1D */
365 fetch_texel_2d_argb1555, /* FetchTexel2D */
366 fetch_texel_3d_argb1555, /* FetchTexel3D */
367 fetch_texel_1d_f_argb1555, /* FetchTexel1Df */
368 fetch_texel_2d_f_argb1555, /* FetchTexel2Df */
369 fetch_texel_3d_f_argb1555, /* FetchTexel3Df */
370 };
371
372 const struct gl_texture_format _mesa_texformat_al88 = {
373 MESA_FORMAT_AL88, /* MesaFormat */
374 GL_LUMINANCE_ALPHA, /* BaseFormat */
375 0, /* RedBits */
376 0, /* GreenBits */
377 0, /* BlueBits */
378 8, /* AlphaBits */
379 8, /* LuminanceBits */
380 0, /* IntensityBits */
381 0, /* IndexBits */
382 0, /* DepthBits */
383 2, /* TexelBytes */
384 fetch_texel_1d_al88, /* FetchTexel1D */
385 fetch_texel_2d_al88, /* FetchTexel2D */
386 fetch_texel_3d_al88, /* FetchTexel3D */
387 fetch_texel_1d_f_al88, /* FetchTexel1Df */
388 fetch_texel_2d_f_al88, /* FetchTexel2Df */
389 fetch_texel_3d_f_al88, /* FetchTexel3Df */
390 };
391
392 const struct gl_texture_format _mesa_texformat_rgb332 = {
393 MESA_FORMAT_RGB332, /* MesaFormat */
394 GL_RGB, /* BaseFormat */
395 3, /* RedBits */
396 3, /* GreenBits */
397 2, /* BlueBits */
398 0, /* AlphaBits */
399 0, /* LuminanceBits */
400 0, /* IntensityBits */
401 0, /* IndexBits */
402 0, /* DepthBits */
403 1, /* TexelBytes */
404 fetch_texel_1d_rgb332, /* FetchTexel1D */
405 fetch_texel_2d_rgb332, /* FetchTexel2D */
406 fetch_texel_3d_rgb332, /* FetchTexel3D */
407 fetch_texel_1d_f_rgb332, /* FetchTexel1Df */
408 fetch_texel_2d_f_rgb332, /* FetchTexel2Df */
409 fetch_texel_3d_f_rgb332, /* FetchTexel3Df */
410 };
411
412 const struct gl_texture_format _mesa_texformat_a8 = {
413 MESA_FORMAT_A8, /* MesaFormat */
414 GL_ALPHA, /* BaseFormat */
415 0, /* RedBits */
416 0, /* GreenBits */
417 0, /* BlueBits */
418 8, /* AlphaBits */
419 0, /* LuminanceBits */
420 0, /* IntensityBits */
421 0, /* IndexBits */
422 0, /* DepthBits */
423 1, /* TexelBytes */
424 fetch_texel_1d_a8, /* FetchTexel1D */
425 fetch_texel_2d_a8, /* FetchTexel2D */
426 fetch_texel_3d_a8, /* FetchTexel3D */
427 fetch_texel_1d_f_a8, /* FetchTexel1Df */
428 fetch_texel_2d_f_a8, /* FetchTexel2Df */
429 fetch_texel_3d_f_a8, /* FetchTexel3Df */
430 };
431
432 const struct gl_texture_format _mesa_texformat_l8 = {
433 MESA_FORMAT_L8, /* MesaFormat */
434 GL_LUMINANCE, /* BaseFormat */
435 0, /* RedBits */
436 0, /* GreenBits */
437 0, /* BlueBits */
438 0, /* AlphaBits */
439 8, /* LuminanceBits */
440 0, /* IntensityBits */
441 0, /* IndexBits */
442 0, /* DepthBits */
443 1, /* TexelBytes */
444 fetch_texel_1d_l8, /* FetchTexel1D */
445 fetch_texel_2d_l8, /* FetchTexel2D */
446 fetch_texel_3d_l8, /* FetchTexel3D */
447 fetch_texel_1d_f_l8, /* FetchTexel1Df */
448 fetch_texel_2d_f_l8, /* FetchTexel2Df */
449 fetch_texel_3d_f_l8, /* FetchTexel3Df */
450 };
451
452 const struct gl_texture_format _mesa_texformat_i8 = {
453 MESA_FORMAT_I8, /* MesaFormat */
454 GL_INTENSITY, /* BaseFormat */
455 0, /* RedBits */
456 0, /* GreenBits */
457 0, /* BlueBits */
458 0, /* AlphaBits */
459 0, /* LuminanceBits */
460 8, /* IntensityBits */
461 0, /* IndexBits */
462 0, /* DepthBits */
463 1, /* TexelBytes */
464 fetch_texel_1d_i8, /* FetchTexel1D */
465 fetch_texel_2d_i8, /* FetchTexel2D */
466 fetch_texel_3d_i8, /* FetchTexel3D */
467 fetch_texel_1d_f_i8, /* FetchTexel1Df */
468 fetch_texel_2d_f_i8, /* FetchTexel2Df */
469 fetch_texel_3d_f_i8, /* FetchTexel3Df */
470 };
471
472 const struct gl_texture_format _mesa_texformat_ci8 = {
473 MESA_FORMAT_CI8, /* MesaFormat */
474 GL_COLOR_INDEX, /* BaseFormat */
475 0, /* RedBits */
476 0, /* GreenBits */
477 0, /* BlueBits */
478 0, /* AlphaBits */
479 0, /* LuminanceBits */
480 0, /* IntensityBits */
481 8, /* IndexBits */
482 0, /* DepthBits */
483 1, /* TexelBytes */
484 fetch_texel_1d_ci8, /* FetchTexel1D */
485 fetch_texel_2d_ci8, /* FetchTexel2D */
486 fetch_texel_3d_ci8, /* FetchTexel3D */
487 fetch_texel_1d_f_ci8, /* FetchTexel1Df */
488 fetch_texel_2d_f_ci8, /* FetchTexel2Df */
489 fetch_texel_3d_f_ci8, /* FetchTexel3Df */
490 };
491
492 const struct gl_texture_format _mesa_texformat_ycbcr = {
493 MESA_FORMAT_YCBCR, /* MesaFormat */
494 GL_YCBCR_MESA, /* BaseFormat */
495 0, /* RedBits */
496 0, /* GreenBits */
497 0, /* BlueBits */
498 0, /* AlphaBits */
499 0, /* LuminanceBits */
500 0, /* IntensityBits */
501 0, /* IndexBits */
502 0, /* DepthBits */
503 2, /* TexelBytes */
504 fetch_texel_1d_ycbcr, /* FetchTexel1D */
505 fetch_texel_2d_ycbcr, /* FetchTexel2D */
506 fetch_texel_3d_ycbcr, /* FetchTexel3D */
507 fetch_texel_1d_f_ycbcr, /* FetchTexel1Df */
508 fetch_texel_2d_f_ycbcr, /* FetchTexel2Df */
509 fetch_texel_3d_f_ycbcr, /* FetchTexel3Df */
510 };
511
512 const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
513 MESA_FORMAT_YCBCR_REV, /* MesaFormat */
514 GL_YCBCR_MESA, /* BaseFormat */
515 0, /* RedBits */
516 0, /* GreenBits */
517 0, /* BlueBits */
518 0, /* AlphaBits */
519 0, /* LuminanceBits */
520 0, /* IntensityBits */
521 0, /* IndexBits */
522 0, /* DepthBits */
523 2, /* TexelBytes */
524 fetch_texel_1d_ycbcr_rev, /* FetchTexel1D */
525 fetch_texel_2d_ycbcr_rev, /* FetchTexel2D */
526 fetch_texel_3d_ycbcr_rev, /* FetchTexel3D */
527 fetch_texel_1d_f_ycbcr_rev, /* FetchTexel1Df */
528 fetch_texel_2d_f_ycbcr_rev, /* FetchTexel2Df */
529 fetch_texel_3d_f_ycbcr_rev, /* FetchTexel3Df */
530 };
531
532 const struct gl_texture_format _mesa_texformat_rgb_fxt1 = {
533 MESA_FORMAT_RGB_FXT1, /* MesaFormat */
534 GL_RGB, /* BaseFormat */
535 4, /*approx*/ /* RedBits */
536 4, /*approx*/ /* GreenBits */
537 4, /*approx*/ /* BlueBits */
538 0, /* AlphaBits */
539 0, /* LuminanceBits */
540 0, /* IntensityBits */
541 0, /* IndexBits */
542 0, /* DepthBits */
543 0, /* TexelBytes */
544 NULL, /*impossible*/ /* FetchTexel1D */
545 fetch_texel_2d_rgb_fxt1, /* FetchTexel2D */
546 NULL, /*impossible*/ /* FetchTexel3D */
547 NULL, /*impossible*/ /* FetchTexel1Df */
548 fetch_texel_2d_f_rgb_fxt1, /* FetchTexel2Df */
549 NULL, /*impossible*/ /* FetchTexel3Df */
550 };
551
552 const struct gl_texture_format _mesa_texformat_rgba_fxt1 = {
553 MESA_FORMAT_RGBA_FXT1, /* MesaFormat */
554 GL_RGBA, /* BaseFormat */
555 4, /*approx*/ /* RedBits */
556 4, /*approx*/ /* GreenBits */
557 4, /*approx*/ /* BlueBits */
558 1, /*approx*/ /* AlphaBits */
559 0, /* LuminanceBits */
560 0, /* IntensityBits */
561 0, /* IndexBits */
562 0, /* DepthBits */
563 0, /* TexelBytes */
564 NULL, /*impossible*/ /* FetchTexel1D */
565 fetch_texel_2d_rgba_fxt1, /* FetchTexel2D */
566 NULL, /*impossible*/ /* FetchTexel3D */
567 NULL, /*impossible*/ /* FetchTexel1Df */
568 fetch_texel_2d_f_rgba_fxt1, /* FetchTexel2Df */
569 NULL, /*impossible*/ /* FetchTexel3Df */
570 };
571
572 const struct gl_texture_format _mesa_texformat_rgb_dxt1 = {
573 MESA_FORMAT_RGB_DXT1, /* MesaFormat */
574 GL_RGB, /* BaseFormat */
575 4, /*approx*/ /* RedBits */
576 4, /*approx*/ /* GreenBits */
577 4, /*approx*/ /* BlueBits */
578 0, /* AlphaBits */
579 0, /* LuminanceBits */
580 0, /* IntensityBits */
581 0, /* IndexBits */
582 0, /* DepthBits */
583 0, /* TexelBytes */
584 NULL, /*impossible*/ /* FetchTexel1D */
585 fetch_texel_2d_rgb_dxt1, /* FetchTexel2D */
586 NULL, /*impossible*/ /* FetchTexel3D */
587 NULL, /*impossible*/ /* FetchTexel1Df */
588 fetch_texel_2d_f_rgb_dxt1, /* FetchTexel2Df */
589 NULL, /*impossible*/ /* FetchTexel3Df */
590 };
591
592 const struct gl_texture_format _mesa_texformat_rgba_dxt1 = {
593 MESA_FORMAT_RGBA_DXT1, /* MesaFormat */
594 GL_RGBA, /* BaseFormat */
595 4, /*approx*/ /* RedBits */
596 4, /*approx*/ /* GreenBits */
597 4, /*approx*/ /* BlueBits */
598 1, /*approx*/ /* AlphaBits */
599 0, /* LuminanceBits */
600 0, /* IntensityBits */
601 0, /* IndexBits */
602 0, /* DepthBits */
603 0, /* TexelBytes */
604 NULL, /*impossible*/ /* FetchTexel1D */
605 fetch_texel_2d_rgba_dxt1, /* FetchTexel2D */
606 NULL, /*impossible*/ /* FetchTexel3D */
607 NULL, /*impossible*/ /* FetchTexel1Df */
608 fetch_texel_2d_f_rgba_dxt1, /* FetchTexel2Df */
609 NULL, /*impossible*/ /* FetchTexel3Df */
610 };
611
612 const struct gl_texture_format _mesa_texformat_rgba_dxt3 = {
613 MESA_FORMAT_RGBA_DXT3, /* MesaFormat */
614 GL_RGBA, /* BaseFormat */
615 4, /*approx*/ /* RedBits */
616 4, /*approx*/ /* GreenBits */
617 4, /*approx*/ /* BlueBits */
618 4, /*approx*/ /* AlphaBits */
619 0, /* LuminanceBits */
620 0, /* IntensityBits */
621 0, /* IndexBits */
622 0, /* DepthBits */
623 0, /* TexelBytes */
624 NULL, /*impossible*/ /* FetchTexel1D */
625 fetch_texel_2d_rgba_dxt3, /* FetchTexel2D */
626 NULL, /*impossible*/ /* FetchTexel3D */
627 NULL, /*impossible*/ /* FetchTexel1Df */
628 fetch_texel_2d_f_rgba_dxt3, /* FetchTexel2Df */
629 NULL, /*impossible*/ /* FetchTexel3Df */
630 };
631
632 const struct gl_texture_format _mesa_texformat_rgba_dxt5 = {
633 MESA_FORMAT_RGBA_DXT5, /* MesaFormat */
634 GL_RGBA, /* BaseFormat */
635 4,/*approx*/ /* RedBits */
636 4,/*approx*/ /* GreenBits */
637 4,/*approx*/ /* BlueBits */
638 4,/*approx*/ /* AlphaBits */
639 0, /* LuminanceBits */
640 0, /* IntensityBits */
641 0, /* IndexBits */
642 0, /* DepthBits */
643 0, /* TexelBytes */
644 NULL, /*impossible*/ /* FetchTexel1D */
645 fetch_texel_2d_rgba_dxt5, /* FetchTexel2D */
646 NULL, /*impossible*/ /* FetchTexel3D */
647 NULL, /*impossible*/ /* FetchTexel1Df */
648 fetch_texel_2d_f_rgba_dxt5, /* FetchTexel2Df */
649 NULL, /*impossible*/ /* FetchTexel3Df */
650 };
651
652
653 /* Big-endian */
654 #if 0
655 const struct gl_texture_format _mesa_texformat_abgr8888 = {
656 MESA_FORMAT_ABGR8888, /* MesaFormat */
657 GL_RGBA, /* BaseFormat */
658 GL_UNSIGNED_INT_8_8_8_8, /* Type */
659 8, /* RedBits */
660 8, /* GreenBits */
661 8, /* BlueBits */
662 8, /* AlphaBits */
663 0, /* LuminanceBits */
664 0, /* IntensityBits */
665 0, /* IndexBits */
666 0, /* DepthBits */
667 4, /* TexelBytes */
668 fetch_texel_1d_abgr8888, /* FetchTexel1D */
669 fetch_texel_2d_abgr8888, /* FetchTexel2D */
670 fetch_texel_3d_abgr8888, /* FetchTexel3D */
671 /* XXX float fetchers */
672 };
673
674 const struct gl_texture_format _mesa_texformat_bgra8888 = {
675 MESA_FORMAT_BGRA8888, /* MesaFormat */
676 GL_RGBA, /* BaseFormat */
677 GL_UNSIGNED_INT_8_8_8_8, /* Type */
678 8, /* RedBits */
679 8, /* GreenBits */
680 8, /* BlueBits */
681 8, /* AlphaBits */
682 0, /* LuminanceBits */
683 0, /* IntensityBits */
684 0, /* IndexBits */
685 0, /* DepthBits */
686 4, /* TexelBytes */
687 fetch_texel_1d_bgra8888, /* FetchTexel1D */
688 fetch_texel_2d_bgra8888, /* FetchTexel2D */
689 fetch_texel_3d_bgra8888, /* FetchTexel3D */
690 /* XXX float fetchers */
691 };
692
693 const struct gl_texture_format _mesa_texformat_bgr888 = {
694 MESA_FORMAT_BGR888, /* MesaFormat */
695 GL_RGB, /* BaseFormat */
696 GL_UNSIGNED_BYTE, /* Type */
697 8, /* RedBits */
698 8, /* GreenBits */
699 8, /* BlueBits */
700 0, /* AlphaBits */
701 0, /* LuminanceBits */
702 0, /* IntensityBits */
703 0, /* IndexBits */
704 0, /* DepthBits */
705 3, /* TexelBytes */
706 fetch_texel_1d_bgr888, /* FetchTexel1D */
707 fetch_texel_2d_bgr888, /* FetchTexel2D */
708 fetch_texel_3d_bgr888, /* FetchTexel3D */
709 /* XXX float fetchers */
710 };
711
712 const struct gl_texture_format _mesa_texformat_bgr565 = {
713 MESA_FORMAT_BGR565, /* MesaFormat */
714 GL_RGB, /* BaseFormat */
715 GL_UNSIGNED_SHORT_5_6_5, /* Type */
716 5, /* RedBits */
717 6, /* GreenBits */
718 5, /* BlueBits */
719 0, /* AlphaBits */
720 0, /* LuminanceBits */
721 0, /* IntensityBits */
722 0, /* IndexBits */
723 0, /* DepthBits */
724 2, /* TexelBytes */
725 fetch_texel_1d_bgr565, /* FetchTexel1D */
726 fetch_texel_2d_bgr565, /* FetchTexel2D */
727 fetch_texel_3d_bgr565, /* FetchTexel3D */
728 /* XXX float fetchers */
729 };
730
731 const struct gl_texture_format _mesa_texformat_bgra4444 = {
732 MESA_FORMAT_BGRA4444, /* MesaFormat */
733 GL_RGBA, /* BaseFormat */
734 GL_UNSIGNED_SHORT_4_4_4_4_REV, /* Type */
735 4, /* RedBits */
736 4, /* GreenBits */
737 4, /* BlueBits */
738 4, /* AlphaBits */
739 0, /* LuminanceBits */
740 0, /* IntensityBits */
741 0, /* IndexBits */
742 0, /* DepthBits */
743 2, /* TexelBytes */
744 fetch_texel_1d_bgra4444, /* FetchTexel1D */
745 fetch_texel_2d_bgra4444, /* FetchTexel2D */
746 fetch_texel_3d_bgra4444, /* FetchTexel3D */
747 /* XXX float fetchers */
748 };
749
750 const struct gl_texture_format _mesa_texformat_bgra5551 = {
751 MESA_FORMAT_BGRA5551, /* MesaFormat */
752 GL_RGBA, /* BaseFormat */
753 GL_UNSIGNED_SHORT_1_5_5_5_REV, /* Type */
754 5, /* RedBits */
755 5, /* GreenBits */
756 5, /* BlueBits */
757 1, /* AlphaBits */
758 0, /* LuminanceBits */
759 0, /* IntensityBits */
760 0, /* IndexBits */
761 0, /* DepthBits */
762 2, /* TexelBytes */
763 fetch_texel_1d_bgra1555, /* FetchTexel1D */
764 fetch_texel_2d_bgra1555, /* FetchTexel2D */
765 fetch_texel_3d_bgra1555, /* FetchTexel3D */
766 /* XXX float fetchers */
767 };
768
769 const struct gl_texture_format _mesa_texformat_la88 = {
770 MESA_FORMAT_LA88, /* MesaFormat */
771 GL_LUMINANCE_ALPHA, /* BaseFormat */
772 GL_UNSIGNED_BYTE, /* Type */
773 0, /* RedBits */
774 0, /* GreenBits */
775 0, /* BlueBits */
776 8, /* AlphaBits */
777 8, /* LuminanceBits */
778 0, /* IntensityBits */
779 0, /* IndexBits */
780 0, /* DepthBits */
781 2, /* TexelBytes */
782 fetch_texel_1d_la88, /* FetchTexel1D */
783 fetch_texel_2d_la88, /* FetchTexel2D */
784 fetch_texel_3d_la88, /* FetchTexel3D */
785 /* XXX float fetchers */
786 };
787
788 const struct gl_texture_format _mesa_texformat_bgr233 = {
789 MESA_FORMAT_BGR233, /* MesaFormat */
790 GL_RGB, /* BaseFormat */
791 GL_UNSIGNED_BYTE_3_3_2, /* Type */
792 3, /* RedBits */
793 3, /* GreenBits */
794 2, /* BlueBits */
795 0, /* AlphaBits */
796 0, /* LuminanceBits */
797 0, /* IntensityBits */
798 0, /* IndexBits */
799 0, /* DepthBits */
800 1, /* TexelBytes */
801 fetch_texel_1d_bgr233, /* FetchTexel1D */
802 fetch_texel_2d_bgr233, /* FetchTexel2D */
803 fetch_texel_3d_bgr233, /* FetchTexel3D */
804 /* XXX float fetchers */
805 };
806 #endif
807
808 /*@}*/
809
810
811 /***************************************************************/
812 /** \name Null format (useful for proxy textures) */
813 /*@{*/
814
815 const struct gl_texture_format _mesa_null_texformat = {
816 -1, /* MesaFormat */
817 0, /* BaseFormat */
818 0, /* RedBits */
819 0, /* GreenBits */
820 0, /* BlueBits */
821 0, /* AlphaBits */
822 0, /* LuminanceBits */
823 0, /* IntensityBits */
824 0, /* IndexBits */
825 0, /* DepthBits */
826 0, /* TexelBytes */
827 fetch_null_texel, /* FetchTexel1D */
828 fetch_null_texel, /* FetchTexel2D */
829 fetch_null_texel, /* FetchTexel3D */
830 fetch_null_texelf, /* FetchTexel1Df */
831 fetch_null_texelf, /* FetchTexel2Df */
832 fetch_null_texelf, /* FetchTexel3Df */
833 };
834
835 /*@}*/
836
837
838 /**
839 * Determine whether a given texture format is a hardware texture
840 * format.
841 *
842 * \param format texture format.
843 *
844 * \return GL_TRUE if \p format is a hardware texture format, or GL_FALSE
845 * otherwise.
846 *
847 * \p format is a hardware texture format if gl_texture_format::MesaFormat is
848 * lower than _format::MESA_FORMAT_RGBA.
849 */
850 GLboolean
851 _mesa_is_hardware_tex_format( const struct gl_texture_format *format )
852 {
853 return (format->MesaFormat < MESA_FORMAT_RGBA);
854 }
855
856
857 /**
858 * Choose an appropriate texture format.
859 *
860 * \param ctx GL context.
861 * \param internalFormat internal texture format.
862 * \param format pixel format.
863 * \param type data type.
864 *
865 * \return a pointer to a gl_texture_format in which to store the texture on
866 * success, or NULL on failure.
867 *
868 * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
869 * typically override this function with a specialized version.
870 */
871 const struct gl_texture_format *
872 _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
873 GLenum format, GLenum type )
874 {
875 (void) format;
876 (void) type;
877
878 switch ( internalFormat ) {
879 /* GH: Bias towards GL_RGB, GL_RGBA texture formats. This has
880 * got to be better than sticking them way down the end of this
881 * huge list.
882 */
883 case 4: /* Quake3 uses this... */
884 case GL_RGBA:
885 return &_mesa_texformat_rgba;
886
887 case 3: /* ... and this. */
888 case GL_RGB:
889 return &_mesa_texformat_rgb;
890
891 /* GH: Okay, keep checking as normal. Still test for GL_RGB,
892 * GL_RGBA formats first.
893 */
894 case GL_RGBA2:
895 case GL_RGBA4:
896 case GL_RGB5_A1:
897 case GL_RGBA8:
898 case GL_RGB10_A2:
899 case GL_RGBA12:
900 case GL_RGBA16:
901 return &_mesa_texformat_rgba;
902
903 case GL_R3_G3_B2:
904 case GL_RGB4:
905 case GL_RGB5:
906 case GL_RGB8:
907 case GL_RGB10:
908 case GL_RGB12:
909 case GL_RGB16:
910 return &_mesa_texformat_rgb;
911
912 case GL_ALPHA:
913 case GL_ALPHA4:
914 case GL_ALPHA8:
915 case GL_ALPHA12:
916 case GL_ALPHA16:
917 return &_mesa_texformat_alpha;
918
919 case 1:
920 case GL_LUMINANCE:
921 case GL_LUMINANCE4:
922 case GL_LUMINANCE8:
923 case GL_LUMINANCE12:
924 case GL_LUMINANCE16:
925 return &_mesa_texformat_luminance;
926
927 case 2:
928 case GL_LUMINANCE_ALPHA:
929 case GL_LUMINANCE4_ALPHA4:
930 case GL_LUMINANCE6_ALPHA2:
931 case GL_LUMINANCE8_ALPHA8:
932 case GL_LUMINANCE12_ALPHA4:
933 case GL_LUMINANCE12_ALPHA12:
934 case GL_LUMINANCE16_ALPHA16:
935 return &_mesa_texformat_luminance_alpha;
936
937 case GL_INTENSITY:
938 case GL_INTENSITY4:
939 case GL_INTENSITY8:
940 case GL_INTENSITY12:
941 case GL_INTENSITY16:
942 return &_mesa_texformat_intensity;
943
944 case GL_COLOR_INDEX:
945 case GL_COLOR_INDEX1_EXT:
946 case GL_COLOR_INDEX2_EXT:
947 case GL_COLOR_INDEX4_EXT:
948 case GL_COLOR_INDEX8_EXT:
949 case GL_COLOR_INDEX12_EXT:
950 case GL_COLOR_INDEX16_EXT:
951 return &_mesa_texformat_color_index;
952
953 case GL_DEPTH_COMPONENT:
954 case GL_DEPTH_COMPONENT16_SGIX:
955 case GL_DEPTH_COMPONENT24_SGIX:
956 case GL_DEPTH_COMPONENT32_SGIX:
957 if (!ctx->Extensions.SGIX_depth_texture)
958 _mesa_problem(ctx, "depth format without GL_SGIX_depth_texture");
959 return &_mesa_texformat_depth_component;
960
961 case GL_COMPRESSED_ALPHA_ARB:
962 if (!ctx->Extensions.ARB_texture_compression)
963 _mesa_problem(ctx, "texture compression extension not enabled");
964 return &_mesa_texformat_alpha;
965 case GL_COMPRESSED_LUMINANCE_ARB:
966 if (!ctx->Extensions.ARB_texture_compression)
967 _mesa_problem(ctx, "texture compression extension not enabled");
968 return &_mesa_texformat_luminance;
969 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
970 if (!ctx->Extensions.ARB_texture_compression)
971 _mesa_problem(ctx, "texture compression extension not enabled");
972 return &_mesa_texformat_luminance_alpha;
973 case GL_COMPRESSED_INTENSITY_ARB:
974 if (!ctx->Extensions.ARB_texture_compression)
975 _mesa_problem(ctx, "texture compression extension not enabled");
976 return &_mesa_texformat_intensity;
977 case GL_COMPRESSED_RGB_ARB:
978 if (!ctx->Extensions.ARB_texture_compression)
979 _mesa_problem(ctx, "texture compression extension not enabled");
980 if (ctx->Extensions.TDFX_texture_compression_FXT1)
981 return &_mesa_texformat_rgb_fxt1;
982 else if (ctx->Extensions.EXT_texture_compression_s3tc || ctx->Extensions.S3_s3tc)
983 return &_mesa_texformat_rgb_dxt1;
984 return &_mesa_texformat_rgb;
985 case GL_COMPRESSED_RGBA_ARB:
986 if (!ctx->Extensions.ARB_texture_compression)
987 _mesa_problem(ctx, "texture compression extension not enabled");
988 if (ctx->Extensions.TDFX_texture_compression_FXT1)
989 return &_mesa_texformat_rgba_fxt1;
990 else if (ctx->Extensions.EXT_texture_compression_s3tc || ctx->Extensions.S3_s3tc)
991 return &_mesa_texformat_rgba_dxt3; /* Not rgba_dxt1! See the spec */
992 return &_mesa_texformat_rgba;
993
994 /* GL_MESA_ycrcr_texture */
995 case GL_YCBCR_MESA:
996 if (type == GL_UNSIGNED_SHORT_8_8_MESA)
997 return &_mesa_texformat_ycbcr;
998 else
999 return &_mesa_texformat_ycbcr_rev;
1000
1001 /* GL_3DFX_texture_compression_FXT1 */
1002 case GL_COMPRESSED_RGB_FXT1_3DFX:
1003 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1004 return &_mesa_texformat_rgb_fxt1;
1005 else
1006 return NULL;
1007 case GL_COMPRESSED_RGBA_FXT1_3DFX:
1008 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1009 return &_mesa_texformat_rgba_fxt1;
1010 else
1011 return NULL;
1012
1013 /* GL_EXT_texture_compression_s3tc */
1014 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1015 if (ctx->Extensions.EXT_texture_compression_s3tc)
1016 return &_mesa_texformat_rgb_dxt1;
1017 else
1018 return NULL;
1019 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1020 if (ctx->Extensions.EXT_texture_compression_s3tc)
1021 return &_mesa_texformat_rgba_dxt1;
1022 else
1023 return NULL;
1024 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1025 if (ctx->Extensions.EXT_texture_compression_s3tc)
1026 return &_mesa_texformat_rgba_dxt3;
1027 else
1028 return NULL;
1029 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1030 if (ctx->Extensions.EXT_texture_compression_s3tc)
1031 return &_mesa_texformat_rgba_dxt5;
1032 else
1033 return NULL;
1034
1035 /* GL_S3_s3tc */
1036 case GL_RGB_S3TC:
1037 case GL_RGB4_S3TC:
1038 if (ctx->Extensions.S3_s3tc)
1039 return &_mesa_texformat_rgb_dxt1;
1040 else
1041 return NULL;
1042 case GL_RGBA_S3TC:
1043 case GL_RGBA4_S3TC:
1044 if (ctx->Extensions.S3_s3tc)
1045 return &_mesa_texformat_rgba_dxt3;
1046 else
1047 return NULL;
1048
1049 default:
1050 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
1051 return NULL;
1052 }
1053 }
1054
1055
1056 /**
1057 * Return the base texture format for the given compressed format
1058 *
1059 * Called via dd_function_table::Driver.BaseCompressedTexFormat.
1060 * This function is used by software rasterizers. Hardware drivers
1061 * which support texture compression should not use this function but
1062 * a specialized function instead.
1063 */
1064 GLint
1065 _mesa_base_compressed_texformat(GLcontext *ctx, GLint intFormat)
1066 {
1067 switch (intFormat) {
1068 case GL_COMPRESSED_ALPHA_ARB:
1069 return GL_ALPHA;
1070 case GL_COMPRESSED_LUMINANCE_ARB:
1071 return GL_LUMINANCE;
1072 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
1073 return GL_LUMINANCE_ALPHA;
1074 case GL_COMPRESSED_INTENSITY_ARB:
1075 return GL_INTENSITY;
1076 case GL_COMPRESSED_RGB_ARB:
1077 return GL_RGB;
1078 case GL_COMPRESSED_RGBA_ARB:
1079 return GL_RGBA;
1080 default:
1081 return -1; /* not a recognized compressed format */
1082 }
1083 }