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
27 #include "wined3d_private.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(d3d
);
31 struct wined3d_format_channels
33 enum wined3d_format_id id
;
34 DWORD red_size
, green_size
, blue_size
, alpha_size
;
35 DWORD red_offset
, green_offset
, blue_offset
, alpha_offset
;
37 BYTE depth_size
, stencil_size
;
40 static const struct wined3d_format_channels formats
[] =
43 * format id r g b a r g b a bpp depth stencil */
44 {WINED3DFMT_UNKNOWN
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
46 {WINED3DFMT_UYVY
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
47 {WINED3DFMT_YUY2
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
48 {WINED3DFMT_YV12
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
49 {WINED3DFMT_NV12
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
50 {WINED3DFMT_DXT1
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
51 {WINED3DFMT_DXT2
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
52 {WINED3DFMT_DXT3
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
53 {WINED3DFMT_DXT4
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
54 {WINED3DFMT_DXT5
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
55 {WINED3DFMT_MULTI2_ARGB8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
56 {WINED3DFMT_G8R8_G8B8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
57 {WINED3DFMT_R8G8_B8G8
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
59 {WINED3DFMT_R32_FLOAT
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
60 {WINED3DFMT_R32G32_FLOAT
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
61 {WINED3DFMT_R32G32B32_FLOAT
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
62 {WINED3DFMT_R32G32B32A32_FLOAT
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
64 {WINED3DFMT_R8G8_SNORM_Cx
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
66 {WINED3DFMT_R16_FLOAT
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
67 {WINED3DFMT_R16G16_FLOAT
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
68 {WINED3DFMT_R16G16_SINT
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
69 {WINED3DFMT_R16G16B16A16_FLOAT
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
70 {WINED3DFMT_R16G16B16A16_SINT
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
71 /* Palettized formats */
72 {WINED3DFMT_P8_UINT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
73 {WINED3DFMT_P8_UINT
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
74 /* Standard ARGB formats. */
75 {WINED3DFMT_B8G8R8_UNORM
, 8, 8, 8, 0, 16, 8, 0, 0, 3, 0, 0},
76 {WINED3DFMT_B8G8R8A8_UNORM
, 8, 8, 8, 8, 16, 8, 0, 24, 4, 0, 0},
77 {WINED3DFMT_B8G8R8X8_UNORM
, 8, 8, 8, 0, 16, 8, 0, 0, 4, 0, 0},
78 {WINED3DFMT_B5G6R5_UNORM
, 5, 6, 5, 0, 11, 5, 0, 0, 2, 0, 0},
79 {WINED3DFMT_B5G5R5X1_UNORM
, 5, 5, 5, 0, 10, 5, 0, 0, 2, 0, 0},
80 {WINED3DFMT_B5G5R5A1_UNORM
, 5, 5, 5, 1, 10, 5, 0, 15, 2, 0, 0},
81 {WINED3DFMT_B4G4R4A4_UNORM
, 4, 4, 4, 4, 8, 4, 0, 12, 2, 0, 0},
82 {WINED3DFMT_B2G3R3_UNORM
, 3, 3, 2, 0, 5, 2, 0, 0, 1, 0, 0},
83 {WINED3DFMT_R8_UNORM
, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
84 {WINED3DFMT_A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 0, 1, 0, 0},
85 {WINED3DFMT_B2G3R3A8_UNORM
, 3, 3, 2, 8, 5, 2, 0, 8, 2, 0, 0},
86 {WINED3DFMT_B4G4R4X4_UNORM
, 4, 4, 4, 0, 8, 4, 0, 0, 2, 0, 0},
87 {WINED3DFMT_R10G10B10A2_UNORM
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
88 {WINED3DFMT_R10G10B10A2_UINT
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
89 {WINED3DFMT_R10G10B10A2_SNORM
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
90 {WINED3DFMT_R8G8B8A8_UNORM
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
91 {WINED3DFMT_R8G8B8A8_UINT
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
92 {WINED3DFMT_R8G8B8X8_UNORM
, 8, 8, 8, 0, 0, 8, 16, 0, 4, 0, 0},
93 {WINED3DFMT_R16G16_UNORM
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
94 {WINED3DFMT_B10G10R10A2_UNORM
, 10, 10, 10, 2, 20, 10, 0, 30, 4, 0, 0},
95 {WINED3DFMT_R16G16B16A16_UNORM
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
97 {WINED3DFMT_L8_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
98 {WINED3DFMT_L8A8_UNORM
, 0, 0, 0, 8, 0, 0, 0, 8, 2, 0, 0},
99 {WINED3DFMT_L4A4_UNORM
, 0, 0, 0, 4, 0, 0, 0, 4, 1, 0, 0},
100 {WINED3DFMT_L16_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
101 /* Bump mapping stuff */
102 {WINED3DFMT_R8G8_SNORM
, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
103 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, 5, 5, 0, 0, 0, 5, 0, 0, 2, 0, 0},
104 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, 8, 8, 0, 0, 0, 8, 0, 0, 4, 0, 0},
105 {WINED3DFMT_R8G8B8A8_SNORM
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
106 {WINED3DFMT_R16G16_SNORM
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
107 {WINED3DFMT_R10G11B11_SNORM
, 10, 11, 11, 0, 0, 10, 21, 0, 4, 0, 0},
108 {WINED3DFMT_R10G10B10_SNORM_A2_UNORM
, 10, 10, 10, 2, 0, 10, 20, 30, 4, 0, 0},
109 /* Depth stencil formats */
110 {WINED3DFMT_D16_LOCKABLE
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
111 {WINED3DFMT_D32_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
112 {WINED3DFMT_S1_UINT_D15_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 15, 1},
113 {WINED3DFMT_D24_UNORM_S8_UINT
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
114 {WINED3DFMT_X8D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 0},
115 {WINED3DFMT_S4X4_UINT_D24_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 4},
116 {WINED3DFMT_D16_UNORM
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 16, 0},
117 {WINED3DFMT_D32_FLOAT
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 32, 0},
118 {WINED3DFMT_S8_UINT_D24_FLOAT
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
119 {WINED3DFMT_VERTEXDATA
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
120 {WINED3DFMT_R16_UINT
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
121 {WINED3DFMT_R32_UINT
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
122 {WINED3DFMT_R32G32_UINT
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
123 {WINED3DFMT_R32G32B32_UINT
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
124 {WINED3DFMT_R32G32B32A32_UINT
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
125 {WINED3DFMT_R16G16B16A16_SNORM
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
126 /* Vendor-specific formats */
127 {WINED3DFMT_ATI1N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
128 {WINED3DFMT_ATI2N
, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
129 {WINED3DFMT_NVDB
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
130 {WINED3DFMT_INST
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
131 {WINED3DFMT_INTZ
, 0, 0, 0, 0, 0, 0, 0, 0, 4, 24, 8},
132 {WINED3DFMT_RESZ
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
133 {WINED3DFMT_NVHU
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
134 {WINED3DFMT_NVHS
, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
135 {WINED3DFMT_NULL
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
136 /* Unsure about them, could not find a Windows driver that supports them */
137 {WINED3DFMT_R16
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
138 {WINED3DFMT_AL16
, 0, 0, 0, 16, 0, 0, 0, 16, 4, 0, 0},
140 {WINED3DFMT_R8_TYPELESS
, 8, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0},
141 {WINED3DFMT_R8G8_TYPELESS
, 8, 8, 0, 0, 0, 8, 0, 0, 2, 0, 0},
142 {WINED3DFMT_R8G8B8A8_TYPELESS
, 8, 8, 8, 8, 0, 8, 16, 24, 4, 0, 0},
143 {WINED3DFMT_R16_TYPELESS
, 16, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0},
144 {WINED3DFMT_R16G16_TYPELESS
, 16, 16, 0, 0, 0, 16, 0, 0, 4, 0, 0},
145 {WINED3DFMT_R16G16B16A16_TYPELESS
, 16, 16, 16, 16, 0, 16, 32, 48, 8, 0, 0},
146 {WINED3DFMT_R32_TYPELESS
, 32, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0},
147 {WINED3DFMT_R32G32_TYPELESS
, 32, 32, 0, 0, 0, 32, 0, 0, 8, 0, 0},
148 {WINED3DFMT_R32G32B32_TYPELESS
, 32, 32, 32, 0, 0, 32, 64, 0, 12, 0, 0},
149 {WINED3DFMT_R32G32B32A32_TYPELESS
, 32, 32, 32, 32, 0, 32, 64, 96, 16, 0, 0},
152 struct wined3d_format_base_flags
154 enum wined3d_format_id id
;
158 /* The ATI2N format behaves like an uncompressed format in LockRect(), but
159 * still needs to use the correct block based calculation for e.g. the
161 static const struct wined3d_format_base_flags format_base_flags
[] =
163 {WINED3DFMT_P8_UINT
, WINED3DFMT_FLAG_GETDC
},
164 {WINED3DFMT_B8G8R8_UNORM
, WINED3DFMT_FLAG_GETDC
},
165 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3DFMT_FLAG_GETDC
},
166 {WINED3DFMT_B8G8R8X8_UNORM
, WINED3DFMT_FLAG_GETDC
},
167 {WINED3DFMT_B5G6R5_UNORM
, WINED3DFMT_FLAG_GETDC
},
168 {WINED3DFMT_B5G5R5X1_UNORM
, WINED3DFMT_FLAG_GETDC
},
169 {WINED3DFMT_B5G5R5A1_UNORM
, WINED3DFMT_FLAG_GETDC
},
170 {WINED3DFMT_B4G4R4A4_UNORM
, WINED3DFMT_FLAG_GETDC
},
171 {WINED3DFMT_B4G4R4X4_UNORM
, WINED3DFMT_FLAG_GETDC
},
172 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3DFMT_FLAG_GETDC
},
173 {WINED3DFMT_R8G8B8X8_UNORM
, WINED3DFMT_FLAG_GETDC
},
174 {WINED3DFMT_ATI1N
, WINED3DFMT_FLAG_BROKEN_PITCH
},
175 {WINED3DFMT_ATI2N
, WINED3DFMT_FLAG_BROKEN_PITCH
},
176 {WINED3DFMT_R32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
177 {WINED3DFMT_R32G32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
178 {WINED3DFMT_R32G32B32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
179 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
180 {WINED3DFMT_R16_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
181 {WINED3DFMT_R16G16_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
182 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
183 {WINED3DFMT_D32_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
184 {WINED3DFMT_S8_UINT_D24_FLOAT
, WINED3DFMT_FLAG_FLOAT
},
187 struct wined3d_format_block_info
189 enum wined3d_format_id id
;
192 UINT block_byte_count
;
196 static const struct wined3d_format_block_info format_block_info
[] =
198 {WINED3DFMT_DXT1
, 4, 4, 8, TRUE
},
199 {WINED3DFMT_DXT2
, 4, 4, 16, TRUE
},
200 {WINED3DFMT_DXT3
, 4, 4, 16, TRUE
},
201 {WINED3DFMT_DXT4
, 4, 4, 16, TRUE
},
202 {WINED3DFMT_DXT5
, 4, 4, 16, TRUE
},
203 {WINED3DFMT_ATI1N
, 4, 4, 8, FALSE
},
204 {WINED3DFMT_ATI2N
, 4, 4, 16, FALSE
},
205 {WINED3DFMT_YUY2
, 2, 1, 4, FALSE
},
206 {WINED3DFMT_UYVY
, 2, 1, 4, FALSE
},
209 struct wined3d_format_vertex_info
211 enum wined3d_format_id id
;
212 enum wined3d_ffp_emit_idx emit_idx
;
213 GLint component_count
;
216 GLboolean gl_normalized
;
217 unsigned int component_size
;
220 static const struct wined3d_format_vertex_info format_vertex_info
[] =
222 {WINED3DFMT_R32_FLOAT
, WINED3D_FFP_EMIT_FLOAT1
, 1, GL_FLOAT
, 1, GL_FALSE
, sizeof(float)},
223 {WINED3DFMT_R32G32_FLOAT
, WINED3D_FFP_EMIT_FLOAT2
, 2, GL_FLOAT
, 2, GL_FALSE
, sizeof(float)},
224 {WINED3DFMT_R32G32B32_FLOAT
, WINED3D_FFP_EMIT_FLOAT3
, 3, GL_FLOAT
, 3, GL_FALSE
, sizeof(float)},
225 {WINED3DFMT_R32G32B32A32_FLOAT
, WINED3D_FFP_EMIT_FLOAT4
, 4, GL_FLOAT
, 4, GL_FALSE
, sizeof(float)},
226 {WINED3DFMT_B8G8R8A8_UNORM
, WINED3D_FFP_EMIT_D3DCOLOR
, 4, GL_UNSIGNED_BYTE
, 4, GL_TRUE
, sizeof(BYTE
)},
227 {WINED3DFMT_R8G8B8A8_UINT
, WINED3D_FFP_EMIT_UBYTE4
, 4, GL_UNSIGNED_BYTE
, 4, GL_FALSE
, sizeof(BYTE
)},
228 {WINED3DFMT_R16G16_SINT
, WINED3D_FFP_EMIT_SHORT2
, 2, GL_SHORT
, 2, GL_FALSE
, sizeof(short int)},
229 {WINED3DFMT_R16G16B16A16_SINT
, WINED3D_FFP_EMIT_SHORT4
, 4, GL_SHORT
, 4, GL_FALSE
, sizeof(short int)},
230 {WINED3DFMT_R8G8B8A8_UNORM
, WINED3D_FFP_EMIT_UBYTE4N
, 4, GL_UNSIGNED_BYTE
, 4, GL_TRUE
, sizeof(BYTE
)},
231 {WINED3DFMT_R16G16_SNORM
, WINED3D_FFP_EMIT_SHORT2N
, 2, GL_SHORT
, 2, GL_TRUE
, sizeof(short int)},
232 {WINED3DFMT_R16G16B16A16_SNORM
, WINED3D_FFP_EMIT_SHORT4N
, 4, GL_SHORT
, 4, GL_TRUE
, sizeof(short int)},
233 {WINED3DFMT_R16G16_UNORM
, WINED3D_FFP_EMIT_USHORT2N
, 2, GL_UNSIGNED_SHORT
, 2, GL_TRUE
, sizeof(short int)},
234 {WINED3DFMT_R16G16B16A16_UNORM
, WINED3D_FFP_EMIT_USHORT4N
, 4, GL_UNSIGNED_SHORT
, 4, GL_TRUE
, sizeof(short int)},
235 {WINED3DFMT_R10G10B10A2_UINT
, WINED3D_FFP_EMIT_UDEC3
, 3, GL_UNSIGNED_SHORT
, 3, GL_FALSE
, sizeof(short int)},
236 {WINED3DFMT_R10G10B10A2_SNORM
, WINED3D_FFP_EMIT_DEC3N
, 3, GL_SHORT
, 3, GL_TRUE
, sizeof(short int)},
237 {WINED3DFMT_R16G16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_2
, 2, GL_FLOAT
, 2, GL_FALSE
, sizeof(GLhalfNV
)},
238 {WINED3DFMT_R16G16B16A16_FLOAT
, WINED3D_FFP_EMIT_FLOAT16_4
, 4, GL_FLOAT
, 4, GL_FALSE
, sizeof(GLhalfNV
)},
239 {WINED3DFMT_R32_UINT
, WINED3D_FFP_EMIT_INVALID
, 1, GL_UNSIGNED_INT
, 1, GL_FALSE
, sizeof(UINT
)},
240 {WINED3DFMT_R32G32_UINT
, WINED3D_FFP_EMIT_INVALID
, 2, GL_UNSIGNED_INT
, 2, GL_FALSE
, sizeof(UINT
)},
241 {WINED3DFMT_R32G32B32_UINT
, WINED3D_FFP_EMIT_INVALID
, 3, GL_UNSIGNED_INT
, 3, GL_FALSE
, sizeof(UINT
)},
242 {WINED3DFMT_R32G32B32A32_UINT
, WINED3D_FFP_EMIT_INVALID
, 4, GL_UNSIGNED_INT
, 4, GL_FALSE
, sizeof(UINT
)},
245 struct wined3d_format_texture_info
247 enum wined3d_format_id id
;
249 GLint gl_srgb_internal
;
250 GLint gl_rt_internal
;
253 unsigned int conv_byte_count
;
255 enum wined3d_gl_extension extension
;
256 void (*convert
)(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
257 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
);
260 static void convert_l4a4_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
261 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
263 /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
264 * format+type combination to load it. Thus convert it to A8L8, then load it
265 * with A4L4 internal, but A8L8 format+type
267 unsigned int x
, y
, z
;
268 const unsigned char *Source
;
271 for (z
= 0; z
< depth
; z
++)
273 for (y
= 0; y
< height
; y
++)
275 Source
= src
+ z
* src_slice_pitch
+ y
* src_row_pitch
;
276 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
277 for (x
= 0; x
< width
; x
++ )
279 unsigned char color
= (*Source
++);
280 /* A */ Dest
[1] = (color
& 0xf0) << 0;
281 /* L */ Dest
[0] = (color
& 0x0f) << 4;
288 static void convert_r5g5_snorm_l6_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
289 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
291 unsigned int x
, y
, z
;
292 unsigned char r_in
, g_in
, l_in
;
293 const unsigned short *texel_in
;
294 unsigned short *texel_out
;
296 /* Emulating signed 5 bit values with unsigned 5 bit values has some precision problems by design:
297 * E.g. the signed input value 0 becomes 16. GL normalizes it to 16 / 31 = 0.516. We convert it
298 * back to a signed value by subtracting 0.5 and multiplying by 2.0. The resulting value is
299 * ((16 / 31) - 0.5) * 2.0 = 0.032, which is quite different from the intended result 0.000. */
300 for (z
= 0; z
< depth
; z
++)
302 for (y
= 0; y
< height
; y
++)
304 texel_out
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
305 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
306 for (x
= 0; x
< width
; x
++ )
308 l_in
= (*texel_in
& 0xfc00) >> 10;
309 g_in
= (*texel_in
& 0x03e0) >> 5;
310 r_in
= *texel_in
& 0x001f;
312 *texel_out
= ((r_in
+ 16) << 11) | (l_in
<< 5) | (g_in
+ 16);
320 static void convert_r5g5_snorm_l6_unorm_ext(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
321 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
323 unsigned int x
, y
, z
;
324 unsigned char *texel_out
, r_out
, g_out
, r_in
, g_in
, l_in
;
325 const unsigned short *texel_in
;
327 for (z
= 0; z
< depth
; z
++)
329 for (y
= 0; y
< height
; y
++)
331 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
332 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
333 for (x
= 0; x
< width
; x
++ )
335 l_in
= (*texel_in
& 0xfc00) >> 10;
336 g_in
= (*texel_in
& 0x03e0) >> 5;
337 r_in
= *texel_in
& 0x001f;
340 if (!(r_in
& 0x10)) /* r > 0 */
344 if (!(g_in
& 0x10)) /* g > 0 */
347 texel_out
[0] = r_out
;
348 texel_out
[1] = g_out
;
349 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
359 static void convert_r5g5_snorm_l6_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
360 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
362 unsigned int x
, y
, z
;
363 unsigned char *texel_out
, ds_out
, dt_out
, r_in
, g_in
, l_in
;
364 const unsigned short *texel_in
;
366 /* This makes the gl surface bigger(24 bit instead of 16), but it works with
367 * fixed function and shaders without further conversion once the surface is
370 * The difference between this function and convert_r5g5_snorm_l6_unorm_ext
371 * is that convert_r5g5_snorm_l6_unorm_ext creates a 32 bit XRGB texture and
372 * this function creates a 24 bit DSDT_MAG texture. Trying to load a DSDT_MAG
373 * internal with a 32 bit DSDT_MAG_INTENSITY or DSDT_MAG_VIB format fails. */
374 for (z
= 0; z
< depth
; z
++)
376 for (y
= 0; y
< height
; y
++)
378 texel_in
= (const unsigned short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
379 texel_out
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
380 for (x
= 0; x
< width
; x
++ )
382 l_in
= (*texel_in
& 0xfc00) >> 10;
383 g_in
= (*texel_in
& 0x03e0) >> 5;
384 r_in
= *texel_in
& 0x001f;
387 if (!(r_in
& 0x10)) /* r > 0 */
391 if (!(g_in
& 0x10)) /* g > 0 */
394 texel_out
[0] = ds_out
;
395 texel_out
[1] = dt_out
;
396 texel_out
[2] = l_in
<< 1 | l_in
>> 5;
405 static void convert_r8g8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
406 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
408 unsigned int x
, y
, z
;
412 for (z
= 0; z
< depth
; z
++)
414 for (y
= 0; y
< height
; y
++)
416 Source
= (const short *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
417 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
418 for (x
= 0; x
< width
; x
++ )
420 const short color
= (*Source
++);
421 /* B */ Dest
[0] = 0xff;
422 /* G */ Dest
[1] = (color
>> 8) + 128; /* V */
423 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
430 static void convert_r8g8_snorm_l8x8_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
431 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
433 unsigned int x
, y
, z
;
437 /* Doesn't work correctly with the fixed function pipeline, but can work in
438 * shaders if the shader is adjusted. (There's no use for this format in gl's
439 * standard fixed function pipeline anyway).
441 for (z
= 0; z
< depth
; z
++)
443 for (y
= 0; y
< height
; y
++)
445 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
446 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
447 for (x
= 0; x
< width
; x
++ )
449 LONG color
= (*Source
++);
450 /* B */ Dest
[0] = ((color
>> 16) & 0xff); /* L */
451 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
452 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
459 static void convert_r8g8_snorm_l8x8_unorm_nv(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
460 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
462 unsigned int x
, y
, z
;
466 /* This implementation works with the fixed function pipeline and shaders
467 * without further modification after converting the surface.
469 for (z
= 0; z
< depth
; z
++)
471 for (y
= 0; y
< height
; y
++)
473 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
474 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
475 for (x
= 0; x
< width
; x
++ )
477 LONG color
= (*Source
++);
478 /* L */ Dest
[2] = ((color
>> 16) & 0xff); /* L */
479 /* V */ Dest
[1] = ((color
>> 8 ) & 0xff); /* V */
480 /* U */ Dest
[0] = (color
& 0xff); /* U */
481 /* I */ Dest
[3] = 255; /* X */
488 static void convert_r8g8b8a8_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
489 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
491 unsigned int x
, y
, z
;
495 for (z
= 0; z
< depth
; z
++)
497 for (y
= 0; y
< height
; y
++)
499 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
500 Dest
= dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
;
501 for (x
= 0; x
< width
; x
++ )
503 LONG color
= (*Source
++);
504 /* B */ Dest
[0] = ((color
>> 16) & 0xff) + 128; /* W */
505 /* G */ Dest
[1] = ((color
>> 8 ) & 0xff) + 128; /* V */
506 /* R */ Dest
[2] = (color
& 0xff) + 128; /* U */
507 /* A */ Dest
[3] = ((color
>> 24) & 0xff) + 128; /* Q */
514 static void convert_r16g16_snorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
515 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
517 unsigned int x
, y
, z
;
519 unsigned short *Dest
;
521 for (z
= 0; z
< depth
; z
++)
523 for (y
= 0; y
< height
; y
++)
525 Source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
526 Dest
= (unsigned short *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
527 for (x
= 0; x
< width
; x
++ )
529 const DWORD color
= (*Source
++);
530 /* B */ Dest
[0] = 0xffff;
531 /* G */ Dest
[1] = (color
>> 16) + 32768; /* V */
532 /* R */ Dest
[2] = (color
& 0xffff) + 32768; /* U */
539 static void convert_r16g16(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
540 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
542 unsigned int x
, y
, z
;
546 for (z
= 0; z
< depth
; z
++)
548 for (y
= 0; y
< height
; y
++)
550 Source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
551 Dest
= (WORD
*) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
552 for (x
= 0; x
< width
; x
++ )
554 WORD green
= (*Source
++);
555 WORD red
= (*Source
++);
558 /* Strictly speaking not correct for R16G16F, but it doesn't matter because the
559 * shader overwrites it anyway */
567 static void convert_r32g32_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
568 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
570 unsigned int x
, y
, z
;
574 for (z
= 0; z
< depth
; z
++)
576 for (y
= 0; y
< height
; y
++)
578 Source
= (const float *)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
579 Dest
= (float *) (dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
580 for (x
= 0; x
< width
; x
++ )
582 float green
= (*Source
++);
583 float red
= (*Source
++);
593 static void convert_s1_uint_d15_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
594 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
596 unsigned int x
, y
, z
;
598 for (z
= 0; z
< depth
; z
++)
600 for (y
= 0; y
< height
; ++y
)
602 const WORD
*source
= (const WORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
603 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
605 for (x
= 0; x
< width
; ++x
)
607 /* The depth data is normalized, so needs to be scaled,
608 * the stencil data isn't. Scale depth data by
609 * (2^24-1)/(2^15-1) ~~ (2^9 + 2^-6). */
610 WORD d15
= source
[x
] >> 1;
611 DWORD d24
= (d15
<< 9) + (d15
>> 6);
612 dest
[x
] = (d24
<< 8) | (source
[x
] & 0x1);
618 static void convert_s4x4_uint_d24_unorm(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
619 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
621 unsigned int x
, y
, z
;
623 for (z
= 0; z
< depth
; z
++)
625 for (y
= 0; y
< height
; ++y
)
627 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
628 DWORD
*dest
= (DWORD
*)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
630 for (x
= 0; x
< width
; ++x
)
632 /* Just need to clear out the X4 part. */
633 dest
[x
] = source
[x
] & ~0xf0;
639 static void convert_s8_uint_d24_float(const BYTE
*src
, BYTE
*dst
, UINT src_row_pitch
, UINT src_slice_pitch
,
640 UINT dst_row_pitch
, UINT dst_slice_pitch
, UINT width
, UINT height
, UINT depth
)
642 unsigned int x
, y
, z
;
644 for (z
= 0; z
< depth
; z
++)
646 for (y
= 0; y
< height
; ++y
)
648 const DWORD
*source
= (const DWORD
*)(src
+ z
* src_slice_pitch
+ y
* src_row_pitch
);
649 float *dest_f
= (float *)(dst
+ z
* dst_slice_pitch
+ y
* dst_row_pitch
);
650 DWORD
*dest_s
= (DWORD
*)dest_f
;
652 for (x
= 0; x
< width
; ++x
)
654 dest_f
[x
* 2] = float_24_to_32((source
[x
] & 0xffffff00) >> 8);
655 dest_s
[x
* 2 + 1] = source
[x
] & 0xff;
661 static BOOL
color_in_range(const struct wined3d_color_key
*color_key
, DWORD color
)
663 /* FIXME: Is this really how color keys are supposed to work? I think it
664 * makes more sense to compare the individual channels. */
665 return color
>= color_key
->color_space_low_value
666 && color
<= color_key
->color_space_high_value
;
669 static void convert_p8_uint_b8g8r8a8_unorm(const BYTE
*src
, unsigned int src_pitch
,
670 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
671 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
679 /* FIXME: This should probably use the system palette. */
680 FIXME("P8 surface loaded without a palette.\n");
682 for (y
= 0; y
< height
; ++y
)
684 memset(&dst
[dst_pitch
* y
], 0, width
* 4);
690 for (y
= 0; y
< height
; ++y
)
692 src_row
= &src
[src_pitch
* y
];
693 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
694 for (x
= 0; x
< width
; ++x
)
696 BYTE src_color
= src_row
[x
];
697 dst_row
[x
] = 0xff000000
698 | (palette
->colors
[src_color
].rgbRed
<< 16)
699 | (palette
->colors
[src_color
].rgbGreen
<< 8)
700 | palette
->colors
[src_color
].rgbBlue
;
705 static void convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
706 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
707 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
713 for (y
= 0; y
< height
; ++y
)
715 src_row
= (WORD
*)&src
[src_pitch
* y
];
716 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
717 for (x
= 0; x
< width
; ++x
)
719 WORD src_color
= src_row
[x
];
720 if (!color_in_range(color_key
, src_color
))
721 dst_row
[x
] = 0x8000 | ((src_color
& 0xffc0) >> 1) | (src_color
& 0x1f);
723 dst_row
[x
] = ((src_color
& 0xffc0) >> 1) | (src_color
& 0x1f);
728 static void convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
729 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
730 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
736 for (y
= 0; y
< height
; ++y
)
738 src_row
= (WORD
*)&src
[src_pitch
* y
];
739 dst_row
= (WORD
*)&dst
[dst_pitch
* y
];
740 for (x
= 0; x
< width
; ++x
)
742 WORD src_color
= src_row
[x
];
743 if (color_in_range(color_key
, src_color
))
744 dst_row
[x
] = src_color
& ~0x8000;
746 dst_row
[x
] = src_color
| 0x8000;
751 static void convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
752 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
753 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
759 for (y
= 0; y
< height
; ++y
)
761 src_row
= &src
[src_pitch
* y
];
762 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
763 for (x
= 0; x
< width
; ++x
)
765 DWORD src_color
= (src_row
[x
* 3 + 2] << 16) | (src_row
[x
* 3 + 1] << 8) | src_row
[x
* 3];
766 if (!color_in_range(color_key
, src_color
))
767 dst_row
[x
] = src_color
| 0xff000000;
772 static void convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
773 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
774 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
776 const DWORD
*src_row
;
780 for (y
= 0; y
< height
; ++y
)
782 src_row
= (DWORD
*)&src
[src_pitch
* y
];
783 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
784 for (x
= 0; x
< width
; ++x
)
786 DWORD src_color
= src_row
[x
];
787 if (color_in_range(color_key
, src_color
))
788 dst_row
[x
] = src_color
& ~0xff000000;
790 dst_row
[x
] = src_color
| 0xff000000;
795 static void convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key(const BYTE
*src
, unsigned int src_pitch
,
796 BYTE
*dst
, unsigned int dst_pitch
, unsigned int width
, unsigned int height
,
797 const struct wined3d_palette
*palette
, const struct wined3d_color_key
*color_key
)
799 const DWORD
*src_row
;
803 for (y
= 0; y
< height
; ++y
)
805 src_row
= (DWORD
*)&src
[src_pitch
* y
];
806 dst_row
= (DWORD
*)&dst
[dst_pitch
* y
];
807 for (x
= 0; x
< width
; ++x
)
809 DWORD src_color
= src_row
[x
];
810 if (color_in_range(color_key
, src_color
))
811 src_color
&= ~0xff000000;
812 dst_row
[x
] = src_color
;
817 const struct wined3d_color_key_conversion
* wined3d_format_get_color_key_conversion(
818 const struct wined3d_texture
*texture
, BOOL need_alpha_ck
)
820 const struct wined3d_format
*format
= texture
->resource
.format
;
825 enum wined3d_format_id src_format
;
826 struct wined3d_color_key_conversion conversion
;
830 {WINED3DFMT_B5G6R5_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g6r5_unorm_b5g5r5a1_unorm_color_key
}},
831 {WINED3DFMT_B5G5R5X1_UNORM
, {WINED3DFMT_B5G5R5A1_UNORM
, convert_b5g5r5x1_unorm_b5g5r5a1_unorm_color_key
}},
832 {WINED3DFMT_B8G8R8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8_unorm_b8g8r8a8_unorm_color_key
}},
833 {WINED3DFMT_B8G8R8X8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8x8_unorm_b8g8r8a8_unorm_color_key
}},
834 {WINED3DFMT_B8G8R8A8_UNORM
, {WINED3DFMT_B8G8R8A8_UNORM
, convert_b8g8r8a8_unorm_b8g8r8a8_unorm_color_key
}},
836 static const struct wined3d_color_key_conversion convert_p8
=
838 WINED3DFMT_B8G8R8A8_UNORM
, convert_p8_uint_b8g8r8a8_unorm
841 if (need_alpha_ck
&& (texture
->async
.flags
& WINED3D_TEXTURE_ASYNC_COLOR_KEY
))
843 for (i
= 0; i
< sizeof(color_key_info
) / sizeof(*color_key_info
); ++i
)
845 if (color_key_info
[i
].src_format
== format
->id
)
846 return &color_key_info
[i
].conversion
;
849 FIXME("Color-keying not supported with format %s.\n", debug_d3dformat(format
->id
));
852 /* FIXME: This should check if the blitter backend can do P8 conversion,
853 * instead of checking for ARB_fragment_program. */
854 if (format
->id
== WINED3DFMT_P8_UINT
855 && !(texture
->resource
.device
->adapter
->gl_info
.supported
[ARB_FRAGMENT_PROGRAM
]
856 && texture
->swapchain
&& texture
== texture
->swapchain
->front_buffer
))
862 /* The following formats explicitly don't have WINED3DFMT_FLAG_TEXTURE set:
864 * These are never supported on native.
865 * WINED3DFMT_B8G8R8_UNORM
866 * WINED3DFMT_B2G3R3_UNORM
867 * WINED3DFMT_L4A4_UNORM
868 * WINED3DFMT_S1_UINT_D15_UNORM
869 * WINED3DFMT_S4X4_UINT_D24_UNORM
871 * Only some Geforce/Voodoo3/G400 cards offer 8-bit textures in case of ddraw.
872 * Since it is not widely available, don't offer it. Further no Windows driver
873 * offers WINED3DFMT_P8_UINT_A8_NORM, so don't offer it either.
875 * WINED3DFMT_P8_UINT_A8_UNORM
877 * These formats seem to be similar to the HILO formats in
878 * GL_NV_texture_shader. NVHU is said to be GL_UNSIGNED_HILO16,
879 * NVHS GL_SIGNED_HILO16. Rumours say that D3D computes a 3rd channel
880 * similarly to D3DFMT_CxV8U8 (So NVHS could be called D3DFMT_CxV16U16). ATI
881 * refused to support formats which can easily be emulated with pixel shaders,
882 * so applications have to deal with not having NVHS and NVHU.
885 static const struct wined3d_format_texture_info format_texture_info
[] =
887 /* format id gl_internal gl_srgb_internal gl_rt_internal
888 gl_format gl_type conv_byte_count
892 /* GL_APPLE_ycbcr_422 claims that its '2YUV' format, which is supported via the UNSIGNED_SHORT_8_8_REV_APPLE type
893 * is equivalent to 'UYVY' format on Windows, and the 'YUVS' via UNSIGNED_SHORT_8_8_APPLE equates to 'YUY2'. The
894 * d3d9 test however shows that the opposite is true. Since the extension is from 2002, it predates the x86 based
895 * Macs, so probably the endianness differs. This could be tested as soon as we have a Windows and MacOS on a big
898 {WINED3DFMT_UYVY
, GL_LUMINANCE_ALPHA
, GL_LUMINANCE_ALPHA
, 0,
899 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
900 WINED3DFMT_FLAG_FILTERING
,
901 WINED3D_GL_EXT_NONE
, NULL
},
902 {WINED3DFMT_UYVY
, GL_RGB
, GL_RGB
, 0,
903 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_APPLE
, 0,
904 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
905 APPLE_YCBCR_422
, NULL
},
906 {WINED3DFMT_YUY2
, GL_LUMINANCE_ALPHA
, GL_LUMINANCE_ALPHA
, 0,
907 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
908 WINED3DFMT_FLAG_FILTERING
,
909 WINED3D_GL_EXT_NONE
, NULL
},
910 {WINED3DFMT_YUY2
, GL_RGB
, GL_RGB
, 0,
911 GL_YCBCR_422_APPLE
, GL_UNSIGNED_SHORT_8_8_REV_APPLE
, 0,
912 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_FILTERING
,
913 APPLE_YCBCR_422
, NULL
},
914 {WINED3DFMT_YV12
, GL_ALPHA
, GL_ALPHA
, 0,
915 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
916 WINED3DFMT_FLAG_FILTERING
,
917 WINED3D_GL_EXT_NONE
, NULL
},
918 {WINED3DFMT_NV12
, GL_ALPHA
, GL_ALPHA
, 0,
919 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
920 WINED3DFMT_FLAG_FILTERING
,
921 WINED3D_GL_EXT_NONE
, NULL
},
922 {WINED3DFMT_DXT1
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
, 0,
923 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
924 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
925 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
926 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
927 {WINED3DFMT_DXT2
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
928 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
929 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
930 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
931 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
932 {WINED3DFMT_DXT3
, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
, 0,
933 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
934 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
935 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
936 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
937 {WINED3DFMT_DXT4
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
938 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
939 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
940 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
941 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
942 {WINED3DFMT_DXT5
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
, 0,
943 GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
944 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
945 | WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_COMPRESSED
,
946 EXT_TEXTURE_COMPRESSION_S3TC
, NULL
},
948 {WINED3DFMT_R32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
950 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
951 ARB_TEXTURE_FLOAT
, NULL
},
952 {WINED3DFMT_R32_FLOAT
, GL_R32F
, GL_R32F
, 0,
954 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
955 ARB_TEXTURE_RG
, NULL
},
956 {WINED3DFMT_R32G32_FLOAT
, GL_RGB32F_ARB
, GL_RGB32F_ARB
, 0,
957 GL_RGB
, GL_FLOAT
, 12,
958 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
959 ARB_TEXTURE_FLOAT
, convert_r32g32_float
},
960 {WINED3DFMT_R32G32_FLOAT
, GL_RG32F
, GL_RG32F
, 0,
962 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
963 ARB_TEXTURE_RG
, NULL
},
964 {WINED3DFMT_R32G32B32A32_FLOAT
, GL_RGBA32F_ARB
, GL_RGBA32F_ARB
, 0,
965 GL_RGBA
, GL_FLOAT
, 0,
966 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
967 ARB_TEXTURE_FLOAT
, NULL
},
969 {WINED3DFMT_R16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
970 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
971 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
972 ARB_TEXTURE_FLOAT
, NULL
},
973 {WINED3DFMT_R16_FLOAT
, GL_R16F
, GL_R16F
, 0,
974 GL_RED
, GL_HALF_FLOAT_ARB
, 0,
975 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
976 ARB_TEXTURE_RG
, NULL
},
977 {WINED3DFMT_R16G16_FLOAT
, GL_RGB16F_ARB
, GL_RGB16F_ARB
, 0,
978 GL_RGB
, GL_HALF_FLOAT_ARB
, 6,
979 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
980 ARB_TEXTURE_FLOAT
, convert_r16g16
},
981 {WINED3DFMT_R16G16_FLOAT
, GL_RG16F
, GL_RG16F
, 0,
982 GL_RG
, GL_HALF_FLOAT_ARB
, 0,
983 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
984 ARB_TEXTURE_RG
, NULL
},
985 {WINED3DFMT_R16G16B16A16_FLOAT
, GL_RGBA16F_ARB
, GL_RGBA16F_ARB
, 0,
986 GL_RGBA
, GL_HALF_FLOAT_ARB
, 0,
987 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_RENDERTARGET
988 | WINED3DFMT_FLAG_VTF
,
989 ARB_TEXTURE_FLOAT
, NULL
},
990 /* Palettized formats */
991 {WINED3DFMT_P8_UINT
, GL_ALPHA8
, GL_ALPHA8
, 0,
992 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
995 /* Standard ARGB formats */
996 {WINED3DFMT_B8G8R8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
997 GL_BGR
, GL_UNSIGNED_BYTE
, 0,
998 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
| WINED3DFMT_FLAG_RENDERTARGET
,
999 WINED3D_GL_EXT_NONE
, NULL
},
1000 {WINED3DFMT_B8G8R8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1001 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1002 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1003 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1004 | WINED3DFMT_FLAG_VTF
,
1005 WINED3D_GL_EXT_NONE
, NULL
},
1006 {WINED3DFMT_B8G8R8X8_UNORM
, GL_RGB8
, GL_SRGB8_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 WINED3D_GL_EXT_NONE
, NULL
},
1011 {WINED3DFMT_B5G6R5_UNORM
, GL_RGB5
, GL_RGB5
, GL_RGB8
,
1012 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 0,
1013 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1014 | WINED3DFMT_FLAG_RENDERTARGET
,
1015 WINED3D_GL_EXT_NONE
, NULL
},
1016 {WINED3DFMT_B5G5R5X1_UNORM
, GL_RGB5
, GL_RGB5_A1
, 0,
1017 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1018 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1019 WINED3D_GL_EXT_NONE
, NULL
},
1020 {WINED3DFMT_B5G5R5A1_UNORM
, GL_RGB5_A1
, GL_RGB5_A1
, 0,
1021 GL_BGRA
, GL_UNSIGNED_SHORT_1_5_5_5_REV
, 0,
1022 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1023 WINED3D_GL_EXT_NONE
, NULL
},
1024 {WINED3DFMT_B4G4R4A4_UNORM
, GL_RGBA4
, GL_SRGB8_ALPHA8_EXT
, 0,
1025 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1026 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1027 | WINED3DFMT_FLAG_SRGB_READ
,
1028 WINED3D_GL_EXT_NONE
, NULL
},
1029 {WINED3DFMT_B2G3R3_UNORM
, GL_R3_G3_B2
, GL_R3_G3_B2
, 0,
1030 GL_RGB
, GL_UNSIGNED_BYTE_3_3_2
, 0,
1031 WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1032 WINED3D_GL_EXT_NONE
, NULL
},
1033 {WINED3DFMT_R8_UNORM
, GL_R8
, GL_R8
, 0,
1034 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1035 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1036 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_VTF
,
1037 ARB_TEXTURE_RG
, NULL
},
1038 {WINED3DFMT_A8_UNORM
, GL_ALPHA8
, GL_ALPHA8
, 0,
1039 GL_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1040 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1041 WINED3D_GL_EXT_NONE
, NULL
},
1042 {WINED3DFMT_B4G4R4X4_UNORM
, GL_RGB4
, GL_RGB4
, 0,
1043 GL_BGRA
, GL_UNSIGNED_SHORT_4_4_4_4_REV
, 0,
1044 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1045 WINED3D_GL_EXT_NONE
, NULL
},
1046 {WINED3DFMT_R10G10B10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1047 GL_RGBA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1048 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1049 | WINED3DFMT_FLAG_RENDERTARGET
,
1050 WINED3D_GL_EXT_NONE
, NULL
},
1051 {WINED3DFMT_R8G8B8A8_UNORM
, GL_RGBA8
, GL_SRGB8_ALPHA8_EXT
, 0,
1052 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1053 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1054 | WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
1055 | WINED3DFMT_FLAG_VTF
,
1056 WINED3D_GL_EXT_NONE
, NULL
},
1057 {WINED3DFMT_R8G8B8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1058 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1059 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1060 WINED3D_GL_EXT_NONE
, NULL
},
1061 {WINED3DFMT_R16G16_UNORM
, GL_RGB16
, GL_RGB16
, GL_RGBA16
,
1062 GL_RGB
, GL_UNSIGNED_SHORT
, 6,
1063 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1064 WINED3D_GL_EXT_NONE
, convert_r16g16
},
1065 {WINED3DFMT_R16G16_UNORM
, GL_RG16
, GL_RG16
, 0,
1066 GL_RG
, GL_UNSIGNED_SHORT
, 0,
1067 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1068 | WINED3DFMT_FLAG_RENDERTARGET
,
1069 ARB_TEXTURE_RG
, NULL
},
1070 {WINED3DFMT_B10G10R10A2_UNORM
, GL_RGB10_A2
, GL_RGB10_A2
, 0,
1071 GL_BGRA
, GL_UNSIGNED_INT_2_10_10_10_REV
, 0,
1072 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1073 | WINED3DFMT_FLAG_RENDERTARGET
,
1074 WINED3D_GL_EXT_NONE
, NULL
},
1075 {WINED3DFMT_R16G16B16A16_UNORM
, GL_RGBA16
, GL_RGBA16
, 0,
1076 GL_RGBA
, GL_UNSIGNED_SHORT
, 0,
1077 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1078 | WINED3DFMT_FLAG_RENDERTARGET
,
1079 WINED3D_GL_EXT_NONE
, NULL
},
1081 {WINED3DFMT_L8_UNORM
, GL_LUMINANCE8
, GL_SLUMINANCE8_EXT
, 0,
1082 GL_LUMINANCE
, GL_UNSIGNED_BYTE
, 0,
1083 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1084 | WINED3DFMT_FLAG_SRGB_READ
,
1085 WINED3D_GL_EXT_NONE
, NULL
},
1086 {WINED3DFMT_L8A8_UNORM
, GL_LUMINANCE8_ALPHA8
, GL_SLUMINANCE8_ALPHA8_EXT
, 0,
1087 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1088 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1089 | WINED3DFMT_FLAG_SRGB_READ
,
1090 WINED3D_GL_EXT_NONE
, NULL
},
1091 {WINED3DFMT_L4A4_UNORM
, GL_LUMINANCE4_ALPHA4
, GL_LUMINANCE4_ALPHA4
, 0,
1092 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 2,
1093 WINED3DFMT_FLAG_FILTERING
,
1094 WINED3D_GL_EXT_NONE
, convert_l4a4_unorm
},
1095 /* Bump mapping stuff */
1096 {WINED3DFMT_R8G8_SNORM
, GL_RGB8
, GL_RGB8
, 0,
1097 GL_BGR
, GL_UNSIGNED_BYTE
, 3,
1098 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1099 | WINED3DFMT_FLAG_BUMPMAP
,
1100 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm
},
1101 {WINED3DFMT_R8G8_SNORM
, GL_DSDT8_NV
, GL_DSDT8_NV
, 0,
1102 GL_DSDT_NV
, GL_BYTE
, 0,
1103 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1104 | WINED3DFMT_FLAG_BUMPMAP
,
1105 NV_TEXTURE_SHADER
, NULL
},
1106 {WINED3DFMT_R8G8_SNORM
, GL_RG8_SNORM
, GL_RG8_SNORM
, 0,
1108 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1109 | WINED3DFMT_FLAG_BUMPMAP
,
1110 EXT_TEXTURE_SNORM
, NULL
},
1111 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB5
, GL_RGB5
, 0,
1112 GL_RGB
, GL_UNSIGNED_SHORT_5_6_5
, 2,
1113 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1114 | WINED3DFMT_FLAG_BUMPMAP
,
1115 WINED3D_GL_EXT_NONE
, convert_r5g5_snorm_l6_unorm
},
1116 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_DSDT8_MAG8_NV
, GL_DSDT8_MAG8_NV
, 0,
1117 GL_DSDT_MAG_NV
, GL_BYTE
, 3,
1118 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1119 | WINED3DFMT_FLAG_BUMPMAP
,
1120 NV_TEXTURE_SHADER
, convert_r5g5_snorm_l6_unorm_nv
},
1121 {WINED3DFMT_R5G5_SNORM_L6_UNORM
, GL_RGB8_SNORM
, GL_RGB8_SNORM
, 0,
1122 GL_RGBA
, GL_BYTE
, 4,
1123 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1124 | WINED3DFMT_FLAG_BUMPMAP
,
1125 EXT_TEXTURE_SNORM
, convert_r5g5_snorm_l6_unorm_ext
},
1126 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_RGB8
, GL_RGB8
, 0,
1127 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 4,
1128 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1129 | WINED3DFMT_FLAG_BUMPMAP
,
1130 WINED3D_GL_EXT_NONE
, convert_r8g8_snorm_l8x8_unorm
},
1131 {WINED3DFMT_R8G8_SNORM_L8X8_UNORM
, GL_DSDT8_MAG8_INTENSITY8_NV
, GL_DSDT8_MAG8_INTENSITY8_NV
, 0,
1132 GL_DSDT_MAG_VIB_NV
, GL_UNSIGNED_INT_8_8_S8_S8_REV_NV
, 4,
1133 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1134 | WINED3DFMT_FLAG_BUMPMAP
,
1135 NV_TEXTURE_SHADER
, convert_r8g8_snorm_l8x8_unorm_nv
},
1136 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8
, GL_RGBA8
, 0,
1137 GL_BGRA
, GL_UNSIGNED_BYTE
, 4,
1138 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1139 | WINED3DFMT_FLAG_BUMPMAP
,
1140 WINED3D_GL_EXT_NONE
, convert_r8g8b8a8_snorm
},
1141 {WINED3DFMT_R8G8B8A8_SNORM
, GL_SIGNED_RGBA8_NV
, GL_SIGNED_RGBA8_NV
, 0,
1142 GL_RGBA
, GL_BYTE
, 0,
1143 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1144 | WINED3DFMT_FLAG_BUMPMAP
,
1145 NV_TEXTURE_SHADER
, NULL
},
1146 {WINED3DFMT_R8G8B8A8_SNORM
, GL_RGBA8_SNORM
, GL_RGBA8_SNORM
, 0,
1147 GL_RGBA
, GL_BYTE
, 0,
1148 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1149 | WINED3DFMT_FLAG_BUMPMAP
,
1150 EXT_TEXTURE_SNORM
, NULL
},
1151 {WINED3DFMT_R16G16_SNORM
, GL_RGB16
, GL_RGB16
, 0,
1152 GL_BGR
, GL_UNSIGNED_SHORT
, 6,
1153 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1154 | WINED3DFMT_FLAG_BUMPMAP
,
1155 WINED3D_GL_EXT_NONE
, convert_r16g16_snorm
},
1156 {WINED3DFMT_R16G16_SNORM
, GL_SIGNED_HILO16_NV
, GL_SIGNED_HILO16_NV
, 0,
1157 GL_HILO_NV
, GL_SHORT
, 0,
1158 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1159 | WINED3DFMT_FLAG_BUMPMAP
,
1160 NV_TEXTURE_SHADER
, NULL
},
1161 {WINED3DFMT_R16G16_SNORM
, GL_RG16_SNORM
, GL_RG16_SNORM
, 0,
1163 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1164 | WINED3DFMT_FLAG_BUMPMAP
,
1165 EXT_TEXTURE_SNORM
, NULL
},
1166 /* Depth stencil formats */
1167 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1168 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1169 WINED3DFMT_FLAG_DEPTH
,
1170 WINED3D_GL_EXT_NONE
, NULL
},
1171 {WINED3DFMT_D16_LOCKABLE
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1172 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1173 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1174 ARB_DEPTH_TEXTURE
, NULL
},
1175 {WINED3DFMT_D32_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1176 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1177 WINED3DFMT_FLAG_DEPTH
,
1178 WINED3D_GL_EXT_NONE
, NULL
},
1179 {WINED3DFMT_D32_UNORM
, GL_DEPTH_COMPONENT32_ARB
, GL_DEPTH_COMPONENT32_ARB
, 0,
1180 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1181 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1182 ARB_DEPTH_TEXTURE
, NULL
},
1183 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1184 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1185 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1186 ARB_DEPTH_TEXTURE
, NULL
},
1187 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1188 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 4,
1189 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1190 EXT_PACKED_DEPTH_STENCIL
, convert_s1_uint_d15_unorm
},
1191 {WINED3DFMT_S1_UINT_D15_UNORM
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1192 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 4,
1193 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1194 ARB_FRAMEBUFFER_OBJECT
, convert_s1_uint_d15_unorm
},
1195 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1196 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1197 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1198 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1199 ARB_DEPTH_TEXTURE
, NULL
},
1200 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1201 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 0,
1202 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1203 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1204 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1205 {WINED3DFMT_D24_UNORM_S8_UINT
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1206 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1207 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1208 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1209 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1210 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1211 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1212 WINED3DFMT_FLAG_DEPTH
,
1213 WINED3D_GL_EXT_NONE
, NULL
},
1214 {WINED3DFMT_X8D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1215 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1216 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1217 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1218 ARB_DEPTH_TEXTURE
, NULL
},
1219 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1220 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, 0,
1221 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1222 ARB_DEPTH_TEXTURE
, NULL
},
1223 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1224 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 4,
1225 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1226 EXT_PACKED_DEPTH_STENCIL
, convert_s4x4_uint_d24_unorm
},
1227 {WINED3DFMT_S4X4_UINT_D24_UNORM
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1228 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 4,
1229 WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1230 ARB_FRAMEBUFFER_OBJECT
, convert_s4x4_uint_d24_unorm
},
1231 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT
, GL_DEPTH_COMPONENT
, 0,
1232 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1233 WINED3DFMT_FLAG_DEPTH
,
1234 WINED3D_GL_EXT_NONE
, NULL
},
1235 {WINED3DFMT_D16_UNORM
, GL_DEPTH_COMPONENT24_ARB
, GL_DEPTH_COMPONENT24_ARB
, 0,
1236 GL_DEPTH_COMPONENT
, GL_UNSIGNED_SHORT
, 0,
1237 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1238 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1239 ARB_DEPTH_TEXTURE
, NULL
},
1240 {WINED3DFMT_L16_UNORM
, GL_LUMINANCE16
, GL_LUMINANCE16
, 0,
1241 GL_LUMINANCE
, GL_UNSIGNED_SHORT
, 0,
1242 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
,
1243 WINED3D_GL_EXT_NONE
, NULL
},
1244 {WINED3DFMT_D32_FLOAT
, GL_DEPTH_COMPONENT32F
, GL_DEPTH_COMPONENT32F
, 0,
1245 GL_DEPTH_COMPONENT
, GL_FLOAT
, 0,
1246 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_SHADOW
,
1247 ARB_DEPTH_BUFFER_FLOAT
, NULL
},
1248 {WINED3DFMT_S8_UINT_D24_FLOAT
, GL_DEPTH32F_STENCIL8
, GL_DEPTH32F_STENCIL8
, 0,
1249 GL_DEPTH_STENCIL
, GL_FLOAT_32_UNSIGNED_INT_24_8_REV
, 8,
1250 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
| WINED3DFMT_FLAG_SHADOW
,
1251 ARB_DEPTH_BUFFER_FLOAT
, convert_s8_uint_d24_float
},
1252 /* Vendor-specific formats */
1253 {WINED3DFMT_ATI1N
, GL_COMPRESSED_RED_RGTC1
, GL_COMPRESSED_RED_RGTC1
, 0,
1254 GL_RED
, GL_UNSIGNED_BYTE
, 0,
1255 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1256 | WINED3DFMT_FLAG_COMPRESSED
,
1257 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1258 {WINED3DFMT_ATI2N
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
, 0,
1259 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1260 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1261 | WINED3DFMT_FLAG_COMPRESSED
,
1262 ATI_TEXTURE_COMPRESSION_3DC
, NULL
},
1263 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1264 GL_LUMINANCE_ALPHA
, GL_UNSIGNED_BYTE
, 0,
1265 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1266 | WINED3DFMT_FLAG_COMPRESSED
,
1267 EXT_TEXTURE_COMPRESSION_RGTC
, NULL
},
1268 {WINED3DFMT_ATI2N
, GL_COMPRESSED_RG_RGTC2
, GL_COMPRESSED_RG_RGTC2
, 0,
1269 GL_RG
, GL_UNSIGNED_BYTE
, 0,
1270 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1271 | WINED3DFMT_FLAG_COMPRESSED
,
1272 ARB_TEXTURE_COMPRESSION_RGTC
, NULL
},
1273 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8_EXT
, GL_DEPTH24_STENCIL8_EXT
, 0,
1274 GL_DEPTH_STENCIL_EXT
, GL_UNSIGNED_INT_24_8_EXT
, 0,
1275 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1276 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
,
1277 EXT_PACKED_DEPTH_STENCIL
, NULL
},
1278 {WINED3DFMT_INTZ
, GL_DEPTH24_STENCIL8
, GL_DEPTH24_STENCIL8
, 0,
1279 GL_DEPTH_STENCIL
, GL_UNSIGNED_INT_24_8
, 0,
1280 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
| WINED3DFMT_FLAG_FILTERING
1281 | WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
,
1282 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1283 {WINED3DFMT_NULL
, 0, 0, 0,
1284 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8_REV
, 0,
1285 WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
,
1286 ARB_FRAMEBUFFER_OBJECT
, NULL
},
1289 static inline int getFmtIdx(enum wined3d_format_id format_id
)
1291 /* First check if the format is at the position of its value.
1292 * This will catch the argb formats before the loop is entered. */
1293 if (format_id
< (sizeof(formats
) / sizeof(*formats
))
1294 && formats
[format_id
].id
== format_id
)
1302 for (i
= 0; i
< (sizeof(formats
) / sizeof(*formats
)); ++i
)
1304 if (formats
[i
].id
== format_id
) return i
;
1310 static void format_set_flag(struct wined3d_format
*format
, unsigned int flag
)
1314 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1315 format
->flags
[i
] |= flag
;
1318 static void format_clear_flag(struct wined3d_format
*format
, unsigned int flag
)
1322 for (i
= 0; i
< ARRAY_SIZE(format
->flags
); ++i
)
1323 format
->flags
[i
] &= ~flag
;
1326 static BOOL
init_format_base_info(struct wined3d_gl_info
*gl_info
)
1328 UINT format_count
= sizeof(formats
) / sizeof(*formats
);
1331 gl_info
->formats
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, format_count
* sizeof(*gl_info
->formats
));
1332 if (!gl_info
->formats
)
1334 ERR("Failed to allocate memory.\n");
1338 for (i
= 0; i
< format_count
; ++i
)
1340 struct wined3d_format
*format
= &gl_info
->formats
[i
];
1341 format
->id
= formats
[i
].id
;
1342 format
->red_size
= formats
[i
].red_size
;
1343 format
->green_size
= formats
[i
].green_size
;
1344 format
->blue_size
= formats
[i
].blue_size
;
1345 format
->alpha_size
= formats
[i
].alpha_size
;
1346 format
->red_offset
= formats
[i
].red_offset
;
1347 format
->green_offset
= formats
[i
].green_offset
;
1348 format
->blue_offset
= formats
[i
].blue_offset
;
1349 format
->alpha_offset
= formats
[i
].alpha_offset
;
1350 format
->byte_count
= formats
[i
].bpp
;
1351 format
->depth_size
= formats
[i
].depth_size
;
1352 format
->stencil_size
= formats
[i
].stencil_size
;
1353 format
->block_width
= 1;
1354 format
->block_height
= 1;
1355 format
->block_byte_count
= formats
[i
].bpp
;
1358 for (i
= 0; i
< (sizeof(format_base_flags
) / sizeof(*format_base_flags
)); ++i
)
1360 int fmt_idx
= getFmtIdx(format_base_flags
[i
].id
);
1364 ERR("Format %s (%#x) not found.\n",
1365 debug_d3dformat(format_base_flags
[i
].id
), format_base_flags
[i
].id
);
1366 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
1370 format_set_flag(&gl_info
->formats
[fmt_idx
], format_base_flags
[i
].flags
);
1376 static BOOL
init_format_block_info(struct wined3d_gl_info
*gl_info
)
1380 for (i
= 0; i
< (sizeof(format_block_info
) / sizeof(*format_block_info
)); ++i
)
1382 struct wined3d_format
*format
;
1383 int fmt_idx
= getFmtIdx(format_block_info
[i
].id
);
1387 ERR("Format %s (%#x) not found.\n",
1388 debug_d3dformat(format_block_info
[i
].id
), format_block_info
[i
].id
);
1392 format
= &gl_info
->formats
[fmt_idx
];
1393 format
->block_width
= format_block_info
[i
].block_width
;
1394 format
->block_height
= format_block_info
[i
].block_height
;
1395 format
->block_byte_count
= format_block_info
[i
].block_byte_count
;
1396 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_BLOCKS
);
1397 if (!format_block_info
[i
].verify
)
1398 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_BLOCKS_NO_VERIFY
);
1404 static GLenum
wined3d_gl_type_to_enum(enum wined3d_gl_resource_type type
)
1408 case WINED3D_GL_RES_TYPE_TEX_1D
:
1409 return GL_TEXTURE_1D
;
1410 case WINED3D_GL_RES_TYPE_TEX_2D
:
1411 return GL_TEXTURE_2D
;
1412 case WINED3D_GL_RES_TYPE_TEX_3D
:
1413 return GL_TEXTURE_3D
;
1414 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1415 return GL_TEXTURE_CUBE_MAP_ARB
;
1416 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1417 return GL_TEXTURE_RECTANGLE_ARB
;
1418 case WINED3D_GL_RES_TYPE_BUFFER
:
1419 return GL_TEXTURE_2D
; /* TODO: GL_TEXTURE_BUFFER. */
1420 case WINED3D_GL_RES_TYPE_RB
:
1421 return GL_RENDERBUFFER
;
1422 case WINED3D_GL_RES_TYPE_COUNT
:
1425 ERR("Unexpected GL resource type %u.\n", type
);
1429 static void delete_fbo_attachment(const struct wined3d_gl_info
*gl_info
,
1430 enum wined3d_gl_resource_type d3d_type
, GLuint object
)
1434 case WINED3D_GL_RES_TYPE_TEX_1D
:
1435 case WINED3D_GL_RES_TYPE_TEX_2D
:
1436 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1437 case WINED3D_GL_RES_TYPE_TEX_3D
:
1438 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1439 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &object
);
1442 case WINED3D_GL_RES_TYPE_RB
:
1443 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &object
);
1446 case WINED3D_GL_RES_TYPE_BUFFER
:
1447 case WINED3D_GL_RES_TYPE_COUNT
:
1452 /* Context activation is done by the caller. */
1453 static void create_and_bind_fbo_attachment(const struct wined3d_gl_info
*gl_info
, unsigned int flags
,
1454 enum wined3d_gl_resource_type d3d_type
, GLuint
*object
, GLenum internal
, GLenum format
, GLenum type
)
1456 GLenum attach_type
= flags
& WINED3DFMT_FLAG_DEPTH
?
1457 GL_DEPTH_ATTACHMENT
: GL_COLOR_ATTACHMENT0
;
1461 case WINED3D_GL_RES_TYPE_TEX_1D
:
1462 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1463 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, *object
);
1464 gl_info
->gl_ops
.gl
.p_glTexImage1D(GL_TEXTURE_1D
, 0, internal
, 16, 0, format
, type
, NULL
);
1465 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1466 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1468 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, attach_type
, GL_TEXTURE_1D
,
1470 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1471 gl_info
->fbo_ops
.glFramebufferTexture1D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_TEXTURE_1D
,
1475 case WINED3D_GL_RES_TYPE_TEX_2D
:
1476 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1477 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1478 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(d3d_type
), *object
);
1479 gl_info
->gl_ops
.gl
.p_glTexImage2D(wined3d_gl_type_to_enum(d3d_type
), 0, internal
, 16, 16, 0,
1480 format
, type
, NULL
);
1481 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1482 gl_info
->gl_ops
.gl
.p_glTexParameteri(wined3d_gl_type_to_enum(d3d_type
), GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1484 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
1485 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
1486 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1487 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1488 wined3d_gl_type_to_enum(d3d_type
), *object
, 0);
1491 case WINED3D_GL_RES_TYPE_TEX_3D
:
1492 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1493 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_3D
, *object
);
1494 GL_EXTCALL(glTexImage3D
)(GL_TEXTURE_3D
, 0, internal
, 16, 16, 16, 0,
1495 format
, type
, NULL
);
1496 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1497 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_3D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1499 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, attach_type
,
1500 GL_TEXTURE_3D
, *object
, 0, 0);
1501 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1502 gl_info
->fbo_ops
.glFramebufferTexture3D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1503 GL_TEXTURE_3D
, *object
, 0, 0);
1506 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1507 gl_info
->gl_ops
.gl
.p_glGenTextures(1, object
);
1508 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, *object
);
1509 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, internal
, 16, 16, 0,
1510 format
, type
, NULL
);
1511 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
, 0, internal
, 16, 16, 0,
1512 format
, type
, NULL
);
1513 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
, 0, internal
, 16, 16, 0,
1514 format
, type
, NULL
);
1515 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
, 0, internal
, 16, 16, 0,
1516 format
, type
, NULL
);
1517 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
, 0, internal
, 16, 16, 0,
1518 format
, type
, NULL
);
1519 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
, 0, internal
, 16, 16, 0,
1520 format
, type
, NULL
);
1521 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1522 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1524 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, attach_type
,
1525 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
1526 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1527 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
,
1528 GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, *object
, 0);
1531 case WINED3D_GL_RES_TYPE_RB
:
1532 gl_info
->fbo_ops
.glGenRenderbuffers(1, object
);
1533 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, *object
);
1534 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, internal
, 16, 16);
1535 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, attach_type
, GL_RENDERBUFFER
,
1537 if (flags
& WINED3DFMT_FLAG_STENCIL
)
1538 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
,
1542 case WINED3D_GL_RES_TYPE_BUFFER
:
1543 case WINED3D_GL_RES_TYPE_COUNT
:
1547 /* Ideally we'd skip all formats already known not to work on textures
1548 * by checking for WINED3DFMT_FLAG_TEXTURE here. However, we want to
1549 * know if we can attach WINED3DFMT_P8_UINT textures to FBOs, and this
1550 * format never has WINED3DFMT_FLAG_TEXTURE set. Instead, swallow GL
1551 * errors generated by invalid formats. */
1552 while (gl_info
->gl_ops
.gl
.p_glGetError());
1555 /* Context activation is done by the caller. */
1556 static void check_fbo_compat(const struct wined3d_gl_info
*gl_info
, struct wined3d_format
*format
)
1558 /* Check if the default internal format is supported as a frame buffer
1559 * target, otherwise fall back to the render target internal.
1561 * Try to stick to the standard format if possible, this limits precision differences. */
1562 GLenum status
, rt_internal
= format
->rtInternal
;
1563 GLuint object
, color_rb
;
1564 enum wined3d_gl_resource_type type
;
1565 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
1567 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
1569 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
1571 const char *type_string
= "color";
1573 if (type
== WINED3D_GL_RES_TYPE_BUFFER
)
1576 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->glInternal
,
1577 format
->glFormat
, format
->glType
);
1579 if (format
->flags
[type
] & (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
1581 gl_info
->fbo_ops
.glGenRenderbuffers(1, &color_rb
);
1582 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, color_rb
);
1583 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
1584 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 1);
1586 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA8
, 16, 16);
1588 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
,
1589 GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, color_rb
);
1590 checkGLcall("Create and attach color rb attachment");
1591 type_string
= "depth / stencil";
1594 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
1595 checkGLcall("Framebuffer format check");
1597 if (status
== GL_FRAMEBUFFER_COMPLETE
)
1599 TRACE("Format %s is supported as FBO %s attachment, type %u.\n",
1600 debug_d3dformat(format
->id
), type_string
, type
);
1601 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
1602 format
->rtInternal
= format
->glInternal
;
1603 regular_fmt_used
= TRUE
;
1609 if (format
->flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
1611 WARN("Format %s with rendertarget flag is not supported as FBO color attachment (type %u),"
1612 " and no fallback specified.\n", debug_d3dformat(format
->id
), type
);
1613 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
1617 TRACE("Format %s is not supported as FBO %s attachment, type %u.\n",
1618 debug_d3dformat(format
->id
), type_string
, type
);
1620 format
->rtInternal
= format
->glInternal
;
1624 TRACE("Format %s is not supported as FBO %s attachment (type %u),"
1625 " trying rtInternal format as fallback.\n",
1626 debug_d3dformat(format
->id
), type_string
, type
);
1628 while (gl_info
->gl_ops
.gl
.p_glGetError());
1630 delete_fbo_attachment(gl_info
, type
, object
);
1631 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->rtInternal
,
1632 format
->glFormat
, format
->glType
);
1634 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
1635 checkGLcall("Framebuffer format check");
1637 if (status
== GL_FRAMEBUFFER_COMPLETE
)
1639 TRACE("Format %s rtInternal format is supported as FBO %s attachment, type %u.\n",
1640 debug_d3dformat(format
->id
), type_string
, type
);
1641 fallback_fmt_used
= TRUE
;
1645 WARN("Format %s rtInternal format is not supported as FBO %s attachment, type %u.\n",
1646 debug_d3dformat(format
->id
), type_string
, type
);
1647 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
1652 if (status
== GL_FRAMEBUFFER_COMPLETE
1653 && ((format
->flags
[type
] & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
)
1654 || !(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
1655 && format
->id
!= WINED3DFMT_NULL
&& format
->id
!= WINED3DFMT_P8_UINT
1656 && format
->glFormat
!= GL_LUMINANCE
&& format
->glFormat
!= GL_LUMINANCE_ALPHA
1657 && (format
->red_size
|| format
->alpha_size
))
1659 DWORD readback
[16 * 16 * 16], color
, r_range
, a_range
;
1664 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
]
1665 || gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
1667 gl_info
->fbo_ops
.glGenRenderbuffers(1, &rb
);
1668 gl_info
->fbo_ops
.glBindRenderbuffer(GL_RENDERBUFFER
, rb
);
1669 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
1670 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 1);
1672 gl_info
->fbo_ops
.glRenderbufferStorage(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 16, 16);
1673 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
1674 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, rb
);
1675 checkGLcall("RB attachment");
1678 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
1679 gl_info
->gl_ops
.gl
.p_glClearColor(0.0f
, 0.0f
, 0.0f
, 1.0f
);
1680 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
1681 if (gl_info
->gl_ops
.gl
.p_glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION
)
1683 while (gl_info
->gl_ops
.gl
.p_glGetError());
1684 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
1685 debug_d3dformat(format
->id
), type
);
1686 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
1690 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
1691 if (type
== WINED3D_GL_RES_TYPE_TEX_1D
)
1692 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
1694 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 16);
1695 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
1696 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
1697 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
1698 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
1699 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
1701 gl_info
->gl_ops
.gl
.p_glBlendFunc(GL_SRC_ALPHA
, GL_ONE_MINUS_SRC_ALPHA
);
1703 /* Draw a full-black quad */
1704 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
1705 gl_info
->gl_ops
.gl
.p_glColor4f(0.0f
, 0.0f
, 0.0f
, 1.0f
);
1706 gl_info
->gl_ops
.gl
.p_glVertex3f(-1.0f
, -1.0f
, 0.0f
);
1707 gl_info
->gl_ops
.gl
.p_glVertex3f(1.0f
, -1.0f
, 0.0f
);
1708 gl_info
->gl_ops
.gl
.p_glVertex3f(-1.0f
, 1.0f
, 0.0f
);
1709 gl_info
->gl_ops
.gl
.p_glVertex3f(1.0f
, 1.0f
, 0.0f
);
1710 gl_info
->gl_ops
.gl
.p_glEnd();
1712 gl_info
->gl_ops
.gl
.p_glEnable(GL_BLEND
);
1713 /* Draw a half-transparent red quad */
1714 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
1715 gl_info
->gl_ops
.gl
.p_glColor4f(1.0f
, 0.0f
, 0.0f
, 0.5f
);
1716 gl_info
->gl_ops
.gl
.p_glVertex3f(-1.0f
, -1.0f
, 0.0f
);
1717 gl_info
->gl_ops
.gl
.p_glVertex3f(1.0f
, -1.0f
, 0.0f
);
1718 gl_info
->gl_ops
.gl
.p_glVertex3f(-1.0f
, 1.0f
, 0.0f
);
1719 gl_info
->gl_ops
.gl
.p_glVertex3f(1.0f
, 1.0f
, 0.0f
);
1720 gl_info
->gl_ops
.gl
.p_glEnd();
1722 gl_info
->gl_ops
.gl
.p_glDisable(GL_BLEND
);
1726 case WINED3D_GL_RES_TYPE_TEX_1D
:
1727 /* Rebinding texture to workaround a fglrx bug. */
1728 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_1D
, object
);
1729 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_1D
, 0, GL_BGRA
,
1730 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
1731 color
= readback
[7];
1734 case WINED3D_GL_RES_TYPE_TEX_2D
:
1735 case WINED3D_GL_RES_TYPE_TEX_3D
:
1736 case WINED3D_GL_RES_TYPE_TEX_RECT
:
1737 /* Rebinding texture to workaround a fglrx bug. */
1738 gl_info
->gl_ops
.gl
.p_glBindTexture(wined3d_gl_type_to_enum(type
), object
);
1739 gl_info
->gl_ops
.gl
.p_glGetTexImage(wined3d_gl_type_to_enum(type
), 0, GL_BGRA
,
1740 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
1741 color
= readback
[7 * 16 + 7];
1744 case WINED3D_GL_RES_TYPE_TEX_CUBE
:
1745 /* Rebinding texture to workaround a fglrx bug. */
1746 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_CUBE_MAP_ARB
, object
);
1747 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
, 0, GL_BGRA
,
1748 GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
1749 color
= readback
[7 * 16 + 7];
1752 case WINED3D_GL_RES_TYPE_RB
:
1753 gl_info
->gl_ops
.gl
.p_glReadPixels(0, 0, 16, 16,
1754 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
1755 color
= readback
[7 * 16 + 7];
1758 case WINED3D_GL_RES_TYPE_BUFFER
:
1759 case WINED3D_GL_RES_TYPE_COUNT
:
1763 checkGLcall("Post-pixelshader blending check");
1766 r
= (color
& 0x00ff0000) >> 16;
1768 r_range
= format
->red_size
< 8 ? 1 << (8 - format
->red_size
) : 1;
1769 a_range
= format
->alpha_size
< 8 ? 1 << (8 - format
->alpha_size
) : 1;
1770 if (format
->red_size
&& (r
< 0x7f - r_range
|| r
> 0x7f + r_range
))
1772 else if (format
->alpha_size
> 1 && (a
< 0xbf - a_range
|| a
> 0xbf + a_range
))
1776 TRACE("Format %s doesn't support post-pixelshader blending, type %u.\n",
1777 debug_d3dformat(format
->id
), type
);
1778 TRACE("Color output: %#x\n", color
);
1779 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
1783 TRACE("Format %s supports post-pixelshader blending, type %u.\n",
1784 debug_d3dformat(format
->id
), type
);
1785 TRACE("Color output: %#x\n", color
);
1786 format
->flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
1790 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
]
1791 || gl_info
->supported
[EXT_PACKED_DEPTH_STENCIL
])
1793 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_DEPTH_ATTACHMENT
, GL_RENDERBUFFER
, 0);
1794 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
, 0);
1795 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &rb
);
1796 checkGLcall("RB cleanup");
1800 if (format
->glInternal
!= format
->glGammaInternal
)
1802 delete_fbo_attachment(gl_info
, type
, object
);
1803 create_and_bind_fbo_attachment(gl_info
, format
->flags
[type
], type
, &object
, format
->glGammaInternal
,
1804 format
->glFormat
, format
->glType
);
1806 status
= gl_info
->fbo_ops
.glCheckFramebufferStatus(GL_FRAMEBUFFER
);
1807 checkGLcall("Framebuffer format check");
1809 if (status
== GL_FRAMEBUFFER_COMPLETE
)
1811 TRACE("Format %s's sRGB format is FBO attachable, type %u.\n",
1812 debug_d3dformat(format
->id
), type
);
1813 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
1817 WARN("Format %s's sRGB format is not FBO attachable, type %u.\n",
1818 debug_d3dformat(format
->id
), type
);
1821 else if (status
== GL_FRAMEBUFFER_COMPLETE
)
1822 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
1824 if (format
->flags
[type
] & (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
1826 gl_info
->fbo_ops
.glFramebufferRenderbuffer(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_RENDERBUFFER
, 0);
1827 gl_info
->fbo_ops
.glDeleteRenderbuffers(1, &color_rb
);
1830 delete_fbo_attachment(gl_info
, type
, object
);
1831 checkGLcall("Framebuffer format check cleaup");
1834 if (fallback_fmt_used
&& regular_fmt_used
)
1836 FIXME("Format %s needs different render target formats for different resource types.\n",
1837 debug_d3dformat(format
->id
));
1838 format_clear_flag(format
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
1839 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
1843 static void query_format_flag(struct wined3d_gl_info
*gl_info
, struct wined3d_format
*format
,
1844 GLint internal
, GLenum pname
, DWORD flag
, const char *string
)
1847 enum wined3d_gl_resource_type type
;
1849 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
1851 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
), internal
, pname
, 1, &value
);
1852 if (value
== GL_FULL_SUPPORT
)
1854 TRACE("Format %s supports %s, resource type %u.\n", debug_d3dformat(format
->id
), string
, type
);
1855 format
->flags
[type
] |= flag
;
1859 TRACE("Format %s doesn't support %s, resource type %u.\n", debug_d3dformat(format
->id
), string
, type
);
1860 format
->flags
[type
] &= ~flag
;
1865 /* Context activation is done by the caller. */
1866 static void init_format_fbo_compat_info(struct wined3d_gl_info
*gl_info
)
1868 unsigned int i
, type
;
1871 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
1873 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); ++i
)
1876 struct wined3d_format
*format
= &gl_info
->formats
[i
];
1877 BOOL fallback_fmt_used
= FALSE
, regular_fmt_used
= FALSE
;
1878 GLenum rt_internal
= format
->rtInternal
;
1880 if (!format
->glInternal
)
1883 for (type
= 0; type
< ARRAY_SIZE(format
->flags
); ++type
)
1885 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
1886 format
->glInternal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
1887 if (value
== GL_FULL_SUPPORT
)
1889 TRACE("Format %s is supported as FBO color attachment, resource type %u.\n",
1890 debug_d3dformat(format
->id
), type
);
1891 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE
;
1892 format
->rtInternal
= format
->glInternal
;
1893 regular_fmt_used
= TRUE
;
1895 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
1896 format
->glInternal
, GL_FRAMEBUFFER_BLEND
, 1, &value
);
1897 if (value
== GL_FULL_SUPPORT
)
1899 TRACE("Format %s supports post-pixelshader blending, resource type %u.\n",
1900 debug_d3dformat(format
->id
), type
);
1901 format
->flags
[type
] |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
1905 TRACE("Format %s doesn't support post-pixelshader blending, resource typed %u.\n",
1906 debug_d3dformat(format
->id
), type
);
1907 format
->flags
[type
] &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
;
1914 if (format
->flags
[type
] & WINED3DFMT_FLAG_RENDERTARGET
)
1916 WARN("Format %s with rendertarget flag is not supported as FBO color attachment"
1917 " and no fallback specified, resource type %u.\n",
1918 debug_d3dformat(format
->id
), type
);
1919 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
1922 TRACE("Format %s is not supported as FBO color attachment,"
1923 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
1924 format
->rtInternal
= format
->glInternal
;
1928 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
1929 rt_internal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
1930 if (value
== GL_FULL_SUPPORT
)
1932 TRACE("Format %s rtInternal format is supported as FBO color attachment,"
1933 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
1934 fallback_fmt_used
= TRUE
;
1938 WARN("Format %s rtInternal format is not supported as FBO color attachment,"
1939 " resource type %u.\n", debug_d3dformat(format
->id
), type
);
1940 format
->flags
[type
] &= ~WINED3DFMT_FLAG_RENDERTARGET
;
1945 if (format
->glInternal
!= format
->glGammaInternal
)
1947 gl_info
->gl_ops
.ext
.p_glGetInternalformativ(wined3d_gl_type_to_enum(type
),
1948 format
->glGammaInternal
, GL_FRAMEBUFFER_RENDERABLE
, 1, &value
);
1949 if (value
== GL_FULL_SUPPORT
)
1951 TRACE("Format %s's sRGB format is FBO attachable, resource type %u.\n",
1952 debug_d3dformat(format
->id
), type
);
1953 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
1957 WARN("Format %s's sRGB format is not FBO attachable, resource type %u.\n",
1958 debug_d3dformat(format
->id
), type
);
1961 else if (format
->flags
[type
] & WINED3DFMT_FLAG_FBO_ATTACHABLE
)
1962 format
->flags
[type
] |= WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
;
1965 if (fallback_fmt_used
&& regular_fmt_used
)
1967 FIXME("Format %s needs different render target formats for different resource types.\n",
1968 debug_d3dformat(format
->id
));
1969 format_clear_flag(format
, WINED3DFMT_FLAG_RENDERTARGET
| WINED3DFMT_FLAG_FBO_ATTACHABLE
1970 | WINED3DFMT_FLAG_FBO_ATTACHABLE_SRGB
| WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING
);
1976 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
1978 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
1979 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
1980 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
1981 gl_info
->gl_ops
.gl
.p_glReadBuffer(GL_COLOR_ATTACHMENT0
);
1984 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); ++i
)
1986 struct wined3d_format
*format
= &gl_info
->formats
[i
];
1988 if (!format
->glInternal
) continue;
1990 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_COMPRESSED
)
1992 TRACE("Skipping format %s because it's a compressed format.\n",
1993 debug_d3dformat(format
->id
));
1997 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
1999 TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(format
->id
));
2000 check_fbo_compat(gl_info
, format
);
2004 format
->rtInternal
= format
->glInternal
;
2008 if (wined3d_settings
.offscreen_rendering_mode
== ORM_FBO
)
2009 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2012 static BOOL
init_format_texture_info(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
2014 struct fragment_caps fragment_caps
;
2015 struct shader_caps shader_caps
;
2019 adapter
->fragment_pipe
->get_caps(gl_info
, &fragment_caps
);
2020 adapter
->shader_backend
->shader_get_caps(gl_info
, &shader_caps
);
2021 srgb_write
= (fragment_caps
.wined3d_caps
& WINED3D_FRAGMENT_CAP_SRGB_WRITE
)
2022 && (shader_caps
.wined3d_caps
& WINED3D_SHADER_CAP_SRGB_WRITE
);
2024 for (i
= 0; i
< sizeof(format_texture_info
) / sizeof(*format_texture_info
); ++i
)
2026 int fmt_idx
= getFmtIdx(format_texture_info
[i
].id
);
2027 struct wined3d_format
*format
;
2031 ERR("Format %s (%#x) not found.\n",
2032 debug_d3dformat(format_texture_info
[i
].id
), format_texture_info
[i
].id
);
2036 if (!gl_info
->supported
[format_texture_info
[i
].extension
]) continue;
2038 format
= &gl_info
->formats
[fmt_idx
];
2040 /* ARB_texture_rg defines floating point formats, but only if
2041 * ARB_texture_float is also supported. */
2042 if (!gl_info
->supported
[ARB_TEXTURE_FLOAT
]
2043 && (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_FLOAT
))
2046 format
->glInternal
= format_texture_info
[i
].gl_internal
;
2047 format
->glGammaInternal
= format_texture_info
[i
].gl_srgb_internal
;
2048 format
->rtInternal
= format_texture_info
[i
].gl_rt_internal
;
2049 format
->glFormat
= format_texture_info
[i
].gl_format
;
2050 format
->glType
= format_texture_info
[i
].gl_type
;
2051 format
->color_fixup
= COLOR_FIXUP_IDENTITY
;
2052 format
->height_scale
.numerator
= 1;
2053 format
->height_scale
.denominator
= 1;
2055 format
->flags
[WINED3D_GL_RES_TYPE_TEX_1D
] |= format_texture_info
[i
].flags
;
2056 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] |= format_texture_info
[i
].flags
;
2057 format
->flags
[WINED3D_GL_RES_TYPE_BUFFER
] |= format_texture_info
[i
].flags
;
2059 /* GL_ARB_depth_texture does not support 3D textures. It also says "cube textures are
2060 * problematic", but doesn't explicitly mandate that an error is generated. */
2061 if (gl_info
->supported
[EXT_TEXTURE3D
]
2062 && !(format_texture_info
[i
].flags
& (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
)))
2063 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] |= format_texture_info
[i
].flags
;
2065 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
2066 format
->flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] |= format_texture_info
[i
].flags
;
2068 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
2069 format
->flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] |= format_texture_info
[i
].flags
;
2071 format
->flags
[WINED3D_GL_RES_TYPE_RB
] |= format_texture_info
[i
].flags
;
2072 format
->flags
[WINED3D_GL_RES_TYPE_RB
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2074 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2076 query_format_flag(gl_info
, format
, format
->glInternal
, GL_VERTEX_TEXTURE
,
2077 WINED3DFMT_FLAG_VTF
, "vertex texture usage");
2078 query_format_flag(gl_info
, format
, format
->glInternal
, GL_FILTER
,
2079 WINED3DFMT_FLAG_FILTERING
, "filtering");
2081 if (format
->glGammaInternal
!= format
->glInternal
)
2083 query_format_flag(gl_info
, format
, format
->glGammaInternal
, GL_SRGB_READ
,
2084 WINED3DFMT_FLAG_SRGB_READ
, "sRGB read");
2087 query_format_flag(gl_info
, format
, format
->glGammaInternal
, GL_SRGB_WRITE
,
2088 WINED3DFMT_FLAG_SRGB_WRITE
, "sRGB write");
2090 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2092 if (!(format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & (WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
)))
2093 format
->glGammaInternal
= format
->glInternal
;
2094 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2095 format
->glInternal
= format
->glGammaInternal
;
2100 if (!gl_info
->limits
.vertex_samplers
)
2101 format_clear_flag(format
, WINED3DFMT_FLAG_VTF
);
2103 if (!(gl_info
->quirks
& WINED3D_QUIRK_LIMITED_TEX_FILTERING
))
2104 format_set_flag(format
, WINED3DFMT_FLAG_FILTERING
);
2105 else if (format
->id
!= WINED3DFMT_R32G32B32A32_FLOAT
&& format
->id
!= WINED3DFMT_R32_FLOAT
)
2106 format_clear_flag(format
, WINED3DFMT_FLAG_VTF
);
2108 if (format
->glGammaInternal
!= format
->glInternal
)
2110 /* Filter sRGB capabilities if EXT_texture_sRGB is not supported. */
2111 if (!gl_info
->supported
[EXT_TEXTURE_SRGB
])
2113 format
->glGammaInternal
= format
->glInternal
;
2114 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_READ
| WINED3DFMT_FLAG_SRGB_WRITE
);
2116 else if (gl_info
->supported
[EXT_TEXTURE_SRGB_DECODE
])
2118 format
->glInternal
= format
->glGammaInternal
;
2122 if ((format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_SRGB_WRITE
) && !srgb_write
)
2123 format_clear_flag(format
, WINED3DFMT_FLAG_SRGB_WRITE
);
2125 if (!gl_info
->supported
[ARB_DEPTH_TEXTURE
]
2126 && format_texture_info
[i
].flags
& (WINED3DFMT_FLAG_DEPTH
| WINED3DFMT_FLAG_STENCIL
))
2128 format
->flags
[WINED3D_GL_RES_TYPE_TEX_1D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2129 format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2130 format
->flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2131 format
->flags
[WINED3D_GL_RES_TYPE_TEX_CUBE
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2132 format
->flags
[WINED3D_GL_RES_TYPE_TEX_RECT
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2136 /* Texture conversion stuff */
2137 format
->convert
= format_texture_info
[i
].convert
;
2138 format
->conv_byte_count
= format_texture_info
[i
].conv_byte_count
;
2144 static BOOL
color_match(DWORD c1
, DWORD c2
, BYTE max_diff
)
2146 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2148 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2150 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2152 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
2156 /* A context is provided by the caller */
2157 static BOOL
check_filter(const struct wined3d_gl_info
*gl_info
, GLenum internal
)
2159 static const DWORD data
[] = {0x00000000, 0xffffffff};
2160 GLuint tex
, fbo
, buffer
;
2161 DWORD readback
[16 * 1];
2164 /* Render a filtered texture and see what happens. This is intended to detect the lack of
2165 * float16 filtering on ATI X1000 class cards. The drivers disable filtering instead of
2166 * falling back to software. If this changes in the future this code will get fooled and
2167 * apps might hit the software path due to incorrectly advertised caps.
2169 * Its unlikely that this changes however. GL Games like Mass Effect depend on the filter
2170 * disable fallback, if Apple or ATI ever change the driver behavior they will break more
2171 * than Wine. The Linux binary <= r500 driver is not maintained any more anyway
2174 while (gl_info
->gl_ops
.gl
.p_glGetError());
2176 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &buffer
);
2177 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
2178 memset(readback
, 0x7e, sizeof(readback
));
2179 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA8
, 16, 1, 0,
2180 GL_RGBA
, GL_UNSIGNED_INT_8_8_8_8
, readback
);
2181 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2182 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2183 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
2184 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
2185 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
2187 gl_info
->gl_ops
.gl
.p_glGenTextures(1, &tex
);
2188 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, tex
);
2189 gl_info
->gl_ops
.gl
.p_glTexImage2D(GL_TEXTURE_2D
, 0, internal
, 2, 1, 0,
2190 GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, data
);
2191 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
2192 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
2193 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
2194 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
2195 gl_info
->gl_ops
.gl
.p_glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
2196 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
2198 gl_info
->fbo_ops
.glGenFramebuffers(1, &fbo
);
2199 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, fbo
);
2200 gl_info
->fbo_ops
.glFramebufferTexture2D(GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, buffer
, 0);
2201 gl_info
->gl_ops
.gl
.p_glDrawBuffer(GL_COLOR_ATTACHMENT0
);
2203 gl_info
->gl_ops
.gl
.p_glViewport(0, 0, 16, 1);
2204 gl_info
->gl_ops
.gl
.p_glDisable(GL_LIGHTING
);
2205 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_MODELVIEW
);
2206 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2207 gl_info
->gl_ops
.gl
.p_glMatrixMode(GL_PROJECTION
);
2208 gl_info
->gl_ops
.gl
.p_glLoadIdentity();
2210 gl_info
->gl_ops
.gl
.p_glClearColor(0, 1, 0, 0);
2211 gl_info
->gl_ops
.gl
.p_glClear(GL_COLOR_BUFFER_BIT
);
2213 gl_info
->gl_ops
.gl
.p_glBegin(GL_TRIANGLE_STRIP
);
2214 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 0.0);
2215 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, -1.0f
);
2216 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 0.0);
2217 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, -1.0f
);
2218 gl_info
->gl_ops
.gl
.p_glTexCoord2f(0.0, 1.0);
2219 gl_info
->gl_ops
.gl
.p_glVertex2f(-1.0f
, 1.0f
);
2220 gl_info
->gl_ops
.gl
.p_glTexCoord2f(1.0, 1.0);
2221 gl_info
->gl_ops
.gl
.p_glVertex2f(1.0f
, 1.0f
);
2222 gl_info
->gl_ops
.gl
.p_glEnd();
2224 gl_info
->gl_ops
.gl
.p_glBindTexture(GL_TEXTURE_2D
, buffer
);
2225 memset(readback
, 0x7f, sizeof(readback
));
2226 gl_info
->gl_ops
.gl
.p_glGetTexImage(GL_TEXTURE_2D
, 0, GL_BGRA
, GL_UNSIGNED_INT_8_8_8_8_REV
, readback
);
2227 if (color_match(readback
[6], 0xffffffff, 5) || color_match(readback
[6], 0x00000000, 5)
2228 || color_match(readback
[9], 0xffffffff, 5) || color_match(readback
[9], 0x00000000, 5))
2230 TRACE("Read back colors 0x%08x and 0x%08x close to unfiltered color, assuming no filtering\n",
2231 readback
[6], readback
[9]);
2236 TRACE("Read back colors are 0x%08x and 0x%08x, assuming texture is filtered\n",
2237 readback
[6], readback
[9]);
2241 gl_info
->fbo_ops
.glBindFramebuffer(GL_FRAMEBUFFER
, 0);
2242 gl_info
->fbo_ops
.glDeleteFramebuffers(1, &fbo
);
2243 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &tex
);
2244 gl_info
->gl_ops
.gl
.p_glDeleteTextures(1, &buffer
);
2246 if (gl_info
->gl_ops
.gl
.p_glGetError())
2248 FIXME("Error during filtering test for format %x, returning no filtering\n", internal
);
2255 static void init_format_filter_info(struct wined3d_gl_info
*gl_info
, enum wined3d_pci_vendor vendor
)
2257 struct wined3d_format
*format
;
2258 unsigned int fmt_idx
, i
;
2259 static const enum wined3d_format_id fmts16
[] =
2261 WINED3DFMT_R16_FLOAT
,
2262 WINED3DFMT_R16G16_FLOAT
,
2263 WINED3DFMT_R16G16B16A16_FLOAT
,
2267 if (gl_info
->supported
[ARB_INTERNALFORMAT_QUERY2
])
2268 /* This was already handled by init_format_texture_info(). */
2271 if(wined3d_settings
.offscreen_rendering_mode
!= ORM_FBO
)
2273 WARN("No FBO support, or no FBO ORM, guessing filter info from GL caps\n");
2274 if (vendor
== HW_VENDOR_NVIDIA
&& gl_info
->supported
[ARB_TEXTURE_FLOAT
])
2276 TRACE("Nvidia card with texture_float support: Assuming float16 blending\n");
2279 else if (gl_info
->limits
.glsl_varyings
> 44)
2281 TRACE("More than 44 GLSL varyings - assuming d3d10 card with float16 blending\n");
2286 TRACE("Assuming no float16 blending\n");
2292 for(i
= 0; i
< (sizeof(fmts16
) / sizeof(*fmts16
)); i
++)
2294 fmt_idx
= getFmtIdx(fmts16
[i
]);
2295 format_set_flag(&gl_info
->formats
[fmt_idx
], WINED3DFMT_FLAG_FILTERING
);
2301 for(i
= 0; i
< (sizeof(fmts16
) / sizeof(*fmts16
)); i
++)
2303 fmt_idx
= getFmtIdx(fmts16
[i
]);
2304 format
= &gl_info
->formats
[fmt_idx
];
2305 if (!format
->glInternal
) continue; /* Not supported by GL */
2307 filtered
= check_filter(gl_info
, gl_info
->formats
[fmt_idx
].glInternal
);
2310 TRACE("Format %s supports filtering\n", debug_d3dformat(fmts16
[i
]));
2311 format_set_flag(format
, WINED3DFMT_FLAG_FILTERING
);
2315 TRACE("Format %s does not support filtering\n", debug_d3dformat(fmts16
[i
]));
2320 static void apply_format_fixups(struct wined3d_adapter
*adapter
, struct wined3d_gl_info
*gl_info
)
2325 idx
= getFmtIdx(WINED3DFMT_R16_FLOAT
);
2326 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2327 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2329 idx
= getFmtIdx(WINED3DFMT_R32_FLOAT
);
2330 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2331 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2333 idx
= getFmtIdx(WINED3DFMT_R16G16_UNORM
);
2334 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2335 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2337 idx
= getFmtIdx(WINED3DFMT_R16G16_FLOAT
);
2338 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2339 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2341 idx
= getFmtIdx(WINED3DFMT_R32G32_FLOAT
);
2342 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2343 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_W
);
2345 /* GL_ATI_envmap_bumpmap in theory supports R8G8_SNORM but is no longer supported by
2347 if (gl_info
->supported
[NV_TEXTURE_SHADER
] || gl_info
->supported
[EXT_TEXTURE_SNORM
])
2349 /* R8G8_SNORM and R16G16_SNORM need a fixup of the undefined blue channel. OpenGL
2350 * returns 0.0 when sampling from it, DirectX 1.0. So we always have in-shader
2351 * conversion for this format. */
2352 idx
= getFmtIdx(WINED3DFMT_R8G8_SNORM
);
2353 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2354 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2355 idx
= getFmtIdx(WINED3DFMT_R16G16_SNORM
);
2356 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2357 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2361 /* Emulate using unsigned formats. This requires load-time conversion in addition to the
2363 idx
= getFmtIdx(WINED3DFMT_R8G8_SNORM
);
2364 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2365 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2366 idx
= getFmtIdx(WINED3DFMT_R16G16_SNORM
);
2367 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2368 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2369 idx
= getFmtIdx(WINED3DFMT_R8G8B8A8_SNORM
);
2370 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2371 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 1, CHANNEL_SOURCE_Z
, 1, CHANNEL_SOURCE_W
);
2372 idx
= getFmtIdx(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
2373 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2374 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Z
, 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_ONE
);
2377 if (!gl_info
->supported
[NV_TEXTURE_SHADER
])
2379 idx
= getFmtIdx(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
2380 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2381 1, CHANNEL_SOURCE_X
, 1, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_Z
, 0, CHANNEL_SOURCE_W
);
2384 if (gl_info
->supported
[ARB_TEXTURE_COMPRESSION_RGTC
] || gl_info
->supported
[EXT_TEXTURE_COMPRESSION_RGTC
])
2386 idx
= getFmtIdx(WINED3DFMT_ATI1N
);
2387 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2388 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_X
);
2390 idx
= getFmtIdx(WINED3DFMT_ATI2N
);
2391 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2392 0, CHANNEL_SOURCE_Y
, 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2394 else if (gl_info
->supported
[ATI_TEXTURE_COMPRESSION_3DC
])
2396 idx
= getFmtIdx(WINED3DFMT_ATI2N
);
2397 gl_info
->formats
[idx
].color_fixup
= create_color_fixup_desc(
2398 0, CHANNEL_SOURCE_X
, 0, CHANNEL_SOURCE_W
, 0, CHANNEL_SOURCE_ONE
, 0, CHANNEL_SOURCE_ONE
);
2401 if (!gl_info
->supported
[APPLE_YCBCR_422
])
2403 idx
= getFmtIdx(WINED3DFMT_YUY2
);
2404 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YUY2
);
2406 idx
= getFmtIdx(WINED3DFMT_UYVY
);
2407 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_UYVY
);
2410 idx
= getFmtIdx(WINED3DFMT_YV12
);
2411 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_HEIGHT_SCALE
);
2412 gl_info
->formats
[idx
].height_scale
.numerator
= 3;
2413 gl_info
->formats
[idx
].height_scale
.denominator
= 2;
2414 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_YV12
);
2416 idx
= getFmtIdx(WINED3DFMT_NV12
);
2417 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_HEIGHT_SCALE
);
2418 gl_info
->formats
[idx
].height_scale
.numerator
= 3;
2419 gl_info
->formats
[idx
].height_scale
.denominator
= 2;
2420 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_NV12
);
2422 if (gl_info
->supported
[ARB_FRAGMENT_PROGRAM
])
2424 idx
= getFmtIdx(WINED3DFMT_P8_UINT
);
2425 gl_info
->formats
[idx
].color_fixup
= create_complex_fixup_desc(COMPLEX_FIXUP_P8
);
2428 if (gl_info
->supported
[ARB_VERTEX_ARRAY_BGRA
])
2430 idx
= getFmtIdx(WINED3DFMT_B8G8R8A8_UNORM
);
2431 gl_info
->formats
[idx
].gl_vtx_format
= GL_BGRA
;
2434 if (gl_info
->supported
[ARB_HALF_FLOAT_VERTEX
])
2436 /* Do not change the size of the type, it is CPU side. We have to change the GPU-side information though.
2437 * It is the job of the vertex buffer code to make sure that the vbos have the right format */
2438 idx
= getFmtIdx(WINED3DFMT_R16G16_FLOAT
);
2439 gl_info
->formats
[idx
].gl_vtx_type
= GL_HALF_FLOAT
; /* == GL_HALF_FLOAT_NV */
2441 idx
= getFmtIdx(WINED3DFMT_R16G16B16A16_FLOAT
);
2442 gl_info
->formats
[idx
].gl_vtx_type
= GL_HALF_FLOAT
;
2445 if (!gl_info
->supported
[ARB_HALF_FLOAT_PIXEL
])
2447 idx
= getFmtIdx(WINED3DFMT_R16_FLOAT
);
2448 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2450 idx
= getFmtIdx(WINED3DFMT_R16G16_FLOAT
);
2451 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2453 idx
= getFmtIdx(WINED3DFMT_R16G16B16A16_FLOAT
);
2454 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2457 if (gl_info
->quirks
& WINED3D_QUIRK_BROKEN_RGBA16
)
2459 idx
= getFmtIdx(WINED3DFMT_R16G16B16A16_UNORM
);
2460 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2463 /* ATI instancing hack: Although ATI cards do not support Shader Model
2464 * 3.0, they support instancing. To query if the card supports instancing
2465 * CheckDeviceFormat() with the special format MAKEFOURCC('I','N','S','T')
2466 * is used. Should an application check for this, provide a proper return
2467 * value. We can do instancing with all shader versions, but we need
2470 * Additionally applications have to set the D3DRS_POINTSIZE render state
2471 * to MAKEFOURCC('I','N','S','T') once to enable instancing. Wined3d
2472 * doesn't need that and just ignores it.
2474 * With Shader Model 3.0 capable cards Instancing 'just works' in Windows. */
2475 /* FIXME: This should just check the shader backend caps. */
2476 if (gl_info
->supported
[ARB_VERTEX_PROGRAM
] || gl_info
->supported
[ARB_VERTEX_SHADER
])
2478 idx
= getFmtIdx(WINED3DFMT_INST
);
2479 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2482 /* Depth bound test. To query if the card supports it CheckDeviceFormat()
2483 * with the special format MAKEFOURCC('N','V','D','B') is used. It is
2484 * enabled by setting D3DRS_ADAPTIVETESS_X render state to
2485 * MAKEFOURCC('N','V','D','B') and then controlled by setting
2486 * D3DRS_ADAPTIVETESS_Z (zMin) and D3DRS_ADAPTIVETESS_W (zMax) to test
2488 if (gl_info
->supported
[EXT_DEPTH_BOUNDS_TEST
])
2490 idx
= getFmtIdx(WINED3DFMT_NVDB
);
2491 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2494 /* RESZ aka AMD DX9-level hack for multisampled depth buffer resolve. You query for RESZ
2495 * support by checking for availability of MAKEFOURCC('R','E','S','Z') surfaces with
2496 * RENDERTARGET usage. */
2497 if (gl_info
->supported
[ARB_FRAMEBUFFER_OBJECT
])
2499 idx
= getFmtIdx(WINED3DFMT_RESZ
);
2500 format_set_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
| WINED3DFMT_FLAG_RENDERTARGET
);
2503 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); ++i
)
2505 struct wined3d_format
*format
= &gl_info
->formats
[i
];
2507 if (!(format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_TEXTURE
))
2510 if (!adapter
->shader_backend
->shader_color_fixup_supported(format
->color_fixup
)
2511 || !adapter
->fragment_pipe
->color_fixup_supported(format
->color_fixup
))
2512 format_clear_flag(&gl_info
->formats
[idx
], WINED3DFMT_FLAG_TEXTURE
);
2515 /* GL_EXT_texture_compression_s3tc does not support 3D textures. Some Windows drivers
2516 * for dx9 GPUs support it, some do not, so not supporting DXTn volumes is OK for d3d9.
2518 * Note that GL_NV_texture_compression_vtc adds this functionality to OpenGL, but the
2519 * block layout is not compatible with the one used by d3d. See volume_dxt5_test. */
2520 idx
= getFmtIdx(WINED3DFMT_DXT1
);
2521 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2522 idx
= getFmtIdx(WINED3DFMT_DXT2
);
2523 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2524 idx
= getFmtIdx(WINED3DFMT_DXT3
);
2525 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2526 idx
= getFmtIdx(WINED3DFMT_DXT4
);
2527 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2528 idx
= getFmtIdx(WINED3DFMT_DXT5
);
2529 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2530 /* Similarly with ATI1N / ATI2N and GL_ARB_texture_compression_rgtc. */
2531 idx
= getFmtIdx(WINED3DFMT_ATI1N
);
2532 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2533 idx
= getFmtIdx(WINED3DFMT_ATI2N
);
2534 gl_info
->formats
[idx
].flags
[WINED3D_GL_RES_TYPE_TEX_3D
] &= ~WINED3DFMT_FLAG_TEXTURE
;
2537 static BOOL
init_format_vertex_info(struct wined3d_gl_info
*gl_info
)
2541 for (i
= 0; i
< (sizeof(format_vertex_info
) / sizeof(*format_vertex_info
)); ++i
)
2543 struct wined3d_format
*format
;
2544 int fmt_idx
= getFmtIdx(format_vertex_info
[i
].id
);
2548 ERR("Format %s (%#x) not found.\n",
2549 debug_d3dformat(format_vertex_info
[i
].id
), format_vertex_info
[i
].id
);
2553 format
= &gl_info
->formats
[fmt_idx
];
2554 format
->emit_idx
= format_vertex_info
[i
].emit_idx
;
2555 format
->component_count
= format_vertex_info
[i
].component_count
;
2556 format
->gl_vtx_type
= format_vertex_info
[i
].gl_vtx_type
;
2557 format
->gl_vtx_format
= format_vertex_info
[i
].gl_vtx_format
;
2558 format
->gl_normalized
= format_vertex_info
[i
].gl_normalized
;
2559 format
->component_size
= format_vertex_info
[i
].component_size
;
2565 BOOL
initPixelFormatsNoGL(struct wined3d_gl_info
*gl_info
)
2567 if (!init_format_base_info(gl_info
)) return FALSE
;
2569 if (!init_format_block_info(gl_info
))
2571 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
2572 gl_info
->formats
= NULL
;
2579 /* Context activation is done by the caller. */
2580 BOOL
wined3d_adapter_init_format_info(struct wined3d_adapter
*adapter
)
2582 struct wined3d_gl_info
*gl_info
= &adapter
->gl_info
;
2584 if (!init_format_base_info(gl_info
)) return FALSE
;
2586 if (!init_format_block_info(gl_info
)) goto fail
;
2587 if (!init_format_texture_info(adapter
, gl_info
)) goto fail
;
2588 if (!init_format_vertex_info(gl_info
)) goto fail
;
2590 apply_format_fixups(adapter
, gl_info
);
2591 init_format_fbo_compat_info(gl_info
);
2592 init_format_filter_info(gl_info
, adapter
->driver_info
.vendor
);
2597 HeapFree(GetProcessHeap(), 0, gl_info
->formats
);
2598 gl_info
->formats
= NULL
;
2602 const struct wined3d_format
*wined3d_get_format(const struct wined3d_gl_info
*gl_info
,
2603 enum wined3d_format_id format_id
)
2605 int idx
= getFmtIdx(format_id
);
2609 FIXME("Can't find format %s (%#x) in the format lookup table\n",
2610 debug_d3dformat(format_id
), format_id
);
2611 /* Get the caller a valid pointer */
2612 idx
= getFmtIdx(WINED3DFMT_UNKNOWN
);
2615 return &gl_info
->formats
[idx
];
2618 UINT
wined3d_format_calculate_pitch(const struct wined3d_format
*format
, UINT width
)
2620 /* For block based formats, pitch means the amount of bytes to the next
2621 * row of blocks rather than the next row of pixels. */
2622 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BLOCKS
)
2623 return format
->block_byte_count
* ((width
+ format
->block_width
- 1) / format
->block_width
);
2625 return format
->byte_count
* width
;
2628 UINT
wined3d_format_calculate_size(const struct wined3d_format
*format
, UINT alignment
,
2629 UINT width
, UINT height
, UINT depth
)
2631 UINT pitch
= wined3d_format_calculate_pitch(format
, width
);
2634 if (format
->id
== WINED3DFMT_UNKNOWN
)
2638 else if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_BLOCKS
)
2640 UINT row_count
= (height
+ format
->block_height
- 1) / format
->block_height
;
2641 size
= row_count
* ((pitch
+ alignment
- 1) & ~(alignment
- 1));
2645 size
= height
* ((pitch
+ alignment
- 1) & ~(alignment
- 1));
2648 if (format
->flags
[WINED3D_GL_RES_TYPE_TEX_2D
] & WINED3DFMT_FLAG_HEIGHT_SCALE
)
2650 /* The D3D format requirements make sure that the resulting format is an integer again */
2651 size
*= format
->height_scale
.numerator
;
2652 size
/= format
->height_scale
.denominator
;
2660 /*****************************************************************************
2661 * Trace formatting of useful values
2663 const char *debug_d3dformat(enum wined3d_format_id format_id
)
2667 #define FMT_TO_STR(format_id) case format_id: return #format_id
2668 FMT_TO_STR(WINED3DFMT_UNKNOWN
);
2669 FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM
);
2670 FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM
);
2671 FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM
);
2672 FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM
);
2673 FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM
);
2674 FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM
);
2675 FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM
);
2676 FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM
);
2677 FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM
);
2678 FMT_TO_STR(WINED3DFMT_P8_UINT
);
2679 FMT_TO_STR(WINED3DFMT_L8_UNORM
);
2680 FMT_TO_STR(WINED3DFMT_L8A8_UNORM
);
2681 FMT_TO_STR(WINED3DFMT_L4A4_UNORM
);
2682 FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM
);
2683 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM
);
2684 FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM
);
2685 FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM
);
2686 FMT_TO_STR(WINED3DFMT_UYVY
);
2687 FMT_TO_STR(WINED3DFMT_YUY2
);
2688 FMT_TO_STR(WINED3DFMT_YV12
);
2689 FMT_TO_STR(WINED3DFMT_NV12
);
2690 FMT_TO_STR(WINED3DFMT_DXT1
);
2691 FMT_TO_STR(WINED3DFMT_DXT2
);
2692 FMT_TO_STR(WINED3DFMT_DXT3
);
2693 FMT_TO_STR(WINED3DFMT_DXT4
);
2694 FMT_TO_STR(WINED3DFMT_DXT5
);
2695 FMT_TO_STR(WINED3DFMT_MULTI2_ARGB8
);
2696 FMT_TO_STR(WINED3DFMT_G8R8_G8B8
);
2697 FMT_TO_STR(WINED3DFMT_R8G8_B8G8
);
2698 FMT_TO_STR(WINED3DFMT_D16_LOCKABLE
);
2699 FMT_TO_STR(WINED3DFMT_D32_UNORM
);
2700 FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM
);
2701 FMT_TO_STR(WINED3DFMT_X8D24_UNORM
);
2702 FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM
);
2703 FMT_TO_STR(WINED3DFMT_L16_UNORM
);
2704 FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT
);
2705 FMT_TO_STR(WINED3DFMT_VERTEXDATA
);
2706 FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx
);
2707 FMT_TO_STR(WINED3DFMT_ATI1N
);
2708 FMT_TO_STR(WINED3DFMT_ATI2N
);
2709 FMT_TO_STR(WINED3DFMT_NVDB
);
2710 FMT_TO_STR(WINED3DFMT_NVHU
);
2711 FMT_TO_STR(WINED3DFMT_NVHS
);
2712 FMT_TO_STR(WINED3DFMT_R32G32B32A32_TYPELESS
);
2713 FMT_TO_STR(WINED3DFMT_R32G32B32A32_FLOAT
);
2714 FMT_TO_STR(WINED3DFMT_R32G32B32A32_UINT
);
2715 FMT_TO_STR(WINED3DFMT_R32G32B32A32_SINT
);
2716 FMT_TO_STR(WINED3DFMT_R32G32B32_TYPELESS
);
2717 FMT_TO_STR(WINED3DFMT_R32G32B32_FLOAT
);
2718 FMT_TO_STR(WINED3DFMT_R32G32B32_UINT
);
2719 FMT_TO_STR(WINED3DFMT_R32G32B32_SINT
);
2720 FMT_TO_STR(WINED3DFMT_R16G16B16A16_TYPELESS
);
2721 FMT_TO_STR(WINED3DFMT_R16G16B16A16_FLOAT
);
2722 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UNORM
);
2723 FMT_TO_STR(WINED3DFMT_R16G16B16A16_UINT
);
2724 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SNORM
);
2725 FMT_TO_STR(WINED3DFMT_R16G16B16A16_SINT
);
2726 FMT_TO_STR(WINED3DFMT_R32G32_TYPELESS
);
2727 FMT_TO_STR(WINED3DFMT_R32G32_FLOAT
);
2728 FMT_TO_STR(WINED3DFMT_R32G32_UINT
);
2729 FMT_TO_STR(WINED3DFMT_R32G32_SINT
);
2730 FMT_TO_STR(WINED3DFMT_R32G8X24_TYPELESS
);
2731 FMT_TO_STR(WINED3DFMT_D32_FLOAT_S8X24_UINT
);
2732 FMT_TO_STR(WINED3DFMT_R32_FLOAT_X8X24_TYPELESS
);
2733 FMT_TO_STR(WINED3DFMT_X32_TYPELESS_G8X24_UINT
);
2734 FMT_TO_STR(WINED3DFMT_R10G10B10A2_TYPELESS
);
2735 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UNORM
);
2736 FMT_TO_STR(WINED3DFMT_R10G10B10A2_UINT
);
2737 FMT_TO_STR(WINED3DFMT_R10G10B10A2_SNORM
);
2738 FMT_TO_STR(WINED3DFMT_R11G11B10_FLOAT
);
2739 FMT_TO_STR(WINED3DFMT_R8G8B8A8_TYPELESS
);
2740 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM
);
2741 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UNORM_SRGB
);
2742 FMT_TO_STR(WINED3DFMT_R8G8B8A8_UINT
);
2743 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SNORM
);
2744 FMT_TO_STR(WINED3DFMT_R8G8B8A8_SINT
);
2745 FMT_TO_STR(WINED3DFMT_R16G16_TYPELESS
);
2746 FMT_TO_STR(WINED3DFMT_R16G16_FLOAT
);
2747 FMT_TO_STR(WINED3DFMT_R16G16_UNORM
);
2748 FMT_TO_STR(WINED3DFMT_R16G16_UINT
);
2749 FMT_TO_STR(WINED3DFMT_R16G16_SNORM
);
2750 FMT_TO_STR(WINED3DFMT_R16G16_SINT
);
2751 FMT_TO_STR(WINED3DFMT_R32_TYPELESS
);
2752 FMT_TO_STR(WINED3DFMT_D32_FLOAT
);
2753 FMT_TO_STR(WINED3DFMT_R32_FLOAT
);
2754 FMT_TO_STR(WINED3DFMT_R32_UINT
);
2755 FMT_TO_STR(WINED3DFMT_R32_SINT
);
2756 FMT_TO_STR(WINED3DFMT_R24G8_TYPELESS
);
2757 FMT_TO_STR(WINED3DFMT_D24_UNORM_S8_UINT
);
2758 FMT_TO_STR(WINED3DFMT_R24_UNORM_X8_TYPELESS
);
2759 FMT_TO_STR(WINED3DFMT_X24_TYPELESS_G8_UINT
);
2760 FMT_TO_STR(WINED3DFMT_R8G8_TYPELESS
);
2761 FMT_TO_STR(WINED3DFMT_R8G8_UNORM
);
2762 FMT_TO_STR(WINED3DFMT_R8G8_UINT
);
2763 FMT_TO_STR(WINED3DFMT_R8G8_SNORM
);
2764 FMT_TO_STR(WINED3DFMT_R8G8_SINT
);
2765 FMT_TO_STR(WINED3DFMT_R16_TYPELESS
);
2766 FMT_TO_STR(WINED3DFMT_R16_FLOAT
);
2767 FMT_TO_STR(WINED3DFMT_D16_UNORM
);
2768 FMT_TO_STR(WINED3DFMT_R16_UNORM
);
2769 FMT_TO_STR(WINED3DFMT_R16_UINT
);
2770 FMT_TO_STR(WINED3DFMT_R16_SNORM
);
2771 FMT_TO_STR(WINED3DFMT_R16_SINT
);
2772 FMT_TO_STR(WINED3DFMT_R8_TYPELESS
);
2773 FMT_TO_STR(WINED3DFMT_R8_UNORM
);
2774 FMT_TO_STR(WINED3DFMT_R8_UINT
);
2775 FMT_TO_STR(WINED3DFMT_R8_SNORM
);
2776 FMT_TO_STR(WINED3DFMT_R8_SINT
);
2777 FMT_TO_STR(WINED3DFMT_A8_UNORM
);
2778 FMT_TO_STR(WINED3DFMT_R1_UNORM
);
2779 FMT_TO_STR(WINED3DFMT_R9G9B9E5_SHAREDEXP
);
2780 FMT_TO_STR(WINED3DFMT_R8G8_B8G8_UNORM
);
2781 FMT_TO_STR(WINED3DFMT_G8R8_G8B8_UNORM
);
2782 FMT_TO_STR(WINED3DFMT_BC1_TYPELESS
);
2783 FMT_TO_STR(WINED3DFMT_BC1_UNORM
);
2784 FMT_TO_STR(WINED3DFMT_BC1_UNORM_SRGB
);
2785 FMT_TO_STR(WINED3DFMT_BC2_TYPELESS
);
2786 FMT_TO_STR(WINED3DFMT_BC2_UNORM
);
2787 FMT_TO_STR(WINED3DFMT_BC2_UNORM_SRGB
);
2788 FMT_TO_STR(WINED3DFMT_BC3_TYPELESS
);
2789 FMT_TO_STR(WINED3DFMT_BC3_UNORM
);
2790 FMT_TO_STR(WINED3DFMT_BC3_UNORM_SRGB
);
2791 FMT_TO_STR(WINED3DFMT_BC4_TYPELESS
);
2792 FMT_TO_STR(WINED3DFMT_BC4_UNORM
);
2793 FMT_TO_STR(WINED3DFMT_BC4_SNORM
);
2794 FMT_TO_STR(WINED3DFMT_BC5_TYPELESS
);
2795 FMT_TO_STR(WINED3DFMT_BC5_UNORM
);
2796 FMT_TO_STR(WINED3DFMT_BC5_SNORM
);
2797 FMT_TO_STR(WINED3DFMT_B5G6R5_UNORM
);
2798 FMT_TO_STR(WINED3DFMT_B5G5R5A1_UNORM
);
2799 FMT_TO_STR(WINED3DFMT_B8G8R8A8_UNORM
);
2800 FMT_TO_STR(WINED3DFMT_B8G8R8X8_UNORM
);
2801 FMT_TO_STR(WINED3DFMT_INTZ
);
2802 FMT_TO_STR(WINED3DFMT_RESZ
);
2803 FMT_TO_STR(WINED3DFMT_NULL
);
2804 FMT_TO_STR(WINED3DFMT_R16
);
2805 FMT_TO_STR(WINED3DFMT_AL16
);
2810 fourcc
[0] = (char)(format_id
);
2811 fourcc
[1] = (char)(format_id
>> 8);
2812 fourcc
[2] = (char)(format_id
>> 16);
2813 fourcc
[3] = (char)(format_id
>> 24);
2815 if (isprint(fourcc
[0]) && isprint(fourcc
[1]) && isprint(fourcc
[2]) && isprint(fourcc
[3]))
2816 FIXME("Unrecognized %#x (as fourcc: %s) WINED3DFORMAT!\n", format_id
, fourcc
);
2818 FIXME("Unrecognized %#x WINED3DFORMAT!\n", format_id
);
2820 return "unrecognized";
2824 const char *debug_d3ddevicetype(enum wined3d_device_type device_type
)
2826 switch (device_type
)
2828 #define DEVTYPE_TO_STR(dev) case dev: return #dev
2829 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_HAL
);
2830 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_REF
);
2831 DEVTYPE_TO_STR(WINED3D_DEVICE_TYPE_SW
);
2832 #undef DEVTYPE_TO_STR
2834 FIXME("Unrecognized device type %#x.\n", device_type
);
2835 return "unrecognized";
2839 const char *debug_d3dusage(DWORD usage
)
2844 #define WINED3DUSAGE_TO_STR(u) if (usage & u) { strcat(buf, " | "#u); usage &= ~u; }
2845 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RENDERTARGET
);
2846 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DEPTHSTENCIL
);
2847 WINED3DUSAGE_TO_STR(WINED3DUSAGE_WRITEONLY
);
2848 WINED3DUSAGE_TO_STR(WINED3DUSAGE_SOFTWAREPROCESSING
);
2849 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DONOTCLIP
);
2850 WINED3DUSAGE_TO_STR(WINED3DUSAGE_POINTS
);
2851 WINED3DUSAGE_TO_STR(WINED3DUSAGE_RTPATCHES
);
2852 WINED3DUSAGE_TO_STR(WINED3DUSAGE_NPATCHES
);
2853 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DYNAMIC
);
2854 WINED3DUSAGE_TO_STR(WINED3DUSAGE_AUTOGENMIPMAP
);
2855 WINED3DUSAGE_TO_STR(WINED3DUSAGE_DMAP
);
2856 WINED3DUSAGE_TO_STR(WINED3DUSAGE_STATICDECL
);
2857 WINED3DUSAGE_TO_STR(WINED3DUSAGE_OVERLAY
);
2858 #undef WINED3DUSAGE_TO_STR
2859 if (usage
) FIXME("Unrecognized usage flag(s) %#x\n", usage
);
2861 return buf
[0] ? wine_dbg_sprintf("%s", &buf
[3]) : "0";
2864 const char *debug_d3dusagequery(DWORD usagequery
)
2869 #define WINED3DUSAGEQUERY_TO_STR(u) if (usagequery & u) { strcat(buf, " | "#u); usagequery &= ~u; }
2870 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_FILTER
);
2871 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_LEGACYBUMPMAP
);
2872 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
);
2873 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBREAD
);
2874 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_SRGBWRITE
);
2875 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_VERTEXTEXTURE
);
2876 WINED3DUSAGEQUERY_TO_STR(WINED3DUSAGE_QUERY_WRAPANDMIP
);
2877 #undef WINED3DUSAGEQUERY_TO_STR
2878 if (usagequery
) FIXME("Unrecognized usage query flag(s) %#x\n", usagequery
);
2880 return buf
[0] ? wine_dbg_sprintf("%s", &buf
[3]) : "0";
2883 const char *debug_d3ddeclmethod(enum wined3d_decl_method method
)
2887 #define WINED3DDECLMETHOD_TO_STR(u) case u: return #u
2888 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_DEFAULT
);
2889 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_U
);
2890 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_PARTIAL_V
);
2891 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_CROSS_UV
);
2892 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_UV
);
2893 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP
);
2894 WINED3DDECLMETHOD_TO_STR(WINED3D_DECL_METHOD_LOOKUP_PRESAMPLED
);
2895 #undef WINED3DDECLMETHOD_TO_STR
2897 FIXME("Unrecognized declaration method %#x.\n", method
);
2898 return "unrecognized";
2902 const char *debug_d3ddeclusage(enum wined3d_decl_usage usage
)
2906 #define WINED3DDECLUSAGE_TO_STR(u) case u: return #u
2907 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITION
);
2908 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_WEIGHT
);
2909 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BLEND_INDICES
);
2910 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_NORMAL
);
2911 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_PSIZE
);
2912 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TEXCOORD
);
2913 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TANGENT
);
2914 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_BINORMAL
);
2915 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_TESS_FACTOR
);
2916 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_POSITIONT
);
2917 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_COLOR
);
2918 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_FOG
);
2919 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_DEPTH
);
2920 WINED3DDECLUSAGE_TO_STR(WINED3D_DECL_USAGE_SAMPLE
);
2921 #undef WINED3DDECLUSAGE_TO_STR
2923 FIXME("Unrecognized %u declaration usage!\n", usage
);
2924 return "unrecognized";
2928 const char *debug_d3dinput_classification(enum wined3d_input_classification classification
)
2930 switch (classification
)
2932 #define WINED3D_TO_STR(x) case x: return #x
2933 WINED3D_TO_STR(WINED3D_INPUT_PER_VERTEX_DATA
);
2934 WINED3D_TO_STR(WINED3D_INPUT_PER_INSTANCE_DATA
);
2935 #undef WINED3D_TO_STR
2937 FIXME("Unrecognized input classification %#x.\n", classification
);
2938 return "unrecognized";
2942 const char *debug_d3dresourcetype(enum wined3d_resource_type resource_type
)
2944 switch (resource_type
)
2946 #define RES_TO_STR(res) case res: return #res
2947 RES_TO_STR(WINED3D_RTYPE_SURFACE
);
2948 RES_TO_STR(WINED3D_RTYPE_VOLUME
);
2949 RES_TO_STR(WINED3D_RTYPE_TEXTURE
);
2950 RES_TO_STR(WINED3D_RTYPE_VOLUME_TEXTURE
);
2951 RES_TO_STR(WINED3D_RTYPE_CUBE_TEXTURE
);
2952 RES_TO_STR(WINED3D_RTYPE_BUFFER
);
2955 FIXME("Unrecognized resource type %#x.\n", resource_type
);
2956 return "unrecognized";
2960 const char *debug_d3dprimitivetype(enum wined3d_primitive_type primitive_type
)
2962 switch (primitive_type
)
2964 #define PRIM_TO_STR(prim) case prim: return #prim
2965 PRIM_TO_STR(WINED3D_PT_UNDEFINED
);
2966 PRIM_TO_STR(WINED3D_PT_POINTLIST
);
2967 PRIM_TO_STR(WINED3D_PT_LINELIST
);
2968 PRIM_TO_STR(WINED3D_PT_LINESTRIP
);
2969 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST
);
2970 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP
);
2971 PRIM_TO_STR(WINED3D_PT_TRIANGLEFAN
);
2972 PRIM_TO_STR(WINED3D_PT_LINELIST_ADJ
);
2973 PRIM_TO_STR(WINED3D_PT_LINESTRIP_ADJ
);
2974 PRIM_TO_STR(WINED3D_PT_TRIANGLELIST_ADJ
);
2975 PRIM_TO_STR(WINED3D_PT_TRIANGLESTRIP_ADJ
);
2978 FIXME("Unrecognized %u primitive type!\n", primitive_type
);
2979 return "unrecognized";
2983 const char *debug_d3drenderstate(enum wined3d_render_state state
)
2987 #define D3DSTATE_TO_STR(u) case u: return #u
2988 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIAS
);
2989 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREPERSPECTIVE
);
2990 D3DSTATE_TO_STR(WINED3D_RS_WRAPU
);
2991 D3DSTATE_TO_STR(WINED3D_RS_WRAPV
);
2992 D3DSTATE_TO_STR(WINED3D_RS_ZENABLE
);
2993 D3DSTATE_TO_STR(WINED3D_RS_FILLMODE
);
2994 D3DSTATE_TO_STR(WINED3D_RS_SHADEMODE
);
2995 D3DSTATE_TO_STR(WINED3D_RS_LINEPATTERN
);
2996 D3DSTATE_TO_STR(WINED3D_RS_MONOENABLE
);
2997 D3DSTATE_TO_STR(WINED3D_RS_ROP2
);
2998 D3DSTATE_TO_STR(WINED3D_RS_PLANEMASK
);
2999 D3DSTATE_TO_STR(WINED3D_RS_ZWRITEENABLE
);
3000 D3DSTATE_TO_STR(WINED3D_RS_ALPHATESTENABLE
);
3001 D3DSTATE_TO_STR(WINED3D_RS_LASTPIXEL
);
3002 D3DSTATE_TO_STR(WINED3D_RS_SRCBLEND
);
3003 D3DSTATE_TO_STR(WINED3D_RS_DESTBLEND
);
3004 D3DSTATE_TO_STR(WINED3D_RS_CULLMODE
);
3005 D3DSTATE_TO_STR(WINED3D_RS_ZFUNC
);
3006 D3DSTATE_TO_STR(WINED3D_RS_ALPHAREF
);
3007 D3DSTATE_TO_STR(WINED3D_RS_ALPHAFUNC
);
3008 D3DSTATE_TO_STR(WINED3D_RS_DITHERENABLE
);
3009 D3DSTATE_TO_STR(WINED3D_RS_ALPHABLENDENABLE
);
3010 D3DSTATE_TO_STR(WINED3D_RS_FOGENABLE
);
3011 D3DSTATE_TO_STR(WINED3D_RS_SPECULARENABLE
);
3012 D3DSTATE_TO_STR(WINED3D_RS_ZVISIBLE
);
3013 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXEL
);
3014 D3DSTATE_TO_STR(WINED3D_RS_SUBPIXELX
);
3015 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEDALPHA
);
3016 D3DSTATE_TO_STR(WINED3D_RS_FOGCOLOR
);
3017 D3DSTATE_TO_STR(WINED3D_RS_FOGTABLEMODE
);
3018 D3DSTATE_TO_STR(WINED3D_RS_FOGSTART
);
3019 D3DSTATE_TO_STR(WINED3D_RS_FOGEND
);
3020 D3DSTATE_TO_STR(WINED3D_RS_FOGDENSITY
);
3021 D3DSTATE_TO_STR(WINED3D_RS_STIPPLEENABLE
);
3022 D3DSTATE_TO_STR(WINED3D_RS_EDGEANTIALIAS
);
3023 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYENABLE
);
3024 D3DSTATE_TO_STR(WINED3D_RS_MIPMAPLODBIAS
);
3025 D3DSTATE_TO_STR(WINED3D_RS_RANGEFOGENABLE
);
3026 D3DSTATE_TO_STR(WINED3D_RS_ANISOTROPY
);
3027 D3DSTATE_TO_STR(WINED3D_RS_FLUSHBATCH
);
3028 D3DSTATE_TO_STR(WINED3D_RS_TRANSLUCENTSORTINDEPENDENT
);
3029 D3DSTATE_TO_STR(WINED3D_RS_STENCILENABLE
);
3030 D3DSTATE_TO_STR(WINED3D_RS_STENCILFAIL
);
3031 D3DSTATE_TO_STR(WINED3D_RS_STENCILZFAIL
);
3032 D3DSTATE_TO_STR(WINED3D_RS_STENCILPASS
);
3033 D3DSTATE_TO_STR(WINED3D_RS_STENCILFUNC
);
3034 D3DSTATE_TO_STR(WINED3D_RS_STENCILREF
);
3035 D3DSTATE_TO_STR(WINED3D_RS_STENCILMASK
);
3036 D3DSTATE_TO_STR(WINED3D_RS_STENCILWRITEMASK
);
3037 D3DSTATE_TO_STR(WINED3D_RS_TEXTUREFACTOR
);
3038 D3DSTATE_TO_STR(WINED3D_RS_WRAP0
);
3039 D3DSTATE_TO_STR(WINED3D_RS_WRAP1
);
3040 D3DSTATE_TO_STR(WINED3D_RS_WRAP2
);
3041 D3DSTATE_TO_STR(WINED3D_RS_WRAP3
);
3042 D3DSTATE_TO_STR(WINED3D_RS_WRAP4
);
3043 D3DSTATE_TO_STR(WINED3D_RS_WRAP5
);
3044 D3DSTATE_TO_STR(WINED3D_RS_WRAP6
);
3045 D3DSTATE_TO_STR(WINED3D_RS_WRAP7
);
3046 D3DSTATE_TO_STR(WINED3D_RS_CLIPPING
);
3047 D3DSTATE_TO_STR(WINED3D_RS_LIGHTING
);
3048 D3DSTATE_TO_STR(WINED3D_RS_EXTENTS
);
3049 D3DSTATE_TO_STR(WINED3D_RS_AMBIENT
);
3050 D3DSTATE_TO_STR(WINED3D_RS_FOGVERTEXMODE
);
3051 D3DSTATE_TO_STR(WINED3D_RS_COLORVERTEX
);
3052 D3DSTATE_TO_STR(WINED3D_RS_LOCALVIEWER
);
3053 D3DSTATE_TO_STR(WINED3D_RS_NORMALIZENORMALS
);
3054 D3DSTATE_TO_STR(WINED3D_RS_COLORKEYBLENDENABLE
);
3055 D3DSTATE_TO_STR(WINED3D_RS_DIFFUSEMATERIALSOURCE
);
3056 D3DSTATE_TO_STR(WINED3D_RS_SPECULARMATERIALSOURCE
);
3057 D3DSTATE_TO_STR(WINED3D_RS_AMBIENTMATERIALSOURCE
);
3058 D3DSTATE_TO_STR(WINED3D_RS_EMISSIVEMATERIALSOURCE
);
3059 D3DSTATE_TO_STR(WINED3D_RS_VERTEXBLEND
);
3060 D3DSTATE_TO_STR(WINED3D_RS_CLIPPLANEENABLE
);
3061 D3DSTATE_TO_STR(WINED3D_RS_SOFTWAREVERTEXPROCESSING
);
3062 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE
);
3063 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MIN
);
3064 D3DSTATE_TO_STR(WINED3D_RS_POINTSPRITEENABLE
);
3065 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALEENABLE
);
3066 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_A
);
3067 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_B
);
3068 D3DSTATE_TO_STR(WINED3D_RS_POINTSCALE_C
);
3069 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEANTIALIAS
);
3070 D3DSTATE_TO_STR(WINED3D_RS_MULTISAMPLEMASK
);
3071 D3DSTATE_TO_STR(WINED3D_RS_PATCHEDGESTYLE
);
3072 D3DSTATE_TO_STR(WINED3D_RS_PATCHSEGMENTS
);
3073 D3DSTATE_TO_STR(WINED3D_RS_DEBUGMONITORTOKEN
);
3074 D3DSTATE_TO_STR(WINED3D_RS_POINTSIZE_MAX
);
3075 D3DSTATE_TO_STR(WINED3D_RS_INDEXEDVERTEXBLENDENABLE
);
3076 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE
);
3077 D3DSTATE_TO_STR(WINED3D_RS_TWEENFACTOR
);
3078 D3DSTATE_TO_STR(WINED3D_RS_BLENDOP
);
3079 D3DSTATE_TO_STR(WINED3D_RS_POSITIONDEGREE
);
3080 D3DSTATE_TO_STR(WINED3D_RS_NORMALDEGREE
);
3081 D3DSTATE_TO_STR(WINED3D_RS_SCISSORTESTENABLE
);
3082 D3DSTATE_TO_STR(WINED3D_RS_SLOPESCALEDEPTHBIAS
);
3083 D3DSTATE_TO_STR(WINED3D_RS_ANTIALIASEDLINEENABLE
);
3084 D3DSTATE_TO_STR(WINED3D_RS_MINTESSELLATIONLEVEL
);
3085 D3DSTATE_TO_STR(WINED3D_RS_MAXTESSELLATIONLEVEL
);
3086 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_X
);
3087 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Y
);
3088 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_Z
);
3089 D3DSTATE_TO_STR(WINED3D_RS_ADAPTIVETESS_W
);
3090 D3DSTATE_TO_STR(WINED3D_RS_ENABLEADAPTIVETESSELLATION
);
3091 D3DSTATE_TO_STR(WINED3D_RS_TWOSIDEDSTENCILMODE
);
3092 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILFAIL
);
3093 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILZFAIL
);
3094 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILPASS
);
3095 D3DSTATE_TO_STR(WINED3D_RS_CCW_STENCILFUNC
);
3096 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE1
);
3097 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE2
);
3098 D3DSTATE_TO_STR(WINED3D_RS_COLORWRITEENABLE3
);
3099 D3DSTATE_TO_STR(WINED3D_RS_BLENDFACTOR
);
3100 D3DSTATE_TO_STR(WINED3D_RS_SRGBWRITEENABLE
);
3101 D3DSTATE_TO_STR(WINED3D_RS_DEPTHBIAS
);
3102 D3DSTATE_TO_STR(WINED3D_RS_WRAP8
);
3103 D3DSTATE_TO_STR(WINED3D_RS_WRAP9
);
3104 D3DSTATE_TO_STR(WINED3D_RS_WRAP10
);
3105 D3DSTATE_TO_STR(WINED3D_RS_WRAP11
);
3106 D3DSTATE_TO_STR(WINED3D_RS_WRAP12
);
3107 D3DSTATE_TO_STR(WINED3D_RS_WRAP13
);
3108 D3DSTATE_TO_STR(WINED3D_RS_WRAP14
);
3109 D3DSTATE_TO_STR(WINED3D_RS_WRAP15
);
3110 D3DSTATE_TO_STR(WINED3D_RS_SEPARATEALPHABLENDENABLE
);
3111 D3DSTATE_TO_STR(WINED3D_RS_SRCBLENDALPHA
);
3112 D3DSTATE_TO_STR(WINED3D_RS_DESTBLENDALPHA
);
3113 D3DSTATE_TO_STR(WINED3D_RS_BLENDOPALPHA
);
3114 #undef D3DSTATE_TO_STR
3116 FIXME("Unrecognized %u render state!\n", state
);
3117 return "unrecognized";
3121 const char *debug_d3dsamplerstate(enum wined3d_sampler_state state
)
3125 #define D3DSTATE_TO_STR(u) case u: return #u
3126 D3DSTATE_TO_STR(WINED3D_SAMP_BORDER_COLOR
);
3127 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_U
);
3128 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_V
);
3129 D3DSTATE_TO_STR(WINED3D_SAMP_ADDRESS_W
);
3130 D3DSTATE_TO_STR(WINED3D_SAMP_MAG_FILTER
);
3131 D3DSTATE_TO_STR(WINED3D_SAMP_MIN_FILTER
);
3132 D3DSTATE_TO_STR(WINED3D_SAMP_MIP_FILTER
);
3133 D3DSTATE_TO_STR(WINED3D_SAMP_MIPMAP_LOD_BIAS
);
3134 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_MIP_LEVEL
);
3135 D3DSTATE_TO_STR(WINED3D_SAMP_MAX_ANISOTROPY
);
3136 D3DSTATE_TO_STR(WINED3D_SAMP_SRGB_TEXTURE
);
3137 D3DSTATE_TO_STR(WINED3D_SAMP_ELEMENT_INDEX
);
3138 D3DSTATE_TO_STR(WINED3D_SAMP_DMAP_OFFSET
);
3139 #undef D3DSTATE_TO_STR
3141 FIXME("Unrecognized %u sampler state!\n", state
);
3142 return "unrecognized";
3146 const char *debug_d3dtexturefiltertype(enum wined3d_texture_filter_type filter_type
)
3148 switch (filter_type
)
3150 #define D3DTEXTUREFILTERTYPE_TO_STR(u) case u: return #u
3151 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_NONE
);
3152 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_POINT
);
3153 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_LINEAR
);
3154 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_ANISOTROPIC
);
3155 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_FLAT_CUBIC
);
3156 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_CUBIC
);
3157 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_PYRAMIDAL_QUAD
);
3158 D3DTEXTUREFILTERTYPE_TO_STR(WINED3D_TEXF_GAUSSIAN_QUAD
);
3159 #undef D3DTEXTUREFILTERTYPE_TO_STR
3161 FIXME("Unrecognied texture filter type 0x%08x.\n", filter_type
);
3162 return "unrecognized";
3166 const char *debug_d3dtexturestate(enum wined3d_texture_stage_state state
)
3170 #define D3DSTATE_TO_STR(u) case u: return #u
3171 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_OP
);
3172 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG1
);
3173 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG2
);
3174 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_OP
);
3175 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG1
);
3176 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG2
);
3177 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT00
);
3178 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT01
);
3179 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT10
);
3180 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_MAT11
);
3181 D3DSTATE_TO_STR(WINED3D_TSS_TEXCOORD_INDEX
);
3182 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LSCALE
);
3183 D3DSTATE_TO_STR(WINED3D_TSS_BUMPENV_LOFFSET
);
3184 D3DSTATE_TO_STR(WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
);
3185 D3DSTATE_TO_STR(WINED3D_TSS_COLOR_ARG0
);
3186 D3DSTATE_TO_STR(WINED3D_TSS_ALPHA_ARG0
);
3187 D3DSTATE_TO_STR(WINED3D_TSS_RESULT_ARG
);
3188 D3DSTATE_TO_STR(WINED3D_TSS_CONSTANT
);
3189 #undef D3DSTATE_TO_STR
3191 FIXME("Unrecognized %u texture state!\n", state
);
3192 return "unrecognized";
3196 const char *debug_d3dtop(enum wined3d_texture_op d3dtop
)
3200 #define D3DTOP_TO_STR(u) case u: return #u
3201 D3DTOP_TO_STR(WINED3D_TOP_DISABLE
);
3202 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG1
);
3203 D3DTOP_TO_STR(WINED3D_TOP_SELECT_ARG2
);
3204 D3DTOP_TO_STR(WINED3D_TOP_MODULATE
);
3205 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_2X
);
3206 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_4X
);
3207 D3DTOP_TO_STR(WINED3D_TOP_ADD
);
3208 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED
);
3209 D3DTOP_TO_STR(WINED3D_TOP_ADD_SIGNED_2X
);
3210 D3DTOP_TO_STR(WINED3D_TOP_SUBTRACT
);
3211 D3DTOP_TO_STR(WINED3D_TOP_ADD_SMOOTH
);
3212 D3DTOP_TO_STR(WINED3D_TOP_BLEND_DIFFUSE_ALPHA
);
3213 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA
);
3214 D3DTOP_TO_STR(WINED3D_TOP_BLEND_FACTOR_ALPHA
);
3215 D3DTOP_TO_STR(WINED3D_TOP_BLEND_TEXTURE_ALPHA_PM
);
3216 D3DTOP_TO_STR(WINED3D_TOP_BLEND_CURRENT_ALPHA
);
3217 D3DTOP_TO_STR(WINED3D_TOP_PREMODULATE
);
3218 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_ALPHA_ADD_COLOR
);
3219 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_COLOR_ADD_ALPHA
);
3220 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVALPHA_ADD_COLOR
);
3221 D3DTOP_TO_STR(WINED3D_TOP_MODULATE_INVCOLOR_ADD_ALPHA
);
3222 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP
);
3223 D3DTOP_TO_STR(WINED3D_TOP_BUMPENVMAP_LUMINANCE
);
3224 D3DTOP_TO_STR(WINED3D_TOP_DOTPRODUCT3
);
3225 D3DTOP_TO_STR(WINED3D_TOP_MULTIPLY_ADD
);
3226 D3DTOP_TO_STR(WINED3D_TOP_LERP
);
3227 #undef D3DTOP_TO_STR
3229 FIXME("Unrecognized texture op %#x.\n", d3dtop
);
3230 return "unrecognized";
3234 const char *debug_d3dtstype(enum wined3d_transform_state tstype
)
3238 #define TSTYPE_TO_STR(tstype) case tstype: return #tstype
3239 TSTYPE_TO_STR(WINED3D_TS_VIEW
);
3240 TSTYPE_TO_STR(WINED3D_TS_PROJECTION
);
3241 TSTYPE_TO_STR(WINED3D_TS_TEXTURE0
);
3242 TSTYPE_TO_STR(WINED3D_TS_TEXTURE1
);
3243 TSTYPE_TO_STR(WINED3D_TS_TEXTURE2
);
3244 TSTYPE_TO_STR(WINED3D_TS_TEXTURE3
);
3245 TSTYPE_TO_STR(WINED3D_TS_TEXTURE4
);
3246 TSTYPE_TO_STR(WINED3D_TS_TEXTURE5
);
3247 TSTYPE_TO_STR(WINED3D_TS_TEXTURE6
);
3248 TSTYPE_TO_STR(WINED3D_TS_TEXTURE7
);
3249 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(0));
3250 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(1));
3251 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(2));
3252 TSTYPE_TO_STR(WINED3D_TS_WORLD_MATRIX(3));
3253 #undef TSTYPE_TO_STR
3255 if (tstype
> 256 && tstype
< 512)
3257 FIXME("WINED3D_TS_WORLD_MATRIX(%u). 1..255 not currently supported.\n", tstype
);
3258 return ("WINED3D_TS_WORLD_MATRIX > 0");
3260 FIXME("Unrecognized transform state %#x.\n", tstype
);
3261 return "unrecognized";
3265 static const char *debug_shader_type(enum wined3d_shader_type type
)
3269 #define WINED3D_TO_STR(type) case type: return #type
3270 WINED3D_TO_STR(WINED3D_SHADER_TYPE_PIXEL
);
3271 WINED3D_TO_STR(WINED3D_SHADER_TYPE_VERTEX
);
3272 WINED3D_TO_STR(WINED3D_SHADER_TYPE_GEOMETRY
);
3273 #undef WINED3D_TO_STR
3275 FIXME("Unrecognized shader type %#x.\n", type
);
3276 return "unrecognized";
3280 const char *debug_d3dstate(DWORD state
)
3282 if (STATE_IS_RENDER(state
))
3283 return wine_dbg_sprintf("STATE_RENDER(%s)", debug_d3drenderstate(state
- STATE_RENDER(0)));
3284 if (STATE_IS_TEXTURESTAGE(state
))
3286 DWORD texture_stage
= (state
- STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE
+ 1);
3287 DWORD texture_state
= state
- STATE_TEXTURESTAGE(texture_stage
, 0);
3288 return wine_dbg_sprintf("STATE_TEXTURESTAGE(%#x, %s)",
3289 texture_stage
, debug_d3dtexturestate(texture_state
));
3291 if (STATE_IS_SAMPLER(state
))
3292 return wine_dbg_sprintf("STATE_SAMPLER(%#x)", state
- STATE_SAMPLER(0));
3293 if (STATE_IS_SHADER(state
))
3294 return wine_dbg_sprintf("STATE_SHADER(%s)", debug_shader_type(state
- STATE_SHADER(0)));
3295 if (STATE_IS_CONSTANT_BUFFER(state
))
3296 return wine_dbg_sprintf("STATE_CONSTANT_BUFFER(%s)", debug_shader_type(state
- STATE_CONSTANT_BUFFER(0)));
3297 if (STATE_IS_SHADER_RESOURCE_BINDING(state
))
3298 return "STATE_SHADER_RESOURCE_BINDING";
3299 if (STATE_IS_TRANSFORM(state
))
3300 return wine_dbg_sprintf("STATE_TRANSFORM(%s)", debug_d3dtstype(state
- STATE_TRANSFORM(0)));
3301 if (STATE_IS_STREAMSRC(state
))
3302 return "STATE_STREAMSRC";
3303 if (STATE_IS_INDEXBUFFER(state
))
3304 return "STATE_INDEXBUFFER";
3305 if (STATE_IS_VDECL(state
))
3306 return "STATE_VDECL";
3307 if (STATE_IS_VIEWPORT(state
))
3308 return "STATE_VIEWPORT";
3309 if (STATE_IS_LIGHT_TYPE(state
))
3310 return "STATE_LIGHT_TYPE";
3311 if (STATE_IS_ACTIVELIGHT(state
))
3312 return wine_dbg_sprintf("STATE_ACTIVELIGHT(%#x)", state
- STATE_ACTIVELIGHT(0));
3313 if (STATE_IS_SCISSORRECT(state
))
3314 return "STATE_SCISSORRECT";
3315 if (STATE_IS_CLIPPLANE(state
))
3316 return wine_dbg_sprintf("STATE_CLIPPLANE(%#x)", state
- STATE_CLIPPLANE(0));
3317 if (STATE_IS_MATERIAL(state
))
3318 return "STATE_MATERIAL";
3319 if (STATE_IS_FRONTFACE(state
))
3320 return "STATE_FRONTFACE";
3321 if (STATE_IS_POINTSPRITECOORDORIGIN(state
))
3322 return "STATE_POINTSPRITECOORDORIGIN";
3323 if (STATE_IS_BASEVERTEXINDEX(state
))
3324 return "STATE_BASEVERTEXINDEX";
3325 if (STATE_IS_FRAMEBUFFER(state
))
3326 return "STATE_FRAMEBUFFER";
3327 if (STATE_IS_POINT_ENABLE(state
))
3328 return "STATE_POINT_ENABLE";
3329 if (STATE_IS_COLOR_KEY(state
))
3330 return "STATE_COLOR_KEY";
3332 return wine_dbg_sprintf("UNKNOWN_STATE(%#x)", state
);
3335 const char *debug_d3dpool(enum wined3d_pool pool
)
3339 #define POOL_TO_STR(p) case p: return #p
3340 POOL_TO_STR(WINED3D_POOL_DEFAULT
);
3341 POOL_TO_STR(WINED3D_POOL_MANAGED
);
3342 POOL_TO_STR(WINED3D_POOL_SYSTEM_MEM
);
3343 POOL_TO_STR(WINED3D_POOL_SCRATCH
);
3346 FIXME("Unrecognized pool %#x.\n", pool
);
3347 return "unrecognized";
3351 const char *debug_fbostatus(GLenum status
) {
3353 #define FBOSTATUS_TO_STR(u) case u: return #u
3354 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE
);
3355 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT
);
3356 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
);
3357 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT
);
3358 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT
);
3359 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER
);
3360 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER
);
3361 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE
);
3362 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED
);
3363 FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED
);
3364 #undef FBOSTATUS_TO_STR
3366 FIXME("Unrecognied FBO status 0x%08x\n", status
);
3367 return "unrecognized";
3371 const char *debug_glerror(GLenum error
) {
3373 #define GLERROR_TO_STR(u) case u: return #u
3374 GLERROR_TO_STR(GL_NO_ERROR
);
3375 GLERROR_TO_STR(GL_INVALID_ENUM
);
3376 GLERROR_TO_STR(GL_INVALID_VALUE
);
3377 GLERROR_TO_STR(GL_INVALID_OPERATION
);
3378 GLERROR_TO_STR(GL_STACK_OVERFLOW
);
3379 GLERROR_TO_STR(GL_STACK_UNDERFLOW
);
3380 GLERROR_TO_STR(GL_OUT_OF_MEMORY
);
3381 GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION
);
3382 #undef GLERROR_TO_STR
3384 FIXME("Unrecognied GL error 0x%08x\n", error
);
3385 return "unrecognized";
3389 static const char *debug_fixup_channel_source(enum fixup_channel_source source
)
3393 #define WINED3D_TO_STR(x) case x: return #x
3394 WINED3D_TO_STR(CHANNEL_SOURCE_ZERO
);
3395 WINED3D_TO_STR(CHANNEL_SOURCE_ONE
);
3396 WINED3D_TO_STR(CHANNEL_SOURCE_X
);
3397 WINED3D_TO_STR(CHANNEL_SOURCE_Y
);
3398 WINED3D_TO_STR(CHANNEL_SOURCE_Z
);
3399 WINED3D_TO_STR(CHANNEL_SOURCE_W
);
3400 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX0
);
3401 WINED3D_TO_STR(CHANNEL_SOURCE_COMPLEX1
);
3402 #undef WINED3D_TO_STR
3404 FIXME("Unrecognized fixup_channel_source %#x\n", source
);
3405 return "unrecognized";
3409 static const char *debug_complex_fixup(enum complex_fixup fixup
)
3413 #define WINED3D_TO_STR(x) case x: return #x
3414 WINED3D_TO_STR(COMPLEX_FIXUP_YUY2
);
3415 WINED3D_TO_STR(COMPLEX_FIXUP_UYVY
);
3416 WINED3D_TO_STR(COMPLEX_FIXUP_YV12
);
3417 WINED3D_TO_STR(COMPLEX_FIXUP_NV12
);
3418 WINED3D_TO_STR(COMPLEX_FIXUP_P8
);
3419 #undef WINED3D_TO_STR
3421 FIXME("Unrecognized complex fixup %#x\n", fixup
);
3422 return "unrecognized";
3426 void dump_color_fixup_desc(struct color_fixup_desc fixup
)
3428 if (is_complex_fixup(fixup
))
3430 TRACE("\tComplex: %s\n", debug_complex_fixup(get_complex_fixup(fixup
)));
3434 TRACE("\tX: %s%s\n", debug_fixup_channel_source(fixup
.x_source
), fixup
.x_sign_fixup
? ", SIGN_FIXUP" : "");
3435 TRACE("\tY: %s%s\n", debug_fixup_channel_source(fixup
.y_source
), fixup
.y_sign_fixup
? ", SIGN_FIXUP" : "");
3436 TRACE("\tZ: %s%s\n", debug_fixup_channel_source(fixup
.z_source
), fixup
.z_sign_fixup
? ", SIGN_FIXUP" : "");
3437 TRACE("\tW: %s%s\n", debug_fixup_channel_source(fixup
.w_source
), fixup
.w_sign_fixup
? ", SIGN_FIXUP" : "");
3440 BOOL
is_invalid_op(const struct wined3d_state
*state
, int stage
,
3441 enum wined3d_texture_op op
, DWORD arg1
, DWORD arg2
, DWORD arg3
)
3443 if (op
== WINED3D_TOP_DISABLE
)
3445 if (state
->textures
[stage
])
3448 if ((arg1
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
3449 && op
!= WINED3D_TOP_SELECT_ARG2
)
3451 if ((arg2
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
3452 && op
!= WINED3D_TOP_SELECT_ARG1
)
3454 if ((arg3
& WINED3DTA_SELECTMASK
) == WINED3DTA_TEXTURE
3455 && (op
== WINED3D_TOP_MULTIPLY_ADD
|| op
== WINED3D_TOP_LERP
))
3461 void get_identity_matrix(struct wined3d_matrix
*mat
)
3463 static const struct wined3d_matrix identity
=
3465 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3466 0.0f
, 1.0f
, 0.0f
, 0.0f
,
3467 0.0f
, 0.0f
, 1.0f
, 0.0f
,
3468 0.0f
, 0.0f
, 0.0f
, 1.0f
,
3474 void get_modelview_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
3475 unsigned int index
, struct wined3d_matrix
*mat
)
3477 if (context
->last_was_rhw
)
3478 get_identity_matrix(mat
);
3480 multiply_matrix(mat
, &state
->transforms
[WINED3D_TS_VIEW
], &state
->transforms
[WINED3D_TS_WORLD_MATRIX(index
)]);
3483 void get_projection_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
3484 struct wined3d_matrix
*mat
)
3486 float center_offset
;
3488 /* There are a couple of additional things we have to take into account
3489 * here besides the projection transformation itself:
3490 * - We need to flip along the y-axis in case of offscreen rendering.
3491 * - OpenGL Z range is {-Wc,...,Wc} while D3D Z range is {0,...,Wc}.
3492 * - D3D coordinates refer to pixel centers while GL coordinates refer
3494 * - D3D has a top-left filling convention. We need to maintain this
3495 * even after the y-flip mentioned above.
3496 * In order to handle the last two points, we translate by
3497 * (63.0 / 128.0) / VPw and (63.0 / 128.0) / VPh. This is equivalent to
3498 * translating slightly less than half a pixel. We want the difference to
3499 * be large enough that it doesn't get lost due to rounding inside the
3500 * driver, but small enough to prevent it from interfering with any
3503 if (context
->swapchain
->device
->wined3d
->flags
& WINED3D_PIXEL_CENTER_INTEGER
)
3504 center_offset
= 63.0f
/ 64.0f
;
3506 center_offset
= -1.0f
/ 64.0f
;
3508 if (context
->last_was_rhw
)
3510 /* Transform D3D RHW coordinates to OpenGL clip coordinates. */
3511 float x
= state
->viewport
.x
;
3512 float y
= state
->viewport
.y
;
3513 float w
= state
->viewport
.width
;
3514 float h
= state
->viewport
.height
;
3515 float x_scale
= 2.0f
/ w
;
3516 float x_offset
= (center_offset
- (2.0f
* x
) - w
) / w
;
3517 float y_scale
= context
->render_offscreen
? 2.0f
/ h
: 2.0f
/ -h
;
3518 float y_offset
= context
->render_offscreen
3519 ? (center_offset
- (2.0f
* y
) - h
) / h
3520 : (center_offset
- (2.0f
* y
) - h
) / -h
;
3521 #if defined(STAGING_CSMT)
3522 enum wined3d_depth_buffer_type zenable
= state
->fb
.depth_stencil
?
3523 #else /* STAGING_CSMT */
3524 enum wined3d_depth_buffer_type zenable
= state
->fb
->depth_stencil
?
3525 #endif /* STAGING_CSMT */
3526 state
->render_states
[WINED3D_RS_ZENABLE
] : WINED3D_ZB_FALSE
;
3527 float z_scale
= zenable
? 2.0f
: 0.0f
;
3528 float z_offset
= zenable
? -1.0f
: 0.0f
;
3529 const struct wined3d_matrix projection
=
3531 x_scale
, 0.0f
, 0.0f
, 0.0f
,
3532 0.0f
, y_scale
, 0.0f
, 0.0f
,
3533 0.0f
, 0.0f
, z_scale
, 0.0f
,
3534 x_offset
, y_offset
, z_offset
, 1.0f
,
3541 float y_scale
= context
->render_offscreen
? -1.0f
: 1.0f
;
3542 float x_offset
= center_offset
/ state
->viewport
.width
;
3543 float y_offset
= context
->render_offscreen
3544 ? center_offset
/ state
->viewport
.height
3545 : -center_offset
/ state
->viewport
.height
;
3546 const struct wined3d_matrix projection
=
3548 1.0f
, 0.0f
, 0.0f
, 0.0f
,
3549 0.0f
, y_scale
, 0.0f
, 0.0f
,
3550 0.0f
, 0.0f
, 2.0f
, 0.0f
,
3551 x_offset
, y_offset
, -1.0f
, 1.0f
,
3554 multiply_matrix(mat
, &projection
, &state
->transforms
[WINED3D_TS_PROJECTION
]);
3558 /* Setup this textures matrix according to the texture flags. */
3559 static void compute_texture_matrix(const struct wined3d_gl_info
*gl_info
, const struct wined3d_matrix
*matrix
,
3560 DWORD flags
, BOOL calculated_coords
, BOOL transformed
, enum wined3d_format_id format_id
,
3561 BOOL ffp_proj_control
, struct wined3d_matrix
*out_matrix
)
3563 struct wined3d_matrix mat
;
3565 if (flags
== WINED3D_TTFF_DISABLE
|| flags
== WINED3D_TTFF_COUNT1
|| transformed
)
3567 get_identity_matrix(out_matrix
);
3571 if (flags
== (WINED3D_TTFF_COUNT1
| WINED3D_TTFF_PROJECTED
))
3573 ERR("Invalid texture transform flags: WINED3D_TTFF_COUNT1 | WINED3D_TTFF_PROJECTED.\n");
3579 if (flags
& WINED3D_TTFF_PROJECTED
)
3581 if (!ffp_proj_control
)
3583 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
3585 case WINED3D_TTFF_COUNT2
:
3590 mat
._12
= mat
._22
= mat
._32
= mat
._42
= 0.0f
;
3592 case WINED3D_TTFF_COUNT3
:
3597 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
3604 /* Under Direct3D the R/Z coord can be used for translation, under
3605 * OpenGL we use the Q coord instead. */
3606 if (!calculated_coords
)
3610 /* Direct3D passes the default 1.0 in the 2nd coord, while GL
3611 * passes it in the 4th. Swap 2nd and 4th coord. No need to
3612 * store the value of mat._41 in mat._21 because the input
3613 * value to the transformation will be 0, so the matrix value
3615 case WINED3DFMT_R32_FLOAT
:
3621 /* See above, just 3rd and 4th coord. */
3622 case WINED3DFMT_R32G32_FLOAT
:
3628 case WINED3DFMT_R32G32B32_FLOAT
: /* Opengl defaults match dx defaults */
3629 case WINED3DFMT_R32G32B32A32_FLOAT
: /* No defaults apply, all app defined */
3631 /* This is to prevent swapping the matrix lines and put the default 4th coord = 1.0
3632 * into a bad place. The division elimination below will apply to make sure the
3633 * 1.0 doesn't do anything bad. The caller will set this value if the stride is 0
3635 case WINED3DFMT_UNKNOWN
: /* No texture coords, 0/0/0/1 defaults are passed */
3638 FIXME("Unexpected fixed function texture coord input\n");
3641 if (!ffp_proj_control
)
3643 switch (flags
& ~WINED3D_TTFF_PROJECTED
)
3645 /* case WINED3D_TTFF_COUNT1: Won't ever get here. */
3646 case WINED3D_TTFF_COUNT2
:
3647 mat
._13
= mat
._23
= mat
._33
= mat
._43
= 0.0f
;
3648 #if defined(STAGING_CSMT)
3649 /* OpenGL divides the first 3 vertex coord by the 4th by default,
3650 * which is essentially the same as D3DTTFF_PROJECTED. Make sure that
3651 * the 4th coord evaluates to 1.0 to eliminate that.
3653 * If the fixed function pipeline is used, the 4th value remains unused,
3654 * so there is no danger in doing this. With vertex shaders we have a
3655 * problem. Should an app hit that problem, the code here would have to
3656 * check for pixel shaders, and the shader has to undo the default gl divide.
3658 * A more serious problem occurs if the app passes 4 coordinates in, and the
3659 * 4th is != 1.0(opengl default). This would have to be fixed in draw_strided_slow
3660 * or a replacement shader. */
3661 #else /* STAGING_CSMT */
3662 /* OpenGL divides the first 3 vertex coord by the 4th by default,
3663 * which is essentially the same as D3DTTFF_PROJECTED. Make sure that
3664 * the 4th coord evaluates to 1.0 to eliminate that.
3666 * If the fixed function pipeline is used, the 4th value remains unused,
3667 * so there is no danger in doing this. With vertex shaders we have a
3668 * problem. Should an app hit that problem, the code here would have to
3669 * check for pixel shaders, and the shader has to undo the default gl divide.
3671 * A more serious problem occurs if the app passes 4 coordinates in, and the
3672 * 4th is != 1.0(opengl default). This would have to be fixed in drawStridedSlow
3673 * or a replacement shader. */
3674 #endif /* STAGING_CSMT */
3676 mat
._14
= mat
._24
= mat
._34
= 0.0f
; mat
._44
= 1.0f
;
3684 void get_texture_matrix(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
3685 unsigned int tex
, struct wined3d_matrix
*mat
)
3687 const struct wined3d_device
*device
= context
->swapchain
->device
;
3688 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
3689 BOOL generated
= (state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
] & 0xffff0000)
3690 != WINED3DTSS_TCI_PASSTHRU
;
3691 unsigned int coord_idx
= min(state
->texture_states
[tex
][WINED3D_TSS_TEXCOORD_INDEX
& 0x0000ffff],
3694 compute_texture_matrix(gl_info
, &state
->transforms
[WINED3D_TS_TEXTURE0
+ tex
],
3695 state
->texture_states
[tex
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
],
3696 generated
, context
->last_was_rhw
,
3697 context
->stream_info
.use_map
& (1 << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))
3698 ? context
->stream_info
.elements
[WINED3D_FFP_TEXCOORD0
+ coord_idx
].format
->id
3699 : WINED3DFMT_UNKNOWN
,
3700 device
->shader_backend
->shader_has_ffp_proj_control(device
->shader_priv
), mat
);
3702 if ((context
->lastWasPow2Texture
& (1 << tex
)) && state
->textures
[tex
])
3705 FIXME("Non-power-of-two texture being used with generated texture coords.\n");
3706 /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
3707 * fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
3710 TRACE("Non-power-of-two texture matrix multiply fixup.\n");
3711 multiply_matrix(mat
, mat
, (struct wined3d_matrix
*)state
->textures
[tex
]->pow2_matrix
);
3716 void get_pointsize_minmax(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
3717 float *out_min
, float *out_max
)
3725 min
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MIN
];
3726 max
.d
= state
->render_states
[WINED3D_RS_POINTSIZE_MAX
];
3735 void get_pointsize(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
3736 float *out_pointsize
, float *out_att
)
3738 /* POINTSCALEENABLE controls how point size value is treated. If set to
3739 * true, the point size is scaled with respect to height of viewport.
3740 * When set to false point size is in pixels. */
3745 } pointsize
, a
, b
, c
;
3751 pointsize
.d
= state
->render_states
[WINED3D_RS_POINTSIZE
];
3752 a
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_A
];
3753 b
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_B
];
3754 c
.d
= state
->render_states
[WINED3D_RS_POINTSCALE_C
];
3756 if (state
->render_states
[WINED3D_RS_POINTSCALEENABLE
])
3758 float scale_factor
= state
->viewport
.height
* state
->viewport
.height
;
3760 out_att
[0] = a
.f
/ scale_factor
;
3761 out_att
[1] = b
.f
/ scale_factor
;
3762 out_att
[2] = c
.f
/ scale_factor
;
3764 *out_pointsize
= pointsize
.f
;
3767 void get_fog_start_end(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
3768 float *start
, float *end
)
3776 switch (context
->fog_source
)
3783 case FOGSOURCE_COORD
:
3789 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGSTART
];
3790 *start
= tmpvalue
.f
;
3791 tmpvalue
.d
= state
->render_states
[WINED3D_RS_FOGEND
];
3793 /* Special handling for fog_start == fog_end. In d3d with vertex
3794 * fog, everything is fogged. With table fog, everything with
3795 * fog_coord < fog_start is unfogged, and fog_coord > fog_start
3796 * is fogged. Windows drivers disagree when fog_coord == fog_start. */
3797 if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
&& *start
== *end
)
3805 /* This should not happen, context->fog_source is set in wined3d, not the app. */
3806 ERR("Unexpected fog coordinate source.\n");
3812 /* This small helper function is used to convert a bitmask into the number of masked bits */
3813 unsigned int count_bits(unsigned int mask
)
3816 for (count
= 0; mask
; ++count
)
3823 /* Helper function for retrieving color info for ChoosePixelFormat and wglChoosePixelFormatARB.
3824 * The later function requires individual color components. */
3825 BOOL
getColorBits(const struct wined3d_format
*format
,
3826 BYTE
*redSize
, BYTE
*greenSize
, BYTE
*blueSize
, BYTE
*alphaSize
, BYTE
*totalSize
)
3828 TRACE("format %s.\n", debug_d3dformat(format
->id
));
3832 case WINED3DFMT_B10G10R10A2_UNORM
:
3833 case WINED3DFMT_R10G10B10A2_UNORM
:
3834 case WINED3DFMT_B8G8R8X8_UNORM
:
3835 case WINED3DFMT_B8G8R8_UNORM
:
3836 case WINED3DFMT_B8G8R8A8_UNORM
:
3837 case WINED3DFMT_R8G8B8A8_UNORM
:
3838 case WINED3DFMT_B5G5R5X1_UNORM
:
3839 case WINED3DFMT_B5G5R5A1_UNORM
:
3840 case WINED3DFMT_B5G6R5_UNORM
:
3841 case WINED3DFMT_B4G4R4X4_UNORM
:
3842 case WINED3DFMT_B4G4R4A4_UNORM
:
3843 case WINED3DFMT_B2G3R3_UNORM
:
3844 case WINED3DFMT_P8_UINT_A8_UNORM
:
3845 case WINED3DFMT_P8_UINT
:
3848 FIXME("Unsupported format %s.\n", debug_d3dformat(format
->id
));
3852 *redSize
= format
->red_size
;
3853 *greenSize
= format
->green_size
;
3854 *blueSize
= format
->blue_size
;
3855 *alphaSize
= format
->alpha_size
;
3856 *totalSize
= *redSize
+ *greenSize
+ *blueSize
+ *alphaSize
;
3858 TRACE("Returning red: %d, green: %d, blue: %d, alpha: %d, total: %d for format %s.\n",
3859 *redSize
, *greenSize
, *blueSize
, *alphaSize
, *totalSize
, debug_d3dformat(format
->id
));
3863 /* Helper function for retrieving depth/stencil info for ChoosePixelFormat and wglChoosePixelFormatARB */
3864 BOOL
getDepthStencilBits(const struct wined3d_format
*format
, BYTE
*depthSize
, BYTE
*stencilSize
)
3866 TRACE("format %s.\n", debug_d3dformat(format
->id
));
3870 case WINED3DFMT_D16_LOCKABLE
:
3871 case WINED3DFMT_D16_UNORM
:
3872 case WINED3DFMT_S1_UINT_D15_UNORM
:
3873 case WINED3DFMT_X8D24_UNORM
:
3874 case WINED3DFMT_S4X4_UINT_D24_UNORM
:
3875 case WINED3DFMT_D24_UNORM_S8_UINT
:
3876 case WINED3DFMT_S8_UINT_D24_FLOAT
:
3877 case WINED3DFMT_D32_UNORM
:
3878 case WINED3DFMT_D32_FLOAT
:
3879 case WINED3DFMT_INTZ
:
3882 FIXME("Unsupported depth/stencil format %s.\n", debug_d3dformat(format
->id
));
3886 *depthSize
= format
->depth_size
;
3887 *stencilSize
= format
->stencil_size
;
3889 TRACE("Returning depthSize: %d and stencilSize: %d for format %s.\n",
3890 *depthSize
, *stencilSize
, debug_d3dformat(format
->id
));
3894 /* Note: It's the caller's responsibility to ensure values can be expressed
3895 * in the requested format. UNORM formats for example can only express values
3896 * in the range 0.0f -> 1.0f. */
3897 DWORD
wined3d_format_convert_from_float(const struct wined3d_surface
*surface
, const struct wined3d_color
*color
)
3901 enum wined3d_format_id format_id
;
3913 {WINED3DFMT_B8G8R8A8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
3914 {WINED3DFMT_B8G8R8X8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
3915 {WINED3DFMT_B8G8R8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 16, 8, 0, 24},
3916 {WINED3DFMT_B5G6R5_UNORM
, 31.0f
, 63.0f
, 31.0f
, 0.0f
, 11, 5, 0, 0},
3917 {WINED3DFMT_B5G5R5A1_UNORM
, 31.0f
, 31.0f
, 31.0f
, 1.0f
, 10, 5, 0, 15},
3918 {WINED3DFMT_B5G5R5X1_UNORM
, 31.0f
, 31.0f
, 31.0f
, 1.0f
, 10, 5, 0, 15},
3919 {WINED3DFMT_R8_UNORM
, 255.0f
, 0.0f
, 0.0f
, 0.0f
, 0, 0, 0, 0},
3920 {WINED3DFMT_A8_UNORM
, 0.0f
, 0.0f
, 0.0f
, 255.0f
, 0, 0, 0, 0},
3921 {WINED3DFMT_B4G4R4A4_UNORM
, 15.0f
, 15.0f
, 15.0f
, 15.0f
, 8, 4, 0, 12},
3922 {WINED3DFMT_B4G4R4X4_UNORM
, 15.0f
, 15.0f
, 15.0f
, 15.0f
, 8, 4, 0, 12},
3923 {WINED3DFMT_B2G3R3_UNORM
, 7.0f
, 7.0f
, 3.0f
, 0.0f
, 5, 2, 0, 0},
3924 {WINED3DFMT_R8G8B8A8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 0, 8, 16, 24},
3925 {WINED3DFMT_R8G8B8X8_UNORM
, 255.0f
, 255.0f
, 255.0f
, 255.0f
, 0, 8, 16, 24},
3926 {WINED3DFMT_B10G10R10A2_UNORM
, 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
, 20, 10, 0, 30},
3927 {WINED3DFMT_R10G10B10A2_UNORM
, 1023.0f
, 1023.0f
, 1023.0f
, 3.0f
, 0, 10, 20, 30},
3928 {WINED3DFMT_P8_UINT
, 0.0f
, 0.0f
, 0.0f
, 255.0f
, 0, 0, 0, 0},
3930 const struct wined3d_format
*format
= surface
->resource
.format
;
3933 TRACE("Converting color {%.8e %.8e %.8e %.8e} to format %s.\n",
3934 color
->r
, color
->g
, color
->b
, color
->a
, debug_d3dformat(format
->id
));
3936 for (i
= 0; i
< sizeof(conv
) / sizeof(*conv
); ++i
)
3940 if (format
->id
!= conv
[i
].format_id
) continue;
3942 ret
= ((DWORD
)((color
->r
* conv
[i
].r_mul
) + 0.5f
)) << conv
[i
].r_shift
;
3943 ret
|= ((DWORD
)((color
->g
* conv
[i
].g_mul
) + 0.5f
)) << conv
[i
].g_shift
;
3944 ret
|= ((DWORD
)((color
->b
* conv
[i
].b_mul
) + 0.5f
)) << conv
[i
].b_shift
;
3945 ret
|= ((DWORD
)((color
->a
* conv
[i
].a_mul
) + 0.5f
)) << conv
[i
].a_shift
;
3947 TRACE("Returning 0x%08x.\n", ret
);
3952 FIXME("Conversion for format %s not implemented.\n", debug_d3dformat(format
->id
));
3957 static float color_to_float(DWORD color
, DWORD size
, DWORD offset
)
3959 DWORD mask
= (1 << size
) - 1;
3967 return (float)color
/ (float)mask
;
3970 BOOL
wined3d_format_convert_color_to_float(const struct wined3d_format
*format
,
3971 const struct wined3d_palette
*palette
, DWORD color
, struct wined3d_color
*float_color
)
3975 case WINED3DFMT_B8G8R8_UNORM
:
3976 case WINED3DFMT_B8G8R8A8_UNORM
:
3977 case WINED3DFMT_B8G8R8X8_UNORM
:
3978 case WINED3DFMT_B5G6R5_UNORM
:
3979 case WINED3DFMT_B5G5R5X1_UNORM
:
3980 case WINED3DFMT_B5G5R5A1_UNORM
:
3981 case WINED3DFMT_B4G4R4A4_UNORM
:
3982 case WINED3DFMT_B2G3R3_UNORM
:
3983 case WINED3DFMT_R8_UNORM
:
3984 case WINED3DFMT_A8_UNORM
:
3985 case WINED3DFMT_B2G3R3A8_UNORM
:
3986 case WINED3DFMT_B4G4R4X4_UNORM
:
3987 case WINED3DFMT_R10G10B10A2_UNORM
:
3988 case WINED3DFMT_R10G10B10A2_SNORM
:
3989 case WINED3DFMT_R8G8B8A8_UNORM
:
3990 case WINED3DFMT_R8G8B8X8_UNORM
:
3991 case WINED3DFMT_R16G16_UNORM
:
3992 case WINED3DFMT_B10G10R10A2_UNORM
:
3993 float_color
->r
= color_to_float(color
, format
->red_size
, format
->red_offset
);
3994 float_color
->g
= color_to_float(color
, format
->green_size
, format
->green_offset
);
3995 float_color
->b
= color_to_float(color
, format
->blue_size
, format
->blue_offset
);
3996 float_color
->a
= color_to_float(color
, format
->alpha_size
, format
->alpha_offset
);
3999 case WINED3DFMT_P8_UINT
:
4002 float_color
->r
= palette
->colors
[color
].rgbRed
/ 255.0f
;
4003 float_color
->g
= palette
->colors
[color
].rgbGreen
/ 255.0f
;
4004 float_color
->b
= palette
->colors
[color
].rgbBlue
/ 255.0f
;
4008 float_color
->r
= 0.0f
;
4009 float_color
->g
= 0.0f
;
4010 float_color
->b
= 0.0f
;
4012 float_color
->a
= color
/ 255.0f
;
4016 ERR("Unhandled conversion from %s to floating point.\n", debug_d3dformat(format
->id
));
4021 /* DirectDraw stuff */
4022 enum wined3d_format_id
pixelformat_for_depth(DWORD depth
)
4026 case 8: return WINED3DFMT_P8_UINT
;
4027 case 15: return WINED3DFMT_B5G5R5X1_UNORM
;
4028 case 16: return WINED3DFMT_B5G6R5_UNORM
;
4029 case 24: return WINED3DFMT_B8G8R8X8_UNORM
; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
4030 case 32: return WINED3DFMT_B8G8R8X8_UNORM
; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
4031 default: return WINED3DFMT_UNKNOWN
;
4035 void multiply_matrix(struct wined3d_matrix
*dst
, const struct wined3d_matrix
*src1
, const struct wined3d_matrix
*src2
)
4037 struct wined3d_matrix tmp
;
4039 /* Now do the multiplication 'by hand'.
4040 I know that all this could be optimised, but this will be done later :-) */
4041 tmp
._11
= (src1
->_11
* src2
->_11
) + (src1
->_21
* src2
->_12
) + (src1
->_31
* src2
->_13
) + (src1
->_41
* src2
->_14
);
4042 tmp
._21
= (src1
->_11
* src2
->_21
) + (src1
->_21
* src2
->_22
) + (src1
->_31
* src2
->_23
) + (src1
->_41
* src2
->_24
);
4043 tmp
._31
= (src1
->_11
* src2
->_31
) + (src1
->_21
* src2
->_32
) + (src1
->_31
* src2
->_33
) + (src1
->_41
* src2
->_34
);
4044 tmp
._41
= (src1
->_11
* src2
->_41
) + (src1
->_21
* src2
->_42
) + (src1
->_31
* src2
->_43
) + (src1
->_41
* src2
->_44
);
4046 tmp
._12
= (src1
->_12
* src2
->_11
) + (src1
->_22
* src2
->_12
) + (src1
->_32
* src2
->_13
) + (src1
->_42
* src2
->_14
);
4047 tmp
._22
= (src1
->_12
* src2
->_21
) + (src1
->_22
* src2
->_22
) + (src1
->_32
* src2
->_23
) + (src1
->_42
* src2
->_24
);
4048 tmp
._32
= (src1
->_12
* src2
->_31
) + (src1
->_22
* src2
->_32
) + (src1
->_32
* src2
->_33
) + (src1
->_42
* src2
->_34
);
4049 tmp
._42
= (src1
->_12
* src2
->_41
) + (src1
->_22
* src2
->_42
) + (src1
->_32
* src2
->_43
) + (src1
->_42
* src2
->_44
);
4051 tmp
._13
= (src1
->_13
* src2
->_11
) + (src1
->_23
* src2
->_12
) + (src1
->_33
* src2
->_13
) + (src1
->_43
* src2
->_14
);
4052 tmp
._23
= (src1
->_13
* src2
->_21
) + (src1
->_23
* src2
->_22
) + (src1
->_33
* src2
->_23
) + (src1
->_43
* src2
->_24
);
4053 tmp
._33
= (src1
->_13
* src2
->_31
) + (src1
->_23
* src2
->_32
) + (src1
->_33
* src2
->_33
) + (src1
->_43
* src2
->_34
);
4054 tmp
._43
= (src1
->_13
* src2
->_41
) + (src1
->_23
* src2
->_42
) + (src1
->_33
* src2
->_43
) + (src1
->_43
* src2
->_44
);
4056 tmp
._14
= (src1
->_14
* src2
->_11
) + (src1
->_24
* src2
->_12
) + (src1
->_34
* src2
->_13
) + (src1
->_44
* src2
->_14
);
4057 tmp
._24
= (src1
->_14
* src2
->_21
) + (src1
->_24
* src2
->_22
) + (src1
->_34
* src2
->_23
) + (src1
->_44
* src2
->_24
);
4058 tmp
._34
= (src1
->_14
* src2
->_31
) + (src1
->_24
* src2
->_32
) + (src1
->_34
* src2
->_33
) + (src1
->_44
* src2
->_34
);
4059 tmp
._44
= (src1
->_14
* src2
->_41
) + (src1
->_24
* src2
->_42
) + (src1
->_34
* src2
->_43
) + (src1
->_44
* src2
->_44
);
4064 DWORD
get_flexible_vertex_size(DWORD d3dvtVertexType
) {
4067 int numTextures
= (d3dvtVertexType
& WINED3DFVF_TEXCOUNT_MASK
) >> WINED3DFVF_TEXCOUNT_SHIFT
;
4069 if (d3dvtVertexType
& WINED3DFVF_NORMAL
) size
+= 3 * sizeof(float);
4070 if (d3dvtVertexType
& WINED3DFVF_DIFFUSE
) size
+= sizeof(DWORD
);
4071 if (d3dvtVertexType
& WINED3DFVF_SPECULAR
) size
+= sizeof(DWORD
);
4072 if (d3dvtVertexType
& WINED3DFVF_PSIZE
) size
+= sizeof(DWORD
);
4073 switch (d3dvtVertexType
& WINED3DFVF_POSITION_MASK
) {
4074 case WINED3DFVF_XYZ
: size
+= 3 * sizeof(float); break;
4075 case WINED3DFVF_XYZRHW
: size
+= 4 * sizeof(float); break;
4076 case WINED3DFVF_XYZB1
: size
+= 4 * sizeof(float); break;
4077 case WINED3DFVF_XYZB2
: size
+= 5 * sizeof(float); break;
4078 case WINED3DFVF_XYZB3
: size
+= 6 * sizeof(float); break;
4079 case WINED3DFVF_XYZB4
: size
+= 7 * sizeof(float); break;
4080 case WINED3DFVF_XYZB5
: size
+= 8 * sizeof(float); break;
4081 case WINED3DFVF_XYZW
: size
+= 4 * sizeof(float); break;
4082 default: ERR("Unexpected position mask\n");
4084 for (i
= 0; i
< numTextures
; i
++) {
4085 size
+= GET_TEXCOORD_SIZE_FROM_FVF(d3dvtVertexType
, i
) * sizeof(float);
4091 void gen_ffp_frag_op(const struct wined3d_context
*context
, const struct wined3d_state
*state
,
4092 struct ffp_frag_settings
*settings
, BOOL ignore_textype
)
4097 static const unsigned char args
[WINED3D_TOP_LERP
+ 1] =
4100 /* D3DTOP_DISABLE */ 0,
4101 /* D3DTOP_SELECTARG1 */ ARG1
,
4102 /* D3DTOP_SELECTARG2 */ ARG2
,
4103 /* D3DTOP_MODULATE */ ARG1
| ARG2
,
4104 /* D3DTOP_MODULATE2X */ ARG1
| ARG2
,
4105 /* D3DTOP_MODULATE4X */ ARG1
| ARG2
,
4106 /* D3DTOP_ADD */ ARG1
| ARG2
,
4107 /* D3DTOP_ADDSIGNED */ ARG1
| ARG2
,
4108 /* D3DTOP_ADDSIGNED2X */ ARG1
| ARG2
,
4109 /* D3DTOP_SUBTRACT */ ARG1
| ARG2
,
4110 /* D3DTOP_ADDSMOOTH */ ARG1
| ARG2
,
4111 /* D3DTOP_BLENDDIFFUSEALPHA */ ARG1
| ARG2
,
4112 /* D3DTOP_BLENDTEXTUREALPHA */ ARG1
| ARG2
,
4113 /* D3DTOP_BLENDFACTORALPHA */ ARG1
| ARG2
,
4114 /* D3DTOP_BLENDTEXTUREALPHAPM */ ARG1
| ARG2
,
4115 /* D3DTOP_BLENDCURRENTALPHA */ ARG1
| ARG2
,
4116 /* D3DTOP_PREMODULATE */ ARG1
| ARG2
,
4117 /* D3DTOP_MODULATEALPHA_ADDCOLOR */ ARG1
| ARG2
,
4118 /* D3DTOP_MODULATECOLOR_ADDALPHA */ ARG1
| ARG2
,
4119 /* D3DTOP_MODULATEINVALPHA_ADDCOLOR */ ARG1
| ARG2
,
4120 /* D3DTOP_MODULATEINVCOLOR_ADDALPHA */ ARG1
| ARG2
,
4121 /* D3DTOP_BUMPENVMAP */ ARG1
| ARG2
,
4122 /* D3DTOP_BUMPENVMAPLUMINANCE */ ARG1
| ARG2
,
4123 /* D3DTOP_DOTPRODUCT3 */ ARG1
| ARG2
,
4124 /* D3DTOP_MULTIPLYADD */ ARG1
| ARG2
| ARG0
,
4125 /* D3DTOP_LERP */ ARG1
| ARG2
| ARG0
4129 DWORD cop
, aop
, carg0
, carg1
, carg2
, aarg0
, aarg1
, aarg2
;
4130 #if defined(STAGING_CSMT)
4131 unsigned int rt_fmt_flags
= state
->fb
.render_targets
[0]->format_flags
;
4132 #else /* STAGING_CSMT */
4133 unsigned int rt_fmt_flags
= state
->fb
->render_targets
[0]->format_flags
;
4134 #endif /* STAGING_CSMT */
4135 const struct wined3d_gl_info
*gl_info
= context
->gl_info
;
4136 const struct wined3d_d3d_info
*d3d_info
= context
->d3d_info
;
4138 settings
->padding
= 0;
4140 for (i
= 0; i
< d3d_info
->limits
.ffp_blend_stages
; ++i
)
4142 const struct wined3d_texture
*texture
;
4144 settings
->op
[i
].padding
= 0;
4145 if (state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
] == WINED3D_TOP_DISABLE
)
4147 settings
->op
[i
].cop
= WINED3D_TOP_DISABLE
;
4148 settings
->op
[i
].aop
= WINED3D_TOP_DISABLE
;
4149 settings
->op
[i
].carg0
= settings
->op
[i
].carg1
= settings
->op
[i
].carg2
= ARG_UNUSED
;
4150 settings
->op
[i
].aarg0
= settings
->op
[i
].aarg1
= settings
->op
[i
].aarg2
= ARG_UNUSED
;
4151 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
4152 settings
->op
[i
].dst
= resultreg
;
4153 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
4154 settings
->op
[i
].projected
= proj_none
;
4159 if ((texture
= state
->textures
[i
]))
4161 settings
->op
[i
].color_fixup
= texture
->resource
.format
->color_fixup
;
4164 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
4168 switch (texture
->target
)
4171 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
4174 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_2D
;
4177 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_3D
;
4179 case GL_TEXTURE_CUBE_MAP_ARB
:
4180 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_CUBE
;
4182 case GL_TEXTURE_RECTANGLE_ARB
:
4183 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_RECT
;
4188 settings
->op
[i
].color_fixup
= COLOR_FIXUP_IDENTITY
;
4189 settings
->op
[i
].tex_type
= WINED3D_GL_RES_TYPE_TEX_1D
;
4192 cop
= state
->texture_states
[i
][WINED3D_TSS_COLOR_OP
];
4193 aop
= state
->texture_states
[i
][WINED3D_TSS_ALPHA_OP
];
4195 carg1
= (args
[cop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG1
] : ARG_UNUSED
;
4196 carg2
= (args
[cop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG2
] : ARG_UNUSED
;
4197 carg0
= (args
[cop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_COLOR_ARG0
] : ARG_UNUSED
;
4199 if (is_invalid_op(state
, i
, cop
, carg1
, carg2
, carg0
))
4203 carg1
= WINED3DTA_CURRENT
;
4204 cop
= WINED3D_TOP_SELECT_ARG1
;
4207 if (cop
== WINED3D_TOP_DOTPRODUCT3
)
4209 /* A dotproduct3 on the colorop overwrites the alphaop operation and replicates
4210 * the color result to the alpha component of the destination
4219 aarg1
= (args
[aop
] & ARG1
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG1
] : ARG_UNUSED
;
4220 aarg2
= (args
[aop
] & ARG2
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG2
] : ARG_UNUSED
;
4221 aarg0
= (args
[aop
] & ARG0
) ? state
->texture_states
[i
][WINED3D_TSS_ALPHA_ARG0
] : ARG_UNUSED
;
4224 if (!i
&& state
->textures
[0] && state
->render_states
[WINED3D_RS_COLORKEYENABLE
])
4226 GLenum texture_dimensions
;
4228 texture
= state
->textures
[0];
4229 texture_dimensions
= texture
->target
;
4231 if (texture_dimensions
== GL_TEXTURE_2D
|| texture_dimensions
== GL_TEXTURE_RECTANGLE_ARB
)
4233 if (texture
->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
&& !texture
->resource
.format
->alpha_size
)
4235 if (aop
== WINED3D_TOP_DISABLE
)
4237 aarg1
= WINED3DTA_TEXTURE
;
4238 aop
= WINED3D_TOP_SELECT_ARG1
;
4240 else if (aop
== WINED3D_TOP_SELECT_ARG1
&& aarg1
!= WINED3DTA_TEXTURE
)
4242 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
])
4244 aarg2
= WINED3DTA_TEXTURE
;
4245 aop
= WINED3D_TOP_MODULATE
;
4247 else aarg1
= WINED3DTA_TEXTURE
;
4249 else if (aop
== WINED3D_TOP_SELECT_ARG2
&& aarg2
!= WINED3DTA_TEXTURE
)
4251 if (state
->render_states
[WINED3D_RS_ALPHABLENDENABLE
])
4253 aarg1
= WINED3DTA_TEXTURE
;
4254 aop
= WINED3D_TOP_MODULATE
;
4256 else aarg2
= WINED3DTA_TEXTURE
;
4262 if (is_invalid_op(state
, i
, aop
, aarg1
, aarg2
, aarg0
))
4266 aarg1
= WINED3DTA_CURRENT
;
4267 aop
= WINED3D_TOP_SELECT_ARG1
;
4270 if (carg1
== WINED3DTA_TEXTURE
|| carg2
== WINED3DTA_TEXTURE
|| carg0
== WINED3DTA_TEXTURE
4271 || aarg1
== WINED3DTA_TEXTURE
|| aarg2
== WINED3DTA_TEXTURE
|| aarg0
== WINED3DTA_TEXTURE
)
4273 ttff
= state
->texture_states
[i
][WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
];
4274 if (ttff
== (WINED3D_TTFF_PROJECTED
| WINED3D_TTFF_COUNT3
))
4275 settings
->op
[i
].projected
= proj_count3
;
4276 else if (ttff
& WINED3D_TTFF_PROJECTED
)
4277 settings
->op
[i
].projected
= proj_count4
;
4279 settings
->op
[i
].projected
= proj_none
;
4283 settings
->op
[i
].projected
= proj_none
;
4286 settings
->op
[i
].cop
= cop
;
4287 settings
->op
[i
].aop
= aop
;
4288 settings
->op
[i
].carg0
= carg0
;
4289 settings
->op
[i
].carg1
= carg1
;
4290 settings
->op
[i
].carg2
= carg2
;
4291 settings
->op
[i
].aarg0
= aarg0
;
4292 settings
->op
[i
].aarg1
= aarg1
;
4293 settings
->op
[i
].aarg2
= aarg2
;
4295 if (state
->texture_states
[i
][WINED3D_TSS_RESULT_ARG
] == WINED3DTA_TEMP
)
4296 settings
->op
[i
].dst
= tempreg
;
4298 settings
->op
[i
].dst
= resultreg
;
4301 /* Clear unsupported stages */
4302 for(; i
< MAX_TEXTURES
; i
++) {
4303 memset(&settings
->op
[i
], 0xff, sizeof(settings
->op
[i
]));
4306 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
4308 settings
->fog
= WINED3D_FFP_PS_FOG_OFF
;
4310 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] == WINED3D_FOG_NONE
)
4312 if (use_vs(state
) || state
->vertex_declaration
->position_transformed
)
4314 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
4318 switch (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
])
4320 case WINED3D_FOG_NONE
:
4321 case WINED3D_FOG_LINEAR
:
4322 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
4324 case WINED3D_FOG_EXP
:
4325 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
4327 case WINED3D_FOG_EXP2
:
4328 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
4335 switch (state
->render_states
[WINED3D_RS_FOGTABLEMODE
])
4337 case WINED3D_FOG_LINEAR
:
4338 settings
->fog
= WINED3D_FFP_PS_FOG_LINEAR
;
4340 case WINED3D_FOG_EXP
:
4341 settings
->fog
= WINED3D_FFP_PS_FOG_EXP
;
4343 case WINED3D_FOG_EXP2
:
4344 settings
->fog
= WINED3D_FFP_PS_FOG_EXP2
;
4348 if (!gl_info
->supported
[ARB_FRAMEBUFFER_SRGB
]
4349 && state
->render_states
[WINED3D_RS_SRGBWRITEENABLE
]
4350 && rt_fmt_flags
& WINED3DFMT_FLAG_SRGB_WRITE
)
4352 settings
->sRGB_write
= 1;
4354 settings
->sRGB_write
= 0;
4356 if (d3d_info
->vs_clipping
|| !use_vs(state
) || !state
->render_states
[WINED3D_RS_CLIPPING
]
4357 || !state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
])
4359 /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
4360 * the fixed function vertex pipeline is used(which always supports clipplanes), or
4361 * if no clipplane is enabled
4363 settings
->emul_clipplanes
= 0;
4365 settings
->emul_clipplanes
= 1;
4368 if (state
->render_states
[WINED3D_RS_COLORKEYENABLE
] && state
->textures
[0]
4369 && state
->textures
[0]->async
.color_key_flags
& WINED3D_CKEY_SRC_BLT
4370 && settings
->op
[0].cop
!= WINED3D_TOP_DISABLE
)
4371 settings
->color_key_enabled
= 1;
4373 settings
->color_key_enabled
= 0;
4376 const struct ffp_frag_desc
*find_ffp_frag_shader(const struct wine_rb_tree
*fragment_shaders
,
4377 const struct ffp_frag_settings
*settings
)
4379 struct wine_rb_entry
*entry
= wine_rb_get(fragment_shaders
, settings
);
4380 return entry
? WINE_RB_ENTRY_VALUE(entry
, struct ffp_frag_desc
, entry
) : NULL
;
4383 void add_ffp_frag_shader(struct wine_rb_tree
*shaders
, struct ffp_frag_desc
*desc
)
4385 /* Note that the key is the implementation independent part of the ffp_frag_desc structure,
4386 * whereas desc points to an extended structure with implementation specific parts. */
4387 if (wine_rb_put(shaders
, &desc
->settings
, &desc
->entry
) == -1)
4389 ERR("Failed to insert ffp frag shader.\n");
4393 /* Activates the texture dimension according to the bound D3D texture. Does
4394 * not care for the colorop or correct gl texture unit (when using nvrc).
4395 * Requires the caller to activate the correct unit. */
4396 /* Context activation is done by the caller (state handler). */
4397 void texture_activate_dimensions(const struct wined3d_texture
*texture
, const struct wined3d_gl_info
*gl_info
)
4401 switch (texture
->target
)
4404 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
4405 checkGLcall("glDisable(GL_TEXTURE_3D)");
4406 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
4408 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
4409 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
4411 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
4413 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
4414 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
4416 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
4417 checkGLcall("glEnable(GL_TEXTURE_2D)");
4419 case GL_TEXTURE_RECTANGLE_ARB
:
4420 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
4421 checkGLcall("glDisable(GL_TEXTURE_2D)");
4422 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
4423 checkGLcall("glDisable(GL_TEXTURE_3D)");
4424 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
4426 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
4427 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
4429 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_RECTANGLE_ARB
);
4430 checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
4433 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
4435 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
4436 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
4438 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
4440 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
4441 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
4443 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
4444 checkGLcall("glDisable(GL_TEXTURE_2D)");
4445 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_3D
);
4446 checkGLcall("glEnable(GL_TEXTURE_3D)");
4448 case GL_TEXTURE_CUBE_MAP_ARB
:
4449 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_2D
);
4450 checkGLcall("glDisable(GL_TEXTURE_2D)");
4451 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
4452 checkGLcall("glDisable(GL_TEXTURE_3D)");
4453 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
4455 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
4456 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
4458 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_CUBE_MAP_ARB
);
4459 checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
4465 gl_info
->gl_ops
.gl
.p_glEnable(GL_TEXTURE_2D
);
4466 checkGLcall("glEnable(GL_TEXTURE_2D)");
4467 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_3D
);
4468 checkGLcall("glDisable(GL_TEXTURE_3D)");
4469 if (gl_info
->supported
[ARB_TEXTURE_CUBE_MAP
])
4471 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_CUBE_MAP_ARB
);
4472 checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
4474 if (gl_info
->supported
[ARB_TEXTURE_RECTANGLE
])
4476 gl_info
->gl_ops
.gl
.p_glDisable(GL_TEXTURE_RECTANGLE_ARB
);
4477 checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
4479 /* Binding textures is done by samplers. A dummy texture will be bound */
4483 /* Context activation is done by the caller (state handler). */
4484 void sampler_texdim(struct wined3d_context
*context
, const struct wined3d_state
*state
, DWORD state_id
)
4486 DWORD sampler
= state_id
- STATE_SAMPLER(0);
4487 DWORD mapped_stage
= context
->tex_unit_map
[sampler
];
4489 /* No need to enable / disable anything here for unused samplers. The
4490 * tex_colorop handler takes care. Also no action is needed with pixel
4491 * shaders, or if tex_colorop will take care of this business. */
4492 if (mapped_stage
== WINED3D_UNMAPPED_STAGE
|| mapped_stage
>= context
->gl_info
->limits
.textures
)
4494 if (sampler
>= context
->lowest_disabled_stage
)
4496 if (isStateDirty(context
, STATE_TEXTURESTAGE(sampler
, WINED3D_TSS_COLOR_OP
)))
4499 texture_activate_dimensions(state
->textures
[sampler
], context
->gl_info
);
4502 void *wined3d_rb_alloc(size_t size
)
4504 return HeapAlloc(GetProcessHeap(), 0, size
);
4507 void *wined3d_rb_realloc(void *ptr
, size_t size
)
4509 return HeapReAlloc(GetProcessHeap(), 0, ptr
, size
);
4512 void wined3d_rb_free(void *ptr
)
4514 HeapFree(GetProcessHeap(), 0, ptr
);
4517 static int ffp_frag_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
4519 const struct ffp_frag_settings
*ka
= key
;
4520 const struct ffp_frag_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
, const struct ffp_frag_desc
, entry
)->settings
;
4522 return memcmp(ka
, kb
, sizeof(*ka
));
4525 const struct wine_rb_functions wined3d_ffp_frag_program_rb_functions
=
4530 ffp_frag_program_key_compare
,
4533 void wined3d_ffp_get_vs_settings(const struct wined3d_state
*state
, const struct wined3d_stream_info
*si
,
4534 struct wined3d_ffp_vs_settings
*settings
)
4536 unsigned int coord_idx
, i
;
4538 if (si
->position_transformed
)
4540 memset(settings
, 0, sizeof(*settings
));
4542 settings
->transformed
= 1;
4543 settings
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
4544 settings
->per_vertex_point_size
= !!(si
->use_map
& 1 << WINED3D_FFP_PSIZE
);
4545 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
4546 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
4547 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
4548 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
4550 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
4552 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
4554 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
4555 if (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1 << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
4556 settings
->texcoords
|= 1 << i
;
4557 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
4562 switch (state
->render_states
[WINED3D_RS_VERTEXBLEND
])
4564 case WINED3D_VBF_DISABLE
:
4565 case WINED3D_VBF_1WEIGHTS
:
4566 case WINED3D_VBF_2WEIGHTS
:
4567 case WINED3D_VBF_3WEIGHTS
:
4568 settings
->vertexblends
= state
->render_states
[WINED3D_RS_VERTEXBLEND
];
4571 FIXME("Unsupported vertex blending: %d\n", state
->render_states
[WINED3D_RS_VERTEXBLEND
]);
4575 settings
->transformed
= 0;
4576 settings
->clipping
= state
->render_states
[WINED3D_RS_CLIPPING
]
4577 && state
->render_states
[WINED3D_RS_CLIPPLANEENABLE
];
4578 settings
->normal
= !!(si
->use_map
& (1 << WINED3D_FFP_NORMAL
));
4579 settings
->normalize
= settings
->normal
&& state
->render_states
[WINED3D_RS_NORMALIZENORMALS
];
4580 settings
->lighting
= !!state
->render_states
[WINED3D_RS_LIGHTING
];
4581 settings
->localviewer
= !!state
->render_states
[WINED3D_RS_LOCALVIEWER
];
4582 settings
->point_size
= state
->gl_primitive_type
== GL_POINTS
;
4583 settings
->per_vertex_point_size
= !!(si
->use_map
& 1 << WINED3D_FFP_PSIZE
);
4585 if (state
->render_states
[WINED3D_RS_COLORVERTEX
] && (si
->use_map
& (1 << WINED3D_FFP_DIFFUSE
)))
4587 settings
->diffuse_source
= state
->render_states
[WINED3D_RS_DIFFUSEMATERIALSOURCE
];
4588 settings
->emissive_source
= state
->render_states
[WINED3D_RS_EMISSIVEMATERIALSOURCE
];
4589 settings
->ambient_source
= state
->render_states
[WINED3D_RS_AMBIENTMATERIALSOURCE
];
4590 settings
->specular_source
= state
->render_states
[WINED3D_RS_SPECULARMATERIALSOURCE
];
4594 settings
->diffuse_source
= WINED3D_MCS_MATERIAL
;
4595 settings
->emissive_source
= WINED3D_MCS_MATERIAL
;
4596 settings
->ambient_source
= WINED3D_MCS_MATERIAL
;
4597 settings
->specular_source
= WINED3D_MCS_MATERIAL
;
4600 settings
->texcoords
= 0;
4601 for (i
= 0; i
< MAX_TEXTURES
; ++i
)
4603 coord_idx
= state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
4604 if (coord_idx
< MAX_TEXTURES
&& (si
->use_map
& (1 << (WINED3D_FFP_TEXCOORD0
+ coord_idx
))))
4605 settings
->texcoords
|= 1 << i
;
4606 settings
->texgen
[i
] = state
->texture_states
[i
][WINED3D_TSS_TEXCOORD_INDEX
];
4609 settings
->light_type
= 0;
4610 for (i
= 0; i
< MAX_ACTIVE_LIGHTS
; ++i
)
4612 if (state
->lights
[i
])
4613 settings
->light_type
|= (state
->lights
[i
]->OriginalParms
.type
4614 & WINED3D_FFP_LIGHT_TYPE_MASK
) << WINED3D_FFP_LIGHT_TYPE_SHIFT(i
);
4617 settings
->ortho_fog
= 0;
4618 if (!state
->render_states
[WINED3D_RS_FOGENABLE
])
4619 settings
->fog_mode
= WINED3D_FFP_VS_FOG_OFF
;
4620 else if (state
->render_states
[WINED3D_RS_FOGTABLEMODE
] != WINED3D_FOG_NONE
)
4622 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
4624 if (state
->transforms
[WINED3D_TS_PROJECTION
]._14
== 0.0f
4625 && state
->transforms
[WINED3D_TS_PROJECTION
]._24
== 0.0f
4626 && state
->transforms
[WINED3D_TS_PROJECTION
]._34
== 0.0f
4627 && state
->transforms
[WINED3D_TS_PROJECTION
]._44
== 1.0f
)
4628 settings
->ortho_fog
= 1;
4630 else if (state
->render_states
[WINED3D_RS_FOGVERTEXMODE
] == WINED3D_FOG_NONE
)
4631 settings
->fog_mode
= WINED3D_FFP_VS_FOG_FOGCOORD
;
4632 else if (state
->render_states
[WINED3D_RS_RANGEFOGENABLE
])
4633 settings
->fog_mode
= WINED3D_FFP_VS_FOG_RANGE
;
4635 settings
->fog_mode
= WINED3D_FFP_VS_FOG_DEPTH
;
4637 settings
->padding
= 0;
4640 static int wined3d_ffp_vertex_program_key_compare(const void *key
, const struct wine_rb_entry
*entry
)
4642 const struct wined3d_ffp_vs_settings
*ka
= key
;
4643 const struct wined3d_ffp_vs_settings
*kb
= &WINE_RB_ENTRY_VALUE(entry
,
4644 const struct wined3d_ffp_vs_desc
, entry
)->settings
;
4646 return memcmp(ka
, kb
, sizeof(*ka
));
4649 const struct wine_rb_functions wined3d_ffp_vertex_program_rb_functions
=
4654 wined3d_ffp_vertex_program_key_compare
,
4657 const struct blit_shader
*wined3d_select_blitter(const struct wined3d_gl_info
*gl_info
,
4658 const struct wined3d_d3d_info
*d3d_info
, enum wined3d_blit_op blit_op
,
4659 const RECT
*src_rect
, DWORD src_usage
, enum wined3d_pool src_pool
, const struct wined3d_format
*src_format
,
4660 const RECT
*dst_rect
, DWORD dst_usage
, enum wined3d_pool dst_pool
, const struct wined3d_format
*dst_format
)
4662 static const struct blit_shader
* const blitters
[] =
4670 for (i
= 0; i
< sizeof(blitters
) / sizeof(*blitters
); ++i
)
4672 if (blitters
[i
]->blit_supported(gl_info
, d3d_info
, blit_op
,
4673 src_rect
, src_usage
, src_pool
, src_format
,
4674 dst_rect
, dst_usage
, dst_pool
, dst_format
))
4681 void wined3d_get_draw_rect(const struct wined3d_state
*state
, RECT
*rect
)
4683 const struct wined3d_viewport
*vp
= &state
->viewport
;
4685 SetRect(rect
, vp
->x
, vp
->y
, vp
->x
+ vp
->width
, vp
->y
+ vp
->height
);
4687 if (state
->render_states
[WINED3D_RS_SCISSORTESTENABLE
])
4688 IntersectRect(rect
, rect
, &state
->scissor_rect
);
4691 const char *wined3d_debug_location(DWORD location
)
4696 #define LOCATION_TO_STR(u) if (location & u) { strcat(buf, " | "#u); location &= ~u; }
4697 LOCATION_TO_STR(WINED3D_LOCATION_DISCARDED
);
4698 LOCATION_TO_STR(WINED3D_LOCATION_SYSMEM
);
4699 LOCATION_TO_STR(WINED3D_LOCATION_USER_MEMORY
);
4700 LOCATION_TO_STR(WINED3D_LOCATION_DIB
);
4701 LOCATION_TO_STR(WINED3D_LOCATION_BUFFER
);
4702 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_RGB
);
4703 LOCATION_TO_STR(WINED3D_LOCATION_TEXTURE_SRGB
);
4704 LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE
);
4705 LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE
);
4706 LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED
);
4707 #undef LOCATION_TO_STR
4708 if (location
) FIXME("Unrecognized location flag(s) %#x.\n", location
);
4710 return buf
[0] ? wine_dbg_sprintf("%s", &buf
[3]) : "0";
4713 /* Print a floating point value with the %.8e format specifier, always using
4714 * '.' as decimal separator. */
4715 void wined3d_ftoa(float value
, char *s
)
4719 if (copysignf(1.0f
, value
) < 0.0f
)
4722 /* Be sure to allocate a buffer of at least 17 characters for the result
4723 as sprintf may return a 3 digit exponent when using the MSVC runtime
4724 instead of a 2 digit exponent. */
4725 sprintf(s
, "%.8e", value
);
4726 if (isfinite(value
))
4730 void wined3d_release_dc(HWND window
, HDC dc
)
4732 /* You'd figure ReleaseDC() would fail if the DC doesn't match the window.
4733 * However, that's not what actually happens, and there are user32 tests
4734 * that confirm ReleaseDC() with the wrong window is supposed to succeed.
4735 * So explicitly check that the DC belongs to the window, since we want to
4736 * avoid releasing a DC that belongs to some other window if the original
4737 * window was already destroyed. */
4738 if (WindowFromDC(dc
) != window
)
4739 WARN("DC %p does not belong to window %p.\n", dc
, window
);
4740 else if (!ReleaseDC(window
, dc
))
4741 ERR("Failed to release device context %p, last error %#x.\n", dc
, GetLastError());