blob: 2c95b8385923361cc351f98fc61199f861246347 [file] [log] [blame]
Brian Paulc5b99502002-09-21 16:51:25 +00001/* $Id: texformat.c,v 1.15 2002/09/21 16:51:25 brianp Exp $ */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +00002
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"
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000043#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 */
59static 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
Gareth Hughes5e23af22001-03-30 14:44:43 +000070/* =============================================================
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000071 * Default GLchan-based formats:
72 */
73
74const struct gl_texture_format _mesa_texformat_rgba = {
Gareth Hughes38f28662001-03-28 20:40:51 +000075 MESA_FORMAT_RGBA, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +000076 GL_RGBA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +000077 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000078 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
92const struct gl_texture_format _mesa_texformat_rgb = {
Gareth Hughes38f28662001-03-28 20:40:51 +000093 MESA_FORMAT_RGB, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +000094 GL_RGB, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +000095 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000096 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
110const struct gl_texture_format _mesa_texformat_alpha = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000111 MESA_FORMAT_ALPHA, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000112 GL_ALPHA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000113 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000114 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
128const struct gl_texture_format _mesa_texformat_luminance = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000129 MESA_FORMAT_LUMINANCE, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000130 GL_LUMINANCE, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000131 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000132 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
146const struct gl_texture_format _mesa_texformat_luminance_alpha = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000147 MESA_FORMAT_LUMINANCE_ALPHA, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000148 GL_LUMINANCE_ALPHA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000149 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000150 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
164const struct gl_texture_format _mesa_texformat_intensity = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000165 MESA_FORMAT_INTENSITY, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000166 GL_INTENSITY, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000167 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000168 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
182const struct gl_texture_format _mesa_texformat_color_index = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000183 MESA_FORMAT_COLOR_INDEX, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000184 GL_COLOR_INDEX, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000185 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000186 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
200const struct gl_texture_format _mesa_texformat_depth_component = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000201 MESA_FORMAT_DEPTH_COMPONENT, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000202 GL_DEPTH_COMPONENT, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000203 GL_FLOAT, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000204 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
Gareth Hughes5e23af22001-03-30 14:44:43 +0000219/* =============================================================
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000220 * Hardware formats:
221 */
222
223const struct gl_texture_format _mesa_texformat_rgba8888 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000224 MESA_FORMAT_RGBA8888, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000225 GL_RGBA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000226 GL_UNSIGNED_INT_8_8_8_8, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000227 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
241const struct gl_texture_format _mesa_texformat_argb8888 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000242 MESA_FORMAT_ARGB8888, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000243 GL_RGBA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000244 GL_UNSIGNED_INT_8_8_8_8_REV, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000245 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
259const struct gl_texture_format _mesa_texformat_rgb888 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000260 MESA_FORMAT_RGB888, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000261 GL_RGB, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000262 GL_UNSIGNED_BYTE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000263 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
277const struct gl_texture_format _mesa_texformat_rgb565 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000278 MESA_FORMAT_RGB565, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000279 GL_RGB, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000280 GL_UNSIGNED_SHORT_5_6_5, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000281 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
295const struct gl_texture_format _mesa_texformat_argb4444 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000296 MESA_FORMAT_ARGB4444, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000297 GL_RGBA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000298 GL_UNSIGNED_SHORT_4_4_4_4_REV, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000299 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
313const struct gl_texture_format _mesa_texformat_argb1555 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000314 MESA_FORMAT_ARGB1555, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000315 GL_RGBA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000316 GL_UNSIGNED_SHORT_1_5_5_5_REV, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000317 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
331const struct gl_texture_format _mesa_texformat_al88 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000332 MESA_FORMAT_AL88, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000333 GL_LUMINANCE_ALPHA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000334 GL_UNSIGNED_BYTE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000335 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
349const struct gl_texture_format _mesa_texformat_rgb332 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000350 MESA_FORMAT_RGB332, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000351 GL_RGB, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000352 GL_UNSIGNED_BYTE_3_3_2, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000353 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
367const struct gl_texture_format _mesa_texformat_a8 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000368 MESA_FORMAT_A8, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000369 GL_ALPHA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000370 GL_UNSIGNED_BYTE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000371 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
385const struct gl_texture_format _mesa_texformat_l8 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000386 MESA_FORMAT_L8, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000387 GL_LUMINANCE, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000388 GL_UNSIGNED_BYTE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000389 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
403const struct gl_texture_format _mesa_texformat_i8 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000404 MESA_FORMAT_I8, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000405 GL_INTENSITY, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000406 GL_UNSIGNED_BYTE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000407 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
421const struct gl_texture_format _mesa_texformat_ci8 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000422 MESA_FORMAT_CI8, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000423 GL_COLOR_INDEX, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000424 GL_UNSIGNED_BYTE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000425 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
Brian Paulc5b99502002-09-21 16:51:25 +0000440const 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
459const 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
Brian Paul4753d602002-06-15 02:38:15 +0000478/* Big-endian */
479#if 0
480const 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
498const 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
516const 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
534const 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
552const 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
570const 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
588const 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
606const 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
Gareth Hughes5e23af22001-03-30 14:44:43 +0000625/* =============================================================
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000626 * Null format:
627 */
628
629const struct gl_texture_format _mesa_null_texformat = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000630 -1, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000631 0, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000632 0, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000633 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
Brian Paul7d58f442001-04-04 21:54:20 +0000649GLboolean
650_mesa_is_hardware_tex_format( const struct gl_texture_format *format )
651{
652 return (format->MesaFormat < MESA_FORMAT_RGBA);
653}
654
655
Brian Paule4276662001-06-15 14:18:46 +0000656/* 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().
Brian Paul4753d602002-06-15 02:38:15 +0000659 * Hardware drivers typically override this function with a specialized
660 * version.
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000661 */
Brian Paul7d58f442001-04-04 21:54:20 +0000662const struct gl_texture_format *
663_mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
664 GLenum format, GLenum type )
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000665{
Brian Paul7d58f442001-04-04 21:54:20 +0000666 (void) format;
667 (void) type;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000668
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:
Brian Paul7d58f442001-04-04 21:54:20 +0000676 return &_mesa_texformat_rgba;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000677
678 case 3: /* ... and this. */
679 case GL_RGB:
Brian Paul7d58f442001-04-04 21:54:20 +0000680 return &_mesa_texformat_rgb;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000681
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:
Brian Paul7d58f442001-04-04 21:54:20 +0000692 return &_mesa_texformat_rgba;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000693
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:
Brian Paul7d58f442001-04-04 21:54:20 +0000701 return &_mesa_texformat_rgb;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000702
703 case GL_ALPHA:
704 case GL_ALPHA4:
705 case GL_ALPHA8:
706 case GL_ALPHA12:
707 case GL_ALPHA16:
Brian Paul7d58f442001-04-04 21:54:20 +0000708 return &_mesa_texformat_alpha;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000709
710 case 1:
711 case GL_LUMINANCE:
712 case GL_LUMINANCE4:
713 case GL_LUMINANCE8:
714 case GL_LUMINANCE12:
715 case GL_LUMINANCE16:
Brian Paul7d58f442001-04-04 21:54:20 +0000716 return &_mesa_texformat_luminance;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000717
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:
Brian Paul7d58f442001-04-04 21:54:20 +0000726 return &_mesa_texformat_luminance_alpha;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000727
728 case GL_INTENSITY:
729 case GL_INTENSITY4:
730 case GL_INTENSITY8:
731 case GL_INTENSITY12:
732 case GL_INTENSITY16:
Brian Paul7d58f442001-04-04 21:54:20 +0000733 return &_mesa_texformat_intensity;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000734
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:
Brian Paul7d58f442001-04-04 21:54:20 +0000742 return &_mesa_texformat_color_index;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000743
744 case GL_DEPTH_COMPONENT:
745 case GL_DEPTH_COMPONENT16_SGIX:
746 case GL_DEPTH_COMPONENT24_SGIX:
747 case GL_DEPTH_COMPONENT32_SGIX:
Brian Paule4276662001-06-15 14:18:46 +0000748 if (!ctx->Extensions.SGIX_depth_texture)
749 _mesa_problem(ctx, "depth format without GL_SGIX_depth_texture");
Brian Paul7d58f442001-04-04 21:54:20 +0000750 return &_mesa_texformat_depth_component;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000751
Brian Paule4276662001-06-15 14:18:46 +0000752 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
Brian Paulc5b99502002-09-21 16:51:25 +0000777 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
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000783 default:
Brian Paule4276662001-06-15 14:18:46 +0000784 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
Brian Paul4e9676f2002-06-29 19:48:15 +0000785 _mesa_debug(ctx, "intformat = %d %x\n", internalFormat, internalFormat);
Brian Paul7d58f442001-04-04 21:54:20 +0000786 return NULL;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000787 }
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000788}
Brian Paule4276662001-06-15 14:18:46 +0000789
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 */
800GLint
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 */
827GLint
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}