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