2 * Copyright (c) 1998 / 2002 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
21 #define NONAMELESSUNION
22 #define NONAMELESSSTRUCT
29 #include "wine/debug.h"
31 #include "d3d_private.h"
32 #include "mesa_private.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(ddraw
);
36 /* First, the 'main' interface... */
38 Main_IDirect3DLightImpl_1_QueryInterface(LPDIRECT3DLIGHT iface
,
42 ICOM_THIS_FROM(IDirect3DLightImpl
, IDirect3DLight
, iface
);
43 FIXME("(%p/%p)->(%s,%p): stub!\n", This
, iface
, debugstr_guid(riid
), obp
);
48 Main_IDirect3DLightImpl_1_AddRef(LPDIRECT3DLIGHT iface
)
50 ICOM_THIS_FROM(IDirect3DLightImpl
, IDirect3DLight
, iface
);
51 TRACE("(%p/%p)->() incrementing from %lu.\n", This
, iface
, This
->ref
);
56 Main_IDirect3DLightImpl_1_Release(LPDIRECT3DLIGHT iface
)
58 ICOM_THIS_FROM(IDirect3DLightImpl
, IDirect3DLight
, iface
);
59 TRACE("(%p/%p)->() decrementing from %lu.\n", This
, iface
, This
->ref
);
61 HeapFree(GetProcessHeap(), 0, This
);
68 Main_IDirect3DLightImpl_1_Initialize(LPDIRECT3DLIGHT iface
,
69 LPDIRECT3D lpDirect3D
)
71 ICOM_THIS_FROM(IDirect3DLightImpl
, IDirect3DLight
, iface
);
72 TRACE("(%p/%p)->(%p) no-op...\n", This
, iface
, lpDirect3D
);
76 /*** IDirect3DLight methods ***/
77 static void dump_light(LPD3DLIGHT2 light
)
79 DPRINTF(" - dwSize : %ld\n", light
->dwSize
);
83 Main_IDirect3DLightImpl_1_SetLight(LPDIRECT3DLIGHT iface
,
86 ICOM_THIS_FROM(IDirect3DLightImpl
, IDirect3DLight
, iface
);
87 TRACE("(%p/%p)->(%p)\n", This
, iface
, lpLight
);
88 if (TRACE_ON(ddraw
)) {
89 TRACE(" Light definition : \n");
90 dump_light((LPD3DLIGHT2
) lpLight
);
92 memcpy(&This
->light
, lpLight
, lpLight
->dwSize
);
93 if ((This
->light
.dwFlags
& D3DLIGHT_ACTIVE
) != 0) {
100 Main_IDirect3DLightImpl_1_GetLight(LPDIRECT3DLIGHT iface
,
103 ICOM_THIS_FROM(IDirect3DLightImpl
, IDirect3DLight
, iface
);
104 TRACE("(%p/%p)->(%p)\n", This
, iface
, lpLight
);
105 if (TRACE_ON(ddraw
)) {
106 TRACE(" Returning light definition : \n");
107 dump_light(&This
->light
);
109 memcpy(lpLight
, &This
->light
, lpLight
->dwSize
);
113 /*******************************************************************************
114 * Light static functions
116 static const float zero_value
[] = {
120 static void update(IDirect3DLightImpl
* This
) {
121 IDirect3DLightGLImpl
*glThis
= (IDirect3DLightGLImpl
*) This
;
123 switch (glThis
->parent
.light
.dltType
) {
124 case D3DLIGHT_POINT
: /* 1 */
125 FIXME("Activating POINT - not supported yet\n");
128 case D3DLIGHT_SPOT
: /* 2 */
129 FIXME("Activating SPOT - not supported yet\n");
132 case D3DLIGHT_DIRECTIONAL
: { /* 3 */
135 if (TRACE_ON(ddraw
)) {
136 TRACE("Activating DIRECTIONAL\n");
137 DPRINTF(" - direction : "); dump_D3DVECTOR(&(glThis
->parent
.light
.dvDirection
)); DPRINTF("\n");
138 DPRINTF(" - color : "); dump_D3DCOLORVALUE(&(glThis
->parent
.light
.dcvColor
)); DPRINTF("\n");
140 glLightfv(glThis
->light_num
, GL_AMBIENT
, (float *) zero_value
);
141 glLightfv(glThis
->light_num
, GL_DIFFUSE
, (float *) &(glThis
->parent
.light
.dcvColor
));
143 direction
[0] = -glThis
->parent
.light
.dvDirection
.u1
.x
;
144 direction
[1] = -glThis
->parent
.light
.dvDirection
.u2
.y
;
145 direction
[2] = -glThis
->parent
.light
.dvDirection
.u3
.z
;
146 direction
[3] = 0.0; /* This is a directional light */
148 glLightfv(glThis
->light_num
, GL_POSITION
, (float *) direction
);
151 case D3DLIGHT_PARALLELPOINT
: /* 4 */
152 FIXME("Activating PARRALLEL-POINT - not supported yet\n");
156 WARN("Not a known Light Type: %d\n", glThis
->parent
.light
.dltType
);
162 static void activate(IDirect3DLightImpl
* This
) {
163 IDirect3DLightGLImpl
*glThis
= (IDirect3DLightGLImpl
*) This
;
166 /* If was not active, activate it */
167 if ((glThis
->parent
.light
.dwFlags
& D3DLIGHT_ACTIVE
) == 0) {
168 glEnable(glThis
->light_num
);
169 glThis
->parent
.light
.dwFlags
|= D3DLIGHT_ACTIVE
;
174 static void desactivate(IDirect3DLightImpl
* This
) {
175 IDirect3DLightGLImpl
*glThis
= (IDirect3DLightGLImpl
*) This
;
177 /* If was not active, activate it */
178 if ((glThis
->parent
.light
.dwFlags
& D3DLIGHT_ACTIVE
) != 0) {
179 glDisable(glThis
->light_num
);
180 glThis
->parent
.light
.dwFlags
&= ~D3DLIGHT_ACTIVE
;
186 GL_IDirect3DLightImpl_1_Release(LPDIRECT3DLIGHT iface
)
188 ICOM_THIS_FROM(IDirect3DLightImpl
, IDirect3DLight
, iface
);
189 IDirect3DLightGLImpl
*glThis
= (IDirect3DLightGLImpl
*) This
;
191 TRACE("(%p/%p)->() decrementing from %lu.\n", This
, iface
, This
->ref
);
192 if (!--(This
->ref
)) {
193 ((IDirect3DGLImpl
*) This
->d3d
)->light_released(This
->d3d
, glThis
->light_num
);
194 HeapFree(GetProcessHeap(), 0, This
);
200 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
201 # define XCAST(fun) (typeof(VTABLE_IDirect3DLight.fun))
203 # define XCAST(fun) (void*)
206 ICOM_VTABLE(IDirect3DLight
) VTABLE_IDirect3DLight
=
208 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
209 XCAST(QueryInterface
) Main_IDirect3DLightImpl_1_QueryInterface
,
210 XCAST(AddRef
) Main_IDirect3DLightImpl_1_AddRef
,
211 XCAST(Release
) GL_IDirect3DLightImpl_1_Release
,
212 XCAST(Initialize
) Main_IDirect3DLightImpl_1_Initialize
,
213 XCAST(SetLight
) Main_IDirect3DLightImpl_1_SetLight
,
214 XCAST(GetLight
) Main_IDirect3DLightImpl_1_GetLight
,
217 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
224 HRESULT
d3dlight_create(IDirect3DLightImpl
**obj
, IDirect3DImpl
*d3d
, GLenum light_num
)
226 IDirect3DLightImpl
*object
;
227 IDirect3DLightGLImpl
*gl_object
;
229 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirect3DLightGLImpl
));
230 if (object
== NULL
) return DDERR_OUTOFMEMORY
;
231 gl_object
= (IDirect3DLightGLImpl
*) object
;
236 object
->activate
= activate
;
237 object
->desactivate
= desactivate
;
238 object
->update
= update
;
239 gl_object
->light_num
= light_num
;
241 ICOM_INIT_INTERFACE(object
, IDirect3DLight
, VTABLE_IDirect3DLight
);
245 TRACE(" creating implementation at %p.\n", *obj
);