ReactOS 0.4.16-dev-197-g92996da
directx.c
Go to the documentation of this file.
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#include "config.h"
24
25#include <stdarg.h>
26
27#include "windef.h"
28#include "winbase.h"
29#include "wingdi.h"
30#include "winuser.h"
31#include "wine/debug.h"
32#include "wine/unicode.h"
33
34#include "d3d8_private.h"
35
37
38static inline struct d3d8 *impl_from_IDirect3D8(IDirect3D8 *iface)
39{
40 return CONTAINING_RECORD(iface, struct d3d8, IDirect3D8_iface);
41}
42
43static HRESULT WINAPI d3d8_QueryInterface(IDirect3D8 *iface, REFIID riid, void **out)
44{
45 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
46
47 if (IsEqualGUID(riid, &IID_IDirect3D8)
49 {
50 IDirect3D8_AddRef(iface);
51 *out = iface;
52 return S_OK;
53 }
54
55 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
56
57 *out = NULL;
58 return E_NOINTERFACE;
59}
60
61static ULONG WINAPI d3d8_AddRef(IDirect3D8 *iface)
62{
63 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
65
66 TRACE("%p increasing refcount to %u.\n", iface, refcount);
67
68 return refcount;
69}
70
71static ULONG WINAPI d3d8_Release(IDirect3D8 *iface)
72{
73 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
75
76 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
77
78 if (!refcount)
79 {
83
85 }
86
87 return refcount;
88}
89
90static HRESULT WINAPI d3d8_RegisterSoftwareDevice(IDirect3D8 *iface, void *init_function)
91{
92 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
93 HRESULT hr;
94
95 TRACE("iface %p, init_function %p.\n", iface, init_function);
96
100
101 return hr;
102}
103
104static UINT WINAPI d3d8_GetAdapterCount(IDirect3D8 *iface)
105{
106 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
107 HRESULT hr;
108
109 TRACE("iface %p.\n", iface);
110
114
115 return hr;
116}
117
120{
121 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
122 struct wined3d_adapter_identifier adapter_id;
123 HRESULT hr;
124
125 TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
126 iface, adapter, flags, identifier);
127
128 adapter_id.driver = identifier->Driver;
129 adapter_id.driver_size = sizeof(identifier->Driver);
130 adapter_id.description = identifier->Description;
131 adapter_id.description_size = sizeof(identifier->Description);
132 adapter_id.device_name = NULL; /* d3d9 only */
133 adapter_id.device_name_size = 0; /* d3d9 only */
134
138
139 identifier->DriverVersion = adapter_id.driver_version;
140 identifier->VendorId = adapter_id.vendor_id;
141 identifier->DeviceId = adapter_id.device_id;
142 identifier->SubSysId = adapter_id.subsystem_id;
143 identifier->Revision = adapter_id.revision;
144 memcpy(&identifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(identifier->DeviceIdentifier));
145 identifier->WHQLLevel = adapter_id.whql_level;
146
147 return hr;
148}
149
151{
152 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
153 HRESULT hr;
154
155 TRACE("iface %p, adapter %u.\n", iface, adapter);
156
161
162 return hr;
163}
164
166{
167 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
168 struct wined3d_display_mode wined3d_mode;
169 HRESULT hr;
170
171 TRACE("iface %p, adapter %u, mode_idx %u, mode %p.\n",
172 iface, adapter, mode_idx, mode);
173
176 WINED3D_SCANLINE_ORDERING_UNKNOWN, mode_idx, &wined3d_mode);
178
179 if (SUCCEEDED(hr))
180 {
181 mode->Width = wined3d_mode.width;
182 mode->Height = wined3d_mode.height;
183 mode->RefreshRate = wined3d_mode.refresh_rate;
184 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
185 }
186
187 return hr;
188}
189
191{
192 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
193 struct wined3d_display_mode wined3d_mode;
194 HRESULT hr;
195
196 TRACE("iface %p, adapter %u, mode %p.\n",
197 iface, adapter, mode);
198
202
203 if (SUCCEEDED(hr))
204 {
205 mode->Width = wined3d_mode.width;
206 mode->Height = wined3d_mode.height;
207 mode->RefreshRate = wined3d_mode.refresh_rate;
208 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
209 }
210
211 return hr;
212}
213
215 D3DFORMAT display_format, D3DFORMAT backbuffer_format, BOOL windowed)
216{
217 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
218 HRESULT hr;
219
220 TRACE("iface %p, adapter %u, device_type %#x, display_format %#x, backbuffer_format %#x, windowed %#x.\n",
221 iface, adapter, device_type, display_format, backbuffer_format, windowed);
222
223 if (!windowed && display_format != D3DFMT_X8R8G8B8 && display_format != D3DFMT_R5G6B5)
225
228 wined3dformat_from_d3dformat(backbuffer_format), windowed);
230
231 return hr;
232}
233
235 D3DFORMAT adapter_format, DWORD usage, D3DRESOURCETYPE resource_type, D3DFORMAT format)
236{
237 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
238 enum wined3d_resource_type wined3d_rtype;
239 HRESULT hr;
240
241 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
242 iface, adapter, device_type, adapter_format, usage, resource_type, format);
243
244 if (!adapter_format)
245 {
246 WARN("Invalid adapter format.\n");
247 return D3DERR_INVALIDCALL;
248 }
249
251 switch (resource_type)
252 {
255 case D3DRTYPE_TEXTURE:
257 case D3DRTYPE_SURFACE:
258 wined3d_rtype = WINED3D_RTYPE_TEXTURE_2D;
259 break;
260
262 case D3DRTYPE_VOLUME:
264 wined3d_rtype = WINED3D_RTYPE_TEXTURE_3D;
265 break;
266
269 wined3d_rtype = WINED3D_RTYPE_BUFFER;
270 break;
271
272 default:
273 FIXME("Unhandled resource type %#x.\n", resource_type);
275 }
276
279 usage, wined3d_rtype, wined3dformat_from_d3dformat(format));
281
282 return hr;
283}
284
286 D3DFORMAT format, BOOL windowed, D3DMULTISAMPLE_TYPE multisample_type)
287{
288 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
289 HRESULT hr;
290
291 TRACE("iface %p, adapter %u, device_type %#x, format %#x, windowed %#x, multisample_type %#x.\n",
292 iface, adapter, device_type, format, windowed, multisample_type);
293
294 if (multisample_type > D3DMULTISAMPLE_16_SAMPLES)
295 return D3DERR_INVALIDCALL;
296
300 (enum wined3d_multisample_type)multisample_type, NULL);
302
303 return hr;
304}
305
307 D3DFORMAT adapter_format, D3DFORMAT rt_format, D3DFORMAT ds_format)
308{
309 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
310 HRESULT hr;
311
312 TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, rt_format %#x, ds_format %#x.\n",
313 iface, adapter, device_type, adapter_format, rt_format, ds_format);
314
320
321 return hr;
322}
323
325{
326 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
327 WINED3DCAPS wined3d_caps;
328 HRESULT hr;
329
330 TRACE("iface %p, adapter %u, device_type %#x, caps %p.\n", iface, adapter, device_type, caps);
331
332 if (!caps)
333 return D3DERR_INVALIDCALL;
334
338
339 d3dcaps_from_wined3dcaps(caps, &wined3d_caps);
340
341 return hr;
342}
343
345{
346 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
348 HRESULT hr;
349
350 TRACE("iface %p, adapter %u.\n", iface, adapter);
351
355
356 if (FAILED(hr))
357 {
358 WARN("Failed to get output desc, hr %#x.\n", hr);
359 return NULL;
360 }
361
362 return desc.monitor;
363}
364
365static HRESULT WINAPI d3d8_CreateDevice(IDirect3D8 *iface, UINT adapter,
366 D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters,
367 IDirect3DDevice8 **device)
368{
369 struct d3d8 *d3d8 = impl_from_IDirect3D8(iface);
370 struct d3d8_device *object;
371 HRESULT hr;
372
373 TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
374 iface, adapter, device_type, focus_window, flags, parameters, device);
375
376 if (!(object = heap_alloc_zero(sizeof(*object))))
377 return E_OUTOFMEMORY;
378
379 hr = device_init(object, d3d8, d3d8->wined3d, adapter, device_type, focus_window, flags, parameters);
380 if (FAILED(hr))
381 {
382 WARN("Failed to initialize device, hr %#x.\n", hr);
383 heap_free(object);
384 return hr;
385 }
386
387 TRACE("Created device %p.\n", object);
388 *device = &object->IDirect3DDevice8_iface;
389
390 return D3D_OK;
391}
392
393static const struct IDirect3D8Vtbl d3d8_vtbl =
394{
395 /* IUnknown */
399 /* IDirect3D8 */
413};
414
416{
421
423 d3d8->refcount = 1;
424
428 if (!d3d8->wined3d)
429 return FALSE;
430
431 return TRUE;
432}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
const GUID IID_IUnknown
static HRESULT WINAPI d3d8_GetDeviceCaps(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type, D3DCAPS8 *caps)
Definition: directx.c:324
static ULONG WINAPI d3d8_Release(IDirect3D8 *iface)
Definition: directx.c:71
static UINT WINAPI d3d8_GetAdapterCount(IDirect3D8 *iface)
Definition: directx.c:104
static HRESULT WINAPI d3d8_CheckDeviceFormat(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type, D3DFORMAT adapter_format, DWORD usage, D3DRESOURCETYPE resource_type, D3DFORMAT format)
Definition: directx.c:234
static HRESULT WINAPI d3d8_EnumAdapterModes(IDirect3D8 *iface, UINT adapter, UINT mode_idx, D3DDISPLAYMODE *mode)
Definition: directx.c:165
static HRESULT WINAPI d3d8_CheckDeviceMultiSampleType(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type, D3DFORMAT format, BOOL windowed, D3DMULTISAMPLE_TYPE multisample_type)
Definition: directx.c:285
static HRESULT WINAPI d3d8_CheckDeviceType(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type, D3DFORMAT display_format, D3DFORMAT backbuffer_format, BOOL windowed)
Definition: directx.c:214
static struct d3d8 * impl_from_IDirect3D8(IDirect3D8 *iface)
Definition: directx.c:38
static HRESULT WINAPI d3d8_GetAdapterIdentifier(IDirect3D8 *iface, UINT adapter, DWORD flags, D3DADAPTER_IDENTIFIER8 *identifier)
Definition: directx.c:118
static HRESULT WINAPI d3d8_CreateDevice(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, IDirect3DDevice8 **device)
Definition: directx.c:365
static ULONG WINAPI d3d8_AddRef(IDirect3D8 *iface)
Definition: directx.c:61
static HRESULT WINAPI d3d8_RegisterSoftwareDevice(IDirect3D8 *iface, void *init_function)
Definition: directx.c:90
static HRESULT WINAPI d3d8_CheckDepthStencilMatch(IDirect3D8 *iface, UINT adapter, D3DDEVTYPE device_type, D3DFORMAT adapter_format, D3DFORMAT rt_format, D3DFORMAT ds_format)
Definition: directx.c:306
static HMONITOR WINAPI d3d8_GetAdapterMonitor(IDirect3D8 *iface, UINT adapter)
Definition: directx.c:344
static HRESULT WINAPI d3d8_QueryInterface(IDirect3D8 *iface, REFIID riid, void **out)
Definition: directx.c:43
BOOL d3d8_init(struct d3d8 *d3d8)
Definition: directx.c:415
static const struct IDirect3D8Vtbl d3d8_vtbl
Definition: directx.c:393
static HRESULT WINAPI d3d8_GetAdapterDisplayMode(IDirect3D8 *iface, UINT adapter, D3DDISPLAYMODE *mode)
Definition: directx.c:190
static UINT WINAPI d3d8_GetAdapterModeCount(IDirect3D8 *iface, UINT adapter)
Definition: directx.c:150
void d3dcaps_from_wined3dcaps(D3DCAPS8 *caps, const WINED3DCAPS *wined3d_caps) DECLSPEC_HIDDEN
Definition: device.c:290
enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_HIDDEN
Definition: device.c:94
D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format) DECLSPEC_HIDDEN
Definition: device.c:44
HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) DECLSPEC_HIDDEN
Definition: device.c:3279
enum _D3DRESOURCETYPE D3DRESOURCETYPE
enum _D3DDEVTYPE D3DDEVTYPE
@ D3DMULTISAMPLE_16_SAMPLES
Definition: d3d8types.h:687
@ D3DFMT_R5G6B5
Definition: d3d8types.h:606
@ D3DFMT_X8R8G8B8
Definition: d3d8types.h:605
@ D3DRTYPE_INDEXBUFFER
Definition: d3d8types.h:816
@ D3DRTYPE_TEXTURE
Definition: d3d8types.h:812
@ D3DRTYPE_VOLUMETEXTURE
Definition: d3d8types.h:813
@ D3DRTYPE_CUBETEXTURE
Definition: d3d8types.h:814
@ D3DRTYPE_VOLUME
Definition: d3d8types.h:811
@ D3DRTYPE_SURFACE
Definition: d3d8types.h:810
@ D3DRTYPE_VERTEXBUFFER
Definition: d3d8types.h:815
enum _D3DFORMAT D3DFORMAT
enum _D3DMULTISAMPLE_TYPE D3DMULTISAMPLE_TYPE
#define D3D_OK
Definition: d3d.h:106
#define D3DERR_INVALIDCALL
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
device_type
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
return adapter
GLenum mode
Definition: glext.h:6217
GLbitfield flags
Definition: glext.h:7161
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
#define debugstr_guid
Definition: kernel32.h:35
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static const WCHAR desc[]
Definition: protectdata.c:36
unsigned int UINT
Definition: ndis.h:50
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
static FILE * out
Definition: regtests2xml.c:44
#define IDirect3D8_AddRef(p)
Definition: d3d8.h:160
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
LARGE_INTEGER DriverVersion
Definition: d3d8types.h:999
char Driver[MAX_DEVICE_IDENTIFIER_STRING]
Definition: d3d8types.h:996
char Description[MAX_DEVICE_IDENTIFIER_STRING]
Definition: d3d8types.h:997
LONG refcount
Definition: d3d8_private.h:50
IDirect3D8 IDirect3D8_iface
Definition: d3d8_private.h:49
struct wined3d * wined3d
Definition: d3d8_private.h:51
Definition: devices.h:37
Definition: format.c:58
LARGE_INTEGER driver_version
Definition: wined3d.h:1719
enum wined3d_format_id format_id
Definition: wined3d.h:1584
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6
ULONG CDECL wined3d_decref(struct wined3d *wined3d)
Definition: directx.c:465
HRESULT CDECL wined3d_check_device_type(const struct wined3d *wined3d, UINT adapter_idx, enum wined3d_device_type device_type, enum wined3d_format_id display_format, enum wined3d_format_id backbuffer_format, BOOL windowed)
Definition: directx.c:5546
UINT CDECL wined3d_get_adapter_count(const struct wined3d *wined3d)
Definition: directx.c:4484
HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT adapter_idx, enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id, DWORD usage, enum wined3d_resource_type resource_type, enum wined3d_format_id check_format_id)
Definition: directx.c:5334
HRESULT CDECL wined3d_get_output_desc(const struct wined3d *wined3d, unsigned int adapter_idx, struct wined3d_output_desc *desc)
Definition: directx.c:4499
UINT CDECL wined3d_get_adapter_mode_count(const struct wined3d *wined3d, UINT adapter_idx, enum wined3d_format_id format_id, enum wined3d_scanline_ordering scanline_ordering)
Definition: directx.c:4536
HRESULT CDECL wined3d_get_adapter_identifier(const struct wined3d *wined3d, UINT adapter_idx, DWORD flags, struct wined3d_adapter_identifier *identifier)
Definition: directx.c:4939
HRESULT CDECL wined3d_enum_adapter_modes(const struct wined3d *wined3d, UINT adapter_idx, enum wined3d_format_id format_id, enum wined3d_scanline_ordering scanline_ordering, UINT mode_idx, struct wined3d_display_mode *mode)
Definition: directx.c:4589
HRESULT CDECL wined3d_register_software_device(struct wined3d *wined3d, void *init_function)
Definition: directx.c:4492
HRESULT CDECL wined3d_get_adapter_display_mode(const struct wined3d *wined3d, UINT adapter_idx, struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation)
Definition: directx.c:4767
HRESULT CDECL wined3d_check_depth_stencil_match(const struct wined3d *wined3d, UINT adapter_idx, enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id, enum wined3d_format_id render_target_format_id, enum wined3d_format_id depth_stencil_format_id)
Definition: directx.c:5091
HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapter_idx, enum wined3d_device_type device_type, WINED3DCAPS *caps)
Definition: directx.c:5659
HRESULT CDECL wined3d_check_device_multisample_type(const struct wined3d *wined3d, UINT adapter_idx, enum wined3d_device_type device_type, enum wined3d_format_id surface_format_id, BOOL windowed, enum wined3d_multisample_type multisample_type, DWORD *quality_levels)
Definition: directx.c:5145
#define WINED3DUSAGE_QUERY_MASK
Definition: wined3d.h:931
wined3d_multisample_type
Definition: wined3d.h:553
#define WINED3D_LIMIT_VIEWPORT
Definition: wined3d.h:1330
#define WINED3DUSAGE_LEGACY_CUBEMAP
Definition: wined3d.h:917
#define WINED3D_VIDMEM_ACCOUNTING
Definition: wined3d.h:1317
#define WINED3D_LEGACY_UNBOUND_RESOURCE_COLOR
Definition: wined3d.h:1325
wined3d_resource_type
Definition: wined3d.h:696
@ WINED3D_RTYPE_TEXTURE_2D
Definition: wined3d.h:700
@ WINED3D_RTYPE_BUFFER
Definition: wined3d.h:698
@ WINED3D_RTYPE_TEXTURE_3D
Definition: wined3d.h:701
#define WINED3D_HANDLE_RESTORE
Definition: wined3d.h:1321
#define WINED3D_NO_PRIMITIVE_RESTART
Definition: wined3d.h:1326
#define WINED3DERR_NOTAVAILABLE
Definition: wined3d.h:46
#define WINED3DUSAGE_MASK
Definition: wined3d.h:913
@ WINED3DFMT_UNKNOWN
Definition: wined3d.h:107
@ WINED3D_SCANLINE_ORDERING_UNKNOWN
Definition: wined3d.h:832
#define WINED3D_LEGACY_DEPTH_BIAS
Definition: wined3d.h:1315
#define WINED3DERR_INVALIDCALL
Definition: wined3d.h:48
#define WINED3D_PIXEL_CENTER_INTEGER
Definition: wined3d.h:1322
#define WINED3DUSAGE_TEXTURE
Definition: wined3d.h:918
#define WINED3D_LEGACY_CUBEMAP_FILTERING
Definition: wined3d.h:1327
void WINAPI wined3d_mutex_unlock(void)
Definition: wined3d_main.c:373
struct wined3d *CDECL wined3d_create(DWORD flags)
Definition: wined3d_main.c:97
void WINAPI wined3d_mutex_lock(void)
Definition: wined3d_main.c:368
#define E_NOINTERFACE
Definition: winerror.h:2364