ReactOS 0.4.17-dev-966-gf06eace
light.c
Go to the documentation of this file.
1/* Direct3D Light
2 * Copyright (c) 1998 / 2002 Lionel ULMER
3 * Copyright (c) 2006 Stefan DÖSINGER
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20#include "ddraw_private.h"
21
23
24/*****************************************************************************
25 * light_update
26 *
27 * Updates the Direct3DDevice7 lighting parameters
28 *
29 *****************************************************************************/
30static void light_update(struct d3d_light *light)
31{
32 struct d3d_device *device;
33
34 TRACE("light %p.\n", light);
35
36 if (!light->active_viewport || !light->active_viewport->active_device) return;
37 device = light->active_viewport->active_device;
38
39 IDirect3DDevice7_SetLight(&device->IDirect3DDevice7_iface, light->active_light_index, &light->light7);
40}
41
42/*****************************************************************************
43 * light_activate
44 *
45 * Uses the Direct3DDevice7::LightEnable method to active the light
46 *
47 *****************************************************************************/
49{
50 struct d3d_device *device;
51
52 TRACE("light %p.\n", light);
53
54 if (!light->active_viewport || !light->active_viewport->active_device
55 || light->active_viewport->active_device->current_viewport != light->active_viewport)
56 return;
57 device = light->active_viewport->active_device;
58
59 if (light->light.dwFlags & D3DLIGHT_ACTIVE)
60 {
63 IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->active_light_index, TRUE);
64 }
65}
66
67/*****************************************************************************
68 *
69 * light_deactivate
70 *
71 * Uses the Direct3DDevice7::LightEnable method to deactivate the light
72 *
73 *****************************************************************************/
75{
76 struct d3d_device *device;
77
78 TRACE("light %p.\n", light);
79
80 if (!light->active_viewport || !light->active_viewport->active_device
81 || light->active_viewport->active_device->current_viewport != light->active_viewport)
82 {
83 assert(!light->active_light_index);
84 return;
85 }
86
87 device = light->active_viewport->active_device;
88 if (light->active_light_index)
89 {
90 IDirect3DDevice7_LightEnable(&device->IDirect3DDevice7_iface, light->active_light_index, FALSE);
92 }
93}
94
95static inline struct d3d_light *impl_from_IDirect3DLight(IDirect3DLight *iface)
96{
98}
99
100/*****************************************************************************
101 * IDirect3DLight::QueryInterface
102 *
103 * Queries the object for different interfaces. Unimplemented for this
104 * object at the moment
105 *
106 * Params:
107 * riid: Interface id asked for
108 * obj: Address to return the resulting pointer at.
109 *
110 * Returns:
111 * E_NOINTERFACE, because it's a stub
112 *****************************************************************************/
113static HRESULT WINAPI d3d_light_QueryInterface(IDirect3DLight *iface, REFIID riid, void **object)
114{
115 FIXME("iface %p, riid %s, object %p stub!\n", iface, debugstr_guid(riid), object);
116
117 *object = NULL;
118 return E_NOINTERFACE;
119}
120
121static ULONG WINAPI d3d_light_AddRef(IDirect3DLight *iface)
122{
125
126 TRACE("%p increasing refcount to %lu.\n", light, ref);
127
128 return ref;
129}
130
131static ULONG WINAPI d3d_light_Release(IDirect3DLight *iface)
132{
135
136 TRACE("%p decreasing refcount to %lu.\n", light, ref);
137
138 if (!ref)
139 {
140 free(light);
141 return 0;
142 }
143 return ref;
144}
145
146/*****************************************************************************
147 * IDirect3DLight Methods.
148 *****************************************************************************/
149
150/*****************************************************************************
151 * IDirect3DLight::Initialize
152 *
153 * Initializes the interface. This implementation is a no-op, because
154 * initialization takes place at creation time
155 *
156 * Params:
157 * Direct3D: Pointer to an IDirect3D interface.
158 *
159 * Returns:
160 * D3D_OK
161 *
162 *****************************************************************************/
163static HRESULT WINAPI d3d_light_Initialize(IDirect3DLight *iface, IDirect3D *d3d)
164{
165 TRACE("iface %p, d3d %p.\n", iface, d3d);
166
167 return D3D_OK;
168}
169
170static HRESULT WINAPI d3d_light_SetLight(IDirect3DLight *iface, D3DLIGHT *data)
171{
172 static const D3DCOLORVALUE zero_value = {{0.0f}, {0.0f}, {0.0f}, {0.0f}};
174 DWORD flags = data->dwSize >= sizeof(D3DLIGHT2) ? ((D3DLIGHT2 *)data)->dwFlags : D3DLIGHT_ACTIVE;
175 D3DLIGHT7 *light7 = &light->light7;
176
177 TRACE("iface %p, data %p.\n", iface, data);
178
179 if ((!data->dltType) || (data->dltType > D3DLIGHT_PARALLELPOINT))
180 return DDERR_INVALIDPARAMS;
181
182 /* Translate D3DLIGHT2 structure to D3DLIGHT7. */
183 light7->dltType = data->dltType;
184 light7->dcvDiffuse = data->dcvColor;
186 light7->dcvSpecular = zero_value;
187 else
188 light7->dcvSpecular = data->dcvColor;
189 light7->dcvAmbient = zero_value;
190 light7->dvPosition = data->dvPosition;
191 light7->dvDirection = data->dvDirection;
192 light7->dvRange = data->dvRange;
193 light7->dvFalloff = data->dvFalloff;
194 light7->dvAttenuation0 = data->dvAttenuation0;
195 light7->dvAttenuation1 = data->dvAttenuation1;
196 light7->dvAttenuation2 = data->dvAttenuation2;
197 light7->dvTheta = data->dvTheta;
198 light7->dvPhi = data->dvPhi;
199
201 memcpy(&light->light, data, sizeof(*data));
202
203 if (!(flags & D3DLIGHT_ACTIVE))
205
206 light->light.dwFlags = flags;
209
210 return D3D_OK;
211}
212
213/*****************************************************************************
214 * IDirect3DLight::GetLight
215 *
216 * Returns the parameters currently assigned to the IDirect3DLight object
217 *
218 * Params:
219 * Light: Pointer to an D3DLIGHT structure to store the parameters
220 *
221 * Returns:
222 * D3D_OK on success
223 * DDERR_INVALIDPARAMS if Light is NULL
224 *****************************************************************************/
225static HRESULT WINAPI d3d_light_GetLight(IDirect3DLight *iface, D3DLIGHT *lpLight)
226{
228
229 TRACE("iface %p, light %p.\n", iface, lpLight);
230
232 memcpy(lpLight, &light->light, lpLight->dwSize);
234
235 return DD_OK;
236}
237
238static const struct IDirect3DLightVtbl d3d_light_vtbl =
239{
240 /*** IUnknown Methods ***/
244 /*** IDirect3DLight Methods ***/
248};
249
251{
252 light->IDirect3DLight_iface.lpVtbl = &d3d_light_vtbl;
253 light->ref = 1;
254 light->ddraw = ddraw;
255}
256
257struct d3d_light *unsafe_impl_from_IDirect3DLight(IDirect3DLight *iface)
258{
259 if (!iface)
260 return NULL;
261 assert(iface->lpVtbl == &d3d_light_vtbl);
262
263 return impl_from_IDirect3DLight(iface);
264}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
#define IDirect3DDevice7_LightEnable(p, a, b)
Definition: d3d.h:1387
#define IDirect3DDevice7_SetLight(p, a, b)
Definition: d3d.h:1361
#define D3D_OK
Definition: d3d.h:106
@ D3DLIGHT_PARALLELPOINT
Definition: d3dtypes.h:558
#define D3DLIGHT_NO_SPECULAR
Definition: d3dtypes.h:597
#define D3DLIGHT_ACTIVE
Definition: d3dtypes.h:596
struct _D3DLIGHT2 D3DLIGHT2
void viewport_alloc_active_light_index(struct d3d_light *light)
Definition: viewport.c:121
void viewport_free_active_light_index(struct d3d_light *light)
Definition: viewport.c:159
#define free
Definition: debug_ros.c:5
static HRESULT WINAPI d3d_light_SetLight(IDirect3DLight *iface, D3DLIGHT *data)
Definition: light.c:170
void light_activate(struct d3d_light *light)
Definition: light.c:48
void light_deactivate(struct d3d_light *light)
Definition: light.c:74
static ULONG WINAPI d3d_light_AddRef(IDirect3DLight *iface)
Definition: light.c:121
static HRESULT WINAPI d3d_light_GetLight(IDirect3DLight *iface, D3DLIGHT *lpLight)
Definition: light.c:225
void d3d_light_init(struct d3d_light *light, struct ddraw *ddraw)
Definition: light.c:250
struct d3d_light * unsafe_impl_from_IDirect3DLight(IDirect3DLight *iface)
Definition: light.c:257
static void light_update(struct d3d_light *light)
Definition: light.c:30
static HRESULT WINAPI d3d_light_QueryInterface(IDirect3DLight *iface, REFIID riid, void **object)
Definition: light.c:113
static const struct IDirect3DLightVtbl d3d_light_vtbl
Definition: light.c:238
static HRESULT WINAPI d3d_light_Initialize(IDirect3DLight *iface, IDirect3D *d3d)
Definition: light.c:163
static struct d3d_light * impl_from_IDirect3DLight(IDirect3DLight *iface)
Definition: light.c:95
static ULONG WINAPI d3d_light_Release(IDirect3DLight *iface)
Definition: light.c:131
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define assert(_expr)
Definition: assert.h:32
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLbitfield flags
Definition: glext.h:7161
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum light
Definition: glfuncs.h:170
REFIID riid
Definition: atlbase.h:39
#define debugstr_guid
Definition: kernel32.h:35
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
_In_ LPWSTR _In_ DWORD _In_ DWORD _In_ DWORD dwFlags
Definition: netsh.h:141
#define REFIID
Definition: guiddef.h:118
#define DD_OK
Definition: ddraw.h:188
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:81
#define TRACE(s)
Definition: solgame.cpp:4
D3DVALUE dvPhi
Definition: d3dtypes.h:593
D3DVALUE dvFalloff
Definition: d3dtypes.h:588
D3DCOLORVALUE dcvDiffuse
Definition: d3dtypes.h:582
D3DCOLORVALUE dcvAmbient
Definition: d3dtypes.h:584
D3DVALUE dvAttenuation2
Definition: d3dtypes.h:591
D3DVALUE dvAttenuation0
Definition: d3dtypes.h:589
D3DVECTOR dvPosition
Definition: d3dtypes.h:585
D3DVALUE dvRange
Definition: d3dtypes.h:587
D3DLIGHTTYPE dltType
Definition: d3dtypes.h:581
D3DVALUE dvTheta
Definition: d3dtypes.h:592
D3DCOLORVALUE dcvSpecular
Definition: d3dtypes.h:583
D3DVALUE dvAttenuation1
Definition: d3dtypes.h:590
D3DVECTOR dvDirection
Definition: d3dtypes.h:586
DWORD dwSize
Definition: d3dtypes.h:566
D3DLIGHT7 light7
IDirect3DLight IDirect3DLight_iface
Definition: devices.h:37
Definition: send.c:48
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define WINAPI
Definition: msvc.h:6
void WINAPI wined3d_mutex_unlock(void)
Definition: wined3d_main.c:544
void WINAPI wined3d_mutex_lock(void)
Definition: wined3d_main.c:539
#define E_NOINTERFACE
Definition: winerror.h:3479