[D3D] Finish moving d3d[1..3] light code to use d3d7

Christian Costa titan.costa at wanadoo.fr
Sun Oct 30 15:43:14 CST 2005


Hi,

Moving d3d[1..3] light code to use d3d7 was started but not completed.
This patch take care of this.
Now, light creation is no more limited and only the number of lights 
than can be
added to a viewport is limited. This fixes the problem with BattleZone 2 
reported by
H. Verbeet.

Changelog:
Finish moving d3d[1..3] light code to use d3d7.

Christian Costa   titan.costa at wanadoo.fr

-------------- next part --------------
Index: dlls/ddraw/direct3d_opengl.c
===================================================================
RCS file: /home/wine/wine/dlls/ddraw/direct3d_opengl.c,v
retrieving revision 1.2
diff -u -r1.2 direct3d_opengl.c
--- dlls/ddraw/direct3d_opengl.c	26 Jul 2005 20:10:51 -0000	1.2
+++ dlls/ddraw/direct3d_opengl.c	30 Oct 2005 19:20:16 -0000
@@ -97,22 +97,12 @@
 				     IUnknown* pUnkOuter)
 {
     ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
-    IDirect3DGLImpl *glThis = (IDirect3DGLImpl *) This->d3d_private;
-    int fl;
     IDirect3DLightImpl *d3dlimpl;
     HRESULT ret_value;
     
     TRACE("(%p/%p)->(%p,%p)\n", This, iface, lplpDirect3DLight, pUnkOuter);
-    for (fl = 0; fl < MAX_LIGHTS; fl++) {
-        if ((glThis->free_lights & (0x01 << fl)) != 0) {
-	    glThis->free_lights &= ~(0x01 << fl);
-	    break;
-	}
-    }
-    if (fl == MAX_LIGHTS) {
-        return DDERR_INVALIDPARAMS; /* No way to say 'max lights reached' ... */
-    }
-    ret_value = d3dlight_create(&d3dlimpl, This, GL_LIGHT0 + fl);
+
+    ret_value = d3dlight_create(&d3dlimpl, This);
     *lplpDirect3DLight = ICOM_INTERFACE(d3dlimpl, IDirect3DLight);
 
     return ret_value;
@@ -306,12 +296,6 @@
     return res;
 }
 
-static void light_released(IDirectDrawImpl *This, GLenum light_num)
-{
-    IDirect3DGLImpl *glThis = (IDirect3DGLImpl *) This->d3d_private;
-    glThis->free_lights |= (light_num - GL_LIGHT0);
-}
-
 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
 # define XCAST(fun)     (typeof(VTABLE_IDirect3D7.fun))
 #else
@@ -453,9 +437,6 @@
     ICOM_INIT_INTERFACE(This, IDirect3D3, VTABLE_IDirect3D3);
     ICOM_INIT_INTERFACE(This, IDirect3D7, VTABLE_IDirect3D7);
 
-    globject->free_lights = (0x01 << MAX_LIGHTS) - 1; /* There are, in total, 8 lights in OpenGL */
-    globject->light_released = light_released;
-
     This->d3d_private = globject;
 
     TRACE(" creating OpenGL private storage at %p.\n", globject);
Index: dlls/ddraw/light.c
===================================================================
RCS file: /home/wine/wine/dlls/ddraw/light.c,v
retrieving revision 1.2
diff -u -r1.2 light.c
--- dlls/ddraw/light.c	26 Jul 2005 20:10:51 -0000	1.2
+++ dlls/ddraw/light.c	30 Oct 2005 19:20:18 -0000
@@ -156,54 +156,63 @@
  *				Light static functions
  */
 
