Fix hardware ROP state handling (Roland Scheidegger)
[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 ) \
52 ((GLfloat *)(t)->Data + (i))
53
54 #define FETCH(x) fetch_texel_1d_##x
55
56 #elif DIM == 2
57
58 #define CHAN_SRC( t, i, j, k, sz ) \
59 ((GLchan *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
60 #define UBYTE_SRC( t, i, j, k, sz ) \
61 ((GLubyte *)(t)->Data + ((t)->RowStride * (j) + (i)) * (sz))
62 #define USHORT_SRC( t, i, j, k ) \
63 ((GLushort *)(t)->Data + ((t)->RowStride * (j) + (i)))
64 #define FLOAT_SRC( t, i, j, k ) \
65 ((GLfloat *)(t)->Data + ((t)->RowStride * (j) + (i)))
66
67 #define FETCH(x) fetch_texel_2d_##x
68
69 #elif DIM == 3
70
71 #define CHAN_SRC( t, i, j, k, sz ) \
72 (GLchan *)(t)->Data + (((t)->Height * (k) + (j)) * \
73 (t)->RowStride + (i)) * (sz)
74 #define UBYTE_SRC( t, i, j, k, sz ) \
75 ((GLubyte *)(t)->Data + (((t)->Height * (k) + (j)) * \
76 (t)->RowStride + (i)) * (sz))
77 #define USHORT_SRC( t, i, j, k ) \
78 ((GLushort *)(t)->Data + (((t)->Height * (k) + (j)) * \
79 (t)->RowStride + (i)))
80 #define FLOAT_SRC( t, i, j, k ) \
81 ((GLfloat *)(t)->Data + (((t)->Height * (k) + (j)) * \
82 (t)->RowStride + (i)))
83
84 #define FETCH(x) fetch_texel_3d_##x
85
86 #else
87 #error illegal number of texture dimensions
88 #endif
89
90
91 /* Fetch color texel from 1D, 2D or 3D RGBA texture, returning 4 GLchans */
92 static void FETCH(rgba)( const struct gl_texture_image *texImage,
93 GLint i, GLint j, GLint k, GLchan *texel )
94 {
95 const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 );
96 COPY_CHAN4( texel, src );
97 }
98
99 /* Fetch color texel from 1D, 2D or 3D RGBA texture, returning 4 GLfloats */
100 static void FETCH(f_rgba)( const struct gl_texture_image *texImage,
101 GLint i, GLint j, GLint k, GLfloat *texel )
102 {
103 const GLchan *src = CHAN_SRC( texImage, i, j, k, 4 );
104 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
105 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
106 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
107 texel[ACOMP] = CHAN_TO_FLOAT(src[3]);
108 }
109
110
111 /* Fetch color texel from 1D, 2D or 3D RGB texture, returning 4 GLchans */
112 static void FETCH(rgb)( const struct gl_texture_image *texImage,
113 GLint i, GLint j, GLint k, GLchan *texel )
114 {
115 const GLchan *src = CHAN_SRC( texImage, i, j, k, 3 );
116 texel[RCOMP] = src[0];
117 texel[GCOMP] = src[1];
118 texel[BCOMP] = src[2];
119 texel[ACOMP] = CHAN_MAX;
120 }
121
122 /* Fetch color texel from 1D, 2D or 3D RGB texture, returning 4 GLfloats */
123 static void FETCH(f_rgb)( const struct gl_texture_image *texImage,
124 GLint i, GLint j, GLint k, GLfloat *texel )
125 {
126 const GLchan *src = CHAN_SRC( texImage, i, j, k, 3 );
127 texel[RCOMP] = CHAN_TO_FLOAT(src[0]);
128 texel[GCOMP] = CHAN_TO_FLOAT(src[1]);
129 texel[BCOMP] = CHAN_TO_FLOAT(src[2]);
130 texel[ACOMP] = CHAN_MAXF;
131 }
132
133 /* Fetch color texel from 1D, 2D or 3D ALPHA texture, returning 4 GLchans */
134 static void FETCH(alpha)( const struct gl_texture_image *texImage,
135 GLint i, GLint j, GLint k, GLchan *texel )
136 {
137 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
138 texel[RCOMP] =
139 texel[GCOMP] =
140 texel[BCOMP] = 0;
141 texel[ACOMP] = src[0];
142 }
143
144 /* Fetch color texel from 1D, 2D or 3D ALPHA texture, returning 4 GLfloats */
145 static void FETCH(f_alpha)( const struct gl_texture_image *texImage,
146 GLint i, GLint j, GLint k, GLfloat *texel )
147 {
148 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
149 texel[RCOMP] =
150 texel[GCOMP] =
151 texel[BCOMP] = 0.0;
152 texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
153 }
154
155 /* Fetch color texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
156 static void FETCH(luminance)( const struct gl_texture_image *texImage,
157 GLint i, GLint j, GLint k, GLchan *texel )
158 {
159 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
160 texel[RCOMP] =
161 texel[GCOMP] =
162 texel[BCOMP] = src[0];
163 texel[ACOMP] = CHAN_MAX;
164 }
165
166 /* Fetch color texel from 1D, 2D or 3D LUMIN texture, returning 4 GLchans */
167 static void FETCH(f_luminance)( const struct gl_texture_image *texImage,
168 GLint i, GLint j, GLint k, GLfloat *texel )
169 {
170 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
171 texel[RCOMP] =
172 texel[GCOMP] =
173 texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
174 texel[ACOMP] = CHAN_MAXF;
175 }
176
177 /* Fetch color texel from 1D, 2D or 3D L_A texture, returning 4 GLchans */
178 static void FETCH(luminance_alpha)( const struct gl_texture_image *texImage,
179 GLint i, GLint j, GLint k, GLchan *texel )
180 {
181 const GLchan *src = CHAN_SRC( texImage, i, j, k, 2 );
182 texel[RCOMP] = src[0];
183 texel[GCOMP] = src[0];
184 texel[BCOMP] = src[0];
185 texel[ACOMP] = src[1];
186 }
187
188 /* Fetch color texel from 1D, 2D or 3D L_A texture, returning 4 GLfloats */
189 static void FETCH(f_luminance_alpha)( const struct gl_texture_image *texImage,
190 GLint i, GLint j, GLint k, GLfloat *texel )
191 {
192 const GLchan *src = CHAN_SRC( texImage, i, j, k, 2 );
193 texel[RCOMP] =
194 texel[GCOMP] =
195 texel[BCOMP] = CHAN_TO_FLOAT(src[0]);
196 texel[ACOMP] = CHAN_TO_FLOAT(src[1]);
197 }
198
199
200 /* Fetch color texel from 1D, 2D or 3D INT. texture, returning 4 GLchans */
201 static void FETCH(intensity)( const struct gl_texture_image *texImage,
202 GLint i, GLint j, GLint k, GLchan *texel )
203 {
204 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
205 texel[RCOMP] = src[0];
206 texel[GCOMP] = src[0];
207 texel[BCOMP] = src[0];
208 texel[ACOMP] = src[0];
209 }
210
211 /* Fetch color texel from 1D, 2D or 3D INT. texture, returning 4 GLfloats */
212 static void FETCH(f_intensity)( const struct gl_texture_image *texImage,
213 GLint i, GLint j, GLint k, GLfloat *texel )
214 {
215 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
216 texel[RCOMP] =
217 texel[GCOMP] =
218 texel[BCOMP] =
219 texel[ACOMP] = CHAN_TO_FLOAT(src[0]);
220 }
221
222
223 /* Fetch CI texel from 1D, 2D or 3D CI texture, returning 1 GLchan */
224 static void FETCH(color_index)( const struct gl_texture_image *texImage,
225 GLint i, GLint j, GLint k, GLchan *texel )
226 {
227 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
228 GLchan *index = (GLchan *) texel;
229 index[0] = src[0];
230 }
231
232 /* Fetch CI texel from 1D, 2D or 3D CI texture, returning 1 GLfloat */
233 static void FETCH(f_color_index)( const struct gl_texture_image *texImage,
234 GLint i, GLint j, GLint k, GLfloat *texel )
235 {
236 const GLchan *src = CHAN_SRC( texImage, i, j, k, 1 );
237 texel[0] = (GLfloat) src[0];
238 }
239
240
241 #if 000
242 /* Fetch depth texel from 1D, 2D or 3D DEPTH texture, returning 1 GLfloat */
243 static void FETCH(depth_component)( const struct gl_texture_image *texImage,
244 GLint i, GLint j, GLint k, GLchan *texel )
245 {
246 #if 0
247 const GLfloat *src = FLOAT_SRC( texImage, i, j, k );
248 GLfloat *depth = (GLfloat *) texel;
249 depth[0] = src[0];
250 #else
251 _mesa_problem(NULL, "fetching depth component as non-float!");
252 #endif
253 }
254 #endif
255
256
257 /* Fetch depth texel from 1D, 2D or 3D DEPTH texture, returning 1 GLfloat */
258 static void FETCH(f_depth_component)( const struct gl_texture_image *texImage,
259 GLint i, GLint j, GLint k, GLfloat *texel )
260 {
261 const GLfloat *src = FLOAT_SRC( texImage, i, j, k );
262 texel[0] = src[0];
263 }
264
265
266 /* Fetch color texel from 1D, 2D or 3D rgba8888 texture, return 4 GLchans */
267 static void FETCH(rgba8888)( const struct gl_texture_image *texImage,
268 GLint i, GLint j, GLint k, GLchan *texel )
269 {
270 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
271 texel[RCOMP] = UBYTE_TO_CHAN( src[3] );
272 texel[GCOMP] = UBYTE_TO_CHAN( src[2] );
273 texel[BCOMP] = UBYTE_TO_CHAN( src[1] );
274 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
275 }
276
277 /* Fetch color texel from 1D, 2D or 3D rgba8888 texture, return 4 GLfloats */
278 static void FETCH(f_rgba8888)( const struct gl_texture_image *texImage,
279 GLint i, GLint j, GLint k, GLfloat *texel )
280 {
281 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
282 texel[RCOMP] = UBYTE_TO_FLOAT( src[3] );
283 texel[GCOMP] = UBYTE_TO_FLOAT( src[2] );
284 texel[BCOMP] = UBYTE_TO_FLOAT( src[1] );
285 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
286 }
287
288
289 /* Fetch color texel from 1D, 2D or 3D argb8888 texture, return 4 GLchans */
290 static void FETCH(argb8888)( const struct gl_texture_image *texImage,
291 GLint i, GLint j, GLint k, GLchan *texel )
292 {
293 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
294 texel[RCOMP] = UBYTE_TO_CHAN( src[2] );
295 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
296 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
297 texel[ACOMP] = UBYTE_TO_CHAN( src[3] );
298 }
299
300 /* Fetch color texel from 1D, 2D or 3D argb8888 texture, return 4 GLfloats */
301 static void FETCH(f_argb8888)( const struct gl_texture_image *texImage,
302 GLint i, GLint j, GLint k, GLfloat *texel )
303 {
304 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
305 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
306 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
307 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
308 texel[ACOMP] = UBYTE_TO_FLOAT( src[3] );
309 }
310
311
312 /* Fetch color texel from 1D, 2D or 3D rgb888 texture, return 4 GLchans */
313 static void FETCH(rgb888)( const struct gl_texture_image *texImage,
314 GLint i, GLint j, GLint k, GLchan *texel )
315 {
316 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
317 texel[RCOMP] = UBYTE_TO_CHAN( src[2] );
318 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
319 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
320 texel[ACOMP] = CHAN_MAX;
321 }
322
323 /* Fetch color texel from 1D, 2D or 3D rgb888 texture, return 4 GLfloats */
324 static void FETCH(f_rgb888)( const struct gl_texture_image *texImage,
325 GLint i, GLint j, GLint k, GLfloat *texel )
326 {
327 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
328 texel[RCOMP] = UBYTE_TO_FLOAT( src[2] );
329 texel[GCOMP] = UBYTE_TO_FLOAT( src[1] );
330 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
331 texel[ACOMP] = CHAN_MAXF;
332 }
333
334
335 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
336 static void FETCH(rgb565)( const struct gl_texture_image *texImage,
337 GLint i, GLint j, GLint k, GLchan *texel )
338 {
339 const GLushort *src = USHORT_SRC( texImage, i, j, k );
340 const GLushort s = *src;
341 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) * 255 / 0xf8 );
342 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) * 255 / 0xfc );
343 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) * 255 / 0xf8 );
344 texel[ACOMP] = CHAN_MAX;
345 }
346
347 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
348 static void FETCH(f_rgb565)( const struct gl_texture_image *texImage,
349 GLint i, GLint j, GLint k, GLfloat *texel )
350 {
351 const GLushort *src = USHORT_SRC( texImage, i, j, k );
352 const GLushort s = *src;
353 /* xxx fixup */
354 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf8) * 255 / 0xf8 );
355 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 3) & 0xfc) * 255 / 0xfc );
356 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xf8) * 255 / 0xf8 );
357 texel[ACOMP] = CHAN_MAXF;
358 }
359
360
361 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLchans */
362 static void FETCH(argb4444)( const struct gl_texture_image *texImage,
363 GLint i, GLint j, GLint k, GLchan *texel )
364 {
365 const GLushort *src = USHORT_SRC( texImage, i, j, k );
366 const GLushort s = *src;
367 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf );
368 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf );
369 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf );
370 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) * 255 / 0xf );
371 }
372
373 /* Fetch color texel from 1D, 2D or 3D rgb565 texture, return 4 GLfloats */
374 static void FETCH(f_argb4444)( const struct gl_texture_image *texImage,
375 GLint i, GLint j, GLint k, GLfloat *texel )
376 {
377 const GLushort *src = USHORT_SRC( texImage, i, j, k );
378 const GLushort s = *src;
379 /* xxx fixup */
380 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 8) & 0xf) * 255 / 0xf );
381 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 4) & 0xf) * 255 / 0xf );
382 texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xf) * 255 / 0xf );
383 texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 12) & 0xf) * 255 / 0xf );
384 }
385
386
387 /* Fetch color texel from 1D, 2D or 3D argb1555 texture, return 4 GLchans */
388 static void FETCH(argb1555)( const struct gl_texture_image *texImage,
389 GLint i, GLint j, GLint k, GLchan *texel )
390 {
391 const GLushort *src = USHORT_SRC( texImage, i, j, k );
392 const GLushort s = *src;
393 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0x1f) * 255 / 0x1f );
394 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0x1f) * 255 / 0x1f );
395 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0x1f) * 255 / 0x1f );
396 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
397 }
398
399 /* Fetch color texel from 1D, 2D or 3D argb1555 texture, return 4 GLfloats */
400 static void FETCH(f_argb1555)( const struct gl_texture_image *texImage,
401 GLint i, GLint j, GLint k, GLfloat *texel )
402 {
403 const GLushort *src = USHORT_SRC( texImage, i, j, k );
404 const GLushort s = *src;
405 /* xxx better */
406 texel[RCOMP] = UBYTE_TO_FLOAT( ((s >> 10) & 0x1f) * 255 / 0x1f );
407 texel[GCOMP] = UBYTE_TO_FLOAT( ((s >> 5) & 0x1f) * 255 / 0x1f );
408 texel[BCOMP] = UBYTE_TO_FLOAT( ((s ) & 0x1f) * 255 / 0x1f );
409 texel[ACOMP] = UBYTE_TO_FLOAT( ((s >> 15) & 0x01) * 255 );
410 }
411
412
413 /* Fetch color texel from 1D, 2D or 3D al88 texture, return 4 GLchans */
414 static void FETCH(al88)( const struct gl_texture_image *texImage,
415 GLint i, GLint j, GLint k, GLchan *texel )
416 {
417 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 2 );
418 texel[RCOMP] =
419 texel[GCOMP] =
420 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
421 texel[ACOMP] = UBYTE_TO_CHAN( src[1] );
422 }
423
424 /* Fetch color texel from 1D, 2D or 3D al88 texture, return 4 GLfloats */
425 static void FETCH(f_al88)( const struct gl_texture_image *texImage,
426 GLint i, GLint j, GLint k, GLfloat *texel )
427 {
428 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 2 );
429 texel[RCOMP] =
430 texel[GCOMP] =
431 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
432 texel[ACOMP] = UBYTE_TO_FLOAT( src[1] );
433 }
434
435
436 /* Fetch color texel from 1D, 2D or 3D rgb332 texture, return 4 GLchans */
437 static void FETCH(rgb332)( const struct gl_texture_image *texImage,
438 GLint i, GLint j, GLint k, GLchan *texel )
439 {
440 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
441 const GLubyte s = *src;
442 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xe0) * 255 / 0xe0 );
443 texel[GCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xe0) * 255 / 0xe0 );
444 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 5) & 0xc0) * 255 / 0xc0 );
445 texel[ACOMP] = CHAN_MAX;
446 }
447
448 /* Fetch color texel from 1D, 2D or 3D rgb332 texture, return 4 GLfloats */
449 static void FETCH(f_rgb332)( const struct gl_texture_image *texImage,
450 GLint i, GLint j, GLint k, GLfloat *texel )
451 {
452 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
453 const GLubyte s = *src;
454 /* xxx improve */
455 texel[RCOMP] = UBYTE_TO_FLOAT( ((s ) & 0xe0) * 255 / 0xe0 );
456 texel[GCOMP] = UBYTE_TO_FLOAT( ((s << 3) & 0xe0) * 255 / 0xe0 );
457 texel[BCOMP] = UBYTE_TO_FLOAT( ((s << 5) & 0xc0) * 255 / 0xc0 );
458 texel[ACOMP] = CHAN_MAXF;
459 }
460
461
462 /* Fetch color texel from 1D, 2D or 3D a8 texture, return 4 GLchans */
463 static void FETCH(a8)( const struct gl_texture_image *texImage,
464 GLint i, GLint j, GLint k, GLchan *texel )
465 {
466 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
467 texel[RCOMP] = 0;
468 texel[GCOMP] = 0;
469 texel[BCOMP] = 0;
470 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
471 }
472
473 /* Fetch color texel from 1D, 2D or 3D a8 texture, return 4 GLfloats */
474 static void FETCH(f_a8)( const struct gl_texture_image *texImage,
475 GLint i, GLint j, GLint k, GLfloat *texel )
476 {
477 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
478 texel[RCOMP] =
479 texel[GCOMP] =
480 texel[BCOMP] = 0.0;
481 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
482 }
483
484
485 /* Fetch color texel from 1D, 2D or 3D l8 texture, return 4 GLchans */
486 static void FETCH(l8)( const struct gl_texture_image *texImage,
487 GLint i, GLint j, GLint k, GLchan *texel )
488 {
489 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
490 texel[RCOMP] = UBYTE_TO_CHAN( src[0] );
491 texel[GCOMP] = UBYTE_TO_CHAN( src[0] );
492 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
493 texel[ACOMP] = CHAN_MAX;
494 }
495
496 /* Fetch color texel from 1D, 2D or 3D l8 texture, return 4 GLfloats */
497 static void FETCH(f_l8)( const struct gl_texture_image *texImage,
498 GLint i, GLint j, GLint k, GLfloat *texel )
499 {
500 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
501 texel[RCOMP] =
502 texel[GCOMP] =
503 texel[BCOMP] = UBYTE_TO_FLOAT( src[0] );
504 texel[ACOMP] = CHAN_MAXF;
505 }
506
507
508 /* Fetch color texel from 1D, 2D or 3D i8 texture, return 4 GLchans */
509 static void FETCH(i8)( 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] = UBYTE_TO_CHAN( src[0] );
514 texel[GCOMP] = UBYTE_TO_CHAN( src[0] );
515 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
516 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
517 }
518
519 /* Fetch color texel from 1D, 2D or 3D i8 texture, return 4 GLfloats */
520 static void FETCH(f_i8)( 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] =
527 texel[ACOMP] = UBYTE_TO_FLOAT( src[0] );
528 }
529
530
531 /* Fetch color texel from 1D, 2D or 3D ci8 texture, return 1 GLchan */
532 static void FETCH(ci8)( 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 GLchan *index = (GLchan *) texel;
537 *index = UBYTE_TO_CHAN( *src );
538 }
539
540
541 /* Fetch color texel from 1D, 2D or 3D ci8 texture, return 1 GLfloat */
542 static void FETCH(f_ci8)( const struct gl_texture_image *texImage,
543 GLint i, GLint j, GLint k, GLfloat *texel )
544 {
545 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
546 texel[0] = UBYTE_TO_FLOAT( *src );
547 }
548
549
550 /* Fetch color texel from 1D, 2D or 3D ycbcr texture, return 4 GLchans */
551 /* We convert YCbCr to RGB here */
552 /* XXX this may break if GLchan != GLubyte */
553 static void FETCH(ycbcr)( const struct gl_texture_image *texImage,
554 GLint i, GLint j, GLint k, GLchan *texel )
555 {
556 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
557 const GLushort *src1 = src0 + 1; /* odd */
558 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
559 const GLubyte cb = *src0 & 0xff; /* chroma U */
560 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
561 const GLubyte cr = *src1 & 0xff; /* chroma V */
562 GLint r, g, b;
563 if (i & 1) {
564 /* odd pixel: use y1,cr,cb */
565 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
566 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
567 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
568 }
569 else {
570 /* even pixel: use y0,cr,cb */
571 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
572 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
573 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
574 }
575 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
576 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
577 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
578 texel[ACOMP] = CHAN_MAX;
579 }
580
581 /* Fetch color texel from 1D, 2D or 3D ycbcr texture, return 4 GLfloats */
582 /* We convert YCbCr to RGB here */
583 static void FETCH(f_ycbcr)( const struct gl_texture_image *texImage,
584 GLint i, GLint j, GLint k, GLfloat *texel )
585 {
586 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
587 const GLushort *src1 = src0 + 1; /* odd */
588 const GLubyte y0 = (*src0 >> 8) & 0xff; /* luminance */
589 const GLubyte cb = *src0 & 0xff; /* chroma U */
590 const GLubyte y1 = (*src1 >> 8) & 0xff; /* luminance */
591 const GLubyte cr = *src1 & 0xff; /* chroma V */
592 GLfloat r, g, b;
593 if (i & 1) {
594 /* odd pixel: use y1,cr,cb */
595 r = (1.164 * (y1-16) + 1.596 * (cr-128));
596 g = (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
597 b = (1.164 * (y1-16) + 2.018 * (cb-128));
598 }
599 else {
600 /* even pixel: use y0,cr,cb */
601 r = (1.164 * (y0-16) + 1.596 * (cr-128));
602 g = (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
603 b = (1.164 * (y0-16) + 2.018 * (cb-128));
604 }
605 /* XXX remove / 255 here by tweaking arithmetic above */
606 r /= 255.0;
607 g /= 255.0;
608 b /= 255.0;
609 /* XXX should we really clamp??? */
610 texel[RCOMP] = CLAMP(r, 0.0, 1.0);
611 texel[GCOMP] = CLAMP(g, 0.0, 1.0);
612 texel[BCOMP] = CLAMP(b, 0.0, 1.0);
613 texel[ACOMP] = CHAN_MAXF;
614 }
615
616
617 /* Fetch color texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLchans */
618 /* We convert YCbCr to RGB here */
619 /* XXX this may break if GLchan != GLubyte */
620 static void FETCH(ycbcr_rev)( const struct gl_texture_image *texImage,
621 GLint i, GLint j, GLint k, GLchan *texel )
622 {
623 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
624 const GLushort *src1 = src0 + 1; /* odd */
625 const GLubyte y0 = *src0 & 0xff; /* luminance */
626 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
627 const GLubyte y1 = *src1 & 0xff; /* luminance */
628 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
629 GLint r, g, b;
630 if (i & 1) {
631 /* odd pixel: use y1,cr,cb */
632 r = (GLint) (1.164 * (y1-16) + 1.596 * (cr-128));
633 g = (GLint) (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
634 b = (GLint) (1.164 * (y1-16) + 2.018 * (cb-128));
635 }
636 else {
637 /* even pixel: use y0,cr,cb */
638 r = (GLint) (1.164 * (y0-16) + 1.596 * (cr-128));
639 g = (GLint) (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
640 b = (GLint) (1.164 * (y0-16) + 2.018 * (cb-128));
641 }
642 texel[RCOMP] = CLAMP(r, 0, CHAN_MAX);
643 texel[GCOMP] = CLAMP(g, 0, CHAN_MAX);
644 texel[BCOMP] = CLAMP(b, 0, CHAN_MAX);
645 texel[ACOMP] = CHAN_MAX;
646 }
647
648 /* Fetch color texel from 1D, 2D or 3D ycbcr_rev texture, return 4 GLfloats */
649 /* We convert YCbCr to RGB here */
650 /* XXX this may break if GLchan != GLubyte */
651 static void FETCH(f_ycbcr_rev)( const struct gl_texture_image *texImage,
652 GLint i, GLint j, GLint k, GLfloat *texel )
653 {
654 const GLushort *src0 = USHORT_SRC( texImage, (i & ~1), j, k ); /* even */
655 const GLushort *src1 = src0 + 1; /* odd */
656 const GLubyte y0 = *src0 & 0xff; /* luminance */
657 const GLubyte cr = (*src0 >> 8) & 0xff; /* chroma V */
658 const GLubyte y1 = *src1 & 0xff; /* luminance */
659 const GLubyte cb = (*src1 >> 8) & 0xff; /* chroma U */
660 GLfloat r, g, b;
661 if (i & 1) {
662 /* odd pixel: use y1,cr,cb */
663 r = (1.164 * (y1-16) + 1.596 * (cr-128));
664 g = (1.164 * (y1-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
665 b = (1.164 * (y1-16) + 2.018 * (cb-128));
666 }
667 else {
668 /* even pixel: use y0,cr,cb */
669 r = (1.164 * (y0-16) + 1.596 * (cr-128));
670 g = (1.164 * (y0-16) - 0.813 * (cr-128) - 0.391 * (cb-128));
671 b = (1.164 * (y0-16) + 2.018 * (cb-128));
672 }
673 /* XXX remove / 255 here by tweaking arithmetic above */
674 r /= 255.0;
675 g /= 255.0;
676 b /= 255.0;
677 /* XXX should we really clamp??? */
678 texel[RCOMP] = CLAMP(r, 0.0, 1.0);
679 texel[GCOMP] = CLAMP(g, 0.0, 1.0);
680 texel[BCOMP] = CLAMP(b, 0.0, 1.0);
681 texel[ACOMP] = CHAN_MAXF;
682 }
683
684
685 #if DIM == 2 /* Only 2D compressed textures possible */
686
687 static void FETCH(rgb_fxt1)( const struct gl_texture_image *texImage,
688 GLint i, GLint j, GLint k, GLchan *texel )
689 {
690 /* Extract the (i,j) pixel from texImage->Data and return it
691 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
692 */
693 }
694
695 static void FETCH(f_rgb_fxt1)( const struct gl_texture_image *texImage,
696 GLint i, GLint j, GLint k, GLfloat *texel )
697 {
698 /* Extract the (i,j) pixel from texImage->Data and return it
699 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
700 */
701 }
702
703 static void FETCH(rgba_fxt1)( const struct gl_texture_image *texImage,
704 GLint i, GLint j, GLint k, GLchan *texel )
705 {
706 /* Extract the (i,j) pixel from texImage->Data and return it
707 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
708 */
709 }
710
711 static void FETCH(f_rgba_fxt1)( const struct gl_texture_image *texImage,
712 GLint i, GLint j, GLint k, GLfloat *texel )
713 {
714 /* Extract the (i,j) pixel from texImage->Data and return it
715 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
716 */
717 }
718
719 #endif /* if DIM == 2 */
720
721
722 #if DIM == 2 /* only 2D is valid */
723
724 static void FETCH(rgb_dxt1)( const struct gl_texture_image *texImage,
725 GLint i, GLint j, GLint k, GLchan *texel )
726 {
727 /* Extract the (i,j) pixel from texImage->Data and return it
728 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
729 */
730 }
731
732 static void FETCH(f_rgb_dxt1)( const struct gl_texture_image *texImage,
733 GLint i, GLint j, GLint k, GLfloat *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
741 static void FETCH(rgba_dxt1)( const struct gl_texture_image *texImage,
742 GLint i, GLint j, GLint k, GLchan *texel )
743 {
744 /* Extract the (i,j) pixel from texImage->Data and return it
745 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
746 */
747 }
748
749 static void FETCH(f_rgba_dxt1)( const struct gl_texture_image *texImage,
750 GLint i, GLint j, GLint k, GLfloat *texel )
751 {
752 /* Extract the (i,j) pixel from texImage->Data and return it
753 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
754 */
755 }
756
757
758 static void FETCH(rgba_dxt3)( const struct gl_texture_image *texImage,
759 GLint i, GLint j, GLint k, GLchan *texel )
760 {
761 /* Extract the (i,j) pixel from texImage->Data and return it
762 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
763 */
764 }
765
766 static void FETCH(f_rgba_dxt3)( const struct gl_texture_image *texImage,
767 GLint i, GLint j, GLint k, GLfloat *texel )
768 {
769 /* Extract the (i,j) pixel from texImage->Data and return it
770 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
771 */
772 }
773
774
775 static void FETCH(rgba_dxt5)( const struct gl_texture_image *texImage,
776 GLint i, GLint j, GLint k, GLchan *texel )
777 {
778 /* Extract the (i,j) pixel from texImage->Data and return it
779 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
780 */
781 }
782
783 static void FETCH(f_rgba_dxt5)( const struct gl_texture_image *texImage,
784 GLint i, GLint j, GLint k, GLfloat *texel )
785 {
786 /* Extract the (i,j) pixel from texImage->Data and return it
787 * in texel[RCOMP], texel[GCOMP], texel[BCOMP], texel[ACOMP].
788 */
789 }
790
791 #endif
792
793
794
795 /* big-endian */
796
797 #if 0
798 static void FETCH(abgr8888)( const struct gl_texture_image *texImage,
799 GLint i, GLint j, GLint k, GLchan *texel )
800 {
801 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
802 texel[RCOMP] = UBYTE_TO_CHAN( src[3] );
803 texel[GCOMP] = UBYTE_TO_CHAN( src[2] );
804 texel[BCOMP] = UBYTE_TO_CHAN( src[1] );
805 texel[ACOMP] = UBYTE_TO_CHAN( src[0] );
806 }
807
808 static void FETCH(bgra8888)( const struct gl_texture_image *texImage,
809 GLint i, GLint j, GLint k, GLchan *texel )
810 {
811 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 4 );
812 texel[RCOMP] = UBYTE_TO_CHAN( src[2] );
813 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
814 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
815 texel[ACOMP] = UBYTE_TO_CHAN( src[3] );
816 }
817
818 static void FETCH(bgr888)( const struct gl_texture_image *texImage,
819 GLint i, GLint j, GLint k, GLchan *texel )
820 {
821 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 3 );
822 texel[RCOMP] = UBYTE_TO_CHAN( src[2] );
823 texel[GCOMP] = UBYTE_TO_CHAN( src[1] );
824 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
825 texel[ACOMP] = CHAN_MAX;
826 }
827
828 static void FETCH(bgr565)( const struct gl_texture_image *texImage,
829 GLint i, GLint j, GLint k, GLchan *texel )
830 {
831 const GLushort *src = USHORT_SRC( texImage, i, j, k );
832 const GLushort s = *src;
833 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf8) * 255 / 0xf8 );
834 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 3) & 0xfc) * 255 / 0xfc );
835 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xf8) * 255 / 0xf8 );
836 texel[ACOMP] = CHAN_MAX;
837 }
838
839 static void FETCH(bgra4444)( const struct gl_texture_image *texImage,
840 GLint i, GLint j, GLint k, GLchan *texel )
841 {
842 const GLushort *src = USHORT_SRC( texImage, i, j, k );
843 const GLushort s = *src;
844 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 8) & 0xf) * 255 / 0xf );
845 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 4) & 0xf) * 255 / 0xf );
846 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0xf) * 255 / 0xf );
847 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 12) & 0xf) * 255 / 0xf );
848 }
849
850 static void FETCH(bgra5551)( const struct gl_texture_image *texImage,
851 GLint i, GLint j, GLint k, GLchan *texel )
852 {
853 const GLushort *src = USHORT_SRC( texImage, i, j, k );
854 const GLushort s = *src;
855 texel[RCOMP] = UBYTE_TO_CHAN( ((s >> 10) & 0x1f) * 255 / 0x1f );
856 texel[GCOMP] = UBYTE_TO_CHAN( ((s >> 5) & 0x1f) * 255 / 0x1f );
857 texel[BCOMP] = UBYTE_TO_CHAN( ((s ) & 0x1f) * 255 / 0x1f );
858 texel[ACOMP] = UBYTE_TO_CHAN( ((s >> 15) & 0x01) * 255 );
859 }
860
861 static void FETCH(la88)( const struct gl_texture_image *texImage,
862 GLint i, GLint j, GLint k, GLchan *texel )
863 {
864 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 2 );
865 texel[RCOMP] = UBYTE_TO_CHAN( src[0] );
866 texel[GCOMP] = UBYTE_TO_CHAN( src[0] );
867 texel[BCOMP] = UBYTE_TO_CHAN( src[0] );
868 texel[ACOMP] = UBYTE_TO_CHAN( src[1] );
869 }
870
871 static void FETCH(bgr233)( const struct gl_texture_image *texImage,
872 GLint i, GLint j, GLint k, GLchan *texel )
873 {
874 const GLubyte *src = UBYTE_SRC( texImage, i, j, k, 1 );
875 const GLubyte s = *src;
876 texel[RCOMP] = UBYTE_TO_CHAN( ((s ) & 0xe0) * 255 / 0xe0 );
877 texel[GCOMP] = UBYTE_TO_CHAN( ((s << 3) & 0xe0) * 255 / 0xe0 );
878 texel[BCOMP] = UBYTE_TO_CHAN( ((s << 5) & 0xc0) * 255 / 0xc0 );
879 texel[ACOMP] = CHAN_MAX;
880 }
881 #endif
882
883
884 #undef CHAN_SRC
885 #undef UBYTE_SRC
886 #undef USHORT_SRC
887 #undef FLOAT_SRC
888 #undef FETCH
889 #undef DIM