xref: /reactos/dll/directx/wine/d3drm/light.c (revision 19b18ce2)
1 /*
2  * Implementation of IDirect3DRMLight Interface
3  *
4  * Copyright 2012 André Hentschel
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_light *impl_from_IDirect3DRMLight(IDirect3DRMLight *iface)
29 {
30     return CONTAINING_RECORD(iface, struct d3drm_light, IDirect3DRMLight_iface);
31 }
32 
33 static HRESULT WINAPI d3drm_light_QueryInterface(IDirect3DRMLight *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_IDirect3DRMLight)
38             || IsEqualGUID(riid, &IID_IDirect3DRMObject)
39             || IsEqualGUID(riid, &IID_IUnknown))
40     {
41         IDirect3DRMLight_AddRef(iface);
42         *out = iface;
43         return S_OK;
44     }
45 
46     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
47 
48     *out = NULL;
49     return E_NOINTERFACE;
50 }
51 
52 static ULONG WINAPI d3drm_light_AddRef(IDirect3DRMLight *iface)
53 {
54     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
55     ULONG refcount = InterlockedIncrement(&light->ref);
56 
57     TRACE("%p increasing refcount to %u.\n", iface, refcount);
58 
59     return refcount;
60 }
61 
62 static ULONG WINAPI d3drm_light_Release(IDirect3DRMLight *iface)
63 {
64     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
65     ULONG refcount = InterlockedDecrement(&light->ref);
66 
67     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
68 
69     if (!refcount)
70     {
71         d3drm_object_cleanup((IDirect3DRMObject *)iface, &light->obj);
72         IDirect3DRM_Release(light->d3drm);
73         heap_free(light);
74     }
75 
76     return refcount;
77 }
78 
79 static HRESULT WINAPI d3drm_light_Clone(IDirect3DRMLight *iface,
80         IUnknown *outer, REFIID iid, void **out)
81 {
82     FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface, outer, debugstr_guid(iid), out);
83 
84     return E_NOTIMPL;
85 }
86 
87 static HRESULT WINAPI d3drm_light_AddDestroyCallback(IDirect3DRMLight *iface,
88         D3DRMOBJECTCALLBACK cb, void *ctx)
89 {
90     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
91 
92     TRACE("iface %p, cb %p, ctx %p.\n", iface, cb, ctx);
93 
94     return d3drm_object_add_destroy_callback(&light->obj, cb, ctx);
95 }
96 
97 static HRESULT WINAPI d3drm_light_DeleteDestroyCallback(IDirect3DRMLight *iface,
98         D3DRMOBJECTCALLBACK cb, void *ctx)
99 {
100     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
101 
102     TRACE("iface %p, cb %p, ctx %p.\n", iface, cb, ctx);
103 
104     return d3drm_object_delete_destroy_callback(&light->obj, cb, ctx);
105 }
106 
107 static HRESULT WINAPI d3drm_light_SetAppData(IDirect3DRMLight *iface, DWORD data)
108 {
109     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
110 
111     TRACE("iface %p, data %#x.\n", iface, data);
112 
113     light->obj.appdata = data;
114 
115     return D3DRM_OK;
116 }
117 
118 static DWORD WINAPI d3drm_light_GetAppData(IDirect3DRMLight *iface)
119 {
120     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
121 
122     TRACE("iface %p.\n", iface);
123 
124     return light->obj.appdata;
125 }
126 
127 static HRESULT WINAPI d3drm_light_SetName(IDirect3DRMLight *iface, const char *name)
128 {
129     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
130 
131     TRACE("iface %p, name %s.\n", iface, debugstr_a(name));
132 
133     return d3drm_object_set_name(&light->obj, name);
134 }
135 
136 static HRESULT WINAPI d3drm_light_GetName(IDirect3DRMLight *iface, DWORD *size, char *name)
137 {
138     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
139 
140     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
141 
142     return d3drm_object_get_name(&light->obj, size, name);
143 }
144 
145 static HRESULT WINAPI d3drm_light_GetClassName(IDirect3DRMLight *iface, DWORD *size, char *name)
146 {
147     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
148 
149     TRACE("iface %p, size %p, name %p.\n", iface, size, name);
150 
151     return d3drm_object_get_class_name(&light->obj, size, name);
152 }
153 
154 static HRESULT WINAPI d3drm_light_SetType(IDirect3DRMLight *iface, D3DRMLIGHTTYPE type)
155 {
156     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
157 
158     TRACE("iface %p, type %#x.\n", iface, type);
159 
160     light->type = type;
161 
162     return D3DRM_OK;
163 }
164 
165 static HRESULT WINAPI d3drm_light_SetColor(IDirect3DRMLight *iface, D3DCOLOR color)
166 {
167     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
168 
169     TRACE("iface %p, color 0x%08x.\n", iface, color);
170 
171     light->color = color;
172 
173     return D3DRM_OK;
174 }
175 
176 static HRESULT WINAPI d3drm_light_SetColorRGB(IDirect3DRMLight *iface,
177         D3DVALUE red, D3DVALUE green, D3DVALUE blue)
178 {
179     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
180 
181     TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface, red, green, blue);
182 
183     d3drm_set_color(&light->color, red, green, blue, 1.0f);
184 
185     return D3DRM_OK;
186 }
187 
188 static HRESULT WINAPI d3drm_light_SetRange(IDirect3DRMLight *iface, D3DVALUE range)
189 {
190     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
191 
192     TRACE("iface %p, range %.8e.\n", iface, range);
193 
194     light->range = range;
195 
196     return D3DRM_OK;
197 }
198 
199 static HRESULT WINAPI d3drm_light_SetUmbra(IDirect3DRMLight *iface, D3DVALUE umbra)
200 {
201     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
202 
203     TRACE("iface %p, umbra %.8e.\n", iface, umbra);
204 
205     light->umbra = umbra;
206 
207     return D3DRM_OK;
208 }
209 
210 static HRESULT WINAPI d3drm_light_SetPenumbra(IDirect3DRMLight *iface, D3DVALUE penumbra)
211 {
212     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
213 
214     TRACE("iface %p, penumbra %.8e.\n", iface, penumbra);
215 
216     light->penumbra = penumbra;
217 
218     return D3DRM_OK;
219 }
220 
221 static HRESULT WINAPI d3drm_light_SetConstantAttenuation(IDirect3DRMLight *iface, D3DVALUE attenuation)
222 {
223     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
224 
225     TRACE("iface %p, attenuation %.8e.\n", iface, attenuation);
226 
227     light->cattenuation = attenuation;
228 
229     return D3DRM_OK;
230 }
231 
232 static HRESULT WINAPI d3drm_light_SetLinearAttenuation(IDirect3DRMLight *iface, D3DVALUE attenuation)
233 {
234     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
235 
236     TRACE("iface %p, attenuation %.8e.\n", iface, attenuation);
237 
238     light->lattenuation = attenuation;
239 
240     return D3DRM_OK;
241 }
242 
243 static HRESULT WINAPI d3drm_light_SetQuadraticAttenuation(IDirect3DRMLight *iface, D3DVALUE attenuation)
244 {
245     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
246 
247     TRACE("iface %p, attenuation %.8e.\n", iface, attenuation);
248 
249     light->qattenuation = attenuation;
250 
251     return D3DRM_OK;
252 }
253 
254 static D3DVALUE WINAPI d3drm_light_GetRange(IDirect3DRMLight *iface)
255 {
256     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
257 
258     TRACE("iface %p.\n", iface);
259 
260     return light->range;
261 }
262 
263 static D3DVALUE WINAPI d3drm_light_GetUmbra(IDirect3DRMLight *iface)
264 {
265     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
266 
267     TRACE("iface %p.\n", light);
268 
269     return light->umbra;
270 }
271 
272 static D3DVALUE WINAPI d3drm_light_GetPenumbra(IDirect3DRMLight *iface)
273 {
274     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
275 
276     TRACE("iface %p.\n", iface);
277 
278     return light->penumbra;
279 }
280 
281 static D3DVALUE WINAPI d3drm_light_GetConstantAttenuation(IDirect3DRMLight *iface)
282 {
283     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
284 
285     TRACE("iface %p.\n", iface);
286 
287     return light->cattenuation;
288 }
289 
290 static D3DVALUE WINAPI d3drm_light_GetLinearAttenuation(IDirect3DRMLight *iface)
291 {
292     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
293 
294     TRACE("iface %p.\n", iface);
295 
296     return light->lattenuation;
297 }
298 
299 static D3DVALUE WINAPI d3drm_light_GetQuadraticAttenuation(IDirect3DRMLight *iface)
300 {
301     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
302 
303     TRACE("iface %p.\n", iface);
304 
305     return light->qattenuation;
306 }
307 
308 static D3DCOLOR WINAPI d3drm_light_GetColor(IDirect3DRMLight *iface)
309 {
310     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
311 
312     TRACE("iface %p.\n", iface);
313 
314     return light->color;
315 }
316 
317 static D3DRMLIGHTTYPE WINAPI d3drm_light_GetType(IDirect3DRMLight *iface)
318 {
319     struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
320 
321     TRACE("iface %p.\n", iface);
322 
323     return light->type;
324 }
325 
326 static HRESULT WINAPI d3drm_light_SetEnableFrame(IDirect3DRMLight *iface, IDirect3DRMFrame *frame)
327 {
328     FIXME("iface %p, frame %p stub!\n", iface, frame);
329 
330     return E_NOTIMPL;
331 }
332 
333 static HRESULT WINAPI d3drm_light_GetEnableFrame(IDirect3DRMLight *iface, IDirect3DRMFrame **frame)
334 {
335     FIXME("iface %p, frame %p stub!\n", iface, frame);
336 
337     return E_NOTIMPL;
338 }
339 
340 static const struct IDirect3DRMLightVtbl d3drm_light_vtbl =
341 {
342     d3drm_light_QueryInterface,
343     d3drm_light_AddRef,
344     d3drm_light_Release,
345     d3drm_light_Clone,
346     d3drm_light_AddDestroyCallback,
347     d3drm_light_DeleteDestroyCallback,
348     d3drm_light_SetAppData,
349     d3drm_light_GetAppData,
350     d3drm_light_SetName,
351     d3drm_light_GetName,
352     d3drm_light_GetClassName,
353     d3drm_light_SetType,
354     d3drm_light_SetColor,
355     d3drm_light_SetColorRGB,
356     d3drm_light_SetRange,
357     d3drm_light_SetUmbra,
358     d3drm_light_SetPenumbra,
359     d3drm_light_SetConstantAttenuation,
360     d3drm_light_SetLinearAttenuation,
361     d3drm_light_SetQuadraticAttenuation,
362     d3drm_light_GetRange,
363     d3drm_light_GetUmbra,
364     d3drm_light_GetPenumbra,
365     d3drm_light_GetConstantAttenuation,
366     d3drm_light_GetLinearAttenuation,
367     d3drm_light_GetQuadraticAttenuation,
368     d3drm_light_GetColor,
369     d3drm_light_GetType,
370     d3drm_light_SetEnableFrame,
371     d3drm_light_GetEnableFrame,
372 };
373 
374 HRESULT d3drm_light_create(struct d3drm_light **light, IDirect3DRM *d3drm)
375 {
376     static const char classname[] = "Light";
377     struct d3drm_light *object;
378 
379     TRACE("light %p.\n", light);
380 
381     if (!(object = heap_alloc_zero(sizeof(*object))))
382         return E_OUTOFMEMORY;
383 
384     object->IDirect3DRMLight_iface.lpVtbl = &d3drm_light_vtbl;
385     object->ref = 1;
386     object->d3drm = d3drm;
387     IDirect3DRM_AddRef(object->d3drm);
388 
389     d3drm_object_init(&object->obj, classname);
390 
391     *light = object;
392 
393     return S_OK;
394 }
395