2 * Copyright (c) 2002 Lionel ULMER
4 * This file contains the implementation of Direct3DMaterial.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/debug.h"
29 #include "d3d_private.h"
30 #include "mesa_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
34 static void dump_material(LPD3DMATERIAL mat)
36 DPRINTF(" dwSize : %ld\n", mat->dwSize);
40 Main_IDirect3DMaterialImpl_3_2T_1T_QueryInterface(LPDIRECT3DMATERIAL3 iface,
44 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
45 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obp);
49 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
50 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
52 TRACE(" Creating IUnknown interface at %p.\n", *obp);
55 if ( IsEqualGUID( &IID_IDirect3DMaterial, riid ) ) {
56 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
57 *obp = ICOM_INTERFACE(This, IDirect3DMaterial);
58 TRACE(" Creating IDirect3DMaterial interface %p\n", *obp);
61 if ( IsEqualGUID( &IID_IDirect3DMaterial2, riid ) ) {
62 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
63 *obp = ICOM_INTERFACE(This, IDirect3DMaterial2);
64 TRACE(" Creating IDirect3DMaterial2 interface %p\n", *obp);
67 if ( IsEqualGUID( &IID_IDirect3DMaterial3, riid ) ) {
68 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
69 *obp = ICOM_INTERFACE(This, IDirect3DMaterial3);
70 TRACE(" Creating IDirect3DMaterial3 interface %p\n", *obp);
73 FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
74 return OLE_E_ENUM_NOMORE;
78 Main_IDirect3DMaterialImpl_3_2T_1T_AddRef(LPDIRECT3DMATERIAL3 iface)
80 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
81 TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
86 Main_IDirect3DMaterialImpl_3_2T_1T_Release(LPDIRECT3DMATERIAL3 iface)
88 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
89 TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
91 HeapFree(GetProcessHeap(), 0, This);
98 Main_IDirect3DMaterialImpl_1_Initialize(LPDIRECT3DMATERIAL iface,
99 LPDIRECT3D lpDirect3D)
101 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
102 TRACE("(%p/%p)->(%p) no-op...!\n", This, iface, lpDirect3D);
107 Main_IDirect3DMaterialImpl_1_Reserve(LPDIRECT3DMATERIAL iface)
109 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
110 TRACE("(%p/%p)->() not implemented.\n", This, iface);
115 Main_IDirect3DMaterialImpl_1_Unreserve(LPDIRECT3DMATERIAL iface)
117 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
118 FIXME("(%p/%p)->() not implemented.\n", This, iface);
123 Main_IDirect3DMaterialImpl_3_2T_1T_SetMaterial(LPDIRECT3DMATERIAL3 iface,
126 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
127 TRACE("(%p/%p)->(%p)\n", This, iface, lpMat);
129 dump_material(lpMat);
131 /* Stores the material */
132 memset(&This->mat, 0, sizeof(This->mat));
133 memcpy(&This->mat, lpMat, lpMat->dwSize);
139 Main_IDirect3DMaterialImpl_3_2T_1T_GetMaterial(LPDIRECT3DMATERIAL3 iface,
142 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
144 TRACE("(%p/%p)->(%p)\n", This, iface, lpMat);
145 if (TRACE_ON(ddraw)) {
146 TRACE(" Returning material : ");
147 dump_material(&This->mat);
150 /* Copies the material structure */
151 dwSize = lpMat->dwSize;
152 memset(lpMat, 0, dwSize);
153 memcpy(lpMat, &This->mat, dwSize);
159 Main_IDirect3DMaterialImpl_3_2T_1T_GetHandle(LPDIRECT3DMATERIAL3 iface,
160 LPDIRECT3DDEVICE3 lpDirect3DDevice3,
161 LPD3DMATERIALHANDLE lpHandle)
163 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
164 TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpDirect3DDevice3, lpHandle);
166 This->active_device = ICOM_OBJECT(IDirect3DDeviceImpl, IDirect3DDevice3, lpDirect3DDevice3);
167 *lpHandle = (DWORD) This; /* Warning: this is not 64 bit clean.
168 Maybe also we need to store this material somewhere in the device ? */
170 TRACE(" returning handle %08lx.\n", *lpHandle);
176 Thunk_IDirect3DMaterialImpl_2_GetHandle(LPDIRECT3DMATERIAL2 iface,
177 LPDIRECT3DDEVICE2 lpDirect3DDevice2,
178 LPD3DMATERIALHANDLE lpHandle)
180 TRACE("(%p)->(%p,%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpDirect3DDevice2, lpHandle);
181 return IDirect3DMaterial3_GetHandle(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
182 COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, lpDirect3DDevice2),
187 Thunk_IDirect3DMaterialImpl_1_GetHandle(LPDIRECT3DMATERIAL iface,
188 LPDIRECT3DDEVICE lpDirect3DDevice,
189 LPD3DMATERIALHANDLE lpHandle)
191 TRACE("(%p)->(%p,%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpDirect3DDevice, lpHandle);
192 return IDirect3DMaterial3_GetHandle(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
193 COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice3, lpDirect3DDevice),
198 Thunk_IDirect3DMaterialImpl_2_QueryInterface(LPDIRECT3DMATERIAL2 iface,
202 TRACE("(%p)->(%s,%p) thunking to IDirect3DMaterial3 interface.\n", iface, debugstr_guid(riid), obp);
203 return IDirect3DMaterial3_QueryInterface(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
209 Thunk_IDirect3DMaterialImpl_1_QueryInterface(LPDIRECT3DMATERIAL iface,
213 TRACE("(%p)->(%s,%p) thunking to IDirect3DMaterial3 interface.\n", iface, debugstr_guid(riid), obp);
214 return IDirect3DMaterial3_QueryInterface(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
220 Thunk_IDirect3DMaterialImpl_2_AddRef(LPDIRECT3DMATERIAL2 iface)
222 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
223 return IDirect3DMaterial3_AddRef(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface));
227 Thunk_IDirect3DMaterialImpl_1_AddRef(LPDIRECT3DMATERIAL iface)
229 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
230 return IDirect3DMaterial3_AddRef(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface));
234 Thunk_IDirect3DMaterialImpl_2_Release(LPDIRECT3DMATERIAL2 iface)
236 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
237 return IDirect3DMaterial3_Release(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface));
241 Thunk_IDirect3DMaterialImpl_1_Release(LPDIRECT3DMATERIAL iface)
243 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
244 return IDirect3DMaterial3_Release(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface));
248 Thunk_IDirect3DMaterialImpl_2_SetMaterial(LPDIRECT3DMATERIAL2 iface,
251 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
252 return IDirect3DMaterial3_SetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
257 Thunk_IDirect3DMaterialImpl_1_SetMaterial(LPDIRECT3DMATERIAL iface,
260 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
261 return IDirect3DMaterial3_SetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
266 Thunk_IDirect3DMaterialImpl_2_GetMaterial(LPDIRECT3DMATERIAL2 iface,
269 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
270 return IDirect3DMaterial3_GetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
275 Thunk_IDirect3DMaterialImpl_1_GetMaterial(LPDIRECT3DMATERIAL iface,
278 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
279 return IDirect3DMaterial3_GetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
283 /*******************************************************************************
284 * Matrial2 static functions
286 static void activate(IDirect3DMaterialImpl* This) {
287 TRACE("Activating material %p\n", This);
291 /* Set the current Material */
292 _dump_colorvalue("Diffuse", This->mat.u.diffuse);
293 glMaterialfv(GL_FRONT_AND_BACK,
295 (float *) &(This->mat.u.diffuse));
296 _dump_colorvalue("Ambient", This->mat.u1.ambient);
297 glMaterialfv(GL_FRONT_AND_BACK,
299 (float *) &(This->mat.u1.ambient));
300 _dump_colorvalue("Specular", This->mat.u2.specular);
301 glMaterialfv(GL_FRONT_AND_BACK,
303 (float *) &(This->mat.u2.specular));
304 _dump_colorvalue("Emissive", This->mat.u3.emissive);
305 glMaterialfv(GL_FRONT_AND_BACK,
307 (float *) &(This->mat.u3.emissive));
309 TRACE("Size : %ld\n", This->mat.dwSize);
310 TRACE("Power : %f\n", This->mat.u4.power);
312 TRACE("Texture handle : %08lx\n", (DWORD)This->mat.hTexture);
318 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
319 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial3.fun))
321 # define XCAST(fun) (void*)
324 ICOM_VTABLE(IDirect3DMaterial3) VTABLE_IDirect3DMaterial3 =
326 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
327 XCAST(QueryInterface) Main_IDirect3DMaterialImpl_3_2T_1T_QueryInterface,
328 XCAST(AddRef) Main_IDirect3DMaterialImpl_3_2T_1T_AddRef,
329 XCAST(Release) Main_IDirect3DMaterialImpl_3_2T_1T_Release,
330 XCAST(SetMaterial) Main_IDirect3DMaterialImpl_3_2T_1T_SetMaterial,
331 XCAST(GetMaterial) Main_IDirect3DMaterialImpl_3_2T_1T_GetMaterial,
332 XCAST(GetHandle) Main_IDirect3DMaterialImpl_3_2T_1T_GetHandle,
335 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
340 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
341 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial2.fun))
343 # define XCAST(fun) (void*)
346 ICOM_VTABLE(IDirect3DMaterial2) VTABLE_IDirect3DMaterial2 =
348 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
349 XCAST(QueryInterface) Thunk_IDirect3DMaterialImpl_2_QueryInterface,
350 XCAST(AddRef) Thunk_IDirect3DMaterialImpl_2_AddRef,
351 XCAST(Release) Thunk_IDirect3DMaterialImpl_2_Release,
352 XCAST(SetMaterial) Thunk_IDirect3DMaterialImpl_2_SetMaterial,
353 XCAST(GetMaterial) Thunk_IDirect3DMaterialImpl_2_GetMaterial,
354 XCAST(GetHandle) Thunk_IDirect3DMaterialImpl_2_GetHandle,
357 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
362 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
363 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial.fun))
365 # define XCAST(fun) (void*)
368 ICOM_VTABLE(IDirect3DMaterial) VTABLE_IDirect3DMaterial =
370 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
371 XCAST(QueryInterface) Thunk_IDirect3DMaterialImpl_1_QueryInterface,
372 XCAST(AddRef) Thunk_IDirect3DMaterialImpl_1_AddRef,
373 XCAST(Release) Thunk_IDirect3DMaterialImpl_1_Release,
374 XCAST(Initialize) Main_IDirect3DMaterialImpl_1_Initialize,
375 XCAST(SetMaterial) Thunk_IDirect3DMaterialImpl_1_SetMaterial,
376 XCAST(GetMaterial) Thunk_IDirect3DMaterialImpl_1_GetMaterial,
377 XCAST(GetHandle) Thunk_IDirect3DMaterialImpl_1_GetHandle,
378 XCAST(Reserve) Main_IDirect3DMaterialImpl_1_Reserve,
379 XCAST(Unreserve) Main_IDirect3DMaterialImpl_1_Unreserve,
382 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
389 HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirect3DImpl *d3d)
391 IDirect3DMaterialImpl *object;
393 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DMaterialImpl));
394 if (object == NULL) return DDERR_OUTOFMEMORY;
398 object->activate = activate;
400 ICOM_INIT_INTERFACE(object, IDirect3DMaterial, VTABLE_IDirect3DMaterial);
401 ICOM_INIT_INTERFACE(object, IDirect3DMaterial2, VTABLE_IDirect3DMaterial2);
402 ICOM_INIT_INTERFACE(object, IDirect3DMaterial3, VTABLE_IDirect3DMaterial3);
406 TRACE(" creating implementation at %p.\n", *obj);