2 * Copyright (c) 1998 Lionel ULMER
4 * This file contains the implementation of Direct3DMaterial2.
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
24 #include "wine/obj_base.h"
27 #include "wine/debug.h"
29 #include "mesa_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
33 static ICOM_VTABLE(IDirect3DMaterial2
) material2_vtable
;
34 static ICOM_VTABLE(IDirect3DMaterial
) material_vtable
;
36 /*******************************************************************************
37 * Matrial2 static functions
39 static void activate(IDirect3DMaterial2Impl
* This
) {
40 TRACE("Activating material %p\n", This
);
43 /* First, set the rendering context */
45 This
->device
.active_device2
->set_context(This
->device
.active_device2
);
47 This
->device
.active_device1
->set_context(This
->device
.active_device1
);
49 /* Set the current Material */
50 _dump_colorvalue("Diffuse", This
->mat
.u
.diffuse
);
51 glMaterialfv(GL_FRONT
,
53 (float *) &(This
->mat
.u
.diffuse
));
54 _dump_colorvalue("Ambient", This
->mat
.u1
.ambient
);
55 glMaterialfv(GL_FRONT
,
57 (float *) &(This
->mat
.u1
.ambient
));
58 _dump_colorvalue("Specular", This
->mat
.u2
.specular
);
59 glMaterialfv(GL_FRONT
,
61 (float *) &(This
->mat
.u2
.specular
));
62 _dump_colorvalue("Emissive", This
->mat
.u3
.emissive
);
63 glMaterialfv(GL_FRONT
,
65 (float *) &(This
->mat
.u3
.emissive
));
67 TRACE("Size : %ld\n", This
->mat
.dwSize
);
68 TRACE("Power : %f\n", This
->mat
.u4
.power
);
70 TRACE("Texture handle : %08lx\n", (DWORD
)This
->mat
.hTexture
);
76 /*******************************************************************************
77 * Matrial2 Creation functions
79 LPDIRECT3DMATERIAL2
d3dmaterial2_create(IDirect3D2Impl
* d3d2
)
81 IDirect3DMaterial2Impl
* mat
;
83 mat
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirect3DMaterial2Impl
));
85 ICOM_VTBL(mat
) = &material2_vtable
;
90 mat
->activate
= activate
;
92 return (LPDIRECT3DMATERIAL2
)mat
;
95 LPDIRECT3DMATERIAL
d3dmaterial_create(IDirect3DImpl
* d3d1
)
97 IDirect3DMaterial2Impl
* mat
;
99 mat
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirect3DMaterial2Impl
));
101 ICOM_VTBL(mat
) = (ICOM_VTABLE(IDirect3DMaterial2
)*)&material_vtable
;
104 mat
->d3d
.d3d1
= d3d1
;
106 mat
->activate
= activate
;
108 return (LPDIRECT3DMATERIAL
) mat
;
111 /*******************************************************************************
112 * IDirect3DMaterial2 methods
115 static HRESULT WINAPI
IDirect3DMaterial2Impl_QueryInterface(LPDIRECT3DMATERIAL2 iface
,
119 ICOM_THIS(IDirect3DMaterial2Impl
,iface
);
121 FIXME("(%p)->(%s,%p): stub\n", This
, debugstr_guid(riid
),ppvObj
);
128 static ULONG WINAPI
IDirect3DMaterial2Impl_AddRef(LPDIRECT3DMATERIAL2 iface
)
130 ICOM_THIS(IDirect3DMaterial2Impl
,iface
);
131 TRACE("(%p)->()incrementing from %lu.\n", This
, This
->ref
);
133 return ++(This
->ref
);
138 static ULONG WINAPI
IDirect3DMaterial2Impl_Release(LPDIRECT3DMATERIAL2 iface
)
140 ICOM_THIS(IDirect3DMaterial2Impl
,iface
);
141 FIXME("(%p)->() decrementing from %lu.\n", This
, This
->ref
);
143 if (!--(This
->ref
)) {
144 HeapFree(GetProcessHeap(),0,This
);
151 /*** IDirect3DMaterial2 methods ***/
152 static void dump_material(LPD3DMATERIAL mat
)
154 DPRINTF(" dwSize : %ld\n", mat
->dwSize
);
157 static HRESULT WINAPI
IDirect3DMaterial2Impl_GetMaterial(LPDIRECT3DMATERIAL2 iface
,
160 ICOM_THIS(IDirect3DMaterial2Impl
,iface
);
161 TRACE("(%p)->(%p)\n", This
, lpMat
);
163 dump_material(lpMat
);
165 /* Copies the material structure */
171 static HRESULT WINAPI
IDirect3DMaterial2Impl_SetMaterial(LPDIRECT3DMATERIAL2 iface
,
174 ICOM_THIS(IDirect3DMaterial2Impl
,iface
);
175 TRACE("(%p)->(%p)\n", This
, lpMat
);
177 dump_material(lpMat
);
179 /* Stores the material */
185 static HRESULT WINAPI
IDirect3DMaterial2Impl_GetHandle(LPDIRECT3DMATERIAL2 iface
,
186 LPDIRECT3DDEVICE2 lpD3DDevice2
,
187 LPD3DMATERIALHANDLE lpMatHandle
)
190 ICOM_THIS(IDirect3DMaterial2Impl
,iface
);
191 FIXME("(%p)->(%p,%p): stub\n", This
, lpD3DDevice2
, lpMatHandle
);
194 This
->device
.active_device2
= (IDirect3DDevice2Impl
*)lpD3DDevice2
;
196 This
->device
.active_device1
= (IDirect3DDeviceImpl
*)lpD3DDevice2
;
198 *lpMatHandle
= (DWORD
) This
; /* lpD3DDevice2->store_material(This); */
203 static HRESULT WINAPI
IDirect3DMaterialImpl_Reserve(LPDIRECT3DMATERIAL iface
)
205 ICOM_THIS(IDirect3DMaterial2Impl
,iface
);
206 FIXME("(%p)->(): stub\n", This
);
208 return DDERR_INVALIDPARAMS
;
211 static HRESULT WINAPI
IDirect3DMaterialImpl_Unreserve(LPDIRECT3DMATERIAL iface
)
213 ICOM_THIS(IDirect3DMaterial2Impl
,iface
);
214 FIXME("(%p)->(): stub\n", This
);
216 return DDERR_INVALIDPARAMS
;
219 static HRESULT WINAPI
IDirect3DMaterialImpl_Initialize(LPDIRECT3DMATERIAL iface
,
220 LPDIRECT3D lpDirect3D
)
223 ICOM_THIS(IDirect3DMaterial2Impl
,iface
);
224 TRACE("(%p)->(%p)\n", This
, lpDirect3D
);
226 return DDERR_ALREADYINITIALIZED
;
230 /*******************************************************************************
231 * IDirect3DMaterial VTable
233 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
234 # define XCAST(fun) (typeof(material_vtable.fun))
236 # define XCAST(fun) (void*)
239 static ICOM_VTABLE(IDirect3DMaterial
) material_vtable
=
241 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
242 /*** IUnknown methods ***/
243 XCAST(QueryInterface
)IDirect3DMaterial2Impl_QueryInterface
,
244 XCAST(AddRef
)IDirect3DMaterial2Impl_AddRef
,
245 XCAST(Release
)IDirect3DMaterial2Impl_Release
,
246 /*** IDirect3DMaterial methods ***/
247 IDirect3DMaterialImpl_Initialize
,
248 XCAST(SetMaterial
)IDirect3DMaterial2Impl_SetMaterial
,
249 XCAST(GetMaterial
)IDirect3DMaterial2Impl_GetMaterial
,
250 XCAST(GetHandle
)IDirect3DMaterial2Impl_GetHandle
,
251 IDirect3DMaterialImpl_Reserve
,
252 IDirect3DMaterialImpl_Unreserve
255 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
259 /*******************************************************************************
260 * IDirect3DMaterial2 VTable
262 static ICOM_VTABLE(IDirect3DMaterial2
) material2_vtable
=
264 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
265 /*** IUnknown methods ***/
266 IDirect3DMaterial2Impl_QueryInterface
,
267 IDirect3DMaterial2Impl_AddRef
,
268 IDirect3DMaterial2Impl_Release
,
269 /*** IDirect3DMaterial methods ***/
270 IDirect3DMaterial2Impl_SetMaterial
,
271 IDirect3DMaterial2Impl_GetMaterial
,
272 IDirect3DMaterial2Impl_GetHandle