disable _glapi_set_warning_func() call as it's not present in older libGLs
[mesa.git] / src / mesa / main / texformat.c
1 /* $Id: texformat.c,v 1.16 2002/09/27 02:45:38 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 * Author:
27 * Gareth Hughes <gareth@valinux.com>
28 */
29
30 #ifdef PC_HEADER
31 #include "all.h"
32 #else
33 #include "glheader.h"
34 #include "colormac.h"
35 #include "context.h"
36 #include "image.h"
37 #include "mem.h"
38 #include "mmath.h"
39 #include "mtypes.h"
40 #include "texformat.h"
41 #include "teximage.h"
42 #include "texstate.h"
43 #endif
44
45
46 /* Texel fetch routines for all supported formats:
47 */
48 #define DIM 1
49 #include "texformat_tmp.h"
50
51 #define DIM 2
52 #include "texformat_tmp.h"
53
54 #define DIM 3
55 #include "texformat_tmp.h"
56
57 /* Have to have this so the FetchTexel function pointer is never NULL.
58 */
59 static void fetch_null_texel( const struct gl_texture_image *texImage,
60 GLint i, GLint j, GLint k, GLvoid *texel )
61 {
62 GLchan *rgba = (GLchan *) texel;
63 rgba[RCOMP] = 0;
64 rgba[GCOMP] = 0;
65 rgba[BCOMP] = 0;
66 rgba[ACOMP] = 0;
67 }
68
69
70 /* =============================================================
71 * Default GLchan-based formats:
72 */
73
74 const struct gl_texture_format _mesa_texformat_rgba = {
75 MESA_FORMAT_RGBA, /* MesaFormat */
76 GL_RGBA, /* BaseFormat */
77 CHAN_BITS, /* RedBits */
78 CHAN_BITS, /* GreenBits */
79 CHAN_BITS, /* BlueBits */
80 CHAN_BITS, /* AlphaBits */
81 0, /* LuminanceBits */
82 0, /* IntensityBits */
83 0, /* IndexBits */
84 0, /* DepthBits */
85 4 * CHAN_BITS / 8, /* TexelBytes */
86 fetch_1d_texel_rgba, /* FetchTexel1D */
87 fetch_2d_texel_rgba, /* FetchTexel2D */
88 fetch_3d_texel_rgba, /* FetchTexel3D */
89 };
90
91 const struct gl_texture_format _mesa_texformat_rgb = {
92 MESA_FORMAT_RGB, /* MesaFormat */
93 GL_RGB, /* BaseFormat */
94 CHAN_BITS, /* RedBits */
95 CHAN_BITS, /* GreenBits */
96 CHAN_BITS, /* BlueBits */
97 0, /* AlphaBits */
98 0, /* LuminanceBits */
99 0, /* IntensityBits */
100 0, /* IndexBits */
101 0, /* DepthBits */
102 3 * CHAN_BITS / 8, /* TexelBytes */
103 fetch_1d_texel_rgb, /* FetchTexel1D */
104 fetch_2d_texel_rgb, /* FetchTexel2D */
105 fetch_3d_texel_rgb, /* FetchTexel3D */
106 };
107
108 const struct gl_texture_format _mesa_texformat_alpha = {
109 MESA_FORMAT_ALPHA, /* MesaFormat */
110 GL_ALPHA, /* BaseFormat */
111 0, /* RedBits */
112 0, /* GreenBits */
113 0, /* BlueBits */
114 CHAN_BITS, /* AlphaBits */
115 0, /* LuminanceBits */
116 0, /* IntensityBits */
117 0, /* IndexBits */
118 0, /* DepthBits */
119 CHAN_BITS / 8, /* TexelBytes */
120 fetch_1d_texel_alpha, /* FetchTexel1D */
121 fetch_2d_texel_alpha, /* FetchTexel2D */
122 fetch_3d_texel_alpha, /* FetchTexel3D */
123 };
124
125 const struct gl_texture_format _mesa_texformat_luminance = {
126 MESA_FORMAT_LUMINANCE, /* MesaFormat */
127 GL_LUMINANCE, /* BaseFormat */
128 0, /* RedBits */
129 0, /* GreenBits */
130 0, /* BlueBits */
131 0, /* AlphaBits */
132 CHAN_BITS, /* LuminanceBits */
133 0, /* IntensityBits */
134 0, /* IndexBits */
135 0, /* DepthBits */
136 CHAN_BITS / 8, /* TexelBytes */
137 fetch_1d_texel_luminance, /* FetchTexel1D */
138 fetch_2d_texel_luminance, /* FetchTexel2D */
139 fetch_3d_texel_luminance, /* FetchTexel3D */
140 };
141
142 const struct gl_texture_format _mesa_texformat_luminance_alpha = {
143 MESA_FORMAT_LUMINANCE_ALPHA, /* MesaFormat */
144 GL_LUMINANCE_ALPHA, /* BaseFormat */
145 0, /* RedBits */
146 0, /* GreenBits */
147 0, /* BlueBits */
148 CHAN_BITS, /* AlphaBits */
149 CHAN_BITS, /* LuminanceBits */
150 0, /* IntensityBits */
151 0, /* IndexBits */
152 0, /* DepthBits */
153 2 * CHAN_BITS / 8, /* TexelBytes */
154 fetch_1d_texel_luminance_alpha, /* FetchTexel1D */
155 fetch_2d_texel_luminance_alpha, /* FetchTexel2D */
156 fetch_3d_texel_luminance_alpha, /* FetchTexel3D */
157 };
158
159 const struct gl_texture_format _mesa_texformat_intensity = {
160 MESA_FORMAT_INTENSITY, /* MesaFormat */
161 GL_INTENSITY, /* BaseFormat */
162 0, /* RedBits */
163 0, /* GreenBits */
164 0, /* BlueBits */
165 0, /* AlphaBits */
166 0, /* LuminanceBits */
167 CHAN_BITS, /* IntensityBits */
168 0, /* IndexBits */
169 0, /* DepthBits */
170 CHAN_BITS / 8, /* TexelBytes */
171 fetch_1d_texel_intensity, /* FetchTexel1D */
172 fetch_2d_texel_intensity, /* FetchTexel2D */
173 fetch_3d_texel_intensity, /* FetchTexel3D */
174 };
175
176 const struct gl_texture_format _mesa_texformat_color_index = {
177 MESA_FORMAT_COLOR_INDEX, /* MesaFormat */
178 GL_COLOR_INDEX, /* BaseFormat */
179 0, /* RedBits */
180 0, /* GreenBits */
181 0, /* BlueBits */
182 0, /* AlphaBits */
183 0, /* LuminanceBits */
184 0, /* IntensityBits */
185 CHAN_BITS, /* IndexBits */
186 0, /* DepthBits */
187 CHAN_BITS / 8, /* TexelBytes */
188 fetch_1d_texel_color_index, /* FetchTexel1D */
189 fetch_2d_texel_color_index, /* FetchTexel2D */
190 fetch_3d_texel_color_index, /* FetchTexel3D */
191 };
192
193 const struct gl_texture_format _mesa_texformat_depth_component = {
194 MESA_FORMAT_DEPTH_COMPONENT, /* MesaFormat */
195 GL_DEPTH_COMPONENT, /* BaseFormat */
196 0, /* RedBits */
197 0, /* GreenBits */
198 0, /* BlueBits */
199 0, /* AlphaBits */
200 0, /* LuminanceBits */
201 0, /* IntensityBits */
202 0, /* IndexBits */
203 sizeof(GLfloat) * 8, /* DepthBits */
204 sizeof(GLfloat), /* TexelBytes */
205 fetch_1d_texel_depth_component, /* FetchTexel1D */
206 fetch_2d_texel_depth_component, /* FetchTexel2D */
207 fetch_3d_texel_depth_component, /* FetchTexel3D */
208 };
209
210
211 /* =============================================================
212 * Hardware formats:
213 */
214
215 const struct gl_texture_format _mesa_texformat_rgba8888 = {
216 MESA_FORMAT_RGBA8888, /* MesaFormat */
217 GL_RGBA, /* BaseFormat */
218 8, /* RedBits */
219 8, /* GreenBits */
220 8, /* BlueBits */
221 8, /* AlphaBits */
222 0, /* LuminanceBits */
223 0, /* IntensityBits */
224 0, /* IndexBits */
225 0, /* DepthBits */
226 4, /* TexelBytes */
227 fetch_1d_texel_rgba8888, /* FetchTexel1D */
228 fetch_2d_texel_rgba8888, /* FetchTexel2D */
229 fetch_3d_texel_rgba8888, /* FetchTexel3D */
230 };
231
232 const struct gl_texture_format _mesa_texformat_argb8888 = {
233 MESA_FORMAT_ARGB8888, /* MesaFormat */
234 GL_RGBA, /* BaseFormat */
235 8, /* RedBits */
236 8, /* GreenBits */
237 8, /* BlueBits */
238 8, /* AlphaBits */
239 0, /* LuminanceBits */
240 0, /* IntensityBits */
241 0, /* IndexBits */
242 0, /* DepthBits */
243 4, /* TexelBytes */
244 fetch_1d_texel_argb8888, /* FetchTexel1D */
245 fetch_2d_texel_argb8888, /* FetchTexel2D */
246 fetch_3d_texel_argb8888, /* FetchTexel3D */
247 };
248
249 const struct gl_texture_format _mesa_texformat_rgb888 = {
250 MESA_FORMAT_RGB888, /* MesaFormat */
251 GL_RGB, /* BaseFormat */
252 8, /* RedBits */
253 8, /* GreenBits */
254 8, /* BlueBits */
255 0, /* AlphaBits */
256 0, /* LuminanceBits */
257 0, /* IntensityBits */
258 0, /* IndexBits */
259 0, /* DepthBits */
260 3, /* TexelBytes */
261 fetch_1d_texel_rgb888, /* FetchTexel1D */
262 fetch_2d_texel_rgb888, /* FetchTexel2D */
263 fetch_3d_texel_rgb888, /* FetchTexel3D */
264 };
265
266 const struct gl_texture_format _mesa_texformat_rgb565 = {
267 MESA_FORMAT_RGB565, /* MesaFormat */
268 GL_RGB, /* BaseFormat */
269 5, /* RedBits */
270 6, /* GreenBits */
271 5, /* BlueBits */
272 0, /* AlphaBits */
273 0, /* LuminanceBits */
274 0, /* IntensityBits */
275 0, /* IndexBits */
276 0, /* DepthBits */
277 2, /* TexelBytes */
278 fetch_1d_texel_rgb565, /* FetchTexel1D */
279 fetch_2d_texel_rgb565, /* FetchTexel2D */
280 fetch_3d_texel_rgb565, /* FetchTexel3D */
281 };
282
283 const struct gl_texture_format _mesa_texformat_argb4444 = {
284 MESA_FORMAT_ARGB4444, /* MesaFormat */
285 GL_RGBA, /* BaseFormat */
286 4, /* RedBits */
287 4, /* GreenBits */
288 4, /* BlueBits */
289 4, /* AlphaBits */
290 0, /* LuminanceBits */
291 0, /* IntensityBits */
292 0, /* IndexBits */
293 0, /* DepthBits */
294 2, /* TexelBytes */
295 fetch_1d_texel_argb4444, /* FetchTexel1D */
296 fetch_2d_texel_argb4444, /* FetchTexel2D */
297 fetch_3d_texel_argb4444, /* FetchTexel3D */
298 };
299
300 const struct gl_texture_format _mesa_texformat_argb1555 = {
301 MESA_FORMAT_ARGB1555, /* MesaFormat */
302 GL_RGBA, /* BaseFormat */
303 5, /* RedBits */
304 5, /* GreenBits */
305 5, /* BlueBits */
306 1, /* AlphaBits */
307 0, /* LuminanceBits */
308 0, /* IntensityBits */
309 0, /* IndexBits */
310 0, /* DepthBits */
311 2, /* TexelBytes */
312 fetch_1d_texel_argb1555, /* FetchTexel1D */
313 fetch_2d_texel_argb1555, /* FetchTexel2D */
314 fetch_3d_texel_argb1555, /* FetchTexel3D */
315 };
316
317 const struct gl_texture_format _mesa_texformat_al88 = {
318 MESA_FORMAT_AL88, /* MesaFormat */
319 GL_LUMINANCE_ALPHA, /* BaseFormat */
320 0, /* RedBits */
321 0, /* GreenBits */
322 0, /* BlueBits */
323 8, /* AlphaBits */
324 8, /* LuminanceBits */
325 0, /* IntensityBits */
326 0, /* IndexBits */
327 0, /* DepthBits */
328 2, /* TexelBytes */
329 fetch_1d_texel_al88, /* FetchTexel1D */
330 fetch_2d_texel_al88, /* FetchTexel2D */
331 fetch_3d_texel_al88, /* FetchTexel3D */
332 };
333
334 const struct gl_texture_format _mesa_texformat_rgb332 = {
335 MESA_FORMAT_RGB332, /* MesaFormat */
336 GL_RGB, /* BaseFormat */
337 3, /* RedBits */
338 3, /* GreenBits */
339 2, /* BlueBits */
340 0, /* AlphaBits */
341 0, /* LuminanceBits */
342 0, /* IntensityBits */
343 0, /* IndexBits */
344 0, /* DepthBits */
345 1, /* TexelBytes */
346 fetch_1d_texel_rgb332, /* FetchTexel1D */
347 fetch_2d_texel_rgb332, /* FetchTexel2D */
348 fetch_3d_texel_rgb332, /* FetchTexel3D */
349 };
350
351 const struct gl_texture_format _mesa_texformat_a8 = {
352 MESA_FORMAT_A8, /* MesaFormat */
353 GL_ALPHA, /* BaseFormat */
354 0, /* RedBits */
355 0, /* GreenBits */
356 0, /* BlueBits */
357 8, /* AlphaBits */
358 0, /* LuminanceBits */
359 0, /* IntensityBits */
360 0, /* IndexBits */
361 0, /* DepthBits */
362 1, /* TexelBytes */
363 fetch_1d_texel_a8, /* FetchTexel1D */
364 fetch_2d_texel_a8, /* FetchTexel2D */
365 fetch_3d_texel_a8, /* FetchTexel3D */
366 };
367
368 const struct gl_texture_format _mesa_texformat_l8 = {
369 MESA_FORMAT_L8, /* MesaFormat */
370 GL_LUMINANCE, /* BaseFormat */
371 0, /* RedBits */
372 0, /* GreenBits */
373 0, /* BlueBits */
374 0, /* AlphaBits */
375 8, /* LuminanceBits */
376 0, /* IntensityBits */
377 0, /* IndexBits */
378 0, /* DepthBits */
379 1, /* TexelBytes */
380 fetch_1d_texel_l8, /* FetchTexel1D */
381 fetch_2d_texel_l8, /* FetchTexel2D */
382 fetch_3d_texel_l8, /* FetchTexel3D */
383 };
384
385 const struct gl_texture_format _mesa_texformat_i8 = {
386 MESA_FORMAT_I8, /* MesaFormat */
387 GL_INTENSITY, /* BaseFormat */
388 0, /* RedBits */
389 0, /* GreenBits */
390 0, /* BlueBits */
391 0, /* AlphaBits */
392 0, /* LuminanceBits */
393 8, /* IntensityBits */
394 0, /* IndexBits */
395 0, /* DepthBits */
396 1, /* TexelBytes */
397 fetch_1d_texel_i8, /* FetchTexel1D */
398 fetch_2d_texel_i8, /* FetchTexel2D */
399 fetch_3d_texel_i8, /* FetchTexel3D */
400 };
401
402 const struct gl_texture_format _mesa_texformat_ci8 = {
403 MESA_FORMAT_CI8, /* MesaFormat */
404 GL_COLOR_INDEX, /* BaseFormat */
405 0, /* RedBits */
406 0, /* GreenBits */
407 0, /* BlueBits */
408 0, /* AlphaBits */
409 0, /* LuminanceBits */
410 0, /* IntensityBits */
411 8, /* IndexBits */
412 0, /* DepthBits */
413 1, /* TexelBytes */
414 fetch_1d_texel_ci8, /* FetchTexel1D */
415 fetch_2d_texel_ci8, /* FetchTexel2D */
416 fetch_3d_texel_ci8, /* FetchTexel3D */
417 };
418
419 const struct gl_texture_format _mesa_texformat_ycbcr = {
420 MESA_FORMAT_YCBCR, /* MesaFormat */
421 GL_YCBCR_MESA, /* BaseFormat */
422 0, /* RedBits */
423 0, /* GreenBits */
424 0, /* BlueBits */
425 0, /* AlphaBits */
426 0, /* LuminanceBits */
427 0, /* IntensityBits */
428 0, /* IndexBits */
429 0, /* DepthBits */
430 2, /* TexelBytes */
431 fetch_1d_texel_ycbcr, /* FetchTexel1D */
432 fetch_2d_texel_ycbcr, /* FetchTexel2D */
433 fetch_3d_texel_ycbcr, /* FetchTexel3D */
434 };
435
436
437 const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
438 MESA_FORMAT_YCBCR_REV, /* MesaFormat */
439 GL_YCBCR_MESA, /* BaseFormat */
440 0, /* RedBits */
441 0, /* GreenBits */
442 0, /* BlueBits */
443 0, /* AlphaBits */
444 0, /* LuminanceBits */
445 0, /* IntensityBits */
446 0, /* IndexBits */
447 0, /* DepthBits */
448 2, /* TexelBytes */
449 fetch_1d_texel_ycbcr_rev, /* FetchTexel1D */
450 fetch_2d_texel_ycbcr_rev, /* FetchTexel2D */
451 fetch_3d_texel_ycbcr_rev, /* FetchTexel3D */
452 };
453
454
455 /* Big-endian */
456 #if 0
457 const struct gl_texture_format _mesa_texformat_abgr8888 = {
458 MESA_FORMAT_ABGR8888, /* MesaFormat */
459 GL_RGBA, /* BaseFormat */
460 GL_UNSIGNED_INT_8_8_8_8, /* Type */
461 8, /* RedBits */
462 8, /* GreenBits */
463 8, /* BlueBits */
464 8, /* AlphaBits */
465 0, /* LuminanceBits */
466 0, /* IntensityBits */
467 0, /* IndexBits */
468 0, /* DepthBits */
469 4, /* TexelBytes */
470 fetch_1d_texel_abgr8888, /* FetchTexel1D */
471 fetch_2d_texel_abgr8888, /* FetchTexel2D */
472 fetch_3d_texel_abgr8888, /* FetchTexel3D */
473 };
474
475 const struct gl_texture_format _mesa_texformat_bgra8888 = {
476 MESA_FORMAT_BGRA8888, /* MesaFormat */
477 GL_RGBA, /* BaseFormat */
478 GL_UNSIGNED_INT_8_8_8_8, /* Type */
479 8, /* RedBits */
480 8, /* GreenBits */
481 8, /* BlueBits */
482 8, /* AlphaBits */
483 0, /* LuminanceBits */
484 0, /* IntensityBits */
485 0, /* IndexBits */
486 0, /* DepthBits */
487 4, /* TexelBytes */
488 fetch_1d_texel_bgra8888, /* FetchTexel1D */
489 fetch_2d_texel_bgra8888, /* FetchTexel2D */
490 fetch_3d_texel_bgra8888, /* FetchTexel3D */
491 };
492
493 const struct gl_texture_format _mesa_texformat_bgr888 = {
494 MESA_FORMAT_BGR888, /* MesaFormat */
495 GL_RGB, /* BaseFormat */
496 GL_UNSIGNED_BYTE, /* Type */
497 8, /* RedBits */
498 8, /* GreenBits */
499 8, /* BlueBits */
500 0, /* AlphaBits */
501 0, /* LuminanceBits */
502 0, /* IntensityBits */
503 0, /* IndexBits */
504 0, /* DepthBits */
505 3, /* TexelBytes */
506 fetch_1d_texel_bgr888, /* FetchTexel1D */
507 fetch_2d_texel_bgr888, /* FetchTexel2D */
508 fetch_3d_texel_bgr888, /* FetchTexel3D */
509 };
510
511 const struct gl_texture_format _mesa_texformat_bgr565 = {
512 MESA_FORMAT_BGR565, /* MesaFormat */
513 GL_RGB, /* BaseFormat */
514 GL_UNSIGNED_SHORT_5_6_5, /* Type */
515 5, /* RedBits */
516 6, /* GreenBits */
517 5, /* BlueBits */
518 0, /* AlphaBits */
519 0, /* LuminanceBits */
520 0, /* IntensityBits */
521 0, /* IndexBits */
522 0, /* DepthBits */
523 2, /* TexelBytes */
524 fetch_1d_texel_bgr565, /* FetchTexel1D */
525 fetch_2d_texel_bgr565, /* FetchTexel2D */
526 fetch_3d_texel_bgr565, /* FetchTexel3D */
527 };
528
529 const struct gl_texture_format _mesa_texformat_bgra4444 = {
530 MESA_FORMAT_BGRA4444, /* MesaFormat */
531 GL_RGBA, /* BaseFormat */
532 GL_UNSIGNED_SHORT_4_4_4_4_REV, /* Type */
533 4, /* RedBits */
534 4, /* GreenBits */
535 4, /* BlueBits */
536 4, /* AlphaBits */
537 0, /* LuminanceBits */
538 0, /* IntensityBits */
539 0, /* IndexBits */
540 0, /* DepthBits */
541 2, /* TexelBytes */
542 fetch_1d_texel_bgra4444, /* FetchTexel1D */
543 fetch_2d_texel_bgra4444, /* FetchTexel2D */
544 fetch_3d_texel_bgra4444, /* FetchTexel3D */
545 };
546
547 const struct gl_texture_format _mesa_texformat_bgra5551 = {
548 MESA_FORMAT_BGRA5551, /* MesaFormat */
549 GL_RGBA, /* BaseFormat */
550 GL_UNSIGNED_SHORT_1_5_5_5_REV, /* Type */
551 5, /* RedBits */
552 5, /* GreenBits */
553 5, /* BlueBits */
554 1, /* AlphaBits */
555 0, /* LuminanceBits */
556 0, /* IntensityBits */
557 0, /* IndexBits */
558 0, /* DepthBits */
559 2, /* TexelBytes */
560 fetch_1d_texel_bgra1555, /* FetchTexel1D */
561 fetch_2d_texel_bgra1555, /* FetchTexel2D */
562 fetch_3d_texel_bgra1555, /* FetchTexel3D */
563 };
564
565 const struct gl_texture_format _mesa_texformat_la88 = {
566 MESA_FORMAT_LA88, /* MesaFormat */
567 GL_LUMINANCE_ALPHA, /* BaseFormat */
568 GL_UNSIGNED_BYTE, /* Type */
569 0, /* RedBits */
570 0, /* GreenBits */
571 0, /* BlueBits */
572 8, /* AlphaBits */
573 8, /* LuminanceBits */
574 0, /* IntensityBits */
575 0, /* IndexBits */
576 0, /* DepthBits */
577 2, /* TexelBytes */
578 fetch_1d_texel_la88, /* FetchTexel1D */
579 fetch_2d_texel_la88, /* FetchTexel2D */
580 fetch_3d_texel_la88, /* FetchTexel3D */
581 };
582
583 const struct gl_texture_format _mesa_texformat_bgr233 = {
584 MESA_FORMAT_BGR233, /* MesaFormat */
585 GL_RGB, /* BaseFormat */
586 GL_UNSIGNED_BYTE_3_3_2, /* Type */
587 3, /* RedBits */
588 3, /* GreenBits */
589 2, /* BlueBits */
590 0, /* AlphaBits */
591 0, /* LuminanceBits */
592 0, /* IntensityBits */
593 0, /* IndexBits */
594 0, /* DepthBits */
595 1, /* TexelBytes */
596 fetch_1d_texel_bgr233, /* FetchTexel1D */
597 fetch_2d_texel_bgr233, /* FetchTexel2D */
598 fetch_3d_texel_bgr233, /* FetchTexel3D */
599 };
600 #endif
601
602 /* =============================================================
603 * Null format (useful for proxy textures):
604 */
605
606 const struct gl_texture_format _mesa_null_texformat = {
607 -1, /* MesaFormat */
608 0, /* BaseFormat */
609 0, /* RedBits */
610 0, /* GreenBits */
611 0, /* BlueBits */
612 0, /* AlphaBits */
613 0, /* LuminanceBits */
614 0, /* IntensityBits */
615 0, /* IndexBits */
616 0, /* DepthBits */
617 0, /* TexelBytes */
618 fetch_null_texel, /* FetchTexel1D */
619 fetch_null_texel, /* FetchTexel2D */
620 fetch_null_texel, /* FetchTexel3D */
621 };
622
623
624 GLboolean
625 _mesa_is_hardware_tex_format( const struct gl_texture_format *format )
626 {
627 return (format->MesaFormat < MESA_FORMAT_RGBA);
628 }
629
630
631 /* Given an internal texture format (or 1, 2, 3, 4) return a pointer
632 * to a gl_texture_format which which to store the texture.
633 * This is called via ctx->Driver.ChooseTextureFormat().
634 * Hardware drivers typically override this function with a specialized
635 * version.
636 */
637 const struct gl_texture_format *
638 _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
639 GLenum format, GLenum type )
640 {
641 (void) format;
642 (void) type;
643
644 switch ( internalFormat ) {
645 /* GH: Bias towards GL_RGB, GL_RGBA texture formats. This has
646 * got to be better than sticking them way down the end of this
647 * huge list.
648 */
649 case 4: /* Quake3 uses this... */
650 case GL_RGBA:
651 return &_mesa_texformat_rgba;
652
653 case 3: /* ... and this. */
654 case GL_RGB:
655 return &_mesa_texformat_rgb;
656
657 /* GH: Okay, keep checking as normal. Still test for GL_RGB,
658 * GL_RGBA formats first.
659 */
660 case GL_RGBA2:
661 case GL_RGBA4:
662 case GL_RGB5_A1:
663 case GL_RGBA8:
664 case GL_RGB10_A2:
665 case GL_RGBA12:
666 case GL_RGBA16:
667 return &_mesa_texformat_rgba;
668
669 case GL_R3_G3_B2:
670 case GL_RGB4:
671 case GL_RGB5:
672 case GL_RGB8:
673 case GL_RGB10:
674 case GL_RGB12:
675 case GL_RGB16:
676 return &_mesa_texformat_rgb;
677
678 case GL_ALPHA:
679 case GL_ALPHA4:
680 case GL_ALPHA8:
681 case GL_ALPHA12:
682 case GL_ALPHA16:
683 return &_mesa_texformat_alpha;
684
685 case 1:
686 case GL_LUMINANCE:
687 case GL_LUMINANCE4:
688 case GL_LUMINANCE8:
689 case GL_LUMINANCE12:
690 case GL_LUMINANCE16:
691 return &_mesa_texformat_luminance;
692
693 case 2:
694 case GL_LUMINANCE_ALPHA:
695 case GL_LUMINANCE4_ALPHA4:
696 case GL_LUMINANCE6_ALPHA2:
697 case GL_LUMINANCE8_ALPHA8:
698 case GL_LUMINANCE12_ALPHA4:
699 case GL_LUMINANCE12_ALPHA12:
700 case GL_LUMINANCE16_ALPHA16:
701 return &_mesa_texformat_luminance_alpha;
702
703 case GL_INTENSITY:
704 case GL_INTENSITY4:
705 case GL_INTENSITY8:
706 case GL_INTENSITY12:
707 case GL_INTENSITY16:
708 return &_mesa_texformat_intensity;
709
710 case GL_COLOR_INDEX:
711 case GL_COLOR_INDEX1_EXT:
712 case GL_COLOR_INDEX2_EXT:
713 case GL_COLOR_INDEX4_EXT:
714 case GL_COLOR_INDEX8_EXT:
715 case GL_COLOR_INDEX12_EXT:
716 case GL_COLOR_INDEX16_EXT:
717 return &_mesa_texformat_color_index;
718
719 case GL_DEPTH_COMPONENT:
720 case GL_DEPTH_COMPONENT16_SGIX:
721 case GL_DEPTH_COMPONENT24_SGIX:
722 case GL_DEPTH_COMPONENT32_SGIX:
723 if (!ctx->Extensions.SGIX_depth_texture)
724 _mesa_problem(ctx, "depth format without GL_SGIX_depth_texture");
725 return &_mesa_texformat_depth_component;
726
727 case GL_COMPRESSED_ALPHA_ARB:
728 if (!ctx->Extensions.ARB_texture_compression)
729 _mesa_problem(ctx, "texture compression extension not enabled");
730 return &_mesa_texformat_alpha;
731 case GL_COMPRESSED_LUMINANCE_ARB:
732 if (!ctx->Extensions.ARB_texture_compression)
733 _mesa_problem(ctx, "texture compression extension not enabled");
734 return &_mesa_texformat_luminance;
735 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
736 if (!ctx->Extensions.ARB_texture_compression)
737 _mesa_problem(ctx, "texture compression extension not enabled");
738 return &_mesa_texformat_luminance_alpha;
739 case GL_COMPRESSED_INTENSITY_ARB:
740 if (!ctx->Extensions.ARB_texture_compression)
741 _mesa_problem(ctx, "texture compression extension not enabled");
742 return &_mesa_texformat_intensity;
743 case GL_COMPRESSED_RGB_ARB:
744 if (!ctx->Extensions.ARB_texture_compression)
745 _mesa_problem(ctx, "texture compression extension not enabled");
746 return &_mesa_texformat_rgb;
747 case GL_COMPRESSED_RGBA_ARB:
748 if (!ctx->Extensions.ARB_texture_compression)
749 _mesa_problem(ctx, "texture compression extension not enabled");
750 return &_mesa_texformat_rgba;
751
752 /* GL_MESA_ycrcr_texture */
753 case GL_YCBCR_MESA:
754 if (type == GL_UNSIGNED_SHORT_8_8_MESA)
755 return &_mesa_texformat_ycbcr;
756 else
757 return &_mesa_texformat_ycbcr_rev;
758
759 default:
760 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
761 return NULL;
762 }
763 }
764
765
766
767
768 /*
769 * Return the base texture format for the given compressed format
770 * Called via ctx->Driver.BaseCompressedTexFormat().
771 * This function is used by software rasterizers. Hardware drivers
772 * which support texture compression should not use this function but
773 * a specialized function instead.
774 */
775 GLint
776 _mesa_base_compressed_texformat(GLcontext *ctx, GLint intFormat)
777 {
778 switch (intFormat) {
779 case GL_COMPRESSED_ALPHA_ARB:
780 return GL_ALPHA;
781 case GL_COMPRESSED_LUMINANCE_ARB:
782 return GL_LUMINANCE;
783 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
784 return GL_LUMINANCE_ALPHA;
785 case GL_COMPRESSED_INTENSITY_ARB:
786 return GL_INTENSITY;
787 case GL_COMPRESSED_RGB_ARB:
788 return GL_RGB;
789 case GL_COMPRESSED_RGBA_ARB:
790 return GL_RGBA;
791 default:
792 return -1; /* not a recognized compressed format */
793 }
794 }