blob: ce145d800bc0317210ee2960cb21efdf5ddb533d [file] [log] [blame]
Brian Paul4753d602002-06-15 02:38:15 +00001/* $Id: texformat.c,v 1.12 2002/06/15 02:38:16 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"
43#include "swrast/s_span.h"
44#endif
45
46
47/* Texel fetch routines for all supported formats:
48 */
49#define DIM 1
50#include "texformat_tmp.h"
51
52#define DIM 2
53#include "texformat_tmp.h"
54
55#define DIM 3
56#include "texformat_tmp.h"
57
58/* Have to have this so the FetchTexel function pointer is never NULL.
59 */
60static void fetch_null_texel( const struct gl_texture_image *texImage,
61 GLint i, GLint j, GLint k, GLvoid *texel )
62{
63 GLchan *rgba = (GLchan *) texel;
64 rgba[RCOMP] = 0;
65 rgba[GCOMP] = 0;
66 rgba[BCOMP] = 0;
67 rgba[ACOMP] = 0;
68}
69
70
Gareth Hughes5e23af22001-03-30 14:44:43 +000071/* =============================================================
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000072 * Default GLchan-based formats:
73 */
74
75const struct gl_texture_format _mesa_texformat_rgba = {
Gareth Hughes38f28662001-03-28 20:40:51 +000076 MESA_FORMAT_RGBA, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +000077 GL_RGBA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +000078 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000079 CHAN_BITS, /* RedBits */
80 CHAN_BITS, /* GreenBits */
81 CHAN_BITS, /* BlueBits */
82 CHAN_BITS, /* AlphaBits */
83 0, /* LuminanceBits */
84 0, /* IntensityBits */
85 0, /* IndexBits */
86 0, /* DepthBits */
87 4 * CHAN_BITS / 8, /* TexelBytes */
88 fetch_1d_texel_rgba, /* FetchTexel1D */
89 fetch_2d_texel_rgba, /* FetchTexel2D */
90 fetch_3d_texel_rgba, /* FetchTexel3D */
91};
92
93const struct gl_texture_format _mesa_texformat_rgb = {
Gareth Hughes38f28662001-03-28 20:40:51 +000094 MESA_FORMAT_RGB, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +000095 GL_RGB, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +000096 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000097 CHAN_BITS, /* RedBits */
98 CHAN_BITS, /* GreenBits */
99 CHAN_BITS, /* BlueBits */
100 0, /* AlphaBits */
101 0, /* LuminanceBits */
102 0, /* IntensityBits */
103 0, /* IndexBits */
104 0, /* DepthBits */
105 3 * CHAN_BITS / 8, /* TexelBytes */
106 fetch_1d_texel_rgb, /* FetchTexel1D */
107 fetch_2d_texel_rgb, /* FetchTexel2D */
108 fetch_3d_texel_rgb, /* FetchTexel3D */
109};
110
111const struct gl_texture_format _mesa_texformat_alpha = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000112 MESA_FORMAT_ALPHA, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000113 GL_ALPHA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000114 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000115 0, /* RedBits */
116 0, /* GreenBits */
117 0, /* BlueBits */
118 CHAN_BITS, /* AlphaBits */
119 0, /* LuminanceBits */
120 0, /* IntensityBits */
121 0, /* IndexBits */
122 0, /* DepthBits */
123 CHAN_BITS / 8, /* TexelBytes */
124 fetch_1d_texel_alpha, /* FetchTexel1D */
125 fetch_2d_texel_alpha, /* FetchTexel2D */
126 fetch_3d_texel_alpha, /* FetchTexel3D */
127};
128
129const struct gl_texture_format _mesa_texformat_luminance = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000130 MESA_FORMAT_LUMINANCE, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000131 GL_LUMINANCE, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000132 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000133 0, /* RedBits */
134 0, /* GreenBits */
135 0, /* BlueBits */
136 0, /* AlphaBits */
137 CHAN_BITS, /* LuminanceBits */
138 0, /* IntensityBits */
139 0, /* IndexBits */
140 0, /* DepthBits */
141 CHAN_BITS / 8, /* TexelBytes */
142 fetch_1d_texel_luminance, /* FetchTexel1D */
143 fetch_2d_texel_luminance, /* FetchTexel2D */
144 fetch_3d_texel_luminance, /* FetchTexel3D */
145};
146
147const struct gl_texture_format _mesa_texformat_luminance_alpha = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000148 MESA_FORMAT_LUMINANCE_ALPHA, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000149 GL_LUMINANCE_ALPHA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000150 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000151 0, /* RedBits */
152 0, /* GreenBits */
153 0, /* BlueBits */
154 CHAN_BITS, /* AlphaBits */
155 CHAN_BITS, /* LuminanceBits */
156 0, /* IntensityBits */
157 0, /* IndexBits */
158 0, /* DepthBits */
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 */
163};
164
165const struct gl_texture_format _mesa_texformat_intensity = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000166 MESA_FORMAT_INTENSITY, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000167 GL_INTENSITY, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000168 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000169 0, /* RedBits */
170 0, /* GreenBits */
171 0, /* BlueBits */
172 0, /* AlphaBits */
173 0, /* LuminanceBits */
174 CHAN_BITS, /* IntensityBits */
175 0, /* IndexBits */
176 0, /* DepthBits */
177 CHAN_BITS / 8, /* TexelBytes */
178 fetch_1d_texel_intensity, /* FetchTexel1D */
179 fetch_2d_texel_intensity, /* FetchTexel2D */
180 fetch_3d_texel_intensity, /* FetchTexel3D */
181};
182
183const struct gl_texture_format _mesa_texformat_color_index = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000184 MESA_FORMAT_COLOR_INDEX, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000185 GL_COLOR_INDEX, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000186 CHAN_TYPE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000187 0, /* RedBits */
188 0, /* GreenBits */
189 0, /* BlueBits */
190 0, /* AlphaBits */
191 0, /* LuminanceBits */
192 0, /* IntensityBits */
193 CHAN_BITS, /* IndexBits */
194 0, /* DepthBits */
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 */
199};
200
201const struct gl_texture_format _mesa_texformat_depth_component = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000202 MESA_FORMAT_DEPTH_COMPONENT, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000203 GL_DEPTH_COMPONENT, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000204 GL_FLOAT, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000205 0, /* RedBits */
206 0, /* GreenBits */
207 0, /* BlueBits */
208 0, /* AlphaBits */
209 0, /* LuminanceBits */
210 0, /* IntensityBits */
211 0, /* IndexBits */
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 */
217};
218
219
Gareth Hughes5e23af22001-03-30 14:44:43 +0000220/* =============================================================
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000221 * Hardware formats:
222 */
223
224const struct gl_texture_format _mesa_texformat_rgba8888 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000225 MESA_FORMAT_RGBA8888, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000226 GL_RGBA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000227 GL_UNSIGNED_INT_8_8_8_8, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000228 8, /* RedBits */
229 8, /* GreenBits */
230 8, /* BlueBits */
231 8, /* AlphaBits */
232 0, /* LuminanceBits */
233 0, /* IntensityBits */
234 0, /* IndexBits */
235 0, /* DepthBits */
236 4, /* TexelBytes */
237 fetch_1d_texel_rgba8888, /* FetchTexel1D */
238 fetch_2d_texel_rgba8888, /* FetchTexel2D */
239 fetch_3d_texel_rgba8888, /* FetchTexel3D */
240};
241
242const struct gl_texture_format _mesa_texformat_argb8888 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000243 MESA_FORMAT_ARGB8888, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000244 GL_RGBA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000245 GL_UNSIGNED_INT_8_8_8_8_REV, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000246 8, /* RedBits */
247 8, /* GreenBits */
248 8, /* BlueBits */
249 8, /* AlphaBits */
250 0, /* LuminanceBits */
251 0, /* IntensityBits */
252 0, /* IndexBits */
253 0, /* DepthBits */
254 4, /* TexelBytes */
255 fetch_1d_texel_argb8888, /* FetchTexel1D */
256 fetch_2d_texel_argb8888, /* FetchTexel2D */
257 fetch_3d_texel_argb8888, /* FetchTexel3D */
258};
259
260const struct gl_texture_format _mesa_texformat_rgb888 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000261 MESA_FORMAT_RGB888, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000262 GL_RGB, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000263 GL_UNSIGNED_BYTE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000264 8, /* RedBits */
265 8, /* GreenBits */
266 8, /* BlueBits */
267 0, /* AlphaBits */
268 0, /* LuminanceBits */
269 0, /* IntensityBits */
270 0, /* IndexBits */
271 0, /* DepthBits */
272 3, /* TexelBytes */
273 fetch_1d_texel_rgb888, /* FetchTexel1D */
274 fetch_2d_texel_rgb888, /* FetchTexel2D */
275 fetch_3d_texel_rgb888, /* FetchTexel3D */
276};
277
278const struct gl_texture_format _mesa_texformat_rgb565 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000279 MESA_FORMAT_RGB565, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000280 GL_RGB, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000281 GL_UNSIGNED_SHORT_5_6_5, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000282 5, /* RedBits */
283 6, /* GreenBits */
284 5, /* BlueBits */
285 0, /* AlphaBits */
286 0, /* LuminanceBits */
287 0, /* IntensityBits */
288 0, /* IndexBits */
289 0, /* DepthBits */
290 2, /* TexelBytes */
291 fetch_1d_texel_rgb565, /* FetchTexel1D */
292 fetch_2d_texel_rgb565, /* FetchTexel2D */
293 fetch_3d_texel_rgb565, /* FetchTexel3D */
294};
295
296const struct gl_texture_format _mesa_texformat_argb4444 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000297 MESA_FORMAT_ARGB4444, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000298 GL_RGBA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000299 GL_UNSIGNED_SHORT_4_4_4_4_REV, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000300 4, /* RedBits */
301 4, /* GreenBits */
302 4, /* BlueBits */
303 4, /* AlphaBits */
304 0, /* LuminanceBits */
305 0, /* IntensityBits */
306 0, /* IndexBits */
307 0, /* DepthBits */
308 2, /* TexelBytes */
309 fetch_1d_texel_argb4444, /* FetchTexel1D */
310 fetch_2d_texel_argb4444, /* FetchTexel2D */
311 fetch_3d_texel_argb4444, /* FetchTexel3D */
312};
313
314const struct gl_texture_format _mesa_texformat_argb1555 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000315 MESA_FORMAT_ARGB1555, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000316 GL_RGBA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000317 GL_UNSIGNED_SHORT_1_5_5_5_REV, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000318 5, /* RedBits */
319 5, /* GreenBits */
320 5, /* BlueBits */
321 1, /* AlphaBits */
322 0, /* LuminanceBits */
323 0, /* IntensityBits */
324 0, /* IndexBits */
325 0, /* DepthBits */
326 2, /* TexelBytes */
327 fetch_1d_texel_argb1555, /* FetchTexel1D */
328 fetch_2d_texel_argb1555, /* FetchTexel2D */
329 fetch_3d_texel_argb1555, /* FetchTexel3D */
330};
331
332const struct gl_texture_format _mesa_texformat_al88 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000333 MESA_FORMAT_AL88, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000334 GL_LUMINANCE_ALPHA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000335 GL_UNSIGNED_BYTE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000336 0, /* RedBits */
337 0, /* GreenBits */
338 0, /* BlueBits */
339 8, /* AlphaBits */
340 8, /* LuminanceBits */
341 0, /* IntensityBits */
342 0, /* IndexBits */
343 0, /* DepthBits */
344 2, /* TexelBytes */
345 fetch_1d_texel_al88, /* FetchTexel1D */
346 fetch_2d_texel_al88, /* FetchTexel2D */
347 fetch_3d_texel_al88, /* FetchTexel3D */
348};
349
350const struct gl_texture_format _mesa_texformat_rgb332 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000351 MESA_FORMAT_RGB332, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000352 GL_RGB, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000353 GL_UNSIGNED_BYTE_3_3_2, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000354 3, /* RedBits */
355 3, /* GreenBits */
356 2, /* BlueBits */
357 0, /* AlphaBits */
358 0, /* LuminanceBits */
359 0, /* IntensityBits */
360 0, /* IndexBits */
361 0, /* DepthBits */
362 1, /* TexelBytes */
363 fetch_1d_texel_rgb332, /* FetchTexel1D */
364 fetch_2d_texel_rgb332, /* FetchTexel2D */
365 fetch_3d_texel_rgb332, /* FetchTexel3D */
366};
367
368const struct gl_texture_format _mesa_texformat_a8 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000369 MESA_FORMAT_A8, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000370 GL_ALPHA, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000371 GL_UNSIGNED_BYTE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000372 0, /* RedBits */
373 0, /* GreenBits */
374 0, /* BlueBits */
375 8, /* AlphaBits */
376 0, /* LuminanceBits */
377 0, /* IntensityBits */
378 0, /* IndexBits */
379 0, /* DepthBits */
380 1, /* TexelBytes */
381 fetch_1d_texel_a8, /* FetchTexel1D */
382 fetch_2d_texel_a8, /* FetchTexel2D */
383 fetch_3d_texel_a8, /* FetchTexel3D */
384};
385
386const struct gl_texture_format _mesa_texformat_l8 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000387 MESA_FORMAT_L8, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000388 GL_LUMINANCE, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000389 GL_UNSIGNED_BYTE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000390 0, /* RedBits */
391 0, /* GreenBits */
392 0, /* BlueBits */
393 0, /* AlphaBits */
394 8, /* LuminanceBits */
395 0, /* IntensityBits */
396 0, /* IndexBits */
397 0, /* DepthBits */
398 1, /* TexelBytes */
399 fetch_1d_texel_l8, /* FetchTexel1D */
400 fetch_2d_texel_l8, /* FetchTexel2D */
401 fetch_3d_texel_l8, /* FetchTexel3D */
402};
403
404const struct gl_texture_format _mesa_texformat_i8 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000405 MESA_FORMAT_I8, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000406 GL_INTENSITY, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000407 GL_UNSIGNED_BYTE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000408 0, /* RedBits */
409 0, /* GreenBits */
410 0, /* BlueBits */
411 0, /* AlphaBits */
412 0, /* LuminanceBits */
413 8, /* IntensityBits */
414 0, /* IndexBits */
415 0, /* DepthBits */
416 1, /* TexelBytes */
417 fetch_1d_texel_i8, /* FetchTexel1D */
418 fetch_2d_texel_i8, /* FetchTexel2D */
419 fetch_3d_texel_i8, /* FetchTexel3D */
420};
421
422const struct gl_texture_format _mesa_texformat_ci8 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000423 MESA_FORMAT_CI8, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000424 GL_COLOR_INDEX, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000425 GL_UNSIGNED_BYTE, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000426 0, /* RedBits */
427 0, /* GreenBits */
428 0, /* BlueBits */
429 0, /* AlphaBits */
430 0, /* LuminanceBits */
431 0, /* IntensityBits */
432 8, /* IndexBits */
433 0, /* DepthBits */
434 1, /* TexelBytes */
435 fetch_1d_texel_ci8, /* FetchTexel1D */
436 fetch_2d_texel_ci8, /* FetchTexel2D */
437 fetch_3d_texel_ci8, /* FetchTexel3D */
438};
439
440
Brian Paul4753d602002-06-15 02:38:15 +0000441/* Big-endian */
442#if 0
443const struct gl_texture_format _mesa_texformat_abgr8888 = {
444 MESA_FORMAT_ABGR8888, /* MesaFormat */
445 GL_RGBA, /* BaseFormat */
446 GL_UNSIGNED_INT_8_8_8_8, /* Type */
447 8, /* RedBits */
448 8, /* GreenBits */
449 8, /* BlueBits */
450 8, /* AlphaBits */
451 0, /* LuminanceBits */
452 0, /* IntensityBits */
453 0, /* IndexBits */
454 0, /* DepthBits */
455 4, /* TexelBytes */
456 fetch_1d_texel_abgr8888, /* FetchTexel1D */
457 fetch_2d_texel_abgr8888, /* FetchTexel2D */
458 fetch_3d_texel_abgr8888, /* FetchTexel3D */
459};
460
461const struct gl_texture_format _mesa_texformat_bgra8888 = {
462 MESA_FORMAT_BGRA8888, /* MesaFormat */
463 GL_RGBA, /* BaseFormat */
464 GL_UNSIGNED_INT_8_8_8_8, /* Type */
465 8, /* RedBits */
466 8, /* GreenBits */
467 8, /* BlueBits */
468 8, /* AlphaBits */
469 0, /* LuminanceBits */
470 0, /* IntensityBits */
471 0, /* IndexBits */
472 0, /* DepthBits */
473 4, /* TexelBytes */
474 fetch_1d_texel_bgra8888, /* FetchTexel1D */
475 fetch_2d_texel_bgra8888, /* FetchTexel2D */
476 fetch_3d_texel_bgra8888, /* FetchTexel3D */
477};
478
479const struct gl_texture_format _mesa_texformat_bgr888 = {
480 MESA_FORMAT_BGR888, /* MesaFormat */
481 GL_RGB, /* BaseFormat */
482 GL_UNSIGNED_BYTE, /* Type */
483 8, /* RedBits */
484 8, /* GreenBits */
485 8, /* BlueBits */
486 0, /* AlphaBits */
487 0, /* LuminanceBits */
488 0, /* IntensityBits */
489 0, /* IndexBits */
490 0, /* DepthBits */
491 3, /* TexelBytes */
492 fetch_1d_texel_bgr888, /* FetchTexel1D */
493 fetch_2d_texel_bgr888, /* FetchTexel2D */
494 fetch_3d_texel_bgr888, /* FetchTexel3D */
495};
496
497const struct gl_texture_format _mesa_texformat_bgr565 = {
498 MESA_FORMAT_BGR565, /* MesaFormat */
499 GL_RGB, /* BaseFormat */
500 GL_UNSIGNED_SHORT_5_6_5, /* Type */
501 5, /* RedBits */
502 6, /* GreenBits */
503 5, /* BlueBits */
504 0, /* AlphaBits */
505 0, /* LuminanceBits */
506 0, /* IntensityBits */
507 0, /* IndexBits */
508 0, /* DepthBits */
509 2, /* TexelBytes */
510 fetch_1d_texel_bgr565, /* FetchTexel1D */
511 fetch_2d_texel_bgr565, /* FetchTexel2D */
512 fetch_3d_texel_bgr565, /* FetchTexel3D */
513};
514
515const struct gl_texture_format _mesa_texformat_bgra4444 = {
516 MESA_FORMAT_BGRA4444, /* MesaFormat */
517 GL_RGBA, /* BaseFormat */
518 GL_UNSIGNED_SHORT_4_4_4_4_REV, /* Type */
519 4, /* RedBits */
520 4, /* GreenBits */
521 4, /* BlueBits */
522 4, /* AlphaBits */
523 0, /* LuminanceBits */
524 0, /* IntensityBits */
525 0, /* IndexBits */
526 0, /* DepthBits */
527 2, /* TexelBytes */
528 fetch_1d_texel_bgra4444, /* FetchTexel1D */
529 fetch_2d_texel_bgra4444, /* FetchTexel2D */
530 fetch_3d_texel_bgra4444, /* FetchTexel3D */
531};
532
533const struct gl_texture_format _mesa_texformat_bgra5551 = {
534 MESA_FORMAT_BGRA5551, /* MesaFormat */
535 GL_RGBA, /* BaseFormat */
536 GL_UNSIGNED_SHORT_1_5_5_5_REV, /* Type */
537 5, /* RedBits */
538 5, /* GreenBits */
539 5, /* BlueBits */
540 1, /* AlphaBits */
541 0, /* LuminanceBits */
542 0, /* IntensityBits */
543 0, /* IndexBits */
544 0, /* DepthBits */
545 2, /* TexelBytes */
546 fetch_1d_texel_bgra1555, /* FetchTexel1D */
547 fetch_2d_texel_bgra1555, /* FetchTexel2D */
548 fetch_3d_texel_bgra1555, /* FetchTexel3D */
549};
550
551const struct gl_texture_format _mesa_texformat_la88 = {
552 MESA_FORMAT_LA88, /* MesaFormat */
553 GL_LUMINANCE_ALPHA, /* BaseFormat */
554 GL_UNSIGNED_BYTE, /* Type */
555 0, /* RedBits */
556 0, /* GreenBits */
557 0, /* BlueBits */
558 8, /* AlphaBits */
559 8, /* LuminanceBits */
560 0, /* IntensityBits */
561 0, /* IndexBits */
562 0, /* DepthBits */
563 2, /* TexelBytes */
564 fetch_1d_texel_la88, /* FetchTexel1D */
565 fetch_2d_texel_la88, /* FetchTexel2D */
566 fetch_3d_texel_la88, /* FetchTexel3D */
567};
568
569const struct gl_texture_format _mesa_texformat_bgr233 = {
570 MESA_FORMAT_BGR233, /* MesaFormat */
571 GL_RGB, /* BaseFormat */
572 GL_UNSIGNED_BYTE_3_3_2, /* Type */
573 3, /* RedBits */
574 3, /* GreenBits */
575 2, /* BlueBits */
576 0, /* AlphaBits */
577 0, /* LuminanceBits */
578 0, /* IntensityBits */
579 0, /* IndexBits */
580 0, /* DepthBits */
581 1, /* TexelBytes */
582 fetch_1d_texel_bgr233, /* FetchTexel1D */
583 fetch_2d_texel_bgr233, /* FetchTexel2D */
584 fetch_3d_texel_bgr233, /* FetchTexel3D */
585};
586#endif
587
Gareth Hughes5e23af22001-03-30 14:44:43 +0000588/* =============================================================
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000589 * Null format:
590 */
591
592const struct gl_texture_format _mesa_null_texformat = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000593 -1, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000594 0, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000595 0, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000596 0, /* RedBits */
597 0, /* GreenBits */
598 0, /* BlueBits */
599 0, /* AlphaBits */
600 0, /* LuminanceBits */
601 0, /* IntensityBits */
602 0, /* IndexBits */
603 0, /* DepthBits */
604 0, /* TexelBytes */
605 fetch_null_texel, /* FetchTexel1D */
606 fetch_null_texel, /* FetchTexel2D */
607 fetch_null_texel, /* FetchTexel3D */
608};
609
610
611
Brian Paul7d58f442001-04-04 21:54:20 +0000612GLboolean
613_mesa_is_hardware_tex_format( const struct gl_texture_format *format )
614{
615 return (format->MesaFormat < MESA_FORMAT_RGBA);
616}
617
618
Brian Paule4276662001-06-15 14:18:46 +0000619/* Given an internal texture format (or 1, 2, 3, 4) return a pointer
620 * to a gl_texture_format which which to store the texture.
621 * This is called via ctx->Driver.ChooseTextureFormat().
Brian Paul4753d602002-06-15 02:38:15 +0000622 * Hardware drivers typically override this function with a specialized
623 * version.
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000624 */
Brian Paul7d58f442001-04-04 21:54:20 +0000625const struct gl_texture_format *
626_mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
627 GLenum format, GLenum type )
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000628{
Brian Paul7d58f442001-04-04 21:54:20 +0000629 (void) format;
630 (void) type;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000631
632 switch ( internalFormat ) {
633 /* GH: Bias towards GL_RGB, GL_RGBA texture formats. This has
634 * got to be better than sticking them way down the end of this
635 * huge list.
636 */
637 case 4: /* Quake3 uses this... */
638 case GL_RGBA:
Brian Paul7d58f442001-04-04 21:54:20 +0000639 return &_mesa_texformat_rgba;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000640
641 case 3: /* ... and this. */
642 case GL_RGB:
Brian Paul7d58f442001-04-04 21:54:20 +0000643 return &_mesa_texformat_rgb;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000644
645 /* GH: Okay, keep checking as normal. Still test for GL_RGB,
646 * GL_RGBA formats first.
647 */
648 case GL_RGBA2:
649 case GL_RGBA4:
650 case GL_RGB5_A1:
651 case GL_RGBA8:
652 case GL_RGB10_A2:
653 case GL_RGBA12:
654 case GL_RGBA16:
Brian Paul7d58f442001-04-04 21:54:20 +0000655 return &_mesa_texformat_rgba;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000656
657 case GL_R3_G3_B2:
658 case GL_RGB4:
659 case GL_RGB5:
660 case GL_RGB8:
661 case GL_RGB10:
662 case GL_RGB12:
663 case GL_RGB16:
Brian Paul7d58f442001-04-04 21:54:20 +0000664 return &_mesa_texformat_rgb;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000665
666 case GL_ALPHA:
667 case GL_ALPHA4:
668 case GL_ALPHA8:
669 case GL_ALPHA12:
670 case GL_ALPHA16:
Brian Paul7d58f442001-04-04 21:54:20 +0000671 return &_mesa_texformat_alpha;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000672
673 case 1:
674 case GL_LUMINANCE:
675 case GL_LUMINANCE4:
676 case GL_LUMINANCE8:
677 case GL_LUMINANCE12:
678 case GL_LUMINANCE16:
Brian Paul7d58f442001-04-04 21:54:20 +0000679 return &_mesa_texformat_luminance;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000680
681 case 2:
682 case GL_LUMINANCE_ALPHA:
683 case GL_LUMINANCE4_ALPHA4:
684 case GL_LUMINANCE6_ALPHA2:
685 case GL_LUMINANCE8_ALPHA8:
686 case GL_LUMINANCE12_ALPHA4:
687 case GL_LUMINANCE12_ALPHA12:
688 case GL_LUMINANCE16_ALPHA16:
Brian Paul7d58f442001-04-04 21:54:20 +0000689 return &_mesa_texformat_luminance_alpha;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000690
691 case GL_INTENSITY:
692 case GL_INTENSITY4:
693 case GL_INTENSITY8:
694 case GL_INTENSITY12:
695 case GL_INTENSITY16:
Brian Paul7d58f442001-04-04 21:54:20 +0000696 return &_mesa_texformat_intensity;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000697
698 case GL_COLOR_INDEX:
699 case GL_COLOR_INDEX1_EXT:
700 case GL_COLOR_INDEX2_EXT:
701 case GL_COLOR_INDEX4_EXT:
702 case GL_COLOR_INDEX8_EXT:
703 case GL_COLOR_INDEX12_EXT:
704 case GL_COLOR_INDEX16_EXT:
Brian Paul7d58f442001-04-04 21:54:20 +0000705 return &_mesa_texformat_color_index;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000706
707 case GL_DEPTH_COMPONENT:
708 case GL_DEPTH_COMPONENT16_SGIX:
709 case GL_DEPTH_COMPONENT24_SGIX:
710 case GL_DEPTH_COMPONENT32_SGIX:
Brian Paule4276662001-06-15 14:18:46 +0000711 if (!ctx->Extensions.SGIX_depth_texture)
712 _mesa_problem(ctx, "depth format without GL_SGIX_depth_texture");
Brian Paul7d58f442001-04-04 21:54:20 +0000713 return &_mesa_texformat_depth_component;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000714
Brian Paule4276662001-06-15 14:18:46 +0000715 case GL_COMPRESSED_ALPHA_ARB:
716 if (!ctx->Extensions.ARB_texture_compression)
717 _mesa_problem(ctx, "texture compression extension not enabled");
718 return &_mesa_texformat_alpha;
719 case GL_COMPRESSED_LUMINANCE_ARB:
720 if (!ctx->Extensions.ARB_texture_compression)
721 _mesa_problem(ctx, "texture compression extension not enabled");
722 return &_mesa_texformat_luminance;
723 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
724 if (!ctx->Extensions.ARB_texture_compression)
725 _mesa_problem(ctx, "texture compression extension not enabled");
726 return &_mesa_texformat_luminance_alpha;
727 case GL_COMPRESSED_INTENSITY_ARB:
728 if (!ctx->Extensions.ARB_texture_compression)
729 _mesa_problem(ctx, "texture compression extension not enabled");
730 return &_mesa_texformat_intensity;
731 case GL_COMPRESSED_RGB_ARB:
732 if (!ctx->Extensions.ARB_texture_compression)
733 _mesa_problem(ctx, "texture compression extension not enabled");
734 return &_mesa_texformat_rgb;
735 case GL_COMPRESSED_RGBA_ARB:
736 if (!ctx->Extensions.ARB_texture_compression)
737 _mesa_problem(ctx, "texture compression extension not enabled");
738 return &_mesa_texformat_rgba;
739
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000740 default:
Brian Paule4276662001-06-15 14:18:46 +0000741 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
742 printf("intformat = %d %x\n", internalFormat, internalFormat);
Brian Paul7d58f442001-04-04 21:54:20 +0000743 return NULL;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000744 }
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000745}
Brian Paule4276662001-06-15 14:18:46 +0000746
747
748
749
750/*
751 * Return the base texture format for the given compressed format
752 * Called via ctx->Driver.BaseCompressedTexFormat().
753 * This function is used by software rasterizers. Hardware drivers
754 * which support texture compression should not use this function but
755 * a specialized function instead.
756 */
757GLint
758_mesa_base_compressed_texformat(GLcontext *ctx, GLint intFormat)
759{
760 switch (intFormat) {
761 case GL_COMPRESSED_ALPHA_ARB:
762 return GL_ALPHA;
763 case GL_COMPRESSED_LUMINANCE_ARB:
764 return GL_LUMINANCE;
765 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
766 return GL_LUMINANCE_ALPHA;
767 case GL_COMPRESSED_INTENSITY_ARB:
768 return GL_INTENSITY;
769 case GL_COMPRESSED_RGB_ARB:
770 return GL_RGB;
771 case GL_COMPRESSED_RGBA_ARB:
772 return GL_RGBA;
773 default:
774 return -1; /* not a recognized compressed format */
775 }
776}
777
778
779/*
780 * Called via ctx->Driver.CompressedTextureSize().
781 * This function is only used by software rasterizers.
782 * Hardware drivers will have to implement a specialized function.
783 */
784GLint
785_mesa_compressed_texture_size(GLcontext *ctx,
786 const struct gl_texture_image *texImage)
787{
788 GLint b;
789 assert(texImage);
790 assert(texImage->TexFormat);
791
792 b = texImage->Width * texImage->Height * texImage->Depth *
793 texImage->TexFormat->TexelBytes;
794 assert(b > 0);
795 return b;
796}