d2d1/tests: Fix stroke style object leak (Valgrind).
[wine.git] / dlls / wined3d / utils.c
blob79c322f9e6e9eae9907aa0de5db639185ffd428e
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},
70 #define WINED3D_FORMAT_COUNT (WINED3D_FORMAT_FOURCC_BASE + ARRAY_SIZE(format_index_remap))
72 struct wined3d_format_channels
74 enum wined3d_format_id id;
75 DWORD red_size, green_size, blue_size, alpha_size;
76 DWORD red_offset, green_offset, blue_offset, alpha_offset;
77 UINT bpp;
78 BYTE depth_size, stencil_size;
81 static const struct wined3d_format_channels formats[] =
83 /* size offset
84 * format id r g b a r g b a bpp depth stencil */
85 {WINED3DFMT_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
86 /* FourCC formats */
87 {WINED3DFMT_UYVY, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
88 {WINED3DFMT_YUY2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
89 {WINED3DFMT_YV12, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
90 {WINED3DFMT_NV12, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
91 {WINED3DFMT_DXT1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
92 {WINED3DFMT_DXT2, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
93 {WINED3DFMT_DXT3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
94 {WINED3DFMT_DXT4, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
95 {WINED3DFMT_DXT5, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
96 {WINED3DFMT_MULTI2_ARGB8, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
97 {WINED3DFMT_G8R8_G8B8, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
98 {WINED3DFMT_R8G8_B8G8, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
99 /* Hmm? */
100 {WINED3DFMT_R8G8_SNORM_Cx, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
101 {WINED3DFMT_R11G11B10_FLOAT, 11, 11, 10, 0, 0, 11, 22, 0, 4, 0, 0},
102 /* Palettized formats */
103 {WINED3DFMT_P8_UINT_A8_UNORM, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
104 {WINED3DFMT_P8_UINT, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
105 /* Standard ARGB formats. */
106 {WINED3DFMT_B8G8R8_UNORM, 8, 8, 8, 0, 16, 8, 0, 0, 3, 0, 0},
107 {WINED3DFMT_B5G6R5_UNORM, 5, 6, 5, 0, 11, 5, 0, 0, 2, 0, 0},
108 {WINED3DFMT_B5G5R5X1_UNORM, 5, 5, 5, 0, 10, 5, 0, 0, 2, 0, 0},
109 {WINED3DFMT_B5G5R5A1_UNORM, 5, 5, 5, 1, 10, 5, 0, 15, 2, 0, 0},
110 {WINED3DFMT_B4G4R4A4_UNORM, 4, 4, 4, 4, 8, 4, 0, 12, 2, 0, 0},
111 {WINED3DFMT_B2G3R3_UNORM, 3, 3, 2, 0, 5, 2, 0, 0, 1, 0, 0},
112 {WINED3DFMT_A8_UNORM, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0},
113 {WINED3DFMT_B2G3R3A8_UNORM, 3, 3, 2, 8, 5, 2, 0, 8, 2, 0, 0},
114 {WINED3DFMT_B4G4R4X4_UNORM, 4, 4, 4, 0, 8, 4, 0, 0, 2, 0, 0},
115 {WINED3DFMT_R8G8B8X8_UNORM, 8, 8, 8, 0, 0, 8, 16, 0, 4, 0, 0},
116 {WINED3DFMT_B10G10R10A2_UNORM, 10, 10, 10, 2, 20, 10, 0, 30, 4, 0, 0},
117 /* Luminance */
118 {WINED3DFMT_L8_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
119 {WINED3DFMT_L8A8_UNORM, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
120 {WINED3DFMT_L4A4_UNORM, 0, 0, 0, 4, 0, 0, 0, 4, 1, 0, 0},
121 {WINED3DFMT_L16_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
122 /* Bump mapping stuff */
123 {WINED3DFMT_R5G5_SNORM_L6_UNORM, 5, 5, 0, 0, 0, 5, 0, 0, 2, 0, 0},
124 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, 8, 8, 0, 0, 0, 8, 0, 0, 4, 0, 0},
125 {WINED3DFMT_R8G8B8A8_SNORM, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
126 {WINED3DFMT_R10G11B11_SNORM, 10, 11, 11, 0, 0, 10, 21, 0, 4, 0, 0},
127 {WINED3DFMT_R10G10B10X2_UINT, 10, 10, 10, 0, 0, 10, 20, 0, 4, 0, 0},
128 {WINED3DFMT_R10G10B10X2_SNORM, 10, 10, 10, 0, 0, 10, 20, 0, 4, 0, 0},
129 {WINED3DFMT_R10G10B10_SNORM_A2_UNORM, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
130 /* Depth stencil formats */
131 {WINED3DFMT_D16_LOCKABLE, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
132 {WINED3DFMT_D32_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
133 {WINED3DFMT_S1_UINT_D15_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 2, 15, 1},
134 {WINED3DFMT_X8D24_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 0},
135 {WINED3DFMT_S4X4_UINT_D24_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 4},
136 {WINED3DFMT_D16_UNORM, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
137 {WINED3DFMT_D32_FLOAT, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
138 {WINED3DFMT_S8_UINT_D24_FLOAT, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
139 /* Vendor-specific formats */
140 {WINED3DFMT_ATI1N, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
141 {WINED3DFMT_ATI2N, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
142 {WINED3DFMT_NVDB, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
143 {WINED3DFMT_INST, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
144 {WINED3DFMT_INTZ, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
145 {WINED3DFMT_RESZ, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
146 {WINED3DFMT_NVHU, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
147 {WINED3DFMT_NVHS, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
148 {WINED3DFMT_NULL, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
149 /* Unsure about them, could not find a Windows driver that supports them */
150 {WINED3DFMT_R16, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
151 {WINED3DFMT_AL16, 0, 0, 0, 16, 0, 0, 0, 16, 4, 0, 0},
152 /* DirectX 10 HDR formats */
153 {WINED3DFMT_R9G9B9E5_SHAREDEXP, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
154 /* Typeless */
155 {WINED3DFMT_R32G32B32A32_TYPELESS, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
156 {WINED3DFMT_R32G32B32_TYPELESS, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
157 {WINED3DFMT_R16G16B16A16_TYPELESS, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
158 {WINED3DFMT_R32G32_TYPELESS, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
159 {WINED3DFMT_R32G8X24_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 8, 32, 8},
160 {WINED3DFMT_R10G10B10A2_TYPELESS, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
161 {WINED3DFMT_R8G8B8A8_TYPELESS, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
162 {WINED3DFMT_R16G16_TYPELESS, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
163 {WINED3DFMT_R32_TYPELESS, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
164 {WINED3DFMT_R24G8_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
165 {WINED3DFMT_R8G8_TYPELESS, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
166 {WINED3DFMT_R16_TYPELESS, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
167 {WINED3DFMT_R8_TYPELESS, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
168 {WINED3DFMT_BC1_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
169 {WINED3DFMT_BC2_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
170 {WINED3DFMT_BC3_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
171 {WINED3DFMT_BC4_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
172 {WINED3DFMT_BC5_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
173 {WINED3DFMT_BC6H_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
174 {WINED3DFMT_BC7_TYPELESS, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
175 {WINED3DFMT_B8G8R8A8_TYPELESS, 8, 8, 8, 8, 16, 8, 0, 24, 4, 0, 0},
176 {WINED3DFMT_B8G8R8X8_TYPELESS, 8, 8, 8, 0, 16, 8, 0, 0, 4, 0, 0},
179 enum wined3d_channel_type
181 WINED3D_CHANNEL_TYPE_NONE,
182 WINED3D_CHANNEL_TYPE_UNORM,
183 WINED3D_CHANNEL_TYPE_SNORM,
184 WINED3D_CHANNEL_TYPE_UINT,
185 WINED3D_CHANNEL_TYPE_SINT,
186 WINED3D_CHANNEL_TYPE_FLOAT,
187 WINED3D_CHANNEL_TYPE_DEPTH,
188 WINED3D_CHANNEL_TYPE_STENCIL,
189 WINED3D_CHANNEL_TYPE_UNUSED,
192 struct wined3d_typed_format_info
194 enum wined3d_format_id id;
195 enum wined3d_format_id typeless_id;
196 const char *channels;
200 * The last entry for a given typeless format defines its internal format.
202 * u - WINED3D_CHANNEL_TYPE_UNORM
203 * i - WINED3D_CHANNEL_TYPE_SNORM
204 * U - WINED3D_CHANNEL_TYPE_UINT
205 * I - WINED3D_CHANNEL_TYPE_SINT
206 * F - WINED3D_CHANNEL_TYPE_FLOAT
207 * D - WINED3D_CHANNEL_TYPE_DEPTH
208 * S - WINED3D_CHANNEL_TYPE_STENCIL
209 * X - WINED3D_CHANNEL_TYPE_UNUSED
211 static const struct wined3d_typed_format_info typed_formats[] =
213 {WINED3DFMT_R32G32B32A32_UINT, WINED3DFMT_R32G32B32A32_TYPELESS, "UUUU"},
214 {WINED3DFMT_R32G32B32A32_SINT, WINED3DFMT_R32G32B32A32_TYPELESS, "IIII"},
215 {WINED3DFMT_R32G32B32A32_FLOAT, WINED3DFMT_R32G32B32A32_TYPELESS, "FFFF"},
216 {WINED3DFMT_R32G32B32_UINT, WINED3DFMT_R32G32B32_TYPELESS, "UUU"},
217 {WINED3DFMT_R32G32B32_SINT, WINED3DFMT_R32G32B32_TYPELESS, "III"},
218 {WINED3DFMT_R32G32B32_FLOAT, WINED3DFMT_R32G32B32_TYPELESS, "FFF"},
219 {WINED3DFMT_R16G16B16A16_UNORM, WINED3DFMT_R16G16B16A16_TYPELESS, "uuuu"},
220 {WINED3DFMT_R16G16B16A16_SNORM, WINED3DFMT_R16G16B16A16_TYPELESS, "iiii"},
221 {WINED3DFMT_R16G16B16A16_UINT, WINED3DFMT_R16G16B16A16_TYPELESS, "UUUU"},
222 {WINED3DFMT_R16G16B16A16_SINT, WINED3DFMT_R16G16B16A16_TYPELESS, "IIII"},
223 {WINED3DFMT_R16G16B16A16_FLOAT, WINED3DFMT_R16G16B16A16_TYPELESS, "FFFF"},
224 {WINED3DFMT_R32G32_UINT, WINED3DFMT_R32G32_TYPELESS, "UU"},
225 {WINED3DFMT_R32G32_SINT, WINED3DFMT_R32G32_TYPELESS, "II"},
226 {WINED3DFMT_R32G32_FLOAT, WINED3DFMT_R32G32_TYPELESS, "FF"},
227 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS, WINED3DFMT_R32G8X24_TYPELESS, "DX"},
228 {WINED3DFMT_X32_TYPELESS_G8X24_UINT, WINED3DFMT_R32G8X24_TYPELESS, "XS"},
229 {WINED3DFMT_D32_FLOAT_S8X24_UINT, WINED3DFMT_R32G8X24_TYPELESS, "DS"},
230 {WINED3DFMT_R10G10B10A2_SNORM, WINED3DFMT_R10G10B10A2_TYPELESS, "iiii"},
231 {WINED3DFMT_R10G10B10A2_UINT, WINED3DFMT_R10G10B10A2_TYPELESS, "UUUU"},
232 {WINED3DFMT_R10G10B10A2_UNORM, WINED3DFMT_R10G10B10A2_TYPELESS, "uuuu"},
233 {WINED3DFMT_R8G8B8A8_UINT, WINED3DFMT_R8G8B8A8_TYPELESS, "UUUU"},
234 {WINED3DFMT_R8G8B8A8_SINT, WINED3DFMT_R8G8B8A8_TYPELESS, "IIII"},
235 {WINED3DFMT_R8G8B8A8_UNORM_SRGB, WINED3DFMT_R8G8B8A8_TYPELESS, "uuuu"},
236 {WINED3DFMT_R8G8B8A8_UNORM, WINED3DFMT_R8G8B8A8_TYPELESS, "uuuu"},
237 {WINED3DFMT_R16G16_UNORM, WINED3DFMT_R16G16_TYPELESS, "uu"},
238 {WINED3DFMT_R16G16_SNORM, WINED3DFMT_R16G16_TYPELESS, "ii"},
239 {WINED3DFMT_R16G16_UINT, WINED3DFMT_R16G16_TYPELESS, "UU"},
240 {WINED3DFMT_R16G16_SINT, WINED3DFMT_R16G16_TYPELESS, "II"},
241 {WINED3DFMT_R16G16_FLOAT, WINED3DFMT_R16G16_TYPELESS, "FF"},
242 {WINED3DFMT_D32_FLOAT, WINED3DFMT_R32_TYPELESS, "D"},
243 {WINED3DFMT_R32_FLOAT, WINED3DFMT_R32_TYPELESS, "F"},
244 {WINED3DFMT_R32_UINT, WINED3DFMT_R32_TYPELESS, "U"},
245 {WINED3DFMT_R32_SINT, WINED3DFMT_R32_TYPELESS, "I"},
246 {WINED3DFMT_R24_UNORM_X8_TYPELESS, WINED3DFMT_R24G8_TYPELESS, "DX"},
247 {WINED3DFMT_X24_TYPELESS_G8_UINT, WINED3DFMT_R24G8_TYPELESS, "XS"},
248 {WINED3DFMT_D24_UNORM_S8_UINT, WINED3DFMT_R24G8_TYPELESS, "DS"},
249 {WINED3DFMT_R8G8_SNORM, WINED3DFMT_R8G8_TYPELESS, "ii"},
250 {WINED3DFMT_R8G8_UNORM, WINED3DFMT_R8G8_TYPELESS, "uu"},
251 {WINED3DFMT_R8G8_UINT, WINED3DFMT_R8G8_TYPELESS, "UU"},
252 {WINED3DFMT_R8G8_SINT, WINED3DFMT_R8G8_TYPELESS, "II"},
253 {WINED3DFMT_D16_UNORM, WINED3DFMT_R16_TYPELESS, "D"},
254 {WINED3DFMT_R16_UNORM, WINED3DFMT_R16_TYPELESS, "u"},
255 {WINED3DFMT_R16_SNORM, WINED3DFMT_R16_TYPELESS, "i"},
256 {WINED3DFMT_R16_UINT, WINED3DFMT_R16_TYPELESS, "U"},
257 {WINED3DFMT_R16_SINT, WINED3DFMT_R16_TYPELESS, "I"},
258 {WINED3DFMT_R16_FLOAT, WINED3DFMT_R16_TYPELESS, "F"},
259 {WINED3DFMT_R8_UNORM, WINED3DFMT_R8_TYPELESS, "u"},
260 {WINED3DFMT_R8_SNORM, WINED3DFMT_R8_TYPELESS, "i"},
261 {WINED3DFMT_R8_UINT, WINED3DFMT_R8_TYPELESS, "U"},
262 {WINED3DFMT_R8_SINT, WINED3DFMT_R8_TYPELESS, "I"},
263 {WINED3DFMT_BC1_UNORM_SRGB, WINED3DFMT_BC1_TYPELESS, ""},
264 {WINED3DFMT_BC1_UNORM, WINED3DFMT_BC1_TYPELESS, ""},
265 {WINED3DFMT_BC2_UNORM_SRGB, WINED3DFMT_BC2_TYPELESS, ""},
266 {WINED3DFMT_BC2_UNORM, WINED3DFMT_BC2_TYPELESS, ""},
267 {WINED3DFMT_BC3_UNORM_SRGB, WINED3DFMT_BC3_TYPELESS, ""},
268 {WINED3DFMT_BC3_UNORM, WINED3DFMT_BC3_TYPELESS, ""},
269 {WINED3DFMT_BC4_UNORM, WINED3DFMT_BC4_TYPELESS, ""},
270 {WINED3DFMT_BC5_UNORM, WINED3DFMT_BC5_TYPELESS, ""},
271 {WINED3DFMT_BC5_SNORM, WINED3DFMT_BC5_TYPELESS, ""},
272 {WINED3DFMT_BC6H_UF16, WINED3DFMT_BC6H_TYPELESS, ""},
273 {WINED3DFMT_BC6H_SF16, WINED3DFMT_BC6H_TYPELESS, ""},
274 {WINED3DFMT_BC7_UNORM_SRGB, WINED3DFMT_BC7_TYPELESS, ""},
275 {WINED3DFMT_BC7_UNORM, WINED3DFMT_BC7_TYPELESS, ""},
276 {WINED3DFMT_B8G8R8A8_UNORM_SRGB, WINED3DFMT_B8G8R8A8_TYPELESS, "uuuu"},
277 {WINED3DFMT_B8G8R8A8_UNORM, WINED3DFMT_B8G8R8A8_TYPELESS, "uuuu"},
278 {WINED3DFMT_B8G8R8X8_UNORM_SRGB, WINED3DFMT_B8G8R8X8_TYPELESS, "uuuX"},
279 {WINED3DFMT_B8G8R8X8_UNORM, WINED3DFMT_B8G8R8X8_TYPELESS, "uuuX"},
282 struct wined3d_typeless_format_depth_stencil_info
284 enum wined3d_format_id typeless_id;
285 enum wined3d_format_id depth_stencil_id;
286 enum wined3d_format_id depth_view_id;
287 enum wined3d_format_id stencil_view_id;
290 static const struct wined3d_typeless_format_depth_stencil_info typeless_depth_stencil_formats[] =
292 {WINED3DFMT_R32G8X24_TYPELESS, WINED3DFMT_D32_FLOAT_S8X24_UINT,
293 WINED3DFMT_R32_FLOAT_X8X24_TYPELESS, WINED3DFMT_X32_TYPELESS_G8X24_UINT},
294 {WINED3DFMT_R24G8_TYPELESS, WINED3DFMT_D24_UNORM_S8_UINT,
295 WINED3DFMT_R24_UNORM_X8_TYPELESS, WINED3DFMT_X24_TYPELESS_G8_UINT},
296 {WINED3DFMT_R32_TYPELESS, WINED3DFMT_D32_FLOAT},
297 {WINED3DFMT_R16_TYPELESS, WINED3DFMT_D16_UNORM},
300 struct wined3d_format_ddi_info
302 enum wined3d_format_id id;
303 D3DDDIFORMAT ddi_format;
306 static const struct wined3d_format_ddi_info ddi_formats[] =
308 {WINED3DFMT_B8G8R8_UNORM, D3DDDIFMT_R8G8B8},
309 {WINED3DFMT_B8G8R8A8_UNORM, D3DDDIFMT_A8R8G8B8},
310 {WINED3DFMT_B8G8R8X8_UNORM, D3DDDIFMT_X8R8G8B8},
311 {WINED3DFMT_B5G6R5_UNORM, D3DDDIFMT_R5G6B5},
312 {WINED3DFMT_B5G5R5X1_UNORM, D3DDDIFMT_X1R5G5B5},
313 {WINED3DFMT_B5G5R5A1_UNORM, D3DDDIFMT_A1R5G5B5},
314 {WINED3DFMT_B4G4R4A4_UNORM, D3DDDIFMT_A4R4G4B4},
315 {WINED3DFMT_B4G4R4X4_UNORM, D3DDDIFMT_X4R4G4B4},
316 {WINED3DFMT_P8_UINT, D3DDDIFMT_P8},
319 struct wined3d_format_base_flags
321 enum wined3d_format_id id;
322 DWORD flags;
325 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
326 * still needs to use the correct block based calculation for e.g. the
327 * resource size. */
328 static const struct wined3d_format_base_flags format_base_flags[] =
330 {WINED3DFMT_ATI1N, WINED3DFMT_FLAG_BROKEN_PITCH},
331 {WINED3DFMT_ATI2N, WINED3DFMT_FLAG_BROKEN_PITCH},
332 {WINED3DFMT_R11G11B10_FLOAT, WINED3DFMT_FLAG_FLOAT},
333 {WINED3DFMT_D32_FLOAT, WINED3DFMT_FLAG_FLOAT},
334 {WINED3DFMT_S8_UINT_D24_FLOAT, WINED3DFMT_FLAG_FLOAT},
335 {WINED3DFMT_D32_FLOAT_S8X24_UINT, WINED3DFMT_FLAG_FLOAT},
338 struct wined3d_format_block_info
340 enum wined3d_format_id id;
341 UINT block_width;
342 UINT block_height;
343 UINT block_byte_count;
344 BOOL verify;
347 static const struct wined3d_format_block_info format_block_info[] =
349 {WINED3DFMT_DXT1, 4, 4, 8, TRUE},
350 {WINED3DFMT_DXT2, 4, 4, 16, TRUE},
351 {WINED3DFMT_DXT3, 4, 4, 16, TRUE},
352 {WINED3DFMT_DXT4, 4, 4, 16, TRUE},
353 {WINED3DFMT_DXT5, 4, 4, 16, TRUE},
354 {WINED3DFMT_BC1_UNORM, 4, 4, 8, TRUE},
355 {WINED3DFMT_BC2_UNORM, 4, 4, 16, TRUE},
356 {WINED3DFMT_BC3_UNORM, 4, 4, 16, TRUE},
357 {WINED3DFMT_BC4_UNORM, 4, 4, 8, TRUE},
358 {WINED3DFMT_BC5_UNORM, 4, 4, 16, TRUE},
359 {WINED3DFMT_BC5_SNORM, 4, 4, 16, TRUE},
360 {WINED3DFMT_BC6H_UF16, 4, 4, 16, TRUE},
361 {WINED3DFMT_BC6H_SF16, 4, 4, 16, TRUE},
362 {WINED3DFMT_BC7_UNORM, 4, 4, 16, TRUE},
363 {WINED3DFMT_ATI1N, 4, 4, 8, FALSE},
364 {WINED3DFMT_ATI2N, 4, 4, 16, FALSE},
365 {WINED3DFMT_YUY2, 2, 1, 4, FALSE},
366 {WINED3DFMT_UYVY, 2, 1, 4, FALSE},
369 struct wined3d_format_vertex_info
371 enum wined3d_format_id id;
372 enum wined3d_ffp_emit_idx emit_idx;
373 unsigned int component_count;
374 GLenum gl_vtx_type;
375 GLboolean gl_normalized;
376 enum wined3d_gl_extension extension;
379 static const struct wined3d_format_vertex_info format_vertex_info[] =
381 {WINED3DFMT_R32_FLOAT, WINED3D_FFP_EMIT_FLOAT1, 1, GL_FLOAT, GL_FALSE},
382 {WINED3DFMT_R32G32_FLOAT, WINED3D_FFP_EMIT_FLOAT2, 2, GL_FLOAT, GL_FALSE},
383 {WINED3DFMT_R32G32B32_FLOAT, WINED3D_FFP_EMIT_FLOAT3, 3, GL_FLOAT, GL_FALSE},
384 {WINED3DFMT_R32G32B32A32_FLOAT, WINED3D_FFP_EMIT_FLOAT4, 4, GL_FLOAT, GL_FALSE},
385 {WINED3DFMT_B8G8R8A8_UNORM, WINED3D_FFP_EMIT_D3DCOLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE },
386 {WINED3DFMT_R8G8B8A8_UINT, WINED3D_FFP_EMIT_UBYTE4, 4, GL_UNSIGNED_BYTE, GL_FALSE},
387 {WINED3DFMT_R16G16_UINT, WINED3D_FFP_EMIT_INVALID, 2, GL_UNSIGNED_SHORT, GL_FALSE},
388 {WINED3DFMT_R16G16_SINT, WINED3D_FFP_EMIT_SHORT2, 2, GL_SHORT, GL_FALSE},
389 {WINED3DFMT_R16G16B16A16_SINT, WINED3D_FFP_EMIT_SHORT4, 4, GL_SHORT, GL_FALSE},
390 {WINED3DFMT_R8G8B8A8_UNORM, WINED3D_FFP_EMIT_UBYTE4N, 4, GL_UNSIGNED_BYTE, GL_TRUE },
391 {WINED3DFMT_R16G16_SNORM, WINED3D_FFP_EMIT_SHORT2N, 2, GL_SHORT, GL_TRUE },
392 {WINED3DFMT_R16G16B16A16_SNORM, WINED3D_FFP_EMIT_SHORT4N, 4, GL_SHORT, GL_TRUE },
393 {WINED3DFMT_R16G16_UNORM, WINED3D_FFP_EMIT_USHORT2N, 2, GL_UNSIGNED_SHORT, GL_TRUE },
394 {WINED3DFMT_R16G16B16A16_UNORM, WINED3D_FFP_EMIT_USHORT4N, 4, GL_UNSIGNED_SHORT, GL_TRUE },
395 {WINED3DFMT_R10G10B10X2_UINT, WINED3D_FFP_EMIT_UDEC3, 3, GL_UNSIGNED_SHORT, GL_FALSE},
396 {WINED3DFMT_R10G10B10X2_SNORM, WINED3D_FFP_EMIT_DEC3N, 3, GL_SHORT, GL_TRUE },
397 {WINED3DFMT_R10G10B10A2_UNORM, WINED3D_FFP_EMIT_INVALID, 4, GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE,
398 ARB_VERTEX_TYPE_2_10_10_10_REV},
399 {WINED3DFMT_R16G16_FLOAT, WINED3D_FFP_EMIT_FLOAT16_2, 2, GL_HALF_FLOAT, GL_FALSE},
400 {WINED3DFMT_R16G16B16A16_FLOAT, WINED3D_FFP_EMIT_FLOAT16_4, 4, GL_HALF_FLOAT, GL_FALSE},
401 {WINED3DFMT_R8G8B8A8_SNORM, WINED3D_FFP_EMIT_INVALID, 4, GL_BYTE, GL_TRUE },
402 {WINED3DFMT_R8G8B8A8_SINT, WINED3D_FFP_EMIT_INVALID, 4, GL_BYTE, GL_FALSE},
403 {WINED3DFMT_R16G16B16A16_UINT, WINED3D_FFP_EMIT_INVALID, 4, GL_UNSIGNED_SHORT, GL_FALSE},
404 {WINED3DFMT_R8_UINT, WINED3D_FFP_EMIT_INVALID, 1, GL_UNSIGNED_BYTE, GL_FALSE},
405 {WINED3DFMT_R8_SINT, WINED3D_FFP_EMIT_INVALID, 1, GL_BYTE, GL_FALSE},
406 {WINED3DFMT_R16_UINT, WINED3D_FFP_EMIT_INVALID, 1, GL_UNSIGNED_SHORT, GL_FALSE},
407 {WINED3DFMT_R16_SINT, WINED3D_FFP_EMIT_INVALID, 1, GL_SHORT, GL_FALSE},
408 {WINED3DFMT_R32_UINT, WINED3D_FFP_EMIT_INVALID, 1, GL_UNSIGNED_INT, GL_FALSE},
409 {WINED3DFMT_R32_SINT, WINED3D_FFP_EMIT_INVALID, 1, GL_INT, GL_FALSE},
410 {WINED3DFMT_R32G32_UINT, WINED3D_FFP_EMIT_INVALID, 2, GL_UNSIGNED_INT, GL_FALSE},
411 {WINED3DFMT_R32G32_SINT, WINED3D_FFP_EMIT_INVALID, 2, GL_INT, GL_FALSE},
412 {WINED3DFMT_R32G32B32_UINT, WINED3D_FFP_EMIT_INVALID, 3, GL_UNSIGNED_INT, GL_FALSE},
413 {WINED3DFMT_R32G32B32A32_UINT, WINED3D_FFP_EMIT_INVALID, 4, GL_UNSIGNED_INT, GL_FALSE},
414 {WINED3DFMT_R32G32B32A32_SINT, WINED3D_FFP_EMIT_INVALID, 4, GL_INT, GL_FALSE},
417 struct wined3d_format_texture_info
419 enum wined3d_format_id id;
420 GLint gl_internal;
421 GLint gl_srgb_internal;
422 GLint gl_rt_internal;
423 GLint gl_format;
424 GLint gl_type;
425 unsigned int conv_byte_count;
426 unsigned int flags;
427 enum wined3d_gl_extension extension;
428 void (*convert)(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
429 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth);
432 static void convert_l4a4_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
433 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
435 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
436 * format+type combination to load it. Thus convert it to A8L8, then load it
437 * with A4L4 internal, but A8L8 format+type
439 unsigned int x, y, z;
440 const unsigned char *Source;
441 unsigned char *Dest;
443 for (z = 0; z < depth; z++)
445 for (y = 0; y < height; y++)
447 Source = src + z * src_slice_pitch + y * src_row_pitch;
448 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
449 for (x = 0; x < width; x++ )
451 unsigned char color = (*Source++);
452 /* A */ Dest[1] = (color & 0xf0u) << 0;
453 /* L */ Dest[0] = (color & 0x0fu) << 4;
454 Dest += 2;
460 static void convert_r5g5_snorm_l6_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
461 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
463 unsigned int x, y, z;
464 unsigned char r_in, g_in, l_in;
465 const unsigned short *texel_in;
466 unsigned short *texel_out;
468 /* Emulating signed 5 bit values with unsigned 5 bit values has some precision problems by design:
469 * E.g. the signed input value 0 becomes 16. GL normalizes it to 16 / 31 = 0.516. We convert it
470 * back to a signed value by subtracting 0.5 and multiplying by 2.0. The resulting value is
471 * ((16 / 31) - 0.5) * 2.0 = 0.032, which is quite different from the intended result 0.000. */
472 for (z = 0; z < depth; z++)
474 for (y = 0; y < height; y++)
476 texel_out = (unsigned short *) (dst + z * dst_slice_pitch + y * dst_row_pitch);
477 texel_in = (const unsigned short *)(src + z * src_slice_pitch + y * src_row_pitch);
478 for (x = 0; x < width; x++ )
480 l_in = (*texel_in & 0xfc00u) >> 10;
481 g_in = (*texel_in & 0x03e0u) >> 5;
482 r_in = *texel_in & 0x001fu;
484 *texel_out = ((r_in + 16) << 11) | (l_in << 5) | (g_in + 16);
485 texel_out++;
486 texel_in++;
492 static void convert_r5g5_snorm_l6_unorm_ext(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
493 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
495 unsigned int x, y, z;
496 unsigned char *texel_out, r_out, g_out, r_in, g_in, l_in;
497 const unsigned short *texel_in;
499 for (z = 0; z < depth; z++)
501 for (y = 0; y < height; y++)
503 texel_in = (const unsigned short *)(src + z * src_slice_pitch + y * src_row_pitch);
504 texel_out = dst + z * dst_slice_pitch + y * dst_row_pitch;
505 for (x = 0; x < width; x++ )
507 l_in = (*texel_in & 0xfc00u) >> 10;
508 g_in = (*texel_in & 0x03e0u) >> 5;
509 r_in = *texel_in & 0x001fu;
511 r_out = r_in << 3;
512 if (!(r_in & 0x10)) /* r > 0 */
513 r_out |= r_in >> 1;
515 g_out = g_in << 3;
516 if (!(g_in & 0x10)) /* g > 0 */
517 g_out |= g_in >> 1;
519 texel_out[0] = r_out;
520 texel_out[1] = g_out;
521 texel_out[2] = l_in << 1 | l_in >> 5;
522 texel_out[3] = 0;
524 texel_out += 4;
525 texel_in++;
531 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
532 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
534 unsigned int x, y, z;
535 unsigned char *texel_out, ds_out, dt_out, r_in, g_in, l_in;
536 const unsigned short *texel_in;
538 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
539 * fixed function and shaders without further conversion once the surface is
540 * loaded.
542 * The difference between this function and convert_r5g5_snorm_l6_unorm_ext
543 * is that convert_r5g5_snorm_l6_unorm_ext creates a 32 bit XRGB texture and
544 * this function creates a 24 bit DSDT_MAG texture. Trying to load a DSDT_MAG
545 * internal with a 32 bit DSDT_MAG_INTENSITY or DSDT_MAG_VIB format fails. */
546 for (z = 0; z < depth; z++)
548 for (y = 0; y < height; y++)
550 texel_in = (const unsigned short *)(src + z * src_slice_pitch + y * src_row_pitch);
551 texel_out = dst + z * dst_slice_pitch + y * dst_row_pitch;
552 for (x = 0; x < width; x++ )
554 l_in = (*texel_in & 0xfc00u) >> 10;
555 g_in = (*texel_in & 0x03e0u) >> 5;
556 r_in = *texel_in & 0x001fu;
558 ds_out = r_in << 3;
559 if (!(r_in & 0x10)) /* r > 0 */
560 ds_out |= r_in >> 1;
562 dt_out = g_in << 3;
563 if (!(g_in & 0x10)) /* g > 0 */
564 dt_out |= g_in >> 1;
566 texel_out[0] = ds_out;
567 texel_out[1] = dt_out;
568 texel_out[2] = l_in << 1 | l_in >> 5;
570 texel_out += 3;
571 texel_in++;
577 static void convert_r8g8_snorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
578 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
580 unsigned int x, y, z;
581 const short *Source;
582 unsigned char *Dest;
584 for (z = 0; z < depth; z++)
586 for (y = 0; y < height; y++)
588 Source = (const short *)(src + z * src_slice_pitch + y * src_row_pitch);
589 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
590 for (x = 0; x < width; x++ )
592 const short color = (*Source++);
593 /* B */ Dest[0] = 0xff;
594 /* G */ Dest[1] = (color >> 8) + 128; /* V */
595 /* R */ Dest[2] = (color & 0xff) + 128; /* U */
596 Dest += 3;
602 static void convert_r8g8_snorm_l8x8_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
603 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
605 unsigned int x, y, z;
606 const DWORD *Source;
607 unsigned char *Dest;
609 /* Doesn't work correctly with the fixed function pipeline, but can work in
610 * shaders if the shader is adjusted. (There's no use for this format in gl's
611 * standard fixed function pipeline anyway).
613 for (z = 0; z < depth; z++)
615 for (y = 0; y < height; y++)
617 Source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
618 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
619 for (x = 0; x < width; x++ )
621 LONG color = (*Source++);
622 /* B */ Dest[0] = ((color >> 16) & 0xff); /* L */
623 /* G */ Dest[1] = ((color >> 8 ) & 0xff) + 128; /* V */
624 /* R */ Dest[2] = (color & 0xff) + 128; /* U */
625 Dest += 4;
631 static void convert_r8g8_snorm_l8x8_unorm_nv(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
632 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
634 unsigned int x, y, z;
635 const DWORD *Source;
636 unsigned char *Dest;
638 /* This implementation works with the fixed function pipeline and shaders
639 * without further modification after converting the surface.
641 for (z = 0; z < depth; z++)
643 for (y = 0; y < height; y++)
645 Source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
646 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
647 for (x = 0; x < width; x++ )
649 LONG color = (*Source++);
650 /* L */ Dest[2] = ((color >> 16) & 0xff); /* L */
651 /* V */ Dest[1] = ((color >> 8 ) & 0xff); /* V */
652 /* U */ Dest[0] = (color & 0xff); /* U */
653 /* I */ Dest[3] = 255; /* X */
654 Dest += 4;
660 static void convert_r8g8b8a8_snorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
661 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
663 unsigned int x, y, z;
664 const DWORD *Source;
665 unsigned char *Dest;
667 for (z = 0; z < depth; z++)
669 for (y = 0; y < height; y++)
671 Source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
672 Dest = dst + z * dst_slice_pitch + y * dst_row_pitch;
673 for (x = 0; x < width; x++ )
675 LONG color = (*Source++);
676 /* B */ Dest[0] = ((color >> 16) & 0xff) + 128; /* W */
677 /* G */ Dest[1] = ((color >> 8 ) & 0xff) + 128; /* V */
678 /* R */ Dest[2] = (color & 0xff) + 128; /* U */
679 /* A */ Dest[3] = ((color >> 24) & 0xff) + 128; /* Q */
680 Dest += 4;
686 static void convert_r16g16_snorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
687 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
689 unsigned int x, y, z;
690 const DWORD *Source;
691 unsigned short *Dest;
693 for (z = 0; z < depth; z++)
695 for (y = 0; y < height; y++)
697 Source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
698 Dest = (unsigned short *) (dst + z * dst_slice_pitch + y * dst_row_pitch);
699 for (x = 0; x < width; x++ )
701 const DWORD color = (*Source++);
702 /* B */ Dest[0] = 0xffff;
703 /* G */ Dest[1] = (color >> 16) + 32768; /* V */
704 /* R */ Dest[2] = (color & 0xffff) + 32768; /* U */
705 Dest += 3;
711 static void convert_r16g16(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
712 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
714 unsigned int x, y, z;
715 const WORD *Source;
716 WORD *Dest;
718 for (z = 0; z < depth; z++)
720 for (y = 0; y < height; y++)
722 Source = (const WORD *)(src + z * src_slice_pitch + y * src_row_pitch);
723 Dest = (WORD *) (dst + z * dst_slice_pitch + y * dst_row_pitch);
724 for (x = 0; x < width; x++ )
726 WORD green = (*Source++);
727 WORD red = (*Source++);
728 Dest[0] = green;
729 Dest[1] = red;
730 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
731 * shader overwrites it anyway */
732 Dest[2] = 0xffff;
733 Dest += 3;
739 static void convert_r32g32_float(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
740 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
742 unsigned int x, y, z;
743 const float *Source;
744 float *Dest;
746 for (z = 0; z < depth; z++)
748 for (y = 0; y < height; y++)
750 Source = (const float *)(src + z * src_slice_pitch + y * src_row_pitch);
751 Dest = (float *) (dst + z * dst_slice_pitch + y * dst_row_pitch);
752 for (x = 0; x < width; x++ )
754 float green = (*Source++);
755 float red = (*Source++);
756 Dest[0] = green;
757 Dest[1] = red;
758 Dest[2] = 1.0f;
759 Dest += 3;
765 static void convert_s1_uint_d15_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
766 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
768 unsigned int x, y, z;
770 for (z = 0; z < depth; z++)
772 for (y = 0; y < height; ++y)
774 const WORD *source = (const WORD *)(src + z * src_slice_pitch + y * src_row_pitch);
775 DWORD *dest = (DWORD *)(dst + z * dst_slice_pitch + y * dst_row_pitch);
777 for (x = 0; x < width; ++x)
779 /* The depth data is normalized, so needs to be scaled,
780 * the stencil data isn't. Scale depth data by
781 * (2^24-1)/(2^15-1) ~~ (2^9 + 2^-6). */
782 WORD d15 = source[x] >> 1;
783 DWORD d24 = (d15 << 9) + (d15 >> 6);
784 dest[x] = (d24 << 8) | (source[x] & 0x1);
790 static void convert_s4x4_uint_d24_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
791 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
793 unsigned int x, y, z;
795 for (z = 0; z < depth; z++)
797 for (y = 0; y < height; ++y)
799 const DWORD *source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
800 DWORD *dest = (DWORD *)(dst + z * dst_slice_pitch + y * dst_row_pitch);
802 for (x = 0; x < width; ++x)
804 /* Just need to clear out the X4 part. */
805 dest[x] = source[x] & ~0xf0;
811 static void convert_s8_uint_d24_float(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
812 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
814 unsigned int x, y, z;
816 for (z = 0; z < depth; z++)
818 for (y = 0; y < height; ++y)
820 const DWORD *source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
821 float *dest_f = (float *)(dst + z * dst_slice_pitch + y * dst_row_pitch);
822 DWORD *dest_s = (DWORD *)dest_f;
824 for (x = 0; x < width; ++x)
826 dest_f[x * 2] = float_24_to_32((source[x] & 0xffffff00u) >> 8);
827 dest_s[x * 2 + 1] = source[x] & 0xff;
833 static void convert_x8_d24_unorm(const BYTE *src, BYTE *dst, UINT src_row_pitch, UINT src_slice_pitch,
834 UINT dst_row_pitch, UINT dst_slice_pitch, UINT width, UINT height, UINT depth)
836 unsigned int x, y, z;
838 for (z = 0; z < depth; ++z)
840 for (y = 0; y < height; ++y)
842 const DWORD *source = (const DWORD *)(src + z * src_slice_pitch + y * src_row_pitch);
843 DWORD *dest = (DWORD *)(dst + z * dst_slice_pitch + y * dst_row_pitch);
845 for (x = 0; x < width; ++x)
847 dest[x] = source[x] << 8 | source[x] >> 16;
853 static BOOL color_in_range(const struct wined3d_color_key *color_key, DWORD color)
855 /* FIXME: Is this really how color keys are supposed to work? I think it
856 * makes more sense to compare the individual channels. */
857 return color >= color_key->color_space_low_value
858 && color <= color_key->color_space_high_value;
861 static void convert_p8_uint_b8g8r8a8_unorm(const BYTE *src, unsigned int src_pitch,
862 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
863 const struct wined3d_palette *palette, const struct wined3d_color_key *color_key)
865 const BYTE *src_row;
866 unsigned int x, y;
867 DWORD *dst_row;
869 if (!palette)
871 /* FIXME: This should probably use the system palette. */
872 FIXME("P8 surface loaded without a palette.\n");
874 for (y = 0; y < height; ++y)
876 memset(&dst[dst_pitch * y], 0, width * 4);
879 return;
882 for (y = 0; y < height; ++y)
884 src_row = &src[src_pitch * y];
885 dst_row = (DWORD *)&dst[dst_pitch * y];
886 for (x = 0; x < width; ++x)
888 BYTE src_color = src_row[x];
889 dst_row[x] = 0xff000000
890 | (palette->colors[src_color].rgbRed << 16)
891 | (palette->colors[src_color].rgbGreen << 8)
892 | palette->colors[src_color].rgbBlue;
897 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(const BYTE *src, unsigned int src_pitch,
898 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
899 const struct wined3d_palette *palette, const struct wined3d_color_key *color_key)
901 const WORD *src_row;
902 unsigned int x, y;
903 WORD *dst_row;
905 for (y = 0; y < height; ++y)
907 src_row = (WORD *)&src[src_pitch * y];
908 dst_row = (WORD *)&dst[dst_pitch * y];
909 for (x = 0; x < width; ++x)
911 WORD src_color = src_row[x];
912 if (!color_in_range(color_key, src_color))
913 dst_row[x] = 0x8000u | ((src_color & 0xffc0u) >> 1) | (src_color & 0x1fu);
914 else
915 dst_row[x] = ((src_color & 0xffc0u) >> 1) | (src_color & 0x1fu);
920 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(const BYTE *src, unsigned int src_pitch,
921 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
922 const struct wined3d_palette *palette, const struct wined3d_color_key *color_key)
924 const WORD *src_row;
925 unsigned int x, y;
926 WORD *dst_row;
928 for (y = 0; y < height; ++y)
930 src_row = (WORD *)&src[src_pitch * y];
931 dst_row = (WORD *)&dst[dst_pitch * y];
932 for (x = 0; x < width; ++x)
934 WORD src_color = src_row[x];
935 if (color_in_range(color_key, src_color))
936 dst_row[x] = src_color & ~0x8000;
937 else
938 dst_row[x] = src_color | 0x8000;
943 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE *src, unsigned int src_pitch,
944 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
945 const struct wined3d_palette *palette, const struct wined3d_color_key *color_key)
947 const BYTE *src_row;
948 unsigned int x, y;
949 DWORD *dst_row;
951 for (y = 0; y < height; ++y)
953 src_row = &src[src_pitch * y];
954 dst_row = (DWORD *)&dst[dst_pitch * y];
955 for (x = 0; x < width; ++x)
957 DWORD src_color = (src_row[x * 3 + 2] << 16) | (src_row[x * 3 + 1] << 8) | src_row[x * 3];
958 if (!color_in_range(color_key, src_color))
959 dst_row[x] = src_color | 0xff000000;
964 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE *src, unsigned int src_pitch,
965 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
966 const struct wined3d_palette *palette, const struct wined3d_color_key *color_key)
968 const DWORD *src_row;
969 unsigned int x, y;
970 DWORD *dst_row;
972 for (y = 0; y < height; ++y)
974 src_row = (DWORD *)&src[src_pitch * y];
975 dst_row = (DWORD *)&dst[dst_pitch * y];
976 for (x = 0; x < width; ++x)
978 DWORD src_color = src_row[x];
979 if (color_in_range(color_key, src_color))
980 dst_row[x] = src_color & ~0xff000000;
981 else
982 dst_row[x] = src_color | 0xff000000;
987 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE *src, unsigned int src_pitch,
988 BYTE *dst, unsigned int dst_pitch, unsigned int width, unsigned int height,
989 const struct wined3d_palette *palette, const struct wined3d_color_key *color_key)
991 const DWORD *src_row;
992 unsigned int x, y;
993 DWORD *dst_row;
995 for (y = 0; y < height; ++y)
997 src_row = (DWORD *)&src[src_pitch * y];
998 dst_row = (DWORD *)&dst[dst_pitch * y];
999 for (x = 0; x < width; ++x)
1001 DWORD src_color = src_row[x];
1002 if (color_in_range(color_key, src_color))
1003 src_color &= ~0xff000000;
1004 dst_row[x] = src_color;
1009 const struct wined3d_color_key_conversion * wined3d_format_get_color_key_conversion(
1010 const struct wined3d_texture *texture, BOOL need_alpha_ck)
1012 const struct wined3d_format *format = texture->resource.format;
1013 unsigned int i;
1015 static const struct
1017 enum wined3d_format_id src_format;
1018 struct wined3d_color_key_conversion conversion;
1020 color_key_info[] =
1022 {WINED3DFMT_B5G6R5_UNORM, {WINED3DFMT_B5G5R5A1_UNORM, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key }},
1023 {WINED3DFMT_B5G5R5X1_UNORM, {WINED3DFMT_B5G5R5A1_UNORM, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key }},
1024 {WINED3DFMT_B8G8R8_UNORM, {WINED3DFMT_B8G8R8A8_UNORM, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key }},
1025 {WINED3DFMT_B8G8R8X8_UNORM, {WINED3DFMT_B8G8R8A8_UNORM, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key }},
1026 {WINED3DFMT_B8G8R8A8_UNORM, {WINED3DFMT_B8G8R8A8_UNORM, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key }},
1028 static const struct wined3d_color_key_conversion convert_p8 =
1030 WINED3DFMT_B8G8R8A8_UNORM, convert_p8_uint_b8g8r8a8_unorm
1033 if (need_alpha_ck && (texture->async.flags & WINED3D_TEXTURE_ASYNC_COLOR_KEY))
1035 for (i = 0; i < ARRAY_SIZE(color_key_info); ++i)
1037 if (color_key_info[i].src_format == format->id)
1038 return &color_key_info[i].conversion;
1041 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format->id));
1044 /* FIXME: This should check if the blitter backend can do P8 conversion,
1045 * instead of checking for ARB_fragment_program. */
1046 if (format->id == WINED3DFMT_P8_UINT
1047 && !(texture->resource.device->adapter->gl_info.supported[ARB_FRAGMENT_PROGRAM]
1048 && texture->swapchain && texture == texture->swapchain->front_buffer))
1049 return &convert_p8;
1051 return NULL;
1054 /* The following formats explicitly don't have WINED3DFMT_FLAG_TEXTURE set:
1056 * These are never supported on native.
1057 * WINED3DFMT_B8G8R8_UNORM
1058 * WINED3DFMT_B2G3R3_UNORM
1059 * WINED3DFMT_L4A4_UNORM
1060 * WINED3DFMT_S1_UINT_D15_UNORM
1061 * WINED3DFMT_S4X4_UINT_D24_UNORM
1063 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
1064 * Since it is not widely available, don't offer it. Further no Windows driver
1065 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
1066 * WINED3DFMT_P8_UINT
1067 * WINED3DFMT_P8_UINT_A8_UNORM
1069 * These formats seem to be similar to the HILO formats in
1070 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
1071 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
1072 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
1073 * refused to support formats which can easily be emulated with pixel shaders,
1074 * so applications have to deal with not having NVHS and NVHU.
1075 * WINED3DFMT_NVHU
1076 * WINED3DFMT_NVHS */
1077 static const struct wined3d_format_texture_info format_texture_info[] =
1079 /* format id gl_internal gl_srgb_internal gl_rt_internal
1080 gl_format gl_type conv_byte_count
1081 flags
1082 extension convert */
1083 /* FourCC formats */
1084 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
1085 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
1086 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
1087 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
1088 * endian machine
1090 {WINED3DFMT_UYVY, GL_RG8, GL_RG8, 0,
1091 GL_RG, GL_UNSIGNED_BYTE, 0,
1092 WINED3DFMT_FLAG_FILTERING,
1093 ARB_TEXTURE_RG, NULL},
1094 {WINED3DFMT_UYVY, GL_LUMINANCE8_ALPHA8, GL_LUMINANCE8_ALPHA8, 0,
1095 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1096 WINED3DFMT_FLAG_FILTERING,
1097 WINED3D_GL_LEGACY_CONTEXT, NULL},
1098 {WINED3DFMT_UYVY, GL_RGB, GL_RGB, 0,
1099 GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, 0,
1100 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_FILTERING,
1101 APPLE_YCBCR_422, NULL},
1102 {WINED3DFMT_YUY2, GL_RG8, GL_RG8, 0,
1103 GL_RG, GL_UNSIGNED_BYTE, 0,
1104 WINED3DFMT_FLAG_FILTERING,
1105 ARB_TEXTURE_RG, NULL},
1106 {WINED3DFMT_YUY2, GL_LUMINANCE8_ALPHA8, GL_LUMINANCE8_ALPHA8, 0,
1107 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1108 WINED3DFMT_FLAG_FILTERING,
1109 WINED3D_GL_LEGACY_CONTEXT, NULL},
1110 {WINED3DFMT_YUY2, GL_RGB, GL_RGB, 0,
1111 GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, 0,
1112 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_FILTERING,
1113 APPLE_YCBCR_422, NULL},
1114 {WINED3DFMT_YV12, GL_R8, GL_R8, 0,
1115 GL_RED, GL_UNSIGNED_BYTE, 0,
1116 WINED3DFMT_FLAG_FILTERING,
1117 ARB_TEXTURE_RG, NULL},
1118 {WINED3DFMT_YV12, GL_ALPHA8, GL_ALPHA8, 0,
1119 GL_ALPHA, GL_UNSIGNED_BYTE, 0,
1120 WINED3DFMT_FLAG_FILTERING,
1121 WINED3D_GL_LEGACY_CONTEXT, NULL},
1122 {WINED3DFMT_NV12, GL_R8, GL_R8, 0,
1123 GL_RED, GL_UNSIGNED_BYTE, 0,
1124 WINED3DFMT_FLAG_FILTERING,
1125 ARB_TEXTURE_RG, NULL},
1126 {WINED3DFMT_NV12, GL_ALPHA8, GL_ALPHA8, 0,
1127 GL_ALPHA, GL_UNSIGNED_BYTE, 0,
1128 WINED3DFMT_FLAG_FILTERING,
1129 WINED3D_GL_LEGACY_CONTEXT, NULL},
1130 {WINED3DFMT_DXT1, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 0,
1131 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1132 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1133 | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_COMPRESSED,
1134 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1135 {WINED3DFMT_DXT2, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0,
1136 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1137 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1138 | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_COMPRESSED,
1139 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1140 {WINED3DFMT_DXT3, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0,
1141 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1142 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1143 | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_COMPRESSED,
1144 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1145 {WINED3DFMT_DXT4, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0,
1146 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1147 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1148 | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_COMPRESSED,
1149 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1150 {WINED3DFMT_DXT5, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0,
1151 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1152 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1153 | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_COMPRESSED,
1154 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1155 {WINED3DFMT_BC1_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 0,
1156 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1157 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1158 | WINED3DFMT_FLAG_COMPRESSED,
1159 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1160 {WINED3DFMT_BC2_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0,
1161 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1162 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1163 | WINED3DFMT_FLAG_COMPRESSED,
1164 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1165 {WINED3DFMT_BC3_UNORM, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0,
1166 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1167 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1168 | WINED3DFMT_FLAG_COMPRESSED,
1169 EXT_TEXTURE_COMPRESSION_S3TC, NULL},
1170 {WINED3DFMT_BC4_UNORM, GL_COMPRESSED_RED_RGTC1, GL_COMPRESSED_RED_RGTC1, 0,
1171 GL_RED, GL_UNSIGNED_BYTE, 0,
1172 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1173 | WINED3DFMT_FLAG_COMPRESSED,
1174 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1175 {WINED3DFMT_BC5_UNORM, GL_COMPRESSED_RG_RGTC2, GL_COMPRESSED_RG_RGTC2, 0,
1176 GL_RG, GL_UNSIGNED_BYTE, 0,
1177 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1178 | WINED3DFMT_FLAG_COMPRESSED,
1179 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1180 {WINED3DFMT_BC5_SNORM, GL_COMPRESSED_SIGNED_RG_RGTC2, GL_COMPRESSED_SIGNED_RG_RGTC2, 0,
1181 GL_RG, GL_UNSIGNED_BYTE, 0,
1182 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1183 | WINED3DFMT_FLAG_COMPRESSED,
1184 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1185 {WINED3DFMT_BC6H_UF16, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB, 0,
1186 GL_RGB, GL_UNSIGNED_BYTE, 0,
1187 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1188 | WINED3DFMT_FLAG_COMPRESSED,
1189 ARB_TEXTURE_COMPRESSION_BPTC, NULL},
1190 {WINED3DFMT_BC6H_SF16, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB, 0,
1191 GL_RGB, GL_UNSIGNED_BYTE, 0,
1192 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1193 | WINED3DFMT_FLAG_COMPRESSED,
1194 ARB_TEXTURE_COMPRESSION_BPTC, NULL},
1195 {WINED3DFMT_BC7_UNORM, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB, 0,
1196 GL_RGBA, GL_UNSIGNED_BYTE, 0,
1197 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1198 | WINED3DFMT_FLAG_COMPRESSED,
1199 ARB_TEXTURE_COMPRESSION_BPTC, NULL},
1200 /* IEEE formats */
1201 {WINED3DFMT_R32_FLOAT, GL_RGB32F_ARB, GL_RGB32F_ARB, 0,
1202 GL_RED, GL_FLOAT, 0,
1203 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1204 ARB_TEXTURE_FLOAT, NULL},
1205 {WINED3DFMT_R32_FLOAT, GL_R32F, GL_R32F, 0,
1206 GL_RED, GL_FLOAT, 0,
1207 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1208 ARB_TEXTURE_RG, NULL},
1209 {WINED3DFMT_R32G32_FLOAT, GL_RGB32F_ARB, GL_RGB32F_ARB, 0,
1210 GL_RGB, GL_FLOAT, 12,
1211 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1212 ARB_TEXTURE_FLOAT, convert_r32g32_float},
1213 {WINED3DFMT_R32G32_FLOAT, GL_RG32F, GL_RG32F, 0,
1214 GL_RG, GL_FLOAT, 0,
1215 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1216 ARB_TEXTURE_RG, NULL},
1217 {WINED3DFMT_R32G32B32_FLOAT, GL_RGB32F, GL_RGB32F, 0,
1218 GL_RGB, GL_FLOAT, 0,
1219 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1220 ARB_TEXTURE_FLOAT, NULL},
1221 {WINED3DFMT_R32G32B32A32_FLOAT, GL_RGBA32F_ARB, GL_RGBA32F_ARB, 0,
1222 GL_RGBA, GL_FLOAT, 0,
1223 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1224 ARB_TEXTURE_FLOAT, NULL},
1225 /* Float */
1226 {WINED3DFMT_R16_FLOAT, GL_RGB16F_ARB, GL_RGB16F_ARB, 0,
1227 GL_RED, GL_HALF_FLOAT_ARB, 0,
1228 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1229 ARB_TEXTURE_FLOAT, NULL},
1230 {WINED3DFMT_R16_FLOAT, GL_R16F, GL_R16F, 0,
1231 GL_RED, GL_HALF_FLOAT_ARB, 0,
1232 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1233 ARB_TEXTURE_RG, NULL},
1234 {WINED3DFMT_R16G16_FLOAT, GL_RGB16F_ARB, GL_RGB16F_ARB, 0,
1235 GL_RGB, GL_HALF_FLOAT_ARB, 6,
1236 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1237 ARB_TEXTURE_FLOAT, convert_r16g16},
1238 {WINED3DFMT_R16G16_FLOAT, GL_RG16F, GL_RG16F, 0,
1239 GL_RG, GL_HALF_FLOAT_ARB, 0,
1240 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1241 ARB_TEXTURE_RG, NULL},
1242 {WINED3DFMT_R16G16B16A16_FLOAT, GL_RGBA16F_ARB, GL_RGBA16F_ARB, 0,
1243 GL_RGBA, GL_HALF_FLOAT_ARB, 0,
1244 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_RENDERTARGET
1245 | WINED3DFMT_FLAG_VTF,
1246 ARB_TEXTURE_FLOAT, NULL},
1247 {WINED3DFMT_R11G11B10_FLOAT, GL_R11F_G11F_B10F, GL_R11F_G11F_B10F, 0,
1248 GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, 0,
1249 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_RENDERTARGET,
1250 EXT_PACKED_FLOAT},
1251 /* Palettized formats */
1252 {WINED3DFMT_P8_UINT, GL_R8, GL_R8, 0,
1253 GL_RED, GL_UNSIGNED_BYTE, 0,
1255 ARB_TEXTURE_RG, NULL},
1256 {WINED3DFMT_P8_UINT, GL_ALPHA8, GL_ALPHA8, 0,
1257 GL_ALPHA, GL_UNSIGNED_BYTE, 0,
1259 WINED3D_GL_LEGACY_CONTEXT, NULL},
1260 /* Standard ARGB formats */
1261 {WINED3DFMT_B8G8R8_UNORM, GL_RGB8, GL_RGB8, 0,
1262 GL_BGR, GL_UNSIGNED_BYTE, 0,
1263 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET,
1264 WINED3D_GL_EXT_NONE, NULL},
1265 {WINED3DFMT_B8G8R8A8_UNORM, GL_RGBA8, GL_SRGB8_ALPHA8_EXT, 0,
1266 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1267 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1268 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE
1269 | WINED3DFMT_FLAG_VTF,
1270 WINED3D_GL_EXT_NONE, NULL},
1271 {WINED3DFMT_B8G8R8X8_UNORM, GL_RGB8, GL_SRGB8_EXT, 0,
1272 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1273 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1274 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE,
1275 WINED3D_GL_EXT_NONE, NULL},
1276 {WINED3DFMT_B5G6R5_UNORM, GL_RGB5, GL_RGB5, GL_RGB8,
1277 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0,
1278 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1279 | WINED3DFMT_FLAG_RENDERTARGET,
1280 WINED3D_GL_EXT_NONE, NULL},
1281 {WINED3DFMT_B5G6R5_UNORM, GL_RGB565, GL_RGB565, GL_RGB8,
1282 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 0,
1283 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1284 | WINED3DFMT_FLAG_RENDERTARGET,
1285 ARB_ES2_COMPATIBILITY, NULL},
1286 {WINED3DFMT_B5G5R5X1_UNORM, GL_RGB5, GL_RGB5, 0,
1287 GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 0,
1288 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1289 | WINED3DFMT_FLAG_RENDERTARGET,
1290 WINED3D_GL_EXT_NONE, NULL},
1291 {WINED3DFMT_B5G5R5A1_UNORM, GL_RGB5_A1, GL_RGB5_A1, 0,
1292 GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV, 0,
1293 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1294 WINED3D_GL_EXT_NONE, NULL},
1295 {WINED3DFMT_B4G4R4A4_UNORM, GL_RGBA4, GL_SRGB8_ALPHA8_EXT, 0,
1296 GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, 0,
1297 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1298 | WINED3DFMT_FLAG_SRGB_READ,
1299 WINED3D_GL_EXT_NONE, NULL},
1300 {WINED3DFMT_B2G3R3_UNORM, GL_R3_G3_B2, GL_R3_G3_B2, 0,
1301 GL_RGB, GL_UNSIGNED_BYTE_3_3_2, 0,
1302 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1303 WINED3D_GL_EXT_NONE, NULL},
1304 {WINED3DFMT_R8_UNORM, GL_R8, GL_R8, 0,
1305 GL_RED, GL_UNSIGNED_BYTE, 0,
1306 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1307 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_VTF,
1308 ARB_TEXTURE_RG, NULL},
1309 {WINED3DFMT_A8_UNORM, GL_R8, GL_R8, 0,
1310 GL_RED, GL_UNSIGNED_BYTE, 0,
1311 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1312 ARB_TEXTURE_RG, NULL},
1313 {WINED3DFMT_A8_UNORM, GL_ALPHA8, GL_ALPHA8, 0,
1314 GL_ALPHA, GL_UNSIGNED_BYTE, 0,
1315 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1316 WINED3D_GL_LEGACY_CONTEXT, NULL},
1317 {WINED3DFMT_B4G4R4X4_UNORM, GL_RGB4, GL_RGB4, 0,
1318 GL_BGRA, GL_UNSIGNED_SHORT_4_4_4_4_REV, 0,
1319 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1320 WINED3D_GL_EXT_NONE, NULL},
1321 {WINED3DFMT_R10G10B10A2_UNORM, GL_RGB10_A2, GL_RGB10_A2, 0,
1322 GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, 0,
1323 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1324 | WINED3DFMT_FLAG_RENDERTARGET,
1325 WINED3D_GL_EXT_NONE, NULL},
1326 {WINED3DFMT_R8G8B8A8_UNORM, GL_RGBA8, GL_SRGB8_ALPHA8_EXT, 0,
1327 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1328 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1329 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE
1330 | WINED3DFMT_FLAG_VTF,
1331 WINED3D_GL_EXT_NONE, NULL},
1332 {WINED3DFMT_R8G8B8A8_UINT, GL_RGBA8UI, GL_RGBA8UI, 0,
1333 GL_RGBA_INTEGER, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1334 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1335 ARB_TEXTURE_RGB10_A2UI, NULL},
1336 {WINED3DFMT_R8G8B8A8_SINT, GL_RGBA8I, GL_RGBA8I, 0,
1337 GL_RGBA_INTEGER, GL_BYTE, 0,
1338 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1339 EXT_TEXTURE_INTEGER, NULL},
1340 {WINED3DFMT_R8G8B8X8_UNORM, GL_RGB8, GL_RGB8, 0,
1341 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1342 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1343 WINED3D_GL_EXT_NONE, NULL},
1344 {WINED3DFMT_R16G16_UNORM, GL_RGB16, GL_RGB16, GL_RGBA16,
1345 GL_RGB, GL_UNSIGNED_SHORT, 6,
1346 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1347 WINED3D_GL_EXT_NONE, convert_r16g16},
1348 {WINED3DFMT_R16G16_UNORM, GL_RG16, GL_RG16, 0,
1349 GL_RG, GL_UNSIGNED_SHORT, 0,
1350 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1351 | WINED3DFMT_FLAG_RENDERTARGET,
1352 ARB_TEXTURE_RG, NULL},
1353 {WINED3DFMT_B10G10R10A2_UNORM, GL_RGB10_A2, GL_RGB10_A2, 0,
1354 GL_BGRA, GL_UNSIGNED_INT_2_10_10_10_REV, 0,
1355 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1356 | WINED3DFMT_FLAG_RENDERTARGET,
1357 WINED3D_GL_EXT_NONE, NULL},
1358 {WINED3DFMT_R16G16B16A16_UNORM, GL_RGBA16, GL_RGBA16, 0,
1359 GL_RGBA, GL_UNSIGNED_SHORT, 0,
1360 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1361 | WINED3DFMT_FLAG_RENDERTARGET,
1362 WINED3D_GL_EXT_NONE, NULL},
1363 {WINED3DFMT_R8G8_UNORM, GL_RG8, GL_RG8, 0,
1364 GL_RG, GL_UNSIGNED_BYTE, 0,
1365 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1366 | WINED3DFMT_FLAG_RENDERTARGET,
1367 ARB_TEXTURE_RG, NULL},
1368 {WINED3DFMT_R8G8_UINT, GL_RG8UI, GL_RG8UI, 0,
1369 GL_RG_INTEGER, GL_UNSIGNED_BYTE, 0,
1370 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1371 ARB_TEXTURE_RG, NULL},
1372 {WINED3DFMT_R8G8_SINT, GL_RG8I, GL_RG8I, 0,
1373 GL_RG_INTEGER, GL_BYTE, 0,
1374 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1375 ARB_TEXTURE_RG, NULL},
1376 {WINED3DFMT_R16G16B16A16_UINT, GL_RGBA16UI, GL_RGBA16UI, 0,
1377 GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, 0,
1378 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1379 EXT_TEXTURE_INTEGER, NULL},
1380 {WINED3DFMT_R16G16B16A16_SINT, GL_RGBA16I, GL_RGBA16I, 0,
1381 GL_RGBA_INTEGER, GL_SHORT, 0,
1382 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1383 EXT_TEXTURE_INTEGER, NULL},
1384 {WINED3DFMT_R32G32_UINT, GL_RG32UI, GL_RG32UI, 0,
1385 GL_RG_INTEGER, GL_UNSIGNED_INT, 0,
1386 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1387 ARB_TEXTURE_RG, NULL},
1388 {WINED3DFMT_R32G32_SINT, GL_RG32I, GL_RG32I, 0,
1389 GL_RG_INTEGER, GL_INT, 0,
1390 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1391 ARB_TEXTURE_RG, NULL},
1392 {WINED3DFMT_R16G16_UINT, GL_RG16UI, GL_RG16UI, 0,
1393 GL_RG_INTEGER, GL_UNSIGNED_SHORT, 0,
1394 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1395 ARB_TEXTURE_RG, NULL},
1396 {WINED3DFMT_R16G16_SINT, GL_RG16I, GL_RG16I, 0,
1397 GL_RG_INTEGER, GL_SHORT, 0,
1398 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1399 ARB_TEXTURE_RG, NULL},
1400 {WINED3DFMT_R32_UINT, GL_R32UI, GL_R32UI, 0,
1401 GL_RED_INTEGER, GL_UNSIGNED_INT, 0,
1402 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1403 ARB_TEXTURE_RG, NULL},
1404 {WINED3DFMT_R32_SINT, GL_R32I, GL_R32I, 0,
1405 GL_RED_INTEGER, GL_INT, 0,
1406 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1407 ARB_TEXTURE_RG, NULL},
1408 {WINED3DFMT_R16_UNORM, GL_R16, GL_R16, 0,
1409 GL_RED, GL_UNSIGNED_SHORT, 0,
1410 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1411 | WINED3DFMT_FLAG_RENDERTARGET,
1412 ARB_TEXTURE_RG, NULL},
1413 {WINED3DFMT_R16_UINT, GL_R16UI, GL_R16UI, 0,
1414 GL_RED_INTEGER, GL_UNSIGNED_SHORT, 0,
1415 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1416 ARB_TEXTURE_RG, NULL},
1417 {WINED3DFMT_R16_SINT, GL_R16I, GL_R16I, 0,
1418 GL_RED_INTEGER, GL_SHORT, 0,
1419 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1420 ARB_TEXTURE_RG, NULL},
1421 {WINED3DFMT_R8_UINT, GL_R8UI, GL_R8UI, 0,
1422 GL_RED_INTEGER, GL_UNSIGNED_BYTE, 0,
1423 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1424 ARB_TEXTURE_RG, NULL},
1425 {WINED3DFMT_R8_SINT, GL_R8I, GL_R8I, 0,
1426 GL_RED_INTEGER, GL_BYTE, 0,
1427 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1428 ARB_TEXTURE_RG, NULL},
1429 /* Luminance */
1430 {WINED3DFMT_L8_UNORM, GL_LUMINANCE8, GL_SLUMINANCE8_EXT, 0,
1431 GL_LUMINANCE, GL_UNSIGNED_BYTE, 0,
1432 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1433 | WINED3DFMT_FLAG_SRGB_READ,
1434 WINED3D_GL_LEGACY_CONTEXT, NULL},
1435 {WINED3DFMT_L8_UNORM, GL_R8, GL_R8, 0,
1436 GL_RED, GL_UNSIGNED_BYTE, 0,
1437 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1438 | WINED3DFMT_FLAG_RENDERTARGET,
1439 ARB_TEXTURE_RG, NULL},
1440 {WINED3DFMT_L8A8_UNORM, GL_RG8, GL_RG8, 0,
1441 GL_RG, GL_UNSIGNED_BYTE, 0,
1442 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1443 ARB_TEXTURE_RG, NULL},
1444 {WINED3DFMT_L8A8_UNORM, GL_LUMINANCE8_ALPHA8, GL_SLUMINANCE8_ALPHA8_EXT, 0,
1445 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1446 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1447 | WINED3DFMT_FLAG_SRGB_READ,
1448 WINED3D_GL_LEGACY_CONTEXT, NULL},
1449 {WINED3DFMT_L4A4_UNORM, GL_RG8, GL_RG8, 0,
1450 GL_RG, GL_UNSIGNED_BYTE, 2,
1451 WINED3DFMT_FLAG_FILTERING,
1452 ARB_TEXTURE_RG, convert_l4a4_unorm},
1453 {WINED3DFMT_L4A4_UNORM, GL_LUMINANCE4_ALPHA4, GL_LUMINANCE4_ALPHA4, 0,
1454 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 2,
1455 WINED3DFMT_FLAG_FILTERING,
1456 WINED3D_GL_LEGACY_CONTEXT, convert_l4a4_unorm},
1457 {WINED3DFMT_L16_UNORM, GL_R16, GL_R16, 0,
1458 GL_RED, GL_UNSIGNED_SHORT, 0,
1459 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1460 ARB_TEXTURE_RG, NULL},
1461 {WINED3DFMT_L16_UNORM, GL_LUMINANCE16, GL_LUMINANCE16, 0,
1462 GL_LUMINANCE, GL_UNSIGNED_SHORT, 0,
1463 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1464 WINED3D_GL_LEGACY_CONTEXT, NULL},
1465 /* Bump mapping stuff */
1466 {WINED3DFMT_R8G8_SNORM, GL_RGB8, GL_RGB8, 0,
1467 GL_BGR, GL_UNSIGNED_BYTE, 3,
1468 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1469 | WINED3DFMT_FLAG_BUMPMAP,
1470 WINED3D_GL_EXT_NONE, convert_r8g8_snorm},
1471 {WINED3DFMT_R8G8_SNORM, GL_DSDT8_NV, GL_DSDT8_NV, 0,
1472 GL_DSDT_NV, GL_BYTE, 0,
1473 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1474 | WINED3DFMT_FLAG_BUMPMAP,
1475 NV_TEXTURE_SHADER, NULL},
1476 {WINED3DFMT_R8G8_SNORM, GL_RG8_SNORM, GL_RG8_SNORM, 0,
1477 GL_RG, GL_BYTE, 0,
1478 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1479 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_BUMPMAP,
1480 EXT_TEXTURE_SNORM, NULL},
1481 {WINED3DFMT_R5G5_SNORM_L6_UNORM, GL_RGB5, GL_RGB5, 0,
1482 GL_RGB, GL_UNSIGNED_SHORT_5_6_5, 2,
1483 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1484 | WINED3DFMT_FLAG_BUMPMAP,
1485 WINED3D_GL_EXT_NONE, convert_r5g5_snorm_l6_unorm},
1486 {WINED3DFMT_R5G5_SNORM_L6_UNORM, GL_DSDT8_MAG8_NV, GL_DSDT8_MAG8_NV, 0,
1487 GL_DSDT_MAG_NV, GL_BYTE, 3,
1488 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1489 | WINED3DFMT_FLAG_BUMPMAP,
1490 NV_TEXTURE_SHADER, convert_r5g5_snorm_l6_unorm_nv},
1491 {WINED3DFMT_R5G5_SNORM_L6_UNORM, GL_RGB8_SNORM, GL_RGB8_SNORM, 0,
1492 GL_RGBA, GL_BYTE, 4,
1493 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1494 | WINED3DFMT_FLAG_BUMPMAP,
1495 EXT_TEXTURE_SNORM, convert_r5g5_snorm_l6_unorm_ext},
1496 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, GL_RGB8, GL_RGB8, 0,
1497 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 4,
1498 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1499 | WINED3DFMT_FLAG_BUMPMAP,
1500 WINED3D_GL_EXT_NONE, convert_r8g8_snorm_l8x8_unorm},
1501 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM, GL_DSDT8_MAG8_INTENSITY8_NV, GL_DSDT8_MAG8_INTENSITY8_NV, 0,
1502 GL_DSDT_MAG_VIB_NV, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV, 4,
1503 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1504 | WINED3DFMT_FLAG_BUMPMAP,
1505 NV_TEXTURE_SHADER, convert_r8g8_snorm_l8x8_unorm_nv},
1506 {WINED3DFMT_R8G8B8A8_SNORM, GL_RGBA8, GL_RGBA8, 0,
1507 GL_BGRA, GL_UNSIGNED_BYTE, 4,
1508 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1509 | WINED3DFMT_FLAG_BUMPMAP,
1510 WINED3D_GL_EXT_NONE, convert_r8g8b8a8_snorm},
1511 {WINED3DFMT_R8G8B8A8_SNORM, GL_SIGNED_RGBA8_NV, GL_SIGNED_RGBA8_NV, 0,
1512 GL_RGBA, GL_BYTE, 0,
1513 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1514 | WINED3DFMT_FLAG_BUMPMAP,
1515 NV_TEXTURE_SHADER, NULL},
1516 {WINED3DFMT_R8G8B8A8_SNORM, GL_RGBA8_SNORM, GL_RGBA8_SNORM, 0,
1517 GL_RGBA, GL_BYTE, 0,
1518 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1519 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_BUMPMAP,
1520 EXT_TEXTURE_SNORM, NULL},
1521 {WINED3DFMT_R16G16_SNORM, GL_RGB16, GL_RGB16, 0,
1522 GL_BGR, GL_UNSIGNED_SHORT, 6,
1523 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1524 | WINED3DFMT_FLAG_BUMPMAP,
1525 WINED3D_GL_EXT_NONE, convert_r16g16_snorm},
1526 {WINED3DFMT_R16G16_SNORM, GL_SIGNED_HILO16_NV, GL_SIGNED_HILO16_NV, 0,
1527 GL_HILO_NV, GL_SHORT, 0,
1528 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1529 | WINED3DFMT_FLAG_BUMPMAP,
1530 NV_TEXTURE_SHADER, NULL},
1531 {WINED3DFMT_R16G16_SNORM, GL_RG16_SNORM, GL_RG16_SNORM, 0,
1532 GL_RG, GL_SHORT, 0,
1533 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1534 | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_BUMPMAP,
1535 EXT_TEXTURE_SNORM, NULL},
1536 {WINED3DFMT_R16G16B16A16_SNORM, GL_RGBA16_SNORM, GL_RGBA16_SNORM, 0,
1537 GL_RGBA, GL_SHORT, 0,
1538 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1539 | WINED3DFMT_FLAG_RENDERTARGET,
1540 EXT_TEXTURE_SNORM, NULL},
1541 {WINED3DFMT_R16_SNORM, GL_R16_SNORM, GL_R16_SNORM, 0,
1542 GL_RED, GL_SHORT, 0,
1543 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1544 | WINED3DFMT_FLAG_RENDERTARGET,
1545 EXT_TEXTURE_SNORM, NULL},
1546 {WINED3DFMT_R8_SNORM, GL_R8_SNORM, GL_R8_SNORM, 0,
1547 GL_RED, GL_BYTE, 0,
1548 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1549 | WINED3DFMT_FLAG_RENDERTARGET,
1550 EXT_TEXTURE_SNORM, NULL},
1551 /* Depth stencil formats */
1552 {WINED3DFMT_D16_LOCKABLE, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, 0,
1553 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1554 WINED3DFMT_FLAG_DEPTH,
1555 WINED3D_GL_EXT_NONE, NULL},
1556 {WINED3DFMT_D16_LOCKABLE, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1557 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1558 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1559 ARB_DEPTH_TEXTURE, NULL},
1560 {WINED3DFMT_D32_UNORM, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, 0,
1561 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0,
1562 WINED3DFMT_FLAG_DEPTH,
1563 WINED3D_GL_EXT_NONE, NULL},
1564 {WINED3DFMT_D32_UNORM, GL_DEPTH_COMPONENT32_ARB, GL_DEPTH_COMPONENT32_ARB, 0,
1565 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0,
1566 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1567 ARB_DEPTH_TEXTURE, NULL},
1568 {WINED3DFMT_S1_UINT_D15_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1569 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1570 WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1571 ARB_DEPTH_TEXTURE, NULL},
1572 {WINED3DFMT_S1_UINT_D15_UNORM, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH24_STENCIL8_EXT, 0,
1573 GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, 4,
1574 WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1575 EXT_PACKED_DEPTH_STENCIL, convert_s1_uint_d15_unorm},
1576 {WINED3DFMT_S1_UINT_D15_UNORM, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, 0,
1577 GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 4,
1578 WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1579 ARB_FRAMEBUFFER_OBJECT, convert_s1_uint_d15_unorm},
1580 {WINED3DFMT_D24_UNORM_S8_UINT, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1581 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0,
1582 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1583 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1584 ARB_DEPTH_TEXTURE, NULL},
1585 {WINED3DFMT_D24_UNORM_S8_UINT, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH24_STENCIL8_EXT, 0,
1586 GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, 0,
1587 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1588 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1589 EXT_PACKED_DEPTH_STENCIL, NULL},
1590 {WINED3DFMT_D24_UNORM_S8_UINT, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, 0,
1591 GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0,
1592 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1593 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1594 ARB_FRAMEBUFFER_OBJECT, NULL},
1595 {WINED3DFMT_X8D24_UNORM, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, 0,
1596 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 4,
1597 WINED3DFMT_FLAG_DEPTH,
1598 WINED3D_GL_EXT_NONE, convert_x8_d24_unorm},
1599 {WINED3DFMT_X8D24_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1600 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 4,
1601 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1602 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1603 ARB_DEPTH_TEXTURE, convert_x8_d24_unorm},
1604 {WINED3DFMT_S4X4_UINT_D24_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1605 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0,
1606 WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1607 ARB_DEPTH_TEXTURE, NULL},
1608 {WINED3DFMT_S4X4_UINT_D24_UNORM, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH24_STENCIL8_EXT, 0,
1609 GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, 4,
1610 WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1611 EXT_PACKED_DEPTH_STENCIL, convert_s4x4_uint_d24_unorm},
1612 {WINED3DFMT_S4X4_UINT_D24_UNORM, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, 0,
1613 GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 4,
1614 WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1615 ARB_FRAMEBUFFER_OBJECT, convert_s4x4_uint_d24_unorm},
1616 {WINED3DFMT_D16_UNORM, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, 0,
1617 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1618 WINED3DFMT_FLAG_DEPTH,
1619 WINED3D_GL_EXT_NONE, NULL},
1620 {WINED3DFMT_D16_UNORM, GL_DEPTH_COMPONENT24_ARB, GL_DEPTH_COMPONENT24_ARB, 0,
1621 GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, 0,
1622 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1623 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1624 ARB_DEPTH_TEXTURE, NULL},
1625 {WINED3DFMT_D32_FLOAT, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT32F, 0,
1626 GL_DEPTH_COMPONENT, GL_FLOAT, 0,
1627 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_SHADOW,
1628 ARB_DEPTH_BUFFER_FLOAT, NULL},
1629 {WINED3DFMT_D32_FLOAT_S8X24_UINT, GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, 0,
1630 GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, 0,
1631 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1632 ARB_DEPTH_BUFFER_FLOAT, NULL},
1633 {WINED3DFMT_S8_UINT_D24_FLOAT, GL_DEPTH32F_STENCIL8, GL_DEPTH32F_STENCIL8, 0,
1634 GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, 8,
1635 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL | WINED3DFMT_FLAG_SHADOW,
1636 ARB_DEPTH_BUFFER_FLOAT, convert_s8_uint_d24_float},
1637 {WINED3DFMT_R32G32B32A32_UINT, GL_RGBA32UI, GL_RGBA32UI, 0,
1638 GL_RGBA_INTEGER, GL_UNSIGNED_INT, 0,
1639 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1640 EXT_TEXTURE_INTEGER, NULL},
1641 {WINED3DFMT_R32G32B32A32_SINT, GL_RGBA32I, GL_RGBA32I, 0,
1642 GL_RGBA_INTEGER, GL_INT, 0,
1643 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET,
1644 EXT_TEXTURE_INTEGER, NULL},
1645 /* Vendor-specific formats */
1646 {WINED3DFMT_ATI1N, GL_COMPRESSED_RED_RGTC1, GL_COMPRESSED_RED_RGTC1, 0,
1647 GL_RED, GL_UNSIGNED_BYTE, 0,
1648 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1649 | WINED3DFMT_FLAG_COMPRESSED,
1650 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1651 {WINED3DFMT_ATI2N, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, 0,
1652 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1653 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1654 | WINED3DFMT_FLAG_COMPRESSED,
1655 ATI_TEXTURE_COMPRESSION_3DC, NULL},
1656 {WINED3DFMT_ATI2N, GL_COMPRESSED_RG_RGTC2, GL_COMPRESSED_RG_RGTC2, 0,
1657 GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 0,
1658 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1659 | WINED3DFMT_FLAG_COMPRESSED,
1660 EXT_TEXTURE_COMPRESSION_RGTC, NULL},
1661 {WINED3DFMT_ATI2N, GL_COMPRESSED_RG_RGTC2, GL_COMPRESSED_RG_RGTC2, 0,
1662 GL_RG, GL_UNSIGNED_BYTE, 0,
1663 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1664 | WINED3DFMT_FLAG_COMPRESSED,
1665 ARB_TEXTURE_COMPRESSION_RGTC, NULL},
1666 {WINED3DFMT_INTZ, GL_DEPTH24_STENCIL8_EXT, GL_DEPTH24_STENCIL8_EXT, 0,
1667 GL_DEPTH_STENCIL_EXT, GL_UNSIGNED_INT_24_8_EXT, 0,
1668 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1669 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
1670 EXT_PACKED_DEPTH_STENCIL, NULL},
1671 {WINED3DFMT_INTZ, GL_DEPTH24_STENCIL8, GL_DEPTH24_STENCIL8, 0,
1672 GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 0,
1673 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING
1674 | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
1675 ARB_FRAMEBUFFER_OBJECT, NULL},
1676 {WINED3DFMT_NULL, 0, 0, 0,
1677 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, 0,
1678 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_FBO_ATTACHABLE,
1679 ARB_FRAMEBUFFER_OBJECT, NULL},
1680 /* DirectX 10 HDR formats */
1681 {WINED3DFMT_R9G9B9E5_SHAREDEXP, GL_RGB9_E5_EXT, GL_RGB9_E5_EXT, 0,
1682 GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV_EXT, 0,
1683 WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
1684 EXT_TEXTURE_SHARED_EXPONENT, NULL},
1687 struct wined3d_format_srgb_info
1689 enum wined3d_format_id srgb_format_id;
1690 enum wined3d_format_id base_format_id;
1693 static const struct wined3d_format_srgb_info format_srgb_info[] =
1695 {WINED3DFMT_R8G8B8A8_UNORM_SRGB, WINED3DFMT_R8G8B8A8_UNORM},
1696 {WINED3DFMT_BC1_UNORM_SRGB, WINED3DFMT_BC1_UNORM},
1697 {WINED3DFMT_BC2_UNORM_SRGB, WINED3DFMT_BC2_UNORM},
1698 {WINED3DFMT_BC3_UNORM_SRGB, WINED3DFMT_BC3_UNORM},
1699 {WINED3DFMT_B8G8R8A8_UNORM_SRGB, WINED3DFMT_B8G8R8A8_UNORM},
1700 {WINED3DFMT_B8G8R8X8_UNORM_SRGB, WINED3DFMT_B8G8R8X8_UNORM},
1701 {WINED3DFMT_BC7_UNORM_SRGB, WINED3DFMT_BC7_UNORM},
1704 static inline int get_format_idx(enum wined3d_format_id format_id)
1706 unsigned int i;
1708 if (format_id < WINED3D_FORMAT_FOURCC_BASE)
1709 return format_id;
1711 for (i = 0; i < ARRAY_SIZE(format_index_remap); ++i)
1713 if (format_index_remap[i].id == format_id)
1714 return format_index_remap[i].idx;
1717 return -1;
1720 static struct wined3d_format *get_format_internal(struct wined3d_gl_info *gl_info,
1721 enum wined3d_format_id format_id)
1723 int fmt_idx;
1725 if ((fmt_idx = get_format_idx(format_id)) == -1)
1727 ERR("Format %s (%#x) not found.\n", debug_d3dformat(format_id), format_id);
1728 return NULL;
1731 return &gl_info->formats[fmt_idx];
1734 static void copy_format(struct wined3d_format *dst_format, const struct wined3d_format *src_format)
1736 enum wined3d_format_id id = dst_format->id;
1737 *dst_format = *src_format;
1738 dst_format->id = id;
1741 static void format_set_flag(struct wined3d_format *format, unsigned int flag)
1743 unsigned int i;
1745 for (i = 0; i < ARRAY_SIZE(format->flags); ++i)
1746 format->flags[i] |= flag;
1749 static void format_clear_flag(struct wined3d_format *format, unsigned int flag)
1751 unsigned int i;
1753 for (i = 0; i < ARRAY_SIZE(format->flags); ++i)
1754 format->flags[i] &= ~flag;
1757 static enum wined3d_channel_type map_channel_type(char t)
1759 switch (t)
1761 case 'u':
1762 return WINED3D_CHANNEL_TYPE_UNORM;
1763 case 'i':
1764 return WINED3D_CHANNEL_TYPE_SNORM;
1765 case 'U':
1766 return WINED3D_CHANNEL_TYPE_UINT;
1767 case 'I':
1768 return WINED3D_CHANNEL_TYPE_SINT;
1769 case 'F':
1770 return WINED3D_CHANNEL_TYPE_FLOAT;
1771 case 'D':
1772 return WINED3D_CHANNEL_TYPE_DEPTH;
1773 case 'S':
1774 return WINED3D_CHANNEL_TYPE_STENCIL;
1775 case 'X':
1776 return WINED3D_CHANNEL_TYPE_UNUSED;
1777 default:
1778 ERR("Invalid channel type '%c'.\n", t);
1779 return WINED3D_CHANNEL_TYPE_NONE;
1783 static BOOL init_format_base_info(struct wined3d_gl_info *gl_info)
1785 struct wined3d_format *format;
1786 unsigned int i, j;
1788 gl_info->format_count = WINED3D_FORMAT_COUNT;
1789 if (!(gl_info->formats = wined3d_calloc(gl_info->format_count
1790 + ARRAY_SIZE(typeless_depth_stencil_formats), sizeof(*gl_info->formats))))
1792 ERR("Failed to allocate memory.\n");
1793 return FALSE;
1796 for (i = 0; i < ARRAY_SIZE(formats); ++i)
1798 if (!(format = get_format_internal(gl_info, formats[i].id)))
1799 goto fail;
1801 format->id = formats[i].id;
1802 format->red_size = formats[i].red_size;
1803 format->green_size = formats[i].green_size;
1804 format->blue_size = formats[i].blue_size;
1805 format->alpha_size = formats[i].alpha_size;
1806 format->red_offset = formats[i].red_offset;
1807 format->green_offset = formats[i].green_offset;
1808 format->blue_offset = formats[i].blue_offset;
1809 format->alpha_offset = formats[i].alpha_offset;
1810 format->byte_count = formats[i].bpp;
1811 format->depth_size = formats[i].depth_size;
1812 format->stencil_size = formats[i].stencil_size;
1813 format->block_width = 1;
1814 format->block_height = 1;
1815 format->block_byte_count = formats[i].bpp;
1818 for (i = 0; i < ARRAY_SIZE(typed_formats); ++i)
1820 const struct wined3d_format *typeless_format;
1821 DWORD flags = 0;
1823 if (!(format = get_format_internal(gl_info, typed_formats[i].id)))
1824 goto fail;
1826 if (!(typeless_format = get_format_internal(gl_info, typed_formats[i].typeless_id)))
1827 goto fail;
1829 format->id = typed_formats[i].id;
1830 format->red_size = typeless_format->red_size;
1831 format->green_size = typeless_format->green_size;
1832 format->blue_size = typeless_format->blue_size;
1833 format->alpha_size = typeless_format->alpha_size;
1834 format->red_offset = typeless_format->red_offset;
1835 format->green_offset = typeless_format->green_offset;
1836 format->blue_offset = typeless_format->blue_offset;
1837 format->alpha_offset = typeless_format->alpha_offset;
1838 format->byte_count = typeless_format->byte_count;
1839 format->depth_size = typeless_format->depth_size;
1840 format->stencil_size = typeless_format->stencil_size;
1841 format->block_width = typeless_format->block_width;
1842 format->block_height = typeless_format->block_height;
1843 format->block_byte_count = typeless_format->block_byte_count;
1844 format->typeless_id = typeless_format->id;
1846 for (j = 0; j < strlen(typed_formats[i].channels); ++j)
1848 enum wined3d_channel_type channel_type = map_channel_type(typed_formats[i].channels[j]);
1849 if (channel_type == WINED3D_CHANNEL_TYPE_UINT || channel_type == WINED3D_CHANNEL_TYPE_SINT)
1850 flags |= WINED3DFMT_FLAG_INTEGER;
1851 if (channel_type == WINED3D_CHANNEL_TYPE_FLOAT)
1852 flags |= WINED3DFMT_FLAG_FLOAT;
1854 if (channel_type == WINED3D_CHANNEL_TYPE_DEPTH && !format->depth_size)
1856 format->depth_size = format->red_size;
1857 format->red_size = format->red_offset = 0;
1861 format_set_flag(format, flags);
1864 for (i = 0; i < ARRAY_SIZE(ddi_formats); ++i)
1866 if (!(format = get_format_internal(gl_info, ddi_formats[i].id)))
1867 goto fail;
1869 format->ddi_format = ddi_formats[i].ddi_format;
1872 for (i = 0; i < ARRAY_SIZE(format_base_flags); ++i)
1874 if (!(format = get_format_internal(gl_info, format_base_flags[i].id)))
1875 goto fail;
1877 format_set_flag(format, format_base_flags[i].flags);
1880 return TRUE;
1882 fail:
1883 HeapFree(GetProcessHeap(), 0, gl_info->formats);
1884 return FALSE;
1887 static BOOL init_format_block_info(struct wined3d_gl_info *gl_info)
1889 struct wined3d_format *format;
1890 unsigned int i;
1892 for (i = 0; i < ARRAY_SIZE(format_block_info); ++i)
1894 if (!(format = get_format_internal(gl_info, format_block_info[i].id)))
1895 return FALSE;
1897 format->block_width = format_block_info[i].block_width;
1898 format->block_height = format_block_info[i].block_height;
1899 format->block_byte_count = format_block_info[i].block_byte_count;
1900 format_set_flag(format, WINED3DFMT_FLAG_BLOCKS);
1901 if (!format_block_info[i].verify)
1902 format_set_flag(format, WINED3DFMT_FLAG_BLOCKS_NO_VERIFY);
1905 return TRUE;
1908 static GLenum wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type)
1910 switch (type)
1912 case WINED3D_GL_RES_TYPE_TEX_1D:
1913 return GL_TEXTURE_1D;
1914 case WINED3D_GL_RES_TYPE_TEX_2D:
1915 return GL_TEXTURE_2D;
1916 case WINED3D_GL_RES_TYPE_TEX_3D:
1917 return GL_TEXTURE_3D;
1918 case WINED3D_GL_RES_TYPE_TEX_CUBE:
1919 return GL_TEXTURE_CUBE_MAP_ARB;
1920 case WINED3D_GL_RES_TYPE_TEX_RECT:
1921 return GL_TEXTURE_RECTANGLE_ARB;
1922 case WINED3D_GL_RES_TYPE_BUFFER:
1923 return GL_TEXTURE_2D; /* TODO: GL_TEXTURE_BUFFER. */
1924 case WINED3D_GL_RES_TYPE_RB:
1925 return GL_RENDERBUFFER;
1926 case WINED3D_GL_RES_TYPE_COUNT:
1927 break;
1929 ERR("Unexpected GL resource type %u.\n", type);
1930 return 0;
1933 static void delete_fbo_attachment(const struct wined3d_gl_info *gl_info,
1934 enum wined3d_gl_resource_type d3d_type, GLuint object)
1936 switch (d3d_type)
1938 case WINED3D_GL_RES_TYPE_TEX_1D:
1939 case WINED3D_GL_RES_TYPE_TEX_2D:
1940 case WINED3D_GL_RES_TYPE_TEX_RECT:
1941 case WINED3D_GL_RES_TYPE_TEX_3D:
1942 case WINED3D_GL_RES_TYPE_TEX_CUBE:
1943 gl_info->gl_ops.gl.p_glDeleteTextures(1, &object);
1944 break;
1946 case WINED3D_GL_RES_TYPE_RB:
1947 gl_info->fbo_ops.glDeleteRenderbuffers(1, &object);
1948 break;
1950 case WINED3D_GL_RES_TYPE_BUFFER:
1951 case WINED3D_GL_RES_TYPE_COUNT:
1952 break;
1956 /* Context activation is done by the caller. */
1957 static void create_and_bind_fbo_attachment(const struct wined3d_gl_info *gl_info, unsigned int flags,
1958 enum wined3d_gl_resource_type d3d_type, GLuint *object, GLenum internal, GLenum format, GLenum type)
1960 GLenum attach_type = flags & WINED3DFMT_FLAG_DEPTH ?
1961 GL_DEPTH_ATTACHMENT : GL_COLOR_ATTACHMENT0;
1963 switch (d3d_type)
1965 case WINED3D_GL_RES_TYPE_TEX_1D:
1966 gl_info->gl_ops.gl.p_glGenTextures(1, object);
1967 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D, *object);
1968 gl_info->gl_ops.gl.p_glTexImage1D(GL_TEXTURE_1D, 0, internal, 16, 0, format, type, NULL);
1969 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1970 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1972 gl_info->fbo_ops.glFramebufferTexture1D(GL_FRAMEBUFFER, attach_type, GL_TEXTURE_1D,
1973 *object, 0);
1974 if (flags & WINED3DFMT_FLAG_STENCIL)
1975 gl_info->fbo_ops.glFramebufferTexture1D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_1D,
1976 *object, 0);
1977 break;
1979 case WINED3D_GL_RES_TYPE_TEX_2D:
1980 case WINED3D_GL_RES_TYPE_TEX_RECT:
1981 gl_info->gl_ops.gl.p_glGenTextures(1, object);
1982 gl_info->gl_ops.gl.p_glBindTexture(wined3d_gl_type_to_enum(d3d_type), *object);
1983 gl_info->gl_ops.gl.p_glTexImage2D(wined3d_gl_type_to_enum(d3d_type), 0, internal, 16, 16, 0,
1984 format, type, NULL);
1985 gl_info->gl_ops.gl.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1986 gl_info->gl_ops.gl.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type), GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1988 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, attach_type,
1989 wined3d_gl_type_to_enum(d3d_type), *object, 0);
1990 if (flags & WINED3DFMT_FLAG_STENCIL)
1991 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
1992 wined3d_gl_type_to_enum(d3d_type), *object, 0);
1993 break;
1995 case WINED3D_GL_RES_TYPE_TEX_3D:
1996 gl_info->gl_ops.gl.p_glGenTextures(1, object);
1997 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_3D, *object);
1998 GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D, 0, internal, 16, 16, 16, 0, format, type, NULL));
1999 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2000 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2002 gl_info->fbo_ops.glFramebufferTexture3D(GL_FRAMEBUFFER, attach_type,
2003 GL_TEXTURE_3D, *object, 0, 0);
2004 if (flags & WINED3DFMT_FLAG_STENCIL)
2005 gl_info->fbo_ops.glFramebufferTexture3D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
2006 GL_TEXTURE_3D, *object, 0, 0);
2007 break;
2009 case WINED3D_GL_RES_TYPE_TEX_CUBE:
2010 gl_info->gl_ops.gl.p_glGenTextures(1, object);
2011 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, *object);
2012 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, internal, 16, 16, 0,
2013 format, type, NULL);
2014 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 0, internal, 16, 16, 0,
2015 format, type, NULL);
2016 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0, internal, 16, 16, 0,
2017 format, type, NULL);
2018 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 0, internal, 16, 16, 0,
2019 format, type, NULL);
2020 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 0, internal, 16, 16, 0,
2021 format, type, NULL);
2022 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 0, internal, 16, 16, 0,
2023 format, type, NULL);
2024 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
2025 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
2027 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, attach_type,
2028 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, *object, 0);
2029 if (flags & WINED3DFMT_FLAG_STENCIL)
2030 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
2031 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, *object, 0);
2032 break;
2034 case WINED3D_GL_RES_TYPE_RB:
2035 gl_info->fbo_ops.glGenRenderbuffers(1, object);
2036 gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, *object);
2037 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, internal, 16, 16);
2038 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, attach_type, GL_RENDERBUFFER,
2039 *object);
2040 if (flags & WINED3DFMT_FLAG_STENCIL)
2041 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
2042 *object);
2043 break;
2045 case WINED3D_GL_RES_TYPE_BUFFER:
2046 case WINED3D_GL_RES_TYPE_COUNT:
2047 break;
2050 /* Ideally we'd skip all formats already known not to work on textures
2051 * by checking for WINED3DFMT_FLAG_TEXTURE here. However, we want to
2052 * know if we can attach WINED3DFMT_P8_UINT textures to FBOs, and this
2053 * format never has WINED3DFMT_FLAG_TEXTURE set. Instead, swallow GL
2054 * errors generated by invalid formats. */
2055 while (gl_info->gl_ops.gl.p_glGetError());
2058 static void draw_test_quad(struct wined3d_caps_gl_ctx *ctx, const struct wined3d_vec3 *geometry,
2059 const struct wined3d_color *color)
2061 const struct wined3d_gl_info *gl_info = ctx->gl_info;
2062 static const struct wined3d_vec3 default_geometry[] =
2064 {-1.0f, -1.0f, 0.0f},
2065 { 1.0f, -1.0f, 0.0f},
2066 {-1.0f, 1.0f, 0.0f},
2067 { 1.0f, 1.0f, 0.0f},
2069 static const char vs_core_header[] =
2070 "#version 150\n"
2071 "in vec4 pos;\n"
2072 "in vec4 color;\n"
2073 "out vec4 out_color;\n"
2074 "\n";
2075 static const char vs_legacy_header[] =
2076 "#version 120\n"
2077 "attribute vec4 pos;\n"
2078 "attribute vec4 color;\n"
2079 "varying vec4 out_color;\n"
2080 "\n";
2081 static const char vs_body[] =
2082 "void main()\n"
2083 "{\n"
2084 " gl_Position = pos;\n"
2085 " out_color = color;\n"
2086 "}\n";
2087 static const char fs_core[] =
2088 "#version 150\n"
2089 "in vec4 out_color;\n"
2090 "out vec4 fragment_color;\n"
2091 "\n"
2092 "void main()\n"
2093 "{\n"
2094 " fragment_color = out_color;\n"
2095 "}\n";
2096 static const char fs_legacy[] =
2097 "#version 120\n"
2098 "varying vec4 out_color;\n"
2099 "\n"
2100 "void main()\n"
2101 "{\n"
2102 " gl_FragData[0] = out_color;\n"
2103 "}\n";
2104 const char *source[2];
2105 GLuint vs_id, fs_id;
2106 unsigned int i;
2108 if (!geometry)
2109 geometry = default_geometry;
2111 if (!gl_info->supported[ARB_VERTEX_BUFFER_OBJECT] || !gl_info->supported[ARB_VERTEX_SHADER]
2112 || !gl_info->supported[ARB_FRAGMENT_SHADER])
2114 gl_info->gl_ops.gl.p_glDisable(GL_LIGHTING);
2115 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
2116 gl_info->gl_ops.gl.p_glLoadIdentity();
2117 gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
2118 gl_info->gl_ops.gl.p_glLoadIdentity();
2120 gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
2121 gl_info->gl_ops.gl.p_glColor4f(color->r, color->g, color->b, color->a);
2122 for (i = 0; i < 4; ++i)
2123 gl_info->gl_ops.gl.p_glVertex3fv(&geometry[i].x);
2124 gl_info->gl_ops.gl.p_glEnd();
2125 checkGLcall("draw quad");
2126 return;
2129 if (!ctx->test_vbo)
2130 GL_EXTCALL(glGenBuffers(1, &ctx->test_vbo));
2131 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, ctx->test_vbo));
2132 GL_EXTCALL(glBufferData(GL_ARRAY_BUFFER, sizeof(struct wined3d_vec3) * 4, geometry, GL_STREAM_DRAW));
2133 GL_EXTCALL(glVertexAttribPointer(0, 3, GL_FLOAT, FALSE, 0, NULL));
2134 GL_EXTCALL(glVertexAttrib4f(1, color->r, color->g, color->b, color->a));
2135 GL_EXTCALL(glEnableVertexAttribArray(0));
2136 GL_EXTCALL(glDisableVertexAttribArray(1));
2138 if (!ctx->test_program_id)
2140 BOOL use_glsl_150 = gl_info->glsl_version >= MAKEDWORD_VERSION(1, 50);
2142 ctx->test_program_id = GL_EXTCALL(glCreateProgram());
2144 vs_id = GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER));
2145 source[0] = use_glsl_150 ? vs_core_header : vs_legacy_header;
2146 source[1] = vs_body;
2147 GL_EXTCALL(glShaderSource(vs_id, 2, source, NULL));
2148 GL_EXTCALL(glAttachShader(ctx->test_program_id, vs_id));
2149 GL_EXTCALL(glDeleteShader(vs_id));
2151 fs_id = GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER));
2152 source[0] = use_glsl_150 ? fs_core : fs_legacy;
2153 GL_EXTCALL(glShaderSource(fs_id, 1, source, NULL));
2154 GL_EXTCALL(glAttachShader(ctx->test_program_id, fs_id));
2155 GL_EXTCALL(glDeleteShader(fs_id));
2157 GL_EXTCALL(glBindAttribLocation(ctx->test_program_id, 0, "pos"));
2158 GL_EXTCALL(glBindAttribLocation(ctx->test_program_id, 1, "color"));
2160 if (use_glsl_150)
2161 GL_EXTCALL(glBindFragDataLocation(ctx->test_program_id, 0, "fragment_color"));
2163 GL_EXTCALL(glCompileShader(vs_id));
2164 print_glsl_info_log(gl_info, vs_id, FALSE);
2165 GL_EXTCALL(glCompileShader(fs_id));
2166 print_glsl_info_log(gl_info, fs_id, FALSE);
2167 GL_EXTCALL(glLinkProgram(ctx->test_program_id));
2168 shader_glsl_validate_link(gl_info, ctx->test_program_id);
2170 GL_EXTCALL(glUseProgram(ctx->test_program_id));
2172 gl_info->gl_ops.gl.p_glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
2174 GL_EXTCALL(glUseProgram(0));
2175 GL_EXTCALL(glDisableVertexAttribArray(0));
2176 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, 0));
2177 checkGLcall("draw quad");
2180 /* Context activation is done by the caller. */
2181 static void check_fbo_compat(struct wined3d_caps_gl_ctx *ctx, struct wined3d_format *format)
2183 /* Check if the default internal format is supported as a frame buffer
2184 * target, otherwise fall back to the render target internal.
2186 * Try to stick to the standard format if possible, this limits precision differences. */
2187 static const struct wined3d_color black = {0.0f, 0.0f, 0.0f, 1.0f};
2188 static const struct wined3d_color half_transparent_red = {1.0f, 0.0f, 0.0f, 0.5f};
2189 const struct wined3d_gl_info *gl_info = ctx->gl_info;
2190 GLenum status, rt_internal = format->rtInternal;
2191 GLuint object, color_rb;
2192 enum wined3d_gl_resource_type type;
2193 BOOL fallback_fmt_used = FALSE, regular_fmt_used = FALSE;
2195 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
2197 for (type = 0; type < ARRAY_SIZE(format->flags); ++type)
2199 const char *type_string = "color";
2201 if (type == WINED3D_GL_RES_TYPE_BUFFER)
2202 continue;
2204 create_and_bind_fbo_attachment(gl_info, format->flags[type], type, &object, format->glInternal,
2205 format->glFormat, format->glType);
2207 if (format->flags[type] & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
2209 gl_info->fbo_ops.glGenRenderbuffers(1, &color_rb);
2210 gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, color_rb);
2211 if (type == WINED3D_GL_RES_TYPE_TEX_1D)
2212 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 16, 1);
2213 else
2214 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, 16, 16);
2216 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER,
2217 GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, color_rb);
2218 checkGLcall("Create and attach color rb attachment");
2219 type_string = "depth / stencil";
2222 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
2223 checkGLcall("Framebuffer format check");
2225 if (status == GL_FRAMEBUFFER_COMPLETE)
2227 TRACE("Format %s is supported as FBO %s attachment, type %u.\n",
2228 debug_d3dformat(format->id), type_string, type);
2229 format->flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE;
2230 format->rtInternal = format->glInternal;
2231 regular_fmt_used = TRUE;
2233 else
2235 if (!rt_internal)
2237 if (format->flags[type] & WINED3DFMT_FLAG_RENDERTARGET)
2239 WARN("Format %s with rendertarget flag is not supported as FBO color attachment (type %u),"
2240 " and no fallback specified.\n", debug_d3dformat(format->id), type);
2241 format->flags[type] &= ~WINED3DFMT_FLAG_RENDERTARGET;
2243 else
2245 TRACE("Format %s is not supported as FBO %s attachment, type %u.\n",
2246 debug_d3dformat(format->id), type_string, type);
2248 format->rtInternal = format->glInternal;
2250 else
2252 TRACE("Format %s is not supported as FBO %s attachment (type %u),"
2253 " trying rtInternal format as fallback.\n",
2254 debug_d3dformat(format->id), type_string, type);
2256 while (gl_info->gl_ops.gl.p_glGetError());
2258 delete_fbo_attachment(gl_info, type, object);
2259 create_and_bind_fbo_attachment(gl_info, format->flags[type], type, &object, format->rtInternal,
2260 format->glFormat, format->glType);
2262 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
2263 checkGLcall("Framebuffer format check");
2265 if (status == GL_FRAMEBUFFER_COMPLETE)
2267 TRACE("Format %s rtInternal format is supported as FBO %s attachment, type %u.\n",
2268 debug_d3dformat(format->id), type_string, type);
2269 fallback_fmt_used = TRUE;
2271 else
2273 WARN("Format %s rtInternal format is not supported as FBO %s attachment, type %u.\n",
2274 debug_d3dformat(format->id), type_string, type);
2275 format->flags[type] &= ~WINED3DFMT_FLAG_RENDERTARGET;
2280 if (status == GL_FRAMEBUFFER_COMPLETE
2281 && ((format->flags[type] & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)
2282 || !(gl_info->quirks & WINED3D_QUIRK_LIMITED_TEX_FILTERING))
2283 && !(format->flags[type] & WINED3DFMT_FLAG_INTEGER)
2284 && format->id != WINED3DFMT_NULL && format->id != WINED3DFMT_P8_UINT
2285 && format->glFormat != GL_LUMINANCE && format->glFormat != GL_LUMINANCE_ALPHA
2286 && (format->red_size || format->alpha_size))
2288 DWORD readback[16 * 16 * 16], color, r_range, a_range;
2289 BYTE r, a;
2290 BOOL match = TRUE;
2291 GLuint rb;
2293 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
2294 || gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
2296 gl_info->fbo_ops.glGenRenderbuffers(1, &rb);
2297 gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, rb);
2298 if (type == WINED3D_GL_RES_TYPE_TEX_1D)
2299 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 16, 1);
2300 else
2301 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 16, 16);
2302 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb);
2303 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb);
2304 checkGLcall("RB attachment");
2307 gl_info->gl_ops.gl.p_glEnable(GL_BLEND);
2308 gl_info->gl_ops.gl.p_glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
2309 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
2310 if (gl_info->gl_ops.gl.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION)
2312 while (gl_info->gl_ops.gl.p_glGetError());
2313 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2314 debug_d3dformat(format->id), type);
2315 format->flags[type] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
2317 else
2319 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
2320 if (type == WINED3D_GL_RES_TYPE_TEX_1D)
2321 gl_info->gl_ops.gl.p_glViewport(0, 0, 16, 1);
2322 else
2323 gl_info->gl_ops.gl.p_glViewport(0, 0, 16, 16);
2324 gl_info->gl_ops.gl.p_glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
2326 draw_test_quad(ctx, NULL, &black);
2328 gl_info->gl_ops.gl.p_glEnable(GL_BLEND);
2330 draw_test_quad(ctx, NULL, &half_transparent_red);
2332 gl_info->gl_ops.gl.p_glDisable(GL_BLEND);
2334 switch (type)
2336 case WINED3D_GL_RES_TYPE_TEX_1D:
2337 /* Rebinding texture to workaround a fglrx bug. */
2338 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_1D, object);
2339 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_1D, 0, GL_BGRA,
2340 GL_UNSIGNED_INT_8_8_8_8_REV, readback);
2341 color = readback[7];
2342 break;
2344 case WINED3D_GL_RES_TYPE_TEX_2D:
2345 case WINED3D_GL_RES_TYPE_TEX_3D:
2346 case WINED3D_GL_RES_TYPE_TEX_RECT:
2347 /* Rebinding texture to workaround a fglrx bug. */
2348 gl_info->gl_ops.gl.p_glBindTexture(wined3d_gl_type_to_enum(type), object);
2349 gl_info->gl_ops.gl.p_glGetTexImage(wined3d_gl_type_to_enum(type), 0, GL_BGRA,
2350 GL_UNSIGNED_INT_8_8_8_8_REV, readback);
2351 color = readback[7 * 16 + 7];
2352 break;
2354 case WINED3D_GL_RES_TYPE_TEX_CUBE:
2355 /* Rebinding texture to workaround a fglrx bug. */
2356 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, object);
2357 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 0, GL_BGRA,
2358 GL_UNSIGNED_INT_8_8_8_8_REV, readback);
2359 color = readback[7 * 16 + 7];
2360 break;
2362 case WINED3D_GL_RES_TYPE_RB:
2363 gl_info->gl_ops.gl.p_glReadPixels(0, 0, 16, 16,
2364 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, readback);
2365 color = readback[7 * 16 + 7];
2366 break;
2368 case WINED3D_GL_RES_TYPE_BUFFER:
2369 case WINED3D_GL_RES_TYPE_COUNT:
2370 color = 0;
2371 break;
2373 checkGLcall("Post-pixelshader blending check");
2375 a = color >> 24;
2376 r = (color & 0x00ff0000u) >> 16;
2378 r_range = format->red_size < 8 ? 1u << (8 - format->red_size) : 1;
2379 a_range = format->alpha_size < 8 ? 1u << (8 - format->alpha_size) : 1;
2380 if (format->red_size && (r < 0x7f - r_range || r > 0x7f + r_range))
2381 match = FALSE;
2382 else if (format->alpha_size > 1 && (a < 0xbf - a_range || a > 0xbf + a_range))
2383 match = FALSE;
2384 if (!match)
2386 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2387 debug_d3dformat(format->id), type);
2388 TRACE("Color output: %#x\n", color);
2389 format->flags[type] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
2391 else
2393 TRACE("Format %s supports post-pixelshader blending, type %u.\n",
2394 debug_d3dformat(format->id), type);
2395 TRACE("Color output: %#x\n", color);
2396 format->flags[type] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
2400 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
2401 || gl_info->supported[EXT_PACKED_DEPTH_STENCIL])
2403 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
2404 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
2405 gl_info->fbo_ops.glDeleteRenderbuffers(1, &rb);
2406 checkGLcall("RB cleanup");
2410 if (format->glInternal != format->glGammaInternal)
2412 delete_fbo_attachment(gl_info, type, object);
2413 create_and_bind_fbo_attachment(gl_info, format->flags[type], type, &object, format->glGammaInternal,
2414 format->glFormat, format->glType);
2416 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
2417 checkGLcall("Framebuffer format check");
2419 if (status == GL_FRAMEBUFFER_COMPLETE)
2421 TRACE("Format %s's sRGB format is FBO attachable, type %u.\n",
2422 debug_d3dformat(format->id), type);
2423 format->flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
2424 if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
2425 format->glInternal = format->glGammaInternal;
2427 else
2429 WARN("Format %s's sRGB format is not FBO attachable, type %u.\n",
2430 debug_d3dformat(format->id), type);
2431 format_clear_flag(format, WINED3DFMT_FLAG_SRGB_WRITE);
2434 else if (status == GL_FRAMEBUFFER_COMPLETE)
2435 format->flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
2437 if (format->flags[type] & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
2439 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, 0);
2440 gl_info->fbo_ops.glDeleteRenderbuffers(1, &color_rb);
2443 delete_fbo_attachment(gl_info, type, object);
2444 checkGLcall("Framebuffer format check cleanup");
2447 if (fallback_fmt_used && regular_fmt_used)
2449 FIXME("Format %s needs different render target formats for different resource types.\n",
2450 debug_d3dformat(format->id));
2451 format_clear_flag(format, WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_FBO_ATTACHABLE
2452 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING);
2456 static void query_format_flag(struct wined3d_gl_info *gl_info, struct wined3d_format *format,
2457 GLint internal, GLenum pname, DWORD flag, const char *string)
2459 GLint value;
2460 enum wined3d_gl_resource_type type;
2462 for (type = 0; type < ARRAY_SIZE(format->flags); ++type)
2464 gl_info->gl_ops.ext.p_glGetInternalformativ(wined3d_gl_type_to_enum(type), internal, pname, 1, &value);
2465 if (value == GL_FULL_SUPPORT)
2467 TRACE("Format %s supports %s, resource type %u.\n", debug_d3dformat(format->id), string, type);
2468 format->flags[type] |= flag;
2470 else
2472 TRACE("Format %s doesn't support %s, resource type %u.\n", debug_d3dformat(format->id), string, type);
2473 format->flags[type] &= ~flag;
2478 /* Context activation is done by the caller. */
2479 static void init_format_fbo_compat_info(struct wined3d_caps_gl_ctx *ctx)
2481 const struct wined3d_gl_info *gl_info = ctx->gl_info;
2482 unsigned int i, type;
2483 GLuint fbo;
2485 if (gl_info->supported[ARB_INTERNALFORMAT_QUERY2])
2487 for (i = 0; i < gl_info->format_count; ++i)
2489 GLint value;
2490 struct wined3d_format *format = &gl_info->formats[i];
2491 BOOL fallback_fmt_used = FALSE, regular_fmt_used = FALSE;
2492 GLenum rt_internal = format->rtInternal;
2494 if (!format->glInternal)
2495 continue;
2497 for (type = 0; type < ARRAY_SIZE(format->flags); ++type)
2499 gl_info->gl_ops.ext.p_glGetInternalformativ(wined3d_gl_type_to_enum(type),
2500 format->glInternal, GL_FRAMEBUFFER_RENDERABLE, 1, &value);
2501 if (value == GL_FULL_SUPPORT)
2503 TRACE("Format %s is supported as FBO color attachment, resource type %u.\n",
2504 debug_d3dformat(format->id), type);
2505 format->flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE;
2506 format->rtInternal = format->glInternal;
2507 regular_fmt_used = TRUE;
2509 gl_info->gl_ops.ext.p_glGetInternalformativ(wined3d_gl_type_to_enum(type),
2510 format->glInternal, GL_FRAMEBUFFER_BLEND, 1, &value);
2511 if (value == GL_FULL_SUPPORT)
2513 TRACE("Format %s supports post-pixelshader blending, resource type %u.\n",
2514 debug_d3dformat(format->id), type);
2515 format->flags[type] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
2517 else
2519 TRACE("Format %s doesn't support post-pixelshader blending, resource typed %u.\n",
2520 debug_d3dformat(format->id), type);
2521 format->flags[type] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
2524 else
2526 if (!rt_internal)
2528 if (format->flags[type] & WINED3DFMT_FLAG_RENDERTARGET)
2530 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
2531 " and no fallback specified, resource type %u.\n",
2532 debug_d3dformat(format->id), type);
2533 format->flags[type] &= ~WINED3DFMT_FLAG_RENDERTARGET;
2535 else
2536 TRACE("Format %s is not supported as FBO color attachment,"
2537 " resource type %u.\n", debug_d3dformat(format->id), type);
2538 format->rtInternal = format->glInternal;
2540 else
2542 gl_info->gl_ops.ext.p_glGetInternalformativ(wined3d_gl_type_to_enum(type),
2543 rt_internal, GL_FRAMEBUFFER_RENDERABLE, 1, &value);
2544 if (value == GL_FULL_SUPPORT)
2546 TRACE("Format %s rtInternal format is supported as FBO color attachment,"
2547 " resource type %u.\n", debug_d3dformat(format->id), type);
2548 fallback_fmt_used = TRUE;
2550 else
2552 WARN("Format %s rtInternal format is not supported as FBO color attachment,"
2553 " resource type %u.\n", debug_d3dformat(format->id), type);
2554 format->flags[type] &= ~WINED3DFMT_FLAG_RENDERTARGET;
2559 if (format->glInternal != format->glGammaInternal)
2561 gl_info->gl_ops.ext.p_glGetInternalformativ(wined3d_gl_type_to_enum(type),
2562 format->glGammaInternal, GL_FRAMEBUFFER_RENDERABLE, 1, &value);
2563 if (value == GL_FULL_SUPPORT)
2565 TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n",
2566 debug_d3dformat(format->id), type);
2567 format->flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
2568 if (gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
2569 format->glInternal = format->glGammaInternal;
2571 else
2573 WARN("Format %s's sRGB format is not FBO attachable, resource type %u.\n",
2574 debug_d3dformat(format->id), type);
2575 format_clear_flag(format, WINED3DFMT_FLAG_SRGB_WRITE);
2578 else if (format->flags[type] & WINED3DFMT_FLAG_FBO_ATTACHABLE)
2579 format->flags[type] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB;
2582 if (fallback_fmt_used && regular_fmt_used)
2584 FIXME("Format %s needs different render target formats for different resource types.\n",
2585 debug_d3dformat(format->id));
2586 format_clear_flag(format, WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_FBO_ATTACHABLE
2587 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING);
2590 return;
2593 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
2595 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
2596 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
2597 gl_info->gl_ops.gl.p_glDrawBuffer(GL_COLOR_ATTACHMENT0);
2598 gl_info->gl_ops.gl.p_glReadBuffer(GL_COLOR_ATTACHMENT0);
2601 for (i = 0; i < gl_info->format_count; ++i)
2603 struct wined3d_format *format = &gl_info->formats[i];
2605 if (!format->glInternal) continue;
2607 if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_COMPRESSED)
2609 TRACE("Skipping format %s because it's a compressed format.\n",
2610 debug_d3dformat(format->id));
2611 continue;
2614 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
2616 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format->id));
2617 check_fbo_compat(ctx, format);
2619 else
2621 format->rtInternal = format->glInternal;
2625 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
2626 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
2629 static GLenum lookup_gl_view_class(GLenum internal_format)
2631 static const struct
2633 GLenum internal_format;
2634 GLenum view_class;
2636 view_classes[] =
2638 /* 128-bit */
2639 {GL_RGBA32F, GL_VIEW_CLASS_128_BITS},
2640 {GL_RGBA32UI, GL_VIEW_CLASS_128_BITS},
2641 {GL_RGBA32I, GL_VIEW_CLASS_128_BITS},
2642 /* 96-bit */
2643 {GL_RGB32F, GL_VIEW_CLASS_96_BITS},
2644 {GL_RGB32UI, GL_VIEW_CLASS_96_BITS},
2645 {GL_RGB32I, GL_VIEW_CLASS_96_BITS},
2646 /* 64-bit */
2647 {GL_RGBA16F, GL_VIEW_CLASS_64_BITS},
2648 {GL_RG32F, GL_VIEW_CLASS_64_BITS},
2649 {GL_RGBA16UI, GL_VIEW_CLASS_64_BITS},
2650 {GL_RG32UI, GL_VIEW_CLASS_64_BITS},
2651 {GL_RGBA16I, GL_VIEW_CLASS_64_BITS},
2652 {GL_RG32I, GL_VIEW_CLASS_64_BITS},
2653 {GL_RGBA16, GL_VIEW_CLASS_64_BITS},
2654 {GL_RGBA16_SNORM, GL_VIEW_CLASS_64_BITS},
2655 /* 48-bit */
2656 {GL_RGB16, GL_VIEW_CLASS_48_BITS},
2657 {GL_RGB16_SNORM, GL_VIEW_CLASS_48_BITS},
2658 {GL_RGB16F, GL_VIEW_CLASS_48_BITS},
2659 {GL_RGB16UI, GL_VIEW_CLASS_48_BITS},
2660 {GL_RGB16I, GL_VIEW_CLASS_48_BITS},
2661 /* 32-bit */
2662 {GL_RG16F, GL_VIEW_CLASS_32_BITS},
2663 {GL_R11F_G11F_B10F, GL_VIEW_CLASS_32_BITS},
2664 {GL_R32F, GL_VIEW_CLASS_32_BITS},
2665 {GL_RGB10_A2UI, GL_VIEW_CLASS_32_BITS},
2666 {GL_RGBA8UI, GL_VIEW_CLASS_32_BITS},
2667 {GL_RG16UI, GL_VIEW_CLASS_32_BITS},
2668 {GL_R32UI, GL_VIEW_CLASS_32_BITS},
2669 {GL_RGBA8I, GL_VIEW_CLASS_32_BITS},
2670 {GL_RG16I, GL_VIEW_CLASS_32_BITS},
2671 {GL_R32I, GL_VIEW_CLASS_32_BITS},
2672 {GL_RGB10_A2, GL_VIEW_CLASS_32_BITS},
2673 {GL_RGBA8, GL_VIEW_CLASS_32_BITS},
2674 {GL_RG16, GL_VIEW_CLASS_32_BITS},
2675 {GL_RGBA8_SNORM, GL_VIEW_CLASS_32_BITS},
2676 {GL_RG16_SNORM, GL_VIEW_CLASS_32_BITS},
2677 {GL_SRGB8_ALPHA8, GL_VIEW_CLASS_32_BITS},
2678 {GL_RGB9_E5, GL_VIEW_CLASS_32_BITS},
2679 /* 24-bit */
2680 {GL_RGB8, GL_VIEW_CLASS_24_BITS},
2681 {GL_RGB8_SNORM, GL_VIEW_CLASS_24_BITS},
2682 {GL_SRGB8, GL_VIEW_CLASS_24_BITS},
2683 {GL_RGB8UI, GL_VIEW_CLASS_24_BITS},
2684 {GL_RGB8I, GL_VIEW_CLASS_24_BITS},
2685 /* 16-bit */
2686 {GL_R16F, GL_VIEW_CLASS_16_BITS},
2687 {GL_RG8UI, GL_VIEW_CLASS_16_BITS},
2688 {GL_R16UI, GL_VIEW_CLASS_16_BITS},
2689 {GL_RG8I, GL_VIEW_CLASS_16_BITS},
2690 {GL_R16I, GL_VIEW_CLASS_16_BITS},
2691 {GL_RG8, GL_VIEW_CLASS_16_BITS},
2692 {GL_R16, GL_VIEW_CLASS_16_BITS},
2693 {GL_RG8_SNORM, GL_VIEW_CLASS_16_BITS},
2694 {GL_R16_SNORM, GL_VIEW_CLASS_16_BITS},
2695 /* 8-bit */
2696 {GL_R8UI, GL_VIEW_CLASS_8_BITS},
2697 {GL_R8I, GL_VIEW_CLASS_8_BITS},
2698 {GL_R8, GL_VIEW_CLASS_8_BITS},
2699 {GL_R8_SNORM, GL_VIEW_CLASS_8_BITS},
2701 /* RGTC1 */
2702 {GL_COMPRESSED_RED_RGTC1, GL_VIEW_CLASS_RGTC1_RED},
2703 {GL_COMPRESSED_SIGNED_RED_RGTC1, GL_VIEW_CLASS_RGTC1_RED},
2704 /* RGTC2 */
2705 {GL_COMPRESSED_RG_RGTC2, GL_VIEW_CLASS_RGTC2_RG},
2706 {GL_COMPRESSED_SIGNED_RG_RGTC2, GL_VIEW_CLASS_RGTC2_RG},
2708 /* BPTC unorm */
2709 {GL_COMPRESSED_RGBA_BPTC_UNORM, GL_VIEW_CLASS_BPTC_UNORM},
2710 {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, GL_VIEW_CLASS_BPTC_UNORM},
2711 /* BPTC float */
2712 {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, GL_VIEW_CLASS_BPTC_FLOAT},
2713 {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, GL_VIEW_CLASS_BPTC_FLOAT},
2715 /* DXT1 RGB */
2716 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_VIEW_CLASS_S3TC_DXT1_RGB},
2717 {GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, GL_VIEW_CLASS_S3TC_DXT1_RGB},
2718 /* DXT1 RGBA */
2719 {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_VIEW_CLASS_S3TC_DXT1_RGBA},
2720 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_VIEW_CLASS_S3TC_DXT1_RGBA},
2721 /* DXT3 */
2722 {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_VIEW_CLASS_S3TC_DXT3_RGBA},
2723 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_VIEW_CLASS_S3TC_DXT3_RGBA},
2724 /* DXT5 */
2725 {GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_VIEW_CLASS_S3TC_DXT5_RGBA},
2726 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_VIEW_CLASS_S3TC_DXT5_RGBA},
2729 unsigned int i;
2731 for (i = 0; i < ARRAY_SIZE(view_classes); ++i)
2733 if (view_classes[i].internal_format == internal_format)
2734 return view_classes[i].view_class;
2737 return GL_NONE;
2740 static void query_view_class(struct wined3d_format *format)
2742 GLenum internal_view_class, gamma_view_class, rt_view_class;
2744 internal_view_class = lookup_gl_view_class(format->glInternal);
2745 gamma_view_class = lookup_gl_view_class(format->glGammaInternal);
2746 rt_view_class = lookup_gl_view_class(format->rtInternal);
2748 if (internal_view_class == gamma_view_class || gamma_view_class == rt_view_class)
2750 format->gl_view_class = internal_view_class;
2751 TRACE("Format %s is member of GL view class %#x.\n",
2752 debug_d3dformat(format->id), format->gl_view_class);
2754 else
2756 format->gl_view_class = GL_NONE;
2760 static void query_internal_format(struct wined3d_adapter *adapter,
2761 struct wined3d_format *format, const struct wined3d_format_texture_info *texture_info,
2762 struct wined3d_gl_info *gl_info, BOOL srgb_write_supported, BOOL srgb_format)
2764 GLint count, multisample_types[MAX_MULTISAMPLE_TYPES];
2765 unsigned int i, max_log2;
2767 if (gl_info->supported[ARB_INTERNALFORMAT_QUERY2])
2769 query_format_flag(gl_info, format, format->glInternal, GL_VERTEX_TEXTURE,
2770 WINED3DFMT_FLAG_VTF, "vertex texture usage");
2771 query_format_flag(gl_info, format, format->glInternal, GL_FILTER,
2772 WINED3DFMT_FLAG_FILTERING, "filtering");
2774 if (srgb_format || format->glGammaInternal != format->glInternal)
2776 query_format_flag(gl_info, format, format->glGammaInternal, GL_SRGB_READ,
2777 WINED3DFMT_FLAG_SRGB_READ, "sRGB read");
2779 if (srgb_write_supported)
2780 query_format_flag(gl_info, format, format->glGammaInternal, GL_SRGB_WRITE,
2781 WINED3DFMT_FLAG_SRGB_WRITE, "sRGB write");
2782 else
2783 format_clear_flag(format, WINED3DFMT_FLAG_SRGB_WRITE);
2785 if (!(format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & (WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE)))
2786 format->glGammaInternal = format->glInternal;
2787 else if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
2788 && gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
2789 format->glInternal = format->glGammaInternal;
2792 else
2794 if (!gl_info->limits.samplers[WINED3D_SHADER_TYPE_VERTEX])
2795 format_clear_flag(format, WINED3DFMT_FLAG_VTF);
2797 if (!(gl_info->quirks & WINED3D_QUIRK_LIMITED_TEX_FILTERING))
2798 format_set_flag(format, WINED3DFMT_FLAG_FILTERING);
2799 else if (format->id != WINED3DFMT_R32G32B32A32_FLOAT && format->id != WINED3DFMT_R32_FLOAT)
2800 format_clear_flag(format, WINED3DFMT_FLAG_VTF);
2802 if (srgb_format || format->glGammaInternal != format->glInternal)
2804 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
2805 if (!gl_info->supported[EXT_TEXTURE_SRGB])
2807 format->glGammaInternal = format->glInternal;
2808 format_clear_flag(format, WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE);
2810 else if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
2811 && gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
2813 format->glInternal = format->glGammaInternal;
2817 if ((format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_SRGB_WRITE) && !srgb_write_supported)
2818 format_clear_flag(format, WINED3DFMT_FLAG_SRGB_WRITE);
2820 if (!gl_info->supported[ARB_DEPTH_TEXTURE]
2821 && texture_info->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
2823 format->flags[WINED3D_GL_RES_TYPE_TEX_1D] &= ~WINED3DFMT_FLAG_TEXTURE;
2824 format->flags[WINED3D_GL_RES_TYPE_TEX_2D] &= ~WINED3DFMT_FLAG_TEXTURE;
2825 format->flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
2826 format->flags[WINED3D_GL_RES_TYPE_TEX_CUBE] &= ~WINED3DFMT_FLAG_TEXTURE;
2827 format->flags[WINED3D_GL_RES_TYPE_TEX_RECT] &= ~WINED3DFMT_FLAG_TEXTURE;
2831 query_view_class(format);
2833 if (format->glInternal && format->flags[WINED3D_GL_RES_TYPE_RB]
2834 & (WINED3DFMT_FLAG_RENDERTARGET | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
2836 if (gl_info->supported[ARB_INTERNALFORMAT_QUERY])
2838 count = 0;
2839 GL_EXTCALL(glGetInternalformativ(GL_RENDERBUFFER, format->glInternal,
2840 GL_NUM_SAMPLE_COUNTS, 1, &count));
2841 checkGLcall("glGetInternalformativ(GL_NUM_SAMPLE_COUNTS)");
2842 count = min(count, MAX_MULTISAMPLE_TYPES);
2843 GL_EXTCALL(glGetInternalformativ(GL_RENDERBUFFER, format->glInternal,
2844 GL_SAMPLES, count, multisample_types));
2845 checkGLcall("glGetInternalformativ(GL_SAMPLES)");
2846 for (i = 0; i < count; ++i)
2848 if (multisample_types[i] > sizeof(format->multisample_types) * 8)
2849 continue;
2850 format->multisample_types |= 1u << (multisample_types[i] - 1);
2853 else
2855 max_log2 = wined3d_log2i(min(gl_info->limits.samples,
2856 sizeof(format->multisample_types) * 8));
2857 for (i = 1; i <= max_log2; ++i)
2858 format->multisample_types |= 1u << ((1u << i) - 1);
2863 static BOOL init_format_texture_info(struct wined3d_adapter *adapter, struct wined3d_gl_info *gl_info)
2865 struct wined3d_format *format, *srgb_format;
2866 struct fragment_caps fragment_caps;
2867 struct shader_caps shader_caps;
2868 unsigned int i, j;
2869 BOOL srgb_write;
2871 adapter->fragment_pipe->get_caps(gl_info, &fragment_caps);
2872 adapter->shader_backend->shader_get_caps(gl_info, &shader_caps);
2873 srgb_write = (fragment_caps.wined3d_caps & WINED3D_FRAGMENT_CAP_SRGB_WRITE)
2874 && (shader_caps.wined3d_caps & WINED3D_SHADER_CAP_SRGB_WRITE);
2876 for (i = 0; i < ARRAY_SIZE(format_texture_info); ++i)
2878 if (!(format = get_format_internal(gl_info, format_texture_info[i].id)))
2879 return FALSE;
2881 if (!gl_info->supported[format_texture_info[i].extension])
2882 continue;
2884 /* ARB_texture_rg defines floating point formats, but only if
2885 * ARB_texture_float is also supported. */
2886 if (!gl_info->supported[ARB_TEXTURE_FLOAT]
2887 && (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_FLOAT))
2888 continue;
2890 /* ARB_texture_rg defines integer formats if EXT_texture_integer is also supported. */
2891 if (!gl_info->supported[EXT_TEXTURE_INTEGER]
2892 && (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_INTEGER))
2893 continue;
2895 format->glInternal = format_texture_info[i].gl_internal;
2896 format->glGammaInternal = format_texture_info[i].gl_srgb_internal;
2897 format->rtInternal = format_texture_info[i].gl_rt_internal;
2898 format->glFormat = format_texture_info[i].gl_format;
2899 format->glType = format_texture_info[i].gl_type;
2900 format->color_fixup = COLOR_FIXUP_IDENTITY;
2901 format->height_scale.numerator = 1;
2902 format->height_scale.denominator = 1;
2904 format->flags[WINED3D_GL_RES_TYPE_TEX_1D] |= format_texture_info[i].flags;
2905 format->flags[WINED3D_GL_RES_TYPE_TEX_2D] |= format_texture_info[i].flags;
2906 format->flags[WINED3D_GL_RES_TYPE_BUFFER] |= format_texture_info[i].flags;
2908 /* GL_ARB_depth_texture does not support 3D textures. It also says "cube textures are
2909 * problematic", but doesn't explicitly mandate that an error is generated. */
2910 if (gl_info->supported[EXT_TEXTURE3D]
2911 && !(format_texture_info[i].flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
2912 format->flags[WINED3D_GL_RES_TYPE_TEX_3D] |= format_texture_info[i].flags;
2914 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
2915 format->flags[WINED3D_GL_RES_TYPE_TEX_CUBE] |= format_texture_info[i].flags;
2917 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
2918 format->flags[WINED3D_GL_RES_TYPE_TEX_RECT] |= format_texture_info[i].flags;
2920 format->flags[WINED3D_GL_RES_TYPE_RB] |= format_texture_info[i].flags;
2921 format->flags[WINED3D_GL_RES_TYPE_RB] &= ~WINED3DFMT_FLAG_TEXTURE;
2923 if (format->glGammaInternal != format->glInternal
2924 && !(adapter->d3d_info.wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL))
2926 format->glGammaInternal = format->glInternal;
2927 format_clear_flag(format, WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE);
2930 query_internal_format(adapter, format, &format_texture_info[i], gl_info, srgb_write, FALSE);
2932 /* Texture conversion stuff */
2933 format->convert = format_texture_info[i].convert;
2934 format->conv_byte_count = format_texture_info[i].conv_byte_count;
2936 srgb_format = NULL;
2937 for (j = 0; j < ARRAY_SIZE(format_srgb_info); ++j)
2939 if (format_srgb_info[j].base_format_id == format->id)
2941 if (!(srgb_format = get_format_internal(gl_info, format_srgb_info[j].srgb_format_id)))
2942 return FALSE;
2943 break;
2946 if (!srgb_format)
2947 continue;
2949 copy_format(srgb_format, format);
2951 if (gl_info->supported[EXT_TEXTURE_SRGB]
2952 && !(adapter->d3d_info.wined3d_creation_flags & WINED3D_SRGB_READ_WRITE_CONTROL))
2954 srgb_format->glInternal = format_texture_info[i].gl_srgb_internal;
2955 srgb_format->glGammaInternal = format_texture_info[i].gl_srgb_internal;
2956 format_set_flag(srgb_format, WINED3DFMT_FLAG_SRGB_READ | WINED3DFMT_FLAG_SRGB_WRITE);
2957 query_internal_format(adapter, srgb_format, &format_texture_info[i], gl_info, srgb_write, TRUE);
2961 return TRUE;
2964 static BOOL color_match(DWORD c1, DWORD c2, BYTE max_diff)
2966 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
2967 c1 >>= 8; c2 >>= 8;
2968 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
2969 c1 >>= 8; c2 >>= 8;
2970 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
2971 c1 >>= 8; c2 >>= 8;
2972 if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
2973 return TRUE;
2976 /* A context is provided by the caller */
2977 static BOOL check_filter(const struct wined3d_gl_info *gl_info, GLenum internal)
2979 static const DWORD data[] = {0x00000000, 0xffffffff};
2980 GLuint tex, fbo, buffer;
2981 DWORD readback[16 * 1];
2982 BOOL ret = FALSE;
2984 /* Render a filtered texture and see what happens. This is intended to detect the lack of
2985 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
2986 * falling back to software. If this changes in the future this code will get fooled and
2987 * apps might hit the software path due to incorrectly advertised caps.
2989 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
2990 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
2991 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
2994 while (gl_info->gl_ops.gl.p_glGetError());
2996 gl_info->gl_ops.gl.p_glGenTextures(1, &buffer);
2997 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, buffer);
2998 memset(readback, 0x7e, sizeof(readback));
2999 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 16, 1, 0,
3000 GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, readback);
3001 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
3002 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
3003 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3004 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3005 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
3007 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
3008 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
3009 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, internal, 2, 1, 0,
3010 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
3011 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
3012 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
3013 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
3014 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
3015 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
3016 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_2D);
3018 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
3019 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3020 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, buffer, 0);
3021 gl_info->gl_ops.gl.p_glDrawBuffer(GL_COLOR_ATTACHMENT0);
3023 gl_info->gl_ops.gl.p_glViewport(0, 0, 16, 1);
3024 gl_info->gl_ops.gl.p_glDisable(GL_LIGHTING);
3025 gl_info->gl_ops.gl.p_glMatrixMode(GL_MODELVIEW);
3026 gl_info->gl_ops.gl.p_glLoadIdentity();
3027 gl_info->gl_ops.gl.p_glMatrixMode(GL_PROJECTION);
3028 gl_info->gl_ops.gl.p_glLoadIdentity();
3030 gl_info->gl_ops.gl.p_glClearColor(0, 1, 0, 0);
3031 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
3033 gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
3034 gl_info->gl_ops.gl.p_glTexCoord2f(0.0, 0.0);
3035 gl_info->gl_ops.gl.p_glVertex2f(-1.0f, -1.0f);
3036 gl_info->gl_ops.gl.p_glTexCoord2f(1.0, 0.0);
3037 gl_info->gl_ops.gl.p_glVertex2f(1.0f, -1.0f);
3038 gl_info->gl_ops.gl.p_glTexCoord2f(0.0, 1.0);
3039 gl_info->gl_ops.gl.p_glVertex2f(-1.0f, 1.0f);
3040 gl_info->gl_ops.gl.p_glTexCoord2f(1.0, 1.0);
3041 gl_info->gl_ops.gl.p_glVertex2f(1.0f, 1.0f);
3042 gl_info->gl_ops.gl.p_glEnd();
3044 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, buffer);
3045 memset(readback, 0x7f, sizeof(readback));
3046 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, readback);
3047 if (color_match(readback[6], 0xffffffff, 5) || color_match(readback[6], 0x00000000, 5)
3048 || color_match(readback[9], 0xffffffff, 5) || color_match(readback[9], 0x00000000, 5))
3050 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
3051 readback[6], readback[9]);
3052 ret = FALSE;
3054 else
3056 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
3057 readback[6], readback[9]);
3058 ret = TRUE;
3061 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
3062 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
3063 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
3064 gl_info->gl_ops.gl.p_glDeleteTextures(1, &buffer);
3065 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
3067 if (gl_info->gl_ops.gl.p_glGetError())
3069 FIXME("Error during filtering test for format %x, returning no filtering\n", internal);
3070 ret = FALSE;
3073 return ret;
3076 static void init_format_filter_info(struct wined3d_gl_info *gl_info, enum wined3d_pci_vendor vendor)
3078 struct wined3d_format *format;
3079 unsigned int fmt_idx, i;
3080 static const enum wined3d_format_id fmts16[] =
3082 WINED3DFMT_R16_FLOAT,
3083 WINED3DFMT_R16G16_FLOAT,
3084 WINED3DFMT_R16G16B16A16_FLOAT,
3086 BOOL filtered;
3088 if (gl_info->supported[ARB_INTERNALFORMAT_QUERY2])
3089 /* This was already handled by init_format_texture_info(). */
3090 return;
3092 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO
3093 || !gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
3095 WARN("No FBO support, or no FBO ORM, guessing filter info from GL caps\n");
3096 if (vendor == HW_VENDOR_NVIDIA && gl_info->supported[ARB_TEXTURE_FLOAT])
3098 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
3099 filtered = TRUE;
3101 else if (gl_info->limits.glsl_varyings > 44)
3103 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
3104 filtered = TRUE;
3106 else
3108 TRACE("Assuming no float16 blending\n");
3109 filtered = FALSE;
3112 if (filtered)
3114 for (i = 0; i < ARRAY_SIZE(fmts16); ++i)
3116 fmt_idx = get_format_idx(fmts16[i]);
3117 format_set_flag(&gl_info->formats[fmt_idx], WINED3DFMT_FLAG_FILTERING);
3120 return;
3123 for (i = 0; i < ARRAY_SIZE(fmts16); ++i)
3125 fmt_idx = get_format_idx(fmts16[i]);
3126 format = &gl_info->formats[fmt_idx];
3127 if (!format->glInternal) continue; /* Not supported by GL */
3129 filtered = check_filter(gl_info, gl_info->formats[fmt_idx].glInternal);
3130 if (filtered)
3132 TRACE("Format %s supports filtering\n", debug_d3dformat(fmts16[i]));
3133 format_set_flag(format, WINED3DFMT_FLAG_FILTERING);
3135 else
3137 TRACE("Format %s does not support filtering\n", debug_d3dformat(fmts16[i]));
3142 static void apply_format_fixups(struct wined3d_adapter *adapter, struct wined3d_gl_info *gl_info)
3144 unsigned int i;
3145 int idx;
3147 idx = get_format_idx(WINED3DFMT_R16_FLOAT);
3148 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3149 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
3151 idx = get_format_idx(WINED3DFMT_R32_FLOAT);
3152 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3153 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
3155 idx = get_format_idx(WINED3DFMT_R16G16_UNORM);
3156 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3157 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
3159 idx = get_format_idx(WINED3DFMT_R16G16_FLOAT);
3160 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3161 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
3163 idx = get_format_idx(WINED3DFMT_R32G32_FLOAT);
3164 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3165 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_W);
3167 /* GL_ATI_envmap_bumpmap in theory supports R8G8_SNORM but is no longer supported by
3168 * any driver. */
3169 if (gl_info->supported[NV_TEXTURE_SHADER] || gl_info->supported[EXT_TEXTURE_SNORM])
3171 /* R8G8_SNORM and R16G16_SNORM need a fixup of the undefined blue channel. OpenGL
3172 * returns 0.0 when sampling from it, DirectX 1.0. So we always have in-shader
3173 * conversion for this format. */
3174 idx = get_format_idx(WINED3DFMT_R8G8_SNORM);
3175 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3176 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
3177 idx = get_format_idx(WINED3DFMT_R16G16_SNORM);
3178 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3179 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
3181 else
3183 /* Emulate using unsigned formats. This requires load-time conversion in addition to the
3184 * fixups here. */
3185 idx = get_format_idx(WINED3DFMT_R8G8_SNORM);
3186 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3187 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
3188 idx = get_format_idx(WINED3DFMT_R16G16_SNORM);
3189 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3190 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
3191 idx = get_format_idx(WINED3DFMT_R8G8B8A8_SNORM);
3192 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3193 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 1, CHANNEL_SOURCE_Z, 1, CHANNEL_SOURCE_W);
3194 idx = get_format_idx(WINED3DFMT_R5G5_SNORM_L6_UNORM);
3195 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3196 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE);
3199 if (!gl_info->supported[NV_TEXTURE_SHADER])
3201 idx = get_format_idx(WINED3DFMT_R8G8_SNORM_L8X8_UNORM);
3202 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3203 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_W);
3206 if (gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] || gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC])
3208 idx = get_format_idx(WINED3DFMT_ATI1N);
3209 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3210 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X);
3212 idx = get_format_idx(WINED3DFMT_ATI2N);
3213 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3214 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
3216 else if (gl_info->supported[ATI_TEXTURE_COMPRESSION_3DC])
3218 idx = get_format_idx(WINED3DFMT_ATI2N);
3219 gl_info->formats[idx].color_fixup= create_color_fixup_desc(
3220 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_W, 0, CHANNEL_SOURCE_ONE, 0, CHANNEL_SOURCE_ONE);
3223 if (!gl_info->supported[APPLE_YCBCR_422])
3225 idx = get_format_idx(WINED3DFMT_YUY2);
3226 gl_info->formats[idx].color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_YUY2);
3228 idx = get_format_idx(WINED3DFMT_UYVY);
3229 gl_info->formats[idx].color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_UYVY);
3232 idx = get_format_idx(WINED3DFMT_YV12);
3233 format_set_flag(&gl_info->formats[idx], WINED3DFMT_FLAG_HEIGHT_SCALE);
3234 gl_info->formats[idx].height_scale.numerator = 3;
3235 gl_info->formats[idx].height_scale.denominator = 2;
3236 gl_info->formats[idx].color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_YV12);
3238 idx = get_format_idx(WINED3DFMT_NV12);
3239 format_set_flag(&gl_info->formats[idx], WINED3DFMT_FLAG_HEIGHT_SCALE);
3240 gl_info->formats[idx].height_scale.numerator = 3;
3241 gl_info->formats[idx].height_scale.denominator = 2;
3242 gl_info->formats[idx].color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_NV12);
3244 if (!gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
3246 idx = get_format_idx(WINED3DFMT_A8_UNORM);
3247 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3248 0, CHANNEL_SOURCE_ZERO, 0, CHANNEL_SOURCE_ZERO, 0, CHANNEL_SOURCE_ZERO, 0, CHANNEL_SOURCE_X);
3249 idx = get_format_idx(WINED3DFMT_L8A8_UNORM);
3250 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3251 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y);
3252 idx = get_format_idx(WINED3DFMT_L4A4_UNORM);
3253 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3254 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_Y);
3255 idx = get_format_idx(WINED3DFMT_L16_UNORM);
3256 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3257 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE);
3258 idx = get_format_idx(WINED3DFMT_INTZ);
3259 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3260 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X);
3263 if (gl_info->supported[ARB_TEXTURE_RG])
3265 idx = get_format_idx(WINED3DFMT_L8_UNORM);
3266 gl_info->formats[idx].color_fixup = create_color_fixup_desc(
3267 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_X, 0, CHANNEL_SOURCE_ONE);
3270 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
3272 idx = get_format_idx(WINED3DFMT_P8_UINT);
3273 gl_info->formats[idx].color_fixup = create_complex_fixup_desc(COMPLEX_FIXUP_P8);
3276 if (gl_info->supported[ARB_VERTEX_ARRAY_BGRA])
3278 idx = get_format_idx(WINED3DFMT_B8G8R8A8_UNORM);
3279 gl_info->formats[idx].gl_vtx_format = GL_BGRA;
3282 if (!gl_info->supported[ARB_HALF_FLOAT_VERTEX])
3284 /* Do not change the size of the type, it is CPU side. We have to change the GPU-side information though.
3285 * It is the job of the vertex buffer code to make sure that the vbos have the right format */
3286 idx = get_format_idx(WINED3DFMT_R16G16_FLOAT);
3287 gl_info->formats[idx].gl_vtx_type = GL_FLOAT;
3289 idx = get_format_idx(WINED3DFMT_R16G16B16A16_FLOAT);
3290 gl_info->formats[idx].gl_vtx_type = GL_FLOAT;
3293 if (!gl_info->supported[ARB_HALF_FLOAT_PIXEL])
3295 idx = get_format_idx(WINED3DFMT_R16_FLOAT);
3296 format_clear_flag(&gl_info->formats[idx], WINED3DFMT_FLAG_TEXTURE);
3298 idx = get_format_idx(WINED3DFMT_R16G16_FLOAT);
3299 format_clear_flag(&gl_info->formats[idx], WINED3DFMT_FLAG_TEXTURE);
3301 idx = get_format_idx(WINED3DFMT_R16G16B16A16_FLOAT);
3302 format_clear_flag(&gl_info->formats[idx], WINED3DFMT_FLAG_TEXTURE);
3305 if (gl_info->quirks & WINED3D_QUIRK_BROKEN_RGBA16)
3307 idx = get_format_idx(WINED3DFMT_R16G16B16A16_UNORM);
3308 format_clear_flag(&gl_info->formats[idx], WINED3DFMT_FLAG_TEXTURE);
3311 /* ATI instancing hack: Although ATI cards do not support Shader Model
3312 * 3.0, they support instancing. To query if the card supports instancing
3313 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
3314 * is used. Should an application check for this, provide a proper return
3315 * value. We can do instancing with all shader versions, but we need
3316 * vertex shaders.
3318 * Additionally applications have to set the D3DRS_POINTSIZE render state
3319 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
3320 * doesn't need that and just ignores it.
3322 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
3323 /* FIXME: This should just check the shader backend caps. */
3324 if (gl_info->supported[ARB_VERTEX_PROGRAM] || gl_info->supported[ARB_VERTEX_SHADER])
3326 idx = get_format_idx(WINED3DFMT_INST);
3327 format_set_flag(&gl_info->formats[idx], WINED3DFMT_FLAG_TEXTURE);
3330 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
3331 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
3332 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
3333 * MAKEFOURCC('N','V','D','B') and then controlled by setting
3334 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
3335 * value. */
3336 if (gl_info->supported[EXT_DEPTH_BOUNDS_TEST])
3338 idx = get_format_idx(WINED3DFMT_NVDB);
3339 format_set_flag(&gl_info->formats[idx], WINED3DFMT_FLAG_TEXTURE);
3342 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
3343 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
3344 * RENDERTARGET usage. */
3345 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
3347 idx = get_format_idx(WINED3DFMT_RESZ);
3348 format_set_flag(&gl_info->formats[idx], WINED3DFMT_FLAG_TEXTURE | WINED3DFMT_FLAG_RENDERTARGET);
3351 for (i = 0; i < gl_info->format_count; ++i)
3353 struct wined3d_format *format = &gl_info->formats[i];
3355 if (!(format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_TEXTURE))
3356 continue;
3358 if (is_identity_fixup(format->color_fixup))
3359 continue;
3361 TRACE("Checking support for fixup:\n");
3362 dump_color_fixup_desc(format->color_fixup);
3363 if (!adapter->shader_backend->shader_color_fixup_supported(format->color_fixup)
3364 || !adapter->fragment_pipe->color_fixup_supported(format->color_fixup))
3366 TRACE("[FAILED]\n");
3367 format_clear_flag(format, WINED3DFMT_FLAG_TEXTURE);
3369 else
3371 TRACE("[OK]\n");
3375 /* GL_EXT_texture_compression_s3tc does not support 3D textures. Some Windows drivers
3376 * for dx9 GPUs support it, some do not, so not supporting DXTn volumes is OK for d3d9.
3378 * Note that GL_NV_texture_compression_vtc adds this functionality to OpenGL, but the
3379 * block layout is not compatible with the one used by d3d. See volume_dxt5_test. */
3380 idx = get_format_idx(WINED3DFMT_DXT1);
3381 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3382 idx = get_format_idx(WINED3DFMT_DXT2);
3383 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3384 idx = get_format_idx(WINED3DFMT_DXT3);
3385 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3386 idx = get_format_idx(WINED3DFMT_DXT4);
3387 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3388 idx = get_format_idx(WINED3DFMT_DXT5);
3389 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3390 idx = get_format_idx(WINED3DFMT_BC1_UNORM);
3391 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3392 idx = get_format_idx(WINED3DFMT_BC1_UNORM_SRGB);
3393 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3394 idx = get_format_idx(WINED3DFMT_BC2_UNORM);
3395 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3396 idx = get_format_idx(WINED3DFMT_BC2_UNORM_SRGB);
3397 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3398 idx = get_format_idx(WINED3DFMT_BC3_UNORM);
3399 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3400 idx = get_format_idx(WINED3DFMT_BC3_UNORM_SRGB);
3401 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3402 /* Similarly with ATI1N / ATI2N and GL_ARB_texture_compression_rgtc. */
3403 idx = get_format_idx(WINED3DFMT_ATI1N);
3404 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3405 idx = get_format_idx(WINED3DFMT_ATI2N);
3406 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3407 idx = get_format_idx(WINED3DFMT_BC4_UNORM);
3408 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3409 idx = get_format_idx(WINED3DFMT_BC5_UNORM);
3410 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3411 idx = get_format_idx(WINED3DFMT_BC5_SNORM);
3412 gl_info->formats[idx].flags[WINED3D_GL_RES_TYPE_TEX_3D] &= ~WINED3DFMT_FLAG_TEXTURE;
3415 static unsigned int calculate_vertex_attribute_size(GLenum type, unsigned int component_count)
3417 switch (type)
3419 case GL_HALF_FLOAT:
3420 return component_count * sizeof(GLhalfNV);
3421 case GL_FLOAT:
3422 return component_count * sizeof(GLfloat);
3423 case GL_BYTE:
3424 return component_count * sizeof(GLbyte);
3425 case GL_UNSIGNED_BYTE:
3426 return component_count * sizeof(GLubyte);
3427 case GL_SHORT:
3428 return component_count * sizeof(GLshort);
3429 case GL_UNSIGNED_SHORT:
3430 return component_count * sizeof(GLushort);
3431 case GL_INT:
3432 return component_count * sizeof(GLint);
3433 case GL_UNSIGNED_INT:
3434 return component_count * sizeof(GLuint);
3435 case GL_UNSIGNED_INT_2_10_10_10_REV:
3436 return sizeof(GLuint);
3437 default:
3438 FIXME("Unhandled GL type %#x.\n", type);
3439 return 0;
3443 static BOOL init_format_vertex_info(struct wined3d_gl_info *gl_info)
3445 struct wined3d_format *format;
3446 unsigned int i;
3448 for (i = 0; i < ARRAY_SIZE(format_vertex_info); ++i)
3450 if (!(format = get_format_internal(gl_info, format_vertex_info[i].id)))
3451 return FALSE;
3453 if (!gl_info->supported[format_vertex_info[i].extension])
3454 continue;
3456 format->emit_idx = format_vertex_info[i].emit_idx;
3457 format->component_count = format_vertex_info[i].component_count;
3458 format->gl_vtx_type = format_vertex_info[i].gl_vtx_type;
3459 format->gl_vtx_format = format_vertex_info[i].component_count;
3460 format->gl_normalized = format_vertex_info[i].gl_normalized;
3461 if (!(format->attribute_size = calculate_vertex_attribute_size(format->gl_vtx_type,
3462 format->component_count)))
3464 ERR("Invalid attribute size for vertex format %s (%#x).\n",
3465 debug_d3dformat(format_vertex_info[i].id), format_vertex_info[i].id);
3466 return FALSE;
3470 return TRUE;
3473 static BOOL init_typeless_formats(struct wined3d_gl_info *gl_info)
3475 unsigned int flags[WINED3D_GL_RES_TYPE_COUNT];
3476 unsigned int i, j;
3478 for (i = 0; i < ARRAY_SIZE(typed_formats); ++i)
3480 struct wined3d_format *format, *typeless_format;
3482 if (!(format = get_format_internal(gl_info, typed_formats[i].id)))
3483 return FALSE;
3484 if (!(typeless_format = get_format_internal(gl_info, typed_formats[i].typeless_id)))
3485 return FALSE;
3487 memcpy(flags, typeless_format->flags, sizeof(flags));
3488 copy_format(typeless_format, format);
3489 for (j = 0; j < ARRAY_SIZE(typeless_format->flags); ++j)
3490 typeless_format->flags[j] |= flags[j];
3493 for (i = 0; i < ARRAY_SIZE(typeless_depth_stencil_formats); ++i)
3495 struct wined3d_format *typeless_format, *typeless_ds_format, *ds_format;
3496 struct wined3d_format *depth_view_format, *stencil_view_format;
3497 enum wined3d_format_id format_id;
3499 if (!(typeless_format = get_format_internal(gl_info, typeless_depth_stencil_formats[i].typeless_id)))
3500 return FALSE;
3501 if (!(ds_format = get_format_internal(gl_info, typeless_depth_stencil_formats[i].depth_stencil_id)))
3502 return FALSE;
3504 typeless_ds_format = &gl_info->formats[WINED3D_FORMAT_COUNT + i];
3505 typeless_ds_format->id = typeless_depth_stencil_formats[i].typeless_id;
3506 copy_format(typeless_ds_format, ds_format);
3507 for (j = 0; j < ARRAY_SIZE(typeless_ds_format->flags); ++j)
3509 typeless_ds_format->flags[j] = typeless_format->flags[j];
3510 typeless_format->flags[j] &= ~(WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL);
3513 if ((format_id = typeless_depth_stencil_formats[i].depth_view_id))
3515 if (!(depth_view_format = get_format_internal(gl_info, format_id)))
3516 return FALSE;
3517 copy_format(depth_view_format, ds_format);
3519 if ((format_id = typeless_depth_stencil_formats[i].stencil_view_id))
3521 if (!(stencil_view_format = get_format_internal(gl_info, format_id)))
3522 return FALSE;
3523 copy_format(stencil_view_format, ds_format);
3527 return TRUE;
3530 /* Context activation is done by the caller. */
3531 BOOL wined3d_adapter_init_format_info(struct wined3d_adapter *adapter, struct wined3d_caps_gl_ctx *ctx)
3533 struct wined3d_gl_info *gl_info = &adapter->gl_info;
3535 if (!init_format_base_info(gl_info)) return FALSE;
3536 if (!init_format_block_info(gl_info)) goto fail;
3538 if (!ctx) /* WINED3D_NO3D */
3539 return TRUE;
3541 if (!init_format_texture_info(adapter, gl_info)) goto fail;
3542 if (!init_format_vertex_info(gl_info)) goto fail;
3544 apply_format_fixups(adapter, gl_info);
3545 init_format_fbo_compat_info(ctx);
3546 init_format_filter_info(gl_info, adapter->driver_info.vendor);
3547 if (!init_typeless_formats(gl_info)) goto fail;
3549 return TRUE;
3551 fail:
3552 HeapFree(GetProcessHeap(), 0, gl_info->formats);
3553 gl_info->formats = NULL;
3554 return FALSE;
3557 BOOL wined3d_caps_gl_ctx_test_viewport_subpixel_bits(struct wined3d_caps_gl_ctx *ctx)
3559 static const struct wined3d_color red = {1.0f, 0.0f, 0.0f, 1.0f};
3560 const struct wined3d_gl_info *gl_info = ctx->gl_info;
3561 static const float offset = -63.0f / 128.0f;
3562 GLuint texture, fbo;
3563 DWORD readback[4];
3564 unsigned int i;
3566 gl_info->gl_ops.gl.p_glGenTextures(1, &texture);
3567 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, texture);
3568 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
3569 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ARRAY_SIZE(readback), 1, 0,
3570 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
3571 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
3572 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3573 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
3574 GL_TEXTURE_2D, texture, 0);
3575 checkGLcall("create resources");
3577 gl_info->gl_ops.gl.p_glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
3578 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
3579 GL_EXTCALL(glViewportIndexedf(0, offset, offset, 4.0f, 1.0f));
3580 draw_test_quad(ctx, NULL, &red);
3581 checkGLcall("draw");
3583 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, texture);
3584 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0,
3585 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, readback);
3586 checkGLcall("readback");
3588 TRACE("Readback colors are 0x%08x, 0x%08x, 0x%08x, 0x%08x.\n",
3589 readback[0], readback[1], readback[2], readback[3]);
3591 gl_info->gl_ops.gl.p_glDeleteTextures(1, &texture);
3592 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
3593 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
3594 checkGLcall("delete resources");
3596 for (i = 0; i < ARRAY_SIZE(readback); ++i)
3598 if (readback[i] != 0xffff0000)
3599 return FALSE;
3601 return TRUE;
3604 float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx *ctx, GLenum format)
3606 const struct wined3d_gl_info *gl_info = ctx->gl_info;
3607 static const struct wined3d_color blue = {0.0f, 0.0f, 1.0f, 1.0f};
3608 GLuint fbo, color, depth;
3609 unsigned int low = 0, high = 32, cur;
3610 DWORD readback[256];
3611 static const struct wined3d_vec3 geometry[] =
3613 {-1.0f, -1.0f, -1.0f},
3614 { 1.0f, -1.0f, 0.0f},
3615 {-1.0f, 1.0f, -1.0f},
3616 { 1.0f, 1.0f, 0.0f},
3619 /* Most drivers want 2^23 for fixed point depth buffers, including r300g, r600g,
3620 * Nvidia. Use this as a fallback if the detection fails. */
3621 unsigned int fallback = 23;
3623 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
3625 FIXME("No FBOs, assuming polyoffset scale of 2^%u.\n", fallback);
3626 return (float)(1u << fallback);
3629 gl_info->gl_ops.gl.p_glGenTextures(1, &color);
3630 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, color);
3631 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
3632 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);
3634 gl_info->fbo_ops.glGenRenderbuffers(1, &depth);
3635 gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, depth);
3636 gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, format, 256, 1);
3638 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
3639 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
3640 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color, 0);
3641 gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depth);
3642 checkGLcall("Setup framebuffer");
3644 gl_info->gl_ops.gl.p_glClearColor(0.0f, 0.0f, 0.5f, 0.0f);
3645 gl_info->gl_ops.gl.p_glClearDepth(0.5f);
3646 gl_info->gl_ops.gl.p_glEnable(GL_DEPTH_TEST);
3647 gl_info->gl_ops.gl.p_glEnable(GL_POLYGON_OFFSET_FILL);
3648 gl_info->gl_ops.gl.p_glViewport(0, 0, 256, 1);
3649 checkGLcall("Misc parameters");
3651 for (;;)
3653 if (high - low <= 1)
3655 ERR("PolygonOffset scale factor detection failed, using fallback value 2^%u.\n", fallback);
3656 cur = fallback;
3657 break;
3659 cur = (low + high) / 2;
3661 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
3662 /* The post viewport transform Z of the geometry runs from 0.0 to 0.5. We want to push it another
3663 * 0.25 so that the Z buffer content (0.5) cuts the quad off at half the screen. */
3664 gl_info->gl_ops.gl.p_glPolygonOffset(0.0f, (float)(1u << cur) * 0.25f);
3665 draw_test_quad(ctx, geometry, &blue);
3666 checkGLcall("Test draw");
3668 /* Rebinding texture to workaround a fglrx bug. */
3669 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, color);
3670 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, readback);
3671 checkGLcall("readback");
3673 TRACE("low %02u, high %02u, cur %2u, 0=0x%08x, 125=0x%08x, 131=0x%08x, 255=0x%08x\n",
3674 low, high, cur, readback[0], readback[125], readback[131], readback[255]);
3676 if ((readback[125] & 0xff) < 0xa0)
3677 high = cur;
3678 else if ((readback[131] & 0xff) > 0xa0)
3679 low = cur;
3680 else
3682 TRACE("Found scale factor 2^%u for format %x\n", cur, format);
3683 break;
3687 gl_info->gl_ops.gl.p_glDeleteTextures(1, &color);
3688 gl_info->fbo_ops.glDeleteRenderbuffers(1, &depth);
3689 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
3690 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
3691 checkGLcall("Delete framebuffer");
3693 gl_info->gl_ops.gl.p_glDisable(GL_DEPTH_TEST);
3694 gl_info->gl_ops.gl.p_glDisable(GL_POLYGON_OFFSET_FILL);
3695 return (float)(1u << cur);
3698 const struct wined3d_format *wined3d_get_format(const struct wined3d_gl_info *gl_info,
3699 enum wined3d_format_id format_id, unsigned int resource_usage)
3701 const struct wined3d_format *format;
3702 int idx = get_format_idx(format_id);
3703 unsigned int i;
3705 if (idx == -1)
3707 FIXME("Can't find format %s (%#x) in the format lookup table.\n",
3708 debug_d3dformat(format_id), format_id);
3709 return &gl_info->formats[get_format_idx(WINED3DFMT_UNKNOWN)];
3712 format = &gl_info->formats[idx];
3714 if (resource_usage & WINED3DUSAGE_DEPTHSTENCIL && wined3d_format_is_typeless(format))
3716 for (i = 0; i < ARRAY_SIZE(typeless_depth_stencil_formats); ++i)
3718 if (typeless_depth_stencil_formats[i].typeless_id == format_id)
3719 return &gl_info->formats[WINED3D_FORMAT_COUNT + i];
3722 FIXME("Cannot find depth/stencil typeless format %s (%#x).\n",
3723 debug_d3dformat(format_id), format_id);
3724 return &gl_info->formats[get_format_idx(WINED3DFMT_UNKNOWN)];
3727 return format;
3730 void wined3d_format_calculate_pitch(const struct wined3d_format *format, unsigned int alignment,
3731 unsigned int width, unsigned int height, unsigned int *row_pitch, unsigned int *slice_pitch)
3733 /* For block based formats, pitch means the amount of bytes to the next
3734 * row of blocks rather than the next row of pixels. */
3735 if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_BLOCKS)
3737 unsigned int row_block_count = (width + format->block_width - 1) / format->block_width;
3738 unsigned int slice_block_count = (height + format->block_height - 1) / format->block_height;
3739 *row_pitch = row_block_count * format->block_byte_count;
3740 *row_pitch = (*row_pitch + alignment - 1) & ~(alignment - 1);
3741 *slice_pitch = *row_pitch * slice_block_count;
3743 else
3745 *row_pitch = format->byte_count * width; /* Bytes / row */
3746 *row_pitch = (*row_pitch + alignment - 1) & ~(alignment - 1);
3747 *slice_pitch = *row_pitch * height;
3750 if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_HEIGHT_SCALE)
3752 /* The D3D format requirements make sure that the resulting format is an integer again */
3753 *slice_pitch *= format->height_scale.numerator;
3754 *slice_pitch /= format->height_scale.denominator;
3757 TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch, *slice_pitch);
3760 UINT wined3d_format_calculate_size(const struct wined3d_format *format, UINT alignment,
3761 UINT width, UINT height, UINT depth)
3763 unsigned int row_pitch, slice_pitch;
3765 if (format->id == WINED3DFMT_UNKNOWN)
3766 return 0;
3768 if (format->flags[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3DFMT_FLAG_BROKEN_PITCH)
3769 return width * height * depth * format->byte_count;
3771 wined3d_format_calculate_pitch(format, alignment, width, height, &row_pitch, &slice_pitch);
3773 return slice_pitch * depth;
3776 /*****************************************************************************
3777 * Trace formatting of useful values
3779 const char *debug_box(const struct wined3d_box *box)
3781 if (!box)
3782 return "(null)";
3783 return wine_dbg_sprintf("(%u, %u, %u)-(%u, %u, %u)",
3784 box->left, box->top, box->front,
3785 box->right, box->bottom, box->back);
3788 const char *debug_color(const struct wined3d_color *color)
3790 if (!color)
3791 return "(null)";
3792 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
3793 color->r, color->g, color->b, color->a);
3796 const char *debug_ivec4(const struct wined3d_ivec4 *v)
3798 if (!v)
3799 return "(null)";
3800 return wine_dbg_sprintf("{%d, %d, %d, %d}",
3801 v->x, v->y, v->z, v->w);
3804 const char *debug_uvec4(const struct wined3d_uvec4 *v)
3806 if (!v)
3807 return "(null)";
3808 return wine_dbg_sprintf("{%u, %u, %u, %u}",
3809 v->x, v->y, v->z, v->w);
3812 const char *debug_vec4(const struct wined3d_vec4 *v)
3814 if (!v)
3815 return "(null)";
3816 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
3817 v->x, v->y, v->z, v->w);
3820 const char *debug_d3dformat(enum wined3d_format_id format_id)
3822 switch (format_id)
3824 #define FMT_TO_STR(format_id) case format_id: return #format_id
3825 FMT_TO_STR(WINED3DFMT_UNKNOWN);
3826 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM);
3827 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM);
3828 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM);
3829 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM);
3830 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM);
3831 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM);
3832 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM);
3833 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM);
3834 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM);
3835 FMT_TO_STR(WINED3DFMT_P8_UINT);
3836 FMT_TO_STR(WINED3DFMT_L8_UNORM);
3837 FMT_TO_STR(WINED3DFMT_L8A8_UNORM);
3838 FMT_TO_STR(WINED3DFMT_L4A4_UNORM);
3839 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM);
3840 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM);
3841 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM);
3842 FMT_TO_STR(WINED3DFMT_R10G10B10X2_UINT);
3843 FMT_TO_STR(WINED3DFMT_R10G10B10X2_SNORM);
3844 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM);
3845 FMT_TO_STR(WINED3DFMT_UYVY);
3846 FMT_TO_STR(WINED3DFMT_YUY2);
3847 FMT_TO_STR(WINED3DFMT_YV12);
3848 FMT_TO_STR(WINED3DFMT_NV12);
3849 FMT_TO_STR(WINED3DFMT_DXT1);
3850 FMT_TO_STR(WINED3DFMT_DXT2);
3851 FMT_TO_STR(WINED3DFMT_DXT3);
3852 FMT_TO_STR(WINED3DFMT_DXT4);
3853 FMT_TO_STR(WINED3DFMT_DXT5);
3854 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8);
3855 FMT_TO_STR(WINED3DFMT_G8R8_G8B8);
3856 FMT_TO_STR(WINED3DFMT_R8G8_B8G8);
3857 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE);
3858 FMT_TO_STR(WINED3DFMT_D32_UNORM);
3859 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM);
3860 FMT_TO_STR(WINED3DFMT_X8D24_UNORM);
3861 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM);
3862 FMT_TO_STR(WINED3DFMT_L16_UNORM);
3863 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT);
3864 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx);
3865 FMT_TO_STR(WINED3DFMT_ATI1N);
3866 FMT_TO_STR(WINED3DFMT_ATI2N);
3867 FMT_TO_STR(WINED3DFMT_NVDB);
3868 FMT_TO_STR(WINED3DFMT_NVHU);
3869 FMT_TO_STR(WINED3DFMT_NVHS);
3870 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS);
3871 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT);
3872 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT);
3873 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT);
3874 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS);
3875 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT);
3876 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT);
3877 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT);
3878 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS);
3879 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT);
3880 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM);
3881 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT);
3882 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM);
3883 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT);
3884 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS);
3885 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT);
3886 FMT_TO_STR(WINED3DFMT_R32G32_UINT);
3887 FMT_TO_STR(WINED3DFMT_R32G32_SINT);
3888 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS);
3889 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT);
3890 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS);
3891 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT);
3892 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS);
3893 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM);
3894 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT);
3895 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM);
3896 FMT_TO_STR(WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM);
3897 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT);
3898 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS);
3899 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM);
3900 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB);
3901 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT);
3902 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM);
3903 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT);
3904 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS);
3905 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT);
3906 FMT_TO_STR(WINED3DFMT_R16G16_UNORM);
3907 FMT_TO_STR(WINED3DFMT_R16G16_UINT);
3908 FMT_TO_STR(WINED3DFMT_R16G16_SNORM);
3909 FMT_TO_STR(WINED3DFMT_R16G16_SINT);
3910 FMT_TO_STR(WINED3DFMT_R32_TYPELESS);
3911 FMT_TO_STR(WINED3DFMT_D32_FLOAT);
3912 FMT_TO_STR(WINED3DFMT_R32_FLOAT);
3913 FMT_TO_STR(WINED3DFMT_R32_UINT);
3914 FMT_TO_STR(WINED3DFMT_R32_SINT);
3915 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS);
3916 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT);
3917 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS);
3918 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT);
3919 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS);
3920 FMT_TO_STR(WINED3DFMT_R8G8_UNORM);
3921 FMT_TO_STR(WINED3DFMT_R8G8_UINT);
3922 FMT_TO_STR(WINED3DFMT_R8G8_SNORM);
3923 FMT_TO_STR(WINED3DFMT_R8G8_SINT);
3924 FMT_TO_STR(WINED3DFMT_R16_TYPELESS);
3925 FMT_TO_STR(WINED3DFMT_R16_FLOAT);
3926 FMT_TO_STR(WINED3DFMT_D16_UNORM);
3927 FMT_TO_STR(WINED3DFMT_R16_UNORM);
3928 FMT_TO_STR(WINED3DFMT_R16_UINT);
3929 FMT_TO_STR(WINED3DFMT_R16_SNORM);
3930 FMT_TO_STR(WINED3DFMT_R16_SINT);
3931 FMT_TO_STR(WINED3DFMT_R8_TYPELESS);
3932 FMT_TO_STR(WINED3DFMT_R8_UNORM);
3933 FMT_TO_STR(WINED3DFMT_R8_UINT);
3934 FMT_TO_STR(WINED3DFMT_R8_SNORM);
3935 FMT_TO_STR(WINED3DFMT_R8_SINT);
3936 FMT_TO_STR(WINED3DFMT_A8_UNORM);
3937 FMT_TO_STR(WINED3DFMT_R1_UNORM);
3938 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP);
3939 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM);
3940 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM);
3941 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS);
3942 FMT_TO_STR(WINED3DFMT_BC1_UNORM);
3943 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB);
3944 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS);
3945 FMT_TO_STR(WINED3DFMT_BC2_UNORM);
3946 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB);
3947 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS);
3948 FMT_TO_STR(WINED3DFMT_BC3_UNORM);
3949 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB);
3950 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS);
3951 FMT_TO_STR(WINED3DFMT_BC4_UNORM);
3952 FMT_TO_STR(WINED3DFMT_BC4_SNORM);
3953 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS);
3954 FMT_TO_STR(WINED3DFMT_BC5_UNORM);
3955 FMT_TO_STR(WINED3DFMT_BC5_SNORM);
3956 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM);
3957 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM);
3958 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM);
3959 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM);
3960 FMT_TO_STR(WINED3DFMT_B8G8R8A8_TYPELESS);
3961 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM_SRGB);
3962 FMT_TO_STR(WINED3DFMT_B8G8R8X8_TYPELESS);
3963 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM_SRGB);
3964 FMT_TO_STR(WINED3DFMT_BC6H_TYPELESS);
3965 FMT_TO_STR(WINED3DFMT_BC6H_UF16);
3966 FMT_TO_STR(WINED3DFMT_BC6H_SF16);
3967 FMT_TO_STR(WINED3DFMT_BC7_TYPELESS);
3968 FMT_TO_STR(WINED3DFMT_BC7_UNORM);
3969 FMT_TO_STR(WINED3DFMT_BC7_UNORM_SRGB);
3970 FMT_TO_STR(WINED3DFMT_INTZ);
3971 FMT_TO_STR(WINED3DFMT_RESZ);
3972 FMT_TO_STR(WINED3DFMT_NULL);
3973 FMT_TO_STR(WINED3DFMT_R16);
3974 FMT_TO_STR(WINED3DFMT_AL16);
3975 #undef FMT_TO_STR
3976 default:
3978 char fourcc[5];
3979 fourcc[0] = (char)(format_id);
3980 fourcc[1] = (char)(format_id >> 8);
3981 fourcc[2] = (char)(format_id >> 16);
3982 fourcc[3] = (char)(format_id >> 24);
3983 fourcc[4] = 0;
3984 if (isprint(fourcc[0]) && isprint(fourcc[1]) && isprint(fourcc[2]) && isprint(fourcc[3]))
3985 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id, fourcc);
3986 else
3987 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id);
3989 return "unrecognized";
3993 const char *debug_d3ddevicetype(enum wined3d_device_type device_type)
3995 switch (device_type)
3997 #define DEVTYPE_TO_STR(dev) case dev: return #dev
3998 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL);
3999 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF);
4000 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW);
4001 #undef DEVTYPE_TO_STR
4002 default:
4003 FIXME("Unrecognized device type %#x.\n", device_type);
4004 return "unrecognized";
4008 const char *debug_d3dusage(DWORD usage)
4010 char buf[552];
4012 buf[0] = '\0';
4013 #define WINED3DUSAGE_TO_STR(u) if (usage & u) { strcat(buf, " | "#u); usage &= ~u; }
4014 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RENDERTARGET);
4015 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DEPTHSTENCIL);
4016 WINED3DUSAGE_TO_STR(WINED3DUSAGE_WRITEONLY);
4017 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING);
4018 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP);
4019 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS);
4020 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES);
4021 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES);
4022 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC);
4023 WINED3DUSAGE_TO_STR(WINED3DUSAGE_AUTOGENMIPMAP);
4024 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICTED_CONTENT);
4025 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE_DRIVER);
4026 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE);
4027 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP);
4028 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTAPI);
4029 WINED3DUSAGE_TO_STR(WINED3DUSAGE_LEGACY_CUBEMAP);
4030 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTURE);
4031 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OWNDC);
4032 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL);
4033 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY);
4034 #undef WINED3DUSAGE_TO_STR
4035 if (usage) FIXME("Unrecognized usage flag(s) %#x\n", usage);
4037 return buf[0] ? wine_dbg_sprintf("%s", &buf[3]) : "0";
4040 const char *debug_d3dusagequery(DWORD usagequery)
4042 char buf[238];
4044 buf[0] = '\0';
4045 #define WINED3DUSAGEQUERY_TO_STR(u) if (usagequery & u) { strcat(buf, " | "#u); usagequery &= ~u; }
4046 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_FILTER);
4047 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP);
4048 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING);
4049 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD);
4050 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE);
4051 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE);
4052 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP);
4053 #undef WINED3DUSAGEQUERY_TO_STR
4054 if (usagequery) FIXME("Unrecognized usage query flag(s) %#x\n", usagequery);
4056 return buf[0] ? wine_dbg_sprintf("%s", &buf[3]) : "0";
4059 const char *debug_d3ddeclmethod(enum wined3d_decl_method method)
4061 switch (method)
4063 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
4064 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT);
4065 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U);
4066 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V);
4067 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV);
4068 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV);
4069 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP);
4070 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED);
4071 #undef WINED3DDECLMETHOD_TO_STR
4072 default:
4073 FIXME("Unrecognized declaration method %#x.\n", method);
4074 return "unrecognized";
4078 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage)
4080 switch (usage)
4082 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
4083 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION);
4084 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT);
4085 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES);
4086 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL);
4087 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE);
4088 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD);
4089 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT);
4090 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL);
4091 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR);
4092 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT);
4093 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR);
4094 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG);
4095 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH);
4096 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE);
4097 #undef WINED3DDECLUSAGE_TO_STR
4098 default:
4099 FIXME("Unrecognized %u declaration usage!\n", usage);
4100 return "unrecognized";
4104 const char *debug_d3dinput_classification(enum wined3d_input_classification classification)
4106 switch (classification)
4108 #define WINED3D_TO_STR(x) case x: return #x
4109 WINED3D_TO_STR(WINED3D_INPUT_PER_VERTEX_DATA);
4110 WINED3D_TO_STR(WINED3D_INPUT_PER_INSTANCE_DATA);
4111 #undef WINED3D_TO_STR
4112 default:
4113 FIXME("Unrecognized input classification %#x.\n", classification);
4114 return "unrecognized";
4118 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type)
4120 switch (resource_type)
4122 #define WINED3D_TO_STR(x) case x: return #x
4123 WINED3D_TO_STR(WINED3D_RTYPE_NONE);
4124 WINED3D_TO_STR(WINED3D_RTYPE_BUFFER);
4125 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_2D);
4126 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_3D);
4127 #undef WINED3D_TO_STR
4128 default:
4129 FIXME("Unrecognized resource type %#x.\n", resource_type);
4130 return "unrecognized";
4134 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type)
4136 switch (primitive_type)
4138 #define PRIM_TO_STR(prim) case prim: return #prim
4139 PRIM_TO_STR(WINED3D_PT_UNDEFINED);
4140 PRIM_TO_STR(WINED3D_PT_POINTLIST);
4141 PRIM_TO_STR(WINED3D_PT_LINELIST);
4142 PRIM_TO_STR(WINED3D_PT_LINESTRIP);
4143 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST);
4144 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP);
4145 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN);
4146 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ);
4147 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ);
4148 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ);
4149 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ);
4150 PRIM_TO_STR(WINED3D_PT_PATCH);
4151 #undef PRIM_TO_STR
4152 default:
4153 FIXME("Unrecognized primitive type %#x.\n", primitive_type);
4154 return "unrecognized";
4158 const char *debug_d3drenderstate(enum wined3d_render_state state)
4160 switch (state)
4162 #define D3DSTATE_TO_STR(u) case u: return #u
4163 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS);
4164 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE);
4165 D3DSTATE_TO_STR(WINED3D_RS_WRAPU);
4166 D3DSTATE_TO_STR(WINED3D_RS_WRAPV);
4167 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE);
4168 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE);
4169 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE);
4170 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN);
4171 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE);
4172 D3DSTATE_TO_STR(WINED3D_RS_ROP2);
4173 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK);
4174 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE);
4175 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE);
4176 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL);
4177 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND);
4178 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND);
4179 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE);
4180 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC);
4181 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF);
4182 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC);
4183 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE);
4184 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE);
4185 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE);
4186 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE);
4187 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE);
4188 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL);
4189 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX);
4190 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA);
4191 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR);
4192 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE);
4193 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART);
4194 D3DSTATE_TO_STR(WINED3D_RS_FOGEND);
4195 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY);
4196 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE);
4197 D3DSTATE_TO_STR(WINED3D_RS_EDGEANTIALIAS);
4198 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE);
4199 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS);
4200 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE);
4201 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY);
4202 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH);
4203 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT);
4204 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE);
4205 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL);
4206 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL);
4207 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS);
4208 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC);
4209 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF);
4210 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK);
4211 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK);
4212 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR);
4213 D3DSTATE_TO_STR(WINED3D_RS_WRAP0);
4214 D3DSTATE_TO_STR(WINED3D_RS_WRAP1);
4215 D3DSTATE_TO_STR(WINED3D_RS_WRAP2);
4216 D3DSTATE_TO_STR(WINED3D_RS_WRAP3);
4217 D3DSTATE_TO_STR(WINED3D_RS_WRAP4);
4218 D3DSTATE_TO_STR(WINED3D_RS_WRAP5);
4219 D3DSTATE_TO_STR(WINED3D_RS_WRAP6);
4220 D3DSTATE_TO_STR(WINED3D_RS_WRAP7);
4221 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING);
4222 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING);
4223 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS);
4224 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT);
4225 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE);
4226 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX);
4227 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER);
4228 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS);
4229 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE);
4230 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE);
4231 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE);
4232 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE);
4233 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE);
4234 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND);
4235 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE);
4236 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING);
4237 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE);
4238 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN);
4239 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE);
4240 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE);
4241 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A);
4242 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B);
4243 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C);
4244 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS);
4245 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK);
4246 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE);
4247 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS);
4248 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN);
4249 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX);
4250 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE);
4251 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE);
4252 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR);
4253 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP);
4254 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE);
4255 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE);
4256 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE);
4257 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS);
4258 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE);
4259 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL);
4260 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL);
4261 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X);
4262 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y);
4263 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z);
4264 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W);
4265 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION);
4266 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE);
4267 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFAIL);
4268 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILZFAIL);
4269 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILPASS);
4270 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFUNC);
4271 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1);
4272 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2);
4273 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3);
4274 D3DSTATE_TO_STR(WINED3D_RS_BLENDFACTOR);
4275 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE);
4276 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS);
4277 D3DSTATE_TO_STR(WINED3D_RS_WRAP8);
4278 D3DSTATE_TO_STR(WINED3D_RS_WRAP9);
4279 D3DSTATE_TO_STR(WINED3D_RS_WRAP10);
4280 D3DSTATE_TO_STR(WINED3D_RS_WRAP11);
4281 D3DSTATE_TO_STR(WINED3D_RS_WRAP12);
4282 D3DSTATE_TO_STR(WINED3D_RS_WRAP13);
4283 D3DSTATE_TO_STR(WINED3D_RS_WRAP14);
4284 D3DSTATE_TO_STR(WINED3D_RS_WRAP15);
4285 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE);
4286 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA);
4287 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA);
4288 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA);
4289 #undef D3DSTATE_TO_STR
4290 default:
4291 FIXME("Unrecognized %u render state!\n", state);
4292 return "unrecognized";
4296 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state)
4298 switch (state)
4300 #define D3DSTATE_TO_STR(u) case u: return #u
4301 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR);
4302 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U);
4303 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V);
4304 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W);
4305 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER);
4306 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER);
4307 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER);
4308 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS);
4309 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL);
4310 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY);
4311 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE);
4312 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX);
4313 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET);
4314 #undef D3DSTATE_TO_STR
4315 default:
4316 FIXME("Unrecognized %u sampler state!\n", state);
4317 return "unrecognized";
4321 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type)
4323 switch (filter_type)
4325 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
4326 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE);
4327 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT);
4328 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR);
4329 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC);
4330 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC);
4331 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC);
4332 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD);
4333 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD);
4334 #undef D3DTEXTUREFILTERTYPE_TO_STR
4335 default:
4336 FIXME("Unrecognized texture filter type 0x%08x.\n", filter_type);
4337 return "unrecognized";
4341 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state)
4343 switch (state)
4345 #define D3DSTATE_TO_STR(u) case u: return #u
4346 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP);
4347 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1);
4348 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2);
4349 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP);
4350 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1);
4351 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2);
4352 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00);
4353 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01);
4354 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10);
4355 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11);
4356 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX);
4357 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE);
4358 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET);
4359 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS);
4360 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0);
4361 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0);
4362 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG);
4363 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT);
4364 #undef D3DSTATE_TO_STR
4365 default:
4366 FIXME("Unrecognized %u texture state!\n", state);
4367 return "unrecognized";
4371 const char *debug_d3dtop(enum wined3d_texture_op d3dtop)
4373 switch (d3dtop)
4375 #define D3DTOP_TO_STR(u) case u: return #u
4376 D3DTOP_TO_STR(WINED3D_TOP_DISABLE);
4377 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1);
4378 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2);
4379 D3DTOP_TO_STR(WINED3D_TOP_MODULATE);
4380 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X);
4381 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X);
4382 D3DTOP_TO_STR(WINED3D_TOP_ADD);
4383 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED);
4384 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X);
4385 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT);
4386 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH);
4387 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA);
4388 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA);
4389 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA);
4390 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM);
4391 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA);
4392 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE);
4393 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR);
4394 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA);
4395 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR);
4396 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA);
4397 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP);
4398 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE);
4399 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3);
4400 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD);
4401 D3DTOP_TO_STR(WINED3D_TOP_LERP);
4402 #undef D3DTOP_TO_STR
4403 default:
4404 FIXME("Unrecognized texture op %#x.\n", d3dtop);
4405 return "unrecognized";
4409 const char *debug_d3dtstype(enum wined3d_transform_state tstype)
4411 switch (tstype)
4413 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
4414 TSTYPE_TO_STR(WINED3D_TS_VIEW);
4415 TSTYPE_TO_STR(WINED3D_TS_PROJECTION);
4416 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0);
4417 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1);
4418 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2);
4419 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3);
4420 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4);
4421 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5);
4422 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6);
4423 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7);
4424 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
4425 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(1));
4426 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(2));
4427 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(3));
4428 #undef TSTYPE_TO_STR
4429 default:
4430 if (tstype > 256 && tstype < 512)
4432 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype);
4433 return ("WINED3D_TS_WORLD_MATRIX > 0");
4435 FIXME("Unrecognized transform state %#x.\n", tstype);
4436 return "unrecognized";
4440 const char *debug_shader_type(enum wined3d_shader_type type)
4442 switch(type)
4444 #define WINED3D_TO_STR(type) case type: return #type
4445 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL);
4446 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX);
4447 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY);
4448 WINED3D_TO_STR(WINED3D_SHADER_TYPE_HULL);
4449 WINED3D_TO_STR(WINED3D_SHADER_TYPE_DOMAIN);
4450 WINED3D_TO_STR(WINED3D_SHADER_TYPE_COMPUTE);
4451 #undef WINED3D_TO_STR
4452 default:
4453 FIXME("Unrecognized shader type %#x.\n", type);
4454 return "unrecognized";
4458 const char *debug_d3dstate(DWORD state)
4460 if (STATE_IS_RENDER(state))
4461 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state - STATE_RENDER(0)));
4462 if (STATE_IS_TEXTURESTAGE(state))
4464 DWORD texture_stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
4465 DWORD texture_state = state - STATE_TEXTURESTAGE(texture_stage, 0);
4466 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
4467 texture_stage, debug_d3dtexturestate(texture_state));
4469 if (STATE_IS_SAMPLER(state))
4470 return wine_dbg_sprintf("STATE_SAMPLER(%#x)", state - STATE_SAMPLER(0));
4471 if (STATE_IS_COMPUTE_SHADER(state))
4472 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE));
4473 if (STATE_IS_GRAPHICS_SHADER(state))
4474 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state - STATE_SHADER(0)));
4475 if (STATE_IS_COMPUTE_CONSTANT_BUFFER(state))
4476 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE));
4477 if (STATE_IS_GRAPHICS_CONSTANT_BUFFER(state))
4478 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state - STATE_CONSTANT_BUFFER(0)));
4479 if (STATE_IS_COMPUTE_SHADER_RESOURCE_BINDING(state))
4480 return "STATE_COMPUTE_SHADER_RESOURCE_BINDING";
4481 if (STATE_IS_GRAPHICS_SHADER_RESOURCE_BINDING(state))
4482 return "STATE_GRAPHICS_SHADER_RESOURCE_BINDING";
4483 if (STATE_IS_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING(state))
4484 return "STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING";
4485 if (STATE_IS_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING(state))
4486 return "STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING";
4487 if (STATE_IS_TRANSFORM(state))
4488 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state - STATE_TRANSFORM(0)));
4489 if (STATE_IS_STREAMSRC(state))
4490 return "STATE_STREAMSRC";
4491 if (STATE_IS_INDEXBUFFER(state))
4492 return "STATE_INDEXBUFFER";
4493 if (STATE_IS_VDECL(state))
4494 return "STATE_VDECL";
4495 if (STATE_IS_VIEWPORT(state))
4496 return "STATE_VIEWPORT";
4497 if (STATE_IS_LIGHT_TYPE(state))
4498 return "STATE_LIGHT_TYPE";
4499 if (STATE_IS_ACTIVELIGHT(state))
4500 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state - STATE_ACTIVELIGHT(0));
4501 if (STATE_IS_SCISSORRECT(state))
4502 return "STATE_SCISSORRECT";
4503 if (STATE_IS_CLIPPLANE(state))
4504 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state - STATE_CLIPPLANE(0));
4505 if (STATE_IS_MATERIAL(state))
4506 return "STATE_MATERIAL";
4507 if (STATE_IS_FRONTFACE(state))
4508 return "STATE_FRONTFACE";
4509 if (STATE_IS_POINTSPRITECOORDORIGIN(state))
4510 return "STATE_POINTSPRITECOORDORIGIN";
4511 if (STATE_IS_BASEVERTEXINDEX(state))
4512 return "STATE_BASEVERTEXINDEX";
4513 if (STATE_IS_FRAMEBUFFER(state))
4514 return "STATE_FRAMEBUFFER";
4515 if (STATE_IS_POINT_ENABLE(state))
4516 return "STATE_POINT_ENABLE";
4517 if (STATE_IS_COLOR_KEY(state))
4518 return "STATE_COLOR_KEY";
4519 if (STATE_IS_STREAM_OUTPUT(state))
4520 return "STATE_STREAM_OUTPUT";
4522 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state);
4525 const char *debug_d3dpool(enum wined3d_pool pool)
4527 switch (pool)
4529 #define POOL_TO_STR(p) case p: return #p
4530 POOL_TO_STR(WINED3D_POOL_DEFAULT);
4531 POOL_TO_STR(WINED3D_POOL_MANAGED);
4532 POOL_TO_STR(WINED3D_POOL_SYSTEM_MEM);
4533 POOL_TO_STR(WINED3D_POOL_SCRATCH);
4534 #undef POOL_TO_STR
4535 default:
4536 FIXME("Unrecognized pool %#x.\n", pool);
4537 return "unrecognized";
4541 const char *debug_fboattachment(GLenum attachment)
4543 switch(attachment)
4545 #define WINED3D_TO_STR(x) case x: return #x
4546 WINED3D_TO_STR(GL_COLOR_ATTACHMENT0);
4547 WINED3D_TO_STR(GL_COLOR_ATTACHMENT1);
4548 WINED3D_TO_STR(GL_COLOR_ATTACHMENT2);
4549 WINED3D_TO_STR(GL_COLOR_ATTACHMENT3);
4550 WINED3D_TO_STR(GL_COLOR_ATTACHMENT4);
4551 WINED3D_TO_STR(GL_COLOR_ATTACHMENT5);
4552 WINED3D_TO_STR(GL_COLOR_ATTACHMENT6);
4553 WINED3D_TO_STR(GL_COLOR_ATTACHMENT7);
4554 WINED3D_TO_STR(GL_COLOR_ATTACHMENT8);
4555 WINED3D_TO_STR(GL_COLOR_ATTACHMENT9);
4556 WINED3D_TO_STR(GL_COLOR_ATTACHMENT10);
4557 WINED3D_TO_STR(GL_COLOR_ATTACHMENT11);
4558 WINED3D_TO_STR(GL_COLOR_ATTACHMENT12);
4559 WINED3D_TO_STR(GL_COLOR_ATTACHMENT13);
4560 WINED3D_TO_STR(GL_COLOR_ATTACHMENT14);
4561 WINED3D_TO_STR(GL_COLOR_ATTACHMENT15);
4562 WINED3D_TO_STR(GL_DEPTH_ATTACHMENT);
4563 WINED3D_TO_STR(GL_STENCIL_ATTACHMENT);
4564 #undef WINED3D_TO_STR
4565 default:
4566 return wine_dbg_sprintf("Unknown FBO attachment %#x", attachment);
4570 const char *debug_fbostatus(GLenum status) {
4571 switch(status) {
4572 #define FBOSTATUS_TO_STR(u) case u: return #u
4573 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE);
4574 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
4575 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT);
4576 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT);
4577 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT);
4578 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER);
4579 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER);
4580 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE);
4581 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS);
4582 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB);
4583 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED);
4584 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED);
4585 #undef FBOSTATUS_TO_STR
4586 default:
4587 FIXME("Unrecognized FBO status 0x%08x.\n", status);
4588 return "unrecognized";
4592 const char *debug_glerror(GLenum error) {
4593 switch(error) {
4594 #define GLERROR_TO_STR(u) case u: return #u
4595 GLERROR_TO_STR(GL_NO_ERROR);
4596 GLERROR_TO_STR(GL_INVALID_ENUM);
4597 GLERROR_TO_STR(GL_INVALID_VALUE);
4598 GLERROR_TO_STR(GL_INVALID_OPERATION);
4599 GLERROR_TO_STR(GL_STACK_OVERFLOW);
4600 GLERROR_TO_STR(GL_STACK_UNDERFLOW);
4601 GLERROR_TO_STR(GL_OUT_OF_MEMORY);
4602 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION);
4603 #undef GLERROR_TO_STR
4604 default:
4605 FIXME("Unrecognized GL error 0x%08x.\n", error);
4606 return "unrecognized";
4610 static const char *debug_fixup_channel_source(enum fixup_channel_source source)
4612 switch(source)
4614 #define WINED3D_TO_STR(x) case x: return #x
4615 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO);
4616 WINED3D_TO_STR(CHANNEL_SOURCE_ONE);
4617 WINED3D_TO_STR(CHANNEL_SOURCE_X);
4618 WINED3D_TO_STR(CHANNEL_SOURCE_Y);
4619 WINED3D_TO_STR(CHANNEL_SOURCE_Z);
4620 WINED3D_TO_STR(CHANNEL_SOURCE_W);
4621 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0);
4622 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1);
4623 #undef WINED3D_TO_STR
4624 default:
4625 FIXME("Unrecognized fixup_channel_source %#x\n", source);
4626 return "unrecognized";
4630 static const char *debug_complex_fixup(enum complex_fixup fixup)
4632 switch(fixup)
4634 #define WINED3D_TO_STR(x) case x: return #x
4635 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2);
4636 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY);
4637 WINED3D_TO_STR(COMPLEX_FIXUP_YV12);
4638 WINED3D_TO_STR(COMPLEX_FIXUP_NV12);
4639 WINED3D_TO_STR(COMPLEX_FIXUP_P8);
4640 #undef WINED3D_TO_STR
4641 default:
4642 FIXME("Unrecognized complex fixup %#x\n", fixup);
4643 return "unrecognized";
4647 void dump_color_fixup_desc(struct color_fixup_desc fixup)
4649 if (is_complex_fixup(fixup))
4651 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup)));
4652 return;
4655 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup.x_source), fixup.x_sign_fixup ? ", SIGN_FIXUP" : "");
4656 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup.y_source), fixup.y_sign_fixup ? ", SIGN_FIXUP" : "");
4657 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup.z_source), fixup.z_sign_fixup ? ", SIGN_FIXUP" : "");
4658 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup.w_source), fixup.w_sign_fixup ? ", SIGN_FIXUP" : "");
4661 BOOL is_invalid_op(const struct wined3d_state *state, int stage,
4662 enum wined3d_texture_op op, DWORD arg1, DWORD arg2, DWORD arg3)
4664 if (op == WINED3D_TOP_DISABLE)
4665 return FALSE;
4666 if (state->textures[stage])
4667 return FALSE;
4669 if ((arg1 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
4670 && op != WINED3D_TOP_SELECT_ARG2)
4671 return TRUE;
4672 if ((arg2 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
4673 && op != WINED3D_TOP_SELECT_ARG1)
4674 return TRUE;
4675 if ((arg3 & WINED3DTA_SELECTMASK) == WINED3DTA_TEXTURE
4676 && (op == WINED3D_TOP_MULTIPLY_ADD || op == WINED3D_TOP_LERP))
4677 return TRUE;
4679 return FALSE;
4682 void get_identity_matrix(struct wined3d_matrix *mat)
4684 static const struct wined3d_matrix identity =
4686 1.0f, 0.0f, 0.0f, 0.0f,
4687 0.0f, 1.0f, 0.0f, 0.0f,
4688 0.0f, 0.0f, 1.0f, 0.0f,
4689 0.0f, 0.0f, 0.0f, 1.0f,
4692 *mat = identity;
4695 void get_modelview_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
4696 unsigned int index, struct wined3d_matrix *mat)
4698 if (context->last_was_rhw)
4699 get_identity_matrix(mat);
4700 else
4701 multiply_matrix(mat, &state->transforms[WINED3D_TS_VIEW], &state->transforms[WINED3D_TS_WORLD_MATRIX(index)]);
4704 void get_projection_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
4705 struct wined3d_matrix *mat)
4707 BOOL clip_control = context->gl_info->supported[ARB_CLIP_CONTROL];
4708 BOOL flip = !clip_control && context->render_offscreen;
4709 float center_offset;
4711 /* There are a couple of additional things we have to take into account
4712 * here besides the projection transformation itself:
4713 * - We need to flip along the y-axis in case of offscreen rendering.
4714 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
4715 * - <= D3D9 coordinates refer to pixel centers while GL coordinates
4716 * refer to pixel corners.
4717 * - D3D has a top-left filling convention. We need to maintain this
4718 * even after the y-flip mentioned above.
4719 * In order to handle the last two points, we translate by
4720 * (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to
4721 * translating slightly less than half a pixel. We want the difference to
4722 * be large enough that it doesn't get lost due to rounding inside the
4723 * driver, but small enough to prevent it from interfering with any
4724 * anti-aliasing. */
4726 if (!clip_control && context->d3d_info->wined3d_creation_flags & WINED3D_PIXEL_CENTER_INTEGER)
4727 center_offset = 63.0f / 64.0f;
4728 else
4729 center_offset = -1.0f / 64.0f;
4731 if (context->last_was_rhw)
4733 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
4734 float x = state->viewport.x;
4735 float y = state->viewport.y;
4736 float w = state->viewport.width;
4737 float h = state->viewport.height;
4738 float x_scale = 2.0f / w;
4739 float x_offset = (center_offset - (2.0f * x) - w) / w;
4740 float y_scale = flip ? 2.0f / h : 2.0f / -h;
4741 float y_offset = flip
4742 ? (center_offset - (2.0f * y) - h) / h
4743 : (center_offset - (2.0f * y) - h) / -h;
4744 enum wined3d_depth_buffer_type zenable = state->fb->depth_stencil ?
4745 state->render_states[WINED3D_RS_ZENABLE] : WINED3D_ZB_FALSE;
4746 float z_scale = zenable ? clip_control ? 1.0f : 2.0f : 0.0f;
4747 float z_offset = zenable ? clip_control ? 0.0f : -1.0f : 0.0f;
4748 const struct wined3d_matrix projection =
4750 x_scale, 0.0f, 0.0f, 0.0f,
4751 0.0f, y_scale, 0.0f, 0.0f,
4752 0.0f, 0.0f, z_scale, 0.0f,
4753 x_offset, y_offset, z_offset, 1.0f,
4756 *mat = projection;
4758 else
4760 float y_scale = flip ? -1.0f : 1.0f;
4761 float x_offset = center_offset / state->viewport.width;
4762 float y_offset = flip
4763 ? center_offset / state->viewport.height
4764 : -center_offset / state->viewport.height;
4765 float z_scale = clip_control ? 1.0f : 2.0f;
4766 float z_offset = clip_control ? 0.0f : -1.0f;
4767 const struct wined3d_matrix projection =
4769 1.0f, 0.0f, 0.0f, 0.0f,
4770 0.0f, y_scale, 0.0f, 0.0f,
4771 0.0f, 0.0f, z_scale, 0.0f,
4772 x_offset, y_offset, z_offset, 1.0f,
4775 multiply_matrix(mat, &projection, &state->transforms[WINED3D_TS_PROJECTION]);
4779 /* Setup this textures matrix according to the texture flags. */
4780 static void compute_texture_matrix(const struct wined3d_gl_info *gl_info, const struct wined3d_matrix *matrix,
4781 DWORD flags, BOOL calculated_coords, BOOL transformed, enum wined3d_format_id format_id,
4782 BOOL ffp_proj_control, struct wined3d_matrix *out_matrix)
4784 struct wined3d_matrix mat;
4786 if (flags == WINED3D_TTFF_DISABLE || flags == WINED3D_TTFF_COUNT1 || transformed)
4788 get_identity_matrix(out_matrix);
4789 return;
4792 if (flags == (WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED))
4794 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
4795 return;
4798 mat = *matrix;
4800 if (flags & WINED3D_TTFF_PROJECTED)
4802 if (!ffp_proj_control)
4804 switch (flags & ~WINED3D_TTFF_PROJECTED)
4806 case WINED3D_TTFF_COUNT2:
4807 mat._14 = mat._12;
4808 mat._24 = mat._22;
4809 mat._34 = mat._32;
4810 mat._44 = mat._42;
4811 mat._12 = mat._22 = mat._32 = mat._42 = 0.0f;
4812 break;
4813 case WINED3D_TTFF_COUNT3:
4814 mat._14 = mat._13;
4815 mat._24 = mat._23;
4816 mat._34 = mat._33;
4817 mat._44 = mat._43;
4818 mat._13 = mat._23 = mat._33 = mat._43 = 0.0f;
4819 break;
4823 else
4825 /* Under Direct3D the R/Z coord can be used for translation, under
4826 * OpenGL we use the Q coord instead. */
4827 if (!calculated_coords)
4829 switch (format_id)
4831 /* Direct3D passes the default 1.0 in the 2nd coord, while GL
4832 * passes it in the 4th. Swap 2nd and 4th coord. No need to
4833 * store the value of mat._41 in mat._21 because the input
4834 * value to the transformation will be 0, so the matrix value
4835 * is irrelevant. */
4836 case WINED3DFMT_R32_FLOAT:
4837 mat._41 = mat._21;
4838 mat._42 = mat._22;
4839 mat._43 = mat._23;
4840 mat._44 = mat._24;
4841 break;
4842 /* See above, just 3rd and 4th coord. */
4843 case WINED3DFMT_R32G32_FLOAT:
4844 mat._41 = mat._31;
4845 mat._42 = mat._32;
4846 mat._43 = mat._33;
4847 mat._44 = mat._34;
4848 break;
4849 case WINED3DFMT_R32G32B32_FLOAT: /* Opengl defaults match dx defaults */
4850 case WINED3DFMT_R32G32B32A32_FLOAT: /* No defaults apply, all app defined */
4852 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
4853 * into a bad place. The division elimination below will apply to make sure the
4854 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
4856 case WINED3DFMT_UNKNOWN: /* No texture coords, 0/0/0/1 defaults are passed */
4857 break;
4858 default:
4859 FIXME("Unexpected fixed function texture coord input\n");
4862 if (!ffp_proj_control)
4864 switch (flags & ~WINED3D_TTFF_PROJECTED)
4866 /* case WINED3D_TTFF_COUNT1: Won't ever get here. */
4867 case WINED3D_TTFF_COUNT2:
4868 mat._13 = mat._23 = mat._33 = mat._43 = 0.0f;
4869 /* OpenGL divides the first 3 vertex coordinates by the 4th by
4870 * default, which is essentially the same as D3DTTFF_PROJECTED.
4871 * Make sure that the 4th coordinate evaluates to 1.0 to
4872 * eliminate that.
4874 * If the fixed function pipeline is used, the 4th value
4875 * remains unused, so there is no danger in doing this. With
4876 * vertex shaders we have a problem. Should an application hit
4877 * that problem, the code here would have to check for pixel
4878 * shaders, and the shader has to undo the default GL divide.
4880 * A more serious problem occurs if the application passes 4
4881 * coordinates in, and the 4th is != 1.0 (OpenGL default).
4882 * This would have to be fixed with immediate mode draws. */
4883 default:
4884 mat._14 = mat._24 = mat._34 = 0.0f; mat._44 = 1.0f;
4889 *out_matrix = mat;
4892 void get_texture_matrix(const struct wined3d_context *context, const struct wined3d_state *state,
4893 unsigned int tex, struct wined3d_matrix *mat)
4895 const struct wined3d_device *device = context->device;
4896 const struct wined3d_gl_info *gl_info = context->gl_info;
4897 BOOL generated = (state->texture_states[tex][WINED3D_TSS_TEXCOORD_INDEX] & 0xffff0000)
4898 != WINED3DTSS_TCI_PASSTHRU;
4899 unsigned int coord_idx = min(state->texture_states[tex][WINED3D_TSS_TEXCOORD_INDEX & 0x0000ffff],
4900 MAX_TEXTURES - 1);
4902 compute_texture_matrix(gl_info, &state->transforms[WINED3D_TS_TEXTURE0 + tex],
4903 state->texture_states[tex][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS],
4904 generated, context->last_was_rhw,
4905 context->stream_info.use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coord_idx))
4906 ? context->stream_info.elements[WINED3D_FFP_TEXCOORD0 + coord_idx].format->id
4907 : WINED3DFMT_UNKNOWN,
4908 device->shader_backend->shader_has_ffp_proj_control(device->shader_priv), mat);
4910 if ((context->lastWasPow2Texture & (1u << tex)) && state->textures[tex])
4912 if (generated)
4913 FIXME("Non-power-of-two texture being used with generated texture coords.\n");
4914 /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
4915 * fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
4916 if (!use_ps(state))
4918 TRACE("Non-power-of-two texture matrix multiply fixup.\n");
4919 multiply_matrix(mat, mat, (struct wined3d_matrix *)state->textures[tex]->pow2_matrix);
4924 void get_pointsize_minmax(const struct wined3d_context *context, const struct wined3d_state *state,
4925 float *out_min, float *out_max)
4927 union
4929 DWORD d;
4930 float f;
4931 } min, max;
4933 min.d = state->render_states[WINED3D_RS_POINTSIZE_MIN];
4934 max.d = state->render_states[WINED3D_RS_POINTSIZE_MAX];
4936 if (min.f > max.f)
4937 min.f = max.f;
4939 *out_min = min.f;
4940 *out_max = max.f;
4943 void get_pointsize(const struct wined3d_context *context, const struct wined3d_state *state,
4944 float *out_pointsize, float *out_att)
4946 /* POINTSCALEENABLE controls how point size value is treated. If set to
4947 * true, the point size is scaled with respect to height of viewport.
4948 * When set to false point size is in pixels. */
4949 union
4951 DWORD d;
4952 float f;
4953 } pointsize, a, b, c;
4955 out_att[0] = 1.0f;
4956 out_att[1] = 0.0f;
4957 out_att[2] = 0.0f;
4959 pointsize.d = state->render_states[WINED3D_RS_POINTSIZE];
4960 a.d = state->render_states[WINED3D_RS_POINTSCALE_A];
4961 b.d = state->render_states[WINED3D_RS_POINTSCALE_B];
4962 c.d = state->render_states[WINED3D_RS_POINTSCALE_C];
4964 if (state->render_states[WINED3D_RS_POINTSCALEENABLE])
4966 float scale_factor = state->viewport.height * state->viewport.height;
4968 out_att[0] = a.f / scale_factor;
4969 out_att[1] = b.f / scale_factor;
4970 out_att[2] = c.f / scale_factor;
4972 *out_pointsize = pointsize.f;
4975 void get_fog_start_end(const struct wined3d_context *context, const struct wined3d_state *state,
4976 float *start, float *end)
4978 union
4980 DWORD d;
4981 float f;
4982 } tmpvalue;
4984 switch (context->fog_source)
4986 case FOGSOURCE_VS:
4987 *start = 1.0f;
4988 *end = 0.0f;
4989 break;
4991 case FOGSOURCE_COORD:
4992 *start = 255.0f;
4993 *end = 0.0f;
4994 break;
4996 case FOGSOURCE_FFP:
4997 tmpvalue.d = state->render_states[WINED3D_RS_FOGSTART];
4998 *start = tmpvalue.f;
4999 tmpvalue.d = state->render_states[WINED3D_RS_FOGEND];
5000 *end = tmpvalue.f;
5001 /* Special handling for fog_start == fog_end. In d3d with vertex
5002 * fog, everything is fogged. With table fog, everything with
5003 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
5004 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
5005 if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE && *start == *end)
5007 *start = -INFINITY;
5008 *end = 0.0f;
5010 break;
5012 default:
5013 /* This should not happen, context->fog_source is set in wined3d, not the app. */
5014 ERR("Unexpected fog coordinate source.\n");
5015 *start = 0.0f;
5016 *end = 0.0f;
5020 /* Note: It's the caller's responsibility to ensure values can be expressed
5021 * in the requested format. UNORM formats for example can only express values
5022 * in the range 0.0f -> 1.0f. */
5023 DWORD wined3d_format_convert_from_float(const struct wined3d_format *format, const struct wined3d_color *color)
5025 static const struct
5027 enum wined3d_format_id format_id;
5028 struct wined3d_vec4 mul;
5029 struct wined3d_uvec4 shift;
5031 float_conv[] =
5033 {WINED3DFMT_B8G8R8A8_UNORM, { 255.0f, 255.0f, 255.0f, 255.0f}, {16, 8, 0, 24}},
5034 {WINED3DFMT_B8G8R8X8_UNORM, { 255.0f, 255.0f, 255.0f, 255.0f}, {16, 8, 0, 24}},
5035 {WINED3DFMT_B8G8R8_UNORM, { 255.0f, 255.0f, 255.0f, 255.0f}, {16, 8, 0, 24}},
5036 {WINED3DFMT_B5G6R5_UNORM, { 31.0f, 63.0f, 31.0f, 0.0f}, {11, 5, 0, 0}},
5037 {WINED3DFMT_B5G5R5A1_UNORM, { 31.0f, 31.0f, 31.0f, 1.0f}, {10, 5, 0, 15}},
5038 {WINED3DFMT_B5G5R5X1_UNORM, { 31.0f, 31.0f, 31.0f, 1.0f}, {10, 5, 0, 15}},
5039 {WINED3DFMT_R8_UNORM, { 255.0f, 0.0f, 0.0f, 0.0f}, { 0, 0, 0, 0}},
5040 {WINED3DFMT_A8_UNORM, { 0.0f, 0.0f, 0.0f, 255.0f}, { 0, 0, 0, 0}},
5041 {WINED3DFMT_B4G4R4A4_UNORM, { 15.0f, 15.0f, 15.0f, 15.0f}, { 8, 4, 0, 12}},
5042 {WINED3DFMT_B4G4R4X4_UNORM, { 15.0f, 15.0f, 15.0f, 15.0f}, { 8, 4, 0, 12}},
5043 {WINED3DFMT_B2G3R3_UNORM, { 7.0f, 7.0f, 3.0f, 0.0f}, { 5, 2, 0, 0}},
5044 {WINED3DFMT_R8G8B8A8_UNORM, { 255.0f, 255.0f, 255.0f, 255.0f}, { 0, 8, 16, 24}},
5045 {WINED3DFMT_R8G8B8X8_UNORM, { 255.0f, 255.0f, 255.0f, 255.0f}, { 0, 8, 16, 24}},
5046 {WINED3DFMT_B10G10R10A2_UNORM, { 1023.0f, 1023.0f, 1023.0f, 3.0f}, {20, 10, 0, 30}},
5047 {WINED3DFMT_R10G10B10A2_UNORM, { 1023.0f, 1023.0f, 1023.0f, 3.0f}, { 0, 10, 20, 30}},
5048 {WINED3DFMT_P8_UINT, { 0.0f, 0.0f, 0.0f, 255.0f}, { 0, 0, 0, 0}},
5049 {WINED3DFMT_S1_UINT_D15_UNORM, { 32767.0f, 0.0f, 0.0f, 0.0f}, { 0, 0, 0, 0}},
5050 {WINED3DFMT_D16_UNORM, { 65535.0f, 0.0f, 0.0f, 0.0f}, { 0, 0, 0, 0}},
5052 static const struct
5054 enum wined3d_format_id format_id;
5055 struct wined3d_dvec4 mul;
5056 struct wined3d_uvec4 shift;
5058 double_conv[] =
5060 {WINED3DFMT_D24_UNORM_S8_UINT, { 16777215.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
5061 {WINED3DFMT_X8D24_UNORM, { 16777215.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
5062 {WINED3DFMT_D32_UNORM, {4294967295.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
5064 unsigned int i;
5065 DWORD ret;
5067 TRACE("Converting color %s to format %s.\n", debug_color(color), debug_d3dformat(format->id));
5069 for (i = 0; i < ARRAY_SIZE(float_conv); ++i)
5071 if (format->id != float_conv[i].format_id)
5072 continue;
5074 ret = ((DWORD)((color->r * float_conv[i].mul.x) + 0.5f)) << float_conv[i].shift.x;
5075 ret |= ((DWORD)((color->g * float_conv[i].mul.y) + 0.5f)) << float_conv[i].shift.y;
5076 ret |= ((DWORD)((color->b * float_conv[i].mul.z) + 0.5f)) << float_conv[i].shift.z;
5077 ret |= ((DWORD)((color->a * float_conv[i].mul.w) + 0.5f)) << float_conv[i].shift.w;
5079 TRACE("Returning 0x%08x.\n", ret);
5081 return ret;
5084 for (i = 0; i < ARRAY_SIZE(double_conv); ++i)
5086 if (format->id != double_conv[i].format_id)
5087 continue;
5089 ret = ((DWORD)((color->r * double_conv[i].mul.x) + 0.5)) << double_conv[i].shift.x;
5090 ret |= ((DWORD)((color->g * double_conv[i].mul.y) + 0.5)) << double_conv[i].shift.y;
5091 ret |= ((DWORD)((color->b * double_conv[i].mul.z) + 0.5)) << double_conv[i].shift.z;
5092 ret |= ((DWORD)((color->a * double_conv[i].mul.w) + 0.5)) << double_conv[i].shift.w;
5094 TRACE("Returning 0x%08x.\n", ret);
5096 return ret;
5099 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format->id));
5101 return 0;
5104 static float color_to_float(DWORD color, DWORD size, DWORD offset)
5106 DWORD mask = size < 32 ? (1u << size) - 1 : ~0u;
5108 if (!size)
5109 return 1.0f;
5111 color >>= offset;
5112 color &= mask;
5114 return (float)color / (float)mask;
5117 void wined3d_format_get_float_color_key(const struct wined3d_format *format,
5118 const struct wined3d_color_key *key, struct wined3d_color *float_colors)
5120 struct wined3d_color slop;
5122 switch (format->id)
5124 case WINED3DFMT_B8G8R8_UNORM:
5125 case WINED3DFMT_B8G8R8A8_UNORM:
5126 case WINED3DFMT_B8G8R8X8_UNORM:
5127 case WINED3DFMT_B5G6R5_UNORM:
5128 case WINED3DFMT_B5G5R5X1_UNORM:
5129 case WINED3DFMT_B5G5R5A1_UNORM:
5130 case WINED3DFMT_B4G4R4A4_UNORM:
5131 case WINED3DFMT_B2G3R3_UNORM:
5132 case WINED3DFMT_R8_UNORM:
5133 case WINED3DFMT_A8_UNORM:
5134 case WINED3DFMT_B2G3R3A8_UNORM:
5135 case WINED3DFMT_B4G4R4X4_UNORM:
5136 case WINED3DFMT_R10G10B10A2_UNORM:
5137 case WINED3DFMT_R10G10B10A2_SNORM:
5138 case WINED3DFMT_R8G8B8A8_UNORM:
5139 case WINED3DFMT_R8G8B8X8_UNORM:
5140 case WINED3DFMT_R16G16_UNORM:
5141 case WINED3DFMT_B10G10R10A2_UNORM:
5142 slop.r = 0.5f / ((1u << format->red_size) - 1);
5143 slop.g = 0.5f / ((1u << format->green_size) - 1);
5144 slop.b = 0.5f / ((1u << format->blue_size) - 1);
5145 slop.a = 0.5f / ((1u << format->alpha_size) - 1);
5147 float_colors[0].r = color_to_float(key->color_space_low_value, format->red_size, format->red_offset)
5148 - slop.r;
5149 float_colors[0].g = color_to_float(key->color_space_low_value, format->green_size, format->green_offset)
5150 - slop.g;
5151 float_colors[0].b = color_to_float(key->color_space_low_value, format->blue_size, format->blue_offset)
5152 - slop.b;
5153 float_colors[0].a = color_to_float(key->color_space_low_value, format->alpha_size, format->alpha_offset)
5154 - slop.a;
5156 float_colors[1].r = color_to_float(key->color_space_high_value, format->red_size, format->red_offset)
5157 + slop.r;
5158 float_colors[1].g = color_to_float(key->color_space_high_value, format->green_size, format->green_offset)
5159 + slop.g;
5160 float_colors[1].b = color_to_float(key->color_space_high_value, format->blue_size, format->blue_offset)
5161 + slop.b;
5162 float_colors[1].a = color_to_float(key->color_space_high_value, format->alpha_size, format->alpha_offset)
5163 + slop.a;
5164 break;
5166 case WINED3DFMT_P8_UINT:
5167 float_colors[0].r = 0.0f;
5168 float_colors[0].g = 0.0f;
5169 float_colors[0].b = 0.0f;
5170 float_colors[0].a = (key->color_space_low_value - 0.5f) / 255.0f;
5172 float_colors[1].r = 0.0f;
5173 float_colors[1].g = 0.0f;
5174 float_colors[1].b = 0.0f;
5175 float_colors[1].a = (key->color_space_high_value + 0.5f) / 255.0f;
5176 break;
5178 default:
5179 ERR("Unhandled color key to float conversion for format %s.\n", debug_d3dformat(format->id));
5183 /* DirectDraw stuff */
5184 enum wined3d_format_id pixelformat_for_depth(DWORD depth)
5186 switch (depth)
5188 case 8: return WINED3DFMT_P8_UINT;
5189 case 15: return WINED3DFMT_B5G5R5X1_UNORM;
5190 case 16: return WINED3DFMT_B5G6R5_UNORM;
5191 case 24: return WINED3DFMT_B8G8R8X8_UNORM; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
5192 case 32: return WINED3DFMT_B8G8R8X8_UNORM; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
5193 default: return WINED3DFMT_UNKNOWN;
5197 void multiply_matrix(struct wined3d_matrix *dst, const struct wined3d_matrix *src1, const struct wined3d_matrix *src2)
5199 struct wined3d_matrix tmp;
5201 /* Now do the multiplication 'by hand'.
5202 I know that all this could be optimised, but this will be done later :-) */
5203 tmp._11 = (src1->_11 * src2->_11) + (src1->_21 * src2->_12) + (src1->_31 * src2->_13) + (src1->_41 * src2->_14);
5204 tmp._21 = (src1->_11 * src2->_21) + (src1->_21 * src2->_22) + (src1->_31 * src2->_23) + (src1->_41 * src2->_24);
5205 tmp._31 = (src1->_11 * src2->_31) + (src1->_21 * src2->_32) + (src1->_31 * src2->_33) + (src1->_41 * src2->_34);
5206 tmp._41 = (src1->_11 * src2->_41) + (src1->_21 * src2->_42) + (src1->_31 * src2->_43) + (src1->_41 * src2->_44);
5208 tmp._12 = (src1->_12 * src2->_11) + (src1->_22 * src2->_12) + (src1->_32 * src2->_13) + (src1->_42 * src2->_14);
5209 tmp._22 = (src1->_12 * src2->_21) + (src1->_22 * src2->_22) + (src1->_32 * src2->_23) + (src1->_42 * src2->_24);
5210 tmp._32 = (src1->_12 * src2->_31) + (src1->_22 * src2->_32) + (src1->_32 * src2->_33) + (src1->_42 * src2->_34);
5211 tmp._42 = (src1->_12 * src2->_41) + (src1->_22 * src2->_42) + (src1->_32 * src2->_43) + (src1->_42 * src2->_44);
5213 tmp._13 = (src1->_13 * src2->_11) + (src1->_23 * src2->_12) + (src1->_33 * src2->_13) + (src1->_43 * src2->_14);
5214 tmp._23 = (src1->_13 * src2->_21) + (src1->_23 * src2->_22) + (src1->_33 * src2->_23) + (src1->_43 * src2->_24);
5215 tmp._33 = (src1->_13 * src2->_31) + (src1->_23 * src2->_32) + (src1->_33 * src2->_33) + (src1->_43 * src2->_34);
5216 tmp._43 = (src1->_13 * src2->_41) + (src1->_23 * src2->_42) + (src1->_33 * src2->_43) + (src1->_43 * src2->_44);
5218 tmp._14 = (src1->_14 * src2->_11) + (src1->_24 * src2->_12) + (src1->_34 * src2->_13) + (src1->_44 * src2->_14);
5219 tmp._24 = (src1->_14 * src2->_21) + (src1->_24 * src2->_22) + (src1->_34 * src2->_23) + (src1->_44 * src2->_24);
5220 tmp._34 = (src1->_14 * src2->_31) + (src1->_24 * src2->_32) + (src1->_34 * src2->_33) + (src1->_44 * src2->_34);
5221 tmp._44 = (src1->_14 * src2->_41) + (src1->_24 * src2->_42) + (src1->_34 * src2->_43) + (src1->_44 * src2->_44);
5223 *dst = tmp;
5226 DWORD get_flexible_vertex_size(DWORD d3dvtVertexType) {
5227 DWORD size = 0;
5228 int i;
5229 int numTextures = (d3dvtVertexType & WINED3DFVF_TEXCOUNT_MASK) >> WINED3DFVF_TEXCOUNT_SHIFT;
5231 if (d3dvtVertexType & WINED3DFVF_NORMAL) size += 3 * sizeof(float);
5232 if (d3dvtVertexType & WINED3DFVF_DIFFUSE) size += sizeof(DWORD);
5233 if (d3dvtVertexType & WINED3DFVF_SPECULAR) size += sizeof(DWORD);
5234 if (d3dvtVertexType & WINED3DFVF_PSIZE) size += sizeof(DWORD);
5235 switch (d3dvtVertexType & WINED3DFVF_POSITION_MASK) {
5236 case WINED3DFVF_XYZ: size += 3 * sizeof(float); break;
5237 case WINED3DFVF_XYZRHW: size += 4 * sizeof(float); break;
5238 case WINED3DFVF_XYZB1: size += 4 * sizeof(float); break;
5239 case WINED3DFVF_XYZB2: size += 5 * sizeof(float); break;
5240 case WINED3DFVF_XYZB3: size += 6 * sizeof(float); break;
5241 case WINED3DFVF_XYZB4: size += 7 * sizeof(float); break;
5242 case WINED3DFVF_XYZB5: size += 8 * sizeof(float); break;
5243 case WINED3DFVF_XYZW: size += 4 * sizeof(float); break;
5244 default: ERR("Unexpected position mask\n");
5246 for (i = 0; i < numTextures; i++) {
5247 size += GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType, i) * sizeof(float);
5250 return size;
5253 unsigned int wined3d_max_compat_varyings(const struct wined3d_gl_info *gl_info)
5255 /* On core profile we have to also count diffuse and specular colors and the
5256 * fog coordinate. */
5257 return gl_info->supported[WINED3D_GL_LEGACY_CONTEXT] ? MAX_TEXTURES * 4 : (MAX_TEXTURES + 2) * 4 + 1;
5260 void gen_ffp_frag_op(const struct wined3d_context *context, const struct wined3d_state *state,
5261 struct ffp_frag_settings *settings, BOOL ignore_textype)
5263 #define ARG1 0x01
5264 #define ARG2 0x02
5265 #define ARG0 0x04
5266 static const unsigned char args[WINED3D_TOP_LERP + 1] =
5268 /* undefined */ 0,
5269 /* D3DTOP_DISABLE */ 0,
5270 /* D3DTOP_SELECTARG1 */ ARG1,
5271 /* D3DTOP_SELECTARG2 */ ARG2,
5272 /* D3DTOP_MODULATE */ ARG1 | ARG2,
5273 /* D3DTOP_MODULATE2X */ ARG1 | ARG2,
5274 /* D3DTOP_MODULATE4X */ ARG1 | ARG2,
5275 /* D3DTOP_ADD */ ARG1 | ARG2,
5276 /* D3DTOP_ADDSIGNED */ ARG1 | ARG2,
5277 /* D3DTOP_ADDSIGNED2X */ ARG1 | ARG2,
5278 /* D3DTOP_SUBTRACT */ ARG1 | ARG2,
5279 /* D3DTOP_ADDSMOOTH */ ARG1 | ARG2,
5280 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1 | ARG2,
5281 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1 | ARG2,
5282 /* D3DTOP_BLENDFACTORALPHA */ ARG1 | ARG2,
5283 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1 | ARG2,
5284 /* D3DTOP_BLENDCURRENTALPHA */ ARG1 | ARG2,
5285 /* D3DTOP_PREMODULATE */ ARG1 | ARG2,
5286 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1 | ARG2,
5287 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1 | ARG2,
5288 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1 | ARG2,
5289 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1 | ARG2,
5290 /* D3DTOP_BUMPENVMAP */ ARG1 | ARG2,
5291 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1 | ARG2,
5292 /* D3DTOP_DOTPRODUCT3 */ ARG1 | ARG2,
5293 /* D3DTOP_MULTIPLYADD */ ARG1 | ARG2 | ARG0,
5294 /* D3DTOP_LERP */ ARG1 | ARG2 | ARG0
5296 unsigned int i;
5297 DWORD ttff;
5298 DWORD cop, aop, carg0, carg1, carg2, aarg0, aarg1, aarg2;
5299 const struct wined3d_gl_info *gl_info = context->gl_info;
5300 const struct wined3d_d3d_info *d3d_info = context->d3d_info;
5302 settings->padding = 0;
5304 for (i = 0; i < d3d_info->limits.ffp_blend_stages; ++i)
5306 const struct wined3d_texture *texture;
5308 settings->op[i].padding = 0;
5309 if (state->texture_states[i][WINED3D_TSS_COLOR_OP] == WINED3D_TOP_DISABLE)
5311 settings->op[i].cop = WINED3D_TOP_DISABLE;
5312 settings->op[i].aop = WINED3D_TOP_DISABLE;
5313 settings->op[i].carg0 = settings->op[i].carg1 = settings->op[i].carg2 = ARG_UNUSED;
5314 settings->op[i].aarg0 = settings->op[i].aarg1 = settings->op[i].aarg2 = ARG_UNUSED;
5315 settings->op[i].color_fixup = COLOR_FIXUP_IDENTITY;
5316 settings->op[i].dst = resultreg;
5317 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_1D;
5318 settings->op[i].projected = proj_none;
5319 i++;
5320 break;
5323 if ((texture = state->textures[i]))
5325 if (can_use_texture_swizzle(gl_info, texture->resource.format))
5326 settings->op[i].color_fixup = COLOR_FIXUP_IDENTITY;
5327 else
5328 settings->op[i].color_fixup = texture->resource.format->color_fixup;
5329 if (ignore_textype)
5331 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_1D;
5333 else
5335 switch (texture->target)
5337 case GL_TEXTURE_1D:
5338 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_1D;
5339 break;
5340 case GL_TEXTURE_2D:
5341 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_2D;
5342 break;
5343 case GL_TEXTURE_3D:
5344 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_3D;
5345 break;
5346 case GL_TEXTURE_CUBE_MAP_ARB:
5347 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_CUBE;
5348 break;
5349 case GL_TEXTURE_RECTANGLE_ARB:
5350 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_RECT;
5351 break;
5354 } else {
5355 settings->op[i].color_fixup = COLOR_FIXUP_IDENTITY;
5356 settings->op[i].tex_type = WINED3D_GL_RES_TYPE_TEX_1D;
5359 cop = state->texture_states[i][WINED3D_TSS_COLOR_OP];
5360 aop = state->texture_states[i][WINED3D_TSS_ALPHA_OP];
5362 carg1 = (args[cop] & ARG1) ? state->texture_states[i][WINED3D_TSS_COLOR_ARG1] : ARG_UNUSED;
5363 carg2 = (args[cop] & ARG2) ? state->texture_states[i][WINED3D_TSS_COLOR_ARG2] : ARG_UNUSED;
5364 carg0 = (args[cop] & ARG0) ? state->texture_states[i][WINED3D_TSS_COLOR_ARG0] : ARG_UNUSED;
5366 if (is_invalid_op(state, i, cop, carg1, carg2, carg0))
5368 carg0 = ARG_UNUSED;
5369 carg2 = ARG_UNUSED;
5370 carg1 = WINED3DTA_CURRENT;
5371 cop = WINED3D_TOP_SELECT_ARG1;
5374 if (cop == WINED3D_TOP_DOTPRODUCT3)
5376 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
5377 * the color result to the alpha component of the destination
5379 aop = cop;
5380 aarg1 = carg1;
5381 aarg2 = carg2;
5382 aarg0 = carg0;
5384 else
5386 aarg1 = (args[aop] & ARG1) ? state->texture_states[i][WINED3D_TSS_ALPHA_ARG1] : ARG_UNUSED;
5387 aarg2 = (args[aop] & ARG2) ? state->texture_states[i][WINED3D_TSS_ALPHA_ARG2] : ARG_UNUSED;
5388 aarg0 = (args[aop] & ARG0) ? state->texture_states[i][WINED3D_TSS_ALPHA_ARG0] : ARG_UNUSED;
5391 if (!i && state->textures[0] && state->render_states[WINED3D_RS_COLORKEYENABLE])
5393 GLenum texture_dimensions;
5395 texture = state->textures[0];
5396 texture_dimensions = texture->target;
5398 if (texture_dimensions == GL_TEXTURE_2D || texture_dimensions == GL_TEXTURE_RECTANGLE_ARB)
5400 if (texture->async.color_key_flags & WINED3D_CKEY_SRC_BLT && !texture->resource.format->alpha_size)
5402 if (aop == WINED3D_TOP_DISABLE)
5404 aarg1 = WINED3DTA_TEXTURE;
5405 aop = WINED3D_TOP_SELECT_ARG1;
5407 else if (aop == WINED3D_TOP_SELECT_ARG1 && aarg1 != WINED3DTA_TEXTURE)
5409 if (state->render_states[WINED3D_RS_ALPHABLENDENABLE])
5411 aarg2 = WINED3DTA_TEXTURE;
5412 aop = WINED3D_TOP_MODULATE;
5414 else aarg1 = WINED3DTA_TEXTURE;
5416 else if (aop == WINED3D_TOP_SELECT_ARG2 && aarg2 != WINED3DTA_TEXTURE)
5418 if (state->render_states[WINED3D_RS_ALPHABLENDENABLE])
5420 aarg1 = WINED3DTA_TEXTURE;
5421 aop = WINED3D_TOP_MODULATE;
5423 else aarg2 = WINED3DTA_TEXTURE;
5429 if (is_invalid_op(state, i, aop, aarg1, aarg2, aarg0))
5431 aarg0 = ARG_UNUSED;
5432 aarg2 = ARG_UNUSED;
5433 aarg1 = WINED3DTA_CURRENT;
5434 aop = WINED3D_TOP_SELECT_ARG1;
5437 if (carg1 == WINED3DTA_TEXTURE || carg2 == WINED3DTA_TEXTURE || carg0 == WINED3DTA_TEXTURE
5438 || aarg1 == WINED3DTA_TEXTURE || aarg2 == WINED3DTA_TEXTURE || aarg0 == WINED3DTA_TEXTURE)
5440 ttff = state->texture_states[i][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS];
5441 if (ttff == (WINED3D_TTFF_PROJECTED | WINED3D_TTFF_COUNT3))
5442 settings->op[i].projected = proj_count3;
5443 else if (ttff & WINED3D_TTFF_PROJECTED)
5444 settings->op[i].projected = proj_count4;
5445 else
5446 settings->op[i].projected = proj_none;
5448 else
5450 settings->op[i].projected = proj_none;
5453 settings->op[i].cop = cop;
5454 settings->op[i].aop = aop;
5455 settings->op[i].carg0 = carg0;
5456 settings->op[i].carg1 = carg1;
5457 settings->op[i].carg2 = carg2;
5458 settings->op[i].aarg0 = aarg0;
5459 settings->op[i].aarg1 = aarg1;
5460 settings->op[i].aarg2 = aarg2;
5462 if (state->texture_states[i][WINED3D_TSS_RESULT_ARG] == WINED3DTA_TEMP)
5463 settings->op[i].dst = tempreg;
5464 else
5465 settings->op[i].dst = resultreg;
5468 /* Clear unsupported stages */
5469 for(; i < MAX_TEXTURES; i++) {
5470 memset(&settings->op[i], 0xff, sizeof(settings->op[i]));
5473 if (!state->render_states[WINED3D_RS_FOGENABLE])
5475 settings->fog = WINED3D_FFP_PS_FOG_OFF;
5477 else if (state->render_states[WINED3D_RS_FOGTABLEMODE] == WINED3D_FOG_NONE)
5479 if (use_vs(state) || state->vertex_declaration->position_transformed)
5481 settings->fog = WINED3D_FFP_PS_FOG_LINEAR;
5483 else
5485 switch (state->render_states[WINED3D_RS_FOGVERTEXMODE])
5487 case WINED3D_FOG_NONE:
5488 case WINED3D_FOG_LINEAR:
5489 settings->fog = WINED3D_FFP_PS_FOG_LINEAR;
5490 break;
5491 case WINED3D_FOG_EXP:
5492 settings->fog = WINED3D_FFP_PS_FOG_EXP;
5493 break;
5494 case WINED3D_FOG_EXP2:
5495 settings->fog = WINED3D_FFP_PS_FOG_EXP2;
5496 break;
5500 else
5502 switch (state->render_states[WINED3D_RS_FOGTABLEMODE])
5504 case WINED3D_FOG_LINEAR:
5505 settings->fog = WINED3D_FFP_PS_FOG_LINEAR;
5506 break;
5507 case WINED3D_FOG_EXP:
5508 settings->fog = WINED3D_FFP_PS_FOG_EXP;
5509 break;
5510 case WINED3D_FOG_EXP2:
5511 settings->fog = WINED3D_FFP_PS_FOG_EXP2;
5512 break;
5515 settings->sRGB_write = !gl_info->supported[ARB_FRAMEBUFFER_SRGB] && needs_srgb_write(context, state, state->fb);
5516 if (d3d_info->vs_clipping || !use_vs(state) || !state->render_states[WINED3D_RS_CLIPPING]
5517 || !state->render_states[WINED3D_RS_CLIPPLANEENABLE])
5519 /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
5520 * the fixed function vertex pipeline is used(which always supports clipplanes), or
5521 * if no clipplane is enabled
5523 settings->emul_clipplanes = 0;
5524 } else {
5525 settings->emul_clipplanes = 1;
5528 if (state->render_states[WINED3D_RS_COLORKEYENABLE] && state->textures[0]
5529 && state->textures[0]->async.color_key_flags & WINED3D_CKEY_SRC_BLT
5530 && settings->op[0].cop != WINED3D_TOP_DISABLE)
5531 settings->color_key_enabled = 1;
5532 else
5533 settings->color_key_enabled = 0;
5535 /* texcoords_initialized is set to meaningful values only when GL doesn't
5536 * support enough varyings to always pass around all the possible texture
5537 * coordinates.
5538 * This is used to avoid reading a varying not written by the vertex shader.
5539 * Reading uninitialized varyings on core profile contexts results in an
5540 * error while with builtin varyings on legacy contexts you get undefined
5541 * behavior. */
5542 if (d3d_info->limits.varying_count
5543 && d3d_info->limits.varying_count < wined3d_max_compat_varyings(gl_info))
5545 settings->texcoords_initialized = 0;
5546 for (i = 0; i < MAX_TEXTURES; ++i)
5548 if (use_vs(state))
5550 if (state->shader[WINED3D_SHADER_TYPE_VERTEX]->reg_maps.output_registers & (1u << i))
5551 settings->texcoords_initialized |= 1u << i;
5553 else
5555 const struct wined3d_stream_info *si = &context->stream_info;
5556 unsigned int coord_idx = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
5557 if ((state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX] >> WINED3D_FFP_TCI_SHIFT)
5558 & WINED3D_FFP_TCI_MASK
5559 || (coord_idx < MAX_TEXTURES && (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coord_idx)))))
5560 settings->texcoords_initialized |= 1u << i;
5564 else
5566 settings->texcoords_initialized = (1u << MAX_TEXTURES) - 1;
5569 settings->pointsprite = state->render_states[WINED3D_RS_POINTSPRITEENABLE]
5570 && state->gl_primitive_type == GL_POINTS;
5572 if (gl_info->supported[WINED3D_GL_LEGACY_CONTEXT])
5573 settings->alpha_test_func = WINED3D_CMP_ALWAYS - 1;
5574 else
5575 settings->alpha_test_func = (state->render_states[WINED3D_RS_ALPHATESTENABLE]
5576 ? wined3d_sanitize_cmp_func(state->render_states[WINED3D_RS_ALPHAFUNC])
5577 : WINED3D_CMP_ALWAYS) - 1;
5579 if (d3d_info->emulated_flatshading)
5580 settings->flatshading = state->render_states[WINED3D_RS_SHADEMODE] == WINED3D_SHADE_FLAT;
5581 else
5582 settings->flatshading = FALSE;
5585 const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders,
5586 const struct ffp_frag_settings *settings)
5588 struct wine_rb_entry *entry = wine_rb_get(fragment_shaders, settings);
5589 return entry ? WINE_RB_ENTRY_VALUE(entry, struct ffp_frag_desc, entry) : NULL;
5592 void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc)
5594 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
5595 * whereas desc points to an extended structure with implementation specific parts. */
5596 if (wine_rb_put(shaders, &desc->settings, &desc->entry) == -1)
5598 ERR("Failed to insert ffp frag shader.\n");
5602 /* Activates the texture dimension according to the bound D3D texture. Does
5603 * not care for the colorop or correct gl texture unit (when using nvrc).
5604 * Requires the caller to activate the correct unit. */
5605 /* Context activation is done by the caller (state handler). */
5606 void texture_activate_dimensions(const struct wined3d_texture *texture, const struct wined3d_gl_info *gl_info)
5608 if (texture)
5610 switch (texture->target)
5612 case GL_TEXTURE_2D:
5613 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
5614 checkGLcall("glDisable(GL_TEXTURE_3D)");
5615 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
5617 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
5618 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5620 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
5622 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
5623 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5625 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_2D);
5626 checkGLcall("glEnable(GL_TEXTURE_2D)");
5627 break;
5628 case GL_TEXTURE_RECTANGLE_ARB:
5629 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
5630 checkGLcall("glDisable(GL_TEXTURE_2D)");
5631 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
5632 checkGLcall("glDisable(GL_TEXTURE_3D)");
5633 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
5635 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
5636 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5638 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_RECTANGLE_ARB);
5639 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
5640 break;
5641 case GL_TEXTURE_3D:
5642 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
5644 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
5645 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5647 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
5649 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
5650 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5652 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
5653 checkGLcall("glDisable(GL_TEXTURE_2D)");
5654 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_3D);
5655 checkGLcall("glEnable(GL_TEXTURE_3D)");
5656 break;
5657 case GL_TEXTURE_CUBE_MAP_ARB:
5658 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_2D);
5659 checkGLcall("glDisable(GL_TEXTURE_2D)");
5660 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
5661 checkGLcall("glDisable(GL_TEXTURE_3D)");
5662 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
5664 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
5665 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5667 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_CUBE_MAP_ARB);
5668 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
5669 break;
5672 else
5674 gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_2D);
5675 checkGLcall("glEnable(GL_TEXTURE_2D)");
5676 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_3D);
5677 checkGLcall("glDisable(GL_TEXTURE_3D)");
5678 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
5680 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB);
5681 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5683 if (gl_info->supported[ARB_TEXTURE_RECTANGLE])
5685 gl_info->gl_ops.gl.p_glDisable(GL_TEXTURE_RECTANGLE_ARB);
5686 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5688 /* Binding textures is done by samplers. A dummy texture will be bound */
5692 /* Context activation is done by the caller (state handler). */
5693 void sampler_texdim(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
5695 DWORD sampler = state_id - STATE_SAMPLER(0);
5696 DWORD mapped_stage = context->tex_unit_map[sampler];
5698 /* No need to enable / disable anything here for unused samplers. The
5699 * tex_colorop handler takes care. Also no action is needed with pixel
5700 * shaders, or if tex_colorop will take care of this business. */
5701 if (mapped_stage == WINED3D_UNMAPPED_STAGE || mapped_stage >= context->gl_info->limits.textures)
5702 return;
5703 if (sampler >= context->lowest_disabled_stage)
5704 return;
5705 if (isStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3D_TSS_COLOR_OP)))
5706 return;
5708 texture_activate_dimensions(state->textures[sampler], context->gl_info);
5711 int wined3d_ffp_frag_program_key_compare(const void *key, const struct wine_rb_entry *entry)
5713 const struct ffp_frag_settings *ka = key;
5714 const struct ffp_frag_settings *kb = &WINE_RB_ENTRY_VALUE(entry, const struct ffp_frag_desc, entry)->settings;
5716 return memcmp(ka, kb, sizeof(*ka));
5719 void wined3d_ffp_get_vs_settings(const struct wined3d_context *context,
5720 const struct wined3d_state *state, struct wined3d_ffp_vs_settings *settings)
5722 const struct wined3d_stream_info *si = &context->stream_info;
5723 const struct wined3d_gl_info *gl_info = context->gl_info;
5724 const struct wined3d_d3d_info *d3d_info = context->d3d_info;
5725 unsigned int coord_idx, i;
5727 memset(settings, 0, sizeof(*settings));
5729 if (si->position_transformed)
5731 settings->transformed = 1;
5732 settings->point_size = state->gl_primitive_type == GL_POINTS;
5733 settings->per_vertex_point_size = !!(si->use_map & 1u << WINED3D_FFP_PSIZE);
5734 if (!state->render_states[WINED3D_RS_FOGENABLE])
5735 settings->fog_mode = WINED3D_FFP_VS_FOG_OFF;
5736 else if (state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE)
5737 settings->fog_mode = WINED3D_FFP_VS_FOG_DEPTH;
5738 else
5739 settings->fog_mode = WINED3D_FFP_VS_FOG_FOGCOORD;
5741 for (i = 0; i < MAX_TEXTURES; ++i)
5743 coord_idx = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
5744 if (coord_idx < MAX_TEXTURES && (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coord_idx))))
5745 settings->texcoords |= 1u << i;
5746 settings->texgen[i] = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
5748 if (d3d_info->limits.varying_count >= wined3d_max_compat_varyings(gl_info))
5749 settings->texcoords = (1u << MAX_TEXTURES) - 1;
5751 if (d3d_info->emulated_flatshading)
5752 settings->flatshading = state->render_states[WINED3D_RS_SHADEMODE] == WINED3D_SHADE_FLAT;
5753 else
5754 settings->flatshading = FALSE;
5756 settings->swizzle_map = si->swizzle_map;
5758 return;
5761 switch (state->render_states[WINED3D_RS_VERTEXBLEND])
5763 case WINED3D_VBF_DISABLE:
5764 case WINED3D_VBF_1WEIGHTS:
5765 case WINED3D_VBF_2WEIGHTS:
5766 case WINED3D_VBF_3WEIGHTS:
5767 settings->vertexblends = state->render_states[WINED3D_RS_VERTEXBLEND];
5768 break;
5769 default:
5770 FIXME("Unsupported vertex blending: %d\n", state->render_states[WINED3D_RS_VERTEXBLEND]);
5771 break;
5774 settings->clipping = state->render_states[WINED3D_RS_CLIPPING]
5775 && state->render_states[WINED3D_RS_CLIPPLANEENABLE];
5776 settings->normal = !!(si->use_map & (1u << WINED3D_FFP_NORMAL));
5777 settings->normalize = settings->normal && state->render_states[WINED3D_RS_NORMALIZENORMALS];
5778 settings->lighting = !!state->render_states[WINED3D_RS_LIGHTING];
5779 settings->localviewer = !!state->render_states[WINED3D_RS_LOCALVIEWER];
5780 settings->point_size = state->gl_primitive_type == GL_POINTS;
5781 settings->per_vertex_point_size = !!(si->use_map & 1u << WINED3D_FFP_PSIZE);
5783 if (state->render_states[WINED3D_RS_COLORVERTEX] && (si->use_map & (1u << WINED3D_FFP_DIFFUSE)))
5785 settings->diffuse_source = state->render_states[WINED3D_RS_DIFFUSEMATERIALSOURCE];
5786 settings->emissive_source = state->render_states[WINED3D_RS_EMISSIVEMATERIALSOURCE];
5787 settings->ambient_source = state->render_states[WINED3D_RS_AMBIENTMATERIALSOURCE];
5788 settings->specular_source = state->render_states[WINED3D_RS_SPECULARMATERIALSOURCE];
5790 else
5792 settings->diffuse_source = WINED3D_MCS_MATERIAL;
5793 settings->emissive_source = WINED3D_MCS_MATERIAL;
5794 settings->ambient_source = WINED3D_MCS_MATERIAL;
5795 settings->specular_source = WINED3D_MCS_MATERIAL;
5798 for (i = 0; i < MAX_TEXTURES; ++i)
5800 coord_idx = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
5801 if (coord_idx < MAX_TEXTURES && (si->use_map & (1u << (WINED3D_FFP_TEXCOORD0 + coord_idx))))
5802 settings->texcoords |= 1u << i;
5803 settings->texgen[i] = state->texture_states[i][WINED3D_TSS_TEXCOORD_INDEX];
5805 if (d3d_info->limits.varying_count >= wined3d_max_compat_varyings(gl_info))
5806 settings->texcoords = (1u << MAX_TEXTURES) - 1;
5808 for (i = 0; i < MAX_ACTIVE_LIGHTS; ++i)
5810 if (!state->lights[i])
5811 continue;
5813 switch (state->lights[i]->OriginalParms.type)
5815 case WINED3D_LIGHT_POINT:
5816 ++settings->point_light_count;
5817 break;
5818 case WINED3D_LIGHT_SPOT:
5819 ++settings->spot_light_count;
5820 break;
5821 case WINED3D_LIGHT_DIRECTIONAL:
5822 ++settings->directional_light_count;
5823 break;
5824 case WINED3D_LIGHT_PARALLELPOINT:
5825 ++settings->parallel_point_light_count;
5826 break;
5827 default:
5828 FIXME("Unhandled light type %#x.\n", state->lights[i]->OriginalParms.type);
5829 break;
5833 if (!state->render_states[WINED3D_RS_FOGENABLE])
5834 settings->fog_mode = WINED3D_FFP_VS_FOG_OFF;
5835 else if (state->render_states[WINED3D_RS_FOGTABLEMODE] != WINED3D_FOG_NONE)
5837 settings->fog_mode = WINED3D_FFP_VS_FOG_DEPTH;
5839 if (state->transforms[WINED3D_TS_PROJECTION]._14 == 0.0f
5840 && state->transforms[WINED3D_TS_PROJECTION]._24 == 0.0f
5841 && state->transforms[WINED3D_TS_PROJECTION]._34 == 0.0f
5842 && state->transforms[WINED3D_TS_PROJECTION]._44 == 1.0f)
5843 settings->ortho_fog = 1;
5845 else if (state->render_states[WINED3D_RS_FOGVERTEXMODE] == WINED3D_FOG_NONE)
5846 settings->fog_mode = WINED3D_FFP_VS_FOG_FOGCOORD;
5847 else if (state->render_states[WINED3D_RS_RANGEFOGENABLE])
5848 settings->fog_mode = WINED3D_FFP_VS_FOG_RANGE;
5849 else
5850 settings->fog_mode = WINED3D_FFP_VS_FOG_DEPTH;
5852 if (d3d_info->emulated_flatshading)
5853 settings->flatshading = state->render_states[WINED3D_RS_SHADEMODE] == WINED3D_SHADE_FLAT;
5854 else
5855 settings->flatshading = FALSE;
5857 settings->swizzle_map = si->swizzle_map;
5860 int wined3d_ffp_vertex_program_key_compare(const void *key, const struct wine_rb_entry *entry)
5862 const struct wined3d_ffp_vs_settings *ka = key;
5863 const struct wined3d_ffp_vs_settings *kb = &WINE_RB_ENTRY_VALUE(entry,
5864 const struct wined3d_ffp_vs_desc, entry)->settings;
5866 return memcmp(ka, kb, sizeof(*ka));
5869 void wined3d_get_draw_rect(const struct wined3d_state *state, RECT *rect)
5871 const struct wined3d_viewport *vp = &state->viewport;
5873 SetRect(rect, vp->x, vp->y, vp->x + vp->width, vp->y + vp->height);
5875 if (state->render_states[WINED3D_RS_SCISSORTESTENABLE])
5876 IntersectRect(rect, rect, &state->scissor_rect);
5879 const char *wined3d_debug_location(DWORD location)
5881 const char *prefix = "";
5882 const char *suffix = "";
5883 char buf[294];
5885 if (wined3d_popcount(location) > 16)
5887 prefix = "~(";
5888 location = ~location;
5889 suffix = ")";
5892 buf[0] = '\0';
5893 #define LOCATION_TO_STR(u) if (location & u) { strcat(buf, " | "#u); location &= ~u; }
5894 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED);
5895 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM);
5896 LOCATION_TO_STR(WINED3D_LOCATION_USER_MEMORY);
5897 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER);
5898 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB);
5899 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB);
5900 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE);
5901 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE);
5902 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED);
5903 #undef LOCATION_TO_STR
5904 if (location) FIXME("Unrecognized location flag(s) %#x.\n", location);
5906 return wine_dbg_sprintf("%s%s%s", prefix, buf[0] ? &buf[3] : "0", suffix);
5909 /* Print a floating point value with the %.8e format specifier, always using
5910 * '.' as decimal separator. */
5911 void wined3d_ftoa(float value, char *s)
5913 int idx = 1;
5915 if (copysignf(1.0f, value) < 0.0f)
5916 ++idx;
5918 /* Be sure to allocate a buffer of at least 17 characters for the result
5919 as sprintf may return a 3 digit exponent when using the MSVC runtime
5920 instead of a 2 digit exponent. */
5921 sprintf(s, "%.8e", value);
5922 if (isfinite(value))
5923 s[idx] = '.';
5926 void wined3d_release_dc(HWND window, HDC dc)
5928 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
5929 * However, that's not what actually happens, and there are user32 tests
5930 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
5931 * So explicitly check that the DC belongs to the window, since we want to
5932 * avoid releasing a DC that belongs to some other window if the original
5933 * window was already destroyed. */
5934 if (WindowFromDC(dc) != window)
5935 WARN("DC %p does not belong to window %p.\n", dc, window);
5936 else if (!ReleaseDC(window, dc))
5937 ERR("Failed to release device context %p, last error %#x.\n", dc, GetLastError());
5940 BOOL wined3d_clip_blit(const RECT *clip_rect, RECT *clipped, RECT *other)
5942 RECT orig = *clipped;
5943 float scale_x = (float)(orig.right - orig.left) / (float)(other->right - other->left);
5944 float scale_y = (float)(orig.bottom - orig.top) / (float)(other->bottom - other->top);
5946 IntersectRect(clipped, clipped, clip_rect);
5948 if (IsRectEmpty(clipped))
5950 SetRectEmpty(other);
5951 return FALSE;
5954 other->left += (LONG)((clipped->left - orig.left) / scale_x);
5955 other->top += (LONG)((clipped->top - orig.top) / scale_y);
5956 other->right -= (LONG)((orig.right - clipped->right) / scale_x);
5957 other->bottom -= (LONG)((orig.bottom - clipped->bottom) / scale_y);
5959 return TRUE;
5962 void wined3d_gl_limits_get_uniform_block_range(const struct wined3d_gl_limits *gl_limits,
5963 enum wined3d_shader_type shader_type, unsigned int *base, unsigned int *count)
5965 unsigned int i;
5967 *base = 0;
5968 for (i = 0; i < WINED3D_SHADER_TYPE_COUNT; ++i)
5970 *count = gl_limits->uniform_blocks[i];
5971 if (i == shader_type)
5972 return;
5973 *base += *count;
5976 ERR("Unrecognized shader type %#x.\n", shader_type);
5977 *count = 0;
5980 void wined3d_gl_limits_get_texture_unit_range(const struct wined3d_gl_limits *gl_limits,
5981 enum wined3d_shader_type shader_type, unsigned int *base, unsigned int *count)
5983 unsigned int i;
5985 if (shader_type == WINED3D_SHADER_TYPE_COMPUTE)
5987 if (gl_limits->combined_samplers == gl_limits->graphics_samplers)
5988 *base = 0;
5989 else
5990 *base = gl_limits->graphics_samplers;
5991 *count = gl_limits->samplers[WINED3D_SHADER_TYPE_COMPUTE];
5992 return;
5995 *base = 0;
5996 for (i = 0; i < WINED3D_SHADER_TYPE_GRAPHICS_COUNT; ++i)
5998 *count = gl_limits->samplers[i];
5999 if (i == shader_type)
6000 return;
6001 *base += *count;
6004 ERR("Unrecognized shader type %#x.\n", shader_type);
6005 *count = 0;
6008 BOOL wined3d_array_reserve(void **elements, SIZE_T *capacity, SIZE_T count, SIZE_T size)
6010 SIZE_T max_capacity, new_capacity;
6011 void *new_elements;
6013 if (count <= *capacity)
6014 return TRUE;
6016 max_capacity = ~(SIZE_T)0 / size;
6017 if (count > max_capacity)
6018 return FALSE;
6020 new_capacity = max(1, *capacity);
6021 while (new_capacity < count && new_capacity <= max_capacity / 2)
6022 new_capacity *= 2;
6023 if (new_capacity < count)
6024 new_capacity = count;
6026 if (!*elements)
6027 new_elements = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, new_capacity * size);
6028 else
6029 new_elements = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, *elements, new_capacity * size);
6030 if (!new_elements)
6031 return FALSE;
6033 *elements = new_elements;
6034 *capacity = new_capacity;
6035 return TRUE;