Update a url.
[wine.git] / dlls / ddraw / d3dmaterial.c
blob3b39f02f1337efb0b11ea8d0dd3e2f933be23db5
1 /* Direct3D Material
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
21 #include "config.h"
23 #include <stdarg.h>
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "objbase.h"
31 #include "wingdi.h"
32 #include "ddraw.h"
33 #include "d3d.h"
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);
46 HRESULT WINAPI
47 Main_IDirect3DMaterialImpl_3_2T_1T_QueryInterface(LPDIRECT3DMATERIAL3 iface,
48 REFIID riid,
49 LPVOID* obp)
51 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
52 TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obp);
54 *obp = NULL;
56 if ( IsEqualGUID( &IID_IUnknown, riid ) ) {
57 IDirect3DMaterial_AddRef(ICOM_INTERFACE(This, IDirect3DMaterial));
58 *obp = iface;
59 TRACE(" Creating IUnknown interface at %p.\n", *obp);
60 return S_OK;
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);
66 return S_OK;
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);
72 return S_OK;
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);
78 return S_OK;
80 FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
81 return OLE_E_ENUM_NOMORE;
84 ULONG WINAPI
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);
89 return ++(This->ref);
92 ULONG WINAPI
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);
97 if (!--(This->ref)) {
98 HeapFree(GetProcessHeap(), 0, This);
99 return 0;
101 return This->ref;
104 HRESULT WINAPI
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);
110 return DD_OK;
113 HRESULT WINAPI
114 Main_IDirect3DMaterialImpl_1_Reserve(LPDIRECT3DMATERIAL iface)
116 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
117 TRACE("(%p/%p)->() not implemented.\n", This, iface);
118 return DD_OK;
121 HRESULT WINAPI
122 Main_IDirect3DMaterialImpl_1_Unreserve(LPDIRECT3DMATERIAL iface)
124 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial, iface);
125 FIXME("(%p/%p)->() not implemented.\n", This, iface);
126 return DD_OK;
129 HRESULT WINAPI
130 Main_IDirect3DMaterialImpl_3_2T_1T_SetMaterial(LPDIRECT3DMATERIAL3 iface,
131 LPD3DMATERIAL lpMat)
133 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
134 TRACE("(%p/%p)->(%p)\n", This, iface, lpMat);
135 if (TRACE_ON(ddraw))
136 dump_material(lpMat);
138 /* Stores the material */
139 memset(&This->mat, 0, sizeof(This->mat));
140 memcpy(&This->mat, lpMat, lpMat->dwSize);
142 return DD_OK;
145 HRESULT WINAPI
146 Main_IDirect3DMaterialImpl_3_2T_1T_GetMaterial(LPDIRECT3DMATERIAL3 iface,
147 LPD3DMATERIAL lpMat)
149 ICOM_THIS_FROM(IDirect3DMaterialImpl, IDirect3DMaterial3, iface);
150 DWORD dwSize;
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);
162 return DD_OK;
165 HRESULT WINAPI
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);
179 return DD_OK;
182 HRESULT WINAPI
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),
190 lpHandle);
193 HRESULT WINAPI
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),
201 lpHandle);
204 HRESULT WINAPI
205 Thunk_IDirect3DMaterialImpl_2_QueryInterface(LPDIRECT3DMATERIAL2 iface,
206 REFIID riid,
207 LPVOID* obp)
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),
211 riid,
212 obp);
215 HRESULT WINAPI
216 Thunk_IDirect3DMaterialImpl_1_QueryInterface(LPDIRECT3DMATERIAL iface,
217 REFIID riid,
218 LPVOID* obp)
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),
222 riid,
223 obp);
226 ULONG WINAPI
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));
233 ULONG WINAPI
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));
240 ULONG WINAPI
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));
247 ULONG WINAPI
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));
254 HRESULT WINAPI
255 Thunk_IDirect3DMaterialImpl_2_SetMaterial(LPDIRECT3DMATERIAL2 iface,
256 LPD3DMATERIAL lpMat)
258 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
259 return IDirect3DMaterial3_SetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
260 lpMat);
263 HRESULT WINAPI
264 Thunk_IDirect3DMaterialImpl_1_SetMaterial(LPDIRECT3DMATERIAL iface,
265 LPD3DMATERIAL lpMat)
267 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
268 return IDirect3DMaterial3_SetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
269 lpMat);
272 HRESULT WINAPI
273 Thunk_IDirect3DMaterialImpl_2_GetMaterial(LPDIRECT3DMATERIAL2 iface,
274 LPD3DMATERIAL lpMat)
276 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
277 return IDirect3DMaterial3_GetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial2, IDirect3DMaterial3, iface),
278 lpMat);
281 HRESULT WINAPI
282 Thunk_IDirect3DMaterialImpl_1_GetMaterial(LPDIRECT3DMATERIAL iface,
283 LPD3DMATERIAL lpMat)
285 TRACE("(%p)->(%p) thunking to IDirect3DMaterial3 interface.\n", iface, lpMat);
286 return IDirect3DMaterial3_GetMaterial(COM_INTERFACE_CAST(IDirect3DMaterialImpl, IDirect3DMaterial, IDirect3DMaterial3, iface),
287 lpMat);
290 /*******************************************************************************
291 * Matrial2 static functions
293 static void activate(IDirect3DMaterialImpl* This) {
294 TRACE("Activating material %p\n", This);
296 /* Set the current Material */
297 ENTER_GL();
298 glMaterialfv(GL_FRONT_AND_BACK,
299 GL_DIFFUSE,
300 (float *) &(This->mat.u.diffuse));
301 glMaterialfv(GL_FRONT_AND_BACK,
302 GL_AMBIENT,
303 (float *) &(This->mat.u1.ambient));
304 glMaterialfv(GL_FRONT_AND_BACK,
305 GL_SPECULAR,
306 (float *) &(This->mat.u2.specular));
307 glMaterialfv(GL_FRONT_AND_BACK,
308 GL_EMISSION,
309 (float *) &(This->mat.u3.emissive));
310 LEAVE_GL();
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))
325 #else
326 # define XCAST(fun) (void*)
327 #endif
329 IDirect3DMaterial3Vtbl VTABLE_IDirect3DMaterial3 =
331 XCAST(QueryInterface) Main_IDirect3DMaterialImpl_3_2T_1T_QueryInterface,
332 XCAST(AddRef) Main_IDirect3DMaterialImpl_3_2T_1T_AddRef,
333 XCAST(Release) Main_IDirect3DMaterialImpl_3_2T_1T_Release,
334 XCAST(SetMaterial) Main_IDirect3DMaterialImpl_3_2T_1T_SetMaterial,
335 XCAST(GetMaterial) Main_IDirect3DMaterialImpl_3_2T_1T_GetMaterial,
336 XCAST(GetHandle) Main_IDirect3DMaterialImpl_3_2T_1T_GetHandle,
339 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
340 #undef XCAST
341 #endif
344 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
345 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial2.fun))
346 #else
347 # define XCAST(fun) (void*)
348 #endif
350 IDirect3DMaterial2Vtbl VTABLE_IDirect3DMaterial2 =
352 XCAST(QueryInterface) Thunk_IDirect3DMaterialImpl_2_QueryInterface,
353 XCAST(AddRef) Thunk_IDirect3DMaterialImpl_2_AddRef,
354 XCAST(Release) Thunk_IDirect3DMaterialImpl_2_Release,
355 XCAST(SetMaterial) Thunk_IDirect3DMaterialImpl_2_SetMaterial,
356 XCAST(GetMaterial) Thunk_IDirect3DMaterialImpl_2_GetMaterial,
357 XCAST(GetHandle) Thunk_IDirect3DMaterialImpl_2_GetHandle,
360 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
361 #undef XCAST
362 #endif
365 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
366 # define XCAST(fun) (typeof(VTABLE_IDirect3DMaterial.fun))
367 #else
368 # define XCAST(fun) (void*)
369 #endif
371 IDirect3DMaterialVtbl VTABLE_IDirect3DMaterial =
373 XCAST(QueryInterface) Thunk_IDirect3DMaterialImpl_1_QueryInterface,
374 XCAST(AddRef) Thunk_IDirect3DMaterialImpl_1_AddRef,
375 XCAST(Release) Thunk_IDirect3DMaterialImpl_1_Release,
376 XCAST(Initialize) Main_IDirect3DMaterialImpl_1_Initialize,
377 XCAST(SetMaterial) Thunk_IDirect3DMaterialImpl_1_SetMaterial,
378 XCAST(GetMaterial) Thunk_IDirect3DMaterialImpl_1_GetMaterial,
379 XCAST(GetHandle) Thunk_IDirect3DMaterialImpl_1_GetHandle,
380 XCAST(Reserve) Main_IDirect3DMaterialImpl_1_Reserve,
381 XCAST(Unreserve) Main_IDirect3DMaterialImpl_1_Unreserve,
384 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
385 #undef XCAST
386 #endif
391 HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirectDrawImpl *d3d)
393 IDirect3DMaterialImpl *object;
395 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DMaterialImpl));
396 if (object == NULL) return DDERR_OUTOFMEMORY;
398 object->ref = 1;
399 object->d3d = d3d;
400 object->activate = activate;
402 ICOM_INIT_INTERFACE(object, IDirect3DMaterial, VTABLE_IDirect3DMaterial);
403 ICOM_INIT_INTERFACE(object, IDirect3DMaterial2, VTABLE_IDirect3DMaterial2);
404 ICOM_INIT_INTERFACE(object, IDirect3DMaterial3, VTABLE_IDirect3DMaterial3);
406 *obj = object;
408 TRACE(" creating implementation at %p.\n", *obj);
410 return D3D_OK;