[D3D] Direct3D / DirectDraw 'merge'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The big part of this patch is a merge between the DDraw and D3D interfaces
(as in 'real' Windows they share the same reference counting). This should
fix the bug report I had recently on 'Superbike'.

The rest are just some small bug reports and some changes after testing
stuff on real Windows.

             Lionel


Changelog:
 - proper (tested on Win2K) reference counting for Direct3D object
 - fix one case of reference counting on textures
 - fix stupid bug in texture upload code
 - yet another texture enumeration reordering

-- 
		 Lionel Ulmer - http://www.bbrox.org/
--- dlls/ddraw_CVS/d3d_private.h	2003-05-21 22:42:07.000000000 +0200
+++ dlls/ddraw/d3d_private.h	2003-06-01 20:31:28.000000000 +0200
@@ -35,12 +35,10 @@
 /*****************************************************************************
  * Predeclare the interface implementation structures
  */
-typedef struct IDirect3DImpl IDirect3DImpl;
 typedef struct IDirect3DLightImpl IDirect3DLightImpl;
 typedef struct IDirect3DMaterialImpl IDirect3DMaterialImpl;
 typedef struct IDirect3DViewportImpl IDirect3DViewportImpl;
 typedef struct IDirect3DExecuteBufferImpl IDirect3DExecuteBufferImpl;
-typedef struct IDirect3DDeviceImpl IDirect3DDeviceImpl;
 typedef struct IDirect3DVertexBufferImpl IDirect3DVertexBufferImpl;
 
 #include "ddraw_private.h"
@@ -56,30 +54,6 @@
    DWORD texture_stage_state[MAX_TEXTURES][HIGHEST_TEXTURE_STAGE_STATE];
 } STATEBLOCK;
 
-/*****************************************************************************
- * IDirect3D implementation structure.
- * This is common for interfaces 1, 2, 3 and 7.
- */
-struct IDirect3DImpl
-{
-    ICOM_VFIELD_MULTI(IDirect3D7);
-    ICOM_VFIELD_MULTI(IDirect3D3);
-    ICOM_VFIELD_MULTI(IDirect3D2);
-    ICOM_VFIELD_MULTI(IDirect3D);
-    DWORD                   ref;
-    /* IDirect3D fields */
-    IDirectDrawImpl*	ddraw;
-
-    /* Used as a callback function to create a texture */
-    HRESULT (*create_texture)(IDirect3DImpl *d3d, IDirectDrawSurfaceImpl *tex, BOOLEAN at_creation, IDirectDrawSurfaceImpl *main);
-
-    /* Used as a callback for Devices to tell to the D3D object it's been created */
-    HRESULT (*added_device)(IDirect3DImpl *d3d, IDirect3DDeviceImpl *device);
-    HRESULT (*removed_device)(IDirect3DImpl *d3d, IDirect3DDeviceImpl *device);
-
-    /* This is needed for delayed texture creation and Z buffer blits */
-    IDirect3DDeviceImpl *current_device;
-};
 
 /*****************************************************************************
  * IDirect3DLight implementation structure
@@ -89,7 +63,7 @@
     ICOM_VFIELD_MULTI(IDirect3DLight);
     DWORD ref;
     /* IDirect3DLight fields */
-    IDirect3DImpl *d3d;
+    IDirectDrawImpl *d3d;
     /* If this light is active for one viewport, put the viewport here */
     IDirect3DViewportImpl *active_viewport;
 
@@ -117,7 +91,7 @@
     ICOM_VFIELD_MULTI(IDirect3DMaterial);
     DWORD  ref;
     /* IDirect3DMaterial2 fields */
-    IDirect3DImpl *d3d;
+    IDirectDrawImpl *d3d;
     IDirect3DDeviceImpl *active_device;
 
     D3DMATERIAL mat;
@@ -133,7 +107,7 @@
     ICOM_VFIELD_MULTI(IDirect3DViewport3);
     DWORD ref;
     /* IDirect3DViewport fields */
-    IDirect3DImpl *d3d;
+    IDirectDrawImpl *d3d;
     /* If this viewport is active for one device, put the device here */
     IDirect3DDeviceImpl *active_device;
 
@@ -167,7 +141,7 @@
     ICOM_VFIELD_MULTI(IDirect3DExecuteBuffer);
     DWORD ref;
     /* IDirect3DExecuteBuffer fields */
-    IDirect3DImpl *d3d;
+    IDirectDrawImpl *d3d;
     IDirect3DDeviceImpl* d3ddev;
 
     D3DEXECUTEBUFFERDESC desc;
@@ -217,7 +191,7 @@
     ICOM_VFIELD_MULTI(IDirect3DDevice);
     DWORD  ref;
     /* IDirect3DDevice fields */
-    IDirect3DImpl *d3d;
+    IDirectDrawImpl *d3d;
     IDirectDrawSurfaceImpl *surface;
 
     IDirect3DViewportImpl *viewport_list;
@@ -270,7 +244,7 @@
     ICOM_VFIELD_MULTI(IDirect3DVertexBuffer7);
     ICOM_VFIELD_MULTI(IDirect3DVertexBuffer);
     DWORD ref;
-    IDirect3DImpl *d3d;
+    IDirectDrawImpl *d3d;
     D3DVERTEXBUFFERDESC desc;
     LPVOID *vertices;
     DWORD vertex_buffer_size;
--- dlls/ddraw_CVS/d3ddevice/main.c	2003-05-25 20:59:34.000000000 +0200
+++ dlls/ddraw/d3ddevice/main.c	2003-06-01 20:16:21.000000000 +0200
@@ -318,15 +318,15 @@
 
 HRESULT WINAPI
 Main_IDirect3DDeviceImpl_7_3T_2T_1T_GetDirect3D(LPDIRECT3DDEVICE7 iface,
-						LPDIRECT3D7* lplpDirect3D3)
+						LPDIRECT3D7* lplpDirect3D7)
 {
     ICOM_THIS_FROM(IDirect3DDeviceImpl, IDirect3DDevice7, iface);
-    TRACE("(%p/%p)->(%p)\n", This, iface, lplpDirect3D3);
+    TRACE("(%p/%p)->(%p)\n", This, iface, lplpDirect3D7);
 
-    *lplpDirect3D3 = ICOM_INTERFACE(This->d3d, IDirect3D7);
+    *lplpDirect3D7 = ICOM_INTERFACE(This->d3d, IDirect3D7);
     IDirect3D7_AddRef(ICOM_INTERFACE(This->d3d, IDirect3D7));
     
-    TRACE(" returning interface %p\n", *lplpDirect3D3);
+    TRACE(" returning interface %p\n", *lplpDirect3D7);
     return DD_OK;
 }
 
@@ -812,14 +812,13 @@
 
     if (This->current_texture[dwStage] != NULL) {
         *lpTexture = ICOM_INTERFACE(This->current_texture[dwStage], IDirectDrawSurface7);
+        IDirectDrawSurface7_AddRef(*lpTexture);
     } else {
         *lpTexture = NULL;
     }
 
     TRACE(" returning interface at %p (for implementation at %p).\n", *lpTexture, This->current_texture[dwStage]);
 
-    /* Note: should this method increase the reference count for this ?? */
-
     return DD_OK;
 }
 
@@ -1559,7 +1558,7 @@
     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lplpDirect3D3);
     ret = IDirect3DDevice7_GetDirect3D(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice3, IDirect3DDevice7, iface),
 				       &ret_ptr);
-    *lplpDirect3D3 = COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D7, IDirect3D3, ret_ptr);
+    *lplpDirect3D3 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D3, ret_ptr);
     TRACE(" returning interface %p\n", *lplpDirect3D3);
     return ret;
 }
@@ -1574,7 +1573,7 @@
     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lplpDirect3D2);
     ret = IDirect3DDevice7_GetDirect3D(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice2, IDirect3DDevice7, iface),
 				       &ret_ptr);
-    *lplpDirect3D2 = COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D7, IDirect3D2, ret_ptr);
+    *lplpDirect3D2 = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D2, ret_ptr);
     TRACE(" returning interface %p\n", *lplpDirect3D2);
     return ret;
 }
