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