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