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
));
115 ICOM_VTBL(light
) = &light_vtable
;
116 light
->d3d
.d3d2
= d3d2
;
121 light
->activate
= activate
;
122 light
->is_active
= 0;
124 return (LPDIRECT3DLIGHT
)light
;
127 LPDIRECT3DLIGHT
d3dlight_create_dx3(IDirect3DImpl
* d3d1
)
129 IDirect3DLightImpl
* light
;
131 light
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDirect3DLightImpl
));
133 ICOM_VTBL(light
) = &light_vtable
;
135 light
->d3d
.d3d1
= d3d1
;
140 light
->activate
= activate
;
141 light
->is_active
= 0;
143 return (LPDIRECT3DLIGHT
)light
;
146 /*******************************************************************************
147 * IDirect3DLight methods
150 static HRESULT WINAPI
IDirect3DLightImpl_QueryInterface(LPDIRECT3DLIGHT iface
,
154 ICOM_THIS(IDirect3DLightImpl
,iface
);
156 FIXME("(%p)->(%s,%p): stub\n", This
, debugstr_guid(riid
),ppvObj
);
163 static ULONG WINAPI
IDirect3DLightImpl_AddRef(LPDIRECT3DLIGHT iface
)
165 ICOM_THIS(IDirect3DLightImpl
,iface
);
166 TRACE("(%p)->()incrementing from %lu.\n", This
, This
->ref
);
168 return ++(This
->ref
);
173 static ULONG WINAPI
IDirect3DLightImpl_Release(LPDIRECT3DLIGHT iface
)
175 ICOM_THIS(IDirect3DLightImpl
,iface
);
176 FIXME("(%p)->() decrementing from %lu.\n", This
, This
->ref
);
178 if (!--(This
->ref
)) {
179 HeapFree(GetProcessHeap(),0,This
);
186 /*** IDirect3DLight methods ***/
187 static void dump_light(LPD3DLIGHT light
)
189 DPRINTF(" dwSize : %ld\n", light
->dwSize
);
192 static HRESULT WINAPI
IDirect3DLightImpl_GetLight(LPDIRECT3DLIGHT iface
,
195 ICOM_THIS(IDirect3DLightImpl
,iface
);
196 TRACE("(%p)->(%p)\n", This
, lpLight
);
200 /* Copies the light structure */
201 switch (This
->type
) {
203 *((LPD3DLIGHT
)lpLight
) = *((LPD3DLIGHT
) &(This
->light
));
206 *((LPD3DLIGHT2
)lpLight
) = *((LPD3DLIGHT2
) &(This
->light
));
213 static HRESULT WINAPI
IDirect3DLightImpl_SetLight(LPDIRECT3DLIGHT iface
,
216 ICOM_THIS(IDirect3DLightImpl
,iface
);
217 TRACE("(%p)->(%p)\n", This
, lpLight
);
221 /* Stores the light */
222 switch (This
->type
) {
224 *((LPD3DLIGHT
) &(This
->light
)) = *((LPD3DLIGHT
)lpLight
);
227 *((LPD3DLIGHT2
) &(This
->light
)) = *((LPD3DLIGHT2
)lpLight
);
239 static HRESULT WINAPI
IDirect3DLightImpl_Initialize(LPDIRECT3DLIGHT iface
,
240 LPDIRECT3D lpDirect3D
)
243 ICOM_THIS(IDirect3DLightImpl
,iface
);
244 TRACE("(%p)->(%p)\n", This
, lpDirect3D
);
246 return DDERR_ALREADYINITIALIZED
;
250 /*******************************************************************************
251 * IDirect3DLight VTable
253 static ICOM_VTABLE(IDirect3DLight
) light_vtable
=
255 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
256 /*** IUnknown methods ***/
257 IDirect3DLightImpl_QueryInterface
,
258 IDirect3DLightImpl_AddRef
,
259 IDirect3DLightImpl_Release
,
260 /*** IDirect3DLight methods ***/
261 IDirect3DLightImpl_Initialize
,
262 IDirect3DLightImpl_SetLight
,
263 IDirect3DLightImpl_GetLight