user32/tests: Skip tests if functions are not implemented.
[wine.git] / dlls / ddraw / material.c
blobd6b9a7c165e271dafb736811e9deba872fa8b0fe
1 /* Direct3D Material
2 * Copyright (c) 2002 Lionel ULMER
3 * Copyright (c) 2006 Stefan DÖSINGER
5 * This file contains the implementation of Direct3DMaterial.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <stdlib.h>
30 #define COBJMACROS
31 #define NONAMELESSUNION
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winerror.h"
36 #include "wingdi.h"
37 #include "wine/exception.h"
39 #include "ddraw.h"
40 #include "d3d.h"
42 #include "ddraw_private.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
46 WINE_DECLARE_DEBUG_CHANNEL(ddraw_thunk);
48 static void dump_material(const D3DMATERIAL *mat)
50 TRACE(" dwSize : %d\n", mat->dwSize);
53 /*****************************************************************************
54 * IUnknown Methods.
55 *****************************************************************************/
57 /*****************************************************************************
58 * IDirect3DMaterial3::QueryInterface
60 * QueryInterface for IDirect3DMaterial. Can query all IDirect3DMaterial
61 * versions.
63 * Params:
64 * riid: Interface id queried for
65 * obj: Address to pass the interface pointer back
67 * Returns:
68 * S_OK on success
69 * E_NOINTERFACE if the requested interface wasn't found
71 *****************************************************************************/
72 static HRESULT WINAPI
73 IDirect3DMaterialImpl_QueryInterface(IDirect3DMaterial3 *iface,
74 REFIID riid,
75 LPVOID* obp)
77 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
78 TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid), obp);
80 *obp = NULL;
82 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
83 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
84 *obp = iface;
85 TRACE(" Creating IUnknown interface at %p.\n", *obp);
86 return S_OK;
88 if ( IsEqualGUID( &IID_IDirect3DMaterial, riid ) ) {
89 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
90 *obp = ICOM_INTERFACE(This, IDirect3DMaterial);
91 TRACE(" Creating IDirect3DMaterial interface %p\n", *obp);
92 return S_OK;
94 if ( IsEqualGUID( &IID_IDirect3DMaterial2, riid ) ) {
95 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
96 *obp = ICOM_INTERFACE(This, IDirect3DMaterial2);
97 TRACE(" Creating IDirect3DMaterial2 interface %p\n", *obp);
98 return S_OK;
100 if ( IsEqualGUID( &IID_IDirect3DMaterial3, riid ) ) {
101 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
102 *obp = ICOM_INTERFACE(This, IDirect3DMaterial3);
103 TRACE(" Creating IDirect3DMaterial3 interface %p\n", *obp);
104 return S_OK;
106 FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
107 return E_NOINTERFACE;
110 /*****************************************************************************
111 * IDirect3DMaterial3::AddRef
113 * Increases the refcount.
115 * Returns:
116 * The new refcount
118 *****************************************************************************/
119 static ULONG WINAPI
120 IDirect3DMaterialImpl_AddRef(IDirect3DMaterial3 *iface)
122 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
123 ULONG ref = InterlockedIncrement(&This->ref);
125 TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
127 return ref;
130 /*****************************************************************************
131 * IDirect3DMaterial3::Release
133 * Reduces the refcount by one. If the refcount falls to 0, the object
134 * is destroyed
136 * Returns:
137 * The new refcount
139 *****************************************************************************/
140 static ULONG WINAPI
141 IDirect3DMaterialImpl_Release(IDirect3DMaterial3 *iface)
143 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
144 ULONG ref = InterlockedDecrement(&This->ref);
146 TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
148 if (!ref)
150 if(This->Handle)
152 EnterCriticalSection(&ddraw_cs);
153 This->ddraw->d3ddevice->Handles[This->Handle - 1].ptr = NULL;
154 This->ddraw->d3ddevice->Handles[This->Handle - 1].type = DDrawHandle_Unknown;
155 LeaveCriticalSection(&ddraw_cs);
158 HeapFree(GetProcessHeap(), 0, This);
159 return 0;
161 return ref;
164 /*****************************************************************************
165 * IDirect3DMaterial Methods
166 *****************************************************************************/
168 /*****************************************************************************
169 * IDirect3DMaterial::Initialize
171 * A no-op initialization
173 * Params:
174 * Direct3D: Pointer to a Direct3D interface
176 * Returns:
177 * D3D_OK
179 *****************************************************************************/
180 static HRESULT WINAPI
181 IDirect3DMaterialImpl_Initialize(IDirect3DMaterial *iface,
182 IDirect3D *Direct3D)
184 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
186 TRACE("(%p)->(%p) no-op...!\n", This, Direct3D);
188 return D3D_OK;
191 /*****************************************************************************
192 * IDirect3DMaterial::Reserve
194 * DirectX 5 sdk: "The IDirect3DMaterial2::Reserve method is not implemented"
195 * Odd. They seem to have mixed their interfaces.
197 * Returns:
198 * DDERR_UNSUPPORTED
200 *****************************************************************************/
201 static HRESULT WINAPI
202 IDirect3DMaterialImpl_Reserve(IDirect3DMaterial *iface)
204 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
205 TRACE("(%p)->() not implemented\n", This);
207 return DDERR_UNSUPPORTED;
210 /*****************************************************************************
211 * IDirect3DMaterial::Unreserve
213 * Not supported too
215 * Returns:
216 * DDERR_UNSUPPORTED
218 *****************************************************************************/
219 static HRESULT WINAPI
220 IDirect3DMaterialImpl_Unreserve(IDirect3DMaterial *iface)
222 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
223 TRACE("(%p)->() not implemented.\n", This);
225 return DDERR_UNSUPPORTED;
228 /*****************************************************************************
229 * IDirect3DMaterial3::SetMaterial
231 * Sets the material description
233 * Params:
234 * Mat: Material to set
236 * Returns:
237 * D3D_OK on success
238 * DDERR_INVALIDPARAMS if Mat is NULL
240 *****************************************************************************/
241 static HRESULT WINAPI
242 IDirect3DMaterialImpl_SetMaterial(IDirect3DMaterial3 *iface,
243 D3DMATERIAL *lpMat)
245 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
246 TRACE("(%p)->(%p)\n", This, lpMat);
247 if (TRACE_ON(d3d7))
248 dump_material(lpMat);
250 /* Stores the material */
251 EnterCriticalSection(&ddraw_cs);
252 memset(&This->mat, 0, sizeof(This->mat));
253 memcpy(&This->mat, lpMat, lpMat->dwSize);
254 LeaveCriticalSection(&ddraw_cs);
256 return DD_OK;
259 /*****************************************************************************
260 * IDirect3DMaterial3::GetMaterial
262 * Returns the material assigned to this interface
264 * Params:
265 * Mat: Pointer to a D3DMATERIAL structure to store the material description
267 * Returns:
268 * D3D_OK on success
269 * DDERR_INVALIDPARAMS if Mat is NULL
271 *****************************************************************************/
272 static HRESULT WINAPI
273 IDirect3DMaterialImpl_GetMaterial(IDirect3DMaterial3 *iface,
274 D3DMATERIAL *lpMat)
276 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
277 DWORD dwSize;
278 TRACE("(%p)->(%p)\n", This, lpMat);
279 if (TRACE_ON(d3d7)) {
280 TRACE(" Returning material : ");
281 dump_material(&This->mat);
284 /* Copies the material structure */
285 EnterCriticalSection(&ddraw_cs);
286 dwSize = lpMat->dwSize;
287 memset(lpMat, 0, dwSize);
288 memcpy(lpMat, &This->mat, dwSize);
289 LeaveCriticalSection(&ddraw_cs);
291 return DD_OK;
294 /*****************************************************************************
295 * IDirect3DMaterial3::GetHandle
297 * Returns a handle for the material interface. The handle is simply a
298 * pointer to the material implementation
300 * Params:
301 * Direct3DDevice3: The device this handle is assigned to
302 * Handle: Address to write the handle to
304 * Returns:
305 * D3D_OK on success
306 * DDERR_INVALIDPARAMS if Handle is NULL
308 *****************************************************************************/
309 static HRESULT WINAPI
310 IDirect3DMaterialImpl_GetHandle(IDirect3DMaterial3 *iface,
311 IDirect3DDevice3 *lpDirect3DDevice3,
312 D3DMATERIALHANDLE *lpHandle)
314 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
315 IDirect3DDeviceImpl *device = ICOM_OBJECT(IDirect3DDeviceImpl, IDirect3DDevice3, lpDirect3DDevice3);
316 TRACE("(%p/%p)->(%p,%p)\n", This, iface, device, lpHandle);
318 EnterCriticalSection(&ddraw_cs);
319 This->active_device = device;
320 if(!This->Handle)
322 This->Handle = IDirect3DDeviceImpl_CreateHandle(device);
323 if(!This->Handle)
325 ERR("Error creating a handle\n");
326 LeaveCriticalSection(&ddraw_cs);
327 return DDERR_INVALIDPARAMS; /* Unchecked */
329 device->Handles[This->Handle - 1].ptr = This;
330 device->Handles[This->Handle - 1].type = DDrawHandle_Material;
332 *lpHandle = This->Handle;
333 TRACE(" returning handle %08x.\n", *lpHandle);
334 LeaveCriticalSection(&ddraw_cs);
336 return D3D_OK;
339 static HRESULT WINAPI
340 Thunk_IDirect3DMaterialImpl_2_GetHandle(LPDIRECT3DMATERIAL2 iface,
341 LPDIRECT3DDEVICE2 lpDirect3DDevice2,
342 LPD3DMATERIALHANDLE lpHandle)
344 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpDirect3DDevice2, lpHandle);
345 return IDirect3DMaterial3_GetHandle(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
346 COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, lpDirect3DDevice2),
347 lpHandle);
350 static HRESULT WINAPI
351 Thunk_IDirect3DMaterialImpl_1_GetHandle(LPDIRECT3DMATERIAL iface,
352 LPDIRECT3DDEVICE lpDirect3DDevice,
353 LPD3DMATERIALHANDLE lpHandle)
355 TRACE_(ddraw_thunk)("(%p)->(%p,%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpDirect3DDevice, lpHandle);
356 return IDirect3DMaterial3_GetHandle(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
357 COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice3, lpDirect3DDevice),
358 lpHandle);
361 static HRESULT WINAPI
362 Thunk_IDirect3DMaterialImpl_2_QueryInterface(LPDIRECT3DMATERIAL2 iface,
363 REFIID riid,
364 LPVOID* obp)
366 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DMaterial3 interface.\n", iface, debugstr_guid(riid), obp);
367 return IDirect3DMaterial3_QueryInterface(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
368 riid,
369 obp);
372 static HRESULT WINAPI
373 Thunk_IDirect3DMaterialImpl_1_QueryInterface(LPDIRECT3DMATERIAL iface,
374 REFIID riid,
375 LPVOID* obp)
377 TRACE_(ddraw_thunk)("(%p)->(%s,%p) thunking to IDirect3DMaterial3 interface.\n", iface, debugstr_guid(riid), obp);
378 return IDirect3DMaterial3_QueryInterface(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
379 riid,
380 obp);
383 static ULONG WINAPI
384 Thunk_IDirect3DMaterialImpl_2_AddRef(LPDIRECT3DMATERIAL2 iface)
386 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
387 return IDirect3DMaterial3_AddRef(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface));
390 static ULONG WINAPI
391 Thunk_IDirect3DMaterialImpl_1_AddRef(LPDIRECT3DMATERIAL iface)
393 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
394 return IDirect3DMaterial3_AddRef(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface));
397 static ULONG WINAPI
398 Thunk_IDirect3DMaterialImpl_2_Release(LPDIRECT3DMATERIAL2 iface)
400 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
401 return IDirect3DMaterial3_Release(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface));
404 static ULONG WINAPI
405 Thunk_IDirect3DMaterialImpl_1_Release(LPDIRECT3DMATERIAL iface)
407 TRACE_(ddraw_thunk)("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
408 return IDirect3DMaterial3_Release(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface));
411 static HRESULT WINAPI
412 Thunk_IDirect3DMaterialImpl_2_SetMaterial(LPDIRECT3DMATERIAL2 iface,
413 LPD3DMATERIAL lpMat)
415 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
416 return IDirect3DMaterial3_SetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
417 lpMat);
420 static HRESULT WINAPI
421 Thunk_IDirect3DMaterialImpl_1_SetMaterial(LPDIRECT3DMATERIAL iface,
422 LPD3DMATERIAL lpMat)
424 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
425 return IDirect3DMaterial3_SetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
426 lpMat);
429 static HRESULT WINAPI
430 Thunk_IDirect3DMaterialImpl_2_GetMaterial(LPDIRECT3DMATERIAL2 iface,
431 LPD3DMATERIAL lpMat)
433 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
434 return IDirect3DMaterial3_GetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
435 lpMat);
438 static HRESULT WINAPI
439 Thunk_IDirect3DMaterialImpl_1_GetMaterial(LPDIRECT3DMATERIAL iface,
440 LPD3DMATERIAL lpMat)
442 TRACE_(ddraw_thunk)("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
443 return IDirect3DMaterial3_GetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
444 lpMat);
448 /*****************************************************************************
449 * material_activate
451 * Uses IDirect3DDevice7::SetMaterial to activate the material
453 * Params:
454 * This: Pointer to the material implementation to activate
456 *****************************************************************************/
457 void material_activate(IDirect3DMaterialImpl* This)
459 D3DMATERIAL7 d3d7mat;
461 TRACE("Activating material %p\n", This);
462 d3d7mat.u.diffuse = This->mat.u.diffuse;
463 d3d7mat.u1.ambient = This->mat.u1.ambient;
464 d3d7mat.u2.specular = This->mat.u2.specular;
465 d3d7mat.u3.emissive = This->mat.u3.emissive;
466 d3d7mat.u4.power = This->mat.u4.power;
468 IDirect3DDevice7_SetMaterial(ICOM_INTERFACE(This->active_device, IDirect3DDevice7),
469 &d3d7mat);
472 const IDirect3DMaterial3Vtbl IDirect3DMaterial3_Vtbl =
474 /*** IUnknown Methods ***/
475 IDirect3DMaterialImpl_QueryInterface,
476 IDirect3DMaterialImpl_AddRef,
477 IDirect3DMaterialImpl_Release,
478 /*** IDirect3DMaterial3 Methods ***/
479 IDirect3DMaterialImpl_SetMaterial,
480 IDirect3DMaterialImpl_GetMaterial,
481 IDirect3DMaterialImpl_GetHandle,
484 const IDirect3DMaterial2Vtbl IDirect3DMaterial2_Vtbl =
486 /*** IUnknown Methods ***/
487 Thunk_IDirect3DMaterialImpl_2_QueryInterface,
488 Thunk_IDirect3DMaterialImpl_2_AddRef,
489 Thunk_IDirect3DMaterialImpl_2_Release,
490 /*** IDirect3DMaterial2 Methods ***/
491 Thunk_IDirect3DMaterialImpl_2_SetMaterial,
492 Thunk_IDirect3DMaterialImpl_2_GetMaterial,
493 Thunk_IDirect3DMaterialImpl_2_GetHandle,
496 const IDirect3DMaterialVtbl IDirect3DMaterial_Vtbl =
498 /*** IUnknown Methods ***/
499 Thunk_IDirect3DMaterialImpl_1_QueryInterface,
500 Thunk_IDirect3DMaterialImpl_1_AddRef,
501 Thunk_IDirect3DMaterialImpl_1_Release,
502 /*** IDirect3DMaterial1 Methods ***/
503 IDirect3DMaterialImpl_Initialize,
504 Thunk_IDirect3DMaterialImpl_1_SetMaterial,
505 Thunk_IDirect3DMaterialImpl_1_GetMaterial,
506 Thunk_IDirect3DMaterialImpl_1_GetHandle,
507 IDirect3DMaterialImpl_Reserve,
508 IDirect3DMaterialImpl_Unreserve