@@ -1589,7 +1588,7 @@
     TRACE("(%p)->(%p) thunking to IDirect3DDevice7 interface.\n", iface, lplpDirect3D);
     ret = IDirect3DDevice7_GetDirect3D(COM_INTERFACE_CAST(IDirect3DDeviceImpl, IDirect3DDevice, IDirect3DDevice7, iface),
 				       &ret_ptr);
-    *lplpDirect3D = COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D7, IDirect3D, ret_ptr);
+    *lplpDirect3D = COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirect3D, ret_ptr);
     TRACE(" returning interface %p\n", *lplpDirect3D);
     return ret;
 }
--- dlls/ddraw_CVS/d3ddevice/mesa.c	2003-05-30 15:15:00.000000000 +0200
+++ dlls/ddraw/d3ddevice/mesa.c	2003-06-01 20:18:54.000000000 +0200
@@ -351,7 +351,7 @@
 	}
 	
 	/* And warn the D3D object that this device is no longer active... */
-	This->d3d->removed_device(This->d3d, This);
+	This->d3d->d3d_removed_device(This->d3d, This);
 
 	HeapFree(GetProcessHeap(), 0, This->world_mat);
 	HeapFree(GetProcessHeap(), 0, This->view_mat);
@@ -415,19 +415,6 @@
     pformat->dwSize = sizeof(DDPIXELFORMAT);
     pformat->dwFourCC = 0;
 
-#if 0
-    /* See argument about the RGBA format for 'packed' texture formats */
-    TRACE("Enumerating GL_RGBA unpacked (32)\n");
-    pformat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
-    pformat->u1.dwRGBBitCount = 32;
-    pformat->u2.dwRBitMask =        0xFF000000;
-    pformat->u3.dwGBitMask =        0x00FF0000;
-    pformat->u4.dwBBitMask =        0x0000FF00;
-    pformat->u5.dwRGBAlphaBitMask = 0x000000FF;
-    if (cb_1) if (cb_1(&sdesc , context) == 0) return DD_OK;
-    if (cb_2) if (cb_2(pformat, context) == 0) return DD_OK;
-#endif
-    
     TRACE("Enumerating GL_RGBA unpacked (32)\n");
     pformat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
     pformat->u1.dwRGBBitCount = 32;
@@ -438,7 +425,6 @@
     if (cb_1) if (cb_1(&sdesc , context) == 0) return DD_OK;
     if (cb_2) if (cb_2(pformat, context) == 0) return DD_OK;
 
-#if 0 /* Enabling this breaks Tomb Raider 3, need to investigate... */
     TRACE("Enumerating GL_RGB unpacked (32)\n");
     pformat->dwFlags = DDPF_RGB;
     pformat->u1.dwRGBBitCount = 32;
@@ -448,7 +434,6 @@
     pformat->u5.dwRGBAlphaBitMask = 0x00000000;
     if (cb_1) if (cb_1(&sdesc , context) == 0) return DD_OK;
     if (cb_2) if (cb_2(pformat, context) == 0) return DD_OK;
-#endif
     
     TRACE("Enumerating GL_RGB unpacked (24)\n");
     pformat->dwFlags = DDPF_RGB;
@@ -508,6 +493,17 @@
        
        So basically, forget our OpenGL roots and do not even enumerate our RGBA ones.
     */
+    /* See argument about the RGBA format for 'packed' texture formats */
+    TRACE("Enumerating GL_RGBA unpacked (32)\n");
+    pformat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
+    pformat->u1.dwRGBBitCount = 32;
+    pformat->u2.dwRBitMask =        0xFF000000;
+    pformat->u3.dwGBitMask =        0x00FF0000;
+    pformat->u4.dwBBitMask =        0x0000FF00;
+    pformat->u5.dwRGBAlphaBitMask = 0x000000FF;
+    if (cb_1) if (cb_1(&sdesc , context) == 0) return DD_OK;
+    if (cb_2) if (cb_2(pformat, context) == 0) return DD_OK;
+    
     TRACE("Enumerating GL_RGBA packed GL_UNSIGNED_SHORT_4_4_4_4 (16)\n");
     pformat->dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
     pformat->u1.dwRGBBitCount = 16;
@@ -555,7 +551,7 @@
 
 
 HRESULT
