Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/cubetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/cubetexture.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/cubetexture.c	(revision 23571)
@@ -56,4 +56,12 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        IUnknown_AddRef(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DCubeTexture_AddRef(This->wineD3DCubeTexture);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -67,9 +75,9 @@
     if (ref == 0) {
         TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
-        EnterCriticalSection(&d3d8_cs);
-        IWineD3DCubeTexture_Destroy(This->wineD3DCubeTexture, D3D8CB_DestroySurface);
-        LeaveCriticalSection(&d3d8_cs);
+
         IUnknown_Release(This->parentDevice);
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_lock();
+        IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
+        wined3d_mutex_unlock();
     }
     return ref;
@@ -83,5 +91,5 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_GetDevice(This->wineD3DCubeTexture, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -90,5 +98,6 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -99,7 +108,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -110,7 +120,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -121,7 +132,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -132,7 +144,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -143,7 +156,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret =  IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -153,7 +167,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -163,7 +177,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     type = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return type;
 }
@@ -175,7 +190,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     lod = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return lod;
 }
@@ -186,7 +202,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     lod = IWineD3DCubeTexture_GetLOD((LPDIRECT3DBASETEXTURE8) This);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return lod;
 }
@@ -197,7 +214,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     cnt = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return cnt;
 }
@@ -211,7 +229,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr))
@@ -237,5 +255,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
     if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
@@ -243,5 +261,6 @@
        IWineD3DCubeTexture_Release(mySurface);
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hrc;
 }
@@ -252,7 +271,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -263,7 +283,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -274,12 +295,12 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
-    LeaveCriticalSection(&d3d8_cs);
-    return hr;
-}
-
-
-const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl =
 {
     /* IUnknown */
@@ -307,2 +328,37 @@
     IDirect3DCubeTexture8Impl_AddDirtyRect
 };
+
+static void STDMETHODCALLTYPE d3d8_cubetexture_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d8_cubetexture_wined3d_parent_ops =
+{
+    d3d8_cubetexture_wined3d_object_destroyed,
+};
+
+HRESULT cubetexture_init(IDirect3DCubeTexture8Impl *texture, IDirect3DDevice8Impl *device,
+        UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
+{
+    HRESULT hr;
+
+    texture->lpVtbl = &Direct3DCubeTexture8_Vtbl;
+    texture->ref = 1;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateCubeTexture(device->WineD3DDevice, edge_length, levels, usage & WINED3DUSAGE_MASK,
+            wined3dformat_from_d3dformat(format), pool, &texture->wineD3DCubeTexture,
+            (IUnknown *)texture, &d3d8_cubetexture_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
+        return hr;
+    }
+
+    texture->parentDevice = (IDirect3DDevice8 *)device;
+    IDirect3DDevice8_AddRef(texture->parentDevice);
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_main.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_main.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_main.c	(revision 23571)
@@ -34,13 +34,4 @@
 #include "wine/debug.h"
 
-static CRITICAL_SECTION_DEBUG d3d8_cs_debug =
-{
-    0, 0, &d3d8_cs,
-    { &d3d8_cs_debug.ProcessLocksList,
-      &d3d8_cs_debug.ProcessLocksList },
-    0, 0, { (DWORD_PTR)(__FILE__ ": d3d8_cs") }
-};
-CRITICAL_SECTION d3d8_cs = { &d3d8_cs_debug, -1, 0, 0, 0, 0 };
-
 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
 
@@ -58,5 +49,6 @@
     TRACE("SDKVersion = %x\n", SDKVersion);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3D8Impl));
 
@@ -66,5 +58,6 @@
 
     TRACE("Created Direct3D object @ %p, WineObj @ %p\n", object, object->WineD3D);
-    LeaveCriticalSection(&d3d8_cs);
+
+    wined3d_mutex_unlock();
 
     if (!object->WineD3D)
@@ -87,12 +80,12 @@
 
 /***********************************************************************
- *		ValidateVertexShader (D3D8.@)
+ *              ValidateVertexShader (D3D8.@)
  *
  * I've seen reserved1 and reserved2 always passed as 0's
- * bool seems always passed as 0 or 1, but other values work as well.... 
+ * bool seems always passed as 0 or 1, but other values work as well...
  * toto       result?
  */
 HRESULT WINAPI ValidateVertexShader(DWORD* vertexshader, DWORD* reserved1, DWORD* reserved2, BOOL bool, DWORD* toto)
-{ 
+{
   HRESULT ret;
   FIXME("(%p %p %p %d %p): stub\n", vertexshader, reserved1, reserved2, bool, toto);
@@ -106,5 +99,5 @@
   switch(*vertexshader) {
         case 0xFFFE0101:
-        case 0xFFFE0100: 
+        case 0xFFFE0100:
             ret=S_OK;
             break;
@@ -118,5 +111,5 @@
 
 /***********************************************************************
- *		ValidatePixelShader (D3D8.@)
+ *              ValidatePixelShader (D3D8.@)
  *
  * PARAMS
@@ -127,10 +120,10 @@
   HRESULT ret;
   FIXME("(%p %p %d %p): stub\n", pixelshader, reserved1, bool, toto);
-  
+
   if (!pixelshader)
       return E_FAIL;
 
   if (reserved1)
-      return E_FAIL;   
+      return E_FAIL;
 
   switch(*pixelshader) {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_private.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_private.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_private.h	(revision 23571)
@@ -107,5 +107,5 @@
     _pD3D8Caps->MaxPixelShaderValue               = _pWineCaps->PixelShader1xMaxValue;
 
-void fixup_caps(WINED3DCAPS *pWineCaps);
+void fixup_caps(WINED3DCAPS *pWineCaps) DECLSPEC_HIDDEN;
 
 /* Direct3D8 Interfaces: */
@@ -132,7 +132,4 @@
 typedef struct IDirect3DVertexShader8Impl IDirect3DVertexShader8Impl;
 
-/* Global critical section */
-extern CRITICAL_SECTION d3d8_cs;
-
 /* ===========================================================================
     The interfaces themselves
@@ -146,5 +143,5 @@
  * Predeclare the interface implementation structures
  */
-extern const IDirect3D8Vtbl Direct3D8_Vtbl;
+extern const IDirect3D8Vtbl Direct3D8_Vtbl DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -168,6 +165,6 @@
  * Predeclare the interface implementation structures
  */
-extern const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl;
-extern const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl;
+extern const IDirect3DDevice8Vtbl Direct3DDevice8_Vtbl DECLSPEC_HIDDEN;
+extern const IWineD3DDeviceParentVtbl d3d8_wined3d_device_parent_vtbl DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -231,5 +228,4 @@
  * IDirect3DVolume8 implementation structure
  */
-extern const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl;
 struct IDirect3DVolume8Impl
 {
@@ -247,4 +243,7 @@
     IUnknown                    *forwardReference;
 };
+
+HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device, UINT width, UINT height,
+        UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool) DECLSPEC_HIDDEN;
 
 /* ------------------- */
@@ -255,5 +254,5 @@
  * Predeclare the interface implementation structures
  */
-extern const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl;
+extern const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -278,9 +277,4 @@
 
 /*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl;
-
-/*****************************************************************************
  * IDirect3DSurface8 implementation structure
  */
@@ -302,8 +296,9 @@
     /* If set forward refcounting to this object */
     IUnknown                    *forwardReference;
-
-    /* Flags an implicit surface */
-    BOOL                        isImplicit;
-};
+};
+
+HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *device,
+        UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
+        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) DECLSPEC_HIDDEN;
 
 /* ------------------ */
@@ -314,5 +309,5 @@
  * Predeclare the interface implementation structures
  */
-extern const IDirect3DResource8Vtbl Direct3DResource8_Vtbl;
+extern const IDirect3DResource8Vtbl Direct3DResource8_Vtbl DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -334,9 +329,4 @@
 
 /*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl;
-
-/*****************************************************************************
  * IDirect3DVertexBuffer8 implementation structure
  */
@@ -355,4 +345,7 @@
     DWORD                             fvf;
 };
+
+HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
+        UINT size, DWORD usage, DWORD fvf, D3DPOOL pool) DECLSPEC_HIDDEN;
 
 /* --------------------- */
@@ -361,9 +354,4 @@
 
 /*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DIndexBuffer8Vtbl Direct3DIndexBuffer8_Vtbl;
-
-/*****************************************************************************
  * IDirect3DIndexBuffer8 implementation structure
  */
@@ -382,4 +370,7 @@
     WINED3DFORMAT                    format;
 };
+
+HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
+        UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
 
 /* --------------------- */
@@ -405,9 +396,4 @@
 
 /*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DCubeTexture8Vtbl Direct3DCubeTexture8_Vtbl;
-
-/*****************************************************************************
  * IDirect3DCubeTexture8 implementation structure
  */
@@ -424,4 +410,7 @@
     LPDIRECT3DDEVICE8                parentDevice;
 };
+
+HRESULT cubetexture_init(IDirect3DCubeTexture8Impl *texture, IDirect3DDevice8Impl *device,
+        UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
 
 /* ----------------- */
@@ -430,9 +419,4 @@
 
 /*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl;
-
-/*****************************************************************************
  * IDirect3DTexture8 implementation structure
  */
@@ -449,4 +433,7 @@
     LPDIRECT3DDEVICE8            parentDevice;
 };
+
+HRESULT texture_init(IDirect3DTexture8Impl *texture, IDirect3DDevice8Impl *device,
+        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
 
 /* ----------------------- */
@@ -455,9 +442,4 @@
 
 /*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl;
-
-/*****************************************************************************
  * IDirect3DVolumeTexture8 implementation structure
  */
@@ -474,4 +456,7 @@
     LPDIRECT3DDEVICE8                  parentDevice;
 };
+
+HRESULT volumetexture_init(IDirect3DVolumeTexture8Impl *texture, IDirect3DDevice8Impl *device,
+        UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
 
 /* ----------------------- */
@@ -481,5 +466,5 @@
 /* TODO: Generate a valid GUIDs */
 /* {83B073CE-6F30-11d9-C687-00046142C14F} */
-DEFINE_GUID(IID_IDirect3DStateBlock8, 
+DEFINE_GUID(IID_IDirect3DStateBlock8,
 0x83b073ce, 0x6f30, 0x11d9, 0xc6, 0x87, 0x0, 0x4, 0x61, 0x42, 0xc1, 0x4f);
 
@@ -523,5 +508,5 @@
  * Predeclare the interface implementation structures
  */
-extern const IDirect3DStateBlock8Vtbl Direct3DStateBlock8_Vtbl;
+extern const IDirect3DStateBlock8Vtbl Direct3DStateBlock8_Vtbl DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -555,7 +540,4 @@
 #define IDirect3DVertexDeclaration8_Release(p)             (p)->lpVtbl->Release(p)
 
-/*** Implementation ***/
-extern const IDirect3DVertexDeclaration8Vtbl Direct3DVertexDeclaration8_Vtbl;
-
 typedef struct {
     const IDirect3DVertexDeclaration8Vtbl *lpVtbl;
@@ -569,4 +551,8 @@
 } IDirect3DVertexDeclaration8Impl;
 
+HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
+        IDirect3DDevice8Impl *device, const DWORD *elements, DWORD shader_handle) DECLSPEC_HIDDEN;
+HRESULT vertexdeclaration_init_fvf(IDirect3DVertexDeclaration8Impl *declaration,
+        IDirect3DDevice8Impl *device, DWORD fvf) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -611,9 +597,4 @@
 
 /*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DVertexShader8Vtbl Direct3DVertexShader8_Vtbl;
-
-/*****************************************************************************
  * IDirect3DVertexShader implementation structure
  */
@@ -627,16 +608,8 @@
 };
 
+HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Impl *device,
+        const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage) DECLSPEC_HIDDEN;
+
 #define D3D8_MAX_VERTEX_SHADER_CONSTANTF 256
-
-
-/* ------------------------ */
-/* IDirect3DPixelShaderImpl */
-/* ------------------------ */
-
-
-/*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl;
 
 /*****************************************************************************
@@ -650,4 +623,7 @@
     IWineD3DPixelShader             *wineD3DPixelShader;
 } IDirect3DPixelShader8Impl;
+
+HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl *device,
+        const DWORD *byte_code, DWORD shader_handle) DECLSPEC_HIDDEN;
 
 /**
@@ -656,16 +632,13 @@
  * to see how not defined it here
  */
-D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format);
-WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format);
-void load_local_constants(const DWORD *d3d8_elements, IWineD3DVertexShader *wined3d_vertex_shader);
-UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elements_size, WINED3DVERTEXELEMENT **wined3d_elements);
-size_t parse_token(const DWORD* pToken);
+D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format) DECLSPEC_HIDDEN;
+WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_HIDDEN;
+void load_local_constants(const DWORD *d3d8_elements, IWineD3DVertexShader *wined3d_vertex_shader) DECLSPEC_HIDDEN;
+UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elements_size,
+        WINED3DVERTEXELEMENT **wined3d_elements) DECLSPEC_HIDDEN;
+size_t parse_token(const DWORD *pToken) DECLSPEC_HIDDEN;
 
 /* Callbacks */
-extern ULONG WINAPI D3D8CB_DestroySwapChain (IWineD3DSwapChain *pSwapChain);
-extern ULONG WINAPI D3D8CB_DestroyDepthStencilSurface (IWineD3DSurface *pSurface);
-extern ULONG WINAPI D3D8CB_DestroyRenderTarget (IWineD3DSurface *pSurface);
-extern ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface);
-extern ULONG WINAPI D3D8CB_DestroyVolume(IWineD3DVolume *pVolume);
+extern ULONG WINAPI D3D8CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) DECLSPEC_HIDDEN;
 
 #endif /* __WINE_D3DX8_PRIVATE_H */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/device.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/device.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/device.c	(revision 23571)
@@ -56,35 +56,35 @@
     {
         case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
-        case WINED3DFMT_R8G8B8: return D3DFMT_R8G8B8;
-        case WINED3DFMT_A8R8G8B8: return D3DFMT_A8R8G8B8;
-        case WINED3DFMT_X8R8G8B8: return D3DFMT_X8R8G8B8;
-        case WINED3DFMT_R5G6B5: return D3DFMT_R5G6B5;
-        case WINED3DFMT_X1R5G5B5: return D3DFMT_X1R5G5B5;
-        case WINED3DFMT_A1R5G5B5: return D3DFMT_A1R5G5B5;
-        case WINED3DFMT_A4R4G4B4: return D3DFMT_A4R4G4B4;
-        case WINED3DFMT_R3G3B2: return D3DFMT_R3G3B2;
+        case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
+        case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
+        case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
+        case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
+        case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
+        case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
+        case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
+        case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
         case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
-        case WINED3DFMT_A8R3G3B2: return D3DFMT_A8R3G3B2;
-        case WINED3DFMT_X4R4G4B4: return D3DFMT_X4R4G4B4;
+        case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
+        case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
         case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
         case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
-        case WINED3DFMT_A8P8: return D3DFMT_A8P8;
-        case WINED3DFMT_P8: return D3DFMT_P8;
-        case WINED3DFMT_L8: return D3DFMT_L8;
-        case WINED3DFMT_A8L8: return D3DFMT_A8L8;
-        case WINED3DFMT_A4L4: return D3DFMT_A4L4;
+        case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
+        case WINED3DFMT_P8_UINT: return D3DFMT_P8;
+        case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
+        case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
+        case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
         case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
-        case WINED3DFMT_L6V5U5: return D3DFMT_L6V5U5;
-        case WINED3DFMT_X8L8V8U8: return D3DFMT_X8L8V8U8;
+        case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
+        case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
         case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
         case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
-        case WINED3DFMT_W11V11U10: return D3DFMT_W11V11U10;
-        case WINED3DFMT_A2W10V10U10: return D3DFMT_A2W10V10U10;
+        case WINED3DFMT_R10G11B11_SNORM: return D3DFMT_W11V11U10;
+        case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
         case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
-        case WINED3DFMT_D32: return D3DFMT_D32;
-        case WINED3DFMT_D15S1: return D3DFMT_D15S1;
-        case WINED3DFMT_D24S8: return D3DFMT_D24S8;
-        case WINED3DFMT_D24X8: return D3DFMT_D24X8;
-        case WINED3DFMT_D24X4S4: return D3DFMT_D24X4S4;
+        case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
+        case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
+        case WINED3DFMT_S8_UINT_D24_UNORM: return D3DFMT_D24S8;
+        case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
+        case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
         case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
         case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
@@ -107,35 +107,35 @@
     {
         case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
-        case D3DFMT_R8G8B8: return WINED3DFMT_R8G8B8;
-        case D3DFMT_A8R8G8B8: return WINED3DFMT_A8R8G8B8;
-        case D3DFMT_X8R8G8B8: return WINED3DFMT_X8R8G8B8;
-        case D3DFMT_R5G6B5: return WINED3DFMT_R5G6B5;
-        case D3DFMT_X1R5G5B5: return WINED3DFMT_X1R5G5B5;
-        case D3DFMT_A1R5G5B5: return WINED3DFMT_A1R5G5B5;
-        case D3DFMT_A4R4G4B4: return WINED3DFMT_A4R4G4B4;
-        case D3DFMT_R3G3B2: return WINED3DFMT_R3G3B2;
+        case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
+        case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
+        case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
+        case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
+        case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
+        case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
+        case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
+        case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
         case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
-        case D3DFMT_A8R3G3B2: return WINED3DFMT_A8R3G3B2;
-        case D3DFMT_X4R4G4B4: return WINED3DFMT_X4R4G4B4;
+        case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
+        case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
         case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
         case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
-        case D3DFMT_A8P8: return WINED3DFMT_A8P8;
-        case D3DFMT_P8: return WINED3DFMT_P8;
-        case D3DFMT_L8: return WINED3DFMT_L8;
-        case D3DFMT_A8L8: return WINED3DFMT_A8L8;
-        case D3DFMT_A4L4: return WINED3DFMT_A4L4;
+        case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
+        case D3DFMT_P8: return WINED3DFMT_P8_UINT;
+        case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
+        case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
+        case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
         case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
-        case D3DFMT_L6V5U5: return WINED3DFMT_L6V5U5;
-        case D3DFMT_X8L8V8U8: return WINED3DFMT_X8L8V8U8;
+        case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
+        case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
         case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
         case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
-        case D3DFMT_W11V11U10: return WINED3DFMT_W11V11U10;
-        case D3DFMT_A2W10V10U10: return WINED3DFMT_A2W10V10U10;
+        case D3DFMT_W11V11U10: return WINED3DFMT_R10G11B11_SNORM;
+        case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
         case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
-        case D3DFMT_D32: return WINED3DFMT_D32;
-        case D3DFMT_D15S1: return WINED3DFMT_D15S1;
-        case D3DFMT_D24S8: return WINED3DFMT_D24S8;
-        case D3DFMT_D24X8: return WINED3DFMT_D24X8;
-        case D3DFMT_D24X4S4: return WINED3DFMT_D24X4S4;
+        case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
+        case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
+        case D3DFMT_D24S8: return WINED3DFMT_S8_UINT_D24_UNORM;
+        case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
+        case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
         case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
         case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
@@ -309,5 +309,7 @@
 
         TRACE("Releasing wined3d device %p\n", This->WineD3DDevice);
-        EnterCriticalSection(&d3d8_cs);
+
+        wined3d_mutex_lock();
+
         This->inDestruction = TRUE;
 
@@ -317,9 +319,10 @@
         HeapFree(GetProcessHeap(), 0, This->decls);
 
-        IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroyDepthStencilSurface, D3D8CB_DestroySwapChain);
+        IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D8CB_DestroySwapChain);
         IWineD3DDevice_Release(This->WineD3DDevice);
         HeapFree(GetProcessHeap(), 0, This->handle_table.entries);
         HeapFree(GetProcessHeap(), 0, This);
-        LeaveCriticalSection(&d3d8_cs);
+
+        wined3d_mutex_unlock();
     }
     return ref;
@@ -332,7 +335,9 @@
 
     TRACE("(%p) : Relay\n", This);
-    EnterCriticalSection(&d3d8_cs);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -343,7 +348,9 @@
 
     TRACE("(%p) Relay\n", This);
-    EnterCriticalSection(&d3d8_cs);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -354,7 +361,9 @@
 
     TRACE("(%p) : Relay bytes(%d)\n", This, Bytes);
-    EnterCriticalSection(&d3d8_cs);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -371,5 +380,5 @@
     }
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
     if (hr == D3D_OK && pWineD3D != NULL)
@@ -381,6 +390,7 @@
         *ppD3D8 = NULL;
     }
+    wined3d_mutex_unlock();
+
     TRACE("(%p) returning %p\n",This , *ppD3D8);
-    LeaveCriticalSection(&d3d8_cs);
 
     return hr;
@@ -401,7 +411,8 @@
     }
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     fixup_caps(pWineCaps);
     WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
@@ -417,7 +428,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, 0, (WINED3DDISPLAYMODE *) pMode);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -431,7 +442,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -447,7 +459,8 @@
     }
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice,XHotSpot,YHotSpot,pSurface->wineD3DSurface);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -457,7 +470,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -467,7 +480,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -512,8 +526,8 @@
     localParameters.AutoRestoreDisplayMode                      = TRUE;
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
             &object->wineD3DSwapChain, (IUnknown *)object, SURFACE_OPENGL);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
@@ -567,7 +581,7 @@
     localParameters.AutoRestoreDisplayMode                      = TRUE;
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
@@ -593,7 +607,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -606,5 +621,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, 0, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
     if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
@@ -612,5 +627,6 @@
         IWineD3DSurface_Release(retSurface);
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return rc;
 }
@@ -621,7 +637,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, 0, (WINED3DRASTER_STATUS *) pRasterStatus);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -632,7 +649,7 @@
 
     /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, 0, Flags, (CONST WINED3DGAMMARAMP *) pRamp);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -642,201 +659,164 @@
 
     /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, 0, (WINED3DGAMMARAMP *) pRamp);
-    LeaveCriticalSection(&d3d8_cs);
-}
-
-static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
-                                                    D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture8 **ppTexture) {
+    wined3d_mutex_unlock();
+}
+
+static HRESULT WINAPI IDirect3DDevice8Impl_CreateTexture(IDirect3DDevice8 *iface,
+        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
+        D3DPOOL pool, IDirect3DTexture8 **texture)
+{
+    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     IDirect3DTexture8Impl *object;
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    HRESULT hrc = D3D_OK;
-
-    TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%u), Pool(%d)\n", This, Width, Height, Levels, Usage, Format,  Pool);
-
-    /* Allocate the storage for the device */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture8Impl));
-
-    if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
-/*        *ppTexture = NULL; */
+    HRESULT hr;
+
+    TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
+            iface, width, height, levels, usage, format, pool, texture);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate texture memory.\n");
         return D3DERR_OUTOFVIDEOMEMORY;
     }
 
-    object->lpVtbl = &Direct3DTexture8_Vtbl;
-    object->ref = 1;
-    EnterCriticalSection(&d3d8_cs);
-    hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
-            wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DTexture, (IUnknown *)object);
-    LeaveCriticalSection(&d3d8_cs);
-
-    if (FAILED(hrc)) {
-        /* free up object */ 
-        FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
+    hr = texture_init(object, This, width, height, levels, usage, format, pool);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize texture, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-/*      *ppTexture = NULL; */
-   } else {
-        IUnknown_AddRef(iface);
-        object->parentDevice = iface;
-        *ppTexture = (LPDIRECT3DTEXTURE8) object;
-        TRACE("(%p) Created Texture %p, %p\n",This,object,object->wineD3DTexture);
-   }
-
-   return hrc;
-}
-
-static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(LPDIRECT3DDEVICE8 iface, 
-                                                          UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, 
-                                                          D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture8** ppVolumeTexture) {
-
+        return hr;
+    }
+
+    TRACE("Created texture %p.\n", object);
+    *texture = (IDirect3DTexture8 *)object;
+
+    return D3D_OK;
+}
+
+static HRESULT WINAPI IDirect3DDevice8Impl_CreateVolumeTexture(IDirect3DDevice8 *iface,
+        UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
+        D3DPOOL pool, IDirect3DVolumeTexture8 **texture)
+{
+    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     IDirect3DVolumeTexture8Impl *object;
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    HRESULT hrc = D3D_OK;
-
-    TRACE("(%p) Relay\n", This);
-
-    /* Allocate the storage for the device */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture8Impl));
-    if (NULL == object) {
-        FIXME("(%p) allocation of memory failed\n", This);
-        *ppVolumeTexture = NULL;
+    HRESULT hr;
+
+    TRACE("iface %p, width %u, height %u, depth %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
+            iface, width, height, depth, levels, usage, format, pool, texture);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate volume texture memory.\n");
         return D3DERR_OUTOFVIDEOMEMORY;
     }
 
-    object->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
-    object->ref = 1;
-    EnterCriticalSection(&d3d8_cs);
-    hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels,
-            Usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(Format),
-            Pool, &object->wineD3DVolumeTexture, (IUnknown *)object);
-    LeaveCriticalSection(&d3d8_cs);
-
-    if (hrc != D3D_OK) {
-
-        /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
+    hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize volume texture, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *ppVolumeTexture = NULL;
-    } else {
-        IUnknown_AddRef(iface);
-        object->parentDevice = iface;
-        *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE8) object;
-    }
-    TRACE("(%p)  returning %p\n", This , *ppVolumeTexture);
-    return hrc;
-}
-
-static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(LPDIRECT3DDEVICE8 iface, UINT EdgeLength, UINT Levels, DWORD Usage, 
-                                                        D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture8** ppCubeTexture) {
-
+        return hr;
+    }
+
+    TRACE("Created volume texture %p.\n", object);
+    *texture = (IDirect3DVolumeTexture8 *)object;
+
+    return D3D_OK;
+}
+
+static HRESULT WINAPI IDirect3DDevice8Impl_CreateCubeTexture(IDirect3DDevice8 *iface, UINT edge_length,
+        UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DCubeTexture8 **texture)
+{
+    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     IDirect3DCubeTexture8Impl *object;
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    HRESULT hr = D3D_OK;
-
-    TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)\n" , This, EdgeLength, Levels, Usage, Format, Pool);
-
-    /* Allocate the storage for the device */
+    HRESULT hr;
+
+    TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p.\n",
+            iface, edge_length, levels, usage, format, pool, texture);
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-
-    if (NULL == object) {
-        FIXME("(%p) allocation of CubeTexture failed\n", This);
-        *ppCubeTexture = NULL;
+    if (!object)
+    {
+        ERR("Failed to allocate cube texture memory.\n");
         return D3DERR_OUTOFVIDEOMEMORY;
     }
 
-    object->lpVtbl = &Direct3DCubeTexture8_Vtbl;
-    object->ref = 1;
-    EnterCriticalSection(&d3d8_cs);
-    hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage & WINED3DUSAGE_MASK,
-            wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DCubeTexture, (IUnknown *)object);
-    LeaveCriticalSection(&d3d8_cs);
-
-    if (hr != D3D_OK){
-
-        /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
+    hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize cube texture, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *ppCubeTexture = NULL;
-    } else {
-        IUnknown_AddRef(iface);
-        object->parentDevice = iface;
-        *ppCubeTexture = (LPDIRECT3DCUBETEXTURE8) object;
-    }
-
-    TRACE("(%p) returning %p\n",This, *ppCubeTexture);
-    return hr;
-}
-
-static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(LPDIRECT3DDEVICE8 iface, UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer8** ppVertexBuffer) {
+        return hr;
+    }
+
+    TRACE("Created cube texture %p.\n", object);
+    *texture = (IDirect3DCubeTexture8 *)object;
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
+        DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer8 **buffer)
+{
+    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     IDirect3DVertexBuffer8Impl *object;
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    HRESULT hrc = D3D_OK;
-
-    TRACE("(%p) Relay\n", This);
-    /* Allocate the storage for the device */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer8Impl));
-    if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
-        *ppVertexBuffer = NULL;
+    HRESULT hr;
+
+    TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p.\n",
+            iface, size, usage, fvf, pool, buffer);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate buffer memory.\n");
         return D3DERR_OUTOFVIDEOMEMORY;
     }
 
-    object->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
-    object->ref = 1;
-    EnterCriticalSection(&d3d8_cs);
-    hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK,
-            0 /* fvf for ddraw only */, (WINED3DPOOL)Pool, &object->wineD3DVertexBuffer, (IUnknown *)object);
-    LeaveCriticalSection(&d3d8_cs);
-    object->fvf = FVF;
-
-    if (D3D_OK != hrc) {
-
-        /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
+    hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *ppVertexBuffer = NULL;
-    } else {
-        IUnknown_AddRef(iface);
-        object->parentDevice = iface;
-        *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER8) object;
-    }
-    return hrc;
-}
-
-static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(LPDIRECT3DDEVICE8 iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer8** ppIndexBuffer) {
+        return hr;
+    }
+
+    TRACE("Created vertex buffer %p.\n", object);
+    *buffer = (IDirect3DVertexBuffer8 *)object;
+
+    return D3D_OK;
+}
+
+static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *iface, UINT size, DWORD usage,
+        D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer8 **buffer)
+{
+    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     IDirect3DIndexBuffer8Impl *object;
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    HRESULT hrc = D3D_OK;
-
-    TRACE("(%p) Relay\n", This);
-    /* Allocate the storage for the device */
+    HRESULT hr;
+
+    TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p.\n",
+            iface, size, usage, format, pool, buffer);
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
-        *ppIndexBuffer = NULL;
+    if (!object)
+    {
+        ERR("Failed to allocate buffer memory.\n");
         return D3DERR_OUTOFVIDEOMEMORY;
     }
 
-    object->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
-    object->ref = 1;
-    object->format = wined3dformat_from_d3dformat(Format);
-    TRACE("Calling wined3d create index buffer\n");
-    EnterCriticalSection(&d3d8_cs);
-    hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
-            (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer, (IUnknown *)object);
-    LeaveCriticalSection(&d3d8_cs);
-
-    if (D3D_OK != hrc) {
-
-        /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
+    hr = indexbuffer_init(object, This, size, usage, format, pool);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize index buffer, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *ppIndexBuffer = NULL;
-    } else {
-        IUnknown_AddRef(iface);
-        object->parentDevice = iface;
-        *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER8)object;
-    }
-    return hrc;
+        return hr;
+    }
+
+    TRACE("Created index buffer %p.\n", object);
+    *buffer = (IDirect3DIndexBuffer8 *)object;
+
+    return D3D_OK;
 }
 
@@ -845,48 +825,30 @@
         UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
 {
-    HRESULT hrc;
+    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     IDirect3DSurface8Impl *object;
-    IDirect3DDevice8Impl  *This = (IDirect3DDevice8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
-
-    if(MultisampleQuality > 0){
-        FIXME("MultisampleQuality set to %d, substituting 0\n" , MultisampleQuality);
-        /*
-        MultisampleQuality
-        [in] Quality level. The valid range is between zero and one less than the level returned by pQualityLevels used by IDirect3D8::CheckDeviceMultiSampleType. Passing a larger value returns the error D3DERR_INVALIDCALL. The MultisampleQuality values of paired render targets, depth stencil surfaces, and the MultiSample type must all match.
-        */
-        MultisampleQuality=0;
-    }
-    /*FIXME: Check MAX bounds of MultisampleQuality*/
-
-    /* Allocate the storage for the device */
+    HRESULT hr;
+
+    TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
-    if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
-        *ppSurface = NULL;
+    if (!object)
+    {
+        FIXME("Failed to allocate surface memory.\n");
         return D3DERR_OUTOFVIDEOMEMORY;
     }
 
-    object->lpVtbl = &Direct3DSurface8_Vtbl;
-    object->ref = 1;
-
-    TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
-
-    EnterCriticalSection(&d3d8_cs);
-    hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
-            Lockable, Discard, Level, &object->wineD3DSurface, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL)Pool,
-            MultiSample, MultisampleQuality, SURFACE_OPENGL, (IUnknown *)object);
-    LeaveCriticalSection(&d3d8_cs);
-    if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
-       /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
+    hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
+            Level, Usage, Pool, MultiSample, MultisampleQuality);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize surface, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *ppSurface = NULL;
-    } else {
-        IUnknown_AddRef(iface);
-        object->parentDevice = iface;
-        *ppSurface = (LPDIRECT3DSURFACE8) object;
-    }
-    return hrc;
+        return hr;
+    }
+
+    TRACE("Created surface %p.\n", object);
+    *ppSurface = (IDirect3DSurface8 *)object;
+
+    return D3D_OK;
 }
 
@@ -941,5 +903,5 @@
     /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
     srcFormat = winedesc.format;
@@ -956,5 +918,5 @@
     if (srcFormat != destFormat && WINED3DFMT_UNKNOWN != destFormat) {
         WARN("(%p) source %p format must match the dest %p format, returning WINED3DERR_INVALIDCALL\n", iface, pSourceSurface, pDestinationSurface);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
         return WINED3DERR_INVALIDCALL;
     } else if (WINED3DFMT_UNKNOWN == destFormat) {
@@ -980,5 +942,5 @@
         }
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -990,7 +952,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice,  ((IDirect3DBaseTexture8Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture8Impl *)pDestinationTexture)->wineD3DBaseTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1008,7 +971,8 @@
     }
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, 0, destSurface->wineD3DSurface);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1022,5 +986,5 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice, &original_ds);
@@ -1034,5 +998,6 @@
     if (original_ds) IWineD3DSurface_Release(original_ds);
 
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1048,5 +1013,6 @@
         return D3DERR_INVALIDCALL;
     }
-    EnterCriticalSection(&d3d8_cs);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetRenderTarget(This->WineD3DDevice, 0, &pRenderTarget);
 
@@ -1058,5 +1024,5 @@
         *ppRenderTarget = NULL;
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -1073,5 +1039,5 @@
     }
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr=IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
     if (hr == WINED3D_OK) {
@@ -1083,5 +1049,5 @@
         *ppZStencilSurface = NULL;
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -1093,7 +1059,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1104,7 +1071,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1116,7 +1084,8 @@
 
     /* Note: D3DRECT is compatible with WINED3DRECT */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1128,7 +1097,8 @@
 
     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1140,7 +1110,8 @@
 
     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1152,7 +1123,8 @@
 
     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1164,7 +1136,8 @@
 
     /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1176,7 +1149,8 @@
 
     /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1188,7 +1162,8 @@
 
     /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1200,7 +1175,8 @@
 
     /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1210,9 +1186,10 @@
     HRESULT hr;
     TRACE("(%p) Relay\n" , This);
- 
+
     /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1224,7 +1201,8 @@
 
     /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1235,7 +1213,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1246,7 +1225,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1257,7 +1237,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1268,7 +1249,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1279,7 +1261,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1290,7 +1273,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1301,7 +1285,8 @@
     TRACE("(%p)\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1318,9 +1303,9 @@
      * of memory later and cause locking problems)
      */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_EndStateBlock(This->WineD3DDevice , &wineD3DStateBlock);
     if (hr != D3D_OK) {
         WARN("IWineD3DDevice_EndStateBlock returned an error\n");
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
         return hr;
     }
@@ -1334,5 +1319,5 @@
 
     *pToken = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (*pToken == D3D8_INVALID_HANDLE)
@@ -1356,14 +1341,15 @@
     TRACE("(%p) %#x Relay\n", This, Token);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
     if (!pSB)
     {
         WARN("Invalid handle (%#x) passed.\n", Token);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
         return D3DERR_INVALIDCALL;
     }
     hr = IWineD3DStateBlock_Apply(pSB->wineD3DStateBlock);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1376,14 +1362,15 @@
     TRACE("(%p) %#x Relay\n", This, Token);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
     if (!pSB)
     {
         WARN("Invalid handle (%#x) passed.\n", Token);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
         return D3DERR_INVALIDCALL;
     }
     hr = IWineD3DStateBlock_Capture(pSB->wineD3DStateBlock);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1395,7 +1382,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     pSB = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (!pSB)
@@ -1440,10 +1427,10 @@
     object->ref = 1;
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type,
             &object->wineD3DStateBlock, (IUnknown *)object);
     if (FAILED(hr))
     {
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
         ERR("IWineD3DDevice_CreateStateBlock failed, hr %#x\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
@@ -1452,5 +1439,5 @@
 
     *handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (*handle == D3D8_INVALID_HANDLE)
@@ -1472,7 +1459,9 @@
     TRACE("(%p) Relay\n" , This);
 /* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
-    EnterCriticalSection(&d3d8_cs);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1483,7 +1472,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1491,6 +1481,6 @@
 static HRESULT WINAPI IDirect3DDevice8Impl_GetTexture(LPDIRECT3DDEVICE8 iface, DWORD Stage,IDirect3DBaseTexture8** ppTexture) {
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    IWineD3DBaseTexture *retTexture = NULL;
-    HRESULT rc = D3D_OK;
+    IWineD3DBaseTexture *retTexture;
+    HRESULT hr;
 
     TRACE("(%p) Relay\n" , This);
@@ -1500,16 +1490,26 @@
     }
 
-    EnterCriticalSection(&d3d8_cs);
-    rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
-    if (rc == D3D_OK && NULL != retTexture) {
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
+    if (FAILED(hr))
+    {
+        WARN("Failed to get texture for stage %u, hr %#x.\n", Stage, hr);
+        wined3d_mutex_unlock();
+        *ppTexture = NULL;
+        return hr;
+    }
+
+    if (retTexture)
+    {
         IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
         IWineD3DBaseTexture_Release(retTexture);
-    } else {
-        FIXME("Call to get texture  (%d) failed (%p)\n", Stage, retTexture);
+    }
+    else
+    {
         *ppTexture = NULL;
     }
-    LeaveCriticalSection(&d3d8_cs);
-
-    return rc;
+    wined3d_mutex_unlock();
+
+    return D3D_OK;
 }
 
@@ -1519,8 +1519,9 @@
     TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
                                    pTexture==NULL ? NULL : ((IDirect3DBaseTexture8Impl *)pTexture)->wineD3DBaseTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1570,10 +1571,9 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
-
+    wined3d_mutex_lock();
     if (l->sampler_state) hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Stage, l->state, pValue);
     else hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, l->state, pValue);
-
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1585,10 +1585,9 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
-
+    wined3d_mutex_lock();
     if (l->sampler_state) hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Stage, l->state, Value);
     else hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, l->state, Value);
-
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1599,7 +1598,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1616,7 +1616,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1627,7 +1628,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1638,7 +1640,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1649,20 +1652,24 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
-    LeaveCriticalSection(&d3d8_cs);
-    return hr;
-}
-
-static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(LPDIRECT3DDEVICE8 iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface; 
-    HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
-
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface, D3DPRIMITIVETYPE PrimitiveType,
+        UINT StartVertex, UINT PrimitiveCount)
+{
+    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
+    HRESULT hr;
+    TRACE("(%p) Relay\n" , This);
+
+    wined3d_mutex_lock();
     IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
     hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
             vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1674,9 +1681,10 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
-    hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, MinVertexIndex, NumVertices,
-            startIndex, vertex_count_from_primitive_count(PrimitiveType, primCount));
-    LeaveCriticalSection(&d3d8_cs);
+    hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
+            vertex_count_from_primitive_count(PrimitiveType, primCount));
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1687,10 +1695,11 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
     hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
             vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
             pVertexStreamZeroData, VertexStreamZeroStride);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1704,10 +1713,11 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
-    hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, MinVertexIndex, NumVertexIndices,
+    hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
             vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
             wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1719,144 +1729,60 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, NULL, Flags, dest->fvf);
-    LeaveCriticalSection(&d3d8_cs);
-    return hr;
-}
-
-static HRESULT IDirect3DDevice8Impl_CreateVertexDeclaration(IDirect3DDevice8 *iface, CONST DWORD *declaration, IDirect3DVertexDeclaration8 **decl_ptr) {
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    IDirect3DVertexDeclaration8Impl *object;
-    WINED3DVERTEXELEMENT *wined3d_elements;
-    UINT wined3d_element_count;
-    HRESULT hr = D3D_OK;
-
-    TRACE("(%p) : declaration %p\n", This, declaration);
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8 *iface,
+        const DWORD *declaration, const DWORD *byte_code, DWORD *shader, DWORD usage)
+{
+    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
+    IDirect3DVertexShader8Impl *object;
+    DWORD shader_handle;
+    DWORD handle;
+    HRESULT hr;
+
+    TRACE("iface %p, declaration %p, byte_code %p, shader %p, usage %#x.\n",
+            iface, declaration, byte_code, shader, usage);
 
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if (!object) {
-        ERR("Memory allocation failed\n");
-        *decl_ptr = NULL;
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->ref_count = 1;
-    object->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
-
-    wined3d_element_count = convert_to_wined3d_declaration(declaration, &object->elements_size, &wined3d_elements);
-    object->elements = HeapAlloc(GetProcessHeap(), 0, object->elements_size);
-    if (!object->elements) {
-        ERR("Memory allocation failed\n");
-        HeapFree(GetProcessHeap(), 0, wined3d_elements);
+    if (!object)
+    {
+        ERR("Failed to allocate vertex shader memory.\n");
+        *shader = 0;
+        return E_OUTOFMEMORY;
+    }
+
+    wined3d_mutex_lock();
+    handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
+    wined3d_mutex_unlock();
+    if (handle == D3D8_INVALID_HANDLE)
+    {
+        ERR("Failed to allocate vertex shader handle.\n");
         HeapFree(GetProcessHeap(), 0, object);
-        *decl_ptr = NULL;
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    CopyMemory(object->elements, declaration, object->elements_size);
-
-    EnterCriticalSection(&d3d8_cs);
-    hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wined3d_vertex_declaration,
-            (IUnknown *)object, wined3d_elements, wined3d_element_count);
-    LeaveCriticalSection(&d3d8_cs);
-    HeapFree(GetProcessHeap(), 0, wined3d_elements);
-
-    if (FAILED(hr)) {
-        ERR("(%p) : IWineD3DDevice_CreateVertexDeclaration call failed\n", This);
-        HeapFree(GetProcessHeap(), 0, object->elements);
+        *shader = 0;
+        return E_OUTOFMEMORY;
+    }
+
+    shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
+
+    hr = vertexshader_init(object, This, declaration, byte_code, shader_handle, usage);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
+        wined3d_mutex_lock();
+        d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
+        wined3d_mutex_unlock();
         HeapFree(GetProcessHeap(), 0, object);
-    } else {
-        *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
-        TRACE("(%p) : Created vertex declaration %p\n", This, object);
-    }
-
-    return hr;
-}
-
-static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pDeclaration, CONST DWORD* pFunction, DWORD* ppShader, DWORD Usage) {
-    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
-    HRESULT hrc = D3D_OK;
-    IDirect3DVertexShader8Impl *object;
-    const DWORD *token = pDeclaration;
-    DWORD handle;
-
-    /* Test if the vertex declaration is valid */
-    while (D3DVSD_END() != *token) {
-        D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
-
-        if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000)) {
-            DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
-            DWORD reg  = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
-
-            if(reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !pFunction) {
-                WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
-                return D3DERR_INVALIDCALL;
-            }
-        }
-        token += parse_token(token);
-    }
-
-    /* Setup a stub object for now */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
-    if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
-        *ppShader = 0;
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->ref = 1;
-    object->lpVtbl = &Direct3DVertexShader8_Vtbl;
-
-    hrc = IDirect3DDevice8Impl_CreateVertexDeclaration(iface, pDeclaration, &object->vertex_declaration);
-    if (FAILED(hrc)) {
-        ERR("(%p) : IDirect3DDeviceImpl_CreateVertexDeclaration call failed\n", This);
-        HeapFree(GetProcessHeap(), 0, object);
-        *ppShader = 0;
-        return D3DERR_INVALIDCALL;
-    }
-
-    EnterCriticalSection(&d3d8_cs);
-    handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
-    if (handle == D3D8_INVALID_HANDLE)
-    {
-        ERR("Failed to allocate shader handle\n");
-        LeaveCriticalSection(&d3d8_cs);
-        IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
-        HeapFree(GetProcessHeap(), 0, object);
-        *ppShader = 0;
-        return E_OUTOFMEMORY;
-    }
-    else
-    {
-        DWORD shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
-        *ppShader = ((IDirect3DVertexDeclaration8Impl *)object->vertex_declaration)->shader_handle = shader_handle;
-    }
-
-    if (pFunction)
-    {
-        /* Usage is missing ... Use SetRenderState to set the sw vp render state in SetVertexShader */
-        hrc = IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, pFunction,
-                NULL /* output signature */, &object->wineD3DVertexShader, (IUnknown *)object);
-
-        if (FAILED(hrc))
-        {
-            /* free up object */
-            FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
-            d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
-            IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
-            HeapFree(GetProcessHeap(), 0, object);
-            *ppShader = 0;
-        }
-        else
-        {
-            load_local_constants(pDeclaration, object->wineD3DVertexShader);
-            TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
-        }
-    }
-
-    LeaveCriticalSection(&d3d8_cs);
-
-    return hrc;
+        *shader = 0;
+        return hr;
+    }
+
+    TRACE("Created vertex shader %p (handle %#x).\n", object, shader_handle);
+    *shader = shader_handle;
+
+    return D3D_OK;
 }
 
@@ -1893,15 +1819,8 @@
     }
 
-    d3d8_declaration->ref_count = 1;
-    d3d8_declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
-    d3d8_declaration->elements = NULL;
-    d3d8_declaration->elements_size = 0;
-    d3d8_declaration->shader_handle = fvf;
-
-    hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(This->WineD3DDevice,
-            &d3d8_declaration->wined3d_vertex_declaration, (IUnknown *)d3d8_declaration, fvf);
+    hr = vertexdeclaration_init_fvf(d3d8_declaration, This, fvf);
     if (FAILED(hr))
     {
-        ERR("Failed to create wined3d vertex declaration.\n");
+        WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, d3d8_declaration);
         return NULL;
@@ -1940,9 +1859,10 @@
         TRACE("Setting FVF, %#x\n", pShader);
 
-        EnterCriticalSection(&d3d8_cs);
+        wined3d_mutex_lock();
         IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice,
                 IDirect3DDevice8Impl_FindDecl(This, pShader)->wined3d_vertex_declaration);
         IWineD3DDevice_SetVertexShader(This->WineD3DDevice, NULL);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
+
         return D3D_OK;
     }
@@ -1950,10 +1870,11 @@
     TRACE("Setting shader\n");
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
     if (!shader)
     {
         WARN("Invalid handle (%#x) passed.\n", pShader);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
+
         return D3DERR_INVALIDCALL;
     }
@@ -1962,5 +1883,5 @@
             ((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
     if (SUCCEEDED(hr)) hr = IWineD3DDevice_SetVertexShader(This->WineD3DDevice, shader->wineD3DVertexShader);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     TRACE("Returning hr %#x\n", hr);
@@ -1976,10 +1897,10 @@
 
     TRACE("(%p) : Relay  device@%p\n", This, This->WineD3DDevice);
-    EnterCriticalSection(&d3d8_cs);
-
+
+    wined3d_mutex_lock();
     hrc = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &wined3d_declaration);
     if (FAILED(hrc))
     {
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
         WARN("(%p) : Call to IWineD3DDevice_GetVertexDeclaration failed %#x (device %p)\n",
                 This, hrc, This->WineD3DDevice);
@@ -1989,5 +1910,5 @@
     if (!wined3d_declaration)
     {
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
         *ppShader = 0;
         return D3D_OK;
@@ -1996,5 +1917,5 @@
     hrc = IWineD3DVertexDeclaration_GetParent(wined3d_declaration, (IUnknown **)&d3d8_declaration);
     IWineD3DVertexDeclaration_Release(wined3d_declaration);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
     if (SUCCEEDED(hrc))
     {
@@ -2015,11 +1936,11 @@
     TRACE("(%p) : pShader %#x\n", This, pShader);
 
-    EnterCriticalSection(&d3d8_cs);
-
+    wined3d_mutex_lock();
     shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
     if (!shader)
     {
         WARN("Invalid handle (%#x) passed.\n", pShader);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
+
         return D3DERR_INVALIDCALL;
     }
@@ -2033,5 +1954,5 @@
     }
 
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (IUnknown_Release((IUnknown *)shader))
@@ -2054,7 +1975,8 @@
     }
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -2071,7 +1993,8 @@
     }
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -2084,8 +2007,8 @@
     TRACE("(%p) : pVertexShader 0x%08x, pData %p, *pSizeOfData %u\n", This, pVertexShader, pData, *pSizeOfData);
 
-    EnterCriticalSection(&d3d8_cs);
-
+    wined3d_mutex_lock();
     shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     if (!shader)
     {
@@ -2120,11 +2043,11 @@
     TRACE("(%p) : pVertexShader %#x, pData %p, pSizeOfData %p\n", This, pVertexShader, pData, pSizeOfData);
 
-    EnterCriticalSection(&d3d8_cs);
-
+    wined3d_mutex_lock();
     shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
     if (!shader)
     {
         WARN("Invalid handle (%#x) passed.\n", pVertexShader);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
+
         return D3DERR_INVALIDCALL;
     }
@@ -2132,5 +2055,5 @@
     if (!shader->wineD3DVertexShader)
     {
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
         *pSizeOfData = 0;
         return D3D_OK;
@@ -2138,6 +2061,6 @@
 
     hr = IWineD3DVertexShader_GetFunction(shader->wineD3DVertexShader, pData, pSizeOfData);
-
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -2149,5 +2072,4 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
     /* WineD3D takes an INT(due to d3d9), but d3d8 uses UINTs. Do I have to add a check here that
      * the UINT doesn't cause an overflow in the INT? It seems rather unlikely because such large
@@ -2156,9 +2078,11 @@
      * problem)
      */
+    wined3d_mutex_lock();
     IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, baseVertexIndex);
-    hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
+    hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
             ib ? ib->wineD3DIndexBuffer : NULL,
             ib ? ib->format : WINED3DFMT_UNKNOWN);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -2175,8 +2099,8 @@
     }
 
-    EnterCriticalSection(&d3d8_cs);
     /* The case from UINT to INT is safe because d3d8 will never set negative values */
+    wined3d_mutex_lock();
     IWineD3DDevice_GetBaseVertexIndex(This->WineD3DDevice, (INT *) pBaseVertexIndex);
-    rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
+    rc = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
     if (SUCCEEDED(rc) && retIndexData) {
         IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
@@ -2186,17 +2110,22 @@
         *ppIndexData = NULL;
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     return rc;
 }
-static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(LPDIRECT3DDEVICE8 iface, CONST DWORD* pFunction, DWORD* ppShader) {
+
+static HRESULT WINAPI IDirect3DDevice8Impl_CreatePixelShader(IDirect3DDevice8 *iface,
+        const DWORD *byte_code, DWORD *shader)
+{
     IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     IDirect3DPixelShader8Impl *object;
+    DWORD shader_handle;
     DWORD handle;
     HRESULT hr;
 
-    TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
-
-    if (NULL == ppShader) {
+    TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
+
+    if (!shader)
+    {
         TRACE("(%p) Invalid call\n", This);
         return D3DERR_INVALIDCALL;
@@ -2206,36 +2135,36 @@
     if (!object)
     {
-        ERR("Failed to allocate memmory.\n");
+        ERR("Failed to allocate pixel shader memmory.\n");
         return E_OUTOFMEMORY;
     }
 
-    object->ref    = 1;
-    object->lpVtbl = &Direct3DPixelShader8_Vtbl;
-
-    EnterCriticalSection(&d3d8_cs);
-    hr = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction,
-            NULL, &object->wineD3DPixelShader, (IUnknown *)object);
+    wined3d_mutex_lock();
+    handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
+    wined3d_mutex_unlock();
+    if (handle == D3D8_INVALID_HANDLE)
+    {
+        ERR("Failed to allocate pixel shader handle.\n");
+        HeapFree(GetProcessHeap(), 0, object);
+        return E_OUTOFMEMORY;
+    }
+
+    shader_handle = handle + VS_HIGHESTFIXEDFXF + 1;
+
+    hr = pixelshader_init(object, This, byte_code, shader_handle);
     if (FAILED(hr))
     {
-        LeaveCriticalSection(&d3d8_cs);
-        FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
-        HeapFree(GetProcessHeap(), 0 , object);
-        *ppShader = 0;
+        WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
+        wined3d_mutex_lock();
+        d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_PS);
+        wined3d_mutex_unlock();
+        HeapFree(GetProcessHeap(), 0, object);
+        *shader = 0;
         return hr;
     }
 
-    handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
-    LeaveCriticalSection(&d3d8_cs);
-    if (handle == D3D8_INVALID_HANDLE)
-    {
-        ERR("Failed to allocate shader handle\n");
-        IDirect3DVertexShader8_Release((IUnknown *)object);
-        return E_OUTOFMEMORY;
-    }
-
-    *ppShader = object->handle = handle + VS_HIGHESTFIXEDFXF + 1;
-    TRACE("(%p) : returning %p (handle %#x)\n", This, object, *ppShader);
-
-    return hr;
+    TRACE("Created pixel shader %p (handle %#x).\n", object, shader_handle);
+    *shader = shader_handle;
+
+    return D3D_OK;
 }
 
@@ -2247,10 +2176,10 @@
     TRACE("(%p) : pShader %#x\n", This, pShader);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
 
     if (!pShader)
     {
         hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, NULL);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
         return hr;
     }
@@ -2260,5 +2189,5 @@
     {
         WARN("Invalid handle (%#x) passed.\n", pShader);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
         return D3DERR_INVALIDCALL;
     }
@@ -2266,5 +2195,6 @@
     TRACE("(%p) : Setting shader %p\n", This, shader);
     hr = IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader->wineD3DPixelShader);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -2281,5 +2211,5 @@
     }
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
     if (D3D_OK == hrc && NULL != object) {
@@ -2292,7 +2222,8 @@
         *ppShader = 0;
     }
+    wined3d_mutex_unlock();
 
     TRACE("(%p) : returning %#x\n", This, *ppShader);
-    LeaveCriticalSection(&d3d8_cs);
+
     return hrc;
 }
@@ -2305,5 +2236,5 @@
     TRACE("(%p) : pShader %#x\n", This, pShader);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
 
     shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
@@ -2311,5 +2242,5 @@
     {
         WARN("Invalid handle (%#x) passed.\n", pShader);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
         return D3D_OK;
     }
@@ -2323,5 +2254,5 @@
     }
 
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (IUnknown_Release((IUnknown *)shader))
@@ -2338,7 +2269,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -2349,7 +2281,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, ConstantCount);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -2362,15 +2295,17 @@
     TRACE("(%p) : pPixelShader %#x, pData %p, pSizeOfData %p\n", This, pPixelShader, pData, pSizeOfData);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
     if (!shader)
     {
         WARN("Invalid handle (%#x) passed.\n", pPixelShader);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
+
         return D3DERR_INVALIDCALL;
     }
 
     hr = IWineD3DPixelShader_GetFunction(shader->wineD3DPixelShader, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -2381,7 +2316,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -2392,7 +2328,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -2403,7 +2340,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -2414,9 +2352,10 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
                                         NULL == pStreamData ? NULL : ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer,
                                         0/* Offset in bytes */, Stride);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -2433,5 +2372,5 @@
     }
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, 0 /* Offset in bytes */, pStride);
     if (rc == D3D_OK  && NULL != retStream) {
@@ -2444,5 +2383,5 @@
         *pStream = NULL;
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     return rc;
@@ -2551,15 +2490,4 @@
 };
 
-ULONG WINAPI D3D8CB_DestroySurface(IWineD3DSurface *pSurface) {
-    IDirect3DSurface8Impl* surfaceParent;
-    TRACE("(%p) call back\n", pSurface);
-
-    IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
-    /* GetParent's AddRef was forwarded to an object in destruction.
-     * Releasing it here again would cause an endless recursion. */
-    surfaceParent->forwardReference = NULL;
-    return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);
-}
-
 /* IWineD3DDeviceParent IUnknown methods */
 
@@ -2621,7 +2549,11 @@
 
     *surface = d3d_surface->wineD3DSurface;
+    IWineD3DSurface_AddRef(*surface);
+
     d3d_surface->container = superior;
     IUnknown_Release(d3d_surface->parentDevice);
     d3d_surface->parentDevice = NULL;
+
+    IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
     d3d_surface->forwardReference = superior;
 
@@ -2650,6 +2582,7 @@
 
     *surface = d3d_surface->wineD3DSurface;
+    IWineD3DSurface_AddRef(*surface);
+
     d3d_surface->container = (IUnknown *)This;
-    d3d_surface->isImplicit = TRUE;
     /* Implicit surfaces are created with an refcount of 0 */
     IUnknown_Release((IUnknown *)d3d_surface);
@@ -2679,6 +2612,7 @@
 
     *surface = d3d_surface->wineD3DSurface;
+    IWineD3DSurface_AddRef(*surface);
+
     d3d_surface->container = (IUnknown *)This;
-    d3d_surface->isImplicit = TRUE;
     /* Implicit surfaces are created with an refcount of 0 */
     IUnknown_Release((IUnknown *)d3d_surface);
@@ -2707,21 +2641,20 @@
     }
 
-    object->lpVtbl = &Direct3DVolume8_Vtbl;
-    object->ref = 1;
-    hr = IWineD3DDevice_CreateVolume(This->WineD3DDevice, width, height, depth, usage,
-            format, pool, &object->wineD3DVolume, (IUnknown *)object);
+    hr = volume_init(object, This, width, height, depth, usage, format, pool);
     if (FAILED(hr))
     {
-        ERR("(%p) CreateVolume failed, returning %#x\n", iface, hr);
+        WARN("Failed to initialize volume, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *volume = NULL;
         return hr;
     }
 
     *volume = object->wineD3DVolume;
+    IWineD3DVolume_AddRef(*volume);
+    IDirect3DVolume8_Release((IDirect3DVolume8 *)object);
+
     object->container = superior;
     object->forwardReference = superior;
 
-    TRACE("(%p) Created volume %p\n", iface, *volume);
+    TRACE("(%p) Created volume %p\n", iface, object);
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/directx.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/directx.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/directx.c	(revision 23571)
@@ -81,7 +81,9 @@
     if (ref == 0) {
         TRACE("Releasing wined3d %p\n", This->WineD3D);
-        EnterCriticalSection(&d3d8_cs);
+
+        wined3d_mutex_lock();
         IWineD3D_Release(This->WineD3D);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
+
         HeapFree(GetProcessHeap(), 0, This);
     }
@@ -96,7 +98,8 @@
     TRACE("(%p)->(%p)\n", This, pInitializeFunction);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -107,7 +110,8 @@
     TRACE("(%p)\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_GetAdapterCount(This->WineD3D);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -129,7 +133,7 @@
     adapter_id.device_name_size = 0; /* d3d9 only */
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     pIdentifier->DriverVersion = adapter_id.driver_version;
@@ -149,7 +153,8 @@
     TRACE("(%p)->(%d)\n", This, Adapter);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, 0 /* format */);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -160,7 +165,7 @@
     TRACE("(%p)->(%d, %d, %p)\n", This, Adapter, Mode, pMode);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, WINED3DFMT_UNKNOWN, Mode, (WINED3DDISPLAYMODE *) pMode);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -174,7 +179,7 @@
     TRACE("(%p)->(%d,%p)\n", This, Adapter, pMode);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -190,8 +195,9 @@
     TRACE("(%p)->(%d, %d, %d, %d, %s)\n", This, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed ? "true" : "false");
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
             wined3dformat_from_d3dformat(BackBufferFormat), Windowed);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -224,37 +230,40 @@
     }
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
             Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
-    LeaveCriticalSection(&d3d8_cs);
-    return hr;
-}
-
-static HRESULT  WINAPI  IDirect3D8Impl_CheckDeviceMultiSampleType(LPDIRECT3D8 iface,
-							   UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
-							   BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType) {
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3D8Impl_CheckDeviceMultiSampleType(IDirect3D8 *iface, UINT Adapter,
+        D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType)
+{
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
     HRESULT hr;
     TRACE("(%p)-<(%d, %d, %d, %s, %d)\n", This, Adapter, DeviceType, SurfaceFormat, Windowed ? "true" : "false", MultiSampleType);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType,
             wined3dformat_from_d3dformat(SurfaceFormat), Windowed, (WINED3DMULTISAMPLE_TYPE) MultiSampleType, NULL);
-    LeaveCriticalSection(&d3d8_cs);
-    return hr;
-}
-
-static HRESULT  WINAPI  IDirect3D8Impl_CheckDepthStencilMatch(LPDIRECT3D8 iface, 
-						       UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
-						       D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3D8Impl_CheckDepthStencilMatch(IDirect3D8 *iface, UINT Adapter, D3DDEVTYPE DeviceType,
+        D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat)
+{
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
     HRESULT hr;
     TRACE("(%p)-<(%d, %d, %d, %d, %d)\n", This, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType,
             wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
             wined3dformat_from_d3dformat(DepthStencilFormat));
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -288,7 +297,9 @@
         return D3DERR_INVALIDCALL; /*well this is what MSDN says to return*/
     }
-    EnterCriticalSection(&d3d8_cs);
+
+    wined3d_mutex_lock();
     hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     fixup_caps(pWineCaps);
     WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
@@ -304,18 +315,9 @@
     TRACE("(%p)->(%d)\n", This, Adapter);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
-}
-
-ULONG WINAPI D3D8CB_DestroyRenderTarget(IWineD3DSurface *pSurface) {
-    IDirect3DSurface8Impl* surfaceParent;
-    TRACE("(%p) call back\n", pSurface);
-
-    IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
-    surfaceParent->isImplicit = FALSE;
-    /* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
-    return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);
 }
 
@@ -327,14 +329,4 @@
     IUnknown_Release(swapChainParent);
     return IUnknown_Release(swapChainParent);
-}
-
-ULONG WINAPI D3D8CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface) {
-    IDirect3DSurface8Impl* surfaceParent;
-    TRACE("(%p) call back\n", pSurface);
-
-    IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
-    surfaceParent->isImplicit = FALSE;
-    /* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
-    return IDirect3DSurface8_Release((IDirect3DSurface8*) surfaceParent);
 }
 
@@ -372,5 +364,5 @@
 
     /* Allocate an associated WineD3DDevice object */
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags,
             (IUnknown *)object, (IWineD3DDeviceParent *)&object->device_parent_vtbl, &object->WineD3DDevice);
@@ -379,5 +371,6 @@
         HeapFree(GetProcessHeap(), 0, object);
         *ppReturnedDeviceInterface = NULL;
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
+
         return hr;
     }
@@ -406,5 +399,5 @@
 
     hr = IWineD3DDevice_Init3D(object->WineD3DDevice, &localParameters);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
@@ -432,7 +425,9 @@
     if(!object->decls) {
         ERR("Out of memory\n");
-        EnterCriticalSection(&d3d8_cs);
+
+        wined3d_mutex_lock();
         IWineD3DDevice_Release(object->WineD3DDevice);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
+
         HeapFree(GetProcessHeap(), 0, object);
         *ppReturnedDeviceInterface = NULL;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/indexbuffer.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/indexbuffer.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/indexbuffer.c	(revision 23571)
@@ -56,4 +56,12 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        IDirect3DDevice8_AddRef(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DBuffer_AddRef(This->wineD3DIndexBuffer);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -66,9 +74,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d8_cs);
+        IDirect3DDevice8_Release(This->parentDevice);
+        wined3d_mutex_lock();
         IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
-        LeaveCriticalSection(&d3d8_cs);
-        IUnknown_Release(This->parentDevice);
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_unlock();
     }
     return ref;
@@ -82,5 +89,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -89,5 +96,6 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -98,7 +106,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -109,7 +118,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -120,7 +130,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -131,7 +142,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -142,7 +154,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -152,7 +165,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -170,7 +183,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -181,7 +195,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -193,7 +208,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) {
@@ -208,6 +223,5 @@
 }
 
-
-const IDirect3DIndexBuffer8Vtbl Direct3DIndexBuffer8_Vtbl =
+static const IDirect3DIndexBuffer8Vtbl Direct3DIndexBuffer8_Vtbl =
 {
     /* IUnknown */
@@ -229,2 +243,38 @@
     IDirect3DIndexBuffer8Impl_GetDesc
 };
+
+static void STDMETHODCALLTYPE d3d8_indexbuffer_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d8_indexbuffer_wined3d_parent_ops =
+{
+    d3d8_indexbuffer_wined3d_object_destroyed,
+};
+
+HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
+        UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
+{
+    HRESULT hr;
+
+    buffer->lpVtbl = &Direct3DIndexBuffer8_Vtbl;
+    buffer->ref = 1;
+    buffer->format = wined3dformat_from_d3dformat(format);
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateIndexBuffer(device->WineD3DDevice, size,
+            usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DIndexBuffer,
+            (IUnknown *)buffer, &d3d8_indexbuffer_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
+        return hr;
+    }
+
+    buffer->parentDevice = (IDirect3DDevice8 *)device;
+    IUnknown_AddRef(buffer->parentDevice);
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/pixelshader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/pixelshader.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/pixelshader.c	(revision 23571)
@@ -56,4 +56,11 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        wined3d_mutex_lock();
+        IWineD3DPixelShader_AddRef(This->wineD3DPixelShader);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -66,13 +73,12 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d8_cs);
+        wined3d_mutex_lock();
         IWineD3DPixelShader_Release(This->wineD3DPixelShader);
-        LeaveCriticalSection(&d3d8_cs);
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_unlock();
     }
     return ref;
 }
 
-const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl =
+static const IDirect3DPixelShader8Vtbl Direct3DPixelShader8_Vtbl =
 {
     /* IUnknown */
@@ -81,2 +87,35 @@
     IDirect3DPixelShader8Impl_Release,
 };
+
+static void STDMETHODCALLTYPE d3d8_pixelshader_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d8_pixelshader_wined3d_parent_ops =
+{
+    d3d8_pixelshader_wined3d_object_destroyed,
+};
+
+HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl *device,
+        const DWORD *byte_code, DWORD shader_handle)
+{
+    HRESULT hr;
+
+    shader->ref = 1;
+    shader->lpVtbl = &Direct3DPixelShader8_Vtbl;
+    shader->handle = shader_handle;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreatePixelShader(device->WineD3DDevice, byte_code,
+            NULL, &shader->wineD3DPixelShader, (IUnknown *)shader,
+            &d3d8_pixelshader_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
+        return hr;
+    }
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/stateblock.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/stateblock.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/stateblock.c	(revision 23571)
@@ -68,7 +68,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d8_cs);
+        wined3d_mutex_lock();
         IWineD3DStateBlock_Release(This->wineD3DStateBlock);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_unlock();
+
         HeapFree(GetProcessHeap(), 0, This);
     }
@@ -84,6 +85,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
-
+    wined3d_mutex_lock();
     hr = IWineD3DStateBlock_GetDevice(This->wineD3DStateBlock, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -92,6 +92,5 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -104,9 +103,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
-
+    wined3d_mutex_lock();
     hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
-
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -119,9 +116,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
-
+    wined3d_mutex_lock();
     hr = IWineD3DStateBlock_Apply(This->wineD3DStateBlock);
-
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/surface.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/surface.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/surface.c	(revision 23571)
@@ -62,5 +62,11 @@
         /* No container, handle our own refcounting */
         ULONG ref = InterlockedIncrement(&This->ref);
-        if(ref == 1 && This->parentDevice) IUnknown_AddRef(This->parentDevice);
+        if (ref == 1)
+        {
+            if (This->parentDevice) IUnknown_AddRef(This->parentDevice);
+            wined3d_mutex_lock();
+            IUnknown_AddRef(This->wineD3DSurface);
+            wined3d_mutex_unlock();
+        }
         TRACE("(%p) : AddRef from %d\n", This, ref - 1);
         return ref;
@@ -85,10 +91,7 @@
             if (This->parentDevice) IUnknown_Release(This->parentDevice);
             /* Implicit surfaces are destroyed with the device, not if refcount reaches 0. */
-            if (!This->isImplicit) {
-                EnterCriticalSection(&d3d8_cs);
-                IWineD3DSurface_Release(This->wineD3DSurface);
-                LeaveCriticalSection(&d3d8_cs);
-                HeapFree(GetProcessHeap(), 0, This);
-            }
+            wined3d_mutex_lock();
+            IWineD3DSurface_Release(This->wineD3DSurface);
+            wined3d_mutex_unlock();
         }
 
@@ -104,5 +107,5 @@
     TRACE("(%p)->(%p)\n", This, ppDevice);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_GetDevice(This->wineD3DSurface, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -111,5 +114,6 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -120,7 +124,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -131,7 +136,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -142,7 +148,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -169,7 +176,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr))
@@ -194,5 +201,5 @@
     TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     if (pRect) {
         D3DSURFACE_DESC desc;
@@ -206,5 +213,6 @@
                 || (pRect->bottom > desc.Height)) {
             WARN("Trying to lock an invalid rectangle, returning D3DERR_INVALIDCALL\n");
-            LeaveCriticalSection(&d3d8_cs);
+            wined3d_mutex_unlock();
+
             return D3DERR_INVALIDCALL;
         }
@@ -212,5 +220,6 @@
 
     hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -221,7 +230,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     switch(hr)
     {
@@ -231,5 +241,5 @@
 }
 
-const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
+static const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
 {
     /* IUnknown */
@@ -248,2 +258,46 @@
     IDirect3DSurface8Impl_UnlockRect
 };
+
+static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d8_surface_wined3d_parent_ops =
+{
+    surface_wined3d_object_destroyed,
+};
+
+HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *device,
+        UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
+        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
+{
+    HRESULT hr;
+
+    surface->lpVtbl = &Direct3DSurface8_Vtbl;
+    surface->ref = 1;
+
+    /* FIXME: Check MAX bounds of MultisampleQuality. */
+    if (multisample_quality > 0)
+    {
+        FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality);
+        multisample_quality = 0;
+    }
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateSurface(device->WineD3DDevice, width, height, wined3dformat_from_d3dformat(format),
+            lockable, discard, level, &surface->wineD3DSurface, usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool,
+            multisample_type, multisample_quality, SURFACE_OPENGL, (IUnknown *)surface,
+            &d3d8_surface_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d surface, hr %#x.\n", hr);
+        return hr;
+    }
+
+    surface->parentDevice = (IDirect3DDevice8 *)device;
+    IUnknown_AddRef(surface->parentDevice);
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/swapchain.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/swapchain.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/swapchain.c	(revision 23571)
@@ -66,7 +66,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d8_cs);
-        IWineD3DSwapChain_Destroy(This->wineD3DSwapChain, D3D8CB_DestroyRenderTarget);
-        LeaveCriticalSection(&d3d8_cs);
+        wined3d_mutex_lock();
+        IWineD3DSwapChain_Destroy(This->wineD3DSwapChain);
+        wined3d_mutex_unlock();
+
         if (This->parentDevice) IUnknown_Release(This->parentDevice);
         HeapFree(GetProcessHeap(), 0, This);
@@ -81,7 +82,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, 0);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -94,5 +96,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, (WINED3DBACKBUFFER_TYPE )Type, &mySurface);
     if (hrc == D3D_OK && NULL != mySurface) {
@@ -100,5 +102,6 @@
        IWineD3DSurface_Release(mySurface);
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hrc;
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/texture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/texture.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/texture.c	(revision 23571)
@@ -57,4 +57,12 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        IDirect3DDevice8_AddRef(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DTexture_AddRef(This->wineD3DTexture);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -67,9 +75,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d8_cs);
-        IWineD3DTexture_Destroy(This->wineD3DTexture, D3D8CB_DestroySurface);
-        LeaveCriticalSection(&d3d8_cs);
-        IUnknown_Release(This->parentDevice);
-        HeapFree(GetProcessHeap(), 0, This);
+        IDirect3DDevice8_Release(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DTexture_Release(This->wineD3DTexture);
+        wined3d_mutex_unlock();
     }
     return ref;
@@ -82,5 +89,6 @@
     HRESULT hr;
     TRACE("(%p) Relay\n", This);
-    EnterCriticalSection(&d3d8_cs);
+
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_GetDevice(This->wineD3DTexture, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -89,5 +97,6 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -98,7 +107,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -109,7 +119,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -120,7 +131,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -131,7 +143,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -142,7 +155,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -152,7 +166,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DTexture_PreLoad(This->wineD3DTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -162,7 +176,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     type = IWineD3DTexture_GetType(This->wineD3DTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return type;
 }
@@ -174,7 +189,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -185,7 +201,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -196,7 +213,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -210,7 +228,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr))
@@ -235,5 +253,6 @@
 
     TRACE("(%p) Relay\n", This);
-    EnterCriticalSection(&d3d8_cs);
+
+    wined3d_mutex_lock();
     hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
     if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
@@ -241,5 +260,6 @@
        IWineD3DSurface_Release(mySurface);
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hrc;
 }
@@ -250,7 +270,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -261,7 +282,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -272,11 +294,12 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
-    LeaveCriticalSection(&d3d8_cs);
-    return hr;
-}
-
-const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static const IDirect3DTexture8Vtbl Direct3DTexture8_Vtbl =
 {
     /* IUnknown */
@@ -304,2 +327,37 @@
     IDirect3DTexture8Impl_AddDirtyRect
 };
+
+static void STDMETHODCALLTYPE d3d8_texture_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops =
+{
+    d3d8_texture_wined3d_object_destroyed,
+};
+
+HRESULT texture_init(IDirect3DTexture8Impl *texture, IDirect3DDevice8Impl *device,
+        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
+{
+    HRESULT hr;
+
+    texture->lpVtbl = &Direct3DTexture8_Vtbl;
+    texture->ref = 1;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
+            usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
+            &texture->wineD3DTexture, (IUnknown *)texture, &d3d8_texture_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d texture, hr %#x.\n", hr);
+        return hr;
+    }
+
+    texture->parentDevice = (IDirect3DDevice8 *)device;
+    IDirect3DDevice8_AddRef(texture->parentDevice);
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexbuffer.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexbuffer.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexbuffer.c	(revision 23571)
@@ -57,4 +57,12 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        IDirect3DDevice8_AddRef(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DBuffer_AddRef(This->wineD3DVertexBuffer);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -67,9 +75,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d8_cs);
+        IDirect3DDevice8_Release(This->parentDevice);
+        wined3d_mutex_lock();
         IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
-        LeaveCriticalSection(&d3d8_cs);
-        IUnknown_Release(This->parentDevice);
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_unlock();
     }
 
@@ -84,5 +91,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetDevice(This->wineD3DVertexBuffer, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -91,5 +98,6 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -100,7 +108,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -111,7 +120,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -122,7 +132,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -133,7 +144,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -144,7 +156,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -154,7 +167,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -172,7 +185,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, ppbData, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -183,7 +197,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -195,7 +210,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &desc);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) {
@@ -211,5 +226,5 @@
 }
 
-const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
+static const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
 {
     /* IUnknown */
@@ -231,2 +246,38 @@
     IDirect3DVertexBuffer8Impl_GetDesc
 };
+
+static void STDMETHODCALLTYPE d3d8_vertexbuffer_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops =
+{
+    d3d8_vertexbuffer_wined3d_object_destroyed,
+};
+
+HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
+        UINT size, DWORD usage, DWORD fvf, D3DPOOL pool)
+{
+    HRESULT hr;
+
+    buffer->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
+    buffer->ref = 1;
+    buffer->fvf = fvf;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
+            usage & WINED3DUSAGE_MASK, 0, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
+            (IUnknown *)buffer, &d3d8_vertexbuffer_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
+        return hr;
+    }
+
+    buffer->parentDevice = (IDirect3DDevice8 *)device;
+    IUnknown_AddRef(buffer->parentDevice);
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexdeclaration.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexdeclaration.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexdeclaration.c	(revision 23571)
@@ -60,4 +60,11 @@
     TRACE("(%p) : AddRef increasing to %d\n", This, ref_count);
 
+    if (ref_count == 1)
+    {
+        wined3d_mutex_lock();
+        IWineD3DVertexDeclaration_AddRef(This->wined3d_vertex_declaration);
+        wined3d_mutex_unlock();
+    }
+
     return ref_count;
 }
@@ -71,9 +78,7 @@
 
     if (!ref_count) {
-        EnterCriticalSection(&d3d8_cs);
+        wined3d_mutex_lock();
         IWineD3DVertexDeclaration_Release(This->wined3d_vertex_declaration);
-        LeaveCriticalSection(&d3d8_cs);
-        HeapFree(GetProcessHeap(), 0, This->elements);
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_unlock();
     }
 
@@ -265,5 +270,5 @@
     /*WINED3DDECLTYPE_FLOAT3*/    WINED3DFMT_R32G32B32_FLOAT,
     /*WINED3DDECLTYPE_FLOAT4*/    WINED3DFMT_R32G32B32A32_FLOAT,
-    /*WINED3DDECLTYPE_D3DCOLOR*/  WINED3DFMT_A8R8G8B8,
+    /*WINED3DDECLTYPE_D3DCOLOR*/  WINED3DFMT_B8G8R8A8_UNORM,
     /*WINED3DDECLTYPE_UBYTE4*/    WINED3DFMT_R8G8B8A8_UINT,
     /*WINED3DDECLTYPE_SHORT2*/    WINED3DFMT_R16G16_SINT,
@@ -361,5 +366,5 @@
 }
 
-const IDirect3DVertexDeclaration8Vtbl Direct3DVertexDeclaration8_Vtbl =
+static const IDirect3DVertexDeclaration8Vtbl Direct3DVertexDeclaration8_Vtbl =
 {
     IDirect3DVertexDeclaration8Impl_QueryInterface,
@@ -367,2 +372,75 @@
     IDirect3DVertexDeclaration8Impl_Release
 };
+
+static void STDMETHODCALLTYPE d3d8_vertexdeclaration_wined3d_object_destroyed(void *parent)
+{
+    IDirect3DVertexDeclaration8Impl *declaration = parent;
+    HeapFree(GetProcessHeap(), 0, declaration->elements);
+    HeapFree(GetProcessHeap(), 0, declaration);
+}
+
+static const struct wined3d_parent_ops d3d8_vertexdeclaration_wined3d_parent_ops =
+{
+    d3d8_vertexdeclaration_wined3d_object_destroyed,
+};
+
+HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
+        IDirect3DDevice8Impl *device, const DWORD *elements, DWORD shader_handle)
+{
+    WINED3DVERTEXELEMENT *wined3d_elements;
+    UINT wined3d_element_count;
+    HRESULT hr;
+
+    declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
+    declaration->ref_count = 1;
+    declaration->shader_handle = shader_handle;
+
+    wined3d_element_count = convert_to_wined3d_declaration(elements, &declaration->elements_size, &wined3d_elements);
+    declaration->elements = HeapAlloc(GetProcessHeap(), 0, declaration->elements_size);
+    if (!declaration->elements)
+    {
+        ERR("Failed to allocate vertex declaration elements memory.\n");
+        HeapFree(GetProcessHeap(), 0, wined3d_elements);
+        return E_OUTOFMEMORY;
+    }
+
+    memcpy(declaration->elements, elements, declaration->elements_size);
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateVertexDeclaration(device->WineD3DDevice, &declaration->wined3d_vertex_declaration,
+            (IUnknown *)declaration, &d3d8_vertexdeclaration_wined3d_parent_ops,
+            wined3d_elements, wined3d_element_count);
+    wined3d_mutex_unlock();
+    HeapFree(GetProcessHeap(), 0, wined3d_elements);
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, declaration->elements);
+        return hr;
+    }
+
+    return D3D_OK;
+}
+
+HRESULT vertexdeclaration_init_fvf(IDirect3DVertexDeclaration8Impl *declaration,
+        IDirect3DDevice8Impl *device, DWORD fvf)
+{
+    HRESULT hr;
+
+    declaration->ref_count = 1;
+    declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
+    declaration->elements = NULL;
+    declaration->elements_size = 0;
+    declaration->shader_handle = fvf;
+
+    hr = IWineD3DDevice_CreateVertexDeclarationFromFVF(device->WineD3DDevice,
+            &declaration->wined3d_vertex_declaration, (IUnknown *)declaration,
+            &d3d8_vertexdeclaration_wined3d_parent_ops, fvf);
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
+        return hr;
+    }
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexshader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexshader.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/vertexshader.c	(revision 23571)
@@ -56,5 +56,19 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1 && This->wineD3DVertexShader)
+    {
+        wined3d_mutex_lock();
+        IWineD3DVertexShader_AddRef(This->wineD3DVertexShader);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
+}
+
+static void STDMETHODCALLTYPE d3d8_vertexshader_wined3d_object_destroyed(void *parent)
+{
+    IDirect3DVertexShader8Impl *shader = parent;
+    IDirect3DVertexDeclaration8_Release(shader->vertex_declaration);
+    HeapFree(GetProcessHeap(), 0, shader);
 }
 
@@ -66,17 +80,19 @@
 
     if (ref == 0) {
-        IDirect3DVertexDeclaration8_Release(This->vertex_declaration);
         if (This->wineD3DVertexShader)
         {
-            EnterCriticalSection(&d3d8_cs);
+            wined3d_mutex_lock();
             IWineD3DVertexShader_Release(This->wineD3DVertexShader);
-            LeaveCriticalSection(&d3d8_cs);
+            wined3d_mutex_unlock();
         }
-        HeapFree(GetProcessHeap(), 0, This);
+        else
+        {
+            d3d8_vertexshader_wined3d_object_destroyed(This);
+        }
     }
     return ref;
 }
 
-const IDirect3DVertexShader8Vtbl Direct3DVertexShader8_Vtbl =
+static const IDirect3DVertexShader8Vtbl Direct3DVertexShader8_Vtbl =
 {
     /* IUnknown */
@@ -85,2 +101,94 @@
     IDirect3DVertexShader8Impl_Release,
 };
+
+static const struct wined3d_parent_ops d3d8_vertexshader_wined3d_parent_ops =
+{
+    d3d8_vertexshader_wined3d_object_destroyed,
+};
+
+static HRESULT vertexshader_create_vertexdeclaration(IDirect3DDevice8Impl *device,
+        const DWORD *declaration, DWORD shader_handle, IDirect3DVertexDeclaration8 **decl_ptr)
+{
+    IDirect3DVertexDeclaration8Impl *object;
+    HRESULT hr;
+
+    TRACE("device %p, declaration %p, shader_handle %#x, decl_ptr %p.\n",
+            device, declaration, shader_handle, decl_ptr);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object) {
+        ERR("Memory allocation failed\n");
+        *decl_ptr = NULL;
+        return D3DERR_OUTOFVIDEOMEMORY;
+    }
+
+    hr = vertexdeclaration_init(object, device, declaration, shader_handle);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created vertex declaration %p.\n", object);
+    *decl_ptr = (IDirect3DVertexDeclaration8 *)object;
+
+    return D3D_OK;
+}
+
+HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Impl *device,
+        const DWORD *declaration, const DWORD *byte_code, DWORD shader_handle, DWORD usage)
+{
+    const DWORD *token = declaration;
+    HRESULT hr;
+
+    /* Test if the vertex declaration is valid */
+    while (D3DVSD_END() != *token)
+    {
+        D3DVSD_TOKENTYPE token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
+
+        if (token_type == D3DVSD_TOKEN_STREAMDATA && !(token_type & 0x10000000))
+        {
+            DWORD type = ((*token & D3DVSD_DATATYPEMASK) >> D3DVSD_DATATYPESHIFT);
+            DWORD reg  = ((*token & D3DVSD_VERTEXREGMASK) >> D3DVSD_VERTEXREGSHIFT);
+
+            if (reg == D3DVSDE_NORMAL && type != D3DVSDT_FLOAT3 && !byte_code)
+            {
+                WARN("Attempt to use a non-FLOAT3 normal with the fixed function function\n");
+                return D3DERR_INVALIDCALL;
+            }
+        }
+        token += parse_token(token);
+    }
+
+    shader->ref = 1;
+    shader->lpVtbl = &Direct3DVertexShader8_Vtbl;
+
+    hr = vertexshader_create_vertexdeclaration(device, declaration, shader_handle, &shader->vertex_declaration);
+    if (FAILED(hr))
+    {
+        WARN("Failed to create vertex declaration, hr %#x.\n", hr);
+        return hr;
+    }
+
+    if (byte_code)
+    {
+        if (usage) FIXME("Usage %#x not implemented.\n", usage);
+
+        wined3d_mutex_lock();
+        hr = IWineD3DDevice_CreateVertexShader(device->WineD3DDevice, byte_code,
+                NULL /* output signature */, &shader->wineD3DVertexShader,
+                (IUnknown *)shader, &d3d8_vertexshader_wined3d_parent_ops);
+        wined3d_mutex_unlock();
+        if (FAILED(hr))
+        {
+            WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
+            IDirect3DVertexDeclaration8_Release(shader->vertex_declaration);
+            return hr;
+        }
+
+        load_local_constants(declaration, shader->wineD3DVertexShader);
+    }
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volume.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volume.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volume.c	(revision 23571)
@@ -62,4 +62,12 @@
         ULONG ref = InterlockedIncrement(&This->ref);
         TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+
+        if (ref == 1)
+        {
+            wined3d_mutex_lock();
+            IWineD3DVolume_AddRef(This->wineD3DVolume);
+            wined3d_mutex_unlock();
+        }
+
         return ref;
     }
@@ -82,8 +90,7 @@
 
         if (ref == 0) {
-            EnterCriticalSection(&d3d8_cs);
+            wined3d_mutex_lock();
             IWineD3DVolume_Release(This->wineD3DVolume);
-            LeaveCriticalSection(&d3d8_cs);
-            HeapFree(GetProcessHeap(), 0, This);
+            wined3d_mutex_unlock();
         }
 
@@ -97,9 +104,10 @@
     IWineD3DDevice       *myDevice = NULL;
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
     IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
     IWineD3DDevice_Release(myDevice);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return D3D_OK;
 }
@@ -110,7 +118,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -121,7 +130,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -132,7 +142,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -164,7 +175,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr))
@@ -188,7 +199,8 @@
     TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *) pLockedVolume, (CONST WINED3DBOX *) pBox, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -199,11 +211,12 @@
     TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolume_UnlockBox(This->wineD3DVolume);
-    LeaveCriticalSection(&d3d8_cs);
-    return hr;
-}
-
-const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl =
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static const IDirect3DVolume8Vtbl Direct3DVolume8_Vtbl =
 {
     /* IUnknown */
@@ -222,11 +235,30 @@
 };
 
-ULONG WINAPI D3D8CB_DestroyVolume(IWineD3DVolume *pVolume) {
-    IDirect3DVolume8Impl* volumeParent;
-
-    IWineD3DVolume_GetParent(pVolume, (IUnknown **) &volumeParent);
-    /* GetParent's AddRef was forwarded to an object in destruction.
-     * Releasing it here again would cause an endless recursion. */
-    volumeParent->forwardReference = NULL;
-    return IDirect3DVolume8_Release((IDirect3DVolume8*) volumeParent);
-}
+static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d8_volume_wined3d_parent_ops =
+{
+    volume_wined3d_object_destroyed,
+};
+
+HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device, UINT width, UINT height,
+        UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool)
+{
+    HRESULT hr;
+
+    volume->lpVtbl = &Direct3DVolume8_Vtbl;
+    volume->ref = 1;
+
+    hr = IWineD3DDevice_CreateVolume(device->WineD3DDevice, width, height, depth, usage,
+            format, pool, &volume->wineD3DVolume, (IUnknown *)volume, &d3d8_volume_wined3d_parent_ops);
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d volume, hr %#x.\n", hr);
+        return hr;
+    }
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volumetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volumetexture.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volumetexture.c	(revision 23571)
@@ -57,4 +57,12 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        IDirect3DDevice8_AddRef(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DVolumeTexture_AddRef(This->wineD3DVolumeTexture);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -67,9 +75,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d8_cs);
-        IWineD3DVolumeTexture_Destroy(This->wineD3DVolumeTexture, D3D8CB_DestroyVolume);
-        LeaveCriticalSection(&d3d8_cs);
         IUnknown_Release(This->parentDevice);
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_lock();
+        IWineD3DVolumeTexture_Release(This->wineD3DVolumeTexture);
+        wined3d_mutex_unlock();
     }
     return ref;
@@ -83,5 +90,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolumeTexture_GetDevice(This->wineD3DVolumeTexture, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -90,5 +97,6 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -99,7 +107,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolumeTexture_SetPrivateData(This->wineD3DVolumeTexture, refguid, pData, SizeOfData, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -110,7 +119,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolumeTexture_GetPrivateData(This->wineD3DVolumeTexture, refguid, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -121,7 +131,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolumeTexture_FreePrivateData(This->wineD3DVolumeTexture, refguid);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -132,7 +143,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DVolumeTexture_SetPriority(This->wineD3DVolumeTexture, PriorityNew);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -143,7 +155,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DVolumeTexture_GetPriority(This->wineD3DVolumeTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -153,7 +166,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     IWineD3DVolumeTexture_PreLoad(This->wineD3DVolumeTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -163,7 +176,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     type = IWineD3DVolumeTexture_GetType(This->wineD3DVolumeTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return type;
 }
@@ -175,7 +189,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DVolumeTexture_SetLOD(This->wineD3DVolumeTexture, LODNew);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -186,7 +201,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DVolumeTexture_GetLOD(This->wineD3DVolumeTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -197,7 +213,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DVolumeTexture_GetLevelCount(This->wineD3DVolumeTexture);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -211,7 +228,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolumeTexture_GetLevelDesc(This->wineD3DVolumeTexture, Level, &wined3ddesc);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr))
@@ -237,5 +254,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hrc = IWineD3DVolumeTexture_GetVolumeLevel(This->wineD3DVolumeTexture, Level, &myVolume);
     if (hrc == D3D_OK && NULL != ppVolumeLevel) {
@@ -243,5 +260,6 @@
        IWineD3DVolumeTexture_Release(myVolume);
     }
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hrc;
 }
@@ -252,7 +270,8 @@
     TRACE("(%p) Relay %p %p %p %d\n", This, This->wineD3DVolumeTexture, pLockedVolume, pBox,Flags);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolumeTexture_LockBox(This->wineD3DVolumeTexture, Level, (WINED3DLOCKED_BOX *) pLockedVolume, (CONST WINED3DBOX *) pBox, Flags);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -263,7 +282,8 @@
     TRACE("(%p) Relay %p %d\n", This, This->wineD3DVolumeTexture, Level);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolumeTexture_UnlockBox(This->wineD3DVolumeTexture, Level);
-    LeaveCriticalSection(&d3d8_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -274,12 +294,12 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d8_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVolumeTexture_AddDirtyBox(This->wineD3DVolumeTexture, (CONST WINED3DBOX *) pDirtyBox);
-    LeaveCriticalSection(&d3d8_cs);
-    return hr;
-}
-
-
-const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl =
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static const IDirect3DVolumeTexture8Vtbl Direct3DVolumeTexture8_Vtbl =
 {
     /* IUnknown */
@@ -307,2 +327,37 @@
     IDirect3DVolumeTexture8Impl_AddDirtyBox
 };
+
+static void STDMETHODCALLTYPE volumetexture_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d8_volumetexture_wined3d_parent_ops =
+{
+    volumetexture_wined3d_object_destroyed,
+};
+
+HRESULT volumetexture_init(IDirect3DVolumeTexture8Impl *texture, IDirect3DDevice8Impl *device,
+        UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
+{
+    HRESULT hr;
+
+    texture->lpVtbl = &Direct3DVolumeTexture8_Vtbl;
+    texture->ref = 1;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateVolumeTexture(device->WineD3DDevice, width, height, depth, levels,
+            usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
+            &texture->wineD3DVolumeTexture, (IUnknown *)texture, &d3d8_volumetexture_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
+        return hr;
+    }
+
+    texture->parentDevice = (IDirect3DDevice8 *)device;
+    IDirect3DDevice8_AddRef(texture->parentDevice);
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/cubetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/cubetexture.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/cubetexture.c	(revision 23571)
@@ -59,4 +59,12 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        IDirect3DDevice9Ex_AddRef(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DCubeTexture_AddRef(This->wineD3DCubeTexture);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -71,10 +79,8 @@
         TRACE("Releasing child %p\n", This->wineD3DCubeTexture);
 
-        EnterCriticalSection(&d3d9_cs);
-        IWineD3DCubeTexture_Destroy(This->wineD3DCubeTexture, D3D9CB_DestroySurface);
         IDirect3DDevice9Ex_Release(This->parentDevice);
-        LeaveCriticalSection(&d3d9_cs);
-
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_lock();
+        IWineD3DCubeTexture_Release(This->wineD3DCubeTexture);
+        wined3d_mutex_unlock();
     }
     return ref;
@@ -88,5 +94,5 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_GetDevice(This->wineD3DCubeTexture, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -95,5 +101,6 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -104,7 +111,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_SetPrivateData(This->wineD3DCubeTexture,refguid,pData,SizeOfData,Flags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -115,7 +123,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_GetPrivateData(This->wineD3DCubeTexture,refguid,pData,pSizeOfData);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -126,7 +135,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_FreePrivateData(This->wineD3DCubeTexture,refguid);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -137,7 +147,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DCubeTexture_SetPriority(This->wineD3DCubeTexture, PriorityNew);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -148,7 +159,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DCubeTexture_GetPriority(This->wineD3DCubeTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -158,7 +170,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     IWineD3DCubeTexture_PreLoad(This->wineD3DCubeTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -168,7 +180,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DCubeTexture_GetType(This->wineD3DCubeTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -180,7 +193,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DCubeTexture_SetLOD(This->wineD3DCubeTexture, LODNew);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -191,7 +205,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DCubeTexture_GetLOD(This->wineD3DCubeTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -202,7 +217,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DCubeTexture_GetLevelCount(This->wineD3DCubeTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -213,7 +229,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_SetAutoGenFilterType(This->wineD3DCubeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -224,7 +241,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = (D3DTEXTUREFILTERTYPE) IWineD3DCubeTexture_GetAutoGenFilterType(This->wineD3DCubeTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -234,7 +252,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     IWineD3DCubeTexture_GenerateMipSubLevels(This->wineD3DCubeTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -247,7 +265,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr))
@@ -273,5 +291,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hrc = IWineD3DCubeTexture_GetCubeMapSurface(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, &mySurface);
     if (hrc == D3D_OK && NULL != ppCubeMapSurface) {
@@ -279,5 +297,6 @@
        IWineD3DCubeTexture_Release(mySurface);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hrc;
 }
@@ -288,7 +307,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_LockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -299,7 +319,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_UnlockRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, Level);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -310,7 +331,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DCubeTexture_AddDirtyRect(This->wineD3DCubeTexture, (WINED3DCUBEMAP_FACES) FaceType, pDirtyRect);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -346,46 +368,36 @@
 };
 
-
-
-
-/* IDirect3DDevice9 IDirect3DCubeTexture9 Methods follow: */
-HRESULT  WINAPI  IDirect3DDevice9Impl_CreateCubeTexture(LPDIRECT3DDEVICE9EX iface,
-                                                        UINT EdgeLength, UINT Levels, DWORD Usage,
-                                                        D3DFORMAT Format, D3DPOOL Pool,
-                                                        IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle) {
-
-    IDirect3DCubeTexture9Impl *object;
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    HRESULT hr = D3D_OK;
-
-    TRACE("(%p) : ELen(%d) Lvl(%d) Usage(%d) fmt(%u), Pool(%d)  Shared(%p)\n", This, EdgeLength, Levels, Usage, Format, Pool, pSharedHandle);
-
-    /* Allocate the storage for the device */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-
-    if (NULL == object) {
-        ERR("(%p) allocation of CubeTexture failed\n", This);
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-    object->lpVtbl = &Direct3DCubeTexture9_Vtbl;
-    object->ref = 1;
-    EnterCriticalSection(&d3d9_cs);
-    hr = IWineD3DDevice_CreateCubeTexture(This->WineD3DDevice, EdgeLength, Levels, Usage,
-            wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DCubeTexture, (IUnknown *)object);
-    LeaveCriticalSection(&d3d9_cs);
-
-    if (hr != D3D_OK){
-
-        /* free up object */
-        WARN("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
-        HeapFree(GetProcessHeap(), 0, object);
-    } else {
-        IDirect3DDevice9Ex_AddRef(iface);
-        object->parentDevice = iface;
-        *ppCubeTexture = (LPDIRECT3DCUBETEXTURE9) object;
-        TRACE("(%p) : Created cube texture %p\n", This, object);
-    }
-
-    TRACE("(%p) returning %p\n",This, *ppCubeTexture);
-    return hr;
-}
+static void STDMETHODCALLTYPE cubetexture_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d9_cubetexture_wined3d_parent_ops =
+{
+    cubetexture_wined3d_object_destroyed,
+};
+
+HRESULT cubetexture_init(IDirect3DCubeTexture9Impl *texture, IDirect3DDevice9Impl *device,
+        UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
+{
+    HRESULT hr;
+
+    texture->lpVtbl = &Direct3DCubeTexture9_Vtbl;
+    texture->ref = 1;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateCubeTexture(device->WineD3DDevice, edge_length, levels, usage,
+            wined3dformat_from_d3dformat(format), pool, &texture->wineD3DCubeTexture,
+            (IUnknown *)texture, &d3d9_cubetexture_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d cube texture, hr %#x.\n", hr);
+        return hr;
+    }
+
+    texture->parentDevice = (IDirect3DDevice9Ex *)device;
+    IDirect3DDevice9Ex_AddRef(texture->parentDevice);
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_main.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_main.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_main.c	(revision 23571)
@@ -35,13 +35,4 @@
 #include "d3d9_private.h"
 
-static CRITICAL_SECTION_DEBUG d3d9_cs_debug =
-{
-    0, 0, &d3d9_cs,
-    { &d3d9_cs_debug.ProcessLocksList,
-    &d3d9_cs_debug.ProcessLocksList },
-    0, 0, { (DWORD_PTR)(__FILE__ ": d3d9_cs") }
-};
-CRITICAL_SECTION d3d9_cs = { &d3d9_cs_debug, -1, 0, 0, 0, 0 };
-
 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
 
@@ -57,7 +48,8 @@
     object->lpVtbl = &Direct3D9_Vtbl;
     object->ref = 1;
-    EnterCriticalSection(&d3d9_cs);
+
+    wined3d_mutex_lock();
     object->WineD3D = WineDirect3DCreate(9, (IUnknown *)object);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     TRACE("SDKVersion = %x, Created Direct3D object @ %p, WineObj @ %p\n", SDKVersion, object, object->WineD3D);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h	(revision 23571)
@@ -4,5 +4,5 @@
  * Copyright 2002-2003 Jason Edmeades
  * Copyright 2002-2003 Raphael Junqueira
- * Copyright 2005 Oliver Stieber 
+ * Copyright 2005 Oliver Stieber
  *
  * This library is free software; you can redistribute it and/or
@@ -51,10 +51,7 @@
    Internal use
    =========================================================================== */
-extern HRESULT vdecl_convert_fvf(
-    DWORD FVF,
-    D3DVERTEXELEMENT9** ppVertexElements);
-extern CRITICAL_SECTION d3d9_cs;
-D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format);
-WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format);
+extern HRESULT vdecl_convert_fvf(DWORD FVF, D3DVERTEXELEMENT9 **ppVertexElements) DECLSPEC_HIDDEN;
+D3DFORMAT d3dformat_from_wined3dformat(WINED3DFORMAT format) DECLSPEC_HIDDEN;
+WINED3DFORMAT wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_HIDDEN;
 
 /* ===========================================================================
@@ -151,5 +148,5 @@
  * Predeclare the interface implementation structures
  */
-extern const IDirect3D9ExVtbl Direct3D9_Vtbl;
+extern const IDirect3D9ExVtbl Direct3D9_Vtbl DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -169,5 +166,5 @@
 } IDirect3D9Impl;
 
-void filter_caps(D3DCAPS9* pCaps);
+void filter_caps(D3DCAPS9* pCaps) DECLSPEC_HIDDEN;
 
 /* ---------------- */
@@ -178,6 +175,6 @@
  * Predeclare the interface implementation structures
  */
-extern const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl;
-extern const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl;
+extern const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl DECLSPEC_HIDDEN;
+extern const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -205,37 +202,52 @@
 
 /* IDirect3DDevice9: */
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9EX iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain);
-extern UINT     WINAPI  IDirect3DDevice9Impl_GetNumberOfSwapChains(LPDIRECT3DDEVICE9EX iface);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateTexture(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVolumeTexture(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateCubeTexture(LPDIRECT3DDEVICE9EX iface, UINT EdgeLength, UINT Levels, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DCubeTexture9** ppCubeTexture, HANDLE* pSharedHandle);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVertexBuffer(LPDIRECT3DDEVICE9EX iface, UINT Length, DWORD Usage, DWORD FVF, D3DPOOL Pool, IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateIndexBuffer(LPDIRECT3DDEVICE9EX iface, UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool, IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateStateBlock(LPDIRECT3DDEVICE9EX iface, D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9** ppSB);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_BeginStateBlock(LPDIRECT3DDEVICE9EX iface);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_EndStateBlock(LPDIRECT3DDEVICE9EX iface, IDirect3DStateBlock9** ppSB);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9EX iface, CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetVertexDeclaration(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexDeclaration9* pDecl);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetVertexDeclaration(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexDeclaration9** ppDecl);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9* pShader);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9** ppShader);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, CONST float* pConstantData, UINT Vector4fCount);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetVertexShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, float* pConstantData, UINT Vector4fCount);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, CONST int* pConstantData, UINT Vector4iCount);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetVertexShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, int* pConstantData, UINT Vector4iCount);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, CONST BOOL* pConstantData, UINT BoolCount);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetVertexShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, BOOL* pConstantData, UINT BoolCount);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreatePixelShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9* pShader);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9** ppShader);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetPixelShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, CONST float* pConstantData, UINT Vector4fCount);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetPixelShaderConstantF(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, float* pConstantData, UINT Vector4fCount);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetPixelShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, CONST int* pConstantData, UINT Vector4iCount);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetPixelShaderConstantI(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, int* pConstantData, UINT Vector4iCount);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_SetPixelShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, CONST BOOL* pConstantData, UINT BoolCount);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_GetPixelShaderConstantB(LPDIRECT3DDEVICE9EX iface, UINT StartRegister, BOOL* pConstantData, UINT BoolCount);
-extern HRESULT  WINAPI  IDirect3DDevice9Impl_CreateQuery(LPDIRECT3DDEVICE9EX iface, D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery);
+extern HRESULT WINAPI IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
+        D3DPRESENT_PARAMETERS *pPresentationParameters, IDirect3DSwapChain9 **pSwapChain) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_GetSwapChain(IDirect3DDevice9Ex *iface,
+        UINT iSwapChain, IDirect3DSwapChain9 **pSwapChain) DECLSPEC_HIDDEN;
+extern UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(IDirect3DDevice9Ex *iface) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(IDirect3DDevice9Ex *iface,
+        D3DSTATEBLOCKTYPE Type, IDirect3DStateBlock9 **ppSB) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface,
+        IDirect3DStateBlock9 **ppSB) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexDeclaration(IDirect3DDevice9Ex *iface,
+        IDirect3DVertexDeclaration9 *pDecl) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexDeclaration(IDirect3DDevice9Ex *iface,
+        IDirect3DVertexDeclaration9 **ppDecl) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(IDirect3DDevice9Ex *iface,
+        IDirect3DVertexShader9 *pShader) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShader(IDirect3DDevice9Ex *iface,
+        IDirect3DVertexShader9 **ppShader) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
+        UINT StartRegister, const float *pConstantData, UINT Vector4fCount) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
+        UINT StartRegister, float *pConstantData, UINT Vector4fCount) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
+        UINT StartRegister, const int *pConstantData, UINT Vector4iCount) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
+        UINT StartRegister, int *pConstantData, UINT Vector4iCount) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
+        UINT StartRegister, const BOOL *pConstantData, UINT BoolCount) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_GetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
+        UINT StartRegister, BOOL *pConstantData, UINT BoolCount) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(IDirect3DDevice9Ex *iface,
+        IDirect3DPixelShader9 *pShader) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(IDirect3DDevice9Ex *iface,
+        IDirect3DPixelShader9  **ppShader) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
+        UINT StartRegister, const float *pConstantData, UINT Vector4fCount) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
+        UINT StartRegister, float *pConstantData, UINT Vector4fCount) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
+        UINT StartRegister, const int *pConstantData, UINT Vector4iCount) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
+        UINT StartRegister, int *pConstantData, UINT Vector4iCount) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
+        UINT StartRegister, const BOOL *pConstantData, UINT BoolCount) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
+        UINT StartRegister, BOOL *pConstantData, UINT BoolCount) DECLSPEC_HIDDEN;
+extern HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(IDirect3DDevice9Ex *iface,
+        D3DQUERYTYPE Type, IDirect3DQuery9 **ppQuery) DECLSPEC_HIDDEN;
 
 
@@ -247,5 +259,4 @@
  * IDirect3DVolume9 implementation structure
  */
-extern const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl;
 typedef struct IDirect3DVolume9Impl
 {
@@ -264,4 +275,7 @@
 } IDirect3DVolume9Impl;
 
+HRESULT volume_init(IDirect3DVolume9Impl *volume, IDirect3DDevice9Impl *device, UINT width, UINT height,
+        UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool) DECLSPEC_HIDDEN;
+
 /* ------------------- */
 /* IDirect3DSwapChain9 */
@@ -292,9 +306,4 @@
 
 /*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl;
-
-/*****************************************************************************
  * IDirect3DSurface9 implementation structure
  */
@@ -317,7 +326,10 @@
     IUnknown                    *forwardReference;
 
-    /* Flags an implicit surface */
-    BOOL                        isImplicit;
+    BOOL                        getdc_supported;
 } IDirect3DSurface9Impl;
+
+HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *device,
+        UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
+        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) DECLSPEC_HIDDEN;
 
 /* ---------------------- */
@@ -343,4 +355,7 @@
 } IDirect3DVertexBuffer9Impl;
 
+HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
+        UINT size, UINT usage, DWORD fvf, D3DPOOL pool) DECLSPEC_HIDDEN;
+
 /* --------------------- */
 /* IDirect3DIndexBuffer9 */
@@ -364,4 +379,7 @@
 } IDirect3DIndexBuffer9Impl;
 
+HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
+        UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
+
 /* --------------------- */
 /* IDirect3DBaseTexture9 */
@@ -379,5 +397,4 @@
     /* IDirect3DResource9 fields */
     IWineD3DBaseTexture    *wineD3DBaseTexture;
-    
 } IDirect3DBaseTexture9Impl;
 
@@ -402,4 +419,6 @@
 }  IDirect3DCubeTexture9Impl;
 
+HRESULT cubetexture_init(IDirect3DCubeTexture9Impl *texture, IDirect3DDevice9Impl *device,
+        UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
 
 /* ----------------- */
@@ -423,4 +442,7 @@
 } IDirect3DTexture9Impl;
 
+HRESULT texture_init(IDirect3DTexture9Impl *texture, IDirect3DDevice9Impl *device,
+        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
+
 /* ----------------------- */
 /* IDirect3DVolumeTexture9 */
@@ -442,4 +464,7 @@
     LPDIRECT3DDEVICE9EX       parentDevice;
 } IDirect3DVolumeTexture9Impl;
+
+HRESULT volumetexture_init(IDirect3DVolumeTexture9Impl *texture, IDirect3DDevice9Impl *device,
+        UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
 
 /* ----------------------- */
@@ -486,5 +511,7 @@
 } IDirect3DVertexDeclaration9Impl;
 
-void IDirect3DVertexDeclaration9Impl_Destroy(LPDIRECT3DVERTEXDECLARATION9 iface);
+void IDirect3DVertexDeclaration9Impl_Destroy(LPDIRECT3DVERTEXDECLARATION9 iface) DECLSPEC_HIDDEN;
+HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration,
+        IDirect3DDevice9Impl *device, const D3DVERTEXELEMENT9 *elements) DECLSPEC_HIDDEN;
 
 /* ---------------------- */
@@ -507,5 +534,9 @@
 } IDirect3DVertexShader9Impl;
 
+HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader,
+        IDirect3DDevice9Impl *device, const DWORD *byte_code) DECLSPEC_HIDDEN;
+
 #define D3D9_MAX_VERTEX_SHADER_CONSTANTF 256
+#define D3D9_MAX_SIMULTANEOUS_RENDERTARGETS 4
 
 /* --------------------- */
@@ -528,4 +559,7 @@
 } IDirect3DPixelShader9Impl;
 
+HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader,
+        IDirect3DDevice9Impl *device, const DWORD *byte_code) DECLSPEC_HIDDEN;
+
 /* --------------- */
 /* IDirect3DQuery9 */
@@ -549,9 +583,5 @@
 
 /* Callbacks */
-extern ULONG WINAPI D3D9CB_DestroySwapChain (IWineD3DSwapChain *pSwapChain);
-extern ULONG WINAPI D3D9CB_DestroyDepthStencilSurface (IWineD3DSurface *pSurface);
-extern ULONG WINAPI D3D9CB_DestroyRenderTarget (IWineD3DSurface *pSurface);
-extern ULONG WINAPI D3D9CB_DestroySurface(IWineD3DSurface *pSurface);
-extern ULONG WINAPI D3D9CB_DestroyVolume(IWineD3DVolume *pVolume);
+extern ULONG WINAPI D3D9CB_DestroySwapChain (IWineD3DSwapChain *pSwapChain) DECLSPEC_HIDDEN;
 
 #endif /* __WINE_D3D9_PRIVATE_H */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 23571)
@@ -45,42 +45,42 @@
     {
         case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
-        case WINED3DFMT_R8G8B8: return D3DFMT_R8G8B8;
-        case WINED3DFMT_A8R8G8B8: return D3DFMT_A8R8G8B8;
-        case WINED3DFMT_X8R8G8B8: return D3DFMT_X8R8G8B8;
-        case WINED3DFMT_R5G6B5: return D3DFMT_R5G6B5;
-        case WINED3DFMT_X1R5G5B5: return D3DFMT_X1R5G5B5;
-        case WINED3DFMT_A1R5G5B5: return D3DFMT_A1R5G5B5;
-        case WINED3DFMT_A4R4G4B4: return D3DFMT_A4R4G4B4;
-        case WINED3DFMT_R3G3B2: return D3DFMT_R3G3B2;
+        case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
+        case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
+        case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
+        case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
+        case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
+        case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
+        case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
+        case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
         case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
-        case WINED3DFMT_A8R3G3B2: return D3DFMT_A8R3G3B2;
-        case WINED3DFMT_X4R4G4B4: return D3DFMT_X4R4G4B4;
+        case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
+        case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
         case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
         case WINED3DFMT_R8G8B8A8_UNORM: return D3DFMT_A8B8G8R8;
-        case WINED3DFMT_X8B8G8R8: return D3DFMT_X8B8G8R8;
+        case WINED3DFMT_R8G8B8X8_UNORM: return D3DFMT_X8B8G8R8;
         case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
-        case WINED3DFMT_A2R10G10B10: return D3DFMT_A2R10G10B10;
+        case WINED3DFMT_B10G10R10A2_UNORM: return D3DFMT_A2R10G10B10;
         case WINED3DFMT_R16G16B16A16_UNORM: return D3DFMT_A16B16G16R16;
-        case WINED3DFMT_A8P8: return D3DFMT_A8P8;
-        case WINED3DFMT_P8: return D3DFMT_P8;
-        case WINED3DFMT_L8: return D3DFMT_L8;
-        case WINED3DFMT_A8L8: return D3DFMT_A8L8;
-        case WINED3DFMT_A4L4: return D3DFMT_A4L4;
+        case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
+        case WINED3DFMT_P8_UINT: return D3DFMT_P8;
+        case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
+        case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
+        case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
         case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
-        case WINED3DFMT_L6V5U5: return D3DFMT_L6V5U5;
-        case WINED3DFMT_X8L8V8U8: return D3DFMT_X8L8V8U8;
+        case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
+        case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
         case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
         case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
-        case WINED3DFMT_A2W10V10U10: return D3DFMT_A2W10V10U10;
+        case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
         case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
-        case WINED3DFMT_D32: return D3DFMT_D32;
-        case WINED3DFMT_D15S1: return D3DFMT_D15S1;
-        case WINED3DFMT_D24S8: return D3DFMT_D24S8;
-        case WINED3DFMT_D24X8: return D3DFMT_D24X8;
-        case WINED3DFMT_D24X4S4: return D3DFMT_D24X4S4;
+        case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
+        case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
+        case WINED3DFMT_S8_UINT_D24_UNORM: return D3DFMT_D24S8;
+        case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
+        case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
         case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
-        case WINED3DFMT_L16: return D3DFMT_L16;
-        case WINED3DFMT_D32F_LOCKABLE: return D3DFMT_D32F_LOCKABLE;
-        case WINED3DFMT_D24FS8: return D3DFMT_D24FS8;
+        case WINED3DFMT_L16_UNORM: return D3DFMT_L16;
+        case WINED3DFMT_D32_FLOAT: return D3DFMT_D32F_LOCKABLE;
+        case WINED3DFMT_S8_UINT_D24_FLOAT: return D3DFMT_D24FS8;
         case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
         case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
@@ -93,5 +93,5 @@
         case WINED3DFMT_R32G32_FLOAT: return D3DFMT_G32R32F;
         case WINED3DFMT_R32G32B32A32_FLOAT: return D3DFMT_A32B32G32R32F;
-        case WINED3DFMT_CxV8U8: return D3DFMT_CxV8U8;
+        case WINED3DFMT_R8G8_SNORM_Cx: return D3DFMT_CxV8U8;
         default:
             FIXME("Unhandled WINED3DFORMAT %#x\n", format);
@@ -110,42 +110,42 @@
     {
         case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
-        case D3DFMT_R8G8B8: return WINED3DFMT_R8G8B8;
-        case D3DFMT_A8R8G8B8: return WINED3DFMT_A8R8G8B8;
-        case D3DFMT_X8R8G8B8: return WINED3DFMT_X8R8G8B8;
-        case D3DFMT_R5G6B5: return WINED3DFMT_R5G6B5;
-        case D3DFMT_X1R5G5B5: return WINED3DFMT_X1R5G5B5;
-        case D3DFMT_A1R5G5B5: return WINED3DFMT_A1R5G5B5;
-        case D3DFMT_A4R4G4B4: return WINED3DFMT_A4R4G4B4;
-        case D3DFMT_R3G3B2: return WINED3DFMT_R3G3B2;
+        case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
+        case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
+        case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
+        case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
+        case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
+        case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
+        case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
+        case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
         case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
-        case D3DFMT_A8R3G3B2: return WINED3DFMT_A8R3G3B2;
-        case D3DFMT_X4R4G4B4: return WINED3DFMT_X4R4G4B4;
+        case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
+        case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
         case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
         case D3DFMT_A8B8G8R8: return WINED3DFMT_R8G8B8A8_UNORM;
-        case D3DFMT_X8B8G8R8: return WINED3DFMT_X8B8G8R8;
+        case D3DFMT_X8B8G8R8: return WINED3DFMT_R8G8B8X8_UNORM;
         case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
-        case D3DFMT_A2R10G10B10: return WINED3DFMT_A2R10G10B10;
+        case D3DFMT_A2R10G10B10: return WINED3DFMT_B10G10R10A2_UNORM;
         case D3DFMT_A16B16G16R16: return WINED3DFMT_R16G16B16A16_UNORM;
-        case D3DFMT_A8P8: return WINED3DFMT_A8P8;
-        case D3DFMT_P8: return WINED3DFMT_P8;
-        case D3DFMT_L8: return WINED3DFMT_L8;
-        case D3DFMT_A8L8: return WINED3DFMT_A8L8;
-        case D3DFMT_A4L4: return WINED3DFMT_A4L4;
+        case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
+        case D3DFMT_P8: return WINED3DFMT_P8_UINT;
+        case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
+        case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
+        case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
         case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
-        case D3DFMT_L6V5U5: return WINED3DFMT_L6V5U5;
-        case D3DFMT_X8L8V8U8: return WINED3DFMT_X8L8V8U8;
+        case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
+        case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
         case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
         case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
-        case D3DFMT_A2W10V10U10: return WINED3DFMT_A2W10V10U10;
+        case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
         case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
-        case D3DFMT_D32: return WINED3DFMT_D32;
-        case D3DFMT_D15S1: return WINED3DFMT_D15S1;
-        case D3DFMT_D24S8: return WINED3DFMT_D24S8;
-        case D3DFMT_D24X8: return WINED3DFMT_D24X8;
-        case D3DFMT_D24X4S4: return WINED3DFMT_D24X4S4;
+        case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
+        case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
+        case D3DFMT_D24S8: return WINED3DFMT_S8_UINT_D24_UNORM;
+        case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
+        case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
         case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
-        case D3DFMT_L16: return WINED3DFMT_L16;
-        case D3DFMT_D32F_LOCKABLE: return WINED3DFMT_D32F_LOCKABLE;
-        case D3DFMT_D24FS8: return WINED3DFMT_D24FS8;
+        case D3DFMT_L16: return WINED3DFMT_L16_UNORM;
+        case D3DFMT_D32F_LOCKABLE: return WINED3DFMT_D32_FLOAT;
+        case D3DFMT_D24FS8: return WINED3DFMT_S8_UINT_D24_FLOAT;
         case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
         case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
@@ -158,5 +158,5 @@
         case D3DFMT_G32R32F: return WINED3DFMT_R32G32_FLOAT;
         case D3DFMT_A32B32G32R32F: return WINED3DFMT_R32G32B32A32_FLOAT;
-        case D3DFMT_CxV8U8: return WINED3DFMT_CxV8U8;
+        case D3DFMT_CxV8U8: return WINED3DFMT_R8G8_SNORM_Cx;
         default:
             FIXME("Unhandled D3DFORMAT %#x\n", format);
@@ -258,5 +258,5 @@
       This->inDestruction = TRUE;
 
-      EnterCriticalSection(&d3d9_cs);
+      wined3d_mutex_lock();
       for(i = 0; i < This->numConvertedDecls; i++) {
           /* Unless Wine is buggy or the app has a bug the refcount will be 0, because decls hold a reference to the
@@ -267,7 +267,8 @@
       HeapFree(GetProcessHeap(), 0, This->convertedDecls);
 
-      IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroyDepthStencilSurface, D3D9CB_DestroySwapChain);
+      IWineD3DDevice_Uninit3D(This->WineD3DDevice, D3D9CB_DestroySwapChain);
       IWineD3DDevice_Release(This->WineD3DDevice);
-      LeaveCriticalSection(&d3d9_cs);
+      wined3d_mutex_unlock();
+
       HeapFree(GetProcessHeap(), 0, This);
     }
@@ -281,7 +282,8 @@
     TRACE("(%p)\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_TestCooperativeLevel(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     if(hr == WINED3D_OK && This->notreset) {
         TRACE("D3D9 Device is marked not reset\n");
@@ -297,7 +299,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetAvailableTextureMem(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -308,7 +311,8 @@
     TRACE("(%p) : Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_EvictManagedResources(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -325,5 +329,5 @@
     }
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
     if (hr == D3D_OK && pWineD3D != NULL)
@@ -336,5 +340,6 @@
     }
     TRACE("(%p) returning %p\n", This, *ppD3D9);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -355,7 +360,9 @@
 
     memset(pCaps, 0, sizeof(*pCaps));
-    EnterCriticalSection(&d3d9_cs);
+
+    wined3d_mutex_lock();
     hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
     HeapFree(GetProcessHeap(), 0, pWineCaps);
@@ -375,7 +382,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetDisplayMode(This->WineD3DDevice, iSwapChain, (WINED3DDISPLAYMODE *) pMode);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -389,7 +396,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetCreationParameters(This->WineD3DDevice, (WINED3DDEVICE_CREATION_PARAMETERS *) pParameters);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -406,7 +414,8 @@
     }
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetCursorProperties(This->WineD3DDevice, XHotSpot, YHotSpot, pSurface->wineD3DSurface);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -416,7 +425,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     IWineD3DDevice_SetCursorPosition(This->WineD3DDevice, XScreenSpace, YScreenSpace, Flags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -426,7 +435,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DDevice_ShowCursor(This->WineD3DDevice, bShow);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -507,6 +517,6 @@
      * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
      */
-    EnterCriticalSection(&d3d9_cs);
-    IWineD3DDevice_SetIndices(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
+    wined3d_mutex_lock();
+    IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice, NULL, WINED3DFMT_UNKNOWN);
     for(i = 0; i < 16; i++) {
         IWineD3DDevice_SetStreamSource(This->WineD3DDevice, i, NULL, 0, 0);
@@ -520,5 +530,6 @@
         WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
         This->notreset = TRUE;
-        LeaveCriticalSection(&d3d9_cs);
+        wined3d_mutex_unlock();
+
         return WINED3DERR_INVALIDCALL;
     }
@@ -562,5 +573,5 @@
     }
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -573,7 +584,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_Present(This->WineD3DDevice, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
  }
@@ -586,5 +598,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     rc = IWineD3DDevice_GetBackBuffer(This->WineD3DDevice, iSwapChain, BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &retSurface);
     if (rc == D3D_OK && NULL != retSurface && NULL != ppBackBuffer) {
@@ -592,5 +604,6 @@
         IWineD3DSurface_Release(retSurface);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return rc;
 }
@@ -600,7 +613,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetRasterStatus(This->WineD3DDevice, iSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -611,19 +625,21 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetDialogBoxMode(This->WineD3DDevice, bEnableDialogs);
-    LeaveCriticalSection(&d3d9_cs);
-    return hr;
-}
-
-static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(LPDIRECT3DDEVICE9EX iface, UINT iSwapChain, DWORD Flags, CONST D3DGAMMARAMP* pRamp) {
-    
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex *iface, UINT iSwapChain,
+        DWORD Flags, const D3DGAMMARAMP *pRamp)
+{
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
     /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
+    wined3d_mutex_lock();
     IWineD3DDevice_SetGammaRamp(This->WineD3DDevice, iSwapChain, Flags, (CONST WINED3DGAMMARAMP *)pRamp);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -632,10 +648,169 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
     /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
+    wined3d_mutex_lock();
     IWineD3DDevice_GetGammaRamp(This->WineD3DDevice, iSwapChain, (WINED3DGAMMARAMP *) pRamp);
-    LeaveCriticalSection(&d3d9_cs);
-}
-
+    wined3d_mutex_unlock();
+}
+
+static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *iface,
+        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
+        D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DTexture9Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
+            iface, width, height, levels, usage, format, pool, texture, shared_handle);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate texture memory.\n");
+        return D3DERR_OUTOFVIDEOMEMORY;
+    }
+
+    hr = texture_init(object, This, width, height, levels, usage, format, pool);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize texture, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created texture %p.\n", object);
+    *texture = (IDirect3DTexture9 *)object;
+
+    return D3D_OK;
+}
+
+static HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
+        UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
+        D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DVolumeTexture9Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
+            iface, width, height, depth, levels);
+    TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
+            usage, format, pool, texture, shared_handle);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate volume texture memory.\n");
+        return D3DERR_OUTOFVIDEOMEMORY;
+    }
+
+    hr = volumetexture_init(object, This, width, height, depth, levels, usage, format, pool);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize volume texture, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created volume texture %p.\n", object);
+    *texture = (IDirect3DVolumeTexture9 *)object;
+
+    return D3D_OK;
+}
+
+static HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex *iface,
+        UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool,
+        IDirect3DCubeTexture9 **texture, HANDLE *shared_handle)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DCubeTexture9Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
+            iface, edge_length, levels, usage, format, pool, texture, shared_handle);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate cube texture memory.\n");
+        return D3DERR_OUTOFVIDEOMEMORY;
+    }
+
+    hr = cubetexture_init(object, This, edge_length, levels, usage, format, pool);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize cube texture, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created cube texture %p.\n", object);
+    *texture = (IDirect3DCubeTexture9 *)object;
+
+    return D3D_OK;
+}
+
+static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
+        DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer9 **buffer, HANDLE *shared_handle)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DVertexBuffer9Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
+            iface, size, usage, fvf, pool, buffer, shared_handle);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate buffer memory.\n");
+        return D3DERR_OUTOFVIDEOMEMORY;
+    }
+
+    hr = vertexbuffer_init(object, This, size, usage, fvf, pool);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created vertex buffer %p.\n", object);
+    *buffer = (IDirect3DVertexBuffer9 *)object;
+
+    return D3D_OK;
+}
+
+static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT size, DWORD usage,
+        D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer9 **buffer, HANDLE *shared_handle)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DIndexBuffer9Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
+            iface, size, usage, format, pool, buffer, shared_handle);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate buffer memory.\n");
+        return D3DERR_OUTOFVIDEOMEMORY;
+    }
+
+    hr = indexbuffer_init(object, This, size, usage, format, pool);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize index buffer, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created index buffer %p.\n", object);
+    *buffer = (IDirect3DIndexBuffer9 *)object;
+
+    return D3D_OK;
+}
 
 static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
@@ -643,58 +818,36 @@
         UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
 {
-    HRESULT hrc;
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     IDirect3DSurface9Impl *object;
-    IDirect3DDevice9Impl  *This = (IDirect3DDevice9Impl *)iface;
-    TRACE("(%p) Relay\n", This);
-    
-    if(MultisampleQuality > 0){
-        FIXME("MultisampleQuality set to %d, bstituting 0\n", MultisampleQuality);
-    /*
-    MultisampleQuality
- [in] Quality level. The valid range is between zero and one less than the level returned by pQualityLevels used by IDirect3D9::CheckDeviceMultiSampleType. Passing a larger value returns the error D3DERR_INVALIDCALL. The MultisampleQuality values of paired render targets, depth stencil surfaces, and the MultiSample type must all match.
- */
- 
-        MultisampleQuality=0;
-    }
-    /*FIXME: Check MAX bounds of MultisampleQuality*/
-
-    /* Allocate the storage for the device */
+    HRESULT hr;
+
+    TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
-    if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
+    if (!object)
+    {
+        FIXME("Failed to allocate surface memory.\n");
         return D3DERR_OUTOFVIDEOMEMORY;
     }
 
-    object->lpVtbl = &Direct3DSurface9_Vtbl;
-    object->ref = 1;
-
-    TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
-
-    EnterCriticalSection(&d3d9_cs);
-    hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
-            Lockable, Discard, Level, &object->wineD3DSurface, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL)Pool,
-            MultiSample, MultisampleQuality, SURFACE_OPENGL, (IUnknown *)object);
-    LeaveCriticalSection(&d3d9_cs);
-
-    if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
-
-       /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
+    hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
+            Level, Usage, Pool, MultiSample, MultisampleQuality);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize surface, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-    } else {
-        IDirect3DDevice9Ex_AddRef(iface);
-        object->parentDevice = iface;
-        TRACE("(%p) : Created surface %p\n", This, object);
-        *ppSurface = (LPDIRECT3DSURFACE9) object;
-    }
-    return hrc;
-}
-
-
-
-static HRESULT  WINAPI  IDirect3DDevice9Impl_CreateRenderTarget(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
-                                                         D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, 
-                                                         DWORD MultisampleQuality, BOOL Lockable, 
-                                                         IDirect3DSurface9 **ppSurface, HANDLE* pSharedHandle) {
+        return hr;
+    }
+
+    TRACE("Created surface %p.\n", object);
+    *ppSurface = (IDirect3DSurface9 *)object;
+
+    return D3D_OK;
+}
+
+static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width, UINT Height,
+        D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, BOOL Lockable,
+        IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
+{
     HRESULT hr;
     TRACE("Relay\n");
@@ -725,7 +878,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_UpdateSurface(This->WineD3DDevice, ((IDirect3DSurface9Impl *)pSourceSurface)->wineD3DSurface, pSourceRect, ((IDirect3DSurface9Impl *)pDestinationSurface)->wineD3DSurface, pDestPoint);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -736,7 +890,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_UpdateTexture(This->WineD3DDevice,  ((IDirect3DBaseTexture9Impl *)pSourceTexture)->wineD3DBaseTexture, ((IDirect3DBaseTexture9Impl *)pDestinationTexture)->wineD3DBaseTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -749,7 +904,8 @@
     TRACE("(%p)->(%p,%p)\n" , This, renderTarget, destSurface);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_BltFast(destSurface->wineD3DSurface, 0, 0, renderTarget->wineD3DSurface, NULL, WINEDDBLTFAST_NOCOLORKEY);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -761,7 +917,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetFrontBufferData(This->WineD3DDevice, iSwapChain, destSurface->wineD3DSurface);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -774,7 +931,9 @@
 
     TRACE("(%p)->(%p,%p,%p,%p,%d)\n" , This, src, pSourceRect, dst, pDestRect, Filter);
-    EnterCriticalSection(&d3d9_cs);
+
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_Blt(dst->wineD3DSurface, pDestRect, src->wineD3DSurface, pSourceRect, 0, NULL, Filter);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -790,5 +949,6 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
+
     IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
     usage = desc.usage;
@@ -800,5 +960,5 @@
      */
     if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != WINED3DPOOL_DEFAULT || restype != WINED3DRTYPE_SURFACE)) {
-        LeaveCriticalSection(&d3d9_cs);
+        wined3d_mutex_unlock();
         WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
         return D3DERR_INVALIDCALL;
@@ -808,5 +968,7 @@
     /* Note: D3DRECT is compatible with WINED3DRECT */
     hr = IWineD3DDevice_ColorFill(This->WineD3DDevice, surface->wineD3DSurface, (CONST WINED3DRECT*)pRect, color);
-    LeaveCriticalSection(&d3d9_cs);
+
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -818,5 +980,5 @@
         FIXME("Attempting to create a managed offscreen plain surface\n");
         return D3DERR_INVALIDCALL;
-    }    
+    }
         /*
         'Off-screen plain surfaces are always lockable, regardless of their pool types.'
@@ -824,5 +986,5 @@
         D3DPOOL_DEFAULT is the appropriate pool for use with the IDirect3DDevice9::StretchRect and IDirect3DDevice9::ColorFill.
         Why, their always lockable?
-        should I change the usage to dynamic?        
+        should I change the usage to dynamic?
         */
     hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
@@ -840,7 +1002,14 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
+    {
+        WARN("Invalid index %u specified.\n", RenderTargetIndex);
+        return D3DERR_INVALIDCALL;
+    }
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetRenderTarget(This->WineD3DDevice, RenderTargetIndex, pSurface ? pSurface->wineD3DSurface : NULL);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -857,5 +1026,12 @@
     }
 
-    EnterCriticalSection(&d3d9_cs);
+    if (RenderTargetIndex >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
+    {
+        WARN("Invalid index %u specified.\n", RenderTargetIndex);
+        return D3DERR_INVALIDCALL;
+    }
+
+    wined3d_mutex_lock();
+
     hr=IWineD3DDevice_GetRenderTarget(This->WineD3DDevice,RenderTargetIndex,&pRenderTarget);
 
@@ -874,5 +1050,5 @@
     }
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -886,6 +1062,7 @@
     TRACE("(%p) Relay\n" , This);
 
-
-    EnterCriticalSection(&d3d9_cs);
+    pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
+
+    wined3d_mutex_lock();
     hr = IDirect3DDevice9_GetDepthStencilSurface(iface, &pOldSurface);
     if (D3D_OK==hr) {
@@ -899,5 +1076,6 @@
         IDirect3DSurface9_AddRef(pZStencilSurface);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -913,5 +1091,5 @@
     }
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetDepthStencilSurface(This->WineD3DDevice,&pZStencilSurface);
     if (hr == WINED3D_OK) {
@@ -923,5 +1101,6 @@
         *ppZStencilSurface = NULL;
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -932,7 +1111,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_BeginScene(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -943,7 +1123,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_EndScene(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -955,7 +1136,8 @@
 
     /* Note: D3DRECT is compatible with WINED3DRECT */
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_Clear(This->WineD3DDevice, Count, (CONST WINED3DRECT*) pRects, Flags, Color, Z, Stencil);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -967,7 +1149,8 @@
 
     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) lpMatrix);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -979,8 +1162,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetTransform(This->WineD3DDevice, State, (WINED3DMATRIX*) pMatrix);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -993,7 +1176,8 @@
 
     /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_MultiplyTransform(This->WineD3DDevice, State, (CONST WINED3DMATRIX*) pMatrix);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1005,7 +1189,8 @@
 
     /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetViewport(This->WineD3DDevice, (const WINED3DVIEWPORT *)pViewport);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1017,7 +1202,8 @@
 
     /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetViewport(This->WineD3DDevice, (WINED3DVIEWPORT *)pViewport);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1029,7 +1215,8 @@
 
     /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetMaterial(This->WineD3DDevice, (const WINED3DMATERIAL *)pMaterial);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1041,7 +1228,8 @@
 
     /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetMaterial(This->WineD3DDevice, (WINED3DMATERIAL *)pMaterial);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1053,7 +1241,8 @@
 
     /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetLight(This->WineD3DDevice, Index, (const WINED3DLIGHT *)pLight);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1065,7 +1254,8 @@
 
     /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetLight(This->WineD3DDevice, Index, (WINED3DLIGHT *)pLight);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1076,7 +1266,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetLightEnable(This->WineD3DDevice, Index, Enable);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1087,7 +1278,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetLightEnable(This->WineD3DDevice, Index, pEnable);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1098,7 +1290,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetClipPlane(This->WineD3DDevice, Index, pPlane);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1109,7 +1302,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetClipPlane(This->WineD3DDevice, Index, pPlane);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1120,7 +1314,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetRenderState(This->WineD3DDevice, State, Value);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1131,7 +1326,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetRenderState(This->WineD3DDevice, State, pValue);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1142,7 +1338,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetClipStatus(This->WineD3DDevice, (const WINED3DCLIPSTATUS *)pClipStatus);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1153,7 +1350,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetClipStatus(This->WineD3DDevice, (WINED3DCLIPSTATUS *)pClipStatus);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1170,5 +1368,5 @@
     }
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
     if (SUCCEEDED(rc) && NULL != retTexture) {
@@ -1181,5 +1379,5 @@
         *ppTexture = NULL;
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return rc;
@@ -1191,8 +1389,9 @@
     TRACE("(%p) Relay %d %p\n" , This, Stage, pTexture);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetTexture(This->WineD3DDevice, Stage,
                                    pTexture==NULL ? NULL:((IDirect3DBaseTexture9Impl *)pTexture)->wineD3DBaseTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1240,7 +1439,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], pValue);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1251,18 +1451,22 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetTextureStageState(This->WineD3DDevice, Stage, tss_lookup[Type], Value);
-    LeaveCriticalSection(&d3d9_cs);
-    return hr;
-}
-
-static HRESULT  WINAPI  IDirect3DDevice9Impl_GetSamplerState(LPDIRECT3DDEVICE9EX iface, DWORD Sampler, D3DSAMPLERSTATETYPE Type, DWORD* pValue) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
-    HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
-
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3DDevice9Impl_GetSamplerState(IDirect3DDevice9Ex *iface, DWORD Sampler,
+        D3DSAMPLERSTATETYPE Type, DWORD *pValue)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    HRESULT hr;
+    TRACE("(%p) Relay\n" , This);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetSamplerState(This->WineD3DDevice, Sampler, Type, pValue);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1273,7 +1477,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetSamplerState(This->WineD3DDevice, Sampler, Type, Value);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1284,18 +1489,22 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_ValidateDevice(This->WineD3DDevice, pNumPasses);
-    LeaveCriticalSection(&d3d9_cs);
-    return hr;
-}
-
-static HRESULT  WINAPI  IDirect3DDevice9Impl_SetPaletteEntries(LPDIRECT3DDEVICE9EX iface, UINT PaletteNumber, CONST PALETTEENTRY* pEntries) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
-    HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
-
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface, UINT PaletteNumber,
+        const PALETTEENTRY *pEntries)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    HRESULT hr;
+    TRACE("(%p) Relay\n" , This);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1306,7 +1515,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetPaletteEntries(This->WineD3DDevice, PaletteNumber, pEntries);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1317,7 +1527,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1328,7 +1539,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetCurrentTexturePalette(This->WineD3DDevice, PaletteNumber);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1339,7 +1551,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetScissorRect(This->WineD3DDevice, pRect);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1350,7 +1563,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetScissorRect(This->WineD3DDevice, pRect);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1361,7 +1575,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetSoftwareVertexProcessing(This->WineD3DDevice, bSoftware);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1372,7 +1587,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DDevice_GetSoftwareVertexProcessing(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -1383,7 +1599,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetNPatchMode(This->WineD3DDevice, nSegments);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1394,20 +1611,24 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DDevice_GetNPatchMode(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
 
-static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
-    HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
-
-    EnterCriticalSection(&d3d9_cs);
+static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitive(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
+        UINT StartVertex, UINT PrimitiveCount)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    HRESULT hr;
+    TRACE("(%p) Relay\n" , This);
+
+    wined3d_mutex_lock();
     IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
     hr = IWineD3DDevice_DrawPrimitive(This->WineD3DDevice, StartVertex,
             vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount));
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1420,24 +1641,28 @@
 
     /* D3D8 passes the baseVertexIndex in SetIndices, and due to the stateblock functions wined3d has to work that way */
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     IWineD3DDevice_SetBaseVertexIndex(This->WineD3DDevice, BaseVertexIndex);
     IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
-    hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, MinVertexIndex, NumVertices,
-            startIndex, vertex_count_from_primitive_count(PrimitiveType, primCount));
-    LeaveCriticalSection(&d3d9_cs);
-    return hr;
-}
-
-static HRESULT  WINAPI  IDirect3DDevice9Impl_DrawPrimitiveUP(LPDIRECT3DDEVICE9EX iface, D3DPRIMITIVETYPE PrimitiveType, UINT PrimitiveCount, CONST void* pVertexStreamZeroData, UINT VertexStreamZeroStride) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
-    HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
-
-    EnterCriticalSection(&d3d9_cs);
+    hr = IWineD3DDevice_DrawIndexedPrimitive(This->WineD3DDevice, startIndex,
+            vertex_count_from_primitive_count(PrimitiveType, primCount));
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3DDevice9Impl_DrawPrimitiveUP(IDirect3DDevice9Ex *iface, D3DPRIMITIVETYPE PrimitiveType,
+        UINT PrimitiveCount, const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    HRESULT hr;
+    TRACE("(%p) Relay\n" , This);
+
+    wined3d_mutex_lock();
     IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
     hr = IWineD3DDevice_DrawPrimitiveUP(This->WineD3DDevice,
             vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount),
             pVertexStreamZeroData, VertexStreamZeroStride);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1450,10 +1675,11 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     IWineD3DDevice_SetPrimitiveType(This->WineD3DDevice, PrimitiveType);
-    hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice, MinVertexIndex, NumVertexIndices,
+    hr = IWineD3DDevice_DrawIndexedPrimitiveUP(This->WineD3DDevice,
             vertex_count_from_primitive_count(PrimitiveType, PrimitiveCount), pIndexData,
             wined3dformat_from_d3dformat(IndexDataFormat), pVertexStreamZeroData, VertexStreamZeroStride);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1466,8 +1692,45 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_ProcessVertices(This->WineD3DDevice,SrcStartIndex, DestIndex, VertexCount, dest->wineD3DVertexBuffer, Decl ? Decl->wineD3DVertexDeclaration : NULL, Flags, dest->fvf);
-    LeaveCriticalSection(&d3d9_cs);
-    return hr;
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexDeclaration(IDirect3DDevice9Ex *iface,
+        const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DVertexDeclaration9Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration);
+
+    if (!declaration)
+    {
+        WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
+        return D3DERR_INVALIDCALL;
+    }
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate vertex declaration memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = vertexdeclaration_init(object, This, elements);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created vertex declaration %p.\n", object);
+    *declaration = (IDirect3DVertexDeclaration9 *)object;
+
+    return D3D_OK;
 }
 
@@ -1542,7 +1805,7 @@
     }
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     decl = getConvertedDecl(This, FVF);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (!decl)
@@ -1588,4 +1851,34 @@
 }
 
+static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex *iface,
+        const DWORD *byte_code, IDirect3DVertexShader9 **shader)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DVertexShader9Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate vertex shader memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = vertexshader_init(object, This, byte_code);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created vertex shader %p.\n", object);
+    *shader = (IDirect3DVertexShader9 *)object;
+
+    return D3D_OK;
+}
+
 static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, IDirect3DVertexBuffer9* pStreamData, UINT OffsetInBytes, UINT Stride) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
@@ -1593,9 +1886,10 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetStreamSource(This->WineD3DDevice, StreamNumber,
-                                          pStreamData==NULL ? NULL:((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer, 
-                                          OffsetInBytes, Stride);
-    LeaveCriticalSection(&d3d9_cs);
+            pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
+            OffsetInBytes, Stride);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1612,5 +1906,5 @@
     }
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     rc = IWineD3DDevice_GetStreamSource(This->WineD3DDevice, StreamNumber, &retStream, OffsetInBytes, pStride);
     if (rc == D3D_OK  && NULL != retStream) {
@@ -1623,17 +1917,20 @@
         *pStream = NULL;
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return rc;
 }
 
-static HRESULT  WINAPI  IDirect3DDevice9Impl_SetStreamSourceFreq(LPDIRECT3DDEVICE9EX iface, UINT StreamNumber, UINT Divider) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
-    HRESULT hr;
-    TRACE("(%p) Relay\n" , This);
-
-    EnterCriticalSection(&d3d9_cs);
+static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT StreamNumber,
+        UINT Divider)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    HRESULT hr;
+    TRACE("(%p) Relay\n" , This);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1644,7 +1941,8 @@
     TRACE("(%p) Relay\n" , This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetStreamSourceFreq(This->WineD3DDevice, StreamNumber, Divider);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1656,9 +1954,10 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
-    hr = IWineD3DDevice_SetIndices(This->WineD3DDevice,
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_SetIndexBuffer(This->WineD3DDevice,
             ib ? ib->wineD3DIndexBuffer : NULL,
             ib ? ib->format : WINED3DFMT_UNKNOWN);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1675,6 +1974,6 @@
     }
 
-    EnterCriticalSection(&d3d9_cs);
-    rc = IWineD3DDevice_GetIndices(This->WineD3DDevice, &retIndexData);
+    wined3d_mutex_lock();
+    rc = IWineD3DDevice_GetIndexBuffer(This->WineD3DDevice, &retIndexData);
     if (SUCCEEDED(rc) && retIndexData) {
         IWineD3DBuffer_GetParent(retIndexData, (IUnknown **)ppIndexData);
@@ -1684,8 +1983,39 @@
         *ppIndexData = NULL;
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return rc;
 }
 
+static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex *iface,
+        const DWORD *byte_code, IDirect3DPixelShader9 **shader)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DPixelShader9Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        FIXME("Failed to allocate pixel shader memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = pixelshader_init(object, This, byte_code);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created pixel shader %p.\n", object);
+    *shader = (IDirect3DPixelShader9 *)object;
+
+    return D3D_OK;
+}
+
 static HRESULT  WINAPI  IDirect3DDevice9Impl_DrawRectPatch(LPDIRECT3DDEVICE9EX iface, UINT Handle, CONST float* pNumSegs, CONST D3DRECTPATCH_INFO* pRectPatchInfo) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
@@ -1693,7 +2023,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_DrawRectPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DRECTPATCH_INFO *)pRectPatchInfo);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1704,7 +2035,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_DrawTriPatch(This->WineD3DDevice, Handle, pNumSegs, (CONST WINED3DTRIPATCH_INFO *)pTriPatchInfo);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1715,7 +2047,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_DeletePatch(This->WineD3DDevice, Handle);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -1953,15 +2286,4 @@
 };
 
-ULONG WINAPI D3D9CB_DestroySurface(IWineD3DSurface *pSurface) {
-    IDirect3DSurface9Impl* surfaceParent;
-    TRACE("(%p) call back\n", pSurface);
-
-    IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
-    /* GetParent's AddRef was forwarded to an object in destruction.
-     * Releasing it here again would cause an endless recursion. */
-    surfaceParent->forwardReference = NULL;
-    return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
-}
-
 /* IWineD3DDeviceParent IUnknown methods */
 
@@ -2023,7 +2345,11 @@
 
     *surface = d3d_surface->wineD3DSurface;
+    IWineD3DSurface_AddRef(*surface);
+
     d3d_surface->container = superior;
     IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
     d3d_surface->parentDevice = NULL;
+
+    IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
     d3d_surface->forwardReference = superior;
 
@@ -2053,6 +2379,7 @@
 
     *surface = d3d_surface->wineD3DSurface;
+    IWineD3DSurface_AddRef(*surface);
+
     d3d_surface->container = superior;
-    d3d_surface->isImplicit = TRUE;
     /* Implicit surfaces are created with an refcount of 0 */
     IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
@@ -2083,6 +2410,6 @@
 
     *surface = d3d_surface->wineD3DSurface;
+    IWineD3DSurface_AddRef(*surface);
     d3d_surface->container = (IUnknown *)This;
-    d3d_surface->isImplicit = TRUE;
     /* Implicit surfaces are created with an refcount of 0 */
     IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
@@ -2111,21 +2438,20 @@
     }
 
-    object->lpVtbl = &Direct3DVolume9_Vtbl;
-    object->ref = 1;
-    hr = IWineD3DDevice_CreateVolume(This->WineD3DDevice, width, height, depth, usage & WINED3DUSAGE_MASK,
-            format, pool, &object->wineD3DVolume, (IUnknown *)object);
+    hr = volume_init(object, This, width, height, depth, usage, format, pool);
     if (FAILED(hr))
     {
-        ERR("(%p) CreateVolume failed, returning %#x\n", iface, hr);
+        WARN("Failed to initialize volume, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *volume = NULL;
         return hr;
     }
 
     *volume = object->wineD3DVolume;
+    IWineD3DVolume_AddRef(*volume);
+    IDirect3DVolume9_Release((IDirect3DVolume9 *)object);
+
     object->container = superior;
     object->forwardReference = superior;
 
-    TRACE("(%p) Created volume %p\n", iface, *volume);
+    TRACE("(%p) Created volume %p\n", iface, object);
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c	(revision 23571)
@@ -79,7 +79,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d9_cs);
+        wined3d_mutex_lock();
         IWineD3D_Release(This->WineD3D);
-        LeaveCriticalSection(&d3d9_cs);
+        wined3d_mutex_unlock();
+
         HeapFree(GetProcessHeap(), 0, This);
     }
@@ -94,7 +95,8 @@
     TRACE("(%p)->(%p)\n", This, pInitializeFunction);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -105,7 +107,8 @@
     TRACE("%p\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_GetAdapterCount(This->WineD3D);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -123,7 +126,7 @@
     adapter_id.device_name_size = sizeof(pIdentifier->DeviceName);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     pIdentifier->DriverVersion = adapter_id.driver_version;
@@ -148,7 +151,8 @@
     }
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format));
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -163,8 +167,8 @@
         return D3DERR_INVALIDCALL;
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format),
             Mode, (WINED3DDISPLAYMODE *) pMode);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -177,7 +181,7 @@
     HRESULT hr;
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -186,7 +190,7 @@
 }
 
-static HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(LPDIRECT3D9EX iface,
-					      UINT Adapter, D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat,
-					      D3DFORMAT BackBufferFormat, BOOL Windowed) {
+static HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(IDirect3D9Ex *iface, UINT Adapter,
+        D3DDEVTYPE CheckType, D3DFORMAT DisplayFormat, D3DFORMAT BackBufferFormat, BOOL Windowed)
+{
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HRESULT hr;
@@ -194,14 +198,15 @@
           BackBufferFormat, Windowed ? "true" : "false");
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
             wined3dformat_from_d3dformat(BackBufferFormat), Windowed);
-    LeaveCriticalSection(&d3d9_cs);
-    return hr;
-}
-
-static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(LPDIRECT3D9EX iface,
-						  UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
-						  DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat) {
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(IDirect3D9Ex *iface, UINT Adapter, D3DDEVTYPE DeviceType,
+        D3DFORMAT AdapterFormat, DWORD Usage, D3DRESOURCETYPE RType, D3DFORMAT CheckFormat)
+{
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HRESULT hr;
@@ -232,37 +237,41 @@
     }
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
             Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
-    LeaveCriticalSection(&d3d9_cs);
-    return hr;
-}
-
-static HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType(LPDIRECT3D9EX iface,
-							   UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat,
-							   BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType, DWORD* pQualityLevels) {
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType(IDirect3D9Ex *iface, UINT Adapter,
+        D3DDEVTYPE DeviceType, D3DFORMAT SurfaceFormat, BOOL Windowed, D3DMULTISAMPLE_TYPE MultiSampleType,
+        DWORD *pQualityLevels)
+{
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HRESULT hr;
     TRACE("%p\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType,
             wined3dformat_from_d3dformat(SurfaceFormat), Windowed, MultiSampleType, pQualityLevels);
-    LeaveCriticalSection(&d3d9_cs);
-    return hr;
-}
-
-static HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch(LPDIRECT3D9EX iface,
-						       UINT Adapter, D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat,
-						       D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat) {
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch(IDirect3D9Ex *iface, UINT Adapter,
+        D3DDEVTYPE DeviceType, D3DFORMAT AdapterFormat, D3DFORMAT RenderTargetFormat, D3DFORMAT DepthStencilFormat)
+{
     IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
     HRESULT hr;
     TRACE("%p\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType,
             wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
             wined3dformat_from_d3dformat(DepthStencilFormat));
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -273,8 +282,9 @@
     TRACE("%p\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_CheckDeviceFormatConversion(This->WineD3D, Adapter, DeviceType,
             wined3dformat_from_d3dformat(SourceFormat), wined3dformat_from_d3dformat(TargetFormat));
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -337,4 +347,5 @@
 
     pCaps->MaxVertexShaderConst = min(D3D9_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
+    pCaps->NumSimultaneousRTs = min(D3D9_MAX_SIMULTANEOUS_RENDERTARGETS, pCaps->NumSimultaneousRTs);
 }
 
@@ -354,7 +365,9 @@
     }
     memset(pCaps, 0, sizeof(*pCaps));
-    EnterCriticalSection(&d3d9_cs);
+
+    wined3d_mutex_lock();
     hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
     HeapFree(GetProcessHeap(), 0, pWineCaps);
@@ -374,18 +387,9 @@
     TRACE("%p\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
-}
-
-ULONG WINAPI D3D9CB_DestroyRenderTarget(IWineD3DSurface *pSurface) {
-    IDirect3DSurface9Impl* surfaceParent;
-    TRACE("(%p) call back\n", pSurface);
-
-    IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
-    surfaceParent->isImplicit = FALSE;
-    /* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
-    return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
 }
 
@@ -398,14 +402,4 @@
     /* Swap chain had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
     return IDirect3DSwapChain9_Release((IDirect3DSwapChain9*) swapChainParent);
-}
-
-ULONG WINAPI D3D9CB_DestroyDepthStencilSurface(IWineD3DSurface *pSurface) {
-    IDirect3DSurface9Impl* surfaceParent;
-    TRACE("(%p) call back\n", pSurface);
-
-    IWineD3DSurface_GetParent(pSurface, (IUnknown **) &surfaceParent);
-    surfaceParent->isImplicit = FALSE;
-    /* Surface had refcount of 0 GetParent addrefed to 1, so 1 Release is enough */
-    return IDirect3DSurface9_Release((IDirect3DSurface9*) surfaceParent);
 }
 
@@ -442,5 +436,5 @@
 
     /* Allocate an associated WineD3DDevice object */
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags,
             (IUnknown *)object, (IWineD3DDeviceParent *)&object->device_parent_vtbl, &object->WineD3DDevice);
@@ -448,5 +442,6 @@
         HeapFree(GetProcessHeap(), 0, object);
         *ppReturnedDeviceInterface = NULL;
-        LeaveCriticalSection(&d3d9_cs);
+        wined3d_mutex_unlock();
+
         return hr;
     }
@@ -516,5 +511,5 @@
      */
     object->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/indexbuffer.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/indexbuffer.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/indexbuffer.c	(revision 23571)
@@ -57,4 +57,12 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        IDirect3DDevice9Ex_AddRef(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DBuffer_AddRef(This->wineD3DIndexBuffer);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -67,9 +75,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d9_cs);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
+        wined3d_mutex_lock();
         IWineD3DBuffer_Release(This->wineD3DIndexBuffer);
-        LeaveCriticalSection(&d3d9_cs);
-        IDirect3DDevice9Ex_Release(This->parentDevice);
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_unlock();
     }
     return ref;
@@ -83,5 +90,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetDevice(This->wineD3DIndexBuffer, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -90,5 +97,6 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -99,7 +107,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_SetPrivateData(This->wineD3DIndexBuffer, refguid, pData, SizeOfData, Flags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -110,7 +119,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetPrivateData(This->wineD3DIndexBuffer, refguid, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -121,7 +131,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_FreePrivateData(This->wineD3DIndexBuffer, refguid);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -132,7 +143,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DBuffer_SetPriority(This->wineD3DIndexBuffer, PriorityNew);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -143,7 +155,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DBuffer_GetPriority(This->wineD3DIndexBuffer);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -153,7 +166,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     IWineD3DBuffer_PreLoad(This->wineD3DIndexBuffer);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -171,7 +184,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_Map(This->wineD3DIndexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -182,7 +196,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_Unmap(This->wineD3DIndexBuffer);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -194,7 +209,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetDesc(This->wineD3DIndexBuffer, &desc);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) {
@@ -231,41 +246,37 @@
 };
 
-
-/* IDirect3DDevice9 IDirect3DIndexBuffer9 Methods follow: */
-HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(LPDIRECT3DDEVICE9EX iface,
-                              UINT Length, DWORD Usage, D3DFORMAT Format, D3DPOOL Pool,
-                              IDirect3DIndexBuffer9** ppIndexBuffer, HANDLE* pSharedHandle) {
-    
-    IDirect3DIndexBuffer9Impl *object;
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    HRESULT hrc = D3D_OK;
-    
-    TRACE("(%p) Relay\n", This);
-    /* Allocate the storage for the device */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    if (NULL == object) {
-        FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
-    object->ref = 1;
-    object->format = wined3dformat_from_d3dformat(Format);
-    TRACE("Calling wined3d create index buffer\n");
-    EnterCriticalSection(&d3d9_cs);
-    hrc = IWineD3DDevice_CreateIndexBuffer(This->WineD3DDevice, Length, Usage & WINED3DUSAGE_MASK,
-            (WINED3DPOOL)Pool, &object->wineD3DIndexBuffer, (IUnknown *)object);
-    LeaveCriticalSection(&d3d9_cs);
-    if (hrc != D3D_OK) {
-
-        /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
-        HeapFree(GetProcessHeap(), 0, object);
-    } else {
-        IDirect3DDevice9Ex_AddRef(iface);
-        object->parentDevice = iface;
-        *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER9) object;
-        TRACE("(%p) : Created index buffer %p\n", This, object);
-    }
-    return hrc;
-}
+static void STDMETHODCALLTYPE d3d9_indexbuffer_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d9_indexbuffer_wined3d_parent_ops =
+{
+    d3d9_indexbuffer_wined3d_object_destroyed,
+};
+
+HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
+        UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool)
+{
+    HRESULT hr;
+
+    buffer->lpVtbl = &Direct3DIndexBuffer9_Vtbl;
+    buffer->ref = 1;
+    buffer->format = wined3dformat_from_d3dformat(format);
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateIndexBuffer(device->WineD3DDevice, size,
+            usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, &buffer->wineD3DIndexBuffer,
+            (IUnknown *)buffer, &d3d9_indexbuffer_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
+        return hr;
+    }
+
+    buffer->parentDevice = (IDirect3DDevice9Ex *)device;
+    IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/pixelshader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/pixelshader.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/pixelshader.c	(revision 23571)
@@ -56,4 +56,12 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        IDirect3DDevice9Ex_AddRef(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DPixelShader_AddRef(This->wineD3DPixelShader);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -66,9 +74,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d9_cs);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
+        wined3d_mutex_lock();
         IWineD3DPixelShader_Release(This->wineD3DPixelShader);
-        LeaveCriticalSection(&d3d9_cs);
-        IDirect3DDevice9Ex_Release(This->parentDevice);
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_unlock();
     }
     return ref;
@@ -82,9 +89,10 @@
     TRACE("(%p) : Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     IWineD3DPixelShader_GetDevice(This->wineD3DPixelShader, &myDevice);
     IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
     IWineD3DDevice_Release(myDevice);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     TRACE("(%p) returning (%p)\n", This, *ppDevice);
     return D3D_OK;
@@ -96,7 +104,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DPixelShader_GetFunction(This->wineD3DPixelShader, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -114,13 +123,56 @@
 };
 
-
-/* IDirect3DDevice9 IDirect3DPixelShader9 Methods follow:  */
-HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DPixelShader9** ppShader) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    IDirect3DPixelShader9Impl *object;
+static void STDMETHODCALLTYPE d3d9_pixelshader_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d9_pixelshader_wined3d_parent_ops =
+{
+    d3d9_pixelshader_wined3d_object_destroyed,
+};
+
+HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
+{
+    HRESULT hr;
+
+    shader->ref = 1;
+    shader->lpVtbl = &Direct3DPixelShader9_Vtbl;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreatePixelShader(device->WineD3DDevice, byte_code,
+            NULL, &shader->wineD3DPixelShader, (IUnknown *)shader,
+            &d3d9_pixelshader_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to created wined3d pixel shader, hr %#x.\n", hr);
+        return hr;
+    }
+
+    shader->parentDevice = (IDirect3DDevice9Ex *)device;
+    IDirect3DDevice9Ex_AddRef(shader->parentDevice);
+
+    return D3D_OK;
+}
+
+HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9* pShader) {
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DPixelShader9Impl *shader = (IDirect3DPixelShader9Impl *)pShader;
+    TRACE("(%p) Relay\n", This);
+
+    wined3d_mutex_lock();
+    IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader == NULL ? NULL :shader->wineD3DPixelShader);
+    wined3d_mutex_unlock();
+
+    return D3D_OK;
+}
+
+HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9** ppShader) {
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IWineD3DPixelShader *object;
+
     HRESULT hrc = D3D_OK;
-
-    TRACE("(%p) Relay\n", This);
-
+    TRACE("(%p) Relay\n", This);
     if (ppShader == NULL) {
         TRACE("(%p) Invalid call\n", This);
@@ -128,56 +180,5 @@
     }
 
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-
-    if (NULL == object) {
-        FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
-        return E_OUTOFMEMORY;
-    }
-
-    object->ref    = 1;
-    object->lpVtbl = &Direct3DPixelShader9_Vtbl;
-    EnterCriticalSection(&d3d9_cs);
-    hrc = IWineD3DDevice_CreatePixelShader(This->WineD3DDevice, pFunction, NULL,
-            &object->wineD3DPixelShader, (IUnknown *)object);
-    LeaveCriticalSection(&d3d9_cs);
-    if (hrc != D3D_OK) {
-
-        /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
-        HeapFree(GetProcessHeap(), 0 , object);
-    } else {
-        IDirect3DDevice9Ex_AddRef(iface);
-        object->parentDevice = iface;
-        *ppShader = (IDirect3DPixelShader9*) object;
-        TRACE("(%p) : Created pixel shader %p\n", This, object);
-    }
-
-    TRACE("(%p) : returning %p\n", This, *ppShader);
-    return hrc;
-}
-
-HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9* pShader) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    IDirect3DPixelShader9Impl *shader = (IDirect3DPixelShader9Impl *)pShader;
-    TRACE("(%p) Relay\n", This);
-
-    EnterCriticalSection(&d3d9_cs);
-    IWineD3DDevice_SetPixelShader(This->WineD3DDevice, shader == NULL ? NULL :shader->wineD3DPixelShader);
-    LeaveCriticalSection(&d3d9_cs);
-    return D3D_OK;
-}
-
-HRESULT WINAPI IDirect3DDevice9Impl_GetPixelShader(LPDIRECT3DDEVICE9EX iface, IDirect3DPixelShader9** ppShader) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    IWineD3DPixelShader *object;
-
-    HRESULT hrc = D3D_OK;
-    TRACE("(%p) Relay\n", This);
-    if (ppShader == NULL) {
-        TRACE("(%p) Invalid call\n", This);
-        return D3DERR_INVALIDCALL;
-    }
-
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hrc = IWineD3DDevice_GetPixelShader(This->WineD3DDevice, &object);
     if (SUCCEEDED(hrc))
@@ -197,5 +198,5 @@
         WARN("(%p) : Call to IWineD3DDevice_GetPixelShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     TRACE("(%p) : returning %p\n", This, *ppShader);
@@ -206,9 +207,10 @@
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This);   
-
-    EnterCriticalSection(&d3d9_cs);
+    TRACE("(%p) Relay\n", This);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -220,7 +222,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetPixelShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -232,7 +234,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetPixelShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -243,7 +246,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetPixelShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -254,7 +258,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetPixelShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -265,7 +270,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetPixelShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
-    LeaveCriticalSection(&d3d9_cs);
-    return hr;
-}
+    wined3d_mutex_unlock();
+
+    return hr;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/query.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/query.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/query.c	(revision 23571)
@@ -67,7 +67,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d9_cs);
+        wined3d_mutex_lock();
         IWineD3DQuery_Release(This->wineD3DQuery);
-        LeaveCriticalSection(&d3d9_cs);
+        wined3d_mutex_unlock();
+
         IDirect3DDevice9Ex_Release(This->parentDevice);
         HeapFree(GetProcessHeap(), 0, This);
@@ -84,5 +85,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DQuery_GetDevice(This->wineD3DQuery, &pDevice);
     if(hr != D3D_OK){
@@ -92,5 +93,6 @@
         IWineD3DDevice_Release(pDevice);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -101,7 +103,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DQuery_GetType(This->wineD3DQuery);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -112,7 +115,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DQuery_GetDataSize(This->wineD3DQuery);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -123,7 +127,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DQuery_Issue(This->wineD3DQuery, dwIssueFlags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -134,7 +139,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DQuery_GetData(This->wineD3DQuery, pData, dwSize, dwGetDataFlags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -164,7 +170,8 @@
     if (!ppQuery)
     {
-        EnterCriticalSection(&d3d9_cs);
+        wined3d_mutex_lock();
         hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, NULL, NULL);
-        LeaveCriticalSection(&d3d9_cs);
+        wined3d_mutex_unlock();
+
         return hr;
     }
@@ -179,7 +186,8 @@
     object->lpVtbl = &Direct3DQuery9_Vtbl;
     object->ref = 1;
-    EnterCriticalSection(&d3d9_cs);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, &object->wineD3DQuery, (IUnknown *)object);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (FAILED(hr)) {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/stateblock.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/stateblock.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/stateblock.c	(revision 23571)
@@ -67,7 +67,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d9_cs);
+        wined3d_mutex_lock();
         IWineD3DStateBlock_Release(This->wineD3DStateBlock);
-        LeaveCriticalSection(&d3d9_cs);
+        wined3d_mutex_unlock();
+
         IDirect3DDevice9Ex_Release(This->parentDevice);
         HeapFree(GetProcessHeap(), 0, This);
@@ -83,5 +84,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DStateBlock_GetDevice(This->wineD3DStateBlock, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -90,5 +91,6 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -97,9 +99,10 @@
     IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface;
     HRESULT hr;
-    TRACE("(%p) Relay\n", This); 
-
-    EnterCriticalSection(&d3d9_cs);
+    TRACE("(%p) Relay\n", This);
+
+    wined3d_mutex_lock();
     hr = IWineD3DStateBlock_Capture(This->wineD3DStateBlock);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -110,7 +113,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DStateBlock_Apply(This->wineD3DStateBlock);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -135,5 +139,5 @@
    IDirect3DStateBlock9Impl* object;
    HRESULT hrc = D3D_OK;
-   
+
    TRACE("(%p) Relay\n", This);
 
@@ -143,13 +147,14 @@
        return D3DERR_INVALIDCALL;
    }
-   
+
    object  = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl));
    if (NULL == object) return E_OUTOFMEMORY;
    object->lpVtbl = &Direct3DStateBlock9_Vtbl;
    object->ref = 1;
-   
-   EnterCriticalSection(&d3d9_cs);
+
+   wined3d_mutex_lock();
    hrc = IWineD3DDevice_CreateStateBlock(This->WineD3DDevice, (WINED3DSTATEBLOCKTYPE)Type, &object->wineD3DStateBlock, (IUnknown*)object);
-   LeaveCriticalSection(&d3d9_cs);
+   wined3d_mutex_unlock();
+
    if(hrc != D3D_OK){
        FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This);
@@ -165,35 +170,39 @@
 }
 
-HRESULT  WINAPI  IDirect3DDevice9Impl_BeginStateBlock(LPDIRECT3DDEVICE9EX iface) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;    
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    EnterCriticalSection(&d3d9_cs);
+HRESULT WINAPI IDirect3DDevice9Impl_BeginStateBlock(IDirect3DDevice9Ex *iface)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    HRESULT hr;
+    TRACE("(%p) Relay\n", This);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_BeginStateBlock(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d9_cs);
-    return hr;
-}
-
-HRESULT  WINAPI  IDirect3DDevice9Impl_EndStateBlock(LPDIRECT3DDEVICE9EX iface, IDirect3DStateBlock9** ppSB) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;   
-    HRESULT hr;
-    IWineD3DStateBlock* wineD3DStateBlock;    
-    IDirect3DStateBlock9Impl* object;
-
-    TRACE("(%p) Relay\n", This); 
-    
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+HRESULT WINAPI IDirect3DDevice9Impl_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **ppSB)
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IWineD3DStateBlock *wineD3DStateBlock;
+    IDirect3DStateBlock9Impl *object;
+    HRESULT hr;
+
+    TRACE("(%p) Relay\n", This);
+
     /* Tell wineD3D to endstateblock before anything else (in case we run out
-     * of memory later and cause locking problems)
-     */
-    EnterCriticalSection(&d3d9_cs);
+     * of memory later and cause locking problems) */
+    wined3d_mutex_lock();
     hr=IWineD3DDevice_EndStateBlock(This->WineD3DDevice,&wineD3DStateBlock);
-    LeaveCriticalSection(&d3d9_cs);
-    if(hr!= D3D_OK){
+    wined3d_mutex_unlock();
+
+    if (hr!= D3D_OK)
+    {
        WARN("IWineD3DDevice_EndStateBlock returned an error\n");
        return hr;
-    }    
+    }
     /* allocate a new IDirectD3DStateBlock */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY ,sizeof(IDirect3DStateBlock9Impl));      
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DStateBlock9Impl));
     if (!object) return E_OUTOFMEMORY;
     object->ref = 1;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c	(revision 23571)
@@ -63,5 +63,11 @@
         /* No container, handle our own refcounting */
         ULONG ref = InterlockedIncrement(&This->ref);
-        if(ref == 1 && This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
+        if (ref == 1)
+        {
+            if (This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
+            wined3d_mutex_lock();
+            IWineD3DSurface_AddRef(This->wineD3DSurface);
+            wined3d_mutex_unlock();
+        }
         TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
@@ -87,10 +93,7 @@
         if (ref == 0) {
             if (This->parentDevice) IDirect3DDevice9Ex_Release(This->parentDevice);
-            if (!This->isImplicit) {
-                EnterCriticalSection(&d3d9_cs);
-                IWineD3DSurface_Release(This->wineD3DSurface);
-                LeaveCriticalSection(&d3d9_cs);
-                HeapFree(GetProcessHeap(), 0, This);
-            }
+            wined3d_mutex_lock();
+            IWineD3DSurface_Release(This->wineD3DSurface);
+            wined3d_mutex_unlock();
         }
 
@@ -106,5 +109,5 @@
     TRACE("(%p)->(%p)\n", This, ppDevice);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_GetDevice(This->wineD3DSurface, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -113,5 +116,6 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -122,7 +126,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_SetPrivateData(This->wineD3DSurface, refguid, pData, SizeOfData, Flags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -133,7 +138,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_GetPrivateData(This->wineD3DSurface, refguid, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -144,7 +150,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_FreePrivateData(This->wineD3DSurface, refguid);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -155,7 +162,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_SetPriority(This->wineD3DSurface, PriorityNew);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -166,7 +174,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_GetPriority(This->wineD3DSurface);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -176,8 +185,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     IWineD3DSurface_PreLoad(This->wineD3DSurface);
-    LeaveCriticalSection(&d3d9_cs);
-    return ;
+    wined3d_mutex_unlock();
 }
 
@@ -187,7 +195,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DSurface_GetType(This->wineD3DSurface);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -219,7 +228,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr))
@@ -243,8 +252,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     TRACE("(%p) calling IWineD3DSurface_LockRect %p %p %p %d\n", This, This->wineD3DSurface, pLockedRect, pRect, Flags);
     hr = IWineD3DSurface_LockRect(This->wineD3DSurface, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -255,7 +265,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_UnlockRect(This->wineD3DSurface);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     switch(hr)
     {
@@ -270,7 +281,15 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    if(!This->getdc_supported)
+    {
+        WARN("Surface does not support GetDC, returning D3DERR_INVALIDCALL\n");
+        /* Don't touch the DC */
+        return D3DERR_INVALIDCALL;
+    }
+
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_GetDC(This->wineD3DSurface, phdc);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -281,7 +300,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSurface_ReleaseDC(This->wineD3DSurface, hdc);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     switch(hr) {
         case WINEDDERR_NODC:    return WINED3DERR_INVALIDCALL;
@@ -290,6 +310,5 @@
 }
 
-
-const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
+static const IDirect3DSurface9Vtbl Direct3DSurface9_Vtbl =
 {
     /* IUnknown */
@@ -314,2 +333,62 @@
     IDirect3DSurface9Impl_ReleaseDC
 };
+
+static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d9_surface_wined3d_parent_ops =
+{
+    surface_wined3d_object_destroyed,
+};
+
+HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *device,
+        UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
+        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
+{
+    HRESULT hr;
+
+    surface->lpVtbl = &Direct3DSurface9_Vtbl;
+    surface->ref = 1;
+
+    switch (format)
+    {
+        case D3DFMT_A8R8G8B8:
+        case D3DFMT_X8R8G8B8:
+        case D3DFMT_R5G6B5:
+        case D3DFMT_X1R5G5B5:
+        case D3DFMT_A1R5G5B5:
+        case D3DFMT_R8G8B8:
+            surface->getdc_supported = TRUE;
+            break;
+
+        default:
+            surface->getdc_supported = FALSE;
+            break;
+    }
+
+    /* FIXME: Check MAX bounds of MultisampleQuality. */
+    if (multisample_quality > 0)
+    {
+        FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality);
+        multisample_quality = 0;
+    }
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateSurface(device->WineD3DDevice, width, height, wined3dformat_from_d3dformat(format),
+            lockable, discard, level, &surface->wineD3DSurface, usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool,
+            multisample_type, multisample_quality, SURFACE_OPENGL, (IUnknown *)surface,
+            &d3d9_surface_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d surface, hr %#x.\n", hr);
+        return hr;
+    }
+
+    surface->parentDevice = (IDirect3DDevice9Ex *)device;
+    IDirect3DDevice9Ex_AddRef(surface->parentDevice);
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/swapchain.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/swapchain.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/swapchain.c	(revision 23571)
@@ -72,7 +72,8 @@
         if (This->parentDevice) IDirect3DDevice9Ex_Release(This->parentDevice);
         if (!This->isImplicit) {
-            EnterCriticalSection(&d3d9_cs);
-            IWineD3DSwapChain_Destroy(This->wineD3DSwapChain, D3D9CB_DestroyRenderTarget);
-            LeaveCriticalSection(&d3d9_cs);
+            wined3d_mutex_lock();
+            IWineD3DSwapChain_Destroy(This->wineD3DSwapChain);
+            wined3d_mutex_unlock();
+
             HeapFree(GetProcessHeap(), 0, This);
         }
@@ -88,7 +89,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -100,7 +101,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain,  ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -113,5 +115,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &mySurface);
     if (hrc == D3D_OK && NULL != mySurface) {
@@ -119,5 +121,6 @@
        IWineD3DSurface_Release(mySurface);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     /* Do not touch the **ppBackBuffer pointer otherwise! (see device test) */
     return hrc;
@@ -129,7 +132,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSwapChain_GetRasterStatus(This->wineD3DSwapChain, (WINED3DRASTER_STATUS *) pRasterStatus);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -140,7 +144,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSwapChain_GetDisplayMode(This->wineD3DSwapChain, (WINED3DDISPLAYMODE *) pMode);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -156,5 +160,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hrc = IWineD3DSwapChain_GetDevice(This->wineD3DSwapChain, &device);
     if (hrc == D3D_OK && NULL != device) {
@@ -162,5 +166,6 @@
        IWineD3DDevice_Release(device);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hrc;
 }
@@ -173,7 +178,7 @@
     TRACE("(%p)->(%p): Relay\n", This, pPresentationParameters);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DSwapChain_GetPresentParameters(This->wineD3DSwapChain, &winePresentParameters);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     pPresentationParameters->BackBufferWidth            = winePresentParameters.BackBufferWidth;
@@ -250,8 +255,8 @@
     localParameters.AutoRestoreDisplayMode              = TRUE;
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters,
             &object->wineD3DSwapChain, (IUnknown*)object, SURFACE_OPENGL);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     pPresentationParameters->BackBufferWidth            = localParameters.BackBufferWidth;
@@ -290,5 +295,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hrc = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, iSwapChain, &swapchain);
     if (hrc == D3D_OK && NULL != swapchain) {
@@ -298,5 +303,6 @@
         *pSwapChain = NULL;
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hrc;
 }
@@ -307,7 +313,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DDevice_GetNumberOfSwapChains(This->WineD3DDevice);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c	(revision 23571)
@@ -59,4 +59,12 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        IDirect3DDevice9Ex_AddRef(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DTexture_AddRef(This->wineD3DTexture);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -69,9 +77,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d9_cs);
-        IWineD3DTexture_Destroy(This->wineD3DTexture, D3D9CB_DestroySurface);
-        LeaveCriticalSection(&d3d9_cs);
         IDirect3DDevice9Ex_Release(This->parentDevice);
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_lock();
+        IWineD3DTexture_Release(This->wineD3DTexture);
+        wined3d_mutex_unlock();
     }
     return ref;
@@ -85,5 +92,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_GetDevice(This->wineD3DTexture, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -92,5 +99,6 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -101,7 +109,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_SetPrivateData(This->wineD3DTexture, refguid, pData, SizeOfData, Flags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -112,7 +121,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_GetPrivateData(This->wineD3DTexture, refguid, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -123,7 +133,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_FreePrivateData(This->wineD3DTexture, refguid);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -134,7 +145,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DTexture_SetPriority(This->wineD3DTexture, PriorityNew);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -145,7 +157,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DTexture_GetPriority(This->wineD3DTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -155,7 +168,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     IWineD3DTexture_PreLoad(This->wineD3DTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -165,7 +178,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DTexture_GetType(This->wineD3DTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -177,7 +191,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DTexture_SetLOD(This->wineD3DTexture, LODNew);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -188,7 +203,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DTexture_GetLOD(This->wineD3DTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -199,7 +215,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = IWineD3DTexture_GetLevelCount(This->wineD3DTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -210,7 +227,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_SetAutoGenFilterType(This->wineD3DTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -221,7 +239,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     ret = (D3DTEXTUREFILTERTYPE) IWineD3DTexture_GetAutoGenFilterType(This->wineD3DTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return ret;
 }
@@ -231,7 +250,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     IWineD3DTexture_GenerateMipSubLevels(This->wineD3DTexture);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -244,7 +263,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr))
@@ -269,5 +288,6 @@
 
     TRACE("(%p) Relay\n", This);
-    EnterCriticalSection(&d3d9_cs);
+
+    wined3d_mutex_lock();
     hrc = IWineD3DTexture_GetSurfaceLevel(This->wineD3DTexture, Level, &mySurface);
     if (hrc == D3D_OK && NULL != ppSurfaceLevel) {
@@ -275,5 +295,6 @@
        IWineD3DSurface_Release(mySurface);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hrc;
 }
@@ -284,7 +305,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_LockRect(This->wineD3DTexture, Level, (WINED3DLOCKED_RECT *) pLockedRect, pRect, Flags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -295,7 +317,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_UnlockRect(This->wineD3DTexture, Level);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -306,7 +329,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DTexture_AddDirtyRect(This->wineD3DTexture, pDirtyRect);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -342,40 +366,36 @@
 };
 
-
-/* IDirect3DDevice9 IDirect3DTexture9 Methods follow: */
-HRESULT  WINAPI  IDirect3DDevice9Impl_CreateTexture(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, UINT Levels, DWORD Usage,
-                                                    D3DFORMAT Format, D3DPOOL Pool, IDirect3DTexture9** ppTexture, HANDLE* pSharedHandle) {
-    IDirect3DTexture9Impl *object;
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    HRESULT hrc = D3D_OK;
-    
-    TRACE("(%p) : W(%d) H(%d), Lvl(%d) d(%d), Fmt(%#x), Pool(%d)\n", This, Width, Height, Levels, Usage, Format,  Pool);
-
-    /* Allocate the storage for the device */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DTexture9Impl));
-
-    if (NULL == object) {
-        ERR("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->lpVtbl = &Direct3DTexture9_Vtbl;
-    object->ref = 1;
-    EnterCriticalSection(&d3d9_cs);
-    hrc = IWineD3DDevice_CreateTexture(This->WineD3DDevice, Width, Height, Levels, Usage & WINED3DUSAGE_MASK,
-            wined3dformat_from_d3dformat(Format), Pool, &object->wineD3DTexture, (IUnknown *)object);
-    LeaveCriticalSection(&d3d9_cs);
-    if (FAILED(hrc)) {
-
-        /* free up object */
-        WARN("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
-        HeapFree(GetProcessHeap(), 0, object);
-   } else {
-        IDirect3DDevice9Ex_AddRef(iface);
-        object->parentDevice = iface;
-        *ppTexture= (LPDIRECT3DTEXTURE9) object;
-        TRACE("(%p) Created Texture %p, %p\n", This, object, object->wineD3DTexture);
-   }
-
-   return hrc;
-}
+static void STDMETHODCALLTYPE d3d9_texture_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d9_texture_wined3d_parent_ops =
+{
+    d3d9_texture_wined3d_object_destroyed,
+};
+
+HRESULT texture_init(IDirect3DTexture9Impl *texture, IDirect3DDevice9Impl *device,
+        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
+{
+    HRESULT hr;
+
+    texture->lpVtbl = &Direct3DTexture9_Vtbl;
+    texture->ref = 1;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
+            usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
+            &texture->wineD3DTexture, (IUnknown *)texture, &d3d9_texture_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d texture, hr %#x.\n", hr);
+        return hr;
+    }
+
+    texture->parentDevice = (IDirect3DDevice9Ex *)device;
+    IDirect3DDevice9Ex_AddRef(texture->parentDevice);
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexbuffer.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexbuffer.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexbuffer.c	(revision 23571)
@@ -58,4 +58,12 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        IDirect3DDevice9Ex_AddRef(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DBuffer_AddRef(This->wineD3DVertexBuffer);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -68,9 +76,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d9_cs);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
+        wined3d_mutex_lock();
         IWineD3DBuffer_Release(This->wineD3DVertexBuffer);
-        LeaveCriticalSection(&d3d9_cs);
-        IDirect3DDevice9Ex_Release(This->parentDevice);
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_unlock();
     }
     return ref;
@@ -84,5 +91,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetDevice(This->wineD3DVertexBuffer, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -91,5 +98,6 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -101,7 +109,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_SetPrivateData(This->wineD3DVertexBuffer, refguid, pData, SizeOfData, Flags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -113,7 +121,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetPrivateData(This->wineD3DVertexBuffer, refguid, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -124,7 +133,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_FreePrivateData(This->wineD3DVertexBuffer, refguid);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -135,7 +145,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_SetPriority(This->wineD3DVertexBuffer, PriorityNew);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -146,7 +157,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetPriority(This->wineD3DVertexBuffer);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -156,8 +168,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     IWineD3DBuffer_PreLoad(This->wineD3DVertexBuffer);
-    LeaveCriticalSection(&d3d9_cs);
-    return ;
+    wined3d_mutex_unlock();
 }
 
@@ -175,7 +186,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_Map(This->wineD3DVertexBuffer, OffsetToLock, SizeToLock, (BYTE **)ppbData, Flags);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -186,7 +198,8 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_Unmap(This->wineD3DVertexBuffer);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -198,7 +211,7 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DBuffer_GetDesc(This->wineD3DVertexBuffer, &desc);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) {
@@ -236,40 +249,37 @@
 };
 
-
-/* IDirect3DDevice9 IDirect3DVertexBuffer9 Methods follow: */
-HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(LPDIRECT3DDEVICE9EX iface,
-                                UINT Size, DWORD Usage, DWORD FVF, D3DPOOL Pool,
-                                IDirect3DVertexBuffer9** ppVertexBuffer, HANDLE* pSharedHandle) {
-    
-    IDirect3DVertexBuffer9Impl *object;
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    HRESULT hrc = D3D_OK;
-
-    /* Allocate the storage for the device */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexBuffer9Impl));
-    if (NULL == object) {
-        FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->lpVtbl = &Direct3DVertexBuffer9_Vtbl;
-    object->ref = 1;
-    object->fvf = FVF;
-    EnterCriticalSection(&d3d9_cs);
-    hrc = IWineD3DDevice_CreateVertexBuffer(This->WineD3DDevice, Size, Usage & WINED3DUSAGE_MASK,
-            0 /* fvf for ddraw only */, (WINED3DPOOL) Pool, &(object->wineD3DVertexBuffer), (IUnknown *)object);
-    LeaveCriticalSection(&d3d9_cs);
-    
-    if (hrc != D3D_OK) {
-
-        /* free up object */
-        WARN("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
-        HeapFree(GetProcessHeap(), 0, object);
-    } else {
-        IDirect3DDevice9Ex_AddRef(iface);
-        object->parentDevice = iface;
-        TRACE("(%p) : Created vertex buffer %p\n", This, object);
-        *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER9) object;
-    }
-    return hrc;
-}
+static void STDMETHODCALLTYPE d3d9_vertexbuffer_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d9_vertexbuffer_wined3d_parent_ops =
+{
+    d3d9_vertexbuffer_wined3d_object_destroyed,
+};
+
+HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
+        UINT size, UINT usage, DWORD fvf, D3DPOOL pool)
+{
+    HRESULT hr;
+
+    buffer->lpVtbl = &Direct3DVertexBuffer9_Vtbl;
+    buffer->ref = 1;
+    buffer->fvf = fvf;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateVertexBuffer(device->WineD3DDevice, size,
+            usage & WINED3DUSAGE_MASK, 0, (WINED3DPOOL)pool, &buffer->wineD3DVertexBuffer,
+            (IUnknown *)buffer, &d3d9_vertexbuffer_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d buffer, hr %#x.\n", hr);
+        return hr;
+    }
+
+    buffer->parentDevice = (IDirect3DDevice9Ex *)device;
+    IDirect3DDevice9Ex_AddRef(buffer->parentDevice);
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexdeclaration.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexdeclaration.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexdeclaration.c	(revision 23571)
@@ -46,5 +46,5 @@
    {D3DDECLTYPE_FLOAT3,    WINED3DFMT_R32G32B32_FLOAT,    3, sizeof(float)},
    {D3DDECLTYPE_FLOAT4,    WINED3DFMT_R32G32B32A32_FLOAT, 4, sizeof(float)},
-   {D3DDECLTYPE_D3DCOLOR,  WINED3DFMT_A8R8G8B8,           4, sizeof(BYTE)},
+   {D3DDECLTYPE_D3DCOLOR,  WINED3DFMT_B8G8R8A8_UNORM,     4, sizeof(BYTE)},
    {D3DDECLTYPE_UBYTE4,    WINED3DFMT_R8G8B8A8_UINT,      4, sizeof(BYTE)},
    {D3DDECLTYPE_SHORT2,    WINED3DFMT_R16G16_SINT,        2, sizeof(short int)},
@@ -97,6 +97,5 @@
     /* convert the declaration */
     elements = HeapAlloc(GetProcessHeap(), 0, size * sizeof(D3DVERTEXELEMENT9));
-    if (!elements) 
-        return D3DERR_OUTOFVIDEOMEMORY;
+    if (!elements) return D3DERR_OUTOFVIDEOMEMORY;
 
     elements[size-1] = end_element;
@@ -228,4 +227,10 @@
     if(ref == 1) {
         IDirect3DDevice9Ex_AddRef(This->parentDevice);
+        if (!This->convFVF)
+        {
+            wined3d_mutex_lock();
+            IWineD3DVertexDeclaration_AddRef(This->wineD3DVertexDeclaration);
+            wined3d_mutex_unlock();
+        }
     }
 
@@ -240,9 +245,8 @@
         ERR("Destroying vdecl with ref != 0\n");
     }
-    EnterCriticalSection(&d3d9_cs);
+
+    wined3d_mutex_lock();
     IWineD3DVertexDeclaration_Release(This->wineD3DVertexDeclaration);
-    LeaveCriticalSection(&d3d9_cs);
-    HeapFree(GetProcessHeap(), 0, This->elements);
-    HeapFree(GetProcessHeap(), 0, This);
+    wined3d_mutex_unlock();
 }
 
@@ -254,10 +258,8 @@
 
     if (ref == 0) {
-        IDirect3DDevice9Ex *parentDevice = This->parentDevice;
-
+        IDirect3DDevice9Ex_Release(This->parentDevice);
         if(!This->convFVF) {
-            IDirect3DVertexDeclaration9Impl_Release(iface);
-        }
-        IDirect3DDevice9Ex_Release(parentDevice);
+            IDirect3DVertexDeclaration9Impl_Destroy(iface);
+        }
     }
     return ref;
@@ -272,5 +274,5 @@
     TRACE("(%p) : Relay\n", iface);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVertexDeclaration_GetDevice(This->wineD3DVertexDeclaration, &myDevice);
     if (hr == D3D_OK && myDevice != NULL) {
@@ -278,5 +280,6 @@
         IWineD3DDevice_Release(myDevice);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -312,4 +315,16 @@
 };
 
+static void STDMETHODCALLTYPE d3d9_vertexdeclaration_wined3d_object_destroyed(void *parent)
+{
+    IDirect3DVertexDeclaration9Impl *declaration = parent;
+    HeapFree(GetProcessHeap(), 0, declaration->elements);
+    HeapFree(GetProcessHeap(), 0, declaration);
+}
+
+static const struct wined3d_parent_ops d3d9_vertexdeclaration_wined3d_parent_ops =
+{
+    d3d9_vertexdeclaration_wined3d_object_destroyed,
+};
+
 static HRESULT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9* d3d9_elements,
         WINED3DVERTEXELEMENT **wined3d_elements, UINT *element_count)
@@ -357,69 +372,49 @@
 }
 
-/* IDirect3DDevice9 IDirect3DVertexDeclaration9 Methods follow: */
-HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9EX iface, CONST D3DVERTEXELEMENT9* pVertexElements, IDirect3DVertexDeclaration9** ppDecl) {
-    
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    IDirect3DVertexDeclaration9Impl *object = NULL;
-    WINED3DVERTEXELEMENT* wined3d_elements;
+HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration,
+        IDirect3DDevice9Impl *device, const D3DVERTEXELEMENT9 *elements)
+{
+    WINED3DVERTEXELEMENT *wined3d_elements;
     UINT wined3d_element_count;
     UINT element_count;
     HRESULT hr;
 
-    TRACE("(%p) : Relay\n", iface);
-    if (NULL == ppDecl) {
-        WARN("(%p) : Caller passed NULL As ppDecl, returning D3DERR_INVALIDCALL\n",This);
-        return D3DERR_INVALIDCALL;
-    }
-
-    hr = convert_to_wined3d_declaration(pVertexElements, &wined3d_elements, &wined3d_element_count);
+    hr = convert_to_wined3d_declaration(elements, &wined3d_elements, &wined3d_element_count);
     if (FAILED(hr))
     {
-        WARN("(%p) : Error parsing vertex declaration\n", This);
+        WARN("Failed to create wined3d vertex declaration elements, hr %#x.\n", hr);
         return hr;
     }
 
-    /* Allocate the storage for the device */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVertexDeclaration9Impl));
-    if (NULL == object) {
+    declaration->lpVtbl = &Direct3DVertexDeclaration9_Vtbl;
+    declaration->ref = 1;
+
+    element_count = wined3d_element_count + 1;
+    declaration->elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(*declaration->elements));
+    if (!declaration->elements)
+    {
         HeapFree(GetProcessHeap(), 0, wined3d_elements);
-        FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
+        ERR("Failed to allocate vertex declaration elements memory.\n");
         return D3DERR_OUTOFVIDEOMEMORY;
     }
-
-    object->lpVtbl = &Direct3DVertexDeclaration9_Vtbl;
-    object->ref = 0;
-
-    element_count = wined3d_element_count + 1;
-    object->elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(D3DVERTEXELEMENT9));
-    if (!object->elements) {
-        HeapFree(GetProcessHeap(), 0, wined3d_elements);
-        HeapFree(GetProcessHeap(), 0, object);
-        ERR("Memory allocation failed\n");
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-    CopyMemory(object->elements, pVertexElements, element_count * sizeof(D3DVERTEXELEMENT9));
-    object->element_count = element_count;
-
-    EnterCriticalSection(&d3d9_cs);
-    hr = IWineD3DDevice_CreateVertexDeclaration(This->WineD3DDevice, &object->wineD3DVertexDeclaration,
-            (IUnknown *)object, wined3d_elements, wined3d_element_count);
-    LeaveCriticalSection(&d3d9_cs);
-
+    memcpy(declaration->elements, elements, element_count * sizeof(*elements));
+    declaration->element_count = element_count;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateVertexDeclaration(device->WineD3DDevice, &declaration->wineD3DVertexDeclaration,
+            (IUnknown *)declaration, &d3d9_vertexdeclaration_wined3d_parent_ops,
+            wined3d_elements, wined3d_element_count);
+    wined3d_mutex_unlock();
     HeapFree(GetProcessHeap(), 0, wined3d_elements);
-
-    if (FAILED(hr)) {
-
-        /* free up object */
-        WARN("(%p) call to IWineD3DDevice_CreateVertexDeclaration failed\n", This);
-        HeapFree(GetProcessHeap(), 0, object->elements);
-        HeapFree(GetProcessHeap(), 0, object);
-    } else {
-        object->parentDevice = iface;
-        *ppDecl = (LPDIRECT3DVERTEXDECLARATION9) object;
-        IDirect3DVertexDeclaration9_AddRef(*ppDecl);
-         TRACE("(%p) : Created vertex declaration %p\n", This, object);
-    }
-    return hr;
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d vertex declaration, hr %#x.\n", hr);
+        return hr;
+    }
+
+    declaration->parentDevice = (IDirect3DDevice9Ex *)device;
+    IDirect3DDevice9Ex_AddRef(declaration->parentDevice);
+
+    return D3D_OK;
 }
 
@@ -431,7 +426,8 @@
     TRACE("(%p) : Relay\n", iface);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetVertexDeclaration(This->WineD3DDevice, pDeclImpl == NULL ? NULL : pDeclImpl->wineD3DVertexDeclaration);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -449,5 +445,6 @@
 
     *ppDecl = NULL;
-    EnterCriticalSection(&d3d9_cs);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetVertexDeclaration(This->WineD3DDevice, &pTest);
     if (hr == D3D_OK && NULL != pTest) {
@@ -457,5 +454,6 @@
         *ppDecl = NULL;
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     TRACE("(%p) : returning %p\n", This, *ppDecl);
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexshader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexshader.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/vertexshader.c	(revision 23571)
@@ -56,4 +56,12 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        IDirect3DDevice9Ex_AddRef(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DVertexShader_AddRef(This->wineD3DVertexShader);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -66,9 +74,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d9_cs);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
+        wined3d_mutex_lock();
         IWineD3DVertexShader_Release(This->wineD3DVertexShader);
-        LeaveCriticalSection(&d3d9_cs);
-        IDirect3DDevice9Ex_Release(This->parentDevice);
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_unlock();
     }
     return ref;
@@ -82,5 +89,5 @@
     TRACE("(%p) : Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice);
     if (WINED3D_OK == hr && myDevice != NULL) {
@@ -90,5 +97,6 @@
         *ppDevice = NULL;
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     TRACE("(%p) returning (%p)\n", This, *ppDevice);
     return hr;
@@ -100,7 +108,8 @@
     TRACE("(%p) : Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DVertexShader_GetFunction(This->wineD3DVertexShader, pData, pSizeOfData);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -118,50 +127,47 @@
 };
 
-
-/* IDirect3DDevice9 IDirect3DVertexShader9 Methods follow: */
-HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9EX iface, CONST DWORD* pFunction, IDirect3DVertexShader9** ppShader) {
+static void STDMETHODCALLTYPE d3d9_vertexshader_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops =
+{
+    d3d9_vertexshader_wined3d_object_destroyed,
+};
+
+HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Impl *device, const DWORD *byte_code)
+{
+    HRESULT hr;
+
+    shader->ref = 1;
+    shader->lpVtbl = &Direct3DVertexShader9_Vtbl;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateVertexShader(device->WineD3DDevice, byte_code,
+            NULL /* output signature */, &shader->wineD3DVertexShader,
+            (IUnknown *)shader, &d3d9_vertexshader_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
+        return hr;
+    }
+
+    shader->parentDevice = (IDirect3DDevice9Ex *)device;
+    IDirect3DDevice9Ex_AddRef(shader->parentDevice);
+
+    return D3D_OK;
+}
+
+HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9* pShader) {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     HRESULT hrc = D3D_OK;
-    IDirect3DVertexShader9Impl *object;
-
-    /* Setup a stub object for now */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
-    TRACE("(%p) : pFunction(%p), ppShader(%p)\n", This, pFunction, ppShader);
-    if (NULL == object) {
-        FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->ref = 1;
-    object->lpVtbl = &Direct3DVertexShader9_Vtbl;
-    EnterCriticalSection(&d3d9_cs);
-    hrc= IWineD3DDevice_CreateVertexShader(This->WineD3DDevice, pFunction,
-            NULL /* output signature */, &object->wineD3DVertexShader, (IUnknown *)object);
-    LeaveCriticalSection(&d3d9_cs);
-
-    if (FAILED(hrc)) {
-
-        /* free up object */
-        FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
-        HeapFree(GetProcessHeap(), 0, object);
-    }else{
-        IDirect3DDevice9Ex_AddRef(iface);
-        object->parentDevice = iface;
-        *ppShader = (IDirect3DVertexShader9 *)object;
-        TRACE("(%p) : Created vertex shader %p\n", This, object);
-    }
-
-    TRACE("(%p) : returning %p\n", This, *ppShader);
-    return hrc;
-}
-
-HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(LPDIRECT3DDEVICE9EX iface, IDirect3DVertexShader9* pShader) {
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    HRESULT hrc = D3D_OK;
-
-    TRACE("(%p) : Relay\n", This);
-    EnterCriticalSection(&d3d9_cs);
+
+    TRACE("(%p) : Relay\n", This);
+
+    wined3d_mutex_lock();
     hrc =  IWineD3DDevice_SetVertexShader(This->WineD3DDevice, pShader==NULL?NULL:((IDirect3DVertexShader9Impl *)pShader)->wineD3DVertexShader);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     TRACE("(%p) : returning hr(%u)\n", This, hrc);
@@ -175,5 +181,6 @@
 
     TRACE("(%p) : Relay  device@%p\n", This, This->WineD3DDevice);
-    EnterCriticalSection(&d3d9_cs);
+
+    wined3d_mutex_lock();
     hrc = IWineD3DDevice_GetVertexShader(This->WineD3DDevice, &pShader);
     if (SUCCEEDED(hrc))
@@ -193,5 +200,6 @@
         WARN("(%p) : Call to IWineD3DDevice_GetVertexShader failed %u (device %p)\n", This, hrc, This->WineD3DDevice);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     TRACE("(%p) : returning %p\n", This, *ppShader);
     return hrc;
@@ -209,7 +217,8 @@
     }
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -226,7 +235,9 @@
 
     TRACE("(%p) : Relay\n", This);
-    EnterCriticalSection(&d3d9_cs);
+
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetVertexShaderConstantF(This->WineD3DDevice, Register, pConstantData, Vector4fCount);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -237,7 +248,8 @@
     TRACE("(%p) : Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -248,7 +260,8 @@
     TRACE("(%p) : Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetVertexShaderConstantI(This->WineD3DDevice, Register, pConstantData, Vector4iCount);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -259,7 +272,8 @@
     TRACE("(%p) : Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_SetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
+
     return hr;
 }
@@ -270,7 +284,8 @@
     TRACE("(%p) : Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DDevice_GetVertexShaderConstantB(This->WineD3DDevice, Register, pConstantData, BoolCount);
-    LeaveCriticalSection(&d3d9_cs);
-    return hr;
-}
+    wined3d_mutex_unlock();
+
+    return hr;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volume.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volume.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volume.c	(revision 23571)
@@ -63,4 +63,12 @@
         ULONG ref = InterlockedIncrement(&This->ref);
         TRACE("(%p) : AddRef from %d\n", This, ref - 1);
+
+        if (ref == 1)
+        {
+            wined3d_mutex_lock();
+            IWineD3DVolume_AddRef(This->wineD3DVolume);
+            wined3d_mutex_unlock();
+        }
+
         return ref;
     }
@@ -82,8 +90,7 @@
 
         if (ref == 0) {
-            EnterCriticalSection(&d3d9_cs);
+            wined3d_mutex_lock();
             IWineD3DVolume_Release(This->wineD3DVolume);
-            LeaveCriticalSection(&d3d9_cs);
-            HeapFree(GetProcessHeap(), 0, This);
+            wined3d_mutex_unlock();
         }
 
@@ -99,5 +106,5 @@
     TRACE("iface %p, ppDevice %p\n", iface, ppDevice);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     IWineD3DVolume_GetDevice(This->wineD3DVolume, &myDevice);
@@ -105,5 +112,5 @@
     IWineD3DDevice_Release(myDevice);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return D3D_OK;
@@ -116,9 +123,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolume_SetPrivateData(This->wineD3DVolume, refguid, pData, SizeOfData, Flags);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -131,9 +138,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolume_GetPrivateData(This->wineD3DVolume, refguid, pData, pSizeOfData);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -146,9 +153,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolume_FreePrivateData(This->wineD3DVolume, refguid);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -181,9 +188,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr))
@@ -207,10 +214,10 @@
     TRACE("(%p) relay %p %p %p %d\n", This, This->wineD3DVolume, pLockedVolume, pBox, Flags);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolume_LockBox(This->wineD3DVolume, (WINED3DLOCKED_BOX *)pLockedVolume,
             (const WINED3DBOX *)pBox, Flags);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -223,14 +230,14 @@
     TRACE("(%p) relay %p\n", This, This->wineD3DVolume);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolume_UnlockBox(This->wineD3DVolume);
 
-    LeaveCriticalSection(&d3d9_cs);
-
-    return hr;
-}
-
-const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
+    wined3d_mutex_unlock();
+
+    return hr;
+}
+
+static const IDirect3DVolume9Vtbl Direct3DVolume9_Vtbl =
 {
     /* IUnknown */
@@ -249,11 +256,30 @@
 };
 
-ULONG WINAPI D3D9CB_DestroyVolume(IWineD3DVolume *pVolume) {
-    IDirect3DVolume9Impl* volumeParent;
-
-    IWineD3DVolume_GetParent(pVolume, (IUnknown **) &volumeParent);
-    /* GetParent's AddRef was forwarded to an object in destruction.
-     * Releasing it here again would cause an endless recursion. */
-    volumeParent->forwardReference = NULL;
-    return IDirect3DVolume9_Release((IDirect3DVolume9*) volumeParent);
-}
+static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d9_volume_wined3d_parent_ops =
+{
+    volume_wined3d_object_destroyed,
+};
+
+HRESULT volume_init(IDirect3DVolume9Impl *volume, IDirect3DDevice9Impl *device, UINT width, UINT height,
+        UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool)
+{
+    HRESULT hr;
+
+    volume->lpVtbl = &Direct3DVolume9_Vtbl;
+    volume->ref = 1;
+
+    hr = IWineD3DDevice_CreateVolume(device->WineD3DDevice, width, height, depth, usage & WINED3DUSAGE_MASK,
+            format, pool, &volume->wineD3DVolume, (IUnknown *)volume, &d3d9_volume_wined3d_parent_ops);
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d volume, hr %#x.\n", hr);
+        return hr;
+    }
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volumetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volumetexture.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volumetexture.c	(revision 23571)
@@ -58,4 +58,12 @@
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
+    if (ref == 1)
+    {
+        IDirect3DDevice9Ex_AddRef(This->parentDevice);
+        wined3d_mutex_lock();
+        IWineD3DVolumeTexture_AddRef(This->wineD3DVolumeTexture);
+        wined3d_mutex_unlock();
+    }
+
     return ref;
 }
@@ -68,9 +76,8 @@
 
     if (ref == 0) {
-        EnterCriticalSection(&d3d9_cs);
-        IWineD3DVolumeTexture_Destroy(This->wineD3DVolumeTexture, D3D9CB_DestroyVolume);
-        LeaveCriticalSection(&d3d9_cs);
         IDirect3DDevice9Ex_Release(This->parentDevice);
-        HeapFree(GetProcessHeap(), 0, This);
+        wined3d_mutex_lock();
+        IWineD3DVolumeTexture_Release(This->wineD3DVolumeTexture);
+        wined3d_mutex_unlock();
     }
     return ref;
@@ -85,5 +92,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
     hr = IWineD3DStateBlock_GetDevice(This->wineD3DVolumeTexture, &wined3d_device);
     if (SUCCEEDED(hr))
@@ -92,5 +99,5 @@
         IWineD3DDevice_Release(wined3d_device);
     }
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -103,9 +110,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolumeTexture_SetPrivateData(This->wineD3DVolumeTexture, refguid, pData, SizeOfData, Flags);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -118,9 +125,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolumeTexture_GetPrivateData(This->wineD3DVolumeTexture, refguid, pData, pSizeOfData);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -133,9 +140,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolumeTexture_FreePrivateData(This->wineD3DVolumeTexture, refguid);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -148,9 +155,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     priority = IWineD3DVolumeTexture_SetPriority(This->wineD3DVolumeTexture, PriorityNew);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return priority;
@@ -163,9 +170,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     priority = IWineD3DVolumeTexture_GetPriority(This->wineD3DVolumeTexture);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return priority;
@@ -177,9 +184,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     IWineD3DVolumeTexture_PreLoad(This->wineD3DVolumeTexture);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -190,9 +197,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     type = IWineD3DVolumeTexture_GetType(This->wineD3DVolumeTexture);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return type;
@@ -206,9 +213,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     lod = IWineD3DVolumeTexture_SetLOD(This->wineD3DVolumeTexture, LODNew);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return lod;
@@ -221,9 +228,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     lod = IWineD3DVolumeTexture_GetLOD(This->wineD3DVolumeTexture);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return lod;
@@ -236,9 +243,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     level_count = IWineD3DVolumeTexture_GetLevelCount(This->wineD3DVolumeTexture);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return level_count;
@@ -251,9 +258,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolumeTexture_SetAutoGenFilterType(This->wineD3DVolumeTexture, (WINED3DTEXTUREFILTERTYPE) FilterType);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -266,9 +273,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     filter_type = (D3DTEXTUREFILTERTYPE)IWineD3DVolumeTexture_GetAutoGenFilterType(This->wineD3DVolumeTexture);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return filter_type;
@@ -280,9 +287,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     IWineD3DVolumeTexture_GenerateMipSubLevels(This->wineD3DVolumeTexture);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 }
 
@@ -295,9 +302,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolumeTexture_GetLevelDesc(This->wineD3DVolumeTexture, Level, &wined3ddesc);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr))
@@ -322,5 +329,5 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hrc = IWineD3DVolumeTexture_GetVolumeLevel(This->wineD3DVolumeTexture, Level, &myVolume);
@@ -330,5 +337,5 @@
     }
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hrc;
@@ -341,10 +348,10 @@
     TRACE("(%p) Relay %p %p %p %d\n", This, This->wineD3DVolumeTexture, pLockedVolume, pBox,Flags);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolumeTexture_LockBox(This->wineD3DVolumeTexture, Level, (WINED3DLOCKED_BOX *)pLockedVolume,
             (const WINED3DBOX *)pBox, Flags);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -357,9 +364,9 @@
     TRACE("(%p) Relay %p %d\n", This, This->wineD3DVolumeTexture, Level);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolumeTexture_UnlockBox(This->wineD3DVolumeTexture, Level);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -372,9 +379,9 @@
     TRACE("(%p) Relay\n", This);
 
-    EnterCriticalSection(&d3d9_cs);
+    wined3d_mutex_lock();
 
     hr = IWineD3DVolumeTexture_AddDirtyBox(This->wineD3DVolumeTexture, (CONST WINED3DBOX *)pDirtyBox);
 
-    LeaveCriticalSection(&d3d9_cs);
+    wined3d_mutex_unlock();
 
     return hr;
@@ -412,47 +419,36 @@
 };
 
-
-/* IDirect3DDevice9 IDirect3DVolumeTexture9 Methods follow: */
-HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVolumeTexture(LPDIRECT3DDEVICE9EX iface,
-                                                          UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, 
-                                                          D3DFORMAT Format, D3DPOOL Pool, 
-                                                          IDirect3DVolumeTexture9** ppVolumeTexture, HANDLE* pSharedHandle) {
-
-    IDirect3DVolumeTexture9Impl *object;
-    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
-    HRESULT hrc = D3D_OK;
-
-    TRACE("(%p) Relay\n", This);
-
-    /* Allocate the storage for the device */
-    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DVolumeTexture9Impl));
-    if (NULL == object) {
-        ERR("(%p) allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n", This);
-        return D3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->lpVtbl = &Direct3DVolumeTexture9_Vtbl;
-    object->ref = 1;
-
-    EnterCriticalSection(&d3d9_cs);
-
-    hrc = IWineD3DDevice_CreateVolumeTexture(This->WineD3DDevice, Width, Height, Depth, Levels,
-            Usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(Format),
-            Pool, &object->wineD3DVolumeTexture, (IUnknown *)object);
-
-    LeaveCriticalSection(&d3d9_cs);
-
-    if (hrc != D3D_OK) {
-
-        /* free up object */
-        WARN("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
-        HeapFree(GetProcessHeap(), 0, object);
-    } else {
-        IDirect3DDevice9Ex_AddRef(iface);
-        object->parentDevice = iface;
-        *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE9) object;
-        TRACE("(%p) : Created volume texture %p\n", This, object);
-    }
-    TRACE("(%p)  returning %p\n", This , *ppVolumeTexture);
-    return hrc;
-}
+static void STDMETHODCALLTYPE volumetexture_wined3d_object_destroyed(void *parent)
+{
+    HeapFree(GetProcessHeap(), 0, parent);
+}
+
+static const struct wined3d_parent_ops d3d9_volumetexture_wined3d_parent_ops =
+{
+    volumetexture_wined3d_object_destroyed,
+};
+
+HRESULT volumetexture_init(IDirect3DVolumeTexture9Impl *texture, IDirect3DDevice9Impl *device,
+        UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
+{
+    HRESULT hr;
+
+    texture->lpVtbl = &Direct3DVolumeTexture9_Vtbl;
+    texture->ref = 1;
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateVolumeTexture(device->WineD3DDevice, width, height, depth, levels,
+            usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
+            &texture->wineD3DVolumeTexture, (IUnknown *)texture, &d3d9_volumetexture_wined3d_parent_ops);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d volume texture, hr %#x.\n", hr);
+        return hr;
+    }
+
+    texture->parentDevice = (IDirect3DDevice9Ex *)device;
+    IDirect3DDevice9Ex_AddRef(texture->parentDevice);
+
+    return D3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/ntddk.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/ntddk.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/ntddk.h	(revision 23571)
@@ -71,6 +71,56 @@
 } CONFIGURATION_INFORMATION, *PCONFIGURATION_INFORMATION;
 
+typedef enum _CONFIGURATION_TYPE
+{
+    ArcSystem = 0,
+    CentralProcessor,
+    FloatingPointProcessor,
+    PrimaryIcache,
+    PrimaryDcache,
+    SecondaryIcache,
+    SecondaryDcache,
+    SecondaryCache,
+    EisaAdapter,
+    TcAdapter,
+    ScsiAdapter,
+    DtiAdapter,
+    MultiFunctionAdapter,
+    DiskController,
+    TapeController,
+    CdromController,
+    WormController,
+    SerialController,
+    NetworkController,
+    DisplayController,
+    ParallelController,
+    PointerController,
+    KeyboardController,
+    AudioController,
+    OtherController,
+    DiskPeripheral,
+    FloppyDiskPeripheral,
+    TapePeripheral,
+    ModemPeripheral,
+    MonitorPeripheral,
+    PrinterPeripheral,
+    PointerPeripheral,
+    KeyboardPeripheral,
+    TerminalPeripheral,
+    OtherPeripheral,
+    LinePeripheral,
+    NetworkPeripheral,
+    SystemMemory,
+    DockingInformation,
+    RealModeIrqRoutingTable,
+    RealModePCIEnumeration,
+    MaximunType
+} CONFIGURATION_TYPE, *PCONFIGURATION_TYPE;
+
 typedef VOID (WINAPI *PDRIVER_REINITIALIZE)(PDRIVER_OBJECT,PVOID,ULONG);
+typedef NTSTATUS (WINAPI *PIO_QUERY_DEVICE_ROUTINE)(PVOID,PUNICODE_STRING,INTERFACE_TYPE,ULONG,
+            PKEY_VALUE_FULL_INFORMATION*,CONFIGURATION_TYPE,ULONG,PKEY_VALUE_FULL_INFORMATION*);
 
+NTSTATUS  WINAPI IoQueryDeviceDescription(PINTERFACE_TYPE,PULONG,PCONFIGURATION_TYPE,PULONG,
+                                  PCONFIGURATION_TYPE,PULONG,PIO_QUERY_DEVICE_ROUTINE,PVOID);
 void      WINAPI IoRegisterDriverReinitialization(PDRIVER_OBJECT,PDRIVER_REINITIALIZE,PVOID);
 NTSTATUS  WINAPI IoRegisterShutdownNotification(PDEVICE_OBJECT);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddraw.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddraw.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddraw.h	(revision 23571)
@@ -950,5 +950,6 @@
 #define DDSD_FVF                0x00200000
 #define DDSD_SRCVBHANDLE        0x00400000
-#define	DDSD_ALL		0x007ff9ee
+#define DDSD_DEPTH              0x00800000
+#define DDSD_ALL                0x00fff9ee
 
 /* EnumSurfaces flags */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dinput.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dinput.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dinput.h	(revision 23571)
@@ -644,4 +644,6 @@
 #define DIGDD_PEEK		0x00000001
 
+#define DISEQUENCE_COMPARE(dwSq1,cmp,dwSq2) ((int)((dwSq1) - (dwSq2)) cmp 0)
+
 typedef struct DIDEVICEOBJECTDATA_DX3 {
     DWORD	dwOfs;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dispex.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dispex.idl	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dispex.idl	(revision 23571)
@@ -33,4 +33,7 @@
 #endif
 
+cpp_quote("DEFINE_GUID(SID_VariantConversion, 0x1f101481,0xbccd,0x11d0,0x93,0x36,0x00,0xa0,0xc9,0xd,0xca,0xa9);")
+cpp_quote("DEFINE_GUID(SID_GetCaller, 0x4717cc40,0xbcb9,0x11d0,0x93,0x36,0x00,0xa0,0xc9,0xd,0xca,0xa9);")
+
 cpp_quote("#define fdexNameCaseSensitive       0x00000001L")
 cpp_quote("#define fdexNameEnsure              0x00000002L")
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusflat.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusflat.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusflat.h	(revision 23571)
@@ -69,4 +69,5 @@
 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream*,GpBitmap**);
 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream*,GpBitmap**);
+GpStatus WINGDIPAPI GdipCreateHBITMAPFromBitmap(GpBitmap*,HBITMAP*,ARGB);
 GpStatus WINGDIPAPI GdipCreateHICONFromBitmap(GpBitmap*,HICON*);
 GpStatus WINGDIPAPI GdipDeleteEffect(CGpEffect*);
@@ -237,7 +238,11 @@
 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics*,GpMatrix*);
 GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics*,ARGB);
+GpStatus WINGDIPAPI GdipGetVisibleClipBounds(GpGraphics*,GpRectF*);
+GpStatus WINGDIPAPI GdipGetVisibleClipBoundsI(GpGraphics*,GpRect*);
 GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics*, BOOL*);
 GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics*,REAL,REAL,BOOL*);
 GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics*,INT,INT,BOOL*);
+GpStatus WINGDIPAPI GdipIsVisibleRect(GpGraphics*,REAL,REAL,REAL,REAL,BOOL*);
+GpStatus WINGDIPAPI GdipIsVisibleRectI(GpGraphics*,INT,INT,INT,INT,BOOL*);
 GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics*, GDIPCONST WCHAR*,
     INT, GDIPCONST GpFont*, GDIPCONST RectF*, GDIPCONST GpStringFormat*, INT,
@@ -417,4 +422,8 @@
 GpStatus WINGDIPAPI GdipGetLineBlend(GpLineGradient*,REAL*,REAL*,INT);
 GpStatus WINGDIPAPI GdipGetLineBlendCount(GpLineGradient*,INT*);
+GpStatus WINGDIPAPI GdipSetLinePresetBlend(GpLineGradient*,GDIPCONST ARGB*,
+    GDIPCONST REAL*,INT);
+GpStatus WINGDIPAPI GdipGetLinePresetBlend(GpLineGradient*,ARGB*,REAL*,INT);
+GpStatus WINGDIPAPI GdipGetLinePresetBlendCount(GpLineGradient*,INT*);
 GpStatus WINGDIPAPI GdipSetLineColors(GpLineGradient*,ARGB,ARGB);
 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient*,BOOL);
@@ -573,4 +582,8 @@
 GpStatus WINGDIPAPI GdipIsEqualRegion(GpRegion *, GpRegion *, GpGraphics *, BOOL *);
 GpStatus WINGDIPAPI GdipIsInfiniteRegion(GpRegion *, GpGraphics *, BOOL *);
+GpStatus WINGDIPAPI GdipIsVisibleRegionPoint(GpRegion *, REAL, REAL, GpGraphics *, BOOL *);
+GpStatus WINGDIPAPI GdipIsVisibleRegionPointI(GpRegion *, INT, INT, GpGraphics *, BOOL *);
+GpStatus WINGDIPAPI GdipIsVisibleRegionRect(GpRegion *, REAL, REAL, REAL, REAL, GpGraphics *, BOOL *);
+GpStatus WINGDIPAPI GdipIsVisibleRegionRectI(GpRegion *, INT, INT, INT, INT, GpGraphics *, BOOL *);
 GpStatus WINGDIPAPI GdipSetEmpty(GpRegion *);
 GpStatus WINGDIPAPI GdipSetInfinite(GpRegion *);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msctf.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msctf.idl	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msctf.idl	(revision 23571)
@@ -1337,2 +1337,32 @@
         [in] ULONG ulCount);
 };
+
+[
+  object,
+  uuid(73131f9c-56a9-49dd-b0ee-d046633f7528),
+  pointer_default(unique)
+]
+interface ITfSourceSingle : IUnknown
+{
+    HRESULT AdviseSingleSink(
+        [in] TfClientId tid,
+        [in] REFIID riid,
+        [in, iid_is(riid)] IUnknown *punk);
+
+    HRESULT UnadviseSingleSink(
+        [in] TfClientId tid,
+        [in] REFIID riid);
+};
+
+[
+  object,
+  local,
+  uuid(c0f1db0c-3a20-405c-a303-96b6010a885f),
+  pointer_default(unique)
+]
+interface ITfThreadFocusSink : IUnknown
+{
+    HRESULT OnSetThreadFocus();
+
+    HRESULT OnKillThreadFocus();
+};
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtml.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtml.idl	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtml.idl	(revision 23571)
@@ -13182,5 +13182,5 @@
     HRESULT systemLanguage([retval, out] BSTR *p);
 
-    [propget, id(DISPID_IOMNAVIGATOR_BROWSERLANGUAGE)]
+    [propget, id(DISPID_IOMNAVIGATOR_BROWSERLANGUAGE), hidden]
     HRESULT browserLanguage([retval, out] BSTR *p);
 
@@ -13194,5 +13194,5 @@
     HRESULT appMinorVersion([retval, out] BSTR *p);
 
-    [propget, id(DISPID_IOMNAVIGATOR_CONNECTIONSPEED)]
+    [propget, id(DISPID_IOMNAVIGATOR_CONNECTIONSPEED), hidden]
     HRESULT connectionSpeed([retval, out] LONG *p);
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msi.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msi.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msi.h	(revision 23571)
@@ -247,4 +247,6 @@
 #define MAX_FEATURE_CHARS 38
 
+#define ERROR_PATCH_TARGET_NOT_FOUND        1642
+
 /* Strings defined in msi.h */
 /* Advertised Information */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msxml.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msxml.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msxml.h	(revision 23571)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.27 from ../../include/msxml.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.30 from ../../include/msxml.idl - Do not edit ***/
 
 #include <rpc.h>
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oaidl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oaidl.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oaidl.h	(revision 23571)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.27 from ../../include/oaidl.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.30 from ../../include/oaidl.idl - Do not edit ***/
 
 #include <rpc.h>
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.h	(revision 23571)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.27 from ../../include/objidl.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.30 from ../../include/objidl.idl - Do not edit ***/
 
 #include <rpc.h>
@@ -7832,4 +7832,8 @@
     void *pAuthInfo;
 } SOLE_AUTHENTICATION_INFO;
+#define COLE_DEFAULT_PRINCIPAL (-1)
+
+#define COLE_DEFAULT_AUTHINFO (-1)
+
 typedef struct tagSOLE_AUTHENTICATION_LIST {
     DWORD cAuthInfo;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.idl	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.idl	(revision 23571)
@@ -1960,4 +1960,7 @@
   } SOLE_AUTHENTICATION_INFO;
 
+  const OLECHAR *COLE_DEFAULT_PRINCIPAL = /*(OLECHAR*)*/ -1;
+  const void *COLE_DEFAULT_AUTHINFO = /*(void*)*/ -1;
+
   typedef struct tagSOLE_AUTHENTICATION_LIST {
     DWORD cAuthInfo;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oledb.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oledb.idl	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oledb.idl	(revision 23571)
@@ -40,4 +40,5 @@
 typedef ULONG DBBYTEOFFSET;
 typedef ULONG DBCOUNTITEM;
+typedef ULONG DBLENGTH;
 
 #include "dbs.idl"
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oleidl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oleidl.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oleidl.h	(revision 23571)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.27 from ../../include/oleidl.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.30 from ../../include/oleidl.idl - Do not edit ***/
 
 #include <rpc.h>
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/propidl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/propidl.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/propidl.h	(revision 23571)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.27 from ../../include/propidl.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.30 from ../../include/propidl.idl - Do not edit ***/
 
 #include <rpc.h>
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/pstore.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/pstore.idl	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/pstore.idl	(revision 23571)
@@ -44,4 +44,16 @@
 typedef GUID PST_PROVIDERID, *PPST_PROVIDERID;
 
+/*****************************************************************************
+ * PSTOREC library
+ */
+[
+    uuid(5a6f1ebd-2db1-11d0-8c39-00c04fd9126b),
+    version(1.0),
+    helpstring("PStore 1.0 Type Library")
+]
+library PSTORECLib
+{
+    importlib("stdole2.tlb");
+
 typedef struct _PST_PROVIDERINFO
 {
@@ -60,5 +72,5 @@
 } PST_PROMPTINFO, *PPST_PROMPTINFO;
 
-typedef struct {
+typedef struct _PST_ACCESSCLAUSE {
     DWORD cbSize;
     PST_ACCESSCLAUSETYPE ClauseType;
@@ -67,5 +79,5 @@
 } PST_ACCESSCLAUSE, *PPST_ACCESSCLAUSE;
 
-typedef struct {
+typedef struct _PST_ACCESSRULE {
     DWORD cbSize;
     PST_ACCESSMODE AccessModeFlags;
@@ -74,5 +86,5 @@
 } PST_ACCESSRULE, *PPST_ACCESSRULE;
 
-typedef struct {
+typedef struct _PST_ACCESSRULESET {
     DWORD cbSize;
     DWORD cClause;
@@ -80,5 +92,5 @@
 } PST_ACCESSRULESET, *PPST_ACCESSRULESET;
 
-typedef struct {
+typedef struct _PST_TYPEINFO {
     DWORD cbSize;
     LPWSTR szDisplayName;
@@ -269,2 +281,4 @@
         [in] IEnumPStoreItems** ppenum );
 }
+
+};
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/rpcdce.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/rpcdce.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/rpcdce.h	(revision 23571)
@@ -200,5 +200,5 @@
 
 typedef RPC_STATUS RPC_ENTRY RPC_IF_CALLBACK_FN( RPC_IF_HANDLE InterfaceUuid, void *Context );
-typedef void (__RPC_USER *RPC_AUTH_KEY_RETRIEVAL_FN)();
+typedef void (__RPC_USER *RPC_AUTH_KEY_RETRIEVAL_FN)(void *, RPC_WSTR, ULONG, void **, RPC_STATUS *);
 
 typedef struct _RPC_POLICY
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/servprov.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/servprov.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/servprov.h	(revision 23571)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.27 from ../../include/servprov.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.30 from ../../include/servprov.idl - Do not edit ***/
 
 #include <rpc.h>
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shellapi.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shellapi.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shellapi.h	(revision 23571)
@@ -153,4 +153,17 @@
 DWORD_PTR	WINAPI SHGetFileInfoW(LPCWSTR,DWORD,SHFILEINFOW*,UINT,UINT);
 #define  SHGetFileInfo WINELIB_NAME_AW(SHGetFileInfo)
+
+/******************************************
+ * SHGetImageList
+ */
+
+HRESULT WINAPI SHGetImageList(INT, REFIID, void **);
+
+#define SHIL_LARGE        0x0
+#define SHIL_SMALL        0x1
+#define SHIL_EXTRALARGE   0x2
+#define SHIL_SYSSMALL     0x3
+#define SHIL_JUMBO        0x4
+#define SHIL_LAST         SHIL_JUMBO
 
 /******************************************
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shlobj.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shlobj.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shlobj.h	(revision 23571)
@@ -227,5 +227,5 @@
     { 'F','i','l','e','C','o','n','t','e','n','t','s',0 };
 static const WCHAR CFSTR_FILENAMEW[] =
-    { 'F','i','l','e','N','a','m','e','W',0 }
+    { 'F','i','l','e','N','a','m','e','W',0 };
 static const WCHAR CFSTR_FILENAMEMAPW[] =
     { 'F','i','l','e','N','a','m','e','M','a','p','W',0 };
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/unknwn.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/unknwn.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/unknwn.h	(revision 23571)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.27 from ../../include/unknwn.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.30 from ../../include/unknwn.idl - Do not edit ***/
 
 #include <rpc.h>
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.h	(revision 23571)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.27 from ../../include/urlmon.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.30 from ../../include/urlmon.idl - Do not edit ***/
 
 /*
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/vmrender.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/vmrender.idl	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/vmrender.idl	(revision 23571)
@@ -223,5 +223,5 @@
 typedef struct tagVMRGUID
 {
-    GUID *pGUID, GUID;
+    struct _GUID *pGUID, GUID;
 } VMRGUID;
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winbase.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winbase.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winbase.h	(revision 23571)
@@ -1333,4 +1333,5 @@
 #define                       CallNamedPipe WINELIB_NAME_AW(CallNamedPipe)
 WINBASEAPI BOOL        WINAPI CancelIo(HANDLE);
+WINBASEAPI BOOL        WINAPI CancelIoEx(HANDLE,LPOVERLAPPED);
 WINBASEAPI BOOL        WINAPI CancelWaitableTimer(HANDLE);
 WINBASEAPI BOOL        WINAPI ChangeTimerQueueTimer(HANDLE,HANDLE,ULONG,ULONG);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincodec.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincodec.idl	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincodec.idl	(revision 23571)
@@ -61,4 +61,25 @@
 } WICBitmapDecoderCapabilities;
 
+typedef enum WICBitmapDitherType {
+    WICBitmapDitherTypeNone = 0x00000000,
+    WICBitmapDitherTypeSolid = 0x00000000,
+    WICBitmapDitherTypeOrdered4x4 = 0x00000001,
+    WICBitmapDitherTypeOrdered8x8 = 0x00000002,
+    WICBitmapDitherTypeOrdered16x16 = 0x00000003,
+    WICBitmapDitherTypeSpiral4x4 = 0x00000004,
+    WICBitmapDitherTypeSpiral8x8 = 0x00000005,
+    WICBitmapDitherTypeDualSpiral4x4 = 0x00000006,
+    WICBitmapDitherTypeDualSpiral8x8 = 0x00000007,
+    WICBitmapDitherTypeErrorDiffusion = 0x00000008,
+    WICBITMAPDITHERTYPE_FORCE_DWORD = CODEC_FORCE_DWORD
+} WICBitmapDitherType;
+
+typedef enum WICBitmapEncoderCacheOption {
+    WICBitmapEncoderCacheInMemory = 0x00000000,
+    WICBitmapEncoderCacheTempFile = 0x00000001,
+    WICBitmapEncoderNoCache = 0x00000002,
+    WICBITMAPENCODERCACHEOPTION_FORCE_DWORD = CODEC_FORCE_DWORD
+} WICBitmapEncoderCacheOption;
+
 typedef enum WICBitmapPaletteType {
     WICBitmapPaletteTypeCustom = 0x00000000,
@@ -115,7 +136,19 @@
 cpp_quote("DEFINE_GUID(GUID_WICPixelFormat8bppIndexed, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x04);")
 
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormatBlackWhite, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x05);")
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat2bppGray, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x06);")
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat4bppGray, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x07);")
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat8bppGray, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x08);")
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat16bppGray, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x0b);")
+
 cpp_quote("DEFINE_GUID(GUID_WICPixelFormat16bppBGR555, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x09);")
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat16bppBGR565, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x0a);")
 cpp_quote("DEFINE_GUID(GUID_WICPixelFormat24bppBGR, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x0c);")
 cpp_quote("DEFINE_GUID(GUID_WICPixelFormat32bppBGR, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x0e);")
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat32bppBGRA, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x0f);")
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat32bppPBGRA, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x10);")
+
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat48bppRGB, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x15);")
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat64bppRGBA, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x16);")
 
 typedef struct WICRect {
@@ -137,18 +170,18 @@
 
 cpp_quote("#define WINCODEC_ERR_WRONGSTATE 0x88982f04")
+cpp_quote("#define WINCODEC_ERR_NOTINITIALIZED 0x88982f0c")
 cpp_quote("#define WINCODEC_ERR_CODECNOTHUMBNAIL 0x88982f44")
 cpp_quote("#define WINCODEC_ERR_PALETTEUNAVAILABLE 0x88982f45")
 cpp_quote("#define WINCODEC_ERR_COMPONENTNOTFOUND 0x88982f50")
+cpp_quote("#define WINCODEC_ERR_FRAMEMISSING 0x88982f62")
+cpp_quote("#define WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT 0x88982f80")
 cpp_quote("#define WINCODEC_ERR_UNSUPPORTEDOPERATION 0x88982f81")
 cpp_quote("#define WINCODEC_ERR_INSUFFICIENTBUFFER 0x88982f8c")
 
 interface IWICBitmap;
-interface IWICBitmapEncoder;
 interface IWICPalette;
-interface IWICFormatConverter;
 interface IWICBitmapScaler;
 interface IWICBitmapClipper;
 interface IWICBitmapFlipRotator;
-interface IWICStream;
 interface IWICColorContext;
 interface IWICColorTransform;
@@ -406,4 +439,159 @@
         [in] UINT index,
         [out] IWICBitmapFrameDecode **ppIBitmapFrame);
+}
+
+[
+    object,
+    uuid(00000105-a8f2-4877-ba0a-fd2b6645fb94)
+]
+interface IWICBitmapFrameEncode : IUnknown
+{
+    HRESULT Initialize(
+        [in, unique] IPropertyBag2 *pIEncoderOptions);
+
+    HRESULT SetSize(
+        [in] UINT uiWidth,
+        [in] UINT uiHeight);
+
+    HRESULT SetResolution(
+        [in] double dpiX,
+        [in] double dpiY);
+
+    HRESULT SetPixelFormat(
+        [in, out] WICPixelFormatGUID *pPixelFormat);
+
+    HRESULT SetColorContexts(
+        [in] UINT cCount,
+        [in, size_is(cCount)] IWICColorContext **ppIColorContext);
+
+    HRESULT SetPalette(
+        [in] IWICPalette *pIPalette);
+
+    HRESULT SetThumbnail(
+        [in] IWICBitmapSource *pIThumbnail);
+
+    HRESULT WritePixels(
+        [in] UINT lineCount,
+        [in] UINT cbStride,
+        [in] UINT cbBufferSize,
+        [in, size_is(cbBufferSize)] BYTE *pbPixels);
+
+    HRESULT WriteSource(
+        [in] IWICBitmapSource *pIBitmapSource,
+        [in, unique] WICRect *prc);
+
+    HRESULT Commit();
+
+    HRESULT GetMetadataQueryWriter(
+        IWICMetadataQueryWriter **ppIMetadataQueryWriter);
+}
+
+interface IWICBitmapEncoder;
+
+[
+    object,
+    uuid(94c9b4ee-a09f-4f92-8a1e-4a9bce7e76fb)
+]
+interface IWICBitmapEncoderInfo : IWICBitmapCodecInfo
+{
+    HRESULT CreateInstance(
+        [out] IWICBitmapEncoder **ppIBitmapEncoder);
+}
+
+[
+    object,
+    uuid(00000103-a8f2-4877-ba0a-fd2b6645fb94)
+]
+interface IWICBitmapEncoder : IUnknown
+{
+    HRESULT Initialize(
+        [in] IStream *pIStream,
+        [in] WICBitmapEncoderCacheOption cacheOption);
+
+    HRESULT GetContainerFormat(
+        [out] GUID *pguidContainerFormat);
+
+    HRESULT GetEncoderInfo(
+        [out] IWICBitmapEncoderInfo **ppIEncoderInfo);
+
+    HRESULT SetColorContexts(
+        [in] UINT cCount,
+        [in, size_is(cCount)] IWICColorContext **ppIColorContext);
+
+    HRESULT SetPalette(
+        [in] IWICPalette *pIPalette);
+
+    HRESULT SetThumbnail(
+        [in] IWICBitmapSource *pIThumbnail);
+
+    HRESULT SetPreview(
+        [in] IWICBitmapSource *pIPreview);
+
+    HRESULT CreateNewFrame(
+        [out] IWICBitmapFrameEncode **ppIFrameEncode,
+        [in, out, unique] IPropertyBag2 **ppIEncoderOptions);
+
+    HRESULT Commit();
+
+    HRESULT GetMetadataQueryWriter(
+        [out] IWICMetadataQueryWriter **ppIMetadataQueryWriter);
+}
+
+[
+    object,
+    uuid(00000301-a8f2-4877-ba0a-fd2b6645fb94)
+]
+interface IWICFormatConverter : IWICBitmapSource
+{
+    HRESULT Initialize(
+        [in] IWICBitmapSource *pISource,
+        [in] REFWICPixelFormatGUID dstFormat,
+        [in] WICBitmapDitherType dither,
+        [in] IWICPalette *pIPalette,
+        [in] double alphaThresholdPercent,
+        [in] WICBitmapPaletteType paletteTranslate);
+
+    HRESULT CanConvert(
+        [in] REFWICPixelFormatGUID srcPixelFormat,
+        [in] REFWICPixelFormatGUID dstPixelFormat,
+        [out] BOOL *pfCanConvert);
+}
+
+[
+    object,
+    uuid(9f34fb65-13f4-4f15-bc57-3726b5e53d9f)
+]
+interface IWICFormatConverterInfo : IWICComponentInfo
+{
+    HRESULT GetPixelFormats(
+        [in] UINT cFormats,
+        [in, out, size_is(cFormats)] WICPixelFormatGUID *pPixelFormatGUIDs,
+        [out] UINT *pcActual);
+
+    HRESULT CreateInstance(
+        [out] IWICFormatConverter **ppIConverter);
+}
+
+[
+    object,
+    uuid(135ff860-22b7-4ddf-b0f6-218f4f299a43)
+]
+interface IWICStream : IStream
+{
+    HRESULT InitializeFromIStream(
+        [in] IStream *pIStream);
+
+    HRESULT InitializeFromFilename(
+        [in] LPCWSTR wzFileName,
+        [in] DWORD dwAccessMode);
+
+    HRESULT InitializeFromMemory(
+        [in, size_is(cbBufferSize)] BYTE *pbBuffer,
+        [in] DWORD cbBufferSize);
+
+    HRESULT InitializeFromIStreamRegion(
+        [in] IStream *pIStream,
+        [in] ULARGE_INTEGER ulOffset,
+        [in] ULARGE_INTEGER ulMaxSize);
 }
 
@@ -536,4 +724,6 @@
 }
 
+cpp_quote("HRESULT WINAPI WICConvertBitmapSource(REFWICPixelFormatGUID dstFormat, IWICBitmapSource *pISrc, IWICBitmapSource **ppIDst);")
+
 cpp_quote("DEFINE_GUID(CLSID_WICBmpDecoder, 0x6b462062,0x7cbf,0x400d,0x9f,0xdb,0x81,0x3d,0xd1,0x0f,0x27,0x78);")
 cpp_quote("DEFINE_GUID(CLSID_WICPngDecoder, 0x389ea17b,0x5078,0x4cde,0xb6,0xef,0x25,0xc1,0x51,0x75,0xc7,0x51);")
@@ -544,4 +734,13 @@
 cpp_quote("DEFINE_GUID(CLSID_WICWmpDecoder, 0xa26cec36,0x234c,0x4950,0xae,0x16,0xe3,0x4a,0xac,0xe7,0x1d,0x0d);")
 
+cpp_quote("DEFINE_GUID(CLSID_WICBmpEncoder, 0x69be8bb4,0xd66d,0x47c8,0x86,0x5a,0xed,0x15,0x89,0x43,0x37,0x82);")
+cpp_quote("DEFINE_GUID(CLSID_WICPngEncoder, 0x27949969,0x876a,0x41d7,0x94,0x47,0x56,0x8f,0x6a,0x35,0xa4,0xdc);")
+cpp_quote("DEFINE_GUID(CLSID_WICJpegEncoder, 0x1a34f5c1,0x4a5a,0x46dc,0xb6,0x44,0x1f,0x45,0x67,0xe7,0xa6,0x76);")
+cpp_quote("DEFINE_GUID(CLSID_WICGifEncoder, 0x114f5598,0x0b22,0x40a0,0x86,0xa1,0xc8,0x3e,0xa4,0x95,0xad,0xbd);")
+cpp_quote("DEFINE_GUID(CLSID_WICTiffEncoder, 0x0131be10,0x2001,0x4c5f,0xa9,0xb0,0xcc,0x88,0xfa,0xb6,0x4c,0xe8);")
+cpp_quote("DEFINE_GUID(CLSID_WICWmpEncoder, 0xac4ce3cb,0xe1c1,0x44cd,0x82,0x15,0x5a,0x16,0x65,0x50,0x9e,0xc2);")
+
+cpp_quote("DEFINE_GUID(CLSID_WICDefaultFormatConverter, 0x1a3f11dc,0xb514,0x4b17,0x8c,0x5f,0x21,0x54,0x51,0x38,0x52,0xf1);")
+
 cpp_quote("DEFINE_GUID(GUID_ContainerFormatBmp, 0x0af1d87e,0xfcfe,0x4188,0xbd,0xeb,0xa7,0x90,0x64,0x71,0xcb,0xe3);")
 cpp_quote("DEFINE_GUID(GUID_ContainerFormatPng, 0x1b7cfaf4,0x713f,0x473c,0xbb,0xcd,0x61,0x37,0x42,0x5f,0xae,0xaf);")
@@ -555,2 +754,4 @@
 
 cpp_quote("DEFINE_GUID(CATID_WICBitmapDecoders, 0x7ed96837,0x96f0,0x4812,0xb2,0x11,0xf1,0x3c,0x24,0x11,0x7e,0xd3);")
+cpp_quote("DEFINE_GUID(CATID_WICBitmapEncoders, 0xac757296,0x3522,0x4e11,0x98,0x62,0xc1,0x7b,0xe5,0xa1,0x76,0x7e);")
+cpp_quote("DEFINE_GUID(CATID_WICFormatConverters, 0x7835eae8,0xbf14,0x49d1,0x93,0xce,0x53,0x3a,0x40,0x7b,0x22,0x48);")
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincon.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincon.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincon.h	(revision 23571)
@@ -33,7 +33,27 @@
 #endif
 
+#ifndef NOGDI
+#include <wingdi.h>
+#endif
+
+/* AttachConsole special pid value */
+#define ATTACH_PARENT_PROCESS ((DWORD) -1)
+
+/* GetConsoleDisplayMode flags */
 #define CONSOLE_FULLSCREEN          1
 #define CONSOLE_FULLSCREEN_HARDWARE 2
 
+/* SetConsoleDisplayMode flags */
+#define CONSOLE_FULLSCREEN_MODE 1
+#define CONSOLE_WINDOWED_MODE   2
+
+/* CONSOLE_SELECTION_INFO.dwFlags */
+#define CONSOLE_NO_SELECTION          0x00
+#define CONSOLE_SELECTION_IN_PROGRESS 0x01
+#define CONSOLE_SELECTION_NOT_EMPTY   0x02
+#define CONSOLE_MOUSE_SELECTION       0x04
+#define CONSOLE_MOUSE_DOWN            0x08
+
+/* handler routine control signal type */
 #define CTRL_C_EVENT        0
 #define CTRL_BREAK_EVENT    1
@@ -43,9 +63,13 @@
 
 /* Console Mode flags */
-#define ENABLE_PROCESSED_INPUT 0x01
-#define ENABLE_LINE_INPUT      0x02
-#define ENABLE_ECHO_INPUT      0x04
-#define ENABLE_WINDOW_INPUT    0x08
-#define ENABLE_MOUSE_INPUT     0x10
+#define ENABLE_PROCESSED_INPUT 0x0001
+#define ENABLE_LINE_INPUT      0x0002
+#define ENABLE_ECHO_INPUT      0x0004
+#define ENABLE_WINDOW_INPUT    0x0008
+#define ENABLE_MOUSE_INPUT     0x0010
+#define ENABLE_INSERT_MODE     0x0020
+#define ENABLE_QUICK_EDIT_MODE 0x0040
+#define ENABLE_EXTENDED_FLAGS  0x0080
+#define ENABLE_AUTO_POSITION   0x0100
 
 #define ENABLE_PROCESSED_OUTPUT   0x01
@@ -57,12 +81,22 @@
 /* Attributes flags: */
 
-#define FOREGROUND_BLUE      0x0001 /* text color contains blue. */
-#define FOREGROUND_GREEN     0x0002 /* text color contains green. */
-#define FOREGROUND_RED       0x0004 /* text color contains red. */
-#define FOREGROUND_INTENSITY 0x0008 /* text color is intensified. */
-#define BACKGROUND_BLUE      0x0010 /* background color contains blue. */
-#define BACKGROUND_GREEN     0x0020 /* background color contains green. */
-#define BACKGROUND_RED       0x0040 /* background color contains red. */
-#define BACKGROUND_INTENSITY 0x0080 /* background color is intensified. */
+#define FOREGROUND_BLUE            0x0001
+#define FOREGROUND_GREEN           0x0002
+#define FOREGROUND_RED             0x0004
+#define FOREGROUND_INTENSITY       0x0008
+#define BACKGROUND_BLUE            0x0010
+#define BACKGROUND_GREEN           0x0020
+#define BACKGROUND_RED             0x0040
+#define BACKGROUND_INTENSITY       0x0080
+#define COMMON_LVB_LEADING_BYTE    0x0100
+#define COMMON_LVB_TRAILING_BYTE   0x0200
+#define COMMON_LVB_GRID_HORIZONTAL 0x0400
+#define COMMON_LVB_GRID_LVERTICAL  0x0800
+#define COMMON_LVB_GRID_RVERTICAL  0x1000
+#define COMMON_LVB_REVERSE_VIDEO   0x4000
+#define COMMON_LVB_UNDERSCORE      0x8000
+
+/* CONSOLE_HISTORY_INFO.dwFlags */
+#define HISTORY_NO_DUP_FLAG  0x01
 
 typedef struct _CONSOLE_CURSOR_INFO {
@@ -84,4 +118,38 @@
     SHORT Bottom;
 } SMALL_RECT,*LPSMALL_RECT;
+
+typedef struct _CONSOLE_FONT_INFO
+{
+    DWORD       nFont;
+    COORD       dwFontSize;
+} CONSOLE_FONT_INFO,*LPCONSOLE_FONT_INFO;
+
+#ifndef NOGDI
+typedef struct _CONSOLE_FONT_INFOEX
+{
+    ULONG       cbSize;
+    DWORD       nFont;
+    COORD       dwFontSize;
+    UINT        FontFamily;
+    UINT        FontWeight;
+    WCHAR       FaceName[LF_FACESIZE];
+} CONSOLE_FONT_INFOEX,*LPCONSOLE_FONT_INFOEX;
+#endif
+
+typedef struct tagCONSOLE_HISTORY_INFO
+{
+    UINT        cbSize;
+    UINT        HistoryBufferSize;
+    UINT        NumberOfHistoryBuffers;
+    DWORD       dwFlags;
+} CONSOLE_HISTORY_INFO,*LPCONSOLE_HISTORY_INFO;
+
+typedef struct _CONSOLE_READCONSOLE_CONTROL
+{
+    ULONG       nLength;
+    ULONG       nInitialChars;
+    ULONG       dwCtrlWakeupMask;
+    ULONG       dwConsoleKeyState;
+} CONSOLE_READCONSOLE_CONTROL,*LPCONSOLE_READCONSOLE_CONTROL;
 
 typedef struct tagCONSOLE_SCREEN_BUFFER_INFO
@@ -93,4 +161,24 @@
     COORD       dwMaximumWindowSize;
 } CONSOLE_SCREEN_BUFFER_INFO,*LPCONSOLE_SCREEN_BUFFER_INFO;
+
+typedef struct _CONSOLE_SCREEN_BUFFER_INFOEX
+{
+    ULONG       cbSize;
+    COORD       dwSize;
+    COORD       dwCursorPosition;
+    WORD        wAttributes;
+    SMALL_RECT  srWindow;
+    COORD       dwMaximumWindowSize;
+    WORD        wPopupAttributes;
+    BOOL        bFullscreenSupported;
+    COLORREF    ColorTable[16];
+} CONSOLE_SCREEN_BUFFER_INFOEX,*LPCONSOLE_SCREEN_BUFFER_INFOEX;
+
+typedef struct _CONSOLE_SELECTION_INFO
+{
+    DWORD       dwFlags;
+    COORD       dwSelectionAnchor;
+    SMALL_RECT  srSelection;
+} CONSOLE_SELECTION_INFO,*LPCONSOLE_SELECTION_INFO;
 
 typedef struct tagCHAR_INFO
@@ -137,4 +225,5 @@
 } MOUSE_EVENT_RECORD,*LPMOUSE_EVENT_RECORD;
 
+/* MOUSE_EVENT_RECORD.dwButtonState */
 #define FROM_LEFT_1ST_BUTTON_PRESSED    0x0001
 #define RIGHTMOST_BUTTON_PRESSED        0x0002
@@ -143,7 +232,9 @@
 #define FROM_LEFT_4TH_BUTTON_PRESSED    0x0010
 
+/* MOUSE_EVENT_RECORD.dwEventFlags */
 #define MOUSE_MOVED                     0x0001
 #define DOUBLE_CLICK                    0x0002
 #define MOUSE_WHEELED                   0x0004
+#define MOUSE_HWHEELED                  0x0008
 
 typedef struct tagWINDOW_BUFFER_SIZE_RECORD
@@ -204,5 +295,9 @@
 #endif  /* __i386__ */
 
+WINBASEAPI BOOL   WINAPI AddConsoleAliasA(LPSTR,LPSTR,LPSTR);
+WINBASEAPI BOOL   WINAPI AddConsoleAliasW(LPWSTR,LPWSTR,LPWSTR);
+#define                  AddConsoleAlias WINELIB_NAME_AW(AddConsoleAlias)
 WINBASEAPI BOOL   WINAPI AllocConsole(VOID);
+WINBASEAPI BOOL   WINAPI AttachConsole(DWORD);
 WINBASEAPI HANDLE WINAPI CreateConsoleScreenBuffer( DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,LPVOID);
 WINBASEAPI BOOL WINAPI   FillConsoleOutputAttribute( HANDLE,WORD,DWORD,COORD,LPDWORD);
@@ -213,16 +308,41 @@
 WINBASEAPI BOOL WINAPI   FreeConsole(VOID);
 WINBASEAPI BOOL WINAPI   GenerateConsoleCtrlEvent( DWORD,DWORD);
+WINBASEAPI DWORD WINAPI  GetConsoleAliasA(LPSTR,LPSTR,DWORD,LPSTR);
+WINBASEAPI DWORD WINAPI  GetConsoleAliasW(LPWSTR,LPWSTR,DWORD,LPWSTR);
+#define                  GetConsoleAlias WINELIB_NAME_AW(GetConsoleAlias)
+WINBASEAPI DWORD WINAPI  GetConsoleAliasesA(LPSTR,DWORD,LPSTR);
+WINBASEAPI DWORD WINAPI  GetConsoleAliasesW(LPWSTR,DWORD,LPWSTR);
+#define                  GetConsoleAliases WINELIB_NAME_AW(GetConsoleAliases)
+WINBASEAPI DWORD WINAPI  GetConsoleAliasesLengthA(LPSTR);
+WINBASEAPI DWORD WINAPI  GetConsoleAliasesLengthW(LPWSTR);
+#define                  GetConsoleAliasesLength WINELIB_NAME_AW(GetConsoleAliasesLength)
+WINBASEAPI DWORD WINAPI  GetConsoleAliasExesA(LPSTR,DWORD);
+WINBASEAPI DWORD WINAPI  GetConsoleAliasExesW(LPWSTR,DWORD);
+#define                  GetConsoleAliasExes WINELIB_NAME_AW(GetConsoleAliasExes)
+WINBASEAPI DWORD WINAPI  GetConsoleAliasExesLengthA(VOID);
+WINBASEAPI DWORD WINAPI  GetConsoleAliasExesLengthW(VOID);
+#define                  GetConsoleAliasExesLength WINELIB_NAME_AW(GetConsoleAliasExesLength)
 WINBASEAPI UINT WINAPI   GetConsoleCP(VOID);
 WINBASEAPI BOOL WINAPI   GetConsoleCursorInfo( HANDLE,LPCONSOLE_CURSOR_INFO);
+WINBASEAPI BOOL WINAPI   GetConsoleDisplayMode(LPDWORD);
+WINBASEAPI COORD WINAPI  GetConsoleFontSize(HANDLE,DWORD);
+WINBASEAPI BOOL WINAPI   GetConsoleHistoryInfo(LPCONSOLE_HISTORY_INFO);
 WINBASEAPI BOOL WINAPI   GetConsoleInputExeNameA(DWORD,LPSTR);
 WINBASEAPI BOOL WINAPI   GetConsoleInputExeNameW(DWORD,LPWSTR);
 #define                  GetConsoleInputExeName WINELIB_NAME_AW(GetConsoleInputExeName)
 WINBASEAPI BOOL WINAPI   GetConsoleMode( HANDLE,LPDWORD);
+WINBASEAPI DWORD WINAPI  GetConsoleOriginalTitleA(LPSTR,DWORD);
+WINBASEAPI DWORD WINAPI  GetConsoleOriginalTitleW(LPWSTR,DWORD);
+#define                  GetConsoleOriginalTitle WINELIB_NAME_AW(GetConsoleOriginalTitle)
 WINBASEAPI UINT WINAPI   GetConsoleOutputCP(VOID);
+WINBASEAPI DWORD WINAPI  GetConsoleProcessList(LPDWORD,DWORD);
 WINBASEAPI BOOL WINAPI   GetConsoleScreenBufferInfo(HANDLE,LPCONSOLE_SCREEN_BUFFER_INFO);
+WINBASEAPI BOOL WINAPI   GetConsoleScreenBufferInfoEx(HANDLE,LPCONSOLE_SCREEN_BUFFER_INFOEX);
 WINBASEAPI DWORD WINAPI  GetConsoleTitleA(LPSTR,DWORD);
 WINBASEAPI DWORD WINAPI  GetConsoleTitleW(LPWSTR,DWORD);
 #define                  GetConsoleTitle WINELIB_NAME_AW(GetConsoleTitle)
 WINBASEAPI HWND WINAPI   GetConsoleWindow(void);
+WINBASEAPI BOOL WINAPI   GetCurrentConsoleFont(HANDLE,BOOL,LPCONSOLE_FONT_INFO);
+WINBASEAPI BOOL WINAPI   GetCurrentConsoleFontEx(HANDLE,BOOL,LPCONSOLE_FONT_INFOEX);
 WINBASEAPI BOOL WINAPI   GetNumberOfConsoleInputEvents( HANDLE,LPDWORD);
 WINBASEAPI BOOL WINAPI   GetNumberOfConsoleMouseButtons(LPDWORD);
@@ -251,6 +371,9 @@
 WINBASEAPI BOOL WINAPI   SetConsoleCursorInfo( HANDLE,LPCONSOLE_CURSOR_INFO);
 WINBASEAPI BOOL WINAPI   SetConsoleCursorPosition(HANDLE,COORD);
+WINBASEAPI BOOL WINAPI   SetConsoleDisplayMode(HANDLE,DWORD,LPCOORD);
+WINBASEAPI BOOL WINAPI   SetConsoleHistoryInfo(LPCONSOLE_HISTORY_INFO);
 WINBASEAPI BOOL WINAPI   SetConsoleMode( HANDLE,DWORD);
 WINBASEAPI BOOL WINAPI   SetConsoleOutputCP(UINT);
+WINBASEAPI BOOL WINAPI   SetConsoleScreenBufferInfoEx(HANDLE,LPCONSOLE_SCREEN_BUFFER_INFOEX);
 WINBASEAPI BOOL WINAPI   SetConsoleScreenBufferSize(HANDLE,COORD);
 WINBASEAPI BOOL WINAPI   SetConsoleTextAttribute( HANDLE,WORD);
@@ -259,4 +382,5 @@
 #define                  SetConsoleTitle WINELIB_NAME_AW(SetConsoleTitle)
 WINBASEAPI BOOL WINAPI   SetConsoleWindowInfo( HANDLE,BOOL,LPSMALL_RECT);
+WINBASEAPI BOOL WINAPI   SetCurrentConsoleFontEx(HANDLE,BOOL,LPCONSOLE_FONT_INFOEX);
 WINBASEAPI BOOL WINAPI   WriteConsoleA(HANDLE,CONST VOID *,DWORD,LPDWORD,LPVOID);
 WINBASEAPI BOOL WINAPI   WriteConsoleW(HANDLE,CONST VOID *,DWORD,LPDWORD,LPVOID);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/port.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/port.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/port.h	(revision 23571)
@@ -39,5 +39,4 @@
 #endif
 
-#define _FILE_OFFSET_BITS 64
 #define _GNU_SOURCE  /* for pread/pwrite */
 #include <fcntl.h>
@@ -427,4 +426,20 @@
 }
 
+#ifdef __x86_64__
+extern inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
+                                                    __int64 xchg_low, __int64 *compare );
+extern inline unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
+                                                    __int64 xchg_low, __int64 *compare )
+{
+    unsigned char ret;
+    __asm__ __volatile__( "lock cmpxchg16b %0; setz %b2"
+                          : "=m" (dest[0]), "=m" (dest[1]), "=r" (ret),
+                            "=a" (compare[0]), "=d" (compare[1])
+                          : "m" (dest[0]), "m" (dest[1]), "3" (compare[0]), "4" (compare[1]),
+                            "c" (xchg_high), "b" (xchg_low) );
+    return ret;
+}
+#endif
+
 #else  /* __GNUC__ */
 
@@ -435,4 +450,8 @@
 extern void *interlocked_xchg_ptr( void **dest, void *val );
 extern int interlocked_xchg_add( int *dest, int incr );
+#ifdef _WIN64
+extern unsigned char interlocked_cmpxchg128( __int64 *dest, __int64 xchg_high,
+                                             __int64 xchg_low, __int64 *compare );
+#endif
 
 #endif  /* __GNUC__ */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/rpcfc.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/rpcfc.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/rpcfc.h	(revision 23571)
@@ -97,4 +97,5 @@
 #define RPC_FC_POINTER			0x36
 
+#define RPC_FC_ALIGNM2			0x37
 #define RPC_FC_ALIGNM4			0x38
 #define RPC_FC_ALIGNM8			0x39
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/server_protocol.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/server_protocol.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/server_protocol.h	(revision 23571)
@@ -153,5 +153,5 @@
         struct { unsigned int eip, ebp, esp, eflags, cs, ss; } i386_regs;
         struct { unsigned __int64 rip, rbp, rsp;
-                 unsigned int cs, ss, flags, mxcsr; } x86_64_regs;
+                 unsigned int cs, ss, flags; } x86_64_regs;
         struct { unsigned __int64 fir;
                  unsigned int psr; } alpha_regs;
@@ -219,4 +219,40 @@
 typedef __int64 timeout_t;
 #define TIMEOUT_INFINITE (((timeout_t)0x7fffffff) << 32 | 0xffffffff)
+
+
+typedef struct
+{
+    unsigned int debug_flags;
+    unsigned int console_flags;
+    obj_handle_t console;
+    obj_handle_t hstdin;
+    obj_handle_t hstdout;
+    obj_handle_t hstderr;
+    unsigned int x;
+    unsigned int y;
+    unsigned int xsize;
+    unsigned int ysize;
+    unsigned int xchars;
+    unsigned int ychars;
+    unsigned int attribute;
+    unsigned int flags;
+    unsigned int show;
+    data_size_t  curdir_len;
+    data_size_t  dllpath_len;
+    data_size_t  imagepath_len;
+    data_size_t  cmdline_len;
+    data_size_t  title_len;
+    data_size_t  desktop_len;
+    data_size_t  shellinfo_len;
+    data_size_t  runtime_len;
+
+
+
+
+
+
+
+
+} startup_info_t;
 
 
@@ -545,12 +581,10 @@
     int          socket_fd;
     obj_handle_t exe_file;
-    obj_handle_t hstdin;
-    obj_handle_t hstdout;
-    obj_handle_t hstderr;
     unsigned int process_access;
     unsigned int process_attr;
     unsigned int thread_access;
     unsigned int thread_attr;
-    /* VARARG(info,startup_info); */
+    data_size_t  info_size;
+    /* VARARG(info,startup_info,info_size); */
     /* VARARG(env,unicode_str); */
 };
@@ -607,8 +641,6 @@
     struct reply_header __header;
     obj_handle_t exe_file;
-    obj_handle_t hstdin;
-    obj_handle_t hstdout;
-    obj_handle_t hstderr;
-    /* VARARG(info,startup_info); */
+    data_size_t  info_size;
+    /* VARARG(info,startup_info,info_size); */
     /* VARARG(env,unicode_str); */
 };
@@ -2869,4 +2901,7 @@
     struct request_header __header;
     obj_handle_t handle;
+    client_ptr_t iosb;
+    int          only_thread;
+    char __pad_28[4];
 };
 struct cancel_async_reply
@@ -5322,5 +5357,5 @@
 };
 
-#define SERVER_PROTOCOL_VERSION 387
+#define SERVER_PROTOCOL_VERSION 390
 
 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/test.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/test.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/test.h	(revision 23571)
@@ -71,4 +71,7 @@
 extern int winetest_get_mainargs( char*** pargv );
 extern void winetest_wait_child_process( HANDLE process );
+
+extern const char *wine_dbgstr_wn( const WCHAR *str, int n );
+static inline const char *wine_dbgstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
 
 #ifdef STANDALONE
@@ -206,4 +209,6 @@
     int todo_level;                  /* current todo nesting level */
     int todo_do_loop;
+    char *str_pos;                   /* position in debug buffer */
+    char strings[2000];              /* buffer for debug strings */
 } tls_data;
 static DWORD tls_index;
@@ -218,9 +223,29 @@
     if (!data)
     {
-        data=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(tls_data));
+        data=HeapAlloc(GetProcessHeap(), 0, sizeof(tls_data));
+        data->todo_level = 0;
+        data->str_pos = data->strings;
         TlsSetValue(tls_index,data);
     }
     SetLastError(last_error);
     return data;
+}
+
+/* allocate some tmp space for a string */
+static char *get_temp_buffer( size_t n )
+{
+    tls_data *data = get_tls_data();
+    char *res = data->str_pos;
+
+    if (res + n >= &data->strings[sizeof(data->strings)]) res = data->strings;
+    data->str_pos = res + n;
+    return res;
+}
+
+/* release extra space that we requested in gimme1() */
+static void release_temp_buffer( char *ptr, size_t size )
+{
+    tls_data *data = get_tls_data();
+    data->str_pos = ptr + size;
 }
 
@@ -417,4 +442,60 @@
 }
 
+const char *wine_dbgstr_wn( const WCHAR *str, int n )
+{
+    char *dst, *res;
+    size_t size;
+
+    if (!((ULONG_PTR)str >> 16))
+    {
+        if (!str) return "(null)";
+        res = get_temp_buffer( 6 );
+        sprintf( res, "#%04x", LOWORD(str) );
+        return res;
+    }
+    if (n == -1)
+    {
+        const WCHAR *end = str;
+        while (*end) end++;
+        n = end - str;
+    }
+    if (n < 0) n = 0;
+    size = 12 + min( 300, n * 5 );
+    dst = res = get_temp_buffer( size );
+    *dst++ = 'L';
+    *dst++ = '"';
+    while (n-- > 0 && dst <= res + size - 10)
+    {
+        WCHAR c = *str++;
+        switch (c)
+        {
+        case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
+        case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
+        case '\t': *dst++ = '\\'; *dst++ = 't'; break;
+        case '"':  *dst++ = '\\'; *dst++ = '"'; break;
+        case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
+        default:
+            if (c >= ' ' && c <= 126)
+                *dst++ = c;
+            else
+            {
+                *dst++ = '\\';
+                sprintf(dst,"%04x",c);
+                dst+=4;
+            }
+        }
+    }
+    *dst++ = '"';
+    if (n > 0)
+    {
+        *dst++ = '.';
+        *dst++ = '.';
+        *dst++ = '.';
+    }
+    *dst++ = 0;
+    release_temp_buffer( res, dst - res );
+    return res;
+}
+
 /* Find a test by name */
 static const struct test *find_test( const char *name )
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/winbase16.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/winbase16.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/winbase16.h	(revision 23571)
@@ -260,6 +260,7 @@
  * NE Header OPERATING SYSTEM
  */
-#define NE_OSFLAGS_UNKNOWN      0x01
-#define NE_OSFLAGS_WINDOWS      0x04
+#define NE_OSFLAGS_UNKNOWN      0x00
+#define NE_OSFLAGS_OS2          0x01
+#define NE_OSFLAGS_WINDOWS      0x02
 
 /*
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h	(revision 23571)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.27 from ../../include/wine/wined3d.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.30 from ../../include/wine/wined3d.idl - Do not edit ***/
 
 #include <rpc.h>
@@ -218,125 +218,120 @@
 typedef enum _WINED3DFORMAT {
     WINED3DFMT_UNKNOWN = 0,
-    WINED3DFMT_R8G8B8 = 1,
-    WINED3DFMT_A8R8G8B8 = 2,
-    WINED3DFMT_X8R8G8B8 = 3,
-    WINED3DFMT_R5G6B5 = 4,
-    WINED3DFMT_X1R5G5B5 = 5,
-    WINED3DFMT_A1R5G5B5 = 6,
-    WINED3DFMT_A4R4G4B4 = 7,
-    WINED3DFMT_R3G3B2 = 8,
-    WINED3DFMT_A8R3G3B2 = 9,
-    WINED3DFMT_X4R4G4B4 = 10,
-    WINED3DFMT_X8B8G8R8 = 11,
-    WINED3DFMT_A2R10G10B10 = 12,
-    WINED3DFMT_A8P8 = 13,
-    WINED3DFMT_P8 = 14,
-    WINED3DFMT_L8 = 15,
-    WINED3DFMT_A8L8 = 16,
-    WINED3DFMT_A4L4 = 17,
-    WINED3DFMT_L6V5U5 = 18,
-    WINED3DFMT_X8L8V8U8 = 19,
-    WINED3DFMT_W11V11U10 = 20,
-    WINED3DFMT_A2W10V10U10 = 21,
-    WINED3DFMT_D16_LOCKABLE = 22,
-    WINED3DFMT_D32 = 23,
-    WINED3DFMT_D15S1 = 24,
-    WINED3DFMT_D24S8 = 25,
-    WINED3DFMT_D24X8 = 26,
-    WINED3DFMT_D24X4S4 = 27,
-    WINED3DFMT_L16 = 28,
-    WINED3DFMT_D32F_LOCKABLE = 29,
-    WINED3DFMT_D24FS8 = 30,
-    WINED3DFMT_VERTEXDATA = 31,
-    WINED3DFMT_CxV8U8 = 32,
-    WINED3DFMT_R32G32B32A32_TYPELESS = 33,
-    WINED3DFMT_R32G32B32A32_FLOAT = 34,
-    WINED3DFMT_R32G32B32A32_UINT = 35,
-    WINED3DFMT_R32G32B32A32_SINT = 36,
-    WINED3DFMT_R32G32B32_TYPELESS = 37,
-    WINED3DFMT_R32G32B32_FLOAT = 38,
-    WINED3DFMT_R32G32B32_UINT = 39,
-    WINED3DFMT_R32G32B32_SINT = 40,
-    WINED3DFMT_R16G16B16A16_TYPELESS = 41,
-    WINED3DFMT_R16G16B16A16_FLOAT = 42,
-    WINED3DFMT_R16G16B16A16_UNORM = 43,
-    WINED3DFMT_R16G16B16A16_UINT = 44,
-    WINED3DFMT_R16G16B16A16_SNORM = 45,
-    WINED3DFMT_R16G16B16A16_SINT = 46,
-    WINED3DFMT_R32G32_TYPELESS = 47,
-    WINED3DFMT_R32G32_FLOAT = 48,
-    WINED3DFMT_R32G32_UINT = 49,
-    WINED3DFMT_R32G32_SINT = 50,
-    WINED3DFMT_R32G8X24_TYPELESS = 51,
-    WINED3DFMT_D32_FLOAT_S8X24_UINT = 52,
-    WINED3DFMT_R32_FLOAT_X8X24_TYPELESS = 53,
-    WINED3DFMT_X32_TYPELESS_G8X24_UINT = 54,
-    WINED3DFMT_R10G10B10A2_TYPELESS = 55,
-    WINED3DFMT_R10G10B10A2_UNORM = 56,
-    WINED3DFMT_R10G10B10A2_UINT = 57,
-    WINED3DFMT_R10G10B10A2_SNORM = 58,
-    WINED3DFMT_R11G11B10_FLOAT = 59,
-    WINED3DFMT_R8G8B8A8_TYPELESS = 60,
-    WINED3DFMT_R8G8B8A8_UNORM = 61,
-    WINED3DFMT_R8G8B8A8_UNORM_SRGB = 62,
-    WINED3DFMT_R8G8B8A8_UINT = 63,
-    WINED3DFMT_R8G8B8A8_SNORM = 64,
-    WINED3DFMT_R8G8B8A8_SINT = 65,
-    WINED3DFMT_R16G16_TYPELESS = 66,
-    WINED3DFMT_R16G16_FLOAT = 67,
-    WINED3DFMT_R16G16_UNORM = 68,
-    WINED3DFMT_R16G16_UINT = 69,
-    WINED3DFMT_R16G16_SNORM = 70,
-    WINED3DFMT_R16G16_SINT = 71,
-    WINED3DFMT_R32_TYPELESS = 72,
-    WINED3DFMT_D32_FLOAT = 73,
-    WINED3DFMT_R32_FLOAT = 74,
-    WINED3DFMT_R32_UINT = 75,
-    WINED3DFMT_R32_SINT = 76,
-    WINED3DFMT_R24G8_TYPELESS = 77,
-    WINED3DFMT_D24_UNORM_S8_UINT = 78,
-    WINED3DFMT_R24_UNORM_X8_TYPELESS = 79,
-    WINED3DFMT_X24_TYPELESS_G8_UINT = 80,
-    WINED3DFMT_R8G8_TYPELESS = 81,
-    WINED3DFMT_R8G8_UNORM = 82,
-    WINED3DFMT_R8G8_UINT = 83,
-    WINED3DFMT_R8G8_SNORM = 84,
-    WINED3DFMT_R8G8_SINT = 85,
-    WINED3DFMT_R16_TYPELESS = 86,
-    WINED3DFMT_R16_FLOAT = 87,
-    WINED3DFMT_D16_UNORM = 88,
-    WINED3DFMT_R16_UNORM = 89,
-    WINED3DFMT_R16_UINT = 90,
-    WINED3DFMT_R16_SNORM = 91,
-    WINED3DFMT_R16_SINT = 92,
-    WINED3DFMT_R8_TYPELESS = 93,
-    WINED3DFMT_R8_UNORM = 94,
-    WINED3DFMT_R8_UINT = 95,
-    WINED3DFMT_R8_SNORM = 96,
-    WINED3DFMT_R8_SINT = 97,
-    WINED3DFMT_A8_UNORM = 98,
-    WINED3DFMT_R1_UNORM = 99,
-    WINED3DFMT_R9G9B9E5_SHAREDEXP = 100,
-    WINED3DFMT_R8G8_B8G8_UNORM = 101,
-    WINED3DFMT_G8R8_G8B8_UNORM = 102,
-    WINED3DFMT_BC1_TYPELESS = 103,
-    WINED3DFMT_BC1_UNORM = 104,
-    WINED3DFMT_BC1_UNORM_SRGB = 105,
-    WINED3DFMT_BC2_TYPELESS = 106,
-    WINED3DFMT_BC2_UNORM = 107,
-    WINED3DFMT_BC2_UNORM_SRGB = 108,
-    WINED3DFMT_BC3_TYPELESS = 109,
-    WINED3DFMT_BC3_UNORM = 110,
-    WINED3DFMT_BC3_UNORM_SRGB = 111,
-    WINED3DFMT_BC4_TYPELESS = 112,
-    WINED3DFMT_BC4_UNORM = 113,
-    WINED3DFMT_BC4_SNORM = 114,
-    WINED3DFMT_BC5_TYPELESS = 115,
-    WINED3DFMT_BC5_UNORM = 116,
-    WINED3DFMT_BC5_SNORM = 117,
-    WINED3DFMT_B5G6R5_UNORM = 118,
-    WINED3DFMT_B5G5R5A1_UNORM = 119,
-    WINED3DFMT_B8G8R8A8_UNORM = 120,
-    WINED3DFMT_B8G8R8X8_UNORM = 121,
+    WINED3DFMT_B8G8R8_UNORM = 1,
+    WINED3DFMT_B5G5R5X1_UNORM = 2,
+    WINED3DFMT_B4G4R4A4_UNORM = 3,
+    WINED3DFMT_B2G3R3_UNORM = 4,
+    WINED3DFMT_B2G3R3A8_UNORM = 5,
+    WINED3DFMT_B4G4R4X4_UNORM = 6,
+    WINED3DFMT_R8G8B8X8_UNORM = 7,
+    WINED3DFMT_B10G10R10A2_UNORM = 8,
+    WINED3DFMT_P8_UINT_A8_UNORM = 9,
+    WINED3DFMT_P8_UINT = 10,
+    WINED3DFMT_L8_UNORM = 11,
+    WINED3DFMT_L8A8_UNORM = 12,
+    WINED3DFMT_L4A4_UNORM = 13,
+    WINED3DFMT_R5G5_SNORM_L6_UNORM = 14,
+    WINED3DFMT_R8G8_SNORM_L8X8_UNORM = 15,
+    WINED3DFMT_R10G11B11_SNORM = 16,
+    WINED3DFMT_R10G10B10_SNORM_A2_UNORM = 17,
+    WINED3DFMT_D16_LOCKABLE = 18,
+    WINED3DFMT_D32_UNORM = 19,
+    WINED3DFMT_S1_UINT_D15_UNORM = 20,
+    WINED3DFMT_S8_UINT_D24_UNORM = 21,
+    WINED3DFMT_X8D24_UNORM = 22,
+    WINED3DFMT_S4X4_UINT_D24_UNORM = 23,
+    WINED3DFMT_L16_UNORM = 24,
+    WINED3DFMT_S8_UINT_D24_FLOAT = 25,
+    WINED3DFMT_VERTEXDATA = 26,
+    WINED3DFMT_R8G8_SNORM_Cx = 27,
+    WINED3DFMT_R32G32B32A32_TYPELESS = 28,
+    WINED3DFMT_R32G32B32A32_FLOAT = 29,
+    WINED3DFMT_R32G32B32A32_UINT = 30,
+    WINED3DFMT_R32G32B32A32_SINT = 31,
+    WINED3DFMT_R32G32B32_TYPELESS = 32,
+    WINED3DFMT_R32G32B32_FLOAT = 33,
+    WINED3DFMT_R32G32B32_UINT = 34,
+    WINED3DFMT_R32G32B32_SINT = 35,
+    WINED3DFMT_R16G16B16A16_TYPELESS = 36,
+    WINED3DFMT_R16G16B16A16_FLOAT = 37,
+    WINED3DFMT_R16G16B16A16_UNORM = 38,
+    WINED3DFMT_R16G16B16A16_UINT = 39,
+    WINED3DFMT_R16G16B16A16_SNORM = 40,
+    WINED3DFMT_R16G16B16A16_SINT = 41,
+    WINED3DFMT_R32G32_TYPELESS = 42,
+    WINED3DFMT_R32G32_FLOAT = 43,
+    WINED3DFMT_R32G32_UINT = 44,
+    WINED3DFMT_R32G32_SINT = 45,
+    WINED3DFMT_R32G8X24_TYPELESS = 46,
+    WINED3DFMT_D32_FLOAT_S8X24_UINT = 47,
+    WINED3DFMT_R32_FLOAT_X8X24_TYPELESS = 48,
+    WINED3DFMT_X32_TYPELESS_G8X24_UINT = 49,
+    WINED3DFMT_R10G10B10A2_TYPELESS = 50,
+    WINED3DFMT_R10G10B10A2_UNORM = 51,
+    WINED3DFMT_R10G10B10A2_UINT = 52,
+    WINED3DFMT_R10G10B10A2_SNORM = 53,
+    WINED3DFMT_R11G11B10_FLOAT = 54,
+    WINED3DFMT_R8G8B8A8_TYPELESS = 55,
+    WINED3DFMT_R8G8B8A8_UNORM = 56,
+    WINED3DFMT_R8G8B8A8_UNORM_SRGB = 57,
+    WINED3DFMT_R8G8B8A8_UINT = 58,
+    WINED3DFMT_R8G8B8A8_SNORM = 59,
+    WINED3DFMT_R8G8B8A8_SINT = 60,
+    WINED3DFMT_R16G16_TYPELESS = 61,
+    WINED3DFMT_R16G16_FLOAT = 62,
+    WINED3DFMT_R16G16_UNORM = 63,
+    WINED3DFMT_R16G16_UINT = 64,
+    WINED3DFMT_R16G16_SNORM = 65,
+    WINED3DFMT_R16G16_SINT = 66,
+    WINED3DFMT_R32_TYPELESS = 67,
+    WINED3DFMT_D32_FLOAT = 68,
+    WINED3DFMT_R32_FLOAT = 69,
+    WINED3DFMT_R32_UINT = 70,
+    WINED3DFMT_R32_SINT = 71,
+    WINED3DFMT_R24G8_TYPELESS = 72,
+    WINED3DFMT_D24_UNORM_S8_UINT = 73,
+    WINED3DFMT_R24_UNORM_X8_TYPELESS = 74,
+    WINED3DFMT_X24_TYPELESS_G8_UINT = 75,
+    WINED3DFMT_R8G8_TYPELESS = 76,
+    WINED3DFMT_R8G8_UNORM = 77,
+    WINED3DFMT_R8G8_UINT = 78,
+    WINED3DFMT_R8G8_SNORM = 79,
+    WINED3DFMT_R8G8_SINT = 80,
+    WINED3DFMT_R16_TYPELESS = 81,
+    WINED3DFMT_R16_FLOAT = 82,
+    WINED3DFMT_D16_UNORM = 83,
+    WINED3DFMT_R16_UNORM = 84,
+    WINED3DFMT_R16_UINT = 85,
+    WINED3DFMT_R16_SNORM = 86,
+    WINED3DFMT_R16_SINT = 87,
+    WINED3DFMT_R8_TYPELESS = 88,
+    WINED3DFMT_R8_UNORM = 89,
+    WINED3DFMT_R8_UINT = 90,
+    WINED3DFMT_R8_SNORM = 91,
+    WINED3DFMT_R8_SINT = 92,
+    WINED3DFMT_A8_UNORM = 93,
+    WINED3DFMT_R1_UNORM = 94,
+    WINED3DFMT_R9G9B9E5_SHAREDEXP = 95,
+    WINED3DFMT_R8G8_B8G8_UNORM = 96,
+    WINED3DFMT_G8R8_G8B8_UNORM = 97,
+    WINED3DFMT_BC1_TYPELESS = 98,
+    WINED3DFMT_BC1_UNORM = 99,
+    WINED3DFMT_BC1_UNORM_SRGB = 100,
+    WINED3DFMT_BC2_TYPELESS = 101,
+    WINED3DFMT_BC2_UNORM = 102,
+    WINED3DFMT_BC2_UNORM_SRGB = 103,
+    WINED3DFMT_BC3_TYPELESS = 104,
+    WINED3DFMT_BC3_UNORM = 105,
+    WINED3DFMT_BC3_UNORM_SRGB = 106,
+    WINED3DFMT_BC4_TYPELESS = 107,
+    WINED3DFMT_BC4_UNORM = 108,
+    WINED3DFMT_BC4_SNORM = 109,
+    WINED3DFMT_BC5_TYPELESS = 110,
+    WINED3DFMT_BC5_UNORM = 111,
+    WINED3DFMT_BC5_SNORM = 112,
+    WINED3DFMT_B5G6R5_UNORM = 113,
+    WINED3DFMT_B5G5R5A1_UNORM = 114,
+    WINED3DFMT_B8G8R8A8_UNORM = 115,
+    WINED3DFMT_B8G8R8X8_UNORM = 116,
     WINED3DFMT_FORCE_DWORD = 0xffffffff
 } WINED3DFORMAT;
@@ -2606,4 +2601,8 @@
 };
 
+struct wined3d_parent_ops {
+    void (STDMETHODCALLTYPE *wined3d_object_destroyed)(void *parent);
+};
+
 #ifndef __IWineD3DResource_FWD_DEFINED__
 #define __IWineD3DResource_FWD_DEFINED__
@@ -2864,6 +2863,4 @@
 #endif  /* __IWineD3DDeviceParent_INTERFACE_DEFINED__ */
 
-typedef ULONG (STDMETHODCALLTYPE *D3DCB_DESTROYSURFACEFN)(IWineD3DSurface *pSurface);
-typedef ULONG (STDMETHODCALLTYPE *D3DCB_DESTROYVOLUMEFN)(IWineD3DVolume *pVolume);
 typedef ULONG (STDMETHODCALLTYPE *D3DCB_DESTROYSWAPCHAINFN)(IWineD3DSwapChain *pSwapChain);
 typedef HRESULT (STDMETHODCALLTYPE *D3DCB_ENUMRESOURCES)(IWineD3DResource *resource,void *pData);
@@ -5070,7 +5067,4 @@
 interface IWineD3DTexture : public IWineD3DBaseTexture
 {
-    virtual void STDMETHODCALLTYPE Destroy(
-        ULONG (STDMETHODCALLTYPE * destroy_surface_callback)(IWineD3DSurface *pSurface)) = 0;
-
     virtual HRESULT STDMETHODCALLTYPE GetLevelDesc(
         UINT level,
@@ -5192,8 +5186,4 @@
 
     /*** IWineD3DTexture methods ***/
-    void (STDMETHODCALLTYPE *Destroy)(
-        IWineD3DTexture* This,
-        ULONG (STDMETHODCALLTYPE * destroy_surface_callback)(IWineD3DSurface *pSurface));
-
     HRESULT (STDMETHODCALLTYPE *GetLevelDesc)(
         IWineD3DTexture* This,
@@ -5257,5 +5247,4 @@
 #define IWineD3DTexture_IsCondNP2(This) (This)->lpVtbl->IsCondNP2(This)
 /*** IWineD3DTexture methods ***/
-#define IWineD3DTexture_Destroy(This,destroy_surface_callback) (This)->lpVtbl->Destroy(This,destroy_surface_callback)
 #define IWineD3DTexture_GetLevelDesc(This,level,desc) (This)->lpVtbl->GetLevelDesc(This,level,desc)
 #define IWineD3DTexture_GetSurfaceLevel(This,level,surface) (This)->lpVtbl->GetSurfaceLevel(This,level,surface)
@@ -5267,12 +5256,4 @@
 #endif
 
-void STDMETHODCALLTYPE IWineD3DTexture_Destroy_Proxy(
-    IWineD3DTexture* This,
-    ULONG (STDMETHODCALLTYPE * destroy_surface_callback)(IWineD3DSurface *pSurface));
-void __RPC_STUB IWineD3DTexture_Destroy_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
 HRESULT STDMETHODCALLTYPE IWineD3DTexture_GetLevelDesc_Proxy(
     IWineD3DTexture* This,
@@ -5333,7 +5314,4 @@
 interface IWineD3DCubeTexture : public IWineD3DBaseTexture
 {
-    virtual void STDMETHODCALLTYPE Destroy(
-        ULONG (STDMETHODCALLTYPE * destroy_surface_callback)(IWineD3DSurface *pSurface)) = 0;
-
     virtual HRESULT STDMETHODCALLTYPE GetLevelDesc(
         UINT level,
@@ -5459,8 +5437,4 @@
 
     /*** IWineD3DCubeTexture methods ***/
-    void (STDMETHODCALLTYPE *Destroy)(
-        IWineD3DCubeTexture* This,
-        ULONG (STDMETHODCALLTYPE * destroy_surface_callback)(IWineD3DSurface *pSurface));
-
     HRESULT (STDMETHODCALLTYPE *GetLevelDesc)(
         IWineD3DCubeTexture* This,
@@ -5528,5 +5502,4 @@
 #define IWineD3DCubeTexture_IsCondNP2(This) (This)->lpVtbl->IsCondNP2(This)
 /*** IWineD3DCubeTexture methods ***/
-#define IWineD3DCubeTexture_Destroy(This,destroy_surface_callback) (This)->lpVtbl->Destroy(This,destroy_surface_callback)
 #define IWineD3DCubeTexture_GetLevelDesc(This,level,desc) (This)->lpVtbl->GetLevelDesc(This,level,desc)
 #define IWineD3DCubeTexture_GetCubeMapSurface(This,face,level,surface) (This)->lpVtbl->GetCubeMapSurface(This,face,level,surface)
@@ -5538,12 +5511,4 @@
 #endif
 
-void STDMETHODCALLTYPE IWineD3DCubeTexture_Destroy_Proxy(
-    IWineD3DCubeTexture* This,
-    ULONG (STDMETHODCALLTYPE * destroy_surface_callback)(IWineD3DSurface *pSurface));
-void __RPC_STUB IWineD3DCubeTexture_Destroy_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
 HRESULT STDMETHODCALLTYPE IWineD3DCubeTexture_GetLevelDesc_Proxy(
     IWineD3DCubeTexture* This,
@@ -5608,7 +5573,4 @@
 interface IWineD3DVolumeTexture : public IWineD3DBaseTexture
 {
-    virtual void STDMETHODCALLTYPE Destroy(
-        ULONG (STDMETHODCALLTYPE * destroy_volume_callback)(IWineD3DVolume *pVolume)) = 0;
-
     virtual HRESULT STDMETHODCALLTYPE GetLevelDesc(
         UINT level,
@@ -5730,8 +5692,4 @@
 
     /*** IWineD3DVolumeTexture methods ***/
-    void (STDMETHODCALLTYPE *Destroy)(
-        IWineD3DVolumeTexture* This,
-        ULONG (STDMETHODCALLTYPE * destroy_volume_callback)(IWineD3DVolume *pVolume));
-
     HRESULT (STDMETHODCALLTYPE *GetLevelDesc)(
         IWineD3DVolumeTexture* This,
@@ -5795,5 +5753,4 @@
 #define IWineD3DVolumeTexture_IsCondNP2(This) (This)->lpVtbl->IsCondNP2(This)
 /*** IWineD3DVolumeTexture methods ***/
-#define IWineD3DVolumeTexture_Destroy(This,destroy_volume_callback) (This)->lpVtbl->Destroy(This,destroy_volume_callback)
 #define IWineD3DVolumeTexture_GetLevelDesc(This,level,desc) (This)->lpVtbl->GetLevelDesc(This,level,desc)
 #define IWineD3DVolumeTexture_GetVolumeLevel(This,level,volume) (This)->lpVtbl->GetVolumeLevel(This,level,volume)
@@ -5805,12 +5762,4 @@
 #endif
 
-void STDMETHODCALLTYPE IWineD3DVolumeTexture_Destroy_Proxy(
-    IWineD3DVolumeTexture* This,
-    ULONG (STDMETHODCALLTYPE * destroy_volume_callback)(IWineD3DVolume *pVolume));
-void __RPC_STUB IWineD3DVolumeTexture_Destroy_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
 HRESULT STDMETHODCALLTYPE IWineD3DVolumeTexture_GetLevelDesc_Proxy(
     IWineD3DVolumeTexture* This,
@@ -6190,5 +6139,5 @@
 {
     virtual void STDMETHODCALLTYPE Destroy(
-        ULONG (STDMETHODCALLTYPE * destroy_surface_callback)(IWineD3DSurface *pSurface)) = 0;
+        ) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE GetDevice(
@@ -6253,6 +6202,5 @@
     /*** IWineD3DSwapChain methods ***/
     void (STDMETHODCALLTYPE *Destroy)(
-        IWineD3DSwapChain* This,
-        ULONG (STDMETHODCALLTYPE * destroy_surface_callback)(IWineD3DSurface *pSurface));
+        IWineD3DSwapChain* This);
 
     HRESULT (STDMETHODCALLTYPE *GetDevice)(
@@ -6317,5 +6265,5 @@
 #define IWineD3DSwapChain_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DSwapChain methods ***/
-#define IWineD3DSwapChain_Destroy(This,destroy_surface_callback) (This)->lpVtbl->Destroy(This,destroy_surface_callback)
+#define IWineD3DSwapChain_Destroy(This) (This)->lpVtbl->Destroy(This)
 #define IWineD3DSwapChain_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DSwapChain_Present(This,src_rect,dst_rect,dst_window_override,dirty_region,flags) (This)->lpVtbl->Present(This,src_rect,dst_rect,dst_window_override,dirty_region,flags)
@@ -6333,6 +6281,5 @@
 
 void STDMETHODCALLTYPE IWineD3DSwapChain_Destroy_Proxy(
-    IWineD3DSwapChain* This,
-    ULONG (STDMETHODCALLTYPE * destroy_surface_callback)(IWineD3DSurface *pSurface));
+    IWineD3DSwapChain* This);
 void __RPC_STUB IWineD3DSwapChain_Destroy_Stub(
     IRpcStubBuffer* This,
@@ -6597,7 +6544,10 @@
 interface IWineD3DBaseShader : public IWineD3DBase
 {
-    virtual HRESULT STDMETHODCALLTYPE SetFunction(
-        const DWORD *function,
-        const struct wined3d_shader_signature *output_signature) = 0;
+    virtual HRESULT STDMETHODCALLTYPE GetDevice(
+        IWineD3DDevice **device) = 0;
+
+    virtual HRESULT STDMETHODCALLTYPE GetFunction(
+        void *data,
+        UINT *data_size) = 0;
 
 };
@@ -6624,8 +6574,12 @@
 
     /*** IWineD3DBaseShader methods ***/
-    HRESULT (STDMETHODCALLTYPE *SetFunction)(
+    HRESULT (STDMETHODCALLTYPE *GetDevice)(
         IWineD3DBaseShader* This,
-        const DWORD *function,
-        const struct wined3d_shader_signature *output_signature);
+        IWineD3DDevice **device);
+
+    HRESULT (STDMETHODCALLTYPE *GetFunction)(
+        IWineD3DBaseShader* This,
+        void *data,
+        UINT *data_size);
 
     END_INTERFACE
@@ -6643,14 +6597,23 @@
 #define IWineD3DBaseShader_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DBaseShader methods ***/
-#define IWineD3DBaseShader_SetFunction(This,function,output_signature) (This)->lpVtbl->SetFunction(This,function,output_signature)
+#define IWineD3DBaseShader_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
+#define IWineD3DBaseShader_GetFunction(This,data,data_size) (This)->lpVtbl->GetFunction(This,data,data_size)
 #endif
 
 #endif
 
-HRESULT STDMETHODCALLTYPE IWineD3DBaseShader_SetFunction_Proxy(
+HRESULT STDMETHODCALLTYPE IWineD3DBaseShader_GetDevice_Proxy(
     IWineD3DBaseShader* This,
-    const DWORD *function,
-    const struct wined3d_shader_signature *output_signature);
-void __RPC_STUB IWineD3DBaseShader_SetFunction_Stub(
+    IWineD3DDevice **device);
+void __RPC_STUB IWineD3DBaseShader_GetDevice_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+HRESULT STDMETHODCALLTYPE IWineD3DBaseShader_GetFunction_Proxy(
+    IWineD3DBaseShader* This,
+    void *data,
+    UINT *data_size);
+void __RPC_STUB IWineD3DBaseShader_GetFunction_Stub(
     IRpcStubBuffer* This,
     IRpcChannelBuffer* pRpcChannelBuffer,
@@ -6670,11 +6633,4 @@
 interface IWineD3DVertexShader : public IWineD3DBaseShader
 {
-    virtual HRESULT STDMETHODCALLTYPE GetDevice(
-        IWineD3DDevice **device) = 0;
-
-    virtual HRESULT STDMETHODCALLTYPE GetFunction(
-        void *data,
-        UINT *data_size) = 0;
-
     virtual HRESULT STDMETHODCALLTYPE SetLocalConstantsF(
         UINT start_idx,
@@ -6705,10 +6661,4 @@
 
     /*** IWineD3DBaseShader methods ***/
-    HRESULT (STDMETHODCALLTYPE *SetFunction)(
-        IWineD3DVertexShader* This,
-        const DWORD *function,
-        const struct wined3d_shader_signature *output_signature);
-
-    /*** IWineD3DVertexShader methods ***/
     HRESULT (STDMETHODCALLTYPE *GetDevice)(
         IWineD3DVertexShader* This,
@@ -6720,4 +6670,5 @@
         UINT *data_size);
 
+    /*** IWineD3DVertexShader methods ***/
     HRESULT (STDMETHODCALLTYPE *SetLocalConstantsF)(
         IWineD3DVertexShader* This,
@@ -6740,8 +6691,7 @@
 #define IWineD3DVertexShader_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DBaseShader methods ***/
-#define IWineD3DVertexShader_SetFunction(This,function,output_signature) (This)->lpVtbl->SetFunction(This,function,output_signature)
-/*** IWineD3DVertexShader methods ***/
 #define IWineD3DVertexShader_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DVertexShader_GetFunction(This,data,data_size) (This)->lpVtbl->GetFunction(This,data,data_size)
+/*** IWineD3DVertexShader methods ***/
 #define IWineD3DVertexShader_SetLocalConstantsF(This,start_idx,src_data,vector4f_count) (This)->lpVtbl->SetLocalConstantsF(This,start_idx,src_data,vector4f_count)
 #endif
@@ -6749,21 +6699,4 @@
 #endif
 
-HRESULT STDMETHODCALLTYPE IWineD3DVertexShader_GetDevice_Proxy(
-    IWineD3DVertexShader* This,
-    IWineD3DDevice **device);
-void __RPC_STUB IWineD3DVertexShader_GetDevice_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
-HRESULT STDMETHODCALLTYPE IWineD3DVertexShader_GetFunction_Proxy(
-    IWineD3DVertexShader* This,
-    void *data,
-    UINT *data_size);
-void __RPC_STUB IWineD3DVertexShader_GetFunction_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
 HRESULT STDMETHODCALLTYPE IWineD3DVertexShader_SetLocalConstantsF_Proxy(
     IWineD3DVertexShader* This,
@@ -6789,11 +6722,4 @@
 interface IWineD3DPixelShader : public IWineD3DBaseShader
 {
-    virtual HRESULT STDMETHODCALLTYPE GetDevice(
-        IWineD3DDevice **device) = 0;
-
-    virtual HRESULT STDMETHODCALLTYPE GetFunction(
-        void *data,
-        UINT *data_size) = 0;
-
 };
 #else
@@ -6819,10 +6745,4 @@
 
     /*** IWineD3DBaseShader methods ***/
-    HRESULT (STDMETHODCALLTYPE *SetFunction)(
-        IWineD3DPixelShader* This,
-        const DWORD *function,
-        const struct wined3d_shader_signature *output_signature);
-
-    /*** IWineD3DPixelShader methods ***/
     HRESULT (STDMETHODCALLTYPE *GetDevice)(
         IWineD3DPixelShader* This,
@@ -6848,6 +6768,4 @@
 #define IWineD3DPixelShader_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DBaseShader methods ***/
-#define IWineD3DPixelShader_SetFunction(This,function,output_signature) (This)->lpVtbl->SetFunction(This,function,output_signature)
-/*** IWineD3DPixelShader methods ***/
 #define IWineD3DPixelShader_GetDevice(This,device) (This)->lpVtbl->GetDevice(This,device)
 #define IWineD3DPixelShader_GetFunction(This,data,data_size) (This)->lpVtbl->GetFunction(This,data,data_size)
@@ -6856,21 +6774,4 @@
 #endif
 
-HRESULT STDMETHODCALLTYPE IWineD3DPixelShader_GetDevice_Proxy(
-    IWineD3DPixelShader* This,
-    IWineD3DDevice **device);
-void __RPC_STUB IWineD3DPixelShader_GetDevice_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
-HRESULT STDMETHODCALLTYPE IWineD3DPixelShader_GetFunction_Proxy(
-    IWineD3DPixelShader* This,
-    void *data,
-    UINT *data_size);
-void __RPC_STUB IWineD3DPixelShader_GetFunction_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
 
 #endif  /* __IWineD3DPixelShader_INTERFACE_DEFINED__ */
@@ -6890,4 +6791,5 @@
         const void *data,
         IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops,
         IWineD3DBuffer **buffer) = 0;
 
@@ -6898,5 +6800,6 @@
         WINED3DPOOL pool,
         IWineD3DBuffer **vertex_buffer,
-        IUnknown *parent) = 0;
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE CreateIndexBuffer(
@@ -6905,5 +6808,6 @@
         WINED3DPOOL pool,
         IWineD3DBuffer **index_buffer,
-        IUnknown *parent) = 0;
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE CreateStateBlock(
@@ -6925,5 +6829,6 @@
         DWORD multisample_quality,
         WINED3DSURFTYPE surface_type,
-        IUnknown *parent) = 0;
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE CreateRendertargetView(
@@ -6940,5 +6845,6 @@
         WINED3DPOOL pool,
         IWineD3DTexture **texture,
-        IUnknown *parent) = 0;
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE CreateVolumeTexture(
@@ -6951,5 +6857,6 @@
         WINED3DPOOL pool,
         IWineD3DVolumeTexture **texture,
-        IUnknown *parent) = 0;
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE CreateVolume(
@@ -6961,5 +6868,6 @@
         WINED3DPOOL pool,
         IWineD3DVolume **volume,
-        IUnknown *parent) = 0;
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE CreateCubeTexture(
@@ -6970,5 +6878,6 @@
         WINED3DPOOL pool,
         IWineD3DCubeTexture **texture,
-        IUnknown *parent) = 0;
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE CreateQuery(
@@ -6986,4 +6895,5 @@
         IWineD3DVertexDeclaration **declaration,
         IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops,
         const WINED3DVERTEXELEMENT *elements,
         UINT element_count) = 0;
@@ -6992,4 +6902,5 @@
         IWineD3DVertexDeclaration **declaration,
         IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops,
         DWORD fvf) = 0;
 
@@ -6998,5 +6909,6 @@
         const struct wined3d_shader_signature *output_signature,
         IWineD3DVertexShader **shader,
-        IUnknown *parent) = 0;
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE CreatePixelShader(
@@ -7004,5 +6916,6 @@
         const struct wined3d_shader_signature *output_signature,
         IWineD3DPixelShader **shader,
-        IUnknown *parent) = 0;
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE CreatePalette(
@@ -7019,5 +6932,4 @@
 
     virtual HRESULT STDMETHODCALLTYPE Uninit3D(
-        ULONG (STDMETHODCALLTYPE * destroy_surface_callback)(IWineD3DSurface *pSurface),
         ULONG (STDMETHODCALLTYPE * destroy_swapchain_callback)(IWineD3DSwapChain *pSwapChain)) = 0;
 
@@ -7125,9 +7037,9 @@
         WINED3DGAMMARAMP *ramp) = 0;
 
-    virtual HRESULT STDMETHODCALLTYPE SetIndices(
+    virtual HRESULT STDMETHODCALLTYPE SetIndexBuffer(
         IWineD3DBuffer *index_buffer,
         WINED3DFORMAT format) = 0;
 
-    virtual HRESULT STDMETHODCALLTYPE GetIndices(
+    virtual HRESULT STDMETHODCALLTYPE GetIndexBuffer(
         IWineD3DBuffer **index_buffer) = 0;
 
@@ -7403,6 +7315,4 @@
 
     virtual HRESULT STDMETHODCALLTYPE DrawIndexedPrimitive(
-        UINT min_vertex_idx,
-        UINT vertex_count,
         UINT start_idx,
         UINT index_count) = 0;
@@ -7414,6 +7324,4 @@
 
     virtual HRESULT STDMETHODCALLTYPE DrawIndexedPrimitiveUP(
-        UINT min_vertex_idx,
-        UINT vertex_count,
         UINT index_count,
         const void *index_data,
@@ -7497,4 +7405,5 @@
         const void *data,
         IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops,
         IWineD3DBuffer **buffer);
 
@@ -7506,5 +7415,6 @@
         WINED3DPOOL pool,
         IWineD3DBuffer **vertex_buffer,
-        IUnknown *parent);
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops);
 
     HRESULT (STDMETHODCALLTYPE *CreateIndexBuffer)(
@@ -7514,5 +7424,6 @@
         WINED3DPOOL pool,
         IWineD3DBuffer **index_buffer,
-        IUnknown *parent);
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops);
 
     HRESULT (STDMETHODCALLTYPE *CreateStateBlock)(
@@ -7536,5 +7447,6 @@
         DWORD multisample_quality,
         WINED3DSURFTYPE surface_type,
-        IUnknown *parent);
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops);
 
     HRESULT (STDMETHODCALLTYPE *CreateRendertargetView)(
@@ -7553,5 +7465,6 @@
         WINED3DPOOL pool,
         IWineD3DTexture **texture,
-        IUnknown *parent);
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops);
 
     HRESULT (STDMETHODCALLTYPE *CreateVolumeTexture)(
@@ -7565,5 +7478,6 @@
         WINED3DPOOL pool,
         IWineD3DVolumeTexture **texture,
-        IUnknown *parent);
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops);
 
     HRESULT (STDMETHODCALLTYPE *CreateVolume)(
@@ -7576,5 +7490,6 @@
         WINED3DPOOL pool,
         IWineD3DVolume **volume,
-        IUnknown *parent);
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops);
 
     HRESULT (STDMETHODCALLTYPE *CreateCubeTexture)(
@@ -7586,5 +7501,6 @@
         WINED3DPOOL pool,
         IWineD3DCubeTexture **texture,
-        IUnknown *parent);
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops);
 
     HRESULT (STDMETHODCALLTYPE *CreateQuery)(
@@ -7605,4 +7521,5 @@
         IWineD3DVertexDeclaration **declaration,
         IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops,
         const WINED3DVERTEXELEMENT *elements,
         UINT element_count);
@@ -7612,4 +7529,5 @@
         IWineD3DVertexDeclaration **declaration,
         IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops,
         DWORD fvf);
 
@@ -7619,5 +7537,6 @@
         const struct wined3d_shader_signature *output_signature,
         IWineD3DVertexShader **shader,
-        IUnknown *parent);
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops);
 
     HRESULT (STDMETHODCALLTYPE *CreatePixelShader)(
@@ -7626,5 +7545,6 @@
         const struct wined3d_shader_signature *output_signature,
         IWineD3DPixelShader **shader,
-        IUnknown *parent);
+        IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops);
 
     HRESULT (STDMETHODCALLTYPE *CreatePalette)(
@@ -7645,5 +7565,4 @@
     HRESULT (STDMETHODCALLTYPE *Uninit3D)(
         IWineD3DDevice* This,
-        ULONG (STDMETHODCALLTYPE * destroy_surface_callback)(IWineD3DSurface *pSurface),
         ULONG (STDMETHODCALLTYPE * destroy_swapchain_callback)(IWineD3DSwapChain *pSwapChain));
 
@@ -7775,10 +7694,10 @@
         WINED3DGAMMARAMP *ramp);
 
-    HRESULT (STDMETHODCALLTYPE *SetIndices)(
+    HRESULT (STDMETHODCALLTYPE *SetIndexBuffer)(
         IWineD3DDevice* This,
         IWineD3DBuffer *index_buffer,
         WINED3DFORMAT format);
 
-    HRESULT (STDMETHODCALLTYPE *GetIndices)(
+    HRESULT (STDMETHODCALLTYPE *GetIndexBuffer)(
         IWineD3DDevice* This,
         IWineD3DBuffer **index_buffer);
@@ -8117,6 +8036,4 @@
     HRESULT (STDMETHODCALLTYPE *DrawIndexedPrimitive)(
         IWineD3DDevice* This,
-        UINT min_vertex_idx,
-        UINT vertex_count,
         UINT start_idx,
         UINT index_count);
@@ -8130,6 +8047,4 @@
     HRESULT (STDMETHODCALLTYPE *DrawIndexedPrimitiveUP)(
         IWineD3DDevice* This,
-        UINT min_vertex_idx,
-        UINT vertex_count,
         UINT index_count,
         const void *index_data,
@@ -8209,24 +8124,24 @@
 #define IWineD3DDevice_GetParent(This,parent) (This)->lpVtbl->GetParent(This,parent)
 /*** IWineD3DDevice methods ***/
-#define IWineD3DDevice_CreateBuffer(This,desc,data,parent,buffer) (This)->lpVtbl->CreateBuffer(This,desc,data,parent,buffer)
-#define IWineD3DDevice_CreateVertexBuffer(This,length,usage,fvf,pool,vertex_buffer,parent) (This)->lpVtbl->CreateVertexBuffer(This,length,usage,fvf,pool,vertex_buffer,parent)
-#define IWineD3DDevice_CreateIndexBuffer(This,length,usage,pool,index_buffer,parent) (This)->lpVtbl->CreateIndexBuffer(This,length,usage,pool,index_buffer,parent)
+#define IWineD3DDevice_CreateBuffer(This,desc,data,parent,parent_ops,buffer) (This)->lpVtbl->CreateBuffer(This,desc,data,parent,parent_ops,buffer)
+#define IWineD3DDevice_CreateVertexBuffer(This,length,usage,fvf,pool,vertex_buffer,parent,parent_ops) (This)->lpVtbl->CreateVertexBuffer(This,length,usage,fvf,pool,vertex_buffer,parent,parent_ops)
+#define IWineD3DDevice_CreateIndexBuffer(This,length,usage,pool,index_buffer,parent,parent_ops) (This)->lpVtbl->CreateIndexBuffer(This,length,usage,pool,index_buffer,parent,parent_ops)
 #define IWineD3DDevice_CreateStateBlock(This,type,stateblock,parent) (This)->lpVtbl->CreateStateBlock(This,type,stateblock,parent)
-#define IWineD3DDevice_CreateSurface(This,width,height,format,lockable,discard,level,surface,usage,pool,multisample_type,multisample_quality,surface_type,parent) (This)->lpVtbl->CreateSurface(This,width,height,format,lockable,discard,level,surface,usage,pool,multisample_type,multisample_quality,surface_type,parent)
+#define IWineD3DDevice_CreateSurface(This,width,height,format,lockable,discard,level,surface,usage,pool,multisample_type,multisample_quality,surface_type,parent,parent_ops) (This)->lpVtbl->CreateSurface(This,width,height,format,lockable,discard,level,surface,usage,pool,multisample_type,multisample_quality,surface_type,parent,parent_ops)
 #define IWineD3DDevice_CreateRendertargetView(This,resource,parent,rendertarget_view) (This)->lpVtbl->CreateRendertargetView(This,resource,parent,rendertarget_view)
-#define IWineD3DDevice_CreateTexture(This,width,height,levels,usage,format,pool,texture,parent) (This)->lpVtbl->CreateTexture(This,width,height,levels,usage,format,pool,texture,parent)
-#define IWineD3DDevice_CreateVolumeTexture(This,width,height,depth,levels,usage,format,pool,texture,parent) (This)->lpVtbl->CreateVolumeTexture(This,width,height,depth,levels,usage,format,pool,texture,parent)
-#define IWineD3DDevice_CreateVolume(This,width,height,depth,usage,format,pool,volume,parent) (This)->lpVtbl->CreateVolume(This,width,height,depth,usage,format,pool,volume,parent)
-#define IWineD3DDevice_CreateCubeTexture(This,edge_length,levels,usage,format,pool,texture,parent) (This)->lpVtbl->CreateCubeTexture(This,edge_length,levels,usage,format,pool,texture,parent)
+#define IWineD3DDevice_CreateTexture(This,width,height,levels,usage,format,pool,texture,parent,parent_ops) (This)->lpVtbl->CreateTexture(This,width,height,levels,usage,format,pool,texture,parent,parent_ops)
+#define IWineD3DDevice_CreateVolumeTexture(This,width,height,depth,levels,usage,format,pool,texture,parent,parent_ops) (This)->lpVtbl->CreateVolumeTexture(This,width,height,depth,levels,usage,format,pool,texture,parent,parent_ops)
+#define IWineD3DDevice_CreateVolume(This,width,height,depth,usage,format,pool,volume,parent,parent_ops) (This)->lpVtbl->CreateVolume(This,width,height,depth,usage,format,pool,volume,parent,parent_ops)
+#define IWineD3DDevice_CreateCubeTexture(This,edge_length,levels,usage,format,pool,texture,parent,parent_ops) (This)->lpVtbl->CreateCubeTexture(This,edge_length,levels,usage,format,pool,texture,parent,parent_ops)
 #define IWineD3DDevice_CreateQuery(This,type,query,parent) (This)->lpVtbl->CreateQuery(This,type,query,parent)
 #define IWineD3DDevice_CreateSwapChain(This,present_parameters,swapchain,parent,surface_type) (This)->lpVtbl->CreateSwapChain(This,present_parameters,swapchain,parent,surface_type)
-#define IWineD3DDevice_CreateVertexDeclaration(This,declaration,parent,elements,element_count) (This)->lpVtbl->CreateVertexDeclaration(This,declaration,parent,elements,element_count)
-#define IWineD3DDevice_CreateVertexDeclarationFromFVF(This,declaration,parent,fvf) (This)->lpVtbl->CreateVertexDeclarationFromFVF(This,declaration,parent,fvf)
-#define IWineD3DDevice_CreateVertexShader(This,function,output_signature,shader,parent) (This)->lpVtbl->CreateVertexShader(This,function,output_signature,shader,parent)
-#define IWineD3DDevice_CreatePixelShader(This,function,output_signature,shader,parent) (This)->lpVtbl->CreatePixelShader(This,function,output_signature,shader,parent)
+#define IWineD3DDevice_CreateVertexDeclaration(This,declaration,parent,parent_ops,elements,element_count) (This)->lpVtbl->CreateVertexDeclaration(This,declaration,parent,parent_ops,elements,element_count)
+#define IWineD3DDevice_CreateVertexDeclarationFromFVF(This,declaration,parent,parent_ops,fvf) (This)->lpVtbl->CreateVertexDeclarationFromFVF(This,declaration,parent,parent_ops,fvf)
+#define IWineD3DDevice_CreateVertexShader(This,function,output_signature,shader,parent,parent_ops) (This)->lpVtbl->CreateVertexShader(This,function,output_signature,shader,parent,parent_ops)
+#define IWineD3DDevice_CreatePixelShader(This,function,output_signature,shader,parent,parent_ops) (This)->lpVtbl->CreatePixelShader(This,function,output_signature,shader,parent,parent_ops)
 #define IWineD3DDevice_CreatePalette(This,flags,palette_entry,palette,parent) (This)->lpVtbl->CreatePalette(This,flags,palette_entry,palette,parent)
 #define IWineD3DDevice_Init3D(This,present_parameters) (This)->lpVtbl->Init3D(This,present_parameters)
 #define IWineD3DDevice_InitGDI(This,present_parameters) (This)->lpVtbl->InitGDI(This,present_parameters)
-#define IWineD3DDevice_Uninit3D(This,destroy_surface_callback,destroy_swapchain_callback) (This)->lpVtbl->Uninit3D(This,destroy_surface_callback,destroy_swapchain_callback)
+#define IWineD3DDevice_Uninit3D(This,destroy_swapchain_callback) (This)->lpVtbl->Uninit3D(This,destroy_swapchain_callback)
 #define IWineD3DDevice_UninitGDI(This,destroy_swapchain_callback) (This)->lpVtbl->UninitGDI(This,destroy_swapchain_callback)
 #define IWineD3DDevice_SetMultithreaded(This) (This)->lpVtbl->SetMultithreaded(This)
@@ -8258,6 +8173,6 @@
 #define IWineD3DDevice_SetGammaRamp(This,swapchain_idx,flags,ramp) (This)->lpVtbl->SetGammaRamp(This,swapchain_idx,flags,ramp)
 #define IWineD3DDevice_GetGammaRamp(This,swapchain_idx,ramp) (This)->lpVtbl->GetGammaRamp(This,swapchain_idx,ramp)
-#define IWineD3DDevice_SetIndices(This,index_buffer,format) (This)->lpVtbl->SetIndices(This,index_buffer,format)
-#define IWineD3DDevice_GetIndices(This,index_buffer) (This)->lpVtbl->GetIndices(This,index_buffer)
+#define IWineD3DDevice_SetIndexBuffer(This,index_buffer,format) (This)->lpVtbl->SetIndexBuffer(This,index_buffer,format)
+#define IWineD3DDevice_GetIndexBuffer(This,index_buffer) (This)->lpVtbl->GetIndexBuffer(This,index_buffer)
 #define IWineD3DDevice_SetBaseVertexIndex(This,base_index) (This)->lpVtbl->SetBaseVertexIndex(This,base_index)
 #define IWineD3DDevice_GetBaseVertexIndex(This,base_index) (This)->lpVtbl->GetBaseVertexIndex(This,base_index)
@@ -8326,7 +8241,7 @@
 #define IWineD3DDevice_GetPrimitiveType(This,primitive_topology) (This)->lpVtbl->GetPrimitiveType(This,primitive_topology)
 #define IWineD3DDevice_DrawPrimitive(This,start_vertex,vertex_count) (This)->lpVtbl->DrawPrimitive(This,start_vertex,vertex_count)
-#define IWineD3DDevice_DrawIndexedPrimitive(This,min_vertex_idx,vertex_count,start_idx,index_count) (This)->lpVtbl->DrawIndexedPrimitive(This,min_vertex_idx,vertex_count,start_idx,index_count)
+#define IWineD3DDevice_DrawIndexedPrimitive(This,start_idx,index_count) (This)->lpVtbl->DrawIndexedPrimitive(This,start_idx,index_count)
 #define IWineD3DDevice_DrawPrimitiveUP(This,vertex_count,stream_data,stream_stride) (This)->lpVtbl->DrawPrimitiveUP(This,vertex_count,stream_data,stream_stride)
-#define IWineD3DDevice_DrawIndexedPrimitiveUP(This,min_vertex_idx,vertex_count,index_count,index_data,index_data_format,stream_data,stream_stride) (This)->lpVtbl->DrawIndexedPrimitiveUP(This,min_vertex_idx,vertex_count,index_count,index_data,index_data_format,stream_data,stream_stride)
+#define IWineD3DDevice_DrawIndexedPrimitiveUP(This,index_count,index_data,index_data_format,stream_data,stream_stride) (This)->lpVtbl->DrawIndexedPrimitiveUP(This,index_count,index_data,index_data_format,stream_data,stream_stride)
 #define IWineD3DDevice_DrawPrimitiveStrided(This,vertex_count,strided_data) (This)->lpVtbl->DrawPrimitiveStrided(This,vertex_count,strided_data)
 #define IWineD3DDevice_DrawIndexedPrimitiveStrided(This,index_count,strided_data,vertex_count,index_data,index_data_format) (This)->lpVtbl->DrawIndexedPrimitiveStrided(This,index_count,strided_data,vertex_count,index_data,index_data_format)
@@ -8348,4 +8263,5 @@
     const void *data,
     IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops,
     IWineD3DBuffer **buffer);
 void __RPC_STUB IWineD3DDevice_CreateBuffer_Stub(
@@ -8361,5 +8277,6 @@
     WINED3DPOOL pool,
     IWineD3DBuffer **vertex_buffer,
-    IUnknown *parent);
+    IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops);
 void __RPC_STUB IWineD3DDevice_CreateVertexBuffer_Stub(
     IRpcStubBuffer* This,
@@ -8373,5 +8290,6 @@
     WINED3DPOOL pool,
     IWineD3DBuffer **index_buffer,
-    IUnknown *parent);
+    IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops);
 void __RPC_STUB IWineD3DDevice_CreateIndexBuffer_Stub(
     IRpcStubBuffer* This,
@@ -8403,5 +8321,6 @@
     DWORD multisample_quality,
     WINED3DSURFTYPE surface_type,
-    IUnknown *parent);
+    IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops);
 void __RPC_STUB IWineD3DDevice_CreateSurface_Stub(
     IRpcStubBuffer* This,
@@ -8428,5 +8347,6 @@
     WINED3DPOOL pool,
     IWineD3DTexture **texture,
-    IUnknown *parent);
+    IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops);
 void __RPC_STUB IWineD3DDevice_CreateTexture_Stub(
     IRpcStubBuffer* This,
@@ -8444,5 +8364,6 @@
     WINED3DPOOL pool,
     IWineD3DVolumeTexture **texture,
-    IUnknown *parent);
+    IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops);
 void __RPC_STUB IWineD3DDevice_CreateVolumeTexture_Stub(
     IRpcStubBuffer* This,
@@ -8459,5 +8380,6 @@
     WINED3DPOOL pool,
     IWineD3DVolume **volume,
-    IUnknown *parent);
+    IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops);
 void __RPC_STUB IWineD3DDevice_CreateVolume_Stub(
     IRpcStubBuffer* This,
@@ -8473,5 +8395,6 @@
     WINED3DPOOL pool,
     IWineD3DCubeTexture **texture,
-    IUnknown *parent);
+    IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops);
 void __RPC_STUB IWineD3DDevice_CreateCubeTexture_Stub(
     IRpcStubBuffer* This,
@@ -8504,4 +8427,5 @@
     IWineD3DVertexDeclaration **declaration,
     IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops,
     const WINED3DVERTEXELEMENT *elements,
     UINT element_count);
@@ -8515,4 +8439,5 @@
     IWineD3DVertexDeclaration **declaration,
     IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops,
     DWORD fvf);
 void __RPC_STUB IWineD3DDevice_CreateVertexDeclarationFromFVF_Stub(
@@ -8526,5 +8451,6 @@
     const struct wined3d_shader_signature *output_signature,
     IWineD3DVertexShader **shader,
-    IUnknown *parent);
+    IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops);
 void __RPC_STUB IWineD3DDevice_CreateVertexShader_Stub(
     IRpcStubBuffer* This,
@@ -8537,5 +8463,6 @@
     const struct wined3d_shader_signature *output_signature,
     IWineD3DPixelShader **shader,
-    IUnknown *parent);
+    IUnknown *parent,
+    const struct wined3d_parent_ops *parent_ops);
 void __RPC_STUB IWineD3DDevice_CreatePixelShader_Stub(
     IRpcStubBuffer* This,
@@ -8572,5 +8499,4 @@
 HRESULT STDMETHODCALLTYPE IWineD3DDevice_Uninit3D_Proxy(
     IWineD3DDevice* This,
-    ULONG (STDMETHODCALLTYPE * destroy_surface_callback)(IWineD3DSurface *pSurface),
     ULONG (STDMETHODCALLTYPE * destroy_swapchain_callback)(IWineD3DSwapChain *pSwapChain));
 void __RPC_STUB IWineD3DDevice_Uninit3D_Stub(
@@ -8822,17 +8748,17 @@
     PRPC_MESSAGE pRpcMessage,
     DWORD* pdwStubPhase);
-HRESULT STDMETHODCALLTYPE IWineD3DDevice_SetIndices_Proxy(
+HRESULT STDMETHODCALLTYPE IWineD3DDevice_SetIndexBuffer_Proxy(
     IWineD3DDevice* This,
     IWineD3DBuffer *index_buffer,
     WINED3DFORMAT format);
-void __RPC_STUB IWineD3DDevice_SetIndices_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
-HRESULT STDMETHODCALLTYPE IWineD3DDevice_GetIndices_Proxy(
+void __RPC_STUB IWineD3DDevice_SetIndexBuffer_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+HRESULT STDMETHODCALLTYPE IWineD3DDevice_GetIndexBuffer_Proxy(
     IWineD3DDevice* This,
     IWineD3DBuffer **index_buffer);
-void __RPC_STUB IWineD3DDevice_GetIndices_Stub(
+void __RPC_STUB IWineD3DDevice_GetIndexBuffer_Stub(
     IRpcStubBuffer* This,
     IRpcChannelBuffer* pRpcChannelBuffer,
@@ -9436,6 +9362,4 @@
 HRESULT STDMETHODCALLTYPE IWineD3DDevice_DrawIndexedPrimitive_Proxy(
     IWineD3DDevice* This,
-    UINT min_vertex_idx,
-    UINT vertex_count,
     UINT start_idx,
     UINT index_count);
@@ -9457,6 +9381,4 @@
 HRESULT STDMETHODCALLTYPE IWineD3DDevice_DrawIndexedPrimitiveUP_Proxy(
     IWineD3DDevice* This,
-    UINT min_vertex_idx,
-    UINT vertex_count,
     UINT index_count,
     const void *index_data,
@@ -9573,4 +9495,8 @@
 IWineD3DClipper * STDMETHODCALLTYPE  WineDirect3DCreateClipper(IUnknown *parent);
 
+void STDMETHODCALLTYPE  wined3d_mutex_lock(void);
+
+void STDMETHODCALLTYPE  wined3d_mutex_unlock(void);
+
 /* Begin additional prototypes for all interfaces */
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.idl	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.idl	(revision 23571)
@@ -151,37 +151,31 @@
 {
     WINED3DFMT_UNKNOWN,
-    WINED3DFMT_R8G8B8,
-    WINED3DFMT_A8R8G8B8,
-    WINED3DFMT_X8R8G8B8,
-    WINED3DFMT_R5G6B5,
-    WINED3DFMT_X1R5G5B5,
-    WINED3DFMT_A1R5G5B5,
-    WINED3DFMT_A4R4G4B4,
-    WINED3DFMT_R3G3B2,
-    WINED3DFMT_A8R3G3B2,
-    WINED3DFMT_X4R4G4B4,
-    WINED3DFMT_X8B8G8R8,
-    WINED3DFMT_A2R10G10B10,
-    WINED3DFMT_A8P8,
-    WINED3DFMT_P8,
-    WINED3DFMT_L8,
-    WINED3DFMT_A8L8,
-    WINED3DFMT_A4L4,
-    WINED3DFMT_L6V5U5,
-    WINED3DFMT_X8L8V8U8,
-    WINED3DFMT_W11V11U10,
-    WINED3DFMT_A2W10V10U10,
+    WINED3DFMT_B8G8R8_UNORM,
+    WINED3DFMT_B5G5R5X1_UNORM,
+    WINED3DFMT_B4G4R4A4_UNORM,
+    WINED3DFMT_B2G3R3_UNORM,
+    WINED3DFMT_B2G3R3A8_UNORM,
+    WINED3DFMT_B4G4R4X4_UNORM,
+    WINED3DFMT_R8G8B8X8_UNORM,
+    WINED3DFMT_B10G10R10A2_UNORM,
+    WINED3DFMT_P8_UINT_A8_UNORM,
+    WINED3DFMT_P8_UINT,
+    WINED3DFMT_L8_UNORM,
+    WINED3DFMT_L8A8_UNORM,
+    WINED3DFMT_L4A4_UNORM,
+    WINED3DFMT_R5G5_SNORM_L6_UNORM,
+    WINED3DFMT_R8G8_SNORM_L8X8_UNORM,
+    WINED3DFMT_R10G11B11_SNORM,
+    WINED3DFMT_R10G10B10_SNORM_A2_UNORM,
     WINED3DFMT_D16_LOCKABLE,
-    WINED3DFMT_D32,
-    WINED3DFMT_D15S1,
-    WINED3DFMT_D24S8,
-    WINED3DFMT_D24X8,
-    WINED3DFMT_D24X4S4,
-    WINED3DFMT_L16,
-    WINED3DFMT_D32F_LOCKABLE,
-    WINED3DFMT_D24FS8,
+    WINED3DFMT_D32_UNORM,
+    WINED3DFMT_S1_UINT_D15_UNORM,
+    WINED3DFMT_S8_UINT_D24_UNORM,
+    WINED3DFMT_X8D24_UNORM,
+    WINED3DFMT_S4X4_UINT_D24_UNORM,
+    WINED3DFMT_L16_UNORM,
+    WINED3DFMT_S8_UINT_D24_FLOAT,
     WINED3DFMT_VERTEXDATA,
-    WINED3DFMT_CxV8U8,
-    /* DXGI formats */
+    WINED3DFMT_R8G8_SNORM_Cx,
     WINED3DFMT_R32G32B32A32_TYPELESS,
     WINED3DFMT_R32G32B32A32_FLOAT,
@@ -2162,4 +2156,9 @@
 };
 
+struct wined3d_parent_ops
+{
+    void (*wined3d_object_destroyed)(void *parent);
+};
+
 interface IWineD3DResource;
 interface IWineD3DSurface;
@@ -2229,6 +2228,4 @@
     );
 }
-typedef ULONG (*D3DCB_DESTROYSURFACEFN)(IWineD3DSurface *pSurface);
-typedef ULONG (*D3DCB_DESTROYVOLUMEFN)(IWineD3DVolume *pVolume);
 typedef ULONG (*D3DCB_DESTROYSWAPCHAINFN)(IWineD3DSwapChain *pSwapChain);
 typedef HRESULT (*D3DCB_ENUMRESOURCES)(IWineD3DResource *resource, void *pData);
@@ -2637,7 +2634,4 @@
 interface IWineD3DTexture : IWineD3DBaseTexture
 {
-    void Destroy(
-        [in] D3DCB_DESTROYSURFACEFN destroy_surface_callback
-    );
     HRESULT GetLevelDesc(
         [in] UINT level,
@@ -2669,7 +2663,4 @@
 interface IWineD3DCubeTexture : IWineD3DBaseTexture
 {
-    void Destroy(
-        [in] D3DCB_DESTROYSURFACEFN destroy_surface_callback
-    );
     HRESULT GetLevelDesc(
         [in] UINT level,
@@ -2705,7 +2696,4 @@
 interface IWineD3DVolumeTexture : IWineD3DBaseTexture
 {
-    void Destroy(
-        [in] D3DCB_DESTROYVOLUMEFN destroy_volume_callback
-    );
     HRESULT GetLevelDesc(
         [in] UINT level,
@@ -2792,5 +2780,4 @@
 {
     void Destroy(
-        [in] D3DCB_DESTROYSURFACEFN destroy_surface_callback
     );
     HRESULT GetDevice(
@@ -2860,7 +2847,10 @@
 interface IWineD3DBaseShader : IWineD3DBase
 {
-    HRESULT SetFunction(
-        [in] const DWORD *function,
-        [in] const struct wined3d_shader_signature *output_signature
+    HRESULT GetDevice(
+        [out] IWineD3DDevice **device
+    );
+    HRESULT GetFunction(
+        [out] void *data,
+        [in, out] UINT *data_size
     );
 }
@@ -2873,11 +2863,4 @@
 interface IWineD3DVertexShader : IWineD3DBaseShader
 {
-    HRESULT GetDevice(
-        [out] IWineD3DDevice **device
-    );
-    HRESULT GetFunction(
-        [out] void *data,
-        [in, out] UINT *data_size
-    );
     HRESULT SetLocalConstantsF(
         [in] UINT start_idx,
@@ -2894,11 +2877,4 @@
 interface IWineD3DPixelShader : IWineD3DBaseShader
 {
-    HRESULT GetDevice(
-        [out] IWineD3DDevice **device
-    );
-    HRESULT GetFunction(
-        [out] void *data,
-        [in, out] UINT *data_size
-    );
 }
 
@@ -2914,4 +2890,5 @@
         [in] const void *data,
         [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops,
         [out] IWineD3DBuffer **buffer
     );
@@ -2922,5 +2899,6 @@
         [in] WINED3DPOOL pool,
         [out] IWineD3DBuffer **vertex_buffer,
-        [in] IUnknown *parent
+        [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops
     );
     HRESULT CreateIndexBuffer(
@@ -2929,5 +2907,6 @@
         [in] WINED3DPOOL pool,
         [out] IWineD3DBuffer **index_buffer,
-        [in] IUnknown *parent
+        [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops
     );
     HRESULT CreateStateBlock(
@@ -2949,5 +2928,6 @@
         [in] DWORD multisample_quality,
         [in] WINED3DSURFTYPE surface_type,
-        [in] IUnknown *parent
+        [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops
     );
     HRESULT CreateRendertargetView(
@@ -2964,5 +2944,6 @@
         [in] WINED3DPOOL pool,
         [out] IWineD3DTexture **texture,
-        [in] IUnknown *parent
+        [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops
     );
     HRESULT CreateVolumeTexture(
@@ -2975,5 +2956,6 @@
         [in] WINED3DPOOL pool,
         [out] IWineD3DVolumeTexture **texture,
-        [in] IUnknown *parent
+        [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops
     );
     HRESULT CreateVolume(
@@ -2985,5 +2967,6 @@
         [in] WINED3DPOOL pool,
         [out] IWineD3DVolume **volume,
-        [in] IUnknown *parent
+        [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops
     );
     HRESULT CreateCubeTexture(
@@ -2994,5 +2977,6 @@
         [in] WINED3DPOOL pool,
         [out] IWineD3DCubeTexture **texture,
-        [in] IUnknown *parent
+        [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops
     );
     HRESULT CreateQuery(
@@ -3010,4 +2994,5 @@
         [out] IWineD3DVertexDeclaration **declaration,
         [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops,
         [in] const WINED3DVERTEXELEMENT *elements,
         [in] UINT element_count
@@ -3016,4 +3001,5 @@
         [out] IWineD3DVertexDeclaration **declaration,
         [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops,
         [in] DWORD fvf
     );
@@ -3022,5 +3008,6 @@
         [in] const struct wined3d_shader_signature *output_signature,
         [out] IWineD3DVertexShader **shader,
-        [in] IUnknown *parent
+        [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops
     );
     HRESULT CreatePixelShader(
@@ -3028,5 +3015,6 @@
         [in] const struct wined3d_shader_signature *output_signature,
         [out] IWineD3DPixelShader **shader,
-        [in] IUnknown *parent
+        [in] IUnknown *parent,
+        [in] const struct wined3d_parent_ops *parent_ops
     );
     HRESULT CreatePalette(
@@ -3043,5 +3031,4 @@
     );
     HRESULT Uninit3D(
-        [in] D3DCB_DESTROYSURFACEFN destroy_surface_callback,
         [in] D3DCB_DESTROYSWAPCHAINFN destroy_swapchain_callback
     );
@@ -3144,9 +3131,9 @@
         [out] WINED3DGAMMARAMP *ramp
     );
-    HRESULT SetIndices(
+    HRESULT SetIndexBuffer(
         [in] IWineD3DBuffer *index_buffer,
         [in] WINED3DFORMAT format
     );
-    HRESULT GetIndices(
+    HRESULT GetIndexBuffer(
         [out] IWineD3DBuffer **index_buffer
     );
@@ -3417,6 +3404,4 @@
     );
     HRESULT DrawIndexedPrimitive(
-        [in] UINT min_vertex_idx,
-        [in] UINT vertex_count,
         [in] UINT start_idx,
         [in] UINT index_count
@@ -3428,6 +3413,4 @@
     );
     HRESULT DrawIndexedPrimitiveUP(
-        [in] UINT min_vertex_idx,
-        [in] UINT vertex_count,
         [in] UINT index_count,
         [in] const void *index_data,
@@ -3487,2 +3470,4 @@
 IWineD3D *WineDirect3DCreate(UINT dxVersion, IUnknown *parent);
 IWineD3DClipper *WineDirect3DCreateClipper(IUnknown *parent);
+void wined3d_mutex_lock(void);
+void wined3d_mutex_unlock(void);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wingdi.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wingdi.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wingdi.h	(revision 23571)
@@ -160,4 +160,7 @@
 typedef LONG LCSCSTYPE;
 typedef LONG LCSGAMUTMATCH;
+
+#define LCS_sRGB                    0x73524742  /* 'sRGB' */
+#define LCS_WINDOWS_COLOR_SPACE     0x57696e20  /* 'Win ' */
 
 #define LCS_CALIBRATED_RGB    0x00000000L
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wininet.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wininet.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wininet.h	(revision 23571)
@@ -380,4 +380,17 @@
 DECL_WINELIB_TYPE_AW(INTERNET_PER_CONN_OPTION_LIST)
 DECL_WINELIB_TYPE_AW(LPINTERNET_PER_CONN_OPTION_LIST)
+
+typedef struct _INTERNET_DIAGNOSTIC_SOCKET_INFO
+{
+    DWORD_PTR Socket;
+    DWORD     SourcePort;
+    DWORD     DestPort;
+    DWORD     Flags;
+} INTERNET_DIAGNOSTIC_SOCKET_INFO, *LPINTERNET_DIAGNOSTIC_SOCKET_INFO;
+
+#define IDSI_FLAG_KEEP_ALIVE 0x00000001
+#define IDSI_FLAG_SECURE     0x00000002
+#define IDSI_FLAG_PROXY      0x00000004
+#define IDSI_FLAG_TUNNEL     0x00000008
 
 BOOLAPI InternetTimeFromSystemTimeA(CONST SYSTEMTIME *,DWORD ,LPSTR ,DWORD);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winsafer.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winsafer.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winsafer.h	(revision 23571)
@@ -53,4 +53,14 @@
 WINADVAPI BOOL WINAPI SaferCreateLevel(DWORD,DWORD,DWORD,SAFER_LEVEL_HANDLE*,LPVOID);
 
+typedef enum _SAFER_POLICY_INFO_CLASS {
+    SaferPolicyLevelList = 1,
+    SaferPolicyEnableTransparentEnforcement,
+    SaferPolicyDefaultLevel,
+    SaferPolicyEvaluateUserScope,
+    SaferPolicyScopeFlags
+} SAFER_POLICY_INFO_CLASS;
+
+WINADVAPI BOOL WINAPI SaferGetPolicyInformation(DWORD,SAFER_POLICY_INFO_CLASS,DWORD,PVOID,PDWORD,LPVOID);
+
 #ifdef __cplusplus
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winsock.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winsock.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winsock.h	(revision 23571)
@@ -276,4 +276,5 @@
 #define IPPROTO_UDP                17
 #define IPPROTO_IDP                22
+#define IPPROTO_IPV6               41
 #define IPPROTO_ND                 77
 #define IPPROTO_RAW                255
@@ -287,4 +288,5 @@
 #define WS_IPPROTO_UDP             17
 #define WS_IPPROTO_IDP             22
+#define WS_IPPROTO_IPV6            41
 #define WS_IPPROTO_ND              77
 #define WS_IPPROTO_RAW             255
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winternl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winternl.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winternl.h	(revision 23571)
@@ -1197,17 +1197,15 @@
 typedef struct _SYSTEM_BASIC_INFORMATION {
 #ifdef __WINESRC__
-    DWORD dwUnknown1;
-    ULONG uKeMaximumIncrement;
-    ULONG uPageSize;
-    ULONG uMmNumberOfPhysicalPages;
-    ULONG uMmLowestPhysicalPage;
-    ULONG uMmHighestPhysicalPage;
-    ULONG uAllocationGranularity;
-    PVOID pLowestUserAddress;
-    PVOID pMmHighestUserAddress;
-    ULONG uKeActiveProcessors;
-    BYTE bKeNumberProcessors;
-    BYTE bUnknown2;
-    WORD wUnknown3;
+    DWORD     unknown;
+    ULONG     KeMaximumIncrement;
+    ULONG     PageSize;
+    ULONG     MmNumberOfPhysicalPages;
+    ULONG     MmLowestPhysicalPage;
+    ULONG     MmHighestPhysicalPage;
+    ULONG_PTR AllocationGranularity;
+    PVOID     LowestUserAddress;
+    PVOID     HighestUserAddress;
+    ULONG_PTR ActiveProcessorsAffinityMask;
+    BYTE      NumberOfProcessors;
 #else
     BYTE Reserved1[24];
@@ -1270,10 +1268,4 @@
 
 typedef struct _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION {
-#ifdef __WINESRC__
-    LARGE_INTEGER liIdleTime;
-    LARGE_INTEGER liKernelTime;
-    LARGE_INTEGER liUserTime;
-    DWORD dwSpare[5];
-#else
     LARGE_INTEGER IdleTime;
     LARGE_INTEGER KernelTime;
@@ -1281,5 +1273,4 @@
     LARGE_INTEGER Reserved1[2];
     ULONG Reserved2;
-#endif
 } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION, *PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
 
@@ -1999,5 +1990,5 @@
 NTSYSAPI NTSTATUS  WINAPI LdrGetDllHandle(LPCWSTR, ULONG, const UNICODE_STRING*, HMODULE*);
 NTSYSAPI NTSTATUS  WINAPI LdrGetProcedureAddress(HMODULE, const ANSI_STRING*, ULONG, void**);
-NTSYSAPI void      WINAPI LdrInitializeThunk(ULONG,ULONG,ULONG,ULONG);
+NTSYSAPI void      WINAPI LdrInitializeThunk(void*,ULONG_PTR,ULONG_PTR,ULONG_PTR);
 NTSYSAPI NTSTATUS  WINAPI LdrLoadDll(LPCWSTR, DWORD, const UNICODE_STRING*, HMODULE*);
 NTSYSAPI NTSTATUS  WINAPI LdrLockLoaderLock(ULONG,ULONG*,ULONG*);
@@ -2023,4 +2014,5 @@
 NTSYSAPI NTSTATUS  WINAPI NtCallbackReturn(PVOID,ULONG,NTSTATUS);
 NTSYSAPI NTSTATUS  WINAPI NtCancelIoFile(HANDLE,PIO_STATUS_BLOCK);
+NTSYSAPI NTSTATUS  WINAPI NtCancelIoFileEx(HANDLE,PIO_STATUS_BLOCK,PIO_STATUS_BLOCK);
 NTSYSAPI NTSTATUS  WINAPI NtCancelTimer(HANDLE, BOOLEAN*);
 NTSYSAPI NTSTATUS  WINAPI NtClearEvent(HANDLE);
@@ -2273,6 +2265,4 @@
 NTSYSAPI DWORD     WINAPI RtlComputeCrc32(DWORD,const BYTE*,INT);
 NTSYSAPI NTSTATUS  WINAPI RtlConvertSidToUnicodeString(PUNICODE_STRING,PSID,BOOLEAN);
-NTSYSAPI LONGLONG  WINAPI RtlConvertLongToLargeInteger(LONG);
-NTSYSAPI ULONGLONG WINAPI RtlConvertUlongToLargeInteger(ULONG);
 NTSYSAPI void      WINAPI RtlCopyLuid(PLUID,const LUID*);
 NTSYSAPI void      WINAPI RtlCopyLuidAndAttributesArray(ULONG,const LUID_AND_ATTRIBUTES*,PLUID_AND_ATTRIBUTES);
@@ -2321,7 +2311,4 @@
 NTSYSAPI NTSTATUS  WINAPI RtlDuplicateUnicodeString(int,const UNICODE_STRING*,UNICODE_STRING*);
 NTSYSAPI NTSTATUS  WINAPI RtlEmptyAtomTable(RTL_ATOM_TABLE,BOOLEAN);
-NTSYSAPI LONGLONG  WINAPI RtlEnlargedIntegerMultiply(INT,INT);
-NTSYSAPI ULONGLONG WINAPI RtlEnlargedUnsignedMultiply(UINT,UINT);
-NTSYSAPI UINT      WINAPI RtlEnlargedUnsignedDivide(ULONGLONG,UINT,UINT *);
 NTSYSAPI NTSTATUS  WINAPI RtlEnterCriticalSection(RTL_CRITICAL_SECTION *);
 NTSYSAPI void      WINAPI RtlEraseUnicodeString(UNICODE_STRING*);
@@ -2335,7 +2322,4 @@
 NTSYSAPI void      DECLSPEC_NORETURN WINAPI RtlExitUserThread(ULONG);
 NTSYSAPI NTSTATUS  WINAPI RtlExpandEnvironmentStrings_U(PCWSTR, const UNICODE_STRING*, UNICODE_STRING*, ULONG*);
-NTSYSAPI LONGLONG  WINAPI RtlExtendedMagicDivide(LONGLONG,LONGLONG,INT);
-NTSYSAPI LONGLONG  WINAPI RtlExtendedIntegerMultiply(LONGLONG,INT);
-NTSYSAPI LONGLONG  WINAPI RtlExtendedLargeIntegerDivide(LONGLONG,INT,INT *);
 NTSYSAPI NTSTATUS  WINAPI RtlFindActivationContextSectionString(ULONG,const GUID*,ULONG,const UNICODE_STRING*,PVOID);
 NTSYSAPI NTSTATUS  WINAPI RtlFindCharInUnicodeString(int,const UNICODE_STRING*,const UNICODE_STRING*,USHORT*);
@@ -2410,12 +2394,4 @@
 NTSYSAPI BOOLEAN   WINAPI RtlIsValidHandle(const RTL_HANDLE_TABLE *, const RTL_HANDLE *);
 NTSYSAPI BOOLEAN   WINAPI RtlIsValidIndexHandle(const RTL_HANDLE_TABLE *, ULONG Index, RTL_HANDLE **);
-NTSYSAPI LONGLONG  WINAPI RtlLargeIntegerAdd(LONGLONG,LONGLONG);
-NTSYSAPI LONGLONG  WINAPI RtlLargeIntegerArithmeticShift(LONGLONG,INT);
-NTSYSAPI ULONGLONG WINAPI RtlLargeIntegerDivide( ULONGLONG,ULONGLONG,ULONGLONG *);
-NTSYSAPI LONGLONG  WINAPI RtlLargeIntegerNegate(LONGLONG);
-NTSYSAPI LONGLONG  WINAPI RtlLargeIntegerShiftLeft(LONGLONG,INT);
-NTSYSAPI LONGLONG  WINAPI RtlLargeIntegerShiftRight(LONGLONG,INT);
-NTSYSAPI LONGLONG  WINAPI RtlLargeIntegerSubtract(LONGLONG,LONGLONG);
-NTSYSAPI NTSTATUS  WINAPI RtlLargeIntegerToChar(const ULONGLONG *,ULONG,ULONG,PCHAR);
 NTSYSAPI NTSTATUS  WINAPI RtlLeaveCriticalSection(RTL_CRITICAL_SECTION *);
 NTSYSAPI DWORD     WINAPI RtlLengthRequiredSid(DWORD);
@@ -2532,4 +2508,25 @@
 NTSYSAPI NTSTATUS  WINAPI vDbgPrintExWithPrefix(LPCSTR,ULONG,ULONG,LPCSTR,__ms_va_list);
 
+/* 32-bit only functions */
+
+#ifndef _WIN64
+NTSYSAPI LONGLONG  WINAPI RtlConvertLongToLargeInteger(LONG);
+NTSYSAPI ULONGLONG WINAPI RtlConvertUlongToLargeInteger(ULONG);
+NTSYSAPI LONGLONG  WINAPI RtlEnlargedIntegerMultiply(INT,INT);
+NTSYSAPI ULONGLONG WINAPI RtlEnlargedUnsignedMultiply(UINT,UINT);
+NTSYSAPI UINT      WINAPI RtlEnlargedUnsignedDivide(ULONGLONG,UINT,UINT *);
+NTSYSAPI LONGLONG  WINAPI RtlExtendedMagicDivide(LONGLONG,LONGLONG,INT);
+NTSYSAPI LONGLONG  WINAPI RtlExtendedIntegerMultiply(LONGLONG,INT);
+NTSYSAPI LONGLONG  WINAPI RtlExtendedLargeIntegerDivide(LONGLONG,INT,INT *);
+NTSYSAPI LONGLONG  WINAPI RtlLargeIntegerAdd(LONGLONG,LONGLONG);
+NTSYSAPI LONGLONG  WINAPI RtlLargeIntegerArithmeticShift(LONGLONG,INT);
+NTSYSAPI ULONGLONG WINAPI RtlLargeIntegerDivide( ULONGLONG,ULONGLONG,ULONGLONG *);
+NTSYSAPI LONGLONG  WINAPI RtlLargeIntegerNegate(LONGLONG);
+NTSYSAPI LONGLONG  WINAPI RtlLargeIntegerShiftLeft(LONGLONG,INT);
+NTSYSAPI LONGLONG  WINAPI RtlLargeIntegerShiftRight(LONGLONG,INT);
+NTSYSAPI LONGLONG  WINAPI RtlLargeIntegerSubtract(LONGLONG,LONGLONG);
+NTSYSAPI NTSTATUS  WINAPI RtlLargeIntegerToChar(const ULONGLONG *,ULONG,ULONG,PCHAR);
+#endif
+
 /* Wine internal functions */
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winuser.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winuser.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winuser.h	(revision 23571)
@@ -2832,4 +2832,6 @@
 #define KEYEVENTF_EXTENDEDKEY        0x0001
 #define KEYEVENTF_KEYUP              0x0002
+#define KEYEVENTF_UNICODE            0x0004
+#define KEYEVENTF_SCANCODE           0x0008
 
   /* mouse_event flags */
@@ -3823,5 +3825,6 @@
 
 /*                          0xE6       OEM specific */
-/*                          0xE7-0xE8  Unassigned */
+#define VK_PACKET           0xE7
+/*                          0xE8       Unassigned */
 /*                          0xE9-0xF5  OEM specific */
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wtypes.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wtypes.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wtypes.h	(revision 23571)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.27 from ../../include/wtypes.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.30 from ../../include/wtypes.idl - Do not edit ***/
 
 #include <rpc.h>
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/config.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/config.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/config.c	(revision 23571)
@@ -147,182 +147,29 @@
 }
 
-/* initialize the server directory value */
-static void init_server_dir( dev_t dev, ino_t ino )
-{
-    char *p;
-#ifdef HAVE_GETUID
-    const unsigned int uid = getuid();
-#else
-    const unsigned int uid = 0;
-#endif
-
-    server_dir = xmalloc( sizeof(server_root_prefix) + 32 + sizeof(server_dir_prefix) +
-                          2*sizeof(dev) + 2*sizeof(ino) );
-    sprintf( server_dir, "%s%u%s", server_root_prefix, uid, server_dir_prefix );
-    p = server_dir + strlen(server_dir);
-
-    if (sizeof(dev) > sizeof(unsigned long) && dev > ~0UL)
-        p += sprintf( p, "%lx%08lx-", (unsigned long)((unsigned long long)dev >> 32), (unsigned long)dev );
-    else
-        p += sprintf( p, "%lx-", (unsigned long)dev );
-
-    if (sizeof(ino) > sizeof(unsigned long) && ino > ~0UL)
-        sprintf( p, "%lx%08lx", (unsigned long)((unsigned long long)ino >> 32), (unsigned long)ino );
-    else
-        sprintf( p, "%lx", (unsigned long)ino );
-}
-
-/* retrieve the default dll dir */
-const char *get_dlldir( const char **default_dlldir )
-{
-    *default_dlldir = DLLDIR;
-    return dlldir;
-}
-
-/* initialize all the paths values */
-static void init_paths(void)
-{
-    struct stat st;
-
-    const char *home = getenv( "HOME" );
-    const char *user = NULL;
-    const char *prefix = getenv( "WINEPREFIX" );
-
-#ifdef HAVE_GETPWUID
-    char uid_str[32];
-    struct passwd *pwd = getpwuid( getuid() );
-
-    if (pwd)
-    {
-        user = pwd->pw_name;
-        if (!home) home = pwd->pw_dir;
-    }
-    if (!user)
-    {
-        sprintf( uid_str, "%lu", (unsigned long)getuid() );
-        user = uid_str;
-    }
-#else  /* HAVE_GETPWUID */
-    if (!(user = getenv( "USER" )))
-        fatal_error( "cannot determine your user name, set the USER environment variable\n" );
-#endif  /* HAVE_GETPWUID */
-    user_name = xstrdup( user );
-
-    /* build config_dir */
-
-    if (prefix)
-    {
-        config_dir = xstrdup( prefix );
-        remove_trailing_slashes( config_dir );
-        if (config_dir[0] != '/')
-            fatal_error( "invalid directory %s in WINEPREFIX: not an absolute path\n", prefix );
-        if (stat( config_dir, &st ) == -1)
-        {
-            if (errno == ENOENT) return;  /* will be created later on */
-            fatal_perror( "cannot open %s as specified in WINEPREFIX", config_dir );
-        }
-    }
-    else
-    {
-        if (!home) fatal_error( "could not determine your home directory\n" );
-        if (home[0] != '/') fatal_error( "your home directory %s is not an absolute path\n", home );
-        config_dir = xmalloc( strlen(home) + sizeof(server_config_dir) );
-        strcpy( config_dir, home );
-        remove_trailing_slashes( config_dir );
-        strcat( config_dir, server_config_dir );
-        if (stat( config_dir, &st ) == -1)
-        {
-            if (errno == ENOENT) return;  /* will be created later on */
-            fatal_perror( "cannot open %s", config_dir );
-        }
-    }
-    if (!S_ISDIR(st.st_mode)) fatal_error( "%s is not a directory\n", config_dir );
-#ifdef HAVE_GETUID
-    if (st.st_uid != getuid()) fatal_error( "%s is not owned by you\n", config_dir );
-#endif
-
-    init_server_dir( st.st_dev, st.st_ino );
-}
-
-/* check if basedir is a valid build dir by checking for wineserver and ntdll */
-/* helper for running_from_build_dir */
-static inline int is_valid_build_dir( char *basedir, int baselen )
-{
-    struct stat st;
-
-    strcpy( basedir + baselen, "/server/wineserver" );
-    if (stat( basedir, &st ) == -1) return 0;  /* no wineserver found */
-    /* check for ntdll too to make sure */
-    strcpy( basedir + baselen, "/dlls/ntdll/ntdll.dll.so" );
-    if (stat( basedir, &st ) == -1) return 0;  /* no ntdll found */
-
-    basedir[baselen] = 0;
-    return 1;
-}
-
-/* check if we are running from the build directory */
-static char *running_from_build_dir( const char *basedir, const char *bindir )
-{
-    struct stat st;
-    const char *p;
-    char *path;
-    int res;
-
-    if (!(path = build_path( bindir, "wineserver" ))) return NULL;
-    res = stat( path, &st );
-    free( path );
-    if (res != -1) return NULL;  /* the real bindir is valid */
-
-    /* remove last component from basedir */
-    p = basedir + strlen(basedir) - 1;
-    while (p > basedir && *p == '/') p--;
-    while (p > basedir && *p != '/') p--;
-    if (p == basedir) return NULL;
-    path = xmalloc( p - basedir + sizeof("/dlls/ntdll/ntdll.dll.so") );
-    memcpy( path, basedir, p - basedir );
-
-    if (!is_valid_build_dir( path, p - basedir ))
-    {
-        /* remove another component */
-        while (p > basedir && *p == '/') p--;
-        while (p > basedir && *p != '/') p--;
-        if (p == basedir || !is_valid_build_dir( path, p - basedir ))
-        {
-            free( path );
-            return NULL;
-        }
-    }
-    return path;
-}
-
-/* initialize the argv0 path */
-void wine_init_argv0_path( const char *argv0 )
-{
-    size_t size, len;
-    const char *p, *basename;
-    char *cwd, *libdir;
-
-    if (!(p = strrchr( argv0, '/' )))
-        basename = argv0;
-    else
-        basename = p + 1;
-
-    argv0_name = xstrdup( basename );
-
-    if ((libdir = get_runtime_libdir()))
-    {
-        bindir = build_path( libdir, LIB_TO_BINDIR );
-        if ((build_dir = running_from_build_dir( libdir, bindir )))
-        {
-            free( libdir );
-            goto in_build_dir;
-        }
-        dlldir = build_path( libdir, LIB_TO_DLLDIR );
-        datadir = build_path( libdir, LIB_TO_DATADIR );
-        free( libdir );
-        return;
-    }
-
-    if (!p) return;  /* if argv0 doesn't contain a path, don't store anything */
+/* return the directory that contains the main exe at run-time */
+static char *get_runtime_bindir( const char *argv0 )
+{
+    char *p, *bindir, *cwd;
+    size_t len, size;
+
+#ifdef linux
+    for (size = 256; ; size *= 2)
+    {
+        int ret;
+        if (!(bindir = malloc( size ))) break;
+        if ((ret = readlink( "/proc/self/exe", bindir, size )) == -1) break;
+        if (ret != size)
+        {
+            if (!(p = memrchr( bindir, '/', ret ))) break;
+            if (p == bindir) p++;
+            *p = 0;
+            return bindir;
+        }
+        free( bindir );
+    }
+    free( bindir );
+#endif
+
+    if (!(p = strrchr( argv0, '/' ))) return NULL;
 
     len = p - argv0;
@@ -340,5 +187,5 @@
         for (size = 256 + len; ; size *= 2)
         {
-            if (!(cwd = malloc( size ))) return;
+            if (!(cwd = malloc( size ))) return NULL;
             if (getcwd( cwd, size - len ))
             {
@@ -351,19 +198,199 @@
             }
             free( cwd );
-            if (errno != ERANGE) return;
-        }
-    }
-
-    if ((build_dir = running_from_build_dir( bindir, bindir ))) goto in_build_dir;
-
-    dlldir = build_path( bindir, BIN_TO_DLLDIR );
-    datadir = build_path( bindir, BIN_TO_DATADIR );
-    return;
-
-in_build_dir:
-    free( bindir );
-    free( argv0_name );
-    bindir = NULL;
-    argv0_name = build_path( "loader/", basename );
+            if (errno != ERANGE) return NULL;
+        }
+    }
+    return bindir;
+}
+
+/* initialize the server directory value */
+static void init_server_dir( dev_t dev, ino_t ino )
+{
+    char *p;
+#ifdef HAVE_GETUID
+    const unsigned int uid = getuid();
+#else
+    const unsigned int uid = 0;
+#endif
+
+    server_dir = xmalloc( sizeof(server_root_prefix) + 32 + sizeof(server_dir_prefix) +
+                          2*sizeof(dev) + 2*sizeof(ino) );
+    sprintf( server_dir, "%s%u%s", server_root_prefix, uid, server_dir_prefix );
+    p = server_dir + strlen(server_dir);
+
+    if (sizeof(dev) > sizeof(unsigned long) && dev > ~0UL)
+        p += sprintf( p, "%lx%08lx-", (unsigned long)((unsigned long long)dev >> 32), (unsigned long)dev );
+    else
+        p += sprintf( p, "%lx-", (unsigned long)dev );
+
+    if (sizeof(ino) > sizeof(unsigned long) && ino > ~0UL)
+        sprintf( p, "%lx%08lx", (unsigned long)((unsigned long long)ino >> 32), (unsigned long)ino );
+    else
+        sprintf( p, "%lx", (unsigned long)ino );
+}
+
+/* retrieve the default dll dir */
+const char *get_dlldir( const char **default_dlldir )
+{
+    *default_dlldir = DLLDIR;
+    return dlldir;
+}
+
+/* initialize all the paths values */
+static void init_paths(void)
+{
+    struct stat st;
+
+    const char *home = getenv( "HOME" );
+    const char *user = NULL;
+    const char *prefix = getenv( "WINEPREFIX" );
+
+#ifdef HAVE_GETPWUID
+    char uid_str[32];
+    struct passwd *pwd = getpwuid( getuid() );
+
+    if (pwd)
+    {
+        user = pwd->pw_name;
+        if (!home) home = pwd->pw_dir;
+    }
+    if (!user)
+    {
+        sprintf( uid_str, "%lu", (unsigned long)getuid() );
+        user = uid_str;
+    }
+#else  /* HAVE_GETPWUID */
+    if (!(user = getenv( "USER" )))
+        fatal_error( "cannot determine your user name, set the USER environment variable\n" );
+#endif  /* HAVE_GETPWUID */
+    user_name = xstrdup( user );
+
+    /* build config_dir */
+
+    if (prefix)
+    {
+        config_dir = xstrdup( prefix );
+        remove_trailing_slashes( config_dir );
+        if (config_dir[0] != '/')
+            fatal_error( "invalid directory %s in WINEPREFIX: not an absolute path\n", prefix );
+        if (stat( config_dir, &st ) == -1)
+        {
+            if (errno == ENOENT) return;  /* will be created later on */
+            fatal_perror( "cannot open %s as specified in WINEPREFIX", config_dir );
+        }
+    }
+    else
+    {
+        if (!home) fatal_error( "could not determine your home directory\n" );
+        if (home[0] != '/') fatal_error( "your home directory %s is not an absolute path\n", home );
+        config_dir = xmalloc( strlen(home) + sizeof(server_config_dir) );
+        strcpy( config_dir, home );
+        remove_trailing_slashes( config_dir );
+        strcat( config_dir, server_config_dir );
+        if (stat( config_dir, &st ) == -1)
+        {
+            if (errno == ENOENT) return;  /* will be created later on */
+            fatal_perror( "cannot open %s", config_dir );
+        }
+    }
+    if (!S_ISDIR(st.st_mode)) fatal_error( "%s is not a directory\n", config_dir );
+#ifdef HAVE_GETUID
+    if (st.st_uid != getuid()) fatal_error( "%s is not owned by you\n", config_dir );
+#endif
+
+    init_server_dir( st.st_dev, st.st_ino );
+}
+
+/* check if bindir is valid by checking for wineserver */
+static int is_valid_bindir( const char *bindir )
+{
+    struct stat st;
+    char *path = build_path( bindir, "wineserver" );
+    int ret = (stat( path, &st ) != -1);
+    free( path );
+    return ret;
+}
+
+/* check if basedir is a valid build dir by checking for wineserver and ntdll */
+/* helper for running_from_build_dir */
+static inline int is_valid_build_dir( char *basedir, int baselen )
+{
+    struct stat st;
+
+    strcpy( basedir + baselen, "/server/wineserver" );
+    if (stat( basedir, &st ) == -1) return 0;  /* no wineserver found */
+    /* check for ntdll too to make sure */
+    strcpy( basedir + baselen, "/dlls/ntdll/ntdll.dll.so" );
+    if (stat( basedir, &st ) == -1) return 0;  /* no ntdll found */
+
+    basedir[baselen] = 0;
+    return 1;
+}
+
+/* check if we are running from the build directory */
+static char *running_from_build_dir( const char *basedir )
+{
+    const char *p;
+    char *path;
+
+    /* remove last component from basedir */
+    p = basedir + strlen(basedir) - 1;
+    while (p > basedir && *p == '/') p--;
+    while (p > basedir && *p != '/') p--;
+    if (p == basedir) return NULL;
+    path = xmalloc( p - basedir + sizeof("/dlls/ntdll/ntdll.dll.so") );
+    memcpy( path, basedir, p - basedir );
+
+    if (!is_valid_build_dir( path, p - basedir ))
+    {
+        /* remove another component */
+        while (p > basedir && *p == '/') p--;
+        while (p > basedir && *p != '/') p--;
+        if (p == basedir || !is_valid_build_dir( path, p - basedir ))
+        {
+            free( path );
+            return NULL;
+        }
+    }
+    return path;
+}
+
+/* initialize the argv0 path */
+void wine_init_argv0_path( const char *argv0 )
+{
+    const char *basename;
+    char *libdir;
+
+    if (!(basename = strrchr( argv0, '/' ))) basename = argv0;
+    else basename++;
+
+    bindir = get_runtime_bindir( argv0 );
+    libdir = get_runtime_libdir();
+
+    if (bindir && !is_valid_bindir( bindir ))
+    {
+        build_dir = running_from_build_dir( bindir );
+        free( bindir );
+        bindir = NULL;
+    }
+    if (libdir && !bindir && !build_dir)
+    {
+        build_dir = running_from_build_dir( libdir );
+        if (!build_dir) bindir = build_path( libdir, LIB_TO_BINDIR );
+    }
+
+    if (build_dir)
+    {
+        argv0_name = build_path( "loader/", basename );
+    }
+    else
+    {
+        if (libdir) dlldir = build_path( libdir, LIB_TO_DLLDIR );
+        else if (bindir) dlldir = build_path( bindir, BIN_TO_DLLDIR );
+
+        if (bindir) datadir = build_path( bindir, BIN_TO_DATADIR );
+        argv0_name = xstrdup( basename );
+    }
+    free( libdir );
 }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/loader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/loader.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/loader.c	(revision 23571)
@@ -159,10 +159,52 @@
 }
 
+/* check if the library is the correct architecture */
+/* only returns false for a valid library of the wrong arch */
+static int check_library_arch( int fd )
+{
+#ifdef __APPLE__
+    struct  /* Mach-O header */
+    {
+        unsigned int magic;
+        unsigned int cputype;
+    } header;
+
+    if (read( fd, &header, sizeof(header) ) != sizeof(header)) return 1;
+    if (header.magic != 0xfeedface) return 1;
+    if (sizeof(void *) == sizeof(int)) return !(header.cputype >> 24);
+    else return (header.cputype >> 24) == 1; /* CPU_ARCH_ABI64 */
+#else
+    struct  /* ELF header */
+    {
+        unsigned char magic[4];
+        unsigned char class;
+        unsigned char data;
+        unsigned char version;
+    } header;
+
+    if (read( fd, &header, sizeof(header) ) != sizeof(header)) return 1;
+    if (memcmp( header.magic, "\177ELF", 4 )) return 1;
+    if (header.version != 1 /* EV_CURRENT */) return 1;
+#ifdef WORDS_BIGENDIAN
+    if (header.data != 2 /* ELFDATA2MSB */) return 1;
+#else
+    if (header.data != 1 /* ELFDATA2LSB */) return 1;
+#endif
+    if (sizeof(void *) == sizeof(int)) return header.class == 1; /* ELFCLASS32 */
+    else return header.class == 2; /* ELFCLASS64 */
+#endif
+}
+
 /* check if a given file can be opened */
 static inline int file_exists( const char *name )
 {
+    int ret = 0;
     int fd = open( name, O_RDONLY );
-    if (fd != -1) close( fd );
-    return (fd != -1);
+    if (fd != -1)
+    {
+        ret = check_library_arch( fd );
+        close( fd );
+    }
+    return ret;
 }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/version.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/version.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/version.c	(revision 23571)
@@ -1,1 +1,1 @@
-const char wine_build[] = "wine-1.1.27";
+const char wine_build[] = "wine-1.1.30";
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/arb_program_shader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/arb_program_shader.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/arb_program_shader.c	(revision 23571)
@@ -101,11 +101,4 @@
 /* ARB_program_shader private data */
 
-struct loop_control
-{
-    unsigned int count;
-    unsigned int start;
-    int step;
-};
-
 struct control_frame
 {
@@ -125,5 +118,5 @@
         unsigned int                ifc_no;
     };
-    struct loop_control             loop_control;
+    struct wined3d_shader_loop_control loop_control;
     BOOL                            had_else;
 };
@@ -142,5 +135,6 @@
 {
     struct ps_compile_args          super;
-    DWORD                           bools; /* WORD is enough, use DWORD for alignment */
+    WORD                            bools;
+    WORD                            clip;  /* only a boolean, use a WORD for alignment */
     unsigned char                   loop_ctrl[MAX_CONST_I][3];
 };
@@ -282,8 +276,7 @@
  ********************************************************/
 
-/** 
- * Loads floating point constants into the currently set ARB_vertex/fragment_program.
+/* Loads floating point constants into the currently set ARB_vertex/fragment_program.
  * When constant_list == NULL, it will load all the constants.
- *  
+ *
  * @target_type should be either GL_VERTEX_PROGRAM_ARB (for vertex shaders)
  *  or GL_FRAGMENT_PROGRAM_ARB (for pixel shaders)
@@ -294,8 +287,9 @@
 {
     local_constant* lconst;
-    DWORD i = 0, j;
+    DWORD i, j;
     unsigned int ret;
 
-    if (TRACE_ON(d3d_shader)) {
+    if (TRACE_ON(d3d_constants))
+    {
         for(i = 0; i < max_constants; i++) {
             if(!dirty_consts[i]) continue;
@@ -305,4 +299,7 @@
         }
     }
+
+    i = 0;
+
     /* In 1.X pixel shaders constants are implicitly clamped in the range [-1;1] */
     if (target_type == GL_FRAGMENT_PROGRAM_ARB && This->baseShader.reg_maps.shader_version.major == 1)
@@ -546,6 +543,6 @@
 /**
  * Loads the app-supplied constants into the currently set ARB_[vertex/fragment]_programs.
- * 
- * We only support float constants in ARB at the moment, so don't 
+ *
+ * We only support float constants in ARB at the moment, so don't
  * worry about the Integers or Booleans
  */
@@ -632,4 +629,5 @@
     unsigned max_constantsF;
     const local_constant *lconst;
+    DWORD map;
 
     /* In pixel shaders, all private constants are program local, we don't need anything
@@ -675,18 +673,19 @@
     }
 
-    for(i = 0; i < This->baseShader.limits.temporary; i++) {
-        if (reg_maps->temporary[i])
-            shader_addline(buffer, "TEMP R%u;\n", i);
-    }
-
-    for (i = 0; i < This->baseShader.limits.address; i++) {
-        if (reg_maps->address[i])
-            shader_addline(buffer, "ADDRESS A%d;\n", i);
-    }
-
-    if(pshader && reg_maps->shader_version.major == 1 && reg_maps->shader_version.minor <= 3) {
-        for(i = 0; i < This->baseShader.limits.texcoord; i++) {
-            if (reg_maps->texcoord[i] && pshader)
-                shader_addline(buffer,"TEMP T%u;\n", i);
+    for (i = 0, map = reg_maps->temporary; map; map >>= 1, ++i)
+    {
+        if (map & 1) shader_addline(buffer, "TEMP R%u;\n", i);
+    }
+
+    for (i = 0, map = reg_maps->address; map; map >>= 1, ++i)
+    {
+        if (map & 1) shader_addline(buffer, "ADDRESS A%u;\n", i);
+    }
+
+    if (pshader && reg_maps->shader_version.major == 1 && reg_maps->shader_version.minor <= 3)
+    {
+        for (i = 0, map = reg_maps->texcoord; map; map >>= 1, ++i)
+        {
+            if (map & 1) shader_addline(buffer, "TEMP T%u;\n", i);
         }
     }
@@ -1262,6 +1261,6 @@
     if (flags & TEX_DERIV)
     {
-        if(flags & TEX_PROJ) FIXME("Projected texture sampling with custom derivates\n");
-        if(flags & TEX_BIAS) FIXME("Biased texture sampling with custom derivates\n");
+        if(flags & TEX_PROJ) FIXME("Projected texture sampling with custom derivatives\n");
+        if(flags & TEX_BIAS) FIXME("Biased texture sampling with custom derivatives\n");
         shader_addline(buffer, "TXD%s %s, %s, %s, %s, texture[%u], %s;\n", mod, dst_str, coord_reg,
                        dsx, dsy,sampler_idx, tex_type);
@@ -2038,5 +2037,5 @@
     char dst_str[50];
     char src0_name[50];
-    char dst_reg[8];
+    char dst_reg[50];
     BOOL is_color;
 
@@ -2081,5 +2080,5 @@
     char src0_name[50];
     char src1_name[50];
-    char dst_reg[8];
+    char dst_reg[50];
     BOOL is_color;
 
@@ -3010,4 +3009,6 @@
 {
     GLuint program_id = 0;
+    GLint pos;
+
     const char *blt_vprogram =
         "!!ARBvp1.0\n"
@@ -3020,12 +3021,22 @@
     GL_EXTCALL(glGenProgramsARB(1, &program_id));
     GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, program_id));
-    GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(blt_vprogram), blt_vprogram));
-
-    if (glGetError() == GL_INVALID_OPERATION) {
-        GLint pos;
-        glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
+    GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+            strlen(blt_vprogram), blt_vprogram));
+    checkGLcall("glProgramStringARB()");
+
+    glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
+    if (pos != -1)
+    {
         FIXME("Vertex program error at position %d: %s\n", pos,
             debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
     }
+    else
+    {
+        GLint native;
+
+        GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
+        checkGLcall("glGetProgramivARB()");
+        if (!native) WARN("Program exceeds native resource limits.\n");
+    }
 
     return program_id;
@@ -3036,4 +3047,6 @@
 {
     GLuint program_id = 0;
+    GLint pos;
+
     static const char * const blt_fprograms[tex_type_count] =
     {
@@ -3070,11 +3083,21 @@
     GL_EXTCALL(glGenProgramsARB(1, &program_id));
     GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, program_id));
-    GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(blt_fprograms[tex_type]), blt_fprograms[tex_type]));
-
-    if (glGetError() == GL_INVALID_OPERATION) {
-        GLint pos;
-        glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
+    GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+            strlen(blt_fprograms[tex_type]), blt_fprograms[tex_type]));
+    checkGLcall("glProgramStringARB()");
+
+    glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
+    if (pos != -1)
+    {
         FIXME("Fragment program error at position %d: %s\n", pos,
             debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
+    }
+    else
+    {
+        GLint native;
+
+        GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
+        checkGLcall("glGetProgramivARB()");
+        if (!native) WARN("Program exceeds native resource limits.\n");
     }
 
@@ -3229,20 +3252,21 @@
     BOOL dcl_tmp = args->super.srgb_correction, dcl_td = FALSE;
     BOOL want_nv_prog = FALSE;
-    struct arb_pshader_private *shader_priv = This->backend_priv;
+    struct arb_pshader_private *shader_priv = This->baseShader.backend_data;
+    GLint errPos;
+    DWORD map;
 
     char srgbtmp[4][4];
     unsigned int i, found = 0;
 
-    for(i = 0; i < This->baseShader.limits.temporary; i++) {
-
-        /* Don't overwrite the color source */
-        if(This->color0_mov && i == This->color0_reg) continue;
-        else if(reg_maps->shader_version.major < 2 && i == 0) continue;
-
-        if(reg_maps->temporary[i]) {
-            sprintf(srgbtmp[found], "R%u", i);
-            found++;
-            if(found == 4) break;
-        }
+    for (i = 0, map = reg_maps->temporary; map; map >>= 1, ++i)
+    {
+        if (!(map & 1)
+                || (This->color0_mov && i == This->color0_reg)
+                || (reg_maps->shader_version.major < 2 && i == 0))
+            continue;
+
+        sprintf(srgbtmp[found], "R%u", i);
+        ++found;
+        if (found == 4) break;
     }
 
@@ -3375,6 +3399,7 @@
             lconst_map, NULL, &priv_ctx);
 
-    for(i = 0; i < (sizeof(reg_maps->bumpmat) / sizeof(reg_maps->bumpmat[0])); i++) {
-        if(!reg_maps->bumpmat[i]) continue;
+    for (i = 0, map = reg_maps->bumpmat; map; map >>= 1, ++i)
+    {
+        if (!(map & 1)) continue;
 
         cur = compiled->numbumpenvmatconsts;
@@ -3398,5 +3423,5 @@
         compiled->numbumpenvmatconsts = cur + 1;
 
-        if(!reg_maps->luminanceparams[i]) continue;
+        if (!(reg_maps->luminanceparams & (1 << i))) continue;
 
         compiled->luminanceconst[cur].const_num = next_local++;
@@ -3486,7 +3511,7 @@
     }
 
-    if(shader_priv->clipplane_emulation)
-    {
-        shader_addline(buffer, "KIL fragment.texcoord[%u];\n", shader_priv->clipplane_emulation - 1);
+    if (shader_priv->clipplane_emulation != ~0U && args->clip)
+    {
+        shader_addline(buffer, "KIL fragment.texcoord[%u];\n", shader_priv->clipplane_emulation);
     }
 
@@ -3512,11 +3537,20 @@
     GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                buffer->bsize, buffer->buffer));
-
-    if (glGetError() == GL_INVALID_OPERATION) {
-        GLint errPos;
-        glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
+    checkGLcall("glProgramStringARB()");
+
+    glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
+    if (errPos != -1)
+    {
         FIXME("HW PixelShader Error at position %d: %s\n",
               errPos, debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
         retval = 0;
+    }
+    else
+    {
+        GLint native;
+
+        GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
+        checkGLcall("glGetProgramivARB()");
+        if (!native) WARN("Program exceeds native resource limits.\n");
     }
 
@@ -3796,4 +3830,5 @@
     struct shader_arb_ctx_priv priv_ctx;
     unsigned int i;
+    GLint errPos;
 
     memset(&priv_ctx, 0, sizeof(priv_ctx));
@@ -3905,12 +3940,21 @@
     GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
                buffer->bsize, buffer->buffer));
-
-    if (glGetError() == GL_INVALID_OPERATION) {
-        GLint errPos;
-        glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
+    checkGLcall("glProgramStringARB()");
+
+    glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errPos);
+    if (errPos != -1)
+    {
         FIXME("HW VertexShader Error at position %d: %s\n",
               errPos, debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
         ret = -1;
-    } else {
+    }
+    else
+    {
+        GLint native;
+
+        GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
+        checkGLcall("glGetProgramivARB()");
+        if (!native) WARN("Program exceeds native resource limits.\n");
+
         /* Load immediate constants */
         if(lconst_map) {
@@ -3924,40 +3968,4 @@
 
     return ret;
-}
-
-static void find_clip_texcoord(IWineD3DPixelShaderImpl *ps)
-{
-    struct arb_pshader_private *shader_priv = ps->backend_priv;
-    int i;
-    const struct wined3d_gl_info *gl_info = &((IWineD3DDeviceImpl *)ps->baseShader.device)->adapter->gl_info;
-
-    /* See if we can use fragment.texcoord[7] for clipplane emulation
-     *
-     * Don't do this if it is not supported, or fragment.texcoord[7] is used
-     */
-    if(ps->baseShader.reg_maps.shader_version.major < 3)
-    {
-        for(i = GL_LIMITS(texture_stages); i > 0; i--)
-        {
-            if(!ps->baseShader.reg_maps.texcoord[i - 1])
-            {
-                shader_priv->clipplane_emulation = i;
-                return;
-            }
-        }
-        WARN("Did not find a free clip reg(2.0)\n");
-    }
-    else
-    {
-        for(i = GL_LIMITS(texture_stages); i > 0; i--)
-        {
-            if(!(ps->baseShader.reg_maps.input_registers & (1 << (i - 1))))
-            {
-                shader_priv->clipplane_emulation = i;
-                return;
-            }
-        }
-        WARN("Did not find a free clip reg(3.0)\n");
-    }
 }
 
@@ -3972,10 +3980,12 @@
     GLuint ret;
 
-    if(!shader->backend_priv) {
+    if (!shader->baseShader.backend_data)
+    {
         IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) shader->baseShader.device;
+        const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
         struct shader_arb_priv *priv = device->shader_priv;
 
-        shader->backend_priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data));
-        shader_data = shader->backend_priv;
+        shader->baseShader.backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data));
+        shader_data = shader->baseShader.backend_data;
         shader_data->clamp_consts = shader->baseShader.reg_maps.shader_version.major == 1;
 
@@ -3986,7 +3996,11 @@
         TRACE("Shader got assigned input signature index %u\n", shader_data->input_signature_idx);
 
-        if(!device->vs_clipping) find_clip_texcoord(shader);
-    }
-    shader_data = shader->backend_priv;
+        if (!device->vs_clipping)
+            shader_data->clipplane_emulation = shader_find_free_input_register(&shader->baseShader.reg_maps,
+                    GL_LIMITS(texture_stages) - 1);
+        else
+            shader_data->clipplane_emulation = ~0U;
+    }
+    shader_data = shader->baseShader.backend_data;
 
     /* Usually we have very few GL shaders for each d3d shader(just 1 or maybe 2),
@@ -4062,8 +4076,9 @@
     const struct wined3d_gl_info *gl_info = &((IWineD3DDeviceImpl *)shader->baseShader.device)->adapter->gl_info;
 
-    if(!shader->backend_priv) {
-        shader->backend_priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data));
-    }
-    shader_data = shader->backend_priv;
+    if (!shader->baseShader.backend_data)
+    {
+        shader->baseShader.backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data));
+    }
+    shader_data = shader->baseShader.backend_data;
 
     /* Usually we have very few GL shaders for each d3d shader(just 1 or maybe 2),
@@ -4130,4 +4145,18 @@
     }
 
+    /* Only enable the clip plane emulation KIL if at least one clipplane is enabled. The KIL instruction
+     * is quite expensive because it forces the driver to disable early Z discards. It is cheaper to
+     * duplicate the shader than have a no-op KIL instruction in every shader
+     */
+    if((!((IWineD3DDeviceImpl *) shader->baseShader.device)->vs_clipping) && use_vs(stateblock) &&
+       stateblock->renderState[WINED3DRS_CLIPPING] && stateblock->renderState[WINED3DRS_CLIPPLANEENABLE])
+    {
+        args->clip = 1;
+    }
+    else
+    {
+        args->clip = 0;
+    }
+
     /* Skip if unused or local, or supported natively */
     int_skip = ~shader->baseShader.reg_maps.integer_constants | shader->baseShader.reg_maps.local_int_consts;
@@ -4168,8 +4197,8 @@
     {
         IWineD3DPixelShaderImpl *ps = (IWineD3DPixelShaderImpl *) stateblock->pixelShader;
-        struct arb_pshader_private *shader_priv = ps->backend_priv;
+        struct arb_pshader_private *shader_priv = ps->baseShader.backend_data;
         args->ps_signature = shader_priv->input_signature_idx;
 
-        args->boolclip.clip_control[0] = shader_priv->clipplane_emulation;
+        args->boolclip.clip_control[0] = shader_priv->clipplane_emulation + 1;
     }
     else
@@ -4264,7 +4293,7 @@
          * a 1.x and newer shader, reload the first 8 constants
          */
-        if(priv->last_ps_const_clamped != ((struct arb_pshader_private *) ps->backend_priv)->clamp_consts)
-        {
-            priv->last_ps_const_clamped = ((struct arb_pshader_private *) ps->backend_priv)->clamp_consts;
+        if(priv->last_ps_const_clamped != ((struct arb_pshader_private *)ps->baseShader.backend_data)->clamp_consts)
+        {
+            priv->last_ps_const_clamped = ((struct arb_pshader_private *)ps->baseShader.backend_data)->clamp_consts;
             This->highest_dirty_ps_const = max(This->highest_dirty_ps_const, 8);
             for(i = 0; i < 8; i++)
@@ -4382,5 +4411,5 @@
     {
         IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *) iface;
-        struct arb_pshader_private *shader_data = This->backend_priv;
+        struct arb_pshader_private *shader_data = This->baseShader.backend_data;
         UINT i;
 
@@ -4397,8 +4426,8 @@
         HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders);
         HeapFree(GetProcessHeap(), 0, shader_data);
-        This->backend_priv = NULL;
+        This->baseShader.backend_data = NULL;
     } else {
         IWineD3DVertexShaderImpl *This = (IWineD3DVertexShaderImpl *) iface;
-        struct arb_vshader_private *shader_data = This->backend_priv;
+        struct arb_vshader_private *shader_data = This->baseShader.backend_data;
         UINT i;
 
@@ -4415,5 +4444,5 @@
         HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders);
         HeapFree(GetProcessHeap(), 0, shader_data);
-        This->backend_priv = NULL;
+        This->baseShader.backend_data = NULL;
     }
 }
@@ -4425,5 +4454,5 @@
 }
 
-struct wine_rb_functions sig_tree_functions =
+static const struct wine_rb_functions sig_tree_functions =
 {
     wined3d_rb_alloc,
@@ -4696,5 +4725,5 @@
 
 static void get_loop_control_const(const struct wined3d_shader_instruction *ins,
-        IWineD3DBaseShaderImpl *This, UINT idx, struct loop_control *loop_control)
+        IWineD3DBaseShaderImpl *This, UINT idx, struct wined3d_shader_loop_control *loop_control)
 {
     struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
@@ -5239,6 +5268,7 @@
     if (use_ps(stateblock))
     {
-        if(stage != 0 &&
-           ((IWineD3DPixelShaderImpl *) stateblock->pixelShader)->baseShader.reg_maps.bumpmat[stage]) {
+        if (stage != 0
+                && (((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.reg_maps.bumpmat & (1 << stage)))
+        {
             /* The pixel shader has to know the bump env matrix. Do a constants update if it isn't scheduled
              * anyway
@@ -5275,6 +5305,7 @@
     if (use_ps(stateblock))
     {
-        if(stage != 0 &&
-           ((IWineD3DPixelShaderImpl *) stateblock->pixelShader)->baseShader.reg_maps.luminanceparams[stage]) {
+        if (stage != 0
+                && (((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.reg_maps.luminanceparams & (1 << stage)))
+        {
             /* The pixel shader has to know the luminance offset. Do a constants update if it
              * isn't scheduled anyway
@@ -5530,4 +5561,5 @@
     BOOL op_equal;
     const char *final_combiner_src = "ret";
+    GLint pos;
 
     /* Find out which textures are read */
@@ -5763,12 +5795,23 @@
     GL_EXTCALL(glGenProgramsARB(1, &ret));
     GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, ret));
-    GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(buffer.buffer), buffer.buffer));
-
-    if (glGetError() == GL_INVALID_OPERATION) {
-        GLint pos;
-        glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
+    GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+            strlen(buffer.buffer), buffer.buffer));
+    checkGLcall("glProgramStringARB()");
+
+    glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
+    if (pos != -1)
+    {
         FIXME("Fragment program error at position %d: %s\n", pos,
               debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
     }
+    else
+    {
+        GLint native;
+
+        GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
+        checkGLcall("glGetProgramivARB()");
+        if (!native) WARN("Program exceeds native resource limits.\n");
+    }
+
     shader_buffer_free(&buffer);
     return ret;
@@ -6349,4 +6392,5 @@
     char luminance_component;
     struct arbfp_blit_priv *priv = device->blit_priv;
+    GLint pos;
 
     /* Shader header */
@@ -6451,12 +6495,23 @@
 
     ENTER_GL();
-    GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(buffer.buffer), buffer.buffer));
-
-    if (glGetError() == GL_INVALID_OPERATION) {
-        GLint pos;
-        glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
+    GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
+            strlen(buffer.buffer), buffer.buffer));
+    checkGLcall("glProgramStringARB()");
+
+    glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
+    if (pos != -1)
+    {
         FIXME("Fragment program error at position %d: %s\n", pos,
               debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
     }
+    else
+    {
+        GLint native;
+
+        GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_UNDER_NATIVE_LIMITS_ARB, &native));
+        checkGLcall("glGetProgramivARB()");
+        if (!native) WARN("Program exceeds native resource limits.\n");
+    }
+
     shader_buffer_free(&buffer);
     LEAVE_GL();
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/baseshader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/baseshader.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/baseshader.c	(revision 23571)
@@ -217,9 +217,13 @@
 }
 
-void shader_init(struct IWineD3DBaseShaderClass *shader, IWineD3DDevice *device)
+void shader_init(struct IWineD3DBaseShaderClass *shader, IWineD3DDeviceImpl *device,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
 {
     shader->ref = 1;
-    shader->device = device;
+    shader->device = (IWineD3DDevice *)device;
+    shader->parent = parent;
+    shader->parent_ops = parent_ops;
     list_init(&shader->linked_programs);
+    list_add_head(&device->shaders, &shader->shader_list_entry);
 }
 
@@ -268,10 +272,10 @@
     {
         case WINED3DSPR_TEXTURE: /* WINED3DSPR_ADDR */
-            if (shader_type == WINED3D_SHADER_TYPE_PIXEL) reg_maps->texcoord[reg->idx] = 1;
-            else reg_maps->address[reg->idx] = 1;
+            if (shader_type == WINED3D_SHADER_TYPE_PIXEL) reg_maps->texcoord |= 1 << reg->idx;
+            else reg_maps->address |= 1 << reg->idx;
             break;
 
         case WINED3DSPR_TEMP:
-            reg_maps->temporary[reg->idx] = 1;
+            reg_maps->temporary |= 1 << reg->idx;
             break;
 
@@ -610,5 +614,5 @@
 
             fe->shader_read_src_param(fe_data, &pToken, &src, &rel_addr);
-            reg_maps->labels[src.reg.idx] = 1;
+            reg_maps->labels |= 1 << src.reg.idx;
         }
         /* Set texture, address, temporary registers */
@@ -697,8 +701,8 @@
                             || ins.handler_idx == WINED3DSIH_TEXBEML)
                     {
-                        reg_maps->bumpmat[sampler_code] = TRUE;
+                        reg_maps->bumpmat |= 1 << dst_param.reg.idx;
                         if (ins.handler_idx == WINED3DSIH_TEXBEML)
                         {
-                            reg_maps->luminanceparams[sampler_code] = TRUE;
+                            reg_maps->luminanceparams |= 1 << dst_param.reg.idx;
                         }
                     }
@@ -706,5 +710,5 @@
                 else if (ins.handler_idx == WINED3DSIH_BEM)
                 {
-                    reg_maps->bumpmat[dst_param.reg.idx] = TRUE;
+                    reg_maps->bumpmat |= 1 << dst_param.reg.idx;
                 }
             }
@@ -778,4 +782,13 @@
 
     return WINED3D_OK;
+}
+
+unsigned int shader_find_free_input_register(const struct shader_reg_maps *reg_maps, unsigned int max)
+{
+    DWORD map = 1 << max;
+    map |= map - 1;
+    map &= reg_maps->shader_version.major < 3 ? ~reg_maps->texcoord : ~reg_maps->input_registers;
+
+    return wined3d_log2i(map);
 }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c	(revision 23571)
@@ -6,4 +6,5 @@
  * Copyright 2005 Oliver Stieber
  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -39,9 +40,10 @@
 HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DRESOURCETYPE resource_type,
         IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct GlPixelFormatDesc *format_desc,
-        WINED3DPOOL pool, IUnknown *parent)
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
 {
     HRESULT hr;
 
-    hr = resource_init((IWineD3DResource *)texture, resource_type, device, size, usage, format_desc, pool, parent);
+    hr = resource_init((IWineD3DResource *)texture, resource_type, device,
+            size, usage, format_desc, pool, parent, parent_ops);
     if (FAILED(hr))
     {
@@ -53,6 +55,6 @@
     texture->baseTexture.filterType = (usage & WINED3DUSAGE_AUTOGENMIPMAP) ? WINED3DTEXF_LINEAR : WINED3DTEXF_NONE;
     texture->baseTexture.LOD = 0;
-    texture->baseTexture.dirty = TRUE;
-    texture->baseTexture.srgbDirty = TRUE;
+    texture->baseTexture.texture_rgb.dirty = TRUE;
+    texture->baseTexture.texture_srgb.dirty = TRUE;
     texture->baseTexture.is_srgb = FALSE;
     texture->baseTexture.pow2Matrix_identity = TRUE;
@@ -78,4 +80,13 @@
 }
 
+/* A GL context is provided by the caller */
+static void gltexture_delete(struct gl_texture *tex)
+{
+    ENTER_GL();
+    glDeleteTextures(1, &tex->name);
+    LEAVE_GL();
+    tex->name = 0;
+}
+
 void basetexture_unload(IWineD3DBaseTexture *iface)
 {
@@ -83,40 +94,48 @@
     IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
 
-    if(This->baseTexture.textureName) {
+    if(This->baseTexture.texture_rgb.name ||
+       This->baseTexture.texture_srgb.name) {
         ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
-        ENTER_GL();
-        glDeleteTextures(1, &This->baseTexture.textureName);
-        This->baseTexture.textureName = 0;
-        LEAVE_GL();
-    }
-
-    if(This->baseTexture.srgbTextureName) {
-        ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
-        ENTER_GL();
-        glDeleteTextures(1, &This->baseTexture.srgbTextureName);
-        This->baseTexture.srgbTextureName = 0;
-        LEAVE_GL();
-    }
-    This->baseTexture.dirty = TRUE;
-    This->baseTexture.srgbDirty = TRUE;
-}
-
-/* There is no OpenGL equivalent of setLOD, getLOD. All they do anyway is prioritize texture loading
- * so just pretend that they work unless something really needs a failure. */
+    }
+
+    if(This->baseTexture.texture_rgb.name) {
+        gltexture_delete(&This->baseTexture.texture_rgb);
+    }
+    if(This->baseTexture.texture_srgb.name) {
+        gltexture_delete(&This->baseTexture.texture_srgb);
+    }
+    This->baseTexture.texture_rgb.dirty = TRUE;
+    This->baseTexture.texture_srgb.dirty = TRUE;
+}
+
 DWORD basetexture_set_lod(IWineD3DBaseTexture *iface, DWORD LODNew)
 {
     IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
-
+    DWORD old = This->baseTexture.LOD;
+
+    /* The d3d9:texture test shows that SetLOD is ignored on non-managed
+     * textures. The call always returns 0, and GetLOD always returns 0
+     */
     if (This->resource.pool != WINED3DPOOL_MANAGED) {
-        return  WINED3DERR_INVALIDCALL;
+        TRACE("Ignoring SetLOD on %s texture, returning 0\n", debug_d3dpool(This->resource.pool));
+        return 0;
     }
 
     if(LODNew >= This->baseTexture.levels)
         LODNew = This->baseTexture.levels - 1;
-     This->baseTexture.LOD = LODNew;
-
-    TRACE("(%p) : set bogus LOD to %d\n", This, This->baseTexture.LOD);
-
-    return This->baseTexture.LOD;
+
+    if(This->baseTexture.LOD != LODNew) {
+        This->baseTexture.LOD = LODNew;
+
+        This->baseTexture.texture_rgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~0U;
+        This->baseTexture.texture_srgb.states[WINED3DTEXSTA_MAXMIPLEVEL] = ~0U;
+        if(This->baseTexture.bindCount) {
+            IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_SAMPLER(This->baseTexture.sampler));
+        }
+    }
+
+    TRACE("(%p) : set LOD to %d\n", This, This->baseTexture.LOD);
+
+    return old;
 }
 
@@ -124,8 +143,4 @@
 {
     IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
-
-    if (This->resource.pool != WINED3DPOOL_MANAGED) {
-        return  WINED3DERR_INVALIDCALL;
-    }
 
     TRACE("(%p) : returning %d\n", This, This->baseTexture.LOD);
@@ -158,5 +173,5 @@
       ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
       ENTER_GL();
-      glBindTexture(textureDimensions, This->baseTexture.textureName);
+      glBindTexture(textureDimensions, This->baseTexture.texture_rgb.name);
       checkGLcall("glBindTexture");
       switch(FilterType) {
@@ -205,7 +220,7 @@
     BOOL old;
     IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
-    old = This->baseTexture.dirty || This->baseTexture.srgbDirty;
-    This->baseTexture.dirty = dirty;
-    This->baseTexture.srgbDirty = dirty;
+    old = This->baseTexture.texture_rgb.dirty || This->baseTexture.texture_srgb.dirty;
+    This->baseTexture.texture_rgb.dirty = dirty;
+    This->baseTexture.texture_srgb.dirty = dirty;
     return old;
 }
@@ -214,5 +229,5 @@
 {
     IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
-    return This->baseTexture.dirty || This->baseTexture.srgbDirty;
+    return This->baseTexture.texture_rgb.dirty || This->baseTexture.texture_srgb.dirty;
 }
 
@@ -224,15 +239,12 @@
     UINT textureDimensions;
     BOOL isNewTexture = FALSE;
-    GLuint *texture;
-    DWORD *states;
+    struct gl_texture *gl_tex;
     TRACE("(%p) : About to bind texture\n", This);
 
     This->baseTexture.is_srgb = srgb; /* SRGB mode cache for PreLoad calls outside drawprim */
     if(srgb) {
-        texture = &This->baseTexture.srgbTextureName;
-        states = This->baseTexture.srgbstates;
+        gl_tex = &This->baseTexture.texture_srgb;
     } else {
-        texture = &This->baseTexture.textureName;
-        states = This->baseTexture.states;
+        gl_tex = &This->baseTexture.texture_rgb;
     }
 
@@ -240,31 +252,31 @@
     ENTER_GL();
     /* Generate a texture name if we don't already have one */
-    if (*texture == 0) {
+    if (gl_tex->name == 0) {
         *set_surface_desc = TRUE;
-        glGenTextures(1, texture);
+        glGenTextures(1, &gl_tex->name);
         checkGLcall("glGenTextures");
-        TRACE("Generated texture %d\n", *texture);
+        TRACE("Generated texture %d\n", gl_tex->name);
         if (This->resource.pool == WINED3DPOOL_DEFAULT) {
             /* Tell opengl to try and keep this texture in video ram (well mostly) */
             GLclampf tmp;
             tmp = 0.9f;
-            glPrioritizeTextures(1, texture, &tmp);
+            glPrioritizeTextures(1, &gl_tex->name, &tmp);
 
         }
         /* Initialise the state of the texture object
         to the openGL defaults, not the directx defaults */
-        states[WINED3DTEXSTA_ADDRESSU]      = WINED3DTADDRESS_WRAP;
-        states[WINED3DTEXSTA_ADDRESSV]      = WINED3DTADDRESS_WRAP;
-        states[WINED3DTEXSTA_ADDRESSW]      = WINED3DTADDRESS_WRAP;
-        states[WINED3DTEXSTA_BORDERCOLOR]   = 0;
-        states[WINED3DTEXSTA_MAGFILTER]     = WINED3DTEXF_LINEAR;
-        states[WINED3DTEXSTA_MINFILTER]     = WINED3DTEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
-        states[WINED3DTEXSTA_MIPFILTER]     = WINED3DTEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
-        states[WINED3DTEXSTA_MAXMIPLEVEL]   = 0;
-        states[WINED3DTEXSTA_MAXANISOTROPY] = 1;
-        states[WINED3DTEXSTA_SRGBTEXTURE]   = 0;
-        states[WINED3DTEXSTA_ELEMENTINDEX]  = 0;
-        states[WINED3DTEXSTA_DMAPOFFSET]    = 0;
-        states[WINED3DTEXSTA_TSSADDRESSW]   = WINED3DTADDRESS_WRAP;
+        gl_tex->states[WINED3DTEXSTA_ADDRESSU]      = WINED3DTADDRESS_WRAP;
+        gl_tex->states[WINED3DTEXSTA_ADDRESSV]      = WINED3DTADDRESS_WRAP;
+        gl_tex->states[WINED3DTEXSTA_ADDRESSW]      = WINED3DTADDRESS_WRAP;
+        gl_tex->states[WINED3DTEXSTA_BORDERCOLOR]   = 0;
+        gl_tex->states[WINED3DTEXSTA_MAGFILTER]     = WINED3DTEXF_LINEAR;
+        gl_tex->states[WINED3DTEXSTA_MINFILTER]     = WINED3DTEXF_POINT; /* GL_NEAREST_MIPMAP_LINEAR */
+        gl_tex->states[WINED3DTEXSTA_MIPFILTER]     = WINED3DTEXF_LINEAR; /* GL_NEAREST_MIPMAP_LINEAR */
+        gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL]   = 0;
+        gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = 1;
+        gl_tex->states[WINED3DTEXSTA_SRGBTEXTURE]   = 0;
+        gl_tex->states[WINED3DTEXSTA_ELEMENTINDEX]  = 0;
+        gl_tex->states[WINED3DTEXSTA_DMAPOFFSET]    = 0;
+        gl_tex->states[WINED3DTEXSTA_TSSADDRESSW]   = WINED3DTADDRESS_WRAP;
         IWineD3DBaseTexture_SetDirty(iface, TRUE);
         isNewTexture = TRUE;
@@ -274,5 +286,5 @@
              * in all, and the run-time path free from additional checks
              */
-            glBindTexture(textureDimensions, *texture);
+            glBindTexture(textureDimensions, gl_tex->name);
             checkGLcall("glBindTexture");
             glTexParameteri(textureDimensions, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
@@ -284,6 +296,6 @@
 
     /* Bind the texture */
-    if (*texture != 0) {
-        glBindTexture(textureDimensions, *texture);
+    if (gl_tex->name != 0) {
+        glBindTexture(textureDimensions, gl_tex->name);
         checkGLcall("glBindTexture");
         if (isNewTexture) {
@@ -348,38 +360,39 @@
 {
     IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
-    DWORD state, *states;
+    DWORD state;
     GLint textureDimensions = IWineD3DBaseTexture_GetTextureDimensions(iface);
     BOOL cond_np2 = IWineD3DBaseTexture_IsCondNP2(iface);
     DWORD aniso;
+    struct gl_texture *gl_tex;
 
     TRACE("iface %p, textureStates %p, samplerStates %p\n", iface, textureStates, samplerStates);
 
     if(This->baseTexture.is_srgb) {
-        states = This->baseTexture.srgbstates;
+        gl_tex = &This->baseTexture.texture_srgb;
     } else {
-        states = This->baseTexture.states;
+        gl_tex = &This->baseTexture.texture_rgb;
     }
 
     /* This function relies on the correct texture being bound and loaded. */
 
-    if(samplerStates[WINED3DSAMP_ADDRESSU]      != states[WINED3DTEXSTA_ADDRESSU]) {
+    if(samplerStates[WINED3DSAMP_ADDRESSU]      != gl_tex->states[WINED3DTEXSTA_ADDRESSU]) {
         state = samplerStates[WINED3DSAMP_ADDRESSU];
         apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_S, cond_np2);
-        states[WINED3DTEXSTA_ADDRESSU] = state;
-    }
-
-    if(samplerStates[WINED3DSAMP_ADDRESSV]      != states[WINED3DTEXSTA_ADDRESSV]) {
+        gl_tex->states[WINED3DTEXSTA_ADDRESSU] = state;
+    }
+
+    if(samplerStates[WINED3DSAMP_ADDRESSV]      != gl_tex->states[WINED3DTEXSTA_ADDRESSV]) {
         state = samplerStates[WINED3DSAMP_ADDRESSV];
         apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_T, cond_np2);
-        states[WINED3DTEXSTA_ADDRESSV] = state;
-    }
-
-    if(samplerStates[WINED3DSAMP_ADDRESSW]      != states[WINED3DTEXSTA_ADDRESSW]) {
+        gl_tex->states[WINED3DTEXSTA_ADDRESSV] = state;
+    }
+
+    if(samplerStates[WINED3DSAMP_ADDRESSW]      != gl_tex->states[WINED3DTEXSTA_ADDRESSW]) {
         state = samplerStates[WINED3DSAMP_ADDRESSW];
         apply_wrap(textureDimensions, state, GL_TEXTURE_WRAP_R, cond_np2);
-        states[WINED3DTEXSTA_ADDRESSW] = state;
-    }
-
-    if(samplerStates[WINED3DSAMP_BORDERCOLOR]   != states[WINED3DTEXSTA_BORDERCOLOR]) {
+        gl_tex->states[WINED3DTEXSTA_ADDRESSW] = state;
+    }
+
+    if(samplerStates[WINED3DSAMP_BORDERCOLOR]   != gl_tex->states[WINED3DTEXSTA_BORDERCOLOR]) {
         float col[4];
 
@@ -389,8 +402,8 @@
         glTexParameterfv(textureDimensions, GL_TEXTURE_BORDER_COLOR, &col[0]);
         checkGLcall("glTexParameteri(..., GL_TEXTURE_BORDER_COLOR, ...)");
-        states[WINED3DTEXSTA_BORDERCOLOR] = state;
-    }
-
-    if(samplerStates[WINED3DSAMP_MAGFILTER]     != states[WINED3DTEXSTA_MAGFILTER]) {
+        gl_tex->states[WINED3DTEXSTA_BORDERCOLOR] = state;
+    }
+
+    if(samplerStates[WINED3DSAMP_MAGFILTER]     != gl_tex->states[WINED3DTEXSTA_MAGFILTER]) {
         GLint glValue;
         state = samplerStates[WINED3DSAMP_MAGFILTER];
@@ -404,23 +417,23 @@
         glTexParameteri(textureDimensions, GL_TEXTURE_MAG_FILTER, glValue);
 
-        states[WINED3DTEXSTA_MAGFILTER] = state;
-    }
-
-    if((samplerStates[WINED3DSAMP_MINFILTER]     != states[WINED3DTEXSTA_MINFILTER] ||
-        samplerStates[WINED3DSAMP_MIPFILTER]     != states[WINED3DTEXSTA_MIPFILTER] ||
-        samplerStates[WINED3DSAMP_MAXMIPLEVEL]   != states[WINED3DTEXSTA_MAXMIPLEVEL])) {
+        gl_tex->states[WINED3DTEXSTA_MAGFILTER] = state;
+    }
+
+    if((samplerStates[WINED3DSAMP_MINFILTER]     != gl_tex->states[WINED3DTEXSTA_MINFILTER] ||
+        samplerStates[WINED3DSAMP_MIPFILTER]     != gl_tex->states[WINED3DTEXSTA_MIPFILTER] ||
+        samplerStates[WINED3DSAMP_MAXMIPLEVEL]   != gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL])) {
         GLint glValue;
 
-        states[WINED3DTEXSTA_MIPFILTER] = samplerStates[WINED3DSAMP_MIPFILTER];
-        states[WINED3DTEXSTA_MINFILTER] = samplerStates[WINED3DSAMP_MINFILTER];
-        states[WINED3DTEXSTA_MAXMIPLEVEL] = samplerStates[WINED3DSAMP_MAXMIPLEVEL];
-
-        if (states[WINED3DTEXSTA_MINFILTER] > WINED3DTEXF_ANISOTROPIC
-                || states[WINED3DTEXSTA_MIPFILTER] > WINED3DTEXF_ANISOTROPIC)
+        gl_tex->states[WINED3DTEXSTA_MIPFILTER] = samplerStates[WINED3DSAMP_MIPFILTER];
+        gl_tex->states[WINED3DTEXSTA_MINFILTER] = samplerStates[WINED3DSAMP_MINFILTER];
+        gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] = samplerStates[WINED3DSAMP_MAXMIPLEVEL];
+
+        if (gl_tex->states[WINED3DTEXSTA_MINFILTER] > WINED3DTEXF_ANISOTROPIC
+            || gl_tex->states[WINED3DTEXSTA_MIPFILTER] > WINED3DTEXF_ANISOTROPIC)
         {
 
             FIXME("Unrecognized or unsupported D3DSAMP_MINFILTER value %d D3DSAMP_MIPFILTER value %d\n",
-                  states[WINED3DTEXSTA_MINFILTER],
-                  states[WINED3DTEXSTA_MIPFILTER]);
+                  gl_tex->states[WINED3DTEXSTA_MINFILTER],
+                  gl_tex->states[WINED3DTEXSTA_MIPFILTER]);
         }
         glValue = wined3d_gl_min_mip_filter(This->baseTexture.minMipLookup,
@@ -435,18 +448,25 @@
 
         if(!cond_np2) {
-            if(states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE) {
-                glValue = 0;
-            } else if(states[WINED3DTEXSTA_MAXMIPLEVEL] >= This->baseTexture.levels) {
+            if(gl_tex->states[WINED3DTEXSTA_MIPFILTER] == WINED3DTEXF_NONE) {
+                glValue = This->baseTexture.LOD;
+            } else if(gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] >= This->baseTexture.levels) {
                 glValue = This->baseTexture.levels - 1;
+            } else if(gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL] < This->baseTexture.LOD) {
+                /* baseTexture.LOD is already clamped in the setter */
+                glValue = This->baseTexture.LOD;
             } else {
-                glValue = states[WINED3DTEXSTA_MAXMIPLEVEL];
+                glValue = gl_tex->states[WINED3DTEXSTA_MAXMIPLEVEL];
             }
+            /* Note that D3DSAMP_MAXMIPLEVEL specifies the biggest mipmap(default 0), while
+             * GL_TEXTURE_MAX_LEVEL specifies the smallest mimap used(default 1000).
+             * So D3DSAMP_MAXMIPLEVEL is the same as GL_TEXTURE_BASE_LEVEL.
+             */
             glTexParameteri(textureDimensions, GL_TEXTURE_BASE_LEVEL, glValue);
         }
     }
 
-    if ((states[WINED3DSAMP_MAGFILTER] != WINED3DTEXF_ANISOTROPIC
-            && states[WINED3DSAMP_MINFILTER] != WINED3DTEXF_ANISOTROPIC
-            && states[WINED3DSAMP_MIPFILTER] != WINED3DTEXF_ANISOTROPIC)
+    if ((gl_tex->states[WINED3DTEXSTA_MAGFILTER] != WINED3DTEXF_ANISOTROPIC
+         && gl_tex->states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_ANISOTROPIC
+         && gl_tex->states[WINED3DTEXSTA_MIPFILTER] != WINED3DTEXF_ANISOTROPIC)
             || cond_np2)
     {
@@ -458,5 +478,5 @@
     }
 
-    if (states[WINED3DTEXSTA_MAXANISOTROPY] != aniso)
+    if (gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] != aniso)
     {
         if (GL_SUPPORT(EXT_TEXTURE_FILTER_ANISOTROPIC))
@@ -469,5 +489,5 @@
             WARN("Anisotropic filtering not supported.\n");
         }
-        states[WINED3DTEXSTA_MAXANISOTROPY] = aniso;
-    }
-}
+        gl_tex->states[WINED3DTEXSTA_MAXANISOTROPY] = aniso;
+    }
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/buffer.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/buffer.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/buffer.c	(revision 23571)
@@ -208,8 +208,9 @@
 }
 
-static BOOL buffer_check_attribute(struct wined3d_buffer *This,
-        const struct wined3d_stream_info_element *attrib, const BOOL check_d3dcolor, const BOOL is_ffp_position,
-        const BOOL is_ffp_color, DWORD *stride_this_run, BOOL *float16_used)
-{
+static BOOL buffer_check_attribute(struct wined3d_buffer *This, const struct wined3d_stream_info *si,
+        UINT attrib_idx, const BOOL check_d3dcolor, const BOOL is_ffp_position, const BOOL is_ffp_color,
+        DWORD *stride_this_run, BOOL *float16_used)
+{
+    const struct wined3d_stream_info_element *attrib = &si->elements[attrib_idx];
     BOOL ret = FALSE;
     WINED3DFORMAT format;
@@ -218,5 +219,7 @@
      * there, on nonexistent attribs the vbo is 0.
      */
-    if (attrib->buffer_object != This->buffer_object) return FALSE;
+    if (!(si->use_map & (1 << attrib_idx))
+            || attrib->buffer_object != This->buffer_object)
+        return FALSE;
 
     format = attrib->format_desc->format;
@@ -230,9 +233,9 @@
         *float16_used = TRUE;
     }
-    else if (check_d3dcolor && format == WINED3DFMT_A8R8G8B8)
+    else if (check_d3dcolor && format == WINED3DFMT_B8G8R8A8_UNORM)
     {
         ret = buffer_process_converted_attribute(This, CONV_D3DCOLOR, attrib, stride_this_run);
 
-        if (!is_ffp_color) FIXME("Test for non-color fixed function WINED3DFMT_A8R8G8B8 format\n");
+        if (!is_ffp_color) FIXME("Test for non-color fixed function WINED3DFMT_B8G8R8A8_UNORM format\n");
     }
     else if (is_ffp_position && format == WINED3DFMT_R32G32B32A32_FLOAT)
@@ -265,5 +268,5 @@
         WINED3DFORMAT format;
 
-        if (strided->elements[i].buffer_object != This->buffer_object) continue;
+        if (!(strided->use_map & (1 << i)) || strided->elements[i].buffer_object != This->buffer_object) continue;
 
         format = strided->elements[i].format_desc->format;
@@ -316,4 +319,5 @@
 {
     IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    const struct wined3d_stream_info *si = &device->strided_streams;
     UINT stride_this_run = 0;
     BOOL float16_used = FALSE;
@@ -403,6 +407,5 @@
         for (i = 0; i < MAX_ATTRIBS; ++i)
         {
-            ret = buffer_check_attribute(This, &device->strided_streams.elements[i],
-                    FALSE, FALSE, FALSE, &stride_this_run, &float16_used) || ret;
+            ret = buffer_check_attribute(This, si, i, FALSE, FALSE, FALSE, &stride_this_run, &float16_used) || ret;
         }
 
@@ -413,5 +416,5 @@
         {
             HeapFree(GetProcessHeap(), 0, This->conversion_shift);
-            This->conversion_shift = find_conversion_shift(This, &device->strided_streams, This->stride);
+            This->conversion_shift = find_conversion_shift(This, si, This->stride);
         }
     }
@@ -423,27 +426,27 @@
          */
         BOOL support_d3dcolor = GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA);
-        ret = buffer_check_attribute(This, &device->strided_streams.elements[WINED3D_FFP_POSITION],
+        ret = buffer_check_attribute(This, si, WINED3D_FFP_POSITION,
                 TRUE, TRUE,  FALSE, &stride_this_run, &float16_used) || ret;
-        ret = buffer_check_attribute(This, &device->strided_streams.elements[WINED3D_FFP_NORMAL],
+        ret = buffer_check_attribute(This, si, WINED3D_FFP_NORMAL,
                 TRUE, FALSE, FALSE, &stride_this_run, &float16_used) || ret;
-        ret = buffer_check_attribute(This, &device->strided_streams.elements[WINED3D_FFP_DIFFUSE],
+        ret = buffer_check_attribute(This, si, WINED3D_FFP_DIFFUSE,
                 !support_d3dcolor, FALSE, TRUE,  &stride_this_run, &float16_used) || ret;
-        ret = buffer_check_attribute(This, &device->strided_streams.elements[WINED3D_FFP_SPECULAR],
+        ret = buffer_check_attribute(This, si, WINED3D_FFP_SPECULAR,
                 !support_d3dcolor, FALSE, TRUE,  &stride_this_run, &float16_used) || ret;
-        ret = buffer_check_attribute(This, &device->strided_streams.elements[WINED3D_FFP_TEXCOORD0],
+        ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD0,
                 TRUE, FALSE, FALSE, &stride_this_run, &float16_used) || ret;
-        ret = buffer_check_attribute(This, &device->strided_streams.elements[WINED3D_FFP_TEXCOORD1],
+        ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD1,
                 TRUE, FALSE, FALSE, &stride_this_run, &float16_used) || ret;
-        ret = buffer_check_attribute(This, &device->strided_streams.elements[WINED3D_FFP_TEXCOORD2],
+        ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD2,
                 TRUE, FALSE, FALSE, &stride_this_run, &float16_used) || ret;
-        ret = buffer_check_attribute(This, &device->strided_streams.elements[WINED3D_FFP_TEXCOORD3],
+        ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD3,
                 TRUE, FALSE, FALSE, &stride_this_run, &float16_used) || ret;
-        ret = buffer_check_attribute(This, &device->strided_streams.elements[WINED3D_FFP_TEXCOORD4],
+        ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD4,
                 TRUE, FALSE, FALSE, &stride_this_run, &float16_used) || ret;
-        ret = buffer_check_attribute(This, &device->strided_streams.elements[WINED3D_FFP_TEXCOORD5],
+        ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD5,
                 TRUE, FALSE, FALSE, &stride_this_run, &float16_used) || ret;
-        ret = buffer_check_attribute(This, &device->strided_streams.elements[WINED3D_FFP_TEXCOORD6],
+        ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD6,
                 TRUE, FALSE, FALSE, &stride_this_run, &float16_used) || ret;
-        ret = buffer_check_attribute(This, &device->strided_streams.elements[WINED3D_FFP_TEXCOORD7],
+        ret = buffer_check_attribute(This, si, WINED3D_FFP_TEXCOORD7,
                 TRUE, FALSE, FALSE, &stride_this_run, &float16_used) || ret;
 
@@ -642,4 +645,5 @@
         buffer_UnLoad(iface);
         resource_cleanup((IWineD3DResource *)iface);
+        This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
         HeapFree(GetProcessHeap(), 0, This);
     }
@@ -1042,5 +1046,5 @@
 }
 
-const struct IWineD3DBufferVtbl wined3d_buffer_vtbl =
+static const struct IWineD3DBufferVtbl wined3d_buffer_vtbl =
 {
     /* IUnknown methods */
@@ -1065,2 +1069,57 @@
     buffer_GetDesc,
 };
+
+HRESULT buffer_init(struct wined3d_buffer *buffer, IWineD3DDeviceImpl *device,
+        UINT size, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, GLenum bind_hint,
+        const char *data, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+{
+    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, &device->adapter->gl_info);
+    HRESULT hr;
+
+    if (!size)
+    {
+        WARN("Size 0 requested, returning WINED3DERR_INVALIDCALL\n");
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    buffer->vtbl = &wined3d_buffer_vtbl;
+
+    hr = resource_init((IWineD3DResource *)buffer, WINED3DRTYPE_BUFFER,
+            device, size, usage, format_desc, pool, parent, parent_ops);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize resource, hr %#x\n", hr);
+        return hr;
+    }
+    buffer->buffer_type_hint = bind_hint;
+
+    TRACE("size %#x, usage %#x, format %s, memory @ %p, iface @ %p.\n", buffer->resource.size, buffer->resource.usage,
+            debug_d3dformat(buffer->resource.format_desc->format), buffer->resource.allocatedMemory, buffer);
+
+    if (data)
+    {
+        BYTE *ptr;
+
+        hr = IWineD3DBuffer_Map((IWineD3DBuffer *)buffer, 0, size, &ptr, 0);
+        if (FAILED(hr))
+        {
+            ERR("Failed to map buffer, hr %#x\n", hr);
+            buffer_UnLoad((IWineD3DBuffer *)buffer);
+            resource_cleanup((IWineD3DResource *)buffer);
+            return hr;
+        }
+
+        memcpy(ptr, data, size);
+
+        hr = IWineD3DBuffer_Unmap((IWineD3DBuffer *)buffer);
+        if (FAILED(hr))
+        {
+            ERR("Failed to unmap buffer, hr %#x\n", hr);
+            buffer_UnLoad((IWineD3DBuffer *)buffer);
+            resource_cleanup((IWineD3DResource *)buffer);
+            return hr;
+        }
+    }
+
+    return WINED3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c	(revision 23571)
@@ -58,6 +58,6 @@
         if (!*fbo)
         {
-            GL_EXTCALL(glGenFramebuffersEXT(1, fbo));
-            checkGLcall("glGenFramebuffersEXT()");
+            gl_info->fbo_ops.glGenFramebuffers(1, fbo);
+            checkGLcall("glGenFramebuffers()");
             TRACE("Created FBO %u.\n", *fbo);
         }
@@ -67,15 +67,15 @@
     switch (target)
     {
-        case GL_READ_FRAMEBUFFER_EXT:
+        case GL_READ_FRAMEBUFFER:
             if (context->fbo_read_binding == f) return;
             context->fbo_read_binding = f;
             break;
 
-        case GL_DRAW_FRAMEBUFFER_EXT:
+        case GL_DRAW_FRAMEBUFFER:
             if (context->fbo_draw_binding == f) return;
             context->fbo_draw_binding = f;
             break;
 
-        case GL_FRAMEBUFFER_EXT:
+        case GL_FRAMEBUFFER:
             if (context->fbo_read_binding == f
                     && context->fbo_draw_binding == f) return;
@@ -89,5 +89,5 @@
     }
 
-    GL_EXTCALL(glBindFramebufferEXT(target, f));
+    gl_info->fbo_ops.glBindFramebuffer(target, f);
     checkGLcall("glBindFramebuffer()");
 }
@@ -100,11 +100,11 @@
     for (i = 0; i < GL_LIMITS(buffers); ++i)
     {
-        GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + i, GL_TEXTURE_2D, 0, 0));
+        gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, 0, 0);
         checkGLcall("glFramebufferTexture2D()");
     }
-    GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0));
+    gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
     checkGLcall("glFramebufferTexture2D()");
 
-    GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0));
+    gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
     checkGLcall("glFramebufferTexture2D()");
 }
@@ -115,9 +115,9 @@
     const struct wined3d_gl_info *gl_info = context->gl_info;
 
-    context_bind_fbo(context, GL_FRAMEBUFFER_EXT, fbo);
+    context_bind_fbo(context, GL_FRAMEBUFFER, fbo);
     context_clean_fbo_attachments(gl_info);
-    context_bind_fbo(context, GL_FRAMEBUFFER_EXT, NULL);
-
-    GL_EXTCALL(glDeleteFramebuffersEXT(1, fbo));
+    context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
+
+    gl_info->fbo_ops.glDeleteFramebuffers(1, fbo);
     checkGLcall("glDeleteFramebuffers()");
 }
@@ -135,15 +135,15 @@
     if (SUCCEEDED(IWineD3DSurface_GetContainer(surface, &IID_IWineD3DBaseTexture, (void **)&texture_impl)))
     {
-        if (texture_impl->baseTexture.states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_POINT
-            || texture_impl->baseTexture.states[WINED3DTEXSTA_MIPFILTER] != WINED3DTEXF_NONE)
-        {
-            texture_impl->baseTexture.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
-            texture_impl->baseTexture.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
+        if (texture_impl->baseTexture.texture_rgb.states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_POINT
+            || texture_impl->baseTexture.texture_rgb.states[WINED3DTEXSTA_MIPFILTER] != WINED3DTEXF_NONE)
+        {
+            texture_impl->baseTexture.texture_rgb.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
+            texture_impl->baseTexture.texture_rgb.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
             update_minfilter = TRUE;
         }
 
-        if (texture_impl->baseTexture.states[WINED3DTEXSTA_MAGFILTER] != WINED3DTEXF_POINT)
-        {
-            texture_impl->baseTexture.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
+        if (texture_impl->baseTexture.texture_rgb.states[WINED3DTEXSTA_MAGFILTER] != WINED3DTEXF_POINT)
+        {
+            texture_impl->baseTexture.texture_rgb.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
             update_magfilter = TRUE;
         }
@@ -204,14 +204,14 @@
             if (format_flags & WINED3DFMT_FLAG_DEPTH)
             {
-                GL_EXTCALL(glFramebufferRenderbufferEXT(fbo_target, GL_DEPTH_ATTACHMENT_EXT,
-                        GL_RENDERBUFFER_EXT, depth_stencil_impl->current_renderbuffer->id));
-                checkGLcall("glFramebufferRenderbufferEXT()");
+                gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_DEPTH_ATTACHMENT,
+                        GL_RENDERBUFFER, depth_stencil_impl->current_renderbuffer->id);
+                checkGLcall("glFramebufferRenderbuffer()");
             }
 
             if (format_flags & WINED3DFMT_FLAG_STENCIL)
             {
-                GL_EXTCALL(glFramebufferRenderbufferEXT(fbo_target, GL_STENCIL_ATTACHMENT_EXT,
-                        GL_RENDERBUFFER_EXT, depth_stencil_impl->current_renderbuffer->id));
-                checkGLcall("glFramebufferRenderbufferEXT()");
+                gl_info->fbo_ops.glFramebufferRenderbuffer(fbo_target, GL_STENCIL_ATTACHMENT,
+                        GL_RENDERBUFFER, depth_stencil_impl->current_renderbuffer->id);
+                checkGLcall("glFramebufferRenderbuffer()");
             }
         }
@@ -222,16 +222,16 @@
             if (format_flags & WINED3DFMT_FLAG_DEPTH)
             {
-                GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_DEPTH_ATTACHMENT_EXT,
+                gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_DEPTH_ATTACHMENT,
                         depth_stencil_impl->texture_target, depth_stencil_impl->texture_name,
-                        depth_stencil_impl->texture_level));
-                checkGLcall("glFramebufferTexture2DEXT()");
+                        depth_stencil_impl->texture_level);
+                checkGLcall("glFramebufferTexture2D()");
             }
 
             if (format_flags & WINED3DFMT_FLAG_STENCIL)
             {
-                GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_STENCIL_ATTACHMENT_EXT,
+                gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_STENCIL_ATTACHMENT,
                         depth_stencil_impl->texture_target, depth_stencil_impl->texture_name,
-                        depth_stencil_impl->texture_level));
-                checkGLcall("glFramebufferTexture2DEXT()");
+                        depth_stencil_impl->texture_level);
+                checkGLcall("glFramebufferTexture2D()");
             }
         }
@@ -239,21 +239,21 @@
         if (!(format_flags & WINED3DFMT_FLAG_DEPTH))
         {
-            GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0));
-            checkGLcall("glFramebufferTexture2DEXT()");
+            gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
+            checkGLcall("glFramebufferTexture2D()");
         }
 
         if (!(format_flags & WINED3DFMT_FLAG_STENCIL))
         {
-            GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0));
-            checkGLcall("glFramebufferTexture2DEXT()");
+            gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
+            checkGLcall("glFramebufferTexture2D()");
         }
     }
     else
     {
-        GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0));
-        checkGLcall("glFramebufferTexture2DEXT()");
-
-        GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0));
-        checkGLcall("glFramebufferTexture2DEXT()");
+        gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
+        checkGLcall("glFramebufferTexture2D()");
+
+        gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
+        checkGLcall("glFramebufferTexture2D()");
     }
 }
@@ -272,10 +272,12 @@
         context_apply_attachment_filter_states(surface, TRUE);
 
-        GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_COLOR_ATTACHMENT0_EXT + idx, surface_impl->texture_target,
-                surface_impl->texture_name, surface_impl->texture_level));
-        checkGLcall("glFramebufferTexture2DEXT()");
-    } else {
-        GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_COLOR_ATTACHMENT0_EXT + idx, GL_TEXTURE_2D, 0, 0));
-        checkGLcall("glFramebufferTexture2DEXT()");
+        gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_COLOR_ATTACHMENT0 + idx, surface_impl->texture_target,
+                surface_impl->texture_name, surface_impl->texture_level);
+        checkGLcall("glFramebufferTexture2D()");
+    }
+    else
+    {
+        gl_info->fbo_ops.glFramebufferTexture2D(fbo_target, GL_COLOR_ATTACHMENT0 + idx, GL_TEXTURE_2D, 0, 0);
+        checkGLcall("glFramebufferTexture2D()");
     }
 }
@@ -287,6 +289,6 @@
     GLenum status;
 
-    status = GL_EXTCALL(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
-    if (status == GL_FRAMEBUFFER_COMPLETE_EXT)
+    status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
+    if (status == GL_FRAMEBUFFER_COMPLETE)
     {
         TRACE("FBO complete\n");
@@ -295,5 +297,4 @@
         unsigned int i;
         FIXME("FBO status %s (%#x)\n", debug_fbostatus(status), status);
-
 
         if (context->current_fbo)
@@ -308,5 +309,4 @@
                             i, attachment, debug_d3dformat(attachment->resource.format_desc->format),
                             attachment->pow2Width, attachment->pow2Height);
-        
                 }
             }
@@ -344,5 +344,5 @@
     const struct wined3d_gl_info *gl_info = context->gl_info;
 
-    context_bind_fbo(context, GL_FRAMEBUFFER_EXT, &entry->id);
+    context_bind_fbo(context, GL_FRAMEBUFFER, &entry->id);
     context_clean_fbo_attachments(gl_info);
 
@@ -409,5 +409,5 @@
     unsigned int i;
 
-    context_bind_fbo(context, GL_FRAMEBUFFER_EXT, &entry->id);
+    context_bind_fbo(context, GL_FRAMEBUFFER, &entry->id);
 
     if (!entry->attached)
@@ -417,5 +417,5 @@
         {
             IWineD3DSurface *render_target = device->render_targets[i];
-            context_attach_surface_fbo(context, GL_FRAMEBUFFER_EXT, i, render_target);
+            context_attach_surface_fbo(context, GL_FRAMEBUFFER, i, render_target);
         }
 
@@ -428,5 +428,5 @@
             surface_set_compatible_renderbuffer(device->stencilBufferTarget, w, h);
         }
-        context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER_EXT, device->stencilBufferTarget, TRUE);
+        context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, device->stencilBufferTarget, TRUE);
 
         entry->attached = TRUE;
@@ -444,5 +444,5 @@
     {
         if (device->render_targets[i])
-            device->draw_buffers[i] = GL_COLOR_ATTACHMENT0_EXT + i;
+            device->draw_buffers[i] = GL_COLOR_ATTACHMENT0 + i;
         else
             device->draw_buffers[i] = GL_NONE;
@@ -459,5 +459,5 @@
     } else {
         context->current_fbo = NULL;
-        context_bind_fbo(context, GL_FRAMEBUFFER_EXT, NULL);
+        context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
     }
 
@@ -690,5 +690,6 @@
         }
 
-        GL_EXTCALL(glDeleteQueriesARB(context->free_occlusion_query_count, context->free_occlusion_queries));
+        if (GL_SUPPORT(ARB_OCCLUSION_QUERY))
+            GL_EXTCALL(glDeleteQueriesARB(context->free_occlusion_query_count, context->free_occlusion_queries));
 
         if (GL_SUPPORT(APPLE_FENCE))
@@ -771,16 +772,19 @@
         if (!pwglMakeCurrent(ctx->hdc, ctx->glCtx))
         {
-            ERR("Failed to make GL context %p current on device context %p.\n", ctx->glCtx, ctx->hdc);
+            DWORD err = GetLastError();
+            ERR("Failed to make GL context %p current on device context %p, last error %#x.\n",
+                    ctx->glCtx, ctx->hdc, err);
+            TlsSetValue(wined3d_context_tls_idx, NULL);
             return FALSE;
         }
         ctx->current = 1;
     }
-    else
+    else if(pwglGetCurrentContext())
     {
         TRACE("Clearing current D3D context.\n");
         if (!pwglMakeCurrent(NULL, NULL))
         {
-            ERR("Failed to clear current GL context.\n");
-            /*In case of failure, wglMakeCurrent makes current GLRC not current anyway.*/
+            DWORD err = GetLastError();
+            ERR("Failed to clear current GL context, last error %#x.\n", err);
             TlsSetValue(wined3d_context_tls_idx, NULL);
             return FALSE;
@@ -810,5 +814,5 @@
     BYTE shift;
 
-    if(!rep || isStateDirty(context, rep)) return;
+    if (isStateDirty(context, rep)) return;
 
     context->dirtyArray[context->numDirtyEntries++] = rep;
@@ -867,5 +871,6 @@
      */
     for(state = 0; state <= STATE_HIGHEST; state++) {
-        Context_MarkStateDirty(This->contexts[This->numContexts], state, This->StateTable);
+        if (This->StateTable[state].representative)
+            Context_MarkStateDirty(This->contexts[This->numContexts], state, This->StateTable);
     }
 
@@ -930,8 +935,8 @@
      * time. It can cause a slight performance hit but fixes a lot of regressions. A fixme reminds of that this
      * issue needs to be fixed. */
-    if (ds_format_desc->format != WINED3DFMT_D24S8)
+    if (ds_format_desc->format != WINED3DFMT_S8_UINT_D24_UNORM)
     {
         FIXME("Add OpenGL context recreation support to SetDepthStencilSurface\n");
-        ds_format_desc = getFormatDescEntry(WINED3DFMT_D24S8, &This->adapter->gl_info);
+        ds_format_desc = getFormatDescEntry(WINED3DFMT_S8_UINT_D24_UNORM, &This->adapter->gl_info);
     }
 
@@ -1145,8 +1150,8 @@
             auxBuffers = TRUE;
 
-            if (color_format_desc->format == WINED3DFMT_X4R4G4B4)
-                color_format_desc = getFormatDescEntry(WINED3DFMT_A4R4G4B4, &This->adapter->gl_info);
-            else if (color_format_desc->format == WINED3DFMT_X8R8G8B8)
-                color_format_desc = getFormatDescEntry(WINED3DFMT_A8R8G8B8, &This->adapter->gl_info);
+            if (color_format_desc->format == WINED3DFMT_B4G4R4X4_UNORM)
+                color_format_desc = getFormatDescEntry(WINED3DFMT_B4G4R4A4_UNORM, &This->adapter->gl_info);
+            else if (color_format_desc->format == WINED3DFMT_B8G8R8X8_UNORM)
+                color_format_desc = getFormatDescEntry(WINED3DFMT_B8G8R8A8_UNORM, &This->adapter->gl_info);
         }
 
@@ -1155,6 +1160,6 @@
          * The conversion (ab)uses the alpha component for storing the palette index. For this reason we require
          * a format with 8bit alpha, so request A8R8G8B8. */
-        if (color_format_desc->format == WINED3DFMT_P8)
-            color_format_desc = getFormatDescEntry(WINED3DFMT_A8R8G8B8, &This->adapter->gl_info);
+        if (color_format_desc->format == WINED3DFMT_P8_UINT)
+            color_format_desc = getFormatDescEntry(WINED3DFMT_B8G8R8A8_UNORM, &This->adapter->gl_info);
 
         /* Retrieve the depth stencil format from the present parameters.
@@ -1374,4 +1379,14 @@
         checkGLcall("glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE)");
     }
+
+    if (GL_SUPPORT(ARB_PROVOKING_VERTEX))
+    {
+        GL_EXTCALL(glProvokingVertex(GL_FIRST_VERTEX_CONVENTION));
+    }
+    else if (GL_SUPPORT(EXT_PROVOKING_VERTEX))
+    {
+        GL_EXTCALL(glProvokingVertexEXT(GL_FIRST_VERTEX_CONVENTION_EXT));
+    }
+
     LEAVE_GL();
 
@@ -1524,7 +1539,8 @@
 static inline void SetupForBlit(IWineD3DDeviceImpl *This, struct wined3d_context *context, UINT width, UINT height)
 {
-    int i, sampler;
+    int i;
     const struct StateEntry *StateTable = This->StateTable;
     const struct wined3d_gl_info *gl_info = context->gl_info;
+    DWORD sampler;
 
     TRACE("Setting up context %p for blitting\n", context);
@@ -1589,5 +1605,6 @@
         checkGLcall("glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);");
 
-        if (sampler != -1) {
+        if (sampler != WINED3D_UNMAPPED_STAGE)
+        {
             if (sampler < MAX_TEXTURES) {
                 Context_MarkStateDirty(context, STATE_TEXTURESTAGE(sampler, WINED3DTSS_COLOROP), StateTable);
@@ -1628,5 +1645,6 @@
     }
 
-    if (sampler != -1) {
+    if (sampler != WINED3D_UNMAPPED_STAGE)
+    {
         if (sampler < MAX_TEXTURES) {
             Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_TEXTURE0 + sampler), StateTable);
@@ -1856,5 +1874,5 @@
     if (context->render_offscreen != old_render_offscreen)
     {
-        Context_MarkStateDirty(context, WINED3DTS_PROJECTION, StateTable);
+        Context_MarkStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION), StateTable);
         Context_MarkStateDirty(context, STATE_VDECL, StateTable);
         Context_MarkStateDirty(context, STATE_VIEWPORT, StateTable);
@@ -1964,5 +1982,5 @@
                 }
             } else {
-                glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
+                glDrawBuffer(GL_COLOR_ATTACHMENT0);
                 checkGLcall("glDrawBuffer()");
             }
@@ -2046,11 +2064,11 @@
                     FIXME("Activating for CTXUSAGE_BLIT for an offscreen target with ORM_FBO. This should be avoided.\n");
                     ENTER_GL();
-                    context_bind_fbo(context, GL_FRAMEBUFFER_EXT, &context->dst_fbo);
-                    context_attach_surface_fbo(context, GL_FRAMEBUFFER_EXT, 0, target);
-                    context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER_EXT, NULL, FALSE);
+                    context_bind_fbo(context, GL_FRAMEBUFFER, &context->dst_fbo);
+                    context_attach_surface_fbo(context, GL_FRAMEBUFFER, 0, target);
+                    context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, NULL, FALSE);
                     LEAVE_GL();
                 } else {
                     ENTER_GL();
-                    context_bind_fbo(context, GL_FRAMEBUFFER_EXT, NULL);
+                    context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
                     LEAVE_GL();
                 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c	(revision 23571)
@@ -6,4 +6,5 @@
  * Copyright 2005 Oliver Stieber
  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -65,5 +66,5 @@
             break;
     }
-    dirty = srgb_mode ? &This->baseTexture.srgbDirty : &This->baseTexture.dirty;
+    dirty = srgb_mode ? &This->baseTexture.texture_srgb.dirty : &This->baseTexture.texture_rgb.dirty;
 
     TRACE("(%p) : About to load texture: dirtified(%u).\n", This, *dirty);
@@ -79,6 +80,6 @@
     }
 
-    if (This->resource.format_desc->format == WINED3DFMT_P8
-            || This->resource.format_desc->format == WINED3DFMT_A8P8)
+    if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
+            || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
     {
         for (i = 0; i < This->baseTexture.levels; ++i)
@@ -120,5 +121,5 @@
 }
 
-static void cubetexture_cleanup(IWineD3DCubeTextureImpl *This, D3DCB_DESTROYSURFACEFN surface_destroy_cb)
+static void cubetexture_cleanup(IWineD3DCubeTextureImpl *This)
 {
     unsigned int i, j;
@@ -140,124 +141,9 @@
                 surface_set_texture_target(surface, 0);
                 IWineD3DSurface_SetContainer(surface, NULL);
-                surface_destroy_cb(surface);
+                IWineD3DSurface_Release(surface);
             }
         }
     }
     basetexture_cleanup((IWineD3DBaseTexture *)This);
-}
-
-HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels,
-        IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
-{
-    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
-    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
-    UINT pow2_edge_length;
-    unsigned int i, j;
-    UINT tmp_w;
-    HRESULT hr;
-
-    /* TODO: It should only be possible to create textures for formats
-     * that are reported as supported. */
-    if (WINED3DFMT_UNKNOWN >= format)
-    {
-        WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
-        return WINED3DERR_INVALIDCALL;
-    }
-
-    if (!GL_SUPPORT(ARB_TEXTURE_CUBE_MAP) && pool != WINED3DPOOL_SCRATCH)
-    {
-        WARN("(%p) : Tried to create not supported cube texture.\n", texture);
-        return WINED3DERR_INVALIDCALL;
-    }
-
-    /* Calculate levels for mip mapping */
-    if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
-    {
-        if (!GL_SUPPORT(SGIS_GENERATE_MIPMAP))
-        {
-            WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
-            return WINED3DERR_INVALIDCALL;
-        }
-
-        if (levels > 1)
-        {
-            WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
-            return WINED3DERR_INVALIDCALL;
-        }
-
-        levels = 1;
-    }
-    else if (!levels)
-    {
-        levels = wined3d_log2i(edge_length) + 1;
-        TRACE("Calculated levels = %u.\n", levels);
-    }
-
-    hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels,
-            WINED3DRTYPE_CUBETEXTURE, device, 0, usage, format_desc, pool, parent);
-    if (FAILED(hr))
-    {
-        WARN("Failed to initialize basetexture, returning %#x\n", hr);
-        return hr;
-    }
-
-    /* Find the nearest pow2 match. */
-    pow2_edge_length = 1;
-    while (pow2_edge_length < edge_length) pow2_edge_length <<= 1;
-
-    if (GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO) || (edge_length == pow2_edge_length))
-    {
-        /* Precalculated scaling for 'faked' non power of two texture coords. */
-        texture->baseTexture.pow2Matrix[0] = 1.0f;
-        texture->baseTexture.pow2Matrix[5] = 1.0f;
-        texture->baseTexture.pow2Matrix[10] = 1.0f;
-        texture->baseTexture.pow2Matrix[15] = 1.0f;
-    }
-    else
-    {
-        /* Precalculated scaling for 'faked' non power of two texture coords. */
-        texture->baseTexture.pow2Matrix[0] = ((float)edge_length) / ((float)pow2_edge_length);
-        texture->baseTexture.pow2Matrix[5] = ((float)edge_length) / ((float)pow2_edge_length);
-        texture->baseTexture.pow2Matrix[10] = ((float)edge_length) / ((float)pow2_edge_length);
-        texture->baseTexture.pow2Matrix[15] = 1.0f;
-        texture->baseTexture.pow2Matrix_identity = FALSE;
-    }
-
-    /* Generate all the surfaces. */
-    tmp_w = edge_length;
-    for (i = 0; i < texture->baseTexture.levels; ++i)
-    {
-        /* Create the 6 faces. */
-        for (j = 0; j < 6; ++j)
-        {
-            static const GLenum cube_targets[6] =
-            {
-                GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
-                GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
-                GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
-                GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
-                GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
-                GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
-            };
-
-            hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
-                    format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]);
-            if (FAILED(hr))
-            {
-                FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr);
-                texture->surfaces[j][i] = NULL;
-                cubetexture_cleanup(texture, D3DCB_DefaultDestroySurface);
-                return hr;
-            }
-
-            IWineD3DSurface_SetContainer(texture->surfaces[j][i], (IWineD3DBase *)texture);
-            TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[j][i]);
-            surface_set_texture_target(texture->surfaces[j][i], cube_targets[j]);
-        }
-        tmp_w = max(1, tmp_w >> 1);
-    }
-    texture->baseTexture.internal_preload = cubetexture_internal_preload;
-
-    return WINED3D_OK;
 }
 
@@ -298,6 +184,9 @@
     TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
     ref = InterlockedDecrement(&This->resource.ref);
-    if (ref == 0) {
-        IWineD3DCubeTexture_Destroy(iface, D3DCB_DefaultDestroySurface);
+    if (!ref)
+    {
+        cubetexture_cleanup(This);
+        This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
+        HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -414,7 +303,7 @@
             for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j) {
                 if(This->baseTexture.is_srgb) {
-                    surface_set_texture_name(This->surfaces[j][i], This->baseTexture.srgbTextureName, TRUE);
+                    surface_set_texture_name(This->surfaces[j][i], This->baseTexture.texture_srgb.name, TRUE);
                 } else {
-                    surface_set_texture_name(This->surfaces[j][i], This->baseTexture.textureName, FALSE);
+                    surface_set_texture_name(This->surfaces[j][i], This->baseTexture.texture_rgb.name, FALSE);
                 }
             }
@@ -442,12 +331,4 @@
    IWineD3DCubeTexture IWineD3DCubeTexture parts follow
    ******************************************* */
-static void WINAPI IWineD3DCubeTextureImpl_Destroy(IWineD3DCubeTexture *iface, D3DCB_DESTROYSURFACEFN D3DCB_DestroySurface) {
-    IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
-
-    cubetexture_cleanup(This, D3DCB_DestroySurface);
-    /* finally delete the object */
-    HeapFree(GetProcessHeap(), 0, This);
-}
-
 static HRESULT WINAPI IWineD3DCubeTextureImpl_GetLevelDesc(IWineD3DCubeTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
     IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
@@ -516,6 +397,6 @@
     HRESULT hr = WINED3DERR_INVALIDCALL;
     IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
-    This->baseTexture.dirty = TRUE;
-    This->baseTexture.srgbDirty = TRUE;
+    This->baseTexture.texture_rgb.dirty = TRUE;
+    This->baseTexture.texture_srgb.dirty = TRUE;
     TRACE("(%p) : dirtyfication of faceType(%d) Level (0)\n", This, FaceType);
     if (FaceType <= WINED3DCUBEMAP_FACE_NEGATIVE_Z) {
@@ -528,6 +409,5 @@
 }
 
-
-const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
+static const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl =
 {
     /* IUnknown */
@@ -559,5 +439,4 @@
     IWineD3DCubeTextureImpl_IsCondNP2,
     /* IWineD3DCubeTexture */
-    IWineD3DCubeTextureImpl_Destroy,
     IWineD3DCubeTextureImpl_GetLevelDesc,
     IWineD3DCubeTextureImpl_GetCubeMapSurface,
@@ -566,2 +445,120 @@
     IWineD3DCubeTextureImpl_AddDirtyRect
 };
+
+HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels,
+        IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+{
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
+    UINT pow2_edge_length;
+    unsigned int i, j;
+    UINT tmp_w;
+    HRESULT hr;
+
+    /* TODO: It should only be possible to create textures for formats
+     * that are reported as supported. */
+    if (WINED3DFMT_UNKNOWN >= format)
+    {
+        WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    if (!gl_info->supported[ARB_TEXTURE_CUBE_MAP] && pool != WINED3DPOOL_SCRATCH)
+    {
+        WARN("(%p) : Tried to create not supported cube texture.\n", texture);
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    /* Calculate levels for mip mapping */
+    if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
+    {
+        if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
+        {
+            WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
+            return WINED3DERR_INVALIDCALL;
+        }
+
+        if (levels > 1)
+        {
+            WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
+            return WINED3DERR_INVALIDCALL;
+        }
+
+        levels = 1;
+    }
+    else if (!levels)
+    {
+        levels = wined3d_log2i(edge_length) + 1;
+        TRACE("Calculated levels = %u.\n", levels);
+    }
+
+    texture->lpVtbl = &IWineD3DCubeTexture_Vtbl;
+
+    hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_CUBETEXTURE,
+            device, 0, usage, format_desc, pool, parent, parent_ops);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize basetexture, returning %#x\n", hr);
+        return hr;
+    }
+
+    /* Find the nearest pow2 match. */
+    pow2_edge_length = 1;
+    while (pow2_edge_length < edge_length) pow2_edge_length <<= 1;
+
+    if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] || (edge_length == pow2_edge_length))
+    {
+        /* Precalculated scaling for 'faked' non power of two texture coords. */
+        texture->baseTexture.pow2Matrix[0] = 1.0f;
+        texture->baseTexture.pow2Matrix[5] = 1.0f;
+        texture->baseTexture.pow2Matrix[10] = 1.0f;
+        texture->baseTexture.pow2Matrix[15] = 1.0f;
+    }
+    else
+    {
+        /* Precalculated scaling for 'faked' non power of two texture coords. */
+        texture->baseTexture.pow2Matrix[0] = ((float)edge_length) / ((float)pow2_edge_length);
+        texture->baseTexture.pow2Matrix[5] = ((float)edge_length) / ((float)pow2_edge_length);
+        texture->baseTexture.pow2Matrix[10] = ((float)edge_length) / ((float)pow2_edge_length);
+        texture->baseTexture.pow2Matrix[15] = 1.0f;
+        texture->baseTexture.pow2Matrix_identity = FALSE;
+    }
+
+    /* Generate all the surfaces. */
+    tmp_w = edge_length;
+    for (i = 0; i < texture->baseTexture.levels; ++i)
+    {
+        /* Create the 6 faces. */
+        for (j = 0; j < 6; ++j)
+        {
+            static const GLenum cube_targets[6] =
+            {
+                GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
+                GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
+                GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
+                GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
+                GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
+                GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB,
+            };
+
+            hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
+                    format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]);
+            if (FAILED(hr))
+            {
+                FIXME("(%p) Failed to create surface, hr %#x.\n", texture, hr);
+                texture->surfaces[j][i] = NULL;
+                cubetexture_cleanup(texture);
+                return hr;
+            }
+
+            IWineD3DSurface_SetContainer(texture->surfaces[j][i], (IWineD3DBase *)texture);
+            TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[j][i]);
+            surface_set_texture_target(texture->surfaces[j][i], cube_targets[j]);
+        }
+        tmp_w = max(1, tmp_w >> 1);
+    }
+    texture->baseTexture.internal_preload = cubetexture_internal_preload;
+
+    return WINED3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c	(revision 23571)
@@ -10,4 +10,5 @@
  * Copyright 2006-2008 Henri Verbeet
  * Copyright 2007 Andrew Riedi
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -192,5 +193,6 @@
     unsigned int i;
 
-    memset(stream_info, 0, sizeof(*stream_info));
+    stream_info->use_map = 0;
+    stream_info->swizzle_map = 0;
 
     /* Check for transformed vertices, disable vertex shader if present. */
@@ -306,5 +308,5 @@
             stream_info->elements[idx].buffer_object = buffer_object;
 
-            if (!GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA) && element->format_desc->format == WINED3DFMT_A8R8G8B8)
+            if (!GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA) && element->format_desc->format == WINED3DFMT_B8G8R8A8_UNORM)
             {
                 stream_info->swizzle_map |= 1 << idx;
@@ -368,5 +370,6 @@
         if (!stream_info->elements[i].format_desc) continue;
 
-        if (!GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA) && stream_info->elements[i].format_desc->format == WINED3DFMT_A8R8G8B8)
+        if (!GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA)
+                && stream_info->elements[i].format_desc->format == WINED3DFMT_B8G8R8A8_UNORM)
         {
             stream_info->swizzle_map |= 1 << i;
@@ -450,9 +453,8 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_CreateBuffer(IWineD3DDevice *iface,
-        struct wined3d_buffer_desc *desc, const void *data, IUnknown *parent, IWineD3DBuffer **buffer)
+static HRESULT WINAPI IWineD3DDeviceImpl_CreateBuffer(IWineD3DDevice *iface, struct wined3d_buffer_desc *desc,
+        const void *data, IUnknown *parent, const struct wined3d_parent_ops *parent_ops, IWineD3DBuffer **buffer)
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(WINED3DFMT_UNKNOWN, &This->adapter->gl_info);
     struct wined3d_buffer *object;
     HRESULT hr;
@@ -467,46 +469,17 @@
     }
 
-    object->vtbl = &wined3d_buffer_vtbl;
-    object->desc = *desc;
-
     FIXME("Ignoring access flags (pool)\n");
 
-    hr = resource_init((IWineD3DResource *)object, WINED3DRTYPE_BUFFER, This, desc->byte_width,
-            desc->usage, format_desc, WINED3DPOOL_MANAGED, parent);
+    hr = buffer_init(object, This, desc->byte_width, desc->usage, WINED3DFMT_UNKNOWN,
+            WINED3DPOOL_MANAGED, GL_ARRAY_BUFFER_ARB, data, parent, parent_ops);
     if (FAILED(hr))
     {
-        WARN("Failed to initialize resource, returning %#x\n", hr);
+        WARN("Failed to initialize buffer, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
         return hr;
     }
-    object->buffer_type_hint = GL_ARRAY_BUFFER_ARB;
-
-    TRACE("Created resource %p\n", object);
-
-    TRACE("size %#x, usage=%#x, format %s, memory @ %p, iface @ %p\n", object->resource.size, object->resource.usage,
-            debug_d3dformat(object->resource.format_desc->format), object->resource.allocatedMemory, object);
-
-    if (data)
-    {
-        BYTE *ptr;
-
-        hr = IWineD3DBuffer_Map((IWineD3DBuffer *)object, 0, desc->byte_width, &ptr, 0);
-        if (FAILED(hr))
-        {
-            ERR("Failed to map buffer, hr %#x\n", hr);
-            IWineD3DBuffer_Release((IWineD3DBuffer *)object);
-            return hr;
-        }
-
-        memcpy(ptr, data, desc->byte_width);
-
-        hr = IWineD3DBuffer_Unmap((IWineD3DBuffer *)object);
-        if (FAILED(hr))
-        {
-            ERR("Failed to unmap buffer, hr %#x\n", hr);
-            IWineD3DBuffer_Release((IWineD3DBuffer *)object);
-            return hr;
-        }
-    }
+    object->desc = *desc;
+
+    TRACE("Created buffer %p.\n", object);
 
     *buffer = (IWineD3DBuffer *)object;
@@ -515,10 +488,9 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexBuffer(IWineD3DDevice *iface, UINT Size, DWORD Usage,
-        DWORD FVF, WINED3DPOOL Pool, IWineD3DBuffer **ppVertexBuffer, IUnknown *parent)
+static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexBuffer(IWineD3DDevice *iface, UINT Size,
+        DWORD Usage, DWORD FVF, WINED3DPOOL Pool, IWineD3DBuffer **ppVertexBuffer,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    /* Dummy format for now */
-    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(WINED3DFMT_VERTEXDATA, &This->adapter->gl_info);
     struct wined3d_buffer *object;
     int dxVersion = ( (IWineD3DImpl *) This->wineD3D)->dxVersion;
@@ -526,9 +498,6 @@
     BOOL conv;
 
-    if(Size == 0) {
-        WARN("Size 0 requested, returning WINED3DERR_INVALIDCALL\n");
-        *ppVertexBuffer = NULL;
-        return WINED3DERR_INVALIDCALL;
-    } else if(Pool == WINED3DPOOL_SCRATCH) {
+    if (Pool == WINED3DPOOL_SCRATCH)
+    {
         /* The d3d9 testsuit shows that this is not allowed. It doesn't make much sense
          * anyway, SCRATCH vertex buffers aren't usable anywhere
@@ -547,18 +516,15 @@
     }
 
-    object->vtbl = &wined3d_buffer_vtbl;
-    hr = resource_init((IWineD3DResource *)object, WINED3DRTYPE_BUFFER, This, Size, Usage, format_desc, Pool, parent);
+    hr = buffer_init(object, This, Size, Usage, WINED3DFMT_VERTEXDATA,
+            Pool, GL_ARRAY_BUFFER_ARB, NULL, parent, parent_ops);
     if (FAILED(hr))
     {
-        WARN("Failed to initialize resource, returning %#x\n", hr);
+        WARN("Failed to initialize buffer, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *ppVertexBuffer = NULL;
         return hr;
     }
-    object->buffer_type_hint = GL_ARRAY_BUFFER_ARB;
-
-    TRACE("(%p) : Created resource %p\n", This, object);
-
-    TRACE("(%p) : Size=%d, Usage=0x%08x, FVF=%x, Pool=%d - Memory@%p, Iface@%p\n", This, Size, Usage, FVF, Pool, object->resource.allocatedMemory, object);
+
+    TRACE("Created buffer %p.\n", object);
+    TRACE("FVF %#x, Pool %#x.\n", FVF, Pool);
     *ppVertexBuffer = (IWineD3DBuffer *)object;
 
@@ -594,8 +560,8 @@
 
 static HRESULT WINAPI IWineD3DDeviceImpl_CreateIndexBuffer(IWineD3DDevice *iface,
-        UINT Length, DWORD Usage, WINED3DPOOL Pool, IWineD3DBuffer **ppIndexBuffer, IUnknown *parent)
+        UINT Length, DWORD Usage, WINED3DPOOL Pool, IWineD3DBuffer **ppIndexBuffer,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(WINED3DFMT_UNKNOWN, &This->adapter->gl_info);
     struct wined3d_buffer *object;
     HRESULT hr;
@@ -612,16 +578,14 @@
     }
 
-    object->vtbl = &wined3d_buffer_vtbl;
-    hr = resource_init((IWineD3DResource *)object, WINED3DRTYPE_BUFFER, This, Length, Usage, format_desc, Pool, parent);
+    hr = buffer_init(object, This, Length, Usage, WINED3DFMT_UNKNOWN,
+            Pool, GL_ELEMENT_ARRAY_BUFFER_ARB, NULL, parent, parent_ops);
     if (FAILED(hr))
     {
-        WARN("Failed to initialize resource, returning %#x\n", hr);
+        WARN("Failed to initialize buffer, hr %#x\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *ppIndexBuffer = NULL;
         return hr;
     }
-    object->buffer_type_hint = GL_ELEMENT_ARRAY_BUFFER_ARB;
-
-    TRACE("(%p) : Created resource %p\n", This, object);
+
+    TRACE("Created buffer %p.\n", object);
 
     if(Pool != WINED3DPOOL_SYSTEMMEM && !(Usage & WINED3DUSAGE_DYNAMIC) && GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT)) {
@@ -629,6 +593,4 @@
     }
 
-    TRACE("(%p) : Len=%d, Use=%x, Pool=%d - Memory@%p, Iface@%p\n", This, Length, Usage,
-            Pool, object, object->resource.allocatedMemory);
     *ppIndexBuffer = (IWineD3DBuffer *) object;
 
@@ -909,5 +871,5 @@
         WINED3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IWineD3DSurface **ppSurface,
         DWORD Usage, WINED3DPOOL Pool, WINED3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,
-        WINED3DSURFTYPE Impl, IUnknown *parent)
+        WINED3DSURFTYPE Impl, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
@@ -932,5 +894,5 @@
 
     hr = surface_init(object, Impl, This->surface_alignment, Width, Height, Level, Lockable,
-            Discard, MultiSample, MultisampleQuality, This, Usage, Format, Pool, parent);
+            Discard, MultiSample, MultisampleQuality, This, Usage, Format, Pool, parent, parent_ops);
     if (FAILED(hr))
     {
@@ -972,6 +934,6 @@
 
 static HRESULT WINAPI IWineD3DDeviceImpl_CreateTexture(IWineD3DDevice *iface,
-        UINT Width, UINT Height, UINT Levels, DWORD Usage, WINED3DFORMAT Format,
-        WINED3DPOOL Pool, IWineD3DTexture **ppTexture, IUnknown *parent)
+        UINT Width, UINT Height, UINT Levels, DWORD Usage, WINED3DFORMAT Format, WINED3DPOOL Pool,
+        IWineD3DTexture **ppTexture, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
@@ -991,7 +953,5 @@
     }
 
-    object->lpVtbl = &IWineD3DTexture_Vtbl;
-
-    hr = texture_init(object, Width, Height, Levels, This, Usage, Format, Pool, parent);
+    hr = texture_init(object, Width, Height, Levels, This, Usage, Format, Pool, parent, parent_ops);
     if (FAILED(hr))
     {
@@ -1010,6 +970,6 @@
 
 static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolumeTexture(IWineD3DDevice *iface,
-        UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, WINED3DFORMAT Format,
-        WINED3DPOOL Pool, IWineD3DVolumeTexture **ppVolumeTexture, IUnknown *parent)
+        UINT Width, UINT Height, UINT Depth, UINT Levels, DWORD Usage, WINED3DFORMAT Format, WINED3DPOOL Pool,
+        IWineD3DVolumeTexture **ppVolumeTexture, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
 {
     IWineD3DDeviceImpl        *This = (IWineD3DDeviceImpl *)iface;
@@ -1028,6 +988,5 @@
     }
 
-    object->lpVtbl = &IWineD3DVolumeTexture_Vtbl;
-    hr = volumetexture_init(object, Width, Height, Depth, Levels, This, Usage, Format, Pool, parent);
+    hr = volumetexture_init(object, Width, Height, Depth, Levels, This, Usage, Format, Pool, parent, parent_ops);
     if (FAILED(hr))
     {
@@ -1044,17 +1003,14 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolume(IWineD3DDevice *iface,
-        UINT Width, UINT Height, UINT Depth, DWORD Usage, WINED3DFORMAT Format,
-        WINED3DPOOL Pool, IWineD3DVolume **ppVolume, IUnknown *parent)
+static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolume(IWineD3DDevice *iface, UINT Width, UINT Height,
+        UINT Depth, DWORD Usage, WINED3DFORMAT Format, WINED3DPOOL Pool, IWineD3DVolume **ppVolume,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
 {
-    IWineD3DDeviceImpl        *This = (IWineD3DDeviceImpl *)iface;
-    IWineD3DVolumeImpl        *object; /** NOTE: impl ref allowed since this is a create function **/
-    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(Format, &GLINFO_LOCATION);
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    IWineD3DVolumeImpl *object;
     HRESULT hr;
 
-    if(!GL_SUPPORT(EXT_TEXTURE3D)) {
-        WARN("(%p) : Volume cannot be created - no volume texture support\n", This);
-        return WINED3DERR_INVALIDCALL;
-    }
+    TRACE("(%p) : W(%d) H(%d) D(%d), Usage(%d), Fmt(%u,%s), Pool(%s)\n", This, Width, Height,
+          Depth, Usage, Format, debug_d3dformat(Format), debug_d3dpool(Pool));
 
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
@@ -1066,40 +1022,21 @@
     }
 
-    object->lpVtbl = &IWineD3DVolume_Vtbl;
-    hr = resource_init((IWineD3DResource *)object, WINED3DRTYPE_VOLUME, This,
-            Width * Height * Depth * format_desc->byte_count, Usage, format_desc, Pool, parent);
+    hr = volume_init(object, This, Width, Height, Depth, Usage, Format, Pool, parent, parent_ops);
     if (FAILED(hr))
     {
-        WARN("Failed to initialize resource, returning %#x\n", hr);
+        WARN("Failed to initialize volume, returning %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *ppVolume = NULL;
         return hr;
     }
 
-    TRACE("(%p) : Created resource %p\n", This, object);
-
+    TRACE("(%p) : Created volume %p.\n", This, object);
     *ppVolume = (IWineD3DVolume *)object;
 
-    TRACE("(%p) : W(%d) H(%d) D(%d), Usage(%d), Fmt(%u,%s), Pool(%s)\n", This, Width, Height,
-          Depth, Usage, Format, debug_d3dformat(Format), debug_d3dpool(Pool));
-
-    object->currentDesc.Width   = Width;
-    object->currentDesc.Height  = Height;
-    object->currentDesc.Depth   = Depth;
-
-    /** Note: Volume textures cannot be dxtn, hence no need to check here **/
-    object->lockable            = TRUE;
-    object->locked              = FALSE;
-    memset(&object->lockedBox, 0, sizeof(WINED3DBOX));
-    object->dirty               = TRUE;
-
-    volume_add_dirty_box((IWineD3DVolume *)object, NULL);
-
-    return WINED3D_OK;
-}
-
-static HRESULT WINAPI IWineD3DDeviceImpl_CreateCubeTexture(IWineD3DDevice *iface,
-        UINT EdgeLength, UINT Levels, DWORD Usage, WINED3DFORMAT Format,
-        WINED3DPOOL Pool, IWineD3DCubeTexture **ppCubeTexture, IUnknown *parent)
+    return WINED3D_OK;
+}
+
+static HRESULT WINAPI IWineD3DDeviceImpl_CreateCubeTexture(IWineD3DDevice *iface, UINT EdgeLength, UINT Levels,
+        DWORD Usage, WINED3DFORMAT Format, WINED3DPOOL Pool, IWineD3DCubeTexture **ppCubeTexture,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
 {
     IWineD3DDeviceImpl      *This = (IWineD3DDeviceImpl *)iface;
@@ -1115,6 +1052,5 @@
     }
 
-    object->lpVtbl = &IWineD3DCubeTexture_Vtbl;
-    hr = cubetexture_init(object, EdgeLength, Levels, This, Usage, Format, Pool, parent);
+    hr = cubetexture_init(object, EdgeLength, Levels, This, Usage, Format, Pool, parent, parent_ops);
     if (FAILED(hr))
     {
@@ -1351,5 +1287,4 @@
     IWineD3DSwapChainImpl  *object; /** NOTE: impl ref allowed since this is a create function **/
     HRESULT                 hr;
-    IUnknown               *bufferParent;
     BOOL                    displaymode_set = FALSE;
     WINED3DDISPLAYMODE      Mode;
@@ -1612,11 +1547,5 @@
         UINT i;
         for(i = 0; i < object->presentParms.BackBufferCount; i++) {
-            if(object->backBuffer[i]) {
-                IWineD3DSurface_GetParent(object->backBuffer[i], &bufferParent);
-                IUnknown_Release(bufferParent); /* once for the get parent */
-                if (IUnknown_Release(bufferParent) > 0) {
-                    FIXME("(%p) Something's still holding the back buffer\n",This);
-                }
-            }
+            if (object->backBuffer[i]) IWineD3DSurface_Release(object->backBuffer[i]);
         }
         HeapFree(GetProcessHeap(), 0, object->backBuffer);
@@ -1625,11 +1554,5 @@
     if(object->context && object->context[0])
         DestroyContext(This, object->context[0]);
-    if(object->frontBuffer) {
-        IWineD3DSurface_GetParent(object->frontBuffer, &bufferParent);
-        IUnknown_Release(bufferParent); /* once for the get parent */
-        if (IUnknown_Release(bufferParent) > 0) {
-            FIXME("(%p) Something's still holding the front buffer\n",This);
-        }
-    }
+    if (object->frontBuffer) IWineD3DSurface_Release(object->frontBuffer);
     HeapFree(GetProcessHeap(), 0, object);
     return hr;
@@ -1660,39 +1583,34 @@
 }
 
-/*****
- * Vertex Declaration
- *****/
-static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexDeclaration(IWineD3DDevice* iface, IWineD3DVertexDeclaration** ppVertexDeclaration,
-        IUnknown *parent, const WINED3DVERTEXELEMENT *elements, UINT element_count) {
-    IWineD3DDeviceImpl            *This   = (IWineD3DDeviceImpl *)iface;
+static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexDeclaration(IWineD3DDevice *iface,
+        IWineD3DVertexDeclaration **declaration, IUnknown *parent, const struct wined3d_parent_ops *parent_ops,
+        const WINED3DVERTEXELEMENT *elements, UINT element_count)
+{
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     IWineD3DVertexDeclarationImpl *object = NULL;
-    HRESULT hr = WINED3D_OK;
-
-    TRACE("(%p) : directXVersion %u, elements %p, element_count %d, ppDecl=%p\n",
-            This, ((IWineD3DImpl *)This->wineD3D)->dxVersion, elements, element_count, ppVertexDeclaration);
+    HRESULT hr;
+
+    TRACE("iface %p, declaration %p, parent %p, elements %p, element_count %u.\n",
+            iface, declaration, parent, elements, element_count);
 
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if(!object)
     {
-        ERR("Out of memory\n");
-        *ppVertexDeclaration = NULL;
-        return WINED3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->lpVtbl = &IWineD3DVertexDeclaration_Vtbl;
-    object->wineD3DDevice = This;
-    object->parent = parent;
-    object->ref = 1;
-
-    *ppVertexDeclaration = (IWineD3DVertexDeclaration *)object;
-
-    hr = vertexdeclaration_init(object, elements, element_count);
-
-    if(FAILED(hr)) {
-        IWineD3DVertexDeclaration_Release((IWineD3DVertexDeclaration *)object);
-        *ppVertexDeclaration = NULL;
-    }
-
-    return hr;
+        ERR("Failed to allocate vertex declaration memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = vertexdeclaration_init(object, This, elements, element_count, parent, parent_ops);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created verrtex declaration %p.\n", object);
+    *declaration = (IWineD3DVertexDeclaration *)object;
+
+    return WINED3D_OK;
 }
 
@@ -1748,5 +1666,5 @@
     if (has_blend && (num_blends > 0)) {
         if (((fvf & WINED3DFVF_XYZB5) == WINED3DFVF_XYZB2) && (fvf & WINED3DFVF_LASTBETA_D3DCOLOR))
-            elements[idx].format = WINED3DFMT_A8R8G8B8;
+            elements[idx].format = WINED3DFMT_B8G8R8A8_UNORM;
         else {
             switch(num_blends) {
@@ -1768,5 +1686,5 @@
             elements[idx].format = WINED3DFMT_R8G8B8A8_UINT;
         else if (fvf & WINED3DFVF_LASTBETA_D3DCOLOR)
-            elements[idx].format = WINED3DFMT_A8R8G8B8;
+            elements[idx].format = WINED3DFMT_B8G8R8A8_UNORM;
         else
             elements[idx].format = WINED3DFMT_R32_FLOAT;
@@ -1788,5 +1706,5 @@
     }
     if (has_diffuse) {
-        elements[idx].format = WINED3DFMT_A8R8G8B8;
+        elements[idx].format = WINED3DFMT_B8G8R8A8_UNORM;
         elements[idx].usage = WINED3DDECLUSAGE_COLOR;
         elements[idx].usage_idx = 0;
@@ -1794,5 +1712,5 @@
     }
     if (has_specular) {
-        elements[idx].format = WINED3DFMT_A8R8G8B8;
+        elements[idx].format = WINED3DFMT_B8G8R8A8_UNORM;
         elements[idx].usage = WINED3DDECLUSAGE_COLOR;
         elements[idx].usage_idx = 1;
@@ -1834,94 +1752,81 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexDeclarationFromFVF(IWineD3DDevice* iface, IWineD3DVertexDeclaration** ppVertexDeclaration, IUnknown *Parent, DWORD Fvf) {
-    WINED3DVERTEXELEMENT* elements = NULL;
+static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexDeclarationFromFVF(IWineD3DDevice *iface,
+        IWineD3DVertexDeclaration **declaration, IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops, DWORD fvf)
+{
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
+    WINED3DVERTEXELEMENT *elements;
     unsigned int size;
     DWORD hr;
 
-    size = ConvertFvfToDeclaration(This, Fvf, &elements);
-    if (size == ~0U) return WINED3DERR_OUTOFVIDEOMEMORY;
-
-    hr = IWineD3DDevice_CreateVertexDeclaration(iface, ppVertexDeclaration, Parent, elements, size);
+    TRACE("iface %p, declaration %p, parent %p, fvf %#x.\n", iface, declaration, parent, fvf);
+
+    size = ConvertFvfToDeclaration(This, fvf, &elements);
+    if (size == ~0U) return E_OUTOFMEMORY;
+
+    hr = IWineD3DDevice_CreateVertexDeclaration(iface, declaration, parent, parent_ops, elements, size);
     HeapFree(GetProcessHeap(), 0, elements);
-    if (hr != S_OK) return hr;
-
-    return WINED3D_OK;
+    return hr;
 }
 
 static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexShader(IWineD3DDevice *iface,
         const DWORD *pFunction, const struct wined3d_shader_signature *output_signature,
-        IWineD3DVertexShader **ppVertexShader, IUnknown *parent)
+        IWineD3DVertexShader **ppVertexShader, IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops)
 {
-    IWineD3DDeviceImpl       *This = (IWineD3DDeviceImpl *)iface;
-    IWineD3DVertexShaderImpl *object;  /* NOTE: impl usage is ok, this is a create */
-    HRESULT hr = WINED3D_OK;
-
-    if (!pFunction) return WINED3DERR_INVALIDCALL;
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    IWineD3DVertexShaderImpl *object;
+    HRESULT hr;
 
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (!object)
     {
-        ERR("Out of memory\n");
-        *ppVertexShader = NULL;
-        return WINED3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->lpVtbl = &IWineD3DVertexShader_Vtbl;
-    object->parent = parent;
-    shader_init(&object->baseShader, iface);
-    list_add_head(&This->shaders, &object->baseShader.shader_list_entry);
-    *ppVertexShader = (IWineD3DVertexShader *)object;
-
-    TRACE("(%p) : Created vertex shader %p\n", This, *ppVertexShader);
-
-    hr = IWineD3DVertexShader_SetFunction(*ppVertexShader, pFunction, output_signature);
+        ERR("Failed to allocate shader memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = vertexshader_init(object, This, pFunction, output_signature, parent, parent_ops);
     if (FAILED(hr))
     {
-        WARN("(%p) : Failed to set function, returning %#x\n", iface, hr);
-        IWineD3DVertexShader_Release(*ppVertexShader);
-        *ppVertexShader = NULL;
+        WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
         return hr;
     }
 
-    return hr;
+    TRACE("Created vertex shader %p.\n", object);
+    *ppVertexShader = (IWineD3DVertexShader *)object;
+
+    return WINED3D_OK;
 }
 
 static HRESULT WINAPI IWineD3DDeviceImpl_CreatePixelShader(IWineD3DDevice *iface,
         const DWORD *pFunction, const struct wined3d_shader_signature *output_signature,
-        IWineD3DPixelShader **ppPixelShader, IUnknown *parent)
+        IWineD3DPixelShader **ppPixelShader, IUnknown *parent,
+        const struct wined3d_parent_ops *parent_ops)
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    IWineD3DPixelShaderImpl *object; /* NOTE: impl allowed, this is a create */
-    HRESULT hr = WINED3D_OK;
-
-    if (!pFunction) return WINED3DERR_INVALIDCALL;
+    IWineD3DPixelShaderImpl *object;
+    HRESULT hr;
 
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (!object)
     {
-        ERR("Out of memory\n");
-        *ppPixelShader = NULL;
-        return WINED3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    object->lpVtbl = &IWineD3DPixelShader_Vtbl;
-    object->parent = parent;
-    shader_init(&object->baseShader, iface);
-    list_add_head(&This->shaders, &object->baseShader.shader_list_entry);
-    *ppPixelShader = (IWineD3DPixelShader *)object;
-
-    TRACE("(%p) : Created pixel shader %p\n", This, *ppPixelShader);
-
-    hr = IWineD3DPixelShader_SetFunction(*ppPixelShader, pFunction, output_signature);
+        ERR("Failed to allocate shader memory.\n");
+        return E_OUTOFMEMORY;
+    }
+
+    hr = pixelshader_init(object, This, pFunction, output_signature, parent, parent_ops);
     if (FAILED(hr))
     {
-        WARN("(%p) : Failed to set function, returning %#x\n", iface, hr);
-        IWineD3DPixelShader_Release(*ppPixelShader);
-        *ppPixelShader = NULL;
+        WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
         return hr;
     }
 
-    return hr;
+    TRACE("Created pixel shader %p.\n", object);
+    *ppPixelShader = (IWineD3DPixelShader *)object;
+
+    return WINED3D_OK;
 }
 
@@ -1990,6 +1895,7 @@
     }
 
-    hr = IWineD3DDevice_CreateSurface((IWineD3DDevice *) This, bm.bmWidth, bm.bmHeight, WINED3DFMT_R5G6B5, TRUE,
-            FALSE, 0, &This->logo_surface, 0, WINED3DPOOL_DEFAULT, WINED3DMULTISAMPLE_NONE, 0, SURFACE_OPENGL, NULL);
+    hr = IWineD3DDevice_CreateSurface((IWineD3DDevice *)This, bm.bmWidth, bm.bmHeight, WINED3DFMT_B5G6R5_UNORM, TRUE,
+            FALSE, 0, &This->logo_surface, 0, WINED3DPOOL_DEFAULT, WINED3DMULTISAMPLE_NONE, 0, SURFACE_OPENGL,
+            NULL, &wined3d_null_parent_ops);
     if(FAILED(hr)) {
         ERR("Wine logo requested, but failed to create surface\n");
@@ -2123,6 +2029,6 @@
             This->rev_tex_unit_map[state] = state;
         } else {
-            This->texUnitMap[state] = -1;
-            This->rev_tex_unit_map[state] = -1;
+            This->texUnitMap[state] = WINED3D_UNMAPPED_STAGE;
+            This->rev_tex_unit_map[state] = WINED3D_UNMAPPED_STAGE;
         }
     }
@@ -2295,6 +2201,10 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_Uninit3D(IWineD3DDevice *iface, D3DCB_DESTROYSURFACEFN D3DCB_DestroyDepthStencilSurface, D3DCB_DESTROYSWAPCHAINFN D3DCB_DestroySwapChain) {
+static HRESULT WINAPI IWineD3DDeviceImpl_Uninit3D(IWineD3DDevice *iface,
+        D3DCB_DESTROYSWAPCHAINFN D3DCB_DestroySwapChain)
+{
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
+    const struct wined3d_context *context;
+    const struct wined3d_gl_info *gl_info;
     int sampler;
     UINT i;
@@ -2306,5 +2216,6 @@
      * it was created. Thus make sure a context is active for the glDelete* calls
      */
-    ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+    context = ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+    gl_info = context->gl_info;
 
     if(This->logo_surface) IWineD3DSurface_Release(This->logo_surface);
@@ -2360,5 +2271,5 @@
     if (This->depth_blt_rb) {
         ENTER_GL();
-        GL_EXTCALL(glDeleteRenderbuffersEXT(1, &This->depth_blt_rb));
+        gl_info->fbo_ops.glDeleteRenderbuffers(1, &This->depth_blt_rb);
         LEAVE_GL();
         This->depth_blt_rb = 0;
@@ -2407,5 +2318,6 @@
 
     if (This->auto_depth_stencil_buffer) {
-        if(D3DCB_DestroyDepthStencilSurface(This->auto_depth_stencil_buffer) > 0) {
+        if (IWineD3DSurface_Release(This->auto_depth_stencil_buffer) > 0)
+        {
             FIXME("(%p) Something's still holding the auto depth stencil buffer\n", This);
         }
@@ -3163,6 +3075,8 @@
  * Get / Set Indices
  *****/
-static HRESULT WINAPI IWineD3DDeviceImpl_SetIndices(IWineD3DDevice *iface, IWineD3DBuffer* pIndexData, WINED3DFORMAT fmt) {
-    IWineD3DDeviceImpl  *This = (IWineD3DDeviceImpl *)iface;
+static HRESULT WINAPI IWineD3DDeviceImpl_SetIndexBuffer(IWineD3DDevice *iface,
+        IWineD3DBuffer *pIndexData, WINED3DFORMAT fmt)
+{
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     IWineD3DBuffer *oldIdxs;
 
@@ -3197,5 +3111,6 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_GetIndices(IWineD3DDevice *iface, IWineD3DBuffer** ppIndexData) {
+static HRESULT WINAPI IWineD3DDeviceImpl_GetIndexBuffer(IWineD3DDevice *iface, IWineD3DBuffer **ppIndexData)
+{
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
 
@@ -3645,16 +3560,19 @@
 }
 
-static void device_map_stage(IWineD3DDeviceImpl *This, int stage, int unit) {
-    int i = This->rev_tex_unit_map[unit];
-    int j = This->texUnitMap[stage];
+static void device_map_stage(IWineD3DDeviceImpl *This, DWORD stage, DWORD unit)
+{
+    DWORD i = This->rev_tex_unit_map[unit];
+    DWORD j = This->texUnitMap[stage];
 
     This->texUnitMap[stage] = unit;
-    if (i != -1 && i != stage) {
-        This->texUnitMap[i] = -1;
+    if (i != WINED3D_UNMAPPED_STAGE && i != stage)
+    {
+        This->texUnitMap[i] = WINED3D_UNMAPPED_STAGE;
     }
 
     This->rev_tex_unit_map[unit] = stage;
-    if (j != -1 && j != unit) {
-        This->rev_tex_unit_map[j] = -1;
+    if (j != WINED3D_UNMAPPED_STAGE && j != unit)
+    {
+        This->rev_tex_unit_map[j] = WINED3D_UNMAPPED_STAGE;
     }
 }
@@ -3750,12 +3668,10 @@
 
 static BOOL device_unit_free_for_vs(IWineD3DDeviceImpl *This, const DWORD *pshader_sampler_tokens,
-        const DWORD *vshader_sampler_tokens, int unit)
+        const DWORD *vshader_sampler_tokens, DWORD unit)
 {
-    int current_mapping = This->rev_tex_unit_map[unit];
-
-    if (current_mapping == -1) {
-        /* Not currently used */
-        return TRUE;
-    }
+    DWORD current_mapping = This->rev_tex_unit_map[unit];
+
+    /* Not currently used */
+    if (current_mapping == WINED3D_UNMAPPED_STAGE) return TRUE;
 
     if (current_mapping < MAX_FRAGMENT_SAMPLERS) {
@@ -3772,5 +3688,5 @@
 
     /* Used by a vertex sampler */
-    return !vshader_sampler_tokens[current_mapping];
+    return !vshader_sampler_tokens[current_mapping - MAX_FRAGMENT_SAMPLERS];
 }
 
@@ -3779,5 +3695,5 @@
             ((IWineD3DVertexShaderImpl *)This->stateBlock->vertexShader)->baseShader.reg_maps.sampler_type;
     const WINED3DSAMPLER_TEXTURE_TYPE *pshader_sampler_type = NULL;
-    int start = GL_LIMITS(combined_samplers) - 1;
+    int start = min(MAX_COMBINED_SAMPLERS, GL_LIMITS(combined_samplers)) - 1;
     int i;
 
@@ -3791,5 +3707,5 @@
 
     for (i = 0; i < MAX_VERTEX_SAMPLERS; ++i) {
-        int vsampler_idx = i + MAX_FRAGMENT_SAMPLERS;
+        DWORD vsampler_idx = i + MAX_FRAGMENT_SAMPLERS;
         if (vshader_sampler_type[i])
         {
@@ -4045,10 +3961,10 @@
     DWORD numTextures;
 
-    if (stream_info->elements[WINED3D_FFP_NORMAL].data)
+    if (stream_info->use_map & (1 << WINED3D_FFP_NORMAL))
     {
         WARN(" lighting state not saved yet... Some strange stuff may happen !\n");
     }
 
-    if (!stream_info->elements[WINED3D_FFP_POSITION].data)
+    if (!(stream_info->use_map & (1 << WINED3D_FFP_POSITION)))
     {
         ERR("Source has no position mask\n");
@@ -4186,5 +4102,5 @@
             if( !doClip ||
                 ( (-rhw -eps < x) && (-rhw -eps < y) && ( -eps < z) &&
-                  (x <= rhw + eps) && (y <= rhw + eps ) && (z <= rhw + eps) && 
+                  (x <= rhw + eps) && (y <= rhw + eps ) && (z <= rhw + eps) &&
                   ( rhw > eps ) ) ) {
 
@@ -4283,5 +4199,6 @@
             const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_DIFFUSE];
             const DWORD *color_d = (const DWORD *)(element->data + i * element->stride);
-            if(!color_d) {
+            if (!(stream_info->use_map & (1 << WINED3D_FFP_DIFFUSE)))
+            {
                 static BOOL warned = FALSE;
 
@@ -4310,9 +4227,11 @@
         }
 
-        if (DestFVF & WINED3DFVF_SPECULAR) { 
+        if (DestFVF & WINED3DFVF_SPECULAR)
+        {
             /* What's the color value in the feedback buffer? */
             const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_SPECULAR];
             const DWORD *color_s = (const DWORD *)(element->data + i * element->stride);
-            if(!color_s) {
+            if (!(stream_info->use_map & (1 << WINED3D_FFP_SPECULAR)))
+            {
                 static BOOL warned = FALSE;
 
@@ -4344,5 +4263,6 @@
             const struct wined3d_stream_info_element *element = &stream_info->elements[WINED3D_FFP_TEXCOORD0 + tex_index];
             const float *tex_coord = (const float *)(element->data + i * element->stride);
-            if(!tex_coord) {
+            if (!(stream_info->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + tex_index))))
+            {
                 ERR("No source texture, but destination requests one\n");
                 dest_ptr+=GET_TEXCOORD_SIZE_FROM_FVF(DestFVF, tex_index) * sizeof(float);
@@ -4406,5 +4326,9 @@
         for (i = 0; i < (sizeof(stream_info.elements) / sizeof(*stream_info.elements)); ++i)
         {
-            struct wined3d_stream_info_element *e = &stream_info.elements[i];
+            struct wined3d_stream_info_element *e;
+
+            if (!(stream_info.use_map & (1 << i))) continue;
+
+            e = &stream_info.elements[i];
             if (e->buffer_object)
             {
@@ -4856,5 +4780,5 @@
     ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
     /* We only have to do this if we need to read the, swapbuffers performs a flush for us */
-    glFlush();
+    wglFlush();
     /* No checkGLcall here to avoid locking the lock just for checking a call that hardly ever
      * fails
@@ -5069,5 +4993,5 @@
     if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *)target, &IID_IWineD3DSwapChain, (void **)&swapchain))) {
         if (target == (IWineD3DSurfaceImpl*) swapchain->frontBuffer) {
-            glFlush();
+            wglFlush();
         }
         IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
@@ -5143,11 +5067,9 @@
     }
     /* Account for the loading offset due to index buffers. Instead of reloading all sources correct it with the startvertex parameter */
-    drawPrimitive(iface, vertex_count, 0/* NumVertices */, StartVertex /* start_idx */,
-                  0 /* indxSize */, NULL /* indxData */, 0 /* minIndex */);
-    return WINED3D_OK;
-}
-
-static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitive(IWineD3DDevice *iface,
-        UINT minIndex, UINT NumVertices, UINT startIndex, UINT index_count)
+    drawPrimitive(iface, vertex_count, StartVertex /* start_idx */, 0 /* indxSize */, NULL /* indxData */);
+    return WINED3D_OK;
+}
+
+static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitive(IWineD3DDevice *iface, UINT startIndex, UINT index_count)
 {
     IWineD3DDeviceImpl  *This = (IWineD3DDeviceImpl *)iface;
@@ -5177,6 +5099,5 @@
     vbo = ((struct wined3d_buffer *) pIB)->buffer_object;
 
-    TRACE("(%p) : min %u, vertex count %u, startIdx %u, index count %u\n",
-            This, minIndex, NumVertices, startIndex, index_count);
+    TRACE("(%p) : startIndex %u, index count %u.\n", This, startIndex, index_count);
 
     if (This->stateBlock->IndexFmt == WINED3DFMT_R16_UINT) {
@@ -5191,6 +5112,6 @@
     }
 
-    drawPrimitive(iface, index_count, NumVertices, startIndex, idxStride,
-            vbo ? NULL : ((struct wined3d_buffer *) pIB)->resource.allocatedMemory, minIndex);
+    drawPrimitive(iface, index_count, startIndex, idxStride,
+            vbo ? NULL : ((struct wined3d_buffer *)pIB)->resource.allocatedMemory);
 
     return WINED3D_OK;
@@ -5223,6 +5144,5 @@
     IWineD3DDeviceImpl_MarkStateDirty(This, STATE_STREAMSRC);
 
-    drawPrimitive(iface, vertex_count, 0 /* NumVertices */, 0 /* start_idx */,
-            0 /* indxSize*/, NULL /* indxData */, 0 /* indxMin */);
+    drawPrimitive(iface, vertex_count, 0 /* start_idx */, 0 /* indxSize*/, NULL /* indxData */);
 
     /* MSDN specifies stream zero settings must be set to NULL */
@@ -5236,6 +5156,6 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveUP(IWineD3DDevice *iface, UINT MinVertexIndex,
-        UINT NumVertices, UINT index_count, const void *pIndexData, WINED3DFORMAT IndexDataFormat,
+static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveUP(IWineD3DDevice *iface,
+        UINT index_count, const void *pIndexData, WINED3DFORMAT IndexDataFormat,
         const void *pVertexStreamZeroData, UINT VertexStreamZeroStride)
 {
@@ -5245,7 +5165,6 @@
     IWineD3DBuffer *ib;
 
-    TRACE("(%p) : MinVtxIdx %u, NumVIdx %u, index count %u, pidxdata %p, IdxFmt %u, pVtxdata %p, stride=%u\n",
-            This, MinVertexIndex, NumVertices, index_count, pIndexData,
-            IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
+    TRACE("(%p) : index count %u, pidxdata %p, IdxFmt %u, pVtxdata %p, stride=%u.\n",
+            This, index_count, pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
 
     if(!This->stateBlock->vertexDecl) {
@@ -5275,6 +5194,5 @@
     IWineD3DDeviceImpl_MarkStateDirty(This, STATE_INDEXBUFFER);
 
-    drawPrimitive(iface, index_count, NumVertices, 0 /* start_idx */,
-            idxStride, pIndexData, MinVertexIndex);
+    drawPrimitive(iface, index_count, 0 /* start_idx */, idxStride, pIndexData);
 
     /* MSDN specifies stream zero settings and index buffer must be set to NULL */
@@ -5306,5 +5224,5 @@
     This->stateBlock->baseVertexIndex = 0;
     This->up_strided = DrawPrimStrideData;
-    drawPrimitive(iface, vertex_count, 0, 0, 0, NULL, 0);
+    drawPrimitive(iface, vertex_count, 0, 0, NULL);
     This->up_strided = NULL;
     return WINED3D_OK;
@@ -5327,5 +5245,5 @@
     This->stateBlock->baseVertexIndex = 0;
     This->up_strided = DrawPrimStrideData;
-    drawPrimitive(iface, vertex_count, 0 /* numindices */, 0 /* start_idx */, idxSize, pIndexData, 0 /* minindex */);
+    drawPrimitive(iface, 0 /* numindices */, 0 /* start_idx */, idxSize, pIndexData);
     This->up_strided = NULL;
     return WINED3D_OK;
@@ -5550,12 +5468,13 @@
     int i;
 
-    for (i = 0; i < MAX_COMBINED_SAMPLERS; i++) {
-            IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl*)device->stateBlock->textures[i];
-            if (texture && (texture->resource.format_desc->format == WINED3DFMT_P8
-                    || texture->resource.format_desc->format == WINED3DFMT_A8P8))
-            {
-                IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(i));
-            }
-        }
+    for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
+    {
+        IWineD3DBaseTextureImpl *texture = (IWineD3DBaseTextureImpl*)device->stateBlock->textures[i];
+        if (texture && (texture->resource.format_desc->format == WINED3DFMT_P8_UINT
+                || texture->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM))
+        {
+            IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(i));
+        }
+    }
 }
 
@@ -5741,5 +5660,5 @@
     const struct GlPixelFormatDesc *src_format_desc, *dst_format_desc;
     GLenum dummy;
-    int sampler;
+    DWORD sampler;
     int bpp;
     CONVERT_TYPES convert = NO_CONVERSION;
@@ -5881,5 +5800,6 @@
     IWineD3DSurface_ModifyLocation(pDestinationSurface, SFLAG_INTEXTURE, TRUE);
     sampler = This->rev_tex_unit_map[0];
-    if (sampler != -1) {
+    if (sampler != WINED3D_UNMAPPED_STAGE)
+    {
         IWineD3DDeviceImpl_MarkStateDirty(This, STATE_SAMPLER(sampler));
     }
@@ -6034,5 +5954,5 @@
         context = ActivateContext(This, surface, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
-        context_bind_fbo(context, GL_FRAMEBUFFER_EXT, NULL);
+        context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
         buffer = surface_get_gl_buffer(surface, swapchain);
         glDrawBuffer(buffer);
@@ -6043,7 +5963,7 @@
         context = ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
-        context_bind_fbo(context, GL_FRAMEBUFFER_EXT, &context->dst_fbo);
-        context_attach_surface_fbo(context, GL_FRAMEBUFFER_EXT, 0, surface);
-        context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER_EXT, NULL, FALSE);
+        context_bind_fbo(context, GL_FRAMEBUFFER, &context->dst_fbo);
+        context_attach_surface_fbo(context, GL_FRAMEBUFFER, 0, surface);
+        context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, NULL, FALSE);
     }
 
@@ -6086,6 +6006,7 @@
     DWORD ret;
 
-    if(destfmt == WINED3DFMT_A8R8G8B8 || destfmt == WINED3DFMT_X8R8G8B8 ||
-       destfmt == WINED3DFMT_R8G8B8)
+    if (destfmt == WINED3DFMT_B8G8R8A8_UNORM
+            || destfmt == WINED3DFMT_B8G8R8X8_UNORM
+            || destfmt == WINED3DFMT_B8G8R8_UNORM)
         return color;
 
@@ -6099,5 +6020,5 @@
     switch(destfmt)
     {
-        case WINED3DFMT_R5G6B5:
+        case WINED3DFMT_B5G6R5_UNORM:
             if(r == 0xff && g == 0xff && b == 0xff) return 0xffff;
             r = (r * 32) / 256;
@@ -6110,6 +6031,6 @@
             return ret;
 
-        case WINED3DFMT_X1R5G5B5:
-        case WINED3DFMT_A1R5G5B5:
+        case WINED3DFMT_B5G5R5X1_UNORM:
+        case WINED3DFMT_B5G5R5A1_UNORM:
             a = (a *  2) / 256;
             r = (r * 32) / 256;
@@ -6127,6 +6048,6 @@
             return a;
 
-        case WINED3DFMT_X4R4G4B4:
-        case WINED3DFMT_A4R4G4B4:
+        case WINED3DFMT_B4G4R4X4_UNORM:
+        case WINED3DFMT_B4G4R4A4_UNORM:
             a = (a * 16) / 256;
             r = (r * 16) / 256;
@@ -6140,5 +6061,5 @@
             return ret;
 
-        case WINED3DFMT_R3G3B2:
+        case WINED3DFMT_B2G3R3_UNORM:
             r = (r * 8) / 256;
             g = (g * 8) / 256;
@@ -6150,5 +6071,5 @@
             return ret;
 
-        case WINED3DFMT_X8B8G8R8:
+        case WINED3DFMT_R8G8B8X8_UNORM:
         case WINED3DFMT_R8G8B8A8_UNORM:
             ret  = a << 24;
@@ -6159,5 +6080,5 @@
             return ret;
 
-        case WINED3DFMT_A2R10G10B10:
+        case WINED3DFMT_B10G10R10A2_UNORM:
             a = (a *    4) / 256;
             r = (r * 1024) / 256;
@@ -6402,4 +6323,5 @@
     GLbitfield mask = GL_COLOR_BUFFER_BIT; /* TODO: Support blitting depth/stencil surfaces */
     IWineD3DSwapChain *src_swapchain, *dst_swapchain;
+    const struct wined3d_gl_info *gl_info;
     struct wined3d_context *context;
     GLenum gl_filter;
@@ -6431,4 +6353,6 @@
     else if (dst_swapchain) context = ActivateContext(This, dst_surface, CTXUSAGE_RESOURCELOAD);
     else context = ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+
+    gl_info = context->gl_info;
 
     if (src_swapchain) {
@@ -6455,5 +6379,5 @@
 
         ENTER_GL();
-        context_bind_fbo(context, GL_READ_FRAMEBUFFER_EXT, NULL);
+        context_bind_fbo(context, GL_READ_FRAMEBUFFER, NULL);
         glReadBuffer(buffer);
         checkGLcall("glReadBuffer()");
@@ -6461,9 +6385,9 @@
         TRACE("Source surface %p is offscreen\n", src_surface);
         ENTER_GL();
-        context_bind_fbo(context, GL_READ_FRAMEBUFFER_EXT, &context->src_fbo);
-        context_attach_surface_fbo(context, GL_READ_FRAMEBUFFER_EXT, 0, src_surface);
-        glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
+        context_bind_fbo(context, GL_READ_FRAMEBUFFER, &context->src_fbo);
+        context_attach_surface_fbo(context, GL_READ_FRAMEBUFFER, 0, src_surface);
+        glReadBuffer(GL_COLOR_ATTACHMENT0);
         checkGLcall("glReadBuffer()");
-        context_attach_depth_stencil_fbo(context, GL_READ_FRAMEBUFFER_EXT, NULL, FALSE);
+        context_attach_depth_stencil_fbo(context, GL_READ_FRAMEBUFFER, NULL, FALSE);
     }
     LEAVE_GL();
@@ -6494,5 +6418,5 @@
 
         ENTER_GL();
-        context_bind_fbo(context, GL_DRAW_FRAMEBUFFER_EXT, NULL);
+        context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, NULL);
         glDrawBuffer(buffer);
         checkGLcall("glDrawBuffer()");
@@ -6501,9 +6425,9 @@
 
         ENTER_GL();
-        context_bind_fbo(context, GL_DRAW_FRAMEBUFFER_EXT, &context->dst_fbo);
-        context_attach_surface_fbo(context, GL_DRAW_FRAMEBUFFER_EXT, 0, dst_surface);
-        glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
+        context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, &context->dst_fbo);
+        context_attach_surface_fbo(context, GL_DRAW_FRAMEBUFFER, 0, dst_surface);
+        glDrawBuffer(GL_COLOR_ATTACHMENT0);
         checkGLcall("glDrawBuffer()");
-        context_attach_depth_stencil_fbo(context, GL_DRAW_FRAMEBUFFER_EXT, NULL, FALSE);
+        context_attach_depth_stencil_fbo(context, GL_DRAW_FRAMEBUFFER, NULL, FALSE);
     }
     glDisable(GL_SCISSOR_TEST);
@@ -6511,10 +6435,10 @@
 
     if (flip) {
-        GL_EXTCALL(glBlitFramebufferEXT(src_rect->x1, src_rect->y1, src_rect->x2, src_rect->y2,
-                dst_rect->x1, dst_rect->y2, dst_rect->x2, dst_rect->y1, mask, gl_filter));
+        gl_info->fbo_ops.glBlitFramebuffer(src_rect->x1, src_rect->y1, src_rect->x2, src_rect->y2,
+                dst_rect->x1, dst_rect->y2, dst_rect->x2, dst_rect->y1, mask, gl_filter);
         checkGLcall("glBlitFramebuffer()");
     } else {
-        GL_EXTCALL(glBlitFramebufferEXT(src_rect->x1, src_rect->y1, src_rect->x2, src_rect->y2,
-                dst_rect->x1, dst_rect->y1, dst_rect->x2, dst_rect->y2, mask, gl_filter));
+        gl_info->fbo_ops.glBlitFramebuffer(src_rect->x1, src_rect->y1, src_rect->x2, src_rect->y2,
+                dst_rect->x1, dst_rect->y1, dst_rect->x2, dst_rect->y2, mask, gl_filter);
         checkGLcall("glBlitFramebuffer()");
     }
@@ -6575,8 +6499,4 @@
         viewport.MinZ   = 0.0f;
         IWineD3DDeviceImpl_SetViewport(iface, &viewport);
-        /* Make sure the viewport state is dirty, because the render_offscreen thing affects it.
-         * SetViewport may catch NOP viewport changes, which would occur when switching between equally sized targets
-         */
-        IWineD3DDeviceImpl_MarkStateDirty(This, STATE_VIEWPORT);
     }
     return WINED3D_OK;
@@ -6656,5 +6576,5 @@
 
         /* MSDN: Cursor must be A8R8G8B8 */
-        if (WINED3DFMT_A8R8G8B8 != pSur->resource.format_desc->format)
+        if (pSur->resource.format_desc->format != WINED3DFMT_B8G8R8A8_UNORM)
         {
             ERR("(%p) : surface(%p) has an invalid format\n", This, pCursorBitmap);
@@ -6682,5 +6602,6 @@
             if (SUCCEEDED(IWineD3DSurface_LockRect(pCursorBitmap, &rect, NULL, WINED3DLOCK_READONLY)))
             {
-                const struct GlPixelFormatDesc *glDesc = getFormatDescEntry(WINED3DFMT_A8R8G8B8, &GLINFO_LOCATION);
+                const struct GlPixelFormatDesc *glDesc =
+                        getFormatDescEntry(WINED3DFMT_B8G8R8A8_UNORM, &GLINFO_LOCATION);
                 char *mem, *bits = rect.pBits;
                 GLint intfmt = glDesc->glInternal;
@@ -6690,5 +6611,6 @@
                 INT width = This->cursorWidth;
                 INT bpp = glDesc->byte_count;
-                INT i, sampler;
+                DWORD sampler;
+                INT i;
 
                 /* Reformat the texture memory (pitch and width can be
@@ -6712,5 +6634,6 @@
                 checkGLcall("glActiveTextureARB");
                 sampler = This->rev_tex_unit_map[0];
-                if (sampler != -1) {
+                if (sampler != WINED3D_UNMAPPED_STAGE)
+                {
                     IWineD3DDeviceImpl_MarkStateDirty(This, STATE_SAMPLER(sampler));
                 }
@@ -6962,8 +6885,11 @@
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
     IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *) swapchain_iface;
+    const struct wined3d_context *context;
+    const struct wined3d_gl_info *gl_info;
     UINT i;
     IWineD3DBaseShaderImpl *shader;
 
-    ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+    context = ActivateContext(This, NULL, CTXUSAGE_RESOURCELOAD);
+    gl_info = context->gl_info;
 
     IWineD3DDevice_EnumResources(iface, reset_unload_resources, NULL);
@@ -6978,5 +6904,5 @@
     }
     if (This->depth_blt_rb) {
-        GL_EXTCALL(glDeleteRenderbuffersEXT(1, &This->depth_blt_rb));
+        gl_info->fbo_ops.glDeleteRenderbuffers(1, &This->depth_blt_rb);
         This->depth_blt_rb = 0;
         This->depth_blt_rb_w = 0;
@@ -7141,4 +7067,8 @@
         IWineD3DDevice_SetDepthStencilSurface(iface, NULL);
 
+    TRACE("Resetting stateblock\n");
+    IWineD3DStateBlock_Release((IWineD3DStateBlock *)This->updateStateBlock);
+    IWineD3DStateBlock_Release((IWineD3DStateBlock *)This->stateBlock);
+
     delete_opengl_contexts(iface, (IWineD3DSwapChain *) swapchain);
 
@@ -7214,8 +7144,4 @@
         This->exStyle = exStyle;
     }
-
-    TRACE("Resetting stateblock\n");
-    IWineD3DStateBlock_Release((IWineD3DStateBlock *)This->updateStateBlock);
-    IWineD3DStateBlock_Release((IWineD3DStateBlock *)This->stateBlock);
 
     /* Note: No parent needed for initial internal stateblock */
@@ -7484,6 +7410,6 @@
     IWineD3DDeviceImpl_SetGammaRamp,
     IWineD3DDeviceImpl_GetGammaRamp,
-    IWineD3DDeviceImpl_SetIndices,
-    IWineD3DDeviceImpl_GetIndices,
+    IWineD3DDeviceImpl_SetIndexBuffer,
+    IWineD3DDeviceImpl_GetIndexBuffer,
     IWineD3DDeviceImpl_SetBaseVertexIndex,
     IWineD3DDeviceImpl_GetBaseVertexIndex,
@@ -7696,5 +7622,4 @@
     UINT i;
 
-    if(!rep) return;
     for(i = 0; i < This->numContexts; i++) {
         context = This->contexts[i];
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c	(revision 23571)
@@ -7,4 +7,5 @@
  * Copyright 2005 Oliver Stieber
  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -66,8 +67,10 @@
     {"GL_ARB_color_buffer_float",           ARB_COLOR_BUFFER_FLOAT,         0                           },
     {"GL_ARB_depth_buffer_float",           ARB_DEPTH_BUFFER_FLOAT,         0                           },
+    {"GL_ARB_depth_clamp",                  ARB_DEPTH_CLAMP,                0                           },
     {"GL_ARB_depth_texture",                ARB_DEPTH_TEXTURE,              0                           },
     {"GL_ARB_draw_buffers",                 ARB_DRAW_BUFFERS,               0                           },
     {"GL_ARB_fragment_program",             ARB_FRAGMENT_PROGRAM,           0                           },
     {"GL_ARB_fragment_shader",              ARB_FRAGMENT_SHADER,            0                           },
+    {"GL_ARB_framebuffer_object",           ARB_FRAMEBUFFER_OBJECT,         0                           },
     {"GL_ARB_geometry_shader4",             ARB_GEOMETRY_SHADER4,           0                           },
     {"GL_ARB_half_float_pixel",             ARB_HALF_FLOAT_PIXEL,           0                           },
@@ -79,4 +82,5 @@
     {"GL_ARB_point_parameters",             ARB_POINT_PARAMETERS,           0                           },
     {"GL_ARB_point_sprite",                 ARB_POINT_SPRITE,               0                           },
+    {"GL_ARB_provoking_vertex",             ARB_PROVOKING_VERTEX,           0                           },
     {"GL_ARB_texture_border_clamp",         ARB_TEXTURE_BORDER_CLAMP,       0                           },
     {"GL_ARB_texture_compression",          ARB_TEXTURE_COMPRESSION,        0                           },
@@ -110,4 +114,5 @@
     {"GL_EXT_paletted_texture",             EXT_PALETTED_TEXTURE,           0                           },
     {"GL_EXT_point_parameters",             EXT_POINT_PARAMETERS,           0                           },
+    {"GL_EXT_provoking_vertex",             EXT_PROVOKING_VERTEX,           0                           },
     {"GL_EXT_secondary_color",              EXT_SECONDARY_COLOR,            0                           },
     {"GL_EXT_stencil_two_side",             EXT_STENCIL_TWO_SIDE,           0                           },
@@ -194,4 +199,12 @@
 };
 
+const struct min_lookup minMipLookup_noMip[] =
+{
+    /* NONE         POINT                       LINEAR */
+    {{GL_NEAREST,   GL_NEAREST,                 GL_NEAREST}},               /* NONE */
+    {{GL_NEAREST,   GL_NEAREST,                 GL_NEAREST}},               /* POINT */
+    {{GL_LINEAR,    GL_LINEAR,                  GL_LINEAR }},               /* LINEAR */
+};
+
 const GLenum magLookup[] =
 {
@@ -376,9 +389,7 @@
 }
 
-/* Set the shader type for this device, depending on the given capabilities,
- * the device type, and the user preferences in wined3d_settings */
-
-static void select_shader_mode(const struct wined3d_gl_info *gl_info,
-        WINED3DDEVTYPE DeviceType, int *ps_selected, int *vs_selected)
+/* Set the shader type for this device, depending on the given capabilities
+ * and the user preferences in wined3d_settings. */
+static void select_shader_mode(const struct wined3d_gl_info *gl_info, int *ps_selected, int *vs_selected)
 {
     if (wined3d_settings.vs_mode == VS_NONE) {
@@ -388,5 +399,5 @@
          * wrong. This combined with the fact that glsl won't offer more features or performance, use ARB
          * shaders only on this card. */
-        if(gl_info->vs_nv_version && gl_info->vs_nv_version < VS_VERSION_20)
+        if (gl_info->supported[NV_VERTEX_PROGRAM] && !gl_info->supported[NV_VERTEX_PROGRAM2])
             *vs_selected = SHADER_ARB;
         else
@@ -528,12 +539,8 @@
             && gl_info->supported[APPLE_YCBCR_422])
     {
-        TRACE_(d3d_caps)("GL_APPLE_fence, GL_APPLE_client_storage, GL_APPLE_flush_render and GL_ycbcr_422 are supported.\n");
-        TRACE_(d3d_caps)("Activating MacOS fixups.\n");
         return TRUE;
     }
     else
     {
-        TRACE_(d3d_caps)("Apple extensions are not supported.\n");
-        TRACE_(d3d_caps)("Not activating MacOS fixups.\n");
         return FALSE;
     }
@@ -585,5 +592,5 @@
 
     GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
-    glFinish(); /* just to be sure */
+    wglFinish(); /* just to be sure */
 
     memset(check, 0, sizeof(check));
@@ -793,5 +800,5 @@
 };
 
-struct driver_quirk quirk_table[] =
+static const struct driver_quirk quirk_table[] =
 {
     {
@@ -936,5 +943,7 @@
     test_pbo_functionality(gl_info);
 
-    /* Fixup the driver version */
+    /* Fixup the driver version we'll report to the app. */
+    gl_info->driver_version        = MAKEDWORD_VERSION(8, 6); /* Nvidia RIVA TNT, arbitrary */
+    gl_info->driver_version_hipart = MAKEDWORD_VERSION(7, 1);
     for (i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); ++i)
     {
@@ -953,4 +962,510 @@
         }
     }
+    TRACE_(d3d_caps)("Reporting (fake) driver version 0x%08X-0x%08X.\n",
+            gl_info->driver_version_hipart, gl_info->driver_version);
+}
+
+static DWORD wined3d_parse_gl_version(const char *gl_version)
+{
+    const char *ptr = gl_version;
+    int major, minor;
+
+    major = atoi(ptr);
+    if (major <= 0) ERR_(d3d_caps)("Invalid opengl major version: %d.\n", major);
+
+    while (isdigit(*ptr)) ++ptr;
+    if (*ptr++ != '.') ERR_(d3d_caps)("Invalid opengl version string: %s.\n", debugstr_a(gl_version));
+
+    minor = atoi(ptr);
+
+    TRACE_(d3d_caps)("Found OpenGL version: %d.%d.\n", major, minor);
+
+    return MAKEDWORD_VERSION(major, minor);
+}
+
+static GL_Vendors wined3d_guess_vendor(const char *gl_vendor, const char *gl_renderer)
+{
+    if (strstr(gl_vendor, "NVIDIA"))
+        return VENDOR_NVIDIA;
+
+    if (strstr(gl_vendor, "ATI"))
+        return VENDOR_ATI;
+
+    if (strstr(gl_vendor, "Intel(R)")
+            || strstr(gl_renderer, "Intel(R)")
+            || strstr(gl_vendor, "Intel Inc."))
+        return VENDOR_INTEL;
+
+    if (strstr(gl_vendor, "Mesa")
+            || strstr(gl_vendor, "DRI R300 Project")
+            || strstr(gl_vendor, "Tungsten Graphics, Inc"))
+        return VENDOR_MESA;
+
+    FIXME_(d3d_caps)("Received unrecognized GL_VENDOR %s. Returning VENDOR_WINE.\n", debugstr_a(gl_vendor));
+
+    return VENDOR_WINE;
+}
+
+static GL_Cards wined3d_guess_card(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
+        GL_Vendors *vendor, unsigned int *vidmem)
+{
+    /* Below is a list of Nvidia and ATI GPUs. Both vendors have dozens of
+     * different GPUs with roughly the same features. In most cases GPUs from a
+     * certain family differ in clockspeeds, the amount of video memory and the
+     * number of shader pipelines.
+     *
+     * A Direct3D device object contains the PCI id (vendor + device) of the
+     * videocard which is used for rendering. Various applications use this
+     * information to get a rough estimation of the features of the card and
+     * some might use it for enabling 3d effects only on certain types of
+     * videocards. In some cases games might even use it to work around bugs
+     * which happen on certain videocards/driver combinations. The problem is
+     * that OpenGL only exposes a rendering string containing the name of the
+     * videocard and not the PCI id.
+     *
+     * Various games depend on the PCI id, so somehow we need to provide one.
+     * A simple option is to parse the renderer string and translate this to
+     * the right PCI id. This is a lot of work because there are more than 200
+     * GPUs just for Nvidia. Various cards share the same renderer string, so
+     * the amount of code might be 'small' but there are quite a number of
+     * exceptions which would make this a pain to maintain. Another way would
+     * be to query the PCI id from the operating system (assuming this is the
+     * videocard which is used for rendering which is not always the case).
+     * This would work but it is not very portable. Second it would not work
+     * well in, let's say, a remote X situation in which the amount of 3d
+     * features which can be used is limited.
+     *
+     * As said most games only use the PCI id to get an indication of the
+     * capabilities of the card. It doesn't really matter if the given id is
+     * the correct one if we return the id of a card with similar 3d features.
+     *
+     * The code below checks the OpenGL capabilities of a videocard and matches
+     * that to a certain level of Direct3D functionality. Once a card passes
+     * the Direct3D9 check, we know that the card (in case of Nvidia) is at
+     * least a GeforceFX. To give a better estimate we do a basic check on the
+     * renderer string but if that won't pass we return a default card. This
+     * way is better than maintaining a full card database as even without a
+     * full database we can return a card with similar features. Second the
+     * size of the database can be made quite small because when you know what
+     * type of 3d functionality a card has, you know to which GPU family the
+     * GPU must belong. Because of this you only have to check a small part of
+     * the renderer string to distinguishes between different models from that
+     * family.
+     *
+     * The code also selects a default amount of video memory which we will
+     * use for an estimation of the amount of free texture memory. In case of
+     * real D3D the amount of texture memory includes video memory and system
+     * memory (to be specific AGP memory or in case of PCIE TurboCache /
+     * HyperMemory). We don't know how much system memory can be addressed by
+     * the system but we can make a reasonable estimation about the amount of
+     * video memory. If the value is slightly wrong it doesn't matter as we
+     * didn't include AGP-like memory which makes the amount of addressable
+     * memory higher and second OpenGL isn't that critical it moves to system
+     * memory behind our backs if really needed. Note that the amount of video
+     * memory can be overruled using a registry setting. */
+
+    switch (*vendor)
+    {
+        case VENDOR_NVIDIA:
+            /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
+             * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
+             */
+            if (WINE_D3D9_CAPABLE(gl_info) && gl_info->supported[NV_VERTEX_PROGRAM3])
+            {
+                /* Geforce 200 - highend */
+                if (strstr(gl_renderer, "GTX 280")
+                        || strstr(gl_renderer, "GTX 285")
+                        || strstr(gl_renderer, "GTX 295"))
+                {
+                    *vidmem = 1024;
+                    return CARD_NVIDIA_GEFORCE_GTX280;
+                }
+
+                /* Geforce 200 - midend high */
+                if (strstr(gl_renderer, "GTX 275"))
+                {
+                    *vidmem = 896;
+                    return CARD_NVIDIA_GEFORCE_GTX275;
+                }
+
+                /* Geforce 200 - midend */
+                if (strstr(gl_renderer, "GTX 260"))
+                {
+                    *vidmem = 1024;
+                    return CARD_NVIDIA_GEFORCE_GTX260;
+                }
+
+                /* Geforce9 - highend / Geforce 200 - midend (GTS 150/250 are based on the same core) */
+                if (strstr(gl_renderer, "9800")
+                        || strstr(gl_renderer, "GTS 150")
+                        || strstr(gl_renderer, "GTS 250"))
+                {
+                    *vidmem = 512;
+                    return CARD_NVIDIA_GEFORCE_9800GT;
+                }
+
+                /* Geforce9 - midend */
+                if (strstr(gl_renderer, "9600"))
+                {
+                    *vidmem = 384; /* The 9600GSO has 384MB, the 9600GT has 512-1024MB */
+                    return CARD_NVIDIA_GEFORCE_9600GT;
+                }
+
+                /* Geforce9 - midend low / Geforce 200 - low */
+                if (strstr(gl_renderer, "9500")
+                        || strstr(gl_renderer, "GT 120")
+                        || strstr(gl_renderer, "GT 130"))
+                {
+                    *vidmem = 256; /* The 9500GT has 256-1024MB */
+                    return CARD_NVIDIA_GEFORCE_9500GT;
+                }
+
+                /* Geforce9 - lowend */
+                if (strstr(gl_renderer, "9400"))
+                {
+                    *vidmem = 256; /* The 9400GT has 256-1024MB */
+                    return CARD_NVIDIA_GEFORCE_9400GT;
+                }
+
+                /* Geforce9 - lowend low */
+                if (strstr(gl_renderer, "9100")
+                        || strstr(gl_renderer, "9200")
+                        || strstr(gl_renderer, "9300")
+                        || strstr(gl_renderer, "G 100"))
+                {
+                    *vidmem = 256; /* The 9100-9300 cards have 256MB */
+                    return CARD_NVIDIA_GEFORCE_9200;
+                }
+
+                /* Geforce8 - highend */
+                if (strstr(gl_renderer, "8800"))
+                {
+                    *vidmem = 320; /* The 8800GTS uses 320MB, a 8800GTX can have 768MB */
+                    return CARD_NVIDIA_GEFORCE_8800GTS;
+                }
+
+                /* Geforce8 - midend mobile */
+                if (strstr(gl_renderer, "8600 M"))
+                {
+                    *vidmem = 512;
+                    return CARD_NVIDIA_GEFORCE_8600MGT;
+                }
+
+                /* Geforce8 - midend */
+                if (strstr(gl_renderer, "8600")
+                        || strstr(gl_renderer, "8700"))
+                {
+                    *vidmem = 256;
+                    return CARD_NVIDIA_GEFORCE_8600GT;
+                }
+
+                /* Geforce8 - lowend */
+                if (strstr(gl_renderer, "8300")
+                        || strstr(gl_renderer, "8400")
+                        || strstr(gl_renderer, "8500"))
+                {
+                    *vidmem = 128; /* 128-256MB for a 8300, 256-512MB for a 8400 */
+                    return CARD_NVIDIA_GEFORCE_8300GS;
+                }
+
+                /* Geforce7 - highend */
+                if (strstr(gl_renderer, "7800")
+                        || strstr(gl_renderer, "7900")
+                        || strstr(gl_renderer, "7950")
+                        || strstr(gl_renderer, "Quadro FX 4")
+                        || strstr(gl_renderer, "Quadro FX 5"))
+                {
+                    *vidmem = 256; /* A 7800GT uses 256MB while highend 7900 cards can use 512MB */
+                    return CARD_NVIDIA_GEFORCE_7800GT;
+                }
+
+                /* Geforce7 midend */
+                if (strstr(gl_renderer, "7600")
+                        || strstr(gl_renderer, "7700"))
+                {
+                    *vidmem = 256; /* The 7600 uses 256-512MB */
+                    return CARD_NVIDIA_GEFORCE_7600;
+                }
+
+                /* Geforce7 lower medium */
+                if (strstr(gl_renderer, "7400"))
+                {
+                    *vidmem = 256; /* The 7400 uses 256-512MB */
+                    return CARD_NVIDIA_GEFORCE_7400;
+                }
+
+                /* Geforce7 lowend */
+                if (strstr(gl_renderer, "7300"))
+                {
+                    *vidmem = 256; /* Mac Pros with this card have 256 MB */
+                    return CARD_NVIDIA_GEFORCE_7300;
+                }
+
+                /* Geforce6 highend */
+                if (strstr(gl_renderer, "6800"))
+                {
+                    *vidmem = 128; /* The 6800 uses 128-256MB, the 7600 uses 256-512MB */
+                    return CARD_NVIDIA_GEFORCE_6800;
+                }
+
+                /* Geforce6 - midend */
+                if (strstr(gl_renderer, "6600")
+                        || strstr(gl_renderer, "6610")
+                        || strstr(gl_renderer, "6700"))
+                {
+                    *vidmem = 128; /* A 6600GT has 128-256MB */
+                    return CARD_NVIDIA_GEFORCE_6600GT;
+                }
+
+                /* Geforce6/7 lowend */
+                *vidmem = 64; /* */
+                return CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
+            }
+
+            if (WINE_D3D9_CAPABLE(gl_info))
+            {
+                /* GeforceFX - highend */
+                if (strstr(gl_renderer, "5800")
+                        || strstr(gl_renderer, "5900")
+                        || strstr(gl_renderer, "5950")
+                        || strstr(gl_renderer, "Quadro FX"))
+                {
+                    *vidmem = 256; /* 5800-5900 cards use 256MB */
+                    return CARD_NVIDIA_GEFORCEFX_5800;
+                }
+
+                /* GeforceFX - midend */
+                if (strstr(gl_renderer, "5600")
+                        || strstr(gl_renderer, "5650")
+                        || strstr(gl_renderer, "5700")
+                        || strstr(gl_renderer, "5750"))
+                {
+                    *vidmem = 128; /* A 5600 uses 128-256MB */
+                    return CARD_NVIDIA_GEFORCEFX_5600;
+                }
+
+                /* GeforceFX - lowend */
+                *vidmem = 64; /* Normal FX5200 cards use 64-256MB; laptop (non-standard) can have less */
+                return CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
+            }
+
+            if (WINE_D3D8_CAPABLE(gl_info))
+            {
+                if (strstr(gl_renderer, "GeForce4 Ti") || strstr(gl_renderer, "Quadro4"))
+                {
+                    *vidmem = 64; /* Geforce4 Ti cards have 64-128MB */
+                    return CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
+                }
+
+                *vidmem = 64; /* Geforce3 cards have 64-128MB */
+                return CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
+            }
+
+            if (WINE_D3D7_CAPABLE(gl_info))
+            {
+                if (strstr(gl_renderer, "GeForce4 MX"))
+                {
+                    /* Most Geforce4MX GPUs have at least 64MB of memory, some
+                     * early models had 32MB but most have 64MB or even 128MB. */
+                    *vidmem = 64;
+                    return CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
+                }
+
+                if (strstr(gl_renderer, "GeForce2 MX") || strstr(gl_renderer, "Quadro2 MXR"))
+                {
+                    *vidmem = 32; /* Geforce2MX GPUs have 32-64MB of video memory */
+                    return CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
+                }
+
+                if (strstr(gl_renderer, "GeForce2") || strstr(gl_renderer, "Quadro2"))
+                {
+                    *vidmem = 32; /* Geforce2 GPUs have 32-64MB of video memory */
+                    return CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
+                }
+
+                /* Most Geforce1 cards have 32MB, there are also some rare 16
+                 * and 64MB (Dell) models. */
+                *vidmem = 32;
+                return CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
+            }
+
+            if (strstr(gl_renderer, "TNT2"))
+            {
+                *vidmem = 32; /* Most TNT2 boards have 32MB, though there are 16MB boards too */
+                return CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
+            }
+
+            *vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
+            return CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
+
+        case VENDOR_ATI:
+            /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx
+             *
+             * Beware: renderer string do not match exact card model,
+             * eg HD 4800 is returned for multiple cards, even for RV790 based ones. */
+            if (WINE_D3D9_CAPABLE(gl_info))
+            {
+                /* Radeon R7xx HD4800 - highend */
+                if (strstr(gl_renderer, "HD 4800")          /* Radeon RV7xx HD48xx generic renderer string */
+                        || strstr(gl_renderer, "HD 4830")   /* Radeon RV770 */
+                        || strstr(gl_renderer, "HD 4850")   /* Radeon RV770 */
+                        || strstr(gl_renderer, "HD 4870")   /* Radeon RV770 */
+                        || strstr(gl_renderer, "HD 4890"))  /* Radeon RV790 */
+                {
+                    *vidmem = 512; /* note: HD4890 cards use 1024MB */
+                    return CARD_ATI_RADEON_HD4800;
+                }
+
+                /* Radeon R740 HD4700 - midend */
+                if (strstr(gl_renderer, "HD 4700")          /* Radeon RV770 */
+                        || strstr(gl_renderer, "HD 4770"))  /* Radeon RV740 */
+                {
+                    *vidmem = 512;
+                    return CARD_ATI_RADEON_HD4700;
+                }
+
+                /* Radeon R730 HD4600 - midend */
+                if (strstr(gl_renderer, "HD 4600")          /* Radeon RV730 */
+                        || strstr(gl_renderer, "HD 4650")   /* Radeon RV730 */
+                        || strstr(gl_renderer, "HD 4670"))  /* Radeon RV730 */
+                {
+                    *vidmem = 512;
+                    return CARD_ATI_RADEON_HD4600;
+                }
+
+                /* Radeon R710 HD4500/HD4350 - lowend */
+                if (strstr(gl_renderer, "HD 4350")          /* Radeon RV710 */
+                        || strstr(gl_renderer, "HD 4550"))  /* Radeon RV710 */
+                {
+                    *vidmem = 256;
+                    return CARD_ATI_RADEON_HD4350;
+                }
+
+                /* Radeon R6xx HD2900/HD3800 - highend */
+                if (strstr(gl_renderer, "HD 2900")
+                        || strstr(gl_renderer, "HD 3870")
+                        || strstr(gl_renderer, "HD 3850"))
+                {
+                    *vidmem = 512; /* HD2900/HD3800 uses 256-1024MB */
+                    return CARD_ATI_RADEON_HD2900;
+                }
+
+                /* Radeon R6xx HD2600/HD3600 - midend; HD3830 is China-only midend */
+                if (strstr(gl_renderer, "HD 2600")
+                        || strstr(gl_renderer, "HD 3830")
+                        || strstr(gl_renderer, "HD 3690")
+                        || strstr(gl_renderer, "HD 3650"))
+                {
+                    *vidmem = 256; /* HD2600/HD3600 uses 256-512MB */
+                    return CARD_ATI_RADEON_HD2600;
+                }
+
+                /* Radeon R6xx HD2300/HD2400/HD3400 - lowend */
+                if (strstr(gl_renderer, "HD 2300")
+                        || strstr(gl_renderer, "HD 2400")
+                        || strstr(gl_renderer, "HD 3470")
+                        || strstr(gl_renderer, "HD 3450")
+                        || strstr(gl_renderer, "HD 3430")
+                        || strstr(gl_renderer, "HD 3400"))
+                {
+                    *vidmem = 128; /* HD2300 uses at least 128MB, HD2400 uses 256MB */
+                    return CARD_ATI_RADEON_HD2300;
+                }
+
+                /* Radeon R6xx/R7xx integrated */
+                if (strstr(gl_renderer, "HD 3100")
+                        || strstr(gl_renderer, "HD 3200")
+                        || strstr(gl_renderer, "HD 3300"))
+                {
+                    *vidmem = 128; /* 128MB */
+                    return CARD_ATI_RADEON_HD3200;
+                }
+
+                /* Radeon R5xx */
+                if (strstr(gl_renderer, "X1600")
+                        || strstr(gl_renderer, "X1650")
+                        || strstr(gl_renderer, "X1800")
+                        || strstr(gl_renderer, "X1900")
+                        || strstr(gl_renderer, "X1950"))
+                {
+                    *vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
+                    return CARD_ATI_RADEON_X1600;
+                }
+
+                /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
+                if (strstr(gl_renderer, "X700")
+                        || strstr(gl_renderer, "X800")
+                        || strstr(gl_renderer, "X850")
+                        || strstr(gl_renderer, "X1300")
+                        || strstr(gl_renderer, "X1400")
+                        || strstr(gl_renderer, "X1450")
+                        || strstr(gl_renderer, "X1550"))
+                {
+                    *vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
+                    return CARD_ATI_RADEON_X700;
+                }
+
+                /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400MHz */
+                if (strstr(gl_renderer, "Radeon Xpress"))
+                {
+                    *vidmem = 64; /* Shared RAM, BIOS configurable, 64-256M */
+                    return CARD_ATI_RADEON_XPRESS_200M;
+                }
+
+                /* Radeon R3xx */
+                *vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
+                return CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
+            }
+
+            if (WINE_D3D8_CAPABLE(gl_info))
+            {
+                *vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
+                return CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
+            }
+
+            if (WINE_D3D7_CAPABLE(gl_info))
+            {
+                *vidmem = 32; /* There are models with up to 64MB */
+                return CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
+            }
+
+            *vidmem = 16; /* There are 16-32MB models */
+            return CARD_ATI_RAGE_128PRO;
+
+        case VENDOR_INTEL:
+            if (strstr(gl_renderer, "X3100"))
+            {
+                /* MacOS calls the card GMA X3100, Google findings also suggest the name GM965 */
+                *vidmem = 128;
+                return CARD_INTEL_X3100;
+            }
+
+            if (strstr(gl_renderer, "GMA 950") || strstr(gl_renderer, "945GM"))
+            {
+                /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */
+                *vidmem = 64;
+                return CARD_INTEL_I945GM;
+            }
+
+            if (strstr(gl_renderer, "915GM")) return CARD_INTEL_I915GM;
+            if (strstr(gl_renderer, "915G")) return CARD_INTEL_I915G;
+            if (strstr(gl_renderer, "865G")) return CARD_INTEL_I865G;
+            if (strstr(gl_renderer, "855G")) return CARD_INTEL_I855G;
+            if (strstr(gl_renderer, "830G")) return CARD_INTEL_I830G;
+            return CARD_INTEL_I915G;
+
+        case VENDOR_MESA:
+        case VENDOR_WINE:
+        default:
+            /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice
+             * for Nvidia was because the hardware and drivers they make are of good quality. This makes
+             * them a good generic choice. */
+            *vendor = VENDOR_NVIDIA;
+            if (WINE_D3D9_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCEFX_5600;
+            if (WINE_D3D8_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE3;
+            if (WINE_D3D7_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE;
+            if (WINE_D3D6_CAPABLE(gl_info)) return CARD_NVIDIA_RIVA_TNT;
+            return CARD_NVIDIA_RIVA_128;
+    }
 }
 
@@ -961,8 +1476,6 @@
     const char *WGL_Extensions   = NULL;
     const char *gl_string        = NULL;
-    const char *gl_string_cursor = NULL;
     GLint       gl_max;
     GLfloat     gl_floatv[2];
-    int         major = 1, minor = 0;
     unsigned    i;
     HDC         hdc;
@@ -977,7 +1490,8 @@
 
     gl_string = (const char *)glGetString(GL_RENDERER);
-    TRACE_(d3d_caps)("GL_RENDERER: %s.\n", gl_string);
+    TRACE_(d3d_caps)("GL_RENDERER: %s.\n", debugstr_a(gl_string));
     if (!gl_string)
     {
+        LEAVE_GL();
         ERR_(d3d_caps)("Received a NULL GL_RENDERER.\n");
         return FALSE;
@@ -988,4 +1502,5 @@
     if (!gl_renderer)
     {
+        LEAVE_GL();
         ERR_(d3d_caps)("Failed to allocate gl_renderer memory.\n");
         return FALSE;
@@ -994,193 +1509,26 @@
 
     gl_string = (const char *)glGetString(GL_VENDOR);
-    TRACE_(d3d_caps)("GL_VENDOR: %s.\n", gl_string);
+    TRACE_(d3d_caps)("GL_VENDOR: %s.\n", debugstr_a(gl_string));
     if (!gl_string)
     {
+        LEAVE_GL();
         ERR_(d3d_caps)("Received a NULL GL_VENDOR.\n");
         HeapFree(GetProcessHeap(), 0, gl_renderer);
         return FALSE;
     }
-
-    /* Fill in the GL vendor */
-    if (strstr(gl_string, "NVIDIA"))
-    {
-        gl_info->gl_vendor = VENDOR_NVIDIA;
-    }
-    else if (strstr(gl_string, "ATI"))
-    {
-        gl_info->gl_vendor = VENDOR_ATI;
-    }
-    else if (strstr(gl_string, "Intel(R)")
-            || strstr(gl_renderer, "Intel(R)")
-            || strstr(gl_string, "Intel Inc."))
-    {
-        gl_info->gl_vendor = VENDOR_INTEL;
-    }
-    else if (strstr(gl_string, "Mesa"))
-    {
-        gl_info->gl_vendor = VENDOR_MESA;
-    }
-    else
-    {
-        FIXME_(d3d_caps)("Received unrecognized GL_VENDOR %s. Setting VENDOR_WINE.\n", gl_string);
-        gl_info->gl_vendor = VENDOR_WINE;
-    }
+    gl_info->gl_vendor = wined3d_guess_vendor(gl_string, gl_renderer);
     TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x)\n", debugstr_a(gl_string), gl_info->gl_vendor);
 
     /* Parse the GL_VERSION field into major and minor information */
     gl_string = (const char *)glGetString(GL_VERSION);
-    TRACE_(d3d_caps)("GL_VERSION: %s.\n", gl_string);
+    TRACE_(d3d_caps)("GL_VERSION: %s.\n", debugstr_a(gl_string));
     if (!gl_string)
     {
+        LEAVE_GL();
         ERR_(d3d_caps)("Received a NULL GL_VERSION.\n");
         HeapFree(GetProcessHeap(), 0, gl_renderer);
         return FALSE;
     }
-
-    /* First, parse the generic opengl version. This is supposed not to be
-     * convoluted with driver specific information. */
-    gl_string_cursor = gl_string;
-
-    major = atoi(gl_string_cursor);
-    if (major <= 0) ERR_(d3d_caps)("Invalid opengl major version: %d.\n", major);
-    while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') ++gl_string_cursor;
-    if (*gl_string_cursor++ != '.') ERR_(d3d_caps)("Invalid opengl version string: %s.\n", debugstr_a(gl_string));
-
-    minor = atoi(gl_string_cursor);
-    TRACE_(d3d_caps)("Found OpenGL version: %d.%d.\n", major, minor);
-    gl_version = MAKEDWORD_VERSION(major, minor);
-
-    /* Now parse the driver specific string which we'll report to the app. */
-    switch (gl_info->gl_vendor)
-    {
-        case VENDOR_NVIDIA:
-            gl_string_cursor = strstr(gl_string, "NVIDIA");
-            if (!gl_string_cursor)
-            {
-                ERR_(d3d_caps)("Invalid nVidia version string: %s.\n", debugstr_a(gl_string));
-                break;
-            }
-
-            gl_string_cursor = strstr(gl_string_cursor, " ");
-            if (!gl_string_cursor)
-            {
-                ERR_(d3d_caps)("Invalid nVidia version string: %s.\n", debugstr_a(gl_string));
-                break;
-            }
-
-            while (*gl_string_cursor == ' ') ++gl_string_cursor;
-
-            if (!*gl_string_cursor)
-            {
-                ERR_(d3d_caps)("Invalid nVidia version string: %s.\n", debugstr_a(gl_string));
-                break;
-            }
-
-            major = atoi(gl_string_cursor);
-            while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') ++gl_string_cursor;
-
-            if (*gl_string_cursor++ != '.')
-            {
-                ERR_(d3d_caps)("Invalid nVidia version string: %s.\n", debugstr_a(gl_string));
-                break;
-            }
-
-            minor = atoi(gl_string_cursor);
-            minor = major * 100 + minor;
-            major = 10;
-            break;
-
-        case VENDOR_ATI:
-            major = minor = 0;
-            gl_string_cursor = strchr(gl_string, '-');
-            if (gl_string_cursor)
-            {
-                ++gl_string_cursor;
-
-                /* Check if version number is of the form x.y.z. */
-                if (*gl_string_cursor < '0' || *gl_string_cursor > '9'
-                        || gl_string_cursor[1] != '.'
-                        || gl_string_cursor[2] < '0' || gl_string_cursor[2] > '9'
-                        || gl_string_cursor[3] != '.'
-                        || gl_string_cursor[4] < '0' || gl_string_cursor[4] > '9')
-                    /* Mark version number as malformed. */
-                    gl_string_cursor = 0;
-            }
-
-            if (!gl_string_cursor)
-            {
-                WARN_(d3d_caps)("malformed GL_VERSION (%s).\n", debugstr_a(gl_string));
-            }
-            else
-            {
-                major = *gl_string_cursor - '0';
-                minor = (gl_string_cursor[2] - '0') * 256 + (gl_string_cursor[4] - '0');
-            }
-            break;
-
-        case VENDOR_INTEL:
-            /* Apple and Mesa version strings look differently, but both provide intel drivers. */
-            if (strstr(gl_string, "APPLE"))
-            {
-                /* [0-9]+.[0-9]+ APPLE-[0-9]+.[0.9]+.[0.9]+
-                 * We only need the first part, and use the APPLE as identification
-                 * "1.2 APPLE-1.4.56". */
-                gl_string_cursor = gl_string;
-                major = atoi(gl_string_cursor);
-                while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') ++gl_string_cursor;
-
-                if (*gl_string_cursor++ != '.')
-                {
-                    ERR_(d3d_caps)("Invalid MacOS-Intel version string: %s.\n", debugstr_a(gl_string));
-                    break;
-                }
-
-                minor = atoi(gl_string_cursor);
-                break;
-            }
-            /* Fallthrough */
-
-        case VENDOR_MESA:
-            gl_string_cursor = strstr(gl_string, "Mesa");
-            gl_string_cursor = strstr(gl_string_cursor, " ");
-            while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
-            if (*gl_string_cursor)
-            {
-                char tmp[16];
-                int cursor = 0;
-
-                while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0')
-                {
-                    tmp[cursor++] = *gl_string_cursor;
-                    ++gl_string_cursor;
-                }
-                tmp[cursor] = 0;
-                major = atoi(tmp);
-
-                if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s).\n", debugstr_a(gl_string));
-                ++gl_string_cursor;
-
-                cursor = 0;
-                while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0')
-                {
-                    tmp[cursor++] = *gl_string_cursor;
-                    ++gl_string_cursor;
-                }
-                tmp[cursor] = 0;
-                minor = atoi(tmp);
-            }
-            break;
-
-        default:
-            major = 0;
-            minor = 9;
-            break;
-    }
-
-    gl_info->driver_version = MAKEDWORD_VERSION(major, minor);
-    TRACE_(d3d_caps)("found driver version (%s)->%i.%i->(0x%08x).\n",
-            debugstr_a(gl_string), major, minor, gl_info->driver_version);
-    /* Current Windows drivers have versions like 6.14.... (some older have an earlier version). */
-    gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
+    gl_version = wined3d_parse_gl_version(gl_string);
 
     /*
@@ -1196,12 +1544,8 @@
     gl_info->max_combined_samplers = gl_info->max_fragment_samplers + gl_info->max_vertex_samplers;
     gl_info->max_sampler_stages = 1;
-    gl_info->ps_arb_version = PS_VERSION_NOT_SUPPORTED;
     gl_info->ps_arb_max_temps = 0;
     gl_info->ps_arb_max_instructions = 0;
-    gl_info->vs_arb_version = VS_VERSION_NOT_SUPPORTED;
     gl_info->vs_arb_max_temps = 0;
     gl_info->vs_arb_max_instructions = 0;
-    gl_info->vs_nv_version  = VS_VERSION_NOT_SUPPORTED;
-    gl_info->vs_ati_version = VS_VERSION_NOT_SUPPORTED;
     gl_info->vs_glsl_constantsF = 0;
     gl_info->ps_glsl_constantsF = 0;
@@ -1232,4 +1576,5 @@
     if (!GL_Extensions)
     {
+        LEAVE_GL();
         ERR_(d3d_caps)("Received a NULL GL_EXTENSIONS.\n");
         HeapFree(GetProcessHeap(), 0, gl_renderer);
@@ -1237,4 +1582,6 @@
     }
 
+    LEAVE_GL();
+
     TRACE_(d3d_caps)("GL_Extensions reported:\n");
 
@@ -1255,5 +1602,5 @@
         memcpy(current_ext, start, len);
         current_ext[len] = '\0';
-        TRACE_(d3d_caps)("- %s\n", current_ext);
+        TRACE_(d3d_caps)("- %s\n", debugstr_a(current_ext));
 
         for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i)
@@ -1267,6 +1614,4 @@
         }
     }
-
-    LEAVE_GL();
 
     /* Now work out what GL support this card really has */
@@ -1334,4 +1679,9 @@
         TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support.\n");
         gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
+    }
+    if (!gl_info->supported[ARB_DEPTH_CLAMP] && gl_info->supported[NV_DEPTH_CLAMP])
+    {
+        TRACE_(d3d_caps)(" IMPLIED: ARB_depth_clamp support (by NV_depth_clamp).\n");
+        gl_info->supported[ARB_DEPTH_CLAMP] = TRUE;
     }
     if (gl_info->supported[NV_TEXTURE_SHADER2])
@@ -1442,5 +1792,4 @@
     if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
     {
-        gl_info->ps_arb_version = PS_VERSION_11;
         GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
         gl_info->ps_arb_constantsF = gl_max;
@@ -1452,8 +1801,10 @@
         gl_info->ps_arb_max_instructions = gl_max;
         TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d.\n", gl_info->ps_arb_max_instructions);
+        GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, &gl_max));
+        gl_info->ps_arb_max_local_constants = gl_max;
+        TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM local parameters: %d.\n", gl_info->ps_arb_max_instructions);
     }
     if (gl_info->supported[ARB_VERTEX_PROGRAM])
     {
-        gl_info->vs_arb_version = VS_VERSION_11;
         GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
         gl_info->vs_arb_constantsF = gl_max;
@@ -1482,32 +1833,4 @@
         gl_info->max_glsl_varyings = gl_max;
         TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings).\n", gl_max, gl_max / 4);
-    }
-    if (gl_info->supported[EXT_VERTEX_SHADER])
-    {
-        gl_info->vs_ati_version = VS_VERSION_11;
-    }
-    if (gl_info->supported[NV_VERTEX_PROGRAM3])
-    {
-        gl_info->vs_nv_version = VS_VERSION_30;
-    }
-    else if (gl_info->supported[NV_VERTEX_PROGRAM2])
-    {
-        gl_info->vs_nv_version = VS_VERSION_20;
-    }
-    else if (gl_info->supported[NV_VERTEX_PROGRAM1_1])
-    {
-        gl_info->vs_nv_version = VS_VERSION_11;
-    }
-    else if (gl_info->supported[NV_VERTEX_PROGRAM])
-    {
-        gl_info->vs_nv_version = VS_VERSION_10;
-    }
-    if (gl_info->supported[NV_FRAGMENT_PROGRAM2])
-    {
-        gl_info->ps_nv_version = PS_VERSION_30;
-    }
-    else if (gl_info->supported[NV_FRAGMENT_PROGRAM])
-    {
-        gl_info->ps_nv_version = PS_VERSION_20;
     }
     if (gl_info->supported[NV_LIGHT_MAX_EXPONENT])
@@ -1554,4 +1877,6 @@
     checkGLcall("extension detection");
 
+    LEAVE_GL();
+
     /* In some cases the number of texture stages can be larger than the number
      * of samplers. The GF4 for example can use only 2 samplers (no fragment
@@ -1559,8 +1884,61 @@
     gl_info->max_sampler_stages = max(gl_info->max_fragment_samplers, gl_info->max_texture_stages);
 
-    /* We can only use ORM_FBO when the hardware supports it. */
-    if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && !gl_info->supported[EXT_FRAMEBUFFER_OBJECT]) {
-        WARN_(d3d_caps)("GL_EXT_framebuffer_object not supported, falling back to backbuffer offscreen rendering mode.\n");
-        wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
+    if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
+    {
+        gl_info->fbo_ops.glIsRenderbuffer = gl_info->glIsRenderbuffer;
+        gl_info->fbo_ops.glBindRenderbuffer = gl_info->glBindRenderbuffer;
+        gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->glDeleteRenderbuffers;
+        gl_info->fbo_ops.glGenRenderbuffers = gl_info->glGenRenderbuffers;
+        gl_info->fbo_ops.glRenderbufferStorage = gl_info->glRenderbufferStorage;
+        gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->glRenderbufferStorageMultisample;
+        gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->glGetRenderbufferParameteriv;
+        gl_info->fbo_ops.glIsFramebuffer = gl_info->glIsFramebuffer;
+        gl_info->fbo_ops.glBindFramebuffer = gl_info->glBindFramebuffer;
+        gl_info->fbo_ops.glDeleteFramebuffers = gl_info->glDeleteFramebuffers;
+        gl_info->fbo_ops.glGenFramebuffers = gl_info->glGenFramebuffers;
+        gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->glCheckFramebufferStatus;
+        gl_info->fbo_ops.glFramebufferTexture1D = gl_info->glFramebufferTexture1D;
+        gl_info->fbo_ops.glFramebufferTexture2D = gl_info->glFramebufferTexture2D;
+        gl_info->fbo_ops.glFramebufferTexture3D = gl_info->glFramebufferTexture3D;
+        gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->glFramebufferRenderbuffer;
+        gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv = gl_info->glGetFramebufferAttachmentParameteriv;
+        gl_info->fbo_ops.glBlitFramebuffer = gl_info->glBlitFramebuffer;
+        gl_info->fbo_ops.glGenerateMipmap = gl_info->glGenerateMipmap;
+    }
+    else
+    {
+        if (gl_info->supported[EXT_FRAMEBUFFER_OBJECT])
+        {
+            gl_info->fbo_ops.glIsRenderbuffer = gl_info->glIsRenderbufferEXT;
+            gl_info->fbo_ops.glBindRenderbuffer = gl_info->glBindRenderbufferEXT;
+            gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->glDeleteRenderbuffersEXT;
+            gl_info->fbo_ops.glGenRenderbuffers = gl_info->glGenRenderbuffersEXT;
+            gl_info->fbo_ops.glRenderbufferStorage = gl_info->glRenderbufferStorageEXT;
+            gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->glGetRenderbufferParameterivEXT;
+            gl_info->fbo_ops.glIsFramebuffer = gl_info->glIsFramebufferEXT;
+            gl_info->fbo_ops.glBindFramebuffer = gl_info->glBindFramebufferEXT;
+            gl_info->fbo_ops.glDeleteFramebuffers = gl_info->glDeleteFramebuffersEXT;
+            gl_info->fbo_ops.glGenFramebuffers = gl_info->glGenFramebuffersEXT;
+            gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->glCheckFramebufferStatusEXT;
+            gl_info->fbo_ops.glFramebufferTexture1D = gl_info->glFramebufferTexture1DEXT;
+            gl_info->fbo_ops.glFramebufferTexture2D = gl_info->glFramebufferTexture2DEXT;
+            gl_info->fbo_ops.glFramebufferTexture3D = gl_info->glFramebufferTexture3DEXT;
+            gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->glFramebufferRenderbufferEXT;
+            gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv = gl_info->glGetFramebufferAttachmentParameterivEXT;
+            gl_info->fbo_ops.glGenerateMipmap = gl_info->glGenerateMipmapEXT;
+        }
+        else if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
+        {
+            WARN_(d3d_caps)("Framebuffer objects not supported, falling back to backbuffer offscreen rendering mode.\n");
+            wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
+        }
+        if (gl_info->supported[EXT_FRAMEBUFFER_BLIT])
+        {
+            gl_info->fbo_ops.glBlitFramebuffer = gl_info->glBlitFramebufferEXT;
+        }
+        if (gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
+        {
+            gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->glRenderbufferStorageMultisampleEXT;
+        }
     }
 
@@ -1570,427 +1948,5 @@
     }
 
-    /* Below is a list of Nvidia and ATI GPUs. Both vendors have dozens of different GPUs with roughly the same
-     * features. In most cases GPUs from a certain family differ in clockspeeds, the amount of video memory and
-     * in case of the latest videocards in the number of pixel/vertex pipelines.
-     *
-     * A Direct3D device object contains the PCI id (vendor + device) of the videocard which is used for
-     * rendering. Various games use this information to get a rough estimation of the features of the card
-     * and some might use it for enabling 3d effects only on certain types of videocards. In some cases
-     * games might even use it to work around bugs which happen on certain videocards/driver combinations.
-     * The problem is that OpenGL only exposes a rendering string containing the name of the videocard and
-     * not the PCI id.
-     *
-     * Various games depend on the PCI id, so somehow we need to provide one. A simple option is to parse
-     * the renderer string and translate this to the right PCI id. This is a lot of work because there are more
-     * than 200 GPUs just for Nvidia. Various cards share the same renderer string, so the amount of code might
-     * be 'small' but there are quite a number of exceptions which would make this a pain to maintain.
-     * Another way would be to query the PCI id from the operating system (assuming this is the videocard which
-     * is used for rendering which is not always the case). This would work but it is not very portable. Second
-     * it would not work well in, let's say, a remote X situation in which the amount of 3d features which can be used
-     * is limited.
-     *
-     * As said most games only use the PCI id to get an indication of the capabilities of the card.
-     * It doesn't really matter if the given id is the correct one if we return the id of a card with
-     * similar 3d features.
-     *
-     * The code below checks the OpenGL capabilities of a videocard and matches that to a certain level of
-     * Direct3D functionality. Once a card passes the Direct3D9 check, we know that the card (in case of Nvidia)
-     * is at least a GeforceFX. To give a better estimate we do a basic check on the renderer string but if that
-     * won't pass we return a default card. This way is better than maintaining a full card database as even
-     * without a full database we can return a card with similar features. Second the size of the database
-     * can be made quite small because when you know what type of 3d functionality a card has, you know to which
-     * GPU family the GPU must belong. Because of this you only have to check a small part of the renderer string
-     * to distinguishes between different models from that family.
-     *
-     * The code also selects a default amount of video memory which we will use for an estimation of the amount
-     * of free texture memory. In case of real D3D the amount of texture memory includes video memory and system
-     * memory (to be specific AGP memory or in case of PCIE TurboCache/HyperMemory). We don't know how much
-     * system memory can be addressed by the system but we can make a reasonable estimation about the amount of
-     * video memory. If the value is slightly wrong it doesn't matter as we didn't include AGP-like memory which
-     * makes the amount of addressable memory higher and second OpenGL isn't that critical it moves to system
-     * memory behind our backs if really needed.
-     * Note that the amount of video memory can be overruled using a registry setting.
-     */
-    switch (gl_info->gl_vendor) {
-        case VENDOR_NVIDIA:
-            /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
-             * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
-             */
-            if(WINE_D3D9_CAPABLE(gl_info) && (gl_info->vs_nv_version == VS_VERSION_30)) {
-                /* Geforce 200 - highend */
-                if (strstr(gl_renderer, "GTX 280")
-                        || strstr(gl_renderer, "GTX 285")
-                        || strstr(gl_renderer, "GTX 295"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_GTX280;
-                    vidmem = 1024;
-                }
-                /* Geforce 200 - midend high */
-                else if (strstr(gl_renderer, "GTX 275"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_GTX275;
-                    vidmem = 896;
-                }
-                /* Geforce 200 - midend */
-                else if (strstr(gl_renderer, "GTX 260"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_GTX260;
-                    vidmem = 1024;
-                }
-                /* Geforce9 - highend / Geforce 200 - midend (GTS 150/250 are based on the same core) */
-                else if (strstr(gl_renderer, "9800")
-                        || strstr(gl_renderer, "GTS 150")
-                        || strstr(gl_renderer, "GTS 250"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_9800GT;
-                    vidmem = 512;
-                }
-                /* Geforce9 - midend */
-                else if (strstr(gl_renderer, "9600"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_9600GT;
-                    vidmem = 384; /* The 9600GSO has 384MB, the 9600GT has 512-1024MB */
-                }
-                /* Geforce9 - midend low / Geforce 200 - low*/
-                else if (strstr(gl_renderer, "9500")
-                        || strstr(gl_renderer, "GT 120")
-                        || strstr(gl_renderer, "GT 130"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_9500GT;
-                    vidmem = 256; /* The 9500GT has 256-1024MB */
-                }
-                /* Geforce9 - lowend */
-                else if (strstr(gl_renderer, "9400"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_9400GT;
-                    vidmem = 256; /* The 9400GT has 256-1024MB */
-                }
-                /* Geforce9 - lowend low */
-                else if (strstr(gl_renderer, "9100")
-                        || strstr(gl_renderer, "9200")
-                        || strstr(gl_renderer, "9300")
-                        || strstr(gl_renderer, "G 100"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_9200;
-                    vidmem = 256; /* The 9100-9300 cards have 256MB */
-                }
-                /* Geforce8 - highend */
-                else if (strstr(gl_renderer, "8800"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_8800GTS;
-                    vidmem = 320; /* The 8800GTS uses 320MB, a 8800GTX can have 768MB */
-                }
-                /* Geforce8 - midend mobile */
-                else if (strstr(gl_renderer, "8600 M"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600MGT;
-                    vidmem = 512;
-                }
-                /* Geforce8 - midend */
-                else if (strstr(gl_renderer, "8600")
-                        || strstr(gl_renderer, "8700"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600GT;
-                    vidmem = 256;
-                }
-                /* Geforce8 - lowend */
-                else if (strstr(gl_renderer, "8300")
-                        || strstr(gl_renderer, "8400")
-                        || strstr(gl_renderer, "8500"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_8300GS;
-                    vidmem = 128; /* 128-256MB for a 8300, 256-512MB for a 8400 */
-                }
-                /* Geforce7 - highend */
-                else if (strstr(gl_renderer, "7800")
-                        || strstr(gl_renderer, "7900")
-                        || strstr(gl_renderer, "7950")
-                        || strstr(gl_renderer, "Quadro FX 4")
-                        || strstr(gl_renderer, "Quadro FX 5"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_7800GT;
-                    vidmem = 256; /* A 7800GT uses 256MB while highend 7900 cards can use 512MB */
-                }
-                /* Geforce7 midend */
-                else if (strstr(gl_renderer, "7600")
-                        || strstr(gl_renderer, "7700"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_7600;
-                    vidmem = 256; /* The 7600 uses 256-512MB */
-                /* Geforce7 lower medium */
-                }
-                else if (strstr(gl_renderer, "7400"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_7400;
-                    vidmem = 256; /* The 7400 uses 256-512MB */
-                }
-                /* Geforce7 lowend */
-                else if (strstr(gl_renderer, "7300"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_7300;
-                    vidmem = 256; /* Mac Pros with this card have 256 MB */
-                }
-                /* Geforce6 highend */
-                else if (strstr(gl_renderer, "6800"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_6800;
-                    vidmem = 128; /* The 6800 uses 128-256MB, the 7600 uses 256-512MB */
-                }
-                /* Geforce6 - midend */
-                else if (strstr(gl_renderer, "6600")
-                        || strstr(gl_renderer, "6610")
-                        || strstr(gl_renderer, "6700"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_6600GT;
-                    vidmem = 128; /* A 6600GT has 128-256MB */
-                }
-                /* Geforce6/7 lowend */
-                else {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
-                    vidmem = 64; /* */
-                }
-            } else if(WINE_D3D9_CAPABLE(gl_info)) {
-                /* GeforceFX - highend */
-                if (strstr(gl_renderer, "5800")
-                        || strstr(gl_renderer, "5900")
-                        || strstr(gl_renderer, "5950")
-                        || strstr(gl_renderer, "Quadro FX"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5800;
-                    vidmem = 256; /* 5800-5900 cards use 256MB */
-                }
-                /* GeforceFX - midend */
-                else if (strstr(gl_renderer, "5600")
-                        || strstr(gl_renderer, "5650")
-                        || strstr(gl_renderer, "5700")
-                        || strstr(gl_renderer, "5750"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
-                    vidmem = 128; /* A 5600 uses 128-256MB */
-                }
-                /* GeforceFX - lowend */
-                else {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
-                    vidmem = 64; /* Normal FX5200 cards use 64-256MB; laptop (non-standard) can have less */
-                }
-            } else if(WINE_D3D8_CAPABLE(gl_info)) {
-                if (strstr(gl_renderer, "GeForce4 Ti") || strstr(gl_renderer, "Quadro4"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
-                    vidmem = 64; /* Geforce4 Ti cards have 64-128MB */
-                }
-                else
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
-                    vidmem = 64; /* Geforce3 cards have 64-128MB */
-                }
-            } else if(WINE_D3D7_CAPABLE(gl_info)) {
-                if (strstr(gl_renderer, "GeForce4 MX"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
-                    vidmem = 64; /* Most Geforce4MX GPUs have at least 64MB of memory, some early models had 32MB but most have 64MB or even 128MB */
-                }
-                else if(strstr(gl_renderer, "GeForce2 MX") || strstr(gl_renderer, "Quadro2 MXR"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
-                    vidmem = 32; /* Geforce2MX GPUs have 32-64MB of video memory */
-                }
-                else if(strstr(gl_renderer, "GeForce2") || strstr(gl_renderer, "Quadro2"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
-                    vidmem = 32; /* Geforce2 GPUs have 32-64MB of video memory */
-                }
-                else
-                {
-                    gl_info->gl_card = CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
-                    vidmem = 32; /* Most Geforce1 cards have 32MB, there are also some rare 16 and 64MB (Dell) models */
-                }
-            } else {
-                if (strstr(gl_renderer, "TNT2"))
-                {
-                    gl_info->gl_card = CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
-                    vidmem = 32; /* Most TNT2 boards have 32MB, though there are 16MB boards too */
-                }
-                else
-                {
-                    gl_info->gl_card = CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
-                    vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
-                }
-            }
-            break;
-        case VENDOR_ATI:
-            /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx
-             *
-             * beware: renderer string do not match exact card model,
-             * eg HD 4800 is returned for multiple card, even for RV790 based one
-             */
-            if(WINE_D3D9_CAPABLE(gl_info)) {
-                /* Radeon R7xx HD4800 - highend */
-                if (strstr(gl_renderer, "HD 4800")          /* Radeon RV7xx HD48xx generic renderer string */
-                        || strstr(gl_renderer, "HD 4830")   /* Radeon RV770 */
-                        || strstr(gl_renderer, "HD 4850")   /* Radeon RV770 */
-                        || strstr(gl_renderer, "HD 4870")   /* Radeon RV770 */
-                        || strstr(gl_renderer, "HD 4890"))  /* Radeon RV790 */
-                {
-                    gl_info->gl_card = CARD_ATI_RADEON_HD4800;
-                    vidmem = 512; /* note: HD4890 cards use 1024MB */
-                }
-                /* Radeon R740 HD4700 - midend */
-                else if (strstr(gl_renderer, "HD 4700")     /* Radeon RV770 */
-                        || strstr(gl_renderer, "HD 4770"))  /* Radeon RV740 */
-                {
-                    gl_info->gl_card = CARD_ATI_RADEON_HD4700;
-                    vidmem = 512;
-                }
-                /* Radeon R730 HD4600 - midend */
-                else if (strstr(gl_renderer, "HD 4600")     /* Radeon RV730 */
-                        || strstr(gl_renderer, "HD 4650")   /* Radeon RV730 */
-                        || strstr(gl_renderer, "HD 4670"))  /* Radeon RV730 */
-                {
-                    gl_info->gl_card = CARD_ATI_RADEON_HD4600;
-                    vidmem = 512;
-                }
-                /* Radeon R710 HD4500/HD4350 - lowend */
-                else if (strstr(gl_renderer, "HD 4350")     /* Radeon RV710 */
-                        || strstr(gl_renderer, "HD 4550"))  /* Radeon RV710 */
-                {
-                    gl_info->gl_card = CARD_ATI_RADEON_HD4350;
-                    vidmem = 256;
-                }
-                /* Radeon R6xx HD2900/HD3800 - highend */
-                else if (strstr(gl_renderer, "HD 2900")
-                        || strstr(gl_renderer, "HD 3870")
-                        || strstr(gl_renderer, "HD 3850"))
-                {
-                    gl_info->gl_card = CARD_ATI_RADEON_HD2900;
-                    vidmem = 512; /* HD2900/HD3800 uses 256-1024MB */
-                }
-                /* Radeon R6xx HD2600/HD3600 - midend; HD3830 is China-only midend */
-                else if (strstr(gl_renderer, "HD 2600")
-                        || strstr(gl_renderer, "HD 3830")
-                        || strstr(gl_renderer, "HD 3690")
-                        || strstr(gl_renderer, "HD 3650"))
-                {
-                    gl_info->gl_card = CARD_ATI_RADEON_HD2600;
-                    vidmem = 256; /* HD2600/HD3600 uses 256-512MB */
-                }
-                /* Radeon R6xx HD2300/HD2400/HD3400 - lowend */
-                else if (strstr(gl_renderer, "HD 2300")
-                        || strstr(gl_renderer, "HD 2400")
-                        || strstr(gl_renderer, "HD 3470")
-                        || strstr(gl_renderer, "HD 3450")
-                        || strstr(gl_renderer, "HD 3430")
-                        || strstr(gl_renderer, "HD 3400"))
-                {
-                    gl_info->gl_card = CARD_ATI_RADEON_HD2300;
-                    vidmem = 128; /* HD2300 uses at least 128MB, HD2400 uses 256MB */
-                }
-                /* Radeon R6xx/R7xx integrated */
-                else if (strstr(gl_renderer, "HD 3100")
-                        || strstr(gl_renderer, "HD 3200")
-                        || strstr(gl_renderer, "HD 3300"))
-                {
-                    gl_info->gl_card = CARD_ATI_RADEON_HD3200;
-                    vidmem = 128; /* 128MB */
-                }
-                /* Radeon R5xx */
-                else if (strstr(gl_renderer, "X1600")
-                        || strstr(gl_renderer, "X1650")
-                        || strstr(gl_renderer, "X1800")
-                        || strstr(gl_renderer, "X1900")
-                        || strstr(gl_renderer, "X1950"))
-                {
-                    gl_info->gl_card = CARD_ATI_RADEON_X1600;
-                    vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
-                }
-                /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
-                else if(strstr(gl_renderer, "X700")
-                        || strstr(gl_renderer, "X800")
-                        || strstr(gl_renderer, "X850")
-                        || strstr(gl_renderer, "X1300")
-                        || strstr(gl_renderer, "X1400")
-                        || strstr(gl_renderer, "X1450")
-                        || strstr(gl_renderer, "X1550"))
-                {
-                    gl_info->gl_card = CARD_ATI_RADEON_X700;
-                    vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
-                }
-                /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400MHz */
-                else if(strstr(gl_renderer, "Radeon Xpress"))
-                {
-                    gl_info->gl_card = CARD_ATI_RADEON_XPRESS_200M;
-                    vidmem = 64; /* Shared RAM, BIOS configurable, 64-256M */
-                }
-                /* Radeon R3xx */ 
-                else {
-                    gl_info->gl_card = CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
-                    vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
-                }
-            } else if(WINE_D3D8_CAPABLE(gl_info)) {
-                gl_info->gl_card = CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
-                vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
-            } else if(WINE_D3D7_CAPABLE(gl_info)) {
-                gl_info->gl_card = CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
-                vidmem = 32; /* There are models with up to 64MB */
-            } else {
-                gl_info->gl_card = CARD_ATI_RAGE_128PRO;
-                vidmem = 16; /* There are 16-32MB models */
-            }
-            break;
-        case VENDOR_INTEL:
-            if(strstr(gl_renderer, "X3100"))
-            {
-                /* MacOS calls the card GMA X3100, Google findings also suggest the name GM965 */
-                gl_info->gl_card = CARD_INTEL_X3100;
-                vidmem = 128;
-            }
-            else if (strstr(gl_renderer, "GMA 950") || strstr(gl_renderer, "945GM"))
-            {
-                /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */
-                gl_info->gl_card = CARD_INTEL_I945GM;
-                vidmem = 64;
-            }
-            else if (strstr(gl_renderer, "915GM"))
-            {
-                gl_info->gl_card = CARD_INTEL_I915GM;
-            }
-            else if (strstr(gl_renderer, "915G"))
-            {
-                gl_info->gl_card = CARD_INTEL_I915G;
-            }
-            else if (strstr(gl_renderer, "865G"))
-            {
-                gl_info->gl_card = CARD_INTEL_I865G;
-            }
-            else if (strstr(gl_renderer, "855G"))
-            {
-                gl_info->gl_card = CARD_INTEL_I855G;
-            }
-            else if (strstr(gl_renderer, "830G"))
-            {
-                gl_info->gl_card = CARD_INTEL_I830G;
-            } else {
-                gl_info->gl_card = CARD_INTEL_I915G;
-            }
-            break;
-        case VENDOR_MESA:
-        case VENDOR_WINE:
-        default:
-            /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice 
-             * for Nvidia was because the hardware and drivers they make are of good quality. This makes
-             * them a good generic choice.
-             */
-            gl_info->gl_vendor = VENDOR_NVIDIA;
-            if(WINE_D3D9_CAPABLE(gl_info))
-                gl_info->gl_card = CARD_NVIDIA_GEFORCEFX_5600;
-            else if(WINE_D3D8_CAPABLE(gl_info))
-                gl_info->gl_card = CARD_NVIDIA_GEFORCE3;
-            else if(WINE_D3D7_CAPABLE(gl_info))
-                gl_info->gl_card = CARD_NVIDIA_GEFORCE;
-            else if(WINE_D3D6_CAPABLE(gl_info))
-                gl_info->gl_card = CARD_NVIDIA_RIVA_TNT;
-            else
-                gl_info->gl_card = CARD_NVIDIA_RIVA_128;
-    }
+    gl_info->gl_card = wined3d_guess_card(gl_info, gl_renderer, &gl_info->gl_vendor, &vidmem);
     TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card);
 
@@ -2044,5 +2000,5 @@
                 memcpy(ThisExtn, Start, len);
                 ThisExtn[len] = '\0';
-                TRACE_(d3d_caps)("- %s\n", ThisExtn);
+                TRACE_(d3d_caps)("- %s\n", debugstr_a(ThisExtn));
 
                 if (!strcmp(ThisExtn, "WGL_ARB_pbuffer")) {
@@ -2061,5 +2017,4 @@
         }
     }
-    LEAVE_GL();
 
     fixup_extensions(gl_info, gl_renderer);
@@ -2131,13 +2086,13 @@
                     break;
 
-                case WINED3DFMT_X8R8G8B8:
+                case WINED3DFMT_B8G8R8X8_UNORM:
                     if (mode.dmBitsPerPel == 32) ++i;
                     break;
 
-                case WINED3DFMT_R5G6B5:
+                case WINED3DFMT_B5G6R5_UNORM:
                     if (mode.dmBitsPerPel == 16) ++i;
                     break;
 
-                case WINED3DFMT_P8:
+                case WINED3DFMT_P8_UINT:
                     if (mode.dmBitsPerPel == 8) ++i;
                     break;
@@ -2191,11 +2146,11 @@
                         DevModeW.dmBitsPerPel == 16) i++;
                     break;
-                case WINED3DFMT_X8R8G8B8:
+                case WINED3DFMT_B8G8R8X8_UNORM:
                     if (DevModeW.dmBitsPerPel == 32) i++;
                     break;
-                case WINED3DFMT_R5G6B5:
+                case WINED3DFMT_B5G6R5_UNORM:
                     if (DevModeW.dmBitsPerPel == 16) i++;
                     break;
-                case WINED3DFMT_P8:
+                case WINED3DFMT_P8_UINT:
                     if (DevModeW.dmBitsPerPel == 8) i++;
                     break;
@@ -2217,5 +2172,5 @@
             pMode->Width        = DevModeW.dmPelsWidth;
             pMode->Height       = DevModeW.dmPelsHeight;
-            pMode->RefreshRate  = WINED3DADAPTER_DEFAULT;
+            pMode->RefreshRate  = DEFAULT_REFRESH_RATE;
             if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
                 pMode->RefreshRate = DevModeW.dmDisplayFrequency;
@@ -2264,5 +2219,5 @@
         pMode->Height       = DevModeW.dmPelsHeight;
         bpp                 = DevModeW.dmBitsPerPel;
-        pMode->RefreshRate  = WINED3DADAPTER_DEFAULT;
+        pMode->RefreshRate  = DEFAULT_REFRESH_RATE;
         if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
         {
@@ -2422,5 +2377,5 @@
     }
 
-    if ((format_desc->format == WINED3DFMT_D16_LOCKABLE) || (format_desc->format == WINED3DFMT_D32F_LOCKABLE))
+    if ((format_desc->format == WINED3DFMT_D16_LOCKABLE) || (format_desc->format == WINED3DFMT_D32_FLOAT))
         lockable = TRUE;
 
@@ -2483,8 +2438,7 @@
 }
 
-static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, 
-                                                       WINED3DFORMAT SurfaceFormat,
-                                                       BOOL Windowed, WINED3DMULTISAMPLE_TYPE MultiSampleType, DWORD*   pQualityLevels) {
-
+static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
+        WINED3DFORMAT SurfaceFormat, BOOL Windowed, WINED3DMULTISAMPLE_TYPE MultiSampleType, DWORD *pQualityLevels)
+{
     IWineD3DImpl *This = (IWineD3DImpl *)iface;
     const struct GlPixelFormatDesc *glDesc;
@@ -2606,8 +2560,8 @@
 
     /* There are only 4 display formats */
-    if(!((DisplayFormat == WINED3DFMT_R5G6B5) ||
-         (DisplayFormat == WINED3DFMT_X1R5G5B5) ||
-         (DisplayFormat == WINED3DFMT_X8R8G8B8) ||
-         (DisplayFormat == WINED3DFMT_A2R10G10B10)))
+    if (!(DisplayFormat == WINED3DFMT_B5G6R5_UNORM
+            || DisplayFormat == WINED3DFMT_B5G5R5X1_UNORM
+            || DisplayFormat == WINED3DFMT_B8G8R8X8_UNORM
+            || DisplayFormat == WINED3DFMT_B10G10R10A2_UNORM))
     {
         TRACE_(d3d_caps)("Format %s unsupported as display format\n", debug_d3dformat(DisplayFormat));
@@ -2629,5 +2583,6 @@
 
     /* In FULLSCREEN mode R5G6B5 can only be mixed with backbuffer format R5G6B5 */
-    if( (DisplayFormat == WINED3DFMT_R5G6B5) && (BackBufferFormat != WINED3DFMT_R5G6B5) ) {
+    if (DisplayFormat == WINED3DFMT_B5G6R5_UNORM && BackBufferFormat != WINED3DFMT_B5G6R5_UNORM)
+    {
         TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
         return WINED3DERR_NOTAVAILABLE;
@@ -2635,5 +2590,7 @@
 
     /* In FULLSCREEN mode X1R5G5B5 can only be mixed with backbuffer format *1R5G5B5 */
-    if( (DisplayFormat == WINED3DFMT_X1R5G5B5) && !((BackBufferFormat == WINED3DFMT_X1R5G5B5) || (BackBufferFormat == WINED3DFMT_A1R5G5B5)) ) {
+    if (DisplayFormat == WINED3DFMT_B5G5R5X1_UNORM
+            && !(BackBufferFormat == WINED3DFMT_B5G5R5X1_UNORM || BackBufferFormat == WINED3DFMT_B5G5R5A1_UNORM))
+    {
         TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
         return WINED3DERR_NOTAVAILABLE;
@@ -2641,5 +2598,7 @@
 
     /* In FULLSCREEN mode X8R8G8B8 can only be mixed with backbuffer format *8R8G8B8 */
-    if( (DisplayFormat == WINED3DFMT_X8R8G8B8) && !((BackBufferFormat == WINED3DFMT_X8R8G8B8) || (BackBufferFormat == WINED3DFMT_A8R8G8B8)) ) {
+    if (DisplayFormat == WINED3DFMT_B8G8R8X8_UNORM
+            && !(BackBufferFormat == WINED3DFMT_B8G8R8X8_UNORM || BackBufferFormat == WINED3DFMT_B8G8R8A8_UNORM))
+    {
         TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
         return WINED3DERR_NOTAVAILABLE;
@@ -2647,5 +2606,7 @@
 
     /* A2R10G10B10 is only allowed in fullscreen mode and it can only be mixed with backbuffer format A2R10G10B10 */
-    if( (DisplayFormat == WINED3DFMT_A2R10G10B10) && ((BackBufferFormat != WINED3DFMT_A2R10G10B10) || Windowed)) {
+    if (DisplayFormat == WINED3DFMT_B10G10R10A2_UNORM
+            && (BackBufferFormat != WINED3DFMT_B10G10R10A2_UNORM || Windowed))
+    {
         TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s/%s\n", debug_d3dformat(DisplayFormat), debug_d3dformat(BackBufferFormat));
         return WINED3DERR_NOTAVAILABLE;
@@ -2671,6 +2632,6 @@
         case WINED3DFMT_R8G8_SNORM:
         case WINED3DFMT_R16G16_SNORM:
-        case WINED3DFMT_L6V5U5:
-        case WINED3DFMT_X8L8V8U8:
+        case WINED3DFMT_R5G5_SNORM_L6_UNORM:
+        case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
         case WINED3DFMT_R8G8B8A8_SNORM:
             /* Ask the fixed function pipeline implementation if it can deal
@@ -2796,9 +2757,9 @@
     switch (format_desc->format)
     {
-        case WINED3DFMT_A8R8G8B8:
-        case WINED3DFMT_X8R8G8B8:
-        case WINED3DFMT_A4R4G4B4:
-        case WINED3DFMT_L8:
-        case WINED3DFMT_A8L8:
+        case WINED3DFMT_B8G8R8A8_UNORM:
+        case WINED3DFMT_B8G8R8X8_UNORM:
+        case WINED3DFMT_B4G4R4A4_UNORM:
+        case WINED3DFMT_L8_UNORM:
+        case WINED3DFMT_L8A8_UNORM:
         case WINED3DFMT_DXT1:
         case WINED3DFMT_DXT2:
@@ -2822,9 +2783,9 @@
      * doing the color fixup in shaders.
      * Note Windows drivers (at least on the Geforce 8800) also offer this on R5G6B5. */
-    if ((format_desc->format == WINED3DFMT_X8R8G8B8) || (format_desc->format == WINED3DFMT_A8R8G8B8))
+    if ((format_desc->format == WINED3DFMT_B8G8R8X8_UNORM) || (format_desc->format == WINED3DFMT_B8G8R8A8_UNORM))
     {
         int vs_selected_mode;
         int ps_selected_mode;
-        select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
+        select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
 
         if((ps_selected_mode == SHADER_ARB) || (ps_selected_mode == SHADER_GLSL)) {
@@ -2875,23 +2836,22 @@
          *  supported: RGB(A) formats
          */
-        case WINED3DFMT_R8G8B8: /* Enable for dx7, blacklisted for 8 and 9 above */
-        case WINED3DFMT_A8R8G8B8:
-        case WINED3DFMT_X8R8G8B8:
-        case WINED3DFMT_R5G6B5:
-        case WINED3DFMT_X1R5G5B5:
-        case WINED3DFMT_A1R5G5B5:
-        case WINED3DFMT_A4R4G4B4:
+        case WINED3DFMT_B8G8R8_UNORM: /* Enable for dx7, blacklisted for 8 and 9 above */
+        case WINED3DFMT_B8G8R8A8_UNORM:
+        case WINED3DFMT_B8G8R8X8_UNORM:
+        case WINED3DFMT_B5G6R5_UNORM:
+        case WINED3DFMT_B5G5R5X1_UNORM:
+        case WINED3DFMT_B5G5R5A1_UNORM:
+        case WINED3DFMT_B4G4R4A4_UNORM:
         case WINED3DFMT_A8_UNORM:
-        case WINED3DFMT_X4R4G4B4:
+        case WINED3DFMT_B4G4R4X4_UNORM:
         case WINED3DFMT_R8G8B8A8_UNORM:
-        case WINED3DFMT_X8B8G8R8:
-        case WINED3DFMT_A2R10G10B10:
+        case WINED3DFMT_R8G8B8X8_UNORM:
+        case WINED3DFMT_B10G10R10A2_UNORM:
         case WINED3DFMT_R10G10B10A2_UNORM:
         case WINED3DFMT_R16G16_UNORM:
-        case WINED3DFMT_R16G16B16A16_UNORM:
             TRACE_(d3d_caps)("[OK]\n");
             return TRUE;
 
-        case WINED3DFMT_R3G3B2:
+        case WINED3DFMT_B2G3R3_UNORM:
             TRACE_(d3d_caps)("[FAILED] - Not supported on Windows\n");
             return FALSE;
@@ -2900,9 +2860,9 @@
          *  supported: Palettized
          */
-        case WINED3DFMT_P8:
+        case WINED3DFMT_P8_UINT:
             TRACE_(d3d_caps)("[OK]\n");
             return TRUE;
-        /* No Windows driver offers A8P8, so don't offer it either */
-        case WINED3DFMT_A8P8:
+        /* No Windows driver offers WINED3DFMT_P8_UINT_A8_UNORM, so don't offer it either */
+        case WINED3DFMT_P8_UINT_A8_UNORM:
             return FALSE;
 
@@ -2910,12 +2870,12 @@
          *  Supported: (Alpha)-Luminance
          */
-        case WINED3DFMT_L8:
-        case WINED3DFMT_A8L8:
-        case WINED3DFMT_L16:
+        case WINED3DFMT_L8_UNORM:
+        case WINED3DFMT_L8A8_UNORM:
+        case WINED3DFMT_L16_UNORM:
             TRACE_(d3d_caps)("[OK]\n");
             return TRUE;
 
         /* Not supported on Windows, thus disabled */
-        case WINED3DFMT_A4L4:
+        case WINED3DFMT_L4A4_UNORM:
             TRACE_(d3d_caps)("[FAILED] - not supported on windows\n");
             return FALSE;
@@ -2926,11 +2886,11 @@
         case WINED3DFMT_D16_LOCKABLE:
         case WINED3DFMT_D16_UNORM:
-        case WINED3DFMT_D15S1:
-        case WINED3DFMT_D24X8:
-        case WINED3DFMT_D24X4S4:
-        case WINED3DFMT_D24S8:
-        case WINED3DFMT_D24FS8:
-        case WINED3DFMT_D32:
-        case WINED3DFMT_D32F_LOCKABLE:
+        case WINED3DFMT_S1_UINT_D15_UNORM:
+        case WINED3DFMT_X8D24_UNORM:
+        case WINED3DFMT_S4X4_UINT_D24_UNORM:
+        case WINED3DFMT_S8_UINT_D24_UNORM:
+        case WINED3DFMT_S8_UINT_D24_FLOAT:
+        case WINED3DFMT_D32_UNORM:
+        case WINED3DFMT_D32_FLOAT:
             return TRUE;
 
@@ -2940,6 +2900,6 @@
          */
         case WINED3DFMT_R8G8_SNORM:
-        case WINED3DFMT_X8L8V8U8:
-        case WINED3DFMT_L6V5U5:
+        case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
+        case WINED3DFMT_R5G5_SNORM_L6_UNORM:
         case WINED3DFMT_R8G8B8A8_SNORM:
         case WINED3DFMT_R16G16_SNORM:
@@ -2976,13 +2936,13 @@
         case WINED3DFMT_R32_UINT:
         case WINED3DFMT_R16G16B16A16_SNORM:
-        case WINED3DFMT_A2W10V10U10:
-        case WINED3DFMT_W11V11U10:
+        case WINED3DFMT_R10G10B10_SNORM_A2_UNORM:
+        case WINED3DFMT_R10G11B11_SNORM:
             TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
             return FALSE;
 
         /*****
-         *  WINED3DFMT_CxV8U8: Not supported right now
+         *  WINED3DFMT_R8G8_SNORM_Cx: Not supported right now
          */
-        case WINED3DFMT_CxV8U8:
+        case WINED3DFMT_R8G8_SNORM_Cx:
             TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
             return FALSE;
@@ -3002,5 +2962,6 @@
 
             /* Not supported */
-        case WINED3DFMT_A8R3G3B2:
+        case WINED3DFMT_R16G16B16A16_UNORM:
+        case WINED3DFMT_B2G3R3A8_UNORM:
             TRACE_(d3d_caps)("[FAILED]\n"); /* Enable when implemented */
             return FALSE;
@@ -3100,22 +3061,22 @@
         switch(check_format_desc->format)
         {
-            case WINED3DFMT_R8G8B8:
-            case WINED3DFMT_A8R8G8B8:
-            case WINED3DFMT_X8R8G8B8:
-            case WINED3DFMT_R5G6B5:
-            case WINED3DFMT_X1R5G5B5:
-            case WINED3DFMT_A1R5G5B5:
-            case WINED3DFMT_A4R4G4B4:
-            case WINED3DFMT_R3G3B2:
+            case WINED3DFMT_B8G8R8_UNORM:
+            case WINED3DFMT_B8G8R8A8_UNORM:
+            case WINED3DFMT_B8G8R8X8_UNORM:
+            case WINED3DFMT_B5G6R5_UNORM:
+            case WINED3DFMT_B5G5R5X1_UNORM:
+            case WINED3DFMT_B5G5R5A1_UNORM:
+            case WINED3DFMT_B4G4R4A4_UNORM:
+            case WINED3DFMT_B2G3R3_UNORM:
             case WINED3DFMT_A8_UNORM:
-            case WINED3DFMT_A8R3G3B2:
-            case WINED3DFMT_X4R4G4B4:
+            case WINED3DFMT_B2G3R3A8_UNORM:
+            case WINED3DFMT_B4G4R4X4_UNORM:
             case WINED3DFMT_R10G10B10A2_UNORM:
             case WINED3DFMT_R8G8B8A8_UNORM:
-            case WINED3DFMT_X8B8G8R8:
+            case WINED3DFMT_R8G8B8X8_UNORM:
             case WINED3DFMT_R16G16_UNORM:
-            case WINED3DFMT_A2R10G10B10:
+            case WINED3DFMT_B10G10R10A2_UNORM:
             case WINED3DFMT_R16G16B16A16_UNORM:
-            case WINED3DFMT_P8:
+            case WINED3DFMT_P8_UINT:
                 TRACE_(d3d_caps)("[OK]\n");
                 return TRUE;
@@ -3170,7 +3131,8 @@
 }
 
-static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, 
+static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
         WINED3DFORMAT AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType, WINED3DFORMAT CheckFormat,
-        WINED3DSURFTYPE SurfaceType) {
+        WINED3DSURFTYPE SurfaceType)
+{
     IWineD3DImpl *This = (IWineD3DImpl *)iface;
     struct WineD3DAdapter *adapter = &This->adapters[Adapter];
@@ -3606,10 +3568,10 @@
          */
         switch(CheckFormat) {
-            case WINED3DFMT_P8:
-            case WINED3DFMT_A4L4:
+            case WINED3DFMT_P8_UINT:
+            case WINED3DFMT_L4A4_UNORM:
             case WINED3DFMT_R32_FLOAT:
             case WINED3DFMT_R16_FLOAT:
-            case WINED3DFMT_X8L8V8U8:
-            case WINED3DFMT_L6V5U5:
+            case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
+            case WINED3DFMT_R5G5_SNORM_L6_UNORM:
             case WINED3DFMT_R16G16_UNORM:
                 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
@@ -3686,5 +3648,5 @@
     int ps_selected_mode;
 
-    select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
+    select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
     if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) {
         ret = &glsl_shader_backend;
@@ -3704,5 +3666,5 @@
     int ps_selected_mode;
 
-    select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
+    select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
     if((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
         return &arbfp_fragment_pipeline;
@@ -3724,5 +3686,5 @@
     int ps_selected_mode;
 
-    select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
+    select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
     if((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
         return &arbfp_blit;
@@ -3754,5 +3716,5 @@
     }
 
-    select_shader_mode(&adapter->gl_info, DeviceType, &ps_selected_mode, &vs_selected_mode);
+    select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
 
     /* This function should *not* be modifying GL caps
@@ -4076,4 +4038,5 @@
 
 
+    /* FIXME: Add D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
     pCaps->VertexProcessingCaps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
                                   WINED3DVTXPCAPS_MATERIALSOURCE7   |
@@ -4082,6 +4045,4 @@
                                   WINED3DVTXPCAPS_VERTEXFOG         |
                                   WINED3DVTXPCAPS_TEXGEN;
-                                  /* FIXME: Add 
-                                     D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
 
     pCaps->MaxPrimitiveCount   = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
@@ -4373,6 +4334,5 @@
     object->devType                      = DeviceType;
 
-    select_shader_mode(&adapter->gl_info, DeviceType,
-            &object->ps_selected_mode, &object->vs_selected_mode);
+    select_shader_mode(&adapter->gl_info, &object->ps_selected_mode, &object->vs_selected_mode);
     object->shader_backend = select_shader_backend(adapter, DeviceType);
 
@@ -4425,14 +4385,4 @@
     *pParent = This->parent;
     return WINED3D_OK;
-}
-
-ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface) {
-    IUnknown* surfaceParent;
-    TRACE("(%p) call back\n", pSurface);
-
-    /* Now, release the parent, which will take care of cleaning up the surface for us */
-    IWineD3DSurface_GetParent(pSurface, &surfaceParent);
-    IUnknown_Release(surfaceParent);
-    return IUnknown_Release(surfaceParent);
 }
 
@@ -4672,9 +4622,9 @@
      */
 #ifdef USE_WIN32_OPENGL
-    glFinish = (void*)GetProcAddress(mod_gl, "glFinish");
-    glFlush = (void*)GetProcAddress(mod_gl, "glFlush");
+    wglFinish = (void*)GetProcAddress(mod_gl, "glFinish");
+    wglFlush = (void*)GetProcAddress(mod_gl, "glFlush");
 #else
-    glFinish = (void*)pwglGetProcAddress("wglFinish");
-    glFlush = (void*)pwglGetProcAddress("wglFlush");
+    wglFinish = (void*)pwglGetProcAddress("wglFinish");
+    wglFlush = (void*)pwglGetProcAddress("wglFlush");
 #endif
 
@@ -4882,5 +4832,5 @@
         WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
 
-        select_shader_mode(&adapter->gl_info, WINED3DDEVTYPE_HAL, &ps_selected_mode, &vs_selected_mode);
+        select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
         select_shader_max_constants(ps_selected_mode, vs_selected_mode, &adapter->gl_info);
         fillGLAttribFuncs(&adapter->gl_info);
@@ -4941,2 +4891,9 @@
     IWineD3DImpl_CreateDevice
 };
+
+static void STDMETHODCALLTYPE wined3d_null_wined3d_object_destroyed(void *parent) {}
+
+const struct wined3d_parent_ops wined3d_null_parent_ops =
+{
+    wined3d_null_wined3d_object_destroyed,
+};
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/drawprim.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/drawprim.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/drawprim.c	(revision 23571)
@@ -8,4 +8,5 @@
  * Copyright 2006, 2008 Henri Verbeet
  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -46,6 +47,5 @@
 /* GL locking is done by the caller */
 static void drawStridedFast(IWineD3DDevice *iface, GLenum primitive_type,
-        UINT min_vertex_idx, UINT max_vertex_idx, UINT count, UINT idx_size,
-        const void *idx_data, UINT start_idx)
+        UINT count, UINT idx_size, const void *idx_data, UINT start_idx)
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
@@ -53,17 +53,10 @@
     if (idx_size)
     {
-        TRACE("(%p) : glElements(%x, %d, %d, ...)\n", This, primitive_type, count, min_vertex_idx);
-
-#if 1
+        TRACE("(%p) : glElements(%x, %d, ...)\n", This, primitive_type, count);
+
         glDrawElements(primitive_type, count,
                 idx_size == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,
                 (const char *)idx_data + (idx_size * start_idx));
         checkGLcall("glDrawElements");
-#else
-        glDrawRangeElements(primitive_type, min_vertex_idx, max_vertex_idx, count,
-                idx_size == 2 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_INT,
-                (const char *)idx_data + (idx_size * start_idx));
-        checkGLcall("glDrawRangeElements");
-#endif
     }
     else
@@ -84,5 +77,5 @@
 static void drawStridedSlow(IWineD3DDevice *iface, const struct wined3d_context *context,
         const struct wined3d_stream_info *si, UINT NumVertexes, GLenum glPrimType,
-        const void *idxData, UINT idxSize, UINT minIndex, UINT startIdx)
+        const void *idxData, UINT idxSize, UINT startIdx)
 {
     unsigned int               textureNo    = 0;
@@ -125,21 +118,37 @@
     glBegin(glPrimType);
 
-    element = &si->elements[WINED3D_FFP_POSITION];
-    if (element->data) position = element->data + streamOffset[element->stream_idx];
-
-    element = &si->elements[WINED3D_FFP_NORMAL];
-    if (element->data) normal = element->data + streamOffset[element->stream_idx];
-    else glNormal3f(0, 0, 0);
-
-    element = &si->elements[WINED3D_FFP_DIFFUSE];
-    if (element->data) diffuse = element->data + streamOffset[element->stream_idx];
-    else glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+    if (si->use_map & (1 << WINED3D_FFP_POSITION))
+    {
+        element = &si->elements[WINED3D_FFP_POSITION];
+        position = element->data + streamOffset[element->stream_idx];
+    }
+
+    if (si->use_map & (1 << WINED3D_FFP_NORMAL))
+    {
+        element = &si->elements[WINED3D_FFP_NORMAL];
+        normal = element->data + streamOffset[element->stream_idx];
+    }
+    else
+    {
+        glNormal3f(0, 0, 0);
+    }
+
     num_untracked_materials = context->num_untracked_materials;
-    if (num_untracked_materials && element->format_desc->format != WINED3DFMT_A8R8G8B8)
-        FIXME("Implement diffuse color tracking from %s\n", debug_d3dformat(element->format_desc->format));
-
-    element = &si->elements[WINED3D_FFP_SPECULAR];
-    if (element->data)
-    {
+    if (si->use_map & (1 << WINED3D_FFP_DIFFUSE))
+    {
+        element = &si->elements[WINED3D_FFP_DIFFUSE];
+        diffuse = element->data + streamOffset[element->stream_idx];
+
+        if (num_untracked_materials && element->format_desc->format != WINED3DFMT_B8G8R8A8_UNORM)
+            FIXME("Implement diffuse color tracking from %s\n", debug_d3dformat(element->format_desc->format));
+    }
+    else
+    {
+        glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+    }
+
+    if (si->use_map & (1 << WINED3D_FFP_SPECULAR))
+    {
+        element = &si->elements[WINED3D_FFP_SPECULAR];
         specular = element->data + streamOffset[element->stream_idx];
 
@@ -152,5 +161,5 @@
             if (GL_SUPPORT(EXT_FOG_COORD))
             {
-                if (element->format_desc->format == WINED3DFMT_A8R8G8B8) specular_fog = TRUE;
+                if (element->format_desc->format == WINED3DFMT_B8G8R8A8_UNORM) specular_fog = TRUE;
                 else FIXME("Implement fog coordinates from %s\n", debug_d3dformat(element->format_desc->format));
             }
@@ -176,5 +185,5 @@
     {
         int coordIdx = This->stateBlock->textureState[textureNo][WINED3DTSS_TEXCOORDINDEX];
-        int texture_idx = This->texUnitMap[textureNo];
+        DWORD texture_idx = This->texUnitMap[textureNo];
 
         if (!GL_SUPPORT(ARB_MULTITEXTURE) && textureNo > 0)
@@ -186,5 +195,5 @@
         if (!pixelShader && !This->stateBlock->textures[textureNo]) continue;
 
-        if (texture_idx == -1) continue;
+        if (texture_idx == WINED3D_UNMAPPED_STAGE) continue;
 
         if (coordIdx > 7)
@@ -199,7 +208,7 @@
         }
 
-        element = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx];
-        if (element->data)
-        {
+        if (si->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx)))
+        {
+            element = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx];
             texCoords[coordIdx] = element->data + streamOffset[element->stream_idx];
             tex_mask |= (1 << textureNo);
@@ -244,5 +253,5 @@
             int coord_idx;
             const void *ptr;
-            int texture_idx;
+            DWORD texture_idx;
 
             if (!(tmp_tex_mask & 1)) continue;
@@ -335,5 +344,5 @@
             GL_EXTCALL(glVertexAttrib4ubvARB(index, ptr));
             break;
-        case WINED3DFMT_A8R8G8B8:
+        case WINED3DFMT_B8G8R8A8_UNORM:
             if (GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA))
             {
@@ -419,5 +428,5 @@
 /* GL locking is done by the caller */
 static void drawStridedSlowVs(IWineD3DDevice *iface, const struct wined3d_stream_info *si, UINT numberOfVertices,
-        GLenum glPrimitiveType, const void *idxData, UINT idxSize, UINT minIndex, UINT startIdx)
+        GLenum glPrimitiveType, const void *idxData, UINT idxSize, UINT startIdx)
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
@@ -463,6 +472,7 @@
         }
 
-        for(i = MAX_ATTRIBS - 1; i >= 0; i--) {
-            if(!si->elements[i].data) continue;
+        for (i = MAX_ATTRIBS - 1; i >= 0; i--)
+        {
+            if (!(si->use_map & (1 << i))) continue;
 
             ptr = si->elements[i].data +
@@ -480,5 +490,5 @@
 /* GL locking is done by the caller */
 static inline void drawStridedInstanced(IWineD3DDevice *iface, const struct wined3d_stream_info *si,
-        UINT numberOfVertices, GLenum glPrimitiveType, const void *idxData, UINT idxSize, UINT minIndex,
+        UINT numberOfVertices, GLenum glPrimitiveType, const void *idxData, UINT idxSize,
         UINT startIdx)
 {
@@ -500,5 +510,5 @@
     }
 
-    TRACE("(%p) : glElements(%x, %d, %d, ...)\n", This, glPrimitiveType, numberOfVertices, minIndex);
+    TRACE("(%p) : glElements(%x, %d, ...)\n", This, glPrimitiveType, numberOfVertices);
 
     /* First, figure out how many instances we have to draw */
@@ -518,4 +528,6 @@
     for (i = 0; i < sizeof(si->elements) / sizeof(*si->elements); ++i)
     {
+        if (!(si->use_map & (1 << i))) continue;
+
         if (stateblock->streamFlags[si->elements[i].stream_idx] & WINED3DSTREAMSOURCE_INSTANCEDATA)
         {
@@ -554,5 +566,9 @@
     for (i = 0; i < (sizeof(s->elements) / sizeof(*s->elements)); ++i)
     {
-        struct wined3d_stream_info_element *e = &s->elements[i];
+        struct wined3d_stream_info_element *e;
+
+        if (!(s->use_map & (1 << i))) continue;
+
+        e = &s->elements[i];
         if (e->buffer_object)
         {
@@ -565,6 +581,5 @@
 
 /* Routine common to the draw primitive and draw indexed primitive routines */
-void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT numberOfVertices,
-        UINT StartIdx, UINT idxSize, const void *idxData, UINT minIndex)
+void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT StartIdx, UINT idxSize, const void *idxData)
 {
 
@@ -616,6 +631,4 @@
         const struct wined3d_stream_info *stream_info = &This->strided_streams;
         struct wined3d_stream_info stridedlcl;
-
-        if (!numberOfVertices) numberOfVertices = index_count;
 
         if (!use_vs(This->stateBlock))
@@ -666,16 +679,15 @@
                     TRACE("Using immediate mode with vertex shaders for half float emulation\n");
                 }
-                drawStridedSlowVs(iface, stream_info, index_count, glPrimType, idxData, idxSize, minIndex, StartIdx);
+                drawStridedSlowVs(iface, stream_info, index_count, glPrimType, idxData, idxSize, StartIdx);
             } else {
                 drawStridedSlow(iface, context, stream_info, index_count,
-                        glPrimType, idxData, idxSize, minIndex, StartIdx);
+                        glPrimType, idxData, idxSize, StartIdx);
             }
         } else if(This->instancedDraw) {
             /* Instancing emulation with mixing immediate mode and arrays */
             drawStridedInstanced(iface, &This->strided_streams, index_count,
-                    glPrimType, idxData, idxSize, minIndex, StartIdx);
+                    glPrimType, idxData, idxSize, StartIdx);
         } else {
-            drawStridedFast(iface, glPrimType, minIndex, minIndex + numberOfVertices - 1,
-                    index_count, idxSize, idxData, StartIdx);
+            drawStridedFast(iface, glPrimType, index_count, idxSize, idxData, StartIdx);
         }
     }
@@ -689,5 +701,5 @@
     {
         static long int primCounter = 0;
-        /* NOTE: set primCounter to the value reported by drawprim 
+        /* NOTE: set primCounter to the value reported by drawprim
            before you want to to write frame makeup to /tmp */
         if (primCounter >= 0) {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c	(revision 23571)
@@ -2,5 +2,5 @@
  * GLSL pixel and vertex shader implementation
  *
- * Copyright 2006 Jason Green 
+ * Copyright 2006 Jason Green
  * Copyright 2006-2007 Henri Verbeet
  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
@@ -198,12 +198,12 @@
     {
         "Vertex shader was successfully compiled to run on hardware.\n",    /* fglrx          */
-        "Fragment shader was successfully compiled to run on hardware.\n",  /* fglrx          */
+        "Fragment shader was successfully compiled to run on hardware.\n",  /* fglrx, with \n */
+        "Fragment shader was successfully compiled to run on hardware.",    /* fglrx, no \n   */
         "Fragment shader(s) linked, vertex shader(s) linked. \n ",          /* fglrx, with \n */
         "Fragment shader(s) linked, vertex shader(s) linked.",              /* fglrx, no \n   */
         "Vertex shader(s) linked, no fragment shader(s) defined. \n ",      /* fglrx, with \n */
         "Vertex shader(s) linked, no fragment shader(s) defined.",          /* fglrx, no \n   */
-        "Fragment shader was successfully compiled to run on hardware.\n"
+        "Fragment shader(s) linked, no vertex shader(s) defined. \n ",      /* fglrx, with \n */
         "Fragment shader(s) linked, no vertex shader(s) defined.",          /* fglrx, no \n   */
-        "Fragment shader(s) linked, no vertex shader(s) defined. \n ",      /* fglrx, with \n */
     };
 
@@ -825,4 +825,5 @@
     unsigned int i, extra_constants_needed = 0;
     const local_constant *lconst;
+    DWORD map;
 
     /* There are some minor differences between pixel and vertex shaders */
@@ -831,7 +832,7 @@
 
     /* Prototype the subroutines */
-    for (i = 0; i < This->baseShader.limits.label; i++) {
-        if (reg_maps->labels[i])
-            shader_addline(buffer, "void subroutine%u();\n", i);
+    for (i = 0, map = reg_maps->labels; map; map >>= 1, ++i)
+    {
+        if (map & 1) shader_addline(buffer, "void subroutine%u();\n", i);
     }
 
@@ -909,12 +910,12 @@
         }
     } else {
-        for(i = 0; i < (sizeof(reg_maps->bumpmat) / sizeof(reg_maps->bumpmat[0])); i++) {
-            if(!reg_maps->bumpmat[i]) {
-                continue;
-            }
+        for (i = 0, map = reg_maps->bumpmat; map; map >>= 1, ++i)
+        {
+            if (!(map & 1)) continue;
 
             shader_addline(buffer, "uniform mat2 bumpenvmat%d;\n", i);
 
-            if(reg_maps->luminanceparams) {
+            if (reg_maps->luminanceparams & (1 << i))
+            {
                 shader_addline(buffer, "uniform float luminancescale%d;\n", i);
                 shader_addline(buffer, "uniform float luminanceoffset%d;\n", i);
@@ -950,5 +951,5 @@
     }
 
-    /* Declare texture samplers */ 
+    /* Declare texture samplers */
     for (i = 0; i < This->baseShader.limits.sampler; i++) {
         if (reg_maps->sampler_type[i])
@@ -984,5 +985,5 @@
      * This is NOT done inside the loop that declares the texture samplers since the NP2 fixup code
      * is currently only used for the GeforceFX series and when forcing the ARB_npot extension off.
-     * Modern cards just skip the code anyway, so put it inside a seperate loop. */
+     * Modern cards just skip the code anyway, so put it inside a separate loop. */
     if (pshader && ps_args->np2_fixup) {
 
@@ -1013,13 +1014,13 @@
 
     /* Declare address variables */
-    for (i = 0; i < This->baseShader.limits.address; i++) {
-        if (reg_maps->address[i])
-            shader_addline(buffer, "ivec4 A%d;\n", i);
+    for (i = 0, map = reg_maps->address; map; map >>= 1, ++i)
+    {
+        if (map & 1) shader_addline(buffer, "ivec4 A%u;\n", i);
     }
 
     /* Declare texture coordinate temporaries and initialize them */
-    for (i = 0; i < This->baseShader.limits.texcoord; i++) {
-        if (reg_maps->texcoord[i]) 
-            shader_addline(buffer, "vec4 T%u = gl_TexCoord[%u];\n", i, i);
+    for (i = 0, map = reg_maps->texcoord; map; map >>= 1, ++i)
+    {
+        if (map & 1) shader_addline(buffer, "vec4 T%u = gl_TexCoord[%u];\n", i, i);
     }
 
@@ -1047,7 +1048,7 @@
 
     /* Declare temporary variables */
-    for(i = 0; i < This->baseShader.limits.temporary; i++) {
-        if (reg_maps->temporary[i])
-            shader_addline(buffer, "vec4 R%u;\n", i);
+    for (i = 0, map = reg_maps->temporary; map; map >>= 1, ++i)
+    {
+        if (map & 1) shader_addline(buffer, "vec4 R%u;\n", i);
     }
 
@@ -1055,11 +1056,7 @@
     if (reg_maps->shader_version.type == WINED3D_SHADER_TYPE_VERTEX)
     {
-        WORD map = reg_maps->input_registers;
-
-        for (i = 0; map; map >>= 1, ++i)
+        for (i = 0, map = reg_maps->input_registers; map; map >>= 1, ++i)
         {
-            if (!(map & 1)) continue;
-
-            shader_addline(buffer, "attribute vec4 attrib%i;\n", i);
+            if (map & 1) shader_addline(buffer, "attribute vec4 attrib%i;\n", i);
         }
     }
@@ -1118,20 +1115,20 @@
 /** Used for opcode modifiers - They multiply the result by the specified amount */
 static const char * const shift_glsl_tab[] = {
-    "",           /*  0 (none) */ 
-    "2.0 * ",     /*  1 (x2)   */ 
-    "4.0 * ",     /*  2 (x4)   */ 
-    "8.0 * ",     /*  3 (x8)   */ 
-    "16.0 * ",    /*  4 (x16)  */ 
-    "32.0 * ",    /*  5 (x32)  */ 
-    "",           /*  6 (x64)  */ 
-    "",           /*  7 (x128) */ 
-    "",           /*  8 (d256) */ 
-    "",           /*  9 (d128) */ 
-    "",           /* 10 (d64)  */ 
-    "",           /* 11 (d32)  */ 
-    "0.0625 * ",  /* 12 (d16)  */ 
-    "0.125 * ",   /* 13 (d8)   */ 
-    "0.25 * ",    /* 14 (d4)   */ 
-    "0.5 * "      /* 15 (d2)   */ 
+    "",           /*  0 (none) */
+    "2.0 * ",     /*  1 (x2)   */
+    "4.0 * ",     /*  2 (x4)   */
+    "8.0 * ",     /*  3 (x8)   */
+    "16.0 * ",    /*  4 (x16)  */
+    "32.0 * ",    /*  5 (x32)  */
+    "",           /*  6 (x64)  */
+    "",           /*  7 (x128) */
+    "",           /*  8 (d256) */
+    "",           /*  9 (d128) */
+    "",           /* 10 (d64)  */
+    "",           /* 11 (d32)  */
+    "0.0625 * ",  /* 12 (d16)  */
+    "0.125 * ",   /* 13 (d8)   */
+    "0.25 * ",    /* 14 (d4)   */
+    "0.5 * "      /* 15 (d2)   */
 };
 
@@ -1791,7 +1788,5 @@
 
 /*****************************************************************************
- * 
  * Begin processing individual instruction opcodes
- * 
  ****************************************************************************/
 
@@ -2278,6 +2273,6 @@
 }
 
-/** Handles transforming all WINED3DSIO_M?x? opcodes for 
-    Vertex shaders to GLSL codes */
+/* Handles transforming all WINED3DSIO_M?x? opcodes for
+   Vertex shaders to GLSL codes */
 static void shader_glsl_mnxn(const struct wined3d_shader_instruction *ins)
 {
@@ -2335,5 +2330,5 @@
 
 /**
-    The LRP instruction performs a component-wise linear interpolation 
+    The LRP instruction performs a component-wise linear interpolation
     between the second and third operands using the first operand as the
     blend factor.  Equation:  (dst = src2 + src0 * (src1 - src2))
@@ -2432,5 +2427,5 @@
  * VS 2.0 requires that specific cosine and sine constants be passed to this instruction so the hardware
  * can handle it.  But, these functions are built-in for GLSL, so we can just ignore the last 2 params.
- * 
+ *
  * dst.x = cos(src0.?)
  * dst.y = sin(src0.?)
@@ -2496,20 +2491,31 @@
     }
 
-    if(control_values) {
-        if(control_values[2] > 0) {
-            shader_addline(ins->ctx->buffer, "for (aL%u = %d; aL%u < (%d * %d + %d); aL%u += %d) {\n",
-                    shader->baseShader.cur_loop_depth, control_values[1],
-                    shader->baseShader.cur_loop_depth, control_values[0], control_values[2], control_values[1],
-                    shader->baseShader.cur_loop_depth, control_values[2]);
-        } else if(control_values[2] == 0) {
-            shader_addline(ins->ctx->buffer, "for (aL%u = %d, tmpInt%u = 0; tmpInt%u < %d; tmpInt%u++) {\n",
-                    shader->baseShader.cur_loop_depth, control_values[1], shader->baseShader.cur_loop_depth,
-                    shader->baseShader.cur_loop_depth, control_values[0],
+    if (control_values)
+    {
+        struct wined3d_shader_loop_control loop_control;
+        loop_control.count = control_values[0];
+        loop_control.start = control_values[1];
+        loop_control.step = (int)control_values[2];
+
+        if (loop_control.step > 0)
+        {
+            shader_addline(ins->ctx->buffer, "for (aL%u = %u; aL%u < (%u * %d + %u); aL%u += %d) {\n",
+                    shader->baseShader.cur_loop_depth, loop_control.start,
+                    shader->baseShader.cur_loop_depth, loop_control.count, loop_control.step, loop_control.start,
+                    shader->baseShader.cur_loop_depth, loop_control.step);
+        }
+        else if (loop_control.step < 0)
+        {
+            shader_addline(ins->ctx->buffer, "for (aL%u = %u; aL%u > (%u * %d + %u); aL%u += %d) {\n",
+                    shader->baseShader.cur_loop_depth, loop_control.start,
+                    shader->baseShader.cur_loop_depth, loop_control.count, loop_control.step, loop_control.start,
+                    shader->baseShader.cur_loop_depth, loop_control.step);
+        }
+        else
+        {
+            shader_addline(ins->ctx->buffer, "for (aL%u = %u, tmpInt%u = 0; tmpInt%u < %u; tmpInt%u++) {\n",
+                    shader->baseShader.cur_loop_depth, loop_control.start, shader->baseShader.cur_loop_depth,
+                    shader->baseShader.cur_loop_depth, loop_control.count,
                     shader->baseShader.cur_loop_depth);
-        } else {
-            shader_addline(ins->ctx->buffer, "for (aL%u = %d; aL%u > (%d * %d + %d); aL%u += %d) {\n",
-                    shader->baseShader.cur_loop_depth, control_values[1],
-                    shader->baseShader.cur_loop_depth, control_values[0], control_values[2], control_values[1],
-                    shader->baseShader.cur_loop_depth, control_values[2]);
         }
     } else {
@@ -2648,5 +2654,5 @@
  * Pixel Shader Specific Code begins here
  ********************************************/
-static void pshader_glsl_tex(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_tex(const struct wined3d_shader_instruction *ins)
 {
     IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->ctx->shader;
@@ -2751,5 +2757,5 @@
     if(!GL_SUPPORT(ARB_SHADER_TEXTURE_LOD)) {
         FIXME("texldd used, but not supported by hardware. Falling back to regular tex\n");
-        return pshader_glsl_tex(ins);
+        return shader_glsl_tex(ins);
     }
 
@@ -2774,4 +2780,5 @@
     IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
+    const struct wined3d_gl_info *gl_info = &deviceImpl->adapter->gl_info;
     glsl_sample_function_t sample_function;
     glsl_src_param_t coord_param, lod_param;
@@ -2792,5 +2799,6 @@
     shader_glsl_add_src_param(ins, &ins->src[0], WINED3DSP_WRITEMASK_3, &lod_param);
 
-    if (shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type))
+    if (!gl_info->supported[ARB_SHADER_TEXTURE_LOD]
+            && shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type))
     {
         /* The GLSL spec claims the Lod sampling functions are only supported in vertex shaders.
@@ -2802,5 +2810,5 @@
 }
 
-static void pshader_glsl_texcoord(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texcoord(const struct wined3d_shader_instruction *ins)
 {
     /* FIXME: Make this work for more than just 2D textures */
@@ -2851,5 +2859,5 @@
  * Take a 3-component dot product of the TexCoord[dstreg] and src,
  * then perform a 1D texture lookup from stage dstregnum, place into dst. */
-static void pshader_glsl_texdp3tex(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texdp3tex(const struct wined3d_shader_instruction *ins)
 {
     glsl_src_param_t src0_param;
@@ -2895,5 +2903,5 @@
 /** Process the WINED3DSIO_TEXDP3 instruction in GLSL:
  * Take a 3-component dot product of the TexCoord[dstreg] and src. */
-static void pshader_glsl_texdp3(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texdp3(const struct wined3d_shader_instruction *ins)
 {
     glsl_src_param_t src0_param;
@@ -2916,5 +2924,5 @@
 /** Process the WINED3DSIO_TEXDEPTH instruction in GLSL:
  * Calculate the depth as dst.x / dst.y   */
-static void pshader_glsl_texdepth(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texdepth(const struct wined3d_shader_instruction *ins)
 {
     glsl_dst_param_t dst_param;
@@ -2937,5 +2945,5 @@
  * depth = (tmp0.y == 0.0) ? 1.0 : tmp0.x / tmp0.y
  */
-static void pshader_glsl_texm3x2depth(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texm3x2depth(const struct wined3d_shader_instruction *ins)
 {
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
@@ -2951,5 +2959,5 @@
 /** Process the WINED3DSIO_TEXM3X2PAD instruction in GLSL
  * Calculate the 1st of a 2-row matrix multiplication. */
-static void pshader_glsl_texm3x2pad(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texm3x2pad(const struct wined3d_shader_instruction *ins)
 {
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
@@ -2964,5 +2972,5 @@
 /** Process the WINED3DSIO_TEXM3X3PAD instruction in GLSL
  * Calculate the 1st or 2nd row of a 3-row matrix multiplication. */
-static void pshader_glsl_texm3x3pad(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texm3x3pad(const struct wined3d_shader_instruction *ins)
 {
     IWineD3DPixelShaderImpl *shader = (IWineD3DPixelShaderImpl *)ins->ctx->shader;
@@ -2978,5 +2986,5 @@
 }
 
-static void pshader_glsl_texm3x2tex(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texm3x2tex(const struct wined3d_shader_instruction *ins)
 {
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
@@ -2998,5 +3006,5 @@
 /** Process the WINED3DSIO_TEXM3X3TEX instruction in GLSL
  * Perform the 3rd row of a 3x3 matrix multiply, then sample the texture using the calculated coordinates */
-static void pshader_glsl_texm3x3tex(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texm3x3tex(const struct wined3d_shader_instruction *ins)
 {
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
@@ -3022,5 +3030,5 @@
 /** Process the WINED3DSIO_TEXM3X3 instruction in GLSL
  * Perform the 3rd row of a 3x3 matrix multiply */
-static void pshader_glsl_texm3x3(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texm3x3(const struct wined3d_shader_instruction *ins)
 {
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
@@ -3040,7 +3048,7 @@
 }
 
-/** Process the WINED3DSIO_TEXM3X3SPEC instruction in GLSL 
+/* Process the WINED3DSIO_TEXM3X3SPEC instruction in GLSL
  * Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */
-static void pshader_glsl_texm3x3spec(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texm3x3spec(const struct wined3d_shader_instruction *ins)
 {
     IWineD3DPixelShaderImpl *shader = (IWineD3DPixelShaderImpl *)ins->ctx->shader;
@@ -3071,7 +3079,7 @@
 }
 
-/** Process the WINED3DSIO_TEXM3X3VSPEC instruction in GLSL 
+/* Process the WINED3DSIO_TEXM3X3VSPEC instruction in GLSL
  * Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */
-static void pshader_glsl_texm3x3vspec(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texm3x3vspec(const struct wined3d_shader_instruction *ins)
 {
     IWineD3DPixelShaderImpl *shader = (IWineD3DPixelShaderImpl *)ins->ctx->shader;
@@ -3107,5 +3115,5 @@
  * texbem is pshader <= 1.3 only, this saves a few version checks
  */
-static void pshader_glsl_texbem(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texbem(const struct wined3d_shader_instruction *ins)
 {
     IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->ctx->shader;
@@ -3166,5 +3174,5 @@
 }
 
-static void pshader_glsl_bem(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_bem(const struct wined3d_shader_instruction *ins)
 {
     glsl_src_param_t src0_param, src1_param;
@@ -3181,5 +3189,5 @@
 /** Process the WINED3DSIO_TEXREG2AR instruction in GLSL
  * Sample 2D texture at dst using the alpha & red (wx) components of src as texture coordinates */
-static void pshader_glsl_texreg2ar(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texreg2ar(const struct wined3d_shader_instruction *ins)
 {
     glsl_src_param_t src0_param;
@@ -3197,5 +3205,5 @@
 /** Process the WINED3DSIO_TEXREG2GB instruction in GLSL
  * Sample 2D texture at dst using the green & blue (yz) components of src as texture coordinates */
-static void pshader_glsl_texreg2gb(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texreg2gb(const struct wined3d_shader_instruction *ins)
 {
     glsl_src_param_t src0_param;
@@ -3213,5 +3221,5 @@
 /** Process the WINED3DSIO_TEXREG2RGB instruction in GLSL
  * Sample texture at dst using the rgb (xyz) components of src as texture coordinates */
-static void pshader_glsl_texreg2rgb(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texreg2rgb(const struct wined3d_shader_instruction *ins)
 {
     glsl_src_param_t src0_param;
@@ -3230,5 +3238,5 @@
 /** Process the WINED3DSIO_TEXKILL instruction in GLSL.
  * If any of the first 3 components are < 0, discard this pixel */
-static void pshader_glsl_texkill(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_texkill(const struct wined3d_shader_instruction *ins)
 {
     glsl_dst_param_t dst_param;
@@ -3251,5 +3259,5 @@
 /** Process the WINED3DSIO_DP2ADD instruction in GLSL.
  * dst = dot2(src0, src1) + src2 */
-static void pshader_glsl_dp2add(const struct wined3d_shader_instruction *ins)
+static void shader_glsl_dp2add(const struct wined3d_shader_instruction *ins)
 {
     glsl_src_param_t src0_param;
@@ -3275,5 +3283,5 @@
 }
 
-static void pshader_glsl_input_pack(IWineD3DPixelShader *iface, struct wined3d_shader_buffer *buffer,
+static void shader_glsl_input_pack(IWineD3DPixelShader *iface, struct wined3d_shader_buffer *buffer,
         const struct wined3d_shader_signature_element *input_signature, const struct shader_reg_maps *reg_maps,
         enum vertexprocessing_mode vertexprocessing)
@@ -3740,5 +3748,5 @@
     if (reg_maps->shader_version.major >= 3 && args->vp_mode != vertexshader)
     {
-        pshader_glsl_input_pack((IWineD3DPixelShader *) This, buffer, This->input_signature, reg_maps, args->vp_mode);
+        shader_glsl_input_pack((IWineD3DPixelShader *) This, buffer, This->input_signature, reg_maps, args->vp_mode);
     }
 
@@ -3883,8 +3891,14 @@
     GLhandleARB ret;
 
-    if(!shader->backend_priv) {
-        shader->backend_priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data));
-    }
-    shader_data = shader->backend_priv;
+    if (!shader->baseShader.backend_data)
+    {
+        shader->baseShader.backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data));
+        if (!shader->baseShader.backend_data)
+        {
+            ERR("Failed to allocate backend data.\n");
+            return 0;
+        }
+    }
+    shader_data = shader->baseShader.backend_data;
 
     /* Usually we have very few GL shaders for each d3d shader(just 1 or maybe 2),
@@ -3952,8 +3966,14 @@
     GLhandleARB ret;
 
-    if(!shader->backend_priv) {
-        shader->backend_priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data));
-    }
-    shader_data = shader->backend_priv;
+    if (!shader->baseShader.backend_data)
+    {
+        shader->baseShader.backend_data = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data));
+        if (!shader->baseShader.backend_data)
+        {
+            ERR("Failed to allocate backend data.\n");
+            return 0;
+        }
+    }
+    shader_data = shader->baseShader.backend_data;
 
     /* Usually we have very few GL shaders for each d3d shader(just 1 or maybe 2),
@@ -4354,9 +4374,9 @@
         struct glsl_pshader_private *shader_data;
         ps = (IWineD3DPixelShaderImpl *) This;
-        shader_data = ps->backend_priv;
+        shader_data = ps->baseShader.backend_data;
         if(!shader_data || shader_data->num_gl_shaders == 0)
         {
             HeapFree(GetProcessHeap(), 0, shader_data);
-            ps->backend_priv = NULL;
+            ps->baseShader.backend_data = NULL;
             return;
         }
@@ -4374,9 +4394,9 @@
         struct glsl_vshader_private *shader_data;
         vs = (IWineD3DVertexShaderImpl *) This;
-        shader_data = vs->backend_priv;
+        shader_data = vs->baseShader.backend_data;
         if(!shader_data || shader_data->num_gl_shaders == 0)
         {
             HeapFree(GetProcessHeap(), 0, shader_data);
-            vs->backend_priv = NULL;
+            vs->baseShader.backend_data = NULL;
             return;
         }
@@ -4414,5 +4434,5 @@
     if(pshader) {
         UINT i;
-        struct glsl_pshader_private *shader_data = ps->backend_priv;
+        struct glsl_pshader_private *shader_data = ps->baseShader.backend_data;
 
         ENTER_GL();
@@ -4425,8 +4445,8 @@
         HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders);
         HeapFree(GetProcessHeap(), 0, shader_data);
-        ps->backend_priv = NULL;
+        ps->baseShader.backend_data = NULL;
     } else {
         UINT i;
-        struct glsl_vshader_private *shader_data = vs->backend_priv;
+        struct glsl_vshader_private *shader_data = vs->baseShader.backend_data;
 
         ENTER_GL();
@@ -4439,5 +4459,5 @@
         HeapFree(GetProcessHeap(), 0, shader_data->gl_shaders);
         HeapFree(GetProcessHeap(), 0, shader_data);
-        vs->backend_priv = NULL;
+        vs->baseShader.backend_data = NULL;
     }
 }
@@ -4580,6 +4600,6 @@
 {
     /* Nvidia Geforce6/7 or Ati R4xx/R5xx cards with GLSL support, support VS 3.0 but older Nvidia/Ati
-     * models with GLSL support only support 2.0. In case of nvidia we can detect VS 2.0 support using
-     * vs_nv_version which is based on NV_vertex_program.
+     * models with GLSL support only support 2.0. In case of nvidia we can detect VS 2.0 support based
+     * on the version of NV_vertex_program.
      * For Ati cards there's no way using glsl (it abstracts the lowlevel info away) and also not
      * using ARB_vertex_program. It is safe to assume that when a card supports pixel shader 2.0 it
@@ -4587,5 +4607,6 @@
      * of native instructions, so use that here. For more info see the pixel shader versioning code below.
      */
-    if((GLINFO_LOCATION.vs_nv_version == VS_VERSION_20) || (GLINFO_LOCATION.ps_arb_max_instructions <= 512))
+    if ((gl_info->supported[NV_VERTEX_PROGRAM2] && !gl_info->supported[NV_VERTEX_PROGRAM3])
+            || gl_info->ps_arb_max_instructions <= 512)
         pCaps->VertexShaderVersion = WINED3DVS_VERSION(2,0);
     else
@@ -4605,5 +4626,6 @@
      * NOTE: ps3.0 hardware requires 512 or more instructions but ati and nvidia offer 'enough' (1024 vs 4096) on their most basic ps3.0 hardware.
      */
-    if((GLINFO_LOCATION.ps_nv_version == PS_VERSION_20) || (GLINFO_LOCATION.ps_arb_max_instructions <= 512))
+    if ((gl_info->supported[NV_FRAGMENT_PROGRAM] && !gl_info->supported[NV_FRAGMENT_PROGRAM2])
+            || (gl_info->ps_arb_max_instructions <= 512))
         pCaps->PixelShaderVersion = WINED3DPS_VERSION(2,0);
     else
@@ -4653,5 +4675,5 @@
     /* WINED3DSIH_ABS           */ shader_glsl_map2gl,
     /* WINED3DSIH_ADD           */ shader_glsl_arith,
-    /* WINED3DSIH_BEM           */ pshader_glsl_bem,
+    /* WINED3DSIH_BEM           */ shader_glsl_bem,
     /* WINED3DSIH_BREAK         */ shader_glsl_break,
     /* WINED3DSIH_BREAKC        */ shader_glsl_breakc,
@@ -4666,5 +4688,5 @@
     /* WINED3DSIH_DEFB          */ NULL,
     /* WINED3DSIH_DEFI          */ NULL,
-    /* WINED3DSIH_DP2ADD        */ pshader_glsl_dp2add,
+    /* WINED3DSIH_DP2ADD        */ shader_glsl_dp2add,
     /* WINED3DSIH_DP3           */ shader_glsl_dot,
     /* WINED3DSIH_DP4           */ shader_glsl_dot,
@@ -4712,26 +4734,26 @@
     /* WINED3DSIH_SLT           */ shader_glsl_compare,
     /* WINED3DSIH_SUB           */ shader_glsl_arith,
-    /* WINED3DSIH_TEX           */ pshader_glsl_tex,
-    /* WINED3DSIH_TEXBEM        */ pshader_glsl_texbem,
-    /* WINED3DSIH_TEXBEML       */ pshader_glsl_texbem,
-    /* WINED3DSIH_TEXCOORD      */ pshader_glsl_texcoord,
-    /* WINED3DSIH_TEXDEPTH      */ pshader_glsl_texdepth,
-    /* WINED3DSIH_TEXDP3        */ pshader_glsl_texdp3,
-    /* WINED3DSIH_TEXDP3TEX     */ pshader_glsl_texdp3tex,
-    /* WINED3DSIH_TEXKILL       */ pshader_glsl_texkill,
+    /* WINED3DSIH_TEX           */ shader_glsl_tex,
+    /* WINED3DSIH_TEXBEM        */ shader_glsl_texbem,
+    /* WINED3DSIH_TEXBEML       */ shader_glsl_texbem,
+    /* WINED3DSIH_TEXCOORD      */ shader_glsl_texcoord,
+    /* WINED3DSIH_TEXDEPTH      */ shader_glsl_texdepth,
+    /* WINED3DSIH_TEXDP3        */ shader_glsl_texdp3,
+    /* WINED3DSIH_TEXDP3TEX     */ shader_glsl_texdp3tex,
+    /* WINED3DSIH_TEXKILL       */ shader_glsl_texkill,
     /* WINED3DSIH_TEXLDD        */ shader_glsl_texldd,
     /* WINED3DSIH_TEXLDL        */ shader_glsl_texldl,
-    /* WINED3DSIH_TEXM3x2DEPTH  */ pshader_glsl_texm3x2depth,
-    /* WINED3DSIH_TEXM3x2PAD    */ pshader_glsl_texm3x2pad,
-    /* WINED3DSIH_TEXM3x2TEX    */ pshader_glsl_texm3x2tex,
-    /* WINED3DSIH_TEXM3x3       */ pshader_glsl_texm3x3,
+    /* WINED3DSIH_TEXM3x2DEPTH  */ shader_glsl_texm3x2depth,
+    /* WINED3DSIH_TEXM3x2PAD    */ shader_glsl_texm3x2pad,
+    /* WINED3DSIH_TEXM3x2TEX    */ shader_glsl_texm3x2tex,
+    /* WINED3DSIH_TEXM3x3       */ shader_glsl_texm3x3,
     /* WINED3DSIH_TEXM3x3DIFF   */ NULL,
-    /* WINED3DSIH_TEXM3x3PAD    */ pshader_glsl_texm3x3pad,
-    /* WINED3DSIH_TEXM3x3SPEC   */ pshader_glsl_texm3x3spec,
-    /* WINED3DSIH_TEXM3x3TEX    */ pshader_glsl_texm3x3tex,
-    /* WINED3DSIH_TEXM3x3VSPEC  */ pshader_glsl_texm3x3vspec,
-    /* WINED3DSIH_TEXREG2AR     */ pshader_glsl_texreg2ar,
-    /* WINED3DSIH_TEXREG2GB     */ pshader_glsl_texreg2gb,
-    /* WINED3DSIH_TEXREG2RGB    */ pshader_glsl_texreg2rgb,
+    /* WINED3DSIH_TEXM3x3PAD    */ shader_glsl_texm3x3pad,
+    /* WINED3DSIH_TEXM3x3SPEC   */ shader_glsl_texm3x3spec,
+    /* WINED3DSIH_TEXM3x3TEX    */ shader_glsl_texm3x3tex,
+    /* WINED3DSIH_TEXM3x3VSPEC  */ shader_glsl_texm3x3vspec,
+    /* WINED3DSIH_TEXREG2AR     */ shader_glsl_texreg2ar,
+    /* WINED3DSIH_TEXREG2GB     */ shader_glsl_texreg2gb,
+    /* WINED3DSIH_TEXREG2RGB    */ shader_glsl_texreg2rgb,
 };
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/pixelshader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/pixelshader.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/pixelshader.c	(revision 23571)
@@ -8,4 +8,5 @@
  * Copyright 2006 Ivan Gyurdiev
  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -81,4 +82,5 @@
     {
         shader_cleanup((IWineD3DBaseShader *)iface);
+        This->baseShader.parent_ops->wined3d_object_destroyed(This->baseShader.parent);
         HeapFree(GetProcessHeap(), 0, This);
     }
@@ -94,5 +96,5 @@
     IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)iface;
 
-    *parent = This->parent;
+    *parent = This->baseShader.parent;
     IUnknown_AddRef(*parent);
     TRACE("(%p) : returning %p\n", This, *parent);
@@ -218,16 +220,17 @@
 }
 
-static HRESULT WINAPI IWineD3DPixelShaderImpl_SetFunction(IWineD3DPixelShader *iface,
-        const DWORD *pFunction, const struct wined3d_shader_signature *output_signature)
+static HRESULT pixelshader_set_function(IWineD3DPixelShaderImpl *shader,
+        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature)
 {
-    IWineD3DPixelShaderImpl *This =(IWineD3DPixelShaderImpl *)iface;
+    IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)shader->baseShader.device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     unsigned int i, highest_reg_used = 0, num_regs_used = 0;
-    shader_reg_maps *reg_maps = &This->baseShader.reg_maps;
+    shader_reg_maps *reg_maps = &shader->baseShader.reg_maps;
     const struct wined3d_shader_frontend *fe;
     HRESULT hr;
 
-    TRACE("(%p) : pFunction %p\n", iface, pFunction);
-
-    fe = shader_select_frontend(*pFunction);
+    TRACE("shader %p, byte_code %p, output_signature %p.\n", shader, byte_code, output_signature);
+
+    fe = shader_select_frontend(*byte_code);
     if (!fe)
     {
@@ -235,7 +238,7 @@
         return WINED3DERR_INVALIDCALL;
     }
-    This->baseShader.frontend = fe;
-    This->baseShader.frontend_data = fe->shader_init(pFunction, output_signature);
-    if (!This->baseShader.frontend_data)
+    shader->baseShader.frontend = fe;
+    shader->baseShader.frontend_data = fe->shader_init(byte_code, output_signature);
+    if (!shader->baseShader.frontend_data)
     {
         FIXME("Failed to initialize frontend.\n");
@@ -244,22 +247,22 @@
 
     /* First pass: trace shader */
-    if (TRACE_ON(d3d_shader)) shader_trace_init(fe, This->baseShader.frontend_data, pFunction);
+    if (TRACE_ON(d3d_shader)) shader_trace_init(fe, shader->baseShader.frontend_data, byte_code);
 
     /* Initialize immediate constant lists */
-    list_init(&This->baseShader.constantsF);
-    list_init(&This->baseShader.constantsB);
-    list_init(&This->baseShader.constantsI);
+    list_init(&shader->baseShader.constantsF);
+    list_init(&shader->baseShader.constantsB);
+    list_init(&shader->baseShader.constantsI);
 
     /* Second pass: figure out which registers are used, what the semantics are, etc.. */
-    hr = shader_get_registers_used((IWineD3DBaseShader *)This, fe,
-            reg_maps, NULL, This->input_signature, NULL,
-            pFunction, GL_LIMITS(pshader_constantsF));
+    hr = shader_get_registers_used((IWineD3DBaseShader *)shader, fe,
+            reg_maps, NULL, shader->input_signature, NULL,
+            byte_code, gl_info->max_pshader_constantsF);
     if (FAILED(hr)) return hr;
 
-    pshader_set_limits(This);
+    pshader_set_limits(shader);
 
     for (i = 0; i < MAX_REG_INPUT; ++i)
     {
-        if (This->input_reg_used[i])
+        if (shader->input_reg_used[i])
         {
             ++num_regs_used;
@@ -270,8 +273,8 @@
     /* Don't do any register mapping magic if it is not needed, or if we can't
      * achieve anything anyway */
-    if (highest_reg_used < (GL_LIMITS(glsl_varyings) / 4)
-            || num_regs_used > (GL_LIMITS(glsl_varyings) / 4))
-    {
-        if (num_regs_used > (GL_LIMITS(glsl_varyings) / 4))
+    if (highest_reg_used < (gl_info->max_glsl_varyings / 4)
+            || num_regs_used > (gl_info->max_glsl_varyings / 4))
+    {
+        if (num_regs_used > (gl_info->max_glsl_varyings / 4))
         {
             /* This happens with relative addressing. The input mapper function
@@ -283,26 +286,26 @@
         for (i = 0; i < MAX_REG_INPUT; ++i)
         {
-            This->input_reg_map[i] = i;
-        }
-
-        This->declared_in_count = highest_reg_used + 1;
+            shader->input_reg_map[i] = i;
+        }
+
+        shader->declared_in_count = highest_reg_used + 1;
     }
     else
     {
-        This->declared_in_count = 0;
+        shader->declared_in_count = 0;
         for (i = 0; i < MAX_REG_INPUT; ++i)
         {
-            if (This->input_reg_used[i]) This->input_reg_map[i] = This->declared_in_count++;
-            else This->input_reg_map[i] = ~0U;
-        }
-    }
-
-    This->baseShader.load_local_constsF = FALSE;
-
-    TRACE("(%p) : Copying the function\n", This);
-
-    This->baseShader.function = HeapAlloc(GetProcessHeap(), 0, This->baseShader.functionLength);
-    if (!This->baseShader.function) return E_OUTOFMEMORY;
-    memcpy(This->baseShader.function, pFunction, This->baseShader.functionLength);
+            if (shader->input_reg_used[i]) shader->input_reg_map[i] = shader->declared_in_count++;
+            else shader->input_reg_map[i] = ~0U;
+        }
+    }
+
+    shader->baseShader.load_local_constsF = FALSE;
+
+    TRACE("(%p) : Copying byte code.\n", shader);
+
+    shader->baseShader.function = HeapAlloc(GetProcessHeap(), 0, shader->baseShader.functionLength);
+    if (!shader->baseShader.function) return E_OUTOFMEMORY;
+    memcpy(shader->baseShader.function, byte_code, shader->baseShader.functionLength);
 
     return WINED3D_OK;
@@ -353,5 +356,5 @@
 }
 
-const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl =
+static const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl =
 {
     /*** IUnknown methods ***/
@@ -362,8 +365,7 @@
     IWineD3DPixelShaderImpl_GetParent,
     /*** IWineD3DBaseShader methods ***/
-    IWineD3DPixelShaderImpl_SetFunction,
-    /*** IWineD3DPixelShader methods ***/
     IWineD3DPixelShaderImpl_GetDevice,
     IWineD3DPixelShaderImpl_GetFunction
+    /*** IWineD3DPixelShader methods ***/
 };
 
@@ -431,2 +433,24 @@
     }
 }
+
+HRESULT pixelshader_init(IWineD3DPixelShaderImpl *shader, IWineD3DDeviceImpl *device,
+        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+{
+    HRESULT hr;
+
+    if (!byte_code) return WINED3DERR_INVALIDCALL;
+
+    shader->lpVtbl = &IWineD3DPixelShader_Vtbl;
+    shader_init(&shader->baseShader, device, parent, parent_ops);
+
+    hr = pixelshader_set_function(shader, byte_code, output_signature);
+    if (FAILED(hr))
+    {
+        WARN("Failed to set function, hr %#x.\n", hr);
+        shader_cleanup((IWineD3DBaseShader *)shader);
+        return hr;
+    }
+
+    return WINED3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/query.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/query.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/query.c	(revision 23571)
@@ -356,4 +356,12 @@
     if (!pData || !dwSize) return S_OK;
 
+    if (!query->context)
+    {
+        ERR("Query not started, returning TRUE.\n");
+        *data = TRUE;
+
+        return S_OK;
+    }
+
     if (query->context->tid != GetCurrentThreadId())
     {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c	(revision 23571)
@@ -6,4 +6,5 @@
  * Copyright 2004 Christian Costa
  * Copyright 2005 Oliver Stieber
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -38,5 +39,5 @@
 HRESULT resource_init(IWineD3DResource *iface, WINED3DRESOURCETYPE resource_type,
         IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct GlPixelFormatDesc *format_desc,
-        WINED3DPOOL pool, IUnknown *parent)
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
 {
     struct IWineD3DResourceClass *resource = &((IWineD3DResourceImpl *)iface)->resource;
@@ -51,4 +52,5 @@
     resource->size = size;
     resource->priority = 0;
+    resource->parent_ops = parent_ops;
     list_init(&resource->privateData);
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm4.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm4.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm4.c	(revision 23571)
@@ -63,4 +63,6 @@
     WINED3D_SM4_OP_EXP      = 0x19,
     WINED3D_SM4_OP_LOG      = 0x2f,
+    WINED3D_SM4_OP_MIN      = 0x33,
+    WINED3D_SM4_OP_MAX      = 0x34,
     WINED3D_SM4_OP_MOV      = 0x36,
     WINED3D_SM4_OP_MUL      = 0x38,
@@ -114,4 +116,6 @@
     {WINED3D_SM4_OP_EXP,    WINED3DSIH_EXP,         1,  1},
     {WINED3D_SM4_OP_LOG,    WINED3DSIH_LOG,         1,  1},
+    {WINED3D_SM4_OP_MIN,    WINED3DSIH_MIN,         1,  2},
+    {WINED3D_SM4_OP_MAX,    WINED3DSIH_MAX,         1,  2},
     {WINED3D_SM4_OP_MOV,    WINED3DSIH_MOV,         1,  1},
     {WINED3D_SM4_OP_MUL,    WINED3DSIH_MUL,         1,  2},
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/state.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/state.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/state.c	(revision 23571)
@@ -9,4 +9,5 @@
  * Copyright 2006 Henri Verbeet
  * Copyright 2006-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -44,5 +45,5 @@
 WINE_DECLARE_DEBUG_CHANNEL(d3d_shader);
 
-#define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
+#define GLINFO_LOCATION (*context->gl_info)
 
 /* GL locking for state handlers is done by the caller. */
@@ -66,9 +67,5 @@
 static void state_undefined(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    /* Print a WARN, this allows the stateblock code to loop over all states to generate a display
-     * list without causing confusing terminal output. Deliberately no special debug name here
-     * because its undefined.
-     */
-    WARN("undefined state %d\n", state);
+    ERR("Undefined state.\n");
 }
 
@@ -578,14 +575,16 @@
         enable  = stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
         disable = ~stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
-        if(GL_SUPPORT(NV_DEPTH_CLAMP)) {
-            glDisable(GL_DEPTH_CLAMP_NV);
-            checkGLcall("glDisable(GL_DEPTH_CLAMP_NV)");
+        if (GL_SUPPORT(ARB_DEPTH_CLAMP))
+        {
+            glDisable(GL_DEPTH_CLAMP);
+            checkGLcall("glDisable(GL_DEPTH_CLAMP)");
         }
     } else {
         disable = 0xffffffff;
         enable  = 0x00;
-        if(GL_SUPPORT(NV_DEPTH_CLAMP)) {
-            glEnable(GL_DEPTH_CLAMP_NV);
-            checkGLcall("glEnable(GL_DEPTH_CLAMP_NV)");
+        if (GL_SUPPORT(ARB_DEPTH_CLAMP))
+        {
+            glEnable(GL_DEPTH_CLAMP);
+            checkGLcall("glEnable(GL_DEPTH_CLAMP)");
         }
     }
@@ -785,6 +784,7 @@
 }
 
-static void
-renderstate_stencil_twosided(IWineD3DStateBlockImpl *stateblock, GLint face, GLint func, GLint ref, GLuint mask, GLint stencilFail, GLint depthFail, GLint stencilPass ) {
+static void renderstate_stencil_twosided(struct wined3d_context *context, GLint face,
+        GLint func, GLint ref, GLuint mask, GLint stencilFail, GLint depthFail, GLint stencilPass)
+{
     glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT);
     checkGLcall("glEnable(GL_STENCIL_TEST_TWO_SIDE_EXT)");
@@ -852,8 +852,8 @@
              * to set it back
              */
-            renderstate_stencil_twosided(stateblock, GL_BACK, func_ccw, ref, mask,
-                                         stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
-            renderstate_stencil_twosided(stateblock, GL_FRONT, func, ref, mask,
-                                         stencilFail, depthFail, stencilPass);
+            renderstate_stencil_twosided(context, GL_BACK,
+                    func_ccw, ref, mask, stencilFail_ccw, depthFail_ccw, stencilPass_ccw);
+            renderstate_stencil_twosided(context, GL_FRONT,
+                    func, ref, mask, stencilFail, depthFail, stencilPass);
         } else if(GL_SUPPORT(ATI_SEPARATE_STENCIL)) {
             GL_EXTCALL(glStencilFuncSeparateATI(func, func_ccw, ref, mask));
@@ -1191,6 +1191,4 @@
     IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
     GLenum Parm = 0;
-    const struct wined3d_stream_info_element *diffuse = &device->strided_streams.elements[WINED3D_FFP_DIFFUSE];
-    BOOL isDiffuseSupplied;
 
     /* Depends on the decoded vertex declaration to read the existence of diffuse data.
@@ -1202,8 +1200,8 @@
     }
 
-    isDiffuseSupplied = diffuse->data || diffuse->buffer_object;
-
     context->num_untracked_materials = 0;
-    if (isDiffuseSupplied && stateblock->renderState[WINED3DRS_COLORVERTEX]) {
+    if ((device->strided_streams.use_map & (1 << WINED3D_FFP_DIFFUSE))
+            && stateblock->renderState[WINED3DRS_COLORVERTEX])
+    {
         TRACE("diff %d, amb %d, emis %d, spec %d\n",
               stateblock->renderState[WINED3DRS_DIFFUSEMATERIALSOURCE],
@@ -1360,6 +1358,5 @@
      */
     if (stateblock->renderState[WINED3DRS_NORMALIZENORMALS]
-            && (stateblock->wineD3DDevice->strided_streams.elements[WINED3D_FFP_NORMAL].data
-            || stateblock->wineD3DDevice->strided_streams.elements[WINED3D_FFP_NORMAL].buffer_object))
+            && (stateblock->wineD3DDevice->strided_streams.use_map & (1 << WINED3D_FFP_NORMAL)))
     {
         glEnable(GL_NORMALIZE);
@@ -1504,4 +1501,9 @@
 }
 
+static void state_debug_monitor(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
+{
+    WARN("token: %#x\n", stateblock->renderState[WINED3DRS_DEBUGMONITORTOKEN]);
+}
+
 static void state_colorwrite(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
@@ -1852,4 +1854,12 @@
 }
 
+static void state_swvp(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
+{
+    if (stateblock->renderState[WINED3DRS_SOFTWAREVERTEXPROCESSING])
+    {
+        FIXME("Software vertex processing not implemented.\n");
+    }
+}
+
 /* Set texture operations up - The following avoids lots of ifdefs in this routine!*/
 #if defined (GL_VERSION_1_3)
@@ -1900,5 +1910,6 @@
 
 /* Setup the texture operations texture stage states */
-static void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
+static void set_tex_op(const struct wined3d_context *context, IWineD3DDevice *iface,
+        BOOL isAlpha, int Stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3)
 {
     GLenum src1, src2, src3;
@@ -1911,5 +1922,4 @@
     BOOL Handled = FALSE;
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    IWineD3DStateBlockImpl *stateblock = This->stateBlock; /* for GLINFO_LOCATION */
 
     TRACE("Alpha?(%d), Stage:%d Op(%s), a1(%d), a2(%d), a3(%d)\n", isAlpha, Stage, debug_d3dtop(op), arg1, arg2, arg3);
@@ -2977,5 +2987,5 @@
     }
 
-    set_tex_op((IWineD3DDevice *)stateblock->wineD3DDevice, FALSE, stage,
+    set_tex_op(context, (IWineD3DDevice *)stateblock->wineD3DDevice, FALSE, stage,
                 stateblock->textureState[stage][WINED3DTSS_COLOROP],
                 stateblock->textureState[stage][WINED3DTSS_COLORARG1],
@@ -3079,5 +3089,5 @@
                          stateblock->textureState[stage][WINED3DTSS_RESULTARG]);
     } else {
-        set_tex_op((IWineD3DDevice *)stateblock->wineD3DDevice, TRUE, stage,
+        set_tex_op(context, (IWineD3DDevice *)stateblock->wineD3DDevice, TRUE, stage,
                     op, arg1, arg2, arg0);
     }
@@ -3110,5 +3120,5 @@
     set_texture_matrix(&stateblock->transforms[WINED3DTS_TEXTURE0 + texUnit].u.m[0][0],
             stateblock->textureState[texUnit][WINED3DTSS_TEXTURETRANSFORMFLAGS], generated, context->last_was_rhw,
-            stateblock->wineD3DDevice->strided_streams.elements[WINED3D_FFP_TEXCOORD0 + coordIdx].stride
+            stateblock->wineD3DDevice->strided_streams.use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx))
             ? stateblock->wineD3DDevice->strided_streams.elements[WINED3D_FFP_TEXCOORD0 + coordIdx].format_desc->format
             : WINED3DFMT_UNKNOWN,
@@ -3130,5 +3140,6 @@
 }
 
-static void unloadTexCoords(IWineD3DStateBlockImpl *stateblock) {
+static void unloadTexCoords(const struct wined3d_context *context)
+{
     unsigned int texture_idx;
 
@@ -3139,5 +3150,6 @@
 }
 
-static void loadTexCoords(IWineD3DStateBlockImpl *stateblock, const struct wined3d_stream_info *si, GLuint *curVBO)
+static void loadTexCoords(const struct wined3d_context *context, IWineD3DStateBlockImpl *stateblock,
+        const struct wined3d_stream_info *si, GLuint *curVBO)
 {
     const UINT *offset = stateblock->streamOffset;
@@ -3147,12 +3159,12 @@
     for (textureNo = 0; textureNo < GL_LIMITS(texture_stages); ++textureNo) {
         int coordIdx = stateblock->textureState[textureNo][WINED3DTSS_TEXCOORDINDEX];
-        const struct wined3d_stream_info_element *e;
 
         mapped_stage = stateblock->wineD3DDevice->texUnitMap[textureNo];
         if (mapped_stage == WINED3D_UNMAPPED_STAGE) continue;
 
-        e = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx];
-        if (coordIdx < MAX_TEXTURES && (e->data || e->buffer_object))
+        if (coordIdx < MAX_TEXTURES && (si->use_map & (1 << (WINED3D_FFP_TEXCOORD0 + coordIdx))))
         {
+            const struct wined3d_stream_info_element *e = &si->elements[WINED3D_FFP_TEXCOORD0 + coordIdx];
+
             TRACE("Setting up texture %u, idx %d, cordindx %u, data %p\n",
                     textureNo, mapped_stage, coordIdx, e->data);
@@ -3355,6 +3367,6 @@
         GLuint curVBO = GL_SUPPORT(ARB_VERTEX_BUFFER_OBJECT) ? ~0U : 0;
 
-        unloadTexCoords(stateblock);
-        loadTexCoords(stateblock, &stateblock->wineD3DDevice->strided_streams, &curVBO);
+        unloadTexCoords(context);
+        loadTexCoords(context, stateblock, &stateblock->wineD3DDevice->strided_streams, &curVBO);
     }
 }
@@ -3379,6 +3391,7 @@
     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
 
-    if(stateblock->pixelShader && stage != 0 &&
-       ((IWineD3DPixelShaderImpl *) stateblock->pixelShader)->baseShader.reg_maps.luminanceparams[stage]) {
+    if (stateblock->pixelShader && stage != 0
+            && (((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.reg_maps.luminanceparams & (1 << stage)))
+    {
         /* The pixel shader has to know the luminance scale. Do a constants update if it
          * isn't scheduled anyway
@@ -3540,6 +3553,7 @@
 {
     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
-    if(stateblock->pixelShader && stage != 0 &&
-       ((IWineD3DPixelShaderImpl *) stateblock->pixelShader)->baseShader.reg_maps.bumpmat[stage]) {
+    if (stateblock->pixelShader && stage != 0
+            && (((IWineD3DPixelShaderImpl *)stateblock->pixelShader)->baseShader.reg_maps.bumpmat & (1 << stage)))
+    {
         /* The pixel shader has to know the bump env matrix. Do a constants update if it isn't scheduled
          * anyway
@@ -3842,6 +3856,7 @@
 
         /* Window Coord 0 is the middle of the first pixel, so translate by 1/2 pixels */
-        glTranslatef(0.5f, 0.5f, 0.0f);
-        checkGLcall("glTranslatef(0.5f, 0.5f, 0.0f)");
+        glTranslatef(63.0f / 128.0f, 63.0f / 128.0f, 0.0f);
+        checkGLcall("glTranslatef(63.0f / 128.0f, 63.0f / 128.0f, 0.0f)");
+
         /* D3D texture coordinates are flipped compared to OpenGL ones, so
          * render everything upside down when rendering offscreen. */
@@ -3889,14 +3904,21 @@
          */
 
+        /* Translate by slightly less than a half pixel to force a top-left
+         * filling convention. We want the difference to be large enough that
+         * it doesn't get lost due to rounding inside the driver, but small
+         * enough to prevent it from interfering with any anti-aliasing. */
+        GLfloat xoffset = (63.0f / 64.0f) / stateblock->viewport.Width;
+        GLfloat yoffset = -(63.0f / 64.0f) / stateblock->viewport.Height;
+
         if (context->render_offscreen)
         {
             /* D3D texture coordinates are flipped compared to OpenGL ones, so
              * render everything upside down when rendering offscreen. */
-            glTranslatef(1.0f / stateblock->viewport.Width, 1.0f / stateblock->viewport.Height, -1.0f);
-            checkGLcall("glTranslatef(1.0f / width, 1.0f / height, -1.0f)");
+            glTranslatef(xoffset, -yoffset, -1.0f);
+            checkGLcall("glTranslatef(xoffset, -yoffset, -1.0f)");
             glScalef(1.0f, -1.0f, 2.0f);
         } else {
-            glTranslatef(1.0f / stateblock->viewport.Width, -1.0f / stateblock->viewport.Height, -1.0f);
-            checkGLcall("glTranslatef(1.0f / width, -1.0f / height, -1.0f)");
+            glTranslatef(xoffset, yoffset, -1.0f);
+            checkGLcall("glTranslatef(xoffset, yoffset, -1.0f)");
             glScalef(1.0f, 1.0f, 2.0f);
         }
@@ -3912,5 +3934,6 @@
  * TODO: Only load / unload arrays if we have to.
  */
-static inline void unloadVertexData(IWineD3DStateBlockImpl *stateblock) {
+static inline void unloadVertexData(const struct wined3d_context *context)
+{
     glDisableClientState(GL_VERTEX_ARRAY);
     glDisableClientState(GL_NORMAL_ARRAY);
@@ -3922,5 +3945,5 @@
         glDisableClientState(GL_WEIGHT_ARRAY_ARB);
     }
-    unloadTexCoords(stateblock);
+    unloadTexCoords(context);
 }
 
@@ -4056,5 +4079,5 @@
                     GL_EXTCALL(glVertexAttrib4NubvARB(i, ptr));
                     break;
-                case WINED3DFMT_A8R8G8B8:
+                case WINED3DFMT_B8G8R8A8_UNORM:
                     if (GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA))
                     {
@@ -4127,5 +4150,6 @@
 
 /* Used from 2 different functions, and too big to justify making it inlined */
-static void loadVertexData(IWineD3DStateBlockImpl *stateblock, const struct wined3d_stream_info *si)
+static void loadVertexData(const struct wined3d_context *context, IWineD3DStateBlockImpl *stateblock,
+        const struct wined3d_stream_info *si)
 {
     const UINT *offset = stateblock->streamOffset;
@@ -4139,9 +4163,9 @@
 
     /* Blend Data ---------------------------------------------- */
-    e = &si->elements[WINED3D_FFP_BLENDWEIGHT];
-    if (e->data || e->buffer_object
-            || si->elements[WINED3D_FFP_BLENDINDICES].data
-            || si->elements[WINED3D_FFP_BLENDINDICES].buffer_object)
+    if ((si->use_map & (1 << WINED3D_FFP_BLENDWEIGHT))
+            || si->use_map & (1 << WINED3D_FFP_BLENDINDICES))
     {
+        e = &si->elements[WINED3D_FFP_BLENDWEIGHT];
+
         if (GL_SUPPORT(ARB_VERTEX_BLEND)) {
             TRACE("Blend %d %p %d\n", e->format_desc->component_count,
@@ -4170,6 +4194,5 @@
             checkGLcall("glWeightPointerARB");
 
-            if (si->elements[WINED3D_FFP_BLENDINDICES].data
-                    || (si->elements[WINED3D_FFP_BLENDINDICES].buffer_object))
+            if (si->use_map & (1 << WINED3D_FFP_BLENDINDICES))
             {
                 static BOOL warned;
@@ -4195,6 +4218,5 @@
 
     /* Point Size ----------------------------------------------*/
-    e = &si->elements[WINED3D_FFP_PSIZE];
-    if (e->data || e->buffer_object)
+    if (si->use_map & (1 << WINED3D_FFP_PSIZE))
     {
         /* no such functionality in the fixed function GL pipeline */
@@ -4204,9 +4226,9 @@
 
     /* Vertex Pointers -----------------------------------------*/
-    e = &si->elements[WINED3D_FFP_POSITION];
-    if (e->data || e->buffer_object)
+    if (si->use_map & (1 << WINED3D_FFP_POSITION))
     {
         VTRACE(("glVertexPointer(%d, GL_FLOAT, %d, %p)\n", e->stride, e->size, e->data));
 
+        e = &si->elements[WINED3D_FFP_POSITION];
         if (curVBO != e->buffer_object)
         {
@@ -4238,8 +4260,9 @@
 
     /* Normals -------------------------------------------------*/
-    e = &si->elements[WINED3D_FFP_NORMAL];
-    if (e->data || e->buffer_object)
+    if (si->use_map & (1 << WINED3D_FFP_NORMAL))
     {
         VTRACE(("glNormalPointer(GL_FLOAT, %d, %p)\n", e->stride, e->data));
+
+        e = &si->elements[WINED3D_FFP_NORMAL];
         if (curVBO != e->buffer_object)
         {
@@ -4268,9 +4291,9 @@
     /* , or the user doesn't care and wants the speed advantage   */
 
-    e = &si->elements[WINED3D_FFP_DIFFUSE];
-    if (e->data || e->buffer_object)
+    if (si->use_map & (1 << WINED3D_FFP_DIFFUSE))
     {
         VTRACE(("glColorPointer(4, GL_UNSIGNED_BYTE, %d, %p)\n", e->stride, e->data));
 
+        e = &si->elements[WINED3D_FFP_DIFFUSE];
         if (curVBO != e->buffer_object)
         {
@@ -4292,10 +4315,10 @@
 
     /* Specular Colour ------------------------------------------*/
-    e = &si->elements[WINED3D_FFP_SPECULAR];
-    if (e->data || e->buffer_object)
+    if (si->use_map & (1 << WINED3D_FFP_SPECULAR))
     {
         TRACE("setting specular colour\n");
         VTRACE(("glSecondaryColorPointer(4, GL_UNSIGNED_BYTE, %d, %p)\n", e->stride, e->data));
 
+        e = &si->elements[WINED3D_FFP_SPECULAR];
         if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
             GLenum type = e->format_desc->gl_vtx_type;
@@ -4358,5 +4381,5 @@
 
     /* Texture coords -------------------------------------------*/
-    loadTexCoords(stateblock, si, &curVBO);
+    loadTexCoords(context, stateblock, si, &curVBO);
 }
 
@@ -4424,16 +4447,21 @@
         }
     }
-    else if (fixup || (!dataLocations->elements[WINED3D_FFP_PSIZE].data
-            && !dataLocations->position_transformed
-            && (GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA)
-            || (!dataLocations->elements[WINED3D_FFP_DIFFUSE].data
-            && !dataLocations->elements[WINED3D_FFP_SPECULAR].data))))
+    else
     {
-        /* Load the vertex data using named arrays */
-        load_named = TRUE;
-        device->useDrawStridedSlow = FALSE;
-    } else {
-        TRACE("Not loading vertex data\n");
-        device->useDrawStridedSlow = TRUE;
+        WORD slow_mask = (1 << WINED3D_FFP_PSIZE);
+        slow_mask |= -!GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA) & ((1 << WINED3D_FFP_DIFFUSE) | (1 << WINED3D_FFP_SPECULAR));
+
+        if (fixup || (!dataLocations->position_transformed
+                && !(dataLocations->use_map & slow_mask)))
+        {
+            /* Load the vertex data using named arrays */
+            load_named = TRUE;
+            device->useDrawStridedSlow = FALSE;
+        }
+        else
+        {
+            TRACE("Not loading vertex data\n");
+            device->useDrawStridedSlow = TRUE;
+        }
     }
 
@@ -4446,5 +4474,5 @@
     else if (context->namedArraysLoaded)
     {
-        unloadVertexData(stateblock);
+        unloadVertexData(context);
         context->namedArraysLoaded = FALSE;
     }
@@ -4459,5 +4487,5 @@
     {
         TRACE("Loading vertex data\n");
-        loadVertexData(stateblock, dataLocations);
+        loadVertexData(context, stateblock, dataLocations);
         context->namedArraysLoaded = TRUE;
     }
@@ -4501,7 +4529,9 @@
          * TODO: Move to the viewport state
          */
-        if (useVertexShaderFunction) {
+        if (useVertexShaderFunction)
+        {
+            GLfloat yoffset = -(63.0f / 64.0f) / stateblock->viewport.Height;
             device->posFixup[1] = context->render_offscreen ? -1.0f : 1.0f;
-            device->posFixup[3] = -device->posFixup[1] / stateblock->viewport.Height;
+            device->posFixup[3] = device->posFixup[1] * yoffset;
         }
     }
@@ -4648,6 +4678,9 @@
 static void viewport_vertexpart(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context)
 {
-    stateblock->wineD3DDevice->posFixup[2] = 1.0f / stateblock->viewport.Width;
-    stateblock->wineD3DDevice->posFixup[3] = -stateblock->wineD3DDevice->posFixup[1] / stateblock->viewport.Height;
+    GLfloat yoffset = -(63.0f / 64.0f) / stateblock->viewport.Height;
+
+    stateblock->wineD3DDevice->posFixup[2] = (63.0f / 64.0f) / stateblock->viewport.Width;
+    stateblock->wineD3DDevice->posFixup[3] = stateblock->wineD3DDevice->posFixup[1] * yoffset;
+
     if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION))) {
         transform_projection(STATE_TRANSFORM(WINED3DTS_PROJECTION), stateblock, context);
@@ -4951,4 +4984,5 @@
     { STATE_RENDER(WINED3DRS_EXTENTS),                    { STATE_RENDER(WINED3DRS_EXTENTS),                    state_extents       }, WINED3D_GL_EXT_NONE             },
     { STATE_RENDER(WINED3DRS_COLORKEYBLENDENABLE),        { STATE_RENDER(WINED3DRS_COLORKEYBLENDENABLE),        state_ckeyblend     }, WINED3D_GL_EXT_NONE             },
+    { STATE_RENDER(WINED3DRS_SOFTWAREVERTEXPROCESSING),   { STATE_RENDER(WINED3DRS_SOFTWAREVERTEXPROCESSING),   state_swvp          }, WINED3D_GL_EXT_NONE             },
     { STATE_RENDER(WINED3DRS_PATCHEDGESTYLE),             { STATE_RENDER(WINED3DRS_PATCHEDGESTYLE),             state_patchedgestyle}, WINED3D_GL_EXT_NONE             },
     { STATE_RENDER(WINED3DRS_PATCHSEGMENTS),              { STATE_RENDER(WINED3DRS_PATCHSEGMENTS),              state_patchsegments }, WINED3D_GL_EXT_NONE             },
@@ -4965,4 +4999,5 @@
     { STATE_RENDER(WINED3DRS_MULTISAMPLEANTIALIAS),       { STATE_RENDER(WINED3DRS_MULTISAMPLEANTIALIAS),       state_msaa_w        }, WINED3D_GL_EXT_NONE             },
     { STATE_RENDER(WINED3DRS_MULTISAMPLEMASK),            { STATE_RENDER(WINED3DRS_MULTISAMPLEMASK),            state_multisampmask }, WINED3D_GL_EXT_NONE             },
+    { STATE_RENDER(WINED3DRS_DEBUGMONITORTOKEN),          { STATE_RENDER(WINED3DRS_DEBUGMONITORTOKEN),          state_debug_monitor }, WINED3D_GL_EXT_NONE             },
     { STATE_RENDER(WINED3DRS_COLORWRITEENABLE),           { STATE_RENDER(WINED3DRS_COLORWRITEENABLE),           state_colorwrite    }, WINED3D_GL_EXT_NONE             },
     { STATE_RENDER(WINED3DRS_BLENDOP),                    { STATE_RENDER(WINED3DRS_BLENDOP),                    state_blendop       }, EXT_BLEND_MINMAX                },
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/stateblock.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/stateblock.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/stateblock.c	(revision 23571)
@@ -41,9 +41,9 @@
  **************************************/
 
-/** Allocates the correct amount of space for pixel and vertex shader constants, 
+/* Allocates the correct amount of space for pixel and vertex shader constants,
  * along with their set/changed flags on the given stateblock object
  */
-HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object) {
-    
+HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object)
+{
     IWineD3DStateBlockImpl *This = object;
 
@@ -123,9 +123,6 @@
 
 /** Set all members of a stateblock savedstate to the given value */
-void stateblock_savedstates_set(
-    IWineD3DStateBlock* iface,
-    SAVEDSTATES* states,
-    BOOL value) {
-    
+void stateblock_savedstates_set(IWineD3DStateBlock *iface, SAVEDSTATES *states, BOOL value)
+{
     IWineD3DStateBlockImpl *This = (IWineD3DStateBlockImpl *)iface;
     unsigned bsize = sizeof(BOOL);
@@ -238,5 +235,5 @@
     memcpy(Dest->pixelShaderConstantB, This->pixelShaderConstantB, sizeof(BOOL) * MAX_CONST_B);
     memcpy(Dest->pixelShaderConstantI, This->pixelShaderConstantI, sizeof(INT) * MAX_CONST_I * 4);
-    
+
     memcpy(Dest->streamStride, This->streamStride, sizeof(UINT) * MAX_STREAMS);
     memcpy(Dest->streamOffset, This->streamOffset, sizeof(UINT) * MAX_STREAMS);
@@ -855,6 +852,7 @@
         }
 
-        if (This->changed.indices) {
-            IWineD3DDevice_SetIndices(pDevice, This->pIndexData, This->IndexFmt);
+        if (This->changed.indices)
+        {
+            IWineD3DDevice_SetIndexBuffer(pDevice, This->pIndexData, This->IndexFmt);
             IWineD3DDevice_SetBaseVertexIndex(pDevice, This->baseVertexIndex);
         }
@@ -1038,5 +1036,5 @@
         }
         This->wineD3DDevice->updateStateBlock->gl_primitive_type = This->gl_primitive_type;
-        IWineD3DDevice_SetIndices(pDevice, This->pIndexData, This->IndexFmt);
+        IWineD3DDevice_SetIndexBuffer(pDevice, This->pIndexData, This->IndexFmt);
         IWineD3DDevice_SetBaseVertexIndex(pDevice, This->baseVertexIndex);
         IWineD3DDevice_SetVertexDeclaration(pDevice, This->vertexDecl);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 23571)
@@ -11,4 +11,5 @@
  * Copyright 2007-2008 Henri Verbeet
  * Copyright 2006-2008 Roderick Colenbrander
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -79,5 +80,5 @@
     LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->renderbuffers, renderbuffer_entry_t, entry)
     {
-        GL_EXTCALL(glDeleteRenderbuffersEXT(1, &entry->id));
+        gl_info->fbo_ops.glDeleteRenderbuffers(1, &entry->id);
         HeapFree(GetProcessHeap(), 0, entry);
     }
@@ -132,5 +133,5 @@
         UINT width, UINT height, UINT level, BOOL lockable, BOOL discard, WINED3DMULTISAMPLE_TYPE multisample_type,
         UINT multisample_quality, IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format,
-        WINED3DPOOL pool, IUnknown *parent)
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
 {
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
@@ -169,5 +170,5 @@
 
     hr = resource_init((IWineD3DResource *)surface, WINED3DRTYPE_SURFACE,
-            device, resource_size, usage, format_desc, pool, parent);
+            device, resource_size, usage, format_desc, pool, parent, parent_ops);
     if (FAILED(hr))
     {
@@ -311,5 +312,5 @@
 /* Context activation is done by the caller. */
 static void surface_bind_and_dirtify(IWineD3DSurfaceImpl *This, BOOL srgb) {
-    int active_sampler;
+    DWORD active_sampler;
 
     /* We don't need a specific texture unit, but after binding the texture the current unit is dirty.
@@ -330,5 +331,6 @@
     active_sampler = This->resource.wineD3DDevice->rev_tex_unit_map[active_texture - GL_TEXTURE0_ARB];
 
-    if (active_sampler != -1) {
+    if (active_sampler != WINED3D_UNMAPPED_STAGE)
+    {
         IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_SAMPLER(active_sampler));
     }
@@ -342,5 +344,5 @@
         IWineD3DSurfaceImpl* render_target = (IWineD3DSurfaceImpl*)device->render_targets[0];
         if ((render_target->resource.usage & WINED3DUSAGE_RENDERTARGET)
-                && (render_target->resource.format_desc->format == WINED3DFMT_P8))
+                && (render_target->resource.format_desc->format == WINED3DFMT_P8_UINT))
             return TRUE;
     }
@@ -359,5 +361,5 @@
 
     /* Only support read back of converted P8 surfaces */
-    if (This->Flags & SFLAG_CONVERTED && format_desc->format != WINED3DFMT_P8)
+    if (This->Flags & SFLAG_CONVERTED && format_desc->format != WINED3DFMT_P8_UINT)
     {
         FIXME("Read back converted textures unsupported, format=%s\n", debug_d3dformat(format_desc->format));
@@ -378,5 +380,5 @@
             checkGLcall("glBindBufferARB");
             GL_EXTCALL(glGetCompressedTexImageARB(This->texture_target, This->texture_level, NULL));
-            checkGLcall("glGetCompressedTexImageARB()");
+            checkGLcall("glGetCompressedTexImageARB");
             GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
             checkGLcall("glBindBufferARB");
@@ -386,5 +388,5 @@
             GL_EXTCALL(glGetCompressedTexImageARB(This->texture_target,
                     This->texture_level, This->resource.allocatedMemory));
-            checkGLcall("glGetCompressedTexImageARB()");
+            checkGLcall("glGetCompressedTexImageARB");
         }
 
@@ -398,5 +400,5 @@
 
         /* In case of P8 the index is stored in the alpha component if the primary render target uses P8 */
-        if (format_desc->format == WINED3DFMT_P8 && primary_render_target_is_p8(This->resource.wineD3DDevice))
+        if (format_desc->format == WINED3DFMT_P8_UINT && primary_render_target_is_p8(This->resource.wineD3DDevice))
         {
             format = GL_ALPHA;
@@ -422,5 +424,5 @@
 
             glGetTexImage(This->texture_target, This->texture_level, format, type, NULL);
-            checkGLcall("glGetTexImage()");
+            checkGLcall("glGetTexImage");
 
             GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
@@ -428,5 +430,5 @@
         } else {
             glGetTexImage(This->texture_target, This->texture_level, format, type, mem);
-            checkGLcall("glGetTexImage()");
+            checkGLcall("glGetTexImage");
         }
         LEAVE_GL();
@@ -618,4 +620,5 @@
 void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int width, unsigned int height) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
+    const struct wined3d_gl_info *gl_info = &This->resource.wineD3DDevice->adapter->gl_info;
     renderbuffer_entry_t *entry;
     GLuint renderbuffer = 0;
@@ -629,5 +632,7 @@
 
     /* Remove any renderbuffer set if the sizes match */
-    if (width == src_width && height == src_height) {
+    if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT]
+            || (width == src_width && height == src_height))
+    {
         This->current_renderbuffer = NULL;
         return;
@@ -644,8 +649,8 @@
 
     if (!renderbuffer) {
-        GL_EXTCALL(glGenRenderbuffersEXT(1, &renderbuffer));
-        GL_EXTCALL(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderbuffer));
-        GL_EXTCALL(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,
-                This->resource.format_desc->glInternal, width, height));
+        gl_info->fbo_ops.glGenRenderbuffers(1, &renderbuffer);
+        gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
+        gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER,
+                This->resource.format_desc->glInternal, width, height);
 
         entry = HeapAlloc(GetProcessHeap(), 0, sizeof(renderbuffer_entry_t));
@@ -736,4 +741,5 @@
     {
         surface_cleanup(This);
+        This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
 
         TRACE("(%p) Released.\n", This);
@@ -768,6 +774,6 @@
         }
 
-        if (This->resource.format_desc->format == WINED3DFMT_P8
-                || This->resource.format_desc->format == WINED3DFMT_A8P8)
+        if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
+                || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
         {
             if(palette9_changed(This)) {
@@ -806,9 +812,9 @@
     ENTER_GL();
     GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
-    checkGLcall("glBindBuffer(GL_PIXEL_UNPACK_BUFFER, This->pbo)");
+    checkGLcall("glBindBufferARB(GL_PIXEL_UNPACK_BUFFER, This->pbo)");
     GL_EXTCALL(glGetBufferSubDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0, This->resource.size, This->resource.allocatedMemory));
-    checkGLcall("glGetBufferSubData");
+    checkGLcall("glGetBufferSubDataARB");
     GL_EXTCALL(glDeleteBuffersARB(1, &This->pbo));
-    checkGLcall("glDeleteBuffers");
+    checkGLcall("glDeleteBuffersARB");
     LEAVE_GL();
 
@@ -821,4 +827,6 @@
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
     IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    const struct wined3d_context *context;
+    const struct wined3d_gl_info *gl_info;
     renderbuffer_entry_t *entry, *entry2;
     TRACE("(%p)\n", iface);
@@ -851,5 +859,6 @@
     This->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
 
-    ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+    context = ActivateContext(device, NULL, CTXUSAGE_RESOURCELOAD);
+    gl_info = context->gl_info;
 
     /* Destroy PBOs, but load them into real sysmem before */
@@ -864,5 +873,5 @@
     LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->renderbuffers, renderbuffer_entry_t, entry) {
         ENTER_GL();
-        GL_EXTCALL(glDeleteRenderbuffersEXT(1, &entry->id));
+        gl_info->fbo_ops.glDeleteRenderbuffers(1, &entry->id);
         LEAVE_GL();
         list_remove(&entry->entry);
@@ -961,5 +970,5 @@
     switch(This->resource.format_desc->format)
     {
-        case WINED3DFMT_P8:
+        case WINED3DFMT_P8_UINT:
         {
             if(primary_render_target_is_p8(myDevice)) {
@@ -1011,9 +1020,9 @@
     /* Save old pixel store pack state */
     glGetIntegerv(GL_PACK_ROW_LENGTH, &rowLen);
-    checkGLcall("glIntegerv");
+    checkGLcall("glGetIntegerv");
     glGetIntegerv(GL_PACK_SKIP_PIXELS, &skipPix);
-    checkGLcall("glIntegerv");
+    checkGLcall("glGetIntegerv");
     glGetIntegerv(GL_PACK_SKIP_ROWS, &skipRow);
-    checkGLcall("glIntegerv");
+    checkGLcall("glGetIntegerv");
 
     /* Setup pixel store pack state -- to glReadPixels into the correct place */
@@ -1067,5 +1076,5 @@
         if(!row) {
             ERR("Out of memory\n");
-            if (This->resource.format_desc->format == WINED3DFMT_P8) HeapFree(GetProcessHeap(), 0, mem);
+            if (This->resource.format_desc->format == WINED3DFMT_P8_UINT) HeapFree(GetProcessHeap(), 0, mem);
             LEAVE_GL();
             return;
@@ -1097,5 +1106,5 @@
      * In case of P8 render targets, the index is stored in the alpha component so no conversion is needed.
      */
-    if ((This->resource.format_desc->format == WINED3DFMT_P8) && !primary_render_target_is_p8(myDevice))
+    if (This->resource.format_desc->format == WINED3DFMT_P8_UINT && !primary_render_target_is_p8(myDevice))
     {
         const PALETTEENTRY *pal = NULL;
@@ -1394,7 +1403,7 @@
 
     glGetIntegerv(GL_PACK_SWAP_BYTES, &prev_store);
-    checkGLcall("glIntegerv");
+    checkGLcall("glGetIntegerv");
     glGetIntegerv(GL_CURRENT_RASTER_POSITION, &prev_rasterpos[0]);
-    checkGLcall("glIntegerv");
+    checkGLcall("glGetIntegerv");
     glPixelZoom(1.0f, -1.0f);
     checkGLcall("glPixelZoom");
@@ -1405,5 +1414,5 @@
 
     glRasterPos3i(This->lockedRect.left, This->lockedRect.top, 1);
-    checkGLcall("glRasterPos2f");
+    checkGLcall("glRasterPos3i");
 
     /* Some drivers(radeon dri, others?) don't like exceptions during
@@ -1455,5 +1464,5 @@
     /* Reset to previous pack row length */
     glPixelStorei(GL_UNPACK_ROW_LENGTH, skipBytes);
-    checkGLcall("glPixelStorei GL_UNPACK_ROW_LENGTH");
+    checkGLcall("glPixelStorei(GL_UNPACK_ROW_LENGTH)");
 
     if(!swapchain) {
@@ -1525,11 +1534,8 @@
         switch(wined3d_settings.rendertargetlock_mode) {
             case RTL_READTEX:
-            case RTL_TEXTEX:
                 IWineD3DSurface_LoadLocation(iface, SFLAG_INTEXTURE, NULL /* partial texture loading not supported yet */);
                 /* drop through */
 
-            case RTL_AUTO:
             case RTL_READDRAW:
-            case RTL_TEXDRAW:
                 IWineD3DSurface_LoadLocation(iface, SFLAG_INDRAWABLE, fullsurface ? NULL : &This->dirtyRect);
                 break;
@@ -1601,18 +1607,10 @@
         return WINED3DERR_INVALIDCALL;
 
-    /* According to Direct3D9 docs, only these formats are supported */
-    if (((IWineD3DImpl *)This->resource.wineD3DDevice->wineD3D)->dxVersion > 7) {
-        if (This->resource.format_desc->format != WINED3DFMT_R5G6B5
-                && This->resource.format_desc->format != WINED3DFMT_X1R5G5B5
-                && This->resource.format_desc->format != WINED3DFMT_R8G8B8
-                && This->resource.format_desc->format != WINED3DFMT_X8R8G8B8)
-            return WINED3DERR_INVALIDCALL;
-    }
-
     memset(&lock, 0, sizeof(lock)); /* To be sure */
 
     /* Create a DIB section if there isn't a hdc yet */
     if(!This->hDC) {
-        IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
+        hr = IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
+        if(FAILED(hr)) return WINED3DERR_INVALIDCALL;
         if(This->Flags & SFLAG_CLIENT) {
             surface_internal_preload(iface, SRGB_RGB);
@@ -1641,6 +1639,6 @@
     }
 
-    if (This->resource.format_desc->format == WINED3DFMT_P8
-            || This->resource.format_desc->format == WINED3DFMT_A8P8)
+    if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
+            || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
     {
         /* GetDC on palettized formats is unsupported in D3D9, and the method is missing in
@@ -1734,5 +1732,5 @@
     switch(This->resource.format_desc->format)
     {
-        case WINED3DFMT_P8:
+        case WINED3DFMT_P8_UINT:
             /* ****************
                 Paletted Texture
@@ -1769,5 +1767,5 @@
             break;
 
-        case WINED3DFMT_R3G3B2:
+        case WINED3DFMT_B2G3R3_UNORM:
             /* **********************
                 GL_UNSIGNED_BYTE_3_3_2
@@ -1780,5 +1778,5 @@
             break;
 
-        case WINED3DFMT_R5G6B5:
+        case WINED3DFMT_B5G6R5_UNORM:
             if (colorkey_active) {
                 *convert = CONVERT_CK_565;
@@ -1789,5 +1787,5 @@
             break;
 
-        case WINED3DFMT_X1R5G5B5:
+        case WINED3DFMT_B5G5R5X1_UNORM:
             if (colorkey_active) {
                 *convert = CONVERT_CK_5551;
@@ -1798,5 +1796,5 @@
             break;
 
-        case WINED3DFMT_R8G8B8:
+        case WINED3DFMT_B8G8R8_UNORM:
             if (colorkey_active) {
                 *convert = CONVERT_CK_RGB24;
@@ -1808,5 +1806,5 @@
             break;
 
-        case WINED3DFMT_X8R8G8B8:
+        case WINED3DFMT_B8G8R8X8_UNORM:
             if (colorkey_active) {
                 *convert = CONVERT_RGB32_888;
@@ -1825,5 +1823,5 @@
             break;
 
-        case WINED3DFMT_L6V5U5:
+        case WINED3DFMT_R5G5_SNORM_L6_UNORM:
             *convert = CONVERT_L6V5U5;
             if(GL_SUPPORT(NV_TEXTURE_SHADER)) {
@@ -1838,5 +1836,5 @@
             break;
 
-        case WINED3DFMT_X8L8V8U8:
+        case WINED3DFMT_R8G8_SNORM_L8X8_UNORM:
             *convert = CONVERT_X8L8V8U8;
             *target_bpp = 4;
@@ -1870,6 +1868,6 @@
             break;
 
-        case WINED3DFMT_A4L4:
-            /* A4L4 exists as an internal gl format, but for some reason there is not
+        case WINED3DFMT_L4A4_UNORM:
+            /* WINED3DFMT_L4A4_UNORM exists as an internal gl format, but for some reason there is not
              * format+type combination to load it. Thus convert it to A8L8, then load it
              * with A4L4 internal, but A8L8 format+type
@@ -1902,6 +1900,7 @@
             break;
 
-        case WINED3DFMT_D15S1:
-            if (GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
+        case WINED3DFMT_S1_UINT_D15_UNORM:
+            if (GL_SUPPORT(ARB_FRAMEBUFFER_OBJECT)
+                    || GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
             {
                 *convert = CONVERT_D15S1;
@@ -1910,6 +1909,7 @@
             break;
 
-        case WINED3DFMT_D24X4S4:
-            if (GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
+        case WINED3DFMT_S4X4_UINT_D24_UNORM:
+            if (GL_SUPPORT(ARB_FRAMEBUFFER_OBJECT)
+                    || GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
             {
                 *convert = CONVERT_D24X4S4;
@@ -1917,5 +1917,5 @@
             break;
 
-        case WINED3DFMT_D24FS8:
+        case WINED3DFMT_S8_UINT_D24_FLOAT:
             if (GL_SUPPORT(ARB_DEPTH_BUFFER_FLOAT))
             {
@@ -2517,6 +2517,6 @@
     IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
 
-    if (This->palette || (This->resource.format_desc->format != WINED3DFMT_P8
-            && This->resource.format_desc->format != WINED3DFMT_A8P8))
+    if (This->palette || (This->resource.format_desc->format != WINED3DFMT_P8_UINT
+            && This->resource.format_desc->format != WINED3DFMT_P8_UINT_A8_UNORM))
     {
         /* If a ddraw-style palette is attached assume no d3d9 palette change.
@@ -2742,5 +2742,5 @@
     FIXME("Saving texture level %d width %d height %d\n", This->texture_level, width, height);
     glGetTexImage(GL_TEXTURE_2D, This->texture_level, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, allocatedMemory);
-    checkGLcall("glTexImage2D");
+    checkGLcall("glGetTexImage");
     if (tmpTexture) {
         glBindTexture(GL_TEXTURE_2D, 0);
@@ -2985,5 +2985,5 @@
 
     if(override) {
-        /* DDraw sets this for the X11 surfaces, so don't confuse the user 
+        /* DDraw sets this for the X11 surfaces, so don't confuse the user
          * FIXME("(%p) Target override is not supported by now\n", This);
          * Additionally, it isn't really possible to support triple-buffering
@@ -3108,4 +3108,9 @@
 
     LEAVE_GL();
+
+    /* The texture is now most up to date - If the surface is a render target and has a drawable, this
+     * path is never entered
+     */
+    IWineD3DSurface_ModifyLocation((IWineD3DSurface *) This, SFLAG_INTEXTURE, TRUE);
 }
 
@@ -3355,4 +3360,9 @@
 
     LEAVE_GL();
+
+    /* The texture is now most up to date - If the surface is a render target and has a drawable, this
+     * path is never entered
+     */
+    IWineD3DSurface_ModifyLocation((IWineD3DSurface *) This, SFLAG_INTEXTURE, TRUE);
 }
 
@@ -3577,5 +3587,5 @@
         /* When blitting from a render target a texture, the texture isn't required to have a palette.
          * In this case grab the palette from the render target. */
-        if ((This->resource.format_desc->format == WINED3DFMT_P8) && (This->palette == NULL))
+        if (This->resource.format_desc->format == WINED3DFMT_P8_UINT && !This->palette)
         {
             paletteOverride = TRUE;
@@ -3599,5 +3609,6 @@
          * backends.
          */
-        if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && GL_SUPPORT(EXT_FRAMEBUFFER_BLIT)
+        if (wined3d_settings.offscreen_rendering_mode == ORM_FBO
+                && myDevice->adapter->gl_info.fbo_ops.glBlitFramebuffer
                 && surface_can_stretch_rect(Src, This))
         {
@@ -3624,8 +3635,4 @@
             This->Flags &= ~SFLAG_INSYSMEM;
         }
-        /* The texture is now most up to date - If the surface is a render target and has a drawable, this
-         * path is never entered
-         */
-        IWineD3DSurface_ModifyLocation((IWineD3DSurface *) This, SFLAG_INTEXTURE, TRUE);
 
         return WINED3D_OK;
@@ -3656,5 +3663,5 @@
          * code further down the road retrieves the palette from the surface, so
          * it must have a palette set. */
-        if ((Src->resource.format_desc->format == WINED3DFMT_P8) && (Src->palette == NULL))
+        if (Src->resource.format_desc->format == WINED3DFMT_P8_UINT && !Src->palette)
         {
             paletteOverride = TRUE;
@@ -3663,5 +3670,6 @@
         }
 
-        if (wined3d_settings.offscreen_rendering_mode == ORM_FBO && GL_SUPPORT(EXT_FRAMEBUFFER_BLIT)
+        if (wined3d_settings.offscreen_rendering_mode == ORM_FBO
+                && myDevice->adapter->gl_info.fbo_ops.glBlitFramebuffer
                 && !(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE))
                 && surface_can_stretch_rect(Src, This))
@@ -3768,5 +3776,5 @@
         if(Flags & (WINEDDBLT_KEYSRC | WINEDDBLT_KEYSRCOVERRIDE)) {
             glEnable(GL_ALPHA_TEST);
-            checkGLcall("glEnable GL_ALPHA_TEST");
+            checkGLcall("glEnable(GL_ALPHA_TEST)");
 
             /* When the primary render target uses P8, the alpha component contains the palette index.
@@ -3780,5 +3788,5 @@
         } else {
             glDisable(GL_ALPHA_TEST);
-            checkGLcall("glDisable GL_ALPHA_TEST");
+            checkGLcall("glDisable(GL_ALPHA_TEST)");
         }
 
@@ -3826,5 +3834,5 @@
         /* Flush in case the drawable is used by multiple GL contexts */
         if(dstSwapchain && (This == (IWineD3DSurfaceImpl *) dstSwapchain->frontBuffer || dstSwapchain->num_contexts >= 2))
-            glFlush();
+            wglFlush();
 
         /* TODO: If the surface is locked often, perform the Blt in software on the memory instead */
@@ -3855,5 +3863,5 @@
              * 'clear' expect it in ARGB format => we need to do some conversion :-)
              */
-            if (This->resource.format_desc->format == WINED3DFMT_P8)
+            if (This->resource.format_desc->format == WINED3DFMT_P8_UINT)
             {
                 DWORD alpha;
@@ -3871,5 +3879,5 @@
                 }
             }
-            else if (This->resource.format_desc->format == WINED3DFMT_R5G6B5)
+            else if (This->resource.format_desc->format == WINED3DFMT_B5G6R5_UNORM)
             {
                 if (DDBltFx->u5.dwFillColor == 0xFFFF) {
@@ -3882,10 +3890,10 @@
                 }
             }
-            else if ((This->resource.format_desc->format == WINED3DFMT_R8G8B8)
-                    || (This->resource.format_desc->format == WINED3DFMT_X8R8G8B8))
+            else if (This->resource.format_desc->format == WINED3DFMT_B8G8R8_UNORM
+                    || This->resource.format_desc->format == WINED3DFMT_B8G8R8X8_UNORM)
             {
                 color = 0xFF000000 | DDBltFx->u5.dwFillColor;
             }
-            else if (This->resource.format_desc->format == WINED3DFMT_A8R8G8B8)
+            else if (This->resource.format_desc->format == WINED3DFMT_B8G8R8A8_UNORM)
             {
                 color = DDBltFx->u5.dwFillColor;
@@ -3920,12 +3928,12 @@
                 depth = (float) DDBltFx->u5.dwFillDepth / (float) 0x0000ffff;
                 break;
-            case WINED3DFMT_D15S1:
+            case WINED3DFMT_S1_UINT_D15_UNORM:
                 depth = (float) DDBltFx->u5.dwFillDepth / (float) 0x0000fffe;
                 break;
-            case WINED3DFMT_D24S8:
-            case WINED3DFMT_D24X8:
+            case WINED3DFMT_S8_UINT_D24_UNORM:
+            case WINED3DFMT_X8D24_UNORM:
                 depth = (float) DDBltFx->u5.dwFillDepth / (float) 0x00ffffff;
                 break;
-            case WINED3DFMT_D32:
+            case WINED3DFMT_D32_UNORM:
                 depth = (float) DDBltFx->u5.dwFillDepth / (float) 0xffffffff;
                 break;
@@ -4060,6 +4068,6 @@
     if (!pal) return WINED3D_OK;
 
-    if (This->resource.format_desc->format == WINED3DFMT_P8
-            || This->resource.format_desc->format == WINED3DFMT_A8P8)
+    if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
+            || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
     {
         int bpp;
@@ -4068,5 +4076,5 @@
 
         /* Check if we are using a RTL mode which uses texturing for uploads */
-        BOOL use_texture = (wined3d_settings.rendertargetlock_mode == RTL_READTEX || wined3d_settings.rendertargetlock_mode == RTL_TEXTEX);
+        BOOL use_texture = (wined3d_settings.rendertargetlock_mode == RTL_READTEX);
 
         /* Check if we have hardware palette conversion if we have convert is set to NO_CONVERSION */
@@ -4173,8 +4181,7 @@
            doesn't work in combination with ARB_TEXTURE_RECTANGLE.
         */
-        if(This->Flags & SFLAG_NONPOW2 && GL_SUPPORT(ARB_TEXTURE_RECTANGLE)
-                && !((This->resource.format_desc->format == WINED3DFMT_P8) && GL_SUPPORT(EXT_PALETTED_TEXTURE)
-                && (wined3d_settings.rendertargetlock_mode == RTL_READTEX
-                || wined3d_settings.rendertargetlock_mode == RTL_TEXTEX)))
+        if (This->Flags & SFLAG_NONPOW2 && GL_SUPPORT(ARB_TEXTURE_RECTANGLE)
+                && !(This->resource.format_desc->format == WINED3DFMT_P8_UINT && GL_SUPPORT(EXT_PALETTED_TEXTURE)
+                && wined3d_settings.rendertargetlock_mode == RTL_READTEX))
         {
             This->texture_target = GL_TEXTURE_RECTANGLE_ARB;
@@ -4361,4 +4368,5 @@
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
     IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
 
     TRACE("(%p) New location %#x\n", This, location);
@@ -4392,5 +4400,5 @@
             /* Note that we use depth_blt here as well, rather than glCopyTexImage2D
              * directly on the FBO texture. That's because we need to flip. */
-            context_bind_fbo(context, GL_FRAMEBUFFER_EXT, NULL);
+            context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
             if (This->texture_target == GL_TEXTURE_RECTANGLE_ARB)
             {
@@ -4414,12 +4422,13 @@
             /* Setup the destination */
             if (!device->depth_blt_rb) {
-                GL_EXTCALL(glGenRenderbuffersEXT(1, &device->depth_blt_rb));
+                gl_info->fbo_ops.glGenRenderbuffers(1, &device->depth_blt_rb);
                 checkGLcall("glGenRenderbuffersEXT");
             }
             if (device->depth_blt_rb_w != This->currentDesc.Width
                     || device->depth_blt_rb_h != This->currentDesc.Height) {
-                GL_EXTCALL(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, device->depth_blt_rb));
+                gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, device->depth_blt_rb);
                 checkGLcall("glBindRenderbufferEXT");
-                GL_EXTCALL(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, This->currentDesc.Width, This->currentDesc.Height));
+                gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8,
+                        This->currentDesc.Width, This->currentDesc.Height);
                 checkGLcall("glRenderbufferStorageEXT");
                 device->depth_blt_rb_w = This->currentDesc.Width;
@@ -4427,8 +4436,9 @@
             }
 
-            context_bind_fbo(context, GL_FRAMEBUFFER_EXT, &context->dst_fbo);
-            GL_EXTCALL(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, device->depth_blt_rb));
+            context_bind_fbo(context, GL_FRAMEBUFFER, &context->dst_fbo);
+            gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER,
+                    GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, device->depth_blt_rb);
             checkGLcall("glFramebufferRenderbufferEXT");
-            context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER_EXT, iface, FALSE);
+            context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER, iface, FALSE);
 
             /* Do the actual blit */
@@ -4436,6 +4446,6 @@
             checkGLcall("depth_blt");
 
-            if (context->current_fbo) context_bind_fbo(context, GL_FRAMEBUFFER_EXT, &context->current_fbo->id);
-            else context_bind_fbo(context, GL_FRAMEBUFFER_EXT, NULL);
+            if (context->current_fbo) context_bind_fbo(context, GL_FRAMEBUFFER, &context->current_fbo->id);
+            else context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
 
             LEAVE_GL();
@@ -4449,10 +4459,10 @@
             ENTER_GL();
 
-            context_bind_fbo(context, GL_FRAMEBUFFER_EXT, NULL);
+            context_bind_fbo(context, GL_FRAMEBUFFER, NULL);
             surface_depth_blt(This, This->texture_name, This->currentDesc.Width,
                     This->currentDesc.Height, This->texture_target);
             checkGLcall("depth_blt");
 
-            if (context->current_fbo) context_bind_fbo(context, GL_FRAMEBUFFER_EXT, &context->current_fbo->id);
+            if (context->current_fbo) context_bind_fbo(context, GL_FRAMEBUFFER, &context->current_fbo->id);
 
             LEAVE_GL();
@@ -4655,5 +4665,5 @@
     checkGLcall("glEnable(bind_target)");
     glBindTexture(bind_target, This->texture_name);
-    checkGLcall("bind_target, This->texture_name)");
+    checkGLcall("glBindTexture(bind_target, This->texture_name)");
     glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     checkGLcall("glTexParameteri");
@@ -4693,5 +4703,5 @@
         if(((IWineD3DSwapChainImpl*)swapchain)->frontBuffer == (IWineD3DSurface*)This ||
            ((IWineD3DSwapChainImpl*)swapchain)->num_contexts >= 2)
-            glFlush();
+            wglFlush();
 
         IWineD3DSwapChain_Release(swapchain);
@@ -4702,7 +4712,7 @@
         if(SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface*)This, &IID_IWineD3DBaseTexture, (void **) &texture)))
         {
-            ((IWineD3DBaseTextureImpl *) texture)->baseTexture.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
-            ((IWineD3DBaseTextureImpl *) texture)->baseTexture.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
-            ((IWineD3DBaseTextureImpl *) texture)->baseTexture.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
+            ((IWineD3DBaseTextureImpl *) texture)->baseTexture.texture_rgb.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
+            ((IWineD3DBaseTextureImpl *) texture)->baseTexture.texture_rgb.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
+            ((IWineD3DBaseTextureImpl *) texture)->baseTexture.texture_rgb.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
             IWineD3DBaseTexture_Release(texture);
         }
@@ -4851,9 +4861,15 @@
                 }
             } else {
-                if((This->Flags & SFLAG_LOCATIONS) == SFLAG_INSRGBTEX) {
+                if((This->Flags & (SFLAG_INSRGBTEX | SFLAG_INSYSMEM)) == SFLAG_INSRGBTEX) {
                     /* Performance warning ... */
                     FIXME("%p: Downloading srgb texture to reload it as rgb\n", This);
                     IWineD3DSurfaceImpl_LoadLocation(iface, SFLAG_INSYSMEM, rect);
                 }
+            }
+            if(!(This->Flags & SFLAG_INSYSMEM)) {
+                /* Should not happen */
+                ERR("Trying to load a texture from sysmem, but SFLAG_INSYSMEM is not set\n");
+                /* Lets hope we get it from somewhere... */
+                IWineD3DSurfaceImpl_LoadLocation(iface, SFLAG_INSYSMEM, rect);
             }
 
@@ -4894,5 +4910,5 @@
                 This->Flags |= SFLAG_CONVERTED;
             }
-            else if ((This->resource.format_desc->format == WINED3DFMT_P8)
+            else if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
                     && (GL_SUPPORT(EXT_PALETTED_TEXTURE) || GL_SUPPORT(ARB_FRAGMENT_PROGRAM)))
             {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c	(revision 23571)
@@ -11,4 +11,5 @@
  * Copyright 2007 Henri Verbeet
  * Copyright 2006-2007 Roderick Colenbrander
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -552,4 +553,10 @@
     UINT usage;
 
+    if(!(format_desc->Flags & WINED3DFMT_FLAG_GETDC))
+    {
+        WARN("Cannot use GetDC on a %s surface\n", debug_d3dformat(format_desc->format));
+        return WINED3DERR_INVALIDCALL;
+    }
+
     switch (format_desc->byte_count)
     {
@@ -602,20 +609,20 @@
     switch (This->resource.format_desc->format)
     {
-        case WINED3DFMT_R8G8B8:
+        case WINED3DFMT_B8G8R8_UNORM:
             usage = DIB_RGB_COLORS;
             b_info->bmiHeader.biCompression = BI_RGB;
             break;
 
-        case WINED3DFMT_X1R5G5B5:
-        case WINED3DFMT_A1R5G5B5:
-        case WINED3DFMT_A4R4G4B4:
-        case WINED3DFMT_X4R4G4B4:
-        case WINED3DFMT_R3G3B2:
-        case WINED3DFMT_A8R3G3B2:
+        case WINED3DFMT_B5G5R5X1_UNORM:
+        case WINED3DFMT_B5G5R5A1_UNORM:
+        case WINED3DFMT_B4G4R4A4_UNORM:
+        case WINED3DFMT_B4G4R4X4_UNORM:
+        case WINED3DFMT_B2G3R3_UNORM:
+        case WINED3DFMT_B2G3R3A8_UNORM:
         case WINED3DFMT_R10G10B10A2_UNORM:
         case WINED3DFMT_R8G8B8A8_UNORM:
-        case WINED3DFMT_X8B8G8R8:
-        case WINED3DFMT_A2R10G10B10:
-        case WINED3DFMT_R5G6B5:
+        case WINED3DFMT_R8G8B8X8_UNORM:
+        case WINED3DFMT_B10G10R10A2_UNORM:
+        case WINED3DFMT_B5G6R5_UNORM:
         case WINED3DFMT_R16G16B16A16_UNORM:
             usage = 0;
@@ -760,7 +767,7 @@
 static const struct d3dfmt_convertor_desc convertors[] =
 {
-    {WINED3DFMT_R32_FLOAT,  WINED3DFMT_R16_FLOAT,   convert_r32_float_r16_float},
-    {WINED3DFMT_R5G6B5,     WINED3DFMT_X8R8G8B8,    convert_r5g6b5_x8r8g8b8},
-    {WINED3DFMT_A8R8G8B8,   WINED3DFMT_X8R8G8B8,    convert_a8r8g8b8_x8r8g8b8},
+    {WINED3DFMT_R32_FLOAT,      WINED3DFMT_R16_FLOAT,       convert_r32_float_r16_float},
+    {WINED3DFMT_B5G6R5_UNORM,   WINED3DFMT_B8G8R8X8_UNORM,  convert_r5g6b5_x8r8g8b8},
+    {WINED3DFMT_B8G8R8A8_UNORM, WINED3DFMT_B8G8R8X8_UNORM,  convert_a8r8g8b8_x8r8g8b8},
 };
 
@@ -803,5 +810,6 @@
             source->currentDesc.Height, to_fmt, TRUE /* lockable */, TRUE /* discard  */, 0 /* level */, &ret,
             0 /* usage */, WINED3DPOOL_SCRATCH, WINED3DMULTISAMPLE_NONE /* TODO: Multisampled conversion */,
-            0 /* MultiSampleQuality */, IWineD3DSurface_GetImplType((IWineD3DSurface *) source), NULL /* parent */);
+            0 /* MultiSampleQuality */, IWineD3DSurface_GetImplType((IWineD3DSurface *) source),
+            NULL /* parent */, &wined3d_null_parent_ops);
     if(!ret) {
         ERR("Failed to create a destination surface for conversion\n");
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_gdi.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_gdi.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_gdi.c	(revision 23571)
@@ -323,5 +323,5 @@
     fprintf(f, "P6\n%d %d\n255\n", This->pow2Width, This->pow2Height);
 
-    if (This->resource.format_desc->format == WINED3DFMT_P8)
+    if (This->resource.format_desc->format == WINED3DFMT_P8_UINT)
     {
         unsigned char table[256][3];
@@ -393,4 +393,10 @@
 
     TRACE("(%p)->(%p)\n",This,pHDC);
+
+    if(!(This->Flags & SFLAG_DIBSECTION))
+    {
+        WARN("DC not supported on this surface\n");
+        return WINED3DERR_INVALIDCALL;
+    }
 
     if(This->Flags & SFLAG_USERPTR) {
@@ -422,6 +428,6 @@
     }
 
-    if (This->resource.format_desc->format == WINED3DFMT_P8
-            || This->resource.format_desc->format == WINED3DFMT_A8P8)
+    if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
+            || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
     {
         unsigned int n;
@@ -535,4 +541,5 @@
 {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
+    HRESULT hr;
 
     if(This->resource.usage & WINED3DUSAGE_OVERLAY)
@@ -541,17 +548,19 @@
         return WINED3DERR_INVALIDCALL;
     }
+
     /* Sysmem textures have memory already allocated -
      * release it, this avoids an unnecessary memcpy
      */
-    HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
-    This->resource.allocatedMemory = NULL;
-    This->resource.heapMemory = NULL;
+    hr = IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
+    if(SUCCEEDED(hr))
+    {
+        HeapFree(GetProcessHeap(), 0, This->resource.heapMemory);
+        This->resource.heapMemory = NULL;
+        This->resource.allocatedMemory = This->dib.bitmap_data;
+    }
 
     /* We don't mind the nonpow2 stuff in GDI */
     This->pow2Width = This->currentDesc.Width;
     This->pow2Height = This->currentDesc.Height;
-
-    IWineD3DBaseSurfaceImpl_CreateDIBSection(iface);
-    This->resource.allocatedMemory = This->dib.bitmap_data;
 
     return WINED3D_OK;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c	(revision 23571)
@@ -46,5 +46,6 @@
 
 /*IWineD3DSwapChain parts follow: */
-static void WINAPI IWineD3DSwapChainImpl_Destroy(IWineD3DSwapChain *iface, D3DCB_DESTROYSURFACEFN D3DCB_DestroyRenderTarget) {
+static void WINAPI IWineD3DSwapChainImpl_Destroy(IWineD3DSwapChain *iface)
+{
     IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
     WINED3DDISPLAYMODE mode;
@@ -55,21 +56,30 @@
     IWineD3DSwapChain_SetGammaRamp(iface, 0, &This->orig_gamma);
 
-    /* release the ref to the front and back buffer parents */
-    if(This->frontBuffer) {
+    /* Release the swapchain's draw buffers. Make sure This->backBuffer[0] is
+     * the last buffer to be destroyed, FindContext() depends on that. */
+    if (This->frontBuffer)
+    {
         IWineD3DSurface_SetContainer(This->frontBuffer, 0);
-        if(D3DCB_DestroyRenderTarget(This->frontBuffer) > 0) {
-            FIXME("(%p) Something's still holding the front buffer\n",This);
-        }
-    }
-
-    if(This->backBuffer) {
-        UINT i;
-        for(i = 0; i < This->presentParms.BackBufferCount; i++) {
+        if (IWineD3DSurface_Release(This->frontBuffer))
+        {
+            WARN("(%p) Something's still holding the front buffer (%p).\n",
+                    This, This->frontBuffer);
+        }
+        This->frontBuffer = NULL;
+    }
+
+    if (This->backBuffer)
+    {
+        UINT i = This->presentParms.BackBufferCount;
+
+        while (i--)
+        {
             IWineD3DSurface_SetContainer(This->backBuffer[i], 0);
-            if(D3DCB_DestroyRenderTarget(This->backBuffer[i]) > 0) {
-                FIXME("(%p) Something's still holding the back buffer\n",This);
-            }
+            if (IWineD3DSurface_Release(This->backBuffer[i]))
+                WARN("(%p) Something's still holding back buffer %u (%p).\n",
+                        This, i, This->backBuffer[i]);
         }
         HeapFree(GetProcessHeap(), 0, This->backBuffer);
+        This->backBuffer = NULL;
     }
 
@@ -120,5 +130,6 @@
         cursor.resource.wineD3DDevice = This->wineD3DDevice;
         cursor.resource.pool = WINED3DPOOL_SCRATCH;
-        cursor.resource.format_desc = getFormatDescEntry(WINED3DFMT_A8R8G8B8, &This->wineD3DDevice->adapter->gl_info);
+        cursor.resource.format_desc =
+                getFormatDescEntry(WINED3DFMT_B8G8R8A8_UNORM, &This->wineD3DDevice->adapter->gl_info);
         cursor.resource.resourceType = WINED3DRTYPE_SURFACE;
         cursor.texture_name = This->wineD3DDevice->cursorTexture;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_base.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_base.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_base.c	(revision 23571)
@@ -69,5 +69,5 @@
     TRACE("(%p) : ReleaseRef to %d\n", This, refCount);
     if (refCount == 0) {
-        IWineD3DSwapChain_Destroy(iface, D3DCB_DefaultDestroySurface);
+        IWineD3DSwapChain_Destroy(iface);
     }
     return refCount;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_gdi.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_gdi.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain_gdi.c	(revision 23571)
@@ -37,5 +37,6 @@
 WINE_DECLARE_DEBUG_CHANNEL(fps);
 
-static void WINAPI IWineGDISwapChainImpl_Destroy(IWineD3DSwapChain *iface, D3DCB_DESTROYSURFACEFN D3DCB_DestroyRenderback) {
+static void WINAPI IWineGDISwapChainImpl_Destroy(IWineD3DSwapChain *iface)
+{
     IWineD3DSwapChainImpl *This = (IWineD3DSwapChainImpl *)iface;
     WINED3DDISPLAYMODE mode;
@@ -48,6 +49,7 @@
     if(This->frontBuffer) {
         IWineD3DSurface_SetContainer(This->frontBuffer, 0);
-        if(D3DCB_DestroyRenderback(This->frontBuffer) > 0) {
-            FIXME("(%p) Something's still holding the front buffer\n",This);
+        if (IWineD3DSurface_Release(This->frontBuffer) > 0)
+        {
+            WARN("(%p) Something's still holding the front buffer\n",This);
         }
     }
@@ -57,6 +59,7 @@
         for(i = 0; i < This->presentParms.BackBufferCount; i++) {
             IWineD3DSurface_SetContainer(This->backBuffer[i], 0);
-            if(D3DCB_DestroyRenderback(This->backBuffer[i]) > 0) {
-                FIXME("(%p) Something's still holding the back buffer\n",This);
+            if (IWineD3DSurface_Release(This->backBuffer[i]) > 0)
+            {
+                WARN("(%p) Something's still holding the back buffer\n",This);
             }
         }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c	(revision 23571)
@@ -6,4 +6,5 @@
  * Copyright 2005 Oliver Stieber
  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -67,5 +68,5 @@
             break;
     }
-    dirty = srgb_mode ? &This->baseTexture.srgbDirty : &This->baseTexture.dirty;
+    dirty = srgb_mode ? &This->baseTexture.texture_srgb.dirty : &This->baseTexture.texture_rgb.dirty;
 
     if (!device->isInDraw)
@@ -76,6 +77,6 @@
     }
 
-    if (This->resource.format_desc->format == WINED3DFMT_P8
-            || This->resource.format_desc->format == WINED3DFMT_A8P8)
+    if (This->resource.format_desc->format == WINED3DFMT_P8_UINT
+            || This->resource.format_desc->format == WINED3DFMT_P8_UINT_A8_UNORM)
     {
         for (i = 0; i < This->baseTexture.levels; ++i)
@@ -110,5 +111,5 @@
 }
 
-static void texture_cleanup(IWineD3DTextureImpl *This, D3DCB_DESTROYSURFACEFN surface_destroy_cb)
+static void texture_cleanup(IWineD3DTextureImpl *This)
 {
     unsigned int i;
@@ -126,5 +127,5 @@
             surface_set_texture_target(This->surfaces[i], 0);
             IWineD3DSurface_SetContainer(This->surfaces[i], 0);
-            surface_destroy_cb(This->surfaces[i]);
+            IWineD3DSurface_Release(This->surfaces[i]);
         }
     }
@@ -132,155 +133,4 @@
     TRACE("(%p) : Cleaning up base texture\n", This);
     basetexture_cleanup((IWineD3DBaseTexture *)This);
-}
-
-HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
-        IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
-{
-    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
-    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
-    UINT pow2_width, pow2_height;
-    UINT tmp_w, tmp_h;
-    unsigned int i;
-    HRESULT hr;
-
-    /* TODO: It should only be possible to create textures for formats
-     * that are reported as supported. */
-    if (WINED3DFMT_UNKNOWN >= format)
-    {
-        WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
-        return WINED3DERR_INVALIDCALL;
-    }
-
-    /* Non-power2 support. */
-    if (GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO))
-    {
-        pow2_width = width;
-        pow2_height = height;
-    }
-    else
-    {
-        /* Find the nearest pow2 match. */
-        pow2_width = pow2_height = 1;
-        while (pow2_width < width) pow2_width <<= 1;
-        while (pow2_height < height) pow2_height <<= 1;
-
-        if (pow2_width != width || pow2_height != height)
-        {
-            if (levels > 1)
-            {
-                WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
-                return WINED3DERR_INVALIDCALL;
-            }
-            levels = 1;
-        }
-    }
-
-    /* Calculate levels for mip mapping. */
-    if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
-    {
-        if (!GL_SUPPORT(SGIS_GENERATE_MIPMAP))
-        {
-            WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
-            return WINED3DERR_INVALIDCALL;
-        }
-
-        if (levels > 1)
-        {
-            WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
-            return WINED3DERR_INVALIDCALL;
-        }
-
-        levels = 1;
-    }
-    else if (!levels)
-    {
-        levels = wined3d_log2i(max(width, height)) + 1;
-        TRACE("Calculated levels = %u.\n", levels);
-    }
-
-    hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels,
-            WINED3DRTYPE_TEXTURE, device, 0, usage, format_desc, pool, parent);
-    if (FAILED(hr))
-    {
-        WARN("Failed to initialize basetexture, returning %#x.\n", hr);
-        return hr;
-    }
-
-    /* Precalculated scaling for 'faked' non power of two texture coords.
-     * Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
-     * is used in combination with texture uploads (RTL_READTEX/RTL_TEXTEX). The reason is that EXT_PALETTED_TEXTURE
-     * doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
-    if (GL_SUPPORT(WINE_NORMALIZED_TEXRECT) && (width != pow2_width || height != pow2_height))
-    {
-        texture->baseTexture.pow2Matrix[0] = 1.0f;
-        texture->baseTexture.pow2Matrix[5] = 1.0f;
-        texture->baseTexture.pow2Matrix[10] = 1.0f;
-        texture->baseTexture.pow2Matrix[15] = 1.0f;
-        texture->target = GL_TEXTURE_2D;
-        texture->cond_np2 = TRUE;
-        texture->baseTexture.minMipLookup = minMipLookup_noFilter;
-    }
-    else if (GL_SUPPORT(ARB_TEXTURE_RECTANGLE) && (width != pow2_width || height != pow2_height)
-            && !((format_desc->format == WINED3DFMT_P8) && GL_SUPPORT(EXT_PALETTED_TEXTURE)
-            && (wined3d_settings.rendertargetlock_mode == RTL_READTEX
-            || wined3d_settings.rendertargetlock_mode == RTL_TEXTEX)))
-    {
-        if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
-
-        texture->baseTexture.pow2Matrix[0] = (float)width;
-        texture->baseTexture.pow2Matrix[5] = (float)height;
-        texture->baseTexture.pow2Matrix[10] = 1.0f;
-        texture->baseTexture.pow2Matrix[15] = 1.0f;
-        texture->target = GL_TEXTURE_RECTANGLE_ARB;
-        texture->cond_np2 = TRUE;
-        texture->baseTexture.minMipLookup = minMipLookup_noFilter;
-    }
-    else
-    {
-        if ((width != pow2_width) || (height != pow2_height))
-        {
-            texture->baseTexture.pow2Matrix_identity = FALSE;
-            texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
-            texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
-        }
-        else
-        {
-            texture->baseTexture.pow2Matrix[0] = 1.0f;
-            texture->baseTexture.pow2Matrix[5] = 1.0f;
-        }
-
-        texture->baseTexture.pow2Matrix[10] = 1.0f;
-        texture->baseTexture.pow2Matrix[15] = 1.0f;
-        texture->target = GL_TEXTURE_2D;
-        texture->cond_np2 = FALSE;
-    }
-    TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
-
-    /* Generate all the surfaces. */
-    tmp_w = width;
-    tmp_h = height;
-    for (i = 0; i < texture->baseTexture.levels; ++i)
-    {
-        /* Use the callback to create the texture surface. */
-        hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
-                usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]);
-        if (FAILED(hr) || ((IWineD3DSurfaceImpl *)texture->surfaces[i])->Flags & SFLAG_OVERSIZE)
-        {
-            FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
-            texture->surfaces[i] = NULL;
-            texture_cleanup(texture, D3DCB_DefaultDestroySurface);
-            return hr;
-        }
-
-        IWineD3DSurface_SetContainer(texture->surfaces[i], (IWineD3DBase *)texture);
-        TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[i]);
-        surface_set_texture_target(texture->surfaces[i], texture->target);
-        /* Calculate the next mipmap level. */
-        tmp_w = max(1, tmp_w >> 1);
-        tmp_h = max(1, tmp_h >> 1);
-    }
-    texture->baseTexture.internal_preload = texture_internal_preload;
-
-    return WINED3D_OK;
 }
 
@@ -321,6 +171,9 @@
     TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
     ref = InterlockedDecrement(&This->resource.ref);
-    if (ref == 0) {
-        IWineD3DTexture_Destroy(iface, D3DCB_DefaultDestroySurface);
+    if (!ref)
+    {
+        texture_cleanup(This);
+        This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
+        HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -432,10 +285,14 @@
     if (set_gl_texture_desc && SUCCEEDED(hr)) {
         UINT i;
+        struct gl_texture *gl_tex;
+
+        if(This->baseTexture.is_srgb) {
+            gl_tex = &This->baseTexture.texture_srgb;
+        } else {
+            gl_tex = &This->baseTexture.texture_rgb;
+        }
+
         for (i = 0; i < This->baseTexture.levels; ++i) {
-            if(This->baseTexture.is_srgb) {
-                surface_set_texture_name(This->surfaces[i], This->baseTexture.srgbTextureName, TRUE);
-            } else {
-                surface_set_texture_name(This->surfaces[i], This->baseTexture.textureName, FALSE);
-            }
+            surface_set_texture_name(This->surfaces[i], gl_tex->name, This->baseTexture.is_srgb);
         }
         /* Conditinal non power of two textures use a different clamping default. If we're using the GL_WINE_normalized_texrect
@@ -455,9 +312,9 @@
             checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
             LEAVE_GL();
-            This->baseTexture.states[WINED3DTEXSTA_ADDRESSU]      = WINED3DTADDRESS_CLAMP;
-            This->baseTexture.states[WINED3DTEXSTA_ADDRESSV]      = WINED3DTADDRESS_CLAMP;
-            This->baseTexture.states[WINED3DTEXSTA_MAGFILTER]     = WINED3DTEXF_POINT;
-            This->baseTexture.states[WINED3DTEXSTA_MINFILTER]     = WINED3DTEXF_POINT;
-            This->baseTexture.states[WINED3DTEXSTA_MIPFILTER]     = WINED3DTEXF_NONE;
+            gl_tex->states[WINED3DTEXSTA_ADDRESSU]      = WINED3DTADDRESS_CLAMP;
+            gl_tex->states[WINED3DTEXSTA_ADDRESSV]      = WINED3DTADDRESS_CLAMP;
+            gl_tex->states[WINED3DTEXSTA_MAGFILTER]     = WINED3DTEXF_POINT;
+            gl_tex->states[WINED3DTEXSTA_MINFILTER]     = WINED3DTEXF_POINT;
+            gl_tex->states[WINED3DTEXSTA_MIPFILTER]     = WINED3DTEXF_NONE;
         }
     }
@@ -483,12 +340,4 @@
    IWineD3DTexture IWineD3DTexture parts follow
    ******************************************* */
-static void WINAPI IWineD3DTextureImpl_Destroy(IWineD3DTexture *iface, D3DCB_DESTROYSURFACEFN D3DCB_DestroySurface) {
-    IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
-
-    texture_cleanup(This, D3DCB_DestroySurface);
-    /* free the object */
-    HeapFree(GetProcessHeap(), 0, This);
-}
-
 static HRESULT WINAPI IWineD3DTextureImpl_GetLevelDesc(IWineD3DTexture *iface, UINT Level, WINED3DSURFACE_DESC* pDesc) {
     IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
@@ -553,6 +402,6 @@
 static HRESULT WINAPI IWineD3DTextureImpl_AddDirtyRect(IWineD3DTexture *iface, CONST RECT* pDirtyRect) {
     IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
-    This->baseTexture.dirty = TRUE;
-    This->baseTexture.srgbDirty = TRUE;
+    This->baseTexture.texture_rgb.dirty = TRUE;
+    This->baseTexture.texture_srgb.dirty = TRUE;
     TRACE("(%p) : dirtyfication of surface Level (0)\n", This);
     surface_add_dirty_rect(This->surfaces[0], pDirtyRect);
@@ -561,5 +410,5 @@
 }
 
-const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
+static const IWineD3DTextureVtbl IWineD3DTexture_Vtbl =
 {
     /* IUnknown */
@@ -591,5 +440,4 @@
     IWineD3DTextureImpl_IsCondNP2,
     /* IWineD3DTexture */
-    IWineD3DTextureImpl_Destroy,
     IWineD3DTextureImpl_GetLevelDesc,
     IWineD3DTextureImpl_GetSurfaceLevel,
@@ -598,2 +446,163 @@
     IWineD3DTextureImpl_AddDirtyRect
 };
+
+HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
+        IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+{
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
+    UINT pow2_width, pow2_height;
+    UINT tmp_w, tmp_h;
+    unsigned int i;
+    HRESULT hr;
+
+    /* TODO: It should only be possible to create textures for formats
+     * that are reported as supported. */
+    if (WINED3DFMT_UNKNOWN >= format)
+    {
+        WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    /* Non-power2 support. */
+    if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
+    {
+        pow2_width = width;
+        pow2_height = height;
+    }
+    else
+    {
+        /* Find the nearest pow2 match. */
+        pow2_width = pow2_height = 1;
+        while (pow2_width < width) pow2_width <<= 1;
+        while (pow2_height < height) pow2_height <<= 1;
+
+        if (pow2_width != width || pow2_height != height)
+        {
+            if (levels > 1)
+            {
+                WARN("Attempted to create a mipmapped np2 texture without unconditional np2 support.\n");
+                return WINED3DERR_INVALIDCALL;
+            }
+            levels = 1;
+        }
+    }
+
+    /* Calculate levels for mip mapping. */
+    if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
+    {
+        if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
+        {
+            WARN("No mipmap generation support, returning WINED3DERR_INVALIDCALL.\n");
+            return WINED3DERR_INVALIDCALL;
+        }
+
+        if (levels > 1)
+        {
+            WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning WINED3DERR_INVALIDCALL.\n");
+            return WINED3DERR_INVALIDCALL;
+        }
+
+        levels = 1;
+    }
+    else if (!levels)
+    {
+        levels = wined3d_log2i(max(width, height)) + 1;
+        TRACE("Calculated levels = %u.\n", levels);
+    }
+
+    texture->lpVtbl = &IWineD3DTexture_Vtbl;
+
+    hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_TEXTURE,
+            device, 0, usage, format_desc, pool, parent, parent_ops);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize basetexture, returning %#x.\n", hr);
+        return hr;
+    }
+
+    /* Precalculated scaling for 'faked' non power of two texture coords.
+     * Second also don't use ARB_TEXTURE_RECTANGLE in case the surface format is P8 and EXT_PALETTED_TEXTURE
+     * is used in combination with texture uploads (RTL_READTEX). The reason is that EXT_PALETTED_TEXTURE
+     * doesn't work in combination with ARB_TEXTURE_RECTANGLE. */
+    if (gl_info->supported[WINE_NORMALIZED_TEXRECT] && (width != pow2_width || height != pow2_height))
+    {
+        texture->baseTexture.pow2Matrix[0] = 1.0f;
+        texture->baseTexture.pow2Matrix[5] = 1.0f;
+        texture->baseTexture.pow2Matrix[10] = 1.0f;
+        texture->baseTexture.pow2Matrix[15] = 1.0f;
+        texture->target = GL_TEXTURE_2D;
+        texture->cond_np2 = TRUE;
+        texture->baseTexture.minMipLookup = minMipLookup_noFilter;
+    }
+    else if (gl_info->supported[ARB_TEXTURE_RECTANGLE] && (width != pow2_width || height != pow2_height)
+            && !(format_desc->format == WINED3DFMT_P8_UINT && gl_info->supported[EXT_PALETTED_TEXTURE]
+            && wined3d_settings.rendertargetlock_mode == RTL_READTEX))
+    {
+        if ((width != 1) || (height != 1)) texture->baseTexture.pow2Matrix_identity = FALSE;
+
+        texture->baseTexture.pow2Matrix[0] = (float)width;
+        texture->baseTexture.pow2Matrix[5] = (float)height;
+        texture->baseTexture.pow2Matrix[10] = 1.0f;
+        texture->baseTexture.pow2Matrix[15] = 1.0f;
+        texture->target = GL_TEXTURE_RECTANGLE_ARB;
+        texture->cond_np2 = TRUE;
+
+        if(texture->resource.format_desc->Flags & WINED3DFMT_FLAG_FILTERING)
+        {
+            texture->baseTexture.minMipLookup = minMipLookup_noMip;
+        }
+        else
+        {
+            texture->baseTexture.minMipLookup = minMipLookup_noFilter;
+        }
+    }
+    else
+    {
+        if ((width != pow2_width) || (height != pow2_height))
+        {
+            texture->baseTexture.pow2Matrix_identity = FALSE;
+            texture->baseTexture.pow2Matrix[0] = (((float)width) / ((float)pow2_width));
+            texture->baseTexture.pow2Matrix[5] = (((float)height) / ((float)pow2_height));
+        }
+        else
+        {
+            texture->baseTexture.pow2Matrix[0] = 1.0f;
+            texture->baseTexture.pow2Matrix[5] = 1.0f;
+        }
+
+        texture->baseTexture.pow2Matrix[10] = 1.0f;
+        texture->baseTexture.pow2Matrix[15] = 1.0f;
+        texture->target = GL_TEXTURE_2D;
+        texture->cond_np2 = FALSE;
+    }
+    TRACE("xf(%f) yf(%f)\n", texture->baseTexture.pow2Matrix[0], texture->baseTexture.pow2Matrix[5]);
+
+    /* Generate all the surfaces. */
+    tmp_w = width;
+    tmp_h = height;
+    for (i = 0; i < texture->baseTexture.levels; ++i)
+    {
+        /* Use the callback to create the texture surface. */
+        hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
+                usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]);
+        if (FAILED(hr) || ((IWineD3DSurfaceImpl *)texture->surfaces[i])->Flags & SFLAG_OVERSIZE)
+        {
+            FIXME("Failed to create surface %p, hr %#x\n", texture, hr);
+            texture->surfaces[i] = NULL;
+            texture_cleanup(texture);
+            return hr;
+        }
+
+        IWineD3DSurface_SetContainer(texture->surfaces[i], (IWineD3DBase *)texture);
+        TRACE("Created surface level %u @ %p.\n", i, texture->surfaces[i]);
+        surface_set_texture_target(texture->surfaces[i], texture->target);
+        /* Calculate the next mipmap level. */
+        tmp_w = max(1, tmp_w >> 1);
+        tmp_h = max(1, tmp_h >> 1);
+    }
+    texture->baseTexture.internal_preload = texture_internal_preload;
+
+    return WINED3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/utils.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/utils.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/utils.c	(revision 23571)
@@ -8,4 +8,5 @@
  * Copyright 2006-2008 Henri Verbeet
  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -59,87 +60,86 @@
 static const struct StaticPixelFormatDesc formats[] =
 {
-  /* WINED3DFORMAT               alphamask    redmask    greenmask    bluemask     bpp    depth  stencil   isFourcc */
-    {WINED3DFMT_UNKNOWN,            0x0,        0x0,        0x0,        0x0,        0,      0,      0,      FALSE},
-    /* FourCC formats, kept here to have WINED3DFMT_R8G8B8(=20) at position 20 */
-    {WINED3DFMT_UYVY,               0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
-    {WINED3DFMT_YUY2,               0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
-    {WINED3DFMT_YV12,               0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_DXT1,               0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_DXT2,               0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_DXT3,               0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_DXT4,               0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_DXT5,               0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_MULTI2_ARGB8,       0x0,        0x0,        0x0,        0x0,        1/*?*/, 0,      0,      TRUE },
-    {WINED3DFMT_G8R8_G8B8,          0x0,        0x0,        0x0,        0x0,        1/*?*/, 0,      0,      TRUE },
-    {WINED3DFMT_R8G8_B8G8,          0x0,        0x0,        0x0,        0x0,        1/*?*/, 0,      0,      TRUE },
+  /* WINED3DFORMAT                   alphamask    redmask    greenmask    bluemask     bpp    depth  stencil isFourcc */
+    {WINED3DFMT_UNKNOWN,                0x0,        0x0,        0x0,        0x0,        0,      0,      0,      FALSE},
+    /* FourCC formats */
+    {WINED3DFMT_UYVY,                   0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
+    {WINED3DFMT_YUY2,                   0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
+    {WINED3DFMT_YV12,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
+    {WINED3DFMT_DXT1,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
+    {WINED3DFMT_DXT2,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
+    {WINED3DFMT_DXT3,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
+    {WINED3DFMT_DXT4,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
+    {WINED3DFMT_DXT5,                   0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
+    {WINED3DFMT_MULTI2_ARGB8,           0x0,        0x0,        0x0,        0x0,        1/*?*/, 0,      0,      TRUE },
+    {WINED3DFMT_G8R8_G8B8,              0x0,        0x0,        0x0,        0x0,        1/*?*/, 0,      0,      TRUE },
+    {WINED3DFMT_R8G8_B8G8,              0x0,        0x0,        0x0,        0x0,        1/*?*/, 0,      0,      TRUE },
     /* IEEE formats */
-    {WINED3DFMT_R32_FLOAT,          0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R32G32_FLOAT,       0x0,        0x0,        0x0,        0x0,        8,      0,      0,      FALSE},
-    {WINED3DFMT_R32G32B32_FLOAT,    0x0,        0x0,        0x0,        0x0,        12,     0,      0,      FALSE},
-    {WINED3DFMT_R32G32B32A32_FLOAT, 0x1,        0x0,        0x0,        0x0,        16,     0,      0,      FALSE},
+    {WINED3DFMT_R32_FLOAT,              0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
+    {WINED3DFMT_R32G32_FLOAT,           0x0,        0x0,        0x0,        0x0,        8,      0,      0,      FALSE},
+    {WINED3DFMT_R32G32B32_FLOAT,        0x0,        0x0,        0x0,        0x0,        12,     0,      0,      FALSE},
+    {WINED3DFMT_R32G32B32A32_FLOAT,     0x1,        0x0,        0x0,        0x0,        16,     0,      0,      FALSE},
     /* Hmm? */
-    {WINED3DFMT_CxV8U8,             0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
+    {WINED3DFMT_R8G8_SNORM_Cx,          0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
     /* Float */
-    {WINED3DFMT_R16_FLOAT,          0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16_FLOAT,       0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16_SINT,        0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16B16A16_FLOAT, 0x1,        0x0,        0x0,        0x0,        8,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16B16A16_SINT,  0x1,        0x0,        0x0,        0x0,        8,      0,      0,      FALSE},
+    {WINED3DFMT_R16_FLOAT,              0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
+    {WINED3DFMT_R16G16_FLOAT,           0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
+    {WINED3DFMT_R16G16_SINT,            0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
+    {WINED3DFMT_R16G16B16A16_FLOAT,     0x1,        0x0,        0x0,        0x0,        8,      0,      0,      FALSE},
+    {WINED3DFMT_R16G16B16A16_SINT,      0x1,        0x0,        0x0,        0x0,        8,      0,      0,      FALSE},
     /* Palettized formats */
-    {WINED3DFMT_A8P8,               0x0000ff00, 0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
-    {WINED3DFMT_P8,                 0x0,        0x0,        0x0,        0x0,        1,      0,      0,      FALSE},
+    {WINED3DFMT_P8_UINT_A8_UNORM,       0x0000ff00, 0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
+    {WINED3DFMT_P8_UINT,                0x0,        0x0,        0x0,        0x0,        1,      0,      0,      FALSE},
     /* Standard ARGB formats. */
-    {WINED3DFMT_R8G8B8,             0x0,        0x00ff0000, 0x0000ff00, 0x000000ff, 3,      0,      0,      FALSE},
-    {WINED3DFMT_A8R8G8B8,           0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, 4,      0,      0,      FALSE},
-    {WINED3DFMT_X8R8G8B8,           0x0,        0x00ff0000, 0x0000ff00, 0x000000ff, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R5G6B5,             0x0,        0x0000f800, 0x000007e0, 0x0000001f, 2,      0,      0,      FALSE},
-    {WINED3DFMT_X1R5G5B5,           0x0,        0x00007c00, 0x000003e0, 0x0000001f, 2,      0,      0,      FALSE},
-    {WINED3DFMT_A1R5G5B5,           0x00008000, 0x00007c00, 0x000003e0, 0x0000001f, 2,      0,      0,      FALSE},
-    {WINED3DFMT_A4R4G4B4,           0x0000f000, 0x00000f00, 0x000000f0, 0x0000000f, 2,      0,      0,      FALSE},
-    {WINED3DFMT_R3G3B2,             0x0,        0x000000e0, 0x0000001c, 0x00000003, 1,      0,      0,      FALSE},
-    {WINED3DFMT_A8_UNORM,           0x000000ff, 0x0,        0x0,        0x0,        1,      0,      0,      FALSE},
-    {WINED3DFMT_A8R3G3B2,           0x0000ff00, 0x000000e0, 0x0000001c, 0x00000003, 2,      0,      0,      FALSE},
-    {WINED3DFMT_X4R4G4B4,           0x0,        0x00000f00, 0x000000f0, 0x0000000f, 2,      0,      0,      FALSE},
-    {WINED3DFMT_R10G10B10A2_UNORM,  0xc0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R10G10B10A2_UINT,   0xc0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R10G10B10A2_SNORM,  0xc0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R8G8B8A8_UNORM,     0xff000000, 0x000000ff, 0x0000ff00, 0x00ff0000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R8G8B8A8_UINT,      0xff000000, 0x000000ff, 0x0000ff00, 0x00ff0000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_X8B8G8R8,           0x0,        0x000000ff, 0x0000ff00, 0x00ff0000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16_UNORM,       0x0,        0x0000ffff, 0xffff0000, 0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_A2R10G10B10,        0xc0000000, 0x3ff00000, 0x000ffc00, 0x000003ff, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16B16A16_UNORM, 0x1,        0x0000ffff, 0xffff0000, 0x0,        8,      0,      0,      FALSE},
+    {WINED3DFMT_B8G8R8_UNORM,           0x0,        0x00ff0000, 0x0000ff00, 0x000000ff, 3,      0,      0,      FALSE},
+    {WINED3DFMT_B8G8R8A8_UNORM,         0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, 4,      0,      0,      FALSE},
+    {WINED3DFMT_B8G8R8X8_UNORM,         0x0,        0x00ff0000, 0x0000ff00, 0x000000ff, 4,      0,      0,      FALSE},
+    {WINED3DFMT_B5G6R5_UNORM,           0x0,        0x0000f800, 0x000007e0, 0x0000001f, 2,      0,      0,      FALSE},
+    {WINED3DFMT_B5G5R5X1_UNORM,         0x0,        0x00007c00, 0x000003e0, 0x0000001f, 2,      0,      0,      FALSE},
+    {WINED3DFMT_B5G5R5A1_UNORM,         0x00008000, 0x00007c00, 0x000003e0, 0x0000001f, 2,      0,      0,      FALSE},
+    {WINED3DFMT_B4G4R4A4_UNORM,         0x0000f000, 0x00000f00, 0x000000f0, 0x0000000f, 2,      0,      0,      FALSE},
+    {WINED3DFMT_B2G3R3_UNORM,           0x0,        0x000000e0, 0x0000001c, 0x00000003, 1,      0,      0,      FALSE},
+    {WINED3DFMT_A8_UNORM,               0x000000ff, 0x0,        0x0,        0x0,        1,      0,      0,      FALSE},
+    {WINED3DFMT_B2G3R3A8_UNORM,         0x0000ff00, 0x000000e0, 0x0000001c, 0x00000003, 2,      0,      0,      FALSE},
+    {WINED3DFMT_B4G4R4X4_UNORM,         0x0,        0x00000f00, 0x000000f0, 0x0000000f, 2,      0,      0,      FALSE},
+    {WINED3DFMT_R10G10B10A2_UNORM,      0xc0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0,      FALSE},
+    {WINED3DFMT_R10G10B10A2_UINT,       0xc0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0,      FALSE},
+    {WINED3DFMT_R10G10B10A2_SNORM,      0xc0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0,      FALSE},
+    {WINED3DFMT_R8G8B8A8_UNORM,         0xff000000, 0x000000ff, 0x0000ff00, 0x00ff0000, 4,      0,      0,      FALSE},
+    {WINED3DFMT_R8G8B8A8_UINT,          0xff000000, 0x000000ff, 0x0000ff00, 0x00ff0000, 4,      0,      0,      FALSE},
+    {WINED3DFMT_R8G8B8X8_UNORM,         0x0,        0x000000ff, 0x0000ff00, 0x00ff0000, 4,      0,      0,      FALSE},
+    {WINED3DFMT_R16G16_UNORM,           0x0,        0x0000ffff, 0xffff0000, 0x0,        4,      0,      0,      FALSE},
+    {WINED3DFMT_B10G10R10A2_UNORM,      0xc0000000, 0x3ff00000, 0x000ffc00, 0x000003ff, 4,      0,      0,      FALSE},
+    {WINED3DFMT_R16G16B16A16_UNORM,     0x1,        0x0000ffff, 0xffff0000, 0x0,        8,      0,      0,      FALSE},
     /* Luminance */
-    {WINED3DFMT_L8,                 0x0,        0x0,        0x0,        0x0,        1,      0,      0,      FALSE},
-    {WINED3DFMT_A8L8,               0x0000ff00, 0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
-    {WINED3DFMT_A4L4,               0x000000f0, 0x0,        0x0,        0x0,        1,      0,      0,      FALSE},
+    {WINED3DFMT_L8_UNORM,               0x0,        0x0,        0x0,        0x0,        1,      0,      0,      FALSE},
+    {WINED3DFMT_L8A8_UNORM,             0x0000ff00, 0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
+    {WINED3DFMT_L4A4_UNORM,             0x000000f0, 0x0,        0x0,        0x0,        1,      0,      0,      FALSE},
+    {WINED3DFMT_L16_UNORM,              0x0,        0x0,        0x0,        0x0,        2,      16,     0,      FALSE},
     /* Bump mapping stuff */
-    {WINED3DFMT_R8G8_SNORM,         0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
-    {WINED3DFMT_L6V5U5,             0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
-    {WINED3DFMT_X8L8V8U8,           0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R8G8B8A8_SNORM,     0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16_SNORM,       0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_W11V11U10,          0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_A2W10V10U10,        0xb0000000, 0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
+    {WINED3DFMT_R8G8_SNORM,             0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
+    {WINED3DFMT_R5G5_SNORM_L6_UNORM,    0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
+    {WINED3DFMT_R8G8_SNORM_L8X8_UNORM,  0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
+    {WINED3DFMT_R8G8B8A8_SNORM,         0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
+    {WINED3DFMT_R16G16_SNORM,           0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
+    {WINED3DFMT_R10G11B11_SNORM,        0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
+    {WINED3DFMT_R10G10B10_SNORM_A2_UNORM,0xb0000000,0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
     /* Depth stencil formats */
-    {WINED3DFMT_D16_LOCKABLE,       0x0,        0x0,        0x0,        0x0,        2,      16,     0,      FALSE},
-    {WINED3DFMT_D32,                0x0,        0x0,        0x0,        0x0,        4,      32,     0,      FALSE},
-    {WINED3DFMT_D15S1,              0x0,        0x0,        0x0,        0x0,        2,      15,     1,      FALSE},
-    {WINED3DFMT_D24S8,              0x0,        0x0,        0x0,        0x0,        4,      24,     8,      FALSE},
-    {WINED3DFMT_D24X8,              0x0,        0x0,        0x0,        0x0,        4,      24,     0,      FALSE},
-    {WINED3DFMT_D24X4S4,            0x0,        0x0,        0x0,        0x0,        4,      24,     4,      FALSE},
-    {WINED3DFMT_D16_UNORM,          0x0,        0x0,        0x0,        0x0,        2,      16,     0,      FALSE},
-    {WINED3DFMT_L16,                0x0,        0x0,        0x0,        0x0,        2,      16,     0,      FALSE},
-    {WINED3DFMT_D32F_LOCKABLE,      0x0,        0x0,        0x0,        0x0,        4,      32,     0,      FALSE},
-    {WINED3DFMT_D24FS8,             0x0,        0x0,        0x0,        0x0,        4,      24,     8,      FALSE},
-    /* Is this a vertex buffer? */
-    {WINED3DFMT_VERTEXDATA,         0x0,        0x0,        0x0,        0x0,        0,      0,      0,      FALSE},
-    {WINED3DFMT_R16_UINT,           0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
-    {WINED3DFMT_R32_UINT,           0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
-    {WINED3DFMT_R16G16B16A16_SNORM, 0x0,        0x0,        0x0,        0x0,        8,      0,      0,      FALSE},
+    {WINED3DFMT_D16_LOCKABLE,           0x0,        0x0,        0x0,        0x0,        2,      16,     0,      FALSE},
+    {WINED3DFMT_D32_UNORM,              0x0,        0x0,        0x0,        0x0,        4,      32,     0,      FALSE},
+    {WINED3DFMT_S1_UINT_D15_UNORM,      0x0,        0x0,        0x0,        0x0,        2,      15,     1,      FALSE},
+    {WINED3DFMT_S8_UINT_D24_UNORM,      0x0,        0x0,        0x0,        0x0,        4,      24,     8,      FALSE},
+    {WINED3DFMT_X8D24_UNORM,            0x0,        0x0,        0x0,        0x0,        4,      24,     0,      FALSE},
+    {WINED3DFMT_S4X4_UINT_D24_UNORM,    0x0,        0x0,        0x0,        0x0,        4,      24,     4,      FALSE},
+    {WINED3DFMT_D16_UNORM,              0x0,        0x0,        0x0,        0x0,        2,      16,     0,      FALSE},
+    {WINED3DFMT_D32_FLOAT,              0x0,        0x0,        0x0,        0x0,        4,      32,     0,      FALSE},
+    {WINED3DFMT_S8_UINT_D24_FLOAT,      0x0,        0x0,        0x0,        0x0,        4,      24,     8,      FALSE},
+    {WINED3DFMT_VERTEXDATA,             0x0,        0x0,        0x0,        0x0,        0,      0,      0,      FALSE},
+    {WINED3DFMT_R16_UINT,               0x0,        0x0,        0x0,        0x0,        2,      0,      0,      FALSE},
+    {WINED3DFMT_R32_UINT,               0x0,        0x0,        0x0,        0x0,        4,      0,      0,      FALSE},
+    {WINED3DFMT_R16G16B16A16_SNORM,     0x0,        0x0,        0x0,        0x0,        8,      0,      0,      FALSE},
     /* Vendor-specific formats */
-    {WINED3DFMT_ATI2N,              0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
-    {WINED3DFMT_NVHU,               0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
-    {WINED3DFMT_NVHS,               0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
+    {WINED3DFMT_ATI2N,                  0x0,        0x0,        0x0,        0x0,        1,      0,      0,      TRUE },
+    {WINED3DFMT_NVHU,                   0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
+    {WINED3DFMT_NVHS,                   0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
 };
 
@@ -179,5 +179,5 @@
     {WINED3DFMT_R32G32B32_FLOAT,    WINED3D_FFP_EMIT_FLOAT3,    3, GL_FLOAT,          3, GL_FALSE, sizeof(float)},
     {WINED3DFMT_R32G32B32A32_FLOAT, WINED3D_FFP_EMIT_FLOAT4,    4, GL_FLOAT,          4, GL_FALSE, sizeof(float)},
-    {WINED3DFMT_A8R8G8B8,           WINED3D_FFP_EMIT_D3DCOLOR,  4, GL_UNSIGNED_BYTE,  4, GL_TRUE,  sizeof(BYTE)},
+    {WINED3DFMT_B8G8R8A8_UNORM,     WINED3D_FFP_EMIT_D3DCOLOR,  4, GL_UNSIGNED_BYTE,  4, GL_TRUE,  sizeof(BYTE)},
     {WINED3DFMT_R8G8B8A8_UINT,      WINED3D_FFP_EMIT_UBYTE4,    4, GL_UNSIGNED_BYTE,  4, GL_FALSE, sizeof(BYTE)},
     {WINED3DFMT_R16G16_SINT,        WINED3D_FFP_EMIT_SHORT2,    2, GL_SHORT,          2, GL_FALSE, sizeof(short int)},
@@ -208,6 +208,6 @@
  */
 static const GlPixelFormatDescTemplate gl_formats_template[] = {
-    /* WINED3DFORMAT                internal                          srgbInternal                            rtInternal
-            format                  type
+    /* WINED3DFORMAT                    internal                          srgbInternal                       rtInternal
+            format                      type
             flags
             extension */
@@ -219,274 +219,293 @@
      * endian machine
      */
-    {WINED3DFMT_UYVY,               GL_LUMINANCE_ALPHA,               GL_LUMINANCE_ALPHA,                     0,
-            GL_LUMINANCE_ALPHA,     GL_UNSIGNED_BYTE,
+    {WINED3DFMT_UYVY,                   GL_LUMINANCE_ALPHA,               GL_LUMINANCE_ALPHA,                     0,
+            GL_LUMINANCE_ALPHA,         GL_UNSIGNED_BYTE,
             WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_UYVY,               GL_RGB,                           GL_RGB,                                 0,
-            GL_YCBCR_422_APPLE,     UNSIGNED_SHORT_8_8_APPLE,
+    {WINED3DFMT_UYVY,                   GL_RGB,                           GL_RGB,                                 0,
+            GL_YCBCR_422_APPLE,         UNSIGNED_SHORT_8_8_APPLE,
             WINED3DFMT_FLAG_FILTERING,
             APPLE_YCBCR_422},
-    {WINED3DFMT_YUY2,               GL_LUMINANCE_ALPHA,               GL_LUMINANCE_ALPHA,                     0,
-            GL_LUMINANCE_ALPHA,     GL_UNSIGNED_BYTE,
+    {WINED3DFMT_YUY2,                   GL_LUMINANCE_ALPHA,               GL_LUMINANCE_ALPHA,                     0,
+            GL_LUMINANCE_ALPHA,         GL_UNSIGNED_BYTE,
             WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_YUY2,               GL_RGB,                           GL_RGB,                                 0,
-            GL_YCBCR_422_APPLE, UNSIGNED_SHORT_8_8_REV_APPLE,
+    {WINED3DFMT_YUY2,                   GL_RGB,                           GL_RGB,                                 0,
+            GL_YCBCR_422_APPLE,         UNSIGNED_SHORT_8_8_REV_APPLE,
             WINED3DFMT_FLAG_FILTERING,
             APPLE_YCBCR_422},
-    {WINED3DFMT_YV12,               GL_ALPHA,                         GL_ALPHA,                               0,
-            GL_ALPHA,               GL_UNSIGNED_BYTE,
+    {WINED3DFMT_YV12,                   GL_ALPHA,                         GL_ALPHA,                               0,
+            GL_ALPHA,                   GL_UNSIGNED_BYTE,
             WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_DXT1,               GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 0,
-            GL_RGBA,                GL_UNSIGNED_BYTE,
+    {WINED3DFMT_DXT1,                   GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 0,
+            GL_RGBA,                    GL_UNSIGNED_BYTE,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             EXT_TEXTURE_COMPRESSION_S3TC},
-    {WINED3DFMT_DXT2,               GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0,
-            GL_RGBA,                GL_UNSIGNED_BYTE,
+    {WINED3DFMT_DXT2,                   GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0,
+            GL_RGBA,                    GL_UNSIGNED_BYTE,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             EXT_TEXTURE_COMPRESSION_S3TC},
-    {WINED3DFMT_DXT3,               GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0,
-            GL_RGBA,                GL_UNSIGNED_BYTE,
+    {WINED3DFMT_DXT3,                   GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0,
+            GL_RGBA,                    GL_UNSIGNED_BYTE,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             EXT_TEXTURE_COMPRESSION_S3TC},
-    {WINED3DFMT_DXT4,               GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0,
-            GL_RGBA,                GL_UNSIGNED_BYTE,
+    {WINED3DFMT_DXT4,                   GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0,
+            GL_RGBA,                    GL_UNSIGNED_BYTE,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             EXT_TEXTURE_COMPRESSION_S3TC},
-    {WINED3DFMT_DXT5,               GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0,
-            GL_RGBA,                GL_UNSIGNED_BYTE,
+    {WINED3DFMT_DXT5,                   GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0,
+            GL_RGBA,                    GL_UNSIGNED_BYTE,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             EXT_TEXTURE_COMPRESSION_S3TC},
     /* IEEE formats */
-    {WINED3DFMT_R32_FLOAT,          GL_RGB32F_ARB,                    GL_RGB32F_ARB,                          0,
-            GL_RED,                 GL_FLOAT,
+    {WINED3DFMT_R32_FLOAT,              GL_RGB32F_ARB,                    GL_RGB32F_ARB,                          0,
+            GL_RED,                     GL_FLOAT,
             WINED3DFMT_FLAG_RENDERTARGET,
             ARB_TEXTURE_FLOAT},
-    {WINED3DFMT_R32_FLOAT,          GL_R32F,                          GL_R32F,                                0,
-            GL_RED,                 GL_FLOAT,
+    {WINED3DFMT_R32_FLOAT,              GL_R32F,                          GL_R32F,                                0,
+            GL_RED,                     GL_FLOAT,
             WINED3DFMT_FLAG_RENDERTARGET,
             ARB_TEXTURE_RG},
-    {WINED3DFMT_R32G32_FLOAT,       GL_RGB32F_ARB,                    GL_RGB32F_ARB,                          0,
-            GL_RGB,                 GL_FLOAT,
+    {WINED3DFMT_R32G32_FLOAT,           GL_RGB32F_ARB,                    GL_RGB32F_ARB,                          0,
+            GL_RGB,                     GL_FLOAT,
             WINED3DFMT_FLAG_RENDERTARGET,
             ARB_TEXTURE_FLOAT},
-    {WINED3DFMT_R32G32_FLOAT,       GL_RG32F,                         GL_RG32F,                               0,
-            GL_RG,                  GL_FLOAT,
+    {WINED3DFMT_R32G32_FLOAT,           GL_RG32F,                         GL_RG32F,                               0,
+            GL_RG,                      GL_FLOAT,
             WINED3DFMT_FLAG_RENDERTARGET,
             ARB_TEXTURE_RG},
-    {WINED3DFMT_R32G32B32A32_FLOAT, GL_RGBA32F_ARB,                   GL_RGBA32F_ARB,                         0,
-            GL_RGBA,                GL_FLOAT,
+    {WINED3DFMT_R32G32B32A32_FLOAT,     GL_RGBA32F_ARB,                   GL_RGBA32F_ARB,                         0,
+            GL_RGBA,                    GL_FLOAT,
             WINED3DFMT_FLAG_RENDERTARGET,
             ARB_TEXTURE_FLOAT},
     /* Float */
-    {WINED3DFMT_R16_FLOAT,          GL_RGB16F_ARB,                    GL_RGB16F_ARB,                          0,
-            GL_RED,                 GL_HALF_FLOAT_ARB,
+    {WINED3DFMT_R16_FLOAT,              GL_RGB16F_ARB,                    GL_RGB16F_ARB,                          0,
+            GL_RED,                     GL_HALF_FLOAT_ARB,
             WINED3DFMT_FLAG_RENDERTARGET,
             ARB_TEXTURE_FLOAT},
-    {WINED3DFMT_R16_FLOAT,          GL_R16F,                          GL_R16F,                                0,
-            GL_RED,                 GL_HALF_FLOAT_ARB,
+    {WINED3DFMT_R16_FLOAT,              GL_R16F,                          GL_R16F,                                0,
+            GL_RED,                     GL_HALF_FLOAT_ARB,
             WINED3DFMT_FLAG_RENDERTARGET,
             ARB_TEXTURE_RG},
-    {WINED3DFMT_R16G16_FLOAT,       GL_RGB16F_ARB,                    GL_RGB16F_ARB,                          0,
-            GL_RGB,                 GL_HALF_FLOAT_ARB,
+    {WINED3DFMT_R16G16_FLOAT,           GL_RGB16F_ARB,                    GL_RGB16F_ARB,                          0,
+            GL_RGB,                     GL_HALF_FLOAT_ARB,
             WINED3DFMT_FLAG_RENDERTARGET,
             ARB_TEXTURE_FLOAT},
-    {WINED3DFMT_R16G16_FLOAT,       GL_RG16F,                         GL_RG16F,                               0,
-            GL_RG,                  GL_HALF_FLOAT_ARB,
+    {WINED3DFMT_R16G16_FLOAT,           GL_RG16F,                         GL_RG16F,                               0,
+            GL_RG,                      GL_HALF_FLOAT_ARB,
             WINED3DFMT_FLAG_RENDERTARGET,
             ARB_TEXTURE_RG},
-    {WINED3DFMT_R16G16B16A16_FLOAT, GL_RGBA16F_ARB,                   GL_RGBA16F_ARB,                         0,
-            GL_RGBA,                GL_HALF_FLOAT_ARB,
+    {WINED3DFMT_R16G16B16A16_FLOAT,     GL_RGBA16F_ARB,                   GL_RGBA16F_ARB,                         0,
+            GL_RGBA,                    GL_HALF_FLOAT_ARB,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_RENDERTARGET,
             ARB_TEXTURE_FLOAT},
     /* Palettized formats */
-    {WINED3DFMT_P8,                 GL_RGBA,                          GL_RGBA,                                0,
-            GL_RGBA,                GL_UNSIGNED_BYTE,
-            0,
+    {WINED3DFMT_P8_UINT,                GL_RGBA,                          GL_RGBA,                                0,
+            GL_RGBA,                    GL_UNSIGNED_BYTE,
+            WINED3DFMT_FLAG_GETDC,
             ARB_FRAGMENT_PROGRAM},
-    {WINED3DFMT_P8,                 GL_COLOR_INDEX8_EXT,              GL_COLOR_INDEX8_EXT,                    0,
-            GL_COLOR_INDEX,         GL_UNSIGNED_BYTE,
-            0,
+    {WINED3DFMT_P8_UINT,                GL_COLOR_INDEX8_EXT,              GL_COLOR_INDEX8_EXT,                    0,
+            GL_COLOR_INDEX,             GL_UNSIGNED_BYTE,
+            WINED3DFMT_FLAG_GETDC,
             EXT_PALETTED_TEXTURE},
     /* Standard ARGB formats */
-    {WINED3DFMT_R8G8B8,             GL_RGB8,                          GL_RGB8,                                0,
-            GL_BGR,                 GL_UNSIGNED_BYTE,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET,
+    {WINED3DFMT_B8G8R8_UNORM,           GL_RGB8,                          GL_RGB8,                                0,
+            GL_BGR,                     GL_UNSIGNED_BYTE,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET |
+            WINED3DFMT_FLAG_GETDC,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_A8R8G8B8,           GL_RGBA8,                         GL_SRGB8_ALPHA8_EXT,                    0,
-            GL_BGRA,                GL_UNSIGNED_INT_8_8_8_8_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET,
+    {WINED3DFMT_B8G8R8A8_UNORM,         GL_RGBA8,                         GL_SRGB8_ALPHA8_EXT,                    0,
+            GL_BGRA,                    GL_UNSIGNED_INT_8_8_8_8_REV,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET |
+            WINED3DFMT_FLAG_GETDC,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_X8R8G8B8,           GL_RGB8,                          GL_SRGB8_EXT,                           0,
-            GL_BGRA,                GL_UNSIGNED_INT_8_8_8_8_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET,
+    {WINED3DFMT_B8G8R8X8_UNORM,         GL_RGB8,                          GL_SRGB8_EXT,                           0,
+            GL_BGRA,                    GL_UNSIGNED_INT_8_8_8_8_REV,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET |
+            WINED3DFMT_FLAG_GETDC,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_R5G6B5,             GL_RGB5,                          GL_RGB5,                                GL_RGB8,
-            GL_RGB,                 GL_UNSIGNED_SHORT_5_6_5,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET,
+    {WINED3DFMT_B5G6R5_UNORM,           GL_RGB5,                          GL_RGB5,                          GL_RGB8,
+            GL_RGB,                     GL_UNSIGNED_SHORT_5_6_5,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET |
+            WINED3DFMT_FLAG_GETDC,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_X1R5G5B5,           GL_RGB5,                          GL_RGB5_A1,                             0,
-            GL_BGRA,                GL_UNSIGNED_SHORT_1_5_5_5_REV,
+    {WINED3DFMT_B5G5R5X1_UNORM,         GL_RGB5,                          GL_RGB5_A1,                             0,
+            GL_BGRA,                    GL_UNSIGNED_SHORT_1_5_5_5_REV,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING |
+            WINED3DFMT_FLAG_GETDC,
+            WINED3D_GL_EXT_NONE},
+    {WINED3DFMT_B5G5R5A1_UNORM,         GL_RGB5_A1,                       GL_RGB5_A1,                             0,
+            GL_BGRA,                    GL_UNSIGNED_SHORT_1_5_5_5_REV,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING |
+            WINED3DFMT_FLAG_GETDC,
+            WINED3D_GL_EXT_NONE},
+    {WINED3DFMT_B4G4R4A4_UNORM,         GL_RGBA4,                         GL_SRGB8_ALPHA8_EXT,                    0,
+            GL_BGRA,                    GL_UNSIGNED_SHORT_4_4_4_4_REV,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING |
+            WINED3DFMT_FLAG_GETDC,
+            WINED3D_GL_EXT_NONE},
+    {WINED3DFMT_B2G3R3_UNORM,           GL_R3_G3_B2,                      GL_R3_G3_B2,                            0,
+            GL_RGB,                     GL_UNSIGNED_BYTE_3_3_2,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING,
+            WINED3D_GL_EXT_NONE},
+    {WINED3DFMT_A8_UNORM,               GL_ALPHA8,                        GL_ALPHA8,                              0,
+            GL_ALPHA,                   GL_UNSIGNED_BYTE,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING,
+            WINED3D_GL_EXT_NONE},
+    {WINED3DFMT_B4G4R4X4_UNORM,         GL_RGB4,                          GL_RGB4,                                0,
+            GL_BGRA,                    GL_UNSIGNED_SHORT_4_4_4_4_REV,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_GETDC,
+            WINED3D_GL_EXT_NONE},
+    {WINED3DFMT_R10G10B10A2_UNORM,      GL_RGB10_A2,                      GL_RGB10_A2,                            0,
+            GL_RGBA,                    GL_UNSIGNED_INT_2_10_10_10_REV,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_A1R5G5B5,           GL_RGB5_A1,                       GL_RGB5_A1,                             0,
-            GL_BGRA,                GL_UNSIGNED_SHORT_1_5_5_5_REV,
+    {WINED3DFMT_R8G8B8A8_UNORM,         GL_RGBA8,                         GL_RGBA8,                               0,
+            GL_RGBA,                    GL_UNSIGNED_INT_8_8_8_8_REV,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_GETDC,
+            WINED3D_GL_EXT_NONE},
+    {WINED3DFMT_R8G8B8X8_UNORM,         GL_RGB8,                          GL_RGB8,                                0,
+            GL_RGBA,                    GL_UNSIGNED_INT_8_8_8_8_REV,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_GETDC,
+            WINED3D_GL_EXT_NONE},
+    {WINED3DFMT_R16G16_UNORM,           GL_RGB16_EXT,                     GL_RGB16_EXT,               GL_RGBA16_EXT,
+            GL_RGB,                     GL_UNSIGNED_SHORT,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_A4R4G4B4,           GL_RGBA4,                         GL_SRGB8_ALPHA8_EXT,                    0,
-            GL_BGRA,                GL_UNSIGNED_SHORT_4_4_4_4_REV,
+    {WINED3DFMT_B10G10R10A2_UNORM,      GL_RGB10_A2,                      GL_RGB10_A2,                            0,
+            GL_BGRA,                    GL_UNSIGNED_INT_2_10_10_10_REV,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_R3G3B2,             GL_R3_G3_B2,                      GL_R3_G3_B2,                            0,
-            GL_RGB,                 GL_UNSIGNED_BYTE_3_3_2,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING,
-            WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_A8_UNORM,           GL_ALPHA8,                        GL_ALPHA8,                              0,
-            GL_ALPHA,               GL_UNSIGNED_BYTE,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING,
-            WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_X4R4G4B4,           GL_RGB4,                          GL_RGB4,                                0,
-            GL_BGRA,                GL_UNSIGNED_SHORT_4_4_4_4_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
-            WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_R10G10B10A2_UNORM,  GL_RGB10_A2,                      GL_RGB10_A2,                            0,
-            GL_RGBA,                GL_UNSIGNED_INT_2_10_10_10_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
-            WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_R8G8B8A8_UNORM,     GL_RGBA8,                         GL_RGBA8,                               0,
-            GL_RGBA,                GL_UNSIGNED_INT_8_8_8_8_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
-            WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_X8B8G8R8,           GL_RGB8,                          GL_RGB8,                                0,
-            GL_RGBA,                GL_UNSIGNED_INT_8_8_8_8_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
-            WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_R16G16_UNORM,       GL_RGB16_EXT,                     GL_RGB16_EXT,                           GL_RGBA16_EXT,
-            GL_RGB,                 GL_UNSIGNED_SHORT,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
-            WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_A2R10G10B10,        GL_RGB10_A2,                      GL_RGB10_A2,                            0,
-            GL_BGRA,                GL_UNSIGNED_INT_2_10_10_10_REV,
-            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
-            WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_R16G16B16A16_UNORM, GL_RGBA16_EXT,                    GL_RGBA16_EXT,                          0,
-            GL_RGBA,                GL_UNSIGNED_SHORT,
+    {WINED3DFMT_R16G16B16A16_UNORM,     GL_RGBA16_EXT,                    GL_RGBA16_EXT,                          0,
+            GL_RGBA,                    GL_UNSIGNED_SHORT,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_RENDERTARGET,
             WINED3D_GL_EXT_NONE},
     /* Luminance */
-    {WINED3DFMT_L8,                 GL_LUMINANCE8,                    GL_SLUMINANCE8_EXT,                     0,
-            GL_LUMINANCE,           GL_UNSIGNED_BYTE,
+    {WINED3DFMT_L8_UNORM,               GL_LUMINANCE8,                    GL_SLUMINANCE8_EXT,                     0,
+            GL_LUMINANCE,               GL_UNSIGNED_BYTE,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_A8L8,               GL_LUMINANCE8_ALPHA8,             GL_SLUMINANCE8_ALPHA8_EXT,              0,
-            GL_LUMINANCE_ALPHA,     GL_UNSIGNED_BYTE,
+    {WINED3DFMT_L8A8_UNORM,             GL_LUMINANCE8_ALPHA8,             GL_SLUMINANCE8_ALPHA8_EXT,              0,
+            GL_LUMINANCE_ALPHA,         GL_UNSIGNED_BYTE,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_A4L4,               GL_LUMINANCE4_ALPHA4,             GL_LUMINANCE4_ALPHA4,                   0,
-            GL_LUMINANCE_ALPHA,     GL_UNSIGNED_BYTE,
+    {WINED3DFMT_L4A4_UNORM,             GL_LUMINANCE4_ALPHA4,             GL_LUMINANCE4_ALPHA4,                   0,
+            GL_LUMINANCE_ALPHA,         GL_UNSIGNED_BYTE,
             0,
             WINED3D_GL_EXT_NONE},
     /* Bump mapping stuff */
-    {WINED3DFMT_R8G8_SNORM,         GL_RGB8,                          GL_RGB8,                                0,
-            GL_BGR,                 GL_UNSIGNED_BYTE,
+    {WINED3DFMT_R8G8_SNORM,             GL_RGB8,                          GL_RGB8,                                0,
+            GL_BGR,                     GL_UNSIGNED_BYTE,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_R8G8_SNORM,         GL_DSDT8_NV,                      GL_DSDT8_NV,                            0,
-            GL_DSDT_NV,             GL_BYTE,
+    {WINED3DFMT_R8G8_SNORM,             GL_DSDT8_NV,                      GL_DSDT8_NV,                            0,
+            GL_DSDT_NV,                 GL_BYTE,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             NV_TEXTURE_SHADER},
-    {WINED3DFMT_L6V5U5,             GL_RGB5,                          GL_RGB5,                                0,
-            GL_RGB,                 GL_UNSIGNED_SHORT_5_6_5,
+    {WINED3DFMT_R5G5_SNORM_L6_UNORM,    GL_RGB5,                          GL_RGB5,                                0,
+            GL_RGB,                     GL_UNSIGNED_SHORT_5_6_5,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_L6V5U5,             GL_DSDT8_MAG8_NV,                 GL_DSDT8_MAG8_NV,                       0,
-            GL_DSDT_MAG_NV,         GL_BYTE,
+    {WINED3DFMT_R5G5_SNORM_L6_UNORM,    GL_DSDT8_MAG8_NV,                 GL_DSDT8_MAG8_NV,                       0,
+            GL_DSDT_MAG_NV,             GL_BYTE,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             NV_TEXTURE_SHADER},
-    {WINED3DFMT_X8L8V8U8,           GL_RGB8,                          GL_RGB8,                                0,
-            GL_BGRA,                GL_UNSIGNED_INT_8_8_8_8_REV,
+    {WINED3DFMT_R8G8_SNORM_L8X8_UNORM,  GL_RGB8,                          GL_RGB8,                                0,
+            GL_BGRA,                    GL_UNSIGNED_INT_8_8_8_8_REV,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_X8L8V8U8,           GL_DSDT8_MAG8_INTENSITY8_NV,      GL_DSDT8_MAG8_INTENSITY8_NV,            0,
-            GL_DSDT_MAG_VIB_NV,     GL_UNSIGNED_INT_8_8_S8_S8_REV_NV,
+    {WINED3DFMT_R8G8_SNORM_L8X8_UNORM,  GL_DSDT8_MAG8_INTENSITY8_NV,      GL_DSDT8_MAG8_INTENSITY8_NV,            0,
+            GL_DSDT_MAG_VIB_NV,         GL_UNSIGNED_INT_8_8_S8_S8_REV_NV,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             NV_TEXTURE_SHADER},
-    {WINED3DFMT_R8G8B8A8_SNORM,     GL_RGBA8,                         GL_RGBA8,                               0,
-            GL_BGRA,                GL_UNSIGNED_BYTE,
+    {WINED3DFMT_R8G8B8A8_SNORM,         GL_RGBA8,                         GL_RGBA8,                               0,
+            GL_BGRA,                    GL_UNSIGNED_BYTE,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_R8G8B8A8_SNORM,     GL_SIGNED_RGBA8_NV,               GL_SIGNED_RGBA8_NV,                     0,
-            GL_RGBA,                GL_BYTE,
+    {WINED3DFMT_R8G8B8A8_SNORM,         GL_SIGNED_RGBA8_NV,               GL_SIGNED_RGBA8_NV,                     0,
+            GL_RGBA,                    GL_BYTE,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             NV_TEXTURE_SHADER},
-    {WINED3DFMT_R16G16_SNORM,       GL_RGB16_EXT,                     GL_RGB16_EXT,                           0,
-            GL_BGR,                 GL_UNSIGNED_SHORT,
+    {WINED3DFMT_R16G16_SNORM,           GL_RGB16_EXT,                     GL_RGB16_EXT,                           0,
+            GL_BGR,                     GL_UNSIGNED_SHORT,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_R16G16_SNORM,       GL_SIGNED_HILO16_NV,              GL_SIGNED_HILO16_NV,                    0,
-            GL_HILO_NV,             GL_SHORT,
+    {WINED3DFMT_R16G16_SNORM,           GL_SIGNED_HILO16_NV,              GL_SIGNED_HILO16_NV,                    0,
+            GL_HILO_NV,                 GL_SHORT,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             NV_TEXTURE_SHADER},
     /* Depth stencil formats */
-    {WINED3DFMT_D16_LOCKABLE,       GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
-            GL_DEPTH_COMPONENT,     GL_UNSIGNED_SHORT,
+    {WINED3DFMT_D16_LOCKABLE,           GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
+            GL_DEPTH_COMPONENT,         GL_UNSIGNED_SHORT,
             WINED3DFMT_FLAG_DEPTH,
             ARB_DEPTH_TEXTURE},
-    {WINED3DFMT_D32,                GL_DEPTH_COMPONENT32_ARB,         GL_DEPTH_COMPONENT32_ARB,               0,
-            GL_DEPTH_COMPONENT,     GL_UNSIGNED_INT,
+    {WINED3DFMT_D32_UNORM,              GL_DEPTH_COMPONENT32_ARB,         GL_DEPTH_COMPONENT32_ARB,               0,
+            GL_DEPTH_COMPONENT,         GL_UNSIGNED_INT,
             WINED3DFMT_FLAG_DEPTH,
             ARB_DEPTH_TEXTURE},
-    {WINED3DFMT_D15S1,              GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
-            GL_DEPTH_COMPONENT,     GL_UNSIGNED_SHORT,
+    {WINED3DFMT_S1_UINT_D15_UNORM,      GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
+            GL_DEPTH_COMPONENT,         GL_UNSIGNED_SHORT,
             WINED3DFMT_FLAG_DEPTH,
             ARB_DEPTH_TEXTURE},
-    {WINED3DFMT_D15S1,              GL_DEPTH24_STENCIL8_EXT,          GL_DEPTH24_STENCIL8_EXT,                0,
-            GL_DEPTH_STENCIL_EXT,   GL_UNSIGNED_INT_24_8_EXT,
+    {WINED3DFMT_S1_UINT_D15_UNORM,      GL_DEPTH24_STENCIL8_EXT,          GL_DEPTH24_STENCIL8_EXT,                0,
+            GL_DEPTH_STENCIL_EXT,       GL_UNSIGNED_INT_24_8_EXT,
             WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
             EXT_PACKED_DEPTH_STENCIL},
-    {WINED3DFMT_D24S8,              GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
-            GL_DEPTH_COMPONENT,     GL_UNSIGNED_INT,
+    {WINED3DFMT_S1_UINT_D15_UNORM,      GL_DEPTH24_STENCIL8,              GL_DEPTH24_STENCIL8,                    0,
+            GL_DEPTH_STENCIL,           GL_UNSIGNED_INT_24_8,
+            WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
+            ARB_FRAMEBUFFER_OBJECT},
+    {WINED3DFMT_S8_UINT_D24_UNORM,      GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
+            GL_DEPTH_COMPONENT,         GL_UNSIGNED_INT,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH,
             ARB_DEPTH_TEXTURE},
-    {WINED3DFMT_D24S8,              GL_DEPTH24_STENCIL8_EXT,          GL_DEPTH24_STENCIL8_EXT,                0,
-            GL_DEPTH_STENCIL_EXT,   GL_UNSIGNED_INT_24_8_EXT,
+    {WINED3DFMT_S8_UINT_D24_UNORM,      GL_DEPTH24_STENCIL8_EXT,          GL_DEPTH24_STENCIL8_EXT,                0,
+            GL_DEPTH_STENCIL_EXT,       GL_UNSIGNED_INT_24_8_EXT,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
             EXT_PACKED_DEPTH_STENCIL},
-    {WINED3DFMT_D24X8,              GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
-            GL_DEPTH_COMPONENT,     GL_UNSIGNED_INT,
+    {WINED3DFMT_S8_UINT_D24_UNORM,      GL_DEPTH24_STENCIL8,              GL_DEPTH24_STENCIL8,                    0,
+            GL_DEPTH_STENCIL,           GL_UNSIGNED_INT_24_8,
+            WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
+            ARB_FRAMEBUFFER_OBJECT},
+    {WINED3DFMT_X8D24_UNORM,            GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
+            GL_DEPTH_COMPONENT,         GL_UNSIGNED_INT,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH,
             ARB_DEPTH_TEXTURE},
-    {WINED3DFMT_D24X4S4,            GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
-            GL_DEPTH_COMPONENT,     GL_UNSIGNED_INT,
+    {WINED3DFMT_S4X4_UINT_D24_UNORM,    GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
+            GL_DEPTH_COMPONENT,         GL_UNSIGNED_INT,
             WINED3DFMT_FLAG_DEPTH,
             ARB_DEPTH_TEXTURE},
-    {WINED3DFMT_D24X4S4,            GL_DEPTH24_STENCIL8_EXT,          GL_DEPTH24_STENCIL8_EXT,                0,
-            GL_DEPTH_STENCIL_EXT,   GL_UNSIGNED_INT_24_8_EXT,
+    {WINED3DFMT_S4X4_UINT_D24_UNORM,    GL_DEPTH24_STENCIL8_EXT,          GL_DEPTH24_STENCIL8_EXT,                0,
+            GL_DEPTH_STENCIL_EXT,       GL_UNSIGNED_INT_24_8_EXT,
             WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
             EXT_PACKED_DEPTH_STENCIL},
-    {WINED3DFMT_D16_UNORM,          GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
-            GL_DEPTH_COMPONENT,     GL_UNSIGNED_SHORT,
+    {WINED3DFMT_S4X4_UINT_D24_UNORM,    GL_DEPTH24_STENCIL8,              GL_DEPTH24_STENCIL8,                    0,
+            GL_DEPTH_STENCIL,           GL_UNSIGNED_INT_24_8,
+            WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
+            ARB_FRAMEBUFFER_OBJECT},
+    {WINED3DFMT_D16_UNORM,              GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
+            GL_DEPTH_COMPONENT,         GL_UNSIGNED_SHORT,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING | WINED3DFMT_FLAG_DEPTH,
             ARB_DEPTH_TEXTURE},
-    {WINED3DFMT_L16,                GL_LUMINANCE16_EXT,               GL_LUMINANCE16_EXT,                     0,
-            GL_LUMINANCE,           GL_UNSIGNED_SHORT,
+    {WINED3DFMT_L16_UNORM,              GL_LUMINANCE16_EXT,               GL_LUMINANCE16_EXT,                     0,
+            GL_LUMINANCE,               GL_UNSIGNED_SHORT,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_D32F_LOCKABLE,      GL_DEPTH_COMPONENT32F,            GL_DEPTH_COMPONENT32F,                  0,
-            GL_DEPTH_COMPONENT,     GL_FLOAT,
+    {WINED3DFMT_D32_FLOAT,              GL_DEPTH_COMPONENT32F,            GL_DEPTH_COMPONENT32F,                  0,
+            GL_DEPTH_COMPONENT,         GL_FLOAT,
             WINED3DFMT_FLAG_DEPTH,
             ARB_DEPTH_BUFFER_FLOAT},
-    {WINED3DFMT_D24FS8,             GL_DEPTH32F_STENCIL8,             GL_DEPTH32F_STENCIL8,                   0,
-            GL_DEPTH_STENCIL_EXT,   GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
+    {WINED3DFMT_S8_UINT_D24_FLOAT,      GL_DEPTH32F_STENCIL8,             GL_DEPTH32F_STENCIL8,                   0,
+            GL_DEPTH_STENCIL,           GL_FLOAT_32_UNSIGNED_INT_24_8_REV,
             WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
             ARB_DEPTH_BUFFER_FLOAT},
     /* Vendor-specific formats */
-    {WINED3DFMT_ATI2N,              GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, 0,
-            GL_LUMINANCE_ALPHA,     GL_UNSIGNED_BYTE,
+    {WINED3DFMT_ATI2N,                  GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, 0,
+            GL_LUMINANCE_ALPHA,         GL_UNSIGNED_BYTE,
             0,
             ATI_TEXTURE_COMPRESSION_3DC},
-    {WINED3DFMT_ATI2N,              GL_COMPRESSED_RED_GREEN_RGTC2_EXT, GL_COMPRESSED_RED_GREEN_RGTC2_EXT,     0,
-            GL_LUMINANCE_ALPHA,     GL_UNSIGNED_BYTE,
+    {WINED3DFMT_ATI2N,                  GL_COMPRESSED_RED_GREEN_RGTC2_EXT, GL_COMPRESSED_RED_GREEN_RGTC2_EXT,     0,
+            GL_LUMINANCE_ALPHA,         GL_UNSIGNED_BYTE,
             0,
             EXT_TEXTURE_COMPRESSION_RGTC},
@@ -590,10 +609,10 @@
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
-    GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0));
-
-    status = GL_EXTCALL(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
+    gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
+
+    status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
     checkGLcall("Framebuffer format check");
 
-    if (status == GL_FRAMEBUFFER_COMPLETE_EXT)
+    if (status == GL_FRAMEBUFFER_COMPLETE)
     {
         TRACE("Format %s is supported as FBO color attachment\n", debug_d3dformat(format_desc->format));
@@ -624,5 +643,5 @@
             while(glGetError());
 
-            GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 0, 0));
+            gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
 
             glTexImage2D(GL_TEXTURE_2D, 0, format_desc->rtInternal, 16, 16, 0,
@@ -631,10 +650,10 @@
             glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
-            GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0));
-
-            status = GL_EXTCALL(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
+            gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
+
+            status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
             checkGLcall("Framebuffer format check");
 
-            if (status == GL_FRAMEBUFFER_COMPLETE_EXT)
+            if (status == GL_FRAMEBUFFER_COMPLETE)
             {
                 TRACE("Format %s rtInternal format is supported as FBO color attachment\n",
@@ -650,17 +669,16 @@
     }
 
-    if (status == GL_FRAMEBUFFER_COMPLETE_EXT && format_desc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)
+    if (status == GL_FRAMEBUFFER_COMPLETE && format_desc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)
     {
         GLuint rb;
 
-        if (GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
+        if (GL_SUPPORT(ARB_FRAMEBUFFER_OBJECT)
+                || GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
         {
-            GL_EXTCALL(glGenRenderbuffersEXT(1, &rb));
-            GL_EXTCALL(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb));
-            GL_EXTCALL(glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH24_STENCIL8_EXT, 16, 16));
-            GL_EXTCALL(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
-                    GL_RENDERBUFFER_EXT, rb));
-            GL_EXTCALL(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
-                    GL_RENDERBUFFER_EXT, rb));
+            gl_info->fbo_ops.glGenRenderbuffers(1, &rb);
+            gl_info->fbo_ops.glBindRenderbuffer(GL_RENDERBUFFER, rb);
+            gl_info->fbo_ops.glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 16, 16);
+            gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb);
+            gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, rb);
             checkGLcall("RB attachment");
         }
@@ -668,5 +686,5 @@
         glEnable(GL_BLEND);
         glClear(GL_COLOR_BUFFER_BIT);
-        if (glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION_EXT)
+        if (glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION)
         {
             while(glGetError());
@@ -675,11 +693,10 @@
         }
 
-        if (GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
+        if (GL_SUPPORT(ARB_FRAMEBUFFER_OBJECT)
+                || GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
         {
-            GL_EXTCALL(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
-                    GL_RENDERBUFFER_EXT, 0));
-            GL_EXTCALL(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
-                    GL_RENDERBUFFER_EXT, 0));
-            GL_EXTCALL(glDeleteRenderbuffersEXT(1, &rb));
+            gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
+            gl_info->fbo_ops.glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, 0);
+            gl_info->fbo_ops.glDeleteRenderbuffers(1, &rb);
             checkGLcall("RB cleanup");
         }
@@ -701,6 +718,6 @@
         ENTER_GL();
 
-        GL_EXTCALL(glGenFramebuffersEXT(1, &fbo));
-        GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo));
+        gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
+        gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
 
         LEAVE_GL();
@@ -742,5 +759,5 @@
         ENTER_GL();
 
-        GL_EXTCALL(glDeleteFramebuffersEXT(1, &fbo));
+        gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
 
         LEAVE_GL();
@@ -833,8 +850,8 @@
     glEnable(GL_TEXTURE_2D);
 
-    GL_EXTCALL(glGenFramebuffersEXT(1, &fbo));
-    GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo));
-    GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, buffer, 0));
-    glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
+    gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
+    gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
+    gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, buffer, 0);
+    glDrawBuffer(GL_COLOR_ATTACHMENT0);
 
     glViewport(0, 0, 16, 1);
@@ -876,6 +893,6 @@
     }
 
-    GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
-    GL_EXTCALL(glDeleteFramebuffersEXT(1, &fbo));
+    gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
+    gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
     glDeleteTextures(1, &tex);
     glDeleteTextures(1, &buffer);
@@ -1007,8 +1024,8 @@
          * with each other
          */
-        idx = getFmtIdx(WINED3DFMT_L6V5U5);
+        idx = getFmtIdx(WINED3DFMT_R5G5_SNORM_L6_UNORM);
         gl_info->gl_formats[idx].color_fixup = create_color_fixup_desc(
                 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_ONE);
-        idx = getFmtIdx(WINED3DFMT_X8L8V8U8);
+        idx = getFmtIdx(WINED3DFMT_R8G8_SNORM_L8X8_UNORM);
         gl_info->gl_formats[idx].color_fixup = create_color_fixup_desc(
                 1, CHANNEL_SOURCE_X, 1, CHANNEL_SOURCE_Y, 0, CHANNEL_SOURCE_Z, 0, CHANNEL_SOURCE_W);
@@ -1054,5 +1071,5 @@
     if (GL_SUPPORT(EXT_VERTEX_ARRAY_BGRA))
     {
-        idx = getFmtIdx(WINED3DFMT_A8R8G8B8);
+        idx = getFmtIdx(WINED3DFMT_B8G8R8A8_UNORM);
         gl_info->gl_formats[idx].gl_vtx_format = GL_BGRA;
     }
@@ -1155,25 +1172,21 @@
 #define FMT_TO_STR(fmt) case fmt: return #fmt
     FMT_TO_STR(WINED3DFMT_UNKNOWN);
-    FMT_TO_STR(WINED3DFMT_R8G8B8);
-    FMT_TO_STR(WINED3DFMT_A8R8G8B8);
-    FMT_TO_STR(WINED3DFMT_X8R8G8B8);
-    FMT_TO_STR(WINED3DFMT_R5G6B5);
-    FMT_TO_STR(WINED3DFMT_X1R5G5B5);
-    FMT_TO_STR(WINED3DFMT_A1R5G5B5);
-    FMT_TO_STR(WINED3DFMT_A4R4G4B4);
-    FMT_TO_STR(WINED3DFMT_R3G3B2);
-    FMT_TO_STR(WINED3DFMT_A8R3G3B2);
-    FMT_TO_STR(WINED3DFMT_X4R4G4B4);
-    FMT_TO_STR(WINED3DFMT_X8B8G8R8);
-    FMT_TO_STR(WINED3DFMT_A2R10G10B10);
-    FMT_TO_STR(WINED3DFMT_A8P8);
-    FMT_TO_STR(WINED3DFMT_P8);
-    FMT_TO_STR(WINED3DFMT_L8);
-    FMT_TO_STR(WINED3DFMT_A8L8);
-    FMT_TO_STR(WINED3DFMT_A4L4);
-    FMT_TO_STR(WINED3DFMT_L6V5U5);
-    FMT_TO_STR(WINED3DFMT_X8L8V8U8);
-    FMT_TO_STR(WINED3DFMT_W11V11U10);
-    FMT_TO_STR(WINED3DFMT_A2W10V10U10);
+    FMT_TO_STR(WINED3DFMT_B8G8R8_UNORM);
+    FMT_TO_STR(WINED3DFMT_B5G5R5X1_UNORM);
+    FMT_TO_STR(WINED3DFMT_B4G4R4A4_UNORM);
+    FMT_TO_STR(WINED3DFMT_B2G3R3_UNORM);
+    FMT_TO_STR(WINED3DFMT_B2G3R3A8_UNORM);
+    FMT_TO_STR(WINED3DFMT_B4G4R4X4_UNORM);
+    FMT_TO_STR(WINED3DFMT_R8G8B8X8_UNORM);
+    FMT_TO_STR(WINED3DFMT_B10G10R10A2_UNORM);
+    FMT_TO_STR(WINED3DFMT_P8_UINT_A8_UNORM);
+    FMT_TO_STR(WINED3DFMT_P8_UINT);
+    FMT_TO_STR(WINED3DFMT_L8_UNORM);
+    FMT_TO_STR(WINED3DFMT_L8A8_UNORM);
+    FMT_TO_STR(WINED3DFMT_L4A4_UNORM);
+    FMT_TO_STR(WINED3DFMT_R5G5_SNORM_L6_UNORM);
+    FMT_TO_STR(WINED3DFMT_R8G8_SNORM_L8X8_UNORM);
+    FMT_TO_STR(WINED3DFMT_R10G11B11_SNORM);
+    FMT_TO_STR(WINED3DFMT_R10G10B10_SNORM_A2_UNORM);
     FMT_TO_STR(WINED3DFMT_UYVY);
     FMT_TO_STR(WINED3DFMT_YUY2);
@@ -1188,14 +1201,13 @@
     FMT_TO_STR(WINED3DFMT_R8G8_B8G8);
     FMT_TO_STR(WINED3DFMT_D16_LOCKABLE);
-    FMT_TO_STR(WINED3DFMT_D32);
-    FMT_TO_STR(WINED3DFMT_D15S1);
-    FMT_TO_STR(WINED3DFMT_D24S8);
-    FMT_TO_STR(WINED3DFMT_D24X8);
-    FMT_TO_STR(WINED3DFMT_D24X4S4);
-    FMT_TO_STR(WINED3DFMT_L16);
-    FMT_TO_STR(WINED3DFMT_D32F_LOCKABLE);
-    FMT_TO_STR(WINED3DFMT_D24FS8);
+    FMT_TO_STR(WINED3DFMT_D32_UNORM);
+    FMT_TO_STR(WINED3DFMT_S1_UINT_D15_UNORM);
+    FMT_TO_STR(WINED3DFMT_S8_UINT_D24_UNORM);
+    FMT_TO_STR(WINED3DFMT_X8D24_UNORM);
+    FMT_TO_STR(WINED3DFMT_S4X4_UINT_D24_UNORM);
+    FMT_TO_STR(WINED3DFMT_L16_UNORM);
+    FMT_TO_STR(WINED3DFMT_S8_UINT_D24_FLOAT);
     FMT_TO_STR(WINED3DFMT_VERTEXDATA);
-    FMT_TO_STR(WINED3DFMT_CxV8U8);
+    FMT_TO_STR(WINED3DFMT_R8G8_SNORM_Cx);
     FMT_TO_STR(WINED3DFMT_ATI2N);
     FMT_TO_STR(WINED3DFMT_NVHU);
@@ -1765,13 +1777,14 @@
     switch(status) {
 #define FBOSTATUS_TO_STR(u) case u: return #u
-        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE_EXT);
-        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT);
-        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT);
+        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_COMPLETE);
+        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT);
+        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT);
         FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT);
         FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT);
-        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT);
-        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT);
-        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT);
-        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED_EXT);
+        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER);
+        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER);
+        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE);
+        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNSUPPORTED);
+        FBOSTATUS_TO_STR(GL_FRAMEBUFFER_UNDEFINED);
 #undef FBOSTATUS_TO_STR
         default:
@@ -1791,5 +1804,5 @@
         GLERROR_TO_STR(GL_STACK_UNDERFLOW);
         GLERROR_TO_STR(GL_OUT_OF_MEMORY);
-        GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION_EXT);
+        GLERROR_TO_STR(GL_INVALID_FRAMEBUFFER_OPERATION);
 #undef GLERROR_TO_STR
         default:
@@ -2044,17 +2057,17 @@
     switch(format_desc->format)
     {
-        case WINED3DFMT_X8R8G8B8:
-        case WINED3DFMT_R8G8B8:
-        case WINED3DFMT_A8R8G8B8:
+        case WINED3DFMT_B8G8R8X8_UNORM:
+        case WINED3DFMT_B8G8R8_UNORM:
+        case WINED3DFMT_B8G8R8A8_UNORM:
         case WINED3DFMT_R8G8B8A8_UNORM:
-        case WINED3DFMT_A2R10G10B10:
-        case WINED3DFMT_X1R5G5B5:
-        case WINED3DFMT_A1R5G5B5:
-        case WINED3DFMT_R5G6B5:
-        case WINED3DFMT_X4R4G4B4:
-        case WINED3DFMT_A4R4G4B4:
-        case WINED3DFMT_R3G3B2:
-        case WINED3DFMT_A8P8:
-        case WINED3DFMT_P8:
+        case WINED3DFMT_B10G10R10A2_UNORM:
+        case WINED3DFMT_B5G5R5X1_UNORM:
+        case WINED3DFMT_B5G5R5A1_UNORM:
+        case WINED3DFMT_B5G6R5_UNORM:
+        case WINED3DFMT_B4G4R4X4_UNORM:
+        case WINED3DFMT_B4G4R4A4_UNORM:
+        case WINED3DFMT_B2G3R3_UNORM:
+        case WINED3DFMT_P8_UINT_A8_UNORM:
+        case WINED3DFMT_P8_UINT:
             break;
         default:
@@ -2082,11 +2095,11 @@
         case WINED3DFMT_D16_LOCKABLE:
         case WINED3DFMT_D16_UNORM:
-        case WINED3DFMT_D15S1:
-        case WINED3DFMT_D24X8:
-        case WINED3DFMT_D24X4S4:
-        case WINED3DFMT_D24S8:
-        case WINED3DFMT_D24FS8:
-        case WINED3DFMT_D32:
-        case WINED3DFMT_D32F_LOCKABLE:
+        case WINED3DFMT_S1_UINT_D15_UNORM:
+        case WINED3DFMT_X8D24_UNORM:
+        case WINED3DFMT_S4X4_UINT_D24_UNORM:
+        case WINED3DFMT_S8_UINT_D24_UNORM:
+        case WINED3DFMT_S8_UINT_D24_FLOAT:
+        case WINED3DFMT_D32_UNORM:
+        case WINED3DFMT_D32_FLOAT:
             break;
         default:
@@ -2106,9 +2119,9 @@
 WINED3DFORMAT pixelformat_for_depth(DWORD depth) {
     switch(depth) {
-        case 8:  return WINED3DFMT_P8;
-        case 15: return WINED3DFMT_X1R5G5B5;
-        case 16: return WINED3DFMT_R5G6B5;
-        case 24: return WINED3DFMT_X8R8G8B8; /* Robots needs 24bit to be X8R8G8B8 */
-        case 32: return WINED3DFMT_X8R8G8B8; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return X8R8G8B8 */
+        case 8:  return WINED3DFMT_P8_UINT;
+        case 15: return WINED3DFMT_B5G5R5X1_UNORM;
+        case 16: return WINED3DFMT_B5G6R5_UNORM;
+        case 24: return WINED3DFMT_B8G8R8X8_UNORM; /* Robots needs 24bit to be WINED3DFMT_B8G8R8X8_UNORM */
+        case 32: return WINED3DFMT_B8G8R8X8_UNORM; /* EVE online and the Fur demo need 32bit AdapterDisplayMode to return WINED3DFMT_B8G8R8X8_UNORM */
         default: return WINED3DFMT_UNKNOWN;
     }
@@ -2543,7 +2556,9 @@
         settings->sRGB_write = 0;
     }
-    if(device->vs_clipping || !use_vs(stateblock)) {
+    if(device->vs_clipping || !use_vs(stateblock) || !stateblock->renderState[WINED3DRS_CLIPPING] ||
+       !stateblock->renderState[WINED3DRS_CLIPPLANEENABLE]) {
         /* No need to emulate clipplanes if GL supports native vertex shader clipping or if
-         * the fixed function vertex pipeline is used(which always supports clipplanes)
+         * the fixed function vertex pipeline is used(which always supports clipplanes), or
+         * if no clipplane is enabled
          */
         settings->emul_clipplanes = 0;
@@ -2702,22 +2717,22 @@
 UINT wined3d_log2i(UINT32 x)
 {
-    static const BYTE l[] =
-    {
-        0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
-        4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
-        5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-        5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
-        6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-        6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-        6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-        6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
-        7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-        7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-        7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-        7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-        7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-        7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-        7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
-        7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+    static const UINT l[] =
+    {
+        ~0U, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
+          4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+          5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+          5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+          6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+          6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+          6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+          6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+          7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+          7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+          7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+          7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+          7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+          7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+          7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+          7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
     };
     UINT32 i;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexdeclaration.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexdeclaration.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexdeclaration.c	(revision 23571)
@@ -6,4 +6,5 @@
  * Copyright 2004 Christian Costa
  * Copyright 2005 Oliver Stieber
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -84,4 +85,5 @@
 
         HeapFree(GetProcessHeap(), 0, This->elements);
+        This->parent_ops->wined3d_object_destroyed(This->parent);
         HeapFree(GetProcessHeap(), 0, This);
     }
@@ -139,5 +141,5 @@
                 case WINED3DFMT_R32G32B32_FLOAT:
                 case WINED3DFMT_R32G32B32A32_FLOAT:
-                case WINED3DFMT_A8R8G8B8:
+                case WINED3DFMT_B8G8R8A8_UNORM:
                 case WINED3DFMT_R8G8B8A8_UINT:
                 case WINED3DFMT_R16G16_SINT:
@@ -183,5 +185,5 @@
                 case WINED3DFMT_R32G32B32_FLOAT:
                 case WINED3DFMT_R32G32B32A32_FLOAT:
-                case WINED3DFMT_A8R8G8B8:
+                case WINED3DFMT_B8G8R8A8_UNORM:
                 case WINED3DFMT_R8G8B8A8_UINT:
                 case WINED3DFMT_R16G16B16A16_SINT:
@@ -200,84 +202,5 @@
 }
 
-HRESULT vertexdeclaration_init(IWineD3DVertexDeclarationImpl *This,
-        const WINED3DVERTEXELEMENT *elements, UINT element_count)
-{
-    HRESULT hr = WINED3D_OK;
-    unsigned int i;
-    char isPreLoaded[MAX_STREAMS];
-
-    TRACE("(%p) : d3d version %d\n", This, ((IWineD3DImpl *)This->wineD3DDevice->wineD3D)->dxVersion);
-    memset(isPreLoaded, 0, sizeof(isPreLoaded));
-
-    if (TRACE_ON(d3d_decl)) {
-        for (i = 0; i < element_count; ++i) {
-            dump_wined3dvertexelement(elements+i);
-        }
-    }
-
-    This->element_count = element_count;
-    This->elements = HeapAlloc(GetProcessHeap(), 0, sizeof(*This->elements) * element_count);
-    if (!This->elements)
-    {
-        ERR("Memory allocation failed\n");
-        return WINED3DERR_OUTOFVIDEOMEMORY;
-    }
-
-    /* Do some static analysis on the elements to make reading the declaration more comfortable
-     * for the drawing code
-     */
-    This->num_streams = 0;
-    This->position_transformed = FALSE;
-    for (i = 0; i < element_count; ++i) {
-        struct wined3d_vertex_declaration_element *e = &This->elements[i];
-
-        e->format_desc = getFormatDescEntry(elements[i].format, &This->wineD3DDevice->adapter->gl_info);
-        e->ffp_valid = declaration_element_valid_ffp(&elements[i]);
-        e->input_slot = elements[i].input_slot;
-        e->offset = elements[i].offset;
-        e->output_slot = elements[i].output_slot;
-        e->method = elements[i].method;
-        e->usage = elements[i].usage;
-        e->usage_idx = elements[i].usage_idx;
-
-        if (e->usage == WINED3DDECLUSAGE_POSITIONT) This->position_transformed = TRUE;
-
-        /* Find the Streams used in the declaration. The vertex buffers have to be loaded
-         * when drawing, but filter tesselation pseudo streams
-         */
-        if (e->input_slot >= MAX_STREAMS) continue;
-
-        if (!e->format_desc->gl_vtx_format)
-        {
-            FIXME("The application tries to use an unsupported format (%s), returning E_FAIL\n",
-                    debug_d3dformat(elements[i].format));
-            /* The caller will release the vdecl, which will free This->elements */
-            return E_FAIL;
-        }
-
-        if (e->offset & 0x3)
-        {
-            WARN("Declaration element %u is not 4 byte aligned(%u), returning E_FAIL\n", i, e->offset);
-            return E_FAIL;
-        }
-
-        if (!isPreLoaded[e->input_slot])
-        {
-            This->streams[This->num_streams] = e->input_slot;
-            This->num_streams++;
-            isPreLoaded[e->input_slot] = 1;
-        }
-
-        if (elements[i].format == WINED3DFMT_R16G16_FLOAT || elements[i].format == WINED3DFMT_R16G16B16A16_FLOAT)
-        {
-            if (!GL_SUPPORT(ARB_HALF_FLOAT_VERTEX)) This->half_float_conv_needed = TRUE;
-        }
-    }
-
-    TRACE("Returning\n");
-    return hr;
-}
-
-const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl =
+static const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl =
 {
     /* IUnknown */
@@ -289,2 +212,83 @@
     IWineD3DVertexDeclarationImpl_GetDevice,
 };
+
+HRESULT vertexdeclaration_init(IWineD3DVertexDeclarationImpl *declaration, IWineD3DDeviceImpl *device,
+        const WINED3DVERTEXELEMENT *elements, UINT element_count,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+{
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    WORD preloaded = 0; /* MAX_STREAMS, 16 */
+    unsigned int i;
+
+    if (TRACE_ON(d3d_decl))
+    {
+        for (i = 0; i < element_count; ++i)
+        {
+            dump_wined3dvertexelement(elements + i);
+        }
+    }
+
+    declaration->lpVtbl = &IWineD3DVertexDeclaration_Vtbl;
+    declaration->ref = 1;
+    declaration->parent = parent;
+    declaration->parent_ops = parent_ops;
+    declaration->wineD3DDevice = device;
+    declaration->elements = HeapAlloc(GetProcessHeap(), 0, sizeof(*declaration->elements) * element_count);
+    if (!declaration->elements)
+    {
+        ERR("Failed to allocate elements memory.\n");
+        return E_OUTOFMEMORY;
+    }
+    declaration->element_count = element_count;
+
+    /* Do some static analysis on the elements to make reading the
+     * declaration more comfortable for the drawing code. */
+    for (i = 0; i < element_count; ++i)
+    {
+        struct wined3d_vertex_declaration_element *e = &declaration->elements[i];
+
+        e->format_desc = getFormatDescEntry(elements[i].format, gl_info);
+        e->ffp_valid = declaration_element_valid_ffp(&elements[i]);
+        e->input_slot = elements[i].input_slot;
+        e->offset = elements[i].offset;
+        e->output_slot = elements[i].output_slot;
+        e->method = elements[i].method;
+        e->usage = elements[i].usage;
+        e->usage_idx = elements[i].usage_idx;
+
+        if (e->usage == WINED3DDECLUSAGE_POSITIONT) declaration->position_transformed = TRUE;
+
+        /* Find the streams used in the declaration. The vertex buffers have
+         * to be loaded when drawing, but filter tesselation pseudo streams. */
+        if (e->input_slot >= MAX_STREAMS) continue;
+
+        if (!e->format_desc->gl_vtx_format)
+        {
+            FIXME("The application tries to use an unsupported format (%s), returning E_FAIL.\n",
+                    debug_d3dformat(elements[i].format));
+            HeapFree(GetProcessHeap(), 0, declaration->elements);
+            return E_FAIL;
+        }
+
+        if (e->offset & 0x3)
+        {
+            WARN("Declaration element %u is not 4 byte aligned(%u), returning E_FAIL.\n", i, e->offset);
+            HeapFree(GetProcessHeap(), 0, declaration->elements);
+            return E_FAIL;
+        }
+
+        if (!(preloaded & (1 << e->input_slot)))
+        {
+            declaration->streams[declaration->num_streams] = e->input_slot;
+            ++declaration->num_streams;
+            preloaded |= 1 << e->input_slot;
+        }
+
+        if (elements[i].format == WINED3DFMT_R16G16_FLOAT || elements[i].format == WINED3DFMT_R16G16B16A16_FLOAT)
+        {
+            if (!gl_info->supported[ARB_HALF_FLOAT_VERTEX]) declaration->half_float_conv_needed = TRUE;
+        }
+    }
+
+    return WINED3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexshader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexshader.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexshader.c	(revision 23571)
@@ -8,4 +8,5 @@
  * Copyright 2006 Ivan Gyurdiev
  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -184,4 +185,5 @@
     {
         shader_cleanup((IWineD3DBaseShader *)iface);
+        This->baseShader.parent_ops->wined3d_object_destroyed(This->baseShader.parent);
         HeapFree(GetProcessHeap(), 0, This);
     }
@@ -196,6 +198,6 @@
 static HRESULT WINAPI IWineD3DVertexShaderImpl_GetParent(IWineD3DVertexShader *iface, IUnknown** parent){
     IWineD3DVertexShaderImpl *This = (IWineD3DVertexShaderImpl *)iface;
-    
-    *parent = This->parent;
+
+    *parent = This->baseShader.parent;
     IUnknown_AddRef(*parent);
     TRACE("(%p) : returning %p\n", This, *parent);
@@ -232,21 +234,17 @@
 }
 
-/* Note that for vertex shaders CompileShader isn't called until the
- * shader is first used. The reason for this is that we need the vertex
- * declaration the shader will be used with in order to determine if
- * the data in a register is of type D3DCOLOR, and needs swizzling. */
-static HRESULT WINAPI IWineD3DVertexShaderImpl_SetFunction(IWineD3DVertexShader *iface,
-        const DWORD *pFunction, const struct wined3d_shader_signature *output_signature)
-{
-    IWineD3DVertexShaderImpl *This =(IWineD3DVertexShaderImpl *)iface;
-    IWineD3DDeviceImpl *deviceImpl = (IWineD3DDeviceImpl *) This->baseShader.device;
+static HRESULT vertexshader_set_function(IWineD3DVertexShaderImpl *shader,
+        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature)
+{
+    IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)shader->baseShader.device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     const struct wined3d_shader_frontend *fe;
     unsigned int i;
     HRESULT hr;
-    shader_reg_maps *reg_maps = &This->baseShader.reg_maps;
-
-    TRACE("(%p) : pFunction %p\n", iface, pFunction);
-
-    fe = shader_select_frontend(*pFunction);
+    shader_reg_maps *reg_maps = &shader->baseShader.reg_maps;
+
+    TRACE("shader %p, byte_code %p, output_signature %p.\n", shader, byte_code, output_signature);
+
+    fe = shader_select_frontend(*byte_code);
     if (!fe)
     {
@@ -254,7 +252,7 @@
         return WINED3DERR_INVALIDCALL;
     }
-    This->baseShader.frontend = fe;
-    This->baseShader.frontend_data = fe->shader_init(pFunction, output_signature);
-    if (!This->baseShader.frontend_data)
+    shader->baseShader.frontend = fe;
+    shader->baseShader.frontend_data = fe->shader_init(byte_code, output_signature);
+    if (!shader->baseShader.frontend_data)
     {
         FIXME("Failed to initialize frontend.\n");
@@ -263,17 +261,17 @@
 
     /* First pass: trace shader */
-    if (TRACE_ON(d3d_shader)) shader_trace_init(fe, This->baseShader.frontend_data, pFunction);
+    if (TRACE_ON(d3d_shader)) shader_trace_init(fe, shader->baseShader.frontend_data, byte_code);
 
     /* Initialize immediate constant lists */
-    list_init(&This->baseShader.constantsF);
-    list_init(&This->baseShader.constantsB);
-    list_init(&This->baseShader.constantsI);
+    list_init(&shader->baseShader.constantsF);
+    list_init(&shader->baseShader.constantsB);
+    list_init(&shader->baseShader.constantsI);
 
     /* Second pass: figure out registers used, semantics, etc.. */
-    This->min_rel_offset = GL_LIMITS(vshader_constantsF);
-    This->max_rel_offset = 0;
-    hr = shader_get_registers_used((IWineD3DBaseShader*) This, fe,
-            reg_maps, This->attributes, NULL, This->output_signature,
-            pFunction, GL_LIMITS(vshader_constantsF));
+    shader->min_rel_offset = gl_info->max_vshader_constantsF;
+    shader->max_rel_offset = 0;
+    hr = shader_get_registers_used((IWineD3DBaseShader *)shader, fe,
+            reg_maps, shader->attributes, NULL, shader->output_signature,
+            byte_code, gl_info->max_vshader_constantsF);
     if (hr != WINED3D_OK) return hr;
 
@@ -284,32 +282,40 @@
             struct wined3d_shader_signature_element *e = &output_signature->elements[i];
             reg_maps->output_registers |= 1 << e->register_idx;
-            This->output_signature[e->register_idx] = *e;
-        }
-    }
-
-    vshader_set_limits(This);
-
-    if (deviceImpl->vs_selected_mode == SHADER_ARB
-            && ((GLINFO_LOCATION).quirks & WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT)
-            && This->min_rel_offset <= This->max_rel_offset)
-    {
-        if(This->max_rel_offset - This->min_rel_offset > 127) {
+            shader->output_signature[e->register_idx] = *e;
+        }
+    }
+
+    vshader_set_limits(shader);
+
+    if (device->vs_selected_mode == SHADER_ARB
+            && (gl_info->quirks & WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT)
+            && shader->min_rel_offset <= shader->max_rel_offset)
+    {
+        if (shader->max_rel_offset - shader->min_rel_offset > 127)
+        {
             FIXME("The difference between the minimum and maximum relative offset is > 127\n");
             FIXME("Which this OpenGL implementation does not support. Try using GLSL\n");
-            FIXME("Min: %d, Max: %d\n", This->min_rel_offset, This->max_rel_offset);
-        } else if(This->max_rel_offset - This->min_rel_offset > 63) {
-            This->rel_offset = This->min_rel_offset + 63;
-        } else if(This->max_rel_offset > 63) {
-            This->rel_offset = This->min_rel_offset;
-        } else {
-            This->rel_offset = 0;
-        }
-    }
-    This->baseShader.load_local_constsF = This->baseShader.reg_maps.usesrelconstF && !list_empty(&This->baseShader.constantsF);
+            FIXME("Min: %d, Max: %d\n", shader->min_rel_offset, shader->max_rel_offset);
+        }
+        else if (shader->max_rel_offset - shader->min_rel_offset > 63)
+        {
+            shader->rel_offset = shader->min_rel_offset + 63;
+        }
+        else if (shader->max_rel_offset > 63)
+        {
+            shader->rel_offset = shader->min_rel_offset;
+        }
+        else
+        {
+            shader->rel_offset = 0;
+        }
+    }
+    shader->baseShader.load_local_constsF = shader->baseShader.reg_maps.usesrelconstF
+            && !list_empty(&shader->baseShader.constantsF);
 
     /* copy the function ... because it will certainly be released by application */
-    This->baseShader.function = HeapAlloc(GetProcessHeap(), 0, This->baseShader.functionLength);
-    if (!This->baseShader.function) return E_OUTOFMEMORY;
-    memcpy(This->baseShader.function, pFunction, This->baseShader.functionLength);
+    shader->baseShader.function = HeapAlloc(GetProcessHeap(), 0, shader->baseShader.functionLength);
+    if (!shader->baseShader.function) return E_OUTOFMEMORY;
+    memcpy(shader->baseShader.function, byte_code, shader->baseShader.functionLength);
 
     return WINED3D_OK;
@@ -342,5 +348,5 @@
 }
 
-const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl =
+static const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl =
 {
     /*** IUnknown methods ***/
@@ -351,8 +357,7 @@
     IWineD3DVertexShaderImpl_GetParent,
     /*** IWineD3DBaseShader methods ***/
-    IWineD3DVertexShaderImpl_SetFunction,
-    /*** IWineD3DVertexShader methods ***/
     IWineD3DVertexShaderImpl_GetDevice,
     IWineD3DVertexShaderImpl_GetFunction,
+    /*** IWineD3DVertexShader methods ***/
     IWIneD3DVertexShaderImpl_SetLocalConstantsF
 };
@@ -362,2 +367,24 @@
     args->swizzle_map = ((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.swizzle_map;
 }
+
+HRESULT vertexshader_init(IWineD3DVertexShaderImpl *shader, IWineD3DDeviceImpl *device,
+        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+{
+    HRESULT hr;
+
+    if (!byte_code) return WINED3DERR_INVALIDCALL;
+
+    shader->lpVtbl = &IWineD3DVertexShader_Vtbl;
+    shader_init(&shader->baseShader, device, parent, parent_ops);
+
+    hr = vertexshader_set_function(shader, byte_code, output_signature);
+    if (FAILED(hr))
+    {
+        WARN("Failed to set function, hr %#x.\n", hr);
+        shader_cleanup((IWineD3DBaseShader *)shader);
+        return hr;
+    }
+
+    return WINED3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c	(revision 23571)
@@ -5,4 +5,5 @@
  * Copyright 2002-2005 Raphael Junqueira
  * Copyright 2005 Oliver Stieber
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -40,5 +41,5 @@
     IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
     IWineD3DVolumeTexture *texture;
-    int active_sampler;
+    DWORD active_sampler;
 
     /* We don't need a specific texture unit, but after binding the texture the current unit is dirty.
@@ -63,5 +64,6 @@
     }
 
-    if (active_sampler != -1) {
+    if (active_sampler != WINED3D_UNMAPPED_STAGE)
+    {
         IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_SAMPLER(active_sampler));
     }
@@ -131,4 +133,5 @@
     if (ref == 0) {
         resource_cleanup((IWineD3DResource *)iface);
+        This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
         HeapFree(GetProcessHeap(), 0, This);
     }
@@ -273,5 +276,6 @@
         if (containerType == WINED3DRTYPE_VOLUMETEXTURE) {
           IWineD3DBaseTextureImpl* pTexture = (IWineD3DBaseTextureImpl*) cont;
-          pTexture->baseTexture.dirty = TRUE;
+          pTexture->baseTexture.texture_rgb.dirty = TRUE;
+          pTexture->baseTexture.texture_srgb.dirty = TRUE;
         } else {
           FIXME("Set dirty on container type %d\n", containerType);
@@ -355,5 +359,5 @@
 }
 
-const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl =
+static const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl =
 {
     /* IUnknown */
@@ -381,2 +385,39 @@
     IWineD3DVolumeImpl_SetContainer
 };
+
+HRESULT volume_init(IWineD3DVolumeImpl *volume, IWineD3DDeviceImpl *device, UINT width,
+        UINT height, UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+{
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
+    HRESULT hr;
+
+    if (!gl_info->supported[EXT_TEXTURE3D])
+    {
+        WARN("Volume cannot be created - no volume texture support.\n");
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    volume->lpVtbl = &IWineD3DVolume_Vtbl;
+
+    hr = resource_init((IWineD3DResource *)volume, WINED3DRTYPE_VOLUME, device,
+            width * height * depth * format_desc->byte_count, usage, format_desc, pool, parent, parent_ops);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize resource, returning %#x.\n", hr);
+        return hr;
+    }
+
+    volume->currentDesc.Width = width;
+    volume->currentDesc.Height = height;
+    volume->currentDesc.Depth = depth;
+    volume->lockable = TRUE;
+    volume->locked = FALSE;
+    memset(&volume->lockedBox, 0, sizeof(volume->lockedBox));
+    volume->dirty = TRUE;
+
+    volume_add_dirty_box((IWineD3DVolume *)volume, NULL);
+
+    return WINED3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c	(revision 23571)
@@ -5,4 +5,5 @@
  * Copyright 2002-2005 Raphael Junqueira
  * Copyright 2005 Oliver Stieber
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -62,5 +63,5 @@
     /* If the texture is marked dirty or the srgb sampler setting has changed
      * since the last load then reload the volumes. */
-    if (This->baseTexture.dirty)
+    if (This->baseTexture.texture_rgb.dirty)
     {
         for (i = 0; i < This->baseTexture.levels; ++i)
@@ -83,8 +84,8 @@
 
     /* No longer dirty */
-    This->baseTexture.dirty = FALSE;
-}
-
-static void volumetexture_cleanup(IWineD3DVolumeTextureImpl *This, D3DCB_DESTROYVOLUMEFN volume_destroy_cb)
+    This->baseTexture.texture_rgb.dirty = FALSE;
+}
+
+static void volumetexture_cleanup(IWineD3DVolumeTextureImpl *This)
 {
     unsigned int i;
@@ -100,99 +101,8 @@
             /* Cleanup the container. */
             IWineD3DVolume_SetContainer(volume, NULL);
-            volume_destroy_cb(volume);
+            IWineD3DVolume_Release(volume);
         }
     }
     basetexture_cleanup((IWineD3DBaseTexture *)This);
-}
-
-HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height, UINT depth, UINT levels,
-        IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
-{
-    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
-    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
-    UINT tmp_w, tmp_h, tmp_d;
-    unsigned int i;
-    HRESULT hr;
-
-    /* TODO: It should only be possible to create textures for formats
-     * that are reported as supported. */
-    if (WINED3DFMT_UNKNOWN >= format)
-    {
-        WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
-        return WINED3DERR_INVALIDCALL;
-    }
-
-    if (!GL_SUPPORT(EXT_TEXTURE3D))
-    {
-        WARN("(%p) : Texture cannot be created - no volume texture support.\n", texture);
-        return WINED3DERR_INVALIDCALL;
-    }
-
-    /* Calculate levels for mip mapping. */
-    if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
-    {
-        if (!GL_SUPPORT(SGIS_GENERATE_MIPMAP))
-        {
-            WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
-            return WINED3DERR_INVALIDCALL;
-        }
-
-        if (levels > 1)
-        {
-            WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
-            return WINED3DERR_INVALIDCALL;
-        }
-
-        levels = 1;
-    }
-    else if (!levels)
-    {
-        levels = wined3d_log2i(max(max(width, height), depth)) + 1;
-        TRACE("Calculated levels = %u.\n", levels);
-    }
-
-    hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels,
-            WINED3DRTYPE_VOLUMETEXTURE, device, 0, usage, format_desc, pool, parent);
-    if (FAILED(hr))
-    {
-        WARN("Failed to initialize basetexture, returning %#x.\n", hr);
-        return hr;
-    }
-
-    /* Is NP2 support for volumes needed? */
-    texture->baseTexture.pow2Matrix[0] = 1.0f;
-    texture->baseTexture.pow2Matrix[5] = 1.0f;
-    texture->baseTexture.pow2Matrix[10] = 1.0f;
-    texture->baseTexture.pow2Matrix[15] = 1.0f;
-
-    /* Generate all the surfaces. */
-    tmp_w = width;
-    tmp_h = height;
-    tmp_d = depth;
-
-    for (i = 0; i < texture->baseTexture.levels; ++i)
-    {
-        /* Create the volume. */
-        hr = IWineD3DDeviceParent_CreateVolume(device->device_parent, parent,
-                tmp_w, tmp_h, tmp_d, format, pool, usage, &texture->volumes[i]);
-        if (FAILED(hr))
-        {
-            ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr);
-            texture->volumes[i] = NULL;
-            volumetexture_cleanup(texture, D3DCB_DefaultDestroyVolume);
-            return hr;
-        }
-
-        /* Set its container to this texture. */
-        IWineD3DVolume_SetContainer(texture->volumes[i], (IWineD3DBase *)texture);
-
-        /* Calculate the next mipmap level. */
-        tmp_w = max(1, tmp_w >> 1);
-        tmp_h = max(1, tmp_h >> 1);
-        tmp_d = max(1, tmp_d >> 1);
-    }
-    texture->baseTexture.internal_preload = volumetexture_internal_preload;
-
-    return WINED3D_OK;
 }
 
@@ -233,6 +143,9 @@
     TRACE("(%p) : Releasing from %d\n", This, This->resource.ref);
     ref = InterlockedDecrement(&This->resource.ref);
-    if (ref == 0) {
-        IWineD3DVolumeTexture_Destroy(iface, D3DCB_DefaultDestroyVolume);
+    if (!ref)
+    {
+        volumetexture_cleanup(This);
+        This->resource.parent_ops->wined3d_object_destroyed(This->resource.parent);
+        HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -354,12 +267,4 @@
    IWineD3DVolumeTexture IWineD3DVolumeTexture parts follow
    ******************************************* */
-static void WINAPI IWineD3DVolumeTextureImpl_Destroy(IWineD3DVolumeTexture *iface, D3DCB_DESTROYVOLUMEFN D3DCB_DestroyVolume) {
-    IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
-
-    volumetexture_cleanup(This, D3DCB_DestroyVolume);
-
-    HeapFree(GetProcessHeap(), 0, This);
-}
-
 static HRESULT WINAPI IWineD3DVolumeTextureImpl_GetLevelDesc(IWineD3DVolumeTexture *iface, UINT Level,WINED3DVOLUME_DESC *pDesc) {
     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
@@ -417,5 +322,6 @@
 static HRESULT WINAPI IWineD3DVolumeTextureImpl_AddDirtyBox(IWineD3DVolumeTexture *iface, CONST WINED3DBOX* pDirtyBox) {
     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
-    This->baseTexture.dirty = TRUE;
+    This->baseTexture.texture_rgb.dirty = TRUE;
+    This->baseTexture.texture_srgb.dirty = TRUE;
     TRACE("(%p) : dirtyfication of volume Level (0)\n", This);
     volume_add_dirty_box(This->volumes[0], pDirtyBox);
@@ -424,5 +330,5 @@
 }
 
-const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
+static const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl =
 {
     /* IUnknown */
@@ -455,5 +361,4 @@
     IWineD3DVolumeTextureImpl_IsCondNP2,
     /* volume texture */
-    IWineD3DVolumeTextureImpl_Destroy,
     IWineD3DVolumeTextureImpl_GetLevelDesc,
     IWineD3DVolumeTextureImpl_GetVolumeLevel,
@@ -462,2 +367,96 @@
     IWineD3DVolumeTextureImpl_AddDirtyBox
 };
+
+HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height,
+        UINT depth, UINT levels, IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format,
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+{
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
+    UINT tmp_w, tmp_h, tmp_d;
+    unsigned int i;
+    HRESULT hr;
+
+    /* TODO: It should only be possible to create textures for formats
+     * that are reported as supported. */
+    if (WINED3DFMT_UNKNOWN >= format)
+    {
+        WARN("(%p) : Texture cannot be created with a format of WINED3DFMT_UNKNOWN.\n", texture);
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    if (!gl_info->supported[EXT_TEXTURE3D])
+    {
+        WARN("(%p) : Texture cannot be created - no volume texture support.\n", texture);
+        return WINED3DERR_INVALIDCALL;
+    }
+
+    /* Calculate levels for mip mapping. */
+    if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
+    {
+        if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
+        {
+            WARN("No mipmap generation support, returning D3DERR_INVALIDCALL.\n");
+            return WINED3DERR_INVALIDCALL;
+        }
+
+        if (levels > 1)
+        {
+            WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL.\n");
+            return WINED3DERR_INVALIDCALL;
+        }
+
+        levels = 1;
+    }
+    else if (!levels)
+    {
+        levels = wined3d_log2i(max(max(width, height), depth)) + 1;
+        TRACE("Calculated levels = %u.\n", levels);
+    }
+
+    texture->lpVtbl = &IWineD3DVolumeTexture_Vtbl;
+
+    hr = basetexture_init((IWineD3DBaseTextureImpl *)texture, levels, WINED3DRTYPE_VOLUMETEXTURE,
+            device, 0, usage, format_desc, pool, parent, parent_ops);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize basetexture, returning %#x.\n", hr);
+        return hr;
+    }
+
+    /* Is NP2 support for volumes needed? */
+    texture->baseTexture.pow2Matrix[0] = 1.0f;
+    texture->baseTexture.pow2Matrix[5] = 1.0f;
+    texture->baseTexture.pow2Matrix[10] = 1.0f;
+    texture->baseTexture.pow2Matrix[15] = 1.0f;
+
+    /* Generate all the surfaces. */
+    tmp_w = width;
+    tmp_h = height;
+    tmp_d = depth;
+
+    for (i = 0; i < texture->baseTexture.levels; ++i)
+    {
+        /* Create the volume. */
+        hr = IWineD3DDeviceParent_CreateVolume(device->device_parent, parent,
+                tmp_w, tmp_h, tmp_d, format, pool, usage, &texture->volumes[i]);
+        if (FAILED(hr))
+        {
+            ERR("Creating a volume for the volume texture failed, hr %#x.\n", hr);
+            texture->volumes[i] = NULL;
+            volumetexture_cleanup(texture);
+            return hr;
+        }
+
+        /* Set its container to this texture. */
+        IWineD3DVolume_SetContainer(texture->volumes[i], (IWineD3DBase *)texture);
+
+        /* Calculate the next mipmap level. */
+        tmp_w = max(1, tmp_w >> 1);
+        tmp_h = max(1, tmp_h >> 1);
+        tmp_d = max(1, tmp_d >> 1);
+    }
+    texture->baseTexture.internal_preload = volumetexture_internal_preload;
+
+    return WINED3D_OK;
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d.def
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d.def	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d.def	(revision 23571)
@@ -4,8 +4,6 @@
 
 EXPORTS
-;  WineDirect3DCreate@8 @1
-;  WineDirect3DCreateClipper@4 @2
-;  WineDirect3DCreate@8 = WineDirect3DCreate
-;  WineDirect3DCreateClipper@4 = WineDirect3DCreateClipper
   WineDirect3DCreate
   WineDirect3DCreateClipper
+  wined3d_mutex_lock
+  wined3d_mutex_unlock
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d.spec
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d.spec	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d.spec	(revision 23571)
@@ -1,2 +1,4 @@
 @ stdcall WineDirect3DCreate(long ptr)
 @ stdcall WineDirect3DCreateClipper(ptr)
+@ stdcall wined3d_mutex_lock()
+@ stdcall wined3d_mutex_unlock()
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h	(revision 23571)
@@ -812,356 +812,377 @@
 #define GL_MULTISAMPLE_BIT                0x20000000
 
-void (WINE_GLAPI *glAccum) (GLenum op, GLfloat value);
-void (WINE_GLAPI *glAlphaFunc) (GLenum func, GLclampf ref);
-GLboolean (WINE_GLAPI *glAreTexturesResident) (GLsizei n, const GLuint* textures, GLboolean* residences);
-void (WINE_GLAPI *glArrayElement) (GLint i);
-void (WINE_GLAPI *glBegin) (GLenum mode);
-void (WINE_GLAPI *glBindTexture) (GLenum target, GLuint texture);
-void (WINE_GLAPI *glBitmap) (GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte* bitmap);
-void (WINE_GLAPI *glBlendFunc) (GLenum sfactor, GLenum dfactor);
-void (WINE_GLAPI *glCallList) (GLuint list);
-void (WINE_GLAPI *glCallLists) (GLsizei n, GLenum type, const GLvoid* lists);
-void (WINE_GLAPI *glClear) (GLbitfield mask);
-void (WINE_GLAPI *glClearAccum) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
-void (WINE_GLAPI *glClearColor) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
-void (WINE_GLAPI *glClearDepth) (GLclampd depth);
-void (WINE_GLAPI *glClearIndex) (GLfloat c);
-void (WINE_GLAPI *glClearStencil) (GLint s);
-void (WINE_GLAPI *glClipPlane) (GLenum plane, const GLdouble* equation);
-void (WINE_GLAPI *glColor3b) (GLbyte red, GLbyte green, GLbyte blue);
-void (WINE_GLAPI *glColor3bv) (const GLbyte* v);
-void (WINE_GLAPI *glColor3d) (GLdouble red, GLdouble green, GLdouble blue);
-void (WINE_GLAPI *glColor3dv) (const GLdouble* v);
-void (WINE_GLAPI *glColor3f) (GLfloat red, GLfloat green, GLfloat blue);
-void (WINE_GLAPI *glColor3fv) (const GLfloat* v);
-void (WINE_GLAPI *glColor3i) (GLint red, GLint green, GLint blue);
-void (WINE_GLAPI *glColor3iv) (const GLint* v);
-void (WINE_GLAPI *glColor3s) (GLshort red, GLshort green, GLshort blue);
-void (WINE_GLAPI *glColor3sv) (const GLshort* v);
-void (WINE_GLAPI *glColor3ub) (GLubyte red, GLubyte green, GLubyte blue);
-void (WINE_GLAPI *glColor3ubv) (const GLubyte* v);
-void (WINE_GLAPI *glColor3ui) (GLuint red, GLuint green, GLuint blue);
-void (WINE_GLAPI *glColor3uiv) (const GLuint* v);
-void (WINE_GLAPI *glColor3us) (GLushort red, GLushort green, GLushort blue);
-void (WINE_GLAPI *glColor3usv) (const GLushort* v);
-void (WINE_GLAPI *glColor4b) (GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha);
-void (WINE_GLAPI *glColor4bv) (const GLbyte* v);
-void (WINE_GLAPI *glColor4d) (GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha);
-void (WINE_GLAPI *glColor4dv) (const GLdouble* v);
-void (WINE_GLAPI *glColor4f) (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
-void (WINE_GLAPI *glColor4fv) (const GLfloat* v);
-void (WINE_GLAPI *glColor4i) (GLint red, GLint green, GLint blue, GLint alpha);
-void (WINE_GLAPI *glColor4iv) (const GLint* v);
-void (WINE_GLAPI *glColor4s) (GLshort red, GLshort green, GLshort blue, GLshort alpha);
-void (WINE_GLAPI *glColor4sv) (const GLshort* v);
-void (WINE_GLAPI *glColor4ub) (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha);
-void (WINE_GLAPI *glColor4ubv) (const GLubyte* v);
-void (WINE_GLAPI *glColor4ui) (GLuint red, GLuint green, GLuint blue, GLuint alpha);
-void (WINE_GLAPI *glColor4uiv) (const GLuint* v);
-void (WINE_GLAPI *glColor4us) (GLushort red, GLushort green, GLushort blue, GLushort alpha);
-void (WINE_GLAPI *glColor4usv) (const GLushort* v);
-void (WINE_GLAPI *glColorMask) (GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha);
-void (WINE_GLAPI *glColorMaterial) (GLenum face, GLenum mode);
-void (WINE_GLAPI *glColorPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid* pointer);
-void (WINE_GLAPI *glCopyPixels) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum type);
-void (WINE_GLAPI *glCopyTexImage1D) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border);
-void (WINE_GLAPI *glCopyTexImage2D) (GLenum target, GLint level, GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border);
-void (WINE_GLAPI *glCopyTexSubImage1D) (GLenum target, GLint level, GLint xoffset, GLint x, GLint y, GLsizei width);
-void (WINE_GLAPI *glCopyTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height);
-void (WINE_GLAPI *glCullFace) (GLenum mode);
-void (WINE_GLAPI *glDeleteLists) (GLuint list, GLsizei range);
-void (WINE_GLAPI *glDeleteTextures) (GLsizei n, const GLuint* textures);
-void (WINE_GLAPI *glDepthFunc) (GLenum func);
-void (WINE_GLAPI *glDepthMask) (GLboolean flag);
-void (WINE_GLAPI *glDepthRange) (GLclampd nearParam, GLclampd farParam);
-void (WINE_GLAPI *glDisable) (GLenum cap);
-void (WINE_GLAPI *glDisableWINE) (GLenum cap);
-void (WINE_GLAPI *glDisableClientState) (GLenum array);
-void (WINE_GLAPI *glDrawArrays) (GLenum mode, GLint first, GLsizei count);
-void (WINE_GLAPI *glDrawBuffer) (GLenum mode);
-void (WINE_GLAPI *glDrawElements) (GLenum mode, GLsizei count, GLenum type, const GLvoid* indices);
-void (WINE_GLAPI *glDrawPixels) (GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels);
-void (WINE_GLAPI *glEdgeFlag) (GLboolean flag);
-void (WINE_GLAPI *glEdgeFlagPointer) (GLsizei stride, const GLvoid* pointer);
-void (WINE_GLAPI *glEdgeFlagv) (const GLboolean* flag);
-void (WINE_GLAPI *glEnable) (GLenum cap);
-void (WINE_GLAPI *glEnableWINE) (GLenum cap);
-void (WINE_GLAPI *glEnableClientState) (GLenum array);
-void (WINE_GLAPI *glEnd) ();
-void (WINE_GLAPI *glEndList) ();
-void (WINE_GLAPI *glEvalCoord1d) (GLdouble u);
-void (WINE_GLAPI *glEvalCoord1dv) (const GLdouble* u);
-void (WINE_GLAPI *glEvalCoord1f) (GLfloat u);
-void (WINE_GLAPI *glEvalCoord1fv) (const GLfloat* u);
-void (WINE_GLAPI *glEvalCoord2d) (GLdouble u, GLdouble v);
-void (WINE_GLAPI *glEvalCoord2dv) (const GLdouble* u);
-void (WINE_GLAPI *glEvalCoord2f) (GLfloat u, GLfloat v);
-void (WINE_GLAPI *glEvalCoord2fv) (const GLfloat* u);
-void (WINE_GLAPI *glEvalMesh1) (GLenum mode, GLint i1, GLint i2);
-void (WINE_GLAPI *glEvalMesh2) (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2);
-void (WINE_GLAPI *glEvalPoint1) (GLint i);
-void (WINE_GLAPI *glEvalPoint2) (GLint i, GLint j);
-void (WINE_GLAPI *glFeedbackBuffer) (GLsizei size, GLenum type, GLfloat* buffer);
-void (WINE_GLAPI *glFogf) (GLenum pname, GLfloat param);
-void (WINE_GLAPI *glFogfv) (GLenum pname, const GLfloat* params);
-void (WINE_GLAPI *glFogi) (GLenum pname, GLint param);
-void (WINE_GLAPI *glFogiv) (GLenum pname, const GLint* params);
-void (WINE_GLAPI *glFrontFace) (GLenum mode);
-void (WINE_GLAPI *glFrustum) (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
-GLuint (WINE_GLAPI *glGenLists) (GLsizei range);
-void (WINE_GLAPI *glGenTextures) (GLsizei n, GLuint* textures);
-void (WINE_GLAPI *glGetBooleanv) (GLenum pname, GLboolean* params);
-void (WINE_GLAPI *glGetClipPlane) (GLenum plane, GLdouble* equation);
-void (WINE_GLAPI *glGetDoublev) (GLenum pname, GLdouble* params);
-GLenum (WINE_GLAPI *glGetError) ();
-void (WINE_GLAPI *glGetFloatv) (GLenum pname, GLfloat* params);
-void (WINE_GLAPI *glGetIntegerv) (GLenum pname, GLint* params);
-void (WINE_GLAPI *glGetLightfv) (GLenum light, GLenum pname, GLfloat* params);
-void (WINE_GLAPI *glGetLightiv) (GLenum light, GLenum pname, GLint* params);
-void (WINE_GLAPI *glGetMapdv) (GLenum target, GLenum query, GLdouble* v);
-void (WINE_GLAPI *glGetMapfv) (GLenum target, GLenum query, GLfloat* v);
-void (WINE_GLAPI *glGetMapiv) (GLenum target, GLenum query, GLint* v);
-void (WINE_GLAPI *glGetMaterialfv) (GLenum face, GLenum pname, GLfloat* params);
-void (WINE_GLAPI *glGetMaterialiv) (GLenum face, GLenum pname, GLint* params);
-void (WINE_GLAPI *glGetPixelMapfv) (GLenum map, GLfloat* values);
-void (WINE_GLAPI *glGetPixelMapuiv) (GLenum map, GLuint* values);
-void (WINE_GLAPI *glGetPixelMapusv) (GLenum map, GLushort* values);
-void (WINE_GLAPI *glGetPointerv) (GLenum pname, GLvoid** params);
-void (WINE_GLAPI *glGetPolygonStipple) (GLubyte* mask);
-const GLubyte * (WINE_GLAPI *glGetString) (GLenum name);
-void (WINE_GLAPI *glGetTexEnvfv) (GLenum target, GLenum pname, GLfloat* params);
-void (WINE_GLAPI *glGetTexEnviv) (GLenum target, GLenum pname, GLint* params);
-void (WINE_GLAPI *glGetTexGendv) (GLenum coord, GLenum pname, GLdouble* params);
-void (WINE_GLAPI *glGetTexGenfv) (GLenum coord, GLenum pname, GLfloat* params);
-void (WINE_GLAPI *glGetTexGeniv) (GLenum coord, GLenum pname, GLint* params);
-void (WINE_GLAPI *glGetTexImage) (GLenum target, GLint level, GLenum format, GLenum type, GLvoid* pixels);
-void (WINE_GLAPI *glGetTexLevelParameterfv) (GLenum target, GLint level, GLenum pname, GLfloat* params);
-void (WINE_GLAPI *glGetTexLevelParameteriv) (GLenum target, GLint level, GLenum pname, GLint* params);
-void (WINE_GLAPI *glGetTexParameterfv) (GLenum target, GLenum pname, GLfloat* params);
-void (WINE_GLAPI *glGetTexParameteriv) (GLenum target, GLenum pname, GLint* params);
-void (WINE_GLAPI *glHint) (GLenum target, GLenum mode);
-void (WINE_GLAPI *glIndexMask) (GLuint mask);
-void (WINE_GLAPI *glIndexPointer) (GLenum type, GLsizei stride, const GLvoid* pointer);
-void (WINE_GLAPI *glIndexd) (GLdouble c);
-void (WINE_GLAPI *glIndexdv) (const GLdouble* c);
-void (WINE_GLAPI *glIndexf) (GLfloat c);
-void (WINE_GLAPI *glIndexfv) (const GLfloat* c);
-void (WINE_GLAPI *glIndexi) (GLint c);
-void (WINE_GLAPI *glIndexiv) (const GLint* c);
-void (WINE_GLAPI *glIndexs) (GLshort c);
-void (WINE_GLAPI *glIndexsv) (const GLshort* c);
-void (WINE_GLAPI *glIndexub) (GLubyte c);
-void (WINE_GLAPI *glIndexubv) (const GLubyte* c);
-void (WINE_GLAPI *glInitNames) ();
-void (WINE_GLAPI *glInterleavedArrays) (GLenum format, GLsizei stride, const GLvoid* pointer);
-GLboolean (WINE_GLAPI *glIsEnabled) (GLenum cap);
-GLboolean (WINE_GLAPI *glIsList) (GLuint list);
-GLboolean (WINE_GLAPI *glIsTexture) (GLuint texture);
-void (WINE_GLAPI *glLightModelf) (GLenum pname, GLfloat param);
-void (WINE_GLAPI *glLightModelfv) (GLenum pname, const GLfloat* params);
-void (WINE_GLAPI *glLightModeli) (GLenum pname, GLint param);
-void (WINE_GLAPI *glLightModeliv) (GLenum pname, const GLint* params);
-void (WINE_GLAPI *glLightf) (GLenum light, GLenum pname, GLfloat param);
-void (WINE_GLAPI *glLightfv) (GLenum light, GLenum pname, const GLfloat* params);
-void (WINE_GLAPI *glLighti) (GLenum light, GLenum pname, GLint param);
-void (WINE_GLAPI *glLightiv) (GLenum light, GLenum pname, const GLint* params);
-void (WINE_GLAPI *glLineStipple) (GLint factor, GLushort pattern);
-void (WINE_GLAPI *glLineWidth) (GLfloat width);
-void (WINE_GLAPI *glListBase) (GLuint base);
-void (WINE_GLAPI *glLoadIdentity) ();
-void (WINE_GLAPI *glLoadMatrixd) (const GLdouble* m);
-void (WINE_GLAPI *glLoadMatrixf) (const GLfloat* m);
-void (WINE_GLAPI *glLoadName) (GLuint name);
-void (WINE_GLAPI *glLogicOp) (GLenum opcode);
-void (WINE_GLAPI *glMap1d) (GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble* points);
-void (WINE_GLAPI *glMap1f) (GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat* points);
-void (WINE_GLAPI *glMap2d) (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble* points);
-void (WINE_GLAPI *glMap2f) (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat* points);
-void (WINE_GLAPI *glMapGrid1d) (GLint un, GLdouble u1, GLdouble u2);
-void (WINE_GLAPI *glMapGrid1f) (GLint un, GLfloat u1, GLfloat u2);
-void (WINE_GLAPI *glMapGrid2d) (GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2);
-void (WINE_GLAPI *glMapGrid2f) (GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2);
-void (WINE_GLAPI *glMaterialf) (GLenum face, GLenum pname, GLfloat param);
-void (WINE_GLAPI *glMaterialfv) (GLenum face, GLenum pname, const GLfloat* params);
-void (WINE_GLAPI *glMateriali) (GLenum face, GLenum pname, GLint param);
-void (WINE_GLAPI *glMaterialiv) (GLenum face, GLenum pname, const GLint* params);
-void (WINE_GLAPI *glMatrixMode) (GLenum mode);
-void (WINE_GLAPI *glMultMatrixd) (const GLdouble* m);
-void (WINE_GLAPI *glMultMatrixf) (const GLfloat* m);
-void (WINE_GLAPI *glNewList) (GLuint list, GLenum mode);
-void (WINE_GLAPI *glNormal3b) (GLbyte nx, GLbyte ny, GLbyte nz);
-void (WINE_GLAPI *glNormal3bv) (const GLbyte* v);
-void (WINE_GLAPI *glNormal3d) (GLdouble nx, GLdouble ny, GLdouble nz);
-void (WINE_GLAPI *glNormal3dv) (const GLdouble* v);
-void (WINE_GLAPI *glNormal3f) (GLfloat nx, GLfloat ny, GLfloat nz);
-void (WINE_GLAPI *glNormal3fv) (const GLfloat* v);
-void (WINE_GLAPI *glNormal3i) (GLint nx, GLint ny, GLint nz);
-void (WINE_GLAPI *glNormal3iv) (const GLint* v);
-void (WINE_GLAPI *glNormal3s) (GLshort nx, GLshort ny, GLshort nz);
-void (WINE_GLAPI *glNormal3sv) (const GLshort* v);
-void (WINE_GLAPI *glNormalPointer) (GLenum type, GLsizei stride, const GLvoid* pointer);
-void (WINE_GLAPI *glOrtho) (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar);
-void (WINE_GLAPI *glPassThrough) (GLfloat token);
-void (WINE_GLAPI *glPixelMapfv) (GLenum map, GLint mapsize, const GLfloat* values);
-void (WINE_GLAPI *glPixelMapuiv) (GLenum map, GLint mapsize, const GLuint* values);
-void (WINE_GLAPI *glPixelMapusv) (GLenum map, GLint mapsize, const GLushort* values);
-void (WINE_GLAPI *glPixelStoref) (GLenum pname, GLfloat param);
-void (WINE_GLAPI *glPixelStorei) (GLenum pname, GLint param);
-void (WINE_GLAPI *glPixelTransferf) (GLenum pname, GLfloat param);
-void (WINE_GLAPI *glPixelTransferi) (GLenum pname, GLint param);
-void (WINE_GLAPI *glPixelZoom) (GLfloat xfactor, GLfloat yfactor);
-void (WINE_GLAPI *glPointSize) (GLfloat size);
-void (WINE_GLAPI *glPolygonMode) (GLenum face, GLenum mode);
-void (WINE_GLAPI *glPolygonOffset) (GLfloat factor, GLfloat units);
-void (WINE_GLAPI *glPolygonStipple) (const GLubyte* mask);
-void (WINE_GLAPI *glPopAttrib) ();
-void (WINE_GLAPI *glPopClientAttrib) ();
-void (WINE_GLAPI *glPopMatrix) ();
-void (WINE_GLAPI *glPopName) ();
-void (WINE_GLAPI *glPrioritizeTextures) (GLsizei n, const GLuint* textures, const GLclampf* priorities);
-void (WINE_GLAPI *glPushAttrib) (GLbitfield mask);
-void (WINE_GLAPI *glPushClientAttrib) (GLbitfield mask);
-void (WINE_GLAPI *glPushMatrix) ();
-void (WINE_GLAPI *glPushName) (GLuint name);
-void (WINE_GLAPI *glRasterPos2d) (GLdouble x, GLdouble y);
-void (WINE_GLAPI *glRasterPos2dv) (const GLdouble* v);
-void (WINE_GLAPI *glRasterPos2f) (GLfloat x, GLfloat y);
-void (WINE_GLAPI *glRasterPos2fv) (const GLfloat* v);
-void (WINE_GLAPI *glRasterPos2i) (GLint x, GLint y);
-void (WINE_GLAPI *glRasterPos2iv) (const GLint* v);
-void (WINE_GLAPI *glRasterPos2s) (GLshort x, GLshort y);
-void (WINE_GLAPI *glRasterPos2sv) (const GLshort* v);
-void (WINE_GLAPI *glRasterPos3d) (GLdouble x, GLdouble y, GLdouble z);
-void (WINE_GLAPI *glRasterPos3dv) (const GLdouble* v);
-void (WINE_GLAPI *glRasterPos3f) (GLfloat x, GLfloat y, GLfloat z);
-void (WINE_GLAPI *glRasterPos3fv) (const GLfloat* v);
-void (WINE_GLAPI *glRasterPos3i) (GLint x, GLint y, GLint z);
-void (WINE_GLAPI *glRasterPos3iv) (const GLint* v);
-void (WINE_GLAPI *glRasterPos3s) (GLshort x, GLshort y, GLshort z);
-void (WINE_GLAPI *glRasterPos3sv) (const GLshort* v);
-void (WINE_GLAPI *glRasterPos4d) (GLdouble x, GLdouble y, GLdouble z, GLdouble w);
-void (WINE_GLAPI *glRasterPos4dv) (const GLdouble* v);
-void (WINE_GLAPI *glRasterPos4f) (GLfloat x, GLfloat y, GLfloat z, GLfloat w);
-void (WINE_GLAPI *glRasterPos4fv) (const GLfloat* v);
-void (WINE_GLAPI *glRasterPos4i) (GLint x, GLint y, GLint z, GLint w);
-void (WINE_GLAPI *glRasterPos4iv) (const GLint* v);
-void (WINE_GLAPI *glRasterPos4s) (GLshort x, GLshort y, GLshort z, GLshort w);
-void (WINE_GLAPI *glRasterPos4sv) (const GLshort* v);
-void (WINE_GLAPI *glReadBuffer) (GLenum mode);
-void (WINE_GLAPI *glReadPixels) (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* pixels);
-void (WINE_GLAPI *glRectd) (GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2);
-void (WINE_GLAPI *glRectdv) (const GLdouble* v1, const GLdouble* v2);
-void (WINE_GLAPI *glRectf) (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2);
-void (WINE_GLAPI *glRectfv) (const GLfloat* v1, const GLfloat* v2);
-void (WINE_GLAPI *glRecti) (GLint x1, GLint y1, GLint x2, GLint y2);
-void (WINE_GLAPI *glRectiv) (const GLint* v1, const GLint* v2);
-void (WINE_GLAPI *glRects) (GLshort x1, GLshort y1, GLshort x2, GLshort y2);
-void (WINE_GLAPI *glRectsv) (const GLshort* v1, const GLshort* v2);
-GLint (WINE_GLAPI *glRenderMode) (GLenum mode);
-void (WINE_GLAPI *glRotated) (GLdouble angle, GLdouble x, GLdouble y, GLdouble z);
-void (WINE_GLAPI *glRotatef) (GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
-void (WINE_GLAPI *glScaled) (GLdouble x, GLdouble y, GLdouble z);
-void (WINE_GLAPI *glScalef) (GLfloat x, GLfloat y, GLfloat z);
-void (WINE_GLAPI *glScissor) (GLint x, GLint y, GLsizei width, GLsizei height);
-void (WINE_GLAPI *glSelectBuffer) (GLsizei size, GLuint* buffer);
-void (WINE_GLAPI *glShadeModel) (GLenum mode);
-void (WINE_GLAPI *glStencilFunc) (GLenum func, GLint ref, GLuint mask);
-void (WINE_GLAPI *glStencilMask) (GLuint mask);
-void (WINE_GLAPI *glStencilOp) (GLenum fail, GLenum zfail, GLenum zpass);
-void (WINE_GLAPI *glTexCoord1d) (GLdouble s);
-void (WINE_GLAPI *glTexCoord1dv) (const GLdouble* v);
-void (WINE_GLAPI *glTexCoord1f) (GLfloat s);
-void (WINE_GLAPI *glTexCoord1fv) (const GLfloat* v);
-void (WINE_GLAPI *glTexCoord1i) (GLint s);
-void (WINE_GLAPI *glTexCoord1iv) (const GLint* v);
-void (WINE_GLAPI *glTexCoord1s) (GLshort s);
-void (WINE_GLAPI *glTexCoord1sv) (const GLshort* v);
-void (WINE_GLAPI *glTexCoord2d) (GLdouble s, GLdouble t);
-void (WINE_GLAPI *glTexCoord2dv) (const GLdouble* v);
-void (WINE_GLAPI *glTexCoord2f) (GLfloat s, GLfloat t);
-void (WINE_GLAPI *glTexCoord2fv) (const GLfloat* v);
-void (WINE_GLAPI *glTexCoord2i) (GLint s, GLint t);
-void (WINE_GLAPI *glTexCoord2iv) (const GLint* v);
-void (WINE_GLAPI *glTexCoord2s) (GLshort s, GLshort t);
-void (WINE_GLAPI *glTexCoord2sv) (const GLshort* v);
-void (WINE_GLAPI *glTexCoord3d) (GLdouble s, GLdouble t, GLdouble r);
-void (WINE_GLAPI *glTexCoord3dv) (const GLdouble* v);
-void (WINE_GLAPI *glTexCoord3f) (GLfloat s, GLfloat t, GLfloat r);
-void (WINE_GLAPI *glTexCoord3fv) (const GLfloat* v);
-void (WINE_GLAPI *glTexCoord3i) (GLint s, GLint t, GLint r);
-void (WINE_GLAPI *glTexCoord3iv) (const GLint* v);
-void (WINE_GLAPI *glTexCoord3s) (GLshort s, GLshort t, GLshort r);
-void (WINE_GLAPI *glTexCoord3sv) (const GLshort* v);
-void (WINE_GLAPI *glTexCoord4d) (GLdouble s, GLdouble t, GLdouble r, GLdouble q);
-void (WINE_GLAPI *glTexCoord4dv) (const GLdouble* v);
-void (WINE_GLAPI *glTexCoord4f) (GLfloat s, GLfloat t, GLfloat r, GLfloat q);
-void (WINE_GLAPI *glTexCoord4fv) (const GLfloat* v);
-void (WINE_GLAPI *glTexCoord4i) (GLint s, GLint t, GLint r, GLint q);
-void (WINE_GLAPI *glTexCoord4iv) (const GLint* v);
-void (WINE_GLAPI *glTexCoord4s) (GLshort s, GLshort t, GLshort r, GLshort q);
-void (WINE_GLAPI *glTexCoord4sv) (const GLshort* v);
-void (WINE_GLAPI *glTexCoordPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid* pointer);
-void (WINE_GLAPI *glTexEnvf) (GLenum target, GLenum pname, GLfloat param);
-void (WINE_GLAPI *glTexEnvfv) (GLenum target, GLenum pname, const GLfloat* params);
-void (WINE_GLAPI *glTexEnvi) (GLenum target, GLenum pname, GLint param);
-void (WINE_GLAPI *glTexEnviv) (GLenum target, GLenum pname, const GLint* params);
-void (WINE_GLAPI *glTexGend) (GLenum coord, GLenum pname, GLdouble param);
-void (WINE_GLAPI *glTexGendv) (GLenum coord, GLenum pname, const GLdouble* params);
-void (WINE_GLAPI *glTexGenf) (GLenum coord, GLenum pname, GLfloat param);
-void (WINE_GLAPI *glTexGenfv) (GLenum coord, GLenum pname, const GLfloat* params);
-void (WINE_GLAPI *glTexGeni) (GLenum coord, GLenum pname, GLint param);
-void (WINE_GLAPI *glTexGeniv) (GLenum coord, GLenum pname, const GLint* params);
-void (WINE_GLAPI *glTexImage1D) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
-void (WINE_GLAPI *glTexImage2D) (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid* pixels);
-void (WINE_GLAPI *glTexParameterf) (GLenum target, GLenum pname, GLfloat param);
-void (WINE_GLAPI *glTexParameterfv) (GLenum target, GLenum pname, const GLfloat* params);
-void (WINE_GLAPI *glTexParameteri) (GLenum target, GLenum pname, GLint param);
-void (WINE_GLAPI *glTexParameteriv) (GLenum target, GLenum pname, const GLint* params);
-void (WINE_GLAPI *glTexSubImage1D) (GLenum target, GLint level, GLint xoffset, GLsizei width, GLenum format, GLenum type, const GLvoid* pixels);
-void (WINE_GLAPI *glTexSubImage2D) (GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid* pixels);
-void (WINE_GLAPI *glTranslated) (GLdouble x, GLdouble y, GLdouble z);
-void (WINE_GLAPI *glTranslatef) (GLfloat x, GLfloat y, GLfloat z);
-void (WINE_GLAPI *glVertex2d) (GLdouble x, GLdouble y);
-void (WINE_GLAPI *glVertex2dv) (const GLdouble* v);
-void (WINE_GLAPI *glVertex2f) (GLfloat x, GLfloat y);
-void (WINE_GLAPI *glVertex2fv) (const GLfloat* v);
-void (WINE_GLAPI *glVertex2i) (GLint x, GLint y);
-void (WINE_GLAPI *glVertex2iv) (const GLint* v);
-void (WINE_GLAPI *glVertex2s) (GLshort x, GLshort y);
-void (WINE_GLAPI *glVertex2sv) (const GLshort* v);
-void (WINE_GLAPI *glVertex3d) (GLdouble x, GLdouble y, GLdouble z);
-void (WINE_GLAPI *glVertex3dv) (const GLdouble* v);
-void (WINE_GLAPI *glVertex3f) (GLfloat x, GLfloat y, GLfloat z);
-void (WINE_GLAPI *glVertex3fv) (const GLfloat* v);
-void (WINE_GLAPI *glVertex3i) (GLint x, GLint y, GLint z);
-void (WINE_GLAPI *glVertex3iv) (const GLint* v);
-void (WINE_GLAPI *glVertex3s) (GLshort x, GLshort y, GLshort z);
-void (WINE_GLAPI *glVertex3sv) (const GLshort* v);
-void (WINE_GLAPI *glVertex4d) (GLdouble x, GLdouble y, GLdouble z, GLdouble w);
-void (WINE_GLAPI *glVertex4dv) (const GLdouble* v);
-void (WINE_GLAPI *glVertex4f) (GLfloat x, GLfloat y, GLfloat z, GLfloat w);
-void (WINE_GLAPI *glVertex4fv) (const GLfloat* v);
-void (WINE_GLAPI *glVertex4i) (GLint x, GLint y, GLint z, GLint w);
-void (WINE_GLAPI *glVertex4iv) (const GLint* v);
-void (WINE_GLAPI *glVertex4s) (GLshort x, GLshort y, GLshort z, GLshort w);
-void (WINE_GLAPI *glVertex4sv) (const GLshort* v);
-void (WINE_GLAPI *glVertexPointer) (GLint size, GLenum type, GLsizei stride, const GLvoid* pointer);
-void (WINE_GLAPI *glViewport) (GLint x, GLint y, GLsizei width, GLsizei height);
-void (WINE_GLAPI *glPointParameterfv) (GLenum pname, const GLfloat *params);
+void (WINE_GLAPI *glAccum)(GLenum op, GLfloat value) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glAlphaFunc)(GLenum func, GLclampf ref) DECLSPEC_HIDDEN;
+GLboolean (WINE_GLAPI *glAreTexturesResident)(GLsizei n, const GLuint *textures, GLboolean *residences) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glArrayElement)(GLint i) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glBegin)(GLenum mode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glBindTexture)(GLenum target, GLuint texture) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glBitmap)(GLsizei width, GLsizei height, GLfloat xorig,
+        GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glBlendFunc)(GLenum sfactor, GLenum dfactor) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glCallList)(GLuint list) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glCallLists)(GLsizei n, GLenum type, const GLvoid *lists) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glClear)(GLbitfield mask) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glClearAccum)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glClearColor)(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glClearDepth)(GLclampd depth) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glClearIndex)(GLfloat c) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glClearStencil)(GLint s) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glClipPlane)(GLenum plane, const GLdouble *equation) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3b)(GLbyte red, GLbyte green, GLbyte blue) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3bv)(const GLbyte *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3d)(GLdouble red, GLdouble green, GLdouble blue) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3f)(GLfloat red, GLfloat green, GLfloat blue) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3i)(GLint red, GLint green, GLint blue) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3s)(GLshort red, GLshort green, GLshort blue) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3ub)(GLubyte red, GLubyte green, GLubyte blue) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3ubv)(const GLubyte *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3ui)(GLuint red, GLuint green, GLuint blue) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3uiv)(const GLuint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3us)(GLushort red, GLushort green, GLushort blue) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor3usv)(const GLushort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4b)(GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4bv)(const GLbyte *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4d)(GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4f)(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4i)(GLint red, GLint green, GLint blue, GLint alpha) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4s)(GLshort red, GLshort green, GLshort blue, GLshort alpha) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4ub)(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4ubv)(const GLubyte *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4ui)(GLuint red, GLuint green, GLuint blue, GLuint alpha) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4uiv)(const GLuint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4us)(GLushort red, GLushort green, GLushort blue, GLushort alpha) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColor4usv)(const GLushort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColorMask)(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColorMaterial)(GLenum face, GLenum mode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glColorPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glCopyPixels)(GLint x, GLint y, GLsizei width, GLsizei height, GLenum type) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glCopyTexImage1D)(GLenum target, GLint level,
+        GLenum internalformat, GLint x, GLint y, GLsizei width, GLint border) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glCopyTexImage2D)(GLenum target, GLint level,
+        GLenum internalformat, GLint x, GLint y, GLsizei width, GLsizei height, GLint border) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glCopyTexSubImage1D)(GLenum target, GLint level,
+        GLint xoffset, GLint x, GLint y, GLsizei width) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glCopyTexSubImage2D)(GLenum target, GLint level,
+        GLint xoffset, GLint yoffset, GLint x, GLint y, GLsizei width, GLsizei height) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glCullFace)(GLenum mode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glDeleteLists)(GLuint list, GLsizei range) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glDeleteTextures)(GLsizei n, const GLuint *textures) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glDepthFunc)(GLenum func) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glDepthMask)(GLboolean flag) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glDepthRange)(GLclampd nearParam, GLclampd farParam) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glDisable)(GLenum cap) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glDisableWINE)(GLenum cap) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glDisableClientState)(GLenum array) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glDrawArrays)(GLenum mode, GLint first, GLsizei count) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glDrawBuffer)(GLenum mode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glDrawElements)(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glDrawPixels)(GLsizei width, GLsizei height, GLenum format,
+        GLenum type, const GLvoid *pixels) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEdgeFlag)(GLboolean flag) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEdgeFlagPointer)(GLsizei stride, const GLvoid *pointer) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEdgeFlagv)(const GLboolean *flag) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEnable)(GLenum cap) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEnableWINE)(GLenum cap) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEnableClientState)(GLenum array) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEnd)(void) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEndList)(void) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEvalCoord1d)(GLdouble u) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEvalCoord1dv)(const GLdouble *u) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEvalCoord1f)(GLfloat u) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEvalCoord1fv)(const GLfloat *u) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEvalCoord2d)(GLdouble u, GLdouble v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEvalCoord2dv)(const GLdouble *u) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEvalCoord2f)(GLfloat u, GLfloat v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEvalCoord2fv)(const GLfloat *u) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEvalMesh1)(GLenum mode, GLint i1, GLint i2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEvalMesh2)(GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEvalPoint1)(GLint i) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glEvalPoint2)(GLint i, GLint j) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glFeedbackBuffer)(GLsizei size, GLenum type, GLfloat *buffer) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glFogf)(GLenum pname, GLfloat param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glFogfv)(GLenum pname, const GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glFogi)(GLenum pname, GLint param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glFogiv)(GLenum pname, const GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glFrontFace)(GLenum mode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glFrustum)(GLdouble left, GLdouble right, GLdouble bottom,
+        GLdouble top, GLdouble zNear, GLdouble zFar) DECLSPEC_HIDDEN;
+GLuint (WINE_GLAPI *glGenLists)(GLsizei range) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGenTextures)(GLsizei n, GLuint *textures) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetBooleanv)(GLenum pname, GLboolean *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetClipPlane)(GLenum plane, GLdouble *equation) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetDoublev)(GLenum pname, GLdouble *params) DECLSPEC_HIDDEN;
+GLenum (WINE_GLAPI *glGetError)(void) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetFloatv)(GLenum pname, GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetIntegerv)(GLenum pname, GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetLightfv)(GLenum light, GLenum pname, GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetLightiv)(GLenum light, GLenum pname, GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetMapdv)(GLenum target, GLenum query, GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetMapfv)(GLenum target, GLenum query, GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetMapiv)(GLenum target, GLenum query, GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetMaterialfv)(GLenum face, GLenum pname, GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetMaterialiv)(GLenum face, GLenum pname, GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetPixelMapfv)(GLenum map, GLfloat *values) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetPixelMapuiv)(GLenum map, GLuint *values) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetPixelMapusv)(GLenum map, GLushort *values) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetPointerv)(GLenum pname, GLvoid **params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetPolygonStipple)(GLubyte *mask) DECLSPEC_HIDDEN;
+const GLubyte * (WINE_GLAPI *glGetString)(GLenum name) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetTexEnvfv)(GLenum target, GLenum pname, GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetTexEnviv)(GLenum target, GLenum pname, GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetTexGendv)(GLenum coord, GLenum pname, GLdouble *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetTexGenfv)(GLenum coord, GLenum pname, GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetTexGeniv)(GLenum coord, GLenum pname, GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetTexImage)(GLenum target, GLint level, GLenum format,
+        GLenum type, GLvoid *pixels) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetTexLevelParameterfv)(GLenum target, GLint level, GLenum pname, GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetTexLevelParameteriv)(GLenum target, GLint level, GLenum pname, GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetTexParameterfv)(GLenum target, GLenum pname, GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glGetTexParameteriv)(GLenum target, GLenum pname, GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glHint)(GLenum target, GLenum mode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glIndexMask)(GLuint mask) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glIndexPointer)(GLenum type, GLsizei stride, const GLvoid *pointer) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glIndexd)(GLdouble c) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glIndexdv)(const GLdouble *c) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glIndexf)(GLfloat c) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glIndexfv)(const GLfloat *c) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glIndexi)(GLint c) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glIndexiv)(const GLint *c) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glIndexs)(GLshort c) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glIndexsv)(const GLshort *c) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glIndexub)(GLubyte c) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glIndexubv)(const GLubyte *c) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glInitNames)(void) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glInterleavedArrays)(GLenum format, GLsizei stride, const GLvoid *pointer) DECLSPEC_HIDDEN;
+GLboolean (WINE_GLAPI *glIsEnabled)(GLenum cap) DECLSPEC_HIDDEN;
+GLboolean (WINE_GLAPI *glIsList)(GLuint list) DECLSPEC_HIDDEN;
+GLboolean (WINE_GLAPI *glIsTexture)(GLuint texture) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLightModelf)(GLenum pname, GLfloat param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLightModelfv)(GLenum pname, const GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLightModeli)(GLenum pname, GLint param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLightModeliv)(GLenum pname, const GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLightf)(GLenum light, GLenum pname, GLfloat param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLightfv)(GLenum light, GLenum pname, const GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLighti)(GLenum light, GLenum pname, GLint param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLightiv)(GLenum light, GLenum pname, const GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLineStipple)(GLint factor, GLushort pattern) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLineWidth)(GLfloat width) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glListBase)(GLuint base) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLoadIdentity)(void) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLoadMatrixd)(const GLdouble *m) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLoadMatrixf)(const GLfloat *m) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLoadName)(GLuint name) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glLogicOp)(GLenum opcode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMap1d)(GLenum target, GLdouble u1, GLdouble u2,
+        GLint stride, GLint order, const GLdouble *points) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMap1f)(GLenum target, GLfloat u1, GLfloat u2, GLint stride,
+        GLint order, const GLfloat *points) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMap2d)(GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder,
+        GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMap2f)(GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder,
+        GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMapGrid1d)(GLint un, GLdouble u1, GLdouble u2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMapGrid1f)(GLint un, GLfloat u1, GLfloat u2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMapGrid2d)(GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMapGrid2f)(GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMaterialf)(GLenum face, GLenum pname, GLfloat param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMaterialfv)(GLenum face, GLenum pname, const GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMateriali)(GLenum face, GLenum pname, GLint param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMaterialiv)(GLenum face, GLenum pname, const GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMatrixMode)(GLenum mode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMultMatrixd)(const GLdouble *m) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glMultMatrixf)(const GLfloat *m) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glNewList)(GLuint list, GLenum mode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glNormal3b)(GLbyte nx, GLbyte ny, GLbyte nz) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glNormal3bv)(const GLbyte *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glNormal3d)(GLdouble nx, GLdouble ny, GLdouble nz) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glNormal3dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glNormal3f)(GLfloat nx, GLfloat ny, GLfloat nz) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glNormal3fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glNormal3i)(GLint nx, GLint ny, GLint nz) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glNormal3iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glNormal3s)(GLshort nx, GLshort ny, GLshort nz) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glNormal3sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glNormalPointer)(GLenum type, GLsizei stride, const GLvoid *pointer) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glOrtho)(GLdouble left, GLdouble right, GLdouble bottom,
+        GLdouble top, GLdouble zNear, GLdouble zFar) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPassThrough)(GLfloat token) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPixelMapfv)(GLenum map, GLint mapsize, const GLfloat *values) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPixelMapuiv)(GLenum map, GLint mapsize, const GLuint *values) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPixelMapusv)(GLenum map, GLint mapsize, const GLushort *values) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPixelStoref)(GLenum pname, GLfloat param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPixelStorei)(GLenum pname, GLint param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPixelTransferf)(GLenum pname, GLfloat param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPixelTransferi)(GLenum pname, GLint param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPixelZoom)(GLfloat xfactor, GLfloat yfactor) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPointSize)(GLfloat size) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPolygonMode)(GLenum face, GLenum mode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPolygonOffset)(GLfloat factor, GLfloat units) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPolygonStipple)(const GLubyte *mask) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPopAttrib)(void) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPopClientAttrib)(void) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPopMatrix)(void) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPopName)(void) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPrioritizeTextures)(GLsizei n, const GLuint *textures, const GLclampf *priorities) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPushAttrib)(GLbitfield mask) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPushClientAttrib)(GLbitfield mask) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPushMatrix)(void) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPushName)(GLuint name) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos2d)(GLdouble x, GLdouble y) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos2dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos2f)(GLfloat x, GLfloat y) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos2fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos2i)(GLint x, GLint y) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos2iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos2s)(GLshort x, GLshort y) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos2sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos3d)(GLdouble x, GLdouble y, GLdouble z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos3dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos3f)(GLfloat x, GLfloat y, GLfloat z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos3fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos3i)(GLint x, GLint y, GLint z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos3iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos3s)(GLshort x, GLshort y, GLshort z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos3sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos4d)(GLdouble x, GLdouble y, GLdouble z, GLdouble w) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos4dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos4fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos4i)(GLint x, GLint y, GLint z, GLint w) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos4iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos4s)(GLshort x, GLshort y, GLshort z, GLshort w) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRasterPos4sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glReadBuffer)(GLenum mode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glReadPixels)(GLint x, GLint y, GLsizei width, GLsizei height,
+        GLenum format, GLenum type, GLvoid *pixels) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRectd)(GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRectdv)(const GLdouble *v1, const GLdouble *v2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRectf)(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRectfv)(const GLfloat *v1, const GLfloat *v2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRecti)(GLint x1, GLint y1, GLint x2, GLint y2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRectiv)(const GLint *v1, const GLint *v2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRects)(GLshort x1, GLshort y1, GLshort x2, GLshort y2) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRectsv)(const GLshort *v1, const GLshort *v2) DECLSPEC_HIDDEN;
+GLint (WINE_GLAPI *glRenderMode)(GLenum mode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRotated)(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glRotatef)(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glScaled)(GLdouble x, GLdouble y, GLdouble z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glScalef)(GLfloat x, GLfloat y, GLfloat z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glScissor)(GLint x, GLint y, GLsizei width, GLsizei height) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glSelectBuffer)(GLsizei size, GLuint *buffer) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glShadeModel)(GLenum mode) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glStencilFunc)(GLenum func, GLint ref, GLuint mask) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glStencilMask)(GLuint mask) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glStencilOp)(GLenum fail, GLenum zfail, GLenum zpass) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord1d)(GLdouble s) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord1dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord1f)(GLfloat s) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord1fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord1i)(GLint s) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord1iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord1s)(GLshort s) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord1sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord2d)(GLdouble s, GLdouble t) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord2dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord2f)(GLfloat s, GLfloat t) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord2fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord2i)(GLint s, GLint t) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord2iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord2s)(GLshort s, GLshort t) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord2sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord3d)(GLdouble s, GLdouble t, GLdouble r) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord3dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord3f)(GLfloat s, GLfloat t, GLfloat r) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord3fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord3i)(GLint s, GLint t, GLint r) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord3iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord3s)(GLshort s, GLshort t, GLshort r) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord3sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord4d)(GLdouble s, GLdouble t, GLdouble r, GLdouble q) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord4dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord4f)(GLfloat s, GLfloat t, GLfloat r, GLfloat q) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord4fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord4i)(GLint s, GLint t, GLint r, GLint q) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord4iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord4s)(GLshort s, GLshort t, GLshort r, GLshort q) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoord4sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexCoordPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexEnvf)(GLenum target, GLenum pname, GLfloat param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexEnvfv)(GLenum target, GLenum pname, const GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexEnvi)(GLenum target, GLenum pname, GLint param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexEnviv)(GLenum target, GLenum pname, const GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexGend)(GLenum coord, GLenum pname, GLdouble param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexGendv)(GLenum coord, GLenum pname, const GLdouble *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexGenf)(GLenum coord, GLenum pname, GLfloat param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexGenfv)(GLenum coord, GLenum pname, const GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexGeni)(GLenum coord, GLenum pname, GLint param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexGeniv)(GLenum coord, GLenum pname, const GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexImage1D)(GLenum target, GLint level, GLint internalformat, GLsizei width,
+        GLint border, GLenum format, GLenum type, const GLvoid *pixels) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width,
+        GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexParameterf)(GLenum target, GLenum pname, GLfloat param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexParameterfv)(GLenum target, GLenum pname, const GLfloat *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexParameteri)(GLenum target, GLenum pname, GLint param) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexParameteriv)(GLenum target, GLenum pname, const GLint *params) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexSubImage1D)(GLenum target, GLint level, GLint xoffset,
+        GLsizei width, GLenum format, GLenum type, const GLvoid *pixels) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTexSubImage2D)(GLenum target, GLint level, GLint xoffset, GLint yoffset,
+        GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTranslated)(GLdouble x, GLdouble y, GLdouble z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glTranslatef)(GLfloat x, GLfloat y, GLfloat z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex2d)(GLdouble x, GLdouble y) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex2dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex2f)(GLfloat x, GLfloat y) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex2fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex2i)(GLint x, GLint y) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex2iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex2s)(GLshort x, GLshort y) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex2sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex3d)(GLdouble x, GLdouble y, GLdouble z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex3dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex3f)(GLfloat x, GLfloat y, GLfloat z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex3fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex3i)(GLint x, GLint y, GLint z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex3iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex3s)(GLshort x, GLshort y, GLshort z) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex3sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex4d)(GLdouble x, GLdouble y, GLdouble z, GLdouble w) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex4dv)(const GLdouble *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex4f)(GLfloat x, GLfloat y, GLfloat z, GLfloat w) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex4fv)(const GLfloat *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex4i)(GLint x, GLint y, GLint z, GLint w) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex4iv)(const GLint *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex4s)(GLshort x, GLshort y, GLshort z, GLshort w) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertex4sv)(const GLshort *v) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glVertexPointer)(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glViewport)(GLint x, GLint y, GLsizei width, GLsizei height) DECLSPEC_HIDDEN;
+void (WINE_GLAPI *glPointParameterfv)(GLenum pname, const GLfloat *params) DECLSPEC_HIDDEN;
 
 /* glFinish and glFlush are always loaded from opengl32.dll, thus they always have
- * __stdcall calling convention
+ * __stdcall calling convention.
+ *
+ * They are wgl functions and must not be called inside the gl lock, give them a
+ * name that makes this clear
  */
-void (__stdcall  *glFinish) ();
-void (__stdcall  *glFlush) ();
+void (__stdcall *wglFinish)(void) DECLSPEC_HIDDEN;
+void (__stdcall *wglFlush)(void) DECLSPEC_HIDDEN;
 
 /* WGL functions */
-HGLRC   (WINAPI *pwglCreateContext)(HDC);
-BOOL    (WINAPI *pwglDeleteContext)(HGLRC);
-HGLRC   (WINAPI *pwglGetCurrentContext)(void);
-HDC     (WINAPI *pwglGetCurrentDC)(void);
-PROC    (WINAPI *pwglGetProcAddress)(LPCSTR);
-BOOL    (WINAPI *pwglMakeCurrent)(HDC,HGLRC);
-BOOL    (WINAPI *pwglShareLists)(HGLRC,HGLRC);
+HGLRC (WINAPI *pwglCreateContext)(HDC) DECLSPEC_HIDDEN;
+BOOL (WINAPI *pwglDeleteContext)(HGLRC) DECLSPEC_HIDDEN;
+HGLRC (WINAPI *pwglGetCurrentContext)(void) DECLSPEC_HIDDEN;
+HDC (WINAPI *pwglGetCurrentDC)(void) DECLSPEC_HIDDEN;
+PROC (WINAPI *pwglGetProcAddress)(LPCSTR) DECLSPEC_HIDDEN;
+BOOL (WINAPI *pwglMakeCurrent)(HDC, HGLRC) DECLSPEC_HIDDEN;
+BOOL (WINAPI *pwglShareLists)(HGLRC, HGLRC) DECLSPEC_HIDDEN;
 
 #define GL_FUNCS_GEN \
@@ -1535,4 +1556,10 @@
 #endif
 
+/* GL_ARB_depth_clamp */
+#ifndef GL_ARB_depth_clamp
+#define GL_ARB_depth_clamp 1
+#define GL_DEPTH_CLAMP                    0x864f
+#endif
+
 /* GL_ARB_depth_texture */
 #ifndef GL_ARB_depth_texture
@@ -1567,4 +1594,112 @@
 #endif
 typedef void (WINE_GLAPI *PGLFNDRAWBUFFERSARBPROC) (GLsizei n, const GLenum *bufs);
+
+/* GL_ARB_framebuffer_object */
+#ifndef GL_ARB_framebuffer_object
+#define GL_ARB_framebuffer_object 1
+#define GL_FRAMEBUFFER                                      0x8d40
+#define GL_READ_FRAMEBUFFER                                 0x8ca8
+#define GL_DRAW_FRAMEBUFFER                                 0x8ca9
+#define GL_RENDERBUFFER                                     0x8d41
+#define GL_STENCIL_INDEX1                                   0x8d46
+#define GL_STENCIL_INDEX4                                   0x8d47
+#define GL_STENCIL_INDEX8                                   0x8d48
+#define GL_STENCIL_INDEX16                                  0x8d49
+#define GL_RENDERBUFFER_WIDTH                               0x8d42
+#define GL_RENDERBUFFER_HEIGHT                              0x8d43
+#define GL_RENDERBUFFER_INTERNAL_FORMAT                     0x8d44
+#define GL_RENDERBUFFER_RED_SIZE                            0x8d50
+#define GL_RENDERBUFFER_GREEN_SIZE                          0x8d51
+#define GL_RENDERBUFFER_BLUE_SIZE                           0x8d52
+#define GL_RENDERBUFFER_ALPHA_SIZE                          0x8d53
+#define GL_RENDERBUFFER_DEPTH_SIZE                          0x8d54
+#define GL_RENDERBUFFER_STENCIL_SIZE                        0x8d55
+#define GL_RENDERBUFFER_SAMPLES                             0x8cab
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE               0x8cd0
+#define GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME               0x8cd1
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL             0x8cd2
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE     0x8cd3
+#define GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER             0x8cd4
+#define GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING            0x8210
+#define GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE            0x8211
+#define GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE                  0x8212
+#define GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE                0x8213
+#define GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE                 0x8214
+#define GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE                0x8215
+#define GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE                0x8216
+#define GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE              0x8217
+#define GL_SRGB                                             0x8c40
+#define GL_UNSIGNED_NORMALIZED                              0x8c17
+#define GL_FRAMEBUFFER_DEFAULT                              0x8218
+#define GL_INDEX                                            0x8222
+#define GL_COLOR_ATTACHMENT0                                0x8ce0
+#define GL_COLOR_ATTACHMENT1                                0x8ce1
+#define GL_COLOR_ATTACHMENT2                                0x8ce2
+#define GL_COLOR_ATTACHMENT3                                0x8ce3
+#define GL_COLOR_ATTACHMENT4                                0x8ce4
+#define GL_COLOR_ATTACHMENT5                                0x8ce5
+#define GL_COLOR_ATTACHMENT6                                0x8ce6
+#define GL_COLOR_ATTACHMENT7                                0x8ce7
+#define GL_COLOR_ATTACHMENT8                                0x8ce8
+#define GL_COLOR_ATTACHMENT9                                0x8ce9
+#define GL_COLOR_ATTACHMENT10                               0x8cea
+#define GL_COLOR_ATTACHMENT11                               0x8ceb
+#define GL_COLOR_ATTACHMENT12                               0x8cec
+#define GL_COLOR_ATTACHMENT13                               0x8ced
+#define GL_COLOR_ATTACHMENT14                               0x8cee
+#define GL_COLOR_ATTACHMENT15                               0x8cef
+#define GL_DEPTH_ATTACHMENT                                 0x8d00
+#define GL_STENCIL_ATTACHMENT                               0x8d20
+#define GL_DEPTH_STENCIL_ATTACHMENT                         0x821a
+#define GL_MAX_SAMPLES                                      0x8d57
+#define GL_FRAMEBUFFER_COMPLETE                             0x8cd5
+#define GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT                0x8cd6
+#define GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT        0x8cd7
+#define GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER               0x8cdb
+#define GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER               0x8cdc
+#define GL_FRAMEBUFFER_UNSUPPORTED                          0x8cdd
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE               0x8d56
+#define GL_FRAMEBUFFER_UNDEFINED                            0x8219
+#define GL_FRAMEBUFFER_BINDING                              0x8ca6
+#define GL_DRAW_FRAMEBUFFER_BINDING                         0x8ca6
+#define GL_READ_FRAMEBUFFER_BINDING                         0x8caa
+#define GL_RENDERBUFFER_BINDING                             0x8ca7
+#define GL_MAX_COLOR_ATTACHMENTS                            0x8cdf
+#define GL_MAX_RENDERBUFFER_SIZE                            0x84e8
+#define GL_INVALID_FRAMEBUFFER_OPERATION                    0x0506
+#define GL_DEPTH_STENCIL                                    0x84f9
+#define GL_UNSIGNED_INT_24_8                                0x84fa
+#define GL_DEPTH24_STENCIL8                                 0x88f0
+#define GL_TEXTURE_STENCIL_SIZE                             0x88f1
+#endif
+typedef GLboolean (WINE_GLAPI * PGLFNGLISRENDERBUFFERPROC)(GLuint renderbuffer);
+typedef void (WINE_GLAPI * PGLFNGLBINDRENDERBUFFERPROC)(GLenum target, GLuint renderbuffer);
+typedef void (WINE_GLAPI * PGLFNGLDELETERENDERBUFFERSPROC)(GLsizei n, const GLuint *renderbuffers);
+typedef void (WINE_GLAPI * PGLFNGLGENRENDERBUFFERSPROC)(GLsizei n, GLuint *renderbuffers);
+typedef void (WINE_GLAPI * PGLFNGLRENDERBUFFERSTORAGEPROC)(GLenum target, GLenum internalformat,
+        GLsizei width, GLsizei height);
+typedef void (WINE_GLAPI * PGLFNRENDERBUFFERSTORAGEMULTISAMPLEPROC)(GLenum target, GLsizei samples,
+        GLenum internalformat, GLsizei width, GLsizei height);
+typedef void (WINE_GLAPI * PGLFNGLGETRENDERBUFFERPARAMETERIVPROC)(GLenum target, GLenum pname, GLint *params);
+typedef GLboolean (WINE_GLAPI * PGLFNGLISFRAMEBUFFERPROC)(GLuint framebuffer);
+typedef void (WINE_GLAPI * PGLFNGLBINDFRAMEBUFFERPROC)(GLenum target, GLuint framebuffer);
+typedef void (WINE_GLAPI * PGLFNGLDELETEFRAMEBUFFERSPROC)(GLsizei n, const GLuint *framebuffers);
+typedef void (WINE_GLAPI * PGLFNGLGENFRAMEBUFFERSPROC)(GLsizei n, GLuint *framebuffers);
+typedef GLenum (WINE_GLAPI * PGLFNGLCHECKFRAMEBUFFERSTATUSPROC)(GLenum target);
+typedef void (WINE_GLAPI * PGLFNGLFRAMEBUFFERTEXTURE1DPROC)(GLenum target, GLenum attachment,
+        GLenum textarget, GLuint texture, GLint level);
+typedef void (WINE_GLAPI * PGLFNGLFRAMEBUFFERTEXTURE2DPROC)(GLenum target, GLenum attachment,
+        GLenum textarget, GLuint texture, GLint level);
+typedef void (WINE_GLAPI * PGLFNGLFRAMEBUFFERTEXTURE3DPROC)(GLenum target, GLenum attachment,
+        GLenum textarget, GLuint texture, GLint level, GLint layer);
+typedef void (WINE_GLAPI * PGLFNGLFRAMEBUFFERTEXTURELAYERPROC)(GLenum target, GLenum attachment,
+        GLuint texture, GLint level, GLint layer);
+typedef void (WINE_GLAPI * PGLFNGLFRAMEBUFFERRENDERBUFFERPROC)(GLenum target, GLenum attachment,
+        GLenum renderbuffertarget, GLuint renderbuffer);
+typedef void (WINE_GLAPI * PGLFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC)(GLenum target, GLenum attachment,
+        GLenum pname, GLint *params);
+typedef void (WINE_GLAPI * PGLFNGLBLITFRAMEBUFFERPROC)(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
+        GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
+typedef void (WINE_GLAPI * PGLFNGLGENERATEMIPMAPPROC)(GLenum target);
 
 /* GL_ARB_geometry_shader4 */
@@ -1759,4 +1894,15 @@
 typedef void (WINE_GLAPI * PGLFNGLPOINTPARAMETERFARBPROC) (GLenum pname, GLfloat param);
 typedef void (WINE_GLAPI * PGLFNGLPOINTPARAMETERFVARBPROC) (GLenum pname, const GLfloat *params);
+
+/* GL_ARB_provoking_vertex */
+#ifndef GL_ARB_provoking_vertex
+#define GL_ARB_provoking_vertex 1
+#define GL_FIRST_VERTEX_CONVENTION                      0x8e4d
+#define GL_LAST_VERTEX_CONVENTION                       0x8e4e
+#define GL_PROVOKING_VERTEX                             0x8e4f
+#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION     0x8e4c
+#endif
+typedef void (WINE_GLAPI * PGLFNGLPROVOKINGVERTEXPROC)(GLenum mode);
+
 /* GL_ARB_vertex_blend */
 #ifndef GL_ARB_vertex_blend
@@ -1962,4 +2108,15 @@
 typedef void (WINE_GLAPI * PGLFNGLPOINTPARAMETERFEXTPROC) (GLenum pname, GLfloat param);
 typedef void (WINE_GLAPI * PGLFNGLPOINTPARAMETERFVEXTPROC) (GLenum pname, const GLfloat *params);
+
+/* GL_EXT_provoking_vertex */
+#ifndef GL_EXT_provoking_vertex
+#define GL_EXT_provoking_vertex 1
+#define GL_FIRST_VERTEX_CONVENTION_EXT                      0x8e4d
+#define GL_LAST_VERTEX_CONVENTION_EXT                       0x8e4e
+#define GL_PROVOKING_VERTEX_EXT                             0x8e4f
+#define GL_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION_EXT     0x8e4c
+#endif
+typedef void (WINE_GLAPI * PGLFNGLPROVOKINGVERTEXEXTPROC)(GLenum mode);
+
 /* GL_EXT_texture3D */
 #ifndef GL_EXT_texture3D
@@ -3021,6 +3178,6 @@
 typedef void (WINE_GLAPI *PGLFNBINDFRAGMENTSHADERATI) (GLuint id);
 typedef void (WINE_GLAPI *PGLFNDELETEFRAGMENTSHADERATI) (GLuint id);
-typedef void (WINE_GLAPI *PGLFNBEGINFRAGMENTSHADERATI) ();
-typedef void (WINE_GLAPI *PGLFNENDFRAGMENTSHADERATI) ();
+typedef void (WINE_GLAPI *PGLFNBEGINFRAGMENTSHADERATI) (void);
+typedef void (WINE_GLAPI *PGLFNENDFRAGMENTSHADERATI) (void);
 typedef void (WINE_GLAPI *PGLFNPASSTEXCOORDATI) (GLuint dst, GLuint coord, GLenum swizzle);
 typedef void (WINE_GLAPI *PGLFNSAMPLEMAPATI) (GLuint dst, GLuint interp, GLenum swizzle);
@@ -3393,27 +3550,4 @@
 #define WINE_DEFAULT_VIDMEM 64*1024*1024
 
-typedef enum _GL_VSVersion {
-  VS_VERSION_NOT_SUPPORTED = 0x0,
-  VS_VERSION_10 = 0x10,
-  VS_VERSION_11 = 0x11,
-  VS_VERSION_20 = 0x20,
-  VS_VERSION_30 = 0x30,
-  /*Force 32-bits*/
-  VS_VERSION_FORCE_DWORD = 0x7FFFFFFF
-} GL_VSVersion;
-
-typedef enum _GL_PSVersion {
-  PS_VERSION_NOT_SUPPORTED = 0x0,
-  PS_VERSION_10 = 0x10,
-  PS_VERSION_11 = 0x11,
-  PS_VERSION_12 = 0x12,
-  PS_VERSION_13 = 0x13,
-  PS_VERSION_14 = 0x14,
-  PS_VERSION_20 = 0x20,
-  PS_VERSION_30 = 0x30,
-  /*Force 32-bits*/
-  PS_VERSION_FORCE_DWORD = 0x7FFFFFFF
-} GL_PSVersion;
-
 #define MAKEDWORD_VERSION(maj, min)  ((maj & 0x0000FFFF) << 16) | (min & 0x0000FFFF)
 
@@ -3424,8 +3558,10 @@
   ARB_COLOR_BUFFER_FLOAT,
   ARB_DEPTH_BUFFER_FLOAT,
+  ARB_DEPTH_CLAMP,
   ARB_DEPTH_TEXTURE,
   ARB_DRAW_BUFFERS,
   ARB_FRAGMENT_PROGRAM,
   ARB_FRAGMENT_SHADER,
+  ARB_FRAMEBUFFER_OBJECT,
   ARB_GEOMETRY_SHADER4,
   ARB_IMAGING,
@@ -3434,4 +3570,5 @@
   ARB_OCCLUSION_QUERY,
   ARB_POINT_PARAMETERS,
+  ARB_PROVOKING_VERTEX,
   ARB_PIXEL_BUFFER_OBJECT,
   ARB_POINT_SPRITE,
@@ -3468,4 +3605,5 @@
   EXT_PIXEL_BUFFER_OBJECT,
   EXT_POINT_PARAMETERS,
+  EXT_PROVOKING_VERTEX,
   EXT_SECONDARY_COLOR,
   EXT_STENCIL_TWO_SIDE,
@@ -3544,4 +3682,25 @@
     /* GL_ARB_draw_buffers */ \
     USE_GL_FUNC(PGLFNDRAWBUFFERSARBPROC,                            glDrawBuffersARB,                           ARB_DRAW_BUFFERS,       NULL )\
+    /* GL_ARB_framebuffer_object */ \
+    USE_GL_FUNC(PGLFNGLISRENDERBUFFERPROC,                          glIsRenderbuffer,                           ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLBINDRENDERBUFFERPROC,                        glBindRenderbuffer,                         ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLDELETERENDERBUFFERSPROC,                     glDeleteRenderbuffers,                      ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLGENRENDERBUFFERSPROC,                        glGenRenderbuffers,                         ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLRENDERBUFFERSTORAGEPROC,                     glRenderbufferStorage,                      ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNRENDERBUFFERSTORAGEMULTISAMPLEPROC,            glRenderbufferStorageMultisample,           ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLGETRENDERBUFFERPARAMETERIVPROC,              glGetRenderbufferParameteriv,               ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLISFRAMEBUFFERPROC,                           glIsFramebuffer,                            ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLBINDFRAMEBUFFERPROC,                         glBindFramebuffer,                          ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLDELETEFRAMEBUFFERSPROC,                      glDeleteFramebuffers,                       ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLGENFRAMEBUFFERSPROC,                         glGenFramebuffers,                          ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLCHECKFRAMEBUFFERSTATUSPROC,                  glCheckFramebufferStatus,                   ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLFRAMEBUFFERTEXTURE1DPROC,                    glFramebufferTexture1D,                     ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLFRAMEBUFFERTEXTURE2DPROC,                    glFramebufferTexture2D,                     ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLFRAMEBUFFERTEXTURE3DPROC,                    glFramebufferTexture3D,                     ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLFRAMEBUFFERTEXTURELAYERPROC,                 glFramebufferTextureLayer,                  ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLFRAMEBUFFERRENDERBUFFERPROC,                 glFramebufferRenderbuffer,                  ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC,     glGetFramebufferAttachmentParameteriv,      ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLBLITFRAMEBUFFERPROC,                         glBlitFramebuffer,                          ARB_FRAMEBUFFER_OBJECT, NULL )\
+    USE_GL_FUNC(PGLFNGLGENERATEMIPMAPPROC,                          glGenerateMipmap,                           ARB_FRAMEBUFFER_OBJECT, NULL )\
     /* GL_ARB_geometry_shader4 */ \
     USE_GL_FUNC(PGLFNPROGRAMPARAMETERIARBPROC,                      glProgramParameteriARB,                     ARB_GEOMETRY_SHADER4,   NULL ) \
@@ -3577,4 +3736,6 @@
     USE_GL_FUNC(PGLFNGLPOINTPARAMETERFARBPROC,                      glPointParameterfARB,                       ARB_POINT_PARAMETERS,   NULL )\
     USE_GL_FUNC(PGLFNGLPOINTPARAMETERFVARBPROC,                     glPointParameterfvARB,                      ARB_POINT_PARAMETERS,   NULL )\
+    /* GL_ARB_provoking_vertex */ \
+    USE_GL_FUNC(PGLFNGLPROVOKINGVERTEXPROC,                         glProvokingVertex,                          ARB_PROVOKING_VERTEX,   NULL)\
     /* GL_ARB_texture_compression */ \
     USE_GL_FUNC(PGLFNCOMPRESSEDTEXIMAGE2DPROC,                      glCompressedTexImage2DARB,                  ARB_TEXTURE_COMPRESSION,NULL )\
@@ -3644,4 +3805,6 @@
     USE_GL_FUNC(PGLFNGLPOINTPARAMETERFEXTPROC,                      glPointParameterfEXT,                       EXT_POINT_PARAMETERS,   NULL )\
     USE_GL_FUNC(PGLFNGLPOINTPARAMETERFVEXTPROC,                     glPointParameterfvEXT,                      EXT_POINT_PARAMETERS,   NULL )\
+    /* GL_EXT_provoking_vertex */ \
+    USE_GL_FUNC(PGLFNGLPROVOKINGVERTEXEXTPROC,                      glProvokingVertexEXT,                       EXT_PROVOKING_VERTEX,   NULL)\
     /* GL_EXT_secondary_color */ \
     USE_GL_FUNC(PGLFNGLSECONDARYCOLOR3UBEXTPROC,                    glSecondaryColor3ubEXT,                     EXT_SECONDARY_COLOR,    NULL )\
@@ -3958,4 +4121,27 @@
  ****************************************************/
 
+struct wined3d_fbo_ops
+{
+    PGLFNGLISRENDERBUFFERPROC                       glIsRenderbuffer;
+    PGLFNGLBINDRENDERBUFFERPROC                     glBindRenderbuffer;
+    PGLFNGLDELETERENDERBUFFERSPROC                  glDeleteRenderbuffers;
+    PGLFNGLGENRENDERBUFFERSPROC                     glGenRenderbuffers;
+    PGLFNGLRENDERBUFFERSTORAGEPROC                  glRenderbufferStorage;
+    PGLFNRENDERBUFFERSTORAGEMULTISAMPLEPROC         glRenderbufferStorageMultisample;
+    PGLFNGLGETRENDERBUFFERPARAMETERIVPROC           glGetRenderbufferParameteriv;
+    PGLFNGLISFRAMEBUFFERPROC                        glIsFramebuffer;
+    PGLFNGLBINDFRAMEBUFFERPROC                      glBindFramebuffer;
+    PGLFNGLDELETEFRAMEBUFFERSPROC                   glDeleteFramebuffers;
+    PGLFNGLGENFRAMEBUFFERSPROC                      glGenFramebuffers;
+    PGLFNGLCHECKFRAMEBUFFERSTATUSPROC               glCheckFramebufferStatus;
+    PGLFNGLFRAMEBUFFERTEXTURE1DPROC                 glFramebufferTexture1D;
+    PGLFNGLFRAMEBUFFERTEXTURE2DPROC                 glFramebufferTexture2D;
+    PGLFNGLFRAMEBUFFERTEXTURE3DPROC                 glFramebufferTexture3D;
+    PGLFNGLFRAMEBUFFERRENDERBUFFERPROC              glFramebufferRenderbuffer;
+    PGLFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVPROC  glGetFramebufferAttachmentParameteriv;
+    PGLFNGLBLITFRAMEBUFFERPROC                      glBlitFramebuffer;
+    PGLFNGLGENERATEMIPMAPPROC                       glGenerateMipmap;
+};
+
 #define USE_GL_FUNC(type, pfn, ext, replace) type pfn;
 
@@ -4000,11 +4186,4 @@
     unsigned int ps_glsl_constantsF;
 
-    GL_PSVersion ps_arb_version;
-    GL_PSVersion ps_nv_version;
-
-    GL_VSVersion vs_arb_version;
-    GL_VSVersion vs_nv_version;
-    GL_VSVersion vs_ati_version;
-
     DWORD reserved_glsl_constants;
 
@@ -4013,4 +4192,5 @@
     BOOL supported[WINED3D_GL_EXT_COUNT];
 
+    struct wined3d_fbo_ops fbo_ops;
     /* GL function pointers */
     GL_EXT_FUNCS_GEN
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_main.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_main.c	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_main.c	(revision 23571)
@@ -6,4 +6,5 @@
  * Copyright 2004      Jason Edmeades
  * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2009 Henri Verbeet for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
@@ -42,15 +43,23 @@
 void (*CDECL wine_tsx11_unlock_ptr)(void) = NULL;
 
+static CRITICAL_SECTION wined3d_cs;
+static CRITICAL_SECTION_DEBUG wined3d_cs_debug =
+{
+    0, 0, &wined3d_cs,
+    {&wined3d_cs_debug.ProcessLocksList,
+    &wined3d_cs_debug.ProcessLocksList},
+    0, 0, {(DWORD_PTR)(__FILE__ ": wined3d_cs")}
+};
+static CRITICAL_SECTION wined3d_cs = {&wined3d_cs_debug, -1, 0, 0, 0, 0};
 
 /* When updating default value here, make sure to update winecfg as well,
  * where appropriate. */
-wined3d_settings_t wined3d_settings = 
+wined3d_settings_t wined3d_settings =
 {
     VS_HW,          /* Hardware by default */
     PS_HW,          /* Hardware by default */
-    VBO_HW,         /* Hardware by default */
     TRUE,           /* Use of GLSL enabled by default */
     ORM_FBO,        /* Use FBOs to do offscreen rendering */
-    RTL_AUTO,       /* Automatically determine best locking method */
+    RTL_READTEX,    /* Default render target locking method */
     PCI_VENDOR_NONE,/* PCI Vendor ID */
     PCI_DEVICE_NONE,/* PCI Device ID */
@@ -206,17 +215,4 @@
             }
         }
-        if ( !get_config_key( hkey, appkey, "VertexBufferMode", buffer, size) )
-        {
-            if (!strcmp(buffer,"none"))
-            {
-                TRACE("Disable Vertex Buffer Hardware support\n");
-                wined3d_settings.vbo_mode = VBO_NONE;
-            }
-            else if (!strcmp(buffer,"hardware"))
-            {
-                TRACE("Allow Vertex Buffer Hardware support\n");
-                wined3d_settings.vbo_mode = VBO_HW;
-            }
-        }
         if ( !get_config_key( hkey, appkey, "UseGLSL", buffer, size) )
         {
@@ -261,14 +257,4 @@
                 TRACE("Using glReadPixels for render target reading and textures for writing\n");
                 wined3d_settings.rendertargetlock_mode = RTL_READTEX;
-            }
-            else if (!strcmp(buffer,"texdraw"))
-            {
-                TRACE("Using textures for render target reading and glDrawPixels for writing\n");
-                wined3d_settings.rendertargetlock_mode = RTL_TEXDRAW;
-            }
-            else if (!strcmp(buffer,"textex"))
-            {
-                TRACE("Reading render targets via textures and writing via textures\n");
-                wined3d_settings.rendertargetlock_mode = RTL_TEXTEX;
             }
         }
@@ -318,6 +304,9 @@
         if ( !get_config_key( hkey, appkey, "WineLogo", buffer, size) )
         {
-            wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, strlen(buffer) + 1);
-            if(wined3d_settings.logo) strcpy(wined3d_settings.logo, buffer);
+            size_t len = strlen(buffer) + 1;
+
+            wined3d_settings.logo = HeapAlloc(GetProcessHeap(), 0, len);
+            if (!wined3d_settings.logo) ERR("Failed to allocate logo path memory.\n");
+            else memcpy(wined3d_settings.logo, buffer, len);
         }
         if ( !get_config_key( hkey, appkey, "Multisampling", buffer, size) )
@@ -334,6 +323,4 @@
     if (wined3d_settings.ps_mode == PS_NONE)
         TRACE("Disable pixel shaders\n");
-    if (wined3d_settings.vbo_mode == VBO_NONE)
-        TRACE("Disable Vertex Buffer Hardware support\n");
     if (wined3d_settings.glslRequested)
         TRACE("If supported by your system, GL Shading Language will be used\n");
@@ -361,4 +348,14 @@
 }
 
+void WINAPI wined3d_mutex_lock(void)
+{
+    EnterCriticalSection(&wined3d_cs);
+}
+
+void WINAPI wined3d_mutex_unlock(void)
+{
+    LeaveCriticalSection(&wined3d_cs);
+}
+
 /* At process attach */
 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 23570)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 23571)
@@ -143,7 +143,7 @@
 }
 
-void *wined3d_rb_alloc(size_t size);
-void *wined3d_rb_realloc(void *ptr, size_t size);
-void wined3d_rb_free(void *ptr);
+void *wined3d_rb_alloc(size_t size) DECLSPEC_HIDDEN;
+void *wined3d_rb_realloc(void *ptr, size_t size) DECLSPEC_HIDDEN;
+void wined3d_rb_free(void *ptr) DECLSPEC_HIDDEN;
 
 /* Device caps */
@@ -165,10 +165,10 @@
 #define NUM_SAVEDVERTEXSTATES_S    1
 
-extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R];
-extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T];
-extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S];
-extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R];
-extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T];
-extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S];
+extern const DWORD SavedPixelStates_R[NUM_SAVEDPIXELSTATES_R] DECLSPEC_HIDDEN;
+extern const DWORD SavedPixelStates_T[NUM_SAVEDPIXELSTATES_T] DECLSPEC_HIDDEN;
+extern const DWORD SavedPixelStates_S[NUM_SAVEDPIXELSTATES_S] DECLSPEC_HIDDEN;
+extern const DWORD SavedVertexStates_R[NUM_SAVEDVERTEXSTATES_R] DECLSPEC_HIDDEN;
+extern const DWORD SavedVertexStates_T[NUM_SAVEDVERTEXSTATES_T] DECLSPEC_HIDDEN;
+extern const DWORD SavedVertexStates_S[NUM_SAVEDVERTEXSTATES_S] DECLSPEC_HIDDEN;
 
 typedef enum _WINELOOKUP {
@@ -177,7 +177,7 @@
 } WINELOOKUP;
 
-extern const int minLookup[MAX_LOOKUPS];
-extern const int maxLookup[MAX_LOOKUPS];
-extern DWORD *stateLookup[MAX_LOOKUPS];
+extern const int minLookup[MAX_LOOKUPS] DECLSPEC_HIDDEN;
+extern const int maxLookup[MAX_LOOKUPS] DECLSPEC_HIDDEN;
+extern DWORD *stateLookup[MAX_LOOKUPS] DECLSPEC_HIDDEN;
 
 struct min_lookup
@@ -186,8 +186,9 @@
 };
 
-const struct min_lookup minMipLookup[WINED3DTEXF_LINEAR + 1];
-const struct min_lookup minMipLookup_noFilter[WINED3DTEXF_LINEAR + 1];
-const GLenum magLookup[WINED3DTEXF_LINEAR + 1];
-const GLenum magLookup_noFilter[WINED3DTEXF_LINEAR + 1];
+const struct min_lookup minMipLookup[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN;
+const struct min_lookup minMipLookup_noFilter[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN;
+const struct min_lookup minMipLookup_noMip[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN;
+const GLenum magLookup[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN;
+const GLenum magLookup_noFilter[WINED3DTEXF_LINEAR + 1] DECLSPEC_HIDDEN;
 
 static inline GLenum wined3d_gl_mag_filter(const GLenum mag_lookup[], WINED3DTEXTUREFILTERTYPE mag_filter)
@@ -259,5 +260,5 @@
 
 /**
- * Settings 
+ * Settings
  */
 #define VS_NONE    0
@@ -284,9 +285,6 @@
 
 #define RTL_DISABLE   -1
-#define RTL_AUTO       0
 #define RTL_READDRAW   1
 #define RTL_READTEX    2
-#define RTL_TEXDRAW    3
-#define RTL_TEXTEX     4
 
 #define PCI_VENDOR_NONE 0xffff /* e.g. 0x8086 for Intel and 0x10de for Nvidia */
@@ -299,5 +297,4 @@
   int vs_mode;
   int ps_mode;
-  int vbo_mode;
 /* Ideally, we don't want the user to have to request GLSL.  If the hardware supports GLSL,
     we should use it.  However, until it's fully implemented, we'll leave it as a registry
@@ -314,5 +311,5 @@
 } wined3d_settings_t;
 
-extern wined3d_settings_t wined3d_settings;
+extern wined3d_settings_t wined3d_settings DECLSPEC_HIDDEN;
 
 typedef enum _WINED3DSAMPLER_TEXTURE_TYPE
@@ -648,8 +645,8 @@
 {
     struct wined3d_shader_version shader_version;
-    char texcoord[MAX_REG_TEXCRD];          /* pixel < 3.0 */
-    char temporary[MAX_REG_TEMP];           /* pixel, vertex */
-    char address[MAX_REG_ADDR];             /* vertex */
-    char labels[MAX_LABELS];                /* pixel, vertex */
+    BYTE texcoord;                          /* MAX_REG_TEXCRD, 8 */
+    BYTE address;                           /* MAX_REG_ADDR, 1 */
+    WORD labels;                            /* MAX_LABELS, 16 */
+    DWORD temporary;                        /* MAX_REG_TEMP, 32 */
     DWORD *constf;                          /* pixel, vertex */
     DWORD texcoord_mask[MAX_REG_TEXCRD];    /* vertex < 3.0 */
@@ -662,19 +659,20 @@
 
     WINED3DSAMPLER_TEXTURE_TYPE sampler_type[max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS)];
-    BOOL bumpmat[MAX_TEXTURES], luminanceparams[MAX_TEXTURES];
-
-    unsigned usesnrm        : 1;
-    unsigned vpos           : 1;
-    unsigned usesdsx        : 1;
-    unsigned usesdsy        : 1;
-    unsigned usestexldd     : 1;
-    unsigned usesmova       : 1;
-    unsigned usesfacing     : 1;
-    unsigned usesrelconstF  : 1;
-    unsigned fog            : 1;
-    unsigned usestexldl     : 1;
-    unsigned usesifc        : 1;
-    unsigned usescall       : 1;
-    unsigned padding        : 4;
+    BYTE bumpmat;                           /* MAX_TEXTURES, 8 */
+    BYTE luminanceparams;                   /* MAX_TEXTURES, 8 */
+
+    WORD usesnrm        : 1;
+    WORD vpos           : 1;
+    WORD usesdsx        : 1;
+    WORD usesdsy        : 1;
+    WORD usestexldd     : 1;
+    WORD usesmova       : 1;
+    WORD usesfacing     : 1;
+    WORD usesrelconstF  : 1;
+    WORD fog            : 1;
+    WORD usestexldl     : 1;
+    WORD usesifc        : 1;
+    WORD usescall       : 1;
+    WORD padding        : 4;
 
     /* Whether or not loops are used in this shader, and nesting depth */
@@ -742,4 +740,11 @@
     WINED3DDECLUSAGE usage;
     UINT usage_idx;
+};
+
+struct wined3d_shader_loop_control
+{
+    unsigned int count;
+    unsigned int start;
+    int step;
 };
 
@@ -759,6 +764,6 @@
 };
 
-extern const struct wined3d_shader_frontend sm1_shader_frontend;
-extern const struct wined3d_shader_frontend sm4_shader_frontend;
+extern const struct wined3d_shader_frontend sm1_shader_frontend DECLSPEC_HIDDEN;
+extern const struct wined3d_shader_frontend sm4_shader_frontend DECLSPEC_HIDDEN;
 
 typedef void (*SHADER_HANDLER)(const struct wined3d_shader_instruction *);
@@ -854,15 +859,15 @@
 } shader_backend_t;
 
-extern const shader_backend_t glsl_shader_backend;
-extern const shader_backend_t arb_program_shader_backend;
-extern const shader_backend_t none_shader_backend;
+extern const shader_backend_t glsl_shader_backend DECLSPEC_HIDDEN;
+extern const shader_backend_t arb_program_shader_backend DECLSPEC_HIDDEN;
+extern const shader_backend_t none_shader_backend DECLSPEC_HIDDEN;
 
 /* X11 locking */
 
-extern void (* CDECL wine_tsx11_lock_ptr)(void);
-extern void (* CDECL wine_tsx11_unlock_ptr)(void);
+extern void (* CDECL wine_tsx11_lock_ptr)(void) DECLSPEC_HIDDEN;
+extern void (* CDECL wine_tsx11_unlock_ptr)(void) DECLSPEC_HIDDEN;
 
 /* As GLX relies on X, this is needed */
-extern int num_lock;
+extern int num_lock DECLSPEC_HIDDEN;
 
 #if 0
@@ -954,8 +959,9 @@
 
 /* Trace vector and strided data information */
-#define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w);
-#define TRACE_STRIDED(si, name) TRACE( #name "=(data:%p, stride:%d, format:%#x, vbo %d, stream %u)\n", \
+#define TRACE_VECTOR(name) TRACE( #name "=(%f, %f, %f, %f)\n", name.x, name.y, name.z, name.w)
+#define TRACE_STRIDED(si, name) do { if (si->use_map & (1 << name)) \
+        TRACE( #name "=(data:%p, stride:%d, format:%#x, vbo %d, stream %u)\n", \
         si->elements[name].data, si->elements[name].stride, si->elements[name].format_desc->format, \
-        si->elements[name].buffer_object, si->elements[name].stream_idx);
+        si->elements[name].buffer_object, si->elements[name].stream_idx); } while(0)
 
 /* Defines used for optimizations */
@@ -972,5 +978,5 @@
 
 /* Global variables */
-extern const float identity[16];
+extern const float identity[16] DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -981,6 +987,6 @@
 #if 0 /* NOTE: Must be 0 in cvs */
 # define VTRACE(A) TRACE A
-#else 
-# define VTRACE(A) 
+#else
+# define VTRACE(A)
 #endif
 
@@ -995,19 +1001,19 @@
 # if 1 /* NOTE: Must be 1 in cvs, as this is mostly more useful than a trace from program start */
 #  define SINGLE_FRAME_DEBUGGING
-# endif  
+# endif
   /* The following, when enabled, lets you see the makeup of the frame, by drawprimitive calls.
-     It can only be enabled when FRAME_DEBUGGING is also enabled                               
-     The contents of the back buffer are written into /tmp/backbuffer_* after each primitive 
+     It can only be enabled when FRAME_DEBUGGING is also enabled
+     The contents of the back buffer are written into /tmp/backbuffer_* after each primitive
      array is drawn.                                                                            */
-# if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */                                                                                       
+# if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
 #  define SHOW_FRAME_MAKEUP 1
-# endif  
+# endif
   /* The following, when enabled, lets you see the makeup of the all the textures used during each
      of the drawprimitive calls. It can only be enabled when SHOW_FRAME_MAKEUP is also enabled.
-     The contents of the textures assigned to each stage are written into 
+     The contents of the textures assigned to each stage are written into
      /tmp/texture_*_<Stage>.ppm after each primitive array is drawn.                            */
 # if 0 /* NOTE: Must be 0 in cvs, as this give a lot of ppm files when compiled in */
 #  define SHOW_TEXTURE_MAKEUP 0
-# endif  
+# endif
 extern BOOL isOn;
 extern BOOL isDumpingFrames;
@@ -1078,16 +1084,16 @@
 
 /* Routine common to the draw primitive and draw indexed primitive routines */
-void drawPrimitive(IWineD3DDevice *iface, UINT index_count, UINT numberOfVertices,
-        UINT start_idx, UINT idxBytes, const void *idxData, UINT minIndex);
-DWORD get_flexible_vertex_size(DWORD d3dvtVertexType);
+void drawPrimitive(IWineD3DDevice *iface, UINT index_count,
+        UINT start_idx, UINT idxBytes, const void *idxData) DECLSPEC_HIDDEN;
+DWORD get_flexible_vertex_size(DWORD d3dvtVertexType) DECLSPEC_HIDDEN;
 
 typedef void (WINE_GLAPI *glAttribFunc)(const void *data);
 typedef void (WINE_GLAPI *glMultiTexCoordFunc)(GLenum unit, const void *data);
-extern glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT];
-extern glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT];
-extern glAttribFunc specular_func_3ubv;
-extern glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT];
-extern glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT];
-extern glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT];
+extern glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
+extern glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
+extern glAttribFunc specular_func_3ubv DECLSPEC_HIDDEN;
+extern glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
+extern glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
+extern glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT] DECLSPEC_HIDDEN;
 
 #define eps 1e-8
@@ -1281,16 +1287,16 @@
 };
 
-extern const struct StateEntryTemplate misc_state_template[];
-extern const struct StateEntryTemplate ffp_vertexstate_template[];
-extern const struct fragment_pipeline ffp_fragment_pipeline;
-extern const struct fragment_pipeline atifs_fragment_pipeline;
-extern const struct fragment_pipeline arbfp_fragment_pipeline;
-extern const struct fragment_pipeline nvts_fragment_pipeline;
-extern const struct fragment_pipeline nvrc_fragment_pipeline;
+extern const struct StateEntryTemplate misc_state_template[] DECLSPEC_HIDDEN;
+extern const struct StateEntryTemplate ffp_vertexstate_template[] DECLSPEC_HIDDEN;
+extern const struct fragment_pipeline ffp_fragment_pipeline DECLSPEC_HIDDEN;
+extern const struct fragment_pipeline atifs_fragment_pipeline DECLSPEC_HIDDEN;
+extern const struct fragment_pipeline arbfp_fragment_pipeline DECLSPEC_HIDDEN;
+extern const struct fragment_pipeline nvts_fragment_pipeline DECLSPEC_HIDDEN;
+extern const struct fragment_pipeline nvrc_fragment_pipeline DECLSPEC_HIDDEN;
 
 /* "Base" state table */
 HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_multistate_funcs,
         const struct wined3d_gl_info *gl_info, const struct StateEntryTemplate *vertex,
-        const struct fragment_pipeline *fragment, const struct StateEntryTemplate *misc);
+        const struct fragment_pipeline *fragment, const struct StateEntryTemplate *misc) DECLSPEC_HIDDEN;
 
 /* Shaders for color conversions in blits */
@@ -1305,6 +1311,6 @@
 };
 
-extern const struct blit_shader ffp_blit;
-extern const struct blit_shader arbfp_blit;
+extern const struct blit_shader ffp_blit DECLSPEC_HIDDEN;
+extern const struct blit_shader arbfp_blit DECLSPEC_HIDDEN;
 
 typedef enum ContextUsage {
@@ -1315,25 +1321,29 @@
 } ContextUsage;
 
-struct wined3d_context *ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, enum ContextUsage usage);
+struct wined3d_context *ActivateContext(IWineD3DDeviceImpl *This,
+        IWineD3DSurface *target, enum ContextUsage usage) DECLSPEC_HIDDEN;
 struct wined3d_context *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, HWND win,
-        BOOL create_pbuffer, const WINED3DPRESENT_PARAMETERS *pPresentParms);
-void DestroyContext(IWineD3DDeviceImpl *This, struct wined3d_context *context);
-void context_alloc_event_query(struct wined3d_context *context, struct wined3d_event_query *query);
-void context_alloc_occlusion_query(struct wined3d_context *context, struct wined3d_occlusion_query *query);
-void context_resource_released(IWineD3DDevice *iface, IWineD3DResource *resource, WINED3DRESOURCETYPE type);
-void context_bind_fbo(struct wined3d_context *context, GLenum target, GLuint *fbo);
+        BOOL create_pbuffer, const WINED3DPRESENT_PARAMETERS *pPresentParms) DECLSPEC_HIDDEN;
+void DestroyContext(IWineD3DDeviceImpl *This, struct wined3d_context *context) DECLSPEC_HIDDEN;
+void context_alloc_event_query(struct wined3d_context *context,
+        struct wined3d_event_query *query) DECLSPEC_HIDDEN;
+void context_alloc_occlusion_query(struct wined3d_context *context,
+        struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;
+void context_resource_released(IWineD3DDevice *iface,
+        IWineD3DResource *resource, WINED3DRESOURCETYPE type) DECLSPEC_HIDDEN;
+void context_bind_fbo(struct wined3d_context *context, GLenum target, GLuint *fbo) DECLSPEC_HIDDEN;
 void context_attach_depth_stencil_fbo(struct wined3d_context *context,
-        GLenum fbo_target, IWineD3DSurface *depth_stencil, BOOL use_render_buffer);
+        GLenum fbo_target, IWineD3DSurface *depth_stencil, BOOL use_render_buffer) DECLSPEC_HIDDEN;
 void context_attach_surface_fbo(const struct wined3d_context *context,
-        GLenum fbo_target, DWORD idx, IWineD3DSurface *surface);
-void context_free_event_query(struct wined3d_event_query *query);
-void context_free_occlusion_query(struct wined3d_occlusion_query *query);
-struct wined3d_context *context_get_current(void);
-DWORD context_get_tls_idx(void);
-BOOL context_set_current(struct wined3d_context *ctx);
-void context_set_tls_idx(DWORD idx);
-
-void delete_opengl_contexts(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain);
-HRESULT create_primary_opengl_context(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain);
+        GLenum fbo_target, DWORD idx, IWineD3DSurface *surface) DECLSPEC_HIDDEN;
+void context_free_event_query(struct wined3d_event_query *query) DECLSPEC_HIDDEN;
+void context_free_occlusion_query(struct wined3d_occlusion_query *query) DECLSPEC_HIDDEN;
+struct wined3d_context *context_get_current(void) DECLSPEC_HIDDEN;
+DWORD context_get_tls_idx(void) DECLSPEC_HIDDEN;
+BOOL context_set_current(struct wined3d_context *ctx) DECLSPEC_HIDDEN;
+void context_set_tls_idx(DWORD idx) DECLSPEC_HIDDEN;
+
+void delete_opengl_contexts(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain) DECLSPEC_HIDDEN;
+HRESULT create_primary_opengl_context(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain) DECLSPEC_HIDDEN;
 
 /* Macros for doing basic GPU detection based on opengl capabilities */
@@ -1344,7 +1354,5 @@
 
 /* Default callbacks for implicit object destruction */
-extern ULONG WINAPI D3DCB_DefaultDestroySurface(IWineD3DSurface *pSurface);
-
-extern ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pSurface);
+extern ULONG WINAPI D3DCB_DefaultDestroyVolume(IWineD3DVolume *pSurface) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -1370,5 +1378,5 @@
 
 /* The default light parameters */
-extern const WINED3DLIGHT WINED3D_default_light;
+extern const WINED3DLIGHT WINED3D_default_light DECLSPEC_HIDDEN;
 
 typedef struct WineD3D_PixelFormat
@@ -1402,8 +1410,8 @@
 };
 
-extern BOOL initPixelFormats(struct wined3d_gl_info *gl_info);
-BOOL initPixelFormatsNoGL(struct wined3d_gl_info *gl_info);
-extern long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram);
-extern void add_gl_compat_wrappers(struct wined3d_gl_info *gl_info);
+extern BOOL initPixelFormats(struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
+BOOL initPixelFormatsNoGL(struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
+extern long WineD3DAdapterChangeGLRam(IWineD3DDeviceImpl *D3DDevice, long glram) DECLSPEC_HIDDEN;
+extern void add_gl_compat_wrappers(struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -1421,5 +1429,5 @@
 };
 
-HRESULT tesselate_rectpatch(IWineD3DDeviceImpl *This, struct WineD3DRectPatch *patch);
+HRESULT tesselate_rectpatch(IWineD3DDeviceImpl *This, struct WineD3DRectPatch *patch) DECLSPEC_HIDDEN;
 
 enum projection_types
@@ -1474,10 +1482,12 @@
 };
 
-extern const struct wine_rb_functions wined3d_ffp_frag_program_rb_functions;
-
-void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_settings *settings, BOOL ignore_textype);
+extern const struct wine_rb_functions wined3d_ffp_frag_program_rb_functions DECLSPEC_HIDDEN;
+extern const struct wined3d_parent_ops wined3d_null_parent_ops DECLSPEC_HIDDEN;
+
+void gen_ffp_frag_op(IWineD3DStateBlockImpl *stateblock, struct ffp_frag_settings *settings,
+        BOOL ignore_textype) DECLSPEC_HIDDEN;
 const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *fragment_shaders,
-        const struct ffp_frag_settings *settings);
-void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc);
+        const struct ffp_frag_settings *settings) DECLSPEC_HIDDEN;
+void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -1498,10 +1508,10 @@
 } IWineD3DImpl;
 
-extern const IWineD3DVtbl IWineD3D_Vtbl;
-
-BOOL InitAdapters(IWineD3DImpl *This);
+extern const IWineD3DVtbl IWineD3D_Vtbl DECLSPEC_HIDDEN;
+
+BOOL InitAdapters(IWineD3DImpl *This) DECLSPEC_HIDDEN;
 
 /* A helper function that dumps a resource list */
-void dumpResources(struct list *list);
+void dumpResources(struct list *list) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -1650,17 +1660,16 @@
 };
 
-extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
-
-void device_resource_add(IWineD3DDeviceImpl *This, IWineD3DResource *resource);
-void device_resource_released(IWineD3DDeviceImpl *This, IWineD3DResource *resource);
+extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl DECLSPEC_HIDDEN;
+
+void device_resource_add(IWineD3DDeviceImpl *This, IWineD3DResource *resource) DECLSPEC_HIDDEN;
+void device_resource_released(IWineD3DDeviceImpl *This, IWineD3DResource *resource) DECLSPEC_HIDDEN;
 void device_stream_info_from_declaration(IWineD3DDeviceImpl *This,
-        BOOL use_vshader, struct wined3d_stream_info *stream_info, BOOL *fixup);
+        BOOL use_vshader, struct wined3d_stream_info *stream_info, BOOL *fixup) DECLSPEC_HIDDEN;
 void device_stream_info_from_strided(IWineD3DDeviceImpl *This,
-        const struct WineDirect3DVertexStridedData *strided, struct wined3d_stream_info *stream_info);
-HRESULT IWineD3DDeviceImpl_ClearSurface(IWineD3DDeviceImpl *This,  IWineD3DSurfaceImpl *target, DWORD Count,
-                                        CONST WINED3DRECT* pRects, DWORD Flags, WINED3DCOLOR Color,
-                                        float Z, DWORD Stencil);
-void IWineD3DDeviceImpl_FindTexUnitMap(IWineD3DDeviceImpl *This);
-void IWineD3DDeviceImpl_MarkStateDirty(IWineD3DDeviceImpl *This, DWORD state);
+        const struct WineDirect3DVertexStridedData *strided, struct wined3d_stream_info *stream_info) DECLSPEC_HIDDEN;
+HRESULT IWineD3DDeviceImpl_ClearSurface(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, DWORD Count,
+        const WINED3DRECT *pRects, DWORD Flags, WINED3DCOLOR Color, float Z, DWORD Stencil) DECLSPEC_HIDDEN;
+void IWineD3DDeviceImpl_FindTexUnitMap(IWineD3DDeviceImpl *This) DECLSPEC_HIDDEN;
+void IWineD3DDeviceImpl_MarkStateDirty(IWineD3DDeviceImpl *This, DWORD state) DECLSPEC_HIDDEN;
 static inline BOOL isStateDirty(struct wined3d_context *context, DWORD state)
 {
@@ -1708,5 +1717,5 @@
     struct list             privateData;
     struct list             resource_list_entry;
-
+    const struct wined3d_parent_ops *parent_ops;
 } IWineD3DResourceClass;
 
@@ -1718,18 +1727,18 @@
 } IWineD3DResourceImpl;
 
-void resource_cleanup(IWineD3DResource *iface);
-HRESULT resource_free_private_data(IWineD3DResource *iface, REFGUID guid);
-HRESULT resource_get_device(IWineD3DResource *iface, IWineD3DDevice **device);
-HRESULT resource_get_parent(IWineD3DResource *iface, IUnknown **parent);
-DWORD resource_get_priority(IWineD3DResource *iface);
+void resource_cleanup(IWineD3DResource *iface) DECLSPEC_HIDDEN;
+HRESULT resource_free_private_data(IWineD3DResource *iface, REFGUID guid) DECLSPEC_HIDDEN;
+HRESULT resource_get_device(IWineD3DResource *iface, IWineD3DDevice **device) DECLSPEC_HIDDEN;
+HRESULT resource_get_parent(IWineD3DResource *iface, IUnknown **parent) DECLSPEC_HIDDEN;
+DWORD resource_get_priority(IWineD3DResource *iface) DECLSPEC_HIDDEN;
 HRESULT resource_get_private_data(IWineD3DResource *iface, REFGUID guid,
-        void *data, DWORD *data_size);
+        void *data, DWORD *data_size) DECLSPEC_HIDDEN;
 HRESULT resource_init(IWineD3DResource *iface, WINED3DRESOURCETYPE resource_type,
         IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct GlPixelFormatDesc *format_desc,
-        WINED3DPOOL pool, IUnknown *parent);
-WINED3DRESOURCETYPE resource_get_type(IWineD3DResource *iface);
-DWORD resource_set_priority(IWineD3DResource *iface, DWORD new_priority);
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
+WINED3DRESOURCETYPE resource_get_type(IWineD3DResource *iface) DECLSPEC_HIDDEN;
+DWORD resource_set_priority(IWineD3DResource *iface, DWORD new_priority) DECLSPEC_HIDDEN;
 HRESULT resource_set_private_data(IWineD3DResource *iface, REFGUID guid,
-        const void *data, DWORD data_size, DWORD flags);
+        const void *data, DWORD data_size, DWORD flags) DECLSPEC_HIDDEN;
 
 /* Tests show that the start address of resources is 32 byte aligned */
@@ -1765,4 +1774,11 @@
 };
 
+struct gl_texture
+{
+    DWORD                   states[MAX_WINETEXTURESTATES];
+    BOOL                    dirty;
+    GLuint                  name;
+};
+
 /*****************************************************************************
  * IWineD3DBaseTexture implementation structure (extends IWineD3DResourceImpl)
@@ -1770,9 +1786,6 @@
 typedef struct IWineD3DBaseTextureClass
 {
-    DWORD                   states[MAX_WINETEXTURESTATES];
-    DWORD                   srgbstates[MAX_WINETEXTURESTATES];
+    struct gl_texture       texture_rgb, texture_srgb;
     UINT                    levels;
-    BOOL                    dirty, srgbDirty;
-    UINT                    textureName, srgbTextureName;
     float                   pow2Matrix[16];
     UINT                    LOD;
@@ -1787,5 +1800,5 @@
 } IWineD3DBaseTextureClass;
 
-void surface_internal_preload(IWineD3DSurface *iface, enum WINED3DSRGB srgb);
+void surface_internal_preload(IWineD3DSurface *iface, enum WINED3DSRGB srgb) DECLSPEC_HIDDEN;
 
 typedef struct IWineD3DBaseTextureImpl
@@ -1800,19 +1813,20 @@
 void basetexture_apply_state_changes(IWineD3DBaseTexture *iface,
         const DWORD texture_states[WINED3D_HIGHEST_TEXTURE_STATE + 1],
-        const DWORD sampler_states[WINED3D_HIGHEST_SAMPLER_STATE + 1]);
-HRESULT basetexture_bind(IWineD3DBaseTexture *iface, BOOL srgb, BOOL *set_surface_desc);
-void basetexture_cleanup(IWineD3DBaseTexture *iface);
-void basetexture_generate_mipmaps(IWineD3DBaseTexture *iface);
-WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTexture *iface);
-BOOL basetexture_get_dirty(IWineD3DBaseTexture *iface);
-DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface);
-DWORD basetexture_get_lod(IWineD3DBaseTexture *iface);
+        const DWORD sampler_states[WINED3D_HIGHEST_SAMPLER_STATE + 1]) DECLSPEC_HIDDEN;
+HRESULT basetexture_bind(IWineD3DBaseTexture *iface, BOOL srgb, BOOL *set_surface_desc) DECLSPEC_HIDDEN;
+void basetexture_cleanup(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
+void basetexture_generate_mipmaps(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
+WINED3DTEXTUREFILTERTYPE basetexture_get_autogen_filter_type(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
+BOOL basetexture_get_dirty(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
+DWORD basetexture_get_level_count(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
+DWORD basetexture_get_lod(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
 HRESULT basetexture_init(IWineD3DBaseTextureImpl *texture, UINT levels, WINED3DRESOURCETYPE resource_type,
         IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct GlPixelFormatDesc *format_desc,
-        WINED3DPOOL pool, IUnknown *parent);
-HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface, WINED3DTEXTUREFILTERTYPE filter_type);
-BOOL basetexture_set_dirty(IWineD3DBaseTexture *iface, BOOL dirty);
-DWORD basetexture_set_lod(IWineD3DBaseTexture *iface, DWORD new_lod);
-void basetexture_unload(IWineD3DBaseTexture *iface);
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
+HRESULT basetexture_set_autogen_filter_type(IWineD3DBaseTexture *iface,
+        WINED3DTEXTUREFILTERTYPE filter_type) DECLSPEC_HIDDEN;
+BOOL basetexture_set_dirty(IWineD3DBaseTexture *iface, BOOL dirty) DECLSPEC_HIDDEN;
+DWORD basetexture_set_lod(IWineD3DBaseTexture *iface, DWORD new_lod) DECLSPEC_HIDDEN;
+void basetexture_unload(IWineD3DBaseTexture *iface) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -1833,8 +1847,7 @@
 } IWineD3DTextureImpl;
 
-extern const IWineD3DTextureVtbl IWineD3DTexture_Vtbl;
-
 HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
-        IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent);
+        IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -1852,8 +1865,7 @@
 } IWineD3DCubeTextureImpl;
 
-extern const IWineD3DCubeTextureVtbl IWineD3DCubeTexture_Vtbl;
-
 HRESULT cubetexture_init(IWineD3DCubeTextureImpl *texture, UINT edge_length, UINT levels,
-        IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent);
+        IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
 
 typedef struct _WINED3DVOLUMET_DESC
@@ -1883,7 +1895,8 @@
 } IWineD3DVolumeImpl;
 
-extern const IWineD3DVolumeVtbl IWineD3DVolume_Vtbl;
-
-void volume_add_dirty_box(IWineD3DVolume *iface, const WINED3DBOX *dirty_box);
+void volume_add_dirty_box(IWineD3DVolume *iface, const WINED3DBOX *dirty_box) DECLSPEC_HIDDEN;
+HRESULT volume_init(IWineD3DVolumeImpl *volume, IWineD3DDeviceImpl *device, UINT width,
+        UINT height, UINT depth, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -1901,8 +1914,7 @@
 } IWineD3DVolumeTextureImpl;
 
-extern const IWineD3DVolumeTextureVtbl IWineD3DVolumeTexture_Vtbl;
-
-HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height, UINT depth, UINT levels,
-        IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent);
+HRESULT volumetexture_init(IWineD3DVolumeTextureImpl *texture, UINT width, UINT height,
+        UINT depth, UINT levels, IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format,
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
 
 typedef struct _WINED3DSURFACET_DESC
@@ -2020,60 +2032,68 @@
 };
 
-extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl;
-extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl;
-
-UINT surface_calculate_size(const struct GlPixelFormatDesc *format_desc, UINT alignment, UINT width, UINT height);
-void surface_gdi_cleanup(IWineD3DSurfaceImpl *This);
+extern const IWineD3DSurfaceVtbl IWineD3DSurface_Vtbl DECLSPEC_HIDDEN;
+extern const IWineD3DSurfaceVtbl IWineGDISurface_Vtbl DECLSPEC_HIDDEN;
+
+UINT surface_calculate_size(const struct GlPixelFormatDesc *format_desc,
+        UINT alignment, UINT width, UINT height) DECLSPEC_HIDDEN;
+void surface_gdi_cleanup(IWineD3DSurfaceImpl *This) DECLSPEC_HIDDEN;
 HRESULT surface_init(IWineD3DSurfaceImpl *surface, WINED3DSURFTYPE surface_type, UINT alignment,
         UINT width, UINT height, UINT level, BOOL lockable, BOOL discard, WINED3DMULTISAMPLE_TYPE multisample_type,
         UINT multisample_quality, IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format,
-        WINED3DPOOL pool, IUnknown *parent);
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
 
 /* Predeclare the shared Surface functions */
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_QueryInterface(IWineD3DSurface *iface, REFIID riid, LPVOID *ppobj);
-ULONG WINAPI IWineD3DBaseSurfaceImpl_AddRef(IWineD3DSurface *iface);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPrivateData(IWineD3DSurface *iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPrivateData(IWineD3DSurface *iface, REFGUID refguid, void* pData, DWORD* pSizeOfData);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid);
-DWORD   WINAPI IWineD3DBaseSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew);
-DWORD   WINAPI IWineD3DBaseSurfaceImpl_GetPriority(IWineD3DSurface *iface);
-WINED3DRESOURCETYPE WINAPI IWineD3DBaseSurfaceImpl_GetType(IWineD3DSurface *iface);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetContainer(IWineD3DSurface* iface, REFIID riid, void** ppContainer);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_IsLost(IWineD3DSurface *iface);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_Restore(IWineD3DSurface *iface);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetColorKey(IWineD3DSurface *iface, DWORD Flags, const WINEDDCOLORKEY *CKey);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container);
-DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPitch(IWineD3DSurface *iface);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_RealizePalette(IWineD3DSurface *iface);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetOverlayPosition(IWineD3DSurface *iface, LONG X, LONG Y);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetOverlayPosition(IWineD3DSurface *iface, LONG *X, LONG *Y);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder(IWineD3DSurface *iface, DWORD Flags, IWineD3DSurface *Ref);
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_QueryInterface(IWineD3DSurface *iface,
+        REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN;
+ULONG WINAPI IWineD3DBaseSurfaceImpl_AddRef(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetParent(IWineD3DSurface *iface, IUnknown **pParent) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDevice(IWineD3DSurface *iface, IWineD3DDevice** ppDevice) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPrivateData(IWineD3DSurface *iface,
+        REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPrivateData(IWineD3DSurface *iface,
+        REFGUID refguid, void *pData, DWORD *pSizeOfData) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_FreePrivateData(IWineD3DSurface *iface, REFGUID refguid) DECLSPEC_HIDDEN;
+DWORD WINAPI IWineD3DBaseSurfaceImpl_SetPriority(IWineD3DSurface *iface, DWORD PriorityNew) DECLSPEC_HIDDEN;
+DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPriority(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
+WINED3DRESOURCETYPE WINAPI IWineD3DBaseSurfaceImpl_GetType(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetContainer(IWineD3DSurface* iface,
+        REFIID riid, void **ppContainer) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetDesc(IWineD3DSurface *iface, WINED3DSURFACE_DESC *pDesc) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetBltStatus(IWineD3DSurface *iface, DWORD Flags) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetFlipStatus(IWineD3DSurface *iface, DWORD Flags) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_IsLost(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_Restore(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetPalette(IWineD3DSurface *iface, IWineD3DPalette **Pal) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetPalette(IWineD3DSurface *iface, IWineD3DPalette *Pal) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetColorKey(IWineD3DSurface *iface,
+        DWORD Flags, const WINEDDCOLORKEY *CKey) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetContainer(IWineD3DSurface *iface, IWineD3DBase *container) DECLSPEC_HIDDEN;
+DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPitch(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_RealizePalette(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetOverlayPosition(IWineD3DSurface *iface, LONG X, LONG Y) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetOverlayPosition(IWineD3DSurface *iface, LONG *X, LONG *Y) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_UpdateOverlayZOrder(IWineD3DSurface *iface,
+        DWORD Flags, IWineD3DSurface *Ref) DECLSPEC_HIDDEN;
 HRESULT WINAPI IWineD3DBaseSurfaceImpl_UpdateOverlay(IWineD3DSurface *iface, const RECT *SrcRect,
-        IWineD3DSurface *DstSurface, const RECT *DstRect, DWORD Flags, const WINEDDOVERLAYFX *FX);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetClipper(IWineD3DSurface *iface, IWineD3DClipper *clipper);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetClipper(IWineD3DSurface *iface, IWineD3DClipper **clipper);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format);
-HRESULT IWineD3DBaseSurfaceImpl_CreateDIBSection(IWineD3DSurface *iface);
+        IWineD3DSurface *DstSurface, const RECT *DstRect, DWORD Flags, const WINEDDOVERLAYFX *FX) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetClipper(IWineD3DSurface *iface, IWineD3DClipper *clipper) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_GetClipper(IWineD3DSurface *iface, IWineD3DClipper **clipper) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_SetFormat(IWineD3DSurface *iface, WINED3DFORMAT format) DECLSPEC_HIDDEN;
+HRESULT IWineD3DBaseSurfaceImpl_CreateDIBSection(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
 HRESULT WINAPI IWineD3DBaseSurfaceImpl_Blt(IWineD3DSurface *iface, const RECT *DestRect, IWineD3DSurface *SrcSurface,
-        const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter);
+        const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx, WINED3DTEXTUREFILTERTYPE Filter) DECLSPEC_HIDDEN;
 HRESULT WINAPI IWineD3DBaseSurfaceImpl_BltFast(IWineD3DSurface *iface, DWORD dstx, DWORD dsty,
-        IWineD3DSurface *Source, const RECT *rsrc, DWORD trans);
-HRESULT WINAPI IWineD3DBaseSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags);
-void WINAPI IWineD3DBaseSurfaceImpl_BindTexture(IWineD3DSurface *iface, BOOL srgb);
-const void *WINAPI IWineD3DBaseSurfaceImpl_GetData(IWineD3DSurface *iface);
-
-void get_drawable_size_swapchain(struct wined3d_context *context, UINT *width, UINT *height);
-void get_drawable_size_backbuffer(struct wined3d_context *context, UINT *width, UINT *height);
-void get_drawable_size_pbuffer(struct wined3d_context *context, UINT *width, UINT *height);
-void get_drawable_size_fbo(struct wined3d_context *context, UINT *width, UINT *height);
-
-void flip_surface(IWineD3DSurfaceImpl *front, IWineD3DSurfaceImpl *back);
+        IWineD3DSurface *Source, const RECT *rsrc, DWORD trans) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED3DLOCKED_RECT *pLockedRect,
+        const RECT *pRect, DWORD Flags) DECLSPEC_HIDDEN;
+void WINAPI IWineD3DBaseSurfaceImpl_BindTexture(IWineD3DSurface *iface, BOOL srgb) DECLSPEC_HIDDEN;
+const void *WINAPI IWineD3DBaseSurfaceImpl_GetData(IWineD3DSurface *iface) DECLSPEC_HIDDEN;
+
+void get_drawable_size_swapchain(struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;
+void get_drawable_size_backbuffer(struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;
+void get_drawable_size_pbuffer(struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;
+void get_drawable_size_fbo(struct wined3d_context *context, UINT *width, UINT *height) DECLSPEC_HIDDEN;
+
+void flip_surface(IWineD3DSurfaceImpl *front, IWineD3DSurfaceImpl *back) DECLSPEC_HIDDEN;
 
 /* Surface flags: */
@@ -2131,5 +2151,5 @@
 #define SFLAG_DS_DISCARDED   SFLAG_DS_LOCATIONS
 
-BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]);
+BOOL CalculateTexRect(IWineD3DSurfaceImpl *This, RECT *Rect, float glTexCoord[4]) DECLSPEC_HIDDEN;
 
 typedef enum {
@@ -2161,7 +2181,8 @@
 } CONVERT_TYPES;
 
-HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing, GLenum *format, GLenum *internal, GLenum *type, CONVERT_TYPES *convert, int *target_bpp, BOOL srgb_mode);
-
-BOOL palette9_changed(IWineD3DSurfaceImpl *This);
+HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_texturing, GLenum *format,
+        GLenum *internal, GLenum *type, CONVERT_TYPES *convert, int *target_bpp, BOOL srgb_mode) DECLSPEC_HIDDEN;
+
+BOOL palette9_changed(IWineD3DSurfaceImpl *This) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -2188,4 +2209,5 @@
 
     IUnknown                *parent;
+    const struct wined3d_parent_ops *parent_ops;
     IWineD3DDeviceImpl      *wineD3DDevice;
 
@@ -2199,8 +2221,7 @@
 } IWineD3DVertexDeclarationImpl;
 
-extern const IWineD3DVertexDeclarationVtbl IWineD3DVertexDeclaration_Vtbl;
-
-HRESULT vertexdeclaration_init(IWineD3DVertexDeclarationImpl *This,
-        const WINED3DVERTEXELEMENT *elements, UINT element_count);
+HRESULT vertexdeclaration_init(IWineD3DVertexDeclarationImpl *declaration, IWineD3DDeviceImpl *device,
+        const WINED3DVERTEXELEMENT *elements, UINT element_count,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -2348,14 +2369,8 @@
 };
 
-extern void stateblock_savedstates_set(
-    IWineD3DStateBlock* iface,
-    SAVEDSTATES* states,
-    BOOL value);
-
-extern void stateblock_copy(
-    IWineD3DStateBlock* destination,
-    IWineD3DStateBlock* source);
-
-extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl;
+extern void stateblock_savedstates_set(IWineD3DStateBlock *iface, SAVEDSTATES *states, BOOL value) DECLSPEC_HIDDEN;
+extern void stateblock_copy(IWineD3DStateBlock *destination, IWineD3DStateBlock *source) DECLSPEC_HIDDEN;
+
+extern const IWineD3DStateBlockVtbl IWineD3DStateBlock_Vtbl DECLSPEC_HIDDEN;
 
 /* Direct3D terminology with little modifications. We do not have an issued state
@@ -2375,5 +2390,5 @@
     const IWineD3DQueryVtbl  *lpVtbl;
     LONG                      ref;     /* Note: Ref counting not required */
-    
+
     IUnknown                 *parent;
     /*TODO: replace with iface usage */
@@ -2389,11 +2404,9 @@
     /* TODO: Think about using a IUnknown instead of a void* */
     void                     *extendedData;
-    
-  
 } IWineD3DQueryImpl;
 
-extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl;
-extern const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl;
-extern const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl;
+extern const IWineD3DQueryVtbl IWineD3DQuery_Vtbl DECLSPEC_HIDDEN;
+extern const IWineD3DQueryVtbl IWineD3DEventQuery_Vtbl DECLSPEC_HIDDEN;
+extern const IWineD3DQueryVtbl IWineD3DOcclusionQuery_Vtbl DECLSPEC_HIDDEN;
 
 /* IWineD3DBuffer */
@@ -2443,7 +2456,9 @@
 };
 
-extern const IWineD3DBufferVtbl wined3d_buffer_vtbl;
-const BYTE *buffer_get_memory(IWineD3DBuffer *iface, UINT offset, GLuint *buffer_object);
-BYTE *buffer_get_sysmem(struct wined3d_buffer *This);
+const BYTE *buffer_get_memory(IWineD3DBuffer *iface, UINT offset, GLuint *buffer_object) DECLSPEC_HIDDEN;
+BYTE *buffer_get_sysmem(struct wined3d_buffer *This) DECLSPEC_HIDDEN;
+HRESULT buffer_init(struct wined3d_buffer *buffer, IWineD3DDeviceImpl *device,
+        UINT size, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, GLenum bind_hint,
+        const char *data, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
 
 /* IWineD3DRendertargetView */
@@ -2457,5 +2472,5 @@
 };
 
-extern const IWineD3DRendertargetViewVtbl wined3d_rendertarget_view_vtbl;
+extern const IWineD3DRendertargetViewVtbl wined3d_rendertarget_view_vtbl DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -2489,81 +2504,105 @@
 } IWineD3DSwapChainImpl;
 
-extern const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl;
-const IWineD3DSwapChainVtbl IWineGDISwapChain_Vtbl;
-void x11_copy_to_screen(IWineD3DSwapChainImpl *This, const RECT *rc);
-
-HRESULT WINAPI IWineD3DBaseSwapChainImpl_QueryInterface(IWineD3DSwapChain *iface, REFIID riid, LPVOID *ppobj);
-ULONG WINAPI IWineD3DBaseSwapChainImpl_AddRef(IWineD3DSwapChain *iface);
-ULONG WINAPI IWineD3DBaseSwapChainImpl_Release(IWineD3DSwapChain *iface);
-HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetParent(IWineD3DSwapChain *iface, IUnknown ** ppParent);
-HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetFrontBufferData(IWineD3DSwapChain *iface, IWineD3DSurface *pDestSurface);
-HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetBackBuffer(IWineD3DSwapChain *iface, UINT iBackBuffer, WINED3DBACKBUFFER_TYPE Type, IWineD3DSurface **ppBackBuffer);
-HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetRasterStatus(IWineD3DSwapChain *iface, WINED3DRASTER_STATUS *pRasterStatus);
-HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDisplayMode(IWineD3DSwapChain *iface, WINED3DDISPLAYMODE*pMode);
-HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDevice(IWineD3DSwapChain *iface, IWineD3DDevice**ppDevice);
-HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetPresentParameters(IWineD3DSwapChain *iface, WINED3DPRESENT_PARAMETERS *pPresentationParameters);
-HRESULT WINAPI IWineD3DBaseSwapChainImpl_SetGammaRamp(IWineD3DSwapChain *iface, DWORD Flags, CONST WINED3DGAMMARAMP *pRamp);
-HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetGammaRamp(IWineD3DSwapChain *iface, WINED3DGAMMARAMP *pRamp);
-
-struct wined3d_context *IWineD3DSwapChainImpl_CreateContextForThread(IWineD3DSwapChain *iface);
+extern const IWineD3DSwapChainVtbl IWineD3DSwapChain_Vtbl DECLSPEC_HIDDEN;
+const IWineD3DSwapChainVtbl IWineGDISwapChain_Vtbl DECLSPEC_HIDDEN;
+void x11_copy_to_screen(IWineD3DSwapChainImpl *This, const RECT *rc) DECLSPEC_HIDDEN;
+
+HRESULT WINAPI IWineD3DBaseSwapChainImpl_QueryInterface(IWineD3DSwapChain *iface,
+        REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN;
+ULONG WINAPI IWineD3DBaseSwapChainImpl_AddRef(IWineD3DSwapChain *iface) DECLSPEC_HIDDEN;
+ULONG WINAPI IWineD3DBaseSwapChainImpl_Release(IWineD3DSwapChain *iface) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetParent(IWineD3DSwapChain *iface, IUnknown **ppParent) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetFrontBufferData(IWineD3DSwapChain *iface,
+        IWineD3DSurface *pDestSurface) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetBackBuffer(IWineD3DSwapChain *iface, UINT iBackBuffer,
+        WINED3DBACKBUFFER_TYPE Type, IWineD3DSurface **ppBackBuffer) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetRasterStatus(IWineD3DSwapChain *iface,
+        WINED3DRASTER_STATUS *pRasterStatus) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDisplayMode(IWineD3DSwapChain *iface,
+        WINED3DDISPLAYMODE *pMode) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDevice(IWineD3DSwapChain *iface,
+        IWineD3DDevice **ppDevice) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetPresentParameters(IWineD3DSwapChain *iface,
+        WINED3DPRESENT_PARAMETERS *pPresentationParameters) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSwapChainImpl_SetGammaRamp(IWineD3DSwapChain *iface,
+        DWORD Flags, const WINED3DGAMMARAMP *pRamp) DECLSPEC_HIDDEN;
+HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetGammaRamp(IWineD3DSwapChain *iface,
+        WINED3DGAMMARAMP *pRamp) DECLSPEC_HIDDEN;
+
+struct wined3d_context *IWineD3DSwapChainImpl_CreateContextForThread(IWineD3DSwapChain *iface) DECLSPEC_HIDDEN;
+
+#define DEFAULT_REFRESH_RATE 0
 
 /*****************************************************************************
- * Utility function prototypes 
+ * Utility function prototypes
  */
 
 /* Trace routines */
-const char* debug_d3dformat(WINED3DFORMAT fmt);
-const char* debug_d3ddevicetype(WINED3DDEVTYPE devtype);
-const char* debug_d3dresourcetype(WINED3DRESOURCETYPE res);
-const char* debug_d3dusage(DWORD usage);
-const char* debug_d3dusagequery(DWORD usagequery);
-const char* debug_d3ddeclmethod(WINED3DDECLMETHOD method);
-const char* debug_d3ddeclusage(BYTE usage);
-const char* debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType);
-const char* debug_d3drenderstate(DWORD state);
-const char* debug_d3dsamplerstate(DWORD state);
-const char* debug_d3dtexturefiltertype(WINED3DTEXTUREFILTERTYPE filter_type);
-const char* debug_d3dtexturestate(DWORD state);
-const char* debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype);
-const char* debug_d3dpool(WINED3DPOOL pool);
-const char *debug_fbostatus(GLenum status);
-const char *debug_glerror(GLenum error);
-const char *debug_d3dbasis(WINED3DBASISTYPE basis);
-const char *debug_d3ddegree(WINED3DDEGREETYPE order);
-const char* debug_d3dtop(WINED3DTEXTUREOP d3dtop);
-void dump_color_fixup_desc(struct color_fixup_desc fixup);
-const char *debug_surflocation(DWORD flag);
+const char *debug_d3dformat(WINED3DFORMAT fmt) DECLSPEC_HIDDEN;
+const char *debug_d3ddevicetype(WINED3DDEVTYPE devtype) DECLSPEC_HIDDEN;
+const char *debug_d3dresourcetype(WINED3DRESOURCETYPE res) DECLSPEC_HIDDEN;
+const char *debug_d3dusage(DWORD usage) DECLSPEC_HIDDEN;
+const char *debug_d3dusagequery(DWORD usagequery) DECLSPEC_HIDDEN;
+const char *debug_d3ddeclmethod(WINED3DDECLMETHOD method) DECLSPEC_HIDDEN;
+const char *debug_d3ddeclusage(BYTE usage) DECLSPEC_HIDDEN;
+const char *debug_d3dprimitivetype(WINED3DPRIMITIVETYPE PrimitiveType) DECLSPEC_HIDDEN;
+const char *debug_d3drenderstate(DWORD state) DECLSPEC_HIDDEN;
+const char *debug_d3dsamplerstate(DWORD state) DECLSPEC_HIDDEN;
+const char *debug_d3dtexturefiltertype(WINED3DTEXTUREFILTERTYPE filter_type) DECLSPEC_HIDDEN;
+const char *debug_d3dtexturestate(DWORD state) DECLSPEC_HIDDEN;
+const char *debug_d3dtstype(WINED3DTRANSFORMSTATETYPE tstype) DECLSPEC_HIDDEN;
+const char *debug_d3dpool(WINED3DPOOL pool) DECLSPEC_HIDDEN;
+const char *debug_fbostatus(GLenum status) DECLSPEC_HIDDEN;
+const char *debug_glerror(GLenum error) DECLSPEC_HIDDEN;
+const char *debug_d3dbasis(WINED3DBASISTYPE basis) DECLSPEC_HIDDEN;
+const char *debug_d3ddegree(WINED3DDEGREETYPE order) DECLSPEC_HIDDEN;
+const char *debug_d3dtop(WINED3DTEXTUREOP d3dtop) DECLSPEC_HIDDEN;
+void dump_color_fixup_desc(struct color_fixup_desc fixup) DECLSPEC_HIDDEN;
+const char *debug_surflocation(DWORD flag) DECLSPEC_HIDDEN;
 
 /* Routines for GL <-> D3D values */
-GLenum StencilOp(DWORD op);
-GLenum CompareFunc(DWORD func);
-BOOL is_invalid_op(IWineD3DDeviceImpl *This, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3);
-void   set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, WINED3DTEXTUREOP op, DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst);
-void   set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords, BOOL transformed, DWORD coordtype, BOOL ffp_can_disable_proj);
-void texture_activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context);
-void sampler_texdim(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context);
-void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context);
-void apply_pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context);
-void state_fogcolor(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context);
-void state_fogdensity(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context);
-void state_fogstartend(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context);
-void state_fog_fragpart(DWORD state, IWineD3DStateBlockImpl *stateblock, struct wined3d_context *context);
-
-void surface_add_dirty_rect(IWineD3DSurface *iface, const RECT *dirty_rect);
-GLenum surface_get_gl_buffer(IWineD3DSurface *iface, IWineD3DSwapChain *swapchain);
-void surface_load_ds_location(IWineD3DSurface *iface, struct wined3d_context *context, DWORD location);
-void surface_modify_ds_location(IWineD3DSurface *iface, DWORD location);
-void surface_set_compatible_renderbuffer(IWineD3DSurface *iface, unsigned int width, unsigned int height);
-void surface_set_texture_name(IWineD3DSurface *iface, GLuint name, BOOL srgb_name);
-void surface_set_texture_target(IWineD3DSurface *iface, GLenum target);
+GLenum StencilOp(DWORD op) DECLSPEC_HIDDEN;
+GLenum CompareFunc(DWORD func) DECLSPEC_HIDDEN;
+BOOL is_invalid_op(IWineD3DDeviceImpl *This, int stage, WINED3DTEXTUREOP op,
+        DWORD arg1, DWORD arg2, DWORD arg3) DECLSPEC_HIDDEN;
+void set_tex_op_nvrc(IWineD3DDevice *iface, BOOL is_alpha, int stage, WINED3DTEXTUREOP op,
+        DWORD arg1, DWORD arg2, DWORD arg3, INT texture_idx, DWORD dst) DECLSPEC_HIDDEN;
+void set_texture_matrix(const float *smat, DWORD flags, BOOL calculatedCoords,
+        BOOL transformed, DWORD coordtype, BOOL ffp_can_disable_proj) DECLSPEC_HIDDEN;
+void texture_activate_dimensions(DWORD stage, IWineD3DStateBlockImpl *stateblock,
+        struct wined3d_context *context) DECLSPEC_HIDDEN;
+void sampler_texdim(DWORD state, IWineD3DStateBlockImpl *stateblock,
+        struct wined3d_context *context) DECLSPEC_HIDDEN;
+void tex_alphaop(DWORD state, IWineD3DStateBlockImpl *stateblock,
+        struct wined3d_context *context) DECLSPEC_HIDDEN;
+void apply_pixelshader(DWORD state, IWineD3DStateBlockImpl *stateblock,
+        struct wined3d_context *context) DECLSPEC_HIDDEN;
+void state_fogcolor(DWORD state, IWineD3DStateBlockImpl *stateblock,
+        struct wined3d_context *context) DECLSPEC_HIDDEN;
+void state_fogdensity(DWORD state, IWineD3DStateBlockImpl *stateblock,
+        struct wined3d_context *context) DECLSPEC_HIDDEN;
+void state_fogstartend(DWORD state, IWineD3DStateBlockImpl *stateblock,
+        struct wined3d_context *context) DECLSPEC_HIDDEN;
+void state_fog_fragpart(DWORD state, IWineD3DStateBlockImpl *stateblock,
+        struct wined3d_context *context) DECLSPEC_HIDDEN;
+
+void surface_add_dirty_rect(IWineD3DSurface *iface, const RECT *dirty_rect) DECLSPEC_HIDDEN;
+GLenum surface_get_gl_buffer(IWineD3DSurface *iface, IWineD3DSwapChain *swapchain) DECLSPEC_HIDDEN;
+void surface_load_ds_location(IWineD3DSurface *iface, struct wined3d_context *context, DWORD location) DECLSPEC_HIDDEN;
+void surface_modify_ds_location(IWineD3DSurface *iface, DWORD location) DECLSPEC_HIDDEN;
+void surface_set_compatible_renderbuffer(IWineD3DSurface *iface,
+        unsigned int width, unsigned int height) DECLSPEC_HIDDEN;
+void surface_set_texture_name(IWineD3DSurface *iface, GLuint name, BOOL srgb_name) DECLSPEC_HIDDEN;
+void surface_set_texture_target(IWineD3DSurface *iface, GLenum target) DECLSPEC_HIDDEN;
 
 BOOL getColorBits(const struct GlPixelFormatDesc *format_desc,
-        short *redSize, short *greenSize, short *blueSize, short *alphaSize, short *totalSize);
-BOOL getDepthStencilBits(const struct GlPixelFormatDesc *format_desc, short *depthSize, short *stencilSize);
+        short *redSize, short *greenSize, short *blueSize, short *alphaSize, short *totalSize) DECLSPEC_HIDDEN;
+BOOL getDepthStencilBits(const struct GlPixelFormatDesc *format_desc,
+        short *depthSize, short *stencilSize) DECLSPEC_HIDDEN;
 
 /* Math utils */
-void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2);
-UINT wined3d_log2i(UINT32 x);
-unsigned int count_bits(unsigned int mask);
+void multiply_matrix(WINED3DMATRIX *dest, const WINED3DMATRIX *src1, const WINED3DMATRIX *src2) DECLSPEC_HIDDEN;
+UINT wined3d_log2i(UINT32 x) DECLSPEC_HIDDEN;
+unsigned int count_bits(unsigned int mask) DECLSPEC_HIDDEN;
 
 typedef struct local_constant {
@@ -2587,6 +2626,6 @@
 } SHADER_LIMITS;
 
-/** Keeps track of details for TEX_M#x# shader opcodes which need to 
-    maintain state information between multiple codes */
+/* Keeps track of details for TEX_M#x# shader opcodes which need to
+ * maintain state information between multiple codes */
 typedef struct SHADER_PARSE_STATE {
     unsigned int current_row;
@@ -2601,14 +2640,12 @@
 
 /* Base Shader utility functions. */
-int shader_addline(struct wined3d_shader_buffer *buffer, const char *fmt, ...) PRINTF_ATTR(2,3);
-int shader_vaddline(struct wined3d_shader_buffer *buffer, const char *fmt, va_list args);
+int shader_addline(struct wined3d_shader_buffer *buffer, const char *fmt, ...) PRINTF_ATTR(2,3) DECLSPEC_HIDDEN;
+int shader_vaddline(struct wined3d_shader_buffer *buffer, const char *fmt, va_list args) DECLSPEC_HIDDEN;
 
 /* Vertex shader utility functions */
-extern BOOL vshader_get_input(
-    IWineD3DVertexShader* iface,
-    BYTE usage_req, BYTE usage_idx_req,
-    unsigned int* regnum);
-
-extern HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object);
+extern BOOL vshader_get_input(IWineD3DVertexShader *iface,
+        BYTE usage_req, BYTE usage_idx_req, unsigned int *regnum) DECLSPEC_HIDDEN;
+
+extern HRESULT allocate_shader_constants(IWineD3DStateBlockImpl* object) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -2626,4 +2663,8 @@
     const struct wined3d_shader_frontend *frontend;
     void *frontend_data;
+    void *backend_data;
+
+    IUnknown *parent;
+    const struct wined3d_parent_ops *parent_ops;
 
     /* Programs this shader is linked with */
@@ -2650,22 +2691,25 @@
 } IWineD3DBaseShaderImpl;
 
-void shader_buffer_clear(struct wined3d_shader_buffer *buffer);
-BOOL shader_buffer_init(struct wined3d_shader_buffer *buffer);
-void shader_buffer_free(struct wined3d_shader_buffer *buffer);
-void shader_cleanup(IWineD3DBaseShader *iface);
+void shader_buffer_clear(struct wined3d_shader_buffer *buffer) DECLSPEC_HIDDEN;
+BOOL shader_buffer_init(struct wined3d_shader_buffer *buffer) DECLSPEC_HIDDEN;
+void shader_buffer_free(struct wined3d_shader_buffer *buffer) DECLSPEC_HIDDEN;
+void shader_cleanup(IWineD3DBaseShader *iface) DECLSPEC_HIDDEN;
 void shader_dump_src_param(const struct wined3d_shader_src_param *param,
-        const struct wined3d_shader_version *shader_version);
+        const struct wined3d_shader_version *shader_version) DECLSPEC_HIDDEN;
 void shader_dump_dst_param(const struct wined3d_shader_dst_param *param,
-        const struct wined3d_shader_version *shader_version);
+        const struct wined3d_shader_version *shader_version) DECLSPEC_HIDDEN;
+unsigned int shader_find_free_input_register(const struct shader_reg_maps *reg_maps, unsigned int max) DECLSPEC_HIDDEN;
 void shader_generate_main(IWineD3DBaseShader *iface, struct wined3d_shader_buffer *buffer,
-        const shader_reg_maps *reg_maps, const DWORD *pFunction, void *backend_ctx);
+        const shader_reg_maps *reg_maps, const DWORD *pFunction, void *backend_ctx) DECLSPEC_HIDDEN;
 HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, const struct wined3d_shader_frontend *fe,
         struct shader_reg_maps *reg_maps, struct wined3d_shader_attribute *attributes,
         struct wined3d_shader_signature_element *input_signature,
-        struct wined3d_shader_signature_element *output_signature, const DWORD *byte_code, DWORD constf_size);
-void shader_init(struct IWineD3DBaseShaderClass *shader, IWineD3DDevice *device);
-BOOL shader_match_semantic(const char *semantic_name, WINED3DDECLUSAGE usage);
-const struct wined3d_shader_frontend *shader_select_frontend(DWORD version_token);
-void shader_trace_init(const struct wined3d_shader_frontend *fe, void *fe_data, const DWORD *pFunction);
+        struct wined3d_shader_signature_element *output_signature,
+        const DWORD *byte_code, DWORD constf_size) DECLSPEC_HIDDEN;
+void shader_init(struct IWineD3DBaseShaderClass *shader, IWineD3DDeviceImpl *device,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
+BOOL shader_match_semantic(const char *semantic_name, WINED3DDECLUSAGE usage) DECLSPEC_HIDDEN;
+const struct wined3d_shader_frontend *shader_select_frontend(DWORD version_token) DECLSPEC_HIDDEN;
+void shader_trace_init(const struct wined3d_shader_frontend *fe, void *fe_data, const DWORD *pFunction) DECLSPEC_HIDDEN;
 
 static inline BOOL shader_is_pshader_version(enum wined3d_shader_type type)
@@ -2735,17 +2779,9 @@
  */
 typedef struct IWineD3DVertexShaderImpl {
-    /* IUnknown parts*/   
+    /* IUnknown parts */
     const IWineD3DVertexShaderVtbl *lpVtbl;
 
     /* IWineD3DBaseShader */
     IWineD3DBaseShaderClass     baseShader;
-
-    /* IWineD3DVertexShaderImpl */
-    IUnknown                    *parent;
-
-    DWORD                       usage;
-
-    /* The GL shader */
-    void                        *backend_priv;
 
     /* Vertex shader input and output semantics */
@@ -2755,10 +2791,11 @@
     UINT                       min_rel_offset, max_rel_offset;
     UINT                       rel_offset;
-
-    UINT                       recompile_count;
 } IWineD3DVertexShaderImpl;
-extern const IWineD3DVertexShaderVtbl IWineD3DVertexShader_Vtbl;
-
-void find_vs_compile_args(IWineD3DVertexShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct vs_compile_args *args);
+
+void find_vs_compile_args(IWineD3DVertexShaderImpl *shader, IWineD3DStateBlockImpl *stateblock,
+        struct vs_compile_args *args) DECLSPEC_HIDDEN;
+HRESULT vertexshader_init(IWineD3DVertexShaderImpl *shader, IWineD3DDeviceImpl *device,
+        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -2790,7 +2827,4 @@
     IWineD3DBaseShaderClass     baseShader;
 
-    /* IWineD3DPixelShaderImpl */
-    IUnknown                   *parent;
-
     /* Pixel shader input semantics */
     struct wined3d_shader_signature_element input_signature[MAX_REG_INPUT];
@@ -2799,7 +2833,4 @@
     unsigned int declared_in_count;
 
-    /* The GL shader */
-    void                        *backend_priv;
-
     /* Some information about the shader behavior */
     char                        vpos_uniform;
@@ -2810,7 +2841,11 @@
 } IWineD3DPixelShaderImpl;
 
-extern const IWineD3DPixelShaderVtbl IWineD3DPixelShader_Vtbl;
-void pixelshader_update_samplers(struct shader_reg_maps *reg_maps, IWineD3DBaseTexture * const *textures);
-void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWineD3DStateBlockImpl *stateblock, struct ps_compile_args *args);
+HRESULT pixelshader_init(IWineD3DPixelShaderImpl *shader, IWineD3DDeviceImpl *device,
+        const DWORD *byte_code, const struct wined3d_shader_signature *output_signature,
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
+void pixelshader_update_samplers(struct shader_reg_maps *reg_maps,
+        IWineD3DBaseTexture * const *textures) DECLSPEC_HIDDEN;
+void find_ps_compile_args(IWineD3DPixelShaderImpl *shader, IWineD3DStateBlockImpl *stateblock,
+        struct ps_compile_args *args) DECLSPEC_HIDDEN;
 
 /* sRGB correction constants */
@@ -2842,9 +2877,9 @@
 };
 
-extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl;
-DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags);
+extern const IWineD3DPaletteVtbl IWineD3DPalette_Vtbl DECLSPEC_HIDDEN;
+DWORD IWineD3DPaletteImpl_Size(DWORD dwFlags) DECLSPEC_HIDDEN;
 
 /* DirectDraw utility functions */
-extern WINED3DFORMAT pixelformat_for_depth(DWORD depth);
+extern WINED3DFORMAT pixelformat_for_depth(DWORD depth) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -2861,4 +2896,5 @@
 #define WINED3DFMT_FLAG_FBO_ATTACHABLE           0x40
 #define WINED3DFMT_FLAG_COMPRESSED               0x80
+#define WINED3DFMT_FLAG_GETDC                    0x100
 
 struct GlPixelFormatDesc
@@ -2894,10 +2930,15 @@
 };
 
-const struct GlPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, const struct wined3d_gl_info *gl_info);
+const struct GlPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt,
+        const struct wined3d_gl_info *gl_info) DECLSPEC_HIDDEN;
 
 static inline BOOL use_vs(IWineD3DStateBlockImpl *stateblock)
 {
+    /* Check stateblock->vertexDecl to allow this to be used from
+     * IWineD3DDeviceImpl_FindTexUnitMap(). This is safe because
+     * stateblock->vertexShader implies a vertex declaration instead of ddraw
+     * style strided data. */
     return (stateblock->vertexShader
-            && !stateblock->wineD3DDevice->strided_streams.position_transformed
+            && !((IWineD3DVertexDeclarationImpl *)stateblock->vertexDecl)->position_transformed
             && stateblock->wineD3DDevice->vs_selected_mode != SHADER_NONE);
 }
@@ -2909,6 +2950,7 @@
 }
 
-void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface, WINED3DRECT *src_rect,
-        IWineD3DSurface *dst_surface, WINED3DRECT *dst_rect, const WINED3DTEXTUREFILTERTYPE filter, BOOL flip);
+void stretch_rect_fbo(IWineD3DDevice *iface, IWineD3DSurface *src_surface,
+        WINED3DRECT *src_rect, IWineD3DSurface *dst_surface, WINED3DRECT *dst_rect,
+        const WINED3DTEXTUREFILTERTYPE filter, BOOL flip) DECLSPEC_HIDDEN;
 
 /* The WNDCLASS-Name for the fake window which we use to retrieve the GL capabilities */
