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
28 #include "wine/port.h"
32 #include "wined3d_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
36 #define WINED3D_FORMAT_FOURCC_BASE (WINED3DFMT_BC7_UNORM_SRGB + 1)
40 enum wined3d_format_id id
;
43 format_index_remap
[] =
45 {WINED3DFMT_UYVY
, WINED3D_FORMAT_FOURCC_BASE
},
46 {WINED3DFMT_YUY2
, WINED3D_FORMAT_FOURCC_BASE
+ 1},
47 {WINED3DFMT_YV12
, WINED3D_FORMAT_FOURCC_BASE
+ 2},
48 {WINED3DFMT_DXT1
, WINED3D_FORMAT_FOURCC_BASE
+ 3},
49 {WINED3DFMT_DXT2
, WINED3D_FORMAT_FOURCC_BASE
+ 4},
50 {WINED3DFMT_DXT3
, WINED3D_FORMAT_FOURCC_BASE
+ 5},
51 {WINED3DFMT_DXT4
, WINED3D_FORMAT_FOURCC_BASE
+ 6},
52 {WINED3DFMT_DXT5
, WINED3D_FORMAT_FOURCC_BASE
+ 7},
53 {WINED3DFMT_MULTI2_ARGB8
, WINED3D_FORMAT_FOURCC_BASE
+ 8},
54 {WINED3DFMT_G8R8_G8B8
, WINED3D_FORMAT_FOURCC_BASE
+ 9},
55 {WINED3DFMT_R8G8_B8G8
, WINED3D_FORMAT_FOURCC_BASE
+ 10},
56 {WINED3DFMT_ATI1N
, WINED3D_FORMAT_FOURCC_BASE
+ 11},
57 {WINED3DFMT_ATI2N
, WINED3D_FORMAT_FOURCC_BASE
+ 12},
58 {WINED3DFMT_INST
, WINED3D_FORMAT_FOURCC_BASE
+ 13},
59 {WINED3DFMT_NVDB
, WINED3D_FORMAT_FOURCC_BASE
+ 14},
60 {WINED3DFMT_NVHU
, WINED3D_FORMAT_FOURCC_BASE
+ 15},
61 {WINED3DFMT_NVHS
, WINED3D_FORMAT_FOURCC_BASE
+ 16},
62 {WINED3DFMT_INTZ
, WINED3D_FORMAT_FOURCC_BASE
+ 17},
63 {WINED3DFMT_RESZ
, WINED3D_FORMAT_FOURCC_BASE
+ 18},
64 {WINED3DFMT_NULL
, WINED3D_FORMAT_FOURCC_BASE
+ 19},
65 {WINED3DFMT_R16
, WINED3D_FORMAT_FOURCC_BASE
+ 20},
66 {WINED3DFMT_AL16
, WINED3D_FORMAT_FOURCC_BASE
+ 21},
67 {WINED3DFMT_NV12
, WINED3D_FORMAT_FOURCC_BASE
+ 22},
68 {WINED3DFMT_ATOC
, WINED3D_FORMAT_FOURCC_BASE
+ 23},
71 #define WINED3D_FORMAT_COUNT (WINED3D_FORMAT_FOURCC_BASE + ARRAY_SIZE(format_index_remap))
73 struct wined3d_format_channels
75 enum wined3d_format_id id
;
76 DWORD red_size
, green_size
, blue_size
, alpha_size
;
77 DWORD red_offset
, green_offset
, blue_offset
, alpha_offset
;
79 BYTE depth_size
, stencil_size
;
82 static const struct wined3d_format_channels formats
[] =
85 * format id r g b a r g b a bpp depth stencil */
86 {WINED3DFMT_UNKNOWN
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
88 {WINED3DFMT_UYVY
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
89 {WINED3DFMT_YUY2
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
90 {WINED3DFMT_YV12
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
91 {WINED3DFMT_NV12
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
92 {WINED3DFMT_DXT1
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
93 {WINED3DFMT_DXT2
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
94 {WINED3DFMT_DXT3
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
95 {WINED3DFMT_DXT4
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
96 {WINED3DFMT_DXT5
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
97 {WINED3DFMT_MULTI2_ARGB8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
98 {WINED3DFMT_G8R8_G8B8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
99 {WINED3DFMT_R8G8_B8G8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
101 {WINED3DFMT_R8G8_SNORM_Cx
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
102 {WINED3DFMT_R11G11B10_FLOAT
, 11, 11, 10, 0, 0, 11, 22, 0, 4, 0, 0},
103 /* Palettized formats */
104 {WINED3DFMT_P8_UINT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
105 {WINED3DFMT_P8_UINT
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
106 /* Standard ARGB formats. */
107 {WINED3DFMT_B8G8R8_UNORM
, 8, 8, 8, 0, 16, 8, 0, 0, 3, 0, 0},
108 {WINED3DFMT_B5G6R5_UNORM
, 5, 6, 5, 0, 11, 5, 0, 0, 2, 0, 0},
109 {WINED3DFMT_B5G5R5X1_UNORM
, 5, 5, 5, 0, 10, 5, 0, 0, 2, 0, 0},
110 {WINED3DFMT_B5G5R5A1_UNORM
, 5, 5, 5, 1, 10, 5, 0, 15, 2, 0, 0},
111 {WINED3DFMT_B4G4R4A4_UNORM
, 4, 4, 4, 4, 8, 4, 0, 12, 2, 0, 0},
112 {WINED3DFMT_B2G3R3_UNORM
, 3, 3, 2, 0, 5, 2, 0, 0, 1, 0, 0},
113 {WINED3DFMT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0},
114 {WINED3DFMT_B2G3R3A8_UNORM
, 3, 3, 2, 8, 5, 2, 0, 8, 2, 0, 0},
115 {WINED3DFMT_B4G4R4X4_UNORM
, 4, 4, 4, 0, 8, 4, 0, 0, 2, 0, 0},
116 {WINED3DFMT_R8G8B8X8_UNORM
, 8, 8, 8, 0, 0, 8, 16, 0, 4, 0, 0},
117 {WINED3DFMT_B10G10R10A2_UNORM
, 10, 10, 10, 2, 20, 10, 0, 30, 4, 0, 0},
119 {WINED3DFMT_L8_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
120 {WINED3DFMT_L8A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
121 {WINED3DFMT_L4A4_UNORM
, 0, 0, 0, 4, 0, 0, 0, 4, 1, 0, 0},
122 {WINED3DFMT_L16_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
123 /* Bump mapping stuff */
124 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, 5, 5, 0, 0, 0, 5, 0, 0, 2, 0, 0},
125 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, 8, 8, 0, 0, 0, 8, 0, 0, 4, 0, 0},
126 {WINED3DFMT_R10G11B11_SNORM
, 10, 11, 11, 0, 0, 10, 21, 0, 4, 0, 0},
127 {WINED3DFMT_R10G10B10_SNORM_A2_UNORM
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
128 /* Depth stencil formats */
129 {WINED3DFMT_D16_LOCKABLE
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
130 {WINED3DFMT_D32_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
131 {WINED3DFMT_S1_UINT_D15_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 15, 1},
132 {WINED3DFMT_X8D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 0},
133 {WINED3DFMT_S4X4_UINT_D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 4},
134 {WINED3DFMT_S8_UINT_D24_FLOAT
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
135 /* Vendor-specific formats */
136 {WINED3DFMT_ATI1N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
137 {WINED3DFMT_ATI2N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
138 {WINED3DFMT_NVDB
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
139 {WINED3DFMT_ATOC
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
140 {WINED3DFMT_INST
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
141 {WINED3DFMT_INTZ
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
142 {WINED3DFMT_RESZ
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
143 {WINED3DFMT_NVHU
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
144 {WINED3DFMT_NVHS
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
145 {WINED3DFMT_NULL
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
146 /* Unsure about them, could not find a Windows driver that supports them */
147 {WINED3DFMT_R16
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
148 {WINED3DFMT_AL16
, 0, 0, 0, 16, 0, 0, 0, 16, 4, 0, 0},
149 /* DirectX 10 HDR formats */
150 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
152 {WINED3DFMT_R32G32B32A32_TYPELESS
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
153 {WINED3DFMT_R32G32B32_TYPELESS
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
154 {WINED3DFMT_R16G16B16A16_TYPELESS
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
155 {WINED3DFMT_R32G32_TYPELESS
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
156 {WINED3DFMT_R32G8X24_TYPELESS
, 32, 8, 0, 0, 0, 0, 0, 0, 8, 0, 0},
157 {WINED3DFMT_R10G10B10A2_TYPELESS
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
158 {WINED3DFMT_R10G10B10X2_TYPELESS
, 10, 10, 10, 0, 0, 10, 20, 0, 4, 0, 0},
159 {WINED3DFMT_R8G8B8A8_TYPELESS
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
160 {WINED3DFMT_R16G16_TYPELESS
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
161 {WINED3DFMT_R32_TYPELESS
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
162 {WINED3DFMT_R24G8_TYPELESS
, 24, 8, 0, 0, 0, 0, 0, 0, 4, 0, 0},
163 {WINED3DFMT_R8G8_TYPELESS
, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
164 {WINED3DFMT_R16_TYPELESS
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
165 {WINED3DFMT_R8_TYPELESS
, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
166 {WINED3DFMT_BC1_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
167 {WINED3DFMT_BC2_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
168 {WINED3DFMT_BC3_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
169 {WINED3DFMT_BC4_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
170 {WINED3DFMT_BC5_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
171 {WINED3DFMT_BC6H_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
172 {WINED3DFMT_BC7_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
173 {WINED3DFMT_B8G8R8A8_TYPELESS
, 8, 8, 8, 8, 16, 8, 0, 24, 4, 0, 0},
174 {WINED3DFMT_B8G8R8X8_TYPELESS
, 8, 8, 8, 0, 16, 8, 0, 0, 4, 0, 0},
177 enum wined3d_channel_type
179 WINED3D_CHANNEL_TYPE_NONE
,
180 WINED3D_CHANNEL_TYPE_UNORM
,
181 WINED3D_CHANNEL_TYPE_SNORM
,
182 WINED3D_CHANNEL_TYPE_UINT
,
183 WINED3D_CHANNEL_TYPE_SINT
,
184 WINED3D_CHANNEL_TYPE_FLOAT
,
185 WINED3D_CHANNEL_TYPE_DEPTH
,
186 WINED3D_CHANNEL_TYPE_STENCIL
,
187 WINED3D_CHANNEL_TYPE_UNUSED
,
190 struct wined3d_typed_format_info
192 enum wined3d_format_id id
;
193 enum wined3d_format_id typeless_id
;
194 const char *channels
;
198 * The last entry for a given typeless format defines its internal format.
200 * u - WINED3D_CHANNEL_TYPE_UNORM
201 * i - WINED3D_CHANNEL_TYPE_SNORM
202 * U - WINED3D_CHANNEL_TYPE_UINT
203 * I - WINED3D_CHANNEL_TYPE_SINT
204 * F - WINED3D_CHANNEL_TYPE_FLOAT
205 * D - WINED3D_CHANNEL_TYPE_DEPTH
206 * S - WINED3D_CHANNEL_TYPE_STENCIL
207 * X - WINED3D_CHANNEL_TYPE_UNUSED
209 static const struct wined3d_typed_format_info typed_formats
[] =
211 {WINED3DFMT_R32G32B32A32_UINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "UUUU"},
212 {WINED3DFMT_R32G32B32A32_SINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "IIII"},
213 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "FFFF"},
214 {WINED3DFMT_R32G32B32_UINT
, WINED3DFMT_R32G32B32_TYPELESS
, "UUU"},
215 {WINED3DFMT_R32G32B32_SINT
, WINED3DFMT_R32G32B32_TYPELESS
, "III"},
216 {WINED3DFMT_R32G32B32_FLOAT
, WINED3DFMT_R32G32B32_TYPELESS
, "FFF"},
217 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "uuuu"},
218 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "iiii"},
219 {WINED3DFMT_R16G16B16A16_UINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "UUUU"},
220 {WINED3DFMT_R16G16B16A16_SINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "IIII"},
221 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "FFFF"},
222 {WINED3DFMT_R32G32_UINT
, WINED3DFMT_R32G32_TYPELESS
, "UU"},
223 {WINED3DFMT_R32G32_SINT
, WINED3DFMT_R32G32_TYPELESS
, "II"},
224 {WINED3DFMT_R32G32_FLOAT
, WINED3DFMT_R32G32_TYPELESS
, "FF"},
225 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, WINED3DFMT_R32G8X24_TYPELESS
, "FXX"},
226 {WINED3DFMT_X32_TYPELESS_G8X24_UINT
, WINED3DFMT_R32G8X24_TYPELESS
, "XUX"},
227 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, WINED3DFMT_R32G8X24_TYPELESS
, "DSX"},
228 {WINED3DFMT_R10G10B10A2_SNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "iiii"},
229 {WINED3DFMT_R10G10B10A2_UINT
, WINED3DFMT_R10G10B10A2_TYPELESS
, "UUUU"},
230 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "uuuu"},
231 {WINED3DFMT_R10G10B10X2_SNORM
, WINED3DFMT_R10G10B10X2_TYPELESS
, "iiiX"},
232 {WINED3DFMT_R10G10B10X2_UINT
, WINED3DFMT_R10G10B10X2_TYPELESS
, "UUUX"},
233 {WINED3DFMT_R8G8B8A8_UINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "UUUU"},
234 {WINED3DFMT_R8G8B8A8_SINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "IIII"},
235 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "iiii"},
236 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
237 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
238 {WINED3DFMT_R16G16_UNORM
, WINED3DFMT_R16G16_TYPELESS
, "uu"},
239 {WINED3DFMT_R16G16_SNORM
, WINED3DFMT_R16G16_TYPELESS
, "ii"},
240 {WINED3DFMT_R16G16_UINT
, WINED3DFMT_R16G16_TYPELESS
, "UU"},
241 {WINED3DFMT_R16G16_SINT
, WINED3DFMT_R16G16_TYPELESS
, "II"},
242 {WINED3DFMT_R16G16_FLOAT
, WINED3DFMT_R16G16_TYPELESS
, "FF"},
243 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "D"},
244 {WINED3DFMT_R32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "F"},
245 {WINED3DFMT_R32_UINT
, WINED3DFMT_R32_TYPELESS
, "U"},
246 {WINED3DFMT_R32_SINT
, WINED3DFMT_R32_TYPELESS
, "I"},
247 {WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_R24G8_TYPELESS
, "uX"},
248 {WINED3DFMT_X24_TYPELESS_G8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "XU"},
249 {WINED3DFMT_D24_UNORM_S8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "DS"},
250 {WINED3DFMT_R8G8_SNORM
, WINED3DFMT_R8G8_TYPELESS
, "ii"},
251 {WINED3DFMT_R8G8_UNORM
, WINED3DFMT_R8G8_TYPELESS
, "uu"},
252 {WINED3DFMT_R8G8_UINT
, WINED3DFMT_R8G8_TYPELESS
, "UU"},
253 {WINED3DFMT_R8G8_SINT
, WINED3DFMT_R8G8_TYPELESS
, "II"},
254 {WINED3DFMT_D16_UNORM
, WINED3DFMT_R16_TYPELESS
, "D"},
255 {WINED3DFMT_R16_UNORM
, WINED3DFMT_R16_TYPELESS
, "u"},
256 {WINED3DFMT_R16_SNORM
, WINED3DFMT_R16_TYPELESS
, "i"},
257 {WINED3DFMT_R16_UINT
, WINED3DFMT_R16_TYPELESS
, "U"},
258 {WINED3DFMT_R16_SINT
, WINED3DFMT_R16_TYPELESS
, "I"},
259 {WINED3DFMT_R16_FLOAT
, WINED3DFMT_R16_TYPELESS
, "F"},
260 {WINED3DFMT_R8_UNORM
, WINED3DFMT_R8_TYPELESS
, "u"},
261 {WINED3DFMT_R8_SNORM
, WINED3DFMT_R8_TYPELESS
, "i"},
262 {WINED3DFMT_R8_UINT
, WINED3DFMT_R8_TYPELESS
, "U"},
263 {WINED3DFMT_R8_SINT
, WINED3DFMT_R8_TYPELESS
, "I"},
264 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_TYPELESS
, ""},
265 {WINED3DFMT_BC1_UNORM
, WINED3DFMT_BC1_TYPELESS
, ""},
266 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_TYPELESS
, ""},
267 {WINED3DFMT_BC2_UNORM
, WINED3DFMT_BC2_TYPELESS
, ""},
268 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_TYPELESS
, ""},
269 {WINED3DFMT_BC3_UNORM
, WINED3DFMT_BC3_TYPELESS
, ""},
270 {WINED3DFMT_BC4_UNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
271 {WINED3DFMT_BC4_SNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
272 {WINED3DFMT_BC5_UNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
273 {WINED3DFMT_BC5_SNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
274 {WINED3DFMT_BC6H_UF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
275 {WINED3DFMT_BC6H_SF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
276 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_TYPELESS
, ""},
277 {WINED3DFMT_BC7_UNORM
, WINED3DFMT_BC7_TYPELESS
, ""},
278 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
279 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
280 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
281 {WINED3DFMT_B8G8R8X8_UNORM
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
284 struct wined3d_typeless_format_depth_stencil_info
286 enum wined3d_format_id typeless_id
;
287 enum wined3d_format_id depth_stencil_id
;
288 enum wined3d_format_id depth_view_id
;
289 enum wined3d_format_id stencil_view_id
;
290 BOOL separate_depth_view_format
;
293 static const struct wined3d_typeless_format_depth_stencil_info typeless_depth_stencil_formats
[] =
295 {WINED3DFMT_R32G8X24_TYPELESS
, WINED3DFMT_D32_FLOAT_S8X24_UINT
,
296 WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, WINED3DFMT_X32_TYPELESS_G8X24_UINT
, TRUE
},
297 {WINED3DFMT_R24G8_TYPELESS
, WINED3DFMT_D24_UNORM_S8_UINT
,
298 WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_X24_TYPELESS_G8_UINT
, TRUE
},
299 {WINED3DFMT_R32_TYPELESS
, WINED3DFMT_D32_FLOAT
, WINED3DFMT_R32_FLOAT
},
300 {WINED3DFMT_R16_TYPELESS
, WINED3DFMT_D16_UNORM
, WINED3DFMT_R16_UNORM
},
303 struct wined3d_format_ddi_info
305 enum wined3d_format_id id
;
306 D3DDDIFORMAT ddi_format
;
309 static const struct wined3d_format_ddi_info ddi_formats
[] =
311 {WINED3DFMT_B8G8R8_UNORM
, D3DDDIFMT_R8G8B8
},
312 {WINED3DFMT_B8G8R8A8_UNORM
, D3DDDIFMT_A8R8G8B8
},
313 {WINED3DFMT_B8G8R8X8_UNORM
, D3DDDIFMT_X8R8G8B8
},
314 {WINED3DFMT_B5G6R5_UNORM
, D3DDDIFMT_R5G6B5
},
315 {WINED3DFMT_B5G5R5X1_UNORM
, D3DDDIFMT_X1R5G5B5
},
316 {WINED3DFMT_B5G5R5A1_UNORM
, D3DDDIFMT_A1R5G5B5
},
317 {WINED3DFMT_B4G4R4A4_UNORM
, D3DDDIFMT_A4R4G4B4
},
318 {WINED3DFMT_B4G4R4X4_UNORM
, D3DDDIFMT_X4R4G4B4
},
319 {WINED3DFMT_P8_UINT
, D3DDDIFMT_P8
},
322 struct wined3d_format_base_flags
324 enum wined3d_format_id id
;
328 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
329 * still needs to use the correct block based calculation for e.g. the
331 static const struct wined3d_format_base_flags format_base_flags
[] =
333 {WINED3DFMT_ATI1N
, WINED3DFMT_FLAG_MAPPABLE
| WINED3DFMT_FLAG_BROKEN_PITCH
},
334 {WINED3DFMT_ATI2N
, WINED3DFMT_FLAG_MAPPABLE
| WINED3DFMT_FLAG_BROKEN_PITCH
},
335 {WINED3DFMT_D16_LOCKABLE
, WINED3DFMT_FLAG_MAPPABLE
},
336 {WINED3DFMT_INTZ
, WINED3DFMT_FLAG_MAPPABLE
},
337 {WINED3DFMT_R11G11B10_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
338 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
339 {WINED3DFMT_S8_UINT_D24_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
340 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, WINED3DFMT_FLAG_FLOAT
},
341 {WINED3DFMT_INST
, WINED3DFMT_FLAG_EXTENSION
},
342 {WINED3DFMT_NULL
, WINED3DFMT_FLAG_EXTENSION
},
343 {WINED3DFMT_NVDB
, WINED3DFMT_FLAG_EXTENSION
},
344 {WINED3DFMT_ATOC
, WINED3DFMT_FLAG_EXTENSION
},
345 {WINED3DFMT_RESZ
, WINED3DFMT_FLAG_EXTENSION
},
348 static void rgb888_from_rgb565(WORD rgb565
, BYTE
*r
, BYTE
*g
, BYTE
*b
)
352 /* (2⁸ - 1) / (2⁵ - 1) ≈ 2⁸ / 2⁵ + 2⁸ / 2¹⁰
353 * (2⁸ - 1) / (2⁶ - 1) ≈ 2⁸ / 2⁶ + 2⁸ / 2¹² */
355 *r
= (c
<< 3) + (c
>> 2);
356 c
= (rgb565
>> 5) & 0x3f;
357 *g
= (c
<< 2) + (c
>> 4);
359 *b
= (c
<< 3) + (c
>> 2);
362 static void build_dxtn_colour_table(WORD colour0
, WORD colour1
,
363 DWORD colour_table
[4], enum wined3d_format_id format_id
)
371 rgb888_from_rgb565(colour0
, &c
[0].r
, &c
[0].g
, &c
[0].b
);
372 rgb888_from_rgb565(colour1
, &c
[1].r
, &c
[1].g
, &c
[1].b
);
374 if (format_id
== WINED3DFMT_BC1_UNORM
&& colour0
<= colour1
)
376 c
[2].r
= (c
[0].r
+ c
[1].r
) / 2;
377 c
[2].g
= (c
[0].g
+ c
[1].g
) / 2;
378 c
[2].b
= (c
[0].b
+ c
[1].b
) / 2;
386 for (i
= 0; i
< 2; ++i
)
388 c
[i
+ 2].r
= (2 * c
[i
].r
+ c
[1 - i
].r
) / 3;
389 c
[i
+ 2].g
= (2 * c
[i
].g
+ c
[1 - i
].g
) / 3;
390 c
[i
+ 2].b
= (2 * c
[i
].b
+ c
[1 - i
].b
) / 3;
394 for (i
= 0; i
< 4; ++i
)
396 colour_table
[i
] = (c
[i
].r
<< 16) | (c
[i
].g
<< 8) | c
[i
].b
;
400 static void build_bc3_alpha_table(BYTE alpha0
, BYTE alpha1
, BYTE alpha_table
[8])
404 alpha_table
[0] = alpha0
;
405 alpha_table
[1] = alpha1
;
409 for (i
= 0; i
< 6; ++i
)
411 alpha_table
[2 + i
] = ((6 - i
) * alpha0
+ (i
+ 1) * alpha1
) / 7;
417 for (i
= 0; i
< 4; ++i
)
419 alpha_table
[2 + i
] = ((4 - i
) * alpha0
+ (i
+ 1) * alpha1
) / 5;
421 alpha_table
[6] = 0x00;
422 alpha_table
[7] = 0xff;
426 static void decompress_dxtn_block(const BYTE
*src
, BYTE
*dst
, unsigned int width
,
427 unsigned int height
, unsigned int dst_row_pitch
, enum wined3d_format_id format_id
)
429 const UINT64
*s
= (const UINT64
*)src
;
430 BOOL bc1_alpha
= FALSE
;
431 DWORD colour_table
[4];
440 if (format_id
== WINED3DFMT_BC1_UNORM
)
442 WORD colour0
, colour1
;
446 colour0
= s
[0] & 0xffff;
447 colour1
= (s
[0] >> 16) & 0xffff;
448 colour_bits
= (s
[0] >> 32) & 0xffffffff;
449 build_dxtn_colour_table(colour0
, colour1
, colour_table
, format_id
);
450 if (colour0
<= colour1
)
456 if (format_id
== WINED3DFMT_BC3_UNORM
)
458 build_bc3_alpha_table(alpha_bits
& 0xff, (alpha_bits
>> 8) & 0xff, alpha_table
);
462 colour_bits
= (s
[1] >> 32) & 0xffffffff;
463 build_dxtn_colour_table(s
[1] & 0xffff, (s
[1] >> 16) & 0xffff, colour_table
, format_id
);
466 for (y
= 0; y
< height
; ++y
)
468 dst_row
= (DWORD
*)&dst
[y
* dst_row_pitch
];
469 for (x
= 0; x
< width
; ++x
)
471 colour_idx
= (colour_bits
>> (y
* 8 + x
* 2)) & 0x3;
474 case WINED3DFMT_BC1_UNORM
:
475 alpha
= bc1_alpha
&& colour_idx
== 3 ? 0x00 : 0xff;
478 case WINED3DFMT_BC2_UNORM
:
479 alpha
= (alpha_bits
>> (y
* 16 + x
* 4)) & 0xf;
480 /* (2⁸ - 1) / (2⁴ - 1) ≈ 2⁸ / 2⁴ + 2⁸ / 2⁸ */
484 case WINED3DFMT_BC3_UNORM
:
485 alpha
= alpha_table
[(alpha_bits
>> (y
* 12 + x
* 3)) & 0x7];
492 dst_row
[x
] = (alpha
<< 24) | colour_table
[colour_idx
];
497 static void decompress_dxtn(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
498 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
499 unsigned int width
, unsigned int height
, unsigned int depth
, enum wined3d_format_id format_id
)
501 unsigned int block_byte_count
, block_w
, block_h
;
502 const BYTE
*src_row
, *src_slice
= src
;
503 BYTE
*dst_row
, *dst_slice
= dst
;
504 unsigned int x
, y
, z
;
506 block_byte_count
= format_id
== WINED3DFMT_BC1_UNORM
? 8 : 16;
508 for (z
= 0; z
< depth
; ++z
)
512 for (y
= 0; y
< height
; y
+= 4)
514 for (x
= 0; x
< width
; x
+= 4)
516 block_w
= min(width
- x
, 4);
517 block_h
= min(height
- y
, 4);
518 decompress_dxtn_block(&src_row
[x
* (block_byte_count
/ 4)],
519 &dst_row
[x
* 4], block_w
, block_h
, dst_row_pitch
, format_id
);
521 src_row
+= src_row_pitch
;
522 dst_row
+= dst_row_pitch
* 4;
524 src_slice
+= src_slice_pitch
;
525 dst_slice
+= dst_slice_pitch
;
529 static void decompress_bc3(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
530 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
531 unsigned int width
, unsigned int height
, unsigned int depth
)
533 decompress_dxtn(src
, dst
, src_row_pitch
, src_slice_pitch
, dst_row_pitch
,
534 dst_slice_pitch
, width
, height
, depth
, WINED3DFMT_BC3_UNORM
);
537 static void decompress_bc2(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
538 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
539 unsigned int width
, unsigned int height
, unsigned int depth
)
541 decompress_dxtn(src
, dst
, src_row_pitch
, src_slice_pitch
, dst_row_pitch
,
542 dst_slice_pitch
, width
, height
, depth
, WINED3DFMT_BC2_UNORM
);
545 static void decompress_bc1(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
546 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
547 unsigned int width
, unsigned int height
, unsigned int depth
)
549 decompress_dxtn(src
, dst
, src_row_pitch
, src_slice_pitch
, dst_row_pitch
,
550 dst_slice_pitch
, width
, height
, depth
, WINED3DFMT_BC1_UNORM
);
553 static const struct wined3d_format_decompress_info
555 enum wined3d_format_id id
;
556 void (*decompress
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
557 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
558 unsigned int width
, unsigned int height
, unsigned int depth
);
560 format_decompress_info
[] =
562 {WINED3DFMT_DXT1
, decompress_bc1
},
563 {WINED3DFMT_DXT2
, decompress_bc2
},
564 {WINED3DFMT_DXT3
, decompress_bc2
},
565 {WINED3DFMT_DXT4
, decompress_bc3
},
566 {WINED3DFMT_DXT5
, decompress_bc3
},
567 {WINED3DFMT_BC1_UNORM
, decompress_bc1
},
568 {WINED3DFMT_BC2_UNORM
, decompress_bc2
},
569 {WINED3DFMT_BC3_UNORM
, decompress_bc3
},
572 struct wined3d_format_block_info
574 enum wined3d_format_id id
;
577 UINT block_byte_count
;
581 static const struct wined3d_format_block_info format_block_info
[] =
583 {WINED3DFMT_DXT1
, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED
},
584 {WINED3DFMT_DXT2
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
585 {WINED3DFMT_DXT3
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
586 {WINED3DFMT_DXT4
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
587 {WINED3DFMT_DXT5
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
588 {WINED3DFMT_BC1_UNORM
, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED
},
589 {WINED3DFMT_BC2_UNORM
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
590 {WINED3DFMT_BC3_UNORM
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
591 {WINED3DFMT_BC4_UNORM
, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED
},
592 {WINED3DFMT_BC4_SNORM
, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED
},
593 {WINED3DFMT_BC5_UNORM
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
594 {WINED3DFMT_BC5_SNORM
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
595 {WINED3DFMT_BC6H_UF16
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
596 {WINED3DFMT_BC6H_SF16
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
597 {WINED3DFMT_BC7_UNORM
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
598 {WINED3DFMT_ATI1N
, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED
| WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
},
599 {WINED3DFMT_ATI2N
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
| WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
},
600 {WINED3DFMT_YUY2
, 2, 1, 4, WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
},
601 {WINED3DFMT_UYVY
, 2, 1, 4, WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
},
604 struct wined3d_format_vertex_info
606 enum wined3d_format_id id
;
607 enum wined3d_ffp_emit_idx emit_idx
;
609 enum wined3d_gl_extension extension
;
612 static const struct wined3d_format_vertex_info format_vertex_info
[] =
614 {WINED3DFMT_R32_FLOAT
, WINED3D_FFP_EMIT_FLOAT1
, GL_FLOAT
},
615 {WINED3DFMT_R32G32_FLOAT
, WINED3D_FFP_EMIT_FLOAT2
, GL_FLOAT
},
616 {WINED3DFMT_R32G32B32_FLOAT
, WINED3D_FFP_EMIT_FLOAT3
, GL_FLOAT
},
617 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3D_FFP_EMIT_FLOAT4
, GL_FLOAT
},
618 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3D_FFP_EMIT_D3DCOLOR
, GL_UNSIGNED_BYTE
},
619 {WINED3DFMT_R8G8B8A8_UINT
, WINED3D_FFP_EMIT_UBYTE4
, GL_UNSIGNED_BYTE
},
620 {WINED3DFMT_R16G16_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_SHORT
},
621 {WINED3DFMT_R16G16_SINT
, WINED3D_FFP_EMIT_SHORT2
, GL_SHORT
},
622 {WINED3DFMT_R16G16B16A16_SINT
, WINED3D_FFP_EMIT_SHORT4
, GL_SHORT
},
623 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3D_FFP_EMIT_UBYTE4N
, GL_UNSIGNED_BYTE
},
624 {WINED3DFMT_R16G16_SNORM
, WINED3D_FFP_EMIT_SHORT2N
, GL_SHORT
},
625 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3D_FFP_EMIT_SHORT4N
, GL_SHORT
},
626 {WINED3DFMT_R16G16_UNORM
, WINED3D_FFP_EMIT_USHORT2N
, GL_UNSIGNED_SHORT
},
627 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3D_FFP_EMIT_USHORT4N
, GL_UNSIGNED_SHORT
},
628 {WINED3DFMT_R10G10B10X2_UINT
, WINED3D_FFP_EMIT_UDEC3
, GL_UNSIGNED_SHORT
},
629 {WINED3DFMT_R10G10B10X2_SNORM
, WINED3D_FFP_EMIT_DEC3N
, GL_SHORT
},
630 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT_2_10_10_10_REV
,
631 ARB_VERTEX_TYPE_2_10_10_10_REV
},
632 /* Without ARB_half_float_vertex we convert these on upload. */
633 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, GL_FLOAT
},
634 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, GL_HALF_FLOAT
, ARB_HALF_FLOAT_VERTEX
},
635 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, GL_FLOAT
},
636 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, GL_HALF_FLOAT
, ARB_HALF_FLOAT_VERTEX
},
637 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3D_FFP_EMIT_INVALID
, GL_BYTE
},
638 {WINED3DFMT_R8G8B8A8_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_BYTE
},
639 {WINED3DFMT_R8G8_UNORM
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
640 {WINED3DFMT_R16G16B16A16_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_SHORT
},
641 {WINED3DFMT_R8_UNORM
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
642 {WINED3DFMT_R8_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
643 {WINED3DFMT_R8_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_BYTE
},
644 {WINED3DFMT_R16_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_SHORT
},
645 {WINED3DFMT_R16_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_SHORT
},
646 {WINED3DFMT_R32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
647 {WINED3DFMT_R32_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_INT
},
648 {WINED3DFMT_R32G32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
649 {WINED3DFMT_R32G32_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_INT
},
650 {WINED3DFMT_R32G32B32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
651 {WINED3DFMT_R32G32B32A32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
652 {WINED3DFMT_R32G32B32A32_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_INT
},
655 struct wined3d_format_texture_info
657 enum wined3d_format_id id
;
659 GLint gl_srgb_internal
;
660 GLint gl_rt_internal
;
663 unsigned int conv_byte_count
;
665 enum wined3d_gl_extension extension
;
666 void (*upload
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
667 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
668 unsigned int width
, unsigned int height
, unsigned int depth
);
669 void (*download
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
670 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
671 unsigned int width
, unsigned int height
, unsigned int depth
);
672 void (*decompress
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
673 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
674 unsigned int width
, unsigned int height
, unsigned int depth
);
677 static void convert_l4a4_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
678 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
680 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
681 * format+type combination to load it. Thus convert it to A8L8, then load it
682 * with A4L4 internal, but A8L8 format+type
684 unsigned int x
, y
, z
;
685 const unsigned char *Source
;
688 for (z
= 0; z
< depth
; z
++)
690 for (y
= 0; y
< height
; y
++)
692 Source
= src
+ z
* src_slice_pitch
+ y
* src_row_pitch
;
693 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
694 for (x
= 0; x
< width
; x
++ )
696 unsigned char color
= (*Source
++);
697 /* A */ Dest
[1] = (color
& 0xf0u
) << 0;
698 /* L */ Dest
[0] = (color
& 0x0fu
) << 4;
705 static void convert_r5g5_snorm_l6_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
706 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
708 unsigned int x
, y
, z
;
709 unsigned char r_in
, g_in
, l_in
;
710 const unsigned short *texel_in
;
711 unsigned short *texel_out
;
713 /* Emulating signed 5 bit values with unsigned 5 bit values has some precision problems by design:
714 * E.g. the signed input value 0 becomes 16. GL normalizes it to 16 / 31 = 0.516. We convert it
715 * back to a signed value by subtracting 0.5 and multiplying by 2.0. The resulting value is
716 * ((16 / 31) - 0.5) * 2.0 = 0.032, which is quite different from the intended result 0.000. */
717 for (z
= 0; z
< depth
; z
++)
719 for (y
= 0; y
< height
; y
++)
721 texel_out
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
722 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
723 for (x
= 0; x
< width
; x
++ )
725 l_in
= (*texel_in
& 0xfc00u
) >> 10;
726 g_in
= (*texel_in
& 0x03e0u
) >> 5;
727 r_in
= *texel_in
& 0x001fu
;
729 *texel_out
= ((r_in
+ 16) << 11) | (l_in
<< 5) | (g_in
+ 16);
737 static void convert_r5g5_snorm_l6_unorm_ext(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
738 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
740 unsigned int x
, y
, z
;
741 unsigned char *texel_out
, r_out
, g_out
, r_in
, g_in
, l_in
;
742 const unsigned short *texel_in
;
744 for (z
= 0; z
< depth
; z
++)
746 for (y
= 0; y
< height
; y
++)
748 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
749 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
750 for (x
= 0; x
< width
; x
++ )
752 l_in
= (*texel_in
& 0xfc00u
) >> 10;
753 g_in
= (*texel_in
& 0x03e0u
) >> 5;
754 r_in
= *texel_in
& 0x001fu
;
757 if (!(r_in
& 0x10)) /* r > 0 */
761 if (!(g_in
& 0x10)) /* g > 0 */
764 texel_out
[0] = r_out
;
765 texel_out
[1] = g_out
;
766 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
776 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
777 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
779 unsigned int x
, y
, z
;
780 unsigned char *texel_out
, ds_out
, dt_out
, r_in
, g_in
, l_in
;
781 const unsigned short *texel_in
;
783 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
784 * fixed function and shaders without further conversion once the surface is
787 * The difference between this function and convert_r5g5_snorm_l6_unorm_ext
788 * is that convert_r5g5_snorm_l6_unorm_ext creates a 32 bit XRGB texture and
789 * this function creates a 24 bit DSDT_MAG texture. Trying to load a DSDT_MAG
790 * internal with a 32 bit DSDT_MAG_INTENSITY or DSDT_MAG_VIB format fails. */
791 for (z
= 0; z
< depth
; z
++)
793 for (y
= 0; y
< height
; y
++)
795 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
796 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
797 for (x
= 0; x
< width
; x
++ )
799 l_in
= (*texel_in
& 0xfc00u
) >> 10;
800 g_in
= (*texel_in
& 0x03e0u
) >> 5;
801 r_in
= *texel_in
& 0x001fu
;
804 if (!(r_in
& 0x10)) /* r > 0 */
808 if (!(g_in
& 0x10)) /* g > 0 */
811 texel_out
[0] = ds_out
;
812 texel_out
[1] = dt_out
;
813 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
822 static void convert_r8g8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
823 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
825 unsigned int x
, y
, z
;
829 for (z
= 0; z
< depth
; z
++)
831 for (y
= 0; y
< height
; y
++)
833 Source
= (const short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
834 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
835 for (x
= 0; x
< width
; x
++ )
837 const short color
= (*Source
++);
838 /* B */ Dest
[0] = 0xff;
839 /* G */ Dest
[1] = (color
>> 8) + 128; /* V */
840 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
847 static void convert_r8g8_snorm_l8x8_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
848 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
850 unsigned int x
, y
, z
;
854 /* Doesn't work correctly with the fixed function pipeline, but can work in
855 * shaders if the shader is adjusted. (There's no use for this format in gl's
856 * standard fixed function pipeline anyway).
858 for (z
= 0; z
< depth
; z
++)
860 for (y
= 0; y
< height
; y
++)
862 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
863 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
864 for (x
= 0; x
< width
; x
++ )
866 LONG color
= (*Source
++);
867 /* B */ Dest
[0] = ((color
>> 16) & 0xff); /* L */
868 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
869 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
876 static void convert_r8g8_snorm_l8x8_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
877 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
879 unsigned int x
, y
, z
;
883 /* This implementation works with the fixed function pipeline and shaders
884 * without further modification after converting the surface.
886 for (z
= 0; z
< depth
; z
++)
888 for (y
= 0; y
< height
; y
++)
890 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
891 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
892 for (x
= 0; x
< width
; x
++ )
894 LONG color
= (*Source
++);
895 /* L */ Dest
[2] = ((color
>> 16) & 0xff); /* L */
896 /* V */ Dest
[1] = ((color
>> 8 ) & 0xff); /* V */
897 /* U */ Dest
[0] = (color
& 0xff); /* U */
898 /* I */ Dest
[3] = 255; /* X */
905 static void convert_r8g8b8a8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
906 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
908 unsigned int x
, y
, z
;
912 for (z
= 0; z
< depth
; z
++)
914 for (y
= 0; y
< height
; y
++)
916 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
917 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
918 for (x
= 0; x
< width
; x
++ )
920 LONG color
= (*Source
++);
921 /* B */ Dest
[0] = ((color
>> 16) & 0xff) + 128; /* W */
922 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
923 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
924 /* A */ Dest
[3] = ((color
>> 24) & 0xff) + 128; /* Q */
931 static void convert_r16g16_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
932 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
934 unsigned int x
, y
, z
;
936 unsigned short *Dest
;
938 for (z
= 0; z
< depth
; z
++)
940 for (y
= 0; y
< height
; y
++)
942 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
943 Dest
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
944 for (x
= 0; x
< width
; x
++ )
946 const DWORD color
= (*Source
++);
947 /* B */ Dest
[0] = 0xffff;
948 /* G */ Dest
[1] = (color
>> 16) + 32768; /* V */
949 /* R */ Dest
[2] = (color
& 0xffff) + 32768; /* U */
956 static void convert_r16g16(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
957 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
959 unsigned int x
, y
, z
;
963 for (z
= 0; z
< depth
; z
++)
965 for (y
= 0; y
< height
; y
++)
967 Source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
968 Dest
= (WORD
*) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
969 for (x
= 0; x
< width
; x
++ )
971 WORD green
= (*Source
++);
972 WORD red
= (*Source
++);
975 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
976 * shader overwrites it anyway */
984 static void convert_r32g32_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
985 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
987 unsigned int x
, y
, z
;
991 for (z
= 0; z
< depth
; z
++)
993 for (y
= 0; y
< height
; y
++)
995 Source
= (const float *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
996 Dest
= (float *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
997 for (x
= 0; x
< width
; x
++ )
999 float green
= (*Source
++);
1000 float red
= (*Source
++);
1010 static void convert_s8_uint_d24_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1011 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1013 unsigned int x
, y
, z
;
1015 for (z
= 0; z
< depth
; z
++)
1017 for (y
= 0; y
< height
; ++y
)
1019 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1020 float *dest_f
= (float *)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1021 DWORD
*dest_s
= (DWORD
*)dest_f
;
1023 for (x
= 0; x
< width
; ++x
)
1025 dest_f
[x
* 2] = float_24_to_32((source
[x
] & 0xffffff00u
) >> 8);
1026 dest_s
[x
* 2 + 1] = source
[x
] & 0xff;
1032 static void x8_d24_unorm_upload(const BYTE
*src
, BYTE
*dst
,
1033 unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
1034 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
1035 unsigned int width
, unsigned int height
, unsigned int depth
)
1037 unsigned int x
, y
, z
;
1039 for (z
= 0; z
< depth
; ++z
)
1041 for (y
= 0; y
< height
; ++y
)
1043 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1044 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1046 for (x
= 0; x
< width
; ++x
)
1048 dest
[x
] = source
[x
] << 8 | ((source
[x
] >> 16) & 0xff);
1054 static void x8_d24_unorm_download(const BYTE
*src
, BYTE
*dst
,
1055 unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
1056 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
1057 unsigned int width
, unsigned int height
, unsigned int depth
)
1059 unsigned int x
, y
, z
;
1061 for (z
= 0; z
< depth
; ++z
)
1063 for (y
= 0; y
< height
; ++y
)
1065 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1066 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1068 for (x
= 0; x
< width
; ++x
)
1070 dest
[x
] = source
[x
] >> 8;
1076 static BOOL
color_in_range(const struct wined3d_color_key
*color_key
, DWORD color
)
1078 /* FIXME: Is this really how color keys are supposed to work? I think it
1079 * makes more sense to compare the individual channels. */
1080 return color
>= color_key
->color_space_low_value
1081 && color
<= color_key
->color_space_high_value
;
1084 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1085 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1086 const struct wined3d_color_key
*color_key
)
1088 const WORD
*src_row
;
1092 for (y
= 0; y
< height
; ++y
)
1094 src_row
= (WORD
*)&src
[src_pitch
* y
];
1095 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
1096 for (x
= 0; x
< width
; ++x
)
1098 WORD src_color
= src_row
[x
];
1099 if (!color_in_range(color_key
, src_color
))
1100 dst_row
[x
] = 0x8000u
| ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
1102 dst_row
[x
] = ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
1107 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1108 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1109 const struct wined3d_color_key
*color_key
)
1111 const WORD
*src_row
;
1115 for (y
= 0; y
< height
; ++y
)
1117 src_row
= (WORD
*)&src
[src_pitch
* y
];
1118 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
1119 for (x
= 0; x
< width
; ++x
)
1121 WORD src_color
= src_row
[x
];
1122 if (color_in_range(color_key
, src_color
))
1123 dst_row
[x
] = src_color
& ~0x8000;
1125 dst_row
[x
] = src_color
| 0x8000;
1130 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1131 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1132 const struct wined3d_color_key
*color_key
)
1134 const BYTE
*src_row
;
1138 for (y
= 0; y
< height
; ++y
)
1140 src_row
= &src
[src_pitch
* y
];
1141 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1142 for (x
= 0; x
< width
; ++x
)
1144 DWORD src_color
= (src_row
[x
* 3 + 2] << 16) | (src_row
[x
* 3 + 1] << 8) | src_row
[x
* 3];
1145 if (!color_in_range(color_key
, src_color
))
1146 dst_row
[x
] = src_color
| 0xff000000;
1151 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1152 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1153 const struct wined3d_color_key
*color_key
)
1155 const DWORD
*src_row
;
1159 for (y
= 0; y
< height
; ++y
)
1161 src_row
= (DWORD
*)&src
[src_pitch
* y
];
1162 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1163 for (x
= 0; x
< width
; ++x
)
1165 DWORD src_color
= src_row
[x
];
1166 if (color_in_range(color_key
, src_color
))
1167 dst_row
[x
] = src_color
& ~0xff000000;
1169 dst_row
[x
] = src_color
| 0xff000000;
1174 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1175 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1176 const struct wined3d_color_key
*color_key
)
1178 const DWORD
*src_row
;
1182 for (y
= 0; y
< height
; ++y
)
1184 src_row
= (DWORD
*)&src
[src_pitch
* y
];
1185 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1186 for (x
= 0; x
< width
; ++x
)
1188 DWORD src_color
= src_row
[x
];
1189 if (color_in_range(color_key
, src_color
))
1190 src_color
&= ~0xff000000;
1191 dst_row
[x
] = src_color
;
1196 const struct wined3d_color_key_conversion
* wined3d_format_get_color_key_conversion(
1197 const struct wined3d_texture
*texture
, BOOL need_alpha_ck
)
1199 const struct wined3d_format
*format
= texture
->resource
.format
;
1204 enum wined3d_format_id src_format
;
1205 struct wined3d_color_key_conversion conversion
;
1209 {WINED3DFMT_B5G6R5_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key
}},
1210 {WINED3DFMT_B5G5R5X1_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key
}},
1211 {WINED3DFMT_B8G8R8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key
}},
1212 {WINED3DFMT_B8G8R8X8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key
}},
1213 {WINED3DFMT_B8G8R8A8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key
}},
1216 if (need_alpha_ck
&& (texture
->async
.flags
& WINED3D_TEXTURE_ASYNC_COLOR_KEY
))
1218 for (i
= 0; i
< ARRAY_SIZE(color_key_info
); ++i
)
1220 if (color_key_info
[i
].src_format
== format
->id
)
1221 return &color_key_info
[i
].conversion
;
1224 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format
->id
));
1230 /* We intentionally don't support WINED3DFMT_D32_UNORM. No hardware driver
1231 * supports it, and applications get confused when we do.
1233 * The following formats explicitly don't have WINED3DFMT_FLAG_TEXTURE set:
1235 * These are never supported on native.
1236 * WINED3DFMT_B8G8R8_UNORM
1237 * WINED3DFMT_B2G3R3_UNORM
1238 * WINED3DFMT_L4A4_UNORM
1239 * WINED3DFMT_S1_UINT_D15_UNORM
1240 * WINED3DFMT_S4X4_UINT_D24_UNORM
1242 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
1243 * Since it is not widely available, don't offer it. Further no Windows driver
1244 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
1245 * WINED3DFMT_P8_UINT
1246 * WINED3DFMT_P8_UINT_A8_UNORM
1248 * These formats seem to be similar to the HILO formats in
1249 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
1250 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
1251 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
1252 * refused to support formats which can easily be emulated with pixel shaders,
1253 * so applications have to deal with not having NVHS and NVHU.
1255 * WINED3DFMT_NVHS */
1256 static const struct wined3d_format_texture_info format_texture_info
[] =
1258 /* format id gl_internal gl_srgb_internal gl_rt_internal
1259 gl_format gl_type conv_byte_count
1261 extension upload download */
1262 /* FourCC formats */
1263 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
1264 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
1265 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
1266 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
1269 {WINED3DFMT_UYVY
, GL_RG8
, GL_RG8
, 0,
1270 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1271 WINED3DFMT_FLAG_FILTERING
,
1272 ARB_TEXTURE_RG
, NULL
},
1273 {WINED3DFMT_UYVY
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1274 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1275 WINED3DFMT_FLAG_FILTERING
,
1276 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1277 {WINED3DFMT_UYVY
, GL_RGB_RAW_422_APPLE
, GL_RGB_RAW_422_APPLE
, 0,
1278 GL_RGB_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
1279 WINED3DFMT_FLAG_FILTERING
,
1280 APPLE_RGB_422
, NULL
},
1281 {WINED3DFMT_UYVY
, GL_RGB
, GL_RGB
, 0,
1282 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
1283 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
1284 APPLE_YCBCR_422
, NULL
},
1285 {WINED3DFMT_YUY2
, GL_RG8
, GL_RG8
, 0,
1286 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1287 WINED3DFMT_FLAG_FILTERING
,
1288 ARB_TEXTURE_RG
, NULL
},
1289 {WINED3DFMT_YUY2
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1290 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1291 WINED3DFMT_FLAG_FILTERING
,
1292 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1293 {WINED3DFMT_YUY2
, GL_RGB_RAW_422_APPLE
, GL_RGB_RAW_422_APPLE
, 0,
1294 GL_RGB_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
1295 WINED3DFMT_FLAG_FILTERING
,
1296 APPLE_RGB_422
, NULL
},
1297 {WINED3DFMT_YUY2
, GL_RGB
, GL_RGB
, 0,
1298 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
1299 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
1300 APPLE_YCBCR_422
, NULL
},
1301 {WINED3DFMT_YV12
, GL_R8
, GL_R8
, 0,
1302 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1303 WINED3DFMT_FLAG_FILTERING
,
1304 ARB_TEXTURE_RG
, NULL
},
1305 {WINED3DFMT_YV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1306 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1307 WINED3DFMT_FLAG_FILTERING
,
1308 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1309 {WINED3DFMT_NV12
, GL_R8
, GL_R8
, 0,
1310 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1311 WINED3DFMT_FLAG_FILTERING
,
1312 ARB_TEXTURE_RG
, NULL
},
1313 {WINED3DFMT_NV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1314 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1315 WINED3DFMT_FLAG_FILTERING
,
1316 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1317 {WINED3DFMT_DXT1
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1318 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1319 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1320 | WINED3DFMT_FLAG_SRGB_READ
,
1321 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1322 {WINED3DFMT_DXT2
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1323 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1324 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1325 | WINED3DFMT_FLAG_SRGB_READ
,
1326 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1327 {WINED3DFMT_DXT3
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1328 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1329 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1330 | WINED3DFMT_FLAG_SRGB_READ
,
1331 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1332 {WINED3DFMT_DXT4
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1333 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1334 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1335 | WINED3DFMT_FLAG_SRGB_READ
,
1336 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1337 {WINED3DFMT_DXT5
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1338 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1339 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1340 | WINED3DFMT_FLAG_SRGB_READ
,
1341 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1342 {WINED3DFMT_BC1_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1343 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1344 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1345 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1346 {WINED3DFMT_BC2_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1347 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1348 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1349 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1350 {WINED3DFMT_BC3_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1351 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1352 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1353 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1354 {WINED3DFMT_BC4_UNORM
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1355 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1356 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1357 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1358 {WINED3DFMT_BC4_SNORM
, GL_COMPRESSED_SIGNED_RED_RGTC1
, GL_COMPRESSED_SIGNED_RED_RGTC1
, 0,
1359 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1360 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1361 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1362 {WINED3DFMT_BC5_UNORM
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1363 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1364 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1365 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1366 {WINED3DFMT_BC5_SNORM
, GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_COMPRESSED_SIGNED_RG_RGTC2
, 0,
1367 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1368 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1369 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1370 {WINED3DFMT_BC6H_UF16
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, 0,
1371 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1372 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1373 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1374 {WINED3DFMT_BC6H_SF16
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, 0,
1375 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1376 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1377 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1378 {WINED3DFMT_BC7_UNORM
, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
, 0,
1379 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1380 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1381 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1383 {WINED3DFMT_R32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1384 GL_RED
, GL_FLOAT
, 0,
1385 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1386 ARB_TEXTURE_FLOAT
, NULL
},
1387 {WINED3DFMT_R32_FLOAT
, GL_R32F
, GL_R32F
, 0,
1388 GL_RED
, GL_FLOAT
, 0,
1389 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1390 ARB_TEXTURE_RG
, NULL
},
1391 {WINED3DFMT_R32G32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1392 GL_RGB
, GL_FLOAT
, 12,
1393 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1394 ARB_TEXTURE_FLOAT
, convert_r32g32_float
},
1395 {WINED3DFMT_R32G32_FLOAT
, GL_RG32F
, GL_RG32F
, 0,
1397 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1398 ARB_TEXTURE_RG
, NULL
},
1399 {WINED3DFMT_R32G32B32_FLOAT
, GL_RGB32F
, GL_RGB32F
, 0,
1400 GL_RGB
, GL_FLOAT
, 0,
1401 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1402 ARB_TEXTURE_FLOAT
, NULL
},
1403 {WINED3DFMT_R32G32B32A32_FLOAT
, GL_RGBA32F_ARB
, GL_RGBA32F_ARB
, 0,
1404 GL_RGBA
, GL_FLOAT
, 0,
1405 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1406 ARB_TEXTURE_FLOAT
, NULL
},
1408 {WINED3DFMT_R16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1409 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1410 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1411 ARB_TEXTURE_FLOAT
, NULL
},
1412 {WINED3DFMT_R16_FLOAT
, GL_R16F
, GL_R16F
, 0,
1413 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1414 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1415 ARB_TEXTURE_RG
, NULL
},
1416 {WINED3DFMT_R16G16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1417 GL_RGB
, GL_HALF_FLOAT_ARB
, 6,
1418 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1419 ARB_TEXTURE_FLOAT
, convert_r16g16
},
1420 {WINED3DFMT_R16G16_FLOAT
, GL_RG16F
, GL_RG16F
, 0,
1421 GL_RG
, GL_HALF_FLOAT_ARB
, 0,
1422 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1423 ARB_TEXTURE_RG
, NULL
},
1424 {WINED3DFMT_R16G16B16A16_FLOAT
, GL_RGBA16F_ARB
, GL_RGBA16F_ARB
, 0,
1425 GL_RGBA
, GL_HALF_FLOAT_ARB
, 0,
1426 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
1427 | WINED3DFMT_FLAG_VTF
,
1428 ARB_TEXTURE_FLOAT
, NULL
},
1429 {WINED3DFMT_R11G11B10_FLOAT
, GL_R11F_G11F_B10F
, GL_R11F_G11F_B10F
, 0,
1430 GL_RGB
, GL_UNSIGNED_INT_10F_11F_11F_REV
, 0,
1431 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
,
1433 /* Palettized formats */
1434 {WINED3DFMT_P8_UINT
, GL_R8
, GL_R8
, 0,
1435 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1437 ARB_TEXTURE_RG
, NULL
},
1438 {WINED3DFMT_P8_UINT
, GL_ALPHA8
, GL_ALPHA8
, 0,
1439 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1441 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1442 /* Standard ARGB formats */
1443 {WINED3DFMT_B8G8R8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1444 GL_BGR
, GL_UNSIGNED_BYTE
, 0,
1445 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
| WINED3DFMT_FLAG_RENDERTARGET
,
1446 WINED3D_GL_EXT_NONE
, NULL
},
1447 {WINED3DFMT_B8G8R8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1448 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1449 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1450 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1451 | WINED3DFMT_FLAG_VTF
,
1452 WINED3D_GL_EXT_NONE
, NULL
},
1453 {WINED3DFMT_B8G8R8X8_UNORM
, GL_RGB8
, GL_SRGB8_EXT
, 0,
1454 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1455 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1456 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
,
1457 WINED3D_GL_EXT_NONE
, NULL
},
1458 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB5
, GL_SRGB8_EXT
, GL_RGB8
,
1459 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1460 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1461 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
,
1462 WINED3D_GL_EXT_NONE
, NULL
},
1463 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB565
, GL_SRGB8_EXT
, GL_RGB8
,
1464 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1465 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1466 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
,
1467 ARB_ES2_COMPATIBILITY
, NULL
},
1468 {WINED3DFMT_B5G5R5X1_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1469 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1470 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1471 | WINED3DFMT_FLAG_RENDERTARGET
,
1472 WINED3D_GL_EXT_NONE
, NULL
},
1473 {WINED3DFMT_B5G5R5A1_UNORM
, GL_RGB5_A1
, GL_RGB5_A1
, 0,
1474 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1475 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1476 WINED3D_GL_EXT_NONE
, NULL
},
1477 {WINED3DFMT_B4G4R4A4_UNORM
, GL_RGBA4
, GL_SRGB8_ALPHA8_EXT
, 0,
1478 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1479 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1480 | WINED3DFMT_FLAG_SRGB_READ
,
1481 WINED3D_GL_EXT_NONE
, NULL
},
1482 {WINED3DFMT_B2G3R3_UNORM
, GL_R3_G3_B2
, GL_R3_G3_B2
, 0,
1483 GL_RGB
, GL_UNSIGNED_BYTE_3_3_2
, 0,
1484 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1485 WINED3D_GL_EXT_NONE
, NULL
},
1486 {WINED3DFMT_R8_UNORM
, GL_R8
, GL_R8
, 0,
1487 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1488 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1489 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1490 ARB_TEXTURE_RG
, NULL
},
1491 {WINED3DFMT_A8_UNORM
, GL_R8
, GL_R8
, 0,
1492 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1493 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1494 | WINED3DFMT_FLAG_RENDERTARGET
,
1495 ARB_TEXTURE_RG
, NULL
},
1496 {WINED3DFMT_A8_UNORM
, GL_ALPHA8
, GL_ALPHA8
, 0,
1497 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1498 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1499 | WINED3DFMT_FLAG_RENDERTARGET
,
1500 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1501 {WINED3DFMT_B4G4R4X4_UNORM
, GL_RGB4
, GL_RGB4
, 0,
1502 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1503 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1504 WINED3D_GL_EXT_NONE
, NULL
},
1505 {WINED3DFMT_R10G10B10A2_UINT
, GL_RGB10_A2UI
, GL_RGB10_A2UI
, 0,
1506 GL_RGBA_INTEGER
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1507 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1508 ARB_TEXTURE_RGB10_A2UI
, NULL
},
1509 {WINED3DFMT_R10G10B10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1510 GL_RGBA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1511 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1512 | WINED3DFMT_FLAG_RENDERTARGET
,
1513 WINED3D_GL_EXT_NONE
, NULL
},
1514 {WINED3DFMT_R8G8B8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1515 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1516 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1517 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1518 | WINED3DFMT_FLAG_VTF
,
1519 WINED3D_GL_EXT_NONE
, NULL
},
1520 {WINED3DFMT_R8G8B8A8_UINT
, GL_RGBA8UI
, GL_RGBA8UI
, 0,
1521 GL_RGBA_INTEGER
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1522 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1523 ARB_TEXTURE_RGB10_A2UI
, NULL
},
1524 {WINED3DFMT_R8G8B8A8_SINT
, GL_RGBA8I
, GL_RGBA8I
, 0,
1525 GL_RGBA_INTEGER
, GL_BYTE
, 0,
1526 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1527 EXT_TEXTURE_INTEGER
, NULL
},
1528 {WINED3DFMT_R8G8B8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1529 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1530 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1531 WINED3D_GL_EXT_NONE
, NULL
},
1532 {WINED3DFMT_R16G16_UNORM
, GL_RGB16
, GL_RGB16
, GL_RGBA16
,
1533 GL_RGB
, GL_UNSIGNED_SHORT
, 6,
1534 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1535 WINED3D_GL_EXT_NONE
, convert_r16g16
},
1536 {WINED3DFMT_R16G16_UNORM
, GL_RG16
, GL_RG16
, 0,
1537 GL_RG
, GL_UNSIGNED_SHORT
, 0,
1538 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1539 | WINED3DFMT_FLAG_RENDERTARGET
,
1540 ARB_TEXTURE_RG
, NULL
},
1541 {WINED3DFMT_B10G10R10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1542 GL_BGRA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1543 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1544 | WINED3DFMT_FLAG_RENDERTARGET
,
1545 WINED3D_GL_EXT_NONE
, NULL
},
1546 {WINED3DFMT_R16G16B16A16_UNORM
, GL_RGBA16
, GL_RGBA16
, 0,
1547 GL_RGBA
, GL_UNSIGNED_SHORT
, 0,
1548 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1549 | WINED3DFMT_FLAG_RENDERTARGET
,
1550 WINED3D_GL_EXT_NONE
, NULL
},
1551 {WINED3DFMT_R8G8_UNORM
, GL_RG8
, GL_RG8
, 0,
1552 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1553 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1554 | WINED3DFMT_FLAG_RENDERTARGET
,
1555 ARB_TEXTURE_RG
, NULL
},
1556 {WINED3DFMT_R8G8_UINT
, GL_RG8UI
, GL_RG8UI
, 0,
1557 GL_RG_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1558 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1559 ARB_TEXTURE_RG
, NULL
},
1560 {WINED3DFMT_R8G8_SINT
, GL_RG8I
, GL_RG8I
, 0,
1561 GL_RG_INTEGER
, GL_BYTE
, 0,
1562 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1563 ARB_TEXTURE_RG
, NULL
},
1564 {WINED3DFMT_R16G16B16A16_UINT
, GL_RGBA16UI
, GL_RGBA16UI
, 0,
1565 GL_RGBA_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1566 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1567 EXT_TEXTURE_INTEGER
, NULL
},
1568 {WINED3DFMT_R16G16B16A16_SINT
, GL_RGBA16I
, GL_RGBA16I
, 0,
1569 GL_RGBA_INTEGER
, GL_SHORT
, 0,
1570 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1571 EXT_TEXTURE_INTEGER
, NULL
},
1572 {WINED3DFMT_R32G32_UINT
, GL_RG32UI
, GL_RG32UI
, 0,
1573 GL_RG_INTEGER
, GL_UNSIGNED_INT
, 0,
1574 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1575 ARB_TEXTURE_RG
, NULL
},
1576 {WINED3DFMT_R32G32_SINT
, GL_RG32I
, GL_RG32I
, 0,
1577 GL_RG_INTEGER
, GL_INT
, 0,
1578 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1579 ARB_TEXTURE_RG
, NULL
},
1580 {WINED3DFMT_R16G16_UINT
, GL_RG16UI
, GL_RG16UI
, 0,
1581 GL_RG_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1582 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1583 ARB_TEXTURE_RG
, NULL
},
1584 {WINED3DFMT_R16G16_SINT
, GL_RG16I
, GL_RG16I
, 0,
1585 GL_RG_INTEGER
, GL_SHORT
, 0,
1586 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1587 ARB_TEXTURE_RG
, NULL
},
1588 {WINED3DFMT_R32_UINT
, GL_R32UI
, GL_R32UI
, 0,
1589 GL_RED_INTEGER
, GL_UNSIGNED_INT
, 0,
1590 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1591 ARB_TEXTURE_RG
, NULL
},
1592 {WINED3DFMT_R32_SINT
, GL_R32I
, GL_R32I
, 0,
1593 GL_RED_INTEGER
, GL_INT
, 0,
1594 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1595 ARB_TEXTURE_RG
, NULL
},
1596 {WINED3DFMT_R16_UNORM
, GL_R16
, GL_R16
, 0,
1597 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1598 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1599 | WINED3DFMT_FLAG_RENDERTARGET
,
1600 ARB_TEXTURE_RG
, NULL
},
1601 {WINED3DFMT_R16_UINT
, GL_R16UI
, GL_R16UI
, 0,
1602 GL_RED_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1603 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1604 ARB_TEXTURE_RG
, NULL
},
1605 {WINED3DFMT_R16_SINT
, GL_R16I
, GL_R16I
, 0,
1606 GL_RED_INTEGER
, GL_SHORT
, 0,
1607 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1608 ARB_TEXTURE_RG
, NULL
},
1609 {WINED3DFMT_R8_UINT
, GL_R8UI
, GL_R8UI
, 0,
1610 GL_RED_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1611 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1612 ARB_TEXTURE_RG
, NULL
},
1613 {WINED3DFMT_R8_SINT
, GL_R8I
, GL_R8I
, 0,
1614 GL_RED_INTEGER
, GL_BYTE
, 0,
1615 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1616 ARB_TEXTURE_RG
, NULL
},
1618 {WINED3DFMT_L8_UNORM
, GL_LUMINANCE8
, GL_SLUMINANCE8_EXT
, 0,
1619 GL_LUMINANCE
, GL_UNSIGNED_BYTE
, 0,
1620 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1621 | WINED3DFMT_FLAG_SRGB_READ
,
1622 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1623 {WINED3DFMT_L8_UNORM
, GL_R8
, GL_R8
, 0,
1624 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1625 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1626 | WINED3DFMT_FLAG_RENDERTARGET
,
1627 ARB_TEXTURE_RG
, NULL
},
1628 {WINED3DFMT_L8A8_UNORM
, GL_RG8
, GL_RG8
, 0,
1629 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1630 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1631 ARB_TEXTURE_RG
, NULL
},
1632 {WINED3DFMT_L8A8_UNORM
, GL_LUMINANCE8_ALPHA8
, GL_SLUMINANCE8_ALPHA8_EXT
, 0,
1633 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1634 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1635 | WINED3DFMT_FLAG_SRGB_READ
,
1636 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1637 {WINED3DFMT_L4A4_UNORM
, GL_RG8
, GL_RG8
, 0,
1638 GL_RG
, GL_UNSIGNED_BYTE
, 2,
1639 WINED3DFMT_FLAG_FILTERING
,
1640 ARB_TEXTURE_RG
, convert_l4a4_unorm
},
1641 {WINED3DFMT_L4A4_UNORM
, GL_LUMINANCE4_ALPHA4
, GL_LUMINANCE4_ALPHA4
, 0,
1642 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 2,
1643 WINED3DFMT_FLAG_FILTERING
,
1644 WINED3D_GL_LEGACY_CONTEXT
, convert_l4a4_unorm
},
1645 {WINED3DFMT_L16_UNORM
, GL_R16
, GL_R16
, 0,
1646 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1647 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1648 ARB_TEXTURE_RG
, NULL
},
1649 {WINED3DFMT_L16_UNORM
, GL_LUMINANCE16
, GL_LUMINANCE16
, 0,
1650 GL_LUMINANCE
, GL_UNSIGNED_SHORT
, 0,
1651 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1652 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1653 /* Bump mapping stuff */
1654 {WINED3DFMT_R8G8_SNORM
, GL_RGB8
, GL_RGB8
, 0,
1655 GL_BGR
, GL_UNSIGNED_BYTE
, 3,
1656 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1657 | WINED3DFMT_FLAG_BUMPMAP
,
1658 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm
},
1659 {WINED3DFMT_R8G8_SNORM
, GL_DSDT8_NV
, GL_DSDT8_NV
, 0,
1660 GL_DSDT_NV
, GL_BYTE
, 0,
1661 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1662 | WINED3DFMT_FLAG_BUMPMAP
,
1663 NV_TEXTURE_SHADER
, NULL
},
1664 {WINED3DFMT_R8G8_SNORM
, GL_RG8_SNORM
, GL_RG8_SNORM
, 0,
1666 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1667 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1668 EXT_TEXTURE_SNORM
, NULL
},
1669 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1670 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 2,
1671 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1672 | WINED3DFMT_FLAG_BUMPMAP
,
1673 WINED3D_GL_EXT_NONE
, convert_r5g5_snorm_l6_unorm
},
1674 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_DSDT8_MAG8_NV
, GL_DSDT8_MAG8_NV
, 0,
1675 GL_DSDT_MAG_NV
, GL_BYTE
, 3,
1676 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1677 | WINED3DFMT_FLAG_BUMPMAP
,
1678 NV_TEXTURE_SHADER
, convert_r5g5_snorm_l6_unorm_nv
},
1679 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB8_SNORM
, GL_RGB8_SNORM
, 0,
1680 GL_RGBA
, GL_BYTE
, 4,
1681 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1682 | WINED3DFMT_FLAG_BUMPMAP
,
1683 EXT_TEXTURE_SNORM
, convert_r5g5_snorm_l6_unorm_ext
},
1684 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1685 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4,
1686 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1687 | WINED3DFMT_FLAG_BUMPMAP
,
1688 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm_l8x8_unorm
},
1689 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_DSDT8_MAG8_INTENSITY8_NV
, GL_DSDT8_MAG8_INTENSITY8_NV
, 0,
1690 GL_DSDT_MAG_VIB_NV
, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV
, 4,
1691 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1692 | WINED3DFMT_FLAG_BUMPMAP
,
1693 NV_TEXTURE_SHADER
, convert_r8g8_snorm_l8x8_unorm_nv
},
1694 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8
, GL_RGBA8
, 0,
1695 GL_BGRA
, GL_UNSIGNED_BYTE
, 4,
1696 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1697 | WINED3DFMT_FLAG_BUMPMAP
,
1698 WINED3D_GL_EXT_NONE
, convert_r8g8b8a8_snorm
},
1699 {WINED3DFMT_R8G8B8A8_SNORM
, GL_SIGNED_RGBA8_NV
, GL_SIGNED_RGBA8_NV
, 0,
1700 GL_RGBA
, GL_BYTE
, 0,
1701 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1702 | WINED3DFMT_FLAG_BUMPMAP
,
1703 NV_TEXTURE_SHADER
, NULL
},
1704 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8_SNORM
, GL_RGBA8_SNORM
, 0,
1705 GL_RGBA
, GL_BYTE
, 0,
1706 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1707 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1708 EXT_TEXTURE_SNORM
, NULL
},
1709 {WINED3DFMT_R16G16_SNORM
, GL_RGB16
, GL_RGB16
, 0,
1710 GL_BGR
, GL_UNSIGNED_SHORT
, 6,
1711 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1712 | WINED3DFMT_FLAG_BUMPMAP
,
1713 WINED3D_GL_EXT_NONE
, convert_r16g16_snorm
},
1714 {WINED3DFMT_R16G16_SNORM
, GL_SIGNED_HILO16_NV
, GL_SIGNED_HILO16_NV
, 0,
1715 GL_HILO_NV
, GL_SHORT
, 0,
1716 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1717 | WINED3DFMT_FLAG_BUMPMAP
,
1718 NV_TEXTURE_SHADER
, NULL
},
1719 {WINED3DFMT_R16G16_SNORM
, GL_RG16_SNORM
, GL_RG16_SNORM
, 0,
1721 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1722 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1723 EXT_TEXTURE_SNORM
, NULL
},
1724 {WINED3DFMT_R16G16B16A16_SNORM
, GL_RGBA16_SNORM
, GL_RGBA16_SNORM
, 0,
1725 GL_RGBA
, GL_SHORT
, 0,
1726 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1727 | WINED3DFMT_FLAG_RENDERTARGET
,
1728 EXT_TEXTURE_SNORM
, NULL
},
1729 {WINED3DFMT_R16_SNORM
, GL_R16_SNORM
, GL_R16_SNORM
, 0,
1730 GL_RED
, GL_SHORT
, 0,
1731 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1732 | WINED3DFMT_FLAG_RENDERTARGET
,
1733 EXT_TEXTURE_SNORM
, NULL
},
1734 {WINED3DFMT_R8_SNORM
, GL_R8_SNORM
, GL_R8_SNORM
, 0,
1736 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1737 | WINED3DFMT_FLAG_RENDERTARGET
,
1738 EXT_TEXTURE_SNORM
, NULL
},
1739 /* Depth stencil formats */
1740 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1741 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1742 WINED3DFMT_FLAG_DEPTH_STENCIL
,
1743 WINED3D_GL_EXT_NONE
, NULL
},
1744 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT16
, GL_DEPTH_COMPONENT16
, 0,
1745 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1746 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1747 ARB_DEPTH_TEXTURE
, NULL
},
1748 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1749 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1750 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1751 | WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1752 ARB_DEPTH_TEXTURE
, NULL
},
1753 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1754 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1755 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1756 | WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1757 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1758 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1759 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 4,
1760 WINED3DFMT_FLAG_DEPTH_STENCIL
,
1761 WINED3D_GL_EXT_NONE
, x8_d24_unorm_upload
, x8_d24_unorm_download
},
1762 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1763 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 4,
1764 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1765 | WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1766 ARB_DEPTH_TEXTURE
, x8_d24_unorm_upload
, x8_d24_unorm_download
},
1767 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1768 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1769 WINED3DFMT_FLAG_DEPTH_STENCIL
,
1770 WINED3D_GL_EXT_NONE
, NULL
},
1771 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT16
, GL_DEPTH_COMPONENT16
, 0,
1772 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1773 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1774 | WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1775 ARB_DEPTH_TEXTURE
, NULL
},
1776 {WINED3DFMT_D32_FLOAT
, GL_DEPTH_COMPONENT32F
, GL_DEPTH_COMPONENT32F
, 0,
1777 GL_DEPTH_COMPONENT
, GL_FLOAT
, 0,
1778 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1779 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1780 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1781 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 0,
1782 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1783 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1784 {WINED3DFMT_S8_UINT_D24_FLOAT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1785 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 8,
1786 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1787 ARB_DEPTH_BUFFER_FLOAT
, convert_s8_uint_d24_float
},
1788 {WINED3DFMT_R32G32B32A32_UINT
, GL_RGBA32UI
, GL_RGBA32UI
, 0,
1789 GL_RGBA_INTEGER
, GL_UNSIGNED_INT
, 0,
1790 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1791 EXT_TEXTURE_INTEGER
, NULL
},
1792 {WINED3DFMT_R32G32B32A32_SINT
, GL_RGBA32I
, GL_RGBA32I
, 0,
1793 GL_RGBA_INTEGER
, GL_INT
, 0,
1794 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1795 EXT_TEXTURE_INTEGER
, NULL
},
1796 /* Vendor-specific formats */
1797 {WINED3DFMT_ATI1N
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1798 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1799 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1800 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1801 {WINED3DFMT_ATI2N
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, 0,
1802 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1803 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1804 ATI_TEXTURE_COMPRESSION_3DC
, NULL
},
1805 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1806 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1807 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1808 EXT_TEXTURE_COMPRESSION_RGTC
, NULL
},
1809 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1810 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1811 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1812 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1813 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1814 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1815 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1816 | WINED3DFMT_FLAG_DEPTH_STENCIL
,
1817 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1818 {WINED3DFMT_NULL
, 0, 0, 0,
1819 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1820 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
,
1821 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1822 /* DirectX 10 HDR formats */
1823 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, GL_RGB9_E5_EXT
, GL_RGB9_E5_EXT
, 0,
1824 GL_RGB
, GL_UNSIGNED_INT_5_9_9_9_REV_EXT
, 0,
1825 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1826 EXT_TEXTURE_SHARED_EXPONENT
, NULL
},
1829 struct wined3d_format_srgb_info
1831 enum wined3d_format_id srgb_format_id
;
1832 enum wined3d_format_id base_format_id
;
1835 static const struct wined3d_format_srgb_info format_srgb_info
[] =
1837 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_UNORM
},
1838 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_UNORM
},
1839 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_UNORM
},
1840 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_UNORM
},
1841 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_UNORM
},
1842 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_UNORM
},
1843 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_UNORM
},
1846 static inline int get_format_idx(enum wined3d_format_id format_id
)
1850 if (format_id
< WINED3D_FORMAT_FOURCC_BASE
)
1853 for (i
= 0; i
< ARRAY_SIZE(format_index_remap
); ++i
)
1855 if (format_index_remap
[i
].id
== format_id
)
1856 return format_index_remap
[i
].idx
;
1862 static struct wined3d_format_gl
*wined3d_format_gl_mutable(struct wined3d_format
*format
)
1864 return CONTAINING_RECORD(format
, struct wined3d_format_gl
, f
);
1867 static struct wined3d_format_vk
*wined3d_format_vk_mutable(struct wined3d_format
*format
)
1869 return CONTAINING_RECORD(format
, struct wined3d_format_vk
, f
);
1872 static struct wined3d_format
*get_format_by_idx(const struct wined3d_adapter
*adapter
, int fmt_idx
)
1874 return (struct wined3d_format
*)((BYTE
*)adapter
->formats
+ fmt_idx
* adapter
->format_size
);
1877 static struct wined3d_format_gl
*get_format_gl_by_idx(const struct wined3d_adapter
*adapter
, int fmt_idx
)
1879 return wined3d_format_gl_mutable(get_format_by_idx(adapter
, fmt_idx
));
1882 static struct wined3d_format
*get_format_internal(const struct wined3d_adapter
*adapter
,
1883 enum wined3d_format_id format_id
)
1887 if ((fmt_idx
= get_format_idx(format_id
)) == -1)
1889 ERR("Format %s (%#x) not found.\n", debug_d3dformat(format_id
), format_id
);
1893 return get_format_by_idx(adapter
, fmt_idx
);
1896 static struct wined3d_format_gl
*get_format_gl_internal(const struct wined3d_adapter
*adapter
,
1897 enum wined3d_format_id format_id
)
1899 struct wined3d_format
*format
;
1901 if ((format
= get_format_internal(adapter
, format_id
)))
1902 return wined3d_format_gl_mutable(format
);
1907 static void copy_format(const struct wined3d_adapter
*adapter
,
1908 struct wined3d_format
*dst_format
, const struct wined3d_format
*src_format
)
1910 enum wined3d_format_id id
= dst_format
->id
;
1911 memcpy(dst_format
, src_format
, adapter
->format_size
);
1912 dst_format
->id
= id
;
1915 static void format_set_flag(struct wined3d_format
*format
, unsigned int flag
)
1919 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1920 format
->flags
[i
] |= flag
;
1923 static void format_clear_flag(struct wined3d_format
*format
, unsigned int flag
)
1927 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1928 format
->flags
[i
] &= ~flag
;
1931 static enum wined3d_channel_type
map_channel_type(char t
)
1936 return WINED3D_CHANNEL_TYPE_UNORM
;
1938 return WINED3D_CHANNEL_TYPE_SNORM
;
1940 return WINED3D_CHANNEL_TYPE_UINT
;
1942 return WINED3D_CHANNEL_TYPE_SINT
;
1944 return WINED3D_CHANNEL_TYPE_FLOAT
;
1946 return WINED3D_CHANNEL_TYPE_DEPTH
;
1948 return WINED3D_CHANNEL_TYPE_STENCIL
;
1950 return WINED3D_CHANNEL_TYPE_UNUSED
;
1952 ERR("Invalid channel type '%c'.\n", t
);
1953 return WINED3D_CHANNEL_TYPE_NONE
;
1957 static BOOL
init_format_base_info(struct wined3d_adapter
*adapter
)
1959 struct wined3d_format
*format
;
1962 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
1964 if (!(format
= get_format_internal(adapter
, formats
[i
].id
)))
1967 format
->id
= formats
[i
].id
;
1968 format
->red_size
= formats
[i
].red_size
;
1969 format
->green_size
= formats
[i
].green_size
;
1970 format
->blue_size
= formats
[i
].blue_size
;
1971 format
->alpha_size
= formats
[i
].alpha_size
;
1972 format
->red_offset
= formats
[i
].red_offset
;
1973 format
->green_offset
= formats
[i
].green_offset
;
1974 format
->blue_offset
= formats
[i
].blue_offset
;
1975 format
->alpha_offset
= formats
[i
].alpha_offset
;
1976 format
->byte_count
= formats
[i
].bpp
;
1977 format
->depth_size
= formats
[i
].depth_size
;
1978 format
->stencil_size
= formats
[i
].stencil_size
;
1979 format
->block_width
= 1;
1980 format
->block_height
= 1;
1981 format
->block_byte_count
= formats
[i
].bpp
;
1984 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
1986 struct wined3d_format
*typeless_format
;
1987 unsigned int component_count
= 0;
1990 if (!(format
= get_format_internal(adapter
, typed_formats
[i
].id
)))
1993 if (!(typeless_format
= get_format_internal(adapter
, typed_formats
[i
].typeless_id
)))
1996 format
->id
= typed_formats
[i
].id
;
1997 format
->red_size
= typeless_format
->red_size
;
1998 format
->green_size
= typeless_format
->green_size
;
1999 format
->blue_size
= typeless_format
->blue_size
;
2000 format
->alpha_size
= typeless_format
->alpha_size
;
2001 format
->red_offset
= typeless_format
->red_offset
;
2002 format
->green_offset
= typeless_format
->green_offset
;
2003 format
->blue_offset
= typeless_format
->blue_offset
;
2004 format
->alpha_offset
= typeless_format
->alpha_offset
;
2005 format
->byte_count
= typeless_format
->byte_count
;
2006 format
->depth_size
= typeless_format
->depth_size
;
2007 format
->stencil_size
= typeless_format
->stencil_size
;
2008 format
->block_width
= typeless_format
->block_width
;
2009 format
->block_height
= typeless_format
->block_height
;
2010 format
->block_byte_count
= typeless_format
->block_byte_count
;
2011 format
->typeless_id
= typeless_format
->id
;
2013 typeless_format
->typeless_id
= typeless_format
->id
;
2015 for (j
= 0; j
< strlen(typed_formats
[i
].channels
); ++j
)
2017 enum wined3d_channel_type channel_type
= map_channel_type(typed_formats
[i
].channels
[j
]);
2019 if (channel_type
== WINED3D_CHANNEL_TYPE_UNORM
|| channel_type
== WINED3D_CHANNEL_TYPE_SNORM
)
2020 flags
|= WINED3DFMT_FLAG_NORMALISED
;
2021 if (channel_type
== WINED3D_CHANNEL_TYPE_UINT
|| channel_type
== WINED3D_CHANNEL_TYPE_SINT
)
2022 flags
|= WINED3DFMT_FLAG_INTEGER
;
2023 if (channel_type
== WINED3D_CHANNEL_TYPE_FLOAT
)
2024 flags
|= WINED3DFMT_FLAG_FLOAT
;
2025 if (channel_type
!= WINED3D_CHANNEL_TYPE_UNUSED
)
2028 if (channel_type
== WINED3D_CHANNEL_TYPE_DEPTH
&& !format
->depth_size
)
2030 format
->depth_size
= format
->red_size
;
2031 format
->red_size
= format
->red_offset
= 0;
2034 if (channel_type
== WINED3D_CHANNEL_TYPE_STENCIL
&& !format
->stencil_size
)
2036 format
->stencil_size
= format
->green_size
;
2037 format
->green_size
= format
->green_offset
= 0;
2041 format
->component_count
= component_count
;
2042 format_set_flag(format
, flags
);
2045 for (i
= 0; i
< ARRAY_SIZE(ddi_formats
); ++i
)
2047 if (!(format
= get_format_internal(adapter
, ddi_formats
[i
].id
)))
2050 format
->ddi_format
= ddi_formats
[i
].ddi_format
;
2053 for (i
= 0; i
< ARRAY_SIZE(format_base_flags
); ++i
)
2055 if (!(format
= get_format_internal(adapter
, format_base_flags
[i
].id
)))
2058 format_set_flag(format
, format_base_flags
[i
].flags
);
2064 static BOOL
init_format_block_info(struct wined3d_adapter
*adapter
)
2066 struct wined3d_format
*format
;
2069 for (i
= 0; i
< ARRAY_SIZE(format_block_info
); ++i
)
2071 if (!(format
= get_format_internal(adapter
, format_block_info
[i
].id
)))
2074 format
->block_width
= format_block_info
[i
].block_width
;
2075 format
->block_height
= format_block_info
[i
].block_height
;
2076 format
->block_byte_count
= format_block_info
[i
].block_byte_count
;
2077 format_set_flag(format
, WINED3DFMT_FLAG_BLOCKS
| format_block_info
[i
].flags
);
2083 /* Most compressed formats are not supported for 3D textures by OpenGL.
2085 * In the case of the S3TC/DXTn formats, NV_texture_compression_vtc provides
2086 * these formats for 3D textures, but unfortunately the block layout is
2087 * different from the one used by Direct3D.
2089 * Since applications either don't check format availability at all before
2090 * using these, or refuse to run without them, we decompress them on upload.
2092 * Affected applications include "Heroes VI", "From Dust", "Halo Online" and
2094 static BOOL
init_format_decompress_info(struct wined3d_adapter
*adapter
)
2096 struct wined3d_format
*format
;
2099 for (i
= 0; i
< ARRAY_SIZE(format_decompress_info
); ++i
)
2101 if (!(format
= get_format_internal(adapter
, format_decompress_info
[i
].id
)))
2104 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] |= WINED3DFMT_FLAG_DECOMPRESS
;
2105 format
->decompress
= format_decompress_info
[i
].decompress
;
2111 static BOOL
init_srgb_formats(struct wined3d_adapter
*adapter
)
2113 struct wined3d_format
*format
, *srgb_format
;
2116 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
2118 if (!(srgb_format
= get_format_internal(adapter
, format_srgb_info
[i
].srgb_format_id
)))
2120 if (!(format
= get_format_internal(adapter
, format_srgb_info
[i
].base_format_id
)))
2123 copy_format(adapter
, srgb_format
, format
);
2129 static GLenum
wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type
)
2133 case WINED3D_GL_RES_TYPE_TEX_1D
:
2134 return GL_TEXTURE_1D
;
2135 case WINED3D_GL_RES_TYPE_TEX_2D
:
2136 return GL_TEXTURE_2D
;
2137 case WINED3D_GL_RES_TYPE_TEX_3D
:
2138 return GL_TEXTURE_3D
;
2139 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2140 return GL_TEXTURE_CUBE_MAP_ARB
;
2141 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2142 return GL_TEXTURE_RECTANGLE_ARB
;
2143 case WINED3D_GL_RES_TYPE_BUFFER
:
2144 return GL_TEXTURE_2D
; /* TODO: GL_TEXTURE_BUFFER. */
2145 case WINED3D_GL_RES_TYPE_RB
:
2146 return GL_RENDERBUFFER
;
2147 case WINED3D_GL_RES_TYPE_COUNT
:
2150 ERR("Unexpected GL resource type %u.\n", type
);
2154 static void delete_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
2155 enum wined3d_gl_resource_type d3d_type
, GLuint object
)
2159 case WINED3D_GL_RES_TYPE_TEX_1D
:
2160 case WINED3D_GL_RES_TYPE_TEX_2D
:
2161 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2162 case WINED3D_GL_RES_TYPE_TEX_3D
:
2163 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2164 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &object
);
2167 case WINED3D_GL_RES_TYPE_RB
:
2168 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &object
);
2171 case WINED3D_GL_RES_TYPE_BUFFER
:
2172 case WINED3D_GL_RES_TYPE_COUNT
:
2177 static void create_and_bind_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
2178 const struct wined3d_format_gl
*format_gl
,
2179 enum wined3d_gl_resource_type d3d_type
, GLuint
*object
, GLenum internal
)
2181 GLenum format
= format_gl
->format
;
2182 GLenum type
= format_gl
->type
;
2185 attach_type
= format_gl
->f
.depth_size
? GL_DEPTH_ATTACHMENT
: GL_COLOR_ATTACHMENT0
;
2188 case WINED3D_GL_RES_TYPE_TEX_1D
:
2189 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2190 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, *object
);
2191 gl_info
->gl_ops
.gl
.p_glTexImage1D(GL_TEXTURE_1D
, 0, internal
, 16, 0, format
, type
, NULL
);
2192 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2193 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2195 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_1D
, *object
, 0);
2196 if (format_gl
->f
.stencil_size
)
2197 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
,
2198 GL_STENCIL_ATTACHMENT
, GL_TEXTURE_1D
, *object
, 0);
2201 case WINED3D_GL_RES_TYPE_TEX_2D
:
2202 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2203 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2204 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(d3d_type
), *object
);
2205 gl_info
->gl_ops
.gl
.p_glTexImage2D(wined3d_gl_type_to_enum(d3d_type
), 0, internal
, 16, 16, 0,
2206 format
, type
, NULL
);
2207 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2208 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2210 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
2211 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
2212 if (format_gl
->f
.stencil_size
)
2213 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
2214 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
2217 case WINED3D_GL_RES_TYPE_TEX_3D
:
2218 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2219 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_3D
, *object
);
2220 GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D
, 0, internal
, 16, 16, 16, 0, format
, type
, NULL
));
2221 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2222 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2224 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_3D
, *object
, 0, 0);
2225 if (format_gl
->f
.stencil_size
)
2226 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
,
2227 GL_STENCIL_ATTACHMENT
, GL_TEXTURE_3D
, *object
, 0, 0);
2230 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2231 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2232 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, *object
);
2233 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, internal
, 16, 16, 0,
2234 format
, type
, NULL
);
2235 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
, 0, internal
, 16, 16, 0,
2236 format
, type
, NULL
);
2237 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
, 0, internal
, 16, 16, 0,
2238 format
, type
, NULL
);
2239 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
, 0, internal
, 16, 16, 0,
2240 format
, type
, NULL
);
2241 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
, 0, internal
, 16, 16, 0,
2242 format
, type
, NULL
);
2243 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
, 0, internal
, 16, 16, 0,
2244 format
, type
, NULL
);
2245 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2246 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2248 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
2249 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
2250 if (format_gl
->f
.stencil_size
)
2251 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
2252 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
2255 case WINED3D_GL_RES_TYPE_RB
:
2256 gl_info
->fbo_ops
.glGenRenderbuffers(1, object
);
2257 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, *object
);
2258 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, internal
, 16, 16);
2259 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, attach_type
, GL_RENDERBUFFER
, *object
);
2260 if (format_gl
->f
.stencil_size
)
2261 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2262 GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, *object
);
2265 case WINED3D_GL_RES_TYPE_BUFFER
:
2266 case WINED3D_GL_RES_TYPE_COUNT
:
2270 /* Ideally we'd skip all formats already known not to work on textures
2271 * by checking for WINED3DFMT_FLAG_TEXTURE here. However, we want to
2272 * know if we can attach WINED3DFMT_P8_UINT textures to FBOs, and this
2273 * format never has WINED3DFMT_FLAG_TEXTURE set. Instead, swallow GL
2274 * errors generated by invalid formats. */
2275 while (gl_info
->gl_ops
.gl
.p_glGetError());
2278 static void draw_test_quad(struct wined3d_caps_gl_ctx
*ctx
, const struct wined3d_vec3
*geometry
,
2279 const struct wined3d_color
*color
)
2281 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2282 static const struct wined3d_vec3 default_geometry
[] =
2284 {-1.0f
, -1.0f
, 0.0f
},
2285 { 1.0f
, -1.0f
, 0.0f
},
2286 {-1.0f
, 1.0f
, 0.0f
},
2287 { 1.0f
, 1.0f
, 0.0f
},
2289 static const char vs_core_header
[] =
2293 "out vec4 out_color;\n"
2295 static const char vs_legacy_header
[] =
2297 "attribute vec4 pos;\n"
2298 "attribute vec4 color;\n"
2299 "varying vec4 out_color;\n"
2301 static const char vs_body
[] =
2304 " gl_Position = pos;\n"
2305 " out_color = color;\n"
2307 static const char fs_core
[] =
2309 "in vec4 out_color;\n"
2310 "out vec4 fragment_color;\n"
2314 " fragment_color = out_color;\n"
2316 static const char fs_legacy
[] =
2318 "varying vec4 out_color;\n"
2322 " gl_FragData[0] = out_color;\n"
2324 const char *source
[2];
2325 GLuint vs_id
, fs_id
;
2329 geometry
= default_geometry
;
2331 if (!gl_info
->supported
[ARB_VERTEX_BUFFER_OBJECT
] || !gl_info
->supported
[ARB_VERTEX_SHADER
]
2332 || !gl_info
->supported
[ARB_FRAGMENT_SHADER
])
2334 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
2335 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
2336 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2337 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
2338 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2340 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
2341 gl_info
->gl_ops
.gl
.p_glColor4f(color
->r
, color
->g
, color
->b
, color
->a
);
2342 for (i
= 0; i
< 4; ++i
)
2343 gl_info
->gl_ops
.gl
.p_glVertex3fv(&geometry
[i
].x
);
2344 gl_info
->gl_ops
.gl
.p_glEnd();
2345 checkGLcall("draw quad");
2350 GL_EXTCALL(glGenBuffers(1, &ctx
->test_vbo
));
2351 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, ctx
->test_vbo
));
2352 GL_EXTCALL(glBufferData(GL_ARRAY_BUFFER
, sizeof(struct wined3d_vec3
) * 4, geometry
, GL_STREAM_DRAW
));
2353 GL_EXTCALL(glVertexAttribPointer(0, 3, GL_FLOAT
, FALSE
, 0, NULL
));
2354 GL_EXTCALL(glVertexAttrib4f(1, color
->r
, color
->g
, color
->b
, color
->a
));
2355 GL_EXTCALL(glEnableVertexAttribArray(0));
2356 GL_EXTCALL(glDisableVertexAttribArray(1));
2358 if (!ctx
->test_program_id
)
2360 BOOL use_glsl_150
= gl_info
->glsl_version
>= MAKEDWORD_VERSION(1, 50);
2362 ctx
->test_program_id
= GL_EXTCALL(glCreateProgram());
2364 vs_id
= GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER
));
2365 source
[0] = use_glsl_150
? vs_core_header
: vs_legacy_header
;
2366 source
[1] = vs_body
;
2367 GL_EXTCALL(glShaderSource(vs_id
, 2, source
, NULL
));
2368 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, vs_id
));
2369 GL_EXTCALL(glDeleteShader(vs_id
));
2371 fs_id
= GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER
));
2372 source
[0] = use_glsl_150
? fs_core
: fs_legacy
;
2373 GL_EXTCALL(glShaderSource(fs_id
, 1, source
, NULL
));
2374 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, fs_id
));
2375 GL_EXTCALL(glDeleteShader(fs_id
));
2377 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 0, "pos"));
2378 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 1, "color"));
2381 GL_EXTCALL(glBindFragDataLocation(ctx
->test_program_id
, 0, "fragment_color"));
2383 GL_EXTCALL(glCompileShader(vs_id
));
2384 print_glsl_info_log(gl_info
, vs_id
, FALSE
);
2385 GL_EXTCALL(glCompileShader(fs_id
));
2386 print_glsl_info_log(gl_info
, fs_id
, FALSE
);
2387 GL_EXTCALL(glLinkProgram(ctx
->test_program_id
));
2388 shader_glsl_validate_link(gl_info
, ctx
->test_program_id
);
2390 GL_EXTCALL(glUseProgram(ctx
->test_program_id
));
2392 gl_info
->gl_ops
.gl
.p_glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
2394 GL_EXTCALL(glUseProgram(0));
2395 GL_EXTCALL(glDisableVertexAttribArray(0));
2396 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, 0));
2397 checkGLcall("draw quad");
2400 /* Context activation is done by the caller. */
2401 static void check_fbo_compat(struct wined3d_caps_gl_ctx
*ctx
, struct wined3d_format_gl
*format
)
2403 /* Check if the default internal format is supported as a frame buffer
2404 * target, otherwise fall back to the render target internal.
2406 * Try to stick to the standard format if possible, this limits precision differences. */
2407 static const struct wined3d_color black
= {0.0f
, 0.0f
, 0.0f
, 1.0f
};
2408 static const struct wined3d_color half_transparent_red
= {1.0f
, 0.0f
, 0.0f
, 0.5f
};
2409 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2410 GLenum status
, rt_internal
= format
->rt_internal
;
2411 GLuint object
, color_rb
;
2412 enum wined3d_gl_resource_type type
;
2413 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2415 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2417 for (type
= 0; type
< ARRAY_SIZE(format
->f
.flags
); ++type
)
2419 const char *type_string
= "color";
2421 if (type
== WINED3D_GL_RES_TYPE_BUFFER
)
2424 create_and_bind_fbo_attachment(gl_info
, format
, type
, &object
, format
->internal
);
2426 if (format
->f
.flags
[type
] & WINED3DFMT_FLAG_DEPTH_STENCIL
)
2428 gl_info
->fbo_ops
.glGenRenderbuffers(1, &color_rb
);
2429 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, color_rb
);
2430 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2431 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 1);
2433 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 16);
2435 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2436 GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, color_rb
);
2437 checkGLcall("Create and attach color rb attachment");
2438 type_string
= "depth / stencil";
2441 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2442 checkGLcall("Framebuffer format check");
2444 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2446 TRACE("Format %s is supported as FBO %s attachment, type %u.\n",
2447 debug_d3dformat(format
->f
.id
), type_string
, type
);
2448 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2449 format
->rt_internal
= format
->internal
;
2450 regular_fmt_used
= TRUE
;
2456 if (format
->f
.flags
[type
] & (WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH_STENCIL
))
2458 WARN("Format %s with rendertarget flag is not supported as FBO color attachment (type %u),"
2459 " and no fallback specified.\n", debug_d3dformat(format
->f
.id
), type
);
2460 format
->f
.flags
[type
] &= ~(WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH_STENCIL
);
2464 TRACE("Format %s is not supported as FBO %s attachment, type %u.\n",
2465 debug_d3dformat(format
->f
.id
), type_string
, type
);
2467 format
->rt_internal
= format
->internal
;
2471 TRACE("Format %s is not supported as FBO %s attachment (type %u),"
2472 " trying rtInternal format as fallback.\n",
2473 debug_d3dformat(format
->f
.id
), type_string
, type
);
2475 while (gl_info
->gl_ops
.gl
.p_glGetError());
2477 delete_fbo_attachment(gl_info
, type
, object
);
2478 create_and_bind_fbo_attachment(gl_info
, format
, type
, &object
, format
->rt_internal
);
2480 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2481 checkGLcall("Framebuffer format check");
2483 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2485 TRACE("Format %s rtInternal format is supported as FBO %s attachment, type %u.\n",
2486 debug_d3dformat(format
->f
.id
), type_string
, type
);
2487 fallback_fmt_used
= TRUE
;
2491 WARN("Format %s rtInternal format is not supported as FBO %s attachment, type %u.\n",
2492 debug_d3dformat(format
->f
.id
), type_string
, type
);
2493 format
->f
.flags
[type
] &= ~(WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH_STENCIL
);
2498 if (status
== GL_FRAMEBUFFER_COMPLETE
2499 && ((format
->f
.flags
[type
] & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
)
2500 || !(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2501 && !(format
->f
.flags
[type
] & WINED3DFMT_FLAG_INTEGER
)
2502 && format
->f
.id
!= WINED3DFMT_NULL
&& format
->f
.id
!= WINED3DFMT_P8_UINT
2503 && format
->format
!= GL_LUMINANCE
&& format
->format
!= GL_LUMINANCE_ALPHA
2504 && (format
->f
.red_size
|| format
->f
.alpha_size
))
2506 DWORD readback
[16 * 16 * 16], color
= 0, r_range
, a_range
;
2511 if (gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2513 gl_info
->fbo_ops
.glGenRenderbuffers(1, &rb
);
2514 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
2515 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2516 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 1);
2518 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 16);
2519 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2520 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2521 checkGLcall("RB attachment");
2524 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2525 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.0f
, 1.0f
);
2526 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
2527 if (gl_info
->gl_ops
.gl
.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION
)
2529 while (gl_info
->gl_ops
.gl
.p_glGetError());
2530 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2531 debug_d3dformat(format
->f
.id
), type
);
2532 format
->f
.flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2536 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2537 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2538 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2540 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 16);
2541 gl_info
->gl_ops
.gl
.p_glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2543 draw_test_quad(ctx
, NULL
, &black
);
2545 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2547 draw_test_quad(ctx
, NULL
, &half_transparent_red
);
2549 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2553 case WINED3D_GL_RES_TYPE_TEX_1D
:
2554 /* Rebinding texture to workaround a fglrx bug. */
2555 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, object
);
2556 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_1D
, 0, GL_BGRA
,
2557 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2558 color
= readback
[7];
2561 case WINED3D_GL_RES_TYPE_TEX_2D
:
2562 case WINED3D_GL_RES_TYPE_TEX_3D
:
2563 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2564 /* Rebinding texture to workaround a fglrx bug. */
2565 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(type
), object
);
2566 gl_info
->gl_ops
.gl
.p_glGetTexImage(wined3d_gl_type_to_enum(type
), 0, GL_BGRA
,
2567 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2568 color
= readback
[7 * 16 + 7];
2571 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2572 /* Rebinding texture to workaround a fglrx bug. */
2573 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, object
);
2574 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, GL_BGRA
,
2575 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2576 color
= readback
[7 * 16 + 7];
2579 case WINED3D_GL_RES_TYPE_RB
:
2580 gl_info
->gl_ops
.gl
.p_glReadPixels(0, 0, 16, 16,
2581 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2582 color
= readback
[7 * 16 + 7];
2585 case WINED3D_GL_RES_TYPE_BUFFER
:
2586 case WINED3D_GL_RES_TYPE_COUNT
:
2590 checkGLcall("Post-pixelshader blending check");
2593 r
= (color
& 0x00ff0000u
) >> 16;
2595 r_range
= format
->f
.red_size
< 8 ? 1u << (8 - format
->f
.red_size
) : 1;
2596 a_range
= format
->f
.alpha_size
< 8 ? 1u << (8 - format
->f
.alpha_size
) : 1;
2597 if (format
->f
.red_size
&& (r
< 0x7f - r_range
|| r
> 0x7f + r_range
))
2599 else if (format
->f
.alpha_size
> 1 && (a
< 0xbf - a_range
|| a
> 0xbf + a_range
))
2603 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2604 debug_d3dformat(format
->f
.id
), type
);
2605 TRACE("Color output: %#x\n", color
);
2606 format
->f
.flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2610 TRACE("Format %s supports post-pixelshader blending, type %u.\n",
2611 debug_d3dformat(format
->f
.id
), type
);
2612 TRACE("Color output: %#x\n", color
);
2613 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2617 if (gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2619 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2620 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2621 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &rb
);
2622 checkGLcall("RB cleanup");
2626 if (format
->internal
!= format
->srgb_internal
)
2628 delete_fbo_attachment(gl_info
, type
, object
);
2629 create_and_bind_fbo_attachment(gl_info
, format
, type
, &object
, format
->srgb_internal
);
2631 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2632 checkGLcall("Framebuffer format check");
2634 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2636 TRACE("Format %s's sRGB format is FBO attachable, type %u.\n",
2637 debug_d3dformat(format
->f
.id
), type
);
2638 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2639 if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2640 format
->internal
= format
->srgb_internal
;
2644 WARN("Format %s's sRGB format is not FBO attachable, type %u.\n",
2645 debug_d3dformat(format
->f
.id
), type
);
2646 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_SRGB_WRITE
);
2649 else if (status
== GL_FRAMEBUFFER_COMPLETE
)
2650 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2652 if (format
->f
.flags
[type
] & WINED3DFMT_FLAG_DEPTH_STENCIL
)
2654 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, 0);
2655 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &color_rb
);
2658 delete_fbo_attachment(gl_info
, type
, object
);
2659 checkGLcall("Framebuffer format check cleanup");
2662 if (fallback_fmt_used
&& regular_fmt_used
)
2664 FIXME("Format %s needs different render target formats for different resource types.\n",
2665 debug_d3dformat(format
->f
.id
));
2666 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH_STENCIL
2667 | WINED3DFMT_FLAG_FBO_ATTACHABLE
| WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
2668 | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2672 static void query_format_flag(struct wined3d_gl_info
*gl_info
, struct wined3d_format_gl
*format
,
2673 GLint internal
, GLenum pname
, DWORD flag
, const char *string
)
2676 enum wined3d_gl_resource_type type
;
2678 for (type
= 0; type
< ARRAY_SIZE(format
->f
.flags
); ++type
)
2680 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
), internal
, pname
, 1, &value
);
2681 if (value
== GL_FULL_SUPPORT
)
2683 TRACE("Format %s supports %s, resource type %u.\n", debug_d3dformat(format
->f
.id
), string
, type
);
2684 format
->f
.flags
[type
] |= flag
;
2688 TRACE("Format %s doesn't support %s, resource type %u.\n", debug_d3dformat(format
->f
.id
), string
, type
);
2689 format
->f
.flags
[type
] &= ~flag
;
2694 /* Context activation is done by the caller. */
2695 static void init_format_fbo_compat_info(const struct wined3d_adapter
*adapter
,
2696 struct wined3d_caps_gl_ctx
*ctx
)
2698 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2699 unsigned int i
, type
;
2702 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2704 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
2706 struct wined3d_format_gl
*format
= get_format_gl_by_idx(adapter
, i
);
2707 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2708 GLenum rt_internal
= format
->rt_internal
;
2711 if (!format
->internal
)
2714 for (type
= 0; type
< ARRAY_SIZE(format
->f
.flags
); ++type
)
2716 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2717 format
->internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2718 if (value
== GL_FULL_SUPPORT
)
2720 TRACE("Format %s is supported as FBO color attachment, resource type %u.\n",
2721 debug_d3dformat(format
->f
.id
), type
);
2722 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2723 format
->rt_internal
= format
->internal
;
2724 regular_fmt_used
= TRUE
;
2726 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2727 format
->internal
, GL_FRAMEBUFFER_BLEND
, 1, &value
);
2728 if (value
== GL_FULL_SUPPORT
)
2730 TRACE("Format %s supports post-pixelshader blending, resource type %u.\n",
2731 debug_d3dformat(format
->f
.id
), type
);
2732 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2736 TRACE("Format %s doesn't support post-pixelshader blending, resource typed %u.\n",
2737 debug_d3dformat(format
->f
.id
), type
);
2738 format
->f
.flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2745 if (format
->f
.flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
2747 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
2748 " and no fallback specified, resource type %u.\n",
2749 debug_d3dformat(format
->f
.id
), type
);
2750 format
->f
.flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2753 TRACE("Format %s is not supported as FBO color attachment,"
2754 " resource type %u.\n", debug_d3dformat(format
->f
.id
), type
);
2755 format
->rt_internal
= format
->internal
;
2759 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2760 rt_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2761 if (value
== GL_FULL_SUPPORT
)
2763 TRACE("Format %s rtInternal format is supported as FBO color attachment,"
2764 " resource type %u.\n", debug_d3dformat(format
->f
.id
), type
);
2765 fallback_fmt_used
= TRUE
;
2769 WARN("Format %s rtInternal format is not supported as FBO color attachment,"
2770 " resource type %u.\n", debug_d3dformat(format
->f
.id
), type
);
2771 format
->f
.flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2776 if (format
->internal
!= format
->srgb_internal
)
2778 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2779 format
->srgb_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2780 if (value
== GL_FULL_SUPPORT
)
2782 TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n",
2783 debug_d3dformat(format
->f
.id
), type
);
2784 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2785 if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2786 format
->internal
= format
->srgb_internal
;
2790 WARN("Format %s's sRGB format is not FBO attachable, resource type %u.\n",
2791 debug_d3dformat(format
->f
.id
), type
);
2792 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_SRGB_WRITE
);
2795 else if (format
->f
.flags
[type
] & WINED3DFMT_FLAG_FBO_ATTACHABLE
)
2796 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2799 if (fallback_fmt_used
&& regular_fmt_used
)
2801 FIXME("Format %s needs different render target formats for different resource types.\n",
2802 debug_d3dformat(format
->f
.id
));
2803 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
2804 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2810 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2812 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2813 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2814 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2815 gl_info
->gl_ops
.gl
.p_glReadBuffer(GL_COLOR_ATTACHMENT0
);
2818 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
2820 struct wined3d_format_gl
*format
= get_format_gl_by_idx(adapter
, i
);
2822 if (!format
->internal
)
2825 if (format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_COMPRESSED
)
2827 TRACE("Skipping format %s because it's a compressed format.\n",
2828 debug_d3dformat(format
->f
.id
));
2832 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2834 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format
->f
.id
));
2835 check_fbo_compat(ctx
, format
);
2839 format
->rt_internal
= format
->internal
;
2843 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2844 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2847 static GLenum
lookup_gl_view_class(GLenum internal_format
)
2851 GLenum internal_format
;
2857 {GL_RGBA32F
, GL_VIEW_CLASS_128_BITS
},
2858 {GL_RGBA32UI
, GL_VIEW_CLASS_128_BITS
},
2859 {GL_RGBA32I
, GL_VIEW_CLASS_128_BITS
},
2861 {GL_RGB32F
, GL_VIEW_CLASS_96_BITS
},
2862 {GL_RGB32UI
, GL_VIEW_CLASS_96_BITS
},
2863 {GL_RGB32I
, GL_VIEW_CLASS_96_BITS
},
2865 {GL_RGBA16F
, GL_VIEW_CLASS_64_BITS
},
2866 {GL_RG32F
, GL_VIEW_CLASS_64_BITS
},
2867 {GL_RGBA16UI
, GL_VIEW_CLASS_64_BITS
},
2868 {GL_RG32UI
, GL_VIEW_CLASS_64_BITS
},
2869 {GL_RGBA16I
, GL_VIEW_CLASS_64_BITS
},
2870 {GL_RG32I
, GL_VIEW_CLASS_64_BITS
},
2871 {GL_RGBA16
, GL_VIEW_CLASS_64_BITS
},
2872 {GL_RGBA16_SNORM
, GL_VIEW_CLASS_64_BITS
},
2874 {GL_RGB16
, GL_VIEW_CLASS_48_BITS
},
2875 {GL_RGB16_SNORM
, GL_VIEW_CLASS_48_BITS
},
2876 {GL_RGB16F
, GL_VIEW_CLASS_48_BITS
},
2877 {GL_RGB16UI
, GL_VIEW_CLASS_48_BITS
},
2878 {GL_RGB16I
, GL_VIEW_CLASS_48_BITS
},
2880 {GL_RG16F
, GL_VIEW_CLASS_32_BITS
},
2881 {GL_R11F_G11F_B10F
, GL_VIEW_CLASS_32_BITS
},
2882 {GL_R32F
, GL_VIEW_CLASS_32_BITS
},
2883 {GL_RGB10_A2UI
, GL_VIEW_CLASS_32_BITS
},
2884 {GL_RGBA8UI
, GL_VIEW_CLASS_32_BITS
},
2885 {GL_RG16UI
, GL_VIEW_CLASS_32_BITS
},
2886 {GL_R32UI
, GL_VIEW_CLASS_32_BITS
},
2887 {GL_RGBA8I
, GL_VIEW_CLASS_32_BITS
},
2888 {GL_RG16I
, GL_VIEW_CLASS_32_BITS
},
2889 {GL_R32I
, GL_VIEW_CLASS_32_BITS
},
2890 {GL_RGB10_A2
, GL_VIEW_CLASS_32_BITS
},
2891 {GL_RGBA8
, GL_VIEW_CLASS_32_BITS
},
2892 {GL_RG16
, GL_VIEW_CLASS_32_BITS
},
2893 {GL_RGBA8_SNORM
, GL_VIEW_CLASS_32_BITS
},
2894 {GL_RG16_SNORM
, GL_VIEW_CLASS_32_BITS
},
2895 {GL_SRGB8_ALPHA8
, GL_VIEW_CLASS_32_BITS
},
2896 {GL_RGB9_E5
, GL_VIEW_CLASS_32_BITS
},
2898 {GL_RGB8
, GL_VIEW_CLASS_24_BITS
},
2899 {GL_RGB8_SNORM
, GL_VIEW_CLASS_24_BITS
},
2900 {GL_SRGB8
, GL_VIEW_CLASS_24_BITS
},
2901 {GL_RGB8UI
, GL_VIEW_CLASS_24_BITS
},
2902 {GL_RGB8I
, GL_VIEW_CLASS_24_BITS
},
2904 {GL_R16F
, GL_VIEW_CLASS_16_BITS
},
2905 {GL_RG8UI
, GL_VIEW_CLASS_16_BITS
},
2906 {GL_R16UI
, GL_VIEW_CLASS_16_BITS
},
2907 {GL_RG8I
, GL_VIEW_CLASS_16_BITS
},
2908 {GL_R16I
, GL_VIEW_CLASS_16_BITS
},
2909 {GL_RG8
, GL_VIEW_CLASS_16_BITS
},
2910 {GL_R16
, GL_VIEW_CLASS_16_BITS
},
2911 {GL_RG8_SNORM
, GL_VIEW_CLASS_16_BITS
},
2912 {GL_R16_SNORM
, GL_VIEW_CLASS_16_BITS
},
2914 {GL_R8UI
, GL_VIEW_CLASS_8_BITS
},
2915 {GL_R8I
, GL_VIEW_CLASS_8_BITS
},
2916 {GL_R8
, GL_VIEW_CLASS_8_BITS
},
2917 {GL_R8_SNORM
, GL_VIEW_CLASS_8_BITS
},
2920 {GL_COMPRESSED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
2921 {GL_COMPRESSED_SIGNED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
2923 {GL_COMPRESSED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
2924 {GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
2927 {GL_COMPRESSED_RGBA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
2928 {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
2930 {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
2931 {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
2934 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
2935 {GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
2937 {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
2938 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
2940 {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
2941 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
2943 {GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
2944 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
2949 for (i
= 0; i
< ARRAY_SIZE(view_classes
); ++i
)
2951 if (view_classes
[i
].internal_format
== internal_format
)
2952 return view_classes
[i
].view_class
;
2958 static void query_view_class(struct wined3d_format_gl
*format
)
2960 GLenum internal_view_class
, gamma_view_class
, rt_view_class
;
2962 internal_view_class
= lookup_gl_view_class(format
->internal
);
2963 gamma_view_class
= lookup_gl_view_class(format
->srgb_internal
);
2964 rt_view_class
= lookup_gl_view_class(format
->rt_internal
);
2966 if (internal_view_class
== gamma_view_class
|| gamma_view_class
== rt_view_class
)
2968 format
->view_class
= internal_view_class
;
2969 TRACE("Format %s is member of GL view class %#x.\n",
2970 debug_d3dformat(format
->f
.id
), format
->view_class
);
2974 format
->view_class
= GL_NONE
;
2978 static void query_internal_format(struct wined3d_adapter
*adapter
,
2979 struct wined3d_format_gl
*format
, const struct wined3d_format_texture_info
*texture_info
,
2980 struct wined3d_gl_info
*gl_info
, BOOL srgb_write_supported
, BOOL srgb_format
)
2982 GLint count
, multisample_types
[8];
2983 unsigned int i
, max_log2
;
2986 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2988 query_format_flag(gl_info
, format
, format
->internal
, GL_VERTEX_TEXTURE
,
2989 WINED3DFMT_FLAG_VTF
, "vertex texture usage");
2990 query_format_flag(gl_info
, format
, format
->internal
, GL_FILTER
,
2991 WINED3DFMT_FLAG_FILTERING
, "filtering");
2992 query_format_flag(gl_info
, format
, format
->internal
, GL_SHADER_IMAGE_STORE
,
2993 WINED3DFMT_FLAG_UNORDERED_ACCESS
, "unordered access");
2995 if (srgb_format
|| format
->srgb_internal
!= format
->internal
)
2997 query_format_flag(gl_info
, format
, format
->srgb_internal
, GL_SRGB_READ
,
2998 WINED3DFMT_FLAG_SRGB_READ
, "sRGB read");
3000 if (srgb_write_supported
)
3001 query_format_flag(gl_info
, format
, format
->srgb_internal
, GL_SRGB_WRITE
,
3002 WINED3DFMT_FLAG_SRGB_WRITE
, "sRGB write");
3004 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_SRGB_WRITE
);
3006 if (!(format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
]
3007 & (WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
)))
3008 format
->srgb_internal
= format
->internal
;
3009 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
3010 format
->internal
= format
->srgb_internal
;
3015 if (!gl_info
->limits
.samplers
[WINED3D_SHADER_TYPE_VERTEX
])
3016 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_VTF
);
3018 if (!(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
3019 format_set_flag(&format
->f
, WINED3DFMT_FLAG_FILTERING
);
3020 else if (format
->f
.id
!= WINED3DFMT_R32G32B32A32_FLOAT
&& format
->f
.id
!= WINED3DFMT_R32_FLOAT
)
3021 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_VTF
);
3023 if (srgb_format
|| format
->srgb_internal
!= format
->internal
)
3025 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
3026 if (!gl_info
->supported
[EXT_TEXTURE_SRGB
])
3028 format
->srgb_internal
= format
->internal
;
3029 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
3031 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
3033 format
->internal
= format
->srgb_internal
;
3037 if ((format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_SRGB_WRITE
) && !srgb_write_supported
)
3038 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_SRGB_WRITE
);
3041 if ((!gl_info
->supported
[ARB_DEPTH_TEXTURE
] || wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
3042 && (format
->f
.depth_size
|| format
->f
.stencil_size
))
3044 TRACE("Disabling texturing support for depth / stencil format %s.\n", debug_d3dformat(format
->f
.id
));
3045 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_1D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3046 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3047 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3048 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3049 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3052 query_view_class(format
);
3054 if (format
->internal
&& format
->f
.flags
[WINED3D_GL_RES_TYPE_RB
]
3055 & (WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH_STENCIL
))
3057 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY
])
3059 target
= gl_info
->supported
[ARB_TEXTURE_MULTISAMPLE
] ? GL_TEXTURE_2D_MULTISAMPLE
: GL_RENDERBUFFER
;
3061 GL_EXTCALL(glGetInternalformativ(target
, format
->internal
,
3062 GL_NUM_SAMPLE_COUNTS
, 1, &count
));
3063 if (count
> ARRAY_SIZE(multisample_types
))
3064 FIXME("Unexpectedly high number of multisample types %d.\n", count
);
3065 count
= min(count
, ARRAY_SIZE(multisample_types
));
3066 GL_EXTCALL(glGetInternalformativ(target
, format
->internal
,
3067 GL_SAMPLES
, count
, multisample_types
));
3068 checkGLcall("query sample counts");
3069 for (i
= 0; i
< count
; ++i
)
3071 if (multisample_types
[i
] > sizeof(format
->f
.multisample_types
) * CHAR_BIT
)
3073 format
->f
.multisample_types
|= 1u << (multisample_types
[i
] - 1);
3078 max_log2
= wined3d_log2i(min(gl_info
->limits
.samples
,
3079 sizeof(format
->f
.multisample_types
) * CHAR_BIT
));
3080 for (i
= 1; i
<= max_log2
; ++i
)
3081 format
->f
.multisample_types
|= 1u << ((1u << i
) - 1);
3086 static BOOL
init_format_texture_info(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
3088 struct wined3d_format_gl
*format
, *srgb_format
;
3089 struct fragment_caps fragment_caps
;
3090 struct shader_caps shader_caps
;
3094 adapter
->fragment_pipe
->get_caps(adapter
, &fragment_caps
);
3095 adapter
->shader_backend
->shader_get_caps(adapter
, &shader_caps
);
3096 srgb_write
= (fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_SRGB_WRITE
)
3097 && (shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_SRGB_WRITE
);
3099 for (i
= 0; i
< ARRAY_SIZE(format_texture_info
); ++i
)
3101 if (!(format
= get_format_gl_internal(adapter
, format_texture_info
[i
].id
)))
3104 if (!gl_info
->supported
[format_texture_info
[i
].extension
])
3107 /* ARB_texture_rg defines floating point formats, but only if
3108 * ARB_texture_float is also supported. */
3109 if (!gl_info
->supported
[ARB_TEXTURE_FLOAT
]
3110 && (format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_FLOAT
))
3113 /* ARB_texture_rg defines integer formats if EXT_texture_integer is also supported. */
3114 if (!gl_info
->supported
[EXT_TEXTURE_INTEGER
]
3115 && (format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_INTEGER
))
3118 format
->internal
= format_texture_info
[i
].gl_internal
;
3119 format
->srgb_internal
= format_texture_info
[i
].gl_srgb_internal
;
3120 format
->rt_internal
= format_texture_info
[i
].gl_rt_internal
;
3121 format
->format
= format_texture_info
[i
].gl_format
;
3122 format
->type
= format_texture_info
[i
].gl_type
;
3123 format
->f
.color_fixup
= COLOR_FIXUP_IDENTITY
;
3124 format
->f
.height_scale
.numerator
= 1;
3125 format
->f
.height_scale
.denominator
= 1;
3127 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_1D
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3128 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3129 format
->f
.flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3131 /* GL_ARB_depth_texture does not support 3D textures. It also says "cube textures are
3132 * problematic", but doesn't explicitly mandate that an error is generated. */
3133 if (gl_info
->supported
[EXT_TEXTURE3D
] && !(format_texture_info
[i
].flags
& WINED3DFMT_FLAG_DEPTH_STENCIL
))
3134 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3136 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
3137 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3139 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
3140 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3142 format
->f
.flags
[WINED3D_GL_RES_TYPE_RB
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3143 format
->f
.flags
[WINED3D_GL_RES_TYPE_RB
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3145 if (format
->srgb_internal
!= format
->internal
3146 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
3148 format
->srgb_internal
= format
->internal
;
3149 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
3152 if (!gl_info
->supported
[ARB_SHADOW
] && (format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_SHADOW
))
3153 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3155 query_internal_format(adapter
, format
, &format_texture_info
[i
], gl_info
, srgb_write
, FALSE
);
3157 /* Texture conversion stuff */
3158 format
->f
.conv_byte_count
= format_texture_info
[i
].conv_byte_count
;
3159 format
->f
.upload
= format_texture_info
[i
].upload
;
3160 format
->f
.download
= format_texture_info
[i
].download
;
3163 for (j
= 0; j
< ARRAY_SIZE(format_srgb_info
); ++j
)
3165 if (format_srgb_info
[j
].base_format_id
== format
->f
.id
)
3167 if (!(srgb_format
= get_format_gl_internal(adapter
, format_srgb_info
[j
].srgb_format_id
)))
3175 copy_format(adapter
, &srgb_format
->f
, &format
->f
);
3177 if (gl_info
->supported
[EXT_TEXTURE_SRGB
]
3178 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
3180 srgb_format
->internal
= format_texture_info
[i
].gl_srgb_internal
;
3181 srgb_format
->srgb_internal
= format_texture_info
[i
].gl_srgb_internal
;
3182 format_set_flag(&srgb_format
->f
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
3183 query_internal_format(adapter
, srgb_format
, &format_texture_info
[i
], gl_info
, srgb_write
, TRUE
);
3190 static BOOL
compare_uint(unsigned int x
, unsigned int y
, unsigned int max_diff
)
3192 unsigned int diff
= x
> y
? x
- y
: y
- x
;
3194 return diff
<= max_diff
;
3197 static BOOL
compare_colour(DWORD c1
, DWORD c2
, BYTE max_diff
)
3199 return compare_uint(c1
& 0xff, c2
& 0xff, max_diff
)
3200 && compare_uint((c1
>> 8) & 0xff, (c2
>> 8) & 0xff, max_diff
)
3201 && compare_uint((c1
>> 16) & 0xff, (c2
>> 16) & 0xff, max_diff
)
3202 && compare_uint((c1
>> 24) & 0xff, (c2
>> 24) & 0xff, max_diff
);
3205 /* A context is provided by the caller */
3206 static BOOL
check_filter(const struct wined3d_gl_info
*gl_info
, GLenum internal
)
3208 static const DWORD data
[] = {0x00000000, 0xffffffff};
3209 GLuint tex
, fbo
, buffer
;
3210 DWORD readback
[16 * 1];
3213 /* Render a filtered texture and see what happens. This is intended to detect the lack of
3214 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
3215 * falling back to software. If this changes in the future this code will get fooled and
3216 * apps might hit the software path due to incorrectly advertised caps.
3218 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
3219 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
3220 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
3223 while (gl_info
->gl_ops
.gl
.p_glGetError());
3225 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &buffer
);
3226 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
3227 memset(readback
, 0x7e, sizeof(readback
));
3228 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 16, 1, 0,
3229 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, readback
);
3230 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
3231 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
3232 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
3233 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
3234 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
3236 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &tex
);
3237 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, tex
);
3238 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, internal
, 2, 1, 0,
3239 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, data
);
3240 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
3241 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
3242 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
3243 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
3244 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
3245 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
3247 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3248 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3249 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, buffer
, 0);
3250 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
3252 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
3253 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
3254 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
3255 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
3256 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
3257 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
3259 gl_info
->gl_ops
.gl
.p_glClearColor(0, 1, 0, 0);
3260 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3262 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
3263 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 0.0);
3264 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, -1.0f
);
3265 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 0.0);
3266 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, -1.0f
);
3267 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 1.0);
3268 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, 1.0f
);
3269 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 1.0);
3270 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, 1.0f
);
3271 gl_info
->gl_ops
.gl
.p_glEnd();
3273 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
3274 memset(readback
, 0x7f, sizeof(readback
));
3275 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3276 if (compare_colour(readback
[6], 0xffffffff, 5) || compare_colour(readback
[6], 0x00000000, 5)
3277 || compare_colour(readback
[9], 0xffffffff, 5) || compare_colour(readback
[9], 0x00000000, 5))
3279 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
3280 readback
[6], readback
[9]);
3285 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
3286 readback
[6], readback
[9]);
3290 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3291 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3292 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &tex
);
3293 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &buffer
);
3294 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
3296 if (gl_info
->gl_ops
.gl
.p_glGetError())
3298 FIXME("Error during filtering test for format %x, returning no filtering\n", internal
);
3305 static void init_format_filter_info(struct wined3d_adapter
*adapter
,
3306 struct wined3d_gl_info
*gl_info
)
3308 enum wined3d_pci_vendor vendor
= adapter
->driver_info
.vendor
;
3309 struct wined3d_format_gl
*format
;
3311 static const enum wined3d_format_id fmts16
[] =
3313 WINED3DFMT_R16_FLOAT
,
3314 WINED3DFMT_R16G16_FLOAT
,
3315 WINED3DFMT_R16G16B16A16_FLOAT
,
3319 /* This was already handled by init_format_texture_info(). */
3320 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
3323 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
3324 || !gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3326 WARN("No FBO support, or no FBO ORM, guessing filter info from GL caps\n");
3327 if (vendor
== HW_VENDOR_NVIDIA
&& gl_info
->supported
[ARB_TEXTURE_FLOAT
])
3329 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
3332 else if (gl_info
->limits
.glsl_varyings
> 44)
3334 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
3339 TRACE("Assuming no float16 blending\n");
3345 for (i
= 0; i
< ARRAY_SIZE(fmts16
); ++i
)
3347 format
= get_format_gl_internal(adapter
, fmts16
[i
]);
3348 format_set_flag(&format
->f
, WINED3DFMT_FLAG_FILTERING
);
3354 for (i
= 0; i
< ARRAY_SIZE(fmts16
); ++i
)
3356 format
= get_format_gl_internal(adapter
, fmts16
[i
]);
3357 if (!format
->internal
)
3358 continue; /* Not supported by GL */
3360 filtered
= check_filter(gl_info
, format
->internal
);
3363 TRACE("Format %s supports filtering.\n", debug_d3dformat(format
->f
.id
));
3364 format_set_flag(&format
->f
, WINED3DFMT_FLAG_FILTERING
);
3368 TRACE("Format %s does not support filtering.\n", debug_d3dformat(format
->f
.id
));
3373 static enum fixup_channel_source
fixup_source_from_char(char c
)
3379 return CHANNEL_SOURCE_ZERO
;
3381 return CHANNEL_SOURCE_ONE
;
3384 return CHANNEL_SOURCE_X
;
3387 return CHANNEL_SOURCE_Y
;
3390 return CHANNEL_SOURCE_Z
;
3393 return CHANNEL_SOURCE_W
;
3397 static unsigned int fixup_sign_from_char(char c
)
3399 if (c
== 'x' || c
== 'y' || c
== 'z' || c
== 'w')
3404 static struct color_fixup_desc
create_color_fixup_desc_from_string(const char *s
)
3406 struct color_fixup_desc fixup
;
3410 ERR("Invalid fixup string %s.\n", wine_dbgstr_a(s
));
3411 return COLOR_FIXUP_IDENTITY
;
3414 fixup
.x_sign_fixup
= fixup_sign_from_char(s
[0]);
3415 fixup
.x_source
= fixup_source_from_char(s
[0]);
3416 fixup
.y_sign_fixup
= fixup_sign_from_char(s
[1]);
3417 fixup
.y_source
= fixup_source_from_char(s
[1]);
3418 fixup
.z_sign_fixup
= fixup_sign_from_char(s
[2]);
3419 fixup
.z_source
= fixup_source_from_char(s
[2]);
3420 fixup
.w_sign_fixup
= fixup_sign_from_char(s
[3]);
3421 fixup
.w_source
= fixup_source_from_char(s
[3]);
3426 static void apply_format_fixups(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
3428 const struct wined3d_d3d_info
*d3d_info
= &adapter
->d3d_info
;
3429 struct wined3d_format_gl
*format
;
3430 BOOL use_legacy_fixups
;
3435 enum wined3d_format_id id
;
3438 enum wined3d_gl_extension extension
;
3442 {WINED3DFMT_R16_FLOAT
, "X11W", TRUE
, WINED3D_GL_EXT_NONE
},
3443 {WINED3DFMT_R32_FLOAT
, "X11W", TRUE
, WINED3D_GL_EXT_NONE
},
3444 {WINED3DFMT_R16G16_UNORM
, "XY1W", TRUE
, WINED3D_GL_EXT_NONE
},
3445 {WINED3DFMT_R16G16_FLOAT
, "XY1W", TRUE
, WINED3D_GL_EXT_NONE
},
3446 {WINED3DFMT_R32G32_FLOAT
, "XY1W", TRUE
, WINED3D_GL_EXT_NONE
},
3448 {WINED3DFMT_R8G8_SNORM
, "xy11", FALSE
, WINED3D_GL_EXT_NONE
},
3449 {WINED3DFMT_R8G8_SNORM
, "XY11", TRUE
, NV_TEXTURE_SHADER
},
3450 {WINED3DFMT_R8G8_SNORM
, "XY11", TRUE
, EXT_TEXTURE_SNORM
},
3452 {WINED3DFMT_R16G16_SNORM
, "xy11", FALSE
, WINED3D_GL_EXT_NONE
},
3453 {WINED3DFMT_R16G16_SNORM
, "XY11", TRUE
, NV_TEXTURE_SHADER
},
3454 {WINED3DFMT_R16G16_SNORM
, "XY11", TRUE
, EXT_TEXTURE_SNORM
},
3456 {WINED3DFMT_R8G8B8A8_SNORM
, "xyzw", FALSE
, WINED3D_GL_EXT_NONE
},
3457 {WINED3DFMT_R8G8B8A8_SNORM
, "XYZW", FALSE
, NV_TEXTURE_SHADER
},
3458 {WINED3DFMT_R8G8B8A8_SNORM
, "XYZW", FALSE
, EXT_TEXTURE_SNORM
},
3460 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, "xzY1", FALSE
, WINED3D_GL_EXT_NONE
},
3461 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, "XYZW", FALSE
, NV_TEXTURE_SHADER
},
3462 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, "XYZW", FALSE
, EXT_TEXTURE_SNORM
},
3464 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, "xyZW", FALSE
, WINED3D_GL_EXT_NONE
},
3465 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, "XYZW", FALSE
, NV_TEXTURE_SHADER
},
3467 {WINED3DFMT_ATI1N
, "XXXX", FALSE
, EXT_TEXTURE_COMPRESSION_RGTC
},
3468 {WINED3DFMT_ATI1N
, "XXXX", FALSE
, ARB_TEXTURE_COMPRESSION_RGTC
},
3470 {WINED3DFMT_ATI2N
, "XW11", FALSE
, ATI_TEXTURE_COMPRESSION_3DC
},
3471 {WINED3DFMT_ATI2N
, "YX11", FALSE
, EXT_TEXTURE_COMPRESSION_RGTC
},
3472 {WINED3DFMT_ATI2N
, "YX11", FALSE
, ARB_TEXTURE_COMPRESSION_RGTC
},
3474 {WINED3DFMT_A8_UNORM
, "000X", FALSE
, WINED3D_GL_EXT_NONE
},
3475 {WINED3DFMT_A8_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3477 {WINED3DFMT_L8A8_UNORM
, "XXXY", FALSE
, WINED3D_GL_EXT_NONE
},
3478 {WINED3DFMT_L8A8_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3480 {WINED3DFMT_L4A4_UNORM
, "XXXY", FALSE
, WINED3D_GL_EXT_NONE
},
3481 {WINED3DFMT_L4A4_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3483 {WINED3DFMT_L16_UNORM
, "XXX1", FALSE
, WINED3D_GL_EXT_NONE
},
3484 {WINED3DFMT_L16_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3486 {WINED3DFMT_INTZ
, "XXXX", FALSE
, WINED3D_GL_EXT_NONE
},
3487 {WINED3DFMT_INTZ
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3489 {WINED3DFMT_L8_UNORM
, "XXX1", FALSE
, ARB_TEXTURE_RG
},
3492 use_legacy_fixups
= d3d_info
->wined3d_creation_flags
& WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR
;
3493 for (i
= 0; i
< ARRAY_SIZE(fixups
); ++i
)
3495 if (fixups
[i
].legacy
&& !use_legacy_fixups
)
3498 if (!gl_info
->supported
[fixups
[i
].extension
])
3501 format
= get_format_gl_internal(adapter
, fixups
[i
].id
);
3502 format
->f
.color_fixup
= create_color_fixup_desc_from_string(fixups
[i
].fixup
);
3505 if (!gl_info
->supported
[APPLE_YCBCR_422
] && !gl_info
->supported
[APPLE_RGB_422
]
3506 && (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3507 || (gl_info
->supported
[ARB_FRAGMENT_SHADER
] && gl_info
->supported
[ARB_VERTEX_SHADER
])))
3509 format
= get_format_gl_internal(adapter
, WINED3DFMT_YUY2
);
3510 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUY2
);
3512 format
= get_format_gl_internal(adapter
, WINED3DFMT_UYVY
);
3513 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_UYVY
);
3515 else if (!gl_info
->supported
[APPLE_YCBCR_422
] && gl_info
->supported
[APPLE_RGB_422
])
3517 format
= get_format_gl_internal(adapter
, WINED3DFMT_YUY2
);
3518 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUV
);
3520 format
= get_format_gl_internal(adapter
, WINED3DFMT_UYVY
);
3521 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUV
);
3523 else if (!gl_info
->supported
[APPLE_YCBCR_422
] && (!gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3524 && (!gl_info
->supported
[ARB_FRAGMENT_SHADER
] || !gl_info
->supported
[ARB_VERTEX_SHADER
])))
3526 format
= get_format_gl_internal(adapter
, WINED3DFMT_YUY2
);
3527 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_BLIT
);
3528 format
->internal
= 0;
3530 format
= get_format_gl_internal(adapter
, WINED3DFMT_UYVY
);
3531 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_BLIT
);
3532 format
->internal
= 0;
3535 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3536 || (gl_info
->supported
[ARB_FRAGMENT_SHADER
] && gl_info
->supported
[ARB_VERTEX_SHADER
]))
3538 format
= get_format_gl_internal(adapter
, WINED3DFMT_YV12
);
3539 format_set_flag(&format
->f
, WINED3DFMT_FLAG_HEIGHT_SCALE
);
3540 format
->f
.height_scale
.numerator
= 3;
3541 format
->f
.height_scale
.denominator
= 2;
3542 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YV12
);
3544 format
= get_format_gl_internal(adapter
, WINED3DFMT_NV12
);
3545 format_set_flag(&format
->f
, WINED3DFMT_FLAG_HEIGHT_SCALE
);
3546 format
->f
.height_scale
.numerator
= 3;
3547 format
->f
.height_scale
.denominator
= 2;
3548 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_NV12
);
3552 format
= get_format_gl_internal(adapter
, WINED3DFMT_YV12
);
3553 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_BLIT
);
3554 format
->internal
= 0;
3556 format
= get_format_gl_internal(adapter
, WINED3DFMT_NV12
);
3557 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_BLIT
);
3558 format
->internal
= 0;
3561 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
] || gl_info
->supported
[ARB_FRAGMENT_SHADER
])
3563 format
= get_format_gl_internal(adapter
, WINED3DFMT_P8_UINT
);
3564 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_P8
);
3567 if (!gl_info
->supported
[ARB_HALF_FLOAT_PIXEL
])
3569 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16_FLOAT
);
3570 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3572 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16G16_FLOAT
);
3573 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3575 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16G16B16A16_FLOAT
);
3576 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3579 if (gl_info
->quirks
& WINED3D_QUIRK_BROKEN_RGBA16
)
3581 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16G16B16A16_UNORM
);
3582 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3585 /* ATI instancing hack: Although ATI cards do not support Shader Model
3586 * 3.0, they support instancing. To query if the card supports instancing
3587 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
3588 * is used. Should an application check for this, provide a proper return
3589 * value. We can do instancing with all shader versions, but we need
3592 * Additionally applications have to set the D3DRS_POINTSIZE render state
3593 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
3594 * doesn't need that and just ignores it.
3596 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
3597 /* FIXME: This should just check the shader backend caps. */
3598 if (gl_info
->supported
[ARB_VERTEX_PROGRAM
] || gl_info
->supported
[ARB_VERTEX_SHADER
])
3600 format
= get_format_gl_internal(adapter
, WINED3DFMT_INST
);
3601 format_set_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3604 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
3605 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
3606 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
3607 * MAKEFOURCC('N','V','D','B') and then controlled by setting
3608 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
3610 if (gl_info
->supported
[EXT_DEPTH_BOUNDS_TEST
])
3612 format
= get_format_gl_internal(adapter
, WINED3DFMT_NVDB
);
3613 format_set_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3616 if (gl_info
->supported
[ARB_MULTISAMPLE
])
3618 format
= get_format_gl_internal(adapter
, WINED3DFMT_ATOC
);
3619 format_set_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3622 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
3623 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
3624 * RENDERTARGET usage. */
3625 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
])
3627 format
= get_format_gl_internal(adapter
, WINED3DFMT_RESZ
);
3628 format_set_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
);
3631 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
3633 format
= get_format_gl_by_idx(adapter
, i
);
3635 if (!(format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_TEXTURE
))
3638 if (is_identity_fixup(format
->f
.color_fixup
))
3641 TRACE("Checking support for fixup:\n");
3642 dump_color_fixup_desc(format
->f
.color_fixup
);
3643 if (!adapter
->shader_backend
->shader_color_fixup_supported(format
->f
.color_fixup
)
3644 || !adapter
->fragment_pipe
->color_fixup_supported(format
->f
.color_fixup
))
3646 TRACE("[FAILED]\n");
3647 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3655 /* These formats are not supported for 3D textures. See also
3656 * WINED3DFMT_FLAG_DECOMPRESS. */
3657 format
= get_format_gl_internal(adapter
, WINED3DFMT_ATI1N
);
3658 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3659 format
= get_format_gl_internal(adapter
, WINED3DFMT_ATI2N
);
3660 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3661 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC4_UNORM
);
3662 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3663 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC4_SNORM
);
3664 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3665 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC5_UNORM
);
3666 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3667 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC5_SNORM
);
3668 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3671 static BOOL
init_format_vertex_info(const struct wined3d_adapter
*adapter
,
3672 struct wined3d_gl_info
*gl_info
)
3674 struct wined3d_format_gl
*format
;
3677 for (i
= 0; i
< ARRAY_SIZE(format_vertex_info
); ++i
)
3679 if (!(format
= get_format_gl_internal(adapter
, format_vertex_info
[i
].id
)))
3682 if (!gl_info
->supported
[format_vertex_info
[i
].extension
])
3685 format
->f
.emit_idx
= format_vertex_info
[i
].emit_idx
;
3686 format
->vtx_type
= format_vertex_info
[i
].gl_vtx_type
;
3687 format
->vtx_format
= format
->f
.component_count
;
3688 format
->f
.flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= WINED3DFMT_FLAG_VERTEX_ATTRIBUTE
;
3691 if (gl_info
->supported
[ARB_VERTEX_ARRAY_BGRA
])
3693 format
= get_format_gl_internal(adapter
, WINED3DFMT_B8G8R8A8_UNORM
);
3694 format
->vtx_format
= GL_BGRA
;
3700 static BOOL
init_typeless_formats(const struct wined3d_adapter
*adapter
)
3702 unsigned int flags
[WINED3D_GL_RES_TYPE_COUNT
];
3705 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
3707 struct wined3d_format
*format
, *typeless_format
;
3709 if (!(format
= get_format_internal(adapter
, typed_formats
[i
].id
)))
3711 if (!(typeless_format
= get_format_internal(adapter
, typed_formats
[i
].typeless_id
)))
3714 memcpy(flags
, typeless_format
->flags
, sizeof(flags
));
3715 copy_format(adapter
, typeless_format
, format
);
3716 for (j
= 0; j
< ARRAY_SIZE(typeless_format
->flags
); ++j
)
3717 typeless_format
->flags
[j
] |= flags
[j
];
3720 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
3722 struct wined3d_format
*typeless_format
, *typeless_ds_format
, *ds_format
;
3723 struct wined3d_format
*depth_view_format
, *stencil_view_format
;
3724 enum wined3d_format_id format_id
;
3726 if (!(typeless_format
= get_format_internal(adapter
, typeless_depth_stencil_formats
[i
].typeless_id
)))
3728 if (!(ds_format
= get_format_internal(adapter
, typeless_depth_stencil_formats
[i
].depth_stencil_id
)))
3731 typeless_ds_format
= get_format_by_idx(adapter
, WINED3D_FORMAT_COUNT
+ i
);
3732 typeless_ds_format
->id
= typeless_depth_stencil_formats
[i
].typeless_id
;
3733 copy_format(adapter
, typeless_ds_format
, ds_format
);
3734 for (j
= 0; j
< ARRAY_SIZE(typeless_ds_format
->flags
); ++j
)
3736 typeless_ds_format
->flags
[j
] = typeless_format
->flags
[j
];
3737 typeless_format
->flags
[j
] &= ~WINED3DFMT_FLAG_DEPTH_STENCIL
;
3740 if ((format_id
= typeless_depth_stencil_formats
[i
].depth_view_id
)
3741 && typeless_depth_stencil_formats
[i
].separate_depth_view_format
)
3743 if (!(depth_view_format
= get_format_internal(adapter
, format_id
)))
3745 copy_format(adapter
, depth_view_format
, ds_format
);
3746 depth_view_format
->red_size
= depth_view_format
->depth_size
;
3747 depth_view_format
->depth_size
= 0;
3748 depth_view_format
->stencil_size
= 0;
3750 if ((format_id
= typeless_depth_stencil_formats
[i
].stencil_view_id
))
3752 if (!(stencil_view_format
= get_format_internal(adapter
, format_id
)))
3754 copy_format(adapter
, stencil_view_format
, ds_format
);
3755 stencil_view_format
->green_size
= stencil_view_format
->stencil_size
;
3756 stencil_view_format
->depth_size
= 0;
3757 stencil_view_format
->stencil_size
= 0;
3764 static void init_format_gen_mipmap_info(const struct wined3d_adapter
*adapter
,
3765 struct wined3d_gl_info
*gl_info
)
3769 if (!gl_info
->fbo_ops
.glGenerateMipmap
)
3772 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
3774 struct wined3d_format
*format
= get_format_by_idx(adapter
, i
);
3776 for (j
= 0; j
< ARRAY_SIZE(format
->flags
); ++j
)
3777 if (!(~format
->flags
[j
] & (WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FILTERING
)))
3778 format
->flags
[j
] |= WINED3DFMT_FLAG_GEN_MIPMAP
;
3782 BOOL
wined3d_caps_gl_ctx_test_viewport_subpixel_bits(struct wined3d_caps_gl_ctx
*ctx
)
3784 static const struct wined3d_color red
= {1.0f
, 0.0f
, 0.0f
, 1.0f
};
3785 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3786 static const float offset
= -63.0f
/ 128.0f
;
3787 GLuint texture
, fbo
;
3791 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &texture
);
3792 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3793 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3794 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, ARRAY_SIZE(readback
), 1, 0,
3795 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, NULL
);
3796 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3797 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3798 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
3799 GL_TEXTURE_2D
, texture
, 0);
3800 checkGLcall("create resources");
3802 gl_info
->gl_ops
.gl
.p_glClearColor(1.0f
, 1.0f
, 1.0f
, 1.0f
);
3803 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3804 GL_EXTCALL(glViewportIndexedf(0, offset
, offset
, 4.0f
, 1.0f
));
3805 draw_test_quad(ctx
, NULL
, &red
);
3806 checkGLcall("draw");
3808 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3809 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0,
3810 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3811 checkGLcall("readback");
3813 TRACE("Readback colors are 0x%08x, 0x%08x, 0x%08x, 0x%08x.\n",
3814 readback
[0], readback
[1], readback
[2], readback
[3]);
3816 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &texture
);
3817 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3818 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3819 checkGLcall("delete resources");
3821 for (i
= 0; i
< ARRAY_SIZE(readback
); ++i
)
3823 if (readback
[i
] != 0xffff0000)
3829 static float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx
*ctx
, GLenum format
)
3831 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3832 static const struct wined3d_color blue
= {0.0f
, 0.0f
, 1.0f
, 1.0f
};
3833 GLuint fbo
, color
, depth
;
3834 unsigned int low
= 0, high
= 32, cur
;
3835 DWORD readback
[256];
3836 static const struct wined3d_vec3 geometry
[] =
3838 {-1.0f
, -1.0f
, -1.0f
},
3839 { 1.0f
, -1.0f
, 0.0f
},
3840 {-1.0f
, 1.0f
, -1.0f
},
3841 { 1.0f
, 1.0f
, 0.0f
},
3844 /* Most drivers want 2^23 for fixed point depth buffers, including r300g, r600g,
3845 * Nvidia. Use this as a fallback if the detection fails. */
3846 unsigned int fallback
= 23;
3848 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
3850 FIXME("No FBOs, assuming polyoffset scale of 2^%u.\n", fallback
);
3851 return (float)(1u << fallback
);
3854 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &color
);
3855 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
3856 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3857 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);
3859 gl_info
->fbo_ops
.glGenRenderbuffers(1, &depth
);
3860 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, depth
);
3861 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, format
, 256, 1);
3863 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3864 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3865 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, color
, 0);
3866 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, depth
);
3867 checkGLcall("Setup framebuffer");
3869 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.5f
, 0.0f
);
3870 gl_info
->gl_ops
.gl
.p_glClearDepth(0.5f
);
3871 gl_info
->gl_ops
.gl
.p_glEnable(GL_DEPTH_TEST
);
3872 gl_info
->gl_ops
.gl
.p_glEnable(GL_POLYGON_OFFSET_FILL
);
3873 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 256, 1);
3874 checkGLcall("Misc parameters");
3878 if (high
- low
<= 1)
3880 ERR("PolygonOffset scale factor detection failed, using fallback value 2^%u.\n", fallback
);
3884 cur
= (low
+ high
) / 2;
3886 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
3887 /* The post viewport transform Z of the geometry runs from 0.0 to 0.5. We want to push it another
3888 * 0.25 so that the Z buffer content (0.5) cuts the quad off at half the screen. */
3889 gl_info
->gl_ops
.gl
.p_glPolygonOffset(0.0f
, (float)(1u << cur
) * 0.25f
);
3890 draw_test_quad(ctx
, geometry
, &blue
);
3891 checkGLcall("Test draw");
3893 /* Rebinding texture to workaround a fglrx bug. */
3894 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
3895 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3896 checkGLcall("readback");
3898 TRACE("low %02u, high %02u, cur %2u, 0=0x%08x, 125=0x%08x, 131=0x%08x, 255=0x%08x\n",
3899 low
, high
, cur
, readback
[0], readback
[125], readback
[131], readback
[255]);
3901 if ((readback
[125] & 0xff) < 0xa0)
3903 else if ((readback
[131] & 0xff) > 0xa0)
3907 TRACE("Found scale factor 2^%u for format %x.\n", cur
, format
);
3912 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &color
);
3913 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &depth
);
3914 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3915 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3916 checkGLcall("Delete framebuffer");
3918 gl_info
->gl_ops
.gl
.p_glDisable(GL_DEPTH_TEST
);
3919 gl_info
->gl_ops
.gl
.p_glDisable(GL_POLYGON_OFFSET_FILL
);
3920 return (float)(1u << cur
);
3923 static void init_format_depth_bias_scale(struct wined3d_adapter
*adapter
,
3924 struct wined3d_caps_gl_ctx
*ctx
)
3926 const struct wined3d_d3d_info
*d3d_info
= &adapter
->d3d_info
;
3929 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
3931 struct wined3d_format_gl
*format
= get_format_gl_by_idx(adapter
, i
);
3933 if (format
->f
.depth_size
&& (format
->f
.flags
[WINED3D_GL_RES_TYPE_RB
] & WINED3DFMT_FLAG_DEPTH_STENCIL
))
3935 TRACE("Testing depth bias scale for format %s.\n", debug_d3dformat(format
->f
.id
));
3936 format
->f
.depth_bias_scale
= wined3d_adapter_find_polyoffset_scale(ctx
, format
->internal
);
3938 if (!(d3d_info
->wined3d_creation_flags
& WINED3D_NORMALIZED_DEPTH_BIAS
))
3940 /* The single-precision binary floating-point format has
3941 * a significand precision of 24 bits.
3943 if (format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_FLOAT
)
3944 format
->f
.depth_bias_scale
/= 1u << 24;
3946 format
->f
.depth_bias_scale
/= 1u << format
->f
.depth_size
;
3952 static BOOL
wined3d_adapter_init_format_info(struct wined3d_adapter
*adapter
, size_t format_size
)
3954 unsigned int count
= WINED3D_FORMAT_COUNT
+ ARRAY_SIZE(typeless_depth_stencil_formats
);
3956 if (!(adapter
->formats
= heap_calloc(count
, format_size
)))
3958 ERR("Failed to allocate memory.\n");
3961 adapter
->format_size
= format_size
;
3963 if (!init_format_base_info(adapter
))
3965 if (!init_format_block_info(adapter
))
3967 if (!init_format_decompress_info(adapter
))
3969 if (!init_srgb_formats(adapter
))
3975 heap_free(adapter
->formats
);
3976 adapter
->formats
= NULL
;
3980 BOOL
wined3d_adapter_no3d_init_format_info(struct wined3d_adapter
*adapter
)
3982 struct wined3d_format
*format
;
3985 static const enum wined3d_format_id blit_formats
[] =
3987 WINED3DFMT_B8G8R8A8_UNORM
,
3988 WINED3DFMT_B8G8R8X8_UNORM
,
3989 WINED3DFMT_B5G6R5_UNORM
,
3990 WINED3DFMT_B5G5R5X1_UNORM
,
3991 WINED3DFMT_B5G5R5A1_UNORM
,
3992 WINED3DFMT_B4G4R4A4_UNORM
,
3993 WINED3DFMT_B2G3R3_UNORM
,
3994 WINED3DFMT_A8_UNORM
,
3995 WINED3DFMT_B2G3R3A8_UNORM
,
3996 WINED3DFMT_B4G4R4X4_UNORM
,
3997 WINED3DFMT_R10G10B10A2_UNORM
,
3998 WINED3DFMT_R8G8B8A8_UNORM
,
3999 WINED3DFMT_R8G8B8X8_UNORM
,
4000 WINED3DFMT_R16G16_UNORM
,
4001 WINED3DFMT_B10G10R10A2_UNORM
,
4002 WINED3DFMT_R16G16B16A16_UNORM
,
4006 if (!wined3d_adapter_init_format_info(adapter
, sizeof(struct wined3d_format
)))
4009 for (i
= 0; i
< ARRAY_SIZE(blit_formats
); ++i
)
4011 if (!(format
= get_format_internal(adapter
, blit_formats
[i
])))
4014 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] |= WINED3DFMT_FLAG_BLIT
;
4015 format
->flags
[WINED3D_GL_RES_TYPE_RB
] |= WINED3DFMT_FLAG_BLIT
;
4021 /* Context activation is done by the caller. */
4022 BOOL
wined3d_adapter_gl_init_format_info(struct wined3d_adapter
*adapter
, struct wined3d_caps_gl_ctx
*ctx
)
4024 struct wined3d_gl_info
*gl_info
= &adapter
->gl_info
;
4026 if (!wined3d_adapter_init_format_info(adapter
, sizeof(struct wined3d_format_gl
)))
4029 if (!init_format_texture_info(adapter
, gl_info
)) goto fail
;
4030 if (!init_format_vertex_info(adapter
, gl_info
)) goto fail
;
4032 apply_format_fixups(adapter
, gl_info
);
4033 init_format_fbo_compat_info(adapter
, ctx
);
4034 init_format_filter_info(adapter
, gl_info
);
4035 init_format_gen_mipmap_info(adapter
, gl_info
);
4036 init_format_depth_bias_scale(adapter
, ctx
);
4038 if (!init_typeless_formats(adapter
)) goto fail
;
4043 heap_free(adapter
->formats
);
4044 adapter
->formats
= NULL
;
4048 static void init_vulkan_format_info(struct wined3d_format_vk
*format
,
4049 const struct wined3d_vk_info
*vk_info
, VkPhysicalDevice vk_physical_device
)
4053 enum wined3d_format_id id
;
4059 {WINED3DFMT_R32G32B32A32_FLOAT
, VK_FORMAT_R32G32B32A32_SFLOAT
, },
4060 {WINED3DFMT_R32G32B32A32_UINT
, VK_FORMAT_R32G32B32A32_UINT
, },
4061 {WINED3DFMT_R32G32B32A32_SINT
, VK_FORMAT_R32G32B32A32_SINT
, },
4062 {WINED3DFMT_R32G32B32_FLOAT
, VK_FORMAT_R32G32B32_SFLOAT
, },
4063 {WINED3DFMT_R32G32B32_UINT
, VK_FORMAT_R32G32B32_UINT
, },
4064 {WINED3DFMT_R32G32B32_SINT
, VK_FORMAT_R32G32B32_SINT
, },
4065 {WINED3DFMT_R16G16B16A16_FLOAT
, VK_FORMAT_R16G16B16A16_SFLOAT
, },
4066 {WINED3DFMT_R16G16B16A16_UNORM
, VK_FORMAT_R16G16B16A16_UNORM
, },
4067 {WINED3DFMT_R16G16B16A16_UINT
, VK_FORMAT_R16G16B16A16_UINT
, },
4068 {WINED3DFMT_R16G16B16A16_SNORM
, VK_FORMAT_R16G16B16A16_SNORM
, },
4069 {WINED3DFMT_R16G16B16A16_SINT
, VK_FORMAT_R16G16B16A16_SINT
, },
4070 {WINED3DFMT_R32G32_FLOAT
, VK_FORMAT_R32G32_SFLOAT
, },
4071 {WINED3DFMT_R32G32_UINT
, VK_FORMAT_R32G32_UINT
, },
4072 {WINED3DFMT_R32G32_SINT
, VK_FORMAT_R32G32_SINT
, },
4073 {WINED3DFMT_R10G10B10A2_UNORM
, VK_FORMAT_A2B10G10R10_UNORM_PACK32
,},
4074 {WINED3DFMT_R11G11B10_FLOAT
, VK_FORMAT_B10G11R11_UFLOAT_PACK32
, },
4075 {WINED3DFMT_R8G8_UNORM
, VK_FORMAT_R8G8_UNORM
, },
4076 {WINED3DFMT_R8G8_UINT
, VK_FORMAT_R8G8_UINT
, },
4077 {WINED3DFMT_R8G8_SNORM
, VK_FORMAT_R8G8_SNORM
, },
4078 {WINED3DFMT_R8G8_SINT
, VK_FORMAT_R8G8_SINT
, },
4079 {WINED3DFMT_R8G8B8A8_UNORM
, VK_FORMAT_R8G8B8A8_UNORM
, },
4080 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, VK_FORMAT_R8G8B8A8_SRGB
, },
4081 {WINED3DFMT_R8G8B8A8_UINT
, VK_FORMAT_R8G8B8A8_UINT
, },
4082 {WINED3DFMT_R8G8B8A8_SNORM
, VK_FORMAT_R8G8B8A8_SNORM
, },
4083 {WINED3DFMT_R8G8B8A8_SINT
, VK_FORMAT_R8G8B8A8_SINT
, },
4084 {WINED3DFMT_R16G16_FLOAT
, VK_FORMAT_R16G16_SFLOAT
, },
4085 {WINED3DFMT_R16G16_UNORM
, VK_FORMAT_R16G16_UNORM
, },
4086 {WINED3DFMT_R16G16_UINT
, VK_FORMAT_R16G16_UINT
, },
4087 {WINED3DFMT_R16G16_SNORM
, VK_FORMAT_R16G16_SNORM
, },
4088 {WINED3DFMT_R16G16_SINT
, VK_FORMAT_R16G16_SINT
, },
4089 {WINED3DFMT_D32_FLOAT
, VK_FORMAT_D32_SFLOAT
, },
4090 {WINED3DFMT_R32_FLOAT
, VK_FORMAT_R32_SFLOAT
, },
4091 {WINED3DFMT_R32_UINT
, VK_FORMAT_R32_UINT
, },
4092 {WINED3DFMT_R32_SINT
, VK_FORMAT_R32_SINT
, },
4093 {WINED3DFMT_R16_FLOAT
, VK_FORMAT_R16_SFLOAT
, },
4094 {WINED3DFMT_D16_UNORM
, VK_FORMAT_D16_UNORM
, },
4095 {WINED3DFMT_R16_UNORM
, VK_FORMAT_R16_UNORM
, },
4096 {WINED3DFMT_R16_UINT
, VK_FORMAT_R16_UINT
, },
4097 {WINED3DFMT_R16_SNORM
, VK_FORMAT_R16_SNORM
, },
4098 {WINED3DFMT_R16_SINT
, VK_FORMAT_R16_SINT
, },
4099 {WINED3DFMT_R8_UNORM
, VK_FORMAT_R8_UNORM
, },
4100 {WINED3DFMT_R8_UINT
, VK_FORMAT_R8_UINT
, },
4101 {WINED3DFMT_R8_SNORM
, VK_FORMAT_R8_SNORM
, },
4102 {WINED3DFMT_R8_SINT
, VK_FORMAT_R8_SINT
, },
4103 {WINED3DFMT_A8_UNORM
, VK_FORMAT_R8_UNORM
, "000X"},
4104 {WINED3DFMT_B8G8R8A8_UNORM
, VK_FORMAT_B8G8R8A8_UNORM
, },
4105 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, VK_FORMAT_B8G8R8A8_SRGB
, },
4106 {WINED3DFMT_B8G8R8X8_UNORM
, VK_FORMAT_B8G8R8A8_UNORM
, "XYZ1"},
4107 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, VK_FORMAT_B8G8R8A8_SRGB
, "XYZ1"},
4108 {WINED3DFMT_BC1_UNORM
, VK_FORMAT_BC1_RGBA_UNORM_BLOCK
, },
4109 {WINED3DFMT_BC1_UNORM_SRGB
, VK_FORMAT_BC1_RGBA_SRGB_BLOCK
, },
4110 {WINED3DFMT_BC2_UNORM
, VK_FORMAT_BC2_UNORM_BLOCK
, },
4111 {WINED3DFMT_BC2_UNORM_SRGB
, VK_FORMAT_BC2_SRGB_BLOCK
, },
4112 {WINED3DFMT_BC3_UNORM
, VK_FORMAT_BC3_UNORM_BLOCK
, },
4113 {WINED3DFMT_BC3_UNORM_SRGB
, VK_FORMAT_BC3_SRGB_BLOCK
, },
4114 {WINED3DFMT_BC4_UNORM
, VK_FORMAT_BC4_UNORM_BLOCK
, },
4115 {WINED3DFMT_BC4_SNORM
, VK_FORMAT_BC4_SNORM_BLOCK
, },
4116 {WINED3DFMT_BC5_UNORM
, VK_FORMAT_BC5_UNORM_BLOCK
, },
4117 {WINED3DFMT_BC5_SNORM
, VK_FORMAT_BC5_SNORM_BLOCK
, },
4118 {WINED3DFMT_BC6H_UF16
, VK_FORMAT_BC6H_UFLOAT_BLOCK
, },
4119 {WINED3DFMT_BC6H_SF16
, VK_FORMAT_BC6H_SFLOAT_BLOCK
, },
4120 {WINED3DFMT_BC7_UNORM
, VK_FORMAT_BC7_UNORM_BLOCK
, },
4121 {WINED3DFMT_BC7_UNORM_SRGB
, VK_FORMAT_BC7_SRGB_BLOCK
, },
4122 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, VK_FORMAT_E5B9G9R9_UFLOAT_PACK32
, },
4123 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4124 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4125 {WINED3DFMT_X32_TYPELESS_G8X24_UINT
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4126 {WINED3DFMT_D24_UNORM_S8_UINT
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4128 VkFormat vk_format
= VK_FORMAT_UNDEFINED
;
4129 VkImageFormatProperties image_properties
;
4130 VkFormatFeatureFlags texture_flags
;
4131 VkFormatProperties properties
;
4132 VkImageUsageFlags vk_usage
;
4138 for (i
= 0; i
< ARRAY_SIZE(vulkan_formats
); ++i
)
4140 if (vulkan_formats
[i
].id
== format
->f
.id
)
4142 vk_format
= vulkan_formats
[i
].vk_format
;
4143 fixup
= vulkan_formats
[i
].fixup
;
4149 WARN("Unsupported format %s.\n", debug_d3dformat(format
->f
.id
));
4153 format
->vk_format
= vk_format
;
4155 format
->f
.color_fixup
= create_color_fixup_desc_from_string(fixup
);
4157 format
->f
.color_fixup
= COLOR_FIXUP_IDENTITY
;
4159 VK_CALL(vkGetPhysicalDeviceFormatProperties(vk_physical_device
, vk_format
, &properties
));
4161 if (properties
.bufferFeatures
& VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
)
4162 format
->f
.flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= WINED3DFMT_FLAG_VERTEX_ATTRIBUTE
;
4163 if (properties
.bufferFeatures
& VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
)
4164 format
->f
.flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= WINED3DFMT_FLAG_TEXTURE
;
4167 texture_flags
= properties
.linearTilingFeatures
| properties
.optimalTilingFeatures
;
4168 if (texture_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
)
4170 flags
|= WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_VTF
;
4172 if (texture_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)
4174 flags
|= WINED3DFMT_FLAG_RENDERTARGET
;
4176 if (texture_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
)
4178 flags
|= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
4180 if (texture_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)
4182 flags
|= WINED3DFMT_FLAG_DEPTH_STENCIL
;
4184 if (texture_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
)
4186 flags
|= WINED3DFMT_FLAG_FILTERING
;
4188 if (texture_flags
& VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
)
4190 flags
|= WINED3DFMT_FLAG_UNORDERED_ACCESS
;
4193 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_1D
] |= flags
;
4194 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] |= flags
;
4195 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] |= flags
;
4196 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= flags
;
4199 if (texture_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)
4200 vk_usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
4201 else if (texture_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)
4202 vk_usage
= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
;
4205 if ((vr
= VK_CALL(vkGetPhysicalDeviceImageFormatProperties(vk_physical_device
, vk_format
,
4206 VK_IMAGE_TYPE_2D
, VK_IMAGE_TILING_OPTIMAL
, vk_usage
, 0, &image_properties
))) < 0)
4208 ERR("Failed to get image format properties, vr %s.\n", wined3d_debug_vkresult(vr
));
4211 format
->f
.multisample_types
= image_properties
.sampleCounts
;
4215 BOOL
wined3d_adapter_vk_init_format_info(struct wined3d_adapter_vk
*adapter_vk
,
4216 const struct wined3d_vk_info
*vk_info
)
4218 VkPhysicalDevice vk_physical_device
= adapter_vk
->physical_device
;
4219 struct wined3d_adapter
*adapter
= &adapter_vk
->a
;
4220 struct wined3d_format_vk
*format
;
4223 if (!wined3d_adapter_init_format_info(adapter
, sizeof(*format
)))
4226 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
4228 format
= wined3d_format_vk_mutable(get_format_by_idx(adapter
, i
));
4231 init_vulkan_format_info(format
, vk_info
, vk_physical_device
);
4234 if (!init_typeless_formats(adapter
)) goto fail
;
4239 heap_free(adapter
->formats
);
4240 adapter
->formats
= NULL
;
4244 const struct wined3d_format
*wined3d_get_format(const struct wined3d_adapter
*adapter
,
4245 enum wined3d_format_id format_id
, unsigned int bind_flags
)
4247 const struct wined3d_format
*format
;
4248 int idx
= get_format_idx(format_id
);
4253 FIXME("Can't find format %s (%#x) in the format lookup table.\n",
4254 debug_d3dformat(format_id
), format_id
);
4255 return get_format_internal(adapter
, WINED3DFMT_UNKNOWN
);
4258 format
= get_format_by_idx(adapter
, idx
);
4260 if (bind_flags
& WINED3D_BIND_DEPTH_STENCIL
&& wined3d_format_is_typeless(format
))
4262 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
4264 if (typeless_depth_stencil_formats
[i
].typeless_id
== format_id
)
4265 return get_format_by_idx(adapter
, WINED3D_FORMAT_COUNT
+ i
);
4268 FIXME("Cannot find depth/stencil typeless format %s (%#x).\n",
4269 debug_d3dformat(format_id
), format_id
);
4270 return get_format_internal(adapter
, WINED3DFMT_UNKNOWN
);
4276 BOOL
wined3d_format_is_depth_view(enum wined3d_format_id resource_format_id
,
4277 enum wined3d_format_id view_format_id
)
4281 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
4283 if (typeless_depth_stencil_formats
[i
].typeless_id
== resource_format_id
)
4284 return typeless_depth_stencil_formats
[i
].depth_view_id
== view_format_id
;
4289 void wined3d_format_calculate_pitch(const struct wined3d_format
*format
, unsigned int alignment
,
4290 unsigned int width
, unsigned int height
, unsigned int *row_pitch
, unsigned int *slice_pitch
)
4292 /* For block based formats, pitch means the amount of bytes to the next
4293 * row of blocks rather than the next row of pixels. */
4294 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BLOCKS
)
4296 unsigned int row_block_count
= (width
+ format
->block_width
- 1) / format
->block_width
;
4297 unsigned int slice_block_count
= (height
+ format
->block_height
- 1) / format
->block_height
;
4298 *row_pitch
= row_block_count
* format
->block_byte_count
;
4299 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
4300 *slice_pitch
= *row_pitch
* slice_block_count
;
4304 *row_pitch
= format
->byte_count
* width
; /* Bytes / row */
4305 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
4306 *slice_pitch
= *row_pitch
* height
;
4309 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_HEIGHT_SCALE
)
4311 /* The D3D format requirements make sure that the resulting format is an integer again */
4312 *slice_pitch
*= format
->height_scale
.numerator
;
4313 *slice_pitch
/= format
->height_scale
.denominator
;
4316 TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch
, *slice_pitch
);
4319 UINT
wined3d_format_calculate_size(const struct wined3d_format
*format
, UINT alignment
,
4320 UINT width
, UINT height
, UINT depth
)
4322 unsigned int row_pitch
, slice_pitch
;
4324 if (format
->id
== WINED3DFMT_UNKNOWN
)
4327 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BROKEN_PITCH
)
4328 return width
* height
* depth
* format
->byte_count
;
4330 wined3d_format_calculate_pitch(format
, alignment
, width
, height
, &row_pitch
, &slice_pitch
);
4332 return slice_pitch
* depth
;
4335 BOOL
wined3d_formats_are_srgb_variants(enum wined3d_format_id format1
, enum wined3d_format_id format2
)
4339 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
4341 if (format1
== format_srgb_info
[i
].srgb_format_id
)
4342 return format2
== format_srgb_info
[i
].base_format_id
;
4343 if (format1
== format_srgb_info
[i
].base_format_id
)
4344 return format2
== format_srgb_info
[i
].srgb_format_id
;
4349 /*****************************************************************************
4350 * Trace formatting of useful values
4352 const char *debug_box(const struct wined3d_box
*box
)
4356 return wine_dbg_sprintf("(%u, %u, %u)-(%u, %u, %u)",
4357 box
->left
, box
->top
, box
->front
,
4358 box
->right
, box
->bottom
, box
->back
);
4361 const char *debug_color(const struct wined3d_color
*color
)
4365 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
4366 color
->r
, color
->g
, color
->b
, color
->a
);
4369 const char *debug_ivec4(const struct wined3d_ivec4
*v
)
4373 return wine_dbg_sprintf("{%d, %d, %d, %d}",
4374 v
->x
, v
->y
, v
->z
, v
->w
);
4377 const char *debug_uvec4(const struct wined3d_uvec4
*v
)
4381 return wine_dbg_sprintf("{%u, %u, %u, %u}",
4382 v
->x
, v
->y
, v
->z
, v
->w
);
4385 const char *debug_vec4(const struct wined3d_vec4
*v
)
4389 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
4390 v
->x
, v
->y
, v
->z
, v
->w
);
4393 const char *debug_const_bo_address(const struct wined3d_const_bo_address
*address
)
4397 return wine_dbg_sprintf("{%#lx:%p}", address
->buffer_object
, address
->addr
);
4400 const char *debug_bo_address(const struct wined3d_bo_address
*address
)
4402 return debug_const_bo_address((const struct wined3d_const_bo_address
*)address
);
4405 const char *debug_d3dformat(enum wined3d_format_id format_id
)
4409 #define FMT_TO_STR(format_id) case format_id: return #format_id
4410 FMT_TO_STR(WINED3DFMT_UNKNOWN
);
4411 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM
);
4412 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM
);
4413 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM
);
4414 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM
);
4415 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM
);
4416 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM
);
4417 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM
);
4418 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM
);
4419 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM
);
4420 FMT_TO_STR(WINED3DFMT_P8_UINT
);
4421 FMT_TO_STR(WINED3DFMT_L8_UNORM
);
4422 FMT_TO_STR(WINED3DFMT_L8A8_UNORM
);
4423 FMT_TO_STR(WINED3DFMT_L4A4_UNORM
);
4424 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
4425 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
4426 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM
);
4427 FMT_TO_STR(WINED3DFMT_R10G10B10X2_TYPELESS
);
4428 FMT_TO_STR(WINED3DFMT_R10G10B10X2_UINT
);
4429 FMT_TO_STR(WINED3DFMT_R10G10B10X2_SNORM
);
4430 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM
);
4431 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE
);
4432 FMT_TO_STR(WINED3DFMT_D32_UNORM
);
4433 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM
);
4434 FMT_TO_STR(WINED3DFMT_X8D24_UNORM
);
4435 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM
);
4436 FMT_TO_STR(WINED3DFMT_L16_UNORM
);
4437 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT
);
4438 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx
);
4439 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS
);
4440 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT
);
4441 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT
);
4442 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT
);
4443 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS
);
4444 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT
);
4445 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT
);
4446 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT
);
4447 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS
);
4448 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT
);
4449 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM
);
4450 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT
);
4451 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM
);
4452 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT
);
4453 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS
);
4454 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT
);
4455 FMT_TO_STR(WINED3DFMT_R32G32_UINT
);
4456 FMT_TO_STR(WINED3DFMT_R32G32_SINT
);
4457 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS
);
4458 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT
);
4459 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
);
4460 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT
);
4461 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS
);
4462 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM
);
4463 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT
);
4464 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM
);
4465 FMT_TO_STR(WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM
);
4466 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT
);
4467 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS
);
4468 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM
);
4469 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB
);
4470 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT
);
4471 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM
);
4472 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT
);
4473 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS
);
4474 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT
);
4475 FMT_TO_STR(WINED3DFMT_R16G16_UNORM
);
4476 FMT_TO_STR(WINED3DFMT_R16G16_UINT
);
4477 FMT_TO_STR(WINED3DFMT_R16G16_SNORM
);
4478 FMT_TO_STR(WINED3DFMT_R16G16_SINT
);
4479 FMT_TO_STR(WINED3DFMT_R32_TYPELESS
);
4480 FMT_TO_STR(WINED3DFMT_D32_FLOAT
);
4481 FMT_TO_STR(WINED3DFMT_R32_FLOAT
);
4482 FMT_TO_STR(WINED3DFMT_R32_UINT
);
4483 FMT_TO_STR(WINED3DFMT_R32_SINT
);
4484 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS
);
4485 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT
);
4486 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS
);
4487 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT
);
4488 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS
);
4489 FMT_TO_STR(WINED3DFMT_R8G8_UNORM
);
4490 FMT_TO_STR(WINED3DFMT_R8G8_UINT
);
4491 FMT_TO_STR(WINED3DFMT_R8G8_SNORM
);
4492 FMT_TO_STR(WINED3DFMT_R8G8_SINT
);
4493 FMT_TO_STR(WINED3DFMT_R16_TYPELESS
);
4494 FMT_TO_STR(WINED3DFMT_R16_FLOAT
);
4495 FMT_TO_STR(WINED3DFMT_D16_UNORM
);
4496 FMT_TO_STR(WINED3DFMT_R16_UNORM
);
4497 FMT_TO_STR(WINED3DFMT_R16_UINT
);
4498 FMT_TO_STR(WINED3DFMT_R16_SNORM
);
4499 FMT_TO_STR(WINED3DFMT_R16_SINT
);
4500 FMT_TO_STR(WINED3DFMT_R8_TYPELESS
);
4501 FMT_TO_STR(WINED3DFMT_R8_UNORM
);
4502 FMT_TO_STR(WINED3DFMT_R8_UINT
);
4503 FMT_TO_STR(WINED3DFMT_R8_SNORM
);
4504 FMT_TO_STR(WINED3DFMT_R8_SINT
);
4505 FMT_TO_STR(WINED3DFMT_A8_UNORM
);
4506 FMT_TO_STR(WINED3DFMT_R1_UNORM
);
4507 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP
);
4508 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM
);
4509 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM
);
4510 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS
);
4511 FMT_TO_STR(WINED3DFMT_BC1_UNORM
);
4512 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB
);
4513 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS
);
4514 FMT_TO_STR(WINED3DFMT_BC2_UNORM
);
4515 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB
);
4516 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS
);
4517 FMT_TO_STR(WINED3DFMT_BC3_UNORM
);
4518 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB
);
4519 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS
);
4520 FMT_TO_STR(WINED3DFMT_BC4_UNORM
);
4521 FMT_TO_STR(WINED3DFMT_BC4_SNORM
);
4522 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS
);
4523 FMT_TO_STR(WINED3DFMT_BC5_UNORM
);
4524 FMT_TO_STR(WINED3DFMT_BC5_SNORM
);
4525 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM
);
4526 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM
);
4527 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM
);
4528 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM
);
4529 FMT_TO_STR(WINED3DFMT_B8G8R8A8_TYPELESS
);
4530 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM_SRGB
);
4531 FMT_TO_STR(WINED3DFMT_B8G8R8X8_TYPELESS
);
4532 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM_SRGB
);
4533 FMT_TO_STR(WINED3DFMT_BC6H_TYPELESS
);
4534 FMT_TO_STR(WINED3DFMT_BC6H_UF16
);
4535 FMT_TO_STR(WINED3DFMT_BC6H_SF16
);
4536 FMT_TO_STR(WINED3DFMT_BC7_TYPELESS
);
4537 FMT_TO_STR(WINED3DFMT_BC7_UNORM
);
4538 FMT_TO_STR(WINED3DFMT_BC7_UNORM_SRGB
);
4539 FMT_TO_STR(WINED3DFMT_UYVY
);
4540 FMT_TO_STR(WINED3DFMT_YUY2
);
4541 FMT_TO_STR(WINED3DFMT_YV12
);
4542 FMT_TO_STR(WINED3DFMT_DXT1
);
4543 FMT_TO_STR(WINED3DFMT_DXT2
);
4544 FMT_TO_STR(WINED3DFMT_DXT3
);
4545 FMT_TO_STR(WINED3DFMT_DXT4
);
4546 FMT_TO_STR(WINED3DFMT_DXT5
);
4547 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8
);
4548 FMT_TO_STR(WINED3DFMT_G8R8_G8B8
);
4549 FMT_TO_STR(WINED3DFMT_R8G8_B8G8
);
4550 FMT_TO_STR(WINED3DFMT_ATI1N
);
4551 FMT_TO_STR(WINED3DFMT_ATI2N
);
4552 FMT_TO_STR(WINED3DFMT_INST
);
4553 FMT_TO_STR(WINED3DFMT_NVDB
);
4554 FMT_TO_STR(WINED3DFMT_NVHU
);
4555 FMT_TO_STR(WINED3DFMT_NVHS
);
4556 FMT_TO_STR(WINED3DFMT_INTZ
);
4557 FMT_TO_STR(WINED3DFMT_RESZ
);
4558 FMT_TO_STR(WINED3DFMT_NULL
);
4559 FMT_TO_STR(WINED3DFMT_R16
);
4560 FMT_TO_STR(WINED3DFMT_AL16
);
4561 FMT_TO_STR(WINED3DFMT_NV12
);
4562 FMT_TO_STR(WINED3DFMT_ATOC
);
4567 fourcc
[0] = (char)(format_id
);
4568 fourcc
[1] = (char)(format_id
>> 8);
4569 fourcc
[2] = (char)(format_id
>> 16);
4570 fourcc
[3] = (char)(format_id
>> 24);
4572 if (isprint(fourcc
[0]) && isprint(fourcc
[1]) && isprint(fourcc
[2]) && isprint(fourcc
[3]))
4573 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id
, fourcc
);
4575 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id
);
4577 return "unrecognized";
4581 const char *debug_d3ddevicetype(enum wined3d_device_type device_type
)
4583 switch (device_type
)
4585 #define DEVTYPE_TO_STR(dev) case dev: return #dev
4586 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL
);
4587 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF
);
4588 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW
);
4589 #undef DEVTYPE_TO_STR
4591 FIXME("Unrecognized device type %#x.\n", device_type
);
4592 return "unrecognized";
4598 char str
[200]; /* wine_dbg_sprintf() limits string size to 200 */
4603 static void init_debug_buffer(struct debug_buffer
*buffer
, const char *default_string
)
4605 snprintf(buffer
->str
, sizeof(buffer
->str
), "%s", default_string
);
4606 buffer
->ptr
= buffer
->str
;
4607 buffer
->size
= sizeof(buffer
->str
);
4610 static void debug_append(struct debug_buffer
*buffer
, const char *str
, const char *separator
)
4614 if (!separator
|| buffer
->ptr
== buffer
->str
)
4616 size
= snprintf(buffer
->ptr
, buffer
->size
, "%s%s", separator
, str
);
4617 if (size
== -1 || size
>= buffer
->size
)
4620 strcpy(&buffer
->str
[sizeof(buffer
->str
) - 4], "...");
4624 buffer
->ptr
+= size
;
4625 buffer
->size
-= size
;
4628 const char *wined3d_debug_resource_access(DWORD access
)
4630 struct debug_buffer buffer
;
4632 init_debug_buffer(&buffer
, "0");
4633 #define ACCESS_TO_STR(x) if (access & x) { debug_append(&buffer, #x, " | "); access &= ~x; }
4634 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_GPU
);
4635 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_CPU
);
4636 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_MAP_R
);
4637 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_MAP_W
);
4638 #undef ACCESS_TO_STR
4640 FIXME("Unrecognised access flag(s) %#x.\n", access
);
4642 return wine_dbg_sprintf("%s", buffer
.str
);
4645 const char *wined3d_debug_bind_flags(DWORD bind_flags
)
4647 struct debug_buffer buffer
;
4649 init_debug_buffer(&buffer
, "0");
4650 #define BIND_FLAG_TO_STR(x) if (bind_flags & x) { debug_append(&buffer, #x, " | "); bind_flags &= ~x; }
4651 BIND_FLAG_TO_STR(WINED3D_BIND_VERTEX_BUFFER
);
4652 BIND_FLAG_TO_STR(WINED3D_BIND_INDEX_BUFFER
);
4653 BIND_FLAG_TO_STR(WINED3D_BIND_CONSTANT_BUFFER
);
4654 BIND_FLAG_TO_STR(WINED3D_BIND_SHADER_RESOURCE
);
4655 BIND_FLAG_TO_STR(WINED3D_BIND_STREAM_OUTPUT
);
4656 BIND_FLAG_TO_STR(WINED3D_BIND_RENDER_TARGET
);
4657 BIND_FLAG_TO_STR(WINED3D_BIND_DEPTH_STENCIL
);
4658 BIND_FLAG_TO_STR(WINED3D_BIND_UNORDERED_ACCESS
);
4659 BIND_FLAG_TO_STR(WINED3D_BIND_INDIRECT_BUFFER
);
4660 #undef BIND_FLAG_TO_STR
4662 FIXME("Unrecognised bind flag(s) %#x.\n", bind_flags
);
4664 return wine_dbg_sprintf("%s", buffer
.str
);
4667 const char *wined3d_debug_view_desc(const struct wined3d_view_desc
*d
, const struct wined3d_resource
*resource
)
4669 struct debug_buffer buffer
;
4670 unsigned int flags
= d
->flags
;
4672 init_debug_buffer(&buffer
, "0");
4673 #define VIEW_FLAG_TO_STR(x) if (flags & x) { debug_append(&buffer, #x, " | "); flags &= ~x; }
4674 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_RAW
);
4675 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_APPEND
);
4676 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_COUNTER
);
4677 VIEW_FLAG_TO_STR(WINED3D_VIEW_TEXTURE_CUBE
);
4678 VIEW_FLAG_TO_STR(WINED3D_VIEW_TEXTURE_ARRAY
);
4679 #undef VIEW_FLAG_TO_STR
4681 FIXME("Unrecognised view flag(s) %#x.\n", flags
);
4683 if (resource
->type
== WINED3D_RTYPE_BUFFER
)
4684 return wine_dbg_sprintf("format %s, flags %s, start_idx %u, count %u",
4685 debug_d3dformat(d
->format_id
), buffer
.str
, d
->u
.buffer
.start_idx
, d
->u
.buffer
.count
);
4687 return wine_dbg_sprintf("format %s, flags %s, level_idx %u, level_count %u, layer_idx %u, layer_count %u",
4688 debug_d3dformat(d
->format_id
), buffer
.str
, d
->u
.texture
.level_idx
, d
->u
.texture
.level_count
,
4689 d
->u
.texture
.layer_idx
, d
->u
.texture
.layer_count
);
4692 const char *debug_d3dusage(DWORD usage
)
4694 struct debug_buffer buffer
;
4696 init_debug_buffer(&buffer
, "0");
4697 #define WINED3DUSAGE_TO_STR(x) if (usage & x) { debug_append(&buffer, #x, " | "); usage &= ~x; }
4698 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING
);
4699 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP
);
4700 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS
);
4701 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES
);
4702 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES
);
4703 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC
);
4704 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICTED_CONTENT
);
4705 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE_DRIVER
);
4706 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE
);
4707 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP
);
4708 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTAPI
);
4709 WINED3DUSAGE_TO_STR(WINED3DUSAGE_LEGACY_CUBEMAP
);
4710 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OWNDC
);
4711 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL
);
4712 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY
);
4713 #undef WINED3DUSAGE_TO_STR
4715 FIXME("Unrecognized usage flag(s) %#x.\n", usage
);
4717 return wine_dbg_sprintf("%s", buffer
.str
);
4720 const char *debug_d3dusagequery(DWORD usage
)
4722 struct debug_buffer buffer
;
4724 init_debug_buffer(&buffer
, "0");
4725 #define WINED3DUSAGEQUERY_TO_STR(x) if (usage & x) { debug_append(&buffer, #x, " | "); usage &= ~x; }
4726 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_FILTER
);
4727 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_GENMIPMAP
);
4728 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP
);
4729 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
);
4730 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD
);
4731 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE
);
4732 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE
);
4733 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP
);
4734 #undef WINED3DUSAGEQUERY_TO_STR
4736 FIXME("Unrecognized usage query flag(s) %#x.\n", usage
);
4738 return wine_dbg_sprintf("%s", buffer
.str
);
4741 const char *debug_d3ddeclmethod(enum wined3d_decl_method method
)
4745 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
4746 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT
);
4747 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U
);
4748 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V
);
4749 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV
);
4750 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV
);
4751 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP
);
4752 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED
);
4753 #undef WINED3DDECLMETHOD_TO_STR
4755 FIXME("Unrecognized declaration method %#x.\n", method
);
4756 return "unrecognized";
4760 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage
)
4764 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
4765 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION
);
4766 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT
);
4767 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES
);
4768 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL
);
4769 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE
);
4770 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD
);
4771 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT
);
4772 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL
);
4773 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR
);
4774 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT
);
4775 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR
);
4776 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG
);
4777 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH
);
4778 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE
);
4779 #undef WINED3DDECLUSAGE_TO_STR
4781 FIXME("Unrecognized %u declaration usage!\n", usage
);
4782 return "unrecognized";
4786 const char *debug_d3dinput_classification(enum wined3d_input_classification classification
)
4788 switch (classification
)
4790 #define WINED3D_TO_STR(x) case x: return #x
4791 WINED3D_TO_STR(WINED3D_INPUT_PER_VERTEX_DATA
);
4792 WINED3D_TO_STR(WINED3D_INPUT_PER_INSTANCE_DATA
);
4793 #undef WINED3D_TO_STR
4795 FIXME("Unrecognized input classification %#x.\n", classification
);
4796 return "unrecognized";
4800 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type
)
4802 switch (resource_type
)
4804 #define WINED3D_TO_STR(x) case x: return #x
4805 WINED3D_TO_STR(WINED3D_RTYPE_NONE
);
4806 WINED3D_TO_STR(WINED3D_RTYPE_BUFFER
);
4807 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_1D
);
4808 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_2D
);
4809 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_3D
);
4810 #undef WINED3D_TO_STR
4812 FIXME("Unrecognized resource type %#x.\n", resource_type
);
4813 return "unrecognized";
4817 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type
)
4819 switch (primitive_type
)
4821 #define PRIM_TO_STR(prim) case prim: return #prim
4822 PRIM_TO_STR(WINED3D_PT_UNDEFINED
);
4823 PRIM_TO_STR(WINED3D_PT_POINTLIST
);
4824 PRIM_TO_STR(WINED3D_PT_LINELIST
);
4825 PRIM_TO_STR(WINED3D_PT_LINESTRIP
);
4826 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST
);
4827 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP
);
4828 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN
);
4829 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ
);
4830 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ
);
4831 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ
);
4832 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ
);
4833 PRIM_TO_STR(WINED3D_PT_PATCH
);
4836 FIXME("Unrecognized primitive type %#x.\n", primitive_type
);
4837 return "unrecognized";
4841 const char *debug_d3drenderstate(enum wined3d_render_state state
)
4845 #define D3DSTATE_TO_STR(u) case u: return #u
4846 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS
);
4847 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE
);
4848 D3DSTATE_TO_STR(WINED3D_RS_WRAPU
);
4849 D3DSTATE_TO_STR(WINED3D_RS_WRAPV
);
4850 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE
);
4851 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE
);
4852 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE
);
4853 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN
);
4854 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE
);
4855 D3DSTATE_TO_STR(WINED3D_RS_ROP2
);
4856 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK
);
4857 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE
);
4858 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE
);
4859 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL
);
4860 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND
);
4861 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND
);
4862 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE
);
4863 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC
);
4864 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF
);
4865 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC
);
4866 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE
);
4867 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE
);
4868 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE
);
4869 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE
);
4870 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE
);
4871 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL
);
4872 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX
);
4873 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA
);
4874 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR
);
4875 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE
);
4876 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART
);
4877 D3DSTATE_TO_STR(WINED3D_RS_FOGEND
);
4878 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY
);
4879 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE
);
4880 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE
);
4881 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS
);
4882 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE
);
4883 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY
);
4884 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH
);
4885 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT
);
4886 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE
);
4887 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL
);
4888 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL
);
4889 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS
);
4890 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC
);
4891 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF
);
4892 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK
);
4893 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK
);
4894 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR
);
4895 D3DSTATE_TO_STR(WINED3D_RS_WRAP0
);
4896 D3DSTATE_TO_STR(WINED3D_RS_WRAP1
);
4897 D3DSTATE_TO_STR(WINED3D_RS_WRAP2
);
4898 D3DSTATE_TO_STR(WINED3D_RS_WRAP3
);
4899 D3DSTATE_TO_STR(WINED3D_RS_WRAP4
);
4900 D3DSTATE_TO_STR(WINED3D_RS_WRAP5
);
4901 D3DSTATE_TO_STR(WINED3D_RS_WRAP6
);
4902 D3DSTATE_TO_STR(WINED3D_RS_WRAP7
);
4903 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING
);
4904 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING
);
4905 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS
);
4906 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT
);
4907 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE
);
4908 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX
);
4909 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER
);
4910 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS
);
4911 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE
);
4912 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE
);
4913 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE
);
4914 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE
);
4915 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE
);
4916 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND
);
4917 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE
);
4918 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING
);
4919 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE
);
4920 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN
);
4921 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE
);
4922 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE
);
4923 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A
);
4924 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B
);
4925 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C
);
4926 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS
);
4927 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK
);
4928 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE
);
4929 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS
);
4930 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN
);
4931 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX
);
4932 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE
);
4933 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE
);
4934 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR
);
4935 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP
);
4936 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE
);
4937 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE
);
4938 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE
);
4939 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS
);
4940 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE
);
4941 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL
);
4942 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL
);
4943 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X
);
4944 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y
);
4945 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z
);
4946 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W
);
4947 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION
);
4948 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE
);
4949 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFAIL
);
4950 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILZFAIL
);
4951 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILPASS
);
4952 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFUNC
);
4953 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1
);
4954 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2
);
4955 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3
);
4956 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE
);
4957 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS
);
4958 D3DSTATE_TO_STR(WINED3D_RS_WRAP8
);
4959 D3DSTATE_TO_STR(WINED3D_RS_WRAP9
);
4960 D3DSTATE_TO_STR(WINED3D_RS_WRAP10
);
4961 D3DSTATE_TO_STR(WINED3D_RS_WRAP11
);
4962 D3DSTATE_TO_STR(WINED3D_RS_WRAP12
);
4963 D3DSTATE_TO_STR(WINED3D_RS_WRAP13
);
4964 D3DSTATE_TO_STR(WINED3D_RS_WRAP14
);
4965 D3DSTATE_TO_STR(WINED3D_RS_WRAP15
);
4966 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE
);
4967 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA
);
4968 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA
);
4969 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA
);
4970 #undef D3DSTATE_TO_STR
4972 FIXME("Unrecognized %u render state!\n", state
);
4973 return "unrecognized";
4977 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state
)
4981 #define D3DSTATE_TO_STR(u) case u: return #u
4982 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR
);
4983 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U
);
4984 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V
);
4985 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W
);
4986 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER
);
4987 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER
);
4988 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER
);
4989 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS
);
4990 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL
);
4991 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY
);
4992 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE
);
4993 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX
);
4994 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET
);
4995 #undef D3DSTATE_TO_STR
4997 FIXME("Unrecognized %u sampler state!\n", state
);
4998 return "unrecognized";
5002 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type
)
5004 switch (filter_type
)
5006 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
5007 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE
);
5008 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT
);
5009 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR
);
5010 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC
);
5011 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC
);
5012 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC
);
5013 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD
);
5014 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD
);
5015 #undef D3DTEXTUREFILTERTYPE_TO_STR
5017 FIXME("Unrecognized texture filter type 0x%08x.\n", filter_type
);
5018 return "unrecognized";
5022 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state
)
5026 #define D3DSTATE_TO_STR(u) case u: return #u
5027 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP
);
5028 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1
);
5029 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2
);
5030 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP
);
5031 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1
);
5032 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2
);
5033 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00
);
5034 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01
);
5035 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10
);
5036 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11
);
5037 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX
);
5038 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE
);
5039 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET
);
5040 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
);
5041 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0
);
5042 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0
);
5043 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG
);
5044 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT
);
5045 #undef D3DSTATE_TO_STR
5047 FIXME("Unrecognized %u texture state!\n", state
);
5048 return "unrecognized";
5052 const char *debug_d3dtop(enum wined3d_texture_op d3dtop
)
5056 #define D3DTOP_TO_STR(u) case u: return #u
5057 D3DTOP_TO_STR(WINED3D_TOP_DISABLE
);
5058 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1
);
5059 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2
);
5060 D3DTOP_TO_STR(WINED3D_TOP_MODULATE
);
5061 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X
);
5062 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X
);
5063 D3DTOP_TO_STR(WINED3D_TOP_ADD
);
5064 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED
);
5065 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X
);
5066 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT
);
5067 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH
);
5068 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA
);
5069 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA
);
5070 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA
);
5071 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM
);
5072 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA
);
5073 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE
);
5074 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR
);
5075 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA
);
5076 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR
);
5077 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA
);
5078 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP
);
5079 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE
);
5080 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3
);
5081 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD
);
5082 D3DTOP_TO_STR(WINED3D_TOP_LERP
);
5083 #undef D3DTOP_TO_STR
5085 FIXME("Unrecognized texture op %#x.\n", d3dtop
);
5086 return "unrecognized";
5090 const char *debug_d3dtstype(enum wined3d_transform_state tstype
)
5094 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
5095 TSTYPE_TO_STR(WINED3D_TS_VIEW
);
5096 TSTYPE_TO_STR(WINED3D_TS_PROJECTION
);
5097 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0
);
5098 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1
);
5099 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2
);
5100 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3
);
5101 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4
);
5102 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5
);
5103 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6
);
5104 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7
);
5105 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
5106 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(1));
5107 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(2));
5108 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(3));
5109 #undef TSTYPE_TO_STR
5111 if (tstype
> 256 && tstype
< 512)
5113 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype
);
5114 return ("WINED3D_TS_WORLD_MATRIX > 0");
5116 FIXME("Unrecognized transform state %#x.\n", tstype
);
5117 return "unrecognized";
5121 const char *debug_shader_type(enum wined3d_shader_type type
)
5125 #define WINED3D_TO_STR(type) case type: return #type
5126 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL
);
5127 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX
);
5128 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY
);
5129 WINED3D_TO_STR(WINED3D_SHADER_TYPE_HULL
);
5130 WINED3D_TO_STR(WINED3D_SHADER_TYPE_DOMAIN
);
5131 WINED3D_TO_STR(WINED3D_SHADER_TYPE_COMPUTE
);
5132 #undef WINED3D_TO_STR
5134 FIXME("Unrecognized shader type %#x.\n", type
);
5135 return "unrecognized";
5139 const char *debug_d3dstate(DWORD state
)
5141 if (STATE_IS_RENDER(state
))
5142 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state
- STATE_RENDER(0)));
5143 if (STATE_IS_TEXTURESTAGE(state
))
5145 DWORD texture_stage
= (state
- STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE
+ 1);
5146 DWORD texture_state
= state
- STATE_TEXTURESTAGE(texture_stage
, 0);
5147 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
5148 texture_stage
, debug_d3dtexturestate(texture_state
));
5150 if (STATE_IS_SAMPLER(state
))
5151 return wine_dbg_sprintf("STATE_SAMPLER(%#x)", state
- STATE_SAMPLER(0));
5152 if (STATE_IS_COMPUTE_SHADER(state
))
5153 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE
));
5154 if (STATE_IS_GRAPHICS_SHADER(state
))
5155 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state
- STATE_SHADER(0)));
5156 if (STATE_IS_COMPUTE_CONSTANT_BUFFER(state
))
5157 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE
));
5158 if (STATE_IS_GRAPHICS_CONSTANT_BUFFER(state
))
5159 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state
- STATE_CONSTANT_BUFFER(0)));
5160 if (STATE_IS_COMPUTE_SHADER_RESOURCE_BINDING(state
))
5161 return "STATE_COMPUTE_SHADER_RESOURCE_BINDING";
5162 if (STATE_IS_GRAPHICS_SHADER_RESOURCE_BINDING(state
))
5163 return "STATE_GRAPHICS_SHADER_RESOURCE_BINDING";
5164 if (STATE_IS_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING(state
))
5165 return "STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING";
5166 if (STATE_IS_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING(state
))
5167 return "STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING";
5168 if (STATE_IS_TRANSFORM(state
))
5169 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state
- STATE_TRANSFORM(0)));
5170 if (STATE_IS_STREAMSRC(state
))
5171 return "STATE_STREAMSRC";
5172 if (STATE_IS_INDEXBUFFER(state
))
5173 return "STATE_INDEXBUFFER";
5174 if (STATE_IS_VDECL(state
))
5175 return "STATE_VDECL";
5176 if (STATE_IS_VIEWPORT(state
))
5177 return "STATE_VIEWPORT";
5178 if (STATE_IS_LIGHT_TYPE(state
))
5179 return "STATE_LIGHT_TYPE";
5180 if (STATE_IS_ACTIVELIGHT(state
))
5181 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state
- STATE_ACTIVELIGHT(0));
5182 if (STATE_IS_SCISSORRECT(state
))
5183 return "STATE_SCISSORRECT";
5184 if (STATE_IS_CLIPPLANE(state
))
5185 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state
- STATE_CLIPPLANE(0));
5186 if (STATE_IS_MATERIAL(state
))
5187 return "STATE_MATERIAL";
5188 if (STATE_IS_RASTERIZER(state
))
5189 return "STATE_RASTERIZER";
5190 if (STATE_IS_POINTSPRITECOORDORIGIN(state
))
5191 return "STATE_POINTSPRITECOORDORIGIN";
5192 if (STATE_IS_BASEVERTEXINDEX(state
))
5193 return "STATE_BASEVERTEXINDEX";
5194 if (STATE_IS_FRAMEBUFFER(state
))
5195 return "STATE_FRAMEBUFFER";
5196 if (STATE_IS_POINT_ENABLE(state
))
5197 return "STATE_POINT_ENABLE";
5198 if (STATE_IS_COLOR_KEY(state
))
5199 return "STATE_COLOR_KEY";
5200 if (STATE_IS_STREAM_OUTPUT(state
))
5201 return "STATE_STREAM_OUTPUT";
5202 if (STATE_IS_BLEND(state
))
5203 return "STATE_BLEND";
5204 if (STATE_IS_BLEND_FACTOR(state
))
5205 return "STATE_BLEND_FACTOR";
5207 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state
);
5210 const char *debug_fboattachment(GLenum attachment
)
5214 #define WINED3D_TO_STR(x) case x: return #x
5215 WINED3D_TO_STR(GL_COLOR_ATTACHMENT0
);
5216 WINED3D_TO_STR(GL_COLOR_ATTACHMENT1
);
5217 WINED3D_TO_STR(GL_COLOR_ATTACHMENT2
);
5218 WINED3D_TO_STR(GL_COLOR_ATTACHMENT3
);
5219 WINED3D_TO_STR(GL_COLOR_ATTACHMENT4
);
5220 WINED3D_TO_STR(GL_COLOR_ATTACHMENT5
);
5221 WINED3D_TO_STR(GL_COLOR_ATTACHMENT6
);
5222 WINED3D_TO_STR(GL_COLOR_ATTACHMENT7
);
5223 WINED3D_TO_STR(GL_COLOR_ATTACHMENT8
);
5224 WINED3D_TO_STR(GL_COLOR_ATTACHMENT9
);
5225 WINED3D_TO_STR(GL_COLOR_ATTACHMENT10
);
5226 WINED3D_TO_STR(GL_COLOR_ATTACHMENT11
);
5227 WINED3D_TO_STR(GL_COLOR_ATTACHMENT12
);
5228 WINED3D_TO_STR(GL_COLOR_ATTACHMENT13
);
5229 WINED3D_TO_STR(GL_COLOR_ATTACHMENT14
);
5230 WINED3D_TO_STR(GL_COLOR_ATTACHMENT15
);
5231 WINED3D_TO_STR(GL_DEPTH_ATTACHMENT
);
5232 WINED3D_TO_STR(GL_STENCIL_ATTACHMENT
);
5233 #undef WINED3D_TO_STR
5235 return wine_dbg_sprintf("Unknown FBO attachment %#x", attachment
);
5239 const char *debug_fbostatus(GLenum status
) {
5241 #define FBOSTATUS_TO_STR(u) case u: return #u
5242 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE
);
5243 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
);
5244 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
);
5245 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
);
5246 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
);
5247 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
);
5248 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
);
5249 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
);
5250 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
);
5251 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB
);
5252 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED
);
5253 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED
);
5254 #undef FBOSTATUS_TO_STR
5256 FIXME("Unrecognized FBO status 0x%08x.\n", status
);
5257 return "unrecognized";
5261 const char *debug_glerror(GLenum error
) {
5263 #define GLERROR_TO_STR(u) case u: return #u
5264 GLERROR_TO_STR(GL_NO_ERROR
);
5265 GLERROR_TO_STR(GL_INVALID_ENUM
);
5266 GLERROR_TO_STR(GL_INVALID_VALUE
);
5267 GLERROR_TO_STR(GL_INVALID_OPERATION
);
5268 GLERROR_TO_STR(GL_STACK_OVERFLOW
);
5269 GLERROR_TO_STR(GL_STACK_UNDERFLOW
);
5270 GLERROR_TO_STR(GL_OUT_OF_MEMORY
);
5271 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION
);
5272 #undef GLERROR_TO_STR
5274 FIXME("Unrecognized GL error 0x%08x.\n", error
);
5275 return "unrecognized";
5279 const char *wined3d_debug_vkresult(VkResult vr
)
5283 #define WINED3D_TO_STR(x) case x: return #x
5284 WINED3D_TO_STR(VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR
);
5285 WINED3D_TO_STR(VK_ERROR_NOT_PERMITTED_EXT
);
5286 WINED3D_TO_STR(VK_ERROR_FRAGMENTATION_EXT
);
5287 WINED3D_TO_STR(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5288 WINED3D_TO_STR(VK_ERROR_OUT_OF_POOL_MEMORY
);
5289 WINED3D_TO_STR(VK_ERROR_INVALID_SHADER_NV
);
5290 WINED3D_TO_STR(VK_ERROR_OUT_OF_DATE_KHR
);
5291 WINED3D_TO_STR(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR
);
5292 WINED3D_TO_STR(VK_ERROR_SURFACE_LOST_KHR
);
5293 WINED3D_TO_STR(VK_ERROR_FRAGMENTED_POOL
);
5294 WINED3D_TO_STR(VK_ERROR_FORMAT_NOT_SUPPORTED
);
5295 WINED3D_TO_STR(VK_ERROR_TOO_MANY_OBJECTS
);
5296 WINED3D_TO_STR(VK_ERROR_INCOMPATIBLE_DRIVER
);
5297 WINED3D_TO_STR(VK_ERROR_FEATURE_NOT_PRESENT
);
5298 WINED3D_TO_STR(VK_ERROR_EXTENSION_NOT_PRESENT
);
5299 WINED3D_TO_STR(VK_ERROR_LAYER_NOT_PRESENT
);
5300 WINED3D_TO_STR(VK_ERROR_MEMORY_MAP_FAILED
);
5301 WINED3D_TO_STR(VK_ERROR_DEVICE_LOST
);
5302 WINED3D_TO_STR(VK_ERROR_INITIALIZATION_FAILED
);
5303 WINED3D_TO_STR(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
5304 WINED3D_TO_STR(VK_ERROR_OUT_OF_HOST_MEMORY
);
5305 WINED3D_TO_STR(VK_SUCCESS
);
5306 WINED3D_TO_STR(VK_NOT_READY
);
5307 WINED3D_TO_STR(VK_TIMEOUT
);
5308 WINED3D_TO_STR(VK_EVENT_SET
);
5309 WINED3D_TO_STR(VK_EVENT_RESET
);
5310 WINED3D_TO_STR(VK_INCOMPLETE
);
5311 WINED3D_TO_STR(VK_SUBOPTIMAL_KHR
);
5312 #undef WINED3D_TO_STR
5314 return wine_dbg_sprintf("unrecognised(%d)", vr
);
5318 static const char *debug_fixup_channel_source(enum fixup_channel_source source
)
5322 #define WINED3D_TO_STR(x) case x: return #x
5323 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO
);
5324 WINED3D_TO_STR(CHANNEL_SOURCE_ONE
);
5325 WINED3D_TO_STR(CHANNEL_SOURCE_X
);
5326 WINED3D_TO_STR(CHANNEL_SOURCE_Y
);
5327 WINED3D_TO_STR(CHANNEL_SOURCE_Z
);
5328 WINED3D_TO_STR(CHANNEL_SOURCE_W
);
5329 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0
);
5330 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1
);
5331 #undef WINED3D_TO_STR
5333 FIXME("Unrecognized fixup_channel_source %#x\n", source
);
5334 return "unrecognized";
5338 static const char *debug_complex_fixup(enum complex_fixup fixup
)
5342 #define WINED3D_TO_STR(x) case x: return #x
5343 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2
);
5344 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY
);
5345 WINED3D_TO_STR(COMPLEX_FIXUP_YV12
);
5346 WINED3D_TO_STR(COMPLEX_FIXUP_NV12
);
5347 WINED3D_TO_STR(COMPLEX_FIXUP_P8
);
5348 WINED3D_TO_STR(COMPLEX_FIXUP_YUV
);
5349 #undef WINED3D_TO_STR
5351 FIXME("Unrecognized complex fixup %#x\n", fixup
);
5352 return "unrecognized";
5356 void dump_color_fixup_desc(struct color_fixup_desc fixup
)
5358 if (is_complex_fixup(fixup
))
5360 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup
)));
5364 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup
.x_source
), fixup
.x_sign_fixup
? ", SIGN_FIXUP" : "");
5365 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup
.y_source
), fixup
.y_sign_fixup
? ", SIGN_FIXUP" : "");
5366 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup
.z_source
), fixup
.z_sign_fixup
? ", SIGN_FIXUP" : "");
5367 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup
.w_source
), fixup
.w_sign_fixup
? ", SIGN_FIXUP" : "");
5370 BOOL
is_invalid_op(const struct wined3d_state
*state
, int stage
,
5371 enum wined3d_texture_op op
, DWORD arg1
, DWORD arg2
, DWORD arg3
)
5373 if (op
== WINED3D_TOP_DISABLE
)
5375 if (state
->textures
[stage
])
5378 if ((arg1
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
5379 && op
!= WINED3D_TOP_SELECT_ARG2
)
5381 if ((arg2
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
5382 && op
!= WINED3D_TOP_SELECT_ARG1
)
5384 if ((arg3
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
5385 && (op
== WINED3D_TOP_MULTIPLY_ADD
|| op
== WINED3D_TOP_LERP
))
5391 void get_identity_matrix(struct wined3d_matrix
*mat
)
5393 static const struct wined3d_matrix identity
=
5395 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5396 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5397 0.0f
, 0.0f
, 1.0f
, 0.0f
,
5398 0.0f
, 0.0f
, 0.0f
, 1.0f
,
5404 void get_modelview_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5405 unsigned int index
, struct wined3d_matrix
*mat
)
5407 if (context
->last_was_rhw
)
5408 get_identity_matrix(mat
);
5410 multiply_matrix(mat
, &state
->transforms
[WINED3D_TS_VIEW
], &state
->transforms
[WINED3D_TS_WORLD_MATRIX(index
)]);
5413 void get_projection_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5414 struct wined3d_matrix
*mat
)
5416 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
5417 BOOL clip_control
, flip
;
5418 float center_offset
;
5420 /* There are a couple of additional things we have to take into account
5421 * here besides the projection transformation itself:
5422 * - We need to flip along the y-axis in case of offscreen rendering.
5423 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
5424 * - <= D3D9 coordinates refer to pixel centers while GL coordinates
5425 * refer to pixel corners.
5426 * - D3D has a top-left filling convention. We need to maintain this
5427 * even after the y-flip mentioned above.
5428 * In order to handle the last two points, we translate by
5429 * (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to
5430 * translating slightly less than half a pixel. We want the difference to
5431 * be large enough that it doesn't get lost due to rounding inside the
5432 * driver, but small enough to prevent it from interfering with any
5435 clip_control
= d3d_info
->clip_control
;
5436 flip
= !clip_control
&& context
->render_offscreen
;
5437 if (!clip_control
&& d3d_info
->wined3d_creation_flags
& WINED3D_PIXEL_CENTER_INTEGER
)
5438 center_offset
= 63.0f
/ 64.0f
;
5440 center_offset
= -1.0f
/ 64.0f
;
5442 if (context
->last_was_rhw
)
5444 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
5445 float x
= state
->viewports
[0].x
;
5446 float y
= state
->viewports
[0].y
;
5447 float w
= state
->viewports
[0].width
;
5448 float h
= state
->viewports
[0].height
;
5449 float x_scale
= 2.0f
/ w
;
5450 float x_offset
= (center_offset
- (2.0f
* x
) - w
) / w
;
5451 float y_scale
= flip
? 2.0f
/ h
: 2.0f
/ -h
;
5452 float y_offset
= flip
5453 ? (center_offset
- (2.0f
* y
) - h
) / h
5454 : (center_offset
- (2.0f
* y
) - h
) / -h
;
5455 bool zenable
= state
->fb
.depth_stencil
?
5456 (state
->depth_stencil_state
? state
->depth_stencil_state
->desc
.depth
: true) : false;
5457 float z_scale
= zenable
? clip_control
? 1.0f
: 2.0f
: 0.0f
;
5458 float z_offset
= zenable
? clip_control
? 0.0f
: -1.0f
: 0.0f
;
5459 const struct wined3d_matrix projection
=
5461 x_scale
, 0.0f
, 0.0f
, 0.0f
,
5462 0.0f
, y_scale
, 0.0f
, 0.0f
,
5463 0.0f
, 0.0f
, z_scale
, 0.0f
,
5464 x_offset
, y_offset
, z_offset
, 1.0f
,
5471 float y_scale
= flip
? -1.0f
: 1.0f
;
5472 float x_offset
= center_offset
/ state
->viewports
[0].width
;
5473 float y_offset
= flip
5474 ? center_offset
/ state
->viewports
[0].height
5475 : -center_offset
/ state
->viewports
[0].height
;
5476 float z_scale
= clip_control
? 1.0f
: 2.0f
;
5477 float z_offset
= clip_control
? 0.0f
: -1.0f
;
5478 const struct wined3d_matrix projection
=
5480 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5481 0.0f
, y_scale
, 0.0f
, 0.0f
,
5482 0.0f
, 0.0f
, z_scale
, 0.0f
,
5483 x_offset
, y_offset
, z_offset
, 1.0f
,
5486 multiply_matrix(mat
, &projection
, &state
->transforms
[WINED3D_TS_PROJECTION
]);
5490 /* Setup this textures matrix according to the texture flags. */
5491 static void compute_texture_matrix(const struct wined3d_matrix
*matrix
, uint32_t flags
, BOOL calculated_coords
,
5492 BOOL transformed
, enum wined3d_format_id format_id
, BOOL ffp_proj_control
, struct wined3d_matrix
*out_matrix
)
5494 struct wined3d_matrix mat
;
5496 if (flags
== WINED3D_TTFF_DISABLE
|| flags
== WINED3D_TTFF_COUNT1
|| transformed
)
5498 get_identity_matrix(out_matrix
);
5502 if (flags
== (WINED3D_TTFF_COUNT1
| WINED3D_TTFF_PROJECTED
))
5504 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
5510 if (flags
& WINED3D_TTFF_PROJECTED
)
5512 if (!ffp_proj_control
)
5514 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
5516 case WINED3D_TTFF_COUNT2
:
5521 mat
._12
= mat
._22
= mat
._32
= mat
._42
= 0.0f
;
5523 case WINED3D_TTFF_COUNT3
:
5528 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
5535 /* Under Direct3D the R/Z coord can be used for translation, under
5536 * OpenGL we use the Q coord instead. */
5537 if (!calculated_coords
)
5541 /* Direct3D passes the default 1.0 in the 2nd coord, while GL
5542 * passes it in the 4th. Swap 2nd and 4th coord. No need to
5543 * store the value of mat._41 in mat._21 because the input
5544 * value to the transformation will be 0, so the matrix value
5546 case WINED3DFMT_R32_FLOAT
:
5552 /* See above, just 3rd and 4th coord. */
5553 case WINED3DFMT_R32G32_FLOAT
:
5559 case WINED3DFMT_R32G32B32_FLOAT
: /* Opengl defaults match dx defaults */
5560 case WINED3DFMT_R32G32B32A32_FLOAT
: /* No defaults apply, all app defined */
5562 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
5563 * into a bad place. The division elimination below will apply to make sure the
5564 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
5566 case WINED3DFMT_UNKNOWN
: /* No texture coords, 0/0/0/1 defaults are passed */
5569 FIXME("Unexpected fixed function texture coord input\n");
5572 if (!ffp_proj_control
)
5574 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
5576 /* case WINED3D_TTFF_COUNT1: Won't ever get here. */
5577 case WINED3D_TTFF_COUNT2
:
5578 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
5579 /* OpenGL divides the first 3 vertex coordinates by the 4th by
5580 * default, which is essentially the same as D3DTTFF_PROJECTED.
5581 * Make sure that the 4th coordinate evaluates to 1.0 to
5584 * If the fixed function pipeline is used, the 4th value
5585 * remains unused, so there is no danger in doing this. With
5586 * vertex shaders we have a problem. Should an application hit
5587 * that problem, the code here would have to check for pixel
5588 * shaders, and the shader has to undo the default GL divide.
5590 * A more serious problem occurs if the application passes 4
5591 * coordinates in, and the 4th is != 1.0 (OpenGL default).
5592 * This would have to be fixed with immediate mode draws. */
5594 mat
._14
= mat
._24
= mat
._34
= 0.0f
; mat
._44
= 1.0f
;
5602 void get_texture_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5603 unsigned int tex
, struct wined3d_matrix
*mat
)
5605 const struct wined3d_device
*device
= context
->device
;
5606 BOOL generated
= (state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
] & 0xffff0000)
5607 != WINED3DTSS_TCI_PASSTHRU
;
5608 unsigned int coord_idx
= min(state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
& 0x0000ffff],
5609 WINED3D_MAX_TEXTURES
- 1);
5611 compute_texture_matrix(&state
->transforms
[WINED3D_TS_TEXTURE0
+ tex
],
5612 state
->texture_states
[tex
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
],
5613 generated
, context
->last_was_rhw
,
5614 context
->stream_info
.use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))
5615 ? context
->stream_info
.elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format
->id
5616 : WINED3DFMT_UNKNOWN
,
5617 device
->shader_backend
->shader_has_ffp_proj_control(device
->shader_priv
), mat
);
5619 if ((context
->lastWasPow2Texture
& (1u << tex
)) && state
->textures
[tex
])
5622 FIXME("Non-power-of-two texture being used with generated texture coords.\n");
5623 /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
5624 * fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
5627 TRACE("Non-power-of-two texture matrix multiply fixup.\n");
5628 multiply_matrix(mat
, mat
, (struct wined3d_matrix
*)state
->textures
[tex
]->pow2_matrix
);
5633 void get_pointsize_minmax(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5634 float *out_min
, float *out_max
)
5642 min
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MIN
];
5643 max
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MAX
];
5652 void get_pointsize(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5653 float *out_pointsize
, float *out_att
)
5655 /* POINTSCALEENABLE controls how point size value is treated. If set to
5656 * true, the point size is scaled with respect to height of viewport.
5657 * When set to false point size is in pixels. */
5662 } pointsize
, a
, b
, c
;
5668 pointsize
.d
= state
->render_states
[WINED3D_RS_POINTSIZE
];
5669 a
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_A
];
5670 b
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_B
];
5671 c
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_C
];
5673 /* Always use first viewport, this path does not apply to d3d10/11 multiple viewports case. */
5674 if (state
->render_states
[WINED3D_RS_POINTSCALEENABLE
])
5676 float scale_factor
= state
->viewports
[0].height
* state
->viewports
[0].height
;
5678 out_att
[0] = a
.f
/ scale_factor
;
5679 out_att
[1] = b
.f
/ scale_factor
;
5680 out_att
[2] = c
.f
/ scale_factor
;
5682 *out_pointsize
= pointsize
.f
;
5685 void get_fog_start_end(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5686 float *start
, float *end
)
5694 switch (context
->fog_source
)
5701 case FOGSOURCE_COORD
:
5707 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGSTART
];
5708 *start
= tmpvalue
.f
;
5709 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGEND
];
5711 /* Special handling for fog_start == fog_end. In d3d with vertex
5712 * fog, everything is fogged. With table fog, everything with
5713 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
5714 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
5715 if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
&& *start
== *end
)
5723 /* This should not happen, context->fog_source is set in wined3d, not the app. */
5724 ERR("Unexpected fog coordinate source.\n");
5730 static BOOL
wined3d_get_primary_display(WCHAR
*display
)
5732 DISPLAY_DEVICEW display_device
;
5733 DWORD device_idx
= 0;
5735 display_device
.cb
= sizeof(display_device
);
5736 while (EnumDisplayDevicesW(NULL
, device_idx
++, &display_device
, 0))
5738 if (display_device
.StateFlags
& DISPLAY_DEVICE_PRIMARY_DEVICE
)
5740 lstrcpyW(display
, display_device
.DeviceName
);
5748 BOOL
wined3d_get_primary_adapter_luid(LUID
*luid
)
5750 D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME open_adapter_param
;
5751 D3DKMT_CLOSEADAPTER close_adapter_param
;
5753 if (!wined3d_get_primary_display(open_adapter_param
.DeviceName
))
5756 if (D3DKMTOpenAdapterFromGdiDisplayName(&open_adapter_param
))
5759 *luid
= open_adapter_param
.AdapterLuid
;
5760 close_adapter_param
.hAdapter
= open_adapter_param
.hAdapter
;
5761 D3DKMTCloseAdapter(&close_adapter_param
);
5765 /* Note: It's the caller's responsibility to ensure values can be expressed
5766 * in the requested format. UNORM formats for example can only express values
5767 * in the range 0.0f -> 1.0f. */
5768 DWORD
wined3d_format_convert_from_float(const struct wined3d_format
*format
, const struct wined3d_color
*color
)
5772 enum wined3d_format_id format_id
;
5773 struct wined3d_vec4 mul
;
5774 struct wined3d_uvec4 shift
;
5778 {WINED3DFMT_B8G8R8A8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, {16, 8, 0, 24}},
5779 {WINED3DFMT_B8G8R8X8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, {16, 8, 0, 24}},
5780 {WINED3DFMT_B8G8R8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, {16, 8, 0, 24}},
5781 {WINED3DFMT_B5G6R5_UNORM
, { 31.0f
, 63.0f
, 31.0f
, 0.0f
}, {11, 5, 0, 0}},
5782 {WINED3DFMT_B5G5R5A1_UNORM
, { 31.0f
, 31.0f
, 31.0f
, 1.0f
}, {10, 5, 0, 15}},
5783 {WINED3DFMT_B5G5R5X1_UNORM
, { 31.0f
, 31.0f
, 31.0f
, 1.0f
}, {10, 5, 0, 15}},
5784 {WINED3DFMT_R8_UNORM
, { 255.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
5785 {WINED3DFMT_A8_UNORM
, { 0.0f
, 0.0f
, 0.0f
, 255.0f
}, { 0, 0, 0, 0}},
5786 {WINED3DFMT_B4G4R4A4_UNORM
, { 15.0f
, 15.0f
, 15.0f
, 15.0f
}, { 8, 4, 0, 12}},
5787 {WINED3DFMT_B4G4R4X4_UNORM
, { 15.0f
, 15.0f
, 15.0f
, 15.0f
}, { 8, 4, 0, 12}},
5788 {WINED3DFMT_B2G3R3_UNORM
, { 7.0f
, 7.0f
, 3.0f
, 0.0f
}, { 5, 2, 0, 0}},
5789 {WINED3DFMT_R8G8B8A8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, { 0, 8, 16, 24}},
5790 {WINED3DFMT_R8G8B8X8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, { 0, 8, 16, 24}},
5791 {WINED3DFMT_B10G10R10A2_UNORM
, { 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
}, {20, 10, 0, 30}},
5792 {WINED3DFMT_R10G10B10A2_UNORM
, { 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
}, { 0, 10, 20, 30}},
5793 {WINED3DFMT_P8_UINT
, { 0.0f
, 0.0f
, 0.0f
, 255.0f
}, { 0, 0, 0, 0}},
5794 {WINED3DFMT_S1_UINT_D15_UNORM
, { 32767.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
5795 {WINED3DFMT_D16_UNORM
, { 65535.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
5799 enum wined3d_format_id format_id
;
5800 struct wined3d_dvec4 mul
;
5801 struct wined3d_uvec4 shift
;
5805 {WINED3DFMT_D24_UNORM_S8_UINT
, { 16777215.0, 1.0, 0.0, 0.0}, {8, 0, 0, 0}},
5806 {WINED3DFMT_X8D24_UNORM
, { 16777215.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
5807 {WINED3DFMT_D32_UNORM
, {4294967295.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
5809 enum wined3d_format_id format_id
= format
->id
;
5810 struct wined3d_color colour_srgb
;
5814 TRACE("Converting colour %s to format %s.\n", debug_color(color
), debug_d3dformat(format_id
));
5816 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
5818 if (format_id
!= format_srgb_info
[i
].srgb_format_id
)
5821 wined3d_colour_srgb_from_linear(&colour_srgb
, color
);
5822 format_id
= format_srgb_info
[i
].base_format_id
;
5823 color
= &colour_srgb
;
5827 for (i
= 0; i
< ARRAY_SIZE(float_conv
); ++i
)
5829 if (format_id
!= float_conv
[i
].format_id
)
5832 ret
= ((DWORD
)((color
->r
* float_conv
[i
].mul
.x
) + 0.5f
)) << float_conv
[i
].shift
.x
;
5833 ret
|= ((DWORD
)((color
->g
* float_conv
[i
].mul
.y
) + 0.5f
)) << float_conv
[i
].shift
.y
;
5834 ret
|= ((DWORD
)((color
->b
* float_conv
[i
].mul
.z
) + 0.5f
)) << float_conv
[i
].shift
.z
;
5835 ret
|= ((DWORD
)((color
->a
* float_conv
[i
].mul
.w
) + 0.5f
)) << float_conv
[i
].shift
.w
;
5837 TRACE("Returning 0x%08x.\n", ret
);
5842 for (i
= 0; i
< ARRAY_SIZE(double_conv
); ++i
)
5844 if (format_id
!= double_conv
[i
].format_id
)
5847 ret
= ((DWORD
)((color
->r
* double_conv
[i
].mul
.x
) + 0.5)) << double_conv
[i
].shift
.x
;
5848 ret
|= ((DWORD
)((color
->g
* double_conv
[i
].mul
.y
) + 0.5)) << double_conv
[i
].shift
.y
;
5849 ret
|= ((DWORD
)((color
->b
* double_conv
[i
].mul
.z
) + 0.5)) << double_conv
[i
].shift
.z
;
5850 ret
|= ((DWORD
)((color
->a
* double_conv
[i
].mul
.w
) + 0.5)) << double_conv
[i
].shift
.w
;
5852 TRACE("Returning 0x%08x.\n", ret
);
5857 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format_id
));
5862 static float color_to_float(DWORD color
, DWORD size
, DWORD offset
)
5864 DWORD mask
= size
< 32 ? (1u << size
) - 1 : ~0u;
5872 return (float)color
/ (float)mask
;
5875 void wined3d_format_get_float_color_key(const struct wined3d_format
*format
,
5876 const struct wined3d_color_key
*key
, struct wined3d_color
*float_colors
)
5878 struct wined3d_color slop
;
5882 case WINED3DFMT_B8G8R8_UNORM
:
5883 case WINED3DFMT_B8G8R8A8_UNORM
:
5884 case WINED3DFMT_B8G8R8X8_UNORM
:
5885 case WINED3DFMT_B5G6R5_UNORM
:
5886 case WINED3DFMT_B5G5R5X1_UNORM
:
5887 case WINED3DFMT_B5G5R5A1_UNORM
:
5888 case WINED3DFMT_B4G4R4A4_UNORM
:
5889 case WINED3DFMT_B2G3R3_UNORM
:
5890 case WINED3DFMT_R8_UNORM
:
5891 case WINED3DFMT_A8_UNORM
:
5892 case WINED3DFMT_B2G3R3A8_UNORM
:
5893 case WINED3DFMT_B4G4R4X4_UNORM
:
5894 case WINED3DFMT_R10G10B10A2_UNORM
:
5895 case WINED3DFMT_R10G10B10A2_SNORM
:
5896 case WINED3DFMT_R8G8B8A8_UNORM
:
5897 case WINED3DFMT_R8G8B8X8_UNORM
:
5898 case WINED3DFMT_R16G16_UNORM
:
5899 case WINED3DFMT_B10G10R10A2_UNORM
:
5900 slop
.r
= 0.5f
/ ((1u << format
->red_size
) - 1);
5901 slop
.g
= 0.5f
/ ((1u << format
->green_size
) - 1);
5902 slop
.b
= 0.5f
/ ((1u << format
->blue_size
) - 1);
5903 slop
.a
= 0.5f
/ ((1u << format
->alpha_size
) - 1);
5905 float_colors
[0].r
= color_to_float(key
->color_space_low_value
, format
->red_size
, format
->red_offset
)
5907 float_colors
[0].g
= color_to_float(key
->color_space_low_value
, format
->green_size
, format
->green_offset
)
5909 float_colors
[0].b
= color_to_float(key
->color_space_low_value
, format
->blue_size
, format
->blue_offset
)
5911 float_colors
[0].a
= color_to_float(key
->color_space_low_value
, format
->alpha_size
, format
->alpha_offset
)
5914 float_colors
[1].r
= color_to_float(key
->color_space_high_value
, format
->red_size
, format
->red_offset
)
5916 float_colors
[1].g
= color_to_float(key
->color_space_high_value
, format
->green_size
, format
->green_offset
)
5918 float_colors
[1].b
= color_to_float(key
->color_space_high_value
, format
->blue_size
, format
->blue_offset
)
5920 float_colors
[1].a
= color_to_float(key
->color_space_high_value
, format
->alpha_size
, format
->alpha_offset
)
5924 case WINED3DFMT_P8_UINT
:
5925 float_colors
[0].r
= 0.0f
;
5926 float_colors
[0].g
= 0.0f
;
5927 float_colors
[0].b
= 0.0f
;
5928 float_colors
[0].a
= (key
->color_space_low_value
- 0.5f
) / 255.0f
;
5930 float_colors
[1].r
= 0.0f
;
5931 float_colors
[1].g
= 0.0f
;
5932 float_colors
[1].b
= 0.0f
;
5933 float_colors
[1].a
= (key
->color_space_high_value
+ 0.5f
) / 255.0f
;
5937 ERR("Unhandled color key to float conversion for format %s.\n", debug_d3dformat(format
->id
));
5941 enum wined3d_format_id
pixelformat_for_depth(DWORD depth
)
5945 case 8: return WINED3DFMT_P8_UINT
;
5946 case 15: return WINED3DFMT_B5G5R5X1_UNORM
;
5947 case 16: return WINED3DFMT_B5G6R5_UNORM
;
5948 case 24: return WINED3DFMT_B8G8R8X8_UNORM
; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
5949 case 32: return WINED3DFMT_B8G8R8X8_UNORM
; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
5950 default: return WINED3DFMT_UNKNOWN
;
5954 void wined3d_format_copy_data(const struct wined3d_format
*format
, const uint8_t *src
,
5955 unsigned int src_row_pitch
, unsigned int src_slice_pitch
, uint8_t *dst
, unsigned int dst_row_pitch
,
5956 unsigned int dst_slice_pitch
, unsigned int w
, unsigned int h
, unsigned int d
)
5958 unsigned int row_block_count
, row_count
, row_size
, slice
, row
;
5959 unsigned int slice_count
= d
;
5960 const uint8_t *src_row
;
5963 row_block_count
= (w
+ format
->block_width
- 1) / format
->block_width
;
5964 row_count
= (h
+ format
->block_height
- 1) / format
->block_height
;
5965 row_size
= row_block_count
* format
->block_byte_count
;
5967 if (src_row_pitch
== row_size
&& dst_row_pitch
== row_size
&& src_slice_pitch
== dst_slice_pitch
)
5969 memcpy(dst
, src
, slice_count
* row_count
* row_size
);
5973 for (slice
= 0; slice
< slice_count
; ++slice
)
5975 for (row
= 0; row
< row_count
; ++row
)
5977 src_row
= &src
[slice
* src_slice_pitch
+ row
* src_row_pitch
];
5978 dst_row
= &dst
[slice
* dst_slice_pitch
+ row
* dst_row_pitch
];
5979 memcpy(dst_row
, src_row
, row_size
);
5984 void multiply_matrix(struct wined3d_matrix
*dst
, const struct wined3d_matrix
*src1
, const struct wined3d_matrix
*src2
)
5986 struct wined3d_matrix tmp
;
5988 /* Now do the multiplication 'by hand'.
5989 I know that all this could be optimised, but this will be done later :-) */
5990 tmp
._11
= (src1
->_11
* src2
->_11
) + (src1
->_21
* src2
->_12
) + (src1
->_31
* src2
->_13
) + (src1
->_41
* src2
->_14
);
5991 tmp
._21
= (src1
->_11
* src2
->_21
) + (src1
->_21
* src2
->_22
) + (src1
->_31
* src2
->_23
) + (src1
->_41
* src2
->_24
);
5992 tmp
._31
= (src1
->_11
* src2
->_31
) + (src1
->_21
* src2
->_32
) + (src1
->_31
* src2
->_33
) + (src1
->_41
* src2
->_34
);
5993 tmp
._41
= (src1
->_11
* src2
->_41
) + (src1
->_21
* src2
->_42
) + (src1
->_31
* src2
->_43
) + (src1
->_41
* src2
->_44
);
5995 tmp
._12
= (src1
->_12
* src2
->_11
) + (src1
->_22
* src2
->_12
) + (src1
->_32
* src2
->_13
) + (src1
->_42
* src2
->_14
);
5996 tmp
._22
= (src1
->_12
* src2
->_21
) + (src1
->_22
* src2
->_22
) + (src1
->_32
* src2
->_23
) + (src1
->_42
* src2
->_24
);
5997 tmp
._32
= (src1
->_12
* src2
->_31
) + (src1
->_22
* src2
->_32
) + (src1
->_32
* src2
->_33
) + (src1
->_42
* src2
->_34
);
5998 tmp
._42
= (src1
->_12
* src2
->_41
) + (src1
->_22
* src2
->_42
) + (src1
->_32
* src2
->_43
) + (src1
->_42
* src2
->_44
);
6000 tmp
._13
= (src1
->_13
* src2
->_11
) + (src1
->_23
* src2
->_12
) + (src1
->_33
* src2
->_13
) + (src1
->_43
* src2
->_14
);
6001 tmp
._23
= (src1
->_13
* src2
->_21
) + (src1
->_23
* src2
->_22
) + (src1
->_33
* src2
->_23
) + (src1
->_43
* src2
->_24
);
6002 tmp
._33
= (src1
->_13
* src2
->_31
) + (src1
->_23
* src2
->_32
) + (src1
->_33
* src2
->_33
) + (src1
->_43
* src2
->_34
);
6003 tmp
._43
= (src1
->_13
* src2
->_41
) + (src1
->_23
* src2
->_42
) + (src1
->_33
* src2
->_43
) + (src1
->_43
* src2
->_44
);
6005 tmp
._14
= (src1
->_14
* src2
->_11
) + (src1
->_24
* src2
->_12
) + (src1
->_34
* src2
->_13
) + (src1
->_44
* src2
->_14
);
6006 tmp
._24
= (src1
->_14
* src2
->_21
) + (src1
->_24
* src2
->_22
) + (src1
->_34
* src2
->_23
) + (src1
->_44
* src2
->_24
);
6007 tmp
._34
= (src1
->_14
* src2
->_31
) + (src1
->_24
* src2
->_32
) + (src1
->_34
* src2
->_33
) + (src1
->_44
* src2
->_34
);
6008 tmp
._44
= (src1
->_14
* src2
->_41
) + (src1
->_24
* src2
->_42
) + (src1
->_34
* src2
->_43
) + (src1
->_44
* src2
->_44
);
6013 void gen_ffp_frag_op(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
6014 struct ffp_frag_settings
*settings
, BOOL ignore_textype
)
6019 static const unsigned char args
[WINED3D_TOP_LERP
+ 1] =
6022 /* D3DTOP_DISABLE */ 0,
6023 /* D3DTOP_SELECTARG1 */ ARG1
,
6024 /* D3DTOP_SELECTARG2 */ ARG2
,
6025 /* D3DTOP_MODULATE */ ARG1
| ARG2
,
6026 /* D3DTOP_MODULATE2X */ ARG1
| ARG2
,
6027 /* D3DTOP_MODULATE4X */ ARG1
| ARG2
,
6028 /* D3DTOP_ADD */ ARG1
| ARG2
,
6029 /* D3DTOP_ADDSIGNED */ ARG1
| ARG2
,
6030 /* D3DTOP_ADDSIGNED2X */ ARG1
| ARG2
,
6031 /* D3DTOP_SUBTRACT */ ARG1
| ARG2
,
6032 /* D3DTOP_ADDSMOOTH */ ARG1
| ARG2
,
6033 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1
| ARG2
,
6034 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1
| ARG2
,
6035 /* D3DTOP_BLENDFACTORALPHA */ ARG1
| ARG2
,
6036 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1
| ARG2
,
6037 /* D3DTOP_BLENDCURRENTALPHA */ ARG1
| ARG2
,
6038 /* D3DTOP_PREMODULATE */ ARG1
| ARG2
,
6039 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1
| ARG2
,
6040 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1
| ARG2
,
6041 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1
| ARG2
,
6042 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1
| ARG2
,
6043 /* D3DTOP_BUMPENVMAP */ ARG1
| ARG2
,
6044 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1
| ARG2
,
6045 /* D3DTOP_DOTPRODUCT3 */ ARG1
| ARG2
,
6046 /* D3DTOP_MULTIPLYADD */ ARG1
| ARG2
| ARG0
,
6047 /* D3DTOP_LERP */ ARG1
| ARG2
| ARG0
6051 DWORD cop
, aop
, carg0
, carg1
, carg2
, aarg0
, aarg1
, aarg2
;
6052 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
6054 settings
->padding
= 0;
6056 for (i
= 0; i
< d3d_info
->limits
.ffp_blend_stages
; ++i
)
6058 struct wined3d_texture
*texture
;
6060 settings
->op
[i
].padding
= 0;
6061 if (state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
] == WINED3D_TOP_DISABLE
)
6063 settings
->op
[i
].cop
= WINED3D_TOP_DISABLE
;
6064 settings
->op
[i
].aop
= WINED3D_TOP_DISABLE
;
6065 settings
->op
[i
].carg0
= settings
->op
[i
].carg1
= settings
->op
[i
].carg2
= ARG_UNUSED
;
6066 settings
->op
[i
].aarg0
= settings
->op
[i
].aarg1
= settings
->op
[i
].aarg2
= ARG_UNUSED
;
6067 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
6068 settings
->op
[i
].tmp_dst
= 0;
6069 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6070 settings
->op
[i
].projected
= WINED3D_PROJECTION_NONE
;
6075 if ((texture
= state
->textures
[i
]))
6077 if (can_use_texture_swizzle(d3d_info
, texture
->resource
.format
))
6078 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
6080 settings
->op
[i
].color_fixup
= texture
->resource
.format
->color_fixup
;
6083 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6087 switch (wined3d_texture_gl(texture
)->target
)
6090 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6093 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_2D
;
6096 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_3D
;
6098 case GL_TEXTURE_CUBE_MAP_ARB
:
6099 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_CUBE
;
6101 case GL_TEXTURE_RECTANGLE_ARB
:
6102 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_RECT
;
6107 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
6108 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6111 cop
= state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
];
6112 aop
= state
->texture_states
[i
][WINED3D_TSS_ALPHA_OP
];
6114 carg1
= (args
[cop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG1
] : ARG_UNUSED
;
6115 carg2
= (args
[cop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG2
] : ARG_UNUSED
;
6116 carg0
= (args
[cop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG0
] : ARG_UNUSED
;
6118 if (is_invalid_op(state
, i
, cop
, carg1
, carg2
, carg0
))
6122 carg1
= WINED3DTA_CURRENT
;
6123 cop
= WINED3D_TOP_SELECT_ARG1
;
6126 if (cop
== WINED3D_TOP_DOTPRODUCT3
)
6128 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
6129 * the color result to the alpha component of the destination
6138 aarg1
= (args
[aop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG1
] : ARG_UNUSED
;
6139 aarg2
= (args
[aop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG2
] : ARG_UNUSED
;
6140 aarg0
= (args
[aop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG0
] : ARG_UNUSED
;
6143 if (!i
&& state
->textures
[0] && state
->render_states
[WINED3D_RS_COLORKEYENABLE
])
6145 GLenum texture_dimensions
;
6147 texture
= state
->textures
[0];
6148 texture_dimensions
= wined3d_texture_gl(texture
)->target
;
6150 if (texture_dimensions
== GL_TEXTURE_2D
|| texture_dimensions
== GL_TEXTURE_RECTANGLE_ARB
)
6152 if (texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
&& !texture
->resource
.format
->alpha_size
)
6154 if (aop
== WINED3D_TOP_DISABLE
)
6156 aarg1
= WINED3DTA_TEXTURE
;
6157 aop
= WINED3D_TOP_SELECT_ARG1
;
6159 else if (aop
== WINED3D_TOP_SELECT_ARG1
&& aarg1
!= WINED3DTA_TEXTURE
)
6161 if (state
->blend_state
&& state
->blend_state
->desc
.rt
[0].enable
)
6163 aarg2
= WINED3DTA_TEXTURE
;
6164 aop
= WINED3D_TOP_MODULATE
;
6166 else aarg1
= WINED3DTA_TEXTURE
;
6168 else if (aop
== WINED3D_TOP_SELECT_ARG2
&& aarg2
!= WINED3DTA_TEXTURE
)
6170 if (state
->blend_state
&& state
->blend_state
->desc
.rt
[0].enable
)
6172 aarg1
= WINED3DTA_TEXTURE
;
6173 aop
= WINED3D_TOP_MODULATE
;
6175 else aarg2
= WINED3DTA_TEXTURE
;
6181 if (is_invalid_op(state
, i
, aop
, aarg1
, aarg2
, aarg0
))
6185 aarg1
= WINED3DTA_CURRENT
;
6186 aop
= WINED3D_TOP_SELECT_ARG1
;
6189 if (carg1
== WINED3DTA_TEXTURE
|| carg2
== WINED3DTA_TEXTURE
|| carg0
== WINED3DTA_TEXTURE
6190 || aarg1
== WINED3DTA_TEXTURE
|| aarg2
== WINED3DTA_TEXTURE
|| aarg0
== WINED3DTA_TEXTURE
)
6192 ttff
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
6193 if (ttff
== (WINED3D_TTFF_PROJECTED
| WINED3D_TTFF_COUNT3
))
6194 settings
->op
[i
].projected
= WINED3D_PROJECTION_COUNT3
;
6195 else if (ttff
& WINED3D_TTFF_PROJECTED
)
6196 settings
->op
[i
].projected
= WINED3D_PROJECTION_COUNT4
;
6198 settings
->op
[i
].projected
= WINED3D_PROJECTION_NONE
;
6202 settings
->op
[i
].projected
= WINED3D_PROJECTION_NONE
;
6205 settings
->op
[i
].cop
= cop
;
6206 settings
->op
[i
].aop
= aop
;
6207 settings
->op
[i
].carg0
= carg0
;
6208 settings
->op
[i
].carg1
= carg1
;
6209 settings
->op
[i
].carg2
= carg2
;
6210 settings
->op
[i
].aarg0
= aarg0
;
6211 settings
->op
[i
].aarg1
= aarg1
;
6212 settings
->op
[i
].aarg2
= aarg2
;
6213 settings
->op
[i
].tmp_dst
= state
->texture_states
[i
][WINED3D_TSS_RESULT_ARG
] == WINED3DTA_TEMP
;
6216 /* Clear unsupported stages */
6217 for(; i
< WINED3D_MAX_TEXTURES
; i
++) {
6218 memset(&settings
->op
[i
], 0xff, sizeof(settings
->op
[i
]));
6221 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6223 settings
->fog
= WINED3D_FFP_PS_FOG_OFF
;
6225 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
)
6227 if (use_vs(state
) || state
->vertex_declaration
->position_transformed
)
6229 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
6233 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
6235 case WINED3D_FOG_NONE
:
6236 case WINED3D_FOG_LINEAR
:
6237 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
6239 case WINED3D_FOG_EXP
:
6240 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
6242 case WINED3D_FOG_EXP2
:
6243 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
6250 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
6252 case WINED3D_FOG_LINEAR
:
6253 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
6255 case WINED3D_FOG_EXP
:
6256 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
6258 case WINED3D_FOG_EXP2
:
6259 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
6263 settings
->sRGB_write
= !d3d_info
->srgb_write_control
&& needs_srgb_write(d3d_info
, state
, &state
->fb
);
6264 if (d3d_info
->vs_clipping
|| !use_vs(state
) || !state
->render_states
[WINED3D_RS_CLIPPING
]
6265 || !state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
])
6267 /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
6268 * the fixed function vertex pipeline is used(which always supports clipplanes), or
6269 * if no clipplane is enabled
6271 settings
->emul_clipplanes
= 0;
6273 settings
->emul_clipplanes
= 1;
6276 if (state
->render_states
[WINED3D_RS_COLORKEYENABLE
] && state
->textures
[0]
6277 && state
->textures
[0]->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
6278 && settings
->op
[0].cop
!= WINED3D_TOP_DISABLE
)
6279 settings
->color_key_enabled
= 1;
6281 settings
->color_key_enabled
= 0;
6283 /* texcoords_initialized is set to meaningful values only when GL doesn't
6284 * support enough varyings to always pass around all the possible texture
6286 * This is used to avoid reading a varying not written by the vertex shader.
6287 * Reading uninitialized varyings on core profile contexts results in an
6288 * error while with builtin varyings on legacy contexts you get undefined
6290 if (d3d_info
->limits
.varying_count
&& !d3d_info
->full_ffp_varyings
)
6292 settings
->texcoords_initialized
= 0;
6293 for (i
= 0; i
< WINED3D_MAX_TEXTURES
; ++i
)
6297 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
6298 settings
->texcoords_initialized
|= 1u << i
;
6302 const struct wined3d_stream_info
*si
= &context
->stream_info
;
6303 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6304 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
6305 & WINED3D_FFP_TCI_MASK
6306 || (coord_idx
< WINED3D_MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
6307 settings
->texcoords_initialized
|= 1u << i
;
6313 settings
->texcoords_initialized
= (1u << WINED3D_MAX_TEXTURES
) - 1;
6316 settings
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
6317 && state
->primitive_type
== WINED3D_PT_POINTLIST
;
6319 if (d3d_info
->ffp_alpha_test
)
6320 settings
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
6322 settings
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
6323 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
6324 : WINED3D_CMP_ALWAYS
) - 1;
6326 if (d3d_info
->emulated_flatshading
)
6327 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6329 settings
->flatshading
= FALSE
;
6332 const struct ffp_frag_desc
*find_ffp_frag_shader(const struct wine_rb_tree
*fragment_shaders
,
6333 const struct ffp_frag_settings
*settings
)
6335 struct wine_rb_entry
*entry
= wine_rb_get(fragment_shaders
, settings
);
6336 return entry
? WINE_RB_ENTRY_VALUE(entry
, struct ffp_frag_desc
, entry
) : NULL
;
6339 void add_ffp_frag_shader(struct wine_rb_tree
*shaders
, struct ffp_frag_desc
*desc
)
6341 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
6342 * whereas desc points to an extended structure with implementation specific parts. */
6343 if (wine_rb_put(shaders
, &desc
->settings
, &desc
->entry
) == -1)
6345 ERR("Failed to insert ffp frag shader.\n");
6349 /* Activates the texture dimension according to the bound D3D texture. Does
6350 * not care for the colorop or correct gl texture unit (when using nvrc).
6351 * Requires the caller to activate the correct unit. */
6352 /* Context activation is done by the caller (state handler). */
6353 void texture_activate_dimensions(struct wined3d_texture
*texture
, const struct wined3d_gl_info
*gl_info
)
6357 switch (wined3d_texture_gl(texture
)->target
)
6360 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
6361 checkGLcall("glDisable(GL_TEXTURE_3D)");
6362 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
6364 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
6365 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6367 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
6369 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
6370 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6372 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
6373 checkGLcall("glEnable(GL_TEXTURE_2D)");
6375 case GL_TEXTURE_RECTANGLE_ARB
:
6376 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
6377 checkGLcall("glDisable(GL_TEXTURE_2D)");
6378 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
6379 checkGLcall("glDisable(GL_TEXTURE_3D)");
6380 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
6382 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
6383 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6385 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_RECTANGLE_ARB
);
6386 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
6389 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
6391 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
6392 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6394 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
6396 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
6397 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6399 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
6400 checkGLcall("glDisable(GL_TEXTURE_2D)");
6401 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_3D
);
6402 checkGLcall("glEnable(GL_TEXTURE_3D)");
6404 case GL_TEXTURE_CUBE_MAP_ARB
:
6405 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
6406 checkGLcall("glDisable(GL_TEXTURE_2D)");
6407 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
6408 checkGLcall("glDisable(GL_TEXTURE_3D)");
6409 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
6411 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
6412 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6414 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
6415 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
6421 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
6422 checkGLcall("glEnable(GL_TEXTURE_2D)");
6423 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
6424 checkGLcall("glDisable(GL_TEXTURE_3D)");
6425 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
6427 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
6428 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6430 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
6432 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
6433 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6435 /* Binding textures is done by samplers. A dummy texture will be bound */
6439 /* Context activation is done by the caller (state handler). */
6440 void sampler_texdim(struct wined3d_context
*context
, const struct wined3d_state
*state
, DWORD state_id
)
6442 struct wined3d_context_gl
*context_gl
= wined3d_context_gl(context
);
6443 unsigned int sampler
= state_id
- STATE_SAMPLER(0);
6444 unsigned int mapped_stage
;
6446 /* No need to enable / disable anything here for unused samplers. The
6447 * tex_colorop handler takes care. Also no action is needed with pixel
6448 * shaders, or if tex_colorop will take care of this business. */
6449 mapped_stage
= context_gl
->tex_unit_map
[sampler
];
6450 if (mapped_stage
== WINED3D_UNMAPPED_STAGE
|| mapped_stage
>= context_gl
->gl_info
->limits
.textures
)
6452 if (sampler
>= context
->lowest_disabled_stage
)
6454 if (isStateDirty(context
, STATE_TEXTURESTAGE(sampler
, WINED3D_TSS_COLOR_OP
)))
6457 texture_activate_dimensions(state
->textures
[sampler
], context_gl
->gl_info
);
6460 int wined3d_ffp_frag_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
6462 const struct ffp_frag_settings
*ka
= key
;
6463 const struct ffp_frag_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
, const struct ffp_frag_desc
, entry
)->settings
;
6465 return memcmp(ka
, kb
, sizeof(*ka
));
6468 void wined3d_ffp_get_vs_settings(const struct wined3d_context
*context
,
6469 const struct wined3d_state
*state
, struct wined3d_ffp_vs_settings
*settings
)
6471 enum wined3d_material_color_source diffuse_source
, emissive_source
, ambient_source
, specular_source
;
6472 const struct wined3d_stream_info
*si
= &context
->stream_info
;
6473 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
6474 unsigned int coord_idx
, i
;
6476 memset(settings
, 0, sizeof(*settings
));
6478 if (si
->position_transformed
)
6480 settings
->transformed
= 1;
6481 settings
->point_size
= state
->primitive_type
== WINED3D_PT_POINTLIST
;
6482 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
6483 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6484 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
6485 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
6486 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6488 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
6490 for (i
= 0; i
< WINED3D_MAX_TEXTURES
; ++i
)
6492 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6493 if (coord_idx
< WINED3D_MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
6494 settings
->texcoords
|= 1u << i
;
6495 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6497 if (d3d_info
->full_ffp_varyings
)
6498 settings
->texcoords
= (1u << WINED3D_MAX_TEXTURES
) - 1;
6500 if (d3d_info
->emulated_flatshading
)
6501 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6503 settings
->flatshading
= FALSE
;
6505 settings
->swizzle_map
= si
->swizzle_map
;
6510 switch (state
->render_states
[WINED3D_RS_VERTEXBLEND
])
6512 case WINED3D_VBF_DISABLE
:
6513 case WINED3D_VBF_1WEIGHTS
:
6514 case WINED3D_VBF_2WEIGHTS
:
6515 case WINED3D_VBF_3WEIGHTS
:
6516 settings
->vertexblends
= state
->render_states
[WINED3D_RS_VERTEXBLEND
];
6519 FIXME("Unsupported vertex blending: %d\n", state
->render_states
[WINED3D_RS_VERTEXBLEND
]);
6523 settings
->clipping
= state
->render_states
[WINED3D_RS_CLIPPING
]
6524 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
6525 settings
->normal
= !!(si
->use_map
& (1u << WINED3D_FFP_NORMAL
));
6526 settings
->normalize
= settings
->normal
&& state
->render_states
[WINED3D_RS_NORMALIZENORMALS
];
6527 settings
->lighting
= !!state
->render_states
[WINED3D_RS_LIGHTING
];
6528 settings
->localviewer
= !!state
->render_states
[WINED3D_RS_LOCALVIEWER
];
6529 settings
->point_size
= state
->primitive_type
== WINED3D_PT_POINTLIST
;
6530 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
6532 wined3d_get_material_colour_source(&diffuse_source
, &emissive_source
,
6533 &ambient_source
, &specular_source
, state
, si
);
6534 settings
->diffuse_source
= diffuse_source
;
6535 settings
->emissive_source
= emissive_source
;
6536 settings
->ambient_source
= ambient_source
;
6537 settings
->specular_source
= specular_source
;
6539 for (i
= 0; i
< WINED3D_MAX_TEXTURES
; ++i
)
6541 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6542 if (coord_idx
< WINED3D_MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
6543 settings
->texcoords
|= 1u << i
;
6544 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6546 if (d3d_info
->full_ffp_varyings
)
6547 settings
->texcoords
= (1u << WINED3D_MAX_TEXTURES
) - 1;
6549 for (i
= 0; i
< WINED3D_MAX_ACTIVE_LIGHTS
; ++i
)
6551 if (!state
->light_state
.lights
[i
])
6554 switch (state
->light_state
.lights
[i
]->OriginalParms
.type
)
6556 case WINED3D_LIGHT_POINT
:
6557 ++settings
->point_light_count
;
6559 case WINED3D_LIGHT_SPOT
:
6560 ++settings
->spot_light_count
;
6562 case WINED3D_LIGHT_DIRECTIONAL
:
6563 ++settings
->directional_light_count
;
6565 case WINED3D_LIGHT_PARALLELPOINT
:
6566 ++settings
->parallel_point_light_count
;
6569 FIXME("Unhandled light type %#x.\n", state
->light_state
.lights
[i
]->OriginalParms
.type
);
6574 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6575 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
6576 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
6578 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6580 if (state
->transforms
[WINED3D_TS_PROJECTION
]._14
== 0.0f
6581 && state
->transforms
[WINED3D_TS_PROJECTION
]._24
== 0.0f
6582 && state
->transforms
[WINED3D_TS_PROJECTION
]._34
== 0.0f
6583 && state
->transforms
[WINED3D_TS_PROJECTION
]._44
== 1.0f
)
6584 settings
->ortho_fog
= 1;
6586 else if (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
] == WINED3D_FOG_NONE
)
6587 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
6588 else if (state
->render_states
[WINED3D_RS_RANGEFOGENABLE
])
6589 settings
->fog_mode
= WINED3D_FFP_VS_FOG_RANGE
;
6591 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6593 if (d3d_info
->emulated_flatshading
)
6594 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6596 settings
->flatshading
= FALSE
;
6598 settings
->swizzle_map
= si
->swizzle_map
;
6601 int wined3d_ffp_vertex_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
6603 const struct wined3d_ffp_vs_settings
*ka
= key
;
6604 const struct wined3d_ffp_vs_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
,
6605 const struct wined3d_ffp_vs_desc
, entry
)->settings
;
6607 return memcmp(ka
, kb
, sizeof(*ka
));
6610 const char *wined3d_debug_location(DWORD location
)
6612 struct debug_buffer buffer
;
6613 const char *prefix
= "";
6614 const char *suffix
= "";
6616 if (wined3d_popcount(location
) > 16)
6619 location
= ~location
;
6623 init_debug_buffer(&buffer
, "0");
6624 #define LOCATION_TO_STR(x) if (location & x) { debug_append(&buffer, #x, " | "); location &= ~x; }
6625 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED
);
6626 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM
);
6627 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER
);
6628 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB
);
6629 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB
);
6630 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE
);
6631 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE
);
6632 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED
);
6633 #undef LOCATION_TO_STR
6635 FIXME("Unrecognized location flag(s) %#x.\n", location
);
6637 return wine_dbg_sprintf("%s%s%s", prefix
, buffer
.str
, suffix
);
6640 const char *wined3d_debug_feature_level(enum wined3d_feature_level level
)
6644 #define LEVEL_TO_STR(level) case level: return #level
6645 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_5
);
6646 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_6
);
6647 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_7
);
6648 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_8
);
6649 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_1
);
6650 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_2
);
6651 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_3
);
6652 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_10
);
6653 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_10_1
);
6654 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_11
);
6655 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_11_1
);
6658 return wine_dbg_sprintf("%#x", level
);
6662 /* Print a floating point value with the %.8e format specifier, always using
6663 * '.' as decimal separator. */
6664 void wined3d_ftoa(float value
, char *s
)
6668 if (copysignf(1.0f
, value
) < 0.0f
)
6671 /* Be sure to allocate a buffer of at least 17 characters for the result
6672 as sprintf may return a 3 digit exponent when using the MSVC runtime
6673 instead of a 2 digit exponent. */
6674 sprintf(s
, "%.8e", value
);
6675 if (isfinite(value
))
6679 void wined3d_release_dc(HWND window
, HDC dc
)
6681 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
6682 * However, that's not what actually happens, and there are user32 tests
6683 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
6684 * So explicitly check that the DC belongs to the window, since we want to
6685 * avoid releasing a DC that belongs to some other window if the original
6686 * window was already destroyed. */
6687 if (WindowFromDC(dc
) != window
)
6688 WARN("DC %p does not belong to window %p.\n", dc
, window
);
6689 else if (!ReleaseDC(window
, dc
))
6690 ERR("Failed to release device context %p, last error %#x.\n", dc
, GetLastError());
6693 BOOL
wined3d_clip_blit(const RECT
*clip_rect
, RECT
*clipped
, RECT
*other
)
6695 RECT orig
= *clipped
;
6696 float scale_x
= (float)(orig
.right
- orig
.left
) / (float)(other
->right
- other
->left
);
6697 float scale_y
= (float)(orig
.bottom
- orig
.top
) / (float)(other
->bottom
- other
->top
);
6699 IntersectRect(clipped
, clipped
, clip_rect
);
6701 if (IsRectEmpty(clipped
))
6703 SetRectEmpty(other
);
6707 other
->left
+= (LONG
)((clipped
->left
- orig
.left
) / scale_x
);
6708 other
->top
+= (LONG
)((clipped
->top
- orig
.top
) / scale_y
);
6709 other
->right
-= (LONG
)((orig
.right
- clipped
->right
) / scale_x
);
6710 other
->bottom
-= (LONG
)((orig
.bottom
- clipped
->bottom
) / scale_y
);
6715 void wined3d_gl_limits_get_uniform_block_range(const struct wined3d_gl_limits
*gl_limits
,
6716 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
6721 for (i
= 0; i
< WINED3D_SHADER_TYPE_COUNT
; ++i
)
6723 *count
= gl_limits
->uniform_blocks
[i
];
6724 if (i
== shader_type
)
6729 ERR("Unrecognized shader type %#x.\n", shader_type
);
6733 void wined3d_gl_limits_get_texture_unit_range(const struct wined3d_gl_limits
*gl_limits
,
6734 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
6738 if (shader_type
== WINED3D_SHADER_TYPE_COMPUTE
)
6740 if (gl_limits
->combined_samplers
== gl_limits
->graphics_samplers
)
6743 *base
= gl_limits
->graphics_samplers
;
6744 *count
= gl_limits
->samplers
[WINED3D_SHADER_TYPE_COMPUTE
];
6749 for (i
= 0; i
< WINED3D_SHADER_TYPE_GRAPHICS_COUNT
; ++i
)
6751 *count
= gl_limits
->samplers
[i
];
6752 if (i
== shader_type
)
6757 ERR("Unrecognized shader type %#x.\n", shader_type
);
6761 BOOL
wined3d_array_reserve(void **elements
, SIZE_T
*capacity
, SIZE_T count
, SIZE_T size
)
6763 SIZE_T max_capacity
, new_capacity
;
6766 if (count
<= *capacity
)
6769 max_capacity
= ~(SIZE_T
)0 / size
;
6770 if (count
> max_capacity
)
6773 new_capacity
= max(1, *capacity
);
6774 while (new_capacity
< count
&& new_capacity
<= max_capacity
/ 2)
6776 if (new_capacity
< count
)
6777 new_capacity
= count
;
6780 new_elements
= heap_alloc_zero(new_capacity
* size
);
6782 new_elements
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, *elements
, new_capacity
* size
);
6786 *elements
= new_elements
;
6787 *capacity
= new_capacity
;
6791 static void swap_rows(float **a
, float **b
)
6799 BOOL
invert_matrix(struct wined3d_matrix
*out
, const struct wined3d_matrix
*m
)
6802 float m0
, m1
, m2
, m3
, s
;
6803 float *r0
, *r1
, *r2
, *r3
;
6815 r0
[5] = r0
[6] = r0
[7] = 0.0f
;
6822 r1
[4] = r1
[6] = r1
[7] = 0.0f
;
6829 r2
[4] = r2
[5] = r2
[7] = 0.0f
;
6836 r3
[4] = r3
[5] = r3
[6] = 0.0f
;
6838 /* Choose pivot - or die. */
6839 if (fabsf(r3
[0]) > fabsf(r2
[0]))
6840 swap_rows(&r3
, &r2
);
6841 if (fabsf(r2
[0]) > fabsf(r1
[0]))
6842 swap_rows(&r2
, &r1
);
6843 if (fabsf(r1
[0]) > fabsf(r0
[0]))
6844 swap_rows(&r1
, &r0
);
6848 /* Eliminate first variable. */
6849 m1
= r1
[0] / r0
[0]; m2
= r2
[0] / r0
[0]; m3
= r3
[0] / r0
[0];
6850 s
= r0
[1]; r1
[1] -= m1
* s
; r2
[1] -= m2
* s
; r3
[1] -= m3
* s
;
6851 s
= r0
[2]; r1
[2] -= m1
* s
; r2
[2] -= m2
* s
; r3
[2] -= m3
* s
;
6852 s
= r0
[3]; r1
[3] -= m1
* s
; r2
[3] -= m2
* s
; r3
[3] -= m3
* s
;
6882 /* Choose pivot - or die. */
6883 if (fabsf(r3
[1]) > fabsf(r2
[1]))
6884 swap_rows(&r3
, &r2
);
6885 if (fabsf(r2
[1]) > fabsf(r1
[1]))
6886 swap_rows(&r2
, &r1
);
6890 /* Eliminate second variable. */
6891 m2
= r2
[1] / r1
[1]; m3
= r3
[1] / r1
[1];
6892 r2
[2] -= m2
* r1
[2]; r3
[2] -= m3
* r1
[2];
6893 r2
[3] -= m2
* r1
[3]; r3
[3] -= m3
* r1
[3];
6919 /* Choose pivot - or die. */
6920 if (fabsf(r3
[2]) > fabsf(r2
[2]))
6921 swap_rows(&r3
, &r2
);
6925 /* Eliminate third variable. */
6927 r3
[3] -= m3
* r2
[3];
6928 r3
[4] -= m3
* r2
[4];
6929 r3
[5] -= m3
* r2
[5];
6930 r3
[6] -= m3
* r2
[6];
6931 r3
[7] -= m3
* r2
[7];
6937 /* Back substitute row 3. */
6944 /* Back substitute row 2. */
6947 r2
[4] = s
* (r2
[4] - r3
[4] * m2
);
6948 r2
[5] = s
* (r2
[5] - r3
[5] * m2
);
6949 r2
[6] = s
* (r2
[6] - r3
[6] * m2
);
6950 r2
[7] = s
* (r2
[7] - r3
[7] * m2
);
6952 r1
[4] -= r3
[4] * m1
;
6953 r1
[5] -= r3
[5] * m1
;
6954 r1
[6] -= r3
[6] * m1
;
6955 r1
[7] -= r3
[7] * m1
;
6957 r0
[4] -= r3
[4] * m0
;
6958 r0
[5] -= r3
[5] * m0
;
6959 r0
[6] -= r3
[6] * m0
;
6960 r0
[7] -= r3
[7] * m0
;
6962 /* Back substitute row 1. */
6965 r1
[4] = s
* (r1
[4] - r2
[4] * m1
);
6966 r1
[5] = s
* (r1
[5] - r2
[5] * m1
);
6967 r1
[6] = s
* (r1
[6] - r2
[6] * m1
);
6968 r1
[7] = s
* (r1
[7] - r2
[7] * m1
);
6970 r0
[4] -= r2
[4] * m0
;
6971 r0
[5] -= r2
[5] * m0
;
6972 r0
[6] -= r2
[6] * m0
;
6973 r0
[7] -= r2
[7] * m0
;
6975 /* Back substitute row 0. */
6978 r0
[4] = s
* (r0
[4] - r1
[4] * m0
);
6979 r0
[5] = s
* (r0
[5] - r1
[5] * m0
);
6980 r0
[6] = s
* (r0
[6] - r1
[6] * m0
);
6981 r0
[7] = s
* (r0
[7] - r1
[7] * m0
);
7003 /* Taken and adapted from Mesa. */
7004 static BOOL
invert_matrix_3d(struct wined3d_matrix
*out
, const struct wined3d_matrix
*in
)
7006 float pos
, neg
, t
, det
;
7007 struct wined3d_matrix temp
;
7009 /* Calculate the determinant of upper left 3x3 submatrix and
7010 * determine if the matrix is singular. */
7012 t
= in
->_11
* in
->_22
* in
->_33
;
7018 t
= in
->_21
* in
->_32
* in
->_13
;
7023 t
= in
->_31
* in
->_12
* in
->_23
;
7029 t
= -in
->_31
* in
->_22
* in
->_13
;
7034 t
= -in
->_21
* in
->_12
* in
->_33
;
7040 t
= -in
->_11
* in
->_32
* in
->_23
;
7048 if (fabsf(det
) < 1e-25f
)
7052 temp
._11
= (in
->_22
* in
->_33
- in
->_32
* in
->_23
) * det
;
7053 temp
._12
= -(in
->_12
* in
->_33
- in
->_32
* in
->_13
) * det
;
7054 temp
._13
= (in
->_12
* in
->_23
- in
->_22
* in
->_13
) * det
;
7055 temp
._21
= -(in
->_21
* in
->_33
- in
->_31
* in
->_23
) * det
;
7056 temp
._22
= (in
->_11
* in
->_33
- in
->_31
* in
->_13
) * det
;
7057 temp
._23
= -(in
->_11
* in
->_23
- in
->_21
* in
->_13
) * det
;
7058 temp
._31
= (in
->_21
* in
->_32
- in
->_31
* in
->_22
) * det
;
7059 temp
._32
= -(in
->_11
* in
->_32
- in
->_31
* in
->_12
) * det
;
7060 temp
._33
= (in
->_11
* in
->_22
- in
->_21
* in
->_12
) * det
;
7066 void compute_normal_matrix(float *normal_matrix
, BOOL legacy_lighting
,
7067 const struct wined3d_matrix
*modelview
)
7069 struct wined3d_matrix mv
;
7073 if (legacy_lighting
)
7074 invert_matrix_3d(&mv
, &mv
);
7076 invert_matrix(&mv
, &mv
);
7077 /* Tests show that singular modelview matrices are used unchanged as normal
7078 * matrices on D3D3 and older. There seems to be no clearly consistent
7079 * behavior on newer D3D versions so always follow older ddraw behavior. */
7080 for (i
= 0; i
< 3; ++i
)
7081 for (j
= 0; j
< 3; ++j
)
7082 normal_matrix
[i
* 3 + j
] = (&mv
._11
)[j
* 4 + i
];
7085 static void wined3d_allocator_release_block(struct wined3d_allocator
*allocator
,
7086 struct wined3d_allocator_block
*block
)
7088 block
->parent
= allocator
->free
;
7089 allocator
->free
= block
;
7092 static struct wined3d_allocator_block
*wined3d_allocator_acquire_block(struct wined3d_allocator
*allocator
)
7094 struct wined3d_allocator_block
*block
;
7096 if (!allocator
->free
)
7097 return heap_alloc(sizeof(*block
));
7099 block
= allocator
->free
;
7100 allocator
->free
= block
->parent
;
7105 void wined3d_allocator_block_free(struct wined3d_allocator_block
*block
)
7107 struct wined3d_allocator
*allocator
= block
->chunk
->allocator
;
7108 struct wined3d_allocator_block
*parent
;
7110 while ((parent
= block
->parent
) && block
->sibling
->free
)
7112 list_remove(&block
->sibling
->entry
);
7113 wined3d_allocator_release_block(allocator
, block
->sibling
);
7114 wined3d_allocator_release_block(allocator
, block
);
7119 list_add_head(&block
->chunk
->available
[block
->order
], &block
->entry
);
7122 static void wined3d_allocator_block_init(struct wined3d_allocator_block
*block
,
7123 struct wined3d_allocator_chunk
*chunk
, struct wined3d_allocator_block
*parent
,
7124 struct wined3d_allocator_block
*sibling
, unsigned int order
, size_t offset
, bool free
)
7126 list_init(&block
->entry
);
7127 block
->chunk
= chunk
;
7128 block
->parent
= parent
;
7129 block
->sibling
= sibling
;
7130 block
->order
= order
;
7131 block
->offset
= offset
;
7135 void wined3d_allocator_chunk_cleanup(struct wined3d_allocator_chunk
*chunk
)
7137 struct wined3d_allocator_block
*block
;
7140 if (list_empty(&chunk
->available
[0]))
7142 ERR("Chunk %p is not empty.\n", chunk
);
7146 for (i
= 1; i
< ARRAY_SIZE(chunk
->available
); ++i
)
7148 if (!list_empty(&chunk
->available
[i
]))
7150 ERR("Chunk %p is not empty.\n", chunk
);
7155 block
= LIST_ENTRY(list_head(&chunk
->available
[0]), struct wined3d_allocator_block
, entry
);
7156 wined3d_allocator_release_block(chunk
->allocator
, block
);
7159 bool wined3d_allocator_chunk_init(struct wined3d_allocator_chunk
*chunk
, struct wined3d_allocator
*allocator
)
7161 struct wined3d_allocator_block
*block
;
7164 if (!(block
= wined3d_allocator_acquire_block(allocator
)))
7166 wined3d_allocator_block_init(block
, chunk
, NULL
, NULL
, 0, 0, true);
7168 list_init(&chunk
->entry
);
7169 for (i
= 0; i
< ARRAY_SIZE(chunk
->available
); ++i
)
7171 list_init(&chunk
->available
[i
]);
7173 list_add_head(&chunk
->available
[0], &block
->entry
);
7174 chunk
->allocator
= allocator
;
7175 chunk
->map_count
= 0;
7176 chunk
->map_ptr
= NULL
;
7181 void wined3d_allocator_cleanup(struct wined3d_allocator
*allocator
)
7183 struct wined3d_allocator_chunk
*chunk
, *chunk2
;
7184 struct wined3d_allocator_block
*block
, *next
;
7187 for (i
= 0; i
< allocator
->pool_count
; ++i
)
7189 LIST_FOR_EACH_ENTRY_SAFE(chunk
, chunk2
, &allocator
->pools
[i
].chunks
, struct wined3d_allocator_chunk
, entry
)
7191 list_remove(&chunk
->entry
);
7192 allocator
->ops
->allocator_destroy_chunk(chunk
);
7195 heap_free(allocator
->pools
);
7197 next
= allocator
->free
;
7198 while ((block
= next
))
7200 next
= block
->parent
;
7205 static struct wined3d_allocator_block
*wined3d_allocator_chunk_allocate(struct wined3d_allocator_chunk
*chunk
,
7208 struct wined3d_allocator_block
*block
, *left
, *right
;
7209 unsigned int i
= order
;
7213 if (!list_empty(&chunk
->available
[i
]))
7218 if (list_empty(&chunk
->available
[i
]))
7221 block
= LIST_ENTRY(list_head(&chunk
->available
[i
]), struct wined3d_allocator_block
, entry
);
7222 list_remove(&block
->entry
);
7223 block
->free
= false;
7227 if (!(left
= wined3d_allocator_acquire_block(chunk
->allocator
)))
7229 ERR("Failed to allocate left.\n");
7233 if (!(right
= wined3d_allocator_acquire_block(chunk
->allocator
)))
7235 ERR("Failed to allocate right.\n");
7236 wined3d_allocator_release_block(chunk
->allocator
, left
);
7240 wined3d_allocator_block_init(left
, chunk
, block
, right
, block
->order
+ 1, block
->offset
, false);
7241 wined3d_allocator_block_init(right
, chunk
, block
, left
, block
->order
+ 1,
7242 block
->offset
+ (WINED3D_ALLOCATOR_CHUNK_SIZE
>> left
->order
), true);
7243 list_add_head(&chunk
->available
[right
->order
], &right
->entry
);
7252 struct wined3d_allocator_block
*wined3d_allocator_allocate(struct wined3d_allocator
*allocator
,
7253 struct wined3d_context
*context
, unsigned int memory_type
, size_t size
)
7255 struct wined3d_allocator_chunk
*chunk
;
7256 struct wined3d_allocator_block
*block
;
7259 if (size
> WINED3D_ALLOCATOR_CHUNK_SIZE
/ 2)
7262 if (size
< WINED3D_ALLOCATOR_MIN_BLOCK_SIZE
)
7263 order
= WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT
- 1;
7265 order
= wined3d_log2i(WINED3D_ALLOCATOR_CHUNK_SIZE
/ size
);
7267 LIST_FOR_EACH_ENTRY(chunk
, &allocator
->pools
[memory_type
].chunks
, struct wined3d_allocator_chunk
, entry
)
7269 if ((block
= wined3d_allocator_chunk_allocate(chunk
, order
)))
7273 if (!(chunk
= allocator
->ops
->allocator_create_chunk(allocator
,
7274 context
, memory_type
, WINED3D_ALLOCATOR_CHUNK_SIZE
)))
7277 if (!(block
= wined3d_allocator_chunk_allocate(chunk
, order
)))
7283 bool wined3d_allocator_init(struct wined3d_allocator
*allocator
,
7284 size_t pool_count
, const struct wined3d_allocator_ops
*allocator_ops
)
7288 allocator
->ops
= allocator_ops
;
7289 allocator
->pool_count
= pool_count
;
7290 if (!(allocator
->pools
= heap_calloc(pool_count
, sizeof(*allocator
->pools
))))
7292 for (i
= 0; i
< pool_count
; ++i
)
7294 list_init(&allocator
->pools
[i
].chunks
);