2 * Implementation of IDirect3DRMMaterial2 interface
4 * Copyright 2012 Christian Costa
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
24 #include "d3drm_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3drm
);
28 static inline struct d3drm_material
*impl_from_IDirect3DRMMaterial2(IDirect3DRMMaterial2
*iface
)
30 return CONTAINING_RECORD(iface
, struct d3drm_material
, IDirect3DRMMaterial2_iface
);
33 static HRESULT WINAPI
d3drm_material_QueryInterface(IDirect3DRMMaterial2
*iface
, REFIID riid
, void **out
)
35 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
37 if (IsEqualGUID(riid
, &IID_IDirect3DRMMaterial2
)
38 || IsEqualGUID(riid
, &IID_IDirect3DRMMaterial
)
39 || IsEqualGUID(riid
, &IID_IDirect3DRMObject
)
40 || IsEqualGUID(riid
, &IID_IUnknown
))
42 IDirect3DRMMaterial2_AddRef(iface
);
47 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
53 static ULONG WINAPI
d3drm_material_AddRef(IDirect3DRMMaterial2
*iface
)
55 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
56 ULONG refcount
= InterlockedIncrement(&material
->ref
);
58 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
63 static ULONG WINAPI
d3drm_material_Release(IDirect3DRMMaterial2
*iface
)
65 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
66 ULONG refcount
= InterlockedDecrement(&material
->ref
);
68 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
72 d3drm_object_cleanup((IDirect3DRMObject
*)iface
, &material
->obj
);
73 IDirect3DRM_Release(material
->d3drm
);
74 HeapFree(GetProcessHeap(), 0, material
);
80 static HRESULT WINAPI
d3drm_material_Clone(IDirect3DRMMaterial2
*iface
,
81 IUnknown
*outer
, REFIID iid
, void **out
)
83 FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface
, outer
, debugstr_guid(iid
), out
);
88 static HRESULT WINAPI
d3drm_material_AddDestroyCallback(IDirect3DRMMaterial2
*iface
,
89 D3DRMOBJECTCALLBACK cb
, void *ctx
)
91 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
93 TRACE("iface %p, cb %p, ctx %p.\n", iface
, cb
, ctx
);
95 return d3drm_object_add_destroy_callback(&material
->obj
, cb
, ctx
);
98 static HRESULT WINAPI
d3drm_material_DeleteDestroyCallback(IDirect3DRMMaterial2
*iface
,
99 D3DRMOBJECTCALLBACK cb
, void *ctx
)
101 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
103 TRACE("iface %p, cb %p, ctx %p.\n", iface
, cb
, ctx
);
105 return d3drm_object_delete_destroy_callback(&material
->obj
, cb
, ctx
);
108 static HRESULT WINAPI
d3drm_material_SetAppData(IDirect3DRMMaterial2
*iface
, DWORD data
)
110 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
112 TRACE("iface %p, data %#x.\n", iface
, data
);
114 material
->obj
.appdata
= data
;
119 static DWORD WINAPI
d3drm_material_GetAppData(IDirect3DRMMaterial2
*iface
)
121 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
123 TRACE("iface %p.\n", iface
);
125 return material
->obj
.appdata
;
128 static HRESULT WINAPI
d3drm_material_SetName(IDirect3DRMMaterial2
*iface
, const char *name
)
130 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
132 TRACE("iface %p, name %s.\n", iface
, debugstr_a(name
));
134 return d3drm_object_set_name(&material
->obj
, name
);
137 static HRESULT WINAPI
d3drm_material_GetName(IDirect3DRMMaterial2
*iface
, DWORD
*size
, char *name
)
139 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
141 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
143 return d3drm_object_get_name(&material
->obj
, size
, name
);
146 static HRESULT WINAPI
d3drm_material_GetClassName(IDirect3DRMMaterial2
*iface
, DWORD
*size
, char *name
)
148 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
150 TRACE("iface %p, size %p, name %p.\n", iface
, size
, name
);
152 return d3drm_object_get_class_name(&material
->obj
, size
, name
);
155 static HRESULT WINAPI
d3drm_material_SetPower(IDirect3DRMMaterial2
*iface
, D3DVALUE power
)
157 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
159 TRACE("iface %p, power %.8e.\n", iface
, power
);
161 material
->power
= power
;
166 static HRESULT WINAPI
d3drm_material_SetSpecular(IDirect3DRMMaterial2
*iface
,
167 D3DVALUE r
, D3DVALUE g
, D3DVALUE b
)
169 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
171 TRACE("iface %p, r %.8e, g %.8e, b %.8e.\n", iface
, r
, g
, b
);
173 material
->specular
.r
= r
;
174 material
->specular
.g
= g
;
175 material
->specular
.b
= b
;
180 static HRESULT WINAPI
d3drm_material_SetEmissive(IDirect3DRMMaterial2
*iface
,
181 D3DVALUE r
, D3DVALUE g
, D3DVALUE b
)
183 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
185 TRACE("iface %p, r %.8e, g %.8e, b %.8e.\n", iface
, r
, g
, b
);
187 material
->emissive
.r
= r
;
188 material
->emissive
.g
= g
;
189 material
->emissive
.b
= b
;
194 static D3DVALUE WINAPI
d3drm_material_GetPower(IDirect3DRMMaterial2
*iface
)
196 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
198 TRACE("iface %p.\n", iface
);
200 return material
->power
;
203 static HRESULT WINAPI
d3drm_material_GetSpecular(IDirect3DRMMaterial2
*iface
,
204 D3DVALUE
*r
, D3DVALUE
*g
, D3DVALUE
*b
)
206 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
208 TRACE("iface %p, r %p, g %p, b %p.\n", iface
, r
, g
, b
);
210 *r
= material
->specular
.r
;
211 *g
= material
->specular
.g
;
212 *b
= material
->specular
.b
;
217 static HRESULT WINAPI
d3drm_material_GetEmissive(IDirect3DRMMaterial2
*iface
,
218 D3DVALUE
*r
, D3DVALUE
*g
, D3DVALUE
*b
)
220 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
222 TRACE("iface %p, r %p, g %p, b %p.\n", iface
, r
, g
, b
);
224 *r
= material
->emissive
.r
;
225 *g
= material
->emissive
.g
;
226 *b
= material
->emissive
.b
;
231 static HRESULT WINAPI
d3drm_material_GetAmbient(IDirect3DRMMaterial2
*iface
,
232 D3DVALUE
*r
, D3DVALUE
*g
, D3DVALUE
*b
)
234 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
236 TRACE("iface %p, r %p, g %p, b %p.\n", iface
, r
, g
, b
);
238 *r
= material
->ambient
.r
;
239 *g
= material
->ambient
.g
;
240 *b
= material
->ambient
.b
;
245 static HRESULT WINAPI
d3drm_material_SetAmbient(IDirect3DRMMaterial2
*iface
,
246 D3DVALUE r
, D3DVALUE g
, D3DVALUE b
)
248 struct d3drm_material
*material
= impl_from_IDirect3DRMMaterial2(iface
);
250 TRACE("iface %p, r %.8e, g %.8e, b %.8e.\n", iface
, r
, g
, b
);
252 material
->ambient
.r
= r
;
253 material
->ambient
.g
= g
;
254 material
->ambient
.b
= b
;
259 static const struct IDirect3DRMMaterial2Vtbl d3drm_material_vtbl
=
261 d3drm_material_QueryInterface
,
262 d3drm_material_AddRef
,
263 d3drm_material_Release
,
264 d3drm_material_Clone
,
265 d3drm_material_AddDestroyCallback
,
266 d3drm_material_DeleteDestroyCallback
,
267 d3drm_material_SetAppData
,
268 d3drm_material_GetAppData
,
269 d3drm_material_SetName
,
270 d3drm_material_GetName
,
271 d3drm_material_GetClassName
,
272 d3drm_material_SetPower
,
273 d3drm_material_SetSpecular
,
274 d3drm_material_SetEmissive
,
275 d3drm_material_GetPower
,
276 d3drm_material_GetSpecular
,
277 d3drm_material_GetEmissive
,
278 d3drm_material_GetAmbient
,
279 d3drm_material_SetAmbient
,
282 HRESULT
d3drm_material_create(struct d3drm_material
**material
, IDirect3DRM
*d3drm
)
284 static const char classname
[] = "Material";
285 struct d3drm_material
*object
;
287 TRACE("material %p, d3drm %p.\n", material
, d3drm
);
289 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
290 return E_OUTOFMEMORY
;
292 object
->IDirect3DRMMaterial2_iface
.lpVtbl
= &d3drm_material_vtbl
;
294 object
->d3drm
= d3drm
;
295 IDirect3DRM_AddRef(object
->d3drm
);
297 object
->specular
.r
= 1.0f
;
298 object
->specular
.g
= 1.0f
;
299 object
->specular
.b
= 1.0f
;
301 d3drm_object_init(&object
->obj
, classname
);