wined3d: Reject raw blits between depth/stencil and colour resources in the GLSL...
[wine.git] / dlls / wined3d / utils.c
blobdc7823b95342f9397f025aeec7a92f35883d5bca
1 /*
2 * Utility functions for the WineD3D Library
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
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.
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.
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
27 #include "config.h"
28 #include "wine/port.h"
30 #include <stdio.h>
32 #include "wined3d_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
36 #define WINED3D_FORMAT_FOURCC_BASE (WINED3DFMT_BC7_UNORM_SRGB + 1)
38 static const struct
40 enum wined3d_format_id id;
41 unsigned int idx;
43 format_index_remap[] =
45 {WINED3DFMT_UYVY, WINED3D_FORMAT_FOURCC_BASE},
46 {WINED3DFMT_YUY2, WINED3D_FORMAT_FOURCC_BASE + 1},
47 {WINED3DFMT_YV12, WINED3D_FORMAT_FOURCC_BASE + 2},
48 {WINED3DFMT_DXT1, WINED3D_FORMAT_FOURCC_BASE + 3},
49 {WINED3DFMT_DXT2, WINED3D_FORMAT_FOURCC_BASE + 4},
50 {WINED3DFMT_DXT3, WINED3D_FORMAT_FOURCC_BASE + 5},
51 {WINED3DFMT_DXT4, WINED3D_FORMAT_FOURCC_BASE + 6},
52 {WINED3DFMT_DXT5, WINED3D_FORMAT_FOURCC_BASE + 7},
53 {WINED3DFMT_MULTI2_ARGB8, WINED3D_FORMAT_FOURCC_BASE + 8},
54 {WINED3DFMT_G8R8_G8B8, WINED3D_FORMAT_FOURCC_BASE + 9},
55 {WINED3DFMT_R8G8_B8G8, WINED3D_FORMAT_FOURCC_BASE + 10},
56 {WINED3DFMT_ATI1N, WINED3D_FORMAT_FOURCC_BASE + 11},
57 {WINED3DFMT_ATI2N, WINED3D_FORMAT_FOURCC_BASE + 12},
58 {WINED3DFMT_INST, WINED3D_FORMAT_FOURCC_BASE + 13},
59 {WINED3DFMT_NVDB, WINED3D_FORMAT_FOURCC_BASE + 14},
60 {WINED3DFMT_NVHU, WINED3D_FORMAT_FOURCC_BASE + 15},
61 {WINED3DFMT_NVHS, WINED3D_FORMAT_FOURCC_BASE + 16},
62 {WINED3DFMT_INTZ, WINED3D_FORMAT_FOURCC_BASE + 17},
63 {WINED3DFMT_RESZ, WINED3D_FORMAT_FOURCC_BASE + 18},
64 {WINED3DFMT_NULL, WINED3D_FORMAT_FOURCC_BASE + 19},
65 {WINED3DFMT_R16, WINED3D_FORMAT_FOURCC_BASE + 20},
66 {WINED3DFMT_AL16, WINED3D_FORMAT_FOURCC_BASE + 21},
67 {WINED3DFMT_NV12, WINED3D_FORMAT_FOURCC_BASE + 22},
68 {WINED3DFMT_ATOC, WINED3D_FORMAT_FOURCC_BASE + 23},
71 #define WINED3D_FORMAT_COUNT (WINED3D_FORMAT_FOURCC_BASE + ARRAY_SIZE(format_index_remap))
73 struct wined3d_format_channels
75 enum wined3d_format_id id;
76 DWORD red_size, green_size, blue_size, alpha_size;
77 DWORD red_offset, green_offset, blue_offset, alpha_offset;
78 UINT bpp;
79 BYTE depth_size, stencil_size;
82 static const struct wined3d_format_channels formats[] =
84 /* size offset
85 * format id r g b a r g b a bpp depth stencil */
86 {WINED3DFMT_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
87 /* FourCC formats */
88 {WINED3DFMT_UYVY, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
89 {WINED3DFMT_YUY2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
90 {WINED3DFMT_YV12, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
91 {WINED3DFMT_NV12, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
92 {WINED3DFMT_DXT1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
93 {WINED3DFMT_DXT2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
94 {WINED3DFMT_DXT3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
95 {WINED3DFMT_DXT4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
96 {WINED3DFMT_DXT5, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
97 {WINED3DFMT_MULTI2_ARGB8, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
98 {WINED3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
99 {WINED3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
100 /* Hmm? */
101 {WINED3DFMT_R8G8_SNORM_Cx, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
102 {WINED3DFMT_R11G11B10_FLOAT, 11, 11, 10, 0, 0, 11, 22, 0, 4, 0, 0},
103 /* Palettized formats */
104 {WINED3DFMT_P8_UINT_A8_UNORM, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
105 {WINED3DFMT_P8_UINT, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
106 /* Standard ARGB formats. */
107 {WINED3DFMT_B8G8R8_UNORM, 8, 8, 8, 0, 16, 8, 0, 0, 3, 0, 0},
108 {WINED3DFMT_B5G6R5_UNORM, 5, 6, 5, 0, 11, 5, 0, 0, 2, 0, 0},
109 {WINED3DFMT_B5G5R5X1_UNORM, 5, 5, 5, 0, 10, 5, 0, 0, 2, 0, 0},
110 {WINED3DFMT_B5G5R5A1_UNORM, 5, 5, 5, 1, 10, 5, 0, 15, 2, 0, 0},
111 {WINED3DFMT_B4G4R4A4_UNORM, 4, 4, 4, 4, 8, 4, 0, 12, 2, 0, 0},
112 {WINED3DFMT_B2G3R3_UNORM, 3, 3, 2, 0, 5, 2, 0, 0, 1, 0, 0},
113 {WINED3DFMT_A8_UNORM, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0},
114 {WINED3DFMT_B2G3R3A8_UNORM, 3, 3, 2, 8, 5, 2, 0, 8, 2, 0, 0},
115 {WINED3DFMT_B4G4R4X4_UNORM, 4, 4, 4, 0, 8, 4, 0, 0, 2, 0, 0},
116 {WINED3DFMT_R8G8B8X8_UNORM, 8, 8, 8, 0, 0, 8, 16, 0, 4, 0, 0},
117 {WINED3DFMT_B10G10R10A2_UNORM, 10, 10, 10, 2, 20, 10, 0, 30, 4, 0, 0},
118 /* Luminance */
119 {WINED3DFMT_L8_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
120 {WINED3DFMT_L8A8_UNORM, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
121 {WINED3DFMT_L4A4_UNORM, 0, 0, 0, 4, 0, 0, 0, 4, 1, 0, 0},
122 {WINED3DFMT_L16_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
123 /* Bump mapping stuff */
124 {WINED3DFMT_R5G5_SNORM_L6_UNORM, 5, 5, 0, 0, 0, 5, 0, 0, 2, 0, 0},
125 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, 8, 8, 0, 0, 0, 8, 0, 0, 4, 0, 0},
126 {WINED3DFMT_R10G11B11_SNORM, 10, 11, 11, 0, 0, 10, 21, 0, 4, 0, 0},
127 {WINED3DFMT_R10G10B10_SNORM_A2_UNORM, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
128 /* Depth stencil formats */
129 {WINED3DFMT_D16_LOCKABLE, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
130 {WINED3DFMT_D32_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
131 {WINED3DFMT_S1_UINT_D15_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 2, 15, 1},
132 {WINED3DFMT_X8D24_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 0},
133 {WINED3DFMT_S4X4_UINT_D24_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 4},
134 {WINED3DFMT_S8_UINT_D24_FLOAT, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
135 /* Vendor-specific formats */
136 {WINED3DFMT_ATI1N, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
137 {WINED3DFMT_ATI2N, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
138 {WINED3DFMT_NVDB, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
139 {WINED3DFMT_ATOC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
140 {WINED3DFMT_INST, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
141 {WINED3DFMT_INTZ, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
142 {WINED3DFMT_RESZ, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
143 {WINED3DFMT_NVHU, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
144 {WINED3DFMT_NVHS, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
145 {WINED3DFMT_NULL, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
146 /* Unsure about them, could not find a Windows driver that supports them */
147 {WINED3DFMT_R16, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
148 {WINED3DFMT_AL16, 0, 0, 0, 16, 0, 0, 0, 16, 4, 0, 0},
149 /* DirectX 10 HDR formats */
150 {WINED3DFMT_R9G9B9E5_SHAREDEXP, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
151 /* Typeless */
152 {WINED3DFMT_R32G32B32A32_TYPELESS, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
153 {WINED3DFMT_R32G32B32_TYPELESS, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
154 {WINED3DFMT_R16G16B16A16_TYPELESS, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
155 {WINED3DFMT_R32G32_TYPELESS, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
156 {WINED3DFMT_R32G8X24_TYPELESS, 32, 8, 0, 0, 0, 0, 0, 0, 8, 0, 0},
157 {WINED3DFMT_R10G10B10A2_TYPELESS, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
158 {WINED3DFMT_R10G10B10X2_TYPELESS, 10, 10, 10, 0, 0, 10, 20, 0, 4, 0, 0},
159 {WINED3DFMT_R8G8B8A8_TYPELESS, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
160 {WINED3DFMT_R16G16_TYPELESS, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
161 {WINED3DFMT_R32_TYPELESS, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
162 {WINED3DFMT_R24G8_TYPELESS, 24, 8, 0, 0, 0, 0, 0, 0, 4, 0, 0},
163 {WINED3DFMT_R8G8_TYPELESS, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
164 {WINED3DFMT_R16_TYPELESS, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
165 {WINED3DFMT_R8_TYPELESS, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
166 {WINED3DFMT_BC1_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
167 {WINED3DFMT_BC2_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
168 {WINED3DFMT_BC3_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
169 {WINED3DFMT_BC4_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
170 {WINED3DFMT_BC5_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
171 {WINED3DFMT_BC6H_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
172 {WINED3DFMT_BC7_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
173 {WINED3DFMT_B8G8R8A8_TYPELESS, 8, 8, 8, 8, 16, 8, 0, 24, 4, 0, 0},
174 {WINED3DFMT_B8G8R8X8_TYPELESS, 8, 8, 8, 0, 16, 8, 0, 0, 4, 0, 0},
177 enum wined3d_channel_type
179 WINED3D_CHANNEL_TYPE_NONE,
180 WINED3D_CHANNEL_TYPE_UNORM,
181 WINED3D_CHANNEL_TYPE_SNORM,
182 WINED3D_CHANNEL_TYPE_UINT,
183 WINED3D_CHANNEL_TYPE_SINT,
184 WINED3D_CHANNEL_TYPE_FLOAT,
185 WINED3D_CHANNEL_TYPE_DEPTH,
186 WINED3D_CHANNEL_TYPE_STENCIL,
187 WINED3D_CHANNEL_TYPE_UNUSED,
190 struct wined3d_typed_format_info
192 enum wined3d_format_id id;
193 enum wined3d_format_id typeless_id;
194 const char *channels;
198 * The last entry for a given typeless format defines its internal format.
200 * u - WINED3D_CHANNEL_TYPE_UNORM
201 * i - WINED3D_CHANNEL_TYPE_SNORM
202 * U - WINED3D_CHANNEL_TYPE_UINT
203 * I - WINED3D_CHANNEL_TYPE_SINT
204 * F - WINED3D_CHANNEL_TYPE_FLOAT
205 * D - WINED3D_CHANNEL_TYPE_DEPTH
206 * S - WINED3D_CHANNEL_TYPE_STENCIL
207 * X - WINED3D_CHANNEL_TYPE_UNUSED
209 static const struct wined3d_typed_format_info typed_formats[] =
211 {WINED3DFMT_R32G32B32A32_UINT, WINED3DFMT_R32G32B32A32_TYPELESS, "UUUU"},
212 {WINED3DFMT_R32G32B32A32_SINT, WINED3DFMT_R32G32B32A32_TYPELESS, "IIII"},
213 {WINED3DFMT_R32G32B32A32_FLOAT, WINED3DFMT_R32G32B32A32_TYPELESS, "FFFF"},
214 {WINED3DFMT_R32G32B32_UINT, WINED3DFMT_R32G32B32_TYPELESS, "UUU"},
215 {WINED3DFMT_R32G32B32_SINT, WINED3DFMT_R32G32B32_TYPELESS, "III"},
216 {WINED3DFMT_R32G32B32_FLOAT, WINED3DFMT_R32G32B32_TYPELESS, "FFF"},
217 {WINED3DFMT_R16G16B16A16_UNORM, WINED3DFMT_R16G16B16A16_TYPELESS, "uuuu"},
218 {WINED3DFMT_R16G16B16A16_SNORM, WINED3DFMT_R16G16B16A16_TYPELESS, "iiii"},
219 {WINED3DFMT_R16G16B16A16_UINT, WINED3DFMT_R16G16B16A16_TYPELESS, "UUUU"},
220 {WINED3DFMT_R16G16B16A16_SINT, WINED3DFMT_R16G16B16A16_TYPELESS, "IIII"},
221 {WINED3DFMT_R16G16B16A16_FLOAT, WINED3DFMT_R16G16B16A16_TYPELESS, "FFFF"},
222 {WINED3DFMT_R32G32_UINT, WINED3DFMT_R32G32_TYPELESS, "UU"},
223 {WINED3DFMT_R32G32_SINT, WINED3DFMT_R32G32_TYPELESS, "II"},
224 {WINED3DFMT_R32G32_FLOAT, WINED3DFMT_R32G32_TYPELESS, "FF"},
225 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS, WINED3DFMT_R32G8X24_TYPELESS, "FXX"},
226 {WINED3DFMT_X32_TYPELESS_G8X24_UINT, WINED3DFMT_R32G8X24_TYPELESS, "XUX"},
227 {WINED3DFMT_D32_FLOAT_S8X24_UINT, WINED3DFMT_R32G8X24_TYPELESS, "DSX"},
228 {WINED3DFMT_R10G10B10A2_SNORM, WINED3DFMT_R10G10B10A2_TYPELESS, "iiii"},
229 {WINED3DFMT_R10G10B10A2_UINT, WINED3DFMT_R10G10B10A2_TYPELESS, "UUUU"},
230 {WINED3DFMT_R10G10B10A2_UNORM, WINED3DFMT_R10G10B10A2_TYPELESS, "uuuu"},
231 {WINED3DFMT_R10G10B10X2_SNORM, WINED3DFMT_R10G10B10X2_TYPELESS, "iiiX"},
232 {WINED3DFMT_R10G10B10X2_UINT, WINED3DFMT_R10G10B10X2_TYPELESS, "UUUX"},
233 {WINED3DFMT_R8G8B8A8_UINT, WINED3DFMT_R8G8B8A8_TYPELESS, "UUUU"},
234 {WINED3DFMT_R8G8B8A8_SINT, WINED3DFMT_R8G8B8A8_TYPELESS, "IIII"},
235 {WINED3DFMT_R8G8B8A8_SNORM, WINED3DFMT_R8G8B8A8_TYPELESS, "iiii"},
236 {WINED3DFMT_R8G8B8A8_UNORM_SRGB, WINED3DFMT_R8G8B8A8_TYPELESS, "uuuu"},
237 {WINED3DFMT_R8G8B8A8_UNORM, WINED3DFMT_R8G8B8A8_TYPELESS, "uuuu"},
238 {WINED3DFMT_R16G16_UNORM, WINED3DFMT_R16G16_TYPELESS, "uu"},
239 {WINED3DFMT_R16G16_SNORM, WINED3DFMT_R16G16_TYPELESS, "ii"},
240 {WINED3DFMT_R16G16_UINT, WINED3DFMT_R16G16_TYPELESS, "UU"},
241 {WINED3DFMT_R16G16_SINT, WINED3DFMT_R16G16_TYPELESS, "II"},
242 {WINED3DFMT_R16G16_FLOAT, WINED3DFMT_R16G16_TYPELESS, "FF"},
243 {WINED3DFMT_D32_FLOAT, WINED3DFMT_R32_TYPELESS, "D"},
244 {WINED3DFMT_R32_FLOAT, WINED3DFMT_R32_TYPELESS, "F"},
245 {WINED3DFMT_R32_UINT, WINED3DFMT_R32_TYPELESS, "U"},
246 {WINED3DFMT_R32_SINT, WINED3DFMT_R32_TYPELESS, "I"},
247 {WINED3DFMT_R24_UNORM_X8_TYPELESS, WINED3DFMT_R24G8_TYPELESS, "uX"},
248 {WINED3DFMT_X24_TYPELESS_G8_UINT, WINED3DFMT_R24G8_TYPELESS, "XU"},
249 {WINED3DFMT_D24_UNORM_S8_UINT, WINED3DFMT_R24G8_TYPELESS, "DS"},
250 {WINED3DFMT_R8G8_SNORM, WINED3DFMT_R8G8_TYPELESS, "ii"},
251 {WINED3DFMT_R8G8_UNORM, WINED3DFMT_R8G8_TYPELESS, "uu"},
252 {WINED3DFMT_R8G8_UINT, WINED3DFMT_R8G8_TYPELESS, "UU"},
253 {WINED3DFMT_R8G8_SINT, WINED3DFMT_R8G8_TYPELESS, "II"},
254 {WINED3DFMT_D16_UNORM, WINED3DFMT_R16_TYPELESS, "D"},
255 {WINED3DFMT_R16_UNORM, WINED3DFMT_R16_TYPELESS, "u"},
256 {WINED3DFMT_R16_SNORM, WINED3DFMT_R16_TYPELESS, "i"},
257 {WINED3DFMT_R16_UINT, WINED3DFMT_R16_TYPELESS, "U"},
258 {WINED3DFMT_R16_SINT, WINED3DFMT_R16_TYPELESS, "I"},
259 {WINED3DFMT_R16_FLOAT, WINED3DFMT_R16_TYPELESS, "F"},
260 {WINED3DFMT_R8_UNORM, WINED3DFMT_R8_TYPELESS, "u"},
261 {WINED3DFMT_R8_SNORM, WINED3DFMT_R8_TYPELESS, "i"},
262 {WINED3DFMT_R8_UINT, WINED3DFMT_R8_TYPELESS, "U"},
263 {WINED3DFMT_R8_SINT, WINED3DFMT_R8_TYPELESS, "I"},
264 {WINED3DFMT_BC1_UNORM_SRGB, WINED3DFMT_BC1_TYPELESS, ""},
265 {WINED3DFMT_BC1_UNORM, WINED3DFMT_BC1_TYPELESS, ""},
266 {WINED3DFMT_BC2_UNORM_SRGB, WINED3DFMT_BC2_TYPELESS, ""},
267 {WINED3DFMT_BC2_UNORM, WINED3DFMT_BC2_TYPELESS, ""},
268 {WINED3DFMT_BC3_UNORM_SRGB, WINED3DFMT_BC3_TYPELESS, ""},
269 {WINED3DFMT_BC3_UNORM, WINED3DFMT_BC3_TYPELESS, ""},
270 {WINED3DFMT_BC4_UNORM, WINED3DFMT_BC4_TYPELESS, ""},
271 {WINED3DFMT_BC4_SNORM, WINED3DFMT_BC4_TYPELESS, ""},
272 {WINED3DFMT_BC5_UNORM, WINED3DFMT_BC5_TYPELESS, ""},
273 {WINED3DFMT_BC5_SNORM, WINED3DFMT_BC5_TYPELESS, ""},
274 {WINED3DFMT_BC6H_UF16, WINED3DFMT_BC6H_TYPELESS, ""},
275 {WINED3DFMT_BC6H_SF16, WINED3DFMT_BC6H_TYPELESS, ""},
276 {WINED3DFMT_BC7_UNORM_SRGB, WINED3DFMT_BC7_TYPELESS, ""},
277 {WINED3DFMT_BC7_UNORM, WINED3DFMT_BC7_TYPELESS, ""},
278 {WINED3DFMT_B8G8R8A8_UNORM_SRGB, WINED3DFMT_B8G8R8A8_TYPELESS, "uuuu"},
279 {WINED3DFMT_B8G8R8A8_UNORM, WINED3DFMT_B8G8R8A8_TYPELESS, "uuuu"},
280 {WINED3DFMT_B8G8R8X8_UNORM_SRGB, WINED3DFMT_B8G8R8X8_TYPELESS, "uuuX"},
281 {WINED3DFMT_B8G8R8X8_UNORM, WINED3DFMT_B8G8R8X8_TYPELESS, "uuuX"},
284 struct wined3d_typeless_format_depth_stencil_info
286 enum wined3d_format_id typeless_id;
287 enum wined3d_format_id depth_stencil_id;
288 enum wined3d_format_id depth_view_id;
289 enum wined3d_format_id stencil_view_id;
290 BOOL separate_depth_view_format;
293 static const struct wined3d_typeless_format_depth_stencil_info typeless_depth_stencil_formats[] =
295 {WINED3DFMT_R32G8X24_TYPELESS, WINED3DFMT_D32_FLOAT_S8X24_UINT,
296 WINED3DFMT_R32_FLOAT_X8X24_TYPELESS, WINED3DFMT_X32_TYPELESS_G8X24_UINT, TRUE},
297 {WINED3DFMT_R24G8_TYPELESS, WINED3DFMT_D24_UNORM_S8_UINT,
298 WINED3DFMT_R24_UNORM_X8_TYPELESS, WINED3DFMT_X24_TYPELESS_G8_UINT, TRUE},
299 {WINED3DFMT_R32_TYPELESS, WINED3DFMT_D32_FLOAT, WINED3DFMT_R32_FLOAT},
300 {WINED3DFMT_R16_TYPELESS, WINED3DFMT_D16_UNORM, WINED3DFMT_R16_UNORM},
303 struct wined3d_format_ddi_info
305 enum wined3d_format_id id;
306 D3DDDIFORMAT ddi_format;
309 static const struct wined3d_format_ddi_info ddi_formats[] =
311 {WINED3DFMT_B8G8R8_UNORM, D3DDDIFMT_R8G8B8},
312 {WINED3DFMT_B8G8R8A8_UNORM, D3DDDIFMT_A8R8G8B8},
313 {WINED3DFMT_B8G8R8X8_UNORM, D3DDDIFMT_X8R8G8B8},
314 {WINED3DFMT_B5G6R5_UNORM, D3DDDIFMT_R5G6B5},
315 {WINED3DFMT_B5G5R5X1_UNORM, D3DDDIFMT_X1R5G5B5},
316 {WINED3DFMT_B5G5R5A1_UNORM, D3DDDIFMT_A1R5G5B5},
317 {WINED3DFMT_B4G4R4A4_UNORM, D3DDDIFMT_A4R4G4B4},
318 {WINED3DFMT_B4G4R4X4_UNORM, D3DDDIFMT_X4R4G4B4},
319 {WINED3DFMT_P8_UINT, D3DDDIFMT_P8},
322 struct wined3d_format_base_flags
324 enum wined3d_format_id id;
325 DWORD flags;
328 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
329 * still needs to use the correct block based calculation for e.g. the
330 * resource size. */
331 static const struct wined3d_format_base_flags format_base_flags[] =
333 {WINED3DFMT_ATI1N, WINED3DFMT_FLAG_MAPPABLE | WINED3DFMT_FLAG_BROKEN_PITCH},
334 {WINED3DFMT_ATI2N, WINED3DFMT_FLAG_MAPPABLE | WINED3DFMT_FLAG_BROKEN_PITCH},
335 {WINED3DFMT_D16_LOCKABLE, WINED3DFMT_FLAG_MAPPABLE},
336 {WINED3DFMT_INTZ, WINED3DFMT_FLAG_MAPPABLE},
337 {WINED3DFMT_R11G11B10_FLOAT, WINED3DFMT_FLAG_FLOAT},
338 {WINED3DFMT_D32_FLOAT, WINED3DFMT_FLAG_FLOAT},
339 {WINED3DFMT_S8_UINT_D24_FLOAT, WINED3DFMT_FLAG_FLOAT},
340 {WINED3DFMT_D32_FLOAT_S8X24_UINT, WINED3DFMT_FLAG_FLOAT},
341 {WINED3DFMT_INST, WINED3DFMT_FLAG_EXTENSION},
342 {WINED3DFMT_NULL, WINED3DFMT_FLAG_EXTENSION},
343 {WINED3DFMT_NVDB, WINED3DFMT_FLAG_EXTENSION},
344 {WINED3DFMT_ATOC, WINED3DFMT_FLAG_EXTENSION},
345 {WINED3DFMT_RESZ, WINED3DFMT_FLAG_EXTENSION},
346 {WINED3DFMT_R32G32B32A32_TYPELESS, WINED3DFMT_FLAG_CAST_TO_BLOCK},
347 {WINED3DFMT_R32G32B32A32_FLOAT, WINED3DFMT_FLAG_CAST_TO_BLOCK},
348 {WINED3DFMT_R32G32B32A32_UINT, WINED3DFMT_FLAG_CAST_TO_BLOCK},
349 {WINED3DFMT_R32G32B32A32_SINT, WINED3DFMT_FLAG_CAST_TO_BLOCK},
350 {WINED3DFMT_R16G16B16A16_TYPELESS, WINED3DFMT_FLAG_CAST_TO_BLOCK},
351 {WINED3DFMT_R16G16B16A16_FLOAT, WINED3DFMT_FLAG_CAST_TO_BLOCK},
352 {WINED3DFMT_R16G16B16A16_UNORM, WINED3DFMT_FLAG_CAST_TO_BLOCK},
353 {WINED3DFMT_R16G16B16A16_UINT, WINED3DFMT_FLAG_CAST_TO_BLOCK},
354 {WINED3DFMT_R16G16B16A16_SNORM, WINED3DFMT_FLAG_CAST_TO_BLOCK},
355 {WINED3DFMT_R16G16B16A16_SINT, WINED3DFMT_FLAG_CAST_TO_BLOCK},
356 {WINED3DFMT_R32G32_TYPELESS, WINED3DFMT_FLAG_CAST_TO_BLOCK},
357 {WINED3DFMT_R32G32_FLOAT, WINED3DFMT_FLAG_CAST_TO_BLOCK},
358 {WINED3DFMT_R32G32_UINT, WINED3DFMT_FLAG_CAST_TO_BLOCK},
359 {WINED3DFMT_R32G32_SINT, WINED3DFMT_FLAG_CAST_TO_BLOCK},
360 {WINED3DFMT_R32_TYPELESS, WINED3DFMT_FLAG_CAST_TO_BLOCK},
361 {WINED3DFMT_R32_FLOAT, WINED3DFMT_FLAG_CAST_TO_BLOCK},
362 {WINED3DFMT_R32_UINT, WINED3DFMT_FLAG_CAST_TO_BLOCK},
363 {WINED3DFMT_R32_SINT, WINED3DFMT_FLAG_CAST_TO_BLOCK},
366 static void rgb888_from_rgb565(WORD rgb565, BYTE *r, BYTE *g, BYTE *b)
368 BYTE c;
370 /* (2⁸ - 1) / (2⁵ - 1) ≈ 2⁸ / 2⁵ + 2⁸ / 2¹⁰
371 * (2⁸ - 1) / (2⁶ - 1) ≈ 2⁸ / 2⁶ + 2⁸ / 2¹² */
372 c = rgb565 >> 11;
373 *r = (c << 3) + (c >> 2);
374 c = (rgb565 >> 5) & 0x3f;
375 *g = (c << 2) + (c >> 4);
376 c = rgb565 & 0x1f;
377 *b = (c << 3) + (c >> 2);
380 static void build_dxtn_colour_table(WORD colour0, WORD colour1,
381 DWORD colour_table[4], enum wined3d_format_id format_id)
383 unsigned int i;
384 struct
386 BYTE r, g, b;
387 } c[4];
389 rgb888_from_rgb565(colour0, &c[0].r, &c[0].g, &c[0].b);
390 rgb888_from_rgb565(colour1, &c[1].r, &c[1].g, &c[1].b);
392 if (format_id == WINED3DFMT_BC1_UNORM && colour0 <= colour1)
394 c[2].r = (c[0].r + c[1].r) / 2;
395 c[2].g = (c[0].g + c[1].g) / 2;
396 c[2].b = (c[0].b + c[1].b) / 2;
398 c[3].r = 0;
399 c[3].g = 0;
400 c[3].b = 0;
402 else
404 for (i = 0; i < 2; ++i)
406 c[i + 2].r = (2 * c[i].r + c[1 - i].r) / 3;
407 c[i + 2].g = (2 * c[i].g + c[1 - i].g) / 3;
408 c[i + 2].b = (2 * c[i].b + c[1 - i].b) / 3;
412 for (i = 0; i < 4; ++i)
414 colour_table[i] = (c[i].r << 16) | (c[i].g << 8) | c[i].b;
418 static void build_bc3_alpha_table(BYTE alpha0, BYTE alpha1, BYTE alpha_table[8])
420 unsigned int i;
422 alpha_table[0] = alpha0;
423 alpha_table[1] = alpha1;
425 if (alpha0 > alpha1)
427 for (i = 0; i < 6; ++i)
429 alpha_table[2 + i] = ((6 - i) * alpha0 + (i + 1) * alpha1) / 7;
431 return;
433 else
435 for (i = 0; i < 4; ++i)
437 alpha_table[2 + i] = ((4 - i) * alpha0 + (i + 1) * alpha1) / 5;
439 alpha_table[6] = 0x00;
440 alpha_table[7] = 0xff;
444 static void decompress_dxtn_block(const BYTE *src, BYTE *dst, unsigned int width,
445 unsigned int height, unsigned int dst_row_pitch, enum wined3d_format_id format_id)
447 const UINT64 *s = (const UINT64 *)src;
448 BOOL bc1_alpha = FALSE;
449 DWORD colour_table[4];
450 BYTE alpha_table[8];
451 UINT64 alpha_bits;
452 DWORD colour_bits;
453 unsigned int x, y;
454 BYTE colour_idx;
455 DWORD *dst_row;
456 BYTE alpha;
458 if (format_id == WINED3DFMT_BC1_UNORM)
460 WORD colour0, colour1;
462 alpha_bits = 0;
464 colour0 = s[0] & 0xffff;
465 colour1 = (s[0] >> 16) & 0xffff;
466 colour_bits = (s[0] >> 32) & 0xffffffff;
467 build_dxtn_colour_table(colour0, colour1, colour_table, format_id);
468 if (colour0 <= colour1)
469 bc1_alpha = TRUE;
471 else
473 alpha_bits = s[0];
474 if (format_id == WINED3DFMT_BC3_UNORM)
476 build_bc3_alpha_table(alpha_bits & 0xff, (alpha_bits >> 8) & 0xff, alpha_table);
477 alpha_bits >>= 16;
480 colour_bits = (s[1] >> 32) & 0xffffffff;
481 build_dxtn_colour_table(s[1] & 0xffff, (s[1] >> 16) & 0xffff, colour_table, format_id);
484 for (y = 0; y < height; ++y)
486 dst_row = (DWORD *)&dst[y * dst_row_pitch];
487 for (x = 0; x < width; ++x)
489 colour_idx = (colour_bits >> (y * 8 + x * 2)) & 0x3;
490 switch (format_id)
492 case WINED3DFMT_BC1_UNORM:
493 alpha = bc1_alpha && colour_idx == 3 ? 0x00 : 0xff;
494 break;
496 case WINED3DFMT_BC2_UNORM:
497 alpha = (alpha_bits >> (y * 16 + x * 4)) & 0xf;
498 /* (2⁸ - 1) / (2⁴ - 1) ≈ 2⁸ / 2⁴ + 2⁸ / 2⁸ */
499 alpha |= alpha << 4;
500 break;
502 case WINED3DFMT_BC3_UNORM:
503 alpha = alpha_table[(alpha_bits >> (y * 12 + x * 3)) & 0x7];
504 break;
506 default:
507 alpha = 0xff;
508 break;
510 dst_row[x] = (alpha << 24) | colour_table[colour_idx];
515 static void decompress_dxtn(const BYTE *src, BYTE *dst, unsigned int src_row_pitch,
516 unsigned int src_slice_pitch, unsigned int dst_row_pitch, unsigned int dst_slice_pitch,
517 unsigned int width, unsigned int height, unsigned int depth, enum wined3d_format_id format_id)
519 unsigned int block_byte_count, block_w, block_h;
520 const BYTE *src_row, *src_slice = src;
521 BYTE *dst_row, *dst_slice = dst;
522 unsigned int x, y, z;
524 block_byte_count = format_id == WINED3DFMT_BC1_UNORM ? 8 : 16;
526 for (z = 0; z < depth; ++z)
528 src_row = src_slice;
529 dst_row = dst_slice;
530 for (y = 0; y < height; y += 4)
532 for (x = 0; x < width; x += 4)
534 block_w = min(width - x, 4);
535 block_h = min(height - y, 4);
536 decompress_dxtn_block(&src_row[x * (block_byte_count / 4)],
537 &dst_row[x * 4], block_w, block_h, dst_row_pitch, format_id);
539 src_row += src_row_pitch;
540 dst_row += dst_row_pitch * 4;
542 src_slice += src_slice_pitch;
543 dst_slice += dst_slice_pitch;
547 static void decompress_bc3(const BYTE *src, BYTE *dst, unsigned int src_row_pitch,
548 unsigned int src_slice_pitch, unsigned int dst_row_pitch, unsigned int dst_slice_pitch,
549 unsigned int width, unsigned int height, unsigned int depth)
551 decompress_dxtn(src, dst, src_row_pitch, src_slice_pitch, dst_row_pitch,
552 dst_slice_pitch, width, height, depth, WINED3DFMT_BC3_UNORM);
555 static void decompress_bc2(const BYTE *src, BYTE *dst, unsigned int src_row_pitch,
556 unsigned int src_slice_pitch, unsigned int dst_row_pitch, unsigned int dst_slice_pitch,
557 unsigned int width, unsigned int height, unsigned int depth)
559 decompress_dxtn(src, dst, src_row_pitch, src_slice_pitch, dst_row_pitch,
560 dst_slice_pitch, width, height, depth, WINED3DFMT_BC2_UNORM);
563 static void decompress_bc1(const BYTE *src, BYTE *dst, unsigned int src_row_pitch,
564 unsigned int src_slice_pitch, unsigned int dst_row_pitch, unsigned int dst_slice_pitch,
565 unsigned int width, unsigned int height, unsigned int depth)
567 decompress_dxtn(src, dst, src_row_pitch, src_slice_pitch, dst_row_pitch,
568 dst_slice_pitch, width, height, depth, WINED3DFMT_BC1_UNORM);
571 static const struct wined3d_format_decompress_info
573 enum wined3d_format_id id;
574 void (*decompress)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
575 unsigned int dst_row_pitch, unsigned int dst_slice_pitch,
576 unsigned int width, unsigned int height, unsigned int depth);
578 format_decompress_info[] =
580 {WINED3DFMT_DXT1, decompress_bc1},
581 {WINED3DFMT_DXT2, decompress_bc2},
582 {WINED3DFMT_DXT3, decompress_bc2},
583 {WINED3DFMT_DXT4, decompress_bc3},
584 {WINED3DFMT_DXT5, decompress_bc3},
585 {WINED3DFMT_BC1_UNORM, decompress_bc1},
586 {WINED3DFMT_BC2_UNORM, decompress_bc2},
587 {WINED3DFMT_BC3_UNORM, decompress_bc3},
590 struct wined3d_format_block_info
592 enum wined3d_format_id id;
593 UINT block_width;
594 UINT block_height;
595 UINT block_byte_count;
596 unsigned int flags;
599 static const struct wined3d_format_block_info format_block_info[] =
601 {WINED3DFMT_DXT1, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED},
602 {WINED3DFMT_DXT2, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED},
603 {WINED3DFMT_DXT3, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED},
604 {WINED3DFMT_DXT4, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED},
605 {WINED3DFMT_DXT5, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED},
606 {WINED3DFMT_BC1_UNORM, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED},
607 {WINED3DFMT_BC2_UNORM, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED},
608 {WINED3DFMT_BC3_UNORM, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED},
609 {WINED3DFMT_BC4_UNORM, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED},
610 {WINED3DFMT_BC4_SNORM, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED},
611 {WINED3DFMT_BC5_UNORM, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED},
612 {WINED3DFMT_BC5_SNORM, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED},
613 {WINED3DFMT_BC6H_UF16, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED},
614 {WINED3DFMT_BC6H_SF16, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED},
615 {WINED3DFMT_BC7_UNORM, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED},
616 {WINED3DFMT_ATI1N, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED | WINED3DFMT_FLAG_BLOCKS_NO_VERIFY},
617 {WINED3DFMT_ATI2N, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED | WINED3DFMT_FLAG_BLOCKS_NO_VERIFY},
618 {WINED3DFMT_YUY2, 2, 1, 4, WINED3DFMT_FLAG_BLOCKS_NO_VERIFY},
619 {WINED3DFMT_UYVY, 2, 1, 4, WINED3DFMT_FLAG_BLOCKS_NO_VERIFY},
620 {WINED3DFMT_R9G9B9E5_SHAREDEXP, 1, 1, 4},
623 struct wined3d_format_vertex_info
625 enum wined3d_format_id id;
626 enum wined3d_ffp_emit_idx emit_idx;
627 GLenum gl_vtx_type;
628 enum wined3d_gl_extension extension;
631 static const struct wined3d_format_vertex_info format_vertex_info[] =
633 {WINED3DFMT_R32_FLOAT, WINED3D_FFP_EMIT_FLOAT1, GL_FLOAT},
634 {WINED3DFMT_R32G32_FLOAT, WINED3D_FFP_EMIT_FLOAT2, GL_FLOAT},
635 {WINED3DFMT_R32G32B32_FLOAT, WINED3D_FFP_EMIT_FLOAT3, GL_FLOAT},
636 {WINED3DFMT_R32G32B32A32_FLOAT, WINED3D_FFP_EMIT_FLOAT4, GL_FLOAT},
637 {WINED3DFMT_B8G8R8A8_UNORM, WINED3D_FFP_EMIT_D3DCOLOR, GL_UNSIGNED_BYTE},
638 {WINED3DFMT_R8G8B8A8_UINT, WINED3D_FFP_EMIT_UBYTE4, GL_UNSIGNED_BYTE},
639 {WINED3DFMT_R16G16_UINT, WINED3D_FFP_EMIT_INVALID, GL_UNSIGNED_SHORT},
640 {WINED3DFMT_R16G16_SINT, WINED3D_FFP_EMIT_SHORT2, GL_SHORT},
641 {WINED3DFMT_R16G16B16A16_SINT, WINED3D_FFP_EMIT_SHORT4, GL_SHORT},
642 {WINED3DFMT_R8G8B8A8_UNORM, WINED3D_FFP_EMIT_UBYTE4N, GL_UNSIGNED_BYTE},
643 {WINED3DFMT_R16G16_SNORM, WINED3D_FFP_EMIT_SHORT2N, GL_SHORT},
644 {WINED3DFMT_R16G16B16A16_SNORM, WINED3D_FFP_EMIT_SHORT4N, GL_SHORT},
645 {WINED3DFMT_R16G16_UNORM, WINED3D_FFP_EMIT_USHORT2N, GL_UNSIGNED_SHORT},
646 {WINED3DFMT_R16G16B16A16_UNORM, WINED3D_FFP_EMIT_USHORT4N, GL_UNSIGNED_SHORT},
647 {WINED3DFMT_R10G10B10X2_UINT, WINED3D_FFP_EMIT_UDEC3, GL_UNSIGNED_SHORT},
648 {WINED3DFMT_R10G10B10X2_SNORM, WINED3D_FFP_EMIT_DEC3N, GL_SHORT},
649 {WINED3DFMT_R10G10B10A2_UNORM, WINED3D_FFP_EMIT_INVALID, GL_UNSIGNED_INT_2_10_10_10_REV,
650 ARB_VERTEX_TYPE_2_10_10_10_REV},
651 /* Without ARB_half_float_vertex we convert these on upload. */
652 {WINED3DFMT_R16G16_FLOAT, WINED3D_FFP_EMIT_FLOAT16_2, GL_FLOAT},
653 {WINED3DFMT_R16G16_FLOAT, WINED3D_FFP_EMIT_FLOAT16_2, GL_HALF_FLOAT, ARB_HALF_FLOAT_VERTEX},
654 {WINED3DFMT_R16G16B16A16_FLOAT, WINED3D_FFP_EMIT_FLOAT16_4, GL_FLOAT},
655 {WINED3DFMT_R16G16B16A16_FLOAT, WINED3D_FFP_EMIT_FLOAT16_4, GL_HALF_FLOAT, ARB_HALF_FLOAT_VERTEX},
656 {WINED3DFMT_R8G8B8A8_SNORM, WINED3D_FFP_EMIT_INVALID, GL_BYTE},
657 {WINED3DFMT_R8G8B8A8_SINT, WINED3D_FFP_EMIT_INVALID, GL_BYTE},
658 {WINED3DFMT_R8G8_UNORM, WINED3D_FFP_EMIT_INVALID, GL_UNSIGNED_BYTE},
659 {WINED3DFMT_R16G16B16A16_UINT, WINED3D_FFP_EMIT_INVALID, GL_UNSIGNED_SHORT},
660 {WINED3DFMT_R8_UNORM, WINED3D_FFP_EMIT_INVALID, GL_UNSIGNED_BYTE},
661 {WINED3DFMT_R8_UINT, WINED3D_FFP_EMIT_INVALID, GL_UNSIGNED_BYTE},
662 {WINED3DFMT_R8_SINT, WINED3D_FFP_EMIT_INVALID, GL_BYTE},
663 {WINED3DFMT_R16_UINT, WINED3D_FFP_EMIT_INVALID, GL_UNSIGNED_SHORT},
664 {WINED3DFMT_R16_SINT, WINED3D_FFP_EMIT_INVALID, GL_SHORT},
665 {WINED3DFMT_R32_UINT, WINED3D_FFP_EMIT_INVALID, GL_UNSIGNED_INT},
666 {WINED3DFMT_R32_SINT, WINED3D_FFP_EMIT_INVALID, GL_INT},
667 {WINED3DFMT_R32G32_UINT, WINED3D_FFP_EMIT_INVALID, GL_UNSIGNED_INT},
668 {WINED3DFMT_R32G32_SINT, WINED3D_FFP_EMIT_INVALID, GL_INT},
669 {WINED3DFMT_R32G32B32_UINT, WINED3D_FFP_EMIT_INVALID, GL_UNSIGNED_INT},
670 {WINED3DFMT_R32G32B32A32_UINT, WINED3D_FFP_EMIT_INVALID, GL_UNSIGNED_INT},
671 {WINED3DFMT_R32G32B32A32_SINT, WINED3D_FFP_EMIT_INVALID, GL_INT},
674 struct wined3d_format_texture_info
676 enum wined3d_format_id id;
677 GLint gl_internal;
678 GLint gl_srgb_internal;
679 GLint gl_rt_internal;
680 GLint gl_format;
681 GLint gl_type;
682 unsigned int conv_byte_count;
683 unsigned int flags;
684 enum wined3d_gl_extension extension;
685 void (*upload)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
686 unsigned int dst_row_pitch, unsigned int dst_slice_pitch,
687 unsigned int width, unsigned int height, unsigned int depth);
688 void (*download)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
689 unsigned int dst_row_pitch, unsigned int dst_slice_pitch,
690 unsigned int width, unsigned int height, unsigned int depth);
691 void (*decompress)(const BYTE *src, BYTE *dst, unsigned int src_row_pitch, unsigned int src_slice_pitch,
692 unsigned int dst_row_pitch, unsigned int dst_slice_pitch,
693 unsigned int width, unsigned int height, unsigned int depth);
696 static void convert_l4a4_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
697 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
699 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
700 * format+type combination to load it. Thus convert it to A8L8, then load it
701 * with A4L4 internal, but A8L8 format+type
703 unsigned int x, y, z;
704 const unsigned char *Source;
705 unsigned char *Dest;
707 for (z = 0; z < depth; z++)
709 for (y = 0; y < height; y++)
711 Source = src + z * src_slice_pitch + y * src_row_pitch;
712 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
713 for (x = 0; x < width; x++ )
715 unsigned char color = (*Source++);
716 /* A */ Dest[1] = (color & 0xf0u) << 0;
717 /* L */ Dest[0] = (color & 0x0fu) << 4;
718 Dest += 2;
724 static void convert_r5g5_snorm_l6_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
725 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
727 unsigned int x, y, z;
728 unsigned char r_in, g_in, l_in;
729 const unsigned short *texel_in;
730 unsigned short *texel_out;
732 /* Emulating signed 5 bit values with unsigned 5 bit values has some precision problems by design:
733 * E.g. the signed input value 0 becomes 16. GL normalizes it to 16 / 31 = 0.516. We convert it
734 * back to a signed value by subtracting 0.5 and multiplying by 2.0. The resulting value is
735 * ((16 / 31) - 0.5) * 2.0 = 0.032, which is quite different from the intended result 0.000. */
736 for (z = 0; z < depth; z++)
738 for (y = 0; y < height; y++)
740 texel_out = (unsigned short *) (dst + z * dst_slice_pitch + y * dst_row_pitch);
741 texel_in = (const unsigned short *)(src + z * src_slice_pitch + y * src_row_pitch);
742 for (x = 0; x < width; x++ )
744 l_in = (*texel_in & 0xfc00u) >> 10;
745 g_in = (*texel_in & 0x03e0u) >> 5;
746 r_in = *texel_in & 0x001fu;
748 *texel_out = ((r_in + 16) << 11) | (l_in << 5) | (g_in + 16);
749 texel_out++;
750 texel_in++;
756 static void convert_r5g5_snorm_l6_unorm_ext(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
757 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
759 unsigned int x, y, z;
760 unsigned char *texel_out, r_out, g_out, r_in, g_in, l_in;
761 const unsigned short *texel_in;
763 for (z = 0; z < depth; z++)
765 for (y = 0; y < height; y++)
767 texel_in = (const unsigned short *)(src + z * src_slice_pitch + y * src_row_pitch);
768 texel_out = dst + z * dst_slice_pitch + y * dst_row_pitch;
769 for (x = 0; x < width; x++ )
771 l_in = (*texel_in & 0xfc00u) >> 10;
772 g_in = (*texel_in & 0x03e0u) >> 5;
773 r_in = *texel_in & 0x001fu;
775 r_out = r_in << 3;
776 if (!(r_in & 0x10)) /* r > 0 */
777 r_out |= r_in >> 1;
779 g_out = g_in << 3;
780 if (!(g_in & 0x10)) /* g > 0 */
781 g_out |= g_in >> 1;
783 texel_out[0] = r_out;
784 texel_out[1] = g_out;
785 texel_out[2] = l_in << 1 | l_in >> 5;
786 texel_out[3] = 0;
788 texel_out += 4;
789 texel_in++;
795 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
796 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
798 unsigned int x, y, z;
799 unsigned char *texel_out, ds_out, dt_out, r_in, g_in, l_in;
800 const unsigned short *texel_in;
802 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
803 * fixed function and shaders without further conversion once the surface is
804 * loaded.
806 * The difference between this function and convert_r5g5_snorm_l6_unorm_ext
807 * is that convert_r5g5_snorm_l6_unorm_ext creates a 32 bit XRGB texture and
808 * this function creates a 24 bit DSDT_MAG texture. Trying to load a DSDT_MAG
809 * internal with a 32 bit DSDT_MAG_INTENSITY or DSDT_MAG_VIB format fails. */
810 for (z = 0; z < depth; z++)
812 for (y = 0; y < height; y++)
814 texel_in = (const unsigned short *)(src + z * src_slice_pitch + y * src_row_pitch);
815 texel_out = dst + z * dst_slice_pitch + y * dst_row_pitch;
816 for (x = 0; x < width; x++ )
818 l_in = (*texel_in & 0xfc00u) >> 10;
819 g_in = (*texel_in & 0x03e0u) >> 5;
820 r_in = *texel_in & 0x001fu;
822 ds_out = r_in << 3;
823 if (!(r_in & 0x10)) /* r > 0 */
824 ds_out |= r_in >> 1;
826 dt_out = g_in << 3;
827 if (!(g_in & 0x10)) /* g > 0 */
828 dt_out |= g_in >> 1;
830 texel_out[0] = ds_out;
831 texel_out[1] = dt_out;
832 texel_out[2] = l_in << 1 | l_in >> 5;
834 texel_out += 3;
835 texel_in++;
841 static void convert_r8g8_snorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
842 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
844 unsigned int x, y, z;
845 const short *Source;
846 unsigned char *Dest;
848 for (z = 0; z < depth; z++)
850 for (y = 0; y < height; y++)
852 Source = (const short *)(src + z * src_slice_pitch + y * src_row_pitch);
853 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
854 for (x = 0; x < width; x++ )
856 const short color = (*Source++);
857 /* B */ Dest[0] = 0xff;
858 /* G */ Dest[1] = (color >> 8) + 128; /* V */
859 /* R */ Dest[2] = (color & 0xff) + 128; /* U */
860 Dest += 3;
866 static void convert_r8g8_snorm_l8x8_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
867 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
869 unsigned int x, y, z;
870 const DWORD *Source;
871 unsigned char *Dest;
873 /* Doesn't work correctly with the fixed function pipeline, but can work in
874 * shaders if the shader is adjusted. (There's no use for this format in gl's
875 * standard fixed function pipeline anyway).
877 for (z = 0; z < depth; z++)
879 for (y = 0; y < height; y++)
881 Source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
882 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
883 for (x = 0; x < width; x++ )
885 LONG color = (*Source++);
886 /* B */ Dest[0] = ((color >> 16) & 0xff); /* L */
887 /* G */ Dest[1] = ((color >> 8 ) & 0xff) + 128; /* V */
888 /* R */ Dest[2] = (color & 0xff) + 128; /* U */
889 Dest += 4;
895 static void convert_r8g8_snorm_l8x8_unorm_nv(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
896 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
898 unsigned int x, y, z;
899 const DWORD *Source;
900 unsigned char *Dest;
902 /* This implementation works with the fixed function pipeline and shaders
903 * without further modification after converting the surface.
905 for (z = 0; z < depth; z++)
907 for (y = 0; y < height; y++)
909 Source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
910 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
911 for (x = 0; x < width; x++ )
913 LONG color = (*Source++);
914 /* L */ Dest[2] = ((color >> 16) & 0xff); /* L */
915 /* V */ Dest[1] = ((color >> 8 ) & 0xff); /* V */
916 /* U */ Dest[0] = (color & 0xff); /* U */
917 /* I */ Dest[3] = 255; /* X */
918 Dest += 4;
924 static void convert_r8g8b8a8_snorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
925 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
927 unsigned int x, y, z;
928 const DWORD *Source;
929 unsigned char *Dest;
931 for (z = 0; z < depth; z++)
933 for (y = 0; y < height; y++)
935 Source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
936 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
937 for (x = 0; x < width; x++ )
939 LONG color = (*Source++);
940 /* B */ Dest[0] = ((color >> 16) & 0xff) + 128; /* W */
941 /* G */ Dest[1] = ((color >> 8 ) & 0xff) + 128; /* V */
942 /* R */ Dest[2] = (color & 0xff) + 128; /* U */
943 /* A */ Dest[3] = ((color >> 24) & 0xff) + 128; /* Q */
944 Dest += 4;
950 static void convert_r16g16_snorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
951 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
953 unsigned int x, y, z;
954 const DWORD *Source;
955 unsigned short *Dest;
957 for (z = 0; z < depth; z++)
959 for (y = 0; y < height; y++)
961 Source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
962 Dest = (unsigned short *) (dst + z * dst_slice_pitch + y * dst_row_pitch);
963 for (x = 0; x < width; x++ )
965 const DWORD color = (*Source++);
966 /* B */ Dest[0] = 0xffff;
967 /* G */ Dest[1] = (color >> 16) + 32768; /* V */
968 /* R */ Dest[2] = (color & 0xffff) + 32768; /* U */
969 Dest += 3;
975 static void convert_r16g16(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
976 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
978 unsigned int x, y, z;
979 const WORD *Source;
980 WORD *Dest;
982 for (z = 0; z < depth; z++)
984 for (y = 0; y < height; y++)
986 Source = (const WORD *)(src + z * src_slice_pitch + y * src_row_pitch);
987 Dest = (WORD *) (dst + z * dst_slice_pitch + y * dst_row_pitch);
988 for (x = 0; x < width; x++ )
990 WORD green = (*Source++);
991 WORD red = (*Source++);
992 Dest[0] = green;
993 Dest[1] = red;
994 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
995 * shader overwrites it anyway */
996 Dest[2] = 0xffff;
997 Dest += 3;
1003 static void convert_r32g32_float(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
1004 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
1006 unsigned int x, y, z;
1007 const float *Source;
1008 float *Dest;
1010 for (z = 0; z < depth; z++)
1012 for (y = 0; y < height; y++)
1014 Source = (const float *)(src + z * src_slice_pitch + y * src_row_pitch);
1015 Dest = (float *) (dst + z * dst_slice_pitch + y * dst_row_pitch);
1016 for (x = 0; x < width; x++ )
1018 float green = (*Source++);
1019 float red = (*Source++);
1020 Dest[0] = green;
1021 Dest[1] = red;
1022 Dest[2] = 1.0f;
1023 Dest += 3;
1029 static void convert_s8_uint_d24_float(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
1030 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
1032 unsigned int x, y, z;
1034 for (z = 0; z < depth; z++)
1036 for (y = 0; y < height; ++y)
1038 const DWORD *source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
1039 float *dest_f = (float *)(dst + z * dst_slice_pitch + y * dst_row_pitch);
1040 DWORD *dest_s = (DWORD *)dest_f;
1042 for (x = 0; x < width; ++x)
1044 dest_f[x * 2] = float_24_to_32((source[x] & 0xffffff00u) >> 8);
1045 dest_s[x * 2 + 1] = source[x] & 0xff;
1051 static void x8_d24_unorm_upload(const BYTE *src, BYTE *dst,
1052 unsigned int src_row_pitch, unsigned int src_slice_pitch,
1053 unsigned int dst_row_pitch, unsigned int dst_slice_pitch,
1054 unsigned int width, unsigned int height, unsigned int depth)
1056 unsigned int x, y, z;
1058 for (z = 0; z < depth; ++z)
1060 for (y = 0; y < height; ++y)
1062 const DWORD *source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
1063 DWORD *dest = (DWORD *)(dst + z * dst_slice_pitch + y * dst_row_pitch);
1065 for (x = 0; x < width; ++x)
1067 dest[x] = source[x] << 8 | ((source[x] >> 16) & 0xff);
1073 static void x8_d24_unorm_download(const BYTE *src, BYTE *dst,
1074 unsigned int src_row_pitch, unsigned int src_slice_pitch,
1075 unsigned int dst_row_pitch, unsigned int dst_slice_pitch,
1076 unsigned int width, unsigned int height, unsigned int depth)
1078 unsigned int x, y, z;
1080 for (z = 0; z < depth; ++z)
1082 for (y = 0; y < height; ++y)
1084 const DWORD *source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
1085 DWORD *dest = (DWORD *)(dst + z * dst_slice_pitch + y * dst_row_pitch);
1087 for (x = 0; x < width; ++x)
1089 dest[x] = source[x] >> 8;
1095 static BOOL color_in_range(const struct wined3d_color_key *color_key, DWORD color)
1097 /* FIXME: Is this really how color keys are supposed to work? I think it
1098 * makes more sense to compare the individual channels. */
1099 return color >= color_key->color_space_low_value
1100 && color <= color_key->color_space_high_value;
1103 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(const BYTE *src, unsigned int src_pitch,
1104 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
1105 const struct wined3d_color_key *color_key)
1107 const WORD *src_row;
1108 unsigned int x, y;
1109 WORD *dst_row;
1111 for (y = 0; y < height; ++y)
1113 src_row = (WORD *)&src[src_pitch * y];
1114 dst_row = (WORD *)&dst[dst_pitch * y];
1115 for (x = 0; x < width; ++x)
1117 WORD src_color = src_row[x];
1118 if (!color_in_range(color_key, src_color))
1119 dst_row[x] = 0x8000u | ((src_color & 0xffc0u) >> 1) | (src_color & 0x1fu);
1120 else
1121 dst_row[x] = ((src_color & 0xffc0u) >> 1) | (src_color & 0x1fu);
1126 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(const BYTE *src, unsigned int src_pitch,
1127 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
1128 const struct wined3d_color_key *color_key)
1130 const WORD *src_row;
1131 unsigned int x, y;
1132 WORD *dst_row;
1134 for (y = 0; y < height; ++y)
1136 src_row = (WORD *)&src[src_pitch * y];
1137 dst_row = (WORD *)&dst[dst_pitch * y];
1138 for (x = 0; x < width; ++x)
1140 WORD src_color = src_row[x];
1141 if (color_in_range(color_key, src_color))
1142 dst_row[x] = src_color & ~0x8000;
1143 else
1144 dst_row[x] = src_color | 0x8000;
1149 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE *src, unsigned int src_pitch,
1150 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
1151 const struct wined3d_color_key *color_key)
1153 const BYTE *src_row;
1154 unsigned int x, y;
1155 DWORD *dst_row;
1157 for (y = 0; y < height; ++y)
1159 src_row = &src[src_pitch * y];
1160 dst_row = (DWORD *)&dst[dst_pitch * y];
1161 for (x = 0; x < width; ++x)
1163 DWORD src_color = (src_row[x * 3 + 2] << 16) | (src_row[x * 3 + 1] << 8) | src_row[x * 3];
1164 if (!color_in_range(color_key, src_color))
1165 dst_row[x] = src_color | 0xff000000;
1170 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE *src, unsigned int src_pitch,
1171 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
1172 const struct wined3d_color_key *color_key)
1174 const DWORD *src_row;
1175 unsigned int x, y;
1176 DWORD *dst_row;
1178 for (y = 0; y < height; ++y)
1180 src_row = (DWORD *)&src[src_pitch * y];
1181 dst_row = (DWORD *)&dst[dst_pitch * y];
1182 for (x = 0; x < width; ++x)
1184 DWORD src_color = src_row[x];
1185 if (color_in_range(color_key, src_color))
1186 dst_row[x] = src_color & ~0xff000000;
1187 else
1188 dst_row[x] = src_color | 0xff000000;
1193 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE *src, unsigned int src_pitch,
1194 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
1195 const struct wined3d_color_key *color_key)
1197 const DWORD *src_row;
1198 unsigned int x, y;
1199 DWORD *dst_row;
1201 for (y = 0; y < height; ++y)
1203 src_row = (DWORD *)&src[src_pitch * y];
1204 dst_row = (DWORD *)&dst[dst_pitch * y];
1205 for (x = 0; x < width; ++x)
1207 DWORD src_color = src_row[x];
1208 if (color_in_range(color_key, src_color))
1209 src_color &= ~0xff000000;
1210 dst_row[x] = src_color;
1215 const struct wined3d_color_key_conversion * wined3d_format_get_color_key_conversion(
1216 const struct wined3d_texture *texture, BOOL need_alpha_ck)
1218 const struct wined3d_format *format = texture->resource.format;
1219 unsigned int i;
1221 static const struct
1223 enum wined3d_format_id src_format;
1224 struct wined3d_color_key_conversion conversion;
1226 color_key_info[] =
1228 {WINED3DFMT_B5G6R5_UNORM, {WINED3DFMT_B5G5R5A1_UNORM, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key }},
1229 {WINED3DFMT_B5G5R5X1_UNORM, {WINED3DFMT_B5G5R5A1_UNORM, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key }},
1230 {WINED3DFMT_B8G8R8_UNORM, {WINED3DFMT_B8G8R8A8_UNORM, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key }},
1231 {WINED3DFMT_B8G8R8X8_UNORM, {WINED3DFMT_B8G8R8A8_UNORM, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key }},
1232 {WINED3DFMT_B8G8R8A8_UNORM, {WINED3DFMT_B8G8R8A8_UNORM, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key }},
1235 if (need_alpha_ck && (texture->async.flags & WINED3D_TEXTURE_ASYNC_COLOR_KEY))
1237 for (i = 0; i < ARRAY_SIZE(color_key_info); ++i)
1239 if (color_key_info[i].src_format == format->id)
1240 return &color_key_info[i].conversion;
1243 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format->id));
1246 return NULL;
1249 /* We intentionally don't support WINED3DFMT_D32_UNORM. No hardware driver
1250 * supports it, and applications get confused when we do.
1252 * The following formats explicitly don't have WINED3DFMT_FLAG_TEXTURE set:
1254 * These are never supported on native.
1255 * WINED3DFMT_B8G8R8_UNORM
1256 * WINED3DFMT_B2G3R3_UNORM
1257 * WINED3DFMT_L4A4_UNORM
1258 * WINED3DFMT_S1_UINT_D15_UNORM
1259 * WINED3DFMT_S4X4_UINT_D24_UNORM
1261 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
1262 * Since it is not widely available, don't offer it. Further no Windows driver
1263 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
1264 * WINED3DFMT_P8_UINT
1265 * WINED3DFMT_P8_UINT_A8_UNORM
1267 * These formats seem to be similar to the HILO formats in
1268 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
1269 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
1270 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
1271 * refused to support formats which can easily be emulated with pixel shaders,
1272 * so applications have to deal with not having NVHS and NVHU.
1273 * WINED3DFMT_NVHU
1274 * WINED3DFMT_NVHS */
1275 static const struct wined3d_format_texture_info format_texture_info[] =
1277 /* format id gl_internal gl_srgb_internal gl_rt_internal
1278 gl_format gl_type conv_byte_count
1279 flags
1280 extension upload download */
1281 /* FourCC formats */
1282 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
1283 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
1284 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
1285 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
1286 * endian machine
1288 {WINED3DFMT_UYVY, GL_RG8, GL_RG8, 0,
1289 GL_RG, GL_UNSIGNED_BYTE, 0,
1290 WINED3DFMT_FLAG_FILTERING,
1291 ARB_TEXTURE_RG, NULL},
1292 {WINED3DFMT_UYVY, GL_LUMINANCE8_ALPHA8, GL_LUMINANCE8_ALPHA8, 0,
1293 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1294 WINED3DFMT_FLAG_FILTERING,
1295 WINED3D_GL_LEGACY_CONTEXT, NULL},
1296 {WINED3DFMT_UYVY, GL_RGB_RAW_422_APPLE, GL_RGB_RAW_422_APPLE, 0,
1297 GL_RGB_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, 0,
1298 WINED3DFMT_FLAG_FILTERING,
1299 APPLE_RGB_422, NULL},
1300 {WINED3DFMT_UYVY, GL_RGB, GL_RGB, 0,
1301 GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, 0,
1302 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_FILTERING,
1303 APPLE_YCBCR_422, NULL},
1304 {WINED3DFMT_YUY2, GL_RG8, GL_RG8, 0,
1305 GL_RG, GL_UNSIGNED_BYTE, 0,
1306 WINED3DFMT_FLAG_FILTERING,
1307 ARB_TEXTURE_RG, NULL},
1308 {WINED3DFMT_YUY2, GL_LUMINANCE8_ALPHA8, GL_LUMINANCE8_ALPHA8, 0,
1309 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1310 WINED3DFMT_FLAG_FILTERING,
1311 WINED3D_GL_LEGACY_CONTEXT, NULL},
1312 {WINED3DFMT_YUY2, GL_RGB_RAW_422_APPLE, GL_RGB_RAW_422_APPLE, 0,
1313 GL_RGB_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, 0,
1314 WINED3DFMT_FLAG_FILTERING,
1315 APPLE_RGB_422, NULL},
1316 {WINED3DFMT_YUY2, GL_RGB, GL_RGB, 0,
1317 GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, 0,
1318 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_FILTERING,
1319 APPLE_YCBCR_422, NULL},
1320 {WINED3DFMT_YV12, GL_R8, GL_R8, 0,
1321 GL_RED, GL_UNSIGNED_BYTE, 0,
1322 WINED3DFMT_FLAG_FILTERING,
1323 ARB_TEXTURE_RG, NULL},
1324 {WINED3DFMT_YV12, GL_ALPHA8, GL_ALPHA8, 0,
1325 GL_ALPHA, GL_UNSIGNED_BYTE, 0,
1326 WINED3DFMT_FLAG_FILTERING,
1327 WINED3D_GL_LEGACY_CONTEXT, NULL},
1328 {WINED3DFMT_NV12, GL_R8, GL_R8, 0,
1329 GL_RED, GL_UNSIGNED_BYTE, 0,
1330 WINED3DFMT_FLAG_FILTERING,
1331 ARB_TEXTURE_RG, NULL},
1332 {WINED3DFMT_NV12, GL_ALPHA8, GL_ALPHA8, 0,
1333 GL_ALPHA, GL_UNSIGNED_BYTE, 0,
1334 WINED3DFMT_FLAG_FILTERING,
1335 WINED3D_GL_LEGACY_CONTEXT, NULL},
1336 {WINED3DFMT_DXT1, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 0,
1337 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1338 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1339 | WINED3DFMT_FLAG_SRGB_READ,
1340 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1341 {WINED3DFMT_DXT2, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0,
1342 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1343 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1344 | WINED3DFMT_FLAG_SRGB_READ,
1345 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1346 {WINED3DFMT_DXT3, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0,
1347 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1348 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1349 | WINED3DFMT_FLAG_SRGB_READ,
1350 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1351 {WINED3DFMT_DXT4, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0,
1352 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1353 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1354 | WINED3DFMT_FLAG_SRGB_READ,
1355 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1356 {WINED3DFMT_DXT5, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0,
1357 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1358 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1359 | WINED3DFMT_FLAG_SRGB_READ,
1360 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1361 {WINED3DFMT_BC1_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 0,
1362 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1363 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1364 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1365 {WINED3DFMT_BC2_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0,
1366 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1367 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1368 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1369 {WINED3DFMT_BC3_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0,
1370 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1371 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1372 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1373 {WINED3DFMT_BC4_UNORM, GL_COMPRESSED_RED_RGTC1, GL_COMPRESSED_RED_RGTC1, 0,
1374 GL_RED, GL_UNSIGNED_BYTE, 0,
1375 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1376 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1377 {WINED3DFMT_BC4_SNORM, GL_COMPRESSED_SIGNED_RED_RGTC1, GL_COMPRESSED_SIGNED_RED_RGTC1, 0,
1378 GL_RED, GL_UNSIGNED_BYTE, 0,
1379 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1380 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1381 {WINED3DFMT_BC5_UNORM, GL_COMPRESSED_RG_RGTC2, GL_COMPRESSED_RG_RGTC2, 0,
1382 GL_RG, GL_UNSIGNED_BYTE, 0,
1383 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1384 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1385 {WINED3DFMT_BC5_SNORM, GL_COMPRESSED_SIGNED_RG_RGTC2, GL_COMPRESSED_SIGNED_RG_RGTC2, 0,
1386 GL_RG, GL_UNSIGNED_BYTE, 0,
1387 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1388 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1389 {WINED3DFMT_BC6H_UF16, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB, 0,
1390 GL_RGB, GL_UNSIGNED_BYTE, 0,
1391 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1392 ARB_TEXTURE_COMPRESSION_BPTC, NULL},
1393 {WINED3DFMT_BC6H_SF16, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, 0,
1394 GL_RGB, GL_UNSIGNED_BYTE, 0,
1395 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1396 ARB_TEXTURE_COMPRESSION_BPTC, NULL},
1397 {WINED3DFMT_BC7_UNORM, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB, 0,
1398 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1399 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1400 ARB_TEXTURE_COMPRESSION_BPTC, NULL},
1401 /* IEEE formats */
1402 {WINED3DFMT_R32_FLOAT, GL_RGB32F_ARB, GL_RGB32F_ARB, 0,
1403 GL_RED, GL_FLOAT, 0,
1404 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1405 ARB_TEXTURE_FLOAT, NULL},
1406 {WINED3DFMT_R32_FLOAT, GL_R32F, GL_R32F, 0,
1407 GL_RED, GL_FLOAT, 0,
1408 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1409 ARB_TEXTURE_RG, NULL},
1410 {WINED3DFMT_R32G32_FLOAT, GL_RGB32F_ARB, GL_RGB32F_ARB, 0,
1411 GL_RGB, GL_FLOAT, 12,
1412 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1413 ARB_TEXTURE_FLOAT, convert_r32g32_float},
1414 {WINED3DFMT_R32G32_FLOAT, GL_RG32F, GL_RG32F, 0,
1415 GL_RG, GL_FLOAT, 0,
1416 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1417 ARB_TEXTURE_RG, NULL},
1418 {WINED3DFMT_R32G32B32_FLOAT, GL_RGB32F, GL_RGB32F, 0,
1419 GL_RGB, GL_FLOAT, 0,
1420 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1421 ARB_TEXTURE_FLOAT, NULL},
1422 {WINED3DFMT_R32G32B32A32_FLOAT, GL_RGBA32F_ARB, GL_RGBA32F_ARB, 0,
1423 GL_RGBA, GL_FLOAT, 0,
1424 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1425 ARB_TEXTURE_FLOAT, NULL},
1426 /* Float */
1427 {WINED3DFMT_R16_FLOAT, GL_RGB16F_ARB, GL_RGB16F_ARB, 0,
1428 GL_RED, GL_HALF_FLOAT_ARB, 0,
1429 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1430 ARB_TEXTURE_FLOAT, NULL},
1431 {WINED3DFMT_R16_FLOAT, GL_R16F, GL_R16F, 0,
1432 GL_RED, GL_HALF_FLOAT_ARB, 0,
1433 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1434 ARB_TEXTURE_RG, NULL},
1435 {WINED3DFMT_R16G16_FLOAT, GL_RGB16F_ARB, GL_RGB16F_ARB, 0,
1436 GL_RGB, GL_HALF_FLOAT_ARB, 6,
1437 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1438 ARB_TEXTURE_FLOAT, convert_r16g16},
1439 {WINED3DFMT_R16G16_FLOAT, GL_RG16F, GL_RG16F, 0,
1440 GL_RG, GL_HALF_FLOAT_ARB, 0,
1441 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1442 ARB_TEXTURE_RG, NULL},
1443 {WINED3DFMT_R16G16B16A16_FLOAT, GL_RGBA16F_ARB, GL_RGBA16F_ARB, 0,
1444 GL_RGBA, GL_HALF_FLOAT_ARB, 0,
1445 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_RENDERTARGET
1446 | WINED3DFMT_FLAG_VTF,
1447 ARB_TEXTURE_FLOAT, NULL},
1448 {WINED3DFMT_R11G11B10_FLOAT, GL_R11F_G11F_B10F, GL_R11F_G11F_B10F, 0,
1449 GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, 0,
1450 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_RENDERTARGET,
1451 EXT_PACKED_FLOAT},
1452 /* Palettized formats */
1453 {WINED3DFMT_P8_UINT, GL_R8, GL_R8, 0,
1454 GL_RED, GL_UNSIGNED_BYTE, 0,
1456 ARB_TEXTURE_RG, NULL},
1457 {WINED3DFMT_P8_UINT, GL_ALPHA8, GL_ALPHA8, 0,
1458 GL_ALPHA, GL_UNSIGNED_BYTE, 0,
1460 WINED3D_GL_LEGACY_CONTEXT, NULL},
1461 /* Standard ARGB formats */
1462 {WINED3DFMT_B8G8R8_UNORM, GL_RGB8, GL_RGB8, 0,
1463 GL_BGR, GL_UNSIGNED_BYTE, 0,
1464 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET,
1465 WINED3D_GL_EXT_NONE, NULL},
1466 {WINED3DFMT_B8G8R8A8_UNORM, GL_RGBA8, GL_SRGB8_ALPHA8_EXT, 0,
1467 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1468 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1469 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE
1470 | WINED3DFMT_FLAG_VTF,
1471 WINED3D_GL_EXT_NONE, NULL},
1472 {WINED3DFMT_B8G8R8X8_UNORM, GL_RGB8, GL_SRGB8_EXT, 0,
1473 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1474 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1475 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE,
1476 WINED3D_GL_EXT_NONE, NULL},
1477 {WINED3DFMT_B5G6R5_UNORM, GL_RGB5, GL_SRGB8_EXT, GL_RGB8,
1478 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0,
1479 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1480 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ,
1481 WINED3D_GL_EXT_NONE, NULL},
1482 {WINED3DFMT_B5G6R5_UNORM, GL_RGB565, GL_SRGB8_EXT, GL_RGB8,
1483 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0,
1484 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1485 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ,
1486 ARB_ES2_COMPATIBILITY, NULL},
1487 {WINED3DFMT_B5G5R5X1_UNORM, GL_RGB5, GL_RGB5, 0,
1488 GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 0,
1489 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1490 | WINED3DFMT_FLAG_RENDERTARGET,
1491 WINED3D_GL_EXT_NONE, NULL},
1492 {WINED3DFMT_B5G5R5A1_UNORM, GL_RGB5_A1, GL_RGB5_A1, 0,
1493 GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 0,
1494 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1495 WINED3D_GL_EXT_NONE, NULL},
1496 {WINED3DFMT_B4G4R4A4_UNORM, GL_RGBA4, GL_SRGB8_ALPHA8_EXT, 0,
1497 GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, 0,
1498 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1499 | WINED3DFMT_FLAG_SRGB_READ,
1500 WINED3D_GL_EXT_NONE, NULL},
1501 {WINED3DFMT_B2G3R3_UNORM, GL_R3_G3_B2, GL_R3_G3_B2, 0,
1502 GL_RGB, GL_UNSIGNED_BYTE_3_3_2, 0,
1503 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1504 WINED3D_GL_EXT_NONE, NULL},
1505 {WINED3DFMT_R8_UNORM, GL_R8, GL_R8, 0,
1506 GL_RED, GL_UNSIGNED_BYTE, 0,
1507 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1508 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1509 ARB_TEXTURE_RG, NULL},
1510 {WINED3DFMT_A8_UNORM, GL_R8, GL_R8, 0,
1511 GL_RED, GL_UNSIGNED_BYTE, 0,
1512 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1513 | WINED3DFMT_FLAG_RENDERTARGET,
1514 ARB_TEXTURE_RG, NULL},
1515 {WINED3DFMT_A8_UNORM, GL_ALPHA8, GL_ALPHA8, 0,
1516 GL_ALPHA, GL_UNSIGNED_BYTE, 0,
1517 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1518 | WINED3DFMT_FLAG_RENDERTARGET,
1519 WINED3D_GL_LEGACY_CONTEXT, NULL},
1520 {WINED3DFMT_B4G4R4X4_UNORM, GL_RGB4, GL_RGB4, 0,
1521 GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, 0,
1522 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1523 WINED3D_GL_EXT_NONE, NULL},
1524 {WINED3DFMT_R10G10B10A2_UINT, GL_RGB10_A2UI, GL_RGB10_A2UI, 0,
1525 GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, 0,
1526 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1527 ARB_TEXTURE_RGB10_A2UI, NULL},
1528 {WINED3DFMT_R10G10B10A2_UNORM, GL_RGB10_A2, GL_RGB10_A2, 0,
1529 GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, 0,
1530 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1531 | WINED3DFMT_FLAG_RENDERTARGET,
1532 WINED3D_GL_EXT_NONE, NULL},
1533 {WINED3DFMT_R8G8B8A8_UNORM, GL_RGBA8, GL_SRGB8_ALPHA8_EXT, 0,
1534 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1535 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1536 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE
1537 | WINED3DFMT_FLAG_VTF,
1538 WINED3D_GL_EXT_NONE, NULL},
1539 {WINED3DFMT_R8G8B8A8_UINT, GL_RGBA8UI, GL_RGBA8UI, 0,
1540 GL_RGBA_INTEGER, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1541 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1542 ARB_TEXTURE_RGB10_A2UI, NULL},
1543 {WINED3DFMT_R8G8B8A8_SINT, GL_RGBA8I, GL_RGBA8I, 0,
1544 GL_RGBA_INTEGER, GL_BYTE, 0,
1545 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1546 EXT_TEXTURE_INTEGER, NULL},
1547 {WINED3DFMT_R8G8B8X8_UNORM, GL_RGB8, GL_RGB8, 0,
1548 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1549 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1550 WINED3D_GL_EXT_NONE, NULL},
1551 {WINED3DFMT_R16G16_UNORM, GL_RGB16, GL_RGB16, GL_RGBA16,
1552 GL_RGB, GL_UNSIGNED_SHORT, 6,
1553 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1554 WINED3D_GL_EXT_NONE, convert_r16g16},
1555 {WINED3DFMT_R16G16_UNORM, GL_RG16, GL_RG16, 0,
1556 GL_RG, GL_UNSIGNED_SHORT, 0,
1557 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1558 | WINED3DFMT_FLAG_RENDERTARGET,
1559 ARB_TEXTURE_RG, NULL},
1560 {WINED3DFMT_B10G10R10A2_UNORM, GL_RGB10_A2, GL_RGB10_A2, 0,
1561 GL_BGRA, GL_UNSIGNED_INT_2_10_10_10_REV, 0,
1562 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1563 | WINED3DFMT_FLAG_RENDERTARGET,
1564 WINED3D_GL_EXT_NONE, NULL},
1565 {WINED3DFMT_R16G16B16A16_UNORM, GL_RGBA16, GL_RGBA16, 0,
1566 GL_RGBA, GL_UNSIGNED_SHORT, 0,
1567 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1568 | WINED3DFMT_FLAG_RENDERTARGET,
1569 WINED3D_GL_EXT_NONE, NULL},
1570 {WINED3DFMT_R8G8_UNORM, GL_RG8, GL_RG8, 0,
1571 GL_RG, GL_UNSIGNED_BYTE, 0,
1572 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1573 | WINED3DFMT_FLAG_RENDERTARGET,
1574 ARB_TEXTURE_RG, NULL},
1575 {WINED3DFMT_R8G8_UINT, GL_RG8UI, GL_RG8UI, 0,
1576 GL_RG_INTEGER, GL_UNSIGNED_BYTE, 0,
1577 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1578 ARB_TEXTURE_RG, NULL},
1579 {WINED3DFMT_R8G8_SINT, GL_RG8I, GL_RG8I, 0,
1580 GL_RG_INTEGER, GL_BYTE, 0,
1581 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1582 ARB_TEXTURE_RG, NULL},
1583 {WINED3DFMT_R16G16B16A16_UINT, GL_RGBA16UI, GL_RGBA16UI, 0,
1584 GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, 0,
1585 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1586 EXT_TEXTURE_INTEGER, NULL},
1587 {WINED3DFMT_R16G16B16A16_SINT, GL_RGBA16I, GL_RGBA16I, 0,
1588 GL_RGBA_INTEGER, GL_SHORT, 0,
1589 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1590 EXT_TEXTURE_INTEGER, NULL},
1591 {WINED3DFMT_R32G32_UINT, GL_RG32UI, GL_RG32UI, 0,
1592 GL_RG_INTEGER, GL_UNSIGNED_INT, 0,
1593 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1594 ARB_TEXTURE_RG, NULL},
1595 {WINED3DFMT_R32G32_SINT, GL_RG32I, GL_RG32I, 0,
1596 GL_RG_INTEGER, GL_INT, 0,
1597 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1598 ARB_TEXTURE_RG, NULL},
1599 {WINED3DFMT_R16G16_UINT, GL_RG16UI, GL_RG16UI, 0,
1600 GL_RG_INTEGER, GL_UNSIGNED_SHORT, 0,
1601 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1602 ARB_TEXTURE_RG, NULL},
1603 {WINED3DFMT_R16G16_SINT, GL_RG16I, GL_RG16I, 0,
1604 GL_RG_INTEGER, GL_SHORT, 0,
1605 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1606 ARB_TEXTURE_RG, NULL},
1607 {WINED3DFMT_R32_UINT, GL_R32UI, GL_R32UI, 0,
1608 GL_RED_INTEGER, GL_UNSIGNED_INT, 0,
1609 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1610 ARB_TEXTURE_RG, NULL},
1611 {WINED3DFMT_R32_SINT, GL_R32I, GL_R32I, 0,
1612 GL_RED_INTEGER, GL_INT, 0,
1613 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1614 ARB_TEXTURE_RG, NULL},
1615 {WINED3DFMT_R16_UNORM, GL_R16, GL_R16, 0,
1616 GL_RED, GL_UNSIGNED_SHORT, 0,
1617 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1618 | WINED3DFMT_FLAG_RENDERTARGET,
1619 ARB_TEXTURE_RG, NULL},
1620 {WINED3DFMT_R16_UINT, GL_R16UI, GL_R16UI, 0,
1621 GL_RED_INTEGER, GL_UNSIGNED_SHORT, 0,
1622 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1623 ARB_TEXTURE_RG, NULL},
1624 {WINED3DFMT_R16_SINT, GL_R16I, GL_R16I, 0,
1625 GL_RED_INTEGER, GL_SHORT, 0,
1626 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1627 ARB_TEXTURE_RG, NULL},
1628 {WINED3DFMT_R8_UINT, GL_R8UI, GL_R8UI, 0,
1629 GL_RED_INTEGER, GL_UNSIGNED_BYTE, 0,
1630 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1631 ARB_TEXTURE_RG, NULL},
1632 {WINED3DFMT_R8_SINT, GL_R8I, GL_R8I, 0,
1633 GL_RED_INTEGER, GL_BYTE, 0,
1634 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1635 ARB_TEXTURE_RG, NULL},
1636 /* Luminance */
1637 {WINED3DFMT_L8_UNORM, GL_LUMINANCE8, GL_SLUMINANCE8_EXT, 0,
1638 GL_LUMINANCE, GL_UNSIGNED_BYTE, 0,
1639 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1640 | WINED3DFMT_FLAG_SRGB_READ,
1641 WINED3D_GL_LEGACY_CONTEXT, NULL},
1642 {WINED3DFMT_L8_UNORM, GL_R8, GL_R8, 0,
1643 GL_RED, GL_UNSIGNED_BYTE, 0,
1644 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1645 | WINED3DFMT_FLAG_RENDERTARGET,
1646 ARB_TEXTURE_RG, NULL},
1647 {WINED3DFMT_L8A8_UNORM, GL_RG8, GL_RG8, 0,
1648 GL_RG, GL_UNSIGNED_BYTE, 0,
1649 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1650 ARB_TEXTURE_RG, NULL},
1651 {WINED3DFMT_L8A8_UNORM, GL_LUMINANCE8_ALPHA8, GL_SLUMINANCE8_ALPHA8_EXT, 0,
1652 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1653 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1654 | WINED3DFMT_FLAG_SRGB_READ,
1655 WINED3D_GL_LEGACY_CONTEXT, NULL},
1656 {WINED3DFMT_L4A4_UNORM, GL_RG8, GL_RG8, 0,
1657 GL_RG, GL_UNSIGNED_BYTE, 2,
1658 WINED3DFMT_FLAG_FILTERING,
1659 ARB_TEXTURE_RG, convert_l4a4_unorm},
1660 {WINED3DFMT_L4A4_UNORM, GL_LUMINANCE4_ALPHA4, GL_LUMINANCE4_ALPHA4, 0,
1661 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 2,
1662 WINED3DFMT_FLAG_FILTERING,
1663 WINED3D_GL_LEGACY_CONTEXT, convert_l4a4_unorm},
1664 {WINED3DFMT_L16_UNORM, GL_R16, GL_R16, 0,
1665 GL_RED, GL_UNSIGNED_SHORT, 0,
1666 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1667 ARB_TEXTURE_RG, NULL},
1668 {WINED3DFMT_L16_UNORM, GL_LUMINANCE16, GL_LUMINANCE16, 0,
1669 GL_LUMINANCE, GL_UNSIGNED_SHORT, 0,
1670 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1671 WINED3D_GL_LEGACY_CONTEXT, NULL},
1672 /* Bump mapping stuff */
1673 {WINED3DFMT_R8G8_SNORM, GL_RGB8, GL_RGB8, 0,
1674 GL_BGR, GL_UNSIGNED_BYTE, 3,
1675 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1676 | WINED3DFMT_FLAG_BUMPMAP,
1677 WINED3D_GL_EXT_NONE, convert_r8g8_snorm},
1678 {WINED3DFMT_R8G8_SNORM, GL_DSDT8_NV, GL_DSDT8_NV, 0,
1679 GL_DSDT_NV, GL_BYTE, 0,
1680 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1681 | WINED3DFMT_FLAG_BUMPMAP,
1682 NV_TEXTURE_SHADER, NULL},
1683 {WINED3DFMT_R8G8_SNORM, GL_RG8_SNORM, GL_RG8_SNORM, 0,
1684 GL_RG, GL_BYTE, 0,
1685 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1686 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_BUMPMAP,
1687 EXT_TEXTURE_SNORM, NULL},
1688 {WINED3DFMT_R5G5_SNORM_L6_UNORM, GL_RGB5, GL_RGB5, 0,
1689 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 2,
1690 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1691 | WINED3DFMT_FLAG_BUMPMAP,
1692 WINED3D_GL_EXT_NONE, convert_r5g5_snorm_l6_unorm},
1693 {WINED3DFMT_R5G5_SNORM_L6_UNORM, GL_DSDT8_MAG8_NV, GL_DSDT8_MAG8_NV, 0,
1694 GL_DSDT_MAG_NV, GL_BYTE, 3,
1695 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1696 | WINED3DFMT_FLAG_BUMPMAP,
1697 NV_TEXTURE_SHADER, convert_r5g5_snorm_l6_unorm_nv},
1698 {WINED3DFMT_R5G5_SNORM_L6_UNORM, GL_RGB8_SNORM, GL_RGB8_SNORM, 0,
1699 GL_RGBA, GL_BYTE, 4,
1700 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1701 | WINED3DFMT_FLAG_BUMPMAP,
1702 EXT_TEXTURE_SNORM, convert_r5g5_snorm_l6_unorm_ext},
1703 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, GL_RGB8, GL_RGB8, 0,
1704 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 4,
1705 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1706 | WINED3DFMT_FLAG_BUMPMAP,
1707 WINED3D_GL_EXT_NONE, convert_r8g8_snorm_l8x8_unorm},
1708 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, GL_DSDT8_MAG8_INTENSITY8_NV, GL_DSDT8_MAG8_INTENSITY8_NV, 0,
1709 GL_DSDT_MAG_VIB_NV, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV, 4,
1710 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1711 | WINED3DFMT_FLAG_BUMPMAP,
1712 NV_TEXTURE_SHADER, convert_r8g8_snorm_l8x8_unorm_nv},
1713 {WINED3DFMT_R8G8B8A8_SNORM, GL_RGBA8, GL_RGBA8, 0,
1714 GL_BGRA, GL_UNSIGNED_BYTE, 4,
1715 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1716 | WINED3DFMT_FLAG_BUMPMAP,
1717 WINED3D_GL_EXT_NONE, convert_r8g8b8a8_snorm},
1718 {WINED3DFMT_R8G8B8A8_SNORM, GL_SIGNED_RGBA8_NV, GL_SIGNED_RGBA8_NV, 0,
1719 GL_RGBA, GL_BYTE, 0,
1720 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1721 | WINED3DFMT_FLAG_BUMPMAP,
1722 NV_TEXTURE_SHADER, NULL},
1723 {WINED3DFMT_R8G8B8A8_SNORM, GL_RGBA8_SNORM, GL_RGBA8_SNORM, 0,
1724 GL_RGBA, GL_BYTE, 0,
1725 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1726 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_BUMPMAP,
1727 EXT_TEXTURE_SNORM, NULL},
1728 {WINED3DFMT_R16G16_SNORM, GL_RGB16, GL_RGB16, 0,
1729 GL_BGR, GL_UNSIGNED_SHORT, 6,
1730 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1731 | WINED3DFMT_FLAG_BUMPMAP,
1732 WINED3D_GL_EXT_NONE, convert_r16g16_snorm},
1733 {WINED3DFMT_R16G16_SNORM, GL_SIGNED_HILO16_NV, GL_SIGNED_HILO16_NV, 0,
1734 GL_HILO_NV, GL_SHORT, 0,
1735 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1736 | WINED3DFMT_FLAG_BUMPMAP,
1737 NV_TEXTURE_SHADER, NULL},
1738 {WINED3DFMT_R16G16_SNORM, GL_RG16_SNORM, GL_RG16_SNORM, 0,
1739 GL_RG, GL_SHORT, 0,
1740 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1741 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_BUMPMAP,
1742 EXT_TEXTURE_SNORM, NULL},
1743 {WINED3DFMT_R16G16B16A16_SNORM, GL_RGBA16_SNORM, GL_RGBA16_SNORM, 0,
1744 GL_RGBA, GL_SHORT, 0,
1745 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1746 | WINED3DFMT_FLAG_RENDERTARGET,
1747 EXT_TEXTURE_SNORM, NULL},
1748 {WINED3DFMT_R16_SNORM, GL_R16_SNORM, GL_R16_SNORM, 0,
1749 GL_RED, GL_SHORT, 0,
1750 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1751 | WINED3DFMT_FLAG_RENDERTARGET,
1752 EXT_TEXTURE_SNORM, NULL},
1753 {WINED3DFMT_R8_SNORM, GL_R8_SNORM, GL_R8_SNORM, 0,
1754 GL_RED, GL_BYTE, 0,
1755 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1756 | WINED3DFMT_FLAG_RENDERTARGET,
1757 EXT_TEXTURE_SNORM, NULL},
1758 /* Depth stencil formats */
1759 {WINED3DFMT_D16_LOCKABLE, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, 0,
1760 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1761 WINED3DFMT_FLAG_DEPTH_STENCIL,
1762 WINED3D_GL_EXT_NONE, NULL},
1763 {WINED3DFMT_D16_LOCKABLE, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, 0,
1764 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1765 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH_STENCIL | WINED3DFMT_FLAG_SHADOW,
1766 ARB_DEPTH_TEXTURE, NULL},
1767 {WINED3DFMT_D24_UNORM_S8_UINT, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1768 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0,
1769 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1770 | WINED3DFMT_FLAG_DEPTH_STENCIL | WINED3DFMT_FLAG_SHADOW,
1771 ARB_DEPTH_TEXTURE, NULL},
1772 {WINED3DFMT_D24_UNORM_S8_UINT, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, 0,
1773 GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0,
1774 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1775 | WINED3DFMT_FLAG_DEPTH_STENCIL | WINED3DFMT_FLAG_SHADOW,
1776 EXT_PACKED_DEPTH_STENCIL, NULL},
1777 {WINED3DFMT_X8D24_UNORM, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, 0,
1778 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 4,
1779 WINED3DFMT_FLAG_DEPTH_STENCIL,
1780 WINED3D_GL_EXT_NONE, x8_d24_unorm_upload, x8_d24_unorm_download},
1781 {WINED3DFMT_X8D24_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1782 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 4,
1783 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1784 | WINED3DFMT_FLAG_DEPTH_STENCIL | WINED3DFMT_FLAG_SHADOW,
1785 ARB_DEPTH_TEXTURE, x8_d24_unorm_upload, x8_d24_unorm_download},
1786 {WINED3DFMT_D16_UNORM, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, 0,
1787 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1788 WINED3DFMT_FLAG_DEPTH_STENCIL,
1789 WINED3D_GL_EXT_NONE, NULL},
1790 {WINED3DFMT_D16_UNORM, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT16, 0,
1791 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1792 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1793 | WINED3DFMT_FLAG_DEPTH_STENCIL | WINED3DFMT_FLAG_SHADOW,
1794 ARB_DEPTH_TEXTURE, NULL},
1795 {WINED3DFMT_D32_FLOAT, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT32F, 0,
1796 GL_DEPTH_COMPONENT, GL_FLOAT, 0,
1797 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH_STENCIL | WINED3DFMT_FLAG_SHADOW,
1798 ARB_DEPTH_BUFFER_FLOAT, NULL},
1799 {WINED3DFMT_D32_FLOAT_S8X24_UINT, GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, 0,
1800 GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, 0,
1801 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH_STENCIL | WINED3DFMT_FLAG_SHADOW,
1802 ARB_DEPTH_BUFFER_FLOAT, NULL},
1803 {WINED3DFMT_S8_UINT_D24_FLOAT, GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, 0,
1804 GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, 8,
1805 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH_STENCIL | WINED3DFMT_FLAG_SHADOW,
1806 ARB_DEPTH_BUFFER_FLOAT, convert_s8_uint_d24_float},
1807 {WINED3DFMT_R32G32B32A32_UINT, GL_RGBA32UI, GL_RGBA32UI, 0,
1808 GL_RGBA_INTEGER, GL_UNSIGNED_INT, 0,
1809 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1810 EXT_TEXTURE_INTEGER, NULL},
1811 {WINED3DFMT_R32G32B32A32_SINT, GL_RGBA32I, GL_RGBA32I, 0,
1812 GL_RGBA_INTEGER, GL_INT, 0,
1813 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1814 EXT_TEXTURE_INTEGER, NULL},
1815 /* Vendor-specific formats */
1816 {WINED3DFMT_ATI1N, GL_COMPRESSED_RED_RGTC1, GL_COMPRESSED_RED_RGTC1, 0,
1817 GL_RED, GL_UNSIGNED_BYTE, 0,
1818 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1819 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1820 {WINED3DFMT_ATI2N, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, 0,
1821 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1822 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1823 ATI_TEXTURE_COMPRESSION_3DC, NULL},
1824 {WINED3DFMT_ATI2N, GL_COMPRESSED_RG_RGTC2, GL_COMPRESSED_RG_RGTC2, 0,
1825 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1826 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1827 EXT_TEXTURE_COMPRESSION_RGTC, NULL},
1828 {WINED3DFMT_ATI2N, GL_COMPRESSED_RG_RGTC2, GL_COMPRESSED_RG_RGTC2, 0,
1829 GL_RG, GL_UNSIGNED_BYTE, 0,
1830 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1831 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1832 {WINED3DFMT_INTZ, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, 0,
1833 GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0,
1834 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1835 | WINED3DFMT_FLAG_DEPTH_STENCIL,
1836 EXT_PACKED_DEPTH_STENCIL, NULL},
1837 {WINED3DFMT_NULL, 0, 0, 0,
1838 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1839 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_FBO_ATTACHABLE,
1840 ARB_FRAMEBUFFER_OBJECT, NULL},
1841 /* DirectX 10 HDR formats */
1842 {WINED3DFMT_R9G9B9E5_SHAREDEXP, GL_RGB9_E5_EXT, GL_RGB9_E5_EXT, 0,
1843 GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV_EXT, 0,
1844 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1845 EXT_TEXTURE_SHARED_EXPONENT, NULL},
1848 struct wined3d_format_srgb_info
1850 enum wined3d_format_id srgb_format_id;
1851 enum wined3d_format_id base_format_id;
1854 static const struct wined3d_format_srgb_info format_srgb_info[] =
1856 {WINED3DFMT_R8G8B8A8_UNORM_SRGB, WINED3DFMT_R8G8B8A8_UNORM},
1857 {WINED3DFMT_BC1_UNORM_SRGB, WINED3DFMT_BC1_UNORM},
1858 {WINED3DFMT_BC2_UNORM_SRGB, WINED3DFMT_BC2_UNORM},
1859 {WINED3DFMT_BC3_UNORM_SRGB, WINED3DFMT_BC3_UNORM},
1860 {WINED3DFMT_B8G8R8A8_UNORM_SRGB, WINED3DFMT_B8G8R8A8_UNORM},
1861 {WINED3DFMT_B8G8R8X8_UNORM_SRGB, WINED3DFMT_B8G8R8X8_UNORM},
1862 {WINED3DFMT_BC7_UNORM_SRGB, WINED3DFMT_BC7_UNORM},
1865 static inline int get_format_idx(enum wined3d_format_id format_id)
1867 unsigned int i;
1869 if (format_id < WINED3D_FORMAT_FOURCC_BASE)
1870 return format_id;
1872 for (i = 0; i < ARRAY_SIZE(format_index_remap); ++i)
1874 if (format_index_remap[i].id == format_id)
1875 return format_index_remap[i].idx;
1878 return -1;
1881 static struct wined3d_format_gl *wined3d_format_gl_mutable(struct wined3d_format *format)
1883 return CONTAINING_RECORD(format, struct wined3d_format_gl, f);
1886 static struct wined3d_format_vk *wined3d_format_vk_mutable(struct wined3d_format *format)
1888 return CONTAINING_RECORD(format, struct wined3d_format_vk, f);
1891 static struct wined3d_format *get_format_by_idx(const struct wined3d_adapter *adapter, int fmt_idx)
1893 return (struct wined3d_format *)((BYTE *)adapter->formats + fmt_idx * adapter->format_size);
1896 static struct wined3d_format_gl *get_format_gl_by_idx(const struct wined3d_adapter *adapter, int fmt_idx)
1898 return wined3d_format_gl_mutable(get_format_by_idx(adapter, fmt_idx));
1901 static struct wined3d_format *get_format_internal(const struct wined3d_adapter *adapter,
1902 enum wined3d_format_id format_id)
1904 int fmt_idx;
1906 if ((fmt_idx = get_format_idx(format_id)) == -1)
1908 ERR("Format %s (%#x) not found.\n", debug_d3dformat(format_id), format_id);
1909 return NULL;
1912 return get_format_by_idx(adapter, fmt_idx);
1915 static struct wined3d_format_gl *get_format_gl_internal(const struct wined3d_adapter *adapter,
1916 enum wined3d_format_id format_id)
1918 struct wined3d_format *format;
1920 if ((format = get_format_internal(adapter, format_id)))
1921 return wined3d_format_gl_mutable(format);
1923 return NULL;
1926 static void copy_format(const struct wined3d_adapter *adapter,
1927 struct wined3d_format *dst_format, const struct wined3d_format *src_format)
1929 enum wined3d_format_id id = dst_format->id;
1930 memcpy(dst_format, src_format, adapter->format_size);
1931 dst_format->id = id;
1934 static void format_set_flag(struct wined3d_format *format, unsigned int flag)
1936 unsigned int i;
1938 for (i = 0; i < ARRAY_SIZE(format->flags); ++i)
1939 format->flags[i] |= flag;
1942 static void format_clear_flag(struct wined3d_format *format, unsigned int flag)
1944 unsigned int i;
1946 for (i = 0; i < ARRAY_SIZE(format->flags); ++i)
1947 format->flags[i] &= ~flag;
1950 static enum wined3d_channel_type map_channel_type(char t)
1952 switch (t)
1954 case 'u':
1955 return WINED3D_CHANNEL_TYPE_UNORM;
1956 case 'i':
1957 return WINED3D_CHANNEL_TYPE_SNORM;
1958 case 'U':
1959 return WINED3D_CHANNEL_TYPE_UINT;
1960 case 'I':
1961 return WINED3D_CHANNEL_TYPE_SINT;
1962 case 'F':
1963 return WINED3D_CHANNEL_TYPE_FLOAT;
1964 case 'D':
1965 return WINED3D_CHANNEL_TYPE_DEPTH;
1966 case 'S':
1967 return WINED3D_CHANNEL_TYPE_STENCIL;
1968 case 'X':
1969 return WINED3D_CHANNEL_TYPE_UNUSED;
1970 default:
1971 ERR("Invalid channel type '%c'.\n", t);
1972 return WINED3D_CHANNEL_TYPE_NONE;
1976 static BOOL init_format_base_info(struct wined3d_adapter *adapter)
1978 struct wined3d_format *format;
1979 unsigned int i, j;
1981 for (i = 0; i < ARRAY_SIZE(formats); ++i)
1983 if (!(format = get_format_internal(adapter, formats[i].id)))
1984 return FALSE;
1986 format->id = formats[i].id;
1987 format->red_size = formats[i].red_size;
1988 format->green_size = formats[i].green_size;
1989 format->blue_size = formats[i].blue_size;
1990 format->alpha_size = formats[i].alpha_size;
1991 format->red_offset = formats[i].red_offset;
1992 format->green_offset = formats[i].green_offset;
1993 format->blue_offset = formats[i].blue_offset;
1994 format->alpha_offset = formats[i].alpha_offset;
1995 format->byte_count = formats[i].bpp;
1996 format->depth_size = formats[i].depth_size;
1997 format->stencil_size = formats[i].stencil_size;
1998 format->block_width = 1;
1999 format->block_height = 1;
2000 format->block_byte_count = formats[i].bpp;
2003 for (i = 0; i < ARRAY_SIZE(typed_formats); ++i)
2005 struct wined3d_format *typeless_format;
2006 unsigned int component_count = 0;
2007 DWORD flags = 0;
2009 if (!(format = get_format_internal(adapter, typed_formats[i].id)))
2010 return FALSE;
2012 if (!(typeless_format = get_format_internal(adapter, typed_formats[i].typeless_id)))
2013 return FALSE;
2015 format->id = typed_formats[i].id;
2016 format->red_size = typeless_format->red_size;
2017 format->green_size = typeless_format->green_size;
2018 format->blue_size = typeless_format->blue_size;
2019 format->alpha_size = typeless_format->alpha_size;
2020 format->red_offset = typeless_format->red_offset;
2021 format->green_offset = typeless_format->green_offset;
2022 format->blue_offset = typeless_format->blue_offset;
2023 format->alpha_offset = typeless_format->alpha_offset;
2024 format->byte_count = typeless_format->byte_count;
2025 format->depth_size = typeless_format->depth_size;
2026 format->stencil_size = typeless_format->stencil_size;
2027 format->block_width = typeless_format->block_width;
2028 format->block_height = typeless_format->block_height;
2029 format->block_byte_count = typeless_format->block_byte_count;
2030 format->typeless_id = typeless_format->id;
2032 typeless_format->typeless_id = typeless_format->id;
2034 for (j = 0; j < strlen(typed_formats[i].channels); ++j)
2036 enum wined3d_channel_type channel_type = map_channel_type(typed_formats[i].channels[j]);
2038 if (channel_type == WINED3D_CHANNEL_TYPE_UNORM || channel_type == WINED3D_CHANNEL_TYPE_SNORM)
2039 flags |= WINED3DFMT_FLAG_NORMALISED;
2040 if (channel_type == WINED3D_CHANNEL_TYPE_UINT || channel_type == WINED3D_CHANNEL_TYPE_SINT)
2041 flags |= WINED3DFMT_FLAG_INTEGER;
2042 if (channel_type == WINED3D_CHANNEL_TYPE_FLOAT)
2043 flags |= WINED3DFMT_FLAG_FLOAT;
2044 if (channel_type != WINED3D_CHANNEL_TYPE_UNUSED)
2045 ++component_count;
2047 if (channel_type == WINED3D_CHANNEL_TYPE_DEPTH && !format->depth_size)
2049 format->depth_size = format->red_size;
2050 format->red_size = format->red_offset = 0;
2053 if (channel_type == WINED3D_CHANNEL_TYPE_STENCIL && !format->stencil_size)
2055 format->stencil_size = format->green_size;
2056 format->green_size = format->green_offset = 0;
2060 format->component_count = component_count;
2061 format_set_flag(format, flags);
2064 for (i = 0; i < ARRAY_SIZE(ddi_formats); ++i)
2066 if (!(format = get_format_internal(adapter, ddi_formats[i].id)))
2067 return FALSE;
2069 format->ddi_format = ddi_formats[i].ddi_format;
2072 for (i = 0; i < ARRAY_SIZE(format_base_flags); ++i)
2074 if (!(format = get_format_internal(adapter, format_base_flags[i].id)))
2075 return FALSE;
2077 format_set_flag(format, format_base_flags[i].flags);
2080 return TRUE;
2083 static BOOL init_format_block_info(struct wined3d_adapter *adapter)
2085 struct wined3d_format *format;
2086 unsigned int i;
2088 for (i = 0; i < ARRAY_SIZE(format_block_info); ++i)
2090 if (!(format = get_format_internal(adapter, format_block_info[i].id)))
2091 return FALSE;
2093 format->block_width = format_block_info[i].block_width;
2094 format->block_height = format_block_info[i].block_height;
2095 format->block_byte_count = format_block_info[i].block_byte_count;
2096 format_set_flag(format, WINED3DFMT_FLAG_BLOCKS | format_block_info[i].flags);
2099 return TRUE;
2102 /* Most compressed formats are not supported for 3D textures by OpenGL.
2104 * In the case of the S3TC/DXTn formats, NV_texture_compression_vtc provides
2105 * these formats for 3D textures, but unfortunately the block layout is
2106 * different from the one used by Direct3D.
2108 * Since applications either don't check format availability at all before
2109 * using these, or refuse to run without them, we decompress them on upload.
2111 * Affected applications include "Heroes VI", "From Dust", "Halo Online" and
2112 * "Eldorado". */
2113 static BOOL init_format_decompress_info(struct wined3d_adapter *adapter)
2115 struct wined3d_format *format;
2116 unsigned int i;
2118 for (i = 0; i < ARRAY_SIZE(format_decompress_info); ++i)
2120 if (!(format = get_format_internal(adapter, format_decompress_info[i].id)))
2121 return FALSE;
2123 format->flags[WINED3D_GL_RES_TYPE_TEX_3D] |= WINED3DFMT_FLAG_DECOMPRESS;
2124 format->decompress = format_decompress_info[i].decompress;
2127 return TRUE;
2130 static BOOL init_srgb_formats(struct wined3d_adapter *adapter)
2132 struct wined3d_format *format, *srgb_format;
2133 unsigned int i;
2135 for (i = 0; i < ARRAY_SIZE(format_srgb_info); ++i)
2137 if (!(srgb_format = get_format_internal(adapter, format_srgb_info[i].srgb_format_id)))
2138 return FALSE;
2139 if (!(format = get_format_internal(adapter, format_srgb_info[i].base_format_id)))
2140 return FALSE;
2142 copy_format(adapter, srgb_format, format);
2145 return TRUE;
2148 static GLenum wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type)
2150 switch (type)
2152 case WINED3D_GL_RES_TYPE_TEX_1D:
2153 return GL_TEXTURE_1D;
2154 case WINED3D_GL_RES_TYPE_TEX_2D:
2155 return GL_TEXTURE_2D;
2156 case WINED3D_GL_RES_TYPE_TEX_3D:
2157 return GL_TEXTURE_3D;
2158 case WINED3D_GL_RES_TYPE_TEX_CUBE:
2159 return GL_TEXTURE_CUBE_MAP_ARB;
2160 case WINED3D_GL_RES_TYPE_TEX_RECT:
2161 return GL_TEXTURE_RECTANGLE_ARB;
2162 case WINED3D_GL_RES_TYPE_BUFFER:
2163 return GL_TEXTURE_2D; /* TODO: GL_TEXTURE_BUFFER. */
2164 case WINED3D_GL_RES_TYPE_RB:
2165 return GL_RENDERBUFFER;
2166 case WINED3D_GL_RES_TYPE_COUNT:
2167 break;
2169 ERR("Unexpected GL resource type %u.\n", type);
2170 return 0;
2173 static void delete_fbo_attachment(const struct wined3d_gl_info *gl_info,
2174 enum wined3d_gl_resource_type d3d_type, GLuint object)
2176 switch (d3d_type)
2178 case WINED3D_GL_RES_TYPE_TEX_1D:
2179 case WINED3D_GL_RES_TYPE_TEX_2D:
2180 case WINED3D_GL_RES_TYPE_TEX_RECT:
2181 case WINED3D_GL_RES_TYPE_TEX_3D:
2182 case WINED3D_GL_RES_TYPE_TEX_CUBE:
2183 gl_info->gl_ops.gl.p_glDeleteTextures(1, &object);
2184 break;
2186 case WINED3D_GL_RES_TYPE_RB:
2187 gl_info->fbo_ops.glDeleteRenderbuffers(1, &object);
2188 break;
2190 case WINED3D_GL_RES_TYPE_BUFFER:
2191 case WINED3D_GL_RES_TYPE_COUNT:
2192 break;
2196 static void create_and_bind_fbo_attachment(const struct wined3d_gl_info *gl_info,
2197 const struct wined3d_format_gl *format_gl,
2198 enum wined3d_gl_resource_type d3d_type, GLuint *object, GLenum internal)
2200 GLenum format = format_gl->format;
2201 GLenum type = format_gl->type;
2202 GLenum attach_type;
2204 attach_type = format_gl->f.depth_size ? GL_DEPTH_ATTACHMENT : GL_COLOR_ATTACHMENT0;
2205 switch (d3d_type)
2207 case WINED3D_GL_RES_TYPE_TEX_1D:
2208 gl_info->gl_ops.gl.p_glGenTextures(1, object);
2209 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D, *object);
2210 gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, 0, internal, 16, 0, format, type, NULL);
2211 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2212 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2214 gl_info->fbo_ops.glFramebufferTexture1D(GL_FRAMEBUFFER, attach_type, GL_TEXTURE_1D, *object, 0);
2215 if (format_gl->f.stencil_size)
2216 gl_info->fbo_ops.glFramebufferTexture1D(GL_FRAMEBUFFER,
2217 GL_STENCIL_ATTACHMENT, GL_TEXTURE_1D, *object, 0);
2218 break;
2220 case WINED3D_GL_RES_TYPE_TEX_2D:
2221 case WINED3D_GL_RES_TYPE_TEX_RECT:
2222 gl_info->gl_ops.gl.p_glGenTextures(1, object);
2223 gl_info->gl_ops.gl.p_glBindTexture(wined3d_gl_type_to_enum(d3d_type), *object);
2224 gl_info->gl_ops.gl.p_glTexImage2D(wined3d_gl_type_to_enum(d3d_type), 0, internal, 16, 16, 0,
2225 format, type, NULL);
2226 gl_info->gl_ops.gl.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2227 gl_info->gl_ops.gl.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2229 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, attach_type,
2230 wined3d_gl_type_to_enum(d3d_type), *object, 0);
2231 if (format_gl->f.stencil_size)
2232 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
2233 wined3d_gl_type_to_enum(d3d_type), *object, 0);
2234 break;
2236 case WINED3D_GL_RES_TYPE_TEX_3D:
2237 gl_info->gl_ops.gl.p_glGenTextures(1, object);
2238 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, *object);
2239 GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D, 0, internal, 16, 16, 16, 0, format, type, NULL));
2240 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2241 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2243 gl_info->fbo_ops.glFramebufferTexture3D(GL_FRAMEBUFFER, attach_type, GL_TEXTURE_3D, *object, 0, 0);
2244 if (format_gl->f.stencil_size)
2245 gl_info->fbo_ops.glFramebufferTexture3D(GL_FRAMEBUFFER,
2246 GL_STENCIL_ATTACHMENT, GL_TEXTURE_3D, *object, 0, 0);
2247 break;
2249 case WINED3D_GL_RES_TYPE_TEX_CUBE:
2250 gl_info->gl_ops.gl.p_glGenTextures(1, object);
2251 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, *object);
2252 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, internal, 16, 16, 0,
2253 format, type, NULL);
2254 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, internal, 16, 16, 0,
2255 format, type, NULL);
2256 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, internal, 16, 16, 0,
2257 format, type, NULL);
2258 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, internal, 16, 16, 0,
2259 format, type, NULL);
2260 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, internal, 16, 16, 0,
2261 format, type, NULL);
2262 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, internal, 16, 16, 0,
2263 format, type, NULL);
2264 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2265 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2267 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, attach_type,
2268 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, *object, 0);
2269 if (format_gl->f.stencil_size)
2270 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
2271 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, *object, 0);
2272 break;
2274 case WINED3D_GL_RES_TYPE_RB:
2275 gl_info->fbo_ops.glGenRenderbuffers(1, object);
2276 gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, *object);
2277 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, internal, 16, 16);
2278 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, attach_type, GL_RENDERBUFFER, *object);
2279 if (format_gl->f.stencil_size)
2280 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER,
2281 GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, *object);
2282 break;
2284 case WINED3D_GL_RES_TYPE_BUFFER:
2285 case WINED3D_GL_RES_TYPE_COUNT:
2286 break;
2289 /* Ideally we'd skip all formats already known not to work on textures
2290 * by checking for WINED3DFMT_FLAG_TEXTURE here. However, we want to
2291 * know if we can attach WINED3DFMT_P8_UINT textures to FBOs, and this
2292 * format never has WINED3DFMT_FLAG_TEXTURE set. Instead, swallow GL
2293 * errors generated by invalid formats. */
2294 while (gl_info->gl_ops.gl.p_glGetError());
2297 static void draw_test_quad(struct wined3d_caps_gl_ctx *ctx, const struct wined3d_vec3 *geometry,
2298 const struct wined3d_color *color)
2300 const struct wined3d_gl_info *gl_info = ctx->gl_info;
2301 static const struct wined3d_vec3 default_geometry[] =
2303 {-1.0f, -1.0f, 0.0f},
2304 { 1.0f, -1.0f, 0.0f},
2305 {-1.0f, 1.0f, 0.0f},
2306 { 1.0f, 1.0f, 0.0f},
2308 static const char vs_core_header[] =
2309 "#version 150\n"
2310 "in vec4 pos;\n"
2311 "in vec4 color;\n"
2312 "out vec4 out_color;\n"
2313 "\n";
2314 static const char vs_legacy_header[] =
2315 "#version 120\n"
2316 "attribute vec4 pos;\n"
2317 "attribute vec4 color;\n"
2318 "varying vec4 out_color;\n"
2319 "\n";
2320 static const char vs_body[] =
2321 "void main()\n"
2322 "{\n"
2323 " gl_Position = pos;\n"
2324 " out_color = color;\n"
2325 "}\n";
2326 static const char fs_core[] =
2327 "#version 150\n"
2328 "in vec4 out_color;\n"
2329 "out vec4 fragment_color;\n"
2330 "\n"
2331 "void main()\n"
2332 "{\n"
2333 " fragment_color = out_color;\n"
2334 "}\n";
2335 static const char fs_legacy[] =
2336 "#version 120\n"
2337 "varying vec4 out_color;\n"
2338 "\n"
2339 "void main()\n"
2340 "{\n"
2341 " gl_FragData[0] = out_color;\n"
2342 "}\n";
2343 const char *source[2];
2344 GLuint vs_id, fs_id;
2345 unsigned int i;
2347 if (!geometry)
2348 geometry = default_geometry;
2350 if (!gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] || !gl_info->supported[ARB_VERTEX_SHADER]
2351 || !gl_info->supported[ARB_FRAGMENT_SHADER])
2353 gl_info->gl_ops.gl.p_glDisable(GL_LIGHTING);
2354 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
2355 gl_info->gl_ops.gl.p_glLoadIdentity();
2356 gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
2357 gl_info->gl_ops.gl.p_glLoadIdentity();
2359 gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
2360 gl_info->gl_ops.gl.p_glColor4f(color->r, color->g, color->b, color->a);
2361 for (i = 0; i < 4; ++i)
2362 gl_info->gl_ops.gl.p_glVertex3fv(&geometry[i].x);
2363 gl_info->gl_ops.gl.p_glEnd();
2364 checkGLcall("draw quad");
2365 return;
2368 if (!ctx->test_vbo)
2369 GL_EXTCALL(glGenBuffers(1, &ctx->test_vbo));
2370 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, ctx->test_vbo));
2371 GL_EXTCALL(glBufferData(GL_ARRAY_BUFFER, sizeof(struct wined3d_vec3) * 4, geometry, GL_STREAM_DRAW));
2372 GL_EXTCALL(glVertexAttribPointer(0, 3, GL_FLOAT, FALSE, 0, NULL));
2373 GL_EXTCALL(glVertexAttrib4f(1, color->r, color->g, color->b, color->a));
2374 GL_EXTCALL(glEnableVertexAttribArray(0));
2375 GL_EXTCALL(glDisableVertexAttribArray(1));
2377 if (!ctx->test_program_id)
2379 BOOL use_glsl_150 = gl_info->glsl_version >= MAKEDWORD_VERSION(1, 50);
2381 ctx->test_program_id = GL_EXTCALL(glCreateProgram());
2383 vs_id = GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER));
2384 source[0] = use_glsl_150 ? vs_core_header : vs_legacy_header;
2385 source[1] = vs_body;
2386 GL_EXTCALL(glShaderSource(vs_id, 2, source, NULL));
2387 GL_EXTCALL(glAttachShader(ctx->test_program_id, vs_id));
2388 GL_EXTCALL(glDeleteShader(vs_id));
2390 fs_id = GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER));
2391 source[0] = use_glsl_150 ? fs_core : fs_legacy;
2392 GL_EXTCALL(glShaderSource(fs_id, 1, source, NULL));
2393 GL_EXTCALL(glAttachShader(ctx->test_program_id, fs_id));
2394 GL_EXTCALL(glDeleteShader(fs_id));
2396 GL_EXTCALL(glBindAttribLocation(ctx->test_program_id, 0, "pos"));
2397 GL_EXTCALL(glBindAttribLocation(ctx->test_program_id, 1, "color"));
2399 if (use_glsl_150)
2400 GL_EXTCALL(glBindFragDataLocation(ctx->test_program_id, 0, "fragment_color"));
2402 GL_EXTCALL(glCompileShader(vs_id));
2403 print_glsl_info_log(gl_info, vs_id, FALSE);
2404 GL_EXTCALL(glCompileShader(fs_id));
2405 print_glsl_info_log(gl_info, fs_id, FALSE);
2406 GL_EXTCALL(glLinkProgram(ctx->test_program_id));
2407 shader_glsl_validate_link(gl_info, ctx->test_program_id);
2409 GL_EXTCALL(glUseProgram(ctx->test_program_id));
2411 gl_info->gl_ops.gl.p_glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
2413 GL_EXTCALL(glUseProgram(0));
2414 GL_EXTCALL(glDisableVertexAttribArray(0));
2415 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, 0));
2416 checkGLcall("draw quad");
2419 /* Context activation is done by the caller. */
2420 static void check_fbo_compat(struct wined3d_caps_gl_ctx *ctx, struct wined3d_format_gl *format)
2422 /* Check if the default internal format is supported as a frame buffer
2423 * target, otherwise fall back to the render target internal.
2425 * Try to stick to the standard format if possible, this limits precision differences. */
2426 static const struct wined3d_color black = {0.0f, 0.0f, 0.0f, 1.0f};
2427 static const struct wined3d_color half_transparent_red = {1.0f, 0.0f, 0.0f, 0.5f};
2428 const struct wined3d_gl_info *gl_info = ctx->gl_info;
2429 GLenum status, rt_internal = format->rt_internal;
2430 GLuint object, color_rb;
2431 enum wined3d_gl_resource_type type;
2432 BOOL fallback_fmt_used = FALSE, regular_fmt_used = FALSE;
2434 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
2436 for (type = 0; type < ARRAY_SIZE(format->f.flags); ++type)
2438 const char *type_string = "color";
2440 if (type == WINED3D_GL_RES_TYPE_BUFFER)
2441 continue;
2443 create_and_bind_fbo_attachment(gl_info, format, type, &object, format->internal);
2445 if (format->f.flags[type] & WINED3DFMT_FLAG_DEPTH_STENCIL)
2447 gl_info->fbo_ops.glGenRenderbuffers(1, &color_rb);
2448 gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, color_rb);
2449 if (type == WINED3D_GL_RES_TYPE_TEX_1D)
2450 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 16, 1);
2451 else
2452 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 16, 16);
2454 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER,
2455 GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color_rb);
2456 checkGLcall("Create and attach color rb attachment");
2457 type_string = "depth / stencil";
2460 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
2461 checkGLcall("Framebuffer format check");
2463 if (status == GL_FRAMEBUFFER_COMPLETE)
2465 TRACE("Format %s is supported as FBO %s attachment, type %u.\n",
2466 debug_d3dformat(format->f.id), type_string, type);
2467 format->f.flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE;
2468 format->rt_internal = format->internal;
2469 regular_fmt_used = TRUE;
2471 else
2473 if (!rt_internal)
2475 if (format->f.flags[type] & (WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_DEPTH_STENCIL))
2477 WARN("Format %s with rendertarget flag is not supported as FBO color attachment (type %u),"
2478 " and no fallback specified.\n", debug_d3dformat(format->f.id), type);
2479 format->f.flags[type] &= ~(WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_DEPTH_STENCIL);
2481 else
2483 TRACE("Format %s is not supported as FBO %s attachment, type %u.\n",
2484 debug_d3dformat(format->f.id), type_string, type);
2486 format->rt_internal = format->internal;
2488 else
2490 TRACE("Format %s is not supported as FBO %s attachment (type %u),"
2491 " trying rtInternal format as fallback.\n",
2492 debug_d3dformat(format->f.id), type_string, type);
2494 while (gl_info->gl_ops.gl.p_glGetError());
2496 delete_fbo_attachment(gl_info, type, object);
2497 create_and_bind_fbo_attachment(gl_info, format, type, &object, format->rt_internal);
2499 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
2500 checkGLcall("Framebuffer format check");
2502 if (status == GL_FRAMEBUFFER_COMPLETE)
2504 TRACE("Format %s rtInternal format is supported as FBO %s attachment, type %u.\n",
2505 debug_d3dformat(format->f.id), type_string, type);
2506 fallback_fmt_used = TRUE;
2508 else
2510 WARN("Format %s rtInternal format is not supported as FBO %s attachment, type %u.\n",
2511 debug_d3dformat(format->f.id), type_string, type);
2512 format->f.flags[type] &= ~(WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_DEPTH_STENCIL);
2517 if (status == GL_FRAMEBUFFER_COMPLETE
2518 && ((format->f.flags[type] & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)
2519 || !(gl_info->quirks & WINED3D_QUIRK_LIMITED_TEX_FILTERING))
2520 && !(format->f.flags[type] & WINED3DFMT_FLAG_INTEGER)
2521 && format->f.id != WINED3DFMT_NULL && format->f.id != WINED3DFMT_P8_UINT
2522 && format->format != GL_LUMINANCE && format->format != GL_LUMINANCE_ALPHA
2523 && (format->f.red_size || format->f.alpha_size))
2525 DWORD readback[16 * 16 * 16], color = 0, r_range, a_range;
2526 BYTE r, a;
2527 BOOL match = TRUE;
2528 GLuint rb;
2530 if (gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
2532 gl_info->fbo_ops.glGenRenderbuffers(1, &rb);
2533 gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, rb);
2534 if (type == WINED3D_GL_RES_TYPE_TEX_1D)
2535 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 16, 1);
2536 else
2537 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 16, 16);
2538 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb);
2539 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb);
2540 checkGLcall("RB attachment");
2543 gl_info->gl_ops.gl.p_glEnable(GL_BLEND);
2544 gl_info->gl_ops.gl.p_glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
2545 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
2546 if (gl_info->gl_ops.gl.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION)
2548 while (gl_info->gl_ops.gl.p_glGetError());
2549 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2550 debug_d3dformat(format->f.id), type);
2551 format->f.flags[type] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
2553 else
2555 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
2556 if (type == WINED3D_GL_RES_TYPE_TEX_1D)
2557 gl_info->gl_ops.gl.p_glViewport(0, 0, 16, 1);
2558 else
2559 gl_info->gl_ops.gl.p_glViewport(0, 0, 16, 16);
2560 gl_info->gl_ops.gl.p_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2562 draw_test_quad(ctx, NULL, &black);
2564 gl_info->gl_ops.gl.p_glEnable(GL_BLEND);
2566 draw_test_quad(ctx, NULL, &half_transparent_red);
2568 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
2570 switch (type)
2572 case WINED3D_GL_RES_TYPE_TEX_1D:
2573 /* Rebinding texture to workaround a fglrx bug. */
2574 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D, object);
2575 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_1D, 0, GL_BGRA,
2576 GL_UNSIGNED_INT_8_8_8_8_REV, readback);
2577 color = readback[7];
2578 break;
2580 case WINED3D_GL_RES_TYPE_TEX_2D:
2581 case WINED3D_GL_RES_TYPE_TEX_3D:
2582 case WINED3D_GL_RES_TYPE_TEX_RECT:
2583 /* Rebinding texture to workaround a fglrx bug. */
2584 gl_info->gl_ops.gl.p_glBindTexture(wined3d_gl_type_to_enum(type), object);
2585 gl_info->gl_ops.gl.p_glGetTexImage(wined3d_gl_type_to_enum(type), 0, GL_BGRA,
2586 GL_UNSIGNED_INT_8_8_8_8_REV, readback);
2587 color = readback[7 * 16 + 7];
2588 break;
2590 case WINED3D_GL_RES_TYPE_TEX_CUBE:
2591 /* Rebinding texture to workaround a fglrx bug. */
2592 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, object);
2593 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL_BGRA,
2594 GL_UNSIGNED_INT_8_8_8_8_REV, readback);
2595 color = readback[7 * 16 + 7];
2596 break;
2598 case WINED3D_GL_RES_TYPE_RB:
2599 gl_info->gl_ops.gl.p_glReadPixels(0, 0, 16, 16,
2600 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, readback);
2601 color = readback[7 * 16 + 7];
2602 break;
2604 case WINED3D_GL_RES_TYPE_BUFFER:
2605 case WINED3D_GL_RES_TYPE_COUNT:
2606 color = 0;
2607 break;
2609 checkGLcall("Post-pixelshader blending check");
2611 a = color >> 24;
2612 r = (color & 0x00ff0000u) >> 16;
2614 r_range = format->f.red_size < 8 ? 1u << (8 - format->f.red_size) : 1;
2615 a_range = format->f.alpha_size < 8 ? 1u << (8 - format->f.alpha_size) : 1;
2616 if (format->f.red_size && (r < 0x7f - r_range || r > 0x7f + r_range))
2617 match = FALSE;
2618 else if (format->f.alpha_size > 1 && (a < 0xbf - a_range || a > 0xbf + a_range))
2619 match = FALSE;
2620 if (!match)
2622 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2623 debug_d3dformat(format->f.id), type);
2624 TRACE("Color output: %#x\n", color);
2625 format->f.flags[type] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
2627 else
2629 TRACE("Format %s supports post-pixelshader blending, type %u.\n",
2630 debug_d3dformat(format->f.id), type);
2631 TRACE("Color output: %#x\n", color);
2632 format->f.flags[type] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
2636 if (gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
2638 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
2639 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
2640 gl_info->fbo_ops.glDeleteRenderbuffers(1, &rb);
2641 checkGLcall("RB cleanup");
2645 if (format->internal != format->srgb_internal)
2647 delete_fbo_attachment(gl_info, type, object);
2648 create_and_bind_fbo_attachment(gl_info, format, type, &object, format->srgb_internal);
2650 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
2651 checkGLcall("Framebuffer format check");
2653 if (status == GL_FRAMEBUFFER_COMPLETE)
2655 TRACE("Format %s's sRGB format is FBO attachable, type %u.\n",
2656 debug_d3dformat(format->f.id), type);
2657 format->f.flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
2658 if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
2659 format->internal = format->srgb_internal;
2661 else
2663 WARN("Format %s's sRGB format is not FBO attachable, type %u.\n",
2664 debug_d3dformat(format->f.id), type);
2665 format_clear_flag(&format->f, WINED3DFMT_FLAG_SRGB_WRITE);
2668 else if (status == GL_FRAMEBUFFER_COMPLETE)
2669 format->f.flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
2671 if (format->f.flags[type] & WINED3DFMT_FLAG_DEPTH_STENCIL)
2673 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
2674 gl_info->fbo_ops.glDeleteRenderbuffers(1, &color_rb);
2677 delete_fbo_attachment(gl_info, type, object);
2678 checkGLcall("Framebuffer format check cleanup");
2681 if (fallback_fmt_used && regular_fmt_used)
2683 FIXME("Format %s needs different render target formats for different resource types.\n",
2684 debug_d3dformat(format->f.id));
2685 format_clear_flag(&format->f, WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_DEPTH_STENCIL
2686 | WINED3DFMT_FLAG_FBO_ATTACHABLE | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
2687 | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING);
2691 static void query_format_flag(struct wined3d_gl_info *gl_info, struct wined3d_format_gl *format,
2692 GLint internal, GLenum pname, DWORD flag, const char *string)
2694 GLint value;
2695 enum wined3d_gl_resource_type type;
2697 for (type = 0; type < ARRAY_SIZE(format->f.flags); ++type)
2699 gl_info->gl_ops.ext.p_glGetInternalformativ(wined3d_gl_type_to_enum(type), internal, pname, 1, &value);
2700 if (value == GL_FULL_SUPPORT)
2702 TRACE("Format %s supports %s, resource type %u.\n", debug_d3dformat(format->f.id), string, type);
2703 format->f.flags[type] |= flag;
2705 else
2707 TRACE("Format %s doesn't support %s, resource type %u.\n", debug_d3dformat(format->f.id), string, type);
2708 format->f.flags[type] &= ~flag;
2713 /* Context activation is done by the caller. */
2714 static void init_format_fbo_compat_info(const struct wined3d_adapter *adapter,
2715 struct wined3d_caps_gl_ctx *ctx)
2717 const struct wined3d_gl_info *gl_info = ctx->gl_info;
2718 unsigned int i, type;
2719 GLuint fbo;
2721 if (gl_info->supported[ARB_INTERNALFORMAT_QUERY2])
2723 for (i = 0; i < WINED3D_FORMAT_COUNT; ++i)
2725 struct wined3d_format_gl *format = get_format_gl_by_idx(adapter, i);
2726 BOOL fallback_fmt_used = FALSE, regular_fmt_used = FALSE;
2727 GLenum rt_internal = format->rt_internal;
2728 GLint value;
2730 if (!format->internal)
2731 continue;
2733 for (type = 0; type < ARRAY_SIZE(format->f.flags); ++type)
2735 gl_info->gl_ops.ext.p_glGetInternalformativ(wined3d_gl_type_to_enum(type),
2736 format->internal, GL_FRAMEBUFFER_RENDERABLE, 1, &value);
2737 if (value == GL_FULL_SUPPORT)
2739 TRACE("Format %s is supported as FBO color attachment, resource type %u.\n",
2740 debug_d3dformat(format->f.id), type);
2741 format->f.flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE;
2742 format->rt_internal = format->internal;
2743 regular_fmt_used = TRUE;
2745 gl_info->gl_ops.ext.p_glGetInternalformativ(wined3d_gl_type_to_enum(type),
2746 format->internal, GL_FRAMEBUFFER_BLEND, 1, &value);
2747 if (value == GL_FULL_SUPPORT)
2749 TRACE("Format %s supports post-pixelshader blending, resource type %u.\n",
2750 debug_d3dformat(format->f.id), type);
2751 format->f.flags[type] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
2753 else
2755 TRACE("Format %s doesn't support post-pixelshader blending, resource typed %u.\n",
2756 debug_d3dformat(format->f.id), type);
2757 format->f.flags[type] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
2760 else
2762 if (!rt_internal)
2764 if (format->f.flags[type] & WINED3DFMT_FLAG_RENDERTARGET)
2766 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
2767 " and no fallback specified, resource type %u.\n",
2768 debug_d3dformat(format->f.id), type);
2769 format->f.flags[type] &= ~WINED3DFMT_FLAG_RENDERTARGET;
2771 else
2772 TRACE("Format %s is not supported as FBO color attachment,"
2773 " resource type %u.\n", debug_d3dformat(format->f.id), type);
2774 format->rt_internal = format->internal;
2776 else
2778 gl_info->gl_ops.ext.p_glGetInternalformativ(wined3d_gl_type_to_enum(type),
2779 rt_internal, GL_FRAMEBUFFER_RENDERABLE, 1, &value);
2780 if (value == GL_FULL_SUPPORT)
2782 TRACE("Format %s rtInternal format is supported as FBO color attachment,"
2783 " resource type %u.\n", debug_d3dformat(format->f.id), type);
2784 fallback_fmt_used = TRUE;
2786 else
2788 WARN("Format %s rtInternal format is not supported as FBO color attachment,"
2789 " resource type %u.\n", debug_d3dformat(format->f.id), type);
2790 format->f.flags[type] &= ~WINED3DFMT_FLAG_RENDERTARGET;
2795 if (format->internal != format->srgb_internal)
2797 gl_info->gl_ops.ext.p_glGetInternalformativ(wined3d_gl_type_to_enum(type),
2798 format->srgb_internal, GL_FRAMEBUFFER_RENDERABLE, 1, &value);
2799 if (value == GL_FULL_SUPPORT)
2801 TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n",
2802 debug_d3dformat(format->f.id), type);
2803 format->f.flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
2804 if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
2805 format->internal = format->srgb_internal;
2807 else
2809 WARN("Format %s's sRGB format is not FBO attachable, resource type %u.\n",
2810 debug_d3dformat(format->f.id), type);
2811 format_clear_flag(&format->f, WINED3DFMT_FLAG_SRGB_WRITE);
2814 else if (format->f.flags[type] & WINED3DFMT_FLAG_FBO_ATTACHABLE)
2815 format->f.flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
2818 if (fallback_fmt_used && regular_fmt_used)
2820 FIXME("Format %s needs different render target formats for different resource types.\n",
2821 debug_d3dformat(format->f.id));
2822 format_clear_flag(&format->f, WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_FBO_ATTACHABLE
2823 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING);
2826 return;
2829 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
2831 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
2832 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2833 gl_info->gl_ops.gl.p_glDrawBuffer(GL_COLOR_ATTACHMENT0);
2834 gl_info->gl_ops.gl.p_glReadBuffer(GL_COLOR_ATTACHMENT0);
2837 for (i = 0; i < WINED3D_FORMAT_COUNT; ++i)
2839 struct wined3d_format_gl *format = get_format_gl_by_idx(adapter, i);
2841 if (!format->internal)
2842 continue;
2844 if (format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_COMPRESSED)
2846 TRACE("Skipping format %s because it's a compressed format.\n",
2847 debug_d3dformat(format->f.id));
2848 continue;
2851 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
2853 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format->f.id));
2854 check_fbo_compat(ctx, format);
2856 else
2858 format->rt_internal = format->internal;
2862 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
2863 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
2866 static GLenum lookup_gl_view_class(GLenum internal_format)
2868 static const struct
2870 GLenum internal_format;
2871 GLenum view_class;
2873 view_classes[] =
2875 /* 128-bit */
2876 {GL_RGBA32F, GL_VIEW_CLASS_128_BITS},
2877 {GL_RGBA32UI, GL_VIEW_CLASS_128_BITS},
2878 {GL_RGBA32I, GL_VIEW_CLASS_128_BITS},
2879 /* 96-bit */
2880 {GL_RGB32F, GL_VIEW_CLASS_96_BITS},
2881 {GL_RGB32UI, GL_VIEW_CLASS_96_BITS},
2882 {GL_RGB32I, GL_VIEW_CLASS_96_BITS},
2883 /* 64-bit */
2884 {GL_RGBA16F, GL_VIEW_CLASS_64_BITS},
2885 {GL_RG32F, GL_VIEW_CLASS_64_BITS},
2886 {GL_RGBA16UI, GL_VIEW_CLASS_64_BITS},
2887 {GL_RG32UI, GL_VIEW_CLASS_64_BITS},
2888 {GL_RGBA16I, GL_VIEW_CLASS_64_BITS},
2889 {GL_RG32I, GL_VIEW_CLASS_64_BITS},
2890 {GL_RGBA16, GL_VIEW_CLASS_64_BITS},
2891 {GL_RGBA16_SNORM, GL_VIEW_CLASS_64_BITS},
2892 /* 48-bit */
2893 {GL_RGB16, GL_VIEW_CLASS_48_BITS},
2894 {GL_RGB16_SNORM, GL_VIEW_CLASS_48_BITS},
2895 {GL_RGB16F, GL_VIEW_CLASS_48_BITS},
2896 {GL_RGB16UI, GL_VIEW_CLASS_48_BITS},
2897 {GL_RGB16I, GL_VIEW_CLASS_48_BITS},
2898 /* 32-bit */
2899 {GL_RG16F, GL_VIEW_CLASS_32_BITS},
2900 {GL_R11F_G11F_B10F, GL_VIEW_CLASS_32_BITS},
2901 {GL_R32F, GL_VIEW_CLASS_32_BITS},
2902 {GL_RGB10_A2UI, GL_VIEW_CLASS_32_BITS},
2903 {GL_RGBA8UI, GL_VIEW_CLASS_32_BITS},
2904 {GL_RG16UI, GL_VIEW_CLASS_32_BITS},
2905 {GL_R32UI, GL_VIEW_CLASS_32_BITS},
2906 {GL_RGBA8I, GL_VIEW_CLASS_32_BITS},
2907 {GL_RG16I, GL_VIEW_CLASS_32_BITS},
2908 {GL_R32I, GL_VIEW_CLASS_32_BITS},
2909 {GL_RGB10_A2, GL_VIEW_CLASS_32_BITS},
2910 {GL_RGBA8, GL_VIEW_CLASS_32_BITS},
2911 {GL_RG16, GL_VIEW_CLASS_32_BITS},
2912 {GL_RGBA8_SNORM, GL_VIEW_CLASS_32_BITS},
2913 {GL_RG16_SNORM, GL_VIEW_CLASS_32_BITS},
2914 {GL_SRGB8_ALPHA8, GL_VIEW_CLASS_32_BITS},
2915 {GL_RGB9_E5, GL_VIEW_CLASS_32_BITS},
2916 /* 24-bit */
2917 {GL_RGB8, GL_VIEW_CLASS_24_BITS},
2918 {GL_RGB8_SNORM, GL_VIEW_CLASS_24_BITS},
2919 {GL_SRGB8, GL_VIEW_CLASS_24_BITS},
2920 {GL_RGB8UI, GL_VIEW_CLASS_24_BITS},
2921 {GL_RGB8I, GL_VIEW_CLASS_24_BITS},
2922 /* 16-bit */
2923 {GL_R16F, GL_VIEW_CLASS_16_BITS},
2924 {GL_RG8UI, GL_VIEW_CLASS_16_BITS},
2925 {GL_R16UI, GL_VIEW_CLASS_16_BITS},
2926 {GL_RG8I, GL_VIEW_CLASS_16_BITS},
2927 {GL_R16I, GL_VIEW_CLASS_16_BITS},
2928 {GL_RG8, GL_VIEW_CLASS_16_BITS},
2929 {GL_R16, GL_VIEW_CLASS_16_BITS},
2930 {GL_RG8_SNORM, GL_VIEW_CLASS_16_BITS},
2931 {GL_R16_SNORM, GL_VIEW_CLASS_16_BITS},
2932 /* 8-bit */
2933 {GL_R8UI, GL_VIEW_CLASS_8_BITS},
2934 {GL_R8I, GL_VIEW_CLASS_8_BITS},
2935 {GL_R8, GL_VIEW_CLASS_8_BITS},
2936 {GL_R8_SNORM, GL_VIEW_CLASS_8_BITS},
2938 /* RGTC1 */
2939 {GL_COMPRESSED_RED_RGTC1, GL_VIEW_CLASS_RGTC1_RED},
2940 {GL_COMPRESSED_SIGNED_RED_RGTC1, GL_VIEW_CLASS_RGTC1_RED},
2941 /* RGTC2 */
2942 {GL_COMPRESSED_RG_RGTC2, GL_VIEW_CLASS_RGTC2_RG},
2943 {GL_COMPRESSED_SIGNED_RG_RGTC2, GL_VIEW_CLASS_RGTC2_RG},
2945 /* BPTC unorm */
2946 {GL_COMPRESSED_RGBA_BPTC_UNORM, GL_VIEW_CLASS_BPTC_UNORM},
2947 {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, GL_VIEW_CLASS_BPTC_UNORM},
2948 /* BPTC float */
2949 {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, GL_VIEW_CLASS_BPTC_FLOAT},
2950 {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, GL_VIEW_CLASS_BPTC_FLOAT},
2952 /* DXT1 RGB */
2953 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_VIEW_CLASS_S3TC_DXT1_RGB},
2954 {GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, GL_VIEW_CLASS_S3TC_DXT1_RGB},
2955 /* DXT1 RGBA */
2956 {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_VIEW_CLASS_S3TC_DXT1_RGBA},
2957 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_VIEW_CLASS_S3TC_DXT1_RGBA},
2958 /* DXT3 */
2959 {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_VIEW_CLASS_S3TC_DXT3_RGBA},
2960 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_VIEW_CLASS_S3TC_DXT3_RGBA},
2961 /* DXT5 */
2962 {GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_VIEW_CLASS_S3TC_DXT5_RGBA},
2963 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_VIEW_CLASS_S3TC_DXT5_RGBA},
2966 unsigned int i;
2968 for (i = 0; i < ARRAY_SIZE(view_classes); ++i)
2970 if (view_classes[i].internal_format == internal_format)
2971 return view_classes[i].view_class;
2974 return GL_NONE;
2977 static void query_view_class(struct wined3d_format_gl *format)
2979 GLenum internal_view_class, gamma_view_class, rt_view_class;
2981 internal_view_class = lookup_gl_view_class(format->internal);
2982 gamma_view_class = lookup_gl_view_class(format->srgb_internal);
2983 rt_view_class = lookup_gl_view_class(format->rt_internal);
2985 if (internal_view_class == gamma_view_class || gamma_view_class == rt_view_class)
2987 format->view_class = internal_view_class;
2988 TRACE("Format %s is member of GL view class %#x.\n",
2989 debug_d3dformat(format->f.id), format->view_class);
2991 else
2993 format->view_class = GL_NONE;
2997 static void query_internal_format(struct wined3d_adapter *adapter,
2998 struct wined3d_format_gl *format, const struct wined3d_format_texture_info *texture_info,
2999 struct wined3d_gl_info *gl_info, BOOL srgb_write_supported, BOOL srgb_format)
3001 GLint count, multisample_types[8];
3002 unsigned int i, max_log2;
3003 GLenum target;
3005 if (gl_info->supported[ARB_INTERNALFORMAT_QUERY2])
3007 query_format_flag(gl_info, format, format->internal, GL_VERTEX_TEXTURE,
3008 WINED3DFMT_FLAG_VTF, "vertex texture usage");
3009 query_format_flag(gl_info, format, format->internal, GL_FILTER,
3010 WINED3DFMT_FLAG_FILTERING, "filtering");
3011 query_format_flag(gl_info, format, format->internal, GL_SHADER_IMAGE_STORE,
3012 WINED3DFMT_FLAG_UNORDERED_ACCESS, "unordered access");
3014 if (srgb_format || format->srgb_internal != format->internal)
3016 query_format_flag(gl_info, format, format->srgb_internal, GL_SRGB_READ,
3017 WINED3DFMT_FLAG_SRGB_READ, "sRGB read");
3019 if (srgb_write_supported)
3020 query_format_flag(gl_info, format, format->srgb_internal, GL_SRGB_WRITE,
3021 WINED3DFMT_FLAG_SRGB_WRITE, "sRGB write");
3022 else
3023 format_clear_flag(&format->f, WINED3DFMT_FLAG_SRGB_WRITE);
3025 if (!(format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D]
3026 & (WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE)))
3027 format->srgb_internal = format->internal;
3028 else if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
3029 format->internal = format->srgb_internal;
3032 else
3034 if (!gl_info->limits.samplers[WINED3D_SHADER_TYPE_VERTEX])
3035 format_clear_flag(&format->f, WINED3DFMT_FLAG_VTF);
3037 if (!(gl_info->quirks & WINED3D_QUIRK_LIMITED_TEX_FILTERING))
3038 format_set_flag(&format->f, WINED3DFMT_FLAG_FILTERING);
3039 else if (format->f.id != WINED3DFMT_R32G32B32A32_FLOAT && format->f.id != WINED3DFMT_R32_FLOAT)
3040 format_clear_flag(&format->f, WINED3DFMT_FLAG_VTF);
3042 if (srgb_format || format->srgb_internal != format->internal)
3044 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
3045 if (!gl_info->supported[EXT_TEXTURE_SRGB])
3047 format->srgb_internal = format->internal;
3048 format_clear_flag(&format->f, WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE);
3050 else if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
3052 format->internal = format->srgb_internal;
3056 if ((format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_SRGB_WRITE) && !srgb_write_supported)
3057 format_clear_flag(&format->f, WINED3DFMT_FLAG_SRGB_WRITE);
3060 if ((!gl_info->supported[ARB_DEPTH_TEXTURE] || wined3d_settings.offscreen_rendering_mode != ORM_FBO)
3061 && (format->f.depth_size || format->f.stencil_size))
3063 TRACE("Disabling texturing support for depth / stencil format %s.\n", debug_d3dformat(format->f.id));
3064 format->f.flags[WINED3D_GL_RES_TYPE_TEX_1D] &= ~WINED3DFMT_FLAG_TEXTURE;
3065 format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] &= ~WINED3DFMT_FLAG_TEXTURE;
3066 format->f.flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3067 format->f.flags[WINED3D_GL_RES_TYPE_TEX_CUBE] &= ~WINED3DFMT_FLAG_TEXTURE;
3068 format->f.flags[WINED3D_GL_RES_TYPE_TEX_RECT] &= ~WINED3DFMT_FLAG_TEXTURE;
3071 query_view_class(format);
3073 if (format->internal && format->f.flags[WINED3D_GL_RES_TYPE_RB]
3074 & (WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_DEPTH_STENCIL)
3075 && (gl_info->supported[ARB_FRAMEBUFFER_OBJECT] || gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
3076 && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3078 if (gl_info->supported[ARB_INTERNALFORMAT_QUERY])
3080 target = gl_info->supported[ARB_TEXTURE_MULTISAMPLE] ? GL_TEXTURE_2D_MULTISAMPLE : GL_RENDERBUFFER;
3081 count = 0;
3082 GL_EXTCALL(glGetInternalformativ(target, format->internal,
3083 GL_NUM_SAMPLE_COUNTS, 1, &count));
3084 if (count > ARRAY_SIZE(multisample_types))
3085 FIXME("Unexpectedly high number of multisample types %d.\n", count);
3086 count = min(count, ARRAY_SIZE(multisample_types));
3087 GL_EXTCALL(glGetInternalformativ(target, format->internal,
3088 GL_SAMPLES, count, multisample_types));
3089 checkGLcall("query sample counts");
3090 for (i = 0; i < count; ++i)
3092 if (multisample_types[i] > sizeof(format->f.multisample_types) * CHAR_BIT)
3093 continue;
3094 format->f.multisample_types |= 1u << (multisample_types[i] - 1);
3097 else
3099 max_log2 = wined3d_log2i(min(gl_info->limits.samples,
3100 sizeof(format->f.multisample_types) * CHAR_BIT));
3101 for (i = 1; i <= max_log2; ++i)
3102 format->f.multisample_types |= 1u << ((1u << i) - 1);
3107 static BOOL init_format_texture_info(struct wined3d_adapter *adapter, struct wined3d_gl_info *gl_info)
3109 struct wined3d_format_gl *format, *srgb_format;
3110 struct fragment_caps fragment_caps;
3111 struct shader_caps shader_caps;
3112 unsigned int i, j;
3113 BOOL srgb_write;
3115 adapter->fragment_pipe->get_caps(adapter, &fragment_caps);
3116 adapter->shader_backend->shader_get_caps(adapter, &shader_caps);
3117 srgb_write = (fragment_caps.wined3d_caps & WINED3D_FRAGMENT_CAP_SRGB_WRITE)
3118 && (shader_caps.wined3d_caps & WINED3D_SHADER_CAP_SRGB_WRITE);
3120 for (i = 0; i < ARRAY_SIZE(format_texture_info); ++i)
3122 if (!(format = get_format_gl_internal(adapter, format_texture_info[i].id)))
3123 return FALSE;
3125 if (!gl_info->supported[format_texture_info[i].extension])
3126 continue;
3128 /* ARB_texture_rg defines floating point formats, but only if
3129 * ARB_texture_float is also supported. */
3130 if (!gl_info->supported[ARB_TEXTURE_FLOAT]
3131 && (format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT))
3132 continue;
3134 /* ARB_texture_rg defines integer formats if EXT_texture_integer is also supported. */
3135 if (!gl_info->supported[EXT_TEXTURE_INTEGER]
3136 && (format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_INTEGER))
3137 continue;
3139 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
3140 && (format->f.id == WINED3DFMT_D16_LOCKABLE || format->f.id == WINED3DFMT_NULL))
3141 continue;
3143 format->internal = format_texture_info[i].gl_internal;
3144 format->srgb_internal = format_texture_info[i].gl_srgb_internal;
3145 format->rt_internal = format_texture_info[i].gl_rt_internal;
3146 format->format = format_texture_info[i].gl_format;
3147 format->type = format_texture_info[i].gl_type;
3148 format->f.color_fixup = COLOR_FIXUP_IDENTITY;
3149 format->f.height_scale.numerator = 1;
3150 format->f.height_scale.denominator = 1;
3152 format->f.flags[WINED3D_GL_RES_TYPE_TEX_1D] |= format_texture_info[i].flags | WINED3DFMT_FLAG_BLIT;
3153 format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] |= format_texture_info[i].flags | WINED3DFMT_FLAG_BLIT;
3154 format->f.flags[WINED3D_GL_RES_TYPE_BUFFER] |= format_texture_info[i].flags | WINED3DFMT_FLAG_BLIT;
3156 /* GL_ARB_depth_texture does not support 3D textures. It also says "cube textures are
3157 * problematic", but doesn't explicitly mandate that an error is generated. */
3158 if (gl_info->supported[EXT_TEXTURE3D] && !(format_texture_info[i].flags & WINED3DFMT_FLAG_DEPTH_STENCIL))
3159 format->f.flags[WINED3D_GL_RES_TYPE_TEX_3D] |= format_texture_info[i].flags | WINED3DFMT_FLAG_BLIT;
3161 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3162 format->f.flags[WINED3D_GL_RES_TYPE_TEX_CUBE] |= format_texture_info[i].flags | WINED3DFMT_FLAG_BLIT;
3164 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
3165 format->f.flags[WINED3D_GL_RES_TYPE_TEX_RECT] |= format_texture_info[i].flags | WINED3DFMT_FLAG_BLIT;
3167 format->f.flags[WINED3D_GL_RES_TYPE_RB] |= format_texture_info[i].flags | WINED3DFMT_FLAG_BLIT;
3168 format->f.flags[WINED3D_GL_RES_TYPE_RB] &= ~WINED3DFMT_FLAG_TEXTURE;
3170 if (format->srgb_internal != format->internal
3171 && !(adapter->d3d_info.wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL))
3173 format->srgb_internal = format->internal;
3174 format_clear_flag(&format->f, WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE);
3177 if (!gl_info->supported[ARB_SHADOW] && (format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_SHADOW))
3178 format_clear_flag(&format->f, WINED3DFMT_FLAG_TEXTURE);
3180 query_internal_format(adapter, format, &format_texture_info[i], gl_info, srgb_write, FALSE);
3182 /* Texture conversion stuff */
3183 format->f.conv_byte_count = format_texture_info[i].conv_byte_count;
3184 format->f.upload = format_texture_info[i].upload;
3185 format->f.download = format_texture_info[i].download;
3187 srgb_format = NULL;
3188 for (j = 0; j < ARRAY_SIZE(format_srgb_info); ++j)
3190 if (format_srgb_info[j].base_format_id == format->f.id)
3192 if (!(srgb_format = get_format_gl_internal(adapter, format_srgb_info[j].srgb_format_id)))
3193 return FALSE;
3194 break;
3197 if (!srgb_format)
3198 continue;
3200 copy_format(adapter, &srgb_format->f, &format->f);
3202 if (gl_info->supported[EXT_TEXTURE_SRGB]
3203 && !(adapter->d3d_info.wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL))
3205 srgb_format->internal = format_texture_info[i].gl_srgb_internal;
3206 srgb_format->srgb_internal = format_texture_info[i].gl_srgb_internal;
3207 format_set_flag(&srgb_format->f, WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE);
3208 query_internal_format(adapter, srgb_format, &format_texture_info[i], gl_info, srgb_write, TRUE);
3212 return TRUE;
3215 static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
3217 unsigned int diff = x > y ? x - y : y - x;
3219 return diff <= max_diff;
3222 static BOOL compare_colour(DWORD c1, DWORD c2, BYTE max_diff)
3224 return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
3225 && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
3226 && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
3227 && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
3230 /* A context is provided by the caller */
3231 static BOOL check_filter(const struct wined3d_gl_info *gl_info, GLenum internal)
3233 static const DWORD data[] = {0x00000000, 0xffffffff};
3234 GLuint tex, fbo, buffer;
3235 DWORD readback[16 * 1];
3236 BOOL ret = FALSE;
3238 /* Render a filtered texture and see what happens. This is intended to detect the lack of
3239 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
3240 * falling back to software. If this changes in the future this code will get fooled and
3241 * apps might hit the software path due to incorrectly advertised caps.
3243 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
3244 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
3245 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
3248 while (gl_info->gl_ops.gl.p_glGetError());
3250 gl_info->gl_ops.gl.p_glGenTextures(1, &buffer);
3251 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, buffer);
3252 memset(readback, 0x7e, sizeof(readback));
3253 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 16, 1, 0,
3254 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, readback);
3255 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3256 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3257 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3258 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3259 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
3261 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
3262 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
3263 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, internal, 2, 1, 0,
3264 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
3265 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3266 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3267 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3268 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3269 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
3270 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_2D);
3272 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
3273 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3274 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, buffer, 0);
3275 gl_info->gl_ops.gl.p_glDrawBuffer(GL_COLOR_ATTACHMENT0);
3277 gl_info->gl_ops.gl.p_glViewport(0, 0, 16, 1);
3278 gl_info->gl_ops.gl.p_glDisable(GL_LIGHTING);
3279 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3280 gl_info->gl_ops.gl.p_glLoadIdentity();
3281 gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
3282 gl_info->gl_ops.gl.p_glLoadIdentity();
3284 gl_info->gl_ops.gl.p_glClearColor(0, 1, 0, 0);
3285 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
3287 gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
3288 gl_info->gl_ops.gl.p_glTexCoord2f(0.0, 0.0);
3289 gl_info->gl_ops.gl.p_glVertex2f(-1.0f, -1.0f);
3290 gl_info->gl_ops.gl.p_glTexCoord2f(1.0, 0.0);
3291 gl_info->gl_ops.gl.p_glVertex2f(1.0f, -1.0f);
3292 gl_info->gl_ops.gl.p_glTexCoord2f(0.0, 1.0);
3293 gl_info->gl_ops.gl.p_glVertex2f(-1.0f, 1.0f);
3294 gl_info->gl_ops.gl.p_glTexCoord2f(1.0, 1.0);
3295 gl_info->gl_ops.gl.p_glVertex2f(1.0f, 1.0f);
3296 gl_info->gl_ops.gl.p_glEnd();
3298 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, buffer);
3299 memset(readback, 0x7f, sizeof(readback));
3300 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, readback);
3301 if (compare_colour(readback[6], 0xffffffff, 5) || compare_colour(readback[6], 0x00000000, 5)
3302 || compare_colour(readback[9], 0xffffffff, 5) || compare_colour(readback[9], 0x00000000, 5))
3304 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
3305 readback[6], readback[9]);
3306 ret = FALSE;
3308 else
3310 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
3311 readback[6], readback[9]);
3312 ret = TRUE;
3315 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
3316 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
3317 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
3318 gl_info->gl_ops.gl.p_glDeleteTextures(1, &buffer);
3319 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
3321 if (gl_info->gl_ops.gl.p_glGetError())
3323 FIXME("Error during filtering test for format %x, returning no filtering\n", internal);
3324 ret = FALSE;
3327 return ret;
3330 static void init_format_filter_info(struct wined3d_adapter *adapter,
3331 struct wined3d_gl_info *gl_info)
3333 enum wined3d_pci_vendor vendor = adapter->driver_info.vendor;
3334 struct wined3d_format_gl *format;
3335 unsigned int i;
3336 static const enum wined3d_format_id fmts16[] =
3338 WINED3DFMT_R16_FLOAT,
3339 WINED3DFMT_R16G16_FLOAT,
3340 WINED3DFMT_R16G16B16A16_FLOAT,
3342 BOOL filtered;
3344 /* This was already handled by init_format_texture_info(). */
3345 if (gl_info->supported[ARB_INTERNALFORMAT_QUERY2])
3346 return;
3348 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
3349 || !gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
3351 WARN("No FBO support, or no FBO ORM, guessing filter info from GL caps\n");
3352 if (vendor == HW_VENDOR_NVIDIA && gl_info->supported[ARB_TEXTURE_FLOAT])
3354 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
3355 filtered = TRUE;
3357 else if (gl_info->limits.glsl_varyings > 44)
3359 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
3360 filtered = TRUE;
3362 else
3364 TRACE("Assuming no float16 blending\n");
3365 filtered = FALSE;
3368 if (filtered)
3370 for (i = 0; i < ARRAY_SIZE(fmts16); ++i)
3372 format = get_format_gl_internal(adapter, fmts16[i]);
3373 format_set_flag(&format->f, WINED3DFMT_FLAG_FILTERING);
3376 return;
3379 for (i = 0; i < ARRAY_SIZE(fmts16); ++i)
3381 format = get_format_gl_internal(adapter, fmts16[i]);
3382 if (!format->internal)
3383 continue; /* Not supported by GL */
3385 filtered = check_filter(gl_info, format->internal);
3386 if (filtered)
3388 TRACE("Format %s supports filtering.\n", debug_d3dformat(format->f.id));
3389 format_set_flag(&format->f, WINED3DFMT_FLAG_FILTERING);
3391 else
3393 TRACE("Format %s does not support filtering.\n", debug_d3dformat(format->f.id));
3398 static enum fixup_channel_source fixup_source_from_char(char c)
3400 switch (c)
3402 default:
3403 case '0':
3404 return CHANNEL_SOURCE_ZERO;
3405 case '1':
3406 return CHANNEL_SOURCE_ONE;
3407 case 'x':
3408 case 'X':
3409 return CHANNEL_SOURCE_X;
3410 case 'y':
3411 case 'Y':
3412 return CHANNEL_SOURCE_Y;
3413 case 'z':
3414 case 'Z':
3415 return CHANNEL_SOURCE_Z;
3416 case 'w':
3417 case 'W':
3418 return CHANNEL_SOURCE_W;
3422 static unsigned int fixup_sign_from_char(char c)
3424 if (c == 'x' || c == 'y' || c == 'z' || c == 'w')
3425 return 1;
3426 return 0;
3429 static struct color_fixup_desc create_color_fixup_desc_from_string(const char *s)
3431 struct color_fixup_desc fixup;
3433 if (strlen(s) != 4)
3435 ERR("Invalid fixup string %s.\n", wine_dbgstr_a(s));
3436 return COLOR_FIXUP_IDENTITY;
3439 fixup.x_sign_fixup = fixup_sign_from_char(s[0]);
3440 fixup.x_source = fixup_source_from_char(s[0]);
3441 fixup.y_sign_fixup = fixup_sign_from_char(s[1]);
3442 fixup.y_source = fixup_source_from_char(s[1]);
3443 fixup.z_sign_fixup = fixup_sign_from_char(s[2]);
3444 fixup.z_source = fixup_source_from_char(s[2]);
3445 fixup.w_sign_fixup = fixup_sign_from_char(s[3]);
3446 fixup.w_source = fixup_source_from_char(s[3]);
3448 return fixup;
3451 static void apply_format_fixups(struct wined3d_adapter *adapter, struct wined3d_gl_info *gl_info)
3453 const struct wined3d_d3d_info *d3d_info = &adapter->d3d_info;
3454 struct wined3d_format_gl *format;
3455 BOOL use_legacy_fixups;
3456 unsigned int i;
3458 static const struct
3460 enum wined3d_format_id id;
3461 const char *fixup;
3462 BOOL legacy;
3463 enum wined3d_gl_extension extension;
3465 fixups[] =
3467 {WINED3DFMT_R16_FLOAT, "X11W", TRUE, WINED3D_GL_EXT_NONE},
3468 {WINED3DFMT_R32_FLOAT, "X11W", TRUE, WINED3D_GL_EXT_NONE},
3469 {WINED3DFMT_R16G16_UNORM, "XY1W", TRUE, WINED3D_GL_EXT_NONE},
3470 {WINED3DFMT_R16G16_FLOAT, "XY1W", TRUE, WINED3D_GL_EXT_NONE},
3471 {WINED3DFMT_R32G32_FLOAT, "XY1W", TRUE, WINED3D_GL_EXT_NONE},
3473 {WINED3DFMT_R8G8_SNORM, "xy11", FALSE, WINED3D_GL_EXT_NONE},
3474 {WINED3DFMT_R8G8_SNORM, "XY11", TRUE, NV_TEXTURE_SHADER},
3475 {WINED3DFMT_R8G8_SNORM, "XY11", TRUE, EXT_TEXTURE_SNORM},
3477 {WINED3DFMT_R16G16_SNORM, "xy11", FALSE, WINED3D_GL_EXT_NONE},
3478 {WINED3DFMT_R16G16_SNORM, "XY11", TRUE, NV_TEXTURE_SHADER},
3479 {WINED3DFMT_R16G16_SNORM, "XY11", TRUE, EXT_TEXTURE_SNORM},
3481 {WINED3DFMT_R8G8B8A8_SNORM, "xyzw", FALSE, WINED3D_GL_EXT_NONE},
3482 {WINED3DFMT_R8G8B8A8_SNORM, "XYZW", FALSE, NV_TEXTURE_SHADER},
3483 {WINED3DFMT_R8G8B8A8_SNORM, "XYZW", FALSE, EXT_TEXTURE_SNORM},
3485 {WINED3DFMT_R5G5_SNORM_L6_UNORM, "xzY1", FALSE, WINED3D_GL_EXT_NONE},
3486 {WINED3DFMT_R5G5_SNORM_L6_UNORM, "XYZW", FALSE, NV_TEXTURE_SHADER},
3487 {WINED3DFMT_R5G5_SNORM_L6_UNORM, "XYZW", FALSE, EXT_TEXTURE_SNORM},
3489 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, "xyZW", FALSE, WINED3D_GL_EXT_NONE},
3490 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, "XYZW", FALSE, NV_TEXTURE_SHADER},
3492 {WINED3DFMT_ATI1N, "XXXX", FALSE, EXT_TEXTURE_COMPRESSION_RGTC},
3493 {WINED3DFMT_ATI1N, "XXXX", FALSE, ARB_TEXTURE_COMPRESSION_RGTC},
3495 {WINED3DFMT_ATI2N, "XW11", FALSE, ATI_TEXTURE_COMPRESSION_3DC},
3496 {WINED3DFMT_ATI2N, "YX11", FALSE, EXT_TEXTURE_COMPRESSION_RGTC},
3497 {WINED3DFMT_ATI2N, "YX11", FALSE, ARB_TEXTURE_COMPRESSION_RGTC},
3499 {WINED3DFMT_A8_UNORM, "000X", FALSE, WINED3D_GL_EXT_NONE},
3500 {WINED3DFMT_A8_UNORM, "XYZW", FALSE, WINED3D_GL_LEGACY_CONTEXT},
3502 {WINED3DFMT_L8A8_UNORM, "XXXY", FALSE, WINED3D_GL_EXT_NONE},
3503 {WINED3DFMT_L8A8_UNORM, "XYZW", FALSE, WINED3D_GL_LEGACY_CONTEXT},
3505 {WINED3DFMT_L4A4_UNORM, "XXXY", FALSE, WINED3D_GL_EXT_NONE},
3506 {WINED3DFMT_L4A4_UNORM, "XYZW", FALSE, WINED3D_GL_LEGACY_CONTEXT},
3508 {WINED3DFMT_L16_UNORM, "XXX1", FALSE, WINED3D_GL_EXT_NONE},
3509 {WINED3DFMT_L16_UNORM, "XYZW", FALSE, WINED3D_GL_LEGACY_CONTEXT},
3511 {WINED3DFMT_INTZ, "XXXX", FALSE, WINED3D_GL_EXT_NONE},
3512 {WINED3DFMT_INTZ, "XYZW", FALSE, WINED3D_GL_LEGACY_CONTEXT},
3514 {WINED3DFMT_L8_UNORM, "XXX1", FALSE, ARB_TEXTURE_RG},
3517 use_legacy_fixups = d3d_info->wined3d_creation_flags & WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR;
3518 for (i = 0; i < ARRAY_SIZE(fixups); ++i)
3520 if (fixups[i].legacy && !use_legacy_fixups)
3521 continue;
3523 if (!gl_info->supported[fixups[i].extension])
3524 continue;
3526 format = get_format_gl_internal(adapter, fixups[i].id);
3527 format->f.color_fixup = create_color_fixup_desc_from_string(fixups[i].fixup);
3530 if (!gl_info->supported[APPLE_YCBCR_422] && !gl_info->supported[APPLE_RGB_422]
3531 && (gl_info->supported[ARB_FRAGMENT_PROGRAM]
3532 || (gl_info->supported[ARB_FRAGMENT_SHADER] && gl_info->supported[ARB_VERTEX_SHADER])))
3534 format = get_format_gl_internal(adapter, WINED3DFMT_YUY2);
3535 format->f.color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_YUY2);
3537 format = get_format_gl_internal(adapter, WINED3DFMT_UYVY);
3538 format->f.color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_UYVY);
3540 else if (!gl_info->supported[APPLE_YCBCR_422] && gl_info->supported[APPLE_RGB_422])
3542 format = get_format_gl_internal(adapter, WINED3DFMT_YUY2);
3543 format->f.color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_YUV);
3545 format = get_format_gl_internal(adapter, WINED3DFMT_UYVY);
3546 format->f.color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_YUV);
3548 else if (!gl_info->supported[APPLE_YCBCR_422] && (!gl_info->supported[ARB_FRAGMENT_PROGRAM]
3549 && (!gl_info->supported[ARB_FRAGMENT_SHADER] || !gl_info->supported[ARB_VERTEX_SHADER])))
3551 format = get_format_gl_internal(adapter, WINED3DFMT_YUY2);
3552 format_clear_flag(&format->f, WINED3DFMT_FLAG_BLIT);
3553 format->internal = 0;
3555 format = get_format_gl_internal(adapter, WINED3DFMT_UYVY);
3556 format_clear_flag(&format->f, WINED3DFMT_FLAG_BLIT);
3557 format->internal = 0;
3560 if (gl_info->supported[ARB_FRAGMENT_PROGRAM]
3561 || (gl_info->supported[ARB_FRAGMENT_SHADER] && gl_info->supported[ARB_VERTEX_SHADER]))
3563 format = get_format_gl_internal(adapter, WINED3DFMT_YV12);
3564 format_set_flag(&format->f, WINED3DFMT_FLAG_HEIGHT_SCALE);
3565 format->f.height_scale.numerator = 3;
3566 format->f.height_scale.denominator = 2;
3567 format->f.color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_YV12);
3569 format = get_format_gl_internal(adapter, WINED3DFMT_NV12);
3570 format_set_flag(&format->f, WINED3DFMT_FLAG_HEIGHT_SCALE);
3571 format->f.height_scale.numerator = 3;
3572 format->f.height_scale.denominator = 2;
3573 format->f.color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_NV12);
3575 else
3577 format = get_format_gl_internal(adapter, WINED3DFMT_YV12);
3578 format_clear_flag(&format->f, WINED3DFMT_FLAG_BLIT);
3579 format->internal = 0;
3581 format = get_format_gl_internal(adapter, WINED3DFMT_NV12);
3582 format_clear_flag(&format->f, WINED3DFMT_FLAG_BLIT);
3583 format->internal = 0;
3586 if (gl_info->supported[ARB_FRAGMENT_PROGRAM] || gl_info->supported[ARB_FRAGMENT_SHADER])
3588 format = get_format_gl_internal(adapter, WINED3DFMT_P8_UINT);
3589 format->f.color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_P8);
3592 if (!gl_info->supported[ARB_HALF_FLOAT_PIXEL])
3594 format = get_format_gl_internal(adapter, WINED3DFMT_R16_FLOAT);
3595 format_clear_flag(&format->f, WINED3DFMT_FLAG_TEXTURE);
3597 format = get_format_gl_internal(adapter, WINED3DFMT_R16G16_FLOAT);
3598 format_clear_flag(&format->f, WINED3DFMT_FLAG_TEXTURE);
3600 format = get_format_gl_internal(adapter, WINED3DFMT_R16G16B16A16_FLOAT);
3601 format_clear_flag(&format->f, WINED3DFMT_FLAG_TEXTURE);
3604 if (gl_info->quirks & WINED3D_QUIRK_BROKEN_RGBA16)
3606 format = get_format_gl_internal(adapter, WINED3DFMT_R16G16B16A16_UNORM);
3607 format_clear_flag(&format->f, WINED3DFMT_FLAG_TEXTURE);
3610 /* ATI instancing hack: Although ATI cards do not support Shader Model
3611 * 3.0, they support instancing. To query if the card supports instancing
3612 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
3613 * is used. Should an application check for this, provide a proper return
3614 * value. We can do instancing with all shader versions, but we need
3615 * vertex shaders.
3617 * Additionally applications have to set the D3DRS_POINTSIZE render state
3618 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
3619 * doesn't need that and just ignores it.
3621 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
3622 /* FIXME: This should just check the shader backend caps. */
3623 if (gl_info->supported[ARB_VERTEX_PROGRAM] || gl_info->supported[ARB_VERTEX_SHADER])
3625 format = get_format_gl_internal(adapter, WINED3DFMT_INST);
3626 format_set_flag(&format->f, WINED3DFMT_FLAG_TEXTURE);
3629 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
3630 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
3631 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
3632 * MAKEFOURCC('N','V','D','B') and then controlled by setting
3633 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
3634 * value. */
3635 if (gl_info->supported[EXT_DEPTH_BOUNDS_TEST])
3637 format = get_format_gl_internal(adapter, WINED3DFMT_NVDB);
3638 format_set_flag(&format->f, WINED3DFMT_FLAG_TEXTURE);
3641 if (gl_info->supported[ARB_MULTISAMPLE])
3643 format = get_format_gl_internal(adapter, WINED3DFMT_ATOC);
3644 format_set_flag(&format->f, WINED3DFMT_FLAG_TEXTURE);
3647 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
3648 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
3649 * RENDERTARGET usage. */
3650 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
3652 format = get_format_gl_internal(adapter, WINED3DFMT_RESZ);
3653 format_set_flag(&format->f, WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET);
3656 for (i = 0; i < WINED3D_FORMAT_COUNT; ++i)
3658 format = get_format_gl_by_idx(adapter, i);
3660 if (!(format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_TEXTURE))
3661 continue;
3663 if (is_identity_fixup(format->f.color_fixup))
3664 continue;
3666 TRACE("Checking support for fixup:\n");
3667 dump_color_fixup_desc(format->f.color_fixup);
3668 if (!adapter->shader_backend->shader_color_fixup_supported(format->f.color_fixup)
3669 || !adapter->fragment_pipe->color_fixup_supported(format->f.color_fixup))
3671 TRACE("[FAILED]\n");
3672 format_clear_flag(&format->f, WINED3DFMT_FLAG_TEXTURE);
3674 else
3676 TRACE("[OK]\n");
3680 /* These formats are not supported for 3D textures. See also
3681 * WINED3DFMT_FLAG_DECOMPRESS. */
3682 format = get_format_gl_internal(adapter, WINED3DFMT_ATI1N);
3683 format->f.flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3684 format = get_format_gl_internal(adapter, WINED3DFMT_ATI2N);
3685 format->f.flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3686 format = get_format_gl_internal(adapter, WINED3DFMT_BC4_UNORM);
3687 format->f.flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3688 format = get_format_gl_internal(adapter, WINED3DFMT_BC4_SNORM);
3689 format->f.flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3690 format = get_format_gl_internal(adapter, WINED3DFMT_BC5_UNORM);
3691 format->f.flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3692 format = get_format_gl_internal(adapter, WINED3DFMT_BC5_SNORM);
3693 format->f.flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3696 static BOOL init_format_vertex_info(const struct wined3d_adapter *adapter,
3697 struct wined3d_gl_info *gl_info)
3699 struct wined3d_format_gl *format;
3700 unsigned int i;
3702 for (i = 0; i < ARRAY_SIZE(format_vertex_info); ++i)
3704 if (!(format = get_format_gl_internal(adapter, format_vertex_info[i].id)))
3705 return FALSE;
3707 if (!gl_info->supported[format_vertex_info[i].extension])
3708 continue;
3710 format->f.emit_idx = format_vertex_info[i].emit_idx;
3711 format->vtx_type = format_vertex_info[i].gl_vtx_type;
3712 format->vtx_format = format->f.component_count;
3713 format->f.flags[WINED3D_GL_RES_TYPE_BUFFER] |= WINED3DFMT_FLAG_VERTEX_ATTRIBUTE;
3716 if (gl_info->supported[ARB_VERTEX_ARRAY_BGRA])
3718 format = get_format_gl_internal(adapter, WINED3DFMT_B8G8R8A8_UNORM);
3719 format->vtx_format = GL_BGRA;
3722 return TRUE;
3725 static BOOL init_typeless_formats(const struct wined3d_adapter *adapter)
3727 unsigned int flags[WINED3D_GL_RES_TYPE_COUNT];
3728 unsigned int i, j;
3730 for (i = 0; i < ARRAY_SIZE(typed_formats); ++i)
3732 struct wined3d_format *format, *typeless_format;
3734 if (!(format = get_format_internal(adapter, typed_formats[i].id)))
3735 return FALSE;
3736 if (!(typeless_format = get_format_internal(adapter, typed_formats[i].typeless_id)))
3737 return FALSE;
3739 memcpy(flags, typeless_format->flags, sizeof(flags));
3740 copy_format(adapter, typeless_format, format);
3741 for (j = 0; j < ARRAY_SIZE(typeless_format->flags); ++j)
3742 typeless_format->flags[j] |= flags[j];
3745 for (i = 0; i < ARRAY_SIZE(typeless_depth_stencil_formats); ++i)
3747 struct wined3d_format *typeless_format, *typeless_ds_format, *ds_format;
3748 struct wined3d_format *depth_view_format, *stencil_view_format;
3749 enum wined3d_format_id format_id;
3751 if (!(typeless_format = get_format_internal(adapter, typeless_depth_stencil_formats[i].typeless_id)))
3752 return FALSE;
3753 if (!(ds_format = get_format_internal(adapter, typeless_depth_stencil_formats[i].depth_stencil_id)))
3754 return FALSE;
3756 typeless_ds_format = get_format_by_idx(adapter, WINED3D_FORMAT_COUNT + i);
3757 typeless_ds_format->id = typeless_depth_stencil_formats[i].typeless_id;
3758 copy_format(adapter, typeless_ds_format, ds_format);
3759 for (j = 0; j < ARRAY_SIZE(typeless_ds_format->flags); ++j)
3761 typeless_ds_format->flags[j] = typeless_format->flags[j];
3762 typeless_format->flags[j] &= ~WINED3DFMT_FLAG_DEPTH_STENCIL;
3765 if ((format_id = typeless_depth_stencil_formats[i].depth_view_id)
3766 && typeless_depth_stencil_formats[i].separate_depth_view_format)
3768 if (!(depth_view_format = get_format_internal(adapter, format_id)))
3769 return FALSE;
3770 copy_format(adapter, depth_view_format, ds_format);
3771 depth_view_format->red_size = depth_view_format->depth_size;
3772 depth_view_format->depth_size = 0;
3773 depth_view_format->stencil_size = 0;
3775 if ((format_id = typeless_depth_stencil_formats[i].stencil_view_id))
3777 if (!(stencil_view_format = get_format_internal(adapter, format_id)))
3778 return FALSE;
3779 copy_format(adapter, stencil_view_format, ds_format);
3780 stencil_view_format->green_size = stencil_view_format->stencil_size;
3781 stencil_view_format->depth_size = 0;
3782 stencil_view_format->stencil_size = 0;
3786 return TRUE;
3789 static void init_format_gen_mipmap_info(const struct wined3d_adapter *adapter,
3790 struct wined3d_gl_info *gl_info)
3792 unsigned int i, j;
3794 if (!gl_info->fbo_ops.glGenerateMipmap)
3795 return;
3797 for (i = 0; i < WINED3D_FORMAT_COUNT; ++i)
3799 struct wined3d_format *format = get_format_by_idx(adapter, i);
3801 for (j = 0; j < ARRAY_SIZE(format->flags); ++j)
3802 if (!(~format->flags[j] & (WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_FILTERING)))
3803 format->flags[j] |= WINED3DFMT_FLAG_GEN_MIPMAP;
3807 BOOL wined3d_caps_gl_ctx_test_viewport_subpixel_bits(struct wined3d_caps_gl_ctx *ctx)
3809 static const struct wined3d_color red = {1.0f, 0.0f, 0.0f, 1.0f};
3810 const struct wined3d_gl_info *gl_info = ctx->gl_info;
3811 static const float offset = -63.0f / 128.0f;
3812 GLuint texture, fbo;
3813 DWORD readback[4];
3814 unsigned int i;
3816 gl_info->gl_ops.gl.p_glGenTextures(1, &texture);
3817 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, texture);
3818 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
3819 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ARRAY_SIZE(readback), 1, 0,
3820 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
3821 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
3822 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3823 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
3824 GL_TEXTURE_2D, texture, 0);
3825 checkGLcall("create resources");
3827 gl_info->gl_ops.gl.p_glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3828 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
3829 GL_EXTCALL(glViewportIndexedf(0, offset, offset, 4.0f, 1.0f));
3830 draw_test_quad(ctx, NULL, &red);
3831 checkGLcall("draw");
3833 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, texture);
3834 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0,
3835 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, readback);
3836 checkGLcall("readback");
3838 TRACE("Readback colors are 0x%08x, 0x%08x, 0x%08x, 0x%08x.\n",
3839 readback[0], readback[1], readback[2], readback[3]);
3841 gl_info->gl_ops.gl.p_glDeleteTextures(1, &texture);
3842 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
3843 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
3844 checkGLcall("delete resources");
3846 for (i = 0; i < ARRAY_SIZE(readback); ++i)
3848 if (readback[i] != 0xffff0000)
3849 return FALSE;
3851 return TRUE;
3854 static float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx *ctx, GLenum format)
3856 const struct wined3d_gl_info *gl_info = ctx->gl_info;
3857 static const struct wined3d_color blue = {0.0f, 0.0f, 1.0f, 1.0f};
3858 GLuint fbo, color, depth;
3859 unsigned int low = 0, high = 32, cur;
3860 DWORD readback[256];
3861 static const struct wined3d_vec3 geometry[] =
3863 {-1.0f, -1.0f, -1.0f},
3864 { 1.0f, -1.0f, 0.0f},
3865 {-1.0f, 1.0f, -1.0f},
3866 { 1.0f, 1.0f, 0.0f},
3869 /* Most drivers want 2^23 for fixed point depth buffers, including r300g, r600g,
3870 * Nvidia. Use this as a fallback if the detection fails. */
3871 unsigned int fallback = 23;
3873 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
3875 FIXME("No FBOs, assuming polyoffset scale of 2^%u.\n", fallback);
3876 return (float)(1u << fallback);
3879 gl_info->gl_ops.gl.p_glGenTextures(1, &color);
3880 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, color);
3881 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
3882 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 1, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
3884 gl_info->fbo_ops.glGenRenderbuffers(1, &depth);
3885 gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, depth);
3886 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, format, 256, 1);
3888 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
3889 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3890 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
3891 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
3892 checkGLcall("Setup framebuffer");
3894 gl_info->gl_ops.gl.p_glClearColor(0.0f, 0.0f, 0.5f, 0.0f);
3895 gl_info->gl_ops.gl.p_glClearDepth(0.5f);
3896 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_TEST);
3897 gl_info->gl_ops.gl.p_glEnable(GL_POLYGON_OFFSET_FILL);
3898 gl_info->gl_ops.gl.p_glViewport(0, 0, 256, 1);
3899 checkGLcall("Misc parameters");
3901 for (;;)
3903 if (high - low <= 1)
3905 ERR("PolygonOffset scale factor detection failed, using fallback value 2^%u.\n", fallback);
3906 cur = fallback;
3907 break;
3909 cur = (low + high) / 2;
3911 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3912 /* The post viewport transform Z of the geometry runs from 0.0 to 0.5. We want to push it another
3913 * 0.25 so that the Z buffer content (0.5) cuts the quad off at half the screen. */
3914 gl_info->gl_ops.gl.p_glPolygonOffset(0.0f, (float)(1u << cur) * 0.25f);
3915 draw_test_quad(ctx, geometry, &blue);
3916 checkGLcall("Test draw");
3918 /* Rebinding texture to workaround a fglrx bug. */
3919 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, color);
3920 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, readback);
3921 checkGLcall("readback");
3923 TRACE("low %02u, high %02u, cur %2u, 0=0x%08x, 125=0x%08x, 131=0x%08x, 255=0x%08x\n",
3924 low, high, cur, readback[0], readback[125], readback[131], readback[255]);
3926 if ((readback[125] & 0xff) < 0xa0)
3927 high = cur;
3928 else if ((readback[131] & 0xff) > 0xa0)
3929 low = cur;
3930 else
3932 TRACE("Found scale factor 2^%u for format %x.\n", cur, format);
3933 break;
3937 gl_info->gl_ops.gl.p_glDeleteTextures(1, &color);
3938 gl_info->fbo_ops.glDeleteRenderbuffers(1, &depth);
3939 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
3940 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
3941 checkGLcall("Delete framebuffer");
3943 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST);
3944 gl_info->gl_ops.gl.p_glDisable(GL_POLYGON_OFFSET_FILL);
3945 return (float)(1u << cur);
3948 static void init_format_depth_bias_scale(struct wined3d_adapter *adapter,
3949 struct wined3d_caps_gl_ctx *ctx)
3951 const struct wined3d_d3d_info *d3d_info = &adapter->d3d_info;
3952 unsigned int i;
3954 for (i = 0; i < WINED3D_FORMAT_COUNT; ++i)
3956 struct wined3d_format_gl *format = get_format_gl_by_idx(adapter, i);
3958 if (format->f.depth_size && (format->f.flags[WINED3D_GL_RES_TYPE_RB] & WINED3DFMT_FLAG_DEPTH_STENCIL))
3960 TRACE("Testing depth bias scale for format %s.\n", debug_d3dformat(format->f.id));
3961 format->f.depth_bias_scale = wined3d_adapter_find_polyoffset_scale(ctx, format->internal);
3963 if (!(d3d_info->wined3d_creation_flags & WINED3D_NORMALIZED_DEPTH_BIAS))
3965 /* The single-precision binary floating-point format has
3966 * a significand precision of 24 bits.
3968 if (format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT)
3969 format->f.depth_bias_scale /= 1u << 24;
3970 else
3971 format->f.depth_bias_scale /= 1u << format->f.depth_size;
3977 static BOOL wined3d_adapter_init_format_info(struct wined3d_adapter *adapter, size_t format_size)
3979 unsigned int count = WINED3D_FORMAT_COUNT + ARRAY_SIZE(typeless_depth_stencil_formats);
3981 if (!(adapter->formats = heap_calloc(count, format_size)))
3983 ERR("Failed to allocate memory.\n");
3984 return FALSE;
3986 adapter->format_size = format_size;
3988 if (!init_format_base_info(adapter))
3989 goto fail;
3990 if (!init_format_block_info(adapter))
3991 goto fail;
3992 if (!init_format_decompress_info(adapter))
3993 goto fail;
3994 if (!init_srgb_formats(adapter))
3995 goto fail;
3997 return TRUE;
3999 fail:
4000 heap_free(adapter->formats);
4001 adapter->formats = NULL;
4002 return FALSE;
4005 BOOL wined3d_adapter_no3d_init_format_info(struct wined3d_adapter *adapter)
4007 struct wined3d_format *format;
4008 unsigned int i;
4010 static const enum wined3d_format_id blit_formats[] =
4012 WINED3DFMT_B8G8R8A8_UNORM,
4013 WINED3DFMT_B8G8R8X8_UNORM,
4014 WINED3DFMT_B5G6R5_UNORM,
4015 WINED3DFMT_B5G5R5X1_UNORM,
4016 WINED3DFMT_B5G5R5A1_UNORM,
4017 WINED3DFMT_B4G4R4A4_UNORM,
4018 WINED3DFMT_B2G3R3_UNORM,
4019 WINED3DFMT_A8_UNORM,
4020 WINED3DFMT_B2G3R3A8_UNORM,
4021 WINED3DFMT_B4G4R4X4_UNORM,
4022 WINED3DFMT_R10G10B10A2_UNORM,
4023 WINED3DFMT_R8G8B8A8_UNORM,
4024 WINED3DFMT_R8G8B8X8_UNORM,
4025 WINED3DFMT_R16G16_UNORM,
4026 WINED3DFMT_B10G10R10A2_UNORM,
4027 WINED3DFMT_R16G16B16A16_UNORM,
4028 WINED3DFMT_P8_UINT,
4031 if (!wined3d_adapter_init_format_info(adapter, sizeof(struct wined3d_format)))
4032 return FALSE;
4034 for (i = 0; i < ARRAY_SIZE(blit_formats); ++i)
4036 if (!(format = get_format_internal(adapter, blit_formats[i])))
4037 return FALSE;
4039 format->flags[WINED3D_GL_RES_TYPE_TEX_2D] |= WINED3DFMT_FLAG_BLIT;
4040 format->flags[WINED3D_GL_RES_TYPE_RB] |= WINED3DFMT_FLAG_BLIT;
4043 return TRUE;
4046 /* Context activation is done by the caller. */
4047 BOOL wined3d_adapter_gl_init_format_info(struct wined3d_adapter *adapter, struct wined3d_caps_gl_ctx *ctx)
4049 struct wined3d_gl_info *gl_info = &adapter->gl_info;
4051 if (!wined3d_adapter_init_format_info(adapter, sizeof(struct wined3d_format_gl)))
4052 return FALSE;
4054 if (!init_format_texture_info(adapter, gl_info)) goto fail;
4055 if (!init_format_vertex_info(adapter, gl_info)) goto fail;
4057 apply_format_fixups(adapter, gl_info);
4058 init_format_fbo_compat_info(adapter, ctx);
4059 init_format_filter_info(adapter, gl_info);
4060 init_format_gen_mipmap_info(adapter, gl_info);
4061 init_format_depth_bias_scale(adapter, ctx);
4063 if (!init_typeless_formats(adapter)) goto fail;
4065 return TRUE;
4067 fail:
4068 heap_free(adapter->formats);
4069 adapter->formats = NULL;
4070 return FALSE;
4073 static void init_vulkan_format_info(struct wined3d_format_vk *format,
4074 const struct wined3d_vk_info *vk_info, VkPhysicalDevice vk_physical_device)
4076 static const struct
4078 enum wined3d_format_id id;
4079 VkFormat vk_format;
4080 const char *fixup;
4082 vulkan_formats[] =
4084 {WINED3DFMT_R32G32B32A32_FLOAT, VK_FORMAT_R32G32B32A32_SFLOAT, },
4085 {WINED3DFMT_R32G32B32A32_UINT, VK_FORMAT_R32G32B32A32_UINT, },
4086 {WINED3DFMT_R32G32B32A32_SINT, VK_FORMAT_R32G32B32A32_SINT, },
4087 {WINED3DFMT_R32G32B32_FLOAT, VK_FORMAT_R32G32B32_SFLOAT, },
4088 {WINED3DFMT_R32G32B32_UINT, VK_FORMAT_R32G32B32_UINT, },
4089 {WINED3DFMT_R32G32B32_SINT, VK_FORMAT_R32G32B32_SINT, },
4090 {WINED3DFMT_R16G16B16A16_FLOAT, VK_FORMAT_R16G16B16A16_SFLOAT, },
4091 {WINED3DFMT_R16G16B16A16_UNORM, VK_FORMAT_R16G16B16A16_UNORM, },
4092 {WINED3DFMT_R16G16B16A16_UINT, VK_FORMAT_R16G16B16A16_UINT, },
4093 {WINED3DFMT_R16G16B16A16_SNORM, VK_FORMAT_R16G16B16A16_SNORM, },
4094 {WINED3DFMT_R16G16B16A16_SINT, VK_FORMAT_R16G16B16A16_SINT, },
4095 {WINED3DFMT_R32G32_FLOAT, VK_FORMAT_R32G32_SFLOAT, },
4096 {WINED3DFMT_R32G32_UINT, VK_FORMAT_R32G32_UINT, },
4097 {WINED3DFMT_R32G32_SINT, VK_FORMAT_R32G32_SINT, },
4098 {WINED3DFMT_R10G10B10A2_UNORM, VK_FORMAT_A2B10G10R10_UNORM_PACK32,},
4099 {WINED3DFMT_R11G11B10_FLOAT, VK_FORMAT_B10G11R11_UFLOAT_PACK32, },
4100 {WINED3DFMT_R8G8_UNORM, VK_FORMAT_R8G8_UNORM, },
4101 {WINED3DFMT_R8G8_UINT, VK_FORMAT_R8G8_UINT, },
4102 {WINED3DFMT_R8G8_SNORM, VK_FORMAT_R8G8_SNORM, },
4103 {WINED3DFMT_R8G8_SINT, VK_FORMAT_R8G8_SINT, },
4104 {WINED3DFMT_R8G8B8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, },
4105 {WINED3DFMT_R8G8B8A8_UNORM_SRGB, VK_FORMAT_R8G8B8A8_SRGB, },
4106 {WINED3DFMT_R8G8B8A8_UINT, VK_FORMAT_R8G8B8A8_UINT, },
4107 {WINED3DFMT_R8G8B8A8_SNORM, VK_FORMAT_R8G8B8A8_SNORM, },
4108 {WINED3DFMT_R8G8B8A8_SINT, VK_FORMAT_R8G8B8A8_SINT, },
4109 {WINED3DFMT_R16G16_FLOAT, VK_FORMAT_R16G16_SFLOAT, },
4110 {WINED3DFMT_R16G16_UNORM, VK_FORMAT_R16G16_UNORM, },
4111 {WINED3DFMT_R16G16_UINT, VK_FORMAT_R16G16_UINT, },
4112 {WINED3DFMT_R16G16_SNORM, VK_FORMAT_R16G16_SNORM, },
4113 {WINED3DFMT_R16G16_SINT, VK_FORMAT_R16G16_SINT, },
4114 {WINED3DFMT_D32_FLOAT, VK_FORMAT_D32_SFLOAT, },
4115 {WINED3DFMT_R32_FLOAT, VK_FORMAT_R32_SFLOAT, },
4116 {WINED3DFMT_R32_UINT, VK_FORMAT_R32_UINT, },
4117 {WINED3DFMT_R32_SINT, VK_FORMAT_R32_SINT, },
4118 {WINED3DFMT_R16_FLOAT, VK_FORMAT_R16_SFLOAT, },
4119 {WINED3DFMT_D16_UNORM, VK_FORMAT_D16_UNORM, },
4120 {WINED3DFMT_R16_UNORM, VK_FORMAT_R16_UNORM, },
4121 {WINED3DFMT_R16_UINT, VK_FORMAT_R16_UINT, },
4122 {WINED3DFMT_R16_SNORM, VK_FORMAT_R16_SNORM, },
4123 {WINED3DFMT_R16_SINT, VK_FORMAT_R16_SINT, },
4124 {WINED3DFMT_R8_UNORM, VK_FORMAT_R8_UNORM, },
4125 {WINED3DFMT_R8_UINT, VK_FORMAT_R8_UINT, },
4126 {WINED3DFMT_R8_SNORM, VK_FORMAT_R8_SNORM, },
4127 {WINED3DFMT_R8_SINT, VK_FORMAT_R8_SINT, },
4128 {WINED3DFMT_A8_UNORM, VK_FORMAT_R8_UNORM, "000X"},
4129 {WINED3DFMT_B8G8R8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM, },
4130 {WINED3DFMT_B8G8R8A8_UNORM_SRGB, VK_FORMAT_B8G8R8A8_SRGB, },
4131 {WINED3DFMT_B8G8R8X8_UNORM, VK_FORMAT_B8G8R8A8_UNORM, "XYZ1"},
4132 {WINED3DFMT_B8G8R8X8_UNORM_SRGB, VK_FORMAT_B8G8R8A8_SRGB, "XYZ1"},
4133 {WINED3DFMT_BC1_UNORM, VK_FORMAT_BC1_RGBA_UNORM_BLOCK, },
4134 {WINED3DFMT_BC1_UNORM_SRGB, VK_FORMAT_BC1_RGBA_SRGB_BLOCK, },
4135 {WINED3DFMT_BC2_UNORM, VK_FORMAT_BC2_UNORM_BLOCK, },
4136 {WINED3DFMT_BC2_UNORM_SRGB, VK_FORMAT_BC2_SRGB_BLOCK, },
4137 {WINED3DFMT_BC3_UNORM, VK_FORMAT_BC3_UNORM_BLOCK, },
4138 {WINED3DFMT_BC3_UNORM_SRGB, VK_FORMAT_BC3_SRGB_BLOCK, },
4139 {WINED3DFMT_BC4_UNORM, VK_FORMAT_BC4_UNORM_BLOCK, },
4140 {WINED3DFMT_BC4_SNORM, VK_FORMAT_BC4_SNORM_BLOCK, },
4141 {WINED3DFMT_BC5_UNORM, VK_FORMAT_BC5_UNORM_BLOCK, },
4142 {WINED3DFMT_BC5_SNORM, VK_FORMAT_BC5_SNORM_BLOCK, },
4143 {WINED3DFMT_BC6H_UF16, VK_FORMAT_BC6H_UFLOAT_BLOCK, },
4144 {WINED3DFMT_BC6H_SF16, VK_FORMAT_BC6H_SFLOAT_BLOCK, },
4145 {WINED3DFMT_BC7_UNORM, VK_FORMAT_BC7_UNORM_BLOCK, },
4146 {WINED3DFMT_BC7_UNORM_SRGB, VK_FORMAT_BC7_SRGB_BLOCK, },
4147 {WINED3DFMT_R9G9B9E5_SHAREDEXP, VK_FORMAT_E5B9G9R9_UFLOAT_PACK32, },
4148 {WINED3DFMT_D32_FLOAT_S8X24_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT, },
4149 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS, VK_FORMAT_D32_SFLOAT_S8_UINT, },
4150 {WINED3DFMT_X32_TYPELESS_G8X24_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT, },
4151 {WINED3DFMT_D24_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, },
4153 VkFormat vk_format = VK_FORMAT_UNDEFINED;
4154 VkImageFormatProperties image_properties;
4155 VkFormatFeatureFlags texture_flags;
4156 VkFormatProperties properties;
4157 VkImageUsageFlags vk_usage;
4158 unsigned int flags;
4159 const char *fixup;
4160 unsigned int i;
4161 uint32_t mask;
4162 VkResult vr;
4164 for (i = 0; i < ARRAY_SIZE(vulkan_formats); ++i)
4166 if (vulkan_formats[i].id == format->f.id)
4168 vk_format = vulkan_formats[i].vk_format;
4169 fixup = vulkan_formats[i].fixup;
4170 break;
4173 if (!vk_format)
4175 WARN("Unsupported format %s.\n", debug_d3dformat(format->f.id));
4176 return;
4179 format->vk_format = vk_format;
4180 if (fixup)
4181 format->f.color_fixup = create_color_fixup_desc_from_string(fixup);
4182 else
4183 format->f.color_fixup = COLOR_FIXUP_IDENTITY;
4185 VK_CALL(vkGetPhysicalDeviceFormatProperties(vk_physical_device, vk_format, &properties));
4186 if (vk_format == VK_FORMAT_D24_UNORM_S8_UINT)
4188 if (~properties.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
4190 /* AMD doesn't support VK_FORMAT_D24_UNORM_S8_UINT. */
4191 WARN("Mapping VK_FORMAT_D24_UNORM_S8_UINT to VK_FORMAT_D32_SFLOAT_S8_UINT.\n");
4193 format->vk_format = vk_format = VK_FORMAT_D32_SFLOAT_S8_UINT;
4194 VK_CALL(vkGetPhysicalDeviceFormatProperties(vk_physical_device, vk_format, &properties));
4198 if (properties.bufferFeatures & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT)
4199 format->f.flags[WINED3D_GL_RES_TYPE_BUFFER] |= WINED3DFMT_FLAG_VERTEX_ATTRIBUTE;
4200 if (properties.bufferFeatures & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT)
4201 format->f.flags[WINED3D_GL_RES_TYPE_BUFFER] |= WINED3DFMT_FLAG_TEXTURE;
4203 flags = 0;
4204 texture_flags = properties.linearTilingFeatures | properties.optimalTilingFeatures;
4205 if (texture_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)
4207 flags |= WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_VTF;
4209 if (texture_flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)
4211 flags |= WINED3DFMT_FLAG_RENDERTARGET;
4213 if (texture_flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT)
4215 flags |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
4217 if (texture_flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
4219 flags |= WINED3DFMT_FLAG_DEPTH_STENCIL;
4221 if (texture_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT)
4223 flags |= WINED3DFMT_FLAG_FILTERING;
4225 if (texture_flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)
4227 flags |= WINED3DFMT_FLAG_UNORDERED_ACCESS;
4230 if (!(~flags & (WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_FILTERING)))
4231 flags |= WINED3DFMT_FLAG_GEN_MIPMAP;
4233 format->f.flags[WINED3D_GL_RES_TYPE_TEX_1D] |= flags;
4234 format->f.flags[WINED3D_GL_RES_TYPE_TEX_2D] |= flags;
4235 format->f.flags[WINED3D_GL_RES_TYPE_TEX_3D] |= flags;
4236 format->f.flags[WINED3D_GL_RES_TYPE_TEX_CUBE] |= flags;
4238 vk_usage = 0;
4239 if (texture_flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)
4240 vk_usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
4241 else if (texture_flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
4242 vk_usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
4243 if (vk_usage)
4245 if ((vr = VK_CALL(vkGetPhysicalDeviceImageFormatProperties(vk_physical_device, vk_format,
4246 VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, vk_usage, 0, &image_properties))) < 0)
4248 ERR("Failed to get image format properties, vr %s.\n", wined3d_debug_vkresult(vr));
4249 return;
4252 mask = image_properties.sampleCounts & 0x3f;
4253 while (mask)
4255 i = (1u << wined3d_bit_scan(&mask)) - 1;
4256 format->f.multisample_types |= 1u << i;
4261 BOOL wined3d_adapter_vk_init_format_info(struct wined3d_adapter_vk *adapter_vk,
4262 const struct wined3d_vk_info *vk_info)
4264 VkPhysicalDevice vk_physical_device = adapter_vk->physical_device;
4265 struct wined3d_adapter *adapter = &adapter_vk->a;
4266 struct wined3d_format_vk *format;
4267 unsigned int i;
4269 if (!wined3d_adapter_init_format_info(adapter, sizeof(*format)))
4270 return FALSE;
4272 for (i = 0; i < WINED3D_FORMAT_COUNT; ++i)
4274 format = wined3d_format_vk_mutable(get_format_by_idx(adapter, i));
4276 if (format->f.id)
4277 init_vulkan_format_info(format, vk_info, vk_physical_device);
4280 if (!init_typeless_formats(adapter)) goto fail;
4282 return TRUE;
4284 fail:
4285 heap_free(adapter->formats);
4286 adapter->formats = NULL;
4287 return FALSE;
4290 const struct wined3d_format *wined3d_get_format(const struct wined3d_adapter *adapter,
4291 enum wined3d_format_id format_id, unsigned int bind_flags)
4293 const struct wined3d_format *format;
4294 int idx = get_format_idx(format_id);
4295 unsigned int i;
4297 if (idx == -1)
4299 FIXME("Can't find format %s (%#x) in the format lookup table.\n",
4300 debug_d3dformat(format_id), format_id);
4301 return get_format_internal(adapter, WINED3DFMT_UNKNOWN);
4304 format = get_format_by_idx(adapter, idx);
4306 if (bind_flags & WINED3D_BIND_DEPTH_STENCIL && wined3d_format_is_typeless(format))
4308 for (i = 0; i < ARRAY_SIZE(typeless_depth_stencil_formats); ++i)
4310 if (typeless_depth_stencil_formats[i].typeless_id == format_id)
4311 return get_format_by_idx(adapter, WINED3D_FORMAT_COUNT + i);
4314 FIXME("Cannot find depth/stencil typeless format %s (%#x).\n",
4315 debug_d3dformat(format_id), format_id);
4316 return get_format_internal(adapter, WINED3DFMT_UNKNOWN);
4319 return format;
4322 BOOL wined3d_format_is_depth_view(enum wined3d_format_id resource_format_id,
4323 enum wined3d_format_id view_format_id)
4325 unsigned int i;
4327 for (i = 0; i < ARRAY_SIZE(typeless_depth_stencil_formats); ++i)
4329 if (typeless_depth_stencil_formats[i].typeless_id == resource_format_id)
4330 return typeless_depth_stencil_formats[i].depth_view_id == view_format_id;
4332 return FALSE;
4335 void wined3d_format_calculate_pitch(const struct wined3d_format *format, unsigned int alignment,
4336 unsigned int width, unsigned int height, unsigned int *row_pitch, unsigned int *slice_pitch)
4338 /* For block based formats, pitch means the amount of bytes to the next
4339 * row of blocks rather than the next row of pixels. */
4340 if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_BLOCKS)
4342 unsigned int row_block_count = (width + format->block_width - 1) / format->block_width;
4343 unsigned int slice_block_count = (height + format->block_height - 1) / format->block_height;
4344 *row_pitch = row_block_count * format->block_byte_count;
4345 *row_pitch = (*row_pitch + alignment - 1) & ~(alignment - 1);
4346 *slice_pitch = *row_pitch * slice_block_count;
4348 else
4350 *row_pitch = format->byte_count * width; /* Bytes / row */
4351 *row_pitch = (*row_pitch + alignment - 1) & ~(alignment - 1);
4352 *slice_pitch = *row_pitch * height;
4355 if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_HEIGHT_SCALE)
4357 /* The D3D format requirements make sure that the resulting format is an integer again */
4358 *slice_pitch *= format->height_scale.numerator;
4359 *slice_pitch /= format->height_scale.denominator;
4362 TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch, *slice_pitch);
4365 UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT alignment,
4366 UINT width, UINT height, UINT depth)
4368 unsigned int row_pitch, slice_pitch;
4370 if (format->id == WINED3DFMT_UNKNOWN)
4371 return 0;
4373 if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_BROKEN_PITCH)
4374 return width * height * depth * format->byte_count;
4376 wined3d_format_calculate_pitch(format, alignment, width, height, &row_pitch, &slice_pitch);
4378 return slice_pitch * depth;
4381 BOOL wined3d_formats_are_srgb_variants(enum wined3d_format_id format1, enum wined3d_format_id format2)
4383 unsigned int i;
4385 for (i = 0; i < ARRAY_SIZE(format_srgb_info); ++i)
4387 if (format1 == format_srgb_info[i].srgb_format_id)
4388 return format2 == format_srgb_info[i].base_format_id;
4389 if (format1 == format_srgb_info[i].base_format_id)
4390 return format2 == format_srgb_info[i].srgb_format_id;
4392 return FALSE;
4395 /*****************************************************************************
4396 * Trace formatting of useful values
4398 const char *debug_box(const struct wined3d_box *box)
4400 if (!box)
4401 return "(null)";
4402 return wine_dbg_sprintf("(%u, %u, %u)-(%u, %u, %u)",
4403 box->left, box->top, box->front,
4404 box->right, box->bottom, box->back);
4407 const char *debug_color(const struct wined3d_color *color)
4409 if (!color)
4410 return "(null)";
4411 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
4412 color->r, color->g, color->b, color->a);
4415 const char *debug_ivec4(const struct wined3d_ivec4 *v)
4417 if (!v)
4418 return "(null)";
4419 return wine_dbg_sprintf("{%d, %d, %d, %d}",
4420 v->x, v->y, v->z, v->w);
4423 const char *debug_uvec4(const struct wined3d_uvec4 *v)
4425 if (!v)
4426 return "(null)";
4427 return wine_dbg_sprintf("{%u, %u, %u, %u}",
4428 v->x, v->y, v->z, v->w);
4431 const char *debug_vec4(const struct wined3d_vec4 *v)
4433 if (!v)
4434 return "(null)";
4435 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
4436 v->x, v->y, v->z, v->w);
4439 const char *debug_const_bo_address(const struct wined3d_const_bo_address *address)
4441 if (!address)
4442 return "(null)";
4443 return wine_dbg_sprintf("{%#lx:%p}", address->buffer_object, address->addr);
4446 const char *debug_bo_address(const struct wined3d_bo_address *address)
4448 return debug_const_bo_address((const struct wined3d_const_bo_address *)address);
4451 const char *debug_d3dformat(enum wined3d_format_id format_id)
4453 switch (format_id)
4455 #define FMT_TO_STR(format_id) case format_id: return #format_id
4456 FMT_TO_STR(WINED3DFMT_UNKNOWN);
4457 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM);
4458 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM);
4459 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM);
4460 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM);
4461 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM);
4462 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM);
4463 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM);
4464 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM);
4465 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM);
4466 FMT_TO_STR(WINED3DFMT_P8_UINT);
4467 FMT_TO_STR(WINED3DFMT_L8_UNORM);
4468 FMT_TO_STR(WINED3DFMT_L8A8_UNORM);
4469 FMT_TO_STR(WINED3DFMT_L4A4_UNORM);
4470 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM);
4471 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM);
4472 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM);
4473 FMT_TO_STR(WINED3DFMT_R10G10B10X2_TYPELESS);
4474 FMT_TO_STR(WINED3DFMT_R10G10B10X2_UINT);
4475 FMT_TO_STR(WINED3DFMT_R10G10B10X2_SNORM);
4476 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM);
4477 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE);
4478 FMT_TO_STR(WINED3DFMT_D32_UNORM);
4479 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM);
4480 FMT_TO_STR(WINED3DFMT_X8D24_UNORM);
4481 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM);
4482 FMT_TO_STR(WINED3DFMT_L16_UNORM);
4483 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT);
4484 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx);
4485 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS);
4486 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT);
4487 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT);
4488 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT);
4489 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS);
4490 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT);
4491 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT);
4492 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT);
4493 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS);
4494 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT);
4495 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM);
4496 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT);
4497 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM);
4498 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT);
4499 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS);
4500 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT);
4501 FMT_TO_STR(WINED3DFMT_R32G32_UINT);
4502 FMT_TO_STR(WINED3DFMT_R32G32_SINT);
4503 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS);
4504 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT);
4505 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS);
4506 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT);
4507 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS);
4508 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM);
4509 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT);
4510 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM);
4511 FMT_TO_STR(WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM);
4512 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT);
4513 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS);
4514 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM);
4515 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB);
4516 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT);
4517 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM);
4518 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT);
4519 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS);
4520 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT);
4521 FMT_TO_STR(WINED3DFMT_R16G16_UNORM);
4522 FMT_TO_STR(WINED3DFMT_R16G16_UINT);
4523 FMT_TO_STR(WINED3DFMT_R16G16_SNORM);
4524 FMT_TO_STR(WINED3DFMT_R16G16_SINT);
4525 FMT_TO_STR(WINED3DFMT_R32_TYPELESS);
4526 FMT_TO_STR(WINED3DFMT_D32_FLOAT);
4527 FMT_TO_STR(WINED3DFMT_R32_FLOAT);
4528 FMT_TO_STR(WINED3DFMT_R32_UINT);
4529 FMT_TO_STR(WINED3DFMT_R32_SINT);
4530 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS);
4531 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT);
4532 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS);
4533 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT);
4534 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS);
4535 FMT_TO_STR(WINED3DFMT_R8G8_UNORM);
4536 FMT_TO_STR(WINED3DFMT_R8G8_UINT);
4537 FMT_TO_STR(WINED3DFMT_R8G8_SNORM);
4538 FMT_TO_STR(WINED3DFMT_R8G8_SINT);
4539 FMT_TO_STR(WINED3DFMT_R16_TYPELESS);
4540 FMT_TO_STR(WINED3DFMT_R16_FLOAT);
4541 FMT_TO_STR(WINED3DFMT_D16_UNORM);
4542 FMT_TO_STR(WINED3DFMT_R16_UNORM);
4543 FMT_TO_STR(WINED3DFMT_R16_UINT);
4544 FMT_TO_STR(WINED3DFMT_R16_SNORM);
4545 FMT_TO_STR(WINED3DFMT_R16_SINT);
4546 FMT_TO_STR(WINED3DFMT_R8_TYPELESS);
4547 FMT_TO_STR(WINED3DFMT_R8_UNORM);
4548 FMT_TO_STR(WINED3DFMT_R8_UINT);
4549 FMT_TO_STR(WINED3DFMT_R8_SNORM);
4550 FMT_TO_STR(WINED3DFMT_R8_SINT);
4551 FMT_TO_STR(WINED3DFMT_A8_UNORM);
4552 FMT_TO_STR(WINED3DFMT_R1_UNORM);
4553 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP);
4554 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM);
4555 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM);
4556 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS);
4557 FMT_TO_STR(WINED3DFMT_BC1_UNORM);
4558 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB);
4559 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS);
4560 FMT_TO_STR(WINED3DFMT_BC2_UNORM);
4561 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB);
4562 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS);
4563 FMT_TO_STR(WINED3DFMT_BC3_UNORM);
4564 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB);
4565 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS);
4566 FMT_TO_STR(WINED3DFMT_BC4_UNORM);
4567 FMT_TO_STR(WINED3DFMT_BC4_SNORM);
4568 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS);
4569 FMT_TO_STR(WINED3DFMT_BC5_UNORM);
4570 FMT_TO_STR(WINED3DFMT_BC5_SNORM);
4571 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM);
4572 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM);
4573 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM);
4574 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM);
4575 FMT_TO_STR(WINED3DFMT_B8G8R8A8_TYPELESS);
4576 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM_SRGB);
4577 FMT_TO_STR(WINED3DFMT_B8G8R8X8_TYPELESS);
4578 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM_SRGB);
4579 FMT_TO_STR(WINED3DFMT_BC6H_TYPELESS);
4580 FMT_TO_STR(WINED3DFMT_BC6H_UF16);
4581 FMT_TO_STR(WINED3DFMT_BC6H_SF16);
4582 FMT_TO_STR(WINED3DFMT_BC7_TYPELESS);
4583 FMT_TO_STR(WINED3DFMT_BC7_UNORM);
4584 FMT_TO_STR(WINED3DFMT_BC7_UNORM_SRGB);
4585 FMT_TO_STR(WINED3DFMT_UYVY);
4586 FMT_TO_STR(WINED3DFMT_YUY2);
4587 FMT_TO_STR(WINED3DFMT_YV12);
4588 FMT_TO_STR(WINED3DFMT_DXT1);
4589 FMT_TO_STR(WINED3DFMT_DXT2);
4590 FMT_TO_STR(WINED3DFMT_DXT3);
4591 FMT_TO_STR(WINED3DFMT_DXT4);
4592 FMT_TO_STR(WINED3DFMT_DXT5);
4593 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8);
4594 FMT_TO_STR(WINED3DFMT_G8R8_G8B8);
4595 FMT_TO_STR(WINED3DFMT_R8G8_B8G8);
4596 FMT_TO_STR(WINED3DFMT_ATI1N);
4597 FMT_TO_STR(WINED3DFMT_ATI2N);
4598 FMT_TO_STR(WINED3DFMT_INST);
4599 FMT_TO_STR(WINED3DFMT_NVDB);
4600 FMT_TO_STR(WINED3DFMT_NVHU);
4601 FMT_TO_STR(WINED3DFMT_NVHS);
4602 FMT_TO_STR(WINED3DFMT_INTZ);
4603 FMT_TO_STR(WINED3DFMT_RESZ);
4604 FMT_TO_STR(WINED3DFMT_NULL);
4605 FMT_TO_STR(WINED3DFMT_R16);
4606 FMT_TO_STR(WINED3DFMT_AL16);
4607 FMT_TO_STR(WINED3DFMT_NV12);
4608 FMT_TO_STR(WINED3DFMT_ATOC);
4609 #undef FMT_TO_STR
4610 default:
4612 char fourcc[5];
4613 fourcc[0] = (char)(format_id);
4614 fourcc[1] = (char)(format_id >> 8);
4615 fourcc[2] = (char)(format_id >> 16);
4616 fourcc[3] = (char)(format_id >> 24);
4617 fourcc[4] = 0;
4618 if (isprint(fourcc[0]) && isprint(fourcc[1]) && isprint(fourcc[2]) && isprint(fourcc[3]))
4619 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id, fourcc);
4620 else
4621 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id);
4623 return "unrecognized";
4627 const char *debug_d3ddevicetype(enum wined3d_device_type device_type)
4629 switch (device_type)
4631 #define DEVTYPE_TO_STR(dev) case dev: return #dev
4632 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL);
4633 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF);
4634 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW);
4635 #undef DEVTYPE_TO_STR
4636 default:
4637 FIXME("Unrecognized device type %#x.\n", device_type);
4638 return "unrecognized";
4642 struct debug_buffer
4644 char str[200]; /* wine_dbg_sprintf() limits string size to 200 */
4645 char *ptr;
4646 int size;
4649 static void init_debug_buffer(struct debug_buffer *buffer, const char *default_string)
4651 snprintf(buffer->str, sizeof(buffer->str), "%s", default_string);
4652 buffer->ptr = buffer->str;
4653 buffer->size = sizeof(buffer->str);
4656 static void debug_append(struct debug_buffer *buffer, const char *str, const char *separator)
4658 int size;
4660 if (!separator || buffer->ptr == buffer->str)
4661 separator = "";
4662 size = snprintf(buffer->ptr, buffer->size, "%s%s", separator, str);
4663 if (size == -1 || size >= buffer->size)
4665 buffer->size = 0;
4666 strcpy(&buffer->str[sizeof(buffer->str) - 4], "...");
4667 return;
4670 buffer->ptr += size;
4671 buffer->size -= size;
4674 const char *wined3d_debug_resource_access(DWORD access)
4676 struct debug_buffer buffer;
4678 init_debug_buffer(&buffer, "0");
4679 #define ACCESS_TO_STR(x) if (access & x) { debug_append(&buffer, #x, " | "); access &= ~x; }
4680 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_GPU);
4681 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_CPU);
4682 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_MAP_R);
4683 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_MAP_W);
4684 #undef ACCESS_TO_STR
4685 if (access)
4686 FIXME("Unrecognised access flag(s) %#x.\n", access);
4688 return wine_dbg_sprintf("%s", buffer.str);
4691 const char *wined3d_debug_bind_flags(DWORD bind_flags)
4693 struct debug_buffer buffer;
4695 init_debug_buffer(&buffer, "0");
4696 #define BIND_FLAG_TO_STR(x) if (bind_flags & x) { debug_append(&buffer, #x, " | "); bind_flags &= ~x; }
4697 BIND_FLAG_TO_STR(WINED3D_BIND_VERTEX_BUFFER);
4698 BIND_FLAG_TO_STR(WINED3D_BIND_INDEX_BUFFER);
4699 BIND_FLAG_TO_STR(WINED3D_BIND_CONSTANT_BUFFER);
4700 BIND_FLAG_TO_STR(WINED3D_BIND_SHADER_RESOURCE);
4701 BIND_FLAG_TO_STR(WINED3D_BIND_STREAM_OUTPUT);
4702 BIND_FLAG_TO_STR(WINED3D_BIND_RENDER_TARGET);
4703 BIND_FLAG_TO_STR(WINED3D_BIND_DEPTH_STENCIL);
4704 BIND_FLAG_TO_STR(WINED3D_BIND_UNORDERED_ACCESS);
4705 BIND_FLAG_TO_STR(WINED3D_BIND_INDIRECT_BUFFER);
4706 #undef BIND_FLAG_TO_STR
4707 if (bind_flags)
4708 FIXME("Unrecognised bind flag(s) %#x.\n", bind_flags);
4710 return wine_dbg_sprintf("%s", buffer.str);
4713 const char *wined3d_debug_view_desc(const struct wined3d_view_desc *d, const struct wined3d_resource *resource)
4715 struct debug_buffer buffer;
4716 unsigned int flags = d->flags;
4718 init_debug_buffer(&buffer, "0");
4719 #define VIEW_FLAG_TO_STR(x) if (flags & x) { debug_append(&buffer, #x, " | "); flags &= ~x; }
4720 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_RAW);
4721 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_APPEND);
4722 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_COUNTER);
4723 VIEW_FLAG_TO_STR(WINED3D_VIEW_TEXTURE_CUBE);
4724 VIEW_FLAG_TO_STR(WINED3D_VIEW_TEXTURE_ARRAY);
4725 VIEW_FLAG_TO_STR(WINED3D_VIEW_READ_ONLY_DEPTH);
4726 VIEW_FLAG_TO_STR(WINED3D_VIEW_READ_ONLY_STENCIL);
4727 #undef VIEW_FLAG_TO_STR
4728 if (flags)
4729 FIXME("Unrecognised view flag(s) %#x.\n", flags);
4731 if (resource->type == WINED3D_RTYPE_BUFFER)
4732 return wine_dbg_sprintf("format %s, flags %s, start_idx %u, count %u",
4733 debug_d3dformat(d->format_id), buffer.str, d->u.buffer.start_idx, d->u.buffer.count);
4734 else
4735 return wine_dbg_sprintf("format %s, flags %s, level_idx %u, level_count %u, layer_idx %u, layer_count %u",
4736 debug_d3dformat(d->format_id), buffer.str, d->u.texture.level_idx, d->u.texture.level_count,
4737 d->u.texture.layer_idx, d->u.texture.layer_count);
4740 const char *debug_d3dusage(DWORD usage)
4742 struct debug_buffer buffer;
4744 init_debug_buffer(&buffer, "0");
4745 #define WINED3DUSAGE_TO_STR(x) if (usage & x) { debug_append(&buffer, #x, " | "); usage &= ~x; }
4746 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING);
4747 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP);
4748 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS);
4749 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES);
4750 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES);
4751 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC);
4752 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICTED_CONTENT);
4753 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE_DRIVER);
4754 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE);
4755 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP);
4756 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTAPI);
4757 WINED3DUSAGE_TO_STR(WINED3DUSAGE_LEGACY_CUBEMAP);
4758 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OWNDC);
4759 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL);
4760 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY);
4761 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_FILTER);
4762 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_GENMIPMAP);
4763 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP);
4764 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING);
4765 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD);
4766 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE);
4767 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE);
4768 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP);
4769 #undef WINED3DUSAGE_TO_STR
4770 if (usage)
4771 FIXME("Unrecognized usage flag(s) %#x.\n", usage);
4773 return wine_dbg_sprintf("%s", buffer.str);
4776 const char *debug_d3ddeclmethod(enum wined3d_decl_method method)
4778 switch (method)
4780 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
4781 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT);
4782 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U);
4783 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V);
4784 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV);
4785 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV);
4786 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP);
4787 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED);
4788 #undef WINED3DDECLMETHOD_TO_STR
4789 default:
4790 FIXME("Unrecognized declaration method %#x.\n", method);
4791 return "unrecognized";
4795 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage)
4797 switch (usage)
4799 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
4800 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION);
4801 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT);
4802 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES);
4803 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL);
4804 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE);
4805 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD);
4806 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT);
4807 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL);
4808 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR);
4809 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT);
4810 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR);
4811 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG);
4812 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH);
4813 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE);
4814 #undef WINED3DDECLUSAGE_TO_STR
4815 default:
4816 FIXME("Unrecognized %u declaration usage!\n", usage);
4817 return "unrecognized";
4821 const char *debug_d3dinput_classification(enum wined3d_input_classification classification)
4823 switch (classification)
4825 #define WINED3D_TO_STR(x) case x: return #x
4826 WINED3D_TO_STR(WINED3D_INPUT_PER_VERTEX_DATA);
4827 WINED3D_TO_STR(WINED3D_INPUT_PER_INSTANCE_DATA);
4828 #undef WINED3D_TO_STR
4829 default:
4830 FIXME("Unrecognized input classification %#x.\n", classification);
4831 return "unrecognized";
4835 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type)
4837 switch (resource_type)
4839 #define WINED3D_TO_STR(x) case x: return #x
4840 WINED3D_TO_STR(WINED3D_RTYPE_NONE);
4841 WINED3D_TO_STR(WINED3D_RTYPE_BUFFER);
4842 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_1D);
4843 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_2D);
4844 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_3D);
4845 #undef WINED3D_TO_STR
4846 default:
4847 FIXME("Unrecognized resource type %#x.\n", resource_type);
4848 return "unrecognized";
4852 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type)
4854 switch (primitive_type)
4856 #define PRIM_TO_STR(prim) case prim: return #prim
4857 PRIM_TO_STR(WINED3D_PT_UNDEFINED);
4858 PRIM_TO_STR(WINED3D_PT_POINTLIST);
4859 PRIM_TO_STR(WINED3D_PT_LINELIST);
4860 PRIM_TO_STR(WINED3D_PT_LINESTRIP);
4861 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST);
4862 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP);
4863 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN);
4864 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ);
4865 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ);
4866 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ);
4867 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ);
4868 PRIM_TO_STR(WINED3D_PT_PATCH);
4869 #undef PRIM_TO_STR
4870 default:
4871 FIXME("Unrecognized primitive type %#x.\n", primitive_type);
4872 return "unrecognized";
4876 const char *debug_d3drenderstate(enum wined3d_render_state state)
4878 switch (state)
4880 #define D3DSTATE_TO_STR(u) case u: return #u
4881 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS);
4882 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE);
4883 D3DSTATE_TO_STR(WINED3D_RS_WRAPU);
4884 D3DSTATE_TO_STR(WINED3D_RS_WRAPV);
4885 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE);
4886 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE);
4887 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE);
4888 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN);
4889 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE);
4890 D3DSTATE_TO_STR(WINED3D_RS_ROP2);
4891 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK);
4892 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE);
4893 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE);
4894 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL);
4895 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND);
4896 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND);
4897 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE);
4898 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC);
4899 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF);
4900 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC);
4901 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE);
4902 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE);
4903 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE);
4904 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE);
4905 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE);
4906 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL);
4907 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX);
4908 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA);
4909 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR);
4910 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE);
4911 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART);
4912 D3DSTATE_TO_STR(WINED3D_RS_FOGEND);
4913 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY);
4914 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE);
4915 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE);
4916 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS);
4917 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE);
4918 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY);
4919 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH);
4920 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT);
4921 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE);
4922 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL);
4923 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL);
4924 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS);
4925 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC);
4926 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF);
4927 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK);
4928 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK);
4929 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR);
4930 D3DSTATE_TO_STR(WINED3D_RS_WRAP0);
4931 D3DSTATE_TO_STR(WINED3D_RS_WRAP1);
4932 D3DSTATE_TO_STR(WINED3D_RS_WRAP2);
4933 D3DSTATE_TO_STR(WINED3D_RS_WRAP3);
4934 D3DSTATE_TO_STR(WINED3D_RS_WRAP4);
4935 D3DSTATE_TO_STR(WINED3D_RS_WRAP5);
4936 D3DSTATE_TO_STR(WINED3D_RS_WRAP6);
4937 D3DSTATE_TO_STR(WINED3D_RS_WRAP7);
4938 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING);
4939 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING);
4940 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS);
4941 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT);
4942 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE);
4943 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX);
4944 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER);
4945 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS);
4946 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE);
4947 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE);
4948 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE);
4949 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE);
4950 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE);
4951 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND);
4952 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE);
4953 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING);
4954 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE);
4955 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN);
4956 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE);
4957 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE);
4958 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A);
4959 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B);
4960 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C);
4961 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS);
4962 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK);
4963 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE);
4964 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS);
4965 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN);
4966 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX);
4967 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE);
4968 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE);
4969 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR);
4970 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP);
4971 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE);
4972 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE);
4973 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE);
4974 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS);
4975 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE);
4976 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL);
4977 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL);
4978 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X);
4979 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y);
4980 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z);
4981 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W);
4982 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION);
4983 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE);
4984 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFAIL);
4985 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILZFAIL);
4986 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILPASS);
4987 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFUNC);
4988 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1);
4989 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2);
4990 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3);
4991 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE);
4992 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS);
4993 D3DSTATE_TO_STR(WINED3D_RS_WRAP8);
4994 D3DSTATE_TO_STR(WINED3D_RS_WRAP9);
4995 D3DSTATE_TO_STR(WINED3D_RS_WRAP10);
4996 D3DSTATE_TO_STR(WINED3D_RS_WRAP11);
4997 D3DSTATE_TO_STR(WINED3D_RS_WRAP12);
4998 D3DSTATE_TO_STR(WINED3D_RS_WRAP13);
4999 D3DSTATE_TO_STR(WINED3D_RS_WRAP14);
5000 D3DSTATE_TO_STR(WINED3D_RS_WRAP15);
5001 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE);
5002 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA);
5003 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA);
5004 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA);
5005 #undef D3DSTATE_TO_STR
5006 default:
5007 FIXME("Unrecognized %u render state!\n", state);
5008 return "unrecognized";
5012 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state)
5014 switch (state)
5016 #define D3DSTATE_TO_STR(u) case u: return #u
5017 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR);
5018 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U);
5019 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V);
5020 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W);
5021 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER);
5022 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER);
5023 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER);
5024 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS);
5025 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL);
5026 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY);
5027 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE);
5028 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX);
5029 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET);
5030 #undef D3DSTATE_TO_STR
5031 default:
5032 FIXME("Unrecognized %u sampler state!\n", state);
5033 return "unrecognized";
5037 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type)
5039 switch (filter_type)
5041 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
5042 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE);
5043 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT);
5044 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR);
5045 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC);
5046 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC);
5047 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC);
5048 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD);
5049 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD);
5050 #undef D3DTEXTUREFILTERTYPE_TO_STR
5051 default:
5052 FIXME("Unrecognized texture filter type 0x%08x.\n", filter_type);
5053 return "unrecognized";
5057 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state)
5059 switch (state)
5061 #define D3DSTATE_TO_STR(u) case u: return #u
5062 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP);
5063 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1);
5064 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2);
5065 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP);
5066 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1);
5067 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2);
5068 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00);
5069 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01);
5070 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10);
5071 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11);
5072 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX);
5073 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE);
5074 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET);
5075 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS);
5076 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0);
5077 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0);
5078 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG);
5079 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT);
5080 #undef D3DSTATE_TO_STR
5081 default:
5082 FIXME("Unrecognized %u texture state!\n", state);
5083 return "unrecognized";
5087 const char *debug_d3dtop(enum wined3d_texture_op d3dtop)
5089 switch (d3dtop)
5091 #define D3DTOP_TO_STR(u) case u: return #u
5092 D3DTOP_TO_STR(WINED3D_TOP_DISABLE);
5093 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1);
5094 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2);
5095 D3DTOP_TO_STR(WINED3D_TOP_MODULATE);
5096 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X);
5097 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X);
5098 D3DTOP_TO_STR(WINED3D_TOP_ADD);
5099 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED);
5100 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X);
5101 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT);
5102 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH);
5103 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA);
5104 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA);
5105 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA);
5106 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM);
5107 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA);
5108 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE);
5109 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR);
5110 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA);
5111 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR);
5112 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA);
5113 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP);
5114 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE);
5115 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3);
5116 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD);
5117 D3DTOP_TO_STR(WINED3D_TOP_LERP);
5118 #undef D3DTOP_TO_STR
5119 default:
5120 FIXME("Unrecognized texture op %#x.\n", d3dtop);
5121 return "unrecognized";
5125 const char *debug_d3dtstype(enum wined3d_transform_state tstype)
5127 switch (tstype)
5129 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
5130 TSTYPE_TO_STR(WINED3D_TS_VIEW);
5131 TSTYPE_TO_STR(WINED3D_TS_PROJECTION);
5132 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0);
5133 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1);
5134 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2);
5135 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3);
5136 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4);
5137 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5);
5138 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6);
5139 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7);
5140 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
5141 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(1));
5142 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(2));
5143 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(3));
5144 #undef TSTYPE_TO_STR
5145 default:
5146 if (tstype > 256 && tstype < 512)
5148 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype);
5149 return ("WINED3D_TS_WORLD_MATRIX > 0");
5151 FIXME("Unrecognized transform state %#x.\n", tstype);
5152 return "unrecognized";
5156 const char *debug_shader_type(enum wined3d_shader_type type)
5158 switch(type)
5160 #define WINED3D_TO_STR(type) case type: return #type
5161 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL);
5162 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX);
5163 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY);
5164 WINED3D_TO_STR(WINED3D_SHADER_TYPE_HULL);
5165 WINED3D_TO_STR(WINED3D_SHADER_TYPE_DOMAIN);
5166 WINED3D_TO_STR(WINED3D_SHADER_TYPE_COMPUTE);
5167 #undef WINED3D_TO_STR
5168 default:
5169 FIXME("Unrecognized shader type %#x.\n", type);
5170 return "unrecognized";
5174 const char *debug_d3dstate(DWORD state)
5176 if (STATE_IS_RENDER(state))
5177 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state - STATE_RENDER(0)));
5178 if (STATE_IS_TEXTURESTAGE(state))
5180 DWORD texture_stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
5181 DWORD texture_state = state - STATE_TEXTURESTAGE(texture_stage, 0);
5182 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
5183 texture_stage, debug_d3dtexturestate(texture_state));
5185 if (STATE_IS_SAMPLER(state))
5186 return wine_dbg_sprintf("STATE_SAMPLER(%#x)", state - STATE_SAMPLER(0));
5187 if (STATE_IS_COMPUTE_SHADER(state))
5188 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE));
5189 if (STATE_IS_GRAPHICS_SHADER(state))
5190 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state - STATE_SHADER(0)));
5191 if (STATE_IS_COMPUTE_CONSTANT_BUFFER(state))
5192 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE));
5193 if (STATE_IS_GRAPHICS_CONSTANT_BUFFER(state))
5194 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state - STATE_CONSTANT_BUFFER(0)));
5195 if (STATE_IS_COMPUTE_SHADER_RESOURCE_BINDING(state))
5196 return "STATE_COMPUTE_SHADER_RESOURCE_BINDING";
5197 if (STATE_IS_GRAPHICS_SHADER_RESOURCE_BINDING(state))
5198 return "STATE_GRAPHICS_SHADER_RESOURCE_BINDING";
5199 if (STATE_IS_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING(state))
5200 return "STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING";
5201 if (STATE_IS_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING(state))
5202 return "STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING";
5203 if (STATE_IS_TRANSFORM(state))
5204 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state - STATE_TRANSFORM(0)));
5205 if (STATE_IS_STREAMSRC(state))
5206 return "STATE_STREAMSRC";
5207 if (STATE_IS_INDEXBUFFER(state))
5208 return "STATE_INDEXBUFFER";
5209 if (STATE_IS_VDECL(state))
5210 return "STATE_VDECL";
5211 if (STATE_IS_VIEWPORT(state))
5212 return "STATE_VIEWPORT";
5213 if (STATE_IS_LIGHT_TYPE(state))
5214 return "STATE_LIGHT_TYPE";
5215 if (STATE_IS_ACTIVELIGHT(state))
5216 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state - STATE_ACTIVELIGHT(0));
5217 if (STATE_IS_SCISSORRECT(state))
5218 return "STATE_SCISSORRECT";
5219 if (STATE_IS_CLIPPLANE(state))
5220 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state - STATE_CLIPPLANE(0));
5221 if (STATE_IS_MATERIAL(state))
5222 return "STATE_MATERIAL";
5223 if (STATE_IS_RASTERIZER(state))
5224 return "STATE_RASTERIZER";
5225 if (STATE_IS_POINTSPRITECOORDORIGIN(state))
5226 return "STATE_POINTSPRITECOORDORIGIN";
5227 if (STATE_IS_BASEVERTEXINDEX(state))
5228 return "STATE_BASEVERTEXINDEX";
5229 if (STATE_IS_FRAMEBUFFER(state))
5230 return "STATE_FRAMEBUFFER";
5231 if (STATE_IS_POINT_ENABLE(state))
5232 return "STATE_POINT_ENABLE";
5233 if (STATE_IS_COLOR_KEY(state))
5234 return "STATE_COLOR_KEY";
5235 if (STATE_IS_STREAM_OUTPUT(state))
5236 return "STATE_STREAM_OUTPUT";
5237 if (STATE_IS_BLEND(state))
5238 return "STATE_BLEND";
5239 if (STATE_IS_BLEND_FACTOR(state))
5240 return "STATE_BLEND_FACTOR";
5241 if (STATE_IS_SAMPLE_MASK(state))
5242 return "STATE_SAMPLE_MASK";
5243 if (STATE_IS_DEPTH_STENCIL(state))
5244 return "STATE_DEPTH_STENCIL";
5245 if (STATE_IS_STENCIL_REF(state))
5246 return "STATE_STENCIL_REF";
5248 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state);
5251 const char *debug_fboattachment(GLenum attachment)
5253 switch(attachment)
5255 #define WINED3D_TO_STR(x) case x: return #x
5256 WINED3D_TO_STR(GL_COLOR_ATTACHMENT0);
5257 WINED3D_TO_STR(GL_COLOR_ATTACHMENT1);
5258 WINED3D_TO_STR(GL_COLOR_ATTACHMENT2);
5259 WINED3D_TO_STR(GL_COLOR_ATTACHMENT3);
5260 WINED3D_TO_STR(GL_COLOR_ATTACHMENT4);
5261 WINED3D_TO_STR(GL_COLOR_ATTACHMENT5);
5262 WINED3D_TO_STR(GL_COLOR_ATTACHMENT6);
5263 WINED3D_TO_STR(GL_COLOR_ATTACHMENT7);
5264 WINED3D_TO_STR(GL_COLOR_ATTACHMENT8);
5265 WINED3D_TO_STR(GL_COLOR_ATTACHMENT9);
5266 WINED3D_TO_STR(GL_COLOR_ATTACHMENT10);
5267 WINED3D_TO_STR(GL_COLOR_ATTACHMENT11);
5268 WINED3D_TO_STR(GL_COLOR_ATTACHMENT12);
5269 WINED3D_TO_STR(GL_COLOR_ATTACHMENT13);
5270 WINED3D_TO_STR(GL_COLOR_ATTACHMENT14);
5271 WINED3D_TO_STR(GL_COLOR_ATTACHMENT15);
5272 WINED3D_TO_STR(GL_DEPTH_ATTACHMENT);
5273 WINED3D_TO_STR(GL_STENCIL_ATTACHMENT);
5274 #undef WINED3D_TO_STR
5275 default:
5276 return wine_dbg_sprintf("Unknown FBO attachment %#x", attachment);
5280 const char *debug_fbostatus(GLenum status) {
5281 switch(status) {
5282 #define FBOSTATUS_TO_STR(u) case u: return #u
5283 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE);
5284 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
5285 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT);
5286 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT);
5287 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT);
5288 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER);
5289 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER);
5290 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE);
5291 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS);
5292 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB);
5293 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED);
5294 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED);
5295 #undef FBOSTATUS_TO_STR
5296 default:
5297 FIXME("Unrecognized FBO status 0x%08x.\n", status);
5298 return "unrecognized";
5302 const char *debug_glerror(GLenum error) {
5303 switch(error) {
5304 #define GLERROR_TO_STR(u) case u: return #u
5305 GLERROR_TO_STR(GL_NO_ERROR);
5306 GLERROR_TO_STR(GL_INVALID_ENUM);
5307 GLERROR_TO_STR(GL_INVALID_VALUE);
5308 GLERROR_TO_STR(GL_INVALID_OPERATION);
5309 GLERROR_TO_STR(GL_STACK_OVERFLOW);
5310 GLERROR_TO_STR(GL_STACK_UNDERFLOW);
5311 GLERROR_TO_STR(GL_OUT_OF_MEMORY);
5312 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION);
5313 #undef GLERROR_TO_STR
5314 default:
5315 FIXME("Unrecognized GL error 0x%08x.\n", error);
5316 return "unrecognized";
5320 const char *wined3d_debug_vkresult(VkResult vr)
5322 switch (vr)
5324 #define WINED3D_TO_STR(x) case x: return #x
5325 WINED3D_TO_STR(VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR);
5326 WINED3D_TO_STR(VK_ERROR_NOT_PERMITTED_EXT);
5327 WINED3D_TO_STR(VK_ERROR_FRAGMENTATION_EXT);
5328 WINED3D_TO_STR(VK_ERROR_INVALID_EXTERNAL_HANDLE);
5329 WINED3D_TO_STR(VK_ERROR_OUT_OF_POOL_MEMORY);
5330 WINED3D_TO_STR(VK_ERROR_INVALID_SHADER_NV);
5331 WINED3D_TO_STR(VK_ERROR_OUT_OF_DATE_KHR);
5332 WINED3D_TO_STR(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR);
5333 WINED3D_TO_STR(VK_ERROR_SURFACE_LOST_KHR);
5334 WINED3D_TO_STR(VK_ERROR_FRAGMENTED_POOL);
5335 WINED3D_TO_STR(VK_ERROR_FORMAT_NOT_SUPPORTED);
5336 WINED3D_TO_STR(VK_ERROR_TOO_MANY_OBJECTS);
5337 WINED3D_TO_STR(VK_ERROR_INCOMPATIBLE_DRIVER);
5338 WINED3D_TO_STR(VK_ERROR_FEATURE_NOT_PRESENT);
5339 WINED3D_TO_STR(VK_ERROR_EXTENSION_NOT_PRESENT);
5340 WINED3D_TO_STR(VK_ERROR_LAYER_NOT_PRESENT);
5341 WINED3D_TO_STR(VK_ERROR_MEMORY_MAP_FAILED);
5342 WINED3D_TO_STR(VK_ERROR_DEVICE_LOST);
5343 WINED3D_TO_STR(VK_ERROR_INITIALIZATION_FAILED);
5344 WINED3D_TO_STR(VK_ERROR_OUT_OF_DEVICE_MEMORY);
5345 WINED3D_TO_STR(VK_ERROR_OUT_OF_HOST_MEMORY);
5346 WINED3D_TO_STR(VK_SUCCESS);
5347 WINED3D_TO_STR(VK_NOT_READY);
5348 WINED3D_TO_STR(VK_TIMEOUT);
5349 WINED3D_TO_STR(VK_EVENT_SET);
5350 WINED3D_TO_STR(VK_EVENT_RESET);
5351 WINED3D_TO_STR(VK_INCOMPLETE);
5352 WINED3D_TO_STR(VK_SUBOPTIMAL_KHR);
5353 #undef WINED3D_TO_STR
5354 default:
5355 return wine_dbg_sprintf("unrecognised(%d)", vr);
5359 static const char *debug_fixup_channel_source(enum fixup_channel_source source)
5361 switch(source)
5363 #define WINED3D_TO_STR(x) case x: return #x
5364 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO);
5365 WINED3D_TO_STR(CHANNEL_SOURCE_ONE);
5366 WINED3D_TO_STR(CHANNEL_SOURCE_X);
5367 WINED3D_TO_STR(CHANNEL_SOURCE_Y);
5368 WINED3D_TO_STR(CHANNEL_SOURCE_Z);
5369 WINED3D_TO_STR(CHANNEL_SOURCE_W);
5370 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0);
5371 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1);
5372 #undef WINED3D_TO_STR
5373 default:
5374 FIXME("Unrecognized fixup_channel_source %#x\n", source);
5375 return "unrecognized";
5379 static const char *debug_complex_fixup(enum complex_fixup fixup)
5381 switch(fixup)
5383 #define WINED3D_TO_STR(x) case x: return #x
5384 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2);
5385 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY);
5386 WINED3D_TO_STR(COMPLEX_FIXUP_YV12);
5387 WINED3D_TO_STR(COMPLEX_FIXUP_NV12);
5388 WINED3D_TO_STR(COMPLEX_FIXUP_P8);
5389 WINED3D_TO_STR(COMPLEX_FIXUP_YUV);
5390 #undef WINED3D_TO_STR
5391 default:
5392 FIXME("Unrecognized complex fixup %#x\n", fixup);
5393 return "unrecognized";
5397 void dump_color_fixup_desc(struct color_fixup_desc fixup)
5399 if (is_complex_fixup(fixup))
5401 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup)));
5402 return;
5405 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup.x_source), fixup.x_sign_fixup ? ", SIGN_FIXUP" : "");
5406 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup.y_source), fixup.y_sign_fixup ? ", SIGN_FIXUP" : "");
5407 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup.z_source), fixup.z_sign_fixup ? ", SIGN_FIXUP" : "");
5408 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup.w_source), fixup.w_sign_fixup ? ", SIGN_FIXUP" : "");
5411 BOOL is_invalid_op(const struct wined3d_state *state, int stage,
5412 enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3)
5414 if (op == WINED3D_TOP_DISABLE)
5415 return FALSE;
5416 if (state->textures[stage])
5417 return FALSE;
5419 if ((arg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
5420 && op != WINED3D_TOP_SELECT_ARG2)
5421 return TRUE;
5422 if ((arg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
5423 && op != WINED3D_TOP_SELECT_ARG1)
5424 return TRUE;
5425 if ((arg3 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
5426 && (op == WINED3D_TOP_MULTIPLY_ADD || op == WINED3D_TOP_LERP))
5427 return TRUE;
5429 return FALSE;
5432 void get_identity_matrix(struct wined3d_matrix *mat)
5434 static const struct wined3d_matrix identity =
5436 1.0f, 0.0f, 0.0f, 0.0f,
5437 0.0f, 1.0f, 0.0f, 0.0f,
5438 0.0f, 0.0f, 1.0f, 0.0f,
5439 0.0f, 0.0f, 0.0f, 1.0f,
5442 *mat = identity;
5445 void get_modelview_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
5446 unsigned int index, struct wined3d_matrix *mat)
5448 if (context->last_was_rhw)
5449 get_identity_matrix(mat);
5450 else
5451 multiply_matrix(mat, &state->transforms[WINED3D_TS_VIEW], &state->transforms[WINED3D_TS_WORLD_MATRIX(index)]);
5454 void get_projection_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
5455 struct wined3d_matrix *mat)
5457 const struct wined3d_d3d_info *d3d_info = context->d3d_info;
5458 BOOL clip_control, flip;
5459 float center_offset;
5461 /* There are a couple of additional things we have to take into account
5462 * here besides the projection transformation itself:
5463 * - We need to flip along the y-axis in case of offscreen rendering.
5464 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
5465 * - <= D3D9 coordinates refer to pixel centers while GL coordinates
5466 * refer to pixel corners.
5467 * - D3D has a top-left filling convention. We need to maintain this
5468 * even after the y-flip mentioned above.
5469 * In order to handle the last two points, we translate by
5470 * (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to
5471 * translating slightly less than half a pixel. We want the difference to
5472 * be large enough that it doesn't get lost due to rounding inside the
5473 * driver, but small enough to prevent it from interfering with any
5474 * anti-aliasing. */
5476 clip_control = d3d_info->clip_control;
5477 flip = !clip_control && context->render_offscreen;
5478 if (!clip_control && d3d_info->wined3d_creation_flags & WINED3D_PIXEL_CENTER_INTEGER)
5479 center_offset = 63.0f / 64.0f;
5480 else
5481 center_offset = -1.0f / 64.0f;
5483 if (context->last_was_rhw)
5485 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
5486 float x = state->viewports[0].x;
5487 float y = state->viewports[0].y;
5488 float w = state->viewports[0].width;
5489 float h = state->viewports[0].height;
5490 float x_scale = 2.0f / w;
5491 float x_offset = (center_offset - (2.0f * x) - w) / w;
5492 float y_scale = flip ? 2.0f / h : 2.0f / -h;
5493 float y_offset = flip
5494 ? (center_offset - (2.0f * y) - h) / h
5495 : (center_offset - (2.0f * y) - h) / -h;
5496 bool zenable = state->fb.depth_stencil ?
5497 (state->depth_stencil_state ? state->depth_stencil_state->desc.depth : true) : false;
5498 float z_scale = zenable ? clip_control ? 1.0f : 2.0f : 0.0f;
5499 float z_offset = zenable ? clip_control ? 0.0f : -1.0f : 0.0f;
5500 const struct wined3d_matrix projection =
5502 x_scale, 0.0f, 0.0f, 0.0f,
5503 0.0f, y_scale, 0.0f, 0.0f,
5504 0.0f, 0.0f, z_scale, 0.0f,
5505 x_offset, y_offset, z_offset, 1.0f,
5508 *mat = projection;
5510 else
5512 float y_scale = flip ? -1.0f : 1.0f;
5513 float x_offset = center_offset / state->viewports[0].width;
5514 float y_offset = flip
5515 ? center_offset / state->viewports[0].height
5516 : -center_offset / state->viewports[0].height;
5517 float z_scale = clip_control ? 1.0f : 2.0f;
5518 float z_offset = clip_control ? 0.0f : -1.0f;
5519 const struct wined3d_matrix projection =
5521 1.0f, 0.0f, 0.0f, 0.0f,
5522 0.0f, y_scale, 0.0f, 0.0f,
5523 0.0f, 0.0f, z_scale, 0.0f,
5524 x_offset, y_offset, z_offset, 1.0f,
5527 multiply_matrix(mat, &projection, &state->transforms[WINED3D_TS_PROJECTION]);
5531 /* Setup this textures matrix according to the texture flags. */
5532 static void compute_texture_matrix(const struct wined3d_matrix *matrix, uint32_t flags, BOOL calculated_coords,
5533 BOOL transformed, enum wined3d_format_id format_id, BOOL ffp_proj_control, struct wined3d_matrix *out_matrix)
5535 struct wined3d_matrix mat;
5537 if (flags == WINED3D_TTFF_DISABLE || flags == WINED3D_TTFF_COUNT1 || transformed)
5539 get_identity_matrix(out_matrix);
5540 return;
5543 if (flags == (WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED))
5545 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
5546 return;
5549 mat = *matrix;
5551 if (flags & WINED3D_TTFF_PROJECTED)
5553 if (!ffp_proj_control)
5555 switch (flags & ~WINED3D_TTFF_PROJECTED)
5557 case WINED3D_TTFF_COUNT2:
5558 mat._14 = mat._12;
5559 mat._24 = mat._22;
5560 mat._34 = mat._32;
5561 mat._44 = mat._42;
5562 mat._12 = mat._22 = mat._32 = mat._42 = 0.0f;
5563 break;
5564 case WINED3D_TTFF_COUNT3:
5565 mat._14 = mat._13;
5566 mat._24 = mat._23;
5567 mat._34 = mat._33;
5568 mat._44 = mat._43;
5569 mat._13 = mat._23 = mat._33 = mat._43 = 0.0f;
5570 break;
5574 else
5576 /* Under Direct3D the R/Z coord can be used for translation, under
5577 * OpenGL we use the Q coord instead. */
5578 if (!calculated_coords)
5580 switch (format_id)
5582 /* Direct3D passes the default 1.0 in the 2nd coord, while GL
5583 * passes it in the 4th. Swap 2nd and 4th coord. No need to
5584 * store the value of mat._41 in mat._21 because the input
5585 * value to the transformation will be 0, so the matrix value
5586 * is irrelevant. */
5587 case WINED3DFMT_R32_FLOAT:
5588 mat._41 = mat._21;
5589 mat._42 = mat._22;
5590 mat._43 = mat._23;
5591 mat._44 = mat._24;
5592 break;
5593 /* See above, just 3rd and 4th coord. */
5594 case WINED3DFMT_R32G32_FLOAT:
5595 mat._41 = mat._31;
5596 mat._42 = mat._32;
5597 mat._43 = mat._33;
5598 mat._44 = mat._34;
5599 break;
5600 case WINED3DFMT_R32G32B32_FLOAT: /* Opengl defaults match dx defaults */
5601 case WINED3DFMT_R32G32B32A32_FLOAT: /* No defaults apply, all app defined */
5603 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
5604 * into a bad place. The division elimination below will apply to make sure the
5605 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
5607 case WINED3DFMT_UNKNOWN: /* No texture coords, 0/0/0/1 defaults are passed */
5608 break;
5609 default:
5610 FIXME("Unexpected fixed function texture coord input\n");
5613 if (!ffp_proj_control)
5615 switch (flags & ~WINED3D_TTFF_PROJECTED)
5617 /* case WINED3D_TTFF_COUNT1: Won't ever get here. */
5618 case WINED3D_TTFF_COUNT2:
5619 mat._13 = mat._23 = mat._33 = mat._43 = 0.0f;
5620 /* OpenGL divides the first 3 vertex coordinates by the 4th by
5621 * default, which is essentially the same as D3DTTFF_PROJECTED.
5622 * Make sure that the 4th coordinate evaluates to 1.0 to
5623 * eliminate that.
5625 * If the fixed function pipeline is used, the 4th value
5626 * remains unused, so there is no danger in doing this. With
5627 * vertex shaders we have a problem. Should an application hit
5628 * that problem, the code here would have to check for pixel
5629 * shaders, and the shader has to undo the default GL divide.
5631 * A more serious problem occurs if the application passes 4
5632 * coordinates in, and the 4th is != 1.0 (OpenGL default).
5633 * This would have to be fixed with immediate mode draws. */
5634 default:
5635 mat._14 = mat._24 = mat._34 = 0.0f; mat._44 = 1.0f;
5640 *out_matrix = mat;
5643 void get_texture_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
5644 unsigned int tex, struct wined3d_matrix *mat)
5646 const struct wined3d_device *device = context->device;
5647 BOOL generated = (state->texture_states[tex][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000)
5648 != WINED3DTSS_TCI_PASSTHRU;
5649 unsigned int coord_idx = min(state->texture_states[tex][WINED3D_TSS_TEXCOORD_INDEX & 0x0000ffff],
5650 WINED3D_MAX_TEXTURES - 1);
5652 compute_texture_matrix(&state->transforms[WINED3D_TS_TEXTURE0 + tex],
5653 state->texture_states[tex][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS],
5654 generated, context->last_was_rhw,
5655 context->stream_info.use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coord_idx))
5656 ? context->stream_info.elements[WINED3D_FFP_TEXCOORD0 + coord_idx].format->id
5657 : WINED3DFMT_UNKNOWN,
5658 device->shader_backend->shader_has_ffp_proj_control(device->shader_priv), mat);
5660 if ((context->lastWasPow2Texture & (1u << tex)) && state->textures[tex])
5662 if (generated)
5663 FIXME("Non-power-of-two texture being used with generated texture coords.\n");
5664 /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
5665 * fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
5666 if (!use_ps(state))
5668 TRACE("Non-power-of-two texture matrix multiply fixup.\n");
5669 multiply_matrix(mat, mat, (struct wined3d_matrix *)state->textures[tex]->pow2_matrix);
5674 void get_pointsize_minmax(const struct wined3d_context *context, const struct wined3d_state *state,
5675 float *out_min, float *out_max)
5677 union
5679 DWORD d;
5680 float f;
5681 } min, max;
5683 min.d = state->render_states[WINED3D_RS_POINTSIZE_MIN];
5684 max.d = state->render_states[WINED3D_RS_POINTSIZE_MAX];
5686 if (min.f > max.f)
5687 min.f = max.f;
5689 *out_min = min.f;
5690 *out_max = max.f;
5693 void get_pointsize(const struct wined3d_context *context, const struct wined3d_state *state,
5694 float *out_pointsize, float *out_att)
5696 /* POINTSCALEENABLE controls how point size value is treated. If set to
5697 * true, the point size is scaled with respect to height of viewport.
5698 * When set to false point size is in pixels. */
5699 union
5701 DWORD d;
5702 float f;
5703 } pointsize, a, b, c;
5705 out_att[0] = 1.0f;
5706 out_att[1] = 0.0f;
5707 out_att[2] = 0.0f;
5709 pointsize.d = state->render_states[WINED3D_RS_POINTSIZE];
5710 a.d = state->render_states[WINED3D_RS_POINTSCALE_A];
5711 b.d = state->render_states[WINED3D_RS_POINTSCALE_B];
5712 c.d = state->render_states[WINED3D_RS_POINTSCALE_C];
5714 /* Always use first viewport, this path does not apply to d3d10/11 multiple viewports case. */
5715 if (state->render_states[WINED3D_RS_POINTSCALEENABLE])
5717 float scale_factor = state->viewports[0].height * state->viewports[0].height;
5719 out_att[0] = a.f / scale_factor;
5720 out_att[1] = b.f / scale_factor;
5721 out_att[2] = c.f / scale_factor;
5723 *out_pointsize = pointsize.f;
5726 void get_fog_start_end(const struct wined3d_context *context, const struct wined3d_state *state,
5727 float *start, float *end)
5729 union
5731 DWORD d;
5732 float f;
5733 } tmpvalue;
5735 switch (context->fog_source)
5737 case FOGSOURCE_VS:
5738 *start = 1.0f;
5739 *end = 0.0f;
5740 break;
5742 case FOGSOURCE_COORD:
5743 *start = 255.0f;
5744 *end = 0.0f;
5745 break;
5747 case FOGSOURCE_FFP:
5748 tmpvalue.d = state->render_states[WINED3D_RS_FOGSTART];
5749 *start = tmpvalue.f;
5750 tmpvalue.d = state->render_states[WINED3D_RS_FOGEND];
5751 *end = tmpvalue.f;
5752 /* Special handling for fog_start == fog_end. In d3d with vertex
5753 * fog, everything is fogged. With table fog, everything with
5754 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
5755 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
5756 if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE && *start == *end)
5758 *start = -INFINITY;
5759 *end = 0.0f;
5761 break;
5763 default:
5764 /* This should not happen, context->fog_source is set in wined3d, not the app. */
5765 ERR("Unexpected fog coordinate source.\n");
5766 *start = 0.0f;
5767 *end = 0.0f;
5771 static BOOL wined3d_get_primary_display(WCHAR *display)
5773 DISPLAY_DEVICEW display_device;
5774 DWORD device_idx = 0;
5776 display_device.cb = sizeof(display_device);
5777 while (EnumDisplayDevicesW(NULL, device_idx++, &display_device, 0))
5779 if (display_device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
5781 lstrcpyW(display, display_device.DeviceName);
5782 return TRUE;
5786 return FALSE;
5789 BOOL wined3d_get_primary_adapter_luid(LUID *luid)
5791 D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME open_adapter_param;
5792 D3DKMT_CLOSEADAPTER close_adapter_param;
5794 if (!wined3d_get_primary_display(open_adapter_param.DeviceName))
5795 return FALSE;
5797 if (D3DKMTOpenAdapterFromGdiDisplayName(&open_adapter_param))
5798 return FALSE;
5800 *luid = open_adapter_param.AdapterLuid;
5801 close_adapter_param.hAdapter = open_adapter_param.hAdapter;
5802 D3DKMTCloseAdapter(&close_adapter_param);
5803 return TRUE;
5806 /* Note: It's the caller's responsibility to ensure values can be expressed
5807 * in the requested format. UNORM formats for example can only express values
5808 * in the range 0.0f -> 1.0f. */
5809 DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, const struct wined3d_color *color)
5811 static const struct
5813 enum wined3d_format_id format_id;
5814 struct wined3d_vec4 mul;
5815 struct wined3d_uvec4 shift;
5817 float_conv[] =
5819 {WINED3DFMT_B8G8R8A8_UNORM, { 255.0f, 255.0f, 255.0f, 255.0f}, {16, 8, 0, 24}},
5820 {WINED3DFMT_B8G8R8X8_UNORM, { 255.0f, 255.0f, 255.0f, 255.0f}, {16, 8, 0, 24}},
5821 {WINED3DFMT_B8G8R8_UNORM, { 255.0f, 255.0f, 255.0f, 255.0f}, {16, 8, 0, 24}},
5822 {WINED3DFMT_B5G6R5_UNORM, { 31.0f, 63.0f, 31.0f, 0.0f}, {11, 5, 0, 0}},
5823 {WINED3DFMT_B5G5R5A1_UNORM, { 31.0f, 31.0f, 31.0f, 1.0f}, {10, 5, 0, 15}},
5824 {WINED3DFMT_B5G5R5X1_UNORM, { 31.0f, 31.0f, 31.0f, 1.0f}, {10, 5, 0, 15}},
5825 {WINED3DFMT_R8_UNORM, { 255.0f, 0.0f, 0.0f, 0.0f}, { 0, 0, 0, 0}},
5826 {WINED3DFMT_A8_UNORM, { 0.0f, 0.0f, 0.0f, 255.0f}, { 0, 0, 0, 0}},
5827 {WINED3DFMT_B4G4R4A4_UNORM, { 15.0f, 15.0f, 15.0f, 15.0f}, { 8, 4, 0, 12}},
5828 {WINED3DFMT_B4G4R4X4_UNORM, { 15.0f, 15.0f, 15.0f, 15.0f}, { 8, 4, 0, 12}},
5829 {WINED3DFMT_B2G3R3_UNORM, { 7.0f, 7.0f, 3.0f, 0.0f}, { 5, 2, 0, 0}},
5830 {WINED3DFMT_R8G8B8A8_UNORM, { 255.0f, 255.0f, 255.0f, 255.0f}, { 0, 8, 16, 24}},
5831 {WINED3DFMT_R8G8B8X8_UNORM, { 255.0f, 255.0f, 255.0f, 255.0f}, { 0, 8, 16, 24}},
5832 {WINED3DFMT_B10G10R10A2_UNORM, { 1023.0f, 1023.0f, 1023.0f, 3.0f}, {20, 10, 0, 30}},
5833 {WINED3DFMT_R10G10B10A2_UNORM, { 1023.0f, 1023.0f, 1023.0f, 3.0f}, { 0, 10, 20, 30}},
5834 {WINED3DFMT_P8_UINT, { 0.0f, 0.0f, 0.0f, 255.0f}, { 0, 0, 0, 0}},
5835 {WINED3DFMT_S1_UINT_D15_UNORM, { 32767.0f, 0.0f, 0.0f, 0.0f}, { 0, 0, 0, 0}},
5836 {WINED3DFMT_D16_UNORM, { 65535.0f, 0.0f, 0.0f, 0.0f}, { 0, 0, 0, 0}},
5838 static const struct
5840 enum wined3d_format_id format_id;
5841 struct wined3d_dvec4 mul;
5842 struct wined3d_uvec4 shift;
5844 double_conv[] =
5846 {WINED3DFMT_D24_UNORM_S8_UINT, { 16777215.0, 1.0, 0.0, 0.0}, {8, 0, 0, 0}},
5847 {WINED3DFMT_X8D24_UNORM, { 16777215.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
5848 {WINED3DFMT_D32_UNORM, {4294967295.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
5850 enum wined3d_format_id format_id = format->id;
5851 struct wined3d_color colour_srgb;
5852 unsigned int i;
5853 DWORD ret;
5855 TRACE("Converting colour %s to format %s.\n", debug_color(color), debug_d3dformat(format_id));
5857 for (i = 0; i < ARRAY_SIZE(format_srgb_info); ++i)
5859 if (format_id != format_srgb_info[i].srgb_format_id)
5860 continue;
5862 wined3d_colour_srgb_from_linear(&colour_srgb, color);
5863 format_id = format_srgb_info[i].base_format_id;
5864 color = &colour_srgb;
5865 break;
5868 for (i = 0; i < ARRAY_SIZE(float_conv); ++i)
5870 if (format_id != float_conv[i].format_id)
5871 continue;
5873 ret = ((DWORD)((color->r * float_conv[i].mul.x) + 0.5f)) << float_conv[i].shift.x;
5874 ret |= ((DWORD)((color->g * float_conv[i].mul.y) + 0.5f)) << float_conv[i].shift.y;
5875 ret |= ((DWORD)((color->b * float_conv[i].mul.z) + 0.5f)) << float_conv[i].shift.z;
5876 ret |= ((DWORD)((color->a * float_conv[i].mul.w) + 0.5f)) << float_conv[i].shift.w;
5878 TRACE("Returning 0x%08x.\n", ret);
5880 return ret;
5883 for (i = 0; i < ARRAY_SIZE(double_conv); ++i)
5885 if (format_id != double_conv[i].format_id)
5886 continue;
5888 ret = ((DWORD)((color->r * double_conv[i].mul.x) + 0.5)) << double_conv[i].shift.x;
5889 ret |= ((DWORD)((color->g * double_conv[i].mul.y) + 0.5)) << double_conv[i].shift.y;
5890 ret |= ((DWORD)((color->b * double_conv[i].mul.z) + 0.5)) << double_conv[i].shift.z;
5891 ret |= ((DWORD)((color->a * double_conv[i].mul.w) + 0.5)) << double_conv[i].shift.w;
5893 TRACE("Returning 0x%08x.\n", ret);
5895 return ret;
5898 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format_id));
5900 return 0;
5903 static float color_to_float(DWORD color, DWORD size, DWORD offset)
5905 DWORD mask = size < 32 ? (1u << size) - 1 : ~0u;
5907 if (!size)
5908 return 1.0f;
5910 color >>= offset;
5911 color &= mask;
5913 return (float)color / (float)mask;
5916 void wined3d_format_get_float_color_key(const struct wined3d_format *format,
5917 const struct wined3d_color_key *key, struct wined3d_color *float_colors)
5919 struct wined3d_color slop;
5921 switch (format->id)
5923 case WINED3DFMT_B8G8R8_UNORM:
5924 case WINED3DFMT_B8G8R8A8_UNORM:
5925 case WINED3DFMT_B8G8R8X8_UNORM:
5926 case WINED3DFMT_B5G6R5_UNORM:
5927 case WINED3DFMT_B5G5R5X1_UNORM:
5928 case WINED3DFMT_B5G5R5A1_UNORM:
5929 case WINED3DFMT_B4G4R4A4_UNORM:
5930 case WINED3DFMT_B2G3R3_UNORM:
5931 case WINED3DFMT_R8_UNORM:
5932 case WINED3DFMT_A8_UNORM:
5933 case WINED3DFMT_B2G3R3A8_UNORM:
5934 case WINED3DFMT_B4G4R4X4_UNORM:
5935 case WINED3DFMT_R10G10B10A2_UNORM:
5936 case WINED3DFMT_R10G10B10A2_SNORM:
5937 case WINED3DFMT_R8G8B8A8_UNORM:
5938 case WINED3DFMT_R8G8B8X8_UNORM:
5939 case WINED3DFMT_R16G16_UNORM:
5940 case WINED3DFMT_B10G10R10A2_UNORM:
5941 slop.r = 0.5f / ((1u << format->red_size) - 1);
5942 slop.g = 0.5f / ((1u << format->green_size) - 1);
5943 slop.b = 0.5f / ((1u << format->blue_size) - 1);
5944 slop.a = 0.5f / ((1u << format->alpha_size) - 1);
5946 float_colors[0].r = color_to_float(key->color_space_low_value, format->red_size, format->red_offset)
5947 - slop.r;
5948 float_colors[0].g = color_to_float(key->color_space_low_value, format->green_size, format->green_offset)
5949 - slop.g;
5950 float_colors[0].b = color_to_float(key->color_space_low_value, format->blue_size, format->blue_offset)
5951 - slop.b;
5952 float_colors[0].a = color_to_float(key->color_space_low_value, format->alpha_size, format->alpha_offset)
5953 - slop.a;
5955 float_colors[1].r = color_to_float(key->color_space_high_value, format->red_size, format->red_offset)
5956 + slop.r;
5957 float_colors[1].g = color_to_float(key->color_space_high_value, format->green_size, format->green_offset)
5958 + slop.g;
5959 float_colors[1].b = color_to_float(key->color_space_high_value, format->blue_size, format->blue_offset)
5960 + slop.b;
5961 float_colors[1].a = color_to_float(key->color_space_high_value, format->alpha_size, format->alpha_offset)
5962 + slop.a;
5963 break;
5965 case WINED3DFMT_P8_UINT:
5966 float_colors[0].r = 0.0f;
5967 float_colors[0].g = 0.0f;
5968 float_colors[0].b = 0.0f;
5969 float_colors[0].a = (key->color_space_low_value - 0.5f) / 255.0f;
5971 float_colors[1].r = 0.0f;
5972 float_colors[1].g = 0.0f;
5973 float_colors[1].b = 0.0f;
5974 float_colors[1].a = (key->color_space_high_value + 0.5f) / 255.0f;
5975 break;
5977 default:
5978 ERR("Unhandled color key to float conversion for format %s.\n", debug_d3dformat(format->id));
5982 enum wined3d_format_id pixelformat_for_depth(DWORD depth)
5984 switch (depth)
5986 case 8: return WINED3DFMT_P8_UINT;
5987 case 15: return WINED3DFMT_B5G5R5X1_UNORM;
5988 case 16: return WINED3DFMT_B5G6R5_UNORM;
5989 case 24: return WINED3DFMT_B8G8R8X8_UNORM; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
5990 case 32: return WINED3DFMT_B8G8R8X8_UNORM; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
5991 default: return WINED3DFMT_UNKNOWN;
5995 void wined3d_format_copy_data(const struct wined3d_format *format, const uint8_t *src,
5996 unsigned int src_row_pitch, unsigned int src_slice_pitch, uint8_t *dst, unsigned int dst_row_pitch,
5997 unsigned int dst_slice_pitch, unsigned int w, unsigned int h, unsigned int d)
5999 unsigned int row_block_count, row_count, row_size, slice, row;
6000 unsigned int slice_count = d, slice_size;
6001 const uint8_t *src_row;
6002 uint8_t *dst_row;
6004 row_block_count = (w + format->block_width - 1) / format->block_width;
6005 row_count = (h + format->block_height - 1) / format->block_height;
6006 row_size = row_block_count * format->block_byte_count;
6007 slice_size = row_size * row_count;
6009 if (src_row_pitch == row_size && dst_row_pitch == row_size
6010 && ((src_slice_pitch == slice_size && dst_slice_pitch == slice_size) || slice_count == 1))
6012 memcpy(dst, src, slice_count * slice_size);
6013 return;
6016 for (slice = 0; slice < slice_count; ++slice)
6018 for (row = 0; row < row_count; ++row)
6020 src_row = &src[slice * src_slice_pitch + row * src_row_pitch];
6021 dst_row = &dst[slice * dst_slice_pitch + row * dst_row_pitch];
6022 memcpy(dst_row, src_row, row_size);
6027 void multiply_matrix(struct wined3d_matrix *dst, const struct wined3d_matrix *src1, const struct wined3d_matrix *src2)
6029 struct wined3d_matrix tmp;
6031 /* Now do the multiplication 'by hand'.
6032 I know that all this could be optimised, but this will be done later :-) */
6033 tmp._11 = (src1->_11 * src2->_11) + (src1->_21 * src2->_12) + (src1->_31 * src2->_13) + (src1->_41 * src2->_14);
6034 tmp._21 = (src1->_11 * src2->_21) + (src1->_21 * src2->_22) + (src1->_31 * src2->_23) + (src1->_41 * src2->_24);
6035 tmp._31 = (src1->_11 * src2->_31) + (src1->_21 * src2->_32) + (src1->_31 * src2->_33) + (src1->_41 * src2->_34);
6036 tmp._41 = (src1->_11 * src2->_41) + (src1->_21 * src2->_42) + (src1->_31 * src2->_43) + (src1->_41 * src2->_44);
6038 tmp._12 = (src1->_12 * src2->_11) + (src1->_22 * src2->_12) + (src1->_32 * src2->_13) + (src1->_42 * src2->_14);
6039 tmp._22 = (src1->_12 * src2->_21) + (src1->_22 * src2->_22) + (src1->_32 * src2->_23) + (src1->_42 * src2->_24);
6040 tmp._32 = (src1->_12 * src2->_31) + (src1->_22 * src2->_32) + (src1->_32 * src2->_33) + (src1->_42 * src2->_34);
6041 tmp._42 = (src1->_12 * src2->_41) + (src1->_22 * src2->_42) + (src1->_32 * src2->_43) + (src1->_42 * src2->_44);
6043 tmp._13 = (src1->_13 * src2->_11) + (src1->_23 * src2->_12) + (src1->_33 * src2->_13) + (src1->_43 * src2->_14);
6044 tmp._23 = (src1->_13 * src2->_21) + (src1->_23 * src2->_22) + (src1->_33 * src2->_23) + (src1->_43 * src2->_24);
6045 tmp._33 = (src1->_13 * src2->_31) + (src1->_23 * src2->_32) + (src1->_33 * src2->_33) + (src1->_43 * src2->_34);
6046 tmp._43 = (src1->_13 * src2->_41) + (src1->_23 * src2->_42) + (src1->_33 * src2->_43) + (src1->_43 * src2->_44);
6048 tmp._14 = (src1->_14 * src2->_11) + (src1->_24 * src2->_12) + (src1->_34 * src2->_13) + (src1->_44 * src2->_14);
6049 tmp._24 = (src1->_14 * src2->_21) + (src1->_24 * src2->_22) + (src1->_34 * src2->_23) + (src1->_44 * src2->_24);
6050 tmp._34 = (src1->_14 * src2->_31) + (src1->_24 * src2->_32) + (src1->_34 * src2->_33) + (src1->_44 * src2->_34);
6051 tmp._44 = (src1->_14 * src2->_41) + (src1->_24 * src2->_42) + (src1->_34 * src2->_43) + (src1->_44 * src2->_44);
6053 *dst = tmp;
6056 void gen_ffp_frag_op(const struct wined3d_context *context, const struct wined3d_state *state,
6057 struct ffp_frag_settings *settings, BOOL ignore_textype)
6059 #define ARG1 0x01
6060 #define ARG2 0x02
6061 #define ARG0 0x04
6062 static const unsigned char args[WINED3D_TOP_LERP + 1] =
6064 /* undefined */ 0,
6065 /* D3DTOP_DISABLE */ 0,
6066 /* D3DTOP_SELECTARG1 */ ARG1,
6067 /* D3DTOP_SELECTARG2 */ ARG2,
6068 /* D3DTOP_MODULATE */ ARG1 | ARG2,
6069 /* D3DTOP_MODULATE2X */ ARG1 | ARG2,
6070 /* D3DTOP_MODULATE4X */ ARG1 | ARG2,
6071 /* D3DTOP_ADD */ ARG1 | ARG2,
6072 /* D3DTOP_ADDSIGNED */ ARG1 | ARG2,
6073 /* D3DTOP_ADDSIGNED2X */ ARG1 | ARG2,
6074 /* D3DTOP_SUBTRACT */ ARG1 | ARG2,
6075 /* D3DTOP_ADDSMOOTH */ ARG1 | ARG2,
6076 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1 | ARG2,
6077 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1 | ARG2,
6078 /* D3DTOP_BLENDFACTORALPHA */ ARG1 | ARG2,
6079 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1 | ARG2,
6080 /* D3DTOP_BLENDCURRENTALPHA */ ARG1 | ARG2,
6081 /* D3DTOP_PREMODULATE */ ARG1 | ARG2,
6082 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1 | ARG2,
6083 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1 | ARG2,
6084 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1 | ARG2,
6085 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1 | ARG2,
6086 /* D3DTOP_BUMPENVMAP */ ARG1 | ARG2,
6087 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1 | ARG2,
6088 /* D3DTOP_DOTPRODUCT3 */ ARG1 | ARG2,
6089 /* D3DTOP_MULTIPLYADD */ ARG1 | ARG2 | ARG0,
6090 /* D3DTOP_LERP */ ARG1 | ARG2 | ARG0
6092 unsigned int i;
6093 DWORD ttff;
6094 DWORD cop, aop, carg0, carg1, carg2, aarg0, aarg1, aarg2;
6095 const struct wined3d_d3d_info *d3d_info = context->d3d_info;
6097 settings->padding = 0;
6099 for (i = 0; i < d3d_info->limits.ffp_blend_stages; ++i)
6101 struct wined3d_texture *texture;
6103 settings->op[i].padding = 0;
6104 if (state->texture_states[i][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_DISABLE)
6106 settings->op[i].cop = WINED3D_TOP_DISABLE;
6107 settings->op[i].aop = WINED3D_TOP_DISABLE;
6108 settings->op[i].carg0 = settings->op[i].carg1 = settings->op[i].carg2 = ARG_UNUSED;
6109 settings->op[i].aarg0 = settings->op[i].aarg1 = settings->op[i].aarg2 = ARG_UNUSED;
6110 settings->op[i].color_fixup = COLOR_FIXUP_IDENTITY;
6111 settings->op[i].tmp_dst = 0;
6112 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_1D;
6113 settings->op[i].projected = WINED3D_PROJECTION_NONE;
6114 i++;
6115 break;
6118 if ((texture = state->textures[i]))
6120 if (can_use_texture_swizzle(d3d_info, texture->resource.format))
6121 settings->op[i].color_fixup = COLOR_FIXUP_IDENTITY;
6122 else
6123 settings->op[i].color_fixup = texture->resource.format->color_fixup;
6124 if (ignore_textype)
6126 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_1D;
6128 else
6130 switch (wined3d_texture_gl(texture)->target)
6132 case GL_TEXTURE_1D:
6133 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_1D;
6134 break;
6135 case GL_TEXTURE_2D:
6136 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_2D;
6137 break;
6138 case GL_TEXTURE_3D:
6139 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_3D;
6140 break;
6141 case GL_TEXTURE_CUBE_MAP_ARB:
6142 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_CUBE;
6143 break;
6144 case GL_TEXTURE_RECTANGLE_ARB:
6145 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_RECT;
6146 break;
6149 } else {
6150 settings->op[i].color_fixup = COLOR_FIXUP_IDENTITY;
6151 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_1D;
6154 cop = state->texture_states[i][WINED3D_TSS_COLOR_OP];
6155 aop = state->texture_states[i][WINED3D_TSS_ALPHA_OP];
6157 carg1 = (args[cop] & ARG1) ? state->texture_states[i][WINED3D_TSS_COLOR_ARG1] : ARG_UNUSED;
6158 carg2 = (args[cop] & ARG2) ? state->texture_states[i][WINED3D_TSS_COLOR_ARG2] : ARG_UNUSED;
6159 carg0 = (args[cop] & ARG0) ? state->texture_states[i][WINED3D_TSS_COLOR_ARG0] : ARG_UNUSED;
6161 if (is_invalid_op(state, i, cop, carg1, carg2, carg0))
6163 carg0 = ARG_UNUSED;
6164 carg2 = ARG_UNUSED;
6165 carg1 = WINED3DTA_CURRENT;
6166 cop = WINED3D_TOP_SELECT_ARG1;
6169 if (cop == WINED3D_TOP_DOTPRODUCT3)
6171 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
6172 * the color result to the alpha component of the destination
6174 aop = cop;
6175 aarg1 = carg1;
6176 aarg2 = carg2;
6177 aarg0 = carg0;
6179 else
6181 aarg1 = (args[aop] & ARG1) ? state->texture_states[i][WINED3D_TSS_ALPHA_ARG1] : ARG_UNUSED;
6182 aarg2 = (args[aop] & ARG2) ? state->texture_states[i][WINED3D_TSS_ALPHA_ARG2] : ARG_UNUSED;
6183 aarg0 = (args[aop] & ARG0) ? state->texture_states[i][WINED3D_TSS_ALPHA_ARG0] : ARG_UNUSED;
6186 if (!i && state->textures[0] && state->render_states[WINED3D_RS_COLORKEYENABLE])
6188 GLenum texture_dimensions;
6190 texture = state->textures[0];
6191 texture_dimensions = wined3d_texture_gl(texture)->target;
6193 if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
6195 if (texture->async.color_key_flags & WINED3D_CKEY_SRC_BLT && !texture->resource.format->alpha_size)
6197 if (aop == WINED3D_TOP_DISABLE)
6199 aarg1 = WINED3DTA_TEXTURE;
6200 aop = WINED3D_TOP_SELECT_ARG1;
6202 else if (aop == WINED3D_TOP_SELECT_ARG1 && aarg1 != WINED3DTA_TEXTURE)
6204 if (state->blend_state && state->blend_state->desc.rt[0].enable)
6206 aarg2 = WINED3DTA_TEXTURE;
6207 aop = WINED3D_TOP_MODULATE;
6209 else aarg1 = WINED3DTA_TEXTURE;
6211 else if (aop == WINED3D_TOP_SELECT_ARG2 && aarg2 != WINED3DTA_TEXTURE)
6213 if (state->blend_state && state->blend_state->desc.rt[0].enable)
6215 aarg1 = WINED3DTA_TEXTURE;
6216 aop = WINED3D_TOP_MODULATE;
6218 else aarg2 = WINED3DTA_TEXTURE;
6224 if (is_invalid_op(state, i, aop, aarg1, aarg2, aarg0))
6226 aarg0 = ARG_UNUSED;
6227 aarg2 = ARG_UNUSED;
6228 aarg1 = WINED3DTA_CURRENT;
6229 aop = WINED3D_TOP_SELECT_ARG1;
6232 if (carg1 == WINED3DTA_TEXTURE || carg2 == WINED3DTA_TEXTURE || carg0 == WINED3DTA_TEXTURE
6233 || aarg1 == WINED3DTA_TEXTURE || aarg2 == WINED3DTA_TEXTURE || aarg0 == WINED3DTA_TEXTURE)
6235 ttff = state->texture_states[i][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS];
6236 if (ttff == (WINED3D_TTFF_PROJECTED | WINED3D_TTFF_COUNT3))
6237 settings->op[i].projected = WINED3D_PROJECTION_COUNT3;
6238 else if (ttff & WINED3D_TTFF_PROJECTED)
6239 settings->op[i].projected = WINED3D_PROJECTION_COUNT4;
6240 else
6241 settings->op[i].projected = WINED3D_PROJECTION_NONE;
6243 else
6245 settings->op[i].projected = WINED3D_PROJECTION_NONE;
6248 settings->op[i].cop = cop;
6249 settings->op[i].aop = aop;
6250 settings->op[i].carg0 = carg0;
6251 settings->op[i].carg1 = carg1;
6252 settings->op[i].carg2 = carg2;
6253 settings->op[i].aarg0 = aarg0;
6254 settings->op[i].aarg1 = aarg1;
6255 settings->op[i].aarg2 = aarg2;
6256 settings->op[i].tmp_dst = state->texture_states[i][WINED3D_TSS_RESULT_ARG] == WINED3DTA_TEMP;
6259 /* Clear unsupported stages */
6260 for(; i < WINED3D_MAX_TEXTURES; i++) {
6261 memset(&settings->op[i], 0xff, sizeof(settings->op[i]));
6264 if (!state->render_states[WINED3D_RS_FOGENABLE])
6266 settings->fog = WINED3D_FFP_PS_FOG_OFF;
6268 else if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE)
6270 if (use_vs(state) || state->vertex_declaration->position_transformed)
6272 settings->fog = WINED3D_FFP_PS_FOG_LINEAR;
6274 else
6276 switch (state->render_states[WINED3D_RS_FOGVERTEXMODE])
6278 case WINED3D_FOG_NONE:
6279 case WINED3D_FOG_LINEAR:
6280 settings->fog = WINED3D_FFP_PS_FOG_LINEAR;
6281 break;
6282 case WINED3D_FOG_EXP:
6283 settings->fog = WINED3D_FFP_PS_FOG_EXP;
6284 break;
6285 case WINED3D_FOG_EXP2:
6286 settings->fog = WINED3D_FFP_PS_FOG_EXP2;
6287 break;
6291 else
6293 switch (state->render_states[WINED3D_RS_FOGTABLEMODE])
6295 case WINED3D_FOG_LINEAR:
6296 settings->fog = WINED3D_FFP_PS_FOG_LINEAR;
6297 break;
6298 case WINED3D_FOG_EXP:
6299 settings->fog = WINED3D_FFP_PS_FOG_EXP;
6300 break;
6301 case WINED3D_FOG_EXP2:
6302 settings->fog = WINED3D_FFP_PS_FOG_EXP2;
6303 break;
6306 settings->sRGB_write = !d3d_info->srgb_write_control && needs_srgb_write(d3d_info, state, &state->fb);
6307 if (d3d_info->vs_clipping || !use_vs(state) || !state->render_states[WINED3D_RS_CLIPPING]
6308 || !state->render_states[WINED3D_RS_CLIPPLANEENABLE])
6310 /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
6311 * the fixed function vertex pipeline is used(which always supports clipplanes), or
6312 * if no clipplane is enabled
6314 settings->emul_clipplanes = 0;
6315 } else {
6316 settings->emul_clipplanes = 1;
6319 if (state->render_states[WINED3D_RS_COLORKEYENABLE] && state->textures[0]
6320 && state->textures[0]->async.color_key_flags & WINED3D_CKEY_SRC_BLT
6321 && settings->op[0].cop != WINED3D_TOP_DISABLE)
6322 settings->color_key_enabled = 1;
6323 else
6324 settings->color_key_enabled = 0;
6326 /* texcoords_initialized is set to meaningful values only when GL doesn't
6327 * support enough varyings to always pass around all the possible texture
6328 * coordinates.
6329 * This is used to avoid reading a varying not written by the vertex shader.
6330 * Reading uninitialized varyings on core profile contexts results in an
6331 * error while with builtin varyings on legacy contexts you get undefined
6332 * behavior. */
6333 if (d3d_info->limits.varying_count && !d3d_info->full_ffp_varyings)
6335 settings->texcoords_initialized = 0;
6336 for (i = 0; i < WINED3D_MAX_TEXTURES; ++i)
6338 if (use_vs(state))
6340 if (state->shader[WINED3D_SHADER_TYPE_VERTEX]->reg_maps.output_registers & (1u << i))
6341 settings->texcoords_initialized |= 1u << i;
6343 else
6345 const struct wined3d_stream_info *si = &context->stream_info;
6346 unsigned int coord_idx = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
6347 if ((state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX] >> WINED3D_FFP_TCI_SHIFT)
6348 & WINED3D_FFP_TCI_MASK
6349 || (coord_idx < WINED3D_MAX_TEXTURES && (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coord_idx)))))
6350 settings->texcoords_initialized |= 1u << i;
6354 else
6356 settings->texcoords_initialized = (1u << WINED3D_MAX_TEXTURES) - 1;
6359 settings->pointsprite = state->render_states[WINED3D_RS_POINTSPRITEENABLE]
6360 && state->primitive_type == WINED3D_PT_POINTLIST;
6362 if (d3d_info->ffp_alpha_test)
6363 settings->alpha_test_func = WINED3D_CMP_ALWAYS - 1;
6364 else
6365 settings->alpha_test_func = (state->render_states[WINED3D_RS_ALPHATESTENABLE]
6366 ? wined3d_sanitize_cmp_func(state->render_states[WINED3D_RS_ALPHAFUNC])
6367 : WINED3D_CMP_ALWAYS) - 1;
6369 if (d3d_info->emulated_flatshading)
6370 settings->flatshading = state->render_states[WINED3D_RS_SHADEMODE] == WINED3D_SHADE_FLAT;
6371 else
6372 settings->flatshading = FALSE;
6375 const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders,
6376 const struct ffp_frag_settings *settings)
6378 struct wine_rb_entry *entry = wine_rb_get(fragment_shaders, settings);
6379 return entry ? WINE_RB_ENTRY_VALUE(entry, struct ffp_frag_desc, entry) : NULL;
6382 void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc)
6384 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
6385 * whereas desc points to an extended structure with implementation specific parts. */
6386 if (wine_rb_put(shaders, &desc->settings, &desc->entry) == -1)
6388 ERR("Failed to insert ffp frag shader.\n");
6392 /* Activates the texture dimension according to the bound D3D texture. Does
6393 * not care for the colorop or correct gl texture unit (when using nvrc).
6394 * Requires the caller to activate the correct unit. */
6395 /* Context activation is done by the caller (state handler). */
6396 void texture_activate_dimensions(struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info)
6398 if (texture)
6400 switch (wined3d_texture_gl(texture)->target)
6402 case GL_TEXTURE_2D:
6403 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
6404 checkGLcall("glDisable(GL_TEXTURE_3D)");
6405 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
6407 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
6408 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6410 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
6412 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
6413 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6415 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_2D);
6416 checkGLcall("glEnable(GL_TEXTURE_2D)");
6417 break;
6418 case GL_TEXTURE_RECTANGLE_ARB:
6419 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
6420 checkGLcall("glDisable(GL_TEXTURE_2D)");
6421 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
6422 checkGLcall("glDisable(GL_TEXTURE_3D)");
6423 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
6425 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
6426 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6428 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_RECTANGLE_ARB);
6429 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
6430 break;
6431 case GL_TEXTURE_3D:
6432 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
6434 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
6435 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6437 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
6439 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
6440 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6442 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
6443 checkGLcall("glDisable(GL_TEXTURE_2D)");
6444 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_3D);
6445 checkGLcall("glEnable(GL_TEXTURE_3D)");
6446 break;
6447 case GL_TEXTURE_CUBE_MAP_ARB:
6448 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
6449 checkGLcall("glDisable(GL_TEXTURE_2D)");
6450 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
6451 checkGLcall("glDisable(GL_TEXTURE_3D)");
6452 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
6454 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
6455 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6457 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_CUBE_MAP_ARB);
6458 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
6459 break;
6462 else
6464 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_2D);
6465 checkGLcall("glEnable(GL_TEXTURE_2D)");
6466 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
6467 checkGLcall("glDisable(GL_TEXTURE_3D)");
6468 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
6470 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
6471 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6473 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
6475 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
6476 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6478 /* Binding textures is done by samplers. A dummy texture will be bound */
6482 /* Context activation is done by the caller (state handler). */
6483 void sampler_texdim(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
6485 struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
6486 unsigned int sampler = state_id - STATE_SAMPLER(0);
6487 unsigned int mapped_stage;
6489 /* No need to enable / disable anything here for unused samplers. The
6490 * tex_colorop handler takes care. Also no action is needed with pixel
6491 * shaders, or if tex_colorop will take care of this business. */
6492 mapped_stage = context_gl->tex_unit_map[sampler];
6493 if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context_gl->gl_info->limits.textures)
6494 return;
6495 if (sampler >= context->lowest_disabled_stage)
6496 return;
6497 if (isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP)))
6498 return;
6500 texture_activate_dimensions(state->textures[sampler], context_gl->gl_info);
6503 int wined3d_ffp_frag_program_key_compare(const void *key, const struct wine_rb_entry *entry)
6505 const struct ffp_frag_settings *ka = key;
6506 const struct ffp_frag_settings *kb = &WINE_RB_ENTRY_VALUE(entry, const struct ffp_frag_desc, entry)->settings;
6508 return memcmp(ka, kb, sizeof(*ka));
6511 void wined3d_ffp_get_vs_settings(const struct wined3d_context *context,
6512 const struct wined3d_state *state, struct wined3d_ffp_vs_settings *settings)
6514 enum wined3d_material_color_source diffuse_source, emissive_source, ambient_source, specular_source;
6515 const struct wined3d_stream_info *si = &context->stream_info;
6516 const struct wined3d_d3d_info *d3d_info = context->d3d_info;
6517 unsigned int coord_idx, i;
6519 memset(settings, 0, sizeof(*settings));
6521 if (si->position_transformed)
6523 settings->transformed = 1;
6524 settings->point_size = state->primitive_type == WINED3D_PT_POINTLIST;
6525 settings->per_vertex_point_size = !!(si->use_map & 1u << WINED3D_FFP_PSIZE);
6526 if (!state->render_states[WINED3D_RS_FOGENABLE])
6527 settings->fog_mode = WINED3D_FFP_VS_FOG_OFF;
6528 else if (state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE)
6529 settings->fog_mode = WINED3D_FFP_VS_FOG_DEPTH;
6530 else
6531 settings->fog_mode = WINED3D_FFP_VS_FOG_FOGCOORD;
6533 for (i = 0; i < WINED3D_MAX_TEXTURES; ++i)
6535 coord_idx = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
6536 if (coord_idx < WINED3D_MAX_TEXTURES && (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coord_idx))))
6537 settings->texcoords |= 1u << i;
6538 settings->texgen[i] = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
6540 if (d3d_info->full_ffp_varyings)
6541 settings->texcoords = (1u << WINED3D_MAX_TEXTURES) - 1;
6543 if (d3d_info->emulated_flatshading)
6544 settings->flatshading = state->render_states[WINED3D_RS_SHADEMODE] == WINED3D_SHADE_FLAT;
6545 else
6546 settings->flatshading = FALSE;
6548 settings->swizzle_map = si->swizzle_map;
6550 return;
6553 switch (state->render_states[WINED3D_RS_VERTEXBLEND])
6555 case WINED3D_VBF_DISABLE:
6556 case WINED3D_VBF_1WEIGHTS:
6557 case WINED3D_VBF_2WEIGHTS:
6558 case WINED3D_VBF_3WEIGHTS:
6559 settings->vertexblends = state->render_states[WINED3D_RS_VERTEXBLEND];
6560 break;
6561 default:
6562 FIXME("Unsupported vertex blending: %d\n", state->render_states[WINED3D_RS_VERTEXBLEND]);
6563 break;
6566 settings->clipping = state->render_states[WINED3D_RS_CLIPPING]
6567 && state->render_states[WINED3D_RS_CLIPPLANEENABLE];
6568 settings->normal = !!(si->use_map & (1u << WINED3D_FFP_NORMAL));
6569 settings->normalize = settings->normal && state->render_states[WINED3D_RS_NORMALIZENORMALS];
6570 settings->lighting = !!state->render_states[WINED3D_RS_LIGHTING];
6571 settings->localviewer = !!state->render_states[WINED3D_RS_LOCALVIEWER];
6572 settings->point_size = state->primitive_type == WINED3D_PT_POINTLIST;
6573 settings->per_vertex_point_size = !!(si->use_map & 1u << WINED3D_FFP_PSIZE);
6575 wined3d_get_material_colour_source(&diffuse_source, &emissive_source,
6576 &ambient_source, &specular_source, state, si);
6577 settings->diffuse_source = diffuse_source;
6578 settings->emissive_source = emissive_source;
6579 settings->ambient_source = ambient_source;
6580 settings->specular_source = specular_source;
6582 for (i = 0; i < WINED3D_MAX_TEXTURES; ++i)
6584 coord_idx = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
6585 if (coord_idx < WINED3D_MAX_TEXTURES && (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coord_idx))))
6586 settings->texcoords |= 1u << i;
6587 settings->texgen[i] = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
6589 if (d3d_info->full_ffp_varyings)
6590 settings->texcoords = (1u << WINED3D_MAX_TEXTURES) - 1;
6592 for (i = 0; i < WINED3D_MAX_ACTIVE_LIGHTS; ++i)
6594 if (!state->light_state.lights[i])
6595 continue;
6597 switch (state->light_state.lights[i]->OriginalParms.type)
6599 case WINED3D_LIGHT_POINT:
6600 ++settings->point_light_count;
6601 break;
6602 case WINED3D_LIGHT_SPOT:
6603 ++settings->spot_light_count;
6604 break;
6605 case WINED3D_LIGHT_DIRECTIONAL:
6606 ++settings->directional_light_count;
6607 break;
6608 case WINED3D_LIGHT_PARALLELPOINT:
6609 ++settings->parallel_point_light_count;
6610 break;
6611 default:
6612 FIXME("Unhandled light type %#x.\n", state->light_state.lights[i]->OriginalParms.type);
6613 break;
6617 if (!state->render_states[WINED3D_RS_FOGENABLE])
6618 settings->fog_mode = WINED3D_FFP_VS_FOG_OFF;
6619 else if (state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE)
6621 settings->fog_mode = WINED3D_FFP_VS_FOG_DEPTH;
6623 if (state->transforms[WINED3D_TS_PROJECTION]._14 == 0.0f
6624 && state->transforms[WINED3D_TS_PROJECTION]._24 == 0.0f
6625 && state->transforms[WINED3D_TS_PROJECTION]._34 == 0.0f
6626 && state->transforms[WINED3D_TS_PROJECTION]._44 == 1.0f)
6627 settings->ortho_fog = 1;
6629 else if (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE)
6630 settings->fog_mode = WINED3D_FFP_VS_FOG_FOGCOORD;
6631 else if (state->render_states[WINED3D_RS_RANGEFOGENABLE])
6632 settings->fog_mode = WINED3D_FFP_VS_FOG_RANGE;
6633 else
6634 settings->fog_mode = WINED3D_FFP_VS_FOG_DEPTH;
6636 if (d3d_info->emulated_flatshading)
6637 settings->flatshading = state->render_states[WINED3D_RS_SHADEMODE] == WINED3D_SHADE_FLAT;
6638 else
6639 settings->flatshading = FALSE;
6641 settings->swizzle_map = si->swizzle_map;
6644 int wined3d_ffp_vertex_program_key_compare(const void *key, const struct wine_rb_entry *entry)
6646 const struct wined3d_ffp_vs_settings *ka = key;
6647 const struct wined3d_ffp_vs_settings *kb = &WINE_RB_ENTRY_VALUE(entry,
6648 const struct wined3d_ffp_vs_desc, entry)->settings;
6650 return memcmp(ka, kb, sizeof(*ka));
6653 const char *wined3d_debug_location(DWORD location)
6655 struct debug_buffer buffer;
6656 const char *prefix = "";
6657 const char *suffix = "";
6659 if (wined3d_popcount(location) > 16)
6661 prefix = "~(";
6662 location = ~location;
6663 suffix = ")";
6666 init_debug_buffer(&buffer, "0");
6667 #define LOCATION_TO_STR(x) if (location & x) { debug_append(&buffer, #x, " | "); location &= ~x; }
6668 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED);
6669 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM);
6670 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER);
6671 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB);
6672 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB);
6673 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE);
6674 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE);
6675 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED);
6676 #undef LOCATION_TO_STR
6677 if (location)
6678 FIXME("Unrecognized location flag(s) %#x.\n", location);
6680 return wine_dbg_sprintf("%s%s%s", prefix, buffer.str, suffix);
6683 const char *wined3d_debug_feature_level(enum wined3d_feature_level level)
6685 switch (level)
6687 #define LEVEL_TO_STR(level) case level: return #level
6688 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_5);
6689 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_6);
6690 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_7);
6691 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_8);
6692 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_1);
6693 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_2);
6694 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_3);
6695 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_10);
6696 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_10_1);
6697 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_11);
6698 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_11_1);
6699 #undef LEVEL_TO_STR
6700 default:
6701 return wine_dbg_sprintf("%#x", level);
6705 /* Print a floating point value with the %.8e format specifier, always using
6706 * '.' as decimal separator. */
6707 void wined3d_ftoa(float value, char *s)
6709 int idx = 1;
6711 if (copysignf(1.0f, value) < 0.0f)
6712 ++idx;
6714 /* Be sure to allocate a buffer of at least 17 characters for the result
6715 as sprintf may return a 3 digit exponent when using the MSVC runtime
6716 instead of a 2 digit exponent. */
6717 sprintf(s, "%.8e", value);
6718 if (isfinite(value))
6719 s[idx] = '.';
6722 void wined3d_release_dc(HWND window, HDC dc)
6724 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
6725 * However, that's not what actually happens, and there are user32 tests
6726 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
6727 * So explicitly check that the DC belongs to the window, since we want to
6728 * avoid releasing a DC that belongs to some other window if the original
6729 * window was already destroyed. */
6730 if (WindowFromDC(dc) != window)
6731 WARN("DC %p does not belong to window %p.\n", dc, window);
6732 else if (!ReleaseDC(window, dc))
6733 ERR("Failed to release device context %p, last error %#x.\n", dc, GetLastError());
6736 BOOL wined3d_clip_blit(const RECT *clip_rect, RECT *clipped, RECT *other)
6738 RECT orig = *clipped;
6739 float scale_x = (float)(orig.right - orig.left) / (float)(other->right - other->left);
6740 float scale_y = (float)(orig.bottom - orig.top) / (float)(other->bottom - other->top);
6742 IntersectRect(clipped, clipped, clip_rect);
6744 if (IsRectEmpty(clipped))
6746 SetRectEmpty(other);
6747 return FALSE;
6750 other->left += (LONG)((clipped->left - orig.left) / scale_x);
6751 other->top += (LONG)((clipped->top - orig.top) / scale_y);
6752 other->right -= (LONG)((orig.right - clipped->right) / scale_x);
6753 other->bottom -= (LONG)((orig.bottom - clipped->bottom) / scale_y);
6755 return TRUE;
6758 void wined3d_gl_limits_get_uniform_block_range(const struct wined3d_gl_limits *gl_limits,
6759 enum wined3d_shader_type shader_type, unsigned int *base, unsigned int *count)
6761 unsigned int i;
6763 *base = 0;
6764 for (i = 0; i < WINED3D_SHADER_TYPE_COUNT; ++i)
6766 *count = gl_limits->uniform_blocks[i];
6767 if (i == shader_type)
6768 return;
6769 *base += *count;
6772 ERR("Unrecognized shader type %#x.\n", shader_type);
6773 *count = 0;
6776 void wined3d_gl_limits_get_texture_unit_range(const struct wined3d_gl_limits *gl_limits,
6777 enum wined3d_shader_type shader_type, unsigned int *base, unsigned int *count)
6779 unsigned int i;
6781 if (shader_type == WINED3D_SHADER_TYPE_COMPUTE)
6783 if (gl_limits->combined_samplers == gl_limits->graphics_samplers)
6784 *base = 0;
6785 else
6786 *base = gl_limits->graphics_samplers;
6787 *count = gl_limits->samplers[WINED3D_SHADER_TYPE_COMPUTE];
6788 return;
6791 *base = 0;
6792 for (i = 0; i < WINED3D_SHADER_TYPE_GRAPHICS_COUNT; ++i)
6794 *count = gl_limits->samplers[i];
6795 if (i == shader_type)
6796 return;
6797 *base += *count;
6800 ERR("Unrecognized shader type %#x.\n", shader_type);
6801 *count = 0;
6804 BOOL wined3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)
6806 SIZE_T max_capacity, new_capacity;
6807 void *new_elements;
6809 if (count <= *capacity)
6810 return TRUE;
6812 max_capacity = ~(SIZE_T)0 / size;
6813 if (count > max_capacity)
6814 return FALSE;
6816 new_capacity = max(1, *capacity);
6817 while (new_capacity < count && new_capacity <= max_capacity / 2)
6818 new_capacity *= 2;
6819 if (new_capacity < count)
6820 new_capacity = count;
6822 if (!*elements)
6823 new_elements = heap_alloc_zero(new_capacity * size);
6824 else
6825 new_elements = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *elements, new_capacity * size);
6826 if (!new_elements)
6827 return FALSE;
6829 *elements = new_elements;
6830 *capacity = new_capacity;
6831 return TRUE;
6834 static void swap_rows(float **a, float **b)
6836 float *tmp = *a;
6838 *a = *b;
6839 *b = tmp;
6842 BOOL invert_matrix(struct wined3d_matrix *out, const struct wined3d_matrix *m)
6844 float wtmp[4][8];
6845 float m0, m1, m2, m3, s;
6846 float *r0, *r1, *r2, *r3;
6848 r0 = wtmp[0];
6849 r1 = wtmp[1];
6850 r2 = wtmp[2];
6851 r3 = wtmp[3];
6853 r0[0] = m->_11;
6854 r0[1] = m->_12;
6855 r0[2] = m->_13;
6856 r0[3] = m->_14;
6857 r0[4] = 1.0f;
6858 r0[5] = r0[6] = r0[7] = 0.0f;
6860 r1[0] = m->_21;
6861 r1[1] = m->_22;
6862 r1[2] = m->_23;
6863 r1[3] = m->_24;
6864 r1[5] = 1.0f;
6865 r1[4] = r1[6] = r1[7] = 0.0f;
6867 r2[0] = m->_31;
6868 r2[1] = m->_32;
6869 r2[2] = m->_33;
6870 r2[3] = m->_34;
6871 r2[6] = 1.0f;
6872 r2[4] = r2[5] = r2[7] = 0.0f;
6874 r3[0] = m->_41;
6875 r3[1] = m->_42;
6876 r3[2] = m->_43;
6877 r3[3] = m->_44;
6878 r3[7] = 1.0f;
6879 r3[4] = r3[5] = r3[6] = 0.0f;
6881 /* Choose pivot - or die. */
6882 if (fabsf(r3[0]) > fabsf(r2[0]))
6883 swap_rows(&r3, &r2);
6884 if (fabsf(r2[0]) > fabsf(r1[0]))
6885 swap_rows(&r2, &r1);
6886 if (fabsf(r1[0]) > fabsf(r0[0]))
6887 swap_rows(&r1, &r0);
6888 if (r0[0] == 0.0f)
6889 return FALSE;
6891 /* Eliminate first variable. */
6892 m1 = r1[0] / r0[0]; m2 = r2[0] / r0[0]; m3 = r3[0] / r0[0];
6893 s = r0[1]; r1[1] -= m1 * s; r2[1] -= m2 * s; r3[1] -= m3 * s;
6894 s = r0[2]; r1[2] -= m1 * s; r2[2] -= m2 * s; r3[2] -= m3 * s;
6895 s = r0[3]; r1[3] -= m1 * s; r2[3] -= m2 * s; r3[3] -= m3 * s;
6896 s = r0[4];
6897 if (s != 0.0f)
6899 r1[4] -= m1 * s;
6900 r2[4] -= m2 * s;
6901 r3[4] -= m3 * s;
6903 s = r0[5];
6904 if (s != 0.0f)
6906 r1[5] -= m1 * s;
6907 r2[5] -= m2 * s;
6908 r3[5] -= m3 * s;
6910 s = r0[6];
6911 if (s != 0.0f)
6913 r1[6] -= m1 * s;
6914 r2[6] -= m2 * s;
6915 r3[6] -= m3 * s;
6917 s = r0[7];
6918 if (s != 0.0f)
6920 r1[7] -= m1 * s;
6921 r2[7] -= m2 * s;
6922 r3[7] -= m3 * s;
6925 /* Choose pivot - or die. */
6926 if (fabsf(r3[1]) > fabsf(r2[1]))
6927 swap_rows(&r3, &r2);
6928 if (fabsf(r2[1]) > fabsf(r1[1]))
6929 swap_rows(&r2, &r1);
6930 if (r1[1] == 0.0f)
6931 return FALSE;
6933 /* Eliminate second variable. */
6934 m2 = r2[1] / r1[1]; m3 = r3[1] / r1[1];
6935 r2[2] -= m2 * r1[2]; r3[2] -= m3 * r1[2];
6936 r2[3] -= m2 * r1[3]; r3[3] -= m3 * r1[3];
6937 s = r1[4];
6938 if (s != 0.0f)
6940 r2[4] -= m2 * s;
6941 r3[4] -= m3 * s;
6943 s = r1[5];
6944 if (s != 0.0f)
6946 r2[5] -= m2 * s;
6947 r3[5] -= m3 * s;
6949 s = r1[6];
6950 if (s != 0.0f)
6952 r2[6] -= m2 * s;
6953 r3[6] -= m3 * s;
6955 s = r1[7];
6956 if (s != 0.0f)
6958 r2[7] -= m2 * s;
6959 r3[7] -= m3 * s;
6962 /* Choose pivot - or die. */
6963 if (fabsf(r3[2]) > fabsf(r2[2]))
6964 swap_rows(&r3, &r2);
6965 if (r2[2] == 0.0f)
6966 return FALSE;
6968 /* Eliminate third variable. */
6969 m3 = r3[2] / r2[2];
6970 r3[3] -= m3 * r2[3];
6971 r3[4] -= m3 * r2[4];
6972 r3[5] -= m3 * r2[5];
6973 r3[6] -= m3 * r2[6];
6974 r3[7] -= m3 * r2[7];
6976 /* Last check. */
6977 if (r3[3] == 0.0f)
6978 return FALSE;
6980 /* Back substitute row 3. */
6981 s = 1.0f / r3[3];
6982 r3[4] *= s;
6983 r3[5] *= s;
6984 r3[6] *= s;
6985 r3[7] *= s;
6987 /* Back substitute row 2. */
6988 m2 = r2[3];
6989 s = 1.0f / r2[2];
6990 r2[4] = s * (r2[4] - r3[4] * m2);
6991 r2[5] = s * (r2[5] - r3[5] * m2);
6992 r2[6] = s * (r2[6] - r3[6] * m2);
6993 r2[7] = s * (r2[7] - r3[7] * m2);
6994 m1 = r1[3];
6995 r1[4] -= r3[4] * m1;
6996 r1[5] -= r3[5] * m1;
6997 r1[6] -= r3[6] * m1;
6998 r1[7] -= r3[7] * m1;
6999 m0 = r0[3];
7000 r0[4] -= r3[4] * m0;
7001 r0[5] -= r3[5] * m0;
7002 r0[6] -= r3[6] * m0;
7003 r0[7] -= r3[7] * m0;
7005 /* Back substitute row 1. */
7006 m1 = r1[2];
7007 s = 1.0f / r1[1];
7008 r1[4] = s * (r1[4] - r2[4] * m1);
7009 r1[5] = s * (r1[5] - r2[5] * m1);
7010 r1[6] = s * (r1[6] - r2[6] * m1);
7011 r1[7] = s * (r1[7] - r2[7] * m1);
7012 m0 = r0[2];
7013 r0[4] -= r2[4] * m0;
7014 r0[5] -= r2[5] * m0;
7015 r0[6] -= r2[6] * m0;
7016 r0[7] -= r2[7] * m0;
7018 /* Back substitute row 0. */
7019 m0 = r0[1];
7020 s = 1.0f / r0[0];
7021 r0[4] = s * (r0[4] - r1[4] * m0);
7022 r0[5] = s * (r0[5] - r1[5] * m0);
7023 r0[6] = s * (r0[6] - r1[6] * m0);
7024 r0[7] = s * (r0[7] - r1[7] * m0);
7026 out->_11 = r0[4];
7027 out->_12 = r0[5];
7028 out->_13 = r0[6];
7029 out->_14 = r0[7];
7030 out->_21 = r1[4];
7031 out->_22 = r1[5];
7032 out->_23 = r1[6];
7033 out->_24 = r1[7];
7034 out->_31 = r2[4];
7035 out->_32 = r2[5];
7036 out->_33 = r2[6];
7037 out->_34 = r2[7];
7038 out->_41 = r3[4];
7039 out->_42 = r3[5];
7040 out->_43 = r3[6];
7041 out->_44 = r3[7];
7043 return TRUE;
7046 /* Taken and adapted from Mesa. */
7047 static BOOL invert_matrix_3d(struct wined3d_matrix *out, const struct wined3d_matrix *in)
7049 float pos, neg, t, det;
7050 struct wined3d_matrix temp;
7052 /* Calculate the determinant of upper left 3x3 submatrix and
7053 * determine if the matrix is singular. */
7054 pos = neg = 0.0f;
7055 t = in->_11 * in->_22 * in->_33;
7056 if (t >= 0.0f)
7057 pos += t;
7058 else
7059 neg += t;
7061 t = in->_21 * in->_32 * in->_13;
7062 if (t >= 0.0f)
7063 pos += t;
7064 else
7065 neg += t;
7066 t = in->_31 * in->_12 * in->_23;
7067 if (t >= 0.0f)
7068 pos += t;
7069 else
7070 neg += t;
7072 t = -in->_31 * in->_22 * in->_13;
7073 if (t >= 0.0f)
7074 pos += t;
7075 else
7076 neg += t;
7077 t = -in->_21 * in->_12 * in->_33;
7078 if (t >= 0.0f)
7079 pos += t;
7080 else
7081 neg += t;
7083 t = -in->_11 * in->_32 * in->_23;
7084 if (t >= 0.0f)
7085 pos += t;
7086 else
7087 neg += t;
7089 det = pos + neg;
7091 if (fabsf(det) < 1e-25f)
7092 return FALSE;
7094 det = 1.0f / det;
7095 temp._11 = (in->_22 * in->_33 - in->_32 * in->_23) * det;
7096 temp._12 = -(in->_12 * in->_33 - in->_32 * in->_13) * det;
7097 temp._13 = (in->_12 * in->_23 - in->_22 * in->_13) * det;
7098 temp._21 = -(in->_21 * in->_33 - in->_31 * in->_23) * det;
7099 temp._22 = (in->_11 * in->_33 - in->_31 * in->_13) * det;
7100 temp._23 = -(in->_11 * in->_23 - in->_21 * in->_13) * det;
7101 temp._31 = (in->_21 * in->_32 - in->_31 * in->_22) * det;
7102 temp._32 = -(in->_11 * in->_32 - in->_31 * in->_12) * det;
7103 temp._33 = (in->_11 * in->_22 - in->_21 * in->_12) * det;
7105 *out = temp;
7106 return TRUE;
7109 void compute_normal_matrix(float *normal_matrix, BOOL legacy_lighting,
7110 const struct wined3d_matrix *modelview)
7112 struct wined3d_matrix mv;
7113 unsigned int i, j;
7115 mv = *modelview;
7116 if (legacy_lighting)
7117 invert_matrix_3d(&mv, &mv);
7118 else
7119 invert_matrix(&mv, &mv);
7120 /* Tests show that singular modelview matrices are used unchanged as normal
7121 * matrices on D3D3 and older. There seems to be no clearly consistent
7122 * behavior on newer D3D versions so always follow older ddraw behavior. */
7123 for (i = 0; i < 3; ++i)
7124 for (j = 0; j < 3; ++j)
7125 normal_matrix[i * 3 + j] = (&mv._11)[j * 4 + i];
7128 static void wined3d_allocator_release_block(struct wined3d_allocator *allocator,
7129 struct wined3d_allocator_block *block)
7131 block->parent = allocator->free;
7132 allocator->free = block;
7135 static struct wined3d_allocator_block *wined3d_allocator_acquire_block(struct wined3d_allocator *allocator)
7137 struct wined3d_allocator_block *block;
7139 if (!allocator->free)
7140 return heap_alloc(sizeof(*block));
7142 block = allocator->free;
7143 allocator->free = block->parent;
7145 return block;
7148 void wined3d_allocator_block_free(struct wined3d_allocator_block *block)
7150 struct wined3d_allocator *allocator = block->chunk->allocator;
7151 struct wined3d_allocator_block *parent;
7153 while ((parent = block->parent) && block->sibling->free)
7155 list_remove(&block->sibling->entry);
7156 wined3d_allocator_release_block(allocator, block->sibling);
7157 wined3d_allocator_release_block(allocator, block);
7158 block = parent;
7161 block->free = true;
7162 list_add_head(&block->chunk->available[block->order], &block->entry);
7165 static void wined3d_allocator_block_init(struct wined3d_allocator_block *block,
7166 struct wined3d_allocator_chunk *chunk, struct wined3d_allocator_block *parent,
7167 struct wined3d_allocator_block *sibling, unsigned int order, size_t offset, bool free)
7169 list_init(&block->entry);
7170 block->chunk = chunk;
7171 block->parent = parent;
7172 block->sibling = sibling;
7173 block->order = order;
7174 block->offset = offset;
7175 block->free = free;
7178 void wined3d_allocator_chunk_cleanup(struct wined3d_allocator_chunk *chunk)
7180 struct wined3d_allocator_block *block;
7181 size_t i;
7183 if (list_empty(&chunk->available[0]))
7185 ERR("Chunk %p is not empty.\n", chunk);
7186 return;
7189 for (i = 1; i < ARRAY_SIZE(chunk->available); ++i)
7191 if (!list_empty(&chunk->available[i]))
7193 ERR("Chunk %p is not empty.\n", chunk);
7194 return;
7198 block = LIST_ENTRY(list_head(&chunk->available[0]), struct wined3d_allocator_block, entry);
7199 wined3d_allocator_release_block(chunk->allocator, block);
7202 bool wined3d_allocator_chunk_init(struct wined3d_allocator_chunk *chunk, struct wined3d_allocator *allocator)
7204 struct wined3d_allocator_block *block;
7205 unsigned int i;
7207 if (!(block = wined3d_allocator_acquire_block(allocator)))
7208 return false;
7209 wined3d_allocator_block_init(block, chunk, NULL, NULL, 0, 0, true);
7211 list_init(&chunk->entry);
7212 for (i = 0; i < ARRAY_SIZE(chunk->available); ++i)
7214 list_init(&chunk->available[i]);
7216 list_add_head(&chunk->available[0], &block->entry);
7217 chunk->allocator = allocator;
7218 chunk->map_count = 0;
7219 chunk->map_ptr = NULL;
7221 return true;
7224 void wined3d_allocator_cleanup(struct wined3d_allocator *allocator)
7226 struct wined3d_allocator_chunk *chunk, *chunk2;
7227 struct wined3d_allocator_block *block, *next;
7228 size_t i;
7230 for (i = 0; i < allocator->pool_count; ++i)
7232 LIST_FOR_EACH_ENTRY_SAFE(chunk, chunk2, &allocator->pools[i].chunks, struct wined3d_allocator_chunk, entry)
7234 list_remove(&chunk->entry);
7235 allocator->ops->allocator_destroy_chunk(chunk);
7238 heap_free(allocator->pools);
7240 next = allocator->free;
7241 while ((block = next))
7243 next = block->parent;
7244 heap_free(block);
7248 static struct wined3d_allocator_block *wined3d_allocator_chunk_allocate(struct wined3d_allocator_chunk *chunk,
7249 unsigned int order)
7251 struct wined3d_allocator_block *block, *left, *right;
7252 unsigned int i = order;
7254 while (i)
7256 if (!list_empty(&chunk->available[i]))
7257 break;
7258 --i;
7261 if (list_empty(&chunk->available[i]))
7262 return NULL;
7264 block = LIST_ENTRY(list_head(&chunk->available[i]), struct wined3d_allocator_block, entry);
7265 list_remove(&block->entry);
7266 block->free = false;
7268 while (i < order)
7270 if (!(left = wined3d_allocator_acquire_block(chunk->allocator)))
7272 ERR("Failed to allocate left.\n");
7273 break;
7276 if (!(right = wined3d_allocator_acquire_block(chunk->allocator)))
7278 ERR("Failed to allocate right.\n");
7279 wined3d_allocator_release_block(chunk->allocator, left);
7280 break;
7283 wined3d_allocator_block_init(left, chunk, block, right, block->order + 1, block->offset, false);
7284 wined3d_allocator_block_init(right, chunk, block, left, block->order + 1,
7285 block->offset + (WINED3D_ALLOCATOR_CHUNK_SIZE >> left->order), true);
7286 list_add_head(&chunk->available[right->order], &right->entry);
7288 block = left;
7289 ++i;
7292 return block;
7295 struct wined3d_allocator_block *wined3d_allocator_allocate(struct wined3d_allocator *allocator,
7296 struct wined3d_context *context, unsigned int memory_type, size_t size)
7298 struct wined3d_allocator_chunk *chunk;
7299 struct wined3d_allocator_block *block;
7300 unsigned int order;
7302 if (size > WINED3D_ALLOCATOR_CHUNK_SIZE / 2)
7303 return NULL;
7305 if (size < WINED3D_ALLOCATOR_MIN_BLOCK_SIZE)
7306 order = WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT - 1;
7307 else
7308 order = wined3d_log2i(WINED3D_ALLOCATOR_CHUNK_SIZE / size);
7310 LIST_FOR_EACH_ENTRY(chunk, &allocator->pools[memory_type].chunks, struct wined3d_allocator_chunk, entry)
7312 if ((block = wined3d_allocator_chunk_allocate(chunk, order)))
7313 return block;
7316 if (!(chunk = allocator->ops->allocator_create_chunk(allocator,
7317 context, memory_type, WINED3D_ALLOCATOR_CHUNK_SIZE)))
7318 return NULL;
7320 if (!(block = wined3d_allocator_chunk_allocate(chunk, order)))
7321 return NULL;
7323 return block;
7326 bool wined3d_allocator_init(struct wined3d_allocator *allocator,
7327 size_t pool_count, const struct wined3d_allocator_ops *allocator_ops)
7329 size_t i;
7331 allocator->ops = allocator_ops;
7332 allocator->pool_count = pool_count;
7333 if (!(allocator->pools = heap_calloc(pool_count, sizeof(*allocator->pools))))
7334 return false;
7335 for (i = 0; i < pool_count; ++i)
7337 list_init(&allocator->pools[i].chunks);
7340 return true;