blob: b5c721f211d24dd4c4a3773faa8c3d0ce3e0ba56 [file] [log] [blame]
Keith Whitwell6dc85572003-07-17 13:43:59 +00001/**
2 * \file texformat.c
3 * Texture formats.
4 *
5 * \author Gareth Hughes
6 */
7
Gareth Hughes2c3d34c2001-03-18 08:53:49 +00008/*
9 * Mesa 3-D graphics library
Brian Paul27558a12003-03-01 01:50:20 +000010 * Version: 5.1
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000011 *
Brian Paul27558a12003-03-01 01:50:20 +000012 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000013 *
14 * Permission is hereby granted, free of charge, to any person obtaining a
15 * copy of this software and associated documentation files (the "Software"),
16 * to deal in the Software without restriction, including without limitation
17 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 * and/or sell copies of the Software, and to permit persons to whom the
19 * Software is furnished to do so, subject to the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be included
22 * in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
28 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000030 */
31
Keith Whitwell6dc85572003-07-17 13:43:59 +000032
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000033#include "glheader.h"
34#include "colormac.h"
35#include "context.h"
36#include "image.h"
Brian Paul3c634522002-10-24 23:57:19 +000037#include "imports.h"
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000038#include "mtypes.h"
39#include "texformat.h"
40#include "teximage.h"
41#include "texstate.h"
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000042
43
Keith Whitwell6dc85572003-07-17 13:43:59 +000044/* Texel fetch routines for all supported formats
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000045 */
46#define DIM 1
47#include "texformat_tmp.h"
48
49#define DIM 2
50#include "texformat_tmp.h"
51
52#define DIM 3
53#include "texformat_tmp.h"
54
Keith Whitwell6dc85572003-07-17 13:43:59 +000055/**
56 * Null texel fetch function.
57 *
58 * Have to have this so the FetchTexel function pointer is never NULL.
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000059 */
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
Keith Whitwell6dc85572003-07-17 13:43:59 +000071/***************************************************************/
72/** \name Default GLchan-based formats */
73/*@{*/
Gareth Hughes2c3d34c2001-03-18 08:53:49 +000074
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 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 Hughes2c3d34c2001-03-18 08:53:49 +000095 CHAN_BITS, /* RedBits */
96 CHAN_BITS, /* GreenBits */
97 CHAN_BITS, /* BlueBits */
98 0, /* AlphaBits */
99 0, /* LuminanceBits */
100 0, /* IntensityBits */
101 0, /* IndexBits */
102 0, /* DepthBits */
103 3 * CHAN_BITS / 8, /* TexelBytes */
104 fetch_1d_texel_rgb, /* FetchTexel1D */
105 fetch_2d_texel_rgb, /* FetchTexel2D */
106 fetch_3d_texel_rgb, /* FetchTexel3D */
107};
108
109const struct gl_texture_format _mesa_texformat_alpha = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000110 MESA_FORMAT_ALPHA, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000111 GL_ALPHA, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000112 0, /* RedBits */
113 0, /* GreenBits */
114 0, /* BlueBits */
115 CHAN_BITS, /* AlphaBits */
116 0, /* LuminanceBits */
117 0, /* IntensityBits */
118 0, /* IndexBits */
119 0, /* DepthBits */
120 CHAN_BITS / 8, /* TexelBytes */
121 fetch_1d_texel_alpha, /* FetchTexel1D */
122 fetch_2d_texel_alpha, /* FetchTexel2D */
123 fetch_3d_texel_alpha, /* FetchTexel3D */
124};
125
126const struct gl_texture_format _mesa_texformat_luminance = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000127 MESA_FORMAT_LUMINANCE, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000128 GL_LUMINANCE, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000129 0, /* RedBits */
130 0, /* GreenBits */
131 0, /* BlueBits */
132 0, /* AlphaBits */
133 CHAN_BITS, /* LuminanceBits */
134 0, /* IntensityBits */
135 0, /* IndexBits */
136 0, /* DepthBits */
137 CHAN_BITS / 8, /* TexelBytes */
138 fetch_1d_texel_luminance, /* FetchTexel1D */
139 fetch_2d_texel_luminance, /* FetchTexel2D */
140 fetch_3d_texel_luminance, /* FetchTexel3D */
141};
142
143const struct gl_texture_format _mesa_texformat_luminance_alpha = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000144 MESA_FORMAT_LUMINANCE_ALPHA, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000145 GL_LUMINANCE_ALPHA, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000146 0, /* RedBits */
147 0, /* GreenBits */
148 0, /* BlueBits */
149 CHAN_BITS, /* AlphaBits */
150 CHAN_BITS, /* LuminanceBits */
151 0, /* IntensityBits */
152 0, /* IndexBits */
153 0, /* DepthBits */
154 2 * CHAN_BITS / 8, /* TexelBytes */
155 fetch_1d_texel_luminance_alpha, /* FetchTexel1D */
156 fetch_2d_texel_luminance_alpha, /* FetchTexel2D */
157 fetch_3d_texel_luminance_alpha, /* FetchTexel3D */
158};
159
160const struct gl_texture_format _mesa_texformat_intensity = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000161 MESA_FORMAT_INTENSITY, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000162 GL_INTENSITY, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000163 0, /* RedBits */
164 0, /* GreenBits */
165 0, /* BlueBits */
166 0, /* AlphaBits */
167 0, /* LuminanceBits */
168 CHAN_BITS, /* IntensityBits */
169 0, /* IndexBits */
170 0, /* DepthBits */
171 CHAN_BITS / 8, /* TexelBytes */
172 fetch_1d_texel_intensity, /* FetchTexel1D */
173 fetch_2d_texel_intensity, /* FetchTexel2D */
174 fetch_3d_texel_intensity, /* FetchTexel3D */
175};
176
177const struct gl_texture_format _mesa_texformat_color_index = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000178 MESA_FORMAT_COLOR_INDEX, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000179 GL_COLOR_INDEX, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000180 0, /* RedBits */
181 0, /* GreenBits */
182 0, /* BlueBits */
183 0, /* AlphaBits */
184 0, /* LuminanceBits */
185 0, /* IntensityBits */
186 CHAN_BITS, /* IndexBits */
187 0, /* DepthBits */
188 CHAN_BITS / 8, /* TexelBytes */
189 fetch_1d_texel_color_index, /* FetchTexel1D */
190 fetch_2d_texel_color_index, /* FetchTexel2D */
191 fetch_3d_texel_color_index, /* FetchTexel3D */
192};
193
194const struct gl_texture_format _mesa_texformat_depth_component = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000195 MESA_FORMAT_DEPTH_COMPONENT, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000196 GL_DEPTH_COMPONENT, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000197 0, /* RedBits */
198 0, /* GreenBits */
199 0, /* BlueBits */
200 0, /* AlphaBits */
201 0, /* LuminanceBits */
202 0, /* IntensityBits */
203 0, /* IndexBits */
204 sizeof(GLfloat) * 8, /* DepthBits */
205 sizeof(GLfloat), /* TexelBytes */
206 fetch_1d_texel_depth_component, /* FetchTexel1D */
207 fetch_2d_texel_depth_component, /* FetchTexel2D */
208 fetch_3d_texel_depth_component, /* FetchTexel3D */
209};
210
Keith Whitwell6dc85572003-07-17 13:43:59 +0000211/*@}*/
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000212
Keith Whitwell6dc85572003-07-17 13:43:59 +0000213
214/***************************************************************/
215/** \name Hardware formats */
216/*@{*/
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000217
218const struct gl_texture_format _mesa_texformat_rgba8888 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000219 MESA_FORMAT_RGBA8888, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000220 GL_RGBA, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000221 8, /* RedBits */
222 8, /* GreenBits */
223 8, /* BlueBits */
224 8, /* AlphaBits */
225 0, /* LuminanceBits */
226 0, /* IntensityBits */
227 0, /* IndexBits */
228 0, /* DepthBits */
229 4, /* TexelBytes */
230 fetch_1d_texel_rgba8888, /* FetchTexel1D */
231 fetch_2d_texel_rgba8888, /* FetchTexel2D */
232 fetch_3d_texel_rgba8888, /* FetchTexel3D */
233};
234
235const struct gl_texture_format _mesa_texformat_argb8888 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000236 MESA_FORMAT_ARGB8888, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000237 GL_RGBA, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000238 8, /* RedBits */
239 8, /* GreenBits */
240 8, /* BlueBits */
241 8, /* AlphaBits */
242 0, /* LuminanceBits */
243 0, /* IntensityBits */
244 0, /* IndexBits */
245 0, /* DepthBits */
246 4, /* TexelBytes */
247 fetch_1d_texel_argb8888, /* FetchTexel1D */
248 fetch_2d_texel_argb8888, /* FetchTexel2D */
249 fetch_3d_texel_argb8888, /* FetchTexel3D */
250};
251
252const struct gl_texture_format _mesa_texformat_rgb888 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000253 MESA_FORMAT_RGB888, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000254 GL_RGB, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000255 8, /* RedBits */
256 8, /* GreenBits */
257 8, /* BlueBits */
258 0, /* AlphaBits */
259 0, /* LuminanceBits */
260 0, /* IntensityBits */
261 0, /* IndexBits */
262 0, /* DepthBits */
263 3, /* TexelBytes */
264 fetch_1d_texel_rgb888, /* FetchTexel1D */
265 fetch_2d_texel_rgb888, /* FetchTexel2D */
266 fetch_3d_texel_rgb888, /* FetchTexel3D */
267};
268
269const struct gl_texture_format _mesa_texformat_rgb565 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000270 MESA_FORMAT_RGB565, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000271 GL_RGB, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000272 5, /* RedBits */
273 6, /* GreenBits */
274 5, /* BlueBits */
275 0, /* AlphaBits */
276 0, /* LuminanceBits */
277 0, /* IntensityBits */
278 0, /* IndexBits */
279 0, /* DepthBits */
280 2, /* TexelBytes */
281 fetch_1d_texel_rgb565, /* FetchTexel1D */
282 fetch_2d_texel_rgb565, /* FetchTexel2D */
283 fetch_3d_texel_rgb565, /* FetchTexel3D */
284};
285
286const struct gl_texture_format _mesa_texformat_argb4444 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000287 MESA_FORMAT_ARGB4444, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000288 GL_RGBA, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000289 4, /* RedBits */
290 4, /* GreenBits */
291 4, /* BlueBits */
292 4, /* AlphaBits */
293 0, /* LuminanceBits */
294 0, /* IntensityBits */
295 0, /* IndexBits */
296 0, /* DepthBits */
297 2, /* TexelBytes */
298 fetch_1d_texel_argb4444, /* FetchTexel1D */
299 fetch_2d_texel_argb4444, /* FetchTexel2D */
300 fetch_3d_texel_argb4444, /* FetchTexel3D */
301};
302
303const struct gl_texture_format _mesa_texformat_argb1555 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000304 MESA_FORMAT_ARGB1555, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000305 GL_RGBA, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000306 5, /* RedBits */
307 5, /* GreenBits */
308 5, /* BlueBits */
309 1, /* AlphaBits */
310 0, /* LuminanceBits */
311 0, /* IntensityBits */
312 0, /* IndexBits */
313 0, /* DepthBits */
314 2, /* TexelBytes */
315 fetch_1d_texel_argb1555, /* FetchTexel1D */
316 fetch_2d_texel_argb1555, /* FetchTexel2D */
317 fetch_3d_texel_argb1555, /* FetchTexel3D */
318};
319
320const struct gl_texture_format _mesa_texformat_al88 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000321 MESA_FORMAT_AL88, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000322 GL_LUMINANCE_ALPHA, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000323 0, /* RedBits */
324 0, /* GreenBits */
325 0, /* BlueBits */
326 8, /* AlphaBits */
327 8, /* LuminanceBits */
328 0, /* IntensityBits */
329 0, /* IndexBits */
330 0, /* DepthBits */
331 2, /* TexelBytes */
332 fetch_1d_texel_al88, /* FetchTexel1D */
333 fetch_2d_texel_al88, /* FetchTexel2D */
334 fetch_3d_texel_al88, /* FetchTexel3D */
335};
336
337const struct gl_texture_format _mesa_texformat_rgb332 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000338 MESA_FORMAT_RGB332, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000339 GL_RGB, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000340 3, /* RedBits */
341 3, /* GreenBits */
342 2, /* BlueBits */
343 0, /* AlphaBits */
344 0, /* LuminanceBits */
345 0, /* IntensityBits */
346 0, /* IndexBits */
347 0, /* DepthBits */
348 1, /* TexelBytes */
349 fetch_1d_texel_rgb332, /* FetchTexel1D */
350 fetch_2d_texel_rgb332, /* FetchTexel2D */
351 fetch_3d_texel_rgb332, /* FetchTexel3D */
352};
353
354const struct gl_texture_format _mesa_texformat_a8 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000355 MESA_FORMAT_A8, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000356 GL_ALPHA, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000357 0, /* RedBits */
358 0, /* GreenBits */
359 0, /* BlueBits */
360 8, /* AlphaBits */
361 0, /* LuminanceBits */
362 0, /* IntensityBits */
363 0, /* IndexBits */
364 0, /* DepthBits */
365 1, /* TexelBytes */
366 fetch_1d_texel_a8, /* FetchTexel1D */
367 fetch_2d_texel_a8, /* FetchTexel2D */
368 fetch_3d_texel_a8, /* FetchTexel3D */
369};
370
371const struct gl_texture_format _mesa_texformat_l8 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000372 MESA_FORMAT_L8, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000373 GL_LUMINANCE, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000374 0, /* RedBits */
375 0, /* GreenBits */
376 0, /* BlueBits */
377 0, /* AlphaBits */
378 8, /* LuminanceBits */
379 0, /* IntensityBits */
380 0, /* IndexBits */
381 0, /* DepthBits */
382 1, /* TexelBytes */
383 fetch_1d_texel_l8, /* FetchTexel1D */
384 fetch_2d_texel_l8, /* FetchTexel2D */
385 fetch_3d_texel_l8, /* FetchTexel3D */
386};
387
388const struct gl_texture_format _mesa_texformat_i8 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000389 MESA_FORMAT_I8, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000390 GL_INTENSITY, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000391 0, /* RedBits */
392 0, /* GreenBits */
393 0, /* BlueBits */
394 0, /* AlphaBits */
395 0, /* LuminanceBits */
396 8, /* IntensityBits */
397 0, /* IndexBits */
398 0, /* DepthBits */
399 1, /* TexelBytes */
400 fetch_1d_texel_i8, /* FetchTexel1D */
401 fetch_2d_texel_i8, /* FetchTexel2D */
402 fetch_3d_texel_i8, /* FetchTexel3D */
403};
404
405const struct gl_texture_format _mesa_texformat_ci8 = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000406 MESA_FORMAT_CI8, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000407 GL_COLOR_INDEX, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000408 0, /* RedBits */
409 0, /* GreenBits */
410 0, /* BlueBits */
411 0, /* AlphaBits */
412 0, /* LuminanceBits */
413 0, /* IntensityBits */
414 8, /* IndexBits */
415 0, /* DepthBits */
416 1, /* TexelBytes */
417 fetch_1d_texel_ci8, /* FetchTexel1D */
418 fetch_2d_texel_ci8, /* FetchTexel2D */
419 fetch_3d_texel_ci8, /* FetchTexel3D */
420};
421
Brian Paulc5b99502002-09-21 16:51:25 +0000422const struct gl_texture_format _mesa_texformat_ycbcr = {
423 MESA_FORMAT_YCBCR, /* MesaFormat */
424 GL_YCBCR_MESA, /* BaseFormat */
Brian Paulc5b99502002-09-21 16:51:25 +0000425 0, /* RedBits */
426 0, /* GreenBits */
427 0, /* BlueBits */
428 0, /* AlphaBits */
429 0, /* LuminanceBits */
430 0, /* IntensityBits */
431 0, /* IndexBits */
432 0, /* DepthBits */
433 2, /* TexelBytes */
434 fetch_1d_texel_ycbcr, /* FetchTexel1D */
435 fetch_2d_texel_ycbcr, /* FetchTexel2D */
436 fetch_3d_texel_ycbcr, /* FetchTexel3D */
437};
438
Brian Paulc5b99502002-09-21 16:51:25 +0000439const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
440 MESA_FORMAT_YCBCR_REV, /* MesaFormat */
441 GL_YCBCR_MESA, /* BaseFormat */
Brian Paulc5b99502002-09-21 16:51:25 +0000442 0, /* RedBits */
443 0, /* GreenBits */
444 0, /* BlueBits */
445 0, /* AlphaBits */
446 0, /* LuminanceBits */
447 0, /* IntensityBits */
448 0, /* IndexBits */
449 0, /* DepthBits */
450 2, /* TexelBytes */
451 fetch_1d_texel_ycbcr_rev, /* FetchTexel1D */
452 fetch_2d_texel_ycbcr_rev, /* FetchTexel2D */
453 fetch_3d_texel_ycbcr_rev, /* FetchTexel3D */
454};
455
Brian Paul78233882003-04-03 20:57:49 +0000456const struct gl_texture_format _mesa_texformat_rgb_dxt1 = {
457 MESA_FORMAT_RGB_DXT1, /* MesaFormat */
458 GL_RGB, /* BaseFormat */
459 4, /*approx*/ /* RedBits */
460 4, /*approx*/ /* GreenBits */
461 4, /*approx*/ /* BlueBits */
462 0, /* AlphaBits */
463 0, /* LuminanceBits */
464 0, /* IntensityBits */
465 0, /* IndexBits */
466 0, /* DepthBits */
467 0, /* TexelBytes */
468 NULL, /*impossible*/ /* FetchTexel1D */
469 fetch_2d_texel_rgb_dxt1, /* FetchTexel2D */
470 NULL, /*impossible*/ /* FetchTexel3D */
471};
472
473const struct gl_texture_format _mesa_texformat_rgba_dxt1 = {
474 MESA_FORMAT_RGBA_DXT1, /* MesaFormat */
475 GL_RGBA, /* BaseFormat */
476 4, /*approx*/ /* RedBits */
477 4, /*approx*/ /* GreenBits */
478 4, /*approx*/ /* BlueBits */
479 1, /*approx*/ /* AlphaBits */
480 0, /* LuminanceBits */
481 0, /* IntensityBits */
482 0, /* IndexBits */
483 0, /* DepthBits */
484 0, /* TexelBytes */
485 NULL, /*impossible*/ /* FetchTexel1D */
486 fetch_2d_texel_rgba_dxt1, /* FetchTexel2D */
487 NULL, /*impossible*/ /* FetchTexel3D */
488};
489
490const struct gl_texture_format _mesa_texformat_rgba_dxt3 = {
491 MESA_FORMAT_RGBA_DXT3, /* MesaFormat */
492 GL_RGBA, /* BaseFormat */
493 4, /*approx*/ /* RedBits */
494 4, /*approx*/ /* GreenBits */
495 4, /*approx*/ /* BlueBits */
496 4, /*approx*/ /* AlphaBits */
497 0, /* LuminanceBits */
498 0, /* IntensityBits */
499 0, /* IndexBits */
500 0, /* DepthBits */
501 0, /* TexelBytes */
502 NULL, /*impossible*/ /* FetchTexel1D */
503 fetch_2d_texel_rgba_dxt3, /* FetchTexel2D */
504 NULL, /*impossible*/ /* FetchTexel3D */
505};
506
507const struct gl_texture_format _mesa_texformat_rgba_dxt5 = {
508 MESA_FORMAT_RGBA_DXT5, /* MesaFormat */
509 GL_RGBA, /* BaseFormat */
510 4,/*approx*/ /* RedBits */
511 4,/*approx*/ /* GreenBits */
512 4,/*approx*/ /* BlueBits */
513 4,/*approx*/ /* AlphaBits */
514 0, /* LuminanceBits */
515 0, /* IntensityBits */
516 0, /* IndexBits */
517 0, /* DepthBits */
518 0, /* TexelBytes */
519 NULL, /*impossible*/ /* FetchTexel1D */
520 fetch_2d_texel_rgba_dxt5, /* FetchTexel2D */
521 NULL, /*impossible*/ /* FetchTexel3D */
522};
523
Brian Paulc5b99502002-09-21 16:51:25 +0000524
Brian Paul4753d602002-06-15 02:38:15 +0000525/* Big-endian */
526#if 0
527const struct gl_texture_format _mesa_texformat_abgr8888 = {
528 MESA_FORMAT_ABGR8888, /* MesaFormat */
529 GL_RGBA, /* BaseFormat */
530 GL_UNSIGNED_INT_8_8_8_8, /* Type */
531 8, /* RedBits */
532 8, /* GreenBits */
533 8, /* BlueBits */
534 8, /* AlphaBits */
535 0, /* LuminanceBits */
536 0, /* IntensityBits */
537 0, /* IndexBits */
538 0, /* DepthBits */
539 4, /* TexelBytes */
540 fetch_1d_texel_abgr8888, /* FetchTexel1D */
541 fetch_2d_texel_abgr8888, /* FetchTexel2D */
542 fetch_3d_texel_abgr8888, /* FetchTexel3D */
543};
544
545const struct gl_texture_format _mesa_texformat_bgra8888 = {
546 MESA_FORMAT_BGRA8888, /* MesaFormat */
547 GL_RGBA, /* BaseFormat */
548 GL_UNSIGNED_INT_8_8_8_8, /* Type */
549 8, /* RedBits */
550 8, /* GreenBits */
551 8, /* BlueBits */
552 8, /* AlphaBits */
553 0, /* LuminanceBits */
554 0, /* IntensityBits */
555 0, /* IndexBits */
556 0, /* DepthBits */
557 4, /* TexelBytes */
558 fetch_1d_texel_bgra8888, /* FetchTexel1D */
559 fetch_2d_texel_bgra8888, /* FetchTexel2D */
560 fetch_3d_texel_bgra8888, /* FetchTexel3D */
561};
562
563const struct gl_texture_format _mesa_texformat_bgr888 = {
564 MESA_FORMAT_BGR888, /* MesaFormat */
565 GL_RGB, /* BaseFormat */
566 GL_UNSIGNED_BYTE, /* Type */
567 8, /* RedBits */
568 8, /* GreenBits */
569 8, /* BlueBits */
570 0, /* AlphaBits */
571 0, /* LuminanceBits */
572 0, /* IntensityBits */
573 0, /* IndexBits */
574 0, /* DepthBits */
575 3, /* TexelBytes */
576 fetch_1d_texel_bgr888, /* FetchTexel1D */
577 fetch_2d_texel_bgr888, /* FetchTexel2D */
578 fetch_3d_texel_bgr888, /* FetchTexel3D */
579};
580
581const struct gl_texture_format _mesa_texformat_bgr565 = {
582 MESA_FORMAT_BGR565, /* MesaFormat */
583 GL_RGB, /* BaseFormat */
584 GL_UNSIGNED_SHORT_5_6_5, /* Type */
585 5, /* RedBits */
586 6, /* GreenBits */
587 5, /* BlueBits */
588 0, /* AlphaBits */
589 0, /* LuminanceBits */
590 0, /* IntensityBits */
591 0, /* IndexBits */
592 0, /* DepthBits */
593 2, /* TexelBytes */
594 fetch_1d_texel_bgr565, /* FetchTexel1D */
595 fetch_2d_texel_bgr565, /* FetchTexel2D */
596 fetch_3d_texel_bgr565, /* FetchTexel3D */
597};
598
599const struct gl_texture_format _mesa_texformat_bgra4444 = {
600 MESA_FORMAT_BGRA4444, /* MesaFormat */
601 GL_RGBA, /* BaseFormat */
602 GL_UNSIGNED_SHORT_4_4_4_4_REV, /* Type */
603 4, /* RedBits */
604 4, /* GreenBits */
605 4, /* BlueBits */
606 4, /* AlphaBits */
607 0, /* LuminanceBits */
608 0, /* IntensityBits */
609 0, /* IndexBits */
610 0, /* DepthBits */
611 2, /* TexelBytes */
612 fetch_1d_texel_bgra4444, /* FetchTexel1D */
613 fetch_2d_texel_bgra4444, /* FetchTexel2D */
614 fetch_3d_texel_bgra4444, /* FetchTexel3D */
615};
616
617const struct gl_texture_format _mesa_texformat_bgra5551 = {
618 MESA_FORMAT_BGRA5551, /* MesaFormat */
619 GL_RGBA, /* BaseFormat */
620 GL_UNSIGNED_SHORT_1_5_5_5_REV, /* Type */
621 5, /* RedBits */
622 5, /* GreenBits */
623 5, /* BlueBits */
624 1, /* AlphaBits */
625 0, /* LuminanceBits */
626 0, /* IntensityBits */
627 0, /* IndexBits */
628 0, /* DepthBits */
629 2, /* TexelBytes */
630 fetch_1d_texel_bgra1555, /* FetchTexel1D */
631 fetch_2d_texel_bgra1555, /* FetchTexel2D */
632 fetch_3d_texel_bgra1555, /* FetchTexel3D */
633};
634
635const struct gl_texture_format _mesa_texformat_la88 = {
636 MESA_FORMAT_LA88, /* MesaFormat */
637 GL_LUMINANCE_ALPHA, /* BaseFormat */
638 GL_UNSIGNED_BYTE, /* Type */
639 0, /* RedBits */
640 0, /* GreenBits */
641 0, /* BlueBits */
642 8, /* AlphaBits */
643 8, /* LuminanceBits */
644 0, /* IntensityBits */
645 0, /* IndexBits */
646 0, /* DepthBits */
647 2, /* TexelBytes */
648 fetch_1d_texel_la88, /* FetchTexel1D */
649 fetch_2d_texel_la88, /* FetchTexel2D */
650 fetch_3d_texel_la88, /* FetchTexel3D */
651};
652
653const struct gl_texture_format _mesa_texformat_bgr233 = {
654 MESA_FORMAT_BGR233, /* MesaFormat */
655 GL_RGB, /* BaseFormat */
656 GL_UNSIGNED_BYTE_3_3_2, /* Type */
657 3, /* RedBits */
658 3, /* GreenBits */
659 2, /* BlueBits */
660 0, /* AlphaBits */
661 0, /* LuminanceBits */
662 0, /* IntensityBits */
663 0, /* IndexBits */
664 0, /* DepthBits */
665 1, /* TexelBytes */
666 fetch_1d_texel_bgr233, /* FetchTexel1D */
667 fetch_2d_texel_bgr233, /* FetchTexel2D */
668 fetch_3d_texel_bgr233, /* FetchTexel3D */
669};
670#endif
671
Keith Whitwell6dc85572003-07-17 13:43:59 +0000672/*@}*/
673
674
675/***************************************************************/
676/** \name Null format (useful for proxy textures) */
677/*@{*/
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000678
679const struct gl_texture_format _mesa_null_texformat = {
Gareth Hughes38f28662001-03-28 20:40:51 +0000680 -1, /* MesaFormat */
Brian Paul1c85aa32001-04-20 16:46:04 +0000681 0, /* BaseFormat */
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000682 0, /* RedBits */
683 0, /* GreenBits */
684 0, /* BlueBits */
685 0, /* AlphaBits */
686 0, /* LuminanceBits */
687 0, /* IntensityBits */
688 0, /* IndexBits */
689 0, /* DepthBits */
690 0, /* TexelBytes */
691 fetch_null_texel, /* FetchTexel1D */
692 fetch_null_texel, /* FetchTexel2D */
693 fetch_null_texel, /* FetchTexel3D */
694};
695
Keith Whitwell6dc85572003-07-17 13:43:59 +0000696/*@}*/
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000697
Keith Whitwell6dc85572003-07-17 13:43:59 +0000698
699/**
700 * Determine whether a given texture format is a hardware texture
701 * format.
702 *
703 * \param format texture format.
704 *
705 * \return GL_TRUE if \p format is a hardware texture format, or GL_FALSE
706 * otherwise.
707 *
708 * \p format is a hardware texture format if gl_texture_format::MesaFormat is
709 * lower than _format::MESA_FORMAT_RGBA.
710 */
Brian Paul7d58f442001-04-04 21:54:20 +0000711GLboolean
712_mesa_is_hardware_tex_format( const struct gl_texture_format *format )
713{
714 return (format->MesaFormat < MESA_FORMAT_RGBA);
715}
716
717
Keith Whitwell6dc85572003-07-17 13:43:59 +0000718/**
719 * Choose an appropriate texture format.
720 *
721 * \param ctx GL context.
722 * \param internalFormat internal texture format.
723 * \param format pixel format.
724 * \param type data type.
725 *
726 * \return a pointer to a gl_texture_format in which to store the texture on
727 * success, or NULL on failure.
728 *
729 * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
730 * typically override this function with a specialized version.
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000731 */
Brian Paul7d58f442001-04-04 21:54:20 +0000732const struct gl_texture_format *
733_mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
734 GLenum format, GLenum type )
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000735{
Brian Paul7d58f442001-04-04 21:54:20 +0000736 (void) format;
737 (void) type;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000738
739 switch ( internalFormat ) {
740 /* GH: Bias towards GL_RGB, GL_RGBA texture formats. This has
741 * got to be better than sticking them way down the end of this
742 * huge list.
743 */
744 case 4: /* Quake3 uses this... */
745 case GL_RGBA:
Brian Paul7d58f442001-04-04 21:54:20 +0000746 return &_mesa_texformat_rgba;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000747
748 case 3: /* ... and this. */
749 case GL_RGB:
Brian Paul7d58f442001-04-04 21:54:20 +0000750 return &_mesa_texformat_rgb;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000751
752 /* GH: Okay, keep checking as normal. Still test for GL_RGB,
753 * GL_RGBA formats first.
754 */
755 case GL_RGBA2:
756 case GL_RGBA4:
757 case GL_RGB5_A1:
758 case GL_RGBA8:
759 case GL_RGB10_A2:
760 case GL_RGBA12:
761 case GL_RGBA16:
Brian Paul7d58f442001-04-04 21:54:20 +0000762 return &_mesa_texformat_rgba;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000763
764 case GL_R3_G3_B2:
765 case GL_RGB4:
766 case GL_RGB5:
767 case GL_RGB8:
768 case GL_RGB10:
769 case GL_RGB12:
770 case GL_RGB16:
Brian Paul7d58f442001-04-04 21:54:20 +0000771 return &_mesa_texformat_rgb;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000772
773 case GL_ALPHA:
774 case GL_ALPHA4:
775 case GL_ALPHA8:
776 case GL_ALPHA12:
777 case GL_ALPHA16:
Brian Paul7d58f442001-04-04 21:54:20 +0000778 return &_mesa_texformat_alpha;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000779
780 case 1:
781 case GL_LUMINANCE:
782 case GL_LUMINANCE4:
783 case GL_LUMINANCE8:
784 case GL_LUMINANCE12:
785 case GL_LUMINANCE16:
Brian Paul7d58f442001-04-04 21:54:20 +0000786 return &_mesa_texformat_luminance;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000787
788 case 2:
789 case GL_LUMINANCE_ALPHA:
790 case GL_LUMINANCE4_ALPHA4:
791 case GL_LUMINANCE6_ALPHA2:
792 case GL_LUMINANCE8_ALPHA8:
793 case GL_LUMINANCE12_ALPHA4:
794 case GL_LUMINANCE12_ALPHA12:
795 case GL_LUMINANCE16_ALPHA16:
Brian Paul7d58f442001-04-04 21:54:20 +0000796 return &_mesa_texformat_luminance_alpha;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000797
798 case GL_INTENSITY:
799 case GL_INTENSITY4:
800 case GL_INTENSITY8:
801 case GL_INTENSITY12:
802 case GL_INTENSITY16:
Brian Paul7d58f442001-04-04 21:54:20 +0000803 return &_mesa_texformat_intensity;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000804
805 case GL_COLOR_INDEX:
806 case GL_COLOR_INDEX1_EXT:
807 case GL_COLOR_INDEX2_EXT:
808 case GL_COLOR_INDEX4_EXT:
809 case GL_COLOR_INDEX8_EXT:
810 case GL_COLOR_INDEX12_EXT:
811 case GL_COLOR_INDEX16_EXT:
Brian Paul7d58f442001-04-04 21:54:20 +0000812 return &_mesa_texformat_color_index;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000813
814 case GL_DEPTH_COMPONENT:
815 case GL_DEPTH_COMPONENT16_SGIX:
816 case GL_DEPTH_COMPONENT24_SGIX:
817 case GL_DEPTH_COMPONENT32_SGIX:
Brian Paule4276662001-06-15 14:18:46 +0000818 if (!ctx->Extensions.SGIX_depth_texture)
819 _mesa_problem(ctx, "depth format without GL_SGIX_depth_texture");
Brian Paul7d58f442001-04-04 21:54:20 +0000820 return &_mesa_texformat_depth_component;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000821
Brian Paule4276662001-06-15 14:18:46 +0000822 case GL_COMPRESSED_ALPHA_ARB:
823 if (!ctx->Extensions.ARB_texture_compression)
824 _mesa_problem(ctx, "texture compression extension not enabled");
825 return &_mesa_texformat_alpha;
826 case GL_COMPRESSED_LUMINANCE_ARB:
827 if (!ctx->Extensions.ARB_texture_compression)
828 _mesa_problem(ctx, "texture compression extension not enabled");
829 return &_mesa_texformat_luminance;
830 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
831 if (!ctx->Extensions.ARB_texture_compression)
832 _mesa_problem(ctx, "texture compression extension not enabled");
833 return &_mesa_texformat_luminance_alpha;
834 case GL_COMPRESSED_INTENSITY_ARB:
835 if (!ctx->Extensions.ARB_texture_compression)
836 _mesa_problem(ctx, "texture compression extension not enabled");
837 return &_mesa_texformat_intensity;
838 case GL_COMPRESSED_RGB_ARB:
839 if (!ctx->Extensions.ARB_texture_compression)
840 _mesa_problem(ctx, "texture compression extension not enabled");
Brian Paul78233882003-04-03 20:57:49 +0000841 if (ctx->Extensions.EXT_texture_compression_s3tc)
842 return &_mesa_texformat_rgb_dxt1;
Brian Paule4276662001-06-15 14:18:46 +0000843 return &_mesa_texformat_rgb;
844 case GL_COMPRESSED_RGBA_ARB:
845 if (!ctx->Extensions.ARB_texture_compression)
846 _mesa_problem(ctx, "texture compression extension not enabled");
Brian Paul78233882003-04-03 20:57:49 +0000847 if (ctx->Extensions.EXT_texture_compression_s3tc)
848 return &_mesa_texformat_rgba_dxt3; /* Not rgba_dxt1! See the spec */
Brian Paule4276662001-06-15 14:18:46 +0000849 return &_mesa_texformat_rgba;
850
Brian Paul89fb06f2002-09-27 02:45:37 +0000851 /* GL_MESA_ycrcr_texture */
Brian Paulc5b99502002-09-21 16:51:25 +0000852 case GL_YCBCR_MESA:
853 if (type == GL_UNSIGNED_SHORT_8_8_MESA)
854 return &_mesa_texformat_ycbcr;
855 else
856 return &_mesa_texformat_ycbcr_rev;
857
Brian Paul78233882003-04-03 20:57:49 +0000858 /* GL_EXT_texture_compression_s3tc */
859 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
860 if (ctx->Extensions.EXT_texture_compression_s3tc)
861 return &_mesa_texformat_rgb_dxt1;
862 else
863 return NULL;
864 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
865 if (ctx->Extensions.EXT_texture_compression_s3tc)
866 return &_mesa_texformat_rgba_dxt1;
867 else
868 return NULL;
869 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
870 if (ctx->Extensions.EXT_texture_compression_s3tc)
871 return &_mesa_texformat_rgba_dxt3;
872 else
873 return NULL;
874 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
875 if (ctx->Extensions.EXT_texture_compression_s3tc)
876 return &_mesa_texformat_rgba_dxt5;
877 else
878 return NULL;
879
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000880 default:
Brian Paule4276662001-06-15 14:18:46 +0000881 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
Brian Paul7d58f442001-04-04 21:54:20 +0000882 return NULL;
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000883 }
Gareth Hughes2c3d34c2001-03-18 08:53:49 +0000884}
Brian Paule4276662001-06-15 14:18:46 +0000885
886
Keith Whitwell6dc85572003-07-17 13:43:59 +0000887/**
Brian Paule4276662001-06-15 14:18:46 +0000888 * Return the base texture format for the given compressed format
Keith Whitwell6dc85572003-07-17 13:43:59 +0000889 *
890 * Called via dd_function_table::Driver.BaseCompressedTexFormat.
Brian Paule4276662001-06-15 14:18:46 +0000891 * This function is used by software rasterizers. Hardware drivers
892 * which support texture compression should not use this function but
893 * a specialized function instead.
894 */
895GLint
896_mesa_base_compressed_texformat(GLcontext *ctx, GLint intFormat)
897{
898 switch (intFormat) {
899 case GL_COMPRESSED_ALPHA_ARB:
900 return GL_ALPHA;
901 case GL_COMPRESSED_LUMINANCE_ARB:
902 return GL_LUMINANCE;
903 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
904 return GL_LUMINANCE_ALPHA;
905 case GL_COMPRESSED_INTENSITY_ARB:
906 return GL_INTENSITY;
907 case GL_COMPRESSED_RGB_ARB:
908 return GL_RGB;
909 case GL_COMPRESSED_RGBA_ARB:
910 return GL_RGBA;
911 default:
912 return -1; /* not a recognized compressed format */
913 }
914}