-d3ddevice_find(IDirect3DImpl *d3d,
+d3ddevice_find(IDirectDrawImpl *d3d,
 	       LPD3DFINDDEVICESEARCH lpD3DDFS,
 	       LPD3DFINDDEVICERESULT lplpD3DDevice)
 {
@@ -3094,7 +3090,7 @@
 }     
 
 HRESULT
-d3ddevice_create(IDirect3DDeviceImpl **obj, IDirect3DImpl *d3d, IDirectDrawSurfaceImpl *surface)
+d3ddevice_create(IDirect3DDeviceImpl **obj, IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surface)
 {
     IDirect3DDeviceImpl *object;
     IDirect3DDeviceGLImpl *gl_object;
@@ -3253,7 +3249,7 @@
     TRACE(" creating implementation at %p.\n", *obj);
 
     /* And finally warn D3D that this device is now present */
-    object->d3d->added_device(object->d3d, object);
+    object->d3d->d3d_added_device(object->d3d, object);
 
     /* FIXME: Should handle other versions than just 7 */
     InitDefaultStateBlock(&object->state_block, 7);
--- dlls/ddraw_CVS/d3dexecutebuffer.c	2003-05-26 13:50:09.000000000 +0200
+++ dlls/ddraw/d3dexecutebuffer.c	2003-06-01 20:19:19.000000000 +0200
@@ -661,7 +661,7 @@
 #endif
 
 
-HRESULT d3dexecutebuffer_create(IDirect3DExecuteBufferImpl **obj, IDirect3DImpl *d3d, IDirect3DDeviceImpl *d3ddev, LPD3DEXECUTEBUFFERDESC lpDesc)
+HRESULT d3dexecutebuffer_create(IDirect3DExecuteBufferImpl **obj, IDirectDrawImpl *d3d, IDirect3DDeviceImpl *d3ddev, LPD3DEXECUTEBUFFERDESC lpDesc)
 {
     IDirect3DExecuteBufferImpl* object;
 
--- dlls/ddraw_CVS/d3dlight.c	2003-05-21 22:42:08.000000000 +0200
+++ dlls/ddraw/d3dlight.c	2003-06-01 20:19:35.000000000 +0200
@@ -221,7 +221,7 @@
 
 
 
-HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirect3DImpl *d3d, GLenum light_num)
+HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirectDrawImpl *d3d, GLenum light_num)
 {
     IDirect3DLightImpl *object;
     IDirect3DLightGLImpl *gl_object;
--- dlls/ddraw_CVS/d3dmaterial.c	2003-01-30 22:07:23.000000000 +0100
+++ dlls/ddraw/d3dmaterial.c	2003-06-01 20:19:51.000000000 +0200
@@ -388,7 +388,7 @@
 
 
 
-HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirect3DImpl *d3d)
+HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirectDrawImpl *d3d)
 {
     IDirect3DMaterialImpl *object;
 
--- dlls/ddraw_CVS/d3dtexture.c	2003-05-30 20:06:43.000000000 +0200
+++ dlls/ddraw/d3dtexture.c	2003-06-01 20:20:09.000000000 +0200
@@ -650,7 +650,7 @@
 #undef XCAST
 #endif
 
-HRESULT d3dtexture_create(IDirect3DImpl *d3d, IDirectDrawSurfaceImpl *surf, BOOLEAN at_creation, 
+HRESULT d3dtexture_create(IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surf, BOOLEAN at_creation, 
 			  IDirectDrawSurfaceImpl *main)
 {
     /* First, initialize the texture vtables... */
--- dlls/ddraw_CVS/d3dvertexbuffer.c	2003-05-21 22:42:08.000000000 +0200
+++ dlls/ddraw/d3dvertexbuffer.c	2003-06-01 20:20:23.000000000 +0200
@@ -507,7 +507,7 @@
 #undef XCAST
 #endif
 
-HRESULT d3dvertexbuffer_create(IDirect3DVertexBufferImpl **obj, IDirect3DImpl *d3d, LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc, DWORD dwFlags)
+HRESULT d3dvertexbuffer_create(IDirect3DVertexBufferImpl **obj, IDirectDrawImpl *d3d, LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc, DWORD dwFlags)
 {
     IDirect3DVertexBufferImpl *object;
     static const flag_info flags[] = {
--- dlls/ddraw_CVS/d3dviewport.c	2003-05-21 22:42:08.000000000 +0200
+++ dlls/ddraw/d3dviewport.c	2003-06-01 20:20:43.000000000 +0200
@@ -479,7 +479,7 @@
 
 
 
-HRESULT d3dviewport_create(IDirect3DViewportImpl **obj, IDirect3DImpl *d3d)
+HRESULT d3dviewport_create(IDirect3DViewportImpl **obj, IDirectDrawImpl *d3d)
 {
     IDirect3DViewportImpl *object;
 
--- dlls/ddraw_CVS/ddraw/main.c	2003-05-24 01:37:13.000000000 +0200
+++ dlls/ddraw/ddraw/main.c	2003-06-01 20:39:16.000000000 +0200
@@ -185,28 +185,24 @@
 	      IsEqualGUID( &IID_IDirect3D7 , refiid ) )
     {
         if (opengl_initialized) {
-	    IDirect3DImpl *d3d_impl;
 	    HRESULT ret_value;
 
-	    ret_value = direct3d_create(&d3d_impl, This);
+	    ret_value = direct3d_create(This);
 	    if (FAILED(ret_value)) return ret_value;
 	    
 	    if ( IsEqualGUID( &IID_IDirect3D  , refiid ) ) {
-	        *obj = ICOM_INTERFACE(d3d_impl, IDirect3D);
+	        *obj = ICOM_INTERFACE(This, IDirect3D);
 		TRACE(" returning Direct3D interface at %p.\n", *obj);	    
 	    } else if ( IsEqualGUID( &IID_IDirect3D2  , refiid ) ) {
-	        *obj = ICOM_INTERFACE(d3d_impl, IDirect3D2);
+	        *obj = ICOM_INTERFACE(This, IDirect3D2);
 		TRACE(" returning Direct3D2 interface at %p.\n", *obj);	    
 	    } else if ( IsEqualGUID( &IID_IDirect3D3  , refiid ) ) {
-	        *obj = ICOM_INTERFACE(d3d_impl, IDirect3D3);
+	        *obj = ICOM_INTERFACE(This, IDirect3D3);
 		TRACE(" returning Direct3D3 interface at %p.\n", *obj);	    
 	    } else {
-	        *obj = ICOM_INTERFACE(d3d_impl, IDirect3D7);
+	        *obj = ICOM_INTERFACE(This, IDirect3D7);
 		TRACE(" returning Direct3D7 interface at %p.\n", *obj);	    
 	    }
-
-	    /* And store the D3D object */
-	    This->d3d = d3d_impl;
 	} else {
 	    ERR("Application requests a Direct3D interface but dynamic OpenGL support loading failed !\n");
 	    ERR("(%p)->(%s,%p): no interface\n",This,debugstr_guid(refiid),obj);
@@ -384,8 +380,8 @@
     hr = This->create_texture(This, &ddsd, ppSurf, pUnkOuter, mipmap_level);
     if (FAILED(hr)) return hr;
 
-    if (This->d3d) This->d3d->create_texture(This->d3d, ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, *ppSurf), TRUE, 
-					     ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, *ppSurf));
+    if (This->d3d_private) This->d3d_create_texture(This, ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, *ppSurf), TRUE, 
+						    ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, *ppSurf));
 
     /* Create attached mipmaps if required. */
     if (more_mipmaps(&ddsd))
@@ -430,8 +426,8 @@
 	    mipmap_impl->mip_main = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, *ppSurf);
 	    mipmap_impl->mipmap_level = mipmap_level;
 
-	    if (This->d3d) This->d3d->create_texture(This->d3d, ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, mipmap), TRUE,
-						     ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, *ppSurf));
+	    if (This->d3d_private) This->d3d_create_texture(This, ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, mipmap), TRUE,
+							    ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, *ppSurf));
 
 	    IDirectDrawSurface7_AddAttachedSurface(prev_mipmap, mipmap);
 	    IDirectDrawSurface7_Release(prev_mipmap);
--- dlls/ddraw_CVS/ddraw_private.h	2003-05-24 01:37:13.000000000 +0200
+++ dlls/ddraw/ddraw_private.h	2003-06-01 20:31:03.000000000 +0200
@@ -58,6 +58,7 @@
 typedef struct IDirectDrawPaletteImpl IDirectDrawPaletteImpl;
 typedef struct IDirectDrawClipperImpl IDirectDrawClipperImpl;
 typedef struct IDirectDrawSurfaceImpl IDirectDrawSurfaceImpl;
+typedef struct IDirect3DDeviceImpl IDirect3DDeviceImpl;
 
 typedef void (*pixel_convert_func)(void *src, void *dst, DWORD width,
 				   DWORD height, LONG pitch,
@@ -73,6 +74,10 @@
     ICOM_VFIELD_MULTI(IDirectDraw4);
     ICOM_VFIELD_MULTI(IDirectDraw2);
     ICOM_VFIELD_MULTI(IDirectDraw);
+    ICOM_VFIELD_MULTI(IDirect3D7);
+    ICOM_VFIELD_MULTI(IDirect3D3);
+    ICOM_VFIELD_MULTI(IDirect3D2);
+    ICOM_VFIELD_MULTI(IDirect3D);
 
     DWORD ref;
 
@@ -159,9 +164,19 @@
     void (*free_memory)(IDirectDrawImpl *This, DWORD mem);
     DWORD total_vidmem, available_vidmem;
     
-    /* This is to get the D3D object associated to this DDraw object */
-    struct IDirect3DImpl *d3d;
-    
+    /* IDirect3D fields */
+    LPVOID d3d_private;
+
+    /* Used as a callback function to create a texture */
+    HRESULT (*d3d_create_texture)(IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *tex, BOOLEAN at_creation, IDirectDrawSurfaceImpl *main);
+
+    /* Used as a callback for Devices to tell to the D3D object it's been created */
+    HRESULT (*d3d_added_device)(IDirectDrawImpl *d3d, IDirect3DDeviceImpl *device);
+    HRESULT (*d3d_removed_device)(IDirectDrawImpl *d3d, IDirect3DDeviceImpl *device);
+
+    /* This is needed for delayed texture creation and Z buffer blits */
+    IDirect3DDeviceImpl *current_device;
+
     /* This is for the fake mainWindow */
     ATOM	winclass;
     PAINTSTRUCT	ps;
--- dlls/ddraw_CVS/direct3d/main.c	2003-05-16 09:51:47.000000000 +0200
+++ dlls/ddraw/direct3d/main.c	2003-06-01 20:28:59.000000000 +0200
@@ -35,96 +35,12 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
 
-HRESULT WINAPI
-Main_IDirect3DImpl_7_3T_2T_1T_QueryInterface(LPDIRECT3D7 iface,
-                                             REFIID riid,
-                                             LPVOID* obp)
-{
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D7, iface);
-
-    TRACE("(%p/%p)->(%s,%p)\n", This, iface, debugstr_guid(riid), obp);
-
-    /* By default, set the object pointer to NULL */
-    *obp = NULL;
-      
-    if (( IsEqualGUID( &IID_IDirectDraw,  riid ) ) ||
-	( IsEqualGUID (&IID_IDirectDraw2, riid ) ) ||
-	( IsEqualGUID (&IID_IDirectDraw4, riid ) ) ||
-	( IsEqualGUID( &IID_IDirectDraw7, riid ) )
-    ) {
-        HRESULT ret;
-	TRACE("  Creating IDirectDrawX interface by calling DirectDraw function.\n");
-	ret = IDirectDraw_QueryInterface(ICOM_INTERFACE(This->ddraw,IDirectDraw), riid, obp);
-	if (ret == S_OK) {
-	    IDirectDraw_Release(ICOM_INTERFACE(This->ddraw,IDirectDraw));
-	    IDirect3D_AddRef(ICOM_INTERFACE(This,IDirect3D));
-	}
-	return ret;
-    }
-    if ( IsEqualGUID( &IID_IUnknown,  riid ) ) {
-        IDirect3D_AddRef(ICOM_INTERFACE(This,IDirect3D));
-	*obp = iface;
-	TRACE("  Creating IUnknown interface at %p.\n", *obp);
-	return S_OK;
-    }
-    if ( IsEqualGUID( &IID_IDirect3D, riid ) ) {
-        IDirect3D_AddRef(ICOM_INTERFACE(This,IDirect3D));
-        *obp = ICOM_INTERFACE(This, IDirect3D);
-	TRACE("  Creating IDirect3D interface %p\n", *obp);
-	return S_OK;
-    }
-    if ( IsEqualGUID( &IID_IDirect3D2, riid ) ) {
-        IDirect3D_AddRef(ICOM_INTERFACE(This,IDirect3D));
-        *obp = ICOM_INTERFACE(This, IDirect3D2);
-	TRACE("  Creating IDirect3D2 interface %p\n", *obp);
-	return S_OK;
-    }
-    if ( IsEqualGUID( &IID_IDirect3D3, riid ) ) {
-        IDirect3D_AddRef(ICOM_INTERFACE(This,IDirect3D));
-        *obp = ICOM_INTERFACE(This, IDirect3D3);
-	TRACE("  Creating IDirect3D3 interface %p\n", *obp);
-	return S_OK;
-    }
-    if ( IsEqualGUID( &IID_IDirect3D7, riid ) ) {
-        /* This is not 100 % true as we should not be able to QueryInterface a '7' version from another one.
-	   But well, to factorize the code, why check for application bugs :-) ?
-	 */
-        IDirect3D_AddRef(ICOM_INTERFACE(This,IDirect3D));
-        *obp = ICOM_INTERFACE(This, IDirect3D7);
-	TRACE("  Creating IDirect3D7 interface %p\n", *obp);
-	return S_OK;
-    }
-    FIXME("(%p): interface for IID %s NOT found!\n", This, debugstr_guid(riid));
-    return OLE_E_ENUM_NOMORE;
-}
-
-ULONG WINAPI
-Main_IDirect3DImpl_7_3T_2T_1T_AddRef(LPDIRECT3D7 iface)
-{
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D7, iface);
-    TRACE("(%p/%p)->() incrementing from %lu.\n", This, iface, This->ref);
-
-    return ++(This->ref);
-}
-
-ULONG WINAPI
-Main_IDirect3DImpl_7_3T_2T_1T_Release(LPDIRECT3D7 iface)
-{
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D7, iface);
-    TRACE("(%p/%p)->() decrementing from %lu.\n", This, iface, This->ref);
-    if (--(This->ref) == 0) {
-        IDirectDraw_Release(ICOM_INTERFACE(This->ddraw, IDirectDraw));
-	HeapFree(GetProcessHeap(), 0, This);
-	return 0;
-    }
-    return This->ref;
-}
 
 HRESULT WINAPI
 Main_IDirect3DImpl_1_Initialize(LPDIRECT3D iface,
                                 REFIID riid)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
     TRACE("(%p/%p)->(%s) no-op...\n", This, iface, debugstr_guid(riid));
     return D3D_OK;
 }
