texformat.c revision defb035b6cf03c555318d9dd48864242ed036f39
1/*
2 * Mesa 3-D graphics library
3 * Version:  6.1
4 *
5 * Copyright (C) 1999-2004  Brian Paul   All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26/**
27 * \file texformat.c
28 * Texture formats.
29 *
30 * \author Gareth Hughes
31 */
32
33
34#include "glheader.h"
35#include "colormac.h"
36#include "context.h"
37#include "image.h"
38#include "imports.h"
39#include "mtypes.h"
40#include "texformat.h"
41#include "teximage.h"
42#include "texstate.h"
43#include "texstore.h"
44
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/**
59 * Null texel fetch function.
60 *
61 * Have to have this so the FetchTexel function pointer is never NULL.
62 */
63static void fetch_null_texel( const struct gl_texture_image *texImage,
64			      GLint i, GLint j, GLint k, GLchan *texel )
65{
66   texel[RCOMP] = 0;
67   texel[GCOMP] = 0;
68   texel[BCOMP] = 0;
69   texel[ACOMP] = 0;
70   _mesa_warning(NULL, "fetch_null_texel() called!");
71}
72
73static void fetch_null_texelf( const struct gl_texture_image *texImage,
74                               GLint i, GLint j, GLint k, GLfloat *texel )
75{
76   texel[RCOMP] = 0.0;
77   texel[GCOMP] = 0.0;
78   texel[BCOMP] = 0.0;
79   texel[ACOMP] = 0.0;
80   _mesa_warning(NULL, "fetch_null_texelf() called!");
81}
82
83
84/***************************************************************/
85/** \name Default GLchan-based formats */
86/*@{*/
87
88const struct gl_texture_format _mesa_texformat_rgba = {
89   MESA_FORMAT_RGBA,			/* MesaFormat */
90   GL_RGBA,				/* BaseFormat */
91   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
92   CHAN_BITS,				/* RedBits */
93   CHAN_BITS,				/* GreenBits */
94   CHAN_BITS,				/* BlueBits */
95   CHAN_BITS,				/* AlphaBits */
96   0,					/* LuminanceBits */
97   0,					/* IntensityBits */
98   0,					/* IndexBits */
99   0,					/* DepthBits */
100   4 * sizeof(GLchan),			/* TexelBytes */
101   _mesa_texstore_rgba,			/* StoreTexImageFunc */
102   fetch_texel_1d_rgba,			/* FetchTexel1D */
103   fetch_texel_2d_rgba,			/* FetchTexel2D */
104   fetch_texel_3d_rgba,			/* FetchTexel3D */
105   fetch_texel_1d_f_rgba,		/* FetchTexel1Df */
106   fetch_texel_2d_f_rgba,		/* FetchTexel2Df */
107   fetch_texel_3d_f_rgba,		/* FetchTexel3Df */
108};
109
110const struct gl_texture_format _mesa_texformat_rgb = {
111   MESA_FORMAT_RGB,			/* MesaFormat */
112   GL_RGB,				/* BaseFormat */
113   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
114   CHAN_BITS,				/* RedBits */
115   CHAN_BITS,				/* GreenBits */
116   CHAN_BITS,				/* BlueBits */
117   0,					/* AlphaBits */
118   0,					/* LuminanceBits */
119   0,					/* IntensityBits */
120   0,					/* IndexBits */
121   0,					/* DepthBits */
122   3 * sizeof(GLchan),			/* TexelBytes */
123   _mesa_texstore_rgba,/*yes*/		/* StoreTexImageFunc */
124   fetch_texel_1d_rgb,			/* FetchTexel1D */
125   fetch_texel_2d_rgb,			/* FetchTexel2D */
126   fetch_texel_3d_rgb,			/* FetchTexel3D */
127   fetch_texel_1d_f_rgb,		/* FetchTexel1Df */
128   fetch_texel_2d_f_rgb,		/* FetchTexel2Df */
129   fetch_texel_3d_f_rgb,		/* FetchTexel3Df */
130};
131
132const struct gl_texture_format _mesa_texformat_alpha = {
133   MESA_FORMAT_ALPHA,			/* MesaFormat */
134   GL_ALPHA,				/* BaseFormat */
135   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
136   0,					/* RedBits */
137   0,					/* GreenBits */
138   0,					/* BlueBits */
139   CHAN_BITS,				/* AlphaBits */
140   0,					/* LuminanceBits */
141   0,					/* IntensityBits */
142   0,					/* IndexBits */
143   0,					/* DepthBits */
144   sizeof(GLchan),			/* TexelBytes */
145   _mesa_texstore_rgba,/*yes*/		/* StoreTexImageFunc */
146   fetch_texel_1d_alpha,		/* FetchTexel1D */
147   fetch_texel_2d_alpha,		/* FetchTexel2D */
148   fetch_texel_3d_alpha,		/* FetchTexel3D */
149   fetch_texel_1d_f_alpha,		/* FetchTexel1Df */
150   fetch_texel_2d_f_alpha,		/* FetchTexel2Df */
151   fetch_texel_3d_f_alpha,		/* FetchTexel3Df */
152};
153
154const struct gl_texture_format _mesa_texformat_luminance = {
155   MESA_FORMAT_LUMINANCE,		/* MesaFormat */
156   GL_LUMINANCE,			/* BaseFormat */
157   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
158   0,					/* RedBits */
159   0,					/* GreenBits */
160   0,					/* BlueBits */
161   0,					/* AlphaBits */
162   CHAN_BITS,				/* LuminanceBits */
163   0,					/* IntensityBits */
164   0,					/* IndexBits */
165   0,					/* DepthBits */
166   sizeof(GLchan),			/* TexelBytes */
167   _mesa_texstore_rgba,/*yes*/		/* StoreTexImageFunc */
168   fetch_texel_1d_luminance,		/* FetchTexel1D */
169   fetch_texel_2d_luminance,		/* FetchTexel2D */
170   fetch_texel_3d_luminance,		/* FetchTexel3D */
171   fetch_texel_1d_f_luminance,		/* FetchTexel1Df */
172   fetch_texel_2d_f_luminance,		/* FetchTexel2Df */
173   fetch_texel_3d_f_luminance,		/* FetchTexel3Df */
174};
175
176const struct gl_texture_format _mesa_texformat_luminance_alpha = {
177   MESA_FORMAT_LUMINANCE_ALPHA,		/* MesaFormat */
178   GL_LUMINANCE_ALPHA,			/* BaseFormat */
179   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
180   0,					/* RedBits */
181   0,					/* GreenBits */
182   0,					/* BlueBits */
183   CHAN_BITS,				/* AlphaBits */
184   CHAN_BITS,				/* LuminanceBits */
185   0,					/* IntensityBits */
186   0,					/* IndexBits */
187   0,					/* DepthBits */
188   2 * sizeof(GLchan),			/* TexelBytes */
189   _mesa_texstore_rgba,/*yes*/		/* StoreTexImageFunc */
190   fetch_texel_1d_luminance_alpha,	/* FetchTexel1D */
191   fetch_texel_2d_luminance_alpha,	/* FetchTexel2D */
192   fetch_texel_3d_luminance_alpha,	/* FetchTexel3D */
193   fetch_texel_1d_f_luminance_alpha,	/* FetchTexel1Df */
194   fetch_texel_2d_f_luminance_alpha,	/* FetchTexel2Df */
195   fetch_texel_3d_f_luminance_alpha,	/* FetchTexel3Df */
196};
197
198const struct gl_texture_format _mesa_texformat_intensity = {
199   MESA_FORMAT_INTENSITY,		/* MesaFormat */
200   GL_INTENSITY,			/* BaseFormat */
201   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
202   0,					/* RedBits */
203   0,					/* GreenBits */
204   0,					/* BlueBits */
205   0,					/* AlphaBits */
206   0,					/* LuminanceBits */
207   CHAN_BITS,				/* IntensityBits */
208   0,					/* IndexBits */
209   0,					/* DepthBits */
210   sizeof(GLchan),			/* TexelBytes */
211   _mesa_texstore_rgba,/*yes*/		/* StoreTexImageFunc */
212   fetch_texel_1d_intensity,		/* FetchTexel1D */
213   fetch_texel_2d_intensity,		/* FetchTexel2D */
214   fetch_texel_3d_intensity,		/* FetchTexel3D */
215   fetch_texel_1d_f_intensity,		/* FetchTexel1Df */
216   fetch_texel_2d_f_intensity,		/* FetchTexel2Df */
217   fetch_texel_3d_f_intensity,		/* FetchTexel3Df */
218};
219
220const struct gl_texture_format _mesa_texformat_depth_component_float32 = {
221   MESA_FORMAT_DEPTH_COMPONENT_FLOAT32,	/* MesaFormat */
222   GL_DEPTH_COMPONENT,			/* BaseFormat */
223   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
224   0,					/* RedBits */
225   0,					/* GreenBits */
226   0,					/* BlueBits */
227   0,					/* AlphaBits */
228   0,					/* LuminanceBits */
229   0,					/* IntensityBits */
230   0,					/* IndexBits */
231   sizeof(GLfloat) * 8,			/* DepthBits */
232   sizeof(GLfloat),			/* TexelBytes */
233   _mesa_texstore_depth_component_float32,/* StoreTexImageFunc */
234   fetch_null_texel,			/* FetchTexel1D */
235   fetch_null_texel,			/* FetchTexel1D */
236   fetch_null_texel,			/* FetchTexel1D */
237   fetch_texel_1d_f_depth_component_f32,/* FetchTexel1Df */
238   fetch_texel_2d_f_depth_component_f32,/* FetchTexel2Df */
239   fetch_texel_3d_f_depth_component_f32,/* FetchTexel3Df */
240};
241
242const struct gl_texture_format _mesa_texformat_depth_component16 = {
243   MESA_FORMAT_DEPTH_COMPONENT16,	/* MesaFormat */
244   GL_DEPTH_COMPONENT,			/* BaseFormat */
245   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
246   0,					/* RedBits */
247   0,					/* GreenBits */
248   0,					/* BlueBits */
249   0,					/* AlphaBits */
250   0,					/* LuminanceBits */
251   0,					/* IntensityBits */
252   0,					/* IndexBits */
253   sizeof(GLushort) * 8,		/* DepthBits */
254   sizeof(GLushort),			/* TexelBytes */
255   _mesa_texstore_depth_component16,	/* StoreTexImageFunc */
256   fetch_null_texel,			/* FetchTexel1D */
257   fetch_null_texel,			/* FetchTexel1D */
258   fetch_null_texel,			/* FetchTexel1D */
259   fetch_texel_1d_f_depth_component16,	/* FetchTexel1Df */
260   fetch_texel_2d_f_depth_component16,	/* FetchTexel2Df */
261   fetch_texel_3d_f_depth_component16,	/* FetchTexel3Df */
262};
263
264const struct gl_texture_format _mesa_texformat_rgba_float32 = {
265   MESA_FORMAT_RGBA_FLOAT32,		/* MesaFormat */
266   GL_RGBA,				/* BaseFormat */
267   GL_FLOAT,				/* DataType */
268   8 * sizeof(GLfloat),			/* RedBits */
269   8 * sizeof(GLfloat),			/* GreenBits */
270   8 * sizeof(GLfloat),			/* BlueBits */
271   8 * sizeof(GLfloat),			/* AlphaBits */
272   0,					/* LuminanceBits */
273   0,					/* IntensityBits */
274   0,					/* IndexBits */
275   0,					/* DepthBits */
276   4 * sizeof(GLfloat),			/* TexelBytes */
277   _mesa_texstore_rgba_float32,		/* StoreTexImageFunc */
278   fetch_texel_1d_rgba_f32,		/* FetchTexel1D */
279   fetch_texel_2d_rgba_f32,		/* FetchTexel1D */
280   fetch_texel_3d_rgba_f32,		/* FetchTexel1D */
281   fetch_texel_1d_f_rgba_f32,		/* FetchTexel1Df */
282   fetch_texel_2d_f_rgba_f32,		/* FetchTexel2Df */
283   fetch_texel_3d_f_rgba_f32,		/* FetchTexel3Df */
284};
285
286const struct gl_texture_format _mesa_texformat_rgba_float16 = {
287   MESA_FORMAT_RGBA_FLOAT16,		/* MesaFormat */
288   GL_RGBA,				/* BaseFormat */
289   GL_FLOAT,				/* DataType */
290   8 * sizeof(GLhalfARB),		/* RedBits */
291   8 * sizeof(GLhalfARB),		/* GreenBits */
292   8 * sizeof(GLhalfARB),		/* BlueBits */
293   8 * sizeof(GLhalfARB),		/* AlphaBits */
294   0,					/* LuminanceBits */
295   0,					/* IntensityBits */
296   0,					/* IndexBits */
297   0,					/* DepthBits */
298   4 * sizeof(GLhalfARB),		/* TexelBytes */
299   _mesa_texstore_rgba_float16,		/* StoreTexImageFunc */
300   fetch_texel_1d_rgba_f16,		/* FetchTexel1D */
301   fetch_texel_2d_rgba_f16,		/* FetchTexel1D */
302   fetch_texel_3d_rgba_f16,		/* FetchTexel1D */
303   fetch_texel_1d_f_rgba_f16,		/* FetchTexel1Df */
304   fetch_texel_2d_f_rgba_f16,		/* FetchTexel2Df */
305   fetch_texel_3d_f_rgba_f16,		/* FetchTexel3Df */
306};
307
308const struct gl_texture_format _mesa_texformat_rgb_float32 = {
309   MESA_FORMAT_RGB_FLOAT32,		/* MesaFormat */
310   GL_RGB,				/* BaseFormat */
311   GL_FLOAT,				/* DataType */
312   8 * sizeof(GLfloat),			/* RedBits */
313   8 * sizeof(GLfloat),			/* GreenBits */
314   8 * sizeof(GLfloat),			/* BlueBits */
315   0,					/* AlphaBits */
316   0,					/* LuminanceBits */
317   0,					/* IntensityBits */
318   0,					/* IndexBits */
319   0,					/* DepthBits */
320   3 * sizeof(GLfloat),			/* TexelBytes */
321   _mesa_texstore_rgba_float32,/*yes*/	/* StoreTexImageFunc */
322   fetch_texel_1d_rgb_f32,		/* FetchTexel1D */
323   fetch_texel_2d_rgb_f32,		/* FetchTexel1D */
324   fetch_texel_3d_rgb_f32,		/* FetchTexel1D */
325   fetch_texel_1d_f_rgb_f32,		/* FetchTexel1Df */
326   fetch_texel_2d_f_rgb_f32,		/* FetchTexel2Df */
327   fetch_texel_3d_f_rgb_f32,		/* FetchTexel3Df */
328};
329
330const struct gl_texture_format _mesa_texformat_rgb_float16 = {
331   MESA_FORMAT_RGB_FLOAT16,		/* MesaFormat */
332   GL_RGB,				/* BaseFormat */
333   GL_FLOAT,				/* DataType */
334   8 * sizeof(GLhalfARB),		/* RedBits */
335   8 * sizeof(GLhalfARB),		/* GreenBits */
336   8 * sizeof(GLhalfARB),		/* BlueBits */
337   0,					/* AlphaBits */
338   0,					/* LuminanceBits */
339   0,					/* IntensityBits */
340   0,					/* IndexBits */
341   0,					/* DepthBits */
342   3 * sizeof(GLhalfARB),		/* TexelBytes */
343   _mesa_texstore_rgba_float16,/*yes*/	/* StoreTexImageFunc */
344   fetch_texel_1d_rgb_f16,		/* FetchTexel1D */
345   fetch_texel_2d_rgb_f16,		/* FetchTexel1D */
346   fetch_texel_3d_rgb_f16,		/* FetchTexel1D */
347   fetch_texel_1d_f_rgb_f16,		/* FetchTexel1Df */
348   fetch_texel_2d_f_rgb_f16,		/* FetchTexel2Df */
349   fetch_texel_3d_f_rgb_f16		/* FetchTexel3Df */
350};
351
352const struct gl_texture_format _mesa_texformat_alpha_float32 = {
353   MESA_FORMAT_ALPHA_FLOAT32,		/* MesaFormat */
354   GL_ALPHA,				/* BaseFormat */
355   GL_FLOAT,				/* DataType */
356   0,					/* RedBits */
357   0,					/* GreenBits */
358   0,					/* BlueBits */
359   8 * sizeof(GLfloat),			/* AlphaBits */
360   0,					/* LuminanceBits */
361   0,					/* IntensityBits */
362   0,					/* IndexBits */
363   0,					/* DepthBits */
364   1 * sizeof(GLfloat),			/* TexelBytes */
365   _mesa_texstore_rgba_float32,/*yes*/	/* StoreTexImageFunc */
366   fetch_texel_1d_alpha_f32,		/* FetchTexel1D */
367   fetch_texel_2d_alpha_f32,		/* FetchTexel1D */
368   fetch_texel_3d_alpha_f32,		/* FetchTexel1D */
369   fetch_texel_1d_f_alpha_f32,		/* FetchTexel1Df */
370   fetch_texel_2d_f_alpha_f32,		/* FetchTexel2Df */
371   fetch_texel_3d_f_alpha_f32		/* FetchTexel3Df */
372};
373
374const struct gl_texture_format _mesa_texformat_alpha_float16 = {
375   MESA_FORMAT_ALPHA_FLOAT16,		/* MesaFormat */
376   GL_ALPHA,				/* BaseFormat */
377   GL_FLOAT,				/* DataType */
378   0,					/* RedBits */
379   0,					/* GreenBits */
380   0,					/* BlueBits */
381   8 * sizeof(GLhalfARB),		/* AlphaBits */
382   0,					/* LuminanceBits */
383   0,					/* IntensityBits */
384   0,					/* IndexBits */
385   0,					/* DepthBits */
386   1 * sizeof(GLhalfARB),		/* TexelBytes */
387   _mesa_texstore_rgba_float16,/*yes*/	/* StoreTexImageFunc */
388   fetch_texel_1d_alpha_f16,		/* FetchTexel1D */
389   fetch_texel_2d_alpha_f16,		/* FetchTexel1D */
390   fetch_texel_3d_alpha_f16,		/* FetchTexel1D */
391   fetch_texel_1d_f_alpha_f16,		/* FetchTexel1Df */
392   fetch_texel_2d_f_alpha_f16,		/* FetchTexel2Df */
393   fetch_texel_3d_f_alpha_f16		/* FetchTexel3Df */
394};
395
396const struct gl_texture_format _mesa_texformat_luminance_float32 = {
397   MESA_FORMAT_LUMINANCE_FLOAT32,	/* MesaFormat */
398   GL_LUMINANCE,			/* BaseFormat */
399   GL_FLOAT,				/* DataType */
400   0,					/* RedBits */
401   0,					/* GreenBits */
402   0,					/* BlueBits */
403   0,					/* AlphaBits */
404   8 * sizeof(GLfloat),			/* LuminanceBits */
405   0,					/* IntensityBits */
406   0,					/* IndexBits */
407   0,					/* DepthBits */
408   1 * sizeof(GLfloat),			/* TexelBytes */
409   _mesa_texstore_rgba_float32,/*yes*/	/* StoreTexImageFunc */
410   fetch_texel_1d_luminance_f32,	/* FetchTexel1D */
411   fetch_texel_2d_luminance_f32,	/* FetchTexel2D */
412   fetch_texel_3d_luminance_f32,	/* FetchTexel3D */
413   fetch_texel_1d_f_luminance_f32,	/* FetchTexel1Df */
414   fetch_texel_2d_f_luminance_f32,	/* FetchTexel2Df */
415   fetch_texel_3d_f_luminance_f32	/* FetchTexel3Df */
416};
417
418const struct gl_texture_format _mesa_texformat_luminance_float16 = {
419   MESA_FORMAT_LUMINANCE_FLOAT16,	/* MesaFormat */
420   GL_LUMINANCE,			/* BaseFormat */
421   GL_FLOAT,				/* DataType */
422   0,					/* RedBits */
423   0,					/* GreenBits */
424   0,					/* BlueBits */
425   0,					/* AlphaBits */
426   8 * sizeof(GLhalfARB),		/* LuminanceBits */
427   0,					/* IntensityBits */
428   0,					/* IndexBits */
429   0,					/* DepthBits */
430   1 * sizeof(GLhalfARB),		/* TexelBytes */
431   _mesa_texstore_rgba_float16,/*yes*/	/* StoreTexImageFunc */
432   fetch_texel_1d_luminance_f16,	/* FetchTexel1D */
433   fetch_texel_2d_luminance_f16,	/* FetchTexel2D */
434   fetch_texel_3d_luminance_f16,	/* FetchTexel3D */
435   fetch_texel_1d_f_luminance_f16,	/* FetchTexel1Df */
436   fetch_texel_2d_f_luminance_f16,	/* FetchTexel2Df */
437   fetch_texel_3d_f_luminance_f16	/* FetchTexel3Df */
438};
439
440const struct gl_texture_format _mesa_texformat_luminance_alpha_float32 = {
441   MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,	/* MesaFormat */
442   GL_LUMINANCE_ALPHA,			/* BaseFormat */
443   GL_FLOAT,				/* DataType */
444   0,					/* RedBits */
445   0,					/* GreenBits */
446   0,					/* BlueBits */
447   8 * sizeof(GLfloat),			/* AlphaBits */
448   8 * sizeof(GLfloat),			/* LuminanceBits */
449   0,					/* IntensityBits */
450   0,					/* IndexBits */
451   0,					/* DepthBits */
452   2 * sizeof(GLfloat),			/* TexelBytes */
453   _mesa_texstore_rgba_float32,		/* StoreTexImageFunc */
454   fetch_texel_1d_luminance_alpha_f32,	/* FetchTexel1D */
455   fetch_texel_2d_luminance_alpha_f32,	/* FetchTexel2D */
456   fetch_texel_3d_luminance_alpha_f32,	/* FetchTexel3D */
457   fetch_texel_1d_f_luminance_alpha_f32,/* FetchTexel1Df */
458   fetch_texel_2d_f_luminance_alpha_f32,/* FetchTexel2Df */
459   fetch_texel_3d_f_luminance_alpha_f32	/* FetchTexel3Df */
460};
461
462const struct gl_texture_format _mesa_texformat_luminance_alpha_float16 = {
463   MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,	/* MesaFormat */
464   GL_LUMINANCE_ALPHA,			/* BaseFormat */
465   GL_FLOAT,				/* DataType */
466   0,					/* RedBits */
467   0,					/* GreenBits */
468   0,					/* BlueBits */
469   8 * sizeof(GLhalfARB),		/* AlphaBits */
470   8 * sizeof(GLhalfARB),		/* LuminanceBits */
471   0,					/* IntensityBits */
472   0,					/* IndexBits */
473   0,					/* DepthBits */
474   2 * sizeof(GLhalfARB),		/* TexelBytes */
475   _mesa_texstore_rgba_float16,		/* StoreTexImageFunc */
476   fetch_texel_1d_luminance_alpha_f16,	/* FetchTexel1D */
477   fetch_texel_2d_luminance_alpha_f16,	/* FetchTexel2D */
478   fetch_texel_3d_luminance_alpha_f16,	/* FetchTexel3D */
479   fetch_texel_1d_f_luminance_alpha_f16,/* FetchTexel1Df */
480   fetch_texel_2d_f_luminance_alpha_f16,/* FetchTexel2Df */
481   fetch_texel_3d_f_luminance_alpha_f16	/* FetchTexel3Df */
482};
483
484const struct gl_texture_format _mesa_texformat_intensity_float32 = {
485   MESA_FORMAT_INTENSITY_FLOAT32,	/* MesaFormat */
486   GL_INTENSITY,			/* BaseFormat */
487   GL_FLOAT,				/* DataType */
488   0,					/* RedBits */
489   0,					/* GreenBits */
490   0,					/* BlueBits */
491   0,					/* AlphaBits */
492   0,					/* LuminanceBits */
493   8 * sizeof(GLfloat),			/* IntensityBits */
494   0,					/* IndexBits */
495   0,					/* DepthBits */
496   1 * sizeof(GLfloat),			/* TexelBytes */
497   _mesa_texstore_rgba_float32,/*yes*/	/* StoreTexImageFunc */
498   fetch_texel_1d_intensity_f32,	/* FetchTexel1D */
499   fetch_texel_2d_intensity_f32,	/* FetchTexel2D */
500   fetch_texel_3d_intensity_f32,	/* FetchTexel3D */
501   fetch_texel_1d_f_intensity_f32,	/* FetchTexel1Df */
502   fetch_texel_2d_f_intensity_f32,	/* FetchTexel2Df */
503   fetch_texel_3d_f_intensity_f32	/* FetchTexel3Df */
504};
505
506const struct gl_texture_format _mesa_texformat_intensity_float16 = {
507   MESA_FORMAT_INTENSITY_FLOAT16,	/* MesaFormat */
508   GL_INTENSITY,			/* BaseFormat */
509   GL_FLOAT,				/* DataType */
510   0,					/* RedBits */
511   0,					/* GreenBits */
512   0,					/* BlueBits */
513   0,					/* AlphaBits */
514   0,					/* LuminanceBits */
515   8 * sizeof(GLhalfARB),		/* IntensityBits */
516   0,					/* IndexBits */
517   0,					/* DepthBits */
518   1 * sizeof(GLhalfARB),		/* TexelBytes */
519   _mesa_texstore_rgba_float16,/*yes*/	/* StoreTexImageFunc */
520   fetch_texel_1d_intensity_f16,	/* FetchTexel1D */
521   fetch_texel_2d_intensity_f16,	/* FetchTexel2D */
522   fetch_texel_3d_intensity_f16,	/* FetchTexel3D */
523   fetch_texel_1d_f_intensity_f16,	/* FetchTexel1Df */
524   fetch_texel_2d_f_intensity_f16,	/* FetchTexel2Df */
525   fetch_texel_3d_f_intensity_f16	/* FetchTexel3Df */
526};
527
528
529/*@}*/
530
531
532/***************************************************************/
533/** \name Hardware formats */
534/*@{*/
535
536const struct gl_texture_format _mesa_texformat_rgba8888 = {
537   MESA_FORMAT_RGBA8888,		/* MesaFormat */
538   GL_RGBA,				/* BaseFormat */
539   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
540   8,					/* RedBits */
541   8,					/* GreenBits */
542   8,					/* BlueBits */
543   8,					/* AlphaBits */
544   0,					/* LuminanceBits */
545   0,					/* IntensityBits */
546   0,					/* IndexBits */
547   0,					/* DepthBits */
548   4,					/* TexelBytes */
549   _mesa_texstore_rgba8888,		/* StoreTexImageFunc */
550   fetch_texel_1d_rgba8888,		/* FetchTexel1D */
551   fetch_texel_2d_rgba8888,		/* FetchTexel2D */
552   fetch_texel_3d_rgba8888,		/* FetchTexel3D */
553   fetch_texel_1d_f_rgba8888,		/* FetchTexel1Df */
554   fetch_texel_2d_f_rgba8888,		/* FetchTexel2Df */
555   fetch_texel_3d_f_rgba8888,		/* FetchTexel3Df */
556};
557
558const struct gl_texture_format _mesa_texformat_rgba8888_rev = {
559   MESA_FORMAT_RGBA8888_REV,		/* MesaFormat */
560   GL_RGBA,				/* BaseFormat */
561   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
562   8,					/* RedBits */
563   8,					/* GreenBits */
564   8,					/* BlueBits */
565   8,					/* AlphaBits */
566   0,					/* LuminanceBits */
567   0,					/* IntensityBits */
568   0,					/* IndexBits */
569   0,					/* DepthBits */
570   4,					/* TexelBytes */
571   _mesa_texstore_rgba8888,		/* StoreTexImageFunc */
572   fetch_texel_1d_rgba8888_rev,		/* FetchTexel1D */
573   fetch_texel_2d_rgba8888_rev,		/* FetchTexel2D */
574   fetch_texel_3d_rgba8888_rev,		/* FetchTexel3D */
575   fetch_texel_1d_f_rgba8888_rev,	/* FetchTexel1Df */
576   fetch_texel_2d_f_rgba8888_rev,	/* FetchTexel2Df */
577   fetch_texel_3d_f_rgba8888_rev,	/* FetchTexel3Df */
578};
579
580const struct gl_texture_format _mesa_texformat_argb8888 = {
581   MESA_FORMAT_ARGB8888,		/* MesaFormat */
582   GL_RGBA,				/* BaseFormat */
583   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
584   8,					/* RedBits */
585   8,					/* GreenBits */
586   8,					/* BlueBits */
587   8,					/* AlphaBits */
588   0,					/* LuminanceBits */
589   0,					/* IntensityBits */
590   0,					/* IndexBits */
591   0,					/* DepthBits */
592   4,					/* TexelBytes */
593   _mesa_texstore_argb8888,		/* StoreTexImageFunc */
594   fetch_texel_1d_argb8888,		/* FetchTexel1D */
595   fetch_texel_2d_argb8888,		/* FetchTexel2D */
596   fetch_texel_3d_argb8888,		/* FetchTexel3D */
597   fetch_texel_1d_f_argb8888,		/* FetchTexel1Df */
598   fetch_texel_2d_f_argb8888,		/* FetchTexel2Df */
599   fetch_texel_3d_f_argb8888,		/* FetchTexel3Df */
600};
601
602const struct gl_texture_format _mesa_texformat_argb8888_rev = {
603   MESA_FORMAT_ARGB8888_REV,		/* MesaFormat */
604   GL_RGBA,				/* BaseFormat */
605   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
606   8,					/* RedBits */
607   8,					/* GreenBits */
608   8,					/* BlueBits */
609   8,					/* AlphaBits */
610   0,					/* LuminanceBits */
611   0,					/* IntensityBits */
612   0,					/* IndexBits */
613   0,					/* DepthBits */
614   4,					/* TexelBytes */
615   _mesa_texstore_argb8888,		/* StoreTexImageFunc */
616   fetch_texel_1d_argb8888_rev,		/* FetchTexel1D */
617   fetch_texel_2d_argb8888_rev,		/* FetchTexel2D */
618   fetch_texel_3d_argb8888_rev,		/* FetchTexel3D */
619   fetch_texel_1d_f_argb8888_rev,	/* FetchTexel1Df */
620   fetch_texel_2d_f_argb8888_rev,	/* FetchTexel2Df */
621   fetch_texel_3d_f_argb8888_rev,	/* FetchTexel3Df */
622};
623
624const struct gl_texture_format _mesa_texformat_rgb888 = {
625   MESA_FORMAT_RGB888,			/* MesaFormat */
626   GL_RGB,				/* BaseFormat */
627   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
628   8,					/* RedBits */
629   8,					/* GreenBits */
630   8,					/* BlueBits */
631   0,					/* AlphaBits */
632   0,					/* LuminanceBits */
633   0,					/* IntensityBits */
634   0,					/* IndexBits */
635   0,					/* DepthBits */
636   3,					/* TexelBytes */
637   _mesa_texstore_rgb888,		/* StoreTexImageFunc */
638   fetch_texel_1d_rgb888,		/* FetchTexel1D */
639   fetch_texel_2d_rgb888,		/* FetchTexel2D */
640   fetch_texel_3d_rgb888,		/* FetchTexel3D */
641   fetch_texel_1d_f_rgb888,		/* FetchTexel1Df */
642   fetch_texel_2d_f_rgb888,		/* FetchTexel2Df */
643   fetch_texel_3d_f_rgb888,		/* FetchTexel3Df */
644};
645
646const struct gl_texture_format _mesa_texformat_bgr888 = {
647   MESA_FORMAT_BGR888,			/* MesaFormat */
648   GL_RGB,				/* BaseFormat */
649   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
650   8,					/* RedBits */
651   8,					/* GreenBits */
652   8,					/* BlueBits */
653   0,					/* AlphaBits */
654   0,					/* LuminanceBits */
655   0,					/* IntensityBits */
656   0,					/* IndexBits */
657   0,					/* DepthBits */
658   3,					/* TexelBytes */
659   _mesa_texstore_bgr888,		/* StoreTexImageFunc */
660   fetch_texel_1d_bgr888,		/* FetchTexel1D */
661   fetch_texel_2d_bgr888,		/* FetchTexel2D */
662   fetch_texel_3d_bgr888,		/* FetchTexel3D */
663   fetch_texel_1d_f_bgr888,		/* FetchTexel1Df */
664   fetch_texel_2d_f_bgr888,		/* FetchTexel2Df */
665   fetch_texel_3d_f_bgr888,		/* FetchTexel3Df */
666};
667
668const struct gl_texture_format _mesa_texformat_rgb565 = {
669   MESA_FORMAT_RGB565,			/* MesaFormat */
670   GL_RGB,				/* BaseFormat */
671   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
672   5,					/* RedBits */
673   6,					/* GreenBits */
674   5,					/* BlueBits */
675   0,					/* AlphaBits */
676   0,					/* LuminanceBits */
677   0,					/* IntensityBits */
678   0,					/* IndexBits */
679   0,					/* DepthBits */
680   2,					/* TexelBytes */
681   _mesa_texstore_rgb565,		/* StoreTexImageFunc */
682   fetch_texel_1d_rgb565,		/* FetchTexel1D */
683   fetch_texel_2d_rgb565,		/* FetchTexel2D */
684   fetch_texel_3d_rgb565,		/* FetchTexel3D */
685   fetch_texel_1d_f_rgb565,		/* FetchTexel1Df */
686   fetch_texel_2d_f_rgb565,		/* FetchTexel2Df */
687   fetch_texel_3d_f_rgb565,		/* FetchTexel3Df */
688};
689
690const struct gl_texture_format _mesa_texformat_rgb565_rev = {
691   MESA_FORMAT_RGB565_REV,		/* MesaFormat */
692   GL_RGB,				/* BaseFormat */
693   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
694   5,					/* RedBits */
695   6,					/* GreenBits */
696   5,					/* BlueBits */
697   0,					/* AlphaBits */
698   0,					/* LuminanceBits */
699   0,					/* IntensityBits */
700   0,					/* IndexBits */
701   0,					/* DepthBits */
702   2,					/* TexelBytes */
703   _mesa_texstore_rgb565,		/* StoreTexImageFunc */
704   fetch_texel_1d_rgb565_rev,		/* FetchTexel1D */
705   fetch_texel_2d_rgb565_rev,		/* FetchTexel2D */
706   fetch_texel_3d_rgb565_rev,		/* FetchTexel3D */
707   fetch_texel_1d_f_rgb565_rev,		/* FetchTexel1Df */
708   fetch_texel_2d_f_rgb565_rev,		/* FetchTexel2Df */
709   fetch_texel_3d_f_rgb565_rev,		/* FetchTexel3Df */
710};
711
712const struct gl_texture_format _mesa_texformat_argb4444 = {
713   MESA_FORMAT_ARGB4444,		/* MesaFormat */
714   GL_RGBA,				/* BaseFormat */
715   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
716   4,					/* RedBits */
717   4,					/* GreenBits */
718   4,					/* BlueBits */
719   4,					/* AlphaBits */
720   0,					/* LuminanceBits */
721   0,					/* IntensityBits */
722   0,					/* IndexBits */
723   0,					/* DepthBits */
724   2,					/* TexelBytes */
725   _mesa_texstore_argb4444,		/* StoreTexImageFunc */
726   fetch_texel_1d_argb4444,		/* FetchTexel1D */
727   fetch_texel_2d_argb4444,		/* FetchTexel2D */
728   fetch_texel_3d_argb4444,		/* FetchTexel3D */
729   fetch_texel_1d_f_argb4444,		/* FetchTexel1Df */
730   fetch_texel_2d_f_argb4444,		/* FetchTexel2Df */
731   fetch_texel_3d_f_argb4444,		/* FetchTexel3Df */
732};
733
734const struct gl_texture_format _mesa_texformat_argb4444_rev = {
735   MESA_FORMAT_ARGB4444_REV,		/* MesaFormat */
736   GL_RGBA,				/* BaseFormat */
737   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
738   4,					/* RedBits */
739   4,					/* GreenBits */
740   4,					/* BlueBits */
741   4,					/* AlphaBits */
742   0,					/* LuminanceBits */
743   0,					/* IntensityBits */
744   0,					/* IndexBits */
745   0,					/* DepthBits */
746   2,					/* TexelBytes */
747   _mesa_texstore_argb4444,		/* StoreTexImageFunc */
748   fetch_texel_1d_argb4444_rev,		/* FetchTexel1D */
749   fetch_texel_2d_argb4444_rev,		/* FetchTexel2D */
750   fetch_texel_3d_argb4444_rev,		/* FetchTexel3D */
751   fetch_texel_1d_f_argb4444_rev,	/* FetchTexel1Df */
752   fetch_texel_2d_f_argb4444_rev,	/* FetchTexel2Df */
753   fetch_texel_3d_f_argb4444_rev,	/* FetchTexel3Df */
754};
755
756const struct gl_texture_format _mesa_texformat_argb1555 = {
757   MESA_FORMAT_ARGB1555,		/* MesaFormat */
758   GL_RGBA,				/* BaseFormat */
759   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
760   5,					/* RedBits */
761   5,					/* GreenBits */
762   5,					/* BlueBits */
763   1,					/* AlphaBits */
764   0,					/* LuminanceBits */
765   0,					/* IntensityBits */
766   0,					/* IndexBits */
767   0,					/* DepthBits */
768   2,					/* TexelBytes */
769   _mesa_texstore_argb1555,		/* StoreTexImageFunc */
770   fetch_texel_1d_argb1555,		/* FetchTexel1D */
771   fetch_texel_2d_argb1555,		/* FetchTexel2D */
772   fetch_texel_3d_argb1555,		/* FetchTexel3D */
773   fetch_texel_1d_f_argb1555,		/* FetchTexel1Df */
774   fetch_texel_2d_f_argb1555,		/* FetchTexel2Df */
775   fetch_texel_3d_f_argb1555,		/* FetchTexel3Df */
776};
777
778const struct gl_texture_format _mesa_texformat_argb1555_rev = {
779   MESA_FORMAT_ARGB1555_REV,		/* MesaFormat */
780   GL_RGBA,				/* BaseFormat */
781   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
782   5,					/* RedBits */
783   5,					/* GreenBits */
784   5,					/* BlueBits */
785   1,					/* AlphaBits */
786   0,					/* LuminanceBits */
787   0,					/* IntensityBits */
788   0,					/* IndexBits */
789   0,					/* DepthBits */
790   2,					/* TexelBytes */
791   _mesa_texstore_argb1555,		/* StoreTexImageFunc */
792   fetch_texel_1d_argb1555_rev,		/* FetchTexel1D */
793   fetch_texel_2d_argb1555_rev,		/* FetchTexel2D */
794   fetch_texel_3d_argb1555_rev,		/* FetchTexel3D */
795   fetch_texel_1d_f_argb1555_rev,	/* FetchTexel1Df */
796   fetch_texel_2d_f_argb1555_rev,	/* FetchTexel2Df */
797   fetch_texel_3d_f_argb1555_rev,	/* FetchTexel3Df */
798};
799
800const struct gl_texture_format _mesa_texformat_al88 = {
801   MESA_FORMAT_AL88,			/* MesaFormat */
802   GL_LUMINANCE_ALPHA,			/* BaseFormat */
803   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
804   0,					/* RedBits */
805   0,					/* GreenBits */
806   0,					/* BlueBits */
807   8,					/* AlphaBits */
808   8,					/* LuminanceBits */
809   0,					/* IntensityBits */
810   0,					/* IndexBits */
811   0,					/* DepthBits */
812   2,					/* TexelBytes */
813   _mesa_texstore_al88,			/* StoreTexImageFunc */
814   fetch_texel_1d_al88,			/* FetchTexel1D */
815   fetch_texel_2d_al88,			/* FetchTexel2D */
816   fetch_texel_3d_al88,			/* FetchTexel3D */
817   fetch_texel_1d_f_al88,		/* FetchTexel1Df */
818   fetch_texel_2d_f_al88,		/* FetchTexel2Df */
819   fetch_texel_3d_f_al88,		/* FetchTexel3Df */
820};
821
822const struct gl_texture_format _mesa_texformat_al88_rev = {
823   MESA_FORMAT_AL88_REV,		/* MesaFormat */
824   GL_LUMINANCE_ALPHA,			/* BaseFormat */
825   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
826   0,					/* RedBits */
827   0,					/* GreenBits */
828   0,					/* BlueBits */
829   8,					/* AlphaBits */
830   8,					/* LuminanceBits */
831   0,					/* IntensityBits */
832   0,					/* IndexBits */
833   0,					/* DepthBits */
834   2,					/* TexelBytes */
835   _mesa_texstore_al88,			/* StoreTexImageFunc */
836   fetch_texel_1d_al88_rev,		/* FetchTexel1D */
837   fetch_texel_2d_al88_rev,		/* FetchTexel2D */
838   fetch_texel_3d_al88_rev,		/* FetchTexel3D */
839   fetch_texel_1d_f_al88_rev,		/* FetchTexel1Df */
840   fetch_texel_2d_f_al88_rev,		/* FetchTexel2Df */
841   fetch_texel_3d_f_al88_rev,		/* FetchTexel3Df */
842};
843
844const struct gl_texture_format _mesa_texformat_rgb332 = {
845   MESA_FORMAT_RGB332,			/* MesaFormat */
846   GL_RGB,				/* BaseFormat */
847   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
848   3,					/* RedBits */
849   3,					/* GreenBits */
850   2,					/* BlueBits */
851   0,					/* AlphaBits */
852   0,					/* LuminanceBits */
853   0,					/* IntensityBits */
854   0,					/* IndexBits */
855   0,					/* DepthBits */
856   1,					/* TexelBytes */
857   _mesa_texstore_rgb332,		/* StoreTexImageFunc */
858   fetch_texel_1d_rgb332,		/* FetchTexel1D */
859   fetch_texel_2d_rgb332,		/* FetchTexel2D */
860   fetch_texel_3d_rgb332,		/* FetchTexel3D */
861   fetch_texel_1d_f_rgb332,		/* FetchTexel1Df */
862   fetch_texel_2d_f_rgb332,		/* FetchTexel2Df */
863   fetch_texel_3d_f_rgb332,		/* FetchTexel3Df */
864};
865
866const struct gl_texture_format _mesa_texformat_a8 = {
867   MESA_FORMAT_A8,			/* MesaFormat */
868   GL_ALPHA,				/* BaseFormat */
869   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
870   0,					/* RedBits */
871   0,					/* GreenBits */
872   0,					/* BlueBits */
873   8,					/* AlphaBits */
874   0,					/* LuminanceBits */
875   0,					/* IntensityBits */
876   0,					/* IndexBits */
877   0,					/* DepthBits */
878   1,					/* TexelBytes */
879   _mesa_texstore_a8,			/* StoreTexImageFunc */
880   fetch_texel_1d_a8,			/* FetchTexel1D */
881   fetch_texel_2d_a8,			/* FetchTexel2D */
882   fetch_texel_3d_a8,			/* FetchTexel3D */
883   fetch_texel_1d_f_a8,			/* FetchTexel1Df */
884   fetch_texel_2d_f_a8,			/* FetchTexel2Df */
885   fetch_texel_3d_f_a8,			/* FetchTexel3Df */
886};
887
888const struct gl_texture_format _mesa_texformat_l8 = {
889   MESA_FORMAT_L8,			/* MesaFormat */
890   GL_LUMINANCE,			/* BaseFormat */
891   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
892   0,					/* RedBits */
893   0,					/* GreenBits */
894   0,					/* BlueBits */
895   0,					/* AlphaBits */
896   8,					/* LuminanceBits */
897   0,					/* IntensityBits */
898   0,					/* IndexBits */
899   0,					/* DepthBits */
900   1,					/* TexelBytes */
901   _mesa_texstore_a8,/*yes*/		/* StoreTexImageFunc */
902   fetch_texel_1d_l8,			/* FetchTexel1D */
903   fetch_texel_2d_l8,			/* FetchTexel2D */
904   fetch_texel_3d_l8,			/* FetchTexel3D */
905   fetch_texel_1d_f_l8,			/* FetchTexel1Df */
906   fetch_texel_2d_f_l8,			/* FetchTexel2Df */
907   fetch_texel_3d_f_l8,			/* FetchTexel3Df */
908};
909
910const struct gl_texture_format _mesa_texformat_i8 = {
911   MESA_FORMAT_I8,			/* MesaFormat */
912   GL_INTENSITY,			/* BaseFormat */
913   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
914   0,					/* RedBits */
915   0,					/* GreenBits */
916   0,					/* BlueBits */
917   0,					/* AlphaBits */
918   0,					/* LuminanceBits */
919   8,					/* IntensityBits */
920   0,					/* IndexBits */
921   0,					/* DepthBits */
922   1,					/* TexelBytes */
923   _mesa_texstore_a8,/*yes*/		/* StoreTexImageFunc */
924   fetch_texel_1d_i8,			/* FetchTexel1D */
925   fetch_texel_2d_i8,			/* FetchTexel2D */
926   fetch_texel_3d_i8,			/* FetchTexel3D */
927   fetch_texel_1d_f_i8,			/* FetchTexel1Df */
928   fetch_texel_2d_f_i8,			/* FetchTexel2Df */
929   fetch_texel_3d_f_i8,			/* FetchTexel3Df */
930};
931
932const struct gl_texture_format _mesa_texformat_ci8 = {
933   MESA_FORMAT_CI8,			/* MesaFormat */
934   GL_COLOR_INDEX,			/* BaseFormat */
935   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
936   0,					/* RedBits */
937   0,					/* GreenBits */
938   0,					/* BlueBits */
939   0,					/* AlphaBits */
940   0,					/* LuminanceBits */
941   0,					/* IntensityBits */
942   8,					/* IndexBits */
943   0,					/* DepthBits */
944   1,					/* TexelBytes */
945   _mesa_texstore_ci8,			/* StoreTexImageFunc */
946   fetch_texel_1d_ci8,			/* FetchTexel1D */
947   fetch_texel_2d_ci8,			/* FetchTexel2D */
948   fetch_texel_3d_ci8,			/* FetchTexel3D */
949   fetch_texel_1d_f_ci8,		/* FetchTexel1Df */
950   fetch_texel_2d_f_ci8,		/* FetchTexel2Df */
951   fetch_texel_3d_f_ci8,		/* FetchTexel3Df */
952};
953
954const struct gl_texture_format _mesa_texformat_ycbcr = {
955   MESA_FORMAT_YCBCR,			/* MesaFormat */
956   GL_YCBCR_MESA,			/* BaseFormat */
957   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
958   0,					/* RedBits */
959   0,					/* GreenBits */
960   0,					/* BlueBits */
961   0,					/* AlphaBits */
962   0,					/* LuminanceBits */
963   0,					/* IntensityBits */
964   0,					/* IndexBits */
965   0,					/* DepthBits */
966   2,					/* TexelBytes */
967   _mesa_texstore_ycbcr,		/* StoreTexImageFunc */
968   fetch_texel_1d_ycbcr,		/* FetchTexel1D */
969   fetch_texel_2d_ycbcr,		/* FetchTexel2D */
970   fetch_texel_3d_ycbcr,		/* FetchTexel3D */
971   fetch_texel_1d_f_ycbcr,		/* FetchTexel1Df */
972   fetch_texel_2d_f_ycbcr,		/* FetchTexel2Df */
973   fetch_texel_3d_f_ycbcr,		/* FetchTexel3Df */
974};
975
976const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
977   MESA_FORMAT_YCBCR_REV,		/* MesaFormat */
978   GL_YCBCR_MESA,			/* BaseFormat */
979   GL_UNSIGNED_NORMALIZED_ARB,		/* DataType */
980   0,					/* RedBits */
981   0,					/* GreenBits */
982   0,					/* BlueBits */
983   0,					/* AlphaBits */
984   0,					/* LuminanceBits */
985   0,					/* IntensityBits */
986   0,					/* IndexBits */
987   0,					/* DepthBits */
988   2,					/* TexelBytes */
989   _mesa_texstore_ycbcr,		/* StoreTexImageFunc */
990   fetch_texel_1d_ycbcr_rev,		/* FetchTexel1D */
991   fetch_texel_2d_ycbcr_rev,		/* FetchTexel2D */
992   fetch_texel_3d_ycbcr_rev,		/* FetchTexel3D */
993   fetch_texel_1d_f_ycbcr_rev,		/* FetchTexel1Df */
994   fetch_texel_2d_f_ycbcr_rev,		/* FetchTexel2Df */
995   fetch_texel_3d_f_ycbcr_rev,		/* FetchTexel3Df */
996};
997
998/*@}*/
999
1000
1001/***************************************************************/
1002/** \name Null format (useful for proxy textures) */
1003/*@{*/
1004
1005const struct gl_texture_format _mesa_null_texformat = {
1006   -1,					/* MesaFormat */
1007   0,					/* BaseFormat */
1008   GL_NONE,				/* DataType */
1009   0,					/* RedBits */
1010   0,					/* GreenBits */
1011   0,					/* BlueBits */
1012   0,					/* AlphaBits */
1013   0,					/* LuminanceBits */
1014   0,					/* IntensityBits */
1015   0,					/* IndexBits */
1016   0,					/* DepthBits */
1017   0,					/* TexelBytes */
1018   NULL,				/* StoreTexImageFunc */
1019   fetch_null_texel,			/* FetchTexel1D */
1020   fetch_null_texel,			/* FetchTexel2D */
1021   fetch_null_texel,			/* FetchTexel3D */
1022   fetch_null_texelf,			/* FetchTexel1Df */
1023   fetch_null_texelf,			/* FetchTexel2Df */
1024   fetch_null_texelf,			/* FetchTexel3Df */
1025};
1026
1027/*@}*/
1028
1029
1030/**
1031 * Choose an appropriate texture format given the format, type and
1032 * internalFormat parameters passed to glTexImage().
1033 *
1034 * \param ctx  the GL context.
1035 * \param internalFormat  user's prefered internal texture format.
1036 * \param format  incoming image pixel format.
1037 * \param type  incoming image data type.
1038 *
1039 * \return a pointer to a gl_texture_format object which describes the
1040 * choosen texture format, or NULL on failure.
1041 *
1042 * This is called via dd_function_table::ChooseTextureFormat.  Hardware drivers
1043 * will typically override this function with a specialized version.
1044 */
1045const struct gl_texture_format *
1046_mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
1047                         GLenum format, GLenum type )
1048{
1049   (void) format;
1050   (void) type;
1051
1052   switch (internalFormat) {
1053      /* RGBA formats */
1054      case 4:
1055      case GL_RGBA:
1056      case GL_RGB10_A2:
1057      case GL_RGBA12:
1058      case GL_RGBA16:
1059         return &_mesa_texformat_rgba;
1060      case GL_RGBA8:
1061         return &_mesa_texformat_rgba8888;
1062      case GL_RGB5_A1:
1063         return &_mesa_texformat_argb1555;
1064      case GL_RGBA2:
1065         return &_mesa_texformat_argb4444_rev; /* just to test another format*/
1066      case GL_RGBA4:
1067         return &_mesa_texformat_argb4444;
1068
1069      /* RGB formats */
1070      case 3:
1071      case GL_RGB:
1072      case GL_RGB10:
1073      case GL_RGB12:
1074      case GL_RGB16:
1075         return &_mesa_texformat_rgb;
1076      case GL_RGB8:
1077         return &_mesa_texformat_rgb888;
1078      case GL_R3_G3_B2:
1079         return &_mesa_texformat_rgb332;
1080      case GL_RGB4:
1081         return &_mesa_texformat_rgb565_rev; /* just to test another format */
1082      case GL_RGB5:
1083         return &_mesa_texformat_rgb565;
1084
1085      /* Alpha formats */
1086      case GL_ALPHA:
1087      case GL_ALPHA4:
1088      case GL_ALPHA12:
1089      case GL_ALPHA16:
1090         return &_mesa_texformat_alpha;
1091      case GL_ALPHA8:
1092         return &_mesa_texformat_a8;
1093
1094      /* Luminance formats */
1095      case 1:
1096      case GL_LUMINANCE:
1097      case GL_LUMINANCE4:
1098      case GL_LUMINANCE12:
1099      case GL_LUMINANCE16:
1100         return &_mesa_texformat_luminance;
1101      case GL_LUMINANCE8:
1102         return &_mesa_texformat_l8;
1103
1104      /* Luminance/Alpha formats */
1105      case 2:
1106      case GL_LUMINANCE_ALPHA:
1107      case GL_LUMINANCE4_ALPHA4:
1108      case GL_LUMINANCE6_ALPHA2:
1109      case GL_LUMINANCE12_ALPHA4:
1110      case GL_LUMINANCE12_ALPHA12:
1111      case GL_LUMINANCE16_ALPHA16:
1112         return &_mesa_texformat_luminance_alpha;
1113      case GL_LUMINANCE8_ALPHA8:
1114         return &_mesa_texformat_al88;
1115
1116      case GL_INTENSITY:
1117      case GL_INTENSITY4:
1118      case GL_INTENSITY12:
1119      case GL_INTENSITY16:
1120         return &_mesa_texformat_intensity;
1121      case GL_INTENSITY8:
1122         return &_mesa_texformat_i8;
1123
1124      case GL_COLOR_INDEX:
1125      case GL_COLOR_INDEX1_EXT:
1126      case GL_COLOR_INDEX2_EXT:
1127      case GL_COLOR_INDEX4_EXT:
1128      case GL_COLOR_INDEX12_EXT:
1129      case GL_COLOR_INDEX16_EXT:
1130      case GL_COLOR_INDEX8_EXT:
1131         return &_mesa_texformat_ci8;
1132
1133      default:
1134         ; /* fallthrough */
1135   }
1136
1137   if (ctx->Extensions.SGIX_depth_texture) {
1138      switch (internalFormat) {
1139         case GL_DEPTH_COMPONENT:
1140         case GL_DEPTH_COMPONENT24_SGIX:
1141         case GL_DEPTH_COMPONENT32_SGIX:
1142            return &_mesa_texformat_depth_component_float32;
1143         case GL_DEPTH_COMPONENT16_SGIX:
1144            return &_mesa_texformat_depth_component16;
1145         default:
1146            ; /* fallthrough */
1147      }
1148   }
1149
1150   if (ctx->Extensions.ARB_texture_compression) {
1151      switch (internalFormat) {
1152         case GL_COMPRESSED_ALPHA_ARB:
1153            return &_mesa_texformat_alpha;
1154         case GL_COMPRESSED_LUMINANCE_ARB:
1155            return &_mesa_texformat_luminance;
1156         case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
1157            return &_mesa_texformat_luminance_alpha;
1158         case GL_COMPRESSED_INTENSITY_ARB:
1159            return &_mesa_texformat_intensity;
1160         case GL_COMPRESSED_RGB_ARB:
1161            if (ctx->Extensions.TDFX_texture_compression_FXT1)
1162               return &_mesa_texformat_rgb_fxt1;
1163            else if (ctx->Extensions.EXT_texture_compression_s3tc ||
1164                     ctx->Extensions.S3_s3tc)
1165               return &_mesa_texformat_rgb_dxt1;
1166            else
1167               return &_mesa_texformat_rgb;
1168         case GL_COMPRESSED_RGBA_ARB:
1169            if (ctx->Extensions.TDFX_texture_compression_FXT1)
1170               return &_mesa_texformat_rgba_fxt1;
1171            else if (ctx->Extensions.EXT_texture_compression_s3tc ||
1172                     ctx->Extensions.S3_s3tc)
1173               return &_mesa_texformat_rgba_dxt3; /* Not rgba_dxt1, see spec */
1174            else
1175               return &_mesa_texformat_rgba;
1176         default:
1177            ; /* fallthrough */
1178      }
1179   }
1180
1181   if (ctx->Extensions.MESA_ycbcr_texture) {
1182      if (internalFormat == GL_YCBCR_MESA) {
1183         if (type == GL_UNSIGNED_SHORT_8_8_MESA)
1184            return &_mesa_texformat_ycbcr;
1185         else
1186            return &_mesa_texformat_ycbcr_rev;
1187      }
1188   }
1189
1190   if (ctx->Extensions.TDFX_texture_compression_FXT1) {
1191      switch (internalFormat) {
1192         case GL_COMPRESSED_RGB_FXT1_3DFX:
1193            return &_mesa_texformat_rgb_fxt1;
1194         case GL_COMPRESSED_RGBA_FXT1_3DFX:
1195            return &_mesa_texformat_rgba_fxt1;
1196         default:
1197            ; /* fallthrough */
1198      }
1199   }
1200
1201   if (ctx->Extensions.EXT_texture_compression_s3tc) {
1202      switch (internalFormat) {
1203         case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1204            return &_mesa_texformat_rgb_dxt1;
1205         case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1206            return &_mesa_texformat_rgba_dxt1;
1207         case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1208            return &_mesa_texformat_rgba_dxt3;
1209         case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1210            return &_mesa_texformat_rgba_dxt5;
1211         default:
1212            ; /* fallthrough */
1213      }
1214   }
1215
1216   if (ctx->Extensions.S3_s3tc) {
1217      switch (internalFormat) {
1218         case GL_RGB_S3TC:
1219         case GL_RGB4_S3TC:
1220            return &_mesa_texformat_rgb_dxt1;
1221         case GL_RGBA_S3TC:
1222         case GL_RGBA4_S3TC:
1223            return &_mesa_texformat_rgba_dxt3;
1224         default:
1225            ; /* fallthrough */
1226      }
1227   }
1228
1229   if (ctx->Extensions.ARB_texture_float) {
1230      switch (internalFormat) {
1231         case GL_ALPHA16F_ARB:
1232            return &_mesa_texformat_alpha_float16;
1233         case GL_ALPHA32F_ARB:
1234            return &_mesa_texformat_alpha_float32;
1235         case GL_LUMINANCE16F_ARB:
1236            return &_mesa_texformat_luminance_float16;
1237         case GL_LUMINANCE32F_ARB:
1238            return &_mesa_texformat_luminance_float32;
1239         case GL_LUMINANCE_ALPHA16F_ARB:
1240            return &_mesa_texformat_luminance_alpha_float16;
1241         case GL_LUMINANCE_ALPHA32F_ARB:
1242            return &_mesa_texformat_luminance_alpha_float32;
1243         case GL_INTENSITY16F_ARB:
1244            return &_mesa_texformat_intensity_float16;
1245         case GL_INTENSITY32F_ARB:
1246            return &_mesa_texformat_intensity_float32;
1247         case GL_RGB16F_ARB:
1248            return &_mesa_texformat_rgb_float16;
1249         case GL_RGB32F_ARB:
1250            return &_mesa_texformat_rgb_float32;
1251         case GL_RGBA16F_ARB:
1252            return &_mesa_texformat_rgba_float16;
1253         case GL_RGBA32F_ARB:
1254            return &_mesa_texformat_rgba_float32;
1255         default:
1256            ; /* fallthrough */
1257      }
1258   }
1259
1260   _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
1261   return NULL;
1262}
1263