light.c 9.99 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
 * Implementation of IDirect3DRMLight Interface
 *
 * Copyright 2012 André Hentschel
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

#include "wine/debug.h"

#define COBJMACROS

#include "winbase.h"
#include "wingdi.h"

#include "d3drm_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(d3drm);

32 33
struct d3drm_light
{
34 35
    IDirect3DRMLight IDirect3DRMLight_iface;
    LONG ref;
36
    D3DRMLIGHTTYPE type;
37
    D3DCOLOR color;
38
    D3DVALUE range;
39
    D3DVALUE cattenuation;
40
    D3DVALUE lattenuation;
41
    D3DVALUE qattenuation;
42
    D3DVALUE umbra;
43
    D3DVALUE penumbra;
44
};
45

46
static inline struct d3drm_light *impl_from_IDirect3DRMLight(IDirect3DRMLight *iface)
47
{
48
    return CONTAINING_RECORD(iface, struct d3drm_light, IDirect3DRMLight_iface);
49 50
}

51
static HRESULT WINAPI d3drm_light_QueryInterface(IDirect3DRMLight *iface, REFIID riid, void **out)
52
{
53
    TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
54

55 56
    if (IsEqualGUID(riid, &IID_IDirect3DRMLight)
            || IsEqualGUID(riid, &IID_IUnknown))
57
    {
58 59 60
        IDirect3DRMLight_AddRef(iface);
        *out = iface;
        return S_OK;
61 62
    }

63 64 65 66
    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));

    *out = NULL;
    return E_NOINTERFACE;
67 68
}

69
static ULONG WINAPI d3drm_light_AddRef(IDirect3DRMLight *iface)
70
{
71 72
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
    ULONG refcount = InterlockedIncrement(&light->ref);
73

74
    TRACE("%p increasing refcount to %u.\n", iface, refcount);
75

76
    return refcount;
77 78
}

79
static ULONG WINAPI d3drm_light_Release(IDirect3DRMLight *iface)
80
{
81 82
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
    ULONG refcount = InterlockedDecrement(&light->ref);
83

84
    TRACE("%p decreasing refcount to %u.\n", iface, refcount);
85

86 87
    if (!refcount)
        HeapFree(GetProcessHeap(), 0, light);
88

89
    return refcount;
90 91
}

92
static HRESULT WINAPI d3drm_light_Clone(IDirect3DRMLight *iface,
Henri Verbeet's avatar
Henri Verbeet committed
93
        IUnknown *outer, REFIID iid, void **out)
94
{
Henri Verbeet's avatar
Henri Verbeet committed
95
    FIXME("iface %p, outer %p, iid %s, out %p stub!\n", iface, outer, debugstr_guid(iid), out);
96 97 98 99

    return E_NOTIMPL;
}

100
static HRESULT WINAPI d3drm_light_AddDestroyCallback(IDirect3DRMLight *iface,
Henri Verbeet's avatar
Henri Verbeet committed
101
        D3DRMOBJECTCALLBACK cb, void *ctx)
102
{
Henri Verbeet's avatar
Henri Verbeet committed
103
    FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
104 105 106 107

    return E_NOTIMPL;
}

108
static HRESULT WINAPI d3drm_light_DeleteDestroyCallback(IDirect3DRMLight *iface,
Henri Verbeet's avatar
Henri Verbeet committed
109
        D3DRMOBJECTCALLBACK cb, void *ctx)
110
{
Henri Verbeet's avatar
Henri Verbeet committed
111
    FIXME("iface %p, cb %p, ctx %p stub!\n", iface, cb, ctx);
112 113 114 115

    return E_NOTIMPL;
}

116
static HRESULT WINAPI d3drm_light_SetAppData(IDirect3DRMLight *iface, DWORD data)
117
{
118
    FIXME("iface %p, data %#x stub!\n", iface, data);
119 120 121 122

    return E_NOTIMPL;
}

123
static DWORD WINAPI d3drm_light_GetAppData(IDirect3DRMLight *iface)
124
{
125
    FIXME("iface %p stub!\n", iface);
126 127 128 129

    return 0;
}

130
static HRESULT WINAPI d3drm_light_SetName(IDirect3DRMLight *iface, const char *name)
131
{
Henri Verbeet's avatar
Henri Verbeet committed
132
    FIXME("iface %p, name %s stub!\n", iface, debugstr_a(name));
133 134 135 136

    return E_NOTIMPL;
}