@@ -134,7 +50,7 @@
                                        LPD3DENUMDEVICESCALLBACK lpEnumDevicesCallback,
                                        LPVOID lpUserArg)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D3, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpEnumDevicesCallback, lpUserArg);
     return D3D_OK;
 }
@@ -144,7 +60,7 @@
                                        LPDIRECT3DLIGHT* lplpDirect3DLight,
                                        IUnknown* pUnkOuter)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D3, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lplpDirect3DLight, pUnkOuter);
     return D3D_OK;
 }
@@ -154,7 +70,7 @@
 					  LPDIRECT3DMATERIAL3* lplpDirect3DMaterial3,
 					  IUnknown* pUnkOuter)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D3, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lplpDirect3DMaterial3, pUnkOuter);
     return D3D_OK;
 }
@@ -164,7 +80,7 @@
 					  LPDIRECT3DVIEWPORT3* lplpD3DViewport3,
 					  IUnknown* pUnkOuter)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D3, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lplpD3DViewport3, pUnkOuter);
     return D3D_OK;
 }
@@ -174,7 +90,7 @@
 				      LPD3DFINDDEVICESEARCH lpD3DDFS,
 				      LPD3DFINDDEVICERESULT lpD3DFDR)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D3, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpD3DDFS, lpD3DFDR);
     return D3D_OK;
 }
@@ -185,7 +101,7 @@
                                   LPDIRECTDRAWSURFACE lpDDS,
                                   LPDIRECT3DDEVICE2* lplpD3DDevice2)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D2, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
     FIXME("(%p/%p)->(%s,%p,%p): stub!\n", This, iface, debugstr_guid(rclsid), lpDDS, lplpD3DDevice2);
     return D3D_OK;
 }
@@ -197,7 +113,7 @@
                                   LPDIRECT3DDEVICE3* lplpD3DDevice3,
                                   LPUNKNOWN lpUnk)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D3, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
     FIXME("(%p/%p)->(%s,%p,%p,%p): stub!\n", This, iface, debugstr_guid(rclsid), lpDDS, lplpD3DDevice3, lpUnk);
     return D3D_OK;
 }
@@ -208,7 +124,7 @@
                                            LPD3DENUMPIXELFORMATSCALLBACK lpEnumCallback,
                                            LPVOID lpContext)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D7, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
     FIXME("(%p/%p)->(%s,%p,%p): stub!\n", This, iface, debugstr_guid(riidDevice), lpEnumCallback, lpContext);
     return D3D_OK;
 }
@@ -216,7 +132,7 @@
 HRESULT WINAPI
 Main_IDirect3DImpl_7_3T_EvictManagedTextures(LPDIRECT3D7 iface)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D7, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
     FIXME("(%p/%p)->(): stub!\n", This, iface);
     return D3D_OK;
 }
@@ -226,7 +142,7 @@
                                  LPD3DENUMDEVICESCALLBACK7 lpEnumDevicesCallback,
                                  LPVOID lpUserArg)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D7, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
     FIXME("(%p/%p)->(%p,%p): stub!\n", This, iface, lpEnumDevicesCallback, lpUserArg);
     return D3D_OK;
 }
@@ -237,7 +153,7 @@
                                   LPDIRECTDRAWSURFACE7 lpDDS,
                                   LPDIRECT3DDEVICE7* lplpD3DDevice)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D7, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
     FIXME("(%p/%p)->(%s,%p,%p): stub!\n", This, iface, debugstr_guid(rclsid), lpDDS, lplpD3DDevice);
     return D3D_OK;
 }
@@ -248,20 +164,31 @@
 					   LPDIRECT3DVERTEXBUFFER7* lplpD3DVertBuf,
 					   DWORD dwFlags)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D7, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
     FIXME("(%p/%p)->(%p,%p,%08lx): stub!\n", This, iface, lpD3DVertBufDesc, lplpD3DVertBuf, dwFlags);
     return D3D_OK;
 }
 
 HRESULT WINAPI
+Thunk_IDirect3DImpl_7_QueryInterface(LPDIRECT3D7 iface,
+                                     REFIID riid,
+                                     LPVOID* obp)
+{
+    TRACE("(%p)->(%s,%p) thunking to IDirectDraw7 interface.\n", iface, debugstr_guid(riid), obp);
+    return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirectDraw7, iface),
+				       riid,
+				       obp);
+}
+
+HRESULT WINAPI
 Thunk_IDirect3DImpl_3_QueryInterface(LPDIRECT3D3 iface,
                                      REFIID riid,
                                      LPVOID* obp)
 {
-    TRACE("(%p)->(%s,%p) thunking to IDirect3D7 interface.\n", iface, debugstr_guid(riid), obp);
-    return IDirect3D7_QueryInterface(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D3, IDirect3D7, iface),
-                                     riid,
-                                     obp);
+    TRACE("(%p)->(%s,%p) thunking to IDirectDraw7 interface.\n", iface, debugstr_guid(riid), obp);
+    return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D3, IDirectDraw7, iface),
+				       riid,
+				       obp);
 }
 
 HRESULT WINAPI
