2 * Utility functions for the WineD3D Library
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2006-2008 Henri Verbeet
9 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
10 * Copyright 2009-2010 Henri Verbeet for CodeWeavers
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/port.h"
32 #include "wined3d_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
36 #define WINED3D_FORMAT_FOURCC_BASE (WINED3DFMT_BC7_UNORM_SRGB + 1)
40 enum wined3d_format_id id
;
43 format_index_remap
[] =
45 {WINED3DFMT_UYVY
, WINED3D_FORMAT_FOURCC_BASE
},
46 {WINED3DFMT_YUY2
, WINED3D_FORMAT_FOURCC_BASE
+ 1},
47 {WINED3DFMT_YV12
, WINED3D_FORMAT_FOURCC_BASE
+ 2},
48 {WINED3DFMT_DXT1
, WINED3D_FORMAT_FOURCC_BASE
+ 3},
49 {WINED3DFMT_DXT2
, WINED3D_FORMAT_FOURCC_BASE
+ 4},
50 {WINED3DFMT_DXT3
, WINED3D_FORMAT_FOURCC_BASE
+ 5},
51 {WINED3DFMT_DXT4
, WINED3D_FORMAT_FOURCC_BASE
+ 6},
52 {WINED3DFMT_DXT5
, WINED3D_FORMAT_FOURCC_BASE
+ 7},
53 {WINED3DFMT_MULTI2_ARGB8
, WINED3D_FORMAT_FOURCC_BASE
+ 8},
54 {WINED3DFMT_G8R8_G8B8
, WINED3D_FORMAT_FOURCC_BASE
+ 9},
55 {WINED3DFMT_R8G8_B8G8
, WINED3D_FORMAT_FOURCC_BASE
+ 10},
56 {WINED3DFMT_ATI1N
, WINED3D_FORMAT_FOURCC_BASE
+ 11},
57 {WINED3DFMT_ATI2N
, WINED3D_FORMAT_FOURCC_BASE
+ 12},
58 {WINED3DFMT_INST
, WINED3D_FORMAT_FOURCC_BASE
+ 13},
59 {WINED3DFMT_NVDB
, WINED3D_FORMAT_FOURCC_BASE
+ 14},
60 {WINED3DFMT_NVHU
, WINED3D_FORMAT_FOURCC_BASE
+ 15},
61 {WINED3DFMT_NVHS
, WINED3D_FORMAT_FOURCC_BASE
+ 16},
62 {WINED3DFMT_INTZ
, WINED3D_FORMAT_FOURCC_BASE
+ 17},
63 {WINED3DFMT_RESZ
, WINED3D_FORMAT_FOURCC_BASE
+ 18},
64 {WINED3DFMT_NULL
, WINED3D_FORMAT_FOURCC_BASE
+ 19},
65 {WINED3DFMT_R16
, WINED3D_FORMAT_FOURCC_BASE
+ 20},
66 {WINED3DFMT_AL16
, WINED3D_FORMAT_FOURCC_BASE
+ 21},
67 {WINED3DFMT_NV12
, WINED3D_FORMAT_FOURCC_BASE
+ 22},
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_R8G8B8A8_SNORM
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
126 {WINED3DFMT_R10G11B11_SNORM
, 10, 11, 11, 0, 0, 10, 21, 0, 4, 0, 0},
127 {WINED3DFMT_R10G10B10X2_UINT
, 10, 10, 10, 0, 0, 10, 20, 0, 4, 0, 0},
128 {WINED3DFMT_R10G10B10X2_SNORM
, 10, 10, 10, 0, 0, 10, 20, 0, 4, 0, 0},
129 {WINED3DFMT_R10G10B10_SNORM_A2_UNORM
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
130 /* Depth stencil formats */
131 {WINED3DFMT_D16_LOCKABLE
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
132 {WINED3DFMT_D32_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
133 {WINED3DFMT_S1_UINT_D15_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 15, 1},
134 {WINED3DFMT_X8D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 0},
135 {WINED3DFMT_S4X4_UINT_D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 4},
136 {WINED3DFMT_D16_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
137 {WINED3DFMT_D32_FLOAT
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
138 {WINED3DFMT_S8_UINT_D24_FLOAT
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
139 /* Vendor-specific formats */
140 {WINED3DFMT_ATI1N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
141 {WINED3DFMT_ATI2N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
142 {WINED3DFMT_NVDB
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
143 {WINED3DFMT_INST
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
144 {WINED3DFMT_INTZ
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
145 {WINED3DFMT_RESZ
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
146 {WINED3DFMT_NVHU
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
147 {WINED3DFMT_NVHS
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
148 {WINED3DFMT_NULL
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
149 /* Unsure about them, could not find a Windows driver that supports them */
150 {WINED3DFMT_R16
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
151 {WINED3DFMT_AL16
, 0, 0, 0, 16, 0, 0, 0, 16, 4, 0, 0},
152 /* DirectX 10 HDR formats */
153 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
155 {WINED3DFMT_R32G32B32A32_TYPELESS
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
156 {WINED3DFMT_R32G32B32_TYPELESS
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
157 {WINED3DFMT_R16G16B16A16_TYPELESS
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
158 {WINED3DFMT_R32G32_TYPELESS
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
159 {WINED3DFMT_R32G8X24_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 8, 32, 8},
160 {WINED3DFMT_R10G10B10A2_TYPELESS
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
161 {WINED3DFMT_R8G8B8A8_TYPELESS
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
162 {WINED3DFMT_R16G16_TYPELESS
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
163 {WINED3DFMT_R32_TYPELESS
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
164 {WINED3DFMT_R24G8_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
165 {WINED3DFMT_R8G8_TYPELESS
, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
166 {WINED3DFMT_R16_TYPELESS
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
167 {WINED3DFMT_R8_TYPELESS
, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
168 {WINED3DFMT_BC1_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
169 {WINED3DFMT_BC2_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
170 {WINED3DFMT_BC3_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
171 {WINED3DFMT_BC4_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
172 {WINED3DFMT_BC5_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
173 {WINED3DFMT_BC6H_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
174 {WINED3DFMT_BC7_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
175 {WINED3DFMT_B8G8R8A8_TYPELESS
, 8, 8, 8, 8, 16, 8, 0, 24, 4, 0, 0},
176 {WINED3DFMT_B8G8R8X8_TYPELESS
, 8, 8, 8, 0, 16, 8, 0, 0, 4, 0, 0},
179 enum wined3d_channel_type
181 WINED3D_CHANNEL_TYPE_NONE
,
182 WINED3D_CHANNEL_TYPE_UNORM
,
183 WINED3D_CHANNEL_TYPE_SNORM
,
184 WINED3D_CHANNEL_TYPE_UINT
,
185 WINED3D_CHANNEL_TYPE_SINT
,
186 WINED3D_CHANNEL_TYPE_FLOAT
,
187 WINED3D_CHANNEL_TYPE_DEPTH
,
188 WINED3D_CHANNEL_TYPE_STENCIL
,
189 WINED3D_CHANNEL_TYPE_UNUSED
,
192 struct wined3d_typed_format_info
194 enum wined3d_format_id id
;
195 enum wined3d_format_id typeless_id
;
196 const char *channels
;
200 * The last entry for a given typeless format defines its internal format.
202 * u - WINED3D_CHANNEL_TYPE_UNORM
203 * i - WINED3D_CHANNEL_TYPE_SNORM
204 * U - WINED3D_CHANNEL_TYPE_UINT
205 * I - WINED3D_CHANNEL_TYPE_SINT
206 * F - WINED3D_CHANNEL_TYPE_FLOAT
207 * D - WINED3D_CHANNEL_TYPE_DEPTH
208 * S - WINED3D_CHANNEL_TYPE_STENCIL
209 * X - WINED3D_CHANNEL_TYPE_UNUSED
211 static const struct wined3d_typed_format_info typed_formats
[] =
213 {WINED3DFMT_R32G32B32A32_UINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "UUUU"},
214 {WINED3DFMT_R32G32B32A32_SINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "IIII"},
215 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "FFFF"},
216 {WINED3DFMT_R32G32B32_UINT
, WINED3DFMT_R32G32B32_TYPELESS
, "UUU"},
217 {WINED3DFMT_R32G32B32_SINT
, WINED3DFMT_R32G32B32_TYPELESS
, "III"},
218 {WINED3DFMT_R32G32B32_FLOAT
, WINED3DFMT_R32G32B32_TYPELESS
, "FFF"},
219 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "uuuu"},
220 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "iiii"},
221 {WINED3DFMT_R16G16B16A16_UINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "UUUU"},
222 {WINED3DFMT_R16G16B16A16_SINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "IIII"},
223 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "FFFF"},
224 {WINED3DFMT_R32G32_UINT
, WINED3DFMT_R32G32_TYPELESS
, "UU"},
225 {WINED3DFMT_R32G32_SINT
, WINED3DFMT_R32G32_TYPELESS
, "II"},
226 {WINED3DFMT_R32G32_FLOAT
, WINED3DFMT_R32G32_TYPELESS
, "FF"},
227 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, WINED3DFMT_R32G8X24_TYPELESS
, "DX"},
228 {WINED3DFMT_X32_TYPELESS_G8X24_UINT
, WINED3DFMT_R32G8X24_TYPELESS
, "XS"},
229 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, WINED3DFMT_R32G8X24_TYPELESS
, "DS"},
230 {WINED3DFMT_R10G10B10A2_SNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "iiii"},
231 {WINED3DFMT_R10G10B10A2_UINT
, WINED3DFMT_R10G10B10A2_TYPELESS
, "UUUU"},
232 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "uuuu"},
233 {WINED3DFMT_R8G8B8A8_UINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "UUUU"},
234 {WINED3DFMT_R8G8B8A8_SINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "IIII"},
235 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "iiii"},
236 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
237 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
238 {WINED3DFMT_R16G16_UNORM
, WINED3DFMT_R16G16_TYPELESS
, "uu"},
239 {WINED3DFMT_R16G16_SNORM
, WINED3DFMT_R16G16_TYPELESS
, "ii"},
240 {WINED3DFMT_R16G16_UINT
, WINED3DFMT_R16G16_TYPELESS
, "UU"},
241 {WINED3DFMT_R16G16_SINT
, WINED3DFMT_R16G16_TYPELESS
, "II"},
242 {WINED3DFMT_R16G16_FLOAT
, WINED3DFMT_R16G16_TYPELESS
, "FF"},
243 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "D"},
244 {WINED3DFMT_R32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "F"},
245 {WINED3DFMT_R32_UINT
, WINED3DFMT_R32_TYPELESS
, "U"},
246 {WINED3DFMT_R32_SINT
, WINED3DFMT_R32_TYPELESS
, "I"},
247 {WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_R24G8_TYPELESS
, "DX"},
248 {WINED3DFMT_X24_TYPELESS_G8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "XS"},
249 {WINED3DFMT_D24_UNORM_S8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "DS"},
250 {WINED3DFMT_R8G8_SNORM
, WINED3DFMT_R8G8_TYPELESS
, "ii"},
251 {WINED3DFMT_R8G8_UNORM
, WINED3DFMT_R8G8_TYPELESS
, "uu"},
252 {WINED3DFMT_R8G8_UINT
, WINED3DFMT_R8G8_TYPELESS
, "UU"},
253 {WINED3DFMT_R8G8_SINT
, WINED3DFMT_R8G8_TYPELESS
, "II"},
254 {WINED3DFMT_D16_UNORM
, WINED3DFMT_R16_TYPELESS
, "D"},
255 {WINED3DFMT_R16_UNORM
, WINED3DFMT_R16_TYPELESS
, "u"},
256 {WINED3DFMT_R16_SNORM
, WINED3DFMT_R16_TYPELESS
, "i"},
257 {WINED3DFMT_R16_UINT
, WINED3DFMT_R16_TYPELESS
, "U"},
258 {WINED3DFMT_R16_SINT
, WINED3DFMT_R16_TYPELESS
, "I"},
259 {WINED3DFMT_R16_FLOAT
, WINED3DFMT_R16_TYPELESS
, "F"},
260 {WINED3DFMT_R8_UNORM
, WINED3DFMT_R8_TYPELESS
, "u"},
261 {WINED3DFMT_R8_SNORM
, WINED3DFMT_R8_TYPELESS
, "i"},
262 {WINED3DFMT_R8_UINT
, WINED3DFMT_R8_TYPELESS
, "U"},
263 {WINED3DFMT_R8_SINT
, WINED3DFMT_R8_TYPELESS
, "I"},
264 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_TYPELESS
, ""},
265 {WINED3DFMT_BC1_UNORM
, WINED3DFMT_BC1_TYPELESS
, ""},
266 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_TYPELESS
, ""},
267 {WINED3DFMT_BC2_UNORM
, WINED3DFMT_BC2_TYPELESS
, ""},
268 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_TYPELESS
, ""},
269 {WINED3DFMT_BC3_UNORM
, WINED3DFMT_BC3_TYPELESS
, ""},
270 {WINED3DFMT_BC4_UNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
271 {WINED3DFMT_BC4_SNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
272 {WINED3DFMT_BC5_UNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
273 {WINED3DFMT_BC5_SNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
274 {WINED3DFMT_BC6H_UF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
275 {WINED3DFMT_BC6H_SF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
276 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_TYPELESS
, ""},
277 {WINED3DFMT_BC7_UNORM
, WINED3DFMT_BC7_TYPELESS
, ""},
278 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
279 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
280 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
281 {WINED3DFMT_B8G8R8X8_UNORM
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
284 struct wined3d_typeless_format_depth_stencil_info
286 enum wined3d_format_id typeless_id
;
287 enum wined3d_format_id depth_stencil_id
;
288 enum wined3d_format_id depth_view_id
;
289 enum wined3d_format_id stencil_view_id
;
290 BOOL separate_depth_view_format
;
293 static const struct wined3d_typeless_format_depth_stencil_info typeless_depth_stencil_formats
[] =
295 {WINED3DFMT_R32G8X24_TYPELESS
, WINED3DFMT_D32_FLOAT_S8X24_UINT
,
296 WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, WINED3DFMT_X32_TYPELESS_G8X24_UINT
, TRUE
},
297 {WINED3DFMT_R24G8_TYPELESS
, WINED3DFMT_D24_UNORM_S8_UINT
,
298 WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_X24_TYPELESS_G8_UINT
, TRUE
},
299 {WINED3DFMT_R32_TYPELESS
, WINED3DFMT_D32_FLOAT
, WINED3DFMT_R32_FLOAT
},
300 {WINED3DFMT_R16_TYPELESS
, WINED3DFMT_D16_UNORM
, WINED3DFMT_R16_UNORM
},
303 struct wined3d_format_ddi_info
305 enum wined3d_format_id id
;
306 D3DDDIFORMAT ddi_format
;
309 static const struct wined3d_format_ddi_info ddi_formats
[] =
311 {WINED3DFMT_B8G8R8_UNORM
, D3DDDIFMT_R8G8B8
},
312 {WINED3DFMT_B8G8R8A8_UNORM
, D3DDDIFMT_A8R8G8B8
},
313 {WINED3DFMT_B8G8R8X8_UNORM
, D3DDDIFMT_X8R8G8B8
},
314 {WINED3DFMT_B5G6R5_UNORM
, D3DDDIFMT_R5G6B5
},
315 {WINED3DFMT_B5G5R5X1_UNORM
, D3DDDIFMT_X1R5G5B5
},
316 {WINED3DFMT_B5G5R5A1_UNORM
, D3DDDIFMT_A1R5G5B5
},
317 {WINED3DFMT_B4G4R4A4_UNORM
, D3DDDIFMT_A4R4G4B4
},
318 {WINED3DFMT_B4G4R4X4_UNORM
, D3DDDIFMT_X4R4G4B4
},
319 {WINED3DFMT_P8_UINT
, D3DDDIFMT_P8
},
322 struct wined3d_format_base_flags
324 enum wined3d_format_id id
;
328 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
329 * still needs to use the correct block based calculation for e.g. the
331 static const struct wined3d_format_base_flags format_base_flags
[] =
333 {WINED3DFMT_ATI1N
, WINED3DFMT_FLAG_BROKEN_PITCH
},
334 {WINED3DFMT_ATI2N
, WINED3DFMT_FLAG_BROKEN_PITCH
},
335 {WINED3DFMT_R11G11B10_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
336 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
337 {WINED3DFMT_S8_UINT_D24_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
338 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, WINED3DFMT_FLAG_FLOAT
},
339 {WINED3DFMT_INST
, WINED3DFMT_FLAG_EXTENSION
},
340 {WINED3DFMT_NULL
, WINED3DFMT_FLAG_EXTENSION
},
341 {WINED3DFMT_NVDB
, WINED3DFMT_FLAG_EXTENSION
},
342 {WINED3DFMT_RESZ
, WINED3DFMT_FLAG_EXTENSION
},
345 struct wined3d_format_block_info
347 enum wined3d_format_id id
;
350 UINT block_byte_count
;
354 static const struct wined3d_format_block_info format_block_info
[] =
356 {WINED3DFMT_DXT1
, 4, 4, 8, TRUE
},
357 {WINED3DFMT_DXT2
, 4, 4, 16, TRUE
},
358 {WINED3DFMT_DXT3
, 4, 4, 16, TRUE
},
359 {WINED3DFMT_DXT4
, 4, 4, 16, TRUE
},
360 {WINED3DFMT_DXT5
, 4, 4, 16, TRUE
},
361 {WINED3DFMT_BC1_UNORM
, 4, 4, 8, TRUE
},
362 {WINED3DFMT_BC2_UNORM
, 4, 4, 16, TRUE
},
363 {WINED3DFMT_BC3_UNORM
, 4, 4, 16, TRUE
},
364 {WINED3DFMT_BC4_UNORM
, 4, 4, 8, TRUE
},
365 {WINED3DFMT_BC4_SNORM
, 4, 4, 8, TRUE
},
366 {WINED3DFMT_BC5_UNORM
, 4, 4, 16, TRUE
},
367 {WINED3DFMT_BC5_SNORM
, 4, 4, 16, TRUE
},
368 {WINED3DFMT_BC6H_UF16
, 4, 4, 16, TRUE
},
369 {WINED3DFMT_BC6H_SF16
, 4, 4, 16, TRUE
},
370 {WINED3DFMT_BC7_UNORM
, 4, 4, 16, TRUE
},
371 {WINED3DFMT_ATI1N
, 4, 4, 8, FALSE
},
372 {WINED3DFMT_ATI2N
, 4, 4, 16, FALSE
},
373 {WINED3DFMT_YUY2
, 2, 1, 4, FALSE
},
374 {WINED3DFMT_UYVY
, 2, 1, 4, FALSE
},
377 struct wined3d_format_vertex_info
379 enum wined3d_format_id id
;
380 enum wined3d_ffp_emit_idx emit_idx
;
381 unsigned int component_count
;
383 GLboolean gl_normalized
;
384 enum wined3d_gl_extension extension
;
387 static const struct wined3d_format_vertex_info format_vertex_info
[] =
389 {WINED3DFMT_R32_FLOAT
, WINED3D_FFP_EMIT_FLOAT1
, 1, GL_FLOAT
, GL_FALSE
},
390 {WINED3DFMT_R32G32_FLOAT
, WINED3D_FFP_EMIT_FLOAT2
, 2, GL_FLOAT
, GL_FALSE
},
391 {WINED3DFMT_R32G32B32_FLOAT
, WINED3D_FFP_EMIT_FLOAT3
, 3, GL_FLOAT
, GL_FALSE
},
392 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3D_FFP_EMIT_FLOAT4
, 4, GL_FLOAT
, GL_FALSE
},
393 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3D_FFP_EMIT_D3DCOLOR
, 4, GL_UNSIGNED_BYTE
, GL_TRUE
},
394 {WINED3DFMT_R8G8B8A8_UINT
, WINED3D_FFP_EMIT_UBYTE4
, 4, GL_UNSIGNED_BYTE
, GL_FALSE
},
395 {WINED3DFMT_R16G16_UINT
, WINED3D_FFP_EMIT_INVALID
, 2, GL_UNSIGNED_SHORT
, GL_FALSE
},
396 {WINED3DFMT_R16G16_SINT
, WINED3D_FFP_EMIT_SHORT2
, 2, GL_SHORT
, GL_FALSE
},
397 {WINED3DFMT_R16G16B16A16_SINT
, WINED3D_FFP_EMIT_SHORT4
, 4, GL_SHORT
, GL_FALSE
},
398 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3D_FFP_EMIT_UBYTE4N
, 4, GL_UNSIGNED_BYTE
, GL_TRUE
},
399 {WINED3DFMT_R16G16_SNORM
, WINED3D_FFP_EMIT_SHORT2N
, 2, GL_SHORT
, GL_TRUE
},
400 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3D_FFP_EMIT_SHORT4N
, 4, GL_SHORT
, GL_TRUE
},
401 {WINED3DFMT_R16G16_UNORM
, WINED3D_FFP_EMIT_USHORT2N
, 2, GL_UNSIGNED_SHORT
, GL_TRUE
},
402 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3D_FFP_EMIT_USHORT4N
, 4, GL_UNSIGNED_SHORT
, GL_TRUE
},
403 {WINED3DFMT_R10G10B10X2_UINT
, WINED3D_FFP_EMIT_UDEC3
, 3, GL_UNSIGNED_SHORT
, GL_FALSE
},
404 {WINED3DFMT_R10G10B10X2_SNORM
, WINED3D_FFP_EMIT_DEC3N
, 3, GL_SHORT
, GL_TRUE
},
405 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3D_FFP_EMIT_INVALID
, 4, GL_UNSIGNED_INT_2_10_10_10_REV
, GL_TRUE
,
406 ARB_VERTEX_TYPE_2_10_10_10_REV
},
407 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, 2, GL_HALF_FLOAT
, GL_FALSE
},
408 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, 4, GL_HALF_FLOAT
, GL_FALSE
},
409 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3D_FFP_EMIT_INVALID
, 4, GL_BYTE
, GL_TRUE
},
410 {WINED3DFMT_R8G8B8A8_SINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_BYTE
, GL_FALSE
},
411 {WINED3DFMT_R16G16B16A16_UINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_UNSIGNED_SHORT
, GL_FALSE
},
412 {WINED3DFMT_R8_UNORM
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_BYTE
, GL_TRUE
},
413 {WINED3DFMT_R8_UINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_BYTE
, GL_FALSE
},
414 {WINED3DFMT_R8_SINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_BYTE
, GL_FALSE
},
415 {WINED3DFMT_R16_UINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_SHORT
, GL_FALSE
},
416 {WINED3DFMT_R16_SINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_SHORT
, GL_FALSE
},
417 {WINED3DFMT_R32_UINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_INT
, GL_FALSE
},
418 {WINED3DFMT_R32_SINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_INT
, GL_FALSE
},
419 {WINED3DFMT_R32G32_UINT
, WINED3D_FFP_EMIT_INVALID
, 2, GL_UNSIGNED_INT
, GL_FALSE
},
420 {WINED3DFMT_R32G32_SINT
, WINED3D_FFP_EMIT_INVALID
, 2, GL_INT
, GL_FALSE
},
421 {WINED3DFMT_R32G32B32_UINT
, WINED3D_FFP_EMIT_INVALID
, 3, GL_UNSIGNED_INT
, GL_FALSE
},
422 {WINED3DFMT_R32G32B32A32_UINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_UNSIGNED_INT
, GL_FALSE
},
423 {WINED3DFMT_R32G32B32A32_SINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_INT
, GL_FALSE
},
426 struct wined3d_format_texture_info
428 enum wined3d_format_id id
;
430 GLint gl_srgb_internal
;
431 GLint gl_rt_internal
;
434 unsigned int conv_byte_count
;
436 enum wined3d_gl_extension extension
;
437 void (*upload
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
438 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
439 unsigned int width
, unsigned int height
, unsigned int depth
);
440 void (*download
)(const BYTE
*src
, BYTE
*dst
, unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
441 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
442 unsigned int width
, unsigned int height
, unsigned int depth
);
445 static void convert_l4a4_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
446 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
448 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
449 * format+type combination to load it. Thus convert it to A8L8, then load it
450 * with A4L4 internal, but A8L8 format+type
452 unsigned int x
, y
, z
;
453 const unsigned char *Source
;
456 for (z
= 0; z
< depth
; z
++)
458 for (y
= 0; y
< height
; y
++)
460 Source
= src
+ z
* src_slice_pitch
+ y
* src_row_pitch
;
461 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
462 for (x
= 0; x
< width
; x
++ )
464 unsigned char color
= (*Source
++);
465 /* A */ Dest
[1] = (color
& 0xf0u
) << 0;
466 /* L */ Dest
[0] = (color
& 0x0fu
) << 4;
473 static void convert_r5g5_snorm_l6_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
474 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
476 unsigned int x
, y
, z
;
477 unsigned char r_in
, g_in
, l_in
;
478 const unsigned short *texel_in
;
479 unsigned short *texel_out
;
481 /* Emulating signed 5 bit values with unsigned 5 bit values has some precision problems by design:
482 * E.g. the signed input value 0 becomes 16. GL normalizes it to 16 / 31 = 0.516. We convert it
483 * back to a signed value by subtracting 0.5 and multiplying by 2.0. The resulting value is
484 * ((16 / 31) - 0.5) * 2.0 = 0.032, which is quite different from the intended result 0.000. */
485 for (z
= 0; z
< depth
; z
++)
487 for (y
= 0; y
< height
; y
++)
489 texel_out
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
490 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
491 for (x
= 0; x
< width
; x
++ )
493 l_in
= (*texel_in
& 0xfc00u
) >> 10;
494 g_in
= (*texel_in
& 0x03e0u
) >> 5;
495 r_in
= *texel_in
& 0x001fu
;
497 *texel_out
= ((r_in
+ 16) << 11) | (l_in
<< 5) | (g_in
+ 16);
505 static void convert_r5g5_snorm_l6_unorm_ext(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
506 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
508 unsigned int x
, y
, z
;
509 unsigned char *texel_out
, r_out
, g_out
, r_in
, g_in
, l_in
;
510 const unsigned short *texel_in
;
512 for (z
= 0; z
< depth
; z
++)
514 for (y
= 0; y
< height
; y
++)
516 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
517 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
518 for (x
= 0; x
< width
; x
++ )
520 l_in
= (*texel_in
& 0xfc00u
) >> 10;
521 g_in
= (*texel_in
& 0x03e0u
) >> 5;
522 r_in
= *texel_in
& 0x001fu
;
525 if (!(r_in
& 0x10)) /* r > 0 */
529 if (!(g_in
& 0x10)) /* g > 0 */
532 texel_out
[0] = r_out
;
533 texel_out
[1] = g_out
;
534 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
544 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
545 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
547 unsigned int x
, y
, z
;
548 unsigned char *texel_out
, ds_out
, dt_out
, r_in
, g_in
, l_in
;
549 const unsigned short *texel_in
;
551 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
552 * fixed function and shaders without further conversion once the surface is
555 * The difference between this function and convert_r5g5_snorm_l6_unorm_ext
556 * is that convert_r5g5_snorm_l6_unorm_ext creates a 32 bit XRGB texture and
557 * this function creates a 24 bit DSDT_MAG texture. Trying to load a DSDT_MAG
558 * internal with a 32 bit DSDT_MAG_INTENSITY or DSDT_MAG_VIB format fails. */
559 for (z
= 0; z
< depth
; z
++)
561 for (y
= 0; y
< height
; y
++)
563 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
564 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
565 for (x
= 0; x
< width
; x
++ )
567 l_in
= (*texel_in
& 0xfc00u
) >> 10;
568 g_in
= (*texel_in
& 0x03e0u
) >> 5;
569 r_in
= *texel_in
& 0x001fu
;
572 if (!(r_in
& 0x10)) /* r > 0 */
576 if (!(g_in
& 0x10)) /* g > 0 */
579 texel_out
[0] = ds_out
;
580 texel_out
[1] = dt_out
;
581 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
590 static void convert_r8g8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
591 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
593 unsigned int x
, y
, z
;
597 for (z
= 0; z
< depth
; z
++)
599 for (y
= 0; y
< height
; y
++)
601 Source
= (const short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
602 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
603 for (x
= 0; x
< width
; x
++ )
605 const short color
= (*Source
++);
606 /* B */ Dest
[0] = 0xff;
607 /* G */ Dest
[1] = (color
>> 8) + 128; /* V */
608 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
615 static void convert_r8g8_snorm_l8x8_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
616 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
618 unsigned int x
, y
, z
;
622 /* Doesn't work correctly with the fixed function pipeline, but can work in
623 * shaders if the shader is adjusted. (There's no use for this format in gl's
624 * standard fixed function pipeline anyway).
626 for (z
= 0; z
< depth
; z
++)
628 for (y
= 0; y
< height
; y
++)
630 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
631 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
632 for (x
= 0; x
< width
; x
++ )
634 LONG color
= (*Source
++);
635 /* B */ Dest
[0] = ((color
>> 16) & 0xff); /* L */
636 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
637 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
644 static void convert_r8g8_snorm_l8x8_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
645 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
647 unsigned int x
, y
, z
;
651 /* This implementation works with the fixed function pipeline and shaders
652 * without further modification after converting the surface.
654 for (z
= 0; z
< depth
; z
++)
656 for (y
= 0; y
< height
; y
++)
658 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
659 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
660 for (x
= 0; x
< width
; x
++ )
662 LONG color
= (*Source
++);
663 /* L */ Dest
[2] = ((color
>> 16) & 0xff); /* L */
664 /* V */ Dest
[1] = ((color
>> 8 ) & 0xff); /* V */
665 /* U */ Dest
[0] = (color
& 0xff); /* U */
666 /* I */ Dest
[3] = 255; /* X */
673 static void convert_r8g8b8a8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
674 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
676 unsigned int x
, y
, z
;
680 for (z
= 0; z
< depth
; z
++)
682 for (y
= 0; y
< height
; y
++)
684 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
685 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
686 for (x
= 0; x
< width
; x
++ )
688 LONG color
= (*Source
++);
689 /* B */ Dest
[0] = ((color
>> 16) & 0xff) + 128; /* W */
690 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
691 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
692 /* A */ Dest
[3] = ((color
>> 24) & 0xff) + 128; /* Q */
699 static void convert_r16g16_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
700 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
702 unsigned int x
, y
, z
;
704 unsigned short *Dest
;
706 for (z
= 0; z
< depth
; z
++)
708 for (y
= 0; y
< height
; y
++)
710 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
711 Dest
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
712 for (x
= 0; x
< width
; x
++ )
714 const DWORD color
= (*Source
++);
715 /* B */ Dest
[0] = 0xffff;
716 /* G */ Dest
[1] = (color
>> 16) + 32768; /* V */
717 /* R */ Dest
[2] = (color
& 0xffff) + 32768; /* U */
724 static void convert_r16g16(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
725 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
727 unsigned int x
, y
, z
;
731 for (z
= 0; z
< depth
; z
++)
733 for (y
= 0; y
< height
; y
++)
735 Source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
736 Dest
= (WORD
*) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
737 for (x
= 0; x
< width
; x
++ )
739 WORD green
= (*Source
++);
740 WORD red
= (*Source
++);
743 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
744 * shader overwrites it anyway */
752 static void convert_r32g32_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
753 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
755 unsigned int x
, y
, z
;
759 for (z
= 0; z
< depth
; z
++)
761 for (y
= 0; y
< height
; y
++)
763 Source
= (const float *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
764 Dest
= (float *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
765 for (x
= 0; x
< width
; x
++ )
767 float green
= (*Source
++);
768 float red
= (*Source
++);
778 static void convert_s1_uint_d15_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
779 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
781 unsigned int x
, y
, z
;
783 for (z
= 0; z
< depth
; z
++)
785 for (y
= 0; y
< height
; ++y
)
787 const WORD
*source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
788 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
790 for (x
= 0; x
< width
; ++x
)
792 /* The depth data is normalized, so needs to be scaled,
793 * the stencil data isn't. Scale depth data by
794 * (2^24-1)/(2^15-1) ~~ (2^9 + 2^-6). */
795 WORD d15
= source
[x
] >> 1;
796 DWORD d24
= (d15
<< 9) + (d15
>> 6);
797 dest
[x
] = (d24
<< 8) | (source
[x
] & 0x1);
803 static void convert_s4x4_uint_d24_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
804 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
806 unsigned int x
, y
, z
;
808 for (z
= 0; z
< depth
; z
++)
810 for (y
= 0; y
< height
; ++y
)
812 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
813 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
815 for (x
= 0; x
< width
; ++x
)
817 /* Just need to clear out the X4 part. */
818 dest
[x
] = source
[x
] & ~0xf0;
824 static void convert_s8_uint_d24_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
825 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
827 unsigned int x
, y
, z
;
829 for (z
= 0; z
< depth
; z
++)
831 for (y
= 0; y
< height
; ++y
)
833 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
834 float *dest_f
= (float *)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
835 DWORD
*dest_s
= (DWORD
*)dest_f
;
837 for (x
= 0; x
< width
; ++x
)
839 dest_f
[x
* 2] = float_24_to_32((source
[x
] & 0xffffff00u
) >> 8);
840 dest_s
[x
* 2 + 1] = source
[x
] & 0xff;
846 static void x8_d24_unorm_upload(const BYTE
*src
, BYTE
*dst
,
847 unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
848 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
849 unsigned int width
, unsigned int height
, unsigned int depth
)
851 unsigned int x
, y
, z
;
853 for (z
= 0; z
< depth
; ++z
)
855 for (y
= 0; y
< height
; ++y
)
857 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
858 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
860 for (x
= 0; x
< width
; ++x
)
862 dest
[x
] = source
[x
] << 8 | ((source
[x
] >> 16) & 0xff);
868 static void x8_d24_unorm_download(const BYTE
*src
, BYTE
*dst
,
869 unsigned int src_row_pitch
, unsigned int src_slice_pitch
,
870 unsigned int dst_row_pitch
, unsigned int dst_slice_pitch
,
871 unsigned int width
, unsigned int height
, unsigned int depth
)
873 unsigned int x
, y
, z
;
875 for (z
= 0; z
< depth
; ++z
)
877 for (y
= 0; y
< height
; ++y
)
879 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
880 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
882 for (x
= 0; x
< width
; ++x
)
884 dest
[x
] = source
[x
] >> 8;
890 static BOOL
color_in_range(const struct wined3d_color_key
*color_key
, DWORD color
)
892 /* FIXME: Is this really how color keys are supposed to work? I think it
893 * makes more sense to compare the individual channels. */
894 return color
>= color_key
->color_space_low_value
895 && color
<= color_key
->color_space_high_value
;
898 static void convert_p8_uint_b8g8r8a8_unorm(const BYTE
*src
, unsigned int src_pitch
,
899 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
900 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
908 /* FIXME: This should probably use the system palette. */
909 FIXME("P8 surface loaded without a palette.\n");
911 for (y
= 0; y
< height
; ++y
)
913 memset(&dst
[dst_pitch
* y
], 0, width
* 4);
919 for (y
= 0; y
< height
; ++y
)
921 src_row
= &src
[src_pitch
* y
];
922 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
923 for (x
= 0; x
< width
; ++x
)
925 BYTE src_color
= src_row
[x
];
926 dst_row
[x
] = 0xff000000
927 | (palette
->colors
[src_color
].rgbRed
<< 16)
928 | (palette
->colors
[src_color
].rgbGreen
<< 8)
929 | palette
->colors
[src_color
].rgbBlue
;
934 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
935 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
936 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
942 for (y
= 0; y
< height
; ++y
)
944 src_row
= (WORD
*)&src
[src_pitch
* y
];
945 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
946 for (x
= 0; x
< width
; ++x
)
948 WORD src_color
= src_row
[x
];
949 if (!color_in_range(color_key
, src_color
))
950 dst_row
[x
] = 0x8000u
| ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
952 dst_row
[x
] = ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
957 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
958 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
959 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
965 for (y
= 0; y
< height
; ++y
)
967 src_row
= (WORD
*)&src
[src_pitch
* y
];
968 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
969 for (x
= 0; x
< width
; ++x
)
971 WORD src_color
= src_row
[x
];
972 if (color_in_range(color_key
, src_color
))
973 dst_row
[x
] = src_color
& ~0x8000;
975 dst_row
[x
] = src_color
| 0x8000;
980 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
981 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
982 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
988 for (y
= 0; y
< height
; ++y
)
990 src_row
= &src
[src_pitch
* y
];
991 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
992 for (x
= 0; x
< width
; ++x
)
994 DWORD src_color
= (src_row
[x
* 3 + 2] << 16) | (src_row
[x
* 3 + 1] << 8) | src_row
[x
* 3];
995 if (!color_in_range(color_key
, src_color
))
996 dst_row
[x
] = src_color
| 0xff000000;
1001 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1002 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1003 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
1005 const DWORD
*src_row
;
1009 for (y
= 0; y
< height
; ++y
)
1011 src_row
= (DWORD
*)&src
[src_pitch
* y
];
1012 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1013 for (x
= 0; x
< width
; ++x
)
1015 DWORD src_color
= src_row
[x
];
1016 if (color_in_range(color_key
, src_color
))
1017 dst_row
[x
] = src_color
& ~0xff000000;
1019 dst_row
[x
] = src_color
| 0xff000000;
1024 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
1025 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
1026 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
1028 const DWORD
*src_row
;
1032 for (y
= 0; y
< height
; ++y
)
1034 src_row
= (DWORD
*)&src
[src_pitch
* y
];
1035 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
1036 for (x
= 0; x
< width
; ++x
)
1038 DWORD src_color
= src_row
[x
];
1039 if (color_in_range(color_key
, src_color
))
1040 src_color
&= ~0xff000000;
1041 dst_row
[x
] = src_color
;
1046 const struct wined3d_color_key_conversion
* wined3d_format_get_color_key_conversion(
1047 const struct wined3d_texture
*texture
, BOOL need_alpha_ck
)
1049 const struct wined3d_format
*format
= texture
->resource
.format
;
1054 enum wined3d_format_id src_format
;
1055 struct wined3d_color_key_conversion conversion
;
1059 {WINED3DFMT_B5G6R5_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key
}},
1060 {WINED3DFMT_B5G5R5X1_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key
}},
1061 {WINED3DFMT_B8G8R8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key
}},
1062 {WINED3DFMT_B8G8R8X8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key
}},
1063 {WINED3DFMT_B8G8R8A8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key
}},
1065 static const struct wined3d_color_key_conversion convert_p8
=
1067 WINED3DFMT_B8G8R8A8_UNORM
, convert_p8_uint_b8g8r8a8_unorm
1070 if (need_alpha_ck
&& (texture
->async
.flags
& WINED3D_TEXTURE_ASYNC_COLOR_KEY
))
1072 for (i
= 0; i
< ARRAY_SIZE(color_key_info
); ++i
)
1074 if (color_key_info
[i
].src_format
== format
->id
)
1075 return &color_key_info
[i
].conversion
;
1078 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format
->id
));
1081 /* FIXME: This should check if the blitter backend can do P8 conversion,
1082 * instead of checking for ARB_fragment_program. */
1083 if (format
->id
== WINED3DFMT_P8_UINT
1084 && !(texture
->resource
.device
->adapter
->gl_info
.supported
[ARB_FRAGMENT_PROGRAM
]
1085 && texture
->swapchain
&& texture
== texture
->swapchain
->front_buffer
))
1091 /* The following formats explicitly don't have WINED3DFMT_FLAG_TEXTURE set:
1093 * These are never supported on native.
1094 * WINED3DFMT_B8G8R8_UNORM
1095 * WINED3DFMT_B2G3R3_UNORM
1096 * WINED3DFMT_L4A4_UNORM
1097 * WINED3DFMT_S1_UINT_D15_UNORM
1098 * WINED3DFMT_S4X4_UINT_D24_UNORM
1100 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
1101 * Since it is not widely available, don't offer it. Further no Windows driver
1102 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
1103 * WINED3DFMT_P8_UINT
1104 * WINED3DFMT_P8_UINT_A8_UNORM
1106 * These formats seem to be similar to the HILO formats in
1107 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
1108 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
1109 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
1110 * refused to support formats which can easily be emulated with pixel shaders,
1111 * so applications have to deal with not having NVHS and NVHU.
1113 * WINED3DFMT_NVHS */
1114 static const struct wined3d_format_texture_info format_texture_info
[] =
1116 /* format id gl_internal gl_srgb_internal gl_rt_internal
1117 gl_format gl_type conv_byte_count
1119 extension upload download */
1120 /* FourCC formats */
1121 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
1122 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
1123 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
1124 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
1127 {WINED3DFMT_UYVY
, GL_RG8
, GL_RG8
, 0,
1128 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1129 WINED3DFMT_FLAG_FILTERING
,
1130 ARB_TEXTURE_RG
, NULL
},
1131 {WINED3DFMT_UYVY
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1132 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1133 WINED3DFMT_FLAG_FILTERING
,
1134 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1135 {WINED3DFMT_UYVY
, GL_RGB
, GL_RGB
, 0,
1136 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
1137 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
1138 APPLE_YCBCR_422
, NULL
},
1139 {WINED3DFMT_YUY2
, GL_RG8
, GL_RG8
, 0,
1140 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1141 WINED3DFMT_FLAG_FILTERING
,
1142 ARB_TEXTURE_RG
, NULL
},
1143 {WINED3DFMT_YUY2
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1144 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1145 WINED3DFMT_FLAG_FILTERING
,
1146 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1147 {WINED3DFMT_YUY2
, GL_RGB
, GL_RGB
, 0,
1148 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
1149 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
1150 APPLE_YCBCR_422
, NULL
},
1151 {WINED3DFMT_YV12
, GL_R8
, GL_R8
, 0,
1152 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1153 WINED3DFMT_FLAG_FILTERING
,
1154 ARB_TEXTURE_RG
, NULL
},
1155 {WINED3DFMT_YV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1156 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1157 WINED3DFMT_FLAG_FILTERING
,
1158 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1159 {WINED3DFMT_NV12
, GL_R8
, GL_R8
, 0,
1160 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1161 WINED3DFMT_FLAG_FILTERING
,
1162 ARB_TEXTURE_RG
, NULL
},
1163 {WINED3DFMT_NV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1164 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1165 WINED3DFMT_FLAG_FILTERING
,
1166 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1167 {WINED3DFMT_DXT1
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1168 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1169 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1170 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1171 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1172 {WINED3DFMT_DXT2
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1173 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1174 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1175 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1176 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1177 {WINED3DFMT_DXT3
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1178 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1179 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1180 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1181 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1182 {WINED3DFMT_DXT4
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1183 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1184 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1185 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1186 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1187 {WINED3DFMT_DXT5
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1188 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1189 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1190 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1191 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1192 {WINED3DFMT_BC1_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1193 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1194 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1195 | WINED3DFMT_FLAG_COMPRESSED
,
1196 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1197 {WINED3DFMT_BC2_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1198 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1199 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1200 | WINED3DFMT_FLAG_COMPRESSED
,
1201 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1202 {WINED3DFMT_BC3_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1203 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1204 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1205 | WINED3DFMT_FLAG_COMPRESSED
,
1206 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1207 {WINED3DFMT_BC4_UNORM
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1208 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1209 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1210 | WINED3DFMT_FLAG_COMPRESSED
,
1211 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1212 {WINED3DFMT_BC4_SNORM
, GL_COMPRESSED_SIGNED_RED_RGTC1
, GL_COMPRESSED_SIGNED_RED_RGTC1
, 0,
1213 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1214 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1215 | WINED3DFMT_FLAG_COMPRESSED
,
1216 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1217 {WINED3DFMT_BC5_UNORM
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1218 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1219 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1220 | WINED3DFMT_FLAG_COMPRESSED
,
1221 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1222 {WINED3DFMT_BC5_SNORM
, GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_COMPRESSED_SIGNED_RG_RGTC2
, 0,
1223 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1224 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1225 | WINED3DFMT_FLAG_COMPRESSED
,
1226 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1227 {WINED3DFMT_BC6H_UF16
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, 0,
1228 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1229 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1230 | WINED3DFMT_FLAG_COMPRESSED
,
1231 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1232 {WINED3DFMT_BC6H_SF16
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, 0,
1233 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1234 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1235 | WINED3DFMT_FLAG_COMPRESSED
,
1236 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1237 {WINED3DFMT_BC7_UNORM
, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
, 0,
1238 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1239 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1240 | WINED3DFMT_FLAG_COMPRESSED
,
1241 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1243 {WINED3DFMT_R32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1244 GL_RED
, GL_FLOAT
, 0,
1245 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1246 ARB_TEXTURE_FLOAT
, NULL
},
1247 {WINED3DFMT_R32_FLOAT
, GL_R32F
, GL_R32F
, 0,
1248 GL_RED
, GL_FLOAT
, 0,
1249 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1250 ARB_TEXTURE_RG
, NULL
},
1251 {WINED3DFMT_R32G32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1252 GL_RGB
, GL_FLOAT
, 12,
1253 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1254 ARB_TEXTURE_FLOAT
, convert_r32g32_float
},
1255 {WINED3DFMT_R32G32_FLOAT
, GL_RG32F
, GL_RG32F
, 0,
1257 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1258 ARB_TEXTURE_RG
, NULL
},
1259 {WINED3DFMT_R32G32B32_FLOAT
, GL_RGB32F
, GL_RGB32F
, 0,
1260 GL_RGB
, GL_FLOAT
, 0,
1261 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1262 ARB_TEXTURE_FLOAT
, NULL
},
1263 {WINED3DFMT_R32G32B32A32_FLOAT
, GL_RGBA32F_ARB
, GL_RGBA32F_ARB
, 0,
1264 GL_RGBA
, GL_FLOAT
, 0,
1265 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1266 ARB_TEXTURE_FLOAT
, NULL
},
1268 {WINED3DFMT_R16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1269 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1270 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1271 ARB_TEXTURE_FLOAT
, NULL
},
1272 {WINED3DFMT_R16_FLOAT
, GL_R16F
, GL_R16F
, 0,
1273 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1274 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1275 ARB_TEXTURE_RG
, NULL
},
1276 {WINED3DFMT_R16G16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1277 GL_RGB
, GL_HALF_FLOAT_ARB
, 6,
1278 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1279 ARB_TEXTURE_FLOAT
, convert_r16g16
},
1280 {WINED3DFMT_R16G16_FLOAT
, GL_RG16F
, GL_RG16F
, 0,
1281 GL_RG
, GL_HALF_FLOAT_ARB
, 0,
1282 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1283 ARB_TEXTURE_RG
, NULL
},
1284 {WINED3DFMT_R16G16B16A16_FLOAT
, GL_RGBA16F_ARB
, GL_RGBA16F_ARB
, 0,
1285 GL_RGBA
, GL_HALF_FLOAT_ARB
, 0,
1286 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
1287 | WINED3DFMT_FLAG_VTF
,
1288 ARB_TEXTURE_FLOAT
, NULL
},
1289 {WINED3DFMT_R11G11B10_FLOAT
, GL_R11F_G11F_B10F
, GL_R11F_G11F_B10F
, 0,
1290 GL_RGB
, GL_UNSIGNED_INT_10F_11F_11F_REV
, 0,
1291 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
,
1293 /* Palettized formats */
1294 {WINED3DFMT_P8_UINT
, GL_R8
, GL_R8
, 0,
1295 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1297 ARB_TEXTURE_RG
, NULL
},
1298 {WINED3DFMT_P8_UINT
, GL_ALPHA8
, GL_ALPHA8
, 0,
1299 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1301 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1302 /* Standard ARGB formats */
1303 {WINED3DFMT_B8G8R8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1304 GL_BGR
, GL_UNSIGNED_BYTE
, 0,
1305 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
| WINED3DFMT_FLAG_RENDERTARGET
,
1306 WINED3D_GL_EXT_NONE
, NULL
},
1307 {WINED3DFMT_B8G8R8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1308 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1309 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1310 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1311 | WINED3DFMT_FLAG_VTF
,
1312 WINED3D_GL_EXT_NONE
, NULL
},
1313 {WINED3DFMT_B8G8R8X8_UNORM
, GL_RGB8
, GL_SRGB8_EXT
, 0,
1314 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1315 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1316 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
,
1317 WINED3D_GL_EXT_NONE
, NULL
},
1318 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB5
, GL_RGB5
, GL_RGB8
,
1319 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1320 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1321 | WINED3DFMT_FLAG_RENDERTARGET
,
1322 WINED3D_GL_EXT_NONE
, NULL
},
1323 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB565
, GL_RGB565
, GL_RGB8
,
1324 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1325 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1326 | WINED3DFMT_FLAG_RENDERTARGET
,
1327 ARB_ES2_COMPATIBILITY
, NULL
},
1328 {WINED3DFMT_B5G5R5X1_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1329 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1330 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1331 | WINED3DFMT_FLAG_RENDERTARGET
,
1332 WINED3D_GL_EXT_NONE
, NULL
},
1333 {WINED3DFMT_B5G5R5A1_UNORM
, GL_RGB5_A1
, GL_RGB5_A1
, 0,
1334 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1335 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1336 WINED3D_GL_EXT_NONE
, NULL
},
1337 {WINED3DFMT_B4G4R4A4_UNORM
, GL_RGBA4
, GL_SRGB8_ALPHA8_EXT
, 0,
1338 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1339 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1340 | WINED3DFMT_FLAG_SRGB_READ
,
1341 WINED3D_GL_EXT_NONE
, NULL
},
1342 {WINED3DFMT_B2G3R3_UNORM
, GL_R3_G3_B2
, GL_R3_G3_B2
, 0,
1343 GL_RGB
, GL_UNSIGNED_BYTE_3_3_2
, 0,
1344 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1345 WINED3D_GL_EXT_NONE
, NULL
},
1346 {WINED3DFMT_R8_UNORM
, GL_R8
, GL_R8
, 0,
1347 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1348 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1349 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1350 ARB_TEXTURE_RG
, NULL
},
1351 {WINED3DFMT_A8_UNORM
, GL_R8
, GL_R8
, 0,
1352 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1353 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1354 ARB_TEXTURE_RG
, NULL
},
1355 {WINED3DFMT_A8_UNORM
, GL_ALPHA8
, GL_ALPHA8
, 0,
1356 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1357 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1358 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1359 {WINED3DFMT_B4G4R4X4_UNORM
, GL_RGB4
, GL_RGB4
, 0,
1360 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1361 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1362 WINED3D_GL_EXT_NONE
, NULL
},
1363 {WINED3DFMT_R10G10B10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1364 GL_RGBA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1365 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1366 | WINED3DFMT_FLAG_RENDERTARGET
,
1367 WINED3D_GL_EXT_NONE
, NULL
},
1368 {WINED3DFMT_R8G8B8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1369 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1370 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1371 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1372 | WINED3DFMT_FLAG_VTF
,
1373 WINED3D_GL_EXT_NONE
, NULL
},
1374 {WINED3DFMT_R8G8B8A8_UINT
, GL_RGBA8UI
, GL_RGBA8UI
, 0,
1375 GL_RGBA_INTEGER
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1376 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1377 ARB_TEXTURE_RGB10_A2UI
, NULL
},
1378 {WINED3DFMT_R8G8B8A8_SINT
, GL_RGBA8I
, GL_RGBA8I
, 0,
1379 GL_RGBA_INTEGER
, GL_BYTE
, 0,
1380 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1381 EXT_TEXTURE_INTEGER
, NULL
},
1382 {WINED3DFMT_R8G8B8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1383 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1384 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1385 WINED3D_GL_EXT_NONE
, NULL
},
1386 {WINED3DFMT_R16G16_UNORM
, GL_RGB16
, GL_RGB16
, GL_RGBA16
,
1387 GL_RGB
, GL_UNSIGNED_SHORT
, 6,
1388 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1389 WINED3D_GL_EXT_NONE
, convert_r16g16
},
1390 {WINED3DFMT_R16G16_UNORM
, GL_RG16
, GL_RG16
, 0,
1391 GL_RG
, GL_UNSIGNED_SHORT
, 0,
1392 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1393 | WINED3DFMT_FLAG_RENDERTARGET
,
1394 ARB_TEXTURE_RG
, NULL
},
1395 {WINED3DFMT_B10G10R10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1396 GL_BGRA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1397 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1398 | WINED3DFMT_FLAG_RENDERTARGET
,
1399 WINED3D_GL_EXT_NONE
, NULL
},
1400 {WINED3DFMT_R16G16B16A16_UNORM
, GL_RGBA16
, GL_RGBA16
, 0,
1401 GL_RGBA
, GL_UNSIGNED_SHORT
, 0,
1402 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1403 | WINED3DFMT_FLAG_RENDERTARGET
,
1404 WINED3D_GL_EXT_NONE
, NULL
},
1405 {WINED3DFMT_R8G8_UNORM
, GL_RG8
, GL_RG8
, 0,
1406 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1407 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1408 | WINED3DFMT_FLAG_RENDERTARGET
,
1409 ARB_TEXTURE_RG
, NULL
},
1410 {WINED3DFMT_R8G8_UINT
, GL_RG8UI
, GL_RG8UI
, 0,
1411 GL_RG_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1412 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1413 ARB_TEXTURE_RG
, NULL
},
1414 {WINED3DFMT_R8G8_SINT
, GL_RG8I
, GL_RG8I
, 0,
1415 GL_RG_INTEGER
, GL_BYTE
, 0,
1416 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1417 ARB_TEXTURE_RG
, NULL
},
1418 {WINED3DFMT_R16G16B16A16_UINT
, GL_RGBA16UI
, GL_RGBA16UI
, 0,
1419 GL_RGBA_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1420 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1421 EXT_TEXTURE_INTEGER
, NULL
},
1422 {WINED3DFMT_R16G16B16A16_SINT
, GL_RGBA16I
, GL_RGBA16I
, 0,
1423 GL_RGBA_INTEGER
, GL_SHORT
, 0,
1424 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1425 EXT_TEXTURE_INTEGER
, NULL
},
1426 {WINED3DFMT_R32G32_UINT
, GL_RG32UI
, GL_RG32UI
, 0,
1427 GL_RG_INTEGER
, GL_UNSIGNED_INT
, 0,
1428 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1429 ARB_TEXTURE_RG
, NULL
},
1430 {WINED3DFMT_R32G32_SINT
, GL_RG32I
, GL_RG32I
, 0,
1431 GL_RG_INTEGER
, GL_INT
, 0,
1432 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1433 ARB_TEXTURE_RG
, NULL
},
1434 {WINED3DFMT_R16G16_UINT
, GL_RG16UI
, GL_RG16UI
, 0,
1435 GL_RG_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1436 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1437 ARB_TEXTURE_RG
, NULL
},
1438 {WINED3DFMT_R16G16_SINT
, GL_RG16I
, GL_RG16I
, 0,
1439 GL_RG_INTEGER
, GL_SHORT
, 0,
1440 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1441 ARB_TEXTURE_RG
, NULL
},
1442 {WINED3DFMT_R32_UINT
, GL_R32UI
, GL_R32UI
, 0,
1443 GL_RED_INTEGER
, GL_UNSIGNED_INT
, 0,
1444 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1445 ARB_TEXTURE_RG
, NULL
},
1446 {WINED3DFMT_R32_SINT
, GL_R32I
, GL_R32I
, 0,
1447 GL_RED_INTEGER
, GL_INT
, 0,
1448 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1449 ARB_TEXTURE_RG
, NULL
},
1450 {WINED3DFMT_R16_UNORM
, GL_R16
, GL_R16
, 0,
1451 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1452 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1453 | WINED3DFMT_FLAG_RENDERTARGET
,
1454 ARB_TEXTURE_RG
, NULL
},
1455 {WINED3DFMT_R16_UINT
, GL_R16UI
, GL_R16UI
, 0,
1456 GL_RED_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1457 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1458 ARB_TEXTURE_RG
, NULL
},
1459 {WINED3DFMT_R16_SINT
, GL_R16I
, GL_R16I
, 0,
1460 GL_RED_INTEGER
, GL_SHORT
, 0,
1461 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1462 ARB_TEXTURE_RG
, NULL
},
1463 {WINED3DFMT_R8_UINT
, GL_R8UI
, GL_R8UI
, 0,
1464 GL_RED_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1465 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1466 ARB_TEXTURE_RG
, NULL
},
1467 {WINED3DFMT_R8_SINT
, GL_R8I
, GL_R8I
, 0,
1468 GL_RED_INTEGER
, GL_BYTE
, 0,
1469 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1470 ARB_TEXTURE_RG
, NULL
},
1472 {WINED3DFMT_L8_UNORM
, GL_LUMINANCE8
, GL_SLUMINANCE8_EXT
, 0,
1473 GL_LUMINANCE
, GL_UNSIGNED_BYTE
, 0,
1474 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1475 | WINED3DFMT_FLAG_SRGB_READ
,
1476 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1477 {WINED3DFMT_L8_UNORM
, GL_R8
, GL_R8
, 0,
1478 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1479 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1480 | WINED3DFMT_FLAG_RENDERTARGET
,
1481 ARB_TEXTURE_RG
, NULL
},
1482 {WINED3DFMT_L8A8_UNORM
, GL_RG8
, GL_RG8
, 0,
1483 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1484 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1485 ARB_TEXTURE_RG
, NULL
},
1486 {WINED3DFMT_L8A8_UNORM
, GL_LUMINANCE8_ALPHA8
, GL_SLUMINANCE8_ALPHA8_EXT
, 0,
1487 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1488 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1489 | WINED3DFMT_FLAG_SRGB_READ
,
1490 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1491 {WINED3DFMT_L4A4_UNORM
, GL_RG8
, GL_RG8
, 0,
1492 GL_RG
, GL_UNSIGNED_BYTE
, 2,
1493 WINED3DFMT_FLAG_FILTERING
,
1494 ARB_TEXTURE_RG
, convert_l4a4_unorm
},
1495 {WINED3DFMT_L4A4_UNORM
, GL_LUMINANCE4_ALPHA4
, GL_LUMINANCE4_ALPHA4
, 0,
1496 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 2,
1497 WINED3DFMT_FLAG_FILTERING
,
1498 WINED3D_GL_LEGACY_CONTEXT
, convert_l4a4_unorm
},
1499 {WINED3DFMT_L16_UNORM
, GL_R16
, GL_R16
, 0,
1500 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1501 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1502 ARB_TEXTURE_RG
, NULL
},
1503 {WINED3DFMT_L16_UNORM
, GL_LUMINANCE16
, GL_LUMINANCE16
, 0,
1504 GL_LUMINANCE
, GL_UNSIGNED_SHORT
, 0,
1505 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1506 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1507 /* Bump mapping stuff */
1508 {WINED3DFMT_R8G8_SNORM
, GL_RGB8
, GL_RGB8
, 0,
1509 GL_BGR
, GL_UNSIGNED_BYTE
, 3,
1510 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1511 | WINED3DFMT_FLAG_BUMPMAP
,
1512 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm
},
1513 {WINED3DFMT_R8G8_SNORM
, GL_DSDT8_NV
, GL_DSDT8_NV
, 0,
1514 GL_DSDT_NV
, GL_BYTE
, 0,
1515 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1516 | WINED3DFMT_FLAG_BUMPMAP
,
1517 NV_TEXTURE_SHADER
, NULL
},
1518 {WINED3DFMT_R8G8_SNORM
, GL_RG8_SNORM
, GL_RG8_SNORM
, 0,
1520 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1521 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1522 EXT_TEXTURE_SNORM
, NULL
},
1523 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1524 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 2,
1525 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1526 | WINED3DFMT_FLAG_BUMPMAP
,
1527 WINED3D_GL_EXT_NONE
, convert_r5g5_snorm_l6_unorm
},
1528 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_DSDT8_MAG8_NV
, GL_DSDT8_MAG8_NV
, 0,
1529 GL_DSDT_MAG_NV
, GL_BYTE
, 3,
1530 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1531 | WINED3DFMT_FLAG_BUMPMAP
,
1532 NV_TEXTURE_SHADER
, convert_r5g5_snorm_l6_unorm_nv
},
1533 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB8_SNORM
, GL_RGB8_SNORM
, 0,
1534 GL_RGBA
, GL_BYTE
, 4,
1535 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1536 | WINED3DFMT_FLAG_BUMPMAP
,
1537 EXT_TEXTURE_SNORM
, convert_r5g5_snorm_l6_unorm_ext
},
1538 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1539 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4,
1540 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1541 | WINED3DFMT_FLAG_BUMPMAP
,
1542 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm_l8x8_unorm
},
1543 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_DSDT8_MAG8_INTENSITY8_NV
, GL_DSDT8_MAG8_INTENSITY8_NV
, 0,
1544 GL_DSDT_MAG_VIB_NV
, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV
, 4,
1545 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1546 | WINED3DFMT_FLAG_BUMPMAP
,
1547 NV_TEXTURE_SHADER
, convert_r8g8_snorm_l8x8_unorm_nv
},
1548 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8
, GL_RGBA8
, 0,
1549 GL_BGRA
, GL_UNSIGNED_BYTE
, 4,
1550 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1551 | WINED3DFMT_FLAG_BUMPMAP
,
1552 WINED3D_GL_EXT_NONE
, convert_r8g8b8a8_snorm
},
1553 {WINED3DFMT_R8G8B8A8_SNORM
, GL_SIGNED_RGBA8_NV
, GL_SIGNED_RGBA8_NV
, 0,
1554 GL_RGBA
, GL_BYTE
, 0,
1555 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1556 | WINED3DFMT_FLAG_BUMPMAP
,
1557 NV_TEXTURE_SHADER
, NULL
},
1558 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8_SNORM
, GL_RGBA8_SNORM
, 0,
1559 GL_RGBA
, GL_BYTE
, 0,
1560 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1561 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1562 EXT_TEXTURE_SNORM
, NULL
},
1563 {WINED3DFMT_R16G16_SNORM
, GL_RGB16
, GL_RGB16
, 0,
1564 GL_BGR
, GL_UNSIGNED_SHORT
, 6,
1565 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1566 | WINED3DFMT_FLAG_BUMPMAP
,
1567 WINED3D_GL_EXT_NONE
, convert_r16g16_snorm
},
1568 {WINED3DFMT_R16G16_SNORM
, GL_SIGNED_HILO16_NV
, GL_SIGNED_HILO16_NV
, 0,
1569 GL_HILO_NV
, GL_SHORT
, 0,
1570 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1571 | WINED3DFMT_FLAG_BUMPMAP
,
1572 NV_TEXTURE_SHADER
, NULL
},
1573 {WINED3DFMT_R16G16_SNORM
, GL_RG16_SNORM
, GL_RG16_SNORM
, 0,
1575 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1576 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1577 EXT_TEXTURE_SNORM
, NULL
},
1578 {WINED3DFMT_R16G16B16A16_SNORM
, GL_RGBA16_SNORM
, GL_RGBA16_SNORM
, 0,
1579 GL_RGBA
, GL_SHORT
, 0,
1580 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1581 | WINED3DFMT_FLAG_RENDERTARGET
,
1582 EXT_TEXTURE_SNORM
, NULL
},
1583 {WINED3DFMT_R16_SNORM
, GL_R16_SNORM
, GL_R16_SNORM
, 0,
1584 GL_RED
, GL_SHORT
, 0,
1585 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1586 | WINED3DFMT_FLAG_RENDERTARGET
,
1587 EXT_TEXTURE_SNORM
, NULL
},
1588 {WINED3DFMT_R8_SNORM
, GL_R8_SNORM
, GL_R8_SNORM
, 0,
1590 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1591 | WINED3DFMT_FLAG_RENDERTARGET
,
1592 EXT_TEXTURE_SNORM
, NULL
},
1593 /* Depth stencil formats */
1594 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1595 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1596 WINED3DFMT_FLAG_DEPTH
,
1597 WINED3D_GL_EXT_NONE
, NULL
},
1598 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT16
, GL_DEPTH_COMPONENT16
, 0,
1599 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1600 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1601 ARB_DEPTH_TEXTURE
, NULL
},
1602 {WINED3DFMT_D32_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1603 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1604 WINED3DFMT_FLAG_DEPTH
,
1605 WINED3D_GL_EXT_NONE
, NULL
},
1606 {WINED3DFMT_D32_UNORM
, GL_DEPTH_COMPONENT32_ARB
, GL_DEPTH_COMPONENT32_ARB
, 0,
1607 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1608 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1609 ARB_DEPTH_TEXTURE
, NULL
},
1610 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH_COMPONENT16
, GL_DEPTH_COMPONENT16
, 0,
1611 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1612 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1613 ARB_DEPTH_TEXTURE
, NULL
},
1614 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1615 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 4,
1616 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1617 EXT_PACKED_DEPTH_STENCIL
, convert_s1_uint_d15_unorm
},
1618 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1619 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 4,
1620 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1621 ARB_FRAMEBUFFER_OBJECT
, convert_s1_uint_d15_unorm
},
1622 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1623 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1624 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1625 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1626 ARB_DEPTH_TEXTURE
, NULL
},
1627 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1628 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 0,
1629 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1630 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1631 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1632 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1633 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1634 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1635 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1636 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1637 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1638 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 4,
1639 WINED3DFMT_FLAG_DEPTH
,
1640 WINED3D_GL_EXT_NONE
, x8_d24_unorm_upload
, x8_d24_unorm_download
},
1641 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1642 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 4,
1643 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1644 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1645 ARB_DEPTH_TEXTURE
, x8_d24_unorm_upload
, x8_d24_unorm_download
},
1646 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1647 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1648 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1649 ARB_DEPTH_TEXTURE
, NULL
},
1650 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1651 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 4,
1652 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1653 EXT_PACKED_DEPTH_STENCIL
, convert_s4x4_uint_d24_unorm
},
1654 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1655 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 4,
1656 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1657 ARB_FRAMEBUFFER_OBJECT
, convert_s4x4_uint_d24_unorm
},
1658 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1659 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1660 WINED3DFMT_FLAG_DEPTH
,
1661 WINED3D_GL_EXT_NONE
, NULL
},
1662 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT16
, GL_DEPTH_COMPONENT16
, 0,
1663 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1664 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1665 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1666 ARB_DEPTH_TEXTURE
, NULL
},
1667 {WINED3DFMT_D32_FLOAT
, GL_DEPTH_COMPONENT32F
, GL_DEPTH_COMPONENT32F
, 0,
1668 GL_DEPTH_COMPONENT
, GL_FLOAT
, 0,
1669 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1670 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1671 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1672 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 0,
1673 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1674 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1675 {WINED3DFMT_S8_UINT_D24_FLOAT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1676 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 8,
1677 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1678 ARB_DEPTH_BUFFER_FLOAT
, convert_s8_uint_d24_float
},
1679 {WINED3DFMT_R32G32B32A32_UINT
, GL_RGBA32UI
, GL_RGBA32UI
, 0,
1680 GL_RGBA_INTEGER
, GL_UNSIGNED_INT
, 0,
1681 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1682 EXT_TEXTURE_INTEGER
, NULL
},
1683 {WINED3DFMT_R32G32B32A32_SINT
, GL_RGBA32I
, GL_RGBA32I
, 0,
1684 GL_RGBA_INTEGER
, GL_INT
, 0,
1685 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1686 EXT_TEXTURE_INTEGER
, NULL
},
1687 /* Vendor-specific formats */
1688 {WINED3DFMT_ATI1N
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1689 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1690 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1691 | WINED3DFMT_FLAG_COMPRESSED
,
1692 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1693 {WINED3DFMT_ATI2N
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, 0,
1694 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1695 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1696 | WINED3DFMT_FLAG_COMPRESSED
,
1697 ATI_TEXTURE_COMPRESSION_3DC
, NULL
},
1698 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1699 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1700 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1701 | WINED3DFMT_FLAG_COMPRESSED
,
1702 EXT_TEXTURE_COMPRESSION_RGTC
, NULL
},
1703 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1704 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1705 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1706 | WINED3DFMT_FLAG_COMPRESSED
,
1707 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1708 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1709 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 0,
1710 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1711 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
,
1712 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1713 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1714 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1715 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1716 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
,
1717 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1718 {WINED3DFMT_NULL
, 0, 0, 0,
1719 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1720 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
,
1721 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1722 /* DirectX 10 HDR formats */
1723 {WINED3DFMT_R9G9B9E5_SHAREDEXP
, GL_RGB9_E5_EXT
, GL_RGB9_E5_EXT
, 0,
1724 GL_RGB
, GL_UNSIGNED_INT_5_9_9_9_REV_EXT
, 0,
1725 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1726 EXT_TEXTURE_SHARED_EXPONENT
, NULL
},
1729 struct wined3d_format_srgb_info
1731 enum wined3d_format_id srgb_format_id
;
1732 enum wined3d_format_id base_format_id
;
1735 static const struct wined3d_format_srgb_info format_srgb_info
[] =
1737 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_UNORM
},
1738 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_UNORM
},
1739 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_UNORM
},
1740 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_UNORM
},
1741 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_UNORM
},
1742 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_UNORM
},
1743 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_UNORM
},
1746 static inline int get_format_idx(enum wined3d_format_id format_id
)
1750 if (format_id
< WINED3D_FORMAT_FOURCC_BASE
)
1753 for (i
= 0; i
< ARRAY_SIZE(format_index_remap
); ++i
)
1755 if (format_index_remap
[i
].id
== format_id
)
1756 return format_index_remap
[i
].idx
;
1762 static struct wined3d_format
*get_format_internal(struct wined3d_gl_info
*gl_info
,
1763 enum wined3d_format_id format_id
)
1767 if ((fmt_idx
= get_format_idx(format_id
)) == -1)
1769 ERR("Format %s (%#x) not found.\n", debug_d3dformat(format_id
), format_id
);
1773 return &gl_info
->formats
[fmt_idx
];
1776 static void copy_format(struct wined3d_format
*dst_format
, const struct wined3d_format
*src_format
)
1778 enum wined3d_format_id id
= dst_format
->id
;
1779 *dst_format
= *src_format
;
1780 dst_format
->id
= id
;
1783 static void format_set_flag(struct wined3d_format
*format
, unsigned int flag
)
1787 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1788 format
->flags
[i
] |= flag
;
1791 static void format_clear_flag(struct wined3d_format
*format
, unsigned int flag
)
1795 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1796 format
->flags
[i
] &= ~flag
;
1799 static enum wined3d_channel_type
map_channel_type(char t
)
1804 return WINED3D_CHANNEL_TYPE_UNORM
;
1806 return WINED3D_CHANNEL_TYPE_SNORM
;
1808 return WINED3D_CHANNEL_TYPE_UINT
;
1810 return WINED3D_CHANNEL_TYPE_SINT
;
1812 return WINED3D_CHANNEL_TYPE_FLOAT
;
1814 return WINED3D_CHANNEL_TYPE_DEPTH
;
1816 return WINED3D_CHANNEL_TYPE_STENCIL
;
1818 return WINED3D_CHANNEL_TYPE_UNUSED
;
1820 ERR("Invalid channel type '%c'.\n", t
);
1821 return WINED3D_CHANNEL_TYPE_NONE
;
1825 static BOOL
init_format_base_info(struct wined3d_gl_info
*gl_info
)
1827 struct wined3d_format
*format
;
1830 gl_info
->format_count
= WINED3D_FORMAT_COUNT
;
1831 if (!(gl_info
->formats
= heap_calloc(gl_info
->format_count
1832 + ARRAY_SIZE(typeless_depth_stencil_formats
), sizeof(*gl_info
->formats
))))
1834 ERR("Failed to allocate memory.\n");
1838 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
1840 if (!(format
= get_format_internal(gl_info
, formats
[i
].id
)))
1843 format
->id
= formats
[i
].id
;
1844 format
->red_size
= formats
[i
].red_size
;
1845 format
->green_size
= formats
[i
].green_size
;
1846 format
->blue_size
= formats
[i
].blue_size
;
1847 format
->alpha_size
= formats
[i
].alpha_size
;
1848 format
->red_offset
= formats
[i
].red_offset
;
1849 format
->green_offset
= formats
[i
].green_offset
;
1850 format
->blue_offset
= formats
[i
].blue_offset
;
1851 format
->alpha_offset
= formats
[i
].alpha_offset
;
1852 format
->byte_count
= formats
[i
].bpp
;
1853 format
->depth_size
= formats
[i
].depth_size
;
1854 format
->stencil_size
= formats
[i
].stencil_size
;
1855 format
->block_width
= 1;
1856 format
->block_height
= 1;
1857 format
->block_byte_count
= formats
[i
].bpp
;
1860 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
1862 const struct wined3d_format
*typeless_format
;
1865 if (!(format
= get_format_internal(gl_info
, typed_formats
[i
].id
)))
1868 if (!(typeless_format
= get_format_internal(gl_info
, typed_formats
[i
].typeless_id
)))
1871 format
->id
= typed_formats
[i
].id
;
1872 format
->red_size
= typeless_format
->red_size
;
1873 format
->green_size
= typeless_format
->green_size
;
1874 format
->blue_size
= typeless_format
->blue_size
;
1875 format
->alpha_size
= typeless_format
->alpha_size
;
1876 format
->red_offset
= typeless_format
->red_offset
;
1877 format
->green_offset
= typeless_format
->green_offset
;
1878 format
->blue_offset
= typeless_format
->blue_offset
;
1879 format
->alpha_offset
= typeless_format
->alpha_offset
;
1880 format
->byte_count
= typeless_format
->byte_count
;
1881 format
->depth_size
= typeless_format
->depth_size
;
1882 format
->stencil_size
= typeless_format
->stencil_size
;
1883 format
->block_width
= typeless_format
->block_width
;
1884 format
->block_height
= typeless_format
->block_height
;
1885 format
->block_byte_count
= typeless_format
->block_byte_count
;
1886 format
->typeless_id
= typeless_format
->id
;
1888 for (j
= 0; j
< strlen(typed_formats
[i
].channels
); ++j
)
1890 enum wined3d_channel_type channel_type
= map_channel_type(typed_formats
[i
].channels
[j
]);
1891 if (channel_type
== WINED3D_CHANNEL_TYPE_UINT
|| channel_type
== WINED3D_CHANNEL_TYPE_SINT
)
1892 flags
|= WINED3DFMT_FLAG_INTEGER
;
1893 if (channel_type
== WINED3D_CHANNEL_TYPE_FLOAT
)
1894 flags
|= WINED3DFMT_FLAG_FLOAT
;
1896 if (channel_type
== WINED3D_CHANNEL_TYPE_DEPTH
&& !format
->depth_size
)
1898 format
->depth_size
= format
->red_size
;
1899 format
->red_size
= format
->red_offset
= 0;
1903 format_set_flag(format
, flags
);
1906 for (i
= 0; i
< ARRAY_SIZE(ddi_formats
); ++i
)
1908 if (!(format
= get_format_internal(gl_info
, ddi_formats
[i
].id
)))
1911 format
->ddi_format
= ddi_formats
[i
].ddi_format
;
1914 for (i
= 0; i
< ARRAY_SIZE(format_base_flags
); ++i
)
1916 if (!(format
= get_format_internal(gl_info
, format_base_flags
[i
].id
)))
1919 format_set_flag(format
, format_base_flags
[i
].flags
);
1925 heap_free(gl_info
->formats
);
1929 static BOOL
init_format_block_info(struct wined3d_gl_info
*gl_info
)
1931 struct wined3d_format
*format
;
1934 for (i
= 0; i
< ARRAY_SIZE(format_block_info
); ++i
)
1936 if (!(format
= get_format_internal(gl_info
, format_block_info
[i
].id
)))
1939 format
->block_width
= format_block_info
[i
].block_width
;
1940 format
->block_height
= format_block_info
[i
].block_height
;
1941 format
->block_byte_count
= format_block_info
[i
].block_byte_count
;
1942 format_set_flag(format
, WINED3DFMT_FLAG_BLOCKS
);
1943 if (!format_block_info
[i
].verify
)
1944 format_set_flag(format
, WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
);
1950 static GLenum
wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type
)
1954 case WINED3D_GL_RES_TYPE_TEX_1D
:
1955 return GL_TEXTURE_1D
;
1956 case WINED3D_GL_RES_TYPE_TEX_2D
:
1957 return GL_TEXTURE_2D
;
1958 case WINED3D_GL_RES_TYPE_TEX_3D
:
1959 return GL_TEXTURE_3D
;
1960 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1961 return GL_TEXTURE_CUBE_MAP_ARB
;
1962 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1963 return GL_TEXTURE_RECTANGLE_ARB
;
1964 case WINED3D_GL_RES_TYPE_BUFFER
:
1965 return GL_TEXTURE_2D
; /* TODO: GL_TEXTURE_BUFFER. */
1966 case WINED3D_GL_RES_TYPE_RB
:
1967 return GL_RENDERBUFFER
;
1968 case WINED3D_GL_RES_TYPE_COUNT
:
1971 ERR("Unexpected GL resource type %u.\n", type
);
1975 static void delete_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
1976 enum wined3d_gl_resource_type d3d_type
, GLuint object
)
1980 case WINED3D_GL_RES_TYPE_TEX_1D
:
1981 case WINED3D_GL_RES_TYPE_TEX_2D
:
1982 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1983 case WINED3D_GL_RES_TYPE_TEX_3D
:
1984 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1985 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &object
);
1988 case WINED3D_GL_RES_TYPE_RB
:
1989 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &object
);
1992 case WINED3D_GL_RES_TYPE_BUFFER
:
1993 case WINED3D_GL_RES_TYPE_COUNT
:
1998 /* Context activation is done by the caller. */
1999 static void create_and_bind_fbo_attachment(const struct wined3d_gl_info
*gl_info
, unsigned int flags
,
2000 enum wined3d_gl_resource_type d3d_type
, GLuint
*object
, GLenum internal
, GLenum format
, GLenum type
)
2002 GLenum attach_type
= flags
& WINED3DFMT_FLAG_DEPTH
?
2003 GL_DEPTH_ATTACHMENT
: GL_COLOR_ATTACHMENT0
;
2007 case WINED3D_GL_RES_TYPE_TEX_1D
:
2008 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2009 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, *object
);
2010 gl_info
->gl_ops
.gl
.p_glTexImage1D(GL_TEXTURE_1D
, 0, internal
, 16, 0, format
, type
, NULL
);
2011 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2012 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2014 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_1D
,
2016 if (flags
& WINED3DFMT_FLAG_STENCIL
)
2017 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_TEXTURE_1D
,
2021 case WINED3D_GL_RES_TYPE_TEX_2D
:
2022 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2023 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2024 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(d3d_type
), *object
);
2025 gl_info
->gl_ops
.gl
.p_glTexImage2D(wined3d_gl_type_to_enum(d3d_type
), 0, internal
, 16, 16, 0,
2026 format
, type
, NULL
);
2027 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2028 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2030 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
2031 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
2032 if (flags
& WINED3DFMT_FLAG_STENCIL
)
2033 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
2034 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
2037 case WINED3D_GL_RES_TYPE_TEX_3D
:
2038 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2039 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_3D
, *object
);
2040 GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D
, 0, internal
, 16, 16, 16, 0, format
, type
, NULL
));
2041 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2042 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2044 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, attach_type
,
2045 GL_TEXTURE_3D
, *object
, 0, 0);
2046 if (flags
& WINED3DFMT_FLAG_STENCIL
)
2047 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
2048 GL_TEXTURE_3D
, *object
, 0, 0);
2051 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2052 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
2053 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, *object
);
2054 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, internal
, 16, 16, 0,
2055 format
, type
, NULL
);
2056 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
, 0, internal
, 16, 16, 0,
2057 format
, type
, NULL
);
2058 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
, 0, internal
, 16, 16, 0,
2059 format
, type
, NULL
);
2060 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
, 0, internal
, 16, 16, 0,
2061 format
, type
, NULL
);
2062 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
, 0, internal
, 16, 16, 0,
2063 format
, type
, NULL
);
2064 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
, 0, internal
, 16, 16, 0,
2065 format
, type
, NULL
);
2066 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2067 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2069 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
2070 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
2071 if (flags
& WINED3DFMT_FLAG_STENCIL
)
2072 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
2073 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
2076 case WINED3D_GL_RES_TYPE_RB
:
2077 gl_info
->fbo_ops
.glGenRenderbuffers(1, object
);
2078 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, *object
);
2079 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, internal
, 16, 16);
2080 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, attach_type
, GL_RENDERBUFFER
,
2082 if (flags
& WINED3DFMT_FLAG_STENCIL
)
2083 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
,
2087 case WINED3D_GL_RES_TYPE_BUFFER
:
2088 case WINED3D_GL_RES_TYPE_COUNT
:
2092 /* Ideally we'd skip all formats already known not to work on textures
2093 * by checking for WINED3DFMT_FLAG_TEXTURE here. However, we want to
2094 * know if we can attach WINED3DFMT_P8_UINT textures to FBOs, and this
2095 * format never has WINED3DFMT_FLAG_TEXTURE set. Instead, swallow GL
2096 * errors generated by invalid formats. */
2097 while (gl_info
->gl_ops
.gl
.p_glGetError());
2100 static void draw_test_quad(struct wined3d_caps_gl_ctx
*ctx
, const struct wined3d_vec3
*geometry
,
2101 const struct wined3d_color
*color
)
2103 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2104 static const struct wined3d_vec3 default_geometry
[] =
2106 {-1.0f
, -1.0f
, 0.0f
},
2107 { 1.0f
, -1.0f
, 0.0f
},
2108 {-1.0f
, 1.0f
, 0.0f
},
2109 { 1.0f
, 1.0f
, 0.0f
},
2111 static const char vs_core_header
[] =
2115 "out vec4 out_color;\n"
2117 static const char vs_legacy_header
[] =
2119 "attribute vec4 pos;\n"
2120 "attribute vec4 color;\n"
2121 "varying vec4 out_color;\n"
2123 static const char vs_body
[] =
2126 " gl_Position = pos;\n"
2127 " out_color = color;\n"
2129 static const char fs_core
[] =
2131 "in vec4 out_color;\n"
2132 "out vec4 fragment_color;\n"
2136 " fragment_color = out_color;\n"
2138 static const char fs_legacy
[] =
2140 "varying vec4 out_color;\n"
2144 " gl_FragData[0] = out_color;\n"
2146 const char *source
[2];
2147 GLuint vs_id
, fs_id
;
2151 geometry
= default_geometry
;
2153 if (!gl_info
->supported
[ARB_VERTEX_BUFFER_OBJECT
] || !gl_info
->supported
[ARB_VERTEX_SHADER
]
2154 || !gl_info
->supported
[ARB_FRAGMENT_SHADER
])
2156 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
2157 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
2158 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2159 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
2160 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2162 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
2163 gl_info
->gl_ops
.gl
.p_glColor4f(color
->r
, color
->g
, color
->b
, color
->a
);
2164 for (i
= 0; i
< 4; ++i
)
2165 gl_info
->gl_ops
.gl
.p_glVertex3fv(&geometry
[i
].x
);
2166 gl_info
->gl_ops
.gl
.p_glEnd();
2167 checkGLcall("draw quad");
2172 GL_EXTCALL(glGenBuffers(1, &ctx
->test_vbo
));
2173 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, ctx
->test_vbo
));
2174 GL_EXTCALL(glBufferData(GL_ARRAY_BUFFER
, sizeof(struct wined3d_vec3
) * 4, geometry
, GL_STREAM_DRAW
));
2175 GL_EXTCALL(glVertexAttribPointer(0, 3, GL_FLOAT
, FALSE
, 0, NULL
));
2176 GL_EXTCALL(glVertexAttrib4f(1, color
->r
, color
->g
, color
->b
, color
->a
));
2177 GL_EXTCALL(glEnableVertexAttribArray(0));
2178 GL_EXTCALL(glDisableVertexAttribArray(1));
2180 if (!ctx
->test_program_id
)
2182 BOOL use_glsl_150
= gl_info
->glsl_version
>= MAKEDWORD_VERSION(1, 50);
2184 ctx
->test_program_id
= GL_EXTCALL(glCreateProgram());
2186 vs_id
= GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER
));
2187 source
[0] = use_glsl_150
? vs_core_header
: vs_legacy_header
;
2188 source
[1] = vs_body
;
2189 GL_EXTCALL(glShaderSource(vs_id
, 2, source
, NULL
));
2190 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, vs_id
));
2191 GL_EXTCALL(glDeleteShader(vs_id
));
2193 fs_id
= GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER
));
2194 source
[0] = use_glsl_150
? fs_core
: fs_legacy
;
2195 GL_EXTCALL(glShaderSource(fs_id
, 1, source
, NULL
));
2196 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, fs_id
));
2197 GL_EXTCALL(glDeleteShader(fs_id
));
2199 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 0, "pos"));
2200 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 1, "color"));
2203 GL_EXTCALL(glBindFragDataLocation(ctx
->test_program_id
, 0, "fragment_color"));
2205 GL_EXTCALL(glCompileShader(vs_id
));
2206 print_glsl_info_log(gl_info
, vs_id
, FALSE
);
2207 GL_EXTCALL(glCompileShader(fs_id
));
2208 print_glsl_info_log(gl_info
, fs_id
, FALSE
);
2209 GL_EXTCALL(glLinkProgram(ctx
->test_program_id
));
2210 shader_glsl_validate_link(gl_info
, ctx
->test_program_id
);
2212 GL_EXTCALL(glUseProgram(ctx
->test_program_id
));
2214 gl_info
->gl_ops
.gl
.p_glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
2216 GL_EXTCALL(glUseProgram(0));
2217 GL_EXTCALL(glDisableVertexAttribArray(0));
2218 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, 0));
2219 checkGLcall("draw quad");
2222 /* Context activation is done by the caller. */
2223 static void check_fbo_compat(struct wined3d_caps_gl_ctx
*ctx
, struct wined3d_format
*format
)
2225 /* Check if the default internal format is supported as a frame buffer
2226 * target, otherwise fall back to the render target internal.
2228 * Try to stick to the standard format if possible, this limits precision differences. */
2229 static const struct wined3d_color black
= {0.0f
, 0.0f
, 0.0f
, 1.0f
};
2230 static const struct wined3d_color half_transparent_red
= {1.0f
, 0.0f
, 0.0f
, 0.5f
};
2231 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2232 GLenum status
, rt_internal
= format
->rtInternal
;
2233 GLuint object
, color_rb
;
2234 enum wined3d_gl_resource_type type
;
2235 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2237 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2239 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
2241 const char *type_string
= "color";
2243 if (type
== WINED3D_GL_RES_TYPE_BUFFER
)
2246 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->glInternal
,
2247 format
->glFormat
, format
->glType
);
2249 if (format
->flags
[type
] & (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2251 gl_info
->fbo_ops
.glGenRenderbuffers(1, &color_rb
);
2252 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, color_rb
);
2253 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2254 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 1);
2256 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 16);
2258 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2259 GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, color_rb
);
2260 checkGLcall("Create and attach color rb attachment");
2261 type_string
= "depth / stencil";
2264 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2265 checkGLcall("Framebuffer format check");
2267 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2269 TRACE("Format %s is supported as FBO %s attachment, type %u.\n",
2270 debug_d3dformat(format
->id
), type_string
, type
);
2271 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2272 format
->rtInternal
= format
->glInternal
;
2273 regular_fmt_used
= TRUE
;
2279 if (format
->flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
2281 WARN("Format %s with rendertarget flag is not supported as FBO color attachment (type %u),"
2282 " and no fallback specified.\n", debug_d3dformat(format
->id
), type
);
2283 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2287 TRACE("Format %s is not supported as FBO %s attachment, type %u.\n",
2288 debug_d3dformat(format
->id
), type_string
, type
);
2290 format
->rtInternal
= format
->glInternal
;
2294 TRACE("Format %s is not supported as FBO %s attachment (type %u),"
2295 " trying rtInternal format as fallback.\n",
2296 debug_d3dformat(format
->id
), type_string
, type
);
2298 while (gl_info
->gl_ops
.gl
.p_glGetError());
2300 delete_fbo_attachment(gl_info
, type
, object
);
2301 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->rtInternal
,
2302 format
->glFormat
, format
->glType
);
2304 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2305 checkGLcall("Framebuffer format check");
2307 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2309 TRACE("Format %s rtInternal format is supported as FBO %s attachment, type %u.\n",
2310 debug_d3dformat(format
->id
), type_string
, type
);
2311 fallback_fmt_used
= TRUE
;
2315 WARN("Format %s rtInternal format is not supported as FBO %s attachment, type %u.\n",
2316 debug_d3dformat(format
->id
), type_string
, type
);
2317 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2322 if (status
== GL_FRAMEBUFFER_COMPLETE
2323 && ((format
->flags
[type
] & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
)
2324 || !(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2325 && !(format
->flags
[type
] & WINED3DFMT_FLAG_INTEGER
)
2326 && format
->id
!= WINED3DFMT_NULL
&& format
->id
!= WINED3DFMT_P8_UINT
2327 && format
->glFormat
!= GL_LUMINANCE
&& format
->glFormat
!= GL_LUMINANCE_ALPHA
2328 && (format
->red_size
|| format
->alpha_size
))
2330 DWORD readback
[16 * 16 * 16], color
, r_range
, a_range
;
2335 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
]
2336 || gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2338 gl_info
->fbo_ops
.glGenRenderbuffers(1, &rb
);
2339 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
2340 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2341 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 1);
2343 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 16);
2344 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2345 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2346 checkGLcall("RB attachment");
2349 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2350 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.0f
, 1.0f
);
2351 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
2352 if (gl_info
->gl_ops
.gl
.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION
)
2354 while (gl_info
->gl_ops
.gl
.p_glGetError());
2355 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2356 debug_d3dformat(format
->id
), type
);
2357 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2361 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2362 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2363 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2365 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 16);
2366 gl_info
->gl_ops
.gl
.p_glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2368 draw_test_quad(ctx
, NULL
, &black
);
2370 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2372 draw_test_quad(ctx
, NULL
, &half_transparent_red
);
2374 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2378 case WINED3D_GL_RES_TYPE_TEX_1D
:
2379 /* Rebinding texture to workaround a fglrx bug. */
2380 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, object
);
2381 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_1D
, 0, GL_BGRA
,
2382 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2383 color
= readback
[7];
2386 case WINED3D_GL_RES_TYPE_TEX_2D
:
2387 case WINED3D_GL_RES_TYPE_TEX_3D
:
2388 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2389 /* Rebinding texture to workaround a fglrx bug. */
2390 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(type
), object
);
2391 gl_info
->gl_ops
.gl
.p_glGetTexImage(wined3d_gl_type_to_enum(type
), 0, GL_BGRA
,
2392 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2393 color
= readback
[7 * 16 + 7];
2396 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2397 /* Rebinding texture to workaround a fglrx bug. */
2398 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, object
);
2399 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, GL_BGRA
,
2400 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2401 color
= readback
[7 * 16 + 7];
2404 case WINED3D_GL_RES_TYPE_RB
:
2405 gl_info
->gl_ops
.gl
.p_glReadPixels(0, 0, 16, 16,
2406 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2407 color
= readback
[7 * 16 + 7];
2410 case WINED3D_GL_RES_TYPE_BUFFER
:
2411 case WINED3D_GL_RES_TYPE_COUNT
:
2415 checkGLcall("Post-pixelshader blending check");
2418 r
= (color
& 0x00ff0000u
) >> 16;
2420 r_range
= format
->red_size
< 8 ? 1u << (8 - format
->red_size
) : 1;
2421 a_range
= format
->alpha_size
< 8 ? 1u << (8 - format
->alpha_size
) : 1;
2422 if (format
->red_size
&& (r
< 0x7f - r_range
|| r
> 0x7f + r_range
))
2424 else if (format
->alpha_size
> 1 && (a
< 0xbf - a_range
|| a
> 0xbf + a_range
))
2428 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2429 debug_d3dformat(format
->id
), type
);
2430 TRACE("Color output: %#x\n", color
);
2431 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2435 TRACE("Format %s supports post-pixelshader blending, type %u.\n",
2436 debug_d3dformat(format
->id
), type
);
2437 TRACE("Color output: %#x\n", color
);
2438 format
->flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2442 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
]
2443 || gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2445 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2446 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2447 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &rb
);
2448 checkGLcall("RB cleanup");
2452 if (format
->glInternal
!= format
->glGammaInternal
)
2454 delete_fbo_attachment(gl_info
, type
, object
);
2455 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->glGammaInternal
,
2456 format
->glFormat
, format
->glType
);
2458 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2459 checkGLcall("Framebuffer format check");
2461 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2463 TRACE("Format %s's sRGB format is FBO attachable, type %u.\n",
2464 debug_d3dformat(format
->id
), type
);
2465 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2466 if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2467 format
->glInternal
= format
->glGammaInternal
;
2471 WARN("Format %s's sRGB format is not FBO attachable, type %u.\n",
2472 debug_d3dformat(format
->id
), type
);
2473 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2476 else if (status
== GL_FRAMEBUFFER_COMPLETE
)
2477 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2479 if (format
->flags
[type
] & (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2481 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, 0);
2482 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &color_rb
);
2485 delete_fbo_attachment(gl_info
, type
, object
);
2486 checkGLcall("Framebuffer format check cleanup");
2489 if (fallback_fmt_used
&& regular_fmt_used
)
2491 FIXME("Format %s needs different render target formats for different resource types.\n",
2492 debug_d3dformat(format
->id
));
2493 format_clear_flag(format
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
2494 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2498 static void query_format_flag(struct wined3d_gl_info
*gl_info
, struct wined3d_format
*format
,
2499 GLint internal
, GLenum pname
, DWORD flag
, const char *string
)
2502 enum wined3d_gl_resource_type type
;
2504 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
2506 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
), internal
, pname
, 1, &value
);
2507 if (value
== GL_FULL_SUPPORT
)
2509 TRACE("Format %s supports %s, resource type %u.\n", debug_d3dformat(format
->id
), string
, type
);
2510 format
->flags
[type
] |= flag
;
2514 TRACE("Format %s doesn't support %s, resource type %u.\n", debug_d3dformat(format
->id
), string
, type
);
2515 format
->flags
[type
] &= ~flag
;
2520 /* Context activation is done by the caller. */
2521 static void init_format_fbo_compat_info(struct wined3d_caps_gl_ctx
*ctx
)
2523 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2524 unsigned int i
, type
;
2527 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2529 for (i
= 0; i
< gl_info
->format_count
; ++i
)
2532 struct wined3d_format
*format
= &gl_info
->formats
[i
];
2533 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2534 GLenum rt_internal
= format
->rtInternal
;
2536 if (!format
->glInternal
)
2539 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
2541 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2542 format
->glInternal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2543 if (value
== GL_FULL_SUPPORT
)
2545 TRACE("Format %s is supported as FBO color attachment, resource type %u.\n",
2546 debug_d3dformat(format
->id
), type
);
2547 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2548 format
->rtInternal
= format
->glInternal
;
2549 regular_fmt_used
= TRUE
;
2551 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2552 format
->glInternal
, GL_FRAMEBUFFER_BLEND
, 1, &value
);
2553 if (value
== GL_FULL_SUPPORT
)
2555 TRACE("Format %s supports post-pixelshader blending, resource type %u.\n",
2556 debug_d3dformat(format
->id
), type
);
2557 format
->flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2561 TRACE("Format %s doesn't support post-pixelshader blending, resource typed %u.\n",
2562 debug_d3dformat(format
->id
), type
);
2563 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2570 if (format
->flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
2572 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
2573 " and no fallback specified, resource type %u.\n",
2574 debug_d3dformat(format
->id
), type
);
2575 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2578 TRACE("Format %s is not supported as FBO color attachment,"
2579 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2580 format
->rtInternal
= format
->glInternal
;
2584 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2585 rt_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2586 if (value
== GL_FULL_SUPPORT
)
2588 TRACE("Format %s rtInternal format is supported as FBO color attachment,"
2589 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2590 fallback_fmt_used
= TRUE
;
2594 WARN("Format %s rtInternal format is not supported as FBO color attachment,"
2595 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2596 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2601 if (format
->glInternal
!= format
->glGammaInternal
)
2603 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2604 format
->glGammaInternal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2605 if (value
== GL_FULL_SUPPORT
)
2607 TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n",
2608 debug_d3dformat(format
->id
), type
);
2609 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2610 if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2611 format
->glInternal
= format
->glGammaInternal
;
2615 WARN("Format %s's sRGB format is not FBO attachable, resource type %u.\n",
2616 debug_d3dformat(format
->id
), type
);
2617 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2620 else if (format
->flags
[type
] & WINED3DFMT_FLAG_FBO_ATTACHABLE
)
2621 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2624 if (fallback_fmt_used
&& regular_fmt_used
)
2626 FIXME("Format %s needs different render target formats for different resource types.\n",
2627 debug_d3dformat(format
->id
));
2628 format_clear_flag(format
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
2629 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2635 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2637 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2638 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2639 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2640 gl_info
->gl_ops
.gl
.p_glReadBuffer(GL_COLOR_ATTACHMENT0
);
2643 for (i
= 0; i
< gl_info
->format_count
; ++i
)
2645 struct wined3d_format
*format
= &gl_info
->formats
[i
];
2647 if (!format
->glInternal
) continue;
2649 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_COMPRESSED
)
2651 TRACE("Skipping format %s because it's a compressed format.\n",
2652 debug_d3dformat(format
->id
));
2656 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2658 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format
->id
));
2659 check_fbo_compat(ctx
, format
);
2663 format
->rtInternal
= format
->glInternal
;
2667 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2668 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2671 static GLenum
lookup_gl_view_class(GLenum internal_format
)
2675 GLenum internal_format
;
2681 {GL_RGBA32F
, GL_VIEW_CLASS_128_BITS
},
2682 {GL_RGBA32UI
, GL_VIEW_CLASS_128_BITS
},
2683 {GL_RGBA32I
, GL_VIEW_CLASS_128_BITS
},
2685 {GL_RGB32F
, GL_VIEW_CLASS_96_BITS
},
2686 {GL_RGB32UI
, GL_VIEW_CLASS_96_BITS
},
2687 {GL_RGB32I
, GL_VIEW_CLASS_96_BITS
},
2689 {GL_RGBA16F
, GL_VIEW_CLASS_64_BITS
},
2690 {GL_RG32F
, GL_VIEW_CLASS_64_BITS
},
2691 {GL_RGBA16UI
, GL_VIEW_CLASS_64_BITS
},
2692 {GL_RG32UI
, GL_VIEW_CLASS_64_BITS
},
2693 {GL_RGBA16I
, GL_VIEW_CLASS_64_BITS
},
2694 {GL_RG32I
, GL_VIEW_CLASS_64_BITS
},
2695 {GL_RGBA16
, GL_VIEW_CLASS_64_BITS
},
2696 {GL_RGBA16_SNORM
, GL_VIEW_CLASS_64_BITS
},
2698 {GL_RGB16
, GL_VIEW_CLASS_48_BITS
},
2699 {GL_RGB16_SNORM
, GL_VIEW_CLASS_48_BITS
},
2700 {GL_RGB16F
, GL_VIEW_CLASS_48_BITS
},
2701 {GL_RGB16UI
, GL_VIEW_CLASS_48_BITS
},
2702 {GL_RGB16I
, GL_VIEW_CLASS_48_BITS
},
2704 {GL_RG16F
, GL_VIEW_CLASS_32_BITS
},
2705 {GL_R11F_G11F_B10F
, GL_VIEW_CLASS_32_BITS
},
2706 {GL_R32F
, GL_VIEW_CLASS_32_BITS
},
2707 {GL_RGB10_A2UI
, GL_VIEW_CLASS_32_BITS
},
2708 {GL_RGBA8UI
, GL_VIEW_CLASS_32_BITS
},
2709 {GL_RG16UI
, GL_VIEW_CLASS_32_BITS
},
2710 {GL_R32UI
, GL_VIEW_CLASS_32_BITS
},
2711 {GL_RGBA8I
, GL_VIEW_CLASS_32_BITS
},
2712 {GL_RG16I
, GL_VIEW_CLASS_32_BITS
},
2713 {GL_R32I
, GL_VIEW_CLASS_32_BITS
},
2714 {GL_RGB10_A2
, GL_VIEW_CLASS_32_BITS
},
2715 {GL_RGBA8
, GL_VIEW_CLASS_32_BITS
},
2716 {GL_RG16
, GL_VIEW_CLASS_32_BITS
},
2717 {GL_RGBA8_SNORM
, GL_VIEW_CLASS_32_BITS
},
2718 {GL_RG16_SNORM
, GL_VIEW_CLASS_32_BITS
},
2719 {GL_SRGB8_ALPHA8
, GL_VIEW_CLASS_32_BITS
},
2720 {GL_RGB9_E5
, GL_VIEW_CLASS_32_BITS
},
2722 {GL_RGB8
, GL_VIEW_CLASS_24_BITS
},
2723 {GL_RGB8_SNORM
, GL_VIEW_CLASS_24_BITS
},
2724 {GL_SRGB8
, GL_VIEW_CLASS_24_BITS
},
2725 {GL_RGB8UI
, GL_VIEW_CLASS_24_BITS
},
2726 {GL_RGB8I
, GL_VIEW_CLASS_24_BITS
},
2728 {GL_R16F
, GL_VIEW_CLASS_16_BITS
},
2729 {GL_RG8UI
, GL_VIEW_CLASS_16_BITS
},
2730 {GL_R16UI
, GL_VIEW_CLASS_16_BITS
},
2731 {GL_RG8I
, GL_VIEW_CLASS_16_BITS
},
2732 {GL_R16I
, GL_VIEW_CLASS_16_BITS
},
2733 {GL_RG8
, GL_VIEW_CLASS_16_BITS
},
2734 {GL_R16
, GL_VIEW_CLASS_16_BITS
},
2735 {GL_RG8_SNORM
, GL_VIEW_CLASS_16_BITS
},
2736 {GL_R16_SNORM
, GL_VIEW_CLASS_16_BITS
},
2738 {GL_R8UI
, GL_VIEW_CLASS_8_BITS
},
2739 {GL_R8I
, GL_VIEW_CLASS_8_BITS
},
2740 {GL_R8
, GL_VIEW_CLASS_8_BITS
},
2741 {GL_R8_SNORM
, GL_VIEW_CLASS_8_BITS
},
2744 {GL_COMPRESSED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
2745 {GL_COMPRESSED_SIGNED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
2747 {GL_COMPRESSED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
2748 {GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
2751 {GL_COMPRESSED_RGBA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
2752 {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
2754 {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
2755 {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
2758 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
2759 {GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
2761 {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
2762 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
2764 {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
2765 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
2767 {GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
2768 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
2773 for (i
= 0; i
< ARRAY_SIZE(view_classes
); ++i
)
2775 if (view_classes
[i
].internal_format
== internal_format
)
2776 return view_classes
[i
].view_class
;
2782 static void query_view_class(struct wined3d_format
*format
)
2784 GLenum internal_view_class
, gamma_view_class
, rt_view_class
;
2786 internal_view_class
= lookup_gl_view_class(format
->glInternal
);
2787 gamma_view_class
= lookup_gl_view_class(format
->glGammaInternal
);
2788 rt_view_class
= lookup_gl_view_class(format
->rtInternal
);
2790 if (internal_view_class
== gamma_view_class
|| gamma_view_class
== rt_view_class
)
2792 format
->gl_view_class
= internal_view_class
;
2793 TRACE("Format %s is member of GL view class %#x.\n",
2794 debug_d3dformat(format
->id
), format
->gl_view_class
);
2798 format
->gl_view_class
= GL_NONE
;
2802 static void query_internal_format(struct wined3d_adapter
*adapter
,
2803 struct wined3d_format
*format
, const struct wined3d_format_texture_info
*texture_info
,
2804 struct wined3d_gl_info
*gl_info
, BOOL srgb_write_supported
, BOOL srgb_format
)
2806 GLint count
, multisample_types
[MAX_MULTISAMPLE_TYPES
];
2807 unsigned int i
, max_log2
;
2810 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2812 query_format_flag(gl_info
, format
, format
->glInternal
, GL_VERTEX_TEXTURE
,
2813 WINED3DFMT_FLAG_VTF
, "vertex texture usage");
2814 query_format_flag(gl_info
, format
, format
->glInternal
, GL_FILTER
,
2815 WINED3DFMT_FLAG_FILTERING
, "filtering");
2817 if (srgb_format
|| format
->glGammaInternal
!= format
->glInternal
)
2819 query_format_flag(gl_info
, format
, format
->glGammaInternal
, GL_SRGB_READ
,
2820 WINED3DFMT_FLAG_SRGB_READ
, "sRGB read");
2822 if (srgb_write_supported
)
2823 query_format_flag(gl_info
, format
, format
->glGammaInternal
, GL_SRGB_WRITE
,
2824 WINED3DFMT_FLAG_SRGB_WRITE
, "sRGB write");
2826 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2828 if (!(format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & (WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
)))
2829 format
->glGammaInternal
= format
->glInternal
;
2830 else if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
2831 && gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2832 format
->glInternal
= format
->glGammaInternal
;
2837 if (!gl_info
->limits
.samplers
[WINED3D_SHADER_TYPE_VERTEX
])
2838 format_clear_flag(format
, WINED3DFMT_FLAG_VTF
);
2840 if (!(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2841 format_set_flag(format
, WINED3DFMT_FLAG_FILTERING
);
2842 else if (format
->id
!= WINED3DFMT_R32G32B32A32_FLOAT
&& format
->id
!= WINED3DFMT_R32_FLOAT
)
2843 format_clear_flag(format
, WINED3DFMT_FLAG_VTF
);
2845 if (srgb_format
|| format
->glGammaInternal
!= format
->glInternal
)
2847 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
2848 if (!gl_info
->supported
[EXT_TEXTURE_SRGB
])
2850 format
->glGammaInternal
= format
->glInternal
;
2851 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2853 else if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
2854 && gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2856 format
->glInternal
= format
->glGammaInternal
;
2860 if ((format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_SRGB_WRITE
) && !srgb_write_supported
)
2861 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2863 if (!gl_info
->supported
[ARB_DEPTH_TEXTURE
]
2864 && texture_info
->flags
& (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2866 format
->flags
[WINED3D_GL_RES_TYPE_TEX_1D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2867 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2868 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2869 format
->flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2870 format
->flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2874 query_view_class(format
);
2876 if (format
->glInternal
&& format
->flags
[WINED3D_GL_RES_TYPE_RB
]
2877 & (WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2879 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY
])
2881 target
= gl_info
->supported
[ARB_TEXTURE_MULTISAMPLE
] ? GL_TEXTURE_2D_MULTISAMPLE
: GL_RENDERBUFFER
;
2883 GL_EXTCALL(glGetInternalformativ(target
, format
->glInternal
,
2884 GL_NUM_SAMPLE_COUNTS
, 1, &count
));
2885 count
= min(count
, MAX_MULTISAMPLE_TYPES
);
2886 GL_EXTCALL(glGetInternalformativ(target
, format
->glInternal
,
2887 GL_SAMPLES
, count
, multisample_types
));
2888 checkGLcall("query sample counts");
2889 for (i
= 0; i
< count
; ++i
)
2891 if (multisample_types
[i
] > sizeof(format
->multisample_types
) * CHAR_BIT
)
2893 format
->multisample_types
|= 1u << (multisample_types
[i
] - 1);
2898 max_log2
= wined3d_log2i(min(gl_info
->limits
.samples
,
2899 sizeof(format
->multisample_types
) * CHAR_BIT
));
2900 for (i
= 1; i
<= max_log2
; ++i
)
2901 format
->multisample_types
|= 1u << ((1u << i
) - 1);
2906 static BOOL
init_format_texture_info(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
2908 struct wined3d_format
*format
, *srgb_format
;
2909 struct fragment_caps fragment_caps
;
2910 struct shader_caps shader_caps
;
2914 adapter
->fragment_pipe
->get_caps(gl_info
, &fragment_caps
);
2915 adapter
->shader_backend
->shader_get_caps(gl_info
, &shader_caps
);
2916 srgb_write
= (fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_SRGB_WRITE
)
2917 && (shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_SRGB_WRITE
);
2919 for (i
= 0; i
< ARRAY_SIZE(format_texture_info
); ++i
)
2921 if (!(format
= get_format_internal(gl_info
, format_texture_info
[i
].id
)))
2924 if (!gl_info
->supported
[format_texture_info
[i
].extension
])
2927 /* ARB_texture_rg defines floating point formats, but only if
2928 * ARB_texture_float is also supported. */
2929 if (!gl_info
->supported
[ARB_TEXTURE_FLOAT
]
2930 && (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_FLOAT
))
2933 /* ARB_texture_rg defines integer formats if EXT_texture_integer is also supported. */
2934 if (!gl_info
->supported
[EXT_TEXTURE_INTEGER
]
2935 && (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_INTEGER
))
2938 format
->glInternal
= format_texture_info
[i
].gl_internal
;
2939 format
->glGammaInternal
= format_texture_info
[i
].gl_srgb_internal
;
2940 format
->rtInternal
= format_texture_info
[i
].gl_rt_internal
;
2941 format
->glFormat
= format_texture_info
[i
].gl_format
;
2942 format
->glType
= format_texture_info
[i
].gl_type
;
2943 format
->color_fixup
= COLOR_FIXUP_IDENTITY
;
2944 format
->height_scale
.numerator
= 1;
2945 format
->height_scale
.denominator
= 1;
2947 format
->flags
[WINED3D_GL_RES_TYPE_TEX_1D
] |= format_texture_info
[i
].flags
;
2948 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] |= format_texture_info
[i
].flags
;
2949 format
->flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= format_texture_info
[i
].flags
;
2951 /* GL_ARB_depth_texture does not support 3D textures. It also says "cube textures are
2952 * problematic", but doesn't explicitly mandate that an error is generated. */
2953 if (gl_info
->supported
[EXT_TEXTURE3D
]
2954 && !(format_texture_info
[i
].flags
& (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
)))
2955 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] |= format_texture_info
[i
].flags
;
2957 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
2958 format
->flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= format_texture_info
[i
].flags
;
2960 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
2961 format
->flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] |= format_texture_info
[i
].flags
;
2963 format
->flags
[WINED3D_GL_RES_TYPE_RB
] |= format_texture_info
[i
].flags
;
2964 format
->flags
[WINED3D_GL_RES_TYPE_RB
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2966 if (format
->glGammaInternal
!= format
->glInternal
2967 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
2969 format
->glGammaInternal
= format
->glInternal
;
2970 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2973 query_internal_format(adapter
, format
, &format_texture_info
[i
], gl_info
, srgb_write
, FALSE
);
2975 /* Texture conversion stuff */
2976 format
->conv_byte_count
= format_texture_info
[i
].conv_byte_count
;
2977 format
->upload
= format_texture_info
[i
].upload
;
2978 format
->download
= format_texture_info
[i
].download
;
2981 for (j
= 0; j
< ARRAY_SIZE(format_srgb_info
); ++j
)
2983 if (format_srgb_info
[j
].base_format_id
== format
->id
)
2985 if (!(srgb_format
= get_format_internal(gl_info
, format_srgb_info
[j
].srgb_format_id
)))
2993 copy_format(srgb_format
, format
);
2995 if (gl_info
->supported
[EXT_TEXTURE_SRGB
]
2996 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
2998 srgb_format
->glInternal
= format_texture_info
[i
].gl_srgb_internal
;
2999 srgb_format
->glGammaInternal
= format_texture_info
[i
].gl_srgb_internal
;
3000 format_set_flag(srgb_format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
3001 query_internal_format(adapter
, srgb_format
, &format_texture_info
[i
], gl_info
, srgb_write
, TRUE
);
3008 static BOOL
color_match(DWORD c1
, DWORD c2
, BYTE max_diff
)
3010 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
3012 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
3014 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
3016 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
3020 /* A context is provided by the caller */
3021 static BOOL
check_filter(const struct wined3d_gl_info
*gl_info
, GLenum internal
)
3023 static const DWORD data
[] = {0x00000000, 0xffffffff};
3024 GLuint tex
, fbo
, buffer
;
3025 DWORD readback
[16 * 1];
3028 /* Render a filtered texture and see what happens. This is intended to detect the lack of
3029 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
3030 * falling back to software. If this changes in the future this code will get fooled and
3031 * apps might hit the software path due to incorrectly advertised caps.
3033 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
3034 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
3035 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
3038 while (gl_info
->gl_ops
.gl
.p_glGetError());
3040 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &buffer
);
3041 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
3042 memset(readback
, 0x7e, sizeof(readback
));
3043 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 16, 1, 0,
3044 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, readback
);
3045 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
3046 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
3047 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
3048 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
3049 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
3051 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &tex
);
3052 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, tex
);
3053 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, internal
, 2, 1, 0,
3054 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, data
);
3055 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
3056 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
3057 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
3058 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
3059 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
3060 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
3062 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3063 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3064 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, buffer
, 0);
3065 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
3067 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
3068 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
3069 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
3070 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
3071 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
3072 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
3074 gl_info
->gl_ops
.gl
.p_glClearColor(0, 1, 0, 0);
3075 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3077 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
3078 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 0.0);
3079 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, -1.0f
);
3080 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 0.0);
3081 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, -1.0f
);
3082 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 1.0);
3083 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, 1.0f
);
3084 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 1.0);
3085 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, 1.0f
);
3086 gl_info
->gl_ops
.gl
.p_glEnd();
3088 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
3089 memset(readback
, 0x7f, sizeof(readback
));
3090 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3091 if (color_match(readback
[6], 0xffffffff, 5) || color_match(readback
[6], 0x00000000, 5)
3092 || color_match(readback
[9], 0xffffffff, 5) || color_match(readback
[9], 0x00000000, 5))
3094 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
3095 readback
[6], readback
[9]);
3100 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
3101 readback
[6], readback
[9]);
3105 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3106 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3107 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &tex
);
3108 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &buffer
);
3109 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
3111 if (gl_info
->gl_ops
.gl
.p_glGetError())
3113 FIXME("Error during filtering test for format %x, returning no filtering\n", internal
);
3120 static void init_format_filter_info(struct wined3d_gl_info
*gl_info
, enum wined3d_pci_vendor vendor
)
3122 struct wined3d_format
*format
;
3123 unsigned int fmt_idx
, i
;
3124 static const enum wined3d_format_id fmts16
[] =
3126 WINED3DFMT_R16_FLOAT
,
3127 WINED3DFMT_R16G16_FLOAT
,
3128 WINED3DFMT_R16G16B16A16_FLOAT
,
3132 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
3133 /* This was already handled by init_format_texture_info(). */
3136 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
3137 || !gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3139 WARN("No FBO support, or no FBO ORM, guessing filter info from GL caps\n");
3140 if (vendor
== HW_VENDOR_NVIDIA
&& gl_info
->supported
[ARB_TEXTURE_FLOAT
])
3142 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
3145 else if (gl_info
->limits
.glsl_varyings
> 44)
3147 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
3152 TRACE("Assuming no float16 blending\n");
3158 for (i
= 0; i
< ARRAY_SIZE(fmts16
); ++i
)
3160 fmt_idx
= get_format_idx(fmts16
[i
]);
3161 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_FILTERING
);
3167 for (i
= 0; i
< ARRAY_SIZE(fmts16
); ++i
)
3169 fmt_idx
= get_format_idx(fmts16
[i
]);
3170 format
= &gl_info
->formats
[fmt_idx
];
3171 if (!format
->glInternal
) continue; /* Not supported by GL */
3173 filtered
= check_filter(gl_info
, gl_info
->formats
[fmt_idx
].glInternal
);
3176 TRACE("Format %s supports filtering\n", debug_d3dformat(fmts16
[i
]));
3177 format_set_flag(format
, WINED3DFMT_FLAG_FILTERING
);
3181 TRACE("Format %s does not support filtering\n", debug_d3dformat(fmts16
[i
]));
3186 static void apply_format_fixups(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
3191 idx
= get_format_idx(WINED3DFMT_R16_FLOAT
);
3192 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3193 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3195 idx
= get_format_idx(WINED3DFMT_R32_FLOAT
);
3196 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3197 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3199 idx
= get_format_idx(WINED3DFMT_R16G16_UNORM
);
3200 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3201 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3203 idx
= get_format_idx(WINED3DFMT_R16G16_FLOAT
);
3204 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3205 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3207 idx
= get_format_idx(WINED3DFMT_R32G32_FLOAT
);
3208 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3209 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3211 /* GL_ATI_envmap_bumpmap in theory supports R8G8_SNORM but is no longer supported by
3213 if (gl_info
->supported
[NV_TEXTURE_SHADER
] || gl_info
->supported
[EXT_TEXTURE_SNORM
])
3215 /* R8G8_SNORM and R16G16_SNORM need a fixup of the undefined blue channel. OpenGL
3216 * returns 0.0 when sampling from it, DirectX 1.0. So we always have in-shader
3217 * conversion for this format. */
3218 idx
= get_format_idx(WINED3DFMT_R8G8_SNORM
);
3219 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3220 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3221 idx
= get_format_idx(WINED3DFMT_R16G16_SNORM
);
3222 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3223 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3227 /* Emulate using unsigned formats. This requires load-time conversion in addition to the
3229 idx
= get_format_idx(WINED3DFMT_R8G8_SNORM
);
3230 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3231 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3232 idx
= get_format_idx(WINED3DFMT_R16G16_SNORM
);
3233 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3234 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3235 idx
= get_format_idx(WINED3DFMT_R8G8B8A8_SNORM
);
3236 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3237 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 1, CHANNEL_SOURCE_Z
, 1, CHANNEL_SOURCE_W
);
3238 idx
= get_format_idx(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
3239 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3240 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Z
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
);
3243 if (!gl_info
->supported
[NV_TEXTURE_SHADER
])
3245 idx
= get_format_idx(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
3246 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3247 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_Z
, 0, CHANNEL_SOURCE_W
);
3250 if (gl_info
->supported
[ARB_TEXTURE_COMPRESSION_RGTC
] || gl_info
->supported
[EXT_TEXTURE_COMPRESSION_RGTC
])
3252 idx
= get_format_idx(WINED3DFMT_ATI1N
);
3253 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3254 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
);
3256 idx
= get_format_idx(WINED3DFMT_ATI2N
);
3257 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3258 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3260 else if (gl_info
->supported
[ATI_TEXTURE_COMPRESSION_3DC
])
3262 idx
= get_format_idx(WINED3DFMT_ATI2N
);
3263 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3264 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_W
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3267 if (!gl_info
->supported
[APPLE_YCBCR_422
] && gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3268 && gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3270 idx
= get_format_idx(WINED3DFMT_YUY2
);
3271 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUY2
);
3273 idx
= get_format_idx(WINED3DFMT_UYVY
);
3274 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_UYVY
);
3276 else if (!gl_info
->supported
[APPLE_YCBCR_422
] && (!gl_info
->supported
[ARB_FRAGMENT_PROGRAM
]
3277 || !gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
]))
3279 idx
= get_format_idx(WINED3DFMT_YUY2
);
3280 gl_info
->formats
[idx
].glInternal
= 0;
3282 idx
= get_format_idx(WINED3DFMT_UYVY
);
3283 gl_info
->formats
[idx
].glInternal
= 0;
3286 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
] && gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3288 idx
= get_format_idx(WINED3DFMT_YV12
);
3289 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_HEIGHT_SCALE
);
3290 gl_info
->formats
[idx
].height_scale
.numerator
= 3;
3291 gl_info
->formats
[idx
].height_scale
.denominator
= 2;
3292 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YV12
);
3294 idx
= get_format_idx(WINED3DFMT_NV12
);
3295 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_HEIGHT_SCALE
);
3296 gl_info
->formats
[idx
].height_scale
.numerator
= 3;
3297 gl_info
->formats
[idx
].height_scale
.denominator
= 2;
3298 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_NV12
);
3302 idx
= get_format_idx(WINED3DFMT_YV12
);
3303 gl_info
->formats
[idx
].glInternal
= 0;
3305 idx
= get_format_idx(WINED3DFMT_NV12
);
3306 gl_info
->formats
[idx
].glInternal
= 0;
3309 if (!gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3311 idx
= get_format_idx(WINED3DFMT_A8_UNORM
);
3312 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3313 0, CHANNEL_SOURCE_ZERO
, 0, CHANNEL_SOURCE_ZERO
, 0, CHANNEL_SOURCE_ZERO
, 0, CHANNEL_SOURCE_X
);
3314 idx
= get_format_idx(WINED3DFMT_L8A8_UNORM
);
3315 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3316 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
);
3317 idx
= get_format_idx(WINED3DFMT_L4A4_UNORM
);
3318 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3319 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
);
3320 idx
= get_format_idx(WINED3DFMT_L16_UNORM
);
3321 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3322 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
);
3323 idx
= get_format_idx(WINED3DFMT_INTZ
);
3324 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3325 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
);
3328 if (gl_info
->supported
[ARB_TEXTURE_RG
])
3330 idx
= get_format_idx(WINED3DFMT_L8_UNORM
);
3331 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3332 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
);
3335 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
])
3337 idx
= get_format_idx(WINED3DFMT_P8_UINT
);
3338 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_P8
);
3341 if (gl_info
->supported
[ARB_VERTEX_ARRAY_BGRA
])
3343 idx
= get_format_idx(WINED3DFMT_B8G8R8A8_UNORM
);
3344 gl_info
->formats
[idx
].gl_vtx_format
= GL_BGRA
;
3347 if (!gl_info
->supported
[ARB_HALF_FLOAT_VERTEX
])
3349 /* Do not change the size of the type, it is CPU side. We have to change the GPU-side information though.
3350 * It is the job of the vertex buffer code to make sure that the vbos have the right format */
3351 idx
= get_format_idx(WINED3DFMT_R16G16_FLOAT
);
3352 gl_info
->formats
[idx
].gl_vtx_type
= GL_FLOAT
;
3354 idx
= get_format_idx(WINED3DFMT_R16G16B16A16_FLOAT
);
3355 gl_info
->formats
[idx
].gl_vtx_type
= GL_FLOAT
;
3358 if (!gl_info
->supported
[ARB_HALF_FLOAT_PIXEL
])
3360 idx
= get_format_idx(WINED3DFMT_R16_FLOAT
);
3361 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3363 idx
= get_format_idx(WINED3DFMT_R16G16_FLOAT
);
3364 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3366 idx
= get_format_idx(WINED3DFMT_R16G16B16A16_FLOAT
);
3367 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3370 if (gl_info
->quirks
& WINED3D_QUIRK_BROKEN_RGBA16
)
3372 idx
= get_format_idx(WINED3DFMT_R16G16B16A16_UNORM
);
3373 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3376 /* ATI instancing hack: Although ATI cards do not support Shader Model
3377 * 3.0, they support instancing. To query if the card supports instancing
3378 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
3379 * is used. Should an application check for this, provide a proper return
3380 * value. We can do instancing with all shader versions, but we need
3383 * Additionally applications have to set the D3DRS_POINTSIZE render state
3384 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
3385 * doesn't need that and just ignores it.
3387 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
3388 /* FIXME: This should just check the shader backend caps. */
3389 if (gl_info
->supported
[ARB_VERTEX_PROGRAM
] || gl_info
->supported
[ARB_VERTEX_SHADER
])
3391 idx
= get_format_idx(WINED3DFMT_INST
);
3392 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3395 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
3396 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
3397 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
3398 * MAKEFOURCC('N','V','D','B') and then controlled by setting
3399 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
3401 if (gl_info
->supported
[EXT_DEPTH_BOUNDS_TEST
])
3403 idx
= get_format_idx(WINED3DFMT_NVDB
);
3404 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3407 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
3408 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
3409 * RENDERTARGET usage. */
3410 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
])
3412 idx
= get_format_idx(WINED3DFMT_RESZ
);
3413 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
);
3416 for (i
= 0; i
< gl_info
->format_count
; ++i
)
3418 struct wined3d_format
*format
= &gl_info
->formats
[i
];
3420 if (!(format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_TEXTURE
))
3423 if (is_identity_fixup(format
->color_fixup
))
3426 TRACE("Checking support for fixup:\n");
3427 dump_color_fixup_desc(format
->color_fixup
);
3428 if (!adapter
->shader_backend
->shader_color_fixup_supported(format
->color_fixup
)
3429 || !adapter
->fragment_pipe
->color_fixup_supported(format
->color_fixup
))
3431 TRACE("[FAILED]\n");
3432 format_clear_flag(format
, WINED3DFMT_FLAG_TEXTURE
);
3440 /* GL_EXT_texture_compression_s3tc does not support 3D textures. Some Windows drivers
3441 * for dx9 GPUs support it, some do not, so not supporting DXTn volumes is OK for d3d9.
3443 * Note that GL_NV_texture_compression_vtc adds this functionality to OpenGL, but the
3444 * block layout is not compatible with the one used by d3d. See volume_dxt5_test. */
3445 idx
= get_format_idx(WINED3DFMT_DXT1
);
3446 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3447 idx
= get_format_idx(WINED3DFMT_DXT2
);
3448 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3449 idx
= get_format_idx(WINED3DFMT_DXT3
);
3450 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3451 idx
= get_format_idx(WINED3DFMT_DXT4
);
3452 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3453 idx
= get_format_idx(WINED3DFMT_DXT5
);
3454 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3455 idx
= get_format_idx(WINED3DFMT_BC1_UNORM
);
3456 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3457 idx
= get_format_idx(WINED3DFMT_BC1_UNORM_SRGB
);
3458 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3459 idx
= get_format_idx(WINED3DFMT_BC2_UNORM
);
3460 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3461 idx
= get_format_idx(WINED3DFMT_BC2_UNORM_SRGB
);
3462 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3463 idx
= get_format_idx(WINED3DFMT_BC3_UNORM
);
3464 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3465 idx
= get_format_idx(WINED3DFMT_BC3_UNORM_SRGB
);
3466 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3467 /* Similarly with ATI1N / ATI2N and GL_ARB_texture_compression_rgtc. */
3468 idx
= get_format_idx(WINED3DFMT_ATI1N
);
3469 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3470 idx
= get_format_idx(WINED3DFMT_ATI2N
);
3471 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3472 idx
= get_format_idx(WINED3DFMT_BC4_UNORM
);
3473 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3474 idx
= get_format_idx(WINED3DFMT_BC4_SNORM
);
3475 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3476 idx
= get_format_idx(WINED3DFMT_BC5_UNORM
);
3477 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3478 idx
= get_format_idx(WINED3DFMT_BC5_SNORM
);
3479 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3482 static unsigned int calculate_vertex_attribute_size(GLenum type
, unsigned int component_count
)
3487 return component_count
* sizeof(GLhalfNV
);
3489 return component_count
* sizeof(GLfloat
);
3491 return component_count
* sizeof(GLbyte
);
3492 case GL_UNSIGNED_BYTE
:
3493 return component_count
* sizeof(GLubyte
);
3495 return component_count
* sizeof(GLshort
);
3496 case GL_UNSIGNED_SHORT
:
3497 return component_count
* sizeof(GLushort
);
3499 return component_count
* sizeof(GLint
);
3500 case GL_UNSIGNED_INT
:
3501 return component_count
* sizeof(GLuint
);
3502 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3503 return sizeof(GLuint
);
3505 FIXME("Unhandled GL type %#x.\n", type
);
3510 static BOOL
init_format_vertex_info(struct wined3d_gl_info
*gl_info
)
3512 struct wined3d_format
*format
;
3515 for (i
= 0; i
< ARRAY_SIZE(format_vertex_info
); ++i
)
3517 if (!(format
= get_format_internal(gl_info
, format_vertex_info
[i
].id
)))
3520 if (!gl_info
->supported
[format_vertex_info
[i
].extension
])
3523 format
->emit_idx
= format_vertex_info
[i
].emit_idx
;
3524 format
->component_count
= format_vertex_info
[i
].component_count
;
3525 format
->gl_vtx_type
= format_vertex_info
[i
].gl_vtx_type
;
3526 format
->gl_vtx_format
= format_vertex_info
[i
].component_count
;
3527 format
->gl_normalized
= format_vertex_info
[i
].gl_normalized
;
3528 if (!(format
->attribute_size
= calculate_vertex_attribute_size(format
->gl_vtx_type
,
3529 format
->component_count
)))
3531 ERR("Invalid attribute size for vertex format %s (%#x).\n",
3532 debug_d3dformat(format_vertex_info
[i
].id
), format_vertex_info
[i
].id
);
3540 static BOOL
init_typeless_formats(struct wined3d_gl_info
*gl_info
)
3542 unsigned int flags
[WINED3D_GL_RES_TYPE_COUNT
];
3545 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
3547 struct wined3d_format
*format
, *typeless_format
;
3549 if (!(format
= get_format_internal(gl_info
, typed_formats
[i
].id
)))
3551 if (!(typeless_format
= get_format_internal(gl_info
, typed_formats
[i
].typeless_id
)))
3554 memcpy(flags
, typeless_format
->flags
, sizeof(flags
));
3555 copy_format(typeless_format
, format
);
3556 for (j
= 0; j
< ARRAY_SIZE(typeless_format
->flags
); ++j
)
3557 typeless_format
->flags
[j
] |= flags
[j
];
3560 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
3562 struct wined3d_format
*typeless_format
, *typeless_ds_format
, *ds_format
;
3563 struct wined3d_format
*depth_view_format
, *stencil_view_format
;
3564 enum wined3d_format_id format_id
;
3566 if (!(typeless_format
= get_format_internal(gl_info
, typeless_depth_stencil_formats
[i
].typeless_id
)))
3568 if (!(ds_format
= get_format_internal(gl_info
, typeless_depth_stencil_formats
[i
].depth_stencil_id
)))
3571 typeless_ds_format
= &gl_info
->formats
[WINED3D_FORMAT_COUNT
+ i
];
3572 typeless_ds_format
->id
= typeless_depth_stencil_formats
[i
].typeless_id
;
3573 copy_format(typeless_ds_format
, ds_format
);
3574 for (j
= 0; j
< ARRAY_SIZE(typeless_ds_format
->flags
); ++j
)
3576 typeless_ds_format
->flags
[j
] = typeless_format
->flags
[j
];
3577 typeless_format
->flags
[j
] &= ~(WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
);
3580 if ((format_id
= typeless_depth_stencil_formats
[i
].depth_view_id
)
3581 && typeless_depth_stencil_formats
[i
].separate_depth_view_format
)
3583 if (!(depth_view_format
= get_format_internal(gl_info
, format_id
)))
3585 copy_format(depth_view_format
, ds_format
);
3587 if ((format_id
= typeless_depth_stencil_formats
[i
].stencil_view_id
))
3589 if (!(stencil_view_format
= get_format_internal(gl_info
, format_id
)))
3591 copy_format(stencil_view_format
, ds_format
);
3598 static void init_format_gen_mipmap_info(struct wined3d_gl_info
*gl_info
)
3602 if (!gl_info
->fbo_ops
.glGenerateMipmap
)
3605 for (i
= 0; i
< gl_info
->format_count
; ++i
)
3607 struct wined3d_format
*format
= &gl_info
->formats
[i
];
3609 for (j
= 0; j
< ARRAY_SIZE(format
->flags
); ++j
)
3610 if (!(~format
->flags
[j
] & (WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FILTERING
)))
3611 format
->flags
[j
] |= WINED3DFMT_FLAG_GEN_MIPMAP
;
3615 BOOL
wined3d_caps_gl_ctx_test_viewport_subpixel_bits(struct wined3d_caps_gl_ctx
*ctx
)
3617 static const struct wined3d_color red
= {1.0f
, 0.0f
, 0.0f
, 1.0f
};
3618 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3619 static const float offset
= -63.0f
/ 128.0f
;
3620 GLuint texture
, fbo
;
3624 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &texture
);
3625 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3626 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3627 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, ARRAY_SIZE(readback
), 1, 0,
3628 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, NULL
);
3629 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3630 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3631 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
3632 GL_TEXTURE_2D
, texture
, 0);
3633 checkGLcall("create resources");
3635 gl_info
->gl_ops
.gl
.p_glClearColor(1.0f
, 1.0f
, 1.0f
, 1.0f
);
3636 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3637 GL_EXTCALL(glViewportIndexedf(0, offset
, offset
, 4.0f
, 1.0f
));
3638 draw_test_quad(ctx
, NULL
, &red
);
3639 checkGLcall("draw");
3641 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3642 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0,
3643 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3644 checkGLcall("readback");
3646 TRACE("Readback colors are 0x%08x, 0x%08x, 0x%08x, 0x%08x.\n",
3647 readback
[0], readback
[1], readback
[2], readback
[3]);
3649 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &texture
);
3650 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3651 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3652 checkGLcall("delete resources");
3654 for (i
= 0; i
< ARRAY_SIZE(readback
); ++i
)
3656 if (readback
[i
] != 0xffff0000)
3662 static float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx
*ctx
, GLenum format
)
3664 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3665 static const struct wined3d_color blue
= {0.0f
, 0.0f
, 1.0f
, 1.0f
};
3666 GLuint fbo
, color
, depth
;
3667 unsigned int low
= 0, high
= 32, cur
;
3668 DWORD readback
[256];
3669 static const struct wined3d_vec3 geometry
[] =
3671 {-1.0f
, -1.0f
, -1.0f
},
3672 { 1.0f
, -1.0f
, 0.0f
},
3673 {-1.0f
, 1.0f
, -1.0f
},
3674 { 1.0f
, 1.0f
, 0.0f
},
3677 /* Most drivers want 2^23 for fixed point depth buffers, including r300g, r600g,
3678 * Nvidia. Use this as a fallback if the detection fails. */
3679 unsigned int fallback
= 23;
3681 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
3683 FIXME("No FBOs, assuming polyoffset scale of 2^%u.\n", fallback
);
3684 return (float)(1u << fallback
);
3687 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &color
);
3688 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
3689 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3690 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);
3692 gl_info
->fbo_ops
.glGenRenderbuffers(1, &depth
);
3693 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, depth
);
3694 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, format
, 256, 1);
3696 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3697 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3698 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, color
, 0);
3699 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, depth
);
3700 checkGLcall("Setup framebuffer");
3702 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.5f
, 0.0f
);
3703 gl_info
->gl_ops
.gl
.p_glClearDepth(0.5f
);
3704 gl_info
->gl_ops
.gl
.p_glEnable(GL_DEPTH_TEST
);
3705 gl_info
->gl_ops
.gl
.p_glEnable(GL_POLYGON_OFFSET_FILL
);
3706 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 256, 1);
3707 checkGLcall("Misc parameters");
3711 if (high
- low
<= 1)
3713 ERR("PolygonOffset scale factor detection failed, using fallback value 2^%u.\n", fallback
);
3717 cur
= (low
+ high
) / 2;
3719 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
3720 /* The post viewport transform Z of the geometry runs from 0.0 to 0.5. We want to push it another
3721 * 0.25 so that the Z buffer content (0.5) cuts the quad off at half the screen. */
3722 gl_info
->gl_ops
.gl
.p_glPolygonOffset(0.0f
, (float)(1u << cur
) * 0.25f
);
3723 draw_test_quad(ctx
, geometry
, &blue
);
3724 checkGLcall("Test draw");
3726 /* Rebinding texture to workaround a fglrx bug. */
3727 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
3728 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3729 checkGLcall("readback");
3731 TRACE("low %02u, high %02u, cur %2u, 0=0x%08x, 125=0x%08x, 131=0x%08x, 255=0x%08x\n",
3732 low
, high
, cur
, readback
[0], readback
[125], readback
[131], readback
[255]);
3734 if ((readback
[125] & 0xff) < 0xa0)
3736 else if ((readback
[131] & 0xff) > 0xa0)
3740 TRACE("Found scale factor 2^%u for format %x.\n", cur
, format
);
3745 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &color
);
3746 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &depth
);
3747 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3748 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3749 checkGLcall("Delete framebuffer");
3751 gl_info
->gl_ops
.gl
.p_glDisable(GL_DEPTH_TEST
);
3752 gl_info
->gl_ops
.gl
.p_glDisable(GL_POLYGON_OFFSET_FILL
);
3753 return (float)(1u << cur
);
3756 static void init_format_depth_bias_scale(struct wined3d_caps_gl_ctx
*ctx
,
3757 const struct wined3d_d3d_info
*d3d_info
)
3759 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3762 for (i
= 0; i
< gl_info
->format_count
; ++i
)
3764 struct wined3d_format
*format
= &gl_info
->formats
[i
];
3766 if (format
->flags
[WINED3D_GL_RES_TYPE_RB
] & WINED3DFMT_FLAG_DEPTH
)
3768 TRACE("Testing depth bias scale for format %s.\n", debug_d3dformat(format
->id
));
3769 format
->depth_bias_scale
= wined3d_adapter_find_polyoffset_scale(ctx
, format
->glInternal
);
3771 if (!(d3d_info
->wined3d_creation_flags
& WINED3D_NORMALIZED_DEPTH_BIAS
))
3773 /* The single-precision binary floating-point format has
3774 * a significand precision of 24 bits.
3776 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_FLOAT
)
3777 format
->depth_bias_scale
/= 1u << 24;
3779 format
->depth_bias_scale
/= 1u << format
->depth_size
;
3785 /* Context activation is done by the caller. */
3786 BOOL
wined3d_adapter_init_format_info(struct wined3d_adapter
*adapter
, struct wined3d_caps_gl_ctx
*ctx
)
3788 struct wined3d_gl_info
*gl_info
= &adapter
->gl_info
;
3790 if (!init_format_base_info(gl_info
)) return FALSE
;
3791 if (!init_format_block_info(gl_info
)) goto fail
;
3793 if (!ctx
) /* WINED3D_NO3D */
3796 if (!init_format_texture_info(adapter
, gl_info
)) goto fail
;
3797 if (!init_format_vertex_info(gl_info
)) goto fail
;
3799 apply_format_fixups(adapter
, gl_info
);
3800 init_format_fbo_compat_info(ctx
);
3801 init_format_filter_info(gl_info
, adapter
->driver_info
.vendor
);
3802 if (!init_typeless_formats(gl_info
)) goto fail
;
3803 init_format_gen_mipmap_info(gl_info
);
3804 init_format_depth_bias_scale(ctx
, &adapter
->d3d_info
);
3809 heap_free(gl_info
->formats
);
3810 gl_info
->formats
= NULL
;
3814 const struct wined3d_format
*wined3d_get_format(const struct wined3d_gl_info
*gl_info
,
3815 enum wined3d_format_id format_id
, unsigned int resource_usage
)
3817 const struct wined3d_format
*format
;
3818 int idx
= get_format_idx(format_id
);
3823 FIXME("Can't find format %s (%#x) in the format lookup table.\n",
3824 debug_d3dformat(format_id
), format_id
);
3825 return &gl_info
->formats
[get_format_idx(WINED3DFMT_UNKNOWN
)];
3828 format
= &gl_info
->formats
[idx
];
3830 if (resource_usage
& WINED3DUSAGE_DEPTHSTENCIL
&& wined3d_format_is_typeless(format
))
3832 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
3834 if (typeless_depth_stencil_formats
[i
].typeless_id
== format_id
)
3835 return &gl_info
->formats
[WINED3D_FORMAT_COUNT
+ i
];
3838 FIXME("Cannot find depth/stencil typeless format %s (%#x).\n",
3839 debug_d3dformat(format_id
), format_id
);
3840 return &gl_info
->formats
[get_format_idx(WINED3DFMT_UNKNOWN
)];
3846 BOOL
wined3d_format_is_depth_view(enum wined3d_format_id resource_format_id
,
3847 enum wined3d_format_id view_format_id
)
3851 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
3853 if (typeless_depth_stencil_formats
[i
].typeless_id
== resource_format_id
)
3854 return typeless_depth_stencil_formats
[i
].depth_view_id
== view_format_id
;
3859 void wined3d_format_calculate_pitch(const struct wined3d_format
*format
, unsigned int alignment
,
3860 unsigned int width
, unsigned int height
, unsigned int *row_pitch
, unsigned int *slice_pitch
)
3862 /* For block based formats, pitch means the amount of bytes to the next
3863 * row of blocks rather than the next row of pixels. */
3864 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BLOCKS
)
3866 unsigned int row_block_count
= (width
+ format
->block_width
- 1) / format
->block_width
;
3867 unsigned int slice_block_count
= (height
+ format
->block_height
- 1) / format
->block_height
;
3868 *row_pitch
= row_block_count
* format
->block_byte_count
;
3869 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
3870 *slice_pitch
= *row_pitch
* slice_block_count
;
3874 *row_pitch
= format
->byte_count
* width
; /* Bytes / row */
3875 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
3876 *slice_pitch
= *row_pitch
* height
;
3879 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_HEIGHT_SCALE
)
3881 /* The D3D format requirements make sure that the resulting format is an integer again */
3882 *slice_pitch
*= format
->height_scale
.numerator
;
3883 *slice_pitch
/= format
->height_scale
.denominator
;
3886 TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch
, *slice_pitch
);
3889 UINT
wined3d_format_calculate_size(const struct wined3d_format
*format
, UINT alignment
,
3890 UINT width
, UINT height
, UINT depth
)
3892 unsigned int row_pitch
, slice_pitch
;
3894 if (format
->id
== WINED3DFMT_UNKNOWN
)
3897 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BROKEN_PITCH
)
3898 return width
* height
* depth
* format
->byte_count
;
3900 wined3d_format_calculate_pitch(format
, alignment
, width
, height
, &row_pitch
, &slice_pitch
);
3902 return slice_pitch
* depth
;
3905 BOOL
wined3d_formats_are_srgb_variants(enum wined3d_format_id format1
, enum wined3d_format_id format2
)
3909 for (i
= 0; i
< ARRAY_SIZE(format_srgb_info
); ++i
)
3911 if (format1
== format_srgb_info
[i
].srgb_format_id
)
3912 return format2
== format_srgb_info
[i
].base_format_id
;
3913 if (format1
== format_srgb_info
[i
].base_format_id
)
3914 return format2
== format_srgb_info
[i
].srgb_format_id
;
3919 /*****************************************************************************
3920 * Trace formatting of useful values
3922 const char *debug_box(const struct wined3d_box
*box
)
3926 return wine_dbg_sprintf("(%u, %u, %u)-(%u, %u, %u)",
3927 box
->left
, box
->top
, box
->front
,
3928 box
->right
, box
->bottom
, box
->back
);
3931 const char *debug_color(const struct wined3d_color
*color
)
3935 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
3936 color
->r
, color
->g
, color
->b
, color
->a
);
3939 const char *debug_ivec4(const struct wined3d_ivec4
*v
)
3943 return wine_dbg_sprintf("{%d, %d, %d, %d}",
3944 v
->x
, v
->y
, v
->z
, v
->w
);
3947 const char *debug_uvec4(const struct wined3d_uvec4
*v
)
3951 return wine_dbg_sprintf("{%u, %u, %u, %u}",
3952 v
->x
, v
->y
, v
->z
, v
->w
);
3955 const char *debug_vec4(const struct wined3d_vec4
*v
)
3959 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
3960 v
->x
, v
->y
, v
->z
, v
->w
);
3963 const char *debug_d3dformat(enum wined3d_format_id format_id
)
3967 #define FMT_TO_STR(format_id) case format_id: return #format_id
3968 FMT_TO_STR(WINED3DFMT_UNKNOWN
);
3969 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM
);
3970 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM
);
3971 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM
);
3972 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM
);
3973 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM
);
3974 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM
);
3975 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM
);
3976 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM
);
3977 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM
);
3978 FMT_TO_STR(WINED3DFMT_P8_UINT
);
3979 FMT_TO_STR(WINED3DFMT_L8_UNORM
);
3980 FMT_TO_STR(WINED3DFMT_L8A8_UNORM
);
3981 FMT_TO_STR(WINED3DFMT_L4A4_UNORM
);
3982 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
3983 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
3984 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM
);
3985 FMT_TO_STR(WINED3DFMT_R10G10B10X2_UINT
);
3986 FMT_TO_STR(WINED3DFMT_R10G10B10X2_SNORM
);
3987 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM
);
3988 FMT_TO_STR(WINED3DFMT_UYVY
);
3989 FMT_TO_STR(WINED3DFMT_YUY2
);
3990 FMT_TO_STR(WINED3DFMT_YV12
);
3991 FMT_TO_STR(WINED3DFMT_NV12
);
3992 FMT_TO_STR(WINED3DFMT_DXT1
);
3993 FMT_TO_STR(WINED3DFMT_DXT2
);
3994 FMT_TO_STR(WINED3DFMT_DXT3
);
3995 FMT_TO_STR(WINED3DFMT_DXT4
);
3996 FMT_TO_STR(WINED3DFMT_DXT5
);
3997 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8
);
3998 FMT_TO_STR(WINED3DFMT_G8R8_G8B8
);
3999 FMT_TO_STR(WINED3DFMT_R8G8_B8G8
);
4000 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE
);
4001 FMT_TO_STR(WINED3DFMT_D32_UNORM
);
4002 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM
);
4003 FMT_TO_STR(WINED3DFMT_X8D24_UNORM
);
4004 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM
);
4005 FMT_TO_STR(WINED3DFMT_L16_UNORM
);
4006 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT
);
4007 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx
);
4008 FMT_TO_STR(WINED3DFMT_ATI1N
);
4009 FMT_TO_STR(WINED3DFMT_ATI2N
);
4010 FMT_TO_STR(WINED3DFMT_NVDB
);
4011 FMT_TO_STR(WINED3DFMT_NVHU
);
4012 FMT_TO_STR(WINED3DFMT_NVHS
);
4013 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS
);
4014 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT
);
4015 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT
);
4016 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT
);
4017 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS
);
4018 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT
);
4019 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT
);
4020 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT
);
4021 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS
);
4022 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT
);
4023 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM
);
4024 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT
);
4025 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM
);
4026 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT
);
4027 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS
);
4028 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT
);
4029 FMT_TO_STR(WINED3DFMT_R32G32_UINT
);
4030 FMT_TO_STR(WINED3DFMT_R32G32_SINT
);
4031 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS
);
4032 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT
);
4033 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
);
4034 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT
);
4035 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS
);
4036 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM
);
4037 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT
);
4038 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM
);
4039 FMT_TO_STR(WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM
);
4040 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT
);
4041 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS
);
4042 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM
);
4043 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB
);
4044 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT
);
4045 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM
);
4046 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT
);
4047 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS
);
4048 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT
);
4049 FMT_TO_STR(WINED3DFMT_R16G16_UNORM
);
4050 FMT_TO_STR(WINED3DFMT_R16G16_UINT
);
4051 FMT_TO_STR(WINED3DFMT_R16G16_SNORM
);
4052 FMT_TO_STR(WINED3DFMT_R16G16_SINT
);
4053 FMT_TO_STR(WINED3DFMT_R32_TYPELESS
);
4054 FMT_TO_STR(WINED3DFMT_D32_FLOAT
);
4055 FMT_TO_STR(WINED3DFMT_R32_FLOAT
);
4056 FMT_TO_STR(WINED3DFMT_R32_UINT
);
4057 FMT_TO_STR(WINED3DFMT_R32_SINT
);
4058 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS
);
4059 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT
);
4060 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS
);
4061 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT
);
4062 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS
);
4063 FMT_TO_STR(WINED3DFMT_R8G8_UNORM
);
4064 FMT_TO_STR(WINED3DFMT_R8G8_UINT
);
4065 FMT_TO_STR(WINED3DFMT_R8G8_SNORM
);
4066 FMT_TO_STR(WINED3DFMT_R8G8_SINT
);
4067 FMT_TO_STR(WINED3DFMT_R16_TYPELESS
);
4068 FMT_TO_STR(WINED3DFMT_R16_FLOAT
);
4069 FMT_TO_STR(WINED3DFMT_D16_UNORM
);
4070 FMT_TO_STR(WINED3DFMT_R16_UNORM
);
4071 FMT_TO_STR(WINED3DFMT_R16_UINT
);
4072 FMT_TO_STR(WINED3DFMT_R16_SNORM
);
4073 FMT_TO_STR(WINED3DFMT_R16_SINT
);
4074 FMT_TO_STR(WINED3DFMT_R8_TYPELESS
);
4075 FMT_TO_STR(WINED3DFMT_R8_UNORM
);
4076 FMT_TO_STR(WINED3DFMT_R8_UINT
);
4077 FMT_TO_STR(WINED3DFMT_R8_SNORM
);
4078 FMT_TO_STR(WINED3DFMT_R8_SINT
);
4079 FMT_TO_STR(WINED3DFMT_A8_UNORM
);
4080 FMT_TO_STR(WINED3DFMT_R1_UNORM
);
4081 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP
);
4082 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM
);
4083 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM
);
4084 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS
);
4085 FMT_TO_STR(WINED3DFMT_BC1_UNORM
);
4086 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB
);
4087 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS
);
4088 FMT_TO_STR(WINED3DFMT_BC2_UNORM
);
4089 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB
);
4090 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS
);
4091 FMT_TO_STR(WINED3DFMT_BC3_UNORM
);
4092 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB
);
4093 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS
);
4094 FMT_TO_STR(WINED3DFMT_BC4_UNORM
);
4095 FMT_TO_STR(WINED3DFMT_BC4_SNORM
);
4096 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS
);
4097 FMT_TO_STR(WINED3DFMT_BC5_UNORM
);
4098 FMT_TO_STR(WINED3DFMT_BC5_SNORM
);
4099 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM
);
4100 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM
);
4101 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM
);
4102 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM
);
4103 FMT_TO_STR(WINED3DFMT_B8G8R8A8_TYPELESS
);
4104 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM_SRGB
);
4105 FMT_TO_STR(WINED3DFMT_B8G8R8X8_TYPELESS
);
4106 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM_SRGB
);
4107 FMT_TO_STR(WINED3DFMT_BC6H_TYPELESS
);
4108 FMT_TO_STR(WINED3DFMT_BC6H_UF16
);
4109 FMT_TO_STR(WINED3DFMT_BC6H_SF16
);
4110 FMT_TO_STR(WINED3DFMT_BC7_TYPELESS
);
4111 FMT_TO_STR(WINED3DFMT_BC7_UNORM
);
4112 FMT_TO_STR(WINED3DFMT_BC7_UNORM_SRGB
);
4113 FMT_TO_STR(WINED3DFMT_INTZ
);
4114 FMT_TO_STR(WINED3DFMT_RESZ
);
4115 FMT_TO_STR(WINED3DFMT_NULL
);
4116 FMT_TO_STR(WINED3DFMT_R16
);
4117 FMT_TO_STR(WINED3DFMT_AL16
);
4122 fourcc
[0] = (char)(format_id
);
4123 fourcc
[1] = (char)(format_id
>> 8);
4124 fourcc
[2] = (char)(format_id
>> 16);
4125 fourcc
[3] = (char)(format_id
>> 24);
4127 if (isprint(fourcc
[0]) && isprint(fourcc
[1]) && isprint(fourcc
[2]) && isprint(fourcc
[3]))
4128 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id
, fourcc
);
4130 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id
);
4132 return "unrecognized";
4136 const char *debug_d3ddevicetype(enum wined3d_device_type device_type
)
4138 switch (device_type
)
4140 #define DEVTYPE_TO_STR(dev) case dev: return #dev
4141 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL
);
4142 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF
);
4143 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW
);
4144 #undef DEVTYPE_TO_STR
4146 FIXME("Unrecognized device type %#x.\n", device_type
);
4147 return "unrecognized";
4153 char str
[200]; /* wine_dbg_sprintf() limits string size to 200 */
4158 static void init_debug_buffer(struct debug_buffer
*buffer
, const char *default_string
)
4160 strcpy(buffer
->str
, default_string
);
4161 buffer
->ptr
= buffer
->str
;
4162 buffer
->size
= ARRAY_SIZE(buffer
->str
);
4165 static void debug_append(struct debug_buffer
*buffer
, const char *str
, const char *separator
)
4169 if (!separator
|| buffer
->ptr
== buffer
->str
)
4171 size
= snprintf(buffer
->ptr
, buffer
->size
, "%s%s", separator
, str
);
4172 if (size
== -1 || size
>= buffer
->size
)
4175 strcpy(&buffer
->str
[ARRAY_SIZE(buffer
->str
) - 4], "...");
4179 buffer
->ptr
+= size
;
4180 buffer
->size
-= size
;
4183 const char *wined3d_debug_resource_access(DWORD access
)
4185 struct debug_buffer buffer
;
4187 init_debug_buffer(&buffer
, "0");
4188 #define ACCESS_TO_STR(x) if (access & x) { debug_append(&buffer, #x, " | "); access &= ~x; }
4189 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_GPU
);
4190 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_CPU
);
4191 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_MAP_R
);
4192 ACCESS_TO_STR(WINED3D_RESOURCE_ACCESS_MAP_W
);
4193 #undef ACCESS_TO_STR
4195 FIXME("Unrecognised access flag(s) %#x.\n", access
);
4197 return wine_dbg_sprintf("%s", buffer
.str
);
4200 const char *debug_d3dusage(DWORD usage
)
4202 struct debug_buffer buffer
;
4204 init_debug_buffer(&buffer
, "0");
4205 #define WINED3DUSAGE_TO_STR(x) if (usage & x) { debug_append(&buffer, #x, " | "); usage &= ~x; }
4206 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RENDERTARGET
);
4207 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DEPTHSTENCIL
);
4208 WINED3DUSAGE_TO_STR(WINED3DUSAGE_WRITEONLY
);
4209 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING
);
4210 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP
);
4211 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS
);
4212 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES
);
4213 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES
);
4214 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC
);
4215 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICTED_CONTENT
);
4216 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE_DRIVER
);
4217 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE
);
4218 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP
);
4219 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTAPI
);
4220 WINED3DUSAGE_TO_STR(WINED3DUSAGE_LEGACY_CUBEMAP
);
4221 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTURE
);
4222 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OWNDC
);
4223 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL
);
4224 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY
);
4225 #undef WINED3DUSAGE_TO_STR
4227 FIXME("Unrecognized usage flag(s) %#x.\n", usage
);
4229 return wine_dbg_sprintf("%s", buffer
.str
);
4232 const char *debug_d3dusagequery(DWORD usage
)
4234 struct debug_buffer buffer
;
4236 init_debug_buffer(&buffer
, "0");
4237 #define WINED3DUSAGEQUERY_TO_STR(x) if (usage & x) { debug_append(&buffer, #x, " | "); usage &= ~x; }
4238 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_FILTER
);
4239 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_GENMIPMAP
);
4240 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP
);
4241 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
);
4242 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD
);
4243 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE
);
4244 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE
);
4245 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP
);
4246 #undef WINED3DUSAGEQUERY_TO_STR
4248 FIXME("Unrecognized usage query flag(s) %#x.\n", usage
);
4250 return wine_dbg_sprintf("%s", buffer
.str
);
4253 const char *debug_d3ddeclmethod(enum wined3d_decl_method method
)
4257 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
4258 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT
);
4259 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U
);
4260 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V
);
4261 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV
);
4262 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV
);
4263 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP
);
4264 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED
);
4265 #undef WINED3DDECLMETHOD_TO_STR
4267 FIXME("Unrecognized declaration method %#x.\n", method
);
4268 return "unrecognized";
4272 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage
)
4276 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
4277 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION
);
4278 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT
);
4279 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES
);
4280 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL
);
4281 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE
);
4282 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD
);
4283 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT
);
4284 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL
);
4285 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR
);
4286 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT
);
4287 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR
);
4288 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG
);
4289 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH
);
4290 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE
);
4291 #undef WINED3DDECLUSAGE_TO_STR
4293 FIXME("Unrecognized %u declaration usage!\n", usage
);
4294 return "unrecognized";
4298 const char *debug_d3dinput_classification(enum wined3d_input_classification classification
)
4300 switch (classification
)
4302 #define WINED3D_TO_STR(x) case x: return #x
4303 WINED3D_TO_STR(WINED3D_INPUT_PER_VERTEX_DATA
);
4304 WINED3D_TO_STR(WINED3D_INPUT_PER_INSTANCE_DATA
);
4305 #undef WINED3D_TO_STR
4307 FIXME("Unrecognized input classification %#x.\n", classification
);
4308 return "unrecognized";
4312 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type
)
4314 switch (resource_type
)
4316 #define WINED3D_TO_STR(x) case x: return #x
4317 WINED3D_TO_STR(WINED3D_RTYPE_NONE
);
4318 WINED3D_TO_STR(WINED3D_RTYPE_BUFFER
);
4319 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_2D
);
4320 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_3D
);
4321 #undef WINED3D_TO_STR
4323 FIXME("Unrecognized resource type %#x.\n", resource_type
);
4324 return "unrecognized";
4328 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type
)
4330 switch (primitive_type
)
4332 #define PRIM_TO_STR(prim) case prim: return #prim
4333 PRIM_TO_STR(WINED3D_PT_UNDEFINED
);
4334 PRIM_TO_STR(WINED3D_PT_POINTLIST
);
4335 PRIM_TO_STR(WINED3D_PT_LINELIST
);
4336 PRIM_TO_STR(WINED3D_PT_LINESTRIP
);
4337 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST
);
4338 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP
);
4339 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN
);
4340 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ
);
4341 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ
);
4342 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ
);
4343 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ
);
4344 PRIM_TO_STR(WINED3D_PT_PATCH
);
4347 FIXME("Unrecognized primitive type %#x.\n", primitive_type
);
4348 return "unrecognized";
4352 const char *debug_d3drenderstate(enum wined3d_render_state state
)
4356 #define D3DSTATE_TO_STR(u) case u: return #u
4357 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS
);
4358 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE
);
4359 D3DSTATE_TO_STR(WINED3D_RS_WRAPU
);
4360 D3DSTATE_TO_STR(WINED3D_RS_WRAPV
);
4361 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE
);
4362 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE
);
4363 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE
);
4364 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN
);
4365 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE
);
4366 D3DSTATE_TO_STR(WINED3D_RS_ROP2
);
4367 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK
);
4368 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE
);
4369 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE
);
4370 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL
);
4371 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND
);
4372 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND
);
4373 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE
);
4374 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC
);
4375 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF
);
4376 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC
);
4377 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE
);
4378 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE
);
4379 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE
);
4380 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE
);
4381 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE
);
4382 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL
);
4383 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX
);
4384 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA
);
4385 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR
);
4386 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE
);
4387 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART
);
4388 D3DSTATE_TO_STR(WINED3D_RS_FOGEND
);
4389 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY
);
4390 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE
);
4391 D3DSTATE_TO_STR(WINED3D_RS_EDGEANTIALIAS
);
4392 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE
);
4393 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS
);
4394 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE
);
4395 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY
);
4396 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH
);
4397 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT
);
4398 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE
);
4399 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL
);
4400 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL
);
4401 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS
);
4402 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC
);
4403 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF
);
4404 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK
);
4405 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK
);
4406 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR
);
4407 D3DSTATE_TO_STR(WINED3D_RS_WRAP0
);
4408 D3DSTATE_TO_STR(WINED3D_RS_WRAP1
);
4409 D3DSTATE_TO_STR(WINED3D_RS_WRAP2
);
4410 D3DSTATE_TO_STR(WINED3D_RS_WRAP3
);
4411 D3DSTATE_TO_STR(WINED3D_RS_WRAP4
);
4412 D3DSTATE_TO_STR(WINED3D_RS_WRAP5
);
4413 D3DSTATE_TO_STR(WINED3D_RS_WRAP6
);
4414 D3DSTATE_TO_STR(WINED3D_RS_WRAP7
);
4415 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING
);
4416 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING
);
4417 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS
);
4418 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT
);
4419 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE
);
4420 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX
);
4421 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER
);
4422 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS
);
4423 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE
);
4424 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE
);
4425 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE
);
4426 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE
);
4427 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE
);
4428 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND
);
4429 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE
);
4430 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING
);
4431 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE
);
4432 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN
);
4433 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE
);
4434 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE
);
4435 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A
);
4436 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B
);
4437 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C
);
4438 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS
);
4439 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK
);
4440 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE
);
4441 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS
);
4442 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN
);
4443 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX
);
4444 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE
);
4445 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE
);
4446 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR
);
4447 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP
);
4448 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE
);
4449 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE
);
4450 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE
);
4451 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS
);
4452 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE
);
4453 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL
);
4454 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL
);
4455 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X
);
4456 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y
);
4457 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z
);
4458 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W
);
4459 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION
);
4460 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE
);
4461 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFAIL
);
4462 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILZFAIL
);
4463 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILPASS
);
4464 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFUNC
);
4465 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1
);
4466 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2
);
4467 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3
);
4468 D3DSTATE_TO_STR(WINED3D_RS_BLENDFACTOR
);
4469 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE
);
4470 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS
);
4471 D3DSTATE_TO_STR(WINED3D_RS_WRAP8
);
4472 D3DSTATE_TO_STR(WINED3D_RS_WRAP9
);
4473 D3DSTATE_TO_STR(WINED3D_RS_WRAP10
);
4474 D3DSTATE_TO_STR(WINED3D_RS_WRAP11
);
4475 D3DSTATE_TO_STR(WINED3D_RS_WRAP12
);
4476 D3DSTATE_TO_STR(WINED3D_RS_WRAP13
);
4477 D3DSTATE_TO_STR(WINED3D_RS_WRAP14
);
4478 D3DSTATE_TO_STR(WINED3D_RS_WRAP15
);
4479 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE
);
4480 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA
);
4481 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA
);
4482 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA
);
4483 #undef D3DSTATE_TO_STR
4485 FIXME("Unrecognized %u render state!\n", state
);
4486 return "unrecognized";
4490 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state
)
4494 #define D3DSTATE_TO_STR(u) case u: return #u
4495 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR
);
4496 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U
);
4497 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V
);
4498 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W
);
4499 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER
);
4500 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER
);
4501 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER
);
4502 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS
);
4503 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL
);
4504 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY
);
4505 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE
);
4506 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX
);
4507 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET
);
4508 #undef D3DSTATE_TO_STR
4510 FIXME("Unrecognized %u sampler state!\n", state
);
4511 return "unrecognized";
4515 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type
)
4517 switch (filter_type
)
4519 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
4520 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE
);
4521 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT
);
4522 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR
);
4523 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC
);
4524 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC
);
4525 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC
);
4526 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD
);
4527 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD
);
4528 #undef D3DTEXTUREFILTERTYPE_TO_STR
4530 FIXME("Unrecognized texture filter type 0x%08x.\n", filter_type
);
4531 return "unrecognized";
4535 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state
)
4539 #define D3DSTATE_TO_STR(u) case u: return #u
4540 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP
);
4541 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1
);
4542 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2
);
4543 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP
);
4544 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1
);
4545 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2
);
4546 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00
);
4547 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01
);
4548 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10
);
4549 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11
);
4550 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX
);
4551 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE
);
4552 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET
);
4553 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
);
4554 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0
);
4555 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0
);
4556 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG
);
4557 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT
);
4558 #undef D3DSTATE_TO_STR
4560 FIXME("Unrecognized %u texture state!\n", state
);
4561 return "unrecognized";
4565 const char *debug_d3dtop(enum wined3d_texture_op d3dtop
)
4569 #define D3DTOP_TO_STR(u) case u: return #u
4570 D3DTOP_TO_STR(WINED3D_TOP_DISABLE
);
4571 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1
);
4572 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2
);
4573 D3DTOP_TO_STR(WINED3D_TOP_MODULATE
);
4574 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X
);
4575 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X
);
4576 D3DTOP_TO_STR(WINED3D_TOP_ADD
);
4577 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED
);
4578 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X
);
4579 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT
);
4580 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH
);
4581 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA
);
4582 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA
);
4583 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA
);
4584 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM
);
4585 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA
);
4586 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE
);
4587 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR
);
4588 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA
);
4589 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR
);
4590 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA
);
4591 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP
);
4592 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE
);
4593 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3
);
4594 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD
);
4595 D3DTOP_TO_STR(WINED3D_TOP_LERP
);
4596 #undef D3DTOP_TO_STR
4598 FIXME("Unrecognized texture op %#x.\n", d3dtop
);
4599 return "unrecognized";
4603 const char *debug_d3dtstype(enum wined3d_transform_state tstype
)
4607 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
4608 TSTYPE_TO_STR(WINED3D_TS_VIEW
);
4609 TSTYPE_TO_STR(WINED3D_TS_PROJECTION
);
4610 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0
);
4611 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1
);
4612 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2
);
4613 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3
);
4614 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4
);
4615 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5
);
4616 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6
);
4617 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7
);
4618 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
4619 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(1));
4620 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(2));
4621 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(3));
4622 #undef TSTYPE_TO_STR
4624 if (tstype
> 256 && tstype
< 512)
4626 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype
);
4627 return ("WINED3D_TS_WORLD_MATRIX > 0");
4629 FIXME("Unrecognized transform state %#x.\n", tstype
);
4630 return "unrecognized";
4634 const char *debug_shader_type(enum wined3d_shader_type type
)
4638 #define WINED3D_TO_STR(type) case type: return #type
4639 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL
);
4640 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX
);
4641 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY
);
4642 WINED3D_TO_STR(WINED3D_SHADER_TYPE_HULL
);
4643 WINED3D_TO_STR(WINED3D_SHADER_TYPE_DOMAIN
);
4644 WINED3D_TO_STR(WINED3D_SHADER_TYPE_COMPUTE
);
4645 #undef WINED3D_TO_STR
4647 FIXME("Unrecognized shader type %#x.\n", type
);
4648 return "unrecognized";
4652 const char *debug_d3dstate(DWORD state
)
4654 if (STATE_IS_RENDER(state
))
4655 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state
- STATE_RENDER(0)));
4656 if (STATE_IS_TEXTURESTAGE(state
))
4658 DWORD texture_stage
= (state
- STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE
+ 1);
4659 DWORD texture_state
= state
- STATE_TEXTURESTAGE(texture_stage
, 0);
4660 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
4661 texture_stage
, debug_d3dtexturestate(texture_state
));
4663 if (STATE_IS_SAMPLER(state
))
4664 return wine_dbg_sprintf("STATE_SAMPLER(%#x)", state
- STATE_SAMPLER(0));
4665 if (STATE_IS_COMPUTE_SHADER(state
))
4666 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE
));
4667 if (STATE_IS_GRAPHICS_SHADER(state
))
4668 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state
- STATE_SHADER(0)));
4669 if (STATE_IS_COMPUTE_CONSTANT_BUFFER(state
))
4670 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE
));
4671 if (STATE_IS_GRAPHICS_CONSTANT_BUFFER(state
))
4672 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state
- STATE_CONSTANT_BUFFER(0)));
4673 if (STATE_IS_COMPUTE_SHADER_RESOURCE_BINDING(state
))
4674 return "STATE_COMPUTE_SHADER_RESOURCE_BINDING";
4675 if (STATE_IS_GRAPHICS_SHADER_RESOURCE_BINDING(state
))
4676 return "STATE_GRAPHICS_SHADER_RESOURCE_BINDING";
4677 if (STATE_IS_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING(state
))
4678 return "STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING";
4679 if (STATE_IS_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING(state
))
4680 return "STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING";
4681 if (STATE_IS_TRANSFORM(state
))
4682 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state
- STATE_TRANSFORM(0)));
4683 if (STATE_IS_STREAMSRC(state
))
4684 return "STATE_STREAMSRC";
4685 if (STATE_IS_INDEXBUFFER(state
))
4686 return "STATE_INDEXBUFFER";
4687 if (STATE_IS_VDECL(state
))
4688 return "STATE_VDECL";
4689 if (STATE_IS_VIEWPORT(state
))
4690 return "STATE_VIEWPORT";
4691 if (STATE_IS_LIGHT_TYPE(state
))
4692 return "STATE_LIGHT_TYPE";
4693 if (STATE_IS_ACTIVELIGHT(state
))
4694 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state
- STATE_ACTIVELIGHT(0));
4695 if (STATE_IS_SCISSORRECT(state
))
4696 return "STATE_SCISSORRECT";
4697 if (STATE_IS_CLIPPLANE(state
))
4698 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state
- STATE_CLIPPLANE(0));
4699 if (STATE_IS_MATERIAL(state
))
4700 return "STATE_MATERIAL";
4701 if (STATE_IS_FRONTFACE(state
))
4702 return "STATE_FRONTFACE";
4703 if (STATE_IS_POINTSPRITECOORDORIGIN(state
))
4704 return "STATE_POINTSPRITECOORDORIGIN";
4705 if (STATE_IS_BASEVERTEXINDEX(state
))
4706 return "STATE_BASEVERTEXINDEX";
4707 if (STATE_IS_FRAMEBUFFER(state
))
4708 return "STATE_FRAMEBUFFER";
4709 if (STATE_IS_POINT_ENABLE(state
))
4710 return "STATE_POINT_ENABLE";
4711 if (STATE_IS_COLOR_KEY(state
))
4712 return "STATE_COLOR_KEY";
4713 if (STATE_IS_STREAM_OUTPUT(state
))
4714 return "STATE_STREAM_OUTPUT";
4715 if (STATE_IS_BLEND(state
))
4716 return "STATE_BLEND";
4718 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state
);
4721 const char *debug_fboattachment(GLenum attachment
)
4725 #define WINED3D_TO_STR(x) case x: return #x
4726 WINED3D_TO_STR(GL_COLOR_ATTACHMENT0
);
4727 WINED3D_TO_STR(GL_COLOR_ATTACHMENT1
);
4728 WINED3D_TO_STR(GL_COLOR_ATTACHMENT2
);
4729 WINED3D_TO_STR(GL_COLOR_ATTACHMENT3
);
4730 WINED3D_TO_STR(GL_COLOR_ATTACHMENT4
);
4731 WINED3D_TO_STR(GL_COLOR_ATTACHMENT5
);
4732 WINED3D_TO_STR(GL_COLOR_ATTACHMENT6
);
4733 WINED3D_TO_STR(GL_COLOR_ATTACHMENT7
);
4734 WINED3D_TO_STR(GL_COLOR_ATTACHMENT8
);
4735 WINED3D_TO_STR(GL_COLOR_ATTACHMENT9
);
4736 WINED3D_TO_STR(GL_COLOR_ATTACHMENT10
);
4737 WINED3D_TO_STR(GL_COLOR_ATTACHMENT11
);
4738 WINED3D_TO_STR(GL_COLOR_ATTACHMENT12
);
4739 WINED3D_TO_STR(GL_COLOR_ATTACHMENT13
);
4740 WINED3D_TO_STR(GL_COLOR_ATTACHMENT14
);
4741 WINED3D_TO_STR(GL_COLOR_ATTACHMENT15
);
4742 WINED3D_TO_STR(GL_DEPTH_ATTACHMENT
);
4743 WINED3D_TO_STR(GL_STENCIL_ATTACHMENT
);
4744 #undef WINED3D_TO_STR
4746 return wine_dbg_sprintf("Unknown FBO attachment %#x", attachment
);
4750 const char *debug_fbostatus(GLenum status
) {
4752 #define FBOSTATUS_TO_STR(u) case u: return #u
4753 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE
);
4754 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
);
4755 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
);
4756 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
);
4757 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
);
4758 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
);
4759 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
);
4760 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
);
4761 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
);
4762 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB
);
4763 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED
);
4764 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED
);
4765 #undef FBOSTATUS_TO_STR
4767 FIXME("Unrecognized FBO status 0x%08x.\n", status
);
4768 return "unrecognized";
4772 const char *debug_glerror(GLenum error
) {
4774 #define GLERROR_TO_STR(u) case u: return #u
4775 GLERROR_TO_STR(GL_NO_ERROR
);
4776 GLERROR_TO_STR(GL_INVALID_ENUM
);
4777 GLERROR_TO_STR(GL_INVALID_VALUE
);
4778 GLERROR_TO_STR(GL_INVALID_OPERATION
);
4779 GLERROR_TO_STR(GL_STACK_OVERFLOW
);
4780 GLERROR_TO_STR(GL_STACK_UNDERFLOW
);
4781 GLERROR_TO_STR(GL_OUT_OF_MEMORY
);
4782 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION
);
4783 #undef GLERROR_TO_STR
4785 FIXME("Unrecognized GL error 0x%08x.\n", error
);
4786 return "unrecognized";
4790 static const char *debug_fixup_channel_source(enum fixup_channel_source source
)
4794 #define WINED3D_TO_STR(x) case x: return #x
4795 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO
);
4796 WINED3D_TO_STR(CHANNEL_SOURCE_ONE
);
4797 WINED3D_TO_STR(CHANNEL_SOURCE_X
);
4798 WINED3D_TO_STR(CHANNEL_SOURCE_Y
);
4799 WINED3D_TO_STR(CHANNEL_SOURCE_Z
);
4800 WINED3D_TO_STR(CHANNEL_SOURCE_W
);
4801 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0
);
4802 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1
);
4803 #undef WINED3D_TO_STR
4805 FIXME("Unrecognized fixup_channel_source %#x\n", source
);
4806 return "unrecognized";
4810 static const char *debug_complex_fixup(enum complex_fixup fixup
)
4814 #define WINED3D_TO_STR(x) case x: return #x
4815 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2
);
4816 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY
);
4817 WINED3D_TO_STR(COMPLEX_FIXUP_YV12
);
4818 WINED3D_TO_STR(COMPLEX_FIXUP_NV12
);
4819 WINED3D_TO_STR(COMPLEX_FIXUP_P8
);
4820 #undef WINED3D_TO_STR
4822 FIXME("Unrecognized complex fixup %#x\n", fixup
);
4823 return "unrecognized";
4827 void dump_color_fixup_desc(struct color_fixup_desc fixup
)
4829 if (is_complex_fixup(fixup
))
4831 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup
)));
4835 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup
.x_source
), fixup
.x_sign_fixup
? ", SIGN_FIXUP" : "");
4836 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup
.y_source
), fixup
.y_sign_fixup
? ", SIGN_FIXUP" : "");
4837 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup
.z_source
), fixup
.z_sign_fixup
? ", SIGN_FIXUP" : "");
4838 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup
.w_source
), fixup
.w_sign_fixup
? ", SIGN_FIXUP" : "");
4841 BOOL
is_invalid_op(const struct wined3d_state
*state
, int stage
,
4842 enum wined3d_texture_op op
, DWORD arg1
, DWORD arg2
, DWORD arg3
)
4844 if (op
== WINED3D_TOP_DISABLE
)
4846 if (state
->textures
[stage
])
4849 if ((arg1
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
4850 && op
!= WINED3D_TOP_SELECT_ARG2
)
4852 if ((arg2
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
4853 && op
!= WINED3D_TOP_SELECT_ARG1
)
4855 if ((arg3
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
4856 && (op
== WINED3D_TOP_MULTIPLY_ADD
|| op
== WINED3D_TOP_LERP
))
4862 void get_identity_matrix(struct wined3d_matrix
*mat
)
4864 static const struct wined3d_matrix identity
=
4866 1.0f
, 0.0f
, 0.0f
, 0.0f
,
4867 0.0f
, 1.0f
, 0.0f
, 0.0f
,
4868 0.0f
, 0.0f
, 1.0f
, 0.0f
,
4869 0.0f
, 0.0f
, 0.0f
, 1.0f
,
4875 void get_modelview_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4876 unsigned int index
, struct wined3d_matrix
*mat
)
4878 if (context
->last_was_rhw
)
4879 get_identity_matrix(mat
);
4881 multiply_matrix(mat
, &state
->transforms
[WINED3D_TS_VIEW
], &state
->transforms
[WINED3D_TS_WORLD_MATRIX(index
)]);
4884 void get_projection_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4885 struct wined3d_matrix
*mat
)
4887 BOOL clip_control
= context
->gl_info
->supported
[ARB_CLIP_CONTROL
];
4888 BOOL flip
= !clip_control
&& context
->render_offscreen
;
4889 float center_offset
;
4891 /* There are a couple of additional things we have to take into account
4892 * here besides the projection transformation itself:
4893 * - We need to flip along the y-axis in case of offscreen rendering.
4894 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
4895 * - <= D3D9 coordinates refer to pixel centers while GL coordinates
4896 * refer to pixel corners.
4897 * - D3D has a top-left filling convention. We need to maintain this
4898 * even after the y-flip mentioned above.
4899 * In order to handle the last two points, we translate by
4900 * (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to
4901 * translating slightly less than half a pixel. We want the difference to
4902 * be large enough that it doesn't get lost due to rounding inside the
4903 * driver, but small enough to prevent it from interfering with any
4906 if (!clip_control
&& context
->d3d_info
->wined3d_creation_flags
& WINED3D_PIXEL_CENTER_INTEGER
)
4907 center_offset
= 63.0f
/ 64.0f
;
4909 center_offset
= -1.0f
/ 64.0f
;
4911 if (context
->last_was_rhw
)
4913 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
4914 float x
= state
->viewport
.x
;
4915 float y
= state
->viewport
.y
;
4916 float w
= state
->viewport
.width
;
4917 float h
= state
->viewport
.height
;
4918 float x_scale
= 2.0f
/ w
;
4919 float x_offset
= (center_offset
- (2.0f
* x
) - w
) / w
;
4920 float y_scale
= flip
? 2.0f
/ h
: 2.0f
/ -h
;
4921 float y_offset
= flip
4922 ? (center_offset
- (2.0f
* y
) - h
) / h
4923 : (center_offset
- (2.0f
* y
) - h
) / -h
;
4924 enum wined3d_depth_buffer_type zenable
= state
->fb
->depth_stencil
?
4925 state
->render_states
[WINED3D_RS_ZENABLE
] : WINED3D_ZB_FALSE
;
4926 float z_scale
= zenable
? clip_control
? 1.0f
: 2.0f
: 0.0f
;
4927 float z_offset
= zenable
? clip_control
? 0.0f
: -1.0f
: 0.0f
;
4928 const struct wined3d_matrix projection
=
4930 x_scale
, 0.0f
, 0.0f
, 0.0f
,
4931 0.0f
, y_scale
, 0.0f
, 0.0f
,
4932 0.0f
, 0.0f
, z_scale
, 0.0f
,
4933 x_offset
, y_offset
, z_offset
, 1.0f
,
4940 float y_scale
= flip
? -1.0f
: 1.0f
;
4941 float x_offset
= center_offset
/ state
->viewport
.width
;
4942 float y_offset
= flip
4943 ? center_offset
/ state
->viewport
.height
4944 : -center_offset
/ state
->viewport
.height
;
4945 float z_scale
= clip_control
? 1.0f
: 2.0f
;
4946 float z_offset
= clip_control
? 0.0f
: -1.0f
;
4947 const struct wined3d_matrix projection
=
4949 1.0f
, 0.0f
, 0.0f
, 0.0f
,
4950 0.0f
, y_scale
, 0.0f
, 0.0f
,
4951 0.0f
, 0.0f
, z_scale
, 0.0f
,
4952 x_offset
, y_offset
, z_offset
, 1.0f
,
4955 multiply_matrix(mat
, &projection
, &state
->transforms
[WINED3D_TS_PROJECTION
]);
4959 /* Setup this textures matrix according to the texture flags. */
4960 static void compute_texture_matrix(const struct wined3d_gl_info
*gl_info
, const struct wined3d_matrix
*matrix
,
4961 DWORD flags
, BOOL calculated_coords
, BOOL transformed
, enum wined3d_format_id format_id
,
4962 BOOL ffp_proj_control
, struct wined3d_matrix
*out_matrix
)
4964 struct wined3d_matrix mat
;
4966 if (flags
== WINED3D_TTFF_DISABLE
|| flags
== WINED3D_TTFF_COUNT1
|| transformed
)
4968 get_identity_matrix(out_matrix
);
4972 if (flags
== (WINED3D_TTFF_COUNT1
| WINED3D_TTFF_PROJECTED
))
4974 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
4980 if (flags
& WINED3D_TTFF_PROJECTED
)
4982 if (!ffp_proj_control
)
4984 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
4986 case WINED3D_TTFF_COUNT2
:
4991 mat
._12
= mat
._22
= mat
._32
= mat
._42
= 0.0f
;
4993 case WINED3D_TTFF_COUNT3
:
4998 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
5005 /* Under Direct3D the R/Z coord can be used for translation, under
5006 * OpenGL we use the Q coord instead. */
5007 if (!calculated_coords
)
5011 /* Direct3D passes the default 1.0 in the 2nd coord, while GL
5012 * passes it in the 4th. Swap 2nd and 4th coord. No need to
5013 * store the value of mat._41 in mat._21 because the input
5014 * value to the transformation will be 0, so the matrix value
5016 case WINED3DFMT_R32_FLOAT
:
5022 /* See above, just 3rd and 4th coord. */
5023 case WINED3DFMT_R32G32_FLOAT
:
5029 case WINED3DFMT_R32G32B32_FLOAT
: /* Opengl defaults match dx defaults */
5030 case WINED3DFMT_R32G32B32A32_FLOAT
: /* No defaults apply, all app defined */
5032 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
5033 * into a bad place. The division elimination below will apply to make sure the
5034 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
5036 case WINED3DFMT_UNKNOWN
: /* No texture coords, 0/0/0/1 defaults are passed */
5039 FIXME("Unexpected fixed function texture coord input\n");
5042 if (!ffp_proj_control
)
5044 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
5046 /* case WINED3D_TTFF_COUNT1: Won't ever get here. */
5047 case WINED3D_TTFF_COUNT2
:
5048 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
5049 /* OpenGL divides the first 3 vertex coordinates by the 4th by
5050 * default, which is essentially the same as D3DTTFF_PROJECTED.
5051 * Make sure that the 4th coordinate evaluates to 1.0 to
5054 * If the fixed function pipeline is used, the 4th value
5055 * remains unused, so there is no danger in doing this. With
5056 * vertex shaders we have a problem. Should an application hit
5057 * that problem, the code here would have to check for pixel
5058 * shaders, and the shader has to undo the default GL divide.
5060 * A more serious problem occurs if the application passes 4
5061 * coordinates in, and the 4th is != 1.0 (OpenGL default).
5062 * This would have to be fixed with immediate mode draws. */
5064 mat
._14
= mat
._24
= mat
._34
= 0.0f
; mat
._44
= 1.0f
;
5072 void get_texture_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5073 unsigned int tex
, struct wined3d_matrix
*mat
)
5075 const struct wined3d_device
*device
= context
->device
;
5076 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
5077 BOOL generated
= (state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
] & 0xffff0000)
5078 != WINED3DTSS_TCI_PASSTHRU
;
5079 unsigned int coord_idx
= min(state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
& 0x0000ffff],
5082 compute_texture_matrix(gl_info
, &state
->transforms
[WINED3D_TS_TEXTURE0
+ tex
],
5083 state
->texture_states
[tex
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
],
5084 generated
, context
->last_was_rhw
,
5085 context
->stream_info
.use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))
5086 ? context
->stream_info
.elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format
->id
5087 : WINED3DFMT_UNKNOWN
,
5088 device
->shader_backend
->shader_has_ffp_proj_control(device
->shader_priv
), mat
);
5090 if ((context
->lastWasPow2Texture
& (1u << tex
)) && state
->textures
[tex
])
5093 FIXME("Non-power-of-two texture being used with generated texture coords.\n");
5094 /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
5095 * fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
5098 TRACE("Non-power-of-two texture matrix multiply fixup.\n");
5099 multiply_matrix(mat
, mat
, (struct wined3d_matrix
*)state
->textures
[tex
]->pow2_matrix
);
5104 void get_pointsize_minmax(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5105 float *out_min
, float *out_max
)
5113 min
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MIN
];
5114 max
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MAX
];
5123 void get_pointsize(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5124 float *out_pointsize
, float *out_att
)
5126 /* POINTSCALEENABLE controls how point size value is treated. If set to
5127 * true, the point size is scaled with respect to height of viewport.
5128 * When set to false point size is in pixels. */
5133 } pointsize
, a
, b
, c
;
5139 pointsize
.d
= state
->render_states
[WINED3D_RS_POINTSIZE
];
5140 a
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_A
];
5141 b
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_B
];
5142 c
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_C
];
5144 if (state
->render_states
[WINED3D_RS_POINTSCALEENABLE
])
5146 float scale_factor
= state
->viewport
.height
* state
->viewport
.height
;
5148 out_att
[0] = a
.f
/ scale_factor
;
5149 out_att
[1] = b
.f
/ scale_factor
;
5150 out_att
[2] = c
.f
/ scale_factor
;
5152 *out_pointsize
= pointsize
.f
;
5155 void get_fog_start_end(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5156 float *start
, float *end
)
5164 switch (context
->fog_source
)
5171 case FOGSOURCE_COORD
:
5177 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGSTART
];
5178 *start
= tmpvalue
.f
;
5179 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGEND
];
5181 /* Special handling for fog_start == fog_end. In d3d with vertex
5182 * fog, everything is fogged. With table fog, everything with
5183 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
5184 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
5185 if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
&& *start
== *end
)
5193 /* This should not happen, context->fog_source is set in wined3d, not the app. */
5194 ERR("Unexpected fog coordinate source.\n");
5200 /* Note: It's the caller's responsibility to ensure values can be expressed
5201 * in the requested format. UNORM formats for example can only express values
5202 * in the range 0.0f -> 1.0f. */
5203 DWORD
wined3d_format_convert_from_float(const struct wined3d_format
*format
, const struct wined3d_color
*color
)
5207 enum wined3d_format_id format_id
;
5208 struct wined3d_vec4 mul
;
5209 struct wined3d_uvec4 shift
;
5213 {WINED3DFMT_B8G8R8A8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, {16, 8, 0, 24}},
5214 {WINED3DFMT_B8G8R8X8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, {16, 8, 0, 24}},
5215 {WINED3DFMT_B8G8R8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, {16, 8, 0, 24}},
5216 {WINED3DFMT_B5G6R5_UNORM
, { 31.0f
, 63.0f
, 31.0f
, 0.0f
}, {11, 5, 0, 0}},
5217 {WINED3DFMT_B5G5R5A1_UNORM
, { 31.0f
, 31.0f
, 31.0f
, 1.0f
}, {10, 5, 0, 15}},
5218 {WINED3DFMT_B5G5R5X1_UNORM
, { 31.0f
, 31.0f
, 31.0f
, 1.0f
}, {10, 5, 0, 15}},
5219 {WINED3DFMT_R8_UNORM
, { 255.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
5220 {WINED3DFMT_A8_UNORM
, { 0.0f
, 0.0f
, 0.0f
, 255.0f
}, { 0, 0, 0, 0}},
5221 {WINED3DFMT_B4G4R4A4_UNORM
, { 15.0f
, 15.0f
, 15.0f
, 15.0f
}, { 8, 4, 0, 12}},
5222 {WINED3DFMT_B4G4R4X4_UNORM
, { 15.0f
, 15.0f
, 15.0f
, 15.0f
}, { 8, 4, 0, 12}},
5223 {WINED3DFMT_B2G3R3_UNORM
, { 7.0f
, 7.0f
, 3.0f
, 0.0f
}, { 5, 2, 0, 0}},
5224 {WINED3DFMT_R8G8B8A8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, { 0, 8, 16, 24}},
5225 {WINED3DFMT_R8G8B8X8_UNORM
, { 255.0f
, 255.0f
, 255.0f
, 255.0f
}, { 0, 8, 16, 24}},
5226 {WINED3DFMT_B10G10R10A2_UNORM
, { 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
}, {20, 10, 0, 30}},
5227 {WINED3DFMT_R10G10B10A2_UNORM
, { 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
}, { 0, 10, 20, 30}},
5228 {WINED3DFMT_P8_UINT
, { 0.0f
, 0.0f
, 0.0f
, 255.0f
}, { 0, 0, 0, 0}},
5229 {WINED3DFMT_S1_UINT_D15_UNORM
, { 32767.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
5230 {WINED3DFMT_D16_UNORM
, { 65535.0f
, 0.0f
, 0.0f
, 0.0f
}, { 0, 0, 0, 0}},
5234 enum wined3d_format_id format_id
;
5235 struct wined3d_dvec4 mul
;
5236 struct wined3d_uvec4 shift
;
5240 {WINED3DFMT_D24_UNORM_S8_UINT
, { 16777215.0, 1.0, 0.0, 0.0}, {8, 0, 0, 0}},
5241 {WINED3DFMT_X8D24_UNORM
, { 16777215.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
5242 {WINED3DFMT_D32_UNORM
, {4294967295.0, 0.0, 0.0, 0.0}, {0, 0, 0, 0}},
5247 TRACE("Converting color %s to format %s.\n", debug_color(color
), debug_d3dformat(format
->id
));
5249 for (i
= 0; i
< ARRAY_SIZE(float_conv
); ++i
)
5251 if (format
->id
!= float_conv
[i
].format_id
)
5254 ret
= ((DWORD
)((color
->r
* float_conv
[i
].mul
.x
) + 0.5f
)) << float_conv
[i
].shift
.x
;
5255 ret
|= ((DWORD
)((color
->g
* float_conv
[i
].mul
.y
) + 0.5f
)) << float_conv
[i
].shift
.y
;
5256 ret
|= ((DWORD
)((color
->b
* float_conv
[i
].mul
.z
) + 0.5f
)) << float_conv
[i
].shift
.z
;
5257 ret
|= ((DWORD
)((color
->a
* float_conv
[i
].mul
.w
) + 0.5f
)) << float_conv
[i
].shift
.w
;
5259 TRACE("Returning 0x%08x.\n", ret
);
5264 for (i
= 0; i
< ARRAY_SIZE(double_conv
); ++i
)
5266 if (format
->id
!= double_conv
[i
].format_id
)
5269 ret
= ((DWORD
)((color
->r
* double_conv
[i
].mul
.x
) + 0.5)) << double_conv
[i
].shift
.x
;
5270 ret
|= ((DWORD
)((color
->g
* double_conv
[i
].mul
.y
) + 0.5)) << double_conv
[i
].shift
.y
;
5271 ret
|= ((DWORD
)((color
->b
* double_conv
[i
].mul
.z
) + 0.5)) << double_conv
[i
].shift
.z
;
5272 ret
|= ((DWORD
)((color
->a
* double_conv
[i
].mul
.w
) + 0.5)) << double_conv
[i
].shift
.w
;
5274 TRACE("Returning 0x%08x.\n", ret
);
5279 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format
->id
));
5284 static float color_to_float(DWORD color
, DWORD size
, DWORD offset
)
5286 DWORD mask
= size
< 32 ? (1u << size
) - 1 : ~0u;
5294 return (float)color
/ (float)mask
;
5297 void wined3d_format_get_float_color_key(const struct wined3d_format
*format
,
5298 const struct wined3d_color_key
*key
, struct wined3d_color
*float_colors
)
5300 struct wined3d_color slop
;
5304 case WINED3DFMT_B8G8R8_UNORM
:
5305 case WINED3DFMT_B8G8R8A8_UNORM
:
5306 case WINED3DFMT_B8G8R8X8_UNORM
:
5307 case WINED3DFMT_B5G6R5_UNORM
:
5308 case WINED3DFMT_B5G5R5X1_UNORM
:
5309 case WINED3DFMT_B5G5R5A1_UNORM
:
5310 case WINED3DFMT_B4G4R4A4_UNORM
:
5311 case WINED3DFMT_B2G3R3_UNORM
:
5312 case WINED3DFMT_R8_UNORM
:
5313 case WINED3DFMT_A8_UNORM
:
5314 case WINED3DFMT_B2G3R3A8_UNORM
:
5315 case WINED3DFMT_B4G4R4X4_UNORM
:
5316 case WINED3DFMT_R10G10B10A2_UNORM
:
5317 case WINED3DFMT_R10G10B10A2_SNORM
:
5318 case WINED3DFMT_R8G8B8A8_UNORM
:
5319 case WINED3DFMT_R8G8B8X8_UNORM
:
5320 case WINED3DFMT_R16G16_UNORM
:
5321 case WINED3DFMT_B10G10R10A2_UNORM
:
5322 slop
.r
= 0.5f
/ ((1u << format
->red_size
) - 1);
5323 slop
.g
= 0.5f
/ ((1u << format
->green_size
) - 1);
5324 slop
.b
= 0.5f
/ ((1u << format
->blue_size
) - 1);
5325 slop
.a
= 0.5f
/ ((1u << format
->alpha_size
) - 1);
5327 float_colors
[0].r
= color_to_float(key
->color_space_low_value
, format
->red_size
, format
->red_offset
)
5329 float_colors
[0].g
= color_to_float(key
->color_space_low_value
, format
->green_size
, format
->green_offset
)
5331 float_colors
[0].b
= color_to_float(key
->color_space_low_value
, format
->blue_size
, format
->blue_offset
)
5333 float_colors
[0].a
= color_to_float(key
->color_space_low_value
, format
->alpha_size
, format
->alpha_offset
)
5336 float_colors
[1].r
= color_to_float(key
->color_space_high_value
, format
->red_size
, format
->red_offset
)
5338 float_colors
[1].g
= color_to_float(key
->color_space_high_value
, format
->green_size
, format
->green_offset
)
5340 float_colors
[1].b
= color_to_float(key
->color_space_high_value
, format
->blue_size
, format
->blue_offset
)
5342 float_colors
[1].a
= color_to_float(key
->color_space_high_value
, format
->alpha_size
, format
->alpha_offset
)
5346 case WINED3DFMT_P8_UINT
:
5347 float_colors
[0].r
= 0.0f
;
5348 float_colors
[0].g
= 0.0f
;
5349 float_colors
[0].b
= 0.0f
;
5350 float_colors
[0].a
= (key
->color_space_low_value
- 0.5f
) / 255.0f
;
5352 float_colors
[1].r
= 0.0f
;
5353 float_colors
[1].g
= 0.0f
;
5354 float_colors
[1].b
= 0.0f
;
5355 float_colors
[1].a
= (key
->color_space_high_value
+ 0.5f
) / 255.0f
;
5359 ERR("Unhandled color key to float conversion for format %s.\n", debug_d3dformat(format
->id
));
5363 /* DirectDraw stuff */
5364 enum wined3d_format_id
pixelformat_for_depth(DWORD depth
)
5368 case 8: return WINED3DFMT_P8_UINT
;
5369 case 15: return WINED3DFMT_B5G5R5X1_UNORM
;
5370 case 16: return WINED3DFMT_B5G6R5_UNORM
;
5371 case 24: return WINED3DFMT_B8G8R8X8_UNORM
; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
5372 case 32: return WINED3DFMT_B8G8R8X8_UNORM
; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
5373 default: return WINED3DFMT_UNKNOWN
;
5377 void multiply_matrix(struct wined3d_matrix
*dst
, const struct wined3d_matrix
*src1
, const struct wined3d_matrix
*src2
)
5379 struct wined3d_matrix tmp
;
5381 /* Now do the multiplication 'by hand'.
5382 I know that all this could be optimised, but this will be done later :-) */
5383 tmp
._11
= (src1
->_11
* src2
->_11
) + (src1
->_21
* src2
->_12
) + (src1
->_31
* src2
->_13
) + (src1
->_41
* src2
->_14
);
5384 tmp
._21
= (src1
->_11
* src2
->_21
) + (src1
->_21
* src2
->_22
) + (src1
->_31
* src2
->_23
) + (src1
->_41
* src2
->_24
);
5385 tmp
._31
= (src1
->_11
* src2
->_31
) + (src1
->_21
* src2
->_32
) + (src1
->_31
* src2
->_33
) + (src1
->_41
* src2
->_34
);
5386 tmp
._41
= (src1
->_11
* src2
->_41
) + (src1
->_21
* src2
->_42
) + (src1
->_31
* src2
->_43
) + (src1
->_41
* src2
->_44
);
5388 tmp
._12
= (src1
->_12
* src2
->_11
) + (src1
->_22
* src2
->_12
) + (src1
->_32
* src2
->_13
) + (src1
->_42
* src2
->_14
);
5389 tmp
._22
= (src1
->_12
* src2
->_21
) + (src1
->_22
* src2
->_22
) + (src1
->_32
* src2
->_23
) + (src1
->_42
* src2
->_24
);
5390 tmp
._32
= (src1
->_12
* src2
->_31
) + (src1
->_22
* src2
->_32
) + (src1
->_32
* src2
->_33
) + (src1
->_42
* src2
->_34
);
5391 tmp
._42
= (src1
->_12
* src2
->_41
) + (src1
->_22
* src2
->_42
) + (src1
->_32
* src2
->_43
) + (src1
->_42
* src2
->_44
);
5393 tmp
._13
= (src1
->_13
* src2
->_11
) + (src1
->_23
* src2
->_12
) + (src1
->_33
* src2
->_13
) + (src1
->_43
* src2
->_14
);
5394 tmp
._23
= (src1
->_13
* src2
->_21
) + (src1
->_23
* src2
->_22
) + (src1
->_33
* src2
->_23
) + (src1
->_43
* src2
->_24
);
5395 tmp
._33
= (src1
->_13
* src2
->_31
) + (src1
->_23
* src2
->_32
) + (src1
->_33
* src2
->_33
) + (src1
->_43
* src2
->_34
);
5396 tmp
._43
= (src1
->_13
* src2
->_41
) + (src1
->_23
* src2
->_42
) + (src1
->_33
* src2
->_43
) + (src1
->_43
* src2
->_44
);
5398 tmp
._14
= (src1
->_14
* src2
->_11
) + (src1
->_24
* src2
->_12
) + (src1
->_34
* src2
->_13
) + (src1
->_44
* src2
->_14
);
5399 tmp
._24
= (src1
->_14
* src2
->_21
) + (src1
->_24
* src2
->_22
) + (src1
->_34
* src2
->_23
) + (src1
->_44
* src2
->_24
);
5400 tmp
._34
= (src1
->_14
* src2
->_31
) + (src1
->_24
* src2
->_32
) + (src1
->_34
* src2
->_33
) + (src1
->_44
* src2
->_34
);
5401 tmp
._44
= (src1
->_14
* src2
->_41
) + (src1
->_24
* src2
->_42
) + (src1
->_34
* src2
->_43
) + (src1
->_44
* src2
->_44
);
5406 DWORD
get_flexible_vertex_size(DWORD d3dvtVertexType
) {
5409 int numTextures
= (d3dvtVertexType
& WINED3DFVF_TEXCOUNT_MASK
) >> WINED3DFVF_TEXCOUNT_SHIFT
;
5411 if (d3dvtVertexType
& WINED3DFVF_NORMAL
) size
+= 3 * sizeof(float);
5412 if (d3dvtVertexType
& WINED3DFVF_DIFFUSE
) size
+= sizeof(DWORD
);
5413 if (d3dvtVertexType
& WINED3DFVF_SPECULAR
) size
+= sizeof(DWORD
);
5414 if (d3dvtVertexType
& WINED3DFVF_PSIZE
) size
+= sizeof(DWORD
);
5415 switch (d3dvtVertexType
& WINED3DFVF_POSITION_MASK
) {
5416 case WINED3DFVF_XYZ
: size
+= 3 * sizeof(float); break;
5417 case WINED3DFVF_XYZRHW
: size
+= 4 * sizeof(float); break;
5418 case WINED3DFVF_XYZB1
: size
+= 4 * sizeof(float); break;
5419 case WINED3DFVF_XYZB2
: size
+= 5 * sizeof(float); break;
5420 case WINED3DFVF_XYZB3
: size
+= 6 * sizeof(float); break;
5421 case WINED3DFVF_XYZB4
: size
+= 7 * sizeof(float); break;
5422 case WINED3DFVF_XYZB5
: size
+= 8 * sizeof(float); break;
5423 case WINED3DFVF_XYZW
: size
+= 4 * sizeof(float); break;
5424 default: ERR("Unexpected position mask\n");
5426 for (i
= 0; i
< numTextures
; i
++) {
5427 size
+= GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType
, i
) * sizeof(float);
5433 unsigned int wined3d_max_compat_varyings(const struct wined3d_gl_info
*gl_info
)
5435 /* On core profile we have to also count diffuse and specular colors and the
5436 * fog coordinate. */
5437 return gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? MAX_TEXTURES
* 4 : (MAX_TEXTURES
+ 2) * 4 + 1;
5440 void gen_ffp_frag_op(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5441 struct ffp_frag_settings
*settings
, BOOL ignore_textype
)
5446 static const unsigned char args
[WINED3D_TOP_LERP
+ 1] =
5449 /* D3DTOP_DISABLE */ 0,
5450 /* D3DTOP_SELECTARG1 */ ARG1
,
5451 /* D3DTOP_SELECTARG2 */ ARG2
,
5452 /* D3DTOP_MODULATE */ ARG1
| ARG2
,
5453 /* D3DTOP_MODULATE2X */ ARG1
| ARG2
,
5454 /* D3DTOP_MODULATE4X */ ARG1
| ARG2
,
5455 /* D3DTOP_ADD */ ARG1
| ARG2
,
5456 /* D3DTOP_ADDSIGNED */ ARG1
| ARG2
,
5457 /* D3DTOP_ADDSIGNED2X */ ARG1
| ARG2
,
5458 /* D3DTOP_SUBTRACT */ ARG1
| ARG2
,
5459 /* D3DTOP_ADDSMOOTH */ ARG1
| ARG2
,
5460 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1
| ARG2
,
5461 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1
| ARG2
,
5462 /* D3DTOP_BLENDFACTORALPHA */ ARG1
| ARG2
,
5463 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1
| ARG2
,
5464 /* D3DTOP_BLENDCURRENTALPHA */ ARG1
| ARG2
,
5465 /* D3DTOP_PREMODULATE */ ARG1
| ARG2
,
5466 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1
| ARG2
,
5467 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1
| ARG2
,
5468 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1
| ARG2
,
5469 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1
| ARG2
,
5470 /* D3DTOP_BUMPENVMAP */ ARG1
| ARG2
,
5471 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1
| ARG2
,
5472 /* D3DTOP_DOTPRODUCT3 */ ARG1
| ARG2
,
5473 /* D3DTOP_MULTIPLYADD */ ARG1
| ARG2
| ARG0
,
5474 /* D3DTOP_LERP */ ARG1
| ARG2
| ARG0
5478 DWORD cop
, aop
, carg0
, carg1
, carg2
, aarg0
, aarg1
, aarg2
;
5479 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
5480 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
5482 settings
->padding
= 0;
5484 for (i
= 0; i
< d3d_info
->limits
.ffp_blend_stages
; ++i
)
5486 const struct wined3d_texture
*texture
;
5488 settings
->op
[i
].padding
= 0;
5489 if (state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
] == WINED3D_TOP_DISABLE
)
5491 settings
->op
[i
].cop
= WINED3D_TOP_DISABLE
;
5492 settings
->op
[i
].aop
= WINED3D_TOP_DISABLE
;
5493 settings
->op
[i
].carg0
= settings
->op
[i
].carg1
= settings
->op
[i
].carg2
= ARG_UNUSED
;
5494 settings
->op
[i
].aarg0
= settings
->op
[i
].aarg1
= settings
->op
[i
].aarg2
= ARG_UNUSED
;
5495 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
5496 settings
->op
[i
].dst
= resultreg
;
5497 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
5498 settings
->op
[i
].projected
= proj_none
;
5503 if ((texture
= state
->textures
[i
]))
5505 if (can_use_texture_swizzle(gl_info
, texture
->resource
.format
))
5506 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
5508 settings
->op
[i
].color_fixup
= texture
->resource
.format
->color_fixup
;
5511 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
5515 switch (texture
->target
)
5518 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
5521 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_2D
;
5524 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_3D
;
5526 case GL_TEXTURE_CUBE_MAP_ARB
:
5527 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_CUBE
;
5529 case GL_TEXTURE_RECTANGLE_ARB
:
5530 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_RECT
;
5535 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
5536 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
5539 cop
= state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
];
5540 aop
= state
->texture_states
[i
][WINED3D_TSS_ALPHA_OP
];
5542 carg1
= (args
[cop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG1
] : ARG_UNUSED
;
5543 carg2
= (args
[cop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG2
] : ARG_UNUSED
;
5544 carg0
= (args
[cop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG0
] : ARG_UNUSED
;
5546 if (is_invalid_op(state
, i
, cop
, carg1
, carg2
, carg0
))
5550 carg1
= WINED3DTA_CURRENT
;
5551 cop
= WINED3D_TOP_SELECT_ARG1
;
5554 if (cop
== WINED3D_TOP_DOTPRODUCT3
)
5556 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
5557 * the color result to the alpha component of the destination
5566 aarg1
= (args
[aop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG1
] : ARG_UNUSED
;
5567 aarg2
= (args
[aop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG2
] : ARG_UNUSED
;
5568 aarg0
= (args
[aop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG0
] : ARG_UNUSED
;
5571 if (!i
&& state
->textures
[0] && state
->render_states
[WINED3D_RS_COLORKEYENABLE
])
5573 GLenum texture_dimensions
;
5575 texture
= state
->textures
[0];
5576 texture_dimensions
= texture
->target
;
5578 if (texture_dimensions
== GL_TEXTURE_2D
|| texture_dimensions
== GL_TEXTURE_RECTANGLE_ARB
)
5580 if (texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
&& !texture
->resource
.format
->alpha_size
)
5582 if (aop
== WINED3D_TOP_DISABLE
)
5584 aarg1
= WINED3DTA_TEXTURE
;
5585 aop
= WINED3D_TOP_SELECT_ARG1
;
5587 else if (aop
== WINED3D_TOP_SELECT_ARG1
&& aarg1
!= WINED3DTA_TEXTURE
)
5589 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
])
5591 aarg2
= WINED3DTA_TEXTURE
;
5592 aop
= WINED3D_TOP_MODULATE
;
5594 else aarg1
= WINED3DTA_TEXTURE
;
5596 else if (aop
== WINED3D_TOP_SELECT_ARG2
&& aarg2
!= WINED3DTA_TEXTURE
)
5598 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
])
5600 aarg1
= WINED3DTA_TEXTURE
;
5601 aop
= WINED3D_TOP_MODULATE
;
5603 else aarg2
= WINED3DTA_TEXTURE
;
5609 if (is_invalid_op(state
, i
, aop
, aarg1
, aarg2
, aarg0
))
5613 aarg1
= WINED3DTA_CURRENT
;
5614 aop
= WINED3D_TOP_SELECT_ARG1
;
5617 if (carg1
== WINED3DTA_TEXTURE
|| carg2
== WINED3DTA_TEXTURE
|| carg0
== WINED3DTA_TEXTURE
5618 || aarg1
== WINED3DTA_TEXTURE
|| aarg2
== WINED3DTA_TEXTURE
|| aarg0
== WINED3DTA_TEXTURE
)
5620 ttff
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
5621 if (ttff
== (WINED3D_TTFF_PROJECTED
| WINED3D_TTFF_COUNT3
))
5622 settings
->op
[i
].projected
= proj_count3
;
5623 else if (ttff
& WINED3D_TTFF_PROJECTED
)
5624 settings
->op
[i
].projected
= proj_count4
;
5626 settings
->op
[i
].projected
= proj_none
;
5630 settings
->op
[i
].projected
= proj_none
;
5633 settings
->op
[i
].cop
= cop
;
5634 settings
->op
[i
].aop
= aop
;
5635 settings
->op
[i
].carg0
= carg0
;
5636 settings
->op
[i
].carg1
= carg1
;
5637 settings
->op
[i
].carg2
= carg2
;
5638 settings
->op
[i
].aarg0
= aarg0
;
5639 settings
->op
[i
].aarg1
= aarg1
;
5640 settings
->op
[i
].aarg2
= aarg2
;
5642 if (state
->texture_states
[i
][WINED3D_TSS_RESULT_ARG
] == WINED3DTA_TEMP
)
5643 settings
->op
[i
].dst
= tempreg
;
5645 settings
->op
[i
].dst
= resultreg
;
5648 /* Clear unsupported stages */
5649 for(; i
< MAX_TEXTURES
; i
++) {
5650 memset(&settings
->op
[i
], 0xff, sizeof(settings
->op
[i
]));
5653 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
5655 settings
->fog
= WINED3D_FFP_PS_FOG_OFF
;
5657 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
)
5659 if (use_vs(state
) || state
->vertex_declaration
->position_transformed
)
5661 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
5665 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
5667 case WINED3D_FOG_NONE
:
5668 case WINED3D_FOG_LINEAR
:
5669 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
5671 case WINED3D_FOG_EXP
:
5672 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
5674 case WINED3D_FOG_EXP2
:
5675 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
5682 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
5684 case WINED3D_FOG_LINEAR
:
5685 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
5687 case WINED3D_FOG_EXP
:
5688 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
5690 case WINED3D_FOG_EXP2
:
5691 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
5695 settings
->sRGB_write
= !gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && needs_srgb_write(context
, state
, state
->fb
);
5696 if (d3d_info
->vs_clipping
|| !use_vs(state
) || !state
->render_states
[WINED3D_RS_CLIPPING
]
5697 || !state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
])
5699 /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
5700 * the fixed function vertex pipeline is used(which always supports clipplanes), or
5701 * if no clipplane is enabled
5703 settings
->emul_clipplanes
= 0;
5705 settings
->emul_clipplanes
= 1;
5708 if (state
->render_states
[WINED3D_RS_COLORKEYENABLE
] && state
->textures
[0]
5709 && state
->textures
[0]->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
5710 && settings
->op
[0].cop
!= WINED3D_TOP_DISABLE
)
5711 settings
->color_key_enabled
= 1;
5713 settings
->color_key_enabled
= 0;
5715 /* texcoords_initialized is set to meaningful values only when GL doesn't
5716 * support enough varyings to always pass around all the possible texture
5718 * This is used to avoid reading a varying not written by the vertex shader.
5719 * Reading uninitialized varyings on core profile contexts results in an
5720 * error while with builtin varyings on legacy contexts you get undefined
5722 if (d3d_info
->limits
.varying_count
5723 && d3d_info
->limits
.varying_count
< wined3d_max_compat_varyings(gl_info
))
5725 settings
->texcoords_initialized
= 0;
5726 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
5730 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
5731 settings
->texcoords_initialized
|= 1u << i
;
5735 const struct wined3d_stream_info
*si
= &context
->stream_info
;
5736 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5737 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
5738 & WINED3D_FFP_TCI_MASK
5739 || (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
5740 settings
->texcoords_initialized
|= 1u << i
;
5746 settings
->texcoords_initialized
= (1u << MAX_TEXTURES
) - 1;
5749 settings
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
5750 && state
->gl_primitive_type
== GL_POINTS
;
5752 if (gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
5753 settings
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
5755 settings
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
5756 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
5757 : WINED3D_CMP_ALWAYS
) - 1;
5759 if (d3d_info
->emulated_flatshading
)
5760 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
5762 settings
->flatshading
= FALSE
;
5765 const struct ffp_frag_desc
*find_ffp_frag_shader(const struct wine_rb_tree
*fragment_shaders
,
5766 const struct ffp_frag_settings
*settings
)
5768 struct wine_rb_entry
*entry
= wine_rb_get(fragment_shaders
, settings
);
5769 return entry
? WINE_RB_ENTRY_VALUE(entry
, struct ffp_frag_desc
, entry
) : NULL
;
5772 void add_ffp_frag_shader(struct wine_rb_tree
*shaders
, struct ffp_frag_desc
*desc
)
5774 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
5775 * whereas desc points to an extended structure with implementation specific parts. */
5776 if (wine_rb_put(shaders
, &desc
->settings
, &desc
->entry
) == -1)
5778 ERR("Failed to insert ffp frag shader.\n");
5782 /* Activates the texture dimension according to the bound D3D texture. Does
5783 * not care for the colorop or correct gl texture unit (when using nvrc).
5784 * Requires the caller to activate the correct unit. */
5785 /* Context activation is done by the caller (state handler). */
5786 void texture_activate_dimensions(const struct wined3d_texture
*texture
, const struct wined3d_gl_info
*gl_info
)
5790 switch (texture
->target
)
5793 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5794 checkGLcall("glDisable(GL_TEXTURE_3D)");
5795 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5797 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5798 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5800 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5802 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5803 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5805 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
5806 checkGLcall("glEnable(GL_TEXTURE_2D)");
5808 case GL_TEXTURE_RECTANGLE_ARB
:
5809 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
5810 checkGLcall("glDisable(GL_TEXTURE_2D)");
5811 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5812 checkGLcall("glDisable(GL_TEXTURE_3D)");
5813 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5815 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5816 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5818 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_RECTANGLE_ARB
);
5819 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
5822 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5824 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5825 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5827 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5829 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5830 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5832 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
5833 checkGLcall("glDisable(GL_TEXTURE_2D)");
5834 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_3D
);
5835 checkGLcall("glEnable(GL_TEXTURE_3D)");
5837 case GL_TEXTURE_CUBE_MAP_ARB
:
5838 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
5839 checkGLcall("glDisable(GL_TEXTURE_2D)");
5840 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5841 checkGLcall("glDisable(GL_TEXTURE_3D)");
5842 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5844 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5845 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5847 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
5848 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
5854 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
5855 checkGLcall("glEnable(GL_TEXTURE_2D)");
5856 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5857 checkGLcall("glDisable(GL_TEXTURE_3D)");
5858 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5860 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5861 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5863 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5865 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5866 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5868 /* Binding textures is done by samplers. A dummy texture will be bound */
5872 /* Context activation is done by the caller (state handler). */
5873 void sampler_texdim(struct wined3d_context
*context
, const struct wined3d_state
*state
, DWORD state_id
)
5875 DWORD sampler
= state_id
- STATE_SAMPLER(0);
5876 DWORD mapped_stage
= context
->tex_unit_map
[sampler
];
5878 /* No need to enable / disable anything here for unused samplers. The
5879 * tex_colorop handler takes care. Also no action is needed with pixel
5880 * shaders, or if tex_colorop will take care of this business. */
5881 if (mapped_stage
== WINED3D_UNMAPPED_STAGE
|| mapped_stage
>= context
->gl_info
->limits
.textures
)
5883 if (sampler
>= context
->lowest_disabled_stage
)
5885 if (isStateDirty(context
, STATE_TEXTURESTAGE(sampler
, WINED3D_TSS_COLOR_OP
)))
5888 texture_activate_dimensions(state
->textures
[sampler
], context
->gl_info
);
5891 int wined3d_ffp_frag_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
5893 const struct ffp_frag_settings
*ka
= key
;
5894 const struct ffp_frag_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
, const struct ffp_frag_desc
, entry
)->settings
;
5896 return memcmp(ka
, kb
, sizeof(*ka
));
5899 void wined3d_ffp_get_vs_settings(const struct wined3d_context
*context
,
5900 const struct wined3d_state
*state
, struct wined3d_ffp_vs_settings
*settings
)
5902 const struct wined3d_stream_info
*si
= &context
->stream_info
;
5903 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
5904 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
5905 unsigned int coord_idx
, i
;
5907 memset(settings
, 0, sizeof(*settings
));
5909 if (si
->position_transformed
)
5911 settings
->transformed
= 1;
5912 settings
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
5913 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
5914 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
5915 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
5916 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
5917 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
5919 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
5921 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
5923 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5924 if (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
5925 settings
->texcoords
|= 1u << i
;
5926 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5928 if (d3d_info
->limits
.varying_count
>= wined3d_max_compat_varyings(gl_info
))
5929 settings
->texcoords
= (1u << MAX_TEXTURES
) - 1;
5931 if (d3d_info
->emulated_flatshading
)
5932 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
5934 settings
->flatshading
= FALSE
;
5936 settings
->swizzle_map
= si
->swizzle_map
;
5941 switch (state
->render_states
[WINED3D_RS_VERTEXBLEND
])
5943 case WINED3D_VBF_DISABLE
:
5944 case WINED3D_VBF_1WEIGHTS
:
5945 case WINED3D_VBF_2WEIGHTS
:
5946 case WINED3D_VBF_3WEIGHTS
:
5947 settings
->vertexblends
= state
->render_states
[WINED3D_RS_VERTEXBLEND
];
5950 FIXME("Unsupported vertex blending: %d\n", state
->render_states
[WINED3D_RS_VERTEXBLEND
]);
5954 settings
->clipping
= state
->render_states
[WINED3D_RS_CLIPPING
]
5955 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
5956 settings
->normal
= !!(si
->use_map
& (1u << WINED3D_FFP_NORMAL
));
5957 settings
->normalize
= settings
->normal
&& state
->render_states
[WINED3D_RS_NORMALIZENORMALS
];
5958 settings
->lighting
= !!state
->render_states
[WINED3D_RS_LIGHTING
];
5959 settings
->localviewer
= !!state
->render_states
[WINED3D_RS_LOCALVIEWER
];
5960 settings
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
5961 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
5963 if (state
->render_states
[WINED3D_RS_COLORVERTEX
] && (si
->use_map
& (1u << WINED3D_FFP_DIFFUSE
)))
5965 settings
->diffuse_source
= state
->render_states
[WINED3D_RS_DIFFUSEMATERIALSOURCE
];
5966 settings
->emissive_source
= state
->render_states
[WINED3D_RS_EMISSIVEMATERIALSOURCE
];
5967 settings
->ambient_source
= state
->render_states
[WINED3D_RS_AMBIENTMATERIALSOURCE
];
5968 settings
->specular_source
= state
->render_states
[WINED3D_RS_SPECULARMATERIALSOURCE
];
5972 settings
->diffuse_source
= WINED3D_MCS_MATERIAL
;
5973 settings
->emissive_source
= WINED3D_MCS_MATERIAL
;
5974 settings
->ambient_source
= WINED3D_MCS_MATERIAL
;
5975 settings
->specular_source
= WINED3D_MCS_MATERIAL
;
5978 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
5980 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5981 if (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
5982 settings
->texcoords
|= 1u << i
;
5983 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5985 if (d3d_info
->limits
.varying_count
>= wined3d_max_compat_varyings(gl_info
))
5986 settings
->texcoords
= (1u << MAX_TEXTURES
) - 1;
5988 for (i
= 0; i
< MAX_ACTIVE_LIGHTS
; ++i
)
5990 if (!state
->lights
[i
])
5993 switch (state
->lights
[i
]->OriginalParms
.type
)
5995 case WINED3D_LIGHT_POINT
:
5996 ++settings
->point_light_count
;
5998 case WINED3D_LIGHT_SPOT
:
5999 ++settings
->spot_light_count
;
6001 case WINED3D_LIGHT_DIRECTIONAL
:
6002 ++settings
->directional_light_count
;
6004 case WINED3D_LIGHT_PARALLELPOINT
:
6005 ++settings
->parallel_point_light_count
;
6008 FIXME("Unhandled light type %#x.\n", state
->lights
[i
]->OriginalParms
.type
);
6013 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
6014 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
6015 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
6017 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6019 if (state
->transforms
[WINED3D_TS_PROJECTION
]._14
== 0.0f
6020 && state
->transforms
[WINED3D_TS_PROJECTION
]._24
== 0.0f
6021 && state
->transforms
[WINED3D_TS_PROJECTION
]._34
== 0.0f
6022 && state
->transforms
[WINED3D_TS_PROJECTION
]._44
== 1.0f
)
6023 settings
->ortho_fog
= 1;
6025 else if (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
] == WINED3D_FOG_NONE
)
6026 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
6027 else if (state
->render_states
[WINED3D_RS_RANGEFOGENABLE
])
6028 settings
->fog_mode
= WINED3D_FFP_VS_FOG_RANGE
;
6030 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
6032 if (d3d_info
->emulated_flatshading
)
6033 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
6035 settings
->flatshading
= FALSE
;
6037 settings
->swizzle_map
= si
->swizzle_map
;
6040 int wined3d_ffp_vertex_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
6042 const struct wined3d_ffp_vs_settings
*ka
= key
;
6043 const struct wined3d_ffp_vs_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
,
6044 const struct wined3d_ffp_vs_desc
, entry
)->settings
;
6046 return memcmp(ka
, kb
, sizeof(*ka
));
6049 const char *wined3d_debug_location(DWORD location
)
6051 struct debug_buffer buffer
;
6052 const char *prefix
= "";
6053 const char *suffix
= "";
6055 if (wined3d_popcount(location
) > 16)
6058 location
= ~location
;
6062 init_debug_buffer(&buffer
, "0");
6063 #define LOCATION_TO_STR(x) if (location & x) { debug_append(&buffer, #x, " | "); location &= ~x; }
6064 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED
);
6065 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM
);
6066 LOCATION_TO_STR(WINED3D_LOCATION_USER_MEMORY
);
6067 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER
);
6068 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB
);
6069 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB
);
6070 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE
);
6071 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE
);
6072 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED
);
6073 #undef LOCATION_TO_STR
6075 FIXME("Unrecognized location flag(s) %#x.\n", location
);
6077 return wine_dbg_sprintf("%s%s%s", prefix
, buffer
.str
, suffix
);
6080 /* Print a floating point value with the %.8e format specifier, always using
6081 * '.' as decimal separator. */
6082 void wined3d_ftoa(float value
, char *s
)
6086 if (copysignf(1.0f
, value
) < 0.0f
)
6089 /* Be sure to allocate a buffer of at least 17 characters for the result
6090 as sprintf may return a 3 digit exponent when using the MSVC runtime
6091 instead of a 2 digit exponent. */
6092 sprintf(s
, "%.8e", value
);
6093 if (isfinite(value
))
6097 void wined3d_release_dc(HWND window
, HDC dc
)
6099 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
6100 * However, that's not what actually happens, and there are user32 tests
6101 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
6102 * So explicitly check that the DC belongs to the window, since we want to
6103 * avoid releasing a DC that belongs to some other window if the original
6104 * window was already destroyed. */
6105 if (WindowFromDC(dc
) != window
)
6106 WARN("DC %p does not belong to window %p.\n", dc
, window
);
6107 else if (!ReleaseDC(window
, dc
))
6108 ERR("Failed to release device context %p, last error %#x.\n", dc
, GetLastError());
6111 BOOL
wined3d_clip_blit(const RECT
*clip_rect
, RECT
*clipped
, RECT
*other
)
6113 RECT orig
= *clipped
;
6114 float scale_x
= (float)(orig
.right
- orig
.left
) / (float)(other
->right
- other
->left
);
6115 float scale_y
= (float)(orig
.bottom
- orig
.top
) / (float)(other
->bottom
- other
->top
);
6117 IntersectRect(clipped
, clipped
, clip_rect
);
6119 if (IsRectEmpty(clipped
))
6121 SetRectEmpty(other
);
6125 other
->left
+= (LONG
)((clipped
->left
- orig
.left
) / scale_x
);
6126 other
->top
+= (LONG
)((clipped
->top
- orig
.top
) / scale_y
);
6127 other
->right
-= (LONG
)((orig
.right
- clipped
->right
) / scale_x
);
6128 other
->bottom
-= (LONG
)((orig
.bottom
- clipped
->bottom
) / scale_y
);
6133 void wined3d_gl_limits_get_uniform_block_range(const struct wined3d_gl_limits
*gl_limits
,
6134 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
6139 for (i
= 0; i
< WINED3D_SHADER_TYPE_COUNT
; ++i
)
6141 *count
= gl_limits
->uniform_blocks
[i
];
6142 if (i
== shader_type
)
6147 ERR("Unrecognized shader type %#x.\n", shader_type
);
6151 void wined3d_gl_limits_get_texture_unit_range(const struct wined3d_gl_limits
*gl_limits
,
6152 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
6156 if (shader_type
== WINED3D_SHADER_TYPE_COMPUTE
)
6158 if (gl_limits
->combined_samplers
== gl_limits
->graphics_samplers
)
6161 *base
= gl_limits
->graphics_samplers
;
6162 *count
= gl_limits
->samplers
[WINED3D_SHADER_TYPE_COMPUTE
];
6167 for (i
= 0; i
< WINED3D_SHADER_TYPE_GRAPHICS_COUNT
; ++i
)
6169 *count
= gl_limits
->samplers
[i
];
6170 if (i
== shader_type
)
6175 ERR("Unrecognized shader type %#x.\n", shader_type
);
6179 BOOL
wined3d_array_reserve(void **elements
, SIZE_T
*capacity
, SIZE_T count
, SIZE_T size
)
6181 SIZE_T max_capacity
, new_capacity
;
6184 if (count
<= *capacity
)
6187 max_capacity
= ~(SIZE_T
)0 / size
;
6188 if (count
> max_capacity
)
6191 new_capacity
= max(1, *capacity
);
6192 while (new_capacity
< count
&& new_capacity
<= max_capacity
/ 2)
6194 if (new_capacity
< count
)
6195 new_capacity
= count
;
6198 new_elements
= heap_alloc_zero(new_capacity
* size
);
6200 new_elements
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, *elements
, new_capacity
* size
);
6204 *elements
= new_elements
;
6205 *capacity
= new_capacity
;