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
37 #include "wine/debug.h"
39 #include "d3d_private.h"
40 #include "opengl_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
44 static void dump_material(LPD3DMATERIAL mat)
46 DPRINTF(" dwSize : %ld\n", mat->dwSize);
50 Main_IDirect3DMaterialImpl_3_2T_1T_QueryInterface(LPDIRECT3DMATERIAL3 iface,
54 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
55 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obp);
59 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
60 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
62 TRACE(" Creating IUnknown interface at %p.\n", *obp);
65 if ( IsEqualGUID( &IID_IDirect3DMaterial, riid ) ) {
66 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
67 *obp = ICOM_INTERFACE(This, IDirect3DMaterial);
68 TRACE(" Creating IDirect3DMaterial interface %p\n", *obp);
71 if ( IsEqualGUID( &IID_IDirect3DMaterial2, riid ) ) {
72 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
73 *obp = ICOM_INTERFACE(This, IDirect3DMaterial2);
74 TRACE(" Creating IDirect3DMaterial2 interface %p\n", *obp);
77 if ( IsEqualGUID( &IID_IDirect3DMaterial3, riid ) ) {
78 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
79 *obp = ICOM_INTERFACE(This, IDirect3DMaterial3);
80 TRACE(" Creating IDirect3DMaterial3 interface %p\n", *obp);
83 FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
84 return OLE_E_ENUM_NOMORE;
88 Main_IDirect3DMaterialImpl_3_2T_1T_AddRef(LPDIRECT3DMATERIAL3 iface)
90 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
91 ULONG ref = InterlockedIncrement(&This->ref);
93 TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1);
99 Main_IDirect3DMaterialImpl_3_2T_1T_Release(LPDIRECT3DMATERIAL3 iface)
101 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
102 ULONG ref = InterlockedDecrement(&This->ref);
104 TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
107 HeapFree(GetProcessHeap(), 0, This);
114 Main_IDirect3DMaterialImpl_1_Initialize(LPDIRECT3DMATERIAL iface,
115 LPDIRECT3D lpDirect3D)
117 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
118 TRACE("(%p/%p)->(%p) no-op...!\n", This, iface, lpDirect3D);
123 Main_IDirect3DMaterialImpl_1_Reserve(LPDIRECT3DMATERIAL iface)
125 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
126 TRACE("(%p/%p)->() not implemented.\n", This, iface);
131 Main_IDirect3DMaterialImpl_1_Unreserve(LPDIRECT3DMATERIAL iface)
133 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
134 FIXME("(%p/%p)->() not implemented.\n", This, iface);
139 Main_IDirect3DMaterialImpl_3_2T_1T_SetMaterial(LPDIRECT3DMATERIAL3 iface,
142 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
143 TRACE("(%p/%p)->(%p)\n", This, iface, lpMat);
145 dump_material(lpMat);
147 /* Stores the material */
148 memset(&This->mat, 0, sizeof(This->mat));
149 memcpy(&This->mat, lpMat, lpMat->dwSize);
155 Main_IDirect3DMaterialImpl_3_2T_1T_GetMaterial(LPDIRECT3DMATERIAL3 iface,
158 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
160 TRACE("(%p/%p)->(%p)\n", This, iface, lpMat);
161 if (TRACE_ON(ddraw)) {
162 TRACE(" Returning material : ");
163 dump_material(&This->mat);
166 /* Copies the material structure */
167 dwSize = lpMat->dwSize;
168 memset(lpMat, 0, dwSize);
169 memcpy(lpMat, &This->mat, dwSize);
175 Main_IDirect3DMaterialImpl_3_2T_1T_GetHandle(LPDIRECT3DMATERIAL3 iface,
176 LPDIRECT3DDEVICE3 lpDirect3DDevice3,
177 LPD3DMATERIALHANDLE lpHandle)
179 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
180 TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpDirect3DDevice3, lpHandle);
182 This->active_device = ICOM_OBJECT(IDirect3DDeviceImpl, IDirect3DDevice3, lpDirect3DDevice3);
183 *lpHandle = (DWORD) This; /* Warning: this is not 64 bit clean.
184 Maybe also we need to store this material somewhere in the device ? */
186 TRACE(" returning handle %08lx.\n", *lpHandle);
192 Thunk_IDirect3DMaterialImpl_2_GetHandle(LPDIRECT3DMATERIAL2 iface,
193 LPDIRECT3DDEVICE2 lpDirect3DDevice2,
194 LPD3DMATERIALHANDLE lpHandle)
196 TRACE("(%p)->(%p,%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpDirect3DDevice2, lpHandle);
197 return IDirect3DMaterial3_GetHandle(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
198 COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, lpDirect3DDevice2),
203 Thunk_IDirect3DMaterialImpl_1_GetHandle(LPDIRECT3DMATERIAL iface,
204 LPDIRECT3DDEVICE lpDirect3DDevice,
205 LPD3DMATERIALHANDLE lpHandle)
207 TRACE("(%p)->(%p,%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpDirect3DDevice, lpHandle);
208 return IDirect3DMaterial3_GetHandle(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
209 COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice3, lpDirect3DDevice),
214 Thunk_IDirect3DMaterialImpl_2_QueryInterface(LPDIRECT3DMATERIAL2 iface,
218 TRACE("(%p)->(%s,%p) thunking to IDirect3DMaterial3 interface.\n", iface, debugstr_guid(riid), obp);
219 return IDirect3DMaterial3_QueryInterface(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
225 Thunk_IDirect3DMaterialImpl_1_QueryInterface(LPDIRECT3DMATERIAL iface,
229 TRACE("(%p)->(%s,%p) thunking to IDirect3DMaterial3 interface.\n", iface, debugstr_guid(riid), obp);
230 return IDirect3DMaterial3_QueryInterface(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
236 Thunk_IDirect3DMaterialImpl_2_AddRef(LPDIRECT3DMATERIAL2 iface)
238 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
239 return IDirect3DMaterial3_AddRef(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface));
243 Thunk_IDirect3DMaterialImpl_1_AddRef(LPDIRECT3DMATERIAL iface)
245 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
246 return IDirect3DMaterial3_AddRef(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface));
250 Thunk_IDirect3DMaterialImpl_2_Release(LPDIRECT3DMATERIAL2 iface)
252 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
253 return IDirect3DMaterial3_Release(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface));
257 Thunk_IDirect3DMaterialImpl_1_Release(LPDIRECT3DMATERIAL iface)
259 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
260 return IDirect3DMaterial3_Release(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface));
264 Thunk_IDirect3DMaterialImpl_2_SetMaterial(LPDIRECT3DMATERIAL2 iface,
267 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
268 return IDirect3DMaterial3_SetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
273 Thunk_IDirect3DMaterialImpl_1_SetMaterial(LPDIRECT3DMATERIAL iface,
276 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
277 return IDirect3DMaterial3_SetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
282 Thunk_IDirect3DMaterialImpl_2_GetMaterial(LPDIRECT3DMATERIAL2 iface,
285 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
286 return IDirect3DMaterial3_GetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
291 Thunk_IDirect3DMaterialImpl_1_GetMaterial(LPDIRECT3DMATERIAL iface,
294 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
295 return IDirect3DMaterial3_GetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
299 /*******************************************************************************
300 * Matrial2 static functions
302 static void activate(IDirect3DMaterialImpl* This) {
303 TRACE("Activating material %p\n", This);
305 /* Set the current Material */
307 glMaterialfv(GL_FRONT_AND_BACK,
309 (float *) &(This->mat.u.diffuse));
310 glMaterialfv(GL_FRONT_AND_BACK,
312 (float *) &(This->mat.u1.ambient));
313 glMaterialfv(GL_FRONT_AND_BACK,
315 (float *) &(This->mat.u2.specular));
316 glMaterialfv(GL_FRONT_AND_BACK,
318 (float *) &(This->mat.u3.emissive));
321 if (TRACE_ON(ddraw)) {
322 DPRINTF(" - size : %ld\n", This->mat.dwSize);
323 DPRINTF(" - diffuse : "); dump_D3DCOLORVALUE(&(This->mat.u.diffuse)); DPRINTF("\n");
324 DPRINTF(" - ambient : "); dump_D3DCOLORVALUE(&(This->mat.u1.ambient)); DPRINTF("\n");
325 DPRINTF(" - specular: "); dump_D3DCOLORVALUE(&(This->mat.u2.specular)); DPRINTF("\n");
326 DPRINTF(" - emissive: "); dump_D3DCOLORVALUE(&(This->mat.u3.emissive)); DPRINTF("\n");
327 DPRINTF(" - power : %f\n", This->mat.u4.power);
328 DPRINTF(" - texture handle : %08lx\n", (DWORD)This->mat.hTexture);
332 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
333 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial3.fun))
335 # define XCAST(fun) (void*)
338 static const IDirect3DMaterial3Vtbl VTABLE_IDirect3DMaterial3 =
340 XCAST(QueryInterface) Main_IDirect3DMaterialImpl_3_2T_1T_QueryInterface,
341 XCAST(AddRef) Main_IDirect3DMaterialImpl_3_2T_1T_AddRef,
342 XCAST(Release) Main_IDirect3DMaterialImpl_3_2T_1T_Release,
343 XCAST(SetMaterial) Main_IDirect3DMaterialImpl_3_2T_1T_SetMaterial,
344 XCAST(GetMaterial) Main_IDirect3DMaterialImpl_3_2T_1T_GetMaterial,
345 XCAST(GetHandle) Main_IDirect3DMaterialImpl_3_2T_1T_GetHandle,
348 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
353 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
354 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial2.fun))
356 # define XCAST(fun) (void*)
359 static const IDirect3DMaterial2Vtbl VTABLE_IDirect3DMaterial2 =
361 XCAST(QueryInterface) Thunk_IDirect3DMaterialImpl_2_QueryInterface,
362 XCAST(AddRef) Thunk_IDirect3DMaterialImpl_2_AddRef,
363 XCAST(Release) Thunk_IDirect3DMaterialImpl_2_Release,
364 XCAST(SetMaterial) Thunk_IDirect3DMaterialImpl_2_SetMaterial,
365 XCAST(GetMaterial) Thunk_IDirect3DMaterialImpl_2_GetMaterial,
366 XCAST(GetHandle) Thunk_IDirect3DMaterialImpl_2_GetHandle,
369 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
374 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
375 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial.fun))
377 # define XCAST(fun) (void*)
380 static const IDirect3DMaterialVtbl VTABLE_IDirect3DMaterial =
382 XCAST(QueryInterface) Thunk_IDirect3DMaterialImpl_1_QueryInterface,
383 XCAST(AddRef) Thunk_IDirect3DMaterialImpl_1_AddRef,
384 XCAST(Release) Thunk_IDirect3DMaterialImpl_1_Release,
385 XCAST(Initialize) Main_IDirect3DMaterialImpl_1_Initialize,
386 XCAST(SetMaterial) Thunk_IDirect3DMaterialImpl_1_SetMaterial,
387 XCAST(GetMaterial) Thunk_IDirect3DMaterialImpl_1_GetMaterial,
388 XCAST(GetHandle) Thunk_IDirect3DMaterialImpl_1_GetHandle,
389 XCAST(Reserve) Main_IDirect3DMaterialImpl_1_Reserve,
390 XCAST(Unreserve) Main_IDirect3DMaterialImpl_1_Unreserve,
393 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
400 HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirectDrawImpl *d3d)
402 IDirect3DMaterialImpl *object;
404 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DMaterialImpl));
405 if (object == NULL) return DDERR_OUTOFMEMORY;
409 object->activate = activate;
411 ICOM_INIT_INTERFACE(object, IDirect3DMaterial, VTABLE_IDirect3DMaterial);
412 ICOM_INIT_INTERFACE(object, IDirect3DMaterial2, VTABLE_IDirect3DMaterial2);
413 ICOM_INIT_INTERFACE(object, IDirect3DMaterial3, VTABLE_IDirect3DMaterial3);
417 TRACE(" creating implementation at %p.\n", *obj);