@@ -269,10 +196,10 @@
                                      REFIID riid,
                                      LPVOID* obp)
 {
-    TRACE("(%p)->(%s,%p) thunking to IDirect3D7 interface.\n", iface, debugstr_guid(riid), obp);
-    return IDirect3D7_QueryInterface(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D2, IDirect3D7, iface),
-                                     riid,
-                                     obp);
+    TRACE("(%p)->(%s,%p) thunking to IDirectDraw7 interface.\n", iface, debugstr_guid(riid), obp);
+    return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirectDraw7, iface),
+				       riid,
+				       obp);
 }
 
 HRESULT WINAPI
@@ -280,52 +207,66 @@
                                      REFIID riid,
                                      LPVOID* obp)
 {
-    TRACE("(%p)->(%s,%p) thunking to IDirect3D7 interface.\n", iface, debugstr_guid(riid), obp);
-    return IDirect3D7_QueryInterface(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D, IDirect3D7, iface),
-                                     riid,
-                                     obp);
+    TRACE("(%p)->(%s,%p) thunking to IDirectDraw7 interface.\n", iface, debugstr_guid(riid), obp);
+    return IDirectDraw7_QueryInterface(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirectDraw7, iface),
+				       riid,
+				       obp);
+}
+
+ULONG WINAPI
+Thunk_IDirect3DImpl_7_AddRef(LPDIRECT3D7 iface)
+{
+    TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
+    return IDirectDraw7_AddRef(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirectDraw7, iface));
 }
 
 ULONG WINAPI
 Thunk_IDirect3DImpl_3_AddRef(LPDIRECT3D3 iface)
 {
-    TRACE("(%p)->() thunking to IDirect3D7 interface.\n", iface);
-    return IDirect3D7_AddRef(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D3, IDirect3D7, iface));
+    TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
+    return IDirectDraw7_AddRef(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D3, IDirectDraw7, iface));
 }
 
 ULONG WINAPI
 Thunk_IDirect3DImpl_2_AddRef(LPDIRECT3D2 iface)
 {
-    TRACE("(%p)->() thunking to IDirect3D7 interface.\n", iface);
-    return IDirect3D7_AddRef(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D2, IDirect3D7, iface));
+    TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
+    return IDirectDraw7_AddRef(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirectDraw7, iface));
 }
 
 ULONG WINAPI
 Thunk_IDirect3DImpl_1_AddRef(LPDIRECT3D iface)
 {
-    TRACE("(%p)->() thunking to IDirect3D7 interface.\n", iface);
-    return IDirect3D7_AddRef(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D, IDirect3D7, iface));
+    TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
+    return IDirectDraw7_AddRef(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirectDraw7, iface));
+}
+
+ULONG WINAPI
+Thunk_IDirect3DImpl_7_Release(LPDIRECT3D7 iface)
+{
+    TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
+    return IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D7, IDirectDraw7, iface));
 }
 
 ULONG WINAPI
 Thunk_IDirect3DImpl_3_Release(LPDIRECT3D3 iface)
 {
-    TRACE("(%p)->() thunking to IDirect3D7 interface.\n", iface);
-    return IDirect3D7_Release(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D3, IDirect3D7, iface));
+    TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
+    return IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D3, IDirectDraw7, iface));
 }
 
 ULONG WINAPI
 Thunk_IDirect3DImpl_2_Release(LPDIRECT3D2 iface)
 {
-    TRACE("(%p)->() thunking to IDirect3D7 interface.\n", iface);
-    return IDirect3D7_Release(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D2, IDirect3D7, iface));
+    TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
+    return IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirectDraw7, iface));
 }
 
 ULONG WINAPI
 Thunk_IDirect3DImpl_1_Release(LPDIRECT3D iface)
 {
-    TRACE("(%p)->() thunking to IDirect3D7 interface.\n", iface);
-    return IDirect3D7_Release(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D, IDirect3D7, iface));
+    TRACE("(%p)->() thunking to IDirectDraw7 interface.\n", iface);
+    return IDirectDraw7_Release(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirectDraw7, iface));
 }
 
 HRESULT WINAPI
@@ -335,7 +276,7 @@
                                          LPVOID lpContext)
 {
     TRACE("(%p)->(%s,%p,%p) thunking to IDirect3D7 interface.\n", iface, debugstr_guid(riidDevice), lpEnumCallback, lpContext);
-    return IDirect3D7_EnumZBufferFormats(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D3, IDirect3D7, iface),
+    return IDirect3D7_EnumZBufferFormats(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D3, IDirect3D7, iface),
                                          riidDevice,
                                          lpEnumCallback,
                                          lpContext);
@@ -345,7 +286,7 @@
 Thunk_IDirect3DImpl_3_EvictManagedTextures(LPDIRECT3D3 iface)
 {
     TRACE("(%p)->() thunking to IDirect3D7 interface.\n", iface);
-    return IDirect3D7_EvictManagedTextures(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D3, IDirect3D7, iface));
+    return IDirect3D7_EvictManagedTextures(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D3, IDirect3D7, iface));
 }
 
 HRESULT WINAPI
@@ -354,7 +295,7 @@
                                   LPVOID lpUserArg)
 {
     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lpEnumDevicesCallback, lpUserArg);
-    return IDirect3D3_EnumDevices(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D2, IDirect3D3, iface),
+    return IDirect3D3_EnumDevices(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirect3D3, iface),
                                   lpEnumDevicesCallback,
                                   lpUserArg);
 }
@@ -365,7 +306,7 @@
                                   IUnknown* pUnkOuter)
 {
     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lplpDirect3DLight, pUnkOuter);
-    return IDirect3D3_CreateLight(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D2, IDirect3D3, iface),
+    return IDirect3D3_CreateLight(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirect3D3, iface),
                                   lplpDirect3DLight,
                                   pUnkOuter);
 }
@@ -376,7 +317,7 @@
                                   IUnknown* pUnkOuter)
 {
     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lplpDirect3DLight, pUnkOuter);
-    return IDirect3D3_CreateLight(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D, IDirect3D3, iface),
+    return IDirect3D3_CreateLight(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirect3D3, iface),
                                   lplpDirect3DLight,
                                   pUnkOuter);
 }
@@ -390,7 +331,7 @@
     LPDIRECT3DMATERIAL3 ret_val;
 
     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lplpDirect3DMaterial, pUnkOuter);
-    ret = IDirect3D3_CreateMaterial(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D, IDirect3D3, iface),
+    ret = IDirect3D3_CreateMaterial(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirect3D3, iface),
 				    &ret_val,
 				    pUnkOuter);
 
@@ -407,7 +348,7 @@
 				     IUnknown* pUnkOuter)
 {
     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lplpD3DViewport, pUnkOuter);
-    return IDirect3D3_CreateViewport(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D, IDirect3D3, iface),
+    return IDirect3D3_CreateViewport(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirect3D3, iface),
 				    (LPDIRECT3DVIEWPORT3 *) lplpD3DViewport /* No need to cast here */,
 				    pUnkOuter);
 }
@@ -421,7 +362,7 @@
     LPDIRECT3DMATERIAL3 ret_val;
 
     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lplpDirect3DMaterial2, pUnkOuter);
-    ret = IDirect3D3_CreateMaterial(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D2, IDirect3D3, iface),
+    ret = IDirect3D3_CreateMaterial(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirect3D3, iface),
 				    &ret_val,
 				    pUnkOuter);
 
@@ -438,7 +379,7 @@
 				     IUnknown* pUnkOuter)
 {
     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lplpD3DViewport2, pUnkOuter);
-    return IDirect3D3_CreateViewport(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D2, IDirect3D3, iface),
+    return IDirect3D3_CreateViewport(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirect3D3, iface),
 				     (LPDIRECT3DVIEWPORT3 *) lplpD3DViewport2 /* No need to cast here */,
 				     pUnkOuter);
 }
@@ -459,7 +400,7 @@
     /* dwFlags is not used in the D3D7 interface, use the vertex buffer description instead */
     if (dwFlags & D3DDP_DONOTCLIP) lpD3DVertBufDesc->dwCaps |= D3DVBCAPS_DONOTCLIP;
 
