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
31 #include "wined3d_private.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
35 #define WINED3D_FORMAT_FOURCC_BASE (WINED3DFMT_BC7_UNORM_SRGB + 1)
39 enum wined3d_format_id id
;
42 format_index_remap
[] =
44 {WINED3DFMT_UYVY
, WINED3D_FORMAT_FOURCC_BASE
},
45 {WINED3DFMT_YUY2
, WINED3D_FORMAT_FOURCC_BASE
+ 1},
46 {WINED3DFMT_YV12
, WINED3D_FORMAT_FOURCC_BASE
+ 2},
47 {WINED3DFMT_DXT1
, WINED3D_FORMAT_FOURCC_BASE
+ 3},
48 {WINED3DFMT_DXT2
, WINED3D_FORMAT_FOURCC_BASE
+ 4},
49 {WINED3DFMT_DXT3
, WINED3D_FORMAT_FOURCC_BASE
+ 5},
50 {WINED3DFMT_DXT4
, WINED3D_FORMAT_FOURCC_BASE
+ 6},
51 {WINED3DFMT_DXT5
, WINED3D_FORMAT_FOURCC_BASE
+ 7},
52 {WINED3DFMT_MULTI2_ARGB8
, WINED3D_FORMAT_FOURCC_BASE
+ 8},
53 {WINED3DFMT_G8R8_G8B8
, WINED3D_FORMAT_FOURCC_BASE
+ 9},
54 {WINED3DFMT_R8G8_B8G8
, WINED3D_FORMAT_FOURCC_BASE
+ 10},
55 {WINED3DFMT_ATI1N
, WINED3D_FORMAT_FOURCC_BASE
+ 11},
56 {WINED3DFMT_ATI2N
, WINED3D_FORMAT_FOURCC_BASE
+ 12},
57 {WINED3DFMT_INST
, WINED3D_FORMAT_FOURCC_BASE
+ 13},
58 {WINED3DFMT_NVDB
, WINED3D_FORMAT_FOURCC_BASE
+ 14},
59 {WINED3DFMT_NVHU
, WINED3D_FORMAT_FOURCC_BASE
+ 15},
60 {WINED3DFMT_NVHS
, WINED3D_FORMAT_FOURCC_BASE
+ 16},
61 {WINED3DFMT_INTZ
, WINED3D_FORMAT_FOURCC_BASE
+ 17},
62 {WINED3DFMT_RESZ
, WINED3D_FORMAT_FOURCC_BASE
+ 18},
63 {WINED3DFMT_NULL
, WINED3D_FORMAT_FOURCC_BASE
+ 19},
64 {WINED3DFMT_R16
, WINED3D_FORMAT_FOURCC_BASE
+ 20},
65 {WINED3DFMT_AL16
, WINED3D_FORMAT_FOURCC_BASE
+ 21},
66 {WINED3DFMT_NV12
, WINED3D_FORMAT_FOURCC_BASE
+ 22},
67 {WINED3DFMT_ATOC
, WINED3D_FORMAT_FOURCC_BASE
+ 23},
70 #define WINED3D_FORMAT_COUNT (WINED3D_FORMAT_FOURCC_BASE + ARRAY_SIZE(format_index_remap))
72 struct wined3d_format_channels
74 enum wined3d_format_id id
;
75 DWORD red_size
, green_size
, blue_size
, alpha_size
;
76 DWORD red_offset
, green_offset
, blue_offset
, alpha_offset
;
78 BYTE depth_size
, stencil_size
;
81 static const struct wined3d_format_channels formats
[] =
84 * format id r g b a r g b a bpp depth stencil */
85 {WINED3DFMT_UNKNOWN
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
87 {WINED3DFMT_UYVY
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
88 {WINED3DFMT_YUY2
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
89 {WINED3DFMT_YV12
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
90 {WINED3DFMT_NV12
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
91 {WINED3DFMT_DXT1
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
92 {WINED3DFMT_DXT2
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
93 {WINED3DFMT_DXT3
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
94 {WINED3DFMT_DXT4
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
95 {WINED3DFMT_DXT5
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
96 {WINED3DFMT_MULTI2_ARGB8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
97 {WINED3DFMT_G8R8_G8B8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
98 {WINED3DFMT_R8G8_B8G8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
100 {WINED3DFMT_R8G8_SNORM_Cx
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
101 {WINED3DFMT_R11G11B10_FLOAT
, 11, 11, 10, 0, 0, 11, 22, 0, 4, 0, 0},
102 /* Palettized formats */
103 {WINED3DFMT_P8_UINT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
104 {WINED3DFMT_P8_UINT
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
105 /* Standard ARGB formats. */
106 {WINED3DFMT_B8G8R8_UNORM
, 8, 8, 8, 0, 16, 8, 0, 0, 3, 0, 0},
107 {WINED3DFMT_B5G6R5_UNORM
, 5, 6, 5, 0, 11, 5, 0, 0, 2, 0, 0},
108 {WINED3DFMT_B5G5R5X1_UNORM
, 5, 5, 5, 0, 10, 5, 0, 0, 2, 0, 0},
109 {WINED3DFMT_B5G5R5A1_UNORM
, 5, 5, 5, 1, 10, 5, 0, 15, 2, 0, 0},
110 {WINED3DFMT_B4G4R4A4_UNORM
, 4, 4, 4, 4, 8, 4, 0, 12, 2, 0, 0},
111 {WINED3DFMT_B2G3R3_UNORM
, 3, 3, 2, 0, 5, 2, 0, 0, 1, 0, 0},
112 {WINED3DFMT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0},
113 {WINED3DFMT_B2G3R3A8_UNORM
, 3, 3, 2, 8, 5, 2, 0, 8, 2, 0, 0},
114 {WINED3DFMT_B4G4R4X4_UNORM
, 4, 4, 4, 0, 8, 4, 0, 0, 2, 0, 0},
115 {WINED3DFMT_R8G8B8X8_UNORM
, 8, 8, 8, 0, 0, 8, 16, 0, 4, 0, 0},
116 {WINED3DFMT_B10G10R10A2_UNORM
, 10, 10, 10, 2, 20, 10, 0, 30, 4, 0, 0},
118 {WINED3DFMT_L8_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
119 {WINED3DFMT_L8A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
120 {WINED3DFMT_L4A4_UNORM
, 0, 0, 0, 4, 0, 0, 0, 4, 1, 0, 0},
121 {WINED3DFMT_L16_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
122 /* Bump mapping stuff */
123 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, 5, 5, 0, 0, 0, 5, 0, 0, 2, 0, 0},
124 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, 8, 8, 0, 0, 0, 8, 0, 0, 4, 0, 0},
125 {WINED3DFMT_R10G11B11_SNORM
, 10, 11, 11, 0, 0, 10, 21, 0, 4, 0, 0},
126 {WINED3DFMT_R10G10B10_SNORM_A2_UNORM
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
127 /* Depth stencil formats */
128 {WINED3DFMT_D16_LOCKABLE
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
129 {WINED3DFMT_D32_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
130 {WINED3DFMT_S1_UINT_D15_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 15, 1},
131 {WINED3DFMT_X8D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 0},
132 {WINED3DFMT_S4X4_UINT_D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 4},
133 {WINED3DFMT_S8_UINT_D24_FLOAT
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
134 /* Vendor-specific formats */
135 {WINED3DFMT_ATI1N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
136 {WINED3DFMT_ATI2N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
137 {WINED3DFMT_NVDB
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
138 {WINED3DFMT_ATOC
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
139 {WINED3DFMT_INST
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
140 {WINED3DFMT_INTZ
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
141 {WINED3DFMT_RESZ
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
142 {WINED3DFMT_NVHU
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
143 {WINED3DFMT_NVHS
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
144 {WINED3DFMT_NULL
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
145 /* Unsure about them, could not find a Windows driver that supports them */
146 {WINED3DFMT_R16
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
147 {WINED3DFMT_AL16
, 0, 0, 0, 16, 0, 0, 0, 16, 4, 0, 0},
148 /* DirectX 10 HDR formats */
149 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
151 {WINED3DFMT_R32G32B32A32_TYPELESS
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
152 {WINED3DFMT_R32G32B32_TYPELESS
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
153 {WINED3DFMT_R16G16B16A16_TYPELESS
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
154 {WINED3DFMT_R32G32_TYPELESS
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
155 {WINED3DFMT_R32G8X24_TYPELESS
, 32, 8, 0, 0, 0, 0, 0, 0, 8, 0, 0},
156 {WINED3DFMT_R10G10B10A2_TYPELESS
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
157 {WINED3DFMT_R10G10B10X2_TYPELESS
, 10, 10, 10, 0, 0, 10, 20, 0, 4, 0, 0},
158 {WINED3DFMT_R8G8B8A8_TYPELESS
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
159 {WINED3DFMT_R16G16_TYPELESS
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
160 {WINED3DFMT_R32_TYPELESS
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
161 {WINED3DFMT_R24G8_TYPELESS
, 24, 8, 0, 0, 0, 0, 0, 0, 4, 0, 0},
162 {WINED3DFMT_R8G8_TYPELESS
, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
163 {WINED3DFMT_R16_TYPELESS
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
164 {WINED3DFMT_R8_TYPELESS
, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
165 {WINED3DFMT_BC1_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
166 {WINED3DFMT_BC2_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
167 {WINED3DFMT_BC3_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
168 {WINED3DFMT_BC4_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
169 {WINED3DFMT_BC5_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
170 {WINED3DFMT_BC6H_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
171 {WINED3DFMT_BC7_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
172 {WINED3DFMT_B8G8R8A8_TYPELESS
, 8, 8, 8, 8, 16, 8, 0, 24, 4, 0, 0},
173 {WINED3DFMT_B8G8R8X8_TYPELESS
, 8, 8, 8, 0, 16, 8, 0, 0, 4, 0, 0},
176 struct wined3d_typed_format_info
178 enum wined3d_format_id id
;
179 enum wined3d_format_id typeless_id
;
180 const char *channels
;
184 * The last entry for a given typeless format defines its internal format.
186 * u - WINED3D_CHANNEL_TYPE_UNORM
187 * i - WINED3D_CHANNEL_TYPE_SNORM
188 * U - WINED3D_CHANNEL_TYPE_UINT
189 * I - WINED3D_CHANNEL_TYPE_SINT
190 * F - WINED3D_CHANNEL_TYPE_FLOAT
191 * D - WINED3D_CHANNEL_TYPE_DEPTH
192 * S - WINED3D_CHANNEL_TYPE_STENCIL
193 * X - WINED3D_CHANNEL_TYPE_UNUSED
195 static const struct wined3d_typed_format_info typed_formats
[] =
197 {WINED3DFMT_R32G32B32A32_UINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "UUUU"},
198 {WINED3DFMT_R32G32B32A32_SINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "IIII"},
199 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "FFFF"},
200 {WINED3DFMT_R32G32B32_UINT
, WINED3DFMT_R32G32B32_TYPELESS
, "UUU"},
201 {WINED3DFMT_R32G32B32_SINT
, WINED3DFMT_R32G32B32_TYPELESS
, "III"},
202 {WINED3DFMT_R32G32B32_FLOAT
, WINED3DFMT_R32G32B32_TYPELESS
, "FFF"},
203 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "uuuu"},
204 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "iiii"},
205 {WINED3DFMT_R16G16B16A16_UINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "UUUU"},
206 {WINED3DFMT_R16G16B16A16_SINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "IIII"},
207 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "FFFF"},
208 {WINED3DFMT_R32G32_UINT
, WINED3DFMT_R32G32_TYPELESS
, "UU"},
209 {WINED3DFMT_R32G32_SINT
, WINED3DFMT_R32G32_TYPELESS
, "II"},
210 {WINED3DFMT_R32G32_FLOAT
, WINED3DFMT_R32G32_TYPELESS
, "FF"},
211 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, WINED3DFMT_R32G8X24_TYPELESS
, "FXX"},
212 {WINED3DFMT_X32_TYPELESS_G8X24_UINT
, WINED3DFMT_R32G8X24_TYPELESS
, "XUX"},
213 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, WINED3DFMT_R32G8X24_TYPELESS
, "DSX"},
214 {WINED3DFMT_R10G10B10A2_SNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "iiii"},
215 {WINED3DFMT_R10G10B10A2_UINT
, WINED3DFMT_R10G10B10A2_TYPELESS
, "UUUU"},
216 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "uuuu"},
217 {WINED3DFMT_R10G10B10X2_SNORM
, WINED3DFMT_R10G10B10X2_TYPELESS
, "iiiX"},
218 {WINED3DFMT_R10G10B10X2_UINT
, WINED3DFMT_R10G10B10X2_TYPELESS
, "UUUX"},
219 {WINED3DFMT_R8G8B8A8_UINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "UUUU"},
220 {WINED3DFMT_R8G8B8A8_SINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "IIII"},
221 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "iiii"},
222 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
223 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
224 {WINED3DFMT_R16G16_UNORM
, WINED3DFMT_R16G16_TYPELESS
, "uu"},
225 {WINED3DFMT_R16G16_SNORM
, WINED3DFMT_R16G16_TYPELESS
, "ii"},
226 {WINED3DFMT_R16G16_UINT
, WINED3DFMT_R16G16_TYPELESS
, "UU"},
227 {WINED3DFMT_R16G16_SINT
, WINED3DFMT_R16G16_TYPELESS
, "II"},
228 {WINED3DFMT_R16G16_FLOAT
, WINED3DFMT_R16G16_TYPELESS
, "FF"},
229 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "D"},
230 {WINED3DFMT_R32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "F"},
231 {WINED3DFMT_R32_UINT
, WINED3DFMT_R32_TYPELESS
, "U"},
232 {WINED3DFMT_R32_SINT
, WINED3DFMT_R32_TYPELESS
, "I"},
233 {WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_R24G8_TYPELESS
, "uX"},
234 {WINED3DFMT_X24_TYPELESS_G8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "XU"},
235 {WINED3DFMT_D24_UNORM_S8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "DS"},
236 {WINED3DFMT_R8G8_SNORM
, WINED3DFMT_R8G8_TYPELESS
, "ii"},
237 {WINED3DFMT_R8G8_UNORM
, WINED3DFMT_R8G8_TYPELESS
, "uu"},
238 {WINED3DFMT_R8G8_UINT
, WINED3DFMT_R8G8_TYPELESS
, "UU"},
239 {WINED3DFMT_R8G8_SINT
, WINED3DFMT_R8G8_TYPELESS
, "II"},
240 {WINED3DFMT_D16_UNORM
, WINED3DFMT_R16_TYPELESS
, "D"},
241 {WINED3DFMT_R16_UNORM
, WINED3DFMT_R16_TYPELESS
, "u"},
242 {WINED3DFMT_R16_SNORM
, WINED3DFMT_R16_TYPELESS
, "i"},
243 {WINED3DFMT_R16_UINT
, WINED3DFMT_R16_TYPELESS
, "U"},
244 {WINED3DFMT_R16_SINT
, WINED3DFMT_R16_TYPELESS
, "I"},
245 {WINED3DFMT_R16_FLOAT
, WINED3DFMT_R16_TYPELESS
, "F"},
246 {WINED3DFMT_R8_UNORM
, WINED3DFMT_R8_TYPELESS
, "u"},
247 {WINED3DFMT_R8_SNORM
, WINED3DFMT_R8_TYPELESS
, "i"},
248 {WINED3DFMT_R8_UINT
, WINED3DFMT_R8_TYPELESS
, "U"},
249 {WINED3DFMT_R8_SINT
, WINED3DFMT_R8_TYPELESS
, "I"},
250 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_TYPELESS
, ""},
251 {WINED3DFMT_BC1_UNORM
, WINED3DFMT_BC1_TYPELESS
, ""},
252 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_TYPELESS
, ""},
253 {WINED3DFMT_BC2_UNORM
, WINED3DFMT_BC2_TYPELESS
, ""},
254 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_TYPELESS
, ""},
255 {WINED3DFMT_BC3_UNORM
, WINED3DFMT_BC3_TYPELESS
, ""},
256 {WINED3DFMT_BC4_UNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
257 {WINED3DFMT_BC4_SNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
258 {WINED3DFMT_BC5_UNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
259 {WINED3DFMT_BC5_SNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
260 {WINED3DFMT_BC6H_UF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
261 {WINED3DFMT_BC6H_SF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
262 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_TYPELESS
, ""},
263 {WINED3DFMT_BC7_UNORM
, WINED3DFMT_BC7_TYPELESS
, ""},
264 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
265 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
266 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
267 {WINED3DFMT_B8G8R8X8_UNORM
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
270 struct wined3d_typeless_format_depth_stencil_info
272 enum wined3d_format_id typeless_id
;
273 enum wined3d_format_id depth_stencil_id
;
274 enum wined3d_format_id depth_view_id
;
275 enum wined3d_format_id stencil_view_id
;
276 BOOL separate_depth_view_format
;
279 static const struct wined3d_typeless_format_depth_stencil_info typeless_depth_stencil_formats
[] =
281 {WINED3DFMT_R32G8X24_TYPELESS
, WINED3DFMT_D32_FLOAT_S8X24_UINT
,
282 WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, WINED3DFMT_X32_TYPELESS_G8X24_UINT
, TRUE
},
283 {WINED3DFMT_R24G8_TYPELESS
, WINED3DFMT_D24_UNORM_S8_UINT
,
284 WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_X24_TYPELESS_G8_UINT
, TRUE
},
285 {WINED3DFMT_R32_TYPELESS
, WINED3DFMT_D32_FLOAT
, WINED3DFMT_R32_FLOAT
},
286 {WINED3DFMT_R16_TYPELESS
, WINED3DFMT_D16_UNORM
, WINED3DFMT_R16_UNORM
},
289 struct wined3d_format_ddi_info
291 enum wined3d_format_id id
;
292 D3DDDIFORMAT ddi_format
;
295 static const struct wined3d_format_ddi_info ddi_formats
[] =
297 {WINED3DFMT_B8G8R8_UNORM
, D3DDDIFMT_R8G8B8
},
298 {WINED3DFMT_B8G8R8A8_UNORM
, D3DDDIFMT_A8R8G8B8
},
299 {WINED3DFMT_B8G8R8X8_UNORM
, D3DDDIFMT_X8R8G8B8
},
300 {WINED3DFMT_B5G6R5_UNORM
, D3DDDIFMT_R5G6B5
},
301 {WINED3DFMT_B5G5R5X1_UNORM
, D3DDDIFMT_X1R5G5B5
},
302 {WINED3DFMT_B5G5R5A1_UNORM
, D3DDDIFMT_A1R5G5B5
},
303 {WINED3DFMT_B4G4R4A4_UNORM
, D3DDDIFMT_A4R4G4B4
},
304 {WINED3DFMT_B4G4R4X4_UNORM
, D3DDDIFMT_X4R4G4B4
},
305 {WINED3DFMT_P8_UINT
, D3DDDIFMT_P8
},
308 struct wined3d_format_base_flags
310 enum wined3d_format_id id
;
314 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
315 * still needs to use the correct block based calculation for e.g. the
317 static const struct wined3d_format_base_flags format_base_flags
[] =
319 {WINED3DFMT_ATI1N
, WINED3DFMT_FLAG_MAPPABLE
| WINED3DFMT_FLAG_BROKEN_PITCH
},
320 {WINED3DFMT_ATI2N
, WINED3DFMT_FLAG_MAPPABLE
| WINED3DFMT_FLAG_BROKEN_PITCH
},
321 {WINED3DFMT_D16_LOCKABLE
, WINED3DFMT_FLAG_MAPPABLE
},
322 {WINED3DFMT_INTZ
, WINED3DFMT_FLAG_MAPPABLE
},
323 {WINED3DFMT_R11G11B10_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
324 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
325 {WINED3DFMT_S8_UINT_D24_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
326 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, WINED3DFMT_FLAG_FLOAT
},
327 {WINED3DFMT_INST
, WINED3DFMT_FLAG_EXTENSION
},
328 {WINED3DFMT_NULL
, WINED3DFMT_FLAG_EXTENSION
},
329 {WINED3DFMT_NVDB
, WINED3DFMT_FLAG_EXTENSION
},
330 {WINED3DFMT_ATOC
, WINED3DFMT_FLAG_EXTENSION
},
331 {WINED3DFMT_RESZ
, WINED3DFMT_FLAG_EXTENSION
},
332 {WINED3DFMT_R32G32B32A32_TYPELESS
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
333 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
334 {WINED3DFMT_R32G32B32A32_UINT
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
335 {WINED3DFMT_R32G32B32A32_SINT
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
336 {WINED3DFMT_R16G16B16A16_TYPELESS
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
337 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
338 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
339 {WINED3DFMT_R16G16B16A16_UINT
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
340 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
341 {WINED3DFMT_R16G16B16A16_SINT
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
342 {WINED3DFMT_R32G32_TYPELESS
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
343 {WINED3DFMT_R32G32_FLOAT
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
344 {WINED3DFMT_R32G32_UINT
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
345 {WINED3DFMT_R32G32_SINT
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
346 {WINED3DFMT_R32_TYPELESS
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
347 {WINED3DFMT_R32_FLOAT
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
348 {WINED3DFMT_R32_UINT
, WINED3DFMT_FLAG_CAST_TO_BLOCK
| WINED3DFMT_FLAG_INDEX_BUFFER
},
349 {WINED3DFMT_R32_SINT
, WINED3DFMT_FLAG_CAST_TO_BLOCK
},
350 {WINED3DFMT_R16_UINT
, WINED3DFMT_FLAG_INDEX_BUFFER
},
353 static void rgb888_from_rgb565(WORD rgb565
, BYTE
*r
, BYTE
*g
, BYTE
*b
)
357 /* (2⁸ - 1) / (2⁵ - 1) ≈ 2⁸ / 2⁵ + 2⁸ / 2¹⁰
358 * (2⁸ - 1) / (2⁶ - 1) ≈ 2⁸ / 2⁶ + 2⁸ / 2¹² */
360 *r
= (c
<< 3) + (c
>> 2);
361 c
= (rgb565
>> 5) & 0x3f;
362 *g
= (c
<< 2) + (c
>> 4);
364 *b
= (c
<< 3) + (c
>> 2);
367 static void build_dxtn_colour_table(WORD colour0
, WORD colour1
,
368 DWORD colour_table
[4], enum wined3d_format_id format_id
)
376 rgb888_from_rgb565(colour0
, &c
[0].r
, &c
[0].g
, &c
[0].b
);
377 rgb888_from_rgb565(colour1
, &c
[1].r
, &c
[1].g
, &c
[1].b
);
379 if (format_id
== WINED3DFMT_BC1_UNORM
&& colour0
<= colour1
)
381 c
[2].r
= (c
[0].r
+ c
[1].r
) / 2;
382 c
[2].g
= (c
[0].g
+ c
[1].g
) / 2;
383 c
[2].b
= (c
[0].b
+ c
[1].b
) / 2;
391 for (i
= 0; i
< 2; ++i
)
393 c
[i
+ 2].r
= (2 * c
[i
].r
+ c
[1 - i
].r
) / 3;
394 c
[i
+ 2].g
= (2 * c
[i
].g
+ c
[1 - i
].g
) / 3;
395 c
[i
+ 2].b
= (2 * c
[i
].b
+ c
[1 - i
].b
) / 3;
399 for (i
= 0; i
< 4; ++i
)
401 colour_table
[i
] = (c
[i
].r
<< 16) | (c
[i
].g
<< 8) | c
[i
].b
;
405 static void build_bc3_alpha_table(BYTE alpha0
, BYTE alpha1
, BYTE alpha_table
[8])
409 alpha_table
[0] = alpha0
;
410 alpha_table
[1] = alpha1
;
414 for (i
= 0; i
< 6; ++i
)
416 alpha_table
[2 + i
] = ((6 - i
) * alpha0
+ (i
+ 1) * alpha1
) / 7;
422 for (i
= 0; i
< 4; ++i
)
424 alpha_table
[2 + i
] = ((4 - i
) * alpha0
+ (i
+ 1) * alpha1
) / 5;
426 alpha_table
[6] = 0x00;
427 alpha_table
[7] = 0xff;
431 static void decompress_dxtn_block(const BYTE
*src
, BYTE
*dst
, unsigned int width
,
432 unsigned int height
, unsigned int dst_row_pitch
, enum wined3d_format_id format_id
)
434 const UINT64
*s
= (const UINT64
*)src
;
435 BOOL bc1_alpha
= FALSE
;
436 DWORD colour_table
[4];
445 if (format_id
== WINED3DFMT_BC1_UNORM
)
447 WORD colour0
, colour1
;
451 colour0
= s
[0] & 0xffff;
452 colour1
= (s
[0] >> 16) & 0xffff;
453 colour_bits
= (s
[0] >> 32) & 0xffffffff;
454 build_dxtn_colour_table(colour0
, colour1
, colour_table
, format_id
);
455 if (colour0
<= colour1
)
461 if (format_id
== WINED3DFMT_BC3_UNORM
)
463 build_bc3_alpha_table(alpha_bits
& 0xff, (alpha_bits
>> 8) & 0xff, alpha_table
);
467 colour_bits
= (s
[1] >> 32) & 0xffffffff;
468 build_dxtn_colour_table(s
[1] & 0xffff, (s
[1] >> 16) & 0xffff, colour_table
, format_id
);
471 for (y
= 0; y
< height
; ++y
)
473 dst_row
= (DWORD
*)&dst
[y
* dst_row_pitch
];
474 for (x
= 0; x
< width
; ++x
)
476 colour_idx
= (colour_bits
>> (y
* 8 + x
* 2)) & 0x3;
479 case WINED3DFMT_BC1_UNORM
:
480 alpha
= bc1_alpha
&& colour_idx
== 3 ? 0x00 : 0xff;
483 case WINED3DFMT_BC2_UNORM
:
484 alpha
= (alpha_bits
>> (y
* 16 + x
* 4)) & 0xf;
485 /* (2⁸ - 1) / (2⁴ - 1) ≈ 2⁸ / 2⁴ + 2⁸ / 2⁸ */
489 case WINED3DFMT_BC3_UNORM
:
490 alpha
= alpha_table
[(alpha_bits
>> (y
* 12 + x
* 3)) & 0x7];
497 dst_row
[x
] = (alpha
<< 24) | colour_table
[colour_idx
];
502 static void decompress_dxtn(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
503 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
504 unsigned int width
, unsigned int height
, unsigned int depth
, enum wined3d_format_id format_id
)
506 unsigned int block_byte_count
, block_w
, block_h
;
507 const BYTE
*src_row
, *src_slice
= src
;
508 BYTE
*dst_row
, *dst_slice
= dst
;
509 unsigned int x
, y
, z
;
511 block_byte_count
= format_id
== WINED3DFMT_BC1_UNORM
? 8 : 16;
513 for (z
= 0; z
< depth
; ++z
)
517 for (y
= 0; y
< height
; y
+= 4)
519 for (x
= 0; x
< width
; x
+= 4)
521 block_w
= min(width
- x
, 4);
522 block_h
= min(height
- y
, 4);
523 decompress_dxtn_block(&src_row
[x
* (block_byte_count
/ 4)],
524 &dst_row
[x
* 4], block_w
, block_h
, dst_row_pitch
, format_id
);
526 src_row
+= src_row_pitch
;
527 dst_row
+= dst_row_pitch
* 4;
529 src_slice
+= src_slice_pitch
;
530 dst_slice
+= dst_slice_pitch
;
534 static void decompress_bc3(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
535 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
536 unsigned int width
, unsigned int height
, unsigned int depth
)
538 decompress_dxtn(src
, dst
, src_row_pitch
, src_slice_pitch
, dst_row_pitch
,
539 dst_slice_pitch
, width
, height
, depth
, WINED3DFMT_BC3_UNORM
);
542 static void decompress_bc2(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
543 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
544 unsigned int width
, unsigned int height
, unsigned int depth
)
546 decompress_dxtn(src
, dst
, src_row_pitch
, src_slice_pitch
, dst_row_pitch
,
547 dst_slice_pitch
, width
, height
, depth
, WINED3DFMT_BC2_UNORM
);
550 static void decompress_bc1(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
,
551 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
552 unsigned int width
, unsigned int height
, unsigned int depth
)
554 decompress_dxtn(src
, dst
, src_row_pitch
, src_slice_pitch
, dst_row_pitch
,
555 dst_slice_pitch
, width
, height
, depth
, WINED3DFMT_BC1_UNORM
);
558 static void build_rgtc_colour_table(uint8_t red0
, uint8_t red1
, uint8_t colour_table
[8])
562 colour_table
[0] = red0
;
563 colour_table
[1] = red1
;
566 for (i
= 0; i
< 4; ++i
)
568 colour_table
[i
+ 2] = ((8 - 2 * i
) * red0
+ (2 + 2 * i
) * red1
+ 5) / 10;
570 colour_table
[6] = 0x00;
571 colour_table
[7] = 0xff;
575 for (i
= 0; i
< 6; ++i
)
577 colour_table
[i
+ 2] = ((12 - 2 * i
) * red0
+ (2 + 2 * i
) * red1
+ 7) / 14;
582 static void decompress_rgtc_block(const uint8_t *src
, uint8_t *dst
,
583 unsigned int width
, unsigned int height
, unsigned int dst_row_pitch
)
585 const uint64_t *s
= (const uint64_t *)src
;
586 uint8_t red0
, red1
, red_idx
;
587 uint8_t colour_table
[8];
593 red1
= (s
[0] >> 8) & 0xff;
595 build_rgtc_colour_table(red0
, red1
, colour_table
);
597 for (y
= 0; y
< height
; ++y
)
599 dst_row
= (uint32_t *)&dst
[y
* dst_row_pitch
];
600 for (x
= 0; x
< width
; ++x
)
602 red_idx
= (bits
>> (y
* 12 + x
* 3)) & 0x7;
603 /* Decompressing to bgra32 is perhaps not ideal for RGTC formats.
604 * It's convenient though. */
605 dst_row
[x
] = 0xff000000 | (colour_table
[red_idx
] << 16);
610 static void decompress_bc4(const uint8_t *src
, uint8_t *dst
, unsigned int src_row_pitch
,
611 unsigned int src_slice_pitch
, unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
612 unsigned int width
, unsigned int height
, unsigned int depth
)
614 unsigned int block_w
, block_h
, x
, y
, z
;
615 const uint8_t *src_row
, *src_slice
;
616 uint8_t *dst_row
, *dst_slice
;
618 for (z
= 0; z
< depth
; ++z
)
620 src_slice
= &src
[z
* src_slice_pitch
];
621 dst_slice
= &dst
[z
* dst_slice_pitch
];
622 for (y
= 0; y
< height
; y
+= 4)
624 src_row
= &src_slice
[(y
/ 4) * src_row_pitch
];
625 dst_row
= &dst_slice
[y
* dst_row_pitch
];
626 for (x
= 0; x
< width
; x
+= 4)
628 block_w
= min(width
- x
, 4);
629 block_h
= min(height
- y
, 4);
630 decompress_rgtc_block(&src_row
[(x
/ 4) * 8], &dst_row
[x
* 4], block_w
, block_h
, dst_row_pitch
);
636 static const struct wined3d_format_decompress_info
638 enum wined3d_format_id id
;
639 void (*decompress
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
640 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
641 unsigned int width
, unsigned int height
, unsigned int depth
);
643 format_decompress_info
[] =
645 {WINED3DFMT_DXT1
, decompress_bc1
},
646 {WINED3DFMT_DXT2
, decompress_bc2
},
647 {WINED3DFMT_DXT3
, decompress_bc2
},
648 {WINED3DFMT_DXT4
, decompress_bc3
},
649 {WINED3DFMT_DXT5
, decompress_bc3
},
650 {WINED3DFMT_BC1_UNORM
, decompress_bc1
},
651 {WINED3DFMT_BC2_UNORM
, decompress_bc2
},
652 {WINED3DFMT_BC3_UNORM
, decompress_bc3
},
653 {WINED3DFMT_BC4_UNORM
, decompress_bc4
},
656 struct wined3d_format_block_info
658 enum wined3d_format_id id
;
661 UINT block_byte_count
;
665 static const struct wined3d_format_block_info format_block_info
[] =
667 {WINED3DFMT_DXT1
, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED
},
668 {WINED3DFMT_DXT2
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
669 {WINED3DFMT_DXT3
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
670 {WINED3DFMT_DXT4
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
671 {WINED3DFMT_DXT5
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
672 {WINED3DFMT_BC1_UNORM
, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED
},
673 {WINED3DFMT_BC2_UNORM
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
674 {WINED3DFMT_BC3_UNORM
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
675 {WINED3DFMT_BC4_UNORM
, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED
},
676 {WINED3DFMT_BC4_SNORM
, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED
},
677 {WINED3DFMT_BC5_UNORM
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
678 {WINED3DFMT_BC5_SNORM
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
679 {WINED3DFMT_BC6H_UF16
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
680 {WINED3DFMT_BC6H_SF16
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
681 {WINED3DFMT_BC7_UNORM
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
},
682 {WINED3DFMT_ATI1N
, 4, 4, 8, WINED3DFMT_FLAG_COMPRESSED
| WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
},
683 {WINED3DFMT_ATI2N
, 4, 4, 16, WINED3DFMT_FLAG_COMPRESSED
| WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
},
684 {WINED3DFMT_YUY2
, 2, 1, 4, WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
},
685 {WINED3DFMT_UYVY
, 2, 1, 4, WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
},
686 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, 1, 1, 4},
689 struct wined3d_format_vertex_info
691 enum wined3d_format_id id
;
692 enum wined3d_ffp_emit_idx emit_idx
;
694 enum wined3d_gl_extension extension
;
697 static const struct wined3d_format_vertex_info format_vertex_info
[] =
699 {WINED3DFMT_R32_FLOAT
, WINED3D_FFP_EMIT_FLOAT1
, GL_FLOAT
},
700 {WINED3DFMT_R32G32_FLOAT
, WINED3D_FFP_EMIT_FLOAT2
, GL_FLOAT
},
701 {WINED3DFMT_R32G32B32_FLOAT
, WINED3D_FFP_EMIT_FLOAT3
, GL_FLOAT
},
702 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3D_FFP_EMIT_FLOAT4
, GL_FLOAT
},
703 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3D_FFP_EMIT_D3DCOLOR
, GL_UNSIGNED_BYTE
},
704 {WINED3DFMT_R8G8B8A8_UINT
, WINED3D_FFP_EMIT_UBYTE4
, GL_UNSIGNED_BYTE
},
705 {WINED3DFMT_R16G16_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_SHORT
},
706 {WINED3DFMT_R16G16_SINT
, WINED3D_FFP_EMIT_SHORT2
, GL_SHORT
},
707 {WINED3DFMT_R16G16B16A16_SINT
, WINED3D_FFP_EMIT_SHORT4
, GL_SHORT
},
708 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3D_FFP_EMIT_UBYTE4N
, GL_UNSIGNED_BYTE
},
709 {WINED3DFMT_R16G16_SNORM
, WINED3D_FFP_EMIT_SHORT2N
, GL_SHORT
},
710 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3D_FFP_EMIT_SHORT4N
, GL_SHORT
},
711 {WINED3DFMT_R16G16_UNORM
, WINED3D_FFP_EMIT_USHORT2N
, GL_UNSIGNED_SHORT
},
712 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3D_FFP_EMIT_USHORT4N
, GL_UNSIGNED_SHORT
},
713 {WINED3DFMT_R11G11B10_FLOAT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT_10F_11F_11F_REV
,
714 ARB_VERTEX_TYPE_10F_11F_11F_REV
},
715 {WINED3DFMT_R10G10B10X2_UINT
, WINED3D_FFP_EMIT_UDEC3
, GL_UNSIGNED_SHORT
},
716 {WINED3DFMT_R10G10B10X2_SNORM
, WINED3D_FFP_EMIT_DEC3N
, GL_SHORT
},
717 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT_2_10_10_10_REV
,
718 ARB_VERTEX_TYPE_2_10_10_10_REV
},
719 /* Without ARB_half_float_vertex we convert these on upload. */
720 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, GL_FLOAT
},
721 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, GL_HALF_FLOAT
, ARB_HALF_FLOAT_VERTEX
},
722 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, GL_FLOAT
},
723 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, GL_HALF_FLOAT
, ARB_HALF_FLOAT_VERTEX
},
724 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3D_FFP_EMIT_INVALID
, GL_BYTE
},
725 {WINED3DFMT_R8G8B8A8_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_BYTE
},
726 {WINED3DFMT_R8G8_UNORM
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
727 {WINED3DFMT_R16G16B16A16_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_SHORT
},
728 {WINED3DFMT_R8_UNORM
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
729 {WINED3DFMT_R8_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
730 {WINED3DFMT_R8_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_BYTE
},
731 {WINED3DFMT_R8G8_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_BYTE
},
732 {WINED3DFMT_R16_FLOAT
, WINED3D_FFP_EMIT_INVALID
, GL_HALF_FLOAT
, ARB_HALF_FLOAT_VERTEX
},
733 {WINED3DFMT_R16_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_SHORT
},
734 {WINED3DFMT_R16_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_SHORT
},
735 {WINED3DFMT_R32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
736 {WINED3DFMT_R32_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_INT
},
737 {WINED3DFMT_R32G32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
738 {WINED3DFMT_R32G32_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_INT
},
739 {WINED3DFMT_R32G32B32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
740 {WINED3DFMT_R32G32B32A32_UINT
, WINED3D_FFP_EMIT_INVALID
, GL_UNSIGNED_INT
},
741 {WINED3DFMT_R32G32B32A32_SINT
, WINED3D_FFP_EMIT_INVALID
, GL_INT
},
744 struct wined3d_format_texture_info
746 enum wined3d_format_id id
;
748 GLint gl_srgb_internal
;
749 GLint gl_rt_internal
;
752 unsigned int conv_byte_count
;
754 enum wined3d_gl_extension extension
;
755 void (*upload
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
756 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
757 unsigned int width
, unsigned int height
, unsigned int depth
);
758 void (*download
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
759 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
760 unsigned int width
, unsigned int height
, unsigned int depth
);
761 void (*decompress
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
762 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
763 unsigned int width
, unsigned int height
, unsigned int depth
);
766 static void convert_l4a4_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
767 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
769 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
770 * format+type combination to load it. Thus convert it to A8L8, then load it
771 * with A4L4 internal, but A8L8 format+type
773 unsigned int x
, y
, z
;
774 const unsigned char *Source
;
777 for (z
= 0; z
< depth
; z
++)
779 for (y
= 0; y
< height
; y
++)
781 Source
= src
+ z
* src_slice_pitch
+ y
* src_row_pitch
;
782 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
783 for (x
= 0; x
< width
; x
++ )
785 unsigned char color
= (*Source
++);
786 /* A */ Dest
[1] = (color
& 0xf0u
) << 0;
787 /* L */ Dest
[0] = (color
& 0x0fu
) << 4;
794 static void convert_r5g5_snorm_l6_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
795 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
797 unsigned int x
, y
, z
;
798 unsigned char r_in
, g_in
, l_in
;
799 const unsigned short *texel_in
;
800 unsigned short *texel_out
;
802 /* Emulating signed 5 bit values with unsigned 5 bit values has some precision problems by design:
803 * E.g. the signed input value 0 becomes 16. GL normalizes it to 16 / 31 = 0.516. We convert it
804 * back to a signed value by subtracting 0.5 and multiplying by 2.0. The resulting value is
805 * ((16 / 31) - 0.5) * 2.0 = 0.032, which is quite different from the intended result 0.000. */
806 for (z
= 0; z
< depth
; z
++)
808 for (y
= 0; y
< height
; y
++)
810 texel_out
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
811 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
812 for (x
= 0; x
< width
; x
++ )
814 l_in
= (*texel_in
& 0xfc00u
) >> 10;
815 g_in
= (*texel_in
& 0x03e0u
) >> 5;
816 r_in
= *texel_in
& 0x001fu
;
818 *texel_out
= ((r_in
+ 16) << 11) | (l_in
<< 5) | (g_in
+ 16);
826 static void convert_r5g5_snorm_l6_unorm_ext(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
827 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
829 unsigned int x
, y
, z
;
830 unsigned char *texel_out
, r_out
, g_out
, r_in
, g_in
, l_in
;
831 const unsigned short *texel_in
;
833 for (z
= 0; z
< depth
; z
++)
835 for (y
= 0; y
< height
; y
++)
837 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
838 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
839 for (x
= 0; x
< width
; x
++ )
841 l_in
= (*texel_in
& 0xfc00u
) >> 10;
842 g_in
= (*texel_in
& 0x03e0u
) >> 5;
843 r_in
= *texel_in
& 0x001fu
;
846 if (!(r_in
& 0x10)) /* r > 0 */
850 if (!(g_in
& 0x10)) /* g > 0 */
853 texel_out
[0] = r_out
;
854 texel_out
[1] = g_out
;
855 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
865 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
866 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
868 unsigned int x
, y
, z
;
869 unsigned char *texel_out
, ds_out
, dt_out
, r_in
, g_in
, l_in
;
870 const unsigned short *texel_in
;
872 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
873 * fixed function and shaders without further conversion once the surface is
876 * The difference between this function and convert_r5g5_snorm_l6_unorm_ext
877 * is that convert_r5g5_snorm_l6_unorm_ext creates a 32 bit XRGB texture and
878 * this function creates a 24 bit DSDT_MAG texture. Trying to load a DSDT_MAG
879 * internal with a 32 bit DSDT_MAG_INTENSITY or DSDT_MAG_VIB format fails. */
880 for (z
= 0; z
< depth
; z
++)
882 for (y
= 0; y
< height
; y
++)
884 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
885 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
886 for (x
= 0; x
< width
; x
++ )
888 l_in
= (*texel_in
& 0xfc00u
) >> 10;
889 g_in
= (*texel_in
& 0x03e0u
) >> 5;
890 r_in
= *texel_in
& 0x001fu
;
893 if (!(r_in
& 0x10)) /* r > 0 */
897 if (!(g_in
& 0x10)) /* g > 0 */
900 texel_out
[0] = ds_out
;
901 texel_out
[1] = dt_out
;
902 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
911 static void convert_r8g8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
912 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
914 unsigned int x
, y
, z
;
918 for (z
= 0; z
< depth
; z
++)
920 for (y
= 0; y
< height
; y
++)
922 Source
= (const short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
923 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
924 for (x
= 0; x
< width
; x
++ )
926 const short color
= (*Source
++);
927 /* B */ Dest
[0] = 0xff;
928 /* G */ Dest
[1] = (color
>> 8) + 128; /* V */
929 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
936 static void convert_r8g8_snorm_l8x8_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
937 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
939 unsigned int x
, y
, z
;
943 /* Doesn't work correctly with the fixed function pipeline, but can work in
944 * shaders if the shader is adjusted. (There's no use for this format in gl's
945 * standard fixed function pipeline anyway).
947 for (z
= 0; z
< depth
; z
++)
949 for (y
= 0; y
< height
; y
++)
951 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
952 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
953 for (x
= 0; x
< width
; x
++ )
955 LONG color
= (*Source
++);
956 /* B */ Dest
[0] = ((color
>> 16) & 0xff); /* L */
957 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
958 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
965 static void convert_r8g8_snorm_l8x8_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
966 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
968 unsigned int x
, y
, z
;
972 /* This implementation works with the fixed function pipeline and shaders
973 * without further modification after converting the surface.
975 for (z
= 0; z
< depth
; z
++)
977 for (y
= 0; y
< height
; y
++)
979 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
980 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
981 for (x
= 0; x
< width
; x
++ )
983 LONG color
= (*Source
++);
984 /* L */ Dest
[2] = ((color
>> 16) & 0xff); /* L */
985 /* V */ Dest
[1] = ((color
>> 8 ) & 0xff); /* V */
986 /* U */ Dest
[0] = (color
& 0xff); /* U */
987 /* I */ Dest
[3] = 255; /* X */
994 static void convert_r8g8b8a8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
995 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
997 unsigned int x
, y
, z
;
1001 for (z
= 0; z
< depth
; z
++)
1003 for (y
= 0; y
< height
; y
++)
1005 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1006 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
1007 for (x
= 0; x
< width
; x
++ )
1009 LONG color
= (*Source
++);
1010 /* B */ Dest
[0] = ((color
>> 16) & 0xff) + 128; /* W */
1011 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
1012 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
1013 /* A */ Dest
[3] = ((color
>> 24) & 0xff) + 128; /* Q */
1020 static void convert_r16g16_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1021 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1023 unsigned int x
, y
, z
;
1024 const DWORD
*Source
;
1025 unsigned short *Dest
;
1027 for (z
= 0; z
< depth
; z
++)
1029 for (y
= 0; y
< height
; y
++)
1031 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1032 Dest
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1033 for (x
= 0; x
< width
; x
++ )
1035 const DWORD color
= (*Source
++);
1036 /* B */ Dest
[0] = 0xffff;
1037 /* G */ Dest
[1] = (color
>> 16) + 32768; /* V */
1038 /* R */ Dest
[2] = (color
& 0xffff) + 32768; /* U */
1045 static void convert_r16g16(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1046 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1048 unsigned int x
, y
, z
;
1052 for (z
= 0; z
< depth
; z
++)
1054 for (y
= 0; y
< height
; y
++)
1056 Source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1057 Dest
= (WORD
*) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1058 for (x
= 0; x
< width
; x
++ )
1060 WORD green
= (*Source
++);
1061 WORD red
= (*Source
++);
1064 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
1065 * shader overwrites it anyway */
1073 static void convert_r32g32_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1074 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1076 unsigned int x
, y
, z
;
1077 const float *Source
;
1080 for (z
= 0; z
< depth
; z
++)
1082 for (y
= 0; y
< height
; y
++)
1084 Source
= (const float *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1085 Dest
= (float *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1086 for (x
= 0; x
< width
; x
++ )
1088 float green
= (*Source
++);
1089 float red
= (*Source
++);
1099 static void convert_s8_uint_d24_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
1100 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
1102 unsigned int x
, y
, z
;
1104 for (z
= 0; z
< depth
; z
++)
1106 for (y
= 0; y
< height
; ++y
)
1108 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1109 float *dest_f
= (float *)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1110 DWORD
*dest_s
= (DWORD
*)dest_f
;
1112 for (x
= 0; x
< width
; ++x
)
1114 dest_f
[x
* 2] = float_24_to_32((source
[x
] & 0xffffff00u
) >> 8);
1115 dest_s
[x
* 2 + 1] = source
[x
] & 0xff;
1121 static void x8_d24_unorm_upload(const BYTE
*src
, BYTE
*dst
,
1122 unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
1123 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
1124 unsigned int width
, unsigned int height
, unsigned int depth
)
1126 unsigned int x
, y
, z
;
1128 for (z
= 0; z
< depth
; ++z
)
1130 for (y
= 0; y
< height
; ++y
)
1132 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1133 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1135 for (x
= 0; x
< width
; ++x
)
1137 dest
[x
] = source
[x
] << 8 | ((source
[x
] >> 16) & 0xff);
1143 static void x8_d24_unorm_download(const BYTE
*src
, BYTE
*dst
,
1144 unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
1145 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
1146 unsigned int width
, unsigned int height
, unsigned int depth
)
1148 unsigned int x
, y
, z
;
1150 for (z
= 0; z
< depth
; ++z
)
1152 for (y
= 0; y
< height
; ++y
)
1154 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
1155 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
1157 for (x
= 0; x
< width
; ++x
)
1159 dest
[x
] = source
[x
] >> 8;
1165 static BOOL
color_in_range(const struct wined3d_color_key
*color_key
, DWORD color
)
1167 /* FIXME: Is this really how color keys are supposed to work? I think it
1168 * makes more sense to compare the individual channels. */
1169 return color
>= color_key
->color_space_low_value
1170 && color
<= color_key
->color_space_high_value
;
1173 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1174 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1175 const struct wined3d_color_key
*color_key
)
1177 const WORD
*src_row
;
1181 for (y
= 0; y
< height
; ++y
)
1183 src_row
= (WORD
*)&src
[src_pitch
* y
];
1184 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
1185 for (x
= 0; x
< width
; ++x
)
1187 WORD src_color
= src_row
[x
];
1188 if (!color_in_range(color_key
, src_color
))
1189 dst_row
[x
] = 0x8000u
| ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
1191 dst_row
[x
] = ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
1196 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1197 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1198 const struct wined3d_color_key
*color_key
)
1200 const WORD
*src_row
;
1204 for (y
= 0; y
< height
; ++y
)
1206 src_row
= (WORD
*)&src
[src_pitch
* y
];
1207 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
1208 for (x
= 0; x
< width
; ++x
)
1210 WORD src_color
= src_row
[x
];
1211 if (color_in_range(color_key
, src_color
))
1212 dst_row
[x
] = src_color
& ~0x8000;
1214 dst_row
[x
] = src_color
| 0x8000;
1219 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1220 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1221 const struct wined3d_color_key
*color_key
)
1223 const BYTE
*src_row
;
1227 for (y
= 0; y
< height
; ++y
)
1229 src_row
= &src
[src_pitch
* y
];
1230 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1231 for (x
= 0; x
< width
; ++x
)
1233 DWORD src_color
= (src_row
[x
* 3 + 2] << 16) | (src_row
[x
* 3 + 1] << 8) | src_row
[x
* 3];
1234 if (!color_in_range(color_key
, src_color
))
1235 dst_row
[x
] = src_color
| 0xff000000;
1240 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1241 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1242 const struct wined3d_color_key
*color_key
)
1244 const DWORD
*src_row
;
1248 for (y
= 0; y
< height
; ++y
)
1250 src_row
= (DWORD
*)&src
[src_pitch
* y
];
1251 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1252 for (x
= 0; x
< width
; ++x
)
1254 DWORD src_color
= src_row
[x
];
1255 if (color_in_range(color_key
, src_color
))
1256 dst_row
[x
] = src_color
& ~0xff000000;
1258 dst_row
[x
] = src_color
| 0xff000000;
1263 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1264 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1265 const struct wined3d_color_key
*color_key
)
1267 const DWORD
*src_row
;
1271 for (y
= 0; y
< height
; ++y
)
1273 src_row
= (DWORD
*)&src
[src_pitch
* y
];
1274 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1275 for (x
= 0; x
< width
; ++x
)
1277 DWORD src_color
= src_row
[x
];
1278 if (color_in_range(color_key
, src_color
))
1279 src_color
&= ~0xff000000;
1280 dst_row
[x
] = src_color
;
1285 const struct wined3d_color_key_conversion
* wined3d_format_get_color_key_conversion(
1286 const struct wined3d_texture
*texture
, BOOL need_alpha_ck
)
1288 const struct wined3d_format
*format
= texture
->resource
.format
;
1293 enum wined3d_format_id src_format
;
1294 struct wined3d_color_key_conversion conversion
;
1298 {WINED3DFMT_B5G6R5_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key
}},
1299 {WINED3DFMT_B5G5R5X1_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key
}},
1300 {WINED3DFMT_B8G8R8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key
}},
1301 {WINED3DFMT_B8G8R8X8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key
}},
1302 {WINED3DFMT_B8G8R8A8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key
}},
1305 if (need_alpha_ck
&& (texture
->async
.flags
& WINED3D_TEXTURE_ASYNC_COLOR_KEY
))
1307 for (i
= 0; i
< ARRAY_SIZE(color_key_info
); ++i
)
1309 if (color_key_info
[i
].src_format
== format
->id
)
1310 return &color_key_info
[i
].conversion
;
1313 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format
->id
));
1319 /* We intentionally don't support WINED3DFMT_D32_UNORM. No hardware driver
1320 * supports it, and applications get confused when we do.
1322 * The following formats explicitly don't have WINED3DFMT_FLAG_TEXTURE set:
1324 * These are never supported on native.
1325 * WINED3DFMT_B8G8R8_UNORM
1326 * WINED3DFMT_B2G3R3_UNORM
1327 * WINED3DFMT_L4A4_UNORM
1328 * WINED3DFMT_S1_UINT_D15_UNORM
1329 * WINED3DFMT_S4X4_UINT_D24_UNORM
1331 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
1332 * Since it is not widely available, don't offer it. Further no Windows driver
1333 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
1334 * WINED3DFMT_P8_UINT
1335 * WINED3DFMT_P8_UINT_A8_UNORM
1337 * These formats seem to be similar to the HILO formats in
1338 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
1339 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
1340 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
1341 * refused to support formats which can easily be emulated with pixel shaders,
1342 * so applications have to deal with not having NVHS and NVHU.
1344 * WINED3DFMT_NVHS */
1345 static const struct wined3d_format_texture_info format_texture_info
[] =
1347 /* format id gl_internal gl_srgb_internal gl_rt_internal
1348 gl_format gl_type conv_byte_count
1350 extension upload download */
1351 /* FourCC formats */
1352 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
1353 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
1354 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
1355 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
1358 {WINED3DFMT_UYVY
, GL_RG8
, GL_RG8
, 0,
1359 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1360 WINED3DFMT_FLAG_FILTERING
,
1361 ARB_TEXTURE_RG
, NULL
},
1362 {WINED3DFMT_UYVY
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1363 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1364 WINED3DFMT_FLAG_FILTERING
,
1365 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1366 {WINED3DFMT_UYVY
, GL_RGB_RAW_422_APPLE
, GL_RGB_RAW_422_APPLE
, 0,
1367 GL_RGB_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
1368 WINED3DFMT_FLAG_FILTERING
,
1369 APPLE_RGB_422
, NULL
},
1370 {WINED3DFMT_UYVY
, GL_RGB
, GL_RGB
, 0,
1371 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
1372 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
1373 APPLE_YCBCR_422
, NULL
},
1374 {WINED3DFMT_YUY2
, GL_RG8
, GL_RG8
, 0,
1375 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1376 WINED3DFMT_FLAG_FILTERING
,
1377 ARB_TEXTURE_RG
, NULL
},
1378 {WINED3DFMT_YUY2
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1379 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1380 WINED3DFMT_FLAG_FILTERING
,
1381 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1382 {WINED3DFMT_YUY2
, GL_RGB_RAW_422_APPLE
, GL_RGB_RAW_422_APPLE
, 0,
1383 GL_RGB_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
1384 WINED3DFMT_FLAG_FILTERING
,
1385 APPLE_RGB_422
, NULL
},
1386 {WINED3DFMT_YUY2
, GL_RGB
, GL_RGB
, 0,
1387 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
1388 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
1389 APPLE_YCBCR_422
, NULL
},
1390 {WINED3DFMT_YV12
, GL_R8
, GL_R8
, 0,
1391 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1392 WINED3DFMT_FLAG_FILTERING
,
1393 ARB_TEXTURE_RG
, NULL
},
1394 {WINED3DFMT_YV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1395 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1396 WINED3DFMT_FLAG_FILTERING
,
1397 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1398 {WINED3DFMT_NV12
, GL_R8
, GL_R8
, 0,
1399 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1400 WINED3DFMT_FLAG_FILTERING
,
1401 ARB_TEXTURE_RG
, NULL
},
1402 {WINED3DFMT_NV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1403 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1404 WINED3DFMT_FLAG_FILTERING
,
1405 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1406 {WINED3DFMT_DXT1
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1407 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1408 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1409 | WINED3DFMT_FLAG_SRGB_READ
,
1410 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1411 {WINED3DFMT_DXT2
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1412 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1413 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1414 | WINED3DFMT_FLAG_SRGB_READ
,
1415 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1416 {WINED3DFMT_DXT3
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1417 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1418 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1419 | WINED3DFMT_FLAG_SRGB_READ
,
1420 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1421 {WINED3DFMT_DXT4
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1422 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1423 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1424 | WINED3DFMT_FLAG_SRGB_READ
,
1425 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1426 {WINED3DFMT_DXT5
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1427 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1428 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1429 | WINED3DFMT_FLAG_SRGB_READ
,
1430 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1431 {WINED3DFMT_BC1_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1432 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1433 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1434 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1435 {WINED3DFMT_BC2_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1436 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1437 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1438 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1439 {WINED3DFMT_BC3_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1440 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1441 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1442 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1443 {WINED3DFMT_BC4_UNORM
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1444 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1445 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1446 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1447 {WINED3DFMT_BC4_SNORM
, GL_COMPRESSED_SIGNED_RED_RGTC1
, GL_COMPRESSED_SIGNED_RED_RGTC1
, 0,
1448 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1449 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1450 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1451 {WINED3DFMT_BC5_UNORM
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1452 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1453 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1454 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1455 {WINED3DFMT_BC5_SNORM
, GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_COMPRESSED_SIGNED_RG_RGTC2
, 0,
1456 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1457 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1458 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1459 {WINED3DFMT_BC6H_UF16
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, 0,
1460 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1461 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1462 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1463 {WINED3DFMT_BC6H_SF16
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, 0,
1464 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1465 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1466 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1467 {WINED3DFMT_BC7_UNORM
, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
, 0,
1468 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1469 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1470 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1472 {WINED3DFMT_R32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1473 GL_RED
, GL_FLOAT
, 0,
1474 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1475 ARB_TEXTURE_FLOAT
, NULL
},
1476 {WINED3DFMT_R32_FLOAT
, GL_R32F
, GL_R32F
, 0,
1477 GL_RED
, GL_FLOAT
, 0,
1478 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1479 ARB_TEXTURE_RG
, NULL
},
1480 {WINED3DFMT_R32G32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1481 GL_RGB
, GL_FLOAT
, 12,
1482 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1483 ARB_TEXTURE_FLOAT
, convert_r32g32_float
},
1484 {WINED3DFMT_R32G32_FLOAT
, GL_RG32F
, GL_RG32F
, 0,
1486 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1487 ARB_TEXTURE_RG
, NULL
},
1488 {WINED3DFMT_R32G32B32_FLOAT
, GL_RGB32F
, GL_RGB32F
, 0,
1489 GL_RGB
, GL_FLOAT
, 0,
1490 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1491 ARB_TEXTURE_FLOAT
, NULL
},
1492 {WINED3DFMT_R32G32B32A32_FLOAT
, GL_RGBA32F_ARB
, GL_RGBA32F_ARB
, 0,
1493 GL_RGBA
, GL_FLOAT
, 0,
1494 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1495 ARB_TEXTURE_FLOAT
, NULL
},
1497 {WINED3DFMT_R16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1498 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1499 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1500 ARB_TEXTURE_FLOAT
, NULL
},
1501 {WINED3DFMT_R16_FLOAT
, GL_R16F
, GL_R16F
, 0,
1502 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1503 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1504 ARB_TEXTURE_RG
, NULL
},
1505 {WINED3DFMT_R16G16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1506 GL_RGB
, GL_HALF_FLOAT_ARB
, 6,
1507 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1508 ARB_TEXTURE_FLOAT
, convert_r16g16
},
1509 {WINED3DFMT_R16G16_FLOAT
, GL_RG16F
, GL_RG16F
, 0,
1510 GL_RG
, GL_HALF_FLOAT_ARB
, 0,
1511 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1512 ARB_TEXTURE_RG
, NULL
},
1513 {WINED3DFMT_R16G16B16A16_FLOAT
, GL_RGBA16F_ARB
, GL_RGBA16F_ARB
, 0,
1514 GL_RGBA
, GL_HALF_FLOAT_ARB
, 0,
1515 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
1516 | WINED3DFMT_FLAG_VTF
,
1517 ARB_TEXTURE_FLOAT
, NULL
},
1518 {WINED3DFMT_R11G11B10_FLOAT
, GL_R11F_G11F_B10F
, GL_R11F_G11F_B10F
, 0,
1519 GL_RGB
, GL_UNSIGNED_INT_10F_11F_11F_REV
, 0,
1520 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
,
1522 /* Palettized formats */
1523 {WINED3DFMT_P8_UINT
, GL_R8
, GL_R8
, 0,
1524 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1526 ARB_TEXTURE_RG
, NULL
},
1527 {WINED3DFMT_P8_UINT
, GL_ALPHA8
, GL_ALPHA8
, 0,
1528 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1530 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1531 /* Standard ARGB formats */
1532 {WINED3DFMT_B8G8R8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1533 GL_BGR
, GL_UNSIGNED_BYTE
, 0,
1534 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
| WINED3DFMT_FLAG_RENDERTARGET
,
1535 WINED3D_GL_EXT_NONE
, NULL
},
1536 {WINED3DFMT_B8G8R8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1537 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1538 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1539 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1540 | WINED3DFMT_FLAG_VTF
,
1541 WINED3D_GL_EXT_NONE
, NULL
},
1542 {WINED3DFMT_B8G8R8X8_UNORM
, GL_RGB8
, GL_SRGB8_EXT
, 0,
1543 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1544 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1545 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
,
1546 WINED3D_GL_EXT_NONE
, NULL
},
1547 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB5
, GL_SRGB8_EXT
, GL_RGB8
,
1548 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1549 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1550 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
,
1551 WINED3D_GL_EXT_NONE
, NULL
},
1552 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB565
, GL_SRGB8_EXT
, GL_RGB8
,
1553 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1554 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1555 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
,
1556 ARB_ES2_COMPATIBILITY
, NULL
},
1557 {WINED3DFMT_B5G5R5X1_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1558 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1559 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1560 | WINED3DFMT_FLAG_RENDERTARGET
,
1561 WINED3D_GL_EXT_NONE
, NULL
},
1562 {WINED3DFMT_B5G5R5A1_UNORM
, GL_RGB5_A1
, GL_RGB5_A1
, 0,
1563 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1564 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1565 WINED3D_GL_EXT_NONE
, NULL
},
1566 {WINED3DFMT_B4G4R4A4_UNORM
, GL_RGBA4
, GL_SRGB8_ALPHA8_EXT
, 0,
1567 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1568 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1569 | WINED3DFMT_FLAG_SRGB_READ
,
1570 WINED3D_GL_EXT_NONE
, NULL
},
1571 {WINED3DFMT_B2G3R3_UNORM
, GL_R3_G3_B2
, GL_R3_G3_B2
, 0,
1572 GL_RGB
, GL_UNSIGNED_BYTE_3_3_2
, 0,
1573 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1574 WINED3D_GL_EXT_NONE
, NULL
},
1575 {WINED3DFMT_R8_UNORM
, GL_R8
, GL_R8
, 0,
1576 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1577 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1578 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1579 ARB_TEXTURE_RG
, NULL
},
1580 {WINED3DFMT_A8_UNORM
, GL_R8
, GL_R8
, 0,
1581 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1582 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1583 | WINED3DFMT_FLAG_RENDERTARGET
,
1584 ARB_TEXTURE_RG
, NULL
},
1585 {WINED3DFMT_A8_UNORM
, GL_ALPHA8
, GL_ALPHA8
, 0,
1586 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1587 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1588 | WINED3DFMT_FLAG_RENDERTARGET
,
1589 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1590 {WINED3DFMT_B4G4R4X4_UNORM
, GL_RGB4
, GL_RGB4
, 0,
1591 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1592 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1593 WINED3D_GL_EXT_NONE
, NULL
},
1594 {WINED3DFMT_R10G10B10A2_UINT
, GL_RGB10_A2UI
, GL_RGB10_A2UI
, 0,
1595 GL_RGBA_INTEGER
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1596 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1597 ARB_TEXTURE_RGB10_A2UI
, NULL
},
1598 {WINED3DFMT_R10G10B10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1599 GL_RGBA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1600 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1601 | WINED3DFMT_FLAG_RENDERTARGET
,
1602 WINED3D_GL_EXT_NONE
, NULL
},
1603 {WINED3DFMT_R8G8B8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1604 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1605 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1606 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1607 | WINED3DFMT_FLAG_VTF
,
1608 WINED3D_GL_EXT_NONE
, NULL
},
1609 {WINED3DFMT_R8G8B8A8_UINT
, GL_RGBA8UI
, GL_RGBA8UI
, 0,
1610 GL_RGBA_INTEGER
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1611 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1612 ARB_TEXTURE_RGB10_A2UI
, NULL
},
1613 {WINED3DFMT_R8G8B8A8_SINT
, GL_RGBA8I
, GL_RGBA8I
, 0,
1614 GL_RGBA_INTEGER
, GL_BYTE
, 0,
1615 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1616 EXT_TEXTURE_INTEGER
, NULL
},
1617 {WINED3DFMT_R8G8B8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1618 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1619 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1620 WINED3D_GL_EXT_NONE
, NULL
},
1621 {WINED3DFMT_R16G16_UNORM
, GL_RGB16
, GL_RGB16
, GL_RGBA16
,
1622 GL_RGB
, GL_UNSIGNED_SHORT
, 6,
1623 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1624 WINED3D_GL_EXT_NONE
, convert_r16g16
},
1625 {WINED3DFMT_R16G16_UNORM
, GL_RG16
, GL_RG16
, 0,
1626 GL_RG
, GL_UNSIGNED_SHORT
, 0,
1627 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1628 | WINED3DFMT_FLAG_RENDERTARGET
,
1629 ARB_TEXTURE_RG
, NULL
},
1630 {WINED3DFMT_B10G10R10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1631 GL_BGRA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1632 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1633 | WINED3DFMT_FLAG_RENDERTARGET
,
1634 WINED3D_GL_EXT_NONE
, NULL
},
1635 {WINED3DFMT_R16G16B16A16_UNORM
, GL_RGBA16
, GL_RGBA16
, 0,
1636 GL_RGBA
, GL_UNSIGNED_SHORT
, 0,
1637 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1638 | WINED3DFMT_FLAG_RENDERTARGET
,
1639 WINED3D_GL_EXT_NONE
, NULL
},
1640 {WINED3DFMT_R8G8_UNORM
, GL_RG8
, GL_RG8
, 0,
1641 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1642 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1643 | WINED3DFMT_FLAG_RENDERTARGET
,
1644 ARB_TEXTURE_RG
, NULL
},
1645 {WINED3DFMT_R8G8_UINT
, GL_RG8UI
, GL_RG8UI
, 0,
1646 GL_RG_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1647 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1648 ARB_TEXTURE_RG
, NULL
},
1649 {WINED3DFMT_R8G8_SINT
, GL_RG8I
, GL_RG8I
, 0,
1650 GL_RG_INTEGER
, GL_BYTE
, 0,
1651 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1652 ARB_TEXTURE_RG
, NULL
},
1653 {WINED3DFMT_R16G16B16A16_UINT
, GL_RGBA16UI
, GL_RGBA16UI
, 0,
1654 GL_RGBA_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1655 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1656 EXT_TEXTURE_INTEGER
, NULL
},
1657 {WINED3DFMT_R16G16B16A16_SINT
, GL_RGBA16I
, GL_RGBA16I
, 0,
1658 GL_RGBA_INTEGER
, GL_SHORT
, 0,
1659 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1660 EXT_TEXTURE_INTEGER
, NULL
},
1661 {WINED3DFMT_R32G32_UINT
, GL_RG32UI
, GL_RG32UI
, 0,
1662 GL_RG_INTEGER
, GL_UNSIGNED_INT
, 0,
1663 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1664 ARB_TEXTURE_RG
, NULL
},
1665 {WINED3DFMT_R32G32_SINT
, GL_RG32I
, GL_RG32I
, 0,
1666 GL_RG_INTEGER
, GL_INT
, 0,
1667 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1668 ARB_TEXTURE_RG
, NULL
},
1669 {WINED3DFMT_R16G16_UINT
, GL_RG16UI
, GL_RG16UI
, 0,
1670 GL_RG_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1671 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1672 ARB_TEXTURE_RG
, NULL
},
1673 {WINED3DFMT_R16G16_SINT
, GL_RG16I
, GL_RG16I
, 0,
1674 GL_RG_INTEGER
, GL_SHORT
, 0,
1675 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1676 ARB_TEXTURE_RG
, NULL
},
1677 {WINED3DFMT_R32_UINT
, GL_R32UI
, GL_R32UI
, 0,
1678 GL_RED_INTEGER
, GL_UNSIGNED_INT
, 0,
1679 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1680 ARB_TEXTURE_RG
, NULL
},
1681 {WINED3DFMT_R32_SINT
, GL_R32I
, GL_R32I
, 0,
1682 GL_RED_INTEGER
, GL_INT
, 0,
1683 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1684 ARB_TEXTURE_RG
, NULL
},
1685 {WINED3DFMT_R16_UNORM
, GL_R16
, GL_R16
, 0,
1686 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1687 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1688 | WINED3DFMT_FLAG_RENDERTARGET
,
1689 ARB_TEXTURE_RG
, NULL
},
1690 {WINED3DFMT_R16_UINT
, GL_R16UI
, GL_R16UI
, 0,
1691 GL_RED_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1692 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1693 ARB_TEXTURE_RG
, NULL
},
1694 {WINED3DFMT_R16_SINT
, GL_R16I
, GL_R16I
, 0,
1695 GL_RED_INTEGER
, GL_SHORT
, 0,
1696 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1697 ARB_TEXTURE_RG
, NULL
},
1698 {WINED3DFMT_R8_UINT
, GL_R8UI
, GL_R8UI
, 0,
1699 GL_RED_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1700 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1701 ARB_TEXTURE_RG
, NULL
},
1702 {WINED3DFMT_R8_SINT
, GL_R8I
, GL_R8I
, 0,
1703 GL_RED_INTEGER
, GL_BYTE
, 0,
1704 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1705 ARB_TEXTURE_RG
, NULL
},
1707 {WINED3DFMT_L8_UNORM
, GL_LUMINANCE8
, GL_SLUMINANCE8_EXT
, 0,
1708 GL_LUMINANCE
, GL_UNSIGNED_BYTE
, 0,
1709 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1710 | WINED3DFMT_FLAG_SRGB_READ
,
1711 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1712 {WINED3DFMT_L8_UNORM
, GL_R8
, GL_R8
, 0,
1713 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1714 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1715 | WINED3DFMT_FLAG_RENDERTARGET
,
1716 ARB_TEXTURE_RG
, NULL
},
1717 {WINED3DFMT_L8A8_UNORM
, GL_RG8
, GL_RG8
, 0,
1718 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1719 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1720 ARB_TEXTURE_RG
, NULL
},
1721 {WINED3DFMT_L8A8_UNORM
, GL_LUMINANCE8_ALPHA8
, GL_SLUMINANCE8_ALPHA8_EXT
, 0,
1722 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1723 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1724 | WINED3DFMT_FLAG_SRGB_READ
,
1725 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1726 {WINED3DFMT_L4A4_UNORM
, GL_RG8
, GL_RG8
, 0,
1727 GL_RG
, GL_UNSIGNED_BYTE
, 2,
1728 WINED3DFMT_FLAG_FILTERING
,
1729 ARB_TEXTURE_RG
, convert_l4a4_unorm
},
1730 {WINED3DFMT_L4A4_UNORM
, GL_LUMINANCE4_ALPHA4
, GL_LUMINANCE4_ALPHA4
, 0,
1731 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 2,
1732 WINED3DFMT_FLAG_FILTERING
,
1733 WINED3D_GL_LEGACY_CONTEXT
, convert_l4a4_unorm
},
1734 {WINED3DFMT_L16_UNORM
, GL_R16
, GL_R16
, 0,
1735 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1736 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1737 ARB_TEXTURE_RG
, NULL
},
1738 {WINED3DFMT_L16_UNORM
, GL_LUMINANCE16
, GL_LUMINANCE16
, 0,
1739 GL_LUMINANCE
, GL_UNSIGNED_SHORT
, 0,
1740 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1741 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1742 /* Bump mapping stuff */
1743 {WINED3DFMT_R8G8_SNORM
, GL_RGB8
, GL_RGB8
, 0,
1744 GL_BGR
, GL_UNSIGNED_BYTE
, 3,
1745 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1746 | WINED3DFMT_FLAG_BUMPMAP
,
1747 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm
},
1748 {WINED3DFMT_R8G8_SNORM
, GL_DSDT8_NV
, GL_DSDT8_NV
, 0,
1749 GL_DSDT_NV
, GL_BYTE
, 0,
1750 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1751 | WINED3DFMT_FLAG_BUMPMAP
,
1752 NV_TEXTURE_SHADER
, NULL
},
1753 {WINED3DFMT_R8G8_SNORM
, GL_RG8_SNORM
, GL_RG8_SNORM
, 0,
1755 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1756 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1757 EXT_TEXTURE_SNORM
, NULL
},
1758 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1759 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 2,
1760 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1761 | WINED3DFMT_FLAG_BUMPMAP
,
1762 WINED3D_GL_EXT_NONE
, convert_r5g5_snorm_l6_unorm
},
1763 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_DSDT8_MAG8_NV
, GL_DSDT8_MAG8_NV
, 0,
1764 GL_DSDT_MAG_NV
, GL_BYTE
, 3,
1765 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1766 | WINED3DFMT_FLAG_BUMPMAP
,
1767 NV_TEXTURE_SHADER
, convert_r5g5_snorm_l6_unorm_nv
},
1768 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB8_SNORM
, GL_RGB8_SNORM
, 0,
1769 GL_RGBA
, GL_BYTE
, 4,
1770 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1771 | WINED3DFMT_FLAG_BUMPMAP
,
1772 EXT_TEXTURE_SNORM
, convert_r5g5_snorm_l6_unorm_ext
},
1773 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1774 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4,
1775 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1776 | WINED3DFMT_FLAG_BUMPMAP
,
1777 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm_l8x8_unorm
},
1778 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_DSDT8_MAG8_INTENSITY8_NV
, GL_DSDT8_MAG8_INTENSITY8_NV
, 0,
1779 GL_DSDT_MAG_VIB_NV
, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV
, 4,
1780 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1781 | WINED3DFMT_FLAG_BUMPMAP
,
1782 NV_TEXTURE_SHADER
, convert_r8g8_snorm_l8x8_unorm_nv
},
1783 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8
, GL_RGBA8
, 0,
1784 GL_BGRA
, GL_UNSIGNED_BYTE
, 4,
1785 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1786 | WINED3DFMT_FLAG_BUMPMAP
,
1787 WINED3D_GL_EXT_NONE
, convert_r8g8b8a8_snorm
},
1788 {WINED3DFMT_R8G8B8A8_SNORM
, GL_SIGNED_RGBA8_NV
, GL_SIGNED_RGBA8_NV
, 0,
1789 GL_RGBA
, GL_BYTE
, 0,
1790 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1791 | WINED3DFMT_FLAG_BUMPMAP
,
1792 NV_TEXTURE_SHADER
, NULL
},
1793 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8_SNORM
, GL_RGBA8_SNORM
, 0,
1794 GL_RGBA
, GL_BYTE
, 0,
1795 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1796 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1797 EXT_TEXTURE_SNORM
, NULL
},
1798 {WINED3DFMT_R16G16_SNORM
, GL_RGB16
, GL_RGB16
, 0,
1799 GL_BGR
, GL_UNSIGNED_SHORT
, 6,
1800 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1801 | WINED3DFMT_FLAG_BUMPMAP
,
1802 WINED3D_GL_EXT_NONE
, convert_r16g16_snorm
},
1803 {WINED3DFMT_R16G16_SNORM
, GL_SIGNED_HILO16_NV
, GL_SIGNED_HILO16_NV
, 0,
1804 GL_HILO_NV
, GL_SHORT
, 0,
1805 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1806 | WINED3DFMT_FLAG_BUMPMAP
,
1807 NV_TEXTURE_SHADER
, NULL
},
1808 {WINED3DFMT_R16G16_SNORM
, GL_RG16_SNORM
, GL_RG16_SNORM
, 0,
1810 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1811 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1812 EXT_TEXTURE_SNORM
, NULL
},
1813 {WINED3DFMT_R16G16B16A16_SNORM
, GL_RGBA16_SNORM
, GL_RGBA16_SNORM
, 0,
1814 GL_RGBA
, GL_SHORT
, 0,
1815 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1816 | WINED3DFMT_FLAG_RENDERTARGET
,
1817 EXT_TEXTURE_SNORM
, NULL
},
1818 {WINED3DFMT_R16_SNORM
, GL_R16_SNORM
, GL_R16_SNORM
, 0,
1819 GL_RED
, GL_SHORT
, 0,
1820 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1821 | WINED3DFMT_FLAG_RENDERTARGET
,
1822 EXT_TEXTURE_SNORM
, NULL
},
1823 {WINED3DFMT_R8_SNORM
, GL_R8_SNORM
, GL_R8_SNORM
, 0,
1825 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1826 | WINED3DFMT_FLAG_RENDERTARGET
,
1827 EXT_TEXTURE_SNORM
, NULL
},
1828 /* Depth stencil formats */
1829 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1830 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1831 WINED3DFMT_FLAG_DEPTH_STENCIL
,
1832 WINED3D_GL_EXT_NONE
, NULL
},
1833 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT16
, GL_DEPTH_COMPONENT16
, 0,
1834 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1835 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1836 ARB_DEPTH_TEXTURE
, NULL
},
1837 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1838 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1839 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1840 | WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1841 ARB_DEPTH_TEXTURE
, NULL
},
1842 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1843 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1844 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1845 | WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1846 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1847 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1848 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 4,
1849 WINED3DFMT_FLAG_DEPTH_STENCIL
,
1850 WINED3D_GL_EXT_NONE
, x8_d24_unorm_upload
, x8_d24_unorm_download
},
1851 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1852 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 4,
1853 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1854 | WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1855 ARB_DEPTH_TEXTURE
, x8_d24_unorm_upload
, x8_d24_unorm_download
},
1856 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1857 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1858 WINED3DFMT_FLAG_DEPTH_STENCIL
,
1859 WINED3D_GL_EXT_NONE
, NULL
},
1860 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT16
, GL_DEPTH_COMPONENT16
, 0,
1861 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1862 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1863 | WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1864 ARB_DEPTH_TEXTURE
, NULL
},
1865 {WINED3DFMT_D32_FLOAT
, GL_DEPTH_COMPONENT32F
, GL_DEPTH_COMPONENT32F
, 0,
1866 GL_DEPTH_COMPONENT
, GL_FLOAT
, 0,
1867 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1868 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1869 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1870 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 0,
1871 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1872 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1873 {WINED3DFMT_S8_UINT_D24_FLOAT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1874 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 8,
1875 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1876 ARB_DEPTH_BUFFER_FLOAT
, convert_s8_uint_d24_float
},
1877 {WINED3DFMT_R32G32B32A32_UINT
, GL_RGBA32UI
, GL_RGBA32UI
, 0,
1878 GL_RGBA_INTEGER
, GL_UNSIGNED_INT
, 0,
1879 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1880 EXT_TEXTURE_INTEGER
, NULL
},
1881 {WINED3DFMT_R32G32B32A32_SINT
, GL_RGBA32I
, GL_RGBA32I
, 0,
1882 GL_RGBA_INTEGER
, GL_INT
, 0,
1883 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1884 EXT_TEXTURE_INTEGER
, NULL
},
1885 /* Vendor-specific formats */
1886 {WINED3DFMT_ATI1N
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1887 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1888 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1889 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1890 {WINED3DFMT_ATI2N
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, 0,
1891 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1892 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1893 ATI_TEXTURE_COMPRESSION_3DC
, NULL
},
1894 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1895 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1896 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1897 EXT_TEXTURE_COMPRESSION_RGTC
, NULL
},
1898 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1899 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1900 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1901 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1902 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1903 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1904 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1905 | WINED3DFMT_FLAG_DEPTH_STENCIL
,
1906 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1907 {WINED3DFMT_NULL
, 0, 0, 0,
1908 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1909 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
,
1910 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1911 /* DirectX 10 HDR formats */
1912 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, GL_RGB9_E5_EXT
, GL_RGB9_E5_EXT
, 0,
1913 GL_RGB
, GL_UNSIGNED_INT_5_9_9_9_REV_EXT
, 0,
1914 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1915 EXT_TEXTURE_SHARED_EXPONENT
, NULL
},
1918 struct wined3d_format_srgb_info
1920 enum wined3d_format_id srgb_format_id
;
1921 enum wined3d_format_id base_format_id
;
1924 static const struct wined3d_format_srgb_info format_srgb_info
[] =
1926 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_UNORM
},
1927 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_UNORM
},
1928 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_UNORM
},
1929 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_UNORM
},
1930 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_UNORM
},
1931 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_UNORM
},
1932 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_UNORM
},
1935 static inline int get_format_idx(enum wined3d_format_id format_id
)
1939 if (format_id
< WINED3D_FORMAT_FOURCC_BASE
)
1942 for (i
= 0; i
< ARRAY_SIZE(format_index_remap
); ++i
)
1944 if (format_index_remap
[i
].id
== format_id
)
1945 return format_index_remap
[i
].idx
;
1951 static struct wined3d_format_gl
*wined3d_format_gl_mutable(struct wined3d_format
*format
)
1953 return CONTAINING_RECORD(format
, struct wined3d_format_gl
, f
);
1956 static struct wined3d_format_vk
*wined3d_format_vk_mutable(struct wined3d_format
*format
)
1958 return CONTAINING_RECORD(format
, struct wined3d_format_vk
, f
);
1961 static struct wined3d_format
*get_format_by_idx(const struct wined3d_adapter
*adapter
, int fmt_idx
)
1963 return (struct wined3d_format
*)((BYTE
*)adapter
->formats
+ fmt_idx
* adapter
->format_size
);
1966 static struct wined3d_format_gl
*get_format_gl_by_idx(const struct wined3d_adapter
*adapter
, int fmt_idx
)
1968 return wined3d_format_gl_mutable(get_format_by_idx(adapter
, fmt_idx
));
1971 static struct wined3d_format
*get_format_internal(const struct wined3d_adapter
*adapter
,
1972 enum wined3d_format_id format_id
)
1976 if ((fmt_idx
= get_format_idx(format_id
)) == -1)
1978 ERR("Format %s (%#x) not found.\n", debug_d3dformat(format_id
), format_id
);
1982 return get_format_by_idx(adapter
, fmt_idx
);
1985 static struct wined3d_format_gl
*get_format_gl_internal(const struct wined3d_adapter
*adapter
,
1986 enum wined3d_format_id format_id
)
1988 struct wined3d_format
*format
;
1990 if ((format
= get_format_internal(adapter
, format_id
)))
1991 return wined3d_format_gl_mutable(format
);
1996 static void copy_format(const struct wined3d_adapter
*adapter
,
1997 struct wined3d_format
*dst_format
, const struct wined3d_format
*src_format
)
1999 enum wined3d_format_id id
= dst_format
->id
;
2000 memcpy(dst_format
, src_format
, adapter
->format_size
);
2001 dst_format
->id
= id
;
2004 static void format_set_flag(struct wined3d_format
*format
, unsigned int flag
)
2008 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
2009 format
->flags
[i
] |= flag
;
2012 static void format_clear_flag(struct wined3d_format
*format
, unsigned int flag
)
2016 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
2017 format
->flags
[i
] &= ~flag
;
2020 static enum wined3d_channel_type
map_channel_type(char t
)
2025 return WINED3D_CHANNEL_TYPE_UNORM
;
2027 return WINED3D_CHANNEL_TYPE_SNORM
;
2029 return WINED3D_CHANNEL_TYPE_UINT
;
2031 return WINED3D_CHANNEL_TYPE_SINT
;
2033 return WINED3D_CHANNEL_TYPE_FLOAT
;
2035 return WINED3D_CHANNEL_TYPE_DEPTH
;
2037 return WINED3D_CHANNEL_TYPE_STENCIL
;
2039 return WINED3D_CHANNEL_TYPE_UNUSED
;
2041 ERR("Invalid channel type '%c'.\n", t
);
2042 return WINED3D_CHANNEL_TYPE_NONE
;
2046 static BOOL
init_format_base_info(struct wined3d_adapter
*adapter
)
2048 struct wined3d_format
*format
;
2051 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
2053 if (!(format
= get_format_internal(adapter
, formats
[i
].id
)))
2056 format
->id
= formats
[i
].id
;
2057 format
->red_size
= formats
[i
].red_size
;
2058 format
->green_size
= formats
[i
].green_size
;
2059 format
->blue_size
= formats
[i
].blue_size
;
2060 format
->alpha_size
= formats
[i
].alpha_size
;
2061 format
->red_offset
= formats
[i
].red_offset
;
2062 format
->green_offset
= formats
[i
].green_offset
;
2063 format
->blue_offset
= formats
[i
].blue_offset
;
2064 format
->alpha_offset
= formats
[i
].alpha_offset
;
2065 format
->byte_count
= formats
[i
].bpp
;
2066 format
->depth_size
= formats
[i
].depth_size
;
2067 format
->stencil_size
= formats
[i
].stencil_size
;
2068 format
->block_width
= 1;
2069 format
->block_height
= 1;
2070 format
->block_byte_count
= formats
[i
].bpp
;
2073 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
2075 struct wined3d_format
*typeless_format
;
2076 unsigned int component_count
= 0;
2079 if (!(format
= get_format_internal(adapter
, typed_formats
[i
].id
)))
2082 if (!(typeless_format
= get_format_internal(adapter
, typed_formats
[i
].typeless_id
)))
2085 format
->id
= typed_formats
[i
].id
;
2086 format
->red_size
= typeless_format
->red_size
;
2087 format
->green_size
= typeless_format
->green_size
;
2088 format
->blue_size
= typeless_format
->blue_size
;
2089 format
->alpha_size
= typeless_format
->alpha_size
;
2090 format
->red_offset
= typeless_format
->red_offset
;
2091 format
->green_offset
= typeless_format
->green_offset
;
2092 format
->blue_offset
= typeless_format
->blue_offset
;
2093 format
->alpha_offset
= typeless_format
->alpha_offset
;
2094 format
->byte_count
= typeless_format
->byte_count
;
2095 format
->depth_size
= typeless_format
->depth_size
;
2096 format
->stencil_size
= typeless_format
->stencil_size
;
2097 format
->block_width
= typeless_format
->block_width
;
2098 format
->block_height
= typeless_format
->block_height
;
2099 format
->block_byte_count
= typeless_format
->block_byte_count
;
2100 format
->typeless_id
= typeless_format
->id
;
2102 typeless_format
->typeless_id
= typeless_format
->id
;
2104 for (j
= 0; j
< strlen(typed_formats
[i
].channels
); ++j
)
2106 enum wined3d_channel_type channel_type
= map_channel_type(typed_formats
[i
].channels
[j
]);
2108 if (channel_type
== WINED3D_CHANNEL_TYPE_UNORM
|| channel_type
== WINED3D_CHANNEL_TYPE_SNORM
)
2109 flags
|= WINED3DFMT_FLAG_NORMALISED
;
2110 if (channel_type
== WINED3D_CHANNEL_TYPE_UINT
|| channel_type
== WINED3D_CHANNEL_TYPE_SINT
)
2111 flags
|= WINED3DFMT_FLAG_INTEGER
;
2112 if (channel_type
== WINED3D_CHANNEL_TYPE_FLOAT
)
2113 flags
|= WINED3DFMT_FLAG_FLOAT
;
2114 if (channel_type
!= WINED3D_CHANNEL_TYPE_UNUSED
)
2117 if (channel_type
== WINED3D_CHANNEL_TYPE_DEPTH
&& !format
->depth_size
)
2119 format
->depth_size
= format
->red_size
;
2120 format
->red_size
= format
->red_offset
= 0;
2123 if (channel_type
== WINED3D_CHANNEL_TYPE_STENCIL
&& !format
->stencil_size
)
2125 format
->stencil_size
= format
->green_size
;
2126 format
->green_size
= format
->green_offset
= 0;
2130 format
->component_count
= component_count
;
2131 format_set_flag(format
, flags
);
2134 for (i
= 0; i
< ARRAY_SIZE(ddi_formats
); ++i
)
2136 if (!(format
= get_format_internal(adapter
, ddi_formats
[i
].id
)))
2139 format
->ddi_format
= ddi_formats
[i
].ddi_format
;
2142 for (i
= 0; i
< ARRAY_SIZE(format_base_flags
); ++i
)
2144 if (!(format
= get_format_internal(adapter
, format_base_flags
[i
].id
)))
2147 format_set_flag(format
, format_base_flags
[i
].flags
);
2153 static BOOL
init_format_block_info(struct wined3d_adapter
*adapter
)
2155 struct wined3d_format
*format
;
2158 for (i
= 0; i
< ARRAY_SIZE(format_block_info
); ++i
)
2160 if (!(format
= get_format_internal(adapter
, format_block_info
[i
].id
)))
2163 format
->block_width
= format_block_info
[i
].block_width
;
2164 format
->block_height
= format_block_info
[i
].block_height
;
2165 format
->block_byte_count
= format_block_info
[i
].block_byte_count
;
2166 format_set_flag(format
, WINED3DFMT_FLAG_BLOCKS
| format_block_info
[i
].flags
);
2172 /* Most compressed formats are not supported for 3D textures by OpenGL.
2174 * In the case of the S3TC/DXTn formats, NV_texture_compression_vtc provides
2175 * these formats for 3D textures, but unfortunately the block layout is
2176 * different from the one used by Direct3D.
2178 * Since applications either don't check format availability at all before
2179 * using these, or refuse to run without them, we decompress them on upload.
2181 * Affected applications include "Heroes VI", "From Dust", "Halo Online" and
2183 static BOOL
init_format_decompress_info(struct wined3d_adapter
*adapter
)
2185 struct wined3d_format
*format
;
2188 for (i
= 0; i
< ARRAY_SIZE(format_decompress_info
); ++i
)
2190 if (!(format
= get_format_internal(adapter
, format_decompress_info
[i
].id
)))
2193 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] |= WINED3DFMT_FLAG_DECOMPRESS
;
2194 format
->decompress
= format_decompress_info
[i
].decompress
;
2200 static BOOL
init_srgb_formats(struct wined3d_adapter
*adapter
)
2202 struct wined3d_format
*format
, *srgb_format
;
2205 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
2207 if (!(srgb_format
= get_format_internal(adapter
, format_srgb_info
[i
].srgb_format_id
)))
2209 if (!(format
= get_format_internal(adapter
, format_srgb_info
[i
].base_format_id
)))
2212 copy_format(adapter
, srgb_format
, format
);
2218 static GLenum
wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type
)
2222 case WINED3D_GL_RES_TYPE_TEX_1D
:
2223 return GL_TEXTURE_1D
;
2224 case WINED3D_GL_RES_TYPE_TEX_2D
:
2225 return GL_TEXTURE_2D
;
2226 case WINED3D_GL_RES_TYPE_TEX_3D
:
2227 return GL_TEXTURE_3D
;
2228 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2229 return GL_TEXTURE_CUBE_MAP_ARB
;
2230 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2231 return GL_TEXTURE_RECTANGLE_ARB
;
2232 case WINED3D_GL_RES_TYPE_BUFFER
:
2233 return GL_TEXTURE_2D
; /* TODO: GL_TEXTURE_BUFFER. */
2234 case WINED3D_GL_RES_TYPE_RB
:
2235 return GL_RENDERBUFFER
;
2236 case WINED3D_GL_RES_TYPE_COUNT
:
2239 ERR("Unexpected GL resource type %u.\n", type
);
2243 static void delete_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
2244 enum wined3d_gl_resource_type d3d_type
, GLuint object
)
2248 case WINED3D_GL_RES_TYPE_TEX_1D
:
2249 case WINED3D_GL_RES_TYPE_TEX_2D
:
2250 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2251 case WINED3D_GL_RES_TYPE_TEX_3D
:
2252 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2253 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &object
);
2256 case WINED3D_GL_RES_TYPE_RB
:
2257 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &object
);
2260 case WINED3D_GL_RES_TYPE_BUFFER
:
2261 case WINED3D_GL_RES_TYPE_COUNT
:
2266 static void create_and_bind_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
2267 const struct wined3d_format_gl
*format_gl
,
2268 enum wined3d_gl_resource_type d3d_type
, GLuint
*object
, GLenum internal
)
2270 GLenum format
= format_gl
->format
;
2271 GLenum type
= format_gl
->type
;
2274 attach_type
= format_gl
->f
.depth_size
? GL_DEPTH_ATTACHMENT
: GL_COLOR_ATTACHMENT0
;
2277 case WINED3D_GL_RES_TYPE_TEX_1D
:
2278 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2279 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, *object
);
2280 gl_info
->gl_ops
.gl
.p_glTexImage1D(GL_TEXTURE_1D
, 0, internal
, 16, 0, format
, type
, NULL
);
2281 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2282 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2284 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_1D
, *object
, 0);
2285 if (format_gl
->f
.stencil_size
)
2286 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
,
2287 GL_STENCIL_ATTACHMENT
, GL_TEXTURE_1D
, *object
, 0);
2290 case WINED3D_GL_RES_TYPE_TEX_2D
:
2291 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2292 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2293 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(d3d_type
), *object
);
2294 gl_info
->gl_ops
.gl
.p_glTexImage2D(wined3d_gl_type_to_enum(d3d_type
), 0, internal
, 16, 16, 0,
2295 format
, type
, NULL
);
2296 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2297 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2299 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
2300 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
2301 if (format_gl
->f
.stencil_size
)
2302 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
2303 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
2306 case WINED3D_GL_RES_TYPE_TEX_3D
:
2307 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2308 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_3D
, *object
);
2309 GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D
, 0, internal
, 16, 16, 16, 0, format
, type
, NULL
));
2310 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2311 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2313 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_3D
, *object
, 0, 0);
2314 if (format_gl
->f
.stencil_size
)
2315 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
,
2316 GL_STENCIL_ATTACHMENT
, GL_TEXTURE_3D
, *object
, 0, 0);
2319 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2320 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2321 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, *object
);
2322 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, internal
, 16, 16, 0,
2323 format
, type
, NULL
);
2324 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
, 0, internal
, 16, 16, 0,
2325 format
, type
, NULL
);
2326 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
, 0, internal
, 16, 16, 0,
2327 format
, type
, NULL
);
2328 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
, 0, internal
, 16, 16, 0,
2329 format
, type
, NULL
);
2330 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
, 0, internal
, 16, 16, 0,
2331 format
, type
, NULL
);
2332 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
, 0, internal
, 16, 16, 0,
2333 format
, type
, NULL
);
2334 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2335 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2337 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
2338 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
2339 if (format_gl
->f
.stencil_size
)
2340 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
2341 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
2344 case WINED3D_GL_RES_TYPE_RB
:
2345 gl_info
->fbo_ops
.glGenRenderbuffers(1, object
);
2346 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, *object
);
2347 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, internal
, 16, 16);
2348 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, attach_type
, GL_RENDERBUFFER
, *object
);
2349 if (format_gl
->f
.stencil_size
)
2350 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2351 GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, *object
);
2354 case WINED3D_GL_RES_TYPE_BUFFER
:
2355 case WINED3D_GL_RES_TYPE_COUNT
:
2359 /* Ideally we'd skip all formats already known not to work on textures
2360 * by checking for WINED3DFMT_FLAG_TEXTURE here. However, we want to
2361 * know if we can attach WINED3DFMT_P8_UINT textures to FBOs, and this
2362 * format never has WINED3DFMT_FLAG_TEXTURE set. Instead, swallow GL
2363 * errors generated by invalid formats. */
2364 while (gl_info
->gl_ops
.gl
.p_glGetError());
2367 static void draw_test_quad(struct wined3d_caps_gl_ctx
*ctx
, const struct wined3d_vec3
*geometry
,
2368 const struct wined3d_color
*color
)
2370 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2371 static const struct wined3d_vec3 default_geometry
[] =
2373 {-1.0f
, -1.0f
, 0.0f
},
2374 { 1.0f
, -1.0f
, 0.0f
},
2375 {-1.0f
, 1.0f
, 0.0f
},
2376 { 1.0f
, 1.0f
, 0.0f
},
2378 static const char vs_core_header
[] =
2382 "out vec4 out_color;\n"
2384 static const char vs_legacy_header
[] =
2386 "attribute vec4 pos;\n"
2387 "attribute vec4 color;\n"
2388 "varying vec4 out_color;\n"
2390 static const char vs_body
[] =
2393 " gl_Position = pos;\n"
2394 " out_color = color;\n"
2396 static const char fs_core
[] =
2398 "in vec4 out_color;\n"
2399 "out vec4 fragment_color;\n"
2403 " fragment_color = out_color;\n"
2405 static const char fs_legacy
[] =
2407 "varying vec4 out_color;\n"
2411 " gl_FragData[0] = out_color;\n"
2413 const char *source
[2];
2414 GLuint vs_id
, fs_id
;
2418 geometry
= default_geometry
;
2420 if (!gl_info
->supported
[ARB_VERTEX_BUFFER_OBJECT
] || !gl_info
->supported
[ARB_VERTEX_SHADER
]
2421 || !gl_info
->supported
[ARB_FRAGMENT_SHADER
])
2423 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
2424 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
2425 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2426 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
2427 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2429 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
2430 gl_info
->gl_ops
.gl
.p_glColor4f(color
->r
, color
->g
, color
->b
, color
->a
);
2431 for (i
= 0; i
< 4; ++i
)
2432 gl_info
->gl_ops
.gl
.p_glVertex3fv(&geometry
[i
].x
);
2433 gl_info
->gl_ops
.gl
.p_glEnd();
2434 checkGLcall("draw quad");
2439 GL_EXTCALL(glGenBuffers(1, &ctx
->test_vbo
));
2440 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, ctx
->test_vbo
));
2441 GL_EXTCALL(glBufferData(GL_ARRAY_BUFFER
, sizeof(struct wined3d_vec3
) * 4, geometry
, GL_STREAM_DRAW
));
2442 GL_EXTCALL(glVertexAttribPointer(0, 3, GL_FLOAT
, FALSE
, 0, NULL
));
2443 GL_EXTCALL(glVertexAttrib4f(1, color
->r
, color
->g
, color
->b
, color
->a
));
2444 GL_EXTCALL(glEnableVertexAttribArray(0));
2445 GL_EXTCALL(glDisableVertexAttribArray(1));
2447 if (!ctx
->test_program_id
)
2449 BOOL use_glsl_150
= gl_info
->glsl_version
>= MAKEDWORD_VERSION(1, 50);
2451 ctx
->test_program_id
= GL_EXTCALL(glCreateProgram());
2453 vs_id
= GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER
));
2454 source
[0] = use_glsl_150
? vs_core_header
: vs_legacy_header
;
2455 source
[1] = vs_body
;
2456 GL_EXTCALL(glShaderSource(vs_id
, 2, source
, NULL
));
2457 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, vs_id
));
2458 GL_EXTCALL(glDeleteShader(vs_id
));
2460 fs_id
= GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER
));
2461 source
[0] = use_glsl_150
? fs_core
: fs_legacy
;
2462 GL_EXTCALL(glShaderSource(fs_id
, 1, source
, NULL
));
2463 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, fs_id
));
2464 GL_EXTCALL(glDeleteShader(fs_id
));
2466 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 0, "pos"));
2467 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 1, "color"));
2470 GL_EXTCALL(glBindFragDataLocation(ctx
->test_program_id
, 0, "fragment_color"));
2472 GL_EXTCALL(glCompileShader(vs_id
));
2473 print_glsl_info_log(gl_info
, vs_id
, FALSE
);
2474 GL_EXTCALL(glCompileShader(fs_id
));
2475 print_glsl_info_log(gl_info
, fs_id
, FALSE
);
2476 GL_EXTCALL(glLinkProgram(ctx
->test_program_id
));
2477 shader_glsl_validate_link(gl_info
, ctx
->test_program_id
);
2479 GL_EXTCALL(glUseProgram(ctx
->test_program_id
));
2481 gl_info
->gl_ops
.gl
.p_glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
2483 GL_EXTCALL(glUseProgram(0));
2484 GL_EXTCALL(glDisableVertexAttribArray(0));
2485 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, 0));
2486 checkGLcall("draw quad");
2489 /* Context activation is done by the caller. */
2490 static void check_fbo_compat(struct wined3d_caps_gl_ctx
*ctx
, struct wined3d_format_gl
*format
)
2492 /* Check if the default internal format is supported as a frame buffer
2493 * target, otherwise fall back to the render target internal.
2495 * Try to stick to the standard format if possible, this limits precision differences. */
2496 static const struct wined3d_color black
= {0.0f
, 0.0f
, 0.0f
, 1.0f
};
2497 static const struct wined3d_color half_transparent_red
= {1.0f
, 0.0f
, 0.0f
, 0.5f
};
2498 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2499 GLenum status
, rt_internal
= format
->rt_internal
;
2500 GLuint object
, color_rb
;
2501 enum wined3d_gl_resource_type type
;
2502 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2504 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2506 for (type
= 0; type
< ARRAY_SIZE(format
->f
.flags
); ++type
)
2508 const char *type_string
= "color";
2510 if (type
== WINED3D_GL_RES_TYPE_BUFFER
)
2513 create_and_bind_fbo_attachment(gl_info
, format
, type
, &object
, format
->internal
);
2515 if (format
->f
.flags
[type
] & WINED3DFMT_FLAG_DEPTH_STENCIL
)
2517 gl_info
->fbo_ops
.glGenRenderbuffers(1, &color_rb
);
2518 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, color_rb
);
2519 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2520 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 1);
2522 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 16);
2524 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2525 GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, color_rb
);
2526 checkGLcall("Create and attach color rb attachment");
2527 type_string
= "depth / stencil";
2530 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2531 checkGLcall("Framebuffer format check");
2533 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2535 TRACE("Format %s is supported as FBO %s attachment, type %u.\n",
2536 debug_d3dformat(format
->f
.id
), type_string
, type
);
2537 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2538 format
->rt_internal
= format
->internal
;
2539 regular_fmt_used
= TRUE
;
2545 if (format
->f
.flags
[type
] & (WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH_STENCIL
))
2547 WARN("Format %s with rendertarget flag is not supported as FBO color attachment (type %u),"
2548 " and no fallback specified.\n", debug_d3dformat(format
->f
.id
), type
);
2549 format
->f
.flags
[type
] &= ~(WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH_STENCIL
);
2553 TRACE("Format %s is not supported as FBO %s attachment, type %u.\n",
2554 debug_d3dformat(format
->f
.id
), type_string
, type
);
2556 format
->rt_internal
= format
->internal
;
2560 TRACE("Format %s is not supported as FBO %s attachment (type %u),"
2561 " trying rtInternal format as fallback.\n",
2562 debug_d3dformat(format
->f
.id
), type_string
, type
);
2564 while (gl_info
->gl_ops
.gl
.p_glGetError());
2566 delete_fbo_attachment(gl_info
, type
, object
);
2567 create_and_bind_fbo_attachment(gl_info
, format
, type
, &object
, format
->rt_internal
);
2569 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2570 checkGLcall("Framebuffer format check");
2572 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2574 TRACE("Format %s rtInternal format is supported as FBO %s attachment, type %u.\n",
2575 debug_d3dformat(format
->f
.id
), type_string
, type
);
2576 fallback_fmt_used
= TRUE
;
2580 WARN("Format %s rtInternal format is not supported as FBO %s attachment, type %u.\n",
2581 debug_d3dformat(format
->f
.id
), type_string
, type
);
2582 format
->f
.flags
[type
] &= ~(WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH_STENCIL
);
2587 if (status
== GL_FRAMEBUFFER_COMPLETE
2588 && ((format
->f
.flags
[type
] & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
)
2589 || !(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2590 && !(format
->f
.flags
[type
] & WINED3DFMT_FLAG_INTEGER
)
2591 && format
->f
.id
!= WINED3DFMT_NULL
&& format
->f
.id
!= WINED3DFMT_P8_UINT
2592 && format
->format
!= GL_LUMINANCE
&& format
->format
!= GL_LUMINANCE_ALPHA
2593 && (format
->f
.red_size
|| format
->f
.alpha_size
))
2595 DWORD readback
[16 * 16 * 16], color
= 0, r_range
, a_range
;
2600 if (gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2602 gl_info
->fbo_ops
.glGenRenderbuffers(1, &rb
);
2603 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
2604 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2605 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 1);
2607 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 16);
2608 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2609 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2610 checkGLcall("RB attachment");
2613 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2614 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.0f
, 1.0f
);
2615 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
2616 if (gl_info
->gl_ops
.gl
.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION
)
2618 while (gl_info
->gl_ops
.gl
.p_glGetError());
2619 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2620 debug_d3dformat(format
->f
.id
), type
);
2621 format
->f
.flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2625 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2626 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2627 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2629 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 16);
2630 gl_info
->gl_ops
.gl
.p_glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2632 draw_test_quad(ctx
, NULL
, &black
);
2634 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2636 draw_test_quad(ctx
, NULL
, &half_transparent_red
);
2638 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2642 case WINED3D_GL_RES_TYPE_TEX_1D
:
2643 /* Rebinding texture to workaround a fglrx bug. */
2644 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, object
);
2645 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_1D
, 0, GL_BGRA
,
2646 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2647 color
= readback
[7];
2650 case WINED3D_GL_RES_TYPE_TEX_2D
:
2651 case WINED3D_GL_RES_TYPE_TEX_3D
:
2652 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2653 /* Rebinding texture to workaround a fglrx bug. */
2654 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(type
), object
);
2655 gl_info
->gl_ops
.gl
.p_glGetTexImage(wined3d_gl_type_to_enum(type
), 0, GL_BGRA
,
2656 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2657 color
= readback
[7 * 16 + 7];
2660 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2661 /* Rebinding texture to workaround a fglrx bug. */
2662 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, object
);
2663 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, GL_BGRA
,
2664 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2665 color
= readback
[7 * 16 + 7];
2668 case WINED3D_GL_RES_TYPE_RB
:
2669 gl_info
->gl_ops
.gl
.p_glReadPixels(0, 0, 16, 16,
2670 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2671 color
= readback
[7 * 16 + 7];
2674 case WINED3D_GL_RES_TYPE_BUFFER
:
2675 case WINED3D_GL_RES_TYPE_COUNT
:
2679 checkGLcall("Post-pixelshader blending check");
2682 r
= (color
& 0x00ff0000u
) >> 16;
2684 r_range
= format
->f
.red_size
< 8 ? 1u << (8 - format
->f
.red_size
) : 1;
2685 a_range
= format
->f
.alpha_size
< 8 ? 1u << (8 - format
->f
.alpha_size
) : 1;
2686 if (format
->f
.red_size
&& (r
< 0x7f - r_range
|| r
> 0x7f + r_range
))
2688 else if (format
->f
.alpha_size
> 1 && (a
< 0xbf - a_range
|| a
> 0xbf + a_range
))
2692 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2693 debug_d3dformat(format
->f
.id
), type
);
2694 TRACE("Color output: %#x\n", color
);
2695 format
->f
.flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2699 TRACE("Format %s supports post-pixelshader blending, type %u.\n",
2700 debug_d3dformat(format
->f
.id
), type
);
2701 TRACE("Color output: %#x\n", color
);
2702 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2706 if (gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2708 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2709 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2710 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &rb
);
2711 checkGLcall("RB cleanup");
2715 if (format
->internal
!= format
->srgb_internal
)
2717 delete_fbo_attachment(gl_info
, type
, object
);
2718 create_and_bind_fbo_attachment(gl_info
, format
, type
, &object
, format
->srgb_internal
);
2720 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2721 checkGLcall("Framebuffer format check");
2723 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2725 TRACE("Format %s's sRGB format is FBO attachable, type %u.\n",
2726 debug_d3dformat(format
->f
.id
), type
);
2727 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2728 if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2729 format
->internal
= format
->srgb_internal
;
2733 WARN("Format %s's sRGB format is not FBO attachable, type %u.\n",
2734 debug_d3dformat(format
->f
.id
), type
);
2735 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_SRGB_WRITE
);
2738 else if (status
== GL_FRAMEBUFFER_COMPLETE
)
2739 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2741 if (format
->f
.flags
[type
] & WINED3DFMT_FLAG_DEPTH_STENCIL
)
2743 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, 0);
2744 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &color_rb
);
2747 delete_fbo_attachment(gl_info
, type
, object
);
2748 checkGLcall("Framebuffer format check cleanup");
2751 if (fallback_fmt_used
&& regular_fmt_used
)
2753 FIXME("Format %s needs different render target formats for different resource types.\n",
2754 debug_d3dformat(format
->f
.id
));
2755 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH_STENCIL
2756 | WINED3DFMT_FLAG_FBO_ATTACHABLE
| WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
2757 | WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2761 static void query_format_flag(struct wined3d_gl_info
*gl_info
, struct wined3d_format_gl
*format
,
2762 GLint internal
, GLenum pname
, DWORD flag
, const char *string
)
2765 enum wined3d_gl_resource_type type
;
2767 for (type
= 0; type
< ARRAY_SIZE(format
->f
.flags
); ++type
)
2769 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
), internal
, pname
, 1, &value
);
2770 if (value
== GL_FULL_SUPPORT
)
2772 TRACE("Format %s supports %s, resource type %u.\n", debug_d3dformat(format
->f
.id
), string
, type
);
2773 format
->f
.flags
[type
] |= flag
;
2777 TRACE("Format %s doesn't support %s, resource type %u.\n", debug_d3dformat(format
->f
.id
), string
, type
);
2778 format
->f
.flags
[type
] &= ~flag
;
2783 /* Context activation is done by the caller. */
2784 static void init_format_fbo_compat_info(const struct wined3d_adapter
*adapter
,
2785 struct wined3d_caps_gl_ctx
*ctx
)
2787 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2788 unsigned int i
, type
;
2791 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2793 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
2795 struct wined3d_format_gl
*format
= get_format_gl_by_idx(adapter
, i
);
2796 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2797 GLenum rt_internal
= format
->rt_internal
;
2800 if (!format
->internal
)
2803 for (type
= 0; type
< ARRAY_SIZE(format
->f
.flags
); ++type
)
2805 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2806 format
->internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2807 if (value
== GL_FULL_SUPPORT
)
2809 TRACE("Format %s is supported as FBO color attachment, resource type %u.\n",
2810 debug_d3dformat(format
->f
.id
), type
);
2811 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2812 format
->rt_internal
= format
->internal
;
2813 regular_fmt_used
= TRUE
;
2815 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2816 format
->internal
, GL_FRAMEBUFFER_BLEND
, 1, &value
);
2817 if (value
== GL_FULL_SUPPORT
)
2819 TRACE("Format %s supports post-pixelshader blending, resource type %u.\n",
2820 debug_d3dformat(format
->f
.id
), type
);
2821 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2825 TRACE("Format %s doesn't support post-pixelshader blending, resource typed %u.\n",
2826 debug_d3dformat(format
->f
.id
), type
);
2827 format
->f
.flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2834 if (format
->f
.flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
2836 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
2837 " and no fallback specified, resource type %u.\n",
2838 debug_d3dformat(format
->f
.id
), type
);
2839 format
->f
.flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2842 TRACE("Format %s is not supported as FBO color attachment,"
2843 " resource type %u.\n", debug_d3dformat(format
->f
.id
), type
);
2844 format
->rt_internal
= format
->internal
;
2848 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2849 rt_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2850 if (value
== GL_FULL_SUPPORT
)
2852 TRACE("Format %s rtInternal format is supported as FBO color attachment,"
2853 " resource type %u.\n", debug_d3dformat(format
->f
.id
), type
);
2854 fallback_fmt_used
= TRUE
;
2858 WARN("Format %s rtInternal format is not supported as FBO color attachment,"
2859 " resource type %u.\n", debug_d3dformat(format
->f
.id
), type
);
2860 format
->f
.flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2865 if (format
->internal
!= format
->srgb_internal
)
2867 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2868 format
->srgb_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2869 if (value
== GL_FULL_SUPPORT
)
2871 TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n",
2872 debug_d3dformat(format
->f
.id
), type
);
2873 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2874 if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2875 format
->internal
= format
->srgb_internal
;
2879 WARN("Format %s's sRGB format is not FBO attachable, resource type %u.\n",
2880 debug_d3dformat(format
->f
.id
), type
);
2881 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_SRGB_WRITE
);
2884 else if (format
->f
.flags
[type
] & WINED3DFMT_FLAG_FBO_ATTACHABLE
)
2885 format
->f
.flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2888 if (fallback_fmt_used
&& regular_fmt_used
)
2890 FIXME("Format %s needs different render target formats for different resource types.\n",
2891 debug_d3dformat(format
->f
.id
));
2892 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
2893 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2899 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2901 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2902 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2903 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2904 gl_info
->gl_ops
.gl
.p_glReadBuffer(GL_COLOR_ATTACHMENT0
);
2907 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
2909 struct wined3d_format_gl
*format
= get_format_gl_by_idx(adapter
, i
);
2911 if (!format
->internal
)
2914 if (format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_COMPRESSED
)
2916 TRACE("Skipping format %s because it's a compressed format.\n",
2917 debug_d3dformat(format
->f
.id
));
2921 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2923 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format
->f
.id
));
2924 check_fbo_compat(ctx
, format
);
2928 format
->rt_internal
= format
->internal
;
2932 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2933 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2936 static GLenum
lookup_gl_view_class(GLenum internal_format
)
2940 GLenum internal_format
;
2946 {GL_RGBA32F
, GL_VIEW_CLASS_128_BITS
},
2947 {GL_RGBA32UI
, GL_VIEW_CLASS_128_BITS
},
2948 {GL_RGBA32I
, GL_VIEW_CLASS_128_BITS
},
2950 {GL_RGB32F
, GL_VIEW_CLASS_96_BITS
},
2951 {GL_RGB32UI
, GL_VIEW_CLASS_96_BITS
},
2952 {GL_RGB32I
, GL_VIEW_CLASS_96_BITS
},
2954 {GL_RGBA16F
, GL_VIEW_CLASS_64_BITS
},
2955 {GL_RG32F
, GL_VIEW_CLASS_64_BITS
},
2956 {GL_RGBA16UI
, GL_VIEW_CLASS_64_BITS
},
2957 {GL_RG32UI
, GL_VIEW_CLASS_64_BITS
},
2958 {GL_RGBA16I
, GL_VIEW_CLASS_64_BITS
},
2959 {GL_RG32I
, GL_VIEW_CLASS_64_BITS
},
2960 {GL_RGBA16
, GL_VIEW_CLASS_64_BITS
},
2961 {GL_RGBA16_SNORM
, GL_VIEW_CLASS_64_BITS
},
2963 {GL_RGB16
, GL_VIEW_CLASS_48_BITS
},
2964 {GL_RGB16_SNORM
, GL_VIEW_CLASS_48_BITS
},
2965 {GL_RGB16F
, GL_VIEW_CLASS_48_BITS
},
2966 {GL_RGB16UI
, GL_VIEW_CLASS_48_BITS
},
2967 {GL_RGB16I
, GL_VIEW_CLASS_48_BITS
},
2969 {GL_RG16F
, GL_VIEW_CLASS_32_BITS
},
2970 {GL_R11F_G11F_B10F
, GL_VIEW_CLASS_32_BITS
},
2971 {GL_R32F
, GL_VIEW_CLASS_32_BITS
},
2972 {GL_RGB10_A2UI
, GL_VIEW_CLASS_32_BITS
},
2973 {GL_RGBA8UI
, GL_VIEW_CLASS_32_BITS
},
2974 {GL_RG16UI
, GL_VIEW_CLASS_32_BITS
},
2975 {GL_R32UI
, GL_VIEW_CLASS_32_BITS
},
2976 {GL_RGBA8I
, GL_VIEW_CLASS_32_BITS
},
2977 {GL_RG16I
, GL_VIEW_CLASS_32_BITS
},
2978 {GL_R32I
, GL_VIEW_CLASS_32_BITS
},
2979 {GL_RGB10_A2
, GL_VIEW_CLASS_32_BITS
},
2980 {GL_RGBA8
, GL_VIEW_CLASS_32_BITS
},
2981 {GL_RG16
, GL_VIEW_CLASS_32_BITS
},
2982 {GL_RGBA8_SNORM
, GL_VIEW_CLASS_32_BITS
},
2983 {GL_RG16_SNORM
, GL_VIEW_CLASS_32_BITS
},
2984 {GL_SRGB8_ALPHA8
, GL_VIEW_CLASS_32_BITS
},
2985 {GL_RGB9_E5
, GL_VIEW_CLASS_32_BITS
},
2987 {GL_RGB8
, GL_VIEW_CLASS_24_BITS
},
2988 {GL_RGB8_SNORM
, GL_VIEW_CLASS_24_BITS
},
2989 {GL_SRGB8
, GL_VIEW_CLASS_24_BITS
},
2990 {GL_RGB8UI
, GL_VIEW_CLASS_24_BITS
},
2991 {GL_RGB8I
, GL_VIEW_CLASS_24_BITS
},
2993 {GL_R16F
, GL_VIEW_CLASS_16_BITS
},
2994 {GL_RG8UI
, GL_VIEW_CLASS_16_BITS
},
2995 {GL_R16UI
, GL_VIEW_CLASS_16_BITS
},
2996 {GL_RG8I
, GL_VIEW_CLASS_16_BITS
},
2997 {GL_R16I
, GL_VIEW_CLASS_16_BITS
},
2998 {GL_RG8
, GL_VIEW_CLASS_16_BITS
},
2999 {GL_R16
, GL_VIEW_CLASS_16_BITS
},
3000 {GL_RG8_SNORM
, GL_VIEW_CLASS_16_BITS
},
3001 {GL_R16_SNORM
, GL_VIEW_CLASS_16_BITS
},
3003 {GL_R8UI
, GL_VIEW_CLASS_8_BITS
},
3004 {GL_R8I
, GL_VIEW_CLASS_8_BITS
},
3005 {GL_R8
, GL_VIEW_CLASS_8_BITS
},
3006 {GL_R8_SNORM
, GL_VIEW_CLASS_8_BITS
},
3009 {GL_COMPRESSED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
3010 {GL_COMPRESSED_SIGNED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
3012 {GL_COMPRESSED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
3013 {GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
3016 {GL_COMPRESSED_RGBA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
3017 {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
3019 {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
3020 {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
3023 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
3024 {GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
3026 {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
3027 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
3029 {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
3030 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
3032 {GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
3033 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
3038 for (i
= 0; i
< ARRAY_SIZE(view_classes
); ++i
)
3040 if (view_classes
[i
].internal_format
== internal_format
)
3041 return view_classes
[i
].view_class
;
3047 static void query_view_class(struct wined3d_format_gl
*format
)
3049 GLenum internal_view_class
, gamma_view_class
, rt_view_class
;
3051 internal_view_class
= lookup_gl_view_class(format
->internal
);
3052 gamma_view_class
= lookup_gl_view_class(format
->srgb_internal
);
3053 rt_view_class
= lookup_gl_view_class(format
->rt_internal
);
3055 if (internal_view_class
== gamma_view_class
|| gamma_view_class
== rt_view_class
)
3057 format
->view_class
= internal_view_class
;
3058 TRACE("Format %s is member of GL view class %#x.\n",
3059 debug_d3dformat(format
->f
.id
), format
->view_class
);
3063 format
->view_class
= GL_NONE
;
3067 static void query_internal_format(struct wined3d_adapter
*adapter
,
3068 struct wined3d_format_gl
*format
, const struct wined3d_format_texture_info
*texture_info
,
3069 struct wined3d_gl_info
*gl_info
, BOOL srgb_write_supported
, BOOL srgb_format
)
3071 GLint count
, multisample_types
[8];
3072 unsigned int i
, max_log2
;
3075 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
3077 query_format_flag(gl_info
, format
, format
->internal
, GL_VERTEX_TEXTURE
,
3078 WINED3DFMT_FLAG_VTF
, "vertex texture usage");
3079 query_format_flag(gl_info
, format
, format
->internal
, GL_FILTER
,
3080 WINED3DFMT_FLAG_FILTERING
, "filtering");
3081 query_format_flag(gl_info
, format
, format
->internal
, GL_SHADER_IMAGE_STORE
,
3082 WINED3DFMT_FLAG_UNORDERED_ACCESS
, "unordered access");
3084 if (srgb_format
|| format
->srgb_internal
!= format
->internal
)
3086 query_format_flag(gl_info
, format
, format
->srgb_internal
, GL_SRGB_READ
,
3087 WINED3DFMT_FLAG_SRGB_READ
, "sRGB read");
3089 if (srgb_write_supported
)
3090 query_format_flag(gl_info
, format
, format
->srgb_internal
, GL_SRGB_WRITE
,
3091 WINED3DFMT_FLAG_SRGB_WRITE
, "sRGB write");
3093 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_SRGB_WRITE
);
3095 if (!(format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
]
3096 & (WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
)))
3097 format
->srgb_internal
= format
->internal
;
3098 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
3099 format
->internal
= format
->srgb_internal
;
3104 if (!gl_info
->limits
.samplers
[WINED3D_SHADER_TYPE_VERTEX
])
3105 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_VTF
);
3107 if (!(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
3108 format_set_flag(&format
->f
, WINED3DFMT_FLAG_FILTERING
);
3109 else if (format
->f
.id
!= WINED3DFMT_R32G32B32A32_FLOAT
&& format
->f
.id
!= WINED3DFMT_R32_FLOAT
)
3110 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_VTF
);
3112 if (srgb_format
|| format
->srgb_internal
!= format
->internal
)
3114 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
3115 if (!gl_info
->supported
[EXT_TEXTURE_SRGB
])
3117 format
->srgb_internal
= format
->internal
;
3118 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
3120 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
3122 format
->internal
= format
->srgb_internal
;
3126 if ((format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_SRGB_WRITE
) && !srgb_write_supported
)
3127 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_SRGB_WRITE
);
3130 if ((!gl_info
->supported
[ARB_DEPTH_TEXTURE
] || wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
3131 && (format
->f
.depth_size
|| format
->f
.stencil_size
))
3133 TRACE("Disabling texturing support for depth / stencil format %s.\n", debug_d3dformat(format
->f
.id
));
3134 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_1D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3135 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3136 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3137 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3138 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3141 query_view_class(format
);
3143 if (format
->internal
&& format
->f
.flags
[WINED3D_GL_RES_TYPE_RB
]
3144 & (WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH_STENCIL
)
3145 && (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
] || gl_info
->supported
[EXT_FRAMEBUFFER_MULTISAMPLE
])
3146 && wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
3148 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY
])
3150 target
= gl_info
->supported
[ARB_TEXTURE_MULTISAMPLE
] ? GL_TEXTURE_2D_MULTISAMPLE
: GL_RENDERBUFFER
;
3152 GL_EXTCALL(glGetInternalformativ(target
, format
->internal
,
3153 GL_NUM_SAMPLE_COUNTS
, 1, &count
));
3154 if (count
> ARRAY_SIZE(multisample_types
))
3155 FIXME("Unexpectedly high number of multisample types %d.\n", count
);
3156 count
= min(count
, ARRAY_SIZE(multisample_types
));
3157 GL_EXTCALL(glGetInternalformativ(target
, format
->internal
,
3158 GL_SAMPLES
, count
, multisample_types
));
3159 checkGLcall("query sample counts");
3160 for (i
= 0; i
< count
; ++i
)
3162 if (multisample_types
[i
] > sizeof(format
->f
.multisample_types
) * CHAR_BIT
)
3164 format
->f
.multisample_types
|= 1u << (multisample_types
[i
] - 1);
3169 max_log2
= wined3d_log2i(min(gl_info
->limits
.samples
,
3170 sizeof(format
->f
.multisample_types
) * CHAR_BIT
));
3171 for (i
= 1; i
<= max_log2
; ++i
)
3172 format
->f
.multisample_types
|= 1u << ((1u << i
) - 1);
3177 static BOOL
init_format_texture_info(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
3179 struct wined3d_format_gl
*format
, *srgb_format
;
3180 struct fragment_caps fragment_caps
;
3181 struct shader_caps shader_caps
;
3185 adapter
->fragment_pipe
->get_caps(adapter
, &fragment_caps
);
3186 adapter
->shader_backend
->shader_get_caps(adapter
, &shader_caps
);
3187 srgb_write
= (fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_SRGB_WRITE
)
3188 && (shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_SRGB_WRITE
);
3190 for (i
= 0; i
< ARRAY_SIZE(format_texture_info
); ++i
)
3192 if (!(format
= get_format_gl_internal(adapter
, format_texture_info
[i
].id
)))
3195 if (!gl_info
->supported
[format_texture_info
[i
].extension
])
3198 /* ARB_texture_rg defines floating point formats, but only if
3199 * ARB_texture_float is also supported. */
3200 if (!gl_info
->supported
[ARB_TEXTURE_FLOAT
]
3201 && (format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_FLOAT
))
3204 /* ARB_texture_rg defines integer formats if EXT_texture_integer is also supported. */
3205 if (!gl_info
->supported
[EXT_TEXTURE_INTEGER
]
3206 && (format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_INTEGER
))
3209 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
3210 && (format
->f
.id
== WINED3DFMT_D16_LOCKABLE
|| format
->f
.id
== WINED3DFMT_NULL
))
3213 format
->internal
= format_texture_info
[i
].gl_internal
;
3214 format
->srgb_internal
= format_texture_info
[i
].gl_srgb_internal
;
3215 format
->rt_internal
= format_texture_info
[i
].gl_rt_internal
;
3216 format
->format
= format_texture_info
[i
].gl_format
;
3217 format
->type
= format_texture_info
[i
].gl_type
;
3218 format
->f
.color_fixup
= COLOR_FIXUP_IDENTITY
;
3219 format
->f
.height_scale
.numerator
= 1;
3220 format
->f
.height_scale
.denominator
= 1;
3222 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_1D
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3223 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3224 format
->f
.flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3226 /* GL_ARB_depth_texture does not support 3D textures. It also says "cube textures are
3227 * problematic", but doesn't explicitly mandate that an error is generated. */
3228 if (gl_info
->supported
[EXT_TEXTURE3D
] && !(format_texture_info
[i
].flags
& WINED3DFMT_FLAG_DEPTH_STENCIL
))
3229 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3231 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
3232 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3234 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
3235 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3237 format
->f
.flags
[WINED3D_GL_RES_TYPE_RB
] |= format_texture_info
[i
].flags
| WINED3DFMT_FLAG_BLIT
;
3238 format
->f
.flags
[WINED3D_GL_RES_TYPE_RB
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3240 if (format
->srgb_internal
!= format
->internal
3241 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
3243 format
->srgb_internal
= format
->internal
;
3244 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
3247 if (!gl_info
->supported
[ARB_SHADOW
] && (format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_SHADOW
))
3248 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3250 query_internal_format(adapter
, format
, &format_texture_info
[i
], gl_info
, srgb_write
, FALSE
);
3252 /* Texture conversion stuff */
3253 format
->f
.conv_byte_count
= format_texture_info
[i
].conv_byte_count
;
3254 format
->f
.upload
= format_texture_info
[i
].upload
;
3255 format
->f
.download
= format_texture_info
[i
].download
;
3258 for (j
= 0; j
< ARRAY_SIZE(format_srgb_info
); ++j
)
3260 if (format_srgb_info
[j
].base_format_id
== format
->f
.id
)
3262 if (!(srgb_format
= get_format_gl_internal(adapter
, format_srgb_info
[j
].srgb_format_id
)))
3270 copy_format(adapter
, &srgb_format
->f
, &format
->f
);
3272 if (gl_info
->supported
[EXT_TEXTURE_SRGB
]
3273 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
3275 srgb_format
->internal
= format_texture_info
[i
].gl_srgb_internal
;
3276 srgb_format
->srgb_internal
= format_texture_info
[i
].gl_srgb_internal
;
3277 format_set_flag(&srgb_format
->f
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
3278 query_internal_format(adapter
, srgb_format
, &format_texture_info
[i
], gl_info
, srgb_write
, TRUE
);
3285 static BOOL
compare_uint(unsigned int x
, unsigned int y
, unsigned int max_diff
)
3287 unsigned int diff
= x
> y
? x
- y
: y
- x
;
3289 return diff
<= max_diff
;
3292 static BOOL
compare_colour(DWORD c1
, DWORD c2
, BYTE max_diff
)
3294 return compare_uint(c1
& 0xff, c2
& 0xff, max_diff
)
3295 && compare_uint((c1
>> 8) & 0xff, (c2
>> 8) & 0xff, max_diff
)
3296 && compare_uint((c1
>> 16) & 0xff, (c2
>> 16) & 0xff, max_diff
)
3297 && compare_uint((c1
>> 24) & 0xff, (c2
>> 24) & 0xff, max_diff
);
3300 /* A context is provided by the caller */
3301 static BOOL
check_filter(const struct wined3d_gl_info
*gl_info
, GLenum internal
)
3303 static const DWORD data
[] = {0x00000000, 0xffffffff};
3304 GLuint tex
, fbo
, buffer
;
3305 DWORD readback
[16 * 1];
3308 /* Render a filtered texture and see what happens. This is intended to detect the lack of
3309 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
3310 * falling back to software. If this changes in the future this code will get fooled and
3311 * apps might hit the software path due to incorrectly advertised caps.
3313 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
3314 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
3315 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
3318 while (gl_info
->gl_ops
.gl
.p_glGetError());
3320 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &buffer
);
3321 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
3322 memset(readback
, 0x7e, sizeof(readback
));
3323 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 16, 1, 0,
3324 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, readback
);
3325 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
3326 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
3327 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
3328 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
3329 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
3331 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &tex
);
3332 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, tex
);
3333 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, internal
, 2, 1, 0,
3334 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, data
);
3335 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
3336 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
3337 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
3338 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
3339 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
3340 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
3342 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3343 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3344 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, buffer
, 0);
3345 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
3347 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
3348 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
3349 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
3350 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
3351 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
3352 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
3354 gl_info
->gl_ops
.gl
.p_glClearColor(0, 1, 0, 0);
3355 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3357 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
3358 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 0.0);
3359 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, -1.0f
);
3360 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 0.0);
3361 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, -1.0f
);
3362 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 1.0);
3363 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, 1.0f
);
3364 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 1.0);
3365 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, 1.0f
);
3366 gl_info
->gl_ops
.gl
.p_glEnd();
3368 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
3369 memset(readback
, 0x7f, sizeof(readback
));
3370 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3371 if (compare_colour(readback
[6], 0xffffffff, 5) || compare_colour(readback
[6], 0x00000000, 5)
3372 || compare_colour(readback
[9], 0xffffffff, 5) || compare_colour(readback
[9], 0x00000000, 5))
3374 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
3375 readback
[6], readback
[9]);
3380 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
3381 readback
[6], readback
[9]);
3385 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3386 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3387 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &tex
);
3388 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &buffer
);
3389 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
3391 if (gl_info
->gl_ops
.gl
.p_glGetError())
3393 FIXME("Error during filtering test for format %x, returning no filtering\n", internal
);
3400 static void init_format_filter_info(struct wined3d_adapter
*adapter
,
3401 struct wined3d_gl_info
*gl_info
)
3403 enum wined3d_pci_vendor vendor
= adapter
->driver_info
.vendor
;
3404 struct wined3d_format_gl
*format
;
3406 static const enum wined3d_format_id fmts16
[] =
3408 WINED3DFMT_R16_FLOAT
,
3409 WINED3DFMT_R16G16_FLOAT
,
3410 WINED3DFMT_R16G16B16A16_FLOAT
,
3414 /* This was already handled by init_format_texture_info(). */
3415 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
3418 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
3419 || !gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3421 if (vendor
== HW_VENDOR_NVIDIA
&& gl_info
->supported
[ARB_TEXTURE_FLOAT
])
3423 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
3426 else if (gl_info
->limits
.glsl_varyings
> 44)
3428 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
3433 TRACE("Assuming no float16 blending\n");
3439 for (i
= 0; i
< ARRAY_SIZE(fmts16
); ++i
)
3441 format
= get_format_gl_internal(adapter
, fmts16
[i
]);
3442 format_set_flag(&format
->f
, WINED3DFMT_FLAG_FILTERING
);
3448 for (i
= 0; i
< ARRAY_SIZE(fmts16
); ++i
)
3450 format
= get_format_gl_internal(adapter
, fmts16
[i
]);
3451 if (!format
->internal
)
3452 continue; /* Not supported by GL */
3454 filtered
= check_filter(gl_info
, format
->internal
);
3457 TRACE("Format %s supports filtering.\n", debug_d3dformat(format
->f
.id
));
3458 format_set_flag(&format
->f
, WINED3DFMT_FLAG_FILTERING
);
3462 TRACE("Format %s does not support filtering.\n", debug_d3dformat(format
->f
.id
));
3467 static enum fixup_channel_source
fixup_source_from_char(char c
)
3473 return CHANNEL_SOURCE_ZERO
;
3475 return CHANNEL_SOURCE_ONE
;
3478 return CHANNEL_SOURCE_X
;
3481 return CHANNEL_SOURCE_Y
;
3484 return CHANNEL_SOURCE_Z
;
3487 return CHANNEL_SOURCE_W
;
3491 static unsigned int fixup_sign_from_char(char c
)
3493 if (c
== 'x' || c
== 'y' || c
== 'z' || c
== 'w')
3498 static struct color_fixup_desc
create_color_fixup_desc_from_string(const char *s
)
3500 struct color_fixup_desc fixup
;
3504 ERR("Invalid fixup string %s.\n", wine_dbgstr_a(s
));
3505 return COLOR_FIXUP_IDENTITY
;
3508 fixup
.x_sign_fixup
= fixup_sign_from_char(s
[0]);
3509 fixup
.x_source
= fixup_source_from_char(s
[0]);
3510 fixup
.y_sign_fixup
= fixup_sign_from_char(s
[1]);
3511 fixup
.y_source
= fixup_source_from_char(s
[1]);
3512 fixup
.z_sign_fixup
= fixup_sign_from_char(s
[2]);
3513 fixup
.z_source
= fixup_source_from_char(s
[2]);
3514 fixup
.w_sign_fixup
= fixup_sign_from_char(s
[3]);
3515 fixup
.w_source
= fixup_source_from_char(s
[3]);
3520 static void apply_format_fixups(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
3522 const struct wined3d_d3d_info
*d3d_info
= &adapter
->d3d_info
;
3523 struct wined3d_format_gl
*format
;
3524 BOOL use_legacy_fixups
;
3529 enum wined3d_format_id id
;
3532 enum wined3d_gl_extension extension
;
3536 {WINED3DFMT_R16_FLOAT
, "X11W", TRUE
, WINED3D_GL_EXT_NONE
},
3537 {WINED3DFMT_R32_FLOAT
, "X11W", TRUE
, WINED3D_GL_EXT_NONE
},
3538 {WINED3DFMT_R16G16_UNORM
, "XY1W", TRUE
, WINED3D_GL_EXT_NONE
},
3539 {WINED3DFMT_R16G16_FLOAT
, "XY1W", TRUE
, WINED3D_GL_EXT_NONE
},
3540 {WINED3DFMT_R32G32_FLOAT
, "XY1W", TRUE
, WINED3D_GL_EXT_NONE
},
3542 {WINED3DFMT_R8G8_SNORM
, "xy11", FALSE
, WINED3D_GL_EXT_NONE
},
3543 {WINED3DFMT_R8G8_SNORM
, "XY11", TRUE
, NV_TEXTURE_SHADER
},
3544 {WINED3DFMT_R8G8_SNORM
, "XY11", TRUE
, EXT_TEXTURE_SNORM
},
3546 {WINED3DFMT_R16G16_SNORM
, "xy11", FALSE
, WINED3D_GL_EXT_NONE
},
3547 {WINED3DFMT_R16G16_SNORM
, "XY11", TRUE
, NV_TEXTURE_SHADER
},
3548 {WINED3DFMT_R16G16_SNORM
, "XY11", TRUE
, EXT_TEXTURE_SNORM
},
3550 {WINED3DFMT_R8G8B8A8_SNORM
, "xyzw", FALSE
, WINED3D_GL_EXT_NONE
},
3551 {WINED3DFMT_R8G8B8A8_SNORM
, "XYZW", FALSE
, NV_TEXTURE_SHADER
},
3552 {WINED3DFMT_R8G8B8A8_SNORM
, "XYZW", FALSE
, EXT_TEXTURE_SNORM
},
3554 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, "xzY1", FALSE
, WINED3D_GL_EXT_NONE
},
3555 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, "XYZW", FALSE
, NV_TEXTURE_SHADER
},
3556 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, "XYZW", FALSE
, EXT_TEXTURE_SNORM
},
3558 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, "xyZW", FALSE
, WINED3D_GL_EXT_NONE
},
3559 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, "XYZW", FALSE
, NV_TEXTURE_SHADER
},
3561 {WINED3DFMT_ATI1N
, "XXXX", FALSE
, EXT_TEXTURE_COMPRESSION_RGTC
},
3562 {WINED3DFMT_ATI1N
, "XXXX", FALSE
, ARB_TEXTURE_COMPRESSION_RGTC
},
3564 {WINED3DFMT_ATI2N
, "XW11", FALSE
, ATI_TEXTURE_COMPRESSION_3DC
},
3565 {WINED3DFMT_ATI2N
, "YX11", FALSE
, EXT_TEXTURE_COMPRESSION_RGTC
},
3566 {WINED3DFMT_ATI2N
, "YX11", FALSE
, ARB_TEXTURE_COMPRESSION_RGTC
},
3568 {WINED3DFMT_A8_UNORM
, "000X", FALSE
, WINED3D_GL_EXT_NONE
},
3569 {WINED3DFMT_A8_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3571 {WINED3DFMT_L8A8_UNORM
, "XXXY", FALSE
, WINED3D_GL_EXT_NONE
},
3572 {WINED3DFMT_L8A8_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3574 {WINED3DFMT_L4A4_UNORM
, "XXXY", FALSE
, WINED3D_GL_EXT_NONE
},
3575 {WINED3DFMT_L4A4_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3577 {WINED3DFMT_L16_UNORM
, "XXX1", FALSE
, WINED3D_GL_EXT_NONE
},
3578 {WINED3DFMT_L16_UNORM
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3580 {WINED3DFMT_INTZ
, "XXXX", FALSE
, WINED3D_GL_EXT_NONE
},
3581 {WINED3DFMT_INTZ
, "XYZW", FALSE
, WINED3D_GL_LEGACY_CONTEXT
},
3583 {WINED3DFMT_L8_UNORM
, "XXX1", FALSE
, ARB_TEXTURE_RG
},
3586 use_legacy_fixups
= d3d_info
->wined3d_creation_flags
& WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR
;
3587 for (i
= 0; i
< ARRAY_SIZE(fixups
); ++i
)
3589 if (fixups
[i
].legacy
&& !use_legacy_fixups
)
3592 if (!gl_info
->supported
[fixups
[i
].extension
])
3595 format
= get_format_gl_internal(adapter
, fixups
[i
].id
);
3596 format
->f
.color_fixup
= create_color_fixup_desc_from_string(fixups
[i
].fixup
);
3599 if (!gl_info
->supported
[APPLE_YCBCR_422
] && !gl_info
->supported
[APPLE_RGB_422
]
3600 && (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3601 || (gl_info
->supported
[ARB_FRAGMENT_SHADER
] && gl_info
->supported
[ARB_VERTEX_SHADER
])))
3603 format
= get_format_gl_internal(adapter
, WINED3DFMT_YUY2
);
3604 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUY2
);
3606 format
= get_format_gl_internal(adapter
, WINED3DFMT_UYVY
);
3607 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_UYVY
);
3609 else if (!gl_info
->supported
[APPLE_YCBCR_422
] && gl_info
->supported
[APPLE_RGB_422
])
3611 format
= get_format_gl_internal(adapter
, WINED3DFMT_YUY2
);
3612 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUV
);
3614 format
= get_format_gl_internal(adapter
, WINED3DFMT_UYVY
);
3615 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUV
);
3617 else if (!gl_info
->supported
[APPLE_YCBCR_422
] && (!gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3618 && (!gl_info
->supported
[ARB_FRAGMENT_SHADER
] || !gl_info
->supported
[ARB_VERTEX_SHADER
])))
3620 format
= get_format_gl_internal(adapter
, WINED3DFMT_YUY2
);
3621 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_BLIT
);
3622 format
->internal
= 0;
3624 format
= get_format_gl_internal(adapter
, WINED3DFMT_UYVY
);
3625 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_BLIT
);
3626 format
->internal
= 0;
3629 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3630 || (gl_info
->supported
[ARB_FRAGMENT_SHADER
] && gl_info
->supported
[ARB_VERTEX_SHADER
]))
3632 format
= get_format_gl_internal(adapter
, WINED3DFMT_YV12
);
3633 format_set_flag(&format
->f
, WINED3DFMT_FLAG_HEIGHT_SCALE
);
3634 format
->f
.height_scale
.numerator
= 3;
3635 format
->f
.height_scale
.denominator
= 2;
3636 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YV12
);
3638 format
= get_format_gl_internal(adapter
, WINED3DFMT_NV12
);
3639 format_set_flag(&format
->f
, WINED3DFMT_FLAG_HEIGHT_SCALE
);
3640 format
->f
.height_scale
.numerator
= 3;
3641 format
->f
.height_scale
.denominator
= 2;
3642 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_NV12
);
3646 format
= get_format_gl_internal(adapter
, WINED3DFMT_YV12
);
3647 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_BLIT
);
3648 format
->internal
= 0;
3650 format
= get_format_gl_internal(adapter
, WINED3DFMT_NV12
);
3651 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_BLIT
);
3652 format
->internal
= 0;
3655 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
] || gl_info
->supported
[ARB_FRAGMENT_SHADER
])
3657 format
= get_format_gl_internal(adapter
, WINED3DFMT_P8_UINT
);
3658 format
->f
.color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_P8
);
3661 if (!gl_info
->supported
[ARB_HALF_FLOAT_PIXEL
])
3663 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16_FLOAT
);
3664 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3666 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16G16_FLOAT
);
3667 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3669 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16G16B16A16_FLOAT
);
3670 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3673 if (gl_info
->quirks
& WINED3D_QUIRK_BROKEN_RGBA16
)
3675 format
= get_format_gl_internal(adapter
, WINED3DFMT_R16G16B16A16_UNORM
);
3676 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3679 /* ATI instancing hack: Although ATI cards do not support Shader Model
3680 * 3.0, they support instancing. To query if the card supports instancing
3681 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
3682 * is used. Should an application check for this, provide a proper return
3683 * value. We can do instancing with all shader versions, but we need
3686 * Additionally applications have to set the D3DRS_POINTSIZE render state
3687 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
3688 * doesn't need that and just ignores it.
3690 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
3691 /* FIXME: This should just check the shader backend caps. */
3692 if (gl_info
->supported
[ARB_VERTEX_PROGRAM
] || gl_info
->supported
[ARB_VERTEX_SHADER
])
3694 format
= get_format_gl_internal(adapter
, WINED3DFMT_INST
);
3695 format_set_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3698 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
3699 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
3700 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
3701 * MAKEFOURCC('N','V','D','B') and then controlled by setting
3702 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
3704 if (gl_info
->supported
[EXT_DEPTH_BOUNDS_TEST
])
3706 format
= get_format_gl_internal(adapter
, WINED3DFMT_NVDB
);
3707 format_set_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3710 if (gl_info
->supported
[ARB_MULTISAMPLE
])
3712 format
= get_format_gl_internal(adapter
, WINED3DFMT_ATOC
);
3713 format_set_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3716 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
3717 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
3718 * RENDERTARGET usage. */
3719 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
])
3721 format
= get_format_gl_internal(adapter
, WINED3DFMT_RESZ
);
3722 format_set_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
);
3725 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
3727 format
= get_format_gl_by_idx(adapter
, i
);
3729 if (!(format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_TEXTURE
))
3732 if (is_identity_fixup(format
->f
.color_fixup
))
3735 TRACE("Checking support for fixup:\n");
3736 dump_color_fixup_desc(format
->f
.color_fixup
);
3737 if (!adapter
->shader_backend
->shader_color_fixup_supported(format
->f
.color_fixup
)
3738 || !adapter
->fragment_pipe
->color_fixup_supported(format
->f
.color_fixup
))
3740 TRACE("[FAILED]\n");
3741 format_clear_flag(&format
->f
, WINED3DFMT_FLAG_TEXTURE
);
3749 /* These formats are not supported for 3D textures. See also
3750 * WINED3DFMT_FLAG_DECOMPRESS. */
3751 format
= get_format_gl_internal(adapter
, WINED3DFMT_ATI1N
);
3752 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3753 format
= get_format_gl_internal(adapter
, WINED3DFMT_ATI2N
);
3754 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3755 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC4_SNORM
);
3756 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3757 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC5_UNORM
);
3758 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3759 format
= get_format_gl_internal(adapter
, WINED3DFMT_BC5_SNORM
);
3760 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3763 static BOOL
init_format_vertex_info(const struct wined3d_adapter
*adapter
,
3764 struct wined3d_gl_info
*gl_info
)
3766 struct wined3d_format_gl
*format
;
3769 for (i
= 0; i
< ARRAY_SIZE(format_vertex_info
); ++i
)
3771 if (!(format
= get_format_gl_internal(adapter
, format_vertex_info
[i
].id
)))
3774 if (!gl_info
->supported
[format_vertex_info
[i
].extension
])
3777 format
->f
.emit_idx
= format_vertex_info
[i
].emit_idx
;
3778 format
->vtx_type
= format_vertex_info
[i
].gl_vtx_type
;
3779 format
->vtx_format
= format
->f
.component_count
;
3780 format
->f
.flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= WINED3DFMT_FLAG_VERTEX_ATTRIBUTE
;
3783 if (gl_info
->supported
[ARB_VERTEX_ARRAY_BGRA
])
3785 format
= get_format_gl_internal(adapter
, WINED3DFMT_B8G8R8A8_UNORM
);
3786 format
->vtx_format
= GL_BGRA
;
3792 static BOOL
init_typeless_formats(const struct wined3d_adapter
*adapter
)
3794 unsigned int flags
[WINED3D_GL_RES_TYPE_COUNT
];
3797 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
3799 struct wined3d_format
*format
, *typeless_format
;
3801 if (!(format
= get_format_internal(adapter
, typed_formats
[i
].id
)))
3803 if (!(typeless_format
= get_format_internal(adapter
, typed_formats
[i
].typeless_id
)))
3806 memcpy(flags
, typeless_format
->flags
, sizeof(flags
));
3807 copy_format(adapter
, typeless_format
, format
);
3808 for (j
= 0; j
< ARRAY_SIZE(typeless_format
->flags
); ++j
)
3809 typeless_format
->flags
[j
] |= flags
[j
];
3812 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
3814 struct wined3d_format
*typeless_format
, *typeless_ds_format
, *ds_format
;
3815 struct wined3d_format
*depth_view_format
, *stencil_view_format
;
3816 enum wined3d_format_id format_id
;
3818 if (!(typeless_format
= get_format_internal(adapter
, typeless_depth_stencil_formats
[i
].typeless_id
)))
3820 if (!(ds_format
= get_format_internal(adapter
, typeless_depth_stencil_formats
[i
].depth_stencil_id
)))
3823 typeless_ds_format
= get_format_by_idx(adapter
, WINED3D_FORMAT_COUNT
+ i
);
3824 typeless_ds_format
->id
= typeless_depth_stencil_formats
[i
].typeless_id
;
3825 copy_format(adapter
, typeless_ds_format
, ds_format
);
3826 for (j
= 0; j
< ARRAY_SIZE(typeless_ds_format
->flags
); ++j
)
3828 typeless_ds_format
->flags
[j
] = typeless_format
->flags
[j
];
3829 typeless_format
->flags
[j
] &= ~WINED3DFMT_FLAG_DEPTH_STENCIL
;
3832 if ((format_id
= typeless_depth_stencil_formats
[i
].depth_view_id
)
3833 && typeless_depth_stencil_formats
[i
].separate_depth_view_format
)
3835 if (!(depth_view_format
= get_format_internal(adapter
, format_id
)))
3837 copy_format(adapter
, depth_view_format
, ds_format
);
3838 depth_view_format
->red_size
= depth_view_format
->depth_size
;
3839 depth_view_format
->depth_size
= 0;
3840 depth_view_format
->stencil_size
= 0;
3842 if ((format_id
= typeless_depth_stencil_formats
[i
].stencil_view_id
))
3844 if (!(stencil_view_format
= get_format_internal(adapter
, format_id
)))
3846 copy_format(adapter
, stencil_view_format
, ds_format
);
3847 stencil_view_format
->green_size
= stencil_view_format
->stencil_size
;
3848 stencil_view_format
->depth_size
= 0;
3849 stencil_view_format
->stencil_size
= 0;
3856 static void init_format_gen_mipmap_info(const struct wined3d_adapter
*adapter
,
3857 struct wined3d_gl_info
*gl_info
)
3861 if (!gl_info
->fbo_ops
.glGenerateMipmap
)
3864 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
3866 struct wined3d_format
*format
= get_format_by_idx(adapter
, i
);
3868 for (j
= 0; j
< ARRAY_SIZE(format
->flags
); ++j
)
3869 if (!(~format
->flags
[j
] & (WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FILTERING
)))
3870 format
->flags
[j
] |= WINED3DFMT_FLAG_GEN_MIPMAP
;
3874 BOOL
wined3d_caps_gl_ctx_test_viewport_subpixel_bits(struct wined3d_caps_gl_ctx
*ctx
)
3876 static const struct wined3d_color red
= {1.0f
, 0.0f
, 0.0f
, 1.0f
};
3877 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3878 static const float offset
= -63.0f
/ 128.0f
;
3879 GLuint texture
, fbo
;
3883 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &texture
);
3884 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3885 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3886 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, ARRAY_SIZE(readback
), 1, 0,
3887 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, NULL
);
3888 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3889 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3890 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
3891 GL_TEXTURE_2D
, texture
, 0);
3892 checkGLcall("create resources");
3894 gl_info
->gl_ops
.gl
.p_glClearColor(1.0f
, 1.0f
, 1.0f
, 1.0f
);
3895 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3896 GL_EXTCALL(glViewportIndexedf(0, offset
, offset
, 4.0f
, 1.0f
));
3897 draw_test_quad(ctx
, NULL
, &red
);
3898 checkGLcall("draw");
3900 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3901 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0,
3902 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3903 checkGLcall("readback");
3905 TRACE("Readback colors are 0x%08x, 0x%08x, 0x%08x, 0x%08x.\n",
3906 readback
[0], readback
[1], readback
[2], readback
[3]);
3908 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &texture
);
3909 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3910 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3911 checkGLcall("delete resources");
3913 for (i
= 0; i
< ARRAY_SIZE(readback
); ++i
)
3915 if (readback
[i
] != 0xffff0000)
3921 bool wined3d_caps_gl_ctx_test_filling_convention(struct wined3d_caps_gl_ctx
*ctx
, float offset
)
3923 static const struct wined3d_color red
= {1.0f
, 0.0f
, 0.0f
, 1.0f
};
3924 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3925 unsigned int x
, y
, clear
= 0, draw
= 0;
3926 GLuint texture
, fbo
;
3927 DWORD readback
[8][8];
3929 /* This is a very simple test to find out how GL handles polygon edges:
3930 * Draw a 1x1 quad exactly through 4 adjacent pixel centers in an 8x8
3931 * viewport and see which pixel it ends up in. So far we've seen top left
3932 * and bottom left conventions. This test may produce unexpected results
3933 * if the driver forces multisampling on us.
3935 * If we find a bottom-left filling behavior we also move the x-axis
3936 * by the same amount. This is necessary to keep diagonals that go
3937 * through the pixel center intact.
3939 * Note that we are ignoring some settings that might influence the
3940 * driver: How we switch GL to an upper-left coordinate system,
3941 * shaders vs fixed function GL. Testing these isn't possible with
3942 * the current draw_test_quad() infrastructure. Also the test is
3943 * skipped if we are not using FBOs. Drawing into the onscreen
3944 * frame buffer may also yield different driver behavior.
3946 * The minimum offset also depends on the viewport size, although
3947 * the relation between those two is GPU dependent and not exactly
3948 * sensible. E.g. a 8192x8192 viewport on a GeForce 9 needs at
3949 * least an offset of 1/240.9, whereas a 8x8 one needs 1/255.982;
3950 * 32x32 needs 1/255.935. 4x4 and lower are happy with something
3951 * below 1/256. The 8x8 size below has been arbitrarily chosen to
3952 * get a useful result out of that card and avoid allocating a
3953 * gigantic texture during library init.
3955 * Newer cards usually do the right thing anyway. In cases where
3956 * they do not (e.g. Radeon GPUs in a macbookpro14,3 running MacOS)
3957 * an offset of 1/2^20 is enough. */
3958 const struct wined3d_vec3 edge_geometry
[] =
3960 {(-1.0f
+ offset
) / 8.0f
, (-1.0f
+ offset
) / 8.0f
, 0.0f
},
3961 {( 1.0f
+ offset
) / 8.0f
, (-1.0f
+ offset
) / 8.0f
, 0.0f
},
3962 {(-1.0f
+ offset
) / 8.0f
, ( 1.0f
+ offset
) / 8.0f
, 0.0f
},
3963 {( 1.0f
+ offset
) / 8.0f
, ( 1.0f
+ offset
) / 8.0f
, 0.0f
},
3966 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &texture
);
3967 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3968 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3969 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 8, 8, 0,
3970 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, NULL
);
3971 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3972 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3973 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
3974 GL_TEXTURE_2D
, texture
, 0);
3975 checkGLcall("create resources");
3977 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 8, 8);
3978 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 1.0f
, 1.0f
);
3979 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3981 draw_test_quad(ctx
, edge_geometry
, &red
);
3982 checkGLcall("draw");
3984 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3985 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0,
3986 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3987 checkGLcall("readback");
3989 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &texture
);
3990 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3991 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3992 checkGLcall("delete resources");
3994 /* We expect that exactly one fragment is generated. */
3995 for (y
= 0; y
< ARRAY_SIZE(readback
); ++y
)
3997 for (x
= 0; x
< ARRAY_SIZE(readback
[0]); ++x
)
3999 if (readback
[y
][x
] == 0xff0000ff)
4001 else if (readback
[y
][x
] == 0xffff0000)
4006 if (clear
!= 63 || draw
!= 1)
4008 FIXME("Unexpected filling convention test result.\n");
4012 /* One pixel was drawn, check if it is the expected one */
4013 return readback
[3][3] == 0xffff0000;
4015 static float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx
*ctx
, GLenum format
)
4017 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
4018 static const struct wined3d_color blue
= {0.0f
, 0.0f
, 1.0f
, 1.0f
};
4019 GLuint fbo
, color
, depth
;
4020 unsigned int low
= 0, high
= 32, cur
;
4021 DWORD readback
[256];
4022 static const struct wined3d_vec3 geometry
[] =
4024 {-1.0f
, -1.0f
, -1.0f
},
4025 { 1.0f
, -1.0f
, 0.0f
},
4026 {-1.0f
, 1.0f
, -1.0f
},
4027 { 1.0f
, 1.0f
, 0.0f
},
4030 /* Most drivers want 2^23 for fixed point depth buffers, including r300g, r600g,
4031 * Nvidia. Use this as a fallback if the detection fails. */
4032 unsigned int fallback
= 23;
4034 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
4036 FIXME("No FBOs, assuming polyoffset scale of 2^%u.\n", fallback
);
4037 return (float)(1u << fallback
);
4040 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &color
);
4041 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
4042 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
4043 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);
4045 gl_info
->fbo_ops
.glGenRenderbuffers(1, &depth
);
4046 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, depth
);
4047 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, format
, 256, 1);
4049 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
4050 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
4051 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, color
, 0);
4052 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, depth
);
4053 checkGLcall("Setup framebuffer");
4055 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.5f
, 0.0f
);
4056 gl_info
->gl_ops
.gl
.p_glClearDepth(0.5f
);
4057 gl_info
->gl_ops
.gl
.p_glEnable(GL_DEPTH_TEST
);
4058 gl_info
->gl_ops
.gl
.p_glEnable(GL_POLYGON_OFFSET_FILL
);
4059 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 256, 1);
4060 checkGLcall("Misc parameters");
4064 if (high
- low
<= 1)
4066 ERR("PolygonOffset scale factor detection failed, using fallback value 2^%u.\n", fallback
);
4070 cur
= (low
+ high
) / 2;
4072 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
4073 /* The post viewport transform Z of the geometry runs from 0.0 to 0.5. We want to push it another
4074 * 0.25 so that the Z buffer content (0.5) cuts the quad off at half the screen. */
4075 gl_info
->gl_ops
.gl
.p_glPolygonOffset(0.0f
, (float)(1u << cur
) * 0.25f
);
4076 draw_test_quad(ctx
, geometry
, &blue
);
4077 checkGLcall("Test draw");
4079 /* Rebinding texture to workaround a fglrx bug. */
4080 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
4081 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
4082 checkGLcall("readback");
4084 TRACE("low %02u, high %02u, cur %2u, 0=0x%08x, 125=0x%08x, 131=0x%08x, 255=0x%08x\n",
4085 low
, high
, cur
, readback
[0], readback
[125], readback
[131], readback
[255]);
4087 if ((readback
[125] & 0xff) < 0xa0)
4089 else if ((readback
[131] & 0xff) > 0xa0)
4093 TRACE("Found scale factor 2^%u for format %x.\n", cur
, format
);
4098 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &color
);
4099 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &depth
);
4100 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
4101 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
4102 checkGLcall("Delete framebuffer");
4104 gl_info
->gl_ops
.gl
.p_glDisable(GL_DEPTH_TEST
);
4105 gl_info
->gl_ops
.gl
.p_glDisable(GL_POLYGON_OFFSET_FILL
);
4106 return (float)(1u << cur
);
4109 static void init_format_depth_bias_scale(struct wined3d_adapter
*adapter
,
4110 struct wined3d_caps_gl_ctx
*ctx
)
4112 const struct wined3d_d3d_info
*d3d_info
= &adapter
->d3d_info
;
4115 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
4117 struct wined3d_format_gl
*format
= get_format_gl_by_idx(adapter
, i
);
4119 if (format
->f
.depth_size
&& (format
->f
.flags
[WINED3D_GL_RES_TYPE_RB
] & WINED3DFMT_FLAG_DEPTH_STENCIL
))
4121 TRACE("Testing depth bias scale for format %s.\n", debug_d3dformat(format
->f
.id
));
4122 format
->f
.depth_bias_scale
= wined3d_adapter_find_polyoffset_scale(ctx
, format
->internal
);
4124 if (!(d3d_info
->wined3d_creation_flags
& WINED3D_NORMALIZED_DEPTH_BIAS
))
4126 /* The single-precision binary floating-point format has
4127 * a significand precision of 24 bits.
4129 if (format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_FLOAT
)
4130 format
->f
.depth_bias_scale
/= 1u << 24;
4132 format
->f
.depth_bias_scale
/= 1u << format
->f
.depth_size
;
4138 static BOOL
wined3d_adapter_init_format_info(struct wined3d_adapter
*adapter
, size_t format_size
)
4140 unsigned int count
= WINED3D_FORMAT_COUNT
+ ARRAY_SIZE(typeless_depth_stencil_formats
);
4142 if (!(adapter
->formats
= heap_calloc(count
, format_size
)))
4144 ERR("Failed to allocate memory.\n");
4147 adapter
->format_size
= format_size
;
4149 if (!init_format_base_info(adapter
))
4151 if (!init_format_block_info(adapter
))
4153 if (!init_format_decompress_info(adapter
))
4155 if (!init_srgb_formats(adapter
))
4161 heap_free(adapter
->formats
);
4162 adapter
->formats
= NULL
;
4166 BOOL
wined3d_adapter_no3d_init_format_info(struct wined3d_adapter
*adapter
)
4168 struct wined3d_format
*format
;
4171 static const enum wined3d_format_id blit_formats
[] =
4173 WINED3DFMT_B8G8R8A8_UNORM
,
4174 WINED3DFMT_B8G8R8X8_UNORM
,
4175 WINED3DFMT_B5G6R5_UNORM
,
4176 WINED3DFMT_B5G5R5X1_UNORM
,
4177 WINED3DFMT_B5G5R5A1_UNORM
,
4178 WINED3DFMT_B4G4R4A4_UNORM
,
4179 WINED3DFMT_B2G3R3_UNORM
,
4180 WINED3DFMT_A8_UNORM
,
4181 WINED3DFMT_B2G3R3A8_UNORM
,
4182 WINED3DFMT_B4G4R4X4_UNORM
,
4183 WINED3DFMT_R10G10B10A2_UNORM
,
4184 WINED3DFMT_R8G8B8A8_UNORM
,
4185 WINED3DFMT_R8G8B8X8_UNORM
,
4186 WINED3DFMT_R16G16_UNORM
,
4187 WINED3DFMT_B10G10R10A2_UNORM
,
4188 WINED3DFMT_R16G16B16A16_UNORM
,
4192 if (!wined3d_adapter_init_format_info(adapter
, sizeof(struct wined3d_format
)))
4195 for (i
= 0; i
< ARRAY_SIZE(blit_formats
); ++i
)
4197 if (!(format
= get_format_internal(adapter
, blit_formats
[i
])))
4200 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] |= WINED3DFMT_FLAG_BLIT
;
4201 format
->flags
[WINED3D_GL_RES_TYPE_RB
] |= WINED3DFMT_FLAG_BLIT
;
4207 /* Context activation is done by the caller. */
4208 BOOL
wined3d_adapter_gl_init_format_info(struct wined3d_adapter
*adapter
, struct wined3d_caps_gl_ctx
*ctx
)
4210 struct wined3d_gl_info
*gl_info
= &adapter
->gl_info
;
4212 if (!wined3d_adapter_init_format_info(adapter
, sizeof(struct wined3d_format_gl
)))
4215 if (!init_format_texture_info(adapter
, gl_info
)) goto fail
;
4216 if (!init_format_vertex_info(adapter
, gl_info
)) goto fail
;
4218 apply_format_fixups(adapter
, gl_info
);
4219 init_format_fbo_compat_info(adapter
, ctx
);
4220 init_format_filter_info(adapter
, gl_info
);
4221 init_format_gen_mipmap_info(adapter
, gl_info
);
4222 init_format_depth_bias_scale(adapter
, ctx
);
4224 if (!init_typeless_formats(adapter
)) goto fail
;
4229 heap_free(adapter
->formats
);
4230 adapter
->formats
= NULL
;
4234 static void init_vulkan_format_info(struct wined3d_format_vk
*format
,
4235 const struct wined3d_vk_info
*vk_info
, VkPhysicalDevice vk_physical_device
)
4239 enum wined3d_format_id id
;
4245 {WINED3DFMT_R32G32B32A32_FLOAT
, VK_FORMAT_R32G32B32A32_SFLOAT
, },
4246 {WINED3DFMT_R32G32B32A32_UINT
, VK_FORMAT_R32G32B32A32_UINT
, },
4247 {WINED3DFMT_R32G32B32A32_SINT
, VK_FORMAT_R32G32B32A32_SINT
, },
4248 {WINED3DFMT_R32G32B32_FLOAT
, VK_FORMAT_R32G32B32_SFLOAT
, },
4249 {WINED3DFMT_R32G32B32_UINT
, VK_FORMAT_R32G32B32_UINT
, },
4250 {WINED3DFMT_R32G32B32_SINT
, VK_FORMAT_R32G32B32_SINT
, },
4251 {WINED3DFMT_R16G16B16A16_FLOAT
, VK_FORMAT_R16G16B16A16_SFLOAT
, },
4252 {WINED3DFMT_R16G16B16A16_UNORM
, VK_FORMAT_R16G16B16A16_UNORM
, },
4253 {WINED3DFMT_R16G16B16A16_UINT
, VK_FORMAT_R16G16B16A16_UINT
, },
4254 {WINED3DFMT_R16G16B16A16_SNORM
, VK_FORMAT_R16G16B16A16_SNORM
, },
4255 {WINED3DFMT_R16G16B16A16_SINT
, VK_FORMAT_R16G16B16A16_SINT
, },
4256 {WINED3DFMT_R32G32_FLOAT
, VK_FORMAT_R32G32_SFLOAT
, },
4257 {WINED3DFMT_R32G32_UINT
, VK_FORMAT_R32G32_UINT
, },
4258 {WINED3DFMT_R32G32_SINT
, VK_FORMAT_R32G32_SINT
, },
4259 {WINED3DFMT_R10G10B10A2_UNORM
, VK_FORMAT_A2B10G10R10_UNORM_PACK32
,},
4260 {WINED3DFMT_R11G11B10_FLOAT
, VK_FORMAT_B10G11R11_UFLOAT_PACK32
, },
4261 {WINED3DFMT_R8G8_UNORM
, VK_FORMAT_R8G8_UNORM
, },
4262 {WINED3DFMT_R8G8_UINT
, VK_FORMAT_R8G8_UINT
, },
4263 {WINED3DFMT_R8G8_SNORM
, VK_FORMAT_R8G8_SNORM
, },
4264 {WINED3DFMT_R8G8_SINT
, VK_FORMAT_R8G8_SINT
, },
4265 {WINED3DFMT_R8G8B8A8_UNORM
, VK_FORMAT_R8G8B8A8_UNORM
, },
4266 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, VK_FORMAT_R8G8B8A8_SRGB
, },
4267 {WINED3DFMT_R8G8B8A8_UINT
, VK_FORMAT_R8G8B8A8_UINT
, },
4268 {WINED3DFMT_R8G8B8A8_SNORM
, VK_FORMAT_R8G8B8A8_SNORM
, },
4269 {WINED3DFMT_R8G8B8A8_SINT
, VK_FORMAT_R8G8B8A8_SINT
, },
4270 {WINED3DFMT_R16G16_FLOAT
, VK_FORMAT_R16G16_SFLOAT
, },
4271 {WINED3DFMT_R16G16_UNORM
, VK_FORMAT_R16G16_UNORM
, },
4272 {WINED3DFMT_R16G16_UINT
, VK_FORMAT_R16G16_UINT
, },
4273 {WINED3DFMT_R16G16_SNORM
, VK_FORMAT_R16G16_SNORM
, },
4274 {WINED3DFMT_R16G16_SINT
, VK_FORMAT_R16G16_SINT
, },
4275 {WINED3DFMT_D32_FLOAT
, VK_FORMAT_D32_SFLOAT
, },
4276 {WINED3DFMT_R32_FLOAT
, VK_FORMAT_R32_SFLOAT
, },
4277 {WINED3DFMT_R32_UINT
, VK_FORMAT_R32_UINT
, },
4278 {WINED3DFMT_R32_SINT
, VK_FORMAT_R32_SINT
, },
4279 {WINED3DFMT_R16_FLOAT
, VK_FORMAT_R16_SFLOAT
, },
4280 {WINED3DFMT_D16_UNORM
, VK_FORMAT_D16_UNORM
, },
4281 {WINED3DFMT_R16_UNORM
, VK_FORMAT_R16_UNORM
, },
4282 {WINED3DFMT_R16_UINT
, VK_FORMAT_R16_UINT
, },
4283 {WINED3DFMT_R16_SNORM
, VK_FORMAT_R16_SNORM
, },
4284 {WINED3DFMT_R16_SINT
, VK_FORMAT_R16_SINT
, },
4285 {WINED3DFMT_R8_UNORM
, VK_FORMAT_R8_UNORM
, },
4286 {WINED3DFMT_R8_UINT
, VK_FORMAT_R8_UINT
, },
4287 {WINED3DFMT_R8_SNORM
, VK_FORMAT_R8_SNORM
, },
4288 {WINED3DFMT_R8_SINT
, VK_FORMAT_R8_SINT
, },
4289 {WINED3DFMT_A8_UNORM
, VK_FORMAT_R8_UNORM
, "000X"},
4290 {WINED3DFMT_B8G8R8A8_UNORM
, VK_FORMAT_B8G8R8A8_UNORM
, },
4291 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, VK_FORMAT_B8G8R8A8_SRGB
, },
4292 {WINED3DFMT_B8G8R8X8_UNORM
, VK_FORMAT_B8G8R8A8_UNORM
, "XYZ1"},
4293 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, VK_FORMAT_B8G8R8A8_SRGB
, "XYZ1"},
4294 {WINED3DFMT_BC1_UNORM
, VK_FORMAT_BC1_RGBA_UNORM_BLOCK
, },
4295 {WINED3DFMT_BC1_UNORM_SRGB
, VK_FORMAT_BC1_RGBA_SRGB_BLOCK
, },
4296 {WINED3DFMT_BC2_UNORM
, VK_FORMAT_BC2_UNORM_BLOCK
, },
4297 {WINED3DFMT_BC2_UNORM_SRGB
, VK_FORMAT_BC2_SRGB_BLOCK
, },
4298 {WINED3DFMT_BC3_UNORM
, VK_FORMAT_BC3_UNORM_BLOCK
, },
4299 {WINED3DFMT_BC3_UNORM_SRGB
, VK_FORMAT_BC3_SRGB_BLOCK
, },
4300 {WINED3DFMT_BC4_UNORM
, VK_FORMAT_BC4_UNORM_BLOCK
, },
4301 {WINED3DFMT_BC4_SNORM
, VK_FORMAT_BC4_SNORM_BLOCK
, },
4302 {WINED3DFMT_BC5_UNORM
, VK_FORMAT_BC5_UNORM_BLOCK
, },
4303 {WINED3DFMT_BC5_SNORM
, VK_FORMAT_BC5_SNORM_BLOCK
, },
4304 {WINED3DFMT_BC6H_UF16
, VK_FORMAT_BC6H_UFLOAT_BLOCK
, },
4305 {WINED3DFMT_BC6H_SF16
, VK_FORMAT_BC6H_SFLOAT_BLOCK
, },
4306 {WINED3DFMT_BC7_UNORM
, VK_FORMAT_BC7_UNORM_BLOCK
, },
4307 {WINED3DFMT_BC7_UNORM_SRGB
, VK_FORMAT_BC7_SRGB_BLOCK
, },
4308 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, VK_FORMAT_E5B9G9R9_UFLOAT_PACK32
, },
4309 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4310 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4311 {WINED3DFMT_X32_TYPELESS_G8X24_UINT
, VK_FORMAT_D32_SFLOAT_S8_UINT
, },
4312 {WINED3DFMT_D24_UNORM_S8_UINT
, VK_FORMAT_D24_UNORM_S8_UINT
, },
4314 VkFormat vk_format
= VK_FORMAT_UNDEFINED
;
4315 VkImageFormatProperties image_properties
;
4316 VkFormatFeatureFlags texture_flags
;
4317 VkFormatProperties properties
;
4318 VkImageUsageFlags vk_usage
;
4325 for (i
= 0; i
< ARRAY_SIZE(vulkan_formats
); ++i
)
4327 if (vulkan_formats
[i
].id
== format
->f
.id
)
4329 vk_format
= vulkan_formats
[i
].vk_format
;
4330 fixup
= vulkan_formats
[i
].fixup
;
4336 WARN("Unsupported format %s.\n", debug_d3dformat(format
->f
.id
));
4340 format
->vk_format
= vk_format
;
4342 format
->f
.color_fixup
= create_color_fixup_desc_from_string(fixup
);
4344 format
->f
.color_fixup
= COLOR_FIXUP_IDENTITY
;
4346 VK_CALL(vkGetPhysicalDeviceFormatProperties(vk_physical_device
, vk_format
, &properties
));
4347 if (vk_format
== VK_FORMAT_D24_UNORM_S8_UINT
)
4349 if (~properties
.optimalTilingFeatures
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)
4351 /* AMD doesn't support VK_FORMAT_D24_UNORM_S8_UINT. */
4352 WARN("Mapping VK_FORMAT_D24_UNORM_S8_UINT to VK_FORMAT_D32_SFLOAT_S8_UINT.\n");
4354 format
->vk_format
= vk_format
= VK_FORMAT_D32_SFLOAT_S8_UINT
;
4355 VK_CALL(vkGetPhysicalDeviceFormatProperties(vk_physical_device
, vk_format
, &properties
));
4359 if (properties
.bufferFeatures
& VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT
)
4360 format
->f
.flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= WINED3DFMT_FLAG_VERTEX_ATTRIBUTE
;
4361 if (properties
.bufferFeatures
& VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT
)
4362 format
->f
.flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= WINED3DFMT_FLAG_TEXTURE
;
4365 texture_flags
= properties
.linearTilingFeatures
| properties
.optimalTilingFeatures
;
4366 if (texture_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
)
4368 flags
|= WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_VTF
;
4370 if (texture_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)
4372 flags
|= WINED3DFMT_FLAG_RENDERTARGET
;
4374 if (texture_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT
)
4376 flags
|= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
4378 if (texture_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)
4380 flags
|= WINED3DFMT_FLAG_DEPTH_STENCIL
;
4382 if (texture_flags
& VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT
)
4384 flags
|= WINED3DFMT_FLAG_FILTERING
;
4386 if (texture_flags
& VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT
)
4388 flags
|= WINED3DFMT_FLAG_UNORDERED_ACCESS
;
4391 if (!(~flags
& (WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FILTERING
)))
4392 flags
|= WINED3DFMT_FLAG_GEN_MIPMAP
;
4394 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_1D
] |= flags
;
4395 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_2D
] |= flags
;
4396 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_3D
] |= flags
;
4397 format
->f
.flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= flags
;
4400 if (texture_flags
& VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT
)
4401 vk_usage
= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
;
4402 else if (texture_flags
& VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT
)
4403 vk_usage
= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
;
4406 if ((vr
= VK_CALL(vkGetPhysicalDeviceImageFormatProperties(vk_physical_device
, vk_format
,
4407 VK_IMAGE_TYPE_2D
, VK_IMAGE_TILING_OPTIMAL
, vk_usage
, 0, &image_properties
))) < 0)
4409 ERR("Failed to get image format properties, vr %s.\n", wined3d_debug_vkresult(vr
));
4413 mask
= image_properties
.sampleCounts
& 0x3f;
4416 i
= (1u << wined3d_bit_scan(&mask
)) - 1;
4417 format
->f
.multisample_types
|= 1u << i
;
4422 BOOL
wined3d_adapter_vk_init_format_info(struct wined3d_adapter_vk
*adapter_vk
,
4423 const struct wined3d_vk_info
*vk_info
)
4425 VkPhysicalDevice vk_physical_device
= adapter_vk
->physical_device
;
4426 struct wined3d_adapter
*adapter
= &adapter_vk
->a
;
4427 struct wined3d_format_vk
*format
;
4430 if (!wined3d_adapter_init_format_info(adapter
, sizeof(*format
)))
4433 for (i
= 0; i
< WINED3D_FORMAT_COUNT
; ++i
)
4435 format
= wined3d_format_vk_mutable(get_format_by_idx(adapter
, i
));
4438 init_vulkan_format_info(format
, vk_info
, vk_physical_device
);
4441 if (!init_typeless_formats(adapter
)) goto fail
;
4446 heap_free(adapter
->formats
);
4447 adapter
->formats
= NULL
;
4451 const struct wined3d_format
*wined3d_get_format(const struct wined3d_adapter
*adapter
,
4452 enum wined3d_format_id format_id
, unsigned int bind_flags
)
4454 const struct wined3d_format
*format
;
4455 int idx
= get_format_idx(format_id
);
4460 FIXME("Can't find format %s (%#x) in the format lookup table.\n",
4461 debug_d3dformat(format_id
), format_id
);
4462 return get_format_internal(adapter
, WINED3DFMT_UNKNOWN
);
4465 format
= get_format_by_idx(adapter
, idx
);
4467 if (bind_flags
& WINED3D_BIND_DEPTH_STENCIL
&& wined3d_format_is_typeless(format
))
4469 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
4471 if (typeless_depth_stencil_formats
[i
].typeless_id
== format_id
)
4472 return get_format_by_idx(adapter
, WINED3D_FORMAT_COUNT
+ i
);
4475 FIXME("Cannot find depth/stencil typeless format %s (%#x).\n",
4476 debug_d3dformat(format_id
), format_id
);
4477 return get_format_internal(adapter
, WINED3DFMT_UNKNOWN
);
4483 enum wined3d_format_id
wined3d_get_typed_format_id(const struct wined3d_adapter
*adapter
,
4484 const struct wined3d_format
*format
, enum wined3d_channel_type channel_type
)
4486 const struct wined3d_typed_format_info
*info
;
4489 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
4491 info
= &typed_formats
[i
];
4492 if (info
->typeless_id
== format
->typeless_id
&& map_channel_type(info
->channels
[0]) == channel_type
)
4496 return WINED3DFMT_UNKNOWN
;
4499 BOOL
wined3d_format_is_depth_view(enum wined3d_format_id resource_format_id
,
4500 enum wined3d_format_id view_format_id
)
4504 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
4506 if (typeless_depth_stencil_formats
[i
].typeless_id
== resource_format_id
)
4507 return typeless_depth_stencil_formats
[i
].depth_view_id
== view_format_id
;
4512 void wined3d_format_calculate_pitch(const struct wined3d_format
*format
, unsigned int alignment
,
4513 unsigned int width
, unsigned int height
, unsigned int *row_pitch
, unsigned int *slice_pitch
)
4515 /* For block based formats, pitch means the amount of bytes to the next
4516 * row of blocks rather than the next row of pixels. */
4517 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BLOCKS
)
4519 unsigned int row_block_count
= (width
+ format
->block_width
- 1) / format
->block_width
;
4520 unsigned int slice_block_count
= (height
+ format
->block_height
- 1) / format
->block_height
;
4521 *row_pitch
= row_block_count
* format
->block_byte_count
;
4522 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
4523 *slice_pitch
= *row_pitch
* slice_block_count
;
4527 *row_pitch
= format
->byte_count
* width
; /* Bytes / row */
4528 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
4529 *slice_pitch
= *row_pitch
* height
;
4532 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_HEIGHT_SCALE
)
4534 /* The D3D format requirements make sure that the resulting format is an integer again */
4535 *slice_pitch
*= format
->height_scale
.numerator
;
4536 *slice_pitch
/= format
->height_scale
.denominator
;
4539 TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch
, *slice_pitch
);
4542 UINT
wined3d_format_calculate_size(const struct wined3d_format
*format
, UINT alignment
,
4543 UINT width
, UINT height
, UINT depth
)
4545 unsigned int row_pitch
, slice_pitch
;
4547 if (format
->id
== WINED3DFMT_UNKNOWN
)
4550 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BROKEN_PITCH
)
4551 return width
* height
* depth
* format
->byte_count
;
4553 wined3d_format_calculate_pitch(format
, alignment
, width
, height
, &row_pitch
, &slice_pitch
);
4555 return slice_pitch
* depth
;
4558 BOOL
wined3d_formats_are_srgb_variants(enum wined3d_format_id format1
, enum wined3d_format_id format2
)
4562 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
4564 if (format1
== format_srgb_info
[i
].srgb_format_id
)
4565 return format2
== format_srgb_info
[i
].base_format_id
;
4566 if (format1
== format_srgb_info
[i
].base_format_id
)
4567 return format2
== format_srgb_info
[i
].srgb_format_id
;
4572 /*****************************************************************************
4573 * Trace formatting of useful values
4575 const char *debug_box(const struct wined3d_box
*box
)
4579 return wine_dbg_sprintf("(%u, %u, %u)-(%u, %u, %u)",
4580 box
->left
, box
->top
, box
->front
,
4581 box
->right
, box
->bottom
, box
->back
);
4584 const char *debug_color(const struct wined3d_color
*color
)
4588 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
4589 color
->r
, color
->g
, color
->b
, color
->a
);
4592 const char *debug_ivec4(const struct wined3d_ivec4
*v
)
4596 return wine_dbg_sprintf("{%d, %d, %d, %d}",
4597 v
->x
, v
->y
, v
->z
, v
->w
);
4600 const char *debug_uvec4(const struct wined3d_uvec4
*v
)
4604 return wine_dbg_sprintf("{%u, %u, %u, %u}",
4605 v
->x
, v
->y
, v
->z
, v
->w
);
4608 const char *debug_vec4(const struct wined3d_vec4
*v
)
4612 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
4613 v
->x
, v
->y
, v
->z
, v
->w
);
4616 const char *debug_const_bo_address(const struct wined3d_const_bo_address
*address
)
4620 return wine_dbg_sprintf("{%p:%p}", address
->buffer_object
, address
->addr
);
4623 const char *debug_bo_address(const struct wined3d_bo_address
*address
)
4625 return debug_const_bo_address((const struct wined3d_const_bo_address
*)address
);
4628 const char *debug_d3dformat(enum wined3d_format_id format_id
)
4632 #define FMT_TO_STR(format_id) case format_id: return #format_id
4633 FMT_TO_STR(WINED3DFMT_UNKNOWN
);
4634 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM
);
4635 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM
);
4636 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM
);
4637 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM
);
4638 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM
);
4639 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM
);
4640 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM
);
4641 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM
);
4642 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM
);
4643 FMT_TO_STR(WINED3DFMT_P8_UINT
);
4644 FMT_TO_STR(WINED3DFMT_L8_UNORM
);
4645 FMT_TO_STR(WINED3DFMT_L8A8_UNORM
);
4646 FMT_TO_STR(WINED3DFMT_L4A4_UNORM
);
4647 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
4648 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
4649 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM
);
4650 FMT_TO_STR(WINED3DFMT_R10G10B10X2_TYPELESS
);
4651 FMT_TO_STR(WINED3DFMT_R10G10B10X2_UINT
);
4652 FMT_TO_STR(WINED3DFMT_R10G10B10X2_SNORM
);
4653 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM
);
4654 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE
);
4655 FMT_TO_STR(WINED3DFMT_D32_UNORM
);
4656 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM
);
4657 FMT_TO_STR(WINED3DFMT_X8D24_UNORM
);
4658 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM
);
4659 FMT_TO_STR(WINED3DFMT_L16_UNORM
);
4660 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT
);
4661 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx
);
4662 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS
);
4663 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT
);
4664 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT
);
4665 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT
);
4666 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS
);
4667 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT
);
4668 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT
);
4669 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT
);
4670 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS
);
4671 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT
);
4672 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM
);
4673 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT
);
4674 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM
);
4675 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT
);
4676 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS
);
4677 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT
);
4678 FMT_TO_STR(WINED3DFMT_R32G32_UINT
);
4679 FMT_TO_STR(WINED3DFMT_R32G32_SINT
);
4680 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS
);
4681 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT
);
4682 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
);
4683 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT
);
4684 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS
);
4685 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM
);
4686 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT
);
4687 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM
);
4688 FMT_TO_STR(WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM
);
4689 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT
);
4690 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS
);
4691 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM
);
4692 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB
);
4693 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT
);
4694 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM
);
4695 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT
);
4696 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS
);
4697 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT
);
4698 FMT_TO_STR(WINED3DFMT_R16G16_UNORM
);
4699 FMT_TO_STR(WINED3DFMT_R16G16_UINT
);
4700 FMT_TO_STR(WINED3DFMT_R16G16_SNORM
);
4701 FMT_TO_STR(WINED3DFMT_R16G16_SINT
);
4702 FMT_TO_STR(WINED3DFMT_R32_TYPELESS
);
4703 FMT_TO_STR(WINED3DFMT_D32_FLOAT
);
4704 FMT_TO_STR(WINED3DFMT_R32_FLOAT
);
4705 FMT_TO_STR(WINED3DFMT_R32_UINT
);
4706 FMT_TO_STR(WINED3DFMT_R32_SINT
);
4707 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS
);
4708 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT
);
4709 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS
);
4710 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT
);
4711 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS
);
4712 FMT_TO_STR(WINED3DFMT_R8G8_UNORM
);
4713 FMT_TO_STR(WINED3DFMT_R8G8_UINT
);
4714 FMT_TO_STR(WINED3DFMT_R8G8_SNORM
);
4715 FMT_TO_STR(WINED3DFMT_R8G8_SINT
);
4716 FMT_TO_STR(WINED3DFMT_R16_TYPELESS
);
4717 FMT_TO_STR(WINED3DFMT_R16_FLOAT
);
4718 FMT_TO_STR(WINED3DFMT_D16_UNORM
);
4719 FMT_TO_STR(WINED3DFMT_R16_UNORM
);
4720 FMT_TO_STR(WINED3DFMT_R16_UINT
);
4721 FMT_TO_STR(WINED3DFMT_R16_SNORM
);
4722 FMT_TO_STR(WINED3DFMT_R16_SINT
);
4723 FMT_TO_STR(WINED3DFMT_R8_TYPELESS
);
4724 FMT_TO_STR(WINED3DFMT_R8_UNORM
);
4725 FMT_TO_STR(WINED3DFMT_R8_UINT
);
4726 FMT_TO_STR(WINED3DFMT_R8_SNORM
);
4727 FMT_TO_STR(WINED3DFMT_R8_SINT
);
4728 FMT_TO_STR(WINED3DFMT_A8_UNORM
);
4729 FMT_TO_STR(WINED3DFMT_R1_UNORM
);
4730 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP
);
4731 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM
);
4732 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM
);
4733 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS
);
4734 FMT_TO_STR(WINED3DFMT_BC1_UNORM
);
4735 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB
);
4736 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS
);
4737 FMT_TO_STR(WINED3DFMT_BC2_UNORM
);
4738 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB
);
4739 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS
);
4740 FMT_TO_STR(WINED3DFMT_BC3_UNORM
);
4741 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB
);
4742 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS
);
4743 FMT_TO_STR(WINED3DFMT_BC4_UNORM
);
4744 FMT_TO_STR(WINED3DFMT_BC4_SNORM
);
4745 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS
);
4746 FMT_TO_STR(WINED3DFMT_BC5_UNORM
);
4747 FMT_TO_STR(WINED3DFMT_BC5_SNORM
);
4748 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM
);
4749 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM
);
4750 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM
);
4751 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM
);
4752 FMT_TO_STR(WINED3DFMT_B8G8R8A8_TYPELESS
);
4753 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM_SRGB
);
4754 FMT_TO_STR(WINED3DFMT_B8G8R8X8_TYPELESS
);
4755 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM_SRGB
);
4756 FMT_TO_STR(WINED3DFMT_BC6H_TYPELESS
);
4757 FMT_TO_STR(WINED3DFMT_BC6H_UF16
);
4758 FMT_TO_STR(WINED3DFMT_BC6H_SF16
);
4759 FMT_TO_STR(WINED3DFMT_BC7_TYPELESS
);
4760 FMT_TO_STR(WINED3DFMT_BC7_UNORM
);
4761 FMT_TO_STR(WINED3DFMT_BC7_UNORM_SRGB
);
4762 FMT_TO_STR(WINED3DFMT_UYVY
);
4763 FMT_TO_STR(WINED3DFMT_YUY2
);
4764 FMT_TO_STR(WINED3DFMT_YV12
);
4765 FMT_TO_STR(WINED3DFMT_DXT1
);
4766 FMT_TO_STR(WINED3DFMT_DXT2
);
4767 FMT_TO_STR(WINED3DFMT_DXT3
);
4768 FMT_TO_STR(WINED3DFMT_DXT4
);
4769 FMT_TO_STR(WINED3DFMT_DXT5
);
4770 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8
);
4771 FMT_TO_STR(WINED3DFMT_G8R8_G8B8
);
4772 FMT_TO_STR(WINED3DFMT_R8G8_B8G8
);
4773 FMT_TO_STR(WINED3DFMT_ATI1N
);
4774 FMT_TO_STR(WINED3DFMT_ATI2N
);
4775 FMT_TO_STR(WINED3DFMT_INST
);
4776 FMT_TO_STR(WINED3DFMT_NVDB
);
4777 FMT_TO_STR(WINED3DFMT_NVHU
);
4778 FMT_TO_STR(WINED3DFMT_NVHS
);
4779 FMT_TO_STR(WINED3DFMT_INTZ
);
4780 FMT_TO_STR(WINED3DFMT_RESZ
);
4781 FMT_TO_STR(WINED3DFMT_NULL
);
4782 FMT_TO_STR(WINED3DFMT_R16
);
4783 FMT_TO_STR(WINED3DFMT_AL16
);
4784 FMT_TO_STR(WINED3DFMT_NV12
);
4785 FMT_TO_STR(WINED3DFMT_ATOC
);
4790 fourcc
[0] = (char)(format_id
);
4791 fourcc
[1] = (char)(format_id
>> 8);
4792 fourcc
[2] = (char)(format_id
>> 16);
4793 fourcc
[3] = (char)(format_id
>> 24);
4795 if (isprint(fourcc
[0]) && isprint(fourcc
[1]) && isprint(fourcc
[2]) && isprint(fourcc
[3]))
4796 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id
, fourcc
);
4798 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id
);
4800 return "unrecognized";
4804 const char *debug_d3ddevicetype(enum wined3d_device_type device_type
)
4806 switch (device_type
)
4808 #define DEVTYPE_TO_STR(dev) case dev: return #dev
4809 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL
);
4810 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF
);
4811 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW
);
4812 #undef DEVTYPE_TO_STR
4814 FIXME("Unrecognized device type %#x.\n", device_type
);
4815 return "unrecognized";
4821 char str
[200]; /* wine_dbg_sprintf() limits string size to 200 */
4826 static void init_debug_buffer(struct debug_buffer
*buffer
, const char *default_string
)
4828 snprintf(buffer
->str
, sizeof(buffer
->str
), "%s", default_string
);
4829 buffer
->ptr
= buffer
->str
;
4830 buffer
->size
= sizeof(buffer
->str
);
4833 static void debug_append(struct debug_buffer
*buffer
, const char *str
, const char *separator
)
4837 if (!separator
|| buffer
->ptr
== buffer
->str
)
4839 size
= snprintf(buffer
->ptr
, buffer
->size
, "%s%s", separator
, str
);
4840 if (size
== -1 || size
>= buffer
->size
)
4843 strcpy(&buffer
->str
[sizeof(buffer
->str
) - 4], "...");
4847 buffer
->ptr
+= size
;
4848 buffer
->size
-= size
;
4851 const char *wined3d_debug_resource_access(DWORD access
)
4853 struct debug_buffer buffer
;
4855 init_debug_buffer(&buffer
, "0");
4856 #define ACCESS_TO_STR(x) if (access & x) { debug_append(&buffer, #x, " | "); access &= ~x; }
4857 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_GPU
);
4858 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_CPU
);
4859 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_MAP_R
);
4860 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_MAP_W
);
4861 #undef ACCESS_TO_STR
4863 FIXME("Unrecognised access flag(s) %#x.\n", access
);
4865 return wine_dbg_sprintf("%s", buffer
.str
);
4868 const char *wined3d_debug_bind_flags(DWORD bind_flags
)
4870 struct debug_buffer buffer
;
4872 init_debug_buffer(&buffer
, "0");
4873 #define BIND_FLAG_TO_STR(x) if (bind_flags & x) { debug_append(&buffer, #x, " | "); bind_flags &= ~x; }
4874 BIND_FLAG_TO_STR(WINED3D_BIND_VERTEX_BUFFER
);
4875 BIND_FLAG_TO_STR(WINED3D_BIND_INDEX_BUFFER
);
4876 BIND_FLAG_TO_STR(WINED3D_BIND_CONSTANT_BUFFER
);
4877 BIND_FLAG_TO_STR(WINED3D_BIND_SHADER_RESOURCE
);
4878 BIND_FLAG_TO_STR(WINED3D_BIND_STREAM_OUTPUT
);
4879 BIND_FLAG_TO_STR(WINED3D_BIND_RENDER_TARGET
);
4880 BIND_FLAG_TO_STR(WINED3D_BIND_DEPTH_STENCIL
);
4881 BIND_FLAG_TO_STR(WINED3D_BIND_UNORDERED_ACCESS
);
4882 BIND_FLAG_TO_STR(WINED3D_BIND_INDIRECT_BUFFER
);
4883 #undef BIND_FLAG_TO_STR
4885 FIXME("Unrecognised bind flag(s) %#x.\n", bind_flags
);
4887 return wine_dbg_sprintf("%s", buffer
.str
);
4890 const char *wined3d_debug_view_desc(const struct wined3d_view_desc
*d
, const struct wined3d_resource
*resource
)
4892 struct debug_buffer buffer
;
4893 unsigned int flags
= d
->flags
;
4895 init_debug_buffer(&buffer
, "0");
4896 #define VIEW_FLAG_TO_STR(x) if (flags & x) { debug_append(&buffer, #x, " | "); flags &= ~x; }
4897 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_RAW
);
4898 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_APPEND
);
4899 VIEW_FLAG_TO_STR(WINED3D_VIEW_BUFFER_COUNTER
);
4900 VIEW_FLAG_TO_STR(WINED3D_VIEW_TEXTURE_CUBE
);
4901 VIEW_FLAG_TO_STR(WINED3D_VIEW_TEXTURE_ARRAY
);
4902 VIEW_FLAG_TO_STR(WINED3D_VIEW_READ_ONLY_DEPTH
);
4903 VIEW_FLAG_TO_STR(WINED3D_VIEW_READ_ONLY_STENCIL
);
4904 #undef VIEW_FLAG_TO_STR
4906 FIXME("Unrecognised view flag(s) %#x.\n", flags
);
4908 if (resource
->type
== WINED3D_RTYPE_BUFFER
)
4909 return wine_dbg_sprintf("format %s, flags %s, start_idx %u, count %u",
4910 debug_d3dformat(d
->format_id
), buffer
.str
, d
->u
.buffer
.start_idx
, d
->u
.buffer
.count
);
4912 return wine_dbg_sprintf("format %s, flags %s, level_idx %u, level_count %u, layer_idx %u, layer_count %u",
4913 debug_d3dformat(d
->format_id
), buffer
.str
, d
->u
.texture
.level_idx
, d
->u
.texture
.level_count
,
4914 d
->u
.texture
.layer_idx
, d
->u
.texture
.layer_count
);
4917 const char *debug_d3dusage(DWORD usage
)
4919 struct debug_buffer buffer
;
4921 init_debug_buffer(&buffer
, "0");
4922 #define WINED3DUSAGE_TO_STR(x) if (usage & x) { debug_append(&buffer, #x, " | "); usage &= ~x; }
4923 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING
);
4924 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP
);
4925 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS
);
4926 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES
);
4927 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES
);
4928 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC
);
4929 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICTED_CONTENT
);
4930 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE_DRIVER
);
4931 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE
);
4932 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP
);
4933 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTAPI
);
4934 WINED3DUSAGE_TO_STR(WINED3DUSAGE_LEGACY_CUBEMAP
);
4935 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OWNDC
);
4936 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL
);
4937 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY
);
4938 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_FILTER
);
4939 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_GENMIPMAP
);
4940 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP
);
4941 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
);
4942 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD
);
4943 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE
);
4944 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE
);
4945 WINED3DUSAGE_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP
);
4946 #undef WINED3DUSAGE_TO_STR
4948 FIXME("Unrecognized usage flag(s) %#x.\n", usage
);
4950 return wine_dbg_sprintf("%s", buffer
.str
);
4953 const char *debug_d3ddeclmethod(enum wined3d_decl_method method
)
4957 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
4958 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT
);
4959 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U
);
4960 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V
);
4961 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV
);
4962 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV
);
4963 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP
);
4964 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED
);
4965 #undef WINED3DDECLMETHOD_TO_STR
4967 FIXME("Unrecognized declaration method %#x.\n", method
);
4968 return "unrecognized";
4972 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage
)
4976 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
4977 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION
);
4978 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT
);
4979 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES
);
4980 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL
);
4981 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE
);
4982 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD
);
4983 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT
);
4984 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL
);
4985 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR
);
4986 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT
);
4987 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR
);
4988 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG
);
4989 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH
);
4990 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE
);
4991 #undef WINED3DDECLUSAGE_TO_STR
4993 FIXME("Unrecognized %u declaration usage!\n", usage
);
4994 return "unrecognized";
4998 const char *debug_d3dinput_classification(enum wined3d_input_classification classification
)
5000 switch (classification
)
5002 #define WINED3D_TO_STR(x) case x: return #x
5003 WINED3D_TO_STR(WINED3D_INPUT_PER_VERTEX_DATA
);
5004 WINED3D_TO_STR(WINED3D_INPUT_PER_INSTANCE_DATA
);
5005 #undef WINED3D_TO_STR
5007 FIXME("Unrecognized input classification %#x.\n", classification
);
5008 return "unrecognized";
5012 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type
)
5014 switch (resource_type
)
5016 #define WINED3D_TO_STR(x) case x: return #x
5017 WINED3D_TO_STR(WINED3D_RTYPE_NONE
);
5018 WINED3D_TO_STR(WINED3D_RTYPE_BUFFER
);
5019 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_1D
);
5020 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_2D
);
5021 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_3D
);
5022 #undef WINED3D_TO_STR
5024 FIXME("Unrecognized resource type %#x.\n", resource_type
);
5025 return "unrecognized";
5029 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type
)
5031 switch (primitive_type
)
5033 #define PRIM_TO_STR(prim) case prim: return #prim
5034 PRIM_TO_STR(WINED3D_PT_UNDEFINED
);
5035 PRIM_TO_STR(WINED3D_PT_POINTLIST
);
5036 PRIM_TO_STR(WINED3D_PT_LINELIST
);
5037 PRIM_TO_STR(WINED3D_PT_LINESTRIP
);
5038 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST
);
5039 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP
);
5040 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN
);
5041 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ
);
5042 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ
);
5043 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ
);
5044 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ
);
5045 PRIM_TO_STR(WINED3D_PT_PATCH
);
5048 FIXME("Unrecognized primitive type %#x.\n", primitive_type
);
5049 return "unrecognized";
5053 const char *debug_d3drenderstate(enum wined3d_render_state state
)
5057 #define D3DSTATE_TO_STR(u) case u: return #u
5058 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS
);
5059 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE
);
5060 D3DSTATE_TO_STR(WINED3D_RS_WRAPU
);
5061 D3DSTATE_TO_STR(WINED3D_RS_WRAPV
);
5062 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE
);
5063 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE
);
5064 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE
);
5065 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN
);
5066 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE
);
5067 D3DSTATE_TO_STR(WINED3D_RS_ROP2
);
5068 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK
);
5069 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE
);
5070 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE
);
5071 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL
);
5072 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND
);
5073 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND
);
5074 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE
);
5075 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC
);
5076 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF
);
5077 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC
);
5078 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE
);
5079 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE
);
5080 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE
);
5081 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE
);
5082 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE
);
5083 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL
);
5084 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX
);
5085 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA
);
5086 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR
);
5087 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE
);
5088 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART
);
5089 D3DSTATE_TO_STR(WINED3D_RS_FOGEND
);
5090 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY
);
5091 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE
);
5092 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE
);
5093 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS
);
5094 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE
);
5095 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY
);
5096 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH
);
5097 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT
);
5098 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE
);
5099 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL
);
5100 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL
);
5101 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS
);
5102 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC
);
5103 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF
);
5104 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK
);
5105 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK
);
5106 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR
);
5107 D3DSTATE_TO_STR(WINED3D_RS_WRAP0
);
5108 D3DSTATE_TO_STR(WINED3D_RS_WRAP1
);
5109 D3DSTATE_TO_STR(WINED3D_RS_WRAP2
);
5110 D3DSTATE_TO_STR(WINED3D_RS_WRAP3
);
5111 D3DSTATE_TO_STR(WINED3D_RS_WRAP4
);
5112 D3DSTATE_TO_STR(WINED3D_RS_WRAP5
);
5113 D3DSTATE_TO_STR(WINED3D_RS_WRAP6
);
5114 D3DSTATE_TO_STR(WINED3D_RS_WRAP7
);
5115 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING
);
5116 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING
);
5117 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS
);
5118 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT
);
5119 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE
);
5120 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX
);
5121 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER
);
5122 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS
);
5123 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE
);
5124 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE
);
5125 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE
);
5126 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE
);
5127 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE
);
5128 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND
);
5129 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE
);
5130 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING
);
5131 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE
);
5132 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN
);
5133 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE
);
5134 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE
);
5135 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A
);
5136 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B
);
5137 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C
);
5138 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS
);
5139 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK
);
5140 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE
);
5141 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS
);
5142 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN
);
5143 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX
);
5144 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE
);
5145 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE
);
5146 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR
);
5147 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP
);
5148 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE
);
5149 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE
);
5150 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE
);
5151 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS
);
5152 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE
);
5153 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL
);
5154 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL
);
5155 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X
);
5156 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y
);
5157 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z
);
5158 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W
);
5159 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION
);
5160 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE
);
5161 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFAIL
);
5162 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILZFAIL
);
5163 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILPASS
);
5164 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFUNC
);
5165 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1
);
5166 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2
);
5167 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3
);
5168 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE
);
5169 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS
);
5170 D3DSTATE_TO_STR(WINED3D_RS_WRAP8
);
5171 D3DSTATE_TO_STR(WINED3D_RS_WRAP9
);
5172 D3DSTATE_TO_STR(WINED3D_RS_WRAP10
);
5173 D3DSTATE_TO_STR(WINED3D_RS_WRAP11
);
5174 D3DSTATE_TO_STR(WINED3D_RS_WRAP12
);
5175 D3DSTATE_TO_STR(WINED3D_RS_WRAP13
);
5176 D3DSTATE_TO_STR(WINED3D_RS_WRAP14
);
5177 D3DSTATE_TO_STR(WINED3D_RS_WRAP15
);
5178 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE
);
5179 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA
);
5180 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA
);
5181 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA
);
5182 #undef D3DSTATE_TO_STR
5184 FIXME("Unrecognized %u render state!\n", state
);
5185 return "unrecognized";
5189 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state
)
5193 #define D3DSTATE_TO_STR(u) case u: return #u
5194 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR
);
5195 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U
);
5196 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V
);
5197 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W
);
5198 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER
);
5199 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER
);
5200 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER
);
5201 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS
);
5202 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL
);
5203 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY
);
5204 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE
);
5205 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX
);
5206 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET
);
5207 #undef D3DSTATE_TO_STR
5209 FIXME("Unrecognized %u sampler state!\n", state
);
5210 return "unrecognized";
5214 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type
)
5216 switch (filter_type
)
5218 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
5219 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE
);
5220 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT
);
5221 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR
);
5222 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC
);
5223 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC
);
5224 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC
);
5225 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD
);
5226 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD
);
5227 #undef D3DTEXTUREFILTERTYPE_TO_STR
5229 FIXME("Unrecognized texture filter type 0x%08x.\n", filter_type
);
5230 return "unrecognized";
5234 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state
)
5238 #define D3DSTATE_TO_STR(u) case u: return #u
5239 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP
);
5240 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1
);
5241 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2
);
5242 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP
);
5243 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1
);
5244 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2
);
5245 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00
);
5246 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01
);
5247 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10
);
5248 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11
);
5249 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX
);
5250 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE
);
5251 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET
);
5252 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
);
5253 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0
);
5254 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0
);
5255 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG
);
5256 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT
);
5257 #undef D3DSTATE_TO_STR
5259 FIXME("Unrecognized %u texture state!\n", state
);
5260 return "unrecognized";
5264 const char *debug_d3dtop(enum wined3d_texture_op d3dtop
)
5268 #define D3DTOP_TO_STR(u) case u: return #u
5269 D3DTOP_TO_STR(WINED3D_TOP_DISABLE
);
5270 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1
);
5271 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2
);
5272 D3DTOP_TO_STR(WINED3D_TOP_MODULATE
);
5273 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X
);
5274 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X
);
5275 D3DTOP_TO_STR(WINED3D_TOP_ADD
);
5276 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED
);
5277 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X
);
5278 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT
);
5279 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH
);
5280 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA
);
5281 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA
);
5282 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA
);
5283 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM
);
5284 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA
);
5285 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE
);
5286 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR
);
5287 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA
);
5288 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR
);
5289 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA
);
5290 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP
);
5291 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE
);
5292 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3
);
5293 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD
);
5294 D3DTOP_TO_STR(WINED3D_TOP_LERP
);
5295 #undef D3DTOP_TO_STR
5297 FIXME("Unrecognized texture op %#x.\n", d3dtop
);
5298 return "unrecognized";
5302 const char *debug_d3dtstype(enum wined3d_transform_state tstype
)
5306 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
5307 TSTYPE_TO_STR(WINED3D_TS_VIEW
);
5308 TSTYPE_TO_STR(WINED3D_TS_PROJECTION
);
5309 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0
);
5310 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1
);
5311 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2
);
5312 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3
);
5313 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4
);
5314 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5
);
5315 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6
);
5316 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7
);
5317 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
5318 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(1));
5319 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(2));
5320 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(3));
5321 #undef TSTYPE_TO_STR
5323 if (tstype
> 256 && tstype
< 512)
5325 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype
);
5326 return ("WINED3D_TS_WORLD_MATRIX > 0");
5328 FIXME("Unrecognized transform state %#x.\n", tstype
);
5329 return "unrecognized";
5333 const char *debug_shader_type(enum wined3d_shader_type type
)
5337 #define WINED3D_TO_STR(type) case type: return #type
5338 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL
);
5339 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX
);
5340 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY
);
5341 WINED3D_TO_STR(WINED3D_SHADER_TYPE_HULL
);
5342 WINED3D_TO_STR(WINED3D_SHADER_TYPE_DOMAIN
);
5343 WINED3D_TO_STR(WINED3D_SHADER_TYPE_COMPUTE
);
5344 #undef WINED3D_TO_STR
5346 FIXME("Unrecognized shader type %#x.\n", type
);
5347 return "unrecognized";
5351 const char *debug_d3dstate(DWORD state
)
5353 if (STATE_IS_RENDER(state
))
5354 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state
- STATE_RENDER(0)));
5355 if (STATE_IS_TEXTURESTAGE(state
))
5357 DWORD texture_stage
= (state
- STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE
+ 1);
5358 DWORD texture_state
= state
- STATE_TEXTURESTAGE(texture_stage
, 0);
5359 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
5360 texture_stage
, debug_d3dtexturestate(texture_state
));
5362 if (STATE_IS_SAMPLER(state
))
5363 return wine_dbg_sprintf("STATE_SAMPLER(%#x)", state
- STATE_SAMPLER(0));
5364 if (STATE_IS_COMPUTE_SHADER(state
))
5365 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE
));
5366 if (STATE_IS_GRAPHICS_SHADER(state
))
5367 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state
- STATE_SHADER(0)));
5368 if (STATE_IS_COMPUTE_CONSTANT_BUFFER(state
))
5369 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE
));
5370 if (STATE_IS_GRAPHICS_CONSTANT_BUFFER(state
))
5371 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state
- STATE_CONSTANT_BUFFER(0)));
5372 if (STATE_IS_COMPUTE_SHADER_RESOURCE_BINDING(state
))
5373 return "STATE_COMPUTE_SHADER_RESOURCE_BINDING";
5374 if (STATE_IS_GRAPHICS_SHADER_RESOURCE_BINDING(state
))
5375 return "STATE_GRAPHICS_SHADER_RESOURCE_BINDING";
5376 if (STATE_IS_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING(state
))
5377 return "STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING";
5378 if (STATE_IS_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING(state
))
5379 return "STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING";
5380 if (STATE_IS_TRANSFORM(state
))
5381 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state
- STATE_TRANSFORM(0)));
5382 if (STATE_IS_STREAMSRC(state
))
5383 return "STATE_STREAMSRC";
5384 if (STATE_IS_INDEXBUFFER(state
))
5385 return "STATE_INDEXBUFFER";
5386 if (STATE_IS_VDECL(state
))
5387 return "STATE_VDECL";
5388 if (STATE_IS_VIEWPORT(state
))
5389 return "STATE_VIEWPORT";
5390 if (STATE_IS_LIGHT_TYPE(state
))
5391 return "STATE_LIGHT_TYPE";
5392 if (STATE_IS_ACTIVELIGHT(state
))
5393 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state
- STATE_ACTIVELIGHT(0));
5394 if (STATE_IS_SCISSORRECT(state
))
5395 return "STATE_SCISSORRECT";
5396 if (STATE_IS_CLIPPLANE(state
))
5397 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state
- STATE_CLIPPLANE(0));
5398 if (STATE_IS_MATERIAL(state
))
5399 return "STATE_MATERIAL";
5400 if (STATE_IS_RASTERIZER(state
))
5401 return "STATE_RASTERIZER";
5402 if (STATE_IS_POINTSPRITECOORDORIGIN(state
))
5403 return "STATE_POINTSPRITECOORDORIGIN";
5404 if (STATE_IS_BASEVERTEXINDEX(state
))
5405 return "STATE_BASEVERTEXINDEX";
5406 if (STATE_IS_FRAMEBUFFER(state
))
5407 return "STATE_FRAMEBUFFER";
5408 if (STATE_IS_POINT_ENABLE(state
))
5409 return "STATE_POINT_ENABLE";
5410 if (STATE_IS_COLOR_KEY(state
))
5411 return "STATE_COLOR_KEY";
5412 if (STATE_IS_STREAM_OUTPUT(state
))
5413 return "STATE_STREAM_OUTPUT";
5414 if (STATE_IS_BLEND(state
))
5415 return "STATE_BLEND";
5416 if (STATE_IS_BLEND_FACTOR(state
))
5417 return "STATE_BLEND_FACTOR";
5418 if (STATE_IS_SAMPLE_MASK(state
))
5419 return "STATE_SAMPLE_MASK";
5420 if (STATE_IS_DEPTH_STENCIL(state
))
5421 return "STATE_DEPTH_STENCIL";
5422 if (STATE_IS_STENCIL_REF(state
))
5423 return "STATE_STENCIL_REF";
5425 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state
);
5428 const char *debug_fboattachment(GLenum attachment
)
5432 #define WINED3D_TO_STR(x) case x: return #x
5433 WINED3D_TO_STR(GL_COLOR_ATTACHMENT0
);
5434 WINED3D_TO_STR(GL_COLOR_ATTACHMENT1
);
5435 WINED3D_TO_STR(GL_COLOR_ATTACHMENT2
);
5436 WINED3D_TO_STR(GL_COLOR_ATTACHMENT3
);
5437 WINED3D_TO_STR(GL_COLOR_ATTACHMENT4
);
5438 WINED3D_TO_STR(GL_COLOR_ATTACHMENT5
);
5439 WINED3D_TO_STR(GL_COLOR_ATTACHMENT6
);
5440 WINED3D_TO_STR(GL_COLOR_ATTACHMENT7
);
5441 WINED3D_TO_STR(GL_COLOR_ATTACHMENT8
);
5442 WINED3D_TO_STR(GL_COLOR_ATTACHMENT9
);
5443 WINED3D_TO_STR(GL_COLOR_ATTACHMENT10
);
5444 WINED3D_TO_STR(GL_COLOR_ATTACHMENT11
);
5445 WINED3D_TO_STR(GL_COLOR_ATTACHMENT12
);
5446 WINED3D_TO_STR(GL_COLOR_ATTACHMENT13
);
5447 WINED3D_TO_STR(GL_COLOR_ATTACHMENT14
);
5448 WINED3D_TO_STR(GL_COLOR_ATTACHMENT15
);
5449 WINED3D_TO_STR(GL_DEPTH_ATTACHMENT
);
5450 WINED3D_TO_STR(GL_STENCIL_ATTACHMENT
);
5451 #undef WINED3D_TO_STR
5453 return wine_dbg_sprintf("Unknown FBO attachment %#x", attachment
);
5457 const char *debug_fbostatus(GLenum status
) {
5459 #define FBOSTATUS_TO_STR(u) case u: return #u
5460 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE
);
5461 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
);
5462 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
);
5463 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
);
5464 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
);
5465 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
);
5466 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
);
5467 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
);
5468 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
);
5469 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB
);
5470 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED
);
5471 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED
);
5472 #undef FBOSTATUS_TO_STR
5474 FIXME("Unrecognized FBO status 0x%08x.\n", status
);
5475 return "unrecognized";
5479 const char *debug_glerror(GLenum error
) {
5481 #define GLERROR_TO_STR(u) case u: return #u
5482 GLERROR_TO_STR(GL_NO_ERROR
);
5483 GLERROR_TO_STR(GL_INVALID_ENUM
);
5484 GLERROR_TO_STR(GL_INVALID_VALUE
);
5485 GLERROR_TO_STR(GL_INVALID_OPERATION
);
5486 GLERROR_TO_STR(GL_STACK_OVERFLOW
);
5487 GLERROR_TO_STR(GL_STACK_UNDERFLOW
);
5488 GLERROR_TO_STR(GL_OUT_OF_MEMORY
);
5489 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION
);
5490 #undef GLERROR_TO_STR
5492 FIXME("Unrecognized GL error 0x%08x.\n", error
);
5493 return "unrecognized";
5497 const char *wined3d_debug_vkresult(VkResult vr
)
5501 #define WINED3D_TO_STR(x) case x: return #x
5502 WINED3D_TO_STR(VK_ERROR_INVALID_OPAQUE_CAPTURE_ADDRESS_KHR
);
5503 WINED3D_TO_STR(VK_ERROR_NOT_PERMITTED_EXT
);
5504 WINED3D_TO_STR(VK_ERROR_FRAGMENTATION_EXT
);
5505 WINED3D_TO_STR(VK_ERROR_INVALID_EXTERNAL_HANDLE
);
5506 WINED3D_TO_STR(VK_ERROR_OUT_OF_POOL_MEMORY
);
5507 WINED3D_TO_STR(VK_ERROR_INVALID_SHADER_NV
);
5508 WINED3D_TO_STR(VK_ERROR_OUT_OF_DATE_KHR
);
5509 WINED3D_TO_STR(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR
);
5510 WINED3D_TO_STR(VK_ERROR_SURFACE_LOST_KHR
);
5511 WINED3D_TO_STR(VK_ERROR_FRAGMENTED_POOL
);
5512 WINED3D_TO_STR(VK_ERROR_FORMAT_NOT_SUPPORTED
);
5513 WINED3D_TO_STR(VK_ERROR_TOO_MANY_OBJECTS
);
5514 WINED3D_TO_STR(VK_ERROR_INCOMPATIBLE_DRIVER
);
5515 WINED3D_TO_STR(VK_ERROR_FEATURE_NOT_PRESENT
);
5516 WINED3D_TO_STR(VK_ERROR_EXTENSION_NOT_PRESENT
);
5517 WINED3D_TO_STR(VK_ERROR_LAYER_NOT_PRESENT
);
5518 WINED3D_TO_STR(VK_ERROR_MEMORY_MAP_FAILED
);
5519 WINED3D_TO_STR(VK_ERROR_DEVICE_LOST
);
5520 WINED3D_TO_STR(VK_ERROR_INITIALIZATION_FAILED
);
5521 WINED3D_TO_STR(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
5522 WINED3D_TO_STR(VK_ERROR_OUT_OF_HOST_MEMORY
);
5523 WINED3D_TO_STR(VK_SUCCESS
);
5524 WINED3D_TO_STR(VK_NOT_READY
);
5525 WINED3D_TO_STR(VK_TIMEOUT
);
5526 WINED3D_TO_STR(VK_EVENT_SET
);
5527 WINED3D_TO_STR(VK_EVENT_RESET
);
5528 WINED3D_TO_STR(VK_INCOMPLETE
);
5529 WINED3D_TO_STR(VK_SUBOPTIMAL_KHR
);
5530 #undef WINED3D_TO_STR
5532 return wine_dbg_sprintf("unrecognised(%d)", vr
);
5536 static const char *debug_fixup_channel_source(enum fixup_channel_source source
)
5540 #define WINED3D_TO_STR(x) case x: return #x
5541 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO
);
5542 WINED3D_TO_STR(CHANNEL_SOURCE_ONE
);
5543 WINED3D_TO_STR(CHANNEL_SOURCE_X
);
5544 WINED3D_TO_STR(CHANNEL_SOURCE_Y
);
5545 WINED3D_TO_STR(CHANNEL_SOURCE_Z
);
5546 WINED3D_TO_STR(CHANNEL_SOURCE_W
);
5547 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0
);
5548 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1
);
5549 #undef WINED3D_TO_STR
5551 FIXME("Unrecognized fixup_channel_source %#x\n", source
);
5552 return "unrecognized";
5556 static const char *debug_complex_fixup(enum complex_fixup fixup
)
5560 #define WINED3D_TO_STR(x) case x: return #x
5561 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2
);
5562 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY
);
5563 WINED3D_TO_STR(COMPLEX_FIXUP_YV12
);
5564 WINED3D_TO_STR(COMPLEX_FIXUP_NV12
);
5565 WINED3D_TO_STR(COMPLEX_FIXUP_P8
);
5566 WINED3D_TO_STR(COMPLEX_FIXUP_YUV
);
5567 #undef WINED3D_TO_STR
5569 FIXME("Unrecognized complex fixup %#x\n", fixup
);
5570 return "unrecognized";
5574 void dump_color_fixup_desc(struct color_fixup_desc fixup
)
5576 if (is_complex_fixup(fixup
))
5578 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup
)));
5582 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup
.x_source
), fixup
.x_sign_fixup
? ", SIGN_FIXUP" : "");
5583 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup
.y_source
), fixup
.y_sign_fixup
? ", SIGN_FIXUP" : "");
5584 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup
.z_source
), fixup
.z_sign_fixup
? ", SIGN_FIXUP" : "");
5585 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup
.w_source
), fixup
.w_sign_fixup
? ", SIGN_FIXUP" : "");
5588 BOOL
is_invalid_op(const struct wined3d_state
*state
, int stage
,
5589 enum wined3d_texture_op op
, DWORD arg1
, DWORD arg2
, DWORD arg3
)
5591 if (op
== WINED3D_TOP_DISABLE
)
5593 if (state
->textures
[stage
])
5596 if ((arg1
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
5597 && op
!= WINED3D_TOP_SELECT_ARG2
)
5599 if ((arg2
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
5600 && op
!= WINED3D_TOP_SELECT_ARG1
)
5602 if ((arg3
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
5603 && (op
== WINED3D_TOP_MULTIPLY_ADD
|| op
== WINED3D_TOP_LERP
))
5609 void get_identity_matrix(struct wined3d_matrix
*mat
)
5611 static const struct wined3d_matrix identity
=
5613 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5614 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5615 0.0f
, 0.0f
, 1.0f
, 0.0f
,
5616 0.0f
, 0.0f
, 0.0f
, 1.0f
,
5622 void get_modelview_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5623 unsigned int index
, struct wined3d_matrix
*mat
)
5625 if (context
->last_was_rhw
)
5626 get_identity_matrix(mat
);
5628 multiply_matrix(mat
, &state
->transforms
[WINED3D_TS_VIEW
], &state
->transforms
[WINED3D_TS_WORLD_MATRIX(index
)]);
5631 void get_projection_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5632 struct wined3d_matrix
*mat
)
5634 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
5635 BOOL clip_control
, flip
;
5636 float center_offset
;
5638 /* There are a couple of additional things we have to take into account
5639 * here besides the projection transformation itself:
5640 * - We need to flip along the y-axis in case of offscreen rendering.
5641 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
5642 * - <= D3D9 coordinates refer to pixel centers while GL coordinates
5643 * refer to pixel corners. D3D10 fixed this particular oddity.
5644 * - D3D has a top-left filling convention while GL does not specify
5645 * a particular behavior, other than that that the GL implementation
5646 * needs to be consistent.
5648 * In order to handle the pixel center, we translate by 0.5 / VPw and
5649 * 0.5 / VPh. We test the filling convention during adapter init and
5650 * add a small offset to correct it if necessary. See
5651 * wined3d_caps_gl_ctx_test_filling_convention() for more details on how
5652 * we test GL and considerations regarding the added offset value.
5654 * If we have GL_ARB_clip_control we take care of all this through
5655 * viewport properties and don't have to translate geometry. */
5657 /* Projection matrices are <= d3d9, which all have integer pixel centers. */
5658 if (!(d3d_info
->wined3d_creation_flags
& WINED3D_PIXEL_CENTER_INTEGER
))
5659 ERR("Did not expect to enter this codepath without WINED3D_PIXEL_CENTER_INTEGER.\n");
5661 clip_control
= d3d_info
->clip_control
;
5662 flip
= !clip_control
&& context
->render_offscreen
;
5664 center_offset
= 1.0f
+ d3d_info
->filling_convention_offset
;
5666 center_offset
= 0.0f
;
5668 if (context
->last_was_rhw
)
5670 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
5671 float x
= state
->viewports
[0].x
;
5672 float y
= state
->viewports
[0].y
;
5673 float w
= state
->viewports
[0].width
;
5674 float h
= state
->viewports
[0].height
;
5675 float x_scale
= 2.0f
/ w
;
5676 float x_offset
= (center_offset
- (2.0f
* x
) - w
) / w
;
5677 float y_scale
= flip
? 2.0f
/ h
: 2.0f
/ -h
;
5678 float y_offset
= flip
5679 ? (center_offset
- (2.0f
* y
) - h
) / h
5680 : (center_offset
- (2.0f
* y
) - h
) / -h
;
5681 bool zenable
= state
->fb
.depth_stencil
?
5682 (state
->depth_stencil_state
? state
->depth_stencil_state
->desc
.depth
: true) : false;
5683 float z_scale
= zenable
? clip_control
? 1.0f
: 2.0f
: 0.0f
;
5684 float z_offset
= zenable
? clip_control
? 0.0f
: -1.0f
: 0.0f
;
5685 const struct wined3d_matrix projection
=
5687 x_scale
, 0.0f
, 0.0f
, 0.0f
,
5688 0.0f
, y_scale
, 0.0f
, 0.0f
,
5689 0.0f
, 0.0f
, z_scale
, 0.0f
,
5690 x_offset
, y_offset
, z_offset
, 1.0f
,
5697 float y_scale
= flip
? -1.0f
: 1.0f
;
5698 float x_offset
= center_offset
/ state
->viewports
[0].width
;
5699 float y_offset
= flip
5700 ? center_offset
/ state
->viewports
[0].height
5701 : -center_offset
/ state
->viewports
[0].height
;
5702 float z_scale
= clip_control
? 1.0f
: 2.0f
;
5703 float z_offset
= clip_control
? 0.0f
: -1.0f
;
5704 const struct wined3d_matrix projection
=
5706 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5707 0.0f
, y_scale
, 0.0f
, 0.0f
,
5708 0.0f
, 0.0f
, z_scale
, 0.0f
,
5709 x_offset
, y_offset
, z_offset
, 1.0f
,
5712 multiply_matrix(mat
, &projection
, &state
->transforms
[WINED3D_TS_PROJECTION
]);
5716 /* Setup this textures matrix according to the texture flags. */
5717 static void compute_texture_matrix(const struct wined3d_matrix
*matrix
, uint32_t flags
, BOOL calculated_coords
,
5718 BOOL transformed
, enum wined3d_format_id format_id
, BOOL ffp_proj_control
, struct wined3d_matrix
*out_matrix
)
5720 struct wined3d_matrix mat
;
5722 if (flags
== WINED3D_TTFF_DISABLE
|| flags
== WINED3D_TTFF_COUNT1
|| transformed
)
5724 get_identity_matrix(out_matrix
);
5728 if (flags
== (WINED3D_TTFF_COUNT1
| WINED3D_TTFF_PROJECTED
))
5730 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
5736 if (flags
& WINED3D_TTFF_PROJECTED
)
5738 if (!ffp_proj_control
)
5740 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
5742 case WINED3D_TTFF_COUNT2
:
5747 mat
._12
= mat
._22
= mat
._32
= mat
._42
= 0.0f
;
5749 case WINED3D_TTFF_COUNT3
:
5754 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
5761 /* Under Direct3D the R/Z coord can be used for translation, under
5762 * OpenGL we use the Q coord instead. */
5763 if (!calculated_coords
)
5767 /* Direct3D passes the default 1.0 in the 2nd coord, while GL
5768 * passes it in the 4th. Swap 2nd and 4th coord. No need to
5769 * store the value of mat._41 in mat._21 because the input
5770 * value to the transformation will be 0, so the matrix value
5772 case WINED3DFMT_R32_FLOAT
:
5778 /* See above, just 3rd and 4th coord. */
5779 case WINED3DFMT_R32G32_FLOAT
:
5785 case WINED3DFMT_R32G32B32_FLOAT
: /* Opengl defaults match dx defaults */
5786 case WINED3DFMT_R32G32B32A32_FLOAT
: /* No defaults apply, all app defined */
5788 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
5789 * into a bad place. The division elimination below will apply to make sure the
5790 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
5792 case WINED3DFMT_UNKNOWN
: /* No texture coords, 0/0/0/1 defaults are passed */
5795 FIXME("Unexpected fixed function texture coord input\n");
5798 if (!ffp_proj_control
)
5800 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
5802 /* case WINED3D_TTFF_COUNT1: Won't ever get here. */
5803 case WINED3D_TTFF_COUNT2
:
5804 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
5805 /* OpenGL divides the first 3 vertex coordinates by the 4th by
5806 * default, which is essentially the same as D3DTTFF_PROJECTED.
5807 * Make sure that the 4th coordinate evaluates to 1.0 to
5810 * If the fixed function pipeline is used, the 4th value
5811 * remains unused, so there is no danger in doing this. With
5812 * vertex shaders we have a problem. Should an application hit
5813 * that problem, the code here would have to check for pixel
5814 * shaders, and the shader has to undo the default GL divide.
5816 * A more serious problem occurs if the application passes 4
5817 * coordinates in, and the 4th is != 1.0 (OpenGL default).
5818 * This would have to be fixed with immediate mode draws. */
5820 mat
._14
= mat
._24
= mat
._34
= 0.0f
; mat
._44
= 1.0f
;
5828 void get_texture_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5829 unsigned int tex
, struct wined3d_matrix
*mat
)
5831 const struct wined3d_device
*device
= context
->device
;
5832 BOOL generated
= (state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
] & 0xffff0000)
5833 != WINED3DTSS_TCI_PASSTHRU
;
5834 unsigned int coord_idx
= min(state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
& 0x0000ffff],
5835 WINED3D_MAX_TEXTURES
- 1);
5837 compute_texture_matrix(&state
->transforms
[WINED3D_TS_TEXTURE0
+ tex
],
5838 state
->texture_states
[tex
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
],
5839 generated
, context
->last_was_rhw
,
5840 context
->stream_info
.use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))
5841 ? context
->stream_info
.elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format
->id
5842 : WINED3DFMT_UNKNOWN
,
5843 device
->shader_backend
->shader_has_ffp_proj_control(device
->shader_priv
), mat
);
5845 if ((context
->lastWasPow2Texture
& (1u << tex
)) && state
->textures
[tex
])
5848 FIXME("Non-power-of-two texture being used with generated texture coords.\n");
5849 /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
5850 * fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
5853 TRACE("Non-power-of-two texture matrix multiply fixup.\n");
5854 multiply_matrix(mat
, mat
, (struct wined3d_matrix
*)state
->textures
[tex
]->pow2_matrix
);
5859 void get_pointsize_minmax(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5860 float *out_min
, float *out_max
)
5868 min
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MIN
];
5869 max
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MAX
];
5878 void get_pointsize(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5879 float *out_pointsize
, float *out_att
)
5881 /* POINTSCALEENABLE controls how point size value is treated. If set to
5882 * true, the point size is scaled with respect to height of viewport.
5883 * When set to false point size is in pixels. */
5888 } pointsize
, a
, b
, c
;
5894 pointsize
.d
= state
->render_states
[WINED3D_RS_POINTSIZE
];
5895 a
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_A
];
5896 b
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_B
];
5897 c
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_C
];
5899 /* Always use first viewport, this path does not apply to d3d10/11 multiple viewports case. */
5900 if (state
->render_states
[WINED3D_RS_POINTSCALEENABLE
])
5902 float scale_factor
= state
->viewports
[0].height
* state
->viewports
[0].height
;
5904 out_att
[0] = a
.f
/ scale_factor
;
5905 out_att
[1] = b
.f
/ scale_factor
;
5906 out_att
[2] = c
.f
/ scale_factor
;
5908 *out_pointsize
= pointsize
.f
;
5911 void get_fog_start_end(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5912 float *start
, float *end
)
5920 switch (context
->fog_source
)
5927 case FOGSOURCE_COORD
:
5933 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGSTART
];
5934 *start
= tmpvalue
.f
;
5935 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGEND
];
5937 /* Special handling for fog_start == fog_end. In d3d with vertex
5938 * fog, everything is fogged. With table fog, everything with
5939 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
5940 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
5941 if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
&& *start
== *end
)
5949 /* This should not happen, context->fog_source is set in wined3d, not the app. */
5950 ERR("Unexpected fog coordinate source.\n");
5956 static BOOL
wined3d_get_primary_display(WCHAR
*display
)
5958 DISPLAY_DEVICEW display_device
;
5959 DWORD device_idx
= 0;
5961 display_device
.cb
= sizeof(display_device
);
5962 while (EnumDisplayDevicesW(NULL
, device_idx
++, &display_device
, 0))
5964 if (display_device
.StateFlags
& DISPLAY_DEVICE_PRIMARY_DEVICE
)
5966 lstrcpyW(display
, display_device
.DeviceName
);
5974 BOOL
wined3d_get_primary_adapter_luid(LUID
*luid
)
5976 D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME open_adapter_param
;
5977 D3DKMT_CLOSEADAPTER close_adapter_param
;
5979 if (!wined3d_get_primary_display(open_adapter_param
.DeviceName
))
5982 if (D3DKMTOpenAdapterFromGdiDisplayName(&open_adapter_param
))
5985 *luid
= open_adapter_param
.AdapterLuid
;
5986 close_adapter_param
.hAdapter
= open_adapter_param
.hAdapter
;
5987 D3DKMTCloseAdapter(&close_adapter_param
);
5991 uint32_t wined3d_format_pack(const struct wined3d_format
*format
, const struct wined3d_uvec4
*value
)
5995 p
|= (value
->x
& wined3d_mask_from_size(format
->red_size
)) << format
->red_offset
;
5996 p
|= (value
->y
& wined3d_mask_from_size(format
->green_size
)) << format
->green_offset
;
5997 p
|= (value
->z
& wined3d_mask_from_size(format
->blue_size
)) << format
->blue_offset
;
5998 p
|= (value
->w
& wined3d_mask_from_size(format
->alpha_size
)) << format
->alpha_offset
;
6003 /* Note: It's the caller's responsibility to ensure values can be expressed
6004 * in the requested format. UNORM formats for example can only express values
6005 * in the range 0.0f -> 1.0f. */
6006 DWORD
wined3d_format_convert_from_float(const struct wined3d_format
*format
, const struct wined3d_color
*color
)
6010 enum wined3d_format_id format_id
;
6011 struct wined3d_vec4 mul
;
6012 struct wined3d_uvec4 shift
;
6016 {WINED3DFMT_B8G8R8A8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, {16, 8, 0, 24}},
6017 {WINED3DFMT_B8G8R8X8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, {16, 8, 0, 24}},
6018 {WINED3DFMT_B8G8R8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, {16, 8, 0, 24}},
6019 {WINED3DFMT_B5G6R5_UNORM
, { 31.0f
, 63.0f
, 31.0f
, 0.0f
}, {11, 5, 0, 0}},
6020 {WINED3DFMT_B5G5R5A1_UNORM
, { 31.0f
, 31.0f
, 31.0f
, 1.0f
}, {10, 5, 0, 15}},
6021 {WINED3DFMT_B5G5R5X1_UNORM
, { 31.0f
, 31.0f
, 31.0f
, 1.0f
}, {10, 5, 0, 15}},
6022 {WINED3DFMT_R8_UNORM
, { 255.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
6023 {WINED3DFMT_A8_UNORM
, { 0.0f
, 0.0f
, 0.0f
, 255.0f
}, { 0, 0, 0, 0}},
6024 {WINED3DFMT_B4G4R4A4_UNORM
, { 15.0f
, 15.0f
, 15.0f
, 15.0f
}, { 8, 4, 0, 12}},
6025 {WINED3DFMT_B4G4R4X4_UNORM
, { 15.0f
, 15.0f
, 15.0f
, 15.0f
}, { 8, 4, 0, 12}},
6026 {WINED3DFMT_B2G3R3_UNORM
, { 7.0f
, 7.0f
, 3.0f
, 0.0f
}, { 5, 2, 0, 0}},
6027 {WINED3DFMT_R8G8B8A8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, { 0, 8, 16, 24}},
6028 {WINED3DFMT_R8G8B8X8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, { 0, 8, 16, 24}},
6029 {WINED3DFMT_B10G10R10A2_UNORM
, { 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
}, {20, 10, 0, 30}},
6030 {WINED3DFMT_R10G10B10A2_UNORM
, { 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
}, { 0, 10, 20, 30}},
6031 {WINED3DFMT_P8_UINT
, { 0.0f
, 0.0f
, 0.0f
, 255.0f
}, { 0, 0, 0, 0}},
6032 {WINED3DFMT_S1_UINT_D15_UNORM
, { 32767.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
6033 {WINED3DFMT_D16_UNORM
, { 65535.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
6037 enum wined3d_format_id format_id
;
6038 struct wined3d_dvec4 mul
;
6039 struct wined3d_uvec4 shift
;
6043 {WINED3DFMT_D24_UNORM_S8_UINT
, { 16777215.0, 1.0, 0.0, 0.0}, {8, 0, 0, 0}},
6044 {WINED3DFMT_X8D24_UNORM
, { 16777215.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
6045 {WINED3DFMT_D32_UNORM
, {4294967295.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
6047 enum wined3d_format_id format_id
= format
->id
;
6048 struct wined3d_color colour_srgb
;
6052 TRACE("Converting colour %s to format %s.\n", debug_color(color
), debug_d3dformat(format_id
));
6054 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
6056 if (format_id
!= format_srgb_info
[i
].srgb_format_id
)
6059 wined3d_colour_srgb_from_linear(&colour_srgb
, color
);
6060 format_id
= format_srgb_info
[i
].base_format_id
;
6061 color
= &colour_srgb
;
6065 for (i
= 0; i
< ARRAY_SIZE(float_conv
); ++i
)
6067 if (format_id
!= float_conv
[i
].format_id
)
6070 ret
= ((DWORD
)((color
->r
* float_conv
[i
].mul
.x
) + 0.5f
)) << float_conv
[i
].shift
.x
;
6071 ret
|= ((DWORD
)((color
->g
* float_conv
[i
].mul
.y
) + 0.5f
)) << float_conv
[i
].shift
.y
;
6072 ret
|= ((DWORD
)((color
->b
* float_conv
[i
].mul
.z
) + 0.5f
)) << float_conv
[i
].shift
.z
;
6073 ret
|= ((DWORD
)((color
->a
* float_conv
[i
].mul
.w
) + 0.5f
)) << float_conv
[i
].shift
.w
;
6075 TRACE("Returning 0x%08x.\n", ret
);
6080 for (i
= 0; i
< ARRAY_SIZE(double_conv
); ++i
)
6082 if (format_id
!= double_conv
[i
].format_id
)
6085 ret
= ((DWORD
)((color
->r
* double_conv
[i
].mul
.x
) + 0.5)) << double_conv
[i
].shift
.x
;
6086 ret
|= ((DWORD
)((color
->g
* double_conv
[i
].mul
.y
) + 0.5)) << double_conv
[i
].shift
.y
;
6087 ret
|= ((DWORD
)((color
->b
* double_conv
[i
].mul
.z
) + 0.5)) << double_conv
[i
].shift
.z
;
6088 ret
|= ((DWORD
)((color
->a
* double_conv
[i
].mul
.w
) + 0.5)) << double_conv
[i
].shift
.w
;
6090 TRACE("Returning 0x%08x.\n", ret
);
6095 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format_id
));
6100 static float color_to_float(DWORD color
, DWORD size
, DWORD offset
)
6102 uint32_t mask
= wined3d_mask_from_size(size
);
6110 return (float)color
/ (float)mask
;
6113 void wined3d_format_get_float_color_key(const struct wined3d_format
*format
,
6114 const struct wined3d_color_key
*key
, struct wined3d_color
*float_colors
)
6116 struct wined3d_color slop
;
6120 case WINED3DFMT_B8G8R8_UNORM
:
6121 case WINED3DFMT_B8G8R8A8_UNORM
:
6122 case WINED3DFMT_B8G8R8X8_UNORM
:
6123 case WINED3DFMT_B5G6R5_UNORM
:
6124 case WINED3DFMT_B5G5R5X1_UNORM
:
6125 case WINED3DFMT_B5G5R5A1_UNORM
:
6126 case WINED3DFMT_B4G4R4A4_UNORM
:
6127 case WINED3DFMT_B2G3R3_UNORM
:
6128 case WINED3DFMT_R8_UNORM
:
6129 case WINED3DFMT_A8_UNORM
:
6130 case WINED3DFMT_B2G3R3A8_UNORM
:
6131 case WINED3DFMT_B4G4R4X4_UNORM
:
6132 case WINED3DFMT_R10G10B10A2_UNORM
:
6133 case WINED3DFMT_R10G10B10A2_SNORM
:
6134 case WINED3DFMT_R8G8B8A8_UNORM
:
6135 case WINED3DFMT_R8G8B8X8_UNORM
:
6136 case WINED3DFMT_R16G16_UNORM
:
6137 case WINED3DFMT_B10G10R10A2_UNORM
:
6138 slop
.r
= 0.5f
/ wined3d_mask_from_size(format
->red_size
);
6139 slop
.g
= 0.5f
/ wined3d_mask_from_size(format
->green_size
);
6140 slop
.b
= 0.5f
/ wined3d_mask_from_size(format
->blue_size
);
6141 slop
.a
= 0.5f
/ wined3d_mask_from_size(format
->alpha_size
);
6143 float_colors
[0].r
= color_to_float(key
->color_space_low_value
, format
->red_size
, format
->red_offset
)
6145 float_colors
[0].g
= color_to_float(key
->color_space_low_value
, format
->green_size
, format
->green_offset
)
6147 float_colors
[0].b
= color_to_float(key
->color_space_low_value
, format
->blue_size
, format
->blue_offset
)
6149 float_colors
[0].a
= color_to_float(key
->color_space_low_value
, format
->alpha_size
, format
->alpha_offset
)
6152 float_colors
[1].r
= color_to_float(key
->color_space_high_value
, format
->red_size
, format
->red_offset
)
6154 float_colors
[1].g
= color_to_float(key
->color_space_high_value
, format
->green_size
, format
->green_offset
)
6156 float_colors
[1].b
= color_to_float(key
->color_space_high_value
, format
->blue_size
, format
->blue_offset
)
6158 float_colors
[1].a
= color_to_float(key
->color_space_high_value
, format
->alpha_size
, format
->alpha_offset
)
6162 case WINED3DFMT_P8_UINT
:
6163 float_colors
[0].r
= 0.0f
;
6164 float_colors
[0].g
= 0.0f
;
6165 float_colors
[0].b
= 0.0f
;
6166 float_colors
[0].a
= (key
->color_space_low_value
- 0.5f
) / 255.0f
;
6168 float_colors
[1].r
= 0.0f
;
6169 float_colors
[1].g
= 0.0f
;
6170 float_colors
[1].b
= 0.0f
;
6171 float_colors
[1].a
= (key
->color_space_high_value
+ 0.5f
) / 255.0f
;
6175 ERR("Unhandled color key to float conversion for format %s.\n", debug_d3dformat(format
->id
));
6179 enum wined3d_format_id
pixelformat_for_depth(DWORD depth
)
6183 case 8: return WINED3DFMT_P8_UINT
;
6184 case 15: return WINED3DFMT_B5G5R5X1_UNORM
;
6185 case 16: return WINED3DFMT_B5G6R5_UNORM
;
6186 case 24: return WINED3DFMT_B8G8R8X8_UNORM
; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
6187 case 32: return WINED3DFMT_B8G8R8X8_UNORM
; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
6188 default: return WINED3DFMT_UNKNOWN
;
6192 void wined3d_format_copy_data(const struct wined3d_format
*format
, const uint8_t *src
,
6193 unsigned int src_row_pitch
, unsigned int src_slice_pitch
, uint8_t *dst
, unsigned int dst_row_pitch
,
6194 unsigned int dst_slice_pitch
, unsigned int w
, unsigned int h
, unsigned int d
)
6196 unsigned int row_block_count
, row_count
, row_size
, slice
, row
;
6197 unsigned int slice_count
= d
, slice_size
;
6198 const uint8_t *src_row
;
6201 row_block_count
= (w
+ format
->block_width
- 1) / format
->block_width
;
6202 row_count
= (h
+ format
->block_height
- 1) / format
->block_height
;
6203 row_size
= row_block_count
* format
->block_byte_count
;
6204 slice_size
= row_size
* row_count
;
6206 if (src_row_pitch
== row_size
&& dst_row_pitch
== row_size
6207 && ((src_slice_pitch
== slice_size
&& dst_slice_pitch
== slice_size
) || slice_count
== 1))
6209 memcpy(dst
, src
, slice_count
* slice_size
);
6213 for (slice
= 0; slice
< slice_count
; ++slice
)
6215 for (row
= 0; row
< row_count
; ++row
)
6217 src_row
= &src
[slice
* src_slice_pitch
+ row
* src_row_pitch
];
6218 dst_row
= &dst
[slice
* dst_slice_pitch
+ row
* dst_row_pitch
];
6219 memcpy(dst_row
, src_row
, row_size
);
6224 void multiply_matrix(struct wined3d_matrix
*dst
, const struct wined3d_matrix
*src1
, const struct wined3d_matrix
*src2
)
6226 struct wined3d_matrix tmp
;
6228 /* Now do the multiplication 'by hand'.
6229 I know that all this could be optimised, but this will be done later :-) */
6230 tmp
._11
= (src1
->_11
* src2
->_11
) + (src1
->_21
* src2
->_12
) + (src1
->_31
* src2
->_13
) + (src1
->_41
* src2
->_14
);
6231 tmp
._21
= (src1
->_11
* src2
->_21
) + (src1
->_21
* src2
->_22
) + (src1
->_31
* src2
->_23
) + (src1
->_41
* src2
->_24
);
6232 tmp
._31
= (src1
->_11
* src2
->_31
) + (src1
->_21
* src2
->_32
) + (src1
->_31
* src2
->_33
) + (src1
->_41
* src2
->_34
);
6233 tmp
._41
= (src1
->_11
* src2
->_41
) + (src1
->_21
* src2
->_42
) + (src1
->_31
* src2
->_43
) + (src1
->_41
* src2
->_44
);
6235 tmp
._12
= (src1
->_12
* src2
->_11
) + (src1
->_22
* src2
->_12
) + (src1
->_32
* src2
->_13
) + (src1
->_42
* src2
->_14
);
6236 tmp
._22
= (src1
->_12
* src2
->_21
) + (src1
->_22
* src2
->_22
) + (src1
->_32
* src2
->_23
) + (src1
->_42
* src2
->_24
);
6237 tmp
._32
= (src1
->_12
* src2
->_31
) + (src1
->_22
* src2
->_32
) + (src1
->_32
* src2
->_33
) + (src1
->_42
* src2
->_34
);
6238 tmp
._42
= (src1
->_12
* src2
->_41
) + (src1
->_22
* src2
->_42
) + (src1
->_32
* src2
->_43
) + (src1
->_42
* src2
->_44
);
6240 tmp
._13
= (src1
->_13
* src2
->_11
) + (src1
->_23
* src2
->_12
) + (src1
->_33
* src2
->_13
) + (src1
->_43
* src2
->_14
);
6241 tmp
._23
= (src1
->_13
* src2
->_21
) + (src1
->_23
* src2
->_22
) + (src1
->_33
* src2
->_23
) + (src1
->_43
* src2
->_24
);
6242 tmp
._33
= (src1
->_13
* src2
->_31
) + (src1
->_23
* src2
->_32
) + (src1
->_33
* src2
->_33
) + (src1
->_43
* src2
->_34
);
6243 tmp
._43
= (src1
->_13
* src2
->_41
) + (src1
->_23
* src2
->_42
) + (src1
->_33
* src2
->_43
) + (src1
->_43
* src2
->_44
);
6245 tmp
._14
= (src1
->_14
* src2
->_11
) + (src1
->_24
* src2
->_12
) + (src1
->_34
* src2
->_13
) + (src1
->_44
* src2
->_14
);
6246 tmp
._24
= (src1
->_14
* src2
->_21
) + (src1
->_24
* src2
->_22
) + (src1
->_34
* src2
->_23
) + (src1
->_44
* src2
->_24
);
6247 tmp
._34
= (src1
->_14
* src2
->_31
) + (src1
->_24
* src2
->_32
) + (src1
->_34
* src2
->_33
) + (src1
->_44
* src2
->_34
);
6248 tmp
._44
= (src1
->_14
* src2
->_41
) + (src1
->_24
* src2
->_42
) + (src1
->_34
* src2
->_43
) + (src1
->_44
* src2
->_44
);
6253 void wined3d_ffp_get_fs_settings(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
6254 struct ffp_frag_settings
*settings
, BOOL ignore_textype
)
6259 static const unsigned char args
[WINED3D_TOP_LERP
+ 1] =
6262 /* D3DTOP_DISABLE */ 0,
6263 /* D3DTOP_SELECTARG1 */ ARG1
,
6264 /* D3DTOP_SELECTARG2 */ ARG2
,
6265 /* D3DTOP_MODULATE */ ARG1
| ARG2
,
6266 /* D3DTOP_MODULATE2X */ ARG1
| ARG2
,
6267 /* D3DTOP_MODULATE4X */ ARG1
| ARG2
,
6268 /* D3DTOP_ADD */ ARG1
| ARG2
,
6269 /* D3DTOP_ADDSIGNED */ ARG1
| ARG2
,
6270 /* D3DTOP_ADDSIGNED2X */ ARG1
| ARG2
,
6271 /* D3DTOP_SUBTRACT */ ARG1
| ARG2
,
6272 /* D3DTOP_ADDSMOOTH */ ARG1
| ARG2
,
6273 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1
| ARG2
,
6274 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1
| ARG2
,
6275 /* D3DTOP_BLENDFACTORALPHA */ ARG1
| ARG2
,
6276 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1
| ARG2
,
6277 /* D3DTOP_BLENDCURRENTALPHA */ ARG1
| ARG2
,
6278 /* D3DTOP_PREMODULATE */ ARG1
| ARG2
,
6279 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1
| ARG2
,
6280 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1
| ARG2
,
6281 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1
| ARG2
,
6282 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1
| ARG2
,
6283 /* D3DTOP_BUMPENVMAP */ ARG1
| ARG2
,
6284 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1
| ARG2
,
6285 /* D3DTOP_DOTPRODUCT3 */ ARG1
| ARG2
,
6286 /* D3DTOP_MULTIPLYADD */ ARG1
| ARG2
| ARG0
,
6287 /* D3DTOP_LERP */ ARG1
| ARG2
| ARG0
6291 DWORD cop
, aop
, carg0
, carg1
, carg2
, aarg0
, aarg1
, aarg2
;
6292 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
6294 settings
->padding
= 0;
6296 for (i
= 0; i
< d3d_info
->limits
.ffp_blend_stages
; ++i
)
6298 struct wined3d_texture
*texture
;
6300 settings
->op
[i
].padding
= 0;
6301 if (state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
] == WINED3D_TOP_DISABLE
)
6303 settings
->op
[i
].cop
= WINED3D_TOP_DISABLE
;
6304 settings
->op
[i
].aop
= WINED3D_TOP_DISABLE
;
6305 settings
->op
[i
].carg0
= settings
->op
[i
].carg1
= settings
->op
[i
].carg2
= ARG_UNUSED
;
6306 settings
->op
[i
].aarg0
= settings
->op
[i
].aarg1
= settings
->op
[i
].aarg2
= ARG_UNUSED
;
6307 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
6308 settings
->op
[i
].tmp_dst
= 0;
6309 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6310 settings
->op
[i
].projected
= WINED3D_PROJECTION_NONE
;
6315 if ((texture
= state
->textures
[i
]))
6317 if (can_use_texture_swizzle(d3d_info
, texture
->resource
.format
))
6318 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
6320 settings
->op
[i
].color_fixup
= texture
->resource
.format
->color_fixup
;
6323 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6327 switch (wined3d_texture_gl(texture
)->target
)
6330 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6333 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_2D
;
6336 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_3D
;
6338 case GL_TEXTURE_CUBE_MAP_ARB
:
6339 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_CUBE
;
6341 case GL_TEXTURE_RECTANGLE_ARB
:
6342 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_RECT
;
6347 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
6348 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
6351 cop
= state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
];
6352 aop
= state
->texture_states
[i
][WINED3D_TSS_ALPHA_OP
];
6354 carg1
= (args
[cop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG1
] : ARG_UNUSED
;
6355 carg2
= (args
[cop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG2
] : ARG_UNUSED
;
6356 carg0
= (args
[cop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG0
] : ARG_UNUSED
;
6358 if (is_invalid_op(state
, i
, cop
, carg1
, carg2
, carg0
))
6362 carg1
= WINED3DTA_CURRENT
;
6363 cop
= WINED3D_TOP_SELECT_ARG1
;
6366 if (cop
== WINED3D_TOP_DOTPRODUCT3
)
6368 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
6369 * the color result to the alpha component of the destination
6378 aarg1
= (args
[aop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG1
] : ARG_UNUSED
;
6379 aarg2
= (args
[aop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG2
] : ARG_UNUSED
;
6380 aarg0
= (args
[aop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG0
] : ARG_UNUSED
;
6383 if (!i
&& state
->textures
[0] && state
->render_states
[WINED3D_RS_COLORKEYENABLE
])
6385 GLenum texture_dimensions
;
6387 texture
= state
->textures
[0];
6388 texture_dimensions
= wined3d_texture_gl(texture
)->target
;
6390 if (texture_dimensions
== GL_TEXTURE_2D
|| texture_dimensions
== GL_TEXTURE_RECTANGLE_ARB
)
6392 if (texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
&& !texture
->resource
.format
->alpha_size
)
6394 if (aop
== WINED3D_TOP_DISABLE
)
6396 aarg1
= WINED3DTA_TEXTURE
;
6397 aop
= WINED3D_TOP_SELECT_ARG1
;
6399 else if (aop
== WINED3D_TOP_SELECT_ARG1
&& aarg1
!= WINED3DTA_TEXTURE
)
6401 if (state
->blend_state
&& state
->blend_state
->desc
.rt
[0].enable
)
6403 aarg2
= WINED3DTA_TEXTURE
;
6404 aop
= WINED3D_TOP_MODULATE
;
6406 else aarg1
= WINED3DTA_TEXTURE
;
6408 else if (aop
== WINED3D_TOP_SELECT_ARG2
&& aarg2
!= WINED3DTA_TEXTURE
)
6410 if (state
->blend_state
&& state
->blend_state
->desc
.rt
[0].enable
)
6412 aarg1
= WINED3DTA_TEXTURE
;
6413 aop
= WINED3D_TOP_MODULATE
;
6415 else aarg2
= WINED3DTA_TEXTURE
;
6421 if (is_invalid_op(state
, i
, aop
, aarg1
, aarg2
, aarg0
))
6425 aarg1
= WINED3DTA_CURRENT
;
6426 aop
= WINED3D_TOP_SELECT_ARG1
;
6429 if (carg1
== WINED3DTA_TEXTURE
|| carg2
== WINED3DTA_TEXTURE
|| carg0
== WINED3DTA_TEXTURE
6430 || aarg1
== WINED3DTA_TEXTURE
|| aarg2
== WINED3DTA_TEXTURE
|| aarg0
== WINED3DTA_TEXTURE
)
6432 ttff
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
6433 if (ttff
== (WINED3D_TTFF_PROJECTED
| WINED3D_TTFF_COUNT3
))
6434 settings
->op
[i
].projected
= WINED3D_PROJECTION_COUNT3
;
6435 else if (ttff
& WINED3D_TTFF_PROJECTED
)
6436 settings
->op
[i
].projected
= WINED3D_PROJECTION_COUNT4
;
6438 settings
->op
[i
].projected
= WINED3D_PROJECTION_NONE
;
6442 settings
->op
[i
].projected
= WINED3D_PROJECTION_NONE
;
6445 settings
->op
[i
].cop
= cop
;
6446 settings
->op
[i
].aop
= aop
;
6447 settings
->op
[i
].carg0
= carg0
;
6448 settings
->op
[i
].carg1
= carg1
;
6449 settings
->op
[i
].carg2
= carg2
;
6450 settings
->op
[i
].aarg0
= aarg0
;
6451 settings
->op
[i
].aarg1
= aarg1
;
6452 settings
->op
[i
].aarg2
= aarg2
;
6453 settings
->op
[i
].tmp_dst
= state
->texture_states
[i
][WINED3D_TSS_RESULT_ARG
] == WINED3DTA_TEMP
;
6456 /* Clear unsupported stages */
6457 for(; i
< WINED3D_MAX_TEXTURES
; i
++) {
6458 memset(&settings
->op
[i
], 0xff, sizeof(settings
->op
[i
]));
6461 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6463 settings
->fog
= WINED3D_FFP_PS_FOG_OFF
;
6465 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
)
6467 if (use_vs(state
) || state
->vertex_declaration
->position_transformed
)
6469 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
6473 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
6475 case WINED3D_FOG_NONE
:
6476 case WINED3D_FOG_LINEAR
:
6477 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
6479 case WINED3D_FOG_EXP
:
6480 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
6482 case WINED3D_FOG_EXP2
:
6483 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
6490 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
6492 case WINED3D_FOG_LINEAR
:
6493 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
6495 case WINED3D_FOG_EXP
:
6496 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
6498 case WINED3D_FOG_EXP2
:
6499 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
6503 settings
->sRGB_write
= !d3d_info
->srgb_write_control
&& needs_srgb_write(d3d_info
, state
, &state
->fb
);
6504 if (d3d_info
->vs_clipping
|| !use_vs(state
) || !state
->render_states
[WINED3D_RS_CLIPPING
]
6505 || !state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
])
6507 /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
6508 * the fixed function vertex pipeline is used(which always supports clipplanes), or
6509 * if no clipplane is enabled
6511 settings
->emul_clipplanes
= 0;
6513 settings
->emul_clipplanes
= 1;
6516 if (state
->render_states
[WINED3D_RS_COLORKEYENABLE
] && state
->textures
[0]
6517 && state
->textures
[0]->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
6518 && settings
->op
[0].cop
!= WINED3D_TOP_DISABLE
)
6519 settings
->color_key_enabled
= 1;
6521 settings
->color_key_enabled
= 0;
6523 /* texcoords_initialized is set to meaningful values only when GL doesn't
6524 * support enough varyings to always pass around all the possible texture
6526 * This is used to avoid reading a varying not written by the vertex shader.
6527 * Reading uninitialized varyings on core profile contexts results in an
6528 * error while with builtin varyings on legacy contexts you get undefined
6530 if (d3d_info
->limits
.varying_count
&& !d3d_info
->full_ffp_varyings
)
6532 settings
->texcoords_initialized
= 0;
6533 for (i
= 0; i
< WINED3D_MAX_TEXTURES
; ++i
)
6537 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
6538 settings
->texcoords_initialized
|= 1u << i
;
6542 const struct wined3d_stream_info
*si
= &context
->stream_info
;
6543 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6544 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
6545 & WINED3D_FFP_TCI_MASK
6546 || (coord_idx
< WINED3D_MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
6547 settings
->texcoords_initialized
|= 1u << i
;
6553 settings
->texcoords_initialized
= wined3d_mask_from_size(WINED3D_MAX_TEXTURES
);
6556 settings
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
6557 && state
->primitive_type
== WINED3D_PT_POINTLIST
;
6559 if (d3d_info
->ffp_alpha_test
)
6560 settings
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
6562 settings
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
6563 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
6564 : WINED3D_CMP_ALWAYS
) - 1;
6566 if (d3d_info
->emulated_flatshading
)
6567 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6569 settings
->flatshading
= FALSE
;
6572 const struct ffp_frag_desc
*find_ffp_frag_shader(const struct wine_rb_tree
*fragment_shaders
,
6573 const struct ffp_frag_settings
*settings
)
6575 struct wine_rb_entry
*entry
= wine_rb_get(fragment_shaders
, settings
);
6576 return entry
? WINE_RB_ENTRY_VALUE(entry
, struct ffp_frag_desc
, entry
) : NULL
;
6579 void add_ffp_frag_shader(struct wine_rb_tree
*shaders
, struct ffp_frag_desc
*desc
)
6581 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
6582 * whereas desc points to an extended structure with implementation specific parts. */
6583 if (wine_rb_put(shaders
, &desc
->settings
, &desc
->entry
) == -1)
6585 ERR("Failed to insert ffp frag shader.\n");
6589 /* Activates the texture dimension according to the bound D3D texture. Does
6590 * not care for the colorop or correct gl texture unit (when using nvrc).
6591 * Requires the caller to activate the correct unit. */
6592 /* Context activation is done by the caller (state handler). */
6593 void texture_activate_dimensions(struct wined3d_texture
*texture
, const struct wined3d_gl_info
*gl_info
)
6597 switch (wined3d_texture_gl(texture
)->target
)
6600 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
6601 checkGLcall("glDisable(GL_TEXTURE_3D)");
6602 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
6604 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
6605 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6607 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
6609 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
6610 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6612 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
6613 checkGLcall("glEnable(GL_TEXTURE_2D)");
6615 case GL_TEXTURE_RECTANGLE_ARB
:
6616 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
6617 checkGLcall("glDisable(GL_TEXTURE_2D)");
6618 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
6619 checkGLcall("glDisable(GL_TEXTURE_3D)");
6620 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
6622 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
6623 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6625 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_RECTANGLE_ARB
);
6626 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
6629 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
6631 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
6632 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6634 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
6636 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
6637 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6639 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
6640 checkGLcall("glDisable(GL_TEXTURE_2D)");
6641 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_3D
);
6642 checkGLcall("glEnable(GL_TEXTURE_3D)");
6644 case GL_TEXTURE_CUBE_MAP_ARB
:
6645 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
6646 checkGLcall("glDisable(GL_TEXTURE_2D)");
6647 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
6648 checkGLcall("glDisable(GL_TEXTURE_3D)");
6649 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
6651 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
6652 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6654 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
6655 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
6661 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
6662 checkGLcall("glEnable(GL_TEXTURE_2D)");
6663 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
6664 checkGLcall("glDisable(GL_TEXTURE_3D)");
6665 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
6667 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
6668 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
6670 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
6672 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
6673 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
6675 /* Binding textures is done by samplers. A dummy texture will be bound */
6679 /* Context activation is done by the caller (state handler). */
6680 void sampler_texdim(struct wined3d_context
*context
, const struct wined3d_state
*state
, DWORD state_id
)
6682 struct wined3d_context_gl
*context_gl
= wined3d_context_gl(context
);
6683 unsigned int sampler
= state_id
- STATE_SAMPLER(0);
6684 unsigned int mapped_stage
;
6686 /* No need to enable / disable anything here for unused samplers. The
6687 * tex_colorop handler takes care. Also no action is needed with pixel
6688 * shaders, or if tex_colorop will take care of this business. */
6689 mapped_stage
= context_gl
->tex_unit_map
[sampler
];
6690 if (mapped_stage
== WINED3D_UNMAPPED_STAGE
|| mapped_stage
>= context_gl
->gl_info
->limits
.textures
)
6692 if (sampler
>= context
->lowest_disabled_stage
)
6694 if (isStateDirty(context
, STATE_TEXTURESTAGE(sampler
, WINED3D_TSS_COLOR_OP
)))
6697 texture_activate_dimensions(state
->textures
[sampler
], context_gl
->gl_info
);
6700 int wined3d_ffp_frag_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
6702 const struct ffp_frag_settings
*ka
= key
;
6703 const struct ffp_frag_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
, const struct ffp_frag_desc
, entry
)->settings
;
6705 return memcmp(ka
, kb
, sizeof(*ka
));
6708 void wined3d_ffp_get_vs_settings(const struct wined3d_context
*context
,
6709 const struct wined3d_state
*state
, struct wined3d_ffp_vs_settings
*settings
)
6711 enum wined3d_material_color_source diffuse_source
, emissive_source
, ambient_source
, specular_source
;
6712 const struct wined3d_stream_info
*si
= &context
->stream_info
;
6713 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
6714 unsigned int coord_idx
, i
;
6716 memset(settings
, 0, sizeof(*settings
));
6718 if (si
->position_transformed
)
6720 settings
->transformed
= 1;
6721 settings
->point_size
= state
->primitive_type
== WINED3D_PT_POINTLIST
;
6722 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
6723 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6724 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
6725 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
6726 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6728 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
6730 for (i
= 0; i
< WINED3D_MAX_TEXTURES
; ++i
)
6732 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6733 if (coord_idx
< WINED3D_MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
6734 settings
->texcoords
|= 1u << i
;
6735 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6737 if (d3d_info
->full_ffp_varyings
)
6738 settings
->texcoords
= wined3d_mask_from_size(WINED3D_MAX_TEXTURES
);
6740 if (d3d_info
->emulated_flatshading
)
6741 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6743 settings
->flatshading
= FALSE
;
6745 settings
->swizzle_map
= si
->swizzle_map
;
6750 switch (state
->render_states
[WINED3D_RS_VERTEXBLEND
])
6752 case WINED3D_VBF_DISABLE
:
6753 case WINED3D_VBF_1WEIGHTS
:
6754 case WINED3D_VBF_2WEIGHTS
:
6755 case WINED3D_VBF_3WEIGHTS
:
6756 settings
->vertexblends
= state
->render_states
[WINED3D_RS_VERTEXBLEND
];
6759 FIXME("Unsupported vertex blending: %d\n", state
->render_states
[WINED3D_RS_VERTEXBLEND
]);
6763 settings
->clipping
= state
->render_states
[WINED3D_RS_CLIPPING
]
6764 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
6765 settings
->normal
= !!(si
->use_map
& (1u << WINED3D_FFP_NORMAL
));
6766 settings
->normalize
= settings
->normal
&& state
->render_states
[WINED3D_RS_NORMALIZENORMALS
];
6767 settings
->lighting
= !!state
->render_states
[WINED3D_RS_LIGHTING
];
6768 settings
->localviewer
= !!state
->render_states
[WINED3D_RS_LOCALVIEWER
];
6769 settings
->point_size
= state
->primitive_type
== WINED3D_PT_POINTLIST
;
6770 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
6772 wined3d_get_material_colour_source(&diffuse_source
, &emissive_source
,
6773 &ambient_source
, &specular_source
, state
, si
);
6774 settings
->diffuse_source
= diffuse_source
;
6775 settings
->emissive_source
= emissive_source
;
6776 settings
->ambient_source
= ambient_source
;
6777 settings
->specular_source
= specular_source
;
6779 for (i
= 0; i
< WINED3D_MAX_TEXTURES
; ++i
)
6781 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6782 if (coord_idx
< WINED3D_MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
6783 settings
->texcoords
|= 1u << i
;
6784 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
6786 if (d3d_info
->full_ffp_varyings
)
6787 settings
->texcoords
= wined3d_mask_from_size(WINED3D_MAX_TEXTURES
);
6789 for (i
= 0; i
< WINED3D_MAX_ACTIVE_LIGHTS
; ++i
)
6791 if (!state
->light_state
.lights
[i
])
6794 switch (state
->light_state
.lights
[i
]->OriginalParms
.type
)
6796 case WINED3D_LIGHT_POINT
:
6797 ++settings
->point_light_count
;
6799 case WINED3D_LIGHT_SPOT
:
6800 ++settings
->spot_light_count
;
6802 case WINED3D_LIGHT_DIRECTIONAL
:
6803 ++settings
->directional_light_count
;
6805 case WINED3D_LIGHT_PARALLELPOINT
:
6806 ++settings
->parallel_point_light_count
;
6809 FIXME("Unhandled light type %#x.\n", state
->light_state
.lights
[i
]->OriginalParms
.type
);
6814 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6815 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
6816 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
6818 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6820 if (state
->transforms
[WINED3D_TS_PROJECTION
]._14
== 0.0f
6821 && state
->transforms
[WINED3D_TS_PROJECTION
]._24
== 0.0f
6822 && state
->transforms
[WINED3D_TS_PROJECTION
]._34
== 0.0f
6823 && state
->transforms
[WINED3D_TS_PROJECTION
]._44
== 1.0f
)
6824 settings
->ortho_fog
= 1;
6826 else if (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
] == WINED3D_FOG_NONE
)
6827 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
6828 else if (state
->render_states
[WINED3D_RS_RANGEFOGENABLE
])
6829 settings
->fog_mode
= WINED3D_FFP_VS_FOG_RANGE
;
6831 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6833 if (d3d_info
->emulated_flatshading
)
6834 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6836 settings
->flatshading
= FALSE
;
6838 settings
->swizzle_map
= si
->swizzle_map
;
6841 int wined3d_ffp_vertex_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
6843 const struct wined3d_ffp_vs_settings
*ka
= key
;
6844 const struct wined3d_ffp_vs_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
,
6845 const struct wined3d_ffp_vs_desc
, entry
)->settings
;
6847 return memcmp(ka
, kb
, sizeof(*ka
));
6850 const char *wined3d_debug_location(DWORD location
)
6852 struct debug_buffer buffer
;
6853 const char *prefix
= "";
6854 const char *suffix
= "";
6856 if (wined3d_popcount(location
) > 16)
6859 location
= ~location
;
6863 init_debug_buffer(&buffer
, "0");
6864 #define LOCATION_TO_STR(x) if (location & x) { debug_append(&buffer, #x, " | "); location &= ~x; }
6865 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED
);
6866 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM
);
6867 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER
);
6868 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB
);
6869 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB
);
6870 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE
);
6871 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE
);
6872 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED
);
6873 #undef LOCATION_TO_STR
6875 FIXME("Unrecognized location flag(s) %#x.\n", location
);
6877 return wine_dbg_sprintf("%s%s%s", prefix
, buffer
.str
, suffix
);
6880 const char *wined3d_debug_feature_level(enum wined3d_feature_level level
)
6884 #define LEVEL_TO_STR(level) case level: return #level
6885 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_5
);
6886 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_6
);
6887 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_7
);
6888 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_8
);
6889 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_1
);
6890 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_2
);
6891 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_9_3
);
6892 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_10
);
6893 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_10_1
);
6894 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_11
);
6895 LEVEL_TO_STR(WINED3D_FEATURE_LEVEL_11_1
);
6898 return wine_dbg_sprintf("%#x", level
);
6902 /* Print a floating point value with the %.8e format specifier, always using
6903 * '.' as decimal separator. */
6904 void wined3d_ftoa(float value
, char *s
)
6908 if (copysignf(1.0f
, value
) < 0.0f
)
6911 /* Be sure to allocate a buffer of at least 17 characters for the result
6912 as sprintf may return a 3 digit exponent when using the MSVC runtime
6913 instead of a 2 digit exponent. */
6914 sprintf(s
, "%.8e", value
);
6915 if (isfinite(value
))
6919 void wined3d_release_dc(HWND window
, HDC dc
)
6921 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
6922 * However, that's not what actually happens, and there are user32 tests
6923 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
6924 * So explicitly check that the DC belongs to the window, since we want to
6925 * avoid releasing a DC that belongs to some other window if the original
6926 * window was already destroyed. */
6927 if (WindowFromDC(dc
) != window
)
6928 WARN("DC %p does not belong to window %p.\n", dc
, window
);
6929 else if (!ReleaseDC(window
, dc
))
6930 ERR("Failed to release device context %p, last error %#x.\n", dc
, GetLastError());
6933 BOOL
wined3d_clip_blit(const RECT
*clip_rect
, RECT
*clipped
, RECT
*other
)
6935 RECT orig
= *clipped
;
6936 float scale_x
= (float)(orig
.right
- orig
.left
) / (float)(other
->right
- other
->left
);
6937 float scale_y
= (float)(orig
.bottom
- orig
.top
) / (float)(other
->bottom
- other
->top
);
6939 IntersectRect(clipped
, clipped
, clip_rect
);
6941 if (IsRectEmpty(clipped
))
6943 SetRectEmpty(other
);
6947 other
->left
+= (LONG
)((clipped
->left
- orig
.left
) / scale_x
);
6948 other
->top
+= (LONG
)((clipped
->top
- orig
.top
) / scale_y
);
6949 other
->right
-= (LONG
)((orig
.right
- clipped
->right
) / scale_x
);
6950 other
->bottom
-= (LONG
)((orig
.bottom
- clipped
->bottom
) / scale_y
);
6955 void wined3d_gl_limits_get_uniform_block_range(const struct wined3d_gl_limits
*gl_limits
,
6956 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
6961 for (i
= 0; i
< WINED3D_SHADER_TYPE_COUNT
; ++i
)
6963 *count
= gl_limits
->uniform_blocks
[i
];
6964 if (i
== shader_type
)
6969 ERR("Unrecognized shader type %#x.\n", shader_type
);
6973 void wined3d_gl_limits_get_texture_unit_range(const struct wined3d_gl_limits
*gl_limits
,
6974 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
6978 if (shader_type
== WINED3D_SHADER_TYPE_COMPUTE
)
6980 if (gl_limits
->combined_samplers
== gl_limits
->graphics_samplers
)
6983 *base
= gl_limits
->graphics_samplers
;
6984 *count
= gl_limits
->samplers
[WINED3D_SHADER_TYPE_COMPUTE
];
6989 for (i
= 0; i
< WINED3D_SHADER_TYPE_GRAPHICS_COUNT
; ++i
)
6991 *count
= gl_limits
->samplers
[i
];
6992 if (i
== shader_type
)
6997 ERR("Unrecognized shader type %#x.\n", shader_type
);
7001 BOOL
wined3d_array_reserve(void **elements
, SIZE_T
*capacity
, SIZE_T count
, SIZE_T size
)
7003 SIZE_T max_capacity
, new_capacity
;
7006 if (count
<= *capacity
)
7009 max_capacity
= ~(SIZE_T
)0 / size
;
7010 if (count
> max_capacity
)
7013 new_capacity
= max(1, *capacity
);
7014 while (new_capacity
< count
&& new_capacity
<= max_capacity
/ 2)
7016 if (new_capacity
< count
)
7017 new_capacity
= count
;
7020 new_elements
= heap_alloc_zero(new_capacity
* size
);
7022 new_elements
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, *elements
, new_capacity
* size
);
7026 *elements
= new_elements
;
7027 *capacity
= new_capacity
;
7031 static void swap_rows(float **a
, float **b
)
7039 BOOL
invert_matrix(struct wined3d_matrix
*out
, const struct wined3d_matrix
*m
)
7042 float m0
, m1
, m2
, m3
, s
;
7043 float *r0
, *r1
, *r2
, *r3
;
7055 r0
[5] = r0
[6] = r0
[7] = 0.0f
;
7062 r1
[4] = r1
[6] = r1
[7] = 0.0f
;
7069 r2
[4] = r2
[5] = r2
[7] = 0.0f
;
7076 r3
[4] = r3
[5] = r3
[6] = 0.0f
;
7078 /* Choose pivot - or die. */
7079 if (fabsf(r3
[0]) > fabsf(r2
[0]))
7080 swap_rows(&r3
, &r2
);
7081 if (fabsf(r2
[0]) > fabsf(r1
[0]))
7082 swap_rows(&r2
, &r1
);
7083 if (fabsf(r1
[0]) > fabsf(r0
[0]))
7084 swap_rows(&r1
, &r0
);
7088 /* Eliminate first variable. */
7089 m1
= r1
[0] / r0
[0]; m2
= r2
[0] / r0
[0]; m3
= r3
[0] / r0
[0];
7090 s
= r0
[1]; r1
[1] -= m1
* s
; r2
[1] -= m2
* s
; r3
[1] -= m3
* s
;
7091 s
= r0
[2]; r1
[2] -= m1
* s
; r2
[2] -= m2
* s
; r3
[2] -= m3
* s
;
7092 s
= r0
[3]; r1
[3] -= m1
* s
; r2
[3] -= m2
* s
; r3
[3] -= m3
* s
;
7122 /* Choose pivot - or die. */
7123 if (fabsf(r3
[1]) > fabsf(r2
[1]))
7124 swap_rows(&r3
, &r2
);
7125 if (fabsf(r2
[1]) > fabsf(r1
[1]))
7126 swap_rows(&r2
, &r1
);
7130 /* Eliminate second variable. */
7131 m2
= r2
[1] / r1
[1]; m3
= r3
[1] / r1
[1];
7132 r2
[2] -= m2
* r1
[2]; r3
[2] -= m3
* r1
[2];
7133 r2
[3] -= m2
* r1
[3]; r3
[3] -= m3
* r1
[3];
7159 /* Choose pivot - or die. */
7160 if (fabsf(r3
[2]) > fabsf(r2
[2]))
7161 swap_rows(&r3
, &r2
);
7165 /* Eliminate third variable. */
7167 r3
[3] -= m3
* r2
[3];
7168 r3
[4] -= m3
* r2
[4];
7169 r3
[5] -= m3
* r2
[5];
7170 r3
[6] -= m3
* r2
[6];
7171 r3
[7] -= m3
* r2
[7];
7177 /* Back substitute row 3. */
7184 /* Back substitute row 2. */
7187 r2
[4] = s
* (r2
[4] - r3
[4] * m2
);
7188 r2
[5] = s
* (r2
[5] - r3
[5] * m2
);
7189 r2
[6] = s
* (r2
[6] - r3
[6] * m2
);
7190 r2
[7] = s
* (r2
[7] - r3
[7] * m2
);
7192 r1
[4] -= r3
[4] * m1
;
7193 r1
[5] -= r3
[5] * m1
;
7194 r1
[6] -= r3
[6] * m1
;
7195 r1
[7] -= r3
[7] * m1
;
7197 r0
[4] -= r3
[4] * m0
;
7198 r0
[5] -= r3
[5] * m0
;
7199 r0
[6] -= r3
[6] * m0
;
7200 r0
[7] -= r3
[7] * m0
;
7202 /* Back substitute row 1. */
7205 r1
[4] = s
* (r1
[4] - r2
[4] * m1
);
7206 r1
[5] = s
* (r1
[5] - r2
[5] * m1
);
7207 r1
[6] = s
* (r1
[6] - r2
[6] * m1
);
7208 r1
[7] = s
* (r1
[7] - r2
[7] * m1
);
7210 r0
[4] -= r2
[4] * m0
;
7211 r0
[5] -= r2
[5] * m0
;
7212 r0
[6] -= r2
[6] * m0
;
7213 r0
[7] -= r2
[7] * m0
;
7215 /* Back substitute row 0. */
7218 r0
[4] = s
* (r0
[4] - r1
[4] * m0
);
7219 r0
[5] = s
* (r0
[5] - r1
[5] * m0
);
7220 r0
[6] = s
* (r0
[6] - r1
[6] * m0
);
7221 r0
[7] = s
* (r0
[7] - r1
[7] * m0
);
7243 /* Taken and adapted from Mesa. */
7244 static BOOL
invert_matrix_3d(struct wined3d_matrix
*out
, const struct wined3d_matrix
*in
)
7246 float pos
, neg
, t
, det
;
7247 struct wined3d_matrix temp
;
7249 /* Calculate the determinant of upper left 3x3 submatrix and
7250 * determine if the matrix is singular. */
7252 t
= in
->_11
* in
->_22
* in
->_33
;
7258 t
= in
->_21
* in
->_32
* in
->_13
;
7263 t
= in
->_31
* in
->_12
* in
->_23
;
7269 t
= -in
->_31
* in
->_22
* in
->_13
;
7274 t
= -in
->_21
* in
->_12
* in
->_33
;
7280 t
= -in
->_11
* in
->_32
* in
->_23
;
7288 if (fabsf(det
) < 1e-25f
)
7292 temp
._11
= (in
->_22
* in
->_33
- in
->_32
* in
->_23
) * det
;
7293 temp
._12
= -(in
->_12
* in
->_33
- in
->_32
* in
->_13
) * det
;
7294 temp
._13
= (in
->_12
* in
->_23
- in
->_22
* in
->_13
) * det
;
7295 temp
._21
= -(in
->_21
* in
->_33
- in
->_31
* in
->_23
) * det
;
7296 temp
._22
= (in
->_11
* in
->_33
- in
->_31
* in
->_13
) * det
;
7297 temp
._23
= -(in
->_11
* in
->_23
- in
->_21
* in
->_13
) * det
;
7298 temp
._31
= (in
->_21
* in
->_32
- in
->_31
* in
->_22
) * det
;
7299 temp
._32
= -(in
->_11
* in
->_32
- in
->_31
* in
->_12
) * det
;
7300 temp
._33
= (in
->_11
* in
->_22
- in
->_21
* in
->_12
) * det
;
7306 void compute_normal_matrix(float *normal_matrix
, BOOL legacy_lighting
,
7307 const struct wined3d_matrix
*modelview
)
7309 struct wined3d_matrix mv
;
7313 if (legacy_lighting
)
7314 invert_matrix_3d(&mv
, &mv
);
7316 invert_matrix(&mv
, &mv
);
7317 /* Tests show that singular modelview matrices are used unchanged as normal
7318 * matrices on D3D3 and older. There seems to be no clearly consistent
7319 * behavior on newer D3D versions so always follow older ddraw behavior. */
7320 for (i
= 0; i
< 3; ++i
)
7321 for (j
= 0; j
< 3; ++j
)
7322 normal_matrix
[i
* 3 + j
] = (&mv
._11
)[j
* 4 + i
];
7325 static void wined3d_allocator_release_block(struct wined3d_allocator
*allocator
,
7326 struct wined3d_allocator_block
*block
)
7328 block
->parent
= allocator
->free
;
7329 allocator
->free
= block
;
7332 static struct wined3d_allocator_block
*wined3d_allocator_acquire_block(struct wined3d_allocator
*allocator
)
7334 struct wined3d_allocator_block
*block
;
7336 if (!allocator
->free
)
7337 return heap_alloc(sizeof(*block
));
7339 block
= allocator
->free
;
7340 allocator
->free
= block
->parent
;
7345 void wined3d_allocator_block_free(struct wined3d_allocator_block
*block
)
7347 struct wined3d_allocator
*allocator
= block
->chunk
->allocator
;
7348 struct wined3d_allocator_block
*parent
;
7350 while ((parent
= block
->parent
) && block
->sibling
->free
)
7352 list_remove(&block
->sibling
->entry
);
7353 wined3d_allocator_release_block(allocator
, block
->sibling
);
7354 wined3d_allocator_release_block(allocator
, block
);
7359 list_add_head(&block
->chunk
->available
[block
->order
], &block
->entry
);
7362 static void wined3d_allocator_block_init(struct wined3d_allocator_block
*block
,
7363 struct wined3d_allocator_chunk
*chunk
, struct wined3d_allocator_block
*parent
,
7364 struct wined3d_allocator_block
*sibling
, unsigned int order
, size_t offset
, bool free
)
7366 list_init(&block
->entry
);
7367 block
->chunk
= chunk
;
7368 block
->parent
= parent
;
7369 block
->sibling
= sibling
;
7370 block
->order
= order
;
7371 block
->offset
= offset
;
7375 void wined3d_allocator_chunk_cleanup(struct wined3d_allocator_chunk
*chunk
)
7377 struct wined3d_allocator_block
*block
;
7380 if (list_empty(&chunk
->available
[0]))
7382 ERR("Chunk %p is not empty.\n", chunk
);
7386 for (i
= 1; i
< ARRAY_SIZE(chunk
->available
); ++i
)
7388 if (!list_empty(&chunk
->available
[i
]))
7390 ERR("Chunk %p is not empty.\n", chunk
);
7395 block
= LIST_ENTRY(list_head(&chunk
->available
[0]), struct wined3d_allocator_block
, entry
);
7396 wined3d_allocator_release_block(chunk
->allocator
, block
);
7399 bool wined3d_allocator_chunk_init(struct wined3d_allocator_chunk
*chunk
, struct wined3d_allocator
*allocator
)
7401 struct wined3d_allocator_block
*block
;
7404 if (!(block
= wined3d_allocator_acquire_block(allocator
)))
7406 wined3d_allocator_block_init(block
, chunk
, NULL
, NULL
, 0, 0, true);
7408 list_init(&chunk
->entry
);
7409 for (i
= 0; i
< ARRAY_SIZE(chunk
->available
); ++i
)
7411 list_init(&chunk
->available
[i
]);
7413 list_add_head(&chunk
->available
[0], &block
->entry
);
7414 chunk
->allocator
= allocator
;
7415 chunk
->map_count
= 0;
7416 chunk
->map_ptr
= NULL
;
7421 void wined3d_allocator_cleanup(struct wined3d_allocator
*allocator
)
7423 struct wined3d_allocator_chunk
*chunk
, *chunk2
;
7424 struct wined3d_allocator_block
*block
, *next
;
7427 for (i
= 0; i
< allocator
->pool_count
; ++i
)
7429 LIST_FOR_EACH_ENTRY_SAFE(chunk
, chunk2
, &allocator
->pools
[i
].chunks
, struct wined3d_allocator_chunk
, entry
)
7431 list_remove(&chunk
->entry
);
7432 allocator
->ops
->allocator_destroy_chunk(chunk
);
7435 heap_free(allocator
->pools
);
7437 next
= allocator
->free
;
7438 while ((block
= next
))
7440 next
= block
->parent
;
7445 static struct wined3d_allocator_block
*wined3d_allocator_chunk_allocate(struct wined3d_allocator_chunk
*chunk
,
7448 struct wined3d_allocator_block
*block
, *left
, *right
;
7449 unsigned int i
= order
;
7453 if (!list_empty(&chunk
->available
[i
]))
7458 if (list_empty(&chunk
->available
[i
]))
7461 block
= LIST_ENTRY(list_head(&chunk
->available
[i
]), struct wined3d_allocator_block
, entry
);
7462 list_remove(&block
->entry
);
7463 block
->free
= false;
7467 if (!(left
= wined3d_allocator_acquire_block(chunk
->allocator
)))
7469 ERR("Failed to allocate left.\n");
7473 if (!(right
= wined3d_allocator_acquire_block(chunk
->allocator
)))
7475 ERR("Failed to allocate right.\n");
7476 wined3d_allocator_release_block(chunk
->allocator
, left
);
7480 wined3d_allocator_block_init(left
, chunk
, block
, right
, block
->order
+ 1, block
->offset
, false);
7481 wined3d_allocator_block_init(right
, chunk
, block
, left
, block
->order
+ 1,
7482 block
->offset
+ (WINED3D_ALLOCATOR_CHUNK_SIZE
>> left
->order
), true);
7483 list_add_head(&chunk
->available
[right
->order
], &right
->entry
);
7492 struct wined3d_allocator_block
*wined3d_allocator_allocate(struct wined3d_allocator
*allocator
,
7493 struct wined3d_context
*context
, unsigned int memory_type
, size_t size
)
7495 struct wined3d_allocator_chunk
*chunk
;
7496 struct wined3d_allocator_block
*block
;
7499 if (size
> WINED3D_ALLOCATOR_CHUNK_SIZE
/ 2)
7502 if (size
< WINED3D_ALLOCATOR_MIN_BLOCK_SIZE
)
7503 order
= WINED3D_ALLOCATOR_CHUNK_ORDER_COUNT
- 1;
7505 order
= wined3d_log2i(WINED3D_ALLOCATOR_CHUNK_SIZE
/ size
);
7507 LIST_FOR_EACH_ENTRY(chunk
, &allocator
->pools
[memory_type
].chunks
, struct wined3d_allocator_chunk
, entry
)
7509 if ((block
= wined3d_allocator_chunk_allocate(chunk
, order
)))
7513 if (!(chunk
= allocator
->ops
->allocator_create_chunk(allocator
,
7514 context
, memory_type
, WINED3D_ALLOCATOR_CHUNK_SIZE
)))
7517 if (!(block
= wined3d_allocator_chunk_allocate(chunk
, order
)))
7523 bool wined3d_allocator_init(struct wined3d_allocator
*allocator
,
7524 size_t pool_count
, const struct wined3d_allocator_ops
*allocator_ops
)
7528 allocator
->ops
= allocator_ops
;
7529 allocator
->pool_count
= pool_count
;
7530 if (!(allocator
->pools
= heap_calloc(pool_count
, sizeof(*allocator
->pools
))))
7532 for (i
= 0; i
< pool_count
; ++i
)
7534 list_init(&allocator
->pools
[i
].chunks
);
7537 allocator
->free
= NULL
;