2 * Copyright (C) 2006 Henri Verbeet
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 "wine/test.h"
22 static HWND create_window(void)
25 wc.lpfnWndProc = &DefWindowProc;
26 wc.lpszClassName = "d3d9_test_wc";
29 return CreateWindow("d3d9_test_wc", "d3d9_test",
30 0, 0, 0, 0, 0, 0, 0, 0, 0);
33 static IDirect3DDevice9 *init_d3d9(HMODULE d3d9_handle)
35 IDirect3D9 * (__stdcall * d3d9_create)(UINT SDKVersion) = 0;
36 IDirect3D9 *d3d9_ptr = 0;
37 IDirect3DDevice9 *device_ptr = 0;
38 D3DPRESENT_PARAMETERS present_parameters;
41 d3d9_create = (void *)GetProcAddress(d3d9_handle, "Direct3DCreate9");
42 ok(d3d9_create != NULL, "Failed to get address of Direct3DCreate9\n");
43 if (!d3d9_create) return NULL;
45 d3d9_ptr = d3d9_create(D3D_SDK_VERSION);
46 ok(d3d9_ptr != NULL, "Failed to create IDirect3D9 object\n");
47 if (!d3d9_ptr) return NULL;
49 ZeroMemory(&present_parameters, sizeof(present_parameters));
50 present_parameters.Windowed = TRUE;
51 present_parameters.hDeviceWindow = create_window();
52 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
54 hr = IDirect3D9_CreateDevice(d3d9_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
55 NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
59 trace("could not create device, IDirect3D9_CreateDevice returned %#x\n", hr);
66 static void test_volume_get_container(IDirect3DDevice9 *device_ptr)
68 IDirect3DVolumeTexture9 *texture_ptr = 0;
69 IDirect3DVolume9 *volume_ptr = 0;
73 hr = IDirect3DDevice9_CreateVolumeTexture(device_ptr, 128, 128, 128, 1, 0,
74 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture_ptr, 0);
75 ok(SUCCEEDED(hr) && texture_ptr != NULL, "CreateVolumeTexture returned: hr %#x, texture_ptr %p. "
76 "Expected hr %#x, texture_ptr != %p\n", hr, texture_ptr, D3D_OK, NULL);
77 if (!texture_ptr || FAILED(hr)) goto cleanup;
79 hr = IDirect3DVolumeTexture9_GetVolumeLevel(texture_ptr, 0, &volume_ptr);
80 ok(SUCCEEDED(hr) && volume_ptr != NULL, "GetVolumeLevel returned: hr %#x, volume_ptr %p. "
81 "Expected hr %#x, volume_ptr != %p\n", hr, volume_ptr, D3D_OK, NULL);
82 if (!volume_ptr || FAILED(hr)) goto cleanup;
84 /* These should work... */
85 container_ptr = (void *)0x1337c0d3;
86 hr = IDirect3DVolume9_GetContainer(volume_ptr, &IID_IUnknown, &container_ptr);
87 ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#x, container_ptr %p. "
88 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr);
89 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
91 container_ptr = (void *)0x1337c0d3;
92 hr = IDirect3DVolume9_GetContainer(volume_ptr, &IID_IDirect3DResource9, &container_ptr);
93 ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#x, container_ptr %p. "
94 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr);
95 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
97 container_ptr = (void *)0x1337c0d3;
98 hr = IDirect3DVolume9_GetContainer(volume_ptr, &IID_IDirect3DBaseTexture9, &container_ptr);
99 ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#x, container_ptr %p. "
100 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr);
101 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
103 container_ptr = (void *)0x1337c0d3;
104 hr = IDirect3DVolume9_GetContainer(volume_ptr, &IID_IDirect3DVolumeTexture9, &container_ptr);
105 ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#x, container_ptr %p. "
106 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr);
107 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
109 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container_ptr to NULL */
110 container_ptr = (void *)0x1337c0d3;
111 hr = IDirect3DVolume9_GetContainer(volume_ptr, &IID_IDirect3DVolume9, &container_ptr);
112 ok(hr == E_NOINTERFACE && container_ptr == NULL, "GetContainer returned: hr %#x, container_ptr %p. "
113 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, E_NOINTERFACE, NULL);
114 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
117 if (texture_ptr) IDirect3DVolumeTexture9_Release(texture_ptr);
118 if (volume_ptr) IDirect3DVolume9_Release(volume_ptr);
124 IDirect3DDevice9 *device_ptr;
127 memset(&caps, 0, sizeof(caps));
128 d3d9_handle = LoadLibraryA("d3d9.dll");
131 skip("Could not load d3d9.dll\n");
135 device_ptr = init_d3d9(d3d9_handle);
136 if (!device_ptr) return;
137 IDirect3DDevice9_GetDeviceCaps(device_ptr, &caps);
139 if(!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)) {
140 skip("No volume texture support\n");
144 test_volume_get_container(device_ptr);