2 * Copyright (C) 2008 Stefan Dösinger(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
19 /* This file contains tests specific to IDirect3D9Ex and IDirect3DDevice9Ex, like
20 * how to obtain them. For testing rendering with extended functions use visual.c
26 #include "wine/test.h"
28 static HMODULE d3d9_handle
= 0;
30 static IDirect3D9
* (WINAPI
*pDirect3DCreate9
)(UINT SDKVersion
);
31 static HRESULT (WINAPI
*pDirect3DCreate9Ex
)(UINT SDKVersion
, IDirect3D9Ex
**d3d9ex
);
33 static HWND
create_window(void)
37 wc
.lpfnWndProc
= &DefWindowProc
;
38 wc
.lpszClassName
= "d3d9_test_wc";
41 ret
= CreateWindow("d3d9_test_wc", "d3d9_test",
42 WS_MAXIMIZE
| WS_VISIBLE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
46 static unsigned long getref(IUnknown
*obj
) {
48 return IUnknown_Release(obj
);
51 static void test_qi_base_to_ex(void)
53 IDirect3D9
*d3d9
= pDirect3DCreate9(D3D_SDK_VERSION
);
54 IDirect3D9Ex
*d3d9ex
= (void *) 0xdeadbeef;
55 IDirect3DDevice9
*device
;
56 IDirect3DDevice9Ex
*deviceEx
= (void *) 0xdeadbeef;
58 HWND window
= create_window();
59 D3DPRESENT_PARAMETERS present_parameters
;
61 hr
= IDirect3D9_QueryInterface(d3d9
, &IID_IDirect3D9Ex
, (void **) &d3d9ex
);
62 ok(hr
== E_NOINTERFACE
,
63 "IDirect3D9::QueryInterface for IID_IDirect3D9Ex returned %s, expected E_NOINTERFACE\n",
64 DXGetErrorString9(hr
));
65 ok(d3d9ex
== NULL
, "QueryInterface returned interface %p, expected NULL\n", d3d9ex
);
66 if(d3d9ex
) IDirect3D9Ex_Release(d3d9ex
);
68 memset(&present_parameters
, 0, sizeof(present_parameters
));
69 present_parameters
.Windowed
= TRUE
;
70 present_parameters
.hDeviceWindow
= window
;
71 present_parameters
.SwapEffect
= D3DSWAPEFFECT_COPY
;
72 present_parameters
.BackBufferWidth
= 640;
73 present_parameters
.BackBufferHeight
= 480;
74 present_parameters
.EnableAutoDepthStencil
= FALSE
;
75 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
76 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
78 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
82 hr
= IDirect3DDevice9_QueryInterface(device
, &IID_IDirect3DDevice9Ex
, (void **) &deviceEx
);
83 ok(hr
== E_NOINTERFACE
,
84 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %s, expected E_NOINTERFACE\n",
85 DXGetErrorString9(hr
));
86 ok(deviceEx
== NULL
, "QueryInterface returned interface %p, expected NULL\n", deviceEx
);
87 if(deviceEx
) IDirect3DDevice9Ex_Release(deviceEx
);
89 IDirect3DDevice9_Release(device
);
92 IDirect3D9_Release(d3d9
);
93 DestroyWindow(window
);
96 static void test_qi_ex_to_base(void)
98 IDirect3D9
*d3d9
= (void *) 0xdeadbeef;
100 IDirect3DDevice9
*device
;
101 IDirect3DDevice9Ex
*deviceEx
= (void *) 0xdeadbeef;
103 HWND window
= create_window();
104 D3DPRESENT_PARAMETERS present_parameters
;
107 hr
= pDirect3DCreate9Ex(D3D_SDK_VERSION
, &d3d9ex
);
108 ok(hr
== D3D_OK
|| hr
== D3DERR_NOTAVAILABLE
, "Direct3DCreate9Ex returned %s\n", DXGetErrorString9(hr
));
110 skip("Direct3D9Ex is not available\n");
114 hr
= IDirect3D9Ex_QueryInterface(d3d9ex
, &IID_IDirect3D9
, (void **) &d3d9
);
116 "IDirect3D9Ex::QueryInterface for IID_IDirect3D9 returned %s, expected D3D_OK\n",
117 DXGetErrorString9(hr
));
118 ok(d3d9
!= NULL
&& d3d9
!= (void *) 0xdeadbeef,
119 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", d3d9
);
120 ref
= getref((IUnknown
*) d3d9ex
);
121 ok(ref
== 2, "IDirect3D9Ex refcount is %ld, expected 2\n", ref
);
122 ref
= getref((IUnknown
*) d3d9
);
123 ok(ref
== 2, "IDirect3D9 refcount is %ld, expected 2\n", ref
);
125 memset(&present_parameters
, 0, sizeof(present_parameters
));
126 present_parameters
.Windowed
= TRUE
;
127 present_parameters
.hDeviceWindow
= window
;
128 present_parameters
.SwapEffect
= D3DSWAPEFFECT_COPY
;
129 present_parameters
.BackBufferWidth
= 640;
130 present_parameters
.BackBufferHeight
= 480;
131 present_parameters
.EnableAutoDepthStencil
= FALSE
;
132 present_parameters
.AutoDepthStencilFormat
= D3DFMT_D16
;
134 /* First, try to create a normal device with IDirect3D9Ex::CreateDevice and QI it for IDirect3DDevice9Ex */
135 hr
= IDirect3D9Ex_CreateDevice(d3d9ex
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
137 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
141 hr
= IDirect3DDevice9_QueryInterface(device
, &IID_IDirect3DDevice9Ex
, (void **) &deviceEx
);
143 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %s, expected D3D_OK\n",
144 DXGetErrorString9(hr
));
145 ok(deviceEx
!= NULL
&& deviceEx
!= (void *) 0xdeadbeef,
146 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx
);
147 ref
= getref((IUnknown
*) device
);
148 ok(ref
== 2, "IDirect3DDevice9 refcount is %ld, expected 2\n", ref
);
149 ref
= getref((IUnknown
*) deviceEx
);
150 ok(ref
== 2, "IDirect3DDevice9Ex refcount is %ld, expected 2\n", ref
);
151 if(deviceEx
) IDirect3DDevice9Ex_Release(deviceEx
);
152 IDirect3DDevice9_Release(device
);
154 /* Next, try to create a normal device with IDirect3D9::CreateDevice(non-ex) and QI it */
155 hr
= IDirect3D9_CreateDevice(d3d9
, D3DADAPTER_DEFAULT
, D3DDEVTYPE_HAL
, present_parameters
.hDeviceWindow
, D3DCREATE_SOFTWARE_VERTEXPROCESSING
, &present_parameters
, &device
);
157 skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n");
161 hr
= IDirect3DDevice9_QueryInterface(device
, &IID_IDirect3DDevice9Ex
, (void **) &deviceEx
);
163 "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %s, expected D3D_OK\n",
164 DXGetErrorString9(hr
));
165 ok(deviceEx
!= NULL
&& deviceEx
!= (void *) 0xdeadbeef,
166 "QueryInterface returned interface %p, expected != NULL && != 0xdeadbeef\n", deviceEx
);
167 ref
= getref((IUnknown
*) device
);
168 ok(ref
== 2, "IDirect3DDevice9 refcount is %ld, expected 2\n", ref
);
169 ref
= getref((IUnknown
*) deviceEx
);
170 ok(ref
== 2, "IDirect3DDevice9Ex refcount is %ld, expected 2\n", ref
);
171 if(deviceEx
) IDirect3DDevice9Ex_Release(deviceEx
);
172 IDirect3DDevice9_Release(device
);
174 IDirect3D9_Release(d3d9
);
177 DestroyWindow(window
);
182 d3d9_handle
= LoadLibraryA("d3d9.dll");
185 skip("Could not load d3d9.dll\n");
188 pDirect3DCreate9
= (void *)GetProcAddress(d3d9_handle
, "Direct3DCreate9");
189 ok(pDirect3DCreate9
!= NULL
, "Failed to get address of Direct3DCreate9\n");
190 if(!pDirect3DCreate9
) {
194 pDirect3DCreate9Ex
= (void *)GetProcAddress(d3d9_handle
, "Direct3DCreate9Ex");
195 if (!pDirect3DCreate9Ex
) {
196 skip("Failed to get address of Direct3DCreate9Ex\n");
200 test_qi_base_to_ex();
201 test_qi_ex_to_base();