• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5  * Copyright (c) 2008-2009  VMware, Inc.
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  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 
27 /**
28  * \file texfetch_tmp.h
29  * Texel fetch functions template.
30  *
31  * This template file is used by texfetch.c to generate texel fetch functions
32  * for 1-D, 2-D and 3-D texture images.
33  *
34  * It should be expanded by defining \p DIM as the number texture dimensions
35  * (1, 2 or 3).  According to the value of \p DIM a series of macros is defined
36  * for the texel lookup in the gl_texture_image::Data.
37  *
38  * \author Gareth Hughes
39  * \author Brian Paul
40  */
41 
42 #include <format_unpack.h>
43 
44 #if DIM == 1
45 
46 #define TEXEL_ADDR( type, image, i, j, k, size ) \
47 	((void) (j), (void) (k), ((type *)(image)->ImageSlices[0] + (i) * (size)))
48 
49 #define FETCH(x) fetch_texel_1d_##x
50 
51 #elif DIM == 2
52 
53 #define TEXEL_ADDR( type, image, i, j, k, size )			\
54        ((void) (k),							\
55         ((type *)((GLubyte *) (image)->ImageSlices[0] + (image)->RowStride * (j)) + \
56           (i) * (size)))
57 
58 #define FETCH(x) fetch_texel_2d_##x
59 
60 #elif DIM == 3
61 
62 #define TEXEL_ADDR( type, image, i, j, k, size )			\
63         ((type *)((GLubyte *) (image)->ImageSlices[k] +                      \
64                   (image)->RowStride * (j)) + (i) * (size))
65 
66 #define FETCH(x) fetch_texel_3d_##x
67 
68 #else
69 #error	illegal number of texture dimensions
70 #endif
71 
72 #define FETCH_Z(x, type, size)                       \
73    static void \
74    FETCH(x) (const struct swrast_texture_image *texImage, \
75              GLint i, GLint j, GLint k, GLfloat *texel) \
76    { \
77             const type *src = TEXEL_ADDR(type, texImage, i, j, k, size); \
78             _mesa_unpack_float_z_row(MESA_FORMAT_##x, 1, src, texel); \
79    }
80 
81 #define FETCH_RGBA(x, type, size)                    \
82    static void \
83    FETCH(x) (const struct swrast_texture_image *texImage, \
84              GLint i, GLint j, GLint k, GLfloat *texel) \
85    { \
86             const type *src = TEXEL_ADDR(type, texImage, i, j, k, size); \
87             _mesa_unpack_rgba_row(MESA_FORMAT_##x, 1, src, (GLvoid *)texel); \
88    }
89 
90 FETCH_Z(Z_UNORM32, GLuint, 1)
91 FETCH_Z(Z_UNORM16, GLushort, 1)
92 FETCH_Z(S8_UINT_Z24_UNORM, GLuint, 1) /* only return Z, not stencil data */
93 FETCH_Z(Z24_UNORM_S8_UINT, GLuint, 1) /* only return Z, not stencil data */
94 FETCH_Z(Z32_FLOAT_S8X24_UINT, GLfloat, 2)
95 
96 FETCH_RGBA(RGBA_FLOAT32, GLfloat, 4)
97 FETCH_RGBA(RGBA_FLOAT16, GLhalfARB, 4)
98 FETCH_RGBA(RGB_FLOAT32, GLfloat, 3)
99 FETCH_RGBA(RGB_FLOAT16, GLhalfARB, 3)
100 FETCH_RGBA(A_FLOAT32, GLfloat, 1)
101 FETCH_RGBA(A_FLOAT16, GLhalfARB, 1)
102 FETCH_RGBA(L_FLOAT32, GLfloat, 1)
103 FETCH_RGBA(L_FLOAT16, GLhalfARB, 1)
104 FETCH_RGBA(LA_FLOAT32, GLfloat, 2)
105 FETCH_RGBA(LA_FLOAT16, GLhalfARB, 2)
106 FETCH_RGBA(I_FLOAT32, GLfloat, 1)
107 FETCH_RGBA(I_FLOAT16, GLhalfARB, 1)
108 FETCH_RGBA(R_FLOAT32, GLfloat, 1)
109 FETCH_RGBA(R_FLOAT16, GLhalfARB, 1)
110 FETCH_RGBA(RG_FLOAT32, GLfloat, 2)
111 FETCH_RGBA(RG_FLOAT16, GLhalfARB, 2)
112 FETCH_RGBA(A8B8G8R8_UNORM, GLuint, 1)
113 FETCH_RGBA(R8G8B8A8_UNORM, GLuint, 1)
114 FETCH_RGBA(B8G8R8A8_UNORM, GLuint, 1)
115 FETCH_RGBA(A8R8G8B8_UNORM, GLuint, 1)
116 FETCH_RGBA(X8B8G8R8_UNORM, GLuint, 1)
117 FETCH_RGBA(R8G8B8X8_UNORM, GLuint, 1)
118 FETCH_RGBA(B8G8R8X8_UNORM, GLuint, 1)
119 FETCH_RGBA(X8R8G8B8_UNORM, GLuint, 1)
120 FETCH_RGBA(BGR_UNORM8, GLubyte, 3)
121 FETCH_RGBA(RGB_UNORM8, GLubyte, 3)
122 FETCH_RGBA(B5G6R5_UNORM, GLushort, 1)
123 FETCH_RGBA(R5G6B5_UNORM, GLushort, 1)
124 FETCH_RGBA(B4G4R4A4_UNORM, GLushort, 1)
125 FETCH_RGBA(A4R4G4B4_UNORM, GLushort, 1)
126 FETCH_RGBA(A1B5G5R5_UNORM, GLushort, 1)
127 FETCH_RGBA(B5G5R5A1_UNORM, GLushort, 1)
128 FETCH_RGBA(A1R5G5B5_UNORM, GLushort, 1)
129 FETCH_RGBA(B10G10R10A2_UNORM, GLuint, 1)
130 FETCH_RGBA(R10G10B10A2_UNORM, GLuint, 1)
131 FETCH_RGBA(R8G8_UNORM, GLushort, 1)
132 FETCH_RGBA(G8R8_UNORM, GLushort, 1)
133 FETCH_RGBA(L4A4_UNORM, GLubyte, 1)
134 FETCH_RGBA(L8A8_UNORM, GLushort, 1)
135 FETCH_RGBA(R_UNORM8, GLubyte, 1)
136 FETCH_RGBA(R_UNORM16, GLushort, 1)
137 FETCH_RGBA(A8L8_UNORM, GLushort, 1)
138 FETCH_RGBA(R16G16_UNORM, GLuint, 1)
139 FETCH_RGBA(G16R16_UNORM, GLuint, 1)
140 FETCH_RGBA(L16A16_UNORM, GLuint, 1)
141 FETCH_RGBA(A16L16_UNORM, GLuint, 1)
142 FETCH_RGBA(B2G3R3_UNORM, GLubyte, 1)
143 FETCH_RGBA(A_UNORM8, GLubyte, 1)
144 FETCH_RGBA(A_UNORM16, GLushort, 1)
145 FETCH_RGBA(L_UNORM8, GLubyte, 1)
146 FETCH_RGBA(L_UNORM16, GLushort, 1)
147 FETCH_RGBA(I_UNORM8, GLubyte, 1)
148 FETCH_RGBA(I_UNORM16, GLushort, 1)
149 FETCH_RGBA(BGR_SRGB8, GLubyte, 3)
150 FETCH_RGBA(A8B8G8R8_SRGB, GLuint, 1)
151 FETCH_RGBA(B8G8R8A8_SRGB, GLuint, 1)
152 FETCH_RGBA(A8R8G8B8_SRGB, GLuint, 1)
153 FETCH_RGBA(R8G8B8A8_SRGB, GLuint, 1)
154 FETCH_RGBA(R8G8B8X8_SRGB, GLuint, 1)
155 FETCH_RGBA(X8B8G8R8_SRGB, GLuint, 1)
156 FETCH_RGBA(L_SRGB8, GLubyte, 1)
157 FETCH_RGBA(L8A8_SRGB, GLushort, 1)
158 FETCH_RGBA(A8L8_SRGB, GLushort, 2)
159 FETCH_RGBA(RGBA_SINT8, GLbyte, 4)
160 FETCH_RGBA(RGBA_SINT16, GLshort, 4)
161 FETCH_RGBA(RGBA_SINT32, GLint, 4)
162 FETCH_RGBA(RGBA_UINT8, GLubyte, 4)
163 FETCH_RGBA(RGBA_UINT16, GLushort, 4)
164 FETCH_RGBA(RGBA_UINT32, GLuint, 4)
165 FETCH_RGBA(R_SNORM8, GLbyte, 1)
166 FETCH_RGBA(A_SNORM8, GLbyte, 1)
167 FETCH_RGBA(L_SNORM8, GLbyte, 1)
168 FETCH_RGBA(I_SNORM8, GLbyte, 1)
169 FETCH_RGBA(R8G8_SNORM, GLshort, 1)
170 FETCH_RGBA(L8A8_SNORM, GLshort, 1)
171 FETCH_RGBA(A8L8_SNORM, GLshort, 1)
172 FETCH_RGBA(X8B8G8R8_SNORM, GLint, 1)
173 FETCH_RGBA(A8B8G8R8_SNORM, GLint, 1)
174 FETCH_RGBA(R8G8B8A8_SNORM, GLint, 1)
175 FETCH_RGBA(R_SNORM16, GLshort, 1)
176 FETCH_RGBA(A_SNORM16, GLshort, 1)
177 FETCH_RGBA(L_SNORM16, GLshort, 1)
178 FETCH_RGBA(I_SNORM16, GLshort, 1)
179 FETCH_RGBA(R16G16_SNORM, GLshort, 2)
180 FETCH_RGBA(LA_SNORM16, GLshort, 2)
181 FETCH_RGBA(RGB_SNORM16, GLshort, 3)
182 FETCH_RGBA(RGBA_SNORM16, GLshort, 4)
183 FETCH_RGBA(RGBA_UNORM16, GLushort, 4)
184 FETCH_RGBA(RGBX_UNORM16, GLushort, 4)
185 FETCH_RGBA(RGBX_FLOAT16, GLhalfARB, 4)
186 FETCH_RGBA(RGBX_FLOAT32, GLfloat, 4)
187 FETCH_RGBA(YCBCR, GLushort, 1) /* Fetch texel from 1D, 2D or 3D ycbcr texture, returning RGBA. */
188 FETCH_RGBA(YCBCR_REV, GLushort, 1) /* Fetch texel from 1D, 2D or 3D ycbcr texture, returning RGBA. */
189 FETCH_RGBA(R9G9B9E5_FLOAT, GLuint, 1)
190 FETCH_RGBA(R11G11B10_FLOAT, GLuint, 1)
191 
192 #undef TEXEL_ADDR
193 #undef DIM
194 #undef FETCH
195 #undef FETCH_Z
196 #undef FETCH_RGBA
197