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_R10G10B10A2_SNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "iiii"},
226 {WINED3DFMT_R10G10B10A2_UINT
, WINED3DFMT_R10G10B10A2_TYPELESS
, "UUUU"},
227 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "uuuu"},
228 {WINED3DFMT_R8G8B8A8_UINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "UUUU"},
229 {WINED3DFMT_R8G8B8A8_SINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "IIII"},
230 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
231 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
232 {WINED3DFMT_R16G16_UNORM
, WINED3DFMT_R16G16_TYPELESS
, "uu"},
233 {WINED3DFMT_R16G16_SNORM
, WINED3DFMT_R16G16_TYPELESS
, "ii"},
234 {WINED3DFMT_R16G16_UINT
, WINED3DFMT_R16G16_TYPELESS
, "UU"},
235 {WINED3DFMT_R16G16_SINT
, WINED3DFMT_R16G16_TYPELESS
, "II"},
236 {WINED3DFMT_R16G16_FLOAT
, WINED3DFMT_R16G16_TYPELESS
, "FF"},
237 {WINED3DFMT_R32_UINT
, WINED3DFMT_R32_TYPELESS
, "U"},
238 {WINED3DFMT_R32_SINT
, WINED3DFMT_R32_TYPELESS
, "I"},
239 {WINED3DFMT_R32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "F"},
240 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "D"},
241 {WINED3DFMT_R24_UNORM_X8_TYPELESS
, WINED3DFMT_R24G8_TYPELESS
, "DX"},
242 {WINED3DFMT_X24_TYPELESS_G8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "XS"},
243 {WINED3DFMT_D24_UNORM_S8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "DS"},
244 {WINED3DFMT_R8G8_SNORM
, WINED3DFMT_R8G8_TYPELESS
, "ii"},
245 {WINED3DFMT_R8G8_UNORM
, WINED3DFMT_R8G8_TYPELESS
, "uu"},
246 {WINED3DFMT_R8G8_UINT
, WINED3DFMT_R8G8_TYPELESS
, "UU"},
247 {WINED3DFMT_R8G8_SINT
, WINED3DFMT_R8G8_TYPELESS
, "II"},
248 {WINED3DFMT_R16_UNORM
, WINED3DFMT_R16_TYPELESS
, "u"},
249 {WINED3DFMT_R16_UINT
, WINED3DFMT_R16_TYPELESS
, "U"},
250 {WINED3DFMT_R16_SINT
, WINED3DFMT_R16_TYPELESS
, "I"},
251 {WINED3DFMT_R16_FLOAT
, WINED3DFMT_R16_TYPELESS
, "F"},
252 {WINED3DFMT_D16_UNORM
, WINED3DFMT_R16_TYPELESS
, "D"},
253 {WINED3DFMT_R8_UNORM
, WINED3DFMT_R8_TYPELESS
, "u"},
254 {WINED3DFMT_R8_UINT
, WINED3DFMT_R8_TYPELESS
, "U"},
255 {WINED3DFMT_R8_SINT
, WINED3DFMT_R8_TYPELESS
, "I"},
256 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_TYPELESS
, ""},
257 {WINED3DFMT_BC1_UNORM
, WINED3DFMT_BC1_TYPELESS
, ""},
258 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_TYPELESS
, ""},
259 {WINED3DFMT_BC2_UNORM
, WINED3DFMT_BC2_TYPELESS
, ""},
260 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_TYPELESS
, ""},
261 {WINED3DFMT_BC3_UNORM
, WINED3DFMT_BC3_TYPELESS
, ""},
262 {WINED3DFMT_BC4_UNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
263 {WINED3DFMT_BC5_UNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
264 {WINED3DFMT_BC6H_UF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
265 {WINED3DFMT_BC6H_SF16
, WINED3DFMT_BC6H_TYPELESS
, ""},
266 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_TYPELESS
, ""},
267 {WINED3DFMT_BC7_UNORM
, WINED3DFMT_BC7_TYPELESS
, ""},
268 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
269 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
270 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
271 {WINED3DFMT_B8G8R8X8_UNORM
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuuX"},
274 struct wined3d_format_ddi_info
276 enum wined3d_format_id id
;
277 D3DDDIFORMAT ddi_format
;
280 static const struct wined3d_format_ddi_info ddi_formats
[] =
282 {WINED3DFMT_B8G8R8_UNORM
, D3DDDIFMT_R8G8B8
},
283 {WINED3DFMT_B8G8R8A8_UNORM
, D3DDDIFMT_A8R8G8B8
},
284 {WINED3DFMT_B8G8R8X8_UNORM
, D3DDDIFMT_X8R8G8B8
},
285 {WINED3DFMT_B5G6R5_UNORM
, D3DDDIFMT_R5G6B5
},
286 {WINED3DFMT_B5G5R5X1_UNORM
, D3DDDIFMT_X1R5G5B5
},
287 {WINED3DFMT_B5G5R5A1_UNORM
, D3DDDIFMT_A1R5G5B5
},
288 {WINED3DFMT_P8_UINT
, D3DDDIFMT_P8
},
291 struct wined3d_format_base_flags
293 enum wined3d_format_id id
;
297 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
298 * still needs to use the correct block based calculation for e.g. the
300 static const struct wined3d_format_base_flags format_base_flags
[] =
302 {WINED3DFMT_ATI1N
, WINED3DFMT_FLAG_BROKEN_PITCH
},
303 {WINED3DFMT_ATI2N
, WINED3DFMT_FLAG_BROKEN_PITCH
},
304 {WINED3DFMT_R11G11B10_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
305 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
306 {WINED3DFMT_S8_UINT_D24_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
309 struct wined3d_format_block_info
311 enum wined3d_format_id id
;
314 UINT block_byte_count
;
318 static const struct wined3d_format_block_info format_block_info
[] =
320 {WINED3DFMT_DXT1
, 4, 4, 8, TRUE
},
321 {WINED3DFMT_DXT2
, 4, 4, 16, TRUE
},
322 {WINED3DFMT_DXT3
, 4, 4, 16, TRUE
},
323 {WINED3DFMT_DXT4
, 4, 4, 16, TRUE
},
324 {WINED3DFMT_DXT5
, 4, 4, 16, TRUE
},
325 {WINED3DFMT_BC1_UNORM
, 4, 4, 8, TRUE
},
326 {WINED3DFMT_BC2_UNORM
, 4, 4, 16, TRUE
},
327 {WINED3DFMT_BC3_UNORM
, 4, 4, 16, TRUE
},
328 {WINED3DFMT_BC4_UNORM
, 4, 4, 8, TRUE
},
329 {WINED3DFMT_BC5_UNORM
, 4, 4, 16, TRUE
},
330 {WINED3DFMT_BC6H_UF16
, 4, 4, 16, TRUE
},
331 {WINED3DFMT_BC6H_SF16
, 4, 4, 16, TRUE
},
332 {WINED3DFMT_BC7_UNORM
, 4, 4, 16, TRUE
},
333 {WINED3DFMT_ATI1N
, 4, 4, 8, FALSE
},
334 {WINED3DFMT_ATI2N
, 4, 4, 16, FALSE
},
335 {WINED3DFMT_YUY2
, 2, 1, 4, FALSE
},
336 {WINED3DFMT_UYVY
, 2, 1, 4, FALSE
},
339 struct wined3d_format_vertex_info
341 enum wined3d_format_id id
;
342 enum wined3d_ffp_emit_idx emit_idx
;
343 unsigned int component_count
;
345 GLboolean gl_normalized
;
346 enum wined3d_gl_extension extension
;
349 static const struct wined3d_format_vertex_info format_vertex_info
[] =
351 {WINED3DFMT_R32_FLOAT
, WINED3D_FFP_EMIT_FLOAT1
, 1, GL_FLOAT
, GL_FALSE
},
352 {WINED3DFMT_R32G32_FLOAT
, WINED3D_FFP_EMIT_FLOAT2
, 2, GL_FLOAT
, GL_FALSE
},
353 {WINED3DFMT_R32G32B32_FLOAT
, WINED3D_FFP_EMIT_FLOAT3
, 3, GL_FLOAT
, GL_FALSE
},
354 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3D_FFP_EMIT_FLOAT4
, 4, GL_FLOAT
, GL_FALSE
},
355 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3D_FFP_EMIT_D3DCOLOR
, 4, GL_UNSIGNED_BYTE
, GL_TRUE
},
356 {WINED3DFMT_R8G8B8A8_UINT
, WINED3D_FFP_EMIT_UBYTE4
, 4, GL_UNSIGNED_BYTE
, GL_FALSE
},
357 {WINED3DFMT_R16G16_UINT
, WINED3D_FFP_EMIT_INVALID
, 2, GL_UNSIGNED_SHORT
, GL_FALSE
},
358 {WINED3DFMT_R16G16_SINT
, WINED3D_FFP_EMIT_SHORT2
, 2, GL_SHORT
, GL_FALSE
},
359 {WINED3DFMT_R16G16B16A16_SINT
, WINED3D_FFP_EMIT_SHORT4
, 4, GL_SHORT
, GL_FALSE
},
360 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3D_FFP_EMIT_UBYTE4N
, 4, GL_UNSIGNED_BYTE
, GL_TRUE
},
361 {WINED3DFMT_R16G16_SNORM
, WINED3D_FFP_EMIT_SHORT2N
, 2, GL_SHORT
, GL_TRUE
},
362 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3D_FFP_EMIT_SHORT4N
, 4, GL_SHORT
, GL_TRUE
},
363 {WINED3DFMT_R16G16_UNORM
, WINED3D_FFP_EMIT_USHORT2N
, 2, GL_UNSIGNED_SHORT
, GL_TRUE
},
364 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3D_FFP_EMIT_USHORT4N
, 4, GL_UNSIGNED_SHORT
, GL_TRUE
},
365 {WINED3DFMT_R10G10B10X2_UINT
, WINED3D_FFP_EMIT_UDEC3
, 3, GL_UNSIGNED_SHORT
, GL_FALSE
},
366 {WINED3DFMT_R10G10B10X2_SNORM
, WINED3D_FFP_EMIT_DEC3N
, 3, GL_SHORT
, GL_TRUE
},
367 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3D_FFP_EMIT_INVALID
, 4, GL_UNSIGNED_INT_2_10_10_10_REV
, GL_TRUE
,
368 ARB_VERTEX_TYPE_2_10_10_10_REV
},
369 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, 2, GL_HALF_FLOAT
, GL_FALSE
},
370 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, 4, GL_HALF_FLOAT
, GL_FALSE
},
371 {WINED3DFMT_R8G8B8A8_SNORM
, WINED3D_FFP_EMIT_INVALID
, 4, GL_BYTE
, GL_TRUE
},
372 {WINED3DFMT_R8G8B8A8_SINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_BYTE
, GL_FALSE
},
373 {WINED3DFMT_R16G16B16A16_UINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_UNSIGNED_SHORT
, GL_FALSE
},
374 {WINED3DFMT_R8_UINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_BYTE
, GL_FALSE
},
375 {WINED3DFMT_R8_SINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_BYTE
, GL_FALSE
},
376 {WINED3DFMT_R16_UINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_SHORT
, GL_FALSE
},
377 {WINED3DFMT_R16_SINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_SHORT
, GL_FALSE
},
378 {WINED3DFMT_R32_UINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_INT
, GL_FALSE
},
379 {WINED3DFMT_R32_SINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_INT
, GL_FALSE
},
380 {WINED3DFMT_R32G32_UINT
, WINED3D_FFP_EMIT_INVALID
, 2, GL_UNSIGNED_INT
, GL_FALSE
},
381 {WINED3DFMT_R32G32_SINT
, WINED3D_FFP_EMIT_INVALID
, 2, GL_INT
, GL_FALSE
},
382 {WINED3DFMT_R32G32B32_UINT
, WINED3D_FFP_EMIT_INVALID
, 3, GL_UNSIGNED_INT
, GL_FALSE
},
383 {WINED3DFMT_R32G32B32A32_UINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_UNSIGNED_INT
, GL_FALSE
},
384 {WINED3DFMT_R32G32B32A32_SINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_INT
, GL_FALSE
},
387 struct wined3d_format_texture_info
389 enum wined3d_format_id id
;
391 GLint gl_srgb_internal
;
392 GLint gl_rt_internal
;
395 unsigned int conv_byte_count
;
397 enum wined3d_gl_extension extension
;
398 void (*convert
)(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
399 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
);
402 static void convert_l4a4_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
403 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
405 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
406 * format+type combination to load it. Thus convert it to A8L8, then load it
407 * with A4L4 internal, but A8L8 format+type
409 unsigned int x
, y
, z
;
410 const unsigned char *Source
;
413 for (z
= 0; z
< depth
; z
++)
415 for (y
= 0; y
< height
; y
++)
417 Source
= src
+ z
* src_slice_pitch
+ y
* src_row_pitch
;
418 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
419 for (x
= 0; x
< width
; x
++ )
421 unsigned char color
= (*Source
++);
422 /* A */ Dest
[1] = (color
& 0xf0u
) << 0;
423 /* L */ Dest
[0] = (color
& 0x0fu
) << 4;
430 static void convert_r5g5_snorm_l6_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 unsigned int x
, y
, z
;
434 unsigned char r_in
, g_in
, l_in
;
435 const unsigned short *texel_in
;
436 unsigned short *texel_out
;
438 /* Emulating signed 5 bit values with unsigned 5 bit values has some precision problems by design:
439 * E.g. the signed input value 0 becomes 16. GL normalizes it to 16 / 31 = 0.516. We convert it
440 * back to a signed value by subtracting 0.5 and multiplying by 2.0. The resulting value is
441 * ((16 / 31) - 0.5) * 2.0 = 0.032, which is quite different from the intended result 0.000. */
442 for (z
= 0; z
< depth
; z
++)
444 for (y
= 0; y
< height
; y
++)
446 texel_out
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
447 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
448 for (x
= 0; x
< width
; x
++ )
450 l_in
= (*texel_in
& 0xfc00u
) >> 10;
451 g_in
= (*texel_in
& 0x03e0u
) >> 5;
452 r_in
= *texel_in
& 0x001fu
;
454 *texel_out
= ((r_in
+ 16) << 11) | (l_in
<< 5) | (g_in
+ 16);
462 static void convert_r5g5_snorm_l6_unorm_ext(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
463 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
465 unsigned int x
, y
, z
;
466 unsigned char *texel_out
, r_out
, g_out
, r_in
, g_in
, l_in
;
467 const unsigned short *texel_in
;
469 for (z
= 0; z
< depth
; z
++)
471 for (y
= 0; y
< height
; y
++)
473 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
474 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
475 for (x
= 0; x
< width
; x
++ )
477 l_in
= (*texel_in
& 0xfc00u
) >> 10;
478 g_in
= (*texel_in
& 0x03e0u
) >> 5;
479 r_in
= *texel_in
& 0x001fu
;
482 if (!(r_in
& 0x10)) /* r > 0 */
486 if (!(g_in
& 0x10)) /* g > 0 */
489 texel_out
[0] = r_out
;
490 texel_out
[1] = g_out
;
491 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
501 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
502 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
504 unsigned int x
, y
, z
;
505 unsigned char *texel_out
, ds_out
, dt_out
, r_in
, g_in
, l_in
;
506 const unsigned short *texel_in
;
508 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
509 * fixed function and shaders without further conversion once the surface is
512 * The difference between this function and convert_r5g5_snorm_l6_unorm_ext
513 * is that convert_r5g5_snorm_l6_unorm_ext creates a 32 bit XRGB texture and
514 * this function creates a 24 bit DSDT_MAG texture. Trying to load a DSDT_MAG
515 * internal with a 32 bit DSDT_MAG_INTENSITY or DSDT_MAG_VIB format fails. */
516 for (z
= 0; z
< depth
; z
++)
518 for (y
= 0; y
< height
; y
++)
520 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
521 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
522 for (x
= 0; x
< width
; x
++ )
524 l_in
= (*texel_in
& 0xfc00u
) >> 10;
525 g_in
= (*texel_in
& 0x03e0u
) >> 5;
526 r_in
= *texel_in
& 0x001fu
;
529 if (!(r_in
& 0x10)) /* r > 0 */
533 if (!(g_in
& 0x10)) /* g > 0 */
536 texel_out
[0] = ds_out
;
537 texel_out
[1] = dt_out
;
538 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
547 static void convert_r8g8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
548 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
550 unsigned int x
, y
, z
;
554 for (z
= 0; z
< depth
; z
++)
556 for (y
= 0; y
< height
; y
++)
558 Source
= (const short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
559 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
560 for (x
= 0; x
< width
; x
++ )
562 const short color
= (*Source
++);
563 /* B */ Dest
[0] = 0xff;
564 /* G */ Dest
[1] = (color
>> 8) + 128; /* V */
565 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
572 static void convert_r8g8_snorm_l8x8_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
573 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
575 unsigned int x
, y
, z
;
579 /* Doesn't work correctly with the fixed function pipeline, but can work in
580 * shaders if the shader is adjusted. (There's no use for this format in gl's
581 * standard fixed function pipeline anyway).
583 for (z
= 0; z
< depth
; z
++)
585 for (y
= 0; y
< height
; y
++)
587 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
588 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
589 for (x
= 0; x
< width
; x
++ )
591 LONG color
= (*Source
++);
592 /* B */ Dest
[0] = ((color
>> 16) & 0xff); /* L */
593 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
594 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
601 static void convert_r8g8_snorm_l8x8_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
602 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
604 unsigned int x
, y
, z
;
608 /* This implementation works with the fixed function pipeline and shaders
609 * without further modification after converting the surface.
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 /* L */ Dest
[2] = ((color
>> 16) & 0xff); /* L */
621 /* V */ Dest
[1] = ((color
>> 8 ) & 0xff); /* V */
622 /* U */ Dest
[0] = (color
& 0xff); /* U */
623 /* I */ Dest
[3] = 255; /* X */
630 static void convert_r8g8b8a8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
631 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
633 unsigned int x
, y
, z
;
637 for (z
= 0; z
< depth
; z
++)
639 for (y
= 0; y
< height
; y
++)
641 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
642 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
643 for (x
= 0; x
< width
; x
++ )
645 LONG color
= (*Source
++);
646 /* B */ Dest
[0] = ((color
>> 16) & 0xff) + 128; /* W */
647 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
648 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
649 /* A */ Dest
[3] = ((color
>> 24) & 0xff) + 128; /* Q */
656 static void convert_r16g16_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
657 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
659 unsigned int x
, y
, z
;
661 unsigned short *Dest
;
663 for (z
= 0; z
< depth
; z
++)
665 for (y
= 0; y
< height
; y
++)
667 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
668 Dest
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
669 for (x
= 0; x
< width
; x
++ )
671 const DWORD color
= (*Source
++);
672 /* B */ Dest
[0] = 0xffff;
673 /* G */ Dest
[1] = (color
>> 16) + 32768; /* V */
674 /* R */ Dest
[2] = (color
& 0xffff) + 32768; /* U */
681 static void convert_r16g16(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
682 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
684 unsigned int x
, y
, z
;
688 for (z
= 0; z
< depth
; z
++)
690 for (y
= 0; y
< height
; y
++)
692 Source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
693 Dest
= (WORD
*) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
694 for (x
= 0; x
< width
; x
++ )
696 WORD green
= (*Source
++);
697 WORD red
= (*Source
++);
700 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
701 * shader overwrites it anyway */
709 static void convert_r32g32_float(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 float *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
721 Dest
= (float *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
722 for (x
= 0; x
< width
; x
++ )
724 float green
= (*Source
++);
725 float red
= (*Source
++);
735 static void convert_s1_uint_d15_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
736 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
738 unsigned int x
, y
, z
;
740 for (z
= 0; z
< depth
; z
++)
742 for (y
= 0; y
< height
; ++y
)
744 const WORD
*source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
745 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
747 for (x
= 0; x
< width
; ++x
)
749 /* The depth data is normalized, so needs to be scaled,
750 * the stencil data isn't. Scale depth data by
751 * (2^24-1)/(2^15-1) ~~ (2^9 + 2^-6). */
752 WORD d15
= source
[x
] >> 1;
753 DWORD d24
= (d15
<< 9) + (d15
>> 6);
754 dest
[x
] = (d24
<< 8) | (source
[x
] & 0x1);
760 static void convert_s4x4_uint_d24_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
761 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
763 unsigned int x
, y
, z
;
765 for (z
= 0; z
< depth
; z
++)
767 for (y
= 0; y
< height
; ++y
)
769 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
770 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
772 for (x
= 0; x
< width
; ++x
)
774 /* Just need to clear out the X4 part. */
775 dest
[x
] = source
[x
] & ~0xf0;
781 static void convert_s8_uint_d24_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
782 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
784 unsigned int x
, y
, z
;
786 for (z
= 0; z
< depth
; z
++)
788 for (y
= 0; y
< height
; ++y
)
790 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
791 float *dest_f
= (float *)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
792 DWORD
*dest_s
= (DWORD
*)dest_f
;
794 for (x
= 0; x
< width
; ++x
)
796 dest_f
[x
* 2] = float_24_to_32((source
[x
] & 0xffffff00u
) >> 8);
797 dest_s
[x
* 2 + 1] = source
[x
] & 0xff;
803 static BOOL
color_in_range(const struct wined3d_color_key
*color_key
, DWORD color
)
805 /* FIXME: Is this really how color keys are supposed to work? I think it
806 * makes more sense to compare the individual channels. */
807 return color
>= color_key
->color_space_low_value
808 && color
<= color_key
->color_space_high_value
;
811 static void convert_p8_uint_b8g8r8a8_unorm(const BYTE
*src
, unsigned int src_pitch
,
812 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
813 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
821 /* FIXME: This should probably use the system palette. */
822 FIXME("P8 surface loaded without a palette.\n");
824 for (y
= 0; y
< height
; ++y
)
826 memset(&dst
[dst_pitch
* y
], 0, width
* 4);
832 for (y
= 0; y
< height
; ++y
)
834 src_row
= &src
[src_pitch
* y
];
835 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
836 for (x
= 0; x
< width
; ++x
)
838 BYTE src_color
= src_row
[x
];
839 dst_row
[x
] = 0xff000000
840 | (palette
->colors
[src_color
].rgbRed
<< 16)
841 | (palette
->colors
[src_color
].rgbGreen
<< 8)
842 | palette
->colors
[src_color
].rgbBlue
;
847 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
848 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
849 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
855 for (y
= 0; y
< height
; ++y
)
857 src_row
= (WORD
*)&src
[src_pitch
* y
];
858 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
859 for (x
= 0; x
< width
; ++x
)
861 WORD src_color
= src_row
[x
];
862 if (!color_in_range(color_key
, src_color
))
863 dst_row
[x
] = 0x8000u
| ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
865 dst_row
[x
] = ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
870 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
871 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
872 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
878 for (y
= 0; y
< height
; ++y
)
880 src_row
= (WORD
*)&src
[src_pitch
* y
];
881 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
882 for (x
= 0; x
< width
; ++x
)
884 WORD src_color
= src_row
[x
];
885 if (color_in_range(color_key
, src_color
))
886 dst_row
[x
] = src_color
& ~0x8000;
888 dst_row
[x
] = src_color
| 0x8000;
893 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
894 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
895 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
901 for (y
= 0; y
< height
; ++y
)
903 src_row
= &src
[src_pitch
* y
];
904 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
905 for (x
= 0; x
< width
; ++x
)
907 DWORD src_color
= (src_row
[x
* 3 + 2] << 16) | (src_row
[x
* 3 + 1] << 8) | src_row
[x
* 3];
908 if (!color_in_range(color_key
, src_color
))
909 dst_row
[x
] = src_color
| 0xff000000;
914 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
915 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
916 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
918 const DWORD
*src_row
;
922 for (y
= 0; y
< height
; ++y
)
924 src_row
= (DWORD
*)&src
[src_pitch
* y
];
925 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
926 for (x
= 0; x
< width
; ++x
)
928 DWORD src_color
= src_row
[x
];
929 if (color_in_range(color_key
, src_color
))
930 dst_row
[x
] = src_color
& ~0xff000000;
932 dst_row
[x
] = src_color
| 0xff000000;
937 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
938 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
939 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
941 const DWORD
*src_row
;
945 for (y
= 0; y
< height
; ++y
)
947 src_row
= (DWORD
*)&src
[src_pitch
* y
];
948 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
949 for (x
= 0; x
< width
; ++x
)
951 DWORD src_color
= src_row
[x
];
952 if (color_in_range(color_key
, src_color
))
953 src_color
&= ~0xff000000;
954 dst_row
[x
] = src_color
;
959 const struct wined3d_color_key_conversion
* wined3d_format_get_color_key_conversion(
960 const struct wined3d_texture
*texture
, BOOL need_alpha_ck
)
962 const struct wined3d_format
*format
= texture
->resource
.format
;
967 enum wined3d_format_id src_format
;
968 struct wined3d_color_key_conversion conversion
;
972 {WINED3DFMT_B5G6R5_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key
}},
973 {WINED3DFMT_B5G5R5X1_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key
}},
974 {WINED3DFMT_B8G8R8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key
}},
975 {WINED3DFMT_B8G8R8X8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key
}},
976 {WINED3DFMT_B8G8R8A8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key
}},
978 static const struct wined3d_color_key_conversion convert_p8
=
980 WINED3DFMT_B8G8R8A8_UNORM
, convert_p8_uint_b8g8r8a8_unorm
983 if (need_alpha_ck
&& (texture
->async
.flags
& WINED3D_TEXTURE_ASYNC_COLOR_KEY
))
985 for (i
= 0; i
< sizeof(color_key_info
) / sizeof(*color_key_info
); ++i
)
987 if (color_key_info
[i
].src_format
== format
->id
)
988 return &color_key_info
[i
].conversion
;
991 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format
->id
));
994 /* FIXME: This should check if the blitter backend can do P8 conversion,
995 * instead of checking for ARB_fragment_program. */
996 if (format
->id
== WINED3DFMT_P8_UINT
997 && !(texture
->resource
.device
->adapter
->gl_info
.supported
[ARB_FRAGMENT_PROGRAM
]
998 && texture
->swapchain
&& texture
== texture
->swapchain
->front_buffer
))
1004 /* The following formats explicitly don't have WINED3DFMT_FLAG_TEXTURE set:
1006 * These are never supported on native.
1007 * WINED3DFMT_B8G8R8_UNORM
1008 * WINED3DFMT_B2G3R3_UNORM
1009 * WINED3DFMT_L4A4_UNORM
1010 * WINED3DFMT_S1_UINT_D15_UNORM
1011 * WINED3DFMT_S4X4_UINT_D24_UNORM
1013 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
1014 * Since it is not widely available, don't offer it. Further no Windows driver
1015 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
1016 * WINED3DFMT_P8_UINT
1017 * WINED3DFMT_P8_UINT_A8_UNORM
1019 * These formats seem to be similar to the HILO formats in
1020 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
1021 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
1022 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
1023 * refused to support formats which can easily be emulated with pixel shaders,
1024 * so applications have to deal with not having NVHS and NVHU.
1026 * WINED3DFMT_NVHS */
1027 static const struct wined3d_format_texture_info format_texture_info
[] =
1029 /* format id gl_internal gl_srgb_internal gl_rt_internal
1030 gl_format gl_type conv_byte_count
1032 extension convert */
1033 /* FourCC formats */
1034 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
1035 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
1036 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
1037 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
1040 {WINED3DFMT_UYVY
, GL_RG8
, GL_RG8
, 0,
1041 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1042 WINED3DFMT_FLAG_FILTERING
,
1043 ARB_TEXTURE_RG
, NULL
},
1044 {WINED3DFMT_UYVY
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1045 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1046 WINED3DFMT_FLAG_FILTERING
,
1047 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1048 {WINED3DFMT_UYVY
, GL_RGB
, GL_RGB
, 0,
1049 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
1050 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
1051 APPLE_YCBCR_422
, NULL
},
1052 {WINED3DFMT_YUY2
, GL_RG8
, GL_RG8
, 0,
1053 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1054 WINED3DFMT_FLAG_FILTERING
,
1055 ARB_TEXTURE_RG
, NULL
},
1056 {WINED3DFMT_YUY2
, GL_LUMINANCE8_ALPHA8
, GL_LUMINANCE8_ALPHA8
, 0,
1057 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1058 WINED3DFMT_FLAG_FILTERING
,
1059 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1060 {WINED3DFMT_YUY2
, GL_RGB
, GL_RGB
, 0,
1061 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
1062 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
1063 APPLE_YCBCR_422
, NULL
},
1064 {WINED3DFMT_YV12
, GL_R8
, GL_R8
, 0,
1065 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1066 WINED3DFMT_FLAG_FILTERING
,
1067 ARB_TEXTURE_RG
, NULL
},
1068 {WINED3DFMT_YV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1069 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1070 WINED3DFMT_FLAG_FILTERING
,
1071 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1072 {WINED3DFMT_NV12
, GL_R8
, GL_R8
, 0,
1073 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1074 WINED3DFMT_FLAG_FILTERING
,
1075 ARB_TEXTURE_RG
, NULL
},
1076 {WINED3DFMT_NV12
, GL_ALPHA8
, GL_ALPHA8
, 0,
1077 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1078 WINED3DFMT_FLAG_FILTERING
,
1079 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1080 {WINED3DFMT_DXT1
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1081 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1082 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1083 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1084 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1085 {WINED3DFMT_DXT2
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1086 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1087 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1088 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1089 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1090 {WINED3DFMT_DXT3
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1091 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1092 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1093 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1094 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1095 {WINED3DFMT_DXT4
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1096 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1097 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1098 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1099 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1100 {WINED3DFMT_DXT5
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1101 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1102 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1103 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1104 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1105 {WINED3DFMT_BC1_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1106 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1107 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1108 | WINED3DFMT_FLAG_COMPRESSED
,
1109 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1110 {WINED3DFMT_BC2_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1111 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1112 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1113 | WINED3DFMT_FLAG_COMPRESSED
,
1114 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1115 {WINED3DFMT_BC3_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1116 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1117 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1118 | WINED3DFMT_FLAG_COMPRESSED
,
1119 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1120 {WINED3DFMT_BC4_UNORM
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1121 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1122 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1123 | WINED3DFMT_FLAG_COMPRESSED
,
1124 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1125 {WINED3DFMT_BC5_UNORM
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1126 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1127 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1128 | WINED3DFMT_FLAG_COMPRESSED
,
1129 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1130 {WINED3DFMT_BC6H_UF16
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB
, 0,
1131 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1132 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1133 | WINED3DFMT_FLAG_COMPRESSED
,
1134 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1135 {WINED3DFMT_BC6H_SF16
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB
, 0,
1136 GL_RGB
, GL_UNSIGNED_BYTE
, 0,
1137 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1138 | WINED3DFMT_FLAG_COMPRESSED
,
1139 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1140 {WINED3DFMT_BC7_UNORM
, GL_COMPRESSED_RGBA_BPTC_UNORM_ARB
, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB
, 0,
1141 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1142 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1143 | WINED3DFMT_FLAG_COMPRESSED
,
1144 ARB_TEXTURE_COMPRESSION_BPTC
, NULL
},
1146 {WINED3DFMT_R32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1147 GL_RED
, GL_FLOAT
, 0,
1148 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1149 ARB_TEXTURE_FLOAT
, NULL
},
1150 {WINED3DFMT_R32_FLOAT
, GL_R32F
, GL_R32F
, 0,
1151 GL_RED
, GL_FLOAT
, 0,
1152 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1153 ARB_TEXTURE_RG
, NULL
},
1154 {WINED3DFMT_R32G32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1155 GL_RGB
, GL_FLOAT
, 12,
1156 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1157 ARB_TEXTURE_FLOAT
, convert_r32g32_float
},
1158 {WINED3DFMT_R32G32_FLOAT
, GL_RG32F
, GL_RG32F
, 0,
1160 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1161 ARB_TEXTURE_RG
, NULL
},
1162 {WINED3DFMT_R32G32B32_FLOAT
, GL_RGB32F
, GL_RGB32F
, 0,
1163 GL_RGB
, GL_FLOAT
, 0,
1164 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1165 ARB_TEXTURE_FLOAT
, NULL
},
1166 {WINED3DFMT_R32G32B32A32_FLOAT
, GL_RGBA32F_ARB
, GL_RGBA32F_ARB
, 0,
1167 GL_RGBA
, GL_FLOAT
, 0,
1168 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1169 ARB_TEXTURE_FLOAT
, NULL
},
1171 {WINED3DFMT_R16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1172 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1173 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1174 ARB_TEXTURE_FLOAT
, NULL
},
1175 {WINED3DFMT_R16_FLOAT
, GL_R16F
, GL_R16F
, 0,
1176 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1177 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1178 ARB_TEXTURE_RG
, NULL
},
1179 {WINED3DFMT_R16G16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1180 GL_RGB
, GL_HALF_FLOAT_ARB
, 6,
1181 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1182 ARB_TEXTURE_FLOAT
, convert_r16g16
},
1183 {WINED3DFMT_R16G16_FLOAT
, GL_RG16F
, GL_RG16F
, 0,
1184 GL_RG
, GL_HALF_FLOAT_ARB
, 0,
1185 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1186 ARB_TEXTURE_RG
, NULL
},
1187 {WINED3DFMT_R16G16B16A16_FLOAT
, GL_RGBA16F_ARB
, GL_RGBA16F_ARB
, 0,
1188 GL_RGBA
, GL_HALF_FLOAT_ARB
, 0,
1189 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
1190 | WINED3DFMT_FLAG_VTF
,
1191 ARB_TEXTURE_FLOAT
, NULL
},
1192 {WINED3DFMT_R11G11B10_FLOAT
, GL_R11F_G11F_B10F
, GL_R11F_G11F_B10F
, 0,
1193 GL_RGB
, GL_UNSIGNED_INT_10F_11F_11F_REV
, 0,
1194 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
,
1196 /* Palettized formats */
1197 {WINED3DFMT_P8_UINT
, GL_R8
, GL_R8
, 0,
1198 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1200 ARB_TEXTURE_RG
, NULL
},
1201 {WINED3DFMT_P8_UINT
, GL_ALPHA8
, GL_ALPHA8
, 0,
1202 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1204 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1205 /* Standard ARGB formats */
1206 {WINED3DFMT_B8G8R8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1207 GL_BGR
, GL_UNSIGNED_BYTE
, 0,
1208 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
| WINED3DFMT_FLAG_RENDERTARGET
,
1209 WINED3D_GL_EXT_NONE
, NULL
},
1210 {WINED3DFMT_B8G8R8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1211 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1212 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1213 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1214 | WINED3DFMT_FLAG_VTF
,
1215 WINED3D_GL_EXT_NONE
, NULL
},
1216 {WINED3DFMT_B8G8R8X8_UNORM
, GL_RGB8
, GL_SRGB8_EXT
, 0,
1217 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1218 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1219 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
,
1220 WINED3D_GL_EXT_NONE
, NULL
},
1221 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB5
, GL_RGB5
, GL_RGB8
,
1222 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1223 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1224 | WINED3DFMT_FLAG_RENDERTARGET
,
1225 WINED3D_GL_EXT_NONE
, NULL
},
1226 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB565
, GL_RGB565
, GL_RGB8
,
1227 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1228 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1229 | WINED3DFMT_FLAG_RENDERTARGET
,
1230 ARB_ES2_COMPATIBILITY
, NULL
},
1231 {WINED3DFMT_B5G5R5X1_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1232 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1233 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1234 | WINED3DFMT_FLAG_RENDERTARGET
,
1235 WINED3D_GL_EXT_NONE
, NULL
},
1236 {WINED3DFMT_B5G5R5A1_UNORM
, GL_RGB5_A1
, GL_RGB5_A1
, 0,
1237 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1238 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1239 WINED3D_GL_EXT_NONE
, NULL
},
1240 {WINED3DFMT_B4G4R4A4_UNORM
, GL_RGBA4
, GL_SRGB8_ALPHA8_EXT
, 0,
1241 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1242 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1243 | WINED3DFMT_FLAG_SRGB_READ
,
1244 WINED3D_GL_EXT_NONE
, NULL
},
1245 {WINED3DFMT_B2G3R3_UNORM
, GL_R3_G3_B2
, GL_R3_G3_B2
, 0,
1246 GL_RGB
, GL_UNSIGNED_BYTE_3_3_2
, 0,
1247 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1248 WINED3D_GL_EXT_NONE
, NULL
},
1249 {WINED3DFMT_R8_UNORM
, GL_R8
, GL_R8
, 0,
1250 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1251 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1252 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1253 ARB_TEXTURE_RG
, NULL
},
1254 {WINED3DFMT_A8_UNORM
, GL_R8
, GL_R8
, 0,
1255 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1256 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1257 ARB_TEXTURE_RG
, NULL
},
1258 {WINED3DFMT_A8_UNORM
, GL_ALPHA8
, GL_ALPHA8
, 0,
1259 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1260 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1261 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1262 {WINED3DFMT_B4G4R4X4_UNORM
, GL_RGB4
, GL_RGB4
, 0,
1263 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1264 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1265 WINED3D_GL_EXT_NONE
, NULL
},
1266 {WINED3DFMT_R10G10B10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1267 GL_RGBA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1268 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1269 | WINED3DFMT_FLAG_RENDERTARGET
,
1270 WINED3D_GL_EXT_NONE
, NULL
},
1271 {WINED3DFMT_R8G8B8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1272 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1273 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1274 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1275 | WINED3DFMT_FLAG_VTF
,
1276 WINED3D_GL_EXT_NONE
, NULL
},
1277 {WINED3DFMT_R8G8B8A8_UINT
, GL_RGBA8UI
, GL_RGBA8UI
, 0,
1278 GL_RGBA_INTEGER
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1279 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1280 ARB_TEXTURE_RGB10_A2UI
, NULL
},
1281 {WINED3DFMT_R8G8B8A8_SINT
, GL_RGBA8I
, GL_RGBA8I
, 0,
1282 GL_RGBA_INTEGER
, GL_BYTE
, 0,
1283 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1284 EXT_TEXTURE_INTEGER
, NULL
},
1285 {WINED3DFMT_R8G8B8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1286 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1287 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1288 WINED3D_GL_EXT_NONE
, NULL
},
1289 {WINED3DFMT_R16G16_UNORM
, GL_RGB16
, GL_RGB16
, GL_RGBA16
,
1290 GL_RGB
, GL_UNSIGNED_SHORT
, 6,
1291 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1292 WINED3D_GL_EXT_NONE
, convert_r16g16
},
1293 {WINED3DFMT_R16G16_UNORM
, GL_RG16
, GL_RG16
, 0,
1294 GL_RG
, GL_UNSIGNED_SHORT
, 0,
1295 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1296 | WINED3DFMT_FLAG_RENDERTARGET
,
1297 ARB_TEXTURE_RG
, NULL
},
1298 {WINED3DFMT_B10G10R10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1299 GL_BGRA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1300 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1301 | WINED3DFMT_FLAG_RENDERTARGET
,
1302 WINED3D_GL_EXT_NONE
, NULL
},
1303 {WINED3DFMT_R16G16B16A16_UNORM
, GL_RGBA16
, GL_RGBA16
, 0,
1304 GL_RGBA
, GL_UNSIGNED_SHORT
, 0,
1305 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1306 | WINED3DFMT_FLAG_RENDERTARGET
,
1307 WINED3D_GL_EXT_NONE
, NULL
},
1308 {WINED3DFMT_R8G8_UNORM
, GL_RG8
, GL_RG8
, 0,
1309 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1310 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1311 | WINED3DFMT_FLAG_RENDERTARGET
,
1312 ARB_TEXTURE_RG
, NULL
},
1313 {WINED3DFMT_R8G8_UINT
, GL_RG8UI
, GL_RG8UI
, 0,
1314 GL_RG_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1315 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1316 ARB_TEXTURE_RG
, NULL
},
1317 {WINED3DFMT_R8G8_SINT
, GL_RG8I
, GL_RG8I
, 0,
1318 GL_RG_INTEGER
, GL_BYTE
, 0,
1319 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1320 ARB_TEXTURE_RG
, NULL
},
1321 {WINED3DFMT_R32G32_UINT
, GL_RG32UI
, GL_RG32UI
, 0,
1322 GL_RG_INTEGER
, GL_UNSIGNED_INT
, 0,
1323 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1324 ARB_TEXTURE_RG
, NULL
},
1325 {WINED3DFMT_R32G32_SINT
, GL_RG32I
, GL_RG32I
, 0,
1326 GL_RG_INTEGER
, GL_INT
, 0,
1327 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1328 ARB_TEXTURE_RG
, NULL
},
1329 {WINED3DFMT_R16G16_UINT
, GL_RG16UI
, GL_RG16UI
, 0,
1330 GL_RG_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1331 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1332 ARB_TEXTURE_RG
, NULL
},
1333 {WINED3DFMT_R16G16_SINT
, GL_RG16I
, GL_RG16I
, 0,
1334 GL_RG_INTEGER
, GL_SHORT
, 0,
1335 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1336 ARB_TEXTURE_RG
, NULL
},
1337 {WINED3DFMT_R32_UINT
, GL_R32UI
, GL_R32UI
, 0,
1338 GL_RED_INTEGER
, GL_UNSIGNED_INT
, 0,
1339 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1340 ARB_TEXTURE_RG
, NULL
},
1341 {WINED3DFMT_R32_SINT
, GL_R32I
, GL_R32I
, 0,
1342 GL_RED_INTEGER
, GL_INT
, 0,
1343 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1344 ARB_TEXTURE_RG
, NULL
},
1345 {WINED3DFMT_R16_UNORM
, GL_R16
, GL_R16
, 0,
1346 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1347 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1348 | WINED3DFMT_FLAG_RENDERTARGET
,
1349 ARB_TEXTURE_RG
, NULL
},
1350 {WINED3DFMT_R16_UINT
, GL_R16UI
, GL_R16UI
, 0,
1351 GL_RED_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1352 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1353 ARB_TEXTURE_RG
, NULL
},
1354 {WINED3DFMT_R16_SINT
, GL_R16I
, GL_R16I
, 0,
1355 GL_RED_INTEGER
, GL_SHORT
, 0,
1356 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1357 ARB_TEXTURE_RG
, NULL
},
1358 {WINED3DFMT_R8_UINT
, GL_R8UI
, GL_R8UI
, 0,
1359 GL_RED_INTEGER
, GL_UNSIGNED_BYTE
, 0,
1360 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1361 ARB_TEXTURE_RG
, NULL
},
1362 {WINED3DFMT_R8_SINT
, GL_R8I
, GL_R8I
, 0,
1363 GL_RED_INTEGER
, GL_BYTE
, 0,
1364 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1365 ARB_TEXTURE_RG
, NULL
},
1367 {WINED3DFMT_L8_UNORM
, GL_LUMINANCE8
, GL_SLUMINANCE8_EXT
, 0,
1368 GL_LUMINANCE
, GL_UNSIGNED_BYTE
, 0,
1369 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1370 | WINED3DFMT_FLAG_SRGB_READ
,
1371 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1372 {WINED3DFMT_L8_UNORM
, GL_R8
, GL_R8
, 0,
1373 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1374 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1375 | WINED3DFMT_FLAG_RENDERTARGET
,
1376 ARB_TEXTURE_RG
, NULL
},
1377 {WINED3DFMT_L8A8_UNORM
, GL_RG8
, GL_RG8
, 0,
1378 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1379 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1380 ARB_TEXTURE_RG
, NULL
},
1381 {WINED3DFMT_L8A8_UNORM
, GL_LUMINANCE8_ALPHA8
, GL_SLUMINANCE8_ALPHA8_EXT
, 0,
1382 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1383 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1384 | WINED3DFMT_FLAG_SRGB_READ
,
1385 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1386 {WINED3DFMT_L4A4_UNORM
, GL_RG8
, GL_RG8
, 0,
1387 GL_RG
, GL_UNSIGNED_BYTE
, 2,
1388 WINED3DFMT_FLAG_FILTERING
,
1389 ARB_TEXTURE_RG
, convert_l4a4_unorm
},
1390 {WINED3DFMT_L4A4_UNORM
, GL_LUMINANCE4_ALPHA4
, GL_LUMINANCE4_ALPHA4
, 0,
1391 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 2,
1392 WINED3DFMT_FLAG_FILTERING
,
1393 WINED3D_GL_LEGACY_CONTEXT
, convert_l4a4_unorm
},
1394 {WINED3DFMT_L16_UNORM
, GL_R16
, GL_R16
, 0,
1395 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1396 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1397 ARB_TEXTURE_RG
, NULL
},
1398 {WINED3DFMT_L16_UNORM
, GL_LUMINANCE16
, GL_LUMINANCE16
, 0,
1399 GL_LUMINANCE
, GL_UNSIGNED_SHORT
, 0,
1400 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1401 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1402 /* Bump mapping stuff */
1403 {WINED3DFMT_R8G8_SNORM
, GL_RGB8
, GL_RGB8
, 0,
1404 GL_BGR
, GL_UNSIGNED_BYTE
, 3,
1405 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1406 | WINED3DFMT_FLAG_BUMPMAP
,
1407 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm
},
1408 {WINED3DFMT_R8G8_SNORM
, GL_DSDT8_NV
, GL_DSDT8_NV
, 0,
1409 GL_DSDT_NV
, GL_BYTE
, 0,
1410 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1411 | WINED3DFMT_FLAG_BUMPMAP
,
1412 NV_TEXTURE_SHADER
, NULL
},
1413 {WINED3DFMT_R8G8_SNORM
, GL_RG8_SNORM
, GL_RG8_SNORM
, 0,
1415 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1416 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1417 EXT_TEXTURE_SNORM
, NULL
},
1418 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1419 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 2,
1420 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1421 | WINED3DFMT_FLAG_BUMPMAP
,
1422 WINED3D_GL_EXT_NONE
, convert_r5g5_snorm_l6_unorm
},
1423 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_DSDT8_MAG8_NV
, GL_DSDT8_MAG8_NV
, 0,
1424 GL_DSDT_MAG_NV
, GL_BYTE
, 3,
1425 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1426 | WINED3DFMT_FLAG_BUMPMAP
,
1427 NV_TEXTURE_SHADER
, convert_r5g5_snorm_l6_unorm_nv
},
1428 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB8_SNORM
, GL_RGB8_SNORM
, 0,
1429 GL_RGBA
, GL_BYTE
, 4,
1430 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1431 | WINED3DFMT_FLAG_BUMPMAP
,
1432 EXT_TEXTURE_SNORM
, convert_r5g5_snorm_l6_unorm_ext
},
1433 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1434 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4,
1435 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1436 | WINED3DFMT_FLAG_BUMPMAP
,
1437 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm_l8x8_unorm
},
1438 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_DSDT8_MAG8_INTENSITY8_NV
, GL_DSDT8_MAG8_INTENSITY8_NV
, 0,
1439 GL_DSDT_MAG_VIB_NV
, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV
, 4,
1440 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1441 | WINED3DFMT_FLAG_BUMPMAP
,
1442 NV_TEXTURE_SHADER
, convert_r8g8_snorm_l8x8_unorm_nv
},
1443 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8
, GL_RGBA8
, 0,
1444 GL_BGRA
, GL_UNSIGNED_BYTE
, 4,
1445 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1446 | WINED3DFMT_FLAG_BUMPMAP
,
1447 WINED3D_GL_EXT_NONE
, convert_r8g8b8a8_snorm
},
1448 {WINED3DFMT_R8G8B8A8_SNORM
, GL_SIGNED_RGBA8_NV
, GL_SIGNED_RGBA8_NV
, 0,
1449 GL_RGBA
, GL_BYTE
, 0,
1450 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1451 | WINED3DFMT_FLAG_BUMPMAP
,
1452 NV_TEXTURE_SHADER
, NULL
},
1453 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8_SNORM
, GL_RGBA8_SNORM
, 0,
1454 GL_RGBA
, GL_BYTE
, 0,
1455 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1456 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1457 EXT_TEXTURE_SNORM
, NULL
},
1458 {WINED3DFMT_R16G16_SNORM
, GL_RGB16
, GL_RGB16
, 0,
1459 GL_BGR
, GL_UNSIGNED_SHORT
, 6,
1460 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1461 | WINED3DFMT_FLAG_BUMPMAP
,
1462 WINED3D_GL_EXT_NONE
, convert_r16g16_snorm
},
1463 {WINED3DFMT_R16G16_SNORM
, GL_SIGNED_HILO16_NV
, GL_SIGNED_HILO16_NV
, 0,
1464 GL_HILO_NV
, GL_SHORT
, 0,
1465 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1466 | WINED3DFMT_FLAG_BUMPMAP
,
1467 NV_TEXTURE_SHADER
, NULL
},
1468 {WINED3DFMT_R16G16_SNORM
, GL_RG16_SNORM
, GL_RG16_SNORM
, 0,
1470 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1471 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_BUMPMAP
,
1472 EXT_TEXTURE_SNORM
, NULL
},
1473 /* Depth stencil formats */
1474 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1475 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1476 WINED3DFMT_FLAG_DEPTH
,
1477 WINED3D_GL_EXT_NONE
, NULL
},
1478 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1479 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1480 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1481 ARB_DEPTH_TEXTURE
, NULL
},
1482 {WINED3DFMT_D32_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1483 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1484 WINED3DFMT_FLAG_DEPTH
,
1485 WINED3D_GL_EXT_NONE
, NULL
},
1486 {WINED3DFMT_D32_UNORM
, GL_DEPTH_COMPONENT32_ARB
, GL_DEPTH_COMPONENT32_ARB
, 0,
1487 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1488 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1489 ARB_DEPTH_TEXTURE
, NULL
},
1490 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1491 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1492 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1493 ARB_DEPTH_TEXTURE
, NULL
},
1494 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1495 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 4,
1496 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1497 EXT_PACKED_DEPTH_STENCIL
, convert_s1_uint_d15_unorm
},
1498 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1499 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 4,
1500 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1501 ARB_FRAMEBUFFER_OBJECT
, convert_s1_uint_d15_unorm
},
1502 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1503 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1504 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1505 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1506 ARB_DEPTH_TEXTURE
, NULL
},
1507 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1508 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 0,
1509 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1510 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1511 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1512 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1513 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1514 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1515 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1516 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1517 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1518 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1519 WINED3DFMT_FLAG_DEPTH
,
1520 WINED3D_GL_EXT_NONE
, NULL
},
1521 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1522 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1523 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1524 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1525 ARB_DEPTH_TEXTURE
, NULL
},
1526 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1527 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1528 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1529 ARB_DEPTH_TEXTURE
, NULL
},
1530 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1531 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 4,
1532 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1533 EXT_PACKED_DEPTH_STENCIL
, convert_s4x4_uint_d24_unorm
},
1534 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1535 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 4,
1536 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1537 ARB_FRAMEBUFFER_OBJECT
, convert_s4x4_uint_d24_unorm
},
1538 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1539 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1540 WINED3DFMT_FLAG_DEPTH
,
1541 WINED3D_GL_EXT_NONE
, NULL
},
1542 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1543 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1544 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1545 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1546 ARB_DEPTH_TEXTURE
, NULL
},
1547 {WINED3DFMT_D32_FLOAT
, GL_DEPTH_COMPONENT32F
, GL_DEPTH_COMPONENT32F
, 0,
1548 GL_DEPTH_COMPONENT
, GL_FLOAT
, 0,
1549 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1550 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1551 {WINED3DFMT_S8_UINT_D24_FLOAT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1552 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 8,
1553 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1554 ARB_DEPTH_BUFFER_FLOAT
, convert_s8_uint_d24_float
},
1555 {WINED3DFMT_R32G32B32A32_UINT
, GL_RGBA32UI
, GL_RGBA32UI
, 0,
1556 GL_RGBA_INTEGER
, GL_UNSIGNED_INT
, 0,
1557 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1558 EXT_TEXTURE_INTEGER
, NULL
},
1559 {WINED3DFMT_R32G32B32A32_SINT
, GL_RGBA32I
, GL_RGBA32I
, 0,
1560 GL_RGBA_INTEGER
, GL_INT
, 0,
1561 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1562 EXT_TEXTURE_INTEGER
, NULL
},
1563 /* Vendor-specific formats */
1564 {WINED3DFMT_ATI1N
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1565 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1566 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1567 | WINED3DFMT_FLAG_COMPRESSED
,
1568 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1569 {WINED3DFMT_ATI2N
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, 0,
1570 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1571 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1572 | WINED3DFMT_FLAG_COMPRESSED
,
1573 ATI_TEXTURE_COMPRESSION_3DC
, NULL
},
1574 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1575 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1576 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1577 | WINED3DFMT_FLAG_COMPRESSED
,
1578 EXT_TEXTURE_COMPRESSION_RGTC
, NULL
},
1579 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1580 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1581 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1582 | WINED3DFMT_FLAG_COMPRESSED
,
1583 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1584 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1585 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 0,
1586 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1587 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
,
1588 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1589 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1590 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1591 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1592 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
,
1593 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1594 {WINED3DFMT_NULL
, 0, 0, 0,
1595 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1596 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
,
1597 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1600 struct wined3d_format_srgb_info
1602 enum wined3d_format_id srgb_format_id
;
1603 enum wined3d_format_id base_format_id
;
1606 static const struct wined3d_format_srgb_info format_srgb_info
[] =
1608 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_UNORM
},
1609 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_UNORM
},
1610 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_UNORM
},
1611 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_UNORM
},
1612 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_UNORM
},
1613 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_UNORM
},
1614 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_UNORM
},
1617 static inline int get_format_idx(enum wined3d_format_id format_id
)
1621 if (format_id
< WINED3D_FORMAT_FOURCC_BASE
)
1624 for (i
= 0; i
< ARRAY_SIZE(format_index_remap
); ++i
)
1626 if (format_index_remap
[i
].id
== format_id
)
1627 return format_index_remap
[i
].idx
;
1633 static void format_set_flag(struct wined3d_format
*format
, unsigned int flag
)
1637 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1638 format
->flags
[i
] |= flag
;
1641 static void format_clear_flag(struct wined3d_format
*format
, unsigned int flag
)
1645 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1646 format
->flags
[i
] &= ~flag
;
1649 static enum wined3d_channel_type
map_channel_type(char t
)
1654 return WINED3D_CHANNEL_TYPE_UNORM
;
1656 return WINED3D_CHANNEL_TYPE_SNORM
;
1658 return WINED3D_CHANNEL_TYPE_UINT
;
1660 return WINED3D_CHANNEL_TYPE_SINT
;
1662 return WINED3D_CHANNEL_TYPE_FLOAT
;
1664 return WINED3D_CHANNEL_TYPE_DEPTH
;
1666 return WINED3D_CHANNEL_TYPE_STENCIL
;
1668 return WINED3D_CHANNEL_TYPE_UNUSED
;
1670 ERR("Invalid channel type '%c'.\n", t
);
1671 return WINED3D_CHANNEL_TYPE_NONE
;
1675 static BOOL
init_format_base_info(struct wined3d_gl_info
*gl_info
)
1679 gl_info
->format_count
= WINED3D_FORMAT_COUNT
;
1680 if (!(gl_info
->formats
= wined3d_calloc(gl_info
->format_count
, sizeof(*gl_info
->formats
))))
1682 ERR("Failed to allocate memory.\n");
1686 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
1688 struct wined3d_format
*format
;
1691 fmt_idx
= get_format_idx(formats
[i
].id
);
1694 ERR("Could not allocate index for format %s %#x.\n",
1695 debug_d3dformat(formats
[i
].id
), formats
[i
].id
);
1698 format
= &gl_info
->formats
[fmt_idx
];
1700 format
->id
= formats
[i
].id
;
1701 format
->red_size
= formats
[i
].red_size
;
1702 format
->green_size
= formats
[i
].green_size
;
1703 format
->blue_size
= formats
[i
].blue_size
;
1704 format
->alpha_size
= formats
[i
].alpha_size
;
1705 format
->red_offset
= formats
[i
].red_offset
;
1706 format
->green_offset
= formats
[i
].green_offset
;
1707 format
->blue_offset
= formats
[i
].blue_offset
;
1708 format
->alpha_offset
= formats
[i
].alpha_offset
;
1709 format
->byte_count
= formats
[i
].bpp
;
1710 format
->depth_size
= formats
[i
].depth_size
;
1711 format
->stencil_size
= formats
[i
].stencil_size
;
1712 format
->block_width
= 1;
1713 format
->block_height
= 1;
1714 format
->block_byte_count
= formats
[i
].bpp
;
1717 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
1719 const struct wined3d_format
*typeless_format
;
1720 struct wined3d_format
*format
;
1724 fmt_idx
= get_format_idx(typed_formats
[i
].id
);
1727 ERR("Could not allocate index for format %s %#x.\n",
1728 debug_d3dformat(typed_formats
[i
].id
), typed_formats
[i
].id
);
1731 format
= &gl_info
->formats
[fmt_idx
];
1733 typeless_format
= wined3d_get_format(gl_info
, typed_formats
[i
].typeless_id
);
1734 if (typeless_format
->id
== WINED3DFMT_UNKNOWN
)
1736 ERR("Typeless format %s (%#x) not found.\n",
1737 debug_d3dformat(typed_formats
[i
].typeless_id
), typed_formats
[i
].typeless_id
);
1741 format
->id
= typed_formats
[i
].id
;
1742 format
->red_size
= typeless_format
->red_size
;
1743 format
->green_size
= typeless_format
->green_size
;
1744 format
->blue_size
= typeless_format
->blue_size
;
1745 format
->alpha_size
= typeless_format
->alpha_size
;
1746 format
->red_offset
= typeless_format
->red_offset
;
1747 format
->green_offset
= typeless_format
->green_offset
;
1748 format
->blue_offset
= typeless_format
->blue_offset
;
1749 format
->alpha_offset
= typeless_format
->alpha_offset
;
1750 format
->byte_count
= typeless_format
->byte_count
;
1751 format
->depth_size
= typeless_format
->depth_size
;
1752 format
->stencil_size
= typeless_format
->stencil_size
;
1753 format
->block_width
= typeless_format
->block_width
;
1754 format
->block_height
= typeless_format
->block_height
;
1755 format
->block_byte_count
= typeless_format
->block_byte_count
;
1756 format
->typeless_id
= typeless_format
->id
;
1758 for (j
= 0; j
< strlen(typed_formats
[i
].channels
); ++j
)
1760 enum wined3d_channel_type channel_type
= map_channel_type(typed_formats
[i
].channels
[j
]);
1761 if (channel_type
== WINED3D_CHANNEL_TYPE_UINT
|| channel_type
== WINED3D_CHANNEL_TYPE_SINT
)
1762 flags
|= WINED3DFMT_FLAG_INTEGER
;
1763 if (channel_type
== WINED3D_CHANNEL_TYPE_FLOAT
)
1764 flags
|= WINED3DFMT_FLAG_FLOAT
;
1766 if (channel_type
== WINED3D_CHANNEL_TYPE_DEPTH
&& !format
->depth_size
)
1768 format
->depth_size
= format
->red_size
;
1769 format
->red_size
= format
->red_offset
= 0;
1773 format_set_flag(format
, flags
);
1776 for (i
= 0; i
< ARRAY_SIZE(ddi_formats
); ++i
)
1778 int fmt_idx
= get_format_idx(ddi_formats
[i
].id
);
1782 ERR("Format %s (%#x) not found.\n", debug_d3dformat(ddi_formats
[i
].id
), ddi_formats
[i
].id
);
1786 gl_info
->formats
[fmt_idx
].ddi_format
= ddi_formats
[i
].ddi_format
;
1789 for (i
= 0; i
< ARRAY_SIZE(format_base_flags
); ++i
)
1791 int fmt_idx
= get_format_idx(format_base_flags
[i
].id
);
1795 ERR("Format %s (%#x) not found.\n",
1796 debug_d3dformat(format_base_flags
[i
].id
), format_base_flags
[i
].id
);
1800 format_set_flag(&gl_info
->formats
[fmt_idx
], format_base_flags
[i
].flags
);
1806 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
1810 static BOOL
init_format_block_info(struct wined3d_gl_info
*gl_info
)
1814 for (i
= 0; i
< (sizeof(format_block_info
) / sizeof(*format_block_info
)); ++i
)
1816 struct wined3d_format
*format
;
1817 int fmt_idx
= get_format_idx(format_block_info
[i
].id
);
1821 ERR("Format %s (%#x) not found.\n",
1822 debug_d3dformat(format_block_info
[i
].id
), format_block_info
[i
].id
);
1826 format
= &gl_info
->formats
[fmt_idx
];
1827 format
->block_width
= format_block_info
[i
].block_width
;
1828 format
->block_height
= format_block_info
[i
].block_height
;
1829 format
->block_byte_count
= format_block_info
[i
].block_byte_count
;
1830 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_BLOCKS
);
1831 if (!format_block_info
[i
].verify
)
1832 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
);
1838 static GLenum
wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type
)
1842 case WINED3D_GL_RES_TYPE_TEX_1D
:
1843 return GL_TEXTURE_1D
;
1844 case WINED3D_GL_RES_TYPE_TEX_2D
:
1845 return GL_TEXTURE_2D
;
1846 case WINED3D_GL_RES_TYPE_TEX_3D
:
1847 return GL_TEXTURE_3D
;
1848 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1849 return GL_TEXTURE_CUBE_MAP_ARB
;
1850 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1851 return GL_TEXTURE_RECTANGLE_ARB
;
1852 case WINED3D_GL_RES_TYPE_BUFFER
:
1853 return GL_TEXTURE_2D
; /* TODO: GL_TEXTURE_BUFFER. */
1854 case WINED3D_GL_RES_TYPE_RB
:
1855 return GL_RENDERBUFFER
;
1856 case WINED3D_GL_RES_TYPE_COUNT
:
1859 ERR("Unexpected GL resource type %u.\n", type
);
1863 static void delete_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
1864 enum wined3d_gl_resource_type d3d_type
, GLuint object
)
1868 case WINED3D_GL_RES_TYPE_TEX_1D
:
1869 case WINED3D_GL_RES_TYPE_TEX_2D
:
1870 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1871 case WINED3D_GL_RES_TYPE_TEX_3D
:
1872 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1873 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &object
);
1876 case WINED3D_GL_RES_TYPE_RB
:
1877 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &object
);
1880 case WINED3D_GL_RES_TYPE_BUFFER
:
1881 case WINED3D_GL_RES_TYPE_COUNT
:
1886 /* Context activation is done by the caller. */
1887 static void create_and_bind_fbo_attachment(const struct wined3d_gl_info
*gl_info
, unsigned int flags
,
1888 enum wined3d_gl_resource_type d3d_type
, GLuint
*object
, GLenum internal
, GLenum format
, GLenum type
)
1890 GLenum attach_type
= flags
& WINED3DFMT_FLAG_DEPTH
?
1891 GL_DEPTH_ATTACHMENT
: GL_COLOR_ATTACHMENT0
;
1895 case WINED3D_GL_RES_TYPE_TEX_1D
:
1896 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1897 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, *object
);
1898 gl_info
->gl_ops
.gl
.p_glTexImage1D(GL_TEXTURE_1D
, 0, internal
, 16, 0, format
, type
, NULL
);
1899 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1900 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1902 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_1D
,
1904 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1905 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_TEXTURE_1D
,
1909 case WINED3D_GL_RES_TYPE_TEX_2D
:
1910 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1911 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1912 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(d3d_type
), *object
);
1913 gl_info
->gl_ops
.gl
.p_glTexImage2D(wined3d_gl_type_to_enum(d3d_type
), 0, internal
, 16, 16, 0,
1914 format
, type
, NULL
);
1915 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1916 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1918 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
1919 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
1920 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1921 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1922 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
1925 case WINED3D_GL_RES_TYPE_TEX_3D
:
1926 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1927 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_3D
, *object
);
1928 GL_EXTCALL(glTexImage3D(GL_TEXTURE_3D
, 0, internal
, 16, 16, 16, 0, format
, type
, NULL
));
1929 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1930 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1932 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, attach_type
,
1933 GL_TEXTURE_3D
, *object
, 0, 0);
1934 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1935 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1936 GL_TEXTURE_3D
, *object
, 0, 0);
1939 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1940 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1941 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, *object
);
1942 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, internal
, 16, 16, 0,
1943 format
, type
, NULL
);
1944 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
, 0, internal
, 16, 16, 0,
1945 format
, type
, NULL
);
1946 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
, 0, internal
, 16, 16, 0,
1947 format
, type
, NULL
);
1948 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
, 0, internal
, 16, 16, 0,
1949 format
, type
, NULL
);
1950 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
, 0, internal
, 16, 16, 0,
1951 format
, type
, NULL
);
1952 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
, 0, internal
, 16, 16, 0,
1953 format
, type
, NULL
);
1954 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1955 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1957 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
1958 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
1959 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1960 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1961 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
1964 case WINED3D_GL_RES_TYPE_RB
:
1965 gl_info
->fbo_ops
.glGenRenderbuffers(1, object
);
1966 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, *object
);
1967 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, internal
, 16, 16);
1968 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, attach_type
, GL_RENDERBUFFER
,
1970 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1971 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
,
1975 case WINED3D_GL_RES_TYPE_BUFFER
:
1976 case WINED3D_GL_RES_TYPE_COUNT
:
1980 /* Ideally we'd skip all formats already known not to work on textures
1981 * by checking for WINED3DFMT_FLAG_TEXTURE here. However, we want to
1982 * know if we can attach WINED3DFMT_P8_UINT textures to FBOs, and this
1983 * format never has WINED3DFMT_FLAG_TEXTURE set. Instead, swallow GL
1984 * errors generated by invalid formats. */
1985 while (gl_info
->gl_ops
.gl
.p_glGetError());
1988 static void draw_test_quad(struct wined3d_caps_gl_ctx
*ctx
, const struct wined3d_vec3
*geometry
,
1989 const struct wined3d_color
*color
)
1991 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
1992 static const struct wined3d_vec3 default_geometry
[] =
1994 {-1.0f
, -1.0f
, 0.0f
},
1995 { 1.0f
, -1.0f
, 0.0f
},
1996 {-1.0f
, 1.0f
, 0.0f
},
1997 { 1.0f
, 1.0f
, 0.0f
},
1999 static const char vs_core_header
[] =
2003 "out vec4 out_color;\n"
2005 static const char vs_legacy_header
[] =
2007 "attribute vec4 pos;\n"
2008 "attribute vec4 color;\n"
2009 "varying vec4 out_color;\n"
2011 static const char vs_body
[] =
2014 " gl_Position = pos;\n"
2015 " out_color = color;\n"
2017 static const char fs_core
[] =
2019 "in vec4 out_color;\n"
2020 "out vec4 fragment_color;\n"
2024 " fragment_color = out_color;\n"
2026 static const char fs_legacy
[] =
2028 "varying vec4 out_color;\n"
2032 " gl_FragData[0] = out_color;\n"
2034 const char *source
[2];
2035 GLuint vs_id
, fs_id
;
2039 geometry
= default_geometry
;
2041 if (!gl_info
->supported
[ARB_VERTEX_BUFFER_OBJECT
] || !gl_info
->supported
[ARB_VERTEX_SHADER
]
2042 || !gl_info
->supported
[ARB_FRAGMENT_SHADER
])
2044 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
2045 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
2046 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2047 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
2048 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2050 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
2051 gl_info
->gl_ops
.gl
.p_glColor4f(color
->r
, color
->g
, color
->b
, color
->a
);
2052 for (i
= 0; i
< 4; ++i
)
2053 gl_info
->gl_ops
.gl
.p_glVertex3fv(&geometry
[i
].x
);
2054 gl_info
->gl_ops
.gl
.p_glEnd();
2055 checkGLcall("Drawing a quad");
2060 GL_EXTCALL(glGenBuffers(1, &ctx
->test_vbo
));
2061 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, ctx
->test_vbo
));
2062 GL_EXTCALL(glBufferData(GL_ARRAY_BUFFER
, sizeof(struct wined3d_vec3
) * 4, geometry
, GL_STREAM_DRAW
));
2063 GL_EXTCALL(glVertexAttribPointer(0, 3, GL_FLOAT
, FALSE
, 0, NULL
));
2064 GL_EXTCALL(glVertexAttrib4f(1, color
->r
, color
->g
, color
->b
, color
->a
));
2065 GL_EXTCALL(glEnableVertexAttribArray(0));
2066 GL_EXTCALL(glDisableVertexAttribArray(1));
2068 if (!ctx
->test_program_id
)
2070 ctx
->test_program_id
= GL_EXTCALL(glCreateProgram());
2072 vs_id
= GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER
));
2073 source
[0] = gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? vs_legacy_header
: vs_core_header
;
2074 source
[1] = vs_body
;
2075 GL_EXTCALL(glShaderSource(vs_id
, 2, source
, NULL
));
2076 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, vs_id
));
2077 GL_EXTCALL(glDeleteShader(vs_id
));
2079 fs_id
= GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER
));
2080 source
[0] = gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? fs_legacy
: fs_core
;
2081 GL_EXTCALL(glShaderSource(fs_id
, 1, source
, NULL
));
2082 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, fs_id
));
2083 GL_EXTCALL(glDeleteShader(fs_id
));
2085 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 0, "pos"));
2086 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 1, "color"));
2088 GL_EXTCALL(glCompileShader(vs_id
));
2089 print_glsl_info_log(gl_info
, vs_id
, FALSE
);
2090 GL_EXTCALL(glCompileShader(fs_id
));
2091 print_glsl_info_log(gl_info
, fs_id
, FALSE
);
2092 GL_EXTCALL(glLinkProgram(ctx
->test_program_id
));
2093 shader_glsl_validate_link(gl_info
, ctx
->test_program_id
);
2095 GL_EXTCALL(glUseProgram(ctx
->test_program_id
));
2097 gl_info
->gl_ops
.gl
.p_glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
2099 GL_EXTCALL(glUseProgram(0));
2100 GL_EXTCALL(glDisableVertexAttribArray(0));
2101 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, 0));
2102 checkGLcall("Drawing a quad");
2105 /* Context activation is done by the caller. */
2106 static void check_fbo_compat(struct wined3d_caps_gl_ctx
*ctx
, struct wined3d_format
*format
)
2108 /* Check if the default internal format is supported as a frame buffer
2109 * target, otherwise fall back to the render target internal.
2111 * Try to stick to the standard format if possible, this limits precision differences. */
2112 static const struct wined3d_color black
= {0.0f
, 0.0f
, 0.0f
, 1.0f
};
2113 static const struct wined3d_color half_transparent_red
= {1.0f
, 0.0f
, 0.0f
, 0.5f
};
2114 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2115 GLenum status
, rt_internal
= format
->rtInternal
;
2116 GLuint object
, color_rb
;
2117 enum wined3d_gl_resource_type type
;
2118 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2120 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2122 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
2124 const char *type_string
= "color";
2126 if (type
== WINED3D_GL_RES_TYPE_BUFFER
)
2129 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->glInternal
,
2130 format
->glFormat
, format
->glType
);
2132 if (format
->flags
[type
] & (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2134 gl_info
->fbo_ops
.glGenRenderbuffers(1, &color_rb
);
2135 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, color_rb
);
2136 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2137 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 1);
2139 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 16);
2141 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2142 GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, color_rb
);
2143 checkGLcall("Create and attach color rb attachment");
2144 type_string
= "depth / stencil";
2147 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2148 checkGLcall("Framebuffer format check");
2150 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2152 TRACE("Format %s is supported as FBO %s attachment, type %u.\n",
2153 debug_d3dformat(format
->id
), type_string
, type
);
2154 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2155 format
->rtInternal
= format
->glInternal
;
2156 regular_fmt_used
= TRUE
;
2162 if (format
->flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
2164 WARN("Format %s with rendertarget flag is not supported as FBO color attachment (type %u),"
2165 " and no fallback specified.\n", debug_d3dformat(format
->id
), type
);
2166 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2170 TRACE("Format %s is not supported as FBO %s attachment, type %u.\n",
2171 debug_d3dformat(format
->id
), type_string
, type
);
2173 format
->rtInternal
= format
->glInternal
;
2177 TRACE("Format %s is not supported as FBO %s attachment (type %u),"
2178 " trying rtInternal format as fallback.\n",
2179 debug_d3dformat(format
->id
), type_string
, type
);
2181 while (gl_info
->gl_ops
.gl
.p_glGetError());
2183 delete_fbo_attachment(gl_info
, type
, object
);
2184 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->rtInternal
,
2185 format
->glFormat
, format
->glType
);
2187 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2188 checkGLcall("Framebuffer format check");
2190 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2192 TRACE("Format %s rtInternal format is supported as FBO %s attachment, type %u.\n",
2193 debug_d3dformat(format
->id
), type_string
, type
);
2194 fallback_fmt_used
= TRUE
;
2198 WARN("Format %s rtInternal format is not supported as FBO %s attachment, type %u.\n",
2199 debug_d3dformat(format
->id
), type_string
, type
);
2200 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2205 if (status
== GL_FRAMEBUFFER_COMPLETE
2206 && ((format
->flags
[type
] & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
)
2207 || !(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2208 && !(format
->flags
[type
] & WINED3DFMT_FLAG_INTEGER
)
2209 && format
->id
!= WINED3DFMT_NULL
&& format
->id
!= WINED3DFMT_P8_UINT
2210 && format
->glFormat
!= GL_LUMINANCE
&& format
->glFormat
!= GL_LUMINANCE_ALPHA
2211 && (format
->red_size
|| format
->alpha_size
))
2213 DWORD readback
[16 * 16 * 16], color
, r_range
, a_range
;
2218 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
]
2219 || gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2221 gl_info
->fbo_ops
.glGenRenderbuffers(1, &rb
);
2222 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
2223 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2224 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 1);
2226 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 16);
2227 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2228 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2229 checkGLcall("RB attachment");
2232 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2233 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.0f
, 1.0f
);
2234 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
2235 if (gl_info
->gl_ops
.gl
.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION
)
2237 while (gl_info
->gl_ops
.gl
.p_glGetError());
2238 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2239 debug_d3dformat(format
->id
), type
);
2240 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2244 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2245 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2246 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2248 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 16);
2249 gl_info
->gl_ops
.gl
.p_glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2251 draw_test_quad(ctx
, NULL
, &black
);
2253 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2255 draw_test_quad(ctx
, NULL
, &half_transparent_red
);
2257 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2261 case WINED3D_GL_RES_TYPE_TEX_1D
:
2262 /* Rebinding texture to workaround a fglrx bug. */
2263 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, object
);
2264 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_1D
, 0, GL_BGRA
,
2265 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2266 color
= readback
[7];
2269 case WINED3D_GL_RES_TYPE_TEX_2D
:
2270 case WINED3D_GL_RES_TYPE_TEX_3D
:
2271 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2272 /* Rebinding texture to workaround a fglrx bug. */
2273 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(type
), object
);
2274 gl_info
->gl_ops
.gl
.p_glGetTexImage(wined3d_gl_type_to_enum(type
), 0, GL_BGRA
,
2275 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2276 color
= readback
[7 * 16 + 7];
2279 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2280 /* Rebinding texture to workaround a fglrx bug. */
2281 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, object
);
2282 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, GL_BGRA
,
2283 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2284 color
= readback
[7 * 16 + 7];
2287 case WINED3D_GL_RES_TYPE_RB
:
2288 gl_info
->gl_ops
.gl
.p_glReadPixels(0, 0, 16, 16,
2289 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2290 color
= readback
[7 * 16 + 7];
2293 case WINED3D_GL_RES_TYPE_BUFFER
:
2294 case WINED3D_GL_RES_TYPE_COUNT
:
2298 checkGLcall("Post-pixelshader blending check");
2301 r
= (color
& 0x00ff0000u
) >> 16;
2303 r_range
= format
->red_size
< 8 ? 1u << (8 - format
->red_size
) : 1;
2304 a_range
= format
->alpha_size
< 8 ? 1u << (8 - format
->alpha_size
) : 1;
2305 if (format
->red_size
&& (r
< 0x7f - r_range
|| r
> 0x7f + r_range
))
2307 else if (format
->alpha_size
> 1 && (a
< 0xbf - a_range
|| a
> 0xbf + a_range
))
2311 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2312 debug_d3dformat(format
->id
), type
);
2313 TRACE("Color output: %#x\n", color
);
2314 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2318 TRACE("Format %s supports post-pixelshader blending, type %u.\n",
2319 debug_d3dformat(format
->id
), type
);
2320 TRACE("Color output: %#x\n", color
);
2321 format
->flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2325 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
]
2326 || gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2328 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2329 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2330 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &rb
);
2331 checkGLcall("RB cleanup");
2335 if (format
->glInternal
!= format
->glGammaInternal
)
2337 delete_fbo_attachment(gl_info
, type
, object
);
2338 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->glGammaInternal
,
2339 format
->glFormat
, format
->glType
);
2341 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2342 checkGLcall("Framebuffer format check");
2344 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2346 TRACE("Format %s's sRGB format is FBO attachable, type %u.\n",
2347 debug_d3dformat(format
->id
), type
);
2348 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2352 WARN("Format %s's sRGB format is not FBO attachable, type %u.\n",
2353 debug_d3dformat(format
->id
), type
);
2356 else if (status
== GL_FRAMEBUFFER_COMPLETE
)
2357 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2359 if (format
->flags
[type
] & (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2361 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, 0);
2362 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &color_rb
);
2365 delete_fbo_attachment(gl_info
, type
, object
);
2366 checkGLcall("Framebuffer format check cleanup");
2369 if (fallback_fmt_used
&& regular_fmt_used
)
2371 FIXME("Format %s needs different render target formats for different resource types.\n",
2372 debug_d3dformat(format
->id
));
2373 format_clear_flag(format
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
2374 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2378 static void query_format_flag(struct wined3d_gl_info
*gl_info
, struct wined3d_format
*format
,
2379 GLint internal
, GLenum pname
, DWORD flag
, const char *string
)
2382 enum wined3d_gl_resource_type type
;
2384 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
2386 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
), internal
, pname
, 1, &value
);
2387 if (value
== GL_FULL_SUPPORT
)
2389 TRACE("Format %s supports %s, resource type %u.\n", debug_d3dformat(format
->id
), string
, type
);
2390 format
->flags
[type
] |= flag
;
2394 TRACE("Format %s doesn't support %s, resource type %u.\n", debug_d3dformat(format
->id
), string
, type
);
2395 format
->flags
[type
] &= ~flag
;
2400 /* Context activation is done by the caller. */
2401 static void init_format_fbo_compat_info(struct wined3d_caps_gl_ctx
*ctx
)
2403 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2404 unsigned int i
, type
;
2407 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2409 for (i
= 0; i
< gl_info
->format_count
; ++i
)
2412 struct wined3d_format
*format
= &gl_info
->formats
[i
];
2413 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2414 GLenum rt_internal
= format
->rtInternal
;
2416 if (!format
->glInternal
)
2419 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
2421 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2422 format
->glInternal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2423 if (value
== GL_FULL_SUPPORT
)
2425 TRACE("Format %s is supported as FBO color attachment, resource type %u.\n",
2426 debug_d3dformat(format
->id
), type
);
2427 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2428 format
->rtInternal
= format
->glInternal
;
2429 regular_fmt_used
= TRUE
;
2431 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2432 format
->glInternal
, GL_FRAMEBUFFER_BLEND
, 1, &value
);
2433 if (value
== GL_FULL_SUPPORT
)
2435 TRACE("Format %s supports post-pixelshader blending, resource type %u.\n",
2436 debug_d3dformat(format
->id
), type
);
2437 format
->flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2441 TRACE("Format %s doesn't support post-pixelshader blending, resource typed %u.\n",
2442 debug_d3dformat(format
->id
), type
);
2443 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2450 if (format
->flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
2452 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
2453 " and no fallback specified, resource type %u.\n",
2454 debug_d3dformat(format
->id
), type
);
2455 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2458 TRACE("Format %s is not supported as FBO color attachment,"
2459 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2460 format
->rtInternal
= format
->glInternal
;
2464 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2465 rt_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2466 if (value
== GL_FULL_SUPPORT
)
2468 TRACE("Format %s rtInternal format is supported as FBO color attachment,"
2469 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2470 fallback_fmt_used
= TRUE
;
2474 WARN("Format %s rtInternal format is not supported as FBO color attachment,"
2475 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2476 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2481 if (format
->glInternal
!= format
->glGammaInternal
)
2483 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2484 format
->glGammaInternal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2485 if (value
== GL_FULL_SUPPORT
)
2487 TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n",
2488 debug_d3dformat(format
->id
), type
);
2489 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2493 WARN("Format %s's sRGB format is not FBO attachable, resource type %u.\n",
2494 debug_d3dformat(format
->id
), type
);
2497 else if (format
->flags
[type
] & WINED3DFMT_FLAG_FBO_ATTACHABLE
)
2498 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2501 if (fallback_fmt_used
&& regular_fmt_used
)
2503 FIXME("Format %s needs different render target formats for different resource types.\n",
2504 debug_d3dformat(format
->id
));
2505 format_clear_flag(format
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
2506 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2512 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2514 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2515 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2516 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2517 gl_info
->gl_ops
.gl
.p_glReadBuffer(GL_COLOR_ATTACHMENT0
);
2520 for (i
= 0; i
< gl_info
->format_count
; ++i
)
2522 struct wined3d_format
*format
= &gl_info
->formats
[i
];
2524 if (!format
->glInternal
) continue;
2526 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_COMPRESSED
)
2528 TRACE("Skipping format %s because it's a compressed format.\n",
2529 debug_d3dformat(format
->id
));
2533 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2535 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format
->id
));
2536 check_fbo_compat(ctx
, format
);
2540 format
->rtInternal
= format
->glInternal
;
2544 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2545 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2548 static GLenum
lookup_gl_view_class(GLenum internal_format
)
2552 GLenum internal_format
;
2558 {GL_RGBA32F
, GL_VIEW_CLASS_128_BITS
},
2559 {GL_RGBA32UI
, GL_VIEW_CLASS_128_BITS
},
2560 {GL_RGBA32I
, GL_VIEW_CLASS_128_BITS
},
2562 {GL_RGB32F
, GL_VIEW_CLASS_96_BITS
},
2563 {GL_RGB32UI
, GL_VIEW_CLASS_96_BITS
},
2564 {GL_RGB32I
, GL_VIEW_CLASS_96_BITS
},
2566 {GL_RGBA16F
, GL_VIEW_CLASS_64_BITS
},
2567 {GL_RG32F
, GL_VIEW_CLASS_64_BITS
},
2568 {GL_RGBA16UI
, GL_VIEW_CLASS_64_BITS
},
2569 {GL_RG32UI
, GL_VIEW_CLASS_64_BITS
},
2570 {GL_RGBA16I
, GL_VIEW_CLASS_64_BITS
},
2571 {GL_RG32I
, GL_VIEW_CLASS_64_BITS
},
2572 {GL_RGBA16
, GL_VIEW_CLASS_64_BITS
},
2573 {GL_RGBA16_SNORM
, GL_VIEW_CLASS_64_BITS
},
2575 {GL_RGB16
, GL_VIEW_CLASS_48_BITS
},
2576 {GL_RGB16_SNORM
, GL_VIEW_CLASS_48_BITS
},
2577 {GL_RGB16F
, GL_VIEW_CLASS_48_BITS
},
2578 {GL_RGB16UI
, GL_VIEW_CLASS_48_BITS
},
2579 {GL_RGB16I
, GL_VIEW_CLASS_48_BITS
},
2581 {GL_RG16F
, GL_VIEW_CLASS_32_BITS
},
2582 {GL_R11F_G11F_B10F
, GL_VIEW_CLASS_32_BITS
},
2583 {GL_R32F
, GL_VIEW_CLASS_32_BITS
},
2584 {GL_RGB10_A2UI
, GL_VIEW_CLASS_32_BITS
},
2585 {GL_RGBA8UI
, GL_VIEW_CLASS_32_BITS
},
2586 {GL_RG16UI
, GL_VIEW_CLASS_32_BITS
},
2587 {GL_R32UI
, GL_VIEW_CLASS_32_BITS
},
2588 {GL_RGBA8I
, GL_VIEW_CLASS_32_BITS
},
2589 {GL_RG16I
, GL_VIEW_CLASS_32_BITS
},
2590 {GL_R32I
, GL_VIEW_CLASS_32_BITS
},
2591 {GL_RGB10_A2
, GL_VIEW_CLASS_32_BITS
},
2592 {GL_RGBA8
, GL_VIEW_CLASS_32_BITS
},
2593 {GL_RG16
, GL_VIEW_CLASS_32_BITS
},
2594 {GL_RGBA8_SNORM
, GL_VIEW_CLASS_32_BITS
},
2595 {GL_RG16_SNORM
, GL_VIEW_CLASS_32_BITS
},
2596 {GL_SRGB8_ALPHA8
, GL_VIEW_CLASS_32_BITS
},
2597 {GL_RGB9_E5
, GL_VIEW_CLASS_32_BITS
},
2599 {GL_RGB8
, GL_VIEW_CLASS_24_BITS
},
2600 {GL_RGB8_SNORM
, GL_VIEW_CLASS_24_BITS
},
2601 {GL_SRGB8
, GL_VIEW_CLASS_24_BITS
},
2602 {GL_RGB8UI
, GL_VIEW_CLASS_24_BITS
},
2603 {GL_RGB8I
, GL_VIEW_CLASS_24_BITS
},
2605 {GL_R16F
, GL_VIEW_CLASS_16_BITS
},
2606 {GL_RG8UI
, GL_VIEW_CLASS_16_BITS
},
2607 {GL_R16UI
, GL_VIEW_CLASS_16_BITS
},
2608 {GL_RG8I
, GL_VIEW_CLASS_16_BITS
},
2609 {GL_R16I
, GL_VIEW_CLASS_16_BITS
},
2610 {GL_RG8
, GL_VIEW_CLASS_16_BITS
},
2611 {GL_R16
, GL_VIEW_CLASS_16_BITS
},
2612 {GL_RG8_SNORM
, GL_VIEW_CLASS_16_BITS
},
2613 {GL_R16_SNORM
, GL_VIEW_CLASS_16_BITS
},
2615 {GL_R8UI
, GL_VIEW_CLASS_8_BITS
},
2616 {GL_R8I
, GL_VIEW_CLASS_8_BITS
},
2617 {GL_R8
, GL_VIEW_CLASS_8_BITS
},
2618 {GL_R8_SNORM
, GL_VIEW_CLASS_8_BITS
},
2621 {GL_COMPRESSED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
2622 {GL_COMPRESSED_SIGNED_RED_RGTC1
, GL_VIEW_CLASS_RGTC1_RED
},
2624 {GL_COMPRESSED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
2625 {GL_COMPRESSED_SIGNED_RG_RGTC2
, GL_VIEW_CLASS_RGTC2_RG
},
2628 {GL_COMPRESSED_RGBA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
2629 {GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
, GL_VIEW_CLASS_BPTC_UNORM
},
2631 {GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
2632 {GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
, GL_VIEW_CLASS_BPTC_FLOAT
},
2635 {GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
2636 {GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGB
},
2638 {GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
2639 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, GL_VIEW_CLASS_S3TC_DXT1_RGBA
},
2641 {GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
2642 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, GL_VIEW_CLASS_S3TC_DXT3_RGBA
},
2644 {GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
2645 {GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, GL_VIEW_CLASS_S3TC_DXT5_RGBA
},
2650 for (i
= 0; i
< ARRAY_SIZE(view_classes
); ++i
)
2652 if (view_classes
[i
].internal_format
== internal_format
)
2653 return view_classes
[i
].view_class
;
2659 static void query_view_class(struct wined3d_format
*format
)
2661 GLenum internal_view_class
, gamma_view_class
, rt_view_class
;
2663 internal_view_class
= lookup_gl_view_class(format
->glInternal
);
2664 gamma_view_class
= lookup_gl_view_class(format
->glGammaInternal
);
2665 rt_view_class
= lookup_gl_view_class(format
->rtInternal
);
2667 if (internal_view_class
== gamma_view_class
|| gamma_view_class
== rt_view_class
)
2669 format
->gl_view_class
= internal_view_class
;
2670 TRACE("Format %s is member of GL view class %#x.\n",
2671 debug_d3dformat(format
->id
), format
->gl_view_class
);
2675 format
->gl_view_class
= GL_NONE
;
2679 static void query_internal_format(struct wined3d_adapter
*adapter
,
2680 struct wined3d_format
*format
, const struct wined3d_format_texture_info
*texture_info
,
2681 struct wined3d_gl_info
*gl_info
, BOOL srgb_write_supported
, BOOL srgb_format
)
2683 GLint count
, multisample_types
[MAX_MULTISAMPLE_TYPES
];
2684 unsigned int i
, max_log2
;
2686 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2688 query_format_flag(gl_info
, format
, format
->glInternal
, GL_VERTEX_TEXTURE
,
2689 WINED3DFMT_FLAG_VTF
, "vertex texture usage");
2690 query_format_flag(gl_info
, format
, format
->glInternal
, GL_FILTER
,
2691 WINED3DFMT_FLAG_FILTERING
, "filtering");
2693 if (srgb_format
|| format
->glGammaInternal
!= format
->glInternal
)
2695 query_format_flag(gl_info
, format
, format
->glGammaInternal
, GL_SRGB_READ
,
2696 WINED3DFMT_FLAG_SRGB_READ
, "sRGB read");
2698 if (srgb_write_supported
)
2699 query_format_flag(gl_info
, format
, format
->glGammaInternal
, GL_SRGB_WRITE
,
2700 WINED3DFMT_FLAG_SRGB_WRITE
, "sRGB write");
2702 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2704 if (!(format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & (WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
)))
2705 format
->glGammaInternal
= format
->glInternal
;
2706 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2707 format
->glInternal
= format
->glGammaInternal
;
2712 if (!gl_info
->limits
.vertex_samplers
)
2713 format_clear_flag(format
, WINED3DFMT_FLAG_VTF
);
2715 if (!(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2716 format_set_flag(format
, WINED3DFMT_FLAG_FILTERING
);
2717 else if (format
->id
!= WINED3DFMT_R32G32B32A32_FLOAT
&& format
->id
!= WINED3DFMT_R32_FLOAT
)
2718 format_clear_flag(format
, WINED3DFMT_FLAG_VTF
);
2720 if (srgb_format
|| format
->glGammaInternal
!= format
->glInternal
)
2722 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
2723 if (!gl_info
->supported
[EXT_TEXTURE_SRGB
])
2725 format
->glGammaInternal
= format
->glInternal
;
2726 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2728 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2730 format
->glInternal
= format
->glGammaInternal
;
2734 if ((format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_SRGB_WRITE
) && !srgb_write_supported
)
2735 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2737 if (!gl_info
->supported
[ARB_DEPTH_TEXTURE
]
2738 && texture_info
->flags
& (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2740 format
->flags
[WINED3D_GL_RES_TYPE_TEX_1D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2741 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2742 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2743 format
->flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2744 format
->flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2748 query_view_class(format
);
2750 if (format
->glInternal
&& format
->flags
[WINED3D_GL_RES_TYPE_RB
]
2751 & (WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2753 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY
])
2755 GL_EXTCALL(glGetInternalformativ(GL_RENDERBUFFER
, format
->glInternal
,
2756 GL_NUM_SAMPLE_COUNTS
, 1, &count
));
2757 checkGLcall("glGetInternalformativ(GL_NUM_SAMPLE_COUNTS)");
2758 count
= min(count
, MAX_MULTISAMPLE_TYPES
);
2759 GL_EXTCALL(glGetInternalformativ(GL_RENDERBUFFER
, format
->glInternal
,
2760 GL_SAMPLES
, count
, multisample_types
));
2761 checkGLcall("glGetInternalformativ(GL_SAMPLES)");
2762 for (i
= 0; i
< count
; ++i
)
2764 if (multisample_types
[i
] > sizeof(format
->multisample_types
) * 8)
2766 format
->multisample_types
|= 1u << (multisample_types
[i
] - 1);
2771 max_log2
= wined3d_log2i(min(gl_info
->limits
.samples
,
2772 sizeof(format
->multisample_types
) * 8));
2773 for (i
= 1; i
<= max_log2
; ++i
)
2774 format
->multisample_types
|= 1u << ((1u << i
) - 1);
2779 static BOOL
init_format_texture_info(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
2781 struct fragment_caps fragment_caps
;
2782 struct shader_caps shader_caps
;
2786 adapter
->fragment_pipe
->get_caps(gl_info
, &fragment_caps
);
2787 adapter
->shader_backend
->shader_get_caps(gl_info
, &shader_caps
);
2788 srgb_write
= (fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_SRGB_WRITE
)
2789 && (shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_SRGB_WRITE
);
2791 for (i
= 0; i
< sizeof(format_texture_info
) / sizeof(*format_texture_info
); ++i
)
2793 int srgb_fmt_idx
= -1, fmt_idx
= get_format_idx(format_texture_info
[i
].id
);
2794 struct wined3d_format
*format
, *srgb_format
;
2798 ERR("Format %s (%#x) not found.\n",
2799 debug_d3dformat(format_texture_info
[i
].id
), format_texture_info
[i
].id
);
2803 if (!gl_info
->supported
[format_texture_info
[i
].extension
]) continue;
2805 format
= &gl_info
->formats
[fmt_idx
];
2807 /* ARB_texture_rg defines floating point formats, but only if
2808 * ARB_texture_float is also supported. */
2809 if (!gl_info
->supported
[ARB_TEXTURE_FLOAT
]
2810 && (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_FLOAT
))
2813 /* ARB_texture_rg defines integer formats if EXT_texture_integer is also supported. */
2814 if (!gl_info
->supported
[EXT_TEXTURE_INTEGER
]
2815 && (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_INTEGER
))
2818 format
->glInternal
= format_texture_info
[i
].gl_internal
;
2819 format
->glGammaInternal
= format_texture_info
[i
].gl_srgb_internal
;
2820 format
->rtInternal
= format_texture_info
[i
].gl_rt_internal
;
2821 format
->glFormat
= format_texture_info
[i
].gl_format
;
2822 format
->glType
= format_texture_info
[i
].gl_type
;
2823 format
->color_fixup
= COLOR_FIXUP_IDENTITY
;
2824 format
->height_scale
.numerator
= 1;
2825 format
->height_scale
.denominator
= 1;
2827 format
->flags
[WINED3D_GL_RES_TYPE_TEX_1D
] |= format_texture_info
[i
].flags
;
2828 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] |= format_texture_info
[i
].flags
;
2829 format
->flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= format_texture_info
[i
].flags
;
2831 /* GL_ARB_depth_texture does not support 3D textures. It also says "cube textures are
2832 * problematic", but doesn't explicitly mandate that an error is generated. */
2833 if (gl_info
->supported
[EXT_TEXTURE3D
]
2834 && !(format_texture_info
[i
].flags
& (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
)))
2835 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] |= format_texture_info
[i
].flags
;
2837 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
2838 format
->flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= format_texture_info
[i
].flags
;
2840 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
2841 format
->flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] |= format_texture_info
[i
].flags
;
2843 format
->flags
[WINED3D_GL_RES_TYPE_RB
] |= format_texture_info
[i
].flags
;
2844 format
->flags
[WINED3D_GL_RES_TYPE_RB
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2846 if (format
->glGammaInternal
!= format
->glInternal
2847 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
2849 format
->glGammaInternal
= format
->glInternal
;
2850 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2853 query_internal_format(adapter
, format
, &format_texture_info
[i
], gl_info
, srgb_write
, FALSE
);
2855 /* Texture conversion stuff */
2856 format
->convert
= format_texture_info
[i
].convert
;
2857 format
->conv_byte_count
= format_texture_info
[i
].conv_byte_count
;
2859 for (j
= 0; j
< sizeof(format_srgb_info
) / sizeof(*format_srgb_info
); ++j
)
2861 if (format_srgb_info
[j
].base_format_id
== format
->id
)
2863 srgb_fmt_idx
= get_format_idx(format_srgb_info
[j
].srgb_format_id
);
2864 if (srgb_fmt_idx
== -1)
2866 ERR("Format %s (%#x) not found.\n",
2867 debug_d3dformat(format_srgb_info
[j
].srgb_format_id
),
2868 format_srgb_info
[j
].srgb_format_id
);
2875 if (srgb_fmt_idx
== -1)
2878 srgb_format
= &gl_info
->formats
[srgb_fmt_idx
];
2880 *srgb_format
= *format
;
2881 srgb_format
->id
= format_srgb_info
[j
].srgb_format_id
;
2883 if (gl_info
->supported
[EXT_TEXTURE_SRGB
]
2884 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
2886 srgb_format
->glInternal
= format_texture_info
[i
].gl_srgb_internal
;
2887 srgb_format
->glGammaInternal
= format_texture_info
[i
].gl_srgb_internal
;
2888 format_set_flag(srgb_format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2889 query_internal_format(adapter
, srgb_format
, &format_texture_info
[i
], gl_info
, srgb_write
, TRUE
);
2896 static BOOL
color_match(DWORD c1
, DWORD c2
, BYTE max_diff
)
2898 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2900 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2902 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2904 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2908 /* A context is provided by the caller */
2909 static BOOL
check_filter(const struct wined3d_gl_info
*gl_info
, GLenum internal
)
2911 static const DWORD data
[] = {0x00000000, 0xffffffff};
2912 GLuint tex
, fbo
, buffer
;
2913 DWORD readback
[16 * 1];
2916 /* Render a filtered texture and see what happens. This is intended to detect the lack of
2917 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
2918 * falling back to software. If this changes in the future this code will get fooled and
2919 * apps might hit the software path due to incorrectly advertised caps.
2921 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
2922 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
2923 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
2926 while (gl_info
->gl_ops
.gl
.p_glGetError());
2928 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &buffer
);
2929 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
2930 memset(readback
, 0x7e, sizeof(readback
));
2931 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 16, 1, 0,
2932 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, readback
);
2933 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2934 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2935 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
2936 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
2937 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
2939 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &tex
);
2940 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, tex
);
2941 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, internal
, 2, 1, 0,
2942 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, data
);
2943 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
2944 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
2945 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
2946 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
2947 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
2948 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
2950 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2951 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2952 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, buffer
, 0);
2953 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2955 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2956 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
2957 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
2958 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2959 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
2960 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2962 gl_info
->gl_ops
.gl
.p_glClearColor(0, 1, 0, 0);
2963 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
2965 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
2966 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 0.0);
2967 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, -1.0f
);
2968 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 0.0);
2969 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, -1.0f
);
2970 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 1.0);
2971 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, 1.0f
);
2972 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 1.0);
2973 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, 1.0f
);
2974 gl_info
->gl_ops
.gl
.p_glEnd();
2976 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
2977 memset(readback
, 0x7f, sizeof(readback
));
2978 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2979 if (color_match(readback
[6], 0xffffffff, 5) || color_match(readback
[6], 0x00000000, 5)
2980 || color_match(readback
[9], 0xffffffff, 5) || color_match(readback
[9], 0x00000000, 5))
2982 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
2983 readback
[6], readback
[9]);
2988 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
2989 readback
[6], readback
[9]);
2993 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
2994 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2995 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &tex
);
2996 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &buffer
);
2998 if (gl_info
->gl_ops
.gl
.p_glGetError())
3000 FIXME("Error during filtering test for format %x, returning no filtering\n", internal
);
3007 static void init_format_filter_info(struct wined3d_gl_info
*gl_info
, enum wined3d_pci_vendor vendor
)
3009 struct wined3d_format
*format
;
3010 unsigned int fmt_idx
, i
;
3011 static const enum wined3d_format_id fmts16
[] =
3013 WINED3DFMT_R16_FLOAT
,
3014 WINED3DFMT_R16G16_FLOAT
,
3015 WINED3DFMT_R16G16B16A16_FLOAT
,
3019 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
3020 /* This was already handled by init_format_texture_info(). */
3023 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
3024 || !gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3026 WARN("No FBO support, or no FBO ORM, guessing filter info from GL caps\n");
3027 if (vendor
== HW_VENDOR_NVIDIA
&& gl_info
->supported
[ARB_TEXTURE_FLOAT
])
3029 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
3032 else if (gl_info
->limits
.glsl_varyings
> 44)
3034 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
3039 TRACE("Assuming no float16 blending\n");
3045 for(i
= 0; i
< (sizeof(fmts16
) / sizeof(*fmts16
)); i
++)
3047 fmt_idx
= get_format_idx(fmts16
[i
]);
3048 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_FILTERING
);
3054 for(i
= 0; i
< (sizeof(fmts16
) / sizeof(*fmts16
)); i
++)
3056 fmt_idx
= get_format_idx(fmts16
[i
]);
3057 format
= &gl_info
->formats
[fmt_idx
];
3058 if (!format
->glInternal
) continue; /* Not supported by GL */
3060 filtered
= check_filter(gl_info
, gl_info
->formats
[fmt_idx
].glInternal
);
3063 TRACE("Format %s supports filtering\n", debug_d3dformat(fmts16
[i
]));
3064 format_set_flag(format
, WINED3DFMT_FLAG_FILTERING
);
3068 TRACE("Format %s does not support filtering\n", debug_d3dformat(fmts16
[i
]));
3073 static void apply_format_fixups(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
3078 idx
= get_format_idx(WINED3DFMT_R16_FLOAT
);
3079 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3080 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3082 idx
= get_format_idx(WINED3DFMT_R32_FLOAT
);
3083 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3084 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3086 idx
= get_format_idx(WINED3DFMT_R16G16_UNORM
);
3087 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3088 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3090 idx
= get_format_idx(WINED3DFMT_R16G16_FLOAT
);
3091 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3092 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3094 idx
= get_format_idx(WINED3DFMT_R32G32_FLOAT
);
3095 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3096 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
3098 /* GL_ATI_envmap_bumpmap in theory supports R8G8_SNORM but is no longer supported by
3100 if (gl_info
->supported
[NV_TEXTURE_SHADER
] || gl_info
->supported
[EXT_TEXTURE_SNORM
])
3102 /* R8G8_SNORM and R16G16_SNORM need a fixup of the undefined blue channel. OpenGL
3103 * returns 0.0 when sampling from it, DirectX 1.0. So we always have in-shader
3104 * conversion for this format. */
3105 idx
= get_format_idx(WINED3DFMT_R8G8_SNORM
);
3106 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3107 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3108 idx
= get_format_idx(WINED3DFMT_R16G16_SNORM
);
3109 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3110 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3114 /* Emulate using unsigned formats. This requires load-time conversion in addition to the
3116 idx
= get_format_idx(WINED3DFMT_R8G8_SNORM
);
3117 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3118 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3119 idx
= get_format_idx(WINED3DFMT_R16G16_SNORM
);
3120 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3121 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3122 idx
= get_format_idx(WINED3DFMT_R8G8B8A8_SNORM
);
3123 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3124 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 1, CHANNEL_SOURCE_Z
, 1, CHANNEL_SOURCE_W
);
3125 idx
= get_format_idx(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
3126 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3127 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Z
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
);
3130 if (!gl_info
->supported
[NV_TEXTURE_SHADER
])
3132 idx
= get_format_idx(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
3133 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3134 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_Z
, 0, CHANNEL_SOURCE_W
);
3137 if (gl_info
->supported
[ARB_TEXTURE_COMPRESSION_RGTC
] || gl_info
->supported
[EXT_TEXTURE_COMPRESSION_RGTC
])
3139 idx
= get_format_idx(WINED3DFMT_ATI1N
);
3140 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3141 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
);
3143 idx
= get_format_idx(WINED3DFMT_ATI2N
);
3144 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3145 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3147 else if (gl_info
->supported
[ATI_TEXTURE_COMPRESSION_3DC
])
3149 idx
= get_format_idx(WINED3DFMT_ATI2N
);
3150 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3151 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_W
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
3154 if (!gl_info
->supported
[APPLE_YCBCR_422
])
3156 idx
= get_format_idx(WINED3DFMT_YUY2
);
3157 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUY2
);
3159 idx
= get_format_idx(WINED3DFMT_UYVY
);
3160 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_UYVY
);
3163 idx
= get_format_idx(WINED3DFMT_YV12
);
3164 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_HEIGHT_SCALE
);
3165 gl_info
->formats
[idx
].height_scale
.numerator
= 3;
3166 gl_info
->formats
[idx
].height_scale
.denominator
= 2;
3167 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YV12
);
3169 idx
= get_format_idx(WINED3DFMT_NV12
);
3170 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_HEIGHT_SCALE
);
3171 gl_info
->formats
[idx
].height_scale
.numerator
= 3;
3172 gl_info
->formats
[idx
].height_scale
.denominator
= 2;
3173 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_NV12
);
3175 if (!gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
3177 idx
= get_format_idx(WINED3DFMT_A8_UNORM
);
3178 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3179 0, CHANNEL_SOURCE_ZERO
, 0, CHANNEL_SOURCE_ZERO
, 0, CHANNEL_SOURCE_ZERO
, 0, CHANNEL_SOURCE_X
);
3180 idx
= get_format_idx(WINED3DFMT_L8A8_UNORM
);
3181 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3182 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
);
3183 idx
= get_format_idx(WINED3DFMT_L4A4_UNORM
);
3184 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3185 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
);
3186 idx
= get_format_idx(WINED3DFMT_L16_UNORM
);
3187 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3188 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
);
3189 idx
= get_format_idx(WINED3DFMT_INTZ
);
3190 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3191 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
);
3194 if (gl_info
->supported
[ARB_TEXTURE_RG
])
3196 idx
= get_format_idx(WINED3DFMT_L8_UNORM
);
3197 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
3198 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
);
3201 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
])
3203 idx
= get_format_idx(WINED3DFMT_P8_UINT
);
3204 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_P8
);
3207 if (gl_info
->supported
[ARB_VERTEX_ARRAY_BGRA
])
3209 idx
= get_format_idx(WINED3DFMT_B8G8R8A8_UNORM
);
3210 gl_info
->formats
[idx
].gl_vtx_format
= GL_BGRA
;
3213 if (!gl_info
->supported
[ARB_HALF_FLOAT_VERTEX
])
3215 /* Do not change the size of the type, it is CPU side. We have to change the GPU-side information though.
3216 * It is the job of the vertex buffer code to make sure that the vbos have the right format */
3217 idx
= get_format_idx(WINED3DFMT_R16G16_FLOAT
);
3218 gl_info
->formats
[idx
].gl_vtx_type
= GL_FLOAT
;
3220 idx
= get_format_idx(WINED3DFMT_R16G16B16A16_FLOAT
);
3221 gl_info
->formats
[idx
].gl_vtx_type
= GL_FLOAT
;
3224 if (!gl_info
->supported
[ARB_HALF_FLOAT_PIXEL
])
3226 idx
= get_format_idx(WINED3DFMT_R16_FLOAT
);
3227 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3229 idx
= get_format_idx(WINED3DFMT_R16G16_FLOAT
);
3230 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3232 idx
= get_format_idx(WINED3DFMT_R16G16B16A16_FLOAT
);
3233 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3236 if (gl_info
->quirks
& WINED3D_QUIRK_BROKEN_RGBA16
)
3238 idx
= get_format_idx(WINED3DFMT_R16G16B16A16_UNORM
);
3239 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3242 /* ATI instancing hack: Although ATI cards do not support Shader Model
3243 * 3.0, they support instancing. To query if the card supports instancing
3244 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
3245 * is used. Should an application check for this, provide a proper return
3246 * value. We can do instancing with all shader versions, but we need
3249 * Additionally applications have to set the D3DRS_POINTSIZE render state
3250 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
3251 * doesn't need that and just ignores it.
3253 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
3254 /* FIXME: This should just check the shader backend caps. */
3255 if (gl_info
->supported
[ARB_VERTEX_PROGRAM
] || gl_info
->supported
[ARB_VERTEX_SHADER
])
3257 idx
= get_format_idx(WINED3DFMT_INST
);
3258 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3261 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
3262 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
3263 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
3264 * MAKEFOURCC('N','V','D','B') and then controlled by setting
3265 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
3267 if (gl_info
->supported
[EXT_DEPTH_BOUNDS_TEST
])
3269 idx
= get_format_idx(WINED3DFMT_NVDB
);
3270 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3273 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
3274 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
3275 * RENDERTARGET usage. */
3276 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
])
3278 idx
= get_format_idx(WINED3DFMT_RESZ
);
3279 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
);
3282 for (i
= 0; i
< gl_info
->format_count
; ++i
)
3284 struct wined3d_format
*format
= &gl_info
->formats
[i
];
3286 if (!(format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_TEXTURE
))
3289 if (!adapter
->shader_backend
->shader_color_fixup_supported(format
->color_fixup
)
3290 || !adapter
->fragment_pipe
->color_fixup_supported(format
->color_fixup
))
3291 format_clear_flag(format
, WINED3DFMT_FLAG_TEXTURE
);
3294 /* GL_EXT_texture_compression_s3tc does not support 3D textures. Some Windows drivers
3295 * for dx9 GPUs support it, some do not, so not supporting DXTn volumes is OK for d3d9.
3297 * Note that GL_NV_texture_compression_vtc adds this functionality to OpenGL, but the
3298 * block layout is not compatible with the one used by d3d. See volume_dxt5_test. */
3299 idx
= get_format_idx(WINED3DFMT_DXT1
);
3300 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3301 idx
= get_format_idx(WINED3DFMT_DXT2
);
3302 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3303 idx
= get_format_idx(WINED3DFMT_DXT3
);
3304 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3305 idx
= get_format_idx(WINED3DFMT_DXT4
);
3306 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3307 idx
= get_format_idx(WINED3DFMT_DXT5
);
3308 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3309 idx
= get_format_idx(WINED3DFMT_BC1_UNORM
);
3310 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3311 idx
= get_format_idx(WINED3DFMT_BC1_UNORM_SRGB
);
3312 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3313 idx
= get_format_idx(WINED3DFMT_BC2_UNORM
);
3314 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3315 idx
= get_format_idx(WINED3DFMT_BC2_UNORM_SRGB
);
3316 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3317 idx
= get_format_idx(WINED3DFMT_BC3_UNORM
);
3318 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3319 idx
= get_format_idx(WINED3DFMT_BC3_UNORM_SRGB
);
3320 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3321 /* Similarly with ATI1N / ATI2N and GL_ARB_texture_compression_rgtc. */
3322 idx
= get_format_idx(WINED3DFMT_ATI1N
);
3323 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3324 idx
= get_format_idx(WINED3DFMT_ATI2N
);
3325 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3326 idx
= get_format_idx(WINED3DFMT_BC4_UNORM
);
3327 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3328 idx
= get_format_idx(WINED3DFMT_BC5_UNORM
);
3329 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3332 static unsigned int calculate_vertex_attribute_size(GLenum type
, unsigned int component_count
)
3337 return component_count
* sizeof(GLhalfNV
);
3339 return component_count
* sizeof(GLfloat
);
3341 return component_count
* sizeof(GLbyte
);
3342 case GL_UNSIGNED_BYTE
:
3343 return component_count
* sizeof(GLubyte
);
3345 return component_count
* sizeof(GLshort
);
3346 case GL_UNSIGNED_SHORT
:
3347 return component_count
* sizeof(GLushort
);
3349 return component_count
* sizeof(GLint
);
3350 case GL_UNSIGNED_INT
:
3351 return component_count
* sizeof(GLuint
);
3352 case GL_UNSIGNED_INT_2_10_10_10_REV
:
3353 return sizeof(GLuint
);
3355 FIXME("Unhandled GL type %#x.\n", type
);
3360 static BOOL
init_format_vertex_info(struct wined3d_gl_info
*gl_info
)
3364 for (i
= 0; i
< ARRAY_SIZE(format_vertex_info
); ++i
)
3366 struct wined3d_format
*format
;
3367 int fmt_idx
= get_format_idx(format_vertex_info
[i
].id
);
3371 ERR("Format %s (%#x) not found.\n",
3372 debug_d3dformat(format_vertex_info
[i
].id
), format_vertex_info
[i
].id
);
3376 if (!gl_info
->supported
[format_vertex_info
[i
].extension
])
3379 format
= &gl_info
->formats
[fmt_idx
];
3380 format
->emit_idx
= format_vertex_info
[i
].emit_idx
;
3381 format
->component_count
= format_vertex_info
[i
].component_count
;
3382 format
->gl_vtx_type
= format_vertex_info
[i
].gl_vtx_type
;
3383 format
->gl_vtx_format
= format_vertex_info
[i
].component_count
;
3384 format
->gl_normalized
= format_vertex_info
[i
].gl_normalized
;
3385 if (!(format
->attribute_size
= calculate_vertex_attribute_size(format
->gl_vtx_type
,
3386 format
->component_count
)))
3388 ERR("Invalid attribute size for vertex format %s (%#x).\n",
3389 debug_d3dformat(format_vertex_info
[i
].id
), format_vertex_info
[i
].id
);
3397 static BOOL
init_typeless_formats(struct wined3d_gl_info
*gl_info
)
3399 unsigned int flags
[WINED3D_GL_RES_TYPE_COUNT
];
3402 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
3404 struct wined3d_format
*format
, *typeless_format
;
3405 int fmt_idx
= get_format_idx(typed_formats
[i
].id
);
3406 int typeless_fmt_idx
= get_format_idx(typed_formats
[i
].typeless_id
);
3410 ERR("Format %s (%#x) not found.\n",
3411 debug_d3dformat(typed_formats
[i
].id
),
3412 typed_formats
[i
].id
);
3415 if (typeless_fmt_idx
== -1)
3417 ERR("Format %s (%#x) not found.\n",
3418 debug_d3dformat(typed_formats
[i
].typeless_id
),
3419 typed_formats
[i
].typeless_id
);
3423 format
= &gl_info
->formats
[fmt_idx
];
3424 typeless_format
= &gl_info
->formats
[typeless_fmt_idx
];
3426 memcpy(flags
, typeless_format
->flags
, sizeof(flags
));
3427 *typeless_format
= *format
;
3428 typeless_format
->id
= typed_formats
[i
].typeless_id
;
3429 for (j
= 0; j
< ARRAY_SIZE(typeless_format
->flags
); ++j
)
3430 typeless_format
->flags
[j
] |= flags
[j
];
3436 BOOL
initPixelFormatsNoGL(struct wined3d_gl_info
*gl_info
)
3438 if (!init_format_base_info(gl_info
)) return FALSE
;
3440 if (!init_format_block_info(gl_info
))
3442 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
3443 gl_info
->formats
= NULL
;
3450 /* Context activation is done by the caller. */
3451 BOOL
wined3d_adapter_init_format_info(struct wined3d_adapter
*adapter
, struct wined3d_caps_gl_ctx
*ctx
)
3453 struct wined3d_gl_info
*gl_info
= &adapter
->gl_info
;
3455 if (!init_format_base_info(gl_info
)) return FALSE
;
3457 if (!init_format_block_info(gl_info
)) goto fail
;
3458 if (!init_format_texture_info(adapter
, gl_info
)) goto fail
;
3459 if (!init_format_vertex_info(gl_info
)) goto fail
;
3461 apply_format_fixups(adapter
, gl_info
);
3462 init_format_fbo_compat_info(ctx
);
3463 init_format_filter_info(gl_info
, adapter
->driver_info
.vendor
);
3464 if (!init_typeless_formats(gl_info
)) goto fail
;
3469 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
3470 gl_info
->formats
= NULL
;
3474 float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx
*ctx
, GLenum format
)
3476 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3477 static const struct wined3d_color blue
= {0.0f
, 0.0f
, 1.0f
, 1.0f
};
3478 GLuint fbo
, color
, depth
;
3479 unsigned int low
= 0, high
= 32, cur
;
3480 DWORD readback
[256];
3481 static const struct wined3d_vec3 geometry
[] =
3483 {-1.0f
, -1.0f
, -1.0f
},
3484 { 1.0f
, -1.0f
, 0.0f
},
3485 {-1.0f
, 1.0f
, -1.0f
},
3486 { 1.0f
, 1.0f
, 0.0f
},
3489 /* Most drivers want 2^23 for fixed point depth buffers, including r300g, r600g,
3490 * Nvidia. Use this as a fallback if the detection fails. */
3491 unsigned int fallback
= 23;
3493 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
3495 FIXME("No FBOs, assuming polyoffset scale of 2^%u.\n", fallback
);
3496 return (float)(1u << fallback
);
3499 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &color
);
3500 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
3501 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3502 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);
3504 gl_info
->fbo_ops
.glGenRenderbuffers(1, &depth
);
3505 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, depth
);
3506 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, format
, 256, 1);
3508 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3509 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3510 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, color
, 0);
3511 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, depth
);
3512 checkGLcall("Setup framebuffer");
3514 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.5f
, 0.0f
);
3515 gl_info
->gl_ops
.gl
.p_glClearDepth(0.5f
);
3516 gl_info
->gl_ops
.gl
.p_glEnable(GL_DEPTH_TEST
);
3517 gl_info
->gl_ops
.gl
.p_glEnable(GL_POLYGON_OFFSET_FILL
);
3518 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 256, 1);
3519 checkGLcall("Misc parameters");
3523 if (high
- low
<= 1)
3525 ERR("PolygonOffset scale factor detection failed, using fallback value 2^%u.\n", fallback
);
3529 cur
= (low
+ high
) / 2;
3531 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
3532 /* The post viewport transform Z of the geometry runs from 0.0 to 0.5. We want to push it another
3533 * 0.25 so that the Z buffer content (0.5) cuts the quad off at half the screen. */
3534 gl_info
->gl_ops
.gl
.p_glPolygonOffset(0.0f
, (float)(1u << cur
) * 0.25f
);
3535 draw_test_quad(ctx
, geometry
, &blue
);
3536 checkGLcall("Test draw");
3538 /* Rebinding texture to workaround a fglrx bug. */
3539 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
3540 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3541 checkGLcall("readback");
3543 TRACE("low %02u, high %02u, cur %2u, 0=0x%08x, 125=0x%08x, 131=0x%08x, 255=0x%08x\n",
3544 low
, high
, cur
, readback
[0], readback
[125], readback
[131], readback
[255]);
3546 if ((readback
[125] & 0xff) < 0xa0)
3548 else if ((readback
[131] & 0xff) > 0xa0)
3552 TRACE("Found scale factor 2^%u for format %x\n", cur
, format
);
3557 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &color
);
3558 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &depth
);
3559 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3560 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3561 checkGLcall("Delete framebuffer");
3563 gl_info
->gl_ops
.gl
.p_glDisable(GL_DEPTH_TEST
);
3564 gl_info
->gl_ops
.gl
.p_glDisable(GL_POLYGON_OFFSET_FILL
);
3565 return (float)(1u << cur
);
3568 const struct wined3d_format
*wined3d_get_format(const struct wined3d_gl_info
*gl_info
,
3569 enum wined3d_format_id format_id
)
3571 int idx
= get_format_idx(format_id
);
3575 FIXME("Can't find format %s (%#x) in the format lookup table\n",
3576 debug_d3dformat(format_id
), format_id
);
3577 /* Get the caller a valid pointer */
3578 idx
= get_format_idx(WINED3DFMT_UNKNOWN
);
3581 return &gl_info
->formats
[idx
];
3584 void wined3d_format_calculate_pitch(const struct wined3d_format
*format
, unsigned int alignment
,
3585 unsigned int width
, unsigned int height
, unsigned int *row_pitch
, unsigned int *slice_pitch
)
3587 /* For block based formats, pitch means the amount of bytes to the next
3588 * row of blocks rather than the next row of pixels. */
3589 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BLOCKS
)
3591 unsigned int row_block_count
= (width
+ format
->block_width
- 1) / format
->block_width
;
3592 unsigned int slice_block_count
= (height
+ format
->block_height
- 1) / format
->block_height
;
3593 *row_pitch
= row_block_count
* format
->block_byte_count
;
3594 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
3595 *slice_pitch
= *row_pitch
* slice_block_count
;
3599 *row_pitch
= format
->byte_count
* width
; /* Bytes / row */
3600 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
3601 *slice_pitch
= *row_pitch
* height
;
3604 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_HEIGHT_SCALE
)
3606 /* The D3D format requirements make sure that the resulting format is an integer again */
3607 *slice_pitch
*= format
->height_scale
.numerator
;
3608 *slice_pitch
/= format
->height_scale
.denominator
;
3611 TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch
, *slice_pitch
);
3614 UINT
wined3d_format_calculate_size(const struct wined3d_format
*format
, UINT alignment
,
3615 UINT width
, UINT height
, UINT depth
)
3617 unsigned int row_pitch
, slice_pitch
;
3619 if (format
->id
== WINED3DFMT_UNKNOWN
)
3622 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BROKEN_PITCH
)
3623 return width
* height
* depth
* format
->byte_count
;
3625 wined3d_format_calculate_pitch(format
, alignment
, width
, height
, &row_pitch
, &slice_pitch
);
3627 return slice_pitch
* depth
;
3630 /*****************************************************************************
3631 * Trace formatting of useful values
3633 const char *debug_box(const struct wined3d_box
*box
)
3637 return wine_dbg_sprintf("(%u, %u, %u)-(%u, %u, %u)",
3638 box
->left
, box
->top
, box
->front
,
3639 box
->right
, box
->bottom
, box
->back
);
3642 const char *debug_color(const struct wined3d_color
*color
)
3646 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
3647 color
->r
, color
->g
, color
->b
, color
->a
);
3650 const char *debug_ivec4(const struct wined3d_ivec4
*v
)
3654 return wine_dbg_sprintf("{%d, %d, %d, %d}",
3655 v
->x
, v
->y
, v
->z
, v
->w
);
3658 const char *debug_vec4(const struct wined3d_vec4
*v
)
3662 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
3663 v
->x
, v
->y
, v
->z
, v
->w
);
3666 const char *debug_d3dformat(enum wined3d_format_id format_id
)
3670 #define FMT_TO_STR(format_id) case format_id: return #format_id
3671 FMT_TO_STR(WINED3DFMT_UNKNOWN
);
3672 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM
);
3673 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM
);
3674 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM
);
3675 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM
);
3676 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM
);
3677 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM
);
3678 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM
);
3679 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM
);
3680 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM
);
3681 FMT_TO_STR(WINED3DFMT_P8_UINT
);
3682 FMT_TO_STR(WINED3DFMT_L8_UNORM
);
3683 FMT_TO_STR(WINED3DFMT_L8A8_UNORM
);
3684 FMT_TO_STR(WINED3DFMT_L4A4_UNORM
);
3685 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
3686 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
3687 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM
);
3688 FMT_TO_STR(WINED3DFMT_R10G10B10X2_UINT
);
3689 FMT_TO_STR(WINED3DFMT_R10G10B10X2_SNORM
);
3690 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM
);
3691 FMT_TO_STR(WINED3DFMT_UYVY
);
3692 FMT_TO_STR(WINED3DFMT_YUY2
);
3693 FMT_TO_STR(WINED3DFMT_YV12
);
3694 FMT_TO_STR(WINED3DFMT_NV12
);
3695 FMT_TO_STR(WINED3DFMT_DXT1
);
3696 FMT_TO_STR(WINED3DFMT_DXT2
);
3697 FMT_TO_STR(WINED3DFMT_DXT3
);
3698 FMT_TO_STR(WINED3DFMT_DXT4
);
3699 FMT_TO_STR(WINED3DFMT_DXT5
);
3700 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8
);
3701 FMT_TO_STR(WINED3DFMT_G8R8_G8B8
);
3702 FMT_TO_STR(WINED3DFMT_R8G8_B8G8
);
3703 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE
);
3704 FMT_TO_STR(WINED3DFMT_D32_UNORM
);
3705 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM
);
3706 FMT_TO_STR(WINED3DFMT_X8D24_UNORM
);
3707 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM
);
3708 FMT_TO_STR(WINED3DFMT_L16_UNORM
);
3709 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT
);
3710 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx
);
3711 FMT_TO_STR(WINED3DFMT_ATI1N
);
3712 FMT_TO_STR(WINED3DFMT_ATI2N
);
3713 FMT_TO_STR(WINED3DFMT_NVDB
);
3714 FMT_TO_STR(WINED3DFMT_NVHU
);
3715 FMT_TO_STR(WINED3DFMT_NVHS
);
3716 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS
);
3717 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT
);
3718 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT
);
3719 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT
);
3720 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS
);
3721 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT
);
3722 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT
);
3723 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT
);
3724 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS
);
3725 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT
);
3726 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM
);
3727 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT
);
3728 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM
);
3729 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT
);
3730 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS
);
3731 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT
);
3732 FMT_TO_STR(WINED3DFMT_R32G32_UINT
);
3733 FMT_TO_STR(WINED3DFMT_R32G32_SINT
);
3734 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS
);
3735 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT
);
3736 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
);
3737 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT
);
3738 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS
);
3739 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM
);
3740 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT
);
3741 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM
);
3742 FMT_TO_STR(WINED3DFMT_R10G10B10_XR_BIAS_A2_UNORM
);
3743 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT
);
3744 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS
);
3745 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM
);
3746 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB
);
3747 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT
);
3748 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM
);
3749 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT
);
3750 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS
);
3751 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT
);
3752 FMT_TO_STR(WINED3DFMT_R16G16_UNORM
);
3753 FMT_TO_STR(WINED3DFMT_R16G16_UINT
);
3754 FMT_TO_STR(WINED3DFMT_R16G16_SNORM
);
3755 FMT_TO_STR(WINED3DFMT_R16G16_SINT
);
3756 FMT_TO_STR(WINED3DFMT_R32_TYPELESS
);
3757 FMT_TO_STR(WINED3DFMT_D32_FLOAT
);
3758 FMT_TO_STR(WINED3DFMT_R32_FLOAT
);
3759 FMT_TO_STR(WINED3DFMT_R32_UINT
);
3760 FMT_TO_STR(WINED3DFMT_R32_SINT
);
3761 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS
);
3762 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT
);
3763 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS
);
3764 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT
);
3765 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS
);
3766 FMT_TO_STR(WINED3DFMT_R8G8_UNORM
);
3767 FMT_TO_STR(WINED3DFMT_R8G8_UINT
);
3768 FMT_TO_STR(WINED3DFMT_R8G8_SNORM
);
3769 FMT_TO_STR(WINED3DFMT_R8G8_SINT
);
3770 FMT_TO_STR(WINED3DFMT_R16_TYPELESS
);
3771 FMT_TO_STR(WINED3DFMT_R16_FLOAT
);
3772 FMT_TO_STR(WINED3DFMT_D16_UNORM
);
3773 FMT_TO_STR(WINED3DFMT_R16_UNORM
);
3774 FMT_TO_STR(WINED3DFMT_R16_UINT
);
3775 FMT_TO_STR(WINED3DFMT_R16_SNORM
);
3776 FMT_TO_STR(WINED3DFMT_R16_SINT
);
3777 FMT_TO_STR(WINED3DFMT_R8_TYPELESS
);
3778 FMT_TO_STR(WINED3DFMT_R8_UNORM
);
3779 FMT_TO_STR(WINED3DFMT_R8_UINT
);
3780 FMT_TO_STR(WINED3DFMT_R8_SNORM
);
3781 FMT_TO_STR(WINED3DFMT_R8_SINT
);
3782 FMT_TO_STR(WINED3DFMT_A8_UNORM
);
3783 FMT_TO_STR(WINED3DFMT_R1_UNORM
);
3784 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP
);
3785 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM
);
3786 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM
);
3787 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS
);
3788 FMT_TO_STR(WINED3DFMT_BC1_UNORM
);
3789 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB
);
3790 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS
);
3791 FMT_TO_STR(WINED3DFMT_BC2_UNORM
);
3792 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB
);
3793 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS
);
3794 FMT_TO_STR(WINED3DFMT_BC3_UNORM
);
3795 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB
);
3796 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS
);
3797 FMT_TO_STR(WINED3DFMT_BC4_UNORM
);
3798 FMT_TO_STR(WINED3DFMT_BC4_SNORM
);
3799 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS
);
3800 FMT_TO_STR(WINED3DFMT_BC5_UNORM
);
3801 FMT_TO_STR(WINED3DFMT_BC5_SNORM
);
3802 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM
);
3803 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM
);
3804 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM
);
3805 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM
);
3806 FMT_TO_STR(WINED3DFMT_B8G8R8A8_TYPELESS
);
3807 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM_SRGB
);
3808 FMT_TO_STR(WINED3DFMT_B8G8R8X8_TYPELESS
);
3809 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM_SRGB
);
3810 FMT_TO_STR(WINED3DFMT_BC6H_TYPELESS
);
3811 FMT_TO_STR(WINED3DFMT_BC6H_UF16
);
3812 FMT_TO_STR(WINED3DFMT_BC6H_SF16
);
3813 FMT_TO_STR(WINED3DFMT_BC7_TYPELESS
);
3814 FMT_TO_STR(WINED3DFMT_BC7_UNORM
);
3815 FMT_TO_STR(WINED3DFMT_BC7_UNORM_SRGB
);
3816 FMT_TO_STR(WINED3DFMT_INTZ
);
3817 FMT_TO_STR(WINED3DFMT_RESZ
);
3818 FMT_TO_STR(WINED3DFMT_NULL
);
3819 FMT_TO_STR(WINED3DFMT_R16
);
3820 FMT_TO_STR(WINED3DFMT_AL16
);
3825 fourcc
[0] = (char)(format_id
);
3826 fourcc
[1] = (char)(format_id
>> 8);
3827 fourcc
[2] = (char)(format_id
>> 16);
3828 fourcc
[3] = (char)(format_id
>> 24);
3830 if (isprint(fourcc
[0]) && isprint(fourcc
[1]) && isprint(fourcc
[2]) && isprint(fourcc
[3]))
3831 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id
, fourcc
);
3833 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id
);
3835 return "unrecognized";
3839 const char *debug_d3ddevicetype(enum wined3d_device_type device_type
)
3841 switch (device_type
)
3843 #define DEVTYPE_TO_STR(dev) case dev: return #dev
3844 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL
);
3845 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF
);
3846 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW
);
3847 #undef DEVTYPE_TO_STR
3849 FIXME("Unrecognized device type %#x.\n", device_type
);
3850 return "unrecognized";
3854 const char *debug_d3dusage(DWORD usage
)
3859 #define WINED3DUSAGE_TO_STR(u) if (usage & u) { strcat(buf, " | "#u); usage &= ~u; }
3860 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RENDERTARGET
);
3861 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DEPTHSTENCIL
);
3862 WINED3DUSAGE_TO_STR(WINED3DUSAGE_WRITEONLY
);
3863 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING
);
3864 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP
);
3865 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS
);
3866 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES
);
3867 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES
);
3868 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC
);
3869 WINED3DUSAGE_TO_STR(WINED3DUSAGE_AUTOGENMIPMAP
);
3870 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICTED_CONTENT
);
3871 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE_DRIVER
);
3872 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RESTRICT_SHARED_RESOURCE
);
3873 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP
);
3874 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTAPI
);
3875 WINED3DUSAGE_TO_STR(WINED3DUSAGE_LEGACY_CUBEMAP
);
3876 WINED3DUSAGE_TO_STR(WINED3DUSAGE_TEXTURE
);
3877 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OWNDC
);
3878 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL
);
3879 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY
);
3880 #undef WINED3DUSAGE_TO_STR
3881 if (usage
) FIXME("Unrecognized usage flag(s) %#x\n", usage
);
3883 return buf
[0] ? wine_dbg_sprintf("%s", &buf
[3]) : "0";
3886 const char *debug_d3dusagequery(DWORD usagequery
)
3891 #define WINED3DUSAGEQUERY_TO_STR(u) if (usagequery & u) { strcat(buf, " | "#u); usagequery &= ~u; }
3892 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_FILTER
);
3893 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP
);
3894 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
);
3895 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD
);
3896 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE
);
3897 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE
);
3898 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP
);
3899 #undef WINED3DUSAGEQUERY_TO_STR
3900 if (usagequery
) FIXME("Unrecognized usage query flag(s) %#x\n", usagequery
);
3902 return buf
[0] ? wine_dbg_sprintf("%s", &buf
[3]) : "0";
3905 const char *debug_d3ddeclmethod(enum wined3d_decl_method method
)
3909 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
3910 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT
);
3911 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U
);
3912 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V
);
3913 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV
);
3914 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV
);
3915 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP
);
3916 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED
);
3917 #undef WINED3DDECLMETHOD_TO_STR
3919 FIXME("Unrecognized declaration method %#x.\n", method
);
3920 return "unrecognized";
3924 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage
)
3928 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
3929 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION
);
3930 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT
);
3931 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES
);
3932 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL
);
3933 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE
);
3934 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD
);
3935 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT
);
3936 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL
);
3937 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR
);
3938 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT
);
3939 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR
);
3940 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG
);
3941 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH
);
3942 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE
);
3943 #undef WINED3DDECLUSAGE_TO_STR
3945 FIXME("Unrecognized %u declaration usage!\n", usage
);
3946 return "unrecognized";
3950 const char *debug_d3dinput_classification(enum wined3d_input_classification classification
)
3952 switch (classification
)
3954 #define WINED3D_TO_STR(x) case x: return #x
3955 WINED3D_TO_STR(WINED3D_INPUT_PER_VERTEX_DATA
);
3956 WINED3D_TO_STR(WINED3D_INPUT_PER_INSTANCE_DATA
);
3957 #undef WINED3D_TO_STR
3959 FIXME("Unrecognized input classification %#x.\n", classification
);
3960 return "unrecognized";
3964 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type
)
3966 switch (resource_type
)
3968 #define WINED3D_TO_STR(x) case x: return #x
3969 WINED3D_TO_STR(WINED3D_RTYPE_BUFFER
);
3970 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_2D
);
3971 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_3D
);
3972 #undef WINED3D_TO_STR
3974 FIXME("Unrecognized resource type %#x.\n", resource_type
);
3975 return "unrecognized";
3979 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type
)
3981 switch (primitive_type
)
3983 #define PRIM_TO_STR(prim) case prim: return #prim
3984 PRIM_TO_STR(WINED3D_PT_UNDEFINED
);
3985 PRIM_TO_STR(WINED3D_PT_POINTLIST
);
3986 PRIM_TO_STR(WINED3D_PT_LINELIST
);
3987 PRIM_TO_STR(WINED3D_PT_LINESTRIP
);
3988 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST
);
3989 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP
);
3990 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN
);
3991 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ
);
3992 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ
);
3993 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ
);
3994 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ
);
3997 FIXME("Unrecognized %u primitive type!\n", primitive_type
);
3998 return "unrecognized";
4002 const char *debug_d3drenderstate(enum wined3d_render_state state
)
4006 #define D3DSTATE_TO_STR(u) case u: return #u
4007 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS
);
4008 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE
);
4009 D3DSTATE_TO_STR(WINED3D_RS_WRAPU
);
4010 D3DSTATE_TO_STR(WINED3D_RS_WRAPV
);
4011 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE
);
4012 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE
);
4013 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE
);
4014 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN
);
4015 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE
);
4016 D3DSTATE_TO_STR(WINED3D_RS_ROP2
);
4017 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK
);
4018 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE
);
4019 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE
);
4020 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL
);
4021 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND
);
4022 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND
);
4023 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE
);
4024 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC
);
4025 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF
);
4026 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC
);
4027 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE
);
4028 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE
);
4029 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE
);
4030 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE
);
4031 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE
);
4032 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL
);
4033 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX
);
4034 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA
);
4035 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR
);
4036 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE
);
4037 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART
);
4038 D3DSTATE_TO_STR(WINED3D_RS_FOGEND
);
4039 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY
);
4040 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE
);
4041 D3DSTATE_TO_STR(WINED3D_RS_EDGEANTIALIAS
);
4042 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE
);
4043 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS
);
4044 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE
);
4045 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY
);
4046 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH
);
4047 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT
);
4048 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE
);
4049 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL
);
4050 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL
);
4051 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS
);
4052 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC
);
4053 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF
);
4054 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK
);
4055 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK
);
4056 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR
);
4057 D3DSTATE_TO_STR(WINED3D_RS_WRAP0
);
4058 D3DSTATE_TO_STR(WINED3D_RS_WRAP1
);
4059 D3DSTATE_TO_STR(WINED3D_RS_WRAP2
);
4060 D3DSTATE_TO_STR(WINED3D_RS_WRAP3
);
4061 D3DSTATE_TO_STR(WINED3D_RS_WRAP4
);
4062 D3DSTATE_TO_STR(WINED3D_RS_WRAP5
);
4063 D3DSTATE_TO_STR(WINED3D_RS_WRAP6
);
4064 D3DSTATE_TO_STR(WINED3D_RS_WRAP7
);
4065 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING
);
4066 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING
);
4067 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS
);
4068 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT
);
4069 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE
);
4070 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX
);
4071 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER
);
4072 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS
);
4073 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE
);
4074 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE
);
4075 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE
);
4076 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE
);
4077 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE
);
4078 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND
);
4079 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE
);
4080 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING
);
4081 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE
);
4082 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN
);
4083 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE
);
4084 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE
);
4085 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A
);
4086 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B
);
4087 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C
);
4088 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS
);
4089 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK
);
4090 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE
);
4091 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS
);
4092 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN
);
4093 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX
);
4094 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE
);
4095 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE
);
4096 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR
);
4097 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP
);
4098 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE
);
4099 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE
);
4100 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE
);
4101 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS
);
4102 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE
);
4103 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL
);
4104 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL
);
4105 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X
);
4106 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y
);
4107 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z
);
4108 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W
);
4109 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION
);
4110 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE
);
4111 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILFAIL
);
4112 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILZFAIL
);
4113 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILPASS
);
4114 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILFUNC
);
4115 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1
);
4116 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2
);
4117 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3
);
4118 D3DSTATE_TO_STR(WINED3D_RS_BLENDFACTOR
);
4119 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE
);
4120 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS
);
4121 D3DSTATE_TO_STR(WINED3D_RS_WRAP8
);
4122 D3DSTATE_TO_STR(WINED3D_RS_WRAP9
);
4123 D3DSTATE_TO_STR(WINED3D_RS_WRAP10
);
4124 D3DSTATE_TO_STR(WINED3D_RS_WRAP11
);
4125 D3DSTATE_TO_STR(WINED3D_RS_WRAP12
);
4126 D3DSTATE_TO_STR(WINED3D_RS_WRAP13
);
4127 D3DSTATE_TO_STR(WINED3D_RS_WRAP14
);
4128 D3DSTATE_TO_STR(WINED3D_RS_WRAP15
);
4129 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE
);
4130 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA
);
4131 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA
);
4132 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA
);
4133 #undef D3DSTATE_TO_STR
4135 FIXME("Unrecognized %u render state!\n", state
);
4136 return "unrecognized";
4140 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state
)
4144 #define D3DSTATE_TO_STR(u) case u: return #u
4145 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR
);
4146 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U
);
4147 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V
);
4148 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W
);
4149 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER
);
4150 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER
);
4151 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER
);
4152 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS
);
4153 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL
);
4154 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY
);
4155 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE
);
4156 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX
);
4157 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET
);
4158 #undef D3DSTATE_TO_STR
4160 FIXME("Unrecognized %u sampler state!\n", state
);
4161 return "unrecognized";
4165 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type
)
4167 switch (filter_type
)
4169 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
4170 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE
);
4171 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT
);
4172 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR
);
4173 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC
);
4174 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC
);
4175 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC
);
4176 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD
);
4177 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD
);
4178 #undef D3DTEXTUREFILTERTYPE_TO_STR
4180 FIXME("Unrecognized texture filter type 0x%08x.\n", filter_type
);
4181 return "unrecognized";
4185 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state
)
4189 #define D3DSTATE_TO_STR(u) case u: return #u
4190 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP
);
4191 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1
);
4192 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2
);
4193 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP
);
4194 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1
);
4195 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2
);
4196 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00
);
4197 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01
);
4198 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10
);
4199 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11
);
4200 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX
);
4201 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE
);
4202 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET
);
4203 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
);
4204 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0
);
4205 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0
);
4206 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG
);
4207 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT
);
4208 #undef D3DSTATE_TO_STR
4210 FIXME("Unrecognized %u texture state!\n", state
);
4211 return "unrecognized";
4215 const char *debug_d3dtop(enum wined3d_texture_op d3dtop
)
4219 #define D3DTOP_TO_STR(u) case u: return #u
4220 D3DTOP_TO_STR(WINED3D_TOP_DISABLE
);
4221 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1
);
4222 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2
);
4223 D3DTOP_TO_STR(WINED3D_TOP_MODULATE
);
4224 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X
);
4225 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X
);
4226 D3DTOP_TO_STR(WINED3D_TOP_ADD
);
4227 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED
);
4228 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X
);
4229 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT
);
4230 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH
);
4231 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA
);
4232 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA
);
4233 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA
);
4234 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM
);
4235 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA
);
4236 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE
);
4237 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR
);
4238 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA
);
4239 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR
);
4240 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA
);
4241 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP
);
4242 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE
);
4243 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3
);
4244 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD
);
4245 D3DTOP_TO_STR(WINED3D_TOP_LERP
);
4246 #undef D3DTOP_TO_STR
4248 FIXME("Unrecognized texture op %#x.\n", d3dtop
);
4249 return "unrecognized";
4253 const char *debug_d3dtstype(enum wined3d_transform_state tstype
)
4257 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
4258 TSTYPE_TO_STR(WINED3D_TS_VIEW
);
4259 TSTYPE_TO_STR(WINED3D_TS_PROJECTION
);
4260 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0
);
4261 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1
);
4262 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2
);
4263 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3
);
4264 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4
);
4265 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5
);
4266 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6
);
4267 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7
);
4268 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
4269 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(1));
4270 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(2));
4271 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(3));
4272 #undef TSTYPE_TO_STR
4274 if (tstype
> 256 && tstype
< 512)
4276 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype
);
4277 return ("WINED3D_TS_WORLD_MATRIX > 0");
4279 FIXME("Unrecognized transform state %#x.\n", tstype
);
4280 return "unrecognized";
4284 const char *debug_shader_type(enum wined3d_shader_type type
)
4288 #define WINED3D_TO_STR(type) case type: return #type
4289 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL
);
4290 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX
);
4291 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY
);
4292 WINED3D_TO_STR(WINED3D_SHADER_TYPE_HULL
);
4293 WINED3D_TO_STR(WINED3D_SHADER_TYPE_DOMAIN
);
4294 WINED3D_TO_STR(WINED3D_SHADER_TYPE_COMPUTE
);
4295 #undef WINED3D_TO_STR
4297 FIXME("Unrecognized shader type %#x.\n", type
);
4298 return "unrecognized";
4302 const char *debug_d3dstate(DWORD state
)
4304 if (STATE_IS_RENDER(state
))
4305 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state
- STATE_RENDER(0)));
4306 if (STATE_IS_TEXTURESTAGE(state
))
4308 DWORD texture_stage
= (state
- STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE
+ 1);
4309 DWORD texture_state
= state
- STATE_TEXTURESTAGE(texture_stage
, 0);
4310 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
4311 texture_stage
, debug_d3dtexturestate(texture_state
));
4313 if (STATE_IS_SAMPLER(state
))
4314 return wine_dbg_sprintf("STATE_SAMPLER(%#x)", state
- STATE_SAMPLER(0));
4315 if (STATE_IS_SHADER(state
))
4316 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state
- STATE_SHADER(0)));
4317 if (STATE_IS_CONSTANT_BUFFER(state
))
4318 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state
- STATE_CONSTANT_BUFFER(0)));
4319 if (STATE_IS_SHADER_RESOURCE_BINDING(state
))
4320 return "STATE_SHADER_RESOURCE_BINDING";
4321 if (STATE_IS_TRANSFORM(state
))
4322 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state
- STATE_TRANSFORM(0)));
4323 if (STATE_IS_STREAMSRC(state
))
4324 return "STATE_STREAMSRC";
4325 if (STATE_IS_INDEXBUFFER(state
))
4326 return "STATE_INDEXBUFFER";
4327 if (STATE_IS_VDECL(state
))
4328 return "STATE_VDECL";
4329 if (STATE_IS_VIEWPORT(state
))
4330 return "STATE_VIEWPORT";
4331 if (STATE_IS_LIGHT_TYPE(state
))
4332 return "STATE_LIGHT_TYPE";
4333 if (STATE_IS_ACTIVELIGHT(state
))
4334 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state
- STATE_ACTIVELIGHT(0));
4335 if (STATE_IS_SCISSORRECT(state
))
4336 return "STATE_SCISSORRECT";
4337 if (STATE_IS_CLIPPLANE(state
))
4338 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state
- STATE_CLIPPLANE(0));
4339 if (STATE_IS_MATERIAL(state
))
4340 return "STATE_MATERIAL";
4341 if (STATE_IS_FRONTFACE(state
))
4342 return "STATE_FRONTFACE";
4343 if (STATE_IS_POINTSPRITECOORDORIGIN(state
))
4344 return "STATE_POINTSPRITECOORDORIGIN";
4345 if (STATE_IS_BASEVERTEXINDEX(state
))
4346 return "STATE_BASEVERTEXINDEX";
4347 if (STATE_IS_FRAMEBUFFER(state
))
4348 return "STATE_FRAMEBUFFER";
4349 if (STATE_IS_POINT_ENABLE(state
))
4350 return "STATE_POINT_ENABLE";
4351 if (STATE_IS_COLOR_KEY(state
))
4352 return "STATE_COLOR_KEY";
4354 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state
);
4357 const char *debug_d3dpool(enum wined3d_pool pool
)
4361 #define POOL_TO_STR(p) case p: return #p
4362 POOL_TO_STR(WINED3D_POOL_DEFAULT
);
4363 POOL_TO_STR(WINED3D_POOL_MANAGED
);
4364 POOL_TO_STR(WINED3D_POOL_SYSTEM_MEM
);
4365 POOL_TO_STR(WINED3D_POOL_SCRATCH
);
4368 FIXME("Unrecognized pool %#x.\n", pool
);
4369 return "unrecognized";
4373 const char *debug_fboattachment(GLenum attachment
)
4377 #define WINED3D_TO_STR(x) case x: return #x
4378 WINED3D_TO_STR(GL_COLOR_ATTACHMENT0
);
4379 WINED3D_TO_STR(GL_COLOR_ATTACHMENT1
);
4380 WINED3D_TO_STR(GL_COLOR_ATTACHMENT2
);
4381 WINED3D_TO_STR(GL_COLOR_ATTACHMENT3
);
4382 WINED3D_TO_STR(GL_COLOR_ATTACHMENT4
);
4383 WINED3D_TO_STR(GL_COLOR_ATTACHMENT5
);
4384 WINED3D_TO_STR(GL_COLOR_ATTACHMENT6
);
4385 WINED3D_TO_STR(GL_COLOR_ATTACHMENT7
);
4386 WINED3D_TO_STR(GL_COLOR_ATTACHMENT8
);
4387 WINED3D_TO_STR(GL_COLOR_ATTACHMENT9
);
4388 WINED3D_TO_STR(GL_COLOR_ATTACHMENT10
);
4389 WINED3D_TO_STR(GL_COLOR_ATTACHMENT11
);
4390 WINED3D_TO_STR(GL_COLOR_ATTACHMENT12
);
4391 WINED3D_TO_STR(GL_COLOR_ATTACHMENT13
);
4392 WINED3D_TO_STR(GL_COLOR_ATTACHMENT14
);
4393 WINED3D_TO_STR(GL_COLOR_ATTACHMENT15
);
4394 WINED3D_TO_STR(GL_DEPTH_ATTACHMENT
);
4395 WINED3D_TO_STR(GL_STENCIL_ATTACHMENT
);
4396 #undef WINED3D_TO_STR
4398 return wine_dbg_sprintf("Unknown FBO attachment %#x", attachment
);
4402 const char *debug_fbostatus(GLenum status
) {
4404 #define FBOSTATUS_TO_STR(u) case u: return #u
4405 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE
);
4406 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
);
4407 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
);
4408 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
);
4409 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
);
4410 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
);
4411 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
);
4412 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
);
4413 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
);
4414 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB
);
4415 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED
);
4416 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED
);
4417 #undef FBOSTATUS_TO_STR
4419 FIXME("Unrecognized FBO status 0x%08x.\n", status
);
4420 return "unrecognized";
4424 const char *debug_glerror(GLenum error
) {
4426 #define GLERROR_TO_STR(u) case u: return #u
4427 GLERROR_TO_STR(GL_NO_ERROR
);
4428 GLERROR_TO_STR(GL_INVALID_ENUM
);
4429 GLERROR_TO_STR(GL_INVALID_VALUE
);
4430 GLERROR_TO_STR(GL_INVALID_OPERATION
);
4431 GLERROR_TO_STR(GL_STACK_OVERFLOW
);
4432 GLERROR_TO_STR(GL_STACK_UNDERFLOW
);
4433 GLERROR_TO_STR(GL_OUT_OF_MEMORY
);
4434 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION
);
4435 #undef GLERROR_TO_STR
4437 FIXME("Unrecognized GL error 0x%08x.\n", error
);
4438 return "unrecognized";
4442 static const char *debug_fixup_channel_source(enum fixup_channel_source source
)
4446 #define WINED3D_TO_STR(x) case x: return #x
4447 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO
);
4448 WINED3D_TO_STR(CHANNEL_SOURCE_ONE
);
4449 WINED3D_TO_STR(CHANNEL_SOURCE_X
);
4450 WINED3D_TO_STR(CHANNEL_SOURCE_Y
);
4451 WINED3D_TO_STR(CHANNEL_SOURCE_Z
);
4452 WINED3D_TO_STR(CHANNEL_SOURCE_W
);
4453 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0
);
4454 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1
);
4455 #undef WINED3D_TO_STR
4457 FIXME("Unrecognized fixup_channel_source %#x\n", source
);
4458 return "unrecognized";
4462 static const char *debug_complex_fixup(enum complex_fixup fixup
)
4466 #define WINED3D_TO_STR(x) case x: return #x
4467 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2
);
4468 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY
);
4469 WINED3D_TO_STR(COMPLEX_FIXUP_YV12
);
4470 WINED3D_TO_STR(COMPLEX_FIXUP_NV12
);
4471 WINED3D_TO_STR(COMPLEX_FIXUP_P8
);
4472 #undef WINED3D_TO_STR
4474 FIXME("Unrecognized complex fixup %#x\n", fixup
);
4475 return "unrecognized";
4479 void dump_color_fixup_desc(struct color_fixup_desc fixup
)
4481 if (is_complex_fixup(fixup
))
4483 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup
)));
4487 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup
.x_source
), fixup
.x_sign_fixup
? ", SIGN_FIXUP" : "");
4488 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup
.y_source
), fixup
.y_sign_fixup
? ", SIGN_FIXUP" : "");
4489 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup
.z_source
), fixup
.z_sign_fixup
? ", SIGN_FIXUP" : "");
4490 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup
.w_source
), fixup
.w_sign_fixup
? ", SIGN_FIXUP" : "");
4493 BOOL
is_invalid_op(const struct wined3d_state
*state
, int stage
,
4494 enum wined3d_texture_op op
, DWORD arg1
, DWORD arg2
, DWORD arg3
)
4496 if (op
== WINED3D_TOP_DISABLE
)
4498 if (state
->textures
[stage
])
4501 if ((arg1
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
4502 && op
!= WINED3D_TOP_SELECT_ARG2
)
4504 if ((arg2
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
4505 && op
!= WINED3D_TOP_SELECT_ARG1
)
4507 if ((arg3
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
4508 && (op
== WINED3D_TOP_MULTIPLY_ADD
|| op
== WINED3D_TOP_LERP
))
4514 void get_identity_matrix(struct wined3d_matrix
*mat
)
4516 static const struct wined3d_matrix identity
=
4518 1.0f
, 0.0f
, 0.0f
, 0.0f
,
4519 0.0f
, 1.0f
, 0.0f
, 0.0f
,
4520 0.0f
, 0.0f
, 1.0f
, 0.0f
,
4521 0.0f
, 0.0f
, 0.0f
, 1.0f
,
4527 void get_modelview_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4528 unsigned int index
, struct wined3d_matrix
*mat
)
4530 if (context
->last_was_rhw
)
4531 get_identity_matrix(mat
);
4533 multiply_matrix(mat
, &state
->transforms
[WINED3D_TS_VIEW
], &state
->transforms
[WINED3D_TS_WORLD_MATRIX(index
)]);
4536 void get_projection_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4537 struct wined3d_matrix
*mat
)
4539 BOOL clip_control
= context
->gl_info
->supported
[ARB_CLIP_CONTROL
];
4540 BOOL flip
= !clip_control
&& context
->render_offscreen
;
4541 float center_offset
;
4543 /* There are a couple of additional things we have to take into account
4544 * here besides the projection transformation itself:
4545 * - We need to flip along the y-axis in case of offscreen rendering.
4546 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
4547 * - <= D3D9 coordinates refer to pixel centers while GL coordinates
4548 * refer to pixel corners.
4549 * - D3D has a top-left filling convention. We need to maintain this
4550 * even after the y-flip mentioned above.
4551 * In order to handle the last two points, we translate by
4552 * (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to
4553 * translating slightly less than half a pixel. We want the difference to
4554 * be large enough that it doesn't get lost due to rounding inside the
4555 * driver, but small enough to prevent it from interfering with any
4558 if (!clip_control
&& context
->d3d_info
->wined3d_creation_flags
& WINED3D_PIXEL_CENTER_INTEGER
)
4559 center_offset
= 63.0f
/ 64.0f
;
4561 center_offset
= -1.0f
/ 64.0f
;
4563 if (context
->last_was_rhw
)
4565 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
4566 float x
= state
->viewport
.x
;
4567 float y
= state
->viewport
.y
;
4568 float w
= state
->viewport
.width
;
4569 float h
= state
->viewport
.height
;
4570 float x_scale
= 2.0f
/ w
;
4571 float x_offset
= (center_offset
- (2.0f
* x
) - w
) / w
;
4572 float y_scale
= flip
? 2.0f
/ h
: 2.0f
/ -h
;
4573 float y_offset
= flip
4574 ? (center_offset
- (2.0f
* y
) - h
) / h
4575 : (center_offset
- (2.0f
* y
) - h
) / -h
;
4576 enum wined3d_depth_buffer_type zenable
= state
->fb
->depth_stencil
?
4577 state
->render_states
[WINED3D_RS_ZENABLE
] : WINED3D_ZB_FALSE
;
4578 float z_scale
= zenable
? clip_control
? 1.0f
: 2.0f
: 0.0f
;
4579 float z_offset
= zenable
? clip_control
? 0.0f
: -1.0f
: 0.0f
;
4580 const struct wined3d_matrix projection
=
4582 x_scale
, 0.0f
, 0.0f
, 0.0f
,
4583 0.0f
, y_scale
, 0.0f
, 0.0f
,
4584 0.0f
, 0.0f
, z_scale
, 0.0f
,
4585 x_offset
, y_offset
, z_offset
, 1.0f
,
4592 float y_scale
= flip
? -1.0f
: 1.0f
;
4593 float x_offset
= center_offset
/ state
->viewport
.width
;
4594 float y_offset
= flip
4595 ? center_offset
/ state
->viewport
.height
4596 : -center_offset
/ state
->viewport
.height
;
4597 float z_scale
= clip_control
? 1.0f
: 2.0f
;
4598 float z_offset
= clip_control
? 0.0f
: -1.0f
;
4599 const struct wined3d_matrix projection
=
4601 1.0f
, 0.0f
, 0.0f
, 0.0f
,
4602 0.0f
, y_scale
, 0.0f
, 0.0f
,
4603 0.0f
, 0.0f
, z_scale
, 0.0f
,
4604 x_offset
, y_offset
, z_offset
, 1.0f
,
4607 multiply_matrix(mat
, &projection
, &state
->transforms
[WINED3D_TS_PROJECTION
]);
4611 /* Setup this textures matrix according to the texture flags. */
4612 static void compute_texture_matrix(const struct wined3d_gl_info
*gl_info
, const struct wined3d_matrix
*matrix
,
4613 DWORD flags
, BOOL calculated_coords
, BOOL transformed
, enum wined3d_format_id format_id
,
4614 BOOL ffp_proj_control
, struct wined3d_matrix
*out_matrix
)
4616 struct wined3d_matrix mat
;
4618 if (flags
== WINED3D_TTFF_DISABLE
|| flags
== WINED3D_TTFF_COUNT1
|| transformed
)
4620 get_identity_matrix(out_matrix
);
4624 if (flags
== (WINED3D_TTFF_COUNT1
| WINED3D_TTFF_PROJECTED
))
4626 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
4632 if (flags
& WINED3D_TTFF_PROJECTED
)
4634 if (!ffp_proj_control
)
4636 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
4638 case WINED3D_TTFF_COUNT2
:
4643 mat
._12
= mat
._22
= mat
._32
= mat
._42
= 0.0f
;
4645 case WINED3D_TTFF_COUNT3
:
4650 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
4657 /* Under Direct3D the R/Z coord can be used for translation, under
4658 * OpenGL we use the Q coord instead. */
4659 if (!calculated_coords
)
4663 /* Direct3D passes the default 1.0 in the 2nd coord, while GL
4664 * passes it in the 4th. Swap 2nd and 4th coord. No need to
4665 * store the value of mat._41 in mat._21 because the input
4666 * value to the transformation will be 0, so the matrix value
4668 case WINED3DFMT_R32_FLOAT
:
4674 /* See above, just 3rd and 4th coord. */
4675 case WINED3DFMT_R32G32_FLOAT
:
4681 case WINED3DFMT_R32G32B32_FLOAT
: /* Opengl defaults match dx defaults */
4682 case WINED3DFMT_R32G32B32A32_FLOAT
: /* No defaults apply, all app defined */
4684 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
4685 * into a bad place. The division elimination below will apply to make sure the
4686 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
4688 case WINED3DFMT_UNKNOWN
: /* No texture coords, 0/0/0/1 defaults are passed */
4691 FIXME("Unexpected fixed function texture coord input\n");
4694 if (!ffp_proj_control
)
4696 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
4698 /* case WINED3D_TTFF_COUNT1: Won't ever get here. */
4699 case WINED3D_TTFF_COUNT2
:
4700 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
4701 /* OpenGL divides the first 3 vertex coordinates by the 4th by
4702 * default, which is essentially the same as D3DTTFF_PROJECTED.
4703 * Make sure that the 4th coordinate evaluates to 1.0 to
4706 * If the fixed function pipeline is used, the 4th value
4707 * remains unused, so there is no danger in doing this. With
4708 * vertex shaders we have a problem. Should an application hit
4709 * that problem, the code here would have to check for pixel
4710 * shaders, and the shader has to undo the default GL divide.
4712 * A more serious problem occurs if the application passes 4
4713 * coordinates in, and the 4th is != 1.0 (OpenGL default).
4714 * This would have to be fixed with immediate mode draws. */
4716 mat
._14
= mat
._24
= mat
._34
= 0.0f
; mat
._44
= 1.0f
;
4724 void get_texture_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4725 unsigned int tex
, struct wined3d_matrix
*mat
)
4727 const struct wined3d_device
*device
= context
->device
;
4728 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
4729 BOOL generated
= (state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
] & 0xffff0000)
4730 != WINED3DTSS_TCI_PASSTHRU
;
4731 unsigned int coord_idx
= min(state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
& 0x0000ffff],
4734 compute_texture_matrix(gl_info
, &state
->transforms
[WINED3D_TS_TEXTURE0
+ tex
],
4735 state
->texture_states
[tex
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
],
4736 generated
, context
->last_was_rhw
,
4737 context
->stream_info
.use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))
4738 ? context
->stream_info
.elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format
->id
4739 : WINED3DFMT_UNKNOWN
,
4740 device
->shader_backend
->shader_has_ffp_proj_control(device
->shader_priv
), mat
);
4742 if ((context
->lastWasPow2Texture
& (1u << tex
)) && state
->textures
[tex
])
4745 FIXME("Non-power-of-two texture being used with generated texture coords.\n");
4746 /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
4747 * fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
4750 TRACE("Non-power-of-two texture matrix multiply fixup.\n");
4751 multiply_matrix(mat
, mat
, (struct wined3d_matrix
*)state
->textures
[tex
]->pow2_matrix
);
4756 void get_pointsize_minmax(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4757 float *out_min
, float *out_max
)
4765 min
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MIN
];
4766 max
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MAX
];
4775 void get_pointsize(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4776 float *out_pointsize
, float *out_att
)
4778 /* POINTSCALEENABLE controls how point size value is treated. If set to
4779 * true, the point size is scaled with respect to height of viewport.
4780 * When set to false point size is in pixels. */
4785 } pointsize
, a
, b
, c
;
4791 pointsize
.d
= state
->render_states
[WINED3D_RS_POINTSIZE
];
4792 a
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_A
];
4793 b
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_B
];
4794 c
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_C
];
4796 if (state
->render_states
[WINED3D_RS_POINTSCALEENABLE
])
4798 float scale_factor
= state
->viewport
.height
* state
->viewport
.height
;
4800 out_att
[0] = a
.f
/ scale_factor
;
4801 out_att
[1] = b
.f
/ scale_factor
;
4802 out_att
[2] = c
.f
/ scale_factor
;
4804 *out_pointsize
= pointsize
.f
;
4807 void get_fog_start_end(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4808 float *start
, float *end
)
4816 switch (context
->fog_source
)
4823 case FOGSOURCE_COORD
:
4829 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGSTART
];
4830 *start
= tmpvalue
.f
;
4831 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGEND
];
4833 /* Special handling for fog_start == fog_end. In d3d with vertex
4834 * fog, everything is fogged. With table fog, everything with
4835 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
4836 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
4837 if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
&& *start
== *end
)
4845 /* This should not happen, context->fog_source is set in wined3d, not the app. */
4846 ERR("Unexpected fog coordinate source.\n");
4852 /* Note: It's the caller's responsibility to ensure values can be expressed
4853 * in the requested format. UNORM formats for example can only express values
4854 * in the range 0.0f -> 1.0f. */
4855 DWORD
wined3d_format_convert_from_float(const struct wined3d_format
*format
, const struct wined3d_color
*color
)
4859 enum wined3d_format_id format_id
;
4871 {WINED3DFMT_B8G8R8A8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
4872 {WINED3DFMT_B8G8R8X8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
4873 {WINED3DFMT_B8G8R8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
4874 {WINED3DFMT_B5G6R5_UNORM
, 31.0f
, 63.0f
, 31.0f
, 0.0f
, 11, 5, 0, 0},
4875 {WINED3DFMT_B5G5R5A1_UNORM
, 31.0f
, 31.0f
, 31.0f
, 1.0f
, 10, 5, 0, 15},
4876 {WINED3DFMT_B5G5R5X1_UNORM
, 31.0f
, 31.0f
, 31.0f
, 1.0f
, 10, 5, 0, 15},
4877 {WINED3DFMT_R8_UNORM
, 255.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 0, 0, 0},
4878 {WINED3DFMT_A8_UNORM
, 0.0f
, 0.0f
, 0.0f
, 255.0f
, 0, 0, 0, 0},
4879 {WINED3DFMT_B4G4R4A4_UNORM
, 15.0f
, 15.0f
, 15.0f
, 15.0f
, 8, 4, 0, 12},
4880 {WINED3DFMT_B4G4R4X4_UNORM
, 15.0f
, 15.0f
, 15.0f
, 15.0f
, 8, 4, 0, 12},
4881 {WINED3DFMT_B2G3R3_UNORM
, 7.0f
, 7.0f
, 3.0f
, 0.0f
, 5, 2, 0, 0},
4882 {WINED3DFMT_R8G8B8A8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 0, 8, 16, 24},
4883 {WINED3DFMT_R8G8B8X8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 0, 8, 16, 24},
4884 {WINED3DFMT_B10G10R10A2_UNORM
, 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
, 20, 10, 0, 30},
4885 {WINED3DFMT_R10G10B10A2_UNORM
, 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
, 0, 10, 20, 30},
4886 {WINED3DFMT_P8_UINT
, 0.0f
, 0.0f
, 0.0f
, 255.0f
, 0, 0, 0, 0},
4890 TRACE("Converting color %s to format %s.\n", debug_color(color
), debug_d3dformat(format
->id
));
4892 for (i
= 0; i
< sizeof(conv
) / sizeof(*conv
); ++i
)
4896 if (format
->id
!= conv
[i
].format_id
) continue;
4898 ret
= ((DWORD
)((color
->r
* conv
[i
].r_mul
) + 0.5f
)) << conv
[i
].r_shift
;
4899 ret
|= ((DWORD
)((color
->g
* conv
[i
].g_mul
) + 0.5f
)) << conv
[i
].g_shift
;
4900 ret
|= ((DWORD
)((color
->b
* conv
[i
].b_mul
) + 0.5f
)) << conv
[i
].b_shift
;
4901 ret
|= ((DWORD
)((color
->a
* conv
[i
].a_mul
) + 0.5f
)) << conv
[i
].a_shift
;
4903 TRACE("Returning 0x%08x.\n", ret
);
4908 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format
->id
));
4913 static float color_to_float(DWORD color
, DWORD size
, DWORD offset
)
4915 DWORD mask
= (1u << size
) - 1;
4923 return (float)color
/ (float)mask
;
4926 BOOL
wined3d_format_convert_color_to_float(const struct wined3d_format
*format
,
4927 const struct wined3d_palette
*palette
, DWORD color
, struct wined3d_color
*float_color
)
4931 case WINED3DFMT_B8G8R8_UNORM
:
4932 case WINED3DFMT_B8G8R8A8_UNORM
:
4933 case WINED3DFMT_B8G8R8X8_UNORM
:
4934 case WINED3DFMT_B5G6R5_UNORM
:
4935 case WINED3DFMT_B5G5R5X1_UNORM
:
4936 case WINED3DFMT_B5G5R5A1_UNORM
:
4937 case WINED3DFMT_B4G4R4A4_UNORM
:
4938 case WINED3DFMT_B2G3R3_UNORM
:
4939 case WINED3DFMT_R8_UNORM
:
4940 case WINED3DFMT_A8_UNORM
:
4941 case WINED3DFMT_B2G3R3A8_UNORM
:
4942 case WINED3DFMT_B4G4R4X4_UNORM
:
4943 case WINED3DFMT_R10G10B10A2_UNORM
:
4944 case WINED3DFMT_R10G10B10A2_SNORM
:
4945 case WINED3DFMT_R8G8B8A8_UNORM
:
4946 case WINED3DFMT_R8G8B8X8_UNORM
:
4947 case WINED3DFMT_R16G16_UNORM
:
4948 case WINED3DFMT_B10G10R10A2_UNORM
:
4949 float_color
->r
= color_to_float(color
, format
->red_size
, format
->red_offset
);
4950 float_color
->g
= color_to_float(color
, format
->green_size
, format
->green_offset
);
4951 float_color
->b
= color_to_float(color
, format
->blue_size
, format
->blue_offset
);
4952 float_color
->a
= color_to_float(color
, format
->alpha_size
, format
->alpha_offset
);
4955 case WINED3DFMT_P8_UINT
:
4958 float_color
->r
= palette
->colors
[color
].rgbRed
/ 255.0f
;
4959 float_color
->g
= palette
->colors
[color
].rgbGreen
/ 255.0f
;
4960 float_color
->b
= palette
->colors
[color
].rgbBlue
/ 255.0f
;
4964 float_color
->r
= 0.0f
;
4965 float_color
->g
= 0.0f
;
4966 float_color
->b
= 0.0f
;
4968 float_color
->a
= color
/ 255.0f
;
4972 ERR("Unhandled conversion from %s to floating point.\n", debug_d3dformat(format
->id
));
4977 void wined3d_format_get_float_color_key(const struct wined3d_format
*format
,
4978 const struct wined3d_color_key
*key
, struct wined3d_color
*float_colors
)
4980 struct wined3d_color slop
;
4984 case WINED3DFMT_B8G8R8_UNORM
:
4985 case WINED3DFMT_B8G8R8A8_UNORM
:
4986 case WINED3DFMT_B8G8R8X8_UNORM
:
4987 case WINED3DFMT_B5G6R5_UNORM
:
4988 case WINED3DFMT_B5G5R5X1_UNORM
:
4989 case WINED3DFMT_B5G5R5A1_UNORM
:
4990 case WINED3DFMT_B4G4R4A4_UNORM
:
4991 case WINED3DFMT_B2G3R3_UNORM
:
4992 case WINED3DFMT_R8_UNORM
:
4993 case WINED3DFMT_A8_UNORM
:
4994 case WINED3DFMT_B2G3R3A8_UNORM
:
4995 case WINED3DFMT_B4G4R4X4_UNORM
:
4996 case WINED3DFMT_R10G10B10A2_UNORM
:
4997 case WINED3DFMT_R10G10B10A2_SNORM
:
4998 case WINED3DFMT_R8G8B8A8_UNORM
:
4999 case WINED3DFMT_R8G8B8X8_UNORM
:
5000 case WINED3DFMT_R16G16_UNORM
:
5001 case WINED3DFMT_B10G10R10A2_UNORM
:
5002 slop
.r
= 0.5f
/ ((1u << format
->red_size
) - 1);
5003 slop
.g
= 0.5f
/ ((1u << format
->green_size
) - 1);
5004 slop
.b
= 0.5f
/ ((1u << format
->blue_size
) - 1);
5005 slop
.a
= 0.5f
/ ((1u << format
->alpha_size
) - 1);
5007 float_colors
[0].r
= color_to_float(key
->color_space_low_value
, format
->red_size
, format
->red_offset
)
5009 float_colors
[0].g
= color_to_float(key
->color_space_low_value
, format
->green_size
, format
->green_offset
)
5011 float_colors
[0].b
= color_to_float(key
->color_space_low_value
, format
->blue_size
, format
->blue_offset
)
5013 float_colors
[0].a
= color_to_float(key
->color_space_low_value
, format
->alpha_size
, format
->alpha_offset
)
5016 float_colors
[1].r
= color_to_float(key
->color_space_high_value
, format
->red_size
, format
->red_offset
)
5018 float_colors
[1].g
= color_to_float(key
->color_space_high_value
, format
->green_size
, format
->green_offset
)
5020 float_colors
[1].b
= color_to_float(key
->color_space_high_value
, format
->blue_size
, format
->blue_offset
)
5022 float_colors
[1].a
= color_to_float(key
->color_space_high_value
, format
->alpha_size
, format
->alpha_offset
)
5026 case WINED3DFMT_P8_UINT
:
5027 float_colors
[0].r
= 0.0f
;
5028 float_colors
[0].g
= 0.0f
;
5029 float_colors
[0].b
= 0.0f
;
5030 float_colors
[0].a
= (key
->color_space_low_value
- 0.5f
) / 255.0f
;
5032 float_colors
[1].r
= 0.0f
;
5033 float_colors
[1].g
= 0.0f
;
5034 float_colors
[1].b
= 0.0f
;
5035 float_colors
[1].a
= (key
->color_space_high_value
+ 0.5f
) / 255.0f
;
5039 ERR("Unhandled color key to float conversion for format %s.\n", debug_d3dformat(format
->id
));
5043 /* DirectDraw stuff */
5044 enum wined3d_format_id
pixelformat_for_depth(DWORD depth
)
5048 case 8: return WINED3DFMT_P8_UINT
;
5049 case 15: return WINED3DFMT_B5G5R5X1_UNORM
;
5050 case 16: return WINED3DFMT_B5G6R5_UNORM
;
5051 case 24: return WINED3DFMT_B8G8R8X8_UNORM
; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
5052 case 32: return WINED3DFMT_B8G8R8X8_UNORM
; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
5053 default: return WINED3DFMT_UNKNOWN
;
5057 void multiply_matrix(struct wined3d_matrix
*dst
, const struct wined3d_matrix
*src1
, const struct wined3d_matrix
*src2
)
5059 struct wined3d_matrix tmp
;
5061 /* Now do the multiplication 'by hand'.
5062 I know that all this could be optimised, but this will be done later :-) */
5063 tmp
._11
= (src1
->_11
* src2
->_11
) + (src1
->_21
* src2
->_12
) + (src1
->_31
* src2
->_13
) + (src1
->_41
* src2
->_14
);
5064 tmp
._21
= (src1
->_11
* src2
->_21
) + (src1
->_21
* src2
->_22
) + (src1
->_31
* src2
->_23
) + (src1
->_41
* src2
->_24
);
5065 tmp
._31
= (src1
->_11
* src2
->_31
) + (src1
->_21
* src2
->_32
) + (src1
->_31
* src2
->_33
) + (src1
->_41
* src2
->_34
);
5066 tmp
._41
= (src1
->_11
* src2
->_41
) + (src1
->_21
* src2
->_42
) + (src1
->_31
* src2
->_43
) + (src1
->_41
* src2
->_44
);
5068 tmp
._12
= (src1
->_12
* src2
->_11
) + (src1
->_22
* src2
->_12
) + (src1
->_32
* src2
->_13
) + (src1
->_42
* src2
->_14
);
5069 tmp
._22
= (src1
->_12
* src2
->_21
) + (src1
->_22
* src2
->_22
) + (src1
->_32
* src2
->_23
) + (src1
->_42
* src2
->_24
);
5070 tmp
._32
= (src1
->_12
* src2
->_31
) + (src1
->_22
* src2
->_32
) + (src1
->_32
* src2
->_33
) + (src1
->_42
* src2
->_34
);
5071 tmp
._42
= (src1
->_12
* src2
->_41
) + (src1
->_22
* src2
->_42
) + (src1
->_32
* src2
->_43
) + (src1
->_42
* src2
->_44
);
5073 tmp
._13
= (src1
->_13
* src2
->_11
) + (src1
->_23
* src2
->_12
) + (src1
->_33
* src2
->_13
) + (src1
->_43
* src2
->_14
);
5074 tmp
._23
= (src1
->_13
* src2
->_21
) + (src1
->_23
* src2
->_22
) + (src1
->_33
* src2
->_23
) + (src1
->_43
* src2
->_24
);
5075 tmp
._33
= (src1
->_13
* src2
->_31
) + (src1
->_23
* src2
->_32
) + (src1
->_33
* src2
->_33
) + (src1
->_43
* src2
->_34
);
5076 tmp
._43
= (src1
->_13
* src2
->_41
) + (src1
->_23
* src2
->_42
) + (src1
->_33
* src2
->_43
) + (src1
->_43
* src2
->_44
);
5078 tmp
._14
= (src1
->_14
* src2
->_11
) + (src1
->_24
* src2
->_12
) + (src1
->_34
* src2
->_13
) + (src1
->_44
* src2
->_14
);
5079 tmp
._24
= (src1
->_14
* src2
->_21
) + (src1
->_24
* src2
->_22
) + (src1
->_34
* src2
->_23
) + (src1
->_44
* src2
->_24
);
5080 tmp
._34
= (src1
->_14
* src2
->_31
) + (src1
->_24
* src2
->_32
) + (src1
->_34
* src2
->_33
) + (src1
->_44
* src2
->_34
);
5081 tmp
._44
= (src1
->_14
* src2
->_41
) + (src1
->_24
* src2
->_42
) + (src1
->_34
* src2
->_43
) + (src1
->_44
* src2
->_44
);
5086 DWORD
get_flexible_vertex_size(DWORD d3dvtVertexType
) {
5089 int numTextures
= (d3dvtVertexType
& WINED3DFVF_TEXCOUNT_MASK
) >> WINED3DFVF_TEXCOUNT_SHIFT
;
5091 if (d3dvtVertexType
& WINED3DFVF_NORMAL
) size
+= 3 * sizeof(float);
5092 if (d3dvtVertexType
& WINED3DFVF_DIFFUSE
) size
+= sizeof(DWORD
);
5093 if (d3dvtVertexType
& WINED3DFVF_SPECULAR
) size
+= sizeof(DWORD
);
5094 if (d3dvtVertexType
& WINED3DFVF_PSIZE
) size
+= sizeof(DWORD
);
5095 switch (d3dvtVertexType
& WINED3DFVF_POSITION_MASK
) {
5096 case WINED3DFVF_XYZ
: size
+= 3 * sizeof(float); break;
5097 case WINED3DFVF_XYZRHW
: size
+= 4 * sizeof(float); break;
5098 case WINED3DFVF_XYZB1
: size
+= 4 * sizeof(float); break;
5099 case WINED3DFVF_XYZB2
: size
+= 5 * sizeof(float); break;
5100 case WINED3DFVF_XYZB3
: size
+= 6 * sizeof(float); break;
5101 case WINED3DFVF_XYZB4
: size
+= 7 * sizeof(float); break;
5102 case WINED3DFVF_XYZB5
: size
+= 8 * sizeof(float); break;
5103 case WINED3DFVF_XYZW
: size
+= 4 * sizeof(float); break;
5104 default: ERR("Unexpected position mask\n");
5106 for (i
= 0; i
< numTextures
; i
++) {
5107 size
+= GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType
, i
) * sizeof(float);
5113 unsigned int wined3d_max_compat_varyings(const struct wined3d_gl_info
*gl_info
)
5115 /* On core profile we have to also count diffuse and specular colors and the
5116 * fog coordinate. */
5117 return gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? MAX_TEXTURES
* 4 : (MAX_TEXTURES
+ 2) * 4 + 1;
5120 void gen_ffp_frag_op(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
5121 struct ffp_frag_settings
*settings
, BOOL ignore_textype
)
5126 static const unsigned char args
[WINED3D_TOP_LERP
+ 1] =
5129 /* D3DTOP_DISABLE */ 0,
5130 /* D3DTOP_SELECTARG1 */ ARG1
,
5131 /* D3DTOP_SELECTARG2 */ ARG2
,
5132 /* D3DTOP_MODULATE */ ARG1
| ARG2
,
5133 /* D3DTOP_MODULATE2X */ ARG1
| ARG2
,
5134 /* D3DTOP_MODULATE4X */ ARG1
| ARG2
,
5135 /* D3DTOP_ADD */ ARG1
| ARG2
,
5136 /* D3DTOP_ADDSIGNED */ ARG1
| ARG2
,
5137 /* D3DTOP_ADDSIGNED2X */ ARG1
| ARG2
,
5138 /* D3DTOP_SUBTRACT */ ARG1
| ARG2
,
5139 /* D3DTOP_ADDSMOOTH */ ARG1
| ARG2
,
5140 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1
| ARG2
,
5141 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1
| ARG2
,
5142 /* D3DTOP_BLENDFACTORALPHA */ ARG1
| ARG2
,
5143 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1
| ARG2
,
5144 /* D3DTOP_BLENDCURRENTALPHA */ ARG1
| ARG2
,
5145 /* D3DTOP_PREMODULATE */ ARG1
| ARG2
,
5146 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1
| ARG2
,
5147 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1
| ARG2
,
5148 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1
| ARG2
,
5149 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1
| ARG2
,
5150 /* D3DTOP_BUMPENVMAP */ ARG1
| ARG2
,
5151 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1
| ARG2
,
5152 /* D3DTOP_DOTPRODUCT3 */ ARG1
| ARG2
,
5153 /* D3DTOP_MULTIPLYADD */ ARG1
| ARG2
| ARG0
,
5154 /* D3DTOP_LERP */ ARG1
| ARG2
| ARG0
5158 DWORD cop
, aop
, carg0
, carg1
, carg2
, aarg0
, aarg1
, aarg2
;
5159 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
5160 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
5162 settings
->padding
= 0;
5164 for (i
= 0; i
< d3d_info
->limits
.ffp_blend_stages
; ++i
)
5166 const struct wined3d_texture
*texture
;
5168 settings
->op
[i
].padding
= 0;
5169 if (state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
] == WINED3D_TOP_DISABLE
)
5171 settings
->op
[i
].cop
= WINED3D_TOP_DISABLE
;
5172 settings
->op
[i
].aop
= WINED3D_TOP_DISABLE
;
5173 settings
->op
[i
].carg0
= settings
->op
[i
].carg1
= settings
->op
[i
].carg2
= ARG_UNUSED
;
5174 settings
->op
[i
].aarg0
= settings
->op
[i
].aarg1
= settings
->op
[i
].aarg2
= ARG_UNUSED
;
5175 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
5176 settings
->op
[i
].dst
= resultreg
;
5177 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
5178 settings
->op
[i
].projected
= proj_none
;
5183 if ((texture
= state
->textures
[i
]))
5185 if (can_use_texture_swizzle(gl_info
, texture
->resource
.format
))
5186 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
5188 settings
->op
[i
].color_fixup
= texture
->resource
.format
->color_fixup
;
5191 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
5195 switch (texture
->target
)
5198 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
5201 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_2D
;
5204 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_3D
;
5206 case GL_TEXTURE_CUBE_MAP_ARB
:
5207 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_CUBE
;
5209 case GL_TEXTURE_RECTANGLE_ARB
:
5210 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_RECT
;
5215 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
5216 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
5219 cop
= state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
];
5220 aop
= state
->texture_states
[i
][WINED3D_TSS_ALPHA_OP
];
5222 carg1
= (args
[cop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG1
] : ARG_UNUSED
;
5223 carg2
= (args
[cop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG2
] : ARG_UNUSED
;
5224 carg0
= (args
[cop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG0
] : ARG_UNUSED
;
5226 if (is_invalid_op(state
, i
, cop
, carg1
, carg2
, carg0
))
5230 carg1
= WINED3DTA_CURRENT
;
5231 cop
= WINED3D_TOP_SELECT_ARG1
;
5234 if (cop
== WINED3D_TOP_DOTPRODUCT3
)
5236 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
5237 * the color result to the alpha component of the destination
5246 aarg1
= (args
[aop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG1
] : ARG_UNUSED
;
5247 aarg2
= (args
[aop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG2
] : ARG_UNUSED
;
5248 aarg0
= (args
[aop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG0
] : ARG_UNUSED
;
5251 if (!i
&& state
->textures
[0] && state
->render_states
[WINED3D_RS_COLORKEYENABLE
])
5253 GLenum texture_dimensions
;
5255 texture
= state
->textures
[0];
5256 texture_dimensions
= texture
->target
;
5258 if (texture_dimensions
== GL_TEXTURE_2D
|| texture_dimensions
== GL_TEXTURE_RECTANGLE_ARB
)
5260 if (texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
&& !texture
->resource
.format
->alpha_size
)
5262 if (aop
== WINED3D_TOP_DISABLE
)
5264 aarg1
= WINED3DTA_TEXTURE
;
5265 aop
= WINED3D_TOP_SELECT_ARG1
;
5267 else if (aop
== WINED3D_TOP_SELECT_ARG1
&& aarg1
!= WINED3DTA_TEXTURE
)
5269 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
])
5271 aarg2
= WINED3DTA_TEXTURE
;
5272 aop
= WINED3D_TOP_MODULATE
;
5274 else aarg1
= WINED3DTA_TEXTURE
;
5276 else if (aop
== WINED3D_TOP_SELECT_ARG2
&& aarg2
!= WINED3DTA_TEXTURE
)
5278 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
])
5280 aarg1
= WINED3DTA_TEXTURE
;
5281 aop
= WINED3D_TOP_MODULATE
;
5283 else aarg2
= WINED3DTA_TEXTURE
;
5289 if (is_invalid_op(state
, i
, aop
, aarg1
, aarg2
, aarg0
))
5293 aarg1
= WINED3DTA_CURRENT
;
5294 aop
= WINED3D_TOP_SELECT_ARG1
;
5297 if (carg1
== WINED3DTA_TEXTURE
|| carg2
== WINED3DTA_TEXTURE
|| carg0
== WINED3DTA_TEXTURE
5298 || aarg1
== WINED3DTA_TEXTURE
|| aarg2
== WINED3DTA_TEXTURE
|| aarg0
== WINED3DTA_TEXTURE
)
5300 ttff
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
5301 if (ttff
== (WINED3D_TTFF_PROJECTED
| WINED3D_TTFF_COUNT3
))
5302 settings
->op
[i
].projected
= proj_count3
;
5303 else if (ttff
& WINED3D_TTFF_PROJECTED
)
5304 settings
->op
[i
].projected
= proj_count4
;
5306 settings
->op
[i
].projected
= proj_none
;
5310 settings
->op
[i
].projected
= proj_none
;
5313 settings
->op
[i
].cop
= cop
;
5314 settings
->op
[i
].aop
= aop
;
5315 settings
->op
[i
].carg0
= carg0
;
5316 settings
->op
[i
].carg1
= carg1
;
5317 settings
->op
[i
].carg2
= carg2
;
5318 settings
->op
[i
].aarg0
= aarg0
;
5319 settings
->op
[i
].aarg1
= aarg1
;
5320 settings
->op
[i
].aarg2
= aarg2
;
5322 if (state
->texture_states
[i
][WINED3D_TSS_RESULT_ARG
] == WINED3DTA_TEMP
)
5323 settings
->op
[i
].dst
= tempreg
;
5325 settings
->op
[i
].dst
= resultreg
;
5328 /* Clear unsupported stages */
5329 for(; i
< MAX_TEXTURES
; i
++) {
5330 memset(&settings
->op
[i
], 0xff, sizeof(settings
->op
[i
]));
5333 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
5335 settings
->fog
= WINED3D_FFP_PS_FOG_OFF
;
5337 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
)
5339 if (use_vs(state
) || state
->vertex_declaration
->position_transformed
)
5341 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
5345 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
5347 case WINED3D_FOG_NONE
:
5348 case WINED3D_FOG_LINEAR
:
5349 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
5351 case WINED3D_FOG_EXP
:
5352 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
5354 case WINED3D_FOG_EXP2
:
5355 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
5362 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
5364 case WINED3D_FOG_LINEAR
:
5365 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
5367 case WINED3D_FOG_EXP
:
5368 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
5370 case WINED3D_FOG_EXP2
:
5371 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
5375 settings
->sRGB_write
= !gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && needs_srgb_write(context
, state
, state
->fb
);
5376 if (d3d_info
->vs_clipping
|| !use_vs(state
) || !state
->render_states
[WINED3D_RS_CLIPPING
]
5377 || !state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
])
5379 /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
5380 * the fixed function vertex pipeline is used(which always supports clipplanes), or
5381 * if no clipplane is enabled
5383 settings
->emul_clipplanes
= 0;
5385 settings
->emul_clipplanes
= 1;
5388 if (state
->render_states
[WINED3D_RS_COLORKEYENABLE
] && state
->textures
[0]
5389 && state
->textures
[0]->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
5390 && settings
->op
[0].cop
!= WINED3D_TOP_DISABLE
)
5391 settings
->color_key_enabled
= 1;
5393 settings
->color_key_enabled
= 0;
5395 /* texcoords_initialized is set to meaningful values only when GL doesn't
5396 * support enough varyings to always pass around all the possible texture
5398 * This is used to avoid reading a varying not written by the vertex shader.
5399 * Reading uninitialized varyings on core profile contexts results in an
5400 * error while with builtin varyings on legacy contexts you get undefined
5402 if (d3d_info
->limits
.varying_count
5403 && d3d_info
->limits
.varying_count
< wined3d_max_compat_varyings(gl_info
))
5405 settings
->texcoords_initialized
= 0;
5406 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
5410 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
5411 settings
->texcoords_initialized
|= 1u << i
;
5415 const struct wined3d_stream_info
*si
= &context
->stream_info
;
5416 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5417 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
5418 & WINED3D_FFP_TCI_MASK
5419 || (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
5420 settings
->texcoords_initialized
|= 1u << i
;
5426 settings
->texcoords_initialized
= (1u << MAX_TEXTURES
) - 1;
5429 settings
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
5430 && state
->gl_primitive_type
== GL_POINTS
;
5432 if (gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
5433 settings
->alpha_test_func
= WINED3D_CMP_ALWAYS
- 1;
5435 settings
->alpha_test_func
= (state
->render_states
[WINED3D_RS_ALPHATESTENABLE
]
5436 ? wined3d_sanitize_cmp_func(state
->render_states
[WINED3D_RS_ALPHAFUNC
])
5437 : WINED3D_CMP_ALWAYS
) - 1;
5439 if (d3d_info
->emulated_flatshading
)
5440 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
5442 settings
->flatshading
= FALSE
;
5445 const struct ffp_frag_desc
*find_ffp_frag_shader(const struct wine_rb_tree
*fragment_shaders
,
5446 const struct ffp_frag_settings
*settings
)
5448 struct wine_rb_entry
*entry
= wine_rb_get(fragment_shaders
, settings
);
5449 return entry
? WINE_RB_ENTRY_VALUE(entry
, struct ffp_frag_desc
, entry
) : NULL
;
5452 void add_ffp_frag_shader(struct wine_rb_tree
*shaders
, struct ffp_frag_desc
*desc
)
5454 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
5455 * whereas desc points to an extended structure with implementation specific parts. */
5456 if (wine_rb_put(shaders
, &desc
->settings
, &desc
->entry
) == -1)
5458 ERR("Failed to insert ffp frag shader.\n");
5462 /* Activates the texture dimension according to the bound D3D texture. Does
5463 * not care for the colorop or correct gl texture unit (when using nvrc).
5464 * Requires the caller to activate the correct unit. */
5465 /* Context activation is done by the caller (state handler). */
5466 void texture_activate_dimensions(const struct wined3d_texture
*texture
, const struct wined3d_gl_info
*gl_info
)
5470 switch (texture
->target
)
5473 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5474 checkGLcall("glDisable(GL_TEXTURE_3D)");
5475 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5477 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5478 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5480 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5482 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5483 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5485 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
5486 checkGLcall("glEnable(GL_TEXTURE_2D)");
5488 case GL_TEXTURE_RECTANGLE_ARB
:
5489 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
5490 checkGLcall("glDisable(GL_TEXTURE_2D)");
5491 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5492 checkGLcall("glDisable(GL_TEXTURE_3D)");
5493 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5495 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5496 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5498 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_RECTANGLE_ARB
);
5499 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
5502 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5504 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5505 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5507 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5509 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5510 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5512 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
5513 checkGLcall("glDisable(GL_TEXTURE_2D)");
5514 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_3D
);
5515 checkGLcall("glEnable(GL_TEXTURE_3D)");
5517 case GL_TEXTURE_CUBE_MAP_ARB
:
5518 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
5519 checkGLcall("glDisable(GL_TEXTURE_2D)");
5520 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5521 checkGLcall("glDisable(GL_TEXTURE_3D)");
5522 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5524 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5525 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5527 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
5528 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
5534 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
5535 checkGLcall("glEnable(GL_TEXTURE_2D)");
5536 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5537 checkGLcall("glDisable(GL_TEXTURE_3D)");
5538 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5540 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5541 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5543 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5545 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5546 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5548 /* Binding textures is done by samplers. A dummy texture will be bound */
5552 /* Context activation is done by the caller (state handler). */
5553 void sampler_texdim(struct wined3d_context
*context
, const struct wined3d_state
*state
, DWORD state_id
)
5555 DWORD sampler
= state_id
- STATE_SAMPLER(0);
5556 DWORD mapped_stage
= context
->tex_unit_map
[sampler
];
5558 /* No need to enable / disable anything here for unused samplers. The
5559 * tex_colorop handler takes care. Also no action is needed with pixel
5560 * shaders, or if tex_colorop will take care of this business. */
5561 if (mapped_stage
== WINED3D_UNMAPPED_STAGE
|| mapped_stage
>= context
->gl_info
->limits
.textures
)
5563 if (sampler
>= context
->lowest_disabled_stage
)
5565 if (isStateDirty(context
, STATE_TEXTURESTAGE(sampler
, WINED3D_TSS_COLOR_OP
)))
5568 texture_activate_dimensions(state
->textures
[sampler
], context
->gl_info
);
5571 int wined3d_ffp_frag_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
5573 const struct ffp_frag_settings
*ka
= key
;
5574 const struct ffp_frag_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
, const struct ffp_frag_desc
, entry
)->settings
;
5576 return memcmp(ka
, kb
, sizeof(*ka
));
5579 void wined3d_ffp_get_vs_settings(const struct wined3d_context
*context
,
5580 const struct wined3d_state
*state
, struct wined3d_ffp_vs_settings
*settings
)
5582 const struct wined3d_stream_info
*si
= &context
->stream_info
;
5583 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
5584 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
5585 unsigned int coord_idx
, i
;
5587 if (si
->position_transformed
)
5589 memset(settings
, 0, sizeof(*settings
));
5591 settings
->transformed
= 1;
5592 settings
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
5593 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
5594 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
5595 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
5596 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
5597 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
5599 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
5601 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
5603 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5604 if (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
5605 settings
->texcoords
|= 1u << i
;
5606 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5608 if (d3d_info
->limits
.varying_count
>= wined3d_max_compat_varyings(gl_info
))
5609 settings
->texcoords
= (1u << MAX_TEXTURES
) - 1;
5611 if (d3d_info
->emulated_flatshading
)
5612 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
5614 settings
->flatshading
= FALSE
;
5616 settings
->swizzle_map
= si
->swizzle_map
;
5621 switch (state
->render_states
[WINED3D_RS_VERTEXBLEND
])
5623 case WINED3D_VBF_DISABLE
:
5624 case WINED3D_VBF_1WEIGHTS
:
5625 case WINED3D_VBF_2WEIGHTS
:
5626 case WINED3D_VBF_3WEIGHTS
:
5627 settings
->vertexblends
= state
->render_states
[WINED3D_RS_VERTEXBLEND
];
5630 FIXME("Unsupported vertex blending: %d\n", state
->render_states
[WINED3D_RS_VERTEXBLEND
]);
5634 settings
->transformed
= 0;
5635 settings
->clipping
= state
->render_states
[WINED3D_RS_CLIPPING
]
5636 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
5637 settings
->normal
= !!(si
->use_map
& (1u << WINED3D_FFP_NORMAL
));
5638 settings
->normalize
= settings
->normal
&& state
->render_states
[WINED3D_RS_NORMALIZENORMALS
];
5639 settings
->lighting
= !!state
->render_states
[WINED3D_RS_LIGHTING
];
5640 settings
->localviewer
= !!state
->render_states
[WINED3D_RS_LOCALVIEWER
];
5641 settings
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
5642 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
5644 if (state
->render_states
[WINED3D_RS_COLORVERTEX
] && (si
->use_map
& (1u << WINED3D_FFP_DIFFUSE
)))
5646 settings
->diffuse_source
= state
->render_states
[WINED3D_RS_DIFFUSEMATERIALSOURCE
];
5647 settings
->emissive_source
= state
->render_states
[WINED3D_RS_EMISSIVEMATERIALSOURCE
];
5648 settings
->ambient_source
= state
->render_states
[WINED3D_RS_AMBIENTMATERIALSOURCE
];
5649 settings
->specular_source
= state
->render_states
[WINED3D_RS_SPECULARMATERIALSOURCE
];
5653 settings
->diffuse_source
= WINED3D_MCS_MATERIAL
;
5654 settings
->emissive_source
= WINED3D_MCS_MATERIAL
;
5655 settings
->ambient_source
= WINED3D_MCS_MATERIAL
;
5656 settings
->specular_source
= WINED3D_MCS_MATERIAL
;
5659 settings
->texcoords
= 0;
5660 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
5662 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5663 if (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
5664 settings
->texcoords
|= 1u << i
;
5665 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5667 if (d3d_info
->limits
.varying_count
>= wined3d_max_compat_varyings(gl_info
))
5668 settings
->texcoords
= (1u << MAX_TEXTURES
) - 1;
5670 settings
->light_type
= 0;
5671 for (i
= 0; i
< MAX_ACTIVE_LIGHTS
; ++i
)
5673 if (state
->lights
[i
])
5674 settings
->light_type
|= (state
->lights
[i
]->OriginalParms
.type
5675 & WINED3D_FFP_LIGHT_TYPE_MASK
) << WINED3D_FFP_LIGHT_TYPE_SHIFT(i
);
5678 settings
->ortho_fog
= 0;
5679 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
5680 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
5681 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
5683 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
5685 if (state
->transforms
[WINED3D_TS_PROJECTION
]._14
== 0.0f
5686 && state
->transforms
[WINED3D_TS_PROJECTION
]._24
== 0.0f
5687 && state
->transforms
[WINED3D_TS_PROJECTION
]._34
== 0.0f
5688 && state
->transforms
[WINED3D_TS_PROJECTION
]._44
== 1.0f
)
5689 settings
->ortho_fog
= 1;
5691 else if (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
] == WINED3D_FOG_NONE
)
5692 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
5693 else if (state
->render_states
[WINED3D_RS_RANGEFOGENABLE
])
5694 settings
->fog_mode
= WINED3D_FFP_VS_FOG_RANGE
;
5696 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
5698 if (d3d_info
->emulated_flatshading
)
5699 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
5701 settings
->flatshading
= FALSE
;
5703 settings
->swizzle_map
= si
->swizzle_map
;
5705 settings
->padding
= 0;
5708 int wined3d_ffp_vertex_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
5710 const struct wined3d_ffp_vs_settings
*ka
= key
;
5711 const struct wined3d_ffp_vs_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
,
5712 const struct wined3d_ffp_vs_desc
, entry
)->settings
;
5714 return memcmp(ka
, kb
, sizeof(*ka
));
5717 const struct blit_shader
*wined3d_select_blitter(const struct wined3d_gl_info
*gl_info
,
5718 const struct wined3d_d3d_info
*d3d_info
, enum wined3d_blit_op blit_op
,
5719 const RECT
*src_rect
, DWORD src_usage
, enum wined3d_pool src_pool
, const struct wined3d_format
*src_format
,
5720 const RECT
*dst_rect
, DWORD dst_usage
, enum wined3d_pool dst_pool
, const struct wined3d_format
*dst_format
)
5722 static const struct blit_shader
* const blitters
[] =
5730 for (i
= 0; i
< sizeof(blitters
) / sizeof(*blitters
); ++i
)
5732 if (blitters
[i
]->blit_supported(gl_info
, d3d_info
, blit_op
,
5733 src_rect
, src_usage
, src_pool
, src_format
,
5734 dst_rect
, dst_usage
, dst_pool
, dst_format
))
5741 void wined3d_get_draw_rect(const struct wined3d_state
*state
, RECT
*rect
)
5743 const struct wined3d_viewport
*vp
= &state
->viewport
;
5745 SetRect(rect
, vp
->x
, vp
->y
, vp
->x
+ vp
->width
, vp
->y
+ vp
->height
);
5747 if (state
->render_states
[WINED3D_RS_SCISSORTESTENABLE
])
5748 IntersectRect(rect
, rect
, &state
->scissor_rect
);
5751 const char *wined3d_debug_location(DWORD location
)
5753 const char *prefix
= "";
5754 const char *suffix
= "";
5757 if (wined3d_popcount(location
) > 16)
5760 location
= ~location
;
5765 #define LOCATION_TO_STR(u) if (location & u) { strcat(buf, " | "#u); location &= ~u; }
5766 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED
);
5767 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM
);
5768 LOCATION_TO_STR(WINED3D_LOCATION_USER_MEMORY
);
5769 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER
);
5770 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB
);
5771 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB
);
5772 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE
);
5773 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE
);
5774 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED
);
5775 #undef LOCATION_TO_STR
5776 if (location
) FIXME("Unrecognized location flag(s) %#x.\n", location
);
5778 return wine_dbg_sprintf("%s%s%s", prefix
, buf
[0] ? &buf
[3] : "0", suffix
);
5781 /* Print a floating point value with the %.8e format specifier, always using
5782 * '.' as decimal separator. */
5783 void wined3d_ftoa(float value
, char *s
)
5787 if (copysignf(1.0f
, value
) < 0.0f
)
5790 /* Be sure to allocate a buffer of at least 17 characters for the result
5791 as sprintf may return a 3 digit exponent when using the MSVC runtime
5792 instead of a 2 digit exponent. */
5793 sprintf(s
, "%.8e", value
);
5794 if (isfinite(value
))
5798 void wined3d_release_dc(HWND window
, HDC dc
)
5800 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
5801 * However, that's not what actually happens, and there are user32 tests
5802 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
5803 * So explicitly check that the DC belongs to the window, since we want to
5804 * avoid releasing a DC that belongs to some other window if the original
5805 * window was already destroyed. */
5806 if (WindowFromDC(dc
) != window
)
5807 WARN("DC %p does not belong to window %p.\n", dc
, window
);
5808 else if (!ReleaseDC(window
, dc
))
5809 ERR("Failed to release device context %p, last error %#x.\n", dc
, GetLastError());
5812 BOOL
wined3d_clip_blit(const RECT
*clip_rect
, RECT
*clipped
, RECT
*other
)
5814 RECT orig
= *clipped
;
5815 float scale_x
= (float)(orig
.right
- orig
.left
) / (float)(other
->right
- other
->left
);
5816 float scale_y
= (float)(orig
.bottom
- orig
.top
) / (float)(other
->bottom
- other
->top
);
5818 IntersectRect(clipped
, clipped
, clip_rect
);
5820 if (IsRectEmpty(clipped
))
5822 SetRectEmpty(other
);
5826 other
->left
+= (LONG
)((clipped
->left
- orig
.left
) / scale_x
);
5827 other
->top
+= (LONG
)((clipped
->top
- orig
.top
) / scale_y
);
5828 other
->right
-= (LONG
)((orig
.right
- clipped
->right
) / scale_x
);
5829 other
->bottom
-= (LONG
)((orig
.bottom
- clipped
->bottom
) / scale_y
);
5834 void wined3d_gl_limits_get_uniform_block_range(const struct wined3d_gl_limits
*gl_limits
,
5835 enum wined3d_shader_type shader_type
, unsigned int *base
, unsigned int *count
)
5838 *count
= gl_limits
->vertex_uniform_blocks
;
5840 if (shader_type
== WINED3D_SHADER_TYPE_VERTEX
)
5844 *count
= gl_limits
->geometry_uniform_blocks
;
5846 if (shader_type
== WINED3D_SHADER_TYPE_GEOMETRY
)
5850 *count
= gl_limits
->fragment_uniform_blocks
;
5852 if (shader_type
== WINED3D_SHADER_TYPE_PIXEL
)
5858 ERR("Unhandled shader type %#x.\n", shader_type
);