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