-    ret = IDirect3D7_CreateVertexBuffer(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D3, IDirect3D7, iface),
+    ret = IDirect3D7_CreateVertexBuffer(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D3, IDirect3D7, iface),
 					lpD3DVertBufDesc,
 					&ret_val,
 					dwFlags);
@@ -477,7 +418,7 @@
 				 LPD3DFINDDEVICERESULT lplpD3DDevice)
 {
     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lpD3DDFS, lplpD3DDevice);
-    return IDirect3D3_FindDevice(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D, IDirect3D3, iface),
+    return IDirect3D3_FindDevice(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D, IDirect3D3, iface),
 				 lpD3DDFS,
 				 lplpD3DDevice);
 }
@@ -488,7 +429,7 @@
 				 LPD3DFINDDEVICERESULT lpD3DFDR)
 {
     TRACE("(%p)->(%p,%p) thunking to IDirect3D3 interface.\n", iface, lpD3DDFS, lpD3DFDR);
-    return IDirect3D3_FindDevice(COM_INTERFACE_CAST(IDirect3DImpl, IDirect3D2, IDirect3D3, iface),
+    return IDirect3D3_FindDevice(COM_INTERFACE_CAST(IDirectDrawImpl, IDirect3D2, IDirect3D3, iface),
 				 lpD3DDFS,
 				 lpD3DFDR);
 }
--- dlls/ddraw_CVS/direct3d/mesa.c	2003-05-16 09:51:47.000000000 +0200
+++ dlls/ddraw/direct3d/mesa.c	2003-06-01 20:36:38.000000000 +0200
@@ -47,7 +47,7 @@
 			       LPD3DENUMDEVICESCALLBACK lpEnumDevicesCallback,
 			       LPVOID lpUserArg)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D, iface);
     TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpEnumDevicesCallback, lpUserArg);
 
     /* Call functions defined in d3ddevices.c */
@@ -62,7 +62,7 @@
 				  LPD3DENUMDEVICESCALLBACK lpEnumDevicesCallback,
 				  LPVOID lpUserArg)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D3, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
     TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpEnumDevicesCallback, lpUserArg);
 
     /* Call functions defined in d3ddevices.c */
@@ -77,7 +77,7 @@
 				     LPDIRECT3DLIGHT* lplpDirect3DLight,
 				     IUnknown* pUnkOuter)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D3, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
     IDirect3DGLImpl *glThis = (IDirect3DGLImpl *) This;
     int fl;
     IDirect3DLightImpl *d3dlimpl;
@@ -106,7 +106,7 @@
 {
     IDirect3DMaterialImpl *D3Dmat_impl;
     HRESULT ret_value;
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D3, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
     
     TRACE("(%p/%p)->(%p,%p)\n", This, iface, lplpDirect3DMaterial3, pUnkOuter);
     ret_value = d3dmaterial_create(&D3Dmat_impl, This);
@@ -123,7 +123,7 @@
 {
     IDirect3DViewportImpl *D3Dvp_impl;
     HRESULT ret_value;
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D3, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
     
     TRACE("(%p/%p)->(%p,%p)\n", This, iface, lplpD3DViewport3, pUnkOuter);
     ret_value = d3dviewport_create(&D3Dvp_impl, This);
@@ -134,7 +134,7 @@
 }
 
 static HRESULT
-create_device_helper(IDirect3DImpl *This,
+create_device_helper(IDirectDrawImpl *This,
 		     REFCLSID iid,
 		     IDirectDrawSurfaceImpl *lpDDS,
 		     void **obj,
@@ -186,7 +186,7 @@
 				LPDIRECTDRAWSURFACE lpDDS,
 				LPDIRECT3DDEVICE2* lplpD3DDevice2)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D2, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D2, iface);
     IDirectDrawSurfaceImpl *ddsurfaceimpl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface3, lpDDS);
     TRACE("(%p/%p)->(%s,%p,%p)\n", This, iface, debugstr_guid(rclsid), lpDDS, lplpD3DDevice2);
     return create_device_helper(This, rclsid, ddsurfaceimpl, (void **) lplpD3DDevice2, 2);
@@ -199,7 +199,7 @@
 				LPDIRECT3DDEVICE3* lplpD3DDevice3,
 				LPUNKNOWN lpUnk)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D3, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
     IDirectDrawSurfaceImpl *ddsurfaceimpl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, lpDDS);
     TRACE("(%p/%p)->(%s,%p,%p)\n", This, iface, debugstr_guid(rclsid), lpDDS, lplpD3DDevice3);
     return create_device_helper(This, rclsid, ddsurfaceimpl, (void **) lplpD3DDevice3, 3);
@@ -210,7 +210,7 @@
 				    LPD3DFINDDEVICESEARCH lpD3DDFS,
 				    LPD3DFINDDEVICERESULT lpD3DFDR)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D3, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D3, iface);
     TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpD3DDFS, lpD3DFDR);
     return d3ddevice_find(This, lpD3DDFS, lpD3DFDR);
 }
@@ -221,7 +221,7 @@
 					 LPD3DENUMPIXELFORMATSCALLBACK lpEnumCallback,
 					 LPVOID lpContext)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D7, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
     DDPIXELFORMAT pformat;
     
     TRACE("(%p/%p)->(%s,%p,%p)\n", This, iface, debugstr_guid(riidDevice), lpEnumCallback, lpContext);
@@ -246,7 +246,7 @@
 			       LPD3DENUMDEVICESCALLBACK7 lpEnumDevicesCallback,
 			       LPVOID lpUserArg)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D7, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
     TRACE("(%p/%p)->(%p,%p)\n", This, iface, lpEnumDevicesCallback, lpUserArg);
 
     if (d3ddevice_enumerate7(lpEnumDevicesCallback, lpUserArg) != D3DENUMRET_OK)
@@ -261,7 +261,7 @@
 				LPDIRECTDRAWSURFACE7 lpDDS,
 				LPDIRECT3DDEVICE7* lplpD3DDevice)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D7, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
     IDirectDrawSurfaceImpl *ddsurfaceimpl = ICOM_OBJECT(IDirectDrawSurfaceImpl, IDirectDrawSurface7, lpDDS);
     TRACE("(%p/%p)->(%s,%p,%p)\n", This, iface, debugstr_guid(rclsid), lpDDS, lplpD3DDevice);
     return create_device_helper(This, rclsid, ddsurfaceimpl, (void **) lplpD3DDevice, 7);
@@ -273,7 +273,7 @@
 					 LPDIRECT3DVERTEXBUFFER7* lplpD3DVertBuf,
 					 DWORD dwFlags)
 {
-    ICOM_THIS_FROM(IDirect3DImpl, IDirect3D7, iface);
+    ICOM_THIS_FROM(IDirectDrawImpl, IDirect3D7, iface);
     IDirect3DVertexBufferImpl *vbimpl;
     HRESULT res;
     
@@ -286,7 +286,7 @@
     return res;
 }
 
