Ownerdraw buttons should erase themselves in WM_ERASEBKGND.
[wine.git] / dlls / ddraw / d3dlight.c
blob35aeafe5126f72bc8e7dbfbcd8f803b6d5c48584
1 /* Direct3D Light
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 #include "config.h"
23 #include <stdarg.h>
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30 #include "objbase.h"
31 #include "wingdi.h"
32 #include "ddraw.h"
33 #include "d3d.h"
34 #include "wine/debug.h"
36 #include "d3d_private.h"
37 #include "mesa_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
41 /* First, the 'main' interface... */
42 HRESULT WINAPI
43 Main_IDirect3DLightImpl_1_QueryInterface(LPDIRECT3DLIGHT iface,
44 REFIID riid,
45 LPVOID* obp)
47 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
48 FIXME("(%p/%p)->(%s,%p): stub!\n", This, iface, debugstr_guid(riid), obp);
49 return DD_OK;
52 ULONG WINAPI
53 Main_IDirect3DLightImpl_1_AddRef(LPDIRECT3DLIGHT iface)
55 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
56 TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
57 return ++(This->ref);
60 ULONG WINAPI
61 Main_IDirect3DLightImpl_1_Release(LPDIRECT3DLIGHT iface)
63 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
64 TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
65 if (!--(This->ref)) {
66 HeapFree(GetProcessHeap(), 0, This);
67 return 0;
69 return This->ref;
72 HRESULT WINAPI
73 Main_IDirect3DLightImpl_1_Initialize(LPDIRECT3DLIGHT iface,
74 LPDIRECT3D lpDirect3D)
76 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
77 TRACE("(%p/%p)->(%p) no-op...\n", This, iface, lpDirect3D);
78 return DD_OK;
81 /*** IDirect3DLight methods ***/
82 static void dump_light(LPD3DLIGHT2 light)
84 DPRINTF(" - dwSize : %ld\n", light->dwSize);
87 static const float zero_value[] = {
88 0.0, 0.0, 0.0, 0.0
91 HRESULT WINAPI
92 Main_IDirect3DLightImpl_1_SetLight(LPDIRECT3DLIGHT iface,
93 LPD3DLIGHT lpLight)
95 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
96 LPD3DLIGHT7 light7 = &(This->light7);
97 TRACE("(%p/%p)->(%p)\n", This, iface, lpLight);
98 if (TRACE_ON(ddraw)) {
99 TRACE(" Light definition : \n");
100 dump_light((LPD3DLIGHT2) lpLight);
103 if ( (lpLight->dltType == 0) || (lpLight->dltType > D3DLIGHT_PARALLELPOINT) )
104 return DDERR_INVALIDPARAMS;
106 if ( lpLight->dltType == D3DLIGHT_PARALLELPOINT )
107 FIXME("D3DLIGHT_PARALLELPOINT no supported\n");
109 /* Translate D3DLIGH2 structure to D3DLIGHT7 */
110 light7->dltType = lpLight->dltType;
111 light7->dcvDiffuse = lpLight->dcvColor;
112 if ((((LPD3DLIGHT2)lpLight)->dwFlags & D3DLIGHT_NO_SPECULAR) != 0)
113 light7->dcvSpecular = lpLight->dcvColor;
114 else
115 light7->dcvSpecular = *(D3DCOLORVALUE*)zero_value;
116 light7->dcvAmbient = lpLight->dcvColor;
117 light7->dvPosition = lpLight->dvPosition;
118 light7->dvDirection = lpLight->dvDirection;
119 light7->dvRange = lpLight->dvRange;
120 light7->dvFalloff = lpLight->dvFalloff;
121 light7->dvAttenuation0 = lpLight->dvAttenuation0;
122 light7->dvAttenuation1 = lpLight->dvAttenuation1;
123 light7->dvAttenuation2 = lpLight->dvAttenuation2;
124 light7->dvTheta = lpLight->dvTheta;
125 light7->dvPhi = lpLight->dvPhi;
127 memcpy(&This->light, lpLight, lpLight->dwSize);
128 if ((This->light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
129 This->update(This);
131 return DD_OK;
134 HRESULT WINAPI
135 Main_IDirect3DLightImpl_1_GetLight(LPDIRECT3DLIGHT iface,
136 LPD3DLIGHT lpLight)
138 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
139 TRACE("(%p/%p)->(%p)\n", This, iface, lpLight);
140 if (TRACE_ON(ddraw)) {
141 TRACE(" Returning light definition : \n");
142 dump_light(&This->light);
144 memcpy(lpLight, &This->light, lpLight->dwSize);
145 return DD_OK;
148 /*******************************************************************************
149 * Light static functions
152 static void update(IDirect3DLightImpl* This) {
153 IDirect3DDeviceImpl* device;
154 if (!This->active_viewport||!This->active_viewport->active_device)
155 return;
156 device = This->active_viewport->active_device;
157 IDirect3DDevice7_SetLight(ICOM_INTERFACE(device,IDirect3DDevice7),This->dwLightIndex,&(This->light7));
160 static void activate(IDirect3DLightImpl* This) {
161 IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
163 TRACE("(%p)\n", This);
165 ENTER_GL();
166 update(This);
167 /* If was not active, activate it */
168 if ((glThis->parent.light.dwFlags & D3DLIGHT_ACTIVE) == 0) {
169 glEnable(glThis->light_num);
170 glThis->parent.light.dwFlags |= D3DLIGHT_ACTIVE;
172 LEAVE_GL();
175 static void desactivate(IDirect3DLightImpl* This) {
176 IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
178 TRACE("(%p)\n", This);
180 ENTER_GL();
181 /* If was not active, activate it */
182 if ((glThis->parent.light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
183 glDisable(glThis->light_num);
184 glThis->parent.light.dwFlags &= ~D3DLIGHT_ACTIVE;
186 LEAVE_GL();
189 ULONG WINAPI
190 GL_IDirect3DLightImpl_1_Release(LPDIRECT3DLIGHT iface)
192 ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
193 IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
195 TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
196 if (!--(This->ref)) {
197 ((IDirect3DGLImpl *) This->d3d)->light_released(This->d3d, glThis->light_num);
198 HeapFree(GetProcessHeap(), 0, This);
199 return 0;
201 return This->ref;
204 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
205 # define XCAST(fun) (typeof(VTABLE_IDirect3DLight.fun))
206 #else
207 # define XCAST(fun) (void*)
208 #endif
210 ICOM_VTABLE(IDirect3DLight) VTABLE_IDirect3DLight =
212 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
213 XCAST(QueryInterface) Main_IDirect3DLightImpl_1_QueryInterface,
214 XCAST(AddRef) Main_IDirect3DLightImpl_1_AddRef,
215 XCAST(Release) GL_IDirect3DLightImpl_1_Release,
216 XCAST(Initialize) Main_IDirect3DLightImpl_1_Initialize,
217 XCAST(SetLight) Main_IDirect3DLightImpl_1_SetLight,
218 XCAST(GetLight) Main_IDirect3DLightImpl_1_GetLight,
221 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
222 #undef XCAST
223 #endif
228 HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d, GLenum light_num)
230 IDirect3DLightImpl *object;
231 IDirect3DLightGLImpl *gl_object;
233 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DLightGLImpl));
234 if (object == NULL) return DDERR_OUTOFMEMORY;
235 gl_object = (IDirect3DLightGLImpl *) object;
237 object->ref = 1;
238 object->d3d = d3d;
239 object->next = NULL;
240 object->activate = activate;
241 object->desactivate = desactivate;
242 object->update = update;
243 object->active_viewport = NULL;
244 gl_object->light_num = light_num;
246 ICOM_INIT_INTERFACE(object, IDirect3DLight, VTABLE_IDirect3DLight);
248 *obj = object;
250 TRACE(" creating implementation at %p.\n", *obj);
252 return D3D_OK;