3
* Mesa 3-D graphics library
6
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8
* Permission is hereby granted, free of charge, to any person obtaining a
9
* copy of this software and associated documentation files (the "Software"),
10
* to deal in the Software without restriction, including without limitation
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
* and/or sell copies of the Software, and to permit persons to whom the
13
* Software is furnished to do so, subject to the following conditions:
15
* The above copyright notice and this permission notice shall be included
16
* in all copies or substantial portions of the Software.
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
* Gareth Hughes <gareth@valinux.com>
40
#include "texformat.h"
43
#include "swrast/s_span.h"
47
/* Texel fetch routines for all supported formats:
50
#include "texformat_tmp.h"
53
#include "texformat_tmp.h"
56
#include "texformat_tmp.h"
58
/* Have to have this so the FetchTexel function pointer is never NULL.
60
static void fetch_null_texel( const struct gl_texture_image *texImage,
61
GLint i, GLint j, GLint k, GLvoid *texel )
63
GLchan *rgba = (GLchan *) texel;
71
/* =============================================================
72
* Default GLchan-based formats:
75
const struct gl_texture_format _mesa_texformat_rgba = {
76
MESA_FORMAT_RGBA, /* MesaFormat */
77
GL_RGBA, /* BaseFormat */
79
CHAN_BITS, /* RedBits */
80
CHAN_BITS, /* GreenBits */
81
CHAN_BITS, /* BlueBits */
82
CHAN_BITS, /* AlphaBits */
83
0, /* LuminanceBits */
84
0, /* IntensityBits */
87
4 * CHAN_BITS / 8, /* TexelBytes */
88
fetch_1d_texel_rgba, /* FetchTexel1D */
89
fetch_2d_texel_rgba, /* FetchTexel2D */
90
fetch_3d_texel_rgba, /* FetchTexel3D */
93
const struct gl_texture_format _mesa_texformat_rgb = {
94
MESA_FORMAT_RGB, /* MesaFormat */
95
GL_RGB, /* BaseFormat */
97
CHAN_BITS, /* RedBits */
98
CHAN_BITS, /* GreenBits */
99
CHAN_BITS, /* BlueBits */
101
0, /* LuminanceBits */
102
0, /* IntensityBits */
105
3 * CHAN_BITS / 8, /* TexelBytes */
106
fetch_1d_texel_rgb, /* FetchTexel1D */
107
fetch_2d_texel_rgb, /* FetchTexel2D */
108
fetch_3d_texel_rgb, /* FetchTexel3D */
111
const struct gl_texture_format _mesa_texformat_alpha = {
112
MESA_FORMAT_ALPHA, /* MesaFormat */
113
GL_ALPHA, /* BaseFormat */
114
CHAN_TYPE, /* Type */
118
CHAN_BITS, /* AlphaBits */
119
0, /* LuminanceBits */
120
0, /* IntensityBits */
123
CHAN_BITS / 8, /* TexelBytes */
124
fetch_1d_texel_alpha, /* FetchTexel1D */
125
fetch_2d_texel_alpha, /* FetchTexel2D */
126
fetch_3d_texel_alpha, /* FetchTexel3D */
129
const struct gl_texture_format _mesa_texformat_luminance = {
130
MESA_FORMAT_LUMINANCE, /* MesaFormat */
131
GL_LUMINANCE, /* BaseFormat */
132
CHAN_TYPE, /* Type */
137
CHAN_BITS, /* LuminanceBits */
138
0, /* IntensityBits */
141
CHAN_BITS / 8, /* TexelBytes */
142
fetch_1d_texel_luminance, /* FetchTexel1D */
143
fetch_2d_texel_luminance, /* FetchTexel2D */
144
fetch_3d_texel_luminance, /* FetchTexel3D */
147
const struct gl_texture_format _mesa_texformat_luminance_alpha = {
148
MESA_FORMAT_LUMINANCE_ALPHA, /* MesaFormat */
149
GL_LUMINANCE_ALPHA, /* BaseFormat */
150
CHAN_TYPE, /* Type */
154
CHAN_BITS, /* AlphaBits */
155
CHAN_BITS, /* LuminanceBits */
156
0, /* IntensityBits */
159
2 * CHAN_BITS / 8, /* TexelBytes */
160
fetch_1d_texel_luminance_alpha, /* FetchTexel1D */
161
fetch_2d_texel_luminance_alpha, /* FetchTexel2D */
162
fetch_3d_texel_luminance_alpha, /* FetchTexel3D */
165
const struct gl_texture_format _mesa_texformat_intensity = {
166
MESA_FORMAT_INTENSITY, /* MesaFormat */
167
GL_INTENSITY, /* BaseFormat */
168
CHAN_TYPE, /* Type */
173
0, /* LuminanceBits */
174
CHAN_BITS, /* IntensityBits */
177
CHAN_BITS / 8, /* TexelBytes */
178
fetch_1d_texel_intensity, /* FetchTexel1D */
179
fetch_2d_texel_intensity, /* FetchTexel2D */
180
fetch_3d_texel_intensity, /* FetchTexel3D */
183
const struct gl_texture_format _mesa_texformat_color_index = {
184
MESA_FORMAT_COLOR_INDEX, /* MesaFormat */
185
GL_COLOR_INDEX, /* BaseFormat */
186
CHAN_TYPE, /* Type */
191
0, /* LuminanceBits */
192
0, /* IntensityBits */
193
CHAN_BITS, /* IndexBits */
195
CHAN_BITS / 8, /* TexelBytes */
196
fetch_1d_texel_color_index, /* FetchTexel1D */
197
fetch_2d_texel_color_index, /* FetchTexel2D */
198
fetch_3d_texel_color_index, /* FetchTexel3D */
201
const struct gl_texture_format _mesa_texformat_depth_component = {
202
MESA_FORMAT_DEPTH_COMPONENT, /* MesaFormat */
203
GL_DEPTH_COMPONENT, /* BaseFormat */
209
0, /* LuminanceBits */
210
0, /* IntensityBits */
212
sizeof(GLfloat) * 8, /* DepthBits */
213
sizeof(GLfloat), /* TexelBytes */
214
fetch_1d_texel_depth_component, /* FetchTexel1D */
215
fetch_2d_texel_depth_component, /* FetchTexel2D */
216
fetch_3d_texel_depth_component, /* FetchTexel3D */
220
/* =============================================================
224
const struct gl_texture_format _mesa_texformat_rgba8888 = {
225
MESA_FORMAT_RGBA8888, /* MesaFormat */
226
GL_RGBA, /* BaseFormat */
227
GL_UNSIGNED_INT_8_8_8_8, /* Type */
232
0, /* LuminanceBits */
233
0, /* IntensityBits */
237
fetch_1d_texel_rgba8888, /* FetchTexel1D */
238
fetch_2d_texel_rgba8888, /* FetchTexel2D */
239
fetch_3d_texel_rgba8888, /* FetchTexel3D */
242
const struct gl_texture_format _mesa_texformat_argb8888 = {
243
MESA_FORMAT_ARGB8888, /* MesaFormat */
244
GL_RGBA, /* BaseFormat */
245
GL_UNSIGNED_INT_8_8_8_8_REV, /* Type */
250
0, /* LuminanceBits */
251
0, /* IntensityBits */
255
fetch_1d_texel_argb8888, /* FetchTexel1D */
256
fetch_2d_texel_argb8888, /* FetchTexel2D */
257
fetch_3d_texel_argb8888, /* FetchTexel3D */
260
const struct gl_texture_format _mesa_texformat_rgb888 = {
261
MESA_FORMAT_RGB888, /* MesaFormat */
262
GL_RGB, /* BaseFormat */
263
GL_UNSIGNED_BYTE, /* Type */
268
0, /* LuminanceBits */
269
0, /* IntensityBits */
273
fetch_1d_texel_rgb888, /* FetchTexel1D */
274
fetch_2d_texel_rgb888, /* FetchTexel2D */
275
fetch_3d_texel_rgb888, /* FetchTexel3D */
278
const struct gl_texture_format _mesa_texformat_rgb565 = {
279
MESA_FORMAT_RGB565, /* MesaFormat */
280
GL_RGB, /* BaseFormat */
281
GL_UNSIGNED_SHORT_5_6_5, /* Type */
286
0, /* LuminanceBits */
287
0, /* IntensityBits */
291
fetch_1d_texel_rgb565, /* FetchTexel1D */
292
fetch_2d_texel_rgb565, /* FetchTexel2D */
293
fetch_3d_texel_rgb565, /* FetchTexel3D */
296
const struct gl_texture_format _mesa_texformat_argb4444 = {
297
MESA_FORMAT_ARGB4444, /* MesaFormat */
298
GL_RGBA, /* BaseFormat */
299
GL_UNSIGNED_SHORT_4_4_4_4_REV, /* Type */
304
0, /* LuminanceBits */
305
0, /* IntensityBits */
309
fetch_1d_texel_argb4444, /* FetchTexel1D */
310
fetch_2d_texel_argb4444, /* FetchTexel2D */
311
fetch_3d_texel_argb4444, /* FetchTexel3D */
314
const struct gl_texture_format _mesa_texformat_argb1555 = {
315
MESA_FORMAT_ARGB1555, /* MesaFormat */
316
GL_RGBA, /* BaseFormat */
317
GL_UNSIGNED_SHORT_1_5_5_5_REV, /* Type */
322
0, /* LuminanceBits */
323
0, /* IntensityBits */
327
fetch_1d_texel_argb1555, /* FetchTexel1D */
328
fetch_2d_texel_argb1555, /* FetchTexel2D */
329
fetch_3d_texel_argb1555, /* FetchTexel3D */
332
const struct gl_texture_format _mesa_texformat_al88 = {
333
MESA_FORMAT_AL88, /* MesaFormat */
334
GL_LUMINANCE_ALPHA, /* BaseFormat */
335
GL_UNSIGNED_BYTE, /* Type */
340
8, /* LuminanceBits */
341
0, /* IntensityBits */
345
fetch_1d_texel_al88, /* FetchTexel1D */
346
fetch_2d_texel_al88, /* FetchTexel2D */
347
fetch_3d_texel_al88, /* FetchTexel3D */
350
const struct gl_texture_format _mesa_texformat_rgb332 = {
351
MESA_FORMAT_RGB332, /* MesaFormat */
352
GL_RGB, /* BaseFormat */
353
GL_UNSIGNED_BYTE_3_3_2, /* Type */
358
0, /* LuminanceBits */
359
0, /* IntensityBits */
363
fetch_1d_texel_rgb332, /* FetchTexel1D */
364
fetch_2d_texel_rgb332, /* FetchTexel2D */
365
fetch_3d_texel_rgb332, /* FetchTexel3D */
368
const struct gl_texture_format _mesa_texformat_a8 = {
369
MESA_FORMAT_A8, /* MesaFormat */
370
GL_ALPHA, /* BaseFormat */
371
GL_UNSIGNED_BYTE, /* Type */
376
0, /* LuminanceBits */
377
0, /* IntensityBits */
381
fetch_1d_texel_a8, /* FetchTexel1D */
382
fetch_2d_texel_a8, /* FetchTexel2D */
383
fetch_3d_texel_a8, /* FetchTexel3D */
386
const struct gl_texture_format _mesa_texformat_l8 = {
387
MESA_FORMAT_L8, /* MesaFormat */
388
GL_LUMINANCE, /* BaseFormat */
389
GL_UNSIGNED_BYTE, /* Type */
394
8, /* LuminanceBits */
395
0, /* IntensityBits */
399
fetch_1d_texel_l8, /* FetchTexel1D */
400
fetch_2d_texel_l8, /* FetchTexel2D */
401
fetch_3d_texel_l8, /* FetchTexel3D */
404
const struct gl_texture_format _mesa_texformat_i8 = {
405
MESA_FORMAT_I8, /* MesaFormat */
406
GL_INTENSITY, /* BaseFormat */
407
GL_UNSIGNED_BYTE, /* Type */
412
0, /* LuminanceBits */
413
8, /* IntensityBits */
417
fetch_1d_texel_i8, /* FetchTexel1D */
418
fetch_2d_texel_i8, /* FetchTexel2D */
419
fetch_3d_texel_i8, /* FetchTexel3D */
422
const struct gl_texture_format _mesa_texformat_ci8 = {
423
MESA_FORMAT_CI8, /* MesaFormat */
424
GL_COLOR_INDEX, /* BaseFormat */
425
GL_UNSIGNED_BYTE, /* Type */
430
0, /* LuminanceBits */
431
0, /* IntensityBits */
435
fetch_1d_texel_ci8, /* FetchTexel1D */
436
fetch_2d_texel_ci8, /* FetchTexel2D */
437
fetch_3d_texel_ci8, /* FetchTexel3D */
441
const struct gl_texture_format _mesa_texformat_ycbcr = {
442
MESA_FORMAT_YCBCR, /* MesaFormat */
443
GL_YCBCR_MESA, /* BaseFormat */
444
GL_UNSIGNED_SHORT_8_8_MESA, /* Type */
449
0, /* LuminanceBits */
450
0, /* IntensityBits */
454
fetch_1d_texel_ycbcr, /* FetchTexel1D */
455
fetch_2d_texel_ycbcr, /* FetchTexel2D */
456
fetch_3d_texel_ycbcr, /* FetchTexel3D */
460
const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
461
MESA_FORMAT_YCBCR_REV, /* MesaFormat */
462
GL_YCBCR_MESA, /* BaseFormat */
463
GL_UNSIGNED_SHORT_8_8_REV_MESA, /* Type */
468
0, /* LuminanceBits */
469
0, /* IntensityBits */
473
fetch_1d_texel_ycbcr_rev, /* FetchTexel1D */
474
fetch_2d_texel_ycbcr_rev, /* FetchTexel2D */
475
fetch_3d_texel_ycbcr_rev, /* FetchTexel3D */
480
/* =============================================================
484
const struct gl_texture_format _mesa_null_texformat = {
492
0, /* LuminanceBits */
493
0, /* IntensityBits */
497
fetch_null_texel, /* FetchTexel1D */
498
fetch_null_texel, /* FetchTexel2D */
499
fetch_null_texel, /* FetchTexel3D */
505
_mesa_is_hardware_tex_format( const struct gl_texture_format *format )
507
return (format->MesaFormat < MESA_FORMAT_RGBA);
511
/* Given an internal texture format (or 1, 2, 3, 4) return a pointer
512
* to a gl_texture_format which which to store the texture.
513
* This is called via ctx->Driver.ChooseTextureFormat().
514
* Hardware drivers should not use this function, but instead a
515
* specialized function.
517
const struct gl_texture_format *
518
_mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
519
GLenum format, GLenum type )
524
switch ( internalFormat ) {
525
/* GH: Bias towards GL_RGB, GL_RGBA texture formats. This has
526
* got to be better than sticking them way down the end of this
529
case 4: /* Quake3 uses this... */
531
return &_mesa_texformat_rgba;
533
case 3: /* ... and this. */
535
return &_mesa_texformat_rgb;
537
/* GH: Okay, keep checking as normal. Still test for GL_RGB,
538
* GL_RGBA formats first.
547
return &_mesa_texformat_rgba;
556
return &_mesa_texformat_rgb;
563
return &_mesa_texformat_alpha;
571
return &_mesa_texformat_luminance;
574
case GL_LUMINANCE_ALPHA:
575
case GL_LUMINANCE4_ALPHA4:
576
case GL_LUMINANCE6_ALPHA2:
577
case GL_LUMINANCE8_ALPHA8:
578
case GL_LUMINANCE12_ALPHA4:
579
case GL_LUMINANCE12_ALPHA12:
580
case GL_LUMINANCE16_ALPHA16:
581
return &_mesa_texformat_luminance_alpha;
588
return &_mesa_texformat_intensity;
591
case GL_COLOR_INDEX1_EXT:
592
case GL_COLOR_INDEX2_EXT:
593
case GL_COLOR_INDEX4_EXT:
594
case GL_COLOR_INDEX8_EXT:
595
case GL_COLOR_INDEX12_EXT:
596
case GL_COLOR_INDEX16_EXT:
597
return &_mesa_texformat_color_index;
599
case GL_DEPTH_COMPONENT:
600
case GL_DEPTH_COMPONENT16_SGIX:
601
case GL_DEPTH_COMPONENT24_SGIX:
602
case GL_DEPTH_COMPONENT32_SGIX:
603
if (!ctx->Extensions.SGIX_depth_texture)
604
_mesa_problem(ctx, "depth format without GL_SGIX_depth_texture");
605
return &_mesa_texformat_depth_component;
607
case GL_COMPRESSED_ALPHA_ARB:
608
if (!ctx->Extensions.ARB_texture_compression)
609
_mesa_problem(ctx, "texture compression extension not enabled");
610
return &_mesa_texformat_alpha;
611
case GL_COMPRESSED_LUMINANCE_ARB:
612
if (!ctx->Extensions.ARB_texture_compression)
613
_mesa_problem(ctx, "texture compression extension not enabled");
614
return &_mesa_texformat_luminance;
615
case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
616
if (!ctx->Extensions.ARB_texture_compression)
617
_mesa_problem(ctx, "texture compression extension not enabled");
618
return &_mesa_texformat_luminance_alpha;
619
case GL_COMPRESSED_INTENSITY_ARB:
620
if (!ctx->Extensions.ARB_texture_compression)
621
_mesa_problem(ctx, "texture compression extension not enabled");
622
return &_mesa_texformat_intensity;
623
case GL_COMPRESSED_RGB_ARB:
624
if (!ctx->Extensions.ARB_texture_compression)
625
_mesa_problem(ctx, "texture compression extension not enabled");
626
return &_mesa_texformat_rgb;
627
case GL_COMPRESSED_RGBA_ARB:
628
if (!ctx->Extensions.ARB_texture_compression)
629
_mesa_problem(ctx, "texture compression extension not enabled");
630
return &_mesa_texformat_rgba;
633
if (type == GL_UNSIGNED_SHORT_8_8_MESA)
634
return &_mesa_texformat_ycbcr;
636
return &_mesa_texformat_ycbcr_rev;
639
_mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
640
printf("intformat = %d %x\n", internalFormat, internalFormat);
649
* Return the base texture format for the given compressed format
650
* Called via ctx->Driver.BaseCompressedTexFormat().
651
* This function is used by software rasterizers. Hardware drivers
652
* which support texture compression should not use this function but
653
* a specialized function instead.
656
_mesa_base_compressed_texformat(GLcontext *ctx, GLint intFormat)
659
case GL_COMPRESSED_ALPHA_ARB:
661
case GL_COMPRESSED_LUMINANCE_ARB:
663
case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
664
return GL_LUMINANCE_ALPHA;
665
case GL_COMPRESSED_INTENSITY_ARB:
667
case GL_COMPRESSED_RGB_ARB:
669
case GL_COMPRESSED_RGBA_ARB:
672
return -1; /* not a recognized compressed format */
678
* Called via ctx->Driver.CompressedTextureSize().
679
* This function is only used by software rasterizers.
680
* Hardware drivers will have to implement a specialized function.
683
_mesa_compressed_texture_size(GLcontext *ctx,
684
const struct gl_texture_image *texImage)
688
assert(texImage->TexFormat);
690
b = texImage->Width * texImage->Height * texImage->Depth *
691
texImage->TexFormat->TexelBytes;