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_R16G16_SINT
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
102 {WINED3DFMT_R16G16B16A16_SINT
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
103 {WINED3DFMT_R11G11B10_FLOAT
, 11, 11, 10, 0, 0, 11, 22, 0, 4, 0, 0},
104 /* Palettized formats */
105 {WINED3DFMT_P8_UINT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
106 {WINED3DFMT_P8_UINT
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
107 /* Standard ARGB formats. */
108 {WINED3DFMT_B8G8R8_UNORM
, 8, 8, 8, 0, 16, 8, 0, 0, 3, 0, 0},
109 {WINED3DFMT_B5G6R5_UNORM
, 5, 6, 5, 0, 11, 5, 0, 0, 2, 0, 0},
110 {WINED3DFMT_B5G5R5X1_UNORM
, 5, 5, 5, 0, 10, 5, 0, 0, 2, 0, 0},
111 {WINED3DFMT_B5G5R5A1_UNORM
, 5, 5, 5, 1, 10, 5, 0, 15, 2, 0, 0},
112 {WINED3DFMT_B4G4R4A4_UNORM
, 4, 4, 4, 4, 8, 4, 0, 12, 2, 0, 0},
113 {WINED3DFMT_B2G3R3_UNORM
, 3, 3, 2, 0, 5, 2, 0, 0, 1, 0, 0},
114 {WINED3DFMT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0},
115 {WINED3DFMT_B2G3R3A8_UNORM
, 3, 3, 2, 8, 5, 2, 0, 8, 2, 0, 0},
116 {WINED3DFMT_B4G4R4X4_UNORM
, 4, 4, 4, 0, 8, 4, 0, 0, 2, 0, 0},
117 {WINED3DFMT_R8G8B8X8_UNORM
, 8, 8, 8, 0, 0, 8, 16, 0, 4, 0, 0},
118 {WINED3DFMT_B10G10R10A2_UNORM
, 10, 10, 10, 2, 20, 10, 0, 30, 4, 0, 0},
120 {WINED3DFMT_L8_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
121 {WINED3DFMT_L8A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
122 {WINED3DFMT_L4A4_UNORM
, 0, 0, 0, 4, 0, 0, 0, 4, 1, 0, 0},
123 {WINED3DFMT_L16_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
124 /* Bump mapping stuff */
125 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, 5, 5, 0, 0, 0, 5, 0, 0, 2, 0, 0},
126 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, 8, 8, 0, 0, 0, 8, 0, 0, 4, 0, 0},
127 {WINED3DFMT_R8G8B8A8_SNORM
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
128 {WINED3DFMT_R10G11B11_SNORM
, 10, 11, 11, 0, 0, 10, 21, 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 {WINED3DFMT_VERTEXDATA
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
140 /* Vendor-specific formats */
141 {WINED3DFMT_ATI1N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
142 {WINED3DFMT_ATI2N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
143 {WINED3DFMT_NVDB
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
144 {WINED3DFMT_INST
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
145 {WINED3DFMT_INTZ
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
146 {WINED3DFMT_RESZ
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
147 {WINED3DFMT_NVHU
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
148 {WINED3DFMT_NVHS
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
149 {WINED3DFMT_NULL
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
150 /* Unsure about them, could not find a Windows driver that supports them */
151 {WINED3DFMT_R16
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
152 {WINED3DFMT_AL16
, 0, 0, 0, 16, 0, 0, 0, 16, 4, 0, 0},
154 {WINED3DFMT_R32G32B32A32_TYPELESS
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
155 {WINED3DFMT_R32G32B32_TYPELESS
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
156 {WINED3DFMT_R16G16B16A16_TYPELESS
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
157 {WINED3DFMT_R32G32_TYPELESS
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
158 {WINED3DFMT_R32G8X24_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 8, 32, 8},
159 {WINED3DFMT_R10G10B10A2_TYPELESS
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
160 {WINED3DFMT_R8G8B8A8_TYPELESS
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
161 {WINED3DFMT_R16G16_TYPELESS
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
162 {WINED3DFMT_R32_TYPELESS
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
163 {WINED3DFMT_R24G8_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
164 {WINED3DFMT_R8G8_TYPELESS
, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
165 {WINED3DFMT_R16_TYPELESS
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
166 {WINED3DFMT_R8_TYPELESS
, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
167 {WINED3DFMT_BC1_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
168 {WINED3DFMT_BC2_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
169 {WINED3DFMT_BC3_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
170 {WINED3DFMT_BC4_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
171 {WINED3DFMT_BC5_TYPELESS
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
172 {WINED3DFMT_B8G8R8A8_TYPELESS
, 8, 8, 8, 8, 16, 8, 0, 24, 4, 0, 0},
173 {WINED3DFMT_B8G8R8X8_TYPELESS
, 8, 8, 8, 0, 16, 8, 0, 0, 4, 0, 0},
176 enum wined3d_channel_type
178 WINED3D_CHANNEL_TYPE_NONE
,
179 WINED3D_CHANNEL_TYPE_UNORM
,
180 WINED3D_CHANNEL_TYPE_SNORM
,
181 WINED3D_CHANNEL_TYPE_UINT
,
182 WINED3D_CHANNEL_TYPE_SINT
,
183 WINED3D_CHANNEL_TYPE_FLOAT
,
184 WINED3D_CHANNEL_TYPE_DEPTH
,
185 WINED3D_CHANNEL_TYPE_STENCIL
,
188 struct wined3d_typed_format_info
190 enum wined3d_format_id id
;
191 enum wined3d_format_id typeless_id
;
192 const char *channels
;
196 * The last entry for a given typeless format defines its internal format.
198 * u - WINED3D_CHANNEL_TYPE_UNORM
199 * i - WINED3D_CHANNEL_TYPE_SNORM
200 * U - WINED3D_CHANNEL_TYPE_UINT
201 * I - WINED3D_CHANNEL_TYPE_SINT
202 * F - WINED3D_CHANNEL_TYPE_FLOAT
203 * D - WINED3D_CHANNEL_TYPE_DEPTH
204 * S - WINED3D_CHANNEL_TYPE_STENCIL
206 static const struct wined3d_typed_format_info typed_formats
[] =
208 {WINED3DFMT_R32G32B32A32_UINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "UUUU"},
209 {WINED3DFMT_R32G32B32A32_SINT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "IIII"},
210 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3DFMT_R32G32B32A32_TYPELESS
, "FFFF"},
211 {WINED3DFMT_R32G32B32_UINT
, WINED3DFMT_R32G32B32_TYPELESS
, "UUU"},
212 {WINED3DFMT_R32G32B32_FLOAT
, WINED3DFMT_R32G32B32_TYPELESS
, "FFF"},
213 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "uuuu"},
214 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3DFMT_R16G16B16A16_TYPELESS
, "iiii"},
215 {WINED3DFMT_R16G16B16A16_SINT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "IIII"},
216 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3DFMT_R16G16B16A16_TYPELESS
, "FFFF"},
217 {WINED3DFMT_R32G32_UINT
, WINED3DFMT_R32G32_TYPELESS
, "UU"},
218 {WINED3DFMT_R32G32_FLOAT
, WINED3DFMT_R32G32_TYPELESS
, "FF"},
219 {WINED3DFMT_R10G10B10A2_SNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "iiii"},
220 {WINED3DFMT_R10G10B10A2_UINT
, WINED3DFMT_R10G10B10A2_TYPELESS
, "UUUU"},
221 {WINED3DFMT_R10G10B10A2_UNORM
, WINED3DFMT_R10G10B10A2_TYPELESS
, "uuuu"},
222 {WINED3DFMT_R8G8B8A8_UINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "UUUU"},
223 {WINED3DFMT_R8G8B8A8_SINT
, WINED3DFMT_R8G8B8A8_TYPELESS
, "IIII"},
224 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
225 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3DFMT_R8G8B8A8_TYPELESS
, "uuuu"},
226 {WINED3DFMT_R16G16_UNORM
, WINED3DFMT_R16G16_TYPELESS
, "uu"},
227 {WINED3DFMT_R16G16_SNORM
, WINED3DFMT_R16G16_TYPELESS
, "ii"},
228 {WINED3DFMT_R16G16_SINT
, WINED3DFMT_R16G16_TYPELESS
, "II"},
229 {WINED3DFMT_R16G16_FLOAT
, WINED3DFMT_R16G16_TYPELESS
, "FF"},
230 {WINED3DFMT_R32_UINT
, WINED3DFMT_R32_TYPELESS
, "U"},
231 {WINED3DFMT_R32_FLOAT
, WINED3DFMT_R32_TYPELESS
, "F"},
232 {WINED3DFMT_D24_UNORM_S8_UINT
, WINED3DFMT_R24G8_TYPELESS
, "DS"},
233 {WINED3DFMT_R8G8_SNORM
, WINED3DFMT_R8G8_TYPELESS
, "ii"},
234 {WINED3DFMT_R8G8_UNORM
, WINED3DFMT_R8G8_TYPELESS
, "uu"},
235 {WINED3DFMT_R16_UNORM
, WINED3DFMT_R16_TYPELESS
, "u"},
236 {WINED3DFMT_R16_UINT
, WINED3DFMT_R16_TYPELESS
, "U"},
237 {WINED3DFMT_R16_FLOAT
, WINED3DFMT_R16_TYPELESS
, "F"},
238 {WINED3DFMT_R8_UNORM
, WINED3DFMT_R8_TYPELESS
, "u"},
239 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_TYPELESS
, ""},
240 {WINED3DFMT_BC1_UNORM
, WINED3DFMT_BC1_TYPELESS
, ""},
241 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_TYPELESS
, ""},
242 {WINED3DFMT_BC2_UNORM
, WINED3DFMT_BC2_TYPELESS
, ""},
243 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_TYPELESS
, ""},
244 {WINED3DFMT_BC3_UNORM
, WINED3DFMT_BC3_TYPELESS
, ""},
245 {WINED3DFMT_BC4_UNORM
, WINED3DFMT_BC4_TYPELESS
, ""},
246 {WINED3DFMT_BC5_UNORM
, WINED3DFMT_BC5_TYPELESS
, ""},
247 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
248 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3DFMT_B8G8R8A8_TYPELESS
, "uuuu"},
249 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuu"},
250 {WINED3DFMT_B8G8R8X8_UNORM
, WINED3DFMT_B8G8R8X8_TYPELESS
, "uuu"},
253 struct wined3d_format_ddi_info
255 enum wined3d_format_id id
;
256 D3DDDIFORMAT ddi_format
;
259 static const struct wined3d_format_ddi_info ddi_formats
[] =
261 {WINED3DFMT_B8G8R8_UNORM
, D3DDDIFMT_R8G8B8
},
262 {WINED3DFMT_B8G8R8A8_UNORM
, D3DDDIFMT_A8R8G8B8
},
263 {WINED3DFMT_B8G8R8X8_UNORM
, D3DDDIFMT_X8R8G8B8
},
264 {WINED3DFMT_B5G6R5_UNORM
, D3DDDIFMT_R5G6B5
},
265 {WINED3DFMT_B5G5R5X1_UNORM
, D3DDDIFMT_X1R5G5B5
},
266 {WINED3DFMT_B5G5R5A1_UNORM
, D3DDDIFMT_A1R5G5B5
},
267 {WINED3DFMT_P8_UINT
, D3DDDIFMT_P8
},
270 struct wined3d_format_base_flags
272 enum wined3d_format_id id
;
276 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
277 * still needs to use the correct block based calculation for e.g. the
279 static const struct wined3d_format_base_flags format_base_flags
[] =
281 {WINED3DFMT_ATI1N
, WINED3DFMT_FLAG_BROKEN_PITCH
},
282 {WINED3DFMT_ATI2N
, WINED3DFMT_FLAG_BROKEN_PITCH
},
283 {WINED3DFMT_R11G11B10_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
284 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
285 {WINED3DFMT_S8_UINT_D24_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
288 struct wined3d_format_block_info
290 enum wined3d_format_id id
;
293 UINT block_byte_count
;
297 static const struct wined3d_format_block_info format_block_info
[] =
299 {WINED3DFMT_DXT1
, 4, 4, 8, TRUE
},
300 {WINED3DFMT_DXT2
, 4, 4, 16, TRUE
},
301 {WINED3DFMT_DXT3
, 4, 4, 16, TRUE
},
302 {WINED3DFMT_DXT4
, 4, 4, 16, TRUE
},
303 {WINED3DFMT_DXT5
, 4, 4, 16, TRUE
},
304 {WINED3DFMT_BC1_UNORM
, 4, 4, 8, TRUE
},
305 {WINED3DFMT_BC2_UNORM
, 4, 4, 16, TRUE
},
306 {WINED3DFMT_BC3_UNORM
, 4, 4, 16, TRUE
},
307 {WINED3DFMT_BC4_UNORM
, 4, 4, 8, TRUE
},
308 {WINED3DFMT_BC5_UNORM
, 4, 4, 16, TRUE
},
309 {WINED3DFMT_ATI1N
, 4, 4, 8, FALSE
},
310 {WINED3DFMT_ATI2N
, 4, 4, 16, FALSE
},
311 {WINED3DFMT_YUY2
, 2, 1, 4, FALSE
},
312 {WINED3DFMT_UYVY
, 2, 1, 4, FALSE
},
315 struct wined3d_format_vertex_info
317 enum wined3d_format_id id
;
318 enum wined3d_ffp_emit_idx emit_idx
;
319 GLint component_count
;
322 GLboolean gl_normalized
;
323 unsigned int component_size
;
326 static const struct wined3d_format_vertex_info format_vertex_info
[] =
328 {WINED3DFMT_R32_FLOAT
, WINED3D_FFP_EMIT_FLOAT1
, 1, GL_FLOAT
, 1, GL_FALSE
, sizeof(float)},
329 {WINED3DFMT_R32G32_FLOAT
, WINED3D_FFP_EMIT_FLOAT2
, 2, GL_FLOAT
, 2, GL_FALSE
, sizeof(float)},
330 {WINED3DFMT_R32G32B32_FLOAT
, WINED3D_FFP_EMIT_FLOAT3
, 3, GL_FLOAT
, 3, GL_FALSE
, sizeof(float)},
331 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3D_FFP_EMIT_FLOAT4
, 4, GL_FLOAT
, 4, GL_FALSE
, sizeof(float)},
332 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3D_FFP_EMIT_D3DCOLOR
, 4, GL_UNSIGNED_BYTE
, 4, GL_TRUE
, sizeof(BYTE
)},
333 {WINED3DFMT_R8G8B8A8_UINT
, WINED3D_FFP_EMIT_UBYTE4
, 4, GL_UNSIGNED_BYTE
, 4, GL_FALSE
, sizeof(BYTE
)},
334 {WINED3DFMT_R16G16_SINT
, WINED3D_FFP_EMIT_SHORT2
, 2, GL_SHORT
, 2, GL_FALSE
, sizeof(short int)},
335 {WINED3DFMT_R16G16B16A16_SINT
, WINED3D_FFP_EMIT_SHORT4
, 4, GL_SHORT
, 4, GL_FALSE
, sizeof(short int)},
336 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3D_FFP_EMIT_UBYTE4N
, 4, GL_UNSIGNED_BYTE
, 4, GL_TRUE
, sizeof(BYTE
)},
337 {WINED3DFMT_R16G16_SNORM
, WINED3D_FFP_EMIT_SHORT2N
, 2, GL_SHORT
, 2, GL_TRUE
, sizeof(short int)},
338 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3D_FFP_EMIT_SHORT4N
, 4, GL_SHORT
, 4, GL_TRUE
, sizeof(short int)},
339 {WINED3DFMT_R16G16_UNORM
, WINED3D_FFP_EMIT_USHORT2N
, 2, GL_UNSIGNED_SHORT
, 2, GL_TRUE
, sizeof(short int)},
340 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3D_FFP_EMIT_USHORT4N
, 4, GL_UNSIGNED_SHORT
, 4, GL_TRUE
, sizeof(short int)},
341 {WINED3DFMT_R10G10B10A2_UINT
, WINED3D_FFP_EMIT_UDEC3
, 3, GL_UNSIGNED_SHORT
, 3, GL_FALSE
, sizeof(short int)},
342 {WINED3DFMT_R10G10B10A2_SNORM
, WINED3D_FFP_EMIT_DEC3N
, 3, GL_SHORT
, 3, GL_TRUE
, sizeof(short int)},
343 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, 2, GL_FLOAT
, 2, GL_FALSE
, sizeof(GLhalfNV
)},
344 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, 4, GL_FLOAT
, 4, GL_FALSE
, sizeof(GLhalfNV
)},
345 {WINED3DFMT_R32_UINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_INT
, 1, GL_FALSE
, sizeof(UINT
)},
346 {WINED3DFMT_R32G32_UINT
, WINED3D_FFP_EMIT_INVALID
, 2, GL_UNSIGNED_INT
, 2, GL_FALSE
, sizeof(UINT
)},
347 {WINED3DFMT_R32G32B32_UINT
, WINED3D_FFP_EMIT_INVALID
, 3, GL_UNSIGNED_INT
, 3, GL_FALSE
, sizeof(UINT
)},
348 {WINED3DFMT_R32G32B32A32_UINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_UNSIGNED_INT
, 4, GL_FALSE
, sizeof(UINT
)},
351 struct wined3d_format_texture_info
353 enum wined3d_format_id id
;
355 GLint gl_srgb_internal
;
356 GLint gl_rt_internal
;
359 unsigned int conv_byte_count
;
361 enum wined3d_gl_extension extension
;
362 void (*convert
)(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
363 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
);
366 static void convert_l4a4_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
367 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
369 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
370 * format+type combination to load it. Thus convert it to A8L8, then load it
371 * with A4L4 internal, but A8L8 format+type
373 unsigned int x
, y
, z
;
374 const unsigned char *Source
;
377 for (z
= 0; z
< depth
; z
++)
379 for (y
= 0; y
< height
; y
++)
381 Source
= src
+ z
* src_slice_pitch
+ y
* src_row_pitch
;
382 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
383 for (x
= 0; x
< width
; x
++ )
385 unsigned char color
= (*Source
++);
386 /* A */ Dest
[1] = (color
& 0xf0u
) << 0;
387 /* L */ Dest
[0] = (color
& 0x0fu
) << 4;
394 static void convert_r5g5_snorm_l6_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
395 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
397 unsigned int x
, y
, z
;
398 unsigned char r_in
, g_in
, l_in
;
399 const unsigned short *texel_in
;
400 unsigned short *texel_out
;
402 /* Emulating signed 5 bit values with unsigned 5 bit values has some precision problems by design:
403 * E.g. the signed input value 0 becomes 16. GL normalizes it to 16 / 31 = 0.516. We convert it
404 * back to a signed value by subtracting 0.5 and multiplying by 2.0. The resulting value is
405 * ((16 / 31) - 0.5) * 2.0 = 0.032, which is quite different from the intended result 0.000. */
406 for (z
= 0; z
< depth
; z
++)
408 for (y
= 0; y
< height
; y
++)
410 texel_out
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
411 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
412 for (x
= 0; x
< width
; x
++ )
414 l_in
= (*texel_in
& 0xfc00u
) >> 10;
415 g_in
= (*texel_in
& 0x03e0u
) >> 5;
416 r_in
= *texel_in
& 0x001fu
;
418 *texel_out
= ((r_in
+ 16) << 11) | (l_in
<< 5) | (g_in
+ 16);
426 static void convert_r5g5_snorm_l6_unorm_ext(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
427 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
429 unsigned int x
, y
, z
;
430 unsigned char *texel_out
, r_out
, g_out
, r_in
, g_in
, l_in
;
431 const unsigned short *texel_in
;
433 for (z
= 0; z
< depth
; z
++)
435 for (y
= 0; y
< height
; y
++)
437 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
438 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
439 for (x
= 0; x
< width
; x
++ )
441 l_in
= (*texel_in
& 0xfc00u
) >> 10;
442 g_in
= (*texel_in
& 0x03e0u
) >> 5;
443 r_in
= *texel_in
& 0x001fu
;
446 if (!(r_in
& 0x10)) /* r > 0 */
450 if (!(g_in
& 0x10)) /* g > 0 */
453 texel_out
[0] = r_out
;
454 texel_out
[1] = g_out
;
455 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
465 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
466 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
468 unsigned int x
, y
, z
;
469 unsigned char *texel_out
, ds_out
, dt_out
, r_in
, g_in
, l_in
;
470 const unsigned short *texel_in
;
472 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
473 * fixed function and shaders without further conversion once the surface is
476 * The difference between this function and convert_r5g5_snorm_l6_unorm_ext
477 * is that convert_r5g5_snorm_l6_unorm_ext creates a 32 bit XRGB texture and
478 * this function creates a 24 bit DSDT_MAG texture. Trying to load a DSDT_MAG
479 * internal with a 32 bit DSDT_MAG_INTENSITY or DSDT_MAG_VIB format fails. */
480 for (z
= 0; z
< depth
; z
++)
482 for (y
= 0; y
< height
; y
++)
484 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
485 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
486 for (x
= 0; x
< width
; x
++ )
488 l_in
= (*texel_in
& 0xfc00u
) >> 10;
489 g_in
= (*texel_in
& 0x03e0u
) >> 5;
490 r_in
= *texel_in
& 0x001fu
;
493 if (!(r_in
& 0x10)) /* r > 0 */
497 if (!(g_in
& 0x10)) /* g > 0 */
500 texel_out
[0] = ds_out
;
501 texel_out
[1] = dt_out
;
502 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
511 static void convert_r8g8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
512 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
514 unsigned int x
, y
, z
;
518 for (z
= 0; z
< depth
; z
++)
520 for (y
= 0; y
< height
; y
++)
522 Source
= (const short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
523 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
524 for (x
= 0; x
< width
; x
++ )
526 const short color
= (*Source
++);
527 /* B */ Dest
[0] = 0xff;
528 /* G */ Dest
[1] = (color
>> 8) + 128; /* V */
529 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
536 static void convert_r8g8_snorm_l8x8_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
537 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
539 unsigned int x
, y
, z
;
543 /* Doesn't work correctly with the fixed function pipeline, but can work in
544 * shaders if the shader is adjusted. (There's no use for this format in gl's
545 * standard fixed function pipeline anyway).
547 for (z
= 0; z
< depth
; z
++)
549 for (y
= 0; y
< height
; y
++)
551 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
552 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
553 for (x
= 0; x
< width
; x
++ )
555 LONG color
= (*Source
++);
556 /* B */ Dest
[0] = ((color
>> 16) & 0xff); /* L */
557 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
558 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
565 static void convert_r8g8_snorm_l8x8_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
566 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
568 unsigned int x
, y
, z
;
572 /* This implementation works with the fixed function pipeline and shaders
573 * without further modification after converting the surface.
575 for (z
= 0; z
< depth
; z
++)
577 for (y
= 0; y
< height
; y
++)
579 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
580 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
581 for (x
= 0; x
< width
; x
++ )
583 LONG color
= (*Source
++);
584 /* L */ Dest
[2] = ((color
>> 16) & 0xff); /* L */
585 /* V */ Dest
[1] = ((color
>> 8 ) & 0xff); /* V */
586 /* U */ Dest
[0] = (color
& 0xff); /* U */
587 /* I */ Dest
[3] = 255; /* X */
594 static void convert_r8g8b8a8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
595 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
597 unsigned int x
, y
, z
;
601 for (z
= 0; z
< depth
; z
++)
603 for (y
= 0; y
< height
; y
++)
605 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
606 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
607 for (x
= 0; x
< width
; x
++ )
609 LONG color
= (*Source
++);
610 /* B */ Dest
[0] = ((color
>> 16) & 0xff) + 128; /* W */
611 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
612 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
613 /* A */ Dest
[3] = ((color
>> 24) & 0xff) + 128; /* Q */
620 static void convert_r16g16_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
621 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
623 unsigned int x
, y
, z
;
625 unsigned short *Dest
;
627 for (z
= 0; z
< depth
; z
++)
629 for (y
= 0; y
< height
; y
++)
631 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
632 Dest
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
633 for (x
= 0; x
< width
; x
++ )
635 const DWORD color
= (*Source
++);
636 /* B */ Dest
[0] = 0xffff;
637 /* G */ Dest
[1] = (color
>> 16) + 32768; /* V */
638 /* R */ Dest
[2] = (color
& 0xffff) + 32768; /* U */
645 static void convert_r16g16(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
646 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
648 unsigned int x
, y
, z
;
652 for (z
= 0; z
< depth
; z
++)
654 for (y
= 0; y
< height
; y
++)
656 Source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
657 Dest
= (WORD
*) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
658 for (x
= 0; x
< width
; x
++ )
660 WORD green
= (*Source
++);
661 WORD red
= (*Source
++);
664 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
665 * shader overwrites it anyway */
673 static void convert_r32g32_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
674 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
676 unsigned int x
, y
, z
;
680 for (z
= 0; z
< depth
; z
++)
682 for (y
= 0; y
< height
; y
++)
684 Source
= (const float *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
685 Dest
= (float *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
686 for (x
= 0; x
< width
; x
++ )
688 float green
= (*Source
++);
689 float red
= (*Source
++);
699 static void convert_s1_uint_d15_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
700 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
702 unsigned int x
, y
, z
;
704 for (z
= 0; z
< depth
; z
++)
706 for (y
= 0; y
< height
; ++y
)
708 const WORD
*source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
709 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
711 for (x
= 0; x
< width
; ++x
)
713 /* The depth data is normalized, so needs to be scaled,
714 * the stencil data isn't. Scale depth data by
715 * (2^24-1)/(2^15-1) ~~ (2^9 + 2^-6). */
716 WORD d15
= source
[x
] >> 1;
717 DWORD d24
= (d15
<< 9) + (d15
>> 6);
718 dest
[x
] = (d24
<< 8) | (source
[x
] & 0x1);
724 static void convert_s4x4_uint_d24_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
725 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
727 unsigned int x
, y
, z
;
729 for (z
= 0; z
< depth
; z
++)
731 for (y
= 0; y
< height
; ++y
)
733 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
734 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
736 for (x
= 0; x
< width
; ++x
)
738 /* Just need to clear out the X4 part. */
739 dest
[x
] = source
[x
] & ~0xf0;
745 static void convert_s8_uint_d24_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
746 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
748 unsigned int x
, y
, z
;
750 for (z
= 0; z
< depth
; z
++)
752 for (y
= 0; y
< height
; ++y
)
754 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
755 float *dest_f
= (float *)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
756 DWORD
*dest_s
= (DWORD
*)dest_f
;
758 for (x
= 0; x
< width
; ++x
)
760 dest_f
[x
* 2] = float_24_to_32((source
[x
] & 0xffffff00u
) >> 8);
761 dest_s
[x
* 2 + 1] = source
[x
] & 0xff;
767 static BOOL
color_in_range(const struct wined3d_color_key
*color_key
, DWORD color
)
769 /* FIXME: Is this really how color keys are supposed to work? I think it
770 * makes more sense to compare the individual channels. */
771 return color
>= color_key
->color_space_low_value
772 && color
<= color_key
->color_space_high_value
;
775 static void convert_p8_uint_b8g8r8a8_unorm(const BYTE
*src
, unsigned int src_pitch
,
776 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
777 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
785 /* FIXME: This should probably use the system palette. */
786 FIXME("P8 surface loaded without a palette.\n");
788 for (y
= 0; y
< height
; ++y
)
790 memset(&dst
[dst_pitch
* y
], 0, width
* 4);
796 for (y
= 0; y
< height
; ++y
)
798 src_row
= &src
[src_pitch
* y
];
799 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
800 for (x
= 0; x
< width
; ++x
)
802 BYTE src_color
= src_row
[x
];
803 dst_row
[x
] = 0xff000000
804 | (palette
->colors
[src_color
].rgbRed
<< 16)
805 | (palette
->colors
[src_color
].rgbGreen
<< 8)
806 | palette
->colors
[src_color
].rgbBlue
;
811 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(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
)
819 for (y
= 0; y
< height
; ++y
)
821 src_row
= (WORD
*)&src
[src_pitch
* y
];
822 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
823 for (x
= 0; x
< width
; ++x
)
825 WORD src_color
= src_row
[x
];
826 if (!color_in_range(color_key
, src_color
))
827 dst_row
[x
] = 0x8000u
| ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
829 dst_row
[x
] = ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
834 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
835 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
836 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
842 for (y
= 0; y
< height
; ++y
)
844 src_row
= (WORD
*)&src
[src_pitch
* y
];
845 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
846 for (x
= 0; x
< width
; ++x
)
848 WORD src_color
= src_row
[x
];
849 if (color_in_range(color_key
, src_color
))
850 dst_row
[x
] = src_color
& ~0x8000;
852 dst_row
[x
] = src_color
| 0x8000;
857 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
858 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
859 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
865 for (y
= 0; y
< height
; ++y
)
867 src_row
= &src
[src_pitch
* y
];
868 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
869 for (x
= 0; x
< width
; ++x
)
871 DWORD src_color
= (src_row
[x
* 3 + 2] << 16) | (src_row
[x
* 3 + 1] << 8) | src_row
[x
* 3];
872 if (!color_in_range(color_key
, src_color
))
873 dst_row
[x
] = src_color
| 0xff000000;
878 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
879 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
880 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
882 const DWORD
*src_row
;
886 for (y
= 0; y
< height
; ++y
)
888 src_row
= (DWORD
*)&src
[src_pitch
* y
];
889 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
890 for (x
= 0; x
< width
; ++x
)
892 DWORD src_color
= src_row
[x
];
893 if (color_in_range(color_key
, src_color
))
894 dst_row
[x
] = src_color
& ~0xff000000;
896 dst_row
[x
] = src_color
| 0xff000000;
901 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
902 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
903 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
905 const DWORD
*src_row
;
909 for (y
= 0; y
< height
; ++y
)
911 src_row
= (DWORD
*)&src
[src_pitch
* y
];
912 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
913 for (x
= 0; x
< width
; ++x
)
915 DWORD src_color
= src_row
[x
];
916 if (color_in_range(color_key
, src_color
))
917 src_color
&= ~0xff000000;
918 dst_row
[x
] = src_color
;
923 const struct wined3d_color_key_conversion
* wined3d_format_get_color_key_conversion(
924 const struct wined3d_texture
*texture
, BOOL need_alpha_ck
)
926 const struct wined3d_format
*format
= texture
->resource
.format
;
931 enum wined3d_format_id src_format
;
932 struct wined3d_color_key_conversion conversion
;
936 {WINED3DFMT_B5G6R5_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key
}},
937 {WINED3DFMT_B5G5R5X1_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key
}},
938 {WINED3DFMT_B8G8R8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key
}},
939 {WINED3DFMT_B8G8R8X8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key
}},
940 {WINED3DFMT_B8G8R8A8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key
}},
942 static const struct wined3d_color_key_conversion convert_p8
=
944 WINED3DFMT_B8G8R8A8_UNORM
, convert_p8_uint_b8g8r8a8_unorm
947 if (need_alpha_ck
&& (texture
->async
.flags
& WINED3D_TEXTURE_ASYNC_COLOR_KEY
))
949 for (i
= 0; i
< sizeof(color_key_info
) / sizeof(*color_key_info
); ++i
)
951 if (color_key_info
[i
].src_format
== format
->id
)
952 return &color_key_info
[i
].conversion
;
955 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format
->id
));
958 /* FIXME: This should check if the blitter backend can do P8 conversion,
959 * instead of checking for ARB_fragment_program. */
960 if (format
->id
== WINED3DFMT_P8_UINT
961 && !(texture
->resource
.device
->adapter
->gl_info
.supported
[ARB_FRAGMENT_PROGRAM
]
962 && texture
->swapchain
&& texture
== texture
->swapchain
->front_buffer
))
968 /* The following formats explicitly don't have WINED3DFMT_FLAG_TEXTURE set:
970 * These are never supported on native.
971 * WINED3DFMT_B8G8R8_UNORM
972 * WINED3DFMT_B2G3R3_UNORM
973 * WINED3DFMT_L4A4_UNORM
974 * WINED3DFMT_S1_UINT_D15_UNORM
975 * WINED3DFMT_S4X4_UINT_D24_UNORM
977 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
978 * Since it is not widely available, don't offer it. Further no Windows driver
979 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
981 * WINED3DFMT_P8_UINT_A8_UNORM
983 * These formats seem to be similar to the HILO formats in
984 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
985 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
986 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
987 * refused to support formats which can easily be emulated with pixel shaders,
988 * so applications have to deal with not having NVHS and NVHU.
991 static const struct wined3d_format_texture_info format_texture_info
[] =
993 /* format id gl_internal gl_srgb_internal gl_rt_internal
994 gl_format gl_type conv_byte_count
998 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
999 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
1000 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
1001 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
1004 {WINED3DFMT_UYVY
, GL_RG8
, GL_RG8
, 0,
1005 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1006 WINED3DFMT_FLAG_FILTERING
,
1007 ARB_TEXTURE_RG
, NULL
},
1008 {WINED3DFMT_UYVY
, GL_LUMINANCE_ALPHA
, GL_LUMINANCE_ALPHA
, 0,
1009 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1010 WINED3DFMT_FLAG_FILTERING
,
1011 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1012 {WINED3DFMT_UYVY
, GL_RGB
, GL_RGB
, 0,
1013 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
1014 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
1015 APPLE_YCBCR_422
, NULL
},
1016 {WINED3DFMT_YUY2
, GL_RG8
, GL_RG8
, 0,
1017 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1018 WINED3DFMT_FLAG_FILTERING
,
1019 ARB_TEXTURE_RG
, NULL
},
1020 {WINED3DFMT_YUY2
, GL_LUMINANCE_ALPHA
, GL_LUMINANCE_ALPHA
, 0,
1021 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1022 WINED3DFMT_FLAG_FILTERING
,
1023 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1024 {WINED3DFMT_YUY2
, GL_RGB
, GL_RGB
, 0,
1025 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
1026 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
1027 APPLE_YCBCR_422
, NULL
},
1028 {WINED3DFMT_YV12
, GL_R8
, GL_R8
, 0,
1029 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1030 WINED3DFMT_FLAG_FILTERING
,
1031 ARB_TEXTURE_RG
, NULL
},
1032 {WINED3DFMT_YV12
, GL_ALPHA
, GL_ALPHA
, 0,
1033 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1034 WINED3DFMT_FLAG_FILTERING
,
1035 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1036 {WINED3DFMT_NV12
, GL_R8
, GL_R8
, 0,
1037 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1038 WINED3DFMT_FLAG_FILTERING
,
1039 ARB_TEXTURE_RG
, NULL
},
1040 {WINED3DFMT_NV12
, GL_ALPHA
, GL_ALPHA
, 0,
1041 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1042 WINED3DFMT_FLAG_FILTERING
,
1043 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1044 {WINED3DFMT_DXT1
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1045 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1046 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1047 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1048 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1049 {WINED3DFMT_DXT2
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1050 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1051 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1052 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1053 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1054 {WINED3DFMT_DXT3
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1055 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1056 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1057 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1058 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1059 {WINED3DFMT_DXT4
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1060 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1061 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1062 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1063 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1064 {WINED3DFMT_DXT5
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1065 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1066 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1067 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
1068 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1069 {WINED3DFMT_BC1_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
1070 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1071 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1072 | WINED3DFMT_FLAG_COMPRESSED
,
1073 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1074 {WINED3DFMT_BC2_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
1075 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1076 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1077 | WINED3DFMT_FLAG_COMPRESSED
,
1078 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1079 {WINED3DFMT_BC3_UNORM
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
1080 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
1081 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1082 | WINED3DFMT_FLAG_COMPRESSED
,
1083 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
1084 {WINED3DFMT_BC4_UNORM
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1085 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1086 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1087 | WINED3DFMT_FLAG_COMPRESSED
,
1088 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1089 {WINED3DFMT_BC5_UNORM
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1090 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1091 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1092 | WINED3DFMT_FLAG_COMPRESSED
,
1093 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1095 {WINED3DFMT_R32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1096 GL_RED
, GL_FLOAT
, 0,
1097 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1098 ARB_TEXTURE_FLOAT
, NULL
},
1099 {WINED3DFMT_R32_FLOAT
, GL_R32F
, GL_R32F
, 0,
1100 GL_RED
, GL_FLOAT
, 0,
1101 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1102 ARB_TEXTURE_RG
, NULL
},
1103 {WINED3DFMT_R32G32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
1104 GL_RGB
, GL_FLOAT
, 12,
1105 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1106 ARB_TEXTURE_FLOAT
, convert_r32g32_float
},
1107 {WINED3DFMT_R32G32_FLOAT
, GL_RG32F
, GL_RG32F
, 0,
1109 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1110 ARB_TEXTURE_RG
, NULL
},
1111 {WINED3DFMT_R32G32B32_FLOAT
, GL_RGB32F
, GL_RGB32F
, 0,
1112 GL_RGB
, GL_FLOAT
, 0,
1113 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
,
1114 ARB_TEXTURE_FLOAT
, NULL
},
1115 {WINED3DFMT_R32G32B32A32_FLOAT
, GL_RGBA32F_ARB
, GL_RGBA32F_ARB
, 0,
1116 GL_RGBA
, GL_FLOAT
, 0,
1117 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1118 ARB_TEXTURE_FLOAT
, NULL
},
1120 {WINED3DFMT_R16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1121 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1122 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1123 ARB_TEXTURE_FLOAT
, NULL
},
1124 {WINED3DFMT_R16_FLOAT
, GL_R16F
, GL_R16F
, 0,
1125 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
1126 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1127 ARB_TEXTURE_RG
, NULL
},
1128 {WINED3DFMT_R16G16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
1129 GL_RGB
, GL_HALF_FLOAT_ARB
, 6,
1130 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1131 ARB_TEXTURE_FLOAT
, convert_r16g16
},
1132 {WINED3DFMT_R16G16_FLOAT
, GL_RG16F
, GL_RG16F
, 0,
1133 GL_RG
, GL_HALF_FLOAT_ARB
, 0,
1134 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1135 ARB_TEXTURE_RG
, NULL
},
1136 {WINED3DFMT_R16G16B16A16_FLOAT
, GL_RGBA16F_ARB
, GL_RGBA16F_ARB
, 0,
1137 GL_RGBA
, GL_HALF_FLOAT_ARB
, 0,
1138 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
1139 | WINED3DFMT_FLAG_VTF
,
1140 ARB_TEXTURE_FLOAT
, NULL
},
1141 {WINED3DFMT_R11G11B10_FLOAT
, GL_R11F_G11F_B10F
, GL_R11F_G11F_B10F
, 0,
1142 GL_RGB
, GL_UNSIGNED_INT_10F_11F_11F_REV
, 0,
1143 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
,
1145 /* Palettized formats */
1146 {WINED3DFMT_P8_UINT
, GL_R8
, GL_R8
, 0,
1147 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1149 ARB_TEXTURE_RG
, NULL
},
1150 {WINED3DFMT_P8_UINT
, GL_ALPHA8
, GL_ALPHA8
, 0,
1151 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1153 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1154 /* Standard ARGB formats */
1155 {WINED3DFMT_B8G8R8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1156 GL_BGR
, GL_UNSIGNED_BYTE
, 0,
1157 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
| WINED3DFMT_FLAG_RENDERTARGET
,
1158 WINED3D_GL_EXT_NONE
, NULL
},
1159 {WINED3DFMT_B8G8R8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1160 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1161 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1162 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1163 | WINED3DFMT_FLAG_VTF
,
1164 WINED3D_GL_EXT_NONE
, NULL
},
1165 {WINED3DFMT_B8G8R8X8_UNORM
, GL_RGB8
, GL_SRGB8_EXT
, 0,
1166 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1167 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1168 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
,
1169 WINED3D_GL_EXT_NONE
, NULL
},
1170 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB5
, GL_RGB5
, GL_RGB8
,
1171 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1172 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1173 | WINED3DFMT_FLAG_RENDERTARGET
,
1174 WINED3D_GL_EXT_NONE
, NULL
},
1175 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB565
, GL_RGB565
, GL_RGB8
,
1176 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1177 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1178 | WINED3DFMT_FLAG_RENDERTARGET
,
1179 ARB_ES2_COMPATIBILITY
, NULL
},
1180 {WINED3DFMT_B5G5R5X1_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1181 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1182 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1183 | WINED3DFMT_FLAG_RENDERTARGET
,
1184 WINED3D_GL_EXT_NONE
, NULL
},
1185 {WINED3DFMT_B5G5R5A1_UNORM
, GL_RGB5_A1
, GL_RGB5_A1
, 0,
1186 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1187 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1188 WINED3D_GL_EXT_NONE
, NULL
},
1189 {WINED3DFMT_B4G4R4A4_UNORM
, GL_RGBA4
, GL_SRGB8_ALPHA8_EXT
, 0,
1190 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1191 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1192 | WINED3DFMT_FLAG_SRGB_READ
,
1193 WINED3D_GL_EXT_NONE
, NULL
},
1194 {WINED3DFMT_B2G3R3_UNORM
, GL_R3_G3_B2
, GL_R3_G3_B2
, 0,
1195 GL_RGB
, GL_UNSIGNED_BYTE_3_3_2
, 0,
1196 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1197 WINED3D_GL_EXT_NONE
, NULL
},
1198 {WINED3DFMT_R8_UNORM
, GL_R8
, GL_R8
, 0,
1199 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1200 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1201 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1202 ARB_TEXTURE_RG
, NULL
},
1203 {WINED3DFMT_A8_UNORM
, GL_R8
, GL_R8
, 0,
1204 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1205 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1206 ARB_TEXTURE_RG
, NULL
},
1207 {WINED3DFMT_A8_UNORM
, GL_ALPHA8
, GL_ALPHA8
, 0,
1208 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1209 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1210 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1211 {WINED3DFMT_B4G4R4X4_UNORM
, GL_RGB4
, GL_RGB4
, 0,
1212 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1213 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1214 WINED3D_GL_EXT_NONE
, NULL
},
1215 {WINED3DFMT_R10G10B10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1216 GL_RGBA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1217 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1218 | WINED3DFMT_FLAG_RENDERTARGET
,
1219 WINED3D_GL_EXT_NONE
, NULL
},
1220 {WINED3DFMT_R8G8B8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1221 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1222 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1223 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1224 | WINED3DFMT_FLAG_VTF
,
1225 WINED3D_GL_EXT_NONE
, NULL
},
1226 {WINED3DFMT_R8G8B8A8_UINT
, GL_RGBA8UI
, GL_RGBA8UI
, 0,
1227 GL_RGBA_INTEGER
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1228 WINED3DFMT_FLAG_TEXTURE
,
1229 ARB_TEXTURE_RGB10_A2UI
, NULL
},
1230 {WINED3DFMT_R8G8B8A8_SINT
, GL_RGBA8I
, GL_RGBA8I
, 0,
1231 GL_RGBA_INTEGER
, GL_BYTE
, 0,
1232 WINED3DFMT_FLAG_TEXTURE
,
1233 EXT_TEXTURE_INTEGER
, NULL
},
1234 {WINED3DFMT_R8G8B8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1235 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1236 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1237 WINED3D_GL_EXT_NONE
, NULL
},
1238 {WINED3DFMT_R16G16_UNORM
, GL_RGB16
, GL_RGB16
, GL_RGBA16
,
1239 GL_RGB
, GL_UNSIGNED_SHORT
, 6,
1240 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1241 WINED3D_GL_EXT_NONE
, convert_r16g16
},
1242 {WINED3DFMT_R16G16_UNORM
, GL_RG16
, GL_RG16
, 0,
1243 GL_RG
, GL_UNSIGNED_SHORT
, 0,
1244 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1245 | WINED3DFMT_FLAG_RENDERTARGET
,
1246 ARB_TEXTURE_RG
, NULL
},
1247 {WINED3DFMT_B10G10R10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1248 GL_BGRA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1249 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1250 | WINED3DFMT_FLAG_RENDERTARGET
,
1251 WINED3D_GL_EXT_NONE
, NULL
},
1252 {WINED3DFMT_R16G16B16A16_UNORM
, GL_RGBA16
, GL_RGBA16
, 0,
1253 GL_RGBA
, GL_UNSIGNED_SHORT
, 0,
1254 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1255 | WINED3DFMT_FLAG_RENDERTARGET
,
1256 WINED3D_GL_EXT_NONE
, NULL
},
1257 {WINED3DFMT_R8G8_UNORM
, GL_RG8
, GL_RG8
, 0,
1258 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1259 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1260 ARB_TEXTURE_RG
, NULL
},
1261 {WINED3DFMT_R16_UNORM
, GL_R16
, GL_R16
, 0,
1262 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1263 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1264 | WINED3DFMT_FLAG_RENDERTARGET
,
1265 ARB_TEXTURE_RG
, NULL
},
1266 {WINED3DFMT_R16_UINT
, GL_R16UI
, GL_R16UI
, 0,
1267 GL_RED_INTEGER
, GL_UNSIGNED_SHORT
, 0,
1268 WINED3DFMT_FLAG_TEXTURE
,
1269 ARB_TEXTURE_RG
, NULL
},
1271 {WINED3DFMT_L8_UNORM
, GL_LUMINANCE8
, GL_SLUMINANCE8_EXT
, 0,
1272 GL_LUMINANCE
, GL_UNSIGNED_BYTE
, 0,
1273 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1274 | WINED3DFMT_FLAG_SRGB_READ
,
1275 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1276 {WINED3DFMT_L8_UNORM
, GL_R8
, GL_R8
, 0,
1277 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1278 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1279 | WINED3DFMT_FLAG_RENDERTARGET
,
1280 ARB_TEXTURE_RG
, NULL
},
1281 {WINED3DFMT_L8A8_UNORM
, GL_RG8
, GL_RG8
, 0,
1282 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1283 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1284 ARB_TEXTURE_RG
, NULL
},
1285 {WINED3DFMT_L8A8_UNORM
, GL_LUMINANCE8_ALPHA8
, GL_SLUMINANCE8_ALPHA8_EXT
, 0,
1286 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1287 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1288 | WINED3DFMT_FLAG_SRGB_READ
,
1289 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1290 {WINED3DFMT_L4A4_UNORM
, GL_RG8
, GL_RG8
, 0,
1291 GL_RG
, GL_UNSIGNED_BYTE
, 2,
1292 WINED3DFMT_FLAG_FILTERING
,
1293 ARB_TEXTURE_RG
, convert_l4a4_unorm
},
1294 {WINED3DFMT_L4A4_UNORM
, GL_LUMINANCE4_ALPHA4
, GL_LUMINANCE4_ALPHA4
, 0,
1295 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 2,
1296 WINED3DFMT_FLAG_FILTERING
,
1297 WINED3D_GL_LEGACY_CONTEXT
, convert_l4a4_unorm
},
1298 {WINED3DFMT_L16_UNORM
, GL_R16
, GL_R16
, 0,
1299 GL_RED
, GL_UNSIGNED_SHORT
, 0,
1300 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1301 ARB_TEXTURE_RG
, NULL
},
1302 {WINED3DFMT_L16_UNORM
, GL_LUMINANCE16
, GL_LUMINANCE16
, 0,
1303 GL_LUMINANCE
, GL_UNSIGNED_SHORT
, 0,
1304 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1305 WINED3D_GL_LEGACY_CONTEXT
, NULL
},
1306 /* Bump mapping stuff */
1307 {WINED3DFMT_R8G8_SNORM
, GL_RGB8
, GL_RGB8
, 0,
1308 GL_BGR
, GL_UNSIGNED_BYTE
, 3,
1309 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1310 | WINED3DFMT_FLAG_BUMPMAP
,
1311 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm
},
1312 {WINED3DFMT_R8G8_SNORM
, GL_DSDT8_NV
, GL_DSDT8_NV
, 0,
1313 GL_DSDT_NV
, GL_BYTE
, 0,
1314 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1315 | WINED3DFMT_FLAG_BUMPMAP
,
1316 NV_TEXTURE_SHADER
, NULL
},
1317 {WINED3DFMT_R8G8_SNORM
, GL_RG8_SNORM
, GL_RG8_SNORM
, 0,
1319 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1320 | WINED3DFMT_FLAG_BUMPMAP
,
1321 EXT_TEXTURE_SNORM
, NULL
},
1322 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1323 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 2,
1324 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1325 | WINED3DFMT_FLAG_BUMPMAP
,
1326 WINED3D_GL_EXT_NONE
, convert_r5g5_snorm_l6_unorm
},
1327 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_DSDT8_MAG8_NV
, GL_DSDT8_MAG8_NV
, 0,
1328 GL_DSDT_MAG_NV
, GL_BYTE
, 3,
1329 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1330 | WINED3DFMT_FLAG_BUMPMAP
,
1331 NV_TEXTURE_SHADER
, convert_r5g5_snorm_l6_unorm_nv
},
1332 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB8_SNORM
, GL_RGB8_SNORM
, 0,
1333 GL_RGBA
, GL_BYTE
, 4,
1334 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1335 | WINED3DFMT_FLAG_BUMPMAP
,
1336 EXT_TEXTURE_SNORM
, convert_r5g5_snorm_l6_unorm_ext
},
1337 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1338 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4,
1339 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1340 | WINED3DFMT_FLAG_BUMPMAP
,
1341 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm_l8x8_unorm
},
1342 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_DSDT8_MAG8_INTENSITY8_NV
, GL_DSDT8_MAG8_INTENSITY8_NV
, 0,
1343 GL_DSDT_MAG_VIB_NV
, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV
, 4,
1344 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1345 | WINED3DFMT_FLAG_BUMPMAP
,
1346 NV_TEXTURE_SHADER
, convert_r8g8_snorm_l8x8_unorm_nv
},
1347 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8
, GL_RGBA8
, 0,
1348 GL_BGRA
, GL_UNSIGNED_BYTE
, 4,
1349 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1350 | WINED3DFMT_FLAG_BUMPMAP
,
1351 WINED3D_GL_EXT_NONE
, convert_r8g8b8a8_snorm
},
1352 {WINED3DFMT_R8G8B8A8_SNORM
, GL_SIGNED_RGBA8_NV
, GL_SIGNED_RGBA8_NV
, 0,
1353 GL_RGBA
, GL_BYTE
, 0,
1354 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1355 | WINED3DFMT_FLAG_BUMPMAP
,
1356 NV_TEXTURE_SHADER
, NULL
},
1357 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8_SNORM
, GL_RGBA8_SNORM
, 0,
1358 GL_RGBA
, GL_BYTE
, 0,
1359 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1360 | WINED3DFMT_FLAG_BUMPMAP
,
1361 EXT_TEXTURE_SNORM
, NULL
},
1362 {WINED3DFMT_R16G16_SNORM
, GL_RGB16
, GL_RGB16
, 0,
1363 GL_BGR
, GL_UNSIGNED_SHORT
, 6,
1364 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1365 | WINED3DFMT_FLAG_BUMPMAP
,
1366 WINED3D_GL_EXT_NONE
, convert_r16g16_snorm
},
1367 {WINED3DFMT_R16G16_SNORM
, GL_SIGNED_HILO16_NV
, GL_SIGNED_HILO16_NV
, 0,
1368 GL_HILO_NV
, GL_SHORT
, 0,
1369 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1370 | WINED3DFMT_FLAG_BUMPMAP
,
1371 NV_TEXTURE_SHADER
, NULL
},
1372 {WINED3DFMT_R16G16_SNORM
, GL_RG16_SNORM
, GL_RG16_SNORM
, 0,
1374 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1375 | WINED3DFMT_FLAG_BUMPMAP
,
1376 EXT_TEXTURE_SNORM
, NULL
},
1377 /* Depth stencil formats */
1378 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1379 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1380 WINED3DFMT_FLAG_DEPTH
,
1381 WINED3D_GL_EXT_NONE
, NULL
},
1382 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1383 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1384 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1385 ARB_DEPTH_TEXTURE
, NULL
},
1386 {WINED3DFMT_D32_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1387 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1388 WINED3DFMT_FLAG_DEPTH
,
1389 WINED3D_GL_EXT_NONE
, NULL
},
1390 {WINED3DFMT_D32_UNORM
, GL_DEPTH_COMPONENT32_ARB
, GL_DEPTH_COMPONENT32_ARB
, 0,
1391 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1392 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1393 ARB_DEPTH_TEXTURE
, NULL
},
1394 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1395 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1396 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1397 ARB_DEPTH_TEXTURE
, NULL
},
1398 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1399 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 4,
1400 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1401 EXT_PACKED_DEPTH_STENCIL
, convert_s1_uint_d15_unorm
},
1402 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1403 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 4,
1404 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1405 ARB_FRAMEBUFFER_OBJECT
, convert_s1_uint_d15_unorm
},
1406 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1407 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1408 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1409 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1410 ARB_DEPTH_TEXTURE
, NULL
},
1411 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1412 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 0,
1413 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1414 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1415 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1416 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1417 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1418 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1419 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1420 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1421 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1422 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1423 WINED3DFMT_FLAG_DEPTH
,
1424 WINED3D_GL_EXT_NONE
, NULL
},
1425 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1426 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1427 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1428 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1429 ARB_DEPTH_TEXTURE
, NULL
},
1430 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1431 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1432 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1433 ARB_DEPTH_TEXTURE
, NULL
},
1434 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1435 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 4,
1436 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1437 EXT_PACKED_DEPTH_STENCIL
, convert_s4x4_uint_d24_unorm
},
1438 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1439 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 4,
1440 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1441 ARB_FRAMEBUFFER_OBJECT
, convert_s4x4_uint_d24_unorm
},
1442 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1443 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1444 WINED3DFMT_FLAG_DEPTH
,
1445 WINED3D_GL_EXT_NONE
, NULL
},
1446 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1447 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1448 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1449 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1450 ARB_DEPTH_TEXTURE
, NULL
},
1451 {WINED3DFMT_D32_FLOAT
, GL_DEPTH_COMPONENT32F
, GL_DEPTH_COMPONENT32F
, 0,
1452 GL_DEPTH_COMPONENT
, GL_FLOAT
, 0,
1453 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1454 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1455 {WINED3DFMT_S8_UINT_D24_FLOAT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1456 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 8,
1457 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1458 ARB_DEPTH_BUFFER_FLOAT
, convert_s8_uint_d24_float
},
1459 {WINED3DFMT_R32G32B32A32_UINT
, GL_RGBA32UI
, GL_RGBA32UI
, 0,
1460 GL_RGBA_INTEGER
, GL_UNSIGNED_INT
, 0,
1461 WINED3DFMT_FLAG_TEXTURE
,
1462 EXT_TEXTURE_INTEGER
, NULL
},
1463 {WINED3DFMT_R32G32B32A32_SINT
, GL_RGBA32I
, GL_RGBA32I
, 0,
1464 GL_RGBA_INTEGER
, GL_INT
, 0,
1465 WINED3DFMT_FLAG_TEXTURE
,
1466 EXT_TEXTURE_INTEGER
, NULL
},
1467 /* Vendor-specific formats */
1468 {WINED3DFMT_ATI1N
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1469 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1470 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1471 | WINED3DFMT_FLAG_COMPRESSED
,
1472 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1473 {WINED3DFMT_ATI2N
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, 0,
1474 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1475 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1476 | WINED3DFMT_FLAG_COMPRESSED
,
1477 ATI_TEXTURE_COMPRESSION_3DC
, NULL
},
1478 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1479 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1480 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1481 | WINED3DFMT_FLAG_COMPRESSED
,
1482 EXT_TEXTURE_COMPRESSION_RGTC
, NULL
},
1483 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1484 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1485 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1486 | WINED3DFMT_FLAG_COMPRESSED
,
1487 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1488 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1489 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 0,
1490 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1491 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
,
1492 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1493 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1494 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1495 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1496 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
,
1497 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1498 {WINED3DFMT_NULL
, 0, 0, 0,
1499 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1500 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
,
1501 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1504 struct wined3d_format_srgb_info
1506 enum wined3d_format_id srgb_format_id
;
1507 enum wined3d_format_id base_format_id
;
1510 static const struct wined3d_format_srgb_info format_srgb_info
[] =
1512 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, WINED3DFMT_R8G8B8A8_UNORM
},
1513 {WINED3DFMT_BC1_UNORM_SRGB
, WINED3DFMT_BC1_UNORM
},
1514 {WINED3DFMT_BC2_UNORM_SRGB
, WINED3DFMT_BC2_UNORM
},
1515 {WINED3DFMT_BC3_UNORM_SRGB
, WINED3DFMT_BC3_UNORM
},
1516 {WINED3DFMT_B8G8R8A8_UNORM_SRGB
, WINED3DFMT_B8G8R8A8_UNORM
},
1517 {WINED3DFMT_B8G8R8X8_UNORM_SRGB
, WINED3DFMT_B8G8R8X8_UNORM
},
1518 {WINED3DFMT_BC7_UNORM_SRGB
, WINED3DFMT_BC7_UNORM
},
1521 static inline int get_format_idx(enum wined3d_format_id format_id
)
1525 if (format_id
< WINED3D_FORMAT_FOURCC_BASE
)
1528 for (i
= 0; i
< ARRAY_SIZE(format_index_remap
); ++i
)
1530 if (format_index_remap
[i
].id
== format_id
)
1531 return format_index_remap
[i
].idx
;
1537 static void format_set_flag(struct wined3d_format
*format
, unsigned int flag
)
1541 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1542 format
->flags
[i
] |= flag
;
1545 static void format_clear_flag(struct wined3d_format
*format
, unsigned int flag
)
1549 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1550 format
->flags
[i
] &= ~flag
;
1553 static enum wined3d_channel_type
map_channel_type(char t
)
1558 return WINED3D_CHANNEL_TYPE_UNORM
;
1560 return WINED3D_CHANNEL_TYPE_SNORM
;
1562 return WINED3D_CHANNEL_TYPE_UINT
;
1564 return WINED3D_CHANNEL_TYPE_SINT
;
1566 return WINED3D_CHANNEL_TYPE_FLOAT
;
1568 return WINED3D_CHANNEL_TYPE_DEPTH
;
1570 return WINED3D_CHANNEL_TYPE_STENCIL
;
1572 ERR("Invalid channel type '%c'.\n", t
);
1573 return WINED3D_CHANNEL_TYPE_NONE
;
1577 static BOOL
init_format_base_info(struct wined3d_gl_info
*gl_info
)
1581 gl_info
->format_count
= WINED3D_FORMAT_COUNT
;
1582 if (!(gl_info
->formats
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1583 gl_info
->format_count
* sizeof(*gl_info
->formats
))))
1585 ERR("Failed to allocate memory.\n");
1589 for (i
= 0; i
< ARRAY_SIZE(formats
); ++i
)
1591 struct wined3d_format
*format
;
1594 fmt_idx
= get_format_idx(formats
[i
].id
);
1597 ERR("Could not allocate index for format %s %#x.\n",
1598 debug_d3dformat(formats
[i
].id
), formats
[i
].id
);
1601 format
= &gl_info
->formats
[fmt_idx
];
1603 format
->id
= formats
[i
].id
;
1604 format
->red_size
= formats
[i
].red_size
;
1605 format
->green_size
= formats
[i
].green_size
;
1606 format
->blue_size
= formats
[i
].blue_size
;
1607 format
->alpha_size
= formats
[i
].alpha_size
;
1608 format
->red_offset
= formats
[i
].red_offset
;
1609 format
->green_offset
= formats
[i
].green_offset
;
1610 format
->blue_offset
= formats
[i
].blue_offset
;
1611 format
->alpha_offset
= formats
[i
].alpha_offset
;
1612 format
->byte_count
= formats
[i
].bpp
;
1613 format
->depth_size
= formats
[i
].depth_size
;
1614 format
->stencil_size
= formats
[i
].stencil_size
;
1615 format
->block_width
= 1;
1616 format
->block_height
= 1;
1617 format
->block_byte_count
= formats
[i
].bpp
;
1620 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
1622 const struct wined3d_format
*typeless_format
;
1623 struct wined3d_format
*format
;
1627 fmt_idx
= get_format_idx(typed_formats
[i
].id
);
1630 ERR("Could not allocate index for format %s %#x.\n",
1631 debug_d3dformat(typed_formats
[i
].id
), typed_formats
[i
].id
);
1634 format
= &gl_info
->formats
[fmt_idx
];
1636 typeless_format
= wined3d_get_format(gl_info
, typed_formats
[i
].typeless_id
);
1637 if (typeless_format
->id
== WINED3DFMT_UNKNOWN
)
1639 ERR("Typeless format %s (%#x) not found.\n",
1640 debug_d3dformat(typed_formats
[i
].typeless_id
), typed_formats
[i
].typeless_id
);
1644 format
->id
= typed_formats
[i
].id
;
1645 format
->red_size
= typeless_format
->red_size
;
1646 format
->green_size
= typeless_format
->green_size
;
1647 format
->blue_size
= typeless_format
->blue_size
;
1648 format
->alpha_size
= typeless_format
->alpha_size
;
1649 format
->red_offset
= typeless_format
->red_offset
;
1650 format
->green_offset
= typeless_format
->green_offset
;
1651 format
->blue_offset
= typeless_format
->blue_offset
;
1652 format
->alpha_offset
= typeless_format
->alpha_offset
;
1653 format
->byte_count
= typeless_format
->byte_count
;
1654 format
->depth_size
= typeless_format
->depth_size
;
1655 format
->stencil_size
= typeless_format
->stencil_size
;
1656 format
->block_width
= typeless_format
->block_width
;
1657 format
->block_height
= typeless_format
->block_height
;
1658 format
->block_byte_count
= typeless_format
->block_byte_count
;
1660 for (j
= 0; j
< strlen(typed_formats
[i
].channels
); ++j
)
1662 enum wined3d_channel_type channel_type
= map_channel_type(typed_formats
[i
].channels
[j
]);
1663 if (channel_type
== WINED3D_CHANNEL_TYPE_UINT
|| channel_type
== WINED3D_CHANNEL_TYPE_SINT
)
1664 flags
|= WINED3DFMT_FLAG_INTEGER
;
1665 if (channel_type
== WINED3D_CHANNEL_TYPE_FLOAT
)
1666 flags
|= WINED3DFMT_FLAG_FLOAT
;
1669 format_set_flag(format
, flags
);
1672 for (i
= 0; i
< ARRAY_SIZE(ddi_formats
); ++i
)
1674 int fmt_idx
= get_format_idx(ddi_formats
[i
].id
);
1678 ERR("Format %s (%#x) not found.\n", debug_d3dformat(ddi_formats
[i
].id
), ddi_formats
[i
].id
);
1682 gl_info
->formats
[fmt_idx
].ddi_format
= ddi_formats
[i
].ddi_format
;
1685 for (i
= 0; i
< ARRAY_SIZE(format_base_flags
); ++i
)
1687 int fmt_idx
= get_format_idx(format_base_flags
[i
].id
);
1691 ERR("Format %s (%#x) not found.\n",
1692 debug_d3dformat(format_base_flags
[i
].id
), format_base_flags
[i
].id
);
1696 format_set_flag(&gl_info
->formats
[fmt_idx
], format_base_flags
[i
].flags
);
1702 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
1706 static BOOL
init_format_block_info(struct wined3d_gl_info
*gl_info
)
1710 for (i
= 0; i
< (sizeof(format_block_info
) / sizeof(*format_block_info
)); ++i
)
1712 struct wined3d_format
*format
;
1713 int fmt_idx
= get_format_idx(format_block_info
[i
].id
);
1717 ERR("Format %s (%#x) not found.\n",
1718 debug_d3dformat(format_block_info
[i
].id
), format_block_info
[i
].id
);
1722 format
= &gl_info
->formats
[fmt_idx
];
1723 format
->block_width
= format_block_info
[i
].block_width
;
1724 format
->block_height
= format_block_info
[i
].block_height
;
1725 format
->block_byte_count
= format_block_info
[i
].block_byte_count
;
1726 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_BLOCKS
);
1727 if (!format_block_info
[i
].verify
)
1728 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
);
1734 static GLenum
wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type
)
1738 case WINED3D_GL_RES_TYPE_TEX_1D
:
1739 return GL_TEXTURE_1D
;
1740 case WINED3D_GL_RES_TYPE_TEX_2D
:
1741 return GL_TEXTURE_2D
;
1742 case WINED3D_GL_RES_TYPE_TEX_3D
:
1743 return GL_TEXTURE_3D
;
1744 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1745 return GL_TEXTURE_CUBE_MAP_ARB
;
1746 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1747 return GL_TEXTURE_RECTANGLE_ARB
;
1748 case WINED3D_GL_RES_TYPE_BUFFER
:
1749 return GL_TEXTURE_2D
; /* TODO: GL_TEXTURE_BUFFER. */
1750 case WINED3D_GL_RES_TYPE_RB
:
1751 return GL_RENDERBUFFER
;
1752 case WINED3D_GL_RES_TYPE_COUNT
:
1755 ERR("Unexpected GL resource type %u.\n", type
);
1759 static void delete_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
1760 enum wined3d_gl_resource_type d3d_type
, GLuint object
)
1764 case WINED3D_GL_RES_TYPE_TEX_1D
:
1765 case WINED3D_GL_RES_TYPE_TEX_2D
:
1766 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1767 case WINED3D_GL_RES_TYPE_TEX_3D
:
1768 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1769 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &object
);
1772 case WINED3D_GL_RES_TYPE_RB
:
1773 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &object
);
1776 case WINED3D_GL_RES_TYPE_BUFFER
:
1777 case WINED3D_GL_RES_TYPE_COUNT
:
1782 /* Context activation is done by the caller. */
1783 static void create_and_bind_fbo_attachment(const struct wined3d_gl_info
*gl_info
, unsigned int flags
,
1784 enum wined3d_gl_resource_type d3d_type
, GLuint
*object
, GLenum internal
, GLenum format
, GLenum type
)
1786 GLenum attach_type
= flags
& WINED3DFMT_FLAG_DEPTH
?
1787 GL_DEPTH_ATTACHMENT
: GL_COLOR_ATTACHMENT0
;
1791 case WINED3D_GL_RES_TYPE_TEX_1D
:
1792 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1793 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, *object
);
1794 gl_info
->gl_ops
.gl
.p_glTexImage1D(GL_TEXTURE_1D
, 0, internal
, 16, 0, format
, type
, NULL
);
1795 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1796 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1798 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_1D
,
1800 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1801 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_TEXTURE_1D
,
1805 case WINED3D_GL_RES_TYPE_TEX_2D
:
1806 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1807 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1808 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(d3d_type
), *object
);
1809 gl_info
->gl_ops
.gl
.p_glTexImage2D(wined3d_gl_type_to_enum(d3d_type
), 0, internal
, 16, 16, 0,
1810 format
, type
, NULL
);
1811 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1812 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1814 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
1815 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
1816 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1817 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1818 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
1821 case WINED3D_GL_RES_TYPE_TEX_3D
:
1822 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1823 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_3D
, *object
);
1824 GL_EXTCALL(glTexImage3D
)(GL_TEXTURE_3D
, 0, internal
, 16, 16, 16, 0,
1825 format
, type
, NULL
);
1826 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1827 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1829 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, attach_type
,
1830 GL_TEXTURE_3D
, *object
, 0, 0);
1831 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1832 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1833 GL_TEXTURE_3D
, *object
, 0, 0);
1836 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1837 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1838 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, *object
);
1839 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, internal
, 16, 16, 0,
1840 format
, type
, NULL
);
1841 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
, 0, internal
, 16, 16, 0,
1842 format
, type
, NULL
);
1843 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
, 0, internal
, 16, 16, 0,
1844 format
, type
, NULL
);
1845 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
, 0, internal
, 16, 16, 0,
1846 format
, type
, NULL
);
1847 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
, 0, internal
, 16, 16, 0,
1848 format
, type
, NULL
);
1849 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
, 0, internal
, 16, 16, 0,
1850 format
, type
, NULL
);
1851 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1852 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1854 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
1855 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
1856 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1857 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1858 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
1861 case WINED3D_GL_RES_TYPE_RB
:
1862 gl_info
->fbo_ops
.glGenRenderbuffers(1, object
);
1863 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, *object
);
1864 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, internal
, 16, 16);
1865 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, attach_type
, GL_RENDERBUFFER
,
1867 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1868 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
,
1872 case WINED3D_GL_RES_TYPE_BUFFER
:
1873 case WINED3D_GL_RES_TYPE_COUNT
:
1877 /* Ideally we'd skip all formats already known not to work on textures
1878 * by checking for WINED3DFMT_FLAG_TEXTURE here. However, we want to
1879 * know if we can attach WINED3DFMT_P8_UINT textures to FBOs, and this
1880 * format never has WINED3DFMT_FLAG_TEXTURE set. Instead, swallow GL
1881 * errors generated by invalid formats. */
1882 while (gl_info
->gl_ops
.gl
.p_glGetError());
1885 static void draw_test_quad(struct wined3d_caps_gl_ctx
*ctx
, const struct wined3d_vec3
*geometry
,
1886 const struct wined3d_color
*color
)
1888 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
1889 static const struct wined3d_vec3 default_geometry
[] =
1891 {-1.0f
, -1.0f
, 0.0f
},
1892 { 1.0f
, -1.0f
, 0.0f
},
1893 {-1.0f
, 1.0f
, 0.0f
},
1894 { 1.0f
, 1.0f
, 0.0f
},
1896 static const char vs_core_header
[] =
1900 "out vec4 out_color;\n"
1902 static const char vs_legacy_header
[] =
1904 "attribute vec4 pos;\n"
1905 "attribute vec4 color;\n"
1906 "varying vec4 out_color;\n"
1908 static const char vs_body
[] =
1911 " gl_Position = pos;\n"
1912 " out_color = color;\n"
1914 static const char fs_core
[] =
1916 "in vec4 out_color;\n"
1917 "out vec4 fragment_color;\n"
1921 " fragment_color = out_color;\n"
1923 static const char fs_legacy
[] =
1925 "varying vec4 out_color;\n"
1929 " gl_FragData[0] = out_color;\n"
1931 const char *source
[2];
1932 GLuint vs_id
, fs_id
;
1936 geometry
= default_geometry
;
1938 if (!gl_info
->supported
[ARB_VERTEX_BUFFER_OBJECT
] || !gl_info
->supported
[ARB_VERTEX_SHADER
]
1939 || !gl_info
->supported
[ARB_FRAGMENT_SHADER
])
1941 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
1942 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
1943 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
1944 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
1945 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
1947 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
1948 gl_info
->gl_ops
.gl
.p_glColor4f(color
->r
, color
->g
, color
->b
, color
->a
);
1949 for (i
= 0; i
< 4; ++i
)
1950 gl_info
->gl_ops
.gl
.p_glVertex3fv(&geometry
[i
].x
);
1951 gl_info
->gl_ops
.gl
.p_glEnd();
1952 checkGLcall("Drawing a quad");
1957 GL_EXTCALL(glGenBuffers(1, &ctx
->test_vbo
));
1958 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, ctx
->test_vbo
));
1959 GL_EXTCALL(glBufferData(GL_ARRAY_BUFFER
, sizeof(struct wined3d_vec3
) * 4, geometry
, GL_STREAM_DRAW
));
1960 GL_EXTCALL(glVertexAttribPointer(0, 3, GL_FLOAT
, FALSE
, 0, NULL
));
1961 GL_EXTCALL(glVertexAttrib4f(1, color
->r
, color
->g
, color
->b
, color
->a
));
1962 GL_EXTCALL(glEnableVertexAttribArray(0));
1963 GL_EXTCALL(glDisableVertexAttribArray(1));
1965 if (!ctx
->test_program_id
)
1967 ctx
->test_program_id
= GL_EXTCALL(glCreateProgram());
1969 vs_id
= GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER
));
1970 source
[0] = gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? vs_legacy_header
: vs_core_header
;
1971 source
[1] = vs_body
;
1972 GL_EXTCALL(glShaderSource(vs_id
, 2, source
, NULL
));
1973 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, vs_id
));
1974 GL_EXTCALL(glDeleteShader(vs_id
));
1976 fs_id
= GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER
));
1977 source
[0] = gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? fs_legacy
: fs_core
;
1978 GL_EXTCALL(glShaderSource(fs_id
, 1, source
, NULL
));
1979 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, fs_id
));
1980 GL_EXTCALL(glDeleteShader(fs_id
));
1982 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 0, "pos"));
1983 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 1, "color"));
1985 GL_EXTCALL(glCompileShader(vs_id
));
1986 print_glsl_info_log(gl_info
, vs_id
, FALSE
);
1987 GL_EXTCALL(glCompileShader(fs_id
));
1988 print_glsl_info_log(gl_info
, fs_id
, FALSE
);
1989 GL_EXTCALL(glLinkProgram(ctx
->test_program_id
));
1990 shader_glsl_validate_link(gl_info
, ctx
->test_program_id
);
1992 GL_EXTCALL(glUseProgram(ctx
->test_program_id
));
1994 gl_info
->gl_ops
.gl
.p_glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
1996 GL_EXTCALL(glUseProgram(0));
1997 GL_EXTCALL(glDisableVertexAttribArray(0));
1998 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, 0));
1999 checkGLcall("Drawing a quad");
2002 /* Context activation is done by the caller. */
2003 static void check_fbo_compat(struct wined3d_caps_gl_ctx
*ctx
, struct wined3d_format
*format
)
2005 /* Check if the default internal format is supported as a frame buffer
2006 * target, otherwise fall back to the render target internal.
2008 * Try to stick to the standard format if possible, this limits precision differences. */
2009 static const struct wined3d_color black
= {0.0f
, 0.0f
, 0.0f
, 1.0f
};
2010 static const struct wined3d_color half_transparent_red
= {1.0f
, 0.0f
, 0.0f
, 0.5f
};
2011 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2012 GLenum status
, rt_internal
= format
->rtInternal
;
2013 GLuint object
, color_rb
;
2014 enum wined3d_gl_resource_type type
;
2015 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2017 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2019 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
2021 const char *type_string
= "color";
2023 if (type
== WINED3D_GL_RES_TYPE_BUFFER
)
2026 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->glInternal
,
2027 format
->glFormat
, format
->glType
);
2029 if (format
->flags
[type
] & (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2031 gl_info
->fbo_ops
.glGenRenderbuffers(1, &color_rb
);
2032 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, color_rb
);
2033 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2034 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 1);
2036 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 16);
2038 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
2039 GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, color_rb
);
2040 checkGLcall("Create and attach color rb attachment");
2041 type_string
= "depth / stencil";
2044 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2045 checkGLcall("Framebuffer format check");
2047 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2049 TRACE("Format %s is supported as FBO %s attachment, type %u.\n",
2050 debug_d3dformat(format
->id
), type_string
, type
);
2051 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2052 format
->rtInternal
= format
->glInternal
;
2053 regular_fmt_used
= TRUE
;
2059 if (format
->flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
2061 WARN("Format %s with rendertarget flag is not supported as FBO color attachment (type %u),"
2062 " and no fallback specified.\n", debug_d3dformat(format
->id
), type
);
2063 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2067 TRACE("Format %s is not supported as FBO %s attachment, type %u.\n",
2068 debug_d3dformat(format
->id
), type_string
, type
);
2070 format
->rtInternal
= format
->glInternal
;
2074 TRACE("Format %s is not supported as FBO %s attachment (type %u),"
2075 " trying rtInternal format as fallback.\n",
2076 debug_d3dformat(format
->id
), type_string
, type
);
2078 while (gl_info
->gl_ops
.gl
.p_glGetError());
2080 delete_fbo_attachment(gl_info
, type
, object
);
2081 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->rtInternal
,
2082 format
->glFormat
, format
->glType
);
2084 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2085 checkGLcall("Framebuffer format check");
2087 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2089 TRACE("Format %s rtInternal format is supported as FBO %s attachment, type %u.\n",
2090 debug_d3dformat(format
->id
), type_string
, type
);
2091 fallback_fmt_used
= TRUE
;
2095 WARN("Format %s rtInternal format is not supported as FBO %s attachment, type %u.\n",
2096 debug_d3dformat(format
->id
), type_string
, type
);
2097 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2102 if (status
== GL_FRAMEBUFFER_COMPLETE
2103 && ((format
->flags
[type
] & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
)
2104 || !(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2105 && !(format
->flags
[type
] & WINED3DFMT_FLAG_INTEGER
)
2106 && format
->id
!= WINED3DFMT_NULL
&& format
->id
!= WINED3DFMT_P8_UINT
2107 && format
->glFormat
!= GL_LUMINANCE
&& format
->glFormat
!= GL_LUMINANCE_ALPHA
2108 && (format
->red_size
|| format
->alpha_size
))
2110 DWORD readback
[16 * 16 * 16], color
, r_range
, a_range
;
2115 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
]
2116 || gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2118 gl_info
->fbo_ops
.glGenRenderbuffers(1, &rb
);
2119 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
2120 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2121 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 1);
2123 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 16);
2124 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2125 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
2126 checkGLcall("RB attachment");
2129 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2130 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.0f
, 1.0f
);
2131 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
2132 if (gl_info
->gl_ops
.gl
.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION
)
2134 while (gl_info
->gl_ops
.gl
.p_glGetError());
2135 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2136 debug_d3dformat(format
->id
), type
);
2137 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2141 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2142 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
2143 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2145 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 16);
2146 gl_info
->gl_ops
.gl
.p_glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
2148 draw_test_quad(ctx
, NULL
, &black
);
2150 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
2152 draw_test_quad(ctx
, NULL
, &half_transparent_red
);
2154 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
2158 case WINED3D_GL_RES_TYPE_TEX_1D
:
2159 /* Rebinding texture to workaround a fglrx bug. */
2160 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, object
);
2161 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_1D
, 0, GL_BGRA
,
2162 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2163 color
= readback
[7];
2166 case WINED3D_GL_RES_TYPE_TEX_2D
:
2167 case WINED3D_GL_RES_TYPE_TEX_3D
:
2168 case WINED3D_GL_RES_TYPE_TEX_RECT
:
2169 /* Rebinding texture to workaround a fglrx bug. */
2170 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(type
), object
);
2171 gl_info
->gl_ops
.gl
.p_glGetTexImage(wined3d_gl_type_to_enum(type
), 0, GL_BGRA
,
2172 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2173 color
= readback
[7 * 16 + 7];
2176 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
2177 /* Rebinding texture to workaround a fglrx bug. */
2178 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, object
);
2179 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, GL_BGRA
,
2180 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2181 color
= readback
[7 * 16 + 7];
2184 case WINED3D_GL_RES_TYPE_RB
:
2185 gl_info
->gl_ops
.gl
.p_glReadPixels(0, 0, 16, 16,
2186 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2187 color
= readback
[7 * 16 + 7];
2190 case WINED3D_GL_RES_TYPE_BUFFER
:
2191 case WINED3D_GL_RES_TYPE_COUNT
:
2195 checkGLcall("Post-pixelshader blending check");
2198 r
= (color
& 0x00ff0000u
) >> 16;
2200 r_range
= format
->red_size
< 8 ? 1u << (8 - format
->red_size
) : 1;
2201 a_range
= format
->alpha_size
< 8 ? 1u << (8 - format
->alpha_size
) : 1;
2202 if (format
->red_size
&& (r
< 0x7f - r_range
|| r
> 0x7f + r_range
))
2204 else if (format
->alpha_size
> 1 && (a
< 0xbf - a_range
|| a
> 0xbf + a_range
))
2208 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
2209 debug_d3dformat(format
->id
), type
);
2210 TRACE("Color output: %#x\n", color
);
2211 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2215 TRACE("Format %s supports post-pixelshader blending, type %u.\n",
2216 debug_d3dformat(format
->id
), type
);
2217 TRACE("Color output: %#x\n", color
);
2218 format
->flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2222 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
]
2223 || gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
2225 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2226 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, 0);
2227 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &rb
);
2228 checkGLcall("RB cleanup");
2232 if (format
->glInternal
!= format
->glGammaInternal
)
2234 delete_fbo_attachment(gl_info
, type
, object
);
2235 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->glGammaInternal
,
2236 format
->glFormat
, format
->glType
);
2238 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
2239 checkGLcall("Framebuffer format check");
2241 if (status
== GL_FRAMEBUFFER_COMPLETE
)
2243 TRACE("Format %s's sRGB format is FBO attachable, type %u.\n",
2244 debug_d3dformat(format
->id
), type
);
2245 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2249 WARN("Format %s's sRGB format is not FBO attachable, type %u.\n",
2250 debug_d3dformat(format
->id
), type
);
2253 else if (status
== GL_FRAMEBUFFER_COMPLETE
)
2254 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2256 if (format
->flags
[type
] & (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2258 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, 0);
2259 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &color_rb
);
2262 delete_fbo_attachment(gl_info
, type
, object
);
2263 checkGLcall("Framebuffer format check cleaup");
2266 if (fallback_fmt_used
&& regular_fmt_used
)
2268 FIXME("Format %s needs different render target formats for different resource types.\n",
2269 debug_d3dformat(format
->id
));
2270 format_clear_flag(format
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
2271 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2275 static void query_format_flag(struct wined3d_gl_info
*gl_info
, struct wined3d_format
*format
,
2276 GLint internal
, GLenum pname
, DWORD flag
, const char *string
)
2279 enum wined3d_gl_resource_type type
;
2281 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
2283 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
), internal
, pname
, 1, &value
);
2284 if (value
== GL_FULL_SUPPORT
)
2286 TRACE("Format %s supports %s, resource type %u.\n", debug_d3dformat(format
->id
), string
, type
);
2287 format
->flags
[type
] |= flag
;
2291 TRACE("Format %s doesn't support %s, resource type %u.\n", debug_d3dformat(format
->id
), string
, type
);
2292 format
->flags
[type
] &= ~flag
;
2297 /* Context activation is done by the caller. */
2298 static void init_format_fbo_compat_info(struct wined3d_caps_gl_ctx
*ctx
)
2300 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2301 unsigned int i
, type
;
2304 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2306 for (i
= 0; i
< gl_info
->format_count
; ++i
)
2309 struct wined3d_format
*format
= &gl_info
->formats
[i
];
2310 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
2311 GLenum rt_internal
= format
->rtInternal
;
2313 if (!format
->glInternal
)
2316 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
2318 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2319 format
->glInternal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2320 if (value
== GL_FULL_SUPPORT
)
2322 TRACE("Format %s is supported as FBO color attachment, resource type %u.\n",
2323 debug_d3dformat(format
->id
), type
);
2324 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2325 format
->rtInternal
= format
->glInternal
;
2326 regular_fmt_used
= TRUE
;
2328 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2329 format
->glInternal
, GL_FRAMEBUFFER_BLEND
, 1, &value
);
2330 if (value
== GL_FULL_SUPPORT
)
2332 TRACE("Format %s supports post-pixelshader blending, resource type %u.\n",
2333 debug_d3dformat(format
->id
), type
);
2334 format
->flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2338 TRACE("Format %s doesn't support post-pixelshader blending, resource typed %u.\n",
2339 debug_d3dformat(format
->id
), type
);
2340 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2347 if (format
->flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
2349 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
2350 " and no fallback specified, resource type %u.\n",
2351 debug_d3dformat(format
->id
), type
);
2352 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2355 TRACE("Format %s is not supported as FBO color attachment,"
2356 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2357 format
->rtInternal
= format
->glInternal
;
2361 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2362 rt_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2363 if (value
== GL_FULL_SUPPORT
)
2365 TRACE("Format %s rtInternal format is supported as FBO color attachment,"
2366 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2367 fallback_fmt_used
= TRUE
;
2371 WARN("Format %s rtInternal format is not supported as FBO color attachment,"
2372 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2373 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2378 if (format
->glInternal
!= format
->glGammaInternal
)
2380 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2381 format
->glGammaInternal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2382 if (value
== GL_FULL_SUPPORT
)
2384 TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n",
2385 debug_d3dformat(format
->id
), type
);
2386 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2390 WARN("Format %s's sRGB format is not FBO attachable, resource type %u.\n",
2391 debug_d3dformat(format
->id
), type
);
2394 else if (format
->flags
[type
] & WINED3DFMT_FLAG_FBO_ATTACHABLE
)
2395 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2398 if (fallback_fmt_used
&& regular_fmt_used
)
2400 FIXME("Format %s needs different render target formats for different resource types.\n",
2401 debug_d3dformat(format
->id
));
2402 format_clear_flag(format
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
2403 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2409 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2411 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2412 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2413 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2414 gl_info
->gl_ops
.gl
.p_glReadBuffer(GL_COLOR_ATTACHMENT0
);
2417 for (i
= 0; i
< gl_info
->format_count
; ++i
)
2419 struct wined3d_format
*format
= &gl_info
->formats
[i
];
2421 if (!format
->glInternal
) continue;
2423 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_COMPRESSED
)
2425 TRACE("Skipping format %s because it's a compressed format.\n",
2426 debug_d3dformat(format
->id
));
2430 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2432 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format
->id
));
2433 check_fbo_compat(ctx
, format
);
2437 format
->rtInternal
= format
->glInternal
;
2441 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2442 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2445 static void query_internal_format(struct wined3d_adapter
*adapter
,
2446 struct wined3d_format
*format
, const struct wined3d_format_texture_info
*texture_info
,
2447 struct wined3d_gl_info
*gl_info
, BOOL srgb_write_supported
, BOOL srgb_format
)
2449 GLint count
, multisample_types
[MAX_MULTISAMPLE_TYPES
];
2450 unsigned int i
, max_log2
;
2452 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2454 query_format_flag(gl_info
, format
, format
->glInternal
, GL_VERTEX_TEXTURE
,
2455 WINED3DFMT_FLAG_VTF
, "vertex texture usage");
2456 query_format_flag(gl_info
, format
, format
->glInternal
, GL_FILTER
,
2457 WINED3DFMT_FLAG_FILTERING
, "filtering");
2459 if (srgb_format
|| format
->glGammaInternal
!= format
->glInternal
)
2461 query_format_flag(gl_info
, format
, format
->glGammaInternal
, GL_SRGB_READ
,
2462 WINED3DFMT_FLAG_SRGB_READ
, "sRGB read");
2464 if (srgb_write_supported
)
2465 query_format_flag(gl_info
, format
, format
->glGammaInternal
, GL_SRGB_WRITE
,
2466 WINED3DFMT_FLAG_SRGB_WRITE
, "sRGB write");
2468 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2470 if (!(format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & (WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
)))
2471 format
->glGammaInternal
= format
->glInternal
;
2472 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2473 format
->glInternal
= format
->glGammaInternal
;
2478 if (!gl_info
->limits
.vertex_samplers
)
2479 format_clear_flag(format
, WINED3DFMT_FLAG_VTF
);
2481 if (!(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2482 format_set_flag(format
, WINED3DFMT_FLAG_FILTERING
);
2483 else if (format
->id
!= WINED3DFMT_R32G32B32A32_FLOAT
&& format
->id
!= WINED3DFMT_R32_FLOAT
)
2484 format_clear_flag(format
, WINED3DFMT_FLAG_VTF
);
2486 if (srgb_format
|| format
->glGammaInternal
!= format
->glInternal
)
2488 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
2489 if (!gl_info
->supported
[EXT_TEXTURE_SRGB
])
2491 format
->glGammaInternal
= format
->glInternal
;
2492 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2494 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2496 format
->glInternal
= format
->glGammaInternal
;
2500 if ((format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_SRGB_WRITE
) && !srgb_write_supported
)
2501 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2503 if (!gl_info
->supported
[ARB_DEPTH_TEXTURE
]
2504 && texture_info
->flags
& (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2506 format
->flags
[WINED3D_GL_RES_TYPE_TEX_1D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2507 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2508 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2509 format
->flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2510 format
->flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2514 if (format
->glInternal
&& format
->flags
[WINED3D_GL_RES_TYPE_RB
]
2515 & (WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2517 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY
])
2519 GL_EXTCALL(glGetInternalformativ(GL_RENDERBUFFER
, format
->glInternal
,
2520 GL_NUM_SAMPLE_COUNTS
, 1, &count
));
2521 checkGLcall("glGetInternalformativ(GL_NUM_SAMPLE_COUNTS)");
2522 count
= min(count
, MAX_MULTISAMPLE_TYPES
);
2523 GL_EXTCALL(glGetInternalformativ(GL_RENDERBUFFER
, format
->glInternal
,
2524 GL_SAMPLES
, count
, multisample_types
));
2525 checkGLcall("glGetInternalformativ(GL_SAMPLES)");
2526 for (i
= 0; i
< count
; ++i
)
2528 if (multisample_types
[i
] > sizeof(format
->multisample_types
) * 8)
2530 format
->multisample_types
|= 1u << (multisample_types
[i
] - 1);
2535 max_log2
= wined3d_log2i(min(gl_info
->limits
.samples
,
2536 sizeof(format
->multisample_types
) * 8));
2537 for (i
= 1; i
<= max_log2
; ++i
)
2538 format
->multisample_types
|= 1u << ((1u << i
) - 1);
2543 static BOOL
init_format_texture_info(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
2545 struct fragment_caps fragment_caps
;
2546 struct shader_caps shader_caps
;
2550 adapter
->fragment_pipe
->get_caps(gl_info
, &fragment_caps
);
2551 adapter
->shader_backend
->shader_get_caps(gl_info
, &shader_caps
);
2552 srgb_write
= (fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_SRGB_WRITE
)
2553 && (shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_SRGB_WRITE
);
2555 for (i
= 0; i
< sizeof(format_texture_info
) / sizeof(*format_texture_info
); ++i
)
2557 int srgb_fmt_idx
= -1, fmt_idx
= get_format_idx(format_texture_info
[i
].id
);
2558 struct wined3d_format
*format
, *srgb_format
;
2562 ERR("Format %s (%#x) not found.\n",
2563 debug_d3dformat(format_texture_info
[i
].id
), format_texture_info
[i
].id
);
2567 if (!gl_info
->supported
[format_texture_info
[i
].extension
]) continue;
2569 format
= &gl_info
->formats
[fmt_idx
];
2571 /* ARB_texture_rg defines floating point formats, but only if
2572 * ARB_texture_float is also supported. */
2573 if (!gl_info
->supported
[ARB_TEXTURE_FLOAT
]
2574 && (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_FLOAT
))
2577 /* ARB_texture_rg defines integer formats if EXT_texture_integer is also supported. */
2578 if (!gl_info
->supported
[EXT_TEXTURE_INTEGER
]
2579 && (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_INTEGER
))
2582 format
->glInternal
= format_texture_info
[i
].gl_internal
;
2583 format
->glGammaInternal
= format_texture_info
[i
].gl_srgb_internal
;
2584 format
->rtInternal
= format_texture_info
[i
].gl_rt_internal
;
2585 format
->glFormat
= format_texture_info
[i
].gl_format
;
2586 format
->glType
= format_texture_info
[i
].gl_type
;
2587 format
->color_fixup
= COLOR_FIXUP_IDENTITY
;
2588 format
->height_scale
.numerator
= 1;
2589 format
->height_scale
.denominator
= 1;
2591 format
->flags
[WINED3D_GL_RES_TYPE_TEX_1D
] |= format_texture_info
[i
].flags
;
2592 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] |= format_texture_info
[i
].flags
;
2593 format
->flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= format_texture_info
[i
].flags
;
2595 /* GL_ARB_depth_texture does not support 3D textures. It also says "cube textures are
2596 * problematic", but doesn't explicitly mandate that an error is generated. */
2597 if (gl_info
->supported
[EXT_TEXTURE3D
]
2598 && !(format_texture_info
[i
].flags
& (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
)))
2599 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] |= format_texture_info
[i
].flags
;
2601 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
2602 format
->flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= format_texture_info
[i
].flags
;
2604 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
2605 format
->flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] |= format_texture_info
[i
].flags
;
2607 format
->flags
[WINED3D_GL_RES_TYPE_RB
] |= format_texture_info
[i
].flags
;
2608 format
->flags
[WINED3D_GL_RES_TYPE_RB
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2610 if (format
->glGammaInternal
!= format
->glInternal
2611 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
2613 format
->glGammaInternal
= format
->glInternal
;
2614 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2617 query_internal_format(adapter
, format
, &format_texture_info
[i
], gl_info
, srgb_write
, FALSE
);
2619 /* Texture conversion stuff */
2620 format
->convert
= format_texture_info
[i
].convert
;
2621 format
->conv_byte_count
= format_texture_info
[i
].conv_byte_count
;
2623 for (j
= 0; j
< sizeof(format_srgb_info
) / sizeof(*format_srgb_info
); ++j
)
2625 if (format_srgb_info
[j
].base_format_id
== format
->id
)
2627 srgb_fmt_idx
= get_format_idx(format_srgb_info
[j
].srgb_format_id
);
2628 if (srgb_fmt_idx
== -1)
2630 ERR("Format %s (%#x) not found.\n",
2631 debug_d3dformat(format_srgb_info
[j
].srgb_format_id
),
2632 format_srgb_info
[j
].srgb_format_id
);
2639 if (srgb_fmt_idx
== -1)
2642 srgb_format
= &gl_info
->formats
[srgb_fmt_idx
];
2644 *srgb_format
= *format
;
2645 srgb_format
->id
= format_srgb_info
[j
].srgb_format_id
;
2647 if (gl_info
->supported
[EXT_TEXTURE_SRGB
]
2648 && !(adapter
->d3d_info
.wined3d_creation_flags
& WINED3D_SRGB_READ_WRITE_CONTROL
))
2650 srgb_format
->glInternal
= format_texture_info
[i
].gl_srgb_internal
;
2651 srgb_format
->glGammaInternal
= format_texture_info
[i
].gl_srgb_internal
;
2652 format_set_flag(srgb_format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2653 query_internal_format(adapter
, srgb_format
, &format_texture_info
[i
], gl_info
, srgb_write
, TRUE
);
2660 static BOOL
color_match(DWORD c1
, DWORD c2
, BYTE max_diff
)
2662 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2664 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2666 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2668 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2672 /* A context is provided by the caller */
2673 static BOOL
check_filter(const struct wined3d_gl_info
*gl_info
, GLenum internal
)
2675 static const DWORD data
[] = {0x00000000, 0xffffffff};
2676 GLuint tex
, fbo
, buffer
;
2677 DWORD readback
[16 * 1];
2680 /* Render a filtered texture and see what happens. This is intended to detect the lack of
2681 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
2682 * falling back to software. If this changes in the future this code will get fooled and
2683 * apps might hit the software path due to incorrectly advertised caps.
2685 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
2686 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
2687 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
2690 while (gl_info
->gl_ops
.gl
.p_glGetError());
2692 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &buffer
);
2693 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
2694 memset(readback
, 0x7e, sizeof(readback
));
2695 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 16, 1, 0,
2696 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, readback
);
2697 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2698 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2699 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
2700 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
2701 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
2703 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &tex
);
2704 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, tex
);
2705 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, internal
, 2, 1, 0,
2706 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, data
);
2707 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
2708 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
2709 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
2710 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
2711 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
2712 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
2714 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2715 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2716 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, buffer
, 0);
2717 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2719 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2720 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
2721 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
2722 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2723 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
2724 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2726 gl_info
->gl_ops
.gl
.p_glClearColor(0, 1, 0, 0);
2727 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
2729 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
2730 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 0.0);
2731 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, -1.0f
);
2732 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 0.0);
2733 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, -1.0f
);
2734 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 1.0);
2735 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, 1.0f
);
2736 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 1.0);
2737 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, 1.0f
);
2738 gl_info
->gl_ops
.gl
.p_glEnd();
2740 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
2741 memset(readback
, 0x7f, sizeof(readback
));
2742 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2743 if (color_match(readback
[6], 0xffffffff, 5) || color_match(readback
[6], 0x00000000, 5)
2744 || color_match(readback
[9], 0xffffffff, 5) || color_match(readback
[9], 0x00000000, 5))
2746 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
2747 readback
[6], readback
[9]);
2752 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
2753 readback
[6], readback
[9]);
2757 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
2758 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2759 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &tex
);
2760 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &buffer
);
2762 if (gl_info
->gl_ops
.gl
.p_glGetError())
2764 FIXME("Error during filtering test for format %x, returning no filtering\n", internal
);
2771 static void init_format_filter_info(struct wined3d_gl_info
*gl_info
, enum wined3d_pci_vendor vendor
)
2773 struct wined3d_format
*format
;
2774 unsigned int fmt_idx
, i
;
2775 static const enum wined3d_format_id fmts16
[] =
2777 WINED3DFMT_R16_FLOAT
,
2778 WINED3DFMT_R16G16_FLOAT
,
2779 WINED3DFMT_R16G16B16A16_FLOAT
,
2783 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2784 /* This was already handled by init_format_texture_info(). */
2787 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
2788 || !gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
2790 WARN("No FBO support, or no FBO ORM, guessing filter info from GL caps\n");
2791 if (vendor
== HW_VENDOR_NVIDIA
&& gl_info
->supported
[ARB_TEXTURE_FLOAT
])
2793 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
2796 else if (gl_info
->limits
.glsl_varyings
> 44)
2798 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
2803 TRACE("Assuming no float16 blending\n");
2809 for(i
= 0; i
< (sizeof(fmts16
) / sizeof(*fmts16
)); i
++)
2811 fmt_idx
= get_format_idx(fmts16
[i
]);
2812 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_FILTERING
);
2818 for(i
= 0; i
< (sizeof(fmts16
) / sizeof(*fmts16
)); i
++)
2820 fmt_idx
= get_format_idx(fmts16
[i
]);
2821 format
= &gl_info
->formats
[fmt_idx
];
2822 if (!format
->glInternal
) continue; /* Not supported by GL */
2824 filtered
= check_filter(gl_info
, gl_info
->formats
[fmt_idx
].glInternal
);
2827 TRACE("Format %s supports filtering\n", debug_d3dformat(fmts16
[i
]));
2828 format_set_flag(format
, WINED3DFMT_FLAG_FILTERING
);
2832 TRACE("Format %s does not support filtering\n", debug_d3dformat(fmts16
[i
]));
2837 static void apply_format_fixups(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
2842 idx
= get_format_idx(WINED3DFMT_R16_FLOAT
);
2843 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2844 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2846 idx
= get_format_idx(WINED3DFMT_R32_FLOAT
);
2847 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2848 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2850 idx
= get_format_idx(WINED3DFMT_R16G16_UNORM
);
2851 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2852 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2854 idx
= get_format_idx(WINED3DFMT_R16G16_FLOAT
);
2855 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2856 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2858 idx
= get_format_idx(WINED3DFMT_R32G32_FLOAT
);
2859 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2860 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2862 /* GL_ATI_envmap_bumpmap in theory supports R8G8_SNORM but is no longer supported by
2864 if (gl_info
->supported
[NV_TEXTURE_SHADER
] || gl_info
->supported
[EXT_TEXTURE_SNORM
])
2866 /* R8G8_SNORM and R16G16_SNORM need a fixup of the undefined blue channel. OpenGL
2867 * returns 0.0 when sampling from it, DirectX 1.0. So we always have in-shader
2868 * conversion for this format. */
2869 idx
= get_format_idx(WINED3DFMT_R8G8_SNORM
);
2870 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2871 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2872 idx
= get_format_idx(WINED3DFMT_R16G16_SNORM
);
2873 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2874 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2878 /* Emulate using unsigned formats. This requires load-time conversion in addition to the
2880 idx
= get_format_idx(WINED3DFMT_R8G8_SNORM
);
2881 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2882 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2883 idx
= get_format_idx(WINED3DFMT_R16G16_SNORM
);
2884 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2885 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2886 idx
= get_format_idx(WINED3DFMT_R8G8B8A8_SNORM
);
2887 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2888 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 1, CHANNEL_SOURCE_Z
, 1, CHANNEL_SOURCE_W
);
2889 idx
= get_format_idx(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
2890 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2891 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Z
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
);
2894 if (!gl_info
->supported
[NV_TEXTURE_SHADER
])
2896 idx
= get_format_idx(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
2897 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2898 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_Z
, 0, CHANNEL_SOURCE_W
);
2901 if (gl_info
->supported
[ARB_TEXTURE_COMPRESSION_RGTC
] || gl_info
->supported
[EXT_TEXTURE_COMPRESSION_RGTC
])
2903 idx
= get_format_idx(WINED3DFMT_ATI1N
);
2904 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2905 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
);
2907 idx
= get_format_idx(WINED3DFMT_ATI2N
);
2908 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2909 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2911 else if (gl_info
->supported
[ATI_TEXTURE_COMPRESSION_3DC
])
2913 idx
= get_format_idx(WINED3DFMT_ATI2N
);
2914 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2915 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_W
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2918 if (!gl_info
->supported
[APPLE_YCBCR_422
])
2920 idx
= get_format_idx(WINED3DFMT_YUY2
);
2921 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUY2
);
2923 idx
= get_format_idx(WINED3DFMT_UYVY
);
2924 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_UYVY
);
2927 idx
= get_format_idx(WINED3DFMT_YV12
);
2928 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_HEIGHT_SCALE
);
2929 gl_info
->formats
[idx
].height_scale
.numerator
= 3;
2930 gl_info
->formats
[idx
].height_scale
.denominator
= 2;
2931 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YV12
);
2933 idx
= get_format_idx(WINED3DFMT_NV12
);
2934 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_HEIGHT_SCALE
);
2935 gl_info
->formats
[idx
].height_scale
.numerator
= 3;
2936 gl_info
->formats
[idx
].height_scale
.denominator
= 2;
2937 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_NV12
);
2939 if (!gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
2941 idx
= get_format_idx(WINED3DFMT_A8_UNORM
);
2942 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2943 0, CHANNEL_SOURCE_ZERO
, 0, CHANNEL_SOURCE_ZERO
, 0, CHANNEL_SOURCE_ZERO
, 0, CHANNEL_SOURCE_X
);
2944 idx
= get_format_idx(WINED3DFMT_L8A8_UNORM
);
2945 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2946 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
);
2947 idx
= get_format_idx(WINED3DFMT_L4A4_UNORM
);
2948 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2949 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
);
2950 idx
= get_format_idx(WINED3DFMT_L16_UNORM
);
2951 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2952 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
);
2953 idx
= get_format_idx(WINED3DFMT_INTZ
);
2954 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2955 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
);
2958 if (gl_info
->supported
[ARB_TEXTURE_RG
])
2960 idx
= get_format_idx(WINED3DFMT_L8_UNORM
);
2961 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2962 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
);
2965 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
])
2967 idx
= get_format_idx(WINED3DFMT_P8_UINT
);
2968 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_P8
);
2971 if (gl_info
->supported
[ARB_VERTEX_ARRAY_BGRA
])
2973 idx
= get_format_idx(WINED3DFMT_B8G8R8A8_UNORM
);
2974 gl_info
->formats
[idx
].gl_vtx_format
= GL_BGRA
;
2977 if (gl_info
->supported
[ARB_HALF_FLOAT_VERTEX
])
2979 /* Do not change the size of the type, it is CPU side. We have to change the GPU-side information though.
2980 * It is the job of the vertex buffer code to make sure that the vbos have the right format */
2981 idx
= get_format_idx(WINED3DFMT_R16G16_FLOAT
);
2982 gl_info
->formats
[idx
].gl_vtx_type
= GL_HALF_FLOAT
; /* == GL_HALF_FLOAT_NV */
2984 idx
= get_format_idx(WINED3DFMT_R16G16B16A16_FLOAT
);
2985 gl_info
->formats
[idx
].gl_vtx_type
= GL_HALF_FLOAT
;
2988 if (!gl_info
->supported
[ARB_HALF_FLOAT_PIXEL
])
2990 idx
= get_format_idx(WINED3DFMT_R16_FLOAT
);
2991 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2993 idx
= get_format_idx(WINED3DFMT_R16G16_FLOAT
);
2994 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2996 idx
= get_format_idx(WINED3DFMT_R16G16B16A16_FLOAT
);
2997 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3000 if (gl_info
->quirks
& WINED3D_QUIRK_BROKEN_RGBA16
)
3002 idx
= get_format_idx(WINED3DFMT_R16G16B16A16_UNORM
);
3003 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3006 /* ATI instancing hack: Although ATI cards do not support Shader Model
3007 * 3.0, they support instancing. To query if the card supports instancing
3008 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
3009 * is used. Should an application check for this, provide a proper return
3010 * value. We can do instancing with all shader versions, but we need
3013 * Additionally applications have to set the D3DRS_POINTSIZE render state
3014 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
3015 * doesn't need that and just ignores it.
3017 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
3018 /* FIXME: This should just check the shader backend caps. */
3019 if (gl_info
->supported
[ARB_VERTEX_PROGRAM
] || gl_info
->supported
[ARB_VERTEX_SHADER
])
3021 idx
= get_format_idx(WINED3DFMT_INST
);
3022 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3025 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
3026 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
3027 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
3028 * MAKEFOURCC('N','V','D','B') and then controlled by setting
3029 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
3031 if (gl_info
->supported
[EXT_DEPTH_BOUNDS_TEST
])
3033 idx
= get_format_idx(WINED3DFMT_NVDB
);
3034 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3037 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
3038 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
3039 * RENDERTARGET usage. */
3040 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
])
3042 idx
= get_format_idx(WINED3DFMT_RESZ
);
3043 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
);
3046 for (i
= 0; i
< gl_info
->format_count
; ++i
)
3048 struct wined3d_format
*format
= &gl_info
->formats
[i
];
3050 if (!(format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_TEXTURE
))
3053 if (!adapter
->shader_backend
->shader_color_fixup_supported(format
->color_fixup
)
3054 || !adapter
->fragment_pipe
->color_fixup_supported(format
->color_fixup
))
3055 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
3058 /* GL_EXT_texture_compression_s3tc does not support 3D textures. Some Windows drivers
3059 * for dx9 GPUs support it, some do not, so not supporting DXTn volumes is OK for d3d9.
3061 * Note that GL_NV_texture_compression_vtc adds this functionality to OpenGL, but the
3062 * block layout is not compatible with the one used by d3d. See volume_dxt5_test. */
3063 idx
= get_format_idx(WINED3DFMT_DXT1
);
3064 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3065 idx
= get_format_idx(WINED3DFMT_DXT2
);
3066 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3067 idx
= get_format_idx(WINED3DFMT_DXT3
);
3068 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3069 idx
= get_format_idx(WINED3DFMT_DXT4
);
3070 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3071 idx
= get_format_idx(WINED3DFMT_DXT5
);
3072 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3073 idx
= get_format_idx(WINED3DFMT_BC1_UNORM
);
3074 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3075 idx
= get_format_idx(WINED3DFMT_BC1_UNORM_SRGB
);
3076 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3077 idx
= get_format_idx(WINED3DFMT_BC2_UNORM
);
3078 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3079 idx
= get_format_idx(WINED3DFMT_BC2_UNORM_SRGB
);
3080 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3081 idx
= get_format_idx(WINED3DFMT_BC3_UNORM
);
3082 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3083 idx
= get_format_idx(WINED3DFMT_BC3_UNORM_SRGB
);
3084 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3085 /* Similarly with ATI1N / ATI2N and GL_ARB_texture_compression_rgtc. */
3086 idx
= get_format_idx(WINED3DFMT_ATI1N
);
3087 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3088 idx
= get_format_idx(WINED3DFMT_ATI2N
);
3089 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3090 idx
= get_format_idx(WINED3DFMT_BC4_UNORM
);
3091 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3092 idx
= get_format_idx(WINED3DFMT_BC5_UNORM
);
3093 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
3096 static BOOL
init_format_vertex_info(struct wined3d_gl_info
*gl_info
)
3100 for (i
= 0; i
< (sizeof(format_vertex_info
) / sizeof(*format_vertex_info
)); ++i
)
3102 struct wined3d_format
*format
;
3103 int fmt_idx
= get_format_idx(format_vertex_info
[i
].id
);
3107 ERR("Format %s (%#x) not found.\n",
3108 debug_d3dformat(format_vertex_info
[i
].id
), format_vertex_info
[i
].id
);
3112 format
= &gl_info
->formats
[fmt_idx
];
3113 format
->emit_idx
= format_vertex_info
[i
].emit_idx
;
3114 format
->component_count
= format_vertex_info
[i
].component_count
;
3115 format
->gl_vtx_type
= format_vertex_info
[i
].gl_vtx_type
;
3116 format
->gl_vtx_format
= format_vertex_info
[i
].gl_vtx_format
;
3117 format
->gl_normalized
= format_vertex_info
[i
].gl_normalized
;
3118 format
->component_size
= format_vertex_info
[i
].component_size
;
3124 static BOOL
init_typeless_formats(struct wined3d_gl_info
*gl_info
)
3126 unsigned int flags
[WINED3D_GL_RES_TYPE_COUNT
];
3129 for (i
= 0; i
< ARRAY_SIZE(typed_formats
); ++i
)
3131 struct wined3d_format
*format
, *typeless_format
;
3132 int fmt_idx
= get_format_idx(typed_formats
[i
].id
);
3133 int typeless_fmt_idx
= get_format_idx(typed_formats
[i
].typeless_id
);
3137 ERR("Format %s (%#x) not found.\n",
3138 debug_d3dformat(typed_formats
[i
].id
),
3139 typed_formats
[i
].id
);
3142 if (typeless_fmt_idx
== -1)
3144 ERR("Format %s (%#x) not found.\n",
3145 debug_d3dformat(typed_formats
[i
].typeless_id
),
3146 typed_formats
[i
].typeless_id
);
3150 format
= &gl_info
->formats
[fmt_idx
];
3151 typeless_format
= &gl_info
->formats
[typeless_fmt_idx
];
3153 memcpy(flags
, typeless_format
->flags
, sizeof(flags
));
3154 *typeless_format
= *format
;
3155 typeless_format
->id
= typed_formats
[i
].typeless_id
;
3156 for (j
= 0; j
< ARRAY_SIZE(typeless_format
->flags
); ++j
)
3157 typeless_format
->flags
[j
] |= flags
[j
];
3163 BOOL
initPixelFormatsNoGL(struct wined3d_gl_info
*gl_info
)
3165 if (!init_format_base_info(gl_info
)) return FALSE
;
3167 if (!init_format_block_info(gl_info
))
3169 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
3170 gl_info
->formats
= NULL
;
3177 /* Context activation is done by the caller. */
3178 BOOL
wined3d_adapter_init_format_info(struct wined3d_adapter
*adapter
, struct wined3d_caps_gl_ctx
*ctx
)
3180 struct wined3d_gl_info
*gl_info
= &adapter
->gl_info
;
3182 if (!init_format_base_info(gl_info
)) return FALSE
;
3184 if (!init_format_block_info(gl_info
)) goto fail
;
3185 if (!init_format_texture_info(adapter
, gl_info
)) goto fail
;
3186 if (!init_format_vertex_info(gl_info
)) goto fail
;
3188 apply_format_fixups(adapter
, gl_info
);
3189 init_format_fbo_compat_info(ctx
);
3190 init_format_filter_info(gl_info
, adapter
->driver_info
.vendor
);
3191 if (!init_typeless_formats(gl_info
)) goto fail
;
3196 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
3197 gl_info
->formats
= NULL
;
3201 float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx
*ctx
, GLenum format
)
3203 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
3204 static const struct wined3d_color blue
= {0.0f
, 0.0f
, 1.0f
, 1.0f
};
3205 GLuint fbo
, color
, depth
;
3206 unsigned int low
= 0, high
= 32, cur
;
3207 DWORD readback
[256];
3208 static const struct wined3d_vec3 geometry
[] =
3210 {-1.0f
, -1.0f
, -1.0f
},
3211 { 1.0f
, -1.0f
, 0.0f
},
3212 {-1.0f
, 1.0f
, -1.0f
},
3213 { 1.0f
, 1.0f
, 0.0f
},
3216 /* Most drivers want 2^23 for fixed point depth buffers, including r300g, r600g,
3217 * Nvidia. Use this as a fallback if the detection fails. */
3218 unsigned int fallback
= 23;
3220 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
3222 FIXME("No FBOs, assuming polyoffset scale of 2^%u.\n", fallback
);
3223 return (float)(1u << fallback
);
3226 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &color
);
3227 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
3228 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
3229 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);
3231 gl_info
->fbo_ops
.glGenRenderbuffers(1, &depth
);
3232 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, depth
);
3233 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, format
, 256, 1);
3235 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
3236 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
3237 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, color
, 0);
3238 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, depth
);
3239 checkGLcall("Setup framebuffer");
3241 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.5f
, 0.0f
);
3242 gl_info
->gl_ops
.gl
.p_glClearDepth(0.5f
);
3243 gl_info
->gl_ops
.gl
.p_glEnable(GL_DEPTH_TEST
);
3244 gl_info
->gl_ops
.gl
.p_glEnable(GL_POLYGON_OFFSET_FILL
);
3245 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 256, 1);
3246 checkGLcall("Misc parameters");
3250 if (high
- low
<= 1)
3252 ERR("PolygonOffset scale factor detection failed, using fallback value 2^%u.\n", fallback
);
3256 cur
= (low
+ high
) / 2;
3258 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
3259 /* The post viewport transform Z of the geometry runs from 0.0 to 0.5. We want to push it another
3260 * 0.25 so that the Z buffer content (0.5) cuts the quad off at half the screen. */
3261 gl_info
->gl_ops
.gl
.p_glPolygonOffset(0.0f
, (float)(1u << cur
) * 0.25f
);
3262 draw_test_quad(ctx
, geometry
, &blue
);
3263 checkGLcall("Test draw");
3265 /* Rebinding texture to workaround a fglrx bug. */
3266 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
3267 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
3268 checkGLcall("readback");
3270 TRACE("low %02u, high %02u, cur %2u, 0=0x%08x, 125=0x%08x, 131=0x%08x, 255=0x%08x\n",
3271 low
, high
, cur
, readback
[0], readback
[125], readback
[131], readback
[255]);
3273 if ((readback
[125] & 0xff) < 0xa0)
3275 else if ((readback
[131] & 0xff) > 0xa0)
3279 TRACE("Found scale factor 2^%u for format %x\n", cur
, format
);
3284 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &color
);
3285 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &depth
);
3286 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
3287 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
3288 checkGLcall("Delete framebuffer");
3290 gl_info
->gl_ops
.gl
.p_glDisable(GL_DEPTH_TEST
);
3291 gl_info
->gl_ops
.gl
.p_glDisable(GL_POLYGON_OFFSET_FILL
);
3292 return (float)(1u << cur
);
3295 const struct wined3d_format
*wined3d_get_format(const struct wined3d_gl_info
*gl_info
,
3296 enum wined3d_format_id format_id
)
3298 int idx
= get_format_idx(format_id
);
3302 FIXME("Can't find format %s (%#x) in the format lookup table\n",
3303 debug_d3dformat(format_id
), format_id
);
3304 /* Get the caller a valid pointer */
3305 idx
= get_format_idx(WINED3DFMT_UNKNOWN
);
3308 return &gl_info
->formats
[idx
];
3311 void wined3d_format_calculate_pitch(const struct wined3d_format
*format
, unsigned int alignment
,
3312 unsigned int width
, unsigned int height
, unsigned int *row_pitch
, unsigned int *slice_pitch
)
3314 /* For block based formats, pitch means the amount of bytes to the next
3315 * row of blocks rather than the next row of pixels. */
3316 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BLOCKS
)
3318 unsigned int row_block_count
= (width
+ format
->block_width
- 1) / format
->block_width
;
3319 unsigned int slice_block_count
= (height
+ format
->block_height
- 1) / format
->block_height
;
3320 *row_pitch
= row_block_count
* format
->block_byte_count
;
3321 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
3322 *slice_pitch
= *row_pitch
* slice_block_count
;
3326 *row_pitch
= format
->byte_count
* width
; /* Bytes / row */
3327 *row_pitch
= (*row_pitch
+ alignment
- 1) & ~(alignment
- 1);
3328 *slice_pitch
= *row_pitch
* height
;
3331 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_HEIGHT_SCALE
)
3333 /* The D3D format requirements make sure that the resulting format is an integer again */
3334 *slice_pitch
*= format
->height_scale
.numerator
;
3335 *slice_pitch
/= format
->height_scale
.denominator
;
3338 TRACE("Returning row pitch %u, slice pitch %u.\n", *row_pitch
, *slice_pitch
);
3341 UINT
wined3d_format_calculate_size(const struct wined3d_format
*format
, UINT alignment
,
3342 UINT width
, UINT height
, UINT depth
)
3344 unsigned int row_pitch
, slice_pitch
;
3346 if (format
->id
== WINED3DFMT_UNKNOWN
)
3349 wined3d_format_calculate_pitch(format
, alignment
, width
, height
, &row_pitch
, &slice_pitch
);
3351 return slice_pitch
* depth
;
3354 /*****************************************************************************
3355 * Trace formatting of useful values
3357 const char *debug_box(const struct wined3d_box
*box
)
3361 return wine_dbg_sprintf("(%u, %u, %u)-(%u, %u, %u)",
3362 box
->left
, box
->top
, box
->front
,
3363 box
->right
, box
->bottom
, box
->back
);
3366 const char *debug_color(const struct wined3d_color
*color
)
3370 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
3371 color
->r
, color
->g
, color
->b
, color
->a
);
3374 const char *debug_ivec4(const struct wined3d_ivec4
*v
)
3378 return wine_dbg_sprintf("{%d, %d, %d, %d}",
3379 v
->x
, v
->y
, v
->z
, v
->w
);
3382 const char *debug_vec4(const struct wined3d_vec4
*v
)
3386 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}",
3387 v
->x
, v
->y
, v
->z
, v
->w
);
3390 const char *debug_d3dformat(enum wined3d_format_id format_id
)
3394 #define FMT_TO_STR(format_id) case format_id: return #format_id
3395 FMT_TO_STR(WINED3DFMT_UNKNOWN
);
3396 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM
);
3397 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM
);
3398 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM
);
3399 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM
);
3400 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM
);
3401 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM
);
3402 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM
);
3403 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM
);
3404 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM
);
3405 FMT_TO_STR(WINED3DFMT_P8_UINT
);
3406 FMT_TO_STR(WINED3DFMT_L8_UNORM
);
3407 FMT_TO_STR(WINED3DFMT_L8A8_UNORM
);
3408 FMT_TO_STR(WINED3DFMT_L4A4_UNORM
);
3409 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
3410 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
3411 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM
);
3412 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM
);
3413 FMT_TO_STR(WINED3DFMT_UYVY
);
3414 FMT_TO_STR(WINED3DFMT_YUY2
);
3415 FMT_TO_STR(WINED3DFMT_YV12
);
3416 FMT_TO_STR(WINED3DFMT_NV12
);
3417 FMT_TO_STR(WINED3DFMT_DXT1
);
3418 FMT_TO_STR(WINED3DFMT_DXT2
);
3419 FMT_TO_STR(WINED3DFMT_DXT3
);
3420 FMT_TO_STR(WINED3DFMT_DXT4
);
3421 FMT_TO_STR(WINED3DFMT_DXT5
);
3422 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8
);
3423 FMT_TO_STR(WINED3DFMT_G8R8_G8B8
);
3424 FMT_TO_STR(WINED3DFMT_R8G8_B8G8
);
3425 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE
);
3426 FMT_TO_STR(WINED3DFMT_D32_UNORM
);
3427 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM
);
3428 FMT_TO_STR(WINED3DFMT_X8D24_UNORM
);
3429 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM
);
3430 FMT_TO_STR(WINED3DFMT_L16_UNORM
);
3431 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT
);
3432 FMT_TO_STR(WINED3DFMT_VERTEXDATA
);
3433 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx
);
3434 FMT_TO_STR(WINED3DFMT_ATI1N
);
3435 FMT_TO_STR(WINED3DFMT_ATI2N
);
3436 FMT_TO_STR(WINED3DFMT_NVDB
);
3437 FMT_TO_STR(WINED3DFMT_NVHU
);
3438 FMT_TO_STR(WINED3DFMT_NVHS
);
3439 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS
);
3440 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT
);
3441 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT
);
3442 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT
);
3443 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS
);
3444 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT
);
3445 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT
);
3446 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT
);
3447 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS
);
3448 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT
);
3449 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM
);
3450 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT
);
3451 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM
);
3452 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT
);
3453 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS
);
3454 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT
);
3455 FMT_TO_STR(WINED3DFMT_R32G32_UINT
);
3456 FMT_TO_STR(WINED3DFMT_R32G32_SINT
);
3457 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS
);
3458 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT
);
3459 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
);
3460 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT
);
3461 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS
);
3462 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM
);
3463 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT
);
3464 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM
);
3465 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT
);
3466 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS
);
3467 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM
);
3468 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB
);
3469 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT
);
3470 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM
);
3471 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT
);
3472 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS
);
3473 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT
);
3474 FMT_TO_STR(WINED3DFMT_R16G16_UNORM
);
3475 FMT_TO_STR(WINED3DFMT_R16G16_UINT
);
3476 FMT_TO_STR(WINED3DFMT_R16G16_SNORM
);
3477 FMT_TO_STR(WINED3DFMT_R16G16_SINT
);
3478 FMT_TO_STR(WINED3DFMT_R32_TYPELESS
);
3479 FMT_TO_STR(WINED3DFMT_D32_FLOAT
);
3480 FMT_TO_STR(WINED3DFMT_R32_FLOAT
);
3481 FMT_TO_STR(WINED3DFMT_R32_UINT
);
3482 FMT_TO_STR(WINED3DFMT_R32_SINT
);
3483 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS
);
3484 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT
);
3485 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS
);
3486 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT
);
3487 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS
);
3488 FMT_TO_STR(WINED3DFMT_R8G8_UNORM
);
3489 FMT_TO_STR(WINED3DFMT_R8G8_UINT
);
3490 FMT_TO_STR(WINED3DFMT_R8G8_SNORM
);
3491 FMT_TO_STR(WINED3DFMT_R8G8_SINT
);
3492 FMT_TO_STR(WINED3DFMT_R16_TYPELESS
);
3493 FMT_TO_STR(WINED3DFMT_R16_FLOAT
);
3494 FMT_TO_STR(WINED3DFMT_D16_UNORM
);
3495 FMT_TO_STR(WINED3DFMT_R16_UNORM
);
3496 FMT_TO_STR(WINED3DFMT_R16_UINT
);
3497 FMT_TO_STR(WINED3DFMT_R16_SNORM
);
3498 FMT_TO_STR(WINED3DFMT_R16_SINT
);
3499 FMT_TO_STR(WINED3DFMT_R8_TYPELESS
);
3500 FMT_TO_STR(WINED3DFMT_R8_UNORM
);
3501 FMT_TO_STR(WINED3DFMT_R8_UINT
);
3502 FMT_TO_STR(WINED3DFMT_R8_SNORM
);
3503 FMT_TO_STR(WINED3DFMT_R8_SINT
);
3504 FMT_TO_STR(WINED3DFMT_A8_UNORM
);
3505 FMT_TO_STR(WINED3DFMT_R1_UNORM
);
3506 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP
);
3507 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM
);
3508 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM
);
3509 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS
);
3510 FMT_TO_STR(WINED3DFMT_BC1_UNORM
);
3511 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB
);
3512 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS
);
3513 FMT_TO_STR(WINED3DFMT_BC2_UNORM
);
3514 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB
);
3515 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS
);
3516 FMT_TO_STR(WINED3DFMT_BC3_UNORM
);
3517 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB
);
3518 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS
);
3519 FMT_TO_STR(WINED3DFMT_BC4_UNORM
);
3520 FMT_TO_STR(WINED3DFMT_BC4_SNORM
);
3521 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS
);
3522 FMT_TO_STR(WINED3DFMT_BC5_UNORM
);
3523 FMT_TO_STR(WINED3DFMT_BC5_SNORM
);
3524 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM
);
3525 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM
);
3526 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM
);
3527 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM
);
3528 FMT_TO_STR(WINED3DFMT_B8G8R8A8_TYPELESS
);
3529 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM_SRGB
);
3530 FMT_TO_STR(WINED3DFMT_B8G8R8X8_TYPELESS
);
3531 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM_SRGB
);
3532 FMT_TO_STR(WINED3DFMT_BC7_TYPELESS
);
3533 FMT_TO_STR(WINED3DFMT_BC7_UNORM
);
3534 FMT_TO_STR(WINED3DFMT_BC7_UNORM_SRGB
);
3535 FMT_TO_STR(WINED3DFMT_INTZ
);
3536 FMT_TO_STR(WINED3DFMT_RESZ
);
3537 FMT_TO_STR(WINED3DFMT_NULL
);
3538 FMT_TO_STR(WINED3DFMT_R16
);
3539 FMT_TO_STR(WINED3DFMT_AL16
);
3544 fourcc
[0] = (char)(format_id
);
3545 fourcc
[1] = (char)(format_id
>> 8);
3546 fourcc
[2] = (char)(format_id
>> 16);
3547 fourcc
[3] = (char)(format_id
>> 24);
3549 if (isprint(fourcc
[0]) && isprint(fourcc
[1]) && isprint(fourcc
[2]) && isprint(fourcc
[3]))
3550 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id
, fourcc
);
3552 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id
);
3554 return "unrecognized";
3558 const char *debug_d3ddevicetype(enum wined3d_device_type device_type
)
3560 switch (device_type
)
3562 #define DEVTYPE_TO_STR(dev) case dev: return #dev
3563 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL
);
3564 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF
);
3565 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW
);
3566 #undef DEVTYPE_TO_STR
3568 FIXME("Unrecognized device type %#x.\n", device_type
);
3569 return "unrecognized";
3573 const char *debug_d3dusage(DWORD usage
)
3578 #define WINED3DUSAGE_TO_STR(u) if (usage & u) { strcat(buf, " | "#u); usage &= ~u; }
3579 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RENDERTARGET
);
3580 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DEPTHSTENCIL
);
3581 WINED3DUSAGE_TO_STR(WINED3DUSAGE_WRITEONLY
);
3582 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING
);
3583 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP
);
3584 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS
);
3585 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES
);
3586 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES
);
3587 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC
);
3588 WINED3DUSAGE_TO_STR(WINED3DUSAGE_AUTOGENMIPMAP
);
3589 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP
);
3590 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL
);
3591 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY
);
3592 #undef WINED3DUSAGE_TO_STR
3593 if (usage
) FIXME("Unrecognized usage flag(s) %#x\n", usage
);
3595 return buf
[0] ? wine_dbg_sprintf("%s", &buf
[3]) : "0";
3598 const char *debug_d3dusagequery(DWORD usagequery
)
3603 #define WINED3DUSAGEQUERY_TO_STR(u) if (usagequery & u) { strcat(buf, " | "#u); usagequery &= ~u; }
3604 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_FILTER
);
3605 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP
);
3606 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
);
3607 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD
);
3608 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE
);
3609 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE
);
3610 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP
);
3611 #undef WINED3DUSAGEQUERY_TO_STR
3612 if (usagequery
) FIXME("Unrecognized usage query flag(s) %#x\n", usagequery
);
3614 return buf
[0] ? wine_dbg_sprintf("%s", &buf
[3]) : "0";
3617 const char *debug_d3ddeclmethod(enum wined3d_decl_method method
)
3621 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
3622 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT
);
3623 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U
);
3624 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V
);
3625 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV
);
3626 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV
);
3627 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP
);
3628 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED
);
3629 #undef WINED3DDECLMETHOD_TO_STR
3631 FIXME("Unrecognized declaration method %#x.\n", method
);
3632 return "unrecognized";
3636 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage
)
3640 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
3641 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION
);
3642 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT
);
3643 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES
);
3644 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL
);
3645 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE
);
3646 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD
);
3647 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT
);
3648 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL
);
3649 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR
);
3650 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT
);
3651 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR
);
3652 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG
);
3653 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH
);
3654 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE
);
3655 #undef WINED3DDECLUSAGE_TO_STR
3657 FIXME("Unrecognized %u declaration usage!\n", usage
);
3658 return "unrecognized";
3662 const char *debug_d3dinput_classification(enum wined3d_input_classification classification
)
3664 switch (classification
)
3666 #define WINED3D_TO_STR(x) case x: return #x
3667 WINED3D_TO_STR(WINED3D_INPUT_PER_VERTEX_DATA
);
3668 WINED3D_TO_STR(WINED3D_INPUT_PER_INSTANCE_DATA
);
3669 #undef WINED3D_TO_STR
3671 FIXME("Unrecognized input classification %#x.\n", classification
);
3672 return "unrecognized";
3676 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type
)
3678 switch (resource_type
)
3680 #define WINED3D_TO_STR(x) case x: return #x
3681 WINED3D_TO_STR(WINED3D_RTYPE_BUFFER
);
3682 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_2D
);
3683 WINED3D_TO_STR(WINED3D_RTYPE_TEXTURE_3D
);
3684 #undef WINED3D_TO_STR
3686 FIXME("Unrecognized resource type %#x.\n", resource_type
);
3687 return "unrecognized";
3691 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type
)
3693 switch (primitive_type
)
3695 #define PRIM_TO_STR(prim) case prim: return #prim
3696 PRIM_TO_STR(WINED3D_PT_UNDEFINED
);
3697 PRIM_TO_STR(WINED3D_PT_POINTLIST
);
3698 PRIM_TO_STR(WINED3D_PT_LINELIST
);
3699 PRIM_TO_STR(WINED3D_PT_LINESTRIP
);
3700 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST
);
3701 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP
);
3702 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN
);
3703 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ
);
3704 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ
);
3705 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ
);
3706 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ
);
3709 FIXME("Unrecognized %u primitive type!\n", primitive_type
);
3710 return "unrecognized";
3714 const char *debug_d3drenderstate(enum wined3d_render_state state
)
3718 #define D3DSTATE_TO_STR(u) case u: return #u
3719 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS
);
3720 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE
);
3721 D3DSTATE_TO_STR(WINED3D_RS_WRAPU
);
3722 D3DSTATE_TO_STR(WINED3D_RS_WRAPV
);
3723 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE
);
3724 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE
);
3725 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE
);
3726 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN
);
3727 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE
);
3728 D3DSTATE_TO_STR(WINED3D_RS_ROP2
);
3729 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK
);
3730 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE
);
3731 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE
);
3732 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL
);
3733 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND
);
3734 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND
);
3735 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE
);
3736 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC
);
3737 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF
);
3738 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC
);
3739 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE
);
3740 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE
);
3741 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE
);
3742 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE
);
3743 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE
);
3744 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL
);
3745 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX
);
3746 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA
);
3747 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR
);
3748 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE
);
3749 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART
);
3750 D3DSTATE_TO_STR(WINED3D_RS_FOGEND
);
3751 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY
);
3752 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE
);
3753 D3DSTATE_TO_STR(WINED3D_RS_EDGEANTIALIAS
);
3754 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE
);
3755 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS
);
3756 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE
);
3757 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY
);
3758 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH
);
3759 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT
);
3760 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE
);
3761 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL
);
3762 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL
);
3763 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS
);
3764 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC
);
3765 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF
);
3766 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK
);
3767 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK
);
3768 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR
);
3769 D3DSTATE_TO_STR(WINED3D_RS_WRAP0
);
3770 D3DSTATE_TO_STR(WINED3D_RS_WRAP1
);
3771 D3DSTATE_TO_STR(WINED3D_RS_WRAP2
);
3772 D3DSTATE_TO_STR(WINED3D_RS_WRAP3
);
3773 D3DSTATE_TO_STR(WINED3D_RS_WRAP4
);
3774 D3DSTATE_TO_STR(WINED3D_RS_WRAP5
);
3775 D3DSTATE_TO_STR(WINED3D_RS_WRAP6
);
3776 D3DSTATE_TO_STR(WINED3D_RS_WRAP7
);
3777 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING
);
3778 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING
);
3779 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS
);
3780 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT
);
3781 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE
);
3782 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX
);
3783 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER
);
3784 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS
);
3785 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE
);
3786 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE
);
3787 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE
);
3788 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE
);
3789 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE
);
3790 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND
);
3791 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE
);
3792 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING
);
3793 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE
);
3794 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN
);
3795 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE
);
3796 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE
);
3797 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A
);
3798 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B
);
3799 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C
);
3800 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS
);
3801 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK
);
3802 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE
);
3803 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS
);
3804 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN
);
3805 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX
);
3806 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE
);
3807 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE
);
3808 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR
);
3809 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP
);
3810 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE
);
3811 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE
);
3812 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE
);
3813 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS
);
3814 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE
);
3815 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL
);
3816 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL
);
3817 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X
);
3818 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y
);
3819 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z
);
3820 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W
);
3821 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION
);
3822 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE
);
3823 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILFAIL
);
3824 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILZFAIL
);
3825 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILPASS
);
3826 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILFUNC
);
3827 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1
);
3828 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2
);
3829 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3
);
3830 D3DSTATE_TO_STR(WINED3D_RS_BLENDFACTOR
);
3831 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE
);
3832 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS
);
3833 D3DSTATE_TO_STR(WINED3D_RS_WRAP8
);
3834 D3DSTATE_TO_STR(WINED3D_RS_WRAP9
);
3835 D3DSTATE_TO_STR(WINED3D_RS_WRAP10
);
3836 D3DSTATE_TO_STR(WINED3D_RS_WRAP11
);
3837 D3DSTATE_TO_STR(WINED3D_RS_WRAP12
);
3838 D3DSTATE_TO_STR(WINED3D_RS_WRAP13
);
3839 D3DSTATE_TO_STR(WINED3D_RS_WRAP14
);
3840 D3DSTATE_TO_STR(WINED3D_RS_WRAP15
);
3841 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE
);
3842 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA
);
3843 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA
);
3844 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA
);
3845 #undef D3DSTATE_TO_STR
3847 FIXME("Unrecognized %u render state!\n", state
);
3848 return "unrecognized";
3852 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state
)
3856 #define D3DSTATE_TO_STR(u) case u: return #u
3857 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR
);
3858 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U
);
3859 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V
);
3860 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W
);
3861 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER
);
3862 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER
);
3863 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER
);
3864 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS
);
3865 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL
);
3866 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY
);
3867 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE
);
3868 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX
);
3869 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET
);
3870 #undef D3DSTATE_TO_STR
3872 FIXME("Unrecognized %u sampler state!\n", state
);
3873 return "unrecognized";
3877 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type
)
3879 switch (filter_type
)
3881 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
3882 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE
);
3883 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT
);
3884 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR
);
3885 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC
);
3886 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC
);
3887 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC
);
3888 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD
);
3889 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD
);
3890 #undef D3DTEXTUREFILTERTYPE_TO_STR
3892 FIXME("Unrecognized texture filter type 0x%08x.\n", filter_type
);
3893 return "unrecognized";
3897 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state
)
3901 #define D3DSTATE_TO_STR(u) case u: return #u
3902 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP
);
3903 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1
);
3904 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2
);
3905 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP
);
3906 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1
);
3907 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2
);
3908 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00
);
3909 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01
);
3910 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10
);
3911 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11
);
3912 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX
);
3913 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE
);
3914 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET
);
3915 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
);
3916 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0
);
3917 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0
);
3918 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG
);
3919 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT
);
3920 #undef D3DSTATE_TO_STR
3922 FIXME("Unrecognized %u texture state!\n", state
);
3923 return "unrecognized";
3927 const char *debug_d3dtop(enum wined3d_texture_op d3dtop
)
3931 #define D3DTOP_TO_STR(u) case u: return #u
3932 D3DTOP_TO_STR(WINED3D_TOP_DISABLE
);
3933 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1
);
3934 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2
);
3935 D3DTOP_TO_STR(WINED3D_TOP_MODULATE
);
3936 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X
);
3937 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X
);
3938 D3DTOP_TO_STR(WINED3D_TOP_ADD
);
3939 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED
);
3940 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X
);
3941 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT
);
3942 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH
);
3943 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA
);
3944 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA
);
3945 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA
);
3946 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM
);
3947 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA
);
3948 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE
);
3949 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR
);
3950 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA
);
3951 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR
);
3952 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA
);
3953 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP
);
3954 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE
);
3955 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3
);
3956 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD
);
3957 D3DTOP_TO_STR(WINED3D_TOP_LERP
);
3958 #undef D3DTOP_TO_STR
3960 FIXME("Unrecognized texture op %#x.\n", d3dtop
);
3961 return "unrecognized";
3965 const char *debug_d3dtstype(enum wined3d_transform_state tstype
)
3969 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
3970 TSTYPE_TO_STR(WINED3D_TS_VIEW
);
3971 TSTYPE_TO_STR(WINED3D_TS_PROJECTION
);
3972 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0
);
3973 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1
);
3974 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2
);
3975 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3
);
3976 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4
);
3977 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5
);
3978 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6
);
3979 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7
);
3980 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
3981 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(1));
3982 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(2));
3983 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(3));
3984 #undef TSTYPE_TO_STR
3986 if (tstype
> 256 && tstype
< 512)
3988 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype
);
3989 return ("WINED3D_TS_WORLD_MATRIX > 0");
3991 FIXME("Unrecognized transform state %#x.\n", tstype
);
3992 return "unrecognized";
3996 const char *debug_shader_type(enum wined3d_shader_type type
)
4000 #define WINED3D_TO_STR(type) case type: return #type
4001 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL
);
4002 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX
);
4003 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY
);
4004 WINED3D_TO_STR(WINED3D_SHADER_TYPE_HULL
);
4005 WINED3D_TO_STR(WINED3D_SHADER_TYPE_DOMAIN
);
4006 #undef WINED3D_TO_STR
4008 FIXME("Unrecognized shader type %#x.\n", type
);
4009 return "unrecognized";
4013 const char *debug_d3dstate(DWORD state
)
4015 if (STATE_IS_RENDER(state
))
4016 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state
- STATE_RENDER(0)));
4017 if (STATE_IS_TEXTURESTAGE(state
))
4019 DWORD texture_stage
= (state
- STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE
+ 1);
4020 DWORD texture_state
= state
- STATE_TEXTURESTAGE(texture_stage
, 0);
4021 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
4022 texture_stage
, debug_d3dtexturestate(texture_state
));
4024 if (STATE_IS_SAMPLER(state
))
4025 return wine_dbg_sprintf("STATE_SAMPLER(%#x)", state
- STATE_SAMPLER(0));
4026 if (STATE_IS_SHADER(state
))
4027 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state
- STATE_SHADER(0)));
4028 if (STATE_IS_CONSTANT_BUFFER(state
))
4029 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state
- STATE_CONSTANT_BUFFER(0)));
4030 if (STATE_IS_SHADER_RESOURCE_BINDING(state
))
4031 return "STATE_SHADER_RESOURCE_BINDING";
4032 if (STATE_IS_TRANSFORM(state
))
4033 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state
- STATE_TRANSFORM(0)));
4034 if (STATE_IS_STREAMSRC(state
))
4035 return "STATE_STREAMSRC";
4036 if (STATE_IS_INDEXBUFFER(state
))
4037 return "STATE_INDEXBUFFER";
4038 if (STATE_IS_VDECL(state
))
4039 return "STATE_VDECL";
4040 if (STATE_IS_VIEWPORT(state
))
4041 return "STATE_VIEWPORT";
4042 if (STATE_IS_LIGHT_TYPE(state
))
4043 return "STATE_LIGHT_TYPE";
4044 if (STATE_IS_ACTIVELIGHT(state
))
4045 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state
- STATE_ACTIVELIGHT(0));
4046 if (STATE_IS_SCISSORRECT(state
))
4047 return "STATE_SCISSORRECT";
4048 if (STATE_IS_CLIPPLANE(state
))
4049 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state
- STATE_CLIPPLANE(0));
4050 if (STATE_IS_MATERIAL(state
))
4051 return "STATE_MATERIAL";
4052 if (STATE_IS_FRONTFACE(state
))
4053 return "STATE_FRONTFACE";
4054 if (STATE_IS_POINTSPRITECOORDORIGIN(state
))
4055 return "STATE_POINTSPRITECOORDORIGIN";
4056 if (STATE_IS_BASEVERTEXINDEX(state
))
4057 return "STATE_BASEVERTEXINDEX";
4058 if (STATE_IS_FRAMEBUFFER(state
))
4059 return "STATE_FRAMEBUFFER";
4060 if (STATE_IS_POINT_ENABLE(state
))
4061 return "STATE_POINT_ENABLE";
4062 if (STATE_IS_COLOR_KEY(state
))
4063 return "STATE_COLOR_KEY";
4065 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state
);
4068 const char *debug_d3dpool(enum wined3d_pool pool
)
4072 #define POOL_TO_STR(p) case p: return #p
4073 POOL_TO_STR(WINED3D_POOL_DEFAULT
);
4074 POOL_TO_STR(WINED3D_POOL_MANAGED
);
4075 POOL_TO_STR(WINED3D_POOL_SYSTEM_MEM
);
4076 POOL_TO_STR(WINED3D_POOL_SCRATCH
);
4079 FIXME("Unrecognized pool %#x.\n", pool
);
4080 return "unrecognized";
4084 const char *debug_fboattachment(GLenum attachment
)
4088 #define WINED3D_TO_STR(x) case x: return #x
4089 WINED3D_TO_STR(GL_COLOR_ATTACHMENT0
);
4090 WINED3D_TO_STR(GL_COLOR_ATTACHMENT1
);
4091 WINED3D_TO_STR(GL_COLOR_ATTACHMENT2
);
4092 WINED3D_TO_STR(GL_COLOR_ATTACHMENT3
);
4093 WINED3D_TO_STR(GL_COLOR_ATTACHMENT4
);
4094 WINED3D_TO_STR(GL_COLOR_ATTACHMENT5
);
4095 WINED3D_TO_STR(GL_COLOR_ATTACHMENT6
);
4096 WINED3D_TO_STR(GL_COLOR_ATTACHMENT7
);
4097 WINED3D_TO_STR(GL_COLOR_ATTACHMENT8
);
4098 WINED3D_TO_STR(GL_COLOR_ATTACHMENT9
);
4099 WINED3D_TO_STR(GL_COLOR_ATTACHMENT10
);
4100 WINED3D_TO_STR(GL_COLOR_ATTACHMENT11
);
4101 WINED3D_TO_STR(GL_COLOR_ATTACHMENT12
);
4102 WINED3D_TO_STR(GL_COLOR_ATTACHMENT13
);
4103 WINED3D_TO_STR(GL_COLOR_ATTACHMENT14
);
4104 WINED3D_TO_STR(GL_COLOR_ATTACHMENT15
);
4105 WINED3D_TO_STR(GL_DEPTH_ATTACHMENT
);
4106 WINED3D_TO_STR(GL_STENCIL_ATTACHMENT
);
4107 #undef WINED3D_TO_STR
4109 return wine_dbg_sprintf("Unknown FBO attachment %#x", attachment
);
4113 const char *debug_fbostatus(GLenum status
) {
4115 #define FBOSTATUS_TO_STR(u) case u: return #u
4116 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE
);
4117 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
);
4118 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
);
4119 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
);
4120 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
);
4121 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
);
4122 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
);
4123 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
);
4124 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS
);
4125 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_LAYER_COUNT_ARB
);
4126 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED
);
4127 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED
);
4128 #undef FBOSTATUS_TO_STR
4130 FIXME("Unrecognized FBO status 0x%08x.\n", status
);
4131 return "unrecognized";
4135 const char *debug_glerror(GLenum error
) {
4137 #define GLERROR_TO_STR(u) case u: return #u
4138 GLERROR_TO_STR(GL_NO_ERROR
);
4139 GLERROR_TO_STR(GL_INVALID_ENUM
);
4140 GLERROR_TO_STR(GL_INVALID_VALUE
);
4141 GLERROR_TO_STR(GL_INVALID_OPERATION
);
4142 GLERROR_TO_STR(GL_STACK_OVERFLOW
);
4143 GLERROR_TO_STR(GL_STACK_UNDERFLOW
);
4144 GLERROR_TO_STR(GL_OUT_OF_MEMORY
);
4145 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION
);
4146 #undef GLERROR_TO_STR
4148 FIXME("Unrecognized GL error 0x%08x.\n", error
);
4149 return "unrecognized";
4153 static const char *debug_fixup_channel_source(enum fixup_channel_source source
)
4157 #define WINED3D_TO_STR(x) case x: return #x
4158 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO
);
4159 WINED3D_TO_STR(CHANNEL_SOURCE_ONE
);
4160 WINED3D_TO_STR(CHANNEL_SOURCE_X
);
4161 WINED3D_TO_STR(CHANNEL_SOURCE_Y
);
4162 WINED3D_TO_STR(CHANNEL_SOURCE_Z
);
4163 WINED3D_TO_STR(CHANNEL_SOURCE_W
);
4164 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0
);
4165 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1
);
4166 #undef WINED3D_TO_STR
4168 FIXME("Unrecognized fixup_channel_source %#x\n", source
);
4169 return "unrecognized";
4173 static const char *debug_complex_fixup(enum complex_fixup fixup
)
4177 #define WINED3D_TO_STR(x) case x: return #x
4178 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2
);
4179 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY
);
4180 WINED3D_TO_STR(COMPLEX_FIXUP_YV12
);
4181 WINED3D_TO_STR(COMPLEX_FIXUP_NV12
);
4182 WINED3D_TO_STR(COMPLEX_FIXUP_P8
);
4183 #undef WINED3D_TO_STR
4185 FIXME("Unrecognized complex fixup %#x\n", fixup
);
4186 return "unrecognized";
4190 void dump_color_fixup_desc(struct color_fixup_desc fixup
)
4192 if (is_complex_fixup(fixup
))
4194 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup
)));
4198 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup
.x_source
), fixup
.x_sign_fixup
? ", SIGN_FIXUP" : "");
4199 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup
.y_source
), fixup
.y_sign_fixup
? ", SIGN_FIXUP" : "");
4200 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup
.z_source
), fixup
.z_sign_fixup
? ", SIGN_FIXUP" : "");
4201 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup
.w_source
), fixup
.w_sign_fixup
? ", SIGN_FIXUP" : "");
4204 BOOL
is_invalid_op(const struct wined3d_state
*state
, int stage
,
4205 enum wined3d_texture_op op
, DWORD arg1
, DWORD arg2
, DWORD arg3
)
4207 if (op
== WINED3D_TOP_DISABLE
)
4209 if (state
->textures
[stage
])
4212 if ((arg1
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
4213 && op
!= WINED3D_TOP_SELECT_ARG2
)
4215 if ((arg2
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
4216 && op
!= WINED3D_TOP_SELECT_ARG1
)
4218 if ((arg3
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
4219 && (op
== WINED3D_TOP_MULTIPLY_ADD
|| op
== WINED3D_TOP_LERP
))
4225 void get_identity_matrix(struct wined3d_matrix
*mat
)
4227 static const struct wined3d_matrix identity
=
4229 1.0f
, 0.0f
, 0.0f
, 0.0f
,
4230 0.0f
, 1.0f
, 0.0f
, 0.0f
,
4231 0.0f
, 0.0f
, 1.0f
, 0.0f
,
4232 0.0f
, 0.0f
, 0.0f
, 1.0f
,
4238 void get_modelview_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4239 unsigned int index
, struct wined3d_matrix
*mat
)
4241 if (context
->last_was_rhw
)
4242 get_identity_matrix(mat
);
4244 multiply_matrix(mat
, &state
->transforms
[WINED3D_TS_VIEW
], &state
->transforms
[WINED3D_TS_WORLD_MATRIX(index
)]);
4247 void get_projection_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4248 struct wined3d_matrix
*mat
)
4250 float center_offset
;
4252 /* There are a couple of additional things we have to take into account
4253 * here besides the projection transformation itself:
4254 * - We need to flip along the y-axis in case of offscreen rendering.
4255 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
4256 * - D3D coordinates refer to pixel centers while GL coordinates refer
4258 * - D3D has a top-left filling convention. We need to maintain this
4259 * even after the y-flip mentioned above.
4260 * In order to handle the last two points, we translate by
4261 * (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to
4262 * translating slightly less than half a pixel. We want the difference to
4263 * be large enough that it doesn't get lost due to rounding inside the
4264 * driver, but small enough to prevent it from interfering with any
4267 if (context
->swapchain
->device
->wined3d
->flags
& WINED3D_PIXEL_CENTER_INTEGER
)
4268 center_offset
= 63.0f
/ 64.0f
;
4270 center_offset
= -1.0f
/ 64.0f
;
4272 if (context
->last_was_rhw
)
4274 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
4275 float x
= state
->viewport
.x
;
4276 float y
= state
->viewport
.y
;
4277 float w
= state
->viewport
.width
;
4278 float h
= state
->viewport
.height
;
4279 float x_scale
= 2.0f
/ w
;
4280 float x_offset
= (center_offset
- (2.0f
* x
) - w
) / w
;
4281 float y_scale
= context
->render_offscreen
? 2.0f
/ h
: 2.0f
/ -h
;
4282 float y_offset
= context
->render_offscreen
4283 ? (center_offset
- (2.0f
* y
) - h
) / h
4284 : (center_offset
- (2.0f
* y
) - h
) / -h
;
4285 enum wined3d_depth_buffer_type zenable
= state
->fb
->depth_stencil
?
4286 state
->render_states
[WINED3D_RS_ZENABLE
] : WINED3D_ZB_FALSE
;
4287 float z_scale
= zenable
? 2.0f
: 0.0f
;
4288 float z_offset
= zenable
? -1.0f
: 0.0f
;
4289 const struct wined3d_matrix projection
=
4291 x_scale
, 0.0f
, 0.0f
, 0.0f
,
4292 0.0f
, y_scale
, 0.0f
, 0.0f
,
4293 0.0f
, 0.0f
, z_scale
, 0.0f
,
4294 x_offset
, y_offset
, z_offset
, 1.0f
,
4301 float y_scale
= context
->render_offscreen
? -1.0f
: 1.0f
;
4302 float x_offset
= center_offset
/ state
->viewport
.width
;
4303 float y_offset
= context
->render_offscreen
4304 ? center_offset
/ state
->viewport
.height
4305 : -center_offset
/ state
->viewport
.height
;
4306 const struct wined3d_matrix projection
=
4308 1.0f
, 0.0f
, 0.0f
, 0.0f
,
4309 0.0f
, y_scale
, 0.0f
, 0.0f
,
4310 0.0f
, 0.0f
, 2.0f
, 0.0f
,
4311 x_offset
, y_offset
, -1.0f
, 1.0f
,
4314 multiply_matrix(mat
, &projection
, &state
->transforms
[WINED3D_TS_PROJECTION
]);
4318 /* Setup this textures matrix according to the texture flags. */
4319 static void compute_texture_matrix(const struct wined3d_gl_info
*gl_info
, const struct wined3d_matrix
*matrix
,
4320 DWORD flags
, BOOL calculated_coords
, BOOL transformed
, enum wined3d_format_id format_id
,
4321 BOOL ffp_proj_control
, struct wined3d_matrix
*out_matrix
)
4323 struct wined3d_matrix mat
;
4325 if (flags
== WINED3D_TTFF_DISABLE
|| flags
== WINED3D_TTFF_COUNT1
|| transformed
)
4327 get_identity_matrix(out_matrix
);
4331 if (flags
== (WINED3D_TTFF_COUNT1
| WINED3D_TTFF_PROJECTED
))
4333 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
4339 if (flags
& WINED3D_TTFF_PROJECTED
)
4341 if (!ffp_proj_control
)
4343 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
4345 case WINED3D_TTFF_COUNT2
:
4350 mat
._12
= mat
._22
= mat
._32
= mat
._42
= 0.0f
;
4352 case WINED3D_TTFF_COUNT3
:
4357 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
4364 /* Under Direct3D the R/Z coord can be used for translation, under
4365 * OpenGL we use the Q coord instead. */
4366 if (!calculated_coords
)
4370 /* Direct3D passes the default 1.0 in the 2nd coord, while GL
4371 * passes it in the 4th. Swap 2nd and 4th coord. No need to
4372 * store the value of mat._41 in mat._21 because the input
4373 * value to the transformation will be 0, so the matrix value
4375 case WINED3DFMT_R32_FLOAT
:
4381 /* See above, just 3rd and 4th coord. */
4382 case WINED3DFMT_R32G32_FLOAT
:
4388 case WINED3DFMT_R32G32B32_FLOAT
: /* Opengl defaults match dx defaults */
4389 case WINED3DFMT_R32G32B32A32_FLOAT
: /* No defaults apply, all app defined */
4391 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
4392 * into a bad place. The division elimination below will apply to make sure the
4393 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
4395 case WINED3DFMT_UNKNOWN
: /* No texture coords, 0/0/0/1 defaults are passed */
4398 FIXME("Unexpected fixed function texture coord input\n");
4401 if (!ffp_proj_control
)
4403 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
4405 /* case WINED3D_TTFF_COUNT1: Won't ever get here. */
4406 case WINED3D_TTFF_COUNT2
:
4407 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
4408 /* OpenGL divides the first 3 vertex coordinates by the 4th by
4409 * default, which is essentially the same as D3DTTFF_PROJECTED.
4410 * Make sure that the 4th coordinate evaluates to 1.0 to
4413 * If the fixed function pipeline is used, the 4th value
4414 * remains unused, so there is no danger in doing this. With
4415 * vertex shaders we have a problem. Should an application hit
4416 * that problem, the code here would have to check for pixel
4417 * shaders, and the shader has to undo the default GL divide.
4419 * A more serious problem occurs if the application passes 4
4420 * coordinates in, and the 4th is != 1.0 (OpenGL default).
4421 * This would have to be fixed with immediate mode draws. */
4423 mat
._14
= mat
._24
= mat
._34
= 0.0f
; mat
._44
= 1.0f
;
4431 void get_texture_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4432 unsigned int tex
, struct wined3d_matrix
*mat
)
4434 const struct wined3d_device
*device
= context
->swapchain
->device
;
4435 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
4436 BOOL generated
= (state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
] & 0xffff0000)
4437 != WINED3DTSS_TCI_PASSTHRU
;
4438 unsigned int coord_idx
= min(state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
& 0x0000ffff],
4441 compute_texture_matrix(gl_info
, &state
->transforms
[WINED3D_TS_TEXTURE0
+ tex
],
4442 state
->texture_states
[tex
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
],
4443 generated
, context
->last_was_rhw
,
4444 context
->stream_info
.use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))
4445 ? context
->stream_info
.elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format
->id
4446 : WINED3DFMT_UNKNOWN
,
4447 device
->shader_backend
->shader_has_ffp_proj_control(device
->shader_priv
), mat
);
4449 if ((context
->lastWasPow2Texture
& (1u << tex
)) && state
->textures
[tex
])
4452 FIXME("Non-power-of-two texture being used with generated texture coords.\n");
4453 /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
4454 * fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
4457 TRACE("Non-power-of-two texture matrix multiply fixup.\n");
4458 multiply_matrix(mat
, mat
, (struct wined3d_matrix
*)state
->textures
[tex
]->pow2_matrix
);
4463 void get_pointsize_minmax(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4464 float *out_min
, float *out_max
)
4472 min
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MIN
];
4473 max
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MAX
];
4482 void get_pointsize(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4483 float *out_pointsize
, float *out_att
)
4485 /* POINTSCALEENABLE controls how point size value is treated. If set to
4486 * true, the point size is scaled with respect to height of viewport.
4487 * When set to false point size is in pixels. */
4492 } pointsize
, a
, b
, c
;
4498 pointsize
.d
= state
->render_states
[WINED3D_RS_POINTSIZE
];
4499 a
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_A
];
4500 b
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_B
];
4501 c
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_C
];
4503 if (state
->render_states
[WINED3D_RS_POINTSCALEENABLE
])
4505 float scale_factor
= state
->viewport
.height
* state
->viewport
.height
;
4507 out_att
[0] = a
.f
/ scale_factor
;
4508 out_att
[1] = b
.f
/ scale_factor
;
4509 out_att
[2] = c
.f
/ scale_factor
;
4511 *out_pointsize
= pointsize
.f
;
4514 void get_fog_start_end(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4515 float *start
, float *end
)
4523 switch (context
->fog_source
)
4530 case FOGSOURCE_COORD
:
4536 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGSTART
];
4537 *start
= tmpvalue
.f
;
4538 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGEND
];
4540 /* Special handling for fog_start == fog_end. In d3d with vertex
4541 * fog, everything is fogged. With table fog, everything with
4542 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
4543 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
4544 if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
&& *start
== *end
)
4552 /* This should not happen, context->fog_source is set in wined3d, not the app. */
4553 ERR("Unexpected fog coordinate source.\n");
4559 /* Note: It's the caller's responsibility to ensure values can be expressed
4560 * in the requested format. UNORM formats for example can only express values
4561 * in the range 0.0f -> 1.0f. */
4562 DWORD
wined3d_format_convert_from_float(const struct wined3d_format
*format
, const struct wined3d_color
*color
)
4566 enum wined3d_format_id format_id
;
4578 {WINED3DFMT_B8G8R8A8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
4579 {WINED3DFMT_B8G8R8X8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
4580 {WINED3DFMT_B8G8R8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
4581 {WINED3DFMT_B5G6R5_UNORM
, 31.0f
, 63.0f
, 31.0f
, 0.0f
, 11, 5, 0, 0},
4582 {WINED3DFMT_B5G5R5A1_UNORM
, 31.0f
, 31.0f
, 31.0f
, 1.0f
, 10, 5, 0, 15},
4583 {WINED3DFMT_B5G5R5X1_UNORM
, 31.0f
, 31.0f
, 31.0f
, 1.0f
, 10, 5, 0, 15},
4584 {WINED3DFMT_R8_UNORM
, 255.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 0, 0, 0},
4585 {WINED3DFMT_A8_UNORM
, 0.0f
, 0.0f
, 0.0f
, 255.0f
, 0, 0, 0, 0},
4586 {WINED3DFMT_B4G4R4A4_UNORM
, 15.0f
, 15.0f
, 15.0f
, 15.0f
, 8, 4, 0, 12},
4587 {WINED3DFMT_B4G4R4X4_UNORM
, 15.0f
, 15.0f
, 15.0f
, 15.0f
, 8, 4, 0, 12},
4588 {WINED3DFMT_B2G3R3_UNORM
, 7.0f
, 7.0f
, 3.0f
, 0.0f
, 5, 2, 0, 0},
4589 {WINED3DFMT_R8G8B8A8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 0, 8, 16, 24},
4590 {WINED3DFMT_R8G8B8X8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 0, 8, 16, 24},
4591 {WINED3DFMT_B10G10R10A2_UNORM
, 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
, 20, 10, 0, 30},
4592 {WINED3DFMT_R10G10B10A2_UNORM
, 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
, 0, 10, 20, 30},
4593 {WINED3DFMT_P8_UINT
, 0.0f
, 0.0f
, 0.0f
, 255.0f
, 0, 0, 0, 0},
4597 TRACE("Converting color %s to format %s.\n", debug_color(color
), debug_d3dformat(format
->id
));
4599 for (i
= 0; i
< sizeof(conv
) / sizeof(*conv
); ++i
)
4603 if (format
->id
!= conv
[i
].format_id
) continue;
4605 ret
= ((DWORD
)((color
->r
* conv
[i
].r_mul
) + 0.5f
)) << conv
[i
].r_shift
;
4606 ret
|= ((DWORD
)((color
->g
* conv
[i
].g_mul
) + 0.5f
)) << conv
[i
].g_shift
;
4607 ret
|= ((DWORD
)((color
->b
* conv
[i
].b_mul
) + 0.5f
)) << conv
[i
].b_shift
;
4608 ret
|= ((DWORD
)((color
->a
* conv
[i
].a_mul
) + 0.5f
)) << conv
[i
].a_shift
;
4610 TRACE("Returning 0x%08x.\n", ret
);
4615 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format
->id
));
4620 static float color_to_float(DWORD color
, DWORD size
, DWORD offset
)
4622 DWORD mask
= (1u << size
) - 1;
4630 return (float)color
/ (float)mask
;
4633 BOOL
wined3d_format_convert_color_to_float(const struct wined3d_format
*format
,
4634 const struct wined3d_palette
*palette
, DWORD color
, struct wined3d_color
*float_color
)
4638 case WINED3DFMT_B8G8R8_UNORM
:
4639 case WINED3DFMT_B8G8R8A8_UNORM
:
4640 case WINED3DFMT_B8G8R8X8_UNORM
:
4641 case WINED3DFMT_B5G6R5_UNORM
:
4642 case WINED3DFMT_B5G5R5X1_UNORM
:
4643 case WINED3DFMT_B5G5R5A1_UNORM
:
4644 case WINED3DFMT_B4G4R4A4_UNORM
:
4645 case WINED3DFMT_B2G3R3_UNORM
:
4646 case WINED3DFMT_R8_UNORM
:
4647 case WINED3DFMT_A8_UNORM
:
4648 case WINED3DFMT_B2G3R3A8_UNORM
:
4649 case WINED3DFMT_B4G4R4X4_UNORM
:
4650 case WINED3DFMT_R10G10B10A2_UNORM
:
4651 case WINED3DFMT_R10G10B10A2_SNORM
:
4652 case WINED3DFMT_R8G8B8A8_UNORM
:
4653 case WINED3DFMT_R8G8B8X8_UNORM
:
4654 case WINED3DFMT_R16G16_UNORM
:
4655 case WINED3DFMT_B10G10R10A2_UNORM
:
4656 float_color
->r
= color_to_float(color
, format
->red_size
, format
->red_offset
);
4657 float_color
->g
= color_to_float(color
, format
->green_size
, format
->green_offset
);
4658 float_color
->b
= color_to_float(color
, format
->blue_size
, format
->blue_offset
);
4659 float_color
->a
= color_to_float(color
, format
->alpha_size
, format
->alpha_offset
);
4662 case WINED3DFMT_P8_UINT
:
4665 float_color
->r
= palette
->colors
[color
].rgbRed
/ 255.0f
;
4666 float_color
->g
= palette
->colors
[color
].rgbGreen
/ 255.0f
;
4667 float_color
->b
= palette
->colors
[color
].rgbBlue
/ 255.0f
;
4671 float_color
->r
= 0.0f
;
4672 float_color
->g
= 0.0f
;
4673 float_color
->b
= 0.0f
;
4675 float_color
->a
= color
/ 255.0f
;
4679 ERR("Unhandled conversion from %s to floating point.\n", debug_d3dformat(format
->id
));
4684 void wined3d_format_get_float_color_key(const struct wined3d_format
*format
,
4685 const struct wined3d_color_key
*key
, struct wined3d_color
*float_colors
)
4687 struct wined3d_color slop
;
4691 case WINED3DFMT_B8G8R8_UNORM
:
4692 case WINED3DFMT_B8G8R8A8_UNORM
:
4693 case WINED3DFMT_B8G8R8X8_UNORM
:
4694 case WINED3DFMT_B5G6R5_UNORM
:
4695 case WINED3DFMT_B5G5R5X1_UNORM
:
4696 case WINED3DFMT_B5G5R5A1_UNORM
:
4697 case WINED3DFMT_B4G4R4A4_UNORM
:
4698 case WINED3DFMT_B2G3R3_UNORM
:
4699 case WINED3DFMT_R8_UNORM
:
4700 case WINED3DFMT_A8_UNORM
:
4701 case WINED3DFMT_B2G3R3A8_UNORM
:
4702 case WINED3DFMT_B4G4R4X4_UNORM
:
4703 case WINED3DFMT_R10G10B10A2_UNORM
:
4704 case WINED3DFMT_R10G10B10A2_SNORM
:
4705 case WINED3DFMT_R8G8B8A8_UNORM
:
4706 case WINED3DFMT_R8G8B8X8_UNORM
:
4707 case WINED3DFMT_R16G16_UNORM
:
4708 case WINED3DFMT_B10G10R10A2_UNORM
:
4709 slop
.r
= 0.5f
/ ((1 << format
->red_size
) - 1);
4710 slop
.g
= 0.5f
/ ((1 << format
->green_size
) - 1);
4711 slop
.b
= 0.5f
/ ((1 << format
->blue_size
) - 1);
4712 slop
.a
= 0.5f
/ ((1 << format
->alpha_size
) - 1);
4714 float_colors
[0].r
= color_to_float(key
->color_space_low_value
, format
->red_size
, format
->red_offset
)
4716 float_colors
[0].g
= color_to_float(key
->color_space_low_value
, format
->green_size
, format
->green_offset
)
4718 float_colors
[0].b
= color_to_float(key
->color_space_low_value
, format
->blue_size
, format
->blue_offset
)
4720 float_colors
[0].a
= color_to_float(key
->color_space_low_value
, format
->alpha_size
, format
->alpha_offset
)
4723 float_colors
[1].r
= color_to_float(key
->color_space_high_value
, format
->red_size
, format
->red_offset
)
4725 float_colors
[1].g
= color_to_float(key
->color_space_high_value
, format
->green_size
, format
->green_offset
)
4727 float_colors
[1].b
= color_to_float(key
->color_space_high_value
, format
->blue_size
, format
->blue_offset
)
4729 float_colors
[1].a
= color_to_float(key
->color_space_high_value
, format
->alpha_size
, format
->alpha_offset
)
4733 case WINED3DFMT_P8_UINT
:
4734 float_colors
[0].r
= 0.0f
;
4735 float_colors
[0].g
= 0.0f
;
4736 float_colors
[0].b
= 0.0f
;
4737 float_colors
[0].a
= (key
->color_space_low_value
- 0.5f
) / 255.0f
;
4739 float_colors
[1].r
= 0.0f
;
4740 float_colors
[1].g
= 0.0f
;
4741 float_colors
[1].b
= 0.0f
;
4742 float_colors
[1].a
= (key
->color_space_high_value
+ 0.5f
) / 255.0f
;
4746 ERR("Unhandled color key to float conversion for format %s.\n", debug_d3dformat(format
->id
));
4750 /* DirectDraw stuff */
4751 enum wined3d_format_id
pixelformat_for_depth(DWORD depth
)
4755 case 8: return WINED3DFMT_P8_UINT
;
4756 case 15: return WINED3DFMT_B5G5R5X1_UNORM
;
4757 case 16: return WINED3DFMT_B5G6R5_UNORM
;
4758 case 24: return WINED3DFMT_B8G8R8X8_UNORM
; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
4759 case 32: return WINED3DFMT_B8G8R8X8_UNORM
; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
4760 default: return WINED3DFMT_UNKNOWN
;
4764 void multiply_matrix(struct wined3d_matrix
*dst
, const struct wined3d_matrix
*src1
, const struct wined3d_matrix
*src2
)
4766 struct wined3d_matrix tmp
;
4768 /* Now do the multiplication 'by hand'.
4769 I know that all this could be optimised, but this will be done later :-) */
4770 tmp
._11
= (src1
->_11
* src2
->_11
) + (src1
->_21
* src2
->_12
) + (src1
->_31
* src2
->_13
) + (src1
->_41
* src2
->_14
);
4771 tmp
._21
= (src1
->_11
* src2
->_21
) + (src1
->_21
* src2
->_22
) + (src1
->_31
* src2
->_23
) + (src1
->_41
* src2
->_24
);
4772 tmp
._31
= (src1
->_11
* src2
->_31
) + (src1
->_21
* src2
->_32
) + (src1
->_31
* src2
->_33
) + (src1
->_41
* src2
->_34
);
4773 tmp
._41
= (src1
->_11
* src2
->_41
) + (src1
->_21
* src2
->_42
) + (src1
->_31
* src2
->_43
) + (src1
->_41
* src2
->_44
);
4775 tmp
._12
= (src1
->_12
* src2
->_11
) + (src1
->_22
* src2
->_12
) + (src1
->_32
* src2
->_13
) + (src1
->_42
* src2
->_14
);
4776 tmp
._22
= (src1
->_12
* src2
->_21
) + (src1
->_22
* src2
->_22
) + (src1
->_32
* src2
->_23
) + (src1
->_42
* src2
->_24
);
4777 tmp
._32
= (src1
->_12
* src2
->_31
) + (src1
->_22
* src2
->_32
) + (src1
->_32
* src2
->_33
) + (src1
->_42
* src2
->_34
);
4778 tmp
._42
= (src1
->_12
* src2
->_41
) + (src1
->_22
* src2
->_42
) + (src1
->_32
* src2
->_43
) + (src1
->_42
* src2
->_44
);
4780 tmp
._13
= (src1
->_13
* src2
->_11
) + (src1
->_23
* src2
->_12
) + (src1
->_33
* src2
->_13
) + (src1
->_43
* src2
->_14
);
4781 tmp
._23
= (src1
->_13
* src2
->_21
) + (src1
->_23
* src2
->_22
) + (src1
->_33
* src2
->_23
) + (src1
->_43
* src2
->_24
);
4782 tmp
._33
= (src1
->_13
* src2
->_31
) + (src1
->_23
* src2
->_32
) + (src1
->_33
* src2
->_33
) + (src1
->_43
* src2
->_34
);
4783 tmp
._43
= (src1
->_13
* src2
->_41
) + (src1
->_23
* src2
->_42
) + (src1
->_33
* src2
->_43
) + (src1
->_43
* src2
->_44
);
4785 tmp
._14
= (src1
->_14
* src2
->_11
) + (src1
->_24
* src2
->_12
) + (src1
->_34
* src2
->_13
) + (src1
->_44
* src2
->_14
);
4786 tmp
._24
= (src1
->_14
* src2
->_21
) + (src1
->_24
* src2
->_22
) + (src1
->_34
* src2
->_23
) + (src1
->_44
* src2
->_24
);
4787 tmp
._34
= (src1
->_14
* src2
->_31
) + (src1
->_24
* src2
->_32
) + (src1
->_34
* src2
->_33
) + (src1
->_44
* src2
->_34
);
4788 tmp
._44
= (src1
->_14
* src2
->_41
) + (src1
->_24
* src2
->_42
) + (src1
->_34
* src2
->_43
) + (src1
->_44
* src2
->_44
);
4793 DWORD
get_flexible_vertex_size(DWORD d3dvtVertexType
) {
4796 int numTextures
= (d3dvtVertexType
& WINED3DFVF_TEXCOUNT_MASK
) >> WINED3DFVF_TEXCOUNT_SHIFT
;
4798 if (d3dvtVertexType
& WINED3DFVF_NORMAL
) size
+= 3 * sizeof(float);
4799 if (d3dvtVertexType
& WINED3DFVF_DIFFUSE
) size
+= sizeof(DWORD
);
4800 if (d3dvtVertexType
& WINED3DFVF_SPECULAR
) size
+= sizeof(DWORD
);
4801 if (d3dvtVertexType
& WINED3DFVF_PSIZE
) size
+= sizeof(DWORD
);
4802 switch (d3dvtVertexType
& WINED3DFVF_POSITION_MASK
) {
4803 case WINED3DFVF_XYZ
: size
+= 3 * sizeof(float); break;
4804 case WINED3DFVF_XYZRHW
: size
+= 4 * sizeof(float); break;
4805 case WINED3DFVF_XYZB1
: size
+= 4 * sizeof(float); break;
4806 case WINED3DFVF_XYZB2
: size
+= 5 * sizeof(float); break;
4807 case WINED3DFVF_XYZB3
: size
+= 6 * sizeof(float); break;
4808 case WINED3DFVF_XYZB4
: size
+= 7 * sizeof(float); break;
4809 case WINED3DFVF_XYZB5
: size
+= 8 * sizeof(float); break;
4810 case WINED3DFVF_XYZW
: size
+= 4 * sizeof(float); break;
4811 default: ERR("Unexpected position mask\n");
4813 for (i
= 0; i
< numTextures
; i
++) {
4814 size
+= GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType
, i
) * sizeof(float);
4820 unsigned int wined3d_max_compat_varyings(const struct wined3d_gl_info
*gl_info
)
4822 /* On core profile we have to also count diffuse and specular colors and the
4823 * fog coordinate. */
4824 return gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? MAX_TEXTURES
* 4 : (MAX_TEXTURES
+ 2) * 4 + 1;
4827 void gen_ffp_frag_op(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4828 struct ffp_frag_settings
*settings
, BOOL ignore_textype
)
4833 static const unsigned char args
[WINED3D_TOP_LERP
+ 1] =
4836 /* D3DTOP_DISABLE */ 0,
4837 /* D3DTOP_SELECTARG1 */ ARG1
,
4838 /* D3DTOP_SELECTARG2 */ ARG2
,
4839 /* D3DTOP_MODULATE */ ARG1
| ARG2
,
4840 /* D3DTOP_MODULATE2X */ ARG1
| ARG2
,
4841 /* D3DTOP_MODULATE4X */ ARG1
| ARG2
,
4842 /* D3DTOP_ADD */ ARG1
| ARG2
,
4843 /* D3DTOP_ADDSIGNED */ ARG1
| ARG2
,
4844 /* D3DTOP_ADDSIGNED2X */ ARG1
| ARG2
,
4845 /* D3DTOP_SUBTRACT */ ARG1
| ARG2
,
4846 /* D3DTOP_ADDSMOOTH */ ARG1
| ARG2
,
4847 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1
| ARG2
,
4848 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1
| ARG2
,
4849 /* D3DTOP_BLENDFACTORALPHA */ ARG1
| ARG2
,
4850 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1
| ARG2
,
4851 /* D3DTOP_BLENDCURRENTALPHA */ ARG1
| ARG2
,
4852 /* D3DTOP_PREMODULATE */ ARG1
| ARG2
,
4853 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1
| ARG2
,
4854 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1
| ARG2
,
4855 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1
| ARG2
,
4856 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1
| ARG2
,
4857 /* D3DTOP_BUMPENVMAP */ ARG1
| ARG2
,
4858 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1
| ARG2
,
4859 /* D3DTOP_DOTPRODUCT3 */ ARG1
| ARG2
,
4860 /* D3DTOP_MULTIPLYADD */ ARG1
| ARG2
| ARG0
,
4861 /* D3DTOP_LERP */ ARG1
| ARG2
| ARG0
4865 DWORD cop
, aop
, carg0
, carg1
, carg2
, aarg0
, aarg1
, aarg2
;
4866 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
4867 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
4869 settings
->padding
= 0;
4871 for (i
= 0; i
< d3d_info
->limits
.ffp_blend_stages
; ++i
)
4873 const struct wined3d_texture
*texture
;
4875 settings
->op
[i
].padding
= 0;
4876 if (state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
] == WINED3D_TOP_DISABLE
)
4878 settings
->op
[i
].cop
= WINED3D_TOP_DISABLE
;
4879 settings
->op
[i
].aop
= WINED3D_TOP_DISABLE
;
4880 settings
->op
[i
].carg0
= settings
->op
[i
].carg1
= settings
->op
[i
].carg2
= ARG_UNUSED
;
4881 settings
->op
[i
].aarg0
= settings
->op
[i
].aarg1
= settings
->op
[i
].aarg2
= ARG_UNUSED
;
4882 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
4883 settings
->op
[i
].dst
= resultreg
;
4884 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
4885 settings
->op
[i
].projected
= proj_none
;
4890 if ((texture
= state
->textures
[i
]))
4892 if (can_use_texture_swizzle(gl_info
, texture
->resource
.format
))
4893 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
4895 settings
->op
[i
].color_fixup
= texture
->resource
.format
->color_fixup
;
4898 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
4902 switch (texture
->target
)
4905 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
4908 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_2D
;
4911 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_3D
;
4913 case GL_TEXTURE_CUBE_MAP_ARB
:
4914 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_CUBE
;
4916 case GL_TEXTURE_RECTANGLE_ARB
:
4917 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_RECT
;
4922 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
4923 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
4926 cop
= state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
];
4927 aop
= state
->texture_states
[i
][WINED3D_TSS_ALPHA_OP
];
4929 carg1
= (args
[cop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG1
] : ARG_UNUSED
;
4930 carg2
= (args
[cop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG2
] : ARG_UNUSED
;
4931 carg0
= (args
[cop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG0
] : ARG_UNUSED
;
4933 if (is_invalid_op(state
, i
, cop
, carg1
, carg2
, carg0
))
4937 carg1
= WINED3DTA_CURRENT
;
4938 cop
= WINED3D_TOP_SELECT_ARG1
;
4941 if (cop
== WINED3D_TOP_DOTPRODUCT3
)
4943 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
4944 * the color result to the alpha component of the destination
4953 aarg1
= (args
[aop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG1
] : ARG_UNUSED
;
4954 aarg2
= (args
[aop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG2
] : ARG_UNUSED
;
4955 aarg0
= (args
[aop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG0
] : ARG_UNUSED
;
4958 if (!i
&& state
->textures
[0] && state
->render_states
[WINED3D_RS_COLORKEYENABLE
])
4960 GLenum texture_dimensions
;
4962 texture
= state
->textures
[0];
4963 texture_dimensions
= texture
->target
;
4965 if (texture_dimensions
== GL_TEXTURE_2D
|| texture_dimensions
== GL_TEXTURE_RECTANGLE_ARB
)
4967 if (texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
&& !texture
->resource
.format
->alpha_size
)
4969 if (aop
== WINED3D_TOP_DISABLE
)
4971 aarg1
= WINED3DTA_TEXTURE
;
4972 aop
= WINED3D_TOP_SELECT_ARG1
;
4974 else if (aop
== WINED3D_TOP_SELECT_ARG1
&& aarg1
!= WINED3DTA_TEXTURE
)
4976 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
])
4978 aarg2
= WINED3DTA_TEXTURE
;
4979 aop
= WINED3D_TOP_MODULATE
;
4981 else aarg1
= WINED3DTA_TEXTURE
;
4983 else if (aop
== WINED3D_TOP_SELECT_ARG2
&& aarg2
!= WINED3DTA_TEXTURE
)
4985 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
])
4987 aarg1
= WINED3DTA_TEXTURE
;
4988 aop
= WINED3D_TOP_MODULATE
;
4990 else aarg2
= WINED3DTA_TEXTURE
;
4996 if (is_invalid_op(state
, i
, aop
, aarg1
, aarg2
, aarg0
))
5000 aarg1
= WINED3DTA_CURRENT
;
5001 aop
= WINED3D_TOP_SELECT_ARG1
;
5004 if (carg1
== WINED3DTA_TEXTURE
|| carg2
== WINED3DTA_TEXTURE
|| carg0
== WINED3DTA_TEXTURE
5005 || aarg1
== WINED3DTA_TEXTURE
|| aarg2
== WINED3DTA_TEXTURE
|| aarg0
== WINED3DTA_TEXTURE
)
5007 ttff
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
5008 if (ttff
== (WINED3D_TTFF_PROJECTED
| WINED3D_TTFF_COUNT3
))
5009 settings
->op
[i
].projected
= proj_count3
;
5010 else if (ttff
& WINED3D_TTFF_PROJECTED
)
5011 settings
->op
[i
].projected
= proj_count4
;
5013 settings
->op
[i
].projected
= proj_none
;
5017 settings
->op
[i
].projected
= proj_none
;
5020 settings
->op
[i
].cop
= cop
;
5021 settings
->op
[i
].aop
= aop
;
5022 settings
->op
[i
].carg0
= carg0
;
5023 settings
->op
[i
].carg1
= carg1
;
5024 settings
->op
[i
].carg2
= carg2
;
5025 settings
->op
[i
].aarg0
= aarg0
;
5026 settings
->op
[i
].aarg1
= aarg1
;
5027 settings
->op
[i
].aarg2
= aarg2
;
5029 if (state
->texture_states
[i
][WINED3D_TSS_RESULT_ARG
] == WINED3DTA_TEMP
)
5030 settings
->op
[i
].dst
= tempreg
;
5032 settings
->op
[i
].dst
= resultreg
;
5035 /* Clear unsupported stages */
5036 for(; i
< MAX_TEXTURES
; i
++) {
5037 memset(&settings
->op
[i
], 0xff, sizeof(settings
->op
[i
]));
5040 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
5042 settings
->fog
= WINED3D_FFP_PS_FOG_OFF
;
5044 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
)
5046 if (use_vs(state
) || state
->vertex_declaration
->position_transformed
)
5048 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
5052 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
5054 case WINED3D_FOG_NONE
:
5055 case WINED3D_FOG_LINEAR
:
5056 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
5058 case WINED3D_FOG_EXP
:
5059 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
5061 case WINED3D_FOG_EXP2
:
5062 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
5069 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
5071 case WINED3D_FOG_LINEAR
:
5072 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
5074 case WINED3D_FOG_EXP
:
5075 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
5077 case WINED3D_FOG_EXP2
:
5078 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
5082 settings
->sRGB_write
= !gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
] && needs_srgb_write(context
, state
, state
->fb
);
5083 if (d3d_info
->vs_clipping
|| !use_vs(state
) || !state
->render_states
[WINED3D_RS_CLIPPING
]
5084 || !state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
])
5086 /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
5087 * the fixed function vertex pipeline is used(which always supports clipplanes), or
5088 * if no clipplane is enabled
5090 settings
->emul_clipplanes
= 0;
5092 settings
->emul_clipplanes
= 1;
5095 if (state
->render_states
[WINED3D_RS_COLORKEYENABLE
] && state
->textures
[0]
5096 && state
->textures
[0]->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
5097 && settings
->op
[0].cop
!= WINED3D_TOP_DISABLE
)
5098 settings
->color_key_enabled
= 1;
5100 settings
->color_key_enabled
= 0;
5102 /* texcoords_initialized is set to meaningful values only when GL doesn't
5103 * support enough varyings to always pass around all the possible texture
5105 * This is used to avoid reading a varying not written by the vertex shader.
5106 * Reading uninitialized varyings on core profile contexts results in an
5107 * error while with builtin varyings on legacy contexts you get undefined
5109 if (d3d_info
->limits
.varying_count
5110 && d3d_info
->limits
.varying_count
< wined3d_max_compat_varyings(gl_info
))
5112 settings
->texcoords_initialized
= 0;
5113 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
5117 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
5118 settings
->texcoords_initialized
|= 1u << i
;
5122 const struct wined3d_stream_info
*si
= &context
->stream_info
;
5123 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5124 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
5125 & WINED3D_FFP_TCI_MASK
5126 || (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
5127 settings
->texcoords_initialized
|= 1u << i
;
5133 settings
->texcoords_initialized
= (1u << MAX_TEXTURES
) - 1;
5136 settings
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
5137 && state
->gl_primitive_type
== GL_POINTS
;
5139 if (d3d_info
->emulated_flatshading
)
5140 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
5142 settings
->flatshading
= FALSE
;
5145 const struct ffp_frag_desc
*find_ffp_frag_shader(const struct wine_rb_tree
*fragment_shaders
,
5146 const struct ffp_frag_settings
*settings
)
5148 struct wine_rb_entry
*entry
= wine_rb_get(fragment_shaders
, settings
);
5149 return entry
? WINE_RB_ENTRY_VALUE(entry
, struct ffp_frag_desc
, entry
) : NULL
;
5152 void add_ffp_frag_shader(struct wine_rb_tree
*shaders
, struct ffp_frag_desc
*desc
)
5154 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
5155 * whereas desc points to an extended structure with implementation specific parts. */
5156 if (wine_rb_put(shaders
, &desc
->settings
, &desc
->entry
) == -1)
5158 ERR("Failed to insert ffp frag shader.\n");
5162 /* Activates the texture dimension according to the bound D3D texture. Does
5163 * not care for the colorop or correct gl texture unit (when using nvrc).
5164 * Requires the caller to activate the correct unit. */
5165 /* Context activation is done by the caller (state handler). */
5166 void texture_activate_dimensions(const struct wined3d_texture
*texture
, const struct wined3d_gl_info
*gl_info
)
5170 switch (texture
->target
)
5173 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5174 checkGLcall("glDisable(GL_TEXTURE_3D)");
5175 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5177 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5178 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5180 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5182 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5183 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5185 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
5186 checkGLcall("glEnable(GL_TEXTURE_2D)");
5188 case GL_TEXTURE_RECTANGLE_ARB
:
5189 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
5190 checkGLcall("glDisable(GL_TEXTURE_2D)");
5191 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5192 checkGLcall("glDisable(GL_TEXTURE_3D)");
5193 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5195 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5196 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5198 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_RECTANGLE_ARB
);
5199 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
5202 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5204 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5205 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5207 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5209 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5210 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5212 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
5213 checkGLcall("glDisable(GL_TEXTURE_2D)");
5214 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_3D
);
5215 checkGLcall("glEnable(GL_TEXTURE_3D)");
5217 case GL_TEXTURE_CUBE_MAP_ARB
:
5218 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
5219 checkGLcall("glDisable(GL_TEXTURE_2D)");
5220 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5221 checkGLcall("glDisable(GL_TEXTURE_3D)");
5222 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5224 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5225 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5227 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
5228 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
5234 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
5235 checkGLcall("glEnable(GL_TEXTURE_2D)");
5236 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
5237 checkGLcall("glDisable(GL_TEXTURE_3D)");
5238 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
5240 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
5241 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
5243 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
5245 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
5246 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
5248 /* Binding textures is done by samplers. A dummy texture will be bound */
5252 /* Context activation is done by the caller (state handler). */
5253 void sampler_texdim(struct wined3d_context
*context
, const struct wined3d_state
*state
, DWORD state_id
)
5255 DWORD sampler
= state_id
- STATE_SAMPLER(0);
5256 DWORD mapped_stage
= context
->tex_unit_map
[sampler
];
5258 /* No need to enable / disable anything here for unused samplers. The
5259 * tex_colorop handler takes care. Also no action is needed with pixel
5260 * shaders, or if tex_colorop will take care of this business. */
5261 if (mapped_stage
== WINED3D_UNMAPPED_STAGE
|| mapped_stage
>= context
->gl_info
->limits
.textures
)
5263 if (sampler
>= context
->lowest_disabled_stage
)
5265 if (isStateDirty(context
, STATE_TEXTURESTAGE(sampler
, WINED3D_TSS_COLOR_OP
)))
5268 texture_activate_dimensions(state
->textures
[sampler
], context
->gl_info
);
5271 void *wined3d_rb_alloc(size_t size
)
5273 return HeapAlloc(GetProcessHeap(), 0, size
);
5276 void *wined3d_rb_realloc(void *ptr
, size_t size
)
5278 return HeapReAlloc(GetProcessHeap(), 0, ptr
, size
);
5281 void wined3d_rb_free(void *ptr
)
5283 HeapFree(GetProcessHeap(), 0, ptr
);
5286 static int ffp_frag_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
5288 const struct ffp_frag_settings
*ka
= key
;
5289 const struct ffp_frag_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
, const struct ffp_frag_desc
, entry
)->settings
;
5291 return memcmp(ka
, kb
, sizeof(*ka
));
5294 const struct wine_rb_functions wined3d_ffp_frag_program_rb_functions
=
5299 ffp_frag_program_key_compare
,
5302 void wined3d_ffp_get_vs_settings(const struct wined3d_context
*context
,
5303 const struct wined3d_state
*state
, struct wined3d_ffp_vs_settings
*settings
)
5305 const struct wined3d_stream_info
*si
= &context
->stream_info
;
5306 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
5307 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
5308 unsigned int coord_idx
, i
;
5310 if (si
->position_transformed
)
5312 memset(settings
, 0, sizeof(*settings
));
5314 settings
->transformed
= 1;
5315 settings
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
5316 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
5317 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
5318 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
5319 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
5320 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
5322 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
5324 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
5326 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5327 if (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
5328 settings
->texcoords
|= 1u << i
;
5329 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5331 if (d3d_info
->limits
.varying_count
>= wined3d_max_compat_varyings(gl_info
))
5332 settings
->texcoords
= (1u << MAX_TEXTURES
) - 1;
5334 if (d3d_info
->emulated_flatshading
)
5335 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
5337 settings
->flatshading
= FALSE
;
5342 switch (state
->render_states
[WINED3D_RS_VERTEXBLEND
])
5344 case WINED3D_VBF_DISABLE
:
5345 case WINED3D_VBF_1WEIGHTS
:
5346 case WINED3D_VBF_2WEIGHTS
:
5347 case WINED3D_VBF_3WEIGHTS
:
5348 settings
->vertexblends
= state
->render_states
[WINED3D_RS_VERTEXBLEND
];
5351 FIXME("Unsupported vertex blending: %d\n", state
->render_states
[WINED3D_RS_VERTEXBLEND
]);
5355 settings
->transformed
= 0;
5356 settings
->clipping
= state
->render_states
[WINED3D_RS_CLIPPING
]
5357 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
5358 settings
->normal
= !!(si
->use_map
& (1u << WINED3D_FFP_NORMAL
));
5359 settings
->normalize
= settings
->normal
&& state
->render_states
[WINED3D_RS_NORMALIZENORMALS
];
5360 settings
->lighting
= !!state
->render_states
[WINED3D_RS_LIGHTING
];
5361 settings
->localviewer
= !!state
->render_states
[WINED3D_RS_LOCALVIEWER
];
5362 settings
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
5363 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
5365 if (state
->render_states
[WINED3D_RS_COLORVERTEX
] && (si
->use_map
& (1u << WINED3D_FFP_DIFFUSE
)))
5367 settings
->diffuse_source
= state
->render_states
[WINED3D_RS_DIFFUSEMATERIALSOURCE
];
5368 settings
->emissive_source
= state
->render_states
[WINED3D_RS_EMISSIVEMATERIALSOURCE
];
5369 settings
->ambient_source
= state
->render_states
[WINED3D_RS_AMBIENTMATERIALSOURCE
];
5370 settings
->specular_source
= state
->render_states
[WINED3D_RS_SPECULARMATERIALSOURCE
];
5374 settings
->diffuse_source
= WINED3D_MCS_MATERIAL
;
5375 settings
->emissive_source
= WINED3D_MCS_MATERIAL
;
5376 settings
->ambient_source
= WINED3D_MCS_MATERIAL
;
5377 settings
->specular_source
= WINED3D_MCS_MATERIAL
;
5380 settings
->texcoords
= 0;
5381 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
5383 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5384 if (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
5385 settings
->texcoords
|= 1u << i
;
5386 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
5388 if (d3d_info
->limits
.varying_count
>= wined3d_max_compat_varyings(gl_info
))
5389 settings
->texcoords
= (1u << MAX_TEXTURES
) - 1;
5391 settings
->light_type
= 0;
5392 for (i
= 0; i
< MAX_ACTIVE_LIGHTS
; ++i
)
5394 if (state
->lights
[i
])
5395 settings
->light_type
|= (state
->lights
[i
]->OriginalParms
.type
5396 & WINED3D_FFP_LIGHT_TYPE_MASK
) << WINED3D_FFP_LIGHT_TYPE_SHIFT(i
);
5399 settings
->ortho_fog
= 0;
5400 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
5401 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
5402 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
5404 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
5406 if (state
->transforms
[WINED3D_TS_PROJECTION
]._14
== 0.0f
5407 && state
->transforms
[WINED3D_TS_PROJECTION
]._24
== 0.0f
5408 && state
->transforms
[WINED3D_TS_PROJECTION
]._34
== 0.0f
5409 && state
->transforms
[WINED3D_TS_PROJECTION
]._44
== 1.0f
)
5410 settings
->ortho_fog
= 1;
5412 else if (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
] == WINED3D_FOG_NONE
)
5413 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
5414 else if (state
->render_states
[WINED3D_RS_RANGEFOGENABLE
])
5415 settings
->fog_mode
= WINED3D_FFP_VS_FOG_RANGE
;
5417 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
5419 if (d3d_info
->emulated_flatshading
)
5420 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
5422 settings
->flatshading
= FALSE
;
5424 settings
->padding
= 0;
5427 static int wined3d_ffp_vertex_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
5429 const struct wined3d_ffp_vs_settings
*ka
= key
;
5430 const struct wined3d_ffp_vs_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
,
5431 const struct wined3d_ffp_vs_desc
, entry
)->settings
;
5433 return memcmp(ka
, kb
, sizeof(*ka
));
5436 const struct wine_rb_functions wined3d_ffp_vertex_program_rb_functions
=
5441 wined3d_ffp_vertex_program_key_compare
,
5444 const struct blit_shader
*wined3d_select_blitter(const struct wined3d_gl_info
*gl_info
,
5445 const struct wined3d_d3d_info
*d3d_info
, enum wined3d_blit_op blit_op
,
5446 const RECT
*src_rect
, DWORD src_usage
, enum wined3d_pool src_pool
, const struct wined3d_format
*src_format
,
5447 const RECT
*dst_rect
, DWORD dst_usage
, enum wined3d_pool dst_pool
, const struct wined3d_format
*dst_format
)
5449 static const struct blit_shader
* const blitters
[] =
5457 for (i
= 0; i
< sizeof(blitters
) / sizeof(*blitters
); ++i
)
5459 if (blitters
[i
]->blit_supported(gl_info
, d3d_info
, blit_op
,
5460 src_rect
, src_usage
, src_pool
, src_format
,
5461 dst_rect
, dst_usage
, dst_pool
, dst_format
))
5468 void wined3d_get_draw_rect(const struct wined3d_state
*state
, RECT
*rect
)
5470 const struct wined3d_viewport
*vp
= &state
->viewport
;
5472 SetRect(rect
, vp
->x
, vp
->y
, vp
->x
+ vp
->width
, vp
->y
+ vp
->height
);
5474 if (state
->render_states
[WINED3D_RS_SCISSORTESTENABLE
])
5475 IntersectRect(rect
, rect
, &state
->scissor_rect
);
5478 const char *wined3d_debug_location(DWORD location
)
5480 const char *prefix
= "";
5481 const char *suffix
= "";
5484 if (wined3d_popcount(location
) > 16)
5487 location
= ~location
;
5492 #define LOCATION_TO_STR(u) if (location & u) { strcat(buf, " | "#u); location &= ~u; }
5493 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED
);
5494 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM
);
5495 LOCATION_TO_STR(WINED3D_LOCATION_USER_MEMORY
);
5496 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER
);
5497 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB
);
5498 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB
);
5499 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE
);
5500 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE
);
5501 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED
);
5502 #undef LOCATION_TO_STR
5503 if (location
) FIXME("Unrecognized location flag(s) %#x.\n", location
);
5505 return wine_dbg_sprintf("%s%s%s", prefix
, buf
[0] ? &buf
[3] : "0", suffix
);
5508 /* Print a floating point value with the %.8e format specifier, always using
5509 * '.' as decimal separator. */
5510 void wined3d_ftoa(float value
, char *s
)
5514 if (copysignf(1.0f
, value
) < 0.0f
)
5517 /* Be sure to allocate a buffer of at least 17 characters for the result
5518 as sprintf may return a 3 digit exponent when using the MSVC runtime
5519 instead of a 2 digit exponent. */
5520 sprintf(s
, "%.8e", value
);
5521 if (isfinite(value
))
5525 void wined3d_release_dc(HWND window
, HDC dc
)
5527 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
5528 * However, that's not what actually happens, and there are user32 tests
5529 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
5530 * So explicitly check that the DC belongs to the window, since we want to
5531 * avoid releasing a DC that belongs to some other window if the original
5532 * window was already destroyed. */
5533 if (WindowFromDC(dc
) != window
)
5534 WARN("DC %p does not belong to window %p.\n", dc
, window
);
5535 else if (!ReleaseDC(window
, dc
))
5536 ERR("Failed to release device context %p, last error %#x.\n", dc
, GetLastError());
5539 BOOL
wined3d_clip_blit(const RECT
*clip_rect
, RECT
*clipped
, RECT
*other
)
5541 RECT orig
= *clipped
;
5542 float scale_x
= (float)(orig
.right
- orig
.left
) / (float)(other
->right
- other
->left
);
5543 float scale_y
= (float)(orig
.bottom
- orig
.top
) / (float)(other
->bottom
- other
->top
);
5545 IntersectRect(clipped
, clipped
, clip_rect
);
5547 if (IsRectEmpty(clipped
))
5549 SetRectEmpty(other
);
5553 other
->left
+= (LONG
)((clipped
->left
- orig
.left
) / scale_x
);
5554 other
->top
+= (LONG
)((clipped
->top
- orig
.top
) / scale_y
);
5555 other
->right
-= (LONG
)((orig
.right
- clipped
->right
) / scale_x
);
5556 other
->bottom
-= (LONG
)((orig
.bottom
- clipped
->bottom
) / scale_y
);