VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/directx.c@ 30720

Last change on this file since 30720 was 25949, checked in by vboxsync, 15 years ago

crOpenGL: update to wine 1.1.36 and disable unnecessary fbo state poll

  • Property svn:eol-style set to native
File size: 13.4 KB
Line 
1/*
2 * IDirect3D8 implementation
3 *
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 */
22
23/*
24 * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
25 * other than GPL or LGPL is available it will apply instead, Sun elects to use only
26 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
27 * a choice of LGPL license versions is made available with the language indicating
28 * that LGPLv2 or any later version may be used, or where a choice of which version
29 * of the LGPL is applied is otherwise unspecified.
30 */
31
32#include "config.h"
33
34#include <stdarg.h>
35
36#define NONAMELESSUNION
37#define NONAMELESSSTRUCT
38#include "windef.h"
39#include "winbase.h"
40#include "wingdi.h"
41#include "winuser.h"
42#include "wine/debug.h"
43#include "wine/unicode.h"
44
45#include "d3d8_private.h"
46
47WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
48
49/* IDirect3D IUnknown parts follow: */
50static HRESULT WINAPI IDirect3D8Impl_QueryInterface(LPDIRECT3D8 iface, REFIID riid,LPVOID *ppobj)
51{
52 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
53
54 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
55
56 if (IsEqualGUID(riid, &IID_IUnknown)
57 || IsEqualGUID(riid, &IID_IDirect3D8)) {
58 IUnknown_AddRef(iface);
59 *ppobj = This;
60 return S_OK;
61 }
62
63 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid),ppobj);
64 *ppobj = NULL;
65 return E_NOINTERFACE;
66}
67
68static ULONG WINAPI IDirect3D8Impl_AddRef(LPDIRECT3D8 iface) {
69 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
70 ULONG ref = InterlockedIncrement(&This->ref);
71
72 TRACE("%p increasing refcount to %u.\n", iface, ref);
73
74 return ref;
75}
76
77static ULONG WINAPI IDirect3D8Impl_Release(LPDIRECT3D8 iface) {
78 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
79 ULONG ref = InterlockedDecrement(&This->ref);
80
81 TRACE("%p decreasing refcount to %u.\n", iface, ref);
82
83 if (ref == 0) {
84 TRACE("Releasing wined3d %p\n", This->WineD3D);
85
86 wined3d_mutex_lock();
87 IWineD3D_Release(This->WineD3D);
88 wined3d_mutex_unlock();
89
90 HeapFree(GetProcessHeap(), 0, This);
91 }
92
93 return ref;
94}
95
96/* IDirect3D8 Interface follow: */
97static HRESULT WINAPI IDirect3D8Impl_RegisterSoftwareDevice (LPDIRECT3D8 iface, void* pInitializeFunction) {
98 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
99 HRESULT hr;
100
101 TRACE("iface %p, init_function %p.\n", iface, pInitializeFunction);
102
103 wined3d_mutex_lock();
104 hr = IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
105 wined3d_mutex_unlock();
106
107 return hr;
108}
109
110static UINT WINAPI IDirect3D8Impl_GetAdapterCount (LPDIRECT3D8 iface) {
111 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
112 HRESULT hr;
113
114 TRACE("iface %p.\n", iface);
115
116 wined3d_mutex_lock();
117 hr = IWineD3D_GetAdapterCount(This->WineD3D);
118 wined3d_mutex_unlock();
119
120 return hr;
121}
122
123static HRESULT WINAPI IDirect3D8Impl_GetAdapterIdentifier(LPDIRECT3D8 iface,
124 UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8 *pIdentifier)
125{
126 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
127 WINED3DADAPTER_IDENTIFIER adapter_id;
128 HRESULT hr;
129
130 TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
131 iface, Adapter, Flags, pIdentifier);
132
133 adapter_id.driver = pIdentifier->Driver;
134 adapter_id.driver_size = sizeof(pIdentifier->Driver);
135 adapter_id.description = pIdentifier->Description;
136 adapter_id.description_size = sizeof(pIdentifier->Description);
137 adapter_id.device_name = NULL; /* d3d9 only */
138 adapter_id.device_name_size = 0; /* d3d9 only */
139
140 wined3d_mutex_lock();
141 hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
142 wined3d_mutex_unlock();
143
144 pIdentifier->DriverVersion = adapter_id.driver_version;
145 pIdentifier->VendorId = adapter_id.vendor_id;
146 pIdentifier->DeviceId = adapter_id.device_id;
147 pIdentifier->SubSysId = adapter_id.subsystem_id;
148 pIdentifier->Revision = adapter_id.revision;
149 memcpy(&pIdentifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(pIdentifier->DeviceIdentifier));
150 pIdentifier->WHQLLevel = adapter_id.whql_level;
151
152 return hr;
153}
154
155static UINT WINAPI IDirect3D8Impl_GetAdapterModeCount (LPDIRECT3D8 iface,UINT Adapter) {
156 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
157 HRESULT hr;
158
159 TRACE("iface %p, adapter %u.\n", iface, Adapter);
160
161 wined3d_mutex_lock();
162 hr = IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, 0 /* format */);
163 wined3d_mutex_unlock();
164
165 return hr;
166}
167
168static HRESULT WINAPI IDirect3D8Impl_EnumAdapterModes (LPDIRECT3D8 iface, UINT Adapter, UINT Mode, D3DDISPLAYMODE* pMode) {
169 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
170 HRESULT hr;
171
172 TRACE("iface %p, adapter %u, mode_idx %u, mode %p.\n",
173 iface, Adapter, Mode, pMode);
174
175 wined3d_mutex_lock();
176 hr = IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, WINED3DFMT_UNKNOWN, Mode, (WINED3DDISPLAYMODE *) pMode);
177 wined3d_mutex_unlock();
178
179 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
180
181 return hr;
182}
183
184static HRESULT WINAPI IDirect3D8Impl_GetAdapterDisplayMode (LPDIRECT3D8 iface, UINT Adapter, D3DDISPLAYMODE* pMode) {
185 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
186 HRESULT hr;
187
188 TRACE("iface %p, adapter %u, mode %p.\n",
189 iface, Adapter, pMode);
190
191 wined3d_mutex_lock();
192 hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
193 wined3d_mutex_unlock();
194
195 if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
196
197 return hr;
198}
199
200static HRESULT WINAPI IDirect3D8Impl_CheckDeviceType (LPDIRECT3D8 iface,
201 UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
202 D3DFORMAT BackBufferFormat, BOOL Windowed) {
203 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
204 HRESULT hr;
205
206 TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
207 iface, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed);
208
209 wined3d_mutex_lock();
210 hr = IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
211 wined3dformat_from_d3dformat(BackBufferFormat), Windowed);
212 wined3d_mutex_unlock();
213
214 return hr;
215}
216
217static HRESULT WINAPI IDirect3D8Impl_CheckDeviceFormat (LPDIRECT3D8 iface,
218 UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
219 DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
220 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
221 HRESULT hr;
222 WINED3DRESOURCETYPE WineD3DRType;
223
224 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
225 iface, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
226
227 if(CheckFormat == D3DFMT_R8G8B8)
228 {
229 /* See comment in dlls/d3d9/directx.c, IDirect3D9Impl_CheckDeviceFormat for details */
230 WARN("D3DFMT_R8G8B8 is not available on windows, returning D3DERR_NOTAVAILABLE\n");
231 return D3DERR_NOTAVAILABLE;
232 }
233
234
235 switch(RType) {
236 case D3DRTYPE_VERTEXBUFFER:
237 case D3DRTYPE_INDEXBUFFER:
238 WineD3DRType = WINED3DRTYPE_BUFFER;
239 break;
240
241 default:
242 WineD3DRType = RType;
243 break;
244 }
245
246 wined3d_mutex_lock();
247 hr = IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
248 Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
249 wined3d_mutex_unlock();
250
251 return hr;
252}
253
254static HRESULT WINAPI IDirect3D8Impl_CheckDeviceMultiSampleType(IDirect3D8 *iface, UINT Adapter,
255 D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType)
256{
257 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
258 HRESULT hr;
259
260 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x.\n",
261 iface, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType);
262
263 wined3d_mutex_lock();
264 hr = IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType,
265 wined3dformat_from_d3dformat(SurfaceFormat), Windowed, (WINED3DMULTISAMPLE_TYPE) MultiSampleType, NULL);
266 wined3d_mutex_unlock();
267
268 return hr;
269}
270
271static HRESULT WINAPI IDirect3D8Impl_CheckDepthStencilMatch(IDirect3D8 *iface, UINT Adapter, D3DDEVTYPE DeviceType,
272 D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat)
273{
274 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
275 HRESULT hr;
276
277 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
278 iface, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
279
280 wined3d_mutex_lock();
281 hr = IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType,
282 wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
283 wined3dformat_from_d3dformat(DepthStencilFormat));
284 wined3d_mutex_unlock();
285
286 return hr;
287}
288
289void fixup_caps(WINED3DCAPS *caps)
290{
291 /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
292 if (caps->PixelShaderVersion > D3DPS_VERSION(1,4)) {
293 caps->PixelShaderVersion = D3DPS_VERSION(1,4);
294 }
295 if (caps->VertexShaderVersion > D3DVS_VERSION(1,1)) {
296 caps->VertexShaderVersion = D3DVS_VERSION(1,1);
297 }
298 caps->MaxVertexShaderConst = min(D3D8_MAX_VERTEX_SHADER_CONSTANTF, caps->MaxVertexShaderConst);
299
300 caps->StencilCaps &= ~WINED3DSTENCILCAPS_TWOSIDED;
301}
302
303static HRESULT WINAPI IDirect3D8Impl_GetDeviceCaps(LPDIRECT3D8 iface, UINT Adapter, D3DDEVTYPE DeviceType, D3DCAPS8* pCaps) {
304 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
305 HRESULT hrc = D3D_OK;
306 WINED3DCAPS *pWineCaps;
307
308 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, Adapter, DeviceType, pCaps);
309
310 if(NULL == pCaps){
311 return D3DERR_INVALIDCALL;
312 }
313 pWineCaps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINED3DCAPS));
314 if(pWineCaps == NULL){
315 return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
316 }
317
318 wined3d_mutex_lock();
319 hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
320 wined3d_mutex_unlock();
321
322 fixup_caps(pWineCaps);
323 WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
324 HeapFree(GetProcessHeap(), 0, pWineCaps);
325
326 TRACE("(%p) returning %p\n", This, pCaps);
327 return hrc;
328}
329
330static HMONITOR WINAPI IDirect3D8Impl_GetAdapterMonitor(LPDIRECT3D8 iface, UINT Adapter) {
331 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
332 HMONITOR ret;
333
334 TRACE("iface %p, adapter %u.\n", iface, Adapter);
335
336 wined3d_mutex_lock();
337 ret = IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
338 wined3d_mutex_unlock();
339
340 return ret;
341}
342
343static HRESULT WINAPI IDirect3D8Impl_CreateDevice(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type,
344 HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, IDirect3DDevice8 **device)
345{
346 IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
347 IDirect3DDevice8Impl *object;
348 HRESULT hr;
349
350 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
351 iface, adapter, device_type, focus_window, flags, parameters, device);
352
353 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
354 if (!object)
355 {
356 ERR("Failed to allocate device memory.\n");
357 return E_OUTOFMEMORY;
358 }
359
360 hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags, parameters);
361 if (FAILED(hr))
362 {
363 WARN("Failed to initialize device, hr %#x.\n", hr);
364 HeapFree(GetProcessHeap(), 0, object);
365 return hr;
366 }
367
368 TRACE("Created device %p.\n", object);
369 *device = (IDirect3DDevice8 *)object;
370
371 return D3D_OK;
372}
373
374const IDirect3D8Vtbl Direct3D8_Vtbl =
375{
376 /* IUnknown */
377 IDirect3D8Impl_QueryInterface,
378 IDirect3D8Impl_AddRef,
379 IDirect3D8Impl_Release,
380 /* IDirect3D8 */
381 IDirect3D8Impl_RegisterSoftwareDevice,
382 IDirect3D8Impl_GetAdapterCount,
383 IDirect3D8Impl_GetAdapterIdentifier,
384 IDirect3D8Impl_GetAdapterModeCount,
385 IDirect3D8Impl_EnumAdapterModes,
386 IDirect3D8Impl_GetAdapterDisplayMode,
387 IDirect3D8Impl_CheckDeviceType,
388 IDirect3D8Impl_CheckDeviceFormat,
389 IDirect3D8Impl_CheckDeviceMultiSampleType,
390 IDirect3D8Impl_CheckDepthStencilMatch,
391 IDirect3D8Impl_GetDeviceCaps,
392 IDirect3D8Impl_GetAdapterMonitor,
393 IDirect3D8Impl_CreateDevice
394};
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette