Add GLAPIENTRY function decorations for correct operation on Windows.
[mesa.git] / src / mesa / main / texformat_tmp.h
1 /**
2 * \file texformat_tmp.h
3 * Texel fetch functions template.
4 *
5 * This template file is used by texformat.c to generate texel fetch functions
6 * for 1-D, 2-D and 3-D texture images.
7 *
8 * It should be expanded by definining \p DIM as the number texture dimensions
9 * (1, 2 or 3). According to the value of \p DIM a serie of macros is defined
10 * for the texel lookup in the gl_texture_image::Data.
11 *
12 * \sa texformat.c and FetchTexel.
13 *
14 * \author Gareth Hughes
15 * \author Brian Paul
16 */
17
18 /*
19 * Mesa 3-D graphics library
20 * Version: 6.1
21 *
22 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
23 *
24 * Permission is hereby granted, free of charge, to any person obtaining a
25 * copy of this software and associated documentation files (the "Software"),
26 * to deal in the Software without restriction, including without limitation
27 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
28 * and/or sell copies of the Software, and to permit persons to whom the
29 * Software is furnished to do so, subject to the following conditions:
30 *
31 * The above copyright notice and this permission notice shall be included
32 * in all copies or substantial portions of the Software.
33 *
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
35 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
37 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
38 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
39 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 */
41
42
43 #if DIM == 1
44
45 #define CHAN_SRC( t, i, j, k, sz ) \
46 ((GLchan *)(t)->Data + (i) * (sz))
47 #define UBYTE_SRC( t, i, j, k, sz ) \
48 ((GLubyte *)(t)->Data + (i) * (sz))
49 #define USHORT_SRC( t, i, j, k ) \
50 ((GLushort *)(t)->Data + (i))
51 #define FLOAT_SRC( t, i, j, k, sz ) \
52 ((GLfloat *)(t)->Data + (i) * (sz))
53 #define HALF_SRC( t, i, j, k, sz ) \
54 ((GLhalfNV *)(t)->Data + (i) * (sz))
55
56 #define FETCH(x) fetch_texel_1d_##x
57
58 #elif DIM == 2
59
60 #define CHAN_SRC( t, i, j, k, sz ) \
61 ((GLchan *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
62 #define UBYTE_SRC( t, i, j, k, sz ) \
63 ((GLubyte *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
64 #define USHORT_SRC( t, i, j, k ) \
65 ((GLushort *)(t)->Data + ((t)->RowStride * (j) + (i)))
66 #define FLOAT_SRC( t, i, j, k, sz ) \
67 ((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
68 #define HALF_SRC( t, i, j, k, sz ) \
69 ((GLhalfNV *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
70
71 #define FETCH(x) fetch_texel_2d_##x
72
73 #elif DIM == 3
74
75 #define CHAN_SRC( t, i, j, k, sz ) \
76 (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \
77 (t)->RowStride + (i)) * (sz)
78 #define UBYTE_SRC( t, i, j, k, sz ) \
79 ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \
80 (t)->RowStride + (i)) * (sz))
81 #define USHORT_SRC( t, i, j, k ) \
82 ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \
83 (t)->RowStride + (i)))
84 #define FLOAT_SRC( t, i, j, k, sz ) \
85 ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \
86 (t)->RowStride + (i)) * (sz))
87 #define HALF_SRC( t, i, j, k, sz ) \
88 ((GLhalfNV *)(t)->Data + (((t)->Height * (k) + (j)) * \
89 (t)->RowStride + (i)) * (sz))
90
91 #define FETCH(x) fetch_texel_3d_##x
92
93 #else
94 #error illegal number of texture dimensions
95 #endif
96
97
98 /* Fetch color texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
99 static void FETCH(rgba)( const struct gl_texture_image *texImage,
100 GLint i, GLint j, GLint k, GLchan *texel )
101 {
102 const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 );
103 COPY_CHAN4( texel, src );
104 }
105
106 /* Fetch color texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
107 static void FETCH(f_rgba)( const struct gl_texture_image *texImage,
108 GLint i, GLint j, GLint k, GLfloat *texel )
109 {
110 const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 );
111 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
112 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
113 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
114 texel[ACOMP] = CHAN_TO_FLOAT(src[3]);
115 }
116
117
118 /* Fetch color texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
119 static void FETCH(rgb)( const struct gl_texture_image *texImage,
120 GLint i, GLint j, GLint k, GLchan *texel )
121 {
122 const GLchan *src = CHAN_SRC( texImage, i, j, k, 3 );
123 texel[RCOMP] = src[0];
124 texel[GCOMP] = src[1];
125 texel[BCOMP] = src[2];
126 texel[ACOMP] = CHAN_MAX;
127 }
128
129 /* Fetch color texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
130 static void FETCH(f_rgb)( const struct gl_texture_image *texImage,
131 GLint i, GLint j, GLint k, GLfloat *texel )
132 {
133 const GLchan *src = CHAN_SRC( texImage, i, j, k, 3 );
134 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
135 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
136 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
137 texel[ACOMP] = CHAN_MAXF;
138 }
139
140 /* Fetch color texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
141 static void FETCH(alpha)( const struct gl_texture_image *texImage,
142 GLint i, GLint j, GLint k, GLchan *texel )
143 {
144 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
145 texel[RCOMP] =
146 texel[GCOMP] =
147 texel[BCOMP] = 0;
148 texel[ACOMP] = src[0];
149 }
150
151 /* Fetch color texel from 1D, 2D or 3D ALPHA texture, returning 4 GLfloats */
152 static void FETCH(f_alpha)( const struct gl_texture_image *texImage,
153 GLint i, GLint j, GLint k, GLfloat *texel )
154 {
155 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
156 texel[RCOMP] =
157 texel[GCOMP] =
158 texel[BCOMP] = 0.0;
159 texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
160 }
161
162 /* Fetch color texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
163 static void FETCH(luminance)( const struct gl_texture_image *texImage,
164 GLint i, GLint j, GLint k, GLchan *texel )
165 {
166 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
167 texel[RCOMP] =
168 texel[GCOMP] =
169 texel[BCOMP] = src[0];
170 texel[ACOMP] = CHAN_MAX;
171 }
172
173 /* Fetch color texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
174 static void FETCH(f_luminance)( const struct gl_texture_image *texImage,
175 GLint i, GLint j, GLint k, GLfloat *texel )
176 {
177 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
178 texel[RCOMP] =
179 texel[GCOMP] =
180 texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
181 texel[ACOMP] = CHAN_MAXF;
182 }
183
184 /* Fetch color texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
185 static void FETCH(luminance_alpha)( const struct gl_texture_image *texImage,
186 GLint i, GLint j, GLint k, GLchan *texel )
187 {
188 const GLchan *src = CHAN_SRC( texImage, i, j, k, 2 );
189 texel[RCOMP] = src[0];
190 texel[GCOMP] = src[0];
191 texel[BCOMP] = src[0];
192 texel[ACOMP] = src[1];
193 }
194
195 /* Fetch color texel from 1D, 2D or 3D L_A texture, returning 4 GLfloats */
196 static void FETCH(f_luminance_alpha)( const struct gl_texture_image *texImage,
197 GLint i, GLint j, GLint k, GLfloat *texel )
198 {
199 const GLchan *src = CHAN_SRC( texImage, i, j, k, 2 );
200 texel[RCOMP] =
201 texel[GCOMP] =
202 texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
203 texel[ACOMP] = CHAN_TO_FLOAT(src[1]);
204 }
205
206
207 /* Fetch color texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
208 static void FETCH(intensity)( const struct gl_texture_image *texImage,
209 GLint i, GLint j, GLint k, GLchan *texel )
210 {
211 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
212 texel[RCOMP] = src[0];
213 texel[GCOMP] = src[0];
214 texel[BCOMP] = src[0];
215 texel[ACOMP] = src[0];
216 }
217
218 /* Fetch color texel from 1D, 2D or 3D INT. texture, returning 4 GLfloats */
219 static void FETCH(f_intensity)( const struct gl_texture_image *texImage,
220 GLint i, GLint j, GLint k, GLfloat *texel )
221 {
222 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
223 texel[RCOMP] =
224 texel[GCOMP] =
225 texel[BCOMP] =
226 texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
227 }
228
229
230 /* Fetch CI texel from 1D, 2D or 3D CI texture, returning 1 GLchan */
231 static void FETCH(color_index)( const struct gl_texture_image *texImage,
232 GLint i, GLint j, GLint k, GLchan *texel )
233 {
234 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
235 texel[0] = src[0];
236 }
237
238 /* Fetch CI texel from 1D, 2D or 3D CI texture, returning 1 GLfloat */
239 static void FETCH(f_color_index)( const struct gl_texture_image *texImage,
240 GLint i, GLint j, GLint k, GLfloat *texel )
241 {
242 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
243 texel[0] = (GLfloat) src[0];
244 }
245
246
247 /* Fetch depth texel from 1D, 2D or 3D DEPTH texture, returning 1 GLfloat */
248 /* Note: no GLchan version of this function */
249 static void FETCH(f_depth_component)( const struct gl_texture_image *texImage,
250 GLint i, GLint j, GLint k, GLfloat *texel )
251 {
252 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 1 );
253 texel[0] = src[0];
254 }
255
256
257 /* Fetch color texel from 1D, 2D or 3D RGBA_FLOAT32 texture,
258 * returning 4 GLfloats.
259 */
260 static void FETCH(f_rgba_f32)( const struct gl_texture_image *texImage,
261 GLint i, GLint j, GLint k, GLfloat *texel )
262 {
263 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 4 );
264 texel[RCOMP] = src[0];
265 texel[GCOMP] = src[1];
266 texel[BCOMP] = src[2];
267 texel[ACOMP] = src[3];
268 }
269
270 /* Fetch color texel from 1D, 2D or 3D RGBA_FLOAT16 texture,
271 * returning 4 GLfloats.
272 */
273 static void FETCH(f_rgba_f16)( const struct gl_texture_image *texImage,
274 GLint i, GLint j, GLint k, GLfloat *texel )
275 {
276 const GLhalfNV *src = HALF_SRC( texImage, i, j, k, 4 );
277 texel[RCOMP] = _mesa_half_to_float(src[0]);
278 texel[GCOMP] = _mesa_half_to_float(src[1]);
279 texel[BCOMP] = _mesa_half_to_float(src[2]);
280 texel[ACOMP] = _mesa_half_to_float(src[3]);
281 }
282
283
284 /* Fetch color texel from 1D, 2D or 3D RGB_FLOAT32 texture,
285 * returning 4 GLfloats.
286 */
287 static void FETCH(f_rgb_f32)( const struct gl_texture_image *texImage,
288 GLint i, GLint j, GLint k, GLfloat *texel )
289 {
290 const GLfloat *src = FLOAT_SRC( texImage, i, j, k, 3 );
291 texel[RCOMP] = src[0];
292 texel[GCOMP] = src[1];
293 texel[BCOMP] = src[2];
294 texel[ACOMP] = CHAN_MAXF;
295 }
296
297 /* Fetch color texel from 1D, 2D or 3D RGB_FLOAT16 texture,
298 * returning 4 GLfloats.
299 */
300 static void FETCH(f_rgb_f16)( const struct gl_texture_image *texImage,
301 GLint i, GLint j, GLint k, GLfloat *texel )
302 {
303 const GLhalfNV *src = HALF_SRC( texImage, i, j, k, 3 );
304 texel[RCOMP] = _mesa_half_to_float(src[0]);
305 texel[GCOMP] = _mesa_half_to_float(src[1]);
306 texel[BCOMP] = _mesa_half_to_float(src[2]);
307 texel[ACOMP] = CHAN_MAXF;
308 }
309
310
311
312 /*
313 * Begin Hardware formats
314 */
315
316 /* Fetch color texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
317 static void FETCH(rgba8888)( const struct gl_texture_image *texImage,
318 GLint i, GLint j, GLint k, GLchan *texel )
319 {
320 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
321 texel[RCOMP] = UBYTE_TO_CHAN( src[3] );
322 texel[GCOMP] = UBYTE_TO_CHAN( src[2] );
323 texel[BCOMP] = UBYTE_TO_CHAN( src[1] );
324 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
325 }
326
327 /* Fetch color texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
328 static void FETCH(f_rgba8888)( const struct gl_texture_image *texImage,
329 GLint i, GLint j, GLint k, GLfloat *texel )
330 {
331 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
332 texel[RCOMP] = UBYTE_TO_FLOAT( src[3] );
333 texel[GCOMP] = UBYTE_TO_FLOAT( src[2] );
334 texel[BCOMP] = UBYTE_TO_FLOAT( src[1] );
335 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
336 }
337
338
339 /* Fetch color texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
340 static void FETCH(argb8888)( const struct gl_texture_image *texImage,
341 GLint i, GLint j, GLint k, GLchan *texel )
342 {
343 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
344 texel[RCOMP] = UBYTE_TO_CHAN( src[2] );
345 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
346 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
347 texel[ACOMP] = UBYTE_TO_CHAN( src[3] );
348 }
349
350 /* Fetch color texel from 1D, 2D or 3D argb8888 texture, return 4 GLfloats */
351 static void FETCH(f_argb8888)( const struct gl_texture_image *texImage,
352 GLint i, GLint j, GLint k, GLfloat *texel )
353 {
354 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
355 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
356 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
357 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
358 texel[ACOMP] = UBYTE_TO_FLOAT( src[3] );
359 }
360
361
362 /* Fetch color texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
363 static void FETCH(rgb888)( const struct gl_texture_image *texImage,
364 GLint i, GLint j, GLint k, GLchan *texel )
365 {
366 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
367 texel[RCOMP] = UBYTE_TO_CHAN( src[2] );
368 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
369 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
370 texel[ACOMP] = CHAN_MAX;
371 }
372
373 /* Fetch color texel from 1D, 2D or 3D rgb888 texture, return 4 GLfloats */
374 static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
375 GLint i, GLint j, GLint k, GLfloat *texel )
376 {
377 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
378 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
379 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
380 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
381 texel[ACOMP] = CHAN_MAXF;
382 }
383
384
385 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
386 static void FETCH(rgb565)( const struct gl_texture_image *texImage,
387 GLint i, GLint j, GLint k, GLchan *texel )
388 {
389 const GLushort *src = USHORT_SRC( texImage, i, j, k );
390 const GLushort s = *src;
391 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) * 255 / 0xf8 );
392 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) * 255 / 0xfc );
393 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) * 255 / 0xf8 );
394 texel[ACOMP] = CHAN_MAX;
395 }
396
397 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
398 static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
399 GLint i, GLint j, GLint k, GLfloat *texel )
400 {
401 const GLushort *src = USHORT_SRC( texImage, i, j, k );
402 const GLushort s = *src;
403 texel[RCOMP] = ((s >> 8) & 0xf8) * (1.0F / 248.0F);
404 texel[GCOMP] = ((s >> 3) & 0xfc) * (1.0F / 252.0F);
405 texel[BCOMP] = ((s << 3) & 0xf8) * (1.0F / 248.0F);
406 texel[ACOMP] = CHAN_MAXF;
407 }
408
409
410 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
411 static void FETCH(argb4444)( const struct gl_texture_image *texImage,
412 GLint i, GLint j, GLint k, GLchan *texel )
413 {
414 const GLushort *src = USHORT_SRC( texImage, i, j, k );
415 const GLushort s = *src;
416 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf );
417 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf );
418 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf );
419 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) * 255 / 0xf );
420 }
421
422 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
423 static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
424 GLint i, GLint j, GLint k, GLfloat *texel )
425 {
426 const GLushort *src = USHORT_SRC( texImage, i, j, k );
427 const GLushort s = *src;
428 texel[RCOMP] = ((s >> 8) & 0xf) * (1.0F / 15.0F);
429 texel[GCOMP] = ((s >> 4) & 0xf) * (1.0F / 15.0F);
430 texel[BCOMP] = ((s ) & 0xf) * (1.0F / 15.0F);
431 texel[ACOMP] = ((s >> 12) & 0xf) * (1.0F / 15.0F);
432 }
433
434
435 /* Fetch color texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
436 static void FETCH(argb1555)( const struct gl_texture_image *texImage,
437 GLint i, GLint j, GLint k, GLchan *texel )
438 {
439 const GLushort *src = USHORT_SRC( texImage, i, j, k );
440 const GLushort s = *src;
441 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0x1f) * 255 / 0x1f );
442 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0x1f) * 255 / 0x1f );
443 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0x1f) * 255 / 0x1f );
444 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
445 }
446
447 /* Fetch color texel from 1D, 2D or 3D argb1555 texture, return 4 GLfloats */
448 static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
449 GLint i, GLint j, GLint k, GLfloat *texel )
450 {
451 const GLushort *src = USHORT_SRC( texImage, i, j, k );
452 const GLushort s = *src;
453 texel[RCOMP] = ((s >> 10) & 0x1f) * (1.0F / 31.0F);
454 texel[GCOMP] = ((s >> 5) & 0x1f) * (1.0F / 31.0F);
455 texel[BCOMP] = ((s ) & 0x1f) * (1.0F / 31.0F);
456 texel[ACOMP] = ((s >> 15) & 0x01);
457 }
458
459
460 /* Fetch color texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
461 static void FETCH(al88)( const struct gl_texture_image *texImage,
462 GLint i, GLint j, GLint k, GLchan *texel )
463 {
464 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 2 );
465 texel[RCOMP] =
466 texel[GCOMP] =
467 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
468 texel[ACOMP] = UBYTE_TO_CHAN( src[1] );
469 }
470
471 /* Fetch color texel from 1D, 2D or 3D al88 texture, return 4 GLfloats */
472 static void FETCH(f_al88)( const struct gl_texture_image *texImage,
473 GLint i, GLint j, GLint k, GLfloat *texel )
474 {
475 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 2 );
476 texel[RCOMP] =
477 texel[GCOMP] =
478 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
479 texel[ACOMP] = UBYTE_TO_FLOAT( src[1] );
480 }
481
482
483 /* Fetch color texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
484 static void FETCH(rgb332)( const struct gl_texture_image *texImage,
485 GLint i, GLint j, GLint k, GLchan *texel )
486 {
487 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
488 const GLubyte s = *src;
489 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xe0) * 255 / 0xe0 );
490 texel[GCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xe0) * 255 / 0xe0 );
491 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 5) & 0xc0) * 255 / 0xc0 );
492 texel[ACOMP] = CHAN_MAX;
493 }
494
495 /* Fetch color texel from 1D, 2D or 3D rgb332 texture, return 4 GLfloats */
496 static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
497 GLint i, GLint j, GLint k, GLfloat *texel )
498 {
499 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
500 const GLubyte s = *src;
501 texel[RCOMP] = ((s ) & 0xe0) * (1.0F / 224.0F);
502 texel[GCOMP] = ((s << 3) & 0xe0) * (1.0F / 224.0F);
503 texel[BCOMP] = ((s << 5) & 0xc0) * (1.0F / 192.0F);
504 texel[ACOMP] = CHAN_MAXF;
505 }
506
507
508 /* Fetch color texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
509 static void FETCH(a8)( const struct gl_texture_image *texImage,
510 GLint i, GLint j, GLint k, GLchan *texel )
511 {
512 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
513 texel[RCOMP] = 0;
514 texel[GCOMP] = 0;
515 texel[BCOMP] = 0;
516 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
517 }
518
519 /* Fetch color texel from 1D, 2D or 3D a8 texture, return 4 GLfloats */
520 static void FETCH(f_a8)( const struct gl_texture_image *texImage,
521 GLint i, GLint j, GLint k, GLfloat *texel )
522 {
523 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
524 texel[RCOMP] =
525 texel[GCOMP] =
526 texel[BCOMP] = 0.0;
527 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
528 }
529
530
531 /* Fetch color texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
532 static void FETCH(l8)( const struct gl_texture_image *texImage,
533 GLint i, GLint j, GLint k, GLchan *texel )
534 {
535 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
536 texel[RCOMP] = UBYTE_TO_CHAN( src[0] );
537 texel[GCOMP] = UBYTE_TO_CHAN( src[0] );
538 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
539 texel[ACOMP] = CHAN_MAX;
540 }
541
542 /* Fetch color texel from 1D, 2D or 3D l8 texture, return 4 GLfloats */
543 static void FETCH(f_l8)( const struct gl_texture_image *texImage,
544 GLint i, GLint j, GLint k, GLfloat *texel )
545 {
546 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
547 texel[RCOMP] =
548 texel[GCOMP] =
549 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
550 texel[ACOMP] = CHAN_MAXF;
551 }
552
553
554 /* Fetch color texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
555 static void FETCH(i8)( const struct gl_texture_image *texImage,
556 GLint i, GLint j, GLint k, GLchan *texel )
557 {
558 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
559 texel[RCOMP] = UBYTE_TO_CHAN( src[0] );
560 texel[GCOMP] = UBYTE_TO_CHAN( src[0] );
561 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
562 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
563 }
564
565 /* Fetch color texel from 1D, 2D or 3D i8 texture, return 4 GLfloats */
566 static void FETCH(f_i8)( const struct gl_texture_image *texImage,
567 GLint i, GLint j, GLint k, GLfloat *texel )
568 {
569 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
570 texel[RCOMP] =
571 texel[GCOMP] =
572 texel[BCOMP] =
573 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
574 }
575
576
577 /* Fetch color texel from 1D, 2D or 3D ci8 texture, return 1 GLchan */
578 static void FETCH(ci8)( const struct gl_texture_image *texImage,
579 GLint i, GLint j, GLint k, GLchan *texel )
580 {
581 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
582 GLchan *index = (GLchan *) texel;
583 *index = UBYTE_TO_CHAN( *src );
584 }
585
586
587 /* Fetch color texel from 1D, 2D or 3D ci8 texture, return 1 GLfloat */
588 static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
589 GLint i, GLint j, GLint k, GLfloat *texel )
590 {
591 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
592 texel[0] = UBYTE_TO_FLOAT( *src );
593 }
594
595
596 /* Fetch color texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
597 /* We convert YCbCr to RGB here */
598 /* XXX this may break if GLchan != GLubyte */
599 static void FETCH(ycbcr)( const struct gl_texture_image *texImage,
600 GLint i, GLint j, GLint k, GLchan *texel )
601 {
602 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
603 const GLushort *src1 = src0 + 1; /* odd */
604 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
605 const GLubyte cb = *src0 & 0xff; /* chroma U */
606 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
607 const GLubyte cr = *src1 & 0xff; /* chroma V */
608 GLint r, g, b;
609 if (i & 1) {
610 /* odd pixel: use y1,cr,cb */
611 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
612 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
613 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
614 }
615 else {
616 /* even pixel: use y0,cr,cb */
617 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
618 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
619 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
620 }
621 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
622 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
623 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
624 texel[ACOMP] = CHAN_MAX;
625 }
626
627 /* Fetch color texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats */
628 /* We convert YCbCr to RGB here */
629 static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
630 GLint i, GLint j, GLint k, GLfloat *texel )
631 {
632 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
633 const GLushort *src1 = src0 + 1; /* odd */
634 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
635 const GLubyte cb = *src0 & 0xff; /* chroma U */
636 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
637 const GLubyte cr = *src1 & 0xff; /* chroma V */
638 GLfloat r, g, b;
639 if (i & 1) {
640 /* odd pixel: use y1,cr,cb */
641 r = (1.164 * (y1-16) + 1.596 * (cr-128));
642 g = (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
643 b = (1.164 * (y1-16) + 2.018 * (cb-128));
644 }
645 else {
646 /* even pixel: use y0,cr,cb */
647 r = (1.164 * (y0-16) + 1.596 * (cr-128));
648 g = (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
649 b = (1.164 * (y0-16) + 2.018 * (cb-128));
650 }
651 /* XXX remove / 255 here by tweaking arithmetic above */
652 r /= 255.0;
653 g /= 255.0;
654 b /= 255.0;
655 /* XXX should we really clamp??? */
656 texel[RCOMP] = CLAMP(r, 0.0, 1.0);
657 texel[GCOMP] = CLAMP(g, 0.0, 1.0);
658 texel[BCOMP] = CLAMP(b, 0.0, 1.0);
659 texel[ACOMP] = CHAN_MAXF;
660 }
661
662
663 /* Fetch color texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
664 /* We convert YCbCr to RGB here */
665 /* XXX this may break if GLchan != GLubyte */
666 static void FETCH(ycbcr_rev)( const struct gl_texture_image *texImage,
667 GLint i, GLint j, GLint k, GLchan *texel )
668 {
669 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
670 const GLushort *src1 = src0 + 1; /* odd */
671 const GLubyte y0 = *src0 & 0xff; /* luminance */
672 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
673 const GLubyte y1 = *src1 & 0xff; /* luminance */
674 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
675 GLint r, g, b;
676 if (i & 1) {
677 /* odd pixel: use y1,cr,cb */
678 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
679 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
680 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
681 }
682 else {
683 /* even pixel: use y0,cr,cb */
684 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
685 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
686 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
687 }
688 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
689 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
690 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
691 texel[ACOMP] = CHAN_MAX;
692 }
693
694 /* Fetch color texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
695 /* We convert YCbCr to RGB here */
696 static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
697 GLint i, GLint j, GLint k, GLfloat *texel )
698 {
699 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
700 const GLushort *src1 = src0 + 1; /* odd */
701 const GLubyte y0 = *src0 & 0xff; /* luminance */
702 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
703 const GLubyte y1 = *src1 & 0xff; /* luminance */
704 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
705 GLfloat r, g, b;
706 if (i & 1) {
707 /* odd pixel: use y1,cr,cb */
708 r = (1.164 * (y1-16) + 1.596 * (cr-128));
709 g = (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
710 b = (1.164 * (y1-16) + 2.018 * (cb-128));
711 }
712 else {
713 /* even pixel: use y0,cr,cb */
714 r = (1.164 * (y0-16) + 1.596 * (cr-128));
715 g = (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
716 b = (1.164 * (y0-16) + 2.018 * (cb-128));
717 }
718 /* XXX remove / 255 here by tweaking arithmetic above */
719 r /= 255.0;
720 g /= 255.0;
721 b /= 255.0;
722 /* XXX should we really clamp??? */
723 texel[RCOMP] = CLAMP(r, 0.0, 1.0);
724 texel[GCOMP] = CLAMP(g, 0.0, 1.0);
725 texel[BCOMP] = CLAMP(b, 0.0, 1.0);
726 texel[ACOMP] = CHAN_MAXF;
727 }
728
729
730 #if DIM == 2 /* Only 2D compressed textures possible */
731
732 static void FETCH(rgb_fxt1)( const struct gl_texture_image *texImage,
733 GLint i, GLint j, GLint k, GLchan *texel )
734 {
735 /* Extract the (i,j) pixel from texImage->Data and return it
736 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
737 */
738 }
739
740 static void FETCH(f_rgb_fxt1)( const struct gl_texture_image *texImage,
741 GLint i, GLint j, GLint k, GLfloat *texel )
742 {
743 /* Extract the (i,j) pixel from texImage->Data and return it
744 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
745 */
746 }
747
748 static void FETCH(rgba_fxt1)( const struct gl_texture_image *texImage,
749 GLint i, GLint j, GLint k, GLchan *texel )
750 {
751 /* Extract the (i,j) pixel from texImage->Data and return it
752 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
753 */
754 }
755
756 static void FETCH(f_rgba_fxt1)( const struct gl_texture_image *texImage,
757 GLint i, GLint j, GLint k, GLfloat *texel )
758 {
759 /* Extract the (i,j) pixel from texImage->Data and return it
760 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
761 */
762 }
763
764 #endif /* if DIM == 2 */
765
766
767 #if DIM == 2 /* only 2D is valid */
768
769 static void FETCH(rgb_dxt1)( const struct gl_texture_image *texImage,
770 GLint i, GLint j, GLint k, GLchan *texel )
771 {
772 /* Extract the (i,j) pixel from texImage->Data and return it
773 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
774 */
775 }
776
777 static void FETCH(f_rgb_dxt1)( const struct gl_texture_image *texImage,
778 GLint i, GLint j, GLint k, GLfloat *texel )
779 {
780 /* Extract the (i,j) pixel from texImage->Data and return it
781 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
782 */
783 }
784
785
786 static void FETCH(rgba_dxt1)( const struct gl_texture_image *texImage,
787 GLint i, GLint j, GLint k, GLchan *texel )
788 {
789 /* Extract the (i,j) pixel from texImage->Data and return it
790 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
791 */
792 }
793
794 static void FETCH(f_rgba_dxt1)( const struct gl_texture_image *texImage,
795 GLint i, GLint j, GLint k, GLfloat *texel )
796 {
797 /* Extract the (i,j) pixel from texImage->Data and return it
798 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
799 */
800 }
801
802
803 static void FETCH(rgba_dxt3)( const struct gl_texture_image *texImage,
804 GLint i, GLint j, GLint k, GLchan *texel )
805 {
806 /* Extract the (i,j) pixel from texImage->Data and return it
807 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
808 */
809 }
810
811 static void FETCH(f_rgba_dxt3)( const struct gl_texture_image *texImage,
812 GLint i, GLint j, GLint k, GLfloat *texel )
813 {
814 /* Extract the (i,j) pixel from texImage->Data and return it
815 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
816 */
817 }
818
819
820 static void FETCH(rgba_dxt5)( const struct gl_texture_image *texImage,
821 GLint i, GLint j, GLint k, GLchan *texel )
822 {
823 /* Extract the (i,j) pixel from texImage->Data and return it
824 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
825 */
826 }
827
828 static void FETCH(f_rgba_dxt5)( const struct gl_texture_image *texImage,
829 GLint i, GLint j, GLint k, GLfloat *texel )
830 {
831 /* Extract the (i,j) pixel from texImage->Data and return it
832 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
833 */
834 }
835
836 #endif
837
838
839
840 /* big-endian */
841
842 #if 0
843 static void FETCH(abgr8888)( const struct gl_texture_image *texImage,
844 GLint i, GLint j, GLint k, GLchan *texel )
845 {
846 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
847 texel[RCOMP] = UBYTE_TO_CHAN( src[3] );
848 texel[GCOMP] = UBYTE_TO_CHAN( src[2] );
849 texel[BCOMP] = UBYTE_TO_CHAN( src[1] );
850 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
851 }
852
853 static void FETCH(bgra8888)( const struct gl_texture_image *texImage,
854 GLint i, GLint j, GLint k, GLchan *texel )
855 {
856 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
857 texel[RCOMP] = UBYTE_TO_CHAN( src[2] );
858 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
859 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
860 texel[ACOMP] = UBYTE_TO_CHAN( src[3] );
861 }
862
863 static void FETCH(bgr888)( const struct gl_texture_image *texImage,
864 GLint i, GLint j, GLint k, GLchan *texel )
865 {
866 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
867 texel[RCOMP] = UBYTE_TO_CHAN( src[2] );
868 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
869 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
870 texel[ACOMP] = CHAN_MAX;
871 }
872
873 static void FETCH(bgr565)( const struct gl_texture_image *texImage,
874 GLint i, GLint j, GLint k, GLchan *texel )
875 {
876 const GLushort *src = USHORT_SRC( texImage, i, j, k );
877 const GLushort s = *src;
878 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) * 255 / 0xf8 );
879 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) * 255 / 0xfc );
880 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) * 255 / 0xf8 );
881 texel[ACOMP] = CHAN_MAX;
882 }
883
884 static void FETCH(bgra4444)( const struct gl_texture_image *texImage,
885 GLint i, GLint j, GLint k, GLchan *texel )
886 {
887 const GLushort *src = USHORT_SRC( texImage, i, j, k );
888 const GLushort s = *src;
889 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf );
890 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf );
891 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf );
892 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) * 255 / 0xf );
893 }
894
895 static void FETCH(bgra5551)( const struct gl_texture_image *texImage,
896 GLint i, GLint j, GLint k, GLchan *texel )
897 {
898 const GLushort *src = USHORT_SRC( texImage, i, j, k );
899 const GLushort s = *src;
900 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0x1f) * 255 / 0x1f );
901 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0x1f) * 255 / 0x1f );
902 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0x1f) * 255 / 0x1f );
903 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
904 }
905
906 static void FETCH(la88)( const struct gl_texture_image *texImage,
907 GLint i, GLint j, GLint k, GLchan *texel )
908 {
909 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 2 );
910 texel[RCOMP] = UBYTE_TO_CHAN( src[0] );
911 texel[GCOMP] = UBYTE_TO_CHAN( src[0] );
912 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
913 texel[ACOMP] = UBYTE_TO_CHAN( src[1] );
914 }
915
916 static void FETCH(bgr233)( const struct gl_texture_image *texImage,
917 GLint i, GLint j, GLint k, GLchan *texel )
918 {
919 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
920 const GLubyte s = *src;
921 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xe0) * 255 / 0xe0 );
922 texel[GCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xe0) * 255 / 0xe0 );
923 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 5) & 0xc0) * 255 / 0xc0 );
924 texel[ACOMP] = CHAN_MAX;
925 }
926 #endif
927
928
929 #undef CHAN_SRC
930 #undef UBYTE_SRC
931 #undef USHORT_SRC
932 #undef FLOAT_SRC
933 #undef HALF_SRC
934 #undef FETCH
935 #undef DIM