137
static HRESULT WINAPI d3drm_light_GetName(IDirect3DRMLight *iface, DWORD *size, char *name)
138
{
Henri Verbeet's avatar
Henri Verbeet committed
139
    FIXME("iface %p, size %p, name %p stub!\n", iface, size, name);
140 141 142 143

    return E_NOTIMPL;
}

144
static HRESULT WINAPI d3drm_light_GetClassName(IDirect3DRMLight *iface, DWORD *size, char *name)
145
{
Henri Verbeet's avatar
Henri Verbeet committed
146
    TRACE("iface %p, size %p, name %p.\n", iface, size, name);
147

148 149 150 151 152 153 154
    if (!size || *size < strlen("Light") || !name)
        return E_INVALIDARG;

    strcpy(name, "Light");
    *size = sizeof("Light");

    return D3DRM_OK;
155 156
}

157
static HRESULT WINAPI d3drm_light_SetType(IDirect3DRMLight *iface, D3DRMLIGHTTYPE type)
158
{
159
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
160

161
    TRACE("iface %p, type %#x.\n", iface, type);
162

163
    light->type = type;
164 165

    return D3DRM_OK;
166 167
}

168
static HRESULT WINAPI d3drm_light_SetColor(IDirect3DRMLight *iface, D3DCOLOR color)
169
{
170
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
171

172
    TRACE("iface %p, color 0x%08x.\n", iface, color);
173

174
    light->color = color;
175 176

    return D3DRM_OK;
177 178
}

179 180
static HRESULT WINAPI d3drm_light_SetColorRGB(IDirect3DRMLight *iface,
        D3DVALUE red, D3DVALUE green, D3DVALUE blue)
181
{
182
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
183

184
    TRACE("iface %p, red %.8e, green %.8e, blue %.8e.\n", iface, red, green, blue);
185

186
    light->color = RGBA_MAKE((BYTE)(red * 255.0f), (BYTE)(green * 255.0f), (BYTE)(blue * 255.0f), 0xff);
187 188

    return D3DRM_OK;
189 190
}

191
static HRESULT WINAPI d3drm_light_SetRange(IDirect3DRMLight *iface, D3DVALUE range)
192
{
193
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
194

195
    TRACE("iface %p, range %.8e.\n", iface, range);
196

197
    light->range = range;
198 199

    return D3DRM_OK;
200 201
}

202
static HRESULT WINAPI d3drm_light_SetUmbra(IDirect3DRMLight *iface, D3DVALUE umbra)
203
{
204
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
205

206
    TRACE("iface %p, umbra %.8e.\n", iface, umbra);
207

208
    light->umbra = umbra;
209 210

    return D3DRM_OK;
211 212
}

213
static HRESULT WINAPI d3drm_light_SetPenumbra(IDirect3DRMLight *iface, D3DVALUE penumbra)
214
{
215
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
216

217
    TRACE("iface %p, penumbra %.8e.\n", iface, penumbra);
218

219
    light->penumbra = penumbra;
220 221

    return D3DRM_OK;
222 223
}

224
static HRESULT WINAPI d3drm_light_SetConstantAttenuation(IDirect3DRMLight *iface, D3DVALUE attenuation)
225
{
226
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
227

228
    TRACE("iface %p, attenuation %.8e.\n", iface, attenuation);
229

230
    light->cattenuation = attenuation;
231 232

    return D3DRM_OK;
233 234
}

235
static HRESULT WINAPI d3drm_light_SetLinearAttenuation(IDirect3DRMLight *iface, D3DVALUE attenuation)
236
{
237
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
238

239
    TRACE("iface %p, attenuation %.8e.\n", iface, attenuation);
240

241
    light->lattenuation = attenuation;
242 243

    return D3DRM_OK;
244 245
}

246
static HRESULT WINAPI d3drm_light_SetQuadraticAttenuation(IDirect3DRMLight *iface, D3DVALUE attenuation)
247
{
248
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
249

250
    TRACE("iface %p, attenuation %.8e.\n", iface, attenuation);
251

252
    light->qattenuation = attenuation;
253 254

    return D3DRM_OK;
255 256
}

