msscript: Implement AddObject().
[wine.git] / dlls / d3d10_1 / d3d10_1_main.c
blobe9fad3ed093925ed4ede3fd09d8fec8fcba995c3
1 /*
2 * Copyright 2014 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
22 #include "wine/debug.h"
24 #define COBJMACROS
25 #include "d3d10_1.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d10);
29 HRESULT WINAPI D3D10CoreCreateDevice(IDXGIFactory *factory, IDXGIAdapter *adapter,
30 unsigned int flags, D3D_FEATURE_LEVEL feature_level, ID3D10Device **device);
32 #define WINE_D3D10_TO_STR(x) case x: return #x
34 static const char *debug_d3d10_driver_type(D3D10_DRIVER_TYPE driver_type)
36 switch (driver_type)
38 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_HARDWARE);
39 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_REFERENCE);
40 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_NULL);
41 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_SOFTWARE);
42 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_WARP);
43 default:
44 FIXME("Unrecognized D3D10_DRIVER_TYPE %#x.\n", driver_type);
45 return "unrecognized";
49 static const char *debug_d3d10_feature_level(D3D10_FEATURE_LEVEL1 feature_level)
51 switch (feature_level)
53 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_10_0);
54 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_10_1);
55 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_9_1);
56 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_9_2);
57 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_9_3);
58 default:
59 FIXME("Unrecognized D3D10_FEATURE_LEVEL1 %#x.\n", feature_level);
60 return "unrecognized";
64 #undef WINE_D3D10_TO_STR
66 HRESULT WINAPI D3D10CreateDevice1(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, HMODULE swrast,
67 UINT flags, D3D10_FEATURE_LEVEL1 hw_level, UINT sdk_version, ID3D10Device1 **device)
69 IDXGIFactory *factory;
70 HRESULT hr;
72 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, hw_level %s, sdk_version %d, device %p.\n",
73 adapter, debug_d3d10_driver_type(driver_type), swrast, flags,
74 debug_d3d10_feature_level(hw_level), sdk_version, device);
76 if (!device)
77 return E_INVALIDARG;
79 *device = NULL;
81 if (!hw_level)
82 return E_INVALIDARG;
84 if (adapter)
86 IDXGIAdapter_AddRef(adapter);
87 if (FAILED(hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory)))
89 WARN("Failed to get dxgi factory, hr %#x.\n", hr);
90 return hr;
93 else
95 if (FAILED(hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory)))
97 WARN("Failed to create dxgi factory, hr %#x.\n", hr);
98 return hr;
101 switch (driver_type)
103 case D3D10_DRIVER_TYPE_WARP:
104 FIXME("WARP driver not implemented, falling back to hardware.\n");
105 case D3D10_DRIVER_TYPE_HARDWARE:
107 if (FAILED(hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter)))
109 WARN("No adapters found, hr %#x.\n", hr);
110 IDXGIFactory_Release(factory);
111 return hr;
113 break;
116 case D3D10_DRIVER_TYPE_NULL:
117 FIXME("NULL device not implemented, falling back to refrast.\n");
118 /* Fall through, for now. */
119 case D3D10_DRIVER_TYPE_REFERENCE:
121 HMODULE refrast;
123 if (!(refrast = LoadLibraryA("d3d10ref.dll")))
125 WARN("Failed to load refrast, returning E_FAIL.\n");
126 IDXGIFactory_Release(factory);
127 return E_FAIL;
129 hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter);
130 FreeLibrary(refrast);
131 if (FAILED(hr))
133 WARN("Failed to create a software adapter, hr %#x.\n", hr);
134 IDXGIFactory_Release(factory);
135 return hr;
137 break;
140 case D3D10_DRIVER_TYPE_SOFTWARE:
142 if (!swrast)
144 WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n");
145 IDXGIFactory_Release(factory);
146 return E_FAIL;
148 if (FAILED(hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter)))
150 WARN("Failed to create a software adapter, hr %#x.\n", hr);
151 IDXGIFactory_Release(factory);
152 return hr;
154 break;
157 default:
158 FIXME("Unhandled driver type %#x.\n", driver_type);
159 IDXGIFactory_Release(factory);
160 return E_FAIL;
164 hr = D3D10CoreCreateDevice(factory, adapter, flags, hw_level, (ID3D10Device **)device);
165 IDXGIAdapter_Release(adapter);
166 IDXGIFactory_Release(factory);
167 if (FAILED(hr))
169 WARN("Failed to create a device, hr %#x.\n", hr);
170 return hr;
173 TRACE("Created device %p.\n", *device);
175 return hr;
178 HRESULT WINAPI D3D10CreateDeviceAndSwapChain1(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
179 HMODULE swrast, UINT flags, D3D10_FEATURE_LEVEL1 feature_level, UINT sdk_version,
180 DXGI_SWAP_CHAIN_DESC *swapchain_desc, IDXGISwapChain **swapchain, ID3D10Device1 **device)
182 IDXGIDevice *dxgi_device;
183 IDXGIFactory *factory;
184 HRESULT hr;
186 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, "
187 "feature_level %s, sdk_version %d, swapchain_desc %p, swapchain %p, device %p.\n",
188 adapter, debug_d3d10_driver_type(driver_type), swrast, flags,
189 debug_d3d10_feature_level(feature_level), sdk_version, swapchain_desc, swapchain, device);
191 if (swapchain)
192 *swapchain = NULL;
194 if (!device)
195 return E_INVALIDARG;
197 if (FAILED(hr = D3D10CreateDevice1(adapter, driver_type, swrast, flags, feature_level, sdk_version, device)))
199 WARN("Failed to create a device, returning %#x.\n", hr);
200 *device = NULL;
201 return hr;
204 if (swapchain)
206 if (FAILED(hr = ID3D10Device1_QueryInterface(*device, &IID_IDXGIDevice, (void **)&dxgi_device)))
208 ERR("Failed to get a dxgi device from the d3d10 device, returning %#x.\n", hr);
209 goto cleanup;
212 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
213 IDXGIDevice_Release(dxgi_device);
214 if (FAILED(hr))
216 ERR("Failed to get the device adapter, returning %#x.\n", hr);
217 goto cleanup;
220 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
221 IDXGIAdapter_Release(adapter);
222 if (FAILED(hr))
224 ERR("Failed to get the adapter factory, returning %#x.\n", hr);
225 goto cleanup;
228 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)*device, swapchain_desc, swapchain);
229 IDXGIFactory_Release(factory);
230 if (FAILED(hr))
232 WARN("Failed to create a swapchain, returning %#x.\n", hr);
233 goto cleanup;
236 TRACE("Created IDXGISwapChain %p.\n", *swapchain);
239 return S_OK;
241 cleanup:
242 ID3D10Device1_Release(*device);
243 *device = NULL;
244 return hr;