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 ULONG ref = InterlockedIncrement(&This->ref);
90 TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, ref - 1);
96 Main_IDirect3DMaterialImpl_3_2T_1T_Release(LPDIRECT3DMATERIAL3 iface)
98 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
99 ULONG ref = InterlockedDecrement(&This->ref);
101 TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
104 HeapFree(GetProcessHeap(), 0, This);
111 Main_IDirect3DMaterialImpl_1_Initialize(LPDIRECT3DMATERIAL iface,
112 LPDIRECT3D lpDirect3D)
114 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
115 TRACE("(%p/%p)->(%p) no-op...!\n", This, iface, lpDirect3D);
120 Main_IDirect3DMaterialImpl_1_Reserve(LPDIRECT3DMATERIAL iface)
122 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
123 TRACE("(%p/%p)->() not implemented.\n", This, iface);
128 Main_IDirect3DMaterialImpl_1_Unreserve(LPDIRECT3DMATERIAL iface)
130 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
131 FIXME("(%p/%p)->() not implemented.\n", This, iface);
136 Main_IDirect3DMaterialImpl_3_2T_1T_SetMaterial(LPDIRECT3DMATERIAL3 iface,
139 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
140 TRACE("(%p/%p)->(%p)\n", This, iface, lpMat);
142 dump_material(lpMat);
144 /* Stores the material */
145 memset(&This->mat, 0, sizeof(This->mat));
146 memcpy(&This->mat, lpMat, lpMat->dwSize);
152 Main_IDirect3DMaterialImpl_3_2T_1T_GetMaterial(LPDIRECT3DMATERIAL3 iface,
155 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
157 TRACE("(%p/%p)->(%p)\n", This, iface, lpMat);
158 if (TRACE_ON(ddraw)) {
159 TRACE(" Returning material : ");
160 dump_material(&This->mat);
163 /* Copies the material structure */
164 dwSize = lpMat->dwSize;
165 memset(lpMat, 0, dwSize);
166 memcpy(lpMat, &This->mat, dwSize);
172 Main_IDirect3DMaterialImpl_3_2T_1T_GetHandle(LPDIRECT3DMATERIAL3 iface,
173 LPDIRECT3DDEVICE3 lpDirect3DDevice3,
174 LPD3DMATERIALHANDLE lpHandle)
176 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
177 TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpDirect3DDevice3, lpHandle);
179 This->active_device = ICOM_OBJECT(IDirect3DDeviceImpl, IDirect3DDevice3, lpDirect3DDevice3);
180 *lpHandle = (DWORD) This; /* Warning: this is not 64 bit clean.
181 Maybe also we need to store this material somewhere in the device ? */
183 TRACE(" returning handle %08lx.\n", *lpHandle);
189 Thunk_IDirect3DMaterialImpl_2_GetHandle(LPDIRECT3DMATERIAL2 iface,
190 LPDIRECT3DDEVICE2 lpDirect3DDevice2,
191 LPD3DMATERIALHANDLE lpHandle)
193 TRACE("(%p)->(%p,%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpDirect3DDevice2, lpHandle);
194 return IDirect3DMaterial3_GetHandle(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
195 COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice3, lpDirect3DDevice2),
200 Thunk_IDirect3DMaterialImpl_1_GetHandle(LPDIRECT3DMATERIAL iface,
201 LPDIRECT3DDEVICE lpDirect3DDevice,
202 LPD3DMATERIALHANDLE lpHandle)
204 TRACE("(%p)->(%p,%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpDirect3DDevice, lpHandle);
205 return IDirect3DMaterial3_GetHandle(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
206 COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice3, lpDirect3DDevice),
211 Thunk_IDirect3DMaterialImpl_2_QueryInterface(LPDIRECT3DMATERIAL2 iface,
215 TRACE("(%p)->(%s,%p) thunking to IDirect3DMaterial3 interface.\n", iface, debugstr_guid(riid), obp);
216 return IDirect3DMaterial3_QueryInterface(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
222 Thunk_IDirect3DMaterialImpl_1_QueryInterface(LPDIRECT3DMATERIAL iface,
226 TRACE("(%p)->(%s,%p) thunking to IDirect3DMaterial3 interface.\n", iface, debugstr_guid(riid), obp);
227 return IDirect3DMaterial3_QueryInterface(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
233 Thunk_IDirect3DMaterialImpl_2_AddRef(LPDIRECT3DMATERIAL2 iface)
235 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
236 return IDirect3DMaterial3_AddRef(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface));
240 Thunk_IDirect3DMaterialImpl_1_AddRef(LPDIRECT3DMATERIAL iface)
242 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
243 return IDirect3DMaterial3_AddRef(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface));
247 Thunk_IDirect3DMaterialImpl_2_Release(LPDIRECT3DMATERIAL2 iface)
249 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
250 return IDirect3DMaterial3_Release(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface));
254 Thunk_IDirect3DMaterialImpl_1_Release(LPDIRECT3DMATERIAL iface)
256 TRACE("(%p)->() thunking to IDirect3DMaterial3 interface.\n", iface);
257 return IDirect3DMaterial3_Release(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface));
261 Thunk_IDirect3DMaterialImpl_2_SetMaterial(LPDIRECT3DMATERIAL2 iface,
264 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
265 return IDirect3DMaterial3_SetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
270 Thunk_IDirect3DMaterialImpl_1_SetMaterial(LPDIRECT3DMATERIAL iface,
273 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
274 return IDirect3DMaterial3_SetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
279 Thunk_IDirect3DMaterialImpl_2_GetMaterial(LPDIRECT3DMATERIAL2 iface,
282 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
283 return IDirect3DMaterial3_GetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
288 Thunk_IDirect3DMaterialImpl_1_GetMaterial(LPDIRECT3DMATERIAL iface,
291 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
292 return IDirect3DMaterial3_GetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
296 /*******************************************************************************
297 * Matrial2 static functions
299 static void activate(IDirect3DMaterialImpl* This) {
300 TRACE("Activating material %p\n", This);
302 /* Set the current Material */
304 glMaterialfv(GL_FRONT_AND_BACK,
306 (float *) &(This->mat.u.diffuse));
307 glMaterialfv(GL_FRONT_AND_BACK,
309 (float *) &(This->mat.u1.ambient));
310 glMaterialfv(GL_FRONT_AND_BACK,
312 (float *) &(This->mat.u2.specular));
313 glMaterialfv(GL_FRONT_AND_BACK,
315 (float *) &(This->mat.u3.emissive));
318 if (TRACE_ON(ddraw)) {
319 DPRINTF(" - size : %ld\n", This->mat.dwSize);
320 DPRINTF(" - diffuse : "); dump_D3DCOLORVALUE(&(This->mat.u.diffuse)); DPRINTF("\n");
321 DPRINTF(" - ambient : "); dump_D3DCOLORVALUE(&(This->mat.u1.ambient)); DPRINTF("\n");
322 DPRINTF(" - specular: "); dump_D3DCOLORVALUE(&(This->mat.u2.specular)); DPRINTF("\n");
323 DPRINTF(" - emissive: "); dump_D3DCOLORVALUE(&(This->mat.u3.emissive)); DPRINTF("\n");
324 DPRINTF(" - power : %f\n", This->mat.u4.power);
325 DPRINTF(" - texture handle : %08lx\n", (DWORD)This->mat.hTexture);
329 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
330 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial3.fun))
332 # define XCAST(fun) (void*)
335 IDirect3DMaterial3Vtbl VTABLE_IDirect3DMaterial3 =
337 XCAST(QueryInterface) Main_IDirect3DMaterialImpl_3_2T_1T_QueryInterface,
338 XCAST(AddRef) Main_IDirect3DMaterialImpl_3_2T_1T_AddRef,
339 XCAST(Release) Main_IDirect3DMaterialImpl_3_2T_1T_Release,
340 XCAST(SetMaterial) Main_IDirect3DMaterialImpl_3_2T_1T_SetMaterial,
341 XCAST(GetMaterial) Main_IDirect3DMaterialImpl_3_2T_1T_GetMaterial,
342 XCAST(GetHandle) Main_IDirect3DMaterialImpl_3_2T_1T_GetHandle,
345 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
350 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
351 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial2.fun))
353 # define XCAST(fun) (void*)
356 IDirect3DMaterial2Vtbl VTABLE_IDirect3DMaterial2 =
358 XCAST(QueryInterface) Thunk_IDirect3DMaterialImpl_2_QueryInterface,
359 XCAST(AddRef) Thunk_IDirect3DMaterialImpl_2_AddRef,
360 XCAST(Release) Thunk_IDirect3DMaterialImpl_2_Release,
361 XCAST(SetMaterial) Thunk_IDirect3DMaterialImpl_2_SetMaterial,
362 XCAST(GetMaterial) Thunk_IDirect3DMaterialImpl_2_GetMaterial,
363 XCAST(GetHandle) Thunk_IDirect3DMaterialImpl_2_GetHandle,
366 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
371 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
372 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial.fun))
374 # define XCAST(fun) (void*)
377 IDirect3DMaterialVtbl VTABLE_IDirect3DMaterial =
379 XCAST(QueryInterface) Thunk_IDirect3DMaterialImpl_1_QueryInterface,
380 XCAST(AddRef) Thunk_IDirect3DMaterialImpl_1_AddRef,
381 XCAST(Release) Thunk_IDirect3DMaterialImpl_1_Release,
382 XCAST(Initialize) Main_IDirect3DMaterialImpl_1_Initialize,
383 XCAST(SetMaterial) Thunk_IDirect3DMaterialImpl_1_SetMaterial,
384 XCAST(GetMaterial) Thunk_IDirect3DMaterialImpl_1_GetMaterial,
385 XCAST(GetHandle) Thunk_IDirect3DMaterialImpl_1_GetHandle,
386 XCAST(Reserve) Main_IDirect3DMaterialImpl_1_Reserve,
387 XCAST(Unreserve) Main_IDirect3DMaterialImpl_1_Unreserve,
390 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
397 HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirectDrawImpl *d3d)
399 IDirect3DMaterialImpl *object;
401 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DMaterialImpl));
402 if (object == NULL) return DDERR_OUTOFMEMORY;
406 object->activate = activate;
408 ICOM_INIT_INTERFACE(object, IDirect3DMaterial, VTABLE_IDirect3DMaterial);
409 ICOM_INIT_INTERFACE(object, IDirect3DMaterial2, VTABLE_IDirect3DMaterial2);
410 ICOM_INIT_INTERFACE(object, IDirect3DMaterial3, VTABLE_IDirect3DMaterial3);
414 TRACE(" creating implementation at %p.\n", *obj);