Overhaul of glRead/DrawBuffer() code. Now, swrast->Driver.SetBuffer()
[mesa.git] / src / mesa / main / texformat.c
1 /* $Id: texformat.c,v 1.14 2002/07/09 01:22:50 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 /* Big-endian */
441 #if 0
442 const struct gl_texture_format _mesa_texformat_abgr8888 = {
443 MESA_FORMAT_ABGR8888, /* MesaFormat */
444 GL_RGBA, /* BaseFormat */
445 GL_UNSIGNED_INT_8_8_8_8, /* Type */
446 8, /* RedBits */
447 8, /* GreenBits */
448 8, /* BlueBits */
449 8, /* AlphaBits */
450 0, /* LuminanceBits */
451 0, /* IntensityBits */
452 0, /* IndexBits */
453 0, /* DepthBits */
454 4, /* TexelBytes */
455 fetch_1d_texel_abgr8888, /* FetchTexel1D */
456 fetch_2d_texel_abgr8888, /* FetchTexel2D */
457 fetch_3d_texel_abgr8888, /* FetchTexel3D */
458 };
459
460 const struct gl_texture_format _mesa_texformat_bgra8888 = {
461 MESA_FORMAT_BGRA8888, /* MesaFormat */
462 GL_RGBA, /* BaseFormat */
463 GL_UNSIGNED_INT_8_8_8_8, /* Type */
464 8, /* RedBits */
465 8, /* GreenBits */
466 8, /* BlueBits */
467 8, /* AlphaBits */
468 0, /* LuminanceBits */
469 0, /* IntensityBits */
470 0, /* IndexBits */
471 0, /* DepthBits */
472 4, /* TexelBytes */
473 fetch_1d_texel_bgra8888, /* FetchTexel1D */
474 fetch_2d_texel_bgra8888, /* FetchTexel2D */
475 fetch_3d_texel_bgra8888, /* FetchTexel3D */
476 };
477
478 const struct gl_texture_format _mesa_texformat_bgr888 = {
479 MESA_FORMAT_BGR888, /* MesaFormat */
480 GL_RGB, /* BaseFormat */
481 GL_UNSIGNED_BYTE, /* Type */
482 8, /* RedBits */
483 8, /* GreenBits */
484 8, /* BlueBits */
485 0, /* AlphaBits */
486 0, /* LuminanceBits */
487 0, /* IntensityBits */
488 0, /* IndexBits */
489 0, /* DepthBits */
490 3, /* TexelBytes */
491 fetch_1d_texel_bgr888, /* FetchTexel1D */
492 fetch_2d_texel_bgr888, /* FetchTexel2D */
493 fetch_3d_texel_bgr888, /* FetchTexel3D */
494 };
495
496 const struct gl_texture_format _mesa_texformat_bgr565 = {
497 MESA_FORMAT_BGR565, /* MesaFormat */
498 GL_RGB, /* BaseFormat */
499 GL_UNSIGNED_SHORT_5_6_5, /* Type */
500 5, /* RedBits */
501 6, /* GreenBits */
502 5, /* BlueBits */
503 0, /* AlphaBits */
504 0, /* LuminanceBits */
505 0, /* IntensityBits */
506 0, /* IndexBits */
507 0, /* DepthBits */
508 2, /* TexelBytes */
509 fetch_1d_texel_bgr565, /* FetchTexel1D */
510 fetch_2d_texel_bgr565, /* FetchTexel2D */
511 fetch_3d_texel_bgr565, /* FetchTexel3D */
512 };
513
514 const struct gl_texture_format _mesa_texformat_bgra4444 = {
515 MESA_FORMAT_BGRA4444, /* MesaFormat */
516 GL_RGBA, /* BaseFormat */
517 GL_UNSIGNED_SHORT_4_4_4_4_REV, /* Type */
518 4, /* RedBits */
519 4, /* GreenBits */
520 4, /* BlueBits */
521 4, /* AlphaBits */
522 0, /* LuminanceBits */
523 0, /* IntensityBits */
524 0, /* IndexBits */
525 0, /* DepthBits */
526 2, /* TexelBytes */
527 fetch_1d_texel_bgra4444, /* FetchTexel1D */
528 fetch_2d_texel_bgra4444, /* FetchTexel2D */
529 fetch_3d_texel_bgra4444, /* FetchTexel3D */
530 };
531
532 const struct gl_texture_format _mesa_texformat_bgra5551 = {
533 MESA_FORMAT_BGRA5551, /* MesaFormat */
534 GL_RGBA, /* BaseFormat */
535 GL_UNSIGNED_SHORT_1_5_5_5_REV, /* Type */
536 5, /* RedBits */
537 5, /* GreenBits */
538 5, /* BlueBits */
539 1, /* AlphaBits */
540 0, /* LuminanceBits */
541 0, /* IntensityBits */
542 0, /* IndexBits */
543 0, /* DepthBits */
544 2, /* TexelBytes */
545 fetch_1d_texel_bgra1555, /* FetchTexel1D */
546 fetch_2d_texel_bgra1555, /* FetchTexel2D */
547 fetch_3d_texel_bgra1555, /* FetchTexel3D */
548 };
549
550 const struct gl_texture_format _mesa_texformat_la88 = {
551 MESA_FORMAT_LA88, /* MesaFormat */
552 GL_LUMINANCE_ALPHA, /* BaseFormat */
553 GL_UNSIGNED_BYTE, /* Type */
554 0, /* RedBits */
555 0, /* GreenBits */
556 0, /* BlueBits */
557 8, /* AlphaBits */
558 8, /* LuminanceBits */
559 0, /* IntensityBits */
560 0, /* IndexBits */
561 0, /* DepthBits */
562 2, /* TexelBytes */
563 fetch_1d_texel_la88, /* FetchTexel1D */
564 fetch_2d_texel_la88, /* FetchTexel2D */
565 fetch_3d_texel_la88, /* FetchTexel3D */
566 };
567
568 const struct gl_texture_format _mesa_texformat_bgr233 = {
569 MESA_FORMAT_BGR233, /* MesaFormat */
570 GL_RGB, /* BaseFormat */
571 GL_UNSIGNED_BYTE_3_3_2, /* Type */
572 3, /* RedBits */
573 3, /* GreenBits */
574 2, /* BlueBits */
575 0, /* AlphaBits */
576 0, /* LuminanceBits */
577 0, /* IntensityBits */
578 0, /* IndexBits */
579 0, /* DepthBits */
580 1, /* TexelBytes */
581 fetch_1d_texel_bgr233, /* FetchTexel1D */
582 fetch_2d_texel_bgr233, /* FetchTexel2D */
583 fetch_3d_texel_bgr233, /* FetchTexel3D */
584 };
585 #endif
586
587 /* =============================================================
588 * Null format:
589 */
590
591 const struct gl_texture_format _mesa_null_texformat = {
592 -1, /* MesaFormat */
593 0, /* BaseFormat */
594 0, /* Type */
595 0, /* RedBits */
596 0, /* GreenBits */
597 0, /* BlueBits */
598 0, /* AlphaBits */
599 0, /* LuminanceBits */
600 0, /* IntensityBits */
601 0, /* IndexBits */
602 0, /* DepthBits */
603 0, /* TexelBytes */
604 fetch_null_texel, /* FetchTexel1D */
605 fetch_null_texel, /* FetchTexel2D */
606 fetch_null_texel, /* FetchTexel3D */
607 };
608
609
610
611 GLboolean
612 _mesa_is_hardware_tex_format( const struct gl_texture_format *format )
613 {
614 return (format->MesaFormat < MESA_FORMAT_RGBA);
615 }
616
617
618 /* Given an internal texture format (or 1, 2, 3, 4) return a pointer
619 * to a gl_texture_format which which to store the texture.
620 * This is called via ctx->Driver.ChooseTextureFormat().
621 * Hardware drivers typically override this function with a specialized
622 * version.
623 */
624 const struct gl_texture_format *
625 _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
626 GLenum format, GLenum type )
627 {
628 (void) format;
629 (void) type;
630
631 switch ( internalFormat ) {
632 /* GH: Bias towards GL_RGB, GL_RGBA texture formats. This has
633 * got to be better than sticking them way down the end of this
634 * huge list.
635 */
636 case 4: /* Quake3 uses this... */
637 case GL_RGBA:
638 return &_mesa_texformat_rgba;
639
640 case 3: /* ... and this. */
641 case GL_RGB:
642 return &_mesa_texformat_rgb;
643
644 /* GH: Okay, keep checking as normal. Still test for GL_RGB,
645 * GL_RGBA formats first.
646 */
647 case GL_RGBA2:
648 case GL_RGBA4:
649 case GL_RGB5_A1:
650 case GL_RGBA8:
651 case GL_RGB10_A2:
652 case GL_RGBA12:
653 case GL_RGBA16:
654 return &_mesa_texformat_rgba;
655
656 case GL_R3_G3_B2:
657 case GL_RGB4:
658 case GL_RGB5:
659 case GL_RGB8:
660 case GL_RGB10:
661 case GL_RGB12:
662 case GL_RGB16:
663 return &_mesa_texformat_rgb;
664
665 case GL_ALPHA:
666 case GL_ALPHA4:
667 case GL_ALPHA8:
668 case GL_ALPHA12:
669 case GL_ALPHA16:
670 return &_mesa_texformat_alpha;
671
672 case 1:
673 case GL_LUMINANCE:
674 case GL_LUMINANCE4:
675 case GL_LUMINANCE8:
676 case GL_LUMINANCE12:
677 case GL_LUMINANCE16:
678 return &_mesa_texformat_luminance;
679
680 case 2:
681 case GL_LUMINANCE_ALPHA:
682 case GL_LUMINANCE4_ALPHA4:
683 case GL_LUMINANCE6_ALPHA2:
684 case GL_LUMINANCE8_ALPHA8:
685 case GL_LUMINANCE12_ALPHA4:
686 case GL_LUMINANCE12_ALPHA12:
687 case GL_LUMINANCE16_ALPHA16:
688 return &_mesa_texformat_luminance_alpha;
689
690 case GL_INTENSITY:
691 case GL_INTENSITY4:
692 case GL_INTENSITY8:
693 case GL_INTENSITY12:
694 case GL_INTENSITY16:
695 return &_mesa_texformat_intensity;
696
697 case GL_COLOR_INDEX:
698 case GL_COLOR_INDEX1_EXT:
699 case GL_COLOR_INDEX2_EXT:
700 case GL_COLOR_INDEX4_EXT:
701 case GL_COLOR_INDEX8_EXT:
702 case GL_COLOR_INDEX12_EXT:
703 case GL_COLOR_INDEX16_EXT:
704 return &_mesa_texformat_color_index;
705
706 case GL_DEPTH_COMPONENT:
707 case GL_DEPTH_COMPONENT16_SGIX:
708 case GL_DEPTH_COMPONENT24_SGIX:
709 case GL_DEPTH_COMPONENT32_SGIX:
710 if (!ctx->Extensions.SGIX_depth_texture)
711 _mesa_problem(ctx, "depth format without GL_SGIX_depth_texture");
712 return &_mesa_texformat_depth_component;
713
714 case GL_COMPRESSED_ALPHA_ARB:
715 if (!ctx->Extensions.ARB_texture_compression)
716 _mesa_problem(ctx, "texture compression extension not enabled");
717 return &_mesa_texformat_alpha;
718 case GL_COMPRESSED_LUMINANCE_ARB:
719 if (!ctx->Extensions.ARB_texture_compression)
720 _mesa_problem(ctx, "texture compression extension not enabled");
721 return &_mesa_texformat_luminance;
722 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
723 if (!ctx->Extensions.ARB_texture_compression)
724 _mesa_problem(ctx, "texture compression extension not enabled");
725 return &_mesa_texformat_luminance_alpha;
726 case GL_COMPRESSED_INTENSITY_ARB:
727 if (!ctx->Extensions.ARB_texture_compression)
728 _mesa_problem(ctx, "texture compression extension not enabled");
729 return &_mesa_texformat_intensity;
730 case GL_COMPRESSED_RGB_ARB:
731 if (!ctx->Extensions.ARB_texture_compression)
732 _mesa_problem(ctx, "texture compression extension not enabled");
733 return &_mesa_texformat_rgb;
734 case GL_COMPRESSED_RGBA_ARB:
735 if (!ctx->Extensions.ARB_texture_compression)
736 _mesa_problem(ctx, "texture compression extension not enabled");
737 return &_mesa_texformat_rgba;
738
739 default:
740 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
741 _mesa_debug(ctx, "intformat = %d %x\n", internalFormat, internalFormat);
742 return NULL;
743 }
744 }
745
746
747
748
749 /*
750 * Return the base texture format for the given compressed format
751 * Called via ctx->Driver.BaseCompressedTexFormat().
752 * This function is used by software rasterizers. Hardware drivers
753 * which support texture compression should not use this function but
754 * a specialized function instead.
755 */
756 GLint
757 _mesa_base_compressed_texformat(GLcontext *ctx, GLint intFormat)
758 {
759 switch (intFormat) {
760 case GL_COMPRESSED_ALPHA_ARB:
761 return GL_ALPHA;
762 case GL_COMPRESSED_LUMINANCE_ARB:
763 return GL_LUMINANCE;
764 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
765 return GL_LUMINANCE_ALPHA;
766 case GL_COMPRESSED_INTENSITY_ARB:
767 return GL_INTENSITY;
768 case GL_COMPRESSED_RGB_ARB:
769 return GL_RGB;
770 case GL_COMPRESSED_RGBA_ARB:
771 return GL_RGBA;
772 default:
773 return -1; /* not a recognized compressed format */
774 }
775 }
776
777
778 /*
779 * Called via ctx->Driver.CompressedTextureSize().
780 * This function is only used by software rasterizers.
781 * Hardware drivers will have to implement a specialized function.
782 */
783 GLint
784 _mesa_compressed_texture_size(GLcontext *ctx,
785 const struct gl_texture_image *texImage)
786 {
787 GLint b;
788 assert(texImage);
789 assert(texImage->TexFormat);
790
791 b = texImage->Width * texImage->Height * texImage->Depth *
792 texImage->TexFormat->TexelBytes;
793 assert(b > 0);
794 return b;
795 }