xref: /reactos/dll/directx/wine/d3drm/material.c (revision fb5d5ecd)
1 /*
2  * Implementation of IDirect3DRMMaterial2 interface
3  *
4  * Copyright 2012 Christian Costa
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include "config.h"
22 #include "wine/port.h"
23 
24 #include "d3drm_private.h"
25 
26 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
27 
28 static inline struct d3drm_material *impl_from_IDirect3DRMMaterial2(IDirect3DRMMaterial2 *iface)
29 {
30     return CONTAINING_RECORD(iface, struct d3drm_material, IDirect3DRMMaterial2_iface);
31 }
32 
33 static HRESULT WINAPI d3drm_material_QueryInterface(IDirect3DRMMaterial2 *iface, REFIID riid, void **out)
34 {
35     TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
36 
37     if (IsEqualGUID(riid, &IID_IDirect3DRMMaterial2)
38             || IsEqualGUID(riid, &IID_IDirect3DRMMaterial)
39             || IsEqualGUID(riid, &IID_IDirect3DRMObject)
40             || IsEqualGUID(riid, &IID_IUnknown))
41     {
42         IDirect3DRMMaterial2_AddRef(iface);
43         *out = iface;
44         return S_OK;
45     }
46 
47     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
48 
49     *out = NULL;
50     return E_NOINTERFACE;
51 }
52 
53 static ULONG WINAPI d3drm_material_AddRef(IDirect3DRMMaterial2 *iface)
54 {
55     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
56     ULONG refcount = InterlockedIncrement(&material->ref);
57 
58     TRACE("%p increasing refcount to %u.\n", iface, refcount);
59 
60     return refcount;
61 }
62 
63 static ULONG WINAPI d3drm_material_Release(IDirect3DRMMaterial2 *iface)
64 {
65     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
66     ULONG refcount = InterlockedDecrement(&material->ref);
67 
68     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
69 
70     if (!refcount)
71     {
72         d3drm_object_cleanup((IDirect3DRMObject *)iface, &material->obj);
73         IDirect3DRM_Release(material->d3drm);
74         heap_free(material);
75     }
76 
77     return refcount;
78 }
79 
80 static HRESULT WINAPI d3drm_material_Clone(IDirect3DRMMaterial2 *iface,
81         IUnknown *outer, REFIID iid, void **out)
82 {
83     FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface, outer, debugstr_guid(iid), out);
84 
85     return E_NOTIMPL;
86 }
87 
88 static HRESULT WINAPI d3drm_material_AddDestroyCallback(IDirect3DRMMaterial2 *iface,
89         D3DRMOBJECTCALLBACK cb, void *ctx)
90 {
91     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
92 
93     TRACE("iface %p, cb %p, ctx %p.\n", iface, cb, ctx);
94 
95     return d3drm_object_add_destroy_callback(&material->obj, cb, ctx);
96 }
97 
98 static HRESULT WINAPI d3drm_material_DeleteDestroyCallback(IDirect3DRMMaterial2 *iface,
99         D3DRMOBJECTCALLBACK cb, void *ctx)
100 {
101     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
102 
103     TRACE("iface %p, cb %p, ctx %p.\n", iface, cb, ctx);
104 
105     return d3drm_object_delete_destroy_callback(&material->obj, cb, ctx);
106 }
107 
108 static HRESULT WINAPI d3drm_material_SetAppData(IDirect3DRMMaterial2 *iface, DWORD data)
109 {
110     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
111 
112     TRACE("iface %p, data %#x.\n", iface, data);
113 
114     material->obj.appdata = data;
115 
116     return D3DRM_OK;
117 }
118 
119 static DWORD WINAPI d3drm_material_GetAppData(IDirect3DRMMaterial2 *iface)
120 {
121     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
122 
123     TRACE("iface %p.\n", iface);
124 
125     return material->obj.appdata;
126 }
127 
128 static HRESULT WINAPI d3drm_material_SetName(IDirect3DRMMaterial2 *iface, const char *name)
129 {
130     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
131 
132     TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
133 
134     return d3drm_object_set_name(&material->obj, name);
135 }
136 
137 static HRESULT WINAPI d3drm_material_GetName(IDirect3DRMMaterial2 *iface, DWORD *size, char *name)
138 {
139     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
140 
141     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
142 
143     return d3drm_object_get_name(&material->obj, size, name);
144 }
145 
146 static HRESULT WINAPI d3drm_material_GetClassName(IDirect3DRMMaterial2 *iface, DWORD *size, char *name)
147 {
148     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
149 
150     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
151 
152     return d3drm_object_get_class_name(&material->obj, size, name);
153 }
154 
155 static HRESULT WINAPI d3drm_material_SetPower(IDirect3DRMMaterial2 *iface, D3DVALUE power)
156 {
157     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
158 
159     TRACE("iface %p, power %.8e.\n", iface, power);
160 
161     material->power = power;
162 
163     return D3DRM_OK;
164 }
165 
166 static HRESULT WINAPI d3drm_material_SetSpecular(IDirect3DRMMaterial2 *iface,
167         D3DVALUE r, D3DVALUE g, D3DVALUE b)
168 {
169     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
170 
171     TRACE("iface %p, r %.8e, g %.8e, b %.8e.\n", iface, r, g, b);
172 
173     material->specular.r = r;
174     material->specular.g = g;
175     material->specular.b = b;
176 
177     return D3DRM_OK;
178 }
179 
180 static HRESULT WINAPI d3drm_material_SetEmissive(IDirect3DRMMaterial2 *iface,
181         D3DVALUE r, D3DVALUE g, D3DVALUE b)
182 {
183     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
184 
185     TRACE("iface %p, r %.8e, g %.8e, b %.8e.\n", iface, r, g, b);
186 
187     material->emissive.r = r;
188     material->emissive.g = g;
189     material->emissive.b = b;
190 
191     return D3DRM_OK;
192 }
193 
194 static D3DVALUE WINAPI d3drm_material_GetPower(IDirect3DRMMaterial2 *iface)
195 {
196     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
197 
198     TRACE("iface %p.\n", iface);
199 
200     return material->power;
201 }
202 
203 static HRESULT WINAPI d3drm_material_GetSpecular(IDirect3DRMMaterial2 *iface,
204         D3DVALUE *r, D3DVALUE *g, D3DVALUE *b)
205 {
206     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
207 
208     TRACE("iface %p, r %p, g %p, b %p.\n", iface, r, g, b);
209 
210     *r = material->specular.r;
211     *g = material->specular.g;
212     *b = material->specular.b;
213 
214     return D3DRM_OK;
215 }
216 
217 static HRESULT WINAPI d3drm_material_GetEmissive(IDirect3DRMMaterial2 *iface,
218         D3DVALUE *r, D3DVALUE *g, D3DVALUE *b)
219 {
220     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
221 
222     TRACE("iface %p, r %p, g %p, b %p.\n", iface, r, g, b);
223 
224     *r = material->emissive.r;
225     *g = material->emissive.g;
226     *b = material->emissive.b;
227 
228     return D3DRM_OK;
229 }
230 
231 static HRESULT WINAPI d3drm_material_GetAmbient(IDirect3DRMMaterial2 *iface,
232         D3DVALUE *r, D3DVALUE *g, D3DVALUE *b)
233 {
234     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
235 
236     TRACE("iface %p, r %p, g %p, b %p.\n", iface, r, g, b);
237 
238     *r = material->ambient.r;
239     *g = material->ambient.g;
240     *b = material->ambient.b;
241 
242     return D3DRM_OK;
243 }
244 
245 static HRESULT WINAPI d3drm_material_SetAmbient(IDirect3DRMMaterial2 *iface,
246         D3DVALUE r, D3DVALUE g, D3DVALUE b)
247 {
248     struct d3drm_material *material = impl_from_IDirect3DRMMaterial2(iface);
249 
250     TRACE("iface %p, r %.8e, g %.8e, b %.8e.\n", iface, r, g, b);
251 
252     material->ambient.r = r;
253     material->ambient.g = g;
254     material->ambient.b = b;
255 
256     return D3DRM_OK;
257 }
258 
259 static const struct IDirect3DRMMaterial2Vtbl d3drm_material_vtbl =
260 {
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,
280 };
281 
282 HRESULT d3drm_material_create(struct d3drm_material **material, IDirect3DRM *d3drm)
283 {
284     static const char classname[] = "Material";
285     struct d3drm_material *object;
286 
287     TRACE("material %p, d3drm %p.\n", material, d3drm);
288 
289     if (!(object = heap_alloc_zero(sizeof(*object))))
290         return E_OUTOFMEMORY;
291 
292     object->IDirect3DRMMaterial2_iface.lpVtbl = &d3drm_material_vtbl;
293     object->ref = 1;
294     object->d3drm = d3drm;
295     IDirect3DRM_AddRef(object->d3drm);
296 
297     object->specular.r = 1.0f;
298     object->specular.g = 1.0f;
299     object->specular.b = 1.0f;
300 
301     d3drm_object_init(&object->obj, classname);
302 
303     *material = object;
304 
305     return S_OK;
306 }
307