257
static D3DVALUE WINAPI d3drm_light_GetRange(IDirect3DRMLight *iface)
258
{
259
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
260

261
    TRACE("iface %p.\n", iface);
262

263
    return light->range;
264 265
}

266
static D3DVALUE WINAPI d3drm_light_GetUmbra(IDirect3DRMLight *iface)
267
{
268
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
269

270
    TRACE("iface %p.\n", light);
271

272
    return light->umbra;
273 274
}

275
static D3DVALUE WINAPI d3drm_light_GetPenumbra(IDirect3DRMLight *iface)
276
{
277
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
278

279
    TRACE("iface %p.\n", iface);
280

281
    return light->penumbra;
282 283
}

284
static D3DVALUE WINAPI d3drm_light_GetConstantAttenuation(IDirect3DRMLight *iface)
285
{
286
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
287

288
    TRACE("iface %p.\n", iface);
289

290
    return light->cattenuation;
291 292
}

293
static D3DVALUE WINAPI d3drm_light_GetLinearAttenuation(IDirect3DRMLight *iface)
294
{
295
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
296

297
    TRACE("iface %p.\n", iface);
298

299
    return light->lattenuation;
300 301
}

302
static D3DVALUE WINAPI d3drm_light_GetQuadraticAttenuation(IDirect3DRMLight *iface)
303
{
304
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
305

306
    TRACE("iface %p.\n", iface);
307

308
    return light->qattenuation;
309 310
}

311
static D3DCOLOR WINAPI d3drm_light_GetColor(IDirect3DRMLight *iface)
312
{
313
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
314

315
    TRACE("iface %p.\n", iface);
316

317
    return light->color;
318 319
}

320
static D3DRMLIGHTTYPE WINAPI d3drm_light_GetType(IDirect3DRMLight *iface)
321
{
322
    struct d3drm_light *light = impl_from_IDirect3DRMLight(iface);
323

324
    TRACE("iface %p.\n", iface);
325

326
    return light->type;
327 328
}

329
static HRESULT WINAPI d3drm_light_SetEnableFrame(IDirect3DRMLight *iface, IDirect3DRMFrame *frame)
330
{
331
    FIXME("iface %p, frame %p stub!\n", iface, frame);
332 333 334 335

    return E_NOTIMPL;
}

336
static HRESULT WINAPI d3drm_light_GetEnableFrame(IDirect3DRMLight *iface, IDirect3DRMFrame **frame)
337
{
338
    FIXME("iface %p, frame %p stub!\n", iface, frame);
339 340 341 342

    return E_NOTIMPL;
}

343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
static const struct IDirect3DRMLightVtbl d3drm_light_vtbl =
{
    d3drm_light_QueryInterface,
    d3drm_light_AddRef,
    d3drm_light_Release,
    d3drm_light_Clone,
    d3drm_light_AddDestroyCallback,
    d3drm_light_DeleteDestroyCallback,
    d3drm_light_SetAppData,
    d3drm_light_GetAppData,
    d3drm_light_SetName,
    d3drm_light_GetName,
    d3drm_light_GetClassName,
    d3drm_light_SetType,
    d3drm_light_SetColor,
    d3drm_light_SetColorRGB,
    d3drm_light_SetRange,
    d3drm_light_SetUmbra,
    d3drm_light_SetPenumbra,
    d3drm_light_SetConstantAttenuation,
    d3drm_light_SetLinearAttenuation,
    d3drm_light_SetQuadraticAttenuation,
    d3drm_light_GetRange,
    d3drm_light_GetUmbra,
    d3drm_light_GetPenumbra,
    d3drm_light_GetConstantAttenuation,
    d3drm_light_GetLinearAttenuation,
    d3drm_light_GetQuadraticAttenuation,
    d3drm_light_GetColor,
    d3drm_light_GetType,
    d3drm_light_SetEnableFrame,
    d3drm_light_GetEnableFrame,
375 376
};

377
HRESULT Direct3DRMLight_create(IUnknown **out)
378
{
379
    struct d3drm_light *object;
380

381
    TRACE("out %p.\n", out);
382

383
    if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
384 385
        return E_OUTOFMEMORY;

386
    object->IDirect3DRMLight_iface.lpVtbl = &d3drm_light_vtbl;
387 388
    object->ref = 1;

389
    *out = (IUnknown *)&object->IDirect3DRMLight_iface;
390 391 392

    return S_OK;
}