2 * Copyright (c) 1998 Lionel ULMER
4 * This file contains the implementation of Direct3DLight.
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/obj_base.h"
27 #include "wine/debug.h"
29 #include "mesa_private.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
33 #define D3DLPRIVATE(x) mesa_d3dl_private*dlpriv=((mesa_d3dl_private*)x->private)
35 static ICOM_VTABLE(IDirect3DLight) light_vtable;
42 /*******************************************************************************
43 * Light static functions
45 static const float zero_value[] = {
49 static void update(IDirect3DLightImpl* This) {
51 switch (This->light.dltType) {
52 case D3DLIGHT_POINT: /* 1 */
53 TRACE("Activating POINT\n");
56 case D3DLIGHT_SPOT: /* 2 */
57 TRACE("Activating SPOT\n");
60 case D3DLIGHT_DIRECTIONAL: { /* 3 */
63 TRACE("Activating DIRECTIONAL\n");
64 TRACE(" direction : %f %f %f\n",
65 This->light.dvDirection.u1.x,
66 This->light.dvDirection.u2.y,
67 This->light.dvDirection.u3.z);
68 _dump_colorvalue(" color ", This->light.dcvColor);
70 glLightfv(dlpriv->light_num, GL_AMBIENT, (float *) zero_value);
71 glLightfv(dlpriv->light_num, GL_DIFFUSE, (float *) &(This->light.dcvColor));
73 direction[0] = -This->light.dvDirection.u1.x;
74 direction[1] = -This->light.dvDirection.u2.y;
75 direction[2] = -This->light.dvDirection.u3.z;
76 direction[3] = 0.0; /* This is a directional light */
78 glLightfv(dlpriv->light_num, GL_POSITION, (float *) direction);
81 case D3DLIGHT_PARALLELPOINT: /* 4 */
82 TRACE("Activating PARRALLEL-POINT\n");
86 TRACE("Not a known Light Type: %d\n",This->light.dltType);
91 static void activate(IDirect3DLightImpl* This) {
96 /* If was not active, activate it */
97 if (This->is_active == 0) {
98 glEnable(dlpriv->light_num);
106 /*******************************************************************************
107 * Light Creation functions
109 LPDIRECT3DLIGHT d3dlight_create(IDirect3D2Impl* d3d2)
111 IDirect3DLightImpl* light;
113 light = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLightImpl));
114 light->private = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(mesa_d3dl_private));
116 ICOM_VTBL(light) = &light_vtable;
117 light->d3d.d3d2 = d3d2;
122 light->activate = activate;
123 light->is_active = 0;
125 return (LPDIRECT3DLIGHT)light;
128 LPDIRECT3DLIGHT d3dlight_create_dx3(IDirect3DImpl* d3d1)
130 IDirect3DLightImpl* light;
132 light = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IDirect3DLightImpl));
133 light->private = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(mesa_d3dl_private));
135 ICOM_VTBL(light) = &light_vtable;
137 light->d3d.d3d1 = d3d1;
142 light->activate = activate;
143 light->is_active = 0;
145 return (LPDIRECT3DLIGHT)light;
148 /*******************************************************************************
149 * IDirect3DLight methods
152 static HRESULT WINAPI IDirect3DLightImpl_QueryInterface(LPDIRECT3DLIGHT iface,
156 ICOM_THIS(IDirect3DLightImpl,iface);
158 FIXME("(%p)->(%s,%p): stub\n", This, debugstr_guid(riid),ppvObj);
165 static ULONG WINAPI IDirect3DLightImpl_AddRef(LPDIRECT3DLIGHT iface)
167 ICOM_THIS(IDirect3DLightImpl,iface);
168 TRACE("(%p)->()incrementing from %lu.\n", This, This->ref );
170 return ++(This->ref);
175 static ULONG WINAPI IDirect3DLightImpl_Release(LPDIRECT3DLIGHT iface)
177 ICOM_THIS(IDirect3DLightImpl,iface);
178 TRACE("(%p)->() decrementing from %lu.\n", This, This->ref );
180 if (!--(This->ref)) {
181 HeapFree(GetProcessHeap(),0,This->private);
182 HeapFree(GetProcessHeap(),0,This);
189 /*** IDirect3DLight methods ***/
190 static void dump_light(LPD3DLIGHT light)
192 DPRINTF(" dwSize : %ld\n", light->dwSize);
195 static HRESULT WINAPI IDirect3DLightImpl_GetLight(LPDIRECT3DLIGHT iface,
198 ICOM_THIS(IDirect3DLightImpl,iface);
199 TRACE("(%p)->(%p)\n", This, lpLight);
203 /* Copies the light structure */
204 switch (This->type) {
206 *((LPD3DLIGHT)lpLight) = *((LPD3DLIGHT) &(This->light));
209 *((LPD3DLIGHT2)lpLight) = *((LPD3DLIGHT2) &(This->light));
216 static HRESULT WINAPI IDirect3DLightImpl_SetLight(LPDIRECT3DLIGHT iface,
219 ICOM_THIS(IDirect3DLightImpl,iface);
220 TRACE("(%p)->(%p)\n", This, lpLight);
224 /* Stores the light */
225 switch (This->type) {
227 *((LPD3DLIGHT) &(This->light)) = *((LPD3DLIGHT)lpLight);
230 *((LPD3DLIGHT2) &(This->light)) = *((LPD3DLIGHT2)lpLight);
242 static HRESULT WINAPI IDirect3DLightImpl_Initialize(LPDIRECT3DLIGHT iface,
243 LPDIRECT3D lpDirect3D)
246 ICOM_THIS(IDirect3DLightImpl,iface);
247 TRACE("(%p)->(%p)\n", This, lpDirect3D);
249 return DDERR_ALREADYINITIALIZED;
253 /*******************************************************************************
254 * IDirect3DLight VTable
256 static ICOM_VTABLE(IDirect3DLight) light_vtable =
258 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
259 /*** IUnknown methods ***/
260 IDirect3DLightImpl_QueryInterface,
261 IDirect3DLightImpl_AddRef,
262 IDirect3DLightImpl_Release,
263 /*** IDirect3DLight methods ***/
264 IDirect3DLightImpl_Initialize,
265 IDirect3DLightImpl_SetLight,
266 IDirect3DLightImpl_GetLight