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 struct wined3d_format_channels
38 enum wined3d_format_id id
;
39 DWORD red_size
, green_size
, blue_size
, alpha_size
;
40 DWORD red_offset
, green_offset
, blue_offset
, alpha_offset
;
42 BYTE depth_size
, stencil_size
;
45 static const struct wined3d_format_channels formats
[] =
48 * format id r g b a r g b a bpp depth stencil */
49 {WINED3DFMT_UNKNOWN
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
51 {WINED3DFMT_UYVY
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
52 {WINED3DFMT_YUY2
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
53 {WINED3DFMT_YV12
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
54 {WINED3DFMT_NV12
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
55 {WINED3DFMT_DXT1
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
56 {WINED3DFMT_DXT2
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
57 {WINED3DFMT_DXT3
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
58 {WINED3DFMT_DXT4
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
59 {WINED3DFMT_DXT5
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
60 {WINED3DFMT_MULTI2_ARGB8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
61 {WINED3DFMT_G8R8_G8B8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
62 {WINED3DFMT_R8G8_B8G8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
64 {WINED3DFMT_R32_FLOAT
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
65 {WINED3DFMT_R32G32_FLOAT
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
66 {WINED3DFMT_R32G32B32_FLOAT
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
67 {WINED3DFMT_R32G32B32A32_FLOAT
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
69 {WINED3DFMT_R8G8_SNORM_Cx
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
71 {WINED3DFMT_R16_FLOAT
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
72 {WINED3DFMT_R16G16_FLOAT
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
73 {WINED3DFMT_R16G16_SINT
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
74 {WINED3DFMT_R16G16B16A16_FLOAT
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
75 {WINED3DFMT_R16G16B16A16_SINT
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
76 /* Palettized formats */
77 {WINED3DFMT_P8_UINT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
78 {WINED3DFMT_P8_UINT
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
79 /* Standard ARGB formats. */
80 {WINED3DFMT_B8G8R8_UNORM
, 8, 8, 8, 0, 16, 8, 0, 0, 3, 0, 0},
81 {WINED3DFMT_B8G8R8A8_UNORM
, 8, 8, 8, 8, 16, 8, 0, 24, 4, 0, 0},
82 {WINED3DFMT_B8G8R8X8_UNORM
, 8, 8, 8, 0, 16, 8, 0, 0, 4, 0, 0},
83 {WINED3DFMT_B5G6R5_UNORM
, 5, 6, 5, 0, 11, 5, 0, 0, 2, 0, 0},
84 {WINED3DFMT_B5G5R5X1_UNORM
, 5, 5, 5, 0, 10, 5, 0, 0, 2, 0, 0},
85 {WINED3DFMT_B5G5R5A1_UNORM
, 5, 5, 5, 1, 10, 5, 0, 15, 2, 0, 0},
86 {WINED3DFMT_B4G4R4A4_UNORM
, 4, 4, 4, 4, 8, 4, 0, 12, 2, 0, 0},
87 {WINED3DFMT_B2G3R3_UNORM
, 3, 3, 2, 0, 5, 2, 0, 0, 1, 0, 0},
88 {WINED3DFMT_R8_UNORM
, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
89 {WINED3DFMT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0},
90 {WINED3DFMT_B2G3R3A8_UNORM
, 3, 3, 2, 8, 5, 2, 0, 8, 2, 0, 0},
91 {WINED3DFMT_B4G4R4X4_UNORM
, 4, 4, 4, 0, 8, 4, 0, 0, 2, 0, 0},
92 {WINED3DFMT_R10G10B10A2_UNORM
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
93 {WINED3DFMT_R10G10B10A2_UINT
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
94 {WINED3DFMT_R10G10B10A2_SNORM
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
95 {WINED3DFMT_R8G8B8A8_UNORM
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
96 {WINED3DFMT_R8G8B8A8_UNORM_SRGB
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
97 {WINED3DFMT_R8G8B8A8_UINT
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
98 {WINED3DFMT_R8G8B8X8_UNORM
, 8, 8, 8, 0, 0, 8, 16, 0, 4, 0, 0},
99 {WINED3DFMT_R16G16_UNORM
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
100 {WINED3DFMT_B10G10R10A2_UNORM
, 10, 10, 10, 2, 20, 10, 0, 30, 4, 0, 0},
101 {WINED3DFMT_R16G16B16A16_UNORM
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
103 {WINED3DFMT_L8_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
104 {WINED3DFMT_L8A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
105 {WINED3DFMT_L4A4_UNORM
, 0, 0, 0, 4, 0, 0, 0, 4, 1, 0, 0},
106 {WINED3DFMT_L16_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
107 /* Bump mapping stuff */
108 {WINED3DFMT_R8G8_SNORM
, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
109 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, 5, 5, 0, 0, 0, 5, 0, 0, 2, 0, 0},
110 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, 8, 8, 0, 0, 0, 8, 0, 0, 4, 0, 0},
111 {WINED3DFMT_R8G8B8A8_SNORM
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
112 {WINED3DFMT_R16G16_SNORM
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
113 {WINED3DFMT_R10G11B11_SNORM
, 10, 11, 11, 0, 0, 10, 21, 0, 4, 0, 0},
114 {WINED3DFMT_R10G10B10_SNORM_A2_UNORM
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
115 /* Depth stencil formats */
116 {WINED3DFMT_D16_LOCKABLE
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
117 {WINED3DFMT_D32_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
118 {WINED3DFMT_S1_UINT_D15_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 15, 1},
119 {WINED3DFMT_D24_UNORM_S8_UINT
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
120 {WINED3DFMT_X8D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 0},
121 {WINED3DFMT_S4X4_UINT_D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 4},
122 {WINED3DFMT_D16_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
123 {WINED3DFMT_D32_FLOAT
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
124 {WINED3DFMT_S8_UINT_D24_FLOAT
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
125 {WINED3DFMT_VERTEXDATA
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
126 {WINED3DFMT_R16_UINT
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
127 {WINED3DFMT_R32_UINT
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
128 {WINED3DFMT_R32G32_UINT
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
129 {WINED3DFMT_R32G32B32_UINT
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
130 {WINED3DFMT_R32G32B32A32_UINT
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
131 {WINED3DFMT_R16G16B16A16_SNORM
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
132 /* Vendor-specific formats */
133 {WINED3DFMT_ATI1N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
134 {WINED3DFMT_ATI2N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
135 {WINED3DFMT_NVDB
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
136 {WINED3DFMT_INST
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
137 {WINED3DFMT_INTZ
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
138 {WINED3DFMT_RESZ
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
139 {WINED3DFMT_NVHU
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
140 {WINED3DFMT_NVHS
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
141 {WINED3DFMT_NULL
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
142 /* Unsure about them, could not find a Windows driver that supports them */
143 {WINED3DFMT_R16
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
144 {WINED3DFMT_AL16
, 0, 0, 0, 16, 0, 0, 0, 16, 4, 0, 0},
146 {WINED3DFMT_R8_TYPELESS
, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
147 {WINED3DFMT_R8G8_TYPELESS
, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
148 {WINED3DFMT_R8G8B8A8_TYPELESS
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
149 {WINED3DFMT_R16_TYPELESS
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
150 {WINED3DFMT_R16G16_TYPELESS
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
151 {WINED3DFMT_R16G16B16A16_TYPELESS
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
152 {WINED3DFMT_R32_TYPELESS
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
153 {WINED3DFMT_R32G32_TYPELESS
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
154 {WINED3DFMT_R32G32B32_TYPELESS
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
155 {WINED3DFMT_R32G32B32A32_TYPELESS
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
158 struct wined3d_format_base_flags
160 enum wined3d_format_id id
;
164 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
165 * still needs to use the correct block based calculation for e.g. the
167 static const struct wined3d_format_base_flags format_base_flags
[] =
169 {WINED3DFMT_P8_UINT
, WINED3DFMT_FLAG_GETDC
},
170 {WINED3DFMT_B8G8R8_UNORM
, WINED3DFMT_FLAG_GETDC
},
171 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3DFMT_FLAG_GETDC
},
172 {WINED3DFMT_B8G8R8X8_UNORM
, WINED3DFMT_FLAG_GETDC
},
173 {WINED3DFMT_B5G6R5_UNORM
, WINED3DFMT_FLAG_GETDC
},
174 {WINED3DFMT_B5G5R5X1_UNORM
, WINED3DFMT_FLAG_GETDC
},
175 {WINED3DFMT_B5G5R5A1_UNORM
, WINED3DFMT_FLAG_GETDC
},
176 {WINED3DFMT_B4G4R4A4_UNORM
, WINED3DFMT_FLAG_GETDC
},
177 {WINED3DFMT_B4G4R4X4_UNORM
, WINED3DFMT_FLAG_GETDC
},
178 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3DFMT_FLAG_GETDC
},
179 {WINED3DFMT_R8G8B8X8_UNORM
, WINED3DFMT_FLAG_GETDC
},
180 {WINED3DFMT_ATI1N
, WINED3DFMT_FLAG_BROKEN_PITCH
},
181 {WINED3DFMT_ATI2N
, WINED3DFMT_FLAG_BROKEN_PITCH
},
182 {WINED3DFMT_R32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
183 {WINED3DFMT_R32G32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
184 {WINED3DFMT_R32G32B32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
185 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
186 {WINED3DFMT_R16_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
187 {WINED3DFMT_R16G16_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
188 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
189 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
190 {WINED3DFMT_S8_UINT_D24_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
193 struct wined3d_format_block_info
195 enum wined3d_format_id id
;
198 UINT block_byte_count
;
202 static const struct wined3d_format_block_info format_block_info
[] =
204 {WINED3DFMT_DXT1
, 4, 4, 8, TRUE
},
205 {WINED3DFMT_DXT2
, 4, 4, 16, TRUE
},
206 {WINED3DFMT_DXT3
, 4, 4, 16, TRUE
},
207 {WINED3DFMT_DXT4
, 4, 4, 16, TRUE
},
208 {WINED3DFMT_DXT5
, 4, 4, 16, TRUE
},
209 {WINED3DFMT_ATI1N
, 4, 4, 8, FALSE
},
210 {WINED3DFMT_ATI2N
, 4, 4, 16, FALSE
},
211 {WINED3DFMT_YUY2
, 2, 1, 4, FALSE
},
212 {WINED3DFMT_UYVY
, 2, 1, 4, FALSE
},
215 struct wined3d_format_vertex_info
217 enum wined3d_format_id id
;
218 enum wined3d_ffp_emit_idx emit_idx
;
219 GLint component_count
;
222 GLboolean gl_normalized
;
223 unsigned int component_size
;
226 static const struct wined3d_format_vertex_info format_vertex_info
[] =
228 {WINED3DFMT_R32_FLOAT
, WINED3D_FFP_EMIT_FLOAT1
, 1, GL_FLOAT
, 1, GL_FALSE
, sizeof(float)},
229 {WINED3DFMT_R32G32_FLOAT
, WINED3D_FFP_EMIT_FLOAT2
, 2, GL_FLOAT
, 2, GL_FALSE
, sizeof(float)},
230 {WINED3DFMT_R32G32B32_FLOAT
, WINED3D_FFP_EMIT_FLOAT3
, 3, GL_FLOAT
, 3, GL_FALSE
, sizeof(float)},
231 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3D_FFP_EMIT_FLOAT4
, 4, GL_FLOAT
, 4, GL_FALSE
, sizeof(float)},
232 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3D_FFP_EMIT_D3DCOLOR
, 4, GL_UNSIGNED_BYTE
, 4, GL_TRUE
, sizeof(BYTE
)},
233 {WINED3DFMT_R8G8B8A8_UINT
, WINED3D_FFP_EMIT_UBYTE4
, 4, GL_UNSIGNED_BYTE
, 4, GL_FALSE
, sizeof(BYTE
)},
234 {WINED3DFMT_R16G16_SINT
, WINED3D_FFP_EMIT_SHORT2
, 2, GL_SHORT
, 2, GL_FALSE
, sizeof(short int)},
235 {WINED3DFMT_R16G16B16A16_SINT
, WINED3D_FFP_EMIT_SHORT4
, 4, GL_SHORT
, 4, GL_FALSE
, sizeof(short int)},
236 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3D_FFP_EMIT_UBYTE4N
, 4, GL_UNSIGNED_BYTE
, 4, GL_TRUE
, sizeof(BYTE
)},
237 {WINED3DFMT_R16G16_SNORM
, WINED3D_FFP_EMIT_SHORT2N
, 2, GL_SHORT
, 2, GL_TRUE
, sizeof(short int)},
238 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3D_FFP_EMIT_SHORT4N
, 4, GL_SHORT
, 4, GL_TRUE
, sizeof(short int)},
239 {WINED3DFMT_R16G16_UNORM
, WINED3D_FFP_EMIT_USHORT2N
, 2, GL_UNSIGNED_SHORT
, 2, GL_TRUE
, sizeof(short int)},
240 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3D_FFP_EMIT_USHORT4N
, 4, GL_UNSIGNED_SHORT
, 4, GL_TRUE
, sizeof(short int)},
241 {WINED3DFMT_R10G10B10A2_UINT
, WINED3D_FFP_EMIT_UDEC3
, 3, GL_UNSIGNED_SHORT
, 3, GL_FALSE
, sizeof(short int)},
242 {WINED3DFMT_R10G10B10A2_SNORM
, WINED3D_FFP_EMIT_DEC3N
, 3, GL_SHORT
, 3, GL_TRUE
, sizeof(short int)},
243 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, 2, GL_FLOAT
, 2, GL_FALSE
, sizeof(GLhalfNV
)},
244 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, 4, GL_FLOAT
, 4, GL_FALSE
, sizeof(GLhalfNV
)},
245 {WINED3DFMT_R32_UINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_INT
, 1, GL_FALSE
, sizeof(UINT
)},
246 {WINED3DFMT_R32G32_UINT
, WINED3D_FFP_EMIT_INVALID
, 2, GL_UNSIGNED_INT
, 2, GL_FALSE
, sizeof(UINT
)},
247 {WINED3DFMT_R32G32B32_UINT
, WINED3D_FFP_EMIT_INVALID
, 3, GL_UNSIGNED_INT
, 3, GL_FALSE
, sizeof(UINT
)},
248 {WINED3DFMT_R32G32B32A32_UINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_UNSIGNED_INT
, 4, GL_FALSE
, sizeof(UINT
)},
251 struct wined3d_format_texture_info
253 enum wined3d_format_id id
;
255 GLint gl_srgb_internal
;
256 GLint gl_rt_internal
;
259 unsigned int conv_byte_count
;
261 enum wined3d_gl_extension extension
;
262 void (*convert
)(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
263 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
);
266 static void convert_l4a4_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
267 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
269 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
270 * format+type combination to load it. Thus convert it to A8L8, then load it
271 * with A4L4 internal, but A8L8 format+type
273 unsigned int x
, y
, z
;
274 const unsigned char *Source
;
277 for (z
= 0; z
< depth
; z
++)
279 for (y
= 0; y
< height
; y
++)
281 Source
= src
+ z
* src_slice_pitch
+ y
* src_row_pitch
;
282 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
283 for (x
= 0; x
< width
; x
++ )
285 unsigned char color
= (*Source
++);
286 /* A */ Dest
[1] = (color
& 0xf0u
) << 0;
287 /* L */ Dest
[0] = (color
& 0x0fu
) << 4;
294 static void convert_r5g5_snorm_l6_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
295 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
297 unsigned int x
, y
, z
;
298 unsigned char r_in
, g_in
, l_in
;
299 const unsigned short *texel_in
;
300 unsigned short *texel_out
;
302 /* Emulating signed 5 bit values with unsigned 5 bit values has some precision problems by design:
303 * E.g. the signed input value 0 becomes 16. GL normalizes it to 16 / 31 = 0.516. We convert it
304 * back to a signed value by subtracting 0.5 and multiplying by 2.0. The resulting value is
305 * ((16 / 31) - 0.5) * 2.0 = 0.032, which is quite different from the intended result 0.000. */
306 for (z
= 0; z
< depth
; z
++)
308 for (y
= 0; y
< height
; y
++)
310 texel_out
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
311 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
312 for (x
= 0; x
< width
; x
++ )
314 l_in
= (*texel_in
& 0xfc00u
) >> 10;
315 g_in
= (*texel_in
& 0x03e0u
) >> 5;
316 r_in
= *texel_in
& 0x001fu
;
318 *texel_out
= ((r_in
+ 16) << 11) | (l_in
<< 5) | (g_in
+ 16);
326 static void convert_r5g5_snorm_l6_unorm_ext(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
327 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
329 unsigned int x
, y
, z
;
330 unsigned char *texel_out
, r_out
, g_out
, r_in
, g_in
, l_in
;
331 const unsigned short *texel_in
;
333 for (z
= 0; z
< depth
; z
++)
335 for (y
= 0; y
< height
; y
++)
337 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
338 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
339 for (x
= 0; x
< width
; x
++ )
341 l_in
= (*texel_in
& 0xfc00u
) >> 10;
342 g_in
= (*texel_in
& 0x03e0u
) >> 5;
343 r_in
= *texel_in
& 0x001fu
;
346 if (!(r_in
& 0x10)) /* r > 0 */
350 if (!(g_in
& 0x10)) /* g > 0 */
353 texel_out
[0] = r_out
;
354 texel_out
[1] = g_out
;
355 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
365 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
366 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
368 unsigned int x
, y
, z
;
369 unsigned char *texel_out
, ds_out
, dt_out
, r_in
, g_in
, l_in
;
370 const unsigned short *texel_in
;
372 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
373 * fixed function and shaders without further conversion once the surface is
376 * The difference between this function and convert_r5g5_snorm_l6_unorm_ext
377 * is that convert_r5g5_snorm_l6_unorm_ext creates a 32 bit XRGB texture and
378 * this function creates a 24 bit DSDT_MAG texture. Trying to load a DSDT_MAG
379 * internal with a 32 bit DSDT_MAG_INTENSITY or DSDT_MAG_VIB format fails. */
380 for (z
= 0; z
< depth
; z
++)
382 for (y
= 0; y
< height
; y
++)
384 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
385 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
386 for (x
= 0; x
< width
; x
++ )
388 l_in
= (*texel_in
& 0xfc00u
) >> 10;
389 g_in
= (*texel_in
& 0x03e0u
) >> 5;
390 r_in
= *texel_in
& 0x001fu
;
393 if (!(r_in
& 0x10)) /* r > 0 */
397 if (!(g_in
& 0x10)) /* g > 0 */
400 texel_out
[0] = ds_out
;
401 texel_out
[1] = dt_out
;
402 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
411 static void convert_r8g8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
412 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
414 unsigned int x
, y
, z
;
418 for (z
= 0; z
< depth
; z
++)
420 for (y
= 0; y
< height
; y
++)
422 Source
= (const short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
423 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
424 for (x
= 0; x
< width
; x
++ )
426 const short color
= (*Source
++);
427 /* B */ Dest
[0] = 0xff;
428 /* G */ Dest
[1] = (color
>> 8) + 128; /* V */
429 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
436 static void convert_r8g8_snorm_l8x8_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
437 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
439 unsigned int x
, y
, z
;
443 /* Doesn't work correctly with the fixed function pipeline, but can work in
444 * shaders if the shader is adjusted. (There's no use for this format in gl's
445 * standard fixed function pipeline anyway).
447 for (z
= 0; z
< depth
; z
++)
449 for (y
= 0; y
< height
; y
++)
451 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
452 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
453 for (x
= 0; x
< width
; x
++ )
455 LONG color
= (*Source
++);
456 /* B */ Dest
[0] = ((color
>> 16) & 0xff); /* L */
457 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
458 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
465 static void convert_r8g8_snorm_l8x8_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
;
472 /* This implementation works with the fixed function pipeline and shaders
473 * without further modification after converting the surface.
475 for (z
= 0; z
< depth
; z
++)
477 for (y
= 0; y
< height
; y
++)
479 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
480 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
481 for (x
= 0; x
< width
; x
++ )
483 LONG color
= (*Source
++);
484 /* L */ Dest
[2] = ((color
>> 16) & 0xff); /* L */
485 /* V */ Dest
[1] = ((color
>> 8 ) & 0xff); /* V */
486 /* U */ Dest
[0] = (color
& 0xff); /* U */
487 /* I */ Dest
[3] = 255; /* X */
494 static void convert_r8g8b8a8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
495 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
497 unsigned int x
, y
, z
;
501 for (z
= 0; z
< depth
; z
++)
503 for (y
= 0; y
< height
; y
++)
505 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
506 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
507 for (x
= 0; x
< width
; x
++ )
509 LONG color
= (*Source
++);
510 /* B */ Dest
[0] = ((color
>> 16) & 0xff) + 128; /* W */
511 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
512 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
513 /* A */ Dest
[3] = ((color
>> 24) & 0xff) + 128; /* Q */
520 static void convert_r16g16_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
521 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
523 unsigned int x
, y
, z
;
525 unsigned short *Dest
;
527 for (z
= 0; z
< depth
; z
++)
529 for (y
= 0; y
< height
; y
++)
531 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
532 Dest
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
533 for (x
= 0; x
< width
; x
++ )
535 const DWORD color
= (*Source
++);
536 /* B */ Dest
[0] = 0xffff;
537 /* G */ Dest
[1] = (color
>> 16) + 32768; /* V */
538 /* R */ Dest
[2] = (color
& 0xffff) + 32768; /* U */
545 static void convert_r16g16(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
546 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
548 unsigned int x
, y
, z
;
552 for (z
= 0; z
< depth
; z
++)
554 for (y
= 0; y
< height
; y
++)
556 Source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
557 Dest
= (WORD
*) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
558 for (x
= 0; x
< width
; x
++ )
560 WORD green
= (*Source
++);
561 WORD red
= (*Source
++);
564 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
565 * shader overwrites it anyway */
573 static void convert_r32g32_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
574 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
576 unsigned int x
, y
, z
;
580 for (z
= 0; z
< depth
; z
++)
582 for (y
= 0; y
< height
; y
++)
584 Source
= (const float *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
585 Dest
= (float *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
586 for (x
= 0; x
< width
; x
++ )
588 float green
= (*Source
++);
589 float red
= (*Source
++);
599 static void convert_s1_uint_d15_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
600 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
602 unsigned int x
, y
, z
;
604 for (z
= 0; z
< depth
; z
++)
606 for (y
= 0; y
< height
; ++y
)
608 const WORD
*source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
609 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
611 for (x
= 0; x
< width
; ++x
)
613 /* The depth data is normalized, so needs to be scaled,
614 * the stencil data isn't. Scale depth data by
615 * (2^24-1)/(2^15-1) ~~ (2^9 + 2^-6). */
616 WORD d15
= source
[x
] >> 1;
617 DWORD d24
= (d15
<< 9) + (d15
>> 6);
618 dest
[x
] = (d24
<< 8) | (source
[x
] & 0x1);
624 static void convert_s4x4_uint_d24_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
625 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
627 unsigned int x
, y
, z
;
629 for (z
= 0; z
< depth
; z
++)
631 for (y
= 0; y
< height
; ++y
)
633 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
634 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
636 for (x
= 0; x
< width
; ++x
)
638 /* Just need to clear out the X4 part. */
639 dest
[x
] = source
[x
] & ~0xf0;
645 static void convert_s8_uint_d24_float(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
;
650 for (z
= 0; z
< depth
; z
++)
652 for (y
= 0; y
< height
; ++y
)
654 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
655 float *dest_f
= (float *)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
656 DWORD
*dest_s
= (DWORD
*)dest_f
;
658 for (x
= 0; x
< width
; ++x
)
660 dest_f
[x
* 2] = float_24_to_32((source
[x
] & 0xffffff00u
) >> 8);
661 dest_s
[x
* 2 + 1] = source
[x
] & 0xff;
667 static BOOL
color_in_range(const struct wined3d_color_key
*color_key
, DWORD color
)
669 /* FIXME: Is this really how color keys are supposed to work? I think it
670 * makes more sense to compare the individual channels. */
671 return color
>= color_key
->color_space_low_value
672 && color
<= color_key
->color_space_high_value
;
675 static void convert_p8_uint_b8g8r8a8_unorm(const BYTE
*src
, unsigned int src_pitch
,
676 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
677 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
685 /* FIXME: This should probably use the system palette. */
686 FIXME("P8 surface loaded without a palette.\n");
688 for (y
= 0; y
< height
; ++y
)
690 memset(&dst
[dst_pitch
* y
], 0, width
* 4);
696 for (y
= 0; y
< height
; ++y
)
698 src_row
= &src
[src_pitch
* y
];
699 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
700 for (x
= 0; x
< width
; ++x
)
702 BYTE src_color
= src_row
[x
];
703 dst_row
[x
] = 0xff000000
704 | (palette
->colors
[src_color
].rgbRed
<< 16)
705 | (palette
->colors
[src_color
].rgbGreen
<< 8)
706 | palette
->colors
[src_color
].rgbBlue
;
711 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
712 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
713 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
719 for (y
= 0; y
< height
; ++y
)
721 src_row
= (WORD
*)&src
[src_pitch
* y
];
722 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
723 for (x
= 0; x
< width
; ++x
)
725 WORD src_color
= src_row
[x
];
726 if (!color_in_range(color_key
, src_color
))
727 dst_row
[x
] = 0x8000u
| ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
729 dst_row
[x
] = ((src_color
& 0xffc0u
) >> 1) | (src_color
& 0x1fu
);
734 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
735 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
736 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
742 for (y
= 0; y
< height
; ++y
)
744 src_row
= (WORD
*)&src
[src_pitch
* y
];
745 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
746 for (x
= 0; x
< width
; ++x
)
748 WORD src_color
= src_row
[x
];
749 if (color_in_range(color_key
, src_color
))
750 dst_row
[x
] = src_color
& ~0x8000;
752 dst_row
[x
] = src_color
| 0x8000;
757 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
758 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
759 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
765 for (y
= 0; y
< height
; ++y
)
767 src_row
= &src
[src_pitch
* y
];
768 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
769 for (x
= 0; x
< width
; ++x
)
771 DWORD src_color
= (src_row
[x
* 3 + 2] << 16) | (src_row
[x
* 3 + 1] << 8) | src_row
[x
* 3];
772 if (!color_in_range(color_key
, src_color
))
773 dst_row
[x
] = src_color
| 0xff000000;
778 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
779 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
780 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
782 const DWORD
*src_row
;
786 for (y
= 0; y
< height
; ++y
)
788 src_row
= (DWORD
*)&src
[src_pitch
* y
];
789 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
790 for (x
= 0; x
< width
; ++x
)
792 DWORD src_color
= src_row
[x
];
793 if (color_in_range(color_key
, src_color
))
794 dst_row
[x
] = src_color
& ~0xff000000;
796 dst_row
[x
] = src_color
| 0xff000000;
801 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
802 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
803 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
805 const DWORD
*src_row
;
809 for (y
= 0; y
< height
; ++y
)
811 src_row
= (DWORD
*)&src
[src_pitch
* y
];
812 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
813 for (x
= 0; x
< width
; ++x
)
815 DWORD src_color
= src_row
[x
];
816 if (color_in_range(color_key
, src_color
))
817 src_color
&= ~0xff000000;
818 dst_row
[x
] = src_color
;
823 const struct wined3d_color_key_conversion
* wined3d_format_get_color_key_conversion(
824 const struct wined3d_texture
*texture
, BOOL need_alpha_ck
)
826 const struct wined3d_format
*format
= texture
->resource
.format
;
831 enum wined3d_format_id src_format
;
832 struct wined3d_color_key_conversion conversion
;
836 {WINED3DFMT_B5G6R5_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key
}},
837 {WINED3DFMT_B5G5R5X1_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key
}},
838 {WINED3DFMT_B8G8R8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key
}},
839 {WINED3DFMT_B8G8R8X8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key
}},
840 {WINED3DFMT_B8G8R8A8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key
}},
842 static const struct wined3d_color_key_conversion convert_p8
=
844 WINED3DFMT_B8G8R8A8_UNORM
, convert_p8_uint_b8g8r8a8_unorm
847 if (need_alpha_ck
&& (texture
->async
.flags
& WINED3D_TEXTURE_ASYNC_COLOR_KEY
))
849 for (i
= 0; i
< sizeof(color_key_info
) / sizeof(*color_key_info
); ++i
)
851 if (color_key_info
[i
].src_format
== format
->id
)
852 return &color_key_info
[i
].conversion
;
855 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format
->id
));
858 /* FIXME: This should check if the blitter backend can do P8 conversion,
859 * instead of checking for ARB_fragment_program. */
860 if (format
->id
== WINED3DFMT_P8_UINT
861 && !(texture
->resource
.device
->adapter
->gl_info
.supported
[ARB_FRAGMENT_PROGRAM
]
862 && texture
->swapchain
&& texture
== texture
->swapchain
->front_buffer
))
868 /* The following formats explicitly don't have WINED3DFMT_FLAG_TEXTURE set:
870 * These are never supported on native.
871 * WINED3DFMT_B8G8R8_UNORM
872 * WINED3DFMT_B2G3R3_UNORM
873 * WINED3DFMT_L4A4_UNORM
874 * WINED3DFMT_S1_UINT_D15_UNORM
875 * WINED3DFMT_S4X4_UINT_D24_UNORM
877 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
878 * Since it is not widely available, don't offer it. Further no Windows driver
879 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
881 * WINED3DFMT_P8_UINT_A8_UNORM
883 * These formats seem to be similar to the HILO formats in
884 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
885 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
886 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
887 * refused to support formats which can easily be emulated with pixel shaders,
888 * so applications have to deal with not having NVHS and NVHU.
891 static const struct wined3d_format_texture_info format_texture_info
[] =
893 /* format id gl_internal gl_srgb_internal gl_rt_internal
894 gl_format gl_type conv_byte_count
898 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
899 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
900 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
901 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
904 {WINED3DFMT_UYVY
, GL_LUMINANCE_ALPHA
, GL_LUMINANCE_ALPHA
, 0,
905 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
906 WINED3DFMT_FLAG_FILTERING
,
907 WINED3D_GL_EXT_NONE
, NULL
},
908 {WINED3DFMT_UYVY
, GL_RGB
, GL_RGB
, 0,
909 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
910 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
911 APPLE_YCBCR_422
, NULL
},
912 {WINED3DFMT_YUY2
, GL_LUMINANCE_ALPHA
, GL_LUMINANCE_ALPHA
, 0,
913 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
914 WINED3DFMT_FLAG_FILTERING
,
915 WINED3D_GL_EXT_NONE
, NULL
},
916 {WINED3DFMT_YUY2
, GL_RGB
, GL_RGB
, 0,
917 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
918 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
919 APPLE_YCBCR_422
, NULL
},
920 {WINED3DFMT_YV12
, GL_ALPHA
, GL_ALPHA
, 0,
921 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
922 WINED3DFMT_FLAG_FILTERING
,
923 WINED3D_GL_EXT_NONE
, NULL
},
924 {WINED3DFMT_NV12
, GL_ALPHA
, GL_ALPHA
, 0,
925 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
926 WINED3DFMT_FLAG_FILTERING
,
927 WINED3D_GL_EXT_NONE
, NULL
},
928 {WINED3DFMT_DXT1
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
929 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
930 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
931 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
932 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
933 {WINED3DFMT_DXT2
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
934 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
935 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
936 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
937 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
938 {WINED3DFMT_DXT3
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
939 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
940 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
941 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
942 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
943 {WINED3DFMT_DXT4
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
944 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
945 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
946 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
947 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
948 {WINED3DFMT_DXT5
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
949 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
950 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
951 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
952 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
954 {WINED3DFMT_R32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
956 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
957 ARB_TEXTURE_FLOAT
, NULL
},
958 {WINED3DFMT_R32_FLOAT
, GL_R32F
, GL_R32F
, 0,
960 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
961 ARB_TEXTURE_RG
, NULL
},
962 {WINED3DFMT_R32G32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
963 GL_RGB
, GL_FLOAT
, 12,
964 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
965 ARB_TEXTURE_FLOAT
, convert_r32g32_float
},
966 {WINED3DFMT_R32G32_FLOAT
, GL_RG32F
, GL_RG32F
, 0,
968 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
969 ARB_TEXTURE_RG
, NULL
},
970 {WINED3DFMT_R32G32B32A32_FLOAT
, GL_RGBA32F_ARB
, GL_RGBA32F_ARB
, 0,
971 GL_RGBA
, GL_FLOAT
, 0,
972 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
973 ARB_TEXTURE_FLOAT
, NULL
},
975 {WINED3DFMT_R16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
976 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
977 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
978 ARB_TEXTURE_FLOAT
, NULL
},
979 {WINED3DFMT_R16_FLOAT
, GL_R16F
, GL_R16F
, 0,
980 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
981 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
982 ARB_TEXTURE_RG
, NULL
},
983 {WINED3DFMT_R16G16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
984 GL_RGB
, GL_HALF_FLOAT_ARB
, 6,
985 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
986 ARB_TEXTURE_FLOAT
, convert_r16g16
},
987 {WINED3DFMT_R16G16_FLOAT
, GL_RG16F
, GL_RG16F
, 0,
988 GL_RG
, GL_HALF_FLOAT_ARB
, 0,
989 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
990 ARB_TEXTURE_RG
, NULL
},
991 {WINED3DFMT_R16G16B16A16_FLOAT
, GL_RGBA16F_ARB
, GL_RGBA16F_ARB
, 0,
992 GL_RGBA
, GL_HALF_FLOAT_ARB
, 0,
993 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
994 | WINED3DFMT_FLAG_VTF
,
995 ARB_TEXTURE_FLOAT
, NULL
},
996 /* Palettized formats */
997 {WINED3DFMT_P8_UINT
, GL_ALPHA8
, GL_ALPHA8
, 0,
998 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1001 /* Standard ARGB formats */
1002 {WINED3DFMT_B8G8R8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1003 GL_BGR
, GL_UNSIGNED_BYTE
, 0,
1004 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
| WINED3DFMT_FLAG_RENDERTARGET
,
1005 WINED3D_GL_EXT_NONE
, NULL
},
1006 {WINED3DFMT_B8G8R8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1007 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1008 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1009 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1010 | WINED3DFMT_FLAG_VTF
,
1011 WINED3D_GL_EXT_NONE
, NULL
},
1012 {WINED3DFMT_B8G8R8X8_UNORM
, GL_RGB8
, GL_SRGB8_EXT
, 0,
1013 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1014 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1015 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
,
1016 WINED3D_GL_EXT_NONE
, NULL
},
1017 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB5
, GL_RGB5
, GL_RGB8
,
1018 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1019 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1020 | WINED3DFMT_FLAG_RENDERTARGET
,
1021 WINED3D_GL_EXT_NONE
, NULL
},
1022 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB565
, GL_RGB565
, GL_RGB8
,
1023 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1024 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1025 | WINED3DFMT_FLAG_RENDERTARGET
,
1026 ARB_ES2_COMPATIBILITY
, NULL
},
1027 {WINED3DFMT_B5G5R5X1_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1028 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1029 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1030 WINED3D_GL_EXT_NONE
, NULL
},
1031 {WINED3DFMT_B5G5R5A1_UNORM
, GL_RGB5_A1
, GL_RGB5_A1
, 0,
1032 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1033 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1034 WINED3D_GL_EXT_NONE
, NULL
},
1035 {WINED3DFMT_B4G4R4A4_UNORM
, GL_RGBA4
, GL_SRGB8_ALPHA8_EXT
, 0,
1036 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1037 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1038 | WINED3DFMT_FLAG_SRGB_READ
,
1039 WINED3D_GL_EXT_NONE
, NULL
},
1040 {WINED3DFMT_B2G3R3_UNORM
, GL_R3_G3_B2
, GL_R3_G3_B2
, 0,
1041 GL_RGB
, GL_UNSIGNED_BYTE_3_3_2
, 0,
1042 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1043 WINED3D_GL_EXT_NONE
, NULL
},
1044 {WINED3DFMT_R8_UNORM
, GL_R8
, GL_R8
, 0,
1045 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1046 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1047 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1048 ARB_TEXTURE_RG
, NULL
},
1049 {WINED3DFMT_A8_UNORM
, GL_ALPHA8
, GL_ALPHA8
, 0,
1050 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1051 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1052 WINED3D_GL_EXT_NONE
, NULL
},
1053 {WINED3DFMT_B4G4R4X4_UNORM
, GL_RGB4
, GL_RGB4
, 0,
1054 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1055 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1056 WINED3D_GL_EXT_NONE
, NULL
},
1057 {WINED3DFMT_R10G10B10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1058 GL_RGBA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1059 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1060 | WINED3DFMT_FLAG_RENDERTARGET
,
1061 WINED3D_GL_EXT_NONE
, NULL
},
1062 {WINED3DFMT_R8G8B8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1063 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1064 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1065 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1066 | WINED3DFMT_FLAG_VTF
,
1067 WINED3D_GL_EXT_NONE
, NULL
},
1068 {WINED3DFMT_R8G8B8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1069 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1070 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1071 WINED3D_GL_EXT_NONE
, NULL
},
1072 {WINED3DFMT_R16G16_UNORM
, GL_RGB16
, GL_RGB16
, GL_RGBA16
,
1073 GL_RGB
, GL_UNSIGNED_SHORT
, 6,
1074 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1075 WINED3D_GL_EXT_NONE
, convert_r16g16
},
1076 {WINED3DFMT_R16G16_UNORM
, GL_RG16
, GL_RG16
, 0,
1077 GL_RG
, GL_UNSIGNED_SHORT
, 0,
1078 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1079 | WINED3DFMT_FLAG_RENDERTARGET
,
1080 ARB_TEXTURE_RG
, NULL
},
1081 {WINED3DFMT_B10G10R10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1082 GL_BGRA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1083 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1084 | WINED3DFMT_FLAG_RENDERTARGET
,
1085 WINED3D_GL_EXT_NONE
, NULL
},
1086 {WINED3DFMT_R16G16B16A16_UNORM
, GL_RGBA16
, GL_RGBA16
, 0,
1087 GL_RGBA
, GL_UNSIGNED_SHORT
, 0,
1088 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1089 | WINED3DFMT_FLAG_RENDERTARGET
,
1090 WINED3D_GL_EXT_NONE
, NULL
},
1092 {WINED3DFMT_L8_UNORM
, GL_LUMINANCE8
, GL_SLUMINANCE8_EXT
, 0,
1093 GL_LUMINANCE
, GL_UNSIGNED_BYTE
, 0,
1094 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1095 | WINED3DFMT_FLAG_SRGB_READ
,
1096 WINED3D_GL_EXT_NONE
, NULL
},
1097 {WINED3DFMT_L8A8_UNORM
, GL_LUMINANCE8_ALPHA8
, GL_SLUMINANCE8_ALPHA8_EXT
, 0,
1098 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1099 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1100 | WINED3DFMT_FLAG_SRGB_READ
,
1101 WINED3D_GL_EXT_NONE
, NULL
},
1102 {WINED3DFMT_L4A4_UNORM
, GL_LUMINANCE4_ALPHA4
, GL_LUMINANCE4_ALPHA4
, 0,
1103 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 2,
1104 WINED3DFMT_FLAG_FILTERING
,
1105 WINED3D_GL_EXT_NONE
, convert_l4a4_unorm
},
1106 /* Bump mapping stuff */
1107 {WINED3DFMT_R8G8_SNORM
, GL_RGB8
, GL_RGB8
, 0,
1108 GL_BGR
, GL_UNSIGNED_BYTE
, 3,
1109 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1110 | WINED3DFMT_FLAG_BUMPMAP
,
1111 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm
},
1112 {WINED3DFMT_R8G8_SNORM
, GL_DSDT8_NV
, GL_DSDT8_NV
, 0,
1113 GL_DSDT_NV
, GL_BYTE
, 0,
1114 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1115 | WINED3DFMT_FLAG_BUMPMAP
,
1116 NV_TEXTURE_SHADER
, NULL
},
1117 {WINED3DFMT_R8G8_SNORM
, GL_RG8_SNORM
, GL_RG8_SNORM
, 0,
1119 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1120 | WINED3DFMT_FLAG_BUMPMAP
,
1121 EXT_TEXTURE_SNORM
, NULL
},
1122 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1123 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 2,
1124 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1125 | WINED3DFMT_FLAG_BUMPMAP
,
1126 WINED3D_GL_EXT_NONE
, convert_r5g5_snorm_l6_unorm
},
1127 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_DSDT8_MAG8_NV
, GL_DSDT8_MAG8_NV
, 0,
1128 GL_DSDT_MAG_NV
, GL_BYTE
, 3,
1129 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1130 | WINED3DFMT_FLAG_BUMPMAP
,
1131 NV_TEXTURE_SHADER
, convert_r5g5_snorm_l6_unorm_nv
},
1132 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB8_SNORM
, GL_RGB8_SNORM
, 0,
1133 GL_RGBA
, GL_BYTE
, 4,
1134 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1135 | WINED3DFMT_FLAG_BUMPMAP
,
1136 EXT_TEXTURE_SNORM
, convert_r5g5_snorm_l6_unorm_ext
},
1137 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1138 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4,
1139 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1140 | WINED3DFMT_FLAG_BUMPMAP
,
1141 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm_l8x8_unorm
},
1142 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_DSDT8_MAG8_INTENSITY8_NV
, GL_DSDT8_MAG8_INTENSITY8_NV
, 0,
1143 GL_DSDT_MAG_VIB_NV
, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV
, 4,
1144 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1145 | WINED3DFMT_FLAG_BUMPMAP
,
1146 NV_TEXTURE_SHADER
, convert_r8g8_snorm_l8x8_unorm_nv
},
1147 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8
, GL_RGBA8
, 0,
1148 GL_BGRA
, GL_UNSIGNED_BYTE
, 4,
1149 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1150 | WINED3DFMT_FLAG_BUMPMAP
,
1151 WINED3D_GL_EXT_NONE
, convert_r8g8b8a8_snorm
},
1152 {WINED3DFMT_R8G8B8A8_SNORM
, GL_SIGNED_RGBA8_NV
, GL_SIGNED_RGBA8_NV
, 0,
1153 GL_RGBA
, GL_BYTE
, 0,
1154 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1155 | WINED3DFMT_FLAG_BUMPMAP
,
1156 NV_TEXTURE_SHADER
, NULL
},
1157 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8_SNORM
, GL_RGBA8_SNORM
, 0,
1158 GL_RGBA
, GL_BYTE
, 0,
1159 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1160 | WINED3DFMT_FLAG_BUMPMAP
,
1161 EXT_TEXTURE_SNORM
, NULL
},
1162 {WINED3DFMT_R16G16_SNORM
, GL_RGB16
, GL_RGB16
, 0,
1163 GL_BGR
, GL_UNSIGNED_SHORT
, 6,
1164 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1165 | WINED3DFMT_FLAG_BUMPMAP
,
1166 WINED3D_GL_EXT_NONE
, convert_r16g16_snorm
},
1167 {WINED3DFMT_R16G16_SNORM
, GL_SIGNED_HILO16_NV
, GL_SIGNED_HILO16_NV
, 0,
1168 GL_HILO_NV
, GL_SHORT
, 0,
1169 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1170 | WINED3DFMT_FLAG_BUMPMAP
,
1171 NV_TEXTURE_SHADER
, NULL
},
1172 {WINED3DFMT_R16G16_SNORM
, GL_RG16_SNORM
, GL_RG16_SNORM
, 0,
1174 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1175 | WINED3DFMT_FLAG_BUMPMAP
,
1176 EXT_TEXTURE_SNORM
, NULL
},
1177 /* Depth stencil formats */
1178 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1179 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1180 WINED3DFMT_FLAG_DEPTH
,
1181 WINED3D_GL_EXT_NONE
, NULL
},
1182 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1183 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1184 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1185 ARB_DEPTH_TEXTURE
, NULL
},
1186 {WINED3DFMT_D32_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1187 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1188 WINED3DFMT_FLAG_DEPTH
,
1189 WINED3D_GL_EXT_NONE
, NULL
},
1190 {WINED3DFMT_D32_UNORM
, GL_DEPTH_COMPONENT32_ARB
, GL_DEPTH_COMPONENT32_ARB
, 0,
1191 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1192 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1193 ARB_DEPTH_TEXTURE
, NULL
},
1194 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1195 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1196 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1197 ARB_DEPTH_TEXTURE
, NULL
},
1198 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1199 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 4,
1200 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1201 EXT_PACKED_DEPTH_STENCIL
, convert_s1_uint_d15_unorm
},
1202 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1203 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 4,
1204 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1205 ARB_FRAMEBUFFER_OBJECT
, convert_s1_uint_d15_unorm
},
1206 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1207 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1208 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1209 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1210 ARB_DEPTH_TEXTURE
, NULL
},
1211 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1212 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 0,
1213 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1214 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1215 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1216 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1217 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1218 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1219 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1220 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1221 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1222 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1223 WINED3DFMT_FLAG_DEPTH
,
1224 WINED3D_GL_EXT_NONE
, NULL
},
1225 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1226 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1227 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1228 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1229 ARB_DEPTH_TEXTURE
, NULL
},
1230 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1231 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1232 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1233 ARB_DEPTH_TEXTURE
, NULL
},
1234 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1235 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 4,
1236 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1237 EXT_PACKED_DEPTH_STENCIL
, convert_s4x4_uint_d24_unorm
},
1238 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1239 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 4,
1240 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1241 ARB_FRAMEBUFFER_OBJECT
, convert_s4x4_uint_d24_unorm
},
1242 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1243 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1244 WINED3DFMT_FLAG_DEPTH
,
1245 WINED3D_GL_EXT_NONE
, NULL
},
1246 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1247 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1248 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1249 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1250 ARB_DEPTH_TEXTURE
, NULL
},
1251 {WINED3DFMT_L16_UNORM
, GL_LUMINANCE16
, GL_LUMINANCE16
, 0,
1252 GL_LUMINANCE
, GL_UNSIGNED_SHORT
, 0,
1253 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1254 WINED3D_GL_EXT_NONE
, NULL
},
1255 {WINED3DFMT_D32_FLOAT
, GL_DEPTH_COMPONENT32F
, GL_DEPTH_COMPONENT32F
, 0,
1256 GL_DEPTH_COMPONENT
, GL_FLOAT
, 0,
1257 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1258 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1259 {WINED3DFMT_S8_UINT_D24_FLOAT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1260 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 8,
1261 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1262 ARB_DEPTH_BUFFER_FLOAT
, convert_s8_uint_d24_float
},
1263 /* Vendor-specific formats */
1264 {WINED3DFMT_ATI1N
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1265 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1266 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1267 | WINED3DFMT_FLAG_COMPRESSED
,
1268 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1269 {WINED3DFMT_ATI2N
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, 0,
1270 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1271 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1272 | WINED3DFMT_FLAG_COMPRESSED
,
1273 ATI_TEXTURE_COMPRESSION_3DC
, NULL
},
1274 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1275 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1276 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1277 | WINED3DFMT_FLAG_COMPRESSED
,
1278 EXT_TEXTURE_COMPRESSION_RGTC
, NULL
},
1279 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1280 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1281 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1282 | WINED3DFMT_FLAG_COMPRESSED
,
1283 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1284 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1285 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 0,
1286 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1287 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
,
1288 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1289 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1290 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1291 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1292 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
,
1293 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1294 {WINED3DFMT_NULL
, 0, 0, 0,
1295 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1296 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
,
1297 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1300 static inline int getFmtIdx(enum wined3d_format_id format_id
)
1302 /* First check if the format is at the position of its value.
1303 * This will catch the argb formats before the loop is entered. */
1304 if (format_id
< (sizeof(formats
) / sizeof(*formats
))
1305 && formats
[format_id
].id
== format_id
)
1313 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
1315 if (formats
[i
].id
== format_id
) return i
;
1321 static void format_set_flag(struct wined3d_format
*format
, unsigned int flag
)
1325 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1326 format
->flags
[i
] |= flag
;
1329 static void format_clear_flag(struct wined3d_format
*format
, unsigned int flag
)
1333 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1334 format
->flags
[i
] &= ~flag
;
1337 static BOOL
init_format_base_info(struct wined3d_gl_info
*gl_info
)
1339 UINT format_count
= sizeof(formats
) / sizeof(*formats
);
1342 gl_info
->formats
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, format_count
* sizeof(*gl_info
->formats
));
1343 if (!gl_info
->formats
)
1345 ERR("Failed to allocate memory.\n");
1349 for (i
= 0; i
< format_count
; ++i
)
1351 struct wined3d_format
*format
= &gl_info
->formats
[i
];
1352 format
->id
= formats
[i
].id
;
1353 format
->red_size
= formats
[i
].red_size
;
1354 format
->green_size
= formats
[i
].green_size
;
1355 format
->blue_size
= formats
[i
].blue_size
;
1356 format
->alpha_size
= formats
[i
].alpha_size
;
1357 format
->red_offset
= formats
[i
].red_offset
;
1358 format
->green_offset
= formats
[i
].green_offset
;
1359 format
->blue_offset
= formats
[i
].blue_offset
;
1360 format
->alpha_offset
= formats
[i
].alpha_offset
;
1361 format
->byte_count
= formats
[i
].bpp
;
1362 format
->depth_size
= formats
[i
].depth_size
;
1363 format
->stencil_size
= formats
[i
].stencil_size
;
1364 format
->block_width
= 1;
1365 format
->block_height
= 1;
1366 format
->block_byte_count
= formats
[i
].bpp
;
1369 for (i
= 0; i
< (sizeof(format_base_flags
) / sizeof(*format_base_flags
)); ++i
)
1371 int fmt_idx
= getFmtIdx(format_base_flags
[i
].id
);
1375 ERR("Format %s (%#x) not found.\n",
1376 debug_d3dformat(format_base_flags
[i
].id
), format_base_flags
[i
].id
);
1377 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
1381 format_set_flag(&gl_info
->formats
[fmt_idx
], format_base_flags
[i
].flags
);
1387 static BOOL
init_format_block_info(struct wined3d_gl_info
*gl_info
)
1391 for (i
= 0; i
< (sizeof(format_block_info
) / sizeof(*format_block_info
)); ++i
)
1393 struct wined3d_format
*format
;
1394 int fmt_idx
= getFmtIdx(format_block_info
[i
].id
);
1398 ERR("Format %s (%#x) not found.\n",
1399 debug_d3dformat(format_block_info
[i
].id
), format_block_info
[i
].id
);
1403 format
= &gl_info
->formats
[fmt_idx
];
1404 format
->block_width
= format_block_info
[i
].block_width
;
1405 format
->block_height
= format_block_info
[i
].block_height
;
1406 format
->block_byte_count
= format_block_info
[i
].block_byte_count
;
1407 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_BLOCKS
);
1408 if (!format_block_info
[i
].verify
)
1409 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
);
1415 static GLenum
wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type
)
1419 case WINED3D_GL_RES_TYPE_TEX_1D
:
1420 return GL_TEXTURE_1D
;
1421 case WINED3D_GL_RES_TYPE_TEX_2D
:
1422 return GL_TEXTURE_2D
;
1423 case WINED3D_GL_RES_TYPE_TEX_3D
:
1424 return GL_TEXTURE_3D
;
1425 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1426 return GL_TEXTURE_CUBE_MAP_ARB
;
1427 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1428 return GL_TEXTURE_RECTANGLE_ARB
;
1429 case WINED3D_GL_RES_TYPE_BUFFER
:
1430 return GL_TEXTURE_2D
; /* TODO: GL_TEXTURE_BUFFER. */
1431 case WINED3D_GL_RES_TYPE_RB
:
1432 return GL_RENDERBUFFER
;
1433 case WINED3D_GL_RES_TYPE_COUNT
:
1436 ERR("Unexpected GL resource type %u.\n", type
);
1440 static void delete_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
1441 enum wined3d_gl_resource_type d3d_type
, GLuint object
)
1445 case WINED3D_GL_RES_TYPE_TEX_1D
:
1446 case WINED3D_GL_RES_TYPE_TEX_2D
:
1447 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1448 case WINED3D_GL_RES_TYPE_TEX_3D
:
1449 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1450 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &object
);
1453 case WINED3D_GL_RES_TYPE_RB
:
1454 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &object
);
1457 case WINED3D_GL_RES_TYPE_BUFFER
:
1458 case WINED3D_GL_RES_TYPE_COUNT
:
1463 /* Context activation is done by the caller. */
1464 static void create_and_bind_fbo_attachment(const struct wined3d_gl_info
*gl_info
, unsigned int flags
,
1465 enum wined3d_gl_resource_type d3d_type
, GLuint
*object
, GLenum internal
, GLenum format
, GLenum type
)
1467 GLenum attach_type
= flags
& WINED3DFMT_FLAG_DEPTH
?
1468 GL_DEPTH_ATTACHMENT
: GL_COLOR_ATTACHMENT0
;
1472 case WINED3D_GL_RES_TYPE_TEX_1D
:
1473 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1474 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, *object
);
1475 gl_info
->gl_ops
.gl
.p_glTexImage1D(GL_TEXTURE_1D
, 0, internal
, 16, 0, format
, type
, NULL
);
1476 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1477 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1479 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_1D
,
1481 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1482 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_TEXTURE_1D
,
1486 case WINED3D_GL_RES_TYPE_TEX_2D
:
1487 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1488 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1489 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(d3d_type
), *object
);
1490 gl_info
->gl_ops
.gl
.p_glTexImage2D(wined3d_gl_type_to_enum(d3d_type
), 0, internal
, 16, 16, 0,
1491 format
, type
, NULL
);
1492 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1493 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1495 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
1496 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
1497 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1498 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1499 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
1502 case WINED3D_GL_RES_TYPE_TEX_3D
:
1503 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1504 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_3D
, *object
);
1505 GL_EXTCALL(glTexImage3D
)(GL_TEXTURE_3D
, 0, internal
, 16, 16, 16, 0,
1506 format
, type
, NULL
);
1507 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1508 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1510 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, attach_type
,
1511 GL_TEXTURE_3D
, *object
, 0, 0);
1512 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1513 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1514 GL_TEXTURE_3D
, *object
, 0, 0);
1517 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1518 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1519 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, *object
);
1520 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, internal
, 16, 16, 0,
1521 format
, type
, NULL
);
1522 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
, 0, internal
, 16, 16, 0,
1523 format
, type
, NULL
);
1524 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
, 0, internal
, 16, 16, 0,
1525 format
, type
, NULL
);
1526 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
, 0, internal
, 16, 16, 0,
1527 format
, type
, NULL
);
1528 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
, 0, internal
, 16, 16, 0,
1529 format
, type
, NULL
);
1530 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
, 0, internal
, 16, 16, 0,
1531 format
, type
, NULL
);
1532 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1533 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1535 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
1536 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
1537 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1538 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1539 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
1542 case WINED3D_GL_RES_TYPE_RB
:
1543 gl_info
->fbo_ops
.glGenRenderbuffers(1, object
);
1544 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, *object
);
1545 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, internal
, 16, 16);
1546 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, attach_type
, GL_RENDERBUFFER
,
1548 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1549 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
,
1553 case WINED3D_GL_RES_TYPE_BUFFER
:
1554 case WINED3D_GL_RES_TYPE_COUNT
:
1558 /* Ideally we'd skip all formats already known not to work on textures
1559 * by checking for WINED3DFMT_FLAG_TEXTURE here. However, we want to
1560 * know if we can attach WINED3DFMT_P8_UINT textures to FBOs, and this
1561 * format never has WINED3DFMT_FLAG_TEXTURE set. Instead, swallow GL
1562 * errors generated by invalid formats. */
1563 while (gl_info
->gl_ops
.gl
.p_glGetError());
1566 static void draw_test_quad(struct wined3d_caps_gl_ctx
*ctx
, const struct wined3d_vec3
*geometry
,
1567 const struct wined3d_color
*color
)
1569 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
1570 static const struct wined3d_vec3 default_geometry
[] =
1572 {-1.0f
, -1.0f
, 0.0f
},
1573 { 1.0f
, -1.0f
, 0.0f
},
1574 {-1.0f
, 1.0f
, 0.0f
},
1575 { 1.0f
, 1.0f
, 0.0f
},
1577 static const char vs_core_header
[] =
1581 "out vec4 out_color;\n"
1583 static const char vs_legacy_header
[] =
1585 "attribute vec4 pos;\n"
1586 "attribute vec4 color;\n"
1587 "varying vec4 out_color;\n"
1589 static const char vs_body
[] =
1592 " gl_Position = pos;\n"
1593 " out_color = color;\n"
1595 static const char fs_core
[] =
1597 "in vec4 out_color;\n"
1598 "out vec4 fragment_color;\n"
1602 " fragment_color = out_color;\n"
1604 static const char fs_legacy
[] =
1606 "varying vec4 out_color;\n"
1610 " gl_FragData[0] = out_color;\n"
1612 const char *source
[2];
1613 GLuint vs_id
, fs_id
;
1617 geometry
= default_geometry
;
1619 if (!gl_info
->supported
[ARB_VERTEX_BUFFER_OBJECT
] || !gl_info
->supported
[ARB_VERTEX_SHADER
]
1620 || !gl_info
->supported
[ARB_FRAGMENT_SHADER
])
1622 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
1623 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
1624 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
1625 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
1626 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
1628 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
1629 gl_info
->gl_ops
.gl
.p_glColor4f(color
->r
, color
->g
, color
->b
, color
->a
);
1630 for (i
= 0; i
< 4; ++i
)
1631 gl_info
->gl_ops
.gl
.p_glVertex3fv(&geometry
[i
].x
);
1632 gl_info
->gl_ops
.gl
.p_glEnd();
1633 checkGLcall("Drawing a quad");
1638 GL_EXTCALL(glGenBuffers(1, &ctx
->test_vbo
));
1639 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, ctx
->test_vbo
));
1640 GL_EXTCALL(glBufferData(GL_ARRAY_BUFFER
, sizeof(struct wined3d_vec3
) * 4, geometry
, GL_STREAM_DRAW
));
1641 GL_EXTCALL(glVertexAttribPointer(0, 3, GL_FLOAT
, FALSE
, 0, NULL
));
1642 GL_EXTCALL(glVertexAttrib4f(1, color
->r
, color
->g
, color
->b
, color
->a
));
1643 GL_EXTCALL(glEnableVertexAttribArray(0));
1644 GL_EXTCALL(glDisableVertexAttribArray(1));
1646 if (!ctx
->test_program_id
)
1648 ctx
->test_program_id
= GL_EXTCALL(glCreateProgram());
1650 vs_id
= GL_EXTCALL(glCreateShader(GL_VERTEX_SHADER
));
1651 source
[0] = gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? vs_legacy_header
: vs_core_header
;
1652 source
[1] = vs_body
;
1653 GL_EXTCALL(glShaderSource(vs_id
, 2, source
, NULL
));
1654 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, vs_id
));
1655 GL_EXTCALL(glDeleteShader(vs_id
));
1657 fs_id
= GL_EXTCALL(glCreateShader(GL_FRAGMENT_SHADER
));
1658 source
[0] = gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? fs_legacy
: fs_core
;
1659 GL_EXTCALL(glShaderSource(fs_id
, 1, source
, NULL
));
1660 GL_EXTCALL(glAttachShader(ctx
->test_program_id
, fs_id
));
1661 GL_EXTCALL(glDeleteShader(fs_id
));
1663 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 0, "pos"));
1664 GL_EXTCALL(glBindAttribLocation(ctx
->test_program_id
, 1, "color"));
1666 GL_EXTCALL(glCompileShader(vs_id
));
1667 print_glsl_info_log(gl_info
, vs_id
, FALSE
);
1668 GL_EXTCALL(glCompileShader(fs_id
));
1669 print_glsl_info_log(gl_info
, fs_id
, FALSE
);
1670 GL_EXTCALL(glLinkProgram(ctx
->test_program_id
));
1671 shader_glsl_validate_link(gl_info
, ctx
->test_program_id
);
1673 GL_EXTCALL(glUseProgram(ctx
->test_program_id
));
1675 gl_info
->gl_ops
.gl
.p_glDrawArrays(GL_TRIANGLE_STRIP
, 0, 4);
1677 GL_EXTCALL(glUseProgram(0));
1678 GL_EXTCALL(glDisableVertexAttribArray(0));
1679 GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER
, 0));
1680 checkGLcall("Drawing a quad");
1683 /* Context activation is done by the caller. */
1684 static void check_fbo_compat(struct wined3d_caps_gl_ctx
*ctx
, struct wined3d_format
*format
)
1686 /* Check if the default internal format is supported as a frame buffer
1687 * target, otherwise fall back to the render target internal.
1689 * Try to stick to the standard format if possible, this limits precision differences. */
1690 static const struct wined3d_color black
= {0.0f
, 0.0f
, 0.0f
, 1.0f
};
1691 static const struct wined3d_color half_transparent_red
= {1.0f
, 0.0f
, 0.0f
, 0.5f
};
1692 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
1693 GLenum status
, rt_internal
= format
->rtInternal
;
1694 GLuint object
, color_rb
;
1695 enum wined3d_gl_resource_type type
;
1696 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
1698 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
1700 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
1702 const char *type_string
= "color";
1704 if (type
== WINED3D_GL_RES_TYPE_BUFFER
)
1707 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->glInternal
,
1708 format
->glFormat
, format
->glType
);
1710 if (format
->flags
[type
] & (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
1712 gl_info
->fbo_ops
.glGenRenderbuffers(1, &color_rb
);
1713 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, color_rb
);
1714 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
1715 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 1);
1717 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 16);
1719 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
1720 GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, color_rb
);
1721 checkGLcall("Create and attach color rb attachment");
1722 type_string
= "depth / stencil";
1725 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
1726 checkGLcall("Framebuffer format check");
1728 if (status
== GL_FRAMEBUFFER_COMPLETE
)
1730 TRACE("Format %s is supported as FBO %s attachment, type %u.\n",
1731 debug_d3dformat(format
->id
), type_string
, type
);
1732 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
1733 format
->rtInternal
= format
->glInternal
;
1734 regular_fmt_used
= TRUE
;
1740 if (format
->flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
1742 WARN("Format %s with rendertarget flag is not supported as FBO color attachment (type %u),"
1743 " and no fallback specified.\n", debug_d3dformat(format
->id
), type
);
1744 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
1748 TRACE("Format %s is not supported as FBO %s attachment, type %u.\n",
1749 debug_d3dformat(format
->id
), type_string
, type
);
1751 format
->rtInternal
= format
->glInternal
;
1755 TRACE("Format %s is not supported as FBO %s attachment (type %u),"
1756 " trying rtInternal format as fallback.\n",
1757 debug_d3dformat(format
->id
), type_string
, type
);
1759 while (gl_info
->gl_ops
.gl
.p_glGetError());
1761 delete_fbo_attachment(gl_info
, type
, object
);
1762 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->rtInternal
,
1763 format
->glFormat
, format
->glType
);
1765 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
1766 checkGLcall("Framebuffer format check");
1768 if (status
== GL_FRAMEBUFFER_COMPLETE
)
1770 TRACE("Format %s rtInternal format is supported as FBO %s attachment, type %u.\n",
1771 debug_d3dformat(format
->id
), type_string
, type
);
1772 fallback_fmt_used
= TRUE
;
1776 WARN("Format %s rtInternal format is not supported as FBO %s attachment, type %u.\n",
1777 debug_d3dformat(format
->id
), type_string
, type
);
1778 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
1783 if (status
== GL_FRAMEBUFFER_COMPLETE
1784 && ((format
->flags
[type
] & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
)
1785 || !(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
1786 && format
->id
!= WINED3DFMT_NULL
&& format
->id
!= WINED3DFMT_P8_UINT
1787 && format
->glFormat
!= GL_LUMINANCE
&& format
->glFormat
!= GL_LUMINANCE_ALPHA
1788 && (format
->red_size
|| format
->alpha_size
))
1790 DWORD readback
[16 * 16 * 16], color
, r_range
, a_range
;
1795 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
]
1796 || gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
1798 gl_info
->fbo_ops
.glGenRenderbuffers(1, &rb
);
1799 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
1800 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
1801 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 1);
1803 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 16);
1804 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
1805 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
1806 checkGLcall("RB attachment");
1809 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
1810 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.0f
, 1.0f
);
1811 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
1812 if (gl_info
->gl_ops
.gl
.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION
)
1814 while (gl_info
->gl_ops
.gl
.p_glGetError());
1815 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
1816 debug_d3dformat(format
->id
), type
);
1817 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
1821 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
1822 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
1823 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
1825 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 16);
1826 gl_info
->gl_ops
.gl
.p_glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1828 draw_test_quad(ctx
, NULL
, &black
);
1830 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
1832 draw_test_quad(ctx
, NULL
, &half_transparent_red
);
1834 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
1838 case WINED3D_GL_RES_TYPE_TEX_1D
:
1839 /* Rebinding texture to workaround a fglrx bug. */
1840 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, object
);
1841 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_1D
, 0, GL_BGRA
,
1842 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
1843 color
= readback
[7];
1846 case WINED3D_GL_RES_TYPE_TEX_2D
:
1847 case WINED3D_GL_RES_TYPE_TEX_3D
:
1848 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1849 /* Rebinding texture to workaround a fglrx bug. */
1850 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(type
), object
);
1851 gl_info
->gl_ops
.gl
.p_glGetTexImage(wined3d_gl_type_to_enum(type
), 0, GL_BGRA
,
1852 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
1853 color
= readback
[7 * 16 + 7];
1856 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1857 /* Rebinding texture to workaround a fglrx bug. */
1858 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, object
);
1859 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, GL_BGRA
,
1860 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
1861 color
= readback
[7 * 16 + 7];
1864 case WINED3D_GL_RES_TYPE_RB
:
1865 gl_info
->gl_ops
.gl
.p_glReadPixels(0, 0, 16, 16,
1866 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
1867 color
= readback
[7 * 16 + 7];
1870 case WINED3D_GL_RES_TYPE_BUFFER
:
1871 case WINED3D_GL_RES_TYPE_COUNT
:
1875 checkGLcall("Post-pixelshader blending check");
1878 r
= (color
& 0x00ff0000u
) >> 16;
1880 r_range
= format
->red_size
< 8 ? 1u << (8 - format
->red_size
) : 1;
1881 a_range
= format
->alpha_size
< 8 ? 1u << (8 - format
->alpha_size
) : 1;
1882 if (format
->red_size
&& (r
< 0x7f - r_range
|| r
> 0x7f + r_range
))
1884 else if (format
->alpha_size
> 1 && (a
< 0xbf - a_range
|| a
> 0xbf + a_range
))
1888 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
1889 debug_d3dformat(format
->id
), type
);
1890 TRACE("Color output: %#x\n", color
);
1891 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
1895 TRACE("Format %s supports post-pixelshader blending, type %u.\n",
1896 debug_d3dformat(format
->id
), type
);
1897 TRACE("Color output: %#x\n", color
);
1898 format
->flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
1902 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
]
1903 || gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
1905 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, 0);
1906 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, 0);
1907 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &rb
);
1908 checkGLcall("RB cleanup");
1912 if (format
->glInternal
!= format
->glGammaInternal
)
1914 delete_fbo_attachment(gl_info
, type
, object
);
1915 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->glGammaInternal
,
1916 format
->glFormat
, format
->glType
);
1918 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
1919 checkGLcall("Framebuffer format check");
1921 if (status
== GL_FRAMEBUFFER_COMPLETE
)
1923 TRACE("Format %s's sRGB format is FBO attachable, type %u.\n",
1924 debug_d3dformat(format
->id
), type
);
1925 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
1929 WARN("Format %s's sRGB format is not FBO attachable, type %u.\n",
1930 debug_d3dformat(format
->id
), type
);
1933 else if (status
== GL_FRAMEBUFFER_COMPLETE
)
1934 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
1936 if (format
->flags
[type
] & (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
1938 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, 0);
1939 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &color_rb
);
1942 delete_fbo_attachment(gl_info
, type
, object
);
1943 checkGLcall("Framebuffer format check cleaup");
1946 if (fallback_fmt_used
&& regular_fmt_used
)
1948 FIXME("Format %s needs different render target formats for different resource types.\n",
1949 debug_d3dformat(format
->id
));
1950 format_clear_flag(format
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
1951 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
1955 static void query_format_flag(struct wined3d_gl_info
*gl_info
, struct wined3d_format
*format
,
1956 GLint internal
, GLenum pname
, DWORD flag
, const char *string
)
1959 enum wined3d_gl_resource_type type
;
1961 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
1963 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
), internal
, pname
, 1, &value
);
1964 if (value
== GL_FULL_SUPPORT
)
1966 TRACE("Format %s supports %s, resource type %u.\n", debug_d3dformat(format
->id
), string
, type
);
1967 format
->flags
[type
] |= flag
;
1971 TRACE("Format %s doesn't support %s, resource type %u.\n", debug_d3dformat(format
->id
), string
, type
);
1972 format
->flags
[type
] &= ~flag
;
1977 /* Context activation is done by the caller. */
1978 static void init_format_fbo_compat_info(struct wined3d_caps_gl_ctx
*ctx
)
1980 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
1981 unsigned int i
, type
;
1984 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
1986 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); ++i
)
1989 struct wined3d_format
*format
= &gl_info
->formats
[i
];
1990 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
1991 GLenum rt_internal
= format
->rtInternal
;
1993 if (!format
->glInternal
)
1996 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
1998 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
1999 format
->glInternal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2000 if (value
== GL_FULL_SUPPORT
)
2002 TRACE("Format %s is supported as FBO color attachment, resource type %u.\n",
2003 debug_d3dformat(format
->id
), type
);
2004 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
2005 format
->rtInternal
= format
->glInternal
;
2006 regular_fmt_used
= TRUE
;
2008 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2009 format
->glInternal
, GL_FRAMEBUFFER_BLEND
, 1, &value
);
2010 if (value
== GL_FULL_SUPPORT
)
2012 TRACE("Format %s supports post-pixelshader blending, resource type %u.\n",
2013 debug_d3dformat(format
->id
), type
);
2014 format
->flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2018 TRACE("Format %s doesn't support post-pixelshader blending, resource typed %u.\n",
2019 debug_d3dformat(format
->id
), type
);
2020 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
2027 if (format
->flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
2029 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
2030 " and no fallback specified, resource type %u.\n",
2031 debug_d3dformat(format
->id
), type
);
2032 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2035 TRACE("Format %s is not supported as FBO color attachment,"
2036 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2037 format
->rtInternal
= format
->glInternal
;
2041 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2042 rt_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2043 if (value
== GL_FULL_SUPPORT
)
2045 TRACE("Format %s rtInternal format is supported as FBO color attachment,"
2046 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2047 fallback_fmt_used
= TRUE
;
2051 WARN("Format %s rtInternal format is not supported as FBO color attachment,"
2052 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
2053 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
2058 if (format
->glInternal
!= format
->glGammaInternal
)
2060 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
2061 format
->glGammaInternal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
2062 if (value
== GL_FULL_SUPPORT
)
2064 TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n",
2065 debug_d3dformat(format
->id
), type
);
2066 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2070 WARN("Format %s's sRGB format is not FBO attachable, resource type %u.\n",
2071 debug_d3dformat(format
->id
), type
);
2074 else if (format
->flags
[type
] & WINED3DFMT_FLAG_FBO_ATTACHABLE
)
2075 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
2078 if (fallback_fmt_used
&& regular_fmt_used
)
2080 FIXME("Format %s needs different render target formats for different resource types.\n",
2081 debug_d3dformat(format
->id
));
2082 format_clear_flag(format
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
2083 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
2089 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2091 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2092 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2093 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2094 gl_info
->gl_ops
.gl
.p_glReadBuffer(GL_COLOR_ATTACHMENT0
);
2097 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); ++i
)
2099 struct wined3d_format
*format
= &gl_info
->formats
[i
];
2101 if (!format
->glInternal
) continue;
2103 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_COMPRESSED
)
2105 TRACE("Skipping format %s because it's a compressed format.\n",
2106 debug_d3dformat(format
->id
));
2110 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2112 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format
->id
));
2113 check_fbo_compat(ctx
, format
);
2117 format
->rtInternal
= format
->glInternal
;
2121 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2122 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2125 static BOOL
init_format_texture_info(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
2127 struct fragment_caps fragment_caps
;
2128 struct shader_caps shader_caps
;
2132 adapter
->fragment_pipe
->get_caps(gl_info
, &fragment_caps
);
2133 adapter
->shader_backend
->shader_get_caps(gl_info
, &shader_caps
);
2134 srgb_write
= (fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_SRGB_WRITE
)
2135 && (shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_SRGB_WRITE
);
2137 for (i
= 0; i
< sizeof(format_texture_info
) / sizeof(*format_texture_info
); ++i
)
2139 int fmt_idx
= getFmtIdx(format_texture_info
[i
].id
);
2140 struct wined3d_format
*format
;
2144 ERR("Format %s (%#x) not found.\n",
2145 debug_d3dformat(format_texture_info
[i
].id
), format_texture_info
[i
].id
);
2149 if (!gl_info
->supported
[format_texture_info
[i
].extension
]) continue;
2151 format
= &gl_info
->formats
[fmt_idx
];
2153 /* ARB_texture_rg defines floating point formats, but only if
2154 * ARB_texture_float is also supported. */
2155 if (!gl_info
->supported
[ARB_TEXTURE_FLOAT
]
2156 && (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_FLOAT
))
2159 format
->glInternal
= format_texture_info
[i
].gl_internal
;
2160 format
->glGammaInternal
= format_texture_info
[i
].gl_srgb_internal
;
2161 format
->rtInternal
= format_texture_info
[i
].gl_rt_internal
;
2162 format
->glFormat
= format_texture_info
[i
].gl_format
;
2163 format
->glType
= format_texture_info
[i
].gl_type
;
2164 format
->color_fixup
= COLOR_FIXUP_IDENTITY
;
2165 format
->height_scale
.numerator
= 1;
2166 format
->height_scale
.denominator
= 1;
2168 format
->flags
[WINED3D_GL_RES_TYPE_TEX_1D
] |= format_texture_info
[i
].flags
;
2169 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] |= format_texture_info
[i
].flags
;
2170 format
->flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= format_texture_info
[i
].flags
;
2172 /* GL_ARB_depth_texture does not support 3D textures. It also says "cube textures are
2173 * problematic", but doesn't explicitly mandate that an error is generated. */
2174 if (gl_info
->supported
[EXT_TEXTURE3D
]
2175 && !(format_texture_info
[i
].flags
& (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
)))
2176 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] |= format_texture_info
[i
].flags
;
2178 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
2179 format
->flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= format_texture_info
[i
].flags
;
2181 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
2182 format
->flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] |= format_texture_info
[i
].flags
;
2184 format
->flags
[WINED3D_GL_RES_TYPE_RB
] |= format_texture_info
[i
].flags
;
2185 format
->flags
[WINED3D_GL_RES_TYPE_RB
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2187 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2189 query_format_flag(gl_info
, format
, format
->glInternal
, GL_VERTEX_TEXTURE
,
2190 WINED3DFMT_FLAG_VTF
, "vertex texture usage");
2191 query_format_flag(gl_info
, format
, format
->glInternal
, GL_FILTER
,
2192 WINED3DFMT_FLAG_FILTERING
, "filtering");
2194 if (format
->glGammaInternal
!= format
->glInternal
)
2196 query_format_flag(gl_info
, format
, format
->glGammaInternal
, GL_SRGB_READ
,
2197 WINED3DFMT_FLAG_SRGB_READ
, "sRGB read");
2200 query_format_flag(gl_info
, format
, format
->glGammaInternal
, GL_SRGB_WRITE
,
2201 WINED3DFMT_FLAG_SRGB_WRITE
, "sRGB write");
2203 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2205 if (!(format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & (WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
)))
2206 format
->glGammaInternal
= format
->glInternal
;
2207 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2208 format
->glInternal
= format
->glGammaInternal
;
2213 if (!gl_info
->limits
.vertex_samplers
)
2214 format_clear_flag(format
, WINED3DFMT_FLAG_VTF
);
2216 if (!(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2217 format_set_flag(format
, WINED3DFMT_FLAG_FILTERING
);
2218 else if (format
->id
!= WINED3DFMT_R32G32B32A32_FLOAT
&& format
->id
!= WINED3DFMT_R32_FLOAT
)
2219 format_clear_flag(format
, WINED3DFMT_FLAG_VTF
);
2221 if (format
->glGammaInternal
!= format
->glInternal
)
2223 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
2224 if (!gl_info
->supported
[EXT_TEXTURE_SRGB
])
2226 format
->glGammaInternal
= format
->glInternal
;
2227 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2229 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2231 format
->glInternal
= format
->glGammaInternal
;
2235 if ((format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_SRGB_WRITE
) && !srgb_write
)
2236 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2238 if (!gl_info
->supported
[ARB_DEPTH_TEXTURE
]
2239 && format_texture_info
[i
].flags
& (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2241 format
->flags
[WINED3D_GL_RES_TYPE_TEX_1D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2242 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2243 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2244 format
->flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2245 format
->flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2249 /* Texture conversion stuff */
2250 format
->convert
= format_texture_info
[i
].convert
;
2251 format
->conv_byte_count
= format_texture_info
[i
].conv_byte_count
;
2257 static BOOL
color_match(DWORD c1
, DWORD c2
, BYTE max_diff
)
2259 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2261 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2263 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2265 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2269 /* A context is provided by the caller */
2270 static BOOL
check_filter(const struct wined3d_gl_info
*gl_info
, GLenum internal
)
2272 static const DWORD data
[] = {0x00000000, 0xffffffff};
2273 GLuint tex
, fbo
, buffer
;
2274 DWORD readback
[16 * 1];
2277 /* Render a filtered texture and see what happens. This is intended to detect the lack of
2278 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
2279 * falling back to software. If this changes in the future this code will get fooled and
2280 * apps might hit the software path due to incorrectly advertised caps.
2282 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
2283 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
2284 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
2287 while (gl_info
->gl_ops
.gl
.p_glGetError());
2289 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &buffer
);
2290 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
2291 memset(readback
, 0x7e, sizeof(readback
));
2292 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 16, 1, 0,
2293 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, readback
);
2294 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2295 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2296 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
2297 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
2298 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
2300 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &tex
);
2301 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, tex
);
2302 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, internal
, 2, 1, 0,
2303 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, data
);
2304 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
2305 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
2306 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
2307 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
2308 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
2309 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
2311 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2312 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2313 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, buffer
, 0);
2314 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2316 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2317 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
2318 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
2319 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2320 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
2321 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2323 gl_info
->gl_ops
.gl
.p_glClearColor(0, 1, 0, 0);
2324 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
2326 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
2327 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 0.0);
2328 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, -1.0f
);
2329 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 0.0);
2330 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, -1.0f
);
2331 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 1.0);
2332 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, 1.0f
);
2333 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 1.0);
2334 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, 1.0f
);
2335 gl_info
->gl_ops
.gl
.p_glEnd();
2337 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
2338 memset(readback
, 0x7f, sizeof(readback
));
2339 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2340 if (color_match(readback
[6], 0xffffffff, 5) || color_match(readback
[6], 0x00000000, 5)
2341 || color_match(readback
[9], 0xffffffff, 5) || color_match(readback
[9], 0x00000000, 5))
2343 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
2344 readback
[6], readback
[9]);
2349 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
2350 readback
[6], readback
[9]);
2354 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
2355 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2356 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &tex
);
2357 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &buffer
);
2359 if (gl_info
->gl_ops
.gl
.p_glGetError())
2361 FIXME("Error during filtering test for format %x, returning no filtering\n", internal
);
2368 static void init_format_filter_info(struct wined3d_gl_info
*gl_info
, enum wined3d_pci_vendor vendor
)
2370 struct wined3d_format
*format
;
2371 unsigned int fmt_idx
, i
;
2372 static const enum wined3d_format_id fmts16
[] =
2374 WINED3DFMT_R16_FLOAT
,
2375 WINED3DFMT_R16G16_FLOAT
,
2376 WINED3DFMT_R16G16B16A16_FLOAT
,
2380 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2381 /* This was already handled by init_format_texture_info(). */
2384 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
2385 || !gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
2387 WARN("No FBO support, or no FBO ORM, guessing filter info from GL caps\n");
2388 if (vendor
== HW_VENDOR_NVIDIA
&& gl_info
->supported
[ARB_TEXTURE_FLOAT
])
2390 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
2393 else if (gl_info
->limits
.glsl_varyings
> 44)
2395 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
2400 TRACE("Assuming no float16 blending\n");
2406 for(i
= 0; i
< (sizeof(fmts16
) / sizeof(*fmts16
)); i
++)
2408 fmt_idx
= getFmtIdx(fmts16
[i
]);
2409 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_FILTERING
);
2415 for(i
= 0; i
< (sizeof(fmts16
) / sizeof(*fmts16
)); i
++)
2417 fmt_idx
= getFmtIdx(fmts16
[i
]);
2418 format
= &gl_info
->formats
[fmt_idx
];
2419 if (!format
->glInternal
) continue; /* Not supported by GL */
2421 filtered
= check_filter(gl_info
, gl_info
->formats
[fmt_idx
].glInternal
);
2424 TRACE("Format %s supports filtering\n", debug_d3dformat(fmts16
[i
]));
2425 format_set_flag(format
, WINED3DFMT_FLAG_FILTERING
);
2429 TRACE("Format %s does not support filtering\n", debug_d3dformat(fmts16
[i
]));
2434 static void apply_format_fixups(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
2439 idx
= getFmtIdx(WINED3DFMT_R16_FLOAT
);
2440 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2441 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2443 idx
= getFmtIdx(WINED3DFMT_R32_FLOAT
);
2444 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2445 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2447 idx
= getFmtIdx(WINED3DFMT_R16G16_UNORM
);
2448 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2449 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2451 idx
= getFmtIdx(WINED3DFMT_R16G16_FLOAT
);
2452 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2453 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2455 idx
= getFmtIdx(WINED3DFMT_R32G32_FLOAT
);
2456 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2457 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2459 /* GL_ATI_envmap_bumpmap in theory supports R8G8_SNORM but is no longer supported by
2461 if (gl_info
->supported
[NV_TEXTURE_SHADER
] || gl_info
->supported
[EXT_TEXTURE_SNORM
])
2463 /* R8G8_SNORM and R16G16_SNORM need a fixup of the undefined blue channel. OpenGL
2464 * returns 0.0 when sampling from it, DirectX 1.0. So we always have in-shader
2465 * conversion for this format. */
2466 idx
= getFmtIdx(WINED3DFMT_R8G8_SNORM
);
2467 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2468 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2469 idx
= getFmtIdx(WINED3DFMT_R16G16_SNORM
);
2470 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2471 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2475 /* Emulate using unsigned formats. This requires load-time conversion in addition to the
2477 idx
= getFmtIdx(WINED3DFMT_R8G8_SNORM
);
2478 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2479 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2480 idx
= getFmtIdx(WINED3DFMT_R16G16_SNORM
);
2481 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2482 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2483 idx
= getFmtIdx(WINED3DFMT_R8G8B8A8_SNORM
);
2484 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2485 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 1, CHANNEL_SOURCE_Z
, 1, CHANNEL_SOURCE_W
);
2486 idx
= getFmtIdx(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
2487 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2488 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Z
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
);
2491 if (!gl_info
->supported
[NV_TEXTURE_SHADER
])
2493 idx
= getFmtIdx(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
2494 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2495 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_Z
, 0, CHANNEL_SOURCE_W
);
2498 if (gl_info
->supported
[ARB_TEXTURE_COMPRESSION_RGTC
] || gl_info
->supported
[EXT_TEXTURE_COMPRESSION_RGTC
])
2500 idx
= getFmtIdx(WINED3DFMT_ATI1N
);
2501 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2502 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
);
2504 idx
= getFmtIdx(WINED3DFMT_ATI2N
);
2505 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2506 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2508 else if (gl_info
->supported
[ATI_TEXTURE_COMPRESSION_3DC
])
2510 idx
= getFmtIdx(WINED3DFMT_ATI2N
);
2511 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2512 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_W
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2515 if (!gl_info
->supported
[APPLE_YCBCR_422
])
2517 idx
= getFmtIdx(WINED3DFMT_YUY2
);
2518 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUY2
);
2520 idx
= getFmtIdx(WINED3DFMT_UYVY
);
2521 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_UYVY
);
2524 idx
= getFmtIdx(WINED3DFMT_YV12
);
2525 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_HEIGHT_SCALE
);
2526 gl_info
->formats
[idx
].height_scale
.numerator
= 3;
2527 gl_info
->formats
[idx
].height_scale
.denominator
= 2;
2528 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YV12
);
2530 idx
= getFmtIdx(WINED3DFMT_NV12
);
2531 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_HEIGHT_SCALE
);
2532 gl_info
->formats
[idx
].height_scale
.numerator
= 3;
2533 gl_info
->formats
[idx
].height_scale
.denominator
= 2;
2534 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_NV12
);
2536 if (!gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
])
2538 idx
= getFmtIdx(WINED3DFMT_INTZ
);
2539 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2540 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
);
2543 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
])
2545 idx
= getFmtIdx(WINED3DFMT_P8_UINT
);
2546 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_P8
);
2549 if (gl_info
->supported
[ARB_VERTEX_ARRAY_BGRA
])
2551 idx
= getFmtIdx(WINED3DFMT_B8G8R8A8_UNORM
);
2552 gl_info
->formats
[idx
].gl_vtx_format
= GL_BGRA
;
2555 if (gl_info
->supported
[ARB_HALF_FLOAT_VERTEX
])
2557 /* Do not change the size of the type, it is CPU side. We have to change the GPU-side information though.
2558 * It is the job of the vertex buffer code to make sure that the vbos have the right format */
2559 idx
= getFmtIdx(WINED3DFMT_R16G16_FLOAT
);
2560 gl_info
->formats
[idx
].gl_vtx_type
= GL_HALF_FLOAT
; /* == GL_HALF_FLOAT_NV */
2562 idx
= getFmtIdx(WINED3DFMT_R16G16B16A16_FLOAT
);
2563 gl_info
->formats
[idx
].gl_vtx_type
= GL_HALF_FLOAT
;
2566 if (!gl_info
->supported
[ARB_HALF_FLOAT_PIXEL
])
2568 idx
= getFmtIdx(WINED3DFMT_R16_FLOAT
);
2569 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2571 idx
= getFmtIdx(WINED3DFMT_R16G16_FLOAT
);
2572 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2574 idx
= getFmtIdx(WINED3DFMT_R16G16B16A16_FLOAT
);
2575 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2578 if (gl_info
->quirks
& WINED3D_QUIRK_BROKEN_RGBA16
)
2580 idx
= getFmtIdx(WINED3DFMT_R16G16B16A16_UNORM
);
2581 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2584 /* ATI instancing hack: Although ATI cards do not support Shader Model
2585 * 3.0, they support instancing. To query if the card supports instancing
2586 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
2587 * is used. Should an application check for this, provide a proper return
2588 * value. We can do instancing with all shader versions, but we need
2591 * Additionally applications have to set the D3DRS_POINTSIZE render state
2592 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
2593 * doesn't need that and just ignores it.
2595 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
2596 /* FIXME: This should just check the shader backend caps. */
2597 if (gl_info
->supported
[ARB_VERTEX_PROGRAM
] || gl_info
->supported
[ARB_VERTEX_SHADER
])
2599 idx
= getFmtIdx(WINED3DFMT_INST
);
2600 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2603 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
2604 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
2605 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
2606 * MAKEFOURCC('N','V','D','B') and then controlled by setting
2607 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
2609 if (gl_info
->supported
[EXT_DEPTH_BOUNDS_TEST
])
2611 idx
= getFmtIdx(WINED3DFMT_NVDB
);
2612 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2615 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
2616 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
2617 * RENDERTARGET usage. */
2618 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
])
2620 idx
= getFmtIdx(WINED3DFMT_RESZ
);
2621 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
);
2624 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); ++i
)
2626 struct wined3d_format
*format
= &gl_info
->formats
[i
];
2628 if (!(format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_TEXTURE
))
2631 if (!adapter
->shader_backend
->shader_color_fixup_supported(format
->color_fixup
)
2632 || !adapter
->fragment_pipe
->color_fixup_supported(format
->color_fixup
))
2633 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2636 /* GL_EXT_texture_compression_s3tc does not support 3D textures. Some Windows drivers
2637 * for dx9 GPUs support it, some do not, so not supporting DXTn volumes is OK for d3d9.
2639 * Note that GL_NV_texture_compression_vtc adds this functionality to OpenGL, but the
2640 * block layout is not compatible with the one used by d3d. See volume_dxt5_test. */
2641 idx
= getFmtIdx(WINED3DFMT_DXT1
);
2642 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2643 idx
= getFmtIdx(WINED3DFMT_DXT2
);
2644 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2645 idx
= getFmtIdx(WINED3DFMT_DXT3
);
2646 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2647 idx
= getFmtIdx(WINED3DFMT_DXT4
);
2648 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2649 idx
= getFmtIdx(WINED3DFMT_DXT5
);
2650 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2651 /* Similarly with ATI1N / ATI2N and GL_ARB_texture_compression_rgtc. */
2652 idx
= getFmtIdx(WINED3DFMT_ATI1N
);
2653 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2654 idx
= getFmtIdx(WINED3DFMT_ATI2N
);
2655 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2658 static BOOL
init_format_vertex_info(struct wined3d_gl_info
*gl_info
)
2662 for (i
= 0; i
< (sizeof(format_vertex_info
) / sizeof(*format_vertex_info
)); ++i
)
2664 struct wined3d_format
*format
;
2665 int fmt_idx
= getFmtIdx(format_vertex_info
[i
].id
);
2669 ERR("Format %s (%#x) not found.\n",
2670 debug_d3dformat(format_vertex_info
[i
].id
), format_vertex_info
[i
].id
);
2674 format
= &gl_info
->formats
[fmt_idx
];
2675 format
->emit_idx
= format_vertex_info
[i
].emit_idx
;
2676 format
->component_count
= format_vertex_info
[i
].component_count
;
2677 format
->gl_vtx_type
= format_vertex_info
[i
].gl_vtx_type
;
2678 format
->gl_vtx_format
= format_vertex_info
[i
].gl_vtx_format
;
2679 format
->gl_normalized
= format_vertex_info
[i
].gl_normalized
;
2680 format
->component_size
= format_vertex_info
[i
].component_size
;
2686 BOOL
initPixelFormatsNoGL(struct wined3d_gl_info
*gl_info
)
2688 if (!init_format_base_info(gl_info
)) return FALSE
;
2690 if (!init_format_block_info(gl_info
))
2692 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
2693 gl_info
->formats
= NULL
;
2700 /* Context activation is done by the caller. */
2701 BOOL
wined3d_adapter_init_format_info(struct wined3d_adapter
*adapter
, struct wined3d_caps_gl_ctx
*ctx
)
2703 struct wined3d_gl_info
*gl_info
= &adapter
->gl_info
;
2705 if (!init_format_base_info(gl_info
)) return FALSE
;
2707 if (!init_format_block_info(gl_info
)) goto fail
;
2708 if (!init_format_texture_info(adapter
, gl_info
)) goto fail
;
2709 if (!init_format_vertex_info(gl_info
)) goto fail
;
2711 apply_format_fixups(adapter
, gl_info
);
2712 init_format_fbo_compat_info(ctx
);
2713 init_format_filter_info(gl_info
, adapter
->driver_info
.vendor
);
2718 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
2719 gl_info
->formats
= NULL
;
2723 float wined3d_adapter_find_polyoffset_scale(struct wined3d_caps_gl_ctx
*ctx
, GLenum format
)
2725 const struct wined3d_gl_info
*gl_info
= ctx
->gl_info
;
2726 static const struct wined3d_color blue
= {0.0f
, 0.0f
, 1.0f
, 1.0f
};
2727 GLuint fbo
, color
, depth
;
2728 unsigned int low
= 0, high
= 32, cur
;
2729 DWORD readback
[256];
2730 static const struct wined3d_vec3 geometry
[] =
2732 {-1.0f
, -1.0f
, -1.0f
},
2733 { 1.0f
, -1.0f
, 0.0f
},
2734 {-1.0f
, 1.0f
, -1.0f
},
2735 { 1.0f
, 1.0f
, 0.0f
},
2738 /* Most drivers want 2^23 for fixed point depth buffers, including r300g, r600g,
2739 * Nvidia. Use this as a fallback if the detection fails. */
2740 unsigned int fallback
= 23;
2742 if (wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
2744 FIXME("No FBOs, assuming polyoffset scale of 2^%u.\n", fallback
);
2745 return (float)(1u << fallback
);
2748 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &color
);
2749 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
2750 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAX_LEVEL
, 0);
2751 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);
2753 gl_info
->fbo_ops
.glGenRenderbuffers(1, &depth
);
2754 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, depth
);
2755 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, format
, 256, 1);
2757 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2758 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2759 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, color
, 0);
2760 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, depth
);
2761 checkGLcall("Setup framebuffer");
2763 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.5f
, 0.0f
);
2764 gl_info
->gl_ops
.gl
.p_glClearDepth(0.5f
);
2765 gl_info
->gl_ops
.gl
.p_glEnable(GL_DEPTH_TEST
);
2766 gl_info
->gl_ops
.gl
.p_glEnable(GL_POLYGON_OFFSET_FILL
);
2767 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 256, 1);
2768 checkGLcall("Misc parameters");
2772 if (high
- low
<= 1)
2774 ERR("PolygonOffset scale factor detection failed, using fallback value 2^%u.\n", fallback
);
2778 cur
= (low
+ high
) / 2;
2780 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
2781 /* The post viewport transform Z of the geometry runs from 0.0 to 0.5. We want to push it another
2782 * 0.25 so that the Z buffer content (0.5) cuts the quad off at half the screen. */
2783 gl_info
->gl_ops
.gl
.p_glPolygonOffset(0.0f
, (float)(1u << cur
) * 0.25f
);
2784 draw_test_quad(ctx
, geometry
, &blue
);
2785 checkGLcall("Test draw");
2787 /* Rebinding texture to workaround a fglrx bug. */
2788 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, color
);
2789 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2790 checkGLcall("readback");
2792 TRACE("low %02u, high %02u, cur %2u, 0=0x%08x, 125=0x%08x, 131=0x%08x, 255=0x%08x\n",
2793 low
, high
, cur
, readback
[0], readback
[125], readback
[131], readback
[255]);
2795 if ((readback
[125] & 0xff) < 0xa0)
2797 else if ((readback
[131] & 0xff) > 0xa0)
2801 TRACE("Found scale factor 2^%u for format %x\n", cur
, format
);
2806 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &color
);
2807 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &depth
);
2808 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2809 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
2810 checkGLcall("Delete framebuffer");
2812 gl_info
->gl_ops
.gl
.p_glDisable(GL_DEPTH_TEST
);
2813 gl_info
->gl_ops
.gl
.p_glDisable(GL_POLYGON_OFFSET_FILL
);
2814 return (float)(1u << cur
);
2817 const struct wined3d_format
*wined3d_get_format(const struct wined3d_gl_info
*gl_info
,
2818 enum wined3d_format_id format_id
)
2820 int idx
= getFmtIdx(format_id
);
2824 FIXME("Can't find format %s (%#x) in the format lookup table\n",
2825 debug_d3dformat(format_id
), format_id
);
2826 /* Get the caller a valid pointer */
2827 idx
= getFmtIdx(WINED3DFMT_UNKNOWN
);
2830 return &gl_info
->formats
[idx
];
2833 UINT
wined3d_format_calculate_pitch(const struct wined3d_format
*format
, UINT width
)
2835 /* For block based formats, pitch means the amount of bytes to the next
2836 * row of blocks rather than the next row of pixels. */
2837 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BLOCKS
)
2838 return format
->block_byte_count
* ((width
+ format
->block_width
- 1) / format
->block_width
);
2840 return format
->byte_count
* width
;
2843 UINT
wined3d_format_calculate_size(const struct wined3d_format
*format
, UINT alignment
,
2844 UINT width
, UINT height
, UINT depth
)
2846 UINT pitch
= wined3d_format_calculate_pitch(format
, width
);
2849 if (format
->id
== WINED3DFMT_UNKNOWN
)
2853 else if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BLOCKS
)
2855 UINT row_count
= (height
+ format
->block_height
- 1) / format
->block_height
;
2856 size
= row_count
* ((pitch
+ alignment
- 1) & ~(alignment
- 1));
2860 size
= height
* ((pitch
+ alignment
- 1) & ~(alignment
- 1));
2863 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_HEIGHT_SCALE
)
2865 /* The D3D format requirements make sure that the resulting format is an integer again */
2866 size
*= format
->height_scale
.numerator
;
2867 size
/= format
->height_scale
.denominator
;
2875 /*****************************************************************************
2876 * Trace formatting of useful values
2878 const char *debug_d3dformat(enum wined3d_format_id format_id
)
2882 #define FMT_TO_STR(format_id) case format_id: return #format_id
2883 FMT_TO_STR(WINED3DFMT_UNKNOWN
);
2884 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM
);
2885 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM
);
2886 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM
);
2887 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM
);
2888 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM
);
2889 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM
);
2890 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM
);
2891 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM
);
2892 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM
);
2893 FMT_TO_STR(WINED3DFMT_P8_UINT
);
2894 FMT_TO_STR(WINED3DFMT_L8_UNORM
);
2895 FMT_TO_STR(WINED3DFMT_L8A8_UNORM
);
2896 FMT_TO_STR(WINED3DFMT_L4A4_UNORM
);
2897 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
2898 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
2899 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM
);
2900 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM
);
2901 FMT_TO_STR(WINED3DFMT_UYVY
);
2902 FMT_TO_STR(WINED3DFMT_YUY2
);
2903 FMT_TO_STR(WINED3DFMT_YV12
);
2904 FMT_TO_STR(WINED3DFMT_NV12
);
2905 FMT_TO_STR(WINED3DFMT_DXT1
);
2906 FMT_TO_STR(WINED3DFMT_DXT2
);
2907 FMT_TO_STR(WINED3DFMT_DXT3
);
2908 FMT_TO_STR(WINED3DFMT_DXT4
);
2909 FMT_TO_STR(WINED3DFMT_DXT5
);
2910 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8
);
2911 FMT_TO_STR(WINED3DFMT_G8R8_G8B8
);
2912 FMT_TO_STR(WINED3DFMT_R8G8_B8G8
);
2913 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE
);
2914 FMT_TO_STR(WINED3DFMT_D32_UNORM
);
2915 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM
);
2916 FMT_TO_STR(WINED3DFMT_X8D24_UNORM
);
2917 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM
);
2918 FMT_TO_STR(WINED3DFMT_L16_UNORM
);
2919 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT
);
2920 FMT_TO_STR(WINED3DFMT_VERTEXDATA
);
2921 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx
);
2922 FMT_TO_STR(WINED3DFMT_ATI1N
);
2923 FMT_TO_STR(WINED3DFMT_ATI2N
);
2924 FMT_TO_STR(WINED3DFMT_NVDB
);
2925 FMT_TO_STR(WINED3DFMT_NVHU
);
2926 FMT_TO_STR(WINED3DFMT_NVHS
);
2927 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS
);
2928 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT
);
2929 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT
);
2930 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT
);
2931 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS
);
2932 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT
);
2933 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT
);
2934 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT
);
2935 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS
);
2936 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT
);
2937 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM
);
2938 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT
);
2939 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM
);
2940 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT
);
2941 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS
);
2942 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT
);
2943 FMT_TO_STR(WINED3DFMT_R32G32_UINT
);
2944 FMT_TO_STR(WINED3DFMT_R32G32_SINT
);
2945 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS
);
2946 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT
);
2947 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
);
2948 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT
);
2949 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS
);
2950 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM
);
2951 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT
);
2952 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM
);
2953 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT
);
2954 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS
);
2955 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM
);
2956 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB
);
2957 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT
);
2958 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM
);
2959 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT
);
2960 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS
);
2961 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT
);
2962 FMT_TO_STR(WINED3DFMT_R16G16_UNORM
);
2963 FMT_TO_STR(WINED3DFMT_R16G16_UINT
);
2964 FMT_TO_STR(WINED3DFMT_R16G16_SNORM
);
2965 FMT_TO_STR(WINED3DFMT_R16G16_SINT
);
2966 FMT_TO_STR(WINED3DFMT_R32_TYPELESS
);
2967 FMT_TO_STR(WINED3DFMT_D32_FLOAT
);
2968 FMT_TO_STR(WINED3DFMT_R32_FLOAT
);
2969 FMT_TO_STR(WINED3DFMT_R32_UINT
);
2970 FMT_TO_STR(WINED3DFMT_R32_SINT
);
2971 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS
);
2972 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT
);
2973 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS
);
2974 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT
);
2975 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS
);
2976 FMT_TO_STR(WINED3DFMT_R8G8_UNORM
);
2977 FMT_TO_STR(WINED3DFMT_R8G8_UINT
);
2978 FMT_TO_STR(WINED3DFMT_R8G8_SNORM
);
2979 FMT_TO_STR(WINED3DFMT_R8G8_SINT
);
2980 FMT_TO_STR(WINED3DFMT_R16_TYPELESS
);
2981 FMT_TO_STR(WINED3DFMT_R16_FLOAT
);
2982 FMT_TO_STR(WINED3DFMT_D16_UNORM
);
2983 FMT_TO_STR(WINED3DFMT_R16_UNORM
);
2984 FMT_TO_STR(WINED3DFMT_R16_UINT
);
2985 FMT_TO_STR(WINED3DFMT_R16_SNORM
);
2986 FMT_TO_STR(WINED3DFMT_R16_SINT
);
2987 FMT_TO_STR(WINED3DFMT_R8_TYPELESS
);
2988 FMT_TO_STR(WINED3DFMT_R8_UNORM
);
2989 FMT_TO_STR(WINED3DFMT_R8_UINT
);
2990 FMT_TO_STR(WINED3DFMT_R8_SNORM
);
2991 FMT_TO_STR(WINED3DFMT_R8_SINT
);
2992 FMT_TO_STR(WINED3DFMT_A8_UNORM
);
2993 FMT_TO_STR(WINED3DFMT_R1_UNORM
);
2994 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP
);
2995 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM
);
2996 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM
);
2997 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS
);
2998 FMT_TO_STR(WINED3DFMT_BC1_UNORM
);
2999 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB
);
3000 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS
);
3001 FMT_TO_STR(WINED3DFMT_BC2_UNORM
);
3002 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB
);
3003 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS
);
3004 FMT_TO_STR(WINED3DFMT_BC3_UNORM
);
3005 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB
);
3006 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS
);
3007 FMT_TO_STR(WINED3DFMT_BC4_UNORM
);
3008 FMT_TO_STR(WINED3DFMT_BC4_SNORM
);
3009 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS
);
3010 FMT_TO_STR(WINED3DFMT_BC5_UNORM
);
3011 FMT_TO_STR(WINED3DFMT_BC5_SNORM
);
3012 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM
);
3013 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM
);
3014 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM
);
3015 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM
);
3016 FMT_TO_STR(WINED3DFMT_INTZ
);
3017 FMT_TO_STR(WINED3DFMT_RESZ
);
3018 FMT_TO_STR(WINED3DFMT_NULL
);
3019 FMT_TO_STR(WINED3DFMT_R16
);
3020 FMT_TO_STR(WINED3DFMT_AL16
);
3025 fourcc
[0] = (char)(format_id
);
3026 fourcc
[1] = (char)(format_id
>> 8);
3027 fourcc
[2] = (char)(format_id
>> 16);
3028 fourcc
[3] = (char)(format_id
>> 24);
3030 if (isprint(fourcc
[0]) && isprint(fourcc
[1]) && isprint(fourcc
[2]) && isprint(fourcc
[3]))
3031 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id
, fourcc
);
3033 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id
);
3035 return "unrecognized";
3039 const char *debug_d3ddevicetype(enum wined3d_device_type device_type
)
3041 switch (device_type
)
3043 #define DEVTYPE_TO_STR(dev) case dev: return #dev
3044 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL
);
3045 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF
);
3046 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW
);
3047 #undef DEVTYPE_TO_STR
3049 FIXME("Unrecognized device type %#x.\n", device_type
);
3050 return "unrecognized";
3054 const char *debug_d3dusage(DWORD usage
)
3059 #define WINED3DUSAGE_TO_STR(u) if (usage & u) { strcat(buf, " | "#u); usage &= ~u; }
3060 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RENDERTARGET
);
3061 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DEPTHSTENCIL
);
3062 WINED3DUSAGE_TO_STR(WINED3DUSAGE_WRITEONLY
);
3063 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING
);
3064 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP
);
3065 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS
);
3066 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES
);
3067 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES
);
3068 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC
);
3069 WINED3DUSAGE_TO_STR(WINED3DUSAGE_AUTOGENMIPMAP
);
3070 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP
);
3071 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL
);
3072 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY
);
3073 #undef WINED3DUSAGE_TO_STR
3074 if (usage
) FIXME("Unrecognized usage flag(s) %#x\n", usage
);
3076 return buf
[0] ? wine_dbg_sprintf("%s", &buf
[3]) : "0";
3079 const char *debug_d3dusagequery(DWORD usagequery
)
3084 #define WINED3DUSAGEQUERY_TO_STR(u) if (usagequery & u) { strcat(buf, " | "#u); usagequery &= ~u; }
3085 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_FILTER
);
3086 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP
);
3087 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
);
3088 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD
);
3089 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE
);
3090 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE
);
3091 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP
);
3092 #undef WINED3DUSAGEQUERY_TO_STR
3093 if (usagequery
) FIXME("Unrecognized usage query flag(s) %#x\n", usagequery
);
3095 return buf
[0] ? wine_dbg_sprintf("%s", &buf
[3]) : "0";
3098 const char *debug_d3ddeclmethod(enum wined3d_decl_method method
)
3102 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
3103 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT
);
3104 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U
);
3105 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V
);
3106 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV
);
3107 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV
);
3108 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP
);
3109 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED
);
3110 #undef WINED3DDECLMETHOD_TO_STR
3112 FIXME("Unrecognized declaration method %#x.\n", method
);
3113 return "unrecognized";
3117 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage
)
3121 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
3122 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION
);
3123 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT
);
3124 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES
);
3125 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL
);
3126 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE
);
3127 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD
);
3128 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT
);
3129 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL
);
3130 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR
);
3131 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT
);
3132 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR
);
3133 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG
);
3134 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH
);
3135 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE
);
3136 #undef WINED3DDECLUSAGE_TO_STR
3138 FIXME("Unrecognized %u declaration usage!\n", usage
);
3139 return "unrecognized";
3143 const char *debug_d3dinput_classification(enum wined3d_input_classification classification
)
3145 switch (classification
)
3147 #define WINED3D_TO_STR(x) case x: return #x
3148 WINED3D_TO_STR(WINED3D_INPUT_PER_VERTEX_DATA
);
3149 WINED3D_TO_STR(WINED3D_INPUT_PER_INSTANCE_DATA
);
3150 #undef WINED3D_TO_STR
3152 FIXME("Unrecognized input classification %#x.\n", classification
);
3153 return "unrecognized";
3157 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type
)
3159 switch (resource_type
)
3161 #define RES_TO_STR(res) case res: return #res
3162 RES_TO_STR(WINED3D_RTYPE_SURFACE
);
3163 RES_TO_STR(WINED3D_RTYPE_VOLUME
);
3164 RES_TO_STR(WINED3D_RTYPE_TEXTURE
);
3165 RES_TO_STR(WINED3D_RTYPE_VOLUME_TEXTURE
);
3166 RES_TO_STR(WINED3D_RTYPE_CUBE_TEXTURE
);
3167 RES_TO_STR(WINED3D_RTYPE_BUFFER
);
3170 FIXME("Unrecognized resource type %#x.\n", resource_type
);
3171 return "unrecognized";
3175 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type
)
3177 switch (primitive_type
)
3179 #define PRIM_TO_STR(prim) case prim: return #prim
3180 PRIM_TO_STR(WINED3D_PT_UNDEFINED
);
3181 PRIM_TO_STR(WINED3D_PT_POINTLIST
);
3182 PRIM_TO_STR(WINED3D_PT_LINELIST
);
3183 PRIM_TO_STR(WINED3D_PT_LINESTRIP
);
3184 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST
);
3185 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP
);
3186 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN
);
3187 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ
);
3188 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ
);
3189 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ
);
3190 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ
);
3193 FIXME("Unrecognized %u primitive type!\n", primitive_type
);
3194 return "unrecognized";
3198 const char *debug_d3drenderstate(enum wined3d_render_state state
)
3202 #define D3DSTATE_TO_STR(u) case u: return #u
3203 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS
);
3204 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE
);
3205 D3DSTATE_TO_STR(WINED3D_RS_WRAPU
);
3206 D3DSTATE_TO_STR(WINED3D_RS_WRAPV
);
3207 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE
);
3208 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE
);
3209 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE
);
3210 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN
);
3211 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE
);
3212 D3DSTATE_TO_STR(WINED3D_RS_ROP2
);
3213 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK
);
3214 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE
);
3215 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE
);
3216 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL
);
3217 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND
);
3218 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND
);
3219 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE
);
3220 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC
);
3221 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF
);
3222 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC
);
3223 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE
);
3224 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE
);
3225 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE
);
3226 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE
);
3227 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE
);
3228 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL
);
3229 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX
);
3230 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA
);
3231 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR
);
3232 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE
);
3233 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART
);
3234 D3DSTATE_TO_STR(WINED3D_RS_FOGEND
);
3235 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY
);
3236 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE
);
3237 D3DSTATE_TO_STR(WINED3D_RS_EDGEANTIALIAS
);
3238 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE
);
3239 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS
);
3240 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE
);
3241 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY
);
3242 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH
);
3243 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT
);
3244 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE
);
3245 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL
);
3246 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL
);
3247 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS
);
3248 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC
);
3249 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF
);
3250 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK
);
3251 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK
);
3252 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR
);
3253 D3DSTATE_TO_STR(WINED3D_RS_WRAP0
);
3254 D3DSTATE_TO_STR(WINED3D_RS_WRAP1
);
3255 D3DSTATE_TO_STR(WINED3D_RS_WRAP2
);
3256 D3DSTATE_TO_STR(WINED3D_RS_WRAP3
);
3257 D3DSTATE_TO_STR(WINED3D_RS_WRAP4
);
3258 D3DSTATE_TO_STR(WINED3D_RS_WRAP5
);
3259 D3DSTATE_TO_STR(WINED3D_RS_WRAP6
);
3260 D3DSTATE_TO_STR(WINED3D_RS_WRAP7
);
3261 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING
);
3262 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING
);
3263 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS
);
3264 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT
);
3265 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE
);
3266 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX
);
3267 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER
);
3268 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS
);
3269 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE
);
3270 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE
);
3271 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE
);
3272 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE
);
3273 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE
);
3274 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND
);
3275 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE
);
3276 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING
);
3277 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE
);
3278 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN
);
3279 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE
);
3280 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE
);
3281 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A
);
3282 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B
);
3283 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C
);
3284 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS
);
3285 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK
);
3286 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE
);
3287 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS
);
3288 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN
);
3289 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX
);
3290 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE
);
3291 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE
);
3292 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR
);
3293 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP
);
3294 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE
);
3295 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE
);
3296 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE
);
3297 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS
);
3298 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE
);
3299 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL
);
3300 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL
);
3301 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X
);
3302 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y
);
3303 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z
);
3304 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W
);
3305 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION
);
3306 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE
);
3307 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILFAIL
);
3308 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILZFAIL
);
3309 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILPASS
);
3310 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILFUNC
);
3311 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1
);
3312 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2
);
3313 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3
);
3314 D3DSTATE_TO_STR(WINED3D_RS_BLENDFACTOR
);
3315 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE
);
3316 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS
);
3317 D3DSTATE_TO_STR(WINED3D_RS_WRAP8
);
3318 D3DSTATE_TO_STR(WINED3D_RS_WRAP9
);
3319 D3DSTATE_TO_STR(WINED3D_RS_WRAP10
);
3320 D3DSTATE_TO_STR(WINED3D_RS_WRAP11
);
3321 D3DSTATE_TO_STR(WINED3D_RS_WRAP12
);
3322 D3DSTATE_TO_STR(WINED3D_RS_WRAP13
);
3323 D3DSTATE_TO_STR(WINED3D_RS_WRAP14
);
3324 D3DSTATE_TO_STR(WINED3D_RS_WRAP15
);
3325 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE
);
3326 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA
);
3327 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA
);
3328 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA
);
3329 #undef D3DSTATE_TO_STR
3331 FIXME("Unrecognized %u render state!\n", state
);
3332 return "unrecognized";
3336 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state
)
3340 #define D3DSTATE_TO_STR(u) case u: return #u
3341 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR
);
3342 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U
);
3343 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V
);
3344 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W
);
3345 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER
);
3346 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER
);
3347 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER
);
3348 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS
);
3349 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL
);
3350 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY
);
3351 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE
);
3352 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX
);
3353 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET
);
3354 #undef D3DSTATE_TO_STR
3356 FIXME("Unrecognized %u sampler state!\n", state
);
3357 return "unrecognized";
3361 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type
)
3363 switch (filter_type
)
3365 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
3366 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE
);
3367 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT
);
3368 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR
);
3369 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC
);
3370 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC
);
3371 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC
);
3372 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD
);
3373 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD
);
3374 #undef D3DTEXTUREFILTERTYPE_TO_STR
3376 FIXME("Unrecognied texture filter type 0x%08x.\n", filter_type
);
3377 return "unrecognized";
3381 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state
)
3385 #define D3DSTATE_TO_STR(u) case u: return #u
3386 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP
);
3387 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1
);
3388 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2
);
3389 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP
);
3390 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1
);
3391 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2
);
3392 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00
);
3393 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01
);
3394 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10
);
3395 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11
);
3396 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX
);
3397 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE
);
3398 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET
);
3399 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
);
3400 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0
);
3401 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0
);
3402 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG
);
3403 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT
);
3404 #undef D3DSTATE_TO_STR
3406 FIXME("Unrecognized %u texture state!\n", state
);
3407 return "unrecognized";
3411 const char *debug_d3dtop(enum wined3d_texture_op d3dtop
)
3415 #define D3DTOP_TO_STR(u) case u: return #u
3416 D3DTOP_TO_STR(WINED3D_TOP_DISABLE
);
3417 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1
);
3418 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2
);
3419 D3DTOP_TO_STR(WINED3D_TOP_MODULATE
);
3420 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X
);
3421 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X
);
3422 D3DTOP_TO_STR(WINED3D_TOP_ADD
);
3423 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED
);
3424 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X
);
3425 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT
);
3426 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH
);
3427 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA
);
3428 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA
);
3429 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA
);
3430 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM
);
3431 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA
);
3432 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE
);
3433 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR
);
3434 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA
);
3435 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR
);
3436 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA
);
3437 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP
);
3438 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE
);
3439 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3
);
3440 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD
);
3441 D3DTOP_TO_STR(WINED3D_TOP_LERP
);
3442 #undef D3DTOP_TO_STR
3444 FIXME("Unrecognized texture op %#x.\n", d3dtop
);
3445 return "unrecognized";
3449 const char *debug_d3dtstype(enum wined3d_transform_state tstype
)
3453 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
3454 TSTYPE_TO_STR(WINED3D_TS_VIEW
);
3455 TSTYPE_TO_STR(WINED3D_TS_PROJECTION
);
3456 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0
);
3457 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1
);
3458 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2
);
3459 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3
);
3460 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4
);
3461 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5
);
3462 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6
);
3463 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7
);
3464 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
3465 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(1));
3466 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(2));
3467 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(3));
3468 #undef TSTYPE_TO_STR
3470 if (tstype
> 256 && tstype
< 512)
3472 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype
);
3473 return ("WINED3D_TS_WORLD_MATRIX > 0");
3475 FIXME("Unrecognized transform state %#x.\n", tstype
);
3476 return "unrecognized";
3480 static const char *debug_shader_type(enum wined3d_shader_type type
)
3484 #define WINED3D_TO_STR(type) case type: return #type
3485 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL
);
3486 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX
);
3487 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY
);
3488 #undef WINED3D_TO_STR
3490 FIXME("Unrecognized shader type %#x.\n", type
);
3491 return "unrecognized";
3495 const char *debug_d3dstate(DWORD state
)
3497 if (STATE_IS_RENDER(state
))
3498 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state
- STATE_RENDER(0)));
3499 if (STATE_IS_TEXTURESTAGE(state
))
3501 DWORD texture_stage
= (state
- STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE
+ 1);
3502 DWORD texture_state
= state
- STATE_TEXTURESTAGE(texture_stage
, 0);
3503 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
3504 texture_stage
, debug_d3dtexturestate(texture_state
));
3506 if (STATE_IS_SAMPLER(state
))
3507 return wine_dbg_sprintf("STATE_SAMPLER(%#x)", state
- STATE_SAMPLER(0));
3508 if (STATE_IS_SHADER(state
))
3509 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state
- STATE_SHADER(0)));
3510 if (STATE_IS_CONSTANT_BUFFER(state
))
3511 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state
- STATE_CONSTANT_BUFFER(0)));
3512 if (STATE_IS_SHADER_RESOURCE_BINDING(state
))
3513 return "STATE_SHADER_RESOURCE_BINDING";
3514 if (STATE_IS_TRANSFORM(state
))
3515 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state
- STATE_TRANSFORM(0)));
3516 if (STATE_IS_STREAMSRC(state
))
3517 return "STATE_STREAMSRC";
3518 if (STATE_IS_INDEXBUFFER(state
))
3519 return "STATE_INDEXBUFFER";
3520 if (STATE_IS_VDECL(state
))
3521 return "STATE_VDECL";
3522 if (STATE_IS_VIEWPORT(state
))
3523 return "STATE_VIEWPORT";
3524 if (STATE_IS_LIGHT_TYPE(state
))
3525 return "STATE_LIGHT_TYPE";
3526 if (STATE_IS_ACTIVELIGHT(state
))
3527 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state
- STATE_ACTIVELIGHT(0));
3528 if (STATE_IS_SCISSORRECT(state
))
3529 return "STATE_SCISSORRECT";
3530 if (STATE_IS_CLIPPLANE(state
))
3531 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state
- STATE_CLIPPLANE(0));
3532 if (STATE_IS_MATERIAL(state
))
3533 return "STATE_MATERIAL";
3534 if (STATE_IS_FRONTFACE(state
))
3535 return "STATE_FRONTFACE";
3536 if (STATE_IS_POINTSPRITECOORDORIGIN(state
))
3537 return "STATE_POINTSPRITECOORDORIGIN";
3538 if (STATE_IS_BASEVERTEXINDEX(state
))
3539 return "STATE_BASEVERTEXINDEX";
3540 if (STATE_IS_FRAMEBUFFER(state
))
3541 return "STATE_FRAMEBUFFER";
3542 if (STATE_IS_POINT_ENABLE(state
))
3543 return "STATE_POINT_ENABLE";
3544 if (STATE_IS_COLOR_KEY(state
))
3545 return "STATE_COLOR_KEY";
3547 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state
);
3550 const char *debug_d3dpool(enum wined3d_pool pool
)
3554 #define POOL_TO_STR(p) case p: return #p
3555 POOL_TO_STR(WINED3D_POOL_DEFAULT
);
3556 POOL_TO_STR(WINED3D_POOL_MANAGED
);
3557 POOL_TO_STR(WINED3D_POOL_SYSTEM_MEM
);
3558 POOL_TO_STR(WINED3D_POOL_SCRATCH
);
3561 FIXME("Unrecognized pool %#x.\n", pool
);
3562 return "unrecognized";
3566 const char *debug_fbostatus(GLenum status
) {
3568 #define FBOSTATUS_TO_STR(u) case u: return #u
3569 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE
);
3570 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
);
3571 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
);
3572 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
);
3573 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
);
3574 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
);
3575 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
);
3576 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
);
3577 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED
);
3578 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED
);
3579 #undef FBOSTATUS_TO_STR
3581 FIXME("Unrecognied FBO status 0x%08x\n", status
);
3582 return "unrecognized";
3586 const char *debug_glerror(GLenum error
) {
3588 #define GLERROR_TO_STR(u) case u: return #u
3589 GLERROR_TO_STR(GL_NO_ERROR
);
3590 GLERROR_TO_STR(GL_INVALID_ENUM
);
3591 GLERROR_TO_STR(GL_INVALID_VALUE
);
3592 GLERROR_TO_STR(GL_INVALID_OPERATION
);
3593 GLERROR_TO_STR(GL_STACK_OVERFLOW
);
3594 GLERROR_TO_STR(GL_STACK_UNDERFLOW
);
3595 GLERROR_TO_STR(GL_OUT_OF_MEMORY
);
3596 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION
);
3597 #undef GLERROR_TO_STR
3599 FIXME("Unrecognied GL error 0x%08x\n", error
);
3600 return "unrecognized";
3604 static const char *debug_fixup_channel_source(enum fixup_channel_source source
)
3608 #define WINED3D_TO_STR(x) case x: return #x
3609 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO
);
3610 WINED3D_TO_STR(CHANNEL_SOURCE_ONE
);
3611 WINED3D_TO_STR(CHANNEL_SOURCE_X
);
3612 WINED3D_TO_STR(CHANNEL_SOURCE_Y
);
3613 WINED3D_TO_STR(CHANNEL_SOURCE_Z
);
3614 WINED3D_TO_STR(CHANNEL_SOURCE_W
);
3615 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0
);
3616 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1
);
3617 #undef WINED3D_TO_STR
3619 FIXME("Unrecognized fixup_channel_source %#x\n", source
);
3620 return "unrecognized";
3624 static const char *debug_complex_fixup(enum complex_fixup fixup
)
3628 #define WINED3D_TO_STR(x) case x: return #x
3629 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2
);
3630 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY
);
3631 WINED3D_TO_STR(COMPLEX_FIXUP_YV12
);
3632 WINED3D_TO_STR(COMPLEX_FIXUP_NV12
);
3633 WINED3D_TO_STR(COMPLEX_FIXUP_P8
);
3634 #undef WINED3D_TO_STR
3636 FIXME("Unrecognized complex fixup %#x\n", fixup
);
3637 return "unrecognized";
3641 void dump_color_fixup_desc(struct color_fixup_desc fixup
)
3643 if (is_complex_fixup(fixup
))
3645 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup
)));
3649 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup
.x_source
), fixup
.x_sign_fixup
? ", SIGN_FIXUP" : "");
3650 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup
.y_source
), fixup
.y_sign_fixup
? ", SIGN_FIXUP" : "");
3651 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup
.z_source
), fixup
.z_sign_fixup
? ", SIGN_FIXUP" : "");
3652 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup
.w_source
), fixup
.w_sign_fixup
? ", SIGN_FIXUP" : "");
3655 BOOL
is_invalid_op(const struct wined3d_state
*state
, int stage
,
3656 enum wined3d_texture_op op
, DWORD arg1
, DWORD arg2
, DWORD arg3
)
3658 if (op
== WINED3D_TOP_DISABLE
)
3660 if (state
->textures
[stage
])
3663 if ((arg1
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
3664 && op
!= WINED3D_TOP_SELECT_ARG2
)
3666 if ((arg2
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
3667 && op
!= WINED3D_TOP_SELECT_ARG1
)
3669 if ((arg3
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
3670 && (op
== WINED3D_TOP_MULTIPLY_ADD
|| op
== WINED3D_TOP_LERP
))
3676 void get_identity_matrix(struct wined3d_matrix
*mat
)
3678 static const struct wined3d_matrix identity
=
3680 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3681 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3682 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3683 0.0f
, 0.0f
, 0.0f
, 1.0f
,
3689 void get_modelview_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
3690 unsigned int index
, struct wined3d_matrix
*mat
)
3692 if (context
->last_was_rhw
)
3693 get_identity_matrix(mat
);
3695 multiply_matrix(mat
, &state
->transforms
[WINED3D_TS_VIEW
], &state
->transforms
[WINED3D_TS_WORLD_MATRIX(index
)]);
3698 void get_projection_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
3699 struct wined3d_matrix
*mat
)
3701 float center_offset
;
3703 /* There are a couple of additional things we have to take into account
3704 * here besides the projection transformation itself:
3705 * - We need to flip along the y-axis in case of offscreen rendering.
3706 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
3707 * - D3D coordinates refer to pixel centers while GL coordinates refer
3709 * - D3D has a top-left filling convention. We need to maintain this
3710 * even after the y-flip mentioned above.
3711 * In order to handle the last two points, we translate by
3712 * (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to
3713 * translating slightly less than half a pixel. We want the difference to
3714 * be large enough that it doesn't get lost due to rounding inside the
3715 * driver, but small enough to prevent it from interfering with any
3718 if (context
->swapchain
->device
->wined3d
->flags
& WINED3D_PIXEL_CENTER_INTEGER
)
3719 center_offset
= 63.0f
/ 64.0f
;
3721 center_offset
= -1.0f
/ 64.0f
;
3723 if (context
->last_was_rhw
)
3725 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
3726 float x
= state
->viewport
.x
;
3727 float y
= state
->viewport
.y
;
3728 float w
= state
->viewport
.width
;
3729 float h
= state
->viewport
.height
;
3730 float x_scale
= 2.0f
/ w
;
3731 float x_offset
= (center_offset
- (2.0f
* x
) - w
) / w
;
3732 float y_scale
= context
->render_offscreen
? 2.0f
/ h
: 2.0f
/ -h
;
3733 float y_offset
= context
->render_offscreen
3734 ? (center_offset
- (2.0f
* y
) - h
) / h
3735 : (center_offset
- (2.0f
* y
) - h
) / -h
;
3736 enum wined3d_depth_buffer_type zenable
= state
->fb
->depth_stencil
?
3737 state
->render_states
[WINED3D_RS_ZENABLE
] : WINED3D_ZB_FALSE
;
3738 float z_scale
= zenable
? 2.0f
: 0.0f
;
3739 float z_offset
= zenable
? -1.0f
: 0.0f
;
3740 const struct wined3d_matrix projection
=
3742 x_scale
, 0.0f
, 0.0f
, 0.0f
,
3743 0.0f
, y_scale
, 0.0f
, 0.0f
,
3744 0.0f
, 0.0f
, z_scale
, 0.0f
,
3745 x_offset
, y_offset
, z_offset
, 1.0f
,
3752 float y_scale
= context
->render_offscreen
? -1.0f
: 1.0f
;
3753 float x_offset
= center_offset
/ state
->viewport
.width
;
3754 float y_offset
= context
->render_offscreen
3755 ? center_offset
/ state
->viewport
.height
3756 : -center_offset
/ state
->viewport
.height
;
3757 const struct wined3d_matrix projection
=
3759 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3760 0.0f
, y_scale
, 0.0f
, 0.0f
,
3761 0.0f
, 0.0f
, 2.0f
, 0.0f
,
3762 x_offset
, y_offset
, -1.0f
, 1.0f
,
3765 multiply_matrix(mat
, &projection
, &state
->transforms
[WINED3D_TS_PROJECTION
]);
3769 /* Setup this textures matrix according to the texture flags. */
3770 static void compute_texture_matrix(const struct wined3d_gl_info
*gl_info
, const struct wined3d_matrix
*matrix
,
3771 DWORD flags
, BOOL calculated_coords
, BOOL transformed
, enum wined3d_format_id format_id
,
3772 BOOL ffp_proj_control
, struct wined3d_matrix
*out_matrix
)
3774 struct wined3d_matrix mat
;
3776 if (flags
== WINED3D_TTFF_DISABLE
|| flags
== WINED3D_TTFF_COUNT1
|| transformed
)
3778 get_identity_matrix(out_matrix
);
3782 if (flags
== (WINED3D_TTFF_COUNT1
| WINED3D_TTFF_PROJECTED
))
3784 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
3790 if (flags
& WINED3D_TTFF_PROJECTED
)
3792 if (!ffp_proj_control
)
3794 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
3796 case WINED3D_TTFF_COUNT2
:
3801 mat
._12
= mat
._22
= mat
._32
= mat
._42
= 0.0f
;
3803 case WINED3D_TTFF_COUNT3
:
3808 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
3815 /* Under Direct3D the R/Z coord can be used for translation, under
3816 * OpenGL we use the Q coord instead. */
3817 if (!calculated_coords
)
3821 /* Direct3D passes the default 1.0 in the 2nd coord, while GL
3822 * passes it in the 4th. Swap 2nd and 4th coord. No need to
3823 * store the value of mat._41 in mat._21 because the input
3824 * value to the transformation will be 0, so the matrix value
3826 case WINED3DFMT_R32_FLOAT
:
3832 /* See above, just 3rd and 4th coord. */
3833 case WINED3DFMT_R32G32_FLOAT
:
3839 case WINED3DFMT_R32G32B32_FLOAT
: /* Opengl defaults match dx defaults */
3840 case WINED3DFMT_R32G32B32A32_FLOAT
: /* No defaults apply, all app defined */
3842 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
3843 * into a bad place. The division elimination below will apply to make sure the
3844 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
3846 case WINED3DFMT_UNKNOWN
: /* No texture coords, 0/0/0/1 defaults are passed */
3849 FIXME("Unexpected fixed function texture coord input\n");
3852 if (!ffp_proj_control
)
3854 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
3856 /* case WINED3D_TTFF_COUNT1: Won't ever get here. */
3857 case WINED3D_TTFF_COUNT2
:
3858 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
3859 /* OpenGL divides the first 3 vertex coord by the 4th by default,
3860 * which is essentially the same as D3DTTFF_PROJECTED. Make sure that
3861 * the 4th coord evaluates to 1.0 to eliminate that.
3863 * If the fixed function pipeline is used, the 4th value remains unused,
3864 * so there is no danger in doing this. With vertex shaders we have a
3865 * problem. Should an app hit that problem, the code here would have to
3866 * check for pixel shaders, and the shader has to undo the default gl divide.
3868 * A more serious problem occurs if the app passes 4 coordinates in, and the
3869 * 4th is != 1.0(opengl default). This would have to be fixed in drawStridedSlow
3870 * or a replacement shader. */
3872 mat
._14
= mat
._24
= mat
._34
= 0.0f
; mat
._44
= 1.0f
;
3880 void get_texture_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
3881 unsigned int tex
, struct wined3d_matrix
*mat
)
3883 const struct wined3d_device
*device
= context
->swapchain
->device
;
3884 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3885 BOOL generated
= (state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
] & 0xffff0000)
3886 != WINED3DTSS_TCI_PASSTHRU
;
3887 unsigned int coord_idx
= min(state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
& 0x0000ffff],
3890 compute_texture_matrix(gl_info
, &state
->transforms
[WINED3D_TS_TEXTURE0
+ tex
],
3891 state
->texture_states
[tex
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
],
3892 generated
, context
->last_was_rhw
,
3893 context
->stream_info
.use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))
3894 ? context
->stream_info
.elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format
->id
3895 : WINED3DFMT_UNKNOWN
,
3896 device
->shader_backend
->shader_has_ffp_proj_control(device
->shader_priv
), mat
);
3898 if ((context
->lastWasPow2Texture
& (1u << tex
)) && state
->textures
[tex
])
3901 FIXME("Non-power-of-two texture being used with generated texture coords.\n");
3902 /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
3903 * fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
3906 TRACE("Non-power-of-two texture matrix multiply fixup.\n");
3907 multiply_matrix(mat
, mat
, (struct wined3d_matrix
*)state
->textures
[tex
]->pow2_matrix
);
3912 void get_pointsize_minmax(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
3913 float *out_min
, float *out_max
)
3921 min
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MIN
];
3922 max
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MAX
];
3931 void get_pointsize(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
3932 float *out_pointsize
, float *out_att
)
3934 /* POINTSCALEENABLE controls how point size value is treated. If set to
3935 * true, the point size is scaled with respect to height of viewport.
3936 * When set to false point size is in pixels. */
3941 } pointsize
, a
, b
, c
;
3947 pointsize
.d
= state
->render_states
[WINED3D_RS_POINTSIZE
];
3948 a
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_A
];
3949 b
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_B
];
3950 c
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_C
];
3952 if (state
->render_states
[WINED3D_RS_POINTSCALEENABLE
])
3954 float scale_factor
= state
->viewport
.height
* state
->viewport
.height
;
3956 out_att
[0] = a
.f
/ scale_factor
;
3957 out_att
[1] = b
.f
/ scale_factor
;
3958 out_att
[2] = c
.f
/ scale_factor
;
3960 *out_pointsize
= pointsize
.f
;
3963 void get_fog_start_end(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
3964 float *start
, float *end
)
3972 switch (context
->fog_source
)
3979 case FOGSOURCE_COORD
:
3985 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGSTART
];
3986 *start
= tmpvalue
.f
;
3987 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGEND
];
3989 /* Special handling for fog_start == fog_end. In d3d with vertex
3990 * fog, everything is fogged. With table fog, everything with
3991 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
3992 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
3993 if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
&& *start
== *end
)
4001 /* This should not happen, context->fog_source is set in wined3d, not the app. */
4002 ERR("Unexpected fog coordinate source.\n");
4008 /* This small helper function is used to convert a bitmask into the number of masked bits */
4009 unsigned int count_bits(unsigned int mask
)
4012 for (count
= 0; mask
; ++count
)
4019 /* Note: It's the caller's responsibility to ensure values can be expressed
4020 * in the requested format. UNORM formats for example can only express values
4021 * in the range 0.0f -> 1.0f. */
4022 DWORD
wined3d_format_convert_from_float(const struct wined3d_surface
*surface
, const struct wined3d_color
*color
)
4026 enum wined3d_format_id format_id
;
4038 {WINED3DFMT_B8G8R8A8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
4039 {WINED3DFMT_B8G8R8X8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
4040 {WINED3DFMT_B8G8R8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
4041 {WINED3DFMT_B5G6R5_UNORM
, 31.0f
, 63.0f
, 31.0f
, 0.0f
, 11, 5, 0, 0},
4042 {WINED3DFMT_B5G5R5A1_UNORM
, 31.0f
, 31.0f
, 31.0f
, 1.0f
, 10, 5, 0, 15},
4043 {WINED3DFMT_B5G5R5X1_UNORM
, 31.0f
, 31.0f
, 31.0f
, 1.0f
, 10, 5, 0, 15},
4044 {WINED3DFMT_R8_UNORM
, 255.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 0, 0, 0},
4045 {WINED3DFMT_A8_UNORM
, 0.0f
, 0.0f
, 0.0f
, 255.0f
, 0, 0, 0, 0},
4046 {WINED3DFMT_B4G4R4A4_UNORM
, 15.0f
, 15.0f
, 15.0f
, 15.0f
, 8, 4, 0, 12},
4047 {WINED3DFMT_B4G4R4X4_UNORM
, 15.0f
, 15.0f
, 15.0f
, 15.0f
, 8, 4, 0, 12},
4048 {WINED3DFMT_B2G3R3_UNORM
, 7.0f
, 7.0f
, 3.0f
, 0.0f
, 5, 2, 0, 0},
4049 {WINED3DFMT_R8G8B8A8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 0, 8, 16, 24},
4050 {WINED3DFMT_R8G8B8X8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 0, 8, 16, 24},
4051 {WINED3DFMT_B10G10R10A2_UNORM
, 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
, 20, 10, 0, 30},
4052 {WINED3DFMT_R10G10B10A2_UNORM
, 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
, 0, 10, 20, 30},
4053 {WINED3DFMT_P8_UINT
, 0.0f
, 0.0f
, 0.0f
, 255.0f
, 0, 0, 0, 0},
4055 const struct wined3d_format
*format
= surface
->resource
.format
;
4058 TRACE("Converting color {%.8e %.8e %.8e %.8e} to format %s.\n",
4059 color
->r
, color
->g
, color
->b
, color
->a
, debug_d3dformat(format
->id
));
4061 for (i
= 0; i
< sizeof(conv
) / sizeof(*conv
); ++i
)
4065 if (format
->id
!= conv
[i
].format_id
) continue;
4067 ret
= ((DWORD
)((color
->r
* conv
[i
].r_mul
) + 0.5f
)) << conv
[i
].r_shift
;
4068 ret
|= ((DWORD
)((color
->g
* conv
[i
].g_mul
) + 0.5f
)) << conv
[i
].g_shift
;
4069 ret
|= ((DWORD
)((color
->b
* conv
[i
].b_mul
) + 0.5f
)) << conv
[i
].b_shift
;
4070 ret
|= ((DWORD
)((color
->a
* conv
[i
].a_mul
) + 0.5f
)) << conv
[i
].a_shift
;
4072 TRACE("Returning 0x%08x.\n", ret
);
4077 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format
->id
));
4082 static float color_to_float(DWORD color
, DWORD size
, DWORD offset
)
4084 DWORD mask
= (1u << size
) - 1;
4092 return (float)color
/ (float)mask
;
4095 BOOL
wined3d_format_convert_color_to_float(const struct wined3d_format
*format
,
4096 const struct wined3d_palette
*palette
, DWORD color
, struct wined3d_color
*float_color
)
4100 case WINED3DFMT_B8G8R8_UNORM
:
4101 case WINED3DFMT_B8G8R8A8_UNORM
:
4102 case WINED3DFMT_B8G8R8X8_UNORM
:
4103 case WINED3DFMT_B5G6R5_UNORM
:
4104 case WINED3DFMT_B5G5R5X1_UNORM
:
4105 case WINED3DFMT_B5G5R5A1_UNORM
:
4106 case WINED3DFMT_B4G4R4A4_UNORM
:
4107 case WINED3DFMT_B2G3R3_UNORM
:
4108 case WINED3DFMT_R8_UNORM
:
4109 case WINED3DFMT_A8_UNORM
:
4110 case WINED3DFMT_B2G3R3A8_UNORM
:
4111 case WINED3DFMT_B4G4R4X4_UNORM
:
4112 case WINED3DFMT_R10G10B10A2_UNORM
:
4113 case WINED3DFMT_R10G10B10A2_SNORM
:
4114 case WINED3DFMT_R8G8B8A8_UNORM
:
4115 case WINED3DFMT_R8G8B8X8_UNORM
:
4116 case WINED3DFMT_R16G16_UNORM
:
4117 case WINED3DFMT_B10G10R10A2_UNORM
:
4118 float_color
->r
= color_to_float(color
, format
->red_size
, format
->red_offset
);
4119 float_color
->g
= color_to_float(color
, format
->green_size
, format
->green_offset
);
4120 float_color
->b
= color_to_float(color
, format
->blue_size
, format
->blue_offset
);
4121 float_color
->a
= color_to_float(color
, format
->alpha_size
, format
->alpha_offset
);
4124 case WINED3DFMT_P8_UINT
:
4127 float_color
->r
= palette
->colors
[color
].rgbRed
/ 255.0f
;
4128 float_color
->g
= palette
->colors
[color
].rgbGreen
/ 255.0f
;
4129 float_color
->b
= palette
->colors
[color
].rgbBlue
/ 255.0f
;
4133 float_color
->r
= 0.0f
;
4134 float_color
->g
= 0.0f
;
4135 float_color
->b
= 0.0f
;
4137 float_color
->a
= color
/ 255.0f
;
4141 ERR("Unhandled conversion from %s to floating point.\n", debug_d3dformat(format
->id
));
4146 void wined3d_format_get_float_color_key(const struct wined3d_format
*format
,
4147 const struct wined3d_color_key
*key
, struct wined3d_color
*float_colors
)
4149 struct wined3d_color slop
;
4153 case WINED3DFMT_B8G8R8_UNORM
:
4154 case WINED3DFMT_B8G8R8A8_UNORM
:
4155 case WINED3DFMT_B8G8R8X8_UNORM
:
4156 case WINED3DFMT_B5G6R5_UNORM
:
4157 case WINED3DFMT_B5G5R5X1_UNORM
:
4158 case WINED3DFMT_B5G5R5A1_UNORM
:
4159 case WINED3DFMT_B4G4R4A4_UNORM
:
4160 case WINED3DFMT_B2G3R3_UNORM
:
4161 case WINED3DFMT_R8_UNORM
:
4162 case WINED3DFMT_A8_UNORM
:
4163 case WINED3DFMT_B2G3R3A8_UNORM
:
4164 case WINED3DFMT_B4G4R4X4_UNORM
:
4165 case WINED3DFMT_R10G10B10A2_UNORM
:
4166 case WINED3DFMT_R10G10B10A2_SNORM
:
4167 case WINED3DFMT_R8G8B8A8_UNORM
:
4168 case WINED3DFMT_R8G8B8X8_UNORM
:
4169 case WINED3DFMT_R16G16_UNORM
:
4170 case WINED3DFMT_B10G10R10A2_UNORM
:
4171 slop
.r
= 0.5f
/ ((1 << format
->red_size
) - 1);
4172 slop
.g
= 0.5f
/ ((1 << format
->green_size
) - 1);
4173 slop
.b
= 0.5f
/ ((1 << format
->blue_size
) - 1);
4174 slop
.a
= 0.5f
/ ((1 << format
->alpha_size
) - 1);
4176 float_colors
[0].r
= color_to_float(key
->color_space_low_value
, format
->red_size
, format
->red_offset
)
4178 float_colors
[0].g
= color_to_float(key
->color_space_low_value
, format
->green_size
, format
->green_offset
)
4180 float_colors
[0].b
= color_to_float(key
->color_space_low_value
, format
->blue_size
, format
->blue_offset
)
4182 float_colors
[0].a
= color_to_float(key
->color_space_low_value
, format
->alpha_size
, format
->alpha_offset
)
4185 float_colors
[1].r
= color_to_float(key
->color_space_high_value
, format
->red_size
, format
->red_offset
)
4187 float_colors
[1].g
= color_to_float(key
->color_space_high_value
, format
->green_size
, format
->green_offset
)
4189 float_colors
[1].b
= color_to_float(key
->color_space_high_value
, format
->blue_size
, format
->blue_offset
)
4191 float_colors
[1].a
= color_to_float(key
->color_space_high_value
, format
->alpha_size
, format
->alpha_offset
)
4195 case WINED3DFMT_P8_UINT
:
4196 float_colors
[0].r
= 0.0f
;
4197 float_colors
[0].g
= 0.0f
;
4198 float_colors
[0].b
= 0.0f
;
4199 float_colors
[0].a
= (key
->color_space_low_value
- 0.5f
) / 255.0f
;
4201 float_colors
[1].r
= 0.0f
;
4202 float_colors
[1].g
= 0.0f
;
4203 float_colors
[1].b
= 0.0f
;
4204 float_colors
[1].a
= (key
->color_space_high_value
+ 0.5f
) / 255.0f
;
4208 ERR("Unhandled color key to float conversion for format %s.\n", debug_d3dformat(format
->id
));
4212 /* DirectDraw stuff */
4213 enum wined3d_format_id
pixelformat_for_depth(DWORD depth
)
4217 case 8: return WINED3DFMT_P8_UINT
;
4218 case 15: return WINED3DFMT_B5G5R5X1_UNORM
;
4219 case 16: return WINED3DFMT_B5G6R5_UNORM
;
4220 case 24: return WINED3DFMT_B8G8R8X8_UNORM
; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
4221 case 32: return WINED3DFMT_B8G8R8X8_UNORM
; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
4222 default: return WINED3DFMT_UNKNOWN
;
4226 void multiply_matrix(struct wined3d_matrix
*dst
, const struct wined3d_matrix
*src1
, const struct wined3d_matrix
*src2
)
4228 struct wined3d_matrix tmp
;
4230 /* Now do the multiplication 'by hand'.
4231 I know that all this could be optimised, but this will be done later :-) */
4232 tmp
._11
= (src1
->_11
* src2
->_11
) + (src1
->_21
* src2
->_12
) + (src1
->_31
* src2
->_13
) + (src1
->_41
* src2
->_14
);
4233 tmp
._21
= (src1
->_11
* src2
->_21
) + (src1
->_21
* src2
->_22
) + (src1
->_31
* src2
->_23
) + (src1
->_41
* src2
->_24
);
4234 tmp
._31
= (src1
->_11
* src2
->_31
) + (src1
->_21
* src2
->_32
) + (src1
->_31
* src2
->_33
) + (src1
->_41
* src2
->_34
);
4235 tmp
._41
= (src1
->_11
* src2
->_41
) + (src1
->_21
* src2
->_42
) + (src1
->_31
* src2
->_43
) + (src1
->_41
* src2
->_44
);
4237 tmp
._12
= (src1
->_12
* src2
->_11
) + (src1
->_22
* src2
->_12
) + (src1
->_32
* src2
->_13
) + (src1
->_42
* src2
->_14
);
4238 tmp
._22
= (src1
->_12
* src2
->_21
) + (src1
->_22
* src2
->_22
) + (src1
->_32
* src2
->_23
) + (src1
->_42
* src2
->_24
);
4239 tmp
._32
= (src1
->_12
* src2
->_31
) + (src1
->_22
* src2
->_32
) + (src1
->_32
* src2
->_33
) + (src1
->_42
* src2
->_34
);
4240 tmp
._42
= (src1
->_12
* src2
->_41
) + (src1
->_22
* src2
->_42
) + (src1
->_32
* src2
->_43
) + (src1
->_42
* src2
->_44
);
4242 tmp
._13
= (src1
->_13
* src2
->_11
) + (src1
->_23
* src2
->_12
) + (src1
->_33
* src2
->_13
) + (src1
->_43
* src2
->_14
);
4243 tmp
._23
= (src1
->_13
* src2
->_21
) + (src1
->_23
* src2
->_22
) + (src1
->_33
* src2
->_23
) + (src1
->_43
* src2
->_24
);
4244 tmp
._33
= (src1
->_13
* src2
->_31
) + (src1
->_23
* src2
->_32
) + (src1
->_33
* src2
->_33
) + (src1
->_43
* src2
->_34
);
4245 tmp
._43
= (src1
->_13
* src2
->_41
) + (src1
->_23
* src2
->_42
) + (src1
->_33
* src2
->_43
) + (src1
->_43
* src2
->_44
);
4247 tmp
._14
= (src1
->_14
* src2
->_11
) + (src1
->_24
* src2
->_12
) + (src1
->_34
* src2
->_13
) + (src1
->_44
* src2
->_14
);
4248 tmp
._24
= (src1
->_14
* src2
->_21
) + (src1
->_24
* src2
->_22
) + (src1
->_34
* src2
->_23
) + (src1
->_44
* src2
->_24
);
4249 tmp
._34
= (src1
->_14
* src2
->_31
) + (src1
->_24
* src2
->_32
) + (src1
->_34
* src2
->_33
) + (src1
->_44
* src2
->_34
);
4250 tmp
._44
= (src1
->_14
* src2
->_41
) + (src1
->_24
* src2
->_42
) + (src1
->_34
* src2
->_43
) + (src1
->_44
* src2
->_44
);
4255 DWORD
get_flexible_vertex_size(DWORD d3dvtVertexType
) {
4258 int numTextures
= (d3dvtVertexType
& WINED3DFVF_TEXCOUNT_MASK
) >> WINED3DFVF_TEXCOUNT_SHIFT
;
4260 if (d3dvtVertexType
& WINED3DFVF_NORMAL
) size
+= 3 * sizeof(float);
4261 if (d3dvtVertexType
& WINED3DFVF_DIFFUSE
) size
+= sizeof(DWORD
);
4262 if (d3dvtVertexType
& WINED3DFVF_SPECULAR
) size
+= sizeof(DWORD
);
4263 if (d3dvtVertexType
& WINED3DFVF_PSIZE
) size
+= sizeof(DWORD
);
4264 switch (d3dvtVertexType
& WINED3DFVF_POSITION_MASK
) {
4265 case WINED3DFVF_XYZ
: size
+= 3 * sizeof(float); break;
4266 case WINED3DFVF_XYZRHW
: size
+= 4 * sizeof(float); break;
4267 case WINED3DFVF_XYZB1
: size
+= 4 * sizeof(float); break;
4268 case WINED3DFVF_XYZB2
: size
+= 5 * sizeof(float); break;
4269 case WINED3DFVF_XYZB3
: size
+= 6 * sizeof(float); break;
4270 case WINED3DFVF_XYZB4
: size
+= 7 * sizeof(float); break;
4271 case WINED3DFVF_XYZB5
: size
+= 8 * sizeof(float); break;
4272 case WINED3DFVF_XYZW
: size
+= 4 * sizeof(float); break;
4273 default: ERR("Unexpected position mask\n");
4275 for (i
= 0; i
< numTextures
; i
++) {
4276 size
+= GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType
, i
) * sizeof(float);
4282 unsigned int wined3d_max_compat_varyings(const struct wined3d_gl_info
*gl_info
)
4284 /* On core profile we have to also count diffuse and specular colors and the
4285 * fog coordinate. */
4286 return gl_info
->supported
[WINED3D_GL_LEGACY_CONTEXT
] ? MAX_TEXTURES
* 4 : (MAX_TEXTURES
+ 2) * 4 + 1;
4289 void gen_ffp_frag_op(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4290 struct ffp_frag_settings
*settings
, BOOL ignore_textype
)
4295 static const unsigned char args
[WINED3D_TOP_LERP
+ 1] =
4298 /* D3DTOP_DISABLE */ 0,
4299 /* D3DTOP_SELECTARG1 */ ARG1
,
4300 /* D3DTOP_SELECTARG2 */ ARG2
,
4301 /* D3DTOP_MODULATE */ ARG1
| ARG2
,
4302 /* D3DTOP_MODULATE2X */ ARG1
| ARG2
,
4303 /* D3DTOP_MODULATE4X */ ARG1
| ARG2
,
4304 /* D3DTOP_ADD */ ARG1
| ARG2
,
4305 /* D3DTOP_ADDSIGNED */ ARG1
| ARG2
,
4306 /* D3DTOP_ADDSIGNED2X */ ARG1
| ARG2
,
4307 /* D3DTOP_SUBTRACT */ ARG1
| ARG2
,
4308 /* D3DTOP_ADDSMOOTH */ ARG1
| ARG2
,
4309 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1
| ARG2
,
4310 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1
| ARG2
,
4311 /* D3DTOP_BLENDFACTORALPHA */ ARG1
| ARG2
,
4312 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1
| ARG2
,
4313 /* D3DTOP_BLENDCURRENTALPHA */ ARG1
| ARG2
,
4314 /* D3DTOP_PREMODULATE */ ARG1
| ARG2
,
4315 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1
| ARG2
,
4316 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1
| ARG2
,
4317 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1
| ARG2
,
4318 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1
| ARG2
,
4319 /* D3DTOP_BUMPENVMAP */ ARG1
| ARG2
,
4320 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1
| ARG2
,
4321 /* D3DTOP_DOTPRODUCT3 */ ARG1
| ARG2
,
4322 /* D3DTOP_MULTIPLYADD */ ARG1
| ARG2
| ARG0
,
4323 /* D3DTOP_LERP */ ARG1
| ARG2
| ARG0
4327 DWORD cop
, aop
, carg0
, carg1
, carg2
, aarg0
, aarg1
, aarg2
;
4328 unsigned int rt_fmt_flags
= state
->fb
->render_targets
[0]->format_flags
;
4329 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
4330 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
4332 settings
->padding
= 0;
4334 for (i
= 0; i
< d3d_info
->limits
.ffp_blend_stages
; ++i
)
4336 const struct wined3d_texture
*texture
;
4338 settings
->op
[i
].padding
= 0;
4339 if (state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
] == WINED3D_TOP_DISABLE
)
4341 settings
->op
[i
].cop
= WINED3D_TOP_DISABLE
;
4342 settings
->op
[i
].aop
= WINED3D_TOP_DISABLE
;
4343 settings
->op
[i
].carg0
= settings
->op
[i
].carg1
= settings
->op
[i
].carg2
= ARG_UNUSED
;
4344 settings
->op
[i
].aarg0
= settings
->op
[i
].aarg1
= settings
->op
[i
].aarg2
= ARG_UNUSED
;
4345 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
4346 settings
->op
[i
].dst
= resultreg
;
4347 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
4348 settings
->op
[i
].projected
= proj_none
;
4353 if ((texture
= state
->textures
[i
]))
4355 settings
->op
[i
].color_fixup
= texture
->resource
.format
->color_fixup
;
4358 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
4362 switch (texture
->target
)
4365 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
4368 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_2D
;
4371 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_3D
;
4373 case GL_TEXTURE_CUBE_MAP_ARB
:
4374 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_CUBE
;
4376 case GL_TEXTURE_RECTANGLE_ARB
:
4377 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_RECT
;
4382 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
4383 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
4386 cop
= state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
];
4387 aop
= state
->texture_states
[i
][WINED3D_TSS_ALPHA_OP
];
4389 carg1
= (args
[cop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG1
] : ARG_UNUSED
;
4390 carg2
= (args
[cop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG2
] : ARG_UNUSED
;
4391 carg0
= (args
[cop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG0
] : ARG_UNUSED
;
4393 if (is_invalid_op(state
, i
, cop
, carg1
, carg2
, carg0
))
4397 carg1
= WINED3DTA_CURRENT
;
4398 cop
= WINED3D_TOP_SELECT_ARG1
;
4401 if (cop
== WINED3D_TOP_DOTPRODUCT3
)
4403 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
4404 * the color result to the alpha component of the destination
4413 aarg1
= (args
[aop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG1
] : ARG_UNUSED
;
4414 aarg2
= (args
[aop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG2
] : ARG_UNUSED
;
4415 aarg0
= (args
[aop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG0
] : ARG_UNUSED
;
4418 if (!i
&& state
->textures
[0] && state
->render_states
[WINED3D_RS_COLORKEYENABLE
])
4420 GLenum texture_dimensions
;
4422 texture
= state
->textures
[0];
4423 texture_dimensions
= texture
->target
;
4425 if (texture_dimensions
== GL_TEXTURE_2D
|| texture_dimensions
== GL_TEXTURE_RECTANGLE_ARB
)
4427 if (texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
&& !texture
->resource
.format
->alpha_size
)
4429 if (aop
== WINED3D_TOP_DISABLE
)
4431 aarg1
= WINED3DTA_TEXTURE
;
4432 aop
= WINED3D_TOP_SELECT_ARG1
;
4434 else if (aop
== WINED3D_TOP_SELECT_ARG1
&& aarg1
!= WINED3DTA_TEXTURE
)
4436 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
])
4438 aarg2
= WINED3DTA_TEXTURE
;
4439 aop
= WINED3D_TOP_MODULATE
;
4441 else aarg1
= WINED3DTA_TEXTURE
;
4443 else if (aop
== WINED3D_TOP_SELECT_ARG2
&& aarg2
!= WINED3DTA_TEXTURE
)
4445 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
])
4447 aarg1
= WINED3DTA_TEXTURE
;
4448 aop
= WINED3D_TOP_MODULATE
;
4450 else aarg2
= WINED3DTA_TEXTURE
;
4456 if (is_invalid_op(state
, i
, aop
, aarg1
, aarg2
, aarg0
))
4460 aarg1
= WINED3DTA_CURRENT
;
4461 aop
= WINED3D_TOP_SELECT_ARG1
;
4464 if (carg1
== WINED3DTA_TEXTURE
|| carg2
== WINED3DTA_TEXTURE
|| carg0
== WINED3DTA_TEXTURE
4465 || aarg1
== WINED3DTA_TEXTURE
|| aarg2
== WINED3DTA_TEXTURE
|| aarg0
== WINED3DTA_TEXTURE
)
4467 ttff
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
4468 if (ttff
== (WINED3D_TTFF_PROJECTED
| WINED3D_TTFF_COUNT3
))
4469 settings
->op
[i
].projected
= proj_count3
;
4470 else if (ttff
& WINED3D_TTFF_PROJECTED
)
4471 settings
->op
[i
].projected
= proj_count4
;
4473 settings
->op
[i
].projected
= proj_none
;
4477 settings
->op
[i
].projected
= proj_none
;
4480 settings
->op
[i
].cop
= cop
;
4481 settings
->op
[i
].aop
= aop
;
4482 settings
->op
[i
].carg0
= carg0
;
4483 settings
->op
[i
].carg1
= carg1
;
4484 settings
->op
[i
].carg2
= carg2
;
4485 settings
->op
[i
].aarg0
= aarg0
;
4486 settings
->op
[i
].aarg1
= aarg1
;
4487 settings
->op
[i
].aarg2
= aarg2
;
4489 if (state
->texture_states
[i
][WINED3D_TSS_RESULT_ARG
] == WINED3DTA_TEMP
)
4490 settings
->op
[i
].dst
= tempreg
;
4492 settings
->op
[i
].dst
= resultreg
;
4495 /* Clear unsupported stages */
4496 for(; i
< MAX_TEXTURES
; i
++) {
4497 memset(&settings
->op
[i
], 0xff, sizeof(settings
->op
[i
]));
4500 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
4502 settings
->fog
= WINED3D_FFP_PS_FOG_OFF
;
4504 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
)
4506 if (use_vs(state
) || state
->vertex_declaration
->position_transformed
)
4508 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
4512 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
4514 case WINED3D_FOG_NONE
:
4515 case WINED3D_FOG_LINEAR
:
4516 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
4518 case WINED3D_FOG_EXP
:
4519 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
4521 case WINED3D_FOG_EXP2
:
4522 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
4529 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
4531 case WINED3D_FOG_LINEAR
:
4532 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
4534 case WINED3D_FOG_EXP
:
4535 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
4537 case WINED3D_FOG_EXP2
:
4538 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
4542 if (!gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
]
4543 && state
->render_states
[WINED3D_RS_SRGBWRITEENABLE
]
4544 && rt_fmt_flags
& WINED3DFMT_FLAG_SRGB_WRITE
)
4546 settings
->sRGB_write
= 1;
4548 settings
->sRGB_write
= 0;
4550 if (d3d_info
->vs_clipping
|| !use_vs(state
) || !state
->render_states
[WINED3D_RS_CLIPPING
]
4551 || !state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
])
4553 /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
4554 * the fixed function vertex pipeline is used(which always supports clipplanes), or
4555 * if no clipplane is enabled
4557 settings
->emul_clipplanes
= 0;
4559 settings
->emul_clipplanes
= 1;
4562 if (state
->render_states
[WINED3D_RS_COLORKEYENABLE
] && state
->textures
[0]
4563 && state
->textures
[0]->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
4564 && settings
->op
[0].cop
!= WINED3D_TOP_DISABLE
)
4565 settings
->color_key_enabled
= 1;
4567 settings
->color_key_enabled
= 0;
4569 /* texcoords_initialized is set to meaningful values only when GL doesn't
4570 * support enough varyings to always pass around all the possible texture
4572 * This is used to avoid reading a varying not written by the vertex shader.
4573 * Reading uninitialized varyings on core profile contexts results in an
4574 * error while with builtin varyings on legacy contexts you get undefined
4576 if (d3d_info
->limits
.varying_count
4577 && d3d_info
->limits
.varying_count
< wined3d_max_compat_varyings(gl_info
))
4579 settings
->texcoords_initialized
= 0;
4580 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
4584 if (state
->shader
[WINED3D_SHADER_TYPE_VERTEX
]->reg_maps
.output_registers
& (1u << i
))
4585 settings
->texcoords_initialized
|= 1u << i
;
4589 const struct wined3d_stream_info
*si
= &context
->stream_info
;
4590 unsigned int coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
4591 if ((state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
] >> WINED3D_FFP_TCI_SHIFT
)
4592 & WINED3D_FFP_TCI_MASK
4593 || (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
)))))
4594 settings
->texcoords_initialized
|= 1u << i
;
4600 settings
->texcoords_initialized
= (1u << MAX_TEXTURES
) - 1;
4603 settings
->pointsprite
= state
->render_states
[WINED3D_RS_POINTSPRITEENABLE
]
4604 && state
->gl_primitive_type
== GL_POINTS
;
4606 if (d3d_info
->emulated_flatshading
)
4607 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
4609 settings
->flatshading
= FALSE
;
4612 const struct ffp_frag_desc
*find_ffp_frag_shader(const struct wine_rb_tree
*fragment_shaders
,
4613 const struct ffp_frag_settings
*settings
)
4615 struct wine_rb_entry
*entry
= wine_rb_get(fragment_shaders
, settings
);
4616 return entry
? WINE_RB_ENTRY_VALUE(entry
, struct ffp_frag_desc
, entry
) : NULL
;
4619 void add_ffp_frag_shader(struct wine_rb_tree
*shaders
, struct ffp_frag_desc
*desc
)
4621 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
4622 * whereas desc points to an extended structure with implementation specific parts. */
4623 if (wine_rb_put(shaders
, &desc
->settings
, &desc
->entry
) == -1)
4625 ERR("Failed to insert ffp frag shader.\n");
4629 /* Activates the texture dimension according to the bound D3D texture. Does
4630 * not care for the colorop or correct gl texture unit (when using nvrc).
4631 * Requires the caller to activate the correct unit. */
4632 /* Context activation is done by the caller (state handler). */
4633 void texture_activate_dimensions(const struct wined3d_texture
*texture
, const struct wined3d_gl_info
*gl_info
)
4637 switch (texture
->target
)
4640 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
4641 checkGLcall("glDisable(GL_TEXTURE_3D)");
4642 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
4644 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
4645 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
4647 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
4649 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
4650 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
4652 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
4653 checkGLcall("glEnable(GL_TEXTURE_2D)");
4655 case GL_TEXTURE_RECTANGLE_ARB
:
4656 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
4657 checkGLcall("glDisable(GL_TEXTURE_2D)");
4658 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
4659 checkGLcall("glDisable(GL_TEXTURE_3D)");
4660 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
4662 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
4663 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
4665 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_RECTANGLE_ARB
);
4666 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
4669 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
4671 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
4672 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
4674 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
4676 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
4677 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
4679 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
4680 checkGLcall("glDisable(GL_TEXTURE_2D)");
4681 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_3D
);
4682 checkGLcall("glEnable(GL_TEXTURE_3D)");
4684 case GL_TEXTURE_CUBE_MAP_ARB
:
4685 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
4686 checkGLcall("glDisable(GL_TEXTURE_2D)");
4687 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
4688 checkGLcall("glDisable(GL_TEXTURE_3D)");
4689 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
4691 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
4692 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
4694 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
4695 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
4701 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
4702 checkGLcall("glEnable(GL_TEXTURE_2D)");
4703 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
4704 checkGLcall("glDisable(GL_TEXTURE_3D)");
4705 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
4707 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
4708 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
4710 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
4712 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
4713 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
4715 /* Binding textures is done by samplers. A dummy texture will be bound */
4719 /* Context activation is done by the caller (state handler). */
4720 void sampler_texdim(struct wined3d_context
*context
, const struct wined3d_state
*state
, DWORD state_id
)
4722 DWORD sampler
= state_id
- STATE_SAMPLER(0);
4723 DWORD mapped_stage
= context
->tex_unit_map
[sampler
];
4725 /* No need to enable / disable anything here for unused samplers. The
4726 * tex_colorop handler takes care. Also no action is needed with pixel
4727 * shaders, or if tex_colorop will take care of this business. */
4728 if (mapped_stage
== WINED3D_UNMAPPED_STAGE
|| mapped_stage
>= context
->gl_info
->limits
.textures
)
4730 if (sampler
>= context
->lowest_disabled_stage
)
4732 if (isStateDirty(context
, STATE_TEXTURESTAGE(sampler
, WINED3D_TSS_COLOR_OP
)))
4735 texture_activate_dimensions(state
->textures
[sampler
], context
->gl_info
);
4738 void *wined3d_rb_alloc(size_t size
)
4740 return HeapAlloc(GetProcessHeap(), 0, size
);
4743 void *wined3d_rb_realloc(void *ptr
, size_t size
)
4745 return HeapReAlloc(GetProcessHeap(), 0, ptr
, size
);
4748 void wined3d_rb_free(void *ptr
)
4750 HeapFree(GetProcessHeap(), 0, ptr
);
4753 static int ffp_frag_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
4755 const struct ffp_frag_settings
*ka
= key
;
4756 const struct ffp_frag_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
, const struct ffp_frag_desc
, entry
)->settings
;
4758 return memcmp(ka
, kb
, sizeof(*ka
));
4761 const struct wine_rb_functions wined3d_ffp_frag_program_rb_functions
=
4766 ffp_frag_program_key_compare
,
4769 void wined3d_ffp_get_vs_settings(const struct wined3d_context
*context
,
4770 const struct wined3d_state
*state
, struct wined3d_ffp_vs_settings
*settings
)
4772 const struct wined3d_stream_info
*si
= &context
->stream_info
;
4773 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
4774 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
4775 unsigned int coord_idx
, i
;
4777 if (si
->position_transformed
)
4779 memset(settings
, 0, sizeof(*settings
));
4781 settings
->transformed
= 1;
4782 settings
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
4783 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
4784 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
4785 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
4786 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
4787 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
4789 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
4791 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
4793 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
4794 if (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
4795 settings
->texcoords
|= 1u << i
;
4796 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
4798 if (d3d_info
->limits
.varying_count
>= wined3d_max_compat_varyings(gl_info
))
4799 settings
->texcoords
= (1u << MAX_TEXTURES
) - 1;
4801 if (d3d_info
->emulated_flatshading
)
4802 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
4804 settings
->flatshading
= FALSE
;
4809 switch (state
->render_states
[WINED3D_RS_VERTEXBLEND
])
4811 case WINED3D_VBF_DISABLE
:
4812 case WINED3D_VBF_1WEIGHTS
:
4813 case WINED3D_VBF_2WEIGHTS
:
4814 case WINED3D_VBF_3WEIGHTS
:
4815 settings
->vertexblends
= state
->render_states
[WINED3D_RS_VERTEXBLEND
];
4818 FIXME("Unsupported vertex blending: %d\n", state
->render_states
[WINED3D_RS_VERTEXBLEND
]);
4822 settings
->transformed
= 0;
4823 settings
->clipping
= state
->render_states
[WINED3D_RS_CLIPPING
]
4824 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
4825 settings
->normal
= !!(si
->use_map
& (1u << WINED3D_FFP_NORMAL
));
4826 settings
->normalize
= settings
->normal
&& state
->render_states
[WINED3D_RS_NORMALIZENORMALS
];
4827 settings
->lighting
= !!state
->render_states
[WINED3D_RS_LIGHTING
];
4828 settings
->localviewer
= !!state
->render_states
[WINED3D_RS_LOCALVIEWER
];
4829 settings
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
4830 settings
->per_vertex_point_size
= !!(si
->use_map
& 1u << WINED3D_FFP_PSIZE
);
4832 if (state
->render_states
[WINED3D_RS_COLORVERTEX
] && (si
->use_map
& (1u << WINED3D_FFP_DIFFUSE
)))
4834 settings
->diffuse_source
= state
->render_states
[WINED3D_RS_DIFFUSEMATERIALSOURCE
];
4835 settings
->emissive_source
= state
->render_states
[WINED3D_RS_EMISSIVEMATERIALSOURCE
];
4836 settings
->ambient_source
= state
->render_states
[WINED3D_RS_AMBIENTMATERIALSOURCE
];
4837 settings
->specular_source
= state
->render_states
[WINED3D_RS_SPECULARMATERIALSOURCE
];
4841 settings
->diffuse_source
= WINED3D_MCS_MATERIAL
;
4842 settings
->emissive_source
= WINED3D_MCS_MATERIAL
;
4843 settings
->ambient_source
= WINED3D_MCS_MATERIAL
;
4844 settings
->specular_source
= WINED3D_MCS_MATERIAL
;
4847 settings
->texcoords
= 0;
4848 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
4850 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
4851 if (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1u << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
4852 settings
->texcoords
|= 1u << i
;
4853 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
4855 if (d3d_info
->limits
.varying_count
>= wined3d_max_compat_varyings(gl_info
))
4856 settings
->texcoords
= (1u << MAX_TEXTURES
) - 1;
4858 settings
->light_type
= 0;
4859 for (i
= 0; i
< MAX_ACTIVE_LIGHTS
; ++i
)
4861 if (state
->lights
[i
])
4862 settings
->light_type
|= (state
->lights
[i
]->OriginalParms
.type
4863 & WINED3D_FFP_LIGHT_TYPE_MASK
) << WINED3D_FFP_LIGHT_TYPE_SHIFT(i
);
4866 settings
->ortho_fog
= 0;
4867 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
4868 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
4869 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
4871 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
4873 if (state
->transforms
[WINED3D_TS_PROJECTION
]._14
== 0.0f
4874 && state
->transforms
[WINED3D_TS_PROJECTION
]._24
== 0.0f
4875 && state
->transforms
[WINED3D_TS_PROJECTION
]._34
== 0.0f
4876 && state
->transforms
[WINED3D_TS_PROJECTION
]._44
== 1.0f
)
4877 settings
->ortho_fog
= 1;
4879 else if (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
] == WINED3D_FOG_NONE
)
4880 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
4881 else if (state
->render_states
[WINED3D_RS_RANGEFOGENABLE
])
4882 settings
->fog_mode
= WINED3D_FFP_VS_FOG_RANGE
;
4884 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
4886 if (d3d_info
->emulated_flatshading
)
4887 settings
->flatshading
= state
->render_states
[WINED3D_RS_SHADEMODE
] == WINED3D_SHADE_FLAT
;
4889 settings
->flatshading
= FALSE
;
4891 settings
->padding
= 0;
4894 static int wined3d_ffp_vertex_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
4896 const struct wined3d_ffp_vs_settings
*ka
= key
;
4897 const struct wined3d_ffp_vs_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
,
4898 const struct wined3d_ffp_vs_desc
, entry
)->settings
;
4900 return memcmp(ka
, kb
, sizeof(*ka
));
4903 const struct wine_rb_functions wined3d_ffp_vertex_program_rb_functions
=
4908 wined3d_ffp_vertex_program_key_compare
,
4911 const struct blit_shader
*wined3d_select_blitter(const struct wined3d_gl_info
*gl_info
,
4912 const struct wined3d_d3d_info
*d3d_info
, enum wined3d_blit_op blit_op
,
4913 const RECT
*src_rect
, DWORD src_usage
, enum wined3d_pool src_pool
, const struct wined3d_format
*src_format
,
4914 const RECT
*dst_rect
, DWORD dst_usage
, enum wined3d_pool dst_pool
, const struct wined3d_format
*dst_format
)
4916 static const struct blit_shader
* const blitters
[] =
4924 for (i
= 0; i
< sizeof(blitters
) / sizeof(*blitters
); ++i
)
4926 if (blitters
[i
]->blit_supported(gl_info
, d3d_info
, blit_op
,
4927 src_rect
, src_usage
, src_pool
, src_format
,
4928 dst_rect
, dst_usage
, dst_pool
, dst_format
))
4935 void wined3d_get_draw_rect(const struct wined3d_state
*state
, RECT
*rect
)
4937 const struct wined3d_viewport
*vp
= &state
->viewport
;
4939 SetRect(rect
, vp
->x
, vp
->y
, vp
->x
+ vp
->width
, vp
->y
+ vp
->height
);
4941 if (state
->render_states
[WINED3D_RS_SCISSORTESTENABLE
])
4942 IntersectRect(rect
, rect
, &state
->scissor_rect
);
4945 const char *wined3d_debug_location(DWORD location
)
4950 #define LOCATION_TO_STR(u) if (location & u) { strcat(buf, " | "#u); location &= ~u; }
4951 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED
);
4952 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM
);
4953 LOCATION_TO_STR(WINED3D_LOCATION_USER_MEMORY
);
4954 LOCATION_TO_STR(WINED3D_LOCATION_DIB
);
4955 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER
);
4956 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB
);
4957 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB
);
4958 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE
);
4959 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE
);
4960 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED
);
4961 #undef LOCATION_TO_STR
4962 if (location
) FIXME("Unrecognized location flag(s) %#x.\n", location
);
4964 return buf
[0] ? wine_dbg_sprintf("%s", &buf
[3]) : "0";
4967 /* Print a floating point value with the %.8e format specifier, always using
4968 * '.' as decimal separator. */
4969 void wined3d_ftoa(float value
, char *s
)
4973 if (copysignf(1.0f
, value
) < 0.0f
)
4976 /* Be sure to allocate a buffer of at least 17 characters for the result
4977 as sprintf may return a 3 digit exponent when using the MSVC runtime
4978 instead of a 2 digit exponent. */
4979 sprintf(s
, "%.8e", value
);
4980 if (isfinite(value
))
4984 void wined3d_release_dc(HWND window
, HDC dc
)
4986 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
4987 * However, that's not what actually happens, and there are user32 tests
4988 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
4989 * So explicitly check that the DC belongs to the window, since we want to
4990 * avoid releasing a DC that belongs to some other window if the original
4991 * window was already destroyed. */
4992 if (WindowFromDC(dc
) != window
)
4993 WARN("DC %p does not belong to window %p.\n", dc
, window
);
4994 else if (!ReleaseDC(window
, dc
))
4995 ERR("Failed to release device context %p, last error %#x.\n", dc
, GetLastError());