-static void update(IDirect3DLightImpl* This) {
+static void update(IDirect3DLightImpl* This)
+{
     IDirect3DDeviceImpl* device;
-    if (!This->active_viewport||!This->active_viewport->active_device)
+
+    TRACE("(%p)\n", This);
+
+    if (!This->active_viewport || !This->active_viewport->active_device)
         return;
     device =  This->active_viewport->active_device;
-    IDirect3DDevice7_SetLight(ICOM_INTERFACE(device,IDirect3DDevice7),This->dwLightIndex,&(This->light7));
+
+    IDirect3DDevice7_SetLight(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, &(This->light7));
 }
 
-static void activate(IDirect3DLightImpl* This) {
-    IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
+static void activate(IDirect3DLightImpl* This)
+{
+    IDirect3DDeviceImpl* device;
 
     TRACE("(%p)\n", This);
+
+    if (!This->active_viewport || !This->active_viewport->active_device)
+        return;
+    device =  This->active_viewport->active_device;
     
-    ENTER_GL();
     update(This);
     /* If was not active, activate it */
-    if ((glThis->parent.light.dwFlags & D3DLIGHT_ACTIVE) == 0) {
-        glEnable(glThis->light_num);
-	glThis->parent.light.dwFlags |= D3DLIGHT_ACTIVE;
+    if ((This->light.dwFlags & D3DLIGHT_ACTIVE) == 0) {
+        IDirect3DDevice7_LightEnable(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, TRUE);
+	This->light.dwFlags |= D3DLIGHT_ACTIVE;
     }
-    LEAVE_GL();
 }
 
-static void desactivate(IDirect3DLightImpl* This) {
-    IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
-    
+static void desactivate(IDirect3DLightImpl* This)
+{
+    IDirect3DDeviceImpl* device;
+
     TRACE("(%p)\n", This);
+
+    if (!This->active_viewport || !This->active_viewport->active_device)
+        return;
+    device =  This->active_viewport->active_device;
     
-    ENTER_GL();
     /* If was not active, activate it */
-    if ((glThis->parent.light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
-        glDisable(glThis->light_num);
-	glThis->parent.light.dwFlags &= ~D3DLIGHT_ACTIVE;
+    if ((This->light.dwFlags & D3DLIGHT_ACTIVE) != 0) {
+        IDirect3DDevice7_LightEnable(ICOM_INTERFACE(device,IDirect3DDevice7), This->dwLightIndex, FALSE);
+	This->light.dwFlags &= ~D3DLIGHT_ACTIVE;
     }
-    LEAVE_GL();
 }
 
 ULONG WINAPI
 GL_IDirect3DLightImpl_1_Release(LPDIRECT3DLIGHT iface)
 {
     ICOM_THIS_FROM(IDirect3DLightImpl, IDirect3DLight, iface);
-    IDirect3DLightGLImpl *glThis = (IDirect3DLightGLImpl *) This;
     ULONG ref = InterlockedDecrement(&This->ref);
     
     TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, ref + 1);
 
     if (!ref) {
-        ((IDirect3DGLImpl *) This->d3d->d3d_private)->light_released(This->d3d, glThis->light_num);
         HeapFree(GetProcessHeap(), 0, This);
 	return 0;
     }
@@ -233,14 +242,12 @@
 
 
 
-HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d, GLenum light_num)
+HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d)
 {
     IDirect3DLightImpl *object;
-    IDirect3DLightGLImpl *gl_object;
     
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DLightGLImpl));
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DLightImpl));
     if (object == NULL) return DDERR_OUTOFMEMORY;
-    gl_object = (IDirect3DLightGLImpl *) object;
     
     object->ref = 1;
     object->d3d = d3d;
@@ -249,7 +256,6 @@
     object->desactivate = desactivate;
     object->update = update;
     object->active_viewport = NULL;
-    gl_object->light_num = light_num;
     
     ICOM_INIT_INTERFACE(object, IDirect3DLight, VTABLE_IDirect3DLight);
 
Index: dlls/ddraw/opengl_private.h
===================================================================
RCS file: /home/wine/wine/dlls/ddraw/opengl_private.h,v
retrieving revision 1.2
diff -u -r1.2 opengl_private.h
--- dlls/ddraw/opengl_private.h	12 Jun 2005 10:43:11 -0000	1.2
+++ dlls/ddraw/opengl_private.h	30 Oct 2005 19:20:21 -0000
@@ -48,16 +48,9 @@
 /* This structure is used for the 'd3d_private' field of the IDirectDraw structure */
 typedef struct IDirect3DGLImpl
 {
-    DWORD free_lights;
-    void (*light_released)(IDirectDrawImpl *, GLenum light_num);
+    int dummy; /* Empty for the moment */
 } IDirect3DGLImpl;
 
-typedef struct IDirect3DLightGLImpl
-{
-    struct IDirect3DLightImpl parent;
-    GLenum light_num;
-} IDirect3DLightGLImpl;
-
 /* This structure is used for the 'private' field of the IDirectDrawSurfaceImpl structure */
 typedef struct IDirect3DTextureGLImpl
 {
@@ -185,7 +178,7 @@
 /* All non-static functions 'exported' by various sub-objects */
 extern HRESULT direct3d_create(IDirectDrawImpl *This);
 extern HRESULT d3dtexture_create(IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surf, BOOLEAN at_creation, IDirectDrawSurfaceImpl *main_surf);
-extern HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d, GLenum light_num);
+extern HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d);
 extern HRESULT d3dexecutebuffer_create(IDirect3DExecuteBufferImpl **obj, IDirectDrawImpl *d3d, IDirect3DDeviceImpl *d3ddev, LPD3DEXECUTEBUFFERDESC lpDesc);
 extern HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirectDrawImpl *d3d);
 extern HRESULT d3dviewport_create(IDirect3DViewportImpl **obj, IDirectDrawImpl *d3d);


More information about the wine-patches mailing list