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
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
34 #include "wine/debug.h"
36 #include "d3d_private.h"
37 #include "mesa_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
41 static void dump_material(LPD3DMATERIAL mat)
43 DPRINTF(" dwSize : %ld\n", mat->dwSize);
47 Main_IDirect3DMaterialImpl_3_2T_1T_QueryInterface(LPDIRECT3DMATERIAL3 iface,
51 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
52 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obp);
56 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
57 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
59 TRACE(" Creating IUnknown interface at %p.\n", *obp);
62 if ( IsEqualGUID( &IID_IDirect3DMaterial, riid ) ) {
63 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
64 *obp = ICOM_INTERFACE(This, IDirect3DMaterial);
65 TRACE(" Creating IDirect3DMaterial interface %p\n", *obp);
68 if ( IsEqualGUID( &IID_IDirect3DMaterial2, riid ) ) {
69 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
70 *obp = ICOM_INTERFACE(This, IDirect3DMaterial2);
71 TRACE(" Creating IDirect3DMaterial2 interface %p\n", *obp);
74 if ( IsEqualGUID( &IID_IDirect3DMaterial3, riid ) ) {
75 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
76 *obp = ICOM_INTERFACE(This, IDirect3DMaterial3);
77 TRACE(" Creating IDirect3DMaterial3 interface %p\n", *obp);
80 FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
81 return OLE_E_ENUM_NOMORE;
85 Main_IDirect3DMaterialImpl_3_2T_1T_AddRef(LPDIRECT3DMATERIAL3 iface)
87 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
88 TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
93 Main_IDirect3DMaterialImpl_3_2T_1T_Release(LPDIRECT3DMATERIAL3 iface)
95 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
96 TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
98 HeapFree(GetProcessHeap(), 0, This);
105 Main_IDirect3DMaterialImpl_1_Initialize(LPDIRECT3DMATERIAL iface,
106 LPDIRECT3D lpDirect3D)
108 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
109 TRACE("(%p/%p)->(%p) no-op...!\n", This, iface, lpDirect3D);
114 Main_IDirect3DMaterialImpl_1_Reserve(LPDIRECT3DMATERIAL iface)
116 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
117 TRACE("(%p/%p)->() not implemented.\n", This, iface);
122 Main_IDirect3DMaterialImpl_1_Unreserve(LPDIRECT3DMATERIAL iface)
124 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
125 FIXME("(%p/%p)->() not implemented.\n", This, iface);
130 Main_IDirect3DMaterialImpl_3_2T_1T_SetMaterial(LPDIRECT3DMATERIAL3 iface,
133 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
134 TRACE("(%p/%p)->(%p)\n", This, iface, lpMat);
136 dump_material(lpMat);
138 /* Stores the material */
139 memset(&This->mat, 0, sizeof(This->mat));
140 memcpy(&This->mat, lpMat, lpMat->dwSize);
146 Main_IDirect3DMaterialImpl_3_2T_1T_GetMaterial(LPDIRECT3DMATERIAL3 iface,
149 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
151 TRACE("(%p/%p)->(%p)\n", This, iface, lpMat);
152 if (TRACE_ON(ddraw)) {
153 TRACE(" Returning material : ");
154 dump_material(&This->mat);
157 /* Copies the material structure */
158 dwSize = lpMat->dwSize;
159 memset(lpMat, 0, dwSize);
160 memcpy(lpMat, &This->mat, dwSize);
166 Main_IDirect3DMaterialImpl_3_2T_1T_GetHandle(LPDIRECT3DMATERIAL3 iface,
167 LPDIRECT3DDEVICE3 lpDirect3DDevice3,
168 LPD3DMATERIALHANDLE lpHandle)
170 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
171 TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpDirect3DDevice3, lpHandle);
173 This->active_device = ICOM_OBJECT(IDirect3DDeviceImpl, IDirect3DDevice3, lpDirect3DDevice3);
174 *lpHandle = (DWORD) This; /* Warning: this is not 64 bit clean.
175 Maybe also we need to store this material somewhere in the device ? */
177 TRACE(" returning handle %08lx.\n", *lpHandle);
183 Thunk_IDirect3DMaterialImpl_2_GetHandle(LPDIRECT3DMATERIAL2 iface,
184 LPDIRECT3DDEVICE2 lpDirect3DDevice2,
185 LPD3DMATERIALHANDLE lpHandle)
187 TRACE("(%p)->(%p,%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpDirect3DDevice2, lpHandle);
188 return IDirect3DMaterial3_GetHandle(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
189 COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, lpDirect3DDevice2),
194 Thunk_IDirect3DMaterialImpl_1_GetHandle(LPDIRECT3DMATERIAL iface,
195 LPDIRECT3DDEVICE lpDirect3DDevice,
196 LPD3DMATERIALHANDLE lpHandle)
198 TRACE("(%p)->(%p,%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpDirect3DDevice, lpHandle);
199 return IDirect3DMaterial3_GetHandle(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
200 COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice3, lpDirect3DDevice),
205 Thunk_IDirect3DMaterialImpl_2_QueryInterface(LPDIRECT3DMATERIAL2 iface,
209 TRACE("(%p)->(%s,%p) thunking to IDirect3DMaterial3 interface.\n", iface, debugstr_guid(riid), obp);
210 return IDirect3DMaterial3_QueryInterface(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
216 Thunk_IDirect3DMaterialImpl_1_QueryInterface(LPDIRECT3DMATERIAL iface,
220 TRACE("(%p)->(%s,%p) thunking to IDirect3DMaterial3 interface.\n", iface, debugstr_guid(riid), obp);
221 return IDirect3DMaterial3_QueryInterface(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
227 Thunk_IDirect3DMaterialImpl_2_AddRef(LPDIRECT3DMATERIAL2 iface)
229 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
230 return IDirect3DMaterial3_AddRef(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface));
234 Thunk_IDirect3DMaterialImpl_1_AddRef(LPDIRECT3DMATERIAL iface)
236 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
237 return IDirect3DMaterial3_AddRef(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface));
241 Thunk_IDirect3DMaterialImpl_2_Release(LPDIRECT3DMATERIAL2 iface)
243 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
244 return IDirect3DMaterial3_Release(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface));
248 Thunk_IDirect3DMaterialImpl_1_Release(LPDIRECT3DMATERIAL iface)
250 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
251 return IDirect3DMaterial3_Release(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface));
255 Thunk_IDirect3DMaterialImpl_2_SetMaterial(LPDIRECT3DMATERIAL2 iface,
258 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
259 return IDirect3DMaterial3_SetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
264 Thunk_IDirect3DMaterialImpl_1_SetMaterial(LPDIRECT3DMATERIAL iface,
267 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
268 return IDirect3DMaterial3_SetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
273 Thunk_IDirect3DMaterialImpl_2_GetMaterial(LPDIRECT3DMATERIAL2 iface,
276 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
277 return IDirect3DMaterial3_GetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
282 Thunk_IDirect3DMaterialImpl_1_GetMaterial(LPDIRECT3DMATERIAL iface,
285 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
286 return IDirect3DMaterial3_GetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
290 /*******************************************************************************
291 * Matrial2 static functions
293 static void activate(IDirect3DMaterialImpl* This) {
294 TRACE("Activating material %p\n", This);
296 /* Set the current Material */
298 glMaterialfv(GL_FRONT_AND_BACK,
300 (float *) &(This->mat.u.diffuse));
301 glMaterialfv(GL_FRONT_AND_BACK,
303 (float *) &(This->mat.u1.ambient));
304 glMaterialfv(GL_FRONT_AND_BACK,
306 (float *) &(This->mat.u2.specular));
307 glMaterialfv(GL_FRONT_AND_BACK,
309 (float *) &(This->mat.u3.emissive));
312 if (TRACE_ON(ddraw)) {
313 DPRINTF(" - size : %ld\n", This->mat.dwSize);
314 DPRINTF(" - diffuse : "); dump_D3DCOLORVALUE(&(This->mat.u.diffuse)); DPRINTF("\n");
315 DPRINTF(" - ambient : "); dump_D3DCOLORVALUE(&(This->mat.u1.ambient)); DPRINTF("\n");
316 DPRINTF(" - specular: "); dump_D3DCOLORVALUE(&(This->mat.u2.specular)); DPRINTF("\n");
317 DPRINTF(" - emissive: "); dump_D3DCOLORVALUE(&(This->mat.u3.emissive)); DPRINTF("\n");
318 DPRINTF(" - power : %f\n", This->mat.u4.power);
319 DPRINTF(" - texture handle : %08lx\n", (DWORD)This->mat.hTexture);
323 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
324 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial3.fun))
326 # define XCAST(fun) (void*)
329 ICOM_VTABLE(IDirect3DMaterial3) VTABLE_IDirect3DMaterial3 =
331 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
332 XCAST(QueryInterface) Main_IDirect3DMaterialImpl_3_2T_1T_QueryInterface,
333 XCAST(AddRef) Main_IDirect3DMaterialImpl_3_2T_1T_AddRef,
334 XCAST(Release) Main_IDirect3DMaterialImpl_3_2T_1T_Release,
335 XCAST(SetMaterial) Main_IDirect3DMaterialImpl_3_2T_1T_SetMaterial,
336 XCAST(GetMaterial) Main_IDirect3DMaterialImpl_3_2T_1T_GetMaterial,
337 XCAST(GetHandle) Main_IDirect3DMaterialImpl_3_2T_1T_GetHandle,
340 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
345 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
346 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial2.fun))
348 # define XCAST(fun) (void*)
351 ICOM_VTABLE(IDirect3DMaterial2) VTABLE_IDirect3DMaterial2 =
353 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
354 XCAST(QueryInterface) Thunk_IDirect3DMaterialImpl_2_QueryInterface,
355 XCAST(AddRef) Thunk_IDirect3DMaterialImpl_2_AddRef,
356 XCAST(Release) Thunk_IDirect3DMaterialImpl_2_Release,
357 XCAST(SetMaterial) Thunk_IDirect3DMaterialImpl_2_SetMaterial,
358 XCAST(GetMaterial) Thunk_IDirect3DMaterialImpl_2_GetMaterial,
359 XCAST(GetHandle) Thunk_IDirect3DMaterialImpl_2_GetHandle,
362 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
367 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
368 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial.fun))
370 # define XCAST(fun) (void*)
373 ICOM_VTABLE(IDirect3DMaterial) VTABLE_IDirect3DMaterial =
375 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
376 XCAST(QueryInterface) Thunk_IDirect3DMaterialImpl_1_QueryInterface,
377 XCAST(AddRef) Thunk_IDirect3DMaterialImpl_1_AddRef,
378 XCAST(Release) Thunk_IDirect3DMaterialImpl_1_Release,
379 XCAST(Initialize) Main_IDirect3DMaterialImpl_1_Initialize,
380 XCAST(SetMaterial) Thunk_IDirect3DMaterialImpl_1_SetMaterial,
381 XCAST(GetMaterial) Thunk_IDirect3DMaterialImpl_1_GetMaterial,
382 XCAST(GetHandle) Thunk_IDirect3DMaterialImpl_1_GetHandle,
383 XCAST(Reserve) Main_IDirect3DMaterialImpl_1_Reserve,
384 XCAST(Unreserve) Main_IDirect3DMaterialImpl_1_Unreserve,
387 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
394 HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirectDrawImpl *d3d)
396 IDirect3DMaterialImpl *object;
398 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DMaterialImpl));
399 if (object == NULL) return DDERR_OUTOFMEMORY;
403 object->activate = activate;
405 ICOM_INIT_INTERFACE(object, IDirect3DMaterial, VTABLE_IDirect3DMaterial);
406 ICOM_INIT_INTERFACE(object, IDirect3DMaterial2, VTABLE_IDirect3DMaterial2);
407 ICOM_INIT_INTERFACE(object, IDirect3DMaterial3, VTABLE_IDirect3DMaterial3);
411 TRACE(" creating implementation at %p.\n", *obj);