-static void light_released(IDirect3DImpl *This, GLenum light_num)
+static void light_released(IDirectDrawImpl *This, GLenum light_num)
 {
     IDirect3DGLImpl *glThis = (IDirect3DGLImpl *) This;
     glThis->free_lights |= (light_num - GL_LIGHT0);
@@ -301,9 +301,9 @@
 ICOM_VTABLE(IDirect3D7) VTABLE_IDirect3D7 =
 {
     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
-    XCAST(QueryInterface) Main_IDirect3DImpl_7_3T_2T_1T_QueryInterface,
-    XCAST(AddRef) Main_IDirect3DImpl_7_3T_2T_1T_AddRef,
-    XCAST(Release) Main_IDirect3DImpl_7_3T_2T_1T_Release,
+    XCAST(QueryInterface) Thunk_IDirect3DImpl_7_QueryInterface,
+    XCAST(AddRef) Thunk_IDirect3DImpl_7_AddRef,
+    XCAST(Release) Thunk_IDirect3DImpl_7_Release,
     XCAST(EnumDevices) GL_IDirect3DImpl_7_EnumDevices,
     XCAST(CreateDevice) GL_IDirect3DImpl_7_CreateDevice,
     XCAST(CreateVertexBuffer) GL_IDirect3DImpl_7_3T_CreateVertexBuffer,
@@ -393,13 +393,13 @@
 #undef XCAST
 #endif
 
-static HRESULT d3d_add_device(IDirect3DImpl *This, IDirect3DDeviceImpl *device)
+static HRESULT d3d_add_device(IDirectDrawImpl *This, IDirect3DDeviceImpl *device)
 {
     if  (This->current_device == NULL) {
         /* Create delayed textures now that we have an OpenGL context...
 	   For that, go through all surface attached to our DDraw object and create
 	   OpenGL textures for all textures.. */
-        IDirectDrawSurfaceImpl *surf = This->ddraw->surfaces;
+        IDirectDrawSurfaceImpl *surf = This->surfaces;
 
 	while (surf != NULL) {
 	    if (surf->surface_desc.ddsCaps.dwCaps & DDSCAPS_TEXTURE) {
@@ -415,38 +415,34 @@
     return DD_OK;
 }
 
-static HRESULT d3d_remove_device(IDirect3DImpl *This, IDirect3DDeviceImpl *device)
+static HRESULT d3d_remove_device(IDirectDrawImpl *This, IDirect3DDeviceImpl *device)
 {
     This->current_device = NULL;
     return DD_OK;
 }
 
-HRESULT direct3d_create(IDirect3DImpl **obj, IDirectDrawImpl *ddraw)
+HRESULT direct3d_create(IDirectDrawImpl *This)
 {
-    IDirect3DImpl *object;
     IDirect3DGLImpl *globject;
     
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DGLImpl));
-    if (object == NULL) return DDERR_OUTOFMEMORY;
+    globject = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DGLImpl));
+    if (globject == NULL) return DDERR_OUTOFMEMORY;
 
-    object->ref = 1;
-    object->ddraw = ddraw;
-    object->create_texture = d3dtexture_create;
-    object->added_device = d3d_add_device;
-    object->removed_device = d3d_remove_device;
-
-    ICOM_INIT_INTERFACE(object, IDirect3D,  VTABLE_IDirect3D);
-    ICOM_INIT_INTERFACE(object, IDirect3D2, VTABLE_IDirect3D2);
-    ICOM_INIT_INTERFACE(object, IDirect3D3, VTABLE_IDirect3D3);
-    ICOM_INIT_INTERFACE(object, IDirect3D7, VTABLE_IDirect3D7);
+    This->d3d_create_texture = d3dtexture_create;
+    This->d3d_added_device = d3d_add_device;
+    This->d3d_removed_device = d3d_remove_device;
+
+    ICOM_INIT_INTERFACE(This, IDirect3D,  VTABLE_IDirect3D);
+    ICOM_INIT_INTERFACE(This, IDirect3D2, VTABLE_IDirect3D2);
+    ICOM_INIT_INTERFACE(This, IDirect3D3, VTABLE_IDirect3D3);
+    ICOM_INIT_INTERFACE(This, IDirect3D7, VTABLE_IDirect3D7);
 
-    globject = (IDirect3DGLImpl *) object;
     globject->free_lights = (0x01 << MAX_LIGHTS) - 1; /* There are, in total, 8 lights in OpenGL */
     globject->light_released = light_released;
 
-    *obj = object;
+    This->d3d_private = globject;
 
-    TRACE(" creating implementation at %p.\n", *obj);
+    TRACE(" creating Mesa private storage at %p.\n", globject);
     
     return D3D_OK;
 }
--- dlls/ddraw_CVS/direct3d/main.h	2003-04-19 18:31:27.000000000 +0200
+++ dlls/ddraw/direct3d/main.h	2003-06-01 20:29:48.000000000 +0200
@@ -19,17 +19,6 @@
 /* This is defined here so as to be able to put them in 'drivers' */
 
 HRESULT WINAPI
-Main_IDirect3DImpl_7_3T_2T_1T_QueryInterface(LPDIRECT3D7 iface,
-                                             REFIID riid,
-                                             LPVOID* obp);
-
-ULONG WINAPI
-Main_IDirect3DImpl_7_3T_2T_1T_AddRef(LPDIRECT3D7 iface);
-
-ULONG WINAPI
-Main_IDirect3DImpl_7_3T_2T_1T_Release(LPDIRECT3D7 iface);
-
-HRESULT WINAPI
 Main_IDirect3DImpl_7_EnumDevices(LPDIRECT3D7 iface,
                                  LPD3DENUMDEVICESCALLBACK7 lpEnumDevicesCallback,
                                  LPVOID lpUserArg);
@@ -130,6 +119,11 @@
                                 LPD3DFINDDEVICERESULT lplpD3DDevice);
 
 HRESULT WINAPI
+Thunk_IDirect3DImpl_7_QueryInterface(LPDIRECT3D7 iface,
+                                     REFIID riid,
+                                     LPVOID* obp);
+
+HRESULT WINAPI
 Thunk_IDirect3DImpl_3_QueryInterface(LPDIRECT3D3 iface,
                                      REFIID riid,
                                      LPVOID* obp);
@@ -145,6 +139,9 @@
                                      LPVOID* obp);
 
 ULONG WINAPI
+Thunk_IDirect3DImpl_7_AddRef(LPDIRECT3D7 iface);
+
+ULONG WINAPI
 Thunk_IDirect3DImpl_3_AddRef(LPDIRECT3D3 iface);
 
 ULONG WINAPI
@@ -154,6 +151,9 @@
 Thunk_IDirect3DImpl_1_AddRef(LPDIRECT3D iface);
 
 ULONG WINAPI
+Thunk_IDirect3DImpl_7_Release(LPDIRECT3D7 iface);
+
+ULONG WINAPI
 Thunk_IDirect3DImpl_3_Release(LPDIRECT3D3 iface);
 
 ULONG WINAPI
--- dlls/ddraw_CVS/dsurface/main.c	2003-05-24 01:37:13.000000000 +0200
+++ dlls/ddraw/dsurface/main.c	2003-06-01 20:41:49.000000000 +0200
@@ -189,7 +189,7 @@
         IDirect3DDeviceImpl *d3ddevimpl;
 	HRESULT ret_value;
 
-	ret_value = d3ddevice_create(&d3ddevimpl, This->ddraw_owner->d3d, This);
+	ret_value = d3ddevice_create(&d3ddevimpl, This->ddraw_owner, This);
 	if (FAILED(ret_value)) return ret_value;
 
 	*ppObj = ICOM_INTERFACE(d3ddevimpl, IDirect3DDevice);
