widl: Generate helper macros for WinRT implementation.
[wine/zf.git] / dlls / d3d10 / d3d10_main.c
blob2d08c82a3c4503f5484a51dc8c98af379adeaf98
1 /*
2 * Direct3D 10
4 * Copyright 2007 Andras Kovacs
5 * Copyright 2009 Henri Verbeet for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "d3d10_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d10);
27 #define WINE_D3D10_TO_STR(x) case x: return #x
29 static const char *debug_d3d10_driver_type(D3D10_DRIVER_TYPE driver_type)
31 switch (driver_type)
33 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_HARDWARE);
34 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_REFERENCE);
35 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_NULL);
36 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_SOFTWARE);
37 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_WARP);
38 default:
39 FIXME("Unrecognised D3D10_DRIVER_TYPE %#x.\n", driver_type);
40 return "unrecognised";
44 #undef WINE_D3D10_TO_STR
46 static HRESULT d3d10_create_device(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
47 HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device)
49 IDXGIFactory *factory;
50 HRESULT hr;
52 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %#x, device %p.\n",
53 adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version, device);
55 if (sdk_version != D3D10_SDK_VERSION)
57 WARN("Invalid SDK version %#x.\n", sdk_version);
58 return E_INVALIDARG;
61 if (adapter)
63 IDXGIAdapter_AddRef(adapter);
64 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
65 if (FAILED(hr))
67 WARN("Failed to get dxgi factory, returning %#x.\n", hr);
68 return hr;
71 else
73 hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory);
74 if (FAILED(hr))
76 WARN("Failed to create dxgi factory, returning %#x.\n", hr);
77 return hr;
80 switch (driver_type)
82 case D3D10_DRIVER_TYPE_WARP:
83 FIXME("WARP driver not implemented, falling back to hardware.\n");
84 case D3D10_DRIVER_TYPE_HARDWARE:
86 hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
87 if (FAILED(hr))
89 WARN("No adapters found, returning %#x.\n", hr);
90 IDXGIFactory_Release(factory);
91 return hr;
93 break;
96 case D3D10_DRIVER_TYPE_NULL:
97 FIXME("NULL device not implemented, falling back to refrast.\n");
98 /* fall through, for now */
99 case D3D10_DRIVER_TYPE_REFERENCE:
101 HMODULE refrast = LoadLibraryA("d3d10ref.dll");
102 if (!refrast)
104 WARN("Failed to load refrast, returning E_FAIL.\n");
105 IDXGIFactory_Release(factory);
106 return E_FAIL;
108 hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter);
109 FreeLibrary(refrast);
110 if (FAILED(hr))
112 WARN("Failed to create a software adapter, returning %#x.\n", hr);
113 IDXGIFactory_Release(factory);
114 return hr;
116 break;
119 case D3D10_DRIVER_TYPE_SOFTWARE:
121 if (!swrast)
123 WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n");
124 IDXGIFactory_Release(factory);
125 return E_FAIL;
127 hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter);
128 if (FAILED(hr))
130 WARN("Failed to create a software adapter, returning %#x.\n", hr);
131 IDXGIFactory_Release(factory);
132 return hr;
134 break;
137 default:
138 FIXME("Unhandled driver type %#x.\n", driver_type);
139 IDXGIFactory_Release(factory);
140 return E_FAIL;
144 hr = D3D10CoreCreateDevice(factory, adapter, flags, D3D_FEATURE_LEVEL_10_0, device);
145 IDXGIAdapter_Release(adapter);
146 IDXGIFactory_Release(factory);
147 if (FAILED(hr))
149 WARN("Failed to create a device, returning %#x.\n", hr);
150 return hr;
153 TRACE("Created ID3D10Device %p.\n", *device);
155 return hr;
158 HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
159 HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device)
161 return d3d10_create_device(adapter, driver_type, swrast, flags, sdk_version, device);
164 HRESULT WINAPI D3D10CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
165 HMODULE swrast, UINT flags, UINT sdk_version, DXGI_SWAP_CHAIN_DESC *swapchain_desc,
166 IDXGISwapChain **swapchain, ID3D10Device **device)
168 IDXGIDevice *dxgi_device;
169 IDXGIFactory *factory;
170 HRESULT hr;
172 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %d, "
173 "swapchain_desc %p, swapchain %p, device %p\n",
174 adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version,
175 swapchain_desc, swapchain, device);
177 /* Avoid forwarding to D3D10CreateDevice(), since it breaks applications
178 * hooking these entry-points. */
179 if (FAILED(hr = d3d10_create_device(adapter, driver_type, swrast, flags, sdk_version, device)))
181 WARN("Failed to create a device, returning %#x\n", hr);
182 *device = NULL;
183 return hr;
186 TRACE("Created ID3D10Device %p\n", *device);
188 hr = ID3D10Device_QueryInterface(*device, &IID_IDXGIDevice, (void **)&dxgi_device);
189 if (FAILED(hr))
191 ERR("Failed to get a dxgi device from the d3d10 device, returning %#x\n", hr);
192 ID3D10Device_Release(*device);
193 *device = NULL;
194 return hr;
197 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
198 IDXGIDevice_Release(dxgi_device);
199 if (FAILED(hr))
201 ERR("Failed to get the device adapter, returning %#x\n", hr);
202 ID3D10Device_Release(*device);
203 *device = NULL;
204 return hr;
207 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
208 IDXGIAdapter_Release(adapter);
209 if (FAILED(hr))
211 ERR("Failed to get the adapter factory, returning %#x\n", hr);
212 ID3D10Device_Release(*device);
213 *device = NULL;
214 return hr;
217 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)*device, swapchain_desc, swapchain);
218 IDXGIFactory_Release(factory);
219 if (FAILED(hr))
221 ID3D10Device_Release(*device);
222 *device = NULL;
224 WARN("Failed to create a swapchain, returning %#x\n", hr);
225 return hr;
228 TRACE("Created IDXGISwapChain %p\n", *swapchain);
230 return S_OK;
233 static int d3d10_effect_type_compare(const void *key, const struct wine_rb_entry *entry)
235 const struct d3d10_effect_type *t = WINE_RB_ENTRY_VALUE(entry, const struct d3d10_effect_type, entry);
236 const DWORD *id = key;
238 return *id - t->id;
241 HRESULT WINAPI D3D10CreateEffectFromMemory(void *data, SIZE_T data_size, UINT flags,
242 ID3D10Device *device, ID3D10EffectPool *effect_pool, ID3D10Effect **effect)
244 struct d3d10_effect *object;
245 HRESULT hr;
247 FIXME("data %p, data_size %lu, flags %#x, device %p, effect_pool %p, effect %p stub!\n",
248 data, data_size, flags, device, effect_pool, effect);
250 if (!(object = heap_alloc_zero(sizeof(*object))))
252 ERR("Failed to allocate D3D10 effect object memory\n");
253 return E_OUTOFMEMORY;
256 wine_rb_init(&object->types, d3d10_effect_type_compare);
257 object->ID3D10Effect_iface.lpVtbl = &d3d10_effect_vtbl;
258 object->refcount = 1;
259 ID3D10Device_AddRef(device);
260 object->device = device;
262 hr = d3d10_effect_parse(object, data, data_size);
263 if (FAILED(hr))
265 ERR("Failed to parse effect\n");
266 IUnknown_Release(&object->ID3D10Effect_iface);
267 return hr;
270 *effect = &object->ID3D10Effect_iface;
272 TRACE("Created ID3D10Effect %p\n", object);
274 return S_OK;
277 HRESULT WINAPI D3D10CompileEffectFromMemory(void *data, SIZE_T data_size, const char *filename,
278 const D3D10_SHADER_MACRO *defines, ID3D10Include *include, UINT hlsl_flags, UINT fx_flags,
279 ID3D10Blob **effect, ID3D10Blob **errors)
281 TRACE("data %p, data_size %lu, filename %s, defines %p, include %p, "
282 "hlsl_flags %#x, fx_flags %#x, effect %p, errors %p.\n",
283 data, data_size, wine_dbgstr_a(filename), defines, include,
284 hlsl_flags, fx_flags, effect, errors);
286 return D3DCompile(data, data_size, filename, defines, include,
287 NULL, "fx_4_0", hlsl_flags, fx_flags, effect, errors);
290 HRESULT WINAPI D3D10CreateEffectPoolFromMemory(void *data, SIZE_T data_size, UINT fx_flags,
291 ID3D10Device *device, ID3D10EffectPool **effect_pool)
293 FIXME("data %p, data_size %lu, fx_flags %#x, device %p, effect_pool %p stub.\n",
294 data, data_size, fx_flags, device, effect_pool);
296 return E_NOTIMPL;
299 const char * WINAPI D3D10GetVertexShaderProfile(ID3D10Device *device)
301 FIXME("device %p stub!\n", device);
303 return "vs_4_0";
306 const char * WINAPI D3D10GetGeometryShaderProfile(ID3D10Device *device)
308 FIXME("device %p stub!\n", device);
310 return "gs_4_0";
313 const char * WINAPI D3D10GetPixelShaderProfile(ID3D10Device *device)
315 FIXME("device %p stub!\n", device);
317 return "ps_4_0";