2 * Copyright (c) 1998 / 2002 Lionel ULMER
3 * Copyright (c) 2006 Stefan DÖSINGER
5 * This file contains the implementation of Direct3DLight.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
24 #include "wine/debug.h"
37 #include "wine/exception.h"
42 #include "ddraw_private.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(d3d7);
46 /*****************************************************************************
48 *****************************************************************************/
50 /*****************************************************************************
51 * IDirect3DLight::QueryInterface
53 * Queries the object for different interfaces. Unimplemented for this
54 * object at the moment
57 * riid: Interface id asked for
58 * obj: Address to return the resulting pointer at.
61 * E_NOINTERFACE, because it's a stub
62 *****************************************************************************/
64 IDirect3DLightImpl_QueryInterface(IDirect3DLight *iface,
68 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
69 FIXME("(%p)->(%s,%p): stub!\n", This, debugstr_guid(riid), obp);
74 /*****************************************************************************
75 * IDirect3DLight::AddRef
77 * Increases the refcount by 1
82 *****************************************************************************/
84 IDirect3DLightImpl_AddRef(IDirect3DLight *iface)
86 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
87 ULONG ref = InterlockedIncrement(&This->ref);
89 TRACE("(%p)->() incrementing from %u.\n", This, ref - 1);
94 /*****************************************************************************
95 * IDirect3DLight::Release
97 * Reduces the refcount by one. If the refcount falls to 0, the object
103 *****************************************************************************/
105 IDirect3DLightImpl_Release(IDirect3DLight *iface)
107 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
108 ULONG ref = InterlockedDecrement(&This->ref);
110 TRACE("(%p)->() decrementing from %u.\n", This, ref + 1);
113 HeapFree(GetProcessHeap(), 0, This);
119 /*****************************************************************************
120 * IDirect3DLight Methods.
121 *****************************************************************************/
123 /*****************************************************************************
124 * IDirect3DLight::Initialize
126 * Initializes the interface. This implementation is a no-op, because
127 * initialization takes place at creation time
130 * Direct3D: Pointer to an IDirect3D interface.
135 *****************************************************************************/
136 static HRESULT WINAPI
137 IDirect3DLightImpl_Initialize(IDirect3DLight *iface,
138 IDirect3D *lpDirect3D)
140 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
141 IDirectDrawImpl *d3d = ICOM_OBJECT(IDirectDrawImpl, IDirect3D, lpDirect3D);
142 TRACE("(%p)->(%p) no-op...\n", This, d3d);
146 /*****************************************************************************
147 * IDirect3DLight::SetLight
149 * Assigns a lighting value to this object
152 * Light: Lighting parametes to set
156 * DDERR_INVALIDPARAMS if Light is NULL
158 *****************************************************************************/
159 static void dump_light(const D3DLIGHT2 *light)
161 DPRINTF(" - dwSize : %d\n", light->dwSize);
164 static const float zero_value[] = {
168 static HRESULT WINAPI
169 IDirect3DLightImpl_SetLight(IDirect3DLight *iface,
172 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
173 LPD3DLIGHT7 light7 = &(This->light7);
174 TRACE("(%p)->(%p)\n", This, lpLight);
175 if (TRACE_ON(d3d7)) {
176 TRACE(" Light definition :\n");
177 dump_light((LPD3DLIGHT2) lpLight);
180 if ( (lpLight->dltType == 0) || (lpLight->dltType > D3DLIGHT_PARALLELPOINT) )
181 return DDERR_INVALIDPARAMS;
183 if ( lpLight->dltType == D3DLIGHT_PARALLELPOINT )
184 FIXME("D3DLIGHT_PARALLELPOINT no supported\n");
186 /* Translate D3DLIGH2 structure to D3DLIGHT7 */
187 light7->dltType = lpLight->dltType;
188 light7->dcvDiffuse = lpLight->dcvColor;
189 if ((((LPD3DLIGHT2)lpLight)->dwFlags & D3DLIGHT_NO_SPECULAR) != 0)
190 light7->dcvSpecular = lpLight->dcvColor;
192 light7->dcvSpecular = *(const D3DCOLORVALUE*)zero_value;
193 light7->dcvAmbient = lpLight->dcvColor;
194 light7->dvPosition = lpLight->dvPosition;
195 light7->dvDirection = lpLight->dvDirection;
196 light7->dvRange = lpLight->dvRange;
197 light7->dvFalloff = lpLight->dvFalloff;
198 light7->dvAttenuation0 = lpLight->dvAttenuation0;
199 light7->dvAttenuation1 = lpLight->dvAttenuation1;
200 light7->dvAttenuation2 = lpLight->dvAttenuation2;
201 light7->dvTheta = lpLight->dvTheta;
202 light7->dvPhi = lpLight->dvPhi;
204 memcpy(&This->light, lpLight, lpLight->dwSize);
205 if ((This->light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
211 /*****************************************************************************
212 * IDirect3DLight::GetLight
214 * Returns the parameters currently assigned to the IDirect3DLight object
217 * Light: Pointer to an D3DLIGHT structure to store the parameters
221 * DDERR_INVALIDPARAMS if Light is NULL
222 *****************************************************************************/
223 static HRESULT WINAPI
224 IDirect3DLightImpl_GetLight(IDirect3DLight *iface,
227 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
228 TRACE("(%p/%p)->(%p)\n", This, iface, lpLight);
229 if (TRACE_ON(d3d7)) {
230 TRACE(" Returning light definition :\n");
231 dump_light(&This->light);
233 memcpy(lpLight, &This->light, lpLight->dwSize);
237 /*****************************************************************************
240 * Updates the Direct3DDevice7 lighting parameters
242 *****************************************************************************/
243 void light_update(IDirect3DLightImpl* This)
245 IDirect3DDeviceImpl* device;
247 TRACE("(%p)\n", This);
249 if (!This->active_viewport || !This->active_viewport->active_device)
251 device = This->active_viewport->active_device;
253 IDirect3DDevice7_SetLight(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, &(This->light7));
256 /*****************************************************************************
259 * Uses the Direct3DDevice7::LightEnable method to active the light
261 *****************************************************************************/
262 void light_activate(IDirect3DLightImpl* This)
264 IDirect3DDeviceImpl* device;
266 TRACE("(%p)\n", This);
268 if (!This->active_viewport || !This->active_viewport->active_device)
270 device = This->active_viewport->active_device;
273 /* If was not active, activate it */
274 if ((This->light.dwFlags & D3DLIGHT_ACTIVE) == 0) {
275 IDirect3DDevice7_LightEnable(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, TRUE);
276 This->light.dwFlags |= D3DLIGHT_ACTIVE;
280 /*****************************************************************************
284 * Uses the Direct3DDevice7::LightEnable method to deactivate the light
286 *****************************************************************************/
287 void light_desactivate(IDirect3DLightImpl* This)
289 IDirect3DDeviceImpl* device;
291 TRACE("(%p)\n", This);
293 if (!This->active_viewport || !This->active_viewport->active_device)
295 device = This->active_viewport->active_device;
297 /* If was not active, activate it */
298 if ((This->light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
299 IDirect3DDevice7_LightEnable(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, FALSE);
300 This->light.dwFlags &= ~D3DLIGHT_ACTIVE;
304 const IDirect3DLightVtbl IDirect3DLight_Vtbl =
306 /*** IUnknown Methods ***/
307 IDirect3DLightImpl_QueryInterface,
308 IDirect3DLightImpl_AddRef,
309 IDirect3DLightImpl_Release,
310 /*** IDirect3DLight Methods ***/
311 IDirect3DLightImpl_Initialize,
312 IDirect3DLightImpl_SetLight,
313 IDirect3DLightImpl_GetLight