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},
153 {WINED3DFMT_R32G32B32A32_TYPELESS
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
154 {WINED3DFMT_R32G32B32_TYPELESS
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
155 {WINED3DFMT_R16G16B16A16_TYPELESS
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
156 {WINED3DFMT_R32G32_TYPELESS
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
157 {WINED3DFMT_R32G8X24_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 8, 32, 8},
158 {WINED3DFMT_R10G10B10A2_TYPELESS
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
159 {WINED3DFMT_R8G8B8A8_TYPELESS
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
160 {WINED3DFMT_R16G16_TYPELESS
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
161 {WINED3DFMT_R32_TYPELESS
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
162 {WINED3DFMT_R24G8_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
163 {WINED3DFMT_R8G8_TYPELESS
, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
164 {WINED3DFMT_R16_TYPELESS
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
165 {WINED3DFMT_R8_TYPELESS
, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
166 {WINED3DFMT_BC1_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
167 {WINED3DFMT_BC2_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
168 {WINED3DFMT_BC3_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
169 {WINED3DFMT_BC4_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
170 {WINED3DFMT_BC5_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
171 {WINED3DFMT_BC6H_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
172 {WINED3DFMT_BC7_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
173 {WINED3DFMT_B8G8R8A8_TYPELESS
, 8, 8, 8, 8, 16, 8, 0, 24, 4, 0, 0},
174 {WINED3DFMT_B8G8R8X8_TYPELESS
, 8, 8, 8, 0, 16, 8, 0, 0, 4, 0, 0},
177 enum wined3d_channel_type
179 WINED3D_CHANNEL_TYPE_NONE
,
180 WINED3D_CHANNEL_TYPE_UNORM
,
181 WINED3D_CHANNEL_TYPE_SNORM
,
182 WINED3D_CHANNEL_TYPE_UINT
,
183 WINED3D_CHANNEL_TYPE_SINT
,
184 WINED3D_CHANNEL_TYPE_FLOAT
,
185 WINED3D_CHANNEL_TYPE_DEPTH
,
186 WINED3D_CHANNEL_TYPE_STENCIL
,
187 WINED3D_CHANNEL_TYPE_UNUSED
,
190 struct wined3d_typed_format_info
192 enum wined3d_format_id id
;
193 enum wined3d_format_id typeless_id
;
194 const char *channels
;
198 * The last entry for a given typeless format defines its internal format.
200 * u - WINED3D_CHANNEL_TYPE_UNORM
201 * i - WINED3D_CHANNEL_TYPE_SNORM
202 * U - WINED3D_CHANNEL_TYPE_UINT
203 * I - WINED3D_CHANNEL_TYPE_SINT
204 * F - WINED3D_CHANNEL_TYPE_FLOAT
205 * D - WINED3D_CHANNEL_TYPE_DEPTH
206 * S - WINED3D_CHANNEL_TYPE_STENCIL
207 * X - WINED3D_CHANNEL_TYPE_UNUSED
209 static const struct wined3d_typed_format_info typed_formats
[] =
211 {WINED3DFMT_R32G32B32A32_UINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "UUUU"},
212 {WINED3DFMT_R32G32B32A32_SINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "IIII"},
213 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "FFFF"},
214 {WINED3DFMT_R32G32B32_UINT
, WINED3DFMT_R32G32B32_TYPELESS
, "UUU"},
215 {WINED3DFMT_R32G32B32_SINT
, WINED3DFMT_R32G32B32_TYPELESS
, "III"},
216 {WINED3DFMT_R32G32B32_FLOAT
, WINED3DFMT_R32G32B32_TYPELESS
, "FFF"},
217 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "uuuu"},
218 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "iiii"},
219 {WINED3DFMT_R16G16B16A16_UINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "UUUU"},
220 {WINED3DFMT_R16G16B16A16_SINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "IIII"},
221 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "FFFF"},
222 {WINED3DFMT_R32G32_UINT
, WINED3DFMT_R32G32_TYPELESS
, "UU"},
223 {WINED3DFMT_R32G32_SINT
, WINED3DFMT_R32G32_TYPELESS
, "II"},
224 {WINED3DFMT_R32G32_FLOAT
, WINED3DFMT_R32G32_TYPELESS
, "FF"},
225 {WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, WINED3DFMT_R32G8X24_TYPELESS
, "DX"},
226 {WINED3DFMT_X32_TYPELESS_G8X24_UINT
, WINED3DFMT_R32G8X24_TYPELESS
, "XS"},
227 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, WINED3DFMT_R32G8X24_TYPELESS
, "DS"},
228 {WINED3DFMT_R10G10B10A2_SNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "iiii"},
229 {WINED3DFMT_R10G10B10A2_UINT
, WINED3DFMT_R10G10B10A2_TYPELESS
, "UUUU"},
230 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "uuuu"},
231 {WINED3DFMT_R8G8B8A8_UINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "UUUU"},
232 {WINED3DFMT_R8G8B8A8_SINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "IIII"},
233 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
234 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
235 {WINED3DFMT_R16G16_UNORM
, WINED3DFMT_R16G16_TYPELESS
, "uu"},
236 {WINED3DFMT_R16G16_SNORM
, WINED3DFMT_R16G16_TYPELESS
, "ii"},
237 {WINED3DFMT_R16G16_UINT
, WINED3DFMT_R16G16_TYPELESS
, "UU"},
238 {WINED3DFMT_R16G16_SINT
, WINED3DFMT_R16G16_TYPELESS
, "II"},
239 {WINED3DFMT_R16G16_FLOAT
, WINED3DFMT_R16G16_TYPELESS
, "FF"},
240 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "D"},
241 {WINED3DFMT_R32_UINT
, WINED3DFMT_R32_TYPELESS
, "U"},
242 {WINED3DFMT_R32_SINT
, WINED3DFMT_R32_TYPELESS
, "I"},
243 {WINED3DFMT_R32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "F"},
244 {WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_R24G8_TYPELESS
, "DX"},
245 {WINED3DFMT_X24_TYPELESS_G8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "XS"},
246 {WINED3DFMT_D24_UNORM_S8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "DS"},
247 {WINED3DFMT_R8G8_SNORM
, WINED3DFMT_R8G8_TYPELESS
, "ii"},
248 {WINED3DFMT_R8G8_UNORM
, WINED3DFMT_R8G8_TYPELESS
, "uu"},
249 {WINED3DFMT_R8G8_UINT
, WINED3DFMT_R8G8_TYPELESS
, "UU"},
250 {WINED3DFMT_R8G8_SINT
, WINED3DFMT_R8G8_TYPELESS
, "II"},
251 {WINED3DFMT_D16_UNORM
, WINED3DFMT_R16_TYPELESS
, "D"},
252 {WINED3DFMT_R16_UNORM
, WINED3DFMT_R16_TYPELESS
, "u"},
253 {WINED3DFMT_R16_SNORM
, WINED3DFMT_R16_TYPELESS
, "i"},
254 {WINED3DFMT_R16_UINT
, WINED3DFMT_R16_TYPELESS
, "U"},
255 {WINED3DFMT_R16_SINT
, WINED3DFMT_R16_TYPELESS
, "I"},
256 {WINED3DFMT_R16_FLOAT
, WINED3DFMT_R16_TYPELESS
, "F"},
257 {WINED3DFMT_R8_UNORM
, WINED3DFMT_R8_TYPELESS
, "u"},
258 {WINED3DFMT_R8_SNORM
, WINED3DFMT_R8_TYPELESS
, "i"},
259 {WINED3DFMT_R8_UINT
, WINED3DFMT_R8_TYPELESS
, "U"},
260 {WINED3DFMT_R8_SINT
, WINED3DFMT_R8_TYPELESS
, "I"},
261 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_TYPELESS
, ""},
262 {WINED3DFMT_BC1_UNORM
, WINED3DFMT_BC1_TYPELESS
, ""},
263 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_TYPELESS
, ""},
264 {WINED3DFMT_BC2_UNORM
, WINED3DFMT_BC2_TYPELESS
, ""},
265 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_TYPELESS
, ""},
266 {WINED3DFMT_BC3_UNORM
, WINED3DFMT_BC3_TYPELESS
, ""},
267 {WINED3DFMT_BC4_UNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
268 {WINED3DFMT_BC5_UNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
269 {WINED3DFMT_BC5_SNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
270 {WINED3DFMT_BC6H_UF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
271 {WINED3DFMT_BC6H_SF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
272 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_TYPELESS
, ""},
273 {WINED3DFMT_BC7_UNORM
, WINED3DFMT_BC7_TYPELESS
, ""},
274 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
275 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
276 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
277 {WINED3DFMT_B8G8R8X8_UNORM
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
280 struct wined3d_typeless_format_depth_stencil_info
282 enum wined3d_format_id typeless_id
;
283 enum wined3d_format_id depth_stencil_id
;
284 enum wined3d_format_id depth_view_id
;
285 enum wined3d_format_id stencil_view_id
;
288 static const struct wined3d_typeless_format_depth_stencil_info typeless_depth_stencil_formats
[] =
290 {WINED3DFMT_R32G8X24_TYPELESS
, WINED3DFMT_D32_FLOAT_S8X24_UINT
,
291 WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
, WINED3DFMT_X32_TYPELESS_G8X24_UINT
},
292 {WINED3DFMT_R24G8_TYPELESS
, WINED3DFMT_D24_UNORM_S8_UINT
,
293 WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_X24_TYPELESS_G8_UINT
},
294 {WINED3DFMT_R32_TYPELESS
, WINED3DFMT_D32_FLOAT
},
295 {WINED3DFMT_R16_TYPELESS
, WINED3DFMT_D16_UNORM
},
298 struct wined3d_format_ddi_info
300 enum wined3d_format_id id
;
301 D3DDDIFORMAT ddi_format
;
304 static const struct wined3d_format_ddi_info ddi_formats
[] =
306 {WINED3DFMT_B8G8R8_UNORM
, D3DDDIFMT_R8G8B8
},
307 {WINED3DFMT_B8G8R8A8_UNORM
, D3DDDIFMT_A8R8G8B8
},
308 {WINED3DFMT_B8G8R8X8_UNORM
, D3DDDIFMT_X8R8G8B8
},
309 {WINED3DFMT_B5G6R5_UNORM
, D3DDDIFMT_R5G6B5
},
310 {WINED3DFMT_B5G5R5X1_UNORM
, D3DDDIFMT_X1R5G5B5
},
311 {WINED3DFMT_B5G5R5A1_UNORM
, D3DDDIFMT_A1R5G5B5
},
312 {WINED3DFMT_B4G4R4A4_UNORM
, D3DDDIFMT_A4R4G4B4
},
313 {WINED3DFMT_B4G4R4X4_UNORM
, D3DDDIFMT_X4R4G4B4
},
314 {WINED3DFMT_P8_UINT
, D3DDDIFMT_P8
},
317 struct wined3d_format_base_flags
319 enum wined3d_format_id id
;
323 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
324 * still needs to use the correct block based calculation for e.g. the
326 static const struct wined3d_format_base_flags format_base_flags
[] =
328 {WINED3DFMT_ATI1N
, WINED3DFMT_FLAG_BROKEN_PITCH
},
329 {WINED3DFMT_ATI2N
, WINED3DFMT_FLAG_BROKEN_PITCH
},
330 {WINED3DFMT_R11G11B10_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
331 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
332 {WINED3DFMT_S8_UINT_D24_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
333 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, WINED3DFMT_FLAG_FLOAT
},
336 struct wined3d_format_block_info
338 enum wined3d_format_id id
;
341 UINT block_byte_count
;
345 static const struct wined3d_format_block_info format_block_info
[] =
347 {WINED3DFMT_DXT1
, 4, 4, 8, TRUE
},
348 {WINED3DFMT_DXT2
, 4, 4, 16, TRUE
},
349 {WINED3DFMT_DXT3
, 4, 4, 16, TRUE
},
350 {WINED3DFMT_DXT4
, 4, 4, 16, TRUE
},
351 {WINED3DFMT_DXT5
, 4, 4, 16, TRUE
},
352 {WINED3DFMT_BC1_UNORM
, 4, 4, 8, TRUE
},
353 {WINED3DFMT_BC2_UNORM
, 4, 4, 16, TRUE
},
354 {WINED3DFMT_BC3_UNORM
, 4, 4, 16, TRUE
},
355 {WINED3DFMT_BC4_UNORM
, 4, 4, 8, TRUE
},
356 {WINED3DFMT_BC5_UNORM
, 4, 4, 16, TRUE
},
357 {WINED3DFMT_BC5_SNORM
, 4, 4, 16, TRUE
},
358 {WINED3DFMT_BC6H_UF16
, 4, 4, 16, TRUE
},
359 {WINED3DFMT_BC6H_SF16
, 4, 4, 16, TRUE
},
360 {WINED3DFMT_BC7_UNORM
, 4, 4, 16, TRUE
},
361 {WINED3DFMT_ATI1N
, 4, 4, 8, FALSE
},
362 {WINED3DFMT_ATI2N
, 4, 4, 16, FALSE
},
363 {WINED3DFMT_YUY2
, 2, 1, 4, FALSE
},
364 {WINED3DFMT_UYVY
, 2, 1, 4, FALSE
},
367 struct wined3d_format_vertex_info
369 enum wined3d_format_id id
;
370 enum wined3d_ffp_emit_idx emit_idx
;
371 unsigned int component_count
;
373 GLboolean gl_normalized
;
374 enum wined3d_gl_extension extension
;
377 static const struct wined3d_format_vertex_info format_vertex_info
[] =
379 {WINED3DFMT_R32_FLOAT
, WINED3D_FFP_EMIT_FLOAT1
, 1, GL_FLOAT
, GL_FALSE
},
380 {WINED3DFMT_R32G32_FLOAT
, WINED3D_FFP_EMIT_FLOAT2
, 2, GL_FLOAT
, GL_FALSE
},
381 {WINED3DFMT_R32G32B32_FLOAT
, WINED3D_FFP_EMIT_FLOAT3
, 3, GL_FLOAT
, GL_FALSE
},
382 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3D_FFP_EMIT_FLOAT4
, 4, GL_FLOAT
, GL_FALSE
},
383 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3D_FFP_EMIT_D3DCOLOR
, 4, GL_UNSIGNED_BYTE
, GL_TRUE
},
384 {WINED3DFMT_R8G8B8A8_UINT
, WINED3D_FFP_EMIT_UBYTE4
, 4, GL_UNSIGNED_BYTE
, GL_FALSE
},
385 {WINED3DFMT_R16G16_UINT
, WINED3D_FFP_EMIT_INVALID
, 2, GL_UNSIGNED_SHORT
, GL_FALSE
},
386 {WINED3DFMT_R16G16_SINT
, WINED3D_FFP_EMIT_SHORT2
, 2, GL_SHORT
, GL_FALSE
},
387 {WINED3DFMT_R16G16B16A16_SINT
, WINED3D_FFP_EMIT_SHORT4
, 4, GL_SHORT
, GL_FALSE
},
388 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3D_FFP_EMIT_UBYTE4N
, 4, GL_UNSIGNED_BYTE
, GL_TRUE
},
389 {WINED3DFMT_R16G16_SNORM
, WINED3D_FFP_EMIT_SHORT2N
, 2, GL_SHORT
, GL_TRUE
},
390 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3D_FFP_EMIT_SHORT4N
, 4, GL_SHORT
, GL_TRUE
},
391 {WINED3DFMT_R16G16_UNORM
, WINED3D_FFP_EMIT_USHORT2N
, 2, GL_UNSIGNED_SHORT
, GL_TRUE
},
392 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3D_FFP_EMIT_USHORT4N
, 4, GL_UNSIGNED_SHORT
, GL_TRUE
},
393 {WINED3DFMT_R10G10B10X2_UINT
, WINED3D_FFP_EMIT_UDEC3
, 3, GL_UNSIGNED_SHORT
, GL_FALSE
},
394 {WINED3DFMT_R10G10B10X2_SNORM
, WINED3D_FFP_EMIT_DEC3N
, 3, GL_SHORT
, GL_TRUE
},
395 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3D_FFP_EMIT_INVALID
, 4, GL_UNSIGNED_INT_2_10_10_10_REV
, GL_TRUE
,
396 ARB_VERTEX_TYPE_2_10_10_10_REV
},
397 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, 2, GL_HALF_FLOAT
, GL_FALSE
},
398 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, 4, GL_HALF_FLOAT
, GL_FALSE
},
399 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3D_FFP_EMIT_INVALID
, 4, GL_BYTE
, GL_TRUE
},
400 {WINED3DFMT_R8G8B8A8_SINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_BYTE
, GL_FALSE
},
401 {WINED3DFMT_R16G16B16A16_UINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_UNSIGNED_SHORT
, GL_FALSE
},
402 {WINED3DFMT_R8_UINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_BYTE
, GL_FALSE
},
403 {WINED3DFMT_R8_SINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_BYTE
, GL_FALSE
},
404 {WINED3DFMT_R16_UINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_SHORT
, GL_FALSE
},
405 {WINED3DFMT_R16_SINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_SHORT
, GL_FALSE
},
406 {WINED3DFMT_R32_UINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_INT
, GL_FALSE
},
407 {WINED3DFMT_R32_SINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_INT
, GL_FALSE
},
408 {WINED3DFMT_R32G32_UINT
, WINED3D_FFP_EMIT_INVALID
, 2, GL_UNSIGNED_INT
, GL_FALSE
},
409 {WINED3DFMT_R32G32_SINT
, WINED3D_FFP_EMIT_INVALID
, 2, GL_INT
, GL_FALSE
},
410 {WINED3DFMT_R32G32B32_UINT
, WINED3D_FFP_EMIT_INVALID
, 3, GL_UNSIGNED_INT
, GL_FALSE
},
411 {WINED3DFMT_R32G32B32A32_UINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_UNSIGNED_INT
, GL_FALSE
},
412 {WINED3DFMT_R32G32B32A32_SINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_INT
, GL_FALSE
},
415 struct wined3d_format_texture_info
417 enum wined3d_format_id id
;
419 GLint gl_srgb_internal
;
420 GLint gl_rt_internal
;
423 unsigned int conv_byte_count
;
425 enum wined3d_gl_extension extension
;
426 void (*convert
)(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
427 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
);
430 static void convert_l4a4_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
431 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
433 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
434 * format+type combination to load it. Thus convert it to A8L8, then load it
435 * with A4L4 internal, but A8L8 format+type
437 unsigned int x
, y
, z
;
438 const unsigned char *Source
;
441 for (z
= 0; z
< depth
; z
++)
443 for (y
= 0; y
< height
; y
++)
445 Source
= src
+ z
* src_slice_pitch
+ y
* src_row_pitch
;
446 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
447 for (x
= 0; x
< width
; x
++ )
449 unsigned char color
= (*Source
++);
450 /* A */ Dest
[1] = (color
& 0xf0u
) << 0;
451 /* L */ Dest
[0] = (color
& 0x0fu
) << 4;
458 static void convert_r5g5_snorm_l6_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
459 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
461 unsigned int x
, y
, z
;
462 unsigned char r_in
, g_in
, l_in
;
463 const unsigned short *texel_in
;
464 unsigned short *texel_out
;
466 /* Emulating signed 5 bit values with unsigned 5 bit values has some precision problems by design:
467 * E.g. the signed input value 0 becomes 16. GL normalizes it to 16 / 31 = 0.516. We convert it
468 * back to a signed value by subtracting 0.5 and multiplying by 2.0. The resulting value is
469 * ((16 / 31) - 0.5) * 2.0 = 0.032, which is quite different from the intended result 0.000. */
470 for (z
= 0; z
< depth
; z
++)
472 for (y
= 0; y
< height
; y
++)
474 texel_out
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
475 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
476 for (x
= 0; x
< width
; x
++ )
478 l_in
= (*texel_in
& 0xfc00u
) >> 10;
479 g_in
= (*texel_in
& 0x03e0u
) >> 5;
480 r_in
= *texel_in
& 0x001fu
;
482 *texel_out
= ((r_in
+ 16) << 11) | (l_in
<< 5) | (g_in
+ 16);
490 static void convert_r5g5_snorm_l6_unorm_ext(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
491 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
493 unsigned int x
, y
, z
;
494 unsigned char *texel_out
, r_out
, g_out
, r_in
, g_in
, l_in
;
495 const unsigned short *texel_in
;
497 for (z
= 0; z
< depth
; z
++)
499 for (y
= 0; y
< height
; y
++)
501 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
502 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
503 for (x
= 0; x
< width
; x
++ )
505 l_in
= (*texel_in
& 0xfc00u
) >> 10;
506 g_in
= (*texel_in
& 0x03e0u
) >> 5;
507 r_in
= *texel_in
& 0x001fu
;
510 if (!(r_in
& 0x10)) /* r > 0 */
514 if (!(g_in
& 0x10)) /* g > 0 */
517 texel_out
[0] = r_out
;
518 texel_out
[1] = g_out
;
519 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
529 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
530 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
532 unsigned int x
, y
, z
;
533 unsigned char *texel_out
, ds_out
, dt_out
, r_in
, g_in
, l_in
;
534 const unsigned short *texel_in
;
536 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
537 * fixed function and shaders without further conversion once the surface is
540 * The difference between this function and convert_r5g5_snorm_l6_unorm_ext
541 * is that convert_r5g5_snorm_l6_unorm_ext creates a 32 bit XRGB texture and
542 * this function creates a 24 bit DSDT_MAG texture. Trying to load a DSDT_MAG
543 * internal with a 32 bit DSDT_MAG_INTENSITY or DSDT_MAG_VIB format fails. */
544 for (z
= 0; z
< depth
; z
++)
546 for (y
= 0; y
< height
; y
++)
548 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
549 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
550 for (x
= 0; x
< width
; x
++ )
552 l_in
= (*texel_in
& 0xfc00u
) >> 10;
553 g_in
= (*texel_in
& 0x03e0u
) >> 5;
554 r_in
= *texel_in
& 0x001fu
;
557 if (!(r_in
& 0x10)) /* r > 0 */
561 if (!(g_in
& 0x10)) /* g > 0 */
564 texel_out
[0] = ds_out
;
565 texel_out
[1] = dt_out
;
566 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
575 static void convert_r8g8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
576 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
578 unsigned int x
, y
, z
;
582 for (z
= 0; z
< depth
; z
++)
584 for (y
= 0; y
< height
; y
++)
586 Source
= (const short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
587 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
588 for (x
= 0; x
< width
; x
++ )
590 const short color
= (*Source
++);
591 /* B */ Dest
[0] = 0xff;
592 /* G */ Dest
[1] = (color
>> 8) + 128; /* V */
593 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
600 static void convert_r8g8_snorm_l8x8_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
601 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
603 unsigned int x
, y
, z
;
607 /* Doesn't work correctly with the fixed function pipeline, but can work in
608 * shaders if the shader is adjusted. (There's no use for this format in gl's
609 * standard fixed function pipeline anyway).
611 for (z
= 0; z
< depth
; z
++)
613 for (y
= 0; y
< height
; y
++)
615 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
616 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
617 for (x
= 0; x
< width
; x
++ )
619 LONG color
= (*Source
++);
620 /* B */ Dest
[0] = ((color
>> 16) & 0xff); /* L */
621 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
622 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
629 static void convert_r8g8_snorm_l8x8_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
630 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
632 unsigned int x
, y
, z
;
636 /* This implementation works with the fixed function pipeline and shaders
637 * without further modification after converting the surface.
639 for (z
= 0; z
< depth
; z
++)
641 for (y
= 0; y
< height
; y
++)
643 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
644 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
645 for (x
= 0; x
< width
; x
++ )
647 LONG color
= (*Source
++);
648 /* L */ Dest
[2] = ((color
>> 16) & 0xff); /* L */
649 /* V */ Dest
[1] = ((color
>> 8 ) & 0xff); /* V */
650 /* U */ Dest
[0] = (color
& 0xff); /* U */
651 /* I */ Dest
[3] = 255; /* X */
658 static void convert_r8g8b8a8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
659 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
661 unsigned int x
, y
, z
;
665 for (z
= 0; z
< depth
; z
++)
667 for (y
= 0; y
< height
; y
++)
669 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
670 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
671 for (x
= 0; x
< width
; x
++ )
673 LONG color
= (*Source
++);
674 /* B */ Dest
[0] = ((color
>> 16) & 0xff) + 128; /* W */
675 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
676 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
677 /* A */ Dest
[3] = ((color
>> 24) & 0xff) + 128; /* Q */
684 static void convert_r16g16_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
685 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
687 unsigned int x
, y
, z
;
689 unsigned short *Dest
;
691 for (z
= 0; z
< depth
; z
++)
693 for (y
= 0; y
< height
; y
++)
695 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
696 Dest
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
697 for (x
= 0; x
< width
; x
++ )
699 const DWORD color
= (*Source
++);
700 /* B */ Dest
[0] = 0xffff;
701 /* G */ Dest
[1] = (color
>> 16) + 32768; /* V */
702 /* R */ Dest
[2] = (color
& 0xffff) + 32768; /* U */
709 static void convert_r16g16(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
710 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
712 unsigned int x
, y
, z
;
716 for (z
= 0; z
< depth
; z
++)
718 for (y
= 0; y
< height
; y
++)
720 Source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
721 Dest
= (WORD
*) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
722 for (x
= 0; x
< width
; x
++ )
724 WORD green
= (*Source
++);
725 WORD red
= (*Source
++);
728 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
729 * shader overwrites it anyway */
737 static void convert_r32g32_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
738 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
740 unsigned int x
, y
, z
;
744 for (z
= 0; z
< depth
; z
++)
746 for (y
= 0; y
< height
; y
++)
748 Source
= (const float *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
749 Dest
= (float *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
750 for (x
= 0; x
< width
; x
++ )
752 float green
= (*Source
++);
753 float red
= (*Source
++);
763 static void convert_s1_uint_d15_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
764 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
766 unsigned int x
, y
, z
;
768 for (z
= 0; z
< depth
; z
++)
770 for (y
= 0; y
< height
; ++y
)
772 const WORD
*source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
773 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
775 for (x
= 0; x
< width
; ++x
)
777 /* The depth data is normalized, so needs to be scaled,
778 * the stencil data isn't. Scale depth data by
779 * (2^24-1)/(2^15-1) ~~ (2^9 + 2^-6). */
780 WORD d15
= source
[x
] >> 1;
781 DWORD d24
= (d15
<< 9) + (d15
>> 6);
782 dest
[x
] = (d24
<< 8) | (source
[x
] & 0x1);
788 static void convert_s4x4_uint_d24_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
789 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
791 unsigned int x
, y
, z
;
793 for (z
= 0; z
< depth
; z
++)
795 for (y
= 0; y
< height
; ++y
)
797 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
798 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
800 for (x
= 0; x
< width
; ++x
)
802 /* Just need to clear out the X4 part. */
803 dest
[x
] = source
[x
] & ~0xf0;
809 static void convert_s8_uint_d24_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
810 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
812 unsigned int x
, y
, z
;
814 for (z
= 0; z
< depth
; z
++)
816 for (y
= 0; y
< height
; ++y
)
818 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
819 float *dest_f
= (float *)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
820 DWORD
*dest_s
= (DWORD
*)dest_f
;
822 for (x
= 0; x
< width
; ++x
)
824 dest_f
[x
* 2] = float_24_to_32((source
[x
] & 0xffffff00u
) >> 8);
825 dest_s
[x
* 2 + 1] = source
[x
] & 0xff;
831 static BOOL
color_in_range(const struct wined3d_color_key
*color_key
, DWORD color
)
833 /* FIXME: Is this really how color keys are supposed to work? I think it
834 * makes more sense to compare the individual channels. */
835 return color
>= color_key
->color_space_low_value
836 && color
<= color_key
->color_space_high_value
;
839 static void convert_p8_uint_b8g8r8a8_unorm(const BYTE
*src
, unsigned int src_pitch
,
840 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
841 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
849 /* FIXME: This should probably use the system palette. */
850 FIXME("P8 surface loaded without a palette.\n");
852 for (y
= 0; y
< height
; ++y
)
854 memset(&dst
[dst_pitch
* y
], 0, width
* 4);
860 for (y
= 0; y
< height
; ++y
)
862 src_row
= &src
[src_pitch
* y
];
863 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
864 for (x
= 0; x
< width
; ++x
)
866 BYTE src_color
= src_row
[x
];
867 dst_row
[x
] = 0xff000000
868 | (palette
->colors
[src_color
].rgbRed
<< 16)
869 | (palette
->colors
[src_color
].rgbGreen
<< 8)
870 | palette
->colors
[src_color
].rgbBlue
;
875 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
876 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
877 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
883 for (y
= 0; y
< height
; ++y
)
885 src_row
= (WORD
*)&src
[src_pitch
* y
];
886 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
887 for (x
= 0; x
< width
; ++x
)
889 WORD src_color
= src_row
[x
];
890 if (!color_in_range(color_key
, src_color
))
891 dst_row
[x
] = 0x8000u
| ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
893 dst_row
[x
] = ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
898 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(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
)
906 for (y
= 0; y
< height
; ++y
)
908 src_row
= (WORD
*)&src
[src_pitch
* y
];
909 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
910 for (x
= 0; x
< width
; ++x
)
912 WORD src_color
= src_row
[x
];
913 if (color_in_range(color_key
, src_color
))
914 dst_row
[x
] = src_color
& ~0x8000;
916 dst_row
[x
] = src_color
| 0x8000;
921 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
922 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
923 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
929 for (y
= 0; y
< height
; ++y
)
931 src_row
= &src
[src_pitch
* y
];
932 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
933 for (x
= 0; x
< width
; ++x
)
935 DWORD src_color
= (src_row
[x
* 3 + 2] << 16) | (src_row
[x
* 3 + 1] << 8) | src_row
[x
* 3];
936 if (!color_in_range(color_key
, src_color
))
937 dst_row
[x
] = src_color
| 0xff000000;
942 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
943 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
944 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
946 const DWORD
*src_row
;
950 for (y
= 0; y
< height
; ++y
)
952 src_row
= (DWORD
*)&src
[src_pitch
* y
];
953 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
954 for (x
= 0; x
< width
; ++x
)
956 DWORD src_color
= src_row
[x
];
957 if (color_in_range(color_key
, src_color
))
958 dst_row
[x
] = src_color
& ~0xff000000;
960 dst_row
[x
] = src_color
| 0xff000000;
965 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
966 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
967 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
969 const DWORD
*src_row
;
973 for (y
= 0; y
< height
; ++y
)
975 src_row
= (DWORD
*)&src
[src_pitch
* y
];
976 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
977 for (x
= 0; x
< width
; ++x
)
979 DWORD src_color
= src_row
[x
];
980 if (color_in_range(color_key
, src_color
))
981 src_color
&= ~0xff000000;
982 dst_row
[x
] = src_color
;
987 const struct wined3d_color_key_conversion
* wined3d_format_get_color_key_conversion(
988 const struct wined3d_texture
*texture
, BOOL need_alpha_ck
)
990 const struct wined3d_format
*format
= texture
->resource
.format
;
995 enum wined3d_format_id src_format
;
996 struct wined3d_color_key_conversion conversion
;
1000 {WINED3DFMT_B5G6R5_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key
}},
1001 {WINED3DFMT_B5G5R5X1_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key
}},
1002 {WINED3DFMT_B8G8R8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key
}},
1003 {WINED3DFMT_B8G8R8X8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key
}},
1004 {WINED3DFMT_B8G8R8A8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key
}},
1006 static const struct wined3d_color_key_conversion convert_p8
=
1008 WINED3DFMT_B8G8R8A8_UNORM
, convert_p8_uint_b8g8r8a8_unorm
1011 if (need_alpha_ck
&& (texture
->async
.flags
& WINED3D_TEXTURE_ASYNC_COLOR_KEY
))
1013 for (i
= 0; i
< sizeof(color_key_info
) / sizeof(*color_key_info
); ++i
)
1015 if (color_key_info
[i
].src_format
== format
->id
)
1016 return &color_key_info
[i
].conversion
;
1019 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format
->id
));
1022 /* FIXME: This should check if the blitter backend can do P8 conversion,
1023 * instead of checking for ARB_fragment_program. */
1024 if (format
->id
== WINED3DFMT_P8_UINT
1025 && !(texture
->resource
.device
->adapter
->gl_info
.supported
[ARB_FRAGMENT_PROGRAM
]
1026 && texture
->swapchain
&& texture
== texture
->swapchain
->front_buffer
))
1032 /* The following formats explicitly don't have WINED3DFMT_FLAG_TEXTURE set:
1034 * These are never supported on native.
1035 * WINED3DFMT_B8G8R8_UNORM
1036 * WINED3DFMT_B2G3R3_UNORM
1037 * WINED3DFMT_L4A4_UNORM
1038 * WINED3DFMT_S1_UINT_D15_UNORM
1039 * WINED3DFMT_S4X4_UINT_D24_UNORM
1041 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
1042 * Since it is not widely available, don't offer it. Further no Windows driver
1043 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
1044 * WINED3DFMT_P8_UINT
1045 * WINED3DFMT_P8_UINT_A8_UNORM
1047 * These formats seem to be similar to the HILO formats in
1048 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
1049 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
1050 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
1051 * refused to support formats which can easily be emulated with pixel shaders,
1052 * so applications have to deal with not having NVHS and NVHU.
1054 * WINED3DFMT_NVHS */
1055 static const struct wined3d_format_texture_info format_texture_info
[] =
1057 /* format id gl_internal gl_srgb_internal gl_rt_internal
1058 gl_format gl_type conv_byte_count
1060 extension convert */
1061 /* FourCC formats */
1062 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
1063 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
1064 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
1065 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
1068 {WINED3DFMT_UYVY
, GL_RG8
, GL_RG8
, 0,
1069 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1070 WINED3DFMT_FLAG_FILTERING
,
1071 ARB_TEXTURE_RG
, NULL
},
1072 {WINED3DFMT_UYVY
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1073 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1074 WINED3DFMT_FLAG_FILTERING
,
1075 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1076 {WINED3DFMT_UYVY
, GL_RGB
, GL_RGB
, 0,
1077 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
1078 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
1079 APPLE_YCBCR_422
, NULL
},
1080 {WINED3DFMT_YUY2
, GL_RG8
, GL_RG8
, 0,
1081 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1082 WINED3DFMT_FLAG_FILTERING
,
1083 ARB_TEXTURE_RG
, NULL
},
1084 {WINED3DFMT_YUY2
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1085 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1086 WINED3DFMT_FLAG_FILTERING
,
1087 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1088 {WINED3DFMT_YUY2
, GL_RGB
, GL_RGB
, 0,
1089 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
1090 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
1091 APPLE_YCBCR_422
, NULL
},
1092 {WINED3DFMT_YV12
, GL_R8
, GL_R8
, 0,
1093 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1094 WINED3DFMT_FLAG_FILTERING
,
1095 ARB_TEXTURE_RG
, NULL
},
1096 {WINED3DFMT_YV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1097 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1098 WINED3DFMT_FLAG_FILTERING
,
1099 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1100 {WINED3DFMT_NV12
, GL_R8
, GL_R8
, 0,
1101 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1102 WINED3DFMT_FLAG_FILTERING
,
1103 ARB_TEXTURE_RG
, NULL
},
1104 {WINED3DFMT_NV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1105 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1106 WINED3DFMT_FLAG_FILTERING
,
1107 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1108 {WINED3DFMT_DXT1
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1109 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1110 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1111 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1112 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1113 {WINED3DFMT_DXT2
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1114 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1115 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1116 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1117 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1118 {WINED3DFMT_DXT3
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1119 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1120 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1121 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1122 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1123 {WINED3DFMT_DXT4
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1124 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1125 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1126 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1127 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1128 {WINED3DFMT_DXT5
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1129 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1130 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1131 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1132 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1133 {WINED3DFMT_BC1_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1134 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1135 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1136 | WINED3DFMT_FLAG_COMPRESSED
,
1137 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1138 {WINED3DFMT_BC2_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1139 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1140 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1141 | WINED3DFMT_FLAG_COMPRESSED
,
1142 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1143 {WINED3DFMT_BC3_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1144 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1145 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1146 | WINED3DFMT_FLAG_COMPRESSED
,
1147 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1148 {WINED3DFMT_BC4_UNORM
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1149 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1150 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1151 | WINED3DFMT_FLAG_COMPRESSED
,
1152 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1153 {WINED3DFMT_BC5_UNORM
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1154 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1155 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1156 | WINED3DFMT_FLAG_COMPRESSED
,
1157 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1158 {WINED3DFMT_BC5_SNORM
, GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_COMPRESSED_SIGNED_RG_RGTC2
, 0,
1159 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1160 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1161 | WINED3DFMT_FLAG_COMPRESSED
,
1162 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1163 {WINED3DFMT_BC6H_UF16
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, 0,
1164 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1165 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1166 | WINED3DFMT_FLAG_COMPRESSED
,
1167 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1168 {WINED3DFMT_BC6H_SF16
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, 0,
1169 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1170 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1171 | WINED3DFMT_FLAG_COMPRESSED
,
1172 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1173 {WINED3DFMT_BC7_UNORM
, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
, 0,
1174 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1175 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1176 | WINED3DFMT_FLAG_COMPRESSED
,
1177 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1179 {WINED3DFMT_R32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1180 GL_RED
, GL_FLOAT
, 0,
1181 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1182 ARB_TEXTURE_FLOAT
, NULL
},
1183 {WINED3DFMT_R32_FLOAT
, GL_R32F
, GL_R32F
, 0,
1184 GL_RED
, GL_FLOAT
, 0,
1185 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1186 ARB_TEXTURE_RG
, NULL
},
1187 {WINED3DFMT_R32G32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1188 GL_RGB
, GL_FLOAT
, 12,
1189 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1190 ARB_TEXTURE_FLOAT
, convert_r32g32_float
},
1191 {WINED3DFMT_R32G32_FLOAT
, GL_RG32F
, GL_RG32F
, 0,
1193 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1194 ARB_TEXTURE_RG
, NULL
},
1195 {WINED3DFMT_R32G32B32_FLOAT
, GL_RGB32F
, GL_RGB32F
, 0,
1196 GL_RGB
, GL_FLOAT
, 0,
1197 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1198 ARB_TEXTURE_FLOAT
, NULL
},
1199 {WINED3DFMT_R32G32B32A32_FLOAT
, GL_RGBA32F_ARB
, GL_RGBA32F_ARB
, 0,
1200 GL_RGBA
, GL_FLOAT
, 0,
1201 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1202 ARB_TEXTURE_FLOAT
, NULL
},
1204 {WINED3DFMT_R16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1205 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1206 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1207 ARB_TEXTURE_FLOAT
, NULL
},
1208 {WINED3DFMT_R16_FLOAT
, GL_R16F
, GL_R16F
, 0,
1209 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1210 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1211 ARB_TEXTURE_RG
, NULL
},
1212 {WINED3DFMT_R16G16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1213 GL_RGB
, GL_HALF_FLOAT_ARB
, 6,
1214 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1215 ARB_TEXTURE_FLOAT
, convert_r16g16
},
1216 {WINED3DFMT_R16G16_FLOAT
, GL_RG16F
, GL_RG16F
, 0,
1217 GL_RG
, GL_HALF_FLOAT_ARB
, 0,
1218 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1219 ARB_TEXTURE_RG
, NULL
},
1220 {WINED3DFMT_R16G16B16A16_FLOAT
, GL_RGBA16F_ARB
, GL_RGBA16F_ARB
, 0,
1221 GL_RGBA
, GL_HALF_FLOAT_ARB
, 0,
1222 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
1223 | WINED3DFMT_FLAG_VTF
,
1224 ARB_TEXTURE_FLOAT
, NULL
},
1225 {WINED3DFMT_R11G11B10_FLOAT
, GL_R11F_G11F_B10F
, GL_R11F_G11F_B10F
, 0,
1226 GL_RGB
, GL_UNSIGNED_INT_10F_11F_11F_REV
, 0,
1227 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
,
1229 /* Palettized formats */
1230 {WINED3DFMT_P8_UINT
, GL_R8
, GL_R8
, 0,
1231 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1233 ARB_TEXTURE_RG
, NULL
},
1234 {WINED3DFMT_P8_UINT
, GL_ALPHA8
, GL_ALPHA8
, 0,
1235 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1237 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1238 /* Standard ARGB formats */
1239 {WINED3DFMT_B8G8R8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1240 GL_BGR
, GL_UNSIGNED_BYTE
, 0,
1241 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
| WINED3DFMT_FLAG_RENDERTARGET
,
1242 WINED3D_GL_EXT_NONE
, NULL
},
1243 {WINED3DFMT_B8G8R8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1244 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1245 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1246 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1247 | WINED3DFMT_FLAG_VTF
,
1248 WINED3D_GL_EXT_NONE
, NULL
},
1249 {WINED3DFMT_B8G8R8X8_UNORM
, GL_RGB8
, GL_SRGB8_EXT
, 0,
1250 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1251 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1252 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
,
1253 WINED3D_GL_EXT_NONE
, NULL
},
1254 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB5
, GL_RGB5
, GL_RGB8
,
1255 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1256 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1257 | WINED3DFMT_FLAG_RENDERTARGET
,
1258 WINED3D_GL_EXT_NONE
, NULL
},
1259 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB565
, GL_RGB565
, GL_RGB8
,
1260 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1261 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1262 | WINED3DFMT_FLAG_RENDERTARGET
,
1263 ARB_ES2_COMPATIBILITY
, NULL
},
1264 {WINED3DFMT_B5G5R5X1_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1265 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1266 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1267 | WINED3DFMT_FLAG_RENDERTARGET
,
1268 WINED3D_GL_EXT_NONE
, NULL
},
1269 {WINED3DFMT_B5G5R5A1_UNORM
, GL_RGB5_A1
, GL_RGB5_A1
, 0,
1270 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1271 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1272 WINED3D_GL_EXT_NONE
, NULL
},
1273 {WINED3DFMT_B4G4R4A4_UNORM
, GL_RGBA4
, GL_SRGB8_ALPHA8_EXT
, 0,
1274 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1275 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1276 | WINED3DFMT_FLAG_SRGB_READ
,
1277 WINED3D_GL_EXT_NONE
, NULL
},
1278 {WINED3DFMT_B2G3R3_UNORM
, GL_R3_G3_B2
, GL_R3_G3_B2
, 0,
1279 GL_RGB
, GL_UNSIGNED_BYTE_3_3_2
, 0,
1280 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1281 WINED3D_GL_EXT_NONE
, NULL
},
1282 {WINED3DFMT_R8_UNORM
, GL_R8
, GL_R8
, 0,
1283 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1284 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1285 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1286 ARB_TEXTURE_RG
, NULL
},
1287 {WINED3DFMT_A8_UNORM
, GL_R8
, GL_R8
, 0,
1288 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1289 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1290 ARB_TEXTURE_RG
, NULL
},
1291 {WINED3DFMT_A8_UNORM
, GL_ALPHA8
, GL_ALPHA8
, 0,
1292 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1293 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1294 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1295 {WINED3DFMT_B4G4R4X4_UNORM
, GL_RGB4
, GL_RGB4
, 0,
1296 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1297 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1298 WINED3D_GL_EXT_NONE
, NULL
},
1299 {WINED3DFMT_R10G10B10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1300 GL_RGBA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1301 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1302 | WINED3DFMT_FLAG_RENDERTARGET
,
1303 WINED3D_GL_EXT_NONE
, NULL
},
1304 {WINED3DFMT_R8G8B8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1305 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1306 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1307 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1308 | WINED3DFMT_FLAG_VTF
,
1309 WINED3D_GL_EXT_NONE
, NULL
},
1310 {WINED3DFMT_R8G8B8A8_UINT
, GL_RGBA8UI
, GL_RGBA8UI
, 0,
1311 GL_RGBA_INTEGER
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1312 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1313 ARB_TEXTURE_RGB10_A2UI
, NULL
},
1314 {WINED3DFMT_R8G8B8A8_SINT
, GL_RGBA8I
, GL_RGBA8I
, 0,
1315 GL_RGBA_INTEGER
, GL_BYTE
, 0,
1316 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1317 EXT_TEXTURE_INTEGER
, NULL
},
1318 {WINED3DFMT_R8G8B8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1319 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1320 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1321 WINED3D_GL_EXT_NONE
, NULL
},
1322 {WINED3DFMT_R16G16_UNORM
, GL_RGB16
, GL_RGB16
, GL_RGBA16
,
1323 GL_RGB
, GL_UNSIGNED_SHORT
, 6,
1324 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1325 WINED3D_GL_EXT_NONE
, convert_r16g16
},
1326 {WINED3DFMT_R16G16_UNORM
, GL_RG16
, GL_RG16
, 0,
1327 GL_RG
, GL_UNSIGNED_SHORT
, 0,
1328 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1329 | WINED3DFMT_FLAG_RENDERTARGET
,
1330 ARB_TEXTURE_RG
, NULL
},
1331 {WINED3DFMT_B10G10R10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1332 GL_BGRA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1333 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1334 | WINED3DFMT_FLAG_RENDERTARGET
,
1335 WINED3D_GL_EXT_NONE
, NULL
},
1336 {WINED3DFMT_R16G16B16A16_UNORM
, GL_RGBA16
, GL_RGBA16
, 0,
1337 GL_RGBA
, GL_UNSIGNED_SHORT
, 0,
1338 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1339 | WINED3DFMT_FLAG_RENDERTARGET
,
1340 WINED3D_GL_EXT_NONE
, NULL
},
1341 {WINED3DFMT_R8G8_UNORM
, GL_RG8
, GL_RG8
, 0,
1342 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1343 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1344 | WINED3DFMT_FLAG_RENDERTARGET
,
1345 ARB_TEXTURE_RG
, NULL
},
1346 {WINED3DFMT_R8G8_UINT
, GL_RG8UI
, GL_RG8UI
, 0,
1347 GL_RG_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1348 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1349 ARB_TEXTURE_RG
, NULL
},
1350 {WINED3DFMT_R8G8_SINT
, GL_RG8I
, GL_RG8I
, 0,
1351 GL_RG_INTEGER
, GL_BYTE
, 0,
1352 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1353 ARB_TEXTURE_RG
, NULL
},
1354 {WINED3DFMT_R16G16B16A16_UINT
, GL_RGBA16UI
, GL_RGBA16UI
, 0,
1355 GL_RGBA_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1356 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1357 EXT_TEXTURE_INTEGER
, NULL
},
1358 {WINED3DFMT_R16G16B16A16_SINT
, GL_RGBA16I
, GL_RGBA16I
, 0,
1359 GL_RGBA_INTEGER
, GL_SHORT
, 0,
1360 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1361 EXT_TEXTURE_INTEGER
, NULL
},
1362 {WINED3DFMT_R32G32_UINT
, GL_RG32UI
, GL_RG32UI
, 0,
1363 GL_RG_INTEGER
, GL_UNSIGNED_INT
, 0,
1364 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1365 ARB_TEXTURE_RG
, NULL
},
1366 {WINED3DFMT_R32G32_SINT
, GL_RG32I
, GL_RG32I
, 0,
1367 GL_RG_INTEGER
, GL_INT
, 0,
1368 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1369 ARB_TEXTURE_RG
, NULL
},
1370 {WINED3DFMT_R16G16_UINT
, GL_RG16UI
, GL_RG16UI
, 0,
1371 GL_RG_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1372 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1373 ARB_TEXTURE_RG
, NULL
},
1374 {WINED3DFMT_R16G16_SINT
, GL_RG16I
, GL_RG16I
, 0,
1375 GL_RG_INTEGER
, GL_SHORT
, 0,
1376 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1377 ARB_TEXTURE_RG
, NULL
},
1378 {WINED3DFMT_R32_UINT
, GL_R32UI
, GL_R32UI
, 0,
1379 GL_RED_INTEGER
, GL_UNSIGNED_INT
, 0,
1380 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1381 ARB_TEXTURE_RG
, NULL
},
1382 {WINED3DFMT_R32_SINT
, GL_R32I
, GL_R32I
, 0,
1383 GL_RED_INTEGER
, GL_INT
, 0,
1384 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1385 ARB_TEXTURE_RG
, NULL
},
1386 {WINED3DFMT_R16_UNORM
, GL_R16
, GL_R16
, 0,
1387 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1388 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1389 | WINED3DFMT_FLAG_RENDERTARGET
,
1390 ARB_TEXTURE_RG
, NULL
},
1391 {WINED3DFMT_R16_UINT
, GL_R16UI
, GL_R16UI
, 0,
1392 GL_RED_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1393 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1394 ARB_TEXTURE_RG
, NULL
},
1395 {WINED3DFMT_R16_SINT
, GL_R16I
, GL_R16I
, 0,
1396 GL_RED_INTEGER
, GL_SHORT
, 0,
1397 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1398 ARB_TEXTURE_RG
, NULL
},
1399 {WINED3DFMT_R8_UINT
, GL_R8UI
, GL_R8UI
, 0,
1400 GL_RED_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1401 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1402 ARB_TEXTURE_RG
, NULL
},
1403 {WINED3DFMT_R8_SINT
, GL_R8I
, GL_R8I
, 0,
1404 GL_RED_INTEGER
, GL_BYTE
, 0,
1405 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1406 ARB_TEXTURE_RG
, NULL
},
1408 {WINED3DFMT_L8_UNORM
, GL_LUMINANCE8
, GL_SLUMINANCE8_EXT
, 0,
1409 GL_LUMINANCE
, GL_UNSIGNED_BYTE
, 0,
1410 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1411 | WINED3DFMT_FLAG_SRGB_READ
,
1412 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1413 {WINED3DFMT_L8_UNORM
, GL_R8
, GL_R8
, 0,
1414 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1415 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1416 | WINED3DFMT_FLAG_RENDERTARGET
,
1417 ARB_TEXTURE_RG
, NULL
},
1418 {WINED3DFMT_L8A8_UNORM
, GL_RG8
, GL_RG8
, 0,
1419 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1420 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1421 ARB_TEXTURE_RG
, NULL
},
1422 {WINED3DFMT_L8A8_UNORM
, GL_LUMINANCE8_ALPHA8
, GL_SLUMINANCE8_ALPHA8_EXT
, 0,
1423 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1424 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1425 | WINED3DFMT_FLAG_SRGB_READ
,
1426 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1427 {WINED3DFMT_L4A4_UNORM
, GL_RG8
, GL_RG8
, 0,
1428 GL_RG
, GL_UNSIGNED_BYTE
, 2,
1429 WINED3DFMT_FLAG_FILTERING
,
1430 ARB_TEXTURE_RG
, convert_l4a4_unorm
},
1431 {WINED3DFMT_L4A4_UNORM
, GL_LUMINANCE4_ALPHA4
, GL_LUMINANCE4_ALPHA4
, 0,
1432 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 2,
1433 WINED3DFMT_FLAG_FILTERING
,
1434 WINED3D_GL_LEGACY_CONTEXT
, convert_l4a4_unorm
},
1435 {WINED3DFMT_L16_UNORM
, GL_R16
, GL_R16
, 0,
1436 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1437 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1438 ARB_TEXTURE_RG
, NULL
},
1439 {WINED3DFMT_L16_UNORM
, GL_LUMINANCE16
, GL_LUMINANCE16
, 0,
1440 GL_LUMINANCE
, GL_UNSIGNED_SHORT
, 0,
1441 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1442 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1443 /* Bump mapping stuff */
1444 {WINED3DFMT_R8G8_SNORM
, GL_RGB8
, GL_RGB8
, 0,
1445 GL_BGR
, GL_UNSIGNED_BYTE
, 3,
1446 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1447 | WINED3DFMT_FLAG_BUMPMAP
,
1448 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm
},
1449 {WINED3DFMT_R8G8_SNORM
, GL_DSDT8_NV
, GL_DSDT8_NV
, 0,
1450 GL_DSDT_NV
, GL_BYTE
, 0,
1451 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1452 | WINED3DFMT_FLAG_BUMPMAP
,
1453 NV_TEXTURE_SHADER
, NULL
},
1454 {WINED3DFMT_R8G8_SNORM
, GL_RG8_SNORM
, GL_RG8_SNORM
, 0,
1456 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1457 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1458 EXT_TEXTURE_SNORM
, NULL
},
1459 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1460 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 2,
1461 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1462 | WINED3DFMT_FLAG_BUMPMAP
,
1463 WINED3D_GL_EXT_NONE
, convert_r5g5_snorm_l6_unorm
},
1464 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_DSDT8_MAG8_NV
, GL_DSDT8_MAG8_NV
, 0,
1465 GL_DSDT_MAG_NV
, GL_BYTE
, 3,
1466 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1467 | WINED3DFMT_FLAG_BUMPMAP
,
1468 NV_TEXTURE_SHADER
, convert_r5g5_snorm_l6_unorm_nv
},
1469 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB8_SNORM
, GL_RGB8_SNORM
, 0,
1470 GL_RGBA
, GL_BYTE
, 4,
1471 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1472 | WINED3DFMT_FLAG_BUMPMAP
,
1473 EXT_TEXTURE_SNORM
, convert_r5g5_snorm_l6_unorm_ext
},
1474 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1475 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4,
1476 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1477 | WINED3DFMT_FLAG_BUMPMAP
,
1478 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm_l8x8_unorm
},
1479 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_DSDT8_MAG8_INTENSITY8_NV
, GL_DSDT8_MAG8_INTENSITY8_NV
, 0,
1480 GL_DSDT_MAG_VIB_NV
, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV
, 4,
1481 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1482 | WINED3DFMT_FLAG_BUMPMAP
,
1483 NV_TEXTURE_SHADER
, convert_r8g8_snorm_l8x8_unorm_nv
},
1484 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8
, GL_RGBA8
, 0,
1485 GL_BGRA
, GL_UNSIGNED_BYTE
, 4,
1486 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1487 | WINED3DFMT_FLAG_BUMPMAP
,
1488 WINED3D_GL_EXT_NONE
, convert_r8g8b8a8_snorm
},
1489 {WINED3DFMT_R8G8B8A8_SNORM
, GL_SIGNED_RGBA8_NV
, GL_SIGNED_RGBA8_NV
, 0,
1490 GL_RGBA
, GL_BYTE
, 0,
1491 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1492 | WINED3DFMT_FLAG_BUMPMAP
,
1493 NV_TEXTURE_SHADER
, NULL
},
1494 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8_SNORM
, GL_RGBA8_SNORM
, 0,
1495 GL_RGBA
, GL_BYTE
, 0,
1496 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1497 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1498 EXT_TEXTURE_SNORM
, NULL
},
1499 {WINED3DFMT_R16G16_SNORM
, GL_RGB16
, GL_RGB16
, 0,
1500 GL_BGR
, GL_UNSIGNED_SHORT
, 6,
1501 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1502 | WINED3DFMT_FLAG_BUMPMAP
,
1503 WINED3D_GL_EXT_NONE
, convert_r16g16_snorm
},
1504 {WINED3DFMT_R16G16_SNORM
, GL_SIGNED_HILO16_NV
, GL_SIGNED_HILO16_NV
, 0,
1505 GL_HILO_NV
, GL_SHORT
, 0,
1506 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1507 | WINED3DFMT_FLAG_BUMPMAP
,
1508 NV_TEXTURE_SHADER
, NULL
},
1509 {WINED3DFMT_R16G16_SNORM
, GL_RG16_SNORM
, GL_RG16_SNORM
, 0,
1511 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1512 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1513 EXT_TEXTURE_SNORM
, NULL
},
1514 {WINED3DFMT_R16G16B16A16_SNORM
, GL_RGBA16_SNORM
, GL_RGBA16_SNORM
, 0,
1515 GL_RGBA
, GL_SHORT
, 0,
1516 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1517 | WINED3DFMT_FLAG_RENDERTARGET
,
1518 EXT_TEXTURE_SNORM
, NULL
},
1519 {WINED3DFMT_R16_SNORM
, GL_R16_SNORM
, GL_R16_SNORM
, 0,
1520 GL_RED
, GL_SHORT
, 0,
1521 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1522 | WINED3DFMT_FLAG_RENDERTARGET
,
1523 EXT_TEXTURE_SNORM
, NULL
},
1524 {WINED3DFMT_R8_SNORM
, GL_R8_SNORM
, GL_R8_SNORM
, 0,
1526 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1527 | WINED3DFMT_FLAG_RENDERTARGET
,
1528 EXT_TEXTURE_SNORM
, NULL
},
1529 /* Depth stencil formats */
1530 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1531 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1532 WINED3DFMT_FLAG_DEPTH
,
1533 WINED3D_GL_EXT_NONE
, NULL
},
1534 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1535 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1536 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1537 ARB_DEPTH_TEXTURE
, NULL
},
1538 {WINED3DFMT_D32_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1539 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1540 WINED3DFMT_FLAG_DEPTH
,
1541 WINED3D_GL_EXT_NONE
, NULL
},
1542 {WINED3DFMT_D32_UNORM
, GL_DEPTH_COMPONENT32_ARB
, GL_DEPTH_COMPONENT32_ARB
, 0,
1543 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1544 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1545 ARB_DEPTH_TEXTURE
, NULL
},
1546 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1547 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1548 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1549 ARB_DEPTH_TEXTURE
, NULL
},
1550 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1551 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 4,
1552 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1553 EXT_PACKED_DEPTH_STENCIL
, convert_s1_uint_d15_unorm
},
1554 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1555 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 4,
1556 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1557 ARB_FRAMEBUFFER_OBJECT
, convert_s1_uint_d15_unorm
},
1558 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1559 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1560 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1561 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1562 ARB_DEPTH_TEXTURE
, NULL
},
1563 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1564 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 0,
1565 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1566 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1567 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1568 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1569 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1570 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1571 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1572 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1573 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1574 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1575 WINED3DFMT_FLAG_DEPTH
,
1576 WINED3D_GL_EXT_NONE
, NULL
},
1577 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1578 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1579 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1580 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1581 ARB_DEPTH_TEXTURE
, NULL
},
1582 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1583 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1584 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1585 ARB_DEPTH_TEXTURE
, NULL
},
1586 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1587 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 4,
1588 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1589 EXT_PACKED_DEPTH_STENCIL
, convert_s4x4_uint_d24_unorm
},
1590 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1591 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 4,
1592 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1593 ARB_FRAMEBUFFER_OBJECT
, convert_s4x4_uint_d24_unorm
},
1594 {WINED3DFMT_D16_UNORM
, 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_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1599 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1600 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1601 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1602 ARB_DEPTH_TEXTURE
, NULL
},
1603 {WINED3DFMT_D32_FLOAT
, GL_DEPTH_COMPONENT32F
, GL_DEPTH_COMPONENT32F
, 0,
1604 GL_DEPTH_COMPONENT
, GL_FLOAT
, 0,
1605 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1606 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1607 {WINED3DFMT_D32_FLOAT_S8X24_UINT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1608 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 0,
1609 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1610 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1611 {WINED3DFMT_S8_UINT_D24_FLOAT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1612 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 8,
1613 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1614 ARB_DEPTH_BUFFER_FLOAT
, convert_s8_uint_d24_float
},
1615 {WINED3DFMT_R32G32B32A32_UINT
, GL_RGBA32UI
, GL_RGBA32UI
, 0,
1616 GL_RGBA_INTEGER
, GL_UNSIGNED_INT
, 0,
1617 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1618 EXT_TEXTURE_INTEGER
, NULL
},
1619 {WINED3DFMT_R32G32B32A32_SINT
, GL_RGBA32I
, GL_RGBA32I
, 0,
1620 GL_RGBA_INTEGER
, GL_INT
, 0,
1621 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1622 EXT_TEXTURE_INTEGER
, NULL
},
1623 /* Vendor-specific formats */
1624 {WINED3DFMT_ATI1N
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1625 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1626 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1627 | WINED3DFMT_FLAG_COMPRESSED
,
1628 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1629 {WINED3DFMT_ATI2N
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, 0,
1630 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1631 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1632 | WINED3DFMT_FLAG_COMPRESSED
,
1633 ATI_TEXTURE_COMPRESSION_3DC
, NULL
},
1634 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1635 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1636 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1637 | WINED3DFMT_FLAG_COMPRESSED
,
1638 EXT_TEXTURE_COMPRESSION_RGTC
, NULL
},
1639 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1640 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1641 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1642 | WINED3DFMT_FLAG_COMPRESSED
,
1643 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1644 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1645 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 0,
1646 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1647 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
,
1648 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1649 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1650 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1651 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1652 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
,
1653 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1654 {WINED3DFMT_NULL
, 0, 0, 0,
1655 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1656 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
,
1657 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1660 struct wined3d_format_srgb_info
1662 enum wined3d_format_id srgb_format_id
;
1663 enum wined3d_format_id base_format_id
;
1666 static const struct wined3d_format_srgb_info format_srgb_info
[] =
1668 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_UNORM
},
1669 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_UNORM
},
1670 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_UNORM
},
1671 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_UNORM
},
1672 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_UNORM
},
1673 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_UNORM
},
1674 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_UNORM
},
1677 static inline int get_format_idx(enum wined3d_format_id format_id
)
1681 if (format_id
< WINED3D_FORMAT_FOURCC_BASE
)
1684 for (i
= 0; i
< ARRAY_SIZE(format_index_remap
); ++i
)
1686 if (format_index_remap
[i
].id
== format_id
)
1687 return format_index_remap
[i
].idx
;
1693 static struct wined3d_format
*get_format_internal(struct wined3d_gl_info
*gl_info
,
1694 enum wined3d_format_id format_id
)
1698 if ((fmt_idx
= get_format_idx(format_id
)) == -1)
1700 ERR("Format %s (%#x) not found.\n", debug_d3dformat(format_id
), format_id
);
1704 return &gl_info
->formats
[fmt_idx
];
1707 static void copy_format(struct wined3d_format
*dst_format
, const struct wined3d_format
*src_format
)
1709 enum wined3d_format_id id
= dst_format
->id
;
1710 *dst_format
= *src_format
;
1711 dst_format
->id
= id
;
1714 static void format_set_flag(struct wined3d_format
*format
, unsigned int flag
)
1718 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1719 format
->flags
[i
] |= flag
;
1722 static void format_clear_flag(struct wined3d_format
*format
, unsigned int flag
)
1726 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1727 format
->flags
[i
] &= ~flag
;
1730 static enum wined3d_channel_type
map_channel_type(char t
)
1735 return WINED3D_CHANNEL_TYPE_UNORM
;
1737 return WINED3D_CHANNEL_TYPE_SNORM
;
1739 return WINED3D_CHANNEL_TYPE_UINT
;
1741 return WINED3D_CHANNEL_TYPE_SINT
;
1743 return WINED3D_CHANNEL_TYPE_FLOAT
;
1745 return WINED3D_CHANNEL_TYPE_DEPTH
;
1747 return WINED3D_CHANNEL_TYPE_STENCIL
;
1749 return WINED3D_CHANNEL_TYPE_UNUSED
;
1751 ERR("Invalid channel type '%c'.\n", t
);
1752 return WINED3D_CHANNEL_TYPE_NONE
;
1756 static BOOL
init_format_base_info(struct wined3d_gl_info
*gl_info
)
1758 struct wined3d_format
*format
;
1761 gl_info
->format_count
= WINED3D_FORMAT_COUNT
;
1762 if (!(gl_info
->formats
= wined3d_calloc(gl_info
->format_count
1763 + ARRAY_SIZE(typeless_depth_stencil_formats
), sizeof(*gl_info
->formats
))))
1765 ERR("Failed to allocate memory.\n");
1769 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
1771 if (!(format
= get_format_internal(gl_info
, formats
[i
].id
)))
1774 format
->id
= formats
[i
].id
;
1775 format
->red_size
= formats
[i
].red_size
;
1776 format
->green_size
= formats
[i
].green_size
;
1777 format
->blue_size
= formats
[i
].blue_size
;
1778 format
->alpha_size
= formats
[i
].alpha_size
;
1779 format
->red_offset
= formats
[i
].red_offset
;
1780 format
->green_offset
= formats
[i
].green_offset
;
1781 format
->blue_offset
= formats
[i
].blue_offset
;
1782 format
->alpha_offset
= formats
[i
].alpha_offset
;
1783 format
->byte_count
= formats
[i
].bpp
;
1784 format
->depth_size
= formats
[i
].depth_size
;
1785 format
->stencil_size
= formats
[i
].stencil_size
;
1786 format
->block_width
= 1;
1787 format
->block_height
= 1;
1788 format
->block_byte_count
= formats
[i
].bpp
;
1791 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
1793 const struct wined3d_format
*typeless_format
;
1796 if (!(format
= get_format_internal(gl_info
, typed_formats
[i
].id
)))
1799 if (!(typeless_format
= get_format_internal(gl_info
, typed_formats
[i
].typeless_id
)))
1802 format
->id
= typed_formats
[i
].id
;
1803 format
->red_size
= typeless_format
->red_size
;
1804 format
->green_size
= typeless_format
->green_size
;
1805 format
->blue_size
= typeless_format
->blue_size
;
1806 format
->alpha_size
= typeless_format
->alpha_size
;
1807 format
->red_offset
= typeless_format
->red_offset
;
1808 format
->green_offset
= typeless_format
->green_offset
;
1809 format
->blue_offset
= typeless_format
->blue_offset
;
1810 format
->alpha_offset
= typeless_format
->alpha_offset
;
1811 format
->byte_count
= typeless_format
->byte_count
;
1812 format
->depth_size
= typeless_format
->depth_size
;
1813 format
->stencil_size
= typeless_format
->stencil_size
;
1814 format
->block_width
= typeless_format
->block_width
;
1815 format
->block_height
= typeless_format
->block_height
;
1816 format
->block_byte_count
= typeless_format
->block_byte_count
;
1817 format
->typeless_id
= typeless_format
->id
;
1819 for (j
= 0; j
< strlen(typed_formats
[i
].channels
); ++j
)
1821 enum wined3d_channel_type channel_type
= map_channel_type(typed_formats
[i
].channels
[j
]);
1822 if (channel_type
== WINED3D_CHANNEL_TYPE_UINT
|| channel_type
== WINED3D_CHANNEL_TYPE_SINT
)
1823 flags
|= WINED3DFMT_FLAG_INTEGER
;
1824 if (channel_type
== WINED3D_CHANNEL_TYPE_FLOAT
)
1825 flags
|= WINED3DFMT_FLAG_FLOAT
;
1827 if (channel_type
== WINED3D_CHANNEL_TYPE_DEPTH
&& !format
->depth_size
)
1829 format
->depth_size
= format
->red_size
;
1830 format
->red_size
= format
->red_offset
= 0;
1834 format_set_flag(format
, flags
);
1837 for (i
= 0; i
< ARRAY_SIZE(ddi_formats
); ++i
)
1839 if (!(format
= get_format_internal(gl_info
, ddi_formats
[i
].id
)))
1842 format
->ddi_format
= ddi_formats
[i
].ddi_format
;
1845 for (i
= 0; i
< ARRAY_SIZE(format_base_flags
); ++i
)
1847 if (!(format
= get_format_internal(gl_info
, format_base_flags
[i
].id
)))
1850 format_set_flag(format
, format_base_flags
[i
].flags
);
1856 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
1860 static BOOL
init_format_block_info(struct wined3d_gl_info
*gl_info
)
1862 struct wined3d_format
*format
;
1865 for (i
= 0; i
< ARRAY_SIZE(format_block_info
); ++i
)
1867 if (!(format
= get_format_internal(gl_info
, format_block_info
[i
].id
)))
1870 format
->block_width
= format_block_info
[i
].block_width
;
1871 format
->block_height
= format_block_info
[i
].block_height
;
1872 format
->block_byte_count
= format_block_info
[i
].block_byte_count
;
1873 format_set_flag(format
, WINED3DFMT_FLAG_BLOCKS
);
1874 if (!format_block_info
[i
].verify
)
1875 format_set_flag(format
, WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
);
1881 static GLenum
wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type
)
1885 case WINED3D_GL_RES_TYPE_TEX_1D
:
1886 return GL_TEXTURE_1D
;
1887 case WINED3D_GL_RES_TYPE_TEX_2D
:
1888 return GL_TEXTURE_2D
;
1889 case WINED3D_GL_RES_TYPE_TEX_3D
:
1890 return GL_TEXTURE_3D
;
1891 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1892 return GL_TEXTURE_CUBE_MAP_ARB
;
1893 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1894 return GL_TEXTURE_RECTANGLE_ARB
;
1895 case WINED3D_GL_RES_TYPE_BUFFER
:
1896 return GL_TEXTURE_2D
; /* TODO: GL_TEXTURE_BUFFER. */
1897 case WINED3D_GL_RES_TYPE_RB
:
1898 return GL_RENDERBUFFER
;
1899 case WINED3D_GL_RES_TYPE_COUNT
:
1902 ERR("Unexpected GL resource type %u.\n", type
);
1906 static void delete_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
1907 enum wined3d_gl_resource_type d3d_type
, GLuint object
)
1911 case WINED3D_GL_RES_TYPE_TEX_1D
:
1912 case WINED3D_GL_RES_TYPE_TEX_2D
:
1913 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1914 case WINED3D_GL_RES_TYPE_TEX_3D
:
1915 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1916 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &object
);
1919 case WINED3D_GL_RES_TYPE_RB
:
1920 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &object
);
1923 case WINED3D_GL_RES_TYPE_BUFFER
:
1924 case WINED3D_GL_RES_TYPE_COUNT
:
1929 /* Context activation is done by the caller. */
1930 static void create_and_bind_fbo_attachment(const struct wined3d_gl_info
*gl_info
, unsigned int flags
,
1931 enum wined3d_gl_resource_type d3d_type
, GLuint
*object
, GLenum internal
, GLenum format
, GLenum type
)
1933 GLenum attach_type
= flags
& WINED3DFMT_FLAG_DEPTH
?
1934 GL_DEPTH_ATTACHMENT
: GL_COLOR_ATTACHMENT0
;
1938 case WINED3D_GL_RES_TYPE_TEX_1D
:
1939 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1940 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, *object
);
1941 gl_info
->gl_ops
.gl
.p_glTexImage1D(GL_TEXTURE_1D
, 0, internal
, 16, 0, format
, type
, NULL
);
1942 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1943 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1945 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_1D
,
1947 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1948 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_TEXTURE_1D
,
1952 case WINED3D_GL_RES_TYPE_TEX_2D
:
1953 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1954 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1955 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(d3d_type
), *object
);
1956 gl_info
->gl_ops
.gl
.p_glTexImage2D(wined3d_gl_type_to_enum(d3d_type
), 0, internal
, 16, 16, 0,
1957 format
, type
, NULL
);
1958 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1959 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1961 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
1962 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
1963 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1964 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1965 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
1968 case WINED3D_GL_RES_TYPE_TEX_3D
:
1969 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1970 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_3D
, *object
);
1971 GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D
, 0, internal
, 16, 16, 16, 0, format
, type
, NULL
));
1972 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1973 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1975 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, attach_type
,
1976 GL_TEXTURE_3D
, *object
, 0, 0);
1977 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1978 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1979 GL_TEXTURE_3D
, *object
, 0, 0);
1982 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1983 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1984 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, *object
);
1985 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, internal
, 16, 16, 0,
1986 format
, type
, NULL
);
1987 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
, 0, internal
, 16, 16, 0,
1988 format
, type
, NULL
);
1989 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
, 0, internal
, 16, 16, 0,
1990 format
, type
, NULL
);
1991 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
, 0, internal
, 16, 16, 0,
1992 format
, type
, NULL
);
1993 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
, 0, internal
, 16, 16, 0,
1994 format
, type
, NULL
);
1995 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
, 0, internal
, 16, 16, 0,
1996 format
, type
, NULL
);
1997 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1998 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2000 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
2001 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
2002 if (flags
& WINED3DFMT_FLAG_STENCIL
)
2003 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
2004 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
2007 case WINED3D_GL_RES_TYPE_RB
:
2008 gl_info
->fbo_ops
.glGenRenderbuffers(1, object
);
2009 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, *object
);
2010 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, internal
, 16, 16);
2011 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, attach_type
, GL_RENDERBUFFER
,
2013 if (flags
& WINED3DFMT_FLAG_STENCIL
)
2014 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
,
2018 case WINED3D_GL_RES_TYPE_BUFFER
:
2019 case WINED3D_GL_RES_TYPE_COUNT
:
2023 /* Ideally we'd skip all formats already known not to work on textures
2024 * by checking for WINED3DFMT_FLAG_TEXTURE here. However, we want to
2025 * know if we can attach WINED3DFMT_P8_UINT textures to FBOs, and this
2026 * format never has WINED3DFMT_FLAG_TEXTURE set. Instead, swallow GL
2027 * errors generated by invalid formats. */
2028 while (gl_info
->gl_ops
.gl
.p_glGetError());
2031 static void draw_test_quad(struct wined3d_caps_gl_ctx
*ctx
, const struct wined3d_vec3
*geometry
,
2032 const struct wined3d_color
*color
)
2034 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2035 static const struct wined3d_vec3 default_geometry
[] =
2037 {-1.0f
, -1.0f
, 0.0f
},
2038 { 1.0f
, -1.0f
, 0.0f
},
2039 {-1.0f
, 1.0f
, 0.0f
},
2040 { 1.0f
, 1.0f
, 0.0f
},
2042 static const char vs_core_header
[] =
2046 "out vec4 out_color;\n"
2048 static const char vs_legacy_header
[] =
2050 "attribute vec4 pos;\n"
2051 "attribute vec4 color;\n"
2052 "varying vec4 out_color;\n"
2054 static const char vs_body
[] =
2057 " gl_Position = pos;\n"
2058 " out_color = color;\n"
2060 static const char fs_core
[] =
2062 "in vec4 out_color;\n"
2063 "out vec4 fragment_color;\n"
2067 " fragment_color = out_color;\n"
2069 static const char fs_legacy
[] =
2071 "varying vec4 out_color;\n"
2075 " gl_FragData[0] = out_color;\n"
2077 const char *source
[2];
2078 GLuint vs_id
, fs_id
;
2082 geometry
= default_geometry
;
2084 if (!gl_info
->supported
[ARB_VERTEX_BUFFER_OBJECT
] || !gl_info
->supported
[ARB_VERTEX_SHADER
]
2085 || !gl_info
->supported
[ARB_FRAGMENT_SHADER
])
2087 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
2088 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
2089 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2090 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
2091 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2093 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
2094 gl_info
->gl_ops
.gl
.p_glColor4f(color
->r
, color
->g
, color
->b
, color
->a
);
2095 for (i
= 0; i
< 4; ++i
)
2096 gl_info
->gl_ops
.gl
.p_glVertex3fv(&geometry
[i
].x
);
2097 gl_info
->gl_ops
.gl
.p_glEnd();
2098 checkGLcall("Drawing a quad");
2103 GL_EXTCALL(glGenBuffers(1, &ctx
->test_vbo
));
2104 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, ctx
->test_vbo
));
2105 GL_EXTCALL(glBufferData(GL_ARRAY_BUFFER
, sizeof(struct wined3d_vec3
) * 4, geometry
, GL_STREAM_DRAW
));
2106 GL_EXTCALL(glVertexAttribPointer(0, 3, GL_FLOAT
, FALSE
, 0, NULL
));
2107 GL_EXTCALL(glVertexAttrib4f(1, color
->r
, color
->g
, color
->b
, color
->a
));
2108 GL_EXTCALL(glEnableVertexAttribArray(0));
2109 GL_EXTCALL(glDisableVertexAttribArray(1));
2111 if (!ctx
->test_program_id
)
2113 ctx
->test_program_id
= GL_EXTCALL(glCreateProgram());
2115 vs_id
= GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER
));
2116 source
[0] = gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? vs_legacy_header
: vs_core_header
;
2117 source
[1] = vs_body
;
2118 GL_EXTCALL(glShaderSource(vs_id
, 2, source
, NULL
));
2119 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, vs_id
));
2120 GL_EXTCALL(glDeleteShader(vs_id
));
2122 fs_id
= GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER
));
2123 source
[0] = gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? fs_legacy
: fs_core
;
2124 GL_EXTCALL(glShaderSource(fs_id
, 1, source
, NULL
));
2125 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, fs_id
));
2126 GL_EXTCALL(glDeleteShader(fs_id
));
2128 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 0, "pos"));
2129 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 1, "color"));
2131 GL_EXTCALL(glCompileShader(vs_id
));
2132 print_glsl_info_log(gl_info
, vs_id
, FALSE
);
2133 GL_EXTCALL(glCompileShader(fs_id
));
2134 print_glsl_info_log(gl_info
, fs_id
, FALSE
);
2135 GL_EXTCALL(glLinkProgram(ctx
->test_program_id
));
2136 shader_glsl_validate_link(gl_info
, ctx
->test_program_id
);
2138 GL_EXTCALL(glUseProgram(ctx
->test_program_id
));
2140 gl_info
->gl_ops
.gl
.p_glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
2142 GL_EXTCALL(glUseProgram(0));
2143 GL_EXTCALL(glDisableVertexAttribArray(0));
2144 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, 0));
2145 checkGLcall("Drawing a quad");
2148 /* Context activation is done by the caller. */
2149 static void check_fbo_compat(struct wined3d_caps_gl_ctx
*ctx
, struct wined3d_format
*format
)
2151 /* Check if the default internal format is supported as a frame buffer
2152 * target, otherwise fall back to the render target internal.
2154 * Try to stick to the standard format if possible, this limits precision differences. */
2155 static const struct wined3d_color black
= {0.0f
, 0.0f
, 0.0f
, 1.0f
};
2156 static const struct wined3d_color half_transparent_red
= {1.0f
, 0.0f
, 0.0f
, 0.5f
};
2157 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2158 GLenum status
, rt_internal
= format
->rtInternal
;
2159 GLuint object
, color_rb
;
2160 enum wined3d_gl_resource_type type
;
2161 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2163 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2165 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
2167 const char *type_string
= "color";
2169 if (type
== WINED3D_GL_RES_TYPE_BUFFER
)
2172 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->glInternal
,
2173 format
->glFormat
, format
->glType
);
2175 if (format
->flags
[type
] & (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2177 gl_info
->fbo_ops
.glGenRenderbuffers(1, &color_rb
);
2178 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, color_rb
);
2179 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2180 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 1);
2182 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 16);
2184 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2185 GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, color_rb
);
2186 checkGLcall("Create and attach color rb attachment");
2187 type_string
= "depth / stencil";
2190 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2191 checkGLcall("Framebuffer format check");
2193 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2195 TRACE("Format %s is supported as FBO %s attachment, type %u.\n",
2196 debug_d3dformat(format
->id
), type_string
, type
);
2197 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2198 format
->rtInternal
= format
->glInternal
;
2199 regular_fmt_used
= TRUE
;
2205 if (format
->flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
2207 WARN("Format %s with rendertarget flag is not supported as FBO color attachment (type %u),"
2208 " and no fallback specified.\n", debug_d3dformat(format
->id
), type
);
2209 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2213 TRACE("Format %s is not supported as FBO %s attachment, type %u.\n",
2214 debug_d3dformat(format
->id
), type_string
, type
);
2216 format
->rtInternal
= format
->glInternal
;
2220 TRACE("Format %s is not supported as FBO %s attachment (type %u),"
2221 " trying rtInternal format as fallback.\n",
2222 debug_d3dformat(format
->id
), type_string
, type
);
2224 while (gl_info
->gl_ops
.gl
.p_glGetError());
2226 delete_fbo_attachment(gl_info
, type
, object
);
2227 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->rtInternal
,
2228 format
->glFormat
, format
->glType
);
2230 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2231 checkGLcall("Framebuffer format check");
2233 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2235 TRACE("Format %s rtInternal format is supported as FBO %s attachment, type %u.\n",
2236 debug_d3dformat(format
->id
), type_string
, type
);
2237 fallback_fmt_used
= TRUE
;
2241 WARN("Format %s rtInternal format is not supported as FBO %s attachment, type %u.\n",
2242 debug_d3dformat(format
->id
), type_string
, type
);
2243 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2248 if (status
== GL_FRAMEBUFFER_COMPLETE
2249 && ((format
->flags
[type
] & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
)
2250 || !(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2251 && !(format
->flags
[type
] & WINED3DFMT_FLAG_INTEGER
)
2252 && format
->id
!= WINED3DFMT_NULL
&& format
->id
!= WINED3DFMT_P8_UINT
2253 && format
->glFormat
!= GL_LUMINANCE
&& format
->glFormat
!= GL_LUMINANCE_ALPHA
2254 && (format
->red_size
|| format
->alpha_size
))
2256 DWORD readback
[16 * 16 * 16], color
, r_range
, a_range
;
2261 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
]
2262 || gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2264 gl_info
->fbo_ops
.glGenRenderbuffers(1, &rb
);
2265 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
2266 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2267 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 1);
2269 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 16);
2270 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2271 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2272 checkGLcall("RB attachment");
2275 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2276 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.0f
, 1.0f
);
2277 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
2278 if (gl_info
->gl_ops
.gl
.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION
)
2280 while (gl_info
->gl_ops
.gl
.p_glGetError());
2281 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2282 debug_d3dformat(format
->id
), type
);
2283 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2287 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2288 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2289 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2291 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 16);
2292 gl_info
->gl_ops
.gl
.p_glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2294 draw_test_quad(ctx
, NULL
, &black
);
2296 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2298 draw_test_quad(ctx
, NULL
, &half_transparent_red
);
2300 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2304 case WINED3D_GL_RES_TYPE_TEX_1D
:
2305 /* Rebinding texture to workaround a fglrx bug. */
2306 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, object
);
2307 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_1D
, 0, GL_BGRA
,
2308 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2309 color
= readback
[7];
2312 case WINED3D_GL_RES_TYPE_TEX_2D
:
2313 case WINED3D_GL_RES_TYPE_TEX_3D
:
2314 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2315 /* Rebinding texture to workaround a fglrx bug. */
2316 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(type
), object
);
2317 gl_info
->gl_ops
.gl
.p_glGetTexImage(wined3d_gl_type_to_enum(type
), 0, GL_BGRA
,
2318 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2319 color
= readback
[7 * 16 + 7];
2322 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2323 /* Rebinding texture to workaround a fglrx bug. */
2324 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, object
);
2325 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, GL_BGRA
,
2326 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2327 color
= readback
[7 * 16 + 7];
2330 case WINED3D_GL_RES_TYPE_RB
:
2331 gl_info
->gl_ops
.gl
.p_glReadPixels(0, 0, 16, 16,
2332 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2333 color
= readback
[7 * 16 + 7];
2336 case WINED3D_GL_RES_TYPE_BUFFER
:
2337 case WINED3D_GL_RES_TYPE_COUNT
:
2341 checkGLcall("Post-pixelshader blending check");
2344 r
= (color
& 0x00ff0000u
) >> 16;
2346 r_range
= format
->red_size
< 8 ? 1u << (8 - format
->red_size
) : 1;
2347 a_range
= format
->alpha_size
< 8 ? 1u << (8 - format
->alpha_size
) : 1;
2348 if (format
->red_size
&& (r
< 0x7f - r_range
|| r
> 0x7f + r_range
))
2350 else if (format
->alpha_size
> 1 && (a
< 0xbf - a_range
|| a
> 0xbf + a_range
))
2354 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2355 debug_d3dformat(format
->id
), type
);
2356 TRACE("Color output: %#x\n", color
);
2357 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2361 TRACE("Format %s supports post-pixelshader blending, type %u.\n",
2362 debug_d3dformat(format
->id
), type
);
2363 TRACE("Color output: %#x\n", color
);
2364 format
->flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2368 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
]
2369 || gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2371 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2372 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2373 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &rb
);
2374 checkGLcall("RB cleanup");
2378 if (format
->glInternal
!= format
->glGammaInternal
)
2380 delete_fbo_attachment(gl_info
, type
, object
);
2381 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->glGammaInternal
,
2382 format
->glFormat
, format
->glType
);
2384 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2385 checkGLcall("Framebuffer format check");
2387 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2389 TRACE("Format %s's sRGB format is FBO attachable, type %u.\n",
2390 debug_d3dformat(format
->id
), type
);
2391 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2392 if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2393 format
->glInternal
= format
->glGammaInternal
;
2397 WARN("Format %s's sRGB format is not FBO attachable, type %u.\n",
2398 debug_d3dformat(format
->id
), type
);
2399 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2402 else if (status
== GL_FRAMEBUFFER_COMPLETE
)
2403 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2405 if (format
->flags
[type
] & (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2407 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, 0);
2408 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &color_rb
);
2411 delete_fbo_attachment(gl_info
, type
, object
);
2412 checkGLcall("Framebuffer format check cleanup");
2415 if (fallback_fmt_used
&& regular_fmt_used
)
2417 FIXME("Format %s needs different render target formats for different resource types.\n",
2418 debug_d3dformat(format
->id
));
2419 format_clear_flag(format
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
2420 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2424 static void query_format_flag(struct wined3d_gl_info
*gl_info
, struct wined3d_format
*format
,
2425 GLint internal
, GLenum pname
, DWORD flag
, const char *string
)
2428 enum wined3d_gl_resource_type type
;
2430 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
2432 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
), internal
, pname
, 1, &value
);
2433 if (value
== GL_FULL_SUPPORT
)
2435 TRACE("Format %s supports %s, resource type %u.\n", debug_d3dformat(format
->id
), string
, type
);
2436 format
->flags
[type
] |= flag
;
2440 TRACE("Format %s doesn't support %s, resource type %u.\n", debug_d3dformat(format
->id
), string
, type
);
2441 format
->flags
[type
] &= ~flag
;
2446 /* Context activation is done by the caller. */
2447 static void init_format_fbo_compat_info(struct wined3d_caps_gl_ctx
*ctx
)
2449 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2450 unsigned int i
, type
;
2453 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2455 for (i
= 0; i
< gl_info
->format_count
; ++i
)
2458 struct wined3d_format
*format
= &gl_info
->formats
[i
];
2459 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2460 GLenum rt_internal
= format
->rtInternal
;
2462 if (!format
->glInternal
)
2465 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
2467 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2468 format
->glInternal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2469 if (value
== GL_FULL_SUPPORT
)
2471 TRACE("Format %s is supported as FBO color attachment, resource type %u.\n",
2472 debug_d3dformat(format
->id
), type
);
2473 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2474 format
->rtInternal
= format
->glInternal
;
2475 regular_fmt_used
= TRUE
;
2477 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2478 format
->glInternal
, GL_FRAMEBUFFER_BLEND
, 1, &value
);
2479 if (value
== GL_FULL_SUPPORT
)
2481 TRACE("Format %s supports post-pixelshader blending, resource type %u.\n",
2482 debug_d3dformat(format
->id
), type
);
2483 format
->flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2487 TRACE("Format %s doesn't support post-pixelshader blending, resource typed %u.\n",
2488 debug_d3dformat(format
->id
), type
);
2489 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2496 if (format
->flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
2498 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
2499 " and no fallback specified, resource type %u.\n",
2500 debug_d3dformat(format
->id
), type
);
2501 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2504 TRACE("Format %s is not supported as FBO color attachment,"
2505 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2506 format
->rtInternal
= format
->glInternal
;
2510 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2511 rt_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2512 if (value
== GL_FULL_SUPPORT
)
2514 TRACE("Format %s rtInternal format is supported as FBO color attachment,"
2515 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2516 fallback_fmt_used
= TRUE
;
2520 WARN("Format %s rtInternal format is not supported as FBO color attachment,"
2521 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2522 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2527 if (format
->glInternal
!= format
->glGammaInternal
)
2529 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2530 format
->glGammaInternal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2531 if (value
== GL_FULL_SUPPORT
)
2533 TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n",
2534 debug_d3dformat(format
->id
), type
);
2535 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2536 if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2537 format
->glInternal
= format
->glGammaInternal
;
2541 WARN("Format %s's sRGB format is not FBO attachable, resource type %u.\n",
2542 debug_d3dformat(format
->id
), type
);
2543 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2546 else if (format
->flags
[type
] & WINED3DFMT_FLAG_FBO_ATTACHABLE
)
2547 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2550 if (fallback_fmt_used
&& regular_fmt_used
)
2552 FIXME("Format %s needs different render target formats for different resource types.\n",
2553 debug_d3dformat(format
->id
));
2554 format_clear_flag(format
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
2555 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2561 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2563 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2564 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2565 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2566 gl_info
->gl_ops
.gl
.p_glReadBuffer(GL_COLOR_ATTACHMENT0
);
2569 for (i
= 0; i
< gl_info
->format_count
; ++i
)
2571 struct wined3d_format
*format
= &gl_info
->formats
[i
];
2573 if (!format
->glInternal
) continue;
2575 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_COMPRESSED
)
2577 TRACE("Skipping format %s because it's a compressed format.\n",
2578 debug_d3dformat(format
->id
));
2582 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2584 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format
->id
));
2585 check_fbo_compat(ctx
, format
);
2589 format
->rtInternal
= format
->glInternal
;
2593 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2594 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2597 static GLenum
lookup_gl_view_class(GLenum internal_format
)
2601 GLenum internal_format
;
2607 {GL_RGBA32F
, GL_VIEW_CLASS_128_BITS
},
2608 {GL_RGBA32UI
, GL_VIEW_CLASS_128_BITS
},
2609 {GL_RGBA32I
, GL_VIEW_CLASS_128_BITS
},
2611 {GL_RGB32F
, GL_VIEW_CLASS_96_BITS
},
2612 {GL_RGB32UI
, GL_VIEW_CLASS_96_BITS
},
2613 {GL_RGB32I
, GL_VIEW_CLASS_96_BITS
},
2615 {GL_RGBA16F
, GL_VIEW_CLASS_64_BITS
},
2616 {GL_RG32F
, GL_VIEW_CLASS_64_BITS
},
2617 {GL_RGBA16UI
, GL_VIEW_CLASS_64_BITS
},
2618 {GL_RG32UI
, GL_VIEW_CLASS_64_BITS
},
2619 {GL_RGBA16I
, GL_VIEW_CLASS_64_BITS
},
2620 {GL_RG32I
, GL_VIEW_CLASS_64_BITS
},
2621 {GL_RGBA16
, GL_VIEW_CLASS_64_BITS
},
2622 {GL_RGBA16_SNORM
, GL_VIEW_CLASS_64_BITS
},
2624 {GL_RGB16
, GL_VIEW_CLASS_48_BITS
},
2625 {GL_RGB16_SNORM
, GL_VIEW_CLASS_48_BITS
},
2626 {GL_RGB16F
, GL_VIEW_CLASS_48_BITS
},
2627 {GL_RGB16UI
, GL_VIEW_CLASS_48_BITS
},
2628 {GL_RGB16I
, GL_VIEW_CLASS_48_BITS
},
2630 {GL_RG16F
, GL_VIEW_CLASS_32_BITS
},
2631 {GL_R11F_G11F_B10F
, GL_VIEW_CLASS_32_BITS
},
2632 {GL_R32F
, GL_VIEW_CLASS_32_BITS
},
2633 {GL_RGB10_A2UI
, GL_VIEW_CLASS_32_BITS
},
2634 {GL_RGBA8UI
, GL_VIEW_CLASS_32_BITS
},
2635 {GL_RG16UI
, GL_VIEW_CLASS_32_BITS
},
2636 {GL_R32UI
, GL_VIEW_CLASS_32_BITS
},
2637 {GL_RGBA8I
, GL_VIEW_CLASS_32_BITS
},
2638 {GL_RG16I
, GL_VIEW_CLASS_32_BITS
},
2639 {GL_R32I
, GL_VIEW_CLASS_32_BITS
},
2640 {GL_RGB10_A2
, GL_VIEW_CLASS_32_BITS
},
2641 {GL_RGBA8
, GL_VIEW_CLASS_32_BITS
},
2642 {GL_RG16
, GL_VIEW_CLASS_32_BITS
},
2643 {GL_RGBA8_SNORM
, GL_VIEW_CLASS_32_BITS
},
2644 {GL_RG16_SNORM
, GL_VIEW_CLASS_32_BITS
},
2645 {GL_SRGB8_ALPHA8
, GL_VIEW_CLASS_32_BITS
},
2646 {GL_RGB9_E5
, GL_VIEW_CLASS_32_BITS
},
2648 {GL_RGB8
, GL_VIEW_CLASS_24_BITS
},
2649 {GL_RGB8_SNORM
, GL_VIEW_CLASS_24_BITS
},
2650 {GL_SRGB8
, GL_VIEW_CLASS_24_BITS
},
2651 {GL_RGB8UI
, GL_VIEW_CLASS_24_BITS
},
2652 {GL_RGB8I
, GL_VIEW_CLASS_24_BITS
},
2654 {GL_R16F
, GL_VIEW_CLASS_16_BITS
},
2655 {GL_RG8UI
, GL_VIEW_CLASS_16_BITS
},
2656 {GL_R16UI
, GL_VIEW_CLASS_16_BITS
},
2657 {GL_RG8I
, GL_VIEW_CLASS_16_BITS
},
2658 {GL_R16I
, GL_VIEW_CLASS_16_BITS
},
2659 {GL_RG8
, GL_VIEW_CLASS_16_BITS
},
2660 {GL_R16
, GL_VIEW_CLASS_16_BITS
},
2661 {GL_RG8_SNORM
, GL_VIEW_CLASS_16_BITS
},
2662 {GL_R16_SNORM
, GL_VIEW_CLASS_16_BITS
},
2664 {GL_R8UI
, GL_VIEW_CLASS_8_BITS
},
2665 {GL_R8I
, GL_VIEW_CLASS_8_BITS
},
2666 {GL_R8
, GL_VIEW_CLASS_8_BITS
},
2667 {GL_R8_SNORM
, GL_VIEW_CLASS_8_BITS
},
2670 {GL_COMPRESSED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
2671 {GL_COMPRESSED_SIGNED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
2673 {GL_COMPRESSED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
2674 {GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
2677 {GL_COMPRESSED_RGBA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
2678 {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
2680 {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
2681 {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
2684 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
2685 {GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
2687 {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
2688 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
2690 {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
2691 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
2693 {GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
2694 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
2699 for (i
= 0; i
< ARRAY_SIZE(view_classes
); ++i
)
2701 if (view_classes
[i
].internal_format
== internal_format
)
2702 return view_classes
[i
].view_class
;
2708 static void query_view_class(struct wined3d_format
*format
)
2710 GLenum internal_view_class
, gamma_view_class
, rt_view_class
;
2712 internal_view_class
= lookup_gl_view_class(format
->glInternal
);
2713 gamma_view_class
= lookup_gl_view_class(format
->glGammaInternal
);
2714 rt_view_class
= lookup_gl_view_class(format
->rtInternal
);
2716 if (internal_view_class
== gamma_view_class
|| gamma_view_class
== rt_view_class
)
2718 format
->gl_view_class
= internal_view_class
;
2719 TRACE("Format %s is member of GL view class %#x.\n",
2720 debug_d3dformat(format
->id
), format
->gl_view_class
);
2724 format
->gl_view_class
= GL_NONE
;
2728 static void query_internal_format(struct wined3d_adapter
*adapter
,
2729 struct wined3d_format
*format
, const struct wined3d_format_texture_info
*texture_info
,
2730 struct wined3d_gl_info
*gl_info
, BOOL srgb_write_supported
, BOOL srgb_format
)
2732 GLint count
, multisample_types
[MAX_MULTISAMPLE_TYPES
];
2733 unsigned int i
, max_log2
;
2735 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2737 query_format_flag(gl_info
, format
, format
->glInternal
, GL_VERTEX_TEXTURE
,
2738 WINED3DFMT_FLAG_VTF
, "vertex texture usage");
2739 query_format_flag(gl_info
, format
, format
->glInternal
, GL_FILTER
,
2740 WINED3DFMT_FLAG_FILTERING
, "filtering");
2742 if (srgb_format
|| format
->glGammaInternal
!= format
->glInternal
)
2744 query_format_flag(gl_info
, format
, format
->glGammaInternal
, GL_SRGB_READ
,
2745 WINED3DFMT_FLAG_SRGB_READ
, "sRGB read");
2747 if (srgb_write_supported
)
2748 query_format_flag(gl_info
, format
, format
->glGammaInternal
, GL_SRGB_WRITE
,
2749 WINED3DFMT_FLAG_SRGB_WRITE
, "sRGB write");
2751 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2753 if (!(format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & (WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
)))
2754 format
->glGammaInternal
= format
->glInternal
;
2755 else if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
2756 && gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2757 format
->glInternal
= format
->glGammaInternal
;
2762 if (!gl_info
->limits
.samplers
[WINED3D_SHADER_TYPE_VERTEX
])
2763 format_clear_flag(format
, WINED3DFMT_FLAG_VTF
);
2765 if (!(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2766 format_set_flag(format
, WINED3DFMT_FLAG_FILTERING
);
2767 else if (format
->id
!= WINED3DFMT_R32G32B32A32_FLOAT
&& format
->id
!= WINED3DFMT_R32_FLOAT
)
2768 format_clear_flag(format
, WINED3DFMT_FLAG_VTF
);
2770 if (srgb_format
|| format
->glGammaInternal
!= format
->glInternal
)
2772 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
2773 if (!gl_info
->supported
[EXT_TEXTURE_SRGB
])
2775 format
->glGammaInternal
= format
->glInternal
;
2776 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2778 else if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
2779 && gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2781 format
->glInternal
= format
->glGammaInternal
;
2785 if ((format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_SRGB_WRITE
) && !srgb_write_supported
)
2786 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2788 if (!gl_info
->supported
[ARB_DEPTH_TEXTURE
]
2789 && texture_info
->flags
& (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2791 format
->flags
[WINED3D_GL_RES_TYPE_TEX_1D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2792 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2793 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2794 format
->flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2795 format
->flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2799 query_view_class(format
);
2801 if (format
->glInternal
&& format
->flags
[WINED3D_GL_RES_TYPE_RB
]
2802 & (WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2804 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY
])
2806 GL_EXTCALL(glGetInternalformativ(GL_RENDERBUFFER
, format
->glInternal
,
2807 GL_NUM_SAMPLE_COUNTS
, 1, &count
));
2808 checkGLcall("glGetInternalformativ(GL_NUM_SAMPLE_COUNTS)");
2809 count
= min(count
, MAX_MULTISAMPLE_TYPES
);
2810 GL_EXTCALL(glGetInternalformativ(GL_RENDERBUFFER
, format
->glInternal
,
2811 GL_SAMPLES
, count
, multisample_types
));
2812 checkGLcall("glGetInternalformativ(GL_SAMPLES)");
2813 for (i
= 0; i
< count
; ++i
)
2815 if (multisample_types
[i
] > sizeof(format
->multisample_types
) * 8)
2817 format
->multisample_types
|= 1u << (multisample_types
[i
] - 1);
2822 max_log2
= wined3d_log2i(min(gl_info
->limits
.samples
,
2823 sizeof(format
->multisample_types
) * 8));
2824 for (i
= 1; i
<= max_log2
; ++i
)
2825 format
->multisample_types
|= 1u << ((1u << i
) - 1);
2830 static BOOL
init_format_texture_info(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
2832 struct wined3d_format
*format
, *srgb_format
;
2833 struct fragment_caps fragment_caps
;
2834 struct shader_caps shader_caps
;
2838 adapter
->fragment_pipe
->get_caps(gl_info
, &fragment_caps
);
2839 adapter
->shader_backend
->shader_get_caps(gl_info
, &shader_caps
);
2840 srgb_write
= (fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_SRGB_WRITE
)
2841 && (shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_SRGB_WRITE
);
2843 for (i
= 0; i
< ARRAY_SIZE(format_texture_info
); ++i
)
2845 if (!(format
= get_format_internal(gl_info
, format_texture_info
[i
].id
)))
2848 if (!gl_info
->supported
[format_texture_info
[i
].extension
])
2851 /* ARB_texture_rg defines floating point formats, but only if
2852 * ARB_texture_float is also supported. */
2853 if (!gl_info
->supported
[ARB_TEXTURE_FLOAT
]
2854 && (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_FLOAT
))
2857 /* ARB_texture_rg defines integer formats if EXT_texture_integer is also supported. */
2858 if (!gl_info
->supported
[EXT_TEXTURE_INTEGER
]
2859 && (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_INTEGER
))
2862 format
->glInternal
= format_texture_info
[i
].gl_internal
;
2863 format
->glGammaInternal
= format_texture_info
[i
].gl_srgb_internal
;
2864 format
->rtInternal
= format_texture_info
[i
].gl_rt_internal
;
2865 format
->glFormat
= format_texture_info
[i
].gl_format
;
2866 format
->glType
= format_texture_info
[i
].gl_type
;
2867 format
->color_fixup
= COLOR_FIXUP_IDENTITY
;
2868 format
->height_scale
.numerator
= 1;
2869 format
->height_scale
.denominator
= 1;
2871 format
->flags
[WINED3D_GL_RES_TYPE_TEX_1D
] |= format_texture_info
[i
].flags
;
2872 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] |= format_texture_info
[i
].flags
;
2873 format
->flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= format_texture_info
[i
].flags
;
2875 /* GL_ARB_depth_texture does not support 3D textures. It also says "cube textures are
2876 * problematic", but doesn't explicitly mandate that an error is generated. */
2877 if (gl_info
->supported
[EXT_TEXTURE3D
]
2878 && !(format_texture_info
[i
].flags
& (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
)))
2879 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] |= format_texture_info
[i
].flags
;
2881 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
2882 format
->flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= format_texture_info
[i
].flags
;
2884 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
2885 format
->flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] |= format_texture_info
[i
].flags
;
2887 format
->flags
[WINED3D_GL_RES_TYPE_RB
] |= format_texture_info
[i
].flags
;
2888 format
->flags
[WINED3D_GL_RES_TYPE_RB
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2890 if (format
->glGammaInternal
!= format
->glInternal
2891 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
2893 format
->glGammaInternal
= format
->glInternal
;
2894 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2897 query_internal_format(adapter
, format
, &format_texture_info
[i
], gl_info
, srgb_write
, FALSE
);
2899 /* Texture conversion stuff */
2900 format
->convert
= format_texture_info
[i
].convert
;
2901 format
->conv_byte_count
= format_texture_info
[i
].conv_byte_count
;
2904 for (j
= 0; j
< ARRAY_SIZE(format_srgb_info
); ++j
)
2906 if (format_srgb_info
[j
].base_format_id
== format
->id
)
2908 if (!(srgb_format
= get_format_internal(gl_info
, format_srgb_info
[j
].srgb_format_id
)))
2916 copy_format(srgb_format
, format
);
2918 if (gl_info
->supported
[EXT_TEXTURE_SRGB
]
2919 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
2921 srgb_format
->glInternal
= format_texture_info
[i
].gl_srgb_internal
;
2922 srgb_format
->glGammaInternal
= format_texture_info
[i
].gl_srgb_internal
;
2923 format_set_flag(srgb_format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2924 query_internal_format(adapter
, srgb_format
, &format_texture_info
[i
], gl_info
, srgb_write
, TRUE
);
2931 static BOOL
color_match(DWORD c1
, DWORD c2
, BYTE max_diff
)
2933 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2935 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2937 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2939 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2943 /* A context is provided by the caller */
2944 static BOOL
check_filter(const struct wined3d_gl_info
*gl_info
, GLenum internal
)
2946 static const DWORD data
[] = {0x00000000, 0xffffffff};
2947 GLuint tex
, fbo
, buffer
;
2948 DWORD readback
[16 * 1];
2951 /* Render a filtered texture and see what happens. This is intended to detect the lack of
2952 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
2953 * falling back to software. If this changes in the future this code will get fooled and
2954 * apps might hit the software path due to incorrectly advertised caps.
2956 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
2957 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
2958 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
2961 while (gl_info
->gl_ops
.gl
.p_glGetError());
2963 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &buffer
);
2964 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
2965 memset(readback
, 0x7e, sizeof(readback
));
2966 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 16, 1, 0,
2967 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, readback
);
2968 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2969 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2970 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
2971 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
2972 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
2974 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &tex
);
2975 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, tex
);
2976 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, internal
, 2, 1, 0,
2977 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, data
);
2978 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
2979 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
2980 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
2981 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
2982 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
2983 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
2985 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2986 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2987 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, buffer
, 0);
2988 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2990 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2991 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
2992 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
2993 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2994 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
2995 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2997 gl_info
->gl_ops
.gl
.p_glClearColor(0, 1, 0, 0);
2998 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3000 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
3001 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 0.0);
3002 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, -1.0f
);
3003 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 0.0);
3004 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, -1.0f
);
3005 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 1.0);
3006 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, 1.0f
);
3007 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 1.0);
3008 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, 1.0f
);
3009 gl_info
->gl_ops
.gl
.p_glEnd();
3011 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
3012 memset(readback
, 0x7f, sizeof(readback
));
3013 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3014 if (color_match(readback
[6], 0xffffffff, 5) || color_match(readback
[6], 0x00000000, 5)
3015 || color_match(readback
[9], 0xffffffff, 5) || color_match(readback
[9], 0x00000000, 5))
3017 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
3018 readback
[6], readback
[9]);
3023 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
3024 readback
[6], readback
[9]);
3028 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3029 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3030 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &tex
);
3031 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &buffer
);
3032 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
3034 if (gl_info
->gl_ops
.gl
.p_glGetError())
3036 FIXME("Error during filtering test for format %x, returning no filtering\n", internal
);
3043 static void init_format_filter_info(struct wined3d_gl_info
*gl_info
, enum wined3d_pci_vendor vendor
)
3045 struct wined3d_format
*format
;
3046 unsigned int fmt_idx
, i
;
3047 static const enum wined3d_format_id fmts16
[] =
3049 WINED3DFMT_R16_FLOAT
,
3050 WINED3DFMT_R16G16_FLOAT
,
3051 WINED3DFMT_R16G16B16A16_FLOAT
,
3055 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
3056 /* This was already handled by init_format_texture_info(). */
3059 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
3060 || !gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3062 WARN("No FBO support, or no FBO ORM, guessing filter info from GL caps\n");
3063 if (vendor
== HW_VENDOR_NVIDIA
&& gl_info
->supported
[ARB_TEXTURE_FLOAT
])
3065 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
3068 else if (gl_info
->limits
.glsl_varyings
> 44)
3070 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
3075 TRACE("Assuming no float16 blending\n");
3081 for(i
= 0; i
< (sizeof(fmts16
) / sizeof(*fmts16
)); i
++)
3083 fmt_idx
= get_format_idx(fmts16
[i
]);
3084 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_FILTERING
);
3090 for(i
= 0; i
< (sizeof(fmts16
) / sizeof(*fmts16
)); i
++)
3092 fmt_idx
= get_format_idx(fmts16
[i
]);
3093 format
= &gl_info
->formats
[fmt_idx
];
3094 if (!format
->glInternal
) continue; /* Not supported by GL */
3096 filtered
= check_filter(gl_info
, gl_info
->formats
[fmt_idx
].glInternal
);
3099 TRACE("Format %s supports filtering\n", debug_d3dformat(fmts16
[i
]));
3100 format_set_flag(format
, WINED3DFMT_FLAG_FILTERING
);
3104 TRACE("Format %s does not support filtering\n", debug_d3dformat(fmts16
[i
]));
3109 static void apply_format_fixups(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
3114 idx
= get_format_idx(WINED3DFMT_R16_FLOAT
);
3115 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3116 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3118 idx
= get_format_idx(WINED3DFMT_R32_FLOAT
);
3119 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3120 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3122 idx
= get_format_idx(WINED3DFMT_R16G16_UNORM
);
3123 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3124 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3126 idx
= get_format_idx(WINED3DFMT_R16G16_FLOAT
);
3127 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3128 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3130 idx
= get_format_idx(WINED3DFMT_R32G32_FLOAT
);
3131 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3132 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3134 /* GL_ATI_envmap_bumpmap in theory supports R8G8_SNORM but is no longer supported by
3136 if (gl_info
->supported
[NV_TEXTURE_SHADER
] || gl_info
->supported
[EXT_TEXTURE_SNORM
])
3138 /* R8G8_SNORM and R16G16_SNORM need a fixup of the undefined blue channel. OpenGL
3139 * returns 0.0 when sampling from it, DirectX 1.0. So we always have in-shader
3140 * conversion for this format. */
3141 idx
= get_format_idx(WINED3DFMT_R8G8_SNORM
);
3142 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3143 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3144 idx
= get_format_idx(WINED3DFMT_R16G16_SNORM
);
3145 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3146 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3150 /* Emulate using unsigned formats. This requires load-time conversion in addition to the
3152 idx
= get_format_idx(WINED3DFMT_R8G8_SNORM
);
3153 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3154 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3155 idx
= get_format_idx(WINED3DFMT_R16G16_SNORM
);
3156 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3157 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3158 idx
= get_format_idx(WINED3DFMT_R8G8B8A8_SNORM
);
3159 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3160 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 1, CHANNEL_SOURCE_Z
, 1, CHANNEL_SOURCE_W
);
3161 idx
= get_format_idx(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
3162 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3163 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Z
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
);
3166 if (!gl_info
->supported
[NV_TEXTURE_SHADER
])
3168 idx
= get_format_idx(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
3169 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3170 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_Z
, 0, CHANNEL_SOURCE_W
);
3173 if (gl_info
->supported
[ARB_TEXTURE_COMPRESSION_RGTC
] || gl_info
->supported
[EXT_TEXTURE_COMPRESSION_RGTC
])
3175 idx
= get_format_idx(WINED3DFMT_ATI1N
);
3176 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3177 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
);
3179 idx
= get_format_idx(WINED3DFMT_ATI2N
);
3180 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3181 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3183 else if (gl_info
->supported
[ATI_TEXTURE_COMPRESSION_3DC
])
3185 idx
= get_format_idx(WINED3DFMT_ATI2N
);
3186 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3187 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_W
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3190 if (!gl_info
->supported
[APPLE_YCBCR_422
])
3192 idx
= get_format_idx(WINED3DFMT_YUY2
);
3193 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUY2
);
3195 idx
= get_format_idx(WINED3DFMT_UYVY
);
3196 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_UYVY
);
3199 idx
= get_format_idx(WINED3DFMT_YV12
);
3200 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_HEIGHT_SCALE
);
3201 gl_info
->formats
[idx
].height_scale
.numerator
= 3;
3202 gl_info
->formats
[idx
].height_scale
.denominator
= 2;
3203 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YV12
);
3205 idx
= get_format_idx(WINED3DFMT_NV12
);
3206 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_HEIGHT_SCALE
);
3207 gl_info
->formats
[idx
].height_scale
.numerator
= 3;
3208 gl_info
->formats
[idx
].height_scale
.denominator
= 2;
3209 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_NV12
);
3211 if (!gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3213 idx
= get_format_idx(WINED3DFMT_A8_UNORM
);
3214 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3215 0, CHANNEL_SOURCE_ZERO
, 0, CHANNEL_SOURCE_ZERO
, 0, CHANNEL_SOURCE_ZERO
, 0, CHANNEL_SOURCE_X
);
3216 idx
= get_format_idx(WINED3DFMT_L8A8_UNORM
);
3217 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3218 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
);
3219 idx
= get_format_idx(WINED3DFMT_L4A4_UNORM
);
3220 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3221 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
);
3222 idx
= get_format_idx(WINED3DFMT_L16_UNORM
);
3223 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3224 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
);
3225 idx
= get_format_idx(WINED3DFMT_INTZ
);
3226 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3227 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
);
3230 if (gl_info
->supported
[ARB_TEXTURE_RG
])
3232 idx
= get_format_idx(WINED3DFMT_L8_UNORM
);
3233 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3234 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
);
3237 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
])
3239 idx
= get_format_idx(WINED3DFMT_P8_UINT
);
3240 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_P8
);
3243 if (gl_info
->supported
[ARB_VERTEX_ARRAY_BGRA
])
3245 idx
= get_format_idx(WINED3DFMT_B8G8R8A8_UNORM
);
3246 gl_info
->formats
[idx
].gl_vtx_format
= GL_BGRA
;
3249 if (!gl_info
->supported
[ARB_HALF_FLOAT_VERTEX
])
3251 /* Do not change the size of the type, it is CPU side. We have to change the GPU-side information though.
3252 * It is the job of the vertex buffer code to make sure that the vbos have the right format */
3253 idx
= get_format_idx(WINED3DFMT_R16G16_FLOAT
);
3254 gl_info
->formats
[idx
].gl_vtx_type
= GL_FLOAT
;
3256 idx
= get_format_idx(WINED3DFMT_R16G16B16A16_FLOAT
);
3257 gl_info
->formats
[idx
].gl_vtx_type
= GL_FLOAT
;
3260 if (!gl_info
->supported
[ARB_HALF_FLOAT_PIXEL
])
3262 idx
= get_format_idx(WINED3DFMT_R16_FLOAT
);
3263 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3265 idx
= get_format_idx(WINED3DFMT_R16G16_FLOAT
);
3266 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3268 idx
= get_format_idx(WINED3DFMT_R16G16B16A16_FLOAT
);
3269 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3272 if (gl_info
->quirks
& WINED3D_QUIRK_BROKEN_RGBA16
)
3274 idx
= get_format_idx(WINED3DFMT_R16G16B16A16_UNORM
);
3275 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3278 /* ATI instancing hack: Although ATI cards do not support Shader Model
3279 * 3.0, they support instancing. To query if the card supports instancing
3280 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
3281 * is used. Should an application check for this, provide a proper return
3282 * value. We can do instancing with all shader versions, but we need
3285 * Additionally applications have to set the D3DRS_POINTSIZE render state
3286 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
3287 * doesn't need that and just ignores it.
3289 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
3290 /* FIXME: This should just check the shader backend caps. */
3291 if (gl_info
->supported
[ARB_VERTEX_PROGRAM
] || gl_info
->supported
[ARB_VERTEX_SHADER
])
3293 idx
= get_format_idx(WINED3DFMT_INST
);
3294 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3297 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
3298 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
3299 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
3300 * MAKEFOURCC('N','V','D','B') and then controlled by setting
3301 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
3303 if (gl_info
->supported
[EXT_DEPTH_BOUNDS_TEST
])
3305 idx
= get_format_idx(WINED3DFMT_NVDB
);
3306 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3309 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
3310 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
3311 * RENDERTARGET usage. */
3312 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
])
3314 idx
= get_format_idx(WINED3DFMT_RESZ
);
3315 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
);
3318 for (i
= 0; i
< gl_info
->format_count
; ++i
)
3320 struct wined3d_format
*format
= &gl_info
->formats
[i
];
3322 if (!(format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_TEXTURE
))
3325 if (!adapter
->shader_backend
->shader_color_fixup_supported(format
->color_fixup
)
3326 || !adapter
->fragment_pipe
->color_fixup_supported(format
->color_fixup
))
3327 format_clear_flag(format
, WINED3DFMT_FLAG_TEXTURE
);
3330 /* GL_EXT_texture_compression_s3tc does not support 3D textures. Some Windows drivers
3331 * for dx9 GPUs support it, some do not, so not supporting DXTn volumes is OK for d3d9.
3333 * Note that GL_NV_texture_compression_vtc adds this functionality to OpenGL, but the
3334 * block layout is not compatible with the one used by d3d. See volume_dxt5_test. */
3335 idx
= get_format_idx(WINED3DFMT_DXT1
);
3336 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3337 idx
= get_format_idx(WINED3DFMT_DXT2
);
3338 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3339 idx
= get_format_idx(WINED3DFMT_DXT3
);
3340 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3341 idx
= get_format_idx(WINED3DFMT_DXT4
);
3342 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3343 idx
= get_format_idx(WINED3DFMT_DXT5
);
3344 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3345 idx
= get_format_idx(WINED3DFMT_BC1_UNORM
);
3346 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3347 idx
= get_format_idx(WINED3DFMT_BC1_UNORM_SRGB
);
3348 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3349 idx
= get_format_idx(WINED3DFMT_BC2_UNORM
);
3350 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3351 idx
= get_format_idx(WINED3DFMT_BC2_UNORM_SRGB
);
3352 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3353 idx
= get_format_idx(WINED3DFMT_BC3_UNORM
);
3354 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3355 idx
= get_format_idx(WINED3DFMT_BC3_UNORM_SRGB
);
3356 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3357 /* Similarly with ATI1N / ATI2N and GL_ARB_texture_compression_rgtc. */
3358 idx
= get_format_idx(WINED3DFMT_ATI1N
);
3359 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3360 idx
= get_format_idx(WINED3DFMT_ATI2N
);
3361 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3362 idx
= get_format_idx(WINED3DFMT_BC4_UNORM
);
3363 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3364 idx
= get_format_idx(WINED3DFMT_BC5_UNORM
);
3365 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3366 idx
= get_format_idx(WINED3DFMT_BC5_SNORM
);
3367 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3370 static unsigned int calculate_vertex_attribute_size(GLenum type
, unsigned int component_count
)
3375 return component_count
* sizeof(GLhalfNV
);
3377 return component_count
* sizeof(GLfloat
);
3379 return component_count
* sizeof(GLbyte
);
3380 case GL_UNSIGNED_BYTE
:
3381 return component_count
* sizeof(GLubyte
);
3383 return component_count
* sizeof(GLshort
);
3384 case GL_UNSIGNED_SHORT
:
3385 return component_count
* sizeof(GLushort
);
3387 return component_count
* sizeof(GLint
);
3388 case GL_UNSIGNED_INT
:
3389 return component_count
* sizeof(GLuint
);
3390 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3391 return sizeof(GLuint
);
3393 FIXME("Unhandled GL type %#x.\n", type
);
3398 static BOOL
init_format_vertex_info(struct wined3d_gl_info
*gl_info
)
3400 struct wined3d_format
*format
;
3403 for (i
= 0; i
< ARRAY_SIZE(format_vertex_info
); ++i
)
3405 if (!(format
= get_format_internal(gl_info
, format_vertex_info
[i
].id
)))
3408 if (!gl_info
->supported
[format_vertex_info
[i
].extension
])
3411 format
->emit_idx
= format_vertex_info
[i
].emit_idx
;
3412 format
->component_count
= format_vertex_info
[i
].component_count
;
3413 format
->gl_vtx_type
= format_vertex_info
[i
].gl_vtx_type
;
3414 format
->gl_vtx_format
= format_vertex_info
[i
].component_count
;
3415 format
->gl_normalized
= format_vertex_info
[i
].gl_normalized
;
3416 if (!(format
->attribute_size
= calculate_vertex_attribute_size(format
->gl_vtx_type
,
3417 format
->component_count
)))
3419 ERR("Invalid attribute size for vertex format %s (%#x).\n",
3420 debug_d3dformat(format_vertex_info
[i
].id
), format_vertex_info
[i
].id
);
3428 static BOOL
init_typeless_formats(struct wined3d_gl_info
*gl_info
)
3430 unsigned int flags
[WINED3D_GL_RES_TYPE_COUNT
];
3433 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
3435 struct wined3d_format
*format
, *typeless_format
;
3437 if (!(format
= get_format_internal(gl_info
, typed_formats
[i
].id
)))
3439 if (!(typeless_format
= get_format_internal(gl_info
, typed_formats
[i
].typeless_id
)))
3442 memcpy(flags
, typeless_format
->flags
, sizeof(flags
));
3443 copy_format(typeless_format
, format
);
3444 for (j
= 0; j
< ARRAY_SIZE(typeless_format
->flags
); ++j
)
3445 typeless_format
->flags
[j
] |= flags
[j
];
3448 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
3450 struct wined3d_format
*typeless_format
, *typeless_ds_format
, *ds_format
;
3451 struct wined3d_format
*depth_view_format
, *stencil_view_format
;
3452 enum wined3d_format_id format_id
;
3454 if (!(typeless_format
= get_format_internal(gl_info
, typeless_depth_stencil_formats
[i
].typeless_id
)))
3456 if (!(ds_format
= get_format_internal(gl_info
, typeless_depth_stencil_formats
[i
].depth_stencil_id
)))
3459 typeless_ds_format
= &gl_info
->formats
[WINED3D_FORMAT_COUNT
+ i
];
3460 typeless_ds_format
->id
= typeless_depth_stencil_formats
[i
].typeless_id
;
3461 copy_format(typeless_ds_format
, ds_format
);
3462 for (j
= 0; j
< ARRAY_SIZE(typeless_ds_format
->flags
); ++j
)
3464 typeless_ds_format
->flags
[j
] = typeless_format
->flags
[j
];
3465 typeless_format
->flags
[j
] &= ~(WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
);
3468 if ((format_id
= typeless_depth_stencil_formats
[i
].depth_view_id
))
3470 if (!(depth_view_format
= get_format_internal(gl_info
, format_id
)))
3472 copy_format(depth_view_format
, ds_format
);
3474 if ((format_id
= typeless_depth_stencil_formats
[i
].stencil_view_id
))
3476 if (!(stencil_view_format
= get_format_internal(gl_info
, format_id
)))
3478 copy_format(stencil_view_format
, ds_format
);
3485 /* Context activation is done by the caller. */
3486 BOOL
wined3d_adapter_init_format_info(struct wined3d_adapter
*adapter
, struct wined3d_caps_gl_ctx
*ctx
)
3488 struct wined3d_gl_info
*gl_info
= &adapter
->gl_info
;
3490 if (!init_format_base_info(gl_info
)) return FALSE
;
3491 if (!init_format_block_info(gl_info
)) goto fail
;
3493 if (!ctx
) /* WINED3D_NO3D */
3496 if (!init_format_texture_info(adapter
, gl_info
)) goto fail
;
3497 if (!init_format_vertex_info(gl_info
)) goto fail
;
3499 apply_format_fixups(adapter
, gl_info
);
3500 init_format_fbo_compat_info(ctx
);
3501 init_format_filter_info(gl_info
, adapter
->driver_info
.vendor
);
3502 if (!init_typeless_formats(gl_info
)) goto fail
;
3507 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
3508 gl_info
->formats
= NULL
;
3512 BOOL
wined3d_caps_gl_ctx_test_viewport_subpixel_bits(struct wined3d_caps_gl_ctx
*ctx
)
3514 static const struct wined3d_color red
= {1.0f
, 0.0f
, 0.0f
, 1.0f
};
3515 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3516 static const float offset
= -63.0f
/ 128.0f
;
3517 GLuint texture
, fbo
;
3521 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &texture
);
3522 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3523 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3524 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, ARRAY_SIZE(readback
), 1, 0,
3525 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, NULL
);
3526 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3527 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3528 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
,
3529 GL_TEXTURE_2D
, texture
, 0);
3530 checkGLcall("create resources");
3532 gl_info
->gl_ops
.gl
.p_glClearColor(1.0f
, 1.0f
, 1.0f
, 1.0f
);
3533 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
3534 GL_EXTCALL(glViewportIndexedf(0, offset
, offset
, 4.0f
, 1.0f
));
3535 draw_test_quad(ctx
, NULL
, &red
);
3536 checkGLcall("draw");
3538 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, texture
);
3539 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0,
3540 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3541 checkGLcall("readback");
3543 TRACE("Readback colors are 0x%08x, 0x%08x, 0x%08x, 0x%08x.\n",
3544 readback
[0], readback
[1], readback
[2], readback
[3]);
3546 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &texture
);
3547 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3548 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3549 checkGLcall("delete resources");
3551 for (i
= 0; i
< ARRAY_SIZE(readback
); ++i
)
3553 if (readback
[i
] != 0xffff0000)
3559 float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx
*ctx
, GLenum format
)
3561 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3562 static const struct wined3d_color blue
= {0.0f
, 0.0f
, 1.0f
, 1.0f
};
3563 GLuint fbo
, color
, depth
;
3564 unsigned int low
= 0, high
= 32, cur
;
3565 DWORD readback
[256];
3566 static const struct wined3d_vec3 geometry
[] =
3568 {-1.0f
, -1.0f
, -1.0f
},
3569 { 1.0f
, -1.0f
, 0.0f
},
3570 {-1.0f
, 1.0f
, -1.0f
},
3571 { 1.0f
, 1.0f
, 0.0f
},
3574 /* Most drivers want 2^23 for fixed point depth buffers, including r300g, r600g,
3575 * Nvidia. Use this as a fallback if the detection fails. */
3576 unsigned int fallback
= 23;
3578 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
3580 FIXME("No FBOs, assuming polyoffset scale of 2^%u.\n", fallback
);
3581 return (float)(1u << fallback
);
3584 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &color
);
3585 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
3586 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3587 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);
3589 gl_info
->fbo_ops
.glGenRenderbuffers(1, &depth
);
3590 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, depth
);
3591 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, format
, 256, 1);
3593 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3594 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3595 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, color
, 0);
3596 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, depth
);
3597 checkGLcall("Setup framebuffer");
3599 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.5f
, 0.0f
);
3600 gl_info
->gl_ops
.gl
.p_glClearDepth(0.5f
);
3601 gl_info
->gl_ops
.gl
.p_glEnable(GL_DEPTH_TEST
);
3602 gl_info
->gl_ops
.gl
.p_glEnable(GL_POLYGON_OFFSET_FILL
);
3603 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 256, 1);
3604 checkGLcall("Misc parameters");
3608 if (high
- low
<= 1)
3610 ERR("PolygonOffset scale factor detection failed, using fallback value 2^%u.\n", fallback
);
3614 cur
= (low
+ high
) / 2;
3616 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
3617 /* The post viewport transform Z of the geometry runs from 0.0 to 0.5. We want to push it another
3618 * 0.25 so that the Z buffer content (0.5) cuts the quad off at half the screen. */
3619 gl_info
->gl_ops
.gl
.p_glPolygonOffset(0.0f
, (float)(1u << cur
) * 0.25f
);
3620 draw_test_quad(ctx
, geometry
, &blue
);
3621 checkGLcall("Test draw");
3623 /* Rebinding texture to workaround a fglrx bug. */
3624 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
3625 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3626 checkGLcall("readback");
3628 TRACE("low %02u, high %02u, cur %2u, 0=0x%08x, 125=0x%08x, 131=0x%08x, 255=0x%08x\n",
3629 low
, high
, cur
, readback
[0], readback
[125], readback
[131], readback
[255]);
3631 if ((readback
[125] & 0xff) < 0xa0)
3633 else if ((readback
[131] & 0xff) > 0xa0)
3637 TRACE("Found scale factor 2^%u for format %x\n", cur
, format
);
3642 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &color
);
3643 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &depth
);
3644 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3645 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3646 checkGLcall("Delete framebuffer");
3648 gl_info
->gl_ops
.gl
.p_glDisable(GL_DEPTH_TEST
);
3649 gl_info
->gl_ops
.gl
.p_glDisable(GL_POLYGON_OFFSET_FILL
);
3650 return (float)(1u << cur
);
3653 const struct wined3d_format
*wined3d_get_format(const struct wined3d_gl_info
*gl_info
,
3654 enum wined3d_format_id format_id
, unsigned int resource_usage
)
3656 const struct wined3d_format
*format
;
3657 int idx
= get_format_idx(format_id
);
3662 FIXME("Can't find format %s (%#x) in the format lookup table.\n",
3663 debug_d3dformat(format_id
), format_id
);
3664 return &gl_info
->formats
[get_format_idx(WINED3DFMT_UNKNOWN
)];
3667 format
= &gl_info
->formats
[idx
];
3669 if (resource_usage
& WINED3DUSAGE_DEPTHSTENCIL
&& wined3d_format_is_typeless(format
))
3671 for (i
= 0; i
< ARRAY_SIZE(typeless_depth_stencil_formats
); ++i
)
3673 if (typeless_depth_stencil_formats
[i
].typeless_id
== format_id
)
3674 return &gl_info
->formats
[WINED3D_FORMAT_COUNT
+ i
];
3677 FIXME("Cannot find depth/stencil typeless format %s (%#x).\n",
3678 debug_d3dformat(format_id
), format_id
);
3679 return &gl_info
->formats
[get_format_idx(WINED3DFMT_UNKNOWN
)];
3685 void wined3d_format_calculate_pitch(const struct wined3d_format
*format
, unsigned int alignment
,
3686 unsigned int width
, unsigned int height
, unsigned int *row_pitch
, unsigned int *slice_pitch
)
3688 /* For block based formats, pitch means the amount of bytes to the next
3689 * row of blocks rather than the next row of pixels. */
3690 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BLOCKS
)
3692 unsigned int row_block_count
= (width
+ format
->block_width
- 1) / format
->block_width
;
3693 unsigned int slice_block_count
= (height
+ format
->block_height
- 1) / format
->block_height
;
3694 *row_pitch
= row_block_count
* format
->block_byte_count
;
3695 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
3696 *slice_pitch
= *row_pitch
* slice_block_count
;
3700 *row_pitch
= format
->byte_count
* width
; /* Bytes / row */
3701 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
3702 *slice_pitch
= *row_pitch
* height
;
3705 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_HEIGHT_SCALE
)
3707 /* The D3D format requirements make sure that the resulting format is an integer again */
3708 *slice_pitch
*= format
->height_scale
.numerator
;
3709 *slice_pitch
/= format
->height_scale
.denominator
;
3712 TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch
, *slice_pitch
);
3715 UINT
wined3d_format_calculate_size(const struct wined3d_format
*format
, UINT alignment
,
3716 UINT width
, UINT height
, UINT depth
)
3718 unsigned int row_pitch
, slice_pitch
;
3720 if (format
->id
== WINED3DFMT_UNKNOWN
)
3723 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BROKEN_PITCH
)
3724 return width
* height
* depth
* format
->byte_count
;
3726 wined3d_format_calculate_pitch(format
, alignment
, width
, height
, &row_pitch
, &slice_pitch
);
3728 return slice_pitch
* depth
;
3731 /*****************************************************************************
3732 * Trace formatting of useful values
3734 const char *debug_box(const struct wined3d_box
*box
)
3738 return wine_dbg_sprintf("(%u, %u, %u)-(%u, %u, %u)",
3739 box
->left
, box
->top
, box
->front
,
3740 box
->right
, box
->bottom
, box
->back
);
3743 const char *debug_color(const struct wined3d_color
*color
)
3747 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
3748 color
->r
, color
->g
, color
->b
, color
->a
);
3751 const char *debug_ivec4(const struct wined3d_ivec4
*v
)
3755 return wine_dbg_sprintf("{%d, %d, %d, %d}",
3756 v
->x
, v
->y
, v
->z
, v
->w
);
3759 const char *debug_vec4(const struct wined3d_vec4
*v
)
3763 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
3764 v
->x
, v
->y
, v
->z
, v
->w
);
3767 const char *debug_d3dformat(enum wined3d_format_id format_id
)
3771 #define FMT_TO_STR(format_id) case format_id: return #format_id
3772 FMT_TO_STR(WINED3DFMT_UNKNOWN
);
3773 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM
);
3774 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM
);
3775 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM
);
3776 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM
);
3777 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM
);
3778 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM
);
3779 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM
);
3780 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM
);
3781 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM
);
3782 FMT_TO_STR(WINED3DFMT_P8_UINT
);
3783 FMT_TO_STR(WINED3DFMT_L8_UNORM
);
3784 FMT_TO_STR(WINED3DFMT_L8A8_UNORM
);
3785 FMT_TO_STR(WINED3DFMT_L4A4_UNORM
);
3786 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
3787 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
3788 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM
);
3789 FMT_TO_STR(WINED3DFMT_R10G10B10X2_UINT
);
3790 FMT_TO_STR(WINED3DFMT_R10G10B10X2_SNORM
);
3791 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM
);
3792 FMT_TO_STR(WINED3DFMT_UYVY
);
3793 FMT_TO_STR(WINED3DFMT_YUY2
);
3794 FMT_TO_STR(WINED3DFMT_YV12
);
3795 FMT_TO_STR(WINED3DFMT_NV12
);
3796 FMT_TO_STR(WINED3DFMT_DXT1
);
3797 FMT_TO_STR(WINED3DFMT_DXT2
);
3798 FMT_TO_STR(WINED3DFMT_DXT3
);
3799 FMT_TO_STR(WINED3DFMT_DXT4
);
3800 FMT_TO_STR(WINED3DFMT_DXT5
);
3801 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8
);
3802 FMT_TO_STR(WINED3DFMT_G8R8_G8B8
);
3803 FMT_TO_STR(WINED3DFMT_R8G8_B8G8
);
3804 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE
);
3805 FMT_TO_STR(WINED3DFMT_D32_UNORM
);
3806 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM
);
3807 FMT_TO_STR(WINED3DFMT_X8D24_UNORM
);
3808 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM
);
3809 FMT_TO_STR(WINED3DFMT_L16_UNORM
);
3810 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT
);
3811 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx
);
3812 FMT_TO_STR(WINED3DFMT_ATI1N
);
3813 FMT_TO_STR(WINED3DFMT_ATI2N
);
3814 FMT_TO_STR(WINED3DFMT_NVDB
);
3815 FMT_TO_STR(WINED3DFMT_NVHU
);
3816 FMT_TO_STR(WINED3DFMT_NVHS
);
3817 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS
);
3818 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT
);
3819 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT
);
3820 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT
);
3821 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS
);
3822 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT
);
3823 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT
);
3824 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT
);
3825 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS
);
3826 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT
);
3827 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM
);
3828 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT
);
3829 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM
);
3830 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT
);
3831 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS
);
3832 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT
);
3833 FMT_TO_STR(WINED3DFMT_R32G32_UINT
);
3834 FMT_TO_STR(WINED3DFMT_R32G32_SINT
);
3835 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS
);
3836 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT
);
3837 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
);
3838 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT
);
3839 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS
);
3840 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM
);
3841 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT
);
3842 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM
);
3843 FMT_TO_STR(WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM
);
3844 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT
);
3845 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS
);
3846 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM
);
3847 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB
);
3848 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT
);
3849 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM
);
3850 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT
);
3851 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS
);
3852 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT
);
3853 FMT_TO_STR(WINED3DFMT_R16G16_UNORM
);
3854 FMT_TO_STR(WINED3DFMT_R16G16_UINT
);
3855 FMT_TO_STR(WINED3DFMT_R16G16_SNORM
);
3856 FMT_TO_STR(WINED3DFMT_R16G16_SINT
);
3857 FMT_TO_STR(WINED3DFMT_R32_TYPELESS
);
3858 FMT_TO_STR(WINED3DFMT_D32_FLOAT
);
3859 FMT_TO_STR(WINED3DFMT_R32_FLOAT
);
3860 FMT_TO_STR(WINED3DFMT_R32_UINT
);
3861 FMT_TO_STR(WINED3DFMT_R32_SINT
);
3862 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS
);
3863 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT
);
3864 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS
);
3865 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT
);
3866 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS
);
3867 FMT_TO_STR(WINED3DFMT_R8G8_UNORM
);
3868 FMT_TO_STR(WINED3DFMT_R8G8_UINT
);
3869 FMT_TO_STR(WINED3DFMT_R8G8_SNORM
);
3870 FMT_TO_STR(WINED3DFMT_R8G8_SINT
);
3871 FMT_TO_STR(WINED3DFMT_R16_TYPELESS
);
3872 FMT_TO_STR(WINED3DFMT_R16_FLOAT
);
3873 FMT_TO_STR(WINED3DFMT_D16_UNORM
);
3874 FMT_TO_STR(WINED3DFMT_R16_UNORM
);
3875 FMT_TO_STR(WINED3DFMT_R16_UINT
);
3876 FMT_TO_STR(WINED3DFMT_R16_SNORM
);
3877 FMT_TO_STR(WINED3DFMT_R16_SINT
);
3878 FMT_TO_STR(WINED3DFMT_R8_TYPELESS
);
3879 FMT_TO_STR(WINED3DFMT_R8_UNORM
);
3880 FMT_TO_STR(WINED3DFMT_R8_UINT
);
3881 FMT_TO_STR(WINED3DFMT_R8_SNORM
);
3882 FMT_TO_STR(WINED3DFMT_R8_SINT
);
3883 FMT_TO_STR(WINED3DFMT_A8_UNORM
);
3884 FMT_TO_STR(WINED3DFMT_R1_UNORM
);
3885 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP
);
3886 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM
);
3887 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM
);
3888 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS
);
3889 FMT_TO_STR(WINED3DFMT_BC1_UNORM
);
3890 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB
);
3891 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS
);
3892 FMT_TO_STR(WINED3DFMT_BC2_UNORM
);
3893 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB
);
3894 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS
);
3895 FMT_TO_STR(WINED3DFMT_BC3_UNORM
);
3896 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB
);
3897 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS
);
3898 FMT_TO_STR(WINED3DFMT_BC4_UNORM
);
3899 FMT_TO_STR(WINED3DFMT_BC4_SNORM
);
3900 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS
);
3901 FMT_TO_STR(WINED3DFMT_BC5_UNORM
);
3902 FMT_TO_STR(WINED3DFMT_BC5_SNORM
);
3903 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM
);
3904 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM
);
3905 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM
);
3906 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM
);
3907 FMT_TO_STR(WINED3DFMT_B8G8R8A8_TYPELESS
);
3908 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM_SRGB
);
3909 FMT_TO_STR(WINED3DFMT_B8G8R8X8_TYPELESS
);
3910 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM_SRGB
);
3911 FMT_TO_STR(WINED3DFMT_BC6H_TYPELESS
);
3912 FMT_TO_STR(WINED3DFMT_BC6H_UF16
);
3913 FMT_TO_STR(WINED3DFMT_BC6H_SF16
);
3914 FMT_TO_STR(WINED3DFMT_BC7_TYPELESS
);
3915 FMT_TO_STR(WINED3DFMT_BC7_UNORM
);
3916 FMT_TO_STR(WINED3DFMT_BC7_UNORM_SRGB
);
3917 FMT_TO_STR(WINED3DFMT_INTZ
);
3918 FMT_TO_STR(WINED3DFMT_RESZ
);
3919 FMT_TO_STR(WINED3DFMT_NULL
);
3920 FMT_TO_STR(WINED3DFMT_R16
);
3921 FMT_TO_STR(WINED3DFMT_AL16
);
3926 fourcc
[0] = (char)(format_id
);
3927 fourcc
[1] = (char)(format_id
>> 8);
3928 fourcc
[2] = (char)(format_id
>> 16);
3929 fourcc
[3] = (char)(format_id
>> 24);
3931 if (isprint(fourcc
[0]) && isprint(fourcc
[1]) && isprint(fourcc
[2]) && isprint(fourcc
[3]))
3932 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id
, fourcc
);
3934 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id
);
3936 return "unrecognized";
3940 const char *debug_d3ddevicetype(enum wined3d_device_type device_type
)
3942 switch (device_type
)
3944 #define DEVTYPE_TO_STR(dev) case dev: return #dev
3945 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL
);
3946 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF
);
3947 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW
);
3948 #undef DEVTYPE_TO_STR
3950 FIXME("Unrecognized device type %#x.\n", device_type
);
3951 return "unrecognized";
3955 const char *debug_d3dusage(DWORD usage
)
3960 #define WINED3DUSAGE_TO_STR(u) if (usage & u) { strcat(buf, " | "#u); usage &= ~u; }
3961 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RENDERTARGET
);
3962 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DEPTHSTENCIL
);
3963 WINED3DUSAGE_TO_STR(WINED3DUSAGE_WRITEONLY
);
3964 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING
);
3965 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP
);
3966 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS
);
3967 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES
);
3968 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES
);
3969 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC
);
3970 WINED3DUSAGE_TO_STR(WINED3DUSAGE_AUTOGENMIPMAP
);
3971 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICTED_CONTENT
);
3972 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE_DRIVER
);
3973 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE
);
3974 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP
);
3975 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTAPI
);
3976 WINED3DUSAGE_TO_STR(WINED3DUSAGE_LEGACY_CUBEMAP
);
3977 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTURE
);
3978 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OWNDC
);
3979 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL
);
3980 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY
);
3981 #undef WINED3DUSAGE_TO_STR
3982 if (usage
) FIXME("Unrecognized usage flag(s) %#x\n", usage
);
3984 return buf
[0] ? wine_dbg_sprintf("%s", &buf
[3]) : "0";
3987 const char *debug_d3dusagequery(DWORD usagequery
)
3992 #define WINED3DUSAGEQUERY_TO_STR(u) if (usagequery & u) { strcat(buf, " | "#u); usagequery &= ~u; }
3993 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_FILTER
);
3994 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP
);
3995 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
);
3996 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD
);
3997 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE
);
3998 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE
);
3999 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP
);
4000 #undef WINED3DUSAGEQUERY_TO_STR
4001 if (usagequery
) FIXME("Unrecognized usage query flag(s) %#x\n", usagequery
);
4003 return buf
[0] ? wine_dbg_sprintf("%s", &buf
[3]) : "0";
4006 const char *debug_d3ddeclmethod(enum wined3d_decl_method method
)
4010 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
4011 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT
);
4012 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U
);
4013 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V
);
4014 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV
);
4015 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV
);
4016 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP
);
4017 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED
);
4018 #undef WINED3DDECLMETHOD_TO_STR
4020 FIXME("Unrecognized declaration method %#x.\n", method
);
4021 return "unrecognized";
4025 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage
)
4029 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
4030 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION
);
4031 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT
);
4032 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES
);
4033 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL
);
4034 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE
);
4035 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD
);
4036 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT
);
4037 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL
);
4038 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR
);
4039 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT
);
4040 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR
);
4041 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG
);
4042 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH
);
4043 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE
);
4044 #undef WINED3DDECLUSAGE_TO_STR
4046 FIXME("Unrecognized %u declaration usage!\n", usage
);
4047 return "unrecognized";
4051 const char *debug_d3dinput_classification(enum wined3d_input_classification classification
)
4053 switch (classification
)
4055 #define WINED3D_TO_STR(x) case x: return #x
4056 WINED3D_TO_STR(WINED3D_INPUT_PER_VERTEX_DATA
);
4057 WINED3D_TO_STR(WINED3D_INPUT_PER_INSTANCE_DATA
);
4058 #undef WINED3D_TO_STR
4060 FIXME("Unrecognized input classification %#x.\n", classification
);
4061 return "unrecognized";
4065 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type
)
4067 switch (resource_type
)
4069 #define WINED3D_TO_STR(x) case x: return #x
4070 WINED3D_TO_STR(WINED3D_RTYPE_BUFFER
);
4071 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_2D
);
4072 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_3D
);
4073 #undef WINED3D_TO_STR
4075 FIXME("Unrecognized resource type %#x.\n", resource_type
);
4076 return "unrecognized";
4080 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type
)
4082 switch (primitive_type
)
4084 #define PRIM_TO_STR(prim) case prim: return #prim
4085 PRIM_TO_STR(WINED3D_PT_UNDEFINED
);
4086 PRIM_TO_STR(WINED3D_PT_POINTLIST
);
4087 PRIM_TO_STR(WINED3D_PT_LINELIST
);
4088 PRIM_TO_STR(WINED3D_PT_LINESTRIP
);
4089 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST
);
4090 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP
);
4091 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN
);
4092 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ
);
4093 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ
);
4094 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ
);
4095 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ
);
4098 FIXME("Unrecognized %u primitive type!\n", primitive_type
);
4099 return "unrecognized";
4103 const char *debug_d3drenderstate(enum wined3d_render_state state
)
4107 #define D3DSTATE_TO_STR(u) case u: return #u
4108 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS
);
4109 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE
);
4110 D3DSTATE_TO_STR(WINED3D_RS_WRAPU
);
4111 D3DSTATE_TO_STR(WINED3D_RS_WRAPV
);
4112 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE
);
4113 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE
);
4114 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE
);
4115 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN
);
4116 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE
);
4117 D3DSTATE_TO_STR(WINED3D_RS_ROP2
);
4118 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK
);
4119 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE
);
4120 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE
);
4121 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL
);
4122 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND
);
4123 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND
);
4124 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE
);
4125 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC
);
4126 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF
);
4127 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC
);
4128 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE
);
4129 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE
);
4130 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE
);
4131 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE
);
4132 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE
);
4133 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL
);
4134 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX
);
4135 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA
);
4136 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR
);
4137 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE
);
4138 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART
);
4139 D3DSTATE_TO_STR(WINED3D_RS_FOGEND
);
4140 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY
);
4141 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE
);
4142 D3DSTATE_TO_STR(WINED3D_RS_EDGEANTIALIAS
);
4143 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE
);
4144 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS
);
4145 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE
);
4146 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY
);
4147 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH
);
4148 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT
);
4149 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE
);
4150 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL
);
4151 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL
);
4152 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS
);
4153 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC
);
4154 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF
);
4155 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK
);
4156 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK
);
4157 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR
);
4158 D3DSTATE_TO_STR(WINED3D_RS_WRAP0
);
4159 D3DSTATE_TO_STR(WINED3D_RS_WRAP1
);
4160 D3DSTATE_TO_STR(WINED3D_RS_WRAP2
);
4161 D3DSTATE_TO_STR(WINED3D_RS_WRAP3
);
4162 D3DSTATE_TO_STR(WINED3D_RS_WRAP4
);
4163 D3DSTATE_TO_STR(WINED3D_RS_WRAP5
);
4164 D3DSTATE_TO_STR(WINED3D_RS_WRAP6
);
4165 D3DSTATE_TO_STR(WINED3D_RS_WRAP7
);
4166 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING
);
4167 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING
);
4168 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS
);
4169 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT
);
4170 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE
);
4171 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX
);
4172 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER
);
4173 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS
);
4174 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE
);
4175 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE
);
4176 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE
);
4177 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE
);
4178 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE
);
4179 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND
);
4180 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE
);
4181 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING
);
4182 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE
);
4183 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN
);
4184 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE
);
4185 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE
);
4186 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A
);
4187 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B
);
4188 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C
);
4189 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS
);
4190 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK
);
4191 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE
);
4192 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS
);
4193 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN
);
4194 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX
);
4195 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE
);
4196 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE
);
4197 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR
);
4198 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP
);
4199 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE
);
4200 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE
);
4201 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE
);
4202 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS
);
4203 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE
);
4204 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL
);
4205 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL
);
4206 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X
);
4207 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y
);
4208 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z
);
4209 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W
);
4210 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION
);
4211 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE
);
4212 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFAIL
);
4213 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILZFAIL
);
4214 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILPASS
);
4215 D3DSTATE_TO_STR(WINED3D_RS_BACK_STENCILFUNC
);
4216 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1
);
4217 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2
);
4218 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3
);
4219 D3DSTATE_TO_STR(WINED3D_RS_BLENDFACTOR
);
4220 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE
);
4221 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS
);
4222 D3DSTATE_TO_STR(WINED3D_RS_WRAP8
);
4223 D3DSTATE_TO_STR(WINED3D_RS_WRAP9
);
4224 D3DSTATE_TO_STR(WINED3D_RS_WRAP10
);
4225 D3DSTATE_TO_STR(WINED3D_RS_WRAP11
);
4226 D3DSTATE_TO_STR(WINED3D_RS_WRAP12
);
4227 D3DSTATE_TO_STR(WINED3D_RS_WRAP13
);
4228 D3DSTATE_TO_STR(WINED3D_RS_WRAP14
);
4229 D3DSTATE_TO_STR(WINED3D_RS_WRAP15
);
4230 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE
);
4231 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA
);
4232 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA
);
4233 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA
);
4234 #undef D3DSTATE_TO_STR
4236 FIXME("Unrecognized %u render state!\n", state
);
4237 return "unrecognized";
4241 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state
)
4245 #define D3DSTATE_TO_STR(u) case u: return #u
4246 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR
);
4247 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U
);
4248 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V
);
4249 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W
);
4250 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER
);
4251 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER
);
4252 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER
);
4253 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS
);
4254 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL
);
4255 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY
);
4256 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE
);
4257 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX
);
4258 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET
);
4259 #undef D3DSTATE_TO_STR
4261 FIXME("Unrecognized %u sampler state!\n", state
);
4262 return "unrecognized";
4266 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type
)
4268 switch (filter_type
)
4270 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
4271 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE
);
4272 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT
);
4273 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR
);
4274 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC
);
4275 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC
);
4276 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC
);
4277 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD
);
4278 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD
);
4279 #undef D3DTEXTUREFILTERTYPE_TO_STR
4281 FIXME("Unrecognized texture filter type 0x%08x.\n", filter_type
);
4282 return "unrecognized";
4286 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state
)
4290 #define D3DSTATE_TO_STR(u) case u: return #u
4291 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP
);
4292 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1
);
4293 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2
);
4294 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP
);
4295 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1
);
4296 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2
);
4297 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00
);
4298 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01
);
4299 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10
);
4300 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11
);
4301 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX
);
4302 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE
);
4303 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET
);
4304 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
);
4305 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0
);
4306 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0
);
4307 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG
);
4308 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT
);
4309 #undef D3DSTATE_TO_STR
4311 FIXME("Unrecognized %u texture state!\n", state
);
4312 return "unrecognized";
4316 const char *debug_d3dtop(enum wined3d_texture_op d3dtop
)
4320 #define D3DTOP_TO_STR(u) case u: return #u
4321 D3DTOP_TO_STR(WINED3D_TOP_DISABLE
);
4322 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1
);
4323 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2
);
4324 D3DTOP_TO_STR(WINED3D_TOP_MODULATE
);
4325 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X
);
4326 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X
);
4327 D3DTOP_TO_STR(WINED3D_TOP_ADD
);
4328 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED
);
4329 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X
);
4330 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT
);
4331 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH
);
4332 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA
);
4333 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA
);
4334 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA
);
4335 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM
);
4336 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA
);
4337 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE
);
4338 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR
);
4339 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA
);
4340 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR
);
4341 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA
);
4342 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP
);
4343 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE
);
4344 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3
);
4345 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD
);
4346 D3DTOP_TO_STR(WINED3D_TOP_LERP
);
4347 #undef D3DTOP_TO_STR
4349 FIXME("Unrecognized texture op %#x.\n", d3dtop
);
4350 return "unrecognized";
4354 const char *debug_d3dtstype(enum wined3d_transform_state tstype
)
4358 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
4359 TSTYPE_TO_STR(WINED3D_TS_VIEW
);
4360 TSTYPE_TO_STR(WINED3D_TS_PROJECTION
);
4361 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0
);
4362 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1
);
4363 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2
);
4364 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3
);
4365 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4
);
4366 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5
);
4367 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6
);
4368 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7
);
4369 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
4370 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(1));
4371 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(2));
4372 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(3));
4373 #undef TSTYPE_TO_STR
4375 if (tstype
> 256 && tstype
< 512)
4377 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype
);
4378 return ("WINED3D_TS_WORLD_MATRIX > 0");
4380 FIXME("Unrecognized transform state %#x.\n", tstype
);
4381 return "unrecognized";
4385 const char *debug_shader_type(enum wined3d_shader_type type
)
4389 #define WINED3D_TO_STR(type) case type: return #type
4390 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL
);
4391 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX
);
4392 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY
);
4393 WINED3D_TO_STR(WINED3D_SHADER_TYPE_HULL
);
4394 WINED3D_TO_STR(WINED3D_SHADER_TYPE_DOMAIN
);
4395 WINED3D_TO_STR(WINED3D_SHADER_TYPE_COMPUTE
);
4396 #undef WINED3D_TO_STR
4398 FIXME("Unrecognized shader type %#x.\n", type
);
4399 return "unrecognized";
4403 const char *debug_d3dstate(DWORD state
)
4405 if (STATE_IS_RENDER(state
))
4406 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state
- STATE_RENDER(0)));
4407 if (STATE_IS_TEXTURESTAGE(state
))
4409 DWORD texture_stage
= (state
- STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE
+ 1);
4410 DWORD texture_state
= state
- STATE_TEXTURESTAGE(texture_stage
, 0);
4411 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
4412 texture_stage
, debug_d3dtexturestate(texture_state
));
4414 if (STATE_IS_SAMPLER(state
))
4415 return wine_dbg_sprintf("STATE_SAMPLER(%#x)", state
- STATE_SAMPLER(0));
4416 if (STATE_IS_COMPUTE_SHADER(state
))
4417 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE
));
4418 if (STATE_IS_GRAPHICS_SHADER(state
))
4419 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state
- STATE_SHADER(0)));
4420 if (STATE_IS_COMPUTE_CONSTANT_BUFFER(state
))
4421 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(WINED3D_SHADER_TYPE_COMPUTE
));
4422 if (STATE_IS_GRAPHICS_CONSTANT_BUFFER(state
))
4423 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state
- STATE_CONSTANT_BUFFER(0)));
4424 if (STATE_IS_COMPUTE_SHADER_RESOURCE_BINDING(state
))
4425 return "STATE_COMPUTE_SHADER_RESOURCE_BINDING";
4426 if (STATE_IS_GRAPHICS_SHADER_RESOURCE_BINDING(state
))
4427 return "STATE_GRAPHICS_SHADER_RESOURCE_BINDING";
4428 if (STATE_IS_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING(state
))
4429 return "STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING";
4430 if (STATE_IS_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING(state
))
4431 return "STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING";
4432 if (STATE_IS_TRANSFORM(state
))
4433 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state
- STATE_TRANSFORM(0)));
4434 if (STATE_IS_STREAMSRC(state
))
4435 return "STATE_STREAMSRC";
4436 if (STATE_IS_INDEXBUFFER(state
))
4437 return "STATE_INDEXBUFFER";
4438 if (STATE_IS_VDECL(state
))
4439 return "STATE_VDECL";
4440 if (STATE_IS_VIEWPORT(state
))
4441 return "STATE_VIEWPORT";
4442 if (STATE_IS_LIGHT_TYPE(state
))
4443 return "STATE_LIGHT_TYPE";
4444 if (STATE_IS_ACTIVELIGHT(state
))
4445 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state
- STATE_ACTIVELIGHT(0));
4446 if (STATE_IS_SCISSORRECT(state
))
4447 return "STATE_SCISSORRECT";
4448 if (STATE_IS_CLIPPLANE(state
))
4449 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state
- STATE_CLIPPLANE(0));
4450 if (STATE_IS_MATERIAL(state
))
4451 return "STATE_MATERIAL";
4452 if (STATE_IS_FRONTFACE(state
))
4453 return "STATE_FRONTFACE";
4454 if (STATE_IS_POINTSPRITECOORDORIGIN(state
))
4455 return "STATE_POINTSPRITECOORDORIGIN";
4456 if (STATE_IS_BASEVERTEXINDEX(state
))
4457 return "STATE_BASEVERTEXINDEX";
4458 if (STATE_IS_FRAMEBUFFER(state
))
4459 return "STATE_FRAMEBUFFER";
4460 if (STATE_IS_POINT_ENABLE(state
))
4461 return "STATE_POINT_ENABLE";
4462 if (STATE_IS_COLOR_KEY(state
))
4463 return "STATE_COLOR_KEY";
4465 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state
);
4468 const char *debug_d3dpool(enum wined3d_pool pool
)
4472 #define POOL_TO_STR(p) case p: return #p
4473 POOL_TO_STR(WINED3D_POOL_DEFAULT
);
4474 POOL_TO_STR(WINED3D_POOL_MANAGED
);
4475 POOL_TO_STR(WINED3D_POOL_SYSTEM_MEM
);
4476 POOL_TO_STR(WINED3D_POOL_SCRATCH
);
4479 FIXME("Unrecognized pool %#x.\n", pool
);
4480 return "unrecognized";
4484 const char *debug_fboattachment(GLenum attachment
)
4488 #define WINED3D_TO_STR(x) case x: return #x
4489 WINED3D_TO_STR(GL_COLOR_ATTACHMENT0
);
4490 WINED3D_TO_STR(GL_COLOR_ATTACHMENT1
);
4491 WINED3D_TO_STR(GL_COLOR_ATTACHMENT2
);
4492 WINED3D_TO_STR(GL_COLOR_ATTACHMENT3
);
4493 WINED3D_TO_STR(GL_COLOR_ATTACHMENT4
);
4494 WINED3D_TO_STR(GL_COLOR_ATTACHMENT5
);
4495 WINED3D_TO_STR(GL_COLOR_ATTACHMENT6
);
4496 WINED3D_TO_STR(GL_COLOR_ATTACHMENT7
);
4497 WINED3D_TO_STR(GL_COLOR_ATTACHMENT8
);
4498 WINED3D_TO_STR(GL_COLOR_ATTACHMENT9
);
4499 WINED3D_TO_STR(GL_COLOR_ATTACHMENT10
);
4500 WINED3D_TO_STR(GL_COLOR_ATTACHMENT11
);
4501 WINED3D_TO_STR(GL_COLOR_ATTACHMENT12
);
4502 WINED3D_TO_STR(GL_COLOR_ATTACHMENT13
);
4503 WINED3D_TO_STR(GL_COLOR_ATTACHMENT14
);
4504 WINED3D_TO_STR(GL_COLOR_ATTACHMENT15
);
4505 WINED3D_TO_STR(GL_DEPTH_ATTACHMENT
);
4506 WINED3D_TO_STR(GL_STENCIL_ATTACHMENT
);
4507 #undef WINED3D_TO_STR
4509 return wine_dbg_sprintf("Unknown FBO attachment %#x", attachment
);
4513 const char *debug_fbostatus(GLenum status
) {
4515 #define FBOSTATUS_TO_STR(u) case u: return #u
4516 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE
);
4517 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
);
4518 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
);
4519 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
);
4520 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
);
4521 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
);
4522 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
);
4523 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
);
4524 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
);
4525 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB
);
4526 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED
);
4527 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED
);
4528 #undef FBOSTATUS_TO_STR
4530 FIXME("Unrecognized FBO status 0x%08x.\n", status
);
4531 return "unrecognized";
4535 const char *debug_glerror(GLenum error
) {
4537 #define GLERROR_TO_STR(u) case u: return #u
4538 GLERROR_TO_STR(GL_NO_ERROR
);
4539 GLERROR_TO_STR(GL_INVALID_ENUM
);
4540 GLERROR_TO_STR(GL_INVALID_VALUE
);
4541 GLERROR_TO_STR(GL_INVALID_OPERATION
);
4542 GLERROR_TO_STR(GL_STACK_OVERFLOW
);
4543 GLERROR_TO_STR(GL_STACK_UNDERFLOW
);
4544 GLERROR_TO_STR(GL_OUT_OF_MEMORY
);
4545 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION
);
4546 #undef GLERROR_TO_STR
4548 FIXME("Unrecognized GL error 0x%08x.\n", error
);
4549 return "unrecognized";
4553 static const char *debug_fixup_channel_source(enum fixup_channel_source source
)
4557 #define WINED3D_TO_STR(x) case x: return #x
4558 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO
);
4559 WINED3D_TO_STR(CHANNEL_SOURCE_ONE
);
4560 WINED3D_TO_STR(CHANNEL_SOURCE_X
);
4561 WINED3D_TO_STR(CHANNEL_SOURCE_Y
);
4562 WINED3D_TO_STR(CHANNEL_SOURCE_Z
);
4563 WINED3D_TO_STR(CHANNEL_SOURCE_W
);
4564 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0
);
4565 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1
);
4566 #undef WINED3D_TO_STR
4568 FIXME("Unrecognized fixup_channel_source %#x\n", source
);
4569 return "unrecognized";
4573 static const char *debug_complex_fixup(enum complex_fixup fixup
)
4577 #define WINED3D_TO_STR(x) case x: return #x
4578 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2
);
4579 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY
);
4580 WINED3D_TO_STR(COMPLEX_FIXUP_YV12
);
4581 WINED3D_TO_STR(COMPLEX_FIXUP_NV12
);
4582 WINED3D_TO_STR(COMPLEX_FIXUP_P8
);
4583 #undef WINED3D_TO_STR
4585 FIXME("Unrecognized complex fixup %#x\n", fixup
);
4586 return "unrecognized";
4590 void dump_color_fixup_desc(struct color_fixup_desc fixup
)
4592 if (is_complex_fixup(fixup
))
4594 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup
)));
4598 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup
.x_source
), fixup
.x_sign_fixup
? ", SIGN_FIXUP" : "");
4599 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup
.y_source
), fixup
.y_sign_fixup
? ", SIGN_FIXUP" : "");
4600 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup
.z_source
), fixup
.z_sign_fixup
? ", SIGN_FIXUP" : "");
4601 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup
.w_source
), fixup
.w_sign_fixup
? ", SIGN_FIXUP" : "");
4604 BOOL
is_invalid_op(const struct wined3d_state
*state
, int stage
,
4605 enum wined3d_texture_op op
, DWORD arg1
, DWORD arg2
, DWORD arg3
)
4607 if (op
== WINED3D_TOP_DISABLE
)
4609 if (state
->textures
[stage
])
4612 if ((arg1
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
4613 && op
!= WINED3D_TOP_SELECT_ARG2
)
4615 if ((arg2
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
4616 && op
!= WINED3D_TOP_SELECT_ARG1
)
4618 if ((arg3
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
4619 && (op
== WINED3D_TOP_MULTIPLY_ADD
|| op
== WINED3D_TOP_LERP
))
4625 void get_identity_matrix(struct wined3d_matrix
*mat
)
4627 static const struct wined3d_matrix identity
=
4629 1.0f
, 0.0f
, 0.0f
, 0.0f
,
4630 0.0f
, 1.0f
, 0.0f
, 0.0f
,
4631 0.0f
, 0.0f
, 1.0f
, 0.0f
,
4632 0.0f
, 0.0f
, 0.0f
, 1.0f
,
4638 void get_modelview_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4639 unsigned int index
, struct wined3d_matrix
*mat
)
4641 if (context
->last_was_rhw
)
4642 get_identity_matrix(mat
);
4644 multiply_matrix(mat
, &state
->transforms
[WINED3D_TS_VIEW
], &state
->transforms
[WINED3D_TS_WORLD_MATRIX(index
)]);
4647 void get_projection_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4648 struct wined3d_matrix
*mat
)
4650 BOOL clip_control
= context
->gl_info
->supported
[ARB_CLIP_CONTROL
];
4651 BOOL flip
= !clip_control
&& context
->render_offscreen
;
4652 float center_offset
;
4654 /* There are a couple of additional things we have to take into account
4655 * here besides the projection transformation itself:
4656 * - We need to flip along the y-axis in case of offscreen rendering.
4657 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
4658 * - <= D3D9 coordinates refer to pixel centers while GL coordinates
4659 * refer to pixel corners.
4660 * - D3D has a top-left filling convention. We need to maintain this
4661 * even after the y-flip mentioned above.
4662 * In order to handle the last two points, we translate by
4663 * (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to
4664 * translating slightly less than half a pixel. We want the difference to
4665 * be large enough that it doesn't get lost due to rounding inside the
4666 * driver, but small enough to prevent it from interfering with any
4669 if (!clip_control
&& context
->d3d_info
->wined3d_creation_flags
& WINED3D_PIXEL_CENTER_INTEGER
)
4670 center_offset
= 63.0f
/ 64.0f
;
4672 center_offset
= -1.0f
/ 64.0f
;
4674 if (context
->last_was_rhw
)
4676 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
4677 float x
= state
->viewport
.x
;
4678 float y
= state
->viewport
.y
;
4679 float w
= state
->viewport
.width
;
4680 float h
= state
->viewport
.height
;
4681 float x_scale
= 2.0f
/ w
;
4682 float x_offset
= (center_offset
- (2.0f
* x
) - w
) / w
;
4683 float y_scale
= flip
? 2.0f
/ h
: 2.0f
/ -h
;
4684 float y_offset
= flip
4685 ? (center_offset
- (2.0f
* y
) - h
) / h
4686 : (center_offset
- (2.0f
* y
) - h
) / -h
;
4687 enum wined3d_depth_buffer_type zenable
= state
->fb
->depth_stencil
?
4688 state
->render_states
[WINED3D_RS_ZENABLE
] : WINED3D_ZB_FALSE
;
4689 float z_scale
= zenable
? clip_control
? 1.0f
: 2.0f
: 0.0f
;
4690 float z_offset
= zenable
? clip_control
? 0.0f
: -1.0f
: 0.0f
;
4691 const struct wined3d_matrix projection
=
4693 x_scale
, 0.0f
, 0.0f
, 0.0f
,
4694 0.0f
, y_scale
, 0.0f
, 0.0f
,
4695 0.0f
, 0.0f
, z_scale
, 0.0f
,
4696 x_offset
, y_offset
, z_offset
, 1.0f
,
4703 float y_scale
= flip
? -1.0f
: 1.0f
;
4704 float x_offset
= center_offset
/ state
->viewport
.width
;
4705 float y_offset
= flip
4706 ? center_offset
/ state
->viewport
.height
4707 : -center_offset
/ state
->viewport
.height
;
4708 float z_scale
= clip_control
? 1.0f
: 2.0f
;
4709 float z_offset
= clip_control
? 0.0f
: -1.0f
;
4710 const struct wined3d_matrix projection
=
4712 1.0f
, 0.0f
, 0.0f
, 0.0f
,
4713 0.0f
, y_scale
, 0.0f
, 0.0f
,
4714 0.0f
, 0.0f
, z_scale
, 0.0f
,
4715 x_offset
, y_offset
, z_offset
, 1.0f
,
4718 multiply_matrix(mat
, &projection
, &state
->transforms
[WINED3D_TS_PROJECTION
]);
4722 /* Setup this textures matrix according to the texture flags. */
4723 static void compute_texture_matrix(const struct wined3d_gl_info
*gl_info
, const struct wined3d_matrix
*matrix
,
4724 DWORD flags
, BOOL calculated_coords
, BOOL transformed
, enum wined3d_format_id format_id
,
4725 BOOL ffp_proj_control
, struct wined3d_matrix
*out_matrix
)
4727 struct wined3d_matrix mat
;
4729 if (flags
== WINED3D_TTFF_DISABLE
|| flags
== WINED3D_TTFF_COUNT1
|| transformed
)
4731 get_identity_matrix(out_matrix
);
4735 if (flags
== (WINED3D_TTFF_COUNT1
| WINED3D_TTFF_PROJECTED
))
4737 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
4743 if (flags
& WINED3D_TTFF_PROJECTED
)
4745 if (!ffp_proj_control
)
4747 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
4749 case WINED3D_TTFF_COUNT2
:
4754 mat
._12
= mat
._22
= mat
._32
= mat
._42
= 0.0f
;
4756 case WINED3D_TTFF_COUNT3
:
4761 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
4768 /* Under Direct3D the R/Z coord can be used for translation, under
4769 * OpenGL we use the Q coord instead. */
4770 if (!calculated_coords
)
4774 /* Direct3D passes the default 1.0 in the 2nd coord, while GL
4775 * passes it in the 4th. Swap 2nd and 4th coord. No need to
4776 * store the value of mat._41 in mat._21 because the input
4777 * value to the transformation will be 0, so the matrix value
4779 case WINED3DFMT_R32_FLOAT
:
4785 /* See above, just 3rd and 4th coord. */
4786 case WINED3DFMT_R32G32_FLOAT
:
4792 case WINED3DFMT_R32G32B32_FLOAT
: /* Opengl defaults match dx defaults */
4793 case WINED3DFMT_R32G32B32A32_FLOAT
: /* No defaults apply, all app defined */
4795 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
4796 * into a bad place. The division elimination below will apply to make sure the
4797 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
4799 case WINED3DFMT_UNKNOWN
: /* No texture coords, 0/0/0/1 defaults are passed */
4802 FIXME("Unexpected fixed function texture coord input\n");
4805 if (!ffp_proj_control
)
4807 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
4809 /* case WINED3D_TTFF_COUNT1: Won't ever get here. */
4810 case WINED3D_TTFF_COUNT2
:
4811 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
4812 /* OpenGL divides the first 3 vertex coordinates by the 4th by
4813 * default, which is essentially the same as D3DTTFF_PROJECTED.
4814 * Make sure that the 4th coordinate evaluates to 1.0 to
4817 * If the fixed function pipeline is used, the 4th value
4818 * remains unused, so there is no danger in doing this. With
4819 * vertex shaders we have a problem. Should an application hit
4820 * that problem, the code here would have to check for pixel
4821 * shaders, and the shader has to undo the default GL divide.
4823 * A more serious problem occurs if the application passes 4
4824 * coordinates in, and the 4th is != 1.0 (OpenGL default).
4825 * This would have to be fixed with immediate mode draws. */
4827 mat
._14
= mat
._24
= mat
._34
= 0.0f
; mat
._44
= 1.0f
;
4835 void get_texture_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4836 unsigned int tex
, struct wined3d_matrix
*mat
)
4838 const struct wined3d_device
*device
= context
->device
;
4839 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
4840 BOOL generated
= (state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
] & 0xffff0000)
4841 != WINED3DTSS_TCI_PASSTHRU
;
4842 unsigned int coord_idx
= min(state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
& 0x0000ffff],
4845 compute_texture_matrix(gl_info
, &state
->transforms
[WINED3D_TS_TEXTURE0
+ tex
],
4846 state
->texture_states
[tex
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
],
4847 generated
, context
->last_was_rhw
,
4848 context
->stream_info
.use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))
4849 ? context
->stream_info
.elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format
->id
4850 : WINED3DFMT_UNKNOWN
,
4851 device
->shader_backend
->shader_has_ffp_proj_control(device
->shader_priv
), mat
);
4853 if ((context
->lastWasPow2Texture
& (1u << tex
)) && state
->textures
[tex
])
4856 FIXME("Non-power-of-two texture being used with generated texture coords.\n");
4857 /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
4858 * fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
4861 TRACE("Non-power-of-two texture matrix multiply fixup.\n");
4862 multiply_matrix(mat
, mat
, (struct wined3d_matrix
*)state
->textures
[tex
]->pow2_matrix
);
4867 void get_pointsize_minmax(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4868 float *out_min
, float *out_max
)
4876 min
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MIN
];
4877 max
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MAX
];
4886 void get_pointsize(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4887 float *out_pointsize
, float *out_att
)
4889 /* POINTSCALEENABLE controls how point size value is treated. If set to
4890 * true, the point size is scaled with respect to height of viewport.
4891 * When set to false point size is in pixels. */
4896 } pointsize
, a
, b
, c
;
4902 pointsize
.d
= state
->render_states
[WINED3D_RS_POINTSIZE
];
4903 a
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_A
];
4904 b
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_B
];
4905 c
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_C
];
4907 if (state
->render_states
[WINED3D_RS_POINTSCALEENABLE
])
4909 float scale_factor
= state
->viewport
.height
* state
->viewport
.height
;
4911 out_att
[0] = a
.f
/ scale_factor
;
4912 out_att
[1] = b
.f
/ scale_factor
;
4913 out_att
[2] = c
.f
/ scale_factor
;
4915 *out_pointsize
= pointsize
.f
;
4918 void get_fog_start_end(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4919 float *start
, float *end
)
4927 switch (context
->fog_source
)
4934 case FOGSOURCE_COORD
:
4940 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGSTART
];
4941 *start
= tmpvalue
.f
;
4942 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGEND
];
4944 /* Special handling for fog_start == fog_end. In d3d with vertex
4945 * fog, everything is fogged. With table fog, everything with
4946 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
4947 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
4948 if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
&& *start
== *end
)
4956 /* This should not happen, context->fog_source is set in wined3d, not the app. */
4957 ERR("Unexpected fog coordinate source.\n");
4963 /* Note: It's the caller's responsibility to ensure values can be expressed
4964 * in the requested format. UNORM formats for example can only express values
4965 * in the range 0.0f -> 1.0f. */
4966 DWORD
wined3d_format_convert_from_float(const struct wined3d_format
*format
, const struct wined3d_color
*color
)
4970 enum wined3d_format_id format_id
;
4982 {WINED3DFMT_B8G8R8A8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
4983 {WINED3DFMT_B8G8R8X8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
4984 {WINED3DFMT_B8G8R8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
4985 {WINED3DFMT_B5G6R5_UNORM
, 31.0f
, 63.0f
, 31.0f
, 0.0f
, 11, 5, 0, 0},
4986 {WINED3DFMT_B5G5R5A1_UNORM
, 31.0f
, 31.0f
, 31.0f
, 1.0f
, 10, 5, 0, 15},
4987 {WINED3DFMT_B5G5R5X1_UNORM
, 31.0f
, 31.0f
, 31.0f
, 1.0f
, 10, 5, 0, 15},
4988 {WINED3DFMT_R8_UNORM
, 255.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 0, 0, 0},
4989 {WINED3DFMT_A8_UNORM
, 0.0f
, 0.0f
, 0.0f
, 255.0f
, 0, 0, 0, 0},
4990 {WINED3DFMT_B4G4R4A4_UNORM
, 15.0f
, 15.0f
, 15.0f
, 15.0f
, 8, 4, 0, 12},
4991 {WINED3DFMT_B4G4R4X4_UNORM
, 15.0f
, 15.0f
, 15.0f
, 15.0f
, 8, 4, 0, 12},
4992 {WINED3DFMT_B2G3R3_UNORM
, 7.0f
, 7.0f
, 3.0f
, 0.0f
, 5, 2, 0, 0},
4993 {WINED3DFMT_R8G8B8A8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 0, 8, 16, 24},
4994 {WINED3DFMT_R8G8B8X8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 0, 8, 16, 24},
4995 {WINED3DFMT_B10G10R10A2_UNORM
, 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
, 20, 10, 0, 30},
4996 {WINED3DFMT_R10G10B10A2_UNORM
, 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
, 0, 10, 20, 30},
4997 {WINED3DFMT_P8_UINT
, 0.0f
, 0.0f
, 0.0f
, 255.0f
, 0, 0, 0, 0},
4998 {WINED3DFMT_S1_UINT_D15_UNORM
, 32767.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 0, 0, 0},
4999 {WINED3DFMT_D16_UNORM
, 65535.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 0, 0, 0},
5000 {WINED3DFMT_D24_UNORM_S8_UINT
, 16777215.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 0, 0, 0},
5001 {WINED3DFMT_X8D24_UNORM
, 16777215.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 0, 0, 0},
5002 {WINED3DFMT_D32_UNORM
, 4294967295.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 0, 0, 0},
5006 TRACE("Converting color %s to format %s.\n", debug_color(color
), debug_d3dformat(format
->id
));
5008 for (i
= 0; i
< sizeof(conv
) / sizeof(*conv
); ++i
)
5012 if (format
->id
!= conv
[i
].format_id
) continue;
5014 ret
= ((DWORD
)((color
->r
* conv
[i
].r_mul
) + 0.5f
)) << conv
[i
].r_shift
;
5015 ret
|= ((DWORD
)((color
->g
* conv
[i
].g_mul
) + 0.5f
)) << conv
[i
].g_shift
;
5016 ret
|= ((DWORD
)((color
->b
* conv
[i
].b_mul
) + 0.5f
)) << conv
[i
].b_shift
;
5017 ret
|= ((DWORD
)((color
->a
* conv
[i
].a_mul
) + 0.5f
)) << conv
[i
].a_shift
;
5019 TRACE("Returning 0x%08x.\n", ret
);
5024 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format
->id
));
5029 static float color_to_float(DWORD color
, DWORD size
, DWORD offset
)
5031 DWORD mask
= size
< 32 ? (1u << size
) - 1 : ~0u;
5039 return (float)color
/ (float)mask
;
5042 BOOL
wined3d_format_convert_color_to_float(const struct wined3d_format
*format
,
5043 const struct wined3d_palette
*palette
, DWORD color
, struct wined3d_color
*float_color
)
5047 case WINED3DFMT_B8G8R8_UNORM
:
5048 case WINED3DFMT_B8G8R8A8_UNORM
:
5049 case WINED3DFMT_B8G8R8X8_UNORM
:
5050 case WINED3DFMT_B5G6R5_UNORM
:
5051 case WINED3DFMT_B5G5R5X1_UNORM
:
5052 case WINED3DFMT_B5G5R5A1_UNORM
:
5053 case WINED3DFMT_B4G4R4A4_UNORM
:
5054 case WINED3DFMT_B2G3R3_UNORM
:
5055 case WINED3DFMT_R8_UNORM
:
5056 case WINED3DFMT_A8_UNORM
:
5057 case WINED3DFMT_B2G3R3A8_UNORM
:
5058 case WINED3DFMT_B4G4R4X4_UNORM
:
5059 case WINED3DFMT_R10G10B10A2_UNORM
:
5060 case WINED3DFMT_R10G10B10A2_SNORM
:
5061 case WINED3DFMT_R8G8B8A8_UNORM
:
5062 case WINED3DFMT_R8G8B8X8_UNORM
:
5063 case WINED3DFMT_R16G16_UNORM
:
5064 case WINED3DFMT_B10G10R10A2_UNORM
:
5065 float_color
->r
= color_to_float(color
, format
->red_size
, format
->red_offset
);
5066 float_color
->g
= color_to_float(color
, format
->green_size
, format
->green_offset
);
5067 float_color
->b
= color_to_float(color
, format
->blue_size
, format
->blue_offset
);
5068 float_color
->a
= color_to_float(color
, format
->alpha_size
, format
->alpha_offset
);
5071 case WINED3DFMT_P8_UINT
:
5074 float_color
->r
= palette
->colors
[color
].rgbRed
/ 255.0f
;
5075 float_color
->g
= palette
->colors
[color
].rgbGreen
/ 255.0f
;
5076 float_color
->b
= palette
->colors
[color
].rgbBlue
/ 255.0f
;
5080 float_color
->r
= 0.0f
;
5081 float_color
->g
= 0.0f
;
5082 float_color
->b
= 0.0f
;
5084 float_color
->a
= color
/ 255.0f
;
5087 case WINED3DFMT_S1_UINT_D15_UNORM
:
5088 case WINED3DFMT_D16_UNORM
:
5089 case WINED3DFMT_D24_UNORM_S8_UINT
:
5090 case WINED3DFMT_X8D24_UNORM
:
5091 case WINED3DFMT_D32_UNORM
:
5092 float_color
->r
= color_to_float(color
, format
->depth_size
, 0);
5096 ERR("Unhandled conversion from %s to floating point.\n", debug_d3dformat(format
->id
));
5101 void wined3d_format_get_float_color_key(const struct wined3d_format
*format
,
5102 const struct wined3d_color_key
*key
, struct wined3d_color
*float_colors
)
5104 struct wined3d_color slop
;
5108 case WINED3DFMT_B8G8R8_UNORM
:
5109 case WINED3DFMT_B8G8R8A8_UNORM
:
5110 case WINED3DFMT_B8G8R8X8_UNORM
:
5111 case WINED3DFMT_B5G6R5_UNORM
:
5112 case WINED3DFMT_B5G5R5X1_UNORM
:
5113 case WINED3DFMT_B5G5R5A1_UNORM
:
5114 case WINED3DFMT_B4G4R4A4_UNORM
:
5115 case WINED3DFMT_B2G3R3_UNORM
:
5116 case WINED3DFMT_R8_UNORM
:
5117 case WINED3DFMT_A8_UNORM
:
5118 case WINED3DFMT_B2G3R3A8_UNORM
:
5119 case WINED3DFMT_B4G4R4X4_UNORM
:
5120 case WINED3DFMT_R10G10B10A2_UNORM
:
5121 case WINED3DFMT_R10G10B10A2_SNORM
:
5122 case WINED3DFMT_R8G8B8A8_UNORM
:
5123 case WINED3DFMT_R8G8B8X8_UNORM
:
5124 case WINED3DFMT_R16G16_UNORM
:
5125 case WINED3DFMT_B10G10R10A2_UNORM
:
5126 slop
.r
= 0.5f
/ ((1u << format
->red_size
) - 1);
5127 slop
.g
= 0.5f
/ ((1u << format
->green_size
) - 1);
5128 slop
.b
= 0.5f
/ ((1u << format
->blue_size
) - 1);
5129 slop
.a
= 0.5f
/ ((1u << format
->alpha_size
) - 1);
5131 float_colors
[0].r
= color_to_float(key
->color_space_low_value
, format
->red_size
, format
->red_offset
)
5133 float_colors
[0].g
= color_to_float(key
->color_space_low_value
, format
->green_size
, format
->green_offset
)
5135 float_colors
[0].b
= color_to_float(key
->color_space_low_value
, format
->blue_size
, format
->blue_offset
)
5137 float_colors
[0].a
= color_to_float(key
->color_space_low_value
, format
->alpha_size
, format
->alpha_offset
)
5140 float_colors
[1].r
= color_to_float(key
->color_space_high_value
, format
->red_size
, format
->red_offset
)
5142 float_colors
[1].g
= color_to_float(key
->color_space_high_value
, format
->green_size
, format
->green_offset
)
5144 float_colors
[1].b
= color_to_float(key
->color_space_high_value
, format
->blue_size
, format
->blue_offset
)
5146 float_colors
[1].a
= color_to_float(key
->color_space_high_value
, format
->alpha_size
, format
->alpha_offset
)
5150 case WINED3DFMT_P8_UINT
:
5151 float_colors
[0].r
= 0.0f
;
5152 float_colors
[0].g
= 0.0f
;
5153 float_colors
[0].b
= 0.0f
;
5154 float_colors
[0].a
= (key
->color_space_low_value
- 0.5f
) / 255.0f
;
5156 float_colors
[1].r
= 0.0f
;
5157 float_colors
[1].g
= 0.0f
;
5158 float_colors
[1].b
= 0.0f
;
5159 float_colors
[1].a
= (key
->color_space_high_value
+ 0.5f
) / 255.0f
;
5163 ERR("Unhandled color key to float conversion for format %s.\n", debug_d3dformat(format
->id
));
5167 /* DirectDraw stuff */
5168 enum wined3d_format_id
pixelformat_for_depth(DWORD depth
)
5172 case 8: return WINED3DFMT_P8_UINT
;
5173 case 15: return WINED3DFMT_B5G5R5X1_UNORM
;
5174 case 16: return WINED3DFMT_B5G6R5_UNORM
;
5175 case 24: return WINED3DFMT_B8G8R8X8_UNORM
; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
5176 case 32: return WINED3DFMT_B8G8R8X8_UNORM
; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
5177 default: return WINED3DFMT_UNKNOWN
;
5181 void multiply_matrix(struct wined3d_matrix
*dst
, const struct wined3d_matrix
*src1
, const struct wined3d_matrix
*src2
)
5183 struct wined3d_matrix tmp
;
5185 /* Now do the multiplication 'by hand'.
5186 I know that all this could be optimised, but this will be done later :-) */
5187 tmp
._11
= (src1
->_11
* src2
->_11
) + (src1
->_21
* src2
->_12
) + (src1
->_31
* src2
->_13
) + (src1
->_41
* src2
->_14
);
5188 tmp
._21
= (src1
->_11
* src2
->_21
) + (src1
->_21
* src2
->_22
) + (src1
->_31
* src2
->_23
) + (src1
->_41
* src2
->_24
);
5189 tmp
._31
= (src1
->_11
* src2
->_31
) + (src1
->_21
* src2
->_32
) + (src1
->_31
* src2
->_33
) + (src1
->_41
* src2
->_34
);
5190 tmp
._41
= (src1
->_11
* src2
->_41
) + (src1
->_21
* src2
->_42
) + (src1
->_31
* src2
->_43
) + (src1
->_41
* src2
->_44
);
5192 tmp
._12
= (src1
->_12
* src2
->_11
) + (src1
->_22
* src2
->_12
) + (src1
->_32
* src2
->_13
) + (src1
->_42
* src2
->_14
);
5193 tmp
._22
= (src1
->_12
* src2
->_21
) + (src1
->_22
* src2
->_22
) + (src1
->_32
* src2
->_23
) + (src1
->_42
* src2
->_24
);
5194 tmp
._32
= (src1
->_12
* src2
->_31
) + (src1
->_22
* src2
->_32
) + (src1
->_32
* src2
->_33
) + (src1
->_42
* src2
->_34
);
5195 tmp
._42
= (src1
->_12
* src2
->_41
) + (src1
->_22
* src2
->_42
) + (src1
->_32
* src2
->_43
) + (src1
->_42
* src2
->_44
);
5197 tmp
._13
= (src1
->_13
* src2
->_11
) + (src1
->_23
* src2
->_12
) + (src1
->_33
* src2
->_13
) + (src1
->_43
* src2
->_14
);
5198 tmp
._23
= (src1
->_13
* src2
->_21
) + (src1
->_23
* src2
->_22
) + (src1
->_33
* src2
->_23
) + (src1
->_43
* src2
->_24
);
5199 tmp
._33
= (src1
->_13
* src2
->_31
) + (src1
->_23
* src2
->_32
) + (src1
->_33
* src2
->_33
) + (src1
->_43
* src2
->_34
);
5200 tmp
._43
= (src1
->_13
* src2
->_41
) + (src1
->_23
* src2
->_42
) + (src1
->_33
* src2
->_43
) + (src1
->_43
* src2
->_44
);
5202 tmp
._14
= (src1
->_14
* src2
->_11
) + (src1
->_24
* src2
->_12
) + (src1
->_34
* src2
->_13
) + (src1
->_44
* src2
->_14
);
5203 tmp
._24
= (src1
->_14
* src2
->_21
) + (src1
->_24
* src2
->_22
) + (src1
->_34
* src2
->_23
) + (src1
->_44
* src2
->_24
);
5204 tmp
._34
= (src1
->_14
* src2
->_31
) + (src1
->_24
* src2
->_32
) + (src1
->_34
* src2
->_33
) + (src1
->_44
* src2
->_34
);
5205 tmp
._44
= (src1
->_14
* src2
->_41
) + (src1
->_24
* src2
->_42
) + (src1
->_34
* src2
->_43
) + (src1
->_44
* src2
->_44
);
5210 DWORD
get_flexible_vertex_size(DWORD d3dvtVertexType
) {
5213 int numTextures
= (d3dvtVertexType
& WINED3DFVF_TEXCOUNT_MASK
) >> WINED3DFVF_TEXCOUNT_SHIFT
;
5215 if (d3dvtVertexType
& WINED3DFVF_NORMAL
) size
+= 3 * sizeof(float);
5216 if (d3dvtVertexType
& WINED3DFVF_DIFFUSE
) size
+= sizeof(DWORD
);
5217 if (d3dvtVertexType
& WINED3DFVF_SPECULAR
) size
+= sizeof(DWORD
);
5218 if (d3dvtVertexType
& WINED3DFVF_PSIZE
) size
+= sizeof(DWORD
);
5219 switch (d3dvtVertexType
& WINED3DFVF_POSITION_MASK
) {
5220 case WINED3DFVF_XYZ
: size
+= 3 * sizeof(float); break;
5221 case WINED3DFVF_XYZRHW
: size
+= 4 * sizeof(float); break;
5222 case WINED3DFVF_XYZB1
: size
+= 4 * sizeof(float); break;
5223 case WINED3DFVF_XYZB2
: size
+= 5 * sizeof(float); break;
5224 case WINED3DFVF_XYZB3
: size
+= 6 * sizeof(float); break;
5225 case WINED3DFVF_XYZB4
: size
+= 7 * sizeof(float); break;
5226 case WINED3DFVF_XYZB5
: size
+= 8 * sizeof(float); break;
5227 case WINED3DFVF_XYZW
: size
+= 4 * sizeof(float); break;
5228 default: ERR("Unexpected position mask\n");
5230 for (i
= 0; i
< numTextures
; i
++) {
5231 size
+= GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType
, i
) * sizeof(float);
5237 unsigned int wined3d_max_compat_varyings(const struct wined3d_gl_info
*gl_info
)
5239 /* On core profile we have to also count diffuse and specular colors and the
5240 * fog coordinate. */
5241 return gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? MAX_TEXTURES
* 4 : (MAX_TEXTURES
+ 2) * 4 + 1;
5244 void gen_ffp_frag_op(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5245 struct ffp_frag_settings
*settings
, BOOL ignore_textype
)
5250 static const unsigned char args
[WINED3D_TOP_LERP
+ 1] =
5253 /* D3DTOP_DISABLE */ 0,
5254 /* D3DTOP_SELECTARG1 */ ARG1
,
5255 /* D3DTOP_SELECTARG2 */ ARG2
,
5256 /* D3DTOP_MODULATE */ ARG1
| ARG2
,
5257 /* D3DTOP_MODULATE2X */ ARG1
| ARG2
,
5258 /* D3DTOP_MODULATE4X */ ARG1
| ARG2
,
5259 /* D3DTOP_ADD */ ARG1
| ARG2
,
5260 /* D3DTOP_ADDSIGNED */ ARG1
| ARG2
,
5261 /* D3DTOP_ADDSIGNED2X */ ARG1
| ARG2
,
5262 /* D3DTOP_SUBTRACT */ ARG1
| ARG2
,
5263 /* D3DTOP_ADDSMOOTH */ ARG1
| ARG2
,
5264 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1
| ARG2
,
5265 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1
| ARG2
,
5266 /* D3DTOP_BLENDFACTORALPHA */ ARG1
| ARG2
,
5267 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1
| ARG2
,
5268 /* D3DTOP_BLENDCURRENTALPHA */ ARG1
| ARG2
,
5269 /* D3DTOP_PREMODULATE */ ARG1
| ARG2
,
5270 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1
| ARG2
,
5271 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1
| ARG2
,
5272 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1
| ARG2
,
5273 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1
| ARG2
,
5274 /* D3DTOP_BUMPENVMAP */ ARG1
| ARG2
,
5275 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1
| ARG2
,
5276 /* D3DTOP_DOTPRODUCT3 */ ARG1
| ARG2
,
5277 /* D3DTOP_MULTIPLYADD */ ARG1
| ARG2
| ARG0
,
5278 /* D3DTOP_LERP */ ARG1
| ARG2
| ARG0
5282 DWORD cop
, aop
, carg0
, carg1
, carg2
, aarg0
, aarg1
, aarg2
;
5283 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
5284 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
5286 settings
->padding
= 0;
5288 for (i
= 0; i
< d3d_info
->limits
.ffp_blend_stages
; ++i
)
5290 const struct wined3d_texture
*texture
;
5292 settings
->op
[i
].padding
= 0;
5293 if (state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
] == WINED3D_TOP_DISABLE
)
5295 settings
->op
[i
].cop
= WINED3D_TOP_DISABLE
;
5296 settings
->op
[i
].aop
= WINED3D_TOP_DISABLE
;
5297 settings
->op
[i
].carg0
= settings
->op
[i
].carg1
= settings
->op
[i
].carg2
= ARG_UNUSED
;
5298 settings
->op
[i
].aarg0
= settings
->op
[i
].aarg1
= settings
->op
[i
].aarg2
= ARG_UNUSED
;
5299 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
5300 settings
->op
[i
].dst
= resultreg
;
5301 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
5302 settings
->op
[i
].projected
= proj_none
;
5307 if ((texture
= state
->textures
[i
]))
5309 if (can_use_texture_swizzle(gl_info
, texture
->resource
.format
))
5310 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
5312 settings
->op
[i
].color_fixup
= texture
->resource
.format
->color_fixup
;
5315 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
5319 switch (texture
->target
)
5322 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
5325 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_2D
;
5328 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_3D
;
5330 case GL_TEXTURE_CUBE_MAP_ARB
:
5331 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_CUBE
;
5333 case GL_TEXTURE_RECTANGLE_ARB
:
5334 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_RECT
;
5339 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
5340 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
5343 cop
= state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
];
5344 aop
= state
->texture_states
[i
][WINED3D_TSS_ALPHA_OP
];
5346 carg1
= (args
[cop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG1
] : ARG_UNUSED
;
5347 carg2
= (args
[cop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG2
] : ARG_UNUSED
;
5348 carg0
= (args
[cop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG0
] : ARG_UNUSED
;
5350 if (is_invalid_op(state
, i
, cop
, carg1
, carg2
, carg0
))
5354 carg1
= WINED3DTA_CURRENT
;
5355 cop
= WINED3D_TOP_SELECT_ARG1
;
5358 if (cop
== WINED3D_TOP_DOTPRODUCT3
)
5360 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
5361 * the color result to the alpha component of the destination
5370 aarg1
= (args
[aop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG1
] : ARG_UNUSED
;
5371 aarg2
= (args
[aop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG2
] : ARG_UNUSED
;
5372 aarg0
= (args
[aop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG0
] : ARG_UNUSED
;
5375 if (!i
&& state
->textures
[0] && state
->render_states
[WINED3D_RS_COLORKEYENABLE
])
5377 GLenum texture_dimensions
;
5379 texture
= state
->textures
[0];
5380 texture_dimensions
= texture
->target
;
5382 if (texture_dimensions
== GL_TEXTURE_2D
|| texture_dimensions
== GL_TEXTURE_RECTANGLE_ARB
)
5384 if (texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
&& !texture
->resource
.format
->alpha_size
)
5386 if (aop
== WINED3D_TOP_DISABLE
)
5388 aarg1
= WINED3DTA_TEXTURE
;
5389 aop
= WINED3D_TOP_SELECT_ARG1
;
5391 else if (aop
== WINED3D_TOP_SELECT_ARG1
&& aarg1
!= WINED3DTA_TEXTURE
)
5393 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
])
5395 aarg2
= WINED3DTA_TEXTURE
;
5396 aop
= WINED3D_TOP_MODULATE
;
5398 else aarg1
= WINED3DTA_TEXTURE
;
5400 else if (aop
== WINED3D_TOP_SELECT_ARG2
&& aarg2
!= WINED3DTA_TEXTURE
)
5402 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
])
5404 aarg1
= WINED3DTA_TEXTURE
;
5405 aop
= WINED3D_TOP_MODULATE
;
5407 else aarg2
= WINED3DTA_TEXTURE
;
5413 if (is_invalid_op(state
, i
, aop
, aarg1
, aarg2
, aarg0
))
5417 aarg1
= WINED3DTA_CURRENT
;
5418 aop
= WINED3D_TOP_SELECT_ARG1
;
5421 if (carg1
== WINED3DTA_TEXTURE
|| carg2
== WINED3DTA_TEXTURE
|| carg0
== WINED3DTA_TEXTURE
5422 || aarg1
== WINED3DTA_TEXTURE
|| aarg2
== WINED3DTA_TEXTURE
|| aarg0
== WINED3DTA_TEXTURE
)
5424 ttff
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
5425 if (ttff
== (WINED3D_TTFF_PROJECTED
| WINED3D_TTFF_COUNT3
))
5426 settings
->op
[i
].projected
= proj_count3
;
5427 else if (ttff
& WINED3D_TTFF_PROJECTED
)
5428 settings
->op
[i
].projected
= proj_count4
;
5430 settings
->op
[i
].projected
= proj_none
;
5434 settings
->op
[i
].projected
= proj_none
;
5437 settings
->op
[i
].cop
= cop
;
5438 settings
->op
[i
].aop
= aop
;
5439 settings
->op
[i
].carg0
= carg0
;
5440 settings
->op
[i
].carg1
= carg1
;
5441 settings
->op
[i
].carg2
= carg2
;
5442 settings
->op
[i
].aarg0
= aarg0
;
5443 settings
->op
[i
].aarg1
= aarg1
;
5444 settings
->op
[i
].aarg2
= aarg2
;
5446 if (state
->texture_states
[i
][WINED3D_TSS_RESULT_ARG
] == WINED3DTA_TEMP
)
5447 settings
->op
[i
].dst
= tempreg
;
5449 settings
->op
[i
].dst
= resultreg
;
5452 /* Clear unsupported stages */
5453 for(; i
< MAX_TEXTURES
; i
++) {
5454 memset(&settings
->op
[i
], 0xff, sizeof(settings
->op
[i
]));
5457 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
5459 settings
->fog
= WINED3D_FFP_PS_FOG_OFF
;
5461 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
)
5463 if (use_vs(state
) || state
->vertex_declaration
->position_transformed
)
5465 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
5469 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
5471 case WINED3D_FOG_NONE
:
5472 case WINED3D_FOG_LINEAR
:
5473 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
5475 case WINED3D_FOG_EXP
:
5476 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
5478 case WINED3D_FOG_EXP2
:
5479 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
5486 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
5488 case WINED3D_FOG_LINEAR
:
5489 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
5491 case WINED3D_FOG_EXP
:
5492 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
5494 case WINED3D_FOG_EXP2
:
5495 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
5499 settings
->sRGB_write
= !gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && needs_srgb_write(context
, state
, state
->fb
);
5500 if (d3d_info
->vs_clipping
|| !use_vs(state
) || !state
->render_states
[WINED3D_RS_CLIPPING
]
5501 || !state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
])
5503 /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
5504 * the fixed function vertex pipeline is used(which always supports clipplanes), or
5505 * if no clipplane is enabled
5507 settings
->emul_clipplanes
= 0;
5509 settings
->emul_clipplanes
= 1;
5512 if (state
->render_states
[WINED3D_RS_COLORKEYENABLE
] && state
->textures
[0]
5513 && state
->textures
[0]->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
5514 && settings
->op
[0].cop
!= WINED3D_TOP_DISABLE
)
5515 settings
->color_key_enabled
= 1;
5517 settings
->color_key_enabled
= 0;
5519 /* texcoords_initialized is set to meaningful values only when GL doesn't
5520 * support enough varyings to always pass around all the possible texture
5522 * This is used to avoid reading a varying not written by the vertex shader.
5523 * Reading uninitialized varyings on core profile contexts results in an
5524 * error while with builtin varyings on legacy contexts you get undefined
5526 if (d3d_info
->limits
.varying_count
5527 && d3d_info
->limits
.varying_count
< wined3d_max_compat_varyings(gl_info
))
5529 settings
->texcoords_initialized
= 0;
5530 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
5534 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
5535 settings
->texcoords_initialized
|= 1u << i
;
5539 const struct wined3d_stream_info
*si
= &context
->stream_info
;
5540 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5541 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
5542 & WINED3D_FFP_TCI_MASK
5543 || (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
5544 settings
->texcoords_initialized
|= 1u << i
;
5550 settings
->texcoords_initialized
= (1u << MAX_TEXTURES
) - 1;
5553 settings
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
5554 && state
->gl_primitive_type
== GL_POINTS
;
5556 if (gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
5557 settings
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
5559 settings
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
5560 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
5561 : WINED3D_CMP_ALWAYS
) - 1;
5563 if (d3d_info
->emulated_flatshading
)
5564 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
5566 settings
->flatshading
= FALSE
;
5569 const struct ffp_frag_desc
*find_ffp_frag_shader(const struct wine_rb_tree
*fragment_shaders
,
5570 const struct ffp_frag_settings
*settings
)
5572 struct wine_rb_entry
*entry
= wine_rb_get(fragment_shaders
, settings
);
5573 return entry
? WINE_RB_ENTRY_VALUE(entry
, struct ffp_frag_desc
, entry
) : NULL
;
5576 void add_ffp_frag_shader(struct wine_rb_tree
*shaders
, struct ffp_frag_desc
*desc
)
5578 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
5579 * whereas desc points to an extended structure with implementation specific parts. */
5580 if (wine_rb_put(shaders
, &desc
->settings
, &desc
->entry
) == -1)
5582 ERR("Failed to insert ffp frag shader.\n");
5586 /* Activates the texture dimension according to the bound D3D texture. Does
5587 * not care for the colorop or correct gl texture unit (when using nvrc).
5588 * Requires the caller to activate the correct unit. */
5589 /* Context activation is done by the caller (state handler). */
5590 void texture_activate_dimensions(const struct wined3d_texture
*texture
, const struct wined3d_gl_info
*gl_info
)
5594 switch (texture
->target
)
5597 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5598 checkGLcall("glDisable(GL_TEXTURE_3D)");
5599 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5601 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5602 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5604 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5606 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5607 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5609 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
5610 checkGLcall("glEnable(GL_TEXTURE_2D)");
5612 case GL_TEXTURE_RECTANGLE_ARB
:
5613 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
5614 checkGLcall("glDisable(GL_TEXTURE_2D)");
5615 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5616 checkGLcall("glDisable(GL_TEXTURE_3D)");
5617 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5619 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5620 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5622 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_RECTANGLE_ARB
);
5623 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
5626 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5628 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5629 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5631 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5633 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5634 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5636 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
5637 checkGLcall("glDisable(GL_TEXTURE_2D)");
5638 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_3D
);
5639 checkGLcall("glEnable(GL_TEXTURE_3D)");
5641 case GL_TEXTURE_CUBE_MAP_ARB
:
5642 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
5643 checkGLcall("glDisable(GL_TEXTURE_2D)");
5644 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5645 checkGLcall("glDisable(GL_TEXTURE_3D)");
5646 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5648 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5649 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5651 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
5652 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
5658 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
5659 checkGLcall("glEnable(GL_TEXTURE_2D)");
5660 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5661 checkGLcall("glDisable(GL_TEXTURE_3D)");
5662 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5664 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5665 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5667 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5669 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5670 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5672 /* Binding textures is done by samplers. A dummy texture will be bound */
5676 /* Context activation is done by the caller (state handler). */
5677 void sampler_texdim(struct wined3d_context
*context
, const struct wined3d_state
*state
, DWORD state_id
)
5679 DWORD sampler
= state_id
- STATE_SAMPLER(0);
5680 DWORD mapped_stage
= context
->tex_unit_map
[sampler
];
5682 /* No need to enable / disable anything here for unused samplers. The
5683 * tex_colorop handler takes care. Also no action is needed with pixel
5684 * shaders, or if tex_colorop will take care of this business. */
5685 if (mapped_stage
== WINED3D_UNMAPPED_STAGE
|| mapped_stage
>= context
->gl_info
->limits
.textures
)
5687 if (sampler
>= context
->lowest_disabled_stage
)
5689 if (isStateDirty(context
, STATE_TEXTURESTAGE(sampler
, WINED3D_TSS_COLOR_OP
)))
5692 texture_activate_dimensions(state
->textures
[sampler
], context
->gl_info
);
5695 int wined3d_ffp_frag_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
5697 const struct ffp_frag_settings
*ka
= key
;
5698 const struct ffp_frag_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
, const struct ffp_frag_desc
, entry
)->settings
;
5700 return memcmp(ka
, kb
, sizeof(*ka
));
5703 void wined3d_ffp_get_vs_settings(const struct wined3d_context
*context
,
5704 const struct wined3d_state
*state
, struct wined3d_ffp_vs_settings
*settings
)
5706 const struct wined3d_stream_info
*si
= &context
->stream_info
;
5707 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
5708 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
5709 unsigned int coord_idx
, i
;
5711 memset(settings
, 0, sizeof(*settings
));
5713 if (si
->position_transformed
)
5715 settings
->transformed
= 1;
5716 settings
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
5717 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
5718 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
5719 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
5720 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
5721 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
5723 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
5725 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
5727 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5728 if (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
5729 settings
->texcoords
|= 1u << i
;
5730 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5732 if (d3d_info
->limits
.varying_count
>= wined3d_max_compat_varyings(gl_info
))
5733 settings
->texcoords
= (1u << MAX_TEXTURES
) - 1;
5735 if (d3d_info
->emulated_flatshading
)
5736 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
5738 settings
->flatshading
= FALSE
;
5740 settings
->swizzle_map
= si
->swizzle_map
;
5745 switch (state
->render_states
[WINED3D_RS_VERTEXBLEND
])
5747 case WINED3D_VBF_DISABLE
:
5748 case WINED3D_VBF_1WEIGHTS
:
5749 case WINED3D_VBF_2WEIGHTS
:
5750 case WINED3D_VBF_3WEIGHTS
:
5751 settings
->vertexblends
= state
->render_states
[WINED3D_RS_VERTEXBLEND
];
5754 FIXME("Unsupported vertex blending: %d\n", state
->render_states
[WINED3D_RS_VERTEXBLEND
]);
5758 settings
->clipping
= state
->render_states
[WINED3D_RS_CLIPPING
]
5759 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
5760 settings
->normal
= !!(si
->use_map
& (1u << WINED3D_FFP_NORMAL
));
5761 settings
->normalize
= settings
->normal
&& state
->render_states
[WINED3D_RS_NORMALIZENORMALS
];
5762 settings
->lighting
= !!state
->render_states
[WINED3D_RS_LIGHTING
];
5763 settings
->localviewer
= !!state
->render_states
[WINED3D_RS_LOCALVIEWER
];
5764 settings
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
5765 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
5767 if (state
->render_states
[WINED3D_RS_COLORVERTEX
] && (si
->use_map
& (1u << WINED3D_FFP_DIFFUSE
)))
5769 settings
->diffuse_source
= state
->render_states
[WINED3D_RS_DIFFUSEMATERIALSOURCE
];
5770 settings
->emissive_source
= state
->render_states
[WINED3D_RS_EMISSIVEMATERIALSOURCE
];
5771 settings
->ambient_source
= state
->render_states
[WINED3D_RS_AMBIENTMATERIALSOURCE
];
5772 settings
->specular_source
= state
->render_states
[WINED3D_RS_SPECULARMATERIALSOURCE
];
5776 settings
->diffuse_source
= WINED3D_MCS_MATERIAL
;
5777 settings
->emissive_source
= WINED3D_MCS_MATERIAL
;
5778 settings
->ambient_source
= WINED3D_MCS_MATERIAL
;
5779 settings
->specular_source
= WINED3D_MCS_MATERIAL
;
5782 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
5784 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5785 if (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
5786 settings
->texcoords
|= 1u << i
;
5787 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5789 if (d3d_info
->limits
.varying_count
>= wined3d_max_compat_varyings(gl_info
))
5790 settings
->texcoords
= (1u << MAX_TEXTURES
) - 1;
5792 for (i
= 0; i
< MAX_ACTIVE_LIGHTS
; ++i
)
5794 if (!state
->lights
[i
])
5797 switch (state
->lights
[i
]->OriginalParms
.type
)
5799 case WINED3D_LIGHT_POINT
:
5800 ++settings
->point_light_count
;
5802 case WINED3D_LIGHT_SPOT
:
5803 ++settings
->spot_light_count
;
5805 case WINED3D_LIGHT_DIRECTIONAL
:
5806 ++settings
->directional_light_count
;
5808 case WINED3D_LIGHT_PARALLELPOINT
:
5809 ++settings
->parallel_point_light_count
;
5812 FIXME("Unhandled light type %#x.\n", state
->lights
[i
]->OriginalParms
.type
);
5817 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
5818 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
5819 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
5821 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
5823 if (state
->transforms
[WINED3D_TS_PROJECTION
]._14
== 0.0f
5824 && state
->transforms
[WINED3D_TS_PROJECTION
]._24
== 0.0f
5825 && state
->transforms
[WINED3D_TS_PROJECTION
]._34
== 0.0f
5826 && state
->transforms
[WINED3D_TS_PROJECTION
]._44
== 1.0f
)
5827 settings
->ortho_fog
= 1;
5829 else if (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
] == WINED3D_FOG_NONE
)
5830 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
5831 else if (state
->render_states
[WINED3D_RS_RANGEFOGENABLE
])
5832 settings
->fog_mode
= WINED3D_FFP_VS_FOG_RANGE
;
5834 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
5836 if (d3d_info
->emulated_flatshading
)
5837 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
5839 settings
->flatshading
= FALSE
;
5841 settings
->swizzle_map
= si
->swizzle_map
;
5844 int wined3d_ffp_vertex_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
5846 const struct wined3d_ffp_vs_settings
*ka
= key
;
5847 const struct wined3d_ffp_vs_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
,
5848 const struct wined3d_ffp_vs_desc
, entry
)->settings
;
5850 return memcmp(ka
, kb
, sizeof(*ka
));
5853 const struct blit_shader
*wined3d_select_blitter(const struct wined3d_gl_info
*gl_info
,
5854 const struct wined3d_d3d_info
*d3d_info
, enum wined3d_blit_op blit_op
,
5855 const RECT
*src_rect
, DWORD src_usage
, enum wined3d_pool src_pool
, const struct wined3d_format
*src_format
,
5856 const RECT
*dst_rect
, DWORD dst_usage
, enum wined3d_pool dst_pool
, const struct wined3d_format
*dst_format
)
5858 static const struct blit_shader
* const blitters
[] =
5866 TRACE("gl_info %p, d3d_info %p, blit_op %#x, src_rect %s, src_usage %s, src_pool %s, src_format %s, "
5867 "dst_rect %s, dst_usage %s, dst_pool %s, dst_format %s.\n", gl_info
, d3d_info
, blit_op
,
5868 wine_dbgstr_rect(src_rect
), debug_d3dusage(src_usage
), debug_d3dpool(src_pool
),
5869 src_format
? debug_d3dformat(src_format
->id
) : "(null)", wine_dbgstr_rect(dst_rect
),
5870 debug_d3dusage(dst_usage
), debug_d3dpool(dst_pool
), debug_d3dformat(dst_format
->id
));
5872 for (i
= 0; i
< sizeof(blitters
) / sizeof(*blitters
); ++i
)
5874 if (blitters
[i
]->blit_supported(gl_info
, d3d_info
, blit_op
,
5875 src_rect
, src_usage
, src_pool
, src_format
,
5876 dst_rect
, dst_usage
, dst_pool
, dst_format
))
5883 void wined3d_get_draw_rect(const struct wined3d_state
*state
, RECT
*rect
)
5885 const struct wined3d_viewport
*vp
= &state
->viewport
;
5887 SetRect(rect
, vp
->x
, vp
->y
, vp
->x
+ vp
->width
, vp
->y
+ vp
->height
);
5889 if (state
->render_states
[WINED3D_RS_SCISSORTESTENABLE
])
5890 IntersectRect(rect
, rect
, &state
->scissor_rect
);
5893 const char *wined3d_debug_location(DWORD location
)
5895 const char *prefix
= "";
5896 const char *suffix
= "";
5899 if (wined3d_popcount(location
) > 16)
5902 location
= ~location
;
5907 #define LOCATION_TO_STR(u) if (location & u) { strcat(buf, " | "#u); location &= ~u; }
5908 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED
);
5909 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM
);
5910 LOCATION_TO_STR(WINED3D_LOCATION_USER_MEMORY
);
5911 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER
);
5912 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB
);
5913 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB
);
5914 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE
);
5915 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE
);
5916 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED
);
5917 #undef LOCATION_TO_STR
5918 if (location
) FIXME("Unrecognized location flag(s) %#x.\n", location
);
5920 return wine_dbg_sprintf("%s%s%s", prefix
, buf
[0] ? &buf
[3] : "0", suffix
);
5923 /* Print a floating point value with the %.8e format specifier, always using
5924 * '.' as decimal separator. */
5925 void wined3d_ftoa(float value
, char *s
)
5929 if (copysignf(1.0f
, value
) < 0.0f
)
5932 /* Be sure to allocate a buffer of at least 17 characters for the result
5933 as sprintf may return a 3 digit exponent when using the MSVC runtime
5934 instead of a 2 digit exponent. */
5935 sprintf(s
, "%.8e", value
);
5936 if (isfinite(value
))
5940 void wined3d_release_dc(HWND window
, HDC dc
)
5942 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
5943 * However, that's not what actually happens, and there are user32 tests
5944 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
5945 * So explicitly check that the DC belongs to the window, since we want to
5946 * avoid releasing a DC that belongs to some other window if the original
5947 * window was already destroyed. */
5948 if (WindowFromDC(dc
) != window
)
5949 WARN("DC %p does not belong to window %p.\n", dc
, window
);
5950 else if (!ReleaseDC(window
, dc
))
5951 ERR("Failed to release device context %p, last error %#x.\n", dc
, GetLastError());
5954 BOOL
wined3d_clip_blit(const RECT
*clip_rect
, RECT
*clipped
, RECT
*other
)
5956 RECT orig
= *clipped
;
5957 float scale_x
= (float)(orig
.right
- orig
.left
) / (float)(other
->right
- other
->left
);
5958 float scale_y
= (float)(orig
.bottom
- orig
.top
) / (float)(other
->bottom
- other
->top
);
5960 IntersectRect(clipped
, clipped
, clip_rect
);
5962 if (IsRectEmpty(clipped
))
5964 SetRectEmpty(other
);
5968 other
->left
+= (LONG
)((clipped
->left
- orig
.left
) / scale_x
);
5969 other
->top
+= (LONG
)((clipped
->top
- orig
.top
) / scale_y
);
5970 other
->right
-= (LONG
)((orig
.right
- clipped
->right
) / scale_x
);
5971 other
->bottom
-= (LONG
)((orig
.bottom
- clipped
->bottom
) / scale_y
);
5976 void wined3d_gl_limits_get_uniform_block_range(const struct wined3d_gl_limits
*gl_limits
,
5977 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
5982 for (i
= 0; i
< WINED3D_SHADER_TYPE_COUNT
; ++i
)
5984 *count
= gl_limits
->uniform_blocks
[i
];
5985 if (i
== shader_type
)
5990 ERR("Unrecognized shader type %#x.\n", shader_type
);
5994 void wined3d_gl_limits_get_texture_unit_range(const struct wined3d_gl_limits
*gl_limits
,
5995 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
5999 if (shader_type
== WINED3D_SHADER_TYPE_COMPUTE
)
6001 if (gl_limits
->combined_samplers
== gl_limits
->graphics_samplers
)
6004 *base
= gl_limits
->graphics_samplers
- 1;
6005 *count
= gl_limits
->samplers
[WINED3D_SHADER_TYPE_COMPUTE
];
6010 for (i
= 0; i
< WINED3D_SHADER_TYPE_GRAPHICS_COUNT
; ++i
)
6012 *count
= gl_limits
->samplers
[i
];
6013 if (i
== shader_type
)
6018 ERR("Unrecognized shader type %#x.\n", shader_type
);
6022 BOOL
wined3d_array_reserve(void **elements
, SIZE_T
*capacity
, SIZE_T count
, SIZE_T size
)
6024 SIZE_T max_capacity
, new_capacity
;
6027 if (count
<= *capacity
)
6030 max_capacity
= ~(SIZE_T
)0 / size
;
6031 if (count
> max_capacity
)
6034 new_capacity
= max(1, *capacity
);
6035 while (new_capacity
< count
&& new_capacity
<= max_capacity
/ 2)
6037 if (new_capacity
< count
)
6038 new_capacity
= count
;
6041 new_elements
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, new_capacity
* size
);
6043 new_elements
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, *elements
, new_capacity
* size
);
6047 *elements
= new_elements
;
6048 *capacity
= new_capacity
;