cmd: Convert wcmd_for to use WCMD_parameter.
[wine] / dlls / d3drm / light.c
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 "wine/debug.h"
22
23 #define COBJMACROS
24
25 #include "winbase.h"
26 #include "wingdi.h"
27
28 #include "d3drm_private.h"
29
30 WINE_DEFAULT_DEBUG_CHANNEL(d3drm);
31
32 typedef struct {
33     IDirect3DRMLight IDirect3DRMLight_iface;
34     LONG ref;
35     D3DRMLIGHTTYPE type;
36     D3DCOLOR color;
37     D3DVALUE range;
38     D3DVALUE cattenuation;
39     D3DVALUE lattenuation;
40     D3DVALUE qattenuation;
41     D3DVALUE umbra;
42     D3DVALUE penumbra;
43 } IDirect3DRMLightImpl;
44
45 static inline IDirect3DRMLightImpl *impl_from_IDirect3DRMLight(IDirect3DRMLight *iface)
46 {
47     return CONTAINING_RECORD(iface, IDirect3DRMLightImpl, IDirect3DRMLight_iface);
48 }
49
50 /*** IUnknown methods ***/
51 static HRESULT WINAPI IDirect3DRMLightImpl_QueryInterface(IDirect3DRMLight* iface,
52                                                            REFIID riid, void** object)
53 {
54     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
55
56     TRACE("(%p/%p)->(%s, %p)\n", iface, This, debugstr_guid(riid), object);
57
58     *object = NULL;
59
60     if(IsEqualGUID(riid, &IID_IUnknown) ||
61        IsEqualGUID(riid, &IID_IDirect3DRMLight))
62     {
63         *object = &This->IDirect3DRMLight_iface;
64     }
65     else
66     {
67         FIXME("interface %s not implemented\n", debugstr_guid(riid));
68         return E_NOINTERFACE;
69     }
70
71     IDirect3DRMLight_AddRef(iface);
72     return S_OK;
73 }
74
75 static ULONG WINAPI IDirect3DRMLightImpl_AddRef(IDirect3DRMLight* iface)
76 {
77     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
78     ULONG ref = InterlockedIncrement(&This->ref);
79
80     TRACE("(%p)->(): new ref = %d\n", iface, ref);
81
82     return ref;
83 }
84
85 static ULONG WINAPI IDirect3DRMLightImpl_Release(IDirect3DRMLight* iface)
86 {
87     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
88     ULONG ref = InterlockedDecrement(&This->ref);
89
90     TRACE("(%p)->(): new ref = %d\n", iface, ref);
91
92     if (!ref)
93         HeapFree(GetProcessHeap(), 0, This);
94
95     return ref;
96 }
97
98 /*** IDirect3DRMObject methods ***/
99 static HRESULT WINAPI IDirect3DRMLightImpl_Clone(IDirect3DRMLight* iface,
100                                                   LPUNKNOWN unkwn, REFIID riid,
101                                                   LPVOID* object)
102 {
103     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
104
105     FIXME("(%p/%p)->(%p, %s, %p): stub\n", iface, This, unkwn, debugstr_guid(riid), object);
106
107     return E_NOTIMPL;
108 }
109
110 static HRESULT WINAPI IDirect3DRMLightImpl_AddDestroyCallback(IDirect3DRMLight* iface,
111                                                                D3DRMOBJECTCALLBACK cb,
112                                                                LPVOID argument)
113 {
114     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
115
116     FIXME("(%p/%p)->(%p, %p): stub\n", iface, This, cb, argument);
117
118     return E_NOTIMPL;
119 }
120
121 static HRESULT WINAPI IDirect3DRMLightImpl_DeleteDestroyCallback(IDirect3DRMLight* iface,
122                                                                   D3DRMOBJECTCALLBACK cb,
123                                                                   LPVOID argument)
124 {
125     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
126
127     FIXME("(%p/%p)->(%p, %p): stub\n", iface, This, cb, argument);
128
129     return E_NOTIMPL;
130 }
131
132 static HRESULT WINAPI IDirect3DRMLightImpl_SetAppData(IDirect3DRMLight* iface,
133                                                        DWORD data)
134 {
135     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
136
137     FIXME("(%p/%p)->(%u): stub\n", iface, This, data);
138
139     return E_NOTIMPL;
140 }
141
142 static DWORD WINAPI IDirect3DRMLightImpl_GetAppData(IDirect3DRMLight* iface)
143 {
144     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
145
146     FIXME("(%p/%p)->(): stub\n", iface, This);
147
148     return 0;
149 }
150
151 static HRESULT WINAPI IDirect3DRMLightImpl_SetName(IDirect3DRMLight* iface, LPCSTR name)
152 {
153     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
154
155     FIXME("(%p/%p)->(%s): stub\n", iface, This, name);
156
157     return E_NOTIMPL;
158 }
159
160 static HRESULT WINAPI IDirect3DRMLightImpl_GetName(IDirect3DRMLight* iface,
161                                                     LPDWORD size, LPSTR name)
162 {
163     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
164
165     FIXME("(%p/%p)->(%p, %p): stub\n", iface, This, size, name);
166
167     return E_NOTIMPL;
168 }
169
170 static HRESULT WINAPI IDirect3DRMLightImpl_GetClassName(IDirect3DRMLight* iface,
171                                                          LPDWORD size, LPSTR name)
172 {
173     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
174
175     TRACE("(%p/%p)->(%p, %p)\n", iface, This, size, name);
176
177     if (!size || *size < strlen("Light") || !name)
178         return E_INVALIDARG;
179
180     strcpy(name, "Light");
181     *size = sizeof("Light");
182
183     return D3DRM_OK;
184 }
185
186 /*** IDirect3DRMLight methods ***/
187 static HRESULT WINAPI IDirect3DRMLightImpl_SetType(IDirect3DRMLight* iface, D3DRMLIGHTTYPE type)
188 {
189     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
190
191     TRACE("(%p/%p)->(%u)\n", iface, This, type);
192
193     This->type = type;
194
195     return D3DRM_OK;
196 }
197
198 static HRESULT WINAPI IDirect3DRMLightImpl_SetColor(IDirect3DRMLight* iface, D3DCOLOR color)
199 {
200     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
201
202     TRACE("(%p/%p)->(%u)\n", iface, This, color);
203
204     This->color = color;
205
206     return D3DRM_OK;
207 }
208
209 static HRESULT WINAPI IDirect3DRMLightImpl_SetColorRGB(IDirect3DRMLight* iface,
210                                                          D3DVALUE red, D3DVALUE green, D3DVALUE blue)
211 {
212     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
213
214     TRACE("(%p/%p)->(%f,%f,%f)\n", iface, This, red, green, blue);
215
216     This->color = D3DCOLOR_ARGB(0xff, (BYTE)(red   * 255.0f),
217                                       (BYTE)(green * 255.0f),
218                                       (BYTE)(blue  * 255.0f));
219
220     return D3DRM_OK;
221 }
222
223 static HRESULT WINAPI IDirect3DRMLightImpl_SetRange(IDirect3DRMLight* iface, D3DVALUE range)
224 {
225     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
226
227     TRACE("(%p/%p)->(%f)\n", iface, This, range);
228
229     This->range = range;
230
231     return D3DRM_OK;
232 }
233
234 static HRESULT WINAPI IDirect3DRMLightImpl_SetUmbra(IDirect3DRMLight* iface, D3DVALUE umbra)
235 {
236     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
237
238     TRACE("(%p/%p)->(%f)\n", iface, This, umbra);
239
240     This->umbra = umbra;
241
242     return D3DRM_OK;
243 }
244
245 static HRESULT WINAPI IDirect3DRMLightImpl_SetPenumbra(IDirect3DRMLight* iface, D3DVALUE penumbra)
246 {
247     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
248
249     TRACE("(%p/%p)->(%f)\n", iface, This, penumbra);
250
251     This->penumbra = penumbra;
252
253     return D3DRM_OK;
254 }
255
256 static HRESULT WINAPI IDirect3DRMLightImpl_SetConstantAttenuation(IDirect3DRMLight* iface,
257                                                                     D3DVALUE cattenuation)
258 {
259     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
260
261     TRACE("(%p/%p)->(%f)\n", iface, This, cattenuation);
262
263     This->cattenuation = cattenuation;
264
265     return D3DRM_OK;
266 }
267
268 static HRESULT WINAPI IDirect3DRMLightImpl_SetLinearAttenuation(IDirect3DRMLight* iface,
269                                                                   D3DVALUE lattenuation)
270 {
271     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
272
273     TRACE("(%p/%p)->(%f)\n", iface, This, lattenuation);
274
275     This->lattenuation = lattenuation;
276
277     return D3DRM_OK;
278 }
279
280 static HRESULT WINAPI IDirect3DRMLightImpl_SetQuadraticAttenuation(IDirect3DRMLight* iface,
281                                                                      D3DVALUE qattenuation)
282 {
283     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
284
285     TRACE("(%p/%p)->(%f)\n", iface, This, qattenuation);
286
287     This->qattenuation = qattenuation;
288
289     return D3DRM_OK;
290 }
291
292 static D3DVALUE WINAPI IDirect3DRMLightImpl_GetRange(IDirect3DRMLight* iface)
293 {
294     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
295
296     TRACE("(%p/%p)->()\n", iface, This);
297
298     return This->range;
299 }
300
301 static D3DVALUE WINAPI IDirect3DRMLightImpl_GetUmbra(IDirect3DRMLight* iface)
302 {
303     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
304
305     TRACE("(%p/%p)->()\n", iface, This);
306
307     return This->umbra;
308 }
309
310 static D3DVALUE WINAPI IDirect3DRMLightImpl_GetPenumbra(IDirect3DRMLight* iface)
311 {
312     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
313
314     TRACE("(%p/%p)->()\n", iface, This);
315
316     return This->penumbra;
317 }
318
319 static D3DVALUE WINAPI IDirect3DRMLightImpl_GetConstantAttenuation(IDirect3DRMLight* iface)
320 {
321     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
322
323     TRACE("(%p/%p)->()\n", iface, This);
324
325     return This->cattenuation;
326 }
327
328 static D3DVALUE WINAPI IDirect3DRMLightImpl_GetLinearAttenuation(IDirect3DRMLight* iface)
329 {
330     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
331
332     TRACE("(%p/%p)->()\n", iface, This);
333
334     return This->lattenuation;
335 }
336
337 static D3DVALUE WINAPI IDirect3DRMLightImpl_GetQuadraticAttenuation(IDirect3DRMLight* iface)
338 {
339     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
340
341     TRACE("(%p/%p)->()\n", iface, This);
342
343     return This->qattenuation;
344 }
345
346 static D3DCOLOR WINAPI IDirect3DRMLightImpl_GetColor(IDirect3DRMLight* iface)
347 {
348     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
349
350     TRACE("(%p/%p)->()\n", iface, This);
351
352     return This->color;
353 }
354
355 static D3DRMLIGHTTYPE WINAPI IDirect3DRMLightImpl_GetType(IDirect3DRMLight* iface)
356 {
357     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
358
359     TRACE("(%p/%p)->()\n", iface, This);
360
361     return This->type;
362 }
363
364 static HRESULT WINAPI IDirect3DRMLightImpl_SetEnableFrame(IDirect3DRMLight* iface,
365                                                             LPDIRECT3DRMFRAME frame)
366 {
367     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
368
369     FIXME("(%p/%p)->(%p): stub\n", iface, This, frame);
370
371     return E_NOTIMPL;
372 }
373
374 static HRESULT WINAPI IDirect3DRMLightImpl_GetEnableFrame(IDirect3DRMLight* iface,
375                                                             LPDIRECT3DRMFRAME* frame)
376 {
377     IDirect3DRMLightImpl *This = impl_from_IDirect3DRMLight(iface);
378
379     FIXME("(%p/%p)->(%p): stub\n", iface, This, frame);
380
381     return E_NOTIMPL;
382 }
383
384 static const struct IDirect3DRMLightVtbl Direct3DRMLight_Vtbl =
385 {
386     /*** IUnknown methods ***/
387     IDirect3DRMLightImpl_QueryInterface,
388     IDirect3DRMLightImpl_AddRef,
389     IDirect3DRMLightImpl_Release,
390     /*** IDirect3DRMObject methods ***/
391     IDirect3DRMLightImpl_Clone,
392     IDirect3DRMLightImpl_AddDestroyCallback,
393     IDirect3DRMLightImpl_DeleteDestroyCallback,
394     IDirect3DRMLightImpl_SetAppData,
395     IDirect3DRMLightImpl_GetAppData,
396     IDirect3DRMLightImpl_SetName,
397     IDirect3DRMLightImpl_GetName,
398     IDirect3DRMLightImpl_GetClassName,
399     /*** IDirect3DRMLight methods ***/
400     IDirect3DRMLightImpl_SetType,
401     IDirect3DRMLightImpl_SetColor,
402     IDirect3DRMLightImpl_SetColorRGB,
403     IDirect3DRMLightImpl_SetRange,
404     IDirect3DRMLightImpl_SetUmbra,
405     IDirect3DRMLightImpl_SetPenumbra,
406     IDirect3DRMLightImpl_SetConstantAttenuation,
407     IDirect3DRMLightImpl_SetLinearAttenuation,
408     IDirect3DRMLightImpl_SetQuadraticAttenuation,
409     IDirect3DRMLightImpl_GetRange,
410     IDirect3DRMLightImpl_GetUmbra,
411     IDirect3DRMLightImpl_GetPenumbra,
412     IDirect3DRMLightImpl_GetConstantAttenuation,
413     IDirect3DRMLightImpl_GetLinearAttenuation,
414     IDirect3DRMLightImpl_GetQuadraticAttenuation,
415     IDirect3DRMLightImpl_GetColor,
416     IDirect3DRMLightImpl_GetType,
417     IDirect3DRMLightImpl_SetEnableFrame,
418     IDirect3DRMLightImpl_GetEnableFrame
419 };
420
421 HRESULT Direct3DRMLight_create(IUnknown** ppObj)
422 {
423     IDirect3DRMLightImpl* object;
424
425     TRACE("(%p)\n", ppObj);
426
427     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DRMLightImpl));
428     if (!object)
429     {
430         ERR("Out of memory\n");
431         return E_OUTOFMEMORY;
432     }
433
434     object->IDirect3DRMLight_iface.lpVtbl = &Direct3DRMLight_Vtbl;
435     object->ref = 1;
436
437     *ppObj = (IUnknown*)&object->IDirect3DRMLight_iface;
438
439     return S_OK;
440 }