advapi32: Make rpcrt4 a delayed import to work around circular dependencies with...
[wine/testsucceed.git] / dlls / d3d10core / tests / device.c
blob7ad8bb695b430d05faebc690af38bf923c7f9b54
1 /*
2 * Copyright 2008 Henri Verbeet 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 #define COBJMACROS
20 #include "initguid.h"
21 #include "d3d10.h"
22 #include "wine/test.h"
24 HRESULT WINAPI D3D10CoreCreateDevice(IDXGIFactory *factory, IDXGIAdapter *adapter,
25 UINT flags, void *unknown0, ID3D10Device **device);
27 static ID3D10Device *create_device(void)
29 IDXGIFactory *factory = NULL;
30 IDXGIAdapter *adapter = NULL;
31 ID3D10Device *device = NULL;
32 HRESULT hr;
34 hr = CreateDXGIFactory(&IID_IDXGIFactory, (void *)&factory);
35 if (FAILED(hr)) goto cleanup;
37 hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
38 ok(SUCCEEDED(hr) ||
39 hr == DXGI_ERROR_NOT_FOUND, /* Some VMware and VirtualBox */
40 "EnumAdapters failed, hr %#x\n", hr);
41 if (FAILED(hr)) goto cleanup;
43 hr = D3D10CoreCreateDevice(factory, adapter, 0, NULL, &device);
44 if (FAILED(hr))
46 HMODULE d3d10ref;
48 trace("Failed to create a HW device, trying REF\n");
49 IDXGIAdapter_Release(adapter);
50 adapter = NULL;
52 d3d10ref = LoadLibraryA("d3d10ref.dll");
53 if (!d3d10ref)
55 trace("d3d10ref.dll not available, unable to create a REF device\n");
56 goto cleanup;
59 hr = IDXGIFactory_CreateSoftwareAdapter(factory, d3d10ref, &adapter);
60 FreeLibrary(d3d10ref);
61 ok(SUCCEEDED(hr), "CreateSoftwareAdapter failed, hr %#x\n", hr);
62 if (FAILED(hr)) goto cleanup;
64 hr = D3D10CoreCreateDevice(factory, adapter, 0, NULL, &device);
65 ok(SUCCEEDED(hr), "Failed to create a REF device, hr %#x\n", hr);
66 if (FAILED(hr)) goto cleanup;
69 cleanup:
70 if (adapter) IDXGIAdapter_Release(adapter);
71 if (factory) IDXGIFactory_Release(factory);
73 return device;
76 static void test_device_interfaces(ID3D10Device *device)
78 IUnknown *obj;
79 HRESULT hr;
81 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_IUnknown, (void **)&obj)))
82 IUnknown_Release(obj);
83 ok(SUCCEEDED(hr), "ID3D10Device does not implement IUnknown\n");
85 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_IDXGIObject, (void **)&obj)))
86 IUnknown_Release(obj);
87 ok(SUCCEEDED(hr), "ID3D10Device does not implement IDXGIObject\n");
89 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&obj)))
90 IUnknown_Release(obj);
91 ok(SUCCEEDED(hr), "ID3D10Device does not implement IDXGIDevice\n");
93 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_ID3D10Device, (void **)&obj)))
94 IUnknown_Release(obj);
95 ok(SUCCEEDED(hr), "ID3D10Device does not implement ID3D10Device\n");
98 static void test_create_texture(ID3D10Device *device)
100 D3D10_TEXTURE2D_DESC desc;
101 ID3D10Texture2D *texture;
102 IDXGISurface *surface;
103 HRESULT hr;
105 desc.Width = 512;
106 desc.Height = 512;
107 desc.MipLevels = 1;
108 desc.ArraySize = 1;
109 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
110 desc.SampleDesc.Count = 1;
111 desc.SampleDesc.Quality = 0;
112 desc.Usage = D3D10_USAGE_DEFAULT;
113 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
114 desc.CPUAccessFlags = 0;
115 desc.MiscFlags = 0;
117 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
118 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
120 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
121 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface\n");
122 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
123 ID3D10Texture2D_Release(texture);
125 desc.MipLevels = 0;
126 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
127 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
129 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
130 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
131 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
132 ID3D10Texture2D_Release(texture);
134 desc.MipLevels = 1;
135 desc.ArraySize = 2;
136 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
137 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
139 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
140 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
141 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
142 ID3D10Texture2D_Release(texture);
145 static void test_create_rendertarget_view(ID3D10Device *device)
147 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
148 D3D10_TEXTURE2D_DESC texture_desc;
149 D3D10_BUFFER_DESC buffer_desc;
150 ID3D10RenderTargetView *rtview;
151 ID3D10Texture2D *texture;
152 ID3D10Buffer *buffer;
153 HRESULT hr;
155 buffer_desc.ByteWidth = 1024;
156 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
157 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
158 buffer_desc.CPUAccessFlags = 0;
159 buffer_desc.MiscFlags = 0;
161 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
162 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr);
164 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
165 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
166 U(rtv_desc).Buffer.ElementOffset = 0;
167 U(rtv_desc).Buffer.ElementWidth = 64;
169 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
170 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
172 ID3D10RenderTargetView_Release(rtview);
173 ID3D10Buffer_Release(buffer);
175 texture_desc.Width = 512;
176 texture_desc.Height = 512;
177 texture_desc.MipLevels = 1;
178 texture_desc.ArraySize = 1;
179 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
180 texture_desc.SampleDesc.Count = 1;
181 texture_desc.SampleDesc.Quality = 0;
182 texture_desc.Usage = D3D10_USAGE_DEFAULT;
183 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
184 texture_desc.CPUAccessFlags = 0;
185 texture_desc.MiscFlags = 0;
187 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
188 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
190 /* For texture resources it's allowed to specify NULL as desc */
191 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtview);
192 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
194 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
195 ok(rtv_desc.Format == texture_desc.Format, "Expected format %#x, got %#x\n", texture_desc.Format, rtv_desc.Format);
196 ok(rtv_desc.ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D,
197 "Expected view dimension D3D10_RTV_DIMENSION_TEXTURE2D, got %#x\n", rtv_desc.ViewDimension);
198 ok(U(rtv_desc).Texture2D.MipSlice == 0, "Expected mip slice 0, got %#x\n", U(rtv_desc).Texture2D.MipSlice);
200 ID3D10RenderTargetView_Release(rtview);
201 ID3D10Texture2D_Release(texture);
204 START_TEST(device)
206 ID3D10Device *device;
207 ULONG refcount;
209 device = create_device();
210 if (!device)
212 skip("Failed to create device, skipping tests\n");
213 return;
216 test_device_interfaces(device);
217 test_create_texture(device);
218 test_create_rendertarget_view(device);
220 refcount = ID3D10Device_Release(device);
221 ok(!refcount, "Device has %u references left\n", refcount);