blob: b75a787862fa3f5f75e0f26c2c98e3bfe72c499f [file] [log] [blame]
Brian Paule4276662001-06-15 14:18:46 +00001/* $Id: texformat.c,v 1.11 2001/06/15 14:18:46 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
Gareth Hughes5e23af22001-03-30 14:44:43 +0000441/* =============================================================
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000442 * Null format:
443 */
444
445const struct gl_texture_format _mesa_null_texformat = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000446 -1, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000447 0, /* BaseFormat */
Gareth Hughes38f28662001-03-28 20:40:51 +0000448 0, /* Type */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000449 0, /* RedBits */
450 0, /* GreenBits */
451 0, /* BlueBits */
452 0, /* AlphaBits */
453 0, /* LuminanceBits */
454 0, /* IntensityBits */
455 0, /* IndexBits */
456 0, /* DepthBits */
457 0, /* TexelBytes */
458 fetch_null_texel, /* FetchTexel1D */
459 fetch_null_texel, /* FetchTexel2D */
460 fetch_null_texel, /* FetchTexel3D */
461};
462
463
464
Brian Paul7d58f442001-04-04 21:54:20 +0000465GLboolean
466_mesa_is_hardware_tex_format( const struct gl_texture_format *format )
467{
468 return (format->MesaFormat < MESA_FORMAT_RGBA);
469}
470
471
Brian Paule4276662001-06-15 14:18:46 +0000472/* Given an internal texture format (or 1, 2, 3, 4) return a pointer
473 * to a gl_texture_format which which to store the texture.
474 * This is called via ctx->Driver.ChooseTextureFormat().
475 * Hardware drivers should not use this function, but instead a
476 * specialized function.
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000477 */
Brian Paul7d58f442001-04-04 21:54:20 +0000478const struct gl_texture_format *
479_mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
480 GLenum format, GLenum type )
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000481{
Brian Paul7d58f442001-04-04 21:54:20 +0000482 (void) format;
483 (void) type;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000484
485 switch ( internalFormat ) {
486 /* GH: Bias towards GL_RGB, GL_RGBA texture formats. This has
487 * got to be better than sticking them way down the end of this
488 * huge list.
489 */
490 case 4: /* Quake3 uses this... */
491 case GL_RGBA:
Brian Paul7d58f442001-04-04 21:54:20 +0000492 return &_mesa_texformat_rgba;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000493
494 case 3: /* ... and this. */
495 case GL_RGB:
Brian Paul7d58f442001-04-04 21:54:20 +0000496 return &_mesa_texformat_rgb;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000497
498 /* GH: Okay, keep checking as normal. Still test for GL_RGB,
499 * GL_RGBA formats first.
500 */
501 case GL_RGBA2:
502 case GL_RGBA4:
503 case GL_RGB5_A1:
504 case GL_RGBA8:
505 case GL_RGB10_A2:
506 case GL_RGBA12:
507 case GL_RGBA16:
Brian Paul7d58f442001-04-04 21:54:20 +0000508 return &_mesa_texformat_rgba;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000509
510 case GL_R3_G3_B2:
511 case GL_RGB4:
512 case GL_RGB5:
513 case GL_RGB8:
514 case GL_RGB10:
515 case GL_RGB12:
516 case GL_RGB16:
Brian Paul7d58f442001-04-04 21:54:20 +0000517 return &_mesa_texformat_rgb;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000518
519 case GL_ALPHA:
520 case GL_ALPHA4:
521 case GL_ALPHA8:
522 case GL_ALPHA12:
523 case GL_ALPHA16:
Brian Paul7d58f442001-04-04 21:54:20 +0000524 return &_mesa_texformat_alpha;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000525
526 case 1:
527 case GL_LUMINANCE:
528 case GL_LUMINANCE4:
529 case GL_LUMINANCE8:
530 case GL_LUMINANCE12:
531 case GL_LUMINANCE16:
Brian Paul7d58f442001-04-04 21:54:20 +0000532 return &_mesa_texformat_luminance;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000533
534 case 2:
535 case GL_LUMINANCE_ALPHA:
536 case GL_LUMINANCE4_ALPHA4:
537 case GL_LUMINANCE6_ALPHA2:
538 case GL_LUMINANCE8_ALPHA8:
539 case GL_LUMINANCE12_ALPHA4:
540 case GL_LUMINANCE12_ALPHA12:
541 case GL_LUMINANCE16_ALPHA16:
Brian Paul7d58f442001-04-04 21:54:20 +0000542 return &_mesa_texformat_luminance_alpha;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000543
544 case GL_INTENSITY:
545 case GL_INTENSITY4:
546 case GL_INTENSITY8:
547 case GL_INTENSITY12:
548 case GL_INTENSITY16:
Brian Paul7d58f442001-04-04 21:54:20 +0000549 return &_mesa_texformat_intensity;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000550
551 case GL_COLOR_INDEX:
552 case GL_COLOR_INDEX1_EXT:
553 case GL_COLOR_INDEX2_EXT:
554 case GL_COLOR_INDEX4_EXT:
555 case GL_COLOR_INDEX8_EXT:
556 case GL_COLOR_INDEX12_EXT:
557 case GL_COLOR_INDEX16_EXT:
Brian Paul7d58f442001-04-04 21:54:20 +0000558 return &_mesa_texformat_color_index;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000559
560 case GL_DEPTH_COMPONENT:
561 case GL_DEPTH_COMPONENT16_SGIX:
562 case GL_DEPTH_COMPONENT24_SGIX:
563 case GL_DEPTH_COMPONENT32_SGIX:
Brian Paule4276662001-06-15 14:18:46 +0000564 if (!ctx->Extensions.SGIX_depth_texture)
565 _mesa_problem(ctx, "depth format without GL_SGIX_depth_texture");
Brian Paul7d58f442001-04-04 21:54:20 +0000566 return &_mesa_texformat_depth_component;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000567
Brian Paule4276662001-06-15 14:18:46 +0000568 case GL_COMPRESSED_ALPHA_ARB:
569 if (!ctx->Extensions.ARB_texture_compression)
570 _mesa_problem(ctx, "texture compression extension not enabled");
571 return &_mesa_texformat_alpha;
572 case GL_COMPRESSED_LUMINANCE_ARB:
573 if (!ctx->Extensions.ARB_texture_compression)
574 _mesa_problem(ctx, "texture compression extension not enabled");
575 return &_mesa_texformat_luminance;
576 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
577 if (!ctx->Extensions.ARB_texture_compression)
578 _mesa_problem(ctx, "texture compression extension not enabled");
579 return &_mesa_texformat_luminance_alpha;
580 case GL_COMPRESSED_INTENSITY_ARB:
581 if (!ctx->Extensions.ARB_texture_compression)
582 _mesa_problem(ctx, "texture compression extension not enabled");
583 return &_mesa_texformat_intensity;
584 case GL_COMPRESSED_RGB_ARB:
585 if (!ctx->Extensions.ARB_texture_compression)
586 _mesa_problem(ctx, "texture compression extension not enabled");
587 return &_mesa_texformat_rgb;
588 case GL_COMPRESSED_RGBA_ARB:
589 if (!ctx->Extensions.ARB_texture_compression)
590 _mesa_problem(ctx, "texture compression extension not enabled");
591 return &_mesa_texformat_rgba;
592
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000593 default:
Brian Paule4276662001-06-15 14:18:46 +0000594 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
595 printf("intformat = %d %x\n", internalFormat, internalFormat);
Brian Paul7d58f442001-04-04 21:54:20 +0000596 return NULL;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000597 }
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000598}
Brian Paule4276662001-06-15 14:18:46 +0000599
600
601
602
603/*
604 * Return the base texture format for the given compressed format
605 * Called via ctx->Driver.BaseCompressedTexFormat().
606 * This function is used by software rasterizers. Hardware drivers
607 * which support texture compression should not use this function but
608 * a specialized function instead.
609 */
610GLint
611_mesa_base_compressed_texformat(GLcontext *ctx, GLint intFormat)
612{
613 switch (intFormat) {
614 case GL_COMPRESSED_ALPHA_ARB:
615 return GL_ALPHA;
616 case GL_COMPRESSED_LUMINANCE_ARB:
617 return GL_LUMINANCE;
618 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
619 return GL_LUMINANCE_ALPHA;
620 case GL_COMPRESSED_INTENSITY_ARB:
621 return GL_INTENSITY;
622 case GL_COMPRESSED_RGB_ARB:
623 return GL_RGB;
624 case GL_COMPRESSED_RGBA_ARB:
625 return GL_RGBA;
626 default:
627 return -1; /* not a recognized compressed format */
628 }
629}
630
631
632/*
633 * Called via ctx->Driver.CompressedTextureSize().
634 * This function is only used by software rasterizers.
635 * Hardware drivers will have to implement a specialized function.
636 */
637GLint
638_mesa_compressed_texture_size(GLcontext *ctx,
639 const struct gl_texture_image *texImage)
640{
641 GLint b;
642 assert(texImage);
643 assert(texImage->TexFormat);
644
645 b = texImage->Width * texImage->Height * texImage->Depth *
646 texImage->TexFormat->TexelBytes;
647 assert(b > 0);
648 return b;
649}