Merge r67713 and r67936 (Eric's parport driver) from trunk
[reactos.git] / reactos / dll / directx / wine / wined3d / utils.c
1 /*
2 * Utility functions for the WineD3D Library
3 *
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2006-2008 Henri Verbeet
9 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
10 * Copyright 2009-2010 Henri Verbeet for CodeWeavers
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27 #include "wined3d_private.h"
28
29 #ifdef _MSC_VER
30 #define copysignf(x, y) ((x) < 0.0f ? -fabsf(y) : fabsf(y))
31 #endif
32
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
34
35 struct wined3d_format_channels
36 {
37 enum wined3d_format_id id;
38 DWORD red_size, green_size, blue_size, alpha_size;
39 DWORD red_offset, green_offset, blue_offset, alpha_offset;
40 UINT bpp;
41 BYTE depth_size, stencil_size;
42 };
43
44 static const struct wined3d_format_channels formats[] =
45 {
46 /* size offset
47 * format id r g b a r g b a bpp depth stencil */
48 {WINED3DFMT_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
49 /* FourCC formats */
50 {WINED3DFMT_UYVY, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
51 {WINED3DFMT_YUY2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
52 {WINED3DFMT_YV12, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
53 {WINED3DFMT_NV12, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
54 {WINED3DFMT_DXT1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
55 {WINED3DFMT_DXT2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
56 {WINED3DFMT_DXT3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
57 {WINED3DFMT_DXT4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
58 {WINED3DFMT_DXT5, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
59 {WINED3DFMT_MULTI2_ARGB8, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
60 {WINED3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
61 {WINED3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
62 /* IEEE formats */
63 {WINED3DFMT_R32_FLOAT, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
64 {WINED3DFMT_R32G32_FLOAT, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
65 {WINED3DFMT_R32G32B32_FLOAT, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
66 {WINED3DFMT_R32G32B32A32_FLOAT, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
67 /* Hmm? */
68 {WINED3DFMT_R8G8_SNORM_Cx, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
69 /* Float */
70 {WINED3DFMT_R16_FLOAT, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
71 {WINED3DFMT_R16G16_FLOAT, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
72 {WINED3DFMT_R16G16_SINT, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
73 {WINED3DFMT_R16G16B16A16_FLOAT, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
74 {WINED3DFMT_R16G16B16A16_SINT, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
75 /* Palettized formats */
76 {WINED3DFMT_P8_UINT_A8_UNORM, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
77 {WINED3DFMT_P8_UINT, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
78 /* Standard ARGB formats. */
79 {WINED3DFMT_B8G8R8_UNORM, 8, 8, 8, 0, 16, 8, 0, 0, 3, 0, 0},
80 {WINED3DFMT_B8G8R8A8_UNORM, 8, 8, 8, 8, 16, 8, 0, 24, 4, 0, 0},
81 {WINED3DFMT_B8G8R8X8_UNORM, 8, 8, 8, 0, 16, 8, 0, 0, 4, 0, 0},
82 {WINED3DFMT_B5G6R5_UNORM, 5, 6, 5, 0, 11, 5, 0, 0, 2, 0, 0},
83 {WINED3DFMT_B5G5R5X1_UNORM, 5, 5, 5, 0, 10, 5, 0, 0, 2, 0, 0},
84 {WINED3DFMT_B5G5R5A1_UNORM, 5, 5, 5, 1, 10, 5, 0, 15, 2, 0, 0},
85 {WINED3DFMT_B4G4R4A4_UNORM, 4, 4, 4, 4, 8, 4, 0, 12, 2, 0, 0},
86 {WINED3DFMT_B2G3R3_UNORM, 3, 3, 2, 0, 5, 2, 0, 0, 1, 0, 0},
87 {WINED3DFMT_R8_UNORM, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
88 {WINED3DFMT_A8_UNORM, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0},
89 {WINED3DFMT_B2G3R3A8_UNORM, 3, 3, 2, 8, 5, 2, 0, 8, 2, 0, 0},
90 {WINED3DFMT_B4G4R4X4_UNORM, 4, 4, 4, 0, 8, 4, 0, 0, 2, 0, 0},
91 {WINED3DFMT_R10G10B10A2_UNORM, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
92 {WINED3DFMT_R10G10B10A2_UINT, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
93 {WINED3DFMT_R10G10B10A2_SNORM, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
94 {WINED3DFMT_R8G8B8A8_UNORM, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
95 {WINED3DFMT_R8G8B8A8_UINT, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
96 {WINED3DFMT_R8G8B8X8_UNORM, 8, 8, 8, 0, 0, 8, 16, 0, 4, 0, 0},
97 {WINED3DFMT_R16G16_UNORM, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
98 {WINED3DFMT_B10G10R10A2_UNORM, 10, 10, 10, 2, 20, 10, 0, 30, 4, 0, 0},
99 {WINED3DFMT_R16G16B16A16_UNORM, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
100 /* Luminance */
101 {WINED3DFMT_L8_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
102 {WINED3DFMT_L8A8_UNORM, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
103 {WINED3DFMT_L4A4_UNORM, 0, 0, 0, 4, 0, 0, 0, 4, 1, 0, 0},
104 {WINED3DFMT_L16_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
105 /* Bump mapping stuff */
106 {WINED3DFMT_R8G8_SNORM, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
107 {WINED3DFMT_R5G5_SNORM_L6_UNORM, 5, 5, 0, 0, 0, 5, 0, 0, 2, 0, 0},
108 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, 8, 8, 0, 0, 0, 8, 0, 0, 4, 0, 0},
109 {WINED3DFMT_R8G8B8A8_SNORM, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
110 {WINED3DFMT_R16G16_SNORM, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
111 {WINED3DFMT_R10G11B11_SNORM, 10, 11, 11, 0, 0, 10, 21, 0, 4, 0, 0},
112 {WINED3DFMT_R10G10B10_SNORM_A2_UNORM, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
113 /* Depth stencil formats */
114 {WINED3DFMT_D16_LOCKABLE, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
115 {WINED3DFMT_D32_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
116 {WINED3DFMT_S1_UINT_D15_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 2, 15, 1},
117 {WINED3DFMT_D24_UNORM_S8_UINT, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
118 {WINED3DFMT_X8D24_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 0},
119 {WINED3DFMT_S4X4_UINT_D24_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 4},
120 {WINED3DFMT_D16_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
121 {WINED3DFMT_D32_FLOAT, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
122 {WINED3DFMT_S8_UINT_D24_FLOAT, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
123 {WINED3DFMT_VERTEXDATA, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
124 {WINED3DFMT_R16_UINT, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
125 {WINED3DFMT_R32_UINT, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
126 {WINED3DFMT_R32G32_UINT, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
127 {WINED3DFMT_R32G32B32_UINT, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
128 {WINED3DFMT_R32G32B32A32_UINT, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
129 {WINED3DFMT_R16G16B16A16_SNORM, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
130 /* Vendor-specific formats */
131 {WINED3DFMT_ATI1N, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
132 {WINED3DFMT_ATI2N, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
133 {WINED3DFMT_NVDB, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
134 {WINED3DFMT_INST, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
135 {WINED3DFMT_INTZ, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
136 {WINED3DFMT_RESZ, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
137 {WINED3DFMT_NVHU, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
138 {WINED3DFMT_NVHS, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
139 {WINED3DFMT_NULL, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
140 /* Unsure about them, could not find a Windows driver that supports them */
141 {WINED3DFMT_R16, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
142 {WINED3DFMT_AL16, 0, 0, 0, 16, 0, 0, 0, 16, 4, 0, 0},
143 /* Typeless */
144 {WINED3DFMT_R8_TYPELESS, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
145 {WINED3DFMT_R8G8_TYPELESS, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
146 {WINED3DFMT_R8G8B8A8_TYPELESS, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
147 {WINED3DFMT_R16_TYPELESS, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
148 {WINED3DFMT_R16G16_TYPELESS, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
149 {WINED3DFMT_R16G16B16A16_TYPELESS, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
150 {WINED3DFMT_R32_TYPELESS, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
151 {WINED3DFMT_R32G32_TYPELESS, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
152 {WINED3DFMT_R32G32B32_TYPELESS, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
153 {WINED3DFMT_R32G32B32A32_TYPELESS, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
154 };
155
156 struct wined3d_format_base_flags
157 {
158 enum wined3d_format_id id;
159 DWORD flags;
160 };
161
162 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
163 * still needs to use the correct block based calculation for e.g. the
164 * resource size. */
165 static const struct wined3d_format_base_flags format_base_flags[] =
166 {
167 {WINED3DFMT_P8_UINT, WINED3DFMT_FLAG_GETDC},
168 {WINED3DFMT_B8G8R8_UNORM, WINED3DFMT_FLAG_GETDC},
169 {WINED3DFMT_B8G8R8A8_UNORM, WINED3DFMT_FLAG_GETDC},
170 {WINED3DFMT_B8G8R8X8_UNORM, WINED3DFMT_FLAG_GETDC},
171 {WINED3DFMT_B5G6R5_UNORM, WINED3DFMT_FLAG_GETDC},
172 {WINED3DFMT_B5G5R5X1_UNORM, WINED3DFMT_FLAG_GETDC},
173 {WINED3DFMT_B5G5R5A1_UNORM, WINED3DFMT_FLAG_GETDC},
174 {WINED3DFMT_B4G4R4A4_UNORM, WINED3DFMT_FLAG_GETDC},
175 {WINED3DFMT_B4G4R4X4_UNORM, WINED3DFMT_FLAG_GETDC},
176 {WINED3DFMT_R8G8B8A8_UNORM, WINED3DFMT_FLAG_GETDC},
177 {WINED3DFMT_R8G8B8X8_UNORM, WINED3DFMT_FLAG_GETDC},
178 {WINED3DFMT_ATI1N, WINED3DFMT_FLAG_BROKEN_PITCH},
179 {WINED3DFMT_ATI2N, WINED3DFMT_FLAG_BROKEN_PITCH},
180 {WINED3DFMT_R32_FLOAT, WINED3DFMT_FLAG_FLOAT},
181 {WINED3DFMT_R32G32_FLOAT, WINED3DFMT_FLAG_FLOAT},
182 {WINED3DFMT_R32G32B32_FLOAT, WINED3DFMT_FLAG_FLOAT},
183 {WINED3DFMT_R32G32B32A32_FLOAT, WINED3DFMT_FLAG_FLOAT},
184 {WINED3DFMT_R16_FLOAT, WINED3DFMT_FLAG_FLOAT},
185 {WINED3DFMT_R16G16_FLOAT, WINED3DFMT_FLAG_FLOAT},
186 {WINED3DFMT_R16G16B16A16_FLOAT, WINED3DFMT_FLAG_FLOAT},
187 {WINED3DFMT_D32_FLOAT, WINED3DFMT_FLAG_FLOAT},
188 {WINED3DFMT_S8_UINT_D24_FLOAT, WINED3DFMT_FLAG_FLOAT},
189 };
190
191 struct wined3d_format_block_info
192 {
193 enum wined3d_format_id id;
194 UINT block_width;
195 UINT block_height;
196 UINT block_byte_count;
197 BOOL verify;
198 };
199
200 static const struct wined3d_format_block_info format_block_info[] =
201 {
202 {WINED3DFMT_DXT1, 4, 4, 8, TRUE},
203 {WINED3DFMT_DXT2, 4, 4, 16, TRUE},
204 {WINED3DFMT_DXT3, 4, 4, 16, TRUE},
205 {WINED3DFMT_DXT4, 4, 4, 16, TRUE},
206 {WINED3DFMT_DXT5, 4, 4, 16, TRUE},
207 {WINED3DFMT_ATI1N, 4, 4, 8, FALSE},
208 {WINED3DFMT_ATI2N, 4, 4, 16, FALSE},
209 {WINED3DFMT_YUY2, 2, 1, 4, FALSE},
210 {WINED3DFMT_UYVY, 2, 1, 4, FALSE},
211 };
212
213 struct wined3d_format_vertex_info
214 {
215 enum wined3d_format_id id;
216 enum wined3d_ffp_emit_idx emit_idx;
217 GLint component_count;
218 GLenum gl_vtx_type;
219 GLint gl_vtx_format;
220 GLboolean gl_normalized;
221 unsigned int component_size;
222 };
223
224 static const struct wined3d_format_vertex_info format_vertex_info[] =
225 {
226 {WINED3DFMT_R32_FLOAT, WINED3D_FFP_EMIT_FLOAT1, 1, GL_FLOAT, 1, GL_FALSE, sizeof(float)},
227 {WINED3DFMT_R32G32_FLOAT, WINED3D_FFP_EMIT_FLOAT2, 2, GL_FLOAT, 2, GL_FALSE, sizeof(float)},
228 {WINED3DFMT_R32G32B32_FLOAT, WINED3D_FFP_EMIT_FLOAT3, 3, GL_FLOAT, 3, GL_FALSE, sizeof(float)},
229 {WINED3DFMT_R32G32B32A32_FLOAT, WINED3D_FFP_EMIT_FLOAT4, 4, GL_FLOAT, 4, GL_FALSE, sizeof(float)},
230 {WINED3DFMT_B8G8R8A8_UNORM, WINED3D_FFP_EMIT_D3DCOLOR, 4, GL_UNSIGNED_BYTE, 4, GL_TRUE, sizeof(BYTE)},
231 {WINED3DFMT_R8G8B8A8_UINT, WINED3D_FFP_EMIT_UBYTE4, 4, GL_UNSIGNED_BYTE, 4, GL_FALSE, sizeof(BYTE)},
232 {WINED3DFMT_R16G16_SINT, WINED3D_FFP_EMIT_SHORT2, 2, GL_SHORT, 2, GL_FALSE, sizeof(short int)},
233 {WINED3DFMT_R16G16B16A16_SINT, WINED3D_FFP_EMIT_SHORT4, 4, GL_SHORT, 4, GL_FALSE, sizeof(short int)},
234 {WINED3DFMT_R8G8B8A8_UNORM, WINED3D_FFP_EMIT_UBYTE4N, 4, GL_UNSIGNED_BYTE, 4, GL_TRUE, sizeof(BYTE)},
235 {WINED3DFMT_R16G16_SNORM, WINED3D_FFP_EMIT_SHORT2N, 2, GL_SHORT, 2, GL_TRUE, sizeof(short int)},
236 {WINED3DFMT_R16G16B16A16_SNORM, WINED3D_FFP_EMIT_SHORT4N, 4, GL_SHORT, 4, GL_TRUE, sizeof(short int)},
237 {WINED3DFMT_R16G16_UNORM, WINED3D_FFP_EMIT_USHORT2N, 2, GL_UNSIGNED_SHORT, 2, GL_TRUE, sizeof(short int)},
238 {WINED3DFMT_R16G16B16A16_UNORM, WINED3D_FFP_EMIT_USHORT4N, 4, GL_UNSIGNED_SHORT, 4, GL_TRUE, sizeof(short int)},
239 {WINED3DFMT_R10G10B10A2_UINT, WINED3D_FFP_EMIT_UDEC3, 3, GL_UNSIGNED_SHORT, 3, GL_FALSE, sizeof(short int)},
240 {WINED3DFMT_R10G10B10A2_SNORM, WINED3D_FFP_EMIT_DEC3N, 3, GL_SHORT, 3, GL_TRUE, sizeof(short int)},
241 {WINED3DFMT_R16G16_FLOAT, WINED3D_FFP_EMIT_FLOAT16_2, 2, GL_FLOAT, 2, GL_FALSE, sizeof(GLhalfNV)},
242 {WINED3DFMT_R16G16B16A16_FLOAT, WINED3D_FFP_EMIT_FLOAT16_4, 4, GL_FLOAT, 4, GL_FALSE, sizeof(GLhalfNV)},
243 {WINED3DFMT_R32_UINT, WINED3D_FFP_EMIT_INVALID, 1, GL_UNSIGNED_INT, 1, GL_FALSE, sizeof(UINT)},
244 {WINED3DFMT_R32G32_UINT, WINED3D_FFP_EMIT_INVALID, 2, GL_UNSIGNED_INT, 2, GL_FALSE, sizeof(UINT)},
245 {WINED3DFMT_R32G32B32_UINT, WINED3D_FFP_EMIT_INVALID, 3, GL_UNSIGNED_INT, 3, GL_FALSE, sizeof(UINT)},
246 {WINED3DFMT_R32G32B32A32_UINT, WINED3D_FFP_EMIT_INVALID, 4, GL_UNSIGNED_INT, 4, GL_FALSE, sizeof(UINT)},
247 };
248
249 struct wined3d_format_texture_info
250 {
251 enum wined3d_format_id id;
252 GLint gl_internal;
253 GLint gl_srgb_internal;
254 GLint gl_rt_internal;
255 GLint gl_format;
256 GLint gl_type;
257 unsigned int conv_byte_count;
258 unsigned int flags;
259 enum wined3d_gl_extension extension;
260 void (*convert)(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
261 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth);
262 };
263
264 static void convert_l4a4_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
265 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
266 {
267 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
268 * format+type combination to load it. Thus convert it to A8L8, then load it
269 * with A4L4 internal, but A8L8 format+type
270 */
271 unsigned int x, y, z;
272 const unsigned char *Source;
273 unsigned char *Dest;
274
275 for (z = 0; z < depth; z++)
276 {
277 for (y = 0; y < height; y++)
278 {
279 Source = src + z * src_slice_pitch + y * src_row_pitch;
280 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
281 for (x = 0; x < width; x++ )
282 {
283 unsigned char color = (*Source++);
284 /* A */ Dest[1] = (color & 0xf0) << 0;
285 /* L */ Dest[0] = (color & 0x0f) << 4;
286 Dest += 2;
287 }
288 }
289 }
290 }
291
292 static void convert_r5g5_snorm_l6_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
293 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
294 {
295 unsigned int x, y, z;
296 const WORD *Source;
297
298 for (z = 0; z < depth; z++)
299 {
300 for (y = 0; y < height; y++)
301 {
302 unsigned short *Dest_s = (unsigned short *) (dst + z * dst_slice_pitch + y * dst_row_pitch);
303 Source = (const WORD *)(src + z * src_slice_pitch + y * src_row_pitch);
304 for (x = 0; x < width; x++ )
305 {
306 short color = (*Source++);
307 unsigned char l = ((color >> 10) & 0xfc);
308 short v = ((color >> 5) & 0x3e);
309 short u = ((color ) & 0x1f);
310 short v_conv = v + 16;
311 short u_conv = u + 16;
312
313 *Dest_s = ((v_conv << 11) & 0xf800) | ((l << 5) & 0x7e0) | (u_conv & 0x1f);
314 Dest_s += 1;
315 }
316 }
317 }
318 }
319
320 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
321 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
322 {
323 unsigned int x, y, z;
324 const WORD *Source;
325 unsigned char *Dest;
326
327 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
328 * fixed function and shaders without further conversion once the surface is
329 * loaded
330 */
331 for (z = 0; z < depth; z++)
332 {
333 for (y = 0; y < height; y++)
334 {
335 Source = (const WORD *)(src + z * src_slice_pitch + y * src_row_pitch);
336 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
337 for (x = 0; x < width; x++ )
338 {
339 short color = (*Source++);
340 unsigned char l = ((color >> 10) & 0xfc);
341 char v = ((color >> 5) & 0x3e);
342 char u = ((color ) & 0x1f);
343
344 /* 8 bits destination, 6 bits source, 8th bit is the sign. gl ignores the sign
345 * and doubles the positive range. Thus shift left only once, gl does the 2nd
346 * shift. GL reads a signed value and converts it into an unsigned value.
347 */
348 /* M */ Dest[2] = l << 1;
349
350 /* Those are read as signed, but kept signed. Just left-shift 3 times to scale
351 * from 5 bit values to 8 bit values.
352 */
353 /* V */ Dest[1] = v << 3;
354 /* U */ Dest[0] = u << 3;
355 Dest += 3;
356 }
357 }
358 }
359 }
360
361 static void convert_r8g8_snorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
362 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
363 {
364 unsigned int x, y, z;
365 const short *Source;
366 unsigned char *Dest;
367
368 for (z = 0; z < depth; z++)
369 {
370 for (y = 0; y < height; y++)
371 {
372 Source = (const short *)(src + z * src_slice_pitch + y * src_row_pitch);
373 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
374 for (x = 0; x < width; x++ )
375 {
376 const short color = (*Source++);
377 /* B */ Dest[0] = 0xff;
378 /* G */ Dest[1] = (color >> 8) + 128; /* V */
379 /* R */ Dest[2] = (color & 0xff) + 128; /* U */
380 Dest += 3;
381 }
382 }
383 }
384 }
385
386 static void convert_r8g8_snorm_l8x8_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
387 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
388 {
389 unsigned int x, y, z;
390 const DWORD *Source;
391 unsigned char *Dest;
392
393 /* Doesn't work correctly with the fixed function pipeline, but can work in
394 * shaders if the shader is adjusted. (There's no use for this format in gl's
395 * standard fixed function pipeline anyway).
396 */
397 for (z = 0; z < depth; z++)
398 {
399 for (y = 0; y < height; y++)
400 {
401 Source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
402 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
403 for (x = 0; x < width; x++ )
404 {
405 LONG color = (*Source++);
406 /* B */ Dest[0] = ((color >> 16) & 0xff); /* L */
407 /* G */ Dest[1] = ((color >> 8 ) & 0xff) + 128; /* V */
408 /* R */ Dest[2] = (color & 0xff) + 128; /* U */
409 Dest += 4;
410 }
411 }
412 }
413 }
414
415 static void convert_r8g8_snorm_l8x8_unorm_nv(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
416 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
417 {
418 unsigned int x, y, z;
419 const DWORD *Source;
420 unsigned char *Dest;
421
422 /* This implementation works with the fixed function pipeline and shaders
423 * without further modification after converting the surface.
424 */
425 for (z = 0; z < depth; z++)
426 {
427 for (y = 0; y < height; y++)
428 {
429 Source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
430 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
431 for (x = 0; x < width; x++ )
432 {
433 LONG color = (*Source++);
434 /* L */ Dest[2] = ((color >> 16) & 0xff); /* L */
435 /* V */ Dest[1] = ((color >> 8 ) & 0xff); /* V */
436 /* U */ Dest[0] = (color & 0xff); /* U */
437 /* I */ Dest[3] = 255; /* X */
438 Dest += 4;
439 }
440 }
441 }
442 }
443
444 static void convert_r8g8b8a8_snorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
445 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
446 {
447 unsigned int x, y, z;
448 const DWORD *Source;
449 unsigned char *Dest;
450
451 for (z = 0; z < depth; z++)
452 {
453 for (y = 0; y < height; y++)
454 {
455 Source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
456 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
457 for (x = 0; x < width; x++ )
458 {
459 LONG color = (*Source++);
460 /* B */ Dest[0] = ((color >> 16) & 0xff) + 128; /* W */
461 /* G */ Dest[1] = ((color >> 8 ) & 0xff) + 128; /* V */
462 /* R */ Dest[2] = (color & 0xff) + 128; /* U */
463 /* A */ Dest[3] = ((color >> 24) & 0xff) + 128; /* Q */
464 Dest += 4;
465 }
466 }
467 }
468 }
469
470 static void convert_r16g16_snorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
471 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
472 {
473 unsigned int x, y, z;
474 const DWORD *Source;
475 unsigned short *Dest;
476
477 for (z = 0; z < depth; z++)
478 {
479 for (y = 0; y < height; y++)
480 {
481 Source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
482 Dest = (unsigned short *) (dst + z * dst_slice_pitch + y * dst_row_pitch);
483 for (x = 0; x < width; x++ )
484 {
485 const DWORD color = (*Source++);
486 /* B */ Dest[0] = 0xffff;
487 /* G */ Dest[1] = (color >> 16) + 32768; /* V */
488 /* R */ Dest[2] = (color & 0xffff) + 32768; /* U */
489 Dest += 3;
490 }
491 }
492 }
493 }
494
495 static void convert_r16g16(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
496 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
497 {
498 unsigned int x, y, z;
499 const WORD *Source;
500 WORD *Dest;
501
502 for (z = 0; z < depth; z++)
503 {
504 for (y = 0; y < height; y++)
505 {
506 Source = (const WORD *)(src + z * src_slice_pitch + y * src_row_pitch);
507 Dest = (WORD *) (dst + z * dst_slice_pitch + y * dst_row_pitch);
508 for (x = 0; x < width; x++ )
509 {
510 WORD green = (*Source++);
511 WORD red = (*Source++);
512 Dest[0] = green;
513 Dest[1] = red;
514 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
515 * shader overwrites it anyway */
516 Dest[2] = 0xffff;
517 Dest += 3;
518 }
519 }
520 }
521 }
522
523 static void convert_r32g32_float(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
524 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
525 {
526 unsigned int x, y, z;
527 const float *Source;
528 float *Dest;
529
530 for (z = 0; z < depth; z++)
531 {
532 for (y = 0; y < height; y++)
533 {
534 Source = (const float *)(src + z * src_slice_pitch + y * src_row_pitch);
535 Dest = (float *) (dst + z * dst_slice_pitch + y * dst_row_pitch);
536 for (x = 0; x < width; x++ )
537 {
538 float green = (*Source++);
539 float red = (*Source++);
540 Dest[0] = green;
541 Dest[1] = red;
542 Dest[2] = 1.0f;
543 Dest += 3;
544 }
545 }
546 }
547 }
548
549 static void convert_s1_uint_d15_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
550 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
551 {
552 unsigned int x, y, z;
553
554 for (z = 0; z < depth; z++)
555 {
556 for (y = 0; y < height; ++y)
557 {
558 const WORD *source = (const WORD *)(src + z * src_slice_pitch + y * src_row_pitch);
559 DWORD *dest = (DWORD *)(dst + z * dst_slice_pitch + y * dst_row_pitch);
560
561 for (x = 0; x < width; ++x)
562 {
563 /* The depth data is normalized, so needs to be scaled,
564 * the stencil data isn't. Scale depth data by
565 * (2^24-1)/(2^15-1) ~~ (2^9 + 2^-6). */
566 WORD d15 = source[x] >> 1;
567 DWORD d24 = (d15 << 9) + (d15 >> 6);
568 dest[x] = (d24 << 8) | (source[x] & 0x1);
569 }
570 }
571 }
572 }
573
574 static void convert_s4x4_uint_d24_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
575 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
576 {
577 unsigned int x, y, z;
578
579 for (z = 0; z < depth; z++)
580 {
581 for (y = 0; y < height; ++y)
582 {
583 const DWORD *source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
584 DWORD *dest = (DWORD *)(dst + z * dst_slice_pitch + y * dst_row_pitch);
585
586 for (x = 0; x < width; ++x)
587 {
588 /* Just need to clear out the X4 part. */
589 dest[x] = source[x] & ~0xf0;
590 }
591 }
592 }
593 }
594
595 static void convert_s8_uint_d24_float(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
596 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
597 {
598 unsigned int x, y, z;
599
600 for (z = 0; z < depth; z++)
601 {
602 for (y = 0; y < height; ++y)
603 {
604 const DWORD *source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
605 float *dest_f = (float *)(dst + z * dst_slice_pitch + y * dst_row_pitch);
606 DWORD *dest_s = (DWORD *)dest_f;
607
608 for (x = 0; x < width; ++x)
609 {
610 dest_f[x * 2] = float_24_to_32((source[x] & 0xffffff00) >> 8);
611 dest_s[x * 2 + 1] = source[x] & 0xff;
612 }
613 }
614 }
615 }
616
617 static BOOL color_in_range(const struct wined3d_color_key *color_key, DWORD color)
618 {
619 /* FIXME: Is this really how color keys are supposed to work? I think it
620 * makes more sense to compare the individual channels. */
621 return color >= color_key->color_space_low_value
622 && color <= color_key->color_space_high_value;
623 }
624
625 static void convert_p8_uint_b8g8r8a8_unorm(const BYTE *src, unsigned int src_pitch,
626 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
627 const struct wined3d_palette *palette, const struct wined3d_color_key *color_key)
628 {
629 const BYTE *src_row;
630 unsigned int x, y;
631 DWORD *dst_row;
632
633 if (!palette)
634 {
635 /* FIXME: This should probably use the system palette. */
636 FIXME("P8 surface loaded without a palette.\n");
637
638 for (y = 0; y < height; ++y)
639 {
640 memset(&dst[dst_pitch * y], 0, width * 4);
641 }
642
643 return;
644 }
645
646 for (y = 0; y < height; ++y)
647 {
648 src_row = &src[src_pitch * y];
649 dst_row = (DWORD *)&dst[dst_pitch * y];
650 for (x = 0; x < width; ++x)
651 {
652 BYTE src_color = src_row[x];
653 dst_row[x] = 0xff000000
654 | (palette->colors[src_color].rgbRed << 16)
655 | (palette->colors[src_color].rgbGreen << 8)
656 | palette->colors[src_color].rgbBlue;
657 }
658 }
659 }
660
661 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(const BYTE *src, unsigned int src_pitch,
662 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
663 const struct wined3d_palette *palette, const struct wined3d_color_key *color_key)
664 {
665 const WORD *src_row;
666 unsigned int x, y;
667 WORD *dst_row;
668
669 for (y = 0; y < height; ++y)
670 {
671 src_row = (WORD *)&src[src_pitch * y];
672 dst_row = (WORD *)&dst[dst_pitch * y];
673 for (x = 0; x < width; ++x)
674 {
675 WORD src_color = src_row[x];
676 if (!color_in_range(color_key, src_color))
677 dst_row[x] = 0x8000 | ((src_color & 0xffc0) >> 1) | (src_color & 0x1f);
678 else
679 dst_row[x] = ((src_color & 0xffc0) >> 1) | (src_color & 0x1f);
680 }
681 }
682 }
683
684 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(const BYTE *src, unsigned int src_pitch,
685 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
686 const struct wined3d_palette *palette, const struct wined3d_color_key *color_key)
687 {
688 const WORD *src_row;
689 unsigned int x, y;
690 WORD *dst_row;
691
692 for (y = 0; y < height; ++y)
693 {
694 src_row = (WORD *)&src[src_pitch * y];
695 dst_row = (WORD *)&dst[dst_pitch * y];
696 for (x = 0; x < width; ++x)
697 {
698 WORD src_color = src_row[x];
699 if (color_in_range(color_key, src_color))
700 dst_row[x] = src_color & ~0x8000;
701 else
702 dst_row[x] = src_color | 0x8000;
703 }
704 }
705 }
706
707 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE *src, unsigned int src_pitch,
708 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
709 const struct wined3d_palette *palette, const struct wined3d_color_key *color_key)
710 {
711 const BYTE *src_row;
712 unsigned int x, y;
713 DWORD *dst_row;
714
715 for (y = 0; y < height; ++y)
716 {
717 src_row = &src[src_pitch * y];
718 dst_row = (DWORD *)&dst[dst_pitch * y];
719 for (x = 0; x < width; ++x)
720 {
721 DWORD src_color = (src_row[x * 3 + 2] << 16) | (src_row[x * 3 + 1] << 8) | src_row[x * 3];
722 if (!color_in_range(color_key, src_color))
723 dst_row[x] = src_color | 0xff000000;
724 }
725 }
726 }
727
728 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE *src, unsigned int src_pitch,
729 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
730 const struct wined3d_palette *palette, const struct wined3d_color_key *color_key)
731 {
732 const DWORD *src_row;
733 unsigned int x, y;
734 DWORD *dst_row;
735
736 for (y = 0; y < height; ++y)
737 {
738 src_row = (DWORD *)&src[src_pitch * y];
739 dst_row = (DWORD *)&dst[dst_pitch * y];
740 for (x = 0; x < width; ++x)
741 {
742 DWORD src_color = src_row[x];
743 if (color_in_range(color_key, src_color))
744 dst_row[x] = src_color & ~0xff000000;
745 else
746 dst_row[x] = src_color | 0xff000000;
747 }
748 }
749 }
750
751 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE *src, unsigned int src_pitch,
752 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
753 const struct wined3d_palette *palette, const struct wined3d_color_key *color_key)
754 {
755 const DWORD *src_row;
756 unsigned int x, y;
757 DWORD *dst_row;
758
759 for (y = 0; y < height; ++y)
760 {
761 src_row = (DWORD *)&src[src_pitch * y];
762 dst_row = (DWORD *)&dst[dst_pitch * y];
763 for (x = 0; x < width; ++x)
764 {
765 DWORD src_color = src_row[x];
766 if (color_in_range(color_key, src_color))
767 src_color &= ~0xff000000;
768 dst_row[x] = src_color;
769 }
770 }
771 }
772
773 const struct wined3d_color_key_conversion * wined3d_format_get_color_key_conversion(
774 const struct wined3d_texture *texture, BOOL need_alpha_ck)
775 {
776 const struct wined3d_format *format = texture->resource.format;
777 unsigned int i;
778
779 static const struct
780 {
781 enum wined3d_format_id src_format;
782 struct wined3d_color_key_conversion conversion;
783 }
784 color_key_info[] =
785 {
786 {WINED3DFMT_B5G6R5_UNORM, {WINED3DFMT_B5G5R5A1_UNORM, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key }},
787 {WINED3DFMT_B5G5R5X1_UNORM, {WINED3DFMT_B5G5R5A1_UNORM, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key }},
788 {WINED3DFMT_B8G8R8_UNORM, {WINED3DFMT_B8G8R8A8_UNORM, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key }},
789 {WINED3DFMT_B8G8R8X8_UNORM, {WINED3DFMT_B8G8R8A8_UNORM, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key }},
790 {WINED3DFMT_B8G8R8A8_UNORM, {WINED3DFMT_B8G8R8A8_UNORM, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key }},
791 };
792 static const struct wined3d_color_key_conversion convert_p8 =
793 {
794 WINED3DFMT_B8G8R8A8_UNORM, convert_p8_uint_b8g8r8a8_unorm
795 };
796
797 if (need_alpha_ck && (texture->flags & WINED3D_TEXTURE_COLOR_KEY))
798 {
799 for (i = 0; i < sizeof(color_key_info) / sizeof(*color_key_info); ++i)
800 {
801 if (color_key_info[i].src_format == format->id)
802 return &color_key_info[i].conversion;
803 }
804
805 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format->id));
806 }
807
808 /* FIXME: This should check if the blitter backend can do P8 conversion,
809 * instead of checking for ARB_fragment_program. */
810 if (format->id == WINED3DFMT_P8_UINT
811 && !(texture->resource.device->adapter->gl_info.supported[ARB_FRAGMENT_PROGRAM]
812 && texture->swapchain && texture == texture->swapchain->front_buffer))
813 return &convert_p8;
814
815 return NULL;
816 }
817
818 /* The following formats explicitly don't have WINED3DFMT_FLAG_TEXTURE set:
819 *
820 * These are never supported on native.
821 * WINED3DFMT_B8G8R8_UNORM
822 * WINED3DFMT_B2G3R3_UNORM
823 * WINED3DFMT_L4A4_UNORM
824 * WINED3DFMT_S1_UINT_D15_UNORM
825 * WINED3DFMT_S4X4_UINT_D24_UNORM
826 *
827 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
828 * Since it is not widely available, don't offer it. Further no Windows driver
829 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
830 * WINED3DFMT_P8_UINT
831 * WINED3DFMT_P8_UINT_A8_UNORM
832 *
833 * These formats seem to be similar to the HILO formats in
834 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
835 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
836 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
837 * refused to support formats which can easily be emulated with pixel shaders,
838 * so applications have to deal with not having NVHS and NVHU.
839 * WINED3DFMT_NVHU
840 * WINED3DFMT_NVHS */
841 static const struct wined3d_format_texture_info format_texture_info[] =
842 {
843 /* format id gl_internal gl_srgb_internal gl_rt_internal
844 gl_format gl_type conv_byte_count
845 flags
846 extension convert */
847 /* FourCC formats */
848 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
849 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
850 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
851 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
852 * endian machine
853 */
854 {WINED3DFMT_UYVY, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, 0,
855 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
856 WINED3DFMT_FLAG_FILTERING,
857 WINED3D_GL_EXT_NONE, NULL},
858 {WINED3DFMT_UYVY, GL_RGB, GL_RGB, 0,
859 GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, 0,
860 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_FILTERING,
861 APPLE_YCBCR_422, NULL},
862 {WINED3DFMT_YUY2, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, 0,
863 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
864 WINED3DFMT_FLAG_FILTERING,
865 WINED3D_GL_EXT_NONE, NULL},
866 {WINED3DFMT_YUY2, GL_RGB, GL_RGB, 0,
867 GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, 0,
868 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_FILTERING,
869 APPLE_YCBCR_422, NULL},
870 {WINED3DFMT_YV12, GL_ALPHA, GL_ALPHA, 0,
871 GL_ALPHA, GL_UNSIGNED_BYTE, 0,
872 WINED3DFMT_FLAG_FILTERING,
873 WINED3D_GL_EXT_NONE, NULL},
874 {WINED3DFMT_NV12, GL_ALPHA, GL_ALPHA, 0,
875 GL_ALPHA, GL_UNSIGNED_BYTE, 0,
876 WINED3DFMT_FLAG_FILTERING,
877 WINED3D_GL_EXT_NONE, NULL},
878 {WINED3DFMT_DXT1, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 0,
879 GL_RGBA, GL_UNSIGNED_BYTE, 0,
880 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
881 | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_COMPRESSED,
882 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
883 {WINED3DFMT_DXT2, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0,
884 GL_RGBA, GL_UNSIGNED_BYTE, 0,
885 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
886 | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_COMPRESSED,
887 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
888 {WINED3DFMT_DXT3, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0,
889 GL_RGBA, GL_UNSIGNED_BYTE, 0,
890 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
891 | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_COMPRESSED,
892 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
893 {WINED3DFMT_DXT4, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0,
894 GL_RGBA, GL_UNSIGNED_BYTE, 0,
895 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
896 | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_COMPRESSED,
897 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
898 {WINED3DFMT_DXT5, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0,
899 GL_RGBA, GL_UNSIGNED_BYTE, 0,
900 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
901 | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_COMPRESSED,
902 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
903 /* IEEE formats */
904 {WINED3DFMT_R32_FLOAT, GL_RGB32F_ARB, GL_RGB32F_ARB, 0,
905 GL_RED, GL_FLOAT, 0,
906 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
907 ARB_TEXTURE_FLOAT, NULL},
908 {WINED3DFMT_R32_FLOAT, GL_R32F, GL_R32F, 0,
909 GL_RED, GL_FLOAT, 0,
910 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
911 ARB_TEXTURE_RG, NULL},
912 {WINED3DFMT_R32G32_FLOAT, GL_RGB32F_ARB, GL_RGB32F_ARB, 0,
913 GL_RGB, GL_FLOAT, 12,
914 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
915 ARB_TEXTURE_FLOAT, convert_r32g32_float},
916 {WINED3DFMT_R32G32_FLOAT, GL_RG32F, GL_RG32F, 0,
917 GL_RG, GL_FLOAT, 0,
918 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
919 ARB_TEXTURE_RG, NULL},
920 {WINED3DFMT_R32G32B32A32_FLOAT, GL_RGBA32F_ARB, GL_RGBA32F_ARB, 0,
921 GL_RGBA, GL_FLOAT, 0,
922 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
923 ARB_TEXTURE_FLOAT, NULL},
924 /* Float */
925 {WINED3DFMT_R16_FLOAT, GL_RGB16F_ARB, GL_RGB16F_ARB, 0,
926 GL_RED, GL_HALF_FLOAT_ARB, 0,
927 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
928 ARB_TEXTURE_FLOAT, NULL},
929 {WINED3DFMT_R16_FLOAT, GL_R16F, GL_R16F, 0,
930 GL_RED, GL_HALF_FLOAT_ARB, 0,
931 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
932 ARB_TEXTURE_RG, NULL},
933 {WINED3DFMT_R16G16_FLOAT, GL_RGB16F_ARB, GL_RGB16F_ARB, 0,
934 GL_RGB, GL_HALF_FLOAT_ARB, 6,
935 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
936 ARB_TEXTURE_FLOAT, convert_r16g16},
937 {WINED3DFMT_R16G16_FLOAT, GL_RG16F, GL_RG16F, 0,
938 GL_RG, GL_HALF_FLOAT_ARB, 0,
939 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
940 ARB_TEXTURE_RG, NULL},
941 {WINED3DFMT_R16G16B16A16_FLOAT, GL_RGBA16F_ARB, GL_RGBA16F_ARB, 0,
942 GL_RGBA, GL_HALF_FLOAT_ARB, 0,
943 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_RENDERTARGET
944 | WINED3DFMT_FLAG_VTF,
945 ARB_TEXTURE_FLOAT, NULL},
946 /* Palettized formats */
947 {WINED3DFMT_P8_UINT, GL_ALPHA8, GL_ALPHA8, 0,
948 GL_ALPHA, GL_UNSIGNED_BYTE, 0,
949 0,
950 0, NULL},
951 /* Standard ARGB formats */
952 {WINED3DFMT_B8G8R8_UNORM, GL_RGB8, GL_RGB8, 0,
953 GL_BGR, GL_UNSIGNED_BYTE, 0,
954 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET,
955 WINED3D_GL_EXT_NONE, NULL},
956 {WINED3DFMT_B8G8R8A8_UNORM, GL_RGBA8, GL_SRGB8_ALPHA8_EXT, 0,
957 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
958 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
959 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE
960 | WINED3DFMT_FLAG_VTF,
961 WINED3D_GL_EXT_NONE, NULL},
962 {WINED3DFMT_B8G8R8X8_UNORM, GL_RGB8, GL_SRGB8_EXT, 0,
963 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
964 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
965 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE,
966 WINED3D_GL_EXT_NONE, NULL},
967 {WINED3DFMT_B5G6R5_UNORM, GL_RGB5, GL_RGB5, GL_RGB8,
968 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0,
969 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
970 | WINED3DFMT_FLAG_RENDERTARGET,
971 WINED3D_GL_EXT_NONE, NULL},
972 {WINED3DFMT_B5G5R5X1_UNORM, GL_RGB5, GL_RGB5_A1, 0,
973 GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 0,
974 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
975 WINED3D_GL_EXT_NONE, NULL},
976 {WINED3DFMT_B5G5R5A1_UNORM, GL_RGB5_A1, GL_RGB5_A1, 0,
977 GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 0,
978 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
979 WINED3D_GL_EXT_NONE, NULL},
980 {WINED3DFMT_B4G4R4A4_UNORM, GL_RGBA4, GL_SRGB8_ALPHA8_EXT, 0,
981 GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, 0,
982 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
983 | WINED3DFMT_FLAG_SRGB_READ,
984 WINED3D_GL_EXT_NONE, NULL},
985 {WINED3DFMT_B2G3R3_UNORM, GL_R3_G3_B2, GL_R3_G3_B2, 0,
986 GL_RGB, GL_UNSIGNED_BYTE_3_3_2, 0,
987 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
988 WINED3D_GL_EXT_NONE, NULL},
989 {WINED3DFMT_R8_UNORM, GL_R8, GL_R8, 0,
990 GL_RED, GL_UNSIGNED_BYTE, 0,
991 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
992 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
993 ARB_TEXTURE_RG, NULL},
994 {WINED3DFMT_A8_UNORM, GL_ALPHA8, GL_ALPHA8, 0,
995 GL_ALPHA, GL_UNSIGNED_BYTE, 0,
996 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
997 WINED3D_GL_EXT_NONE, NULL},
998 {WINED3DFMT_B4G4R4X4_UNORM, GL_RGB4, GL_RGB4, 0,
999 GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, 0,
1000 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1001 WINED3D_GL_EXT_NONE, NULL},
1002 {WINED3DFMT_R10G10B10A2_UNORM, GL_RGB10_A2, GL_RGB10_A2, 0,
1003 GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, 0,
1004 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1005 | WINED3DFMT_FLAG_RENDERTARGET,
1006 WINED3D_GL_EXT_NONE, NULL},
1007 {WINED3DFMT_R8G8B8A8_UNORM, GL_RGBA8, GL_SRGB8_ALPHA8_EXT, 0,
1008 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1009 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1010 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE
1011 | WINED3DFMT_FLAG_VTF,
1012 WINED3D_GL_EXT_NONE, NULL},
1013 {WINED3DFMT_R8G8B8X8_UNORM, GL_RGB8, GL_RGB8, 0,
1014 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1015 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1016 WINED3D_GL_EXT_NONE, NULL},
1017 {WINED3DFMT_R16G16_UNORM, GL_RGB16, GL_RGB16, GL_RGBA16,
1018 GL_RGB, GL_UNSIGNED_SHORT, 6,
1019 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1020 WINED3D_GL_EXT_NONE, convert_r16g16},
1021 {WINED3DFMT_R16G16_UNORM, GL_RG16, GL_RG16, 0,
1022 GL_RG, GL_UNSIGNED_SHORT, 0,
1023 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1024 | WINED3DFMT_FLAG_RENDERTARGET,
1025 ARB_TEXTURE_RG, NULL},
1026 {WINED3DFMT_B10G10R10A2_UNORM, GL_RGB10_A2, GL_RGB10_A2, 0,
1027 GL_BGRA, GL_UNSIGNED_INT_2_10_10_10_REV, 0,
1028 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1029 | WINED3DFMT_FLAG_RENDERTARGET,
1030 WINED3D_GL_EXT_NONE, NULL},
1031 {WINED3DFMT_R16G16B16A16_UNORM, GL_RGBA16, GL_RGBA16, 0,
1032 GL_RGBA, GL_UNSIGNED_SHORT, 0,
1033 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1034 | WINED3DFMT_FLAG_RENDERTARGET,
1035 WINED3D_GL_EXT_NONE, NULL},
1036 /* Luminance */
1037 {WINED3DFMT_L8_UNORM, GL_LUMINANCE8, GL_SLUMINANCE8_EXT, 0,
1038 GL_LUMINANCE, GL_UNSIGNED_BYTE, 0,
1039 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1040 | WINED3DFMT_FLAG_SRGB_READ,
1041 WINED3D_GL_EXT_NONE, NULL},
1042 {WINED3DFMT_L8A8_UNORM, GL_LUMINANCE8_ALPHA8, GL_SLUMINANCE8_ALPHA8_EXT, 0,
1043 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1044 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1045 | WINED3DFMT_FLAG_SRGB_READ,
1046 WINED3D_GL_EXT_NONE, NULL},
1047 {WINED3DFMT_L4A4_UNORM, GL_LUMINANCE4_ALPHA4, GL_LUMINANCE4_ALPHA4, 0,
1048 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 2,
1049 WINED3DFMT_FLAG_FILTERING,
1050 WINED3D_GL_EXT_NONE, convert_l4a4_unorm},
1051 /* Bump mapping stuff */
1052 {WINED3DFMT_R8G8_SNORM, GL_RGB8, GL_RGB8, 0,
1053 GL_BGR, GL_UNSIGNED_BYTE, 3,
1054 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1055 | WINED3DFMT_FLAG_BUMPMAP,
1056 WINED3D_GL_EXT_NONE, convert_r8g8_snorm},
1057 {WINED3DFMT_R8G8_SNORM, GL_DSDT8_NV, GL_DSDT8_NV, 0,
1058 GL_DSDT_NV, GL_BYTE, 0,
1059 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1060 | WINED3DFMT_FLAG_BUMPMAP,
1061 NV_TEXTURE_SHADER, NULL},
1062 {WINED3DFMT_R5G5_SNORM_L6_UNORM, GL_RGB5, GL_RGB5, 0,
1063 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 2,
1064 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1065 | WINED3DFMT_FLAG_BUMPMAP,
1066 WINED3D_GL_EXT_NONE, convert_r5g5_snorm_l6_unorm},
1067 {WINED3DFMT_R5G5_SNORM_L6_UNORM, GL_DSDT8_MAG8_NV, GL_DSDT8_MAG8_NV, 0,
1068 GL_DSDT_MAG_NV, GL_BYTE, 3,
1069 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1070 | WINED3DFMT_FLAG_BUMPMAP,
1071 NV_TEXTURE_SHADER, convert_r5g5_snorm_l6_unorm_nv},
1072 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, GL_RGB8, GL_RGB8, 0,
1073 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 4,
1074 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1075 | WINED3DFMT_FLAG_BUMPMAP,
1076 WINED3D_GL_EXT_NONE, convert_r8g8_snorm_l8x8_unorm},
1077 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, GL_DSDT8_MAG8_INTENSITY8_NV, GL_DSDT8_MAG8_INTENSITY8_NV, 0,
1078 GL_DSDT_MAG_VIB_NV, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV, 4,
1079 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1080 | WINED3DFMT_FLAG_BUMPMAP,
1081 NV_TEXTURE_SHADER, convert_r8g8_snorm_l8x8_unorm_nv},
1082 {WINED3DFMT_R8G8B8A8_SNORM, GL_RGBA8, GL_RGBA8, 0,
1083 GL_BGRA, GL_UNSIGNED_BYTE, 4,
1084 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1085 | WINED3DFMT_FLAG_BUMPMAP,
1086 WINED3D_GL_EXT_NONE, convert_r8g8b8a8_snorm},
1087 {WINED3DFMT_R8G8B8A8_SNORM, GL_SIGNED_RGBA8_NV, GL_SIGNED_RGBA8_NV, 0,
1088 GL_RGBA, GL_BYTE, 0,
1089 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1090 | WINED3DFMT_FLAG_BUMPMAP,
1091 NV_TEXTURE_SHADER, NULL},
1092 {WINED3DFMT_R16G16_SNORM, GL_RGB16, GL_RGB16, 0,
1093 GL_BGR, GL_UNSIGNED_SHORT, 6,
1094 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1095 | WINED3DFMT_FLAG_BUMPMAP,
1096 WINED3D_GL_EXT_NONE, convert_r16g16_snorm},
1097 {WINED3DFMT_R16G16_SNORM, GL_SIGNED_HILO16_NV, GL_SIGNED_HILO16_NV, 0,
1098 GL_HILO_NV, GL_SHORT, 0,
1099 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1100 | WINED3DFMT_FLAG_BUMPMAP,
1101 NV_TEXTURE_SHADER, NULL},
1102 /* Depth stencil formats */
1103 {WINED3DFMT_D16_LOCKABLE, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, 0,
1104 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1105 WINED3DFMT_FLAG_DEPTH,
1106 WINED3D_GL_EXT_NONE, NULL},
1107 {WINED3DFMT_D16_LOCKABLE, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1108 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1109 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1110 ARB_DEPTH_TEXTURE, NULL},
1111 {WINED3DFMT_D32_UNORM, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, 0,
1112 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0,
1113 WINED3DFMT_FLAG_DEPTH,
1114 WINED3D_GL_EXT_NONE, NULL},
1115 {WINED3DFMT_D32_UNORM, GL_DEPTH_COMPONENT32_ARB, GL_DEPTH_COMPONENT32_ARB, 0,
1116 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0,
1117 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1118 ARB_DEPTH_TEXTURE, NULL},
1119 {WINED3DFMT_S1_UINT_D15_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1120 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1121 WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1122 ARB_DEPTH_TEXTURE, NULL},
1123 {WINED3DFMT_S1_UINT_D15_UNORM, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH24_STENCIL8_EXT, 0,
1124 GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, 4,
1125 WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1126 EXT_PACKED_DEPTH_STENCIL, convert_s1_uint_d15_unorm},
1127 {WINED3DFMT_S1_UINT_D15_UNORM, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, 0,
1128 GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 4,
1129 WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1130 ARB_FRAMEBUFFER_OBJECT, convert_s1_uint_d15_unorm},
1131 {WINED3DFMT_D24_UNORM_S8_UINT, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1132 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0,
1133 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1134 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1135 ARB_DEPTH_TEXTURE, NULL},
1136 {WINED3DFMT_D24_UNORM_S8_UINT, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH24_STENCIL8_EXT, 0,
1137 GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, 0,
1138 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1139 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1140 EXT_PACKED_DEPTH_STENCIL, NULL},
1141 {WINED3DFMT_D24_UNORM_S8_UINT, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, 0,
1142 GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0,
1143 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1144 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1145 ARB_FRAMEBUFFER_OBJECT, NULL},
1146 {WINED3DFMT_X8D24_UNORM, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, 0,
1147 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0,
1148 WINED3DFMT_FLAG_DEPTH,
1149 WINED3D_GL_EXT_NONE, NULL},
1150 {WINED3DFMT_X8D24_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1151 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0,
1152 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1153 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1154 ARB_DEPTH_TEXTURE, NULL},
1155 {WINED3DFMT_S4X4_UINT_D24_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1156 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0,
1157 WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1158 ARB_DEPTH_TEXTURE, NULL},
1159 {WINED3DFMT_S4X4_UINT_D24_UNORM, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH24_STENCIL8_EXT, 0,
1160 GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, 4,
1161 WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1162 EXT_PACKED_DEPTH_STENCIL, convert_s4x4_uint_d24_unorm},
1163 {WINED3DFMT_S4X4_UINT_D24_UNORM, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, 0,
1164 GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 4,
1165 WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1166 ARB_FRAMEBUFFER_OBJECT, convert_s4x4_uint_d24_unorm},
1167 {WINED3DFMT_D16_UNORM, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, 0,
1168 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1169 WINED3DFMT_FLAG_DEPTH,
1170 WINED3D_GL_EXT_NONE, NULL},
1171 {WINED3DFMT_D16_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1172 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1173 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1174 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1175 ARB_DEPTH_TEXTURE, NULL},
1176 {WINED3DFMT_L16_UNORM, GL_LUMINANCE16, GL_LUMINANCE16, 0,
1177 GL_LUMINANCE, GL_UNSIGNED_SHORT, 0,
1178 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1179 WINED3D_GL_EXT_NONE, NULL},
1180 {WINED3DFMT_D32_FLOAT, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT32F, 0,
1181 GL_DEPTH_COMPONENT, GL_FLOAT, 0,
1182 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1183 ARB_DEPTH_BUFFER_FLOAT, NULL},
1184 {WINED3DFMT_S8_UINT_D24_FLOAT, GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, 0,
1185 GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, 8,
1186 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1187 ARB_DEPTH_BUFFER_FLOAT, convert_s8_uint_d24_float},
1188 /* Vendor-specific formats */
1189 {WINED3DFMT_ATI1N, GL_COMPRESSED_RED_RGTC1, GL_COMPRESSED_RED_RGTC1, 0,
1190 GL_RED, GL_UNSIGNED_BYTE, 0,
1191 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1192 | WINED3DFMT_FLAG_COMPRESSED,
1193 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1194 {WINED3DFMT_ATI2N, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, 0,
1195 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1196 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1197 | WINED3DFMT_FLAG_COMPRESSED,
1198 ATI_TEXTURE_COMPRESSION_3DC, NULL},
1199 {WINED3DFMT_ATI2N, GL_COMPRESSED_RG_RGTC2, GL_COMPRESSED_RG_RGTC2, 0,
1200 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1201 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1202 | WINED3DFMT_FLAG_COMPRESSED,
1203 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1204 {WINED3DFMT_INTZ, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH24_STENCIL8_EXT, 0,
1205 GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, 0,
1206 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1207 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
1208 EXT_PACKED_DEPTH_STENCIL, NULL},
1209 {WINED3DFMT_INTZ, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, 0,
1210 GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0,
1211 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1212 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
1213 ARB_FRAMEBUFFER_OBJECT, NULL},
1214 {WINED3DFMT_NULL, 0, 0, 0,
1215 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1216 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1217 ARB_FRAMEBUFFER_OBJECT, NULL},
1218 };
1219
1220 static inline int getFmtIdx(enum wined3d_format_id format_id)
1221 {
1222 /* First check if the format is at the position of its value.
1223 * This will catch the argb formats before the loop is entered. */
1224 if (format_id < (sizeof(formats) / sizeof(*formats))
1225 && formats[format_id].id == format_id)
1226 {
1227 return format_id;
1228 }
1229 else
1230 {
1231 unsigned int i;
1232
1233 for (i = 0; i < (sizeof(formats) / sizeof(*formats)); ++i)
1234 {
1235 if (formats[i].id == format_id) return i;
1236 }
1237 }
1238 return -1;
1239 }
1240
1241 static BOOL init_format_base_info(struct wined3d_gl_info *gl_info)
1242 {
1243 UINT format_count = sizeof(formats) / sizeof(*formats);
1244 UINT i;
1245
1246 gl_info->formats = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, format_count * sizeof(*gl_info->formats));
1247 if (!gl_info->formats)
1248 {
1249 ERR("Failed to allocate memory.\n");
1250 return FALSE;
1251 }
1252
1253 for (i = 0; i < format_count; ++i)
1254 {
1255 struct wined3d_format *format = &gl_info->formats[i];
1256 format->id = formats[i].id;
1257 format->red_size = formats[i].red_size;
1258 format->green_size = formats[i].green_size;
1259 format->blue_size = formats[i].blue_size;
1260 format->alpha_size = formats[i].alpha_size;
1261 format->red_offset = formats[i].red_offset;
1262 format->green_offset = formats[i].green_offset;
1263 format->blue_offset = formats[i].blue_offset;
1264 format->alpha_offset = formats[i].alpha_offset;
1265 format->byte_count = formats[i].bpp;
1266 format->depth_size = formats[i].depth_size;
1267 format->stencil_size = formats[i].stencil_size;
1268 format->block_width = 1;
1269 format->block_height = 1;
1270 format->block_byte_count = formats[i].bpp;
1271 }
1272
1273 for (i = 0; i < (sizeof(format_base_flags) / sizeof(*format_base_flags)); ++i)
1274 {
1275 int fmt_idx = getFmtIdx(format_base_flags[i].id);
1276
1277 if (fmt_idx == -1)
1278 {
1279 ERR("Format %s (%#x) not found.\n",
1280 debug_d3dformat(format_base_flags[i].id), format_base_flags[i].id);
1281 HeapFree(GetProcessHeap(), 0, gl_info->formats);
1282 return FALSE;
1283 }
1284
1285 gl_info->formats[fmt_idx].flags |= format_base_flags[i].flags;
1286 }
1287
1288 return TRUE;
1289 }
1290
1291 static BOOL init_format_block_info(struct wined3d_gl_info *gl_info)
1292 {
1293 unsigned int i;
1294
1295 for (i = 0; i < (sizeof(format_block_info) / sizeof(*format_block_info)); ++i)
1296 {
1297 struct wined3d_format *format;
1298 int fmt_idx = getFmtIdx(format_block_info[i].id);
1299
1300 if (fmt_idx == -1)
1301 {
1302 ERR("Format %s (%#x) not found.\n",
1303 debug_d3dformat(format_block_info[i].id), format_block_info[i].id);
1304 return FALSE;
1305 }
1306
1307 format = &gl_info->formats[fmt_idx];
1308 format->block_width = format_block_info[i].block_width;
1309 format->block_height = format_block_info[i].block_height;
1310 format->block_byte_count = format_block_info[i].block_byte_count;
1311 format->flags |= WINED3DFMT_FLAG_BLOCKS;
1312 if (!format_block_info[i].verify)
1313 format->flags |= WINED3DFMT_FLAG_BLOCKS_NO_VERIFY;
1314 }
1315
1316 return TRUE;
1317 }
1318
1319 /* Context activation is done by the caller. */
1320 static void check_fbo_compat(const struct wined3d_gl_info *gl_info, struct wined3d_format *format)
1321 {
1322 /* Check if the default internal format is supported as a frame buffer
1323 * target, otherwise fall back to the render target internal.
1324 *
1325 * Try to stick to the standard format if possible, this limits precision differences. */
1326 GLenum status;
1327 GLuint tex;
1328
1329 while (gl_info->gl_ops.gl.p_glGetError());
1330 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
1331
1332 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
1333 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
1334
1335 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, format->glInternal, 16, 16, 0,
1336 format->glFormat, format->glType, NULL);
1337 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1338 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1339
1340 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
1341
1342 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
1343 checkGLcall("Framebuffer format check");
1344
1345 if (status == GL_FRAMEBUFFER_COMPLETE)
1346 {
1347 TRACE("Format %s is supported as FBO color attachment.\n", debug_d3dformat(format->id));
1348 format->flags |= WINED3DFMT_FLAG_FBO_ATTACHABLE;
1349 format->rtInternal = format->glInternal;
1350 }
1351 else
1352 {
1353 if (!format->rtInternal)
1354 {
1355 if (format->flags & WINED3DFMT_FLAG_RENDERTARGET)
1356 {
1357 FIXME("Format %s with rendertarget flag is not supported as FBO color attachment,"
1358 " and no fallback specified.\n", debug_d3dformat(format->id));
1359 format->flags &= ~WINED3DFMT_FLAG_RENDERTARGET;
1360 }
1361 else
1362 {
1363 TRACE("Format %s is not supported as FBO color attachment.\n", debug_d3dformat(format->id));
1364 }
1365 format->rtInternal = format->glInternal;
1366 }
1367 else
1368 {
1369 TRACE("Format %s is not supported as FBO color attachment, trying rtInternal format as fallback.\n",
1370 debug_d3dformat(format->id));
1371
1372 while (gl_info->gl_ops.gl.p_glGetError());
1373
1374 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
1375
1376 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, format->rtInternal, 16, 16, 0,
1377 format->glFormat, format->glType, NULL);
1378 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1379 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1380
1381 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
1382
1383 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
1384 checkGLcall("Framebuffer format check");
1385
1386 if (status == GL_FRAMEBUFFER_COMPLETE)
1387 {
1388 TRACE("Format %s rtInternal format is supported as FBO color attachment.\n",
1389 debug_d3dformat(format->id));
1390 }
1391 else
1392 {
1393 FIXME("Format %s rtInternal format is not supported as FBO color attachment.\n",
1394 debug_d3dformat(format->id));
1395 format->flags &= ~WINED3DFMT_FLAG_RENDERTARGET;
1396 }
1397 }
1398 }
1399
1400 if (status == GL_FRAMEBUFFER_COMPLETE && ((format->flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)
1401 || !(gl_info->quirks & WINED3D_QUIRK_LIMITED_TEX_FILTERING))
1402 && format->id != WINED3DFMT_NULL && format->id != WINED3DFMT_P8_UINT
1403 && format->glFormat != GL_LUMINANCE && format->glFormat != GL_LUMINANCE_ALPHA
1404 && (format->red_size || format->alpha_size))
1405 {
1406 DWORD readback[16 * 16], color, r_range, a_range;
1407 BYTE r, a;
1408 BOOL match = TRUE;
1409 GLuint rb;
1410
1411 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
1412 || gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
1413 {
1414 gl_info->fbo_ops.glGenRenderbuffers(1, &rb);
1415 gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, rb);
1416 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 16, 16);
1417 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb);
1418 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb);
1419 checkGLcall("RB attachment");
1420 }
1421
1422 gl_info->gl_ops.gl.p_glEnable(GL_BLEND);
1423 gl_info->gl_ops.gl.p_glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
1424 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
1425 if (gl_info->gl_ops.gl.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION)
1426 {
1427 while (gl_info->gl_ops.gl.p_glGetError());
1428 TRACE("Format doesn't support post-pixelshader blending.\n");
1429 format->flags &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
1430 }
1431 else
1432 {
1433 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
1434 gl_info->gl_ops.gl.p_glViewport(0, 0, 16, 16);
1435 gl_info->gl_ops.gl.p_glDisable(GL_LIGHTING);
1436 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
1437 gl_info->gl_ops.gl.p_glLoadIdentity();
1438 gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
1439 gl_info->gl_ops.gl.p_glLoadIdentity();
1440
1441 gl_info->gl_ops.gl.p_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1442
1443 /* Draw a full-black quad */
1444 gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
1445 gl_info->gl_ops.gl.p_glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
1446 gl_info->gl_ops.gl.p_glVertex3f(-1.0f, -1.0f, 0.0f);
1447 gl_info->gl_ops.gl.p_glVertex3f(1.0f, -1.0f, 0.0f);
1448 gl_info->gl_ops.gl.p_glVertex3f(-1.0f, 1.0f, 0.0f);
1449 gl_info->gl_ops.gl.p_glVertex3f(1.0f, 1.0f, 0.0f);
1450 gl_info->gl_ops.gl.p_glEnd();
1451
1452 gl_info->gl_ops.gl.p_glEnable(GL_BLEND);
1453 /* Draw a half-transparent red quad */
1454 gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
1455 gl_info->gl_ops.gl.p_glColor4f(1.0f, 0.0f, 0.0f, 0.5f);
1456 gl_info->gl_ops.gl.p_glVertex3f(-1.0f, -1.0f, 0.0f);
1457 gl_info->gl_ops.gl.p_glVertex3f(1.0f, -1.0f, 0.0f);
1458 gl_info->gl_ops.gl.p_glVertex3f(-1.0f, 1.0f, 0.0f);
1459 gl_info->gl_ops.gl.p_glVertex3f(1.0f, 1.0f, 0.0f);
1460 gl_info->gl_ops.gl.p_glEnd();
1461
1462 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
1463
1464 /* Rebinding texture to workaround a fglrx bug. */
1465 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
1466 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, readback);
1467 checkGLcall("Post-pixelshader blending check");
1468
1469 color = readback[7 * 16 + 7];
1470 a = color >> 24;
1471 r = (color & 0x00ff0000) >> 16;
1472
1473 r_range = format->red_size < 8 ? 1 << (8 - format->red_size) : 1;
1474 a_range = format->alpha_size < 8 ? 1 << (8 - format->alpha_size) : 1;
1475 if (format->red_size && (r < 0x7f - r_range || r > 0x7f + r_range))
1476 match = FALSE;
1477 else if (format->alpha_size > 1 && (a < 0xbf - a_range || a > 0xbf + a_range))
1478 match = FALSE;
1479 if (!match)
1480 {
1481 TRACE("Format doesn't support post-pixelshader blending.\n");
1482 TRACE("Color output: %#x\n", color);
1483 format->flags &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
1484 }
1485 else
1486 {
1487 TRACE("Format supports post-pixelshader blending.\n");
1488 TRACE("Color output: %#x\n", color);
1489 format->flags |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
1490 }
1491 }
1492
1493 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
1494 || gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
1495 {
1496 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
1497 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
1498 gl_info->fbo_ops.glDeleteRenderbuffers(1, &rb);
1499 checkGLcall("RB cleanup");
1500 }
1501 }
1502
1503 if (format->glInternal != format->glGammaInternal)
1504 {
1505 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, format->glGammaInternal, 16, 16, 0,
1506 format->glFormat, format->glType, NULL);
1507 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
1508
1509 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
1510 checkGLcall("Framebuffer format check");
1511
1512 if (status == GL_FRAMEBUFFER_COMPLETE)
1513 {
1514 TRACE("Format %s's sRGB format is FBO attachable.\n", debug_d3dformat(format->id));
1515 format->flags |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
1516 }
1517 else
1518 {
1519 WARN("Format %s's sRGB format is not FBO attachable.\n", debug_d3dformat(format->id));
1520 }
1521 }
1522 else if (status == GL_FRAMEBUFFER_COMPLETE)
1523 format->flags |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
1524
1525 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
1526 }
1527
1528 static void query_format_flag(struct wined3d_gl_info *gl_info, struct wined3d_format *format,
1529 GLint internal, GLenum pname, DWORD flag, const char *string)
1530 {
1531 GLint value;
1532
1533 gl_info->gl_ops.ext.p_glGetInternalformativ(GL_TEXTURE_2D, internal, pname, 1, &value);
1534 if (value == GL_FULL_SUPPORT)
1535 {
1536 TRACE("Format %s supports %s.\n", debug_d3dformat(format->id), string);
1537 format->flags |= flag;
1538 }
1539 else
1540 {
1541 TRACE("Format %s doesn't support %s.\n", debug_d3dformat(format->id), string);
1542 format->flags &= ~flag;
1543 }
1544 }
1545
1546 /* Context activation is done by the caller. */
1547 static void init_format_fbo_compat_info(struct wined3d_gl_info *gl_info)
1548 {
1549 unsigned int i;
1550 GLuint fbo;
1551
1552 if (gl_info->supported[ARB_INTERNALFORMAT_QUERY2])
1553 {
1554 for (i = 0; i < sizeof(formats) / sizeof(*formats); ++i)
1555 {
1556 GLint value;
1557 struct wined3d_format *format = &gl_info->formats[i];
1558
1559 if (!format->glInternal)
1560 continue;
1561 if (format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
1562 continue;
1563
1564 gl_info->gl_ops.ext.p_glGetInternalformativ(GL_TEXTURE_2D, format->glInternal,
1565 GL_FRAMEBUFFER_RENDERABLE, 1, &value);
1566 if (value == GL_FULL_SUPPORT)
1567 {
1568 TRACE("Format %s is supported as FBO color attachment.\n", debug_d3dformat(format->id));
1569 format->flags |= WINED3DFMT_FLAG_FBO_ATTACHABLE;
1570 format->rtInternal = format->glInternal;
1571
1572 query_format_flag(gl_info, format, format->glInternal, GL_FRAMEBUFFER_BLEND,
1573 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING, "post-pixelshader blending");
1574 }
1575 else
1576 {
1577 if (!format->rtInternal)
1578 {
1579 if (format->flags & WINED3DFMT_FLAG_RENDERTARGET)
1580 {
1581 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
1582 " and no fallback specified.\n", debug_d3dformat(format->id));
1583 format->flags &= ~WINED3DFMT_FLAG_RENDERTARGET;
1584 }
1585 else
1586 TRACE("Format %s is not supported as FBO color attachment.\n", debug_d3dformat(format->id));
1587 format->rtInternal = format->glInternal;
1588 }
1589 else
1590 {
1591 gl_info->gl_ops.ext.p_glGetInternalformativ(GL_TEXTURE_2D, format->rtInternal,
1592 GL_FRAMEBUFFER_RENDERABLE, 1, &value);
1593 if (value == GL_FULL_SUPPORT)
1594 {
1595 TRACE("Format %s rtInternal format is supported as FBO color attachment.\n",
1596 debug_d3dformat(format->id));
1597 }
1598 else
1599 {
1600 WARN("Format %s rtInternal format is not supported as FBO color attachment.\n",
1601 debug_d3dformat(format->id));
1602 format->flags &= ~WINED3DFMT_FLAG_RENDERTARGET;
1603 }
1604 }
1605 }
1606
1607 if (format->glInternal != format->glGammaInternal)
1608 {
1609 gl_info->gl_ops.ext.p_glGetInternalformativ(GL_TEXTURE_2D, format->glGammaInternal,
1610 GL_FRAMEBUFFER_RENDERABLE, 1, &value);
1611 if (value == GL_FULL_SUPPORT)
1612 {
1613 TRACE("Format %s's sRGB format is FBO attachable.\n", debug_d3dformat(format->id));
1614 format->flags |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
1615 }
1616 else
1617 {
1618 WARN("Format %s's sRGB format is not FBO attachable.\n", debug_d3dformat(format->id));
1619 }
1620 }
1621 else if (format->flags & WINED3DFMT_FLAG_FBO_ATTACHABLE)
1622 format->flags |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
1623 }
1624 return;
1625 }
1626
1627 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
1628 {
1629 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
1630 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1631 gl_info->gl_ops.gl.p_glDrawBuffer(GL_COLOR_ATTACHMENT0);
1632 gl_info->gl_ops.gl.p_glReadBuffer(GL_COLOR_ATTACHMENT0);
1633 }
1634
1635 for (i = 0; i < sizeof(formats) / sizeof(*formats); ++i)
1636 {
1637 struct wined3d_format *format = &gl_info->formats[i];
1638
1639 if (!format->glInternal) continue;
1640
1641 if (format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
1642 {
1643 TRACE("Skipping format %s because it's a depth/stencil format.\n",
1644 debug_d3dformat(format->id));
1645 continue;
1646 }
1647
1648 if (format->flags & WINED3DFMT_FLAG_COMPRESSED)
1649 {
1650 TRACE("Skipping format %s because it's a compressed format.\n",
1651 debug_d3dformat(format->id));
1652 continue;
1653 }
1654
1655 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
1656 {
1657 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format->id));
1658 check_fbo_compat(gl_info, format);
1659 }
1660 else
1661 {
1662 format->rtInternal = format->glInternal;
1663 }
1664 }
1665
1666 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
1667 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
1668 }
1669
1670 static BOOL init_format_texture_info(struct wined3d_adapter *adapter, struct wined3d_gl_info *gl_info)
1671 {
1672 struct fragment_caps fragment_caps;
1673 struct shader_caps shader_caps;
1674 BOOL srgb_write;
1675 unsigned int i;
1676
1677 adapter->fragment_pipe->get_caps(gl_info, &fragment_caps);
1678 adapter->shader_backend->shader_get_caps(gl_info, &shader_caps);
1679 srgb_write = (fragment_caps.wined3d_caps & WINED3D_FRAGMENT_CAP_SRGB_WRITE)
1680 && (shader_caps.wined3d_caps & WINED3D_SHADER_CAP_SRGB_WRITE);
1681
1682 for (i = 0; i < sizeof(format_texture_info) / sizeof(*format_texture_info); ++i)
1683 {
1684 int fmt_idx = getFmtIdx(format_texture_info[i].id);
1685 struct wined3d_format *format;
1686
1687 if (fmt_idx == -1)
1688 {
1689 ERR("Format %s (%#x) not found.\n",
1690 debug_d3dformat(format_texture_info[i].id), format_texture_info[i].id);
1691 return FALSE;
1692 }
1693
1694 if (!gl_info->supported[format_texture_info[i].extension]) continue;
1695
1696 format = &gl_info->formats[fmt_idx];
1697
1698 /* ARB_texture_rg defines floating point formats, but only if
1699 * ARB_texture_float is also supported. */
1700 if (!gl_info->supported[ARB_TEXTURE_FLOAT]
1701 && (format->flags & WINED3DFMT_FLAG_FLOAT))
1702 continue;
1703
1704 format->glInternal = format_texture_info[i].gl_internal;
1705 format->glGammaInternal = format_texture_info[i].gl_srgb_internal;
1706 format->rtInternal = format_texture_info[i].gl_rt_internal;
1707 format->glFormat = format_texture_info[i].gl_format;
1708 format->glType = format_texture_info[i].gl_type;
1709 format->color_fixup = COLOR_FIXUP_IDENTITY;
1710 format->flags |= format_texture_info[i].flags;
1711 format->height_scale.numerator = 1;
1712 format->height_scale.denominator = 1;
1713
1714 if (gl_info->supported[ARB_INTERNALFORMAT_QUERY2])
1715 {
1716 query_format_flag(gl_info, format, format->glInternal, GL_VERTEX_TEXTURE,
1717 WINED3DFMT_FLAG_VTF, "vertex texture usage");
1718 query_format_flag(gl_info, format, format->glInternal, GL_FILTER,
1719 WINED3DFMT_FLAG_FILTERING, "filtering");
1720
1721 if (format->glGammaInternal != format->glInternal)
1722 {
1723 query_format_flag(gl_info, format, format->glGammaInternal, GL_SRGB_READ,
1724 WINED3DFMT_FLAG_SRGB_READ, "sRGB read");
1725
1726 if (srgb_write)
1727 query_format_flag(gl_info, format, format->glGammaInternal, GL_SRGB_WRITE,
1728 WINED3DFMT_FLAG_SRGB_WRITE, "sRGB write");
1729 else
1730 format->flags &= ~WINED3DFMT_FLAG_SRGB_WRITE;
1731
1732 if (!(format->flags & (WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE)))
1733 format->glGammaInternal = format->glInternal;
1734 else if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
1735 format->glInternal = format->glGammaInternal;
1736 }
1737 }
1738 else
1739 {
1740 if (!gl_info->limits.vertex_samplers)
1741 format->flags &= ~WINED3DFMT_FLAG_VTF;
1742
1743 if (!(gl_info->quirks & WINED3D_QUIRK_LIMITED_TEX_FILTERING))
1744 format->flags |= WINED3DFMT_FLAG_FILTERING;
1745 else if (format->id != WINED3DFMT_R32G32B32A32_FLOAT && format->id != WINED3DFMT_R32_FLOAT)
1746 format->flags &= ~WINED3DFMT_FLAG_VTF;
1747
1748 if (format->glGammaInternal != format->glInternal)
1749 {
1750 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
1751 if (!gl_info->supported[EXT_TEXTURE_SRGB])
1752 {
1753 format->glGammaInternal = format->glInternal;
1754 format->flags &= ~(WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE);
1755 }
1756 else if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
1757 {
1758 format->glInternal = format->glGammaInternal;
1759 }
1760 }
1761
1762 if ((format->flags & WINED3DFMT_FLAG_SRGB_WRITE) && !srgb_write)
1763 format->flags &= ~WINED3DFMT_FLAG_SRGB_WRITE;
1764 }
1765
1766 /* Texture conversion stuff */
1767 format->convert = format_texture_info[i].convert;
1768 format->conv_byte_count = format_texture_info[i].conv_byte_count;
1769 }
1770
1771 return TRUE;
1772 }
1773
1774 static BOOL color_match(DWORD c1, DWORD c2, BYTE max_diff)
1775 {
1776 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
1777 c1 >>= 8; c2 >>= 8;
1778 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
1779 c1 >>= 8; c2 >>= 8;
1780 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
1781 c1 >>= 8; c2 >>= 8;
1782 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
1783 return TRUE;
1784 }
1785
1786 /* A context is provided by the caller */
1787 static BOOL check_filter(const struct wined3d_gl_info *gl_info, GLenum internal)
1788 {
1789 static const DWORD data[] = {0x00000000, 0xffffffff};
1790 GLuint tex, fbo, buffer;
1791 DWORD readback[16 * 1];
1792 BOOL ret = FALSE;
1793
1794 /* Render a filtered texture and see what happens. This is intended to detect the lack of
1795 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
1796 * falling back to software. If this changes in the future this code will get fooled and
1797 * apps might hit the software path due to incorrectly advertised caps.
1798 *
1799 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
1800 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
1801 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
1802 */
1803
1804 while (gl_info->gl_ops.gl.p_glGetError());
1805
1806 gl_info->gl_ops.gl.p_glGenTextures(1, &buffer);
1807 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, buffer);
1808 memset(readback, 0x7e, sizeof(readback));
1809 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 16, 1, 0,
1810 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, readback);
1811 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1812 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1813 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1814 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1815 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
1816
1817 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
1818 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
1819 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, internal, 2, 1, 0,
1820 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
1821 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1822 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1823 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1824 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1825 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
1826 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_2D);
1827
1828 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
1829 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
1830 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, buffer, 0);
1831 gl_info->gl_ops.gl.p_glDrawBuffer(GL_COLOR_ATTACHMENT0);
1832
1833 gl_info->gl_ops.gl.p_glViewport(0, 0, 16, 1);
1834 gl_info->gl_ops.gl.p_glDisable(GL_LIGHTING);
1835 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
1836 gl_info->gl_ops.gl.p_glLoadIdentity();
1837 gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
1838 gl_info->gl_ops.gl.p_glLoadIdentity();
1839
1840 gl_info->gl_ops.gl.p_glClearColor(0, 1, 0, 0);
1841 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
1842
1843 gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
1844 gl_info->gl_ops.gl.p_glTexCoord2f(0.0, 0.0);
1845 gl_info->gl_ops.gl.p_glVertex2f(-1.0f, -1.0f);
1846 gl_info->gl_ops.gl.p_glTexCoord2f(1.0, 0.0);
1847 gl_info->gl_ops.gl.p_glVertex2f(1.0f, -1.0f);
1848 gl_info->gl_ops.gl.p_glTexCoord2f(0.0, 1.0);
1849 gl_info->gl_ops.gl.p_glVertex2f(-1.0f, 1.0f);
1850 gl_info->gl_ops.gl.p_glTexCoord2f(1.0, 1.0);
1851 gl_info->gl_ops.gl.p_glVertex2f(1.0f, 1.0f);
1852 gl_info->gl_ops.gl.p_glEnd();
1853
1854 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, buffer);
1855 memset(readback, 0x7f, sizeof(readback));
1856 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, readback);
1857 if (color_match(readback[6], 0xffffffff, 5) || color_match(readback[6], 0x00000000, 5)
1858 || color_match(readback[9], 0xffffffff, 5) || color_match(readback[9], 0x00000000, 5))
1859 {
1860 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
1861 readback[6], readback[9]);
1862 ret = FALSE;
1863 }
1864 else
1865 {
1866 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
1867 readback[6], readback[9]);
1868 ret = TRUE;
1869 }
1870
1871 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
1872 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
1873 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
1874 gl_info->gl_ops.gl.p_glDeleteTextures(1, &buffer);
1875
1876 if (gl_info->gl_ops.gl.p_glGetError())
1877 {
1878 FIXME("Error during filtering test for format %x, returning no filtering\n", internal);
1879 ret = FALSE;
1880 }
1881
1882 return ret;
1883 }
1884
1885 static void init_format_filter_info(struct wined3d_gl_info *gl_info, enum wined3d_pci_vendor vendor)
1886 {
1887 struct wined3d_format *format;
1888 unsigned int fmt_idx, i;
1889 static const enum wined3d_format_id fmts16[] =
1890 {
1891 WINED3DFMT_R16_FLOAT,
1892 WINED3DFMT_R16G16_FLOAT,
1893 WINED3DFMT_R16G16B16A16_FLOAT,
1894 };
1895 BOOL filtered;
1896
1897 if (gl_info->supported[ARB_INTERNALFORMAT_QUERY2])
1898 /* This was already handled by init_format_texture_info(). */
1899 return;
1900
1901 if(wined3d_settings.offscreen_rendering_mode != ORM_FBO)
1902 {
1903 WARN("No FBO support, or no FBO ORM, guessing filter info from GL caps\n");
1904 if (vendor == HW_VENDOR_NVIDIA && gl_info->supported[ARB_TEXTURE_FLOAT])
1905 {
1906 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
1907 filtered = TRUE;
1908 }
1909 else if (gl_info->limits.glsl_varyings > 44)
1910 {
1911 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
1912 filtered = TRUE;
1913 }
1914 else
1915 {
1916 TRACE("Assuming no float16 blending\n");
1917 filtered = FALSE;
1918 }
1919
1920 if(filtered)
1921 {
1922 for(i = 0; i < (sizeof(fmts16) / sizeof(*fmts16)); i++)
1923 {
1924 fmt_idx = getFmtIdx(fmts16[i]);
1925 gl_info->formats[fmt_idx].flags |= WINED3DFMT_FLAG_FILTERING;
1926 }
1927 }
1928 return;
1929 }
1930
1931 for(i = 0; i < (sizeof(fmts16) / sizeof(*fmts16)); i++)
1932 {
1933 fmt_idx = getFmtIdx(fmts16[i]);
1934 format = &gl_info->formats[fmt_idx];
1935 if (!format->glInternal) continue; /* Not supported by GL */
1936
1937 filtered = check_filter(gl_info, gl_info->formats[fmt_idx].glInternal);
1938 if(filtered)
1939 {
1940 TRACE("Format %s supports filtering\n", debug_d3dformat(fmts16[i]));
1941 format->flags |= WINED3DFMT_FLAG_FILTERING;
1942 }
1943 else
1944 {
1945 TRACE("Format %s does not support filtering\n", debug_d3dformat(fmts16[i]));
1946 }
1947 }
1948 }
1949
1950 static void apply_format_fixups(struct wined3d_adapter *adapter, struct wined3d_gl_info *gl_info)
1951 {
1952 unsigned int i;
1953 int idx;
1954
1955 idx = getFmtIdx(WINED3DFMT_R16_FLOAT);
1956 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
1957 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
1958
1959 idx = getFmtIdx(WINED3DFMT_R32_FLOAT);
1960 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
1961 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
1962
1963 idx = getFmtIdx(WINED3DFMT_R16G16_UNORM);
1964 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
1965 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
1966
1967 idx = getFmtIdx(WINED3DFMT_R16G16_FLOAT);
1968 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
1969 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
1970
1971 idx = getFmtIdx(WINED3DFMT_R32G32_FLOAT);
1972 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
1973 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
1974
1975 /* V8U8 is supported natively by GL_ATI_envmap_bumpmap and GL_NV_texture_shader.
1976 * V16U16 is only supported by GL_NV_texture_shader. The formats need fixup if
1977 * their extensions are not available. GL_ATI_envmap_bumpmap is not used because
1978 * the only driver that implements it(fglrx) has a buggy implementation.
1979 *
1980 * V8U8 and V16U16 need a fixup of the undefined blue channel. OpenGL
1981 * returns 0.0 when sampling from it, DirectX 1.0. So we always have in-shader
1982 * conversion for this format.
1983 */
1984 if (!gl_info->supported[NV_TEXTURE_SHADER])
1985 {
1986 idx = getFmtIdx(WINED3DFMT_R8G8_SNORM);
1987 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
1988 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
1989 idx = getFmtIdx(WINED3DFMT_R16G16_SNORM);
1990 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
1991 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
1992 }
1993 else
1994 {
1995 idx = getFmtIdx(WINED3DFMT_R8G8_SNORM);
1996 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
1997 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
1998
1999 idx = getFmtIdx(WINED3DFMT_R16G16_SNORM);
2000 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
2001 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
2002 }
2003
2004 if (!gl_info->supported[NV_TEXTURE_SHADER])
2005 {
2006 /* If GL_NV_texture_shader is not supported, those formats are converted, incompatibly
2007 * with each other
2008 */
2009 idx = getFmtIdx(WINED3DFMT_R5G5_SNORM_L6_UNORM);
2010 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
2011 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE);
2012 idx = getFmtIdx(WINED3DFMT_R8G8_SNORM_L8X8_UNORM);
2013 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
2014 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_W);
2015 idx = getFmtIdx(WINED3DFMT_R8G8B8A8_SNORM);
2016 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
2017 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 1, CHANNEL_SOURCE_Z, 1, CHANNEL_SOURCE_W);
2018 }
2019 else
2020 {
2021 /* If GL_NV_texture_shader is supported, WINED3DFMT_L6V5U5 and WINED3DFMT_X8L8V8U8
2022 * are converted at surface loading time, but they do not need any modification in
2023 * the shader, thus they are compatible with all WINED3DFMT_UNKNOWN group formats.
2024 * WINED3DFMT_Q8W8V8U8 doesn't even need load-time conversion
2025 */
2026 }
2027
2028 if (gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC])
2029 {
2030 idx = getFmtIdx(WINED3DFMT_ATI1N);
2031 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
2032 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X);
2033
2034 idx = getFmtIdx(WINED3DFMT_ATI2N);
2035 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
2036 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
2037 }
2038 else if (gl_info->supported[ATI_TEXTURE_COMPRESSION_3DC])
2039 {
2040 idx = getFmtIdx(WINED3DFMT_ATI2N);
2041 gl_info->formats[idx].color_fixup= create_color_fixup_desc(
2042 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_W, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
2043 }
2044
2045 if (!gl_info->supported[APPLE_YCBCR_422])
2046 {
2047 idx = getFmtIdx(WINED3DFMT_YUY2);
2048 gl_info->formats[idx].color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_YUY2);
2049
2050 idx = getFmtIdx(WINED3DFMT_UYVY);
2051 gl_info->formats[idx].color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_UYVY);
2052 }
2053
2054 idx = getFmtIdx(WINED3DFMT_YV12);
2055 gl_info->formats[idx].flags |= WINED3DFMT_FLAG_HEIGHT_SCALE;
2056 gl_info->formats[idx].height_scale.numerator = 3;
2057 gl_info->formats[idx].height_scale.denominator = 2;
2058 gl_info->formats[idx].color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_YV12);
2059
2060 idx = getFmtIdx(WINED3DFMT_NV12);
2061 gl_info->formats[idx].flags |= WINED3DFMT_FLAG_HEIGHT_SCALE;
2062 gl_info->formats[idx].height_scale.numerator = 3;
2063 gl_info->formats[idx].height_scale.denominator = 2;
2064 gl_info->formats[idx].color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_NV12);
2065
2066 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
2067 {
2068 idx = getFmtIdx(WINED3DFMT_P8_UINT);
2069 gl_info->formats[idx].color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_P8);
2070 }
2071
2072 if (gl_info->supported[ARB_VERTEX_ARRAY_BGRA])
2073 {
2074 idx = getFmtIdx(WINED3DFMT_B8G8R8A8_UNORM);
2075 gl_info->formats[idx].gl_vtx_format = GL_BGRA;
2076 }
2077
2078 if (gl_info->supported[ARB_HALF_FLOAT_VERTEX])
2079 {
2080 /* Do not change the size of the type, it is CPU side. We have to change the GPU-side information though.
2081 * It is the job of the vertex buffer code to make sure that the vbos have the right format */
2082 idx = getFmtIdx(WINED3DFMT_R16G16_FLOAT);
2083 gl_info->formats[idx].gl_vtx_type = GL_HALF_FLOAT; /* == GL_HALF_FLOAT_NV */
2084
2085 idx = getFmtIdx(WINED3DFMT_R16G16B16A16_FLOAT);
2086 gl_info->formats[idx].gl_vtx_type = GL_HALF_FLOAT;
2087 }
2088
2089 if (!gl_info->supported[ARB_HALF_FLOAT_PIXEL])
2090 {
2091 idx = getFmtIdx(WINED3DFMT_R16_FLOAT);
2092 gl_info->formats[idx].flags &= ~WINED3DFMT_FLAG_TEXTURE;
2093
2094 idx = getFmtIdx(WINED3DFMT_R16G16_FLOAT);
2095 gl_info->formats[idx].flags &= ~WINED3DFMT_FLAG_TEXTURE;
2096
2097 idx = getFmtIdx(WINED3DFMT_R16G16B16A16_FLOAT);
2098 gl_info->formats[idx].flags &= ~WINED3DFMT_FLAG_TEXTURE;
2099 }
2100
2101 if (gl_info->quirks & WINED3D_QUIRK_BROKEN_RGBA16)
2102 {
2103 idx = getFmtIdx(WINED3DFMT_R16G16B16A16_UNORM);
2104 gl_info->formats[idx].flags &= ~WINED3DFMT_FLAG_TEXTURE;
2105 }
2106
2107 /* ATI instancing hack: Although ATI cards do not support Shader Model
2108 * 3.0, they support instancing. To query if the card supports instancing
2109 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
2110 * is used. Should an application check for this, provide a proper return
2111 * value. We can do instancing with all shader versions, but we need
2112 * vertex shaders.
2113 *
2114 * Additionally applications have to set the D3DRS_POINTSIZE render state
2115 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
2116 * doesn't need that and just ignores it.
2117 *
2118 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
2119 /* FIXME: This should just check the shader backend caps. */
2120 if (gl_info->supported[ARB_VERTEX_PROGRAM] || gl_info->supported[ARB_VERTEX_SHADER])
2121 {
2122 idx = getFmtIdx(WINED3DFMT_INST);
2123 gl_info->formats[idx].flags |= WINED3DFMT_FLAG_TEXTURE;
2124 }
2125
2126 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
2127 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
2128 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
2129 * MAKEFOURCC('N','V','D','B') and then controlled by setting
2130 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
2131 * value. */
2132 if (gl_info->supported[EXT_DEPTH_BOUNDS_TEST])
2133 {
2134 idx = getFmtIdx(WINED3DFMT_NVDB);
2135 gl_info->formats[idx].flags |= WINED3DFMT_FLAG_TEXTURE;
2136 }
2137
2138 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
2139 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
2140 * RENDERTARGET usage. */
2141 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
2142 {
2143 idx = getFmtIdx(WINED3DFMT_RESZ);
2144 gl_info->formats[idx].flags |= WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET;
2145 }
2146
2147 for (i = 0; i < sizeof(formats) / sizeof(*formats); ++i)
2148 {
2149 struct wined3d_format *format = &gl_info->formats[i];
2150
2151 if (!(format->flags & WINED3DFMT_FLAG_TEXTURE))
2152 continue;
2153
2154 if (!adapter->shader_backend->shader_color_fixup_supported(format->color_fixup)
2155 || !adapter->fragment_pipe->color_fixup_supported(format->color_fixup))
2156 format->flags &= ~WINED3DFMT_FLAG_TEXTURE;
2157 }
2158 }
2159
2160 static BOOL init_format_vertex_info(struct wined3d_gl_info *gl_info)
2161 {
2162 unsigned int i;
2163
2164 for (i = 0; i < (sizeof(format_vertex_info) / sizeof(*format_vertex_info)); ++i)
2165 {
2166 struct wined3d_format *format;
2167 int fmt_idx = getFmtIdx(format_vertex_info[i].id);
2168
2169 if (fmt_idx == -1)
2170 {
2171 ERR("Format %s (%#x) not found.\n",
2172 debug_d3dformat(format_vertex_info[i].id), format_vertex_info[i].id);
2173 return FALSE;
2174 }
2175
2176 format = &gl_info->formats[fmt_idx];
2177 format->emit_idx = format_vertex_info[i].emit_idx;
2178 format->component_count = format_vertex_info[i].component_count;
2179 format->gl_vtx_type = format_vertex_info[i].gl_vtx_type;
2180 format->gl_vtx_format = format_vertex_info[i].gl_vtx_format;
2181 format->gl_normalized = format_vertex_info[i].gl_normalized;
2182 format->component_size = format_vertex_info[i].component_size;
2183 }
2184
2185 return TRUE;
2186 }
2187
2188 BOOL initPixelFormatsNoGL(struct wined3d_gl_info *gl_info)
2189 {
2190 if (!init_format_base_info(gl_info)) return FALSE;
2191
2192 if (!init_format_block_info(gl_info))
2193 {
2194 HeapFree(GetProcessHeap(), 0, gl_info->formats);
2195 gl_info->formats = NULL;
2196 return FALSE;
2197 }
2198
2199 return TRUE;
2200 }
2201
2202 /* Context activation is done by the caller. */
2203 BOOL wined3d_adapter_init_format_info(struct wined3d_adapter *adapter)
2204 {
2205 struct wined3d_gl_info *gl_info = &adapter->gl_info;
2206
2207 if (!init_format_base_info(gl_info)) return FALSE;
2208
2209 if (!init_format_block_info(gl_info)) goto fail;
2210 if (!init_format_texture_info(adapter, gl_info)) goto fail;
2211 if (!init_format_vertex_info(gl_info)) goto fail;
2212
2213 apply_format_fixups(adapter, gl_info);
2214 init_format_fbo_compat_info(gl_info);
2215 init_format_filter_info(gl_info, adapter->driver_info.vendor);
2216
2217 return TRUE;
2218
2219 fail:
2220 HeapFree(GetProcessHeap(), 0, gl_info->formats);
2221 gl_info->formats = NULL;
2222 return FALSE;
2223 }
2224
2225 const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl_info,
2226 enum wined3d_format_id format_id)
2227 {
2228 int idx = getFmtIdx(format_id);
2229
2230 if (idx == -1)
2231 {
2232 FIXME("Can't find format %s (%#x) in the format lookup table\n",
2233 debug_d3dformat(format_id), format_id);
2234 /* Get the caller a valid pointer */
2235 idx = getFmtIdx(WINED3DFMT_UNKNOWN);
2236 }
2237
2238 return &gl_info->formats[idx];
2239 }
2240
2241 UINT wined3d_format_calculate_pitch(const struct wined3d_format *format, UINT width)
2242 {
2243 /* For block based formats, pitch means the amount of bytes to the next
2244 * row of blocks rather than the next row of pixels. */
2245 if (format->flags & WINED3DFMT_FLAG_BLOCKS)
2246 return format->block_byte_count * ((width + format->block_width - 1) / format->block_width);
2247
2248 return format->byte_count * width;
2249 }
2250
2251 UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT alignment,
2252 UINT width, UINT height, UINT depth)
2253 {
2254 UINT pitch = wined3d_format_calculate_pitch(format, width);
2255 UINT size;
2256
2257 if (format->id == WINED3DFMT_UNKNOWN)
2258 {
2259 size = 0;
2260 }
2261 else if (format->flags & WINED3DFMT_FLAG_BLOCKS)
2262 {
2263 UINT row_count = (height + format->block_height - 1) / format->block_height;
2264 size = row_count * ((pitch + alignment - 1) & ~(alignment - 1));
2265 }
2266 else
2267 {
2268 size = height * ((pitch + alignment - 1) & ~(alignment - 1));
2269 }
2270
2271 if (format->flags & WINED3DFMT_FLAG_HEIGHT_SCALE)
2272 {
2273 /* The D3D format requirements make sure that the resulting format is an integer again */
2274 size *= format->height_scale.numerator;
2275 size /= format->height_scale.denominator;
2276 }
2277
2278 size *= depth;
2279
2280 return size;
2281 }
2282
2283 /*****************************************************************************
2284 * Trace formatting of useful values
2285 */
2286 const char *debug_d3dformat(enum wined3d_format_id format_id)
2287 {
2288 switch (format_id)
2289 {
2290 #define FMT_TO_STR(format_id) case format_id: return #format_id
2291 FMT_TO_STR(WINED3DFMT_UNKNOWN);
2292 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM);
2293 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM);
2294 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM);
2295 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM);
2296 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM);
2297 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM);
2298 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM);
2299 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM);
2300 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM);
2301 FMT_TO_STR(WINED3DFMT_P8_UINT);
2302 FMT_TO_STR(WINED3DFMT_L8_UNORM);
2303 FMT_TO_STR(WINED3DFMT_L8A8_UNORM);
2304 FMT_TO_STR(WINED3DFMT_L4A4_UNORM);
2305 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM);
2306 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM);
2307 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM);
2308 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM);
2309 FMT_TO_STR(WINED3DFMT_UYVY);
2310 FMT_TO_STR(WINED3DFMT_YUY2);
2311 FMT_TO_STR(WINED3DFMT_YV12);
2312 FMT_TO_STR(WINED3DFMT_NV12);
2313 FMT_TO_STR(WINED3DFMT_DXT1);
2314 FMT_TO_STR(WINED3DFMT_DXT2);
2315 FMT_TO_STR(WINED3DFMT_DXT3);
2316 FMT_TO_STR(WINED3DFMT_DXT4);
2317 FMT_TO_STR(WINED3DFMT_DXT5);
2318 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8);
2319 FMT_TO_STR(WINED3DFMT_G8R8_G8B8);
2320 FMT_TO_STR(WINED3DFMT_R8G8_B8G8);
2321 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE);
2322 FMT_TO_STR(WINED3DFMT_D32_UNORM);
2323 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM);
2324 FMT_TO_STR(WINED3DFMT_X8D24_UNORM);
2325 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM);
2326 FMT_TO_STR(WINED3DFMT_L16_UNORM);
2327 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT);
2328 FMT_TO_STR(WINED3DFMT_VERTEXDATA);
2329 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx);
2330 FMT_TO_STR(WINED3DFMT_ATI1N);
2331 FMT_TO_STR(WINED3DFMT_ATI2N);
2332 FMT_TO_STR(WINED3DFMT_NVDB);
2333 FMT_TO_STR(WINED3DFMT_NVHU);
2334 FMT_TO_STR(WINED3DFMT_NVHS);
2335 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS);
2336 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT);
2337 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT);
2338 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT);
2339 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS);
2340 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT);
2341 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT);
2342 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT);
2343 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS);
2344 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT);
2345 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM);
2346 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT);
2347 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM);
2348 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT);
2349 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS);
2350 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT);
2351 FMT_TO_STR(WINED3DFMT_R32G32_UINT);
2352 FMT_TO_STR(WINED3DFMT_R32G32_SINT);
2353 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS);
2354 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT);
2355 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS);
2356 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT);
2357 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS);
2358 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM);
2359 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT);
2360 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM);
2361 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT);
2362 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS);
2363 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM);
2364 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB);
2365 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT);
2366 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM);
2367 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT);
2368 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS);
2369 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT);
2370 FMT_TO_STR(WINED3DFMT_R16G16_UNORM);
2371 FMT_TO_STR(WINED3DFMT_R16G16_UINT);
2372 FMT_TO_STR(WINED3DFMT_R16G16_SNORM);
2373 FMT_TO_STR(WINED3DFMT_R16G16_SINT);
2374 FMT_TO_STR(WINED3DFMT_R32_TYPELESS);
2375 FMT_TO_STR(WINED3DFMT_D32_FLOAT);
2376 FMT_TO_STR(WINED3DFMT_R32_FLOAT);
2377 FMT_TO_STR(WINED3DFMT_R32_UINT);
2378 FMT_TO_STR(WINED3DFMT_R32_SINT);
2379 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS);
2380 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT);
2381 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS);
2382 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT);
2383 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS);
2384 FMT_TO_STR(WINED3DFMT_R8G8_UNORM);
2385 FMT_TO_STR(WINED3DFMT_R8G8_UINT);
2386 FMT_TO_STR(WINED3DFMT_R8G8_SNORM);
2387 FMT_TO_STR(WINED3DFMT_R8G8_SINT);
2388 FMT_TO_STR(WINED3DFMT_R16_TYPELESS);
2389 FMT_TO_STR(WINED3DFMT_R16_FLOAT);
2390 FMT_TO_STR(WINED3DFMT_D16_UNORM);
2391 FMT_TO_STR(WINED3DFMT_R16_UNORM);
2392 FMT_TO_STR(WINED3DFMT_R16_UINT);
2393 FMT_TO_STR(WINED3DFMT_R16_SNORM);
2394 FMT_TO_STR(WINED3DFMT_R16_SINT);
2395 FMT_TO_STR(WINED3DFMT_R8_TYPELESS);
2396 FMT_TO_STR(WINED3DFMT_R8_UNORM);
2397 FMT_TO_STR(WINED3DFMT_R8_UINT);
2398 FMT_TO_STR(WINED3DFMT_R8_SNORM);
2399 FMT_TO_STR(WINED3DFMT_R8_SINT);
2400 FMT_TO_STR(WINED3DFMT_A8_UNORM);
2401 FMT_TO_STR(WINED3DFMT_R1_UNORM);
2402 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP);
2403 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM);
2404 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM);
2405 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS);
2406 FMT_TO_STR(WINED3DFMT_BC1_UNORM);
2407 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB);
2408 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS);
2409 FMT_TO_STR(WINED3DFMT_BC2_UNORM);
2410 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB);
2411 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS);
2412 FMT_TO_STR(WINED3DFMT_BC3_UNORM);
2413 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB);
2414 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS);
2415 FMT_TO_STR(WINED3DFMT_BC4_UNORM);
2416 FMT_TO_STR(WINED3DFMT_BC4_SNORM);
2417 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS);
2418 FMT_TO_STR(WINED3DFMT_BC5_UNORM);
2419 FMT_TO_STR(WINED3DFMT_BC5_SNORM);
2420 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM);
2421 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM);
2422 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM);
2423 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM);
2424 FMT_TO_STR(WINED3DFMT_INTZ);
2425 FMT_TO_STR(WINED3DFMT_RESZ);
2426 FMT_TO_STR(WINED3DFMT_NULL);
2427 FMT_TO_STR(WINED3DFMT_R16);
2428 FMT_TO_STR(WINED3DFMT_AL16);
2429 #undef FMT_TO_STR
2430 default:
2431 {
2432 char fourcc[5];
2433 fourcc[0] = (char)(format_id);
2434 fourcc[1] = (char)(format_id >> 8);
2435 fourcc[2] = (char)(format_id >> 16);
2436 fourcc[3] = (char)(format_id >> 24);
2437 fourcc[4] = 0;
2438 if (isprint(fourcc[0]) && isprint(fourcc[1]) && isprint(fourcc[2]) && isprint(fourcc[3]))
2439 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id, fourcc);
2440 else
2441 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id);
2442 }
2443 return "unrecognized";
2444 }
2445 }
2446
2447 const char *debug_d3ddevicetype(enum wined3d_device_type device_type)
2448 {
2449 switch (device_type)
2450 {
2451 #define DEVTYPE_TO_STR(dev) case dev: return #dev
2452 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL);
2453 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF);
2454 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW);
2455 #undef DEVTYPE_TO_STR
2456 default:
2457 FIXME("Unrecognized device type %#x.\n", device_type);
2458 return "unrecognized";
2459 }
2460 }
2461
2462 const char *debug_d3dusage(DWORD usage)
2463 {
2464 char buf[333];
2465
2466 buf[0] = '\0';
2467 #define WINED3DUSAGE_TO_STR(u) if (usage & u) { strcat(buf, " | "#u); usage &= ~u; }
2468 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RENDERTARGET);
2469 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DEPTHSTENCIL);
2470 WINED3DUSAGE_TO_STR(WINED3DUSAGE_WRITEONLY);
2471 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING);
2472 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP);
2473 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS);
2474 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES);
2475 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES);
2476 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC);
2477 WINED3DUSAGE_TO_STR(WINED3DUSAGE_AUTOGENMIPMAP);
2478 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP);
2479 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL);
2480 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY);
2481 #undef WINED3DUSAGE_TO_STR
2482 if (usage) FIXME("Unrecognized usage flag(s) %#x\n", usage);
2483
2484 return buf[0] ? wine_dbg_sprintf("%s", &buf[3]) : "0";
2485 }
2486
2487 const char *debug_d3dusagequery(DWORD usagequery)
2488 {
2489 char buf[238];
2490
2491 buf[0] = '\0';
2492 #define WINED3DUSAGEQUERY_TO_STR(u) if (usagequery & u) { strcat(buf, " | "#u); usagequery &= ~u; }
2493 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_FILTER);
2494 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP);
2495 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING);
2496 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD);
2497 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE);
2498 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE);
2499 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP);
2500 #undef WINED3DUSAGEQUERY_TO_STR
2501 if (usagequery) FIXME("Unrecognized usage query flag(s) %#x\n", usagequery);
2502
2503 return buf[0] ? wine_dbg_sprintf("%s", &buf[3]) : "0";
2504 }
2505
2506 const char *debug_d3ddeclmethod(enum wined3d_decl_method method)
2507 {
2508 switch (method)
2509 {
2510 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
2511 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT);
2512 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U);
2513 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V);
2514 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV);
2515 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV);
2516 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP);
2517 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED);
2518 #undef WINED3DDECLMETHOD_TO_STR
2519 default:
2520 FIXME("Unrecognized declaration method %#x.\n", method);
2521 return "unrecognized";
2522 }
2523 }
2524
2525 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage)
2526 {
2527 switch (usage)
2528 {
2529 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
2530 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION);
2531 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT);
2532 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES);
2533 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL);
2534 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE);
2535 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD);
2536 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT);
2537 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL);
2538 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR);
2539 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT);
2540 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR);
2541 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG);
2542 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH);
2543 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE);
2544 #undef WINED3DDECLUSAGE_TO_STR
2545 default:
2546 FIXME("Unrecognized %u declaration usage!\n", usage);
2547 return "unrecognized";
2548 }
2549 }
2550
2551 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type)
2552 {
2553 switch (resource_type)
2554 {
2555 #define RES_TO_STR(res) case res: return #res
2556 RES_TO_STR(WINED3D_RTYPE_SURFACE);
2557 RES_TO_STR(WINED3D_RTYPE_VOLUME);
2558 RES_TO_STR(WINED3D_RTYPE_TEXTURE);
2559 RES_TO_STR(WINED3D_RTYPE_VOLUME_TEXTURE);
2560 RES_TO_STR(WINED3D_RTYPE_CUBE_TEXTURE);
2561 RES_TO_STR(WINED3D_RTYPE_BUFFER);
2562 #undef RES_TO_STR
2563 default:
2564 FIXME("Unrecognized resource type %#x.\n", resource_type);
2565 return "unrecognized";
2566 }
2567 }
2568
2569 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type)
2570 {
2571 switch (primitive_type)
2572 {
2573 #define PRIM_TO_STR(prim) case prim: return #prim
2574 PRIM_TO_STR(WINED3D_PT_UNDEFINED);
2575 PRIM_TO_STR(WINED3D_PT_POINTLIST);
2576 PRIM_TO_STR(WINED3D_PT_LINELIST);
2577 PRIM_TO_STR(WINED3D_PT_LINESTRIP);
2578 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST);
2579 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP);
2580 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN);
2581 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ);
2582 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ);
2583 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ);
2584 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ);
2585 #undef PRIM_TO_STR
2586 default:
2587 FIXME("Unrecognized %u primitive type!\n", primitive_type);
2588 return "unrecognized";
2589 }
2590 }
2591
2592 const char *debug_d3drenderstate(enum wined3d_render_state state)
2593 {
2594 switch (state)
2595 {
2596 #define D3DSTATE_TO_STR(u) case u: return #u
2597 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS);
2598 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE);
2599 D3DSTATE_TO_STR(WINED3D_RS_WRAPU);
2600 D3DSTATE_TO_STR(WINED3D_RS_WRAPV);
2601 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE);
2602 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE);
2603 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE);
2604 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN);
2605 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE);
2606 D3DSTATE_TO_STR(WINED3D_RS_ROP2);
2607 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK);
2608 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE);
2609 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE);
2610 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL);
2611 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND);
2612 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND);
2613 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE);
2614 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC);
2615 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF);
2616 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC);
2617 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE);
2618 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE);
2619 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE);
2620 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE);
2621 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE);
2622 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL);
2623 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX);
2624 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA);
2625 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR);
2626 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE);
2627 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART);
2628 D3DSTATE_TO_STR(WINED3D_RS_FOGEND);
2629 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY);
2630 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE);
2631 D3DSTATE_TO_STR(WINED3D_RS_EDGEANTIALIAS);
2632 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE);
2633 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS);
2634 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE);
2635 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY);
2636 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH);
2637 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT);
2638 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE);
2639 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL);
2640 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL);
2641 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS);
2642 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC);
2643 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF);
2644 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK);
2645 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK);
2646 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR);
2647 D3DSTATE_TO_STR(WINED3D_RS_WRAP0);
2648 D3DSTATE_TO_STR(WINED3D_RS_WRAP1);
2649 D3DSTATE_TO_STR(WINED3D_RS_WRAP2);
2650 D3DSTATE_TO_STR(WINED3D_RS_WRAP3);
2651 D3DSTATE_TO_STR(WINED3D_RS_WRAP4);
2652 D3DSTATE_TO_STR(WINED3D_RS_WRAP5);
2653 D3DSTATE_TO_STR(WINED3D_RS_WRAP6);
2654 D3DSTATE_TO_STR(WINED3D_RS_WRAP7);
2655 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING);
2656 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING);
2657 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS);
2658 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT);
2659 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE);
2660 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX);
2661 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER);
2662 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS);
2663 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE);
2664 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE);
2665 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE);
2666 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE);
2667 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE);
2668 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND);
2669 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE);
2670 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING);
2671 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE);
2672 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN);
2673 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE);
2674 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE);
2675 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A);
2676 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B);
2677 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C);
2678 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS);
2679 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK);
2680 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE);
2681 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS);
2682 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN);
2683 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX);
2684 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE);
2685 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE);
2686 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR);
2687 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP);
2688 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE);
2689 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE);
2690 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE);
2691 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS);
2692 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE);
2693 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL);
2694 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL);
2695 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X);
2696 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y);
2697 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z);
2698 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W);
2699 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION);
2700 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE);
2701 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILFAIL);
2702 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILZFAIL);
2703 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILPASS);
2704 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILFUNC);
2705 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1);
2706 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2);
2707 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3);
2708 D3DSTATE_TO_STR(WINED3D_RS_BLENDFACTOR);
2709 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE);
2710 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS);
2711 D3DSTATE_TO_STR(WINED3D_RS_WRAP8);
2712 D3DSTATE_TO_STR(WINED3D_RS_WRAP9);
2713 D3DSTATE_TO_STR(WINED3D_RS_WRAP10);
2714 D3DSTATE_TO_STR(WINED3D_RS_WRAP11);
2715 D3DSTATE_TO_STR(WINED3D_RS_WRAP12);
2716 D3DSTATE_TO_STR(WINED3D_RS_WRAP13);
2717 D3DSTATE_TO_STR(WINED3D_RS_WRAP14);
2718 D3DSTATE_TO_STR(WINED3D_RS_WRAP15);
2719 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE);
2720 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA);
2721 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA);
2722 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA);
2723 #undef D3DSTATE_TO_STR
2724 default:
2725 FIXME("Unrecognized %u render state!\n", state);
2726 return "unrecognized";
2727 }
2728 }
2729
2730 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state)
2731 {
2732 switch (state)
2733 {
2734 #define D3DSTATE_TO_STR(u) case u: return #u
2735 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR);
2736 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U);
2737 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V);
2738 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W);
2739 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER);
2740 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER);
2741 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER);
2742 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS);
2743 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL);
2744 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY);
2745 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE);
2746 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX);
2747 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET);
2748 #undef D3DSTATE_TO_STR
2749 default:
2750 FIXME("Unrecognized %u sampler state!\n", state);
2751 return "unrecognized";
2752 }
2753 }
2754
2755 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type)
2756 {
2757 switch (filter_type)
2758 {
2759 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
2760 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE);
2761 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT);
2762 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR);
2763 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC);
2764 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC);
2765 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC);
2766 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD);
2767 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD);
2768 #undef D3DTEXTUREFILTERTYPE_TO_STR
2769 default:
2770 FIXME("Unrecognied texture filter type 0x%08x.\n", filter_type);
2771 return "unrecognized";
2772 }
2773 }
2774
2775 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state)
2776 {
2777 switch (state)
2778 {
2779 #define D3DSTATE_TO_STR(u) case u: return #u
2780 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP);
2781 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1);
2782 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2);
2783 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP);
2784 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1);
2785 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2);
2786 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00);
2787 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01);
2788 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10);
2789 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11);
2790 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX);
2791 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE);
2792 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET);
2793 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS);
2794 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0);
2795 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0);
2796 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG);
2797 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT);
2798 #undef D3DSTATE_TO_STR
2799 default:
2800 FIXME("Unrecognized %u texture state!\n", state);
2801 return "unrecognized";
2802 }
2803 }
2804
2805 const char *debug_d3dtop(enum wined3d_texture_op d3dtop)
2806 {
2807 switch (d3dtop)
2808 {
2809 #define D3DTOP_TO_STR(u) case u: return #u
2810 D3DTOP_TO_STR(WINED3D_TOP_DISABLE);
2811 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1);
2812 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2);
2813 D3DTOP_TO_STR(WINED3D_TOP_MODULATE);
2814 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X);
2815 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X);
2816 D3DTOP_TO_STR(WINED3D_TOP_ADD);
2817 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED);
2818 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X);
2819 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT);
2820 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH);
2821 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA);
2822 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA);
2823 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA);
2824 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM);
2825 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA);
2826 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE);
2827 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR);
2828 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA);
2829 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR);
2830 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA);
2831 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP);
2832 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE);
2833 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3);
2834 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD);
2835 D3DTOP_TO_STR(WINED3D_TOP_LERP);
2836 #undef D3DTOP_TO_STR
2837 default:
2838 FIXME("Unrecognized texture op %#x.\n", d3dtop);
2839 return "unrecognized";
2840 }
2841 }
2842
2843 const char *debug_d3dtstype(enum wined3d_transform_state tstype)
2844 {
2845 switch (tstype)
2846 {
2847 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
2848 TSTYPE_TO_STR(WINED3D_TS_VIEW);
2849 TSTYPE_TO_STR(WINED3D_TS_PROJECTION);
2850 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0);
2851 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1);
2852 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2);
2853 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3);
2854 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4);
2855 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5);
2856 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6);
2857 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7);
2858 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
2859 #undef TSTYPE_TO_STR
2860 default:
2861 if (tstype > 256 && tstype < 512)
2862 {
2863 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype);
2864 return ("WINED3D_TS_WORLD_MATRIX > 0");
2865 }
2866 FIXME("Unrecognized transform state %#x.\n", tstype);
2867 return "unrecognized";
2868 }
2869 }
2870
2871 static const char *debug_shader_type(enum wined3d_shader_type type)
2872 {
2873 switch(type)
2874 {
2875 #define WINED3D_TO_STR(type) case type: return #type
2876 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL);
2877 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX);
2878 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY);
2879 #undef WINED3D_TO_STR
2880 default:
2881 FIXME("Unrecognized shader type %#x.\n", type);
2882 return "unrecognized";
2883 }
2884 }
2885
2886 const char *debug_d3dstate(DWORD state)
2887 {
2888 if (STATE_IS_RENDER(state))
2889 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state - STATE_RENDER(0)));
2890 if (STATE_IS_TEXTURESTAGE(state))
2891 {
2892 DWORD texture_stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
2893 DWORD texture_state = state - STATE_TEXTURESTAGE(texture_stage, 0);
2894 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
2895 texture_stage, debug_d3dtexturestate(texture_state));
2896 }
2897 if (STATE_IS_SAMPLER(state))
2898 return wine_dbg_sprintf("STATE_SAMPLER(%#x)", state - STATE_SAMPLER(0));
2899 if (STATE_IS_SHADER(state))
2900 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state - STATE_SHADER(0)));
2901 if (STATE_IS_CONSTANT_BUFFER(state))
2902 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state - STATE_CONSTANT_BUFFER(0)));
2903 if (STATE_IS_SHADER_RESOURCE_BINDING(state))
2904 return "STATE_SHADER_RESOURCE_BINDING";
2905 if (STATE_IS_TRANSFORM(state))
2906 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state - STATE_TRANSFORM(0)));
2907 if (STATE_IS_STREAMSRC(state))
2908 return "STATE_STREAMSRC";
2909 if (STATE_IS_INDEXBUFFER(state))
2910 return "STATE_INDEXBUFFER";
2911 if (STATE_IS_VDECL(state))
2912 return "STATE_VDECL";
2913 if (STATE_IS_VIEWPORT(state))
2914 return "STATE_VIEWPORT";
2915 if (STATE_IS_LIGHT_TYPE(state))
2916 return "STATE_LIGHT_TYPE";
2917 if (STATE_IS_ACTIVELIGHT(state))
2918 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state - STATE_ACTIVELIGHT(0));
2919 if (STATE_IS_SCISSORRECT(state))
2920 return "STATE_SCISSORRECT";
2921 if (STATE_IS_CLIPPLANE(state))
2922 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state - STATE_CLIPPLANE(0));
2923 if (STATE_IS_MATERIAL(state))
2924 return "STATE_MATERIAL";
2925 if (STATE_IS_FRONTFACE(state))
2926 return "STATE_FRONTFACE";
2927 if (STATE_IS_POINTSPRITECOORDORIGIN(state))
2928 return "STATE_POINTSPRITECOORDORIGIN";
2929 if (STATE_IS_BASEVERTEXINDEX(state))
2930 return "STATE_BASEVERTEXINDEX";
2931 if (STATE_IS_FRAMEBUFFER(state))
2932 return "STATE_FRAMEBUFFER";
2933 if (STATE_IS_POINT_SIZE_ENABLE(state))
2934 return "STATE_POINT_SIZE_ENABLE";
2935
2936 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state);
2937 }
2938
2939 const char *debug_d3dpool(enum wined3d_pool pool)
2940 {
2941 switch (pool)
2942 {
2943 #define POOL_TO_STR(p) case p: return #p
2944 POOL_TO_STR(WINED3D_POOL_DEFAULT);
2945 POOL_TO_STR(WINED3D_POOL_MANAGED);
2946 POOL_TO_STR(WINED3D_POOL_SYSTEM_MEM);
2947 POOL_TO_STR(WINED3D_POOL_SCRATCH);
2948 #undef POOL_TO_STR
2949 default:
2950 FIXME("Unrecognized pool %#x.\n", pool);
2951 return "unrecognized";
2952 }
2953 }
2954
2955 const char *debug_fbostatus(GLenum status) {
2956 switch(status) {
2957 #define FBOSTATUS_TO_STR(u) case u: return #u
2958 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE);
2959 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
2960 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT);
2961 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT);
2962 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT);
2963 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER);
2964 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER);
2965 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE);
2966 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED);
2967 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED);
2968 #undef FBOSTATUS_TO_STR
2969 default:
2970 FIXME("Unrecognied FBO status 0x%08x\n", status);
2971 return "unrecognized";
2972 }
2973 }
2974
2975 const char *debug_glerror(GLenum error) {
2976 switch(error) {
2977 #define GLERROR_TO_STR(u) case u: return #u
2978 GLERROR_TO_STR(GL_NO_ERROR);
2979 GLERROR_TO_STR(GL_INVALID_ENUM);
2980 GLERROR_TO_STR(GL_INVALID_VALUE);
2981 GLERROR_TO_STR(GL_INVALID_OPERATION);
2982 GLERROR_TO_STR(GL_STACK_OVERFLOW);
2983 GLERROR_TO_STR(GL_STACK_UNDERFLOW);
2984 GLERROR_TO_STR(GL_OUT_OF_MEMORY);
2985 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION);
2986 #undef GLERROR_TO_STR
2987 default:
2988 FIXME("Unrecognied GL error 0x%08x\n", error);
2989 return "unrecognized";
2990 }
2991 }
2992
2993 static const char *debug_fixup_channel_source(enum fixup_channel_source source)
2994 {
2995 switch(source)
2996 {
2997 #define WINED3D_TO_STR(x) case x: return #x
2998 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO);
2999 WINED3D_TO_STR(CHANNEL_SOURCE_ONE);
3000 WINED3D_TO_STR(CHANNEL_SOURCE_X);
3001 WINED3D_TO_STR(CHANNEL_SOURCE_Y);
3002 WINED3D_TO_STR(CHANNEL_SOURCE_Z);
3003 WINED3D_TO_STR(CHANNEL_SOURCE_W);
3004 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0);
3005 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1);
3006 #undef WINED3D_TO_STR
3007 default:
3008 FIXME("Unrecognized fixup_channel_source %#x\n", source);
3009 return "unrecognized";
3010 }
3011 }
3012
3013 static const char *debug_complex_fixup(enum complex_fixup fixup)
3014 {
3015 switch(fixup)
3016 {
3017 #define WINED3D_TO_STR(x) case x: return #x
3018 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2);
3019 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY);
3020 WINED3D_TO_STR(COMPLEX_FIXUP_YV12);
3021 WINED3D_TO_STR(COMPLEX_FIXUP_NV12);
3022 WINED3D_TO_STR(COMPLEX_FIXUP_P8);
3023 #undef WINED3D_TO_STR
3024 default:
3025 FIXME("Unrecognized complex fixup %#x\n", fixup);
3026 return "unrecognized";
3027 }
3028 }
3029
3030 void dump_color_fixup_desc(struct color_fixup_desc fixup)
3031 {
3032 if (is_complex_fixup(fixup))
3033 {
3034 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup)));
3035 return;
3036 }
3037
3038 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup.x_source), fixup.x_sign_fixup ? ", SIGN_FIXUP" : "");
3039 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup.y_source), fixup.y_sign_fixup ? ", SIGN_FIXUP" : "");
3040 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup.z_source), fixup.z_sign_fixup ? ", SIGN_FIXUP" : "");
3041 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup.w_source), fixup.w_sign_fixup ? ", SIGN_FIXUP" : "");
3042 }
3043
3044 BOOL is_invalid_op(const struct wined3d_state *state, int stage,
3045 enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3)
3046 {
3047 if (op == WINED3D_TOP_DISABLE)
3048 return FALSE;
3049 if (state->textures[stage])
3050 return FALSE;
3051
3052 if ((arg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
3053 && op != WINED3D_TOP_SELECT_ARG2)
3054 return TRUE;
3055 if ((arg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
3056 && op != WINED3D_TOP_SELECT_ARG1)
3057 return TRUE;
3058 if ((arg3 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
3059 && (op == WINED3D_TOP_MULTIPLY_ADD || op == WINED3D_TOP_LERP))
3060 return TRUE;
3061
3062 return FALSE;
3063 }
3064
3065 /* Setup this textures matrix according to the texture flags. */
3066 /* Context activation is done by the caller (state handler). */
3067 void set_texture_matrix(const struct wined3d_gl_info *gl_info, const float *smat, DWORD flags,
3068 BOOL calculatedCoords, BOOL transformed, enum wined3d_format_id vtx_fmt, BOOL ffp_proj_control)
3069 {
3070 float mat[16];
3071
3072 gl_info->gl_ops.gl.p_glMatrixMode(GL_TEXTURE);
3073 checkGLcall("glMatrixMode(GL_TEXTURE)");
3074
3075 if (flags == WINED3D_TTFF_DISABLE || flags == WINED3D_TTFF_COUNT1 || transformed)
3076 {
3077 gl_info->gl_ops.gl.p_glLoadIdentity();
3078 checkGLcall("glLoadIdentity()");
3079 return;
3080 }
3081
3082 if (flags == (WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED))
3083 {
3084 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
3085 return;
3086 }
3087
3088 memcpy(mat, smat, 16 * sizeof(float));
3089
3090 if (flags & WINED3D_TTFF_PROJECTED)
3091 {
3092 if (!ffp_proj_control)
3093 {
3094 switch (flags & ~WINED3D_TTFF_PROJECTED)
3095 {
3096 case WINED3D_TTFF_COUNT2:
3097 mat[ 3] = mat[ 1];
3098 mat[ 7] = mat[ 5];
3099 mat[11] = mat[ 9];
3100 mat[15] = mat[13];
3101 mat[ 1] = mat[ 5] = mat[ 9] = mat[13] = 0.0f;
3102 break;
3103 case WINED3D_TTFF_COUNT3:
3104 mat[ 3] = mat[ 2];
3105 mat[ 7] = mat[ 6];
3106 mat[11] = mat[10];
3107 mat[15] = mat[14];
3108 mat[ 2] = mat[ 6] = mat[10] = mat[14] = 0.0f;
3109 break;
3110 }
3111 }
3112 } else { /* under directx the R/Z coord can be used for translation, under opengl we use the Q coord instead */
3113 if(!calculatedCoords) {
3114 switch(vtx_fmt)
3115 {
3116 case WINED3DFMT_R32_FLOAT:
3117 /* Direct3D passes the default 1.0 in the 2nd coord, while gl passes it in the 4th.
3118 * swap 2nd and 4th coord. No need to store the value of mat[12] in mat[4] because
3119 * the input value to the transformation will be 0, so the matrix value is irrelevant
3120 */
3121 mat[12] = mat[4];
3122 mat[13] = mat[5];
3123 mat[14] = mat[6];
3124 mat[15] = mat[7];
3125 break;
3126 case WINED3DFMT_R32G32_FLOAT:
3127 /* See above, just 3rd and 4th coord
3128 */
3129 mat[12] = mat[8];
3130 mat[13] = mat[9];
3131 mat[14] = mat[10];
3132 mat[15] = mat[11];
3133 break;
3134 case WINED3DFMT_R32G32B32_FLOAT: /* Opengl defaults match dx defaults */
3135 case WINED3DFMT_R32G32B32A32_FLOAT: /* No defaults apply, all app defined */
3136
3137 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
3138 * into a bad place. The division elimination below will apply to make sure the
3139 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
3140 */
3141 case WINED3DFMT_UNKNOWN: /* No texture coords, 0/0/0/1 defaults are passed */
3142 break;
3143 default:
3144 FIXME("Unexpected fixed function texture coord input\n");
3145 }
3146 }
3147 if (!ffp_proj_control)
3148 {
3149 switch (flags & ~WINED3D_TTFF_PROJECTED)
3150 {
3151 /* case WINED3D_TTFF_COUNT1: Won't ever get here. */
3152 case WINED3D_TTFF_COUNT2:
3153 mat[2] = mat[6] = mat[10] = mat[14] = 0;
3154 /* OpenGL divides the first 3 vertex coord by the 4th by default,
3155 * which is essentially the same as D3DTTFF_PROJECTED. Make sure that
3156 * the 4th coord evaluates to 1.0 to eliminate that.
3157 *
3158 * If the fixed function pipeline is used, the 4th value remains unused,
3159 * so there is no danger in doing this. With vertex shaders we have a
3160 * problem. Should an app hit that problem, the code here would have to
3161 * check for pixel shaders, and the shader has to undo the default gl divide.
3162 *
3163 * A more serious problem occurs if the app passes 4 coordinates in, and the
3164 * 4th is != 1.0(opengl default). This would have to be fixed in drawStridedSlow
3165 * or a replacement shader. */
3166 default:
3167 mat[3] = mat[7] = mat[11] = 0; mat[15] = 1;
3168 }
3169 }
3170 }
3171
3172 gl_info->gl_ops.gl.p_glLoadMatrixf(mat);
3173 checkGLcall("glLoadMatrixf(mat)");
3174 }
3175
3176 /* This small helper function is used to convert a bitmask into the number of masked bits */
3177 unsigned int count_bits(unsigned int mask)
3178 {
3179 unsigned int count;
3180 for (count = 0; mask; ++count)
3181 {
3182 mask &= mask - 1;
3183 }
3184 return count;
3185 }
3186
3187 /* Helper function for retrieving color info for ChoosePixelFormat and wglChoosePixelFormatARB.
3188 * The later function requires individual color components. */
3189 BOOL getColorBits(const struct wined3d_format *format,
3190 BYTE *redSize, BYTE *greenSize, BYTE *blueSize, BYTE *alphaSize, BYTE *totalSize)
3191 {
3192 TRACE("format %s.\n", debug_d3dformat(format->id));
3193
3194 switch (format->id)
3195 {
3196 case WINED3DFMT_B10G10R10A2_UNORM:
3197 case WINED3DFMT_R10G10B10A2_UNORM:
3198 case WINED3DFMT_B8G8R8X8_UNORM:
3199 case WINED3DFMT_B8G8R8_UNORM:
3200 case WINED3DFMT_B8G8R8A8_UNORM:
3201 case WINED3DFMT_R8G8B8A8_UNORM:
3202 case WINED3DFMT_B5G5R5X1_UNORM:
3203 case WINED3DFMT_B5G5R5A1_UNORM:
3204 case WINED3DFMT_B5G6R5_UNORM:
3205 case WINED3DFMT_B4G4R4X4_UNORM:
3206 case WINED3DFMT_B4G4R4A4_UNORM:
3207 case WINED3DFMT_B2G3R3_UNORM:
3208 case WINED3DFMT_P8_UINT_A8_UNORM:
3209 case WINED3DFMT_P8_UINT:
3210 break;
3211 default:
3212 FIXME("Unsupported format %s.\n", debug_d3dformat(format->id));
3213 return FALSE;
3214 }
3215
3216 *redSize = format->red_size;
3217 *greenSize = format->green_size;
3218 *blueSize = format->blue_size;
3219 *alphaSize = format->alpha_size;
3220 *totalSize = *redSize + *greenSize + *blueSize + *alphaSize;
3221
3222 TRACE("Returning red: %d, green: %d, blue: %d, alpha: %d, total: %d for format %s.\n",
3223 *redSize, *greenSize, *blueSize, *alphaSize, *totalSize, debug_d3dformat(format->id));
3224 return TRUE;
3225 }
3226
3227 /* Helper function for retrieving depth/stencil info for ChoosePixelFormat and wglChoosePixelFormatARB */
3228 BOOL getDepthStencilBits(const struct wined3d_format *format, BYTE *depthSize, BYTE *stencilSize)
3229 {
3230 TRACE("format %s.\n", debug_d3dformat(format->id));
3231
3232 switch (format->id)
3233 {
3234 case WINED3DFMT_D16_LOCKABLE:
3235 case WINED3DFMT_D16_UNORM:
3236 case WINED3DFMT_S1_UINT_D15_UNORM:
3237 case WINED3DFMT_X8D24_UNORM:
3238 case WINED3DFMT_S4X4_UINT_D24_UNORM:
3239 case WINED3DFMT_D24_UNORM_S8_UINT:
3240 case WINED3DFMT_S8_UINT_D24_FLOAT:
3241 case WINED3DFMT_D32_UNORM:
3242 case WINED3DFMT_D32_FLOAT:
3243 case WINED3DFMT_INTZ:
3244 break;
3245 default:
3246 FIXME("Unsupported depth/stencil format %s.\n", debug_d3dformat(format->id));
3247 return FALSE;
3248 }
3249
3250 *depthSize = format->depth_size;
3251 *stencilSize = format->stencil_size;
3252
3253 TRACE("Returning depthSize: %d and stencilSize: %d for format %s.\n",
3254 *depthSize, *stencilSize, debug_d3dformat(format->id));
3255 return TRUE;
3256 }
3257
3258 /* Note: It's the caller's responsibility to ensure values can be expressed
3259 * in the requested format. UNORM formats for example can only express values
3260 * in the range 0.0f -> 1.0f. */
3261 DWORD wined3d_format_convert_from_float(const struct wined3d_surface *surface, const struct wined3d_color *color)
3262 {
3263 static const struct
3264 {
3265 enum wined3d_format_id format_id;
3266 float r_mul;
3267 float g_mul;
3268 float b_mul;
3269 float a_mul;
3270 BYTE r_shift;
3271 BYTE g_shift;
3272 BYTE b_shift;
3273 BYTE a_shift;
3274 }
3275 conv[] =
3276 {
3277 {WINED3DFMT_B8G8R8A8_UNORM, 255.0f, 255.0f, 255.0f, 255.0f, 16, 8, 0, 24},
3278 {WINED3DFMT_B8G8R8X8_UNORM, 255.0f, 255.0f, 255.0f, 255.0f, 16, 8, 0, 24},
3279 {WINED3DFMT_B8G8R8_UNORM, 255.0f, 255.0f, 255.0f, 255.0f, 16, 8, 0, 24},
3280 {WINED3DFMT_B5G6R5_UNORM, 31.0f, 63.0f, 31.0f, 0.0f, 11, 5, 0, 0},
3281 {WINED3DFMT_B5G5R5A1_UNORM, 31.0f, 31.0f, 31.0f, 1.0f, 10, 5, 0, 15},
3282 {WINED3DFMT_B5G5R5X1_UNORM, 31.0f, 31.0f, 31.0f, 1.0f, 10, 5, 0, 15},
3283 {WINED3DFMT_R8_UNORM, 255.0f, 0.0f, 0.0f, 0.0f, 0, 0, 0, 0},
3284 {WINED3DFMT_A8_UNORM, 0.0f, 0.0f, 0.0f, 255.0f, 0, 0, 0, 0},
3285 {WINED3DFMT_B4G4R4A4_UNORM, 15.0f, 15.0f, 15.0f, 15.0f, 8, 4, 0, 12},
3286 {WINED3DFMT_B4G4R4X4_UNORM, 15.0f, 15.0f, 15.0f, 15.0f, 8, 4, 0, 12},
3287 {WINED3DFMT_B2G3R3_UNORM, 7.0f, 7.0f, 3.0f, 0.0f, 5, 2, 0, 0},
3288 {WINED3DFMT_R8G8B8A8_UNORM, 255.0f, 255.0f, 255.0f, 255.0f, 0, 8, 16, 24},
3289 {WINED3DFMT_R8G8B8X8_UNORM, 255.0f, 255.0f, 255.0f, 255.0f, 0, 8, 16, 24},
3290 {WINED3DFMT_B10G10R10A2_UNORM, 1023.0f, 1023.0f, 1023.0f, 3.0f, 20, 10, 0, 30},
3291 {WINED3DFMT_R10G10B10A2_UNORM, 1023.0f, 1023.0f, 1023.0f, 3.0f, 0, 10, 20, 30},
3292 {WINED3DFMT_P8_UINT, 0.0f, 0.0f, 0.0f, 255.0f, 0, 0, 0, 0},
3293 };
3294 const struct wined3d_format *format = surface->resource.format;
3295 unsigned int i;
3296
3297 TRACE("Converting color {%.8e %.8e %.8e %.8e} to format %s.\n",
3298 color->r, color->g, color->b, color->a, debug_d3dformat(format->id));
3299
3300 for (i = 0; i < sizeof(conv) / sizeof(*conv); ++i)
3301 {
3302 DWORD ret;
3303
3304 if (format->id != conv[i].format_id) continue;
3305
3306 ret = ((DWORD)((color->r * conv[i].r_mul) + 0.5f)) << conv[i].r_shift;
3307 ret |= ((DWORD)((color->g * conv[i].g_mul) + 0.5f)) << conv[i].g_shift;
3308 ret |= ((DWORD)((color->b * conv[i].b_mul) + 0.5f)) << conv[i].b_shift;
3309 ret |= ((DWORD)((color->a * conv[i].a_mul) + 0.5f)) << conv[i].a_shift;
3310
3311 TRACE("Returning 0x%08x.\n", ret);
3312
3313 return ret;
3314 }
3315
3316 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format->id));
3317
3318 return 0;
3319 }
3320
3321 /* DirectDraw stuff */
3322 enum wined3d_format_id pixelformat_for_depth(DWORD depth)
3323 {
3324 switch (depth)
3325 {
3326 case 8: return WINED3DFMT_P8_UINT;
3327 case 15: return WINED3DFMT_B5G5R5X1_UNORM;
3328 case 16: return WINED3DFMT_B5G6R5_UNORM;
3329 case 24: return WINED3DFMT_B8G8R8X8_UNORM; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
3330 case 32: return WINED3DFMT_B8G8R8X8_UNORM; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
3331 default: return WINED3DFMT_UNKNOWN;
3332 }
3333 }
3334
3335 void multiply_matrix(struct wined3d_matrix *dest, const struct wined3d_matrix *src1,
3336 const struct wined3d_matrix *src2)
3337 {
3338 struct wined3d_matrix temp;
3339
3340 /* Now do the multiplication 'by hand'.
3341 I know that all this could be optimised, but this will be done later :-) */
3342 temp.u.s._11 = (src1->u.s._11 * src2->u.s._11) + (src1->u.s._21 * src2->u.s._12) + (src1->u.s._31 * src2->u.s._13) + (src1->u.s._41 * src2->u.s._14);
3343 temp.u.s._21 = (src1->u.s._11 * src2->u.s._21) + (src1->u.s._21 * src2->u.s._22) + (src1->u.s._31 * src2->u.s._23) + (src1->u.s._41 * src2->u.s._24);
3344 temp.u.s._31 = (src1->u.s._11 * src2->u.s._31) + (src1->u.s._21 * src2->u.s._32) + (src1->u.s._31 * src2->u.s._33) + (src1->u.s._41 * src2->u.s._34);
3345 temp.u.s._41 = (src1->u.s._11 * src2->u.s._41) + (src1->u.s._21 * src2->u.s._42) + (src1->u.s._31 * src2->u.s._43) + (src1->u.s._41 * src2->u.s._44);
3346
3347 temp.u.s._12 = (src1->u.s._12 * src2->u.s._11) + (src1->u.s._22 * src2->u.s._12) + (src1->u.s._32 * src2->u.s._13) + (src1->u.s._42 * src2->u.s._14);
3348 temp.u.s._22 = (src1->u.s._12 * src2->u.s._21) + (src1->u.s._22 * src2->u.s._22) + (src1->u.s._32 * src2->u.s._23) + (src1->u.s._42 * src2->u.s._24);
3349 temp.u.s._32 = (src1->u.s._12 * src2->u.s._31) + (src1->u.s._22 * src2->u.s._32) + (src1->u.s._32 * src2->u.s._33) + (src1->u.s._42 * src2->u.s._34);
3350 temp.u.s._42 = (src1->u.s._12 * src2->u.s._41) + (src1->u.s._22 * src2->u.s._42) + (src1->u.s._32 * src2->u.s._43) + (src1->u.s._42 * src2->u.s._44);
3351
3352 temp.u.s._13 = (src1->u.s._13 * src2->u.s._11) + (src1->u.s._23 * src2->u.s._12) + (src1->u.s._33 * src2->u.s._13) + (src1->u.s._43 * src2->u.s._14);
3353 temp.u.s._23 = (src1->u.s._13 * src2->u.s._21) + (src1->u.s._23 * src2->u.s._22) + (src1->u.s._33 * src2->u.s._23) + (src1->u.s._43 * src2->u.s._24);
3354 temp.u.s._33 = (src1->u.s._13 * src2->u.s._31) + (src1->u.s._23 * src2->u.s._32) + (src1->u.s._33 * src2->u.s._33) + (src1->u.s._43 * src2->u.s._34);
3355 temp.u.s._43 = (src1->u.s._13 * src2->u.s._41) + (src1->u.s._23 * src2->u.s._42) + (src1->u.s._33 * src2->u.s._43) + (src1->u.s._43 * src2->u.s._44);
3356
3357 temp.u.s._14 = (src1->u.s._14 * src2->u.s._11) + (src1->u.s._24 * src2->u.s._12) + (src1->u.s._34 * src2->u.s._13) + (src1->u.s._44 * src2->u.s._14);
3358 temp.u.s._24 = (src1->u.s._14 * src2->u.s._21) + (src1->u.s._24 * src2->u.s._22) + (src1->u.s._34 * src2->u.s._23) + (src1->u.s._44 * src2->u.s._24);
3359 temp.u.s._34 = (src1->u.s._14 * src2->u.s._31) + (src1->u.s._24 * src2->u.s._32) + (src1->u.s._34 * src2->u.s._33) + (src1->u.s._44 * src2->u.s._34);
3360 temp.u.s._44 = (src1->u.s._14 * src2->u.s._41) + (src1->u.s._24 * src2->u.s._42) + (src1->u.s._34 * src2->u.s._43) + (src1->u.s._44 * src2->u.s._44);
3361
3362 /* And copy the new matrix in the good storage.. */
3363 memcpy(dest, &temp, 16 * sizeof(float));
3364 }
3365
3366 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType) {
3367 DWORD size = 0;
3368 int i;
3369 int numTextures = (d3dvtVertexType & WINED3DFVF_TEXCOUNT_MASK) >> WINED3DFVF_TEXCOUNT_SHIFT;
3370
3371 if (d3dvtVertexType & WINED3DFVF_NORMAL) size += 3 * sizeof(float);
3372 if (d3dvtVertexType & WINED3DFVF_DIFFUSE) size += sizeof(DWORD);
3373 if (d3dvtVertexType & WINED3DFVF_SPECULAR) size += sizeof(DWORD);
3374 if (d3dvtVertexType & WINED3DFVF_PSIZE) size += sizeof(DWORD);
3375 switch (d3dvtVertexType & WINED3DFVF_POSITION_MASK) {
3376 case WINED3DFVF_XYZ: size += 3 * sizeof(float); break;
3377 case WINED3DFVF_XYZRHW: size += 4 * sizeof(float); break;
3378 case WINED3DFVF_XYZB1: size += 4 * sizeof(float); break;
3379 case WINED3DFVF_XYZB2: size += 5 * sizeof(float); break;
3380 case WINED3DFVF_XYZB3: size += 6 * sizeof(float); break;
3381 case WINED3DFVF_XYZB4: size += 7 * sizeof(float); break;
3382 case WINED3DFVF_XYZB5: size += 8 * sizeof(float); break;
3383 case WINED3DFVF_XYZW: size += 4 * sizeof(float); break;
3384 default: ERR("Unexpected position mask\n");
3385 }
3386 for (i = 0; i < numTextures; i++) {
3387 size += GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, i) * sizeof(float);
3388 }
3389
3390 return size;
3391 }
3392
3393 void gen_ffp_frag_op(const struct wined3d_context *context, const struct wined3d_state *state,
3394 struct ffp_frag_settings *settings, BOOL ignore_textype)
3395 {
3396 #define ARG1 0x01
3397 #define ARG2 0x02
3398 #define ARG0 0x04
3399 static const unsigned char args[WINED3D_TOP_LERP + 1] =
3400 {
3401 /* undefined */ 0,
3402 /* D3DTOP_DISABLE */ 0,
3403 /* D3DTOP_SELECTARG1 */ ARG1,
3404 /* D3DTOP_SELECTARG2 */ ARG2,
3405 /* D3DTOP_MODULATE */ ARG1 | ARG2,
3406 /* D3DTOP_MODULATE2X */ ARG1 | ARG2,
3407 /* D3DTOP_MODULATE4X */ ARG1 | ARG2,
3408 /* D3DTOP_ADD */ ARG1 | ARG2,
3409 /* D3DTOP_ADDSIGNED */ ARG1 | ARG2,
3410 /* D3DTOP_ADDSIGNED2X */ ARG1 | ARG2,
3411 /* D3DTOP_SUBTRACT */ ARG1 | ARG2,
3412 /* D3DTOP_ADDSMOOTH */ ARG1 | ARG2,
3413 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1 | ARG2,
3414 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1 | ARG2,
3415 /* D3DTOP_BLENDFACTORALPHA */ ARG1 | ARG2,
3416 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1 | ARG2,
3417 /* D3DTOP_BLENDCURRENTALPHA */ ARG1 | ARG2,
3418 /* D3DTOP_PREMODULATE */ ARG1 | ARG2,
3419 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1 | ARG2,
3420 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1 | ARG2,
3421 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1 | ARG2,
3422 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1 | ARG2,
3423 /* D3DTOP_BUMPENVMAP */ ARG1 | ARG2,
3424 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1 | ARG2,
3425 /* D3DTOP_DOTPRODUCT3 */ ARG1 | ARG2,
3426 /* D3DTOP_MULTIPLYADD */ ARG1 | ARG2 | ARG0,
3427 /* D3DTOP_LERP */ ARG1 | ARG2 | ARG0
3428 };
3429 unsigned int i;
3430 DWORD ttff;
3431 DWORD cop, aop, carg0, carg1, carg2, aarg0, aarg1, aarg2;
3432 const struct wined3d_format *rt_format = state->fb->render_targets[0]->format;
3433 const struct wined3d_gl_info *gl_info = context->gl_info;
3434 const struct wined3d_d3d_info *d3d_info = context->d3d_info;
3435
3436 for (i = 0; i < d3d_info->limits.ffp_blend_stages; ++i)
3437 {
3438 const struct wined3d_texture *texture;
3439
3440 settings->op[i].padding = 0;
3441 if (state->texture_states[i][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_DISABLE)
3442 {
3443 settings->op[i].cop = WINED3D_TOP_DISABLE;
3444 settings->op[i].aop = WINED3D_TOP_DISABLE;
3445 settings->op[i].carg0 = settings->op[i].carg1 = settings->op[i].carg2 = ARG_UNUSED;
3446 settings->op[i].aarg0 = settings->op[i].aarg1 = settings->op[i].aarg2 = ARG_UNUSED;
3447 settings->op[i].color_fixup = COLOR_FIXUP_IDENTITY;
3448 settings->op[i].dst = resultreg;
3449 settings->op[i].tex_type = tex_1d;
3450 settings->op[i].projected = proj_none;
3451 i++;
3452 break;
3453 }
3454
3455 if ((texture = state->textures[i]))
3456 {
3457 settings->op[i].color_fixup = texture->resource.format->color_fixup;
3458 if (ignore_textype)
3459 {
3460 settings->op[i].tex_type = tex_1d;
3461 }
3462 else
3463 {
3464 switch (texture->target)
3465 {
3466 case GL_TEXTURE_1D:
3467 settings->op[i].tex_type = tex_1d;
3468 break;
3469 case GL_TEXTURE_2D:
3470 settings->op[i].tex_type = tex_2d;
3471 break;
3472 case GL_TEXTURE_3D:
3473 settings->op[i].tex_type = tex_3d;
3474 break;
3475 case GL_TEXTURE_CUBE_MAP_ARB:
3476 settings->op[i].tex_type = tex_cube;
3477 break;
3478 case GL_TEXTURE_RECTANGLE_ARB:
3479 settings->op[i].tex_type = tex_rect;
3480 break;
3481 }
3482 }
3483 } else {
3484 settings->op[i].color_fixup = COLOR_FIXUP_IDENTITY;
3485 settings->op[i].tex_type = tex_1d;
3486 }
3487
3488 cop = state->texture_states[i][WINED3D_TSS_COLOR_OP];
3489 aop = state->texture_states[i][WINED3D_TSS_ALPHA_OP];
3490
3491 carg1 = (args[cop] & ARG1) ? state->texture_states[i][WINED3D_TSS_COLOR_ARG1] : ARG_UNUSED;
3492 carg2 = (args[cop] & ARG2) ? state->texture_states[i][WINED3D_TSS_COLOR_ARG2] : ARG_UNUSED;
3493 carg0 = (args[cop] & ARG0) ? state->texture_states[i][WINED3D_TSS_COLOR_ARG0] : ARG_UNUSED;
3494
3495 if (is_invalid_op(state, i, cop, carg1, carg2, carg0))
3496 {
3497 carg0 = ARG_UNUSED;
3498 carg2 = ARG_UNUSED;
3499 carg1 = WINED3DTA_CURRENT;
3500 cop = WINED3D_TOP_SELECT_ARG1;
3501 }
3502
3503 if (cop == WINED3D_TOP_DOTPRODUCT3)
3504 {
3505 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
3506 * the color result to the alpha component of the destination
3507 */
3508 aop = cop;
3509 aarg1 = carg1;
3510 aarg2 = carg2;
3511 aarg0 = carg0;
3512 }
3513 else
3514 {
3515 aarg1 = (args[aop] & ARG1) ? state->texture_states[i][WINED3D_TSS_ALPHA_ARG1] : ARG_UNUSED;
3516 aarg2 = (args[aop] & ARG2) ? state->texture_states[i][WINED3D_TSS_ALPHA_ARG2] : ARG_UNUSED;
3517 aarg0 = (args[aop] & ARG0) ? state->texture_states[i][WINED3D_TSS_ALPHA_ARG0] : ARG_UNUSED;
3518 }
3519
3520 if (!i && state->textures[0] && state->render_states[WINED3D_RS_COLORKEYENABLE])
3521 {
3522 GLenum texture_dimensions;
3523
3524 texture = state->textures[0];
3525 texture_dimensions = texture->target;
3526
3527 if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
3528 {
3529 if (texture->color_key_flags & WINED3D_CKEY_SRC_BLT && !texture->resource.format->alpha_size)
3530 {
3531 if (aop == WINED3D_TOP_DISABLE)
3532 {
3533 aarg1 = WINED3DTA_TEXTURE;
3534 aop = WINED3D_TOP_SELECT_ARG1;
3535 }
3536 else if (aop == WINED3D_TOP_SELECT_ARG1 && aarg1 != WINED3DTA_TEXTURE)
3537 {
3538 if (state->render_states[WINED3D_RS_ALPHABLENDENABLE])
3539 {
3540 aarg2 = WINED3DTA_TEXTURE;
3541 aop = WINED3D_TOP_MODULATE;
3542 }
3543 else aarg1 = WINED3DTA_TEXTURE;
3544 }
3545 else if (aop == WINED3D_TOP_SELECT_ARG2 && aarg2 != WINED3DTA_TEXTURE)
3546 {
3547 if (state->render_states[WINED3D_RS_ALPHABLENDENABLE])
3548 {
3549 aarg1 = WINED3DTA_TEXTURE;
3550 aop = WINED3D_TOP_MODULATE;
3551 }
3552 else aarg2 = WINED3DTA_TEXTURE;
3553 }
3554 }
3555 }
3556 }
3557
3558 if (is_invalid_op(state, i, aop, aarg1, aarg2, aarg0))
3559 {
3560 aarg0 = ARG_UNUSED;
3561 aarg2 = ARG_UNUSED;
3562 aarg1 = WINED3DTA_CURRENT;
3563 aop = WINED3D_TOP_SELECT_ARG1;
3564 }
3565
3566 if (carg1 == WINED3DTA_TEXTURE || carg2 == WINED3DTA_TEXTURE || carg0 == WINED3DTA_TEXTURE
3567 || aarg1 == WINED3DTA_TEXTURE || aarg2 == WINED3DTA_TEXTURE || aarg0 == WINED3DTA_TEXTURE)
3568 {
3569 ttff = state->texture_states[i][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS];
3570 if (ttff == (WINED3D_TTFF_PROJECTED | WINED3D_TTFF_COUNT3))
3571 settings->op[i].projected = proj_count3;
3572 else if (ttff & WINED3D_TTFF_PROJECTED)
3573 settings->op[i].projected = proj_count4;
3574 else
3575 settings->op[i].projected = proj_none;
3576 }
3577 else
3578 {
3579 settings->op[i].projected = proj_none;
3580 }
3581
3582 settings->op[i].cop = cop;
3583 settings->op[i].aop = aop;
3584 settings->op[i].carg0 = carg0;
3585 settings->op[i].carg1 = carg1;
3586 settings->op[i].carg2 = carg2;
3587 settings->op[i].aarg0 = aarg0;
3588 settings->op[i].aarg1 = aarg1;
3589 settings->op[i].aarg2 = aarg2;
3590
3591 if (state->texture_states[i][WINED3D_TSS_RESULT_ARG] == WINED3DTA_TEMP)
3592 settings->op[i].dst = tempreg;
3593 else
3594 settings->op[i].dst = resultreg;
3595 }
3596
3597 /* Clear unsupported stages */
3598 for(; i < MAX_TEXTURES; i++) {
3599 memset(&settings->op[i], 0xff, sizeof(settings->op[i]));
3600 }
3601
3602 if (!state->render_states[WINED3D_RS_FOGENABLE])
3603 {
3604 settings->fog = WINED3D_FFP_PS_FOG_OFF;
3605 }
3606 else if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE)
3607 {
3608 if (use_vs(state) || state->vertex_declaration->position_transformed)
3609 {
3610 settings->fog = WINED3D_FFP_PS_FOG_LINEAR;
3611 }
3612 else
3613 {
3614 switch (state->render_states[WINED3D_RS_FOGVERTEXMODE])
3615 {
3616 case WINED3D_FOG_NONE:
3617 case WINED3D_FOG_LINEAR:
3618 settings->fog = WINED3D_FFP_PS_FOG_LINEAR;
3619 break;
3620 case WINED3D_FOG_EXP:
3621 settings->fog = WINED3D_FFP_PS_FOG_EXP;
3622 break;
3623 case WINED3D_FOG_EXP2:
3624 settings->fog = WINED3D_FFP_PS_FOG_EXP2;
3625 break;
3626 }
3627 }
3628 }
3629 else
3630 {
3631 switch (state->render_states[WINED3D_RS_FOGTABLEMODE])
3632 {
3633 case WINED3D_FOG_LINEAR:
3634 settings->fog = WINED3D_FFP_PS_FOG_LINEAR;
3635 break;
3636 case WINED3D_FOG_EXP:
3637 settings->fog = WINED3D_FFP_PS_FOG_EXP;
3638 break;
3639 case WINED3D_FOG_EXP2:
3640 settings->fog = WINED3D_FFP_PS_FOG_EXP2;
3641 break;
3642 }
3643 }
3644 if (!gl_info->supported[ARB_FRAMEBUFFER_SRGB]
3645 && state->render_states[WINED3D_RS_SRGBWRITEENABLE]
3646 && rt_format->flags & WINED3DFMT_FLAG_SRGB_WRITE)
3647 {
3648 settings->sRGB_write = 1;
3649 } else {
3650 settings->sRGB_write = 0;
3651 }
3652 if (d3d_info->vs_clipping || !use_vs(state) || !state->render_states[WINED3D_RS_CLIPPING]
3653 || !state->render_states[WINED3D_RS_CLIPPLANEENABLE])
3654 {
3655 /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
3656 * the fixed function vertex pipeline is used(which always supports clipplanes), or
3657 * if no clipplane is enabled
3658 */
3659 settings->emul_clipplanes = 0;
3660 } else {
3661 settings->emul_clipplanes = 1;
3662 }
3663 }
3664
3665 const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders,
3666 const struct ffp_frag_settings *settings)
3667 {
3668 struct wine_rb_entry *entry = wine_rb_get(fragment_shaders, settings);
3669 return entry ? WINE_RB_ENTRY_VALUE(entry, struct ffp_frag_desc, entry) : NULL;
3670 }
3671
3672 void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc)
3673 {
3674 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
3675 * whereas desc points to an extended structure with implementation specific parts. */
3676 if (wine_rb_put(shaders, &desc->settings, &desc->entry) == -1)
3677 {
3678 ERR("Failed to insert ffp frag shader.\n");
3679 }
3680 }
3681
3682 /* Activates the texture dimension according to the bound D3D texture. Does
3683 * not care for the colorop or correct gl texture unit (when using nvrc).
3684 * Requires the caller to activate the correct unit. */
3685 /* Context activation is done by the caller (state handler). */
3686 void texture_activate_dimensions(const struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info)
3687 {
3688 if (texture)
3689 {
3690 switch (texture->target)
3691 {
3692 case GL_TEXTURE_2D:
3693 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
3694 checkGLcall("glDisable(GL_TEXTURE_3D)");
3695 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3696 {
3697 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
3698 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
3699 }
3700 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
3701 {
3702 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
3703 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
3704 }
3705 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_2D);
3706 checkGLcall("glEnable(GL_TEXTURE_2D)");
3707 break;
3708 case GL_TEXTURE_RECTANGLE_ARB:
3709 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
3710 checkGLcall("glDisable(GL_TEXTURE_2D)");
3711 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
3712 checkGLcall("glDisable(GL_TEXTURE_3D)");
3713 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3714 {
3715 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
3716 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
3717 }
3718 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_RECTANGLE_ARB);
3719 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
3720 break;
3721 case GL_TEXTURE_3D:
3722 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3723 {
3724 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
3725 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
3726 }
3727 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
3728 {
3729 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
3730 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
3731 }
3732 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
3733 checkGLcall("glDisable(GL_TEXTURE_2D)");
3734 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_3D);
3735 checkGLcall("glEnable(GL_TEXTURE_3D)");
3736 break;
3737 case GL_TEXTURE_CUBE_MAP_ARB:
3738 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
3739 checkGLcall("glDisable(GL_TEXTURE_2D)");
3740 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
3741 checkGLcall("glDisable(GL_TEXTURE_3D)");
3742 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
3743 {
3744 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
3745 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
3746 }
3747 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_CUBE_MAP_ARB);
3748 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
3749 break;
3750 }
3751 }
3752 else
3753 {
3754 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_2D);
3755 checkGLcall("glEnable(GL_TEXTURE_2D)");
3756 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
3757 checkGLcall("glDisable(GL_TEXTURE_3D)");
3758 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3759 {
3760 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
3761 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
3762 }
3763 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
3764 {
3765 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
3766 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
3767 }
3768 /* Binding textures is done by samplers. A dummy texture will be bound */
3769 }
3770 }
3771
3772 /* Context activation is done by the caller (state handler). */
3773 void sampler_texdim(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
3774 {
3775 DWORD sampler = state_id - STATE_SAMPLER(0);
3776 DWORD mapped_stage = context->tex_unit_map[sampler];
3777
3778 /* No need to enable / disable anything here for unused samplers. The
3779 * tex_colorop handler takes care. Also no action is needed with pixel
3780 * shaders, or if tex_colorop will take care of this business. */
3781 if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures)
3782 return;
3783 if (sampler >= context->lowest_disabled_stage)
3784 return;
3785 if (isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP)))
3786 return;
3787
3788 texture_activate_dimensions(state->textures[sampler], context->gl_info);
3789 }
3790
3791 void *wined3d_rb_alloc(size_t size)
3792 {
3793 return HeapAlloc(GetProcessHeap(), 0, size);
3794 }
3795
3796 void *wined3d_rb_realloc(void *ptr, size_t size)
3797 {
3798 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
3799 }
3800
3801 void wined3d_rb_free(void *ptr)
3802 {
3803 HeapFree(GetProcessHeap(), 0, ptr);
3804 }
3805
3806 static int ffp_frag_program_key_compare(const void *key, const struct wine_rb_entry *entry)
3807 {
3808 const struct ffp_frag_settings *ka = key;
3809 const struct ffp_frag_settings *kb = &WINE_RB_ENTRY_VALUE(entry, const struct ffp_frag_desc, entry)->settings;
3810
3811 return memcmp(ka, kb, sizeof(*ka));
3812 }
3813
3814 const struct wine_rb_functions wined3d_ffp_frag_program_rb_functions =
3815 {
3816 wined3d_rb_alloc,
3817 wined3d_rb_realloc,
3818 wined3d_rb_free,
3819 ffp_frag_program_key_compare,
3820 };
3821
3822 void wined3d_ffp_get_vs_settings(const struct wined3d_state *state, const struct wined3d_stream_info *si,
3823 struct wined3d_ffp_vs_settings *settings)
3824 {
3825 unsigned int coord_idx, i;
3826
3827 if (si->position_transformed)
3828 {
3829 memset(settings, 0, sizeof(*settings));
3830
3831 settings->transformed = 1;
3832 settings->point_size = state->gl_primitive_type == GL_POINTS;
3833 if (!state->render_states[WINED3D_RS_FOGENABLE])
3834 settings->fog_mode = WINED3D_FFP_VS_FOG_OFF;
3835 else if (state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE)
3836 settings->fog_mode = WINED3D_FFP_VS_FOG_DEPTH;
3837 else
3838 settings->fog_mode = WINED3D_FFP_VS_FOG_FOGCOORD;
3839
3840 for (i = 0; i < MAX_TEXTURES; ++i)
3841 {
3842 coord_idx = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
3843 if (coord_idx < MAX_TEXTURES && (si->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coord_idx))))
3844 settings->texcoords |= 1 << i;
3845 settings->texgen[i] = (state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX] >> WINED3D_FFP_TCI_SHIFT)
3846 & WINED3D_FFP_TCI_MASK;
3847 }
3848 return;
3849 }
3850
3851 settings->transformed = 0;
3852 settings->clipping = state->render_states[WINED3D_RS_CLIPPING]
3853 && state->render_states[WINED3D_RS_CLIPPLANEENABLE];
3854 settings->normal = !!(si->use_map & (1 << WINED3D_FFP_NORMAL));
3855 settings->normalize = settings->normal && state->render_states[WINED3D_RS_NORMALIZENORMALS];
3856 settings->lighting = !!state->render_states[WINED3D_RS_LIGHTING];
3857 settings->localviewer = !!state->render_states[WINED3D_RS_LOCALVIEWER];
3858 settings->point_size = state->gl_primitive_type == GL_POINTS;
3859
3860 if (state->render_states[WINED3D_RS_COLORVERTEX] && (si->use_map & (1 << WINED3D_FFP_DIFFUSE)))
3861 {
3862 settings->diffuse_source = state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE];
3863 settings->emission_source = state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE];
3864 settings->ambient_source = state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE];
3865 settings->specular_source = state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE];
3866 }
3867 else
3868 {
3869 settings->diffuse_source = WINED3D_MCS_MATERIAL;
3870 settings->emission_source = WINED3D_MCS_MATERIAL;
3871 settings->ambient_source = WINED3D_MCS_MATERIAL;
3872 settings->specular_source = WINED3D_MCS_MATERIAL;
3873 }
3874
3875 settings->texcoords = 0;
3876 for (i = 0; i < MAX_TEXTURES; ++i)
3877 {
3878 coord_idx = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
3879 if (coord_idx < MAX_TEXTURES && (si->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coord_idx))))
3880 settings->texcoords |= 1 << i;
3881 settings->texgen[i] = (state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX] >> WINED3D_FFP_TCI_SHIFT)
3882 & WINED3D_FFP_TCI_MASK;
3883 }
3884
3885 settings->light_type = 0;
3886 for (i = 0; i < MAX_ACTIVE_LIGHTS; ++i)
3887 {
3888 if (state->lights[i])
3889 settings->light_type |= (state->lights[i]->OriginalParms.type
3890 & WINED3D_FFP_LIGHT_TYPE_MASK) << WINED3D_FFP_LIGHT_TYPE_SHIFT(i);
3891 }
3892
3893 settings->ortho_fog = 0;
3894 if (!state->render_states[WINED3D_RS_FOGENABLE])
3895 settings->fog_mode = WINED3D_FFP_VS_FOG_OFF;
3896 else if (state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE)
3897 {
3898 settings->fog_mode = WINED3D_FFP_VS_FOG_DEPTH;
3899
3900 if (state->transforms[WINED3D_TS_PROJECTION].u.m[0][3] == 0.0f
3901 && state->transforms[WINED3D_TS_PROJECTION].u.m[1][3] == 0.0f
3902 && state->transforms[WINED3D_TS_PROJECTION].u.m[2][3] == 0.0f
3903 && state->transforms[WINED3D_TS_PROJECTION].u.m[3][3] == 1.0f)
3904 settings->ortho_fog = 1;
3905 }
3906 else if (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE)
3907 settings->fog_mode = WINED3D_FFP_VS_FOG_FOGCOORD;
3908 else if (state->render_states[WINED3D_RS_RANGEFOGENABLE])
3909 settings->fog_mode = WINED3D_FFP_VS_FOG_RANGE;
3910 else
3911 settings->fog_mode = WINED3D_FFP_VS_FOG_DEPTH;
3912
3913 settings->padding = 0;
3914 }
3915
3916 static int wined3d_ffp_vertex_program_key_compare(const void *key, const struct wine_rb_entry *entry)
3917 {
3918 const struct wined3d_ffp_vs_settings *ka = key;
3919 const struct wined3d_ffp_vs_settings *kb = &WINE_RB_ENTRY_VALUE(entry,
3920 const struct wined3d_ffp_vs_desc, entry)->settings;
3921
3922 return memcmp(ka, kb, sizeof(*ka));
3923 }
3924
3925 const struct wine_rb_functions wined3d_ffp_vertex_program_rb_functions =
3926 {
3927 wined3d_rb_alloc,
3928 wined3d_rb_realloc,
3929 wined3d_rb_free,
3930 wined3d_ffp_vertex_program_key_compare,
3931 };
3932
3933 const struct blit_shader *wined3d_select_blitter(const struct wined3d_gl_info *gl_info, enum wined3d_blit_op blit_op,
3934 const RECT *src_rect, DWORD src_usage, enum wined3d_pool src_pool, const struct wined3d_format *src_format,
3935 const RECT *dst_rect, DWORD dst_usage, enum wined3d_pool dst_pool, const struct wined3d_format *dst_format)
3936 {
3937 static const struct blit_shader * const blitters[] =
3938 {
3939 &arbfp_blit,
3940 &ffp_blit,
3941 &cpu_blit,
3942 };
3943 unsigned int i;
3944
3945 for (i = 0; i < sizeof(blitters) / sizeof(*blitters); ++i)
3946 {
3947 if (blitters[i]->blit_supported(gl_info, blit_op,
3948 src_rect, src_usage, src_pool, src_format,
3949 dst_rect, dst_usage, dst_pool, dst_format))
3950 return blitters[i];
3951 }
3952
3953 return NULL;
3954 }
3955
3956 void wined3d_get_draw_rect(const struct wined3d_state *state, RECT *rect)
3957 {
3958 const struct wined3d_viewport *vp = &state->viewport;
3959
3960 SetRect(rect, vp->x, vp->y, vp->x + vp->width, vp->y + vp->height);
3961
3962 if (state->render_states[WINED3D_RS_SCISSORTESTENABLE])
3963 IntersectRect(rect, rect, &state->scissor_rect);
3964 }
3965
3966 const char *wined3d_debug_location(DWORD location)
3967 {
3968 char buf[294];
3969
3970 buf[0] = '\0';
3971 #define LOCATION_TO_STR(u) if (location & u) { strcat(buf, " | "#u); location &= ~u; }
3972 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED);
3973 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM);
3974 LOCATION_TO_STR(WINED3D_LOCATION_USER_MEMORY);
3975 LOCATION_TO_STR(WINED3D_LOCATION_DIB);
3976 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER);
3977 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB);
3978 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB);
3979 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE);
3980 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE);
3981 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED);
3982 #undef LOCATION_TO_STR
3983 if (location) FIXME("Unrecognized location flag(s) %#x.\n", location);
3984
3985 return buf[0] ? wine_dbg_sprintf("%s", &buf[3]) : "0";
3986 }
3987
3988 /* Print a floating point value with the %.8e format specifier, always using
3989 * '.' as decimal separator. */
3990 void wined3d_ftoa(float value, char *s)
3991 {
3992 int idx = 1;
3993
3994 if (copysignf(1.0f, value) < 0.0f)
3995 ++idx;
3996
3997 /* Be sure to allocate a buffer of at least 17 characters for the result
3998 as sprintf may return a 3 digit exponent when using the MSVC runtime
3999 instead of a 2 digit exponent. */
4000 sprintf(s, "%.8e", value);
4001 if (isfinite(value))
4002 s[idx] = '.';
4003 }
4004
4005 void wined3d_release_dc(HWND window, HDC dc)
4006 {
4007 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
4008 * However, that's not what actually happens, and there are user32 tests
4009 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
4010 * So explicitly check that the DC belongs to the window, since we want to
4011 * avoid releasing a DC that belongs to some other window if the original
4012 * window was already destroyed. */
4013 if (WindowFromDC(dc) != window)
4014 WARN("DC %p does not belong to window %p.\n", dc, window);
4015 else if (!ReleaseDC(window, dc))
4016 ERR("Failed to release device context %p, last error %#x.\n", dc, GetLastError());
4017 }