s,CHAN_BITS/8,sizeof(GLchan),
[mesa.git] / src / mesa / main / texformat.c
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 */
63 static 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
73 static 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
88 const 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
110 const 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
132 const 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
154 const 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
176 const 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
198 const 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
220 const struct gl_texture_format _mesa_texformat_color_index = {
221 MESA_FORMAT_COLOR_INDEX, /* MesaFormat */
222 GL_COLOR_INDEX, /* 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 CHAN_BITS, /* IndexBits */
231 0, /* DepthBits */
232 sizeof(GLchan), /* TexelBytes */
233 _mesa_texstore_color_index, /* StoreTexImageFunc */
234 fetch_texel_1d_color_index, /* FetchTexel1D */
235 fetch_texel_2d_color_index, /* FetchTexel2D */
236 fetch_texel_3d_color_index, /* FetchTexel3D */
237 fetch_texel_1d_f_color_index, /* FetchTexel1Df */
238 fetch_texel_2d_f_color_index, /* FetchTexel2Df */
239 fetch_texel_3d_f_color_index, /* FetchTexel3Df */
240 };
241
242 const struct gl_texture_format _mesa_texformat_depth_component_float32 = {
243 MESA_FORMAT_DEPTH_COMPONENT_FLOAT32, /* 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(GLfloat) * 8, /* DepthBits */
254 sizeof(GLfloat), /* TexelBytes */
255 _mesa_texstore_depth_component_float32,/* StoreTexImageFunc */
256 fetch_null_texel, /* FetchTexel1D */
257 fetch_null_texel, /* FetchTexel1D */
258 fetch_null_texel, /* FetchTexel1D */
259 fetch_texel_1d_f_depth_component_f32,/* FetchTexel1Df */
260 fetch_texel_2d_f_depth_component_f32,/* FetchTexel2Df */
261 fetch_texel_3d_f_depth_component_f32,/* FetchTexel3Df */
262 };
263
264 const struct gl_texture_format _mesa_texformat_depth_component16 = {
265 MESA_FORMAT_DEPTH_COMPONENT16, /* MesaFormat */
266 GL_DEPTH_COMPONENT, /* BaseFormat */
267 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
268 0, /* RedBits */
269 0, /* GreenBits */
270 0, /* BlueBits */
271 0, /* AlphaBits */
272 0, /* LuminanceBits */
273 0, /* IntensityBits */
274 0, /* IndexBits */
275 sizeof(GLushort) * 8, /* DepthBits */
276 sizeof(GLushort), /* TexelBytes */
277 _mesa_texstore_depth_component16, /* StoreTexImageFunc */
278 fetch_null_texel, /* FetchTexel1D */
279 fetch_null_texel, /* FetchTexel1D */
280 fetch_null_texel, /* FetchTexel1D */
281 fetch_texel_1d_f_depth_component16, /* FetchTexel1Df */
282 fetch_texel_2d_f_depth_component16, /* FetchTexel2Df */
283 fetch_texel_3d_f_depth_component16, /* FetchTexel3Df */
284 };
285
286 const struct gl_texture_format _mesa_texformat_rgba_float32 = {
287 MESA_FORMAT_RGBA_FLOAT32, /* MesaFormat */
288 GL_RGBA, /* BaseFormat */
289 GL_FLOAT, /* DataType */
290 8 * sizeof(GLfloat), /* RedBits */
291 8 * sizeof(GLfloat), /* GreenBits */
292 8 * sizeof(GLfloat), /* BlueBits */
293 8 * sizeof(GLfloat), /* AlphaBits */
294 0, /* LuminanceBits */
295 0, /* IntensityBits */
296 0, /* IndexBits */
297 0, /* DepthBits */
298 4 * sizeof(GLfloat), /* TexelBytes */
299 _mesa_texstore_rgba_float32, /* StoreTexImageFunc */
300 fetch_texel_1d_rgba_f32, /* FetchTexel1D */
301 fetch_texel_2d_rgba_f32, /* FetchTexel1D */
302 fetch_texel_3d_rgba_f32, /* FetchTexel1D */
303 fetch_texel_1d_f_rgba_f32, /* FetchTexel1Df */
304 fetch_texel_2d_f_rgba_f32, /* FetchTexel2Df */
305 fetch_texel_3d_f_rgba_f32, /* FetchTexel3Df */
306 };
307
308 const struct gl_texture_format _mesa_texformat_rgba_float16 = {
309 MESA_FORMAT_RGBA_FLOAT16, /* MesaFormat */
310 GL_RGBA, /* BaseFormat */
311 GL_FLOAT, /* DataType */
312 8 * sizeof(GLhalfARB), /* RedBits */
313 8 * sizeof(GLhalfARB), /* GreenBits */
314 8 * sizeof(GLhalfARB), /* BlueBits */
315 8 * sizeof(GLhalfARB), /* AlphaBits */
316 0, /* LuminanceBits */
317 0, /* IntensityBits */
318 0, /* IndexBits */
319 0, /* DepthBits */
320 4 * sizeof(GLhalfARB), /* TexelBytes */
321 _mesa_texstore_rgba_float16, /* StoreTexImageFunc */
322 fetch_texel_1d_rgba_f16, /* FetchTexel1D */
323 fetch_texel_2d_rgba_f16, /* FetchTexel1D */
324 fetch_texel_3d_rgba_f16, /* FetchTexel1D */
325 fetch_texel_1d_f_rgba_f16, /* FetchTexel1Df */
326 fetch_texel_2d_f_rgba_f16, /* FetchTexel2Df */
327 fetch_texel_3d_f_rgba_f16, /* FetchTexel3Df */
328 };
329
330 const struct gl_texture_format _mesa_texformat_rgb_float32 = {
331 MESA_FORMAT_RGB_FLOAT32, /* MesaFormat */
332 GL_RGB, /* BaseFormat */
333 GL_FLOAT, /* DataType */
334 8 * sizeof(GLfloat), /* RedBits */
335 8 * sizeof(GLfloat), /* GreenBits */
336 8 * sizeof(GLfloat), /* BlueBits */
337 0, /* AlphaBits */
338 0, /* LuminanceBits */
339 0, /* IntensityBits */
340 0, /* IndexBits */
341 0, /* DepthBits */
342 3 * sizeof(GLfloat), /* TexelBytes */
343 _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */
344 fetch_texel_1d_rgb_f32, /* FetchTexel1D */
345 fetch_texel_2d_rgb_f32, /* FetchTexel1D */
346 fetch_texel_3d_rgb_f32, /* FetchTexel1D */
347 fetch_texel_1d_f_rgb_f32, /* FetchTexel1Df */
348 fetch_texel_2d_f_rgb_f32, /* FetchTexel2Df */
349 fetch_texel_3d_f_rgb_f32, /* FetchTexel3Df */
350 };
351
352 const struct gl_texture_format _mesa_texformat_rgb_float16 = {
353 MESA_FORMAT_RGB_FLOAT16, /* MesaFormat */
354 GL_RGB, /* BaseFormat */
355 GL_FLOAT, /* DataType */
356 8 * sizeof(GLhalfARB), /* RedBits */
357 8 * sizeof(GLhalfARB), /* GreenBits */
358 8 * sizeof(GLhalfARB), /* BlueBits */
359 0, /* AlphaBits */
360 0, /* LuminanceBits */
361 0, /* IntensityBits */
362 0, /* IndexBits */
363 0, /* DepthBits */
364 3 * sizeof(GLhalfARB), /* TexelBytes */
365 _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */
366 fetch_texel_1d_rgb_f16, /* FetchTexel1D */
367 fetch_texel_2d_rgb_f16, /* FetchTexel1D */
368 fetch_texel_3d_rgb_f16, /* FetchTexel1D */
369 fetch_texel_1d_f_rgb_f16, /* FetchTexel1Df */
370 fetch_texel_2d_f_rgb_f16, /* FetchTexel2Df */
371 fetch_texel_3d_f_rgb_f16 /* FetchTexel3Df */
372 };
373
374 const struct gl_texture_format _mesa_texformat_alpha_float32 = {
375 MESA_FORMAT_ALPHA_FLOAT32, /* MesaFormat */
376 GL_ALPHA, /* BaseFormat */
377 GL_FLOAT, /* DataType */
378 0, /* RedBits */
379 0, /* GreenBits */
380 0, /* BlueBits */
381 8 * sizeof(GLfloat), /* AlphaBits */
382 0, /* LuminanceBits */
383 0, /* IntensityBits */
384 0, /* IndexBits */
385 0, /* DepthBits */
386 1 * sizeof(GLfloat), /* TexelBytes */
387 _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */
388 fetch_texel_1d_alpha_f32, /* FetchTexel1D */
389 fetch_texel_2d_alpha_f32, /* FetchTexel1D */
390 fetch_texel_3d_alpha_f32, /* FetchTexel1D */
391 fetch_texel_1d_f_alpha_f32, /* FetchTexel1Df */
392 fetch_texel_2d_f_alpha_f32, /* FetchTexel2Df */
393 fetch_texel_3d_f_alpha_f32 /* FetchTexel3Df */
394 };
395
396 const struct gl_texture_format _mesa_texformat_alpha_float16 = {
397 MESA_FORMAT_ALPHA_FLOAT16, /* MesaFormat */
398 GL_ALPHA, /* BaseFormat */
399 GL_FLOAT, /* DataType */
400 0, /* RedBits */
401 0, /* GreenBits */
402 0, /* BlueBits */
403 8 * sizeof(GLhalfARB), /* AlphaBits */
404 0, /* LuminanceBits */
405 0, /* IntensityBits */
406 0, /* IndexBits */
407 0, /* DepthBits */
408 1 * sizeof(GLhalfARB), /* TexelBytes */
409 _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */
410 fetch_texel_1d_alpha_f16, /* FetchTexel1D */
411 fetch_texel_2d_alpha_f16, /* FetchTexel1D */
412 fetch_texel_3d_alpha_f16, /* FetchTexel1D */
413 fetch_texel_1d_f_alpha_f16, /* FetchTexel1Df */
414 fetch_texel_2d_f_alpha_f16, /* FetchTexel2Df */
415 fetch_texel_3d_f_alpha_f16 /* FetchTexel3Df */
416 };
417
418 const struct gl_texture_format _mesa_texformat_luminance_float32 = {
419 MESA_FORMAT_LUMINANCE_FLOAT32, /* MesaFormat */
420 GL_LUMINANCE, /* BaseFormat */
421 GL_FLOAT, /* DataType */
422 0, /* RedBits */
423 0, /* GreenBits */
424 0, /* BlueBits */
425 0, /* AlphaBits */
426 8 * sizeof(GLfloat), /* LuminanceBits */
427 0, /* IntensityBits */
428 0, /* IndexBits */
429 0, /* DepthBits */
430 1 * sizeof(GLfloat), /* TexelBytes */
431 _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */
432 fetch_texel_1d_luminance_f32, /* FetchTexel1D */
433 fetch_texel_2d_luminance_f32, /* FetchTexel2D */
434 fetch_texel_3d_luminance_f32, /* FetchTexel3D */
435 fetch_texel_1d_f_luminance_f32, /* FetchTexel1Df */
436 fetch_texel_2d_f_luminance_f32, /* FetchTexel2Df */
437 fetch_texel_3d_f_luminance_f32 /* FetchTexel3Df */
438 };
439
440 const struct gl_texture_format _mesa_texformat_luminance_float16 = {
441 MESA_FORMAT_LUMINANCE_FLOAT16, /* MesaFormat */
442 GL_LUMINANCE, /* BaseFormat */
443 GL_FLOAT, /* DataType */
444 0, /* RedBits */
445 0, /* GreenBits */
446 0, /* BlueBits */
447 0, /* AlphaBits */
448 8 * sizeof(GLhalfARB), /* LuminanceBits */
449 0, /* IntensityBits */
450 0, /* IndexBits */
451 0, /* DepthBits */
452 1 * sizeof(GLhalfARB), /* TexelBytes */
453 _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */
454 fetch_texel_1d_luminance_f16, /* FetchTexel1D */
455 fetch_texel_2d_luminance_f16, /* FetchTexel2D */
456 fetch_texel_3d_luminance_f16, /* FetchTexel3D */
457 fetch_texel_1d_f_luminance_f16, /* FetchTexel1Df */
458 fetch_texel_2d_f_luminance_f16, /* FetchTexel2Df */
459 fetch_texel_3d_f_luminance_f16 /* FetchTexel3Df */
460 };
461
462 const struct gl_texture_format _mesa_texformat_luminance_alpha_float32 = {
463 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, /* MesaFormat */
464 GL_LUMINANCE_ALPHA, /* BaseFormat */
465 GL_FLOAT, /* DataType */
466 0, /* RedBits */
467 0, /* GreenBits */
468 0, /* BlueBits */
469 8 * sizeof(GLfloat), /* AlphaBits */
470 8 * sizeof(GLfloat), /* LuminanceBits */
471 0, /* IntensityBits */
472 0, /* IndexBits */
473 0, /* DepthBits */
474 2 * sizeof(GLfloat), /* TexelBytes */
475 _mesa_texstore_rgba_float32, /* StoreTexImageFunc */
476 fetch_texel_1d_luminance_alpha_f32, /* FetchTexel1D */
477 fetch_texel_2d_luminance_alpha_f32, /* FetchTexel2D */
478 fetch_texel_3d_luminance_alpha_f32, /* FetchTexel3D */
479 fetch_texel_1d_f_luminance_alpha_f32,/* FetchTexel1Df */
480 fetch_texel_2d_f_luminance_alpha_f32,/* FetchTexel2Df */
481 fetch_texel_3d_f_luminance_alpha_f32 /* FetchTexel3Df */
482 };
483
484 const struct gl_texture_format _mesa_texformat_luminance_alpha_float16 = {
485 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, /* MesaFormat */
486 GL_LUMINANCE_ALPHA, /* BaseFormat */
487 GL_FLOAT, /* DataType */
488 0, /* RedBits */
489 0, /* GreenBits */
490 0, /* BlueBits */
491 8 * sizeof(GLhalfARB), /* AlphaBits */
492 8 * sizeof(GLhalfARB), /* LuminanceBits */
493 0, /* IntensityBits */
494 0, /* IndexBits */
495 0, /* DepthBits */
496 2 * sizeof(GLhalfARB), /* TexelBytes */
497 _mesa_texstore_rgba_float16, /* StoreTexImageFunc */
498 fetch_texel_1d_luminance_alpha_f16, /* FetchTexel1D */
499 fetch_texel_2d_luminance_alpha_f16, /* FetchTexel2D */
500 fetch_texel_3d_luminance_alpha_f16, /* FetchTexel3D */
501 fetch_texel_1d_f_luminance_alpha_f16,/* FetchTexel1Df */
502 fetch_texel_2d_f_luminance_alpha_f16,/* FetchTexel2Df */
503 fetch_texel_3d_f_luminance_alpha_f16 /* FetchTexel3Df */
504 };
505
506 const struct gl_texture_format _mesa_texformat_intensity_float32 = {
507 MESA_FORMAT_INTENSITY_FLOAT32, /* 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(GLfloat), /* IntensityBits */
516 0, /* IndexBits */
517 0, /* DepthBits */
518 1 * sizeof(GLfloat), /* TexelBytes */
519 _mesa_texstore_rgba_float32,/*yes*/ /* StoreTexImageFunc */
520 fetch_texel_1d_intensity_f32, /* FetchTexel1D */
521 fetch_texel_2d_intensity_f32, /* FetchTexel2D */
522 fetch_texel_3d_intensity_f32, /* FetchTexel3D */
523 fetch_texel_1d_f_intensity_f32, /* FetchTexel1Df */
524 fetch_texel_2d_f_intensity_f32, /* FetchTexel2Df */
525 fetch_texel_3d_f_intensity_f32 /* FetchTexel3Df */
526 };
527
528 const struct gl_texture_format _mesa_texformat_intensity_float16 = {
529 MESA_FORMAT_INTENSITY_FLOAT16, /* MesaFormat */
530 GL_INTENSITY, /* BaseFormat */
531 GL_FLOAT, /* DataType */
532 0, /* RedBits */
533 0, /* GreenBits */
534 0, /* BlueBits */
535 0, /* AlphaBits */
536 0, /* LuminanceBits */
537 8 * sizeof(GLhalfARB), /* IntensityBits */
538 0, /* IndexBits */
539 0, /* DepthBits */
540 1 * sizeof(GLhalfARB), /* TexelBytes */
541 _mesa_texstore_rgba_float16,/*yes*/ /* StoreTexImageFunc */
542 fetch_texel_1d_intensity_f16, /* FetchTexel1D */
543 fetch_texel_2d_intensity_f16, /* FetchTexel2D */
544 fetch_texel_3d_intensity_f16, /* FetchTexel3D */
545 fetch_texel_1d_f_intensity_f16, /* FetchTexel1Df */
546 fetch_texel_2d_f_intensity_f16, /* FetchTexel2Df */
547 fetch_texel_3d_f_intensity_f16 /* FetchTexel3Df */
548 };
549
550
551 /*@}*/
552
553
554 /***************************************************************/
555 /** \name Hardware formats */
556 /*@{*/
557
558 const struct gl_texture_format _mesa_texformat_rgba8888 = {
559 MESA_FORMAT_RGBA8888, /* 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, /* FetchTexel1D */
573 fetch_texel_2d_rgba8888, /* FetchTexel2D */
574 fetch_texel_3d_rgba8888, /* FetchTexel3D */
575 fetch_texel_1d_f_rgba8888, /* FetchTexel1Df */
576 fetch_texel_2d_f_rgba8888, /* FetchTexel2Df */
577 fetch_texel_3d_f_rgba8888, /* FetchTexel3Df */
578 };
579
580 const 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
602 const struct gl_texture_format _mesa_texformat_rgb888 = {
603 MESA_FORMAT_RGB888, /* MesaFormat */
604 GL_RGB, /* BaseFormat */
605 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
606 8, /* RedBits */
607 8, /* GreenBits */
608 8, /* BlueBits */
609 0, /* AlphaBits */
610 0, /* LuminanceBits */
611 0, /* IntensityBits */
612 0, /* IndexBits */
613 0, /* DepthBits */
614 3, /* TexelBytes */
615 _mesa_texstore_rgb888, /* StoreTexImageFunc */
616 fetch_texel_1d_rgb888, /* FetchTexel1D */
617 fetch_texel_2d_rgb888, /* FetchTexel2D */
618 fetch_texel_3d_rgb888, /* FetchTexel3D */
619 fetch_texel_1d_f_rgb888, /* FetchTexel1Df */
620 fetch_texel_2d_f_rgb888, /* FetchTexel2Df */
621 fetch_texel_3d_f_rgb888, /* FetchTexel3Df */
622 };
623
624 const struct gl_texture_format _mesa_texformat_rgb565 = {
625 MESA_FORMAT_RGB565, /* MesaFormat */
626 GL_RGB, /* BaseFormat */
627 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
628 5, /* RedBits */
629 6, /* GreenBits */
630 5, /* BlueBits */
631 0, /* AlphaBits */
632 0, /* LuminanceBits */
633 0, /* IntensityBits */
634 0, /* IndexBits */
635 0, /* DepthBits */
636 2, /* TexelBytes */
637 _mesa_texstore_rgb565, /* StoreTexImageFunc */
638 fetch_texel_1d_rgb565, /* FetchTexel1D */
639 fetch_texel_2d_rgb565, /* FetchTexel2D */
640 fetch_texel_3d_rgb565, /* FetchTexel3D */
641 fetch_texel_1d_f_rgb565, /* FetchTexel1Df */
642 fetch_texel_2d_f_rgb565, /* FetchTexel2Df */
643 fetch_texel_3d_f_rgb565, /* FetchTexel3Df */
644 };
645
646 const struct gl_texture_format _mesa_texformat_argb4444 = {
647 MESA_FORMAT_ARGB4444, /* MesaFormat */
648 GL_RGBA, /* BaseFormat */
649 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
650 4, /* RedBits */
651 4, /* GreenBits */
652 4, /* BlueBits */
653 4, /* AlphaBits */
654 0, /* LuminanceBits */
655 0, /* IntensityBits */
656 0, /* IndexBits */
657 0, /* DepthBits */
658 2, /* TexelBytes */
659 _mesa_texstore_argb4444, /* StoreTexImageFunc */
660 fetch_texel_1d_argb4444, /* FetchTexel1D */
661 fetch_texel_2d_argb4444, /* FetchTexel2D */
662 fetch_texel_3d_argb4444, /* FetchTexel3D */
663 fetch_texel_1d_f_argb4444, /* FetchTexel1Df */
664 fetch_texel_2d_f_argb4444, /* FetchTexel2Df */
665 fetch_texel_3d_f_argb4444, /* FetchTexel3Df */
666 };
667
668 const struct gl_texture_format _mesa_texformat_argb1555 = {
669 MESA_FORMAT_ARGB1555, /* MesaFormat */
670 GL_RGBA, /* BaseFormat */
671 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
672 5, /* RedBits */
673 5, /* GreenBits */
674 5, /* BlueBits */
675 1, /* AlphaBits */
676 0, /* LuminanceBits */
677 0, /* IntensityBits */
678 0, /* IndexBits */
679 0, /* DepthBits */
680 2, /* TexelBytes */
681 _mesa_texstore_argb1555, /* StoreTexImageFunc */
682 fetch_texel_1d_argb1555, /* FetchTexel1D */
683 fetch_texel_2d_argb1555, /* FetchTexel2D */
684 fetch_texel_3d_argb1555, /* FetchTexel3D */
685 fetch_texel_1d_f_argb1555, /* FetchTexel1Df */
686 fetch_texel_2d_f_argb1555, /* FetchTexel2Df */
687 fetch_texel_3d_f_argb1555, /* FetchTexel3Df */
688 };
689
690 const struct gl_texture_format _mesa_texformat_al88 = {
691 MESA_FORMAT_AL88, /* MesaFormat */
692 GL_LUMINANCE_ALPHA, /* BaseFormat */
693 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
694 0, /* RedBits */
695 0, /* GreenBits */
696 0, /* BlueBits */
697 8, /* AlphaBits */
698 8, /* LuminanceBits */
699 0, /* IntensityBits */
700 0, /* IndexBits */
701 0, /* DepthBits */
702 2, /* TexelBytes */
703 _mesa_texstore_al88, /* StoreTexImageFunc */
704 fetch_texel_1d_al88, /* FetchTexel1D */
705 fetch_texel_2d_al88, /* FetchTexel2D */
706 fetch_texel_3d_al88, /* FetchTexel3D */
707 fetch_texel_1d_f_al88, /* FetchTexel1Df */
708 fetch_texel_2d_f_al88, /* FetchTexel2Df */
709 fetch_texel_3d_f_al88, /* FetchTexel3Df */
710 };
711
712 const struct gl_texture_format _mesa_texformat_rgb332 = {
713 MESA_FORMAT_RGB332, /* MesaFormat */
714 GL_RGB, /* BaseFormat */
715 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
716 3, /* RedBits */
717 3, /* GreenBits */
718 2, /* BlueBits */
719 0, /* AlphaBits */
720 0, /* LuminanceBits */
721 0, /* IntensityBits */
722 0, /* IndexBits */
723 0, /* DepthBits */
724 1, /* TexelBytes */
725 _mesa_texstore_rgb332, /* StoreTexImageFunc */
726 fetch_texel_1d_rgb332, /* FetchTexel1D */
727 fetch_texel_2d_rgb332, /* FetchTexel2D */
728 fetch_texel_3d_rgb332, /* FetchTexel3D */
729 fetch_texel_1d_f_rgb332, /* FetchTexel1Df */
730 fetch_texel_2d_f_rgb332, /* FetchTexel2Df */
731 fetch_texel_3d_f_rgb332, /* FetchTexel3Df */
732 };
733
734 const struct gl_texture_format _mesa_texformat_a8 = {
735 MESA_FORMAT_A8, /* MesaFormat */
736 GL_ALPHA, /* BaseFormat */
737 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
738 0, /* RedBits */
739 0, /* GreenBits */
740 0, /* BlueBits */
741 8, /* AlphaBits */
742 0, /* LuminanceBits */
743 0, /* IntensityBits */
744 0, /* IndexBits */
745 0, /* DepthBits */
746 1, /* TexelBytes */
747 _mesa_texstore_a8, /* StoreTexImageFunc */
748 fetch_texel_1d_a8, /* FetchTexel1D */
749 fetch_texel_2d_a8, /* FetchTexel2D */
750 fetch_texel_3d_a8, /* FetchTexel3D */
751 fetch_texel_1d_f_a8, /* FetchTexel1Df */
752 fetch_texel_2d_f_a8, /* FetchTexel2Df */
753 fetch_texel_3d_f_a8, /* FetchTexel3Df */
754 };
755
756 const struct gl_texture_format _mesa_texformat_l8 = {
757 MESA_FORMAT_L8, /* MesaFormat */
758 GL_LUMINANCE, /* BaseFormat */
759 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
760 0, /* RedBits */
761 0, /* GreenBits */
762 0, /* BlueBits */
763 0, /* AlphaBits */
764 8, /* LuminanceBits */
765 0, /* IntensityBits */
766 0, /* IndexBits */
767 0, /* DepthBits */
768 1, /* TexelBytes */
769 _mesa_texstore_a8,/*yes*/ /* StoreTexImageFunc */
770 fetch_texel_1d_l8, /* FetchTexel1D */
771 fetch_texel_2d_l8, /* FetchTexel2D */
772 fetch_texel_3d_l8, /* FetchTexel3D */
773 fetch_texel_1d_f_l8, /* FetchTexel1Df */
774 fetch_texel_2d_f_l8, /* FetchTexel2Df */
775 fetch_texel_3d_f_l8, /* FetchTexel3Df */
776 };
777
778 const struct gl_texture_format _mesa_texformat_i8 = {
779 MESA_FORMAT_I8, /* MesaFormat */
780 GL_INTENSITY, /* BaseFormat */
781 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
782 0, /* RedBits */
783 0, /* GreenBits */
784 0, /* BlueBits */
785 0, /* AlphaBits */
786 0, /* LuminanceBits */
787 8, /* IntensityBits */
788 0, /* IndexBits */
789 0, /* DepthBits */
790 1, /* TexelBytes */
791 _mesa_texstore_a8,/*yes*/ /* StoreTexImageFunc */
792 fetch_texel_1d_i8, /* FetchTexel1D */
793 fetch_texel_2d_i8, /* FetchTexel2D */
794 fetch_texel_3d_i8, /* FetchTexel3D */
795 fetch_texel_1d_f_i8, /* FetchTexel1Df */
796 fetch_texel_2d_f_i8, /* FetchTexel2Df */
797 fetch_texel_3d_f_i8, /* FetchTexel3Df */
798 };
799
800 const struct gl_texture_format _mesa_texformat_ci8 = {
801 MESA_FORMAT_CI8, /* MesaFormat */
802 GL_COLOR_INDEX, /* BaseFormat */
803 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
804 0, /* RedBits */
805 0, /* GreenBits */
806 0, /* BlueBits */
807 0, /* AlphaBits */
808 0, /* LuminanceBits */
809 0, /* IntensityBits */
810 8, /* IndexBits */
811 0, /* DepthBits */
812 1, /* TexelBytes */
813 _mesa_texstore_ci8, /* StoreTexImageFunc */
814 fetch_texel_1d_ci8, /* FetchTexel1D */
815 fetch_texel_2d_ci8, /* FetchTexel2D */
816 fetch_texel_3d_ci8, /* FetchTexel3D */
817 fetch_texel_1d_f_ci8, /* FetchTexel1Df */
818 fetch_texel_2d_f_ci8, /* FetchTexel2Df */
819 fetch_texel_3d_f_ci8, /* FetchTexel3Df */
820 };
821
822 const struct gl_texture_format _mesa_texformat_ycbcr = {
823 MESA_FORMAT_YCBCR, /* MesaFormat */
824 GL_YCBCR_MESA, /* BaseFormat */
825 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
826 0, /* RedBits */
827 0, /* GreenBits */
828 0, /* BlueBits */
829 0, /* AlphaBits */
830 0, /* LuminanceBits */
831 0, /* IntensityBits */
832 0, /* IndexBits */
833 0, /* DepthBits */
834 2, /* TexelBytes */
835 _mesa_texstore_ycbcr, /* StoreTexImageFunc */
836 fetch_texel_1d_ycbcr, /* FetchTexel1D */
837 fetch_texel_2d_ycbcr, /* FetchTexel2D */
838 fetch_texel_3d_ycbcr, /* FetchTexel3D */
839 fetch_texel_1d_f_ycbcr, /* FetchTexel1Df */
840 fetch_texel_2d_f_ycbcr, /* FetchTexel2Df */
841 fetch_texel_3d_f_ycbcr, /* FetchTexel3Df */
842 };
843
844 const struct gl_texture_format _mesa_texformat_ycbcr_rev = {
845 MESA_FORMAT_YCBCR_REV, /* MesaFormat */
846 GL_YCBCR_MESA, /* BaseFormat */
847 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
848 0, /* RedBits */
849 0, /* GreenBits */
850 0, /* BlueBits */
851 0, /* AlphaBits */
852 0, /* LuminanceBits */
853 0, /* IntensityBits */
854 0, /* IndexBits */
855 0, /* DepthBits */
856 2, /* TexelBytes */
857 _mesa_texstore_ycbcr, /* StoreTexImageFunc */
858 fetch_texel_1d_ycbcr_rev, /* FetchTexel1D */
859 fetch_texel_2d_ycbcr_rev, /* FetchTexel2D */
860 fetch_texel_3d_ycbcr_rev, /* FetchTexel3D */
861 fetch_texel_1d_f_ycbcr_rev, /* FetchTexel1Df */
862 fetch_texel_2d_f_ycbcr_rev, /* FetchTexel2Df */
863 fetch_texel_3d_f_ycbcr_rev, /* FetchTexel3Df */
864 };
865
866 const struct gl_texture_format _mesa_texformat_rgb_fxt1 = {
867 MESA_FORMAT_RGB_FXT1, /* MesaFormat */
868 GL_RGB, /* BaseFormat */
869 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
870 4, /*approx*/ /* RedBits */
871 4, /*approx*/ /* GreenBits */
872 4, /*approx*/ /* BlueBits */
873 0, /* AlphaBits */
874 0, /* LuminanceBits */
875 0, /* IntensityBits */
876 0, /* IndexBits */
877 0, /* DepthBits */
878 0, /* TexelBytes */
879 NULL, /* StoreTexImageFunc */
880 NULL, /*impossible*/ /* FetchTexel1D */
881 fetch_texel_2d_rgb_fxt1, /* FetchTexel2D */
882 NULL, /*impossible*/ /* FetchTexel3D */
883 NULL, /*impossible*/ /* FetchTexel1Df */
884 fetch_texel_2d_f_rgb_fxt1, /* FetchTexel2Df */
885 NULL, /*impossible*/ /* FetchTexel3Df */
886 };
887
888 const struct gl_texture_format _mesa_texformat_rgba_fxt1 = {
889 MESA_FORMAT_RGBA_FXT1, /* MesaFormat */
890 GL_RGBA, /* BaseFormat */
891 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
892 4, /*approx*/ /* RedBits */
893 4, /*approx*/ /* GreenBits */
894 4, /*approx*/ /* BlueBits */
895 1, /*approx*/ /* AlphaBits */
896 0, /* LuminanceBits */
897 0, /* IntensityBits */
898 0, /* IndexBits */
899 0, /* DepthBits */
900 0, /* TexelBytes */
901 NULL, /* StoreTexImageFunc */
902 NULL, /*impossible*/ /* FetchTexel1D */
903 fetch_texel_2d_rgba_fxt1, /* FetchTexel2D */
904 NULL, /*impossible*/ /* FetchTexel3D */
905 NULL, /*impossible*/ /* FetchTexel1Df */
906 fetch_texel_2d_f_rgba_fxt1, /* FetchTexel2Df */
907 NULL, /*impossible*/ /* FetchTexel3Df */
908 };
909
910 const struct gl_texture_format _mesa_texformat_rgb_dxt1 = {
911 MESA_FORMAT_RGB_DXT1, /* MesaFormat */
912 GL_RGB, /* BaseFormat */
913 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
914 4, /*approx*/ /* RedBits */
915 4, /*approx*/ /* GreenBits */
916 4, /*approx*/ /* BlueBits */
917 0, /* AlphaBits */
918 0, /* LuminanceBits */
919 0, /* IntensityBits */
920 0, /* IndexBits */
921 0, /* DepthBits */
922 0, /* TexelBytes */
923 NULL, /* StoreTexImageFunc */
924 NULL, /*impossible*/ /* FetchTexel1D */
925 fetch_texel_2d_rgb_dxt1, /* FetchTexel2D */
926 NULL, /*impossible*/ /* FetchTexel3D */
927 NULL, /*impossible*/ /* FetchTexel1Df */
928 fetch_texel_2d_f_rgb_dxt1, /* FetchTexel2Df */
929 NULL, /*impossible*/ /* FetchTexel3Df */
930 };
931
932 const struct gl_texture_format _mesa_texformat_rgba_dxt1 = {
933 MESA_FORMAT_RGBA_DXT1, /* MesaFormat */
934 GL_RGBA, /* BaseFormat */
935 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
936 4, /*approx*/ /* RedBits */
937 4, /*approx*/ /* GreenBits */
938 4, /*approx*/ /* BlueBits */
939 1, /*approx*/ /* AlphaBits */
940 0, /* LuminanceBits */
941 0, /* IntensityBits */
942 0, /* IndexBits */
943 0, /* DepthBits */
944 0, /* TexelBytes */
945 NULL, /* StoreTexImageFunc */
946 NULL, /*impossible*/ /* FetchTexel1D */
947 fetch_texel_2d_rgba_dxt1, /* FetchTexel2D */
948 NULL, /*impossible*/ /* FetchTexel3D */
949 NULL, /*impossible*/ /* FetchTexel1Df */
950 fetch_texel_2d_f_rgba_dxt1, /* FetchTexel2Df */
951 NULL, /*impossible*/ /* FetchTexel3Df */
952 };
953
954 const struct gl_texture_format _mesa_texformat_rgba_dxt3 = {
955 MESA_FORMAT_RGBA_DXT3, /* MesaFormat */
956 GL_RGBA, /* BaseFormat */
957 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
958 4, /*approx*/ /* RedBits */
959 4, /*approx*/ /* GreenBits */
960 4, /*approx*/ /* BlueBits */
961 4, /*approx*/ /* AlphaBits */
962 0, /* LuminanceBits */
963 0, /* IntensityBits */
964 0, /* IndexBits */
965 0, /* DepthBits */
966 0, /* TexelBytes */
967 NULL, /* StoreTexImageFunc */
968 NULL, /*impossible*/ /* FetchTexel1D */
969 fetch_texel_2d_rgba_dxt3, /* FetchTexel2D */
970 NULL, /*impossible*/ /* FetchTexel3D */
971 NULL, /*impossible*/ /* FetchTexel1Df */
972 fetch_texel_2d_f_rgba_dxt3, /* FetchTexel2Df */
973 NULL, /*impossible*/ /* FetchTexel3Df */
974 };
975
976 const struct gl_texture_format _mesa_texformat_rgba_dxt5 = {
977 MESA_FORMAT_RGBA_DXT5, /* MesaFormat */
978 GL_RGBA, /* BaseFormat */
979 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
980 4,/*approx*/ /* RedBits */
981 4,/*approx*/ /* GreenBits */
982 4,/*approx*/ /* BlueBits */
983 4,/*approx*/ /* AlphaBits */
984 0, /* LuminanceBits */
985 0, /* IntensityBits */
986 0, /* IndexBits */
987 0, /* DepthBits */
988 0, /* TexelBytes */
989 NULL, /* StoreTexImageFunc */
990 NULL, /*impossible*/ /* FetchTexel1D */
991 fetch_texel_2d_rgba_dxt5, /* FetchTexel2D */
992 NULL, /*impossible*/ /* FetchTexel3D */
993 NULL, /*impossible*/ /* FetchTexel1Df */
994 fetch_texel_2d_f_rgba_dxt5, /* FetchTexel2Df */
995 NULL, /*impossible*/ /* FetchTexel3Df */
996 };
997
998
999 /* Big-endian */
1000 #if 0
1001 const struct gl_texture_format _mesa_texformat_abgr8888 = {
1002 MESA_FORMAT_ABGR8888, /* MesaFormat */
1003 GL_RGBA, /* BaseFormat */
1004 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1005 8, /* RedBits */
1006 8, /* GreenBits */
1007 8, /* BlueBits */
1008 8, /* AlphaBits */
1009 0, /* LuminanceBits */
1010 0, /* IntensityBits */
1011 0, /* IndexBits */
1012 0, /* DepthBits */
1013 4, /* TexelBytes */
1014 NULL, /* StoreTexImageFunc */
1015 fetch_texel_1d_abgr8888, /* FetchTexel1D */
1016 fetch_texel_2d_abgr8888, /* FetchTexel2D */
1017 fetch_texel_3d_abgr8888, /* FetchTexel3D */
1018 /* XXX float fetchers */
1019 };
1020
1021 const struct gl_texture_format _mesa_texformat_bgra8888 = {
1022 MESA_FORMAT_BGRA8888, /* MesaFormat */
1023 GL_RGBA, /* BaseFormat */
1024 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1025 GL_UNSIGNED_INT_8_8_8_8, /* Type */
1026 8, /* RedBits */
1027 8, /* GreenBits */
1028 8, /* BlueBits */
1029 8, /* AlphaBits */
1030 0, /* LuminanceBits */
1031 0, /* IntensityBits */
1032 0, /* IndexBits */
1033 0, /* DepthBits */
1034 4, /* TexelBytes */
1035 NULL, /* StoreTexImageFunc */
1036 fetch_texel_1d_bgra8888, /* FetchTexel1D */
1037 fetch_texel_2d_bgra8888, /* FetchTexel2D */
1038 fetch_texel_3d_bgra8888, /* FetchTexel3D */
1039 /* XXX float fetchers */
1040 };
1041
1042 const struct gl_texture_format _mesa_texformat_bgr888 = {
1043 MESA_FORMAT_BGR888, /* MesaFormat */
1044 GL_RGB, /* BaseFormat */
1045 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1046 GL_UNSIGNED_BYTE, /* Type */
1047 8, /* RedBits */
1048 8, /* GreenBits */
1049 8, /* BlueBits */
1050 0, /* AlphaBits */
1051 0, /* LuminanceBits */
1052 0, /* IntensityBits */
1053 0, /* IndexBits */
1054 0, /* DepthBits */
1055 3, /* TexelBytes */
1056 NULL, /* StoreTexImageFunc */
1057 fetch_texel_1d_bgr888, /* FetchTexel1D */
1058 fetch_texel_2d_bgr888, /* FetchTexel2D */
1059 fetch_texel_3d_bgr888, /* FetchTexel3D */
1060 /* XXX float fetchers */
1061 };
1062
1063 const struct gl_texture_format _mesa_texformat_bgr565 = {
1064 MESA_FORMAT_BGR565, /* MesaFormat */
1065 GL_RGB, /* BaseFormat */
1066 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1067 GL_UNSIGNED_SHORT_5_6_5, /* Type */
1068 5, /* RedBits */
1069 6, /* GreenBits */
1070 5, /* BlueBits */
1071 0, /* AlphaBits */
1072 0, /* LuminanceBits */
1073 0, /* IntensityBits */
1074 0, /* IndexBits */
1075 0, /* DepthBits */
1076 2, /* TexelBytes */
1077 NULL, /* StoreTexImageFunc */
1078 fetch_texel_1d_bgr565, /* FetchTexel1D */
1079 fetch_texel_2d_bgr565, /* FetchTexel2D */
1080 fetch_texel_3d_bgr565, /* FetchTexel3D */
1081 /* XXX float fetchers */
1082 };
1083
1084 const struct gl_texture_format _mesa_texformat_bgra4444 = {
1085 MESA_FORMAT_BGRA4444, /* MesaFormat */
1086 GL_RGBA, /* BaseFormat */
1087 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1088 GL_UNSIGNED_SHORT_4_4_4_4_REV, /* Type */
1089 4, /* RedBits */
1090 4, /* GreenBits */
1091 4, /* BlueBits */
1092 4, /* AlphaBits */
1093 0, /* LuminanceBits */
1094 0, /* IntensityBits */
1095 0, /* IndexBits */
1096 0, /* DepthBits */
1097 2, /* TexelBytes */
1098 NULL, /* StoreTexImageFunc */
1099 fetch_texel_1d_bgra4444, /* FetchTexel1D */
1100 fetch_texel_2d_bgra4444, /* FetchTexel2D */
1101 fetch_texel_3d_bgra4444, /* FetchTexel3D */
1102 /* XXX float fetchers */
1103 };
1104
1105 const struct gl_texture_format _mesa_texformat_bgra5551 = {
1106 MESA_FORMAT_BGRA5551, /* MesaFormat */
1107 GL_RGBA, /* BaseFormat */
1108 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1109 GL_UNSIGNED_SHORT_1_5_5_5_REV, /* Type */
1110 5, /* RedBits */
1111 5, /* GreenBits */
1112 5, /* BlueBits */
1113 1, /* AlphaBits */
1114 0, /* LuminanceBits */
1115 0, /* IntensityBits */
1116 0, /* IndexBits */
1117 0, /* DepthBits */
1118 2, /* TexelBytes */
1119 NULL, /* StoreTexImageFunc */
1120 fetch_texel_1d_bgra1555, /* FetchTexel1D */
1121 fetch_texel_2d_bgra1555, /* FetchTexel2D */
1122 fetch_texel_3d_bgra1555, /* FetchTexel3D */
1123 /* XXX float fetchers */
1124 };
1125
1126 const struct gl_texture_format _mesa_texformat_la88 = {
1127 MESA_FORMAT_LA88, /* MesaFormat */
1128 GL_LUMINANCE_ALPHA, /* BaseFormat */
1129 GL_UNSIGNED_NORMALIZED_ARB, /* DataType */
1130 GL_UNSIGNED_BYTE, /* Type */
1131 0, /* RedBits */
1132 0, /* GreenBits */
1133 0, /* BlueBits */
1134 8, /* AlphaBits */
1135 8, /* LuminanceBits */
1136 0, /* IntensityBits */
1137 0, /* IndexBits */
1138 0, /* DepthBits */
1139 2, /* TexelBytes */
1140 NULL, /* StoreTexImageFunc */
1141 fetch_texel_1d_la88, /* FetchTexel1D */
1142 fetch_texel_2d_la88, /* FetchTexel2D */
1143 fetch_texel_3d_la88, /* FetchTexel3D */
1144 /* XXX float fetchers */
1145 };
1146
1147 const struct gl_texture_format _mesa_texformat_bgr233 = {
1148 MESA_FORMAT_BGR233, /* MesaFormat */
1149 GL_RGB, /* BaseFormat */
1150 GL_UNSIGNED_NORMALIZED_ARB /* DataType */
1151 GL_UNSIGNED_BYTE_3_3_2, /* Type */
1152 3, /* RedBits */
1153 3, /* GreenBits */
1154 2, /* BlueBits */
1155 0, /* AlphaBits */
1156 0, /* LuminanceBits */
1157 0, /* IntensityBits */
1158 0, /* IndexBits */
1159 0, /* DepthBits */
1160 1, /* TexelBytes */
1161 NULL, /* StoreTexImageFunc */
1162 fetch_texel_1d_bgr233, /* FetchTexel1D */
1163 fetch_texel_2d_bgr233, /* FetchTexel2D */
1164 fetch_texel_3d_bgr233, /* FetchTexel3D */
1165 /* XXX float fetchers */
1166 };
1167 #endif
1168
1169 /*@}*/
1170
1171
1172 /***************************************************************/
1173 /** \name Null format (useful for proxy textures) */
1174 /*@{*/
1175
1176 const struct gl_texture_format _mesa_null_texformat = {
1177 -1, /* MesaFormat */
1178 0, /* BaseFormat */
1179 GL_NONE, /* DataType */
1180 0, /* RedBits */
1181 0, /* GreenBits */
1182 0, /* BlueBits */
1183 0, /* AlphaBits */
1184 0, /* LuminanceBits */
1185 0, /* IntensityBits */
1186 0, /* IndexBits */
1187 0, /* DepthBits */
1188 0, /* TexelBytes */
1189 NULL, /* StoreTexImageFunc */
1190 fetch_null_texel, /* FetchTexel1D */
1191 fetch_null_texel, /* FetchTexel2D */
1192 fetch_null_texel, /* FetchTexel3D */
1193 fetch_null_texelf, /* FetchTexel1Df */
1194 fetch_null_texelf, /* FetchTexel2Df */
1195 fetch_null_texelf, /* FetchTexel3Df */
1196 };
1197
1198 /*@}*/
1199
1200
1201 #if !NEWTEXSTORE
1202 /**
1203 * Determine whether a given texture format is a hardware texture
1204 * format.
1205 *
1206 * \param format texture format.
1207 *
1208 * \return GL_TRUE if \p format is a hardware texture format, or GL_FALSE
1209 * otherwise.
1210 *
1211 * \p format is a hardware texture format if gl_texture_format::MesaFormat is
1212 * lower than _format::MESA_FORMAT_RGBA.
1213 */
1214 GLboolean
1215 _mesa_is_hardware_tex_format( const struct gl_texture_format *format )
1216 {
1217 return (format->MesaFormat < MESA_FORMAT_RGBA);
1218 }
1219 #endif
1220
1221
1222 /**
1223 * Choose an appropriate texture format given the format, type and
1224 * internalFormat parameters passed to glTexImage().
1225 *
1226 * \param ctx the GL context.
1227 * \param internalFormat user's prefered internal texture format.
1228 * \param format incoming image pixel format.
1229 * \param type incoming image data type.
1230 *
1231 * \return a pointer to a gl_texture_format object which describes the
1232 * choosen texture format, or NULL on failure.
1233 *
1234 * This is called via dd_function_table::ChooseTextureFormat. Hardware drivers
1235 * will typically override this function with a specialized version.
1236 */
1237 const struct gl_texture_format *
1238 _mesa_choose_tex_format( GLcontext *ctx, GLint internalFormat,
1239 GLenum format, GLenum type )
1240 {
1241 (void) format;
1242 (void) type;
1243
1244 switch (internalFormat) {
1245 /* RGBA formats */
1246 case 4:
1247 case GL_RGBA:
1248 case GL_RGBA8:
1249 case GL_RGB10_A2:
1250 case GL_RGBA12:
1251 case GL_RGBA16:
1252 return &_mesa_texformat_rgba;
1253 case GL_RGB5_A1:
1254 return &_mesa_texformat_argb1555;
1255 case GL_RGBA2:
1256 case GL_RGBA4:
1257 return &_mesa_texformat_argb4444;
1258
1259 /* RGB formats */
1260 case 3:
1261 case GL_RGB:
1262 case GL_RGB8:
1263 case GL_RGB10:
1264 case GL_RGB12:
1265 case GL_RGB16:
1266 return &_mesa_texformat_rgb;
1267 case GL_R3_G3_B2:
1268 return &_mesa_texformat_rgb332;
1269 case GL_RGB4:
1270 case GL_RGB5:
1271 return &_mesa_texformat_rgb565;
1272
1273 /* Alpha formats */
1274 case GL_ALPHA:
1275 case GL_ALPHA4:
1276 case GL_ALPHA8:
1277 case GL_ALPHA12:
1278 case GL_ALPHA16:
1279 return &_mesa_texformat_alpha;
1280
1281 /* Luminance formats */
1282 case 1:
1283 case GL_LUMINANCE:
1284 case GL_LUMINANCE4:
1285 case GL_LUMINANCE12:
1286 case GL_LUMINANCE16:
1287 return &_mesa_texformat_luminance;
1288 case GL_LUMINANCE8:
1289 return &_mesa_texformat_l8;
1290
1291 /* Luminance/Alpha formats */
1292 case 2:
1293 case GL_LUMINANCE_ALPHA:
1294 case GL_LUMINANCE4_ALPHA4:
1295 case GL_LUMINANCE6_ALPHA2:
1296 case GL_LUMINANCE12_ALPHA4:
1297 case GL_LUMINANCE12_ALPHA12:
1298 case GL_LUMINANCE16_ALPHA16:
1299 return &_mesa_texformat_luminance_alpha;
1300 case GL_LUMINANCE8_ALPHA8:
1301 return &_mesa_texformat_al88;
1302
1303 case GL_INTENSITY:
1304 case GL_INTENSITY4:
1305 case GL_INTENSITY12:
1306 case GL_INTENSITY16:
1307 return &_mesa_texformat_intensity;
1308 case GL_INTENSITY8:
1309 return &_mesa_texformat_i8;
1310
1311 case GL_COLOR_INDEX:
1312 case GL_COLOR_INDEX1_EXT:
1313 case GL_COLOR_INDEX2_EXT:
1314 case GL_COLOR_INDEX4_EXT:
1315 case GL_COLOR_INDEX12_EXT:
1316 case GL_COLOR_INDEX16_EXT:
1317 return &_mesa_texformat_color_index;
1318 case GL_COLOR_INDEX8_EXT:
1319 return &_mesa_texformat_ci8;
1320
1321 default:
1322 ; /* fallthrough */
1323 }
1324
1325 if (ctx->Extensions.SGIX_depth_texture) {
1326 switch (internalFormat) {
1327 case GL_DEPTH_COMPONENT:
1328 case GL_DEPTH_COMPONENT24_SGIX:
1329 case GL_DEPTH_COMPONENT32_SGIX:
1330 return &_mesa_texformat_depth_component_float32;
1331 case GL_DEPTH_COMPONENT16_SGIX:
1332 return &_mesa_texformat_depth_component16;
1333 default:
1334 ; /* fallthrough */
1335 }
1336 }
1337
1338 if (ctx->Extensions.ARB_texture_compression) {
1339 switch (internalFormat) {
1340 case GL_COMPRESSED_ALPHA_ARB:
1341 return &_mesa_texformat_alpha;
1342 case GL_COMPRESSED_LUMINANCE_ARB:
1343 return &_mesa_texformat_luminance;
1344 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
1345 return &_mesa_texformat_luminance_alpha;
1346 case GL_COMPRESSED_INTENSITY_ARB:
1347 return &_mesa_texformat_intensity;
1348 case GL_COMPRESSED_RGB_ARB:
1349 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1350 return &_mesa_texformat_rgb_fxt1;
1351 else if (ctx->Extensions.EXT_texture_compression_s3tc ||
1352 ctx->Extensions.S3_s3tc)
1353 return &_mesa_texformat_rgb_dxt1;
1354 else
1355 return &_mesa_texformat_rgb;
1356 case GL_COMPRESSED_RGBA_ARB:
1357 if (ctx->Extensions.TDFX_texture_compression_FXT1)
1358 return &_mesa_texformat_rgba_fxt1;
1359 else if (ctx->Extensions.EXT_texture_compression_s3tc ||
1360 ctx->Extensions.S3_s3tc)
1361 return &_mesa_texformat_rgba_dxt3; /* Not rgba_dxt1, see spec */
1362 else
1363 return &_mesa_texformat_rgba;
1364 default:
1365 ; /* fallthrough */
1366 }
1367 }
1368
1369 if (ctx->Extensions.MESA_ycbcr_texture) {
1370 if (internalFormat == GL_YCBCR_MESA) {
1371 if (type == GL_UNSIGNED_SHORT_8_8_MESA)
1372 return &_mesa_texformat_ycbcr;
1373 else
1374 return &_mesa_texformat_ycbcr_rev;
1375 }
1376 }
1377
1378 if (ctx->Extensions.TDFX_texture_compression_FXT1) {
1379 switch (internalFormat) {
1380 case GL_COMPRESSED_RGB_FXT1_3DFX:
1381 return &_mesa_texformat_rgb_fxt1;
1382 case GL_COMPRESSED_RGBA_FXT1_3DFX:
1383 return &_mesa_texformat_rgba_fxt1;
1384 default:
1385 ; /* fallthrough */
1386 }
1387 }
1388
1389 if (ctx->Extensions.EXT_texture_compression_s3tc) {
1390 switch (internalFormat) {
1391 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
1392 return &_mesa_texformat_rgb_dxt1;
1393 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1394 return &_mesa_texformat_rgba_dxt1;
1395 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1396 return &_mesa_texformat_rgba_dxt3;
1397 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1398 return &_mesa_texformat_rgba_dxt5;
1399 default:
1400 ; /* fallthrough */
1401 }
1402 }
1403
1404 if (ctx->Extensions.S3_s3tc) {
1405 switch (internalFormat) {
1406 case GL_RGB_S3TC:
1407 case GL_RGB4_S3TC:
1408 return &_mesa_texformat_rgb_dxt1;
1409 case GL_RGBA_S3TC:
1410 case GL_RGBA4_S3TC:
1411 return &_mesa_texformat_rgba_dxt3;
1412 default:
1413 ; /* fallthrough */
1414 }
1415 }
1416
1417 if (ctx->Extensions.ARB_texture_float) {
1418 switch (internalFormat) {
1419 case GL_ALPHA16F_ARB:
1420 return &_mesa_texformat_alpha_float16;
1421 case GL_ALPHA32F_ARB:
1422 return &_mesa_texformat_alpha_float32;
1423 case GL_LUMINANCE16F_ARB:
1424 return &_mesa_texformat_luminance_float16;
1425 case GL_LUMINANCE32F_ARB:
1426 return &_mesa_texformat_luminance_float32;
1427 case GL_LUMINANCE_ALPHA16F_ARB:
1428 return &_mesa_texformat_luminance_alpha_float16;
1429 case GL_LUMINANCE_ALPHA32F_ARB:
1430 return &_mesa_texformat_luminance_alpha_float32;
1431 case GL_INTENSITY16F_ARB:
1432 return &_mesa_texformat_intensity_float16;
1433 case GL_INTENSITY32F_ARB:
1434 return &_mesa_texformat_intensity_float32;
1435 case GL_RGB16F_ARB:
1436 return &_mesa_texformat_rgb_float16;
1437 case GL_RGB32F_ARB:
1438 return &_mesa_texformat_rgb_float32;
1439 case GL_RGBA16F_ARB:
1440 return &_mesa_texformat_rgba_float16;
1441 case GL_RGBA32F_ARB:
1442 return &_mesa_texformat_rgba_float32;
1443 default:
1444 ; /* fallthrough */
1445 }
1446 }
1447
1448 _mesa_problem(ctx, "unexpected format in _mesa_choose_tex_format()");
1449 return NULL;
1450 }
1451
1452
1453 /**
1454 * Return the base texture format for the given compressed format
1455 *
1456 * Called via dd_function_table::Driver.BaseCompressedTexFormat.
1457 * This function is used by software rasterizers. Hardware drivers
1458 * which support texture compression should not use this function but
1459 * a specialized function instead.
1460 */
1461 GLint
1462 _mesa_base_compressed_texformat(GLcontext *ctx, GLint intFormat)
1463 {
1464 switch (intFormat) {
1465 case GL_COMPRESSED_ALPHA_ARB:
1466 return GL_ALPHA;
1467 case GL_COMPRESSED_LUMINANCE_ARB:
1468 return GL_LUMINANCE;
1469 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
1470 return GL_LUMINANCE_ALPHA;
1471 case GL_COMPRESSED_INTENSITY_ARB:
1472 return GL_INTENSITY;
1473 case GL_COMPRESSED_RGB_ARB:
1474 return GL_RGB;
1475 case GL_COMPRESSED_RGBA_ARB:
1476 return GL_RGBA;
1477 default:
1478 return -1; /* not a recognized compressed format */
1479 }
1480 }