include: Add definitions of SERVICES_*_DATABASEW for generic compilers.
[wine.git] / dlls / d3d10 / d3d10_main.c
blob7c8bee7534d47fe96e5ae63708b10475ea9aa6b1
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 "config.h"
24 #include "wine/port.h"
26 #include "d3d10_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d10);
30 HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
31 HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device)
33 IDXGIFactory *factory;
34 HRESULT hr;
36 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %#x, device %p.\n",
37 adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version, device);
39 if (sdk_version != D3D10_SDK_VERSION)
41 WARN("Invalid SDK version %#x.\n", sdk_version);
42 return E_INVALIDARG;
45 if (adapter)
47 IDXGIAdapter_AddRef(adapter);
48 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
49 if (FAILED(hr))
51 WARN("Failed to get dxgi factory, returning %#x.\n", hr);
52 return hr;
55 else
57 hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory);
58 if (FAILED(hr))
60 WARN("Failed to create dxgi factory, returning %#x.\n", hr);
61 return hr;
64 switch (driver_type)
66 case D3D10_DRIVER_TYPE_HARDWARE:
68 hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
69 if (FAILED(hr))
71 WARN("No adapters found, returning %#x.\n", hr);
72 IDXGIFactory_Release(factory);
73 return hr;
75 break;
78 case D3D10_DRIVER_TYPE_NULL:
79 FIXME("NULL device not implemented, falling back to refrast.\n");
80 /* fall through, for now */
81 case D3D10_DRIVER_TYPE_REFERENCE:
83 HMODULE refrast = LoadLibraryA("d3d10ref.dll");
84 if (!refrast)
86 WARN("Failed to load refrast, returning E_FAIL.\n");
87 IDXGIFactory_Release(factory);
88 return E_FAIL;
90 hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter);
91 FreeLibrary(refrast);
92 if (FAILED(hr))
94 WARN("Failed to create a software adapter, returning %#x.\n", hr);
95 IDXGIFactory_Release(factory);
96 return hr;
98 break;
101 case D3D10_DRIVER_TYPE_SOFTWARE:
103 if (!swrast)
105 WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n");
106 IDXGIFactory_Release(factory);
107 return E_FAIL;
109 hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter);
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 default:
120 FIXME("Unhandled driver type %#x.\n", driver_type);
121 IDXGIFactory_Release(factory);
122 return E_FAIL;
126 hr = D3D10CoreCreateDevice(factory, adapter, flags, D3D_FEATURE_LEVEL_10_0, device);
127 IDXGIAdapter_Release(adapter);
128 IDXGIFactory_Release(factory);
129 if (FAILED(hr))
131 WARN("Failed to create a device, returning %#x.\n", hr);
132 return hr;
135 TRACE("Created ID3D10Device %p.\n", *device);
137 return hr;
140 HRESULT WINAPI D3D10CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type,
141 HMODULE swrast, UINT flags, UINT sdk_version, DXGI_SWAP_CHAIN_DESC *swapchain_desc,
142 IDXGISwapChain **swapchain, ID3D10Device **device)
144 IDXGIDevice *dxgi_device;
145 IDXGIFactory *factory;
146 HRESULT hr;
148 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %d, "
149 "swapchain_desc %p, swapchain %p, device %p\n",
150 adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version,
151 swapchain_desc, swapchain, device);
153 hr = D3D10CreateDevice(adapter, driver_type, swrast, flags, sdk_version, device);
154 if (FAILED(hr))
156 WARN("Failed to create a device, returning %#x\n", hr);
157 *device = NULL;
158 return hr;
161 TRACE("Created ID3D10Device %p\n", *device);
163 hr = ID3D10Device_QueryInterface(*device, &IID_IDXGIDevice, (void **)&dxgi_device);
164 if (FAILED(hr))
166 ERR("Failed to get a dxgi device from the d3d10 device, returning %#x\n", hr);
167 ID3D10Device_Release(*device);
168 *device = NULL;
169 return hr;
172 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
173 IDXGIDevice_Release(dxgi_device);
174 if (FAILED(hr))
176 ERR("Failed to get the device adapter, returning %#x\n", hr);
177 ID3D10Device_Release(*device);
178 *device = NULL;
179 return hr;
182 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
183 IDXGIAdapter_Release(adapter);
184 if (FAILED(hr))
186 ERR("Failed to get the adapter factory, returning %#x\n", hr);
187 ID3D10Device_Release(*device);
188 *device = NULL;
189 return hr;
192 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)*device, swapchain_desc, swapchain);
193 IDXGIFactory_Release(factory);
194 if (FAILED(hr))
196 ID3D10Device_Release(*device);
197 *device = NULL;
199 WARN("Failed to create a swapchain, returning %#x\n", hr);
200 return hr;
203 TRACE("Created IDXGISwapChain %p\n", *swapchain);
205 return S_OK;
208 static int d3d10_effect_type_compare(const void *key, const struct wine_rb_entry *entry)
210 const struct d3d10_effect_type *t = WINE_RB_ENTRY_VALUE(entry, const struct d3d10_effect_type, entry);
211 const DWORD *id = key;
213 return *id - t->id;
216 HRESULT WINAPI D3D10CreateEffectFromMemory(void *data, SIZE_T data_size, UINT flags,
217 ID3D10Device *device, ID3D10EffectPool *effect_pool, ID3D10Effect **effect)
219 struct d3d10_effect *object;
220 HRESULT hr;
222 FIXME("data %p, data_size %lu, flags %#x, device %p, effect_pool %p, effect %p stub!\n",
223 data, data_size, flags, device, effect_pool, effect);
225 if (!(object = heap_alloc_zero(sizeof(*object))))
227 ERR("Failed to allocate D3D10 effect object memory\n");
228 return E_OUTOFMEMORY;
231 wine_rb_init(&object->types, d3d10_effect_type_compare);
232 object->ID3D10Effect_iface.lpVtbl = &d3d10_effect_vtbl;
233 object->refcount = 1;
234 ID3D10Device_AddRef(device);
235 object->device = device;
237 hr = d3d10_effect_parse(object, data, data_size);
238 if (FAILED(hr))
240 ERR("Failed to parse effect\n");
241 IUnknown_Release(&object->ID3D10Effect_iface);
242 return hr;
245 *effect = &object->ID3D10Effect_iface;
247 TRACE("Created ID3D10Effect %p\n", object);
249 return S_OK;
252 HRESULT WINAPI D3D10CompileEffectFromMemory(void *data, SIZE_T data_size, const char *filename,
253 const D3D10_SHADER_MACRO *defines, ID3D10Include *include, UINT hlsl_flags, UINT fx_flags,
254 ID3D10Blob **effect, ID3D10Blob **errors)
256 TRACE("data %p, data_size %lu, filename %s, defines %p, include %p, "
257 "hlsl_flags %#x, fx_flags %#x, effect %p, errors %p.\n",
258 data, data_size, wine_dbgstr_a(filename), defines, include,
259 hlsl_flags, fx_flags, effect, errors);
261 return D3DCompile(data, data_size, filename, defines, include,
262 NULL, "fx_4_0", hlsl_flags, fx_flags, effect, errors);
265 HRESULT WINAPI D3D10CreateEffectPoolFromMemory(void *data, SIZE_T data_size, UINT fx_flags,
266 ID3D10Device *device, ID3D10EffectPool **effect_pool)
268 FIXME("data %p, data_size %lu, fx_flags %#x, device %p, effect_pool %p stub.\n",
269 data, data_size, fx_flags, device, effect_pool);
271 return E_NOTIMPL;
274 const char * WINAPI D3D10GetVertexShaderProfile(ID3D10Device *device)
276 FIXME("device %p stub!\n", device);
278 return "vs_4_0";
281 const char * WINAPI D3D10GetGeometryShaderProfile(ID3D10Device *device)
283 FIXME("device %p stub!\n", device);
285 return "gs_4_0";
288 const char * WINAPI D3D10GetPixelShaderProfile(ID3D10Device *device)
290 FIXME("device %p stub!\n", device);
292 return "ps_4_0";
295 HRESULT WINAPI D3D10ReflectShader(const void *data, SIZE_T data_size, ID3D10ShaderReflection **reflector)
297 struct d3d10_shader_reflection *object;
299 FIXME("data %p, data_size %lu, reflector %p stub!\n", data, data_size, reflector);
301 if (!(object = heap_alloc_zero(sizeof(*object))))
303 ERR("Failed to allocate D3D10 shader reflection object memory\n");
304 return E_OUTOFMEMORY;
307 object->ID3D10ShaderReflection_iface.lpVtbl = &d3d10_shader_reflection_vtbl;
308 object->refcount = 1;
310 *reflector = &object->ID3D10ShaderReflection_iface;
312 TRACE("Created ID3D10ShaderReflection %p\n", object);
314 return S_OK;