@@ -207,12 +207,12 @@
 
 	/* In case the texture surface was created before the D3D creation */
 	if (This->tex_private == NULL) {
-   	    if (This->ddraw_owner->d3d == NULL) {
+   	    if (This->ddraw_owner->d3d_private == NULL) {
 	        ERR("Texture created with no D3D object yet.. Not supported !\n");
 		return E_NOINTERFACE;
 	    }
 
-	    ret_value = This->ddraw_owner->d3d->create_texture(This->ddraw_owner->d3d, This, FALSE, This->mip_main);
+	    ret_value = This->ddraw_owner->d3d_create_texture(This->ddraw_owner, This, FALSE, This->mip_main);
 	    if (FAILED(ret_value)) return ret_value;
 	}
 	if (IsEqualGUID( &IID_IDirect3DTexture, riid )) {
--- dlls/ddraw_CVS/dsurface/fakezbuffer.c	2003-05-25 20:59:34.000000000 +0200
+++ dlls/ddraw/dsurface/fakezbuffer.c	2003-06-01 20:41:01.000000000 +0200
@@ -132,8 +132,8 @@
     }
 
     /* We only support the BLT with DEPTH_FILL for now */
-    if ((dwFlags & DDBLT_DEPTHFILL) && (This->ddraw_owner->d3d != NULL)) {
-        if (This->ddraw_owner->d3d->current_device != NULL) {
+    if ((dwFlags & DDBLT_DEPTHFILL) && (This->ddraw_owner->d3d_private != NULL)) {
+        if (This->ddraw_owner->current_device != NULL) {
 	    D3DRECT rect;
 	    if (rdst) {
 	        rect.u1.x1 = rdst->left;
@@ -141,12 +141,12 @@
 		rect.u3.x2 = rdst->right;
 		rect.u4.y2 = rdst->bottom;
 	    }
-	    This->ddraw_owner->d3d->current_device->clear(This->ddraw_owner->d3d->current_device,
-							  (rdst == NULL ? 0 : 1), &rect,
-							  D3DCLEAR_ZBUFFER,
-							  0x00000000,
-							  ((double) lpbltfx->u5.dwFillDepth) / 4294967295.0,
-							  0x00000000);
+	    This->ddraw_owner->current_device->clear(This->ddraw_owner->current_device,
+						     (rdst == NULL ? 0 : 1), &rect,
+						     D3DCLEAR_ZBUFFER,
+						     0x00000000,
+						     ((double) lpbltfx->u5.dwFillDepth) / 4294967295.0,
+						     0x00000000);
 	    return DD_OK;
 	}
     }
--- dlls/ddraw_CVS/mesa.c	2003-05-30 15:15:00.000000000 +0200
+++ dlls/ddraw/mesa.c	2003-06-01 20:52:42.000000000 +0200
@@ -785,7 +785,7 @@
 		       (src_pf->u3.dwGBitMask ==        0x0000FF00) &&
 		       (src_pf->u4.dwBBitMask ==        0x000000FF) &&
 		       (src_pf->u5.dwRGBAlphaBitMask == 0x00000000)) {
-		if (need_alpha_ck) {
+		if (need_alpha_ck == TRUE) {
 		    convert_type = CONVERT_RGB32_888;
 		    current_format = GL_RGBA;
 		    internal_format = GL_RGBA;
@@ -901,7 +901,7 @@
 	    DWORD i;
 	    WORD *src = (WORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
-	    if (*temp_buffer != NULL)
+	    if (*temp_buffer == NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
 					 current_tex_width * current_tex_height * sizeof(WORD));
 	    dst = (WORD *) *temp_buffer;
@@ -921,7 +921,7 @@
 	    DWORD i;
 	    WORD *src = (WORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
-	    if (*temp_buffer != NULL)
+	    if (*temp_buffer == NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
 					 current_tex_width * current_tex_height * sizeof(WORD));
 	    dst = (WORD *) *temp_buffer;
@@ -941,7 +941,7 @@
 	    DWORD i;
 	    WORD *src = (WORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
-	    if (*temp_buffer != NULL)
+	    if (*temp_buffer == NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
 					 current_tex_width * current_tex_height * sizeof(WORD));
 	    dst = (WORD *) *temp_buffer;
@@ -980,7 +980,7 @@
 	    DWORD i;
 	    WORD *src = (WORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
-	    if (*temp_buffer != NULL)
+	    if (*temp_buffer == NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
 					 current_tex_width * current_tex_height * sizeof(WORD));
 	    dst = (WORD *) *temp_buffer;
@@ -1000,7 +1000,7 @@
 	    DWORD i;
 	    WORD *src = (WORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
-	    if (*temp_buffer != NULL)
+	    if (*temp_buffer == NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
 					 current_tex_width * current_tex_height * sizeof(WORD));
 	    dst = (WORD *) *temp_buffer;
@@ -1029,7 +1029,7 @@
 	    BYTE *src = (BYTE *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top));
 	    DWORD *dst;
 	    
-	    if (*temp_buffer != NULL)
+	    if (*temp_buffer == NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
 					 current_tex_width * current_tex_height * sizeof(DWORD));
 	    dst = (DWORD *) *temp_buffer;
@@ -1050,7 +1050,7 @@
 	    DWORD i;
 	    DWORD *src = (DWORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
-	    if (*temp_buffer != NULL)
+	    if (*temp_buffer == NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
 					 current_tex_width * current_tex_height * sizeof(DWORD));	    
 	    dst = (DWORD *) *temp_buffer;
@@ -1069,7 +1069,7 @@
 	    DWORD i;
 	    DWORD *src = (DWORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
-	    if (*temp_buffer != NULL)
+	    if (*temp_buffer == NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
 					 current_tex_width * current_tex_height * sizeof(DWORD));	    
 	    dst = (DWORD *) *temp_buffer;
@@ -1089,7 +1089,7 @@
 	    DWORD i;
 	    DWORD *src = (DWORD *) (((BYTE *) src_d->lpSurface) + (bpp * rect->left) + (src_d->u1.lPitch * rect->top)), *dst;
 	    
-	    if (*temp_buffer != NULL)
+	    if (*temp_buffer == NULL)
 		*temp_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
 					 current_tex_width * current_tex_height * sizeof(DWORD));	    
 	    dst = (DWORD *) *temp_buffer;
--- dlls/ddraw_CVS/mesa_private.h	2003-05-30 15:15:00.000000000 +0200
+++ dlls/ddraw/mesa_private.h	2003-06-01 20:34:57.000000000 +0200
@@ -45,11 +45,11 @@
     SURFACE_MEMORY_DIRTY
 } SURFACE_STATE;
 
+/* This structure is used for the 'd3d_private' field of the IDirectDraw structure */
 typedef struct IDirect3DGLImpl
 {
-    struct IDirect3DImpl parent;
     DWORD free_lights;
-    void (*light_released)(IDirect3DImpl *, GLenum light_num);
+    void (*light_released)(IDirectDrawImpl *, GLenum light_num);
 } IDirect3DGLImpl;
 
 typedef struct IDirect3DLightGLImpl
@@ -124,19 +124,19 @@
 } IDirect3DVertexBufferGLImpl;
 
 /* All non-static functions 'exported' by various sub-objects */
-extern HRESULT direct3d_create(IDirect3DImpl **obj, IDirectDrawImpl *ddraw);
-extern HRESULT d3dtexture_create(IDirect3DImpl *d3d, IDirectDrawSurfaceImpl *surf, BOOLEAN at_creation, IDirectDrawSurfaceImpl *main_surf);
-extern HRESULT d3dlight_create(IDirect3DLightImpl **obj, IDirect3DImpl *d3d, GLenum light_num);
-extern HRESULT d3dexecutebuffer_create(IDirect3DExecuteBufferImpl **obj, IDirect3DImpl *d3d, IDirect3DDeviceImpl *d3ddev, LPD3DEXECUTEBUFFERDESC lpDesc);
-extern HRESULT d3dmaterial_create(IDirect3DMaterialImpl **obj, IDirect3DImpl *d3d);
-extern HRESULT d3dviewport_create(IDirect3DViewportImpl **obj, IDirect3DImpl *d3d);
-extern HRESULT d3dvertexbuffer_create(IDirect3DVertexBufferImpl **obj, IDirect3DImpl *d3d, LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc, DWORD dwFlags);
-extern HRESULT d3ddevice_create(IDirect3DDeviceImpl **obj, IDirect3DImpl *d3d, IDirectDrawSurfaceImpl *surface);
+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 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);
+extern HRESULT d3dvertexbuffer_create(IDirect3DVertexBufferImpl **obj, IDirectDrawImpl *d3d, LPD3DVERTEXBUFFERDESC lpD3DVertBufDesc, DWORD dwFlags);
+extern HRESULT d3ddevice_create(IDirect3DDeviceImpl **obj, IDirectDrawImpl *d3d, IDirectDrawSurfaceImpl *surface);
 
 /* Used for Direct3D to request the device to enumerate itself */
 extern HRESULT d3ddevice_enumerate(LPD3DENUMDEVICESCALLBACK cb, LPVOID context, DWORD version) ;
 extern HRESULT d3ddevice_enumerate7(LPD3DENUMDEVICESCALLBACK7 cb, LPVOID context) ;
-extern HRESULT d3ddevice_find(IDirect3DImpl *d3d, LPD3DFINDDEVICESEARCH lpD3DDFS, LPD3DFINDDEVICERESULT lplpD3DDevice);
+extern HRESULT d3ddevice_find(IDirectDrawImpl *d3d, LPD3DFINDDEVICESEARCH lpD3DDFS, LPD3DFINDDEVICERESULT lplpD3DDevice);
 
 /* Used to upload the texture */
 extern HRESULT gltex_upload_texture(IDirectDrawSurfaceImpl *This) ;

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux