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 = "d3d8_test_wc";
29 return CreateWindow("d3d8_test_wc", "d3d8_test",
30 0, 0, 0, 0, 0, 0, 0, 0, 0);
33 static IDirect3DDevice8 *init_d3d8(HMODULE d3d8_handle)
35 IDirect3D8 * (__stdcall * d3d8_create)(UINT SDKVersion) = 0;
36 IDirect3D8 *d3d8_ptr = 0;
37 IDirect3DDevice8 *device_ptr = 0;
38 D3DPRESENT_PARAMETERS present_parameters;
42 d3d8_create = (void *)GetProcAddress(d3d8_handle, "Direct3DCreate8");
43 ok(d3d8_create != NULL, "Failed to get address of Direct3DCreate8\n");
44 if (!d3d8_create) return NULL;
46 d3d8_ptr = d3d8_create(D3D_SDK_VERSION);
47 ok(d3d8_ptr != NULL, "Failed to create IDirect3D8 object\n");
48 if (!d3d8_ptr) return NULL;
50 IDirect3D8_GetAdapterDisplayMode(d3d8_ptr, D3DADAPTER_DEFAULT, &d3ddm );
51 ZeroMemory(&present_parameters, sizeof(present_parameters));
52 present_parameters.Windowed = TRUE;
53 present_parameters.hDeviceWindow = create_window();
54 present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
55 present_parameters.BackBufferFormat = d3ddm.Format;
57 hr = IDirect3D8_CreateDevice(d3d8_ptr, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
58 NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device_ptr);
62 skip("could not create device, IDirect3D8_CreateDevice returned %#x\n", hr);
69 static void test_volume_get_container(IDirect3DDevice8 *device_ptr)
71 IDirect3DVolumeTexture8 *texture_ptr = 0;
72 IDirect3DVolume8 *volume_ptr = 0;
76 hr = IDirect3DDevice8_CreateVolumeTexture(device_ptr, 128, 128, 128, 1, 0,
77 D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &texture_ptr);
78 ok(SUCCEEDED(hr) && texture_ptr != NULL, "CreateVolumeTexture returned: hr %#x, texture_ptr %p. "
79 "Expected hr %#x, texture_ptr != %p\n", hr, texture_ptr, D3D_OK, NULL);
80 if (!texture_ptr || FAILED(hr)) goto cleanup;
82 hr = IDirect3DVolumeTexture8_GetVolumeLevel(texture_ptr, 0, &volume_ptr);
83 ok(SUCCEEDED(hr) && volume_ptr != NULL, "GetVolumeLevel returned: hr %#x, volume_ptr %p. "
84 "Expected hr %#x, volume_ptr != %p\n", hr, volume_ptr, D3D_OK, NULL);
85 if (!volume_ptr || FAILED(hr)) goto cleanup;
87 /* These should work... */
88 container_ptr = (void *)0x1337c0d3;
89 hr = IDirect3DVolume8_GetContainer(volume_ptr, &IID_IUnknown, &container_ptr);
90 ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#x, container_ptr %p. "
91 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr);
92 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
94 container_ptr = (void *)0x1337c0d3;
95 hr = IDirect3DVolume8_GetContainer(volume_ptr, &IID_IDirect3DResource8, &container_ptr);
96 ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#x, container_ptr %p. "
97 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr);
98 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
100 container_ptr = (void *)0x1337c0d3;
101 hr = IDirect3DVolume8_GetContainer(volume_ptr, &IID_IDirect3DBaseTexture8, &container_ptr);
102 ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#x, container_ptr %p. "
103 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr);
104 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
106 container_ptr = (void *)0x1337c0d3;
107 hr = IDirect3DVolume8_GetContainer(volume_ptr, &IID_IDirect3DVolumeTexture8, &container_ptr);
108 ok(SUCCEEDED(hr) && container_ptr == texture_ptr, "GetContainer returned: hr %#x, container_ptr %p. "
109 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, S_OK, texture_ptr);
110 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
112 /* ...and this one shouldn't. This should return E_NOINTERFACE and set container_ptr to NULL */
113 container_ptr = (void *)0x1337c0d3;
114 hr = IDirect3DVolume8_GetContainer(volume_ptr, &IID_IDirect3DVolume8, &container_ptr);
115 ok(hr == E_NOINTERFACE && container_ptr == NULL, "GetContainer returned: hr %#x, container_ptr %p. "
116 "Expected hr %#x, container_ptr %p\n", hr, container_ptr, E_NOINTERFACE, NULL);
117 if (container_ptr && container_ptr != (void *)0x1337c0d3) IUnknown_Release((IUnknown *)container_ptr);
120 if (texture_ptr) IDirect3DVolumeTexture8_Release(texture_ptr);
121 if (volume_ptr) IDirect3DVolume8_Release(volume_ptr);
127 IDirect3DDevice8 *device_ptr;
130 d3d8_handle = LoadLibraryA("d3d8.dll");
133 skip("Could not load d3d8.dll\n");
137 device_ptr = init_d3d8(d3d8_handle);
138 if (!device_ptr) return;
140 IDirect3DDevice8_GetDeviceCaps(device_ptr, &caps);
141 if(!(caps.TextureCaps & D3DPTEXTURECAPS_VOLUMEMAP)) {
142 skip("Volume textures not supported\n");
146 test_volume_get_container(device_ptr);