Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/cubetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/cubetexture.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/cubetexture.c	(revision 21731)
@@ -211,20 +211,19 @@
     TRACE("(%p) Relay\n", This);
 
-    /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
-    wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
-    wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
-    wined3ddesc.Usage               = &pDesc->Usage;
-    wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
-    wined3ddesc.Size                = &pDesc->Size;
-    wined3ddesc.MultiSampleType     = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
-    wined3ddesc.MultiSampleQuality  = NULL; /* DirectX9 only */
-    wined3ddesc.Width               = &pDesc->Width;
-    wined3ddesc.Height              = &pDesc->Height;
-
     EnterCriticalSection(&d3d8_cs);
     hr = IWineD3DCubeTexture_GetLevelDesc(This->wineD3DCubeTexture, Level, &wined3ddesc);
     LeaveCriticalSection(&d3d8_cs);
 
-    if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(pDesc->Format);
+    if (SUCCEEDED(hr))
+    {
+        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
+        pDesc->Type = wined3ddesc.resource_type;
+        pDesc->Usage = wined3ddesc.usage;
+        pDesc->Pool = wined3ddesc.pool;
+        pDesc->Size = wined3ddesc.size;
+        pDesc->MultiSampleType = wined3ddesc.multisample_type;
+        pDesc->Width = wined3ddesc.width;
+        pDesc->Height = wined3ddesc.height;
+    }
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_private.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_private.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/d3d8_private.h	(revision 21731)
@@ -176,8 +176,22 @@
 #define D3D8_INVALID_HANDLE ~0U
 
+enum d3d8_handle_type
+{
+    D3D8_HANDLE_FREE,
+    D3D8_HANDLE_VS,
+    D3D8_HANDLE_PS,
+    D3D8_HANDLE_SB,
+};
+
+struct d3d8_handle_entry
+{
+    void *object;
+    enum d3d8_handle_type type;
+};
+
 struct d3d8_handle_table
 {
-    void **entries;
-    void **free_entries;
+    struct d3d8_handle_entry *entries;
+    struct d3d8_handle_entry *free_entries;
     UINT table_size;
     UINT entry_count;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/device.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/device.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/device.c	(revision 21731)
@@ -79,4 +79,5 @@
         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_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
@@ -129,4 +130,5 @@
         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_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
@@ -173,12 +175,21 @@
 
 /* Handle table functions */
-static DWORD d3d8_allocate_handle(struct d3d8_handle_table *t, void *object)
+static DWORD d3d8_allocate_handle(struct d3d8_handle_table *t, void *object, enum d3d8_handle_type type)
 {
+    struct d3d8_handle_entry *entry;
+
     if (t->free_entries)
     {
         /* Use a free handle */
-        void **entry = t->free_entries;
-        t->free_entries = *entry;
-        *entry = object;
+        entry = t->free_entries;
+        if (entry->type != D3D8_HANDLE_FREE)
+        {
+            ERR("Handle %u(%p) is in the free list, but has type %#x.\n", (entry - t->entries), entry, entry->type);
+            return D3D8_INVALID_HANDLE;
+        }
+        t->free_entries = entry->object;
+        entry->object = object;
+        entry->type = type;
+
         return entry - t->entries;
     }
@@ -188,23 +199,43 @@
         /* Grow the table */
         UINT new_size = t->table_size + (t->table_size >> 1);
-        void **new_entries = HeapReAlloc(GetProcessHeap(), 0, t->entries, new_size * sizeof(void *));
-        if (!new_entries) return D3D8_INVALID_HANDLE;
+        struct d3d8_handle_entry *new_entries = HeapReAlloc(GetProcessHeap(),
+                0, t->entries, new_size * sizeof(*t->entries));
+        if (!new_entries)
+        {
+            ERR("Failed to grow the handle table.\n");
+            return D3D8_INVALID_HANDLE;
+        }
         t->entries = new_entries;
         t->table_size = new_size;
     }
 
-    t->entries[t->entry_count] = object;
+    entry = &t->entries[t->entry_count];
+    entry->object = object;
+    entry->type = type;
+
     return t->entry_count++;
 }
 
-static void *d3d8_free_handle(struct d3d8_handle_table *t, DWORD handle)
+static void *d3d8_free_handle(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
 {
-    void **entry, *object;
-
-    if (handle >= t->entry_count) return NULL;
+    struct d3d8_handle_entry *entry;
+    void *object;
+
+    if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
+    {
+        WARN("Invalid handle %u passed.\n", handle);
+        return NULL;
+    }
 
     entry = &t->entries[handle];
-    object = *entry;
-    *entry = t->free_entries;
+    if (entry->type != type)
+    {
+        WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
+        return NULL;
+    }
+
+    object = entry->object;
+    entry->object = t->free_entries;
+    entry->type = D3D8_HANDLE_FREE;
     t->free_entries = entry;
 
@@ -212,8 +243,22 @@
 }
 
-static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle)
+static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d8_handle_type type)
 {
-    if (handle >= t->entry_count) return NULL;
-    return t->entries[handle];
+    struct d3d8_handle_entry *entry;
+
+    if (handle == D3D8_INVALID_HANDLE || handle >= t->entry_count)
+    {
+        WARN("Invalid handle %u passed.\n", handle);
+        return NULL;
+    }
+
+    entry = &t->entries[handle];
+    if (entry->type != type)
+    {
+        WARN("Handle %u(%p) is not of type %#x.\n", handle, entry, type);
+        return NULL;
+    }
+
+    return entry->object;
 }
 
@@ -804,5 +849,8 @@
 }
 
-static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,D3DRESOURCETYPE Type, UINT Usage,D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)  {
+static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height,
+        D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,
+        UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
+{
     HRESULT hrc;
     IDirect3DSurface8Impl *object;
@@ -835,6 +883,6 @@
     EnterCriticalSection(&d3d8_cs);
     hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
-            Lockable, Discard, Level,  &object->wineD3DSurface, Type, Usage & WINED3DUSAGE_MASK,
-            (WINED3DPOOL)Pool, MultiSample, MultisampleQuality, SURFACE_OPENGL, (IUnknown *)object);
+            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) {
@@ -855,5 +903,7 @@
     TRACE("Relay\n");
 
-    hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */, 0 /* Level */ , ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
+    hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
+            0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, 0);
+
     return hr;
 }
@@ -864,7 +914,7 @@
 
     /* TODO: Verify that Discard is false */
-    hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE, 0 /* Level */
-                                               ,ppSurface, D3DRTYPE_SURFACE, D3DUSAGE_DEPTHSTENCIL,
-                                                D3DPOOL_DEFAULT, MultiSample, 0);
+    hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE,
+            0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, 0);
+
     return hr;
 }
@@ -875,6 +925,8 @@
     TRACE("Relay\n");
 
-    hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Loackable */ , FALSE /*Discard*/ , 0 /* Level */ , ppSurface,
-                                            D3DRTYPE_SURFACE, 0 /* Usage (undefined/none) */ , D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
+    hr = IDirect3DDevice8Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
+            0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, D3DPOOL_SYSTEMMEM, D3DMULTISAMPLE_NONE,
+            0 /* MultisampleQuality */);
+
     return hr;
 }
@@ -896,18 +948,16 @@
 
     /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the destination texture is in WINED3DPOOL_DEFAULT */
-    memset(&winedesc, 0, sizeof(winedesc));
-
-    winedesc.Format = &srcFormat;
-    winedesc.Width  = &srcWidth;
-    winedesc.Height = &srcHeight;
-    winedesc.Size   = &srcSize;
+
     EnterCriticalSection(&d3d8_cs);
     IWineD3DSurface_GetDesc(Source->wineD3DSurface, &winedesc);
-
-    winedesc.Format = &destFormat;
-    winedesc.Width  = &destWidth;
-    winedesc.Height = &destHeight;
-    winedesc.Size   = NULL;
+    srcFormat = winedesc.format;
+    srcWidth = winedesc.width;
+    srcHeight = winedesc.height;
+    srcSize = winedesc.size;
+
     IWineD3DSurface_GetDesc(Dest->wineD3DSurface, &winedesc);
+    destFormat = winedesc.format;
+    destWidth = winedesc.width;
+    destHeight = winedesc.height;
 
     /* Check that the source and destination formats match */
@@ -1291,5 +1341,5 @@
     object->wineD3DStateBlock = wineD3DStateBlock;
 
-    *pToken = d3d8_allocate_handle(&This->handle_table, object);
+    *pToken = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
     LeaveCriticalSection(&d3d8_cs);
 
@@ -1315,5 +1365,5 @@
 
     EnterCriticalSection(&d3d8_cs);
-    pSB = d3d8_get_object(&This->handle_table, Token - 1);
+    pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
     if (!pSB)
     {
@@ -1335,5 +1385,5 @@
 
     EnterCriticalSection(&d3d8_cs);
-    pSB = d3d8_get_object(&This->handle_table, Token - 1);
+    pSB = d3d8_get_object(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
     if (!pSB)
     {
@@ -1354,5 +1404,5 @@
 
     EnterCriticalSection(&d3d8_cs);
-    pSB = d3d8_free_handle(&This->handle_table, Token - 1);
+    pSB = d3d8_free_handle(&This->handle_table, Token - 1, D3D8_HANDLE_SB);
     LeaveCriticalSection(&d3d8_cs);
 
@@ -1409,5 +1459,5 @@
     }
 
-    *handle = d3d8_allocate_handle(&This->handle_table, object);
+    *handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_SB);
     LeaveCriticalSection(&d3d8_cs);
 
@@ -1776,5 +1826,5 @@
 
     EnterCriticalSection(&d3d8_cs);
-    handle = d3d8_allocate_handle(&This->handle_table, object);
+    handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_VS);
     if (handle == D3D8_INVALID_HANDLE)
     {
@@ -1802,5 +1852,5 @@
             /* free up object */
             FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
-            d3d8_free_handle(&This->handle_table, handle);
+            d3d8_free_handle(&This->handle_table, handle, D3D8_HANDLE_VS);
             IDirect3DVertexDeclaration8_Release(object->vertex_declaration);
             HeapFree(GetProcessHeap(), 0, object);
@@ -1909,5 +1959,5 @@
 
     EnterCriticalSection(&d3d8_cs);
-    shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
+    shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
     if (!shader)
     {
@@ -1975,5 +2025,5 @@
     EnterCriticalSection(&d3d8_cs);
 
-    shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
+    shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
     if (!shader)
     {
@@ -2044,5 +2094,5 @@
     EnterCriticalSection(&d3d8_cs);
 
-    shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1));
+    shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
     LeaveCriticalSection(&d3d8_cs);
     if (!shader)
@@ -2080,5 +2130,5 @@
     EnterCriticalSection(&d3d8_cs);
 
-    shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1));
+    shader = d3d8_get_object(&This->handle_table, pVertexShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_VS);
     if (!shader)
     {
@@ -2183,5 +2233,5 @@
     }
 
-    handle = d3d8_allocate_handle(&This->handle_table, object);
+    handle = d3d8_allocate_handle(&This->handle_table, object, D3D8_HANDLE_PS);
     LeaveCriticalSection(&d3d8_cs);
     if (handle == D3D8_INVALID_HANDLE)
@@ -2214,5 +2264,5 @@
     }
 
-    shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
+    shader = d3d8_get_object(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
     if (!shader)
     {
@@ -2265,10 +2315,10 @@
     EnterCriticalSection(&d3d8_cs);
 
-    shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1));
+    shader = d3d8_free_handle(&This->handle_table, pShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
     if (!shader)
     {
         WARN("Invalid handle (%#x) passed.\n", pShader);
         LeaveCriticalSection(&d3d8_cs);
-        return D3DERR_INVALIDCALL;
+        return D3D_OK;
     }
 
@@ -2321,5 +2371,5 @@
 
     EnterCriticalSection(&d3d8_cs);
-    shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1));
+    shader = d3d8_get_object(&This->handle_table, pPixelShader - (VS_HIGHESTFIXEDFXF + 1), D3D8_HANDLE_PS);
     if (!shader)
     {
@@ -2571,6 +2621,5 @@
     hr = IDirect3DDevice8Impl_CreateSurface((IDirect3DDevice8 *)This, width, height,
             d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
-            (IDirect3DSurface8 **)&d3d_surface, D3DRTYPE_SURFACE, usage, pool,
-            D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
+            (IDirect3DSurface8 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
     if (FAILED(hr))
     {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/directx.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/directx.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/directx.c	(revision 21731)
@@ -113,6 +113,7 @@
 }
 
-static HRESULT  WINAPI  IDirect3D8Impl_GetAdapterIdentifier       (LPDIRECT3D8 iface,
-                                                            UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8* pIdentifier) {
+static HRESULT WINAPI IDirect3D8Impl_GetAdapterIdentifier(LPDIRECT3D8 iface,
+        UINT Adapter, DWORD Flags, D3DADAPTER_IDENTIFIER8 *pIdentifier)
+{
     IDirect3D8Impl *This = (IDirect3D8Impl *)iface;
     WINED3DADAPTER_IDENTIFIER adapter_id;
@@ -120,21 +121,24 @@
 
     TRACE("(%p)->(%d,%08x, %p\n", This, Adapter, Flags, pIdentifier);
-    EnterCriticalSection(&d3d8_cs);
-    /* dx8 and dx9 have different structures to be filled in, with incompatible 
-       layouts so pass in pointers to the places to be filled via an internal 
-       structure                                                                */
-    adapter_id.Driver           = pIdentifier->Driver;
-    adapter_id.Description      = pIdentifier->Description;
-    adapter_id.DeviceName       = NULL; /* d3d9 only */
-    adapter_id.DriverVersion    = &pIdentifier->DriverVersion;
-    adapter_id.VendorId         = &pIdentifier->VendorId;
-    adapter_id.DeviceId         = &pIdentifier->DeviceId;
-    adapter_id.SubSysId         = &pIdentifier->SubSysId;
-    adapter_id.Revision         = &pIdentifier->Revision;
-    adapter_id.DeviceIdentifier = &pIdentifier->DeviceIdentifier;
-    adapter_id.WHQLLevel        = &pIdentifier->WHQLLevel;
-
+
+    adapter_id.driver = pIdentifier->Driver;
+    adapter_id.driver_size = sizeof(pIdentifier->Driver);
+    adapter_id.description = pIdentifier->Description;
+    adapter_id.description_size = sizeof(pIdentifier->Description);
+    adapter_id.device_name = NULL; /* d3d9 only */
+    adapter_id.device_name_size = 0; /* d3d9 only */
+
+    EnterCriticalSection(&d3d8_cs);
     hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
     LeaveCriticalSection(&d3d8_cs);
+
+    pIdentifier->DriverVersion = adapter_id.driver_version;
+    pIdentifier->VendorId = adapter_id.vendor_id;
+    pIdentifier->DeviceId = adapter_id.device_id;
+    pIdentifier->SubSysId = adapter_id.subsystem_id;
+    pIdentifier->Revision = adapter_id.revision;
+    memcpy(&pIdentifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(pIdentifier->DeviceIdentifier));
+    pIdentifier->WHQLLevel = adapter_id.whql_level;
+
     return hr;
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/surface.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/surface.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/surface.c	(revision 21731)
@@ -169,20 +169,19 @@
     TRACE("(%p) Relay\n", This);
 
-    /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
-    memset(&wined3ddesc, 0, sizeof(wined3ddesc));
-    wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
-    wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
-    wined3ddesc.Usage               = &pDesc->Usage;
-    wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
-    wined3ddesc.Size                = &pDesc->Size;
-    wined3ddesc.MultiSampleType     = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
-    wined3ddesc.Width               = &pDesc->Width;
-    wined3ddesc.Height              = &pDesc->Height;
-
     EnterCriticalSection(&d3d8_cs);
     hr = IWineD3DSurface_GetDesc(This->wineD3DSurface, &wined3ddesc);
     LeaveCriticalSection(&d3d8_cs);
 
-    if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(pDesc->Format);
+    if (SUCCEEDED(hr))
+    {
+        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
+        pDesc->Type = wined3ddesc.resource_type;
+        pDesc->Usage = wined3ddesc.usage;
+        pDesc->Pool = wined3ddesc.pool;
+        pDesc->Size = wined3ddesc.size;
+        pDesc->MultiSampleType = wined3ddesc.multisample_type;
+        pDesc->Width = wined3ddesc.width;
+        pDesc->Height = wined3ddesc.height;
+    }
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/texture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/texture.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/texture.c	(revision 21731)
@@ -210,20 +210,19 @@
     TRACE("(%p) Relay\n", This);
 
-    /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
-    memset(&wined3ddesc, 0, sizeof(wined3ddesc));
-    wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
-    wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
-    wined3ddesc.Usage               = &pDesc->Usage;
-    wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
-    wined3ddesc.Size                = &pDesc->Size;
-    wined3ddesc.MultiSampleType     = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
-    wined3ddesc.Width               = &pDesc->Width;
-    wined3ddesc.Height              = &pDesc->Height;
-
     EnterCriticalSection(&d3d8_cs);
     hr = IWineD3DTexture_GetLevelDesc(This->wineD3DTexture, Level, &wined3ddesc);
     LeaveCriticalSection(&d3d8_cs);
 
-    if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(pDesc->Format);
+    if (SUCCEEDED(hr))
+    {
+        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
+        pDesc->Type = wined3ddesc.resource_type;
+        pDesc->Usage = wined3ddesc.usage;
+        pDesc->Pool = wined3ddesc.pool;
+        pDesc->Size = wined3ddesc.size;
+        pDesc->MultiSampleType = wined3ddesc.multisample_type;
+        pDesc->Width = wined3ddesc.width;
+        pDesc->Height = wined3ddesc.height;
+    }
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/version.rc
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/version.rc	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/version.rc	(revision 21731)
@@ -26,4 +26,13 @@
  */
 
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
 #define WINE_FILEDESCRIPTION_STR "Wine Direct3D"
 #define WINE_FILENAME_STR "d3d8.dll"
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volume.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volume.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volume.c	(revision 21731)
@@ -164,19 +164,19 @@
     TRACE("(%p) Relay\n", This);
 
-    /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
-    wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
-    wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
-    wined3ddesc.Usage               = &pDesc->Usage;
-    wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
-    wined3ddesc.Size                = &pDesc->Size;
-    wined3ddesc.Width               = &pDesc->Width;
-    wined3ddesc.Height              = &pDesc->Height;
-    wined3ddesc.Depth               = &pDesc->Depth;
-
     EnterCriticalSection(&d3d8_cs);
     hr = IWineD3DVolume_GetDesc(This->wineD3DVolume, &wined3ddesc);
     LeaveCriticalSection(&d3d8_cs);
 
-    if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(pDesc->Format);
+    if (SUCCEEDED(hr))
+    {
+        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.Format);
+        pDesc->Type = wined3ddesc.Type;
+        pDesc->Usage = wined3ddesc.Usage;
+        pDesc->Pool = wined3ddesc.Pool;
+        pDesc->Size = wined3ddesc.Size;
+        pDesc->Width = wined3ddesc.Width;
+        pDesc->Height = wined3ddesc.Height;
+        pDesc->Depth = wined3ddesc.Depth;
+    }
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volumetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volumetexture.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d8/volumetexture.c	(revision 21731)
@@ -207,18 +207,7 @@
     IDirect3DVolumeTexture8Impl *This = (IDirect3DVolumeTexture8Impl *)iface;
     WINED3DVOLUME_DESC     wined3ddesc;
-    UINT                   tmpInt = -1;
-    HRESULT hr;
-
-    TRACE("(%p) Relay\n", This);
-
-    /* As d3d8 and d3d8 structures differ, pass in ptrs to where data needs to go */
-    wined3ddesc.Format              = (WINED3DFORMAT *)&pDesc->Format;
-    wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
-    wined3ddesc.Usage               = &pDesc->Usage;
-    wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
-    wined3ddesc.Size                = &tmpInt;
-    wined3ddesc.Width               = &pDesc->Width;
-    wined3ddesc.Height              = &pDesc->Height;
-    wined3ddesc.Depth               = &pDesc->Depth;
+    HRESULT hr;
+
+    TRACE("(%p) Relay\n", This);
 
     EnterCriticalSection(&d3d8_cs);
@@ -226,5 +215,15 @@
     LeaveCriticalSection(&d3d8_cs);
 
-    if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(pDesc->Format);
+    if (SUCCEEDED(hr))
+    {
+        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.Format);
+        pDesc->Type = wined3ddesc.Type;
+        pDesc->Usage = wined3ddesc.Usage;
+        pDesc->Pool = wined3ddesc.Pool;
+        pDesc->Size = wined3ddesc.Size;
+        pDesc->Width = wined3ddesc.Width;
+        pDesc->Height = wined3ddesc.Height;
+        pDesc->Depth = wined3ddesc.Depth;
+    }
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/cubetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/cubetexture.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/cubetexture.c	(revision 21731)
@@ -242,21 +242,8 @@
 static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(LPDIRECT3DCUBETEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
     IDirect3DCubeTexture9Impl *This = (IDirect3DCubeTexture9Impl *)iface;
-    WINED3DSURFACE_DESC    wined3ddesc;
-    UINT                   tmpInt = -1;
-    WINED3DFORMAT format;
-    HRESULT hr;
-
-    TRACE("(%p) Relay\n", This);
-
-    /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
-    wined3ddesc.Format              = &format;
-    wined3ddesc.Type                = (WINED3DRESOURCETYPE *) &pDesc->Type;
-    wined3ddesc.Usage               = &pDesc->Usage;
-    wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
-    wined3ddesc.Size                = &tmpInt;
-    wined3ddesc.MultiSampleType     = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
-    wined3ddesc.MultiSampleQuality  = &pDesc->MultiSampleQuality;
-    wined3ddesc.Width               = &pDesc->Width;
-    wined3ddesc.Height              = &pDesc->Height;
+    WINED3DSURFACE_DESC wined3ddesc;
+    HRESULT hr;
+
+    TRACE("(%p) Relay\n", This);
 
     EnterCriticalSection(&d3d9_cs);
@@ -264,5 +251,15 @@
     LeaveCriticalSection(&d3d9_cs);
 
-    if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(format);
+    if (SUCCEEDED(hr))
+    {
+        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
+        pDesc->Type = wined3ddesc.resource_type;
+        pDesc->Usage = wined3ddesc.usage;
+        pDesc->Pool = wined3ddesc.pool;
+        pDesc->MultiSampleType = wined3ddesc.multisample_type;
+        pDesc->MultiSampleQuality = wined3ddesc.multisample_quality;
+        pDesc->Width = wined3ddesc.width;
+        pDesc->Height = wined3ddesc.height;
+    }
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 21731)
@@ -434,5 +434,5 @@
 static HRESULT WINAPI reset_enum_callback(IWineD3DResource *resource, void *data) {
     BOOL *resources_ok = data;
-    WINED3DRESOURCETYPE type;
+    D3DRESOURCETYPE type;
     HRESULT ret = S_OK;
     WINED3DSURFACE_DESC surface_desc;
@@ -440,8 +440,5 @@
     D3DINDEXBUFFER_DESC index_desc;
     D3DVERTEXBUFFER_DESC vertex_desc;
-    WINED3DFORMAT dummy_format;
-    WINED3DMULTISAMPLE_TYPE dummy_multisampletype;
-    DWORD dummy_dword;
-    WINED3DPOOL pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
+    WINED3DPOOL pool;
     IDirect3DResource9 *parent;
 
@@ -450,27 +447,11 @@
     switch(type) {
         case D3DRTYPE_SURFACE:
-            surface_desc.Format = &dummy_format;
-            surface_desc.Type = &type;
-            surface_desc.Usage = &dummy_dword;
-            surface_desc.Pool = &pool;
-            surface_desc.Size = &dummy_dword;
-            surface_desc.MultiSampleType = &dummy_multisampletype;
-            surface_desc.MultiSampleQuality = &dummy_dword;
-            surface_desc.Width = &dummy_dword;
-            surface_desc.Height = &dummy_dword;
-
             IWineD3DSurface_GetDesc((IWineD3DSurface *) resource, &surface_desc);
+            pool = surface_desc.pool;
             break;
 
         case D3DRTYPE_VOLUME:
-            volume_desc.Format = &dummy_format;
-            volume_desc.Type = &type;
-            volume_desc.Usage = &dummy_dword;
-            volume_desc.Pool = &pool;
-            volume_desc.Size = &dummy_dword;
-            volume_desc.Width = &dummy_dword;
-            volume_desc.Height = &dummy_dword;
-            volume_desc.Depth = &dummy_dword;
             IWineD3DVolume_GetDesc((IWineD3DVolume *) resource, &volume_desc);
+            pool = volume_desc.Pool;
             break;
 
@@ -489,4 +470,5 @@
          */
         default:
+            pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
             break;
     }
@@ -657,5 +639,8 @@
 
 
-static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height, D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,D3DRESOURCETYPE Type, UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,HANDLE* pSharedHandle )  {
+static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
+        D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,
+        UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
+{
     HRESULT hrc;
     IDirect3DSurface9Impl *object;
@@ -688,6 +673,6 @@
     EnterCriticalSection(&d3d9_cs);
     hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
-            Lockable, Discard, Level, &object->wineD3DSurface, Type, Usage & WINED3DUSAGE_MASK,
-            (WINED3DPOOL)Pool, MultiSample, MultisampleQuality, SURFACE_OPENGL, (IUnknown *)object);
+            Lockable, Discard, Level, &object->wineD3DSurface, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL)Pool,
+            MultiSample, MultisampleQuality, SURFACE_OPENGL, (IUnknown *)object);
     LeaveCriticalSection(&d3d9_cs);
 
@@ -715,6 +700,8 @@
     TRACE("Relay\n");
 
-   hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,Lockable,FALSE/*Discard*/, 0/*Level*/, ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_RENDERTARGET,D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
-   return hr;
+    hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, Lockable, FALSE /* Discard */,
+            0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
+
+    return hr;
 }
 
@@ -726,8 +713,8 @@
     TRACE("Relay\n");
 
-     hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,TRUE/* Lockable */,Discard, 0/* Level */
-                                               ,ppSurface,D3DRTYPE_SURFACE,D3DUSAGE_DEPTHSTENCIL,
-                                                D3DPOOL_DEFAULT,MultiSample,MultisampleQuality,pSharedHandle);
-     return hr;
+    hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, Discard,
+            0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample, MultisampleQuality);
+
+    return hr;
 }
 
@@ -803,16 +790,14 @@
     TRACE("(%p) Relay\n" , This);
 
-    memset(&desc, 0, sizeof(desc));
-    desc.Usage = &usage;
-    desc.Pool = &pool;
-    desc.Type = &restype;
-
     EnterCriticalSection(&d3d9_cs);
     IWineD3DSurface_GetDesc(surface->wineD3DSurface, &desc);
+    usage = desc.usage;
+    pool = desc.pool;
+    restype = desc.resource_type;
 
     /* This method is only allowed with surfaces that are render targets, or offscreen plain surfaces
      * in D3DPOOL_DEFAULT
      */
-    if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != D3DPOOL_DEFAULT || restype != D3DRTYPE_SURFACE)) {
+    if(!(usage & WINED3DUSAGE_RENDERTARGET) && (pool != WINED3DPOOL_DEFAULT || restype != WINED3DRTYPE_SURFACE)) {
         LeaveCriticalSection(&d3d9_cs);
         WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
@@ -841,5 +826,7 @@
         should I change the usage to dynamic?        
         */
-    hr = IDirect3DDevice9Impl_CreateSurface(iface,Width,Height,Format,TRUE/*Loackable*/,FALSE/*Discard*/,0/*Level*/ , ppSurface,D3DRTYPE_SURFACE, 0/*Usage (undefined/none)*/,(WINED3DPOOL) Pool,D3DMULTISAMPLE_NONE,0/*MultisampleQuality*/,pSharedHandle);
+    hr = IDirect3DDevice9Impl_CreateSurface(iface, Width, Height, Format, TRUE /* Lockable */, FALSE /* Discard */,
+            0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */, (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE,
+            0 /* MultisampleQuality */);
 
     return hr;
@@ -2017,6 +2004,5 @@
     hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
             d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
-            (IDirect3DSurface9 **)&d3d_surface, D3DRTYPE_SURFACE, usage, pool,
-            D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */, NULL);
+            (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
     if (FAILED(hr))
     {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/directx.c	(revision 21731)
@@ -116,21 +116,23 @@
     HRESULT hr;
 
-    /* dx8 and dx9 have different structures to be filled in, with incompatible 
-       layouts so pass in pointers to the places to be filled via an internal 
-       structure                                                                */
-    adapter_id.Driver           = pIdentifier->Driver;          
-    adapter_id.Description      = pIdentifier->Description;     
-    adapter_id.DeviceName       = pIdentifier->DeviceName;      
-    adapter_id.DriverVersion    = &pIdentifier->DriverVersion;   
-    adapter_id.VendorId         = &pIdentifier->VendorId;        
-    adapter_id.DeviceId         = &pIdentifier->DeviceId;        
-    adapter_id.SubSysId         = &pIdentifier->SubSysId;        
-    adapter_id.Revision         = &pIdentifier->Revision;        
-    adapter_id.DeviceIdentifier = &pIdentifier->DeviceIdentifier;
-    adapter_id.WHQLLevel        = &pIdentifier->WHQLLevel;       
+    adapter_id.driver = pIdentifier->Driver;
+    adapter_id.driver_size = sizeof(pIdentifier->Driver);
+    adapter_id.description = pIdentifier->Description;
+    adapter_id.description_size = sizeof(pIdentifier->Description);
+    adapter_id.device_name = pIdentifier->DeviceName;
+    adapter_id.device_name_size = sizeof(pIdentifier->DeviceName);
 
     EnterCriticalSection(&d3d9_cs);
     hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
     LeaveCriticalSection(&d3d9_cs);
+
+    pIdentifier->DriverVersion = adapter_id.driver_version;
+    pIdentifier->VendorId = adapter_id.vendor_id;
+    pIdentifier->DeviceId = adapter_id.device_id;
+    pIdentifier->SubSysId = adapter_id.subsystem_id;
+    pIdentifier->Revision = adapter_id.revision;
+    memcpy(&pIdentifier->DeviceIdentifier, &adapter_id.device_identifier, sizeof(pIdentifier->DeviceIdentifier));
+    pIdentifier->WHQLLevel = adapter_id.whql_level;
+
     return hr;
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c	(revision 21731)
@@ -215,20 +215,7 @@
 static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(LPDIRECT3DSURFACE9 iface, D3DSURFACE_DESC* pDesc) {
     IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
-    WINED3DSURFACE_DESC    wined3ddesc;
-    UINT                   tmpInt = -1;
-    WINED3DFORMAT format;
-    HRESULT hr;
-    TRACE("(%p) Relay\n", This);
-
-    /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
-    wined3ddesc.Format              = &format;
-    wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
-    wined3ddesc.Usage               = &pDesc->Usage;
-    wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
-    wined3ddesc.Size                = &tmpInt;
-    wined3ddesc.MultiSampleType     = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
-    wined3ddesc.MultiSampleQuality  = &pDesc->MultiSampleQuality;
-    wined3ddesc.Width               = &pDesc->Width;
-    wined3ddesc.Height              = &pDesc->Height;
+    WINED3DSURFACE_DESC wined3ddesc;
+    HRESULT hr;
+    TRACE("(%p) Relay\n", This);
 
     EnterCriticalSection(&d3d9_cs);
@@ -236,5 +223,15 @@
     LeaveCriticalSection(&d3d9_cs);
 
-    if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(format);
+    if (SUCCEEDED(hr))
+    {
+        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
+        pDesc->Type = wined3ddesc.resource_type;
+        pDesc->Usage = wined3ddesc.usage;
+        pDesc->Pool = wined3ddesc.pool;
+        pDesc->MultiSampleType = wined3ddesc.multisample_type;
+        pDesc->MultiSampleQuality = wined3ddesc.multisample_quality;
+        pDesc->Width = wined3ddesc.width;
+        pDesc->Height = wined3ddesc.height;
+    }
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c	(revision 21731)
@@ -239,22 +239,8 @@
 static HRESULT WINAPI IDirect3DTexture9Impl_GetLevelDesc(LPDIRECT3DTEXTURE9 iface, UINT Level, D3DSURFACE_DESC* pDesc) {
     IDirect3DTexture9Impl *This = (IDirect3DTexture9Impl *)iface;
-
-    WINED3DSURFACE_DESC    wined3ddesc;
-    UINT                   tmpInt = -1;
-    HRESULT                hr;
-    WINED3DFORMAT format;
-
-    TRACE("(%p) Relay\n", This);
-
-    /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
-    wined3ddesc.Format              = &format;
-    wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
-    wined3ddesc.Usage               = &pDesc->Usage;
-    wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
-    wined3ddesc.Size                = &tmpInt; /* required for d3d8 */
-    wined3ddesc.MultiSampleType     = (WINED3DMULTISAMPLE_TYPE *) &pDesc->MultiSampleType;
-    wined3ddesc.MultiSampleQuality  = &pDesc->MultiSampleQuality;
-    wined3ddesc.Width               = &pDesc->Width;
-    wined3ddesc.Height              = &pDesc->Height;
+    WINED3DSURFACE_DESC wined3ddesc;
+    HRESULT hr;
+
+    TRACE("(%p) Relay\n", This);
 
     EnterCriticalSection(&d3d9_cs);
@@ -262,5 +248,15 @@
     LeaveCriticalSection(&d3d9_cs);
 
-    if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(format);
+    if (SUCCEEDED(hr))
+    {
+        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.format);
+        pDesc->Type = wined3ddesc.resource_type;
+        pDesc->Usage = wined3ddesc.usage;
+        pDesc->Pool = wined3ddesc.pool;
+        pDesc->MultiSampleType = wined3ddesc.multisample_type;
+        pDesc->MultiSampleQuality = wined3ddesc.multisample_quality;
+        pDesc->Width = wined3ddesc.width;
+        pDesc->Height = wined3ddesc.height;
+    }
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/version.rc
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/version.rc	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/version.rc	(revision 21731)
@@ -26,4 +26,13 @@
  */
 
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
 #define WINE_FILEDESCRIPTION_STR "Wine Direct3D"
 #define WINE_FILENAME_STR "d3d9.dll"
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volume.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volume.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volume.c	(revision 21731)
@@ -177,19 +177,7 @@
     IDirect3DVolume9Impl *This = (IDirect3DVolume9Impl *)iface;
     WINED3DVOLUME_DESC     wined3ddesc;
-    UINT                   tmpInt = -1;
-    WINED3DFORMAT format;
-    HRESULT hr;
-
-    TRACE("(%p) Relay\n", This);
-
-    /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
-    wined3ddesc.Format              = &format;
-    wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
-    wined3ddesc.Usage               = &pDesc->Usage;
-    wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
-    wined3ddesc.Size                = &tmpInt;
-    wined3ddesc.Width               = &pDesc->Width;
-    wined3ddesc.Height              = &pDesc->Height;
-    wined3ddesc.Depth               = &pDesc->Depth;
+    HRESULT hr;
+
+    TRACE("(%p) Relay\n", This);
 
     EnterCriticalSection(&d3d9_cs);
@@ -199,5 +187,14 @@
     LeaveCriticalSection(&d3d9_cs);
 
-    if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(format);
+    if (SUCCEEDED(hr))
+    {
+        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.Format);
+        pDesc->Type = wined3ddesc.Type;
+        pDesc->Usage = wined3ddesc.Usage;
+        pDesc->Pool = wined3ddesc.Pool;
+        pDesc->Width = wined3ddesc.Width;
+        pDesc->Height = wined3ddesc.Height;
+        pDesc->Depth = wined3ddesc.Depth;
+    }
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volumetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volumetexture.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/volumetexture.c	(revision 21731)
@@ -291,19 +291,7 @@
     IDirect3DVolumeTexture9Impl *This = (IDirect3DVolumeTexture9Impl *)iface;
     WINED3DVOLUME_DESC     wined3ddesc;
-    UINT                   tmpInt = -1;
-    WINED3DFORMAT format;
-    HRESULT hr;
-
-    TRACE("(%p) Relay\n", This);
-
-    /* As d3d8 and d3d9 structures differ, pass in ptrs to where data needs to go */
-    wined3ddesc.Format              = &format;
-    wined3ddesc.Type                = (WINED3DRESOURCETYPE *)&pDesc->Type;
-    wined3ddesc.Usage               = &pDesc->Usage;
-    wined3ddesc.Pool                = (WINED3DPOOL *) &pDesc->Pool;
-    wined3ddesc.Size                = &tmpInt;
-    wined3ddesc.Width               = &pDesc->Width;
-    wined3ddesc.Height              = &pDesc->Height;
-    wined3ddesc.Depth               = &pDesc->Depth;
+    HRESULT hr;
+
+    TRACE("(%p) Relay\n", This);
 
     EnterCriticalSection(&d3d9_cs);
@@ -313,5 +301,14 @@
     LeaveCriticalSection(&d3d9_cs);
 
-    if (SUCCEEDED(hr)) pDesc->Format = d3dformat_from_wined3dformat(format);
+    if (SUCCEEDED(hr))
+    {
+        pDesc->Format = d3dformat_from_wined3dformat(wined3ddesc.Format);
+        pDesc->Type = wined3ddesc.Type;
+        pDesc->Usage = wined3ddesc.Usage;
+        pDesc->Pool = wined3ddesc.Pool;
+        pDesc->Width = wined3ddesc.Width;
+        pDesc->Height = wined3ddesc.Height;
+        pDesc->Depth = wined3ddesc.Depth;
+    }
 
     return hr;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/Makefile.in
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/Makefile.in	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/Makefile.in	(revision 21731)
@@ -51,4 +51,5 @@
 	msxml.idl \
 	msxml2.idl \
+	netcon.idl \
 	netfw.idl \
 	oaidl.idl \
@@ -78,4 +79,6 @@
 	urlmon.idl \
 	vmr9.idl \
+	wbemcli.idl \
+	wincodec.idl \
 	wine/itss.idl \
 	wine/svcctl.idl \
@@ -139,9 +142,4 @@
 	d3dtypes.h \
 	d3dvec.inl \
-	d3dx8.h \
-	d3dx8core.h \
-	d3dx8math.h \
-	d3dx8math.inl \
-	d3dx8mesh.h \
 	d3dx9.h \
 	d3dx9core.h \
@@ -176,4 +174,5 @@
 	ddk/winsplp.h \
 	ddraw.h \
+	ddrawgdi.h \
 	ddrawi.h \
 	devenum.idl \
@@ -348,4 +347,5 @@
 	nspapi.h \
 	ntddcdrm.h \
+	ntddndis.h \
 	ntddscsi.h \
 	ntddstor.h \
@@ -389,4 +389,5 @@
 	rpcnterr.h \
 	rpcproxy.h \
+	rtutils.h \
 	scarderr.h \
 	schannel.h \
@@ -416,4 +417,5 @@
 	storage.h \
 	svrapi.h \
+	t2embapi.h \
 	tapi.h \
 	tchar.h \
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/activscp.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/activscp.idl	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/activscp.idl	(revision 21731)
@@ -50,6 +50,9 @@
 cpp_quote("#define SCRIPTPROP_DEBUGGER               0x00001100")
 cpp_quote("#define SCRIPTPROP_JITDEBUG               0x00001101")
-cpp_quote("#define SCRIPTPROP_HACK_FIBERSUPPORT      0x70000000")
-cpp_quote("#define SCRIPTPROP_HACK_TRIDENTEVENTSINK  0x70000001")
+cpp_quote("#define SCRIPTPROP_INVOKEVERSIONING       0x00004000")
+
+cpp_quote("#define SCRIPTPROP_HACK_FIBERSUPPORT                0x70000000")
+cpp_quote("#define SCRIPTPROP_HACK_TRIDENTEVENTSINK            0x70000001")
+cpp_quote("#define SCRIPTPROP_ABBREVIATE_GLOBALNAME_RESOLUTION 0x70000002")
  
 typedef enum tagSCRIPTSTATE {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/commctrl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/commctrl.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/commctrl.h	(revision 21731)
@@ -494,4 +494,6 @@
 #define PBM_SETBARCOLOR     (WM_USER+9)
 #define PBM_SETMARQUEE      (WM_USER+10)
+#define PBM_GETBKCOLOR      (WM_USER+14)
+#define PBM_GETBARCOLOR     (WM_USER+15)
 #define PBM_SETBKCOLOR      CCM_SETBKCOLOR
 
@@ -746,4 +748,6 @@
 #define HDS_FLAT                0x0200
 #define HDS_CHECKBOXES          0x0400
+#define HDS_NOSIZING            0x0800
+#define HDS_OVERFLOW            0x1000
 
 #define HDI_WIDTH               0x0001
@@ -757,4 +761,7 @@
 #define HDI_ORDER               0x0080
 #define HDI_FILTER              0x0100
+#define HDI_STATE               0x0200
+
+#define HDIS_FOCUSED        0x00000001
 
 #define HDF_LEFT                0x0000
@@ -773,4 +780,5 @@
 #define HDF_STRING              0x4000
 #define HDF_OWNERDRAW           0x8000
+#define HDF_SPLITBUTTON      0x1000000
 
 #define HHT_NOWHERE             0x0001
@@ -785,4 +793,6 @@
 #define HHT_TOLEFT              0x0800
 #define HHT_ONITEMSTATEICON     0x1000
+#define HHT_ONDROPDOWN          0x2000
+#define HHT_ONOVERFLOW          0x4000
 
 #define HDM_FIRST               0x1200
@@ -872,8 +882,12 @@
     INT     fmt;
     LPARAM    lParam;
+    /* (_WIN32_IE >= 0x0300) */
     INT     iImage;
     INT     iOrder;
+    /* (_WIN32_IE >= 0x0500) */
     UINT    type;
     LPVOID  pvFilter;
+    /* (_WIN32_WINNT >= 0x0600) */
+    UINT    state;
 } HDITEMA, *LPHDITEMA;
 
@@ -887,8 +901,12 @@
     INT     fmt;
     LPARAM    lParam;
+    /* (_WIN32_IE >= 0x0300) */
     INT     iImage;
     INT     iOrder;
+    /* (_WIN32_IE >= 0x0500) */
     UINT    type;
     LPVOID  pvFilter;
+    /* (_WIN32_WINNT >= 0x0600) */
+    UINT    state;
 } HDITEMW, *LPHDITEMW;
 
@@ -1980,4 +1998,7 @@
     LPARAM    lParam;
     UINT    cxHeader;
+    /* _WIN32_WINNT >= 0x0600 */
+    RECT    rcChevronLocation;
+    UINT    uChevronState;
 } REBARBANDINFOA, *LPREBARBANDINFOA;
 
@@ -2006,4 +2027,7 @@
     LPARAM    lParam;
     UINT    cxHeader;
+    /* _WIN32_WINNT >= 0x0600 */
+    RECT    rcChevronLocation;
+    UINT    uChevronState;
 } REBARBANDINFOW, *LPREBARBANDINFOW;
 
@@ -2017,4 +2041,7 @@
 #define REBARBANDINFOW_V3_SIZE CCSIZEOF_STRUCT(REBARBANDINFOW, wID)
 #define REBARBANDINFO_V3_SIZE  CCSIZEOF_STRUCT(WINELIB_NAME_AW(REBARBANDINFO), wID)
+#define REBARBANDINFOA_V6_SIZE CCSIZEOF_STRUCT(REBARBANDINFOA, cxHeader)
+#define REBARBANDINFOW_V6_SIZE CCSIZEOF_STRUCT(REBARBANDINFOW, cxHeader)
+#define REBARBANDINFO_V6_SIZE  CCSIZEOF_STRUCT(WINELIB_NAME_AW(REBARBANDINFO), cxHeader)
 
 typedef struct tagNMREBARCHILDSIZE
@@ -2516,4 +2543,7 @@
       LPARAM lParam;
       INT iIntegral;
+      UINT uStateEx;        /* _WIN32_IE >= 0x600 */
+      HWND hwnd;            /* _WIN32_IE >= 0x600 */
+      INT iExpandedImage;   /* _WIN32_IE >= 0x600 */
 } TVITEMEXA, *LPTVITEMEXA;
 
@@ -2530,4 +2560,7 @@
       LPARAM lParam;
       INT iIntegral;
+      UINT uStateEx;        /* _WIN32_IE >= 0x600 */
+      HWND hwnd;            /* _WIN32_IE >= 0x600 */
+      INT iExpandedImage;   /* _WIN32_IE >= 0x600 */
 } TVITEMEXW, *LPTVITEMEXW;
 
@@ -2605,6 +2638,18 @@
 } NMTVDISPINFOW, *LPNMTVDISPINFOW;
 
+typedef struct tagTVDISPINFOEXA {
+	NMHDR	hdr;
+	TVITEMEXA	item;
+} NMTVDISPINFOEXA, *LPNMTVDISPINFOEXA;
+
+typedef struct tagTVDISPINFOEXW {
+	NMHDR	hdr;
+	TVITEMEXW	item;
+} NMTVDISPINFOEXW, *LPNMTVDISPINFOEXW;
+
 #define NMTVDISPINFO            WINELIB_NAME_AW(NMTVDISPINFO)
 #define LPNMTVDISPINFO          WINELIB_NAME_AW(LPNMTVDISPINFO)
+#define NMTVDISPINFOEX          WINELIB_NAME_AW(NMTVDISPINFOEX)
+#define LPNMTVDISPINFOEX        WINELIB_NAME_AW(LPNMTVDISPINFOEX)
 #define TV_DISPINFOA            NMTVDISPINFOA
 #define TV_DISPINFOW            NMTVDISPINFOW
@@ -3228,4 +3273,5 @@
 #define LVM_MAPINDEXTOID        (LVM_FIRST + 180)
 #define LVM_MAPIDTOINDEX        (LVM_FIRST + 181)
+#define LVM_ISITEMVISIBLE       (LVM_FIRST + 182)
 
 #define LVN_FIRST               (0U-100U)
@@ -3293,8 +3339,13 @@
     INT  iImage;
     LPARAM lParam;
-    INT  iIndent;	/* (_WIN32_IE >= 0x0300) */
-    int iGroupId;       /* (_WIN32_IE >= 0x560) */
-    UINT cColumns;      /* (_WIN32_IE >= 0x560) */
-    PUINT puColumns;	/* (_WIN32_IE >= 0x560) */
+    /* (_WIN32_IE >= 0x0300) */
+    INT  iIndent;
+    /* (_WIN32_IE >= 0x0560) */
+    INT iGroupId;
+    UINT cColumns;
+    PUINT puColumns;
+    /* (_WIN32_WINNT >= 0x0600) */
+    PINT piColFmt;
+    INT iGroup;
 } LVITEMA, *LPLVITEMA;
 
@@ -3310,8 +3361,13 @@
     INT  iImage;
     LPARAM lParam;
-    INT  iIndent;	/* (_WIN32_IE >= 0x0300) */
-    int iGroupId;       /* (_WIN32_IE >= 0x560) */
-    UINT cColumns;      /* (_WIN32_IE >= 0x560) */
-    PUINT puColumns;	/* (_WIN32_IE >= 0x560) */
+    /* (_WIN32_IE >= 0x0300) */
+    INT  iIndent;
+    /* (_WIN32_IE >= 0x0560) */
+    INT iGroupId;
+    UINT cColumns;
+    PUINT puColumns;
+    /* (_WIN32_WINNT >= 0x0600) */
+    PINT piColFmt;
+    INT iGroup;
 } LVITEMW, *LPLVITEMW;
 
@@ -3322,4 +3378,8 @@
 #define LVITEM_V1_SIZEW CCSIZEOF_STRUCT(LVITEMW, lParam)
 #define LVITEM_V1_SIZE WINELIB_NAME_AW(LVITEM_V1_SIZE)
+
+#define LVITEMA_V5_SIZE CCSIZEOF_STRUCT(LVITEMA, puColumns)
+#define LVITEMW_V5_SIZE CCSIZEOF_STRUCT(LVITEMW, puColumns)
+#define LVITEM_V5_SIZE WINELIB_NAME_AW(LVITEM_V5_SIZE)
 
 #define LV_ITEM  LVITEM
@@ -3386,6 +3446,11 @@
     INT  cchTextMax;
     INT  iSubItem;
-    INT  iImage;  /* (_WIN32_IE >= 0x0300) */
-    INT  iOrder;  /* (_WIN32_IE >= 0x0300) */
+    /* (_WIN32_IE >= 0x0300) */
+    INT  iImage;
+    INT  iOrder;
+    /* (_WIN32_WINNT >= 0x0600) */
+    INT  cxMin;
+    INT  cxDefault;
+    INT  cxIdeal;
 } LVCOLUMNA, *LPLVCOLUMNA;
 
@@ -3398,6 +3463,11 @@
     INT  cchTextMax;
     INT  iSubItem;
-    INT  iImage;	/* (_WIN32_IE >= 0x0300) */
-    INT  iOrder;	/* (_WIN32_IE >= 0x0300) */
+    /* (_WIN32_IE >= 0x0300) */
+    INT  iImage;
+    INT  iOrder;
+    /* (_WIN32_WINNT >= 0x0600) */
+    INT  cxMin;
+    INT  cxDefault;
+    INT  cxIdeal;
 } LVCOLUMNW, *LPLVCOLUMNW;
 
@@ -3505,4 +3575,6 @@
     INT   iItem;
     INT   iSubItem;
+    /* (_WIN32_WINNT >= 0x0600) */
+    INT   iGroup;
 } LVHITTESTINFO, *LPLVHITTESTINFO;
 
@@ -3543,12 +3615,29 @@
 	UINT mask;
 	LPWSTR pszHeader;
-	int cchHeader;
+	INT cchHeader;
 	LPWSTR pszFooter;
-	int cchFooter;
-	int iGroupId;
+	INT cchFooter;
+	INT iGroupId;
 	UINT stateMask;
 	UINT state;
 	UINT uAlign;
+        /* (_WIN32_WINNT >= 0x0600) */
+	LPWSTR  pszSubtitle;
+	UINT    cchSubtitle;
+	LPWSTR  pszTask;
+	UINT    cchTask;
+	LPWSTR  pszDescriptionTop;
+	UINT    cchDescriptionTop;
+	LPWSTR  pszDescriptionBottom;
+	UINT    cchDescriptionBottom;
+	INT     iTitleImage;
+	INT     iExtendedImage;
+	INT     iFirstItem;
+	UINT    cItems;
+	LPWSTR  pszSubsetTitle;
+	UINT    cchSubsetTitle;
 } LVGROUP, *PLVGROUP;
+
+#define LVGROUP_V5_SIZE CCSIZEOF_STRUCT(LVGROUP, uAlign)
 
 typedef struct LVGROUPMETRICS
@@ -3585,4 +3674,6 @@
 	UINT cColumns;
 	PUINT puColumns;
+        /* (_WIN32_WINNT >= 0x0600) */
+	int* piColFmt;
 } LVTILEINFO, *PLVTILEINFO;
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/config.h.in
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/config.h.in	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/config.h.in	(revision 21731)
@@ -124,7 +124,4 @@
 #undef HAVE_FREETYPE_FTMODAPI_H
 
-/* Define to 1 if you have the <freetype/ftnames.h> header file. */
-#undef HAVE_FREETYPE_FTNAMES_H
-
 /* Define to 1 if you have the <freetype/ftoutln.h> header file. */
 #undef HAVE_FREETYPE_FTOUTLN_H
@@ -223,7 +220,4 @@
 #undef HAVE_GETUID
 
-/* Define to 1 if you have the <GL/glext.h> header file. */
-#undef HAVE_GL_GLEXT_H
-
 /* Define to 1 if you have the <GL/glu.h> header file. */
 #undef HAVE_GL_GLU_H
@@ -559,4 +553,7 @@
 #undef HAVE_PID_T
 
+/* Define to 1 if you have the `pipe2' function. */
+#undef HAVE_PIPE2
+
 /* Define to 1 if you have the <png.h> header file. */
 #undef HAVE_PNG_H
@@ -700,4 +697,7 @@
 #undef HAVE_STATVFS
 
+/* Define to 1 if you have the <stdbool.h> header file. */
+#undef HAVE_STDBOOL_H
+
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
@@ -832,4 +832,7 @@
 #undef HAVE_SYS_FILIO_H
 
+/* Define to 1 if you have the <sys/inotify.h> header file. */
+#undef HAVE_SYS_INOTIFY_H
+
 /* Define to 1 if you have the <sys/ioctl.h> header file. */
 #undef HAVE_SYS_IOCTL_H
@@ -1189,9 +1192,26 @@
 #undef X_DISPLAY_MISSING
 
+/* Define to a macro to output a .cfi assembly pseudo-op */
+#undef __ASM_CFI
+
+/* Define to a macro to define an assembly function */
+#undef __ASM_DEFINE_FUNC
+
 /* Define to a macro to generate an assembly function directive */
 #undef __ASM_FUNC
 
+/* Define to a macro to generate an assembly function with C calling
+   convention */
+#undef __ASM_GLOBAL_FUNC
+
 /* Define to a macro to generate an assembly name from a C symbol */
 #undef __ASM_NAME
+
+/* Define to a macro to generate an stdcall suffix */
+#undef __ASM_STDCALL
+
+/* Define to a macro to generate an assembly function with stdcall calling
+   convention */
+#undef __ASM_STDCALL_FUNC
 
 /* Define to empty if `const' does not conform to ANSI C. */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3d10effect.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3d10effect.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3d10effect.h	(revision 21731)
@@ -213,4 +213,47 @@
 #undef INTERFACE
 
+DEFINE_GUID(IID_ID3D10EffectMatrixVariable, 0x50666c24, 0xb82f, 0x4eed, 0xa1, 0x72, 0x5b, 0x6e, 0x7e, 0x85, 0x22, 0xe0);
+
+#define INTERFACE ID3D10EffectMatrixVariable
+DECLARE_INTERFACE_(ID3D10EffectMatrixVariable, ID3D10EffectVariable)
+{
+    /* ID3D10EffectVariable methods */
+    STDMETHOD_(BOOL, IsValid)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectType *, GetType)(THIS) PURE;
+    STDMETHOD(GetDesc)(THIS_ D3D10_EFFECT_VARIABLE_DESC *desc) PURE;
+    STDMETHOD_(struct ID3D10EffectVariable *, GetAnnotationByIndex)(THIS_ UINT index) PURE;
+    STDMETHOD_(struct ID3D10EffectVariable *, GetAnnotationByName)(THIS_ LPCSTR name) PURE;
+    STDMETHOD_(struct ID3D10EffectVariable *, GetMemberByIndex)(THIS_ UINT index) PURE;
+    STDMETHOD_(struct ID3D10EffectVariable *, GetMemberByName)(THIS_ LPCSTR name) PURE;
+    STDMETHOD_(struct ID3D10EffectVariable *, GetMemberBySemantic)(THIS_ LPCSTR semantic) PURE;
+    STDMETHOD_(struct ID3D10EffectVariable *, GetElement)(THIS_ UINT index) PURE;
+    STDMETHOD_(struct ID3D10EffectConstantBuffer *, GetParentConstantBuffer)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectScalarVariable *, AsScalar)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectVectorVariable *, AsVector)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectMatrixVariable *, AsMatrix)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectStringVariable *, AsString)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectShaderResourceVariable *, AsShaderResource)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectRenderTargetViewVariable *, AsRenderTargetView)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectDepthStencilViewVariable *, AsDepthStencilView)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectConstantBuffer *, AsConstantBuffer)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectShaderVariable *, AsShader)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectBlendVariable *, AsBlend)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectDepthStencilVariable *, AsDepthStencil)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectRasterizerVariable *, AsRasterizer)(THIS) PURE;
+    STDMETHOD_(struct ID3D10EffectSamplerVariable *, AsSampler)(THIS) PURE;
+    STDMETHOD(SetRawValue)(THIS_ void *data, UINT offset, UINT count) PURE;
+    STDMETHOD(GetRawValue)(THIS_ void *data, UINT offset, UINT count) PURE;
+    /* ID3D10EffectMatrixVariable methods */
+    STDMETHOD(SetMatrix)(THIS_ float *data) PURE;
+    STDMETHOD(GetMatrix)(THIS_ float *data) PURE;
+    STDMETHOD(SetMatrixArray)(THIS_ float *data, UINT offset, UINT count) PURE;
+    STDMETHOD(GetMatrixArray)(THIS_ float *data, UINT offset, UINT count) PURE;
+    STDMETHOD(SetMatrixTranspose)(THIS_ float *data) PURE;
+    STDMETHOD(GetMatrixTranspose)(THIS_ float *data) PURE;
+    STDMETHOD(SetMatrixTransposeArray)(THIS_ float *data, UINT offset, UINT count) PURE;
+    STDMETHOD(GetMatrixTransposeArray)(THIS_ float *data, UINT offset, UINT count) PURE;
+};
+#undef INTERFACE
+
 DEFINE_GUID(IID_ID3D10EffectTechnique, 0xdb122ce8, 0xd1c9, 0x4292, 0xb2, 0x37, 0x24, 0xed, 0x3d, 0xe8, 0xb1, 0x75);
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8.h	(revision 21731)
@@ -26,4 +26,40 @@
  */
 
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
 #ifndef __D3DX8_H__
 #define __D3DX8_H__
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8core.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8core.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8core.h	(revision 21731)
@@ -15,4 +15,40 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
  */
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8math.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8math.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8math.h	(revision 21731)
@@ -16,4 +16,40 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
  */
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8math.inl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8math.inl	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8math.inl	(revision 21731)
@@ -27,4 +27,40 @@
  */
 
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
 #ifndef __D3DX8MATH_INL__
 #define __D3DX8MATH_INL__
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8mesh.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8mesh.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx8mesh.h	(revision 21731)
@@ -15,4 +15,40 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
  */
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx9math.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx9math.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx9math.h	(revision 21731)
@@ -40,4 +40,6 @@
 #define D3DXToDegree(radian) ((radian) * (180.0f / D3DX_PI))
 
+
+
 typedef struct D3DXVECTOR2
 {
@@ -276,7 +278,9 @@
 D3DXCOLOR* WINAPI D3DXColorAdjustSaturation(D3DXCOLOR *pout, CONST D3DXCOLOR *pc, FLOAT s);
 
-D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *pout, float scaling, D3DXVECTOR3 *rotationcenter, D3DXQUATERNION *rotation, D3DXVECTOR3 *translation);
+FLOAT WINAPI D3DXFresnelTerm(FLOAT costheta, FLOAT refractionindex);
+
+D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation(D3DXMATRIX *pout, FLOAT scaling, CONST D3DXVECTOR3 *rotationcenter, CONST D3DXQUATERNION *rotation, CONST D3DXVECTOR3 *translation);
 D3DXMATRIX* WINAPI D3DXMatrixAffineTransformation2D(D3DXMATRIX *pout, FLOAT scaling, CONST D3DXVECTOR2 *protationcenter, FLOAT rotation, CONST D3DXVECTOR2 *ptranslation);
-HRESULT WINAPI D3DXMatrixDecompose(D3DXVECTOR3 *poutscale, D3DXQUATERNION *poutrotation, D3DXVECTOR3 *pouttranslation, D3DXMATRIX *pm);
+HRESULT WINAPI D3DXMatrixDecompose(D3DXVECTOR3 *poutscale, D3DXQUATERNION *poutrotation, D3DXVECTOR3 *pouttranslation, CONST D3DXMATRIX *pm);
 FLOAT WINAPI D3DXMatrixDeterminant(CONST D3DXMATRIX *pm);
 D3DXMATRIX* WINAPI D3DXMatrixInverse(D3DXMATRIX *pout, FLOAT *pdeterminant, CONST D3DXMATRIX *pm);
@@ -368,4 +372,69 @@
 #endif
 
+typedef interface ID3DXMatrixStack *LPD3DXMATRIXSTACK;
+
+DEFINE_GUID(IID_ID3DXMatrixStack,
+0xc7885ba7, 0xf990, 0x4fe7, 0x92, 0x2d, 0x85, 0x15, 0xe4, 0x77, 0xdd, 0x85);
+
+#undef INTERFACE
+#define INTERFACE ID3DXMatrixStack
+
+DECLARE_INTERFACE_(ID3DXMatrixStack, IUnknown)
+{
+    STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj) PURE;
+    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+    STDMETHOD_(ULONG,Release)(THIS) PURE;
+    STDMETHOD(Pop)(THIS) PURE;
+    STDMETHOD(Push)(THIS) PURE;
+    STDMETHOD(LoadIdentity)(THIS) PURE;
+    STDMETHOD(LoadMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
+    STDMETHOD(MultMatrix)(THIS_ CONST D3DXMATRIX* pM ) PURE;
+    STDMETHOD(MultMatrixLocal)(THIS_ CONST D3DXMATRIX* pM ) PURE;
+    STDMETHOD(RotateAxis)(THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
+    STDMETHOD(RotateAxisLocal)(THIS_ CONST D3DXVECTOR3* pV, FLOAT Angle) PURE;
+    STDMETHOD(RotateYawPitchRoll)(THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
+    STDMETHOD(RotateYawPitchRollLocal)(THIS_ FLOAT Yaw, FLOAT Pitch, FLOAT Roll) PURE;
+    STDMETHOD(Scale)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
+    STDMETHOD(ScaleLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
+    STDMETHOD(Translate)(THIS_ FLOAT x, FLOAT y, FLOAT z ) PURE;
+    STDMETHOD(TranslateLocal)(THIS_ FLOAT x, FLOAT y, FLOAT z) PURE;
+    STDMETHOD_(D3DXMATRIX*, GetTop)(THIS) PURE;
+};
+
+#undef INTERFACE
+
+#if !defined(__cplusplus) || defined(CINTERFACE)
+
+#define ID3DXMatrixStack_QueryInterface(p,a,b)            (p)->lpVtbl->QueryInterface(p,a,b)
+#define ID3DXMatrixStack_AddRef(p)                        (p)->lpVtbl->AddRef(p)
+#define ID3DXMatrixStack_Release(p)                       (p)->lpVtbl->Release(p)
+#define ID3DXMatrixStack_Pop(p)                           (p)->lpVtbl->Pop(p)
+#define ID3DXMatrixStack_Push(p)                          (p)->lpVtbl->Push(p)
+#define ID3DXMatrixStack_LoadIdentity(p)                  (p)->lpVtbl->LoadIdentity(p)
+#define ID3DXMatrixStack_LoadMatrix(p,a)                  (p)->lpVtbl->LoadMatrix(p,a)
+#define ID3DXMatrixStack_MultMatrix(p,a)                  (p)->lpVtbl->MultMatrix(p,a)
+#define ID3DXMatrixStack_MultMatrixLocal(p,a)             (p)->lpVtbl->MultMatrixLocal(p,a)
+#define ID3DXMatrixStack_RotateAxis(p,a,b)                (p)->lpVtbl->RotateAxis(p,a,b)
+#define ID3DXMatrixStack_RotateAxisLocal(p,a,b)           (p)->lpVtbl->RotateAxisLocal(p,a,b)
+#define ID3DXMatrixStack_RotateYawPitchRoll(p,a,b,c)      (p)->lpVtbl->RotateYawPitchRoll(p,a,b,c)
+#define ID3DXMatrixStack_RotateYawPitchRollLocal(p,a,b,c) (p)->lpVtbl->RotateYawPitchRollLocal(p,a,b,c)
+#define ID3DXMatrixStack_Scale(p,a,b,c)                   (p)->lpVtbl->Scale(p,a,b,c)
+#define ID3DXMatrixStack_ScaleLocal(p,a,b,c)              (p)->lpVtbl->ScaleLocal(p,a,b,c)
+#define ID3DXMatrixStack_Translate(p,a,b,c)               (p)->lpVtbl->Translate(p,a,b,c)
+#define ID3DXMatrixStack_TranslateLocal(p,a,b,c)          (p)->lpVtbl->TranslateLocal(p,a,b,c)
+#define ID3DXMatrixStack_GetTop(p)                        (p)->lpVtbl->GetTop(p)
+
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+HRESULT WINAPI D3DXCreateMatrixStack(DWORD flags, LPD3DXMATRIXSTACK* ppstack);
+
+#ifdef __cplusplus
+}
+#endif
+
 #include <d3dx9math.inl>
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx9mesh.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx9mesh.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/d3dx9mesh.h	(revision 21731)
@@ -36,4 +36,5 @@
 
 HRESULT WINAPI D3DXCreateBuffer(DWORD, LPD3DXBUFFER*);
+UINT    WINAPI D3DXGetDeclVertexSize(const D3DVERTEXELEMENT9 *decl, DWORD stream_idx);
 UINT    WINAPI D3DXGetFVFVertexSize(DWORD);
 BOOL    WINAPI D3DXBoxBoundProbe(CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *, CONST D3DXVECTOR3 *);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/wdm.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/wdm.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddk/wdm.h	(revision 21731)
@@ -134,11 +134,17 @@
 } KWAIT_REASON;
 
+typedef struct _ALLOCATE_FUNCTION *PALLOCATE_FUNCTION;
 typedef struct _IO_TIMER *PIO_TIMER;
+typedef struct _IO_TIMER_ROUTINE *PIO_TIMER_ROUTINE;
 typedef struct _ETHREAD *PETHREAD;
+typedef struct _FREE_FUNCTION *PFREE_FUNCTION;
 typedef struct _KTHREAD *PKTHREAD;
 typedef struct _EPROCESS *PEPROCESS;
+typedef struct _ERESOURCE *PERESOURCE;
 typedef struct _IO_WORKITEM *PIO_WORKITEM;
+typedef struct _NPAGED_LOOKASIDE_LIST *PNPAGED_LOOKASIDE_LIST;
 typedef struct _OBJECT_TYPE *POBJECT_TYPE;
 typedef struct _OBJECT_HANDLE_INFORMATION *POBJECT_HANDLE_INFORMATION;
+typedef struct _ZONE_HEADER *PZONE_HEADER;
 
 typedef struct _FAST_MUTEX
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddrawgdi.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddrawgdi.h	(revision 21731)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ddrawgdi.h	(revision 21731)
@@ -0,0 +1,45 @@
+/*
+ * Ddrawgdi definitions
+ *
+ * Copyright (C) 2009 Louis Lenders
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+#ifndef __WINE_DDRAWGDI_H
+#define __WINE_DDRAWGDI_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define DdQueryDisplaySettingsUniqueness    GdiEntry13
+
+ULONG APIENTRY DdQueryDisplaySettingsUniqueness(VOID);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __WINE_DDRAWGDI_H */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dls1.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dls1.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/dls1.h	(revision 21731)
@@ -17,5 +17,5 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
-
+ 
 /*
  * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusenums.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusenums.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusenums.h	(revision 21731)
@@ -182,16 +182,16 @@
     MatrixOrderPrepend = 0,
     MatrixOrderAppend  = 1
+};
+
+enum ImageType
+{
+    ImageTypeUnknown,
+    ImageTypeBitmap,
+    ImageTypeMetafile
+};
+
 enum WarpMode {
     WarpModePerspective,
     WarpModeBilinear
-};
-
-};
-
-enum ImageType
-{
-    ImageTypeUnknown,
-    ImageTypeBitmap,
-    ImageTypeMetafile
 };
 
@@ -442,5 +442,4 @@
 typedef enum LineJoin LineJoin;
 typedef enum QualityMode QualityMode;
-typedef enum WarpMode WarpMode;
 typedef enum SmoothingMode SmoothingMode;
 typedef enum CompositingQuality CompositingQuality;
@@ -452,4 +451,5 @@
 typedef enum ImageType ImageType;
 typedef enum ImageFlags ImageFlags;
+typedef enum WarpMode WarpMode;
 typedef enum WrapMode WrapMode;
 typedef enum MetafileType MetafileType;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusflat.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusflat.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/gdiplusflat.h	(revision 21731)
@@ -40,6 +40,4 @@
 GpStatus WINGDIPAPI GdipCreateAdjustableArrowCap(REAL,REAL,BOOL,GpAdjustableArrowCap**);
 GpStatus WINGDIPAPI GdipGetAdjustableArrowCapFillState(GpAdjustableArrowCap*,BOOL*);
-GpStatus WINGDIPAPI GdipBitmapApplyEffect(GpBitmap*,CGpEffect*,RECT*,BOOL,VOID**,INT*);
-GpStatus WINGDIPAPI GdipBitmapCreateApplyEffect(GpBitmap**,INT,CGpEffect*,RECT*,RECT*,GpBitmap**,BOOL,VOID**,INT*);
 GpStatus WINGDIPAPI GdipGetAdjustableArrowCapHeight(GpAdjustableArrowCap*,REAL*);
 GpStatus WINGDIPAPI GdipGetAdjustableArrowCapMiddleInset(GpAdjustableArrowCap*,REAL*);
@@ -47,10 +45,10 @@
 GpStatus WINGDIPAPI GdipSetAdjustableArrowCapFillState(GpAdjustableArrowCap*,BOOL);
 GpStatus WINGDIPAPI GdipSetAdjustableArrowCapHeight(GpAdjustableArrowCap*,REAL);
-GpStatus WINGDIPAPI GdipCloneBitmapArea(REAL,REAL,REAL,REAL,PixelFormat,GpBitmap*,GpBitmap**);
-GpStatus WINGDIPAPI GdipCloneBitmapAreaI(INT,INT,INT,INT,PixelFormat,GpBitmap*,GpBitmap**);
 GpStatus WINGDIPAPI GdipSetAdjustableArrowCapMiddleInset(GpAdjustableArrowCap*,REAL);
 GpStatus WINGDIPAPI GdipSetAdjustableArrowCapWidth(GpAdjustableArrowCap*,REAL);
 
 /* Bitmap */
+GpStatus WINGDIPAPI GdipBitmapApplyEffect(GpBitmap*,CGpEffect*,RECT*,BOOL,VOID**,INT*);
+GpStatus WINGDIPAPI GdipBitmapCreateApplyEffect(GpBitmap**,INT,CGpEffect*,RECT*,RECT*,GpBitmap**,BOOL,VOID**,INT*);
 GpStatus WINGDIPAPI GdipBitmapGetPixel(GpBitmap*,INT,INT,ARGB*);
 GpStatus WINGDIPAPI GdipBitmapLockBits(GpBitmap*,GDIPCONST GpRect*,UINT,
@@ -58,8 +56,8 @@
 GpStatus WINGDIPAPI GdipBitmapSetPixel(GpBitmap*,INT,INT,ARGB);
 GpStatus WINGDIPAPI GdipBitmapUnlockBits(GpBitmap*,BitmapData*);
+GpStatus WINGDIPAPI GdipCloneBitmapArea(REAL,REAL,REAL,REAL,PixelFormat,GpBitmap*,GpBitmap**);
+GpStatus WINGDIPAPI GdipCloneBitmapAreaI(INT,INT,INT,INT,PixelFormat,GpBitmap*,GpBitmap**);
 GpStatus WINGDIPAPI GdipCreateBitmapFromFile(GDIPCONST WCHAR*,GpBitmap**);
 GpStatus WINGDIPAPI GdipCreateBitmapFromFileICM(GDIPCONST WCHAR*,GpBitmap**);
-GpStatus WINGDIPAPI GdipCreateHICONFromBitmap(GpBitmap*,HICON*);
-GpStatus WINGDIPAPI GdipDeleteEffect(CGpEffect*);
 GpStatus WINGDIPAPI GdipCreateBitmapFromGdiDib(GDIPCONST BITMAPINFO*,VOID*,GpBitmap**);
 GpStatus WINGDIPAPI GdipCreateBitmapFromGraphics(INT,INT,GpGraphics*,GpBitmap**);
@@ -71,4 +69,6 @@
 GpStatus WINGDIPAPI GdipCreateBitmapFromStream(IStream*,GpBitmap**);
 GpStatus WINGDIPAPI GdipCreateBitmapFromStreamICM(IStream*,GpBitmap**);
+GpStatus WINGDIPAPI GdipCreateHICONFromBitmap(GpBitmap*,HICON*);
+GpStatus WINGDIPAPI GdipDeleteEffect(CGpEffect*);
 
 /* Brush */
@@ -125,8 +125,4 @@
 GpStatus WINGDIPAPI GdipGetCellAscent(GDIPCONST GpFontFamily*, INT, UINT16*);
 GpStatus WINGDIPAPI GdipGetCellDescent(GDIPCONST GpFontFamily*, INT, UINT16*);
-GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics*,GDIPCONST GpRectF*,GDIPCONST GpRectF*,GpUnit,GraphicsContainer*);
-GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics*,GraphicsContainer*);
-GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics*,GDIPCONST GpRect*,GDIPCONST GpRect*,GpUnit,GraphicsContainer*);
-GpStatus WINGDIPAPI GdipComment(GpGraphics*,UINT,GDIPCONST BYTE*);
 GpStatus WINGDIPAPI GdipGetEmHeight(GDIPCONST GpFontFamily*, INT, UINT16*);
 GpStatus WINGDIPAPI GdipGetGenericFontFamilySansSerif(GpFontFamily**);
@@ -138,4 +134,9 @@
 /* Graphics */
 GpStatus WINGDIPAPI GdipFlush(GpGraphics*, GpFlushIntention);
+GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics*,GDIPCONST GpRectF*,GDIPCONST GpRectF*,GpUnit,GraphicsContainer*);
+GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics*,GraphicsContainer*);
+GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics*,GDIPCONST GpRect*,GDIPCONST GpRect*,GpUnit,GraphicsContainer*);
+GpStatus WINGDIPAPI GdipEndContainer(GpGraphics*,GraphicsContainer);
+GpStatus WINGDIPAPI GdipComment(GpGraphics*,UINT,GDIPCONST BYTE*);
 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC,GpGraphics**);
 GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC,HANDLE,GpGraphics**);
@@ -152,8 +153,4 @@
 GpStatus WINGDIPAPI GdipDrawClosedCurveI(GpGraphics*,GpPen*,GDIPCONST GpPoint*,INT);
 GpStatus WINGDIPAPI GdipDrawClosedCurve2(GpGraphics*,GpPen*,GDIPCONST GpPointF*,INT,REAL);
-GpStatus WINGDIPAPI GdipDrawImagePointRect(GpGraphics*,GpImage*,REAL,REAL,REAL,REAL,REAL,REAL,GpUnit);
-GpStatus WINGDIPAPI GdipDrawImagePointRectI(GpGraphics*,GpImage*,INT,INT,INT,INT,INT,INT,GpUnit);
-GpStatus WINGDIPAPI GdipDrawImagePoints(GpGraphics*,GpImage*,GDIPCONST GpPointF*,INT);
-GpStatus WINGDIPAPI GdipDrawImagePointsI(GpGraphics*,GpImage*,GDIPCONST GpPoint*,INT);
 GpStatus WINGDIPAPI GdipDrawClosedCurve2I(GpGraphics*,GpPen*,GDIPCONST GpPoint*,INT,REAL);
 GpStatus WINGDIPAPI GdipDrawCurve(GpGraphics*,GpPen*,GDIPCONST GpPointF*,INT);
@@ -161,8 +158,14 @@
 GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics*,GpPen*,GDIPCONST GpPointF*,INT,REAL);
 GpStatus WINGDIPAPI GdipDrawCurve2I(GpGraphics*,GpPen*,GDIPCONST GpPoint*,INT,REAL);
+GpStatus WINGDIPAPI GdipDrawCurve3(GpGraphics*,GpPen*,GDIPCONST GpPointF*,INT,INT,INT,REAL);
+GpStatus WINGDIPAPI GdipDrawCurve3I(GpGraphics*,GpPen*,GDIPCONST GpPoint*,INT,INT,INT,REAL);
 GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics*,GpPen*,REAL,REAL,REAL,REAL);
 GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics*,GpPen*,INT,INT,INT,INT);
 GpStatus WINGDIPAPI GdipDrawImage(GpGraphics*,GpImage*,REAL,REAL);
 GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics*,GpImage*,INT,INT);
+GpStatus WINGDIPAPI GdipDrawImagePointRect(GpGraphics*,GpImage*,REAL,REAL,REAL,REAL,REAL,REAL,GpUnit);
+GpStatus WINGDIPAPI GdipDrawImagePointRectI(GpGraphics*,GpImage*,INT,INT,INT,INT,INT,INT,GpUnit);
+GpStatus WINGDIPAPI GdipDrawImagePoints(GpGraphics*,GpImage*,GDIPCONST GpPointF*,INT);
+GpStatus WINGDIPAPI GdipDrawImagePointsI(GpGraphics*,GpImage*,GDIPCONST GpPoint*,INT);
 GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics*,GpImage*,
     GDIPCONST GpPointF*,INT,REAL,REAL,REAL,REAL,GpUnit,
@@ -296,6 +299,4 @@
 GpStatus WINGDIPAPI GdipAddPathLine2(GpPath*,GDIPCONST GpPointF*,INT);
 GpStatus WINGDIPAPI GdipAddPathLine2I(GpPath*,GDIPCONST GpPoint*,INT);
-GpStatus WINGDIPAPI GdipAddPathString(GpPath*,GDIPCONST WCHAR*,INT,GDIPCONST GpFontFamily*,INT,REAL,GDIPCONST RectF*,GDIPCONST GpStringFormat*);
-GpStatus WINGDIPAPI GdipAddPathStringI(GpPath*,GDIPCONST WCHAR*,INT,GDIPCONST GpFontFamily*,INT,REAL,GDIPCONST Rect*,GDIPCONST GpStringFormat*);
 GpStatus WINGDIPAPI GdipAddPathPath(GpPath*,GDIPCONST GpPath*,BOOL);
 GpStatus WINGDIPAPI GdipAddPathPie(GpPath*,REAL,REAL,REAL,REAL,REAL,REAL);
@@ -307,4 +308,6 @@
 GpStatus WINGDIPAPI GdipAddPathRectangles(GpPath*,GDIPCONST GpRectF*,INT);
 GpStatus WINGDIPAPI GdipAddPathRectanglesI(GpPath*,GDIPCONST GpRect*,INT);
+GpStatus WINGDIPAPI GdipAddPathString(GpPath*,GDIPCONST WCHAR*,INT,GDIPCONST GpFontFamily*,INT,REAL,GDIPCONST RectF*,GDIPCONST GpStringFormat*);
+GpStatus WINGDIPAPI GdipAddPathStringI(GpPath*,GDIPCONST WCHAR*,INT,GDIPCONST GpFontFamily*,INT,REAL,GDIPCONST Rect*,GDIPCONST GpStringFormat*);
 GpStatus WINGDIPAPI GdipClearPathMarkers(GpPath*);
 GpStatus WINGDIPAPI GdipClonePath(GpPath*,GpPath**);
@@ -334,5 +337,4 @@
 GpStatus WINGDIPAPI GdipResetPath(GpPath*);
 GpStatus WINGDIPAPI GdipReversePath(GpPath*);
-GpStatus WINGDIPAPI GdipEmfToWmfBits(HENHMETAFILE,UINT,LPBYTE,INT,INT);
 GpStatus WINGDIPAPI GdipSetPathFillMode(GpPath*,GpFillMode);
 GpStatus WINGDIPAPI GdipSetPathMarker(GpPath*);
@@ -344,4 +346,5 @@
 GpStatus WINGDIPAPI GdipCloneImageAttributes(GDIPCONST GpImageAttributes*,GpImageAttributes**);
 GpStatus WINGDIPAPI GdipDisposeImage(GpImage*);
+GpStatus WINGDIPAPI GdipEmfToWmfBits(HENHMETAFILE,UINT,LPBYTE,INT,INT);
 GpStatus WINGDIPAPI GdipFindFirstImageItem(GpImage*,ImageItemData*);
 GpStatus WINGDIPAPI GdipFindNextImageItem(GpImage*,ImageItemData*);
@@ -416,4 +419,5 @@
 GpStatus WINGDIPAPI GdipSetLineGammaCorrection(GpLineGradient*,BOOL);
 GpStatus WINGDIPAPI GdipSetLineSigmaBlend(GpLineGradient*,REAL,REAL);
+GpStatus WINGDIPAPI GdipSetLineLinearBlend(GpLineGradient*,REAL,REAL);
 GpStatus WINGDIPAPI GdipSetLineWrapMode(GpLineGradient*,GpWrapMode);
 
@@ -442,6 +446,4 @@
 
 /* Metafile */
-GpStatus WINGDIPAPI GdipCreateMetafileFromFile(GDIPCONST WCHAR*,GpMetafile**);
-GpStatus WINGDIPAPI GdipCreateMetafileFromStream(IStream*,GpMetafile**);
 GpStatus WINGDIPAPI GdipConvertToEmfPlus(const GpGraphics*,GpMetafile*,INT*,
     EmfType,const WCHAR*,GpMetafile**);
@@ -453,4 +455,6 @@
 GpStatus WINGDIPAPI GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR*, GDIPCONST WmfPlaceableFileHeader*,
     GpMetafile**);
+GpStatus WINGDIPAPI GdipCreateMetafileFromFile(GDIPCONST WCHAR*,GpMetafile**);
+GpStatus WINGDIPAPI GdipCreateMetafileFromStream(IStream*,GpMetafile**);
 GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile*,UINT);
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msctf.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msctf.idl	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msctf.idl	(revision 21731)
@@ -26,12 +26,25 @@
  */
 
-cpp_quote("#define TF_E_DISCONNECTED    MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0504)")
 #ifndef DO_NO_IMPORTS
-cpp_quote("#define TF_E_NOLOCK          MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0201)")
-
 import "oaidl.idl";
 import "comcat.idl";
 import "textstor.idl";
 /* import "ctfutb.idl"; */
+#endif
+cpp_quote("#include <winuser.h>")
+
+cpp_quote("#define TF_E_STACKFULL MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0501)")
+cpp_quote("#define TF_E_DISCONNECTED    MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0504)")
+cpp_quote("#define TF_E_ALREADY_EXISTS  MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0506)")
+cpp_quote("#define TF_E_NOLOCK          MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0201)")
+
+cpp_quote("HRESULT WINAPI TF_CreateThreadMgr(ITfThreadMgr **pptim);")
+cpp_quote("HRESULT WINAPI TF_GetThreadMgr(ITfThreadMgr **pptim);")
+cpp_quote("HRESULT WINAPI TF_CreateInputProcessorProfiles(ITfInputProcessorProfiles **ppipr);")
+
+cpp_quote("EXTERN_C const CLSID CLSID_TF_ThreadMgr;")
+cpp_quote("EXTERN_C const CLSID CLSID_TF_InputProcessorProfiles;")
+cpp_quote("EXTERN_C const CLSID CLSID_TF_CategoryMgr;")
+
 /* GUIDs for Compartments */
 cpp_quote("EXTERN_C const GUID GUID_COMPARTMENT_KEYBOARD_DISABLED;")
@@ -44,13 +57,4 @@
 cpp_quote("EXTERN_C const GUID GUID_COMPARTMENT_EMPTYCONTEXT;")
 cpp_quote("EXTERN_C const GUID GUID_COMPARTMENT_TIPUISTATUS;")
-
-#endif
-cpp_quote("#include <winuser.h>")
-
-cpp_quote("#define TF_E_STACKFULL MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0501)")
-cpp_quote("#define TF_E_ALREADY_EXISTS  MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0506)")
-cpp_quote("EXTERN_C const CLSID CLSID_TF_ThreadMgr;")
-cpp_quote("EXTERN_C const CLSID CLSID_TF_InputProcessorProfiles;")
-cpp_quote("EXTERN_C const CLSID CLSID_TF_CategoryMgr;")
 
 /* GUIDs for Categories */
@@ -102,6 +106,4 @@
     GUID catid;
     BOOL fActive;
-typedef [uuid(5a886226-ae9a-489b-b991-2b1e25ee59a9)]  enum { TF_ANCHOR_START = 0, TF_ANCHOR_END = 1 } TfAnchor;
-
     GUID guidProfile;
 } TF_LANGUAGEPROFILE;
@@ -112,4 +114,6 @@
     UINT uModifiers;
 } TF_PRESERVEDKEY;
+
+typedef [uuid(5a886226-ae9a-489b-b991-2b1e25ee59a9)]  enum { TF_ANCHOR_START = 0, TF_ANCHOR_END = 1 } TfAnchor;
 
 [
@@ -716,4 +720,13 @@
   object,
   local,
+  uuid(d60a7b49-1b9f-4be2-b702-47e9dc05dec3),
+  pointer_default(unique)
+]
+interface ITfClientId : IUnknown
+{
+    HRESULT GetClientId(
+        [in] REFCLSID rclsid,
+        [out] TfClientId *ptid);
+};
 
 [
@@ -939,11 +952,55 @@
         [out] IEnumGUID **ppEnum);
 };
-  uuid(d60a7b49-1b9f-4be2-b702-47e9dc05dec3),
-  pointer_default(unique)
-]
-interface ITfClientId : IUnknown
-{
-    HRESULT GetClientId(
-        [in] REFCLSID rclsid,
-        [out] TfClientId *ptid);
-};
+
+[
+  object,
+  uuid(743abd5f-f26d-48df-8cc5-238492419b64),
+  pointer_default(unique)
+]
+interface ITfCompartmentEventSink : IUnknown
+{
+    HRESULT OnChange(
+        [in] REFGUID rguid);
+}
+
+[
+  object,
+  uuid(8f1a7ea6-1654-4502-a86e-b2902344d507),
+  pointer_default(unique)
+]
+interface IEnumTfContexts : IUnknown
+{
+    HRESULT Clone(
+        [out] IEnumTfContexts **ppEnum);
+
+    HRESULT Next(
+        [in] ULONG ulCount,
+        [out, size_is(ulCount), length_is(*pcFetched)] ITfContext **rgContext,
+        [out] ULONG *pcFetched);
+
+    HRESULT Reset();
+
+    HRESULT Skip(
+        [in] ULONG ulCount);
+};
+
+[
+  object,
+  uuid(aa80e808-2021-11d2-93e0-0060b067b86e),
+  pointer_default(unique)
+]
+interface IEnumTfDocumentMgrs : IUnknown
+{
+    HRESULT Clone(
+        [out] IEnumTfDocumentMgrs **ppEnum);
+
+    HRESULT Next(
+        [in] ULONG ulCount,
+        [out, size_is(ulCount), length_is(*pcFetched)] ITfDocumentMgr **rgDocumentMgr,
+        [out] ULONG *pcFetched);
+
+    HRESULT Reset();
+
+    HRESULT Skip(
+        [in] ULONG ulCount);
+};
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtmdid.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtmdid.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtmdid.h	(revision 21731)
@@ -1325,4 +1325,11 @@
 #define DISPID_IHTMLDATABINDING_DATAFORMATAS  DISPID_ELEMENT+23
 
+/* IHTMLDOMConstructor */
+#define DISPID_IHTMLDOMCONSTRUCTOR_CONSTRUCTOR   DISPID_HTMLOBJECT+9
+#define DISPID_IHTMLDOMCONSTRUCTOR_LOOKUPGETTER
+#define DISPID_IHTMLDOMCONSTRUCTOR_LOOKUPSETTER
+#define DISPID_IHTMLDOMCONSTRUCTOR_DEFINEGETTER
+#define DISPID_IHTMLDOMCONSTRUCTOR_DEFINESETTER
+
 /* IHTMLStyle */
 #define DISPID_IHTMLSTYLE_PIXELTOP                    DISPID_STYLE
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtml.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtml.idl	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/mshtml.idl	(revision 21731)
@@ -13027,4 +13027,79 @@
 }
 
+/*****************************************************************************
+ *    DispHTMLNavigator dispinterface
+ */
+[
+    hidden,
+    uuid(3050f54c-98b5-11cf-bb82-00aa00bdce0b)
+]
+dispinterface DispHTMLNavigator
+{
+properties:
+methods:
+    [propget, id(DISPID_IOMNAVIGATOR_APPCODENAME)]
+    BSTR appCodeName();
+
+    [propget, id(DISPID_IOMNAVIGATOR_APPNAME)]
+    BSTR appName();
+
+    [propget, id(DISPID_IOMNAVIGATOR_APPVERSION)]
+    BSTR appVersion();
+
+    [propget, id(DISPID_IOMNAVIGATOR_USERAGENT)]
+    BSTR userAgent();
+
+    [id(DISPID_IOMNAVIGATOR_JAVAENABLED)]
+    VARIANT_BOOL javaEnabled();
+
+    [id(DISPID_IOMNAVIGATOR_TAINTENABLED)]
+    VARIANT_BOOL taintEnabled();
+
+    [propget, id(DISPID_IOMNAVIGATOR_MIMETYPES)]
+    IHTMLMimeTypesCollection *mimeTypes();
+
+    [propget, id(DISPID_IOMNAVIGATOR_PLUGINS)]
+    IHTMLPluginsCollection *plugins();
+
+    [propget, id(DISPID_IOMNAVIGATOR_COOKIEENABLED)]
+    VARIANT_BOOL cookieEnabled();
+
+    [propget, id(DISPID_IOMNAVIGATOR_OPSPROFILE)]
+    IHTMLOpsProfile *opsProfile();
+
+    [id(DISPID_IOMNAVIGATOR_TOSTRING)]
+    BSTR toString();
+
+    [propget, id(DISPID_IOMNAVIGATOR_CPUCLASS)]
+    BSTR cpuClass();
+
+    [propget, id(DISPID_IOMNAVIGATOR_SYSTEMLANGUAGE)]
+    BSTR systemLanguage();
+
+    [propget, id(DISPID_IOMNAVIGATOR_BROWSERLANGUAGE), hidden]
+    BSTR browserLanguage();
+
+    [propget, id(DISPID_IOMNAVIGATOR_USERLANGUAGE)]
+    BSTR userLanguage();
+
+    [propget, id(DISPID_IOMNAVIGATOR_PLATFORM)]
+    BSTR platform();
+
+    [propget, id(DISPID_IOMNAVIGATOR_APPMINORVERSION)]
+    BSTR appMinorVersion();
+
+    [propget, id(DISPID_IOMNAVIGATOR_CONNECTIONSPEED), hidden]
+    LONG connectionSpeed();
+
+    [propget, id(DISPID_IOMNAVIGATOR_ONLINE)]
+    VARIANT_BOOL onLine();
+
+    [propget, id(DISPID_IOMNAVIGATOR_USERPROFILE)]
+    IHTMLOpsProfile *userProfile();
+
+    [propget, id(DISPID_IHTMLDOMCONSTRUCTOR_CONSTRUCTOR), hidden]
+    IDispatch *constructor();
+}
+
 [
     noncreatable,
@@ -13033,5 +13108,6 @@
 coclass HTMLNavigator
 {
-    [default]           interface IOmNavigator;
+    [default]  dispinterface DispHTMLNavigator;
+               interface IOmNavigator;
 }
 
@@ -13108,4 +13184,79 @@
 }
 
+/*****************************************************************************
+ *    DispHTMLLocation dispinterface
+ */
+[
+    hidden,
+    uuid(3050f54e-98b5-11cf-bb82-00aa00bdce0b)
+]
+dispinterface DispHTMLLocation
+{
+properties:
+methods:
+    [propput, id(DISPID_IHTMLLOCATION_HREF)]
+    void href(BSTR v);
+
+    [propget, id(DISPID_IHTMLLOCATION_HREF)]
+    BSTR href();
+
+    [propput, id(DISPID_IHTMLLOCATION_PROTOCOL)]
+    void protocol(BSTR v);
+
+    [propget, id(DISPID_IHTMLLOCATION_PROTOCOL)]
+    BSTR protocol();
+
+    [propput, id(DISPID_IHTMLLOCATION_HOST)]
+    void host(BSTR v);
+
+    [propget, id(DISPID_IHTMLLOCATION_HOST)]
+    BSTR host();
+
+    [propput, id(DISPID_IHTMLLOCATION_HOSTNAME)]
+    void hostname(BSTR v);
+
+    [propget, id(DISPID_IHTMLLOCATION_HOSTNAME)]
+    BSTR hostname();
+
+    [propput, id(DISPID_IHTMLLOCATION_PORT)]
+    void port(BSTR v);
+
+    [propget, id(DISPID_IHTMLLOCATION_PORT)]
+    BSTR port();
+
+    [propput, id(DISPID_IHTMLLOCATION_PATHNAME)]
+    void pathname(BSTR v);
+
+    [propget, id(DISPID_IHTMLLOCATION_PATHNAME)]
+    BSTR pathname();
+
+    [propput, id(DISPID_IHTMLLOCATION_SEARCH)]
+    void search(BSTR v);
+
+    [propget, id(DISPID_IHTMLLOCATION_SEARCH)]
+    BSTR search();
+
+    [propput, id(DISPID_IHTMLLOCATION_HASH)]
+    void hash(BSTR v);
+
+    [propget, id(DISPID_IHTMLLOCATION_HASH)]
+    BSTR hash();
+
+    [id(DISPID_IHTMLLOCATION_RELOAD)]
+    void reload([in, defaultvalue(0)] VARIANT_BOOL flag);
+
+    [id(DISPID_IHTMLLOCATION_REPLACE)]
+    void replace([in] BSTR bstr);
+
+    [id(DISPID_IHTMLLOCATION_ASSIGN)]
+    void assign([in] BSTR bstr);
+
+    [id(DISPID_IHTMLLOCATION_TOSTRING)]
+    BSTR toString();
+
+    [propget, id(DISPID_IHTMLDOMCONSTRUCTOR_CONSTRUCTOR), hidden]
+    IDispatch *constructor();
+}
+
 [
     noncreatable,
@@ -13114,5 +13265,6 @@
 coclass HTMLLocation
 {
-    [default]           interface IHTMLLocation;
+    [default]  dispinterface DispHTMLLocation;
+               interface IHTMLLocation;
 }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/conio.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/conio.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/conio.h	(revision 21731)
@@ -36,8 +36,8 @@
 #ifdef _M_IX86
 int            __cdecl _inp(unsigned short);
-unsigned long  __cdecl _inpd(unsigned short);
+__msvcrt_ulong __cdecl _inpd(unsigned short);
 unsigned short __cdecl _inpw(unsigned short);
 int            __cdecl _outp(unsigned short, int);
-unsigned long  __cdecl _outpd(unsigned short, unsigned long);
+__msvcrt_ulong __cdecl _outpd(unsigned short, __msvcrt_ulong);
 unsigned short __cdecl _outpw(unsigned short, unsigned short);
 #endif
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/crtdbg.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/crtdbg.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/crtdbg.h	(revision 21731)
@@ -18,13 +18,4 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
-/*
- * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
- * other than GPL or LGPL is available it will apply instead, Sun elects to use only
- * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
- * a choice of LGPL license versions is made available with the language indicating
- * that LGPLv2 or any later version may be used, or where a choice of which version
- * of the LGPL is applied is otherwise unspecified.
- */
-
 #ifndef __WINE_CRTDBG_H_
 #define __WINE_CRTDBG_H_
@@ -54,8 +45,8 @@
 {
     struct _CrtMemBlockHeader* pBlockHeader;
-    unsigned long lCounts[_MAX_BLOCKS];
-    unsigned long lSizes[_MAX_BLOCKS];
-    unsigned long lHighWaterCount;
-    unsigned long lTotalCount;
+    __msvcrt_ulong lCounts[_MAX_BLOCKS];
+    __msvcrt_ulong lSizes[_MAX_BLOCKS];
+    __msvcrt_ulong lHighWaterCount;
+    __msvcrt_ulong lTotalCount;
 } _CrtMemState;
 
@@ -70,5 +61,5 @@
 #define _CrtDbgReport(...)              ((int)0)
 #define _CrtDumpMemoryLeaks()           ((int)0)
-#define _CrtSetBreakAlloc(a)            ((long)0)
+#define _CrtSetBreakAlloc(a)            ((__msvcrt_long)0)
 #define _CrtSetDbgFlag(f)               ((int)0)
 #define _CrtSetDumpClient(f)            ((void)0)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/crtdefs.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/crtdefs.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/crtdefs.h	(revision 21731)
@@ -90,4 +90,11 @@
 #endif
 
+#ifndef _MSVCRT_LONG_DEFINED
+#define _MSVCRT_LONG_DEFINED
+/* we need 32-bit longs even on 64-bit */
+typedef int __msvcrt_long;
+typedef unsigned int __msvcrt_ulong;
+#endif
+
 #ifndef _INTPTR_T_DEFINED
 #ifdef  _WIN64
@@ -127,5 +134,5 @@
 
 #ifndef _TIME32_T_DEFINED
-typedef long __time32_t;
+typedef __msvcrt_long __time32_t;
 #define _TIME32_T_DEFINED
 #endif
@@ -136,9 +143,17 @@
 #endif
 
+#ifdef _USE_32BIT_TIME_T
+# ifdef _WIN64
+#  error You cannot use 32-bit time_t in Win64
+# endif
+#elif !defined(_WIN64)
+# define _USE_32BIT_TIME_T
+#endif
+
 #ifndef _TIME_T_DEFINED
-#ifdef _WIN64
+#ifdef _USE_32BIT_TIME_T
+typedef __time32_t time_t;
+#else
 typedef __time64_t time_t;
-#else
-typedef __time32_t time_t;
 #endif
 #define _TIME_T_DEFINED
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/direct.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/direct.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/direct.h	(revision 21731)
@@ -41,5 +41,5 @@
 char*         __cdecl _getdcwd(int,char*,int);
 int           __cdecl _getdrive(void);
-unsigned long __cdecl _getdrives(void);
+__msvcrt_ulong __cdecl _getdrives(void);
 int           __cdecl _mkdir(const char*);
 int           __cdecl _rmdir(const char*);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/float.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/float.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/float.h	(revision 21731)
@@ -138,5 +138,5 @@
 double __cdecl _copysign (double, double);
 double __cdecl _chgsign (double);
-double __cdecl _scalb(double, long);
+double __cdecl _scalb(double, __msvcrt_long);
 double __cdecl _logb(double);
 double __cdecl _nextafter(double, double);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/io.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/io.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/io.h	(revision 21731)
@@ -32,5 +32,5 @@
 
 #ifndef _FSIZE_T_DEFINED
-typedef unsigned long _fsize_t;
+typedef __msvcrt_ulong _fsize_t;
 #define _FSIZE_T_DEFINED
 #endif
@@ -86,5 +86,5 @@
 int         __cdecl _access(const char*,int);
 int         __cdecl _chmod(const char*,int);
-int         __cdecl _chsize(int,long);
+int         __cdecl _chsize(int,__msvcrt_ulong);
 int         __cdecl _close(int);
 int         __cdecl _commit(int);
@@ -94,5 +94,5 @@
 int         __cdecl _eof(int);
 __int64     __cdecl _filelengthi64(int);
-long        __cdecl _filelength(int);
+__msvcrt_long __cdecl _filelength(int);
 int         __cdecl _findclose(intptr_t);
 intptr_t    __cdecl _findfirst(const char*,struct _finddata_t*);
@@ -102,6 +102,6 @@
 intptr_t    __cdecl _get_osfhandle(int);
 int         __cdecl _isatty(int);
-int         __cdecl _locking(int,int,long);
-long        __cdecl _lseek(int,long,int);
+int         __cdecl _locking(int,int,__msvcrt_long);
+__msvcrt_long __cdecl _lseek(int,__msvcrt_long,int);
 __int64     __cdecl _lseeki64(int,__int64,int);
 char*       __cdecl _mktemp(char*);
@@ -112,5 +112,5 @@
 int         __cdecl _setmode(int,int);
 int         __cdecl _sopen(const char*,int,int,...);
-long        __cdecl _tell(int);
+__msvcrt_long __cdecl _tell(int);
 __int64     __cdecl _telli64(int);
 int         __cdecl _umask(int);
@@ -144,5 +144,5 @@
 static inline int access(const char* path, int mode) { return _access(path, mode); }
 static inline int chmod(const char* path, int mode) { return _chmod(path, mode); }
-static inline int chsize(int fd, long size) { return _chsize(fd, size); }
+static inline int chsize(int fd, __msvcrt_long size) { return _chsize(fd, size); }
 static inline int close(int fd) { return _close(fd); }
 static inline int creat(const char* path, int mode) { return _creat(path, mode); }
@@ -150,12 +150,12 @@
 static inline int dup2(int od, int nd) { return _dup2(od, nd); }
 static inline int eof(int fd) { return _eof(fd); }
-static inline long filelength(int fd) { return _filelength(fd); }
+static inline __msvcrt_long filelength(int fd) { return _filelength(fd); }
 static inline int isatty(int fd) { return _isatty(fd); }
-static inline int locking(int fd, int mode, long size) { return _locking(fd, mode, size); }
-static inline long lseek(int fd, long off, int where) { return _lseek(fd, off, where); }
+static inline int locking(int fd, int mode, __msvcrt_long size) { return _locking(fd, mode, size); }
+static inline __msvcrt_long lseek(int fd, __msvcrt_long off, int where) { return _lseek(fd, off, where); }
 static inline char* mktemp(char* pat) { return _mktemp(pat); }
 static inline int read(int fd, void* buf, unsigned int size) { return _read(fd, buf, size); }
 static inline int setmode(int fd, int mode) { return _setmode(fd, mode); }
-static inline long tell(int fd) { return _tell(fd); }
+static inline __msvcrt_long tell(int fd) { return _tell(fd); }
 #ifndef _UMASK_DEFINED
 static inline int umask(int fd) { return _umask(fd); }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/stddef.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/stddef.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/stddef.h	(revision 21731)
@@ -52,6 +52,6 @@
 #endif
 
-unsigned long __cdecl __threadid(void);
-unsigned long __cdecl __threadhandle(void);
+__msvcrt_ulong __cdecl __threadid(void);
+__msvcrt_ulong __cdecl __threadhandle(void);
 #define _threadid    (__threadid())
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/stdio.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/stdio.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/stdio.h	(revision 21731)
@@ -144,7 +144,7 @@
 FILE*  __cdecl freopen(const char*,const char*,FILE*);
 int    __cdecl fscanf(FILE*,const char*,...);
-int    __cdecl fseek(FILE*,long,int);
+int    __cdecl fseek(FILE*,__msvcrt_long,int);
 int    __cdecl fsetpos(FILE*,fpos_t*);
-long   __cdecl ftell(FILE*);
+__msvcrt_long __cdecl ftell(FILE*);
 size_t __cdecl fwrite(const void*,size_t,size_t,FILE*);
 int    __cdecl getc(FILE*);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/stdlib.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/stdlib.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/stdlib.h	(revision 21731)
@@ -65,6 +65,6 @@
 
 typedef struct _ldiv_t {
-    long quot;
-    long rem;
+    __msvcrt_long quot;
+    __msvcrt_long rem;
 } ldiv_t;
 
@@ -127,5 +127,5 @@
 extern int*           __cdecl ___mb_cur_max_func(void);
 #define __mb_cur_max        (*___mb_cur_max_func())
-extern unsigned long* __cdecl __doserrno(void);
+extern __msvcrt_ulong* __cdecl __doserrno(void);
 #define _doserrno           (*__doserrno())
 extern int*           __cdecl _errno(void);
@@ -153,7 +153,7 @@
 char*         __cdecl _i64toa(__int64,char*,int);
 char*         __cdecl _itoa(int,char*,int);
-char*         __cdecl _ltoa(long,char*,int);
-unsigned long __cdecl _lrotl(unsigned long,int);
-unsigned long __cdecl _lrotr(unsigned long,int);
+char*         __cdecl _ltoa(__msvcrt_long,char*,int);
+__msvcrt_ulong __cdecl _lrotl(__msvcrt_ulong,int);
+__msvcrt_ulong __cdecl _lrotr(__msvcrt_ulong,int);
 void          __cdecl _makepath(char*,const char*,const char*,const char*,const char*);
 size_t        __cdecl _mbstrlen(const char*);
@@ -165,10 +165,10 @@
 int           __cdecl _set_error_mode(int);
 void          __cdecl _seterrormode(int);
-void          __cdecl _sleep(unsigned long);
+void          __cdecl _sleep(__msvcrt_ulong);
 void          __cdecl _splitpath(const char*,char*,char*,char*,char*);
 long double   __cdecl _strtold(const char*,char**);
 void          __cdecl _swab(char*,char*,int);
 char*         __cdecl _ui64toa(unsigned __int64,char*,int);
-char*         __cdecl _ultoa(unsigned long,char*,int);
+char*         __cdecl _ultoa(__msvcrt_ulong,char*,int);
 
 void          __cdecl _exit(int);
@@ -178,14 +178,14 @@
 double        __cdecl atof(const char*);
 int           __cdecl atoi(const char*);
-long          __cdecl atol(const char*);
+__msvcrt_long __cdecl atol(const char*);
 void*         __cdecl calloc(size_t,size_t);
 #ifndef __i386__
 div_t  __cdecl div(int,int);
-ldiv_t __cdecl ldiv(long,long);
+ldiv_t __cdecl ldiv(__msvcrt_long,__msvcrt_long);
 #endif
 void          __cdecl exit(int);
 void          __cdecl free(void*);
 char*         __cdecl getenv(const char*);
-long          __cdecl labs(long);
+__msvcrt_long __cdecl labs(__msvcrt_long);
 void*         __cdecl malloc(size_t);
 int           __cdecl mblen(const char*,size_t);
@@ -195,6 +195,6 @@
 void          __cdecl srand(unsigned int);
 double        __cdecl strtod(const char*,char**);
-long          __cdecl strtol(const char*,char**,int);
-unsigned long __cdecl strtoul(const char*,char**,int);
+__msvcrt_long __cdecl strtol(const char*,char**,int);
+__msvcrt_ulong __cdecl strtoul(const char*,char**,int);
 int           __cdecl system(const char*);
 void*         __cdecl bsearch(const void*,const void*,size_t,size_t,int (*)(const void*,const void*));
@@ -205,7 +205,7 @@
 wchar_t*      __cdecl _itow(int,wchar_t*,int);
 wchar_t*      __cdecl _i64tow(__int64,wchar_t*,int);
-wchar_t*      __cdecl _ltow(long,wchar_t*,int);
+wchar_t*      __cdecl _ltow(__msvcrt_long,wchar_t*,int);
 wchar_t*      __cdecl _ui64tow(unsigned __int64,wchar_t*,int);
-wchar_t*      __cdecl _ultow(unsigned long,wchar_t*,int);
+wchar_t*      __cdecl _ultow(__msvcrt_ulong,wchar_t*,int);
 wchar_t*      __cdecl _wfullpath(wchar_t*,const wchar_t*,size_t);
 wchar_t*      __cdecl _wgetenv(const wchar_t*);
@@ -218,12 +218,12 @@
 int           __cdecl _wtoi(const wchar_t*);
 __int64       __cdecl _wtoi64(const wchar_t*);
-long          __cdecl _wtol(const wchar_t*);
+__msvcrt_long __cdecl _wtol(const wchar_t*);
 
 size_t        __cdecl mbstowcs(wchar_t*,const char*,size_t);
 int           __cdecl mbtowc(wchar_t*,const char*,size_t);
 double        __cdecl wcstod(const wchar_t*,wchar_t**);
-long          __cdecl wcstol(const wchar_t*,wchar_t**,int);
+__msvcrt_long __cdecl wcstol(const wchar_t*,wchar_t**,int);
 size_t        __cdecl wcstombs(char*,const wchar_t*,size_t);
-unsigned long __cdecl wcstoul(const wchar_t*,wchar_t**,int);
+__msvcrt_ulong __cdecl wcstoul(const wchar_t*,wchar_t**,int);
 int           __cdecl wctomb(char*,wchar_t);
 #endif /* _WSTDLIB_DEFINED */
@@ -241,9 +241,9 @@
 static inline char* gcvt(double value, int ndigit, char* buf) { return _gcvt(value, ndigit, buf); }
 static inline char* itoa(int value, char* str, int radix) { return _itoa(value, str, radix); }
-static inline char* ltoa(long value, char* str, int radix) { return _ltoa(value, str, radix); }
+static inline char* ltoa(__msvcrt_long value, char* str, int radix) { return _ltoa(value, str, radix); }
 static inline _onexit_t onexit(_onexit_t func) { return _onexit(func); }
 static inline int putenv(const char* str) { return _putenv(str); }
 static inline void swab(char* src, char* dst, int len) { _swab(src, dst, len); }
-static inline char* ultoa(unsigned long value, char* str, int radix) { return _ultoa(value, str, radix); }
+static inline char* ultoa(__msvcrt_ulong value, char* str, int radix) { return _ultoa(value, str, radix); }
 
 #ifdef __i386__
@@ -257,11 +257,11 @@
     return ret;
 }
-static inline ldiv_t __wine_msvcrt_ldiv(long num, long denom)
-{
-    extern unsigned __int64 ldiv(long,long);
+static inline ldiv_t __wine_msvcrt_ldiv(__msvcrt_long num, __msvcrt_long denom)
+{
+    extern unsigned __int64 ldiv(__msvcrt_long,__msvcrt_long);
     ldiv_t ret;
     unsigned __int64 res = ldiv(num,denom);
-    ret.quot = (long)res;
-    ret.rem  = (long)(res >> 32);
+    ret.quot = (__msvcrt_long)res;
+    ret.rem  = (__msvcrt_long)(res >> 32);
     return ret;
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/sys/timeb.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/sys/timeb.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/sys/timeb.h	(revision 21731)
@@ -44,4 +44,18 @@
     short          dstflag;
 };
+struct __timeb32
+{
+    __time32_t     time;
+    unsigned short millitm;
+    short          timezone;
+    short          dstflag;
+};
+struct __timeb64
+{
+    __time64_t     time;
+    unsigned short millitm;
+    short          timezone;
+    short          dstflag;
+};
 #endif /* _TIMEB_DEFINED */
 
@@ -51,5 +65,6 @@
 #endif
 
-void __cdecl _ftime(struct _timeb*);
+void __cdecl _ftime32(struct __timeb32*);
+void __cdecl _ftime64(struct __timeb64*);
 
 #ifdef __cplusplus
@@ -57,4 +72,9 @@
 #endif
 
+#ifdef _USE_32BIT_TIME_T
+static inline void __cdecl _ftime(struct _timeb *tb) { return _ftime32((struct __timeb32*)tb); }
+#else
+static inline void __cdecl _ftime(struct _timeb *tb) { return _ftime64((struct __timeb64*)tb); }
+#endif
 
 #define timeb _timeb
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/sys/types.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/sys/types.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/sys/types.h	(revision 21731)
@@ -57,5 +57,5 @@
 typedef unsigned short u_short;
 typedef unsigned int  u_int;
-typedef unsigned long u_long;
+typedef __msvcrt_ulong u_long;
 #define _BSDTYPES_DEFINED
 #endif
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/sys/utime.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/sys/utime.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/sys/utime.h	(revision 21731)
@@ -42,4 +42,14 @@
     time_t modtime;
 };
+struct __utimbuf32
+{
+    __time32_t actime;
+    __time32_t modtime;
+};
+struct __utimbuf64
+{
+    __time64_t actime;
+    __time64_t modtime;
+};
 #endif /* _UTIMBUF_DEFINED */
 
@@ -48,7 +58,20 @@
 #endif
 
-int __cdecl _futime(int,struct _utimbuf*);
-int __cdecl _utime(const char*,struct _utimbuf*);
-int __cdecl _wutime(const wchar_t*,struct _utimbuf*);
+int __cdecl _futime32(int,struct __utimbuf32*);
+int __cdecl _futime64(int,struct __utimbuf64*);
+int __cdecl _utime32(const char*,struct __utimbuf32*);
+int __cdecl _utime64(const char*,struct __utimbuf64*);
+int __cdecl _wutime32(const wchar_t*,struct __utimbuf32*);
+int __cdecl _wutime64(const wchar_t*,struct __utimbuf64*);
+
+#ifdef _USE_32BIT_TIME_T
+static inline int _futime(int fd, struct _utimbuf *buf) { return _futime32(fd, (struct __utimbuf32*)buf); }
+static inline int _utime(const char *s, struct _utimbuf *buf) { return _utime32(s, (struct __utimbuf32*)buf); }
+static inline int _wutime(const wchar_t *s, struct _utimbuf *buf) { return _wutime32(s, (struct __utimbuf32*)buf); }
+#else
+static inline int _futime(int fd, struct _utimbuf *buf) { return _futime64(fd, (struct __utimbuf64*)buf); }
+static inline int _utime(const char *s, struct _utimbuf *buf) { return _utime64(s, (struct __utimbuf64*)buf); }
+static inline int _wutime(const wchar_t *s, struct _utimbuf *buf) { return _wutime64(s, (struct __utimbuf64*)buf); }
+#endif
 
 #ifdef __cplusplus
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/time.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/time.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/time.h	(revision 21731)
@@ -36,5 +36,5 @@
 
 #ifndef _CLOCK_T_DEFINED
-typedef long clock_t;
+typedef __msvcrt_long clock_t;
 #define _CLOCK_T_DEFINED
 #endif
@@ -78,12 +78,21 @@
 
 int *   __cdecl __p__daylight(void);
-long *  __cdecl __p__dstbias(void);
-long *  __cdecl __p__timezone(void);
+__msvcrt_long *  __cdecl __p__dstbias(void);
+__msvcrt_long *  __cdecl __p__timezone(void);
 char ** __cdecl __p__tzname(void);
 #else
 extern int _daylight;
-extern long _dstbias;
-extern long _timezone;
+extern __msvcrt_long _dstbias;
+extern __msvcrt_long _timezone;
 extern char *_tzname;
+#endif
+
+#ifdef _USE_32BIT_TIME_T
+#define _ctime32     ctime
+#define _difftime32  difftime
+#define _gmtime32    gmtime
+#define _localtime32 localtime
+#define _mktime32    mktime
+#define _time32      time
 #endif
 
@@ -96,19 +105,45 @@
 char*       __cdecl asctime(const struct tm*);
 clock_t     __cdecl clock(void);
-char*       __cdecl ctime(const time_t*);
-double      __cdecl difftime(time_t,time_t);
-struct tm*  __cdecl gmtime(const time_t*);
-struct tm*  __cdecl localtime(const time_t*);
-time_t      __cdecl mktime(struct tm*);
+char*       __cdecl _ctime32(const __time32_t*);
+char*       __cdecl _ctime64(const __time64_t*);
+double      __cdecl _difftime32(__time32_t,__time32_t);
+double      __cdecl _difftime64(__time64_t,__time64_t);
+struct tm*  __cdecl _gmtime32(const __time32_t*);
+struct tm*  __cdecl _gmtime64(const __time64_t*);
+struct tm*  __cdecl _localtime32(const __time32_t*);
+struct tm*  __cdecl _localtime64(const __time64_t*);
+__time32_t  __cdecl _mktime32(struct tm*);
+__time64_t  __cdecl _mktime64(struct tm*);
 size_t      __cdecl strftime(char*,size_t,const char*,const struct tm*);
-time_t      __cdecl time(time_t*);
+__time32_t  __cdecl _time32(__time32_t*);
+__time64_t  __cdecl _time64(__time64_t*);
+
+#ifndef _USE_32BIT_TIME_T
+static inline char* ctime(const time_t *t) { return _ctime64(t); }
+static inline double difftime(time_t t1, time_t t2) { return _difftime64(t1, t2); }
+static inline struct tm* gmtime(const time_t *t) { return _gmtime64(t); }
+static inline struct tm* localtime(const time_t *t) { return _localtime64(t); }
+static inline time_t mktime(struct tm *tm) { return _mktime64(tm); }
+static inline time_t time(time_t *t) { return _time64(t); }
+#endif
 
 #ifndef _WTIME_DEFINED
 #define _WTIME_DEFINED
+
+#ifdef _USE_32BIT_TIME_T
+#define _wctime32 _wctime
+#endif
+
 wchar_t* __cdecl _wasctime(const struct tm*);
 size_t   __cdecl wcsftime(wchar_t*,size_t,const wchar_t*,const struct tm*);
-wchar_t* __cdecl _wctime(const time_t*);
+wchar_t* __cdecl _wctime32(const __time32_t*);
+wchar_t* __cdecl _wctime64(const __time64_t*);
 wchar_t* __cdecl _wstrdate(wchar_t*);
 wchar_t* __cdecl _wstrtime(wchar_t*);
+
+#ifndef _USE_32BIT_TIME_T
+static inline wchar_t* _wctime(const time_t *t) { return _wctime64(t); }
+#endif
+
 #endif /* _WTIME_DEFINED */
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/wchar.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/wchar.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msvcrt/wchar.h	(revision 21731)
@@ -56,5 +56,5 @@
 
 #ifndef _FSIZE_T_DEFINED
-typedef unsigned long _fsize_t;
+typedef __msvcrt_ulong _fsize_t;
 #define _FSIZE_T_DEFINED
 #endif
@@ -235,8 +235,8 @@
 int      __cdecl _wchmod(const wchar_t*,int);
 int      __cdecl _wcreat(const wchar_t*,int);
-long     __cdecl _wfindfirst(const wchar_t*,struct _wfinddata_t*);
-long     __cdecl _wfindfirsti64(const wchar_t*, struct _wfinddatai64_t*);
-int      __cdecl _wfindnext(long,struct _wfinddata_t*);
-int      __cdecl _wfindnexti64(long, struct _wfinddatai64_t*);
+__msvcrt_long __cdecl _wfindfirst(const wchar_t*,struct _wfinddata_t*);
+__msvcrt_long __cdecl _wfindfirsti64(const wchar_t*, struct _wfinddatai64_t*);
+int      __cdecl _wfindnext(__msvcrt_long,struct _wfinddata_t*);
+int      __cdecl _wfindnexti64(__msvcrt_long, struct _wfinddatai64_t*);
 wchar_t* __cdecl _wmktemp(wchar_t*);
 int      __cdecl _wopen(const wchar_t*,int,...);
@@ -325,7 +325,7 @@
 wchar_t* __cdecl _itow(int,wchar_t*,int);
 wchar_t* __cdecl _i64tow(__int64,wchar_t*,int);
-wchar_t* __cdecl _ltow(long,wchar_t*,int);
+wchar_t* __cdecl _ltow(__msvcrt_long,wchar_t*,int);
 wchar_t* __cdecl _ui64tow(unsigned __int64,wchar_t*,int);
-wchar_t* __cdecl _ultow(unsigned long,wchar_t*,int);
+wchar_t* __cdecl _ultow(__msvcrt_ulong,wchar_t*,int);
 wchar_t* __cdecl _wfullpath(wchar_t*,const wchar_t*,size_t);
 wchar_t* __cdecl _wgetenv(const wchar_t*);
@@ -338,12 +338,12 @@
 int      __cdecl _wtoi(const wchar_t*);
 __int64  __cdecl _wtoi64(const wchar_t*);
-long     __cdecl _wtol(const wchar_t*);
+__msvcrt_long __cdecl _wtol(const wchar_t*);
 
 size_t        __cdecl mbstowcs(wchar_t*,const char*,size_t);
 int           __cdecl mbtowc(wchar_t*,const char*,size_t);
 double        __cdecl wcstod(const wchar_t*,wchar_t**);
-long          __cdecl wcstol(const wchar_t*,wchar_t**,int);
+__msvcrt_long __cdecl wcstol(const wchar_t*,wchar_t**,int);
 size_t        __cdecl wcstombs(char*,const wchar_t*,size_t);
-unsigned long __cdecl wcstoul(const wchar_t*,wchar_t**,int);
+__msvcrt_ulong __cdecl wcstoul(const wchar_t*,wchar_t**,int);
 int           __cdecl wctomb(char*,wchar_t);
 #endif /* _WSTDLIB_DEFINED */
@@ -381,9 +381,20 @@
 #ifndef _WTIME_DEFINED
 #define _WTIME_DEFINED
+
+#ifdef _USE_32BIT_TIME_T
+#define _wctime32 _wctime
+#endif
+
 wchar_t* __cdecl _wasctime(const struct tm*);
 size_t   __cdecl wcsftime(wchar_t*,size_t,const wchar_t*,const struct tm*);
-wchar_t* __cdecl _wctime(const time_t*);
+wchar_t* __cdecl _wctime32(const __time32_t*);
+wchar_t* __cdecl _wctime64(const __time64_t*);
 wchar_t* __cdecl _wstrdate(wchar_t*);
 wchar_t* __cdecl _wstrtime(wchar_t*);
+
+#ifndef _USE_32BIT_TIME_T
+static inline wchar_t* _wctime(const time_t *t) { return _wctime64(t); }
+#endif
+
 #endif /* _WTIME_DEFINED */
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msxml.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msxml.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/msxml.h	(revision 21731)
@@ -1,3 +1,4 @@
-/*** Autogenerated by WIDL 1.1.23 from ../../../dlls/wined3d/../../include/msxml.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.26 from ../../include/msxml.idl - Do not edit ***/
+
 #include <rpc.h>
 #include <rpcndr.h>
@@ -5,7 +6,10 @@
 #ifndef __WIDL_MSXML_H
 #define __WIDL_MSXML_H
+
 #ifdef __cplusplus
 extern "C" {
 #endif
+
+/* Headers for imported files */
 
 #include <unknwn.h>
@@ -13,8 +17,52 @@
 #include <objidl.h>
 #include <oaidl.h>
+
+/* Forward declarations */
+
 #ifndef __IXMLElementCollection_FWD_DEFINED__
 #define __IXMLElementCollection_FWD_DEFINED__
 typedef interface IXMLElementCollection IXMLElementCollection;
 #endif
+
+#ifndef __IXMLElement_FWD_DEFINED__
+#define __IXMLElement_FWD_DEFINED__
+typedef interface IXMLElement IXMLElement;
+#endif
+
+#ifndef __IXMLDocument_FWD_DEFINED__
+#define __IXMLDocument_FWD_DEFINED__
+typedef interface IXMLDocument IXMLDocument;
+#endif
+
+#ifndef __IXMLElement2_FWD_DEFINED__
+#define __IXMLElement2_FWD_DEFINED__
+typedef interface IXMLElement2 IXMLElement2;
+#endif
+
+#ifndef __IXMLDocument2_FWD_DEFINED__
+#define __IXMLDocument2_FWD_DEFINED__
+typedef interface IXMLDocument2 IXMLDocument2;
+#endif
+
+#ifndef __IXMLAttribute_FWD_DEFINED__
+#define __IXMLAttribute_FWD_DEFINED__
+typedef interface IXMLAttribute IXMLAttribute;
+#endif
+
+#ifndef __IXMLError_FWD_DEFINED__
+#define __IXMLError_FWD_DEFINED__
+typedef interface IXMLError IXMLError;
+#endif
+
+#ifndef __IXMLElementNotificationSink_FWD_DEFINED__
+#define __IXMLElementNotificationSink_FWD_DEFINED__
+typedef interface IXMLElementNotificationSink IXMLElementNotificationSink;
+#endif
+
+#ifndef __XMLDocument_FWD_DEFINED__
+#define __XMLDocument_FWD_DEFINED__
+typedef struct XMLDocument XMLDocument;
+#endif /* defined __XMLDocument_FWD_DEFINED__ */
+
 
 /*****************************************************************************
@@ -29,8 +77,8 @@
 {
     virtual HRESULT STDMETHODCALLTYPE put_length(
-        long v) = 0;
+        LONG v) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE get_length(
-        long *p) = 0;
+        LONG *p) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE get__newEnum(
@@ -92,9 +140,9 @@
     HRESULT (STDMETHODCALLTYPE *put_length)(
         IXMLElementCollection* This,
-        long v);
+        LONG v);
 
     HRESULT (STDMETHODCALLTYPE *get_length)(
         IXMLElementCollection* This,
-        long *p);
+        LONG *p);
 
     HRESULT (STDMETHODCALLTYPE *get__newEnum)(
@@ -135,5 +183,5 @@
 HRESULT STDMETHODCALLTYPE IXMLElementCollection_put_length_Proxy(
     IXMLElementCollection* This,
-    long v);
+    LONG v);
 void __RPC_STUB IXMLElementCollection_put_length_Stub(
     IRpcStubBuffer* This,
@@ -143,5 +191,5 @@
 HRESULT STDMETHODCALLTYPE IXMLElementCollection_get_length_Proxy(
     IXMLElementCollection* This,
-    long *p);
+    LONG *p);
 void __RPC_STUB IXMLElementCollection_get_length_Stub(
     IRpcStubBuffer* This,
@@ -170,9 +218,4 @@
 #endif  /* __IXMLElementCollection_INTERFACE_DEFINED__ */
 
-#ifndef __IXMLElement_FWD_DEFINED__
-#define __IXMLElement_FWD_DEFINED__
-typedef interface IXMLElement IXMLElement;
-#endif
-
 /*****************************************************************************
  * IXMLElement interface
@@ -209,5 +252,5 @@
 
     virtual HRESULT STDMETHODCALLTYPE get_type(
-        long *p) = 0;
+        LONG *p) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE get_text(
@@ -219,6 +262,6 @@
     virtual HRESULT STDMETHODCALLTYPE addChild(
         IXMLElement *pChildElem,
-        long lIndex,
-        long lreserved) = 0;
+        LONG lIndex,
+        LONG lreserved) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE removeChild(
@@ -305,5 +348,5 @@
     HRESULT (STDMETHODCALLTYPE *get_type)(
         IXMLElement* This,
-        long *p);
+        LONG *p);
 
     HRESULT (STDMETHODCALLTYPE *get_text)(
@@ -318,6 +361,6 @@
         IXMLElement* This,
         IXMLElement *pChildElem,
-        long lIndex,
-        long lreserved);
+        LONG lIndex,
+        LONG lreserved);
 
     HRESULT (STDMETHODCALLTYPE *removeChild)(
@@ -418,5 +461,5 @@
 HRESULT STDMETHODCALLTYPE IXMLElement_get_type_Proxy(
     IXMLElement* This,
-    long *p);
+    LONG *p);
 void __RPC_STUB IXMLElement_get_type_Stub(
     IRpcStubBuffer* This,
@@ -443,6 +486,6 @@
     IXMLElement* This,
     IXMLElement *pChildElem,
-    long lIndex,
-    long lreserved);
+    LONG lIndex,
+    LONG lreserved);
 void __RPC_STUB IXMLElement_addChild_Stub(
     IRpcStubBuffer* This,
@@ -460,9 +503,4 @@
 
 #endif  /* __IXMLElement_INTERFACE_DEFINED__ */
-
-#ifndef __IXMLDocument_FWD_DEFINED__
-#define __IXMLDocument_FWD_DEFINED__
-typedef interface IXMLDocument IXMLDocument;
-#endif
 
 /*****************************************************************************
@@ -498,5 +536,5 @@
 
     virtual HRESULT STDMETHODCALLTYPE get_readyState(
-        long *p) = 0;
+        LONG *p) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE get_charset(
@@ -598,5 +636,5 @@
     HRESULT (STDMETHODCALLTYPE *get_readyState)(
         IXMLDocument* This,
-        long *p);
+        LONG *p);
 
     HRESULT (STDMETHODCALLTYPE *get_charset)(
@@ -719,5 +757,5 @@
 HRESULT STDMETHODCALLTYPE IXMLDocument_get_readyState_Proxy(
     IXMLDocument* This,
-    long *p);
+    LONG *p);
 void __RPC_STUB IXMLDocument_get_readyState_Stub(
     IRpcStubBuffer* This,
@@ -778,9 +816,4 @@
 #endif  /* __IXMLDocument_INTERFACE_DEFINED__ */
 
-#ifndef __IXMLElement2_FWD_DEFINED__
-#define __IXMLElement2_FWD_DEFINED__
-typedef interface IXMLElement2 IXMLElement2;
-#endif
-
 /*****************************************************************************
  * IXMLElement2 interface
@@ -817,5 +850,5 @@
 
     virtual HRESULT STDMETHODCALLTYPE get_type(
-        long *plType) = 0;
+        LONG *plType) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE get_text(
@@ -827,6 +860,6 @@
     virtual HRESULT STDMETHODCALLTYPE addChild(
         IXMLElement2 *pChildElem,
-        long lIndex,
-        long lReserved) = 0;
+        LONG lIndex,
+        LONG lReserved) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE removeChild(
@@ -916,5 +949,5 @@
     HRESULT (STDMETHODCALLTYPE *get_type)(
         IXMLElement2* This,
-        long *plType);
+        LONG *plType);
 
     HRESULT (STDMETHODCALLTYPE *get_text)(
@@ -929,6 +962,6 @@
         IXMLElement2* This,
         IXMLElement2 *pChildElem,
-        long lIndex,
-        long lReserved);
+        LONG lIndex,
+        LONG lReserved);
 
     HRESULT (STDMETHODCALLTYPE *removeChild)(
@@ -1034,5 +1067,5 @@
 HRESULT STDMETHODCALLTYPE IXMLElement2_get_type_Proxy(
     IXMLElement2* This,
-    long *plType);
+    LONG *plType);
 void __RPC_STUB IXMLElement2_get_type_Stub(
     IRpcStubBuffer* This,
@@ -1059,6 +1092,6 @@
     IXMLElement2* This,
     IXMLElement2 *pChildElem,
-    long lIndex,
-    long lReserved);
+    LONG lIndex,
+    LONG lReserved);
 void __RPC_STUB IXMLElement2_addChild_Stub(
     IRpcStubBuffer* This,
@@ -1084,9 +1117,4 @@
 
 #endif  /* __IXMLElement2_INTERFACE_DEFINED__ */
-
-#ifndef __IXMLDocument2_FWD_DEFINED__
-#define __IXMLDocument2_FWD_DEFINED__
-typedef interface IXMLDocument2 IXMLDocument2;
-#endif
 
 /*****************************************************************************
@@ -1122,5 +1150,5 @@
 
     virtual HRESULT STDMETHODCALLTYPE get_readyState(
-        long *pl) = 0;
+        LONG *pl) = 0;
 
     virtual HRESULT STDMETHODCALLTYPE get_charset(
@@ -1228,5 +1256,5 @@
     HRESULT (STDMETHODCALLTYPE *get_readyState)(
         IXMLDocument2* This,
-        long *pl);
+        LONG *pl);
 
     HRESULT (STDMETHODCALLTYPE *get_charset)(
@@ -1359,5 +1387,5 @@
 HRESULT STDMETHODCALLTYPE IXMLDocument2_get_readyState_Proxy(
     IXMLDocument2* This,
-    long *pl);
+    LONG *pl);
 void __RPC_STUB IXMLDocument2_get_readyState_Stub(
     IRpcStubBuffer* This,
@@ -1453,9 +1481,4 @@
     DWORD _reserved2;
 } XML_ERROR;
-#ifndef __IXMLAttribute_FWD_DEFINED__
-#define __IXMLAttribute_FWD_DEFINED__
-typedef interface IXMLAttribute IXMLAttribute;
-#endif
-
 /*****************************************************************************
  * IXMLAttribute interface
@@ -1572,9 +1595,4 @@
 #endif  /* __IXMLAttribute_INTERFACE_DEFINED__ */
 
-#ifndef __IXMLError_FWD_DEFINED__
-#define __IXMLError_FWD_DEFINED__
-typedef interface IXMLError IXMLError;
-#endif
-
 /*****************************************************************************
  * IXMLError interface
@@ -1639,9 +1657,4 @@
 
 #endif  /* __IXMLError_INTERFACE_DEFINED__ */
-
-#ifndef __IXMLElementNotificationSink_FWD_DEFINED__
-#define __IXMLElementNotificationSink_FWD_DEFINED__
-typedef interface IXMLElementNotificationSink IXMLElementNotificationSink;
-#endif
 
 /*****************************************************************************
@@ -1749,19 +1762,6 @@
 DEFINE_GUID(CLSID_XMLDocument, 0xcfc399af, 0xd876, 0x11d0, 0x9c,0x10, 0x00,0xc0,0x4f,0xc9,0x9c,0x8e);
 
-#ifndef __XMLDocument_FWD_DEFINED__
-#define __XMLDocument_FWD_DEFINED__
-typedef struct XMLDocument XMLDocument;
-#endif /* defined __XMLDocument_FWD_DEFINED__ */
-
 /* Begin additional prototypes for all interfaces */
 
-ULONG           __RPC_USER VARIANT_UserSize     (ULONG *, ULONG, VARIANT *);
-unsigned char * __RPC_USER VARIANT_UserMarshal  (ULONG *, unsigned char *, VARIANT *);
-unsigned char * __RPC_USER VARIANT_UserUnmarshal(ULONG *, unsigned char *, VARIANT *);
-void            __RPC_USER VARIANT_UserFree     (ULONG *, VARIANT *);
-ULONG           __RPC_USER BSTR_UserSize     (ULONG *, ULONG, BSTR *);
-unsigned char * __RPC_USER BSTR_UserMarshal  (ULONG *, unsigned char *, BSTR *);
-unsigned char * __RPC_USER BSTR_UserUnmarshal(ULONG *, unsigned char *, BSTR *);
-void            __RPC_USER BSTR_UserFree     (ULONG *, BSTR *);
 
 /* End additional prototypes */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/netcon.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/netcon.idl	(revision 21731)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/netcon.idl	(revision 21731)
@@ -0,0 +1,421 @@
+/*
+ * Copyright 2009 Jacek Caban for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+#ifndef DO_NO_IMPORTS
+import "oaidl.idl";
+import "unknwn.idl";
+import "wtypes.idl";
+/* import "prsht.idl"; */
+#endif
+
+cpp_quote("DEFINE_GUID(CLSID_NetSharingManager,0x5c63c1ad,0x3956,0x4ff8,0x84,0x86,0x40,0x03,0x47,0x58,0x31,0x5b);")
+
+[
+    object,
+    uuid(c08956a1-1cd3-11d1-b1c5-00805fc1270e),
+    pointer_default(unique)
+]
+interface INetConnection : IUnknown
+{
+    typedef enum tagNETCON_CHARACTERISTIC_FLAGS
+    {
+        NCCF_NONE               = 0x0000,
+        NCCF_ALL_USERS          = 0x0001,
+        NCCF_ALLOW_DUPLICATION  = 0x0002,
+        NCCF_ALLOW_REMOVAL      = 0x0004,
+        NCCF_ALLOW_RENAME       = 0x0008,
+        NCCF_INCOMING_ONLY      = 0x0020,
+        NCCF_OUTGOING_ONLY      = 0x0040,
+        NCCF_BRANDED            = 0x0080,
+        NCCF_SHARED             = 0x0100,
+        NCCF_BRIDGED            = 0x0200,
+        NCCF_FIREWALLED         = 0x0400,
+        NCCF_DEFAULT            = 0x0800,
+        NCCF_HOMENET_CAPABLE    = 0x1000,
+        NCCF_SHARED_PRIVATE     = 0x2000,
+        NCCF_QUARANTINED        = 0x4000,
+        NCCF_RESERVED           = 0x8000,
+        NCCF_BLUETOOTH_MASK  = 0x000F0000,
+        NCCF_LAN_MASK        = 0x00F00000
+    } NETCON_CHARACTERISTIC_FLAGS;
+
+    typedef enum tagNETCON_STATUS
+    {
+        NCS_DISCONNECTED,
+        NCS_CONNECTING,
+        NCS_CONNECTED,
+        NCS_DISCONNECTING,
+        NCS_HARDWARE_NOT_PRESENT,
+        NCS_HARDWARE_DISABLED,
+        NCS_HARDWARE_MALFUNCTION,
+        NCS_MEDIA_DISCONNECTED,
+        NCS_AUTHENTICATING,
+        NCS_AUTHENTICATION_SUCCEEDED,
+        NCS_AUTHENTICATION_FAILED,
+        NCS_INVALID_ADDRESS,
+        NCS_CREDENTIALS_REQUIRED
+    } NETCON_STATUS;
+
+    typedef enum tagNETCON_TYPE
+    {
+        NCT_DIRECT_CONNECT,
+        NCT_INBOUND,
+        NCT_INTERNET,
+        NCT_LAN,
+        NCT_PHONE,
+        NCT_TUNNEL,
+        NCT_BRIDGE
+    } NETCON_TYPE;
+
+    typedef enum tagNETCON_MEDIATYPE
+    {
+        NCM_NONE,
+        NCM_DIRECT,
+        NCM_ISDN,
+        NCM_LAN,
+        NCM_PHONE,
+        NCM_TUNNEL,
+        NCM_PPPOE,
+        NCM_BRIDGE,
+        NCM_SHAREDACCESSHOST_LAN,
+        NCM_SHAREDACCESSHOST_RAS
+    } NETCON_MEDIATYPE;
+
+    typedef struct tagNETCON_PROPERTIES
+    {
+        GUID              guidId;
+        [string] LPWSTR   pszwName;
+        [string] LPWSTR   pszwDeviceName;
+        NETCON_STATUS     Status;
+        NETCON_MEDIATYPE  MediaType;
+        DWORD             dwCharacter;
+        CLSID             clsidThisObject;
+        CLSID             clsidUiObject;
+    } NETCON_PROPERTIES;
+
+    HRESULT Connect();
+
+    HRESULT Disconnect();
+
+    HRESULT Delete();
+
+    HRESULT Duplicate(
+            [in, string] LPCWSTR pszwDuplicateName,
+            [out]        INetConnection **ppCon);
+
+    HRESULT GetProperties([out] NETCON_PROPERTIES **ppProps);
+
+    HRESULT GetUiObjectClassId([out, ref] CLSID *pclsid);
+
+    HRESULT Rename([in, string] LPCWSTR pszwNewName);
+}
+
+[
+    object,
+    uuid(24b7e9b5-e38f-4685-851b-00892cf5f940),
+    oleautomation,
+    dual,
+    pointer_default(unique)
+]
+interface INetSharingPortMappingProps : IDispatch
+{
+    [propget, id(1)]
+    HRESULT Name([out, retval] BSTR *pbstrName);
+
+    [propget, id(2)]
+    HRESULT IPProtocol([out, retval] UCHAR *pucIPProt);
+
+    [propget, id(3)]
+    HRESULT ExternalPort([out, retval] long *pusPort);
+
+    [propget, id(4)]
+    HRESULT InternalPort([out, retval] long *pusPort);
+
+    [propget, id(5)]
+    HRESULT Options([out, retval] long *pdwOptions);
+
+    [propget, id(6)]
+    HRESULT TargetName([out, retval] BSTR *pbstrTargetName);
+
+    [propget, id(7)]
+    HRESULT TargetIPAddress([out, retval] BSTR *pbstrTargetIPAddress);
+
+    [propget, id(8)]
+    HRESULT Enabled([out, retval] VARIANT_BOOL *pbool);
+}
+
+[
+    object,
+    uuid(c08956b1-1cd3-11d1-b1c5-00805fc1270e),
+    oleautomation,
+    dual,
+    pointer_default(unique)
+]
+interface INetSharingPortMapping : IDispatch
+{
+    [id(1)]
+    HRESULT Disable();
+
+    [id(2)]
+    HRESULT Enable();
+
+    [propget, id(3)]
+    HRESULT Properties([out, retval] INetSharingPortMappingProps **ppNSPMP);
+
+    [id(4)]
+    HRESULT Delete();
+};
+[
+    object,
+    uuid(02e4a2de-da20-4e34-89c8-ac22275a010b),
+    oleautomation,
+    dual,
+    pointer_default(unique)
+]
+interface INetSharingPortMappingCollection : IDispatch
+{
+    [propget, id(DISPID_NEWENUM), restricted]
+    HRESULT _NewEnum([out, retval] IUnknown **pVal);
+
+    [propget, id(1)]
+    HRESULT Count([out, retval] long *pVal);
+}
+
+[
+    object,
+    uuid(c08956b6-1cd3-11d1-b1c5-00805fc1270e),
+    oleautomation,
+    dual,
+    pointer_default(unique)
+]
+interface INetSharingConfiguration : IDispatch
+{
+    typedef enum tagSHARINGCONNECTIONTYPE {
+        ICSSHARINGTYPE_PUBLIC,
+        ICSSHARINGTYPE_PRIVATE
+    } SHARINGCONNECTIONTYPE, *LPSHARINGCONNECTIONTYPE;
+
+    typedef enum tagSHARINGCONNECTION_ENUM_FLAGS {
+            ICSSC_DEFAULT,
+            ICSSC_ENABLED
+    } SHARINGCONNECTION_ENUM_FLAGS;
+
+    typedef enum tagICS_TARGETTYPE {
+            ICSTT_NAME,
+            ICSTT_IPADDRESS
+    }ICS_TARGETTYPE;
+
+    [propget, id(1)]
+    HRESULT SharingEnabled([out, retval] VARIANT_BOOL *pbEnabled);
+
+    [propget, id(2)]
+    HRESULT SharingConnectionType([out, retval] SHARINGCONNECTIONTYPE *pType);
+
+    [id(3)]
+    HRESULT DisableSharing();
+
+    [id(4)]
+    HRESULT EnableSharing([in] SHARINGCONNECTIONTYPE Type);
+
+    [propget, id(5)]
+    HRESULT InternetFirewallEnabled([out, retval] VARIANT_BOOL *pbEnabled);
+
+    [id(6)]
+    HRESULT DisableInternetFirewall();
+
+    [id(7)]
+    HRESULT EnableInternetFirewall();
+
+    [propget, id(8)]
+    HRESULT EnumPortMappings(
+        [in] SHARINGCONNECTION_ENUM_FLAGS Flags,
+        [out, retval] INetSharingPortMappingCollection **ppColl);
+
+    [id(9)]
+    HRESULT AddPortMapping(
+            [in] BSTR bstrName,
+            [in] UCHAR ucIPProtocol,
+            [in] USHORT usExternalPort,
+            [in] USHORT usInternalPort,
+            [in] DWORD dwOptions,
+            [in] BSTR bstrTargetNameOrIPAddress,
+            [in] ICS_TARGETTYPE eTargetType,
+            [out, retval] INetSharingPortMapping **ppMapping );
+
+    [id(10)]
+    HRESULT RemovePortMapping([in] INetSharingPortMapping *pMapping);
+}
+
+[
+    object,
+    uuid(c08956b4-1cd3-11d1-b1c5-00805fc1270e),
+    pointer_default(unique)
+]
+interface IEnumNetSharingPublicConnection : IUnknown
+{
+    HRESULT Next(
+            [in] ULONG celt,
+            [out, size_is(celt), length_is(*pceltFetched)] VARIANT *rgVar,
+            [out] ULONG *pceltFetched);
+
+    HRESULT Skip([in] ULONG celt);
+
+    HRESULT Reset();
+
+    HRESULT Clone([out] IEnumNetSharingPublicConnection **ppenum);
+}
+
+[
+    object,
+    uuid(c08956b5-1cd3-11d1-b1c5-00805fc1270e),
+    pointer_default(unique)
+]
+interface IEnumNetSharingPrivateConnection : IUnknown
+{
+    HRESULT Next(
+            [in] ULONG celt,
+            [out, size_is(celt), length_is(*pCeltFetched)] VARIANT *rgVar,
+            [out] ULONG *pCeltFetched);
+
+    HRESULT Skip([in] ULONG celt);
+
+    HRESULT Reset();
+
+    HRESULT Clone([out] IEnumNetSharingPrivateConnection **ppenum);
+}
+
+[
+    object,
+    uuid(f4277c95-ce5b-463d-8167-5662d9bcaa72),
+    oleautomation,
+    dual,
+    pointer_default(unique)
+]
+interface INetConnectionProps : IDispatch
+{
+    [propget, id(1)]
+    HRESULT Guid([out, retval] BSTR *pbstrGuid);
+
+    [propget, id(2)]
+    HRESULT Name([out, retval] BSTR *pbstrName);
+
+    [propget, id(3)]
+    HRESULT DeviceName([out, retval] BSTR *pbstrDeviceName);
+
+    [propget, id(4)]
+    HRESULT Status([out, retval] NETCON_STATUS *pStatus);
+
+    [propget, id(5)]
+    HRESULT MediaType([out, retval] NETCON_MEDIATYPE *pMediaType);
+
+    [propget, id(6)]
+    HRESULT Characteristics([out, retval] DWORD *pdwFlags);
+}
+
+[
+    object,
+    uuid(7d7a6355-f372-4971-a149-bfc927be762a),
+    oleautomation,
+    dual,
+    pointer_default(unique)
+]
+interface INetSharingPublicConnectionCollection : IDispatch
+{
+    [propget, id(DISPID_NEWENUM), restricted]
+    HRESULT _NewEnum([out, retval] IUnknown **pVal);
+
+    [propget, id(1)]
+    HRESULT Count([out, retval] long *pVal);
+}
+
+[
+    object,
+    uuid(33c4643c-7811-46fa-a89a-768597bd7223),
+    oleautomation,
+    dual,
+    pointer_default(unique)
+ ]
+interface INetSharingEveryConnectionCollection : IDispatch
+{
+    [propget, id(DISPID_NEWENUM), restricted]
+    HRESULT _NewEnum([out, retval] IUnknown **pVal);
+
+    [propget, id(1)]
+    HRESULT Count([out, retval] long *pVal);
+}
+
+[
+    object,
+    uuid(38ae69e0-4409-402a-a2cb-e965c727f840),
+    oleautomation,
+    dual,
+    pointer_default(unique)
+ ]
+interface INetSharingPrivateConnectionCollection : IDispatch
+{
+    [propget, id(DISPID_NEWENUM), restricted]
+    HRESULT _NewEnum([out, retval] IUnknown **pVal);
+
+    [propget, id(1)]
+    HRESULT Count([out, retval] long *pVal);
+}
+
+[
+    object,
+    uuid(c08956b7-1cd3-11d1-b1c5-00805fc1270e),
+    oleautomation,
+    dual,
+    pointer_default(unique)
+]
+interface INetSharingManager : IDispatch
+{
+    [propget, id(1)]
+    HRESULT SharingInstalled([out, retval] VARIANT_BOOL *pbInstalled);
+
+    [propget, id(2)]
+    HRESULT EnumPublicConnections(
+            [in]  SHARINGCONNECTION_ENUM_FLAGS Flags,
+            [out, retval] INetSharingPublicConnectionCollection **ppColl);
+
+    [propget, id(3)]
+    HRESULT EnumPrivateConnections(
+            [in]  SHARINGCONNECTION_ENUM_FLAGS Flags,
+            [out, retval] INetSharingPrivateConnectionCollection **ppColl);
+
+    [propget, id(6)]
+    HRESULT INetSharingConfigurationForINetConnection(
+            [in] INetConnection *pNetConnection,
+            [out, retval] INetSharingConfiguration **ppNetSharingConfiguration);
+
+    [propget, id(7)]
+    HRESULT EnumEveryConnection([out, retval] INetSharingEveryConnectionCollection **ppColl);
+
+    [propget, id(8)]
+    HRESULT NetConnectionProps(
+            [in] INetConnection *pNetConnection,
+            [out, retval] INetConnectionProps **ppProps);
+}
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ntddndis.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ntddndis.h	(revision 21731)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/ntddndis.h	(revision 21731)
@@ -0,0 +1,177 @@
+/*
+ * Copyright 2009 Jacek Caban for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+#ifndef _NTDDNDIS_
+#define _NTDDNDIS_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* #include <ifdef.h>*/
+/* #include <devpkey.h> */
+/* #include <pciprop.h> */
+
+#define _NDIS_CONTROL_CODE(request, method) \
+    CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, request, method, FILE_ANY_ACCESS)
+
+#define IOCTL_NDIS_QUERY_GLOBAL_STATS    _NDIS_CONTROL_CODE(0, METHOD_OUT_DIRECT)
+#define IOCTL_NDIS_QUERY_ALL_STATS       _NDIS_CONTROL_CODE(1, METHOD_OUT_DIRECT)
+#define IOCTL_NDIS_DO_PNP_OPERATION      _NDIS_CONTROL_CODE(2, METHOD_BUFFERED)
+#define IOCTL_NDIS_QUERY_SELECTED_STATS  _NDIS_CONTROL_CODE(3, METHOD_OUT_DIRECT)
+#define IOCTL_NDIS_ENUMERATE_INTERFACES  _NDIS_CONTROL_CODE(4, METHOD_BUFFERED)
+#define IOCTL_NDIS_ADD_TDI_DEVICE        _NDIS_CONTROL_CODE(5, METHOD_BUFFERED)
+#define IOCTL_NDIS_GET_LOG_DATA          _NDIS_CONTROL_CODE(7, METHOD_OUT_DIRECT)
+#define IOCTL_NDIS_GET_VERSION           _NDIS_CONTROL_CODE(8, METHOD_BUFFERED)
+
+#define IOCTL_NDIS_RESERVED1   _NDIS_CONTROL_CODE(0x09, METHOD_BUFFERED)
+#define IOCTL_NDIS_RESERVED2   _NDIS_CONTROL_CODE(0x0a, METHOD_BUFFERED)
+#define IOCTL_NDIS_RESERVED3   _NDIS_CONTROL_CODE(0x0b, METHOD_BUFFERED)
+#define IOCTL_NDIS_RESERVED4   _NDIS_CONTROL_CODE(0x0c, METHOD_BUFFERED)
+#define IOCTL_NDIS_RESERVED5   CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, 0x0d, METHOD_BUFFERED, FILE_ANY_ACCESS)
+#define IOCTL_NDIS_RESERVED6   CTL_CODE(FILE_DEVICE_PHYSICAL_NETCARD, 0x0e, METHOD_BUFFERED, FILE_WRITE_ACCESS)
+#define IOCTL_NDIS_RESERVED7   _NDIS_CONTROL_CODE(0x0f, METHOD_OUT_DIRECT)
+#define IOCTL_NDIS_RESERVED8   _NDIS_CONTROL_CODE(0x10, METHOD_BUFFERED)
+#define IOCTL_NDIS_RESERVED9   _NDIS_CONTROL_CODE(0x11, METHOD_BUFFERED)
+#define IOCTL_NDIS_RESERVED10  _NDIS_CONTROL_CODE(0x12, METHOD_BUFFERED)
+#define IOCTL_NDIS_RESERVED11  _NDIS_CONTROL_CODE(0x13, METHOD_BUFFERED)
+#define IOCTL_NDIS_RESERVED12  _NDIS_CONTROL_CODE(0x14, METHOD_BUFFERED)
+#define IOCTL_NDIS_RESERVED13  _NDIS_CONTROL_CODE(0x15, METHOD_BUFFERED)
+
+
+#define OID_802_11_BSSID                    0x0d010101
+#define OID_802_11_SSID                     0x0d010102
+#define OID_802_11_NETWORK_TYPES_SUPPORTED  0x0d010203
+#define OID_802_11_NETWORK_TYPE_IN_USE      0x0d010204
+#define OID_802_11_TX_POWER_LEVEL           0x0d010205
+#define OID_802_11_RSSI                     0x0d010206
+#define OID_802_11_RSSI_TRIGGER             0x0d010207
+#define OID_802_11_INFRASTRUCTURE_MODE      0x0d010108
+#define OID_802_11_FRAGMENTATION_THRESHOLD  0x0d010209
+#define OID_802_11_RTS_THRESHOLD            0x0d01020a
+#define OID_802_11_NUMBER_OF_ANTENNAS       0x0d01020b
+#define OID_802_11_RX_ANTENNA_SELECTED      0x0d01020c
+#define OID_802_11_TX_ANTENNA_SELECTED      0x0d01020d
+#define OID_802_11_SUPPORTED_RATES          0x0d01020e
+#define OID_802_11_DESIRED_RATES            0x0d010210
+#define OID_802_11_CONFIGURATION            0x0d010211
+#define OID_802_11_STATISTICS               0x0d020212
+#define OID_802_11_ADD_WEP                  0x0d010113
+#define OID_802_11_REMOVE_WEP               0x0d010114
+#define OID_802_11_DISASSOCIATE             0x0d010115
+#define OID_802_11_POWER_MODE               0x0d010216
+#define OID_802_11_BSSID_LIST               0x0d010217
+#define OID_802_11_AUTHENTICATION_MODE      0x0d010118
+#define OID_802_11_PRIVACY_FILTER           0x0d010119
+#define OID_802_11_BSSID_LIST_SCAN          0x0d01011a
+#define OID_802_11_WEP_STATUS               0x0d01011b
+#define OID_802_11_ENCRYPTION_STATUS        OID_802_11_WEP_STATUS
+#define OID_802_11_RELOAD_DEFAULTS          0x0d01011c
+#define OID_802_11_ADD_KEY                  0x0d01011d
+#define OID_802_11_REMOVE_KEY               0x0d01011e
+#define OID_802_11_ASSOCIATION_INFORMATION  0x0d01011f
+#define OID_802_11_TEST                     0x0d010120
+#define OID_802_11_MEDIA_STREAM_MODE        0x0d010121
+#define OID_802_11_CAPABILITY               0x0d010122
+#define OID_802_11_PMKID                    0x0d010123
+#define OID_802_11_NON_BCAST_SSID_LIST      0x0d010124
+#define OID_802_11_RADIO_STATUS             0x0d010125
+
+#define NDIS_802_11_LENGTH_SSID      32
+#define NDIS_802_11_LENGTH_RATES     8
+#define NDIS_802_11_LENGTH_RATES_EX  16
+
+typedef LONG NDIS_802_11_RSSI;
+
+typedef struct _NDIS_802_11_CONFIGURATION_FH {
+    ULONG Length;
+    ULONG HopPattern;
+    ULONG HopSet;
+    ULONG DwellTime;
+} NDIS_802_11_CONFIGURATION_FH, *PNDIS_802_11_CONFIGURATION_FH;
+
+typedef struct _NDIS_802_11_CONFIGURATION {
+    ULONG Length;
+    ULONG BeaconPeriod;
+    ULONG ATIMWindow;
+    ULONG DSConfig;
+    NDIS_802_11_CONFIGURATION_FH FHConfig;
+} NDIS_802_11_CONFIGURATION, *PNDIS_802_11_CONFIGURATION;
+
+typedef UCHAR NDIS_802_11_MAC_ADDRESS[6];
+
+typedef enum _NDIS_802_11_NETWORK_INFRASTRUCTURE {
+    Ndis802_11IBSS,
+    Ndis802_11Infrastructure,
+    Ndis802_11AutoUnknown,
+    Ndis802_11InfrastructureMax
+} NDIS_802_11_NETWORK_INFRASTRUCTURE, *PNDIS_802_11_NETWORK_INFRASTRUCTURE;
+
+typedef enum _NDIS_802_11_NETWORK_TYPE {
+    Ndis802_11FH,
+    Ndis802_11DS,
+    Ndis802_11OFDM5,
+    Ndis802_11OFDM24,
+    Ndis802_11Automode,
+    Ndis802_11NetworkTypeMax
+} NDIS_802_11_NETWORK_TYPE, *PNDIS_802_11_NETWORK_TYPE;
+
+typedef UCHAR NDIS_802_11_RATES[NDIS_802_11_LENGTH_RATES];
+typedef UCHAR NDIS_802_11_RATES_EX[NDIS_802_11_LENGTH_RATES_EX];
+
+typedef struct _NDIS_802_11_SSID {
+    ULONG SsidLength;
+    UCHAR Ssid[NDIS_802_11_LENGTH_SSID];
+} NDIS_802_11_SSID, *PNDIS_802_11_SSID;
+
+typedef struct _NDIS_WLAN_BSSID {
+    ULONG                               Length;
+    NDIS_802_11_MAC_ADDRESS             MacAddress;
+    UCHAR                               Reserved[2];
+    NDIS_802_11_SSID                    Ssid;
+    ULONG                               Privacy;
+    NDIS_802_11_RSSI                    Rssi;
+    NDIS_802_11_NETWORK_TYPE            NetworkTypeInUse;
+    NDIS_802_11_CONFIGURATION           Configuration;
+    NDIS_802_11_NETWORK_INFRASTRUCTURE  InfrastructureMode;
+    NDIS_802_11_RATES                   SupportedRates;
+} NDIS_WLAN_BSSID, *PNDIS_WLAN_BSSID;
+
+typedef struct _NDIS_802_11_BSSID_LIST {
+    ULONG NumberOfItems;
+    NDIS_WLAN_BSSID Bssid[1];
+} NDIS_802_11_BSSID_LIST, *PNDIS_802_11_BSSID_LIST;
+
+#ifndef _NDIS_
+typedef int NDIS_STATUS, *PNDIS_STATUS;
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _NTDDNDIS_ */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oaidl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oaidl.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oaidl.h	(revision 21731)
@@ -1,3 +1,4 @@
-/*** Autogenerated by WIDL 1.1.23 from ../../../dlls/wined3d/../../include/oaidl.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.26 from ../../include/oaidl.idl - Do not edit ***/
+
 #include <rpc.h>
 #include <rpcndr.h>
@@ -5,9 +6,15 @@
 #ifndef __WIDL_OAIDL_H
 #define __WIDL_OAIDL_H
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+/* Headers for imported files */
+
 #include <objidl.h>
+
+/* Forward declarations */
+
 #ifndef __IDispatch_FWD_DEFINED__
 #define __IDispatch_FWD_DEFINED__
@@ -15,4 +22,14 @@
 #endif
 
+#ifndef __IEnumVARIANT_FWD_DEFINED__
+#define __IEnumVARIANT_FWD_DEFINED__
+typedef interface IEnumVARIANT IEnumVARIANT;
+#endif
+
+#ifndef __ITypeComp_FWD_DEFINED__
+#define __ITypeComp_FWD_DEFINED__
+typedef interface ITypeComp ITypeComp;
+#endif
+
 #ifndef __ITypeInfo_FWD_DEFINED__
 #define __ITypeInfo_FWD_DEFINED__
@@ -20,4 +37,9 @@
 #endif
 
+#ifndef __ITypeInfo2_FWD_DEFINED__
+#define __ITypeInfo2_FWD_DEFINED__
+typedef interface ITypeInfo2 ITypeInfo2;
+#endif
+
 #ifndef __ITypeLib_FWD_DEFINED__
 #define __ITypeLib_FWD_DEFINED__
@@ -25,4 +47,39 @@
 #endif
 
+#ifndef __ITypeLib2_FWD_DEFINED__
+#define __ITypeLib2_FWD_DEFINED__
+typedef interface ITypeLib2 ITypeLib2;
+#endif
+
+#ifndef __ITypeChangeEvents_FWD_DEFINED__
+#define __ITypeChangeEvents_FWD_DEFINED__
+typedef interface ITypeChangeEvents ITypeChangeEvents;
+#endif
+
+#ifndef __IErrorInfo_FWD_DEFINED__
+#define __IErrorInfo_FWD_DEFINED__
+typedef interface IErrorInfo IErrorInfo;
+#endif
+
+#ifndef __ICreateErrorInfo_FWD_DEFINED__
+#define __ICreateErrorInfo_FWD_DEFINED__
+typedef interface ICreateErrorInfo ICreateErrorInfo;
+#endif
+
+#ifndef __ISupportErrorInfo_FWD_DEFINED__
+#define __ISupportErrorInfo_FWD_DEFINED__
+typedef interface ISupportErrorInfo ISupportErrorInfo;
+#endif
+
+#ifndef __ITypeFactory_FWD_DEFINED__
+#define __ITypeFactory_FWD_DEFINED__
+typedef interface ITypeFactory ITypeFactory;
+#endif
+
+#ifndef __ITypeMarshal_FWD_DEFINED__
+#define __ITypeMarshal_FWD_DEFINED__
+typedef interface ITypeMarshal ITypeMarshal;
+#endif
+
 #ifndef __IRecordInfo_FWD_DEFINED__
 #define __IRecordInfo_FWD_DEFINED__
@@ -30,4 +87,66 @@
 #endif
 
+#ifndef __ICreateTypeInfo_FWD_DEFINED__
+#define __ICreateTypeInfo_FWD_DEFINED__
+typedef interface ICreateTypeInfo ICreateTypeInfo;
+#endif
+
+#ifndef __ICreateTypeInfo2_FWD_DEFINED__
+#define __ICreateTypeInfo2_FWD_DEFINED__
+typedef interface ICreateTypeInfo2 ICreateTypeInfo2;
+#endif
+
+#ifndef __ICreateTypeLib_FWD_DEFINED__
+#define __ICreateTypeLib_FWD_DEFINED__
+typedef interface ICreateTypeLib ICreateTypeLib;
+#endif
+
+#ifndef __ICreateTypeLib2_FWD_DEFINED__
+#define __ICreateTypeLib2_FWD_DEFINED__
+typedef interface ICreateTypeLib2 ICreateTypeLib2;
+#endif
+
+#ifndef __IErrorLog_FWD_DEFINED__
+#define __IErrorLog_FWD_DEFINED__
+typedef interface IErrorLog IErrorLog;
+#endif
+
+#ifndef __IPropertyBag_FWD_DEFINED__
+#define __IPropertyBag_FWD_DEFINED__
+typedef interface IPropertyBag IPropertyBag;
+#endif
+
+
+#ifndef __IDispatch_FWD_DEFINED__
+#define __IDispatch_FWD_DEFINED__
+typedef interface IDispatch IDispatch;
+#endif
+
+#ifndef __ITypeInfo_FWD_DEFINED__
+#define __ITypeInfo_FWD_DEFINED__
+typedef interface ITypeInfo ITypeInfo;
+#endif
+
+#ifndef __ITypeLib_FWD_DEFINED__
+#define __ITypeLib_FWD_DEFINED__
+typedef interface ITypeLib ITypeLib;
+#endif
+
+#ifndef __IRecordInfo_FWD_DEFINED__
+#define __IRecordInfo_FWD_DEFINED__
+typedef interface IRecordInfo IRecordInfo;
+#endif
+
+void * __RPC_USER MIDL_user_allocate(SIZE_T);
+void __RPC_USER MIDL_user_free(void *);
+
+/*****************************************************************************
+ * IOleAutomationTypes interface (v1.0)
+ */
+#ifndef __IOleAutomationTypes_INTERFACE_DEFINED__
+#define __IOleAutomationTypes_INTERFACE_DEFINED__
+
+extern RPC_IF_HANDLE IOleAutomationTypes_v1_0_c_ifspec;
+extern RPC_IF_HANDLE IOleAutomationTypes_v1_0_s_ifspec;
 typedef CY CURRENCY;
 typedef struct tagSAFEARRAYBOUND {
@@ -536,34 +655,6 @@
 } CUSTDATA;
 typedef struct tagCUSTDATA *LPCUSTDATA;
-void * __RPC_USER MIDL_user_allocate(size_t);
-void __RPC_USER MIDL_user_free(void *);
-
-/*****************************************************************************
- * IOleAutomationTypes interface (v1.0)
- */
-#ifndef __IOleAutomationTypes_INTERFACE_DEFINED__
-#define __IOleAutomationTypes_INTERFACE_DEFINED__
-
-extern RPC_IF_HANDLE IOleAutomationTypes_v1_0_c_ifspec;
-extern RPC_IF_HANDLE IOleAutomationTypes_v1_0_s_ifspec;
 
 #endif  /* __IOleAutomationTypes_INTERFACE_DEFINED__ */
-
-typedef IDispatch *LPDISPATCH;
-#define DISPID_UNKNOWN (-1)
-
-#define DISPID_VALUE (0)
-
-#define DISPID_PROPERTYPUT (-3)
-
-#define DISPID_NEWENUM (-4)
-
-#define DISPID_EVALUATE (-5)
-
-#define DISPID_CONSTRUCTOR (-6)
-
-#define DISPID_DESTRUCTOR (-7)
-
-#define DISPID_COLLECT (-8)
 
 /*****************************************************************************
@@ -572,4 +663,21 @@
 #ifndef __IDispatch_INTERFACE_DEFINED__
 #define __IDispatch_INTERFACE_DEFINED__
+
+typedef IDispatch *LPDISPATCH;
+#define DISPID_UNKNOWN (-1)
+
+#define DISPID_VALUE (0)
+
+#define DISPID_PROPERTYPUT (-3)
+
+#define DISPID_NEWENUM (-4)
+
+#define DISPID_EVALUATE (-5)
+
+#define DISPID_CONSTRUCTOR (-6)
+
+#define DISPID_DESTRUCTOR (-7)
+
+#define DISPID_COLLECT (-8)
 
 DEFINE_GUID(IID_IDispatch, 0x00020400, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
@@ -743,10 +851,4 @@
 #endif  /* __IDispatch_INTERFACE_DEFINED__ */
 
-#ifndef __IEnumVARIANT_FWD_DEFINED__
-#define __IEnumVARIANT_FWD_DEFINED__
-typedef interface IEnumVARIANT IEnumVARIANT;
-#endif
-
-typedef IEnumVARIANT *LPENUMVARIANT;
 /*****************************************************************************
  * IEnumVARIANT interface
@@ -755,4 +857,5 @@
 #define __IEnumVARIANT_INTERFACE_DEFINED__
 
+typedef IEnumVARIANT *LPENUMVARIANT;
 DEFINE_GUID(IID_IEnumVARIANT, 0x00020404, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -874,8 +977,9 @@
 #endif  /* __IEnumVARIANT_INTERFACE_DEFINED__ */
 
-#ifndef __ITypeComp_FWD_DEFINED__
-#define __ITypeComp_FWD_DEFINED__
-typedef interface ITypeComp ITypeComp;
-#endif
+/*****************************************************************************
+ * ITypeComp interface
+ */
+#ifndef __ITypeComp_INTERFACE_DEFINED__
+#define __ITypeComp_INTERFACE_DEFINED__
 
 typedef ITypeComp *LPTYPECOMP;
@@ -894,10 +998,4 @@
 } BINDPTR;
 typedef union tagBINDPTR *LPBINDPTR;
-/*****************************************************************************
- * ITypeComp interface
- */
-#ifndef __ITypeComp_INTERFACE_DEFINED__
-#define __ITypeComp_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_ITypeComp, 0x00020403, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1029,5 +1127,4 @@
 #endif  /* __ITypeComp_INTERFACE_DEFINED__ */
 
-typedef ITypeInfo *LPTYPEINFO;
 /*****************************************************************************
  * ITypeInfo interface
@@ -1036,4 +1133,5 @@
 #define __ITypeInfo_INTERFACE_DEFINED__
 
+typedef ITypeInfo *LPTYPEINFO;
 DEFINE_GUID(IID_ITypeInfo, 0x00020401, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1583,10 +1681,4 @@
 #endif  /* __ITypeInfo_INTERFACE_DEFINED__ */
 
-#ifndef __ITypeInfo2_FWD_DEFINED__
-#define __ITypeInfo2_FWD_DEFINED__
-typedef interface ITypeInfo2 ITypeInfo2;
-#endif
-
-typedef ITypeInfo2 *LPTYPEINFO2;
 /*****************************************************************************
  * ITypeInfo2 interface
@@ -1595,4 +1687,5 @@
 #define __ITypeInfo2_INTERFACE_DEFINED__
 
+typedef ITypeInfo2 *LPTYPEINFO2;
 DEFINE_GUID(IID_ITypeInfo2, 0x00020412, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2085,4 +2178,10 @@
 #endif  /* __ITypeInfo2_INTERFACE_DEFINED__ */
 
+/*****************************************************************************
+ * ITypeLib interface
+ */
+#ifndef __ITypeLib_INTERFACE_DEFINED__
+#define __ITypeLib_INTERFACE_DEFINED__
+
 typedef ITypeLib *LPTYPELIB;
 typedef enum tagSYSKIND {
@@ -2107,10 +2206,4 @@
 } TLIBATTR;
 typedef struct tagTLIBATTR *LPTLIBATTR;
-/*****************************************************************************
- * ITypeLib interface
- */
-#ifndef __ITypeLib_INTERFACE_DEFINED__
-#define __ITypeLib_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_ITypeLib, 0x00020402, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2413,10 +2506,4 @@
 #endif  /* __ITypeLib_INTERFACE_DEFINED__ */
 
-#ifndef __ITypeLib2_FWD_DEFINED__
-#define __ITypeLib2_FWD_DEFINED__
-typedef interface ITypeLib2 ITypeLib2;
-#endif
-
-typedef ITypeLib2 *LPTYPELIB2;
 /*****************************************************************************
  * ITypeLib2 interface
@@ -2425,4 +2512,5 @@
 #define __ITypeLib2_INTERFACE_DEFINED__
 
+typedef ITypeLib2 *LPTYPELIB2;
 DEFINE_GUID(IID_ITypeLib2, 0x00020411, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2636,8 +2724,9 @@
 #endif  /* __ITypeLib2_INTERFACE_DEFINED__ */
 
-#ifndef __ITypeChangeEvents_FWD_DEFINED__
-#define __ITypeChangeEvents_FWD_DEFINED__
-typedef interface ITypeChangeEvents ITypeChangeEvents;
-#endif
+/*****************************************************************************
+ * ITypeChangeEvents interface
+ */
+#ifndef __ITypeChangeEvents_INTERFACE_DEFINED__
+#define __ITypeChangeEvents_INTERFACE_DEFINED__
 
 typedef ITypeChangeEvents *LPTYPECHANGEEVENTS;
@@ -2652,10 +2741,4 @@
     CHANGEKIND_MAX = 7
 } CHANGEKIND;
-/*****************************************************************************
- * ITypeChangeEvents interface
- */
-#ifndef __ITypeChangeEvents_INTERFACE_DEFINED__
-#define __ITypeChangeEvents_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_ITypeChangeEvents, 0x00020410, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2746,10 +2829,4 @@
 #endif  /* __ITypeChangeEvents_INTERFACE_DEFINED__ */
 
-#ifndef __IErrorInfo_FWD_DEFINED__
-#define __IErrorInfo_FWD_DEFINED__
-typedef interface IErrorInfo IErrorInfo;
-#endif
-
-typedef IErrorInfo *LPERRORINFO;
 /*****************************************************************************
  * IErrorInfo interface
@@ -2758,4 +2835,5 @@
 #define __IErrorInfo_INTERFACE_DEFINED__
 
+typedef IErrorInfo *LPERRORINFO;
 DEFINE_GUID(IID_IErrorInfo, 0x1cf2b120, 0x547d, 0x101b, 0x8e,0x65, 0x08,0x00,0x2b,0x2b,0xd1,0x19);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2879,10 +2957,4 @@
 #endif  /* __IErrorInfo_INTERFACE_DEFINED__ */
 
-#ifndef __ICreateErrorInfo_FWD_DEFINED__
-#define __ICreateErrorInfo_FWD_DEFINED__
-typedef interface ICreateErrorInfo ICreateErrorInfo;
-#endif
-
-typedef ICreateErrorInfo *LPCREATEERRORINFO;
 /*****************************************************************************
  * ICreateErrorInfo interface
@@ -2891,4 +2963,5 @@
 #define __ICreateErrorInfo_INTERFACE_DEFINED__
 
+typedef ICreateErrorInfo *LPCREATEERRORINFO;
 DEFINE_GUID(IID_ICreateErrorInfo, 0x22f03340, 0x547d, 0x101b, 0x8e,0x65, 0x08,0x00,0x2b,0x2b,0xd1,0x19);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -3012,10 +3085,4 @@
 #endif  /* __ICreateErrorInfo_INTERFACE_DEFINED__ */
 
-#ifndef __ISupportErrorInfo_FWD_DEFINED__
-#define __ISupportErrorInfo_FWD_DEFINED__
-typedef interface ISupportErrorInfo ISupportErrorInfo;
-#endif
-
-typedef ISupportErrorInfo *LPSUPPORTERRORINFO;
 /*****************************************************************************
  * ISupportErrorInfo interface
@@ -3024,4 +3091,5 @@
 #define __ISupportErrorInfo_INTERFACE_DEFINED__
 
+typedef ISupportErrorInfo *LPSUPPORTERRORINFO;
 DEFINE_GUID(IID_ISupportErrorInfo, 0xdf0b3d60, 0x548f, 0x101b, 0x8e,0x65, 0x08,0x00,0x2b,0x2b,0xd1,0x19);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -3080,9 +3148,4 @@
 
 #endif  /* __ISupportErrorInfo_INTERFACE_DEFINED__ */
-
-#ifndef __ITypeFactory_FWD_DEFINED__
-#define __ITypeFactory_FWD_DEFINED__
-typedef interface ITypeFactory ITypeFactory;
-#endif
 
 /*****************************************************************************
@@ -3154,9 +3217,4 @@
 
 #endif  /* __ITypeFactory_INTERFACE_DEFINED__ */
-
-#ifndef __ITypeMarshal_FWD_DEFINED__
-#define __ITypeMarshal_FWD_DEFINED__
-typedef interface ITypeMarshal ITypeMarshal;
-#endif
 
 /*****************************************************************************
@@ -3307,5 +3365,4 @@
 #endif  /* __ITypeMarshal_INTERFACE_DEFINED__ */
 
-typedef IRecordInfo *LPRECORDINFO;
 /*****************************************************************************
  * IRecordInfo interface
@@ -3314,4 +3371,5 @@
 #define __IRecordInfo_INTERFACE_DEFINED__
 
+typedef IRecordInfo *LPRECORDINFO;
 DEFINE_GUID(IID_IRecordInfo, 0x0000002f, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -3651,10 +3709,4 @@
 #endif  /* __IRecordInfo_INTERFACE_DEFINED__ */
 
-#ifndef __ICreateTypeInfo_FWD_DEFINED__
-#define __ICreateTypeInfo_FWD_DEFINED__
-typedef interface ICreateTypeInfo ICreateTypeInfo;
-#endif
-
-typedef ICreateTypeInfo *LPCREATETYPEINFO;
 /*****************************************************************************
  * ICreateTypeInfo interface
@@ -3663,4 +3715,5 @@
 #define __ICreateTypeInfo_INTERFACE_DEFINED__
 
+typedef ICreateTypeInfo *LPCREATETYPEINFO;
 DEFINE_GUID(IID_ICreateTypeInfo, 0x00020405, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -4118,10 +4171,4 @@
 #endif  /* __ICreateTypeInfo_INTERFACE_DEFINED__ */
 
-#ifndef __ICreateTypeInfo2_FWD_DEFINED__
-#define __ICreateTypeInfo2_FWD_DEFINED__
-typedef interface ICreateTypeInfo2 ICreateTypeInfo2;
-#endif
-
-typedef ICreateTypeInfo2 *LPCREATETYPEINFO2;
 /*****************************************************************************
  * ICreateTypeInfo2 interface
@@ -4130,4 +4177,5 @@
 #define __ICreateTypeInfo2_INTERFACE_DEFINED__
 
+typedef ICreateTypeInfo2 *LPCREATETYPEINFO2;
 DEFINE_GUID(IID_ICreateTypeInfo2, 0x0002040e, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -4580,10 +4628,4 @@
 #endif  /* __ICreateTypeInfo2_INTERFACE_DEFINED__ */
 
-#ifndef __ICreateTypeLib_FWD_DEFINED__
-#define __ICreateTypeLib_FWD_DEFINED__
-typedef interface ICreateTypeLib ICreateTypeLib;
-#endif
-
-typedef ICreateTypeLib *LPCREATETYPELIB;
 /*****************************************************************************
  * ICreateTypeLib interface
@@ -4592,4 +4634,5 @@
 #define __ICreateTypeLib_INTERFACE_DEFINED__
 
+typedef ICreateTypeLib *LPCREATETYPELIB;
 DEFINE_GUID(IID_ICreateTypeLib, 0x00020406, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -4800,10 +4843,4 @@
 #endif  /* __ICreateTypeLib_INTERFACE_DEFINED__ */
 
-#ifndef __ICreateTypeLib2_FWD_DEFINED__
-#define __ICreateTypeLib2_FWD_DEFINED__
-typedef interface ICreateTypeLib2 ICreateTypeLib2;
-#endif
-
-typedef ICreateTypeLib2 *LPCREATETYPELIB2;
 /*****************************************************************************
  * ICreateTypeLib2 interface
@@ -4812,4 +4849,5 @@
 #define __ICreateTypeLib2_INTERFACE_DEFINED__
 
+typedef ICreateTypeLib2 *LPCREATETYPELIB2;
 DEFINE_GUID(IID_ICreateTypeLib2, 0x0002040f, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -4974,10 +5012,4 @@
 #endif  /* __ICreateTypeLib2_INTERFACE_DEFINED__ */
 
-#ifndef __IErrorLog_FWD_DEFINED__
-#define __IErrorLog_FWD_DEFINED__
-typedef interface IErrorLog IErrorLog;
-#endif
-
-typedef IErrorLog *LPERRORLOG;
 /*****************************************************************************
  * IErrorLog interface
@@ -4986,4 +5018,5 @@
 #define __IErrorLog_INTERFACE_DEFINED__
 
+typedef IErrorLog *LPERRORLOG;
 DEFINE_GUID(IID_IErrorLog, 0x3127ca40, 0x446e, 0x11ce, 0x81,0x35, 0x00,0xaa,0x00,0x4b,0xb8,0x51);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -5046,10 +5079,4 @@
 #endif  /* __IErrorLog_INTERFACE_DEFINED__ */
 
-#ifndef __IPropertyBag_FWD_DEFINED__
-#define __IPropertyBag_FWD_DEFINED__
-typedef interface IPropertyBag IPropertyBag;
-#endif
-
-typedef IPropertyBag *LPPROPERTYBAG;
 /*****************************************************************************
  * IPropertyBag interface
@@ -5058,4 +5085,5 @@
 #define __IPropertyBag_INTERFACE_DEFINED__
 
+typedef IPropertyBag *LPPROPERTYBAG;
 DEFINE_GUID(IID_IPropertyBag, 0x55272a00, 0x42cb, 0x11ce, 0x81,0x35, 0x00,0xaa,0x00,0x4b,0xb8,0x51);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -5156,12 +5184,12 @@
 /* Begin additional prototypes for all interfaces */
 
+ULONG           __RPC_USER VARIANT_UserSize     (ULONG *, ULONG, VARIANT *);
+unsigned char * __RPC_USER VARIANT_UserMarshal  (ULONG *, unsigned char *, VARIANT *);
+unsigned char * __RPC_USER VARIANT_UserUnmarshal(ULONG *, unsigned char *, VARIANT *);
+void            __RPC_USER VARIANT_UserFree     (ULONG *, VARIANT *);
 ULONG           __RPC_USER BSTR_UserSize     (ULONG *, ULONG, BSTR *);
 unsigned char * __RPC_USER BSTR_UserMarshal  (ULONG *, unsigned char *, BSTR *);
 unsigned char * __RPC_USER BSTR_UserUnmarshal(ULONG *, unsigned char *, BSTR *);
 void            __RPC_USER BSTR_UserFree     (ULONG *, BSTR *);
-ULONG           __RPC_USER VARIANT_UserSize     (ULONG *, ULONG, VARIANT *);
-unsigned char * __RPC_USER VARIANT_UserMarshal  (ULONG *, unsigned char *, VARIANT *);
-unsigned char * __RPC_USER VARIANT_UserUnmarshal(ULONG *, unsigned char *, VARIANT *);
-void            __RPC_USER VARIANT_UserFree     (ULONG *, VARIANT *);
 ULONG           __RPC_USER CLEANLOCALSTORAGE_UserSize     (ULONG *, ULONG, CLEANLOCALSTORAGE *);
 unsigned char * __RPC_USER CLEANLOCALSTORAGE_UserMarshal  (ULONG *, unsigned char *, CLEANLOCALSTORAGE *);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.h	(revision 21731)
@@ -1,3 +1,4 @@
-/*** Autogenerated by WIDL 1.1.23 from ../../../dlls/wined3d/../../include/objidl.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.26 from ../../include/objidl.idl - Do not edit ***/
+
 #include <rpc.h>
 #include <rpcndr.h>
@@ -5,9 +6,406 @@
 #ifndef __WIDL_OBJIDL_H
 #define __WIDL_OBJIDL_H
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+/* Headers for imported files */
+
 #include <unknwn.h>
+
+/* Forward declarations */
+
+#ifndef __IMarshal_FWD_DEFINED__
+#define __IMarshal_FWD_DEFINED__
+typedef interface IMarshal IMarshal;
+#endif
+
+#ifndef __IMarshal2_FWD_DEFINED__
+#define __IMarshal2_FWD_DEFINED__
+typedef interface IMarshal2 IMarshal2;
+#endif
+
+#ifndef __IStdMarshalInfo_FWD_DEFINED__
+#define __IStdMarshalInfo_FWD_DEFINED__
+typedef interface IStdMarshalInfo IStdMarshalInfo;
+#endif
+
+#ifndef __IExternalConnection_FWD_DEFINED__
+#define __IExternalConnection_FWD_DEFINED__
+typedef interface IExternalConnection IExternalConnection;
+#endif
+
+#ifndef __IMultiQI_FWD_DEFINED__
+#define __IMultiQI_FWD_DEFINED__
+typedef interface IMultiQI IMultiQI;
+#endif
+
+#ifndef __IMalloc_FWD_DEFINED__
+#define __IMalloc_FWD_DEFINED__
+typedef interface IMalloc IMalloc;
+#endif
+
+#ifndef __IMallocSpy_FWD_DEFINED__
+#define __IMallocSpy_FWD_DEFINED__
+typedef interface IMallocSpy IMallocSpy;
+#endif
+
+#ifndef __IInternalUnknown_FWD_DEFINED__
+#define __IInternalUnknown_FWD_DEFINED__
+typedef interface IInternalUnknown IInternalUnknown;
+#endif
+
+#ifndef __IEnumUnknown_FWD_DEFINED__
+#define __IEnumUnknown_FWD_DEFINED__
+typedef interface IEnumUnknown IEnumUnknown;
+#endif
+
+#ifndef __ISurrogate_FWD_DEFINED__
+#define __ISurrogate_FWD_DEFINED__
+typedef interface ISurrogate ISurrogate;
+#endif
+
+#ifndef __IGlobalInterfaceTable_FWD_DEFINED__
+#define __IGlobalInterfaceTable_FWD_DEFINED__
+typedef interface IGlobalInterfaceTable IGlobalInterfaceTable;
+#endif
+
+#ifndef __IBindCtx_FWD_DEFINED__
+#define __IBindCtx_FWD_DEFINED__
+typedef interface IBindCtx IBindCtx;
+#endif
+
+#ifndef __IEnumMoniker_FWD_DEFINED__
+#define __IEnumMoniker_FWD_DEFINED__
+typedef interface IEnumMoniker IEnumMoniker;
+#endif
+
+#ifndef __IRunnableObject_FWD_DEFINED__
+#define __IRunnableObject_FWD_DEFINED__
+typedef interface IRunnableObject IRunnableObject;
+#endif
+
+#ifndef __IRunningObjectTable_FWD_DEFINED__
+#define __IRunningObjectTable_FWD_DEFINED__
+typedef interface IRunningObjectTable IRunningObjectTable;
+#endif
+
+#ifndef __IPersist_FWD_DEFINED__
+#define __IPersist_FWD_DEFINED__
+typedef interface IPersist IPersist;
+#endif
+
+#ifndef __IPersistStream_FWD_DEFINED__
+#define __IPersistStream_FWD_DEFINED__
+typedef interface IPersistStream IPersistStream;
+#endif
+
+#ifndef __IMoniker_FWD_DEFINED__
+#define __IMoniker_FWD_DEFINED__
+typedef interface IMoniker IMoniker;
+#endif
+
+#ifndef __IROTData_FWD_DEFINED__
+#define __IROTData_FWD_DEFINED__
+typedef interface IROTData IROTData;
+#endif
+
+#ifndef __IEnumString_FWD_DEFINED__
+#define __IEnumString_FWD_DEFINED__
+typedef interface IEnumString IEnumString;
+#endif
+
+#ifndef __IClassActivator_FWD_DEFINED__
+#define __IClassActivator_FWD_DEFINED__
+typedef interface IClassActivator IClassActivator;
+#endif
+
+#ifndef __ISequentialStream_FWD_DEFINED__
+#define __ISequentialStream_FWD_DEFINED__
+typedef interface ISequentialStream ISequentialStream;
+#endif
+
+#ifndef __IStream_FWD_DEFINED__
+#define __IStream_FWD_DEFINED__
+typedef interface IStream IStream;
+#endif
+
+#ifndef __IEnumSTATSTG_FWD_DEFINED__
+#define __IEnumSTATSTG_FWD_DEFINED__
+typedef interface IEnumSTATSTG IEnumSTATSTG;
+#endif
+
+#ifndef __IStorage_FWD_DEFINED__
+#define __IStorage_FWD_DEFINED__
+typedef interface IStorage IStorage;
+#endif
+
+#ifndef __IPersistFile_FWD_DEFINED__
+#define __IPersistFile_FWD_DEFINED__
+typedef interface IPersistFile IPersistFile;
+#endif
+
+#ifndef __IPersistStorage_FWD_DEFINED__
+#define __IPersistStorage_FWD_DEFINED__
+typedef interface IPersistStorage IPersistStorage;
+#endif
+
+#ifndef __IRootStorage_FWD_DEFINED__
+#define __IRootStorage_FWD_DEFINED__
+typedef interface IRootStorage IRootStorage;
+#endif
+
+#ifndef __ILockBytes_FWD_DEFINED__
+#define __ILockBytes_FWD_DEFINED__
+typedef interface ILockBytes ILockBytes;
+#endif
+
+#ifndef __IFillLockBytes_FWD_DEFINED__
+#define __IFillLockBytes_FWD_DEFINED__
+typedef interface IFillLockBytes IFillLockBytes;
+#endif
+
+#ifndef __IProgressNotify_FWD_DEFINED__
+#define __IProgressNotify_FWD_DEFINED__
+typedef interface IProgressNotify IProgressNotify;
+#endif
+
+#ifndef __ILayoutStorage_FWD_DEFINED__
+#define __ILayoutStorage_FWD_DEFINED__
+typedef interface ILayoutStorage ILayoutStorage;
+#endif
+
+#ifndef __IBlockingLock_FWD_DEFINED__
+#define __IBlockingLock_FWD_DEFINED__
+typedef interface IBlockingLock IBlockingLock;
+#endif
+
+#ifndef __ITimeAndNoticeControl_FWD_DEFINED__
+#define __ITimeAndNoticeControl_FWD_DEFINED__
+typedef interface ITimeAndNoticeControl ITimeAndNoticeControl;
+#endif
+
+#ifndef __IOplockStorage_FWD_DEFINED__
+#define __IOplockStorage_FWD_DEFINED__
+typedef interface IOplockStorage IOplockStorage;
+#endif
+
+#ifndef __IEnumFORMATETC_FWD_DEFINED__
+#define __IEnumFORMATETC_FWD_DEFINED__
+typedef interface IEnumFORMATETC IEnumFORMATETC;
+#endif
+
+#ifndef __IEnumSTATDATA_FWD_DEFINED__
+#define __IEnumSTATDATA_FWD_DEFINED__
+typedef interface IEnumSTATDATA IEnumSTATDATA;
+#endif
+
+#ifndef __IAdviseSink_FWD_DEFINED__
+#define __IAdviseSink_FWD_DEFINED__
+typedef interface IAdviseSink IAdviseSink;
+#endif
+
+#ifndef __IAdviseSink2_FWD_DEFINED__
+#define __IAdviseSink2_FWD_DEFINED__
+typedef interface IAdviseSink2 IAdviseSink2;
+#endif
+
+#ifndef __IDataObject_FWD_DEFINED__
+#define __IDataObject_FWD_DEFINED__
+typedef interface IDataObject IDataObject;
+#endif
+
+#ifndef __IDataAdviseHolder_FWD_DEFINED__
+#define __IDataAdviseHolder_FWD_DEFINED__
+typedef interface IDataAdviseHolder IDataAdviseHolder;
+#endif
+
+#ifndef __IMessageFilter_FWD_DEFINED__
+#define __IMessageFilter_FWD_DEFINED__
+typedef interface IMessageFilter IMessageFilter;
+#endif
+
+#ifndef __IRpcChannelBuffer_FWD_DEFINED__
+#define __IRpcChannelBuffer_FWD_DEFINED__
+typedef interface IRpcChannelBuffer IRpcChannelBuffer;
+#endif
+
+#ifndef __IRpcChannelBuffer2_FWD_DEFINED__
+#define __IRpcChannelBuffer2_FWD_DEFINED__
+typedef interface IRpcChannelBuffer2 IRpcChannelBuffer2;
+#endif
+
+#ifndef __IRpcChannelBuffer3_FWD_DEFINED__
+#define __IRpcChannelBuffer3_FWD_DEFINED__
+typedef interface IRpcChannelBuffer3 IRpcChannelBuffer3;
+#endif
+
+#ifndef __IAsyncRpcChannelBuffer_FWD_DEFINED__
+#define __IAsyncRpcChannelBuffer_FWD_DEFINED__
+typedef interface IAsyncRpcChannelBuffer IAsyncRpcChannelBuffer;
+#endif
+
+#ifndef __IRpcSyntaxNegotiate_FWD_DEFINED__
+#define __IRpcSyntaxNegotiate_FWD_DEFINED__
+typedef interface IRpcSyntaxNegotiate IRpcSyntaxNegotiate;
+#endif
+
+#ifndef __IRpcProxyBuffer_FWD_DEFINED__
+#define __IRpcProxyBuffer_FWD_DEFINED__
+typedef interface IRpcProxyBuffer IRpcProxyBuffer;
+#endif
+
+#ifndef __IRpcStubBuffer_FWD_DEFINED__
+#define __IRpcStubBuffer_FWD_DEFINED__
+typedef interface IRpcStubBuffer IRpcStubBuffer;
+#endif
+
+#ifndef __IPSFactoryBuffer_FWD_DEFINED__
+#define __IPSFactoryBuffer_FWD_DEFINED__
+typedef interface IPSFactoryBuffer IPSFactoryBuffer;
+#endif
+
+#ifndef __IChannelHook_FWD_DEFINED__
+#define __IChannelHook_FWD_DEFINED__
+typedef interface IChannelHook IChannelHook;
+#endif
+
+#ifndef __IClientSecurity_FWD_DEFINED__
+#define __IClientSecurity_FWD_DEFINED__
+typedef interface IClientSecurity IClientSecurity;
+#endif
+
+#ifndef __IServerSecurity_FWD_DEFINED__
+#define __IServerSecurity_FWD_DEFINED__
+typedef interface IServerSecurity IServerSecurity;
+#endif
+
+#ifndef __IAsyncSetup_FWD_DEFINED__
+#define __IAsyncSetup_FWD_DEFINED__
+typedef interface IAsyncSetup IAsyncSetup;
+#endif
+
+#ifndef __IDirectWriterLock_FWD_DEFINED__
+#define __IDirectWriterLock_FWD_DEFINED__
+typedef interface IDirectWriterLock IDirectWriterLock;
+#endif
+
+#ifndef __ISynchronize_FWD_DEFINED__
+#define __ISynchronize_FWD_DEFINED__
+typedef interface ISynchronize ISynchronize;
+#endif
+
+#ifndef __ISynchronizeHandle_FWD_DEFINED__
+#define __ISynchronizeHandle_FWD_DEFINED__
+typedef interface ISynchronizeHandle ISynchronizeHandle;
+#endif
+
+#ifndef __ISynchronizeEvent_FWD_DEFINED__
+#define __ISynchronizeEvent_FWD_DEFINED__
+typedef interface ISynchronizeEvent ISynchronizeEvent;
+#endif
+
+#ifndef __ISynchronizeContainer_FWD_DEFINED__
+#define __ISynchronizeContainer_FWD_DEFINED__
+typedef interface ISynchronizeContainer ISynchronizeContainer;
+#endif
+
+#ifndef __ISynchronizeMutex_FWD_DEFINED__
+#define __ISynchronizeMutex_FWD_DEFINED__
+typedef interface ISynchronizeMutex ISynchronizeMutex;
+#endif
+
+#ifndef __ICancelMethodCalls_FWD_DEFINED__
+#define __ICancelMethodCalls_FWD_DEFINED__
+typedef interface ICancelMethodCalls ICancelMethodCalls;
+#endif
+
+#ifndef __IAsyncManager_FWD_DEFINED__
+#define __IAsyncManager_FWD_DEFINED__
+typedef interface IAsyncManager IAsyncManager;
+#endif
+
+#ifndef __ICallFactory_FWD_DEFINED__
+#define __ICallFactory_FWD_DEFINED__
+typedef interface ICallFactory ICallFactory;
+#endif
+
+#ifndef __IRpcOptions_FWD_DEFINED__
+#define __IRpcOptions_FWD_DEFINED__
+typedef interface IRpcOptions IRpcOptions;
+#endif
+
+#ifndef __IRpcHelper_FWD_DEFINED__
+#define __IRpcHelper_FWD_DEFINED__
+typedef interface IRpcHelper IRpcHelper;
+#endif
+
+#ifndef __IReleaseMarshalBuffers_FWD_DEFINED__
+#define __IReleaseMarshalBuffers_FWD_DEFINED__
+typedef interface IReleaseMarshalBuffers IReleaseMarshalBuffers;
+#endif
+
+#ifndef __IWaitMultiple_FWD_DEFINED__
+#define __IWaitMultiple_FWD_DEFINED__
+typedef interface IWaitMultiple IWaitMultiple;
+#endif
+
+#ifndef __IUrlMon_FWD_DEFINED__
+#define __IUrlMon_FWD_DEFINED__
+typedef interface IUrlMon IUrlMon;
+#endif
+
+#ifndef __IForegroundTransfer_FWD_DEFINED__
+#define __IForegroundTransfer_FWD_DEFINED__
+typedef interface IForegroundTransfer IForegroundTransfer;
+#endif
+
+#ifndef __IAddrTrackingControl_FWD_DEFINED__
+#define __IAddrTrackingControl_FWD_DEFINED__
+typedef interface IAddrTrackingControl IAddrTrackingControl;
+#endif
+
+#ifndef __IAddrExclusionControl_FWD_DEFINED__
+#define __IAddrExclusionControl_FWD_DEFINED__
+typedef interface IAddrExclusionControl IAddrExclusionControl;
+#endif
+
+#ifndef __IComThreadingInfo_FWD_DEFINED__
+#define __IComThreadingInfo_FWD_DEFINED__
+typedef interface IComThreadingInfo IComThreadingInfo;
+#endif
+
+#ifndef __IProcessInitControl_FWD_DEFINED__
+#define __IProcessInitControl_FWD_DEFINED__
+typedef interface IProcessInitControl IProcessInitControl;
+#endif
+
+#ifndef __IInitializeSpy_FWD_DEFINED__
+#define __IInitializeSpy_FWD_DEFINED__
+typedef interface IInitializeSpy IInitializeSpy;
+#endif
+
+#ifndef __IThumbnailExtractor_FWD_DEFINED__
+#define __IThumbnailExtractor_FWD_DEFINED__
+typedef interface IThumbnailExtractor IThumbnailExtractor;
+#endif
+
+#ifndef __IEnumContextProps_FWD_DEFINED__
+#define __IEnumContextProps_FWD_DEFINED__
+typedef interface IEnumContextProps IEnumContextProps;
+#endif
+
+#ifndef __IContext_FWD_DEFINED__
+#define __IContext_FWD_DEFINED__
+typedef interface IContext IContext;
+#endif
+
+#ifndef __IObjContext_FWD_DEFINED__
+#define __IObjContext_FWD_DEFINED__
+typedef interface IObjContext IObjContext;
+#endif
+
+
 #ifndef __IStream_FWD_DEFINED__
 #define __IStream_FWD_DEFINED__
@@ -51,10 +449,4 @@
     DWORD dwReserved2;
 } COSERVERINFO;
-#ifndef __IMarshal_FWD_DEFINED__
-#define __IMarshal_FWD_DEFINED__
-typedef interface IMarshal IMarshal;
-#endif
-
-typedef IMarshal *LPMARSHAL;
 /*****************************************************************************
  * IMarshal interface
@@ -63,4 +455,5 @@
 #define __IMarshal_INTERFACE_DEFINED__
 
+typedef IMarshal *LPMARSHAL;
 DEFINE_GUID(IID_IMarshal, 0x00000003, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -251,10 +644,4 @@
 #endif  /* __IMarshal_INTERFACE_DEFINED__ */
 
-#ifndef __IMarshal2_FWD_DEFINED__
-#define __IMarshal2_FWD_DEFINED__
-typedef interface IMarshal2 IMarshal2;
-#endif
-
-typedef IMarshal2 *LPMARSHAL2;
 /*****************************************************************************
  * IMarshal2 interface
@@ -263,4 +650,5 @@
 #define __IMarshal2_INTERFACE_DEFINED__
 
+typedef IMarshal2 *LPMARSHAL2;
 DEFINE_GUID(IID_IMarshal2, 0x000001cf, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -351,10 +739,4 @@
 #endif  /* __IMarshal2_INTERFACE_DEFINED__ */
 
-#ifndef __IStdMarshalInfo_FWD_DEFINED__
-#define __IStdMarshalInfo_FWD_DEFINED__
-typedef interface IStdMarshalInfo IStdMarshalInfo;
-#endif
-
-typedef IStdMarshalInfo *LPSTDMARSHALINFO;
 /*****************************************************************************
  * IStdMarshalInfo interface
@@ -363,4 +745,5 @@
 #define __IStdMarshalInfo_INTERFACE_DEFINED__
 
+typedef IStdMarshalInfo *LPSTDMARSHALINFO;
 DEFINE_GUID(IID_IStdMarshalInfo, 0x00000018, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -426,8 +809,9 @@
 #endif  /* __IStdMarshalInfo_INTERFACE_DEFINED__ */
 
-#ifndef __IExternalConnection_FWD_DEFINED__
-#define __IExternalConnection_FWD_DEFINED__
-typedef interface IExternalConnection IExternalConnection;
-#endif
+/*****************************************************************************
+ * IExternalConnection interface
+ */
+#ifndef __IExternalConnection_INTERFACE_DEFINED__
+#define __IExternalConnection_INTERFACE_DEFINED__
 
 typedef IExternalConnection *LPEXTERNALCONNECTION;
@@ -437,10 +821,4 @@
     EXTCONN_CALLABLE = 0x4
 } EXTCONN;
-/*****************************************************************************
- * IExternalConnection interface
- */
-#ifndef __IExternalConnection_INTERFACE_DEFINED__
-#define __IExternalConnection_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IExternalConnection, 0x00000019, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -525,8 +903,9 @@
 #endif  /* __IExternalConnection_INTERFACE_DEFINED__ */
 
-#ifndef __IMultiQI_FWD_DEFINED__
-#define __IMultiQI_FWD_DEFINED__
-typedef interface IMultiQI IMultiQI;
-#endif
+/*****************************************************************************
+ * IMultiQI interface
+ */
+#ifndef __IMultiQI_INTERFACE_DEFINED__
+#define __IMultiQI_INTERFACE_DEFINED__
 
 typedef IMultiQI *LPMULTIQI;
@@ -536,10 +915,4 @@
     HRESULT hr;
 } MULTI_QI;
-/*****************************************************************************
- * IMultiQI interface
- */
-#ifndef __IMultiQI_INTERFACE_DEFINED__
-#define __IMultiQI_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IMultiQI, 0x00000020, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -602,10 +975,4 @@
 #endif  /* __IMultiQI_INTERFACE_DEFINED__ */
 
-#ifndef __IMalloc_FWD_DEFINED__
-#define __IMalloc_FWD_DEFINED__
-typedef interface IMalloc IMalloc;
-#endif
-
-typedef IMalloc *LPMALLOC;
 /*****************************************************************************
  * IMalloc interface
@@ -614,4 +981,5 @@
 #define __IMalloc_INTERFACE_DEFINED__
 
+typedef IMalloc *LPMALLOC;
 DEFINE_GUID(IID_IMalloc, 0x00000002, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -752,10 +1120,4 @@
 #endif  /* __IMalloc_INTERFACE_DEFINED__ */
 
-#ifndef __IMallocSpy_FWD_DEFINED__
-#define __IMallocSpy_FWD_DEFINED__
-typedef interface IMallocSpy IMallocSpy;
-#endif
-
-typedef IMallocSpy *LPMALLOCSPY;
 /*****************************************************************************
  * IMallocSpy interface
@@ -764,4 +1126,5 @@
 #define __IMallocSpy_INTERFACE_DEFINED__
 
+typedef IMallocSpy *LPMALLOCSPY;
 DEFINE_GUID(IID_IMallocSpy, 0x0000001d, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1023,9 +1386,4 @@
 #endif  /* __IMallocSpy_INTERFACE_DEFINED__ */
 
-#ifndef __IInternalUnknown_FWD_DEFINED__
-#define __IInternalUnknown_FWD_DEFINED__
-typedef interface IInternalUnknown IInternalUnknown;
-#endif
-
 /*****************************************************************************
  * IInternalUnknown interface
@@ -1094,10 +1452,4 @@
 #endif  /* __IInternalUnknown_INTERFACE_DEFINED__ */
 
-#ifndef __IEnumUnknown_FWD_DEFINED__
-#define __IEnumUnknown_FWD_DEFINED__
-typedef interface IEnumUnknown IEnumUnknown;
-#endif
-
-typedef IEnumUnknown *LPENUMUNKNOWN;
 /*****************************************************************************
  * IEnumUnknown interface
@@ -1106,4 +1458,5 @@
 #define __IEnumUnknown_INTERFACE_DEFINED__
 
+typedef IEnumUnknown *LPENUMUNKNOWN;
 DEFINE_GUID(IID_IEnumUnknown, 0x00000100, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1225,10 +1578,4 @@
 #endif  /* __IEnumUnknown_INTERFACE_DEFINED__ */
 
-#ifndef __ISurrogate_FWD_DEFINED__
-#define __ISurrogate_FWD_DEFINED__
-typedef interface ISurrogate ISurrogate;
-#endif
-
-typedef ISurrogate *LPSURROGATE;
 /*****************************************************************************
  * ISurrogate interface
@@ -1237,4 +1584,5 @@
 #define __ISurrogate_INTERFACE_DEFINED__
 
+typedef ISurrogate *LPSURROGATE;
 DEFINE_GUID(IID_ISurrogate, 0x00000022, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1308,10 +1656,4 @@
 #endif  /* __ISurrogate_INTERFACE_DEFINED__ */
 
-#ifndef __IGlobalInterfaceTable_FWD_DEFINED__
-#define __IGlobalInterfaceTable_FWD_DEFINED__
-typedef interface IGlobalInterfaceTable IGlobalInterfaceTable;
-#endif
-
-typedef IGlobalInterfaceTable *LPGLOBALINTERFACETABLE;
 /*****************************************************************************
  * IGlobalInterfaceTable interface
@@ -1320,4 +1662,5 @@
 #define __IGlobalInterfaceTable_INTERFACE_DEFINED__
 
+typedef IGlobalInterfaceTable *LPGLOBALINTERFACETABLE;
 DEFINE_GUID(IID_IGlobalInterfaceTable, 0x00000146, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1421,8 +1764,9 @@
 #endif  /* __IGlobalInterfaceTable_INTERFACE_DEFINED__ */
 
-#ifndef __IBindCtx_FWD_DEFINED__
-#define __IBindCtx_FWD_DEFINED__
-typedef interface IBindCtx IBindCtx;
-#endif
+/*****************************************************************************
+ * IBindCtx interface
+ */
+#ifndef __IBindCtx_INTERFACE_DEFINED__
+#define __IBindCtx_INTERFACE_DEFINED__
 
 typedef IBindCtx *LPBINDCTX;
@@ -1450,10 +1794,4 @@
     BIND_JUSTTESTEXISTENCE = 2
 } BIND_FLAGS;
-/*****************************************************************************
- * IBindCtx interface
- */
-#ifndef __IBindCtx_INTERFACE_DEFINED__
-#define __IBindCtx_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IBindCtx, 0x0000000e, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1673,10 +2011,4 @@
 #endif  /* __IBindCtx_INTERFACE_DEFINED__ */
 
-#ifndef __IEnumMoniker_FWD_DEFINED__
-#define __IEnumMoniker_FWD_DEFINED__
-typedef interface IEnumMoniker IEnumMoniker;
-#endif
-
-typedef IEnumMoniker *LPENUMMONIKER;
 /*****************************************************************************
  * IEnumMoniker interface
@@ -1685,4 +2017,5 @@
 #define __IEnumMoniker_INTERFACE_DEFINED__
 
+typedef IEnumMoniker *LPENUMMONIKER;
 DEFINE_GUID(IID_IEnumMoniker, 0x00000102, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1804,10 +2137,4 @@
 #endif  /* __IEnumMoniker_INTERFACE_DEFINED__ */
 
-#ifndef __IRunnableObject_FWD_DEFINED__
-#define __IRunnableObject_FWD_DEFINED__
-typedef interface IRunnableObject IRunnableObject;
-#endif
-
-typedef IRunnableObject *LPRUNNABLEOBJECT;
 /*****************************************************************************
  * IRunnableObject interface
@@ -1816,4 +2143,5 @@
 #define __IRunnableObject_INTERFACE_DEFINED__
 
+typedef IRunnableObject *LPRUNNABLEOBJECT;
 DEFINE_GUID(IID_IRunnableObject, 0x00000126, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1945,5 +2273,4 @@
 #undef GetObject
 #endif
-typedef IRunningObjectTable *LPRUNNINGOBJECTTABLE;
 /*****************************************************************************
  * IRunningObjectTable interface
@@ -1952,4 +2279,5 @@
 #define __IRunningObjectTable_INTERFACE_DEFINED__
 
+typedef IRunningObjectTable *LPRUNNINGOBJECTTABLE;
 DEFINE_GUID(IID_IRunningObjectTable, 0x00000010, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2123,10 +2451,4 @@
 #endif  /* __IRunningObjectTable_INTERFACE_DEFINED__ */
 
-#ifndef __IPersist_FWD_DEFINED__
-#define __IPersist_FWD_DEFINED__
-typedef interface IPersist IPersist;
-#endif
-
-typedef IPersist *LPPERSIST;
 /*****************************************************************************
  * IPersist interface
@@ -2135,4 +2457,5 @@
 #define __IPersist_INTERFACE_DEFINED__
 
+typedef IPersist *LPPERSIST;
 DEFINE_GUID(IID_IPersist, 0x0000010c, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2192,10 +2515,4 @@
 #endif  /* __IPersist_INTERFACE_DEFINED__ */
 
-#ifndef __IPersistStream_FWD_DEFINED__
-#define __IPersistStream_FWD_DEFINED__
-typedef interface IPersistStream IPersistStream;
-#endif
-
-typedef IPersistStream *LPPERSISTSTREAM;
 /*****************************************************************************
  * IPersistStream interface
@@ -2204,4 +2521,5 @@
 #define __IPersistStream_INTERFACE_DEFINED__
 
+typedef IPersistStream *LPPERSISTSTREAM;
 DEFINE_GUID(IID_IPersistStream, 0x00000109, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2316,4 +2634,10 @@
 
 #endif  /* __IPersistStream_INTERFACE_DEFINED__ */
+
+/*****************************************************************************
+ * IMoniker interface
+ */
+#ifndef __IMoniker_INTERFACE_DEFINED__
+#define __IMoniker_INTERFACE_DEFINED__
 
 typedef IMoniker *LPMONIKER;
@@ -2333,10 +2657,4 @@
     MKRREDUCE_ALL = 0
 } MKRREDUCE;
-/*****************************************************************************
- * IMoniker interface
- */
-#ifndef __IMoniker_INTERFACE_DEFINED__
-#define __IMoniker_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IMoniker, 0x0000000f, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2745,9 +3063,4 @@
 #endif  /* __IMoniker_INTERFACE_DEFINED__ */
 
-#ifndef __IROTData_FWD_DEFINED__
-#define __IROTData_FWD_DEFINED__
-typedef interface IROTData IROTData;
-#endif
-
 /*****************************************************************************
  * IROTData interface
@@ -2819,5 +3132,4 @@
 #endif  /* __IROTData_INTERFACE_DEFINED__ */
 
-typedef IEnumString *LPENUMSTRING;
 /*****************************************************************************
  * IEnumString interface
@@ -2826,4 +3138,5 @@
 #define __IEnumString_INTERFACE_DEFINED__
 
+typedef IEnumString *LPENUMSTRING;
 DEFINE_GUID(IID_IEnumString, 0x00000101, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2945,9 +3258,4 @@
 #endif  /* __IEnumString_INTERFACE_DEFINED__ */
 
-#ifndef __IClassActivator_FWD_DEFINED__
-#define __IClassActivator_FWD_DEFINED__
-typedef interface IClassActivator IClassActivator;
-#endif
-
 /*****************************************************************************
  * IClassActivator interface
@@ -3024,9 +3332,4 @@
 
 #endif  /* __IClassActivator_INTERFACE_DEFINED__ */
-
-#ifndef __ISequentialStream_FWD_DEFINED__
-#define __ISequentialStream_FWD_DEFINED__
-typedef interface ISequentialStream ISequentialStream;
-#endif
 
 /*****************************************************************************
@@ -3140,4 +3443,10 @@
 
 #endif  /* __ISequentialStream_INTERFACE_DEFINED__ */
+
+/*****************************************************************************
+ * IStream interface
+ */
+#ifndef __IStream_INTERFACE_DEFINED__
+#define __IStream_INTERFACE_DEFINED__
 
 typedef IStream *LPSTREAM;
@@ -3175,10 +3484,4 @@
     LOCK_ONLYONCE = 4
 } LOCKTYPE;
-/*****************************************************************************
- * IStream interface
- */
-#ifndef __IStream_INTERFACE_DEFINED__
-#define __IStream_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IStream, 0x0000000c, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -3432,10 +3735,4 @@
 #endif  /* __IStream_INTERFACE_DEFINED__ */
 
-#ifndef __IEnumSTATSTG_FWD_DEFINED__
-#define __IEnumSTATSTG_FWD_DEFINED__
-typedef interface IEnumSTATSTG IEnumSTATSTG;
-#endif
-
-typedef IEnumSTATSTG *LPENUMSTATSTG;
 /*****************************************************************************
  * IEnumSTATSTG interface
@@ -3444,4 +3741,5 @@
 #define __IEnumSTATSTG_INTERFACE_DEFINED__
 
+typedef IEnumSTATSTG *LPENUMSTATSTG;
 DEFINE_GUID(IID_IEnumSTATSTG, 0x0000000d, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -3563,17 +3861,4 @@
 #endif  /* __IEnumSTATSTG_INTERFACE_DEFINED__ */
 
-#ifndef __IStorage_FWD_DEFINED__
-#define __IStorage_FWD_DEFINED__
-typedef interface IStorage IStorage;
-#endif
-
-typedef IStorage *LPSTORAGE;
-typedef struct tagRemSNB {
-    unsigned long ulCntStr;
-    unsigned long ulCntChar;
-    OLECHAR rgString[1];
-} RemSNB;
-typedef RemSNB *wireSNB;
-typedef OLECHAR **SNB;
 /*****************************************************************************
  * IStorage interface
@@ -3582,4 +3867,12 @@
 #define __IStorage_INTERFACE_DEFINED__
 
+typedef IStorage *LPSTORAGE;
+typedef struct tagRemSNB {
+    ULONG ulCntStr;
+    ULONG ulCntChar;
+    OLECHAR rgString[1];
+} RemSNB;
+typedef RemSNB *wireSNB;
+typedef OLECHAR **SNB;
 DEFINE_GUID(IID_IStorage, 0x0000000b, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -3818,5 +4111,5 @@
     IStorage* This,
     LPCOLESTR pwcsName,
-    unsigned long cbReserved1,
+    ULONG cbReserved1,
     byte *reserved1,
     DWORD grfMode,
@@ -3893,5 +4186,5 @@
     IStorage* This,
     DWORD reserved1,
-    unsigned long cbReserved2,
+    ULONG cbReserved2,
     byte *reserved2,
     DWORD reserved3,
@@ -3966,5 +4259,5 @@
     IStorage* This,
     LPCOLESTR pwcsName,
-    unsigned long cbReserved1,
+    ULONG cbReserved1,
     byte *reserved1,
     DWORD grfMode,
@@ -3980,5 +4273,5 @@
     IStorage* This,
     DWORD reserved1,
-    unsigned long cbReserved2,
+    ULONG cbReserved2,
     byte *reserved2,
     DWORD reserved3,
@@ -3987,10 +4280,4 @@
 #endif  /* __IStorage_INTERFACE_DEFINED__ */
 
-#ifndef __IPersistFile_FWD_DEFINED__
-#define __IPersistFile_FWD_DEFINED__
-typedef interface IPersistFile IPersistFile;
-#endif
-
-typedef IPersistFile *LPPERSISTFILE;
 /*****************************************************************************
  * IPersistFile interface
@@ -3999,4 +4286,5 @@
 #define __IPersistFile_INTERFACE_DEFINED__
 
+typedef IPersistFile *LPPERSISTFILE;
 DEFINE_GUID(IID_IPersistFile, 0x0000010b, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -4131,10 +4419,4 @@
 #endif  /* __IPersistFile_INTERFACE_DEFINED__ */
 
-#ifndef __IPersistStorage_FWD_DEFINED__
-#define __IPersistStorage_FWD_DEFINED__
-typedef interface IPersistStorage IPersistStorage;
-#endif
-
-typedef IPersistStorage *LPPERSISTSTORAGE;
 /*****************************************************************************
  * IPersistStorage interface
@@ -4143,4 +4425,5 @@
 #define __IPersistStorage_INTERFACE_DEFINED__
 
+typedef IPersistStorage *LPPERSISTSTORAGE;
 DEFINE_GUID(IID_IPersistStorage, 0x0000010a, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -4286,10 +4569,4 @@
 #endif  /* __IPersistStorage_INTERFACE_DEFINED__ */
 
-#ifndef __IRootStorage_FWD_DEFINED__
-#define __IRootStorage_FWD_DEFINED__
-typedef interface IRootStorage IRootStorage;
-#endif
-
-typedef IRootStorage *LPROOTSTORAGE;
 /*****************************************************************************
  * IRootStorage interface
@@ -4298,4 +4575,5 @@
 #define __IRootStorage_INTERFACE_DEFINED__
 
+typedef IRootStorage *LPROOTSTORAGE;
 DEFINE_GUID(IID_IRootStorage, 0x00000012, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -4355,10 +4633,4 @@
 #endif  /* __IRootStorage_INTERFACE_DEFINED__ */
 
-#ifndef __ILockBytes_FWD_DEFINED__
-#define __ILockBytes_FWD_DEFINED__
-typedef interface ILockBytes ILockBytes;
-#endif
-
-typedef ILockBytes *LPLOCKBYTES;
 /*****************************************************************************
  * ILockBytes interface
@@ -4367,4 +4639,5 @@
 #define __ILockBytes_INTERFACE_DEFINED__
 
+typedef ILockBytes *LPLOCKBYTES;
 DEFINE_GUID(IID_ILockBytes, 0x0000000a, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -4575,9 +4848,4 @@
 #endif  /* __ILockBytes_INTERFACE_DEFINED__ */
 
-#ifndef __IFillLockBytes_FWD_DEFINED__
-#define __IFillLockBytes_FWD_DEFINED__
-typedef interface IFillLockBytes IFillLockBytes;
-#endif
-
 /*****************************************************************************
  * IFillLockBytes interface
@@ -4728,9 +4996,4 @@
 #endif  /* __IFillLockBytes_INTERFACE_DEFINED__ */
 
-#ifndef __IProgressNotify_FWD_DEFINED__
-#define __IProgressNotify_FWD_DEFINED__
-typedef interface IProgressNotify IProgressNotify;
-#endif
-
 /*****************************************************************************
  * IProgressNotify interface
@@ -4805,8 +5068,9 @@
 #endif  /* __IProgressNotify_INTERFACE_DEFINED__ */
 
-#ifndef __ILayoutStorage_FWD_DEFINED__
-#define __ILayoutStorage_FWD_DEFINED__
-typedef interface ILayoutStorage ILayoutStorage;
-#endif
+/*****************************************************************************
+ * ILayoutStorage interface
+ */
+#ifndef __ILayoutStorage_INTERFACE_DEFINED__
+#define __ILayoutStorage_INTERFACE_DEFINED__
 
 typedef struct tagStorageLayout {
@@ -4816,10 +5080,4 @@
     LARGE_INTEGER cBytes;
 } StorageLayout;
-/*****************************************************************************
- * ILayoutStorage interface
- */
-#ifndef __ILayoutStorage_INTERFACE_DEFINED__
-#define __ILayoutStorage_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_ILayoutStorage, 0x0e6d4d90, 0x6738, 0x11cf, 0x96,0x08, 0x00,0xaa,0x00,0x68,0x0d,0xb4);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -4945,9 +5203,4 @@
 #endif  /* __ILayoutStorage_INTERFACE_DEFINED__ */
 
-#ifndef __IBlockingLock_FWD_DEFINED__
-#define __IBlockingLock_FWD_DEFINED__
-typedef interface IBlockingLock IBlockingLock;
-#endif
-
 /*****************************************************************************
  * IBlockingLock interface
@@ -5027,9 +5280,4 @@
 #endif  /* __IBlockingLock_INTERFACE_DEFINED__ */
 
-#ifndef __ITimeAndNoticeControl_FWD_DEFINED__
-#define __ITimeAndNoticeControl_FWD_DEFINED__
-typedef interface ITimeAndNoticeControl ITimeAndNoticeControl;
-#endif
-
 /*****************************************************************************
  * ITimeAndNoticeControl interface
@@ -5097,9 +5345,4 @@
 
 #endif  /* __ITimeAndNoticeControl_INTERFACE_DEFINED__ */
-
-#ifndef __IOplockStorage_FWD_DEFINED__
-#define __IOplockStorage_FWD_DEFINED__
-typedef interface IOplockStorage IOplockStorage;
-#endif
 
 /*****************************************************************************
@@ -5212,8 +5455,9 @@
 #endif  /* __IOplockStorage_INTERFACE_DEFINED__ */
 
-#ifndef __IEnumFORMATETC_FWD_DEFINED__
-#define __IEnumFORMATETC_FWD_DEFINED__
-typedef interface IEnumFORMATETC IEnumFORMATETC;
-#endif
+/*****************************************************************************
+ * IEnumFORMATETC interface
+ */
+#ifndef __IEnumFORMATETC_INTERFACE_DEFINED__
+#define __IEnumFORMATETC_INTERFACE_DEFINED__
 
 typedef IEnumFORMATETC *LPENUMFORMATETC;
@@ -5235,10 +5479,4 @@
 } FORMATETC;
 typedef struct tagFORMATETC *LPFORMATETC;
-/*****************************************************************************
- * IEnumFORMATETC interface
- */
-#ifndef __IEnumFORMATETC_INTERFACE_DEFINED__
-#define __IEnumFORMATETC_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IEnumFORMATETC, 0x00000103, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -5360,8 +5598,9 @@
 #endif  /* __IEnumFORMATETC_INTERFACE_DEFINED__ */
 
-#ifndef __IEnumSTATDATA_FWD_DEFINED__
-#define __IEnumSTATDATA_FWD_DEFINED__
-typedef interface IEnumSTATDATA IEnumSTATDATA;
-#endif
+/*****************************************************************************
+ * IEnumSTATDATA interface
+ */
+#ifndef __IEnumSTATDATA_INTERFACE_DEFINED__
+#define __IEnumSTATDATA_INTERFACE_DEFINED__
 
 typedef IEnumSTATDATA *LPENUMSTATDATA;
@@ -5382,10 +5621,4 @@
 } STATDATA;
 typedef struct tagSTATDATA *LPSTATDATA;
-/*****************************************************************************
- * IEnumSTATDATA interface
- */
-#ifndef __IEnumSTATDATA_INTERFACE_DEFINED__
-#define __IEnumSTATDATA_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IEnumSTATDATA, 0x00000105, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -5506,4 +5739,10 @@
 
 #endif  /* __IEnumSTATDATA_INTERFACE_DEFINED__ */
+
+/*****************************************************************************
+ * IAdviseSink interface
+ */
+#ifndef __IAdviseSink_INTERFACE_DEFINED__
+#define __IAdviseSink_INTERFACE_DEFINED__
 
 typedef IAdviseSink *LPADVISESINK;
@@ -5521,7 +5760,7 @@
     DWORD tymed;
     DWORD dwHandleType;
-    unsigned long pData;
-    unsigned long pUnkForRelease;
-    unsigned long cbData;
+    ULONG pData;
+    ULONG pUnkForRelease;
+    ULONG cbData;
     byte data[1];
 } RemSTGMEDIUM;
@@ -5568,20 +5807,14 @@
 typedef STGMEDIUM *LPSTGMEDIUM;
 typedef struct _userFLAG_STGMEDIUM {
-    long ContextFlags;
-    long fPassOwnership;
+    LONG ContextFlags;
+    LONG fPassOwnership;
     userSTGMEDIUM Stgmed;
 } userFLAG_STGMEDIUM;
 typedef userFLAG_STGMEDIUM *wireFLAG_STGMEDIUM;
 typedef struct _FLAG_STGMEDIUM {
-    long ContextFlags;
-    long fPassOwnership;
+    LONG ContextFlags;
+    LONG fPassOwnership;
     STGMEDIUM Stgmed;
 } FLAG_STGMEDIUM;
-/*****************************************************************************
- * IAdviseSink interface
- */
-#ifndef __IAdviseSink_INTERFACE_DEFINED__
-#define __IAdviseSink_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IAdviseSink, 0x0000010f, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -5737,10 +5970,4 @@
 #endif  /* __IAdviseSink_INTERFACE_DEFINED__ */
 
-#ifndef __IAdviseSink2_FWD_DEFINED__
-#define __IAdviseSink2_FWD_DEFINED__
-typedef interface IAdviseSink2 IAdviseSink2;
-#endif
-
-typedef IAdviseSink2 *LPADVISESINK2;
 /*****************************************************************************
  * IAdviseSink2 interface
@@ -5749,4 +5976,5 @@
 #define __IAdviseSink2_INTERFACE_DEFINED__
 
+typedef IAdviseSink2 *LPADVISESINK2;
 DEFINE_GUID(IID_IAdviseSink2, 0x00000125, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -5839,8 +6067,9 @@
 #endif  /* __IAdviseSink2_INTERFACE_DEFINED__ */
 
-#ifndef __IDataObject_FWD_DEFINED__
-#define __IDataObject_FWD_DEFINED__
-typedef interface IDataObject IDataObject;
-#endif
+/*****************************************************************************
+ * IDataObject interface
+ */
+#ifndef __IDataObject_INTERFACE_DEFINED__
+#define __IDataObject_INTERFACE_DEFINED__
 
 typedef IDataObject *LPDATAOBJECT;
@@ -5849,10 +6078,4 @@
     DATADIR_SET = 2
 } DATADIR;
-/*****************************************************************************
- * IDataObject interface
- */
-#ifndef __IDataObject_INTERFACE_DEFINED__
-#define __IDataObject_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IDataObject, 0x0000010e, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -6093,10 +6316,4 @@
 #endif  /* __IDataObject_INTERFACE_DEFINED__ */
 
-#ifndef __IDataAdviseHolder_FWD_DEFINED__
-#define __IDataAdviseHolder_FWD_DEFINED__
-typedef interface IDataAdviseHolder IDataAdviseHolder;
-#endif
-
-typedef IDataAdviseHolder *LPDATAADVISEHOLDER;
 /*****************************************************************************
  * IDataAdviseHolder interface
@@ -6105,4 +6322,5 @@
 #define __IDataAdviseHolder_INTERFACE_DEFINED__
 
+typedef IDataAdviseHolder *LPDATAADVISEHOLDER;
 DEFINE_GUID(IID_IDataAdviseHolder, 0x00000110, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -6228,8 +6446,9 @@
 #endif  /* __IDataAdviseHolder_INTERFACE_DEFINED__ */
 
-#ifndef __IMessageFilter_FWD_DEFINED__
-#define __IMessageFilter_FWD_DEFINED__
-typedef interface IMessageFilter IMessageFilter;
-#endif
+/*****************************************************************************
+ * IMessageFilter interface
+ */
+#ifndef __IMessageFilter_INTERFACE_DEFINED__
+#define __IMessageFilter_INTERFACE_DEFINED__
 
 typedef IMessageFilter *LPMESSAGEFILTER;
@@ -6261,10 +6480,4 @@
 } INTERFACEINFO;
 typedef struct tagINTERFACEINFO *LPINTERFACEINFO;
-/*****************************************************************************
- * IMessageFilter interface
- */
-#ifndef __IMessageFilter_INTERFACE_DEFINED__
-#define __IMessageFilter_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IMessageFilter, 0x00000016, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -6377,11 +6590,12 @@
 #endif  /* __IMessageFilter_INTERFACE_DEFINED__ */
 
-#ifndef __IRpcChannelBuffer_FWD_DEFINED__
-#define __IRpcChannelBuffer_FWD_DEFINED__
-typedef interface IRpcChannelBuffer IRpcChannelBuffer;
-#endif
+/*****************************************************************************
+ * IRpcChannelBuffer interface
+ */
+#ifndef __IRpcChannelBuffer_INTERFACE_DEFINED__
+#define __IRpcChannelBuffer_INTERFACE_DEFINED__
 
 typedef IRpcChannelBuffer *LPRPCCHANNELBUFFER;
-typedef unsigned long RPCOLEDATAREP;
+typedef ULONG RPCOLEDATAREP;
 typedef struct tagRPCOLEMESSAGE {
     void *reserved1;
@@ -6394,10 +6608,4 @@
 } RPCOLEMESSAGE;
 typedef RPCOLEMESSAGE *PRPCOLEMESSAGE;
-/*****************************************************************************
- * IRpcChannelBuffer interface
- */
-#ifndef __IRpcChannelBuffer_INTERFACE_DEFINED__
-#define __IRpcChannelBuffer_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IRpcChannelBuffer, 0xd5f56b60, 0x593b, 0x101a, 0xb5,0x69, 0x08,0x00,0x2b,0x2d,0xbf,0x7a);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -6528,10 +6736,4 @@
 #endif  /* __IRpcChannelBuffer_INTERFACE_DEFINED__ */
 
-#ifndef __IRpcChannelBuffer2_FWD_DEFINED__
-#define __IRpcChannelBuffer2_FWD_DEFINED__
-typedef interface IRpcChannelBuffer2 IRpcChannelBuffer2;
-#endif
-
-typedef IRpcChannelBuffer2 *LPRPCCHANNELBUFFER2;
 /*****************************************************************************
  * IRpcChannelBuffer2 interface
@@ -6540,4 +6742,5 @@
 #define __IRpcChannelBuffer2_INTERFACE_DEFINED__
 
+typedef IRpcChannelBuffer2 *LPRPCCHANNELBUFFER2;
 DEFINE_GUID(IID_IRpcChannelBuffer2, 0x594f31d0, 0x7f19, 0x11d0, 0xb1,0x94, 0x00,0xa0,0xc9,0x0d,0xc8,0xbf);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -6626,10 +6829,4 @@
 #endif  /* __IRpcChannelBuffer2_INTERFACE_DEFINED__ */
 
-#ifndef __IRpcChannelBuffer3_FWD_DEFINED__
-#define __IRpcChannelBuffer3_FWD_DEFINED__
-typedef interface IRpcChannelBuffer3 IRpcChannelBuffer3;
-#endif
-
-typedef IRpcChannelBuffer3 *LPRPCCHANNELBUFFER3;
 /*****************************************************************************
  * IRpcChannelBuffer3 interface
@@ -6638,4 +6835,5 @@
 #define __IRpcChannelBuffer3_INTERFACE_DEFINED__
 
+typedef IRpcChannelBuffer3 *LPRPCCHANNELBUFFER3;
 DEFINE_GUID(IID_IRpcChannelBuffer3, 0x25b15600, 0x0115, 0x11d0, 0xbf,0x0d, 0x00,0xaa,0x00,0xb8,0xdf,0xd2);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -6854,9 +7052,4 @@
 #endif  /* __IRpcChannelBuffer3_INTERFACE_DEFINED__ */
 
-#ifndef __IAsyncRpcChannelBuffer_FWD_DEFINED__
-#define __IAsyncRpcChannelBuffer_FWD_DEFINED__
-typedef interface IAsyncRpcChannelBuffer IAsyncRpcChannelBuffer;
-#endif
-
 /*****************************************************************************
  * IAsyncRpcChannelBuffer interface
@@ -7005,9 +7198,4 @@
 #endif  /* __IAsyncRpcChannelBuffer_INTERFACE_DEFINED__ */
 
-#ifndef __IRpcSyntaxNegotiate_FWD_DEFINED__
-#define __IRpcSyntaxNegotiate_FWD_DEFINED__
-typedef interface IRpcSyntaxNegotiate IRpcSyntaxNegotiate;
-#endif
-
 /*****************************************************************************
  * IRpcSyntaxNegotiate interface
@@ -7073,10 +7261,4 @@
 #endif  /* __IRpcSyntaxNegotiate_INTERFACE_DEFINED__ */
 
-#ifndef __IRpcProxyBuffer_FWD_DEFINED__
-#define __IRpcProxyBuffer_FWD_DEFINED__
-typedef interface IRpcProxyBuffer IRpcProxyBuffer;
-#endif
-
-typedef IRpcProxyBuffer *LPRPCPROXYBUFFER;
 /*****************************************************************************
  * IRpcProxyBuffer interface
@@ -7085,4 +7267,5 @@
 #define __IRpcProxyBuffer_INTERFACE_DEFINED__
 
+typedef IRpcProxyBuffer *LPRPCPROXYBUFFER;
 DEFINE_GUID(IID_IRpcProxyBuffer, 0xd5f56a34, 0x593b, 0x101a, 0xb5,0x69, 0x08,0x00,0x2b,0x2d,0xbf,0x7a);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -7156,10 +7339,4 @@
 #endif  /* __IRpcProxyBuffer_INTERFACE_DEFINED__ */
 
-#ifndef __IRpcStubBuffer_FWD_DEFINED__
-#define __IRpcStubBuffer_FWD_DEFINED__
-typedef interface IRpcStubBuffer IRpcStubBuffer;
-#endif
-
-typedef IRpcStubBuffer *LPRPCSTUBBUFFER;
 /*****************************************************************************
  * IRpcStubBuffer interface
@@ -7168,4 +7345,5 @@
 #define __IRpcStubBuffer_INTERFACE_DEFINED__
 
+typedef IRpcStubBuffer *LPRPCSTUBBUFFER;
 DEFINE_GUID(IID_IRpcStubBuffer, 0xd5f56afc, 0x593b, 0x101a, 0xb5,0x69, 0x08,0x00,0x2b,0x2d,0xbf,0x7a);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -7320,10 +7498,4 @@
 #endif  /* __IRpcStubBuffer_INTERFACE_DEFINED__ */
 
-#ifndef __IPSFactoryBuffer_FWD_DEFINED__
-#define __IPSFactoryBuffer_FWD_DEFINED__
-typedef interface IPSFactoryBuffer IPSFactoryBuffer;
-#endif
-
-typedef IPSFactoryBuffer *LPPSFACTORYBUFFER;
 /*****************************************************************************
  * IPSFactoryBuffer interface
@@ -7332,4 +7504,5 @@
 #define __IPSFactoryBuffer_INTERFACE_DEFINED__
 
+typedef IPSFactoryBuffer *LPPSFACTORYBUFFER;
 DEFINE_GUID(IID_IPSFactoryBuffer, 0xd5f569d0, 0x593b, 0x101a, 0xb5,0x69, 0x08,0x00,0x2b,0x2d,0xbf,0x7a);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -7420,8 +7593,9 @@
 #endif  /* __IPSFactoryBuffer_INTERFACE_DEFINED__ */
 
-#ifndef __IChannelHook_FWD_DEFINED__
-#define __IChannelHook_FWD_DEFINED__
-typedef interface IChannelHook IChannelHook;
-#endif
+/*****************************************************************************
+ * IChannelHook interface
+ */
+#ifndef __IChannelHook_INTERFACE_DEFINED__
+#define __IChannelHook_INTERFACE_DEFINED__
 
 typedef IChannelHook *LPCHANNELHOOK;
@@ -7434,10 +7608,4 @@
     void *pObject;
 } SChannelHookCallInfo;
-/*****************************************************************************
- * IChannelHook interface
- */
-#ifndef __IChannelHook_INTERFACE_DEFINED__
-#define __IChannelHook_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IChannelHook, 0x1008c4a0, 0x7613, 0x11cf, 0x9a,0xf1, 0x00,0x20,0xaf,0x6e,0x72,0xf4);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -7646,8 +7814,9 @@
 extern const FMTID FMTID_UserDefinedProperties;
 
-#ifndef __IClientSecurity_FWD_DEFINED__
-#define __IClientSecurity_FWD_DEFINED__
-typedef interface IClientSecurity IClientSecurity;
-#endif
+/*****************************************************************************
+ * IClientSecurity interface
+ */
+#ifndef __IClientSecurity_INTERFACE_DEFINED__
+#define __IClientSecurity_INTERFACE_DEFINED__
 
 typedef struct tagSOLE_AUTHENTICATION_SERVICE {
@@ -7684,10 +7853,4 @@
     EOAC_NO_CUSTOM_MARSHAL = 0x2000
 } EOLE_AUTHENTICATION_CAPABILITIES;
-/*****************************************************************************
- * IClientSecurity interface
- */
-#ifndef __IClientSecurity_INTERFACE_DEFINED__
-#define __IClientSecurity_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IClientSecurity, 0x0000013d, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -7824,9 +7987,4 @@
 #endif  /* __IClientSecurity_INTERFACE_DEFINED__ */
 
-#ifndef __IServerSecurity_FWD_DEFINED__
-#define __IServerSecurity_FWD_DEFINED__
-typedef interface IServerSecurity IServerSecurity;
-#endif
-
 /*****************************************************************************
  * IServerSecurity interface
@@ -7952,9 +8110,4 @@
 #endif  /* __IServerSecurity_INTERFACE_DEFINED__ */
 
-#ifndef __IAsyncSetup_FWD_DEFINED__
-#define __IAsyncSetup_FWD_DEFINED__
-typedef interface IAsyncSetup IAsyncSetup;
-#endif
-
 /*****************************************************************************
  * IAsyncSetup interface
@@ -8031,9 +8184,4 @@
 
 #endif  /* __IAsyncSetup_INTERFACE_DEFINED__ */
-
-#ifndef __IDirectWriterLock_FWD_DEFINED__
-#define __IDirectWriterLock_FWD_DEFINED__
-typedef interface IDirectWriterLock IDirectWriterLock;
-#endif
 
 /*****************************************************************************
@@ -8222,9 +8370,4 @@
 #endif  /* __ISynchronize_INTERFACE_DEFINED__ */
 
-#ifndef __ISynchronizeHandle_FWD_DEFINED__
-#define __ISynchronizeHandle_FWD_DEFINED__
-typedef interface ISynchronizeHandle ISynchronizeHandle;
-#endif
-
 /*****************************************************************************
  * ISynchronizeHandle interface
@@ -8289,9 +8432,4 @@
 
 #endif  /* __ISynchronizeHandle_INTERFACE_DEFINED__ */
-
-#ifndef __ISynchronizeEvent_FWD_DEFINED__
-#define __ISynchronizeEvent_FWD_DEFINED__
-typedef interface ISynchronizeEvent ISynchronizeEvent;
-#endif
 
 /*****************************************************************************
@@ -8365,9 +8503,4 @@
 #endif  /* __ISynchronizeEvent_INTERFACE_DEFINED__ */
 
-#ifndef __ISynchronizeContainer_FWD_DEFINED__
-#define __ISynchronizeContainer_FWD_DEFINED__
-typedef interface ISynchronizeContainer ISynchronizeContainer;
-#endif
-
 /*****************************************************************************
  * ISynchronizeContainer interface
@@ -8454,9 +8587,4 @@
 
 #endif  /* __ISynchronizeContainer_INTERFACE_DEFINED__ */
-
-#ifndef __ISynchronizeMutex_FWD_DEFINED__
-#define __ISynchronizeMutex_FWD_DEFINED__
-typedef interface ISynchronizeMutex ISynchronizeMutex;
-#endif
 
 /*****************************************************************************
@@ -8537,10 +8665,4 @@
 #endif  /* __ISynchronizeMutex_INTERFACE_DEFINED__ */
 
-#ifndef __ICancelMethodCalls_FWD_DEFINED__
-#define __ICancelMethodCalls_FWD_DEFINED__
-typedef interface ICancelMethodCalls ICancelMethodCalls;
-#endif
-
-typedef ICancelMethodCalls *LPCANCELMETHODCALLS;
 /*****************************************************************************
  * ICancelMethodCalls interface
@@ -8549,4 +8671,5 @@
 #define __ICancelMethodCalls_INTERFACE_DEFINED__
 
+typedef ICancelMethodCalls *LPCANCELMETHODCALLS;
 DEFINE_GUID(IID_ICancelMethodCalls, 0x00000029, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -8620,4 +8743,10 @@
 #endif  /* __ICancelMethodCalls_INTERFACE_DEFINED__ */
 
+/*****************************************************************************
+ * IAsyncManager interface
+ */
+#ifndef __IAsyncManager_INTERFACE_DEFINED__
+#define __IAsyncManager_INTERFACE_DEFINED__
+
 typedef enum tagDCOM_CALL_STATE {
     DCOM_NONE = 0,
@@ -8625,10 +8754,4 @@
     DCOM_CALL_CANCELED = 2
 } DCOM_CALL_STATE;
-/*****************************************************************************
- * IAsyncManager interface
- */
-#ifndef __IAsyncManager_INTERFACE_DEFINED__
-#define __IAsyncManager_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IAsyncManager, 0x0000002a, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -8723,9 +8846,4 @@
 #endif  /* __IAsyncManager_INTERFACE_DEFINED__ */
 
-#ifndef __ICallFactory_FWD_DEFINED__
-#define __ICallFactory_FWD_DEFINED__
-typedef interface ICallFactory ICallFactory;
-#endif
-
 /*****************************************************************************
  * ICallFactory interface
@@ -8799,9 +8917,4 @@
 
 #endif  /* __ICallFactory_INTERFACE_DEFINED__ */
-
-#ifndef __IRpcOptions_FWD_DEFINED__
-#define __IRpcOptions_FWD_DEFINED__
-typedef interface IRpcOptions IRpcOptions;
-#endif
 
 /*****************************************************************************
@@ -8907,9 +9020,4 @@
 };
 
-#ifndef __IRpcHelper_FWD_DEFINED__
-#define __IRpcHelper_FWD_DEFINED__
-typedef interface IRpcHelper IRpcHelper;
-#endif
-
 /*****************************************************************************
  * IRpcHelper interface
@@ -8994,9 +9102,4 @@
 #endif  /* __IRpcHelper_INTERFACE_DEFINED__ */
 
-#ifndef __IReleaseMarshalBuffers_FWD_DEFINED__
-#define __IReleaseMarshalBuffers_FWD_DEFINED__
-typedef interface IReleaseMarshalBuffers IReleaseMarshalBuffers;
-#endif
-
 /*****************************************************************************
  * IReleaseMarshalBuffers interface
@@ -9068,9 +9171,4 @@
 #endif  /* __IReleaseMarshalBuffers_INTERFACE_DEFINED__ */
 
-#ifndef __IWaitMultiple_FWD_DEFINED__
-#define __IWaitMultiple_FWD_DEFINED__
-typedef interface IWaitMultiple IWaitMultiple;
-#endif
-
 /*****************************************************************************
  * IWaitMultiple interface
@@ -9154,9 +9252,4 @@
 
 #endif  /* __IWaitMultiple_INTERFACE_DEFINED__ */
-
-#ifndef __IUrlMon_FWD_DEFINED__
-#define __IUrlMon_FWD_DEFINED__
-typedef interface IUrlMon IUrlMon;
-#endif
 
 /*****************************************************************************
@@ -9250,9 +9343,4 @@
 #endif  /* __IUrlMon_INTERFACE_DEFINED__ */
 
-#ifndef __IForegroundTransfer_FWD_DEFINED__
-#define __IForegroundTransfer_FWD_DEFINED__
-typedef interface IForegroundTransfer IForegroundTransfer;
-#endif
-
 /*****************************************************************************
  * IForegroundTransfer interface
@@ -9318,10 +9406,4 @@
 #endif  /* __IForegroundTransfer_INTERFACE_DEFINED__ */
 
-#ifndef __IAddrTrackingControl_FWD_DEFINED__
-#define __IAddrTrackingControl_FWD_DEFINED__
-typedef interface IAddrTrackingControl IAddrTrackingControl;
-#endif
-
-typedef IAddrTrackingControl *LPADDRTRACKINGCONTROL;
 /*****************************************************************************
  * IAddrTrackingControl interface
@@ -9330,4 +9412,5 @@
 #define __IAddrTrackingControl_INTERFACE_DEFINED__
 
+typedef IAddrTrackingControl *LPADDRTRACKINGCONTROL;
 DEFINE_GUID(IID_IAddrTrackingControl, 0x00000147, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -9399,10 +9482,4 @@
 #endif  /* __IAddrTrackingControl_INTERFACE_DEFINED__ */
 
-#ifndef __IAddrExclusionControl_FWD_DEFINED__
-#define __IAddrExclusionControl_FWD_DEFINED__
-typedef interface IAddrExclusionControl IAddrExclusionControl;
-#endif
-
-typedef IAddrExclusionControl *LPADDREXCLUSIONCONTROL;
 /*****************************************************************************
  * IAddrExclusionControl interface
@@ -9411,4 +9488,5 @@
 #define __IAddrExclusionControl_INTERFACE_DEFINED__
 
+typedef IAddrExclusionControl *LPADDREXCLUSIONCONTROL;
 DEFINE_GUID(IID_IAddrExclusionControl, 0x00000148, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -9498,9 +9576,4 @@
     THDTYPE_PROCESSMESSAGES = 1
 } THDTYPE;
-#ifndef __IComThreadingInfo_FWD_DEFINED__
-#define __IComThreadingInfo_FWD_DEFINED__
-typedef interface IComThreadingInfo IComThreadingInfo;
-#endif
-
 /*****************************************************************************
  * IComThreadingInfo interface
@@ -9614,9 +9687,4 @@
 #endif  /* __IComThreadingInfo_INTERFACE_DEFINED__ */
 
-#ifndef __IProcessInitControl_FWD_DEFINED__
-#define __IProcessInitControl_FWD_DEFINED__
-typedef interface IProcessInitControl IProcessInitControl;
-#endif
-
 /*****************************************************************************
  * IProcessInitControl interface
@@ -9682,10 +9750,4 @@
 #endif  /* __IProcessInitControl_INTERFACE_DEFINED__ */
 
-#ifndef __IInitializeSpy_FWD_DEFINED__
-#define __IInitializeSpy_FWD_DEFINED__
-typedef interface IInitializeSpy IInitializeSpy;
-#endif
-
-typedef IInitializeSpy *LPINITIALIZESPY;
 /*****************************************************************************
  * IInitializeSpy interface
@@ -9694,4 +9756,5 @@
 #define __IInitializeSpy_INTERFACE_DEFINED__
 
+typedef IInitializeSpy *LPINITIALIZESPY;
 DEFINE_GUID(IID_IInitializeSpy, 0x00000034, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -9807,9 +9870,4 @@
 
 #endif  /* __IInitializeSpy_INTERFACE_DEFINED__ */
-
-#ifndef __IThumbnailExtractor_FWD_DEFINED__
-#define __IThumbnailExtractor_FWD_DEFINED__
-typedef interface IThumbnailExtractor IThumbnailExtractor;
-#endif
 
 /*****************************************************************************
@@ -9914,10 +9972,4 @@
     IUnknown *pUnk;
 } ContextProperty;
-#ifndef __IEnumContextProps_FWD_DEFINED__
-#define __IEnumContextProps_FWD_DEFINED__
-typedef interface IEnumContextProps IEnumContextProps;
-#endif
-
-typedef IEnumContextProps *LPENUMCONTEXTPROPS;
 /*****************************************************************************
  * IEnumContextProps interface
@@ -9926,4 +9978,5 @@
 #define __IEnumContextProps_INTERFACE_DEFINED__
 
+typedef IEnumContextProps *LPENUMCONTEXTPROPS;
 DEFINE_GUID(IID_IEnumContextProps, 0x000001c1, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -10051,9 +10104,4 @@
 #endif  /* __IEnumContextProps_INTERFACE_DEFINED__ */
 
-#ifndef __IContext_FWD_DEFINED__
-#define __IContext_FWD_DEFINED__
-typedef interface IContext IContext;
-#endif
-
 /*****************************************************************************
  * IContext interface
@@ -10178,4 +10226,175 @@
 
 #endif  /* __IContext_INTERFACE_DEFINED__ */
+
+/*****************************************************************************
+ * IObjContext interface
+ */
+#ifndef __IObjContext_INTERFACE_DEFINED__
+#define __IObjContext_INTERFACE_DEFINED__
+
+DEFINE_GUID(IID_IObjContext, 0x000001c6, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
+#if defined(__cplusplus) && !defined(CINTERFACE)
+interface IObjContext : public IContext
+{
+    virtual void STDMETHODCALLTYPE Reserved1(
+        ) = 0;
+
+    virtual void STDMETHODCALLTYPE Reserved2(
+        ) = 0;
+
+    virtual void STDMETHODCALLTYPE Reserved3(
+        ) = 0;
+
+    virtual void STDMETHODCALLTYPE Reserved4(
+        ) = 0;
+
+    virtual void STDMETHODCALLTYPE Reserved5(
+        ) = 0;
+
+    virtual void STDMETHODCALLTYPE Reserved6(
+        ) = 0;
+
+    virtual void STDMETHODCALLTYPE Reserved7(
+        ) = 0;
+
+};
+#else
+typedef struct IObjContextVtbl {
+    BEGIN_INTERFACE
+
+    /*** IUnknown methods ***/
+    HRESULT (STDMETHODCALLTYPE *QueryInterface)(
+        IObjContext* This,
+        REFIID riid,
+        void **ppvObject);
+
+    ULONG (STDMETHODCALLTYPE *AddRef)(
+        IObjContext* This);
+
+    ULONG (STDMETHODCALLTYPE *Release)(
+        IObjContext* This);
+
+    /*** IContext methods ***/
+    HRESULT (STDMETHODCALLTYPE *SetProperty)(
+        IObjContext* This,
+        REFGUID policyId,
+        CPFLAGS flags,
+        IUnknown *pUnk);
+
+    HRESULT (STDMETHODCALLTYPE *RemoveProperty)(
+        IObjContext* This,
+        REFGUID policyId);
+
+    HRESULT (STDMETHODCALLTYPE *GetProperty)(
+        IObjContext* This,
+        REFGUID guid,
+        CPFLAGS *pFlags,
+        IUnknown **ppUnk);
+
+    HRESULT (STDMETHODCALLTYPE *EnumContextProps)(
+        IObjContext* This,
+        IEnumContextProps **ppEnumContextProps);
+
+    /*** IObjContext methods ***/
+    void (STDMETHODCALLTYPE *Reserved1)(
+        IObjContext* This);
+
+    void (STDMETHODCALLTYPE *Reserved2)(
+        IObjContext* This);
+
+    void (STDMETHODCALLTYPE *Reserved3)(
+        IObjContext* This);
+
+    void (STDMETHODCALLTYPE *Reserved4)(
+        IObjContext* This);
+
+    void (STDMETHODCALLTYPE *Reserved5)(
+        IObjContext* This);
+
+    void (STDMETHODCALLTYPE *Reserved6)(
+        IObjContext* This);
+
+    void (STDMETHODCALLTYPE *Reserved7)(
+        IObjContext* This);
+
+    END_INTERFACE
+} IObjContextVtbl;
+interface IObjContext {
+    CONST_VTBL IObjContextVtbl* lpVtbl;
+};
+
+#ifdef COBJMACROS
+/*** IUnknown methods ***/
+#define IObjContext_QueryInterface(This,riid,ppvObject) (This)->lpVtbl->QueryInterface(This,riid,ppvObject)
+#define IObjContext_AddRef(This) (This)->lpVtbl->AddRef(This)
+#define IObjContext_Release(This) (This)->lpVtbl->Release(This)
+/*** IContext methods ***/
+#define IObjContext_SetProperty(This,policyId,flags,pUnk) (This)->lpVtbl->SetProperty(This,policyId,flags,pUnk)
+#define IObjContext_RemoveProperty(This,policyId) (This)->lpVtbl->RemoveProperty(This,policyId)
+#define IObjContext_GetProperty(This,guid,pFlags,ppUnk) (This)->lpVtbl->GetProperty(This,guid,pFlags,ppUnk)
+#define IObjContext_EnumContextProps(This,ppEnumContextProps) (This)->lpVtbl->EnumContextProps(This,ppEnumContextProps)
+/*** IObjContext methods ***/
+#define IObjContext_Reserved1(This) (This)->lpVtbl->Reserved1(This)
+#define IObjContext_Reserved2(This) (This)->lpVtbl->Reserved2(This)
+#define IObjContext_Reserved3(This) (This)->lpVtbl->Reserved3(This)
+#define IObjContext_Reserved4(This) (This)->lpVtbl->Reserved4(This)
+#define IObjContext_Reserved5(This) (This)->lpVtbl->Reserved5(This)
+#define IObjContext_Reserved6(This) (This)->lpVtbl->Reserved6(This)
+#define IObjContext_Reserved7(This) (This)->lpVtbl->Reserved7(This)
+#endif
+
+#endif
+
+void STDMETHODCALLTYPE IObjContext_Reserved1_Proxy(
+    IObjContext* This);
+void __RPC_STUB IObjContext_Reserved1_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+void STDMETHODCALLTYPE IObjContext_Reserved2_Proxy(
+    IObjContext* This);
+void __RPC_STUB IObjContext_Reserved2_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+void STDMETHODCALLTYPE IObjContext_Reserved3_Proxy(
+    IObjContext* This);
+void __RPC_STUB IObjContext_Reserved3_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+void STDMETHODCALLTYPE IObjContext_Reserved4_Proxy(
+    IObjContext* This);
+void __RPC_STUB IObjContext_Reserved4_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+void STDMETHODCALLTYPE IObjContext_Reserved5_Proxy(
+    IObjContext* This);
+void __RPC_STUB IObjContext_Reserved5_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+void STDMETHODCALLTYPE IObjContext_Reserved6_Proxy(
+    IObjContext* This);
+void __RPC_STUB IObjContext_Reserved6_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+void STDMETHODCALLTYPE IObjContext_Reserved7_Proxy(
+    IObjContext* This);
+void __RPC_STUB IObjContext_Reserved7_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+
+#endif  /* __IObjContext_INTERFACE_DEFINED__ */
 
 #endif /* defined USE_COM_CONTEXT_DEF */
@@ -10198,24 +10417,12 @@
 unsigned char * __RPC_USER ASYNC_STGMEDIUM_UserUnmarshal(ULONG *, unsigned char *, ASYNC_STGMEDIUM *);
 void            __RPC_USER ASYNC_STGMEDIUM_UserFree     (ULONG *, ASYNC_STGMEDIUM *);
+ULONG           __RPC_USER FLAG_STGMEDIUM_UserSize     (ULONG *, ULONG, FLAG_STGMEDIUM *);
+unsigned char * __RPC_USER FLAG_STGMEDIUM_UserMarshal  (ULONG *, unsigned char *, FLAG_STGMEDIUM *);
+unsigned char * __RPC_USER FLAG_STGMEDIUM_UserUnmarshal(ULONG *, unsigned char *, FLAG_STGMEDIUM *);
+void            __RPC_USER FLAG_STGMEDIUM_UserFree     (ULONG *, FLAG_STGMEDIUM *);
 ULONG           __RPC_USER HBITMAP_UserSize     (ULONG *, ULONG, HBITMAP *);
 unsigned char * __RPC_USER HBITMAP_UserMarshal  (ULONG *, unsigned char *, HBITMAP *);
 unsigned char * __RPC_USER HBITMAP_UserUnmarshal(ULONG *, unsigned char *, HBITMAP *);
 void            __RPC_USER HBITMAP_UserFree     (ULONG *, HBITMAP *);
-ULONG           __RPC_USER HMETAFILEPICT_UserSize     (ULONG *, ULONG, HMETAFILEPICT *);
-unsigned char * __RPC_USER HMETAFILEPICT_UserMarshal  (ULONG *, unsigned char *, HMETAFILEPICT *);
-unsigned char * __RPC_USER HMETAFILEPICT_UserUnmarshal(ULONG *, unsigned char *, HMETAFILEPICT *);
-void            __RPC_USER HMETAFILEPICT_UserFree     (ULONG *, HMETAFILEPICT *);
-ULONG           __RPC_USER HENHMETAFILE_UserSize     (ULONG *, ULONG, HENHMETAFILE *);
-unsigned char * __RPC_USER HENHMETAFILE_UserMarshal  (ULONG *, unsigned char *, HENHMETAFILE *);
-unsigned char * __RPC_USER HENHMETAFILE_UserUnmarshal(ULONG *, unsigned char *, HENHMETAFILE *);
-void            __RPC_USER HENHMETAFILE_UserFree     (ULONG *, HENHMETAFILE *);
-ULONG           __RPC_USER HGLOBAL_UserSize     (ULONG *, ULONG, HGLOBAL *);
-unsigned char * __RPC_USER HGLOBAL_UserMarshal  (ULONG *, unsigned char *, HGLOBAL *);
-unsigned char * __RPC_USER HGLOBAL_UserUnmarshal(ULONG *, unsigned char *, HGLOBAL *);
-void            __RPC_USER HGLOBAL_UserFree     (ULONG *, HGLOBAL *);
-ULONG           __RPC_USER FLAG_STGMEDIUM_UserSize     (ULONG *, ULONG, FLAG_STGMEDIUM *);
-unsigned char * __RPC_USER FLAG_STGMEDIUM_UserMarshal  (ULONG *, unsigned char *, FLAG_STGMEDIUM *);
-unsigned char * __RPC_USER FLAG_STGMEDIUM_UserUnmarshal(ULONG *, unsigned char *, FLAG_STGMEDIUM *);
-void            __RPC_USER FLAG_STGMEDIUM_UserFree     (ULONG *, FLAG_STGMEDIUM *);
 
 /* End additional prototypes */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.idl	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/objidl.idl	(revision 21731)
@@ -2464,3 +2464,20 @@
 }
 
+[
+    local,
+    object,
+    uuid(000001c6-0000-0000-c000-000000000046),
+    pointer_default(unique)
+]
+interface IObjContext : IContext
+{
+    void Reserved1();
+    void Reserved2();
+    void Reserved3();
+    void Reserved4();
+    void Reserved5();
+    void Reserved6();
+    void Reserved7();
+}
+
 cpp_quote("#endif /* defined USE_COM_CONTEXT_DEF */")
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oleidl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oleidl.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/oleidl.h	(revision 21731)
@@ -1,3 +1,4 @@
-/*** Autogenerated by WIDL 1.1.23 from ../../../dlls/wined3d/../../include/oleidl.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.26 from ../../include/oleidl.idl - Do not edit ***/
+
 #include <rpc.h>
 #include <rpcndr.h>
@@ -5,9 +6,35 @@
 #ifndef __WIDL_OLEIDL_H
 #define __WIDL_OLEIDL_H
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+/* Headers for imported files */
+
 #include <objidl.h>
+
+/* Forward declarations */
+
+#ifndef __IOleWindow_FWD_DEFINED__
+#define __IOleWindow_FWD_DEFINED__
+typedef interface IOleWindow IOleWindow;
+#endif
+
+#ifndef __IOleInPlaceObject_FWD_DEFINED__
+#define __IOleInPlaceObject_FWD_DEFINED__
+typedef interface IOleInPlaceObject IOleInPlaceObject;
+#endif
+
+#ifndef __IOleInPlaceUIWindow_FWD_DEFINED__
+#define __IOleInPlaceUIWindow_FWD_DEFINED__
+typedef interface IOleInPlaceUIWindow IOleInPlaceUIWindow;
+#endif
+
+#ifndef __IOleInPlaceFrame_FWD_DEFINED__
+#define __IOleInPlaceFrame_FWD_DEFINED__
+typedef interface IOleInPlaceFrame IOleInPlaceFrame;
+#endif
+
 #ifndef __IOleInPlaceActiveObject_FWD_DEFINED__
 #define __IOleInPlaceActiveObject_FWD_DEFINED__
@@ -15,4 +42,107 @@
 #endif
 
+#ifndef __IOleInPlaceSite_FWD_DEFINED__
+#define __IOleInPlaceSite_FWD_DEFINED__
+typedef interface IOleInPlaceSite IOleInPlaceSite;
+#endif
+
+#ifndef __IParseDisplayName_FWD_DEFINED__
+#define __IParseDisplayName_FWD_DEFINED__
+typedef interface IParseDisplayName IParseDisplayName;
+#endif
+
+#ifndef __IOleContainer_FWD_DEFINED__
+#define __IOleContainer_FWD_DEFINED__
+typedef interface IOleContainer IOleContainer;
+#endif
+
+#ifndef __IOleItemContainer_FWD_DEFINED__
+#define __IOleItemContainer_FWD_DEFINED__
+typedef interface IOleItemContainer IOleItemContainer;
+#endif
+
+#ifndef __IOleLink_FWD_DEFINED__
+#define __IOleLink_FWD_DEFINED__
+typedef interface IOleLink IOleLink;
+#endif
+
+#ifndef __IOleClientSite_FWD_DEFINED__
+#define __IOleClientSite_FWD_DEFINED__
+typedef interface IOleClientSite IOleClientSite;
+#endif
+
+#ifndef __IOleCache_FWD_DEFINED__
+#define __IOleCache_FWD_DEFINED__
+typedef interface IOleCache IOleCache;
+#endif
+
+#ifndef __IOleCache2_FWD_DEFINED__
+#define __IOleCache2_FWD_DEFINED__
+typedef interface IOleCache2 IOleCache2;
+#endif
+
+#ifndef __IOleCacheControl_FWD_DEFINED__
+#define __IOleCacheControl_FWD_DEFINED__
+typedef interface IOleCacheControl IOleCacheControl;
+#endif
+
+#ifndef __IEnumOLEVERB_FWD_DEFINED__
+#define __IEnumOLEVERB_FWD_DEFINED__
+typedef interface IEnumOLEVERB IEnumOLEVERB;
+#endif
+
+#ifndef __IOleObject_FWD_DEFINED__
+#define __IOleObject_FWD_DEFINED__
+typedef interface IOleObject IOleObject;
+#endif
+
+#ifndef __IOleAdviseHolder_FWD_DEFINED__
+#define __IOleAdviseHolder_FWD_DEFINED__
+typedef interface IOleAdviseHolder IOleAdviseHolder;
+#endif
+
+#ifndef __IContinue_FWD_DEFINED__
+#define __IContinue_FWD_DEFINED__
+typedef interface IContinue IContinue;
+#endif
+
+#ifndef __IViewObject_FWD_DEFINED__
+#define __IViewObject_FWD_DEFINED__
+typedef interface IViewObject IViewObject;
+#endif
+
+#ifndef __IViewObject2_FWD_DEFINED__
+#define __IViewObject2_FWD_DEFINED__
+typedef interface IViewObject2 IViewObject2;
+#endif
+
+#ifndef __IDropSource_FWD_DEFINED__
+#define __IDropSource_FWD_DEFINED__
+typedef interface IDropSource IDropSource;
+#endif
+
+#ifndef __IDropTarget_FWD_DEFINED__
+#define __IDropTarget_FWD_DEFINED__
+typedef interface IDropTarget IDropTarget;
+#endif
+
+
+#ifndef __IOleInPlaceActiveObject_FWD_DEFINED__
+#define __IOleInPlaceActiveObject_FWD_DEFINED__
+typedef interface IOleInPlaceActiveObject IOleInPlaceActiveObject;
+#endif
+
+#include <winuser.h>
+void * __RPC_USER MIDL_user_allocate(SIZE_T);
+void __RPC_USER MIDL_user_free(void *);
+
+/*****************************************************************************
+ * IOLETypes interface (v0.0)
+ */
+#ifndef __IOLETypes_INTERFACE_DEFINED__
+#define __IOLETypes_INTERFACE_DEFINED__
+
+extern RPC_IF_HANDLE IOLETypes_v0_0_c_ifspec;
+extern RPC_IF_HANDLE IOLETypes_v0_0_s_ifspec;
 typedef enum tagOLERENDER {
     OLERENDER_NONE = 0,
@@ -37,24 +167,7 @@
 typedef struct tagOBJECTDESCRIPTOR *PLINKSRCDESCRIPTOR;
 typedef struct tagOBJECTDESCRIPTOR *LPLINKSRCDESCRIPTOR;
-void * __RPC_USER MIDL_user_allocate(size_t);
-void __RPC_USER MIDL_user_free(void *);
-
-/*****************************************************************************
- * IOLETypes interface (v0.0)
- */
-#ifndef __IOLETypes_INTERFACE_DEFINED__
-#define __IOLETypes_INTERFACE_DEFINED__
-
-extern RPC_IF_HANDLE IOLETypes_v0_0_c_ifspec;
-extern RPC_IF_HANDLE IOLETypes_v0_0_s_ifspec;
 
 #endif  /* __IOLETypes_INTERFACE_DEFINED__ */
 
-#ifndef __IOleWindow_FWD_DEFINED__
-#define __IOleWindow_FWD_DEFINED__
-typedef interface IOleWindow IOleWindow;
-#endif
-
-typedef IOleWindow *LPOLEWINDOW;
 /*****************************************************************************
  * IOleWindow interface
@@ -63,4 +176,5 @@
 #define __IOleWindow_INTERFACE_DEFINED__
 
+typedef IOleWindow *LPOLEWINDOW;
 DEFINE_GUID(IID_IOleWindow, 0x00000114, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -136,10 +250,4 @@
 #endif  /* __IOleWindow_INTERFACE_DEFINED__ */
 
-#ifndef __IOleInPlaceObject_FWD_DEFINED__
-#define __IOleInPlaceObject_FWD_DEFINED__
-typedef interface IOleInPlaceObject IOleInPlaceObject;
-#endif
-
-typedef IOleInPlaceObject *LPOLEINPLACEOBJECT;
 /*****************************************************************************
  * IOleInPlaceObject interface
@@ -148,4 +256,5 @@
 #define __IOleInPlaceObject_INTERFACE_DEFINED__
 
+typedef IOleInPlaceObject *LPOLEINPLACEOBJECT;
 DEFINE_GUID(IID_IOleInPlaceObject, 0x00000113, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -262,13 +371,4 @@
 #endif  /* __IOleInPlaceObject_INTERFACE_DEFINED__ */
 
-#ifndef __IOleInPlaceUIWindow_FWD_DEFINED__
-#define __IOleInPlaceUIWindow_FWD_DEFINED__
-typedef interface IOleInPlaceUIWindow IOleInPlaceUIWindow;
-#endif
-
-typedef IOleInPlaceUIWindow *LPOLEINPLACEUIWINDOW;
-typedef RECT BORDERWIDTHS;
-typedef LPRECT LPBORDERWIDTHS;
-typedef LPCRECT LPCBORDERWIDTHS;
 /*****************************************************************************
  * IOleInPlaceUIWindow interface
@@ -277,4 +377,8 @@
 #define __IOleInPlaceUIWindow_INTERFACE_DEFINED__
 
+typedef IOleInPlaceUIWindow *LPOLEINPLACEUIWINDOW;
+typedef RECT BORDERWIDTHS;
+typedef LPRECT LPBORDERWIDTHS;
+typedef LPCRECT LPCBORDERWIDTHS;
 DEFINE_GUID(IID_IOleInPlaceUIWindow, 0x00000115, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -400,8 +504,9 @@
 #undef TranslateAccelerator
 #endif
-#ifndef __IOleInPlaceFrame_FWD_DEFINED__
-#define __IOleInPlaceFrame_FWD_DEFINED__
-typedef interface IOleInPlaceFrame IOleInPlaceFrame;
-#endif
+/*****************************************************************************
+ * IOleInPlaceFrame interface
+ */
+#ifndef __IOleInPlaceFrame_INTERFACE_DEFINED__
+#define __IOleInPlaceFrame_INTERFACE_DEFINED__
 
 typedef IOleInPlaceFrame *LPOLEINPLACEFRAME;
@@ -419,10 +524,4 @@
 typedef struct tagOleMenuGroupWidths *LPOLEMENUGROUPWIDTHS;
 typedef HGLOBAL HOLEMENU;
-/*****************************************************************************
- * IOleInPlaceFrame interface
- */
-#ifndef __IOleInPlaceFrame_INTERFACE_DEFINED__
-#define __IOleInPlaceFrame_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IOleInPlaceFrame, 0x00000116, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -609,5 +708,4 @@
 #endif  /* __IOleInPlaceFrame_INTERFACE_DEFINED__ */
 
-typedef IOleInPlaceActiveObject *LPOLEINPLACEACTIVEOBJECT;
 /*****************************************************************************
  * IOleInPlaceActiveObject interface
@@ -616,4 +714,5 @@
 #define __IOleInPlaceActiveObject_INTERFACE_DEFINED__
 
+typedef IOleInPlaceActiveObject *LPOLEINPLACEACTIVEOBJECT;
 DEFINE_GUID(IID_IOleInPlaceActiveObject, 0x00000117, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -771,10 +870,4 @@
 #endif  /* __IOleInPlaceActiveObject_INTERFACE_DEFINED__ */
 
-#ifndef __IOleInPlaceSite_FWD_DEFINED__
-#define __IOleInPlaceSite_FWD_DEFINED__
-typedef interface IOleInPlaceSite IOleInPlaceSite;
-#endif
-
-typedef IOleInPlaceSite *LPOLEINPLACESITE;
 /*****************************************************************************
  * IOleInPlaceSite interface
@@ -783,4 +876,5 @@
 #define __IOleInPlaceSite_INTERFACE_DEFINED__
 
+typedef IOleInPlaceSite *LPOLEINPLACESITE;
 DEFINE_GUID(IID_IOleInPlaceSite, 0x00000119, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -996,10 +1090,4 @@
 #endif  /* __IOleInPlaceSite_INTERFACE_DEFINED__ */
 
-#ifndef __IParseDisplayName_FWD_DEFINED__
-#define __IParseDisplayName_FWD_DEFINED__
-typedef interface IParseDisplayName IParseDisplayName;
-#endif
-
-typedef IParseDisplayName *LPPARSEDISPLAYNAME;
 /*****************************************************************************
  * IParseDisplayName interface
@@ -1008,4 +1096,5 @@
 #define __IParseDisplayName_INTERFACE_DEFINED__
 
+typedef IParseDisplayName *LPPARSEDISPLAYNAME;
 DEFINE_GUID(IID_IParseDisplayName, 0x0000011a, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1074,10 +1163,4 @@
 #endif  /* __IParseDisplayName_INTERFACE_DEFINED__ */
 
-#ifndef __IOleContainer_FWD_DEFINED__
-#define __IOleContainer_FWD_DEFINED__
-typedef interface IOleContainer IOleContainer;
-#endif
-
-typedef IOleContainer *LPOLECONTAINER;
 /*****************************************************************************
  * IOleContainer interface
@@ -1086,4 +1169,5 @@
 #define __IOleContainer_INTERFACE_DEFINED__
 
+typedef IOleContainer *LPOLECONTAINER;
 DEFINE_GUID(IID_IOleContainer, 0x0000011b, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1172,8 +1256,9 @@
 #endif  /* __IOleContainer_INTERFACE_DEFINED__ */
 
-#ifndef __IOleItemContainer_FWD_DEFINED__
-#define __IOleItemContainer_FWD_DEFINED__
-typedef interface IOleItemContainer IOleItemContainer;
-#endif
+/*****************************************************************************
+ * IOleItemContainer interface
+ */
+#ifndef __IOleItemContainer_INTERFACE_DEFINED__
+#define __IOleItemContainer_INTERFACE_DEFINED__
 
 typedef IOleItemContainer *LPOLEITEMCONTAINER;
@@ -1193,10 +1278,4 @@
 #undef GetObject
 #endif
-/*****************************************************************************
- * IOleItemContainer interface
- */
-#ifndef __IOleItemContainer_INTERFACE_DEFINED__
-#define __IOleItemContainer_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IOleItemContainer, 0x0000011c, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1332,8 +1411,9 @@
 #endif  /* __IOleItemContainer_INTERFACE_DEFINED__ */
 
-#ifndef __IOleLink_FWD_DEFINED__
-#define __IOleLink_FWD_DEFINED__
-typedef interface IOleLink IOleLink;
-#endif
+/*****************************************************************************
+ * IOleLink interface
+ */
+#ifndef __IOleLink_INTERFACE_DEFINED__
+#define __IOleLink_INTERFACE_DEFINED__
 
 typedef IOleLink *LPOLELINK;
@@ -1347,10 +1427,4 @@
     OLELINKBIND_EVENIFCLASSDIFF = 1
 } OLELINKBIND;
-/*****************************************************************************
- * IOleLink interface
- */
-#ifndef __IOleLink_INTERFACE_DEFINED__
-#define __IOleLink_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IOleLink, 0x0000011d, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1572,10 +1646,4 @@
 #endif  /* __IOleLink_INTERFACE_DEFINED__ */
 
-#ifndef __IOleClientSite_FWD_DEFINED__
-#define __IOleClientSite_FWD_DEFINED__
-typedef interface IOleClientSite IOleClientSite;
-#endif
-
-typedef IOleClientSite *LPOLECLIENTSITE;
 /*****************************************************************************
  * IOleClientSite interface
@@ -1584,4 +1652,5 @@
 #define __IOleClientSite_INTERFACE_DEFINED__
 
+typedef IOleClientSite *LPOLECLIENTSITE;
 DEFINE_GUID(IID_IOleClientSite, 0x00000118, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1721,10 +1790,4 @@
 #endif  /* __IOleClientSite_INTERFACE_DEFINED__ */
 
-#ifndef __IOleCache_FWD_DEFINED__
-#define __IOleCache_FWD_DEFINED__
-typedef interface IOleCache IOleCache;
-#endif
-
-typedef IOleCache *LPOLECACHE;
 /*****************************************************************************
  * IOleCache interface
@@ -1733,4 +1796,5 @@
 #define __IOleCache_INTERFACE_DEFINED__
 
+typedef IOleCache *LPOLECACHE;
 DEFINE_GUID(IID_IOleCache, 0x0000011e, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -1866,32 +1930,4 @@
 #endif  /* __IOleCache_INTERFACE_DEFINED__ */
 
-#ifndef __IOleCache2_FWD_DEFINED__
-#define __IOleCache2_FWD_DEFINED__
-typedef interface IOleCache2 IOleCache2;
-#endif
-
-typedef IOleCache2 *LPOLECACHE2;
-#define UPDFCACHE_NODATACACHE (0x1)
-
-#define UPDFCACHE_ONSAVECACHE (0x2)
-
-#define UPDFCACHE_ONSTOPCACHE (0x4)
-
-#define UPDFCACHE_NORMALCACHE (0x8)
-
-#define UPDFCACHE_IFBLANK (0x10)
-
-#define UPDFCACHE_ONLYIFBLANK (0x80000000)
-
-#define UPDFCACHE_IFBLANKORONSAVECACHE (UPDFCACHE_IFBLANK | UPDFCACHE_ONSAVECACHE)
-
-#define UPDFCACHE_ALL ((DWORD)~UPDFCACHE_ONLYIFBLANK)
-
-#define UPDFCACHE_ALLBUTNODATACACHE (UPDFCACHE_ALL & (DWORD)~UPDFCACHE_NODATACACHE)
-
-typedef enum tagDISCARDCACHE {
-    DISCARDCACHE_SAVEIFDIRTY = 0,
-    DISCARDCACHE_NOSAVE = 1
-} DISCARDCACHE;
 /*****************************************************************************
  * IOleCache2 interface
@@ -1900,4 +1936,27 @@
 #define __IOleCache2_INTERFACE_DEFINED__
 
+typedef IOleCache2 *LPOLECACHE2;
+#define UPDFCACHE_NODATACACHE (0x1)
+
+#define UPDFCACHE_ONSAVECACHE (0x2)
+
+#define UPDFCACHE_ONSTOPCACHE (0x4)
+
+#define UPDFCACHE_NORMALCACHE (0x8)
+
+#define UPDFCACHE_IFBLANK (0x10)
+
+#define UPDFCACHE_ONLYIFBLANK (0x80000000)
+
+#define UPDFCACHE_IFBLANKORONSAVECACHE (UPDFCACHE_IFBLANK | UPDFCACHE_ONSAVECACHE)
+
+#define UPDFCACHE_ALL ((DWORD)~UPDFCACHE_ONLYIFBLANK)
+
+#define UPDFCACHE_ALLBUTNODATACACHE (UPDFCACHE_ALL & (DWORD)~UPDFCACHE_NODATACACHE)
+
+typedef enum tagDISCARDCACHE {
+    DISCARDCACHE_SAVEIFDIRTY = 0,
+    DISCARDCACHE_NOSAVE = 1
+} DISCARDCACHE;
 DEFINE_GUID(IID_IOleCache2, 0x00000128, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2020,10 +2079,4 @@
 #endif  /* __IOleCache2_INTERFACE_DEFINED__ */
 
-#ifndef __IOleCacheControl_FWD_DEFINED__
-#define __IOleCacheControl_FWD_DEFINED__
-typedef interface IOleCacheControl IOleCacheControl;
-#endif
-
-typedef IOleCacheControl *LPOLECACHECONTROL;
 /*****************************************************************************
  * IOleCacheControl interface
@@ -2032,4 +2085,5 @@
 #define __IOleCacheControl_INTERFACE_DEFINED__
 
+typedef IOleCacheControl *LPOLECACHECONTROL;
 DEFINE_GUID(IID_IOleCacheControl, 0x00000129, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2103,8 +2157,9 @@
 #endif  /* __IOleCacheControl_INTERFACE_DEFINED__ */
 
-#ifndef __IEnumOLEVERB_FWD_DEFINED__
-#define __IEnumOLEVERB_FWD_DEFINED__
-typedef interface IEnumOLEVERB IEnumOLEVERB;
-#endif
+/*****************************************************************************
+ * IEnumOLEVERB interface
+ */
+#ifndef __IEnumOLEVERB_INTERFACE_DEFINED__
+#define __IEnumOLEVERB_INTERFACE_DEFINED__
 
 typedef IEnumOLEVERB *LPENUMOLEVERB;
@@ -2120,10 +2175,4 @@
     OLEVERBATTRIB_ONCONTAINERMENU = 2
 } OLEVERBATTRIB;
-/*****************************************************************************
- * IEnumOLEVERB interface
- */
-#ifndef __IEnumOLEVERB_INTERFACE_DEFINED__
-#define __IEnumOLEVERB_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IEnumOLEVERB, 0x00000104, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2245,8 +2294,9 @@
 #endif  /* __IEnumOLEVERB_INTERFACE_DEFINED__ */
 
-#ifndef __IOleObject_FWD_DEFINED__
-#define __IOleObject_FWD_DEFINED__
-typedef interface IOleObject IOleObject;
-#endif
+/*****************************************************************************
+ * IOleObject interface
+ */
+#ifndef __IOleObject_INTERFACE_DEFINED__
+#define __IOleObject_INTERFACE_DEFINED__
 
 typedef IOleObject *LPOLEOBJECT;
@@ -2296,10 +2346,4 @@
     OLECLOSE_PROMPTSAVE = 2
 } OLECLOSE;
-/*****************************************************************************
- * IOleObject interface
- */
-#ifndef __IOleObject_INTERFACE_DEFINED__
-#define __IOleObject_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IOleObject, 0x00000112, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2726,10 +2770,4 @@
 #endif  /* __IOleObject_INTERFACE_DEFINED__ */
 
-#ifndef __IOleAdviseHolder_FWD_DEFINED__
-#define __IOleAdviseHolder_FWD_DEFINED__
-typedef interface IOleAdviseHolder IOleAdviseHolder;
-#endif
-
-typedef IOleAdviseHolder *LPOLEADVISEHOLDER;
 /*****************************************************************************
  * IOleAdviseHolder interface
@@ -2738,4 +2776,5 @@
 #define __IOleAdviseHolder_INTERFACE_DEFINED__
 
+typedef IOleAdviseHolder *LPOLEADVISEHOLDER;
 DEFINE_GUID(IID_IOleAdviseHolder, 0x00000111, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -2874,9 +2913,4 @@
 #endif  /* __IOleAdviseHolder_INTERFACE_DEFINED__ */
 
-#ifndef __IContinue_FWD_DEFINED__
-#define __IContinue_FWD_DEFINED__
-typedef interface IContinue IContinue;
-#endif
-
 /*****************************************************************************
  * IContinue interface
@@ -2940,10 +2974,4 @@
 #endif  /* __IContinue_INTERFACE_DEFINED__ */
 
-#ifndef __IViewObject_FWD_DEFINED__
-#define __IViewObject_FWD_DEFINED__
-typedef interface IViewObject IViewObject;
-#endif
-
-typedef IViewObject *LPVIEWOBJECT;
 /*****************************************************************************
  * IViewObject interface
@@ -2952,4 +2980,5 @@
 #define __IViewObject_INTERFACE_DEFINED__
 
+typedef IViewObject *LPVIEWOBJECT;
 DEFINE_GUID(IID_IViewObject, 0x0000010d, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -3212,10 +3241,4 @@
 #endif  /* __IViewObject_INTERFACE_DEFINED__ */
 
-#ifndef __IViewObject2_FWD_DEFINED__
-#define __IViewObject2_FWD_DEFINED__
-typedef interface IViewObject2 IViewObject2;
-#endif
-
-typedef IViewObject2 *LPVIEWOBJECT2;
 /*****************************************************************************
  * IViewObject2 interface
@@ -3224,4 +3247,5 @@
 #define __IViewObject2_INTERFACE_DEFINED__
 
+typedef IViewObject2 *LPVIEWOBJECT2;
 DEFINE_GUID(IID_IViewObject2, 0x00000127, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -3343,10 +3367,4 @@
 #endif  /* __IViewObject2_INTERFACE_DEFINED__ */
 
-#ifndef __IDropSource_FWD_DEFINED__
-#define __IDropSource_FWD_DEFINED__
-typedef interface IDropSource IDropSource;
-#endif
-
-typedef IDropSource *LPDROPSOURCE;
 /*****************************************************************************
  * IDropSource interface
@@ -3355,4 +3373,5 @@
 #define __IDropSource_INTERFACE_DEFINED__
 
+typedef IDropSource *LPDROPSOURCE;
 DEFINE_GUID(IID_IDropSource, 0x00000121, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -3431,32 +3450,4 @@
 #endif  /* __IDropSource_INTERFACE_DEFINED__ */
 
-#ifndef __IDropTarget_FWD_DEFINED__
-#define __IDropTarget_FWD_DEFINED__
-typedef interface IDropTarget IDropTarget;
-#endif
-
-typedef IDropTarget *LPDROPTARGET;
-#define MK_ALT (0x20)
-
-#define DROPEFFECT_NONE (0)
-
-#define DROPEFFECT_COPY (1)
-
-#define DROPEFFECT_MOVE (2)
-
-#define DROPEFFECT_LINK (4)
-
-#define DROPEFFECT_SCROLL (0x80000000)
-
-#define DD_DEFSCROLLINSET (11)
-
-#define DD_DEFSCROLLDELAY (50)
-
-#define DD_DEFSCROLLINTERVAL (50)
-
-#define DD_DEFDRAGDELAY (200)
-
-#define DD_DEFDRAGMINDIST (2)
-
 /*****************************************************************************
  * IDropTarget interface
@@ -3464,4 +3455,27 @@
 #ifndef __IDropTarget_INTERFACE_DEFINED__
 #define __IDropTarget_INTERFACE_DEFINED__
+
+typedef IDropTarget *LPDROPTARGET;
+#define MK_ALT (0x20)
+
+#define DROPEFFECT_NONE (0)
+
+#define DROPEFFECT_COPY (1)
+
+#define DROPEFFECT_MOVE (2)
+
+#define DROPEFFECT_LINK (4)
+
+#define DROPEFFECT_SCROLL (0x80000000)
+
+#define DD_DEFSCROLLINSET (11)
+
+#define DD_DEFSCROLLDELAY (50)
+
+#define DD_DEFSCROLLINTERVAL (50)
+
+#define DD_DEFDRAGDELAY (200)
+
+#define DD_DEFDRAGMINDIST (2)
 
 DEFINE_GUID(IID_IDropTarget, 0x00000122, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/propidl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/propidl.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/propidl.h	(revision 21731)
@@ -1,3 +1,4 @@
-/*** Autogenerated by WIDL 1.1.23 from ../../../dlls/wined3d/../../include/propidl.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.26 from ../../include/propidl.idl - Do not edit ***/
+
 #include <rpc.h>
 #include <rpcndr.h>
@@ -5,19 +6,26 @@
 #ifndef __WIDL_PROPIDL_H
 #define __WIDL_PROPIDL_H
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+/* Headers for imported files */
+
 #include <objidl.h>
 #include <oaidl.h>
-#ifdef PID_DICTIONARY
-#undef PID_DICTIONARY
-#endif
-#ifdef PID_CODEPAGE
-#undef PID_CODEPAGE
-#endif
-#ifdef PID_SECURITY
-#undef PID_SECURITY
-#endif
+
+/* Forward declarations */
+
+#ifndef __IPropertyStorage_FWD_DEFINED__
+#define __IPropertyStorage_FWD_DEFINED__
+typedef interface IPropertyStorage IPropertyStorage;
+#endif
+
+#ifndef __IPropertySetStorage_FWD_DEFINED__
+#define __IPropertySetStorage_FWD_DEFINED__
+typedef interface IPropertySetStorage IPropertySetStorage;
+#endif
+
 #ifndef __IEnumSTATPROPSTG_FWD_DEFINED__
 #define __IEnumSTATPROPSTG_FWD_DEFINED__
@@ -30,8 +38,29 @@
 #endif
 
-#ifndef __IPropertyStorage_FWD_DEFINED__
-#define __IPropertyStorage_FWD_DEFINED__
-typedef interface IPropertyStorage IPropertyStorage;
-#endif
+
+#ifdef PID_DICTIONARY
+#undef PID_DICTIONARY
+#endif
+#ifdef PID_CODEPAGE
+#undef PID_CODEPAGE
+#endif
+#ifdef PID_SECURITY
+#undef PID_SECURITY
+#endif
+#ifndef __IEnumSTATPROPSTG_FWD_DEFINED__
+#define __IEnumSTATPROPSTG_FWD_DEFINED__
+typedef interface IEnumSTATPROPSTG IEnumSTATPROPSTG;
+#endif
+
+#ifndef __IEnumSTATPROPSETSTG_FWD_DEFINED__
+#define __IEnumSTATPROPSETSTG_FWD_DEFINED__
+typedef interface IEnumSTATPROPSETSTG IEnumSTATPROPSETSTG;
+#endif
+
+/*****************************************************************************
+ * IPropertyStorage interface
+ */
+#ifndef __IPropertyStorage_INTERFACE_DEFINED__
+#define __IPropertyStorage_INTERFACE_DEFINED__
 
 typedef IPropertyStorage *LPPROPERTYSTORAGE;
@@ -85,5 +114,5 @@
 typedef struct tagCAL {
     ULONG cElems;
-    long *pElems;
+    LONG *pElems;
 } CAL;
 typedef struct tagCAUL {
@@ -166,5 +195,5 @@
         USHORT uiVal;
         VARIANT_BOOL boolVal;
-        long lVal;
+        LONG lVal;
         ULONG ulVal;
         float fltVal;
@@ -300,10 +329,4 @@
     DWORD dwOSVersion;
 } STATPROPSETSTG;
-/*****************************************************************************
- * IPropertyStorage interface
- */
-#ifndef __IPropertyStorage_INTERFACE_DEFINED__
-#define __IPropertyStorage_INTERFACE_DEFINED__
-
 DEFINE_GUID(IID_IPropertyStorage, 0x00000138, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -576,10 +599,4 @@
 #endif  /* __IPropertyStorage_INTERFACE_DEFINED__ */
 
-#ifndef __IPropertySetStorage_FWD_DEFINED__
-#define __IPropertySetStorage_FWD_DEFINED__
-typedef interface IPropertySetStorage IPropertySetStorage;
-#endif
-
-typedef IPropertySetStorage *LPPROPERTYSETSTORAGE;
 /*****************************************************************************
  * IPropertySetStorage interface
@@ -588,4 +605,5 @@
 #define __IPropertySetStorage_INTERFACE_DEFINED__
 
+typedef IPropertySetStorage *LPPROPERTYSETSTORAGE;
 DEFINE_GUID(IID_IPropertySetStorage, 0x0000013a, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -711,5 +729,4 @@
 #endif  /* __IPropertySetStorage_INTERFACE_DEFINED__ */
 
-typedef IEnumSTATPROPSTG *LPENUMSTATPROPSTG;
 /*****************************************************************************
  * IEnumSTATPROPSTG interface
@@ -718,4 +735,5 @@
 #define __IEnumSTATPROPSTG_INTERFACE_DEFINED__
 
+typedef IEnumSTATPROPSTG *LPENUMSTATPROPSTG;
 DEFINE_GUID(IID_IEnumSTATPROPSTG, 0x00000139, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -837,5 +855,4 @@
 #endif  /* __IEnumSTATPROPSTG_INTERFACE_DEFINED__ */
 
-typedef IEnumSTATPROPSETSTG *LPENUMSTATPROPSETSTG;
 /*****************************************************************************
  * IEnumSTATPROPSETSTG interface
@@ -844,4 +861,5 @@
 #define __IEnumSTATPROPSETSTG_INTERFACE_DEFINED__
 
+typedef IEnumSTATPROPSETSTG *LPENUMSTATPROPSETSTG;
 DEFINE_GUID(IID_IEnumSTATPROPSETSTG, 0x0000013b, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/rtutils.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/rtutils.h	(revision 21731)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/rtutils.h	(revision 21731)
@@ -0,0 +1,58 @@
+/*
+ * Rtutils.h - Routing utilities / RRAS tracing
+ *
+ * Copyright (C) 2009 Alexander Scott-Johns
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+#ifndef _RTUTILS_H_
+#define _RTUTILS_H_
+
+#include <stdarg.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+DWORD WINAPI TraceRegisterExW(LPCWSTR name, DWORD flags);
+DWORD WINAPI TraceRegisterExA(LPCSTR name, DWORD flags);
+#define      TraceRegisterEx  WINELIB_NAME_AW(TraceRegisterEx)
+
+#define TraceRegisterW(name) TraceRegisterExW((name), 0)
+#define TraceRegisterA(name) TraceRegisterExA((name), 0)
+#define TraceRegister  WINELIB_NAME_AW(TraceRegister)
+
+/* Flags for TraceRegisterEx(W|A) */
+#define TRACE_USE_FILE     1
+#define TRACE_USE_CONSOLE  2
+
+/* Return value of TraceRegisterEx(W|A) */
+#define INVALID_TRACEID    0xFFFFFFFF
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _RTUTILS_H_ */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/servprov.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/servprov.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/servprov.h	(revision 21731)
@@ -1,3 +1,4 @@
-/*** Autogenerated by WIDL 1.1.23 from ../../../dlls/wined3d/../../include/servprov.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.26 from ../../include/servprov.idl - Do not edit ***/
+
 #include <rpc.h>
 #include <rpcndr.h>
@@ -5,9 +6,15 @@
 #ifndef __WIDL_SERVPROV_H
 #define __WIDL_SERVPROV_H
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+/* Headers for imported files */
+
 #include <objidl.h>
+
+/* Forward declarations */
+
 #ifndef __IServiceProvider_FWD_DEFINED__
 #define __IServiceProvider_FWD_DEFINED__
@@ -15,5 +22,5 @@
 #endif
 
-typedef IServiceProvider *LPSERVICEPROVIDER;
+
 /*****************************************************************************
  * IServiceProvider interface
@@ -22,4 +29,5 @@
 #define __IServiceProvider_INTERFACE_DEFINED__
 
+typedef IServiceProvider *LPSERVICEPROVIDER;
 DEFINE_GUID(IID_IServiceProvider, 0x6d5140c1, 0x7436, 0x11ce, 0x80,0x34, 0x00,0xaa,0x00,0x60,0x09,0xfa);
 #if defined(__cplusplus) && !defined(CINTERFACE)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/setupapi.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/setupapi.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/setupapi.h	(revision 21731)
@@ -1392,15 +1392,15 @@
 /* SetupDiGetWizardPage PageType values */
 #define SPWPT_SELECTDEVICE 0x00000001
+/* SetupDiGetWizardPage Flags values */
+#define SPWP_USE_DEVINFO_DATA 0x00000001
+
+/* SetupDiGetCustomDeviceProperty Flags values */
+#define DICUSTOMDEVPROP_MERGE_MULTISZ 0x00000001
+
+/* SetupConfigureWmiFromInfSection Flags values */
+#define SCWMI_CLOBBER_SECURITY 0x00000001
+
 /* SetupUninstallOEMInf Flags values */
 #define SUOI_FORCEDELETE 0x00000001
-
-/* SetupDiGetWizardPage Flags values */
-#define SPWP_USE_DEVINFO_DATA 0x00000001
-
-/* SetupDiGetCustomDeviceProperty Flags values */
-#define DICUSTOMDEVPROP_MERGE_MULTISZ 0x00000001
-
-/* SetupConfigureWmiFromInfSection Flags values */
-#define SCWMI_CLOBBER_SECURITY 0x00000001
 
 LONG     WINAPI AddTagToGroupOrderList(PCWSTR lpGroupName, DWORD dwUnknown2, DWORD dwUnknown3);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shlobj.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shlobj.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/shlobj.h	(revision 21731)
@@ -87,4 +87,5 @@
 int          WINAPI RestartDialog(HWND,LPCWSTR,DWORD);
 int          WINAPI RestartDialogEx(HWND,LPCWSTR,DWORD,DWORD);
+BOOL         WINAPI IsUserAnAdmin(void);
 
 #define SHFMT_ERROR     0xFFFFFFFFL  /* Error on last format, drive may be formattable */
@@ -523,4 +524,29 @@
 #endif
 
+/****************************************************************************
+ * IShellFolderViewCB interface
+ */
+
+#define INTERFACE IShellFolderViewCB
+DECLARE_INTERFACE_(IShellFolderViewCB,IUnknown)
+{
+    /*** IUnknown methods ***/
+    STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** ppvObject) PURE;
+    STDMETHOD_(ULONG,AddRef)(THIS) PURE;
+    STDMETHOD_(ULONG,Release)(THIS) PURE;
+    /*** IShellFolderViewCB methods ***/
+    STDMETHOD(MessageSFVCB)(THIS_ UINT uMsg, WPARAM wParam, LPARAM lParam) PURE;
+};
+#undef INTERFACE
+
+#if !defined(__cplusplus) || defined(CINTERFACE)
+/*** IUnknown methods ***/
+#define IShellFolderViewCB_QueryInterface(p,a,b)      (p)->lpVtbl->QueryInterface(p,a,b)
+#define IShellFolderViewCB_AddRef(p)                  (p)->lpVtbl->AddRef(p)
+#define IShellFolderViewCB_Release(p)                 (p)->lpVtbl->Release(p)
+/*** IShellFolderViewCB methods ***/
+#define IShellFolderViewCB_MessageSFVCB(p,a,b,c)      (p)->lpVtbl->MessageSFVCB(p,a,b,c)
+#endif
+
 /* IProgressDialog interface */
 #define PROGDLG_NORMAL           0x00000000
@@ -745,4 +771,14 @@
 #define SFVM_GET_WEBVIEW_THEME        86 /* undocumented */
 #define SFVM_GETDEFERREDVIEWSETTINGS  92 /* undocumented */
+
+typedef struct _SFV_CREATE
+{
+    UINT cbSize;
+    IShellFolder *pshf;
+    IShellView *psvOuter;
+    IShellFolderViewCB *psfvcb;
+} SFV_CREATE;
+
+HRESULT WINAPI SHCreateShellFolderView(const SFV_CREATE *pscfv, IShellView **ppsv);
 
 /* Types and definitions for the SFM_* parameters */
@@ -1264,5 +1300,4 @@
                                         LPITEMIDLIST **pppidl, LONG *plEvent);
 BOOL WINAPI SHChangeNotification_Unlock(HANDLE hLock);
-#define    SHCreateDirectoryEx WINELIB_NAME_AW(SHCreateDirectoryEx)
 
 HRESULT WINAPI SHGetRealIDL(IShellFolder *psf, LPCITEMIDLIST pidlSimple, LPITEMIDLIST * ppidlReal);
@@ -1274,4 +1309,5 @@
 int WINAPI SHCreateDirectoryExA(HWND, LPCSTR, LPSECURITY_ATTRIBUTES);
 int WINAPI SHCreateDirectoryExW(HWND, LPCWSTR, LPSECURITY_ATTRIBUTES);
+#define    SHCreateDirectoryEx WINELIB_NAME_AW(SHCreateDirectoryEx)
 
 /****************************************************************************
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/t2embapi.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/t2embapi.h	(revision 21731)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/t2embapi.h	(revision 21731)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2009 Andrew Nguyen
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+#ifndef __WINE_T2EMBAPI_H
+#define __WINE_T2EMBAPI_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Possible return values. */
+#define E_NONE                              0x0000L
+#define E_API_NOTIMPL                       0x0001L
+
+typedef ULONG (WINAPIV * READEMBEDPROC)(void*,void*,ULONG);
+
+typedef struct
+{
+    unsigned short usStructSize;
+    unsigned short usRefStrSize;
+    unsigned short *pusRefStr;
+} TTLOADINFO;
+
+LONG WINAPI TTLoadEmbeddedFont(HANDLE*,ULONG,ULONG*,ULONG,ULONG*,READEMBEDPROC,
+                               LPVOID,LPWSTR,LPSTR,TTLOADINFO*);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/textstor.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/textstor.idl	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/textstor.idl	(revision 21731)
@@ -21,8 +21,4 @@
  * other than GPL or LGPL is available it will apply instead, Sun elects to use only
  * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
-cpp_quote("#define TS_E_READONLY        MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0209)")
-cpp_quote("#define TS_E_NOLOCK          MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0201)")
-
-
  * a choice of LGPL license versions is made available with the language indicating
  * that LGPLv2 or any later version may be used, or where a choice of which version
@@ -34,4 +30,8 @@
 #endif
 
+cpp_quote("#define TS_E_READONLY        MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0209)")
+cpp_quote("#define TS_E_NOLOCK          MAKE_HRESULT(SEVERITY_ERROR, FACILITY_ITF, 0x0201)")
+
+
 const ULONG TS_DEFAULT_SELECTION = ~0u;
 
@@ -47,16 +47,16 @@
 const DWORD TS_AS_SEL_CHANGE       = 0x02;
 const DWORD TS_AS_LAYOUT_CHANGE    = 0x04;
+const DWORD TS_AS_ATTR_CHANGE      = 0x08;
+const DWORD TS_AS_STATUS_CHANGE    = 0x10;
+
+const DWORD TS_AS_ALL_SINKS = (TS_AS_TEXT_CHANGE | TS_AS_SEL_CHANGE | TS_AS_LAYOUT_CHANGE | TS_AS_ATTR_CHANGE | TS_AS_STATUS_CHANGE);
+
+const DWORD TS_LF_SYNC            = 0x1;
+const DWORD TS_LF_READ            = 0x2;
+const DWORD TS_LF_READWRITE       = 0x6;
+
 const WCHAR TS_CHAR_EMBEDDED     = 0xfffc;
 const WCHAR TS_CHAR_REGION       = 0x0000;
 const WCHAR TS_CHAR_REPLACEMENT  = 0xfffd;
-
-const DWORD TS_AS_ATTR_CHANGE      = 0x08;
-const DWORD TS_AS_STATUS_CHANGE    = 0x10;
-
-const DWORD TS_AS_ALL_SINKS = (TS_AS_TEXT_CHANGE | TS_AS_SEL_CHANGE | TS_AS_LAYOUT_CHANGE | TS_AS_ATTR_CHANGE | TS_AS_STATUS_CHANGE);
-
-const DWORD TS_LF_SYNC            = 0x1;
-const DWORD TS_LF_READ            = 0x2;
-const DWORD TS_LF_READWRITE       = 0x6;
 
 typedef [uuid(05fcf85b-5e9c-4c3e-ab71-29471d4f38e7)]  enum { TS_AE_NONE, TS_AE_START, TS_AE_END } TsActiveSelEnd;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/unknwn.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/unknwn.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/unknwn.h	(revision 21731)
@@ -1,3 +1,4 @@
-/*** Autogenerated by WIDL 1.1.23 from ../../../dlls/wined3d/../../include/unknwn.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.26 from ../../include/unknwn.idl - Do not edit ***/
+
 #include <rpc.h>
 #include <rpcndr.h>
@@ -5,9 +6,15 @@
 #ifndef __WIDL_UNKNWN_H
 #define __WIDL_UNKNWN_H
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+/* Headers for imported files */
+
 #include <wtypes.h>
+
+/* Forward declarations */
+
 #ifndef __IUnknown_FWD_DEFINED__
 #define __IUnknown_FWD_DEFINED__
@@ -15,5 +22,10 @@
 #endif
 
-typedef IUnknown *LPUNKNOWN;
+#ifndef __IClassFactory_FWD_DEFINED__
+#define __IClassFactory_FWD_DEFINED__
+typedef interface IClassFactory IClassFactory;
+#endif
+
+
 /*****************************************************************************
  * IUnknown interface
@@ -22,4 +34,5 @@
 #define __IUnknown_INTERFACE_DEFINED__
 
+typedef IUnknown *LPUNKNOWN;
 DEFINE_GUID(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
@@ -97,10 +110,4 @@
 #endif  /* __IUnknown_INTERFACE_DEFINED__ */
 
-#ifndef __IClassFactory_FWD_DEFINED__
-#define __IClassFactory_FWD_DEFINED__
-typedef interface IClassFactory IClassFactory;
-#endif
-
-typedef IClassFactory *LPCLASSFACTORY;
 /*****************************************************************************
  * IClassFactory interface
@@ -109,4 +116,5 @@
 #define __IClassFactory_INTERFACE_DEFINED__
 
+typedef IClassFactory *LPCLASSFACTORY;
 DEFINE_GUID(IID_IClassFactory, 0x00000001, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46);
 #if defined(__cplusplus) && !defined(CINTERFACE)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.h	(revision 21731)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.23 from ../../include/urlmon.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.26 from ../../include/urlmon.idl - Do not edit ***/
 
 /*
@@ -44,4 +44,9 @@
 #endif
 
+#ifndef __IBindStatusCallbackEx_FWD_DEFINED__
+#define __IBindStatusCallbackEx_FWD_DEFINED__
+typedef interface IBindStatusCallbackEx IBindStatusCallbackEx;
+#endif
+
 #ifndef __IAuthenticate_FWD_DEFINED__
 #define __IAuthenticate_FWD_DEFINED__
@@ -147,4 +152,14 @@
 #define __IInternetZoneManager_FWD_DEFINED__
 typedef interface IInternetZoneManager IInternetZoneManager;
+#endif
+
+#ifndef __IInternetZoneManagerEx_FWD_DEFINED__
+#define __IInternetZoneManagerEx_FWD_DEFINED__
+typedef interface IInternetZoneManagerEx IInternetZoneManagerEx;
+#endif
+
+#ifndef __IInternetZoneManagerEx2_FWD_DEFINED__
+#define __IInternetZoneManagerEx2_FWD_DEFINED__
+typedef interface IInternetZoneManagerEx2 IInternetZoneManagerEx2;
 #endif
 
@@ -762,4 +777,152 @@
 
 /*****************************************************************************
+ * IBindStatusCallbackEx interface
+ */
+#ifndef __IBindStatusCallbackEx_INTERFACE_DEFINED__
+#define __IBindStatusCallbackEx_INTERFACE_DEFINED__
+
+typedef IBindStatusCallbackEx *LPBINDSTATUSCALLBACKEX;
+typedef enum __WIDL_urlmon_generated_name_00000005 {
+    BINDF2_DISABLEBASICOVERHTTP = 0x1,
+    BINDF2_DISABLEAUTOCOOKIEHANDLING = 0x2,
+    BINDF2_READ_DATA_GREATER_THAN_4GB = 0x4,
+    BINDF2_DISABLE_HTTP_REDIRECT_XSECURITYID = 0x8,
+    BINDF2_RESERVED_3 = 0x20000000,
+    BINDF2_RESERVED_2 = 0x40000000,
+    BINDF2_RESERVED_1 = 0x80000000
+} BINDF2;
+DEFINE_GUID(IID_IBindStatusCallbackEx, 0xaaa74ef9, 0x8ee7, 0x4659, 0x88,0xd9, 0xf8,0xc5,0x04,0xda,0x73,0xcc);
+#if defined(__cplusplus) && !defined(CINTERFACE)
+interface IBindStatusCallbackEx : public IBindStatusCallback
+{
+    virtual HRESULT STDMETHODCALLTYPE GetBindInfoEx(
+        DWORD *grfBINDF,
+        BINDINFO *pbindinfo,
+        DWORD *grfBINDF2,
+        DWORD *pdwReserved) = 0;
+
+};
+#else
+typedef struct IBindStatusCallbackExVtbl {
+    BEGIN_INTERFACE
+
+    /*** IUnknown methods ***/
+    HRESULT (STDMETHODCALLTYPE *QueryInterface)(
+        IBindStatusCallbackEx* This,
+        REFIID riid,
+        void **ppvObject);
+
+    ULONG (STDMETHODCALLTYPE *AddRef)(
+        IBindStatusCallbackEx* This);
+
+    ULONG (STDMETHODCALLTYPE *Release)(
+        IBindStatusCallbackEx* This);
+
+    /*** IBindStatusCallback methods ***/
+    HRESULT (STDMETHODCALLTYPE *OnStartBinding)(
+        IBindStatusCallbackEx* This,
+        DWORD dwReserved,
+        IBinding *pib);
+
+    HRESULT (STDMETHODCALLTYPE *GetPriority)(
+        IBindStatusCallbackEx* This,
+        LONG *pnPriority);
+
+    HRESULT (STDMETHODCALLTYPE *OnLowResource)(
+        IBindStatusCallbackEx* This,
+        DWORD reserved);
+
+    HRESULT (STDMETHODCALLTYPE *OnProgress)(
+        IBindStatusCallbackEx* This,
+        ULONG ulProgress,
+        ULONG ulProgressMax,
+        ULONG ulStatusCode,
+        LPCWSTR szStatusText);
+
+    HRESULT (STDMETHODCALLTYPE *OnStopBinding)(
+        IBindStatusCallbackEx* This,
+        HRESULT hresult,
+        LPCWSTR szError);
+
+    HRESULT (STDMETHODCALLTYPE *GetBindInfo)(
+        IBindStatusCallbackEx* This,
+        DWORD *grfBINDF,
+        BINDINFO *pbindinfo);
+
+    HRESULT (STDMETHODCALLTYPE *OnDataAvailable)(
+        IBindStatusCallbackEx* This,
+        DWORD grfBSCF,
+        DWORD dwSize,
+        FORMATETC *pformatetc,
+        STGMEDIUM *pstgmed);
+
+    HRESULT (STDMETHODCALLTYPE *OnObjectAvailable)(
+        IBindStatusCallbackEx* This,
+        REFIID riid,
+        IUnknown *punk);
+
+    /*** IBindStatusCallbackEx methods ***/
+    HRESULT (STDMETHODCALLTYPE *GetBindInfoEx)(
+        IBindStatusCallbackEx* This,
+        DWORD *grfBINDF,
+        BINDINFO *pbindinfo,
+        DWORD *grfBINDF2,
+        DWORD *pdwReserved);
+
+    END_INTERFACE
+} IBindStatusCallbackExVtbl;
+interface IBindStatusCallbackEx {
+    CONST_VTBL IBindStatusCallbackExVtbl* lpVtbl;
+};
+
+#ifdef COBJMACROS
+/*** IUnknown methods ***/
+#define IBindStatusCallbackEx_QueryInterface(This,riid,ppvObject) (This)->lpVtbl->QueryInterface(This,riid,ppvObject)
+#define IBindStatusCallbackEx_AddRef(This) (This)->lpVtbl->AddRef(This)
+#define IBindStatusCallbackEx_Release(This) (This)->lpVtbl->Release(This)
+/*** IBindStatusCallback methods ***/
+#define IBindStatusCallbackEx_OnStartBinding(This,dwReserved,pib) (This)->lpVtbl->OnStartBinding(This,dwReserved,pib)
+#define IBindStatusCallbackEx_GetPriority(This,pnPriority) (This)->lpVtbl->GetPriority(This,pnPriority)
+#define IBindStatusCallbackEx_OnLowResource(This,reserved) (This)->lpVtbl->OnLowResource(This,reserved)
+#define IBindStatusCallbackEx_OnProgress(This,ulProgress,ulProgressMax,ulStatusCode,szStatusText) (This)->lpVtbl->OnProgress(This,ulProgress,ulProgressMax,ulStatusCode,szStatusText)
+#define IBindStatusCallbackEx_OnStopBinding(This,hresult,szError) (This)->lpVtbl->OnStopBinding(This,hresult,szError)
+#define IBindStatusCallbackEx_GetBindInfo(This,grfBINDF,pbindinfo) (This)->lpVtbl->GetBindInfo(This,grfBINDF,pbindinfo)
+#define IBindStatusCallbackEx_OnDataAvailable(This,grfBSCF,dwSize,pformatetc,pstgmed) (This)->lpVtbl->OnDataAvailable(This,grfBSCF,dwSize,pformatetc,pstgmed)
+#define IBindStatusCallbackEx_OnObjectAvailable(This,riid,punk) (This)->lpVtbl->OnObjectAvailable(This,riid,punk)
+/*** IBindStatusCallbackEx methods ***/
+#define IBindStatusCallbackEx_GetBindInfoEx(This,grfBINDF,pbindinfo,grfBINDF2,pdwReserved) (This)->lpVtbl->GetBindInfoEx(This,grfBINDF,pbindinfo,grfBINDF2,pdwReserved)
+#endif
+
+#endif
+
+HRESULT STDMETHODCALLTYPE IBindStatusCallbackEx_RemoteGetBindInfoEx_Proxy(
+    IBindStatusCallbackEx* This,
+    DWORD *grfBINDF,
+    RemBINDINFO *pbindinfo,
+    RemSTGMEDIUM *pstgmed,
+    DWORD *grfBINDF2,
+    DWORD *pdwReserved);
+void __RPC_STUB IBindStatusCallbackEx_RemoteGetBindInfoEx_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+HRESULT CALLBACK IBindStatusCallbackEx_GetBindInfoEx_Proxy(
+    IBindStatusCallbackEx* This,
+    DWORD *grfBINDF,
+    BINDINFO *pbindinfo,
+    DWORD *grfBINDF2,
+    DWORD *pdwReserved);
+HRESULT __RPC_STUB IBindStatusCallbackEx_GetBindInfoEx_Stub(
+    IBindStatusCallbackEx* This,
+    DWORD *grfBINDF,
+    RemBINDINFO *pbindinfo,
+    RemSTGMEDIUM *pstgmed,
+    DWORD *grfBINDF2,
+    DWORD *pdwReserved);
+
+#endif  /* __IBindStatusCallbackEx_INTERFACE_DEFINED__ */
+
+/*****************************************************************************
  * IAuthenticate interface
  */
@@ -1661,5 +1824,5 @@
 
 typedef IMonikerProp *LPMONIKERPROP;
-typedef enum __WIDL_urlmon_generated_name_00000005 {
+typedef enum __WIDL_urlmon_generated_name_00000006 {
     MIMETYPEPROP = 0,
     USE_SRC_URL = 1,
@@ -2950,5 +3113,5 @@
 
 #define MAX_SIZE_SECURITY_ID 512
-typedef enum __WIDL_urlmon_generated_name_00000006 {
+typedef enum __WIDL_urlmon_generated_name_00000007 {
     PUAF_DEFAULT = 0x0,
     PUAF_NOUI = 0x1,
@@ -2958,5 +3121,5 @@
     PUAF_CHECK_TIPS = 0x10
 } PUAF;
-typedef enum __WIDL_urlmon_generated_name_00000007 {
+typedef enum __WIDL_urlmon_generated_name_00000008 {
     SZM_CREATE = 0x0,
     SZM_DELETE = 0x1
@@ -3317,9 +3480,11 @@
     URLTEMPLATE_PREDEFINED_MIN = 0x10000,
     URLTEMPLATE_LOW = 0x10000,
+    URLTEMPLATE_MEDLOW = 0x10500,
     URLTEMPLATE_MEDIUM = 0x11000,
+    URLTEMPLATE_MEDHIGH = 0x11500,
     URLTEMPLATE_HIGH = 0x12000,
     URLTEMPLATE_PREDEFINED_MAX = 0x20000
 } URLTEMPLATE;
-typedef enum __WIDL_urlmon_generated_name_00000008 {
+typedef enum __WIDL_urlmon_generated_name_00000009 {
     ZAFLAGS_CUSTOM_EDIT = 0x1,
     ZAFLAGS_ADD_SITES = 0x2,
@@ -3329,5 +3494,9 @@
     ZAFLAGS_NO_UI = 0x20,
     ZAFLAGS_SUPPORTS_VERIFICATION = 0x40,
-    ZAFLAGS_UNC_AS_INTRANET = 0x80
+    ZAFLAGS_UNC_AS_INTRANET = 0x80,
+    ZAFLAGS_DETECT_INTRANET = 0x100,
+    ZAFLAGS_USE_LOCKED_ZONES = 0x10000,
+    ZAFLAGS_VERIFY_TEMPLATE_SETTINGS = 0x20000,
+    ZAFLAGS_NO_CACHE = 0x40000
 } ZAFLAGS;
 enum {
@@ -3677,4 +3846,456 @@
 
 #endif  /* __IInternetZoneManager_INTERFACE_DEFINED__ */
+
+/*****************************************************************************
+ * IInternetZoneManagerEx interface
+ */
+#ifndef __IInternetZoneManagerEx_INTERFACE_DEFINED__
+#define __IInternetZoneManagerEx_INTERFACE_DEFINED__
+
+DEFINE_GUID(IID_IInternetZoneManagerEx, 0xa4c23339, 0x8e06, 0x431e, 0x9b,0xf4, 0x7e,0x71,0x1c,0x08,0x56,0x48);
+#if defined(__cplusplus) && !defined(CINTERFACE)
+interface IInternetZoneManagerEx : public IInternetZoneManager
+{
+    virtual HRESULT STDMETHODCALLTYPE GetZoneActionPolicyEx(
+        DWORD dwZone,
+        DWORD dwAction,
+        BYTE *pPolicy,
+        DWORD cbPolicy,
+        URLZONEREG urlZoneReg,
+        DWORD dwFlags) = 0;
+
+    virtual HRESULT STDMETHODCALLTYPE SetZoneActionPolicyEx(
+        DWORD dwZone,
+        DWORD dwAction,
+        BYTE *pPolicy,
+        DWORD cbPolicy,
+        URLZONEREG urlZoneReg,
+        DWORD dwFlags) = 0;
+
+};
+#else
+typedef struct IInternetZoneManagerExVtbl {
+    BEGIN_INTERFACE
+
+    /*** IUnknown methods ***/
+    HRESULT (STDMETHODCALLTYPE *QueryInterface)(
+        IInternetZoneManagerEx* This,
+        REFIID riid,
+        void **ppvObject);
+
+    ULONG (STDMETHODCALLTYPE *AddRef)(
+        IInternetZoneManagerEx* This);
+
+    ULONG (STDMETHODCALLTYPE *Release)(
+        IInternetZoneManagerEx* This);
+
+    /*** IInternetZoneManager methods ***/
+    HRESULT (STDMETHODCALLTYPE *GetZoneAttributes)(
+        IInternetZoneManagerEx* This,
+        DWORD dwZone,
+        ZONEATTRIBUTES *pZoneAttributes);
+
+    HRESULT (STDMETHODCALLTYPE *SetZoneAttributes)(
+        IInternetZoneManagerEx* This,
+        DWORD dwZone,
+        ZONEATTRIBUTES *pZoneAttributes);
+
+    HRESULT (STDMETHODCALLTYPE *GetZoneCustomPolicy)(
+        IInternetZoneManagerEx* This,
+        DWORD dwZone,
+        REFGUID guidKey,
+        BYTE **ppPolicy,
+        DWORD *pcbPolicy,
+        URLZONEREG ulrZoneReg);
+
+    HRESULT (STDMETHODCALLTYPE *SetZoneCustomPolicy)(
+        IInternetZoneManagerEx* This,
+        DWORD dwZone,
+        REFGUID guidKey,
+        BYTE *ppPolicy,
+        DWORD pcbPolicy,
+        URLZONEREG ulrZoneReg);
+
+    HRESULT (STDMETHODCALLTYPE *GetZoneActionPolicy)(
+        IInternetZoneManagerEx* This,
+        DWORD dwZone,
+        DWORD dwAction,
+        BYTE *pPolicy,
+        DWORD cbPolicy,
+        URLZONEREG urlZoneReg);
+
+    HRESULT (STDMETHODCALLTYPE *SetZoneActionPolicy)(
+        IInternetZoneManagerEx* This,
+        DWORD dwZone,
+        DWORD dwAction,
+        BYTE *pPolicy,
+        DWORD cbPolicy,
+        URLZONEREG urlZoneReg);
+
+    HRESULT (STDMETHODCALLTYPE *PromptAction)(
+        IInternetZoneManagerEx* This,
+        DWORD dwAction,
+        HWND hwndParent,
+        LPCWSTR pwszUrl,
+        LPCWSTR pwszText,
+        DWORD dwPromptFlags);
+
+    HRESULT (STDMETHODCALLTYPE *LogAction)(
+        IInternetZoneManagerEx* This,
+        DWORD dwAction,
+        LPCWSTR pwszUrl,
+        LPCWSTR pwszText,
+        DWORD dwLogFlags);
+
+    HRESULT (STDMETHODCALLTYPE *CreateZoneEnumerator)(
+        IInternetZoneManagerEx* This,
+        DWORD *pdwEnum,
+        DWORD *pdwCount,
+        DWORD dwFlags);
+
+    HRESULT (STDMETHODCALLTYPE *GetZoneAt)(
+        IInternetZoneManagerEx* This,
+        DWORD dwEnum,
+        DWORD dwIndex,
+        DWORD *pdwZone);
+
+    HRESULT (STDMETHODCALLTYPE *DestroyZoneEnumerator)(
+        IInternetZoneManagerEx* This,
+        DWORD dwEnum);
+
+    HRESULT (STDMETHODCALLTYPE *CopyTemplatePoliciesToZone)(
+        IInternetZoneManagerEx* This,
+        DWORD dwTemplate,
+        DWORD dwZone,
+        DWORD dwReserved);
+
+    /*** IInternetZoneManagerEx methods ***/
+    HRESULT (STDMETHODCALLTYPE *GetZoneActionPolicyEx)(
+        IInternetZoneManagerEx* This,
+        DWORD dwZone,
+        DWORD dwAction,
+        BYTE *pPolicy,
+        DWORD cbPolicy,
+        URLZONEREG urlZoneReg,
+        DWORD dwFlags);
+
+    HRESULT (STDMETHODCALLTYPE *SetZoneActionPolicyEx)(
+        IInternetZoneManagerEx* This,
+        DWORD dwZone,
+        DWORD dwAction,
+        BYTE *pPolicy,
+        DWORD cbPolicy,
+        URLZONEREG urlZoneReg,
+        DWORD dwFlags);
+
+    END_INTERFACE
+} IInternetZoneManagerExVtbl;
+interface IInternetZoneManagerEx {
+    CONST_VTBL IInternetZoneManagerExVtbl* lpVtbl;
+};
+
+#ifdef COBJMACROS
+/*** IUnknown methods ***/
+#define IInternetZoneManagerEx_QueryInterface(This,riid,ppvObject) (This)->lpVtbl->QueryInterface(This,riid,ppvObject)
+#define IInternetZoneManagerEx_AddRef(This) (This)->lpVtbl->AddRef(This)
+#define IInternetZoneManagerEx_Release(This) (This)->lpVtbl->Release(This)
+/*** IInternetZoneManager methods ***/
+#define IInternetZoneManagerEx_GetZoneAttributes(This,dwZone,pZoneAttributes) (This)->lpVtbl->GetZoneAttributes(This,dwZone,pZoneAttributes)
+#define IInternetZoneManagerEx_SetZoneAttributes(This,dwZone,pZoneAttributes) (This)->lpVtbl->SetZoneAttributes(This,dwZone,pZoneAttributes)
+#define IInternetZoneManagerEx_GetZoneCustomPolicy(This,dwZone,guidKey,ppPolicy,pcbPolicy,ulrZoneReg) (This)->lpVtbl->GetZoneCustomPolicy(This,dwZone,guidKey,ppPolicy,pcbPolicy,ulrZoneReg)
+#define IInternetZoneManagerEx_SetZoneCustomPolicy(This,dwZone,guidKey,ppPolicy,pcbPolicy,ulrZoneReg) (This)->lpVtbl->SetZoneCustomPolicy(This,dwZone,guidKey,ppPolicy,pcbPolicy,ulrZoneReg)
+#define IInternetZoneManagerEx_GetZoneActionPolicy(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg) (This)->lpVtbl->GetZoneActionPolicy(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg)
+#define IInternetZoneManagerEx_SetZoneActionPolicy(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg) (This)->lpVtbl->SetZoneActionPolicy(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg)
+#define IInternetZoneManagerEx_PromptAction(This,dwAction,hwndParent,pwszUrl,pwszText,dwPromptFlags) (This)->lpVtbl->PromptAction(This,dwAction,hwndParent,pwszUrl,pwszText,dwPromptFlags)
+#define IInternetZoneManagerEx_LogAction(This,dwAction,pwszUrl,pwszText,dwLogFlags) (This)->lpVtbl->LogAction(This,dwAction,pwszUrl,pwszText,dwLogFlags)
+#define IInternetZoneManagerEx_CreateZoneEnumerator(This,pdwEnum,pdwCount,dwFlags) (This)->lpVtbl->CreateZoneEnumerator(This,pdwEnum,pdwCount,dwFlags)
+#define IInternetZoneManagerEx_GetZoneAt(This,dwEnum,dwIndex,pdwZone) (This)->lpVtbl->GetZoneAt(This,dwEnum,dwIndex,pdwZone)
+#define IInternetZoneManagerEx_DestroyZoneEnumerator(This,dwEnum) (This)->lpVtbl->DestroyZoneEnumerator(This,dwEnum)
+#define IInternetZoneManagerEx_CopyTemplatePoliciesToZone(This,dwTemplate,dwZone,dwReserved) (This)->lpVtbl->CopyTemplatePoliciesToZone(This,dwTemplate,dwZone,dwReserved)
+/*** IInternetZoneManagerEx methods ***/
+#define IInternetZoneManagerEx_GetZoneActionPolicyEx(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg,dwFlags) (This)->lpVtbl->GetZoneActionPolicyEx(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg,dwFlags)
+#define IInternetZoneManagerEx_SetZoneActionPolicyEx(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg,dwFlags) (This)->lpVtbl->SetZoneActionPolicyEx(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg,dwFlags)
+#endif
+
+#endif
+
+HRESULT STDMETHODCALLTYPE IInternetZoneManagerEx_GetZoneActionPolicyEx_Proxy(
+    IInternetZoneManagerEx* This,
+    DWORD dwZone,
+    DWORD dwAction,
+    BYTE *pPolicy,
+    DWORD cbPolicy,
+    URLZONEREG urlZoneReg,
+    DWORD dwFlags);
+void __RPC_STUB IInternetZoneManagerEx_GetZoneActionPolicyEx_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+HRESULT STDMETHODCALLTYPE IInternetZoneManagerEx_SetZoneActionPolicyEx_Proxy(
+    IInternetZoneManagerEx* This,
+    DWORD dwZone,
+    DWORD dwAction,
+    BYTE *pPolicy,
+    DWORD cbPolicy,
+    URLZONEREG urlZoneReg,
+    DWORD dwFlags);
+void __RPC_STUB IInternetZoneManagerEx_SetZoneActionPolicyEx_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+
+#endif  /* __IInternetZoneManagerEx_INTERFACE_DEFINED__ */
+
+#define SECURITY_IE_STATE_GREEN 0
+#define SECURITY_IE_STATE_RED   1
+/*****************************************************************************
+ * IInternetZoneManagerEx2 interface
+ */
+#ifndef __IInternetZoneManagerEx2_INTERFACE_DEFINED__
+#define __IInternetZoneManagerEx2_INTERFACE_DEFINED__
+
+DEFINE_GUID(IID_IInternetZoneManagerEx2, 0xedc17559, 0xdd5d, 0x4846, 0x8e,0xef, 0x8b,0xec,0xba,0x5a,0x4a,0xbf);
+#if defined(__cplusplus) && !defined(CINTERFACE)
+interface IInternetZoneManagerEx2 : public IInternetZoneManagerEx
+{
+    virtual HRESULT STDMETHODCALLTYPE GetZoneAttributesEx(
+        DWORD dwZone,
+        ZONEATTRIBUTES *pZoneAttributes,
+        DWORD dwFlags) = 0;
+
+    virtual HRESULT STDMETHODCALLTYPE GetZoneSecurityState(
+        DWORD dwZoneIndex,
+        BOOL fRespectPolicy,
+        LPDWORD pdwState,
+        BOOL *pfPolicyEncountered) = 0;
+
+    virtual HRESULT STDMETHODCALLTYPE GetIESecurityState(
+        BOOL fRespectPolicy,
+        LPDWORD pdwState,
+        BOOL *pfPolicyEncountered,
+        BOOL fNoCache) = 0;
+
+    virtual HRESULT STDMETHODCALLTYPE FixInsecureSettings(
+        ) = 0;
+
+};
+#else
+typedef struct IInternetZoneManagerEx2Vtbl {
+    BEGIN_INTERFACE
+
+    /*** IUnknown methods ***/
+    HRESULT (STDMETHODCALLTYPE *QueryInterface)(
+        IInternetZoneManagerEx2* This,
+        REFIID riid,
+        void **ppvObject);
+
+    ULONG (STDMETHODCALLTYPE *AddRef)(
+        IInternetZoneManagerEx2* This);
+
+    ULONG (STDMETHODCALLTYPE *Release)(
+        IInternetZoneManagerEx2* This);
+
+    /*** IInternetZoneManager methods ***/
+    HRESULT (STDMETHODCALLTYPE *GetZoneAttributes)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwZone,
+        ZONEATTRIBUTES *pZoneAttributes);
+
+    HRESULT (STDMETHODCALLTYPE *SetZoneAttributes)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwZone,
+        ZONEATTRIBUTES *pZoneAttributes);
+
+    HRESULT (STDMETHODCALLTYPE *GetZoneCustomPolicy)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwZone,
+        REFGUID guidKey,
+        BYTE **ppPolicy,
+        DWORD *pcbPolicy,
+        URLZONEREG ulrZoneReg);
+
+    HRESULT (STDMETHODCALLTYPE *SetZoneCustomPolicy)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwZone,
+        REFGUID guidKey,
+        BYTE *ppPolicy,
+        DWORD pcbPolicy,
+        URLZONEREG ulrZoneReg);
+
+    HRESULT (STDMETHODCALLTYPE *GetZoneActionPolicy)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwZone,
+        DWORD dwAction,
+        BYTE *pPolicy,
+        DWORD cbPolicy,
+        URLZONEREG urlZoneReg);
+
+    HRESULT (STDMETHODCALLTYPE *SetZoneActionPolicy)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwZone,
+        DWORD dwAction,
+        BYTE *pPolicy,
+        DWORD cbPolicy,
+        URLZONEREG urlZoneReg);
+
+    HRESULT (STDMETHODCALLTYPE *PromptAction)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwAction,
+        HWND hwndParent,
+        LPCWSTR pwszUrl,
+        LPCWSTR pwszText,
+        DWORD dwPromptFlags);
+
+    HRESULT (STDMETHODCALLTYPE *LogAction)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwAction,
+        LPCWSTR pwszUrl,
+        LPCWSTR pwszText,
+        DWORD dwLogFlags);
+
+    HRESULT (STDMETHODCALLTYPE *CreateZoneEnumerator)(
+        IInternetZoneManagerEx2* This,
+        DWORD *pdwEnum,
+        DWORD *pdwCount,
+        DWORD dwFlags);
+
+    HRESULT (STDMETHODCALLTYPE *GetZoneAt)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwEnum,
+        DWORD dwIndex,
+        DWORD *pdwZone);
+
+    HRESULT (STDMETHODCALLTYPE *DestroyZoneEnumerator)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwEnum);
+
+    HRESULT (STDMETHODCALLTYPE *CopyTemplatePoliciesToZone)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwTemplate,
+        DWORD dwZone,
+        DWORD dwReserved);
+
+    /*** IInternetZoneManagerEx methods ***/
+    HRESULT (STDMETHODCALLTYPE *GetZoneActionPolicyEx)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwZone,
+        DWORD dwAction,
+        BYTE *pPolicy,
+        DWORD cbPolicy,
+        URLZONEREG urlZoneReg,
+        DWORD dwFlags);
+
+    HRESULT (STDMETHODCALLTYPE *SetZoneActionPolicyEx)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwZone,
+        DWORD dwAction,
+        BYTE *pPolicy,
+        DWORD cbPolicy,
+        URLZONEREG urlZoneReg,
+        DWORD dwFlags);
+
+    /*** IInternetZoneManagerEx2 methods ***/
+    HRESULT (STDMETHODCALLTYPE *GetZoneAttributesEx)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwZone,
+        ZONEATTRIBUTES *pZoneAttributes,
+        DWORD dwFlags);
+
+    HRESULT (STDMETHODCALLTYPE *GetZoneSecurityState)(
+        IInternetZoneManagerEx2* This,
+        DWORD dwZoneIndex,
+        BOOL fRespectPolicy,
+        LPDWORD pdwState,
+        BOOL *pfPolicyEncountered);
+
+    HRESULT (STDMETHODCALLTYPE *GetIESecurityState)(
+        IInternetZoneManagerEx2* This,
+        BOOL fRespectPolicy,
+        LPDWORD pdwState,
+        BOOL *pfPolicyEncountered,
+        BOOL fNoCache);
+
+    HRESULT (STDMETHODCALLTYPE *FixInsecureSettings)(
+        IInternetZoneManagerEx2* This);
+
+    END_INTERFACE
+} IInternetZoneManagerEx2Vtbl;
+interface IInternetZoneManagerEx2 {
+    CONST_VTBL IInternetZoneManagerEx2Vtbl* lpVtbl;
+};
+
+#ifdef COBJMACROS
+/*** IUnknown methods ***/
+#define IInternetZoneManagerEx2_QueryInterface(This,riid,ppvObject) (This)->lpVtbl->QueryInterface(This,riid,ppvObject)
+#define IInternetZoneManagerEx2_AddRef(This) (This)->lpVtbl->AddRef(This)
+#define IInternetZoneManagerEx2_Release(This) (This)->lpVtbl->Release(This)
+/*** IInternetZoneManager methods ***/
+#define IInternetZoneManagerEx2_GetZoneAttributes(This,dwZone,pZoneAttributes) (This)->lpVtbl->GetZoneAttributes(This,dwZone,pZoneAttributes)
+#define IInternetZoneManagerEx2_SetZoneAttributes(This,dwZone,pZoneAttributes) (This)->lpVtbl->SetZoneAttributes(This,dwZone,pZoneAttributes)
+#define IInternetZoneManagerEx2_GetZoneCustomPolicy(This,dwZone,guidKey,ppPolicy,pcbPolicy,ulrZoneReg) (This)->lpVtbl->GetZoneCustomPolicy(This,dwZone,guidKey,ppPolicy,pcbPolicy,ulrZoneReg)
+#define IInternetZoneManagerEx2_SetZoneCustomPolicy(This,dwZone,guidKey,ppPolicy,pcbPolicy,ulrZoneReg) (This)->lpVtbl->SetZoneCustomPolicy(This,dwZone,guidKey,ppPolicy,pcbPolicy,ulrZoneReg)
+#define IInternetZoneManagerEx2_GetZoneActionPolicy(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg) (This)->lpVtbl->GetZoneActionPolicy(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg)
+#define IInternetZoneManagerEx2_SetZoneActionPolicy(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg) (This)->lpVtbl->SetZoneActionPolicy(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg)
+#define IInternetZoneManagerEx2_PromptAction(This,dwAction,hwndParent,pwszUrl,pwszText,dwPromptFlags) (This)->lpVtbl->PromptAction(This,dwAction,hwndParent,pwszUrl,pwszText,dwPromptFlags)
+#define IInternetZoneManagerEx2_LogAction(This,dwAction,pwszUrl,pwszText,dwLogFlags) (This)->lpVtbl->LogAction(This,dwAction,pwszUrl,pwszText,dwLogFlags)
+#define IInternetZoneManagerEx2_CreateZoneEnumerator(This,pdwEnum,pdwCount,dwFlags) (This)->lpVtbl->CreateZoneEnumerator(This,pdwEnum,pdwCount,dwFlags)
+#define IInternetZoneManagerEx2_GetZoneAt(This,dwEnum,dwIndex,pdwZone) (This)->lpVtbl->GetZoneAt(This,dwEnum,dwIndex,pdwZone)
+#define IInternetZoneManagerEx2_DestroyZoneEnumerator(This,dwEnum) (This)->lpVtbl->DestroyZoneEnumerator(This,dwEnum)
+#define IInternetZoneManagerEx2_CopyTemplatePoliciesToZone(This,dwTemplate,dwZone,dwReserved) (This)->lpVtbl->CopyTemplatePoliciesToZone(This,dwTemplate,dwZone,dwReserved)
+/*** IInternetZoneManagerEx methods ***/
+#define IInternetZoneManagerEx2_GetZoneActionPolicyEx(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg,dwFlags) (This)->lpVtbl->GetZoneActionPolicyEx(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg,dwFlags)
+#define IInternetZoneManagerEx2_SetZoneActionPolicyEx(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg,dwFlags) (This)->lpVtbl->SetZoneActionPolicyEx(This,dwZone,dwAction,pPolicy,cbPolicy,urlZoneReg,dwFlags)
+/*** IInternetZoneManagerEx2 methods ***/
+#define IInternetZoneManagerEx2_GetZoneAttributesEx(This,dwZone,pZoneAttributes,dwFlags) (This)->lpVtbl->GetZoneAttributesEx(This,dwZone,pZoneAttributes,dwFlags)
+#define IInternetZoneManagerEx2_GetZoneSecurityState(This,dwZoneIndex,fRespectPolicy,pdwState,pfPolicyEncountered) (This)->lpVtbl->GetZoneSecurityState(This,dwZoneIndex,fRespectPolicy,pdwState,pfPolicyEncountered)
+#define IInternetZoneManagerEx2_GetIESecurityState(This,fRespectPolicy,pdwState,pfPolicyEncountered,fNoCache) (This)->lpVtbl->GetIESecurityState(This,fRespectPolicy,pdwState,pfPolicyEncountered,fNoCache)
+#define IInternetZoneManagerEx2_FixInsecureSettings(This) (This)->lpVtbl->FixInsecureSettings(This)
+#endif
+
+#endif
+
+HRESULT STDMETHODCALLTYPE IInternetZoneManagerEx2_GetZoneAttributesEx_Proxy(
+    IInternetZoneManagerEx2* This,
+    DWORD dwZone,
+    ZONEATTRIBUTES *pZoneAttributes,
+    DWORD dwFlags);
+void __RPC_STUB IInternetZoneManagerEx2_GetZoneAttributesEx_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+HRESULT STDMETHODCALLTYPE IInternetZoneManagerEx2_GetZoneSecurityState_Proxy(
+    IInternetZoneManagerEx2* This,
+    DWORD dwZoneIndex,
+    BOOL fRespectPolicy,
+    LPDWORD pdwState,
+    BOOL *pfPolicyEncountered);
+void __RPC_STUB IInternetZoneManagerEx2_GetZoneSecurityState_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+HRESULT STDMETHODCALLTYPE IInternetZoneManagerEx2_GetIESecurityState_Proxy(
+    IInternetZoneManagerEx2* This,
+    BOOL fRespectPolicy,
+    LPDWORD pdwState,
+    BOOL *pfPolicyEncountered,
+    BOOL fNoCache);
+void __RPC_STUB IInternetZoneManagerEx2_GetIESecurityState_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+HRESULT STDMETHODCALLTYPE IInternetZoneManagerEx2_FixInsecureSettings_Proxy(
+    IInternetZoneManagerEx2* This);
+void __RPC_STUB IInternetZoneManagerEx2_FixInsecureSettings_Stub(
+    IRpcStubBuffer* This,
+    IRpcChannelBuffer* pRpcChannelBuffer,
+    PRPC_MESSAGE pRpcMessage,
+    DWORD* pdwStubPhase);
+
+#endif  /* __IInternetZoneManagerEx2_INTERFACE_DEFINED__ */
 
 typedef struct _tagSOFTDISTINFO {
@@ -3883,5 +4504,5 @@
 #define __IUri_INTERFACE_DEFINED__
 
-typedef enum __WIDL_urlmon_generated_name_00000009 {
+typedef enum __WIDL_urlmon_generated_name_0000000A {
     Uri_PROPERTY_ABSOLUTE_URI = 0,
     Uri_PROPERTY_STRING_START = Uri_PROPERTY_ABSOLUTE_URI,
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.idl	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/urlmon.idl	(revision 21731)
@@ -321,4 +321,43 @@
 
 /*****************************************************************************
+ * IBindStatusCallbackEx interface
+ */
+[
+    object,
+    uuid(aaa74ef9-8ee7-4659-88d9-f8c504da73cc),
+    pointer_default(unique)
+]
+interface IBindStatusCallbackEx : IBindStatusCallback
+{
+    typedef [unique] IBindStatusCallbackEx *LPBINDSTATUSCALLBACKEX;
+
+    typedef enum {
+        BINDF2_DISABLEBASICOVERHTTP               = 0x00000001,
+        BINDF2_DISABLEAUTOCOOKIEHANDLING          = 0x00000002,
+        BINDF2_READ_DATA_GREATER_THAN_4GB         = 0x00000004,
+        BINDF2_DISABLE_HTTP_REDIRECT_XSECURITYID  = 0x00000008,
+        BINDF2_RESERVED_3                         = 0x20000000,
+        BINDF2_RESERVED_2                         = 0x40000000,
+        BINDF2_RESERVED_1                         = 0x80000000,
+    } BINDF2;
+
+    [local]
+    HRESULT GetBindInfoEx(
+            [out] DWORD *grfBINDF,
+            [in, out, unique] BINDINFO *pbindinfo,
+            [out] DWORD *grfBINDF2,
+            [out] DWORD *pdwReserved);
+
+    [call_as(GetBindInfoEx)]
+    HRESULT RemoteGetBindInfoEx(
+            [out] DWORD *grfBINDF,
+            [in, out, unique] RemBINDINFO *pbindinfo,
+            [in, out, unique] RemSTGMEDIUM *pstgmed,
+            [out] DWORD *grfBINDF2,
+            [out] DWORD *pdwReserved);
+}
+
+
+/*****************************************************************************
  * IAuthenticate interface
  */
@@ -1181,5 +1220,7 @@
         URLTEMPLATE_PREDEFINED_MIN = 0x10000,
         URLTEMPLATE_LOW            = 0x10000,
+        URLTEMPLATE_MEDLOW         = 0x10500,
         URLTEMPLATE_MEDIUM         = 0x11000,
+        URLTEMPLATE_MEDHIGH        = 0x11500,
         URLTEMPLATE_HIGH           = 0x12000,
         URLTEMPLATE_PREDEFINED_MAX = 0x20000,
@@ -1187,12 +1228,16 @@
 
     typedef enum {
-        ZAFLAGS_CUSTOM_EDIT            = 0x00000001,
-        ZAFLAGS_ADD_SITES              = 0x00000002,
-        ZAFLAGS_REQUIRE_VERIFICATION   = 0x00000004,
-        ZAFLAGS_INCLUDE_PROXY_OVERRIDE = 0x00000008,
-        ZAFLAGS_INCLUDE_INTRANET_SITES = 0x00000010,
-        ZAFLAGS_NO_UI                  = 0x00000020,
-        ZAFLAGS_SUPPORTS_VERIFICATION  = 0x00000040,
-        ZAFLAGS_UNC_AS_INTRANET        = 0x00000080,
+        ZAFLAGS_CUSTOM_EDIT              = 0x00000001,
+        ZAFLAGS_ADD_SITES                = 0x00000002,
+        ZAFLAGS_REQUIRE_VERIFICATION     = 0x00000004,
+        ZAFLAGS_INCLUDE_PROXY_OVERRIDE   = 0x00000008,
+        ZAFLAGS_INCLUDE_INTRANET_SITES   = 0x00000010,
+        ZAFLAGS_NO_UI                    = 0x00000020,
+        ZAFLAGS_SUPPORTS_VERIFICATION    = 0x00000040,
+        ZAFLAGS_UNC_AS_INTRANET          = 0x00000080,
+        ZAFLAGS_DETECT_INTRANET          = 0x00000100,
+        ZAFLAGS_USE_LOCKED_ZONES         = 0x00010000,
+        ZAFLAGS_VERIFY_TEMPLATE_SETTINGS = 0x00020000,
+        ZAFLAGS_NO_CACHE                 = 0x00040000,
     } ZAFLAGS ;
 
@@ -1286,4 +1331,70 @@
         [in] DWORD dwReserved);
 }
+
+/*****************************************************************************
+ * IInternetZoneManagerEx interface
+ */
+[
+    local,
+    object,
+    uuid(A4C23339-8E06-431E-9BF4-7E711C085648),
+    pointer_default(unique)
+]
+interface IInternetZoneManagerEx : IInternetZoneManager
+{
+    HRESULT GetZoneActionPolicyEx(
+        [in]  DWORD dwZone,
+        [in]  DWORD dwAction,
+        [out] BYTE* pPolicy,
+        [in]  DWORD cbPolicy,
+        [in]  URLZONEREG urlZoneReg,
+        [in]  DWORD dwFlags);
+
+    HRESULT SetZoneActionPolicyEx(
+        [in] DWORD dwZone,
+        [in] DWORD dwAction,
+        [in] BYTE* pPolicy,
+        [in] DWORD cbPolicy,
+        [in] URLZONEREG urlZoneReg,
+        [in] DWORD dwFlags);
+
+}
+
+/*****************************************************************************
+ * IInternetZoneManagerEx2 interface
+ */
+
+cpp_quote("#define SECURITY_IE_STATE_GREEN 0")
+cpp_quote("#define SECURITY_IE_STATE_RED   1")
+
+[
+    local,
+    object,
+    uuid(EDC17559-DD5D-4846-8EEF-8BECBA5A4ABF),
+    pointer_default(unique)
+]
+interface IInternetZoneManagerEx2 : IInternetZoneManagerEx
+{
+    HRESULT GetZoneAttributesEx(
+        [in]              DWORD dwZone,
+        [in, out, unique] ZONEATTRIBUTES* pZoneAttributes,
+        [in]              DWORD dwFlags);
+
+    HRESULT GetZoneSecurityState(
+        [in]      DWORD dwZoneIndex,
+        [in]      BOOL fRespectPolicy,
+        [in, out] LPDWORD pdwState,
+        [in, out] BOOL *pfPolicyEncountered);
+
+    HRESULT GetIESecurityState(
+        [in]      BOOL fRespectPolicy,
+        [in, out] LPDWORD pdwState,
+        [in, out] BOOL *pfPolicyEncountered,
+        [in]      BOOL fNoCache);
+
+    HRESULT FixInsecureSettings(void);
+
+}
+
 
 typedef struct _tagSOFTDISTINFO
@@ -1501,18 +1612,4 @@
         [out] DWORD *pdwZone);
 
- * IUriContainer interface
- */
-[
-    local,
-    object,
-    uuid(a158a630-ed6f-45fb-b987-f68676f57752),
-    pointer_default(unique)
-]
-interface IUriContainer : IUnknown
-{
-    HRESULT GetIUri([out] IUri **ppIUri);
-}
-
-/*****************************************************************************
     HRESULT GetProperties(
         [out] LPDWORD pdwFlags);
@@ -1521,4 +1618,18 @@
         [in]  IUri *pUri,
         [out] BOOL *pfEqual);
+}
+
+/*****************************************************************************
+ * IUriContainer interface
+ */
+[
+    local,
+    object,
+    uuid(a158a630-ed6f-45fb-b987-f68676f57752),
+    pointer_default(unique)
+]
+interface IUriContainer : IUnknown
+{
+    HRESULT GetIUri([out] IUri **ppIUri);
 }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wbemcli.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wbemcli.idl	(revision 21731)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wbemcli.idl	(revision 21731)
@@ -0,0 +1,220 @@
+/*
+ * Copyright 2009 Hans Leidekker for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+cpp_quote("DEFINE_GUID(CLSID_WbemLocator, 0x4590f811,0x1d3A,0x11d0,0x89,0x1f,0x00,0xaa,0x00,0x4b,0x2e,0x24);")
+cpp_quote("DEFINE_GUID(CLSID_WbemStatusCode, 0xeb87e1bd,0x3233,0x11d2,0xae,0xc9,0x00,0xc0,0x4f,0xb6,0x88,0x20);")
+
+import "objidl.idl";
+
+interface IWbemContext;
+interface IWbemServices;
+interface IWbemStatusCodeText;
+
+typedef [v1_enum] enum tag_WBEMSTATUS
+{
+    WBEM_NO_ERROR                           = 0,
+    WBEM_S_NO_ERROR                         = 0,
+    WBEM_S_SAME                             = 0,
+    WBEM_S_FALSE                            = 1,
+    WBEM_S_ALREADY_EXISTS                   = 0x40001,
+    WBEM_S_RESET_TO_DEFAULT                 = 0x40002,
+    WBEM_S_DIFFERENT                        = 0x40003,
+    WBEM_S_TIMEDOUT                         = 0x40004,
+    WBEM_S_NO_MORE_DATA                     = 0x40005,
+    WBEM_S_OPERATION_CANCELLED              = 0x40006,
+    WBEM_S_PENDING                          = 0x40007,
+    WBEM_S_DUPLICATE_OBJECTS                = 0x40008,
+    WBEM_S_ACCESS_DENIED                    = 0x40009,
+    WBEM_S_PARTIAL_RESULTS                  = 0x40010,
+    WBEM_S_SOURCE_NOT_AVAILABLE             = 0x40017,
+    WBEM_E_FAILED                           = 0x80041001,
+    WBEM_E_NOT_FOUND                        = 0x80041002,
+    WBEM_E_ACCESS_DENIED                    = 0x80041003,
+    WBEM_E_PROVIDER_FAILURE                 = 0x80041004,
+    WBEM_E_TYPE_MISMATCH                    = 0x80041005,
+    WBEM_E_OUT_OF_MEMORY                    = 0x80041006,
+    WBEM_E_INVALID_CONTEXT                  = 0x80041007,
+    WBEM_E_INVALID_PARAMETER                = 0x80041008,
+    WBEM_E_NOT_AVAILABLE                    = 0x80041009,
+    WBEM_E_CRITICAL_ERROR                   = 0x8004100a,
+    WBEM_E_INVALID_STREAM                   = 0x8004100b,
+    WBEM_E_NOT_SUPPORTED                    = 0x8004100c,
+    WBEM_E_INVALID_SUPERCLASS               = 0x8004100d,
+    WBEM_E_INVALID_NAMESPACE                = 0x8004100e,
+    WBEM_E_INVALID_OBJECT                   = 0x8004100f,
+    WBEM_E_INVALID_CLASS                    = 0x80041010,
+    WBEM_E_PROVIDER_NOT_FOUND               = 0x80041011,
+    WBEM_E_INVALID_PROVIDER_REGISTRATION    = 0x80041012,
+    WBEM_E_PROVIDER_LOAD_FAILURE            = 0x80041013,
+    WBEM_E_INITIALIZATION_FAILURE           = 0x80041014,
+    WBEM_E_TRANSPORT_FAILURE                = 0x80041015,
+    WBEM_E_INVALID_OPERATION                = 0x80041016,
+    WBEM_E_INVALID_QUERY                    = 0x80041017,
+    WBEM_E_INVALID_QUERY_TYPE               = 0x80041018,
+    WBEM_E_ALREADY_EXISTS                   = 0x80041019,
+    WBEM_E_OVERRIDE_NOT_ALLOWED             = 0x8004101a,
+    WBEM_E_PROPAGATED_QUALIFIER             = 0x8004101b,
+    WBEM_E_PROPAGATED_PROPERTY              = 0x8004101c,
+    WBEM_E_UNEXPECTED                       = 0x8004101d,
+    WBEM_E_ILLEGAL_OPERATION                = 0x8004101e,
+    WBEM_E_CANNOT_BE_KEY                    = 0x8004101f,
+    WBEM_E_INCOMPLETE_CLASS                 = 0x80041020,
+    WBEM_E_INVALID_SYNTAX                   = 0x80041021,
+    WBEM_E_NONDECORATED_OBJECT              = 0x80041022,
+    WBEM_E_READ_ONLY                        = 0x80041023,
+    WBEM_E_PROVIDER_NOT_CAPABLE             = 0x80041024,
+    WBEM_E_CLASS_HAS_CHILDREN               = 0x80041025,
+    WBEM_E_CLASS_HAS_INSTANCES              = 0x80041026,
+    WBEM_E_QUERY_NOT_IMPLEMENTED            = 0x80041027,
+    WBEM_E_ILLEGAL_NULL                     = 0x80041028,
+    WBEM_E_INVALID_QUALIFIER_TYPE           = 0x80041029,
+    WBEM_E_INVALID_PROPERTY_TYPE            = 0x8004102a,
+    WBEM_E_VALUE_OUT_OF_RANGE               = 0x8004102b,
+    WBEM_E_CANNOT_BE_SINGLETON              = 0x8004102c,
+    WBEM_E_INVALID_CIM_TYPE                 = 0x8004102d,
+    WBEM_E_INVALID_METHOD                   = 0x8004102e,
+    WBEM_E_INVALID_METHOD_PARAMETERS        = 0x8004102f,
+    WBEM_E_SYSTEM_PROPERTY                  = 0x80041030,
+    WBEM_E_INVALID_PROPERTY                 = 0x80041031,
+    WBEM_E_CALL_CANCELLED                   = 0x80041032,
+    WBEM_E_SHUTTING_DOWN                    = 0x80041033,
+    WBEM_E_PROPAGATED_METHOD                = 0x80041034,
+    WBEM_E_UNSUPPORTED_PARAMETER            = 0x80041035,
+    WBEM_E_MISSING_PARAMETER_ID             = 0x80041036,
+    WBEM_E_INVALID_PARAMETER_ID             = 0x80041037,
+    WBEM_E_NONCONSECUTIVE_PARAMETER_IDS     = 0x80041038,
+    WBEM_E_PARAMETER_ID_ON_RETVAL           = 0x80041039,
+    WBEM_E_INVALID_OBJECT_PATH              = 0x8004103a,
+    WBEM_E_OUT_OF_DISK_SPACE                = 0x8004103b,
+    WBEM_E_BUFFER_TOO_SMALL                 = 0x8004103c,
+    WBEM_E_UNSUPPORTED_PUT_EXTENSION        = 0x8004103d,
+    WBEM_E_UNKNOWN_OBJECT_TYPE              = 0x8004103e,
+    WBEM_E_UNKNOWN_PACKET_TYPE              = 0x8004103f,
+    WBEM_E_MARSHAL_VERSION_MISMATCH         = 0x80041040,
+    WBEM_E_MARSHAL_INVALID_SIGNATURE        = 0x80041041,
+    WBEM_E_INVALID_QUALIFIER                = 0x80041042,
+    WBEM_E_INVALID_DUPLICATE_PARAMETER      = 0x80041043,
+    WBEM_E_TOO_MUCH_DATA                    = 0x80041044,
+    WBEM_E_SERVER_TOO_BUSY                  = 0x80041045,
+    WBEM_E_INVALID_FLAVOR                   = 0x80041046,
+    WBEM_E_CIRCULAR_REFERENCE               = 0x80041047,
+    WBEM_E_UNSUPPORTED_CLASS_UPDATE         = 0x80041048,
+    WBEM_E_CANNOT_CHANGE_KEY_INHERITANCE    = 0x80041049,
+    WBEM_E_CANNOT_CHANGE_INDEX_INHERITANCE  = 0x80041050,
+    WBEM_E_TOO_MANY_PROPERTIES              = 0x80041051,
+    WBEM_E_UPDATE_TYPE_MISMATCH             = 0x80041052,
+    WBEM_E_UPDATE_OVERRIDE_NOT_ALLOWED      = 0x80041053,
+    WBEM_E_UPDATE_PROPAGATED_METHOD         = 0x80041054,
+    WBEM_E_METHOD_NOT_IMPLEMENTED           = 0x80041055,
+    WBEM_E_METHOD_DISABLED                  = 0x80041056,
+    WBEM_E_REFRESHER_BUSY                   = 0x80041057,
+    WBEM_E_UNPARSABLE_QUERY                 = 0x80041058,
+    WBEM_E_NOT_EVENT_CLASS                  = 0x80041059,
+    WBEM_E_MISSING_GROUP_WITHIN             = 0x8004105a,
+    WBEM_E_MISSING_AGGREGATION_LIST         = 0x8004105b,
+    WBEM_E_PROPERTY_NOT_AN_OBJECT           = 0x8004105c,
+    WBEM_E_AGGREGATING_BY_OBJECT            = 0x8004105d,
+    WBEM_E_UNINTERPRETABLE_PROVIDER_QUERY   = 0x8004105f,
+    WBEM_E_BACKUP_RESTORE_WINMGMT_RUNNING   = 0x80041060,
+    WBEM_E_QUEUE_OVERFLOW                   = 0x80041061,
+    WBEM_E_PRIVILEGE_NOT_HELD               = 0x80041062,
+    WBEM_E_INVALID_OPERATOR                 = 0x80041063,
+    WBEM_E_LOCAL_CREDENTIALS                = 0x80041064,
+    WBEM_E_CANNOT_BE_ABSTRACT               = 0x80041065,
+    WBEM_E_AMENDED_OBJECT                   = 0x80041066,
+    WBEM_E_CLIENT_TOO_SLOW                  = 0x80041067,
+    WBEM_E_NULL_SECURITY_DESCRIPTOR         = 0x80041068,
+    WBEM_E_TIMED_OUT                        = 0x80041069,
+    WBEM_E_INVALID_ASSOCIATION              = 0x8004106a,
+    WBEM_E_AMBIGUOUS_OPERATION              = 0x8004106b,
+    WBEM_E_QUOTA_VIOLATION                  = 0x8004106c,
+    WBEM_E_RESERVED_001                     = 0x8004106d,
+    WBEM_E_RESERVED_002                     = 0x8004106e,
+    WBEM_E_UNSUPPORTED_LOCALE               = 0x8004106f,
+    WBEM_E_HANDLE_OUT_OF_DATE               = 0x80041070,
+    WBEM_E_CONNECTION_FAILED                = 0x80041071,
+    WBEM_E_INVALID_HANDLE_REQUEST           = 0x80041072,
+    WBEM_E_PROPERTY_NAME_TOO_WIDE           = 0x80041073,
+    WBEM_E_CLASS_NAME_TOO_WIDE              = 0x80041074,
+    WBEM_E_METHOD_NAME_TOO_WIDE             = 0x80041075,
+    WBEM_E_QUALIFIER_NAME_TOO_WIDE          = 0x80041076,
+    WBEM_E_RERUN_COMMAND                    = 0x80041077,
+    WBEM_E_DATABASE_VER_MISMATCH            = 0x80041078,
+    WBEM_E_VETO_DELETE                      = 0x80041079,
+    WBEM_E_VETO_PUT                         = 0x8004107a,
+    WBEM_E_INVALID_LOCALE                   = 0x80041080,
+    WBEM_E_PROVIDER_SUSPENDED               = 0x80041081,
+    WBEM_E_SYNCHRONIZATION_REQUIRED         = 0x80041082,
+    WBEM_E_NO_SCHEMA                        = 0x80041083,
+    WBEM_E_PROVIDER_ALREADY_REGISTERED      = 0x80041084,
+    WBEM_E_PROVIDER_NOT_REGISTERED          = 0x80041085,
+    WBEM_E_FATAL_TRANSPORT_ERROR            = 0x80041086,
+    WBEM_E_ENCRYPTED_CONNECTION_REQUIRED    = 0x80041087,
+    WBEM_E_PROVIDER_TIMED_OUT               = 0x80041088,
+    WBEM_E_NO_KEY                           = 0x80041089,
+    WBEM_E_PROVIDER_DISABLED                = 0x8004108a
+} WBEMSTATUS;
+
+[
+    object,
+    restricted,
+    local,
+    uuid(dc12a687-737f-11cf-884d-00aa004b2e24),
+    pointer_default(unique)
+]
+interface IWbemLocator : IUnknown
+{
+    HRESULT ConnectServer(
+        [in] const BSTR strNetworkResource,
+        [in] const BSTR strUser,
+        [in] const BSTR strPassword,
+        [in] const BSTR strLocale,
+        [in] LONG lSecurityFlags,
+        [in] const BSTR strAuthority,
+        [in] IWbemContext *pCtx,
+        [out] IWbemServices **ppNamespace);
+};
+
+[
+    object,
+    local,
+    uuid(eb87e1bc-3233-11d2-aec9-00c04fb68820)
+]
+interface IWbemStatusCodeText : IUnknown
+{
+    HRESULT GetErrorCodeText(
+        [in] HRESULT hRes,
+        [in] LCID LocaleId,
+        [in] LONG lFlags,
+        [out] BSTR *MessageText);
+
+    HRESULT GetFacilityCodeText(
+        [in] HRESULT hRes,
+        [in] LCID LocaleId,
+        [in] LONG lFlags,
+        [out] BSTR *MessageText);
+};
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winbase.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winbase.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winbase.h	(revision 21731)
@@ -1736,4 +1736,7 @@
 WINBASEAPI UINT        WINAPI GetSystemWindowsDirectoryW(LPWSTR,UINT);
 #define                       GetSystemWindowsDirectory WINELIB_NAME_AW(GetSystemWindowsDirectory)
+WINBASEAPI UINT        WINAPI GetSystemWow64DirectoryA(LPSTR,UINT);
+WINBASEAPI UINT        WINAPI GetSystemWow64DirectoryW(LPWSTR,UINT);
+#define                       GetSystemWow64Directory WINELIB_NAME_AW(GetSystemWow64Directory)
 WINBASEAPI DWORD       WINAPI GetTapeParameters(HANDLE,DWORD,LPDWORD,LPVOID);
 WINBASEAPI DWORD       WINAPI GetTapePosition(HANDLE,DWORD,LPDWORD,LPDWORD,LPDWORD);
@@ -2143,4 +2146,5 @@
 WINBASEAPI SIZE_T      WINAPI VirtualQueryEx(HANDLE,LPCVOID,PMEMORY_BASIC_INFORMATION,SIZE_T);
 WINBASEAPI BOOL        WINAPI VirtualUnlock(LPVOID,SIZE_T);
+WINBASEAPI DWORD       WINAPI WTSGetActiveConsoleSessionId(void);
 WINBASEAPI BOOL        WINAPI WaitCommEvent(HANDLE,LPDWORD,LPOVERLAPPED);
 WINBASEAPI BOOL        WINAPI WaitForDebugEvent(LPDEBUG_EVENT,DWORD);
@@ -2153,4 +2157,7 @@
 #define                       WaitNamedPipe WINELIB_NAME_AW(WaitNamedPipe)
 WINBASEAPI UINT        WINAPI WinExec(LPCSTR,UINT);
+WINBASEAPI BOOL        WINAPI Wow64DisableWow64FsRedirection(PVOID*);
+WINBASEAPI BOOLEAN     WINAPI Wow64EnableWow64FsRedirection(BOOLEAN);
+WINBASEAPI BOOL        WINAPI Wow64RevertWow64FsRedirection(PVOID);
 WINBASEAPI BOOL        WINAPI WriteFile(HANDLE,LPCVOID,DWORD,LPDWORD,LPOVERLAPPED);
 WINBASEAPI BOOL        WINAPI WriteFileEx(HANDLE,LPCVOID,DWORD,LPOVERLAPPED,LPOVERLAPPED_COMPLETION_ROUTINE);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincodec.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincodec.idl	(revision 21731)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincodec.idl	(revision 21731)
@@ -0,0 +1,405 @@
+/*
+ * Copyright 2009 Vincent Povirk for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+import "wtypes.idl";
+import "propidl.idl";
+import "objidl.idl";
+import "ocidl.idl";
+
+#define CODEC_FORCE_DWORD 0x7fffffff
+
+typedef enum WICDecodeOptions {
+    WICDecodeMetadataCacheOnDemand = 0x00000000,
+    WICDecodeMetadataCacheOnLoad = 0x00000001,
+    WICMETADATACACHEOPTION_FORCE_DWORD = CODEC_FORCE_DWORD
+} WICDecodeOptions;
+
+typedef enum WICBitmapCreateCacheOption {
+    WICBitmapNoCache = 0x00000000,
+    WICBitmapCacheOnDemand = 0x00000001,
+    WICBitmapCacheOnLoad = 0x00000002,
+    WICBITMAPCREATECACHEOPTION_FORCE_DWORD = CODEC_FORCE_DWORD
+} WICBitmapCreateCacheOption;
+
+typedef enum WICBitmapAlphaChannelOption {
+    WICBitmapUseAlpha = 0x00000000,
+    WICBitmapUsePremultipliedAlpha = 0x00000001,
+    WICBitmapIgnoreAlpha = 0x00000002,
+    WICBITMAPALPHACHANNELOPTIONS_FORCE_DWORD = CODEC_FORCE_DWORD
+} WICBitmapAlphaChannelOption;
+
+typedef enum WICBitmapDecoderCapabilities {
+    WICBitmapDecoderCapabilitySameEncoder = 0x00000001,
+    WICBitmapDecoderCapabilityCanDecodeAllImages = 0x00000002,
+    WICBitmapDecoderCapabilityCanDecodeSomeImages = 0x00000004,
+    WICBitmapDecoderCapabilityCanEnumerateMetadata = 0x00000008,
+    WICBitmapDecoderCapabilityCanDecodeThumbnail = 0x00000010,
+} WICBitmapDecoderCapabilities;
+
+typedef enum WICBitmapPaletteType {
+    WICBitmapPaletteTypeCustom = 0x00000000,
+    WICBitmapPaletteTypeMedianCut = 0x00000001,
+    WICBitmapPaletteTypeFixedBW = 0x00000002,
+    WICBitmapPaletteTypeFixedHalftone8 = 0x00000003,
+    WICBitmapPaletteTypeFixedHalftone27 = 0x00000004,
+    WICBitmapPaletteTypeFixedHalftone64 = 0x00000005,
+    WICBitmapPaletteTypeFixedHalftone125 = 0x00000006,
+    WICBitmapPaletteTypeFixedHalftone216 = 0x00000007,
+    WICBitmapPaletteTypeFixedWebPalette = WICBitmapPaletteTypeFixedHalftone216,
+    WICBitmapPaletteTypeFixedHalftone252 = 0x00000008,
+    WICBitmapPaletteTypeFixedHalftone256 = 0x00000009,
+    WICBitmapPaletteTypeFixedGray4 = 0x0000000A,
+    WICBitmapPaletteTypeFixedGray16 = 0x0000000B,
+    WICBitmapPaletteTypeFixedGray256 = 0x0000000C,
+    WICBITMAPPALETTETYPE_FORCE_DWORD = CODEC_FORCE_DWORD
+} WICBitmapPaletteType;
+
+typedef GUID WICPixelFormatGUID;
+typedef REFGUID REFWICPixelFormatGUID;
+
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormatDontCare, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x00);")
+cpp_quote("#define GUID_WICPixelFormatUndefined GUID_WICPixelFormatDontCare")
+
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat1bppIndexed, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x01);")
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat2bppIndexed, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x02);")
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat4bppIndexed, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x03);")
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat8bppIndexed, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x04);")
+
+cpp_quote("DEFINE_GUID(GUID_WICPixelFormat16bppBGR555, 0x6fddc324,0x4e03,0x4bfe,0xb1,0x85,0x3d,0x77,0x76,0x8d,0xc9,0x09);")
+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);")
+
+typedef struct WICRect {
+    INT X;
+    INT Y;
+    INT Width;
+    INT Height;
+} WICRect;
+
+typedef UINT32 WICColor;
+
+cpp_quote("#define WINCODEC_ERR_WRONGSTATE 0x88982f04")
+cpp_quote("#define WINCODEC_ERR_CODECNOTHUMBNAIL 0x88982f44")
+cpp_quote("#define WINCODEC_ERR_PALETTEUNAVAILABLE 0x88982f45")
+cpp_quote("#define WINCODEC_ERR_UNSUPPORTEDOPERATION 0x88982f81")
+
+interface IWICBitmap;
+interface IWICComponentInfo;
+interface IWICBitmapEncoder;
+interface IWICPalette;
+interface IWICFormatConverter;
+interface IWICBitmapScaler;
+interface IWICBitmapClipper;
+interface IWICBitmapFlipRotator;
+interface IWICStream;
+interface IWICColorContext;
+interface IWICColorTransform;
+interface IWICFastMetadataEncoder;
+interface IWICMetadataQueryReader;
+interface IWICMetadataQueryWriter;
+interface IWICBitmapDecoderInfo;
+
+[
+    object,
+    uuid(00000120-a8f2-4877-ba0a-fd2b6645fb94)
+]
+interface IWICBitmapSource : IUnknown
+{
+    HRESULT GetSize(
+        [out] UINT *puiWidth,
+        [out] UINT *puiHeight);
+
+    HRESULT GetPixelFormat(
+        [out] WICPixelFormatGUID *pPixelFormat);
+
+    HRESULT GetResolution(
+        [out] double *pDpiX,
+        [out] double *pDpiY);
+
+    HRESULT CopyPalette(
+        [in] IWICPalette *pIPalette);
+
+    HRESULT CopyPixels(
+        [in] const WICRect *prc,
+        [in] UINT cbStride,
+        [in] UINT cbBufferSize,
+        [out, size_is(cbBufferSize)] BYTE *pbBuffer);
+}
+
+[
+    object,
+    uuid(00000040-a8f2-4877-ba0a-fd2b6645fb94)
+]
+interface IWICPalette : IUnknown
+{
+    HRESULT InitializePredefined(
+        [in] WICBitmapPaletteType ePaletteType,
+        [in] BOOL fAddTransparentColor);
+
+    HRESULT InitializeCustom(
+        [in, size_is(colorCount)] WICColor *pColors,
+        [in] UINT colorCount);
+
+    HRESULT InitializeFromBitmap(
+        [in] IWICBitmapSource *pISurface,
+        [in] UINT colorCount,
+        [in] BOOL fAddTransparentColor);
+
+    HRESULT InitializeFromPalette(
+        [in] IWICPalette *pIPalette);
+
+    HRESULT GetType(
+        [out] WICBitmapPaletteType *pePaletteType);
+
+    HRESULT GetColorCount(
+        [out] UINT *pcCount);
+
+    HRESULT GetColors(
+        [in] UINT colorCount,
+        [out, size_is(colorCount)] WICColor *pColors,
+        [out] UINT *pcActualColors);
+
+    HRESULT IsBlackWhite(
+        [out] BOOL *pfIsBlackWhite);
+
+    HRESULT IsGrayscale(
+        [out] BOOL *pfIsGrayscale);
+
+    HRESULT HasAlpha(
+        [out] BOOL *pfHasAlpha);
+}
+
+[
+    object,
+    uuid(3b16811b-6a43-4ec9-a813-3d930c13b940)
+]
+interface IWICBitmapFrameDecode : IWICBitmapSource
+{
+    HRESULT GetMetadataQueryReader(
+        [out] IWICMetadataQueryReader **ppIMetadataQueryReader);
+
+    HRESULT GetColorContexts(
+        [in] UINT cCount,
+        [in, out, unique, size_is(cCount)] IWICColorContext **ppIColorContexts,
+        [out] UINT *pcActualCount);
+
+    HRESULT GetThumbnail(
+        [out] IWICBitmapSource **ppIThumbnail);
+}
+
+[
+    object,
+    uuid(9edde9e7-8dee-47ea-99df-e6faf2ed44bf)
+]
+interface IWICBitmapDecoder : IUnknown
+{
+    HRESULT QueryCapability(
+        [in] IStream *pIStream,
+        [out] DWORD *pdwCapability);
+
+    HRESULT Initialize(
+        [in] IStream *pIStream,
+        [in] WICDecodeOptions cacheOptions);
+
+    HRESULT GetContainerFormat(
+        [out] GUID *pguidContainerFormat);
+
+    HRESULT GetDecoderInfo(
+        [out] IWICBitmapDecoderInfo **ppIDecoderInfo);
+
+    HRESULT CopyPalette(
+        [in] IWICPalette *pIPalette);
+
+    HRESULT GetMetadataQueryReader(
+        [out] IWICMetadataQueryReader **ppIMetadataQueryReader);
+
+    HRESULT GetPreview(
+        [out] IWICBitmapSource **ppIBitmapSource);
+
+    HRESULT GetColorContexts(
+        [in] UINT cCount,
+        [in, out, unique, size_is(cCount)] IWICColorContext **ppIColorContexts,
+        [out] UINT *pcActualCount);
+
+    HRESULT GetThumbnail(
+        [out] IWICBitmapSource **ppIThumbnail);
+
+    HRESULT GetFrameCount(
+        [out] UINT *pCount);
+
+    HRESULT GetFrame(
+        [in] UINT index,
+        [out] IWICBitmapFrameDecode **ppIBitmapFrame);
+}
+
+cpp_quote("DEFINE_GUID(CLSID_WICImagingFactory, 0xcacaf262,0x9370,0x4615,0xa1,0x3b,0x9f,0x55,0x39,0xda,0x4c,0x0a);")
+
+[
+    object,
+    uuid(ec5ec8a9-c395-4314-9c77-54d7a935ff70)
+]
+interface IWICImagingFactory : IUnknown
+{
+    HRESULT CreateDecoderFromFilename(
+        [in] LPCWSTR wzFilename,
+        [in, unique] const GUID *pguidVendor,
+        [in] DWORD dwDesiredAccess,
+        [in] WICDecodeOptions metadataOptions,
+        [out, retval] IWICBitmapDecoder **ppIDecoder);
+
+    HRESULT CreateDecoderFromStream(
+        [in] IStream *pIStream,
+        [in, unique] const GUID *pguidVendor,
+        [in] WICDecodeOptions metadataOptions,
+        [out, retval] IWICBitmapDecoder **ppIDecoder);
+
+    HRESULT CreateDecoderFromFileHandle(
+        [in] ULONG_PTR hFile,
+        [in, unique] const GUID *pguidVendor,
+        [in] WICDecodeOptions metadataOptions,
+        [out, retval] IWICBitmapDecoder **ppIDecoder);
+
+    HRESULT CreateComponentInfo(
+        [in] REFCLSID clsidComponent,
+        [out] IWICComponentInfo **ppIInfo);
+
+    HRESULT CreateDecoder(
+        [in] REFGUID guidContainerFormat,
+        [in, unique] const GUID *pguidVendor,
+        [out, retval] IWICBitmapDecoder **ppIDecoder);
+
+    HRESULT CreateEncoder(
+        [in] REFGUID guidContainerFormat,
+        [in, unique] const GUID *pguidVendor,
+        [out, retval] IWICBitmapEncoder **ppIEncoder);
+
+    HRESULT CreatePalette(
+        [out] IWICPalette **ppIPalette);
+
+    HRESULT CreateFormatConverter(
+        [out] IWICFormatConverter **ppIFormatConverter);
+
+    HRESULT CreateBitmapScaler(
+        [out] IWICBitmapScaler **ppIBitmapScaler);
+
+    HRESULT CreateBitmapClipper(
+        [out] IWICBitmapClipper **ppIBitmapClipper);
+
+    HRESULT CreateBitmapFlipRotator(
+        [out] IWICBitmapFlipRotator **ppIBitmapFlipRotator);
+
+    HRESULT CreateStream(
+        [out] IWICStream **ppIWICStream);
+
+    HRESULT CreateColorContext(
+        [out] IWICColorContext **ppIWICColorContext);
+
+    HRESULT CreateColorTransformer(
+        [out] IWICColorTransform **ppIWICColorTransform);
+
+    HRESULT CreateBitmap(
+        [in] UINT uiWidth,
+        [in] UINT uiHeight,
+        [in] REFWICPixelFormatGUID pixelFormat,
+        [in] WICBitmapCreateCacheOption option,
+        [out] IWICBitmap **ppIBitmap);
+
+    HRESULT CreateBitmapFromSource(
+        [in] IWICBitmapSource *piBitmapSource,
+        [in] WICBitmapCreateCacheOption option,
+        [out] IWICBitmap **ppIBitmap);
+
+    HRESULT CreateBitmapFromSourceRect(
+        [in] IWICBitmapSource *piBitmapSource,
+        [in] UINT x,
+        [in] UINT y,
+        [in] UINT width,
+        [in] UINT height,
+        [out] IWICBitmap **ppIBitmap);
+
+    HRESULT CreateBitmapFromMemory(
+        [in] UINT uiWidth,
+        [in] UINT uiHeight,
+        [in] REFWICPixelFormatGUID pixelFormat,
+        [in] UINT cbStride,
+        [in] UINT cbBufferSize,
+        [in, size_is(cbBufferSize)] BYTE *pbBuffer,
+        [out] IWICBitmap **ppIBitmap);
+
+    HRESULT CreateBitmapFromHBITMAP(
+        [in] HBITMAP hBitmap,
+        [in, unique] HPALETTE hPalette,
+        [in] WICBitmapAlphaChannelOption options,
+        [out] IWICBitmap **ppIBitmap);
+
+    HRESULT CreateBitmapFromHICON(
+        [in] HICON hIcon,
+        [out] IWICBitmap **ppIBitmap);
+
+    HRESULT CreateComponentEnumerator(
+        [in] DWORD componentTypes,
+        [in] DWORD options,
+        [out] IEnumUnknown **ppIEnumUnknown);
+
+    HRESULT CreateFastMetadataEncoderFromDecoder(
+        [in] IWICBitmapDecoder *pIDecoder,
+        [out] IWICFastMetadataEncoder **ppIFastEncoder);
+
+    HRESULT CreateFastMetadataEncoderFromFrameDecode(
+        [in] IWICBitmapFrameDecode *pIFrameDecoder,
+        [out] IWICFastMetadataEncoder **ppIFastEncoder);
+
+    HRESULT CreateQueryWriter(
+        [in] REFGUID guidMetadataFormat,
+        [in, unique] const GUID *pguidVendor,
+        [out] IWICMetadataQueryWriter **ppIQueryWriter);
+
+    HRESULT CreateQueryWriterFromReader(
+        [in] IWICMetadataQueryReader *pIQueryReader,
+        [in, unique] const GUID *pguidVendor,
+        [out] IWICMetadataQueryWriter **ppIQueryWriter);
+}
+
+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);")
+cpp_quote("DEFINE_GUID(CLSID_WICIcoDecoder, 0xc61bfcdf,0x2e0f,0x4aad,0xa8,0xd7,0xe0,0x6b,0xaf,0xeb,0xcd,0xfe);")
+cpp_quote("DEFINE_GUID(CLSID_WICJpegDecoder, 0x9456a480,0xe88b,0x43ea,0x9e,0x73,0x0b,0x2d,0x9b,0x71,0xb1,0xca);")
+cpp_quote("DEFINE_GUID(CLSID_WICGifDecoder, 0x381dda3c,0x9ce9,0x4834,0xa2,0x3e,0x1f,0x98,0xf8,0xfc,0x52,0xbe);")
+cpp_quote("DEFINE_GUID(CLSID_WICTiffDecoder, 0xb54e85d9,0xfe23,0x499f,0x8b,0x88,0x6a,0xce,0xa7,0x13,0x75,0x2b);")
+cpp_quote("DEFINE_GUID(CLSID_WICWmpDecoder, 0xa26cec36,0x234c,0x4950,0xae,0x16,0xe3,0x4a,0xac,0xe7,0x1d,0x0d);")
+
+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);")
+cpp_quote("DEFINE_GUID(GUID_ContainerFormatIco, 0xa3a860c4,0x338f,0x4c17,0x91,0x9a,0xfb,0xa4,0xb5,0x62,0x8f,0x21);")
+cpp_quote("DEFINE_GUID(GUID_ContainerFormatJpeg, 0x19e4a5aa,0x5662,0x4fc5,0xa0,0xc0,0x17,0x58,0x02,0x8e,0x10,0x57);")
+cpp_quote("DEFINE_GUID(GUID_ContainerFormatTiff, 0x163bcc30,0xe2e9,0x4f0b,0x96,0x1d,0xa3,0xe9,0xfd,0xb7,0x88,0xa3);")
+cpp_quote("DEFINE_GUID(GUID_ContainerFormatGif, 0x1f8a5601,0x7d4d,0x4cbd,0x9c,0x82,0x1b,0xc8,0xd4,0xee,0xb9,0xa5);")
+cpp_quote("DEFINE_GUID(GUID_ContainerFormatWmp, 0x57a37caa,0x367a,0x4540,0x91,0x6b,0xf1,0x83,0xc5,0x09,0x3a,0x4b);")
+
+cpp_quote("DEFINE_GUID(GUID_VendorMicrosoft, 0xf0e749ca,0xedef,0x4589,0xa7,0x3a,0xee,0x0e,0x62,0x6a,0x2a,0x2b);")
+
+cpp_quote("DEFINE_GUID(CATID_WICBitmapDecoders, 0x7ed96837,0x96f0,0x4812,0xb2,0x11,0xf1,0x3c,0x24,0x11,0x7e,0xd3);")
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincrypt.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincrypt.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wincrypt.h	(revision 21731)
@@ -1042,5 +1042,4 @@
 #define CERT_CHAIN_DISABLE_AUTH_ROOT_AUTO_UPDATE       0x00000100
 #define CERT_CHAIN_TIMESTAMP_TIME                      0x00000200
-    LPFILETIME       pftCacheResync;
 
 typedef struct _CERT_CHAIN_PARA {
@@ -1052,4 +1051,5 @@
     BOOL             fCheckRevocationFreshnessTime;
     DWORD            dwRevocationFreshnessTime;
+    LPFILETIME       pftCacheResync;
 #endif
 } CERT_CHAIN_PARA, *PCERT_CHAIN_PARA;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/exception.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/exception.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/exception.h	(revision 21731)
@@ -223,4 +223,16 @@
 }
 
+static inline EXCEPTION_REGISTRATION_RECORD *__wine_get_frame(void)
+{
+#if defined(__GNUC__) && defined(__i386__)
+    EXCEPTION_REGISTRATION_RECORD *ret;
+    __asm__ __volatile__(".byte 0x64\n\tmovl (0),%0" : "=r" (ret) );
+    return ret;
+#else
+    NT_TIB *teb = (NT_TIB *)NtCurrentTeb();
+    return teb->ExceptionList;
+#endif
+}
+
 /* Exception handling flags - from OS/2 2.0 exception handling */
 
@@ -248,24 +260,34 @@
 NTSYSAPI void WINAPI RtlUnwind(PVOID,PVOID,PEXCEPTION_RECORD,PVOID);
 
+static inline void DECLSPEC_NORETURN __wine_unwind_target(void)
+{
+    __WINE_FRAME *wine_frame = (__WINE_FRAME *)__wine_get_frame();
+    __wine_pop_frame( &wine_frame->frame );
+    siglongjmp( wine_frame->jmp, 1 );
+}
+
 /* wrapper for RtlUnwind since it clobbers registers on Windows */
-static inline void __wine_rtl_unwind( EXCEPTION_REGISTRATION_RECORD* frame, EXCEPTION_RECORD *record )
+static inline void DECLSPEC_NORETURN __wine_rtl_unwind( EXCEPTION_REGISTRATION_RECORD* frame,
+                                                        EXCEPTION_RECORD *record,
+                                                        void (*target)(void) )
 {
 #if defined(__GNUC__) && defined(__i386__)
-    int dummy1, dummy2, dummy3;
+    int dummy1, dummy2, dummy3, dummy4;
     __asm__ __volatile__("pushl %%ebp\n\t"
                          "pushl %%ebx\n\t"
                          "pushl $0\n\t"
+                         "pushl %3\n\t"
                          "pushl %2\n\t"
-                         "pushl $0\n\t"
                          "pushl %1\n\t"
                          "call *%0\n\t"
                          "popl %%ebx\n\t"
                          "popl %%ebp"
-                         : "=a" (dummy1), "=S" (dummy2), "=D" (dummy3)
-                         : "0" (RtlUnwind), "1" (frame), "2" (record)
-                         : "ecx", "edx", "memory" );
+                         : "=a" (dummy1), "=S" (dummy2), "=D" (dummy3), "=c" (dummy4)
+                         : "0" (RtlUnwind), "1" (frame), "2" (target), "3" (record)
+                         : "edx", "memory" );
 #else
-    RtlUnwind( frame, 0, record, 0 );
-#endif
+    RtlUnwind( frame, target, record, 0 );
+#endif
+    for (;;) target();
 }
 
@@ -279,7 +301,5 @@
     wine_frame->ExceptionRecord = wine_frame;
 
-    __wine_rtl_unwind( frame, record );
-    __wine_pop_frame( frame );
-    siglongjmp( wine_frame->jmp, 1 );
+    __wine_rtl_unwind( frame, record, __wine_unwind_target );
 }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/port.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/port.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/port.h	(revision 21731)
@@ -213,27 +213,4 @@
 #define M_PI_2 1.570796326794896619
 #endif
-
-
-/* Macros to define assembler functions somewhat portably */
-
-#if defined(__GNUC__) && !defined(__INTERIX) && !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__APPLE__)
-# define __ASM_GLOBAL_FUNC(name,code) \
-      __asm__( ".text\n\t" \
-               ".align 4\n\t" \
-               ".globl " __ASM_NAME(#name) "\n\t" \
-               __ASM_FUNC(#name) "\n" \
-               __ASM_NAME(#name) ":\n\t" \
-               code \
-               "\n\t.previous" );
-#else  /* defined(__GNUC__) && !defined(__MINGW32__) && !defined(__APPLE__)  */
-# define __ASM_GLOBAL_FUNC(name,code) \
-      void __asm_dummy_##name(void) { \
-          asm( ".align 4\n\t" \
-               ".globl " __ASM_NAME(#name) "\n\t" \
-               __ASM_FUNC(#name) "\n" \
-               __ASM_NAME(#name) ":\n\t" \
-               code ); \
-      }
-#endif  /* __GNUC__ */
 
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/pthread.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/pthread.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/pthread.h	(revision 21731)
@@ -17,4 +17,31 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
+ */
+
+/*
+ * Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+ * other than GPL or LGPL is available it will apply instead, Sun elects to use only
+ * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+ * a choice of LGPL license versions is made available with the language indicating
+ * that LGPLv2 or any later version may be used, or where a choice of which version
+ * of the LGPL is applied is otherwise unspecified.
  */
 
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 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/server_protocol.h	(revision 21731)
@@ -703,4 +703,6 @@
     int          exit_code;
     int          priority;
+    cpu_type_t   cpu;
+    char __pad_60[4];
 };
 
@@ -5320,5 +5322,5 @@
 };
 
-#define SERVER_PROTOCOL_VERSION 386
+#define SERVER_PROTOCOL_VERSION 387
 
 #endif /* __WINE_WINE_SERVER_PROTOCOL_H */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h	(revision 21731)
@@ -1,3 +1,3 @@
-/*** Autogenerated by WIDL 1.1.23 from ../../include/wine/wined3d.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.26 from ../../include/wine/wined3d.idl - Do not edit ***/
 
 #include <rpc.h>
@@ -2243,14 +2243,17 @@
 } WINED3DTRIPATCH_INFO;
 typedef struct _WINED3DADAPTER_IDENTIFIER {
-    char *Driver;
-    char *Description;
-    char *DeviceName;
-    LARGE_INTEGER *DriverVersion;
-    DWORD *VendorId;
-    DWORD *DeviceId;
-    DWORD *SubSysId;
-    DWORD *Revision;
-    GUID *DeviceIdentifier;
-    DWORD *WHQLLevel;
+    char *driver;
+    UINT driver_size;
+    char *description;
+    UINT description_size;
+    char *device_name;
+    UINT device_name_size;
+    LARGE_INTEGER driver_version;
+    DWORD vendor_id;
+    DWORD device_id;
+    DWORD subsystem_id;
+    DWORD revision;
+    GUID device_identifier;
+    DWORD whql_level;
 } WINED3DADAPTER_IDENTIFIER;
 typedef struct _WINED3DPRESENT_PARAMETERS {
@@ -2272,23 +2275,23 @@
 } WINED3DPRESENT_PARAMETERS;
 typedef struct _WINED3DSURFACE_DESC {
-    WINED3DFORMAT *Format;
-    WINED3DRESOURCETYPE *Type;
-    DWORD *Usage;
-    WINED3DPOOL *Pool;
-    UINT *Size;
-    WINED3DMULTISAMPLE_TYPE *MultiSampleType;
-    DWORD *MultiSampleQuality;
-    UINT *Width;
-    UINT *Height;
+    WINED3DFORMAT format;
+    WINED3DRESOURCETYPE resource_type;
+    DWORD usage;
+    WINED3DPOOL pool;
+    UINT size;
+    WINED3DMULTISAMPLE_TYPE multisample_type;
+    DWORD multisample_quality;
+    UINT width;
+    UINT height;
 } WINED3DSURFACE_DESC;
 typedef struct _WINED3DVOLUME_DESC {
-    WINED3DFORMAT *Format;
-    WINED3DRESOURCETYPE *Type;
-    DWORD *Usage;
-    WINED3DPOOL *Pool;
-    UINT *Size;
-    UINT *Width;
-    UINT *Height;
-    UINT *Depth;
+    WINED3DFORMAT Format;
+    WINED3DRESOURCETYPE Type;
+    DWORD Usage;
+    WINED3DPOOL Pool;
+    UINT Size;
+    UINT Width;
+    UINT Height;
+    UINT Depth;
 } WINED3DVOLUME_DESC;
 typedef struct _WINED3DCLIPSTATUS {
@@ -2392,10 +2395,4 @@
     UINT Size;
 } WINED3DBUFFER_DESC;
-typedef struct glDescriptor {
-    UINT textureName;
-    UINT srgbTextureName;
-    int level;
-    int target;
-} glDescriptor;
 typedef struct WineDirect3DStridedData {
     WINED3DFORMAT format;
@@ -3980,7 +3977,4 @@
         IWineD3DBase *container) = 0;
 
-    virtual void STDMETHODCALLTYPE GetGlDesc(
-        glDescriptor **desc) = 0;
-
     virtual const void * STDMETHODCALLTYPE GetData(
         ) = 0;
@@ -4198,8 +4192,4 @@
         IWineD3DSurface* This,
         IWineD3DBase *container);
-
-    void (STDMETHODCALLTYPE *GetGlDesc)(
-        IWineD3DSurface* This,
-        glDescriptor **desc);
 
     const void * (STDMETHODCALLTYPE *GetData)(
@@ -4282,5 +4272,4 @@
 #define IWineD3DSurface_SaveSnapshot(This,filename) (This)->lpVtbl->SaveSnapshot(This,filename)
 #define IWineD3DSurface_SetContainer(This,container) (This)->lpVtbl->SetContainer(This,container)
-#define IWineD3DSurface_GetGlDesc(This,desc) (This)->lpVtbl->GetGlDesc(This,desc)
 #define IWineD3DSurface_GetData(This) (This)->lpVtbl->GetData(This)
 #define IWineD3DSurface_SetFormat(This,format) (This)->lpVtbl->SetFormat(This,format)
@@ -4538,12 +4527,4 @@
     IWineD3DBase *container);
 void __RPC_STUB IWineD3DSurface_SetContainer_Stub(
-    IRpcStubBuffer* This,
-    IRpcChannelBuffer* pRpcChannelBuffer,
-    PRPC_MESSAGE pRpcMessage,
-    DWORD* pdwStubPhase);
-void STDMETHODCALLTYPE IWineD3DSurface_GetGlDesc_Proxy(
-    IWineD3DSurface* This,
-    glDescriptor **desc);
-void __RPC_STUB IWineD3DSurface_GetGlDesc_Stub(
     IRpcStubBuffer* This,
     IRpcChannelBuffer* pRpcChannelBuffer,
@@ -6939,5 +6920,4 @@
         UINT level,
         IWineD3DSurface **surface,
-        WINED3DRESOURCETYPE resource_type,
         DWORD usage,
         WINED3DPOOL pool,
@@ -7551,5 +7531,4 @@
         UINT level,
         IWineD3DSurface **surface,
-        WINED3DRESOURCETYPE resource_type,
         DWORD usage,
         WINED3DPOOL pool,
@@ -8234,5 +8213,5 @@
 #define IWineD3DDevice_CreateIndexBuffer(This,length,usage,pool,index_buffer,parent) (This)->lpVtbl->CreateIndexBuffer(This,length,usage,pool,index_buffer,parent)
 #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,resource_type,usage,pool,multisample_type,multisample_quality,surface_type,parent) (This)->lpVtbl->CreateSurface(This,width,height,format,lockable,discard,level,surface,resource_type,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) (This)->lpVtbl->CreateSurface(This,width,height,format,lockable,discard,level,surface,usage,pool,multisample_type,multisample_quality,surface_type,parent)
 #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)
@@ -8419,5 +8398,4 @@
     UINT level,
     IWineD3DSurface **surface,
-    WINED3DRESOURCETYPE resource_type,
     DWORD usage,
     WINED3DPOOL pool,
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.idl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.idl	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.idl	(revision 21731)
@@ -1701,14 +1701,17 @@
 typedef struct _WINED3DADAPTER_IDENTIFIER
 {
-    char *Driver;
-    char *Description;
-    char *DeviceName;
-    LARGE_INTEGER *DriverVersion;
-    DWORD *VendorId;
-    DWORD *DeviceId;
-    DWORD *SubSysId;
-    DWORD *Revision;
-    GUID *DeviceIdentifier;
-    DWORD *WHQLLevel;
+    char *driver;
+    UINT driver_size;
+    char *description;
+    UINT description_size;
+    char *device_name;
+    UINT device_name_size;
+    LARGE_INTEGER driver_version;
+    DWORD vendor_id;
+    DWORD device_id;
+    DWORD subsystem_id;
+    DWORD revision;
+    GUID device_identifier;
+    DWORD whql_level;
 } WINED3DADAPTER_IDENTIFIER;
 
@@ -1734,25 +1737,25 @@
 typedef struct _WINED3DSURFACE_DESC
 {
-    WINED3DFORMAT *Format;
-    WINED3DRESOURCETYPE *Type;
-    DWORD *Usage;
-    WINED3DPOOL *Pool;
-    UINT *Size;
-    WINED3DMULTISAMPLE_TYPE *MultiSampleType;
-    DWORD *MultiSampleQuality;
-    UINT *Width;
-    UINT *Height;
+    WINED3DFORMAT format;
+    WINED3DRESOURCETYPE resource_type;
+    DWORD usage;
+    WINED3DPOOL pool;
+    UINT size;
+    WINED3DMULTISAMPLE_TYPE multisample_type;
+    DWORD multisample_quality;
+    UINT width;
+    UINT height;
 } WINED3DSURFACE_DESC;
 
 typedef struct _WINED3DVOLUME_DESC
 {
-    WINED3DFORMAT *Format;
-    WINED3DRESOURCETYPE *Type;
-    DWORD *Usage;
-    WINED3DPOOL *Pool;
-    UINT *Size;
-    UINT *Width;
-    UINT *Height;
-    UINT *Depth;
+    WINED3DFORMAT Format;
+    WINED3DRESOURCETYPE Type;
+    DWORD Usage;
+    WINED3DPOOL Pool;
+    UINT Size;
+    UINT Width;
+    UINT Height;
+    UINT Depth;
 } WINED3DVOLUME_DESC;
 
@@ -1892,11 +1895,4 @@
     UINT Size;
 } WINED3DBUFFER_DESC;
-
-typedef struct glDescriptor
-{
-    UINT textureName, srgbTextureName;
-    int level;
-    int /*GLenum*/ target;
-} glDescriptor;
 
 typedef struct WineDirect3DStridedData
@@ -2539,7 +2535,4 @@
         [in] IWineD3DBase *container
     );
-    void GetGlDesc(
-        [out] glDescriptor **desc
-    );
     const void *GetData(
     );
@@ -2942,5 +2935,4 @@
         [in] UINT level,
         [out] IWineD3DSurface **surface,
-        [in] WINED3DRESOURCETYPE resource_type,
         [in] DWORD usage,
         [in] WINED3DPOOL pool,
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wininet.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wininet.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wininet.h	(revision 21731)
@@ -1546,4 +1546,10 @@
 DECL_WINELIB_TYPE_AW(LPINTERNET_CACHE_ENTRY_INFO)
 
+typedef struct _INTERNET_CACHE_TIMESTAMPS
+{
+    FILETIME ftExpires;
+    FILETIME ftLastModified;
+} INTERNET_CACHE_TIMESTAMPS, *LPINTERNET_CACHE_TIMESTAMPS;
+
 BOOLAPI CreateUrlCacheEntryA(LPCSTR ,DWORD ,LPCSTR ,LPSTR ,DWORD);
 BOOLAPI CreateUrlCacheEntryW(LPCWSTR ,DWORD ,LPCWSTR ,LPWSTR ,DWORD);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winineti.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winineti.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winineti.h	(revision 21731)
@@ -91,9 +91,7 @@
 } INTERNET_CACHE_CONFIG_INFOW, *LPINTERNET_CACHE_CONFIG_INFOW;
 
-BOOL        WINAPI GetDiskInfoA(PCSTR,PDWORD,PDWORDLONG,PDWORDLONG);
 DECL_WINELIB_TYPE_AW(INTERNET_CACHE_CONFIG_INFO)
 DECL_WINELIB_TYPE_AW(LPINTERNET_CACHE_CONFIG_INFO)
 
-BOOL        WINAPI IncrementUrlCacheHeaderData(DWORD,LPDWORD);
 
 #ifdef __cplusplus
@@ -102,7 +100,9 @@
 
 DWORD       WINAPI DeleteIE3Cache(HWND,HINSTANCE,LPSTR,int);
+BOOL        WINAPI GetDiskInfoA(PCSTR,PDWORD,PDWORDLONG,PDWORDLONG);
 BOOL        WINAPI GetUrlCacheConfigInfoA(LPINTERNET_CACHE_CONFIG_INFOA,LPDWORD,DWORD);
 BOOL        WINAPI GetUrlCacheConfigInfoW(LPINTERNET_CACHE_CONFIG_INFOW,LPDWORD,DWORD);
 #define     GetUrlCacheConfigInfo WINELIB_NAME_AW(GetUrlCacheConfigInfo)
+BOOL        WINAPI IncrementUrlCacheHeaderData(DWORD,LPDWORD);
 BOOL        WINAPI InternetQueryFortezzaStatus(DWORD*,DWORD_PTR);
 BOOL        WINAPI IsUrlCacheEntryExpiredA(LPCSTR,DWORD,FILETIME*);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winternl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winternl.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/winternl.h	(revision 21731)
@@ -995,9 +995,4 @@
             PULONG64 R11;
             PULONG64 R12;
-#define UNW_FLAG_NHANDLER  0
-#define UNW_FLAG_EHANDLER  1
-#define UNW_FLAG_UHANDLER  2
-#define UNW_FLAG_CHAININFO 4
-
             PULONG64 R13;
             PULONG64 R14;
@@ -1008,4 +1003,9 @@
 
 PVOID WINAPI RtlVirtualUnwind(ULONG,ULONG64,ULONG64,RUNTIME_FUNCTION*,CONTEXT*,PVOID*,ULONG64*,KNONVOLATILE_CONTEXT_POINTERS*);
+
+#define UNW_FLAG_NHANDLER  0
+#define UNW_FLAG_EHANDLER  1
+#define UNW_FLAG_UHANDLER  2
+#define UNW_FLAG_CHAININFO 4
 
 #endif  /* __x86_64 */
@@ -2522,4 +2522,6 @@
 NTSYSAPI NTSTATUS  WINAPI RtlVerifyVersionInfo(const RTL_OSVERSIONINFOEXW*,DWORD,DWORDLONG);
 NTSYSAPI NTSTATUS  WINAPI RtlWalkHeap(HANDLE,PVOID);
+NTSYSAPI NTSTATUS  WINAPI RtlWow64EnableFsRedirection(BOOLEAN);
+NTSYSAPI NTSTATUS  WINAPI RtlWow64EnableFsRedirectionEx(ULONG,ULONG*);
 NTSYSAPI NTSTATUS  WINAPI RtlWriteRegistryValue(ULONG,PCWSTR,PCWSTR,ULONG,PVOID,ULONG);
 NTSYSAPI NTSTATUS  WINAPI RtlpNtCreateKey(PHANDLE,ACCESS_MASK,const OBJECT_ATTRIBUTES*,ULONG,const UNICODE_STRING*,ULONG,PULONG);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wtypes.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wtypes.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wtypes.h	(revision 21731)
@@ -1,3 +1,4 @@
-/*** Autogenerated by WIDL 1.1.23 from ../../../dlls/wined3d/../../include/wtypes.idl - Do not edit ***/
+/*** Autogenerated by WIDL 1.1.26 from ../../include/wtypes.idl - Do not edit ***/
+
 #include <rpc.h>
 #include <rpcndr.h>
@@ -5,15 +6,33 @@
 #ifndef __WIDL_WTYPES_H
 #define __WIDL_WTYPES_H
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+/* Headers for imported files */
+
 #include <basetsd.h>
 #include <guiddef.h>
+
+/* Forward declarations */
+
+
+void * __RPC_USER MIDL_user_allocate(SIZE_T);
+void __RPC_USER MIDL_user_free(void *);
+
+/*****************************************************************************
+ * IWinTypes interface (v0.1)
+ */
+#ifndef __IWinTypes_INTERFACE_DEFINED__
+#define __IWinTypes_INTERFACE_DEFINED__
+
+extern RPC_IF_HANDLE IWinTypes_v0_1_c_ifspec;
+extern RPC_IF_HANDLE IWinTypes_v0_1_s_ifspec;
 #if 0 /* winnt.h */
 typedef unsigned char BYTE;
 typedef unsigned short WORD;
-typedef unsigned long DWORD;
-typedef long BOOL;
+typedef ULONG DWORD;
+typedef LONG BOOL;
 typedef unsigned char UCHAR;
 typedef int INT;
@@ -21,6 +40,6 @@
 typedef short SHORT;
 typedef unsigned short USHORT;
-typedef long LONG;
-typedef unsigned long ULONG;
+typedef LONG LONG;
+typedef ULONG ULONG;
 typedef float FLOAT;
 typedef void *PVOID;
@@ -54,4 +73,5 @@
 typedef LONG HRESULT;
 typedef DWORD LCID;
+typedef USHORT LANGID;
 typedef unsigned __int64 DWORDLONG;
 typedef __int64 LONGLONG;
@@ -319,34 +339,34 @@
 } MSHCTX;
 typedef struct _BYTE_BLOB {
-    unsigned long clSize;
+    ULONG clSize;
     byte abData[1];
 } BYTE_BLOB;
 typedef BYTE_BLOB *UP_BYTE_BLOB;
 typedef struct _FLAGGED_BYTE_BLOB {
-    unsigned long fFlags;
-    unsigned long clSize;
+    ULONG fFlags;
+    ULONG clSize;
     byte abData[1];
 } FLAGGED_BYTE_BLOB;
 typedef FLAGGED_BYTE_BLOB *UP_FLAGGED_BYTE_BLOB;
 typedef struct _FLAGGED_WORD_BLOB {
-    unsigned long fFlags;
-    unsigned long clSize;
+    ULONG fFlags;
+    ULONG clSize;
     unsigned short asData[1];
 } FLAGGED_WORD_BLOB;
 typedef FLAGGED_WORD_BLOB *UP_FLAGGED_WORD_BLOB;
 typedef struct _BYTE_SIZEDARR {
-    unsigned long clSize;
+    ULONG clSize;
     byte *pData;
 } BYTE_SIZEDARR;
 typedef struct _SHORT_SIZEDARR {
-    unsigned long clSize;
+    ULONG clSize;
     unsigned short *pData;
 } WORD_SIZEDARR;
 typedef struct _LONG_SIZEDARR {
-    unsigned long clSize;
-    unsigned long *pData;
+    ULONG clSize;
+    ULONG *pData;
 } DWORD_SIZEDARR;
 typedef struct _HYPER_SIZEDARR {
-    unsigned long clSize;
+    ULONG clSize;
     hyper *pData;
 } HYPER_SIZEDARR;
@@ -358,5 +378,5 @@
 
 typedef struct _userCLIPFORMAT {
-    long fContext;
+    LONG fContext;
     union {
         DWORD dwValue;
@@ -367,63 +387,63 @@
 typedef WORD CLIPFORMAT;
 typedef struct tagRemHGLOBAL {
-    long fNullHGlobal;
-    unsigned long cbData;
+    LONG fNullHGlobal;
+    ULONG cbData;
     byte data[1];
 } RemHGLOBAL;
 typedef struct _userHGLOBAL {
-    long fContext;
-    union {
-        long hInproc;
+    LONG fContext;
+    union {
+        LONG hInproc;
         FLAGGED_BYTE_BLOB *hRemote;
-        long hGlobal;
+        __int64 hInproc64;
     } u;
 } userHGLOBAL;
 typedef userHGLOBAL *wireHGLOBAL;
 typedef struct tagRemHMETAFILEPICT {
-    long mm;
-    long xExt;
-    long yExt;
-    unsigned long cbData;
+    LONG mm;
+    LONG xExt;
+    LONG yExt;
+    ULONG cbData;
     byte data[1];
 } RemHMETAFILEPICT;
 typedef struct _userHMETAFILE {
-    long fContext;
-    union {
-        long hInproc;
+    LONG fContext;
+    union {
+        LONG hInproc;
         BYTE_BLOB *hRemote;
-        long hGlobal;
+        __int64 hInproc64;
     } u;
 } userHMETAFILE;
 typedef userHMETAFILE *wireHMETAFILE;
 typedef struct _remoteMETAFILEPICT {
-    long mm;
-    long xExt;
-    long yExt;
+    LONG mm;
+    LONG xExt;
+    LONG yExt;
     userHMETAFILE *hMF;
 } remoteMETAFILEPICT;
 typedef struct _userHMETAFILEPICT {
-    long fContext;
-    union {
-        long hInproc;
+    LONG fContext;
+    union {
+        LONG hInproc;
         remoteMETAFILEPICT *hRemote;
-        long hGlobal;
+        __int64 hInproc64;
     } u;
 } userHMETAFILEPICT;
 typedef userHMETAFILEPICT *wireHMETAFILEPICT;
 typedef struct tagRemHENHMETAFILE {
-    unsigned long cbData;
+    ULONG cbData;
     byte data[1];
 } RemHENHMETAFILE;
 typedef struct _userHENHMETAFILE {
-    long fContext;
-    union {
-        long hInproc;
+    LONG fContext;
+    union {
+        LONG hInproc;
         BYTE_BLOB *hRemote;
-        long hGlobal;
+        __int64 hInproc64;
     } u;
 } userHENHMETAFILE;
 typedef userHENHMETAFILE *wireHENHMETAFILE;
 typedef struct tagRemHBITMAP {
-    unsigned long cbData;
+    ULONG cbData;
     byte data[1];
 } RemHBITMAP;
@@ -439,14 +459,14 @@
 } userBITMAP;
 typedef struct _userHBITMAP {
-    long fContext;
-    union {
-        long hInproc;
+    LONG fContext;
+    union {
+        LONG hInproc;
         userBITMAP *hRemote;
-        long hGlobal;
+        __int64 hInproc64;
     } u;
 } userHBITMAP;
 typedef userHBITMAP *wireHBITMAP;
 typedef struct tagRemHPALETTE {
-    unsigned long cbData;
+    ULONG cbData;
     byte data[1];
 } RemHPALETTE;
@@ -457,9 +477,9 @@
 } rpcLOGPALETTE;
 typedef struct _userHPALETTE {
-    long fContext;
-    union {
-        long hInproc;
+    LONG fContext;
+    union {
+        LONG hInproc;
         rpcLOGPALETTE *hRemote;
-        long hGlobal;
+        __int64 hInproc64;
     } u;
 } userHPALETTE;
@@ -475,8 +495,8 @@
 typedef void *HMETAFILEPICT;
 typedef struct _RemotableHandle {
-    long fContext;
-    union {
-        long hInproc;
-        long hRemote;
+    LONG fContext;
+    union {
+        LONG hInproc;
+        LONG hRemote;
     } u;
 } RemotableHandle;
@@ -625,5 +645,5 @@
 typedef struct tagCLIPDATA {
     ULONG cbSize;
-    long ulClipFmt;
+    LONG ulClipFmt;
     BYTE *pClipData;
 } CLIPDATA;
@@ -726,15 +746,4 @@
     } tagged_union;
 } uCLSSPEC;
-void * __RPC_USER MIDL_user_allocate(size_t);
-void __RPC_USER MIDL_user_free(void *);
-
-/*****************************************************************************
- * IWinTypes interface (v0.1)
- */
-#ifndef __IWinTypes_INTERFACE_DEFINED__
-#define __IWinTypes_INTERFACE_DEFINED__
-
-extern RPC_IF_HANDLE IWinTypes_v0_1_c_ifspec;
-extern RPC_IF_HANDLE IWinTypes_v0_1_s_ifspec;
 
 #endif  /* __IWinTypes_INTERFACE_DEFINED__ */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/cpmap.pl
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/cpmap.pl	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/cpmap.pl	(revision 21731)
@@ -18,4 +18,13 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+#
+
+#
+# Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+# other than GPL or LGPL is available it will apply instead, Sun elects to use only
+# the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+# a choice of LGPL license versions is made available with the language indicating
+# that LGPLv2 or any later version may be used, or where a choice of which version
+# of the LGPL is applied is otherwise unspecified.
 #
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/defaults
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/defaults	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/defaults	(revision 21731)
@@ -34,4 +34,13 @@
 # are handled automatically and do not have to be defined here. They can
 # still be defined if necessary to override the unicode decomposition.
+#
+
+#
+# Sun LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
+# other than GPL or LGPL is available it will apply instead, Sun elects to use only
+# the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
+# a choice of LGPL license versions is made available with the language indicating
+# that LGPLv2 or any later version may be used, or where a choice of which version
+# of the LGPL is applied is otherwise unspecified.
 #
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/port.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/port.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/port.c	(revision 21731)
@@ -36,7 +36,8 @@
 
 #include "wine/library.h"
-#include "wine/pthread.h"
 
-static struct wine_pthread_functions pthread_functions;
+/* no longer used, for backwards compatibility only */
+struct wine_pthread_functions;
+static void *pthread_functions[8];
 
 /***********************************************************************
@@ -63,28 +64,5 @@
  * Switch to the specified stack and call the function.
  */
-void DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack );
-#if defined(__i386__) && defined(__GNUC__)
-__ASM_GLOBAL_FUNC( wine_switch_to_stack,
-                   "movl 4(%esp),%ecx\n\t"  /* func */
-                   "movl 8(%esp),%edx\n\t"  /* arg */
-                   "movl 12(%esp),%esp\n\t"  /* stack */
-                   "andl $~15,%esp\n\t"
-                   "subl $12,%esp\n\t"
-                   "pushl %edx\n\t"
-                   "xorl %ebp,%ebp\n\t"
-                   "call *%ecx\n\t"
-                   "int $3" /* we never return here */ )
-#elif defined(__i386__) && defined(_MSC_VER)
-__declspec(naked) void wine_switch_to_stack( void (*func)(void *), void *arg, void *stack )
-{
-  __asm mov ecx, 4[esp];
-  __asm mov edx, 8[esp];
-  __asm mov esp, 12[esp];
-  __asm push edx;
-  __asm xor ebp, ebp;
-  __asm call [ecx];
-  __asm int 3;
-}
-#elif defined(__sparc__) && defined(__GNUC__)
+#if defined(__sparc__) && defined(__GNUC__)
 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
                    "mov %o0, %l0\n\t" /* store first argument */
@@ -102,14 +80,4 @@
                    "bctrl\n" /* call ctr */
                    "1:\tb 1b") /* loop */
-#elif defined(__powerpc__) && defined(__GNUC__)
-__ASM_GLOBAL_FUNC( wine_switch_to_stack,
-                   "mtctr 3\n\t" /* func -> ctr */
-                   "mr 3,4\n\t" /* args -> function param 1 (r3) */
-                   "mr 1,5\n\t" /* stack */
-                   "subi 1, 1, 16\n\t" /* allocate space for the callee */
-                   "li 0, 0\n\t" /* load zero */
-                   "stw 0, 0(1)\n\t" /* create a bottom stack frame */
-                   "bctrl\n\t" /* call ctr */
-                   "1:\tb 1b") /* loop */
 #elif defined(__ALPHA__) && defined(__GNUC__)
 __ASM_GLOBAL_FUNC( wine_switch_to_stack,
@@ -119,13 +87,4 @@
                    "jsr $31,($0),0\n\t" /* call func */
                    "L1:\tbr $31,L1") /* loop */
-#elif defined(__x86_64__) && defined(__GNUC__)
-__ASM_GLOBAL_FUNC( wine_switch_to_stack,
-                   "movq %rdi,%rax\n\t" /* func */
-                   "movq %rsi,%rdi\n\t" /* arg */
-                   "andq $~15,%rdx\n\t" /* stack */
-                   "movq %rdx,%rsp\n\t"
-                   "xorq %rbp,%rbp\n\t"
-                   "callq *%rax\n\t"    /* call func */
-                   "int $3")
 #else
 void DECLSPEC_NORETURN wine_switch_to_stack( void (*func)(void *), void *arg, void *stack )
@@ -146,11 +105,17 @@
 __ASM_GLOBAL_FUNC( wine_call_on_stack,
                    "pushl %ebp\n\t"
+                   __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
+                   __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
                    "pushl %esi\n\t"
+                   __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
+                   __ASM_CFI(".cfi_rel_offset %esi,0\n\t")
+                   "movl %esp,%esi\n\t"
+                   __ASM_CFI(".cfi_def_cfa_register %esi\n\t")
                    "movl 12(%esp),%ecx\n\t"  /* func */
                    "movl 16(%esp),%edx\n\t"  /* arg */
-                   "movl 20(%esp),%esi\n\t"  /* stack */
-                   "andl $~15,%esi\n\t"
-                   "subl $12,%esi\n\t"
-                   "xchgl %esi,%esp\n\t"
+                   "movl 20(%esp),%eax\n\t"  /* stack */
+                   "andl $~15,%eax\n\t"
+                   "subl $12,%eax\n\t"
+                   "movl %eax,%esp\n\t"
                    "pushl %edx\n\t"
                    "xorl %ebp,%ebp\n\t"
@@ -158,5 +123,9 @@
                    "movl %esi,%esp\n\t"
                    "popl %esi\n\t"
+                   __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t")
+                   __ASM_CFI(".cfi_same_value %esi\n\t")
                    "popl %ebp\n\t"
+                   __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
+                   __ASM_CFI(".cfi_same_value %ebp\n\t")
                    "ret" )
 #elif defined(__i386__) && defined(_MSC_VER)
@@ -180,15 +149,18 @@
 __ASM_GLOBAL_FUNC( wine_call_on_stack,
                    "pushq %rbp\n\t"
-                   "pushq %rbx\n\t"
-                   "movq %rsp,%rbx\n\t"
+                   ".cfi_adjust_cfa_offset 8\n\t"
+                   ".cfi_rel_offset %rbp,0\n\t"
+                   "movq %rsp,%rbp\n\t"
+                   ".cfi_def_cfa_register %rbp\n\t"
                    "movq %rdi,%rax\n\t" /* func */
                    "movq %rsi,%rdi\n\t" /* arg */
                    "andq $~15,%rdx\n\t" /* stack */
                    "movq %rdx,%rsp\n\t"
-                   "xorq %rbp,%rbp\n\t"
                    "callq *%rax\n\t"    /* call func */
-                   "movq %rbx,%rsp\n\t"
-                   "popq %rbx\n\t"
+                   "movq %rbp,%rsp\n\t"
+                   ".cfi_def_cfa_register %rsp\n\t"
                    "popq %rbp\n\t"
+                   ".cfi_adjust_cfa_offset -8\n\t"
+                   ".cfi_same_value %rbp\n\t"
                    "ret")
 #elif defined(__powerpc__) && defined(__GNUC__)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/version.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/version.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/libWine/version.c	(revision 21731)
@@ -1,1 +1,1 @@
-const char wine_build[] = "wine-1.1.23";
+const char wine_build[] = "wine-1.1.26";
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 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/arb_program_shader.c	(revision 21731)
@@ -52,5 +52,6 @@
 
 /* GL locking for state handlers is done by the caller. */
-static BOOL need_mova_const(IWineD3DBaseShader *shader, const WineD3D_GL_Info *gl_info) {
+static BOOL need_mova_const(IWineD3DBaseShader *shader, const struct wined3d_gl_info *gl_info)
+{
     IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *) shader;
     if(!This->baseShader.reg_maps.usesmova) return FALSE;
@@ -58,8 +59,10 @@
 }
 
-static BOOL need_helper_const(const WineD3D_GL_Info *gl_info) {
-    if(!GL_SUPPORT(NV_VERTEX_PROGRAM)   || /* Need to init colors */
-       gl_info->arb_vs_offset_limit     || /* Have to init texcoords */
-       gl_info->set_texcoord_w) {          /* Load the immval offset */
+static BOOL need_helper_const(const struct wined3d_gl_info *gl_info)
+{
+    if (!GL_SUPPORT(NV_VERTEX_PROGRAM) /* Need to init colors. */
+            || gl_info->quirks & WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT /* Load the immval offset. */
+            || gl_info->quirks & WINED3D_QUIRK_SET_TEXCOORD_W) /* Have to init texcoords. */
+    {
         return TRUE;
     }
@@ -67,5 +70,6 @@
 }
 
-static unsigned int reserved_vs_const(IWineD3DBaseShader *shader, const WineD3D_GL_Info *gl_info) {
+static unsigned int reserved_vs_const(IWineD3DBaseShader *shader, const struct wined3d_gl_info *gl_info)
+{
     unsigned int ret = 1;
     /* We use one PARAM for the pos fixup, and in some cases one to load
@@ -77,4 +81,15 @@
 }
 
+static inline BOOL ffp_clip_emul(IWineD3DStateBlockImpl *stateblock)
+{
+    return stateblock->lowest_disabled_stage < 7;
+}
+
+/* Returns TRUE if result.clip from GL_NV_vertex_program2 should be used and FALSE otherwise */
+static inline BOOL use_nv_clip(const struct wined3d_gl_info *gl_info)
+{
+    return GL_SUPPORT(NV_VERTEX_PROGRAM2_OPTION);
+}
+
 /* Internally used shader constants. Applications can use constants 0 to GL_LIMITS(vshader_constantsF) - 1,
  * so upload them above that
@@ -84,22 +99,111 @@
 
 /* ARB_program_shader private data */
-struct shader_arb_priv {
-    GLuint                  current_vprogram_id;
-    GLuint                  current_fprogram_id;
-    GLuint                  depth_blt_vprogram_id;
-    GLuint                  depth_blt_fprogram_id[tex_type_count];
-    BOOL                    use_arbfp_fixed_func;
-    struct wine_rb_tree     fragment_shaders;
+
+struct loop_control
+{
+    unsigned int count;
+    unsigned int start;
+    int step;
 };
 
-struct if_frame {
+struct control_frame
+{
+    struct                          list entry;
+    enum
+    {
+        IF,
+        IFC,
+        LOOP,
+        REP
+    } type;
+    BOOL                            muting;
+    BOOL                            outer_loop;
+    union
+    {
+        unsigned int                loop_no;
+        unsigned int                ifc_no;
+    };
+    struct loop_control             loop_control;
+    BOOL                            had_else;
+};
+
+struct arb_ps_np2fixup_info
+{
+    struct ps_np2fixup_info         super;
+    /* For ARB we need a offset value:
+     * With both GLSL and ARB mode the NP2 fixup information (the texture dimensions) are stored in a
+     * consecutive way (GLSL uses a uniform array). Since ARB doesn't know the notion of a "standalone"
+     * array we need an offset to the index inside the program local parameter array. */
+    UINT                            offset;
+};
+
+struct arb_ps_compile_args
+{
+    struct ps_compile_args          super;
+    DWORD                           bools; /* WORD is enough, use DWORD for alignment */
+    unsigned char                   loop_ctrl[MAX_CONST_I][3];
+};
+
+struct stb_const_desc
+{
+    unsigned char           texunit;
+    UINT                    const_num;
+};
+
+struct arb_ps_compiled_shader
+{
+    struct arb_ps_compile_args      args;
+    struct arb_ps_np2fixup_info     np2fixup_info;
+    struct stb_const_desc           bumpenvmatconst[MAX_TEXTURES];
+    struct stb_const_desc           luminanceconst[MAX_TEXTURES];
+    UINT                            int_consts[MAX_CONST_I];
+    GLuint                          prgId;
+    UINT                            ycorrection;
+    unsigned char                   numbumpenvmatconsts;
+    char                            num_int_consts;
+};
+
+struct arb_vs_compile_args
+{
+    struct vs_compile_args          super;
+    union
+    {
+        struct
+        {
+            WORD                    bools;
+            char                    clip_control[2];
+        }                           boolclip;
+        DWORD                       boolclip_compare;
+    };
+    DWORD                           ps_signature;
+    union
+    {
+        unsigned char               vertex_samplers[4];
+        DWORD                       vertex_samplers_compare;
+    };
+    unsigned char                   loop_ctrl[MAX_CONST_I][3];
+};
+
+struct arb_vs_compiled_shader
+{
+    struct arb_vs_compile_args      args;
+    GLuint                          prgId;
+    UINT                            int_consts[MAX_CONST_I];
+    char                            num_int_consts;
+    char                            need_color_unclamp;
+    UINT                            pos_fixup;
+};
+
+struct recorded_instruction
+{
+    struct wined3d_shader_instruction ins;
     struct list entry;
-    BOOL ifc;
-    BOOL muting;
 };
 
-struct shader_arb_ctx_priv {
+struct shader_arb_ctx_priv
+{
     char addr_reg[20];
-    enum {
+    enum
+    {
         /* plain GL_ARB_vertex_program or GL_ARB_fragment_program */
         ARB,
@@ -112,16 +216,32 @@
     const struct arb_vs_compile_args    *cur_vs_args;
     const struct arb_ps_compile_args    *cur_ps_args;
-    struct list if_frames;
-    BOOL muted;
+    const struct arb_ps_compiled_shader *compiled_fprog;
+    const struct arb_vs_compiled_shader *compiled_vprog;
+    struct arb_ps_np2fixup_info         *cur_np2fixup_info;
+    struct list                         control_frames;
+    struct list                         record;
+    BOOL                                recording;
+    BOOL                                muted;
+    unsigned int                        num_loops, loop_depth, num_ifcs;
+    int                                 aL;
+
+    unsigned int                        vs_clipplanes;
+    BOOL                                footer_written;
+    BOOL                                in_main_func;
+
+    /* For 3.0 vertex shaders */
+    const char                          *vs_output[MAX_REG_OUTPUT];
+    /* For 2.x and earlier vertex shaders */
+    const char                          *texcrd_output[8], *color_output[2], *fog_output;
+
+    /* 3.0 pshader input for compatibility with fixed function */
+    const char                          *ps_input[MAX_REG_INPUT];
 };
 
-struct arb_ps_compile_args {
-    struct ps_compile_args          super;
-    DWORD                           bools; /* WORD is enough, use DWORD for alignment */
-};
-
-struct arb_ps_compiled_shader {
-    struct arb_ps_compile_args      args;
-    GLuint                          prgId;
+struct ps_signature
+{
+    struct wined3d_shader_signature_element *sig;
+    DWORD                               idx;
+    struct wine_rb_entry                entry;
 };
 
@@ -129,14 +249,8 @@
     struct arb_ps_compiled_shader   *gl_shaders;
     UINT                            num_gl_shaders, shader_array_size;
-};
-
-struct arb_vs_compile_args {
-    struct vs_compile_args          super;
-    DWORD                           bools; /* WORD is enough, use DWORD for alignment */
-};
-
-struct arb_vs_compiled_shader {
-    struct arb_vs_compile_args      args;
-    GLuint                          prgId;
+    BOOL                            has_signature_idx;
+    DWORD                           input_signature_idx;
+    DWORD                           clipplane_emulation;
+    BOOL                            clamp_consts;
 };
 
@@ -144,4 +258,21 @@
     struct arb_vs_compiled_shader   *gl_shaders;
     UINT                            num_gl_shaders, shader_array_size;
+};
+
+struct shader_arb_priv
+{
+    GLuint                  current_vprogram_id;
+    GLuint                  current_fprogram_id;
+    const struct arb_ps_compiled_shader *compiled_fprog;
+    const struct arb_vs_compiled_shader *compiled_vprog;
+    GLuint                  depth_blt_vprogram_id;
+    GLuint                  depth_blt_fprogram_id[tex_type_count];
+    BOOL                    use_arbfp_fixed_func;
+    struct wine_rb_tree     fragment_shaders;
+    BOOL                    last_ps_const_clamped;
+    BOOL                    last_vs_color_unclamp;
+
+    struct wine_rb_tree     signature_tree;
+    DWORD ps_sig_number;
 };
 
@@ -158,5 +289,5 @@
  */
 /* GL locking is done by the caller */
-static unsigned int shader_arb_load_constantsF(IWineD3DBaseShaderImpl* This, const WineD3D_GL_Info *gl_info,
+static unsigned int shader_arb_load_constantsF(IWineD3DBaseShaderImpl *This, const struct wined3d_gl_info *gl_info,
         GLuint target_type, unsigned int max_constants, const float *constants, char *dirty_consts)
 {
@@ -182,18 +313,18 @@
 
             j = 4 * i;
-            if(constants[j + 0] > 1.0) lcl_const[0] = 1.0;
-            else if(constants[j + 0] < -1.0) lcl_const[0] = -1.0;
+            if (constants[j + 0] > 1.0f) lcl_const[0] = 1.0f;
+            else if (constants[j + 0] < -1.0f) lcl_const[0] = -1.0f;
             else lcl_const[0] = constants[j + 0];
 
-            if(constants[j + 1] > 1.0) lcl_const[1] = 1.0;
-            else if(constants[j + 1] < -1.0) lcl_const[1] = -1.0;
+            if (constants[j + 1] > 1.0f) lcl_const[1] = 1.0f;
+            else if (constants[j + 1] < -1.0f) lcl_const[1] = -1.0f;
             else lcl_const[1] = constants[j + 1];
 
-            if(constants[j + 2] > 1.0) lcl_const[2] = 1.0;
-            else if(constants[j + 2] < -1.0) lcl_const[2] = -1.0;
+            if (constants[j + 2] > 1.0f) lcl_const[2] = 1.0f;
+            else if (constants[j + 2] < -1.0f) lcl_const[2] = -1.0f;
             else lcl_const[2] = constants[j + 2];
 
-            if(constants[j + 3] > 1.0) lcl_const[3] = 1.0;
-            else if(constants[j + 3] < -1.0) lcl_const[3] = -1.0;
+            if (constants[j + 3] > 1.0f) lcl_const[3] = 1.0f;
+            else if (constants[j + 3] < -1.0f) lcl_const[3] = -1.0f;
             else lcl_const[3] = constants[j + 3];
 
@@ -260,22 +391,65 @@
     char usePixelShader,
     char useVertexShader) {
-    /* not implemented */
-}
-
+
+    IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl *) device;
+    const struct shader_arb_priv* const priv = (const struct shader_arb_priv *) deviceImpl->shader_priv;
+    IWineD3DStateBlockImpl* stateBlock = deviceImpl->stateBlock;
+    const struct wined3d_gl_info *gl_info = &deviceImpl->adapter->gl_info;
+
+    if (!usePixelShader) {
+        /* NP2 texcoord fixup is (currently) only done for pixelshaders. */
+        return;
+    }
+
+    if (priv->compiled_fprog && priv->compiled_fprog->np2fixup_info.super.active) {
+        const struct arb_ps_np2fixup_info* const fixup = &priv->compiled_fprog->np2fixup_info;
+        UINT i;
+        WORD active = fixup->super.active;
+        GLfloat np2fixup_constants[4 * MAX_FRAGMENT_SAMPLERS];
+
+        for (i = 0; active; active >>= 1, ++i) {
+            const unsigned char idx = fixup->super.idx[i];
+            const IWineD3DTextureImpl* const tex = (const IWineD3DTextureImpl*) stateBlock->textures[i];
+            GLfloat* tex_dim = &np2fixup_constants[(idx >> 1) * 4];
+
+            if (!(active & 1)) continue;
+
+            if (!tex) {
+                FIXME("Nonexistent texture is flagged for NP2 texcoord fixup\n");
+                continue;
+            }
+
+            if (idx % 2) {
+                tex_dim[2] = tex->baseTexture.pow2Matrix[0]; tex_dim[3] = tex->baseTexture.pow2Matrix[5];
+            } else {
+                tex_dim[0] = tex->baseTexture.pow2Matrix[0]; tex_dim[1] = tex->baseTexture.pow2Matrix[5];
+            }
+        }
+
+        for (i = 0; i < fixup->super.num_consts; ++i) {
+            GL_EXTCALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB,
+                                                   fixup->offset + i, &np2fixup_constants[i * 4]));
+        }
+    }
+}
+
+/* GL locking is done by the caller. */
 static inline void shader_arb_ps_local_constants(IWineD3DDeviceImpl* deviceImpl)
 {
     IWineD3DStateBlockImpl* stateBlock = deviceImpl->stateBlock;
-    IWineD3DBaseShaderImpl* pshader = (IWineD3DBaseShaderImpl*) stateBlock->pixelShader;
-    IWineD3DPixelShaderImpl *psi = (IWineD3DPixelShaderImpl *) pshader;
-    const WineD3D_GL_Info *gl_info = &deviceImpl->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &deviceImpl->adapter->gl_info;
     unsigned char i;
-
-    for(i = 0; i < psi->numbumpenvmatconsts; i++)
-    {
+    struct shader_arb_priv *priv = deviceImpl->shader_priv;
+    const struct arb_ps_compiled_shader *gl_shader = priv->compiled_fprog;
+
+    for(i = 0; i < gl_shader->numbumpenvmatconsts; i++)
+    {
+        int texunit = gl_shader->bumpenvmatconst[i].texunit;
+
         /* The state manager takes care that this function is always called if the bump env matrix changes */
-        const float *data = (const float *)&stateBlock->textureState[(int) psi->bumpenvmatconst[i].texunit][WINED3DTSS_BUMPENVMAT00];
-        GL_EXTCALL(glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, psi->bumpenvmatconst[i].const_num, data));
-
-        if (psi->luminanceconst[i].const_num != WINED3D_CONST_NUM_UNUSED)
+        const float *data = (const float *)&stateBlock->textureState[texunit][WINED3DTSS_BUMPENVMAT00];
+        GL_EXTCALL(glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, gl_shader->bumpenvmatconst[i].const_num, data));
+
+        if (gl_shader->luminanceconst[i].const_num != WINED3D_CONST_NUM_UNUSED)
         {
             /* WINED3DTSS_BUMPENVLSCALE and WINED3DTSS_BUMPENVLOFFSET are next to each other.
@@ -284,9 +458,76 @@
              * (they're WINED3DTSS_TEXTURETRANSFORMFLAGS and WINED3DTSS_ADDRESSW, so most likely 0 or NaN
             */
-            const float *scale = (const float *)&stateBlock->textureState[(int) psi->luminanceconst[i].texunit][WINED3DTSS_BUMPENVLSCALE];
-            GL_EXTCALL(glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, psi->luminanceconst[i].const_num, scale));
-        }
-    }
-}
+            const float *scale = (const float *)&stateBlock->textureState[texunit][WINED3DTSS_BUMPENVLSCALE];
+            GL_EXTCALL(glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, gl_shader->luminanceconst[i].const_num, scale));
+        }
+    }
+    checkGLcall("Load bumpmap consts");
+
+    if(gl_shader->ycorrection != WINED3D_CONST_NUM_UNUSED)
+    {
+        /* ycorrection.x: Backbuffer height(onscreen) or 0(offscreen).
+        * ycorrection.y: -1.0(onscreen), 1.0(offscreen)
+        * ycorrection.z: 1.0
+        * ycorrection.w: 0.0
+        */
+        float val[4];
+        val[0] = deviceImpl->render_offscreen ? 0.0f : ((IWineD3DSurfaceImpl *) deviceImpl->render_targets[0])->currentDesc.Height;
+        val[1] = deviceImpl->render_offscreen ? 1.0f : -1.0f;
+        val[2] = 1.0f;
+        val[3] = 0.0f;
+        GL_EXTCALL(glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, gl_shader->ycorrection, val));
+        checkGLcall("y correction loading");
+    }
+
+    if(gl_shader->num_int_consts == 0) return;
+
+    for(i = 0; i < MAX_CONST_I; i++)
+    {
+        if(gl_shader->int_consts[i] != WINED3D_CONST_NUM_UNUSED)
+        {
+            float val[4];
+            val[0] = stateBlock->pixelShaderConstantI[4 * i];
+            val[1] = stateBlock->pixelShaderConstantI[4 * i + 1];
+            val[2] = stateBlock->pixelShaderConstantI[4 * i + 2];
+            val[3] = -1.0f;
+
+            GL_EXTCALL(glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, gl_shader->int_consts[i], val));
+        }
+    }
+    checkGLcall("Load ps int consts");
+}
+
+/* GL locking is done by the caller. */
+static inline void shader_arb_vs_local_constants(IWineD3DDeviceImpl* deviceImpl)
+{
+    IWineD3DStateBlockImpl* stateBlock;
+    const struct wined3d_gl_info *gl_info = &deviceImpl->adapter->gl_info;
+    unsigned char i;
+    struct shader_arb_priv *priv = deviceImpl->shader_priv;
+    const struct arb_vs_compiled_shader *gl_shader = priv->compiled_vprog;
+
+    /* Upload the position fixup */
+    GL_EXTCALL(glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, gl_shader->pos_fixup, deviceImpl->posFixup));
+
+    if(gl_shader->num_int_consts == 0) return;
+
+    stateBlock = deviceImpl->stateBlock;
+
+    for(i = 0; i < MAX_CONST_I; i++)
+    {
+        if(gl_shader->int_consts[i] != WINED3D_CONST_NUM_UNUSED)
+        {
+            float val[4];
+            val[0] = stateBlock->vertexShaderConstantI[4 * i];
+            val[1] = stateBlock->vertexShaderConstantI[4 * i + 1];
+            val[2] = stateBlock->vertexShaderConstantI[4 * i + 2];
+            val[3] = -1.0f;
+
+            GL_EXTCALL(glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, gl_shader->int_consts[i], val));
+        }
+    }
+    checkGLcall("Load vs int consts");
+}
+
 /**
  * Loads the app-supplied constants into the currently set ARB_[vertex/fragment]_programs.
@@ -303,5 +544,5 @@
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) device; 
     IWineD3DStateBlockImpl* stateBlock = deviceImpl->stateBlock;
-    const WineD3D_GL_Info *gl_info = &deviceImpl->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &deviceImpl->adapter->gl_info;
 
     if (useVertexShader) {
@@ -315,6 +556,5 @@
                 deviceImpl->activeContext->vshader_const_dirty);
 
-        /* Upload the position fixup */
-        GL_EXTCALL(glProgramEnvParameter4fvARB(GL_VERTEX_PROGRAM_ARB, ARB_SHADER_PRIVCONST_POS, deviceImpl->posFixup));
+        shader_arb_vs_local_constants(deviceImpl);
     }
 
@@ -340,5 +580,5 @@
     memset(This->activeContext->vshader_const_dirty + start, 1,
             sizeof(*This->activeContext->vshader_const_dirty) * count);
-    This->highest_dirty_vs_const = max(This->highest_dirty_vs_const, start + count + 1);
+    This->highest_dirty_vs_const = max(This->highest_dirty_vs_const, start + count);
 }
 
@@ -351,5 +591,5 @@
     memset(This->activeContext->pshader_const_dirty + start, 1,
             sizeof(*This->activeContext->pshader_const_dirty) * count);
-    This->highest_dirty_ps_const = max(This->highest_dirty_ps_const, start + count + 1);
+    This->highest_dirty_ps_const = max(This->highest_dirty_ps_const, start + count);
 }
 
@@ -375,9 +615,10 @@
 
 /* Generate the variable & register declarations for the ARB_vertex_program output target */
-static void shader_generate_arb_declarations(IWineD3DBaseShader *iface, const shader_reg_maps *reg_maps,
-        SHADER_BUFFER *buffer, const WineD3D_GL_Info *gl_info, DWORD *lconst_map)
+static DWORD shader_generate_arb_declarations(IWineD3DBaseShader *iface, const shader_reg_maps *reg_maps,
+        struct wined3d_shader_buffer *buffer, const struct wined3d_gl_info *gl_info, DWORD *lconst_map,
+        DWORD *num_clipplanes, struct shader_arb_ctx_priv *ctx)
 {
     IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
-    DWORD i, cur, next_local = 0;
+    DWORD i, next_local = 0;
     char pshader = shader_is_pshader_version(reg_maps->shader_version.type);
     unsigned max_constantsF;
@@ -398,8 +639,29 @@
     } else {
         if(This->baseShader.reg_maps.usesrelconstF) {
+            DWORD highest_constf = 0, clip_limit;
             max_constantsF = GL_LIMITS(vshader_constantsF) - reserved_vs_const(iface, gl_info);
-            if(GL_SUPPORT(NV_VERTEX_PROGRAM2_OPTION)) max_constantsF -= GL_LIMITS(clipplanes);
-        } else {
-            max_constantsF = GL_LIMITS(vshader_constantsF) - 1;
+            max_constantsF -= count_bits(This->baseShader.reg_maps.integer_constants);
+
+            for(i = 0; i < This->baseShader.limits.constant_float; i++)
+            {
+                DWORD idx = i >> 5;
+                DWORD shift = i & 0x1f;
+                if(reg_maps->constf[idx] & (1 << shift)) highest_constf = i;
+            }
+
+            clip_limit = GL_LIMITS(clipplanes);
+            if(ctx->target_version == ARB) clip_limit = min(clip_limit, 4);
+            *num_clipplanes = min(clip_limit, max_constantsF - highest_constf - 1);
+            max_constantsF -= *num_clipplanes;
+            if(*num_clipplanes < clip_limit)
+            {
+                WARN("Only %u clipplanes out of %u enabled\n", *num_clipplanes, GL_LIMITS(clipplanes));
+            }
+        }
+        else
+        {
+            if(ctx->target_version >= NV2) *num_clipplanes = GL_LIMITS(clipplanes);
+            else *num_clipplanes = min(GL_LIMITS(clipplanes), 4);
+            max_constantsF = GL_LIMITS(vshader_constantsF);
         }
     }
@@ -454,35 +716,5 @@
     }
 
-    for(i = 0; i < (sizeof(reg_maps->bumpmat) / sizeof(reg_maps->bumpmat[0])); i++) {
-        IWineD3DPixelShaderImpl *ps = (IWineD3DPixelShaderImpl *) This;
-        if(!reg_maps->bumpmat[i]) continue;
-
-        cur = ps->numbumpenvmatconsts;
-        ps->bumpenvmatconst[cur].const_num = -1;
-        ps->bumpenvmatconst[cur].texunit = i;
-        ps->luminanceconst[cur].const_num = -1;
-        ps->luminanceconst[cur].texunit = i;
-
-        /* We can fit the constants into the constant limit for sure because texbem, texbeml, bem and beml are only supported
-         * in 1.x shaders, and GL_ARB_fragment_program has a constant limit of 24 constants. So in the worst case we're loading
-         * 8 shader constants, 8 bump matrices and 8 luminance parameters and are perfectly fine. (No NP2 fixup on bumpmapped
-         * textures due to conditional NP2 restrictions)
-         *
-         * Use local constants to load the bump env parameters, not program.env. This avoids collisions with d3d constants of
-         * shaders in newer shader models. Since the bump env parameters have to share their space with NP2 fixup constants,
-         * their location is shader dependent anyway and they cannot be loaded globally.
-         */
-        ps->bumpenvmatconst[cur].const_num = next_local++;
-        shader_addline(buffer, "PARAM bumpenvmat%d = program.local[%d];\n",
-                       i, ps->bumpenvmatconst[cur].const_num);
-        ps->numbumpenvmatconsts = cur + 1;
-
-        if(!reg_maps->luminanceparams[i]) continue;
-
-        ((IWineD3DPixelShaderImpl *)This)->luminanceconst[cur].const_num = next_local++;
-        shader_addline(buffer, "PARAM luminance%d = program.local[%d];\n",
-                        i, ps->luminanceconst[cur].const_num);
-    }
-
+    return next_local;
 }
 
@@ -559,5 +791,5 @@
 {
     struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
 
     if(strcmp(priv->addr_reg, src) == 0) return;
@@ -590,6 +822,79 @@
             if (pshader)
             {
-                if (reg->idx == 0) strcpy(register_name, "fragment.color.primary");
-                else strcpy(register_name, "fragment.color.secondary");
+                if(This->baseShader.reg_maps.shader_version.major < 3)
+                {
+                    if (reg->idx == 0) strcpy(register_name, "fragment.color.primary");
+                    else strcpy(register_name, "fragment.color.secondary");
+                }
+                else
+                {
+                    if(reg->rel_addr)
+                    {
+                        char rel_reg[50];
+                        shader_arb_get_src_param(ins, reg->rel_addr, 0, rel_reg);
+
+                        if(strcmp(rel_reg, "**aL_emul**") == 0)
+                        {
+                            DWORD idx = ctx->aL + reg->idx;
+                            if(idx < MAX_REG_INPUT)
+                            {
+                                strcpy(register_name, ctx->ps_input[idx]);
+                            }
+                            else
+                            {
+                                ERR("Pixel shader input register out of bounds: %u\n", idx);
+                                sprintf(register_name, "out_of_bounds_%u", idx);
+                            }
+                        }
+                        else if(This->baseShader.reg_maps.input_registers & 0x0300)
+                        {
+                            /* There are two ways basically:
+                             *
+                             * 1) Use the unrolling code that is used for loop emulation and unroll the loop.
+                             *    That means trouble if the loop also contains a breakc or if the control values
+                             *    aren't local constants.
+                             * 2) Generate an if block that checks if aL.y < 8, == 8 or == 9 and selects the
+                             *    source dynamically. The trouble is that we cannot simply read aL.y because it
+                             *    is an ADDRESS register. We could however push it, load .zw with a value and use
+                             *    ADAC to load the condition code register and pop it again afterwards
+                             */
+                            FIXME("Relative input register addressing with more than 8 registers\n");
+
+                            /* This is better than nothing for now */
+                            sprintf(register_name, "fragment.texcoord[%s + %u]", rel_reg, reg->idx);
+                        }
+                        else if(ctx->cur_ps_args->super.vp_mode != vertexshader)
+                        {
+                            /* This is problematic because we'd have to consult the ctx->ps_input strings
+                             * for where to find the varying. Some may be "0.0", others can be texcoords or
+                             * colors. This needs either a pipeline replacement to make the vertex shader feed
+                             * proper varyings, or loop unrolling
+                             *
+                             * For now use the texcoords and hope for the best
+                             */
+                            FIXME("Non-vertex shader varying input with indirect addressing\n");
+                            sprintf(register_name, "fragment.texcoord[%s + %u]", rel_reg, reg->idx);
+                        }
+                        else
+                        {
+                            /* D3D supports indirect addressing only with aL in loop registers. The loop instruction
+                             * pulls GL_NV_fragment_program2 in
+                             */
+                            sprintf(register_name, "fragment.texcoord[%s + %u]", rel_reg, reg->idx);
+                        }
+                    }
+                    else
+                    {
+                        if(reg->idx < MAX_REG_INPUT)
+                        {
+                            strcpy(register_name, ctx->ps_input[reg->idx]);
+                        }
+                        else
+                        {
+                            ERR("Pixel shader input register out of bounds: %u\n", reg->idx);
+                            sprintf(register_name, "out_of_bounds_%u", reg->idx);
+                        }
+                    }
+                }
             }
             else
@@ -603,4 +908,5 @@
             if (!pshader && reg->rel_addr)
             {
+                BOOL aL = FALSE;
                 char rel_reg[50];
                 UINT rel_offset = ((IWineD3DVertexShaderImpl *)This)->rel_offset;
@@ -610,9 +916,15 @@
                     shader_arb_get_src_param(ins, reg->rel_addr, 0, rel_reg);
                     if(ctx->target_version == ARB) {
-                        shader_arb_request_a0(ins, rel_reg);
-                        sprintf(rel_reg, "A0.x");
+                        if(strcmp(rel_reg, "**aL_emul**") == 0) {
+                            aL = TRUE;
+                        } else {
+                            shader_arb_request_a0(ins, rel_reg);
+                            sprintf(rel_reg, "A0.x");
+                        }
                     }
                 }
-                if (reg->idx >= rel_offset)
+                if(aL)
+                    sprintf(register_name, "C[%u]", ctx->aL + reg->idx);
+                else if (reg->idx >= rel_offset)
                     sprintf(register_name, "C[%s + %u]", rel_reg, reg->idx - rel_offset);
                 else
@@ -656,9 +968,14 @@
 
         case WINED3DSPR_COLOROUT:
-            if (reg->idx == 0)
+            if(ctx->cur_ps_args->super.srgb_correction && reg->idx == 0)
             {
-                if(ctx->cur_ps_args->super.srgb_correction)
+                strcpy(register_name, "TMP_COLOR");
+            }
+            else
+            {
+                if(ctx->cur_ps_args->super.srgb_correction) FIXME("sRGB correction on higher render targets\n");
+                if(This->baseShader.reg_maps.highest_render_target > 0)
                 {
-                    strcpy(register_name, "TMP_COLOR");
+                    sprintf(register_name, "result.color[%u]", reg->idx);
                 }
                 else
@@ -667,14 +984,9 @@
                 }
             }
-            else
-            {
-                /* TODO: See GL_ARB_draw_buffers */
-                FIXME("Unsupported write to render target %u\n", reg->idx);
-                sprintf(register_name, "unsupported_register");
-            }
             break;
 
         case WINED3DSPR_RASTOUT:
-            sprintf(register_name, "%s", rastout_reg_names[reg->idx]);
+            if(reg->idx == 1) sprintf(register_name, "%s", ctx->fog_output);
+            else sprintf(register_name, "%s", rastout_reg_names[reg->idx]);
             break;
 
@@ -684,12 +996,64 @@
 
         case WINED3DSPR_ATTROUT:
+        /* case WINED3DSPR_OUTPUT: */
             if (pshader) sprintf(register_name, "oD[%u]", reg->idx);
-            else if (reg->idx == 0) strcpy(register_name, "result.color.primary");
-            else strcpy(register_name, "result.color.secondary");
+            else strcpy(register_name, ctx->color_output[reg->idx]);
             break;
 
         case WINED3DSPR_TEXCRDOUT:
-            if (pshader) sprintf(register_name, "oT[%u]", reg->idx);
-            else sprintf(register_name, "result.texcoord[%u]", reg->idx);
+            if (pshader)
+            {
+                sprintf(register_name, "oT[%u]", reg->idx);
+            }
+            else
+            {
+                if(This->baseShader.reg_maps.shader_version.major < 3)
+                {
+                    strcpy(register_name, ctx->texcrd_output[reg->idx]);
+                }
+                else
+                {
+                    strcpy(register_name, ctx->vs_output[reg->idx]);
+                }
+            }
+            break;
+
+        case WINED3DSPR_LOOP:
+            if(ctx->target_version >= NV2)
+            {
+                /* Pshader has an implicitly declared loop index counter A0.x that cannot be renamed */
+                if(pshader) sprintf(register_name, "A0.x");
+                else sprintf(register_name, "aL.y");
+            }
+            else
+            {
+                /* Unfortunately this code cannot return the value of ctx->aL here. An immediate value
+                 * would be valid, but if aL is used for indexing(its only use), there's likely an offset,
+                 * thus the result would be something like C[15 + 30], which is not valid in the ARB program
+                 * grammar. So return a marker for the emulated aL and intercept it in constant and varying
+                 * indexing
+                 */
+                sprintf(register_name, "**aL_emul**");
+            }
+
+            break;
+
+        case WINED3DSPR_CONSTINT:
+            sprintf(register_name, "I%u", reg->idx);
+            break;
+
+        case WINED3DSPR_MISCTYPE:
+            if(reg->idx == 0)
+            {
+                sprintf(register_name, "vpos");
+            }
+            else if(reg->idx == 1)
+            {
+                sprintf(register_name, "fragment.facing.x");
+            }
+            else
+            {
+                FIXME("Unknown MISCTYPE register index %u\n", reg->idx);
+            }
             break;
 
@@ -731,6 +1095,6 @@
 }
 
-static void gen_color_correction(SHADER_BUFFER *buffer, const char *reg, DWORD dst_mask,
-                                 const char *one, const char *two, struct color_fixup_desc fixup)
+static void gen_color_correction(struct wined3d_shader_buffer *buffer, const char *reg,
+        DWORD dst_mask, const char *one, const char *two, struct color_fixup_desc fixup)
 {
     DWORD mask;
@@ -783,13 +1147,61 @@
 }
 
+static const char *shader_arb_get_modifier(const struct wined3d_shader_instruction *ins)
+{
+    DWORD mod;
+    struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
+    if (!ins->dst_count) return "";
+
+    mod = ins->dst[0].modifiers;
+
+    /* Silently ignore PARTIALPRECISION if its not supported */
+    if(priv->target_version == ARB) mod &= ~WINED3DSPDM_PARTIALPRECISION;
+
+    if(mod & WINED3DSPDM_MSAMPCENTROID)
+    {
+        FIXME("Unhandled modifier WINED3DSPDM_MSAMPCENTROID\n");
+        mod &= ~WINED3DSPDM_MSAMPCENTROID;
+    }
+
+    switch(mod)
+    {
+        case WINED3DSPDM_SATURATE | WINED3DSPDM_PARTIALPRECISION:
+            return "H_SAT";
+
+        case WINED3DSPDM_SATURATE:
+            return "_SAT";
+
+        case WINED3DSPDM_PARTIALPRECISION:
+            return "H";
+
+        case 0:
+            return "";
+
+        default:
+            FIXME("Unknown modifiers 0x%08x\n", mod);
+            return "";
+    }
+}
+
+#define TEX_PROJ        0x1
+#define TEX_BIAS        0x2
+#define TEX_LOD         0x4
+#define TEX_DERIV       0x10
+
 static void shader_hw_sample(const struct wined3d_shader_instruction *ins, DWORD sampler_idx,
-        const char *dst_str, const char *coord_reg, BOOL projected, BOOL bias)
-{
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+        const char *dst_str, const char *coord_reg, WORD flags, const char *dsx, const char *dsy)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     DWORD sampler_type = ins->ctx->reg_maps->sampler_type[sampler_idx];
     const char *tex_type;
+    BOOL np2_fixup = FALSE;
     IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device;
     struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
+    const char *mod;
+    BOOL pshader = shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type);
+
+    /* D3D vertex shader sampler IDs are vertex samplers(0-3), not global d3d samplers */
+    if(!pshader) sampler_idx += MAX_FRAGMENT_SAMPLERS;
 
     switch(sampler_type) {
@@ -807,7 +1219,8 @@
             if (shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type))
             {
-                if(priv->cur_ps_args->super.np2_fixup & (1 << sampler_idx))
+                if (priv->cur_np2fixup_info->super.active & (1 << sampler_idx))
                 {
-                    FIXME("NP2 texcoord fixup is currently not implemented in ARB mode (use GLSL instead).\n");
+                    if (flags) FIXME("Only ordinary sampling from NP2 textures is supported.\n");
+                    else np2_fixup = TRUE;
                 }
             }
@@ -827,16 +1240,56 @@
     }
 
-    if (bias) {
+    /* TEX, TXL, TXD and TXP do not support the "H" modifier,
+     * so don't use shader_arb_get_modifier
+     */
+    if(ins->dst[0].modifiers & WINED3DSPDM_SATURATE) mod = "_SAT";
+    else mod = "";
+
+    /* Fragment samplers always have indentity mapping */
+    if(sampler_idx >= MAX_FRAGMENT_SAMPLERS)
+    {
+        sampler_idx = priv->cur_vs_args->vertex_samplers[sampler_idx - MAX_FRAGMENT_SAMPLERS];
+    }
+
+    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");
+        shader_addline(buffer, "TXD%s %s, %s, %s, %s, texture[%u], %s;\n", mod, dst_str, coord_reg,
+                       dsx, dsy,sampler_idx, tex_type);
+    }
+    else if(flags & TEX_LOD)
+    {
+        if(flags & TEX_PROJ) FIXME("Projected texture sampling with explicit lod\n");
+        if(flags & TEX_BIAS) FIXME("Biased texture sampling with explicit lod\n");
+        shader_addline(buffer, "TXL%s %s, %s, texture[%u], %s;\n", mod, dst_str, coord_reg,
+                       sampler_idx, tex_type);
+    }
+    else if (flags & TEX_BIAS)
+    {
         /* Shouldn't be possible, but let's check for it */
-        if(projected) FIXME("Biased and Projected texture sampling\n");
+        if(flags & TEX_PROJ) FIXME("Biased and Projected texture sampling\n");
         /* TXB takes the 4th component of the source vector automatically, as d3d. Nothing more to do */
-        shader_addline(buffer, "TXB %s, %s, texture[%u], %s;\n", dst_str, coord_reg, sampler_idx, tex_type);
-    } else if (projected) {
-        shader_addline(buffer, "TXP %s, %s, texture[%u], %s;\n", dst_str, coord_reg, sampler_idx, tex_type);
-    } else {
-        shader_addline(buffer, "TEX %s, %s, texture[%u], %s;\n", dst_str, coord_reg, sampler_idx, tex_type);
-    }
-
-    if (shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type))
+        shader_addline(buffer, "TXB%s %s, %s, texture[%u], %s;\n", mod, dst_str, coord_reg, sampler_idx, tex_type);
+    }
+    else if (flags & TEX_PROJ)
+    {
+        shader_addline(buffer, "TXP%s %s, %s, texture[%u], %s;\n", mod, dst_str, coord_reg, sampler_idx, tex_type);
+    }
+    else
+    {
+        if (np2_fixup)
+        {
+            const unsigned char idx = priv->cur_np2fixup_info->super.idx[sampler_idx];
+            shader_addline(buffer, "MUL TA, np2fixup[%u].%s, %s;\n", idx >> 1,
+                           (idx % 2) ? "zwxy" : "xyzw", coord_reg);
+
+            shader_addline(buffer, "TEX%s %s, TA, texture[%u], %s;\n", mod, dst_str, sampler_idx, tex_type);
+        }
+        else
+            shader_addline(buffer, "TEX%s %s, %s, texture[%u], %s;\n", mod, dst_str, coord_reg, sampler_idx, tex_type);
+    }
+
+    if (pshader)
     {
         gen_color_correction(buffer, dst_str, ins->dst[0].write_mask,
@@ -853,5 +1306,5 @@
     char swzstr[20];
     int insert_line;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     struct shader_arb_ctx_priv *ctx = ins->ctx->backend_data;
 
@@ -929,33 +1382,8 @@
 }
 
-static const char *shader_arb_get_modifier(const struct wined3d_shader_instruction *ins)
-{
-    DWORD mod;
-    const char *ret = "";
-    if (!ins->dst_count) return "";
-
-    mod = ins->dst[0].modifiers;
-    if(mod & WINED3DSPDM_SATURATE) {
-        ret = "_SAT";
-        mod &= ~WINED3DSPDM_SATURATE;
-    }
-    if(mod & WINED3DSPDM_PARTIALPRECISION) {
-        FIXME("Unhandled modifier WINED3DSPDM_PARTIALPRECISION\n");
-        mod &= ~WINED3DSPDM_PARTIALPRECISION;
-    }
-    if(mod & WINED3DSPDM_MSAMPCENTROID) {
-        FIXME("Unhandled modifier WINED3DSPDM_MSAMPCENTROID\n");
-        mod &= ~WINED3DSPDM_MSAMPCENTROID;
-    }
-    if(mod) {
-        FIXME("Unknown modifiers 0x%08x\n", mod);
-    }
-    return ret;
-}
-
 static void pshader_hw_bem(const struct wined3d_shader_instruction *ins)
 {
     const struct wined3d_shader_dst_param *dst = &ins->dst[0];
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char dst_name[50];
     char src_name[2][50];
@@ -980,12 +1408,36 @@
 }
 
+static DWORD negate_modifiers(DWORD mod, char *extra_char)
+{
+    *extra_char = ' ';
+    switch(mod)
+    {
+        case WINED3DSPSM_NONE:      return WINED3DSPSM_NEG;
+        case WINED3DSPSM_NEG:       return WINED3DSPSM_NONE;
+        case WINED3DSPSM_BIAS:      return WINED3DSPSM_BIASNEG;
+        case WINED3DSPSM_BIASNEG:   return WINED3DSPSM_BIAS;
+        case WINED3DSPSM_SIGN:      return WINED3DSPSM_SIGNNEG;
+        case WINED3DSPSM_SIGNNEG:   return WINED3DSPSM_SIGN;
+        case WINED3DSPSM_COMP:      *extra_char = '-'; return WINED3DSPSM_COMP;
+        case WINED3DSPSM_X2:        return WINED3DSPSM_X2NEG;
+        case WINED3DSPSM_X2NEG:     return WINED3DSPSM_X2;
+        case WINED3DSPSM_DZ:        *extra_char = '-'; return WINED3DSPSM_DZ;
+        case WINED3DSPSM_DW:        *extra_char = '-'; return WINED3DSPSM_DW;
+        case WINED3DSPSM_ABS:       return WINED3DSPSM_ABSNEG;
+        case WINED3DSPSM_ABSNEG:    return WINED3DSPSM_ABS;
+    }
+    FIXME("Unknown modifier %u\n", mod);
+    return mod;
+}
+
 static void pshader_hw_cnd(const struct wined3d_shader_instruction *ins)
 {
     const struct wined3d_shader_dst_param *dst = &ins->dst[0];
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char dst_name[50];
     char src_name[3][50];
     DWORD shader_version = WINED3D_SHADER_VERSION(ins->ctx->reg_maps->shader_version.major,
             ins->ctx->reg_maps->shader_version.minor);
+    BOOL is_color;
 
     shader_arb_get_dst_param(ins, dst, dst_name);
@@ -997,9 +1449,22 @@
         shader_addline(buffer, "MOV%s %s, %s;\n", shader_arb_get_modifier(ins), dst_name, src_name[1]);
     } else {
-        shader_arb_get_src_param(ins, &ins->src[0], 0, src_name[0]);
+        struct wined3d_shader_src_param src0_copy = ins->src[0];
+        char extra_neg;
+
+        /* src0 may have a negate srcmod set, so we can't blindly add "-" to the name */
+        src0_copy.modifiers = negate_modifiers(src0_copy.modifiers, &extra_neg);
+
+        shader_arb_get_src_param(ins, &src0_copy, 0, src_name[0]);
         shader_arb_get_src_param(ins, &ins->src[2], 2, src_name[2]);
-        shader_addline(buffer, "ADD TA, -%s, coefdiv.x;\n", src_name[0]);
-        shader_addline(buffer, "CMP%s %s, TA, %s, %s;\n",
-                       shader_arb_get_modifier(ins), dst_name, src_name[1], src_name[2]);
+        shader_addline(buffer, "ADD TA, %c%s, coefdiv.x;\n", extra_neg, src_name[0]);
+        /* No modifiers supported on CMP */
+        shader_addline(buffer, "CMP %s, TA, %s, %s;\n", dst_name, src_name[1], src_name[2]);
+
+        /* _SAT on CMP doesn't make much sense, but it is not a pure NOP */
+        if(ins->dst[0].modifiers & WINED3DSPDM_SATURATE)
+        {
+            shader_arb_get_register_name(ins, &dst->reg, src_name[0], &is_color);
+            shader_addline(buffer, "MOV_SAT %s, %s;\n", dst_name, dst_name);
+        }
     }
 }
@@ -1008,7 +1473,8 @@
 {
     const struct wined3d_shader_dst_param *dst = &ins->dst[0];
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char dst_name[50];
     char src_name[3][50];
+    BOOL is_color;
 
     shader_arb_get_dst_param(ins, dst, dst_name);
@@ -1019,6 +1485,13 @@
     shader_arb_get_src_param(ins, &ins->src[2], 2, src_name[2]);
 
-    shader_addline(buffer, "CMP%s %s, %s, %s, %s;\n", shader_arb_get_modifier(ins), dst_name,
+    /* No modifiers are supported on CMP */
+    shader_addline(buffer, "CMP %s, %s, %s, %s;\n", dst_name,
                    src_name[0], src_name[2], src_name[1]);
+
+    if(ins->dst[0].modifiers & WINED3DSPDM_SATURATE)
+    {
+        shader_arb_get_register_name(ins, &dst->reg, src_name[0], &is_color);
+        shader_addline(buffer, "MOV_SAT %s, %s;\n", dst_name, src_name[0]);
+    }
 }
 
@@ -1028,5 +1501,5 @@
 {
     const struct wined3d_shader_dst_param *dst = &ins->dst[0];
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char dst_name[50];
     char src_name[3][50];
@@ -1081,5 +1554,5 @@
 static void shader_hw_map2gl(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     const char *instruction;
     char arguments[256], dst_str[50];
@@ -1095,10 +1568,6 @@
         case WINED3DSIH_DP4: instruction = "DP4"; break;
         case WINED3DSIH_DST: instruction = "DST"; break;
-        case WINED3DSIH_EXP: instruction = "EX2"; break;
-        case WINED3DSIH_EXPP: instruction = "EXP"; break;
         case WINED3DSIH_FRC: instruction = "FRC"; break;
         case WINED3DSIH_LIT: instruction = "LIT"; break;
-        case WINED3DSIH_LOG: instruction = "LG2"; break;
-        case WINED3DSIH_LOGP: instruction = "LOG"; break;
         case WINED3DSIH_LRP: instruction = "LRP"; break;
         case WINED3DSIH_MAD: instruction = "MAD"; break;
@@ -1107,5 +1576,4 @@
         case WINED3DSIH_MOV: instruction = "MOV"; break;
         case WINED3DSIH_MUL: instruction = "MUL"; break;
-        case WINED3DSIH_POW: instruction = "POW"; break;
         case WINED3DSIH_SGE: instruction = "SGE"; break;
         case WINED3DSIH_SLT: instruction = "SLT"; break;
@@ -1134,5 +1602,5 @@
 static void shader_hw_nop(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     shader_addline(buffer, "NOP;\n");
 }
@@ -1144,9 +1612,8 @@
     struct shader_arb_ctx_priv *ctx = ins->ctx->backend_data;
 
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char src0_param[256];
 
     if(ins->handler_idx == WINED3DSIH_MOVA) {
-        struct wined3d_shader_src_param tmp_src = ins->src[0];
         char write_mask[6];
 
@@ -1155,6 +1622,5 @@
             return;
         }
-        tmp_src.swizzle = (tmp_src.swizzle & 0x3) * 0x55;
-        shader_arb_get_src_param(ins, &tmp_src, 0, src0_param);
+        shader_arb_get_src_param(ins, &ins->src[0], 0, src0_param);
         shader_arb_get_write_mask(ins, &ins->dst[0], write_mask);
 
@@ -1175,4 +1641,8 @@
         shader_addline(buffer, "ADD TA%s, TA, mova_const.x;\n", write_mask);
         shader_addline(buffer, "FLR TA%s, TA;\n", write_mask);
+        if (((IWineD3DVertexShaderImpl *)shader)->rel_offset)
+        {
+            shader_addline(buffer, "ADD TA%s, TA, helper_const.z;\n", write_mask);
+        }
         shader_addline(buffer, "MUL A0_SHADOW%s, TA, A0_SHADOW;\n", write_mask);
 
@@ -1219,5 +1689,5 @@
 {
     const struct wined3d_shader_dst_param *dst = &ins->dst[0];
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char reg_dest[40];
 
@@ -1229,7 +1699,26 @@
     if (ins->ctx->reg_maps->shader_version.major >= 2)
     {
-        /* The arb backend doesn't claim ps 2.0 support, but try to eat what the app feeds to us */
-        shader_arb_get_dst_param(ins, dst, reg_dest);
-        shader_addline(buffer, "KIL %s;\n", reg_dest);
+        const char *kilsrc = "TA";
+        BOOL is_color;
+
+        shader_arb_get_register_name(ins, &dst->reg, reg_dest, &is_color);
+        if(dst->write_mask == WINED3DSP_WRITEMASK_ALL)
+        {
+            kilsrc = reg_dest;
+        }
+        else
+        {
+            /* Sigh. KIL doesn't support swizzles/writemasks. KIL passes a writemask, but ".xy" for example
+             * is not valid as a swizzle in ARB (needs ".xyyy"). Use SWZ to load the register properly, and set
+             * masked out components to 0(won't kill)
+             */
+            char x = '0', y = '0', z = '0', w = '0';
+            if(dst->write_mask & WINED3DSP_WRITEMASK_0) x = 'x';
+            if(dst->write_mask & WINED3DSP_WRITEMASK_1) y = 'y';
+            if(dst->write_mask & WINED3DSP_WRITEMASK_2) z = 'z';
+            if(dst->write_mask & WINED3DSP_WRITEMASK_3) w = 'w';
+            shader_addline(buffer, "SWZ TA, %s, %c, %c, %c, %c;\n", reg_dest, x, y, z, w);
+        }
+        shader_addline(buffer, "KIL %s;\n", kilsrc);
     } else {
         /* ARB fp doesn't like swizzles on the parameter of the KIL instruction. To mask the 4th component,
@@ -1256,5 +1745,4 @@
     DWORD shader_version = WINED3D_SHADER_VERSION(ins->ctx->reg_maps->shader_version.major,
             ins->ctx->reg_maps->shader_version.minor);
-    BOOL projected = FALSE, bias = FALSE;
     struct wined3d_shader_src_param src;
 
@@ -1262,4 +1750,5 @@
     char reg_coord[40];
     DWORD reg_sampler_code;
+    DWORD myflags = 0;
 
     /* All versions have a destination register */
@@ -1297,5 +1786,5 @@
         }
         if (flags & WINED3DTTFF_PROJECTED) {
-            projected = TRUE;
+            myflags |= TEX_PROJ;
         }
     }
@@ -1309,13 +1798,13 @@
             shader_addline(ins->ctx->buffer, "SWZ TA, %s, x, y, z, z;\n", reg_coord);
             strcpy(reg_coord, "TA");
-            projected = TRUE;
+            myflags |= TEX_PROJ;
         } else if(src_mod == WINED3DSPSM_DW) {
-            projected = TRUE;
+            myflags |= TEX_PROJ;
         }
     } else {
-        if (ins->flags & WINED3DSI_TEXLD_PROJECT) projected = TRUE;
-        if (ins->flags & WINED3DSI_TEXLD_BIAS) bias = TRUE;
-    }
-    shader_hw_sample(ins, reg_sampler_code, reg_dest, reg_coord, projected, bias);
+        if (ins->flags & WINED3DSI_TEXLD_PROJECT) myflags |= TEX_PROJ;
+        if (ins->flags & WINED3DSI_TEXLD_BIAS) myflags |= TEX_BIAS;
+    }
+    shader_hw_sample(ins, reg_sampler_code, reg_dest, reg_coord, myflags, NULL, NULL);
 }
 
@@ -1323,5 +1812,5 @@
 {
     const struct wined3d_shader_dst_param *dst = &ins->dst[0];
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     DWORD shader_version = WINED3D_SHADER_VERSION(ins->ctx->reg_maps->shader_version.major,
             ins->ctx->reg_maps->shader_version.minor);
@@ -1345,5 +1834,5 @@
 static void pshader_hw_texreg2ar(const struct wined3d_shader_instruction *ins)
 {
-     SHADER_BUFFER *buffer = ins->ctx->buffer;
+     struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
      IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->ctx->shader;
      IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
@@ -1361,10 +1850,10 @@
      shader_addline(buffer, "MOV TA.x, %s.w;\n", src_str);
      flags = reg1 < MAX_TEXTURES ? deviceImpl->stateBlock->textureState[reg1][WINED3DTSS_TEXTURETRANSFORMFLAGS] : 0;
-     shader_hw_sample(ins, reg1, dst_str, "TA", flags & WINED3DTTFF_PROJECTED, FALSE);
+     shader_hw_sample(ins, reg1, dst_str, "TA", flags & WINED3DTTFF_PROJECTED ? TEX_PROJ : 0, NULL, NULL);
 }
 
 static void pshader_hw_texreg2gb(const struct wined3d_shader_instruction *ins)
 {
-     SHADER_BUFFER *buffer = ins->ctx->buffer;
+     struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
 
      DWORD reg1 = ins->dst[0].reg.idx;
@@ -1377,5 +1866,5 @@
      shader_addline(buffer, "MOV TA.x, %s.y;\n", src_str);
      shader_addline(buffer, "MOV TA.y, %s.z;\n", src_str);
-     shader_hw_sample(ins, reg1, dst_str, "TA", FALSE, FALSE);
+     shader_hw_sample(ins, reg1, dst_str, "TA", 0, NULL, NULL);
 }
 
@@ -1389,5 +1878,5 @@
     shader_arb_get_dst_param(ins, &ins->dst[0], dst_str);
     shader_arb_get_src_param(ins, &ins->src[0], 0, src_str);
-    shader_hw_sample(ins, reg1, dst_str, src_str, FALSE, FALSE);
+    shader_hw_sample(ins, reg1, dst_str, src_str, 0, NULL, NULL);
 }
 
@@ -1396,5 +1885,5 @@
     IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->ctx->shader;
     const struct wined3d_shader_dst_param *dst = &ins->dst[0];
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char reg_coord[40], dst_reg[50], src_reg[50];
     DWORD reg_dest_code;
@@ -1435,5 +1924,5 @@
     }
 
-    shader_hw_sample(ins, reg_dest_code, dst_reg, "TA", FALSE, FALSE);
+    shader_hw_sample(ins, reg_dest_code, dst_reg, "TA", 0, NULL, NULL);
 
     if (ins->handler_idx == WINED3DSIH_TEXBEML)
@@ -1449,5 +1938,5 @@
 {
     DWORD reg = ins->dst[0].reg.idx;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char src0_name[50], dst_name[50];
     BOOL is_color;
@@ -1469,5 +1958,5 @@
     DWORD flags;
     DWORD reg = ins->dst[0].reg.idx;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char dst_str[50];
     char src0_name[50];
@@ -1482,5 +1971,5 @@
     shader_addline(buffer, "DP3 %s.y, fragment.texcoord[%u], %s;\n", dst_reg, reg, src0_name);
     flags = reg < MAX_TEXTURES ? deviceImpl->stateBlock->textureState[reg][WINED3DTSS_TEXTURETRANSFORMFLAGS] : 0;
-    shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3DTTFF_PROJECTED, FALSE);
+    shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3DTTFF_PROJECTED ? TEX_PROJ : 0, NULL, NULL);
 }
 
@@ -1489,5 +1978,5 @@
     IWineD3DPixelShaderImpl *This = (IWineD3DPixelShaderImpl *)ins->ctx->shader;
     DWORD reg = ins->dst[0].reg.idx;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     SHADER_PARSE_STATE* current_state = &This->baseShader.parse_state;
     char src0_name[50], dst_name[50];
@@ -1503,6 +1992,6 @@
 
     shader_arb_get_src_param(ins, &ins->src[0], 0, src0_name);
-    shader_addline(buffer, "DP3 %s%u.%c, fragment.texcoord[%u], %s;\n",
-                   dst_name, tmp_reg.idx, 'x' + current_state->current_row, reg, src0_name);
+    shader_addline(buffer, "DP3 %s.%c, fragment.texcoord[%u], %s;\n",
+                   dst_name, 'x' + current_state->current_row, reg, src0_name);
     current_state->texcoord_w[current_state->current_row++] = reg;
 }
@@ -1514,5 +2003,5 @@
     DWORD flags;
     DWORD reg = ins->dst[0].reg.idx;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     SHADER_PARSE_STATE* current_state = &This->baseShader.parse_state;
     char dst_str[50];
@@ -1527,5 +2016,5 @@
     shader_arb_get_dst_param(ins, &ins->dst[0], dst_str);
     flags = reg < MAX_TEXTURES ? deviceImpl->stateBlock->textureState[reg][WINED3DTSS_TEXTURETRANSFORMFLAGS] : 0;
-    shader_hw_sample(ins, reg, dst_str, dst_name, flags & WINED3DTTFF_PROJECTED, FALSE);
+    shader_hw_sample(ins, reg, dst_str, dst_name, flags & WINED3DTTFF_PROJECTED ? TEX_PROJ : 0, NULL, NULL);
     current_state->current_row = 0;
 }
@@ -1537,5 +2026,5 @@
     DWORD flags;
     DWORD reg = ins->dst[0].reg.idx;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     SHADER_PARSE_STATE* current_state = &This->baseShader.parse_state;
     char dst_str[50];
@@ -1569,5 +2058,5 @@
     shader_arb_get_dst_param(ins, &ins->dst[0], dst_str);
     flags = reg < MAX_TEXTURES ? deviceImpl->stateBlock->textureState[reg][WINED3DTSS_TEXTURETRANSFORMFLAGS] : 0;
-    shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3DTTFF_PROJECTED, FALSE);
+    shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3DTTFF_PROJECTED ? TEX_PROJ : 0, NULL, NULL);
     current_state->current_row = 0;
 }
@@ -1580,5 +2069,5 @@
     DWORD reg = ins->dst[0].reg.idx;
     SHADER_PARSE_STATE* current_state = &This->baseShader.parse_state;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char dst_str[50];
     char src0_name[50];
@@ -1611,5 +2100,5 @@
     shader_arb_get_dst_param(ins, &ins->dst[0], dst_str);
     flags = reg < MAX_TEXTURES ? deviceImpl->stateBlock->textureState[reg][WINED3DTSS_TEXTURETRANSFORMFLAGS] : 0;
-    shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3DTTFF_PROJECTED, FALSE);
+    shader_hw_sample(ins, reg, dst_str, dst_reg, flags & WINED3DTTFF_PROJECTED ? TEX_PROJ : 0, NULL, NULL);
     current_state->current_row = 0;
 }
@@ -1618,5 +2107,5 @@
 {
     const struct wined3d_shader_dst_param *dst = &ins->dst[0];
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char dst_name[50];
 
@@ -1648,5 +2137,5 @@
 static void pshader_hw_texdp3tex(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     DWORD sampler_idx = ins->dst[0].reg.idx;
     char src0[50];
@@ -1658,5 +2147,5 @@
 
     shader_arb_get_dst_param(ins, &ins->dst[0], dst_str);
-    shader_hw_sample(ins, sampler_idx, dst_str, "TB", FALSE /* Only one coord, can't be projected */, FALSE);
+    shader_hw_sample(ins, sampler_idx, dst_str, "TB", 0 /* Only one coord, can't be projected */, NULL, NULL);
 }
 
@@ -1668,5 +2157,5 @@
     char src0[50];
     char dst_str[50];
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
 
     /* Handle output register */
@@ -1681,5 +2170,5 @@
 {
     const struct wined3d_shader_dst_param *dst = &ins->dst[0];
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char dst_str[50], dst_name[50];
     char src0[50];
@@ -1700,5 +2189,5 @@
 static void pshader_hw_texm3x2depth(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     const struct wined3d_shader_dst_param *dst = &ins->dst[0];
     char src0[50], dst_name[50];
@@ -1775,7 +2264,7 @@
 }
 
-static void shader_hw_rsq_rcp(const struct wined3d_shader_instruction *ins)
-{
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+static void shader_hw_scalar_op(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     const char *instruction;
 
@@ -1785,6 +2274,8 @@
     switch(ins->handler_idx)
     {
-        case WINED3DSIH_RSQ: instruction = "RSQ"; break;
-        case WINED3DSIH_RCP: instruction = "RCP"; break;
+        case WINED3DSIH_RSQ:  instruction = "RSQ"; break;
+        case WINED3DSIH_RCP:  instruction = "RCP"; break;
+        case WINED3DSIH_EXP:  instruction = "EX2"; break;
+        case WINED3DSIH_EXPP: instruction = "EXP"; break;
         default: instruction = "";
             FIXME("Unhandled opcode %#x\n", ins->handler_idx);
@@ -1807,5 +2298,5 @@
 static void shader_hw_nrm(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char dst_name[50];
     char src_name[50];
@@ -1832,5 +2323,5 @@
 static void shader_hw_lrp(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char dst_name[50];
     char src_name[3][50];
@@ -1858,5 +2349,5 @@
      * can't use map2gl
      */
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
     const struct wined3d_shader_dst_param *dst = &ins->dst[0];
@@ -1868,6 +2359,12 @@
     if(shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type)) {
         shader_arb_get_dst_param(ins, &ins->dst[0], dst_name);
-        shader_addline(buffer, "SCS%s %s, %s;\n", shader_arb_get_modifier(ins), dst_name,
-                       src_name0);
+        /* No modifiers are supported on SCS */
+        shader_addline(buffer, "SCS %s, %s;\n", dst_name, src_name0);
+
+        if(ins->dst[0].modifiers & WINED3DSPDM_SATURATE)
+        {
+            shader_arb_get_register_name(ins, &dst->reg, src_name0, &is_color);
+            shader_addline(buffer, "MOV_SAT %s, %s;\n", dst_name, src_name0);
+        }
     } else if(priv->target_version >= NV2) {
         shader_arb_get_register_name(ins, &dst->reg, dst_name, &is_color);
@@ -1953,8 +2450,7 @@
 }
 
-/* GL locking is done by the caller */
 static void shader_hw_sgn(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     char dst_name[50];
     char src_name[50];
@@ -1969,5 +2465,4 @@
     shader_arb_get_src_param(ins, &ins->src[0], 0, src_name);
 
-    FIXME("Emulated SGN untested\n");
     /* If SRC > 0.0, -SRC < SRC = TRUE, otherwise false.
      * if SRC < 0.0,  SRC < -SRC = TRUE. If neither is true, src = 0.0
@@ -1976,11 +2471,533 @@
         shader_addline(buffer, "SLT %s, -%s, %s;\n", dst_name, src_name, src_name);
     } else {
-        shader_addline(buffer, "SLT TB, -%s, %s;\n", src_name, src_name);
-        shader_addline(buffer, "SLT TC,  %s, -%s;\n", src_name, src_name);
-        shader_addline(buffer, "ADD %s, TB, -TC;\n", dst_name);
-    }
-}
-
-static GLuint create_arb_blt_vertex_program(const WineD3D_GL_Info *gl_info)
+        /* src contains TA? Write to the dest first. This won't overwrite our destination.
+         * Then use TA, and calculate the final result
+         *
+         * Not reading from TA? Store the first result in TA to avoid overwriting the
+         * destination if src reg = dst reg
+         */
+        if(strstr(src_name, "TA"))
+        {
+            shader_addline(buffer, "SLT %s,  %s, -%s;\n", dst_name, src_name, src_name);
+            shader_addline(buffer, "SLT TA, -%s, %s;\n", src_name, src_name);
+            shader_addline(buffer, "ADD %s, %s, -TA;\n", dst_name, dst_name);
+        }
+        else
+        {
+            shader_addline(buffer, "SLT TA, -%s, %s;\n", src_name, src_name);
+            shader_addline(buffer, "SLT %s,  %s, -%s;\n", dst_name, src_name, src_name);
+            shader_addline(buffer, "ADD %s, TA, -%s;\n", dst_name, dst_name);
+        }
+    }
+}
+
+static void shader_hw_dsy(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    char src[50];
+    char dst[50];
+    char dst_name[50];
+    BOOL is_color;
+
+    shader_arb_get_dst_param(ins, &ins->dst[0], dst);
+    shader_arb_get_src_param(ins, &ins->src[0], 0, src);
+    shader_arb_get_register_name(ins, &ins->dst[0].reg, dst_name, &is_color);
+
+    shader_addline(buffer, "DDY %s, %s;\n", dst, src);
+    shader_addline(buffer, "MUL%s %s, %s, ycorrection.y;\n", shader_arb_get_modifier(ins), dst, dst_name);
+}
+
+static DWORD abs_modifier(DWORD mod, BOOL *need_abs)
+{
+    *need_abs = FALSE;
+
+    switch(mod)
+    {
+        case WINED3DSPSM_NONE:      return WINED3DSPSM_ABS;
+        case WINED3DSPSM_NEG:       return WINED3DSPSM_ABS;
+        case WINED3DSPSM_BIAS:      *need_abs = TRUE; return WINED3DSPSM_BIAS;
+        case WINED3DSPSM_BIASNEG:   *need_abs = TRUE; return WINED3DSPSM_BIASNEG;
+        case WINED3DSPSM_SIGN:      *need_abs = TRUE; return WINED3DSPSM_SIGN;
+        case WINED3DSPSM_SIGNNEG:   *need_abs = TRUE; return WINED3DSPSM_SIGNNEG;
+        case WINED3DSPSM_COMP:      *need_abs = TRUE; return WINED3DSPSM_COMP;
+        case WINED3DSPSM_X2:        *need_abs = TRUE; return WINED3DSPSM_X2;
+        case WINED3DSPSM_X2NEG:     *need_abs = TRUE; return WINED3DSPSM_X2NEG;
+        case WINED3DSPSM_DZ:        *need_abs = TRUE; return WINED3DSPSM_DZ;
+        case WINED3DSPSM_DW:        *need_abs = TRUE; return WINED3DSPSM_DW;
+        case WINED3DSPSM_ABS:       return WINED3DSPSM_ABS;
+        case WINED3DSPSM_ABSNEG:    return WINED3DSPSM_ABS;
+    }
+    FIXME("Unknown modifier %u\n", mod);
+    return mod;
+}
+
+static void shader_hw_log_pow(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    char src0[50], src1[50], dst[50];
+    struct wined3d_shader_src_param src0_copy = ins->src[0];
+    BOOL need_abs = FALSE;
+    const char *instr;
+    BOOL arg2 = FALSE;
+
+    switch(ins->handler_idx)
+    {
+        case WINED3DSIH_LOG:  instr = "LG2"; break;
+        case WINED3DSIH_LOGP: instr = "LOG"; break;
+        case WINED3DSIH_POW:  instr = "POW"; arg2 = TRUE; break;
+        default:
+            ERR("Unexpected instruction %d\n", ins->handler_idx);
+            return;
+    }
+
+    /* LOG, LOGP and POW operate on the absolute value of the input */
+    src0_copy.modifiers = abs_modifier(src0_copy.modifiers, &need_abs);
+
+    shader_arb_get_dst_param(ins, &ins->dst[0], dst);
+    shader_arb_get_src_param(ins, &src0_copy, 0, src0);
+    if(arg2) shader_arb_get_src_param(ins, &ins->src[1], 1, src1);
+
+    if(need_abs)
+    {
+        shader_addline(buffer, "ABS TA, %s;\n", src0);
+        if(arg2)
+        {
+            shader_addline(buffer, "%s%s %s, TA, %s;\n", instr, shader_arb_get_modifier(ins), dst, src1);
+        }
+        else
+        {
+            shader_addline(buffer, "%s%s %s, TA;\n", instr, shader_arb_get_modifier(ins), dst);
+        }
+    }
+    else if(arg2)
+    {
+        shader_addline(buffer, "%s%s %s, %s, %s;\n", instr, shader_arb_get_modifier(ins), dst, src0, src1);
+    }
+    else
+    {
+        shader_addline(buffer, "%s%s %s, %s;\n", instr, shader_arb_get_modifier(ins), dst, src0);
+    }
+}
+
+static void shader_hw_loop(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    char src_name[50];
+    BOOL vshader = shader_is_vshader_version(ins->ctx->reg_maps->shader_version.type);
+
+    /* src0 is aL */
+    shader_arb_get_src_param(ins, &ins->src[1], 0, src_name);
+
+    if(vshader)
+    {
+        struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
+        struct list *e = list_head(&priv->control_frames);
+        struct control_frame *control_frame = LIST_ENTRY(e, struct control_frame, entry);
+
+        if(priv->loop_depth > 1) shader_addline(buffer, "PUSHA aL;\n");
+        /* The constant loader makes sure to load -1 into iX.w */
+        shader_addline(buffer, "ARLC aL, %s.xywz;\n", src_name);
+        shader_addline(buffer, "BRA loop_%u_end (LE.x);\n", control_frame->loop_no);
+        shader_addline(buffer, "loop_%u_start:\n", control_frame->loop_no);
+    }
+    else
+    {
+        shader_addline(buffer, "LOOP %s;\n", src_name);
+    }
+}
+
+static void shader_hw_rep(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    char src_name[50];
+    BOOL vshader = shader_is_vshader_version(ins->ctx->reg_maps->shader_version.type);
+
+    shader_arb_get_src_param(ins, &ins->src[0], 0, src_name);
+
+    /* The constant loader makes sure to load -1 into iX.w */
+    if(vshader)
+    {
+        struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
+        struct list *e = list_head(&priv->control_frames);
+        struct control_frame *control_frame = LIST_ENTRY(e, struct control_frame, entry);
+
+        if(priv->loop_depth > 1) shader_addline(buffer, "PUSHA aL;\n");
+
+        shader_addline(buffer, "ARLC aL, %s.xywz;\n", src_name);
+        shader_addline(buffer, "BRA loop_%u_end (LE.x);\n", control_frame->loop_no);
+        shader_addline(buffer, "loop_%u_start:\n", control_frame->loop_no);
+    }
+    else
+    {
+        shader_addline(buffer, "REP %s;\n", src_name);
+    }
+}
+
+static void shader_hw_endloop(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    BOOL vshader = shader_is_vshader_version(ins->ctx->reg_maps->shader_version.type);
+
+    if(vshader)
+    {
+        struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
+        struct list *e = list_head(&priv->control_frames);
+        struct control_frame *control_frame = LIST_ENTRY(e, struct control_frame, entry);
+
+        shader_addline(buffer, "ARAC aL.xy, aL;\n");
+        shader_addline(buffer, "BRA loop_%u_start (GT.x);\n", control_frame->loop_no);
+        shader_addline(buffer, "loop_%u_end:\n", control_frame->loop_no);
+
+        if(priv->loop_depth > 1) shader_addline(buffer, "POPA aL;\n");
+    }
+    else
+    {
+        shader_addline(buffer, "ENDLOOP;\n");
+    }
+}
+
+static void shader_hw_endrep(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    BOOL vshader = shader_is_vshader_version(ins->ctx->reg_maps->shader_version.type);
+
+    if(vshader)
+    {
+        struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
+        struct list *e = list_head(&priv->control_frames);
+        struct control_frame *control_frame = LIST_ENTRY(e, struct control_frame, entry);
+
+        shader_addline(buffer, "ARAC aL.xy, aL;\n");
+        shader_addline(buffer, "BRA loop_%u_start (GT.x);\n", control_frame->loop_no);
+        shader_addline(buffer, "loop_%u_end:\n", control_frame->loop_no);
+
+        if(priv->loop_depth > 1) shader_addline(buffer, "POPA aL;\n");
+    }
+    else
+    {
+        shader_addline(buffer, "ENDREP;\n");
+    }
+}
+
+static const struct control_frame *find_last_loop(const struct shader_arb_ctx_priv *priv)
+{
+    struct control_frame *control_frame;
+
+    LIST_FOR_EACH_ENTRY(control_frame, &priv->control_frames, struct control_frame, entry)
+    {
+        if(control_frame->type == LOOP || control_frame->type == REP) return control_frame;
+    }
+    ERR("Could not find loop for break\n");
+    return NULL;
+}
+
+static void shader_hw_break(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    const struct control_frame *control_frame = find_last_loop(ins->ctx->backend_data);
+    BOOL vshader = shader_is_vshader_version(ins->ctx->reg_maps->shader_version.type);
+
+    if(vshader)
+    {
+        shader_addline(buffer, "BRA loop_%u_end;\n", control_frame->loop_no);
+    }
+    else
+    {
+        shader_addline(buffer, "BRK;\n");
+    }
+}
+
+static const char *get_compare(COMPARISON_TYPE flags)
+{
+    switch (flags)
+    {
+        case COMPARISON_GT: return "GT";
+        case COMPARISON_EQ: return "EQ";
+        case COMPARISON_GE: return "GE";
+        case COMPARISON_LT: return "LT";
+        case COMPARISON_NE: return "NE";
+        case COMPARISON_LE: return "LE";
+        default:
+            FIXME("Unrecognized comparison value: %u\n", flags);
+            return "(\?\?)";
+    }
+}
+
+static COMPARISON_TYPE invert_compare(COMPARISON_TYPE flags)
+{
+    switch (flags)
+    {
+        case COMPARISON_GT: return COMPARISON_LE;
+        case COMPARISON_EQ: return COMPARISON_NE;
+        case COMPARISON_GE: return COMPARISON_LT;
+        case COMPARISON_LT: return COMPARISON_GE;
+        case COMPARISON_NE: return COMPARISON_EQ;
+        case COMPARISON_LE: return COMPARISON_GT;
+        default:
+            FIXME("Unrecognized comparison value: %u\n", flags);
+            return -1;
+    }
+}
+
+static void shader_hw_breakc(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    BOOL vshader = shader_is_vshader_version(ins->ctx->reg_maps->shader_version.type);
+    const struct control_frame *control_frame = find_last_loop(ins->ctx->backend_data);
+    char src_name0[50];
+    char src_name1[50];
+    const char *comp = get_compare(ins->flags);
+
+    shader_arb_get_src_param(ins, &ins->src[0], 0, src_name0);
+    shader_arb_get_src_param(ins, &ins->src[1], 1, src_name1);
+
+    if(vshader)
+    {
+        /* SUBC CC, src0, src1" works only in pixel shaders, so use TA to throw
+         * away the subtraction result
+         */
+        shader_addline(buffer, "SUBC TA, %s, %s;\n", src_name0, src_name1);
+        shader_addline(buffer, "BRA loop_%u_end (%s.x);\n", control_frame->loop_no, comp);
+    }
+    else
+    {
+        shader_addline(buffer, "SUBC TA, %s, %s;\n", src_name0, src_name1);
+        shader_addline(buffer, "BRK (%s.x);\n", comp);
+    }
+}
+
+static void shader_hw_ifc(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
+    struct list *e = list_head(&priv->control_frames);
+    struct control_frame *control_frame = LIST_ENTRY(e, struct control_frame, entry);
+    const char *comp;
+    char src_name0[50];
+    char src_name1[50];
+    BOOL vshader = shader_is_vshader_version(ins->ctx->reg_maps->shader_version.type);
+
+    shader_arb_get_src_param(ins, &ins->src[0], 0, src_name0);
+    shader_arb_get_src_param(ins, &ins->src[1], 1, src_name1);
+
+    if(vshader)
+    {
+        /* Invert the flag. We jump to the else label if the condition is NOT true */
+        comp = get_compare(invert_compare(ins->flags));
+        shader_addline(buffer, "SUBC TA, %s, %s;\n", src_name0, src_name1);
+        shader_addline(buffer, "BRA ifc_%u_else (%s.x);\n", control_frame->ifc_no, comp);
+    }
+    else
+    {
+        comp = get_compare(ins->flags);
+        shader_addline(buffer, "SUBC TA, %s, %s;\n", src_name0, src_name1);
+        shader_addline(buffer, "IF %s.x;\n", comp);
+    }
+}
+
+static void shader_hw_else(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
+    struct list *e = list_head(&priv->control_frames);
+    struct control_frame *control_frame = LIST_ENTRY(e, struct control_frame, entry);
+    BOOL vshader = shader_is_vshader_version(ins->ctx->reg_maps->shader_version.type);
+
+    if(vshader)
+    {
+        shader_addline(buffer, "BRA ifc_%u_endif;\n", control_frame->ifc_no);
+        shader_addline(buffer, "ifc_%u_else:\n", control_frame->ifc_no);
+        control_frame->had_else = TRUE;
+    }
+    else
+    {
+        shader_addline(buffer, "ELSE;\n");
+    }
+}
+
+static void shader_hw_endif(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
+    struct list *e = list_head(&priv->control_frames);
+    struct control_frame *control_frame = LIST_ENTRY(e, struct control_frame, entry);
+    BOOL vshader = shader_is_vshader_version(ins->ctx->reg_maps->shader_version.type);
+
+    if(vshader)
+    {
+        if(control_frame->had_else)
+        {
+            shader_addline(buffer, "ifc_%u_endif:\n", control_frame->ifc_no);
+        }
+        else
+        {
+            shader_addline(buffer, "#No else branch. else is endif\n");
+            shader_addline(buffer, "ifc_%u_else:\n", control_frame->ifc_no);
+        }
+    }
+    else
+    {
+        shader_addline(buffer, "ENDIF;\n");
+    }
+}
+
+static void shader_hw_texldd(const struct wined3d_shader_instruction *ins)
+{
+    DWORD sampler_idx = ins->src[1].reg.idx;
+    char reg_dest[40];
+    char reg_src[3][40];
+    DWORD flags = TEX_DERIV;
+
+    shader_arb_get_dst_param(ins, &ins->dst[0], reg_dest);
+    shader_arb_get_src_param(ins, &ins->src[0], 0, reg_src[0]);
+    shader_arb_get_src_param(ins, &ins->src[2], 1, reg_src[1]);
+    shader_arb_get_src_param(ins, &ins->src[3], 2, reg_src[2]);
+
+    if (ins->flags & WINED3DSI_TEXLD_PROJECT) flags |= TEX_PROJ;
+    if (ins->flags & WINED3DSI_TEXLD_BIAS) flags |= TEX_BIAS;
+
+    shader_hw_sample(ins, sampler_idx, reg_dest, reg_src[0], flags, reg_src[1], reg_src[2]);
+}
+
+static void shader_hw_texldl(const struct wined3d_shader_instruction *ins)
+{
+    DWORD sampler_idx = ins->src[1].reg.idx;
+    char reg_dest[40];
+    char reg_coord[40];
+    DWORD flags = TEX_LOD;
+
+    shader_arb_get_dst_param(ins, &ins->dst[0], reg_dest);
+    shader_arb_get_src_param(ins, &ins->src[0], 0, reg_coord);
+
+    if (ins->flags & WINED3DSI_TEXLD_PROJECT) flags |= TEX_PROJ;
+    if (ins->flags & WINED3DSI_TEXLD_BIAS) flags |= TEX_BIAS;
+
+    shader_hw_sample(ins, sampler_idx, reg_dest, reg_coord, flags, NULL, NULL);
+}
+
+static void shader_hw_label(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
+
+    priv->in_main_func = FALSE;
+    /* Call instructions activate the NV extensions, not labels and rets. If there is an uncalled
+     * subroutine, don't generate a label that will make GL complain
+     */
+    if(priv->target_version == ARB) return;
+
+    shader_addline(buffer, "l%u:\n", ins->src[0].reg.idx);
+}
+
+static void vshader_add_footer(IWineD3DVertexShaderImpl *This, struct wined3d_shader_buffer *buffer,
+        const struct arb_vs_compile_args *args, struct shader_arb_ctx_priv *priv_ctx)
+{
+    const shader_reg_maps *reg_maps = &This->baseShader.reg_maps;
+    IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)This->baseShader.device;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    unsigned int i;
+
+    /* The D3DRS_FOGTABLEMODE render state defines if the shader-generated fog coord is used
+     * or if the fragment depth is used. If the fragment depth is used(FOGTABLEMODE != NONE),
+     * the fog frag coord is thrown away. If the fog frag coord is used, but not written by
+     * the shader, it is set to 0.0(fully fogged, since start = 1.0, end = 0.0)
+     */
+    if(args->super.fog_src == VS_FOG_Z) {
+        shader_addline(buffer, "MOV result.fogcoord, TMP_OUT.z;\n");
+    } else if (!reg_maps->fog) {
+        /* posFixup.x is always 1.0, so we can savely use it */
+        shader_addline(buffer, "ADD result.fogcoord, posFixup.x, -posFixup.x;\n");
+    }
+
+    /* Write the final position.
+     *
+     * OpenGL coordinates specify the center of the pixel while d3d coords specify
+     * the corner. The offsets are stored in z and w in posFixup. posFixup.y contains
+     * 1.0 or -1.0 to turn the rendering upside down for offscreen rendering. PosFixup.x
+     * contains 1.0 to allow a mad, but arb vs swizzles are too restricted for that.
+     */
+    shader_addline(buffer, "MUL TA, posFixup, TMP_OUT.w;\n");
+    shader_addline(buffer, "ADD TMP_OUT.x, TMP_OUT.x, TA.z;\n");
+    shader_addline(buffer, "MAD TMP_OUT.y, TMP_OUT.y, posFixup.y, TA.w;\n");
+
+    if(use_nv_clip(gl_info) && priv_ctx->target_version >= NV2)
+    {
+        for(i = 0; i < priv_ctx->vs_clipplanes; i++)
+        {
+            shader_addline(buffer, "DP4 result.clip[%u].x, TMP_OUT, state.clip[%u].plane;\n", i, i);
+        }
+    }
+    else if(args->boolclip.clip_control[0])
+    {
+        unsigned int cur_clip = 0;
+        char component[4] = {'x', 'y', 'z', 'w'};
+
+        for(i = 0; i < GL_LIMITS(clipplanes); i++)
+        {
+            if(args->boolclip.clip_control[1] & (1 << i))
+            {
+                shader_addline(buffer, "DP4 TA.%c, TMP_OUT, state.clip[%u].plane;\n",
+                               component[cur_clip++], i);
+            }
+        }
+        switch(cur_clip)
+        {
+            case 0:
+                shader_addline(buffer, "MOV TA, -helper_const.w;\n");
+                break;
+            case 1:
+                shader_addline(buffer, "MOV TA.yzw, -helper_const.w;\n");
+                break;
+            case 2:
+                shader_addline(buffer, "MOV TA.zw, -helper_const.w;\n");
+                break;
+            case 3:
+                shader_addline(buffer, "MOV TA.w, -helper_const.w;\n");
+                break;
+        }
+        shader_addline(buffer, "MOV result.texcoord[%u], TA;\n",
+                       args->boolclip.clip_control[0] - 1);
+    }
+
+    /* Z coord [0;1]->[-1;1] mapping, see comment in transform_projection in state.c
+     * and the glsl equivalent
+     */
+    if(need_helper_const(gl_info)) {
+        shader_addline(buffer, "MAD TMP_OUT.z, TMP_OUT.z, helper_const.x, -TMP_OUT.w;\n");
+    } else {
+        shader_addline(buffer, "ADD TMP_OUT.z, TMP_OUT.z, TMP_OUT.z;\n");
+        shader_addline(buffer, "ADD TMP_OUT.z, TMP_OUT.z, -TMP_OUT.w;\n");
+    }
+
+    shader_addline(buffer, "MOV result.position, TMP_OUT;\n");
+
+    priv_ctx->footer_written = TRUE;
+}
+
+static void shader_hw_ret(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
+    IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *) ins->ctx->shader;
+    BOOL vshader = shader_is_vshader_version(ins->ctx->reg_maps->shader_version.type);
+
+    if(priv->target_version == ARB) return;
+
+    if(vshader)
+    {
+        if(priv->in_main_func) vshader_add_footer((IWineD3DVertexShaderImpl *) shader, buffer, priv->cur_vs_args, priv);
+    }
+
+    shader_addline(buffer, "RET;\n");
+}
+
+static void shader_hw_call(const struct wined3d_shader_instruction *ins)
+{
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    shader_addline(buffer, "CAL l%u;\n", ins->src[0].reg.idx);
+}
+
+/* GL locking is done by the caller */
+static GLuint create_arb_blt_vertex_program(const struct wined3d_gl_info *gl_info)
 {
     GLuint program_id = 0;
@@ -2008,5 +3025,5 @@
 
 /* GL locking is done by the caller */
-static GLuint create_arb_blt_fragment_program(const WineD3D_GL_Info *gl_info, enum tex_types tex_type)
+static GLuint create_arb_blt_fragment_program(const struct wined3d_gl_info *gl_info, enum tex_types tex_type)
 {
     GLuint program_id = 0;
@@ -2057,6 +3074,7 @@
 }
 
-static void arbfp_add_sRGB_correction(SHADER_BUFFER *buffer, const char *fragcolor, const char *tmp1,
-                                      const char *tmp2, const char *tmp3, const char *tmp4, BOOL condcode) {
+static void arbfp_add_sRGB_correction(struct wined3d_shader_buffer *buffer, const char *fragcolor,
+        const char *tmp1, const char *tmp2, const char *tmp3, const char *tmp4, BOOL condcode)
+{
     /* Perform sRGB write correction. See GLX_EXT_framebuffer_sRGB */
 
@@ -2101,18 +3119,107 @@
 }
 
+static const DWORD *find_loop_control_values(IWineD3DBaseShaderImpl *This, DWORD idx)
+{
+    const local_constant *constant;
+
+    LIST_FOR_EACH_ENTRY(constant, &This->baseShader.constantsI, local_constant, entry)
+    {
+        if (constant->idx == idx)
+        {
+            return constant->value;
+        }
+    }
+    return NULL;
+}
+
+static void init_ps_input(const IWineD3DPixelShaderImpl *This, const struct arb_ps_compile_args *args,
+                          struct shader_arb_ctx_priv *priv)
+{
+    const char *texcoords[8] =
+    {
+        "fragment.texcoord[0]", "fragment.texcoord[1]", "fragment.texcoord[2]", "fragment.texcoord[3]",
+        "fragment.texcoord[4]", "fragment.texcoord[5]", "fragment.texcoord[6]", "fragment.texcoord[7]"
+    };
+    unsigned int i;
+    const struct wined3d_shader_signature_element *sig = This->input_signature;
+    const char *semantic_name;
+    DWORD semantic_idx;
+
+    switch(args->super.vp_mode)
+    {
+        case pretransformed:
+        case fixedfunction:
+            /* The pixelshader has to collect the varyings on its own. In any case properly load
+             * color0 and color1. In the case of pretransformed vertices also load texcoords. Set
+             * other attribs to 0.0.
+             *
+             * For fixedfunction this behavior is correct, according to the tests. For pretransformed
+             * we'd either need a replacement shader that can load other attribs like BINORMAL, or
+             * load the texcoord attrib pointers to match the pixel shader signature
+             */
+            for(i = 0; i < MAX_REG_INPUT; i++)
+            {
+                semantic_name = sig[i].semantic_name;
+                semantic_idx = sig[i].semantic_idx;
+                if(semantic_name == NULL) continue;
+
+                if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_COLOR))
+                {
+                    if(semantic_idx == 0) priv->ps_input[i] = "fragment.color.primary";
+                    else if(semantic_idx == 1) priv->ps_input[i] = "fragment.color.secondary";
+                    else priv->ps_input[i] = "0.0";
+                }
+                else if(args->super.vp_mode == fixedfunction)
+                {
+                    priv->ps_input[i] = "0.0";
+                }
+                else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_TEXCOORD))
+                {
+                    if(semantic_idx < 8) priv->ps_input[i] = texcoords[semantic_idx];
+                    else priv->ps_input[i] = "0.0";
+                }
+                else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_FOG))
+                {
+                    if(semantic_idx == 0) priv->ps_input[i] = "fragment.fogcoord";
+                    else priv->ps_input[i] = "0.0";
+                }
+                else
+                {
+                    priv->ps_input[i] = "0.0";
+                }
+
+                TRACE("v%u, semantic %s%u is %s\n", i, semantic_name, semantic_idx, priv->ps_input[i]);
+            }
+            break;
+
+        case vertexshader:
+            /* That one is easy. The vertex shaders provide v0-v7 in fragment.texcoord and v8 and v9 in
+             * fragment.color
+             */
+            for(i = 0; i < 8; i++)
+            {
+                priv->ps_input[i] = texcoords[i];
+            }
+            priv->ps_input[8] = "fragment.color.primary";
+            priv->ps_input[9] = "fragment.color.secondary";
+            break;
+    }
+}
+
 /* GL locking is done by the caller */
-static GLuint shader_arb_generate_pshader(IWineD3DPixelShaderImpl *This,
-        SHADER_BUFFER *buffer, const struct arb_ps_compile_args *args)
+static GLuint shader_arb_generate_pshader(IWineD3DPixelShaderImpl *This, struct wined3d_shader_buffer *buffer,
+        const struct arb_ps_compile_args *args, struct arb_ps_compiled_shader *compiled)
 {
     const shader_reg_maps* reg_maps = &This->baseShader.reg_maps;
     CONST DWORD *function = This->baseShader.function;
-    const WineD3D_GL_Info *gl_info = &((IWineD3DDeviceImpl *)This->baseShader.device)->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &((IWineD3DDeviceImpl *)This->baseShader.device)->adapter->gl_info;
     const local_constant *lconst;
     GLuint retval;
     char fragcolor[16];
-    DWORD *lconst_map = local_const_mapping((IWineD3DBaseShaderImpl *) This);
+    DWORD *lconst_map = local_const_mapping((IWineD3DBaseShaderImpl *) This), next_local, cur;
     struct shader_arb_ctx_priv priv_ctx;
     BOOL dcl_tmp = args->super.srgb_correction, dcl_td = FALSE;
     BOOL want_nv_prog = FALSE;
+    struct arb_pshader_private *shader_priv = This->backend_priv;
 
     char srgbtmp[4][4];
@@ -2158,5 +3265,8 @@
     memset(&priv_ctx, 0, sizeof(priv_ctx));
     priv_ctx.cur_ps_args = args;
-    list_init(&priv_ctx.if_frames);
+    priv_ctx.compiled_fprog = compiled;
+    priv_ctx.cur_np2fixup_info = &compiled->np2fixup_info;
+    init_ps_input(This, args, &priv_ctx);
+    list_init(&priv_ctx.control_frames);
 
     /* Avoid enabling NV_fragment_program* if we do not need it.
@@ -2171,5 +3281,6 @@
      * So enable the best we can get.
      */
-    if(reg_maps->usesdsx || reg_maps->usesdsy || reg_maps->loop_depth > 0)
+    if(reg_maps->usesdsx || reg_maps->usesdsy || reg_maps->loop_depth > 0 || reg_maps->usestexldd ||
+       reg_maps->usestexldl || reg_maps->usesfacing || reg_maps->usesifc || reg_maps->usescall)
     {
         want_nv_prog = TRUE;
@@ -2193,4 +3304,9 @@
         }
         priv_ctx.target_version = ARB;
+    }
+
+    if(This->baseShader.reg_maps.highest_render_target > 0)
+    {
+        shader_addline(buffer, "OPTION ARB_draw_buffers;\n");
     }
 
@@ -2248,5 +3364,122 @@
 
     /* Base Declarations */
-    shader_generate_arb_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION, lconst_map);
+    next_local = shader_generate_arb_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION,
+            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;
+
+        cur = compiled->numbumpenvmatconsts;
+        compiled->bumpenvmatconst[cur].const_num = WINED3D_CONST_NUM_UNUSED;
+        compiled->bumpenvmatconst[cur].texunit = i;
+        compiled->luminanceconst[cur].const_num = WINED3D_CONST_NUM_UNUSED;
+        compiled->luminanceconst[cur].texunit = i;
+
+        /* We can fit the constants into the constant limit for sure because texbem, texbeml, bem and beml are only supported
+         * in 1.x shaders, and GL_ARB_fragment_program has a constant limit of 24 constants. So in the worst case we're loading
+         * 8 shader constants, 8 bump matrices and 8 luminance parameters and are perfectly fine. (No NP2 fixup on bumpmapped
+         * textures due to conditional NP2 restrictions)
+         *
+         * Use local constants to load the bump env parameters, not program.env. This avoids collisions with d3d constants of
+         * shaders in newer shader models. Since the bump env parameters have to share their space with NP2 fixup constants,
+         * their location is shader dependent anyway and they cannot be loaded globally.
+         */
+        compiled->bumpenvmatconst[cur].const_num = next_local++;
+        shader_addline(buffer, "PARAM bumpenvmat%d = program.local[%d];\n",
+                       i, compiled->bumpenvmatconst[cur].const_num);
+        compiled->numbumpenvmatconsts = cur + 1;
+
+        if(!reg_maps->luminanceparams[i]) continue;
+
+        compiled->luminanceconst[cur].const_num = next_local++;
+        shader_addline(buffer, "PARAM luminance%d = program.local[%d];\n",
+                       i, compiled->luminanceconst[cur].const_num);
+    }
+
+    for(i = 0; i < MAX_CONST_I; i++)
+    {
+        compiled->int_consts[i] = WINED3D_CONST_NUM_UNUSED;
+        if (reg_maps->integer_constants & (1 << i) && priv_ctx.target_version >= NV2)
+        {
+            const DWORD *control_values = find_loop_control_values((IWineD3DBaseShaderImpl *) This, i);
+
+            if(control_values)
+            {
+                shader_addline(buffer, "PARAM I%u = {%u, %u, %u, -1};\n", i,
+                                control_values[0], control_values[1], control_values[2]);
+            }
+            else
+            {
+                compiled->int_consts[i] = next_local;
+                compiled->num_int_consts++;
+                shader_addline(buffer, "PARAM I%u = program.local[%u];\n", i, next_local++);
+            }
+        }
+    }
+
+    if(reg_maps->vpos || reg_maps->usesdsy)
+    {
+        compiled->ycorrection = next_local;
+        shader_addline(buffer, "PARAM ycorrection = program.local[%u];\n", next_local++);
+
+        if(reg_maps->vpos)
+        {
+            shader_addline(buffer, "TEMP vpos;\n");
+            /* ycorrection.x: Backbuffer height(onscreen) or 0(offscreen).
+             * ycorrection.y: -1.0(onscreen), 1.0(offscreen)
+             * ycorrection.z: 1.0
+             * ycorrection.w: 0.0
+             */
+            shader_addline(buffer, "MAD vpos, fragment.position, ycorrection.zyww, ycorrection.wxww;\n");
+            shader_addline(buffer, "FLR vpos.xy, vpos;\n");
+        }
+    }
+    else
+    {
+        compiled->ycorrection = WINED3D_CONST_NUM_UNUSED;
+    }
+
+    /* Load constants to fixup NP2 texcoords if there are still free constants left:
+     * Constants (texture dimensions) for the NP2 fixup are loaded as local program parameters. This will consume
+     * at most 8 (MAX_FRAGMENT_SAMPLERS / 2) parameters, which is highly unlikely, since the application had to
+     * use 16 NP2 textures at the same time. In case that we run out of constants the fixup is simply not
+     * applied / activated. This will probably result in wrong rendering of the texture, but will save us from
+     * shader compilation errors and the subsequent errors when drawing with this shader. */
+    if (priv_ctx.cur_ps_args->super.np2_fixup) {
+
+        struct arb_ps_np2fixup_info* const fixup = priv_ctx.cur_np2fixup_info;
+        const WORD map = priv_ctx.cur_ps_args->super.np2_fixup;
+        const UINT max_lconsts = gl_info->ps_arb_max_local_constants;
+
+        fixup->offset = next_local;
+        fixup->super.active = 0;
+
+        cur = 0;
+        for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i) {
+            if (!(map & (1 << i))) continue;
+
+            if (fixup->offset + (cur >> 1) < max_lconsts) {
+                fixup->super.active |= (1 << i);
+                fixup->super.idx[i] = cur++;
+            } else {
+                FIXME("No free constant found to load NP2 fixup data into shader. "
+                      "Sampling from this texture will probably look wrong.\n");
+                break;
+            }
+        }
+
+        fixup->super.num_consts = (cur + 1) >> 1;
+        if (fixup->super.num_consts) {
+            shader_addline(buffer, "PARAM np2fixup[%u] = { program.env[%u..%u] };\n",
+                           fixup->super.num_consts, fixup->offset, fixup->super.num_consts + fixup->offset - 1);
+        }
+
+        next_local += fixup->super.num_consts;
+    }
+
+    if(shader_priv->clipplane_emulation)
+    {
+        shader_addline(buffer, "KIL fragment.texcoord[%u];\n", shader_priv->clipplane_emulation - 1);
+    }
 
     /* Base Shader Body */
@@ -2293,15 +3526,264 @@
 }
 
+static int compare_sig(const struct wined3d_shader_signature_element *sig1, const struct wined3d_shader_signature_element *sig2)
+{
+    unsigned int i;
+    int ret;
+
+    for(i = 0; i < MAX_REG_INPUT; i++)
+    {
+        if(sig1[i].semantic_name == NULL || sig2[i].semantic_name == NULL)
+        {
+            /* Compare pointers, not contents. One string is NULL(element does not exist), the other one is not NULL */
+            if(sig1[i].semantic_name != sig2[i].semantic_name) return sig1[i].semantic_name < sig2[i].semantic_name ? -1 : 1;
+            continue;
+        }
+
+        ret = strcmp(sig1[i].semantic_name, sig2[i].semantic_name);
+        if(ret != 0) return ret;
+        if(sig1[i].semantic_idx    != sig2[i].semantic_idx)    return sig1[i].semantic_idx    < sig2[i].semantic_idx    ? -1 : 1;
+        if(sig1[i].sysval_semantic != sig2[i].sysval_semantic) return sig1[i].sysval_semantic < sig2[i].sysval_semantic ? -1 : 1;
+        if(sig1[i].component_type  != sig2[i].component_type)  return sig1[i].sysval_semantic < sig2[i].component_type  ? -1 : 1;
+        if(sig1[i].register_idx    != sig2[i].register_idx)    return sig1[i].register_idx    < sig2[i].register_idx    ? -1 : 1;
+        if(sig1[i].mask            != sig2->mask)              return sig1[i].mask            < sig2[i].mask            ? -1 : 1;
+    }
+    return 0;
+}
+
+static struct wined3d_shader_signature_element *clone_sig(const struct wined3d_shader_signature_element *sig)
+{
+    struct wined3d_shader_signature_element *new;
+    int i;
+    char *name;
+
+    new = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*new) * MAX_REG_INPUT);
+    for(i = 0; i < MAX_REG_INPUT; i++)
+    {
+        if(sig[i].semantic_name == NULL)
+        {
+            continue;
+        }
+
+        new[i] = sig[i];
+        /* Clone the semantic string */
+        name = HeapAlloc(GetProcessHeap(), 0, strlen(sig[i].semantic_name) + 1);
+        strcpy(name, sig[i].semantic_name);
+        new[i].semantic_name = name;
+    }
+    return new;
+}
+
+static DWORD find_input_signature(struct shader_arb_priv *priv, const struct wined3d_shader_signature_element *sig)
+{
+    struct wine_rb_entry *entry = wine_rb_get(&priv->signature_tree, sig);
+    struct ps_signature *found_sig;
+
+    if(entry != NULL)
+    {
+        found_sig = WINE_RB_ENTRY_VALUE(entry, struct ps_signature, entry);
+        TRACE("Found existing signature %u\n", found_sig->idx);
+        return found_sig->idx;
+    }
+    found_sig = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*sig));
+    found_sig->sig = clone_sig(sig);
+    found_sig->idx = priv->ps_sig_number++;
+    TRACE("New signature stored and assigned number %u\n", found_sig->idx);
+    if(wine_rb_put(&priv->signature_tree, sig, &found_sig->entry) == -1)
+    {
+        ERR("Failed to insert program entry.\n");
+    }
+    return found_sig->idx;
+}
+
+static void init_output_registers(IWineD3DVertexShaderImpl *shader, DWORD sig_num, struct shader_arb_ctx_priv *priv_ctx,
+                                  struct arb_vs_compiled_shader *compiled)
+{
+    unsigned int i, j;
+    static const char *texcoords[8] =
+    {
+        "result.texcoord[0]", "result.texcoord[1]", "result.texcoord[2]", "result.texcoord[3]",
+        "result.texcoord[4]", "result.texcoord[5]", "result.texcoord[6]", "result.texcoord[7]"
+    };
+    IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) shader->baseShader.device;
+    const struct wined3d_shader_signature_element *sig;
+    const char *semantic_name;
+    DWORD semantic_idx, reg_idx;
+
+    /* Write generic input varyings 0 to 7 to result.texcoord[], varying 8 to result.color.primary
+     * and varying 9 to result.color.secondary
+     */
+    const char *decl_idx_to_string[MAX_REG_INPUT] =
+    {
+        texcoords[0], texcoords[1], texcoords[2], texcoords[3],
+        texcoords[4], texcoords[5], texcoords[6], texcoords[7],
+        "result.color.primary", "result.color.secondary"
+    };
+
+    if(sig_num == ~0)
+    {
+        TRACE("Pixel shader uses builtin varyings\n");
+        /* Map builtins to builtins */
+        for(i = 0; i < 8; i++)
+        {
+            priv_ctx->texcrd_output[i] = texcoords[i];
+        }
+        priv_ctx->color_output[0] = "result.color.primary";
+        priv_ctx->color_output[1] = "result.color.secondary";
+        priv_ctx->fog_output = "result.fogcoord";
+
+        /* Map declared regs to builtins. Use "TA" to /dev/null unread output */
+        for(i = 0; i < (sizeof(shader->output_signature) / sizeof(*shader->output_signature)); i++)
+        {
+            semantic_name = shader->output_signature[i].semantic_name;
+            if(semantic_name == NULL) continue;
+
+            if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_POSITION))
+            {
+                TRACE("o%u is TMP_OUT\n", i);
+                if(shader->output_signature[i].semantic_idx == 0) priv_ctx->vs_output[i] = "TMP_OUT";
+                else priv_ctx->vs_output[i] = "TA";
+            }
+            else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_PSIZE))
+            {
+                TRACE("o%u is result.pointsize\n", i);
+                if(shader->output_signature[i].semantic_idx == 0) priv_ctx->vs_output[i] = "result.pointsize";
+                else priv_ctx->vs_output[i] = "TA";
+            }
+            else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_COLOR))
+            {
+                TRACE("o%u is result.color.?, idx %u\n", i, shader->output_signature[i].semantic_idx);
+                if(shader->output_signature[i].semantic_idx == 0) priv_ctx->vs_output[i] = "result.color.primary";
+                else if(shader->output_signature[i].semantic_idx == 1) priv_ctx->vs_output[i] = "result.color.secondary";
+                else priv_ctx->vs_output[i] = "TA";
+            }
+            else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_TEXCOORD))
+            {
+                TRACE("o%u is %s\n", i, texcoords[shader->output_signature[i].semantic_idx]);
+                if(shader->output_signature[i].semantic_idx >= 8) priv_ctx->vs_output[i] = "TA";
+                else priv_ctx->vs_output[i] = texcoords[shader->output_signature[i].semantic_idx];
+            }
+            else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_FOG))
+            {
+                TRACE("o%u is result.fogcoord\n", i);
+                if(shader->output_signature[i].semantic_idx > 0) priv_ctx->vs_output[i] = "TA";
+                else priv_ctx->vs_output[i] = "result.fogcoord";
+            }
+            else
+            {
+                priv_ctx->vs_output[i] = "TA";
+            }
+        }
+        return;
+    }
+
+    /* Instead of searching for the signature in the signature list, read the one from the current pixel shader.
+     * Its maybe not the shader where the signature came from, but it is the same signature and faster to find
+     */
+    sig = ((IWineD3DPixelShaderImpl *)device->stateBlock->pixelShader)->input_signature;
+    TRACE("Pixel shader uses declared varyings\n");
+
+    /* Map builtin to declared. /dev/null the results by default to the TA temp reg */
+    for(i = 0; i < 8; i++)
+    {
+        priv_ctx->texcrd_output[i] = "TA";
+    }
+    priv_ctx->color_output[0] = "TA";
+    priv_ctx->color_output[1] = "TA";
+    priv_ctx->fog_output = "TA";
+
+    for(i = 0; i < MAX_REG_INPUT; i++)
+    {
+        semantic_name = sig[i].semantic_name;
+        semantic_idx = sig[i].semantic_idx;
+        reg_idx = sig[i].register_idx;
+        if(semantic_name == NULL) continue;
+
+        /* If a declared input register is not written by builtin arguments, don't write to it.
+         * GL_NV_vertex_program makes sure the input defaults to 0.0, which is correct with D3D
+         *
+         * Don't care about POSITION and PSIZE here - this is a builtin vertex shader, position goes
+         * to TMP_OUT in any case
+         */
+        if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_TEXCOORD))
+        {
+            if(semantic_idx < 8) priv_ctx->texcrd_output[semantic_idx] = decl_idx_to_string[reg_idx];
+        }
+        else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_COLOR))
+        {
+            if(semantic_idx < 2) priv_ctx->color_output[semantic_idx] = decl_idx_to_string[reg_idx];
+        }
+        else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_FOG))
+        {
+            if(semantic_idx == 0) priv_ctx->fog_output = decl_idx_to_string[reg_idx];
+        }
+        else
+        {
+            continue;
+        }
+
+        if(strcmp(decl_idx_to_string[reg_idx], "result.color.primary") == 0 ||
+           strcmp(decl_idx_to_string[reg_idx], "result.color.secondary") == 0)
+        {
+            compiled->need_color_unclamp = TRUE;
+        }
+    }
+
+    /* Map declared to declared */
+    for(i = 0; i < (sizeof(shader->output_signature) / sizeof(*shader->output_signature)); i++)
+    {
+        /* Write unread output to TA to throw them away */
+        priv_ctx->vs_output[i] = "TA";
+        semantic_name = shader->output_signature[i].semantic_name;
+        if(semantic_name == NULL)
+        {
+            continue;
+        }
+
+        if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_POSITION) &&
+           shader->output_signature[i].semantic_idx == 0)
+        {
+            priv_ctx->vs_output[i] = "TMP_OUT";
+            continue;
+        }
+        else if(shader_match_semantic(semantic_name, WINED3DDECLUSAGE_PSIZE) &&
+           shader->output_signature[i].semantic_idx == 0)
+        {
+            priv_ctx->vs_output[i] = "result.pointsize";
+            continue;
+        }
+
+        for(j = 0; j < MAX_REG_INPUT; j++)
+        {
+            if(sig[j].semantic_name == NULL)
+            {
+                continue;
+            }
+
+            if(strcmp(sig[j].semantic_name, semantic_name) == 0 &&
+               sig[j].semantic_idx == shader->output_signature[i].semantic_idx)
+            {
+                priv_ctx->vs_output[i] = decl_idx_to_string[sig[j].register_idx];
+
+                if(strcmp(priv_ctx->vs_output[i], "result.color.primary") == 0 ||
+                   strcmp(priv_ctx->vs_output[i], "result.color.secondary") == 0)
+                {
+                    compiled->need_color_unclamp = TRUE;
+                }
+            }
+        }
+    }
+}
+
 /* GL locking is done by the caller */
-static GLuint shader_arb_generate_vshader(IWineD3DVertexShaderImpl *This,
-        SHADER_BUFFER *buffer, const struct arb_vs_compile_args *args)
+static GLuint shader_arb_generate_vshader(IWineD3DVertexShaderImpl *This, struct wined3d_shader_buffer *buffer,
+        const struct arb_vs_compile_args *args, struct arb_vs_compiled_shader *compiled)
 {
     const shader_reg_maps *reg_maps = &This->baseShader.reg_maps;
     CONST DWORD *function = This->baseShader.function;
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)This->baseShader.device;
-    const WineD3D_GL_Info *gl_info = &device->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     const local_constant *lconst;
     GLuint ret;
-    DWORD *lconst_map = local_const_mapping((IWineD3DBaseShaderImpl *) This);
+    DWORD next_local, *lconst_map = local_const_mapping((IWineD3DBaseShaderImpl *) This);
     struct shader_arb_ctx_priv priv_ctx;
     unsigned int i;
@@ -2309,5 +3791,6 @@
     memset(&priv_ctx, 0, sizeof(priv_ctx));
     priv_ctx.cur_vs_args = args;
-    list_init(&priv_ctx.if_frames);
+    list_init(&priv_ctx.control_frames);
+    init_output_registers(This, args->ps_signature, &priv_ctx, compiled);
 
     /*  Create the hw ARB shader */
@@ -2317,7 +3800,12 @@
      * mesurable performance penalty, and we can always make use of it for clipplanes.
      */
-    if(GL_SUPPORT(NV_VERTEX_PROGRAM2_OPTION)) {
+    if(GL_SUPPORT(NV_VERTEX_PROGRAM3)) {
+        shader_addline(buffer, "OPTION NV_vertex_program3;\n");
+        priv_ctx.target_version = NV3;
+        shader_addline(buffer, "ADDRESS aL;\n");
+    } else if(GL_SUPPORT(NV_VERTEX_PROGRAM2_OPTION)) {
         shader_addline(buffer, "OPTION NV_vertex_program2;\n");
         priv_ctx.target_version = NV2;
+        shader_addline(buffer, "ADDRESS aL;\n");
     } else {
         priv_ctx.target_version = ARB;
@@ -2336,8 +3824,31 @@
 
     /* Base Declarations */
-    shader_generate_arb_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION, lconst_map);
+    next_local = shader_generate_arb_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION,
+            lconst_map, &priv_ctx.vs_clipplanes, &priv_ctx);
+
+    for(i = 0; i < MAX_CONST_I; i++)
+    {
+        compiled->int_consts[i] = WINED3D_CONST_NUM_UNUSED;
+        if(reg_maps->integer_constants & (1 << i) && priv_ctx.target_version >= NV2)
+        {
+            const DWORD *control_values = find_loop_control_values((IWineD3DBaseShaderImpl *) This, i);
+
+            if(control_values)
+            {
+                shader_addline(buffer, "PARAM I%u = {%u, %u, %u, -1};\n", i,
+                                control_values[0], control_values[1], control_values[2]);
+            }
+            else
+            {
+                compiled->int_consts[i] = next_local;
+                compiled->num_int_consts++;
+                shader_addline(buffer, "PARAM I%u = program.local[%u];\n", i, next_local++);
+            }
+        }
+    }
 
     /* We need a constant to fixup the final position */
-    shader_addline(buffer, "PARAM posFixup = program.env[%d];\n", ARB_SHADER_PRIVCONST_POS);
+    shader_addline(buffer, "PARAM posFixup = program.local[%u];\n", next_local);
+    compiled->pos_fixup = next_local++;
 
     /* Initialize output parameters. GL_ARB_vertex_program does not require special initialization values
@@ -2355,5 +3866,6 @@
         shader_addline(buffer, "MOV result.color.secondary, -helper_const.wwwy;\n");
 
-        if((GLINFO_LOCATION).set_texcoord_w && !device->frag_pipe->ffp_proj_control) {
+        if ((GLINFO_LOCATION).quirks & WINED3D_QUIRK_SET_TEXCOORD_W && !device->frag_pipe->ffp_proj_control)
+        {
             int i;
             for(i = 0; i < min(8, MAX_REG_TEXCRD); i++) {
@@ -2366,49 +3878,10 @@
     }
 
+    /* The shader starts with the main function */
+    priv_ctx.in_main_func = TRUE;
     /* Base Shader Body */
     shader_generate_main((IWineD3DBaseShader *)This, buffer, reg_maps, function, &priv_ctx);
 
-    /* The D3DRS_FOGTABLEMODE render state defines if the shader-generated fog coord is used
-     * or if the fragment depth is used. If the fragment depth is used(FOGTABLEMODE != NONE),
-     * the fog frag coord is thrown away. If the fog frag coord is used, but not written by
-     * the shader, it is set to 0.0(fully fogged, since start = 1.0, end = 0.0)
-     */
-    if(args->super.fog_src == VS_FOG_Z) {
-        shader_addline(buffer, "MOV result.fogcoord, TMP_OUT.z;\n");
-    } else if (!reg_maps->fog) {
-        /* posFixup.x is always 1.0, so we can savely use it */
-        shader_addline(buffer, "ADD result.fogcoord, posFixup.x, -posFixup.x;\n");
-    }
-
-    /* Write the final position.
-     *
-     * OpenGL coordinates specify the center of the pixel while d3d coords specify
-     * the corner. The offsets are stored in z and w in posFixup. posFixup.y contains
-     * 1.0 or -1.0 to turn the rendering upside down for offscreen rendering. PosFixup.x
-     * contains 1.0 to allow a mad, but arb vs swizzles are too restricted for that.
-     */
-    shader_addline(buffer, "MUL TA, posFixup, TMP_OUT.w;\n");
-    shader_addline(buffer, "ADD TMP_OUT.x, TMP_OUT.x, TA.z;\n");
-    shader_addline(buffer, "MAD TMP_OUT.y, TMP_OUT.y, posFixup.y, TA.w;\n");
-
-    if(priv_ctx.target_version >= NV2)
-    {
-        for(i = 0; i < GL_LIMITS(clipplanes); i++)
-        {
-            shader_addline(buffer, "DP4 result.clip[%u].x, TMP_OUT, state.clip[%u].plane;\n", i, i);
-        }
-    }
-
-    /* Z coord [0;1]->[-1;1] mapping, see comment in transform_projection in state.c
-     * and the glsl equivalent
-     */
-    if(need_helper_const(gl_info)) {
-        shader_addline(buffer, "MAD TMP_OUT.z, TMP_OUT.z, helper_const.x, -TMP_OUT.w;\n");
-    } else {
-        shader_addline(buffer, "ADD TMP_OUT.z, TMP_OUT.z, TMP_OUT.z;\n");
-        shader_addline(buffer, "ADD TMP_OUT.z, TMP_OUT.z, -TMP_OUT.w;\n");
-    }
-
-    shader_addline(buffer, "MOV result.position, TMP_OUT;\n");
+    if(!priv_ctx.footer_written) vshader_add_footer(This, buffer, args, &priv_ctx);
 
     shader_addline(buffer, "END\n");
@@ -2445,16 +3918,65 @@
 }
 
+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");
+    }
+}
+
 /* GL locking is done by the caller */
-static GLuint find_arb_pshader(IWineD3DPixelShaderImpl *shader, const struct arb_ps_compile_args *args)
+static struct arb_ps_compiled_shader *find_arb_pshader(IWineD3DPixelShaderImpl *shader, const struct arb_ps_compile_args *args)
 {
     UINT i;
     DWORD new_size;
     struct arb_ps_compiled_shader *new_array;
-    SHADER_BUFFER buffer;
+    struct wined3d_shader_buffer buffer;
     struct arb_pshader_private *shader_data;
     GLuint ret;
 
     if(!shader->backend_priv) {
+        IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) shader->baseShader.device;
+        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_data->clamp_consts = shader->baseShader.reg_maps.shader_version.major == 1;
+
+        if(shader->baseShader.reg_maps.shader_version.major < 3) shader_data->input_signature_idx = ~0;
+        else shader_data->input_signature_idx = find_input_signature(priv, shader->input_signature);
+
+        shader_data->has_signature_idx = TRUE;
+        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;
@@ -2466,5 +3988,5 @@
     for(i = 0; i < shader_data->num_gl_shaders; i++) {
         if(memcmp(&shader_data->gl_shaders[i].args, args, sizeof(*args)) == 0) {
-            return shader_data->gl_shaders[i].prgId;
+            return &shader_data->gl_shaders[i];
         }
     }
@@ -2475,8 +3997,8 @@
         {
             new_size = shader_data->shader_array_size + max(1, shader_data->shader_array_size / 2);
-            new_array = HeapReAlloc(GetProcessHeap(), 0, shader_data->gl_shaders,
+            new_array = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, shader_data->gl_shaders,
                                     new_size * sizeof(*shader_data->gl_shaders));
         } else {
-            new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*shader_data->gl_shaders));
+            new_array = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data->gl_shaders));
             new_size = 1;
         }
@@ -2495,20 +4017,31 @@
             ((IWineD3DDeviceImpl *)shader->baseShader.device)->stateBlock->textures);
 
-    shader_buffer_init(&buffer);
-    ret = shader_arb_generate_pshader(shader, &buffer, args);
+    if (!shader_buffer_init(&buffer))
+    {
+        ERR("Failed to initialize shader buffer.\n");
+        return 0;
+    }
+
+    ret = shader_arb_generate_pshader(shader, &buffer, args,
+                                      &shader_data->gl_shaders[shader_data->num_gl_shaders]);
     shader_buffer_free(&buffer);
-    shader_data->gl_shaders[shader_data->num_gl_shaders++].prgId = ret;
-
-    return ret;
+    shader_data->gl_shaders[shader_data->num_gl_shaders].prgId = ret;
+
+    return &shader_data->gl_shaders[shader_data->num_gl_shaders++];
 }
 
 static inline BOOL vs_args_equal(const struct arb_vs_compile_args *stored, const struct arb_vs_compile_args *new,
-                                 const DWORD use_map) {
+                                 const DWORD use_map, BOOL skip_int) {
     if((stored->super.swizzle_map & use_map) != new->super.swizzle_map) return FALSE;
     if(stored->super.fog_src != new->super.fog_src) return FALSE;
-    return stored->bools == new->bools;
-}
-
-static GLuint find_arb_vshader(IWineD3DVertexShaderImpl *shader, const struct arb_vs_compile_args *args)
+    if(stored->boolclip_compare != new->boolclip_compare) return FALSE;
+    if(stored->ps_signature != new->ps_signature) return FALSE;
+    if(stored->vertex_samplers_compare != new->vertex_samplers_compare) return FALSE;
+    if(skip_int) return TRUE;
+
+    return memcmp(stored->loop_ctrl, new->loop_ctrl, sizeof(stored->loop_ctrl)) == 0;
+}
+
+static struct arb_vs_compiled_shader *find_arb_vshader(IWineD3DVertexShaderImpl *shader, const struct arb_vs_compile_args *args)
 {
     UINT i;
@@ -2516,7 +4049,8 @@
     struct arb_vs_compiled_shader *new_array;
     DWORD use_map = ((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.use_map;
-    SHADER_BUFFER buffer;
+    struct wined3d_shader_buffer buffer;
     struct arb_vshader_private *shader_data;
     GLuint ret;
+    const struct wined3d_gl_info *gl_info = &((IWineD3DDeviceImpl *)shader->baseShader.device)->adapter->gl_info;
 
     if(!shader->backend_priv) {
@@ -2530,6 +4064,6 @@
      */
     for(i = 0; i < shader_data->num_gl_shaders; i++) {
-        if(vs_args_equal(&shader_data->gl_shaders[i].args, args, use_map)) {
-            return shader_data->gl_shaders[i].prgId;
+        if(vs_args_equal(&shader_data->gl_shaders[i].args, args, use_map, GL_SUPPORT(NV_VERTEX_PROGRAM2_OPTION))) {
+            return &shader_data->gl_shaders[i];
         }
     }
@@ -2541,8 +4075,8 @@
         {
             new_size = shader_data->shader_array_size + max(1, shader_data->shader_array_size / 2);
-            new_array = HeapReAlloc(GetProcessHeap(), 0, shader_data->gl_shaders,
+            new_array = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, shader_data->gl_shaders,
                                     new_size * sizeof(*shader_data->gl_shaders));
         } else {
-            new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*shader_data->gl_shaders));
+            new_array = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*shader_data->gl_shaders));
             new_size = 1;
         }
@@ -2558,10 +4092,16 @@
     shader_data->gl_shaders[shader_data->num_gl_shaders].args = *args;
 
-    shader_buffer_init(&buffer);
-    ret = shader_arb_generate_vshader(shader, &buffer, args);
+    if (!shader_buffer_init(&buffer))
+    {
+        ERR("Failed to initialize shader buffer.\n");
+        return 0;
+    }
+
+    ret = shader_arb_generate_vshader(shader, &buffer, args,
+            &shader_data->gl_shaders[shader_data->num_gl_shaders]);
     shader_buffer_free(&buffer);
-    shader_data->gl_shaders[shader_data->num_gl_shaders++].prgId = ret;
-
-    return ret;
+    shader_data->gl_shaders[shader_data->num_gl_shaders].prgId = ret;
+
+    return &shader_data->gl_shaders[shader_data->num_gl_shaders++];
 }
 
@@ -2570,4 +4110,6 @@
 {
     int i;
+    WORD int_skip;
+    const struct wined3d_gl_info *gl_info = &((IWineD3DDeviceImpl *)shader->baseShader.device)->adapter->gl_info;
     find_ps_compile_args(shader, stateblock, &args->super);
 
@@ -2580,4 +4122,27 @@
     }
 
+    /* Skip if unused or local, or supported natively */
+    int_skip = ~shader->baseShader.reg_maps.integer_constants | shader->baseShader.reg_maps.local_int_consts;
+    if(int_skip == 0xffff || GL_SUPPORT(NV_FRAGMENT_PROGRAM_OPTION))
+    {
+        memset(&args->loop_ctrl, 0, sizeof(args->loop_ctrl));
+        return;
+    }
+
+    for(i = 0; i < MAX_CONST_I; i++)
+    {
+        if(int_skip & (1 << i))
+        {
+            args->loop_ctrl[i][0] = 0;
+            args->loop_ctrl[i][1] = 0;
+            args->loop_ctrl[i][2] = 0;
+        }
+        else
+        {
+            args->loop_ctrl[i][0] = stateblock->pixelShaderConstantI[i * 4];
+            args->loop_ctrl[i][1] = stateblock->pixelShaderConstantI[i * 4 + 1];
+            args->loop_ctrl[i][2] = stateblock->pixelShaderConstantI[i * 4 + 2];
+        }
+    }
 }
 
@@ -2586,15 +4151,73 @@
 {
     int i;
+    WORD int_skip;
+    IWineD3DDeviceImpl *dev = (IWineD3DDeviceImpl *)shader->baseShader.device;
+    const struct wined3d_gl_info *gl_info = &dev->adapter->gl_info;
     find_vs_compile_args(shader, stateblock, &args->super);
 
+    args->boolclip_compare = 0;
+    if(use_ps(stateblock))
+    {
+        IWineD3DPixelShaderImpl *ps = (IWineD3DPixelShaderImpl *) stateblock->pixelShader;
+        struct arb_pshader_private *shader_priv = ps->backend_priv;
+        args->ps_signature = shader_priv->input_signature_idx;
+
+        args->boolclip.clip_control[0] = shader_priv->clipplane_emulation;
+    }
+    else
+    {
+        args->ps_signature = ~0;
+        if(!dev->vs_clipping)
+        {
+            args->boolclip.clip_control[0] = ffp_clip_emul(stateblock) ? GL_LIMITS(texture_stages) : 0;
+        }
+        /* Otherwise: Setting boolclip_compare set clip_control[0] to 0 */
+    }
+
+    if(args->boolclip.clip_control[0])
+    {
+        if(stateblock->renderState[WINED3DRS_CLIPPING])
+        {
+            args->boolclip.clip_control[1] = stateblock->renderState[WINED3DRS_CLIPPLANEENABLE];
+        }
+        /* clip_control[1] was set to 0 by setting boolclip_compare to 0 */
+    }
+
     /* This forces all local boolean constants to 1 to make them stateblock independent */
-    args->bools = shader->baseShader.reg_maps.local_bool_consts;
-
+    args->boolclip.bools = shader->baseShader.reg_maps.local_bool_consts;
     /* TODO: Figure out if it would be better to store bool constants as bitmasks in the stateblock */
     for(i = 0; i < MAX_CONST_B; i++)
     {
-        if(stateblock->vertexShaderConstantB[i]) args->bools |= ( 1 << i);
-    }
-
+        if(stateblock->vertexShaderConstantB[i]) args->boolclip.bools |= ( 1 << i);
+    }
+
+    args->vertex_samplers[0] = dev->texUnitMap[MAX_FRAGMENT_SAMPLERS + 0];
+    args->vertex_samplers[1] = dev->texUnitMap[MAX_FRAGMENT_SAMPLERS + 1];
+    args->vertex_samplers[2] = dev->texUnitMap[MAX_FRAGMENT_SAMPLERS + 2];
+    args->vertex_samplers[3] = 0;
+
+    /* Skip if unused or local */
+    int_skip = ~shader->baseShader.reg_maps.integer_constants | shader->baseShader.reg_maps.local_int_consts;
+    if(int_skip == 0xffff || GL_SUPPORT(NV_VERTEX_PROGRAM2_OPTION)) /* This is about flow control, not clipping */
+    {
+        memset(&args->loop_ctrl, 0, sizeof(args->loop_ctrl));
+        return;
+    }
+
+    for(i = 0; i < MAX_CONST_I; i++)
+    {
+        if(int_skip & (1 << i))
+        {
+            args->loop_ctrl[i][0] = 0;
+            args->loop_ctrl[i][1] = 0;
+            args->loop_ctrl[i][2] = 0;
+        }
+        else
+        {
+            args->loop_ctrl[i][0] = stateblock->vertexShaderConstantI[i * 4];
+            args->loop_ctrl[i][1] = stateblock->vertexShaderConstantI[i * 4 + 1];
+            args->loop_ctrl[i][2] = stateblock->vertexShaderConstantI[i * 4 + 2];
+        }
+    }
 }
 
@@ -2603,12 +4226,71 @@
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     struct shader_arb_priv *priv = This->shader_priv;
-    const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
+    int i;
+
+    /* Deal with pixel shaders first so the vertex shader arg function has the input signature ready */
+    if (usePS) {
+        struct arb_ps_compile_args compile_args;
+        struct arb_ps_compiled_shader *compiled;
+        IWineD3DPixelShaderImpl *ps = (IWineD3DPixelShaderImpl *) This->stateBlock->pixelShader;
+
+        TRACE("Using pixel shader %p\n", This->stateBlock->pixelShader);
+        find_arb_ps_compile_args(ps, This->stateBlock, &compile_args);
+        compiled = find_arb_pshader(ps, &compile_args);
+        priv->current_fprogram_id = compiled->prgId;
+        priv->compiled_fprog = compiled;
+
+        /* Bind the fragment program */
+        GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, priv->current_fprogram_id));
+        checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, priv->current_fprogram_id);");
+
+        if(!priv->use_arbfp_fixed_func) {
+            /* Enable OpenGL fragment programs */
+            glEnable(GL_FRAGMENT_PROGRAM_ARB);
+            checkGLcall("glEnable(GL_FRAGMENT_PROGRAM_ARB);");
+        }
+        TRACE("(%p) : Bound fragment program %u and enabled GL_FRAGMENT_PROGRAM_ARB\n", This, priv->current_fprogram_id);
+
+        /* Pixel Shader 1.x constants are clamped to [-1;1], Pixel Shader 2.0 constants are not. If switching between
+         * 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;
+            This->highest_dirty_ps_const = max(This->highest_dirty_ps_const, 8);
+            for(i = 0; i < 8; i++)
+            {
+                This->activeContext->pshader_const_dirty[i] = 1;
+            }
+            /* Also takes care of loading local constants */
+            shader_arb_load_constants(iface, TRUE, FALSE);
+        }
+        else
+        {
+            shader_arb_ps_local_constants(This);
+        }
+
+        /* Force constant reloading for the NP2 fixup (see comment in shader_glsl_select for more info) */
+        if (compiled->np2fixup_info.super.active) This->shader_backend->shader_load_np2fixup_constants(iface, usePS, useVS);
+    } else if(GL_SUPPORT(ARB_FRAGMENT_PROGRAM) && !priv->use_arbfp_fixed_func) {
+        /* Disable only if we're not using arbfp fixed function fragment processing. If this is used,
+        * keep GL_FRAGMENT_PROGRAM_ARB enabled, and the fixed function pipeline will bind the fixed function
+        * replacement shader
+        */
+        glDisable(GL_FRAGMENT_PROGRAM_ARB);
+        checkGLcall("glDisable(GL_FRAGMENT_PROGRAM_ARB)");
+        priv->current_fprogram_id = 0;
+    }
 
     if (useVS) {
         struct arb_vs_compile_args compile_args;
-
-        TRACE("Using vertex shader\n");
-        find_arb_vs_compile_args((IWineD3DVertexShaderImpl *) This->stateBlock->vertexShader, This->stateBlock, &compile_args);
-        priv->current_vprogram_id = find_arb_vshader((IWineD3DVertexShaderImpl *) This->stateBlock->vertexShader, &compile_args);
+        struct arb_vs_compiled_shader *compiled;
+        IWineD3DVertexShaderImpl *vs = (IWineD3DVertexShaderImpl *) This->stateBlock->vertexShader;
+
+        TRACE("Using vertex shader %p\n", This->stateBlock->vertexShader);
+        find_arb_vs_compile_args(vs, This->stateBlock, &compile_args);
+        compiled = find_arb_vshader(vs, &compile_args);
+        priv->current_vprogram_id = compiled->prgId;
+        priv->compiled_vprog = compiled;
 
         /* Bind the vertex program */
@@ -2620,37 +4302,20 @@
         checkGLcall("glEnable(GL_VERTEX_PROGRAM_ARB);");
         TRACE("(%p) : Bound vertex program %u and enabled GL_VERTEX_PROGRAM_ARB\n", This, priv->current_vprogram_id);
+        shader_arb_vs_local_constants(This);
+
+        if(priv->last_vs_color_unclamp != compiled->need_color_unclamp) {
+            priv->last_vs_color_unclamp = compiled->need_color_unclamp;
+
+            if (GL_SUPPORT(ARB_COLOR_BUFFER_FLOAT)) {
+                GL_EXTCALL(glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, !compiled->need_color_unclamp));
+                checkGLcall("glClampColorARB");
+            } else {
+                FIXME("vertex color clamp needs to be changed, but extension not supported.\n");
+            }
+        }
     } else if(GL_SUPPORT(ARB_VERTEX_PROGRAM)) {
         priv->current_vprogram_id = 0;
         glDisable(GL_VERTEX_PROGRAM_ARB);
         checkGLcall("glDisable(GL_VERTEX_PROGRAM_ARB)");
-    }
-
-    if (usePS) {
-        struct arb_ps_compile_args compile_args;
-        TRACE("Using pixel shader\n");
-        find_arb_ps_compile_args((IWineD3DPixelShaderImpl *) This->stateBlock->pixelShader, This->stateBlock, &compile_args);
-        priv->current_fprogram_id = find_arb_pshader((IWineD3DPixelShaderImpl *) This->stateBlock->pixelShader,
-                                                     &compile_args);
-
-        /* Bind the fragment program */
-        GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, priv->current_fprogram_id));
-        checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, priv->current_fprogram_id);");
-
-        if(!priv->use_arbfp_fixed_func) {
-            /* Enable OpenGL fragment programs */
-            glEnable(GL_FRAGMENT_PROGRAM_ARB);
-            checkGLcall("glEnable(GL_FRAGMENT_PROGRAM_ARB);");
-        }
-        TRACE("(%p) : Bound fragment program %u and enabled GL_FRAGMENT_PROGRAM_ARB\n", This, priv->current_fprogram_id);
-
-        shader_arb_ps_local_constants(This);
-    } else if(GL_SUPPORT(ARB_FRAGMENT_PROGRAM) && !priv->use_arbfp_fixed_func) {
-        /* Disable only if we're not using arbfp fixed function fragment processing. If this is used,
-         * keep GL_FRAGMENT_PROGRAM_ARB enabled, and the fixed function pipeline will bind the fixed function
-         * replacement shader
-         */
-        glDisable(GL_FRAGMENT_PROGRAM_ARB);
-        checkGLcall("glDisable(GL_FRAGMENT_PROGRAM_ARB)");
-        priv->current_fprogram_id = 0;
     }
 }
@@ -2661,5 +4326,5 @@
     struct shader_arb_priv *priv = This->shader_priv;
     GLuint *blt_fprogram = &priv->depth_blt_fprogram_id[tex_type];
-    const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
 
     if (!priv->depth_blt_vprogram_id) priv->depth_blt_vprogram_id = create_arb_blt_vertex_program(gl_info);
@@ -2676,12 +4341,9 @@
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     struct shader_arb_priv *priv = This->shader_priv;
-    const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
 
     if (priv->current_vprogram_id) {
         GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, priv->current_vprogram_id));
         checkGLcall("glBindProgramARB(GL_VERTEX_PROGRAM_ARB, vertexShader->prgId);");
-
-        glEnable(GL_VERTEX_PROGRAM_ARB);
-        checkGLcall("glEnable(GL_VERTEX_PROGRAM_ARB);");
 
         TRACE("(%p) : Bound vertex program %u and enabled GL_VERTEX_PROGRAM_ARB\n", This, priv->current_vprogram_id);
@@ -2695,9 +4357,6 @@
         checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, pixelShader->prgId);");
 
-        glEnable(GL_FRAGMENT_PROGRAM_ARB);
-        checkGLcall("glEnable(GL_FRAGMENT_PROGRAM_ARB);");
-
         TRACE("(%p) : Bound fragment program %u and enabled GL_FRAGMENT_PROGRAM_ARB\n", This, priv->current_fprogram_id);
-    } else {
+    } else if(!priv->use_arbfp_fixed_func) {
         glDisable(GL_FRAGMENT_PROGRAM_ARB);
         checkGLcall("glDisable(GL_FRAGMENT_PROGRAM_ARB)");
@@ -2708,5 +4367,5 @@
     IWineD3DBaseShaderImpl *baseShader = (IWineD3DBaseShaderImpl *) iface;
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)baseShader->baseShader.device;
-    const WineD3D_GL_Info *gl_info = &device->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
 
     ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
@@ -2746,13 +4405,47 @@
 }
 
+static int sig_tree_compare(const void *key, const struct wine_rb_entry *entry)
+{
+    struct ps_signature *e = WINE_RB_ENTRY_VALUE(entry, struct ps_signature, entry);
+    return compare_sig(key, e->sig);
+}
+
+struct wine_rb_functions sig_tree_functions =
+{
+    wined3d_rb_alloc,
+    wined3d_rb_realloc,
+    wined3d_rb_free,
+    sig_tree_compare
+};
+
 static HRESULT shader_arb_alloc(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    This->shader_priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct shader_arb_priv));
+    struct shader_arb_priv *priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*priv));
+    if(wine_rb_init(&priv->signature_tree, &sig_tree_functions) == -1)
+    {
+        ERR("RB tree init failed\n");
+        HeapFree(GetProcessHeap(), 0, priv);
+        return E_OUTOFMEMORY;
+    }
+    This->shader_priv = priv;
     return WINED3D_OK;
 }
 
+static void release_signature(struct wine_rb_entry *entry, void *context)
+{
+    struct ps_signature *sig = WINE_RB_ENTRY_VALUE(entry, struct ps_signature, entry);
+    int i;
+    for(i = 0; i < MAX_REG_INPUT; i++)
+    {
+        HeapFree(GetProcessHeap(), 0, (char *) sig->sig[i].semantic_name);
+    }
+    HeapFree(GetProcessHeap(), 0, sig->sig);
+    HeapFree(GetProcessHeap(), 0, sig);
+}
+
+/* Context activation is done by the caller. */
 static void shader_arb_free(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     struct shader_arb_priv *priv = This->shader_priv;
     int i;
@@ -2769,4 +4462,5 @@
     LEAVE_GL();
 
+    wine_rb_destroy(&priv->signature_tree, release_signature, NULL);
     HeapFree(GetProcessHeap(), 0, This->shader_priv);
 }
@@ -2776,5 +4470,6 @@
 }
 
-static void shader_arb_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct shader_caps *pCaps)
+static void shader_arb_get_caps(WINED3DDEVTYPE devtype, const struct wined3d_gl_info *gl_info,
+        struct shader_caps *pCaps)
 {
     /* We don't have an ARB fixed function pipeline yet, so let the none backend set its caps,
@@ -2784,17 +4479,45 @@
 
     if(GL_SUPPORT(ARB_VERTEX_PROGRAM)) {
-        pCaps->VertexShaderVersion = WINED3DVS_VERSION(1,1);
-        TRACE_(d3d_caps)("Hardware vertex shader version 1.1 enabled (ARB_PROGRAM)\n");
-        pCaps->MaxVertexShaderConst = GL_LIMITS(vshader_constantsF) - 1;
+        if(GL_SUPPORT(NV_VERTEX_PROGRAM3))
+        {
+            pCaps->VertexShaderVersion = WINED3DVS_VERSION(3,0);
+            TRACE_(d3d_caps)("Hardware vertex shader version 3.0 enabled (NV_VERTEX_PROGRAM3)\n");
+        }
+        else if(GL_LIMITS(vshader_constantsF) >= 256)
+        {
+            /* Shader Model 2.0 requires at least 256 vertex shader constants */
+            pCaps->VertexShaderVersion = WINED3DVS_VERSION(2,0);
+            TRACE_(d3d_caps)("Hardware vertex shader version 2.0 enabled (ARB_PROGRAM)\n");
+        }
+        else
+        {
+            pCaps->VertexShaderVersion = WINED3DVS_VERSION(1,1);
+            TRACE_(d3d_caps)("Hardware vertex shader version 1.1 enabled (ARB_PROGRAM)\n");
+        }
+        pCaps->MaxVertexShaderConst = GL_LIMITS(vshader_constantsF);
     }
 
     if(GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
-        pCaps->PixelShaderVersion    = WINED3DPS_VERSION(1,4);
-        pCaps->PixelShader1xMaxValue = 8.0;
-        TRACE_(d3d_caps)("Hardware pixel shader version 1.4 enabled (ARB_PROGRAM)\n");
+        if(GL_SUPPORT(NV_FRAGMENT_PROGRAM2))
+        {
+            pCaps->PixelShaderVersion    = WINED3DPS_VERSION(3,0);
+            TRACE_(d3d_caps)("Hardware pixel shader version 3.0 enabled (NV_FRAGMENT_PROGRAM2)\n");
+        }
+        else if(GL_LIMITS(pshader_constantsF) >= 32)
+        {
+            /* Shader Model 2.0 requires at least 32 pixel shader constants */
+            pCaps->PixelShaderVersion    = WINED3DPS_VERSION(2,0);
+            TRACE_(d3d_caps)("Hardware pixel shader version 2.0 enabled (ARB_PROGRAM)\n");
+        }
+        else
+        {
+            pCaps->PixelShaderVersion    = WINED3DPS_VERSION(1,4);
+            TRACE_(d3d_caps)("Hardware pixel shader version 1.4 enabled (ARB_PROGRAM)\n");
+        }
+        pCaps->PixelShader1xMaxValue = 8.0f;
         pCaps->MaxPixelShaderConst = GL_LIMITS(pshader_constantsF);
     }
 
-    pCaps->VSClipping = GL_SUPPORT(NV_VERTEX_PROGRAM2_OPTION);
+    pCaps->VSClipping = use_nv_clip(gl_info);
 }
 
@@ -2821,5 +4544,5 @@
     DWORD shift;
     char write_mask[20], regstr[50];
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     BOOL is_color = FALSE;
     const struct wined3d_shader_dst_param *dst;
@@ -2847,8 +4570,8 @@
     /* WINED3DSIH_ADD           */ shader_hw_map2gl,
     /* WINED3DSIH_BEM           */ pshader_hw_bem,
-    /* WINED3DSIH_BREAK         */ NULL,
-    /* WINED3DSIH_BREAKC        */ NULL,
+    /* WINED3DSIH_BREAK         */ shader_hw_break,
+    /* WINED3DSIH_BREAKC        */ shader_hw_breakc,
     /* WINED3DSIH_BREAKP        */ NULL,
-    /* WINED3DSIH_CALL          */ NULL,
+    /* WINED3DSIH_CALL          */ shader_hw_call,
     /* WINED3DSIH_CALLNZ        */ NULL,
     /* WINED3DSIH_CMP           */ pshader_hw_cmp,
@@ -2864,19 +4587,19 @@
     /* WINED3DSIH_DST           */ shader_hw_map2gl,
     /* WINED3DSIH_DSX           */ shader_hw_map2gl,
-    /* WINED3DSIH_DSY           */ NULL,
-    /* WINED3DSIH_ELSE          */ NULL,
-    /* WINED3DSIH_ENDIF         */ NULL,
-    /* WINED3DSIH_ENDLOOP       */ NULL,
-    /* WINED3DSIH_ENDREP        */ NULL,
-    /* WINED3DSIH_EXP           */ shader_hw_map2gl,
-    /* WINED3DSIH_EXPP          */ shader_hw_map2gl,
+    /* WINED3DSIH_DSY           */ shader_hw_dsy,
+    /* WINED3DSIH_ELSE          */ shader_hw_else,
+    /* WINED3DSIH_ENDIF         */ shader_hw_endif,
+    /* WINED3DSIH_ENDLOOP       */ shader_hw_endloop,
+    /* WINED3DSIH_ENDREP        */ shader_hw_endrep,
+    /* WINED3DSIH_EXP           */ shader_hw_scalar_op,
+    /* WINED3DSIH_EXPP          */ shader_hw_scalar_op,
     /* WINED3DSIH_FRC           */ shader_hw_map2gl,
-    /* WINED3DSIH_IF            */ NULL,
-    /* WINED3DSIH_IFC           */ NULL,
-    /* WINED3DSIH_LABEL         */ NULL,
+    /* WINED3DSIH_IF            */ NULL /* Hardcoded into the shader */,
+    /* WINED3DSIH_IFC           */ shader_hw_ifc,
+    /* WINED3DSIH_LABEL         */ shader_hw_label,
     /* WINED3DSIH_LIT           */ shader_hw_map2gl,
-    /* WINED3DSIH_LOG           */ shader_hw_map2gl,
-    /* WINED3DSIH_LOGP          */ shader_hw_map2gl,
-    /* WINED3DSIH_LOOP          */ NULL,
+    /* WINED3DSIH_LOG           */ shader_hw_log_pow,
+    /* WINED3DSIH_LOGP          */ shader_hw_log_pow,
+    /* WINED3DSIH_LOOP          */ shader_hw_loop,
     /* WINED3DSIH_LRP           */ shader_hw_lrp,
     /* WINED3DSIH_M3x2          */ shader_hw_mnxn,
@@ -2894,9 +4617,9 @@
     /* WINED3DSIH_NRM           */ shader_hw_nrm,
     /* WINED3DSIH_PHASE         */ NULL,
-    /* WINED3DSIH_POW           */ shader_hw_map2gl,
-    /* WINED3DSIH_RCP           */ shader_hw_rsq_rcp,
-    /* WINED3DSIH_REP           */ NULL,
-    /* WINED3DSIH_RET           */ NULL,
-    /* WINED3DSIH_RSQ           */ shader_hw_rsq_rcp,
+    /* WINED3DSIH_POW           */ shader_hw_log_pow,
+    /* WINED3DSIH_RCP           */ shader_hw_scalar_op,
+    /* WINED3DSIH_REP           */ shader_hw_rep,
+    /* WINED3DSIH_RET           */ shader_hw_ret,
+    /* WINED3DSIH_RSQ           */ shader_hw_scalar_op,
     /* WINED3DSIH_SETP          */ NULL,
     /* WINED3DSIH_SGE           */ shader_hw_map2gl,
@@ -2913,6 +4636,6 @@
     /* WINED3DSIH_TEXDP3TEX     */ pshader_hw_texdp3tex,
     /* WINED3DSIH_TEXKILL       */ pshader_hw_texkill,
-    /* WINED3DSIH_TEXLDD        */ NULL,
-    /* WINED3DSIH_TEXLDL        */ NULL,
+    /* WINED3DSIH_TEXLDD        */ shader_hw_texldd,
+    /* WINED3DSIH_TEXLDL        */ shader_hw_texldl,
     /* WINED3DSIH_TEXM3x2DEPTH  */ pshader_hw_texm3x2depth,
     /* WINED3DSIH_TEXM3x2PAD    */ pshader_hw_texm3x2pad,
@@ -2952,7 +4675,144 @@
     else
     {
-        if(vshader) bools = priv->cur_vs_args->bools;
+        if(vshader) bools = priv->cur_vs_args->boolclip.bools;
         else bools = priv->cur_ps_args->bools;
         return bools & flag;
+    }
+}
+
+static void get_loop_control_const(const struct wined3d_shader_instruction *ins,
+        IWineD3DBaseShaderImpl *This, UINT idx, struct loop_control *loop_control)
+{
+    struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
+
+    /* Integer constants can either be a local constant, or they can be stored in the shader
+     * type specific compile args. */
+    if (This->baseShader.reg_maps.local_int_consts & (1 << idx))
+    {
+        const local_constant *constant;
+
+        LIST_FOR_EACH_ENTRY(constant, &This->baseShader.constantsI, local_constant, entry)
+        {
+            if (constant->idx == idx)
+            {
+                loop_control->count = constant->value[0];
+                loop_control->start = constant->value[1];
+                /* Step is signed. */
+                loop_control->step = (int)constant->value[2];
+                return;
+            }
+        }
+        /* If this happens the flag was set incorrectly */
+        ERR("Local constant not found\n");
+        loop_control->count = 0;
+        loop_control->start = 0;
+        loop_control->step = 0;
+        return;
+    }
+
+    switch (This->baseShader.reg_maps.shader_version.type)
+    {
+        case WINED3D_SHADER_TYPE_VERTEX:
+            /* Count and aL start value are unsigned */
+            loop_control->count = priv->cur_vs_args->loop_ctrl[idx][0];
+            loop_control->start = priv->cur_vs_args->loop_ctrl[idx][1];
+            /* Step is signed. */
+            loop_control->step = ((char)priv->cur_vs_args->loop_ctrl[idx][2]);
+            break;
+
+        case WINED3D_SHADER_TYPE_PIXEL:
+            loop_control->count = priv->cur_ps_args->loop_ctrl[idx][0];
+            loop_control->start = priv->cur_ps_args->loop_ctrl[idx][1];
+            loop_control->step = ((char)priv->cur_ps_args->loop_ctrl[idx][2]);
+            break;
+
+        default:
+            FIXME("Unhandled shader type %#x.\n", This->baseShader.reg_maps.shader_version.type);
+            break;
+    }
+}
+
+static void record_instruction(struct list *list, const struct wined3d_shader_instruction *ins)
+{
+    unsigned int i;
+    struct wined3d_shader_dst_param *dst_param = NULL;
+    struct wined3d_shader_src_param *src_param = NULL, *rel_addr = NULL;
+    struct recorded_instruction *rec = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*rec));
+    if(!rec)
+    {
+        ERR("Out of memory\n");
+        return;
+    }
+
+    rec->ins = *ins;
+    dst_param = HeapAlloc(GetProcessHeap(), 0, sizeof(*dst_param));
+    if(!dst_param) goto free;
+    *dst_param = *ins->dst;
+    if(ins->dst->reg.rel_addr)
+    {
+        rel_addr = HeapAlloc(GetProcessHeap(), 0, sizeof(*dst_param->reg.rel_addr));
+        if(!rel_addr) goto free;
+        *rel_addr = *ins->dst->reg.rel_addr;
+        dst_param->reg.rel_addr = rel_addr;
+    }
+    rec->ins.dst = dst_param;
+
+    src_param = HeapAlloc(GetProcessHeap(), 0, sizeof(*src_param) * ins->src_count);
+    if(!src_param) goto free;
+    for(i = 0; i < ins->src_count; i++)
+    {
+        src_param[i] = ins->src[i];
+        if(ins->src[i].reg.rel_addr)
+        {
+            rel_addr = HeapAlloc(GetProcessHeap(), 0, sizeof(*rel_addr));
+            if(!rel_addr) goto free;
+            *rel_addr = *ins->src[i].reg.rel_addr;
+            src_param[i].reg.rel_addr = rel_addr;
+        }
+    }
+    rec->ins.src = src_param;
+    list_add_tail(list, &rec->entry);
+    return;
+
+free:
+    ERR("Out of memory\n");
+    if(dst_param)
+    {
+        HeapFree(GetProcessHeap(), 0, (void *) dst_param->reg.rel_addr);
+        HeapFree(GetProcessHeap(), 0, dst_param);
+    }
+    if(src_param)
+    {
+        for(i = 0; i < ins->src_count; i++)
+        {
+            HeapFree(GetProcessHeap(), 0, (void *) src_param[i].reg.rel_addr);
+        }
+        HeapFree(GetProcessHeap(), 0, src_param);
+    }
+    HeapFree(GetProcessHeap(), 0, rec);
+}
+
+static void free_recorded_instruction(struct list *list)
+{
+    struct recorded_instruction *rec_ins, *entry2;
+    unsigned int i;
+
+    LIST_FOR_EACH_ENTRY_SAFE(rec_ins, entry2, list, struct recorded_instruction, entry)
+    {
+        list_remove(&rec_ins->entry);
+        if(rec_ins->ins.dst)
+        {
+            HeapFree(GetProcessHeap(), 0, (void *) rec_ins->ins.dst->reg.rel_addr);
+            HeapFree(GetProcessHeap(), 0, (void *) rec_ins->ins.dst);
+        }
+        if(rec_ins->ins.src)
+        {
+            for(i = 0; i < rec_ins->ins.src_count; i++)
+            {
+                HeapFree(GetProcessHeap(), 0, (void *) rec_ins->ins.src[i].reg.rel_addr);
+            }
+            HeapFree(GetProcessHeap(), 0, (void *) rec_ins->ins.src);
+        }
+        HeapFree(GetProcessHeap(), 0, rec_ins);
     }
 }
@@ -2962,18 +4822,137 @@
     struct shader_arb_ctx_priv *priv = ins->ctx->backend_data;
     IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
-    struct if_frame *if_frame;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct control_frame *control_frame;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
+    BOOL bool_const;
+
+    if(ins->handler_idx == WINED3DSIH_LOOP || ins->handler_idx == WINED3DSIH_REP)
+    {
+        control_frame = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*control_frame));
+        list_add_head(&priv->control_frames, &control_frame->entry);
+
+        if(ins->handler_idx == WINED3DSIH_LOOP) control_frame->type = LOOP;
+        if(ins->handler_idx == WINED3DSIH_REP) control_frame->type = REP;
+
+        if(priv->target_version >= NV2)
+        {
+            control_frame->loop_no = priv->num_loops++;
+            priv->loop_depth++;
+        }
+        else
+        {
+            /* Don't bother recording when we're in a not used if branch */
+            if(priv->muted)
+            {
+                return;
+            }
+
+            if(!priv->recording)
+            {
+                list_init(&priv->record);
+                priv->recording = TRUE;
+                control_frame->outer_loop = TRUE;
+                get_loop_control_const(ins, This, ins->src[0].reg.idx, &control_frame->loop_control);
+                return; /* Instruction is handled */
+            }
+            /* Record this loop in the outer loop's recording */
+        }
+    }
+    else if(ins->handler_idx == WINED3DSIH_ENDLOOP || ins->handler_idx == WINED3DSIH_ENDREP)
+    {
+        if(priv->target_version >= NV2)
+        {
+            /* Nothing to do. The control frame is popped after the HW instr handler */
+        }
+        else
+        {
+            struct list *e = list_head(&priv->control_frames);
+            control_frame = LIST_ENTRY(e, struct control_frame, entry);
+            list_remove(&control_frame->entry);
+
+            if(control_frame->outer_loop)
+            {
+                int iteration, aL = 0;
+                struct list copy;
+
+                /* Turn off recording before playback */
+                priv->recording = FALSE;
+
+                /* Move the recorded instructions to a separate list and get them out of the private data
+                 * structure. If there are nested loops, the shader_arb_handle_instruction below will
+                 * be recorded again, thus priv->record might be overwritten
+                 */
+                list_init(&copy);
+                list_move_tail(&copy, &priv->record);
+                list_init(&priv->record);
+
+                if(ins->handler_idx == WINED3DSIH_ENDLOOP)
+                {
+                    shader_addline(buffer, "#unrolling loop: %u iterations, aL=%u, inc %d\n",
+                                   control_frame->loop_control.count, control_frame->loop_control.start,
+                                   control_frame->loop_control.step);
+                    aL = control_frame->loop_control.start;
+                }
+                else
+                {
+                    shader_addline(buffer, "#unrolling rep: %u iterations\n", control_frame->loop_control.count);
+                }
+
+                for (iteration = 0; iteration < control_frame->loop_control.count; ++iteration)
+                {
+                    struct recorded_instruction *rec_ins;
+                    if(ins->handler_idx == WINED3DSIH_ENDLOOP)
+                    {
+                        priv->aL = aL;
+                        shader_addline(buffer, "#Iteration %d, aL=%d\n", iteration, aL);
+                    }
+                    else
+                    {
+                        shader_addline(buffer, "#Iteration %d\n", iteration);
+                    }
+
+                    LIST_FOR_EACH_ENTRY(rec_ins, &copy, struct recorded_instruction, entry)
+                    {
+                        shader_arb_handle_instruction(&rec_ins->ins);
+                    }
+
+                    if(ins->handler_idx == WINED3DSIH_ENDLOOP)
+                    {
+                        aL += control_frame->loop_control.step;
+                    }
+                }
+                shader_addline(buffer, "#end loop/rep\n");
+
+                free_recorded_instruction(&copy);
+                HeapFree(GetProcessHeap(), 0, control_frame);
+                return; /* Instruction is handled */
+            }
+            else
+            {
+                /* This is a nested loop. Proceed to the normal recording function */
+                HeapFree(GetProcessHeap(), 0, control_frame);
+            }
+        }
+    }
+
+    if(priv->recording)
+    {
+        record_instruction(&priv->record, ins);
+        return;
+    }
 
     /* boolean if */
     if(ins->handler_idx == WINED3DSIH_IF)
     {
-        if_frame = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*if_frame));
-        list_add_head(&priv->if_frames, &if_frame->entry);
-
-        if(!priv->muted && get_bool_const(ins, This, ins->src[0].reg.idx) == FALSE)
+        control_frame = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*control_frame));
+        list_add_head(&priv->control_frames, &control_frame->entry);
+        control_frame->type = IF;
+
+        bool_const = get_bool_const(ins, This, ins->src[0].reg.idx);
+        if(ins->src[0].modifiers == WINED3DSPSM_NOT) bool_const = !bool_const;
+        if(!priv->muted && bool_const == FALSE)
         {
             shader_addline(buffer, "#if(FALSE){\n");
             priv->muted = TRUE;
-            if_frame->muting = TRUE;
+            control_frame->muting = TRUE;
         }
         else shader_addline(buffer, "#if(TRUE) {\n");
@@ -2984,22 +4963,23 @@
     {
         /* IF(bool) and if_cond(a, b) use the same ELSE and ENDIF tokens */
-        if_frame = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*if_frame));
-        if_frame->ifc = TRUE;
-        list_add_head(&priv->if_frames, &if_frame->entry);
+        control_frame = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*control_frame));
+        control_frame->type = IFC;
+        control_frame->ifc_no = priv->num_ifcs++;
+        list_add_head(&priv->control_frames, &control_frame->entry);
     }
     else if(ins->handler_idx == WINED3DSIH_ELSE)
     {
-        struct list *e = list_head(&priv->if_frames);
-        if_frame = LIST_ENTRY(e, struct if_frame, entry);
-
-        if(if_frame->ifc == FALSE)
+        struct list *e = list_head(&priv->control_frames);
+        control_frame = LIST_ENTRY(e, struct control_frame, entry);
+
+        if(control_frame->type == IF)
         {
             shader_addline(buffer, "#} else {\n");
-            if(!priv->muted && !if_frame->muting)
+            if(!priv->muted && !control_frame->muting)
             {
                 priv->muted = TRUE;
-                if_frame->muting = TRUE;
-            }
-            else if(if_frame->muting) priv->muted = FALSE;
+                control_frame->muting = TRUE;
+            }
+            else if(control_frame->muting) priv->muted = FALSE;
             return; /* Instruction is handled. */
         }
@@ -3008,20 +4988,14 @@
     else if(ins->handler_idx == WINED3DSIH_ENDIF)
     {
-        struct list *e = list_head(&priv->if_frames);
-        if_frame = LIST_ENTRY(e, struct if_frame, entry);
-
-        if(!if_frame->ifc)
+        struct list *e = list_head(&priv->control_frames);
+        control_frame = LIST_ENTRY(e, struct control_frame, entry);
+
+        if(control_frame->type == IF)
         {
             shader_addline(buffer, "#} endif\n");
-            if(if_frame->muting) priv->muted = FALSE;
-            list_remove(&if_frame->entry);
-            HeapFree(GetProcessHeap(), 0, if_frame);
+            if(control_frame->muting) priv->muted = FALSE;
+            list_remove(&control_frame->entry);
+            HeapFree(GetProcessHeap(), 0, control_frame);
             return; /* Instruction is handled */
-        }
-        else
-        {
-            list_remove(&if_frame->entry);
-            HeapFree(GetProcessHeap(), 0, if_frame);
-            /* ifc - generate a hw endif */
         }
     }
@@ -3039,4 +5013,22 @@
     }
     hw_fct(ins);
+
+    if(ins->handler_idx == WINED3DSIH_ENDLOOP || ins->handler_idx == WINED3DSIH_ENDREP)
+    {
+        struct list *e = list_head(&priv->control_frames);
+        control_frame = LIST_ENTRY(e, struct control_frame, entry);
+        list_remove(&control_frame->entry);
+        HeapFree(GetProcessHeap(), 0, control_frame);
+        priv->loop_depth--;
+    }
+    else if(ins->handler_idx == WINED3DSIH_ENDIF)
+    {
+        /* Non-ifc ENDIFs don't reach that place because of the return in the if block above */
+        struct list *e = list_head(&priv->control_frames);
+        control_frame = LIST_ENTRY(e, struct control_frame, entry);
+        list_remove(&control_frame->entry);
+        HeapFree(GetProcessHeap(), 0, control_frame);
+    }
+
 
     shader_arb_add_instruction_modifiers(ins);
@@ -3074,4 +5066,5 @@
 };
 
+/* Context activation is done by the caller. */
 static void arbfp_enable(IWineD3DDevice *iface, BOOL enable) {
     ENTER_GL();
@@ -3110,7 +5103,8 @@
 }
 
+/* Context activation is done by the caller. */
 static void arbfp_free_ffpshader(struct wine_rb_entry *entry, void *context)
 {
-    const WineD3D_GL_Info *gl_info = context;
+    const struct wined3d_gl_info *gl_info = context;
     struct arbfp_ffp_desc *entry_arb = WINE_RB_ENTRY_VALUE(entry, struct arbfp_ffp_desc, parent.entry);
 
@@ -3122,4 +5116,5 @@
 }
 
+/* Context activation is done by the caller. */
 static void arbfp_free(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
@@ -3134,5 +5129,5 @@
 }
 
-static void arbfp_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct fragment_caps *caps)
+static void arbfp_get_caps(WINED3DDEVTYPE devtype, const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
 {
     caps->TextureOpCaps =  WINED3DTEXOPCAPS_DISABLE                     |
@@ -3210,9 +5205,9 @@
     if(stateblock->renderState[WINED3DRS_SPECULARENABLE]) {
         /* The specular color has no alpha */
-        col[0] = 1.0; col[1] = 1.0;
-        col[2] = 1.0; col[3] = 0.0;
+        col[0] = 1.0f; col[1] = 1.0f;
+        col[2] = 1.0f; col[3] = 0.0f;
     } else {
-        col[0] = 0.0; col[1] = 0.0;
-        col[2] = 0.0; col[3] = 0.0;
+        col[0] = 0.0f; col[1] = 0.0f;
+        col[2] = 0.0f; col[3] = 0.0f;
     }
     GL_EXTCALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_SPECULAR_ENABLE, col));
@@ -3283,6 +5278,6 @@
     param[0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVLSCALE]);
     param[1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVLOFFSET]);
-    param[2] = 0.0;
-    param[3] = 0.0;
+    param[2] = 0.0f;
+    param[3] = 0.0f;
 
     GL_EXTCALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_LUMINANCE(stage), param));
@@ -3290,5 +5285,6 @@
 }
 
-static const char *get_argreg(SHADER_BUFFER *buffer, DWORD argnum, unsigned int stage, DWORD arg) {
+static const char *get_argreg(struct wined3d_shader_buffer *buffer, DWORD argnum, unsigned int stage, DWORD arg)
+{
     const char *ret;
 
@@ -3361,6 +5357,7 @@
 }
 
-static void gen_ffp_instr(SHADER_BUFFER *buffer, unsigned int stage, BOOL color, BOOL alpha,
-                          DWORD dst, DWORD op, DWORD dw_arg0, DWORD dw_arg1, DWORD dw_arg2) {
+static void gen_ffp_instr(struct wined3d_shader_buffer *buffer, unsigned int stage, BOOL color,
+        BOOL alpha, DWORD dst, DWORD op, DWORD dw_arg0, DWORD dw_arg1, DWORD dw_arg2)
+{
     const char *dstmask, *dstreg, *arg0, *arg1, *arg2;
     unsigned int mul = 1;
@@ -3503,5 +5500,5 @@
 {
     unsigned int stage;
-    SHADER_BUFFER buffer;
+    struct wined3d_shader_buffer buffer;
     BOOL tex_read[MAX_TEXTURES] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
     BOOL bump_used[MAX_TEXTURES] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
@@ -3566,5 +5563,9 @@
 
     /* Shader header */
-    shader_buffer_init(&buffer);
+    if (!shader_buffer_init(&buffer))
+    {
+        ERR("Failed to initialize shader buffer.\n");
+        return 0;
+    }
 
     shader_addline(&buffer, "!!ARBfp1.0\n");
@@ -3604,4 +5605,6 @@
                        srgb_sub_high, 0.0, 0.0, 0.0);
     }
+
+    if(ffp_clip_emul(stateblock) && settings->emul_clipplanes) shader_addline(&buffer, "KIL fragment.texcoord[7];\n");
 
     /* Generate texture sampling instructions) */
@@ -3790,4 +5793,5 @@
                 return;
             }
+
             new_desc->num_textures_used = 0;
             for(i = 0; i < GL_LIMITS(texture_stages); i++) {
@@ -4067,4 +6071,6 @@
     return WINED3D_OK;
 }
+
+/* Context activation is done by the caller. */
 static void arbfp_blit_free(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) iface;
@@ -4078,9 +6084,10 @@
     GL_EXTCALL(glDeleteProgramsARB(1, &priv->yv12_rect_shader));
     GL_EXTCALL(glDeleteProgramsARB(1, &priv->yv12_2d_shader));
-    checkGLcall("Delete yuv programs\n");
+    checkGLcall("Delete yuv programs");
     LEAVE_GL();
 }
 
-static BOOL gen_planar_yuv_read(SHADER_BUFFER *buffer, enum yuv_fixup yuv_fixup, GLenum textype, char *luminance)
+static BOOL gen_planar_yuv_read(struct wined3d_shader_buffer *buffer, enum yuv_fixup yuv_fixup,
+        GLenum textype, char *luminance)
 {
     char chroma;
@@ -4169,5 +6176,5 @@
 }
 
-static BOOL gen_yv12_read(SHADER_BUFFER *buffer, GLenum textype, char *luminance)
+static BOOL gen_yv12_read(struct wined3d_shader_buffer *buffer, GLenum textype, char *luminance)
 {
     const char *tex;
@@ -4220,5 +6227,5 @@
      */
     shader_addline(buffer, "PARAM yv12_coef = {%f, %f, %f, %f};\n",
-                   2.0 / 3.0, 1.0 / 6.0, (2.0 / 3.0) + (1.0 / 6.0), 1.0 / 3.0);
+            2.0f / 3.0f, 1.0f / 6.0f, (2.0f / 3.0f) + (1.0f / 6.0f), 1.0f / 3.0f);
 
     shader_addline(buffer, "MOV texcrd, fragment.texcoord[0];\n");
@@ -4315,13 +6322,18 @@
 }
 
+/* Context activation is done by the caller. */
 static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, enum yuv_fixup yuv_fixup, GLenum textype)
 {
     GLenum shader;
-    SHADER_BUFFER buffer;
+    struct wined3d_shader_buffer buffer;
     char luminance_component;
     struct arbfp_blit_priv *priv = device->blit_priv;
 
     /* Shader header */
-    shader_buffer_init(&buffer);
+    if (!shader_buffer_init(&buffer))
+    {
+        ERR("Failed to initialize shader buffer.\n");
+        return 0;
+    }
 
     ENTER_GL();
@@ -4451,4 +6463,5 @@
 }
 
+/* Context activation is done by the caller. */
 static HRESULT arbfp_blit_set(IWineD3DDevice *iface, const struct GlPixelFormatDesc *format_desc,
         GLenum textype, UINT width, UINT height)
@@ -4511,4 +6524,5 @@
 }
 
+/* Context activation is done by the caller. */
 static void arbfp_blit_unset(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) iface;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/ati_fragment_shader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/ati_fragment_shader.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/ati_fragment_shader.c	(revision 21731)
@@ -202,6 +202,7 @@
 #define GLINFO_LOCATION (*gl_info)
 
-static void wrap_op1(const WineD3D_GL_Info *gl_info, GLuint op, GLuint dst, GLuint dstMask, GLuint dstMod,
-                     GLuint arg1, GLuint arg1Rep, GLuint arg1Mod) {
+static void wrap_op1(const struct wined3d_gl_info *gl_info, GLuint op, GLuint dst, GLuint dstMask, GLuint dstMod,
+        GLuint arg1, GLuint arg1Rep, GLuint arg1Mod)
+{
     if(dstMask == GL_ALPHA) {
         TRACE("glAlphaFragmentOp1ATI(%s, %s, %s, %s, %s, %s)\n", debug_op(op), debug_register(dst), debug_dstmod(dstMod),
@@ -216,7 +217,7 @@
 }
 
-static void wrap_op2(const WineD3D_GL_Info *gl_info, GLuint op, GLuint dst, GLuint dstMask, GLuint dstMod,
-                     GLuint arg1, GLuint arg1Rep, GLuint arg1Mod,
-                     GLuint arg2, GLuint arg2Rep, GLuint arg2Mod) {
+static void wrap_op2(const struct wined3d_gl_info *gl_info, GLuint op, GLuint dst, GLuint dstMask, GLuint dstMod,
+        GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod)
+{
     if(dstMask == GL_ALPHA) {
         TRACE("glAlphaFragmentOp2ATI(%s, %s, %s, %s, %s, %s, %s, %s, %s)\n", debug_op(op), debug_register(dst), debug_dstmod(dstMod),
@@ -233,8 +234,8 @@
 }
 
-static void wrap_op3(const WineD3D_GL_Info *gl_info, GLuint op, GLuint dst, GLuint dstMask, GLuint dstMod,
-                     GLuint arg1, GLuint arg1Rep, GLuint arg1Mod,
-                     GLuint arg2, GLuint arg2Rep, GLuint arg2Mod,
-                     GLuint arg3, GLuint arg3Rep, GLuint arg3Mod) {
+static void wrap_op3(const struct wined3d_gl_info *gl_info, GLuint op, GLuint dst, GLuint dstMask, GLuint dstMod,
+        GLuint arg1, GLuint arg1Rep, GLuint arg1Mod, GLuint arg2, GLuint arg2Rep, GLuint arg2Mod,
+        GLuint arg3, GLuint arg3Rep, GLuint arg3Mod)
+{
     if(dstMask == GL_ALPHA) {
         /* Leave some free space to fit "GL_NONE, " in to align most alpha and color op lines */
@@ -260,5 +261,5 @@
 }
 
-static GLuint register_for_arg(DWORD arg, const WineD3D_GL_Info *gl_info,
+static GLuint register_for_arg(DWORD arg, const struct wined3d_gl_info *gl_info,
         unsigned int stage, GLuint *mod, GLuint *rep, GLuint tmparg)
 {
@@ -388,5 +389,5 @@
 }
 
-static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], const WineD3D_GL_Info *gl_info)
+static GLuint gen_ati_shader(const struct texture_stage_op op[MAX_TEXTURES], const struct wined3d_gl_info *gl_info)
 {
     GLuint ret = GL_EXTCALL(glGenFragmentShadersATI(1));
@@ -433,11 +434,4 @@
                    GL_TEXTURE0_ARB + stage + 1,
                    swizzle));
-
-        /* We need GL_REG_5_ATI as a temporary register to swizzle the bump matrix. So we run into
-         * issues if we're bump mapping on stage 4 or 5
-         */
-        if(stage >= 4) {
-            FIXME("Bump mapping in stage %d\n", stage);
-        }
     }
 
@@ -470,20 +464,22 @@
                  GL_REG_0_ATI + stage + 1, GL_RED, GL_NONE);
 
-        /* FIXME: How can I make GL_DOT2_ADD_ATI read the factors from blue and alpha? It defaults to red and green,
-         * and it is fairly easy to make it read GL_BLUE or BL_ALPHA, but I can't get an R * B + G * A. So we're wasting
-         * one register and two instructions in this pass for a simple swizzling operation.
-         * For starters it might be good enough to merge the two movs into one, but even that isn't possible :-(
+        /* Don't use GL_DOT2_ADD_ATI here because we cannot configure it to read the blue and alpha
+         * component of the bump matrix. Instead do this with two MADs:
          *
-         * NOTE: GL_BLUE | GL_ALPHA is not possible. It doesn't throw a compilation error, but an OR operation on the
-         * constants doesn't make sense, considering their values.
+         * coord.a = tex.r * bump.b + coord.g
+         * coord.g = tex.g * bump.a + coord.a
+         *
+         * The first instruction writes to alpha so it can be coissued with the above DOT2_ADD.
+         * coord.a is unused. If the perturbed texture is projected, this was already handled
+         * in the glPassTexCoordATI above.
          */
-        wrap_op1(gl_info, GL_MOV_ATI, GL_REG_5_ATI, GL_RED_BIT_ATI, GL_NONE,
-                 ATI_FFP_CONST_BUMPMAT(stage), GL_BLUE, GL_NONE);
-        wrap_op1(gl_info, GL_MOV_ATI, GL_REG_5_ATI, GL_GREEN_BIT_ATI, GL_NONE,
-                 ATI_FFP_CONST_BUMPMAT(stage), GL_ALPHA, GL_NONE);
-        wrap_op3(gl_info, GL_DOT2_ADD_ATI, GL_REG_0_ATI + stage + 1, GL_GREEN_BIT_ATI, GL_NONE,
-                 GL_REG_0_ATI + stage, GL_NONE, argmodextra_y,
-                 GL_REG_5_ATI, GL_NONE, GL_2X_BIT_ATI | GL_BIAS_BIT_ATI,
+        wrap_op3(gl_info, GL_MAD_ATI, GL_REG_0_ATI + stage + 1, GL_ALPHA, GL_NONE,
+                 GL_REG_0_ATI + stage, GL_RED, argmodextra_y,
+                 ATI_FFP_CONST_BUMPMAT(stage), GL_BLUE, GL_NONE,
                  GL_REG_0_ATI + stage + 1, GL_GREEN, GL_NONE);
+        wrap_op3(gl_info, GL_MAD_ATI, GL_REG_0_ATI + stage + 1, GL_GREEN_BIT_ATI, GL_NONE,
+                 GL_REG_0_ATI + stage, GL_GREEN, argmodextra_y,
+                 ATI_FFP_CONST_BUMPMAT(stage), GL_ALPHA, GL_NONE,
+                 GL_REG_0_ATI + stage + 1, GL_ALPHA, GL_NONE);
     }
 
@@ -879,8 +875,8 @@
      * support proper floats it shouldn't, and if it doesn't we can't get anything better anyway
      */
-    mat[0][0] = (mat[0][0] + 1.0) * 0.5;
-    mat[1][0] = (mat[1][0] + 1.0) * 0.5;
-    mat[0][1] = (mat[0][1] + 1.0) * 0.5;
-    mat[1][1] = (mat[1][1] + 1.0) * 0.5;
+    mat[0][0] = (mat[0][0] + 1.0f) * 0.5f;
+    mat[1][0] = (mat[1][0] + 1.0f) * 0.5f;
+    mat[0][1] = (mat[0][1] + 1.0f) * 0.5f;
+    mat[1][1] = (mat[1][1] + 1.0f) * 0.5f;
     GL_EXTCALL(glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage), (float *) mat));
     checkGLcall("glSetFragmentShaderConstantATI(ATI_FFP_CONST_BUMPMAT(stage), mat)");
@@ -1053,4 +1049,5 @@
 };
 
+/* Context activation is done by the caller. */
 static void atifs_enable(IWineD3DDevice *iface, BOOL enable) {
     ENTER_GL();
@@ -1065,5 +1062,5 @@
 }
 
-static void atifs_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct fragment_caps *caps)
+static void atifs_get_caps(WINED3DDEVTYPE devtype, const struct wined3d_gl_info *gl_info, struct fragment_caps *caps)
 {
     caps->TextureOpCaps =  WINED3DTEXOPCAPS_DISABLE                     |
@@ -1133,4 +1130,5 @@
 
 #define GLINFO_LOCATION This->adapter->gl_info
+/* Context activation is done by the caller. */
 static void atifs_free_ffpshader(struct wine_rb_entry *entry, void *context)
 {
@@ -1145,4 +1143,5 @@
 }
 
+/* Context activation is done by the caller. */
 static void atifs_free(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/baseshader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/baseshader.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/baseshader.c	(revision 21731)
@@ -148,12 +148,6 @@
 }
 
-static inline BOOL shader_is_version_token(DWORD token) {
-    return shader_is_pshader_version(token) ||
-           shader_is_vshader_version(token);
-}
-
-void shader_buffer_init(struct SHADER_BUFFER *buffer)
-{
-    buffer->buffer = HeapAlloc(GetProcessHeap(), 0, SHADER_PGMSIZE);
+void shader_buffer_clear(struct wined3d_shader_buffer *buffer)
+{
     buffer->buffer[0] = '\0';
     buffer->bsize = 0;
@@ -162,10 +156,23 @@
 }
 
-void shader_buffer_free(struct SHADER_BUFFER *buffer)
+BOOL shader_buffer_init(struct wined3d_shader_buffer *buffer)
+{
+    buffer->buffer = HeapAlloc(GetProcessHeap(), 0, SHADER_PGMSIZE);
+    if (!buffer->buffer)
+    {
+        ERR("Failed to allocate shader buffer memory.\n");
+        return FALSE;
+    }
+
+    shader_buffer_clear(buffer);
+    return TRUE;
+}
+
+void shader_buffer_free(struct wined3d_shader_buffer *buffer)
 {
     HeapFree(GetProcessHeap(), 0, buffer->buffer);
 }
 
-int shader_vaddline(SHADER_BUFFER* buffer, const char *format, va_list args)
+int shader_vaddline(struct wined3d_shader_buffer *buffer, const char *format, va_list args)
 {
     char* base = buffer->buffer + buffer->bsize;
@@ -174,7 +181,6 @@
     rc = _vsnprintf(base, SHADER_PGMSIZE - 1 - buffer->bsize, format, args);
 
-    if (rc < 0 ||                                   /* C89 */ 
-        rc > SHADER_PGMSIZE - 1 - buffer->bsize) {  /* C99 */
-
+    if (rc < 0 /* C89 */ || (unsigned int)rc > SHADER_PGMSIZE - 1 - buffer->bsize /* C99 */)
+    {
         ERR("The buffer allocated for the shader program string "
             "is too small at %d bytes.\n", SHADER_PGMSIZE);
@@ -198,5 +204,5 @@
 }
 
-int shader_addline(SHADER_BUFFER* buffer, const char *format, ...)
+int shader_addline(struct wined3d_shader_buffer *buffer, const char *format, ...)
 {
     int ret;
@@ -256,10 +262,10 @@
 
 static void shader_record_register_usage(IWineD3DBaseShaderImpl *This, struct shader_reg_maps *reg_maps,
-        const struct wined3d_shader_register *reg, BOOL pshader)
+        const struct wined3d_shader_register *reg, enum wined3d_shader_type shader_type)
 {
     switch (reg->type)
     {
         case WINED3DSPR_TEXTURE: /* WINED3DSPR_ADDR */
-            if (pshader) reg_maps->texcoord[reg->idx] = 1;
+            if (shader_type == WINED3D_SHADER_TYPE_PIXEL) reg_maps->texcoord[reg->idx] = 1;
             else reg_maps->address[reg->idx] = 1;
             break;
@@ -270,6 +276,5 @@
 
         case WINED3DSPR_INPUT:
-            if (!pshader) reg_maps->input_registers |= 1 << reg->idx;
-            else
+            if (shader_type == WINED3D_SHADER_TYPE_PIXEL)
             {
                 if (reg->rel_addr)
@@ -289,4 +294,5 @@
                 }
             }
+            else reg_maps->input_registers |= 1 << reg->idx;
             break;
 
@@ -296,5 +302,9 @@
 
         case WINED3DSPR_MISCTYPE:
-            if (pshader && reg->idx == 0) reg_maps->vpos = 1;
+            if (shader_type == WINED3D_SHADER_TYPE_PIXEL)
+            {
+                if (reg->idx == 0) reg_maps->vpos = 1;
+                else if (reg->idx == 1) reg_maps->usesfacing = 1;
+            }
             break;
 
@@ -302,10 +312,14 @@
             if (reg->rel_addr)
             {
-                if (!pshader)
+                if (shader_type != WINED3D_SHADER_TYPE_PIXEL)
                 {
-                    if (reg->idx <= ((IWineD3DVertexShaderImpl *)This)->min_rel_offset)
+                    if (reg->idx < ((IWineD3DVertexShaderImpl *)This)->min_rel_offset)
+                    {
                         ((IWineD3DVertexShaderImpl *)This)->min_rel_offset = reg->idx;
-                    else if (reg->idx >= ((IWineD3DVertexShaderImpl *)This)->max_rel_offset)
+                    }
+                    if (reg->idx > ((IWineD3DVertexShaderImpl *)This)->max_rel_offset)
+                    {
                         ((IWineD3DVertexShaderImpl *)This)->max_rel_offset = reg->idx;
+                    }
                 }
                 reg_maps->usesrelconstF = TRUE;
@@ -323,4 +337,8 @@
         case WINED3DSPR_CONSTBOOL:
             reg_maps->boolean_constants |= (1 << reg->idx);
+            break;
+
+        case WINED3DSPR_COLOROUT:
+            reg_maps->highest_render_target = max(reg_maps->highest_render_target, reg->idx);
             break;
 
@@ -409,5 +427,4 @@
     unsigned int cur_loop_depth = 0, max_loop_depth = 0;
     const DWORD* pToken = byte_code;
-    char pshader;
 
     /* There are some minor differences between pixel and vertex shaders */
@@ -424,5 +441,4 @@
     fe->shader_read_header(fe_data, &pToken, &shader_version);
     reg_maps->shader_version = shader_version;
-    pshader = shader_is_pshader_version(shader_version.type);
 
     reg_maps->constf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
@@ -510,15 +526,15 @@
 
             /* In pixel shader 1.X shaders, the constants are clamped between [-1;1] */
-            if (shader_version.major == 1 && pshader)
+            if (shader_version.major == 1 && shader_version.type == WINED3D_SHADER_TYPE_PIXEL)
             {
                 float *value = (float *) lconst->value;
-                if(value[0] < -1.0) value[0] = -1.0;
-                else if(value[0] >  1.0) value[0] =  1.0;
-                if(value[1] < -1.0) value[1] = -1.0;
-                else if(value[1] >  1.0) value[1] =  1.0;
-                if(value[2] < -1.0) value[2] = -1.0;
-                else if(value[2] >  1.0) value[2] =  1.0;
-                if(value[3] < -1.0) value[3] = -1.0;
-                else if(value[3] >  1.0) value[3] =  1.0;
+                if (value[0] < -1.0f) value[0] = -1.0f;
+                else if (value[0] > 1.0f) value[0] = 1.0f;
+                if (value[1] < -1.0f) value[1] = -1.0f;
+                else if (value[1] > 1.0f) value[1] = 1.0f;
+                if (value[2] < -1.0f) value[2] = -1.0f;
+                else if (value[2] > 1.0f) value[2] = 1.0f;
+                if (value[3] < -1.0f) value[3] = -1.0f;
+                else if (value[3] > 1.0f) value[3] = 1.0f;
             }
 
@@ -540,4 +556,5 @@
 
             list_add_head(&This->baseShader.constantsI, &lconst->entry);
+            reg_maps->local_int_consts |= (1 << dst.reg.idx);
         }
         else if (ins.handler_idx == WINED3DSIH_DEFB)
@@ -614,24 +631,47 @@
                 fe->shader_read_dst_param(fe_data, &pToken, &dst_param, &dst_rel_addr);
 
+                shader_record_register_usage(This, reg_maps, &dst_param.reg, shader_version.type);
+
                 /* WINED3DSPR_TEXCRDOUT is the same as WINED3DSPR_OUTPUT. _OUTPUT can be > MAX_REG_TEXCRD and
                  * is used in >= 3.0 shaders. Filter 3.0 shaders to prevent overflows, and also filter pixel
                  * shaders because TECRDOUT isn't used in them, but future register types might cause issues */
-                if (!pshader && shader_version.major < 3 && dst_param.reg.type == WINED3DSPR_TEXCRDOUT)
+                if (shader_version.type == WINED3D_SHADER_TYPE_VERTEX && shader_version.major < 3
+                        && dst_param.reg.type == WINED3DSPR_TEXCRDOUT)
                 {
-                    reg_maps->texcoord_mask[dst_param.reg.type] |= dst_param.write_mask;
+                    reg_maps->texcoord_mask[dst_param.reg.idx] |= dst_param.write_mask;
                 }
-                else
+
+                if (shader_version.type == WINED3D_SHADER_TYPE_PIXEL)
                 {
-                    if(pshader && dst_param.reg.type == WINED3DSPR_COLOROUT && dst_param.reg.idx == 0)
+                    IWineD3DPixelShaderImpl *ps = (IWineD3DPixelShaderImpl *)This;
+
+                    if(dst_param.reg.type == WINED3DSPR_COLOROUT && dst_param.reg.idx == 0)
                     {
-                        IWineD3DPixelShaderImpl *ps = (IWineD3DPixelShaderImpl *) This;
+                    /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
+                     * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
+                     * the mov and perform the sRGB write correction from the source register.
+                     *
+                     * However, if the mov is only partial, we can't do this, and if the write
+                     * comes from an instruction other than MOV it is hard to do as well. If
+                     * COLOROUT 0 is overwritten partially later, the marker is dropped again. */
+
+                        ps->color0_mov = FALSE;
+                        if (ins.handler_idx == WINED3DSIH_MOV)
+                        {
+                            /* Used later when the source register is read. */
+                            color0_mov = TRUE;
+                        }
+                    }
+                    /* Also drop the MOV marker if the source register is overwritten prior to the shader
+                     * end
+                     */
+                    else if(dst_param.reg.type == WINED3DSPR_TEMP && dst_param.reg.idx == ps->color0_reg)
+                    {
                         ps->color0_mov = FALSE;
                     }
-                    shader_record_register_usage(This, reg_maps, &dst_param.reg, pshader);
                 }
 
                 /* Declare 1.X samplers implicitly, based on the destination reg. number */
                 if (shader_version.major == 1
-                        && pshader /* Filter different instructions with the same enum values in VS */
                         && (ins.handler_idx == WINED3DSIH_TEX
                             || ins.handler_idx == WINED3DSIH_TEXBEM
@@ -663,24 +703,8 @@
                     }
                 }
-                else if (pshader && ins.handler_idx == WINED3DSIH_BEM)
+                else if (ins.handler_idx == WINED3DSIH_BEM)
                 {
                     reg_maps->bumpmat[dst_param.reg.idx] = TRUE;
                 }
-                else if(pshader && ins.handler_idx == WINED3DSIH_MOV)
-                {
-                    /* Many 2.0 and 3.0 pixel shaders end with a MOV from a temp register to
-                     * COLOROUT 0. If we know this in advance, the ARB shader backend can skip
-                     * the mov and perform the sRGB write correction from the source register.
-                     *
-                     * However, if the mov is only partial, we can't do this, and if the write
-                     * comes from an instruction other than MOV it is hard to do as well. If
-                     * COLOROUT 0 is overwritten partially later, the marker is dropped again
-                     */
-                    if(dst_param.reg.type == WINED3DSPR_COLOROUT && dst_param.reg.idx == 0)
-                    {
-                        /* Used later when the source register is read */
-                        color0_mov = TRUE;
-                    }
-                }
             }
 
@@ -701,7 +725,19 @@
                 reg_maps->usestexldd = 1;
             }
+            else if(ins.handler_idx == WINED3DSIH_TEXLDL)
+            {
+                reg_maps->usestexldl = 1;
+            }
             else if(ins.handler_idx == WINED3DSIH_MOVA)
             {
                 reg_maps->usesmova = 1;
+            }
+            else if(ins.handler_idx == WINED3DSIH_IFC)
+            {
+                reg_maps->usesifc = 1;
+            }
+            else if(ins.handler_idx == WINED3DSIH_CALL)
+            {
+                reg_maps->usescall = 1;
             }
 
@@ -715,9 +751,9 @@
                 count = get_instr_extra_regcount(ins.handler_idx, i);
 
-                shader_record_register_usage(This, reg_maps, &src_param.reg, pshader);
+                shader_record_register_usage(This, reg_maps, &src_param.reg, shader_version.type);
                 while (count)
                 {
                     ++src_param.reg.idx;
-                    shader_record_register_usage(This, reg_maps, &src_param.reg, pshader);
+                    shader_record_register_usage(This, reg_maps, &src_param.reg, shader_version.type);
                     --count;
                 }
@@ -738,5 +774,5 @@
     reg_maps->loop_depth = max_loop_depth;
 
-    This->baseShader.functionLength = ((char *)pToken - (char *)byte_code);
+    This->baseShader.functionLength = ((const char *)pToken - (const char *)byte_code);
 
     return WINED3D_OK;
@@ -761,5 +797,5 @@
     {
         /* Pixel shaders 3.0 don't have usage semantics */
-        if (shader_is_pshader_version(shader_version->type) && shader_version->major < 3)
+        if (shader_version->major < 3 && shader_version->type == WINED3D_SHADER_TYPE_PIXEL)
             return;
         else
@@ -843,5 +879,5 @@
 
         case WINED3DSPR_TEXTURE: /* vs: case WINED3DSPR_ADDR */
-            TRACE("%c", shader_is_pshader_version(shader_version->type) ? 't' : 'a');
+            TRACE("%c", shader_version->type == WINED3D_SHADER_TYPE_PIXEL ? 't' : 'a');
             break;
 
@@ -902,4 +938,8 @@
             break;
 
+        case WINED3DSPR_CONSTBUFFER:
+            TRACE("cb");
+            break;
+
         default:
             TRACE("unhandled_rtype(%#x)", reg->type);
@@ -913,11 +953,11 @@
         {
             case WINED3D_IMMCONST_FLOAT:
-                TRACE("%.8e", *(float *)reg->immconst_data);
+                TRACE("%.8e", *(const float *)reg->immconst_data);
                 break;
 
             case WINED3D_IMMCONST_FLOAT4:
                 TRACE("%.8e, %.8e, %.8e, %.8e",
-                        *(float *)&reg->immconst_data[0], *(float *)&reg->immconst_data[1],
-                        *(float *)&reg->immconst_data[2], *(float *)&reg->immconst_data[3]);
+                        *(const float *)&reg->immconst_data[0], *(const float *)&reg->immconst_data[1],
+                        *(const float *)&reg->immconst_data[2], *(const float *)&reg->immconst_data[3]);
                 break;
 
@@ -930,12 +970,25 @@
     else if (reg->type != WINED3DSPR_RASTOUT && reg->type != WINED3DSPR_MISCTYPE)
     {
-        if (reg->rel_addr)
-        {
-            TRACE("[");
-            shader_dump_src_param(reg->rel_addr, shader_version);
-            TRACE(" + ");
-        }
-        TRACE("%u", offset);
-        if (reg->rel_addr) TRACE("]");
+        if (reg->array_idx != ~0U)
+        {
+            TRACE("%u[%u", offset, reg->array_idx);
+            if (reg->rel_addr)
+            {
+                TRACE(" + ");
+                shader_dump_src_param(reg->rel_addr, shader_version);
+            }
+            TRACE("]");
+        }
+        else
+        {
+            if (reg->rel_addr)
+            {
+                TRACE("[");
+                shader_dump_src_param(reg->rel_addr, shader_version);
+                TRACE(" + ");
+            }
+            TRACE("%u", offset);
+            if (reg->rel_addr) TRACE("]");
+        }
     }
 }
@@ -1029,5 +1082,5 @@
 /* Shared code in order to generate the bulk of the shader string.
  * NOTE: A description of how to parse tokens can be found on msdn */
-void shader_generate_main(IWineD3DBaseShader *iface, SHADER_BUFFER *buffer,
+void shader_generate_main(IWineD3DBaseShader *iface, struct wined3d_shader_buffer *buffer,
         const shader_reg_maps *reg_maps, const DWORD *pFunction, void *backend_ctx)
 {
@@ -1085,6 +1138,5 @@
                 || ins.handler_idx == WINED3DSIH_DEFI
                 || ins.handler_idx == WINED3DSIH_DEFB
-                || ins.handler_idx == WINED3DSIH_PHASE
-                || ins.handler_idx == WINED3DSIH_RET)
+                || ins.handler_idx == WINED3DSIH_PHASE)
         {
             pToken += param_size;
@@ -1138,4 +1190,5 @@
     struct wined3d_shader_version shader_version;
     const DWORD* pToken = pFunction;
+    const char *type_prefix;
     DWORD i;
 
@@ -1144,6 +1197,25 @@
     fe->shader_read_header(fe_data, &pToken, &shader_version);
 
-    TRACE("%s_%u_%u\n", shader_is_pshader_version(shader_version.type) ? "ps": "vs",
-            shader_version.major, shader_version.minor);
+    switch (shader_version.type)
+    {
+        case WINED3D_SHADER_TYPE_VERTEX:
+            type_prefix = "vs";
+            break;
+
+        case WINED3D_SHADER_TYPE_GEOMETRY:
+            type_prefix = "gs";
+            break;
+
+        case WINED3D_SHADER_TYPE_PIXEL:
+            type_prefix = "ps";
+            break;
+
+        default:
+            FIXME("Unhandled shader type %#x.\n", shader_version.type);
+            type_prefix = "unknown";
+            break;
+    }
+
+    TRACE("%s_%u_%u\n", type_prefix, shader_version.major, shader_version.minor);
 
     while (!fe->shader_is_end(fe_data, &pToken))
@@ -1317,10 +1389,11 @@
 
 #define GLINFO_LOCATION      (*gl_info)
-static void shader_none_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct shader_caps *pCaps)
+static void shader_none_get_caps(WINED3DDEVTYPE devtype,
+        const struct wined3d_gl_info *gl_info, struct shader_caps *pCaps)
 {
     /* Set the shader caps to 0 for the none shader backend */
     pCaps->VertexShaderVersion  = 0;
     pCaps->PixelShaderVersion    = 0;
-    pCaps->PixelShader1xMaxValue = 0.0;
+    pCaps->PixelShader1xMaxValue = 0.0f;
 }
 #undef GLINFO_LOCATION
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c	(revision 21731)
@@ -63,17 +63,5 @@
 void basetexture_cleanup(IWineD3DBaseTexture *iface)
 {
-    IWineD3DBaseTextureImpl *This = (IWineD3DBaseTextureImpl *)iface;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
-
-    TRACE("(%p) : textureName(%d)\n", This, This->baseTexture.textureName);
-    if (This->baseTexture.textureName != 0) {
-        ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
-        ENTER_GL();
-        TRACE("(%p) : Deleting texture %d\n", This, This->baseTexture.textureName);
-        glDeleteTextures(1, &This->baseTexture.textureName);
-        glDeleteTextures(1, &This->baseTexture.srgbTextureName);
-        LEAVE_GL();
-    }
-
+    basetexture_unload(iface);
     resource_cleanup((IWineD3DResource *)iface);
 }
@@ -88,6 +76,12 @@
         ENTER_GL();
         glDeleteTextures(1, &This->baseTexture.textureName);
+        This->baseTexture.textureName = 0;
+        LEAVE_GL();
+    }
+
+    if(This->baseTexture.srgbTextureName) {
+        ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
+        ENTER_GL();
         glDeleteTextures(1, &This->baseTexture.srgbTextureName);
-        This->baseTexture.textureName = 0;
         This->baseTexture.srgbTextureName = 0;
         LEAVE_GL();
@@ -213,4 +207,5 @@
 }
 
+/* Context activation is done by the caller. */
 HRESULT basetexture_bind(IWineD3DBaseTexture *iface, BOOL srgb, BOOL *set_surface_desc)
 {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/buffer.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/buffer.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/buffer.c	(revision 21731)
@@ -44,14 +44,12 @@
 #define VB_RESETDECLCHANGE    1000    /* Reset the changecount after that number of draws */
 
+/* Context activation is done by the caller. */
 static void buffer_create_buffer_object(struct wined3d_buffer *This)
 {
     GLenum error, gl_usage;
-    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
 
     TRACE("Creating an OpenGL vertex buffer object for IWineD3DVertexBuffer %p Usage(%s)\n",
             This, debug_d3dusage(This->resource.usage));
 
-    /* Make sure that a context is there. Needed in a multithreaded environment. Otherwise this call is a nop */
-    ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
     ENTER_GL();
 
@@ -467,4 +465,5 @@
 }
 
+/* Context activation is done by the caller. */
 static void buffer_check_buffer_object_size(struct wined3d_buffer *This)
 {
@@ -516,27 +515,16 @@
 static inline void fixup_transformed_pos(float *p)
 {
-    float x, y, z, w;
-
-    /* rhw conversion like in drawStridedSlow */
-    if (p[3] == 1.0 || ((p[3] < eps) && (p[3] > -eps)))
-    {
-        x = p[0];
-        y = p[1];
-        z = p[2];
-        w = 1.0;
-    }
-    else
-    {
-        w = 1.0 / p[3];
-        x = p[0] * w;
-        y = p[1] * w;
-        z = p[2] * w;
-    }
-    p[0] = x;
-    p[1] = y;
-    p[2] = z;
-    p[3] = w;
-}
-
+    /* rhw conversion like in position_float4(). */
+    if (p[3] != 1.0f && p[3] != 0.0f)
+    {
+        float w = 1.0f / p[3];
+        p[0] *= w;
+        p[1] *= w;
+        p[2] *= w;
+        p[3] = w;
+    }
+}
+
+/* Context activation is done by the caller. */
 const BYTE *buffer_get_memory(IWineD3DBuffer *iface, UINT offset, GLuint *buffer_object)
 {
@@ -598,5 +586,6 @@
 }
 
-const BYTE *buffer_get_sysmem(struct wined3d_buffer *This)
+/* Context activation is done by the caller. */
+BYTE *buffer_get_sysmem(struct wined3d_buffer *This)
 {
     /* AllocatedMemory exists if the buffer is double buffered or has no buffer object at all */
@@ -711,4 +700,6 @@
     TRACE("iface %p\n", iface);
 
+    ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
+
     if (!This->buffer_object)
     {
@@ -746,5 +737,5 @@
         {
             FIXME("Too many declaration changes, stopping converting\n");
-            ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
+
             ENTER_GL();
             GL_EXTCALL(glDeleteBuffersARB(1, &This->buffer_object));
@@ -994,4 +985,14 @@
 
     TRACE("(%p)\n", This);
+
+    /* In the case that the number of Unmap calls > the
+     * number of Map calls, d3d returns always D3D_OK.
+     * This is also needed to prevent Map from returning garbage on
+     * the next call (this will happen if the lock_count is < 0). */
+    if(This->lock_count == 0)
+    {
+        TRACE("Unmap called without a previous Map call!\n");
+        return WINED3D_OK;
+    }
 
     if (InterlockedDecrement(&This->lock_count))
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/context.c	(revision 21731)
@@ -37,7 +37,6 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
 
-#define GLINFO_LOCATION This->adapter->gl_info
-
-/* GL locking is done by the caller */
+#define GLINFO_LOCATION (*gl_info)
+
 /* The last used device.
  *
@@ -47,23 +46,62 @@
 static IWineD3DDeviceImpl *last_device;
 
+void context_set_last_device(IWineD3DDeviceImpl *device)
+{
+    last_device = device;
+}
+
 /* FBO helper functions */
 
-void context_bind_fbo(IWineD3DDevice *iface, GLenum target, GLuint *fbo)
+/* GL locking is done by the caller */
+void context_bind_fbo(struct WineD3DContext *context, GLenum target, GLuint *fbo)
 {
-    const IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-
-    if (!*fbo)
-    {
-        GL_EXTCALL(glGenFramebuffersEXT(1, fbo));
-        checkGLcall("glGenFramebuffersEXT()");
-        TRACE("Created FBO %d\n", *fbo);
-    }
-
-    GL_EXTCALL(glBindFramebufferEXT(target, *fbo));
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+    GLuint f;
+
+    if (!fbo)
+    {
+        f = 0;
+    }
+    else
+    {
+        if (!*fbo)
+        {
+            GL_EXTCALL(glGenFramebuffersEXT(1, fbo));
+            checkGLcall("glGenFramebuffersEXT()");
+            TRACE("Created FBO %u.\n", *fbo);
+        }
+        f = *fbo;
+    }
+
+    switch (target)
+    {
+        case GL_READ_FRAMEBUFFER_EXT:
+            if (context->fbo_read_binding == f) return;
+            context->fbo_read_binding = f;
+            break;
+
+        case GL_DRAW_FRAMEBUFFER_EXT:
+            if (context->fbo_draw_binding == f) return;
+            context->fbo_draw_binding = f;
+            break;
+
+        case GL_FRAMEBUFFER_EXT:
+            if (context->fbo_read_binding == f
+                    && context->fbo_draw_binding == f) return;
+            context->fbo_read_binding = f;
+            context->fbo_draw_binding = f;
+            break;
+
+        default:
+            FIXME("Unhandled target %#x.\n", target);
+            break;
+    }
+
+    GL_EXTCALL(glBindFramebufferEXT(target, f));
     checkGLcall("glBindFramebuffer()");
 }
 
 /* GL locking is done by the caller */
-static void context_clean_fbo_attachments(IWineD3DDeviceImpl *This)
+static void context_clean_fbo_attachments(const struct wined3d_gl_info *gl_info)
 {
     unsigned int i;
@@ -76,16 +114,18 @@
     GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0));
     checkGLcall("glFramebufferTexture2D()");
+
+    GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0));
+    checkGLcall("glFramebufferTexture2D()");
 }
 
 /* GL locking is done by the caller */
-static void context_destroy_fbo(IWineD3DDeviceImpl *This, const GLuint *fbo)
+static void context_destroy_fbo(struct WineD3DContext *context, GLuint *fbo)
 {
-    GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, *fbo));
-    checkGLcall("glBindFramebuffer()");
-
-    context_clean_fbo_attachments(This);
-
-    GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
-    checkGLcall("glBindFramebuffer()");
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+
+    context_bind_fbo(context, GL_FRAMEBUFFER_EXT, fbo);
+    context_clean_fbo_attachments(gl_info);
+    context_bind_fbo(context, GL_FRAMEBUFFER_EXT, NULL);
+
     GL_EXTCALL(glDeleteFramebuffersEXT(1, fbo));
     checkGLcall("glDeleteFramebuffers()");
@@ -93,8 +133,8 @@
 
 /* GL locking is done by the caller */
-static void context_apply_attachment_filter_states(IWineD3DDevice *iface, IWineD3DSurface *surface, BOOL force_preload)
+static void context_apply_attachment_filter_states(IWineD3DSurface *surface, BOOL force_preload)
 {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     const IWineD3DSurfaceImpl *surface_impl = (IWineD3DSurfaceImpl *)surface;
+    IWineD3DDeviceImpl *device = surface_impl->resource.wineD3DDevice;
     IWineD3DBaseTextureImpl *texture_impl;
     BOOL update_minfilter = FALSE;
@@ -121,5 +161,5 @@
         {
             WARN("Render targets should not be bound to a sampler\n");
-            IWineD3DDeviceImpl_MarkStateDirty(This, STATE_SAMPLER(texture_impl->baseTexture.sampler));
+            IWineD3DDeviceImpl_MarkStateDirty(device, STATE_SAMPLER(texture_impl->baseTexture.sampler));
         }
 
@@ -132,5 +172,5 @@
         GLint old_binding;
 
-        target = surface_impl->glDescription.target;
+        target = surface_impl->texture_target;
         if (target == GL_TEXTURE_2D)
         {
@@ -147,5 +187,5 @@
         surface_internal_preload(surface, SRGB_RGB);
 
-        glBindTexture(bind_target, surface_impl->glDescription.textureName);
+        glBindTexture(bind_target, surface_impl->texture_name);
         if (update_minfilter) glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
         if (update_magfilter) glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
@@ -156,9 +196,10 @@
 }
 
-/* TODO: Handle stencil attachments */
 /* GL locking is done by the caller */
-void context_attach_depth_stencil_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, IWineD3DSurface *depth_stencil, BOOL use_render_buffer)
+void context_attach_depth_stencil_fbo(struct WineD3DContext *context,
+        GLenum fbo_target, IWineD3DSurface *depth_stencil, BOOL use_render_buffer)
 {
     IWineD3DSurfaceImpl *depth_stencil_impl = (IWineD3DSurfaceImpl *)depth_stencil;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
 
     TRACE("Attach depth stencil %p\n", depth_stencil);
@@ -166,25 +207,71 @@
     if (depth_stencil)
     {
+        DWORD format_flags = depth_stencil_impl->resource.format_desc->Flags;
+
         if (use_render_buffer && depth_stencil_impl->current_renderbuffer)
         {
-            GL_EXTCALL(glFramebufferRenderbufferEXT(fbo_target, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_stencil_impl->current_renderbuffer->id));
-            checkGLcall("glFramebufferRenderbufferEXT()");
-        } else {
-            context_apply_attachment_filter_states((IWineD3DDevice *)This, depth_stencil, TRUE);
-
-            GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_DEPTH_ATTACHMENT_EXT, depth_stencil_impl->glDescription.target,
-                        depth_stencil_impl->glDescription.textureName, depth_stencil_impl->glDescription.level));
+            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()");
+            }
+
+            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()");
+            }
+        }
+        else
+        {
+            context_apply_attachment_filter_states(depth_stencil, TRUE);
+
+            if (format_flags & WINED3DFMT_FLAG_DEPTH)
+            {
+                GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_DEPTH_ATTACHMENT_EXT,
+                        depth_stencil_impl->texture_target, depth_stencil_impl->texture_name,
+                        depth_stencil_impl->texture_level));
+                checkGLcall("glFramebufferTexture2DEXT()");
+            }
+
+            if (format_flags & WINED3DFMT_FLAG_STENCIL)
+            {
+                GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_STENCIL_ATTACHMENT_EXT,
+                        depth_stencil_impl->texture_target, depth_stencil_impl->texture_name,
+                        depth_stencil_impl->texture_level));
+                checkGLcall("glFramebufferTexture2DEXT()");
+            }
+        }
+
+        if (!(format_flags & WINED3DFMT_FLAG_DEPTH))
+        {
+            GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0));
             checkGLcall("glFramebufferTexture2DEXT()");
         }
-    } else {
+
+        if (!(format_flags & WINED3DFMT_FLAG_STENCIL))
+        {
+            GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0));
+            checkGLcall("glFramebufferTexture2DEXT()");
+        }
+    }
+    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 locking is done by the caller */
-void context_attach_surface_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, DWORD idx, IWineD3DSurface *surface)
+void context_attach_surface_fbo(const struct WineD3DContext *context,
+        GLenum fbo_target, DWORD idx, IWineD3DSurface *surface)
 {
     const IWineD3DSurfaceImpl *surface_impl = (IWineD3DSurfaceImpl *)surface;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
 
     TRACE("Attach surface %p to %u\n", surface, idx);
@@ -192,8 +279,8 @@
     if (surface)
     {
-        context_apply_attachment_filter_states((IWineD3DDevice *)This, surface, TRUE);
-
-        GL_EXTCALL(glFramebufferTexture2DEXT(fbo_target, GL_COLOR_ATTACHMENT0_EXT + idx, surface_impl->glDescription.target,
-                surface_impl->glDescription.textureName, surface_impl->glDescription.level));
+        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 {
@@ -204,7 +291,7 @@
 
 /* GL locking is done by the caller */
-static void context_check_fbo_status(IWineD3DDevice *iface)
+static void context_check_fbo_status(struct WineD3DContext *context)
 {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     GLenum status;
 
@@ -221,5 +308,5 @@
         for (i = 0; i < GL_LIMITS(buffers); ++i)
         {
-            attachment = (IWineD3DSurfaceImpl *)This->activeContext->current_fbo->render_targets[i];
+            attachment = (IWineD3DSurfaceImpl *)context->current_fbo->render_targets[i];
             if (attachment)
             {
@@ -229,5 +316,5 @@
             }
         }
-        attachment = (IWineD3DSurfaceImpl *)This->activeContext->current_fbo->depth_stencil;
+        attachment = (IWineD3DSurfaceImpl *)context->current_fbo->depth_stencil;
         if (attachment)
         {
@@ -239,13 +326,14 @@
 }
 
-static struct fbo_entry *context_create_fbo_entry(IWineD3DDevice *iface)
+static struct fbo_entry *context_create_fbo_entry(struct WineD3DContext *context)
 {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     struct fbo_entry *entry;
 
     entry = HeapAlloc(GetProcessHeap(), 0, sizeof(*entry));
     entry->render_targets = HeapAlloc(GetProcessHeap(), 0, GL_LIMITS(buffers) * sizeof(*entry->render_targets));
-    memcpy(entry->render_targets, This->render_targets, GL_LIMITS(buffers) * sizeof(*entry->render_targets));
-    entry->depth_stencil = This->stencilBufferTarget;
+    memcpy(entry->render_targets, device->render_targets, GL_LIMITS(buffers) * sizeof(*entry->render_targets));
+    entry->depth_stencil = device->stencilBufferTarget;
     entry->attached = FALSE;
     entry->id = 0;
@@ -255,24 +343,24 @@
 
 /* GL locking is done by the caller */
-static void context_reuse_fbo_entry(IWineD3DDevice *iface, struct fbo_entry *entry)
+static void context_reuse_fbo_entry(struct WineD3DContext *context, struct fbo_entry *entry)
 {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-
-    GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, entry->id));
-    checkGLcall("glBindFramebuffer()");
-    context_clean_fbo_attachments(This);
-
-    memcpy(entry->render_targets, This->render_targets, GL_LIMITS(buffers) * sizeof(*entry->render_targets));
-    entry->depth_stencil = This->stencilBufferTarget;
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
+
+    context_bind_fbo(context, GL_FRAMEBUFFER_EXT, &entry->id);
+    context_clean_fbo_attachments(gl_info);
+
+    memcpy(entry->render_targets, device->render_targets, GL_LIMITS(buffers) * sizeof(*entry->render_targets));
+    entry->depth_stencil = device->stencilBufferTarget;
     entry->attached = FALSE;
 }
 
 /* GL locking is done by the caller */
-static void context_destroy_fbo_entry(IWineD3DDeviceImpl *This, WineD3DContext *context, struct fbo_entry *entry)
+static void context_destroy_fbo_entry(struct WineD3DContext *context, struct fbo_entry *entry)
 {
     if (entry->id)
     {
         TRACE("Destroy FBO %d\n", entry->id);
-        context_destroy_fbo(This, &entry->id);
+        context_destroy_fbo(context, &entry->id);
     }
     --context->fbo_entry_count;
@@ -284,13 +372,14 @@
 
 /* GL locking is done by the caller */
-static struct fbo_entry *context_find_fbo_entry(IWineD3DDevice *iface, WineD3DContext *context)
+static struct fbo_entry *context_find_fbo_entry(struct WineD3DContext *context)
 {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     struct fbo_entry *entry;
 
     LIST_FOR_EACH_ENTRY(entry, &context->fbo_list, struct fbo_entry, entry)
     {
-        if (!memcmp(entry->render_targets, This->render_targets, GL_LIMITS(buffers) * sizeof(*entry->render_targets))
-                && entry->depth_stencil == This->stencilBufferTarget)
+        if (!memcmp(entry->render_targets, device->render_targets, GL_LIMITS(buffers) * sizeof(*entry->render_targets))
+                && entry->depth_stencil == device->stencilBufferTarget)
         {
             list_remove(&entry->entry);
@@ -302,5 +391,5 @@
     if (context->fbo_entry_count < WINED3D_MAX_FBO_ENTRIES)
     {
-        entry = context_create_fbo_entry(iface);
+        entry = context_create_fbo_entry(context);
         list_add_head(&context->fbo_list, &entry->entry);
         ++context->fbo_entry_count;
@@ -309,5 +398,5 @@
     {
         entry = LIST_ENTRY(list_tail(&context->fbo_list), struct fbo_entry, entry);
-        context_reuse_fbo_entry(iface, entry);
+        context_reuse_fbo_entry(context, entry);
         list_remove(&entry->entry);
         list_add_head(&context->fbo_list, &entry->entry);
@@ -318,10 +407,11 @@
 
 /* GL locking is done by the caller */
-static void context_apply_fbo_entry(IWineD3DDevice *iface, struct fbo_entry *entry)
+static void context_apply_fbo_entry(struct WineD3DContext *context, struct fbo_entry *entry)
 {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     unsigned int i;
 
-    context_bind_fbo(iface, GL_FRAMEBUFFER_EXT, &entry->id);
+    context_bind_fbo(context, GL_FRAMEBUFFER_EXT, &entry->id);
 
     if (!entry->attached)
@@ -330,16 +420,17 @@
         for (i = 0; i < GL_LIMITS(buffers); ++i)
         {
-            IWineD3DSurface *render_target = This->render_targets[i];
-            context_attach_surface_fbo(This, GL_FRAMEBUFFER_EXT, i, render_target);
+            IWineD3DSurface *render_target = device->render_targets[i];
+            context_attach_surface_fbo(context, GL_FRAMEBUFFER_EXT, i, render_target);
         }
 
         /* Apply depth targets */
-        if (This->stencilBufferTarget) {
-            unsigned int w = ((IWineD3DSurfaceImpl *)This->render_targets[0])->pow2Width;
-            unsigned int h = ((IWineD3DSurfaceImpl *)This->render_targets[0])->pow2Height;
-
-            surface_set_compatible_renderbuffer(This->stencilBufferTarget, w, h);
-        }
-        context_attach_depth_stencil_fbo(This, GL_FRAMEBUFFER_EXT, This->stencilBufferTarget, TRUE);
+        if (device->stencilBufferTarget)
+        {
+            unsigned int w = ((IWineD3DSurfaceImpl *)device->render_targets[0])->pow2Width;
+            unsigned int h = ((IWineD3DSurfaceImpl *)device->render_targets[0])->pow2Height;
+
+            surface_set_compatible_renderbuffer(device->stencilBufferTarget, w, h);
+        }
+        context_attach_depth_stencil_fbo(context, GL_FRAMEBUFFER_EXT, device->stencilBufferTarget, TRUE);
 
         entry->attached = TRUE;
@@ -347,36 +438,35 @@
         for (i = 0; i < GL_LIMITS(buffers); ++i)
         {
-            if (This->render_targets[i])
-                context_apply_attachment_filter_states(iface, This->render_targets[i], FALSE);
-        }
-        if (This->stencilBufferTarget)
-            context_apply_attachment_filter_states(iface, This->stencilBufferTarget, FALSE);
+            if (device->render_targets[i])
+                context_apply_attachment_filter_states(device->render_targets[i], FALSE);
+        }
+        if (device->stencilBufferTarget)
+            context_apply_attachment_filter_states(device->stencilBufferTarget, FALSE);
     }
 
     for (i = 0; i < GL_LIMITS(buffers); ++i)
     {
-        if (This->render_targets[i])
-            This->draw_buffers[i] = GL_COLOR_ATTACHMENT0_EXT + i;
+        if (device->render_targets[i])
+            device->draw_buffers[i] = GL_COLOR_ATTACHMENT0_EXT + i;
         else
-            This->draw_buffers[i] = GL_NONE;
+            device->draw_buffers[i] = GL_NONE;
     }
 }
 
 /* GL locking is done by the caller */
-static void context_apply_fbo_state(IWineD3DDevice *iface)
+static void context_apply_fbo_state(struct WineD3DContext *context)
 {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    WineD3DContext *context = This->activeContext;
-
-    if (This->render_offscreen)
-    {
-        context->current_fbo = context_find_fbo_entry(iface, context);
-        context_apply_fbo_entry(iface, context->current_fbo);
+    IWineD3DDeviceImpl *device = ((IWineD3DSurfaceImpl *)context->surface)->resource.wineD3DDevice;
+
+    if (device->render_offscreen)
+    {
+        context->current_fbo = context_find_fbo_entry(context);
+        context_apply_fbo_entry(context, context->current_fbo);
     } else {
         context->current_fbo = NULL;
-        GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
-    }
-
-    context_check_fbo_status(iface);
+        context_bind_fbo(context, GL_FRAMEBUFFER_EXT, NULL);
+    }
+
+    context_check_fbo_status(context);
 }
 
@@ -390,7 +480,59 @@
         case WINED3DRTYPE_SURFACE:
         {
+            if ((IWineD3DSurface *)resource == This->lastActiveRenderTarget)
+            {
+                IWineD3DSwapChainImpl *swapchain;
+
+                TRACE("Last active render target destroyed.\n");
+
+                /* Find a replacement surface for the currently active back
+                 * buffer. The context manager does not do NULL checks, so
+                 * switch to a valid target as long as the currently set
+                 * surface is still valid. Use the surface of the implicit
+                 * swpchain. If that is the same as the destroyed surface the
+                 * device is destroyed and the lastActiveRenderTarget member
+                 * shouldn't matter. */
+                swapchain = This->swapchains ? (IWineD3DSwapChainImpl *)This->swapchains[0] : NULL;
+                if (swapchain)
+                {
+                    if (swapchain->backBuffer && swapchain->backBuffer[0] != (IWineD3DSurface *)resource)
+                    {
+                        TRACE("Activating primary back buffer.\n");
+                        ActivateContext(This, swapchain->backBuffer[0], CTXUSAGE_RESOURCELOAD);
+                    }
+                    else if (!swapchain->backBuffer && swapchain->frontBuffer != (IWineD3DSurface *)resource)
+                    {
+                        /* Single buffering environment */
+                        TRACE("Activating primary front buffer.\n");
+
+                        ActivateContext(This, swapchain->frontBuffer, CTXUSAGE_RESOURCELOAD);
+                    }
+                    else
+                    {
+                        /* Implicit render target destroyed, that means the
+                         * device is being destroyed whatever we set here, it
+                         * shouldn't matter. */
+                        TRACE("Device is being destroyed, setting lastActiveRenderTarget to 0xdeadbabe.\n");
+
+                        This->lastActiveRenderTarget = (IWineD3DSurface *) 0xdeadbabe;
+                    }
+                }
+                else
+                {
+                    WARN("Render target set, but swapchain does not exist!\n");
+
+                    /* May happen during ddraw uninitialization. */
+                    This->lastActiveRenderTarget = (IWineD3DSurface *)0xdeadcafe;
+                }
+            }
+            else if (This->d3d_initialized)
+            {
+                ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
+            }
+
             for (i = 0; i < This->numContexts; ++i)
             {
                 WineD3DContext *context = This->contexts[i];
+                const struct wined3d_gl_info *gl_info = context->gl_info;
                 struct fbo_entry *entry, *entry2;
 
@@ -406,5 +548,5 @@
                         if (entry->render_targets[j] == (IWineD3DSurface *)resource)
                         {
-                            context_destroy_fbo_entry(This, context, entry);
+                            context_destroy_fbo_entry(context, entry);
                             destroyed = TRUE;
                         }
@@ -412,5 +554,5 @@
 
                     if (!destroyed && entry->depth_stencil == (IWineD3DSurface *)resource)
-                        context_destroy_fbo_entry(This, context, entry);
+                        context_destroy_fbo_entry(context, entry);
                 }
 
@@ -699,9 +841,10 @@
  *****************************************************************************/
 WineD3DContext *CreateContext(IWineD3DDeviceImpl *This, IWineD3DSurfaceImpl *target, HWND win_handle, BOOL create_pbuffer, const WINED3DPRESENT_PARAMETERS *pPresentParms) {
-    HDC oldDrawable, hdc;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     HPBUFFERARB pbuffer = NULL;
-    HGLRC ctx = NULL, oldCtx;
     WineD3DContext *ret = NULL;
     unsigned int s;
+    HGLRC ctx;
+    HDC hdc;
 
     TRACE("(%p): Creating a %s context for render target %p\n", This, create_pbuffer ? "offscreen" : "onscreen", target);
@@ -852,5 +995,13 @@
 
     ctx = pwglCreateContext(hdc);
-    if(This->numContexts) pwglShareLists(This->contexts[0]->glCtx, ctx);
+    if (This->numContexts)
+    {
+        if (!pwglShareLists(This->contexts[0]->glCtx, ctx))
+        {
+            DWORD err = GetLastError();
+            ERR("wglShareLists(%p, %p) failed, last error %#x.\n",
+                    This->contexts[0]->glCtx, ctx, err);
+        }
+    }
 
     if(!ctx) {
@@ -865,5 +1016,9 @@
     if(!ret) {
         ERR("Failed to add the newly created context to the context list\n");
-        pwglDeleteContext(ctx);
+        if (!pwglDeleteContext(ctx))
+        {
+            DWORD err = GetLastError();
+            ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, err);
+        }
         if(create_pbuffer) {
             GL_EXTCALL(wglReleasePbufferDCARB(pbuffer, hdc));
@@ -872,4 +1027,5 @@
         goto out;
     }
+    ret->gl_info = &This->adapter->gl_info;
     ret->surface = (IWineD3DSurface *) target;
     ret->isPBuffer = create_pbuffer;
@@ -892,10 +1048,4 @@
 
     /* Set up the context defaults */
-    oldCtx  = pwglGetCurrentContext();
-    oldDrawable = pwglGetCurrentDC();
-    if(oldCtx && oldDrawable) {
-        /* See comment in ActivateContext context switching */
-        This->frag_pipe->enable_extension((IWineD3DDevice *) This, FALSE);
-    }
     if(pwglMakeCurrent(hdc, ctx) == FALSE) {
         ERR("Cannot activate context to set up defaults\n");
@@ -909,5 +1059,5 @@
     TRACE("Setting up the screen\n");
     /* Clear the screen */
-    glClearColor(1.0, 0.0, 0.0, 0.0);
+    glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
     checkGLcall("glClearColor");
     glClearIndex(0);
@@ -953,5 +1103,5 @@
             GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + s));
             glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, GL_TEXTURE0_ARB + s - 1);
-            checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, ...\n");
+            checkGLcall("glTexEnvi(GL_TEXTURE_SHADER_NV, GL_PREVIOUS_TEXTURE_INPUT_NV, ...");
         }
     }
@@ -978,16 +1128,9 @@
         GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + s));
         glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
-        checkGLcall("glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE)\n");
+        checkGLcall("glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE)");
     }
     LEAVE_GL();
 
-    /* Never keep GL_FRAGMENT_SHADER_ATI enabled on a context that we switch away from,
-     * but enable it for the first context we create, and reenable it on the old context
-     */
-    if(oldDrawable && oldCtx) {
-        pwglMakeCurrent(oldDrawable, oldCtx);
-    } else {
-        last_device = This;
-    }
+    context_set_last_device(This);
     This->frag_pipe->enable_extension((IWineD3DDevice *) This, TRUE);
 
@@ -1070,29 +1213,38 @@
  *****************************************************************************/
 void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context) {
+    const struct wined3d_gl_info *gl_info = context->gl_info;
     struct fbo_entry *entry, *entry2;
+    BOOL has_glctx;
 
     TRACE("Destroying ctx %p\n", context);
 
     /* The correct GL context needs to be active to cleanup the GL resources below */
-    if(pwglGetCurrentContext() != context->glCtx){
-        pwglMakeCurrent(context->hdc, context->glCtx);
-        last_device = NULL;
-    }
+    has_glctx = pwglMakeCurrent(context->hdc, context->glCtx);
+    context_set_last_device(NULL);
+
+    if (!has_glctx) WARN("Failed to activate context. Window already destroyed?\n");
 
     ENTER_GL();
 
     LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &context->fbo_list, struct fbo_entry, entry) {
-        context_destroy_fbo_entry(This, context, entry);
-    }
-    if (context->src_fbo) {
-        TRACE("Destroy src FBO %d\n", context->src_fbo);
-        context_destroy_fbo(This, &context->src_fbo);
-    }
-    if (context->dst_fbo) {
-        TRACE("Destroy dst FBO %d\n", context->dst_fbo);
-        context_destroy_fbo(This, &context->dst_fbo);
-    }
-    if(context->dummy_arbfp_prog) {
-        GL_EXTCALL(glDeleteProgramsARB(1, &context->dummy_arbfp_prog));
+        if (!has_glctx) entry->id = 0;
+        context_destroy_fbo_entry(context, entry);
+    }
+    if (has_glctx)
+    {
+        if (context->src_fbo)
+        {
+            TRACE("Destroy src FBO %d\n", context->src_fbo);
+            context_destroy_fbo(context, &context->src_fbo);
+        }
+        if (context->dst_fbo)
+        {
+            TRACE("Destroy dst FBO %d\n", context->dst_fbo);
+            context_destroy_fbo(context, &context->dst_fbo);
+        }
+        if (context->dummy_arbfp_prog)
+        {
+            GL_EXTCALL(glDeleteProgramsARB(1, &context->dummy_arbfp_prog));
+        }
     }
 
@@ -1106,5 +1258,9 @@
 
     /* Cleanup the GL context */
-    pwglMakeCurrent(NULL, NULL);
+    if (!pwglMakeCurrent(NULL, NULL))
+    {
+        ERR("Failed to disable GL context.\n");
+    }
+
     if(context->isPBuffer) {
         GL_EXTCALL(wglReleasePbufferDCARB(context->pbuffer, context->hdc));
@@ -1148,7 +1304,9 @@
  *
  *****************************************************************************/
+/* Context activation is done by the caller. */
 static inline void SetupForBlit(IWineD3DDeviceImpl *This, WineD3DContext *context, UINT width, UINT height) {
     int i, sampler;
     const struct StateEntry *StateTable = This->StateTable;
+    const struct wined3d_gl_info *gl_info = context->gl_info;
 
     TRACE("Setting up context %p for blitting\n", context);
@@ -1248,5 +1406,5 @@
         glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT,
                   GL_TEXTURE_LOD_BIAS_EXT,
-                  0.0);
+                  0.0f);
         checkGLcall("glTexEnvi GL_TEXTURE_LOD_BIAS_EXT ...");
     }
@@ -1528,5 +1686,6 @@
          * Read the back buffer of the old drawable into the destination texture
          */
-        if(((IWineD3DSurfaceImpl *)This->lastActiveRenderTarget)->glDescription.srgbTextureName) {
+        if (((IWineD3DSurfaceImpl *)This->lastActiveRenderTarget)->texture_name_srgb)
+        {
             surface_internal_preload(This->lastActiveRenderTarget, SRGB_BOTH);
         } else {
@@ -1543,6 +1702,8 @@
 }
 
+/* Context activation is done by the caller. */
 static void apply_draw_buffer(IWineD3DDeviceImpl *This, IWineD3DSurface *target, BOOL blit)
 {
+    const struct wined3d_gl_info *gl_info = This->activeContext->gl_info;
     IWineD3DSwapChain *swapchain;
 
@@ -1605,4 +1766,5 @@
     WineD3DContext                *context;
     const struct StateEntry       *StateTable = This->StateTable;
+    const struct wined3d_gl_info *gl_info;
 
     TRACE("(%p): Selecting context for render target %p, thread %d\n", This, target, tid);
@@ -1617,4 +1779,6 @@
     }
 
+    gl_info = context->gl_info;
+
     /* Activate the opengl context */
     if(last_device != This || context != This->activeContext) {
@@ -1646,5 +1810,5 @@
         }
         This->activeContext = context;
-        last_device = This;
+        context_set_last_device(This);
     }
 
@@ -1654,5 +1818,5 @@
             if (wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
                 ENTER_GL();
-                context_apply_fbo_state((IWineD3DDevice *)This);
+                context_apply_fbo_state(context);
                 LEAVE_GL();
             }
@@ -1668,13 +1832,11 @@
                     FIXME("Activating for CTXUSAGE_BLIT for an offscreen target with ORM_FBO. This should be avoided.\n");
                     ENTER_GL();
-                    context_bind_fbo((IWineD3DDevice *)This, GL_FRAMEBUFFER_EXT, &context->dst_fbo);
-                    context_attach_surface_fbo(This, GL_FRAMEBUFFER_EXT, 0, target);
-                    GL_EXTCALL(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0));
-                    checkGLcall("glFramebufferRenderbufferEXT");
+                    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);
                     LEAVE_GL();
                 } else {
                     ENTER_GL();
-                    GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
-                    checkGLcall("glFramebufferRenderbufferEXT");
+                    context_bind_fbo(context, GL_FRAMEBUFFER_EXT, 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 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c	(revision 21731)
@@ -150,5 +150,5 @@
         IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
 {
-    const WineD3D_GL_Info *gl_info = &device->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, gl_info);
     UINT pow2_edge_length;
@@ -220,8 +220,8 @@
     {
         /* Precalculated scaling for 'faked' non power of two texture coords. */
-        texture->baseTexture.pow2Matrix[0] = 1.0;
-        texture->baseTexture.pow2Matrix[5] = 1.0;
-        texture->baseTexture.pow2Matrix[10] = 1.0;
-        texture->baseTexture.pow2Matrix[15] = 1.0;
+        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
@@ -231,5 +231,5 @@
         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.0;
+        texture->baseTexture.pow2Matrix[15] = 1.0f;
         texture->baseTexture.pow2Matrix_identity = FALSE;
     }
@@ -411,4 +411,5 @@
 }
 
+/* Context activation is done by the caller. */
 static HRESULT WINAPI IWineD3DCubeTextureImpl_BindTexture(IWineD3DCubeTexture *iface, BOOL srgb) {
     IWineD3DCubeTextureImpl *This = (IWineD3DCubeTextureImpl *)iface;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c	(revision 21731)
@@ -48,15 +48,15 @@
 const WINED3DLIGHT WINED3D_default_light = {
 
-    WINED3DLIGHT_DIRECTIONAL, /* Type */
-    { 1.0, 1.0, 1.0, 0.0 },   /* Diffuse r,g,b,a */
-    { 0.0, 0.0, 0.0, 0.0 },   /* Specular r,g,b,a */
-    { 0.0, 0.0, 0.0, 0.0 },   /* Ambient r,g,b,a, */
-    { 0.0, 0.0, 0.0 },        /* Position x,y,z */
-    { 0.0, 0.0, 1.0 },        /* Direction x,y,z */
-    0.0,                      /* Range */
-    0.0,                      /* Falloff */
-    0.0, 0.0, 0.0,            /* Attenuation 0,1,2 */
-    0.0,                      /* Theta */
-    0.0                       /* Phi */
+    WINED3DLIGHT_DIRECTIONAL,   /* Type */
+    { 1.0f, 1.0f, 1.0f, 0.0f }, /* Diffuse r,g,b,a */
+    { 0.0f, 0.0f, 0.0f, 0.0f }, /* Specular r,g,b,a */
+    { 0.0f, 0.0f, 0.0f, 0.0f }, /* Ambient r,g,b,a, */
+    { 0.0f, 0.0f, 0.0f },       /* Position x,y,z */
+    { 0.0f, 0.0f, 1.0f },       /* Direction x,y,z */
+    0.0f,                       /* Range */
+    0.0f,                       /* Falloff */
+    0.0f, 0.0f, 0.0f,           /* Attenuation 0,1,2 */
+    0.0f,                       /* Theta */
+    0.0f                        /* Phi */
 };
 
@@ -64,5 +64,11 @@
  * Global variable / Constants follow
  **********************************************************/
-const float identity[16] = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};  /* When needed for comparisons */
+const float identity[] =
+{
+    1.0f, 0.0f, 0.0f, 0.0f,
+    0.0f, 1.0f, 0.0f, 0.0f,
+    0.0f, 0.0f, 1.0f, 0.0f,
+    0.0f, 0.0f, 0.0f, 1.0f,
+};  /* When needed for comparisons */
 
 /* Note that except for WINED3DPT_POINTLIST and WINED3DPT_LINELIST these
@@ -176,4 +182,5 @@
 }
 
+/* Context activation is done by the caller. */
 void device_stream_info_from_declaration(IWineD3DDeviceImpl *This,
         BOOL use_vshader, struct wined3d_stream_info *stream_info, BOOL *fixup)
@@ -899,89 +906,34 @@
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface,
-        UINT Width, UINT Height, WINED3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level,
-        IWineD3DSurface **ppSurface, WINED3DRESOURCETYPE Type, DWORD Usage, WINED3DPOOL Pool,
-        WINED3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality, WINED3DSURFTYPE Impl, IUnknown *parent)
+static HRESULT WINAPI IWineD3DDeviceImpl_CreateSurface(IWineD3DDevice *iface, UINT Width, UINT Height,
+        WINED3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IWineD3DSurface **ppSurface,
+        DWORD Usage, WINED3DPOOL Pool, WINED3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,
+        WINED3DSURFTYPE Impl, IUnknown *parent)
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    IWineD3DSurfaceImpl *object; /*NOTE: impl ref allowed since this is a create function */
-    unsigned int Size       = 1;
-    const struct GlPixelFormatDesc *glDesc = getFormatDescEntry(Format, &GLINFO_LOCATION);
-    UINT mul_4w, mul_4h;
+    IWineD3DSurfaceImpl *object;
     HRESULT hr;
 
     TRACE("(%p) Create surface\n",This);
 
-    if(MultisampleQuality > 0) {
-        FIXME("MultisampleQuality set to %d, substituting 0\n", MultisampleQuality);
-        MultisampleQuality=0;
-    }
-
-    /** FIXME: Check that the format is supported
-    *    by the device.
-      *******************************/
-
-    /** DXTn mipmaps use the same number of 'levels' down to eg. 8x1, but since
-     *  it is based around 4x4 pixel blocks it requires padding, so allocate enough
-     *  space!
-      *********************************/
-    mul_4w = (Width + 3) & ~3;
-    mul_4h = (Height + 3) & ~3;
-    if (WINED3DFMT_UNKNOWN == Format) {
-        Size = 0;
-    } else if (Format == WINED3DFMT_DXT1) {
-        /* DXT1 is half byte per pixel */
-        Size = (mul_4w * glDesc->byte_count * mul_4h) >> 1;
-
-    } else if (Format == WINED3DFMT_DXT2 || Format == WINED3DFMT_DXT3 ||
-               Format == WINED3DFMT_DXT4 || Format == WINED3DFMT_DXT5 ||
-               Format == WINED3DFMT_ATI2N) {
-        Size = (mul_4w * glDesc->byte_count * mul_4h);
-    } else {
-       /* The pitch is a multiple of 4 bytes */
-        Size = ((Width * glDesc->byte_count) + This->surface_alignment - 1) & ~(This->surface_alignment - 1);
-        Size *= Height;
-    }
-
-    if(glDesc->heightscale != 0.0) Size *= glDesc->heightscale;
-
-    /** Create and initialise the surface resource **/
+    if (Impl == SURFACE_OPENGL && !This->adapter)
+    {
+        ERR("OpenGL surfaces are not available without OpenGL.\n");
+        return WINED3DERR_NOTAVAILABLE;
+    }
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (!object)
     {
-        ERR("Out of memory\n");
+        ERR("Failed to allocate surface memory.\n");
         *ppSurface = NULL;
         return WINED3DERR_OUTOFVIDEOMEMORY;
     }
 
-    /* Look at the implementation and set the correct Vtable */
-    switch(Impl)
-    {
-        case SURFACE_OPENGL:
-            /* Check if a 3D adapter is available when creating gl surfaces */
-            if (!This->adapter)
-            {
-                ERR("OpenGL surfaces are not available without opengl\n");
-                HeapFree(GetProcessHeap(), 0, object);
-                return WINED3DERR_NOTAVAILABLE;
-            }
-            object->lpVtbl = &IWineD3DSurface_Vtbl;
-            break;
-
-        case SURFACE_GDI:
-            object->lpVtbl = &IWineGDISurface_Vtbl;
-            break;
-
-        default:
-            /* To be sure to catch this */
-            ERR("Unknown requested surface implementation %d!\n", Impl);
-            HeapFree(GetProcessHeap(), 0, object);
-            return WINED3DERR_INVALIDCALL;
-    }
-
-    hr = resource_init((IWineD3DResource *)object, WINED3DRTYPE_SURFACE, This, Size, Usage, glDesc, Pool, parent);
+    hr = surface_init(object, Impl, This->surface_alignment, Width, Height, Level, Lockable,
+            Discard, MultiSample, MultisampleQuality, This, Usage, Format, Pool, parent);
     if (FAILED(hr))
     {
-        WARN("Failed to initialize resource, returning %#x\n", hr);
+        WARN("Failed to initialize surface, returning %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
         *ppSurface = NULL;
@@ -989,76 +941,7 @@
     }
 
-    TRACE("(%p) : Created resource %p\n", This, object);
+    TRACE("(%p) : Created surface %p\n", This, object);
 
     *ppSurface = (IWineD3DSurface *)object;
-
-    /* "Standalone" surface */
-    IWineD3DSurface_SetContainer((IWineD3DSurface *)object, NULL);
-
-    object->currentDesc.Width      = Width;
-    object->currentDesc.Height     = Height;
-    object->currentDesc.MultiSampleType    = MultiSample;
-    object->currentDesc.MultiSampleQuality = MultisampleQuality;
-    object->glDescription.level            = Level;
-    list_init(&object->overlays);
-
-    /* Flags */
-    object->Flags      = SFLAG_NORMCOORD; /* Default to normalized coords */
-    object->Flags     |= Discard ? SFLAG_DISCARD : 0;
-    object->Flags     |= (WINED3DFMT_D16_LOCKABLE == Format) ? SFLAG_LOCKABLE : 0;
-    object->Flags     |= Lockable ? SFLAG_LOCKABLE : 0;
-
-    TRACE("Pool %d %d %d %d\n",Pool, WINED3DPOOL_DEFAULT, WINED3DPOOL_MANAGED, WINED3DPOOL_SYSTEMMEM);
-
-    /** Quick lockable sanity check TODO: remove this after surfaces, usage and lockability have been debugged properly
-    * this function is too deep to need to care about things like this.
-    * Levels need to be checked too, and possibly Type since they all affect what can be done.
-    * ****************************************/
-    switch(Pool) {
-    case WINED3DPOOL_SCRATCH:
-        if(!Lockable)
-            FIXME("Create surface called with a pool of SCRATCH and a Lockable of FALSE "
-                "which are mutually exclusive, setting lockable to TRUE\n");
-                Lockable = TRUE;
-    break;
-    case WINED3DPOOL_SYSTEMMEM:
-        if(!Lockable) FIXME("Create surface called with a pool of SYSTEMMEM and a Lockable of FALSE, "
-                                    "this is acceptable but unexpected (I can't know how the surface can be usable!)\n");
-    case WINED3DPOOL_MANAGED:
-        if(Usage == WINED3DUSAGE_DYNAMIC) FIXME("Create surface called with a pool of MANAGED and a "
-                                                "Usage of DYNAMIC which are mutually exclusive, not doing "
-                                                "anything just telling you.\n");
-    break;
-    case WINED3DPOOL_DEFAULT: /*TODO: Create offscreen plain can cause this check to fail..., find out if it should */
-        if(!(Usage & WINED3DUSAGE_DYNAMIC) && !(Usage & WINED3DUSAGE_RENDERTARGET)
-           && !(Usage && WINED3DUSAGE_DEPTHSTENCIL ) && Lockable)
-            WARN("Creating a surface with a POOL of DEFAULT with Lockable true, that doesn't specify DYNAMIC usage.\n");
-    break;
-    default:
-        FIXME("(%p) Unknown pool %d\n", This, Pool);
-    break;
-    };
-
-    if (Usage & WINED3DUSAGE_RENDERTARGET && Pool != WINED3DPOOL_DEFAULT) {
-        FIXME("Trying to create a render target that isn't in the default pool\n");
-    }
-
-    /* mark the texture as dirty so that it gets loaded first time around*/
-    surface_add_dirty_rect(*ppSurface, NULL);
-    TRACE("(%p) : w(%d) h(%d) fmt(%d,%s) lockable(%d) surf@%p, surfmem@%p, %d bytes\n",
-           This, Width, Height, Format, debug_d3dformat(Format),
-           (WINED3DFMT_D16_LOCKABLE == Format), *ppSurface, object->resource.allocatedMemory, object->resource.size);
-
-    list_init(&object->renderbuffers);
-
-    /* Call the private setup routine */
-    hr = IWineD3DSurface_PrivateSetup((IWineD3DSurface *)object);
-    if (FAILED(hr))
-    {
-        ERR("Private setup failed, returning %#x\n", hr);
-        IWineD3DSurface_Release(*ppSurface);
-        *ppSurface = NULL;
-        return hr;
-    }
 
     return hr;
@@ -2126,7 +2009,6 @@
     }
 
-    hr = IWineD3DDevice_CreateSurface((IWineD3DDevice *) This, bm.bmWidth, bm.bmHeight, WINED3DFMT_R5G6B5,
-                                      TRUE, FALSE, 0, &This->logo_surface, WINED3DRTYPE_SURFACE, 0,
-                                      WINED3DPOOL_DEFAULT, WINED3DMULTISAMPLE_NONE, 0, SURFACE_OPENGL, NULL);
+    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);
     if(FAILED(hr)) {
         ERR("Wine logo requested, but failed to create surface\n");
@@ -2158,4 +2040,5 @@
 }
 
+/* Context activation is done by the caller. */
 static void create_dummy_textures(IWineD3DDeviceImpl *This) {
     unsigned int i;
@@ -2264,5 +2147,5 @@
     }
 
-    /* Setup the implicit swapchain */
+    /* Setup the implicit swapchain. This also initializes a context. */
     TRACE("Creating implicit swapchain\n");
     hr = IWineD3DDeviceParent_CreateSwapChain(This->device_parent,
@@ -2356,5 +2239,5 @@
     IWineD3DDevice_Clear((IWineD3DDevice *) This, 0, NULL,
                           WINED3DCLEAR_TARGET | pPresentationParameters->EnableAutoDepthStencil ? WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL : 0,
-                          0x00, 1.0, 0);
+                          0x00, 1.0f, 0);
 
     This->d3d_initialized = TRUE;
@@ -2931,5 +2814,6 @@
              * most wanted
              */
-            if(pLight->Attenuation0 < 0.0 || pLight->Attenuation1 < 0.0 || pLight->Attenuation2 < 0.0) {
+            if (pLight->Attenuation0 < 0.0f || pLight->Attenuation1 < 0.0f || pLight->Attenuation2 < 0.0f)
+            {
                 WARN("Attenuation is negative, returning WINED3DERR_INVALIDCALL\n");
                 return WINED3DERR_INVALIDCALL;
@@ -2993,5 +2877,5 @@
         object->lightPosn[1] = -pLight->Direction.y;
         object->lightPosn[2] = -pLight->Direction.z;
-        object->lightPosn[3] = 0.0;
+        object->lightPosn[3] = 0.0f;
         object->exponent     = 0.0f;
         object->cutoff       = 180.0f;
@@ -3003,5 +2887,5 @@
         object->lightPosn[1] = pLight->Position.y;
         object->lightPosn[2] = pLight->Position.z;
-        object->lightPosn[3] = 1.0;
+        object->lightPosn[3] = 1.0f;
 
         /* Direction */
@@ -3009,5 +2893,5 @@
         object->lightDirn[1] = pLight->Direction.y;
         object->lightDirn[2] = pLight->Direction.z;
-        object->lightDirn[3] = 1.0;
+        object->lightDirn[3] = 1.0f;
 
         /*
@@ -3024,12 +2908,13 @@
              * rest of the rather complex calculation
              */
-            object->exponent = 0;
+            object->exponent = 0.0f;
         } else {
             rho = pLight->Theta + (pLight->Phi - pLight->Theta)/(2*pLight->Falloff);
-            if (rho < 0.0001) rho = 0.0001f;
-            object->exponent = -0.3/log(cos(rho/2));
-        }
-        if (object->exponent > 128.0) {
-            object->exponent = 128.0;
+            if (rho < 0.0001f) rho = 0.0001f;
+            object->exponent = -0.3f/log(cos(rho/2));
+        }
+        if (object->exponent > 128.0f)
+        {
+            object->exponent = 128.0f;
         }
         object->cutoff = pLight->Phi*90/M_PI;
@@ -3081,7 +2966,4 @@
     struct list *e;
     TRACE("(%p) : Idx(%d), enable? %d\n", This, Index, Enable);
-
-    /* Tests show true = 128...not clear why */
-    Enable = Enable? 128: 0;
 
     LIST_FOR_EACH(e, &This->updateStateBlock->lightMap[Hi]) {
@@ -4172,4 +4054,5 @@
 }
 
+/* Context activation is done by the caller. */
 #define copy_and_next(dest, src, size) memcpy(dest, src, size); dest += (size)
 static HRESULT process_vertices_strided(IWineD3DDeviceImpl *This, DWORD dwDestIndex, DWORD dwCount,
@@ -4299,8 +4182,8 @@
 
             /* Multiplication with world, view and projection matrix */
-            x =   (p[0] * mat.u.s._11) + (p[1] * mat.u.s._21) + (p[2] * mat.u.s._31) + (1.0 * mat.u.s._41);
-            y =   (p[0] * mat.u.s._12) + (p[1] * mat.u.s._22) + (p[2] * mat.u.s._32) + (1.0 * mat.u.s._42);
-            z =   (p[0] * mat.u.s._13) + (p[1] * mat.u.s._23) + (p[2] * mat.u.s._33) + (1.0 * mat.u.s._43);
-            rhw = (p[0] * mat.u.s._14) + (p[1] * mat.u.s._24) + (p[2] * mat.u.s._34) + (1.0 * mat.u.s._44);
+            x =   (p[0] * mat.u.s._11) + (p[1] * mat.u.s._21) + (p[2] * mat.u.s._31) + (1.0f * mat.u.s._41);
+            y =   (p[0] * mat.u.s._12) + (p[1] * mat.u.s._22) + (p[2] * mat.u.s._32) + (1.0f * mat.u.s._42);
+            z =   (p[0] * mat.u.s._13) + (p[1] * mat.u.s._23) + (p[2] * mat.u.s._33) + (1.0f * mat.u.s._43);
+            rhw = (p[0] * mat.u.s._14) + (p[1] * mat.u.s._24) + (p[2] * mat.u.s._34) + (1.0f * mat.u.s._44);
 
             TRACE("x=%f y=%f z=%f rhw=%f\n", x, y, z, rhw);
@@ -5865,4 +5748,5 @@
       ****************************************/
     IWineD3DSurfaceImpl *pSrcSurface  = (IWineD3DSurfaceImpl *)pSourceSurface;
+    IWineD3DSurfaceImpl *dst_impl = (IWineD3DSurfaceImpl *)pDestinationSurface;
     int srcWidth, srcHeight;
     unsigned int  srcSurfaceWidth, srcSurfaceHeight, destSurfaceWidth, destSurfaceHeight;
@@ -5873,5 +5757,4 @@
     int offset    = 0;
     int rowoffset = 0; /* how many bytes to add onto the end of a row to wraparound to the beginning of the next */
-    glDescriptor *glDescription = NULL;
     const struct GlPixelFormatDesc *src_format_desc, *dst_format_desc;
     GLenum dummy;
@@ -5883,19 +5766,17 @@
 
     TRACE("(%p) : Source (%p)  Rect (%p) Destination (%p) Point(%p)\n", This, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
-    memset(&winedesc, 0, sizeof(winedesc));
-    winedesc.Width  = &srcSurfaceWidth;
-    winedesc.Height = &srcSurfaceHeight;
-    winedesc.Pool   = &srcPool;
-    winedesc.Format = &srcFormat;
 
     IWineD3DSurface_GetDesc(pSourceSurface, &winedesc);
-
-    winedesc.Width  = &destSurfaceWidth;
-    winedesc.Height = &destSurfaceHeight;
-    winedesc.Pool   = &destPool;
-    winedesc.Format = &destFormat;
-    winedesc.Size   = &destSize;
+    srcSurfaceWidth = winedesc.width;
+    srcSurfaceHeight = winedesc.height;
+    srcPool = winedesc.pool;
+    srcFormat = winedesc.format;
 
     IWineD3DSurface_GetDesc(pDestinationSurface, &winedesc);
+    destSurfaceWidth = winedesc.width;
+    destSurfaceHeight = winedesc.height;
+    destPool = winedesc.pool;
+    destFormat = winedesc.format;
+    destSize = winedesc.size;
 
     if(srcPool != WINED3DPOOL_SYSTEMMEM  || destPool != WINED3DPOOL_DEFAULT){
@@ -5908,6 +5789,5 @@
      * copy in sysmem and use regular surface loading.
      */
-    d3dfmt_get_conv((IWineD3DSurfaceImpl *) pDestinationSurface, FALSE, TRUE,
-                    &dummy, &dummy, &dummy, &convert, &bpp, FALSE);
+    d3dfmt_get_conv(dst_impl, FALSE, TRUE, &dummy, &dummy, &dummy, &convert, &bpp, FALSE);
     if(convert != NO_CONVERSION) {
         return IWineD3DSurface_BltFast(pDestinationSurface,
@@ -5936,8 +5816,6 @@
     IWineD3DSurface_BindTexture(pDestinationSurface, FALSE);
 
-    IWineD3DSurface_GetGlDesc(pDestinationSurface, &glDescription);
-
     src_format_desc = ((IWineD3DSurfaceImpl *)pSrcSurface)->resource.format_desc;
-    dst_format_desc = ((IWineD3DSurfaceImpl *)pDestinationSurface)->resource.format_desc;
+    dst_format_desc = dst_impl->resource.format_desc;
 
     /* this needs to be done in lines if the sourceRect != the sourceWidth */
@@ -5962,5 +5840,5 @@
     }
     TRACE("(%p) glTexSubImage2D, level %d, left %d, top %d, width %d, height %d, fmt %#x, type %#x, memory %p+%#x\n",
-            This, glDescription->level, destLeft, destTop, srcWidth, srcHeight, dst_format_desc->glFormat,
+            This, dst_impl->texture_level, destLeft, destTop, srcWidth, srcHeight, dst_format_desc->glFormat,
             dst_format_desc->glType, IWineD3DSurface_GetData(pSourceSurface), offset);
 
@@ -5984,5 +5862,5 @@
         for (j = destTop; j < (srcHeight + destTop); ++j)
         {
-            glTexSubImage2D(glDescription->target, glDescription->level, destLeft, j,
+            glTexSubImage2D(dst_impl->texture_target, dst_impl->texture_level, destLeft, j,
                     srcWidth, 1, dst_format_desc->glFormat, dst_format_desc->glType,data);
             data += rowoffset;
@@ -5992,26 +5870,24 @@
         const unsigned char* data = ((const unsigned char *)IWineD3DSurface_GetData(pSourceSurface)) + offset;
 
-        if (WINED3DFMT_DXT1 == destFormat ||
-            WINED3DFMT_DXT2 == destFormat ||
-            WINED3DFMT_DXT3 == destFormat ||
-            WINED3DFMT_DXT4 == destFormat ||
-            WINED3DFMT_DXT5 == destFormat) {
-            if (GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
-                if (destSurfaceHeight != srcHeight || destSurfaceWidth != srcWidth) {
-                    /* FIXME: The easy way to do this is to lock the destination, and copy the bits across */
-                    FIXME("Updating part of a compressed texture is not supported at the moment\n");
-                } if (destFormat != srcFormat) {
-                    FIXME("Updating mixed format compressed texture is not curretly support\n");
-                } else {
-                    GL_EXTCALL(glCompressedTexImage2DARB(glDescription->target, glDescription->level,
-                            dst_format_desc->glInternal, srcWidth, srcHeight, 0, destSize, data));
-                }
-            } else {
-                FIXME("Attempting to update a DXT compressed texture without hardware support\n");
+        if (dst_format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED)
+        {
+            if (destSurfaceHeight != srcHeight || destSurfaceWidth != srcWidth)
+            {
+                /* FIXME: The easy way to do this is to lock the destination, and copy the bits across. */
+                FIXME("Updating part of a compressed texture is not supported.\n");
             }
-
-
-        } else {
-            glTexSubImage2D(glDescription->target, glDescription->level, destLeft, destTop,
+            if (destFormat != srcFormat)
+            {
+                FIXME("Updating mixed format compressed textures is not supported.\n");
+            }
+            else
+            {
+                GL_EXTCALL(glCompressedTexImage2DARB(dst_impl->texture_target, dst_impl->texture_level,
+                        dst_format_desc->glInternal, srcWidth, srcHeight, 0, destSize, data));
+            }
+        }
+        else
+        {
+            glTexSubImage2D(dst_impl->texture_target, dst_impl->texture_level, destLeft, destTop,
                     srcWidth, srcHeight, dst_format_desc->glFormat, dst_format_desc->glType, data);
         }
@@ -6175,5 +6051,5 @@
         ActivateContext(This, surface, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
-        GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
+        context_bind_fbo(This->activeContext, GL_FRAMEBUFFER_EXT, NULL);
         buffer = surface_get_gl_buffer(surface, swapchain);
         glDrawBuffer(buffer);
@@ -6184,8 +6060,7 @@
         ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
-        context_bind_fbo(iface, GL_FRAMEBUFFER_EXT, &This->activeContext->dst_fbo);
-        context_attach_surface_fbo(This, GL_FRAMEBUFFER_EXT, 0, surface);
-        GL_EXTCALL(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0));
-        checkGLcall("glFramebufferRenderbufferEXT");
+        context_bind_fbo(This->activeContext, GL_FRAMEBUFFER_EXT, &This->activeContext->dst_fbo);
+        context_attach_surface_fbo(This->activeContext, GL_FRAMEBUFFER_EXT, 0, surface);
+        context_attach_depth_stencil_fbo(This->activeContext, GL_FRAMEBUFFER_EXT, NULL, FALSE);
     }
 
@@ -6216,8 +6091,7 @@
 
     if (This->activeContext->current_fbo) {
-        context_bind_fbo(iface, GL_FRAMEBUFFER_EXT, &This->activeContext->current_fbo->id);
+        context_bind_fbo(This->activeContext, GL_FRAMEBUFFER_EXT, &This->activeContext->current_fbo->id);
     } else {
-        GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
-        checkGLcall("glBindFramebuffer()");
+        context_bind_fbo(This->activeContext, GL_FRAMEBUFFER_EXT, NULL);
     }
 
@@ -6397,8 +6271,8 @@
         WARN("Converting to WINED3DCOLOR, this might give incorrect results\n");
 
-        c = ((DWORD)(color[2] * 255.0));
-        c |= ((DWORD)(color[1] * 255.0)) << 8;
-        c |= ((DWORD)(color[0] * 255.0)) << 16;
-        c |= ((DWORD)(color[3] * 255.0)) << 24;
+        c = ((DWORD)(color[2] * 255.0f));
+        c |= ((DWORD)(color[1] * 255.0f)) << 8;
+        c |= ((DWORD)(color[0] * 255.0f)) << 16;
+        c |= ((DWORD)(color[3] * 255.0f)) << 24;
 
         /* Just forward this to the DirectDraw blitting engine */
@@ -6491,4 +6365,6 @@
          * This function is called by IDirect3D7::CreateDevice so in theory its initialization code
          */
+        WARN("No active context?\n");
+
         ENTER_GL();
         if(!Swapchain->backBuffer[0]) {
@@ -6572,9 +6448,14 @@
     /* Attach src surface to src fbo */
     src_swapchain = get_swapchain(src_surface);
+    dst_swapchain = get_swapchain(dst_surface);
+
+    if (src_swapchain) ActivateContext(This, src_surface, CTXUSAGE_RESOURCELOAD);
+    else if (dst_swapchain) ActivateContext(This, dst_surface, CTXUSAGE_RESOURCELOAD);
+    else ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
+
     if (src_swapchain) {
         GLenum buffer = surface_get_gl_buffer(src_surface, src_swapchain);
 
         TRACE("Source surface %p is onscreen\n", src_surface);
-        ActivateContext(This, src_surface, CTXUSAGE_RESOURCELOAD);
         /* Make sure the drawable is up to date. In the offscreen case
          * attach_surface_fbo() implicitly takes care of this. */
@@ -6596,5 +6477,5 @@
 
         ENTER_GL();
-        GL_EXTCALL(glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0));
+        context_bind_fbo(This->activeContext, GL_READ_FRAMEBUFFER_EXT, NULL);
         glReadBuffer(buffer);
         checkGLcall("glReadBuffer()");
@@ -6602,20 +6483,17 @@
         TRACE("Source surface %p is offscreen\n", src_surface);
         ENTER_GL();
-        context_bind_fbo(iface, GL_READ_FRAMEBUFFER_EXT, &This->activeContext->src_fbo);
-        context_attach_surface_fbo(This, GL_READ_FRAMEBUFFER_EXT, 0, src_surface);
+        context_bind_fbo(This->activeContext, GL_READ_FRAMEBUFFER_EXT, &This->activeContext->src_fbo);
+        context_attach_surface_fbo(This->activeContext, GL_READ_FRAMEBUFFER_EXT, 0, src_surface);
         glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
         checkGLcall("glReadBuffer()");
-        GL_EXTCALL(glFramebufferRenderbufferEXT(GL_READ_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0));
-        checkGLcall("glFramebufferRenderbufferEXT");
+        context_attach_depth_stencil_fbo(This->activeContext, GL_READ_FRAMEBUFFER_EXT, NULL, FALSE);
     }
     LEAVE_GL();
 
     /* Attach dst surface to dst fbo */
-    dst_swapchain = get_swapchain(dst_surface);
     if (dst_swapchain) {
         GLenum buffer = surface_get_gl_buffer(dst_surface, dst_swapchain);
 
         TRACE("Destination surface %p is onscreen\n", dst_surface);
-        ActivateContext(This, dst_surface, CTXUSAGE_RESOURCELOAD);
         /* Make sure the drawable is up to date. In the offscreen case
          * attach_surface_fbo() implicitly takes care of this. */
@@ -6638,5 +6516,5 @@
 
         ENTER_GL();
-        GL_EXTCALL(glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0));
+        context_bind_fbo(This->activeContext, GL_DRAW_FRAMEBUFFER_EXT, NULL);
         glDrawBuffer(buffer);
         checkGLcall("glDrawBuffer()");
@@ -6644,16 +6522,10 @@
         TRACE("Destination surface %p is offscreen\n", dst_surface);
 
-        /* No src or dst swapchain? Make sure some context is active(multithreading) */
-        if(!src_swapchain) {
-            ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
-        }
-
         ENTER_GL();
-        context_bind_fbo(iface, GL_DRAW_FRAMEBUFFER_EXT, &This->activeContext->dst_fbo);
-        context_attach_surface_fbo(This, GL_DRAW_FRAMEBUFFER_EXT, 0, dst_surface);
+        context_bind_fbo(This->activeContext, GL_DRAW_FRAMEBUFFER_EXT, &This->activeContext->dst_fbo);
+        context_attach_surface_fbo(This->activeContext, GL_DRAW_FRAMEBUFFER_EXT, 0, dst_surface);
         glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
         checkGLcall("glDrawBuffer()");
-        GL_EXTCALL(glFramebufferRenderbufferEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0));
-        checkGLcall("glFramebufferRenderbufferEXT");
+        context_attach_depth_stencil_fbo(This->activeContext, GL_DRAW_FRAMEBUFFER_EXT, NULL, FALSE);
     }
     glDisable(GL_SCISSOR_TEST);
@@ -6673,8 +6545,7 @@
 
     if (This->activeContext->current_fbo) {
-        context_bind_fbo(iface, GL_FRAMEBUFFER_EXT, &This->activeContext->current_fbo->id);
+        context_bind_fbo(This->activeContext, GL_FRAMEBUFFER_EXT, &This->activeContext->current_fbo->id);
     } else {
-        GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
-        checkGLcall("glBindFramebuffer()");
+        context_bind_fbo(This->activeContext, GL_FRAMEBUFFER_EXT, NULL);
     }
 
@@ -6855,4 +6726,7 @@
                     memcpy(&mem[width * bpp * i], &bits[rect.Pitch * i], width * bpp);
                 IWineD3DSurface_UnlockRect(pCursorBitmap);
+
+                ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
+
                 ENTER_GL();
 
@@ -7003,12 +6877,19 @@
 }
 
+static HRESULT WINAPI evict_managed_resource(IWineD3DResource *resource, void *data) {
+    TRACE("checking resource %p for eviction\n", resource);
+    if(((IWineD3DResourceImpl *) resource)->resource.pool == WINED3DPOOL_MANAGED) {
+        TRACE("Evicting %p\n", resource);
+        IWineD3DResource_UnLoad(resource);
+    }
+    IWineD3DResource_Release(resource);
+    return S_OK;
+}
 
 static HRESULT  WINAPI  IWineD3DDeviceImpl_EvictManagedResources(IWineD3DDevice* iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
-    /** FIXME: Resource tracking needs to be done,
-    * The closes we can do to this is set the priorities of all managed textures low
-    * and then reset them.
-     ***********************************************************/
-    FIXME("(%p) : stub\n", This);
+    TRACE("(%p)\n", This);
+
+    IWineD3DDevice_EnumResources(iface, evict_managed_resource, NULL);
     return WINED3D_OK;
 }
@@ -7045,10 +6926,11 @@
     surface->glRect.bottom = surface->pow2Height;
 
-    if(surface->glDescription.textureName) {
+    if (surface->texture_name)
+    {
         ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
         ENTER_GL();
-        glDeleteTextures(1, &surface->glDescription.textureName);
+        glDeleteTextures(1, &surface->texture_name);
         LEAVE_GL();
-        surface->glDescription.textureName = 0;
+        surface->texture_name = 0;
         surface->Flags &= ~SFLAG_CLIENT;
     }
@@ -7110,4 +6992,6 @@
     UINT i;
     IWineD3DBaseShaderImpl *shader;
+
+    ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
 
     IWineD3DDevice_EnumResources(iface, reset_unload_resources, NULL);
@@ -7465,37 +7349,6 @@
             unsigned int i;
 
-            /* Cleanup any FBO attachments if d3d is enabled */
-            if(This->d3d_initialized) {
-                if((IWineD3DSurface *)resource == This->lastActiveRenderTarget) {
-                    IWineD3DSwapChainImpl *swapchain = This->swapchains ? (IWineD3DSwapChainImpl *) This->swapchains[0] : NULL;
-
-                    TRACE("Last active render target destroyed\n");
-                    /* Find a replacement surface for the currently active back buffer. The context manager does not do NULL
-                     * checks, so switch to a valid target as long as the currently set surface is still valid. Use the
-                     * surface of the implicit swpchain. If that is the same as the destroyed surface the device is destroyed
-                     * and the lastActiveRenderTarget member shouldn't matter
-                     */
-                    if(swapchain) {
-                        if(swapchain->backBuffer && swapchain->backBuffer[0] != (IWineD3DSurface *)resource) {
-                            TRACE("Activating primary back buffer\n");
-                            ActivateContext(This, swapchain->backBuffer[0], CTXUSAGE_RESOURCELOAD);
-                        } else if(!swapchain->backBuffer && swapchain->frontBuffer != (IWineD3DSurface *)resource) {
-                            /* Single buffering environment */
-                            TRACE("Activating primary front buffer\n");
-                            ActivateContext(This, swapchain->frontBuffer, CTXUSAGE_RESOURCELOAD);
-                        } else {
-                            TRACE("Device is being destroyed, setting lastActiveRenderTarget = 0xdeadbabe\n");
-                            /* Implicit render target destroyed, that means the device is being destroyed
-                             * whatever we set here, it shouldn't matter
-                             */
-                            This->lastActiveRenderTarget = (IWineD3DSurface *) 0xdeadbabe;
-                        }
-                    } else {
-                        /* May happen during ddraw uninitialization */
-                        TRACE("Render target set, but swapchain does not exist!\n");
-                        This->lastActiveRenderTarget = (IWineD3DSurface *) 0xdeadcafe;
-                    }
-                }
-
+            if (This->d3d_initialized)
+            {
                 for (i = 0; i < GL_LIMITS(buffers); ++i) {
                     if (This->render_targets[i] == (IWineD3DSurface *)resource) {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/directx.c	(revision 21731)
@@ -32,13 +32,5 @@
  */
 
-/* Compile time diagnostics: */
-
-#ifndef DEBUG_SINGLE_MODE
-/* Set to 1 to force only a single display mode to be exposed: */
-#define DEBUG_SINGLE_MODE 0
-#endif
-
 #include "config.h"
-#include <assert.h>
 #include "wined3d_private.h"
 
@@ -73,4 +65,5 @@
     /* ARB */
     {"GL_ARB_color_buffer_float",           ARB_COLOR_BUFFER_FLOAT,         0                           },
+    {"GL_ARB_depth_buffer_float",           ARB_DEPTH_BUFFER_FLOAT,         0                           },
     {"GL_ARB_depth_texture",                ARB_DEPTH_TEXTURE,              0                           },
     {"GL_ARB_draw_buffers",                 ARB_DRAW_BUFFERS,               0                           },
@@ -214,130 +207,98 @@
  */
 
-static int             wined3d_fake_gl_context_ref = 0;
-static BOOL            wined3d_fake_gl_context_foreign;
-static BOOL            wined3d_fake_gl_context_available = FALSE;
-static HDC             wined3d_fake_gl_context_hdc = NULL;
-static HWND            wined3d_fake_gl_context_hwnd = NULL;
-
-static CRITICAL_SECTION wined3d_fake_gl_context_cs;
-static CRITICAL_SECTION_DEBUG wined3d_fake_gl_context_cs_debug =
-{
-    0, 0, &wined3d_fake_gl_context_cs,
-    { &wined3d_fake_gl_context_cs_debug.ProcessLocksList,
-      &wined3d_fake_gl_context_cs_debug.ProcessLocksList },
-    0, 0, { (DWORD_PTR)(__FILE__ ": wined3d_fake_gl_context_cs") }
+struct wined3d_fake_gl_ctx
+{
+    HDC dc;
+    HWND wnd;
+    HGLRC gl_ctx;
 };
-static CRITICAL_SECTION wined3d_fake_gl_context_cs = { &wined3d_fake_gl_context_cs_debug, -1, 0, 0, 0, 0 };
-
-static void WineD3D_ReleaseFakeGLContext(void) {
-    HGLRC glCtx;
-
-    EnterCriticalSection(&wined3d_fake_gl_context_cs);
-
-    if(!wined3d_fake_gl_context_available) {
-        TRACE_(d3d_caps)("context not available\n");
-        LeaveCriticalSection(&wined3d_fake_gl_context_cs);
-        return;
-    }
-
-    glCtx = pwglGetCurrentContext();
-
-    TRACE_(d3d_caps)("decrementing ref from %i\n", wined3d_fake_gl_context_ref);
-    if (0 == (--wined3d_fake_gl_context_ref) ) {
-        if(!wined3d_fake_gl_context_foreign && glCtx) {
-            TRACE_(d3d_caps)("destroying fake GL context\n");
-            pwglMakeCurrent(NULL, NULL);
-            pwglDeleteContext(glCtx);
-        }
-        if(wined3d_fake_gl_context_hdc)
-            ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
-        wined3d_fake_gl_context_hdc = NULL; /* Make sure we don't think that it is still around */
-        if(wined3d_fake_gl_context_hwnd)
-            DestroyWindow(wined3d_fake_gl_context_hwnd);
-        wined3d_fake_gl_context_hwnd = NULL;
-        wined3d_fake_gl_context_available = FALSE;
-    }
-    assert(wined3d_fake_gl_context_ref >= 0);
-
-    LeaveCriticalSection(&wined3d_fake_gl_context_cs);
-}
-
-static BOOL WineD3D_CreateFakeGLContext(void) {
-    HGLRC glCtx = NULL;
-
-    EnterCriticalSection(&wined3d_fake_gl_context_cs);
+
+static void WineD3D_ReleaseFakeGLContext(struct wined3d_fake_gl_ctx *ctx)
+{
+    TRACE_(d3d_caps)("Destroying fake GL context.\n");
+
+    if (!pwglMakeCurrent(NULL, NULL))
+    {
+        ERR_(d3d_caps)("Failed to disable fake GL context.\n");
+    }
+
+    if (!pwglDeleteContext(ctx->gl_ctx))
+    {
+        DWORD err = GetLastError();
+        ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx->gl_ctx, err);
+    }
+
+    ReleaseDC(ctx->wnd, ctx->dc);
+    DestroyWindow(ctx->wnd);
+}
+
+static BOOL WineD3D_CreateFakeGLContext(struct wined3d_fake_gl_ctx *ctx)
+{
+    PIXELFORMATDESCRIPTOR pfd;
+    int iPixelFormat;
 
     TRACE("getting context...\n");
-    if(wined3d_fake_gl_context_ref > 0) goto ret;
-    assert(0 == wined3d_fake_gl_context_ref);
-
-    wined3d_fake_gl_context_foreign = TRUE;
-
-    glCtx = pwglGetCurrentContext();
-    if (!glCtx) {
-        PIXELFORMATDESCRIPTOR pfd;
-        int iPixelFormat;
-
-        wined3d_fake_gl_context_foreign = FALSE;
-
-        /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes */
-        wined3d_fake_gl_context_hwnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window", WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
-        if(!wined3d_fake_gl_context_hwnd) {
-            ERR("HWND creation failed!\n");
-            goto fail;
-        }
-        wined3d_fake_gl_context_hdc = GetDC(wined3d_fake_gl_context_hwnd);
-        if(!wined3d_fake_gl_context_hdc) {
-            ERR("GetDC failed!\n");
-            goto fail;
-        }
-
-        /* PixelFormat selection */
-        ZeroMemory(&pfd, sizeof(pfd));
-        pfd.nSize      = sizeof(pfd);
-        pfd.nVersion   = 1;
-        pfd.dwFlags    = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW;/*PFD_GENERIC_ACCELERATED*/
-        pfd.iPixelType = PFD_TYPE_RGBA;
-        pfd.cColorBits = 32;
-        pfd.iLayerType = PFD_MAIN_PLANE;
-
-        iPixelFormat = ChoosePixelFormat(wined3d_fake_gl_context_hdc, &pfd);
-        if(!iPixelFormat) {
-            /* If this happens something is very wrong as ChoosePixelFormat barely fails */
-            ERR("Can't find a suitable iPixelFormat\n");
-            goto fail;
-        }
-        DescribePixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, sizeof(pfd), &pfd);
-        SetPixelFormat(wined3d_fake_gl_context_hdc, iPixelFormat, &pfd);
-
-        /* Create a GL context */
-        glCtx = pwglCreateContext(wined3d_fake_gl_context_hdc);
-        if (!glCtx) {
-            WARN_(d3d_caps)("Error creating default context for capabilities initialization\n");
-            goto fail;
-        }
-
-        /* Make it the current GL context */
-        if (!pwglMakeCurrent(wined3d_fake_gl_context_hdc, glCtx)) {
-            WARN_(d3d_caps)("Error setting default context as current for capabilities initialization\n");
-            goto fail;
-        }
-    }
-
-  ret:
-    TRACE("incrementing ref from %i\n", wined3d_fake_gl_context_ref);
-    wined3d_fake_gl_context_ref++;
-    wined3d_fake_gl_context_available = TRUE;
-    LeaveCriticalSection(&wined3d_fake_gl_context_cs);
+
+    /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes. */
+    ctx->wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window",
+            WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
+    if (!ctx->wnd)
+    {
+        ERR_(d3d_caps)("Failed to create a window.\n");
+        goto fail;
+    }
+
+    ctx->dc = GetDC(ctx->wnd);
+    if (!ctx->dc)
+    {
+        ERR_(d3d_caps)("Failed to get a DC.\n");
+        goto fail;
+    }
+
+    /* PixelFormat selection */
+    ZeroMemory(&pfd, sizeof(pfd));
+    pfd.nSize = sizeof(pfd);
+    pfd.nVersion = 1;
+    pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; /* PFD_GENERIC_ACCELERATED */
+    pfd.iPixelType = PFD_TYPE_RGBA;
+    pfd.cColorBits = 32;
+    pfd.iLayerType = PFD_MAIN_PLANE;
+
+    iPixelFormat = ChoosePixelFormat(ctx->dc, &pfd);
+    if (!iPixelFormat)
+    {
+        /* If this happens something is very wrong as ChoosePixelFormat barely fails. */
+        ERR_(d3d_caps)("Can't find a suitable iPixelFormat.\n");
+        goto fail;
+    }
+    DescribePixelFormat(ctx->dc, iPixelFormat, sizeof(pfd), &pfd);
+    SetPixelFormat(ctx->dc, iPixelFormat, &pfd);
+
+    /* Create a GL context. */
+    ctx->gl_ctx = pwglCreateContext(ctx->dc);
+    if (!ctx->gl_ctx)
+    {
+        WARN_(d3d_caps)("Error creating default context for capabilities initialization.\n");
+        goto fail;
+    }
+
+    /* Make it the current GL context. */
+    if (!pwglMakeCurrent(ctx->dc, ctx->gl_ctx))
+    {
+        ERR_(d3d_caps)("Failed to make fake GL context current.\n");
+        goto fail;
+    }
+    context_set_last_device(NULL);
+
     return TRUE;
-  fail:
-    if(wined3d_fake_gl_context_hdc)
-        ReleaseDC(wined3d_fake_gl_context_hwnd, wined3d_fake_gl_context_hdc);
-    wined3d_fake_gl_context_hdc = NULL;
-    if(wined3d_fake_gl_context_hwnd)
-        DestroyWindow(wined3d_fake_gl_context_hwnd);
-    wined3d_fake_gl_context_hwnd = NULL;
-    if(glCtx) pwglDeleteContext(glCtx);
-    LeaveCriticalSection(&wined3d_fake_gl_context_cs);
+
+fail:
+    if (ctx->gl_ctx) pwglDeleteContext(ctx->gl_ctx);
+    ctx->gl_ctx = NULL;
+    if (ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
+    ctx->dc = NULL;
+    if (ctx->wnd) DestroyWindow(ctx->wnd);
+    ctx->wnd = NULL;
+
     return FALSE;
 }
@@ -401,5 +362,6 @@
  * the device type, and the user preferences in wined3d_settings */
 
-static void select_shader_mode(const WineD3D_GL_Info *gl_info, WINED3DDEVTYPE DeviceType, int *ps_selected, int *vs_selected)
+static void select_shader_mode(const struct wined3d_gl_info *gl_info,
+        WINED3DDEVTYPE DeviceType, int *ps_selected, int *vs_selected)
 {
     if (wined3d_settings.vs_mode == VS_NONE) {
@@ -433,9 +395,6 @@
 
 /** Select the number of report maximum shader constants based on the selected shader modes */
-static void select_shader_max_constants(
-    int ps_selected_mode,
-    int vs_selected_mode,
-    WineD3D_GL_Info *gl_info) {
-
+static void select_shader_max_constants(int ps_selected_mode, int vs_selected_mode, struct wined3d_gl_info *gl_info)
+{
     switch (vs_selected_mode) {
         case SHADER_GLSL:
@@ -468,5 +427,5 @@
 
 /* GL locking is done by the caller */
-static inline BOOL test_arb_vs_offset_limit(const WineD3D_GL_Info *gl_info)
+static inline BOOL test_arb_vs_offset_limit(const struct wined3d_gl_info *gl_info)
 {
     GLuint prog;
@@ -497,5 +456,5 @@
     GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
     GL_EXTCALL(glDeleteProgramsARB(1, &prog));
-    checkGLcall("ARB vp offset limit test cleanup\n");
+    checkGLcall("ARB vp offset limit test cleanup");
 
     return ret;
@@ -513,5 +472,470 @@
 }
 
-static BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
+static BOOL match_ati_r300_to_500(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
+{
+    if (gl_info->gl_vendor != VENDOR_ATI) return FALSE;
+    if (gl_info->gl_card == CARD_ATI_RADEON_9500) return TRUE;
+    if (gl_info->gl_card == CARD_ATI_RADEON_X700) return TRUE;
+    if (gl_info->gl_card == CARD_ATI_RADEON_X1600) return TRUE;
+    return FALSE;
+}
+
+static BOOL match_geforce5(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
+{
+    if (gl_info->gl_vendor == VENDOR_NVIDIA)
+    {
+        if (gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5800 || gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5600)
+        {
+            return TRUE;
+        }
+    }
+    return FALSE;
+}
+
+static BOOL match_apple(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
+{
+    /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
+     * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
+     * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
+     *
+     * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
+     * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
+     * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
+     * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
+     * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
+     * the chance that other implementations support them is rather small since Win32 QuickTime uses
+     * DirectDraw, not OpenGL. */
+    if (gl_info->supported[APPLE_FENCE]
+            && gl_info->supported[APPLE_CLIENT_STORAGE]
+            && gl_info->supported[APPLE_FLUSH_RENDER]
+            && 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;
+    }
+}
+
+/* Context activation is done by the caller. */
+static void test_pbo_functionality(struct wined3d_gl_info *gl_info)
+{
+    /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
+     * but glTexSubImage from a PBO fails miserably, with the first line repeated over
+     * all the texture. This function detects this bug by its symptom and disables PBOs
+     * if the test fails.
+     *
+     * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
+     * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
+     * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
+     * read back is compared to the original. If they are equal PBOs are assumed to work,
+     * otherwise the PBO extension is disabled. */
+    GLuint texture, pbo;
+    static const unsigned int pattern[] =
+    {
+        0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
+        0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
+        0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
+        0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
+    };
+    unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
+
+    /* No PBO -> No point in testing them. */
+    if (!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) return;
+
+    ENTER_GL();
+
+    while (glGetError());
+    glGenTextures(1, &texture);
+    glBindTexture(GL_TEXTURE_2D, texture);
+
+    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
+    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
+    checkGLcall("Specifying the PBO test texture");
+
+    GL_EXTCALL(glGenBuffersARB(1, &pbo));
+    GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
+    GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
+    checkGLcall("Specifying the PBO test pbo");
+
+    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
+    checkGLcall("Loading the PBO test texture");
+
+    GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
+    glFinish(); /* just to be sure */
+
+    memset(check, 0, sizeof(check));
+    glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
+    checkGLcall("Reading back the PBO test texture");
+
+    glDeleteTextures(1, &texture);
+    GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
+    checkGLcall("PBO test cleanup");
+
+    LEAVE_GL();
+
+    if (memcmp(check, pattern, sizeof(check)))
+    {
+        WARN_(d3d_caps)("PBO test failed, read back data doesn't match original.\n");
+        WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance.\n");
+        gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
+    }
+    else
+    {
+        TRACE_(d3d_caps)("PBO test successful.\n");
+    }
+}
+
+static BOOL match_apple_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
+{
+    return gl_info->gl_vendor == VENDOR_INTEL && match_apple(gl_info, gl_renderer);
+}
+
+static BOOL match_apple_nonr500ati(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
+{
+    if (!match_apple(gl_info, gl_renderer)) return FALSE;
+    if (gl_info->gl_vendor != VENDOR_ATI) return FALSE;
+    if (gl_info->gl_card == CARD_ATI_RADEON_X1600) return FALSE;
+    return TRUE;
+}
+
+static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
+{
+    if (gl_info->gl_vendor != VENDOR_ATI) return FALSE;
+    if (match_apple(gl_info, gl_renderer)) return FALSE;
+    if (strstr(gl_renderer, "DRI")) return FALSE; /* Filter out Mesa DRI drivers. */
+    return TRUE;
+}
+
+static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
+{
+    /* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
+     * 44 varyings. So assume that if we have more than 44 varyings we have a dx10 card.
+     * This detection is for the gl_ClipPos varying quirk. If a d3d9 card really supports more than 44
+     * varyings and we subtract one in dx9 shaders its not going to hurt us because the dx9 limit is
+     * hardcoded
+     *
+     * dx10 cards usually have 64 varyings */
+    return gl_info->max_glsl_varyings > 44;
+}
+
+/* A GL context is provided by the caller */
+static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
+{
+    GLenum error;
+    DWORD data[16];
+
+    if(!GL_SUPPORT(EXT_SECONDARY_COLOR)) return FALSE;
+
+    ENTER_GL();
+    while(glGetError());
+    GL_EXTCALL(glSecondaryColorPointerEXT)(4, GL_UNSIGNED_BYTE, 4, data);
+    error = glGetError();
+    LEAVE_GL();
+
+    if(error == GL_NO_ERROR)
+    {
+        TRACE("GL Implementation accepts 4 component specular color pointers\n");
+        return TRUE;
+    }
+    else
+    {
+        TRACE("GL implementation does not accept 4 component specular colors, error %s\n",
+              debug_glerror(error));
+        return FALSE;
+    }
+}
+
+static void quirk_arb_constants(struct wined3d_gl_info *gl_info)
+{
+    TRACE_(d3d_caps)("Using ARB vs constant limit(=%u) for GLSL.\n", gl_info->vs_arb_constantsF);
+    gl_info->vs_glsl_constantsF = gl_info->vs_arb_constantsF;
+    TRACE_(d3d_caps)("Using ARB ps constant limit(=%u) for GLSL.\n", gl_info->ps_arb_constantsF);
+    gl_info->ps_glsl_constantsF = gl_info->ps_arb_constantsF;
+}
+
+static void quirk_apple_glsl_constants(struct wined3d_gl_info *gl_info)
+{
+    quirk_arb_constants(gl_info);
+    /* MacOS needs uniforms for relative addressing offsets. This can accumulate to quite a few uniforms.
+     * Beyond that the general uniform isn't optimal, so reserve a number of uniforms. 12 vec4's should
+     * allow 48 different offsets or other helper immediate values. */
+    TRACE_(d3d_caps)("Reserving 12 GLSL constants for compiler private use.\n");
+    gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
+}
+
+/* fglrx crashes with a very bad kernel panic if GL_POINT_SPRITE_ARB is set to GL_COORD_REPLACE_ARB
+ * on more than one texture unit. This means that the d3d9 visual point size test will cause a
+ * kernel panic on any machine running fglrx 9.3(latest that supports r300 to r500 cards). This
+ * quirk only enables point sprites on the first texture unit. This keeps point sprites working in
+ * most games, but avoids the crash
+ *
+ * A more sophisticated way would be to find all units that need texture coordinates and enable
+ * point sprites for one if only one is found, and software emulate point sprites in drawStridedSlow
+ * if more than one unit needs texture coordinates(This requires software ffp and vertex shaders though)
+ *
+ * Note that disabling the extension entirely does not gain predictability because there is no point
+ * sprite capability flag in d3d, so the potential rendering bugs are the same if we disable the extension. */
+static void quirk_one_point_sprite(struct wined3d_gl_info *gl_info)
+{
+    if (gl_info->supported[ARB_POINT_SPRITE])
+    {
+        TRACE("Limiting point sprites to one texture unit.\n");
+        gl_info->max_point_sprite_units = 1;
+    }
+}
+
+static void quirk_ati_dx9(struct wined3d_gl_info *gl_info)
+{
+    quirk_arb_constants(gl_info);
+
+    /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
+     * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
+     * If real NP2 textures are used, the driver falls back to software. We could just remove the
+     * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconventient
+     * due to the non-normalized texture coordinates. Thus set an internal extension flag,
+     * GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures
+     * as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits.
+     *
+     * fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it advertises opengl 2.0 which
+     * has this extension promoted to core. The extension loading code sets this extension supported
+     * due to that, so this code works on fglrx as well. */
+    TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing.\n");
+    gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
+    gl_info->supported[WINE_NORMALIZED_TEXRECT] = TRUE;
+
+    /* fglrx has the same structural issues as the one described in quirk_apple_glsl_constants, although
+     * it is generally more efficient. Reserve just 8 constants. */
+    TRACE_(d3d_caps)("Reserving 8 GLSL constants for compiler private use.\n");
+    gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 8);
+}
+
+static void quirk_no_np2(struct wined3d_gl_info *gl_info)
+{
+    /*  The nVidia GeForceFX series reports OpenGL 2.0 capabilities with the latest drivers versions, but
+     *  doesn't explicitly advertise the ARB_tex_npot extension in the GL extension string.
+     *  This usually means that ARB_tex_npot is supported in hardware as long as the application is staying
+     *  within the limits enforced by the ARB_texture_rectangle extension. This however is not true for the
+     *  FX series, which instantly falls back to a slower software path as soon as ARB_tex_npot is used.
+     *  We therefore completely remove ARB_tex_npot from the list of supported extensions.
+     *
+     *  Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot,
+     *  triggering the software fallback. There is not much we can do here apart from disabling the
+     *  software-emulated extension and reenable ARB_tex_rect (which was previously disabled
+     *  in IWineD3DImpl_FillGLCaps).
+     *  This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer
+     *  post-processing effects in the game "Max Payne 2").
+     *  The behaviour can be verified through a simple test app attached in bugreport #14724. */
+    TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing.\n");
+    gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
+    gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
+}
+
+static void quirk_texcoord_w(struct wined3d_gl_info *gl_info)
+{
+    /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
+     * with fixed function fragment processing. Ideally this flag should be detected with a test shader
+     * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
+     * do not like vertex shaders in feedback mode and return an error, even though it should be valid
+     * according to the spec.
+     *
+     * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
+     * makes the shader slower and eats instruction slots which should be available to the d3d app.
+     *
+     * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
+     * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
+     * this workaround is activated on cards that do not need it, it won't break things, just affect
+     * performance negatively. */
+    TRACE("Enabling vertex texture coord fixes in vertex shaders.\n");
+    gl_info->quirks |= WINED3D_QUIRK_SET_TEXCOORD_W;
+}
+
+static void quirk_clip_varying(struct wined3d_gl_info *gl_info)
+{
+    gl_info->quirks |= WINED3D_QUIRK_GLSL_CLIP_VARYING;
+}
+
+static void quirk_allows_specular_alpha(struct wined3d_gl_info *gl_info)
+{
+    gl_info->quirks |= WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA;
+}
+
+struct driver_quirk
+{
+    BOOL (*match)(const struct wined3d_gl_info *gl_info, const char *gl_renderer);
+    void (*apply)(struct wined3d_gl_info *gl_info);
+    const char *description;
+};
+
+struct driver_quirk quirk_table[] =
+{
+    {
+        match_ati_r300_to_500,
+        quirk_ati_dx9,
+        "ATI GLSL constant and normalized texrect quirk"
+    },
+    /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
+     * used it falls back to software. While the compiler can detect if the shader uses all declared
+     * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
+     * using relative addressing falls back to software.
+     *
+     * ARB vp gives the correct amount of uniforms, so use it instead of GLSL. */
+    {
+        match_apple,
+        quirk_apple_glsl_constants,
+        "Apple GLSL uniform override"
+    },
+    {
+        match_geforce5,
+        quirk_no_np2,
+        "Geforce 5 NP2 disable"
+    },
+    {
+        match_apple_intel,
+        quirk_texcoord_w,
+        "Init texcoord .w for Apple Intel GPU driver"
+    },
+    {
+        match_apple_nonr500ati,
+        quirk_texcoord_w,
+        "Init texcoord .w for Apple ATI >= r600 GPU driver"
+    },
+    {
+        match_fglrx,
+        quirk_one_point_sprite,
+        "Fglrx point sprite crash workaround"
+    },
+    {
+        match_dx10_capable,
+        quirk_clip_varying,
+        "Reserved varying for gl_ClipPos"
+    },
+    {
+        /* GL_EXT_secondary_color does not allow 4 component secondary colors, but most
+         * GL implementations accept it. The Mac GL is the only implementation known to
+         * reject it.
+         *
+         * If we can pass 4 component specular colors, do it, because (a) we don't have
+         * to screw around with the data, and (b) the D3D fixed function vertex pipeline
+         * passes specular alpha to the pixel shader if any is used. Otherwise the
+         * specular alpha is used to pass the fog coordinate, which we pass to opengl
+         * via GL_EXT_fog_coord.
+         */
+        match_allows_spec_alpha,
+        quirk_allows_specular_alpha,
+        "Allow specular alpha quirk"
+    }
+};
+
+/* Certain applications (Steam) complain if we report an outdated driver version. In general,
+ * reporting a driver version is moot because we are not the Windows driver, and we have different
+ * bugs, features, etc.
+ *
+ * If a card is not found in this table, the GL driver version is reported. */
+struct driver_version_information
+{
+    WORD vendor;                    /* reported PCI card vendor ID  */
+    WORD card;                      /* reported PCI card device ID  */
+    const char *description;        /* Description of the card e.g. NVIDIA RIVA TNT */
+    WORD hipart_hi, hipart_lo;      /* driver hiword to report      */
+    WORD lopart_hi, lopart_lo;      /* driver loword to report      */
+};
+
+static const struct driver_version_information driver_version_table[] =
+{
+    /* Nvidia drivers. Geforce6 and newer cards are supported by the current driver (180.x)
+     * GeforceFX support is up to 173.x, - driver uses numbering x.y.11.7341 for 173.41 where x is the windows revision (6=2000/xp, 7=vista), y is unknown
+     * Geforce2MX/3/4 up to 96.x - driver uses numbering 9.6.8.9 for 96.89
+     * TNT/Geforce1/2 up to 71.x - driver uses numbering 7.1.8.6 for 71.86
+     *
+     * All version numbers used below are from the Linux nvidia drivers. */
+    {VENDOR_NVIDIA,     CARD_NVIDIA_RIVA_TNT,           "NVIDIA RIVA TNT",                  7,  1,  8,  6      },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_RIVA_TNT2,          "NVIDIA RIVA TNT2/TNT2 Pro",        7,  1,  8,  6      },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE,            "NVIDIA GeForce 256",               7,  1,  8,  6      },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE2_MX,        "NVIDIA GeForce2 MX/MX 400",        9,  6,  4,  3      },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE2,           "NVIDIA GeForce2 GTS/GeForce2 Pro", 7,  1,  8,  6      },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE3,           "NVIDIA GeForce3",                  9,  6,  10, 9371   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE4_MX,        "NVIDIA GeForce4 MX 460",           9,  6,  10, 9371   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE4_TI4200,    "NVIDIA GeForce4 Ti 4200",          9,  6,  10, 9371   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5200,     "NVIDIA GeForce FX 5200",           7,  15, 11, 7516   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5600,     "NVIDIA GeForce FX 5600",           7,  15, 11, 7516   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5800,     "NVIDIA GeForce FX 5800",           7,  15, 11, 7516   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6200,       "NVIDIA GeForce 6200",              7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6600GT,     "NVIDIA GeForce 6600 GT",           7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6800,       "NVIDIA GeForce 6800",              7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7300,       "NVIDIA GeForce Go 7300",           7,  15, 11, 8585   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7400,       "NVIDIA GeForce Go 7400",           7,  15, 11, 8585   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7600,       "NVIDIA GeForce 7600 GT",           7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7800GT,     "NVIDIA GeForce 7800 GT",           7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8300GS,     "NVIDIA GeForce 8300 GS",           7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8600GT,     "NVIDIA GeForce 8600 GT",           7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8600MGT,    "NVIDIA GeForce 8600M GT",          7,  15, 11, 8585   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8800GTS,    "NVIDIA GeForce 8800 GTS",          7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9200,       "NVIDIA GeForce 9200",              7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9400GT,     "NVIDIA GeForce 9400 GT",           7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9500GT,     "NVIDIA GeForce 9500 GT",           7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9600GT,     "NVIDIA GeForce 9600 GT",           7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9800GT,     "NVIDIA GeForce 9800 GT",           7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX260,     "NVIDIA GeForce GTX 260",           7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX275,     "NVIDIA GeForce GTX 275",           7,  15, 11, 8618   },
+    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX280,     "NVIDIA GeForce GTX 280",           7,  15, 11, 8618   },
+
+    /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode. */
+    {VENDOR_ATI,        CARD_ATI_RADEON_9500,           "ATI Radeon 9500",                  6,  14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_X700,           "ATI Radeon X700 SE",               6,  14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_X1600,          "ATI Radeon X1600 Series",          6,  14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD2300,         "ATI Mobility Radeon HD 2300",      6,  14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD2600,         "ATI Mobility Radeon HD 2600",      6,  14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD2900,         "ATI Radeon HD 2900 XT",            6,  14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD4350,         "ATI Radeon HD 4350",               6,  14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD4600,         "ATI Radeon HD 4600 Series",        6,  14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD4700,         "ATI Radeon HD 4700 Series",        6,  14, 10, 6764    },
+    {VENDOR_ATI,        CARD_ATI_RADEON_HD4800,         "ATI Radeon HD 4800 Series",        6,  14, 10, 6764    },
+
+    /* TODO: Add information about legacy ATI hardware, Intel and other cards. */
+};
+
+/* Context activation is done by the caller. */
+static void fixup_extensions(struct wined3d_gl_info *gl_info, const char *gl_renderer)
+{
+    unsigned int i;
+
+    for (i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); ++i)
+    {
+        if (!quirk_table[i].match(gl_info, gl_renderer)) continue;
+        TRACE_(d3d_caps)("Applying driver quirk \"%s\".\n", quirk_table[i].description);
+        quirk_table[i].apply(gl_info);
+    }
+
+    /* Find out if PBOs work as they are supposed to. */
+    test_pbo_functionality(gl_info);
+
+    /* Fixup the driver version */
+    for (i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); ++i)
+    {
+        if (gl_info->gl_vendor == driver_version_table[i].vendor
+                && gl_info->gl_card == driver_version_table[i].card)
+        {
+            TRACE_(d3d_caps)("Found card 0x%04x, 0x%04x in driver version DB.\n",
+                    gl_info->gl_vendor, gl_info->gl_card);
+
+            gl_info->driver_version = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
+                    driver_version_table[i].lopart_lo);
+            gl_info->driver_version_hipart = MAKEDWORD_VERSION(driver_version_table[i].hipart_hi,
+                    driver_version_table[i].hipart_lo);
+            gl_info->driver_description = driver_version_table[i].description;
+            break;
+        }
+    }
+}
+
+/* Context activation is done by the caller. */
+static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_gl_info *gl_info)
+{
     const char *GL_Extensions    = NULL;
     const char *WGL_Extensions   = NULL;
@@ -521,8 +945,10 @@
     GLfloat     gl_floatv[2];
     int         major = 1, minor = 0;
-    BOOL        return_value = TRUE;
     unsigned    i;
     HDC         hdc;
     unsigned int vidmem=0;
+    char *gl_renderer;
+    DWORD gl_version;
+    size_t len;
 
     TRACE_(d3d_caps)("(%p)\n", gl_info);
@@ -530,92 +956,117 @@
     ENTER_GL();
 
-    gl_string = (const char *) glGetString(GL_RENDERER);
-    if (!gl_string) gl_string = "None";
-    strcpy(gl_info->gl_renderer, gl_string);
-
-    gl_string = (const char *) glGetString(GL_VENDOR);
-    TRACE_(d3d_caps)("Filling vendor string %s\n", gl_string);
-    if (gl_string != NULL) {
-        /* 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_info->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 {
-            gl_info->gl_vendor = VENDOR_WINE;
-        }
-    } else {
+    gl_string = (const char *)glGetString(GL_RENDERER);
+    TRACE_(d3d_caps)("GL_RENDERER: %s.\n", gl_string);
+    if (!gl_string)
+    {
+        ERR_(d3d_caps)("Received a NULL GL_RENDERER.\n");
+        return FALSE;
+    }
+
+    len = strlen(gl_string) + 1;
+    gl_renderer = HeapAlloc(GetProcessHeap(), 0, len);
+    if (!gl_renderer)
+    {
+        ERR_(d3d_caps)("Failed to allocate gl_renderer memory.\n");
+        return FALSE;
+    }
+    memcpy(gl_renderer, gl_string, len);
+
+    gl_string = (const char *)glGetString(GL_VENDOR);
+    TRACE_(d3d_caps)("GL_VENDOR: %s.\n", gl_string);
+    if (!gl_string)
+    {
+        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;
     }
-
-
     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);
-    if (gl_string != NULL) {
-
-        /* 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("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_info->gl_version = MAKEDWORD_VERSION(major, minor);
-
-        /* Now parse the driver specific string which we'll report to the app */
-        switch (gl_info->gl_vendor) {
+    gl_string = (const char *)glGetString(GL_VERSION);
+    TRACE_(d3d_caps)("GL_VERSION: %s.\n", gl_string);
+    if (!gl_string)
+    {
+        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));
+            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));
+            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));
+            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));
+            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;
+            minor = major * 100 + minor;
             major = 10;
-
             break;
 
@@ -623,46 +1074,43 @@
             major = minor = 0;
             gl_string_cursor = strchr(gl_string, '-');
-            if (gl_string_cursor) {
-                int error = 0;
-                gl_string_cursor++;
-
-                /* Check if version number is of the form x.y.z */
-                if (*gl_string_cursor > '9' && *gl_string_cursor < '0')
-                    error = 1;
-                if (!error && *(gl_string_cursor+2) > '9' && *(gl_string_cursor+2) < '0')
-                    error = 1;
-                if (!error && *(gl_string_cursor+4) > '9' && *(gl_string_cursor+4) < '0')
-                    error = 1;
-                if (!error && *(gl_string_cursor+1) != '.' && *(gl_string_cursor+3) != '.')
-                    error = 1;
-
-                /* Mark version number as malformed */
-                if (error)
+            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 {
+            {
+                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');
+                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")) {
+            /* 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"
-                 */
+                 * "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));
+                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;
                 }
@@ -671,4 +1119,5 @@
                 break;
             }
+            /* Fallthrough */
 
         case VENDOR_MESA:
@@ -676,9 +1125,11 @@
             gl_string_cursor = strstr(gl_string_cursor, " ");
             while (*gl_string_cursor && ' ' == *gl_string_cursor) ++gl_string_cursor;
-            if (*gl_string_cursor) {
+            if (*gl_string_cursor)
+            {
                 char tmp[16];
                 int cursor = 0;
 
-                while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0') {
+                while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0')
+                {
                     tmp[cursor++] = *gl_string_cursor;
                     ++gl_string_cursor;
@@ -687,9 +1138,10 @@
                 major = atoi(tmp);
 
-                if (*gl_string_cursor != '.') WARN_(d3d_caps)("malformed GL_VERSION (%s)\n", debugstr_a(gl_string));
+                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') {
+                while (*gl_string_cursor <= '9' && *gl_string_cursor >= '0')
+                {
                     tmp[cursor++] = *gl_string_cursor;
                     ++gl_string_cursor;
@@ -703,16 +1155,12 @@
             major = 0;
             minor = 9;
-        }
-        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);
-    } else {
-        FIXME("OpenGL driver did not return version information\n");
-        gl_info->driver_version = MAKEDWORD_VERSION(0, 0);
-        gl_info->driver_version_hipart = MAKEDWORD_VERSION(6, 14);
-    }
-
-    TRACE_(d3d_caps)("found GL_RENDERER (%s)->(0x%04x)\n", debugstr_a(gl_info->gl_renderer), gl_info->gl_card);
+            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);
 
     /*
@@ -740,4 +1188,5 @@
     gl_info->vs_arb_constantsF = 0;
     gl_info->ps_arb_constantsF = 0;
+    gl_info->ps_arb_max_local_constants = 0;
 
     /* Retrieve opengl defaults */
@@ -759,283 +1208,329 @@
     TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
 
-    /* Parse the gl supported features, in theory enabling parts of our code appropriately */
-    GL_Extensions = (const char *) glGetString(GL_EXTENSIONS);
+    /* Parse the gl supported features, in theory enabling parts of our code appropriately. */
+    GL_Extensions = (const char *)glGetString(GL_EXTENSIONS);
+    if (!GL_Extensions)
+    {
+        ERR_(d3d_caps)("Received a NULL GL_EXTENSIONS.\n");
+        HeapFree(GetProcessHeap(), 0, gl_renderer);
+        return FALSE;
+    }
+
     TRACE_(d3d_caps)("GL_Extensions reported:\n");
 
-    if (NULL == GL_Extensions) {
-        ERR("   GL_Extensions returns NULL\n");
-    } else {
-        gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
-
-        while (*GL_Extensions != 0x00) {
-            const char *Start;
-            char        ThisExtn[256];
-            size_t      len;
-
-            while (isspace(*GL_Extensions)) GL_Extensions++;
-            Start = GL_Extensions;
-            while (!isspace(*GL_Extensions) && *GL_Extensions != 0x00) {
-                GL_Extensions++;
-            }
-
-            len = GL_Extensions - Start;
-            if (len == 0 || len >= sizeof(ThisExtn))
-                continue;
-
-            memcpy(ThisExtn, Start, len);
-            ThisExtn[len] = '\0';
-            TRACE_(d3d_caps)("- %s\n", ThisExtn);
-
-            for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
-                if (!strcmp(ThisExtn, EXTENSION_MAP[i].extension_string)) {
-                    TRACE_(d3d_caps)(" FOUND: %s support\n", EXTENSION_MAP[i].extension_string);
-                    gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
-                    break;
-                }
-            }
-        }
-
-        LEAVE_GL();
-
-        /* Now work out what GL support this card really has */
-#define USE_GL_FUNC(type, pfn, ext, replace) { \
-            DWORD ver = ver_for_ext(ext); \
-            if(gl_info->supported[ext]) gl_info->pfn = (type) pwglGetProcAddress(#pfn); \
-            else if(ver && ver <= gl_info->gl_version) gl_info->pfn = (type) pwglGetProcAddress(#replace); \
-            else gl_info->pfn = NULL; \
-        }
-        GL_EXT_FUNCS_GEN;
+    gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
+
+    while (*GL_Extensions)
+    {
+        const char *start;
+        char current_ext[256];
+
+        while (isspace(*GL_Extensions)) ++GL_Extensions;
+        start = GL_Extensions;
+        while (!isspace(*GL_Extensions) && *GL_Extensions) ++GL_Extensions;
+
+        len = GL_Extensions - start;
+        if (!len || len >= sizeof(current_ext)) continue;
+
+        memcpy(current_ext, start, len);
+        current_ext[len] = '\0';
+        TRACE_(d3d_caps)("- %s\n", current_ext);
+
+        for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i)
+        {
+            if (!strcmp(current_ext, EXTENSION_MAP[i].extension_string))
+            {
+                TRACE_(d3d_caps)(" FOUND: %s support.\n", EXTENSION_MAP[i].extension_string);
+                gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
+                break;
+            }
+        }
+    }
+
+    LEAVE_GL();
+
+    /* Now work out what GL support this card really has */
+#define USE_GL_FUNC(type, pfn, ext, replace) \
+{ \
+    DWORD ver = ver_for_ext(ext); \
+    if (gl_info->supported[ext]) gl_info->pfn = (type)pwglGetProcAddress(#pfn); \
+    else if (ver && ver <= gl_version) gl_info->pfn = (type)pwglGetProcAddress(#replace); \
+    else gl_info->pfn = NULL; \
+}
+    GL_EXT_FUNCS_GEN;
 #undef USE_GL_FUNC
 
-#define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type) pwglGetProcAddress(#pfn);
-        WGL_EXT_FUNCS_GEN;
+#define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type)pwglGetProcAddress(#pfn);
+    WGL_EXT_FUNCS_GEN;
 #undef USE_GL_FUNC
 
-        ENTER_GL();
-        /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
-         * loading the functions, otherwise the code above will load the extension entry points instead of the
-         * core functions, which may not work
+    ENTER_GL();
+
+    /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
+     * loading the functions, otherwise the code above will load the extension entry points instead of the
+     * core functions, which may not work. */
+    for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i)
+    {
+        if (!gl_info->supported[EXTENSION_MAP[i].extension]
+                && EXTENSION_MAP[i].version <= gl_version && EXTENSION_MAP[i].version)
+        {
+            TRACE_(d3d_caps)(" GL CORE: %s support.\n", EXTENSION_MAP[i].extension_string);
+            gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
+        }
+    }
+
+    if (gl_info->supported[APPLE_FENCE])
+    {
+        /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
+         * The apple extension interacts with some other apple exts. Disable the NV
+         * extension if the apple one is support to prevent confusion in other parts
+         * of the code. */
+        gl_info->supported[NV_FENCE] = FALSE;
+    }
+    if (gl_info->supported[APPLE_FLOAT_PIXELS])
+    {
+        /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
+         *
+         * The enums are the same:
+         * GL_RGBA16F_ARB     = GL_RGBA_FLOAT16_APPLE = 0x881A
+         * GL_RGB16F_ARB      = GL_RGB_FLOAT16_APPLE  = 0x881B
+         * GL_RGBA32F_ARB     = GL_RGBA_FLOAT32_APPLE = 0x8814
+         * GL_RGB32F_ARB      = GL_RGB_FLOAT32_APPLE  = 0x8815
+         * GL_HALF_FLOAT_ARB  = GL_HALF_APPLE         = 0x140B
          */
-        for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
-            if (gl_info->supported[EXTENSION_MAP[i].extension] == FALSE &&
-                EXTENSION_MAP[i].version <= gl_info->gl_version && EXTENSION_MAP[i].version) {
-                TRACE_(d3d_caps)(" GL CORE: %s support\n", EXTENSION_MAP[i].extension_string);
-                gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
-            }
-        }
-
-        if (gl_info->supported[APPLE_FENCE]) {
-            /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
-             * The apple extension interacts with some other apple exts. Disable the NV
-             * extension if the apple one is support to prevent confusion in other parts
-             * of the code
-             */
-            gl_info->supported[NV_FENCE] = FALSE;
-        }
-        if (gl_info->supported[APPLE_FLOAT_PIXELS]) {
-            /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
+        if (!gl_info->supported[ARB_TEXTURE_FLOAT])
+        {
+            TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels.\n");
+            gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
+        }
+        if (!gl_info->supported[ARB_HALF_FLOAT_PIXEL])
+        {
+            TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels.\n");
+            gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
+        }
+    }
+    if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
+    {
+        TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support.\n");
+        gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
+    }
+    if (gl_info->supported[NV_TEXTURE_SHADER2])
+    {
+        if (gl_info->supported[NV_REGISTER_COMBINERS])
+        {
+            /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
+             * are supported. The nv extensions provide the same functionality as the
+             * ATI one, and a bit more(signed pixelformats). */
+            gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
+        }
+    }
+    if (gl_info->supported[ARB_DRAW_BUFFERS])
+    {
+        glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
+        gl_info->max_buffers = gl_max;
+        TRACE_(d3d_caps)("Max draw buffers: %u.\n", gl_max);
+    }
+    if (gl_info->supported[ARB_MULTITEXTURE])
+    {
+        glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
+        gl_info->max_textures = min(MAX_TEXTURES, gl_max);
+        TRACE_(d3d_caps)("Max textures: %d.\n", gl_info->max_textures);
+
+        if (gl_info->supported[NV_REGISTER_COMBINERS])
+        {
+            GLint tmp;
+            glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &tmp);
+            gl_info->max_texture_stages = min(MAX_TEXTURES, tmp);
+        }
+        else
+        {
+            gl_info->max_texture_stages = min(MAX_TEXTURES, gl_max);
+        }
+        TRACE_(d3d_caps)("Max texture stages: %d.\n", gl_info->max_texture_stages);
+
+        if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
+        {
+            GLint tmp;
+            glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
+            gl_info->max_fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
+        }
+        else
+        {
+            gl_info->max_fragment_samplers = max(gl_info->max_fragment_samplers, gl_max);
+        }
+        TRACE_(d3d_caps)("Max fragment samplers: %d.\n", gl_info->max_fragment_samplers);
+
+        if (gl_info->supported[ARB_VERTEX_SHADER])
+        {
+            GLint tmp;
+            glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
+            gl_info->max_vertex_samplers = tmp;
+            glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
+            gl_info->max_combined_samplers = tmp;
+
+            /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
+             * is known at shader link time. In a vertex shader + pixel shader combination this isn't
+             * an issue because then the sampler setup only depends on the two shaders. If a pixel
+             * shader is used with fixed function vertex processing we're fine too because fixed function
+             * vertex processing doesn't use any samplers. If fixed function fragment processing is
+             * used we have to make sure that all vertex sampler setups are valid together with all
+             * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
+             * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
+             * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
+             * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
+             * a fixed function pipeline anymore.
              *
-             * The enums are the same:
-             * GL_RGBA16F_ARB     = GL_RGBA_FLOAT16_APPLE = 0x881A
-             * GL_RGB16F_ARB      = GL_RGB_FLOAT16_APPLE  = 0x881B
-             * GL_RGBA32F_ARB     = GL_RGBA_FLOAT32_APPLE = 0x8814
-             * GL_RGB32F_ARB      = GL_RGB_FLOAT32_APPLE  = 0x8815
-             * GL_HALF_FLOAT_ARB  = GL_HALF_APPLE         =  0x140B
-             */
-            if(!gl_info->supported[ARB_TEXTURE_FLOAT]) {
-                TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels\n");
-                gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
-            }
-            if(!gl_info->supported[ARB_HALF_FLOAT_PIXEL]) {
-                TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels\n");
-                gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
-            }
-        }
-        if (gl_info->supported[ARB_TEXTURE_CUBE_MAP]) {
-            TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support\n");
-            gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
-        }
-        if (gl_info->supported[NV_TEXTURE_SHADER2]) {
-            if(gl_info->supported[NV_REGISTER_COMBINERS]) {
-                /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
-                 * are supported. The nv extensions provide the same functionality as the
-                 * ATI one, and a bit more(signed pixelformats)
-                 */
-                gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
-            }
-        }
-        if (gl_info->supported[ARB_DRAW_BUFFERS]) {
-            glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
-            gl_info->max_buffers = gl_max;
-            TRACE_(d3d_caps)("Max draw buffers: %u\n", gl_max);
-        }
-        if (gl_info->supported[ARB_MULTITEXTURE]) {
-            glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
-            gl_info->max_textures = min(MAX_TEXTURES, gl_max);
-            TRACE_(d3d_caps)("Max textures: %d\n", gl_info->max_textures);
-
-            if (gl_info->supported[NV_REGISTER_COMBINERS]) {
-                GLint tmp;
-                glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &tmp);
-                gl_info->max_texture_stages = min(MAX_TEXTURES, tmp);
-            } else {
-                gl_info->max_texture_stages = min(MAX_TEXTURES, gl_max);
-            }
-            TRACE_(d3d_caps)("Max texture stages: %d\n", gl_info->max_texture_stages);
-
-            if (gl_info->supported[ARB_FRAGMENT_PROGRAM]) {
-                GLint tmp;
-                glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
-                gl_info->max_fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
-            } else {
-                gl_info->max_fragment_samplers = max(gl_info->max_fragment_samplers, gl_max);
-            }
-            TRACE_(d3d_caps)("Max fragment samplers: %d\n", gl_info->max_fragment_samplers);
-
-            if (gl_info->supported[ARB_VERTEX_SHADER]) {
-                GLint tmp;
-                glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
-                gl_info->max_vertex_samplers = tmp;
-                glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
-                gl_info->max_combined_samplers = tmp;
-
-                /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
-                 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
-                 * an issue because then the sampler setup only depends on the two shaders. If a pixel
-                 * shader is used with fixed function vertex processing we're fine too because fixed function
-                 * vertex processing doesn't use any samplers. If fixed function fragment processing is
-                 * used we have to make sure that all vertex sampler setups are valid together with all
-                 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
-                 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
-                 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
-                 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
-                 * a fixed function pipeline anymore.
-                 *
-                 * So this is just a check to check that our assumption holds true. If not, write a warning
-                 * and reduce the number of vertex samplers or probably disable vertex texture fetch.
-                 */
-                if(gl_info->max_vertex_samplers && gl_info->max_combined_samplers < 12 &&
-                   MAX_TEXTURES + gl_info->max_vertex_samplers > gl_info->max_combined_samplers) {
-                    FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers\n",
-                          gl_info->max_vertex_samplers, gl_info->max_combined_samplers);
-                    FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers\n");
-                    if( gl_info->max_combined_samplers > MAX_TEXTURES )
-                        gl_info->max_vertex_samplers =
-                            gl_info->max_combined_samplers - MAX_TEXTURES;
-                    else
-                        gl_info->max_vertex_samplers = 0;
-                }
-            } else {
-                gl_info->max_combined_samplers = gl_info->max_fragment_samplers;
-            }
-            TRACE_(d3d_caps)("Max vertex samplers: %u\n", gl_info->max_vertex_samplers);
-            TRACE_(d3d_caps)("Max combined samplers: %u\n", gl_info->max_combined_samplers);
-        }
-        if (gl_info->supported[ARB_VERTEX_BLEND]) {
-            glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
-            gl_info->max_blends = gl_max;
-            TRACE_(d3d_caps)("Max blends: %u\n", gl_info->max_blends);
-        }
-        if (gl_info->supported[EXT_TEXTURE3D]) {
-            glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
-            gl_info->max_texture3d_size = gl_max;
-            TRACE_(d3d_caps)("Max texture3D size: %d\n", gl_info->max_texture3d_size);
-        }
-        if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC]) {
-            glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
-            gl_info->max_anisotropy = gl_max;
-            TRACE_(d3d_caps)("Max anisotropy: %d\n", gl_info->max_anisotropy);
-        }
-        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;
-            TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d\n", gl_info->ps_arb_constantsF);
-            GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
-            gl_info->ps_arb_max_temps = gl_max;
-            TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d\n", gl_info->ps_arb_max_temps);
-            GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
-            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);
-        }
-        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;
-            TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d\n", gl_info->vs_arb_constantsF);
-            GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
-            gl_info->vs_arb_max_temps = gl_max;
-            TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d\n", gl_info->vs_arb_max_temps);
-            GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
-            gl_info->vs_arb_max_instructions = gl_max;
-            TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d\n", gl_info->vs_arb_max_instructions);
-
-            gl_info->arb_vs_offset_limit = test_arb_vs_offset_limit(gl_info);
-        }
-        if (gl_info->supported[ARB_VERTEX_SHADER]) {
-            glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
-            gl_info->vs_glsl_constantsF = gl_max / 4;
-            TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u\n", gl_info->vs_glsl_constantsF);
-        }
-        if (gl_info->supported[ARB_FRAGMENT_SHADER]) {
-            glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
-            gl_info->ps_glsl_constantsF = gl_max / 4;
-            TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u\n", gl_info->ps_glsl_constantsF);
-            glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
-            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]) {
-            glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->max_shininess);
-        } else {
-            gl_info->max_shininess = 128.0;
-        }
-        if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO]) {
-            /* If we have full NP2 texture support, disable GL_ARB_texture_rectangle because we will never use it.
-             * This saves a few redundant glDisable calls
-             */
-            gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
-        }
-        if(gl_info->supported[ATI_FRAGMENT_SHADER]) {
-            /* Disable NV_register_combiners and fragment shader if this is supported.
-             * generally the NV extensions are preferred over the ATI ones, and this
-             * extension is disabled if register_combiners and texture_shader2 are both
-             * supported. So we reach this place only if we have incomplete NV dxlevel 8
-             * fragment processing support
-             */
-            gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
-            gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
-            gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
-            gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
-            gl_info->supported[NV_TEXTURE_SHADER3] = FALSE;
-        }
-        if(gl_info->supported[NV_HALF_FLOAT]) {
-            /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float */
-            gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE;
-        }
-        if(gl_info->supported[ARB_POINT_SPRITE]) {
-            gl_info->max_point_sprite_units = gl_info->max_textures;
-        } else {
-            gl_info->max_point_sprite_units = 0;
-        }
-    }
-    checkGLcall("extension detection\n");
+             * So this is just a check to check that our assumption holds true. If not, write a warning
+             * and reduce the number of vertex samplers or probably disable vertex texture fetch. */
+            if (gl_info->max_vertex_samplers && gl_info->max_combined_samplers < 12
+                    && MAX_TEXTURES + gl_info->max_vertex_samplers > gl_info->max_combined_samplers)
+            {
+                FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers.\n",
+                        gl_info->max_vertex_samplers, gl_info->max_combined_samplers);
+                FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers.\n");
+                if (gl_info->max_combined_samplers > MAX_TEXTURES)
+                    gl_info->max_vertex_samplers = gl_info->max_combined_samplers - MAX_TEXTURES;
+                else
+                    gl_info->max_vertex_samplers = 0;
+            }
+        }
+        else
+        {
+            gl_info->max_combined_samplers = gl_info->max_fragment_samplers;
+        }
+        TRACE_(d3d_caps)("Max vertex samplers: %u.\n", gl_info->max_vertex_samplers);
+        TRACE_(d3d_caps)("Max combined samplers: %u.\n", gl_info->max_combined_samplers);
+    }
+    if (gl_info->supported[ARB_VERTEX_BLEND])
+    {
+        glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
+        gl_info->max_blends = gl_max;
+        TRACE_(d3d_caps)("Max blends: %u.\n", gl_info->max_blends);
+    }
+    if (gl_info->supported[EXT_TEXTURE3D])
+    {
+        glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
+        gl_info->max_texture3d_size = gl_max;
+        TRACE_(d3d_caps)("Max texture3D size: %d.\n", gl_info->max_texture3d_size);
+    }
+    if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
+    {
+        glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
+        gl_info->max_anisotropy = gl_max;
+        TRACE_(d3d_caps)("Max anisotropy: %d.\n", gl_info->max_anisotropy);
+    }
+    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;
+        TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d.\n", gl_info->ps_arb_constantsF);
+        GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
+        gl_info->ps_arb_max_temps = gl_max;
+        TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d.\n", gl_info->ps_arb_max_temps);
+        GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
+        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);
+    }
+    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;
+        TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d.\n", gl_info->vs_arb_constantsF);
+        GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
+        gl_info->vs_arb_max_temps = gl_max;
+        TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d.\n", gl_info->vs_arb_max_temps);
+        GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
+        gl_info->vs_arb_max_instructions = gl_max;
+        TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d.\n", gl_info->vs_arb_max_instructions);
+
+        if (test_arb_vs_offset_limit(gl_info)) gl_info->quirks |= WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT;
+    }
+    if (gl_info->supported[ARB_VERTEX_SHADER])
+    {
+        glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
+        gl_info->vs_glsl_constantsF = gl_max / 4;
+        TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u.\n", gl_info->vs_glsl_constantsF);
+    }
+    if (gl_info->supported[ARB_FRAGMENT_SHADER])
+    {
+        glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
+        gl_info->ps_glsl_constantsF = gl_max / 4;
+        TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u.\n", gl_info->ps_glsl_constantsF);
+        glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
+        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])
+    {
+        glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->max_shininess);
+    }
+    else
+    {
+        gl_info->max_shininess = 128.0f;
+    }
+    if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
+    {
+        /* If we have full NP2 texture support, disable
+         * GL_ARB_texture_rectangle because we will never use it.
+         * This saves a few redundant glDisable calls. */
+        gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
+    }
+    if (gl_info->supported[ATI_FRAGMENT_SHADER])
+    {
+        /* Disable NV_register_combiners and fragment shader if this is supported.
+         * generally the NV extensions are preferred over the ATI ones, and this
+         * extension is disabled if register_combiners and texture_shader2 are both
+         * supported. So we reach this place only if we have incomplete NV dxlevel 8
+         * fragment processing support. */
+        gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
+        gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
+        gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
+        gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
+        gl_info->supported[NV_TEXTURE_SHADER3] = FALSE;
+    }
+    if (gl_info->supported[NV_HALF_FLOAT])
+    {
+        /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float. */
+        gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE;
+    }
+    if (gl_info->supported[ARB_POINT_SPRITE])
+    {
+        gl_info->max_point_sprite_units = gl_info->max_textures;
+    }
+    else
+    {
+        gl_info->max_point_sprite_units = 0;
+    }
+    checkGLcall("extension detection");
 
     /* In some cases the number of texture stages can be larger than the number
@@ -1046,6 +1541,6 @@
     /* 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 PBuffer offscreen rendering mode.\n");
-        wined3d_settings.offscreen_rendering_mode = ORM_PBUFFER;
+        WARN_(d3d_caps)("GL_EXT_framebuffer_object not supported, falling back to backbuffer offscreen rendering mode.\n");
+        wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
     }
 
@@ -1104,7 +1599,7 @@
             if(WINE_D3D9_CAPABLE(gl_info) && (gl_info->vs_nv_version == VS_VERSION_30)) {
                 /* Geforce 200 - highend */
-                if(strstr(gl_info->gl_renderer, "GTX 280") ||
-                   strstr(gl_info->gl_renderer, "GTX 285") ||
-                   strstr(gl_info->gl_renderer, "GTX 295"))
+                if (strstr(gl_renderer, "GTX 280")
+                        || strstr(gl_renderer, "GTX 285")
+                        || strstr(gl_renderer, "GTX 295"))
                 {
                     gl_info->gl_card = CARD_NVIDIA_GEFORCE_GTX280;
@@ -1112,17 +1607,19 @@
                 }
                 /* Geforce 200 - midend high */
-                if(strstr(gl_info->gl_renderer, "GTX 275")) {
+                else if (strstr(gl_renderer, "GTX 275"))
+                {
                     gl_info->gl_card = CARD_NVIDIA_GEFORCE_GTX275;
                     vidmem = 896;
                 }
                 /* Geforce 200 - midend */
-                if(strstr(gl_info->gl_renderer, "GTX 260")) {
+                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_info->gl_renderer, "9800") ||
-                        strstr(gl_info->gl_renderer, "GTS 150") ||
-                        strstr(gl_info->gl_renderer, "GTS 250"))
+                else if (strstr(gl_renderer, "9800")
+                        || strstr(gl_renderer, "GTS 150")
+                        || strstr(gl_renderer, "GTS 250"))
                 {
                     gl_info->gl_card = CARD_NVIDIA_GEFORCE_9800GT;
@@ -1130,12 +1627,13 @@
                 }
                 /* Geforce9 - midend */
-                else if(strstr(gl_info->gl_renderer, "9600")) {
+                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_info->gl_renderer, "9500") ||
-                        strstr(gl_info->gl_renderer, "GT 120") ||
-                        strstr(gl_info->gl_renderer, "GT 130"))
+                else if (strstr(gl_renderer, "9500")
+                        || strstr(gl_renderer, "GT 120")
+                        || strstr(gl_renderer, "GT 130"))
                 {
                     gl_info->gl_card = CARD_NVIDIA_GEFORCE_9500GT;
@@ -1143,13 +1641,14 @@
                 }
                 /* Geforce9 - lowend */
-                else if(strstr(gl_info->gl_renderer, "9400")) {
+                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_info->gl_renderer, "9100") ||
-                        strstr(gl_info->gl_renderer, "9200") ||
-                        strstr(gl_info->gl_renderer, "9300") ||
-                        strstr(gl_info->gl_renderer, "G 100"))
+                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;
@@ -1157,16 +1656,18 @@
                 }
                 /* Geforce8 - highend */
-                else if (strstr(gl_info->gl_renderer, "8800")) {
+                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_info->gl_renderer, "8600 M")) {
+                else if (strstr(gl_renderer, "8600 M"))
+                {
                     gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600MGT;
                     vidmem = 512;
                 }
                 /* Geforce8 - midend */
-                else if(strstr(gl_info->gl_renderer, "8600") ||
-                        strstr(gl_info->gl_renderer, "8700"))
+                else if (strstr(gl_renderer, "8600")
+                        || strstr(gl_renderer, "8700"))
                 {
                     gl_info->gl_card = CARD_NVIDIA_GEFORCE_8600GT;
@@ -1174,7 +1675,7 @@
                 }
                 /* Geforce8 - lowend */
-                else if(strstr(gl_info->gl_renderer, "8300") ||
-                        strstr(gl_info->gl_renderer, "8400") ||
-                        strstr(gl_info->gl_renderer, "8500"))
+                else if (strstr(gl_renderer, "8300")
+                        || strstr(gl_renderer, "8400")
+                        || strstr(gl_renderer, "8500"))
                 {
                     gl_info->gl_card = CARD_NVIDIA_GEFORCE_8300GS;
@@ -1182,9 +1683,9 @@
                 }
                 /* Geforce7 - highend */
-                else if(strstr(gl_info->gl_renderer, "7800") ||
-                        strstr(gl_info->gl_renderer, "7900") ||
-                        strstr(gl_info->gl_renderer, "7950") ||
-                        strstr(gl_info->gl_renderer, "Quadro FX 4") ||
-                        strstr(gl_info->gl_renderer, "Quadro FX 5"))
+                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;
@@ -1192,20 +1693,24 @@
                 }
                 /* Geforce7 midend */
-                else if(strstr(gl_info->gl_renderer, "7600") ||
-                        strstr(gl_info->gl_renderer, "7700")) {
+                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_info->gl_renderer, "7400")) {
+                }
+                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_info->gl_renderer, "7300")) {
+                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_info->gl_renderer, "6800"))
+                else if (strstr(gl_renderer, "6800"))
                 {
                     gl_info->gl_card = CARD_NVIDIA_GEFORCE_6800;
@@ -1213,7 +1718,7 @@
                 }
                 /* Geforce6 - midend */
-                else if(strstr(gl_info->gl_renderer, "6600") ||
-                        strstr(gl_info->gl_renderer, "6610") ||
-                        strstr(gl_info->gl_renderer, "6700"))
+                else if (strstr(gl_renderer, "6600")
+                        || strstr(gl_renderer, "6610")
+                        || strstr(gl_renderer, "6700"))
                 {
                     gl_info->gl_card = CARD_NVIDIA_GEFORCE_6600GT;
@@ -1227,8 +1732,8 @@
             } else if(WINE_D3D9_CAPABLE(gl_info)) {
                 /* GeforceFX - highend */
-                if (strstr(gl_info->gl_renderer, "5800") ||
-                    strstr(gl_info->gl_renderer, "5900") ||
-                    strstr(gl_info->gl_renderer, "5950") ||
-                    strstr(gl_info->gl_renderer, "Quadro FX"))
+                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;
@@ -1236,8 +1741,8 @@
                 }
                 /* GeforceFX - midend */
-                else if(strstr(gl_info->gl_renderer, "5600") ||
-                        strstr(gl_info->gl_renderer, "5650") ||
-                        strstr(gl_info->gl_renderer, "5700") ||
-                        strstr(gl_info->gl_renderer, "5750"))
+                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;
@@ -1250,35 +1755,43 @@
                 }
             } else if(WINE_D3D8_CAPABLE(gl_info)) {
-                if (strstr(gl_info->gl_renderer, "GeForce4 Ti") || strstr(gl_info->gl_renderer, "Quadro4")) {
+                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 {
+                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_info->gl_renderer, "GeForce4 MX")) {
+                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_info->gl_renderer, "GeForce2 MX") || strstr(gl_info->gl_renderer, "Quadro2 MXR")) {
+                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_info->gl_renderer, "GeForce2") || strstr(gl_info->gl_renderer, "Quadro2")) {
+                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 {
+                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_info->gl_renderer, "TNT2")) {
+                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 {
+                else
+                {
                     gl_info->gl_card = CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
                     vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
@@ -1287,19 +1800,46 @@
             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_info->gl_renderer, "HD 4800") ||
-                    strstr(gl_info->gl_renderer, "HD 4830") ||
-                    strstr(gl_info->gl_renderer, "HD 4850") ||
-                    strstr(gl_info->gl_renderer, "HD 4870") ||
-                    strstr(gl_info->gl_renderer, "HD 4890"))
+                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; /* HD4800 cards use 512-1024MB */
+                    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_info->gl_renderer, "HD 2900") ||
-                         strstr(gl_info->gl_renderer, "HD 3870") ||
-                         strstr(gl_info->gl_renderer, "HD 3850"))
+                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;
@@ -1307,8 +1847,8 @@
                 }
                 /* Radeon R6xx HD2600/HD3600 - midend; HD3830 is China-only midend */
-                else if (strstr(gl_info->gl_renderer, "HD 2600") ||
-                         strstr(gl_info->gl_renderer, "HD 3830") ||
-                         strstr(gl_info->gl_renderer, "HD 3690") ||
-                         strstr(gl_info->gl_renderer, "HD 3650"))
+                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;
@@ -1316,9 +1856,10 @@
                 }
                 /* Radeon R6xx HD2300/HD2400/HD3400 - lowend */
-                else if (strstr(gl_info->gl_renderer, "HD 2300") ||
-                         strstr(gl_info->gl_renderer, "HD 2400") ||
-                         strstr(gl_info->gl_renderer, "HD 3470") ||
-                         strstr(gl_info->gl_renderer, "HD 3450") ||
-                         strstr(gl_info->gl_renderer, "HD 3430"))
+                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;
@@ -1326,7 +1867,7 @@
                 }
                 /* Radeon R6xx/R7xx integrated */
-                else if (strstr(gl_info->gl_renderer, "HD 3100") ||
-                         strstr(gl_info->gl_renderer, "HD 3200") ||
-                         strstr(gl_info->gl_renderer, "HD 3300"))
+                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;
@@ -1334,9 +1875,9 @@
                 }
                 /* Radeon R5xx */
-                else if (strstr(gl_info->gl_renderer, "X1600") ||
-                         strstr(gl_info->gl_renderer, "X1650") ||
-                         strstr(gl_info->gl_renderer, "X1800") ||
-                         strstr(gl_info->gl_renderer, "X1900") ||
-                         strstr(gl_info->gl_renderer, "X1950"))
+                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;
@@ -1344,11 +1885,11 @@
                 }
                 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
-                else if(strstr(gl_info->gl_renderer, "X700") ||
-                        strstr(gl_info->gl_renderer, "X800") ||
-                        strstr(gl_info->gl_renderer, "X850") ||
-                        strstr(gl_info->gl_renderer, "X1300") ||
-                        strstr(gl_info->gl_renderer, "X1400") ||
-                        strstr(gl_info->gl_renderer, "X1450") ||
-                        strstr(gl_info->gl_renderer, "X1550"))
+                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;
@@ -1356,5 +1897,5 @@
                 }
                 /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400MHz */
-                else if(strstr(gl_info->gl_renderer, "Radeon Xpress"))
+                else if(strstr(gl_renderer, "Radeon Xpress"))
                 {
                     gl_info->gl_card = CARD_ATI_RADEON_XPRESS_200M;
@@ -1378,18 +1919,34 @@
             break;
         case VENDOR_INTEL:
-            if (strstr(gl_info->gl_renderer, "GMA 950") ||
-                strstr(gl_info->gl_renderer, "945GM")) {
+            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_info->gl_renderer, "915GM")) {
+            }
+            else if (strstr(gl_renderer, "915GM"))
+            {
                 gl_info->gl_card = CARD_INTEL_I915GM;
-            } else if (strstr(gl_info->gl_renderer, "915G")) {
+            }
+            else if (strstr(gl_renderer, "915G"))
+            {
                 gl_info->gl_card = CARD_INTEL_I915G;
-            } else if (strstr(gl_info->gl_renderer, "865G")) {
+            }
+            else if (strstr(gl_renderer, "865G"))
+            {
                 gl_info->gl_card = CARD_INTEL_I865G;
-            } else if (strstr(gl_info->gl_renderer, "855G")) {
+            }
+            else if (strstr(gl_renderer, "855G"))
+            {
                 gl_info->gl_card = CARD_INTEL_I855G;
-            } else if (strstr(gl_info->gl_renderer, "830G")) {
+            }
+            else if (strstr(gl_renderer, "830G"))
+            {
                 gl_info->gl_card = CARD_INTEL_I830G;
             } else {
@@ -1479,5 +2036,4 @@
                 const char *Start;
                 char ThisExtn[256];
-                size_t len;
 
                 while (isspace(*WGL_Extensions)) WGL_Extensions++;
@@ -1512,5 +2068,9 @@
     LEAVE_GL();
 
-    return return_value;
+    fixup_extensions(gl_info, gl_renderer);
+    add_gl_compat_wrappers(gl_info);
+
+    HeapFree(GetProcessHeap(), 0, gl_renderer);
+    return TRUE;
 }
 
@@ -1559,38 +2119,37 @@
     /* TODO: Store modes per adapter and read it from the adapter structure */
     if (Adapter == 0) { /* Display */
-        int i = 0;
-        int j = 0;
-
-        if (!DEBUG_SINGLE_MODE) {
-            DEVMODEW DevModeW;
-
-            ZeroMemory(&DevModeW, sizeof(DevModeW));
-            DevModeW.dmSize = sizeof(DevModeW);
-            while (EnumDisplaySettingsExW(NULL, j, &DevModeW, 0)) {
-                j++;
-                switch (Format)
-                {
-                    case WINED3DFMT_UNKNOWN:
-                        /* This is for D3D8, do not enumerate P8 here */
-                        if (DevModeW.dmBitsPerPel == 32 ||
-                            DevModeW.dmBitsPerPel == 16) i++;
-                        break;
-                    case WINED3DFMT_X8R8G8B8:
-                        if (DevModeW.dmBitsPerPel == 32) i++;
-                        break;
-                    case WINED3DFMT_R5G6B5:
-                        if (DevModeW.dmBitsPerPel == 16) i++;
-                        break;
-                    case WINED3DFMT_P8:
-                        if (DevModeW.dmBitsPerPel == 8) i++;
-                        break;
-                    default:
-                        /* Skip other modes as they do not match the requested format */
-                        break;
-                }
-            }
-        } else {
-            i = 1;
-            j = 1;
+        unsigned int i = 0;
+        unsigned int j = 0;
+        DEVMODEW mode;
+
+        memset(&mode, 0, sizeof(mode));
+        mode.dmSize = sizeof(mode);
+
+        while (EnumDisplaySettingsExW(NULL, j, &mode, 0))
+        {
+            ++j;
+            switch (Format)
+            {
+                case WINED3DFMT_UNKNOWN:
+                    /* This is for D3D8, do not enumerate P8 here */
+                    if (mode.dmBitsPerPel == 32 || mode.dmBitsPerPel == 16) ++i;
+                    break;
+
+                case WINED3DFMT_X8R8G8B8:
+                    if (mode.dmBitsPerPel == 32) ++i;
+                    break;
+
+                case WINED3DFMT_R5G6B5:
+                    if (mode.dmBitsPerPel == 16) ++i;
+                    break;
+
+                case WINED3DFMT_P8:
+                    if (mode.dmBitsPerPel == 8) ++i;
+                    break;
+
+                default:
+                    /* Skip other modes as they do not match the requested format */
+                    break;
+            }
         }
 
@@ -1616,5 +2175,6 @@
 
     /* TODO: Store modes per adapter and read it from the adapter structure */
-    if (Adapter == 0 && !DEBUG_SINGLE_MODE) { /* Display */
+    if (Adapter == 0)
+    {
         DEVMODEW DevModeW;
         int ModeIdx = 0;
@@ -1680,12 +2240,7 @@
                 DevModeW.dmBitsPerPel);
 
-    } else if (DEBUG_SINGLE_MODE) {
-        /* Return one setting of the format requested */
-        if (Mode > 0) return WINED3DERR_INVALIDCALL;
-        pMode->Width        = 800;
-        pMode->Height       = 600;
-        pMode->RefreshRate  = 60;
-        pMode->Format       = (Format == WINED3DFMT_UNKNOWN) ? WINED3DFMT_X8R8G8B8 : Format;
-    } else {
+    }
+    else
+    {
         FIXME_(d3d_caps)("Adapter not primary display\n");
     }
@@ -1735,4 +2290,5 @@
                                                    WINED3DADAPTER_IDENTIFIER* pIdentifier) {
     IWineD3DImpl *This = (IWineD3DImpl *)iface;
+    size_t len;
 
     TRACE_(d3d_caps)("(%p}->(Adapter: %d, Flags: %x, pId=%p)\n", This, Adapter, Flags, pIdentifier);
@@ -1744,24 +2300,54 @@
     /* Return the information requested */
     TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
-    strcpy(pIdentifier->Driver, This->adapters[Adapter].driver);
-    if(This->adapters[Adapter].gl_info.driver_description)
-        strcpy(pIdentifier->Description, This->adapters[Adapter].gl_info.driver_description);
-    else /* Copy default description "Direct3D HAL" */
-        strcpy(pIdentifier->Description, This->adapters[Adapter].description);
-
-    /* Note dx8 doesn't supply a DeviceName */
-    if (NULL != pIdentifier->DeviceName) strcpy(pIdentifier->DeviceName, "\\\\.\\DISPLAY1"); /* FIXME: May depend on desktop? */
-    pIdentifier->DriverVersion->u.HighPart = This->adapters[Adapter].gl_info.driver_version_hipart;
-    pIdentifier->DriverVersion->u.LowPart = This->adapters[Adapter].gl_info.driver_version;
-    *(pIdentifier->VendorId) = This->adapters[Adapter].gl_info.gl_vendor;
-    *(pIdentifier->DeviceId) = This->adapters[Adapter].gl_info.gl_card;
-    *(pIdentifier->SubSysId) = 0;
-    *(pIdentifier->Revision) = 0;
-    *pIdentifier->DeviceIdentifier = IID_D3DDEVICE_D3DUID;
+
+    if (pIdentifier->driver_size)
+    {
+        len = min(strlen(This->adapters[Adapter].driver), pIdentifier->driver_size - 1);
+        memcpy(pIdentifier->driver, This->adapters[Adapter].driver, len);
+        pIdentifier->driver[len] = '\0';
+    }
+
+    if (pIdentifier->description_size)
+    {
+        const char *description;
+
+        if (This->adapters[Adapter].gl_info.driver_description)
+            description = This->adapters[Adapter].gl_info.driver_description;
+        else
+            description = This->adapters[Adapter].description;
+
+        len = min(strlen(description), pIdentifier->description_size - 1);
+        memcpy(pIdentifier->description, description, len);
+        pIdentifier->description[len] = '\0';
+    }
+
+    /* Note that d3d8 doesn't supply a device name. */
+    if (pIdentifier->device_name_size)
+    {
+        static const char *device_name = "\\\\.\\DISPLAY1"; /* FIXME: May depend on desktop? */
+
+        len = strlen(device_name);
+        if (len >= pIdentifier->device_name_size)
+        {
+            ERR("Device name size too small.\n");
+            return WINED3DERR_INVALIDCALL;
+        }
+
+        memcpy(pIdentifier->device_name, device_name, len);
+        pIdentifier->device_name[len] = '\0';
+    }
+
+    pIdentifier->driver_version.u.HighPart = This->adapters[Adapter].gl_info.driver_version_hipart;
+    pIdentifier->driver_version.u.LowPart = This->adapters[Adapter].gl_info.driver_version;
+    pIdentifier->vendor_id = This->adapters[Adapter].gl_info.gl_vendor;
+    pIdentifier->device_id = This->adapters[Adapter].gl_info.gl_card;
+    pIdentifier->subsystem_id = 0;
+    pIdentifier->revision = 0;
+    memcpy(&pIdentifier->device_identifier, &IID_D3DDEVICE_D3DUID, sizeof(pIdentifier->device_identifier));
 
     if(wined3d_settings.pci_device_id != PCI_DEVICE_NONE)
     {
         TRACE_(d3d_caps)("Overriding pci device id with: %x\n", wined3d_settings.pci_device_id);
-        *(pIdentifier->DeviceId) = wined3d_settings.pci_device_id;
+        pIdentifier->device_id = wined3d_settings.pci_device_id;
     }
 
@@ -1769,17 +2355,13 @@
     {
         TRACE_(d3d_caps)("Overriding pci vendor id with: %x\n", wined3d_settings.pci_vendor_id);
-        *(pIdentifier->VendorId) = wined3d_settings.pci_vendor_id;
-    }
-
-    if (Flags & WINED3DENUM_NO_WHQL_LEVEL) {
-        *(pIdentifier->WHQLLevel) = 0;
-    } else {
-        *(pIdentifier->WHQLLevel) = 1;
-    }
+        pIdentifier->vendor_id = wined3d_settings.pci_vendor_id;
+    }
+
+    pIdentifier->whql_level = (Flags & WINED3DENUM_NO_WHQL_LEVEL) ? 0 : 1;
 
     return WINED3D_OK;
 }
 
-static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const WineD3D_GL_Info *gl_info,
+static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(const struct wined3d_gl_info *gl_info,
         const WineD3D_PixelFormat *cfg, const struct GlPixelFormatDesc *format_desc)
 {
@@ -1830,5 +2412,5 @@
 }
 
-static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const WineD3D_GL_Info *gl_info,
+static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const struct wined3d_gl_info *gl_info,
         const WineD3D_PixelFormat *cfg, const struct GlPixelFormatDesc *format_desc)
 {
@@ -2209,5 +2791,5 @@
 static BOOL CheckSrgbReadCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
 {
-    const WineD3D_GL_Info *gl_info = &adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &adapter->gl_info;
 
     /* Check for supported sRGB formats (Texture loading and framebuffer) */
@@ -2289,5 +2871,5 @@
         WINED3DDEVTYPE DeviceType, const struct GlPixelFormatDesc *format_desc)
 {
-    const WineD3D_GL_Info *gl_info = &adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &adapter->gl_info;
     const shader_backend_t *shader_backend;
     const struct fragment_pipeline *fp;
@@ -2569,5 +3151,5 @@
 static BOOL CheckVertexTextureCapability(struct WineD3DAdapter *adapter, const struct GlPixelFormatDesc *format_desc)
 {
-    const WineD3D_GL_Info *gl_info = &adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &adapter->gl_info;
 
     if (!GL_LIMITS(vertex_samplers)) {
@@ -2598,5 +3180,5 @@
     IWineD3DImpl *This = (IWineD3DImpl *)iface;
     struct WineD3DAdapter *adapter = &This->adapters[Adapter];
-    const WineD3D_GL_Info *gl_info = &adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &adapter->gl_info;
     const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(CheckFormat, gl_info);
     const struct GlPixelFormatDesc *adapter_format_desc = getFormatDescEntry(AdapterFormat, gl_info);
@@ -3135,5 +3717,5 @@
         WINED3DDEVTYPE DeviceType)
 {
-    const WineD3D_GL_Info *gl_info = &adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &adapter->gl_info;
     int vs_selected_mode;
     int ps_selected_mode;
@@ -3155,5 +3737,5 @@
 static const struct blit_shader *select_blit_implementation(struct WineD3DAdapter *adapter, WINED3DDEVTYPE DeviceType)
 {
-    const WineD3D_GL_Info *gl_info = &adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &adapter->gl_info;
     int vs_selected_mode;
     int ps_selected_mode;
@@ -3174,5 +3756,5 @@
     IWineD3DImpl    *This = (IWineD3DImpl *)iface;
     struct WineD3DAdapter *adapter = &This->adapters[Adapter];
-    const WineD3D_GL_Info *gl_info = &adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &adapter->gl_info;
     int vs_selected_mode;
     int ps_selected_mode;
@@ -3476,12 +4058,12 @@
     pCaps->MaxTextureRepeat = 32768;
     pCaps->MaxTextureAspectRatio = GL_LIMITS(texture_size);
-    pCaps->MaxVertexW = 1.0;
-
-    pCaps->GuardBandLeft = 0;
-    pCaps->GuardBandTop = 0;
-    pCaps->GuardBandRight = 0;
-    pCaps->GuardBandBottom = 0;
-
-    pCaps->ExtentsAdjust = 0;
+    pCaps->MaxVertexW = 1.0f;
+
+    pCaps->GuardBandLeft = 0.0f;
+    pCaps->GuardBandTop = 0.0f;
+    pCaps->GuardBandRight = 0.0f;
+    pCaps->GuardBandBottom = 0.0f;
+
+    pCaps->ExtentsAdjust = 0.0f;
 
     pCaps->StencilCaps =  WINED3DSTENCILCAPS_DECRSAT |
@@ -3569,5 +4151,5 @@
         TRACE_(d3d_caps)("Pixel shader disabled in config, reporting version 0.0\n");
         pCaps->PixelShaderVersion           = WINED3DPS_VERSION(0,0);
-        pCaps->PixelShader1xMaxValue        = 0.0;
+        pCaps->PixelShader1xMaxValue        = 0.0f;
     } else {
         pCaps->PixelShaderVersion           = shader_caps.PixelShaderVersion;
@@ -3792,5 +4374,5 @@
         object->surface_alignment = D3D8_PITCH_ALIGNMENT;
     }
-    object->posFixup[0] = 1.0; /* This is needed to get the x coord unmodified through a MAD */
+    object->posFixup[0] = 1.0f; /* This is needed to get the x coord unmodified through a MAD. */
 
     /* Set the state up as invalid until the device is fully created */
@@ -3884,390 +4466,4 @@
 }
 
-static BOOL match_apple(const WineD3D_GL_Info *gl_info)
-{
-    /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
-     * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
-     * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
-     *
-     * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
-     * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
-     * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
-     * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
-     * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
-     * the chance that other implementations support them is rather small since Win32 QuickTime uses
-     * DirectDraw, not OpenGL.
-     */
-    if(gl_info->supported[APPLE_FENCE] &&
-       gl_info->supported[APPLE_CLIENT_STORAGE] &&
-       gl_info->supported[APPLE_FLUSH_RENDER] &&
-       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;
-    }
-}
-
-static void test_pbo_functionality(WineD3D_GL_Info *gl_info) {
-    /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
-     * but glTexSubImage from a PBO fails miserably, with the first line repeated over
-     * all the texture. This function detects this bug by its symptom and disables PBOs
-     * if the test fails.
-     *
-     * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
-     * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
-     * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
-     * read back is compared to the original. If they are equal PBOs are assumed to work,
-     * otherwise the PBO extension is disabled.
-     */
-    GLuint texture, pbo;
-    static const unsigned int pattern[] = {
-        0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
-        0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
-        0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
-        0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
-    };
-    unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
-
-    if(!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) {
-        /* No PBO -> No point in testing them */
-        return;
-    }
-
-    ENTER_GL();
-
-    while(glGetError());
-    glGenTextures(1, &texture);
-    glBindTexture(GL_TEXTURE_2D, texture);
-
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
-    checkGLcall("Specifying the PBO test texture\n");
-
-    GL_EXTCALL(glGenBuffersARB(1, &pbo));
-    GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
-    GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
-    checkGLcall("Specifying the PBO test pbo\n");
-
-    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
-    checkGLcall("Loading the PBO test texture\n");
-
-    GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
-    glFinish(); /* just to be sure */
-
-    memset(check, 0, sizeof(check));
-    glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
-    checkGLcall("Reading back the PBO test texture\n");
-
-    glDeleteTextures(1, &texture);
-    GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
-    checkGLcall("PBO test cleanup\n");
-
-    LEAVE_GL();
-
-    if(memcmp(check, pattern, sizeof(check)) != 0) {
-        WARN_(d3d_caps)("PBO test failed, read back data doesn't match original\n");
-        WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance\n");
-        gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
-    } else {
-        TRACE_(d3d_caps)("PBO test successful\n");
-    }
-}
-
-/* Certain applications(Steam) complain if we report an outdated driver version. In general,
- * reporting a driver version is moot because we are not the Windows driver, and we have different
- * bugs, features, etc.
- *
- * If a card is not found in this table, the gl driver version is reported
- */
-struct driver_version_information {
-    WORD vendor;                        /* reported PCI card vendor ID  */
-    WORD card;                          /* reported PCI card device ID  */
-    const char *description;                  /* Description of the card e.g. NVIDIA RIVA TNT */
-    WORD hipart_hi, hipart_lo;          /* driver hiword to report      */
-    WORD lopart_hi, lopart_lo;          /* driver loword to report      */
-};
-
-static const struct driver_version_information driver_version_table[] = {
-    /* Nvidia drivers. Geforce6 and newer cards are supported by the current driver (180.x)
-     * GeforceFX support is up to 173.x, - driver uses numbering x.y.11.7341 for 173.41 where x is the windows revision (6=2000/xp, 7=vista), y is unknown
-     * Geforce2MX/3/4 up to 96.x - driver uses numbering 9.6.8.9 for 96.89
-     * TNT/Geforce1/2 up to 71.x - driver uses numbering 7.1.8.6 for 71.86
-     *
-     * All version numbers used below are from the Linux nvidia drivers.
-     */
-    {VENDOR_NVIDIA,     CARD_NVIDIA_RIVA_TNT,           "NVIDIA RIVA TNT",                  7,  1,  8,  6      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_RIVA_TNT2,          "NVIDIA RIVA TNT2/TNT2 Pro",        7,  1,  8,  6      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE,            "NVIDIA GeForce 256",               7,  1,  8,  6      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE2_MX,        "NVIDIA GeForce2 MX/MX 400",        9,  6,  4,  3      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE2,           "NVIDIA GeForce2 GTS/GeForce2 Pro", 7,  1,  8,  6      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE3,           "NVIDIA GeForce3",                  9,  6,  4,  3      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE4_MX,        "NVIDIA GeForce4 MX 460",           9,  6,  4,  3      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE4_TI4200,    "NVIDIA GeForce4 Ti 4200",          9,  6,  4,  3      },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5200,     "NVIDIA GeForce FX 5200",           7,  15, 11, 7341   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5600,     "NVIDIA GeForce FX 5600",           7,  15, 11, 7341   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCEFX_5800,     "NVIDIA GeForce FX 5800",           7,  15, 11, 7341   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6200,       "NVIDIA GeForce 6200",              7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6600GT,     "NVIDIA GeForce 6600 GT",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_6800,       "NVIDIA GeForce 6800",              7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7300,       "NVIDIA GeForce Go 7300",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7400,       "NVIDIA GeForce Go 7400",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7600,       "NVIDIA GeForce 7600 GT",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_7800GT,     "NVIDIA GeForce 7800 GT",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8300GS,     "NVIDIA GeForce 8300 GS",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8600GT,     "NVIDIA GeForce 8600 GT",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8600MGT,    "NVIDIA GeForce 8600M GT",          7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_8800GTS,    "NVIDIA GeForce 8800 GTS",          7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9200,       "NVIDIA GeForce 9200",              7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9400GT,     "NVIDIA GeForce 9400 GT",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9500GT,     "NVIDIA GeForce 9500 GT",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9600GT,     "NVIDIA GeForce 9600 GT",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_9800GT,     "NVIDIA GeForce 9800 GT",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX260,     "NVIDIA GeForce GTX 260",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX275,     "NVIDIA GeForce GTX 275",           7,  15, 11, 8044   },
-    {VENDOR_NVIDIA,     CARD_NVIDIA_GEFORCE_GTX280,     "NVIDIA GeForce GTX 280",           7,  15, 11, 8044   },
-
-    /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode */
-    {VENDOR_ATI,        CARD_ATI_RADEON_9500,           "ATI Radeon 9500",                  6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_X700,           "ATI Radeon X700 SE",               6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_X1600,          "ATI Radeon X1600 Series",          6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_HD2300,         "ATI Mobility Radeon HD 2300",      6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_HD2600,         "ATI Mobility Radeon HD 2600",      6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_HD2900,         "ATI Radeon HD 2900 XT",            6,  14, 10, 6764    },
-    {VENDOR_ATI,        CARD_ATI_RADEON_HD4800,         "ATI Radeon HD 4800 Series",        6,  14, 10, 6764    },
-
-    /* TODO: Add information about legacy ATI hardware, Intel and other cards */
-};
-
-static BOOL match_ati_r300_to_500(const WineD3D_GL_Info *gl_info) {
-    if(gl_info->gl_vendor != VENDOR_ATI) return FALSE;
-    if(gl_info->gl_card == CARD_ATI_RADEON_9500) return TRUE;
-    if(gl_info->gl_card == CARD_ATI_RADEON_X700) return TRUE;
-    if(gl_info->gl_card == CARD_ATI_RADEON_X1600) return TRUE;
-    return FALSE;
-}
-
-static BOOL match_geforce5(const WineD3D_GL_Info *gl_info) {
-    if(gl_info->gl_vendor == VENDOR_NVIDIA) {
-        if(gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5800 || gl_info->gl_card == CARD_NVIDIA_GEFORCEFX_5600) {
-            return TRUE;
-        }
-    }
-    return FALSE;
-}
-
-static BOOL match_apple_intel(const WineD3D_GL_Info *gl_info) {
-    return gl_info->gl_vendor == VENDOR_INTEL && match_apple(gl_info);
-}
-
-static BOOL match_apple_nonr500ati(const WineD3D_GL_Info *gl_info) {
-    if(!match_apple(gl_info)) return FALSE;
-    if(gl_info->gl_vendor != VENDOR_ATI) return FALSE;
-    if(gl_info->gl_card == CARD_ATI_RADEON_X1600) return FALSE;
-    return TRUE;
-}
-
-static BOOL match_fglrx(const WineD3D_GL_Info *gl_info) {
-    if(gl_info->gl_vendor != VENDOR_ATI) return FALSE;
-    if(match_apple(gl_info)) return FALSE;
-    if(strstr(gl_info->gl_renderer, "DRI")) return FALSE; /* Filter out Mesa DRI drivers */
-    return TRUE;
-}
-
-static BOOL match_dx10_capable(const WineD3D_GL_Info *gl_info) {
-    /* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
-     * 44 varyings. So assume that if we have more than 44 varyings we have a dx10 card.
-     * This detection is for the gl_ClipPos varying quirk. If a d3d9 card really supports more than 44
-     * varyings and we subtract one in dx9 shaders its not going to hurt us because the dx9 limit is
-     * hardcoded
-     *
-     * dx10 cards usually have 64 varyings
-     */
-    return gl_info->max_glsl_varyings > 44;
-}
-
-static void quirk_arb_constants(WineD3D_GL_Info *gl_info) {
-    TRACE_(d3d_caps)("Using ARB vs constant limit(=%u) for GLSL\n", gl_info->vs_arb_constantsF);
-    gl_info->vs_glsl_constantsF = gl_info->vs_arb_constantsF;
-    TRACE_(d3d_caps)("Using ARB ps constant limit(=%u) for GLSL\n", gl_info->ps_arb_constantsF);
-    gl_info->ps_glsl_constantsF = gl_info->ps_arb_constantsF;
-}
-
-static void quirk_apple_glsl_constants(WineD3D_GL_Info *gl_info) {
-    quirk_arb_constants(gl_info);
-    /* MacOS needs uniforms for relative addressing offsets. This can accumulate to quite a few uniforms.
-     * Beyond that the general uniform isn't optimal, so reserve a number of uniforms. 12 vec4's should
-     * allow 48 different offsets or other helper immediate values
-     */
-    TRACE_(d3d_caps)("Reserving 12 GLSL constants for compiler private use\n");
-    gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
-}
-
-/* fglrx crashes with a very bad kernel panic if GL_POINT_SPRITE_ARB is set to GL_COORD_REPLACE_ARB
- * on more than one texture unit. This means that the d3d9 visual point size test will cause a
- * kernel panic on any machine running fglrx 9.3(latest that supports r300 to r500 cards). This
- * quirk only enables point sprites on the first texture unit. This keeps point sprites working in
- * most games, but avoids the crash
- *
- * A more sophisticated way would be to find all units that need texture coordinates and enable
- * point sprites for one if only one is found, and software emulate point sprites in drawStridedSlow
- * if more than one unit needs texture coordinates(This requires software ffp and vertex shaders though)
- *
- * Note that disabling the extension entirely does not gain predictability because there is no point
- * sprite capability flag in d3d, so the potential rendering bugs are the same if we disable the extension.
- */
-static void quirk_one_point_sprite(WineD3D_GL_Info *gl_info) {
-    if(gl_info->supported[ARB_POINT_SPRITE]) {
-        TRACE("Limiting point sprites to one texture unit\n");
-        gl_info->max_point_sprite_units = 1;
-    }
-}
-
-static void quirk_ati_dx9(WineD3D_GL_Info *gl_info) {
-    quirk_arb_constants(gl_info);
-
-    /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
-     * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
-     * If real NP2 textures are used, the driver falls back to software. We could just remove the
-     * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconventient
-     * due to the non-normalized texture coordinates. Thus set an internal extension flag,
-     * GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures
-     * as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits.
-     *
-     * fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it advertises opengl 2.0 which
-     * has this extension promoted to core. The extension loading code sets this extension supported
-     * due to that, so this code works on fglrx as well.
-     */
-    TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing\n");
-    gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
-    gl_info->supported[WINE_NORMALIZED_TEXRECT] = TRUE;
-
-    /* fglrx has the same structural issues as the one described in quirk_apple_glsl_constants, although
-     * it is generally more efficient. Reserve just 8 constants
-     */
-    TRACE_(d3d_caps)("Reserving 8 GLSL constants for compiler private use\n");
-    gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 8);
-}
-
-static void quirk_no_np2(WineD3D_GL_Info *gl_info) {
-    /*  The nVidia GeForceFX series reports OpenGL 2.0 capabilities with the latest drivers versions, but
-     *  doesn't explicitly advertise the ARB_tex_npot extension in the GL extension string.
-     *  This usually means that ARB_tex_npot is supported in hardware as long as the application is staying
-     *  within the limits enforced by the ARB_texture_rectangle extension. This however is not true for the
-     *  FX series, which instantly falls back to a slower software path as soon as ARB_tex_npot is used.
-     *  We therefore completely remove ARB_tex_npot from the list of supported extensions.
-     *
-     *  Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot,
-     *  triggering the software fallback. There is not much we can do here apart from disabling the
-     *  software-emulated extension and reenable ARB_tex_rect (which was previously disabled
-     *  in IWineD3DImpl_FillGLCaps).
-     *  This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer
-     *  post-processing effects in the game "Max Payne 2").
-     *  The behaviour can be verified through a simple test app attached in bugreport #14724.
-     */
-    TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing\n");
-    gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
-    gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
-}
-
-static void quirk_texcoord_w(WineD3D_GL_Info *gl_info) {
-    /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
-     * with fixed function fragment processing. Ideally this flag should be detected with a test shader
-     * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
-     * do not like vertex shaders in feedback mode and return an error, even though it should be valid
-     * according to the spec.
-     *
-     * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
-     * makes the shader slower and eats instruction slots which should be available to the d3d app.
-     *
-     * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
-     * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
-     * this workaround is activated on cards that do not need it, it won't break things, just affect
-     * performance negatively.
-     */
-    TRACE("Enabling vertex texture coord fixes in vertex shaders\n");
-    gl_info->set_texcoord_w = TRUE;
-}
-
-static void quirk_clip_varying(WineD3D_GL_Info *gl_info) {
-    gl_info->glsl_clip_varying = TRUE;
-}
-
-struct driver_quirk quirk_table[] = {
-    {
-        match_ati_r300_to_500,
-        quirk_ati_dx9,
-        "ATI GLSL constant and normalized texrect quirk"
-    },
-    /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
-     * used it falls back to software. While the compiler can detect if the shader uses all declared
-     * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
-     * using relative addressing falls back to software.
-     *
-     * ARB vp gives the correct amount of uniforms, so use it instead of GLSL
-     */
-    {
-        match_apple,
-        quirk_apple_glsl_constants,
-        "Apple GLSL uniform override"
-    },
-    {
-        match_geforce5,
-        quirk_no_np2,
-        "Geforce 5 NP2 disable"
-    },
-    {
-        match_apple_intel,
-        quirk_texcoord_w,
-        "Init texcoord .w for Apple Intel GPU driver"
-    },
-    {
-        match_apple_nonr500ati,
-        quirk_texcoord_w,
-        "Init texcoord .w for Apple ATI >= r600 GPU driver"
-    },
-    {
-        match_fglrx,
-        quirk_one_point_sprite,
-        "Fglrx point sprite crash workaround"
-    },
-    {
-        match_dx10_capable,
-        quirk_clip_varying,
-        "Reserved varying for gl_ClipPos"
-    }
-};
-
-static void fixup_extensions(WineD3D_GL_Info *gl_info) {
-    unsigned int i;
-
-    for(i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); i++) {
-        if(!quirk_table[i].match(gl_info)) continue;
-        TRACE_(d3d_caps)("Applying driver quirk \"%s\"\n", quirk_table[i].description);
-        quirk_table[i].apply(gl_info);
-    }
-
-    /* Find out if PBOs work as they are supposed to */
-    test_pbo_functionality(gl_info);
-
-    /* Fixup the driver version */
-    for(i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++) {
-        if(gl_info->gl_vendor == driver_version_table[i].vendor &&
-           gl_info->gl_card   == driver_version_table[i].card) {
-            TRACE_(d3d_caps)("Found card 0x%04x, 0x%04x in driver version DB\n", gl_info->gl_vendor, gl_info->gl_card);
-
-            gl_info->driver_version        = MAKEDWORD_VERSION(driver_version_table[i].lopart_hi,
-                                                               driver_version_table[i].lopart_lo);
-            gl_info->driver_version_hipart = MAKEDWORD_VERSION(driver_version_table[i].hipart_hi,
-                                                               driver_version_table[i].hipart_lo);
-            strcpy(gl_info->driver_description, driver_version_table[i].description);
-            break;
-        }
-    }
-}
-
 static void WINE_GLAPI invalid_func(const void *data)
 {
@@ -4300,10 +4496,13 @@
     const GLfloat *pos = data;
 
-    if (pos[3] < eps && pos[3] > -eps)
+    if (pos[3] != 0.0f && pos[3] != 1.0f)
+    {
+        float w = 1.0f / pos[3];
+
+        glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
+    }
+    else
+    {
         glVertex3fv(pos);
-    else {
-        float w = 1.0 / pos[3];
-
-        glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
     }
 }
@@ -4334,5 +4533,5 @@
 }
 
-static void fillGLAttribFuncs(const WineD3D_GL_Info *gl_info)
+static void fillGLAttribFuncs(const struct wined3d_gl_info *gl_info)
 {
     position_funcs[WINED3D_FFP_EMIT_FLOAT1]      = invalid_func;
@@ -4505,5 +4704,6 @@
     {
         struct WineD3DAdapter *adapter = &This->adapters[0];
-        const WineD3D_GL_Info *gl_info = &adapter->gl_info;
+        const struct wined3d_gl_info *gl_info = &adapter->gl_info;
+        struct wined3d_fake_gl_ctx fake_gl_ctx = {0};
         int iPixelFormat;
         int res;
@@ -4518,7 +4718,7 @@
         adapter->monitorPoint.y = -1;
 
-        if (!WineD3D_CreateFakeGLContext()) {
+        if (!WineD3D_CreateFakeGLContext(&fake_gl_ctx))
+        {
             ERR("Failed to get a gl context for default adapter\n");
-            WineD3D_ReleaseFakeGLContext();
             goto nogl_adapter;
         }
@@ -4527,5 +4727,5 @@
         if(!ret) {
             ERR("Failed to initialize gl caps for default adapter\n");
-            WineD3D_ReleaseFakeGLContext();
+            WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
             goto nogl_adapter;
         }
@@ -4533,14 +4733,9 @@
         if(!ret) {
             ERR("Failed to init gl formats\n");
-            WineD3D_ReleaseFakeGLContext();
+            WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
             goto nogl_adapter;
         }
 
-        hdc = pwglGetCurrentDC();
-        if(!hdc) {
-            ERR("Failed to get gl HDC\n");
-            WineD3D_ReleaseFakeGLContext();
-            goto nogl_adapter;
-        }
+        hdc = fake_gl_ctx.dc;
 
         adapter->driver = "Display";
@@ -4679,5 +4874,5 @@
                 ERR("Disabling Direct3D because no hardware accelerated pixel formats have been found!\n");
 
-                WineD3D_ReleaseFakeGLContext();
+                WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
                 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
                 goto nogl_adapter;
@@ -4704,8 +4899,5 @@
         }
 
-        fixup_extensions(&adapter->gl_info);
-        add_gl_compat_wrappers(&adapter->gl_info);
-
-        WineD3D_ReleaseFakeGLContext();
+        WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
 
         select_shader_mode(&adapter->gl_info, WINED3DDEVTYPE_HAL, &ps_selected_mode, &vs_selected_mode);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/drawprim.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/drawprim.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/drawprim.c	(revision 21731)
@@ -98,4 +98,5 @@
     const BYTE *diffuse = NULL, *specular = NULL, *normal = NULL, *position = NULL;
     const struct wined3d_stream_info_element *element;
+    UINT num_untracked_materials;
     DWORD tex_mask = 0;
 
@@ -133,5 +134,6 @@
     if (element->data) diffuse = element->data + streamOffset[element->stream_idx];
     else glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
-    if (This->activeContext->num_untracked_materials && element->format_desc->format != WINED3DFMT_A8R8G8B8)
+    num_untracked_materials = This->activeContext->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));
 
@@ -258,15 +260,17 @@
 
             diffuse_funcs[si->elements[WINED3D_FFP_DIFFUSE].format_desc->emit_idx](ptrToCoords);
-            if(This->activeContext->num_untracked_materials) {
+            if (num_untracked_materials)
+            {
                 DWORD diffuseColor = ((const DWORD *)ptrToCoords)[0];
                 unsigned char i;
                 float color[4];
 
-                color[0] = D3DCOLOR_B_R(diffuseColor) / 255.0;
-                color[1] = D3DCOLOR_B_G(diffuseColor) / 255.0;
-                color[2] = D3DCOLOR_B_B(diffuseColor) / 255.0;
-                color[3] = D3DCOLOR_B_A(diffuseColor) / 255.0;
-
-                for(i = 0; i < This->activeContext->num_untracked_materials; i++) {
+                color[0] = D3DCOLOR_B_R(diffuseColor) / 255.0f;
+                color[1] = D3DCOLOR_B_G(diffuseColor) / 255.0f;
+                color[2] = D3DCOLOR_B_B(diffuseColor) / 255.0f;
+                color[3] = D3DCOLOR_B_A(diffuseColor) / 255.0f;
+
+                for (i = 0; i < num_untracked_materials; ++i)
+                {
                     glMaterialfv(GL_FRONT_AND_BACK, This->activeContext->untracked_materials[i], color);
                 }
@@ -570,10 +574,15 @@
     if (!index_count) return;
 
-    /* Invalidate the back buffer memory so LockRect will read it the next time */
-    for(i = 0; i < GL_LIMITS(buffers); i++) {
-        target = (IWineD3DSurfaceImpl *) This->render_targets[i];
-        if (target) {
-            IWineD3DSurface_LoadLocation((IWineD3DSurface *) target, SFLAG_INDRAWABLE, NULL);
-            IWineD3DSurface_ModifyLocation((IWineD3DSurface *) target, SFLAG_INDRAWABLE, TRUE);
+    if (This->stateBlock->renderState[WINED3DRS_COLORWRITEENABLE])
+    {
+        /* Invalidate the back buffer memory so LockRect will read it the next time */
+        for (i = 0; i < GL_LIMITS(buffers); ++i)
+        {
+            target = (IWineD3DSurfaceImpl *)This->render_targets[i];
+            if (target)
+            {
+                IWineD3DSurface_LoadLocation((IWineD3DSurface *)target, SFLAG_INDRAWABLE, NULL);
+                IWineD3DSurface_ModifyLocation((IWineD3DSurface *)target, SFLAG_INDRAWABLE, TRUE);
+            }
         }
     }
@@ -586,8 +595,14 @@
     if (This->stencilBufferTarget) {
         /* Note that this depends on the ActivateContext call above to set
-         * This->render_offscreen properly */
+         * This->render_offscreen properly. We don't currently take the
+         * Z-compare function into account, but we could skip loading the
+         * depthstencil for D3DCMP_NEVER and D3DCMP_ALWAYS as well. Also note
+         * that we never copy the stencil data.*/
         DWORD location = This->render_offscreen ? SFLAG_DS_OFFSCREEN : SFLAG_DS_ONSCREEN;
-        surface_load_ds_location(This->stencilBufferTarget, location);
-        surface_modify_ds_location(This->stencilBufferTarget, location);
+        if (This->stateBlock->renderState[WINED3DRS_ZWRITEENABLE]
+                || This->stateBlock->renderState[WINED3DRS_ZENABLE])
+            surface_load_ds_location(This->stencilBufferTarget, location);
+        if (This->stateBlock->renderState[WINED3DRS_ZWRITEENABLE])
+            surface_modify_ds_location(This->stencilBufferTarget, location);
     }
 
@@ -712,5 +727,5 @@
 static void normalize_normal(float *n) {
     float length = n[0] * n[0] + n[1] * n[1] + n[2] * n[2];
-    if(length == 0.0) return;
+    if (length == 0.0f) return;
     length = sqrt(length);
     n[0] = n[0] / length;
@@ -744,5 +759,5 @@
                             struct WineD3DRectPatch *patch) {
     unsigned int i, j, num_quads, out_vertex_size, buffer_size, d3d_out_vertex_size;
-    float max_x = 0.0, max_y = 0.0, max_z = 0.0, neg_z = 0.0;
+    float max_x = 0.0f, max_y = 0.0f, max_z = 0.0f, neg_z = 0.0f;
     struct wined3d_stream_info stream_info;
     struct wined3d_stream_info_element *e;
@@ -752,4 +767,9 @@
     GLenum feedback_type;
     GLfloat *feedbuffer;
+
+    /* Simply activate the context for blitting. This disables all the things we don't want and
+     * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the
+     * patch (as opposed to normal draws) will most likely need different changes anyway. */
+    ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_BLIT);
 
     /* First, locate the position data. This is provided in a vertex buffer in the stateblock.
@@ -803,9 +823,4 @@
     patch->has_texcoords = FALSE;
 
-    /* Simply activate the context for blitting. This disables all the things we don't want and
-     * takes care of dirtifying. Dirtifying is preferred over pushing / popping, since drawing the
-     * patch (as opposed to normal draws) will most likely need different changes anyway
-     */
-    ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_BLIT);
     ENTER_GL();
 
@@ -814,6 +829,6 @@
     glLoadIdentity();
     checkGLcall("glLoadIndentity()");
-    glScalef(1 / (max_x) , 1 / (max_y), max_z == 0 ? 1 : 1 / ( 2 * max_z));
-    glTranslatef(0, 0, 0.5);
+    glScalef(1.0f / (max_x), 1.0f / (max_y), max_z == 0.0f ? 1.0f : 1.0f / (2.0f * max_z));
+    glTranslatef(0.0f, 0.0f, 0.5f);
     checkGLcall("glScalef");
     glViewport(-max_x, -max_y, 2 * (max_x), 2 * (max_y));
@@ -827,9 +842,9 @@
     IWineD3DDeviceImpl_MarkStateDirty(This, STATE_RENDER(WINED3DRS_FILLMODE));
     if(patch->has_normals) {
-        static const GLfloat black[] = {0, 0, 0, 0};
-        static const GLfloat red[]   = {1, 0, 0, 0};
-        static const GLfloat green[] = {0, 1, 0, 0};
-        static const GLfloat blue[]  = {0, 0, 1, 0};
-        static const GLfloat white[] = {1, 1, 1, 1};
+        static const GLfloat black[] = {0.0f, 0.0f, 0.0f, 0.0f};
+        static const GLfloat red[]   = {1.0f, 0.0f, 0.0f, 0.0f};
+        static const GLfloat green[] = {0.0f, 1.0f, 0.0f, 0.0f};
+        static const GLfloat blue[]  = {0.0f, 0.0f, 1.0f, 0.0f};
+        static const GLfloat white[] = {1.0f, 1.0f, 1.0f, 1.0f};
         glEnable(GL_LIGHTING);
         checkGLcall("glEnable(GL_LIGHTING)");
@@ -850,5 +865,5 @@
         glLightfv(GL_LIGHT0, GL_POSITION, red);
         glEnable(GL_LIGHT0);
-        checkGLcall("Setting up light 1\n");
+        checkGLcall("Setting up light 1");
         IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(1));
         glLightfv(GL_LIGHT1, GL_DIFFUSE, green);
@@ -857,5 +872,5 @@
         glLightfv(GL_LIGHT1, GL_POSITION, green);
         glEnable(GL_LIGHT1);
-        checkGLcall("Setting up light 2\n");
+        checkGLcall("Setting up light 2");
         IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(2));
         glLightfv(GL_LIGHT2, GL_DIFFUSE, blue);
@@ -864,5 +879,5 @@
         glLightfv(GL_LIGHT2, GL_POSITION, blue);
         glEnable(GL_LIGHT2);
-        checkGLcall("Setting up light 3\n");
+        checkGLcall("Setting up light 3");
 
         IWineD3DDeviceImpl_MarkStateDirty(This, STATE_MATERIAL);
@@ -872,5 +887,5 @@
         glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black);
         glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, white);
-        checkGLcall("Setting up materials\n");
+        checkGLcall("Setting up materials");
     }
 
@@ -912,16 +927,16 @@
 
     glMap2f(GL_MAP2_VERTEX_3,
-            0, 1, vtxStride / sizeof(float), info->Width,
-            0, 1, info->Stride * vtxStride / sizeof(float), info->Height,
+            0.0f, 1.0f, vtxStride / sizeof(float), info->Width,
+            0.0f, 1.0f, info->Stride * vtxStride / sizeof(float), info->Height,
             (const GLfloat *)data);
     checkGLcall("glMap2f");
     if(patch->has_texcoords) {
         glMap2f(GL_MAP2_TEXTURE_COORD_4,
-                0, 1, vtxStride / sizeof(float), info->Width,
-                0, 1, info->Stride * vtxStride / sizeof(float), info->Height,
+                0.0f, 1.0f, vtxStride / sizeof(float), info->Width,
+                0.0f, 1.0f, info->Stride * vtxStride / sizeof(float), info->Height,
                 (const GLfloat *)data);
         checkGLcall("glMap2f");
     }
-    glMapGrid2f(ceilf(patch->numSegs[0]), 0.0, 1.0, ceilf(patch->numSegs[1]), 0.0, 1.0);
+    glMapGrid2f(ceilf(patch->numSegs[0]), 0.0f, 1.0f, ceilf(patch->numSegs[1]), 0.0f, 1.0f);
     checkGLcall("glMapGrid2f");
 
@@ -931,5 +946,5 @@
 
     glEvalMesh2(GL_FILL, 0, ceilf(patch->numSegs[0]), 0, ceilf(patch->numSegs[1]));
-    checkGLcall("glEvalMesh2\n");
+    checkGLcall("glEvalMesh2");
 
     i = glRenderMode(GL_RENDER);
@@ -965,5 +980,5 @@
         patch->mem[i + 0] =  feedbuffer[j + out_vertex_size * 2 + 2]; /* x, triangle 2 */
         patch->mem[i + 1] =  feedbuffer[j + out_vertex_size * 2 + 3]; /* y, triangle 2 */
-        patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 2 + 4] - 0.5) * 4 * max_z; /* z, triangle 3 */
+        patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 2 + 4] - 0.5f) * 4.0f * max_z; /* z, triangle 3 */
         if(patch->has_normals) {
             patch->mem[i + 3] = feedbuffer[j + out_vertex_size * 2 + 5];
@@ -975,5 +990,5 @@
         patch->mem[i + 0] =  feedbuffer[j + out_vertex_size * 1 + 2]; /* x, triangle 2 */
         patch->mem[i + 1] =  feedbuffer[j + out_vertex_size * 1 + 3]; /* y, triangle 2 */
-        patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 1 + 4] - 0.5) * 4 * max_z; /* z, triangle 2 */
+        patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 1 + 4] - 0.5f) * 4.0f * max_z; /* z, triangle 2 */
         if(patch->has_normals) {
             patch->mem[i + 3] = feedbuffer[j + out_vertex_size * 1 + 5];
@@ -985,5 +1000,5 @@
         patch->mem[i + 0] =  feedbuffer[j + out_vertex_size * 0 + 2]; /* x, triangle 1 */
         patch->mem[i + 1] =  feedbuffer[j + out_vertex_size * 0 + 3]; /* y, triangle 1 */
-        patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 0 + 4] - 0.5) * 4 * max_z; /* z, triangle 1 */
+        patch->mem[i + 2] = (feedbuffer[j + out_vertex_size * 0 + 4] - 0.5f) * 4.0f * max_z; /* z, triangle 1 */
         if(patch->has_normals) {
             patch->mem[i + 3] = feedbuffer[j + out_vertex_size * 0 + 5];
@@ -996,16 +1011,16 @@
     if(patch->has_normals) {
         /* Now do the same with reverse light directions */
-        static const GLfloat x[] = {-1,  0,  0, 0};
-        static const GLfloat y[] = { 0, -1,  0, 0};
-        static const GLfloat z[] = { 0,  0, -1, 0};
+        static const GLfloat x[] = {-1.0f,  0.0f,  0.0f, 0.0f};
+        static const GLfloat y[] = { 0.0f, -1.0f,  0.0f, 0.0f};
+        static const GLfloat z[] = { 0.0f,  0.0f, -1.0f, 0.0f};
         glLightfv(GL_LIGHT0, GL_POSITION, x);
         glLightfv(GL_LIGHT1, GL_POSITION, y);
         glLightfv(GL_LIGHT2, GL_POSITION, z);
-        checkGLcall("Setting up reverse light directions\n");
+        checkGLcall("Setting up reverse light directions");
 
         glRenderMode(GL_FEEDBACK);
         checkGLcall("glRenderMode(GL_FEEDBACK)");
         glEvalMesh2(GL_FILL, 0, ceilf(patch->numSegs[0]), 0, ceilf(patch->numSegs[1]));
-        checkGLcall("glEvalMesh2\n");
+        checkGLcall("glEvalMesh2");
         i = glRenderMode(GL_RENDER);
         checkGLcall("glRenderMode(GL_RENDER)");
@@ -1021,27 +1036,27 @@
                 continue;
             }
-            if(patch->mem[i + 3] == 0.0)
+            if(patch->mem[i + 3] == 0.0f)
                 patch->mem[i + 3] = -feedbuffer[j + out_vertex_size * 2 + 5];
-            if(patch->mem[i + 4] == 0.0)
+            if(patch->mem[i + 4] == 0.0f)
                 patch->mem[i + 4] = -feedbuffer[j + out_vertex_size * 2 + 6];
-            if(patch->mem[i + 5] == 0.0)
+            if(patch->mem[i + 5] == 0.0f)
                 patch->mem[i + 5] = -feedbuffer[j + out_vertex_size * 2 + 7];
             normalize_normal(patch->mem + i + 3);
             i += d3d_out_vertex_size;
 
-            if(patch->mem[i + 3] == 0.0)
+            if(patch->mem[i + 3] == 0.0f)
                 patch->mem[i + 3] = -feedbuffer[j + out_vertex_size * 1 + 5];
-            if(patch->mem[i + 4] == 0.0)
+            if(patch->mem[i + 4] == 0.0f)
                 patch->mem[i + 4] = -feedbuffer[j + out_vertex_size * 1 + 6];
-            if(patch->mem[i + 5] == 0.0)
+            if(patch->mem[i + 5] == 0.0f)
                 patch->mem[i + 5] = -feedbuffer[j + out_vertex_size * 1 + 7];
             normalize_normal(patch->mem + i + 3);
             i += d3d_out_vertex_size;
 
-            if(patch->mem[i + 3] == 0.0)
+            if(patch->mem[i + 3] == 0.0f)
                 patch->mem[i + 3] = -feedbuffer[j + out_vertex_size * 0 + 5];
-            if(patch->mem[i + 4] == 0.0)
+            if(patch->mem[i + 4] == 0.0f)
                 patch->mem[i + 4] = -feedbuffer[j + out_vertex_size * 0 + 6];
-            if(patch->mem[i + 5] == 0.0)
+            if(patch->mem[i + 5] == 0.0f)
                 patch->mem[i + 5] = -feedbuffer[j + out_vertex_size * 0 + 7];
             normalize_normal(patch->mem + i + 3);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/gl_compat.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/gl_compat.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/gl_compat.c	(revision 21731)
@@ -143,5 +143,5 @@
 static void (WINE_GLAPI *old_multitex_glGetFloatv) (GLenum pname, GLfloat* params) = NULL;
 static void WINE_GLAPI wine_glGetFloatv(GLenum pname, GLfloat* params) {
-    if(pname == GL_ACTIVE_TEXTURE) *params = 0.0;
+    if (pname == GL_ACTIVE_TEXTURE) *params = 0.0f;
     else old_multitex_glGetFloatv(pname, params);
 }
@@ -285,7 +285,7 @@
 
         i = (ctx->fogend - ctx->fog_coord_value) / (ctx->fogend - ctx->fogstart);
-        c[0] = i * c[0] + (1.0 - i) * ctx->fogcolor[0];
-        c[1] = i * c[1] + (1.0 - i) * ctx->fogcolor[1];
-        c[2] = i * c[2] + (1.0 - i) * ctx->fogcolor[2];
+        c[0] = i * c[0] + (1.0f - i) * ctx->fogcolor[0];
+        c[1] = i * c[1] + (1.0f - i) * ctx->fogcolor[1];
+        c[2] = i * c[2] + (1.0f - i) * ctx->fogcolor[2];
 
         old_fogcoord_glColor4f(c[0], c[1], c[2], c[3]);
@@ -301,9 +301,9 @@
 
 static void WINE_GLAPI wine_glVertex3f(GLfloat x, GLfloat y, GLfloat z) {
-    wine_glVertex4f(x, y, z, 1.0);
+    wine_glVertex4f(x, y, z, 1.0f);
 }
 
 static void WINE_GLAPI wine_glVertex3fv(const GLfloat *pos) {
-    wine_glVertex4f(pos[0], pos[1], pos[2], 1.0);
+    wine_glVertex4f(pos[0], pos[1], pos[2], 1.0f);
 }
 
@@ -322,13 +322,13 @@
 
 static void WINE_GLAPI wine_glColor3f(GLfloat r, GLfloat g, GLfloat b) {
-    wine_glColor4f(r, g, b, 1.0);
+    wine_glColor4f(r, g, b, 1.0f);
 }
 
 static void WINE_GLAPI wine_glColor3fv(const GLfloat *c) {
-    wine_glColor4f(c[0], c[1], c[2], 1.0);
+    wine_glColor4f(c[0], c[1], c[2], 1.0f);
 }
 
 static void WINE_GLAPI wine_glColor4ub(GLubyte r, GLubyte g, GLubyte b, GLubyte a) {
-    wine_glColor4f(r / 255.0, g / 255.0, b / 255.0, a / 255.0);
+    wine_glColor4f(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
 }
 
@@ -353,5 +353,6 @@
 
 #define GLINFO_LOCATION (*gl_info)
-void add_gl_compat_wrappers(WineD3D_GL_Info *gl_info) {
+void add_gl_compat_wrappers(struct wined3d_gl_info *gl_info)
+{
     if(!GL_SUPPORT(ARB_MULTITEXTURE)) {
         TRACE("Applying GL_ARB_multitexture emulation hooks\n");
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/glsl_shader.c	(revision 21731)
@@ -93,4 +93,5 @@
 /* GLSL shader private data */
 struct shader_glsl_priv {
+    struct wined3d_shader_buffer shader_buffer;
     struct wine_rb_tree program_lookup;
     struct glsl_shader_prog_link *glsl_program;
@@ -113,5 +114,5 @@
     GLint                       puniformI_locations[MAX_CONST_I];
     GLint                       posFixup_location;
-    GLint                       np2Fixup_location[MAX_FRAGMENT_SAMPLERS];
+    GLint                       np2Fixup_location;
     GLint                       bumpenvmat_location[MAX_TEXTURES];
     GLint                       luminancescale_location[MAX_TEXTURES];
@@ -124,4 +125,5 @@
     struct ps_compile_args      ps_args;
     UINT                        constant_version;
+    const struct ps_np2fixup_info *np2Fixup_info;
 };
 
@@ -136,4 +138,5 @@
     const struct vs_compile_args    *cur_vs_args;
     const struct ps_compile_args    *cur_ps_args;
+    struct ps_np2fixup_info         *cur_np2fixup_info;
 };
 
@@ -141,4 +144,5 @@
 {
     struct ps_compile_args          args;
+    struct ps_np2fixup_info         np2fixup;
     GLhandleARB                     prgId;
 };
@@ -183,5 +187,5 @@
 /** Prints the GLSL info log which will contain error messages if they exist */
 /* GL locking is done by the caller */
-static void print_glsl_info_log(const WineD3D_GL_Info *gl_info, GLhandleARB obj)
+static void print_glsl_info_log(const struct wined3d_gl_info *gl_info, GLhandleARB obj)
 {
     int infologLength = 0;
@@ -199,8 +203,6 @@
         "Vertex shader(s) linked, no fragment shader(s) defined.",          /* fglrx, no \n   */
         "Fragment shader was successfully compiled to run on hardware.\n"
-        "WARNING: 0:2: extension 'GL_ARB_draw_buffers' is not supported",
         "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 */
-        "WARNING: 0:2: extension 'GL_ARB_draw_buffers' is not supported\n"  /* MacOS ati      */
     };
 
@@ -250,5 +252,6 @@
  */
 /* GL locking is done by the caller */
-static void shader_glsl_load_psamplers(const WineD3D_GL_Info *gl_info, DWORD *tex_unit_map, GLhandleARB programId)
+static void shader_glsl_load_psamplers(const struct wined3d_gl_info *gl_info,
+        DWORD *tex_unit_map, GLhandleARB programId)
 {
     GLint name_loc;
@@ -274,5 +277,6 @@
 
 /* GL locking is done by the caller */
-static void shader_glsl_load_vsamplers(const WineD3D_GL_Info *gl_info, DWORD *tex_unit_map, GLhandleARB programId)
+static void shader_glsl_load_vsamplers(const struct wined3d_gl_info *gl_info,
+        DWORD *tex_unit_map, GLhandleARB programId)
 {
     GLint name_loc;
@@ -298,5 +302,5 @@
 
 /* GL locking is done by the caller */
-static inline void walk_constant_heap(const WineD3D_GL_Info *gl_info, const float *constants,
+static inline void walk_constant_heap(const struct wined3d_gl_info *gl_info, const float *constants,
         const GLint *constant_locations, const struct constant_heap *heap, unsigned char *stack, DWORD version)
 {
@@ -360,5 +364,5 @@
 
 /* GL locking is done by the caller */
-static inline void apply_clamped_constant(const WineD3D_GL_Info *gl_info, GLint location, const GLfloat *data)
+static inline void apply_clamped_constant(const struct wined3d_gl_info *gl_info, GLint location, const GLfloat *data)
 {
     GLfloat clamped_constant[4];
@@ -366,8 +370,8 @@
     if (location == -1) return;
 
-    clamped_constant[0] = data[0] < -1.0f ? -1.0f : data[0] > 1.0 ? 1.0 : data[0];
-    clamped_constant[1] = data[1] < -1.0f ? -1.0f : data[1] > 1.0 ? 1.0 : data[1];
-    clamped_constant[2] = data[2] < -1.0f ? -1.0f : data[2] > 1.0 ? 1.0 : data[2];
-    clamped_constant[3] = data[3] < -1.0f ? -1.0f : data[3] > 1.0 ? 1.0 : data[3];
+    clamped_constant[0] = data[0] < -1.0f ? -1.0f : data[0] > 1.0f ? 1.0f : data[0];
+    clamped_constant[1] = data[1] < -1.0f ? -1.0f : data[1] > 1.0f ? 1.0f : data[1];
+    clamped_constant[2] = data[2] < -1.0f ? -1.0f : data[2] > 1.0f ? 1.0f : data[2];
+    clamped_constant[3] = data[3] < -1.0f ? -1.0f : data[3] > 1.0f ? 1.0f : data[3];
 
     GL_EXTCALL(glUniform4fvARB(location, 1, clamped_constant));
@@ -375,5 +379,5 @@
 
 /* GL locking is done by the caller */
-static inline void walk_constant_heap_clamped(const WineD3D_GL_Info *gl_info, const float *constants,
+static inline void walk_constant_heap_clamped(const struct wined3d_gl_info *gl_info, const float *constants,
         const GLint *constant_locations, const struct constant_heap *heap, unsigned char *stack, DWORD version)
 {
@@ -436,5 +440,5 @@
 /* Loads floating point constants (aka uniforms) into the currently set GLSL program. */
 /* GL locking is done by the caller */
-static void shader_glsl_load_constantsF(IWineD3DBaseShaderImpl *This, const WineD3D_GL_Info *gl_info,
+static void shader_glsl_load_constantsF(IWineD3DBaseShaderImpl *This, const struct wined3d_gl_info *gl_info,
         const float *constants, const GLint *constant_locations, const struct constant_heap *heap,
         unsigned char *stack, UINT version)
@@ -467,5 +471,5 @@
 /* Loads integer constants (aka uniforms) into the currently set GLSL program. */
 /* GL locking is done by the caller */
-static void shader_glsl_load_constantsI(IWineD3DBaseShaderImpl *This, const WineD3D_GL_Info *gl_info,
+static void shader_glsl_load_constantsI(IWineD3DBaseShaderImpl *This, const struct wined3d_gl_info *gl_info,
         const GLint locations[MAX_CONST_I], const int *constants, WORD constants_set)
 {
@@ -504,5 +508,5 @@
 /* Loads boolean constants (aka uniforms) into the currently set GLSL program. */
 /* GL locking is done by the caller */
-static void shader_glsl_load_constantsB(IWineD3DBaseShaderImpl *This, const WineD3D_GL_Info *gl_info,
+static void shader_glsl_load_constantsB(IWineD3DBaseShaderImpl *This, const struct wined3d_gl_info *gl_info,
         GLhandleARB programId, const BOOL *constants, WORD constants_set)
 {
@@ -510,7 +514,27 @@
     unsigned int i;
     char tmp_name[8];
-    char is_pshader = shader_is_pshader_version(This->baseShader.reg_maps.shader_version.type);
-    const char* prefix = is_pshader? "PB":"VB";
+    const char *prefix;
     struct list* ptr;
+
+    switch (This->baseShader.reg_maps.shader_version.type)
+    {
+        case WINED3D_SHADER_TYPE_VERTEX:
+            prefix = "VB";
+            break;
+
+        case WINED3D_SHADER_TYPE_GEOMETRY:
+            prefix = "GB";
+            break;
+
+        case WINED3D_SHADER_TYPE_PIXEL:
+            prefix = "PB";
+            break;
+
+        default:
+            FIXME("Unknown shader type %#x.\n",
+                    This->baseShader.reg_maps.shader_version.type);
+            prefix = "UB";
+            break;
+    }
 
     /* TODO: Benchmark and see if it would be beneficial to store the
@@ -581,22 +605,29 @@
     }
 
-    if (prog->ps_args.np2_fixup) {
+    if (prog->ps_args.np2_fixup && -1 != prog->np2Fixup_location) {
+        const struct wined3d_gl_info *gl_info = &deviceImpl->adapter->gl_info;
+        const IWineD3DStateBlockImpl* stateBlock = (const IWineD3DStateBlockImpl*) deviceImpl->stateBlock;
         UINT i;
         UINT fixup = prog->ps_args.np2_fixup;
-        const WineD3D_GL_Info* gl_info = &deviceImpl->adapter->gl_info;
-        const IWineD3DStateBlockImpl* stateBlock = (const IWineD3DStateBlockImpl*) deviceImpl->stateBlock;
+        GLfloat np2fixup_constants[4 * MAX_FRAGMENT_SAMPLERS];
 
         for (i = 0; fixup; fixup >>= 1, ++i) {
-            if (-1 != prog->np2Fixup_location[i]) {
-                const IWineD3DBaseTextureImpl* const tex = (const IWineD3DBaseTextureImpl*) stateBlock->textures[i];
-                if (!tex) {
-                    FIXME("Nonexistent texture is flagged for NP2 texcoord fixup\n");
-                    continue;
-                } else {
-                    const float tex_dim[2] = {tex->baseTexture.pow2Matrix[0], tex->baseTexture.pow2Matrix[5]};
-                    GL_EXTCALL(glUniform2fvARB(prog->np2Fixup_location[i], 1, tex_dim));
-                }
-            }
-        }
+            const unsigned char idx = prog->np2Fixup_info->idx[i];
+            const IWineD3DBaseTextureImpl* const tex = (const IWineD3DBaseTextureImpl*) stateBlock->textures[i];
+            GLfloat* tex_dim = &np2fixup_constants[(idx >> 1) * 4];
+
+            if (!tex) {
+                FIXME("Nonexistent texture is flagged for NP2 texcoord fixup\n");
+                continue;
+            }
+
+            if (idx % 2) {
+                tex_dim[2] = tex->baseTexture.pow2Matrix[0]; tex_dim[3] = tex->baseTexture.pow2Matrix[5];
+            } else {
+                tex_dim[0] = tex->baseTexture.pow2Matrix[0]; tex_dim[1] = tex->baseTexture.pow2Matrix[5];
+            }
+        }
+
+        GL_EXTCALL(glUniform4fvARB(prog->np2Fixup_location, prog->np2Fixup_info->num_consts, np2fixup_constants));
     }
 }
@@ -614,5 +645,5 @@
     struct shader_glsl_priv *priv = deviceImpl->shader_priv;
     IWineD3DStateBlockImpl* stateBlock = deviceImpl->stateBlock;
-    const WineD3D_GL_Info *gl_info = &deviceImpl->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &deviceImpl->adapter->gl_info;
 
     GLhandleARB programId;
@@ -667,9 +698,10 @@
          * It can't be 0 for a valid texbem instruction.
          */
-        for(i = 0; i < ((IWineD3DPixelShaderImpl *) pshader)->numbumpenvmatconsts; i++) {
-            IWineD3DPixelShaderImpl *ps = (IWineD3DPixelShaderImpl *) pshader;
-            int stage = ps->luminanceconst[i].texunit;
-
-            const float *data = (const float *)&stateBlock->textureState[(int)ps->bumpenvmatconst[i].texunit][WINED3DTSS_BUMPENVMAT00];
+        for(i = 0; i < MAX_TEXTURES; i++) {
+            const float *data;
+
+            if(prog->bumpenvmat_location[i] == -1) continue;
+
+            data = (const float *)&stateBlock->textureState[i][WINED3DTSS_BUMPENVMAT00];
             GL_EXTCALL(glUniformMatrix2fvARB(prog->bumpenvmat_location[i], 1, 0, data));
             checkGLcall("glUniformMatrix2fvARB");
@@ -678,7 +710,7 @@
              * is set too, so we can check that in the needsbumpmat check
              */
-            if(ps->baseShader.reg_maps.luminanceparams[stage]) {
-                const GLfloat *scale = (const GLfloat *)&stateBlock->textureState[stage][WINED3DTSS_BUMPENVLSCALE];
-                const GLfloat *offset = (const GLfloat *)&stateBlock->textureState[stage][WINED3DTSS_BUMPENVLOFFSET];
+            if(prog->luminancescale_location[i] != -1) {
+                const GLfloat *scale = (const GLfloat *)&stateBlock->textureState[i][WINED3DTSS_BUMPENVLSCALE];
+                const GLfloat *offset = (const GLfloat *)&stateBlock->textureState[i][WINED3DTSS_BUMPENVLOFFSET];
 
                 GL_EXTCALL(glUniform1fvARB(prog->luminancescale_location[i], 1, scale));
@@ -692,10 +724,10 @@
             float correction_params[4];
             if(deviceImpl->render_offscreen) {
-                correction_params[0] = 0.0;
-                correction_params[1] = 1.0;
+                correction_params[0] = 0.0f;
+                correction_params[1] = 1.0f;
             } else {
                 /* position is window relative, not viewport relative */
                 correction_params[0] = ((IWineD3DSurfaceImpl *) deviceImpl->render_targets[0])->currentDesc.Height;
-                correction_params[1] = -1.0;
+                correction_params[1] = -1.0f;
             }
             GL_EXTCALL(glUniform4fvARB(prog->ycorrection_location, 1, correction_params));
@@ -770,12 +802,12 @@
 }
 
-static int vec4_varyings(DWORD shader_major, const WineD3D_GL_Info *gl_info)
-{
-    int ret = GL_LIMITS(glsl_varyings) / 4;
+static unsigned int vec4_varyings(DWORD shader_major, const struct wined3d_gl_info *gl_info)
+{
+    unsigned int ret = GL_LIMITS(glsl_varyings) / 4;
     /* 4.0 shaders do not write clip coords because d3d10 does not support user clipplanes */
     if(shader_major > 3) return ret;
 
     /* 3.0 shaders may need an extra varying for the clip coord on some cards(mostly dx10 ones) */
-    if(gl_info->glsl_clip_varying) ret -= 1;
+    if (gl_info->quirks & WINED3D_QUIRK_GLSL_CLIP_VARYING) ret -= 1;
     return ret;
 }
@@ -783,9 +815,10 @@
 /** Generate the variable & register declarations for the GLSL output target */
 static void shader_generate_glsl_declarations(IWineD3DBaseShader *iface, const shader_reg_maps *reg_maps,
-        SHADER_BUFFER *buffer, const WineD3D_GL_Info *gl_info,
-        const struct ps_compile_args *ps_args)
+        struct wined3d_shader_buffer *buffer, const struct wined3d_gl_info *gl_info,
+        struct shader_glsl_ctx_priv *ctx_priv)
 {
     IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device;
+    const struct ps_compile_args *ps_args = ctx_priv->cur_ps_args;
     unsigned int i, extra_constants_needed = 0;
     const local_constant *lconst;
@@ -874,7 +907,4 @@
         }
     } else {
-        IWineD3DPixelShaderImpl *ps_impl = (IWineD3DPixelShaderImpl *) This;
-
-        ps_impl->numbumpenvmatconsts = 0;
         for(i = 0; i < (sizeof(reg_maps->bumpmat) / sizeof(reg_maps->bumpmat[0])); i++) {
             if(!reg_maps->bumpmat[i]) {
@@ -882,25 +912,21 @@
             }
 
-            ps_impl->bumpenvmatconst[(int) ps_impl->numbumpenvmatconsts].texunit = i;
             shader_addline(buffer, "uniform mat2 bumpenvmat%d;\n", i);
 
             if(reg_maps->luminanceparams) {
-                ps_impl->luminanceconst[(int) ps_impl->numbumpenvmatconsts].texunit = i;
                 shader_addline(buffer, "uniform float luminancescale%d;\n", i);
                 shader_addline(buffer, "uniform float luminanceoffset%d;\n", i);
                 extra_constants_needed++;
-            } else {
-                ps_impl->luminanceconst[(int) ps_impl->numbumpenvmatconsts].texunit = -1;
             }
 
             extra_constants_needed++;
-            ps_impl->numbumpenvmatconsts++;
-        }
-
-        if(ps_args->srgb_correction) {
-            shader_addline(buffer, "const vec4 srgb_mul_low = vec4(%f, %f, %f, %f);\n",
-                            srgb_mul_low, srgb_mul_low, srgb_mul_low, srgb_mul_low);
-            shader_addline(buffer, "const vec4 srgb_comparison = vec4(%f, %f, %f, %f);\n",
-                            srgb_cmp, srgb_cmp, srgb_cmp, srgb_cmp);
+        }
+
+        if (ps_args->srgb_correction)
+        {
+            shader_addline(buffer, "const vec4 srgb_const0 = vec4(%.8e, %.8e, %.8e, %.8e);\n",
+                    srgb_pow, srgb_mul_high, srgb_sub_high, srgb_mul_low);
+            shader_addline(buffer, "const vec4 srgb_const1 = vec4(%.8e, 0.0, 0.0, 0.0);\n",
+                    srgb_cmp);
         }
         if(reg_maps->vpos || reg_maps->usesdsy) {
@@ -915,6 +941,6 @@
                 FIXME("Cannot find a free uniform for vpos correction params\n");
                 shader_addline(buffer, "const vec4 ycorrection = vec4(%f, %f, 0.0, 0.0);\n",
-                               device->render_offscreen ? 0.0 : ((IWineD3DSurfaceImpl *) device->render_targets[0])->currentDesc.Height,
-                               device->render_offscreen ? 1.0 : -1.0);
+                        device->render_offscreen ? 0.0f : ((IWineD3DSurfaceImpl *)device->render_targets[0])->currentDesc.Height,
+                        device->render_offscreen ? 1.0f : -1.0f);
             }
             shader_addline(buffer, "vec4 vpos;\n");
@@ -938,13 +964,4 @@
                         shader_addline(buffer, "uniform sampler2D %csampler%u;\n", prefix, i);
                     }
-
-                    if (pshader && ps_args->np2_fixup & (1 << i))
-                    {
-                        /* NP2/RECT textures in OpenGL use texcoords in the range [0,width]x[0,height]
-                         * while D3D has them in the (normalized) [0,1]x[0,1] range.
-                         * samplerNP2Fixup stores texture dimensions and is updated through
-                         * shader_glsl_load_np2fixup_constants when the sampler changes. */
-                        shader_addline(buffer, "uniform vec2 %csamplerNP2Fixup%u;\n", prefix, i);
-                    }
                     break;
                 case WINED3DSTT_CUBE:
@@ -961,5 +978,36 @@
         }
     }
-    
+
+    /* Declare uniforms for NP2 texcoord fixup:
+     * 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. */
+    if (pshader && ps_args->np2_fixup) {
+
+        struct ps_np2fixup_info* const fixup = ctx_priv->cur_np2fixup_info;
+        UINT cur = 0;
+
+        /* NP2/RECT textures in OpenGL use texcoords in the range [0,width]x[0,height]
+         * while D3D has them in the (normalized) [0,1]x[0,1] range.
+         * samplerNP2Fixup stores texture dimensions and is updated through
+         * shader_glsl_load_np2fixup_constants when the sampler changes. */
+
+        for (i = 0; i < This->baseShader.limits.sampler; ++i) {
+            if (reg_maps->sampler_type[i]) {
+                if (!(ps_args->np2_fixup & (1 << i))) continue;
+
+                if (WINED3DSTT_2D != reg_maps->sampler_type[i]) {
+                    FIXME("Non-2D texture is flagged for NP2 texcoord fixup.\n");
+                    continue;
+                }
+
+                fixup->idx[i] = cur++;
+            }
+        }
+
+        fixup->num_consts = (cur + 1) >> 1;
+        shader_addline(buffer, "uniform vec4 %csamplerNP2Fixup[%u];\n", prefix, fixup->num_consts);
+    }
+
     /* Declare address variables */
     for (i = 0; i < This->baseShader.limits.address; i++) {
@@ -1147,5 +1195,5 @@
     IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
-    const WineD3D_GL_Info* gl_info = &deviceImpl->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &deviceImpl->adapter->gl_info;
     char pshader = shader_is_pshader_version(This->baseShader.reg_maps.shader_version.type);
 
@@ -1172,5 +1220,5 @@
             {
                 DWORD idx = ((IWineD3DPixelShaderImpl *)This)->input_reg_map[reg->idx];
-                DWORD in_count = vec4_varyings(This->baseShader.reg_maps.shader_version.major, gl_info);
+                unsigned int in_count = vec4_varyings(This->baseShader.reg_maps.shader_version.major, gl_info);
 
                 if (reg->rel_addr)
@@ -1275,7 +1323,5 @@
                 WARN("Write to render target %u, only %d supported\n", reg->idx, GL_LIMITS(buffers));
 
-            if (GL_SUPPORT(ARB_DRAW_BUFFERS)) sprintf(register_name, "gl_FragData[%u]", reg->idx);
-            /* On older cards with GLSL support like the GeforceFX there's only one buffer. */
-            else sprintf(register_name, "gl_FragColor");
+            sprintf(register_name, "gl_FragData[%u]", reg->idx);
             break;
 
@@ -1322,11 +1368,11 @@
             {
                 case WINED3D_IMMCONST_FLOAT:
-                    sprintf(register_name, "%.8e", *(float *)reg->immconst_data);
+                    sprintf(register_name, "%.8e", *(const float *)reg->immconst_data);
                     break;
 
                 case WINED3D_IMMCONST_FLOAT4:
                     sprintf(register_name, "vec4(%.8e, %.8e, %.8e, %.8e)",
-                            *(float *)&reg->immconst_data[0], *(float *)&reg->immconst_data[1],
-                            *(float *)&reg->immconst_data[2], *(float *)&reg->immconst_data[3]);
+                            *(const float *)&reg->immconst_data[0], *(const float *)&reg->immconst_data[1],
+                            *(const float *)&reg->immconst_data[2], *(const float *)&reg->immconst_data[3]);
                     break;
 
@@ -1442,5 +1488,5 @@
 
 /* Append the destination part of the instruction to the buffer, return the effective write mask */
-static DWORD shader_glsl_append_dst_ext(SHADER_BUFFER *buffer,
+static DWORD shader_glsl_append_dst_ext(struct wined3d_shader_buffer *buffer,
         const struct wined3d_shader_instruction *ins, const struct wined3d_shader_dst_param *dst)
 {
@@ -1455,5 +1501,5 @@
 
 /* Append the destination part of the instruction to the buffer, return the effective write mask */
-static DWORD shader_glsl_append_dst(SHADER_BUFFER *buffer, const struct wined3d_shader_instruction *ins)
+static DWORD shader_glsl_append_dst(struct wined3d_shader_buffer *buffer, const struct wined3d_shader_instruction *ins)
 {
     return shader_glsl_append_dst_ext(buffer, ins, &ins->dst[0]);
@@ -1697,5 +1743,5 @@
     if (shader_is_pshader_version(ins->ctx->reg_maps->shader_version.type))
     {
-        struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
+        const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
         fixup = priv->cur_ps_args->color_fixup[sampler];
         sampler_base = "Psampler";
@@ -1725,5 +1771,9 @@
     } else {
         if (np2_fixup) {
-            shader_addline(ins->ctx->buffer, " * PsamplerNP2Fixup%u)%s);\n", sampler, dst_swizzle);
+            const struct shader_glsl_ctx_priv *priv = ins->ctx->backend_data;
+            const unsigned char idx = priv->cur_np2fixup_info->idx[sampler];
+
+            shader_addline(ins->ctx->buffer, " * PsamplerNP2Fixup[%u].%s)%s);\n", idx >> 1,
+                           (idx % 2) ? "zw" : "xy", dst_swizzle);
         } else if(dx && dy) {
             shader_addline(ins->ctx->buffer, ", %s, %s)%s);\n", dx, dy, dst_swizzle);
@@ -1747,5 +1797,5 @@
 static void shader_glsl_arith(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
@@ -1774,5 +1824,5 @@
 static void shader_glsl_mov(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     glsl_src_param_t src0_param;
     DWORD write_mask;
@@ -1812,5 +1862,5 @@
 static void shader_glsl_dot(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
@@ -1860,5 +1910,5 @@
 static void shader_glsl_pow(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
@@ -1884,5 +1934,5 @@
 static void shader_glsl_log(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     glsl_src_param_t src0_param;
     DWORD dst_write_mask;
@@ -1904,5 +1954,5 @@
 static void shader_glsl_map2gl(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     glsl_src_param_t src_param;
     const char *instruction;
@@ -2008,5 +2058,5 @@
 static void shader_glsl_rsq(const struct wined3d_shader_instruction *ins)
 {
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     glsl_src_param_t src_param;
     DWORD write_mask;
@@ -2586,4 +2636,11 @@
 }
 
+static void shader_glsl_ret(const struct wined3d_shader_instruction *ins)
+{
+    /* No-op. The closing } is written when a new function is started, and at the end of the shader. This
+     * function only suppresses the unhandled instruction warning
+     */
+}
+
 /*********************************************
  * Pixel Shader Specific Code begins here
@@ -2682,5 +2739,5 @@
     IWineD3DBaseShaderImpl *This = (IWineD3DBaseShaderImpl *)ins->ctx->shader;
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
-    const WineD3D_GL_Info* gl_info = &deviceImpl->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &deviceImpl->adapter->gl_info;
     glsl_sample_function_t sample_function;
     glsl_src_param_t coord_param, dx_param, dy_param;
@@ -2746,5 +2803,5 @@
 {
     /* FIXME: Make this work for more than just 2D textures */
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     DWORD write_mask = shader_glsl_append_dst(ins->ctx->buffer, ins);
 
@@ -2896,5 +2953,5 @@
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
     DWORD reg = ins->dst[0].reg.idx;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     glsl_src_param_t src0_param;
 
@@ -2910,5 +2967,5 @@
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
     DWORD reg = ins->dst[0].reg.idx;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     SHADER_PARSE_STATE* current_state = &shader->baseShader.parse_state;
     glsl_src_param_t src0_param;
@@ -2923,5 +2980,5 @@
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
     DWORD reg = ins->dst[0].reg.idx;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     glsl_src_param_t src0_param;
     WINED3DSAMPLER_TEXTURE_TYPE sampler_type = ins->ctx->reg_maps->sampler_type[reg];
@@ -2989,5 +3046,5 @@
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     SHADER_PARSE_STATE* current_state = &shader->baseShader.parse_state;
     WINED3DSAMPLER_TEXTURE_TYPE stype = ins->ctx->reg_maps->sampler_type[reg];
@@ -3018,5 +3075,5 @@
     IWineD3DPixelShaderImpl *shader = (IWineD3DPixelShaderImpl *)ins->ctx->shader;
     DWORD reg = ins->dst[0].reg.idx;
-    SHADER_BUFFER *buffer = ins->ctx->buffer;
+    struct wined3d_shader_buffer *buffer = ins->ctx->buffer;
     SHADER_PARSE_STATE* current_state = &shader->baseShader.parse_state;
     glsl_src_param_t src0_param;
@@ -3216,5 +3273,5 @@
 }
 
-static void pshader_glsl_input_pack(IWineD3DPixelShader *iface, SHADER_BUFFER *buffer,
+static void pshader_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)
@@ -3300,5 +3357,5 @@
 
 /* GL locking is done by the caller */
-static void delete_glsl_program_entry(struct shader_glsl_priv *priv, const WineD3D_GL_Info *gl_info,
+static void delete_glsl_program_entry(struct shader_glsl_priv *priv, const struct wined3d_gl_info *gl_info,
         struct glsl_shader_prog_link *entry)
 {
@@ -3319,5 +3376,5 @@
 }
 
-static void handle_ps3_input(SHADER_BUFFER *buffer, const WineD3D_GL_Info *gl_info, const DWORD *map,
+static void handle_ps3_input(struct wined3d_shader_buffer *buffer, const struct wined3d_gl_info *gl_info, const DWORD *map,
         const struct wined3d_shader_signature_element *input_signature, const struct shader_reg_maps *reg_maps_in,
         const struct wined3d_shader_signature_element *output_signature, const struct shader_reg_maps *reg_maps_out)
@@ -3328,5 +3385,5 @@
     DWORD *set;
     DWORD in_idx;
-    DWORD in_count = vec4_varyings(3, gl_info);
+    unsigned int in_count = vec4_varyings(3, gl_info);
     char reg_mask[6], reg_mask_out[6];
     char destination[50];
@@ -3440,5 +3497,6 @@
      */
     for(i = 0; i < in_count + 2; i++) {
-        if(set[i] != WINED3DSP_WRITEMASK_ALL) {
+        if (set[i] && set[i] != WINED3DSP_WRITEMASK_ALL)
+        {
             unsigned int size = 0;
             memset(reg_mask, 0, sizeof(reg_mask));
@@ -3480,6 +3538,6 @@
 
 /* GL locking is done by the caller */
-static GLhandleARB generate_param_reorder_function(IWineD3DVertexShader *vertexshader,
-        IWineD3DPixelShader *pixelshader, const WineD3D_GL_Info *gl_info)
+static GLhandleARB generate_param_reorder_function(struct wined3d_shader_buffer *buffer,
+        IWineD3DVertexShader *vertexshader, IWineD3DPixelShader *pixelshader, const struct wined3d_gl_info *gl_info)
 {
     GLhandleARB ret = 0;
@@ -3490,5 +3548,4 @@
     DWORD ps_major = ps ? ps->baseShader.reg_maps.shader_version.major : 0;
     unsigned int i;
-    SHADER_BUFFER buffer;
     const char *semantic_name;
     UINT semantic_idx;
@@ -3496,7 +3553,7 @@
     const struct wined3d_shader_signature_element *output_signature;
 
-    shader_buffer_init(&buffer);
-
-    shader_addline(&buffer, "#version 120\n");
+    shader_buffer_clear(buffer);
+
+    shader_addline(buffer, "#version 120\n");
 
     if(vs_major < 3 && ps_major < 3) {
@@ -3505,16 +3562,17 @@
          */
         device = (IWineD3DDeviceImpl *) vs->baseShader.device;
-        if((GLINFO_LOCATION).set_texcoord_w && ps_major == 0 && vs_major > 0 &&
-            !device->frag_pipe->ffp_proj_control) {
-            shader_addline(&buffer, "void order_ps_input() {\n");
+        if (((GLINFO_LOCATION).quirks & WINED3D_QUIRK_SET_TEXCOORD_W)
+                && ps_major == 0 && vs_major > 0 && !device->frag_pipe->ffp_proj_control)
+        {
+            shader_addline(buffer, "void order_ps_input() {\n");
             for(i = 0; i < min(8, MAX_REG_TEXCRD); i++) {
                 if(vs->baseShader.reg_maps.texcoord_mask[i] != 0 &&
                    vs->baseShader.reg_maps.texcoord_mask[i] != WINED3DSP_WRITEMASK_ALL) {
-                    shader_addline(&buffer, "gl_TexCoord[%u].w = 1.0;\n", i);
+                    shader_addline(buffer, "gl_TexCoord[%u].w = 1.0;\n", i);
                 }
             }
-            shader_addline(&buffer, "}\n");
+            shader_addline(buffer, "}\n");
         } else {
-            shader_addline(&buffer, "void order_ps_input() { /* do nothing */ }\n");
+            shader_addline(buffer, "void order_ps_input() { /* do nothing */ }\n");
         }
     } else if(ps_major < 3 && vs_major >= 3) {
@@ -3524,5 +3582,5 @@
         output_signature = vs->output_signature;
 
-        shader_addline(&buffer, "void order_ps_input(in vec4 OUT[%u]) {\n", MAX_REG_OUTPUT);
+        shader_addline(buffer, "void order_ps_input(in vec4 OUT[%u]) {\n", MAX_REG_OUTPUT);
         for (i = 0; map; map >>= 1, ++i)
         {
@@ -3539,11 +3597,11 @@
             {
                 if (semantic_idx == 0)
-                    shader_addline(&buffer, "gl_FrontColor%s = OUT[%u]%s;\n", reg_mask, i, reg_mask);
+                    shader_addline(buffer, "gl_FrontColor%s = OUT[%u]%s;\n", reg_mask, i, reg_mask);
                 else if (semantic_idx == 1)
-                    shader_addline(&buffer, "gl_FrontSecondaryColor%s = OUT[%u]%s;\n", reg_mask, i, reg_mask);
+                    shader_addline(buffer, "gl_FrontSecondaryColor%s = OUT[%u]%s;\n", reg_mask, i, reg_mask);
             }
             else if (shader_match_semantic(semantic_name, WINED3DDECLUSAGE_POSITION))
             {
-                shader_addline(&buffer, "gl_Position%s = OUT[%u]%s;\n", reg_mask, i, reg_mask);
+                shader_addline(buffer, "gl_Position%s = OUT[%u]%s;\n", reg_mask, i, reg_mask);
             }
             else if (shader_match_semantic(semantic_name, WINED3DDECLUSAGE_TEXCOORD))
@@ -3551,22 +3609,23 @@
                 if (semantic_idx < 8)
                 {
-                    if (!(GLINFO_LOCATION).set_texcoord_w || ps_major > 0) write_mask |= WINED3DSP_WRITEMASK_3;
-
-                    shader_addline(&buffer, "gl_TexCoord[%u]%s = OUT[%u]%s;\n",
+                    if (!((GLINFO_LOCATION).quirks & WINED3D_QUIRK_SET_TEXCOORD_W) || ps_major > 0)
+                        write_mask |= WINED3DSP_WRITEMASK_3;
+
+                    shader_addline(buffer, "gl_TexCoord[%u]%s = OUT[%u]%s;\n",
                             semantic_idx, reg_mask, i, reg_mask);
                     if (!(write_mask & WINED3DSP_WRITEMASK_3))
-                        shader_addline(&buffer, "gl_TexCoord[%u].w = 1.0;\n", semantic_idx);
+                        shader_addline(buffer, "gl_TexCoord[%u].w = 1.0;\n", semantic_idx);
                 }
             }
             else if (shader_match_semantic(semantic_name, WINED3DDECLUSAGE_PSIZE))
             {
-                shader_addline(&buffer, "gl_PointSize = OUT[%u].x;\n", i);
+                shader_addline(buffer, "gl_PointSize = OUT[%u].x;\n", i);
             }
             else if (shader_match_semantic(semantic_name, WINED3DDECLUSAGE_FOG))
             {
-                shader_addline(&buffer, "gl_FogFragCoord = OUT[%u].%c;\n", i, reg_mask[1]);
-            }
-        }
-        shader_addline(&buffer, "}\n");
+                shader_addline(buffer, "gl_FogFragCoord = OUT[%u].%c;\n", i, reg_mask[1]);
+            }
+        }
+        shader_addline(buffer, "}\n");
 
     } else if(ps_major >= 3 && vs_major >= 3) {
@@ -3576,6 +3635,6 @@
 
         /* This one is tricky: a 3.0 pixel shader reads from a 3.0 vertex shader */
-        shader_addline(&buffer, "varying vec4 IN[%u];\n", vec4_varyings(3, gl_info));
-        shader_addline(&buffer, "void order_ps_input(in vec4 OUT[%u]) {\n", MAX_REG_OUTPUT);
+        shader_addline(buffer, "varying vec4 IN[%u];\n", vec4_varyings(3, gl_info));
+        shader_addline(buffer, "void order_ps_input(in vec4 OUT[%u]) {\n", MAX_REG_OUTPUT);
 
         /* First, sort out position and point size. Those are not passed to the pixel shader */
@@ -3589,27 +3648,27 @@
             if (shader_match_semantic(semantic_name, WINED3DDECLUSAGE_POSITION))
             {
-                shader_addline(&buffer, "gl_Position%s = OUT[%u]%s;\n", reg_mask, i, reg_mask);
+                shader_addline(buffer, "gl_Position%s = OUT[%u]%s;\n", reg_mask, i, reg_mask);
             }
             else if (shader_match_semantic(semantic_name, WINED3DDECLUSAGE_PSIZE))
             {
-                shader_addline(&buffer, "gl_PointSize = OUT[%u].x;\n", i);
+                shader_addline(buffer, "gl_PointSize = OUT[%u].x;\n", i);
             }
         }
 
         /* Then, fix the pixel shader input */
-        handle_ps3_input(&buffer, gl_info, ps->input_reg_map, ps->input_signature,
+        handle_ps3_input(buffer, gl_info, ps->input_reg_map, ps->input_signature,
                 &ps->baseShader.reg_maps, output_signature, &vs->baseShader.reg_maps);
 
-        shader_addline(&buffer, "}\n");
+        shader_addline(buffer, "}\n");
     } else if(ps_major >= 3 && vs_major < 3) {
-        shader_addline(&buffer, "varying vec4 IN[%u];\n", vec4_varyings(3, gl_info));
-        shader_addline(&buffer, "void order_ps_input() {\n");
+        shader_addline(buffer, "varying vec4 IN[%u];\n", vec4_varyings(3, gl_info));
+        shader_addline(buffer, "void order_ps_input() {\n");
         /* The vertex shader wrote to the builtin varyings. There is no need to figure out position and
          * point size, but we depend on the optimizers kindness to find out that the pixel shader doesn't
          * read gl_TexCoord and gl_ColorX, otherwise we'll run out of varyings
          */
-        handle_ps3_input(&buffer, gl_info, ps->input_reg_map, ps->input_signature,
+        handle_ps3_input(buffer, gl_info, ps->input_reg_map, ps->input_signature,
                 &ps->baseShader.reg_maps, NULL, NULL);
-        shader_addline(&buffer, "}\n");
+        shader_addline(buffer, "}\n");
     } else {
         ERR("Unexpected vertex and pixel shader version condition: vs: %d, ps: %d\n", vs_major, ps_major);
@@ -3618,15 +3677,14 @@
     ret = GL_EXTCALL(glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB));
     checkGLcall("glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB)");
-    GL_EXTCALL(glShaderSourceARB(ret, 1, (const char**)&buffer.buffer, NULL));
-    checkGLcall("glShaderSourceARB(ret, 1, &buffer.buffer, NULL)");
+    GL_EXTCALL(glShaderSourceARB(ret, 1, (const char**)&buffer->buffer, NULL));
+    checkGLcall("glShaderSourceARB(ret, 1, &buffer->buffer, NULL)");
     GL_EXTCALL(glCompileShaderARB(ret));
     checkGLcall("glCompileShaderARB(ret)");
 
-    shader_buffer_free(&buffer);
     return ret;
 }
 
 /* GL locking is done by the caller */
-static void hardcode_local_constants(IWineD3DBaseShaderImpl *shader, const WineD3D_GL_Info *gl_info,
+static void hardcode_local_constants(IWineD3DBaseShaderImpl *shader, const struct wined3d_gl_info *gl_info,
         GLhandleARB programId, char prefix)
 {
@@ -3642,15 +3700,14 @@
         GL_EXTCALL(glUniform4fvARB(tmp_loc, 1, value));
     }
-    checkGLcall("Hardcoding local constants\n");
+    checkGLcall("Hardcoding local constants");
 }
 
 /* GL locking is done by the caller */
-static GLuint shader_glsl_generate_pshader(IWineD3DPixelShaderImpl *This,
-        SHADER_BUFFER *buffer, const struct ps_compile_args *args)
+static GLuint shader_glsl_generate_pshader(IWineD3DPixelShaderImpl *This, struct wined3d_shader_buffer *buffer,
+        const struct ps_compile_args *args, struct ps_np2fixup_info *np2fixup_info)
 {
     const struct shader_reg_maps *reg_maps = &This->baseShader.reg_maps;
     CONST DWORD *function = This->baseShader.function;
-    const char *fragcolor;
-    const WineD3D_GL_Info *gl_info = &((IWineD3DDeviceImpl *)This->baseShader.device)->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &((IWineD3DDeviceImpl *)This->baseShader.device)->adapter->gl_info;
     struct shader_glsl_ctx_priv priv_ctx;
 
@@ -3660,10 +3717,8 @@
     memset(&priv_ctx, 0, sizeof(priv_ctx));
     priv_ctx.cur_ps_args = args;
+    priv_ctx.cur_np2fixup_info = np2fixup_info;
 
     shader_addline(buffer, "#version 120\n");
 
-    if (GL_SUPPORT(ARB_DRAW_BUFFERS)) {
-        shader_addline(buffer, "#extension GL_ARB_draw_buffers : enable\n");
-    }
     if(GL_SUPPORT(ARB_SHADER_TEXTURE_LOD) && reg_maps->usestexldd) {
         shader_addline(buffer, "#extension GL_ARB_shader_texture_lod : enable\n");
@@ -3677,5 +3732,5 @@
 
     /* Base Declarations */
-    shader_generate_glsl_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION, args);
+    shader_generate_glsl_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION, &priv_ctx);
 
     /* Pack 3.0 inputs */
@@ -3692,24 +3747,15 @@
     {
         /* Some older cards like GeforceFX ones don't support multiple buffers, so also not gl_FragData */
-        if(GL_SUPPORT(ARB_DRAW_BUFFERS))
-            shader_addline(buffer, "gl_FragData[0] = R0;\n");
-        else
-            shader_addline(buffer, "gl_FragColor = R0;\n");
-    }
-
-    if(GL_SUPPORT(ARB_DRAW_BUFFERS)) {
-        fragcolor = "gl_FragData[0]";
-    } else {
-        fragcolor = "gl_FragColor";
-    }
-    if(args->srgb_correction) {
-        shader_addline(buffer, "tmp0.xyz = pow(%s.xyz, vec3(%f, %f, %f)) * vec3(%f, %f, %f) - vec3(%f, %f, %f);\n",
-                        fragcolor, srgb_pow, srgb_pow, srgb_pow, srgb_mul_high, srgb_mul_high, srgb_mul_high,
-                        srgb_sub_high, srgb_sub_high, srgb_sub_high);
-        shader_addline(buffer, "tmp1.xyz = %s.xyz * srgb_mul_low.xyz;\n", fragcolor);
-        shader_addline(buffer, "%s.x = %s.x < srgb_comparison.x ? tmp1.x : tmp0.x;\n", fragcolor, fragcolor);
-        shader_addline(buffer, "%s.y = %s.y < srgb_comparison.y ? tmp1.y : tmp0.y;\n", fragcolor, fragcolor);
-        shader_addline(buffer, "%s.z = %s.z < srgb_comparison.z ? tmp1.z : tmp0.z;\n", fragcolor, fragcolor);
-        shader_addline(buffer, "%s = clamp(%s, 0.0, 1.0);\n", fragcolor, fragcolor);
+        shader_addline(buffer, "gl_FragData[0] = R0;\n");
+    }
+
+    if (args->srgb_correction)
+    {
+        shader_addline(buffer, "tmp0.xyz = pow(gl_FragData[0].xyz, vec3(srgb_const0.x));\n");
+        shader_addline(buffer, "tmp0.xyz = tmp0.xyz * vec3(srgb_const0.y) - vec3(srgb_const0.z);\n");
+        shader_addline(buffer, "tmp1.xyz = gl_FragData[0].xyz * vec3(srgb_const0.w);\n");
+        shader_addline(buffer, "bvec3 srgb_compare = lessThan(gl_FragData[0].xyz, vec3(srgb_const1.x));\n");
+        shader_addline(buffer, "gl_FragData[0].xyz = mix(tmp0.xyz, tmp1.xyz, vec3(srgb_compare));\n");
+        shader_addline(buffer, "gl_FragData[0] = clamp(gl_FragData[0], 0.0, 1.0);\n");
     }
     /* Pixel shader < 3.0 do not replace the fog stage.
@@ -3727,5 +3773,5 @@
                 shader_addline(buffer, "float fogend = gl_Fog.end * -fogstart;\n");
                 shader_addline(buffer, "float Fog = clamp(gl_FogFragCoord * fogstart + fogend, 0.0, 1.0);\n");
-                shader_addline(buffer, "%s.xyz = mix(gl_Fog.color.xyz, %s.xyz, Fog);\n", fragcolor, fragcolor);
+                shader_addline(buffer, "gl_FragData[0].xyz = mix(gl_Fog.color.xyz, gl_FragData[0].xyz, Fog);\n");
                 break;
             case FOG_EXP:
@@ -3733,5 +3779,5 @@
                 shader_addline(buffer, "float Fog = exp(-gl_Fog.density * gl_FogFragCoord);\n");
                 shader_addline(buffer, "Fog = clamp(Fog, 0.0, 1.0);\n");
-                shader_addline(buffer, "%s.xyz = mix(gl_Fog.color.xyz, %s.xyz, Fog);\n", fragcolor, fragcolor);
+                shader_addline(buffer, "gl_FragData[0].xyz = mix(gl_Fog.color.xyz, gl_FragData[0].xyz, Fog);\n");
                 break;
             case FOG_EXP2:
@@ -3739,5 +3785,5 @@
                 shader_addline(buffer, "float Fog = exp(-gl_Fog.density * gl_Fog.density * gl_FogFragCoord * gl_FogFragCoord);\n");
                 shader_addline(buffer, "Fog = clamp(Fog, 0.0, 1.0);\n");
-                shader_addline(buffer, "%s.xyz = mix(gl_Fog.color.xyz, %s.xyz, Fog);\n", fragcolor, fragcolor);
+                shader_addline(buffer, "gl_FragData[0].xyz = mix(gl_Fog.color.xyz, gl_FragData[0].xyz, Fog);\n");
                 break;
         }
@@ -3757,9 +3803,9 @@
 /* GL locking is done by the caller */
 static GLuint shader_glsl_generate_vshader(IWineD3DVertexShaderImpl *This,
-        SHADER_BUFFER *buffer, const struct vs_compile_args *args)
+        struct wined3d_shader_buffer *buffer, const struct vs_compile_args *args)
 {
     const struct shader_reg_maps *reg_maps = &This->baseShader.reg_maps;
     CONST DWORD *function = This->baseShader.function;
-    const WineD3D_GL_Info *gl_info = &((IWineD3DDeviceImpl *)This->baseShader.device)->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &((IWineD3DDeviceImpl *)This->baseShader.device)->adapter->gl_info;
     struct shader_glsl_ctx_priv priv_ctx;
 
@@ -3773,5 +3819,5 @@
 
     /* Base Declarations */
-    shader_generate_glsl_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION, NULL);
+    shader_generate_glsl_declarations( (IWineD3DBaseShader*) This, reg_maps, buffer, &GLINFO_LOCATION, &priv_ctx);
 
     /* Base Shader Body */
@@ -3822,11 +3868,12 @@
 }
 
-static GLhandleARB find_glsl_pshader(IWineD3DPixelShaderImpl *shader, const struct ps_compile_args *args)
+static GLhandleARB find_glsl_pshader(struct wined3d_shader_buffer *buffer, IWineD3DPixelShaderImpl *shader,
+        const struct ps_compile_args *args, const struct ps_np2fixup_info **np2fixup_info)
 {
     UINT i;
     DWORD new_size;
     struct glsl_ps_compiled_shader *new_array;
-    SHADER_BUFFER buffer;
-    struct glsl_pshader_private *shader_data;
+    struct glsl_pshader_private    *shader_data;
+    struct ps_np2fixup_info        *np2fixup = NULL;
     GLhandleARB ret;
 
@@ -3842,9 +3889,10 @@
     for(i = 0; i < shader_data->num_gl_shaders; i++) {
         if(memcmp(&shader_data->gl_shaders[i].args, args, sizeof(*args)) == 0) {
+            if(args->np2_fixup) *np2fixup_info = &shader_data->gl_shaders[i].np2fixup;
             return shader_data->gl_shaders[i].prgId;
         }
     }
 
-    TRACE("No matching GL shader found, compiling a new shader\n");
+    TRACE("No matching GL shader found for shader %p, compiling a new shader.\n", shader);
     if(shader_data->shader_array_size == shader_data->num_gl_shaders) {
         if (shader_data->num_gl_shaders)
@@ -3868,11 +3916,14 @@
     shader_data->gl_shaders[shader_data->num_gl_shaders].args = *args;
 
+    memset(&shader_data->gl_shaders[shader_data->num_gl_shaders].np2fixup, 0, sizeof(struct ps_np2fixup_info));
+    if (args->np2_fixup) np2fixup = &shader_data->gl_shaders[shader_data->num_gl_shaders].np2fixup;
+
     pixelshader_update_samplers(&shader->baseShader.reg_maps,
             ((IWineD3DDeviceImpl *)shader->baseShader.device)->stateBlock->textures);
 
-    shader_buffer_init(&buffer);
-    ret = shader_glsl_generate_pshader(shader, &buffer, args);
-    shader_buffer_free(&buffer);
+    shader_buffer_clear(buffer);
+    ret = shader_glsl_generate_pshader(shader, buffer, args, np2fixup);
     shader_data->gl_shaders[shader_data->num_gl_shaders++].prgId = ret;
+    *np2fixup_info = np2fixup;
 
     return ret;
@@ -3885,5 +3936,6 @@
 }
 
-static GLhandleARB find_glsl_vshader(IWineD3DVertexShaderImpl *shader, const struct vs_compile_args *args)
+static GLhandleARB find_glsl_vshader(struct wined3d_shader_buffer *buffer, IWineD3DVertexShaderImpl *shader,
+        const struct vs_compile_args *args)
 {
     UINT i;
@@ -3891,5 +3943,4 @@
     struct glsl_vs_compiled_shader *new_array;
     DWORD use_map = ((IWineD3DDeviceImpl *)shader->baseShader.device)->strided_streams.use_map;
-    SHADER_BUFFER buffer;
     struct glsl_vshader_private *shader_data;
     GLhandleARB ret;
@@ -3910,5 +3961,5 @@
     }
 
-    TRACE("No matching GL shader found, compiling a new shader\n");
+    TRACE("No matching GL shader found for shader %p, compiling a new shader.\n", shader);
 
     if(shader_data->shader_array_size == shader_data->num_gl_shaders) {
@@ -3933,7 +3984,6 @@
     shader_data->gl_shaders[shader_data->num_gl_shaders].args = *args;
 
-    shader_buffer_init(&buffer);
-    ret = shader_glsl_generate_vshader(shader, &buffer, args);
-    shader_buffer_free(&buffer);
+    shader_buffer_clear(buffer);
+    ret = shader_glsl_generate_vshader(shader, buffer, args);
     shader_data->gl_shaders[shader_data->num_gl_shaders++].prgId = ret;
 
@@ -3954,5 +4004,5 @@
     IWineD3DDeviceImpl *This               = (IWineD3DDeviceImpl *)iface;
     struct shader_glsl_priv *priv          = This->shader_priv;
-    const WineD3D_GL_Info *gl_info         = &This->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info  = &This->adapter->gl_info;
     IWineD3DPixelShader  *pshader          = use_ps ? This->stateBlock->pixelShader : NULL;
     IWineD3DVertexShader *vshader          = use_vs ? This->stateBlock->vertexShader : NULL;
@@ -3962,20 +4012,10 @@
     unsigned int i;
     char glsl_name[8];
-    GLhandleARB vshader_id, pshader_id;
     struct ps_compile_args ps_compile_args;
     struct vs_compile_args vs_compile_args;
 
-    if(use_vs) {
-        find_vs_compile_args((IWineD3DVertexShaderImpl*)This->stateBlock->vertexShader, This->stateBlock, &vs_compile_args);
-    } else {
-        /* FIXME: Do we really have to spend CPU cycles to generate a few zeroed bytes? */
-        memset(&vs_compile_args, 0, sizeof(vs_compile_args));
-    }
-    if(use_ps) {
-        find_ps_compile_args((IWineD3DPixelShaderImpl*)This->stateBlock->pixelShader, This->stateBlock, &ps_compile_args);
-    } else {
-        /* FIXME: Do we really have to spend CPU cycles to generate a few zeroed bytes? */
-        memset(&ps_compile_args, 0, sizeof(ps_compile_args));
-    }
+    if (vshader) find_vs_compile_args((IWineD3DVertexShaderImpl *)vshader, This->stateBlock, &vs_compile_args);
+    if (pshader) find_ps_compile_args((IWineD3DPixelShaderImpl *)pshader, This->stateBlock, &ps_compile_args);
+
     entry = get_glsl_program_entry(priv, vshader, pshader, &vs_compile_args, &ps_compile_args);
     if (entry) {
@@ -3996,4 +4036,5 @@
     entry->ps_args = ps_compile_args;
     entry->constant_version = 0;
+    entry->np2Fixup_info = NULL;
     /* Add the hash table entry */
     add_glsl_program_entry(priv, entry);
@@ -4002,16 +4043,13 @@
     priv->glsl_program = entry;
 
-    if(use_vs) {
-        vshader_id = find_glsl_vshader((IWineD3DVertexShaderImpl *) vshader, &vs_compile_args);
-    } else {
-        vshader_id = 0;
-    }
-
     /* Attach GLSL vshader */
-    if (vshader_id) {
+    if (vshader)
+    {
+        GLhandleARB vshader_id = find_glsl_vshader(&priv->shader_buffer, (IWineD3DVertexShaderImpl *)vshader,
+                &vs_compile_args);
         WORD map = ((IWineD3DBaseShaderImpl *)vshader)->baseShader.reg_maps.input_registers;
         char tmp_name[10];
 
-        reorder_shader_id = generate_param_reorder_function(vshader, pshader, gl_info);
+        reorder_shader_id = generate_param_reorder_function(&priv->shader_buffer, vshader, pshader, gl_info);
         TRACE("Attaching GLSL shader object %u to program %u\n", reorder_shader_id, programId);
         GL_EXTCALL(glAttachObjectARB(programId, reorder_shader_id));
@@ -4047,12 +4085,9 @@
     }
 
-    if(use_ps) {
-        pshader_id = find_glsl_pshader((IWineD3DPixelShaderImpl *) pshader, &ps_compile_args);
-    } else {
-        pshader_id = 0;
-    }
-
     /* Attach GLSL pshader */
-    if (pshader_id) {
+    if (pshader)
+    {
+        GLhandleARB pshader_id = find_glsl_pshader(&priv->shader_buffer, (IWineD3DPixelShaderImpl *)pshader,
+                &ps_compile_args, &entry->np2Fixup_info);
         TRACE("Attaching GLSL shader object %u to program %u\n", pshader_id, programId);
         GL_EXTCALL(glAttachObjectARB(programId, pshader_id));
@@ -4087,23 +4122,20 @@
 
     if(pshader) {
-        for(i = 0; i < ((IWineD3DPixelShaderImpl*)pshader)->numbumpenvmatconsts; i++) {
-            char name[32];
-            sprintf(name, "bumpenvmat%d", ((IWineD3DPixelShaderImpl*)pshader)->bumpenvmatconst[i].texunit);
+        char name[32];
+
+        for(i = 0; i < MAX_TEXTURES; i++) {
+            sprintf(name, "bumpenvmat%u", i);
             entry->bumpenvmat_location[i] = GL_EXTCALL(glGetUniformLocationARB(programId, name));
-            sprintf(name, "luminancescale%d", ((IWineD3DPixelShaderImpl*)pshader)->luminanceconst[i].texunit);
+            sprintf(name, "luminancescale%u", i);
             entry->luminancescale_location[i] = GL_EXTCALL(glGetUniformLocationARB(programId, name));
-            sprintf(name, "luminanceoffset%d", ((IWineD3DPixelShaderImpl*)pshader)->luminanceconst[i].texunit);
+            sprintf(name, "luminanceoffset%u", i);
             entry->luminanceoffset_location[i] = GL_EXTCALL(glGetUniformLocationARB(programId, name));
         }
-    }
-
-    if (use_ps && ps_compile_args.np2_fixup) {
-        char name[32];
-        for (i = 0; i < MAX_FRAGMENT_SAMPLERS; ++i) {
-            if (ps_compile_args.np2_fixup & (1 << i)) {
-                sprintf(name, "PsamplerNP2Fixup%u", i);
-                entry->np2Fixup_location[i] = GL_EXTCALL(glGetUniformLocationARB(programId, name));
+
+        if (ps_compile_args.np2_fixup) {
+            if (entry->np2Fixup_info) {
+                entry->np2Fixup_location = GL_EXTCALL(glGetUniformLocationARB(programId, "PsamplerNP2Fixup"));
             } else {
-                entry->np2Fixup_location[i] = -1;
+                FIXME("NP2 texcoord fixup needed for this pixelshader, but no fixup uniform found.\n");
             }
         }
@@ -4136,12 +4168,6 @@
      * won't change.
      */
-    if(vshader_id) {
-        /* Load vertex shader samplers */
-        shader_glsl_load_vsamplers(gl_info, This->texUnitMap, programId);
-    }
-    if(pshader_id) {
-        /* Load pixel shader samplers */
-        shader_glsl_load_psamplers(gl_info, This->texUnitMap, programId);
-    }
+    if (vshader) shader_glsl_load_vsamplers(gl_info, This->texUnitMap, programId);
+    if (pshader) shader_glsl_load_psamplers(gl_info, This->texUnitMap, programId);
 
     /* If the local constants do not have to be loaded with the environment constants,
@@ -4158,5 +4184,5 @@
 
 /* GL locking is done by the caller */
-static GLhandleARB create_glsl_blt_shader(const WineD3D_GL_Info *gl_info, enum tex_types tex_type)
+static GLhandleARB create_glsl_blt_shader(const struct wined3d_gl_info *gl_info, enum tex_types tex_type)
 {
     GLhandleARB program_id;
@@ -4236,5 +4262,5 @@
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     struct shader_glsl_priv *priv = This->shader_priv;
-    const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     GLhandleARB program_id = 0;
     GLenum old_vertex_color_clamp, current_vertex_color_clamp;
@@ -4260,4 +4286,11 @@
     GL_EXTCALL(glUseProgramObjectARB(program_id));
     checkGLcall("glUseProgramObjectARB");
+
+    /* In case that NP2 texcoord fixup data is found for the selected program, trigger a reload of the
+     * constants. This has to be done because it can't be guaranteed that sampler() (from state.c) is
+     * called between selecting the shader and using it, which results in wrong fixup for some frames. */
+    if (priv->glsl_program && priv->glsl_program->np2Fixup_info) {
+        This->shader_backend->shader_load_np2fixup_constants(iface, usePS, useVS);
+    }
 }
 
@@ -4265,5 +4298,5 @@
 static void shader_glsl_select_depth_blt(IWineD3DDevice *iface, enum tex_types tex_type) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     struct shader_glsl_priv *priv = This->shader_priv;
     GLhandleARB *blt_program = &priv->depth_blt_program[tex_type];
@@ -4283,5 +4316,5 @@
 static void shader_glsl_deselect_depth_blt(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     struct shader_glsl_priv *priv = This->shader_priv;
     GLhandleARB program_id;
@@ -4299,5 +4332,5 @@
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)This->baseShader.device;
     struct shader_glsl_priv *priv = device->shader_priv;
-    const WineD3D_GL_Info *gl_info = &device->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     IWineD3DPixelShaderImpl *ps = NULL;
     IWineD3DVertexShaderImpl *vs = NULL;
@@ -4409,9 +4442,8 @@
     else if (k->pshader < prog->pshader) return -1;
 
-    cmp = memcmp(&k->vs_args, &prog->vs_args, sizeof(prog->vs_args));
-    if (cmp) return cmp;
-
-    cmp = memcmp(&k->ps_args, &prog->ps_args, sizeof(prog->ps_args));
-    return cmp;
+    if (k->vshader && (cmp = memcmp(&k->vs_args, &prog->vs_args, sizeof(prog->vs_args)))) return cmp;
+    if (k->pshader && (cmp = memcmp(&k->ps_args, &prog->ps_args, sizeof(prog->ps_args)))) return cmp;
+
+    return 0;
 }
 
@@ -4450,14 +4482,19 @@
 static HRESULT shader_glsl_alloc(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     struct shader_glsl_priv *priv = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct shader_glsl_priv));
     SIZE_T stack_size = wined3d_log2i(max(GL_LIMITS(vshader_constantsF), GL_LIMITS(pshader_constantsF))) + 1;
 
+    if (!shader_buffer_init(&priv->shader_buffer))
+    {
+        ERR("Failed to initialize shader buffer.\n");
+        goto fail;
+    }
+
     priv->stack = HeapAlloc(GetProcessHeap(), 0, stack_size * sizeof(*priv->stack));
     if (!priv->stack)
     {
         ERR("Failed to allocate memory.\n");
-        HeapFree(GetProcessHeap(), 0, priv);
-        return E_OUTOFMEMORY;
+        goto fail;
     }
 
@@ -4465,7 +4502,5 @@
     {
         ERR("Failed to initialize vertex shader constant heap\n");
-        HeapFree(GetProcessHeap(), 0, priv->stack);
-        HeapFree(GetProcessHeap(), 0, priv);
-        return E_OUTOFMEMORY;
+        goto fail;
     }
 
@@ -4473,8 +4508,5 @@
     {
         ERR("Failed to initialize pixel shader constant heap\n");
-        constant_heap_free(&priv->vconst_heap);
-        HeapFree(GetProcessHeap(), 0, priv->stack);
-        HeapFree(GetProcessHeap(), 0, priv);
-        return E_OUTOFMEMORY;
+        goto fail;
     }
 
@@ -4482,9 +4514,5 @@
     {
         ERR("Failed to initialize rbtree.\n");
-        constant_heap_free(&priv->pconst_heap);
-        constant_heap_free(&priv->vconst_heap);
-        HeapFree(GetProcessHeap(), 0, priv->stack);
-        HeapFree(GetProcessHeap(), 0, priv);
-        return E_OUTOFMEMORY;
+        goto fail;
     }
 
@@ -4493,9 +4521,18 @@
     This->shader_priv = priv;
     return WINED3D_OK;
-}
-
+
+fail:
+    constant_heap_free(&priv->pconst_heap);
+    constant_heap_free(&priv->vconst_heap);
+    HeapFree(GetProcessHeap(), 0, priv->stack);
+    shader_buffer_free(&priv->shader_buffer);
+    HeapFree(GetProcessHeap(), 0, priv);
+    return E_OUTOFMEMORY;
+}
+
+/* Context activation is done by the caller. */
 static void shader_glsl_free(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    const WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &This->adapter->gl_info;
     struct shader_glsl_priv *priv = This->shader_priv;
     int i;
@@ -4525,5 +4562,6 @@
 }
 
-static void shader_glsl_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct shader_caps *pCaps)
+static void shader_glsl_get_caps(WINED3DDEVTYPE devtype,
+        const struct wined3d_gl_info *gl_info, struct shader_caps *pCaps)
 {
     /* Nvidia Geforce6/7 or Ati R4xx/R5xx cards with GLSL support, support VS 3.0 but older Nvidia/Ati
@@ -4652,5 +4690,5 @@
     /* WINED3DSIH_RCP           */ shader_glsl_rcp,
     /* WINED3DSIH_REP           */ shader_glsl_rep,
-    /* WINED3DSIH_RET           */ NULL,
+    /* WINED3DSIH_RET           */ shader_glsl_ret,
     /* WINED3DSIH_RSQ           */ shader_glsl_rsq,
     /* WINED3DSIH_SETP          */ NULL,
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/nvidia_texture_shader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/nvidia_texture_shader.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/nvidia_texture_shader.c	(revision 21731)
@@ -459,6 +459,5 @@
     }
 
-    checkGLcall("set_tex_op_nvrc()\n");
-
+    checkGLcall("set_tex_op_nvrc()");
 }
 
@@ -606,6 +605,8 @@
 
 #define GLINFO_LOCATION (*gl_info)
+/* Context activation is done by the caller. */
 static void nvrc_enable(IWineD3DDevice *iface, BOOL enable) { }
 
+/* Context activation is done by the caller. */
 static void nvts_enable(IWineD3DDevice *iface, BOOL enable) {
     ENTER_GL();
@@ -620,5 +621,6 @@
 }
 
-static void nvrc_fragment_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct fragment_caps *pCaps)
+static void nvrc_fragment_get_caps(WINED3DDEVTYPE devtype,
+        const struct wined3d_gl_info *gl_info, struct fragment_caps *pCaps)
 {
     pCaps->TextureOpCaps =  WINED3DTEXOPCAPS_ADD                        |
@@ -675,4 +677,5 @@
 
 static HRESULT nvrc_fragment_alloc(IWineD3DDevice *iface) { return WINED3D_OK; }
+/* Context activation is done by the caller. */
 static void nvrc_fragment_free(IWineD3DDevice *iface) {}
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/palette.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/palette.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/palette.c	(revision 21731)
@@ -33,5 +33,4 @@
 #include "wine/debug.h"
 
-#include <assert.h>
 #include <string.h>
 
@@ -89,5 +88,7 @@
         case WINEDDPCAPS_4BIT: return 16;
         case WINEDDPCAPS_8BIT: return 256;
-        default: assert(0); return 256;
+        default:
+            FIXME("Unhandled size bits %#x.\n", dwFlags & SIZE_BITS);
+            return 256;
     }
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/pixelshader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/pixelshader.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/pixelshader.c	(revision 21731)
@@ -179,8 +179,4 @@
         case WINED3D_SHADER_VERSION(2,1):
             This->baseShader.limits.temporary = 32;
-        case WINED3D_SHADER_VERSION(4,0):
-            FIXME("Using 3.0 limits for 4.0 shader\n");
-            /* Fall through */
-
             This->baseShader.limits.constant_float = 32;
             This->baseShader.limits.constant_int = 16;
@@ -191,4 +187,8 @@
             This->baseShader.limits.label = 16;
             break;
+
+        case WINED3D_SHADER_VERSION(4,0):
+            FIXME("Using 3.0 limits for 4.0 shader\n");
+            /* Fall through */
 
         case WINED3D_SHADER_VERSION(3,0):
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/query.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/query.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/query.c	(revision 21731)
@@ -71,36 +71,56 @@
     ref = InterlockedDecrement(&This->ref);
     if (ref == 0) {
-        ENTER_GL();
         /* Queries are specific to the GL context that created them. Not
          * deleting the query will obviously leak it, but that's still better
          * than potentially deleting a different query with the same id in this
          * context, and (still) leaking the actual query. */
-        if(This->type == WINED3DQUERYTYPE_EVENT) {
-            if (((WineQueryEventData *)This->extendedData)->ctx != This->wineD3DDevice->activeContext
-                    || This->wineD3DDevice->activeContext->tid != GetCurrentThreadId())
+        if (This->type == WINED3DQUERYTYPE_EVENT)
+        {
+            WineQueryEventData *query_data = (WineQueryEventData *)This->extendedData;
+
+            if (query_data->ctx->tid != GetCurrentThreadId())
             {
-                FIXME("Query was created in a different context, skipping deletion\n");
-            }
-            else if(GL_SUPPORT(APPLE_FENCE))
-            {
-                GL_EXTCALL(glDeleteFencesAPPLE(1, &((WineQueryEventData *)(This->extendedData))->fenceId));
-                checkGLcall("glDeleteFencesAPPLE");
-            } else if(GL_SUPPORT(NV_FENCE)) {
-                GL_EXTCALL(glDeleteFencesNV(1, &((WineQueryEventData *)(This->extendedData))->fenceId));
-                checkGLcall("glDeleteFencesNV");
-            }
-        } else if(This->type == WINED3DQUERYTYPE_OCCLUSION && GL_SUPPORT(ARB_OCCLUSION_QUERY)) {
-            if (((WineQueryOcclusionData *)This->extendedData)->ctx != This->wineD3DDevice->activeContext
-                    || This->wineD3DDevice->activeContext->tid != GetCurrentThreadId())
-            {
-                FIXME("Query was created in a different context, skipping deletion\n");
+                FIXME("Query was created in a different thread, skipping deletion.\n");
             }
             else
             {
-                GL_EXTCALL(glDeleteQueriesARB(1, &((WineQueryOcclusionData *)(This->extendedData))->queryId));
+                ActivateContext(This->wineD3DDevice, query_data->ctx->surface, CTXUSAGE_RESOURCELOAD);
+
+                ENTER_GL();
+
+                if (GL_SUPPORT(APPLE_FENCE))
+                {
+                    GL_EXTCALL(glDeleteFencesAPPLE(1, &query_data->fenceId));
+                    checkGLcall("glDeleteFencesAPPLE");
+                }
+                else if (GL_SUPPORT(NV_FENCE))
+                {
+                    GL_EXTCALL(glDeleteFencesNV(1, &query_data->fenceId));
+                    checkGLcall("glDeleteFencesNV");
+                }
+
+                LEAVE_GL();
+            }
+        }
+        else if (This->type == WINED3DQUERYTYPE_OCCLUSION && GL_SUPPORT(ARB_OCCLUSION_QUERY))
+        {
+            WineQueryOcclusionData *query_data = (WineQueryOcclusionData *)This->extendedData;
+
+            if (query_data->ctx->tid != GetCurrentThreadId())
+            {
+                FIXME("Query was created in a different thread, skipping deletion.\n");
+            }
+            else
+            {
+                ActivateContext(This->wineD3DDevice, query_data->ctx->surface, CTXUSAGE_RESOURCELOAD);
+
+                ENTER_GL();
+
+                GL_EXTCALL(glDeleteQueriesARB(1, &query_data->queryId));
                 checkGLcall("glDeleteQueriesARB");
-            }
-        }
-        LEAVE_GL();
+
+                LEAVE_GL();
+            }
+        }
 
         HeapFree(GetProcessHeap(), 0, This->extendedData);
@@ -295,5 +315,5 @@
 static HRESULT  WINAPI IWineD3DOcclusionQueryImpl_GetData(IWineD3DQuery* iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
-    GLuint queryId = ((WineQueryOcclusionData *)This->extendedData)->queryId;
+    WineQueryOcclusionData *query_data = (WineQueryOcclusionData *)This->extendedData;
     DWORD* data = pData;
     GLuint available;
@@ -325,16 +345,17 @@
     }
 
-    if (((WineQueryOcclusionData *)This->extendedData)->ctx != This->wineD3DDevice->activeContext
-            || This->wineD3DDevice->activeContext->tid != GetCurrentThreadId())
-    {
-        FIXME("%p Wrong context, returning 1.\n", This);
+    if (query_data->ctx->tid != GetCurrentThreadId())
+    {
+        FIXME("%p Wrong thread, returning 1.\n", This);
         *data = 1;
         return S_OK;
     }
 
+    ActivateContext(This->wineD3DDevice, query_data->ctx->surface, CTXUSAGE_RESOURCELOAD);
+
     ENTER_GL();
 
-    GL_EXTCALL(glGetQueryObjectuivARB(queryId, GL_QUERY_RESULT_AVAILABLE_ARB, &available));
-    checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)\n");
+    GL_EXTCALL(glGetQueryObjectuivARB(query_data->queryId, GL_QUERY_RESULT_AVAILABLE_ARB, &available));
+    checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT_AVAILABLE)");
     TRACE("(%p) : available %d.\n", This, available);
 
@@ -343,6 +364,6 @@
         if (data)
         {
-            GL_EXTCALL(glGetQueryObjectuivARB(queryId, GL_QUERY_RESULT_ARB, &samples));
-            checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)\n");
+            GL_EXTCALL(glGetQueryObjectuivARB(query_data->queryId, GL_QUERY_RESULT_ARB, &samples));
+            checkGLcall("glGetQueryObjectuivARB(GL_QUERY_RESULT)");
             TRACE("(%p) : Returning %d samples.\n", This, samples);
             *data = samples;
@@ -363,28 +384,40 @@
     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *) iface;
     BOOL* data = pData;
-    WineD3DContext *ctx;
+    WineQueryEventData *query_data = (WineQueryEventData *)This->extendedData;
+
     TRACE("(%p) : type D3DQUERY_EVENT, pData %p, dwSize %#x, dwGetDataFlags %#x\n", This, pData, dwSize, dwGetDataFlags);
 
-    ctx = ((WineQueryEventData *)This->extendedData)->ctx;
-    if(pData == NULL || dwSize == 0) {
+    if (!pData || !dwSize) return S_OK;
+
+    if (query_data->ctx->tid != GetCurrentThreadId())
+    {
+        /* See comment in IWineD3DQuery::Issue, event query codeblock */
+        FIXME("Wrong thread, reporting GPU idle.\n");
+        *data = TRUE;
+
         return S_OK;
-    } if(ctx != This->wineD3DDevice->activeContext || ctx->tid != GetCurrentThreadId()) {
-        /* See comment in IWineD3DQuery::Issue, event query codeblock */
-        FIXME("Query context not active, reporting GPU idle\n");
-        *data = TRUE;
-    } else if(GL_SUPPORT(APPLE_FENCE)) {
-        ENTER_GL();
-        *data = GL_EXTCALL(glTestFenceAPPLE(((WineQueryEventData *)This->extendedData)->fenceId));
+    }
+
+    ActivateContext(This->wineD3DDevice, query_data->ctx->surface, CTXUSAGE_RESOURCELOAD);
+
+    ENTER_GL();
+
+    if (GL_SUPPORT(APPLE_FENCE))
+    {
+        *data = GL_EXTCALL(glTestFenceAPPLE(query_data->fenceId));
         checkGLcall("glTestFenceAPPLE");
-        LEAVE_GL();
-    } else if(GL_SUPPORT(NV_FENCE)) {
-        ENTER_GL();
-        *data = GL_EXTCALL(glTestFenceNV(((WineQueryEventData *)This->extendedData)->fenceId));
+    }
+    else if (GL_SUPPORT(NV_FENCE))
+    {
+        *data = GL_EXTCALL(glTestFenceNV(query_data->fenceId));
         checkGLcall("glTestFenceNV");
-        LEAVE_GL();
-    } else {
+    }
+    else
+    {
         WARN("(%p): reporting GPU idle\n", This);
         *data = TRUE;
     }
+
+    LEAVE_GL();
 
     return S_OK;
@@ -464,7 +497,10 @@
 
     TRACE("(%p) : dwIssueFlags %#x, type D3DQUERY_EVENT\n", This, dwIssueFlags);
-    if (dwIssueFlags & WINED3DISSUE_END) {
-        WineD3DContext *ctx = ((WineQueryEventData *)This->extendedData)->ctx;
-        if(ctx != This->wineD3DDevice->activeContext || ctx->tid != GetCurrentThreadId()) {
+    if (dwIssueFlags & WINED3DISSUE_END)
+    {
+        WineQueryEventData *query_data = (WineQueryEventData *)This->extendedData;
+
+        if (query_data->ctx->tid != GetCurrentThreadId())
+        {
             /* GL fences can be used only from the context that created them,
              * so if a different context is active, don't bother setting the query. The penalty
@@ -475,13 +511,22 @@
              */
             WARN("Query context not active\n");
-        } else if(GL_SUPPORT(APPLE_FENCE)) {
+        }
+        else
+        {
+            ActivateContext(This->wineD3DDevice, query_data->ctx->surface, CTXUSAGE_RESOURCELOAD);
+
             ENTER_GL();
-            GL_EXTCALL(glSetFenceAPPLE(((WineQueryEventData *)This->extendedData)->fenceId));
-            checkGLcall("glSetFenceAPPLE");
-            LEAVE_GL();
-        } else if (GL_SUPPORT(NV_FENCE)) {
-            ENTER_GL();
-            GL_EXTCALL(glSetFenceNV(((WineQueryEventData *)This->extendedData)->fenceId, GL_ALL_COMPLETED_NV));
-            checkGLcall("glSetFenceNV");
+
+            if (GL_SUPPORT(APPLE_FENCE))
+            {
+                GL_EXTCALL(glSetFenceAPPLE(query_data->fenceId));
+                checkGLcall("glSetFenceAPPLE");
+            }
+            else if (GL_SUPPORT(NV_FENCE))
+            {
+                GL_EXTCALL(glSetFenceNV(query_data->fenceId, GL_ALL_COMPLETED_NV));
+                checkGLcall("glSetFenceNV");
+            }
+
             LEAVE_GL();
         }
@@ -503,10 +548,16 @@
     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
 
-    if (GL_SUPPORT(ARB_OCCLUSION_QUERY)) {
-        WineD3DContext *ctx = ((WineQueryOcclusionData *)This->extendedData)->ctx;
-
-        if(ctx != This->wineD3DDevice->activeContext || ctx->tid != GetCurrentThreadId()) {
-            FIXME("Not the owning context, can't start query\n");
-        } else {
+    if (GL_SUPPORT(ARB_OCCLUSION_QUERY))
+    {
+        WineQueryOcclusionData *query_data = (WineQueryOcclusionData *)This->extendedData;
+
+        if (query_data->ctx->tid != GetCurrentThreadId())
+        {
+            FIXME("Not the owning context, can't start query.\n");
+        }
+        else
+        {
+            ActivateContext(This->wineD3DDevice, query_data->ctx->surface, CTXUSAGE_RESOURCELOAD);
+
             ENTER_GL();
             /* This is allowed according to msdn and our tests. Reset the query and restart */
@@ -517,5 +568,5 @@
                 }
 
-                GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, ((WineQueryOcclusionData *)This->extendedData)->queryId));
+                GL_EXTCALL(glBeginQueryARB(GL_SAMPLES_PASSED_ARB, query_data->queryId));
                 checkGLcall("glBeginQuery()");
             }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm1.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm1.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm1.c	(revision 21731)
@@ -359,4 +359,5 @@
             | ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
     src->reg.idx = param & WINED3DSP_REGNUM_MASK;
+    src->reg.array_idx = ~0U;
     src->swizzle = (param & WINED3DSP_SWIZZLE_MASK) >> WINED3DSP_SWIZZLE_SHIFT;
     src->modifiers = (param & WINED3DSP_SRCMOD_MASK) >> WINED3DSP_SRCMOD_SHIFT;
@@ -370,4 +371,5 @@
             | ((param & WINED3DSP_REGTYPE_MASK2) >> WINED3DSP_REGTYPE_SHIFT2);
     dst->reg.idx = param & WINED3DSP_REGNUM_MASK;
+    dst->reg.array_idx = ~0U;
     dst->write_mask = (param & WINED3D_SM1_WRITEMASK_MASK) >> WINED3D_SM1_WRITEMASK_SHIFT;
     dst->modifiers = (param & WINED3DSP_DSTMOD_MASK) >> WINED3DSP_DSTMOD_SHIFT;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm4.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm4.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/shader_sm4.c	(revision 21731)
@@ -38,4 +38,7 @@
 #define WINED3D_SM4_OPCODE_MASK                 0xff
 
+#define WINED3D_SM4_REGISTER_ORDER_SHIFT        20
+#define WINED3D_SM4_REGISTER_ORDER_MASK         (0x3 << WINED3D_SM4_REGISTER_ORDER_SHIFT)
+
 #define WINED3D_SM4_REGISTER_TYPE_SHIFT         12
 #define WINED3D_SM4_REGISTER_TYPE_MASK          (0xf << WINED3D_SM4_REGISTER_TYPE_SHIFT)
@@ -56,8 +59,11 @@
 {
     WINED3D_SM4_OP_ADD      = 0x00,
+    WINED3D_SM4_OP_DP3      = 0x10,
+    WINED3D_SM4_OP_DP4      = 0x11,
     WINED3D_SM4_OP_EXP      = 0x19,
     WINED3D_SM4_OP_MOV      = 0x36,
     WINED3D_SM4_OP_MUL      = 0x38,
     WINED3D_SM4_OP_RET      = 0x3e,
+    WINED3D_SM4_OP_RSQ      = 0x44,
     WINED3D_SM4_OP_SINCOS   = 0x4d,
 };
@@ -65,8 +71,9 @@
 enum wined3d_sm4_register_type
 {
-    WINED3D_SM4_RT_TEMP     = 0x0,
-    WINED3D_SM4_RT_INPUT    = 0x1,
-    WINED3D_SM4_RT_OUTPUT   = 0x2,
-    WINED3D_SM4_RT_IMMCONST = 0x4,
+    WINED3D_SM4_RT_TEMP         = 0x0,
+    WINED3D_SM4_RT_INPUT        = 0x1,
+    WINED3D_SM4_RT_OUTPUT       = 0x2,
+    WINED3D_SM4_RT_IMMCONST     = 0x4,
+    WINED3D_SM4_RT_CONSTBUFFER  = 0x8,
 };
 
@@ -102,8 +109,11 @@
 {
     {WINED3D_SM4_OP_ADD,    WINED3DSIH_ADD,         1,  2},
+    {WINED3D_SM4_OP_DP3,    WINED3DSIH_DP3,         1,  2},
+    {WINED3D_SM4_OP_DP4,    WINED3DSIH_DP4,         1,  2},
     {WINED3D_SM4_OP_EXP,    WINED3DSIH_EXP,         1,  1},
     {WINED3D_SM4_OP_MOV,    WINED3DSIH_MOV,         1,  1},
     {WINED3D_SM4_OP_MUL,    WINED3DSIH_MUL,         1,  2},
     {WINED3D_SM4_OP_RET,    WINED3DSIH_RET,         0,  0},
+    {WINED3D_SM4_OP_RSQ,    WINED3DSIH_RSQ,         1,  1},
     {WINED3D_SM4_OP_SINCOS, WINED3DSIH_SINCOS,      1,  2},
 };
@@ -111,9 +121,13 @@
 static const WINED3DSHADER_PARAM_REGISTER_TYPE register_type_table[] =
 {
-    /* WINED3D_SM4_RT_TEMP */       WINED3DSPR_TEMP,
-    /* WINED3D_SM4_RT_INPUT */      WINED3DSPR_INPUT,
-    /* WINED3D_SM4_RT_OUTPUT */     WINED3DSPR_OUTPUT,
-    /* UNKNOWN */                   0,
-    /* WINED3D_SM4_RT_IMMCONST */   WINED3DSPR_IMMCONST,
+    /* WINED3D_SM4_RT_TEMP */           WINED3DSPR_TEMP,
+    /* WINED3D_SM4_RT_INPUT */          WINED3DSPR_INPUT,
+    /* WINED3D_SM4_RT_OUTPUT */         WINED3DSPR_OUTPUT,
+    /* UNKNOWN */                       0,
+    /* WINED3D_SM4_RT_IMMCONST */       WINED3DSPR_IMMCONST,
+    /* UNKNOWN */                       0,
+    /* UNKNOWN */                       0,
+    /* UNKNOWN */                       0,
+    /* WINED3D_SM4_RT_CONSTBUFFER */    WINED3DSPR_CONSTBUFFER,
 };
 
@@ -275,4 +289,5 @@
     DWORD token = *(*ptr)++;
     enum wined3d_sm4_register_type register_type;
+    DWORD order;
 
     register_type = (token & WINED3D_SM4_REGISTER_TYPE_MASK) >> WINED3D_SM4_REGISTER_TYPE_SHIFT;
@@ -286,4 +301,14 @@
         src_param->reg.type = register_type_table[register_type];
     }
+
+    order = (token & WINED3D_SM4_REGISTER_ORDER_MASK) >> WINED3D_SM4_REGISTER_ORDER_SHIFT;
+
+    if (order < 1) src_param->reg.idx = ~0U;
+    else src_param->reg.idx = *(*ptr)++;
+
+    if (order < 2) src_param->reg.array_idx = ~0U;
+    else src_param->reg.array_idx = *(*ptr)++;
+
+    if (order > 2) FIXME("Unhandled order %u.\n", order);
 
     if (register_type == WINED3D_SM4_RT_IMMCONST)
@@ -314,5 +339,4 @@
     else
     {
-        src_param->reg.idx = *(*ptr)++;
         src_param->swizzle = (token & WINED3D_SM4_SWIZZLE_MASK) >> WINED3D_SM4_SWIZZLE_SHIFT;
     }
@@ -329,6 +353,6 @@
     struct wined3d_sm4_data *priv = data;
     DWORD token = *(*ptr)++;
-    UINT register_idx = *(*ptr)++;
     enum wined3d_sm4_register_type register_type;
+    DWORD order;
 
     register_type = (token & WINED3D_SM4_REGISTER_TYPE_MASK) >> WINED3D_SM4_REGISTER_TYPE_SHIFT;
@@ -343,5 +367,14 @@
     }
 
-    dst_param->reg.idx = register_idx;
+    order = (token & WINED3D_SM4_REGISTER_ORDER_MASK) >> WINED3D_SM4_REGISTER_ORDER_SHIFT;
+
+    if (order < 1) dst_param->reg.idx = ~0U;
+    else dst_param->reg.idx = *(*ptr)++;
+
+    if (order < 2) dst_param->reg.array_idx = ~0U;
+    else dst_param->reg.array_idx = *(*ptr)++;
+
+    if (order > 2) FIXME("Unhandled order %u.\n", order);
+
     dst_param->write_mask = (token & WINED3D_SM4_WRITEMASK_MASK) >> WINED3D_SM4_WRITEMASK_SHIFT;
     dst_param->modifiers = 0;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/state.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/state.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/state.c	(revision 21731)
@@ -37,6 +37,4 @@
 #include <stdio.h>
 #ifdef HAVE_FLOAT_H
-/* GL locking for state handlers is done by the caller. */
-
 # include <float.h>
 #endif
@@ -47,4 +45,6 @@
 
 #define GLINFO_LOCATION stateblock->wineD3DDevice->adapter->gl_info
+
+/* GL locking for state handlers is done by the caller. */
 
 static void state_blendop(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context);
@@ -520,5 +520,5 @@
     if(stateblock->renderState[WINED3DRS_COLORKEYENABLE] && enable_ckey) {
         glParm = GL_NOTEQUAL;
-        ref = 0.0;
+        ref = 0.0f;
     } else {
         ref = ((float) stateblock->renderState[WINED3DRS_ALPHAREF]) / 255.0f;
@@ -945,11 +945,11 @@
     switch(context->fog_source) {
         case FOGSOURCE_VS:
-            fogstart = 1.0;
-            fogend = 0.0;
+            fogstart = 1.0f;
+            fogend = 0.0f;
             break;
 
         case FOGSOURCE_COORD:
-            fogstart = 255.0;
-            fogend = 0.0;
+            fogstart = 255.0f;
+            fogend = 0.0f;
             break;
 
@@ -963,5 +963,5 @@
                 unsigned long fNegInf = 0xff800000;
                 fogstart = *(float*)(&fNegInf); /* -1.0/0.0 */
-                fogend = 0.0;
+                fogend = 0.0f;
             }
             break;
@@ -972,6 +972,6 @@
              */
             ERR("Unexpected fog coordinate source\n");
-            fogstart = 0.0;
-            fogend = 0.0;
+            fogstart = 0.0f;
+            fogend = 0.0f;
     }
 
@@ -1346,9 +1346,11 @@
 
     tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MIN];
-    if(tmpvalue.f != 1.0) {
+    if (tmpvalue.f != 1.0f)
+    {
         FIXME("WINED3DRS_POINTSIZE_MIN not supported on this opengl, value is %f\n", tmpvalue.f);
     }
     tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MAX];
-    if(tmpvalue.f != 64.0) {
+    if (tmpvalue.f != 64.0f)
+    {
         FIXME("WINED3DRS_POINTSIZE_MAX not supported on this opengl, value is %f\n", tmpvalue.f);
     }
@@ -3046,6 +3048,6 @@
             FIXME("Non-power2 texture being used with generated texture coords\n");
         }
-        /* NP2 texcoord fixup is implemented for pixelshaders (currently only in GLSL backend) so
-           only enable the fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
+        /* NP2 texcoord fixup is implemented for pixelshaders so only enable the
+           fixed-function-pipeline fixup via pow2Matrix when no PS is used. */
         if (!use_ps(stateblock)) {
             TRACE("Non power two matrix multiply fixup\n");
@@ -3114,8 +3116,8 @@
     DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / (WINED3D_HIGHEST_TEXTURE_STATE + 1);
     DWORD mapped_stage = stateblock->wineD3DDevice->texUnitMap[stage];
-    static const GLfloat s_plane[] = { 1.0, 0.0, 0.0, 0.0 };
-    static const GLfloat t_plane[] = { 0.0, 1.0, 0.0, 0.0 };
-    static const GLfloat r_plane[] = { 0.0, 0.0, 1.0, 0.0 };
-    static const GLfloat q_plane[] = { 0.0, 0.0, 0.0, 1.0 };
+    static const GLfloat s_plane[] = { 1.0f, 0.0f, 0.0f, 0.0f };
+    static const GLfloat t_plane[] = { 0.0f, 1.0f, 0.0f, 0.0f };
+    static const GLfloat r_plane[] = { 0.0f, 0.0f, 1.0f, 0.0f };
+    static const GLfloat q_plane[] = { 0.0f, 0.0f, 0.0f, 1.0f };
 
     if (mapped_stage == WINED3D_UNMAPPED_STAGE)
@@ -3390,6 +3392,5 @@
         }
 
-        /* Trigger shader constant reloading (for NP2 texcoord fixup)
-         * Only do this if pshaders are used (note: fixup is currently only implemented in GLSL). */
+        /* Trigger shader constant reloading (for NP2 texcoord fixup) */
         if (!tex_impl->baseTexture.pow2Matrix_identity) {
             IWineD3DDeviceImpl* d3ddevice = stateblock->wineD3DDevice;
@@ -3520,5 +3521,5 @@
         glLoadIdentity();
         if(stateblock->wineD3DDevice->render_offscreen) {
-            glScalef(1.0, -1.0, 1.0);
+            glScalef(1.0f, -1.0f, 1.0f);
         }
     }
@@ -3754,10 +3755,10 @@
 
         /* Window Coord 0 is the middle of the first pixel, so translate by 1/2 pixels */
-        glTranslatef(0.5, 0.5, 0);
-        checkGLcall("glTranslatef(0.5, 0.5, 0)");
+        glTranslatef(0.5f, 0.5f, 0.0f);
+        checkGLcall("glTranslatef(0.5f, 0.5f, 0.0f)");
         /* D3D texture coordinates are flipped compared to OpenGL ones, so
          * render everything upside down when rendering offscreen. */
         if (stateblock->wineD3DDevice->render_offscreen) {
-            glScalef(1.0, -1.0, 1.0);
+            glScalef(1.0f, -1.0f, 1.0f);
             checkGLcall("glScalef");
         }
@@ -3803,11 +3804,11 @@
             /* D3D texture coordinates are flipped compared to OpenGL ones, so
              * render everything upside down when rendering offscreen. */
-            glTranslatef(1.0 / stateblock->viewport.Width, 1.0 / stateblock->viewport.Height, -1.0);
-            checkGLcall("glTranslatef(1.0 / width, 1.0 / height, -1.0)");
-            glScalef(1.0, -1.0, 2.0);
+            glTranslatef(1.0f / stateblock->viewport.Width, 1.0f / stateblock->viewport.Height, -1.0f);
+            checkGLcall("glTranslatef(1.0f / width, 1.0f / height, -1.0f)");
+            glScalef(1.0f, -1.0f, 2.0f);
         } else {
-            glTranslatef(1.0 / stateblock->viewport.Width, -1.0 / stateblock->viewport.Height, -1.0);
-            checkGLcall("glTranslatef(1.0 / width, -1.0 / height, -1.0)");
-            glScalef(1.0, 1.0, 2.0);
+            glTranslatef(1.0f / stateblock->viewport.Width, -1.0f / stateblock->viewport.Height, -1.0f);
+            checkGLcall("glTranslatef(1.0f / width, -1.0f / height, -1.0f)");
+            glScalef(1.0f, 1.0f, 2.0f);
         }
         checkGLcall("glScalef");
@@ -3839,12 +3840,4 @@
     GL_EXTCALL(glDisableVertexAttribArrayARB(i));
     checkGLcall("glDisableVertexAttribArrayARB(reg)");
-    /* Some Windows drivers(NV GF 7) use the latest value that was used when drawing with the now
-     * deactivated stream disabled, some other drivers(ATI, NV GF 8) set the undefined values to 0x00.
-     * Let's set them to 0x00 to avoid hitting some undefined aspects of OpenGL. All that is really
-     * important here is the glDisableVertexAttribArrayARB call above. The test shows that the refrast
-     * keeps dereferencing the pointers, which would cause crashes in some games like Half Life 2: Episode Two.
-     */
-    GL_EXTCALL(glVertexAttrib4NubARB(i, 0, 0, 0, 0));
-    checkGLcall("glVertexAttrib4NubARB(i, 0, 0, 0, 0)");
 
     context->numbered_array_mask &= ~(1 << i);
@@ -4217,4 +4210,7 @@
 
         if (GL_SUPPORT(EXT_SECONDARY_COLOR)) {
+            GLenum type = e->format_desc->gl_vtx_type;
+            GLint format = e->format_desc->gl_vtx_format;
+
             if (curVBO != e->buffer_object)
             {
@@ -4223,7 +4219,34 @@
                 curVBO = e->buffer_object;
             }
-            GL_EXTCALL(glSecondaryColorPointerEXT)(e->format_desc->gl_vtx_format, e->format_desc->gl_vtx_type,
-                    e->stride, e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
-            checkGLcall("glSecondaryColorPointerEXT(4, GL_UNSIGNED_BYTE, ...)");
+
+            if(format != 4 || (GLINFO_LOCATION.quirks & WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA))
+            {
+                /* Usually specular colors only allow 3 components, since they have no alpha. In D3D, the specular alpha
+                 * contains the fog coordinate, which is passed to GL with GL_EXT_fog_coord. However, the fixed function
+                 * vertex pipeline can pass the specular alpha through, and pixel shaders can read it. So it GL accepts
+                 * 4 component secondary colors use it
+                 */
+                GL_EXTCALL(glSecondaryColorPointerEXT)(format, type,
+                        e->stride, e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
+                checkGLcall("glSecondaryColorPointerEXT(format, type, ...)");
+            }
+            else
+            {
+                switch(type)
+                {
+                    case GL_UNSIGNED_BYTE:
+                        GL_EXTCALL(glSecondaryColorPointerEXT)(3, GL_UNSIGNED_BYTE,
+                                e->stride, e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
+                        checkGLcall("glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, ...)");
+                        break;
+
+                    default:
+                        FIXME("Add 4 component specular color pointers for type %x\n", type);
+                        /* Make sure that the right color component is dropped */
+                        GL_EXTCALL(glSecondaryColorPointerEXT)(3, type,
+                                e->stride, e->data + stateblock->loadBaseVertexIndex * e->stride + offset[e->stream_idx]);
+                        checkGLcall("glSecondaryColorPointerEXT(3, type, ...)");
+                }
+            }
             glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT);
             checkGLcall("glEnableClientState(GL_SECONDARY_COLOR_ARRAY_EXT)");
@@ -4388,5 +4411,5 @@
          */
         if (useVertexShaderFunction) {
-            device->posFixup[1] = device->render_offscreen ? -1.0 : 1.0;
+            device->posFixup[1] = device->render_offscreen ? -1.0f : 1.0f;
             device->posFixup[3] = -device->posFixup[1] / stateblock->viewport.Height;
         }
@@ -4531,5 +4554,5 @@
 
 static void viewport_vertexpart(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
-    stateblock->wineD3DDevice->posFixup[2] = 1.0 / stateblock->viewport.Width;
+    stateblock->wineD3DDevice->posFixup[2] = 1.0f / stateblock->viewport.Width;
     stateblock->wineD3DDevice->posFixup[3] = -stateblock->wineD3DDevice->posFixup[1] / stateblock->viewport.Height;
     if(!isStateDirty(context, STATE_TRANSFORM(WINED3DTS_PROJECTION))) {
@@ -4550,5 +4573,5 @@
     } else {
         float quad_att;
-        float colRGBA[] = {0.0, 0.0, 0.0, 0.0};
+        float colRGBA[] = {0.0f, 0.0f, 0.0f, 0.0f};
 
         /* Light settings are affected by the model view in OpenGL, the View transform in direct3d*/
@@ -4582,7 +4605,7 @@
 
         if ((lightInfo->OriginalParms.Range *lightInfo->OriginalParms.Range) >= FLT_MIN) {
-            quad_att = 1.4/(lightInfo->OriginalParms.Range *lightInfo->OriginalParms.Range);
+            quad_att = 1.4f/(lightInfo->OriginalParms.Range *lightInfo->OriginalParms.Range);
         } else {
-            quad_att = 0; /*  0 or  MAX?  (0 seems to be ok) */
+            quad_att = 0.0f; /*  0 or  MAX?  (0 seems to be ok) */
         }
 
@@ -5377,7 +5400,9 @@
 
 #define GLINFO_LOCATION (*gl_info)
+/* Context activation is done by the caller. */
 static void ffp_enable(IWineD3DDevice *iface, BOOL enable) { }
 
-static void ffp_fragment_get_caps(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct fragment_caps *pCaps)
+static void ffp_fragment_get_caps(WINED3DDEVTYPE devtype,
+        const struct wined3d_gl_info *gl_info, struct fragment_caps *pCaps)
 {
     pCaps->TextureOpCaps =  WINED3DTEXOPCAPS_ADD         |
@@ -5466,5 +5491,5 @@
 
 HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_multistate_funcs,
-        const WineD3D_GL_Info *gl_info, const struct StateEntryTemplate *vertex,
+        const struct wined3d_gl_info *gl_info, const struct StateEntryTemplate *vertex,
         const struct fragment_pipeline *fragment, const struct StateEntryTemplate *misc)
 {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/stateblock.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/stateblock.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/stateblock.c	(revision 21731)
@@ -1097,7 +1097,4 @@
     IWineD3DSwapChain *swapchain;
     IWineD3DSurface *backbuffer;
-    WINED3DSURFACE_DESC desc = {0};
-    UINT width, height;
-    RECT scissorrect;
     HRESULT hr;
 
@@ -1302,8 +1299,4 @@
     }
 
-    /* Set the default scissor rect values */
-    desc.Width = &width;
-    desc.Height = &height;
-
     /* check the return values, because the GetBackBuffer call isn't valid for ddraw */
     hr = IWineD3DDevice_GetSwapChain(device, 0, &swapchain);
@@ -1312,16 +1305,19 @@
 
         hr = IWineD3DSwapChain_GetBackBuffer(swapchain, 0, WINED3DBACKBUFFER_TYPE_MONO, &backbuffer);
-        if( hr == WINED3D_OK && backbuffer != NULL) {
+        if (SUCCEEDED(hr) && backbuffer)
+        {
+            WINED3DSURFACE_DESC desc;
+            RECT scissorrect;
+
             IWineD3DSurface_GetDesc(backbuffer, &desc);
             IWineD3DSurface_Release(backbuffer);
 
+            /* Set the default scissor rect values */
             scissorrect.left = 0;
-            scissorrect.right = width;
+            scissorrect.right = desc.width;
             scissorrect.top = 0;
-            scissorrect.bottom = height;
+            scissorrect.bottom = desc.height;
             hr = IWineD3DDevice_SetScissorRect(device, &scissorrect);
-            if( hr != WINED3D_OK ) {
-                ERR("This should never happen, expect rendering issues!\n");
-            }
+            if (FAILED(hr)) ERR("This should never happen, expect rendering issues!\n");
         }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 21731)
@@ -42,5 +42,210 @@
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
 WINE_DECLARE_DEBUG_CHANNEL(d3d);
-#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
+
+#define GLINFO_LOCATION (*gl_info)
+
+static void surface_cleanup(IWineD3DSurfaceImpl *This)
+{
+    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    renderbuffer_entry_t *entry, *entry2;
+
+    TRACE("(%p) : Cleaning up.\n", This);
+
+    /* Need a context to destroy the texture. Use the currently active render
+     * target, but only if the primary render target exists. Otherwise
+     * lastActiveRenderTarget is garbage. When destroying the primary render
+     * target, Uninit3D() will activate a context before doing anything. */
+    if (device->render_targets && device->render_targets[0])
+    {
+        ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
+    }
+
+    ENTER_GL();
+
+    if (This->texture_name)
+    {
+        /* Release the OpenGL texture. */
+        TRACE("Deleting texture %u.\n", This->texture_name);
+        glDeleteTextures(1, &This->texture_name);
+    }
+
+    if (This->Flags & SFLAG_PBO)
+    {
+        /* Delete the PBO. */
+        GL_EXTCALL(glDeleteBuffersARB(1, &This->pbo));
+    }
+
+    LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->renderbuffers, renderbuffer_entry_t, entry)
+    {
+        GL_EXTCALL(glDeleteRenderbuffersEXT(1, &entry->id));
+        HeapFree(GetProcessHeap(), 0, entry);
+    }
+
+    LEAVE_GL();
+
+    if (This->Flags & SFLAG_DIBSECTION)
+    {
+        /* Release the DC. */
+        SelectObject(This->hDC, This->dib.holdbitmap);
+        DeleteDC(This->hDC);
+        /* Release the DIB section. */
+        DeleteObject(This->dib.DIBsection);
+        This->dib.bitmap_data = NULL;
+        This->resource.allocatedMemory = NULL;
+    }
+
+    if (This->Flags & SFLAG_USERPTR) IWineD3DSurface_SetMem((IWineD3DSurface *)This, NULL);
+    if (This->overlay_dest) list_remove(&This->overlay_entry);
+
+    HeapFree(GetProcessHeap(), 0, This->palette9);
+
+    resource_cleanup((IWineD3DResource *)This);
+}
+
+UINT surface_calculate_size(const struct GlPixelFormatDesc *format_desc, UINT alignment, UINT width, UINT height)
+{
+    UINT size;
+
+    if (format_desc->format == WINED3DFMT_UNKNOWN)
+    {
+        size = 0;
+    }
+    else if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED)
+    {
+        UINT row_block_count = (width + format_desc->block_width - 1) / format_desc->block_width;
+        UINT row_count = (height + format_desc->block_height - 1) / format_desc->block_height;
+        size = row_count * row_block_count * format_desc->block_byte_count;
+    }
+    else
+    {
+        /* The pitch is a multiple of 4 bytes. */
+        size = height * (((width * format_desc->byte_count) + alignment - 1) & ~(alignment - 1));
+    }
+
+    if (format_desc->heightscale != 0.0f) size *= format_desc->heightscale;
+
+    return size;
+}
+
+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)
+{
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
+    const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(format, &GLINFO_LOCATION);
+    void (*cleanup)(IWineD3DSurfaceImpl *This);
+    unsigned int resource_size;
+    HRESULT hr;
+
+    if (multisample_quality > 0)
+    {
+        FIXME("multisample_quality set to %u, substituting 0\n", multisample_quality);
+        multisample_quality = 0;
+    }
+
+    /* FIXME: Check that the format is supported by the device. */
+
+    resource_size = surface_calculate_size(format_desc, alignment, width, height);
+
+    /* Look at the implementation and set the correct Vtable. */
+    switch (surface_type)
+    {
+        case SURFACE_OPENGL:
+            surface->lpVtbl = &IWineD3DSurface_Vtbl;
+            cleanup = surface_cleanup;
+            break;
+
+        case SURFACE_GDI:
+            surface->lpVtbl = &IWineGDISurface_Vtbl;
+            cleanup = surface_gdi_cleanup;
+            break;
+
+        default:
+            ERR("Requested unknown surface implementation %#x.\n", surface_type);
+            return WINED3DERR_INVALIDCALL;
+    }
+
+    hr = resource_init((IWineD3DResource *)surface, WINED3DRTYPE_SURFACE,
+            device, resource_size, usage, format_desc, pool, parent);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize resource, returning %#x.\n", hr);
+        return hr;
+    }
+
+    /* "Standalone" surface. */
+    IWineD3DSurface_SetContainer((IWineD3DSurface *)surface, NULL);
+
+    surface->currentDesc.Width = width;
+    surface->currentDesc.Height = height;
+    surface->currentDesc.MultiSampleType = multisample_type;
+    surface->currentDesc.MultiSampleQuality = multisample_quality;
+    surface->texture_level = level;
+    list_init(&surface->overlays);
+
+    /* Flags */
+    surface->Flags = SFLAG_NORMCOORD; /* Default to normalized coords. */
+    if (discard) surface->Flags |= SFLAG_DISCARD;
+    if (lockable || format == WINED3DFMT_D16_LOCKABLE) surface->Flags |= SFLAG_LOCKABLE;
+
+    /* Quick lockable sanity check.
+     * TODO: remove this after surfaces, usage and lockability have been debugged properly
+     * this function is too deep to need to care about things like this.
+     * Levels need to be checked too, since they all affect what can be done. */
+    switch (pool)
+    {
+        case WINED3DPOOL_SCRATCH:
+            if(!lockable)
+            {
+                FIXME("Called with a pool of SCRATCH and a lockable of FALSE "
+                        "which are mutually exclusive, setting lockable to TRUE.\n");
+                lockable = TRUE;
+            }
+            break;
+
+        case WINED3DPOOL_SYSTEMMEM:
+            if (!lockable)
+                FIXME("Called with a pool of SYSTEMMEM and a lockable of FALSE, this is acceptable but unexpected.\n");
+            break;
+
+        case WINED3DPOOL_MANAGED:
+            if (usage & WINED3DUSAGE_DYNAMIC)
+                FIXME("Called with a pool of MANAGED and a usage of DYNAMIC which are mutually exclusive.\n");
+            break;
+
+        case WINED3DPOOL_DEFAULT:
+            if (lockable && !(usage & (WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_RENDERTARGET | WINED3DUSAGE_DEPTHSTENCIL)))
+                WARN("Creating a lockable surface with a POOL of DEFAULT, that doesn't specify DYNAMIC usage.\n");
+            break;
+
+        default:
+            FIXME("Unknown pool %#x.\n", pool);
+            break;
+    };
+
+    if (usage & WINED3DUSAGE_RENDERTARGET && pool != WINED3DPOOL_DEFAULT)
+    {
+        FIXME("Trying to create a render target that isn't in the default pool.\n");
+    }
+
+    /* Mark the texture as dirty so that it gets loaded first time around. */
+    surface_add_dirty_rect((IWineD3DSurface *)surface, NULL);
+    list_init(&surface->renderbuffers);
+
+    TRACE("surface %p, memory %p, size %u\n", surface, surface->resource.allocatedMemory, surface->resource.size);
+
+    /* Call the private setup routine */
+    hr = IWineD3DSurface_PrivateSetup((IWineD3DSurface *)surface);
+    if (FAILED(hr))
+    {
+        ERR("Private setup failed, returning %#x\n", hr);
+        cleanup(surface);
+        return hr;
+    }
+
+    return hr;
+}
 
 static void surface_force_reload(IWineD3DSurface *iface)
@@ -59,10 +264,10 @@
     if(srgb)
     {
-        name = &This->glDescription.srgbTextureName;
+        name = &This->texture_name_srgb;
         flag = SFLAG_INSRGBTEX;
     }
     else
     {
-        name = &This->glDescription.textureName;
+        name = &This->texture_name;
         flag = SFLAG_INTEXTURE;
     }
@@ -89,5 +294,5 @@
     TRACE("(%p) : setting target %#x\n", This, target);
 
-    if (This->glDescription.target != target)
+    if (This->texture_target != target)
     {
         if (target == GL_TEXTURE_RECTANGLE_ARB)
@@ -95,13 +300,14 @@
             This->Flags &= ~SFLAG_NORMCOORD;
         }
-        else if (This->glDescription.target == GL_TEXTURE_RECTANGLE_ARB)
+        else if (This->texture_target == GL_TEXTURE_RECTANGLE_ARB)
         {
             This->Flags |= SFLAG_NORMCOORD;
         }
     }
-    This->glDescription.target = target;
+    This->texture_target = target;
     surface_force_reload(iface);
 }
 
+/* Context activation is done by the caller. */
 static void surface_bind_and_dirtify(IWineD3DSurfaceImpl *This, BOOL srgb) {
     int active_sampler;
@@ -142,6 +348,11 @@
 }
 
-/* This call just downloads data, the caller is responsible for activating the
- * right context and binding the correct texture. */
+#undef GLINFO_LOCATION
+
+#define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
+
+/* This call just downloads data, the caller is responsible for binding the
+ * correct texture. */
+/* Context activation is done by the caller. */
 static void surface_download_data(IWineD3DSurfaceImpl *This) {
     const struct GlPixelFormatDesc *format_desc = This->resource.format_desc;
@@ -156,27 +367,26 @@
     ENTER_GL();
 
-    if (format_desc->format == WINED3DFMT_DXT1 || format_desc->format == WINED3DFMT_DXT2
-            || format_desc->format == WINED3DFMT_DXT3 || format_desc->format == WINED3DFMT_DXT4
-            || format_desc->format == WINED3DFMT_DXT5 || format_desc->format == WINED3DFMT_ATI2N)
-    {
-        if (!GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) { /* We can assume this as the texture would not have been created otherwise */
-            FIXME("(%p) : Attempting to lock a compressed texture when texture compression isn't supported by opengl\n", This);
-        } else {
-            TRACE("(%p) : Calling glGetCompressedTexImageARB level %d, format %#x, type %#x, data %p\n",
-                    This, This->glDescription.level, format_desc->glFormat, format_desc->glType,
-                    This->resource.allocatedMemory);
-
-            if(This->Flags & SFLAG_PBO) {
-                GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, This->pbo));
-                checkGLcall("glBindBufferARB");
-                GL_EXTCALL(glGetCompressedTexImageARB(This->glDescription.target, This->glDescription.level, NULL));
-                checkGLcall("glGetCompressedTexImageARB()");
-                GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
-                checkGLcall("glBindBufferARB");
-            } else {
-                GL_EXTCALL(glGetCompressedTexImageARB(This->glDescription.target, This->glDescription.level, This->resource.allocatedMemory));
-                checkGLcall("glGetCompressedTexImageARB()");
-            }
-        }
+    if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED)
+    {
+        TRACE("(%p) : Calling glGetCompressedTexImageARB level %d, format %#x, type %#x, data %p.\n",
+                This, This->texture_level, format_desc->glFormat, format_desc->glType,
+                This->resource.allocatedMemory);
+
+        if (This->Flags & SFLAG_PBO)
+        {
+            GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, This->pbo));
+            checkGLcall("glBindBufferARB");
+            GL_EXTCALL(glGetCompressedTexImageARB(This->texture_target, This->texture_level, NULL));
+            checkGLcall("glGetCompressedTexImageARB()");
+            GL_EXTCALL(glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0));
+            checkGLcall("glBindBufferARB");
+        }
+        else
+        {
+            GL_EXTCALL(glGetCompressedTexImageARB(This->texture_target,
+                    This->texture_level, This->resource.allocatedMemory));
+            checkGLcall("glGetCompressedTexImageARB()");
+        }
+
         LEAVE_GL();
     } else {
@@ -204,6 +414,6 @@
         }
 
-        TRACE("(%p) : Calling glGetTexImage level %d, format %#x, type %#x, data %p\n", This, This->glDescription.level,
-                format, type, mem);
+        TRACE("(%p) : Calling glGetTexImage level %d, format %#x, type %#x, data %p\n",
+                This, This->texture_level, format, type, mem);
 
         if(This->Flags & SFLAG_PBO) {
@@ -211,6 +421,5 @@
             checkGLcall("glBindBufferARB");
 
-            glGetTexImage(This->glDescription.target, This->glDescription.level, format,
-                          type, NULL);
+            glGetTexImage(This->texture_target, This->texture_level, format, type, NULL);
             checkGLcall("glGetTexImage()");
 
@@ -218,6 +427,5 @@
             checkGLcall("glBindBufferARB");
         } else {
-            glGetTexImage(This->glDescription.target, This->glDescription.level, format,
-                          type, mem);
+            glGetTexImage(This->texture_target, This->texture_level, format, type, mem);
             checkGLcall("glGetTexImage()");
         }
@@ -296,44 +504,49 @@
 }
 
-/* This call just uploads data, the caller is responsible for activating the
- * right context and binding the correct texture. */
+/* This call just uploads data, the caller is responsible for binding the
+ * correct texture. */
+/* Context activation is done by the caller. */
 static void surface_upload_data(IWineD3DSurfaceImpl *This, GLenum internal, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *data) {
     const struct GlPixelFormatDesc *format_desc = This->resource.format_desc;
 
-    if (format_desc->heightscale != 1.0 && format_desc->heightscale != 0.0) height *= format_desc->heightscale;
-
-    if (format_desc->format == WINED3DFMT_DXT1 || format_desc->format == WINED3DFMT_DXT2
-            || format_desc->format == WINED3DFMT_DXT3 || format_desc->format == WINED3DFMT_DXT4
-            || format_desc->format == WINED3DFMT_DXT5 || format_desc->format == WINED3DFMT_ATI2N)
-    {
-        if (!GL_SUPPORT(EXT_TEXTURE_COMPRESSION_S3TC)) {
-            FIXME("Using DXT1/3/5 without advertized support\n");
-        } else {
-            /* glCompressedTexSubImage2D for uploading and glTexImage2D for allocating does not work well on some drivers(r200 dri, MacOS ATI driver)
-             * glCompressedTexImage2D does not accept NULL pointers. So for compressed textures surface_allocate_surface does nothing, and this
-             * function uses glCompressedTexImage2D instead of the SubImage call
-             */
-            TRACE("(%p) : Calling glCompressedTexSubImage2D w %d, h %d, data %p\n", This, width, height, data);
-            ENTER_GL();
-
-            if(This->Flags & SFLAG_PBO) {
-                GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
-                checkGLcall("glBindBufferARB");
-                TRACE("(%p) pbo: %#x, data: %p\n", This, This->pbo, data);
-
-                GL_EXTCALL(glCompressedTexImage2DARB(This->glDescription.target, This->glDescription.level, internal,
-                        width, height, 0 /* border */, This->resource.size, NULL));
-                checkGLcall("glCompressedTexSubImage2D");
-
-                GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
-                checkGLcall("glBindBufferARB");
-            } else {
-                GL_EXTCALL(glCompressedTexImage2DARB(This->glDescription.target, This->glDescription.level, internal,
-                        width, height, 0 /* border */, This->resource.size, data));
-                checkGLcall("glCompressedTexSubImage2D");
-            }
-            LEAVE_GL();
-        }
-    } else {
+    if (format_desc->heightscale != 1.0f && format_desc->heightscale != 0.0f) height *= format_desc->heightscale;
+
+    if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED)
+    {
+        /* glCompressedTexSubImage2D() for uploading and glTexImage2D() for
+         * allocating does not work well on some drivers (r200 dri, MacOS ATI
+         * driver). glCompressedTexImage2D() does not accept NULL pointers. So
+         * for compressed textures surface_allocate_surface() does nothing,
+         * and this function uses glCompressedTexImage2D() instead of
+         * glCompressedTexSubImage2D(). */
+        TRACE("(%p) : Calling glCompressedTexImage2DARB w %u, h %u, data %p.\n", This, width, height, data);
+
+        ENTER_GL();
+
+        if (This->Flags & SFLAG_PBO)
+        {
+            GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, This->pbo));
+            checkGLcall("glBindBufferARB");
+
+            TRACE("(%p) pbo: %#x, data: %p.\n", This, This->pbo, data);
+
+            GL_EXTCALL(glCompressedTexImage2DARB(This->texture_target, This->texture_level,
+                    internal, width, height, 0 /* border */, This->resource.size, NULL));
+            checkGLcall("glCompressedTexImage2DARB");
+
+            GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
+            checkGLcall("glBindBufferARB");
+        }
+        else
+        {
+            GL_EXTCALL(glCompressedTexImage2DARB(This->texture_target, This->texture_level,
+                    internal, width, height, 0 /* border */, This->resource.size, data));
+            checkGLcall("glCompressedTexSubImage2D");
+        }
+
+        LEAVE_GL();
+    }
+    else
+    {
         TRACE("(%p) : Calling glTexSubImage2D w %d,  h %d, data, %p\n", This, width, height, data);
         ENTER_GL();
@@ -344,5 +557,5 @@
             TRACE("(%p) pbo: %#x, data: %p\n", This, This->pbo, data);
 
-            glTexSubImage2D(This->glDescription.target, This->glDescription.level, 0, 0, width, height, format, type, NULL);
+            glTexSubImage2D(This->texture_target, This->texture_level, 0, 0, width, height, format, type, NULL);
             checkGLcall("glTexSubImage2D");
 
@@ -351,5 +564,5 @@
         }
         else {
-            glTexSubImage2D(This->glDescription.target, This->glDescription.level, 0, 0, width, height, format, type, data);
+            glTexSubImage2D(This->texture_target, This->texture_level, 0, 0, width, height, format, type, data);
             checkGLcall("glTexSubImage2D");
         }
@@ -359,6 +572,7 @@
 }
 
-/* This call just allocates the texture, the caller is responsible for
- * activating the right context and binding the correct texture. */
+/* This call just allocates the texture, the caller is responsible for binding
+ * the correct texture. */
+/* Context activation is done by the caller. */
 static void surface_allocate_surface(IWineD3DSurfaceImpl *This, GLenum internal, GLsizei width, GLsizei height, GLenum format, GLenum type) {
     const struct GlPixelFormatDesc *format_desc = This->resource.format_desc;
@@ -366,13 +580,11 @@
     const BYTE *mem = NULL;
 
-    if (format_desc->heightscale != 1.0 && format_desc->heightscale != 0.0) height *= format_desc->heightscale;
+    if (format_desc->heightscale != 1.0f && format_desc->heightscale != 0.0f) height *= format_desc->heightscale;
 
     TRACE("(%p) : Creating surface (target %#x)  level %d, d3d format %s, internal format %#x, width %d, height %d, gl format %#x, gl type=%#x\n",
-            This, This->glDescription.target, This->glDescription.level, debug_d3dformat(format_desc->format),
+            This, This->texture_target, This->texture_level, debug_d3dformat(format_desc->format),
             internal, width, height, format, type);
 
-    if (format_desc->format == WINED3DFMT_DXT1 || format_desc->format == WINED3DFMT_DXT2
-            || format_desc->format == WINED3DFMT_DXT3 || format_desc->format == WINED3DFMT_DXT4
-            || format_desc->format == WINED3DFMT_DXT5 || format_desc->format == WINED3DFMT_ATI2N)
+    if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED)
     {
         /* glCompressedTexImage2D does not accept NULL pointers, so we cannot allocate a compressed texture without uploading data */
@@ -387,6 +599,6 @@
             mem = (BYTE *)(((ULONG_PTR) This->resource.heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
             ENTER_GL();
-            GL_EXTCALL(glCompressedTexImage2DARB(This->glDescription.target, This->glDescription.level, internal,
-                       width, height, 0 /* border */, This->resource.size, mem));
+            GL_EXTCALL(glCompressedTexImage2DARB(This->texture_target, This->texture_level, internal,
+                    width, height, 0 /* border */, This->resource.size, mem));
             LEAVE_GL();
         }
@@ -419,5 +631,5 @@
         }
     }
-    glTexImage2D(This->glDescription.target, This->glDescription.level, internal, width, height, 0, format, type, mem);
+    glTexImage2D(This->texture_target, This->texture_level, internal, width, height, 0, format, type, mem);
     checkGLcall("glTexImage2D");
 
@@ -549,57 +761,13 @@
     ULONG ref = InterlockedDecrement(&This->resource.ref);
     TRACE("(%p) : Releasing from %d\n", This, ref + 1);
-    if (ref == 0) {
-        IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
-        renderbuffer_entry_t *entry, *entry2;
-        TRACE("(%p) : cleaning up\n", This);
-
-        /* Need a context to destroy the texture. Use the currently active render target, but only if
-         * the primary render target exists. Otherwise lastActiveRenderTarget is garbage, see above.
-         * When destroying the primary rt, Uninit3D will activate a context before doing anything
-         */
-        if(device->render_targets && device->render_targets[0]) {
-            ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
-        }
-
-        ENTER_GL();
-        if (This->glDescription.textureName != 0) { /* release the openGL texture.. */
-            TRACE("Deleting texture %d\n", This->glDescription.textureName);
-            glDeleteTextures(1, &This->glDescription.textureName);
-        }
-
-        if(This->Flags & SFLAG_PBO) {
-            /* Delete the PBO */
-            GL_EXTCALL(glDeleteBuffersARB(1, &This->pbo));
-        }
-
-        LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->renderbuffers, renderbuffer_entry_t, entry) {
-            GL_EXTCALL(glDeleteRenderbuffersEXT(1, &entry->id));
-            HeapFree(GetProcessHeap(), 0, entry);
-        }
-        LEAVE_GL();
-
-        if(This->Flags & SFLAG_DIBSECTION) {
-            /* Release the DC */
-            SelectObject(This->hDC, This->dib.holdbitmap);
-            DeleteDC(This->hDC);
-            /* Release the DIB section */
-            DeleteObject(This->dib.DIBsection);
-            This->dib.bitmap_data = NULL;
-            This->resource.allocatedMemory = NULL;
-        }
-        if(This->Flags & SFLAG_USERPTR) IWineD3DSurface_SetMem(iface, NULL);
-
-        HeapFree(GetProcessHeap(), 0, This->palette9);
-
-        resource_cleanup((IWineD3DResource *)iface);
-
-        if(This->overlay_dest) {
-            list_remove(&This->overlay_entry);
-        }
-
-        TRACE("(%p) Released\n", This);
+
+    if (!ref)
+    {
+        surface_cleanup(This);
+
+        TRACE("(%p) Released.\n", This);
         HeapFree(GetProcessHeap(), 0, This);
-
-    }
+    }
+
     return ref;
 }
@@ -648,5 +816,5 @@
             tmp = 0.9f;
             ENTER_GL();
-            glPrioritizeTextures(1, &This->glDescription.textureName, &tmp);
+            glPrioritizeTextures(1, &This->texture_name, &tmp);
             LEAVE_GL();
         }
@@ -659,4 +827,5 @@
 }
 
+/* Context activation is done by the caller. */
 static void surface_remove_pbo(IWineD3DSurfaceImpl *This) {
     This->resource.heapMemory = HeapAlloc(GetProcessHeap() ,0 , This->resource.size + RESOURCE_ALIGNMENT);
@@ -680,4 +849,5 @@
     IWineD3DBaseTexture *texture = NULL;
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
+    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
     renderbuffer_entry_t *entry, *entry2;
     TRACE("(%p)\n", iface);
@@ -707,5 +877,8 @@
     }
     IWineD3DSurface_ModifyLocation(iface, SFLAG_INTEXTURE, FALSE);
+    IWineD3DSurface_ModifyLocation(iface, SFLAG_INSRGBTEX, FALSE);
     This->Flags &= ~(SFLAG_ALLOCATED | SFLAG_SRGBALLOCATED);
+
+    ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
 
     /* Destroy PBOs, but load them into real sysmem before */
@@ -734,6 +907,8 @@
     if(!texture) {
         ENTER_GL();
-        glDeleteTextures(1, &This->glDescription.textureName);
-        This->glDescription.textureName = 0;
+        glDeleteTextures(1, &This->texture_name);
+        This->texture_name = 0;
+        glDeleteTextures(1, &This->texture_name_srgb);
+        This->texture_name_srgb = 0;
         LEAVE_GL();
     } else {
@@ -746,11 +921,4 @@
    IWineD3DSurface IWineD3DSurface parts follow
    ****************************************************** */
-
-static void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription)
-{
-    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-    TRACE("(%p) : returning %p\n", This, &This->glDescription);
-    *glDescription = &This->glDescription;
-}
 
 /* Read the framebuffer back into the surface */
@@ -1057,9 +1225,6 @@
      * we can use FBOs */
 
-    glCopyTexSubImage2D(This->glDescription.target,
-                        This->glDescription.level,
-                        0, 0, 0, 0,
-                        This->currentDesc.Width,
-                        This->currentDesc.Height);
+    glCopyTexSubImage2D(This->texture_target, This->texture_level,
+            0, 0, 0, 0, This->currentDesc.Width, This->currentDesc.Height);
     checkGLcall("glCopyTexSubImage2D");
 
@@ -1068,5 +1233,5 @@
 
     LEAVE_GL();
-    TRACE("Updated target %d\n", This->glDescription.target);
+    TRACE("Updated target %d\n", This->texture_target);
 }
 
@@ -1138,4 +1303,5 @@
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
     IWineD3DDeviceImpl  *myDevice = This->resource.wineD3DDevice;
+    const RECT *pass_rect = pRect;
 
     TRACE("(%p) : rect@%p flags(%08x), output lockedRect@%p, memory@%p\n", This, pRect, Flags, pLockedRect, This->resource.allocatedMemory);
@@ -1170,70 +1336,17 @@
     }
 
-    /* Now download the surface content from opengl
-     * Use the render target readback if the surface is on a swapchain(=onscreen render target) or the current primary target
-     * Offscreen targets which are not active at the moment or are higher targets(FBOs) can be locked with the texture path
-     */
-    if ((This->Flags & SFLAG_SWAPCHAIN) || iface == myDevice->render_targets[0])
-    {
-        const RECT *pass_rect = pRect;
-
-        /* IWineD3DSurface_LoadLocation does not check if the rectangle specifies the full surfaces
-         * because most caller functions do not need that. So do that here
-         */
-        if(pRect &&
-           pRect->top    == 0 &&
-           pRect->left   == 0 &&
-           pRect->right  == This->currentDesc.Width &&
-           pRect->bottom == This->currentDesc.Height) {
-            pass_rect = NULL;
-        }
-
-        switch(wined3d_settings.rendertargetlock_mode) {
-            case RTL_TEXDRAW:
-            case RTL_TEXTEX:
-                FIXME("Reading from render target with a texture isn't implemented yet, falling back to framebuffer reading\n");
-#if 0
-                /* Disabled for now. LoadLocation prefers the texture over the drawable as the source. So if we copy to the
-                 * texture first, then to sysmem, we'll avoid glReadPixels and use glCopyTexImage and glGetTexImage2D instead.
-                 * This may be faster on some cards
-                 */
-                IWineD3DSurface_LoadLocation(iface, SFLAG_INTEXTURE, NULL /* No partial texture copy yet */);
-#endif
-                /* drop through */
-
-            case RTL_AUTO:
-            case RTL_READDRAW:
-            case RTL_READTEX:
-                IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, pass_rect);
-                break;
-
-            case RTL_DISABLE:
-                break;
-        }
-    } else if(iface == myDevice->stencilBufferTarget) {
-        /** the depth stencil in openGL has a format of GL_FLOAT
-         * which should be good for WINED3DFMT_D16_LOCKABLE
-         * and WINED3DFMT_D16
-         * it is unclear what format the stencil buffer is in except.
-         * 'Each index is converted to fixed point...
-         * If GL_MAP_STENCIL is GL_TRUE, indices are replaced by their
-         * mappings in the table GL_PIXEL_MAP_S_TO_S.
-         * glReadPixels(This->lockedRect.left,
-         *             This->lockedRect.bottom - j - 1,
-         *             This->lockedRect.right - This->lockedRect.left,
-         *             1,
-         *             GL_DEPTH_COMPONENT,
-         *             type,
-         *             (char *)pLockedRect->pBits + (pLockedRect->Pitch * (j-This->lockedRect.top)));
-         *
-         * Depth Stencil surfaces which are not the current depth stencil target should have their data in a
-         * gl texture(next path), or in local memory(early return because of set SFLAG_INSYSMEM above). If
-         * none of that is the case the problem is not in this function :-)
-         ********************************************/
-        FIXME("Depth stencil locking not supported yet\n");
-    } else {
-        /* This path is for normal surfaces, offscreen render targets and everything else that is in a gl texture */
-        TRACE("locking an ordinary surface\n");
-        IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, NULL /* no partial locking for textures yet */);
+    /* IWineD3DSurface_LoadLocation() does not check if the rectangle specifies
+     * the full surface. Most callers don't need that, so do it here. */
+    if (pRect && pRect->top == 0 && pRect->left == 0
+            && pRect->right == This->currentDesc.Width
+            && pRect->bottom == This->currentDesc.Height)
+    {
+        pass_rect = NULL;
+    }
+
+    if (!(wined3d_settings.rendertargetlock_mode == RTL_DISABLE
+            && ((This->Flags & SFLAG_SWAPCHAIN) || iface == myDevice->render_targets[0])))
+    {
+        IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, pass_rect);
     }
 
@@ -1313,5 +1426,5 @@
     glGetIntegerv(GL_CURRENT_RASTER_POSITION, &prev_rasterpos[0]);
     checkGLcall("glIntegerv");
-    glPixelZoom(1.0, -1.0);
+    glPixelZoom(1.0f, -1.0f);
     checkGLcall("glPixelZoom");
 
@@ -1363,5 +1476,5 @@
     }
 
-    glPixelZoom(1.0,1.0);
+    glPixelZoom(1.0f, 1.0f);
     checkGLcall("glPixelZoom");
 
@@ -1442,5 +1555,4 @@
             case RTL_READTEX:
             case RTL_TEXTEX:
-                ActivateContext(myDevice, iface, CTXUSAGE_BLIT);
                 IWineD3DSurface_LoadLocation(iface, SFLAG_INTEXTURE, NULL /* partial texture loading not supported yet */);
                 /* drop through */
@@ -1680,5 +1792,4 @@
             else if(!GL_SUPPORT(EXT_PALETTED_TEXTURE) && GL_SUPPORT(ARB_FRAGMENT_PROGRAM)) {
                 *format = GL_ALPHA;
-                *internal = GL_RGBA;
                 *type = GL_UNSIGNED_BYTE;
                 *target_bpp = 1;
@@ -1702,5 +1813,5 @@
                 *convert = CONVERT_CK_565;
                 *format = GL_RGBA;
-                *internal = GL_RGBA;
+                *internal = GL_RGB5_A1;
                 *type = GL_UNSIGNED_SHORT_5_5_5_1;
             }
@@ -1711,5 +1822,5 @@
                 *convert = CONVERT_CK_5551;
                 *format = GL_BGRA;
-                *internal = GL_RGBA;
+                *internal = GL_RGB5_A1;
                 *type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
             }
@@ -1720,5 +1831,5 @@
                 *convert = CONVERT_CK_RGB24;
                 *format = GL_RGBA;
-                *internal = GL_RGBA;
+                *internal = GL_RGBA8;
                 *type = GL_UNSIGNED_INT_8_8_8_8;
                 *target_bpp = 4;
@@ -1730,5 +1841,5 @@
                 *convert = CONVERT_RGB32_888;
                 *format = GL_RGBA;
-                *internal = GL_RGBA;
+                *internal = GL_RGBA8;
                 *type = GL_UNSIGNED_INT_8_8_8_8;
             }
@@ -1736,8 +1847,7 @@
 
         case WINED3DFMT_R8G8_SNORM:
-            if(GL_SUPPORT(NV_TEXTURE_SHADER3)) break;
+            if (GL_SUPPORT(NV_TEXTURE_SHADER)) break;
             *convert = CONVERT_V8U8;
             *format = GL_BGR;
-            *internal = GL_RGB8;
             *type = GL_UNSIGNED_BYTE;
             *target_bpp = 3;
@@ -1753,5 +1863,4 @@
                 *target_bpp = 2;
                 *format = GL_RGB;
-                *internal = GL_RGB5;
                 *type = GL_UNSIGNED_SHORT_5_6_5;
             }
@@ -1770,5 +1879,4 @@
             } else {
                 *format = GL_BGRA;
-                *internal = GL_RGB8;
                 *type = GL_UNSIGNED_INT_8_8_8_8_REV;
             }
@@ -1776,8 +1884,7 @@
 
         case WINED3DFMT_R8G8B8A8_SNORM:
-            if(GL_SUPPORT(NV_TEXTURE_SHADER3)) break;
+            if (GL_SUPPORT(NV_TEXTURE_SHADER)) break;
             *convert = CONVERT_Q8W8V8U8;
             *format = GL_BGRA;
-            *internal = GL_RGBA8;
             *type = GL_UNSIGNED_BYTE;
             *target_bpp = 4;
@@ -1785,8 +1892,7 @@
 
         case WINED3DFMT_R16G16_SNORM:
-            if(GL_SUPPORT(NV_TEXTURE_SHADER3)) break;
+            if (GL_SUPPORT(NV_TEXTURE_SHADER)) break;
             *convert = CONVERT_V16U16;
             *format = GL_BGR;
-            *internal = GL_RGB16_EXT;
             *type = GL_UNSIGNED_SHORT;
             *target_bpp = 6;
@@ -1800,5 +1906,4 @@
             *convert = CONVERT_A4L4;
             *format = GL_LUMINANCE_ALPHA;
-            *internal = GL_LUMINANCE4_ALPHA4;
             *type = GL_UNSIGNED_BYTE;
             *target_bpp = 2;
@@ -1808,5 +1913,4 @@
             *convert = CONVERT_G16R16;
             *format = GL_RGB;
-            *internal = GL_RGB16_EXT;
             *type = GL_UNSIGNED_SHORT;
             *target_bpp = 6;
@@ -1816,5 +1920,4 @@
             *convert = CONVERT_R16G16F;
             *format = GL_RGB;
-            *internal = GL_RGB16F_ARB;
             *type = GL_HALF_FLOAT_ARB;
             *target_bpp = 6;
@@ -1824,7 +1927,29 @@
             *convert = CONVERT_R32G32F;
             *format = GL_RGB;
-            *internal = GL_RGB32F_ARB;
             *type = GL_FLOAT;
             *target_bpp = 12;
+            break;
+
+        case WINED3DFMT_D15S1:
+            if (GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
+            {
+                *convert = CONVERT_D15S1;
+                *target_bpp = 4;
+            }
+            break;
+
+        case WINED3DFMT_D24X4S4:
+            if (GL_SUPPORT(EXT_PACKED_DEPTH_STENCIL))
+            {
+                *convert = CONVERT_D24X4S4;
+            }
+            break;
+
+        case WINED3DFMT_D24FS8:
+            if (GL_SUPPORT(ARB_DEPTH_BUFFER_FLOAT))
+            {
+                *convert = CONVERT_D24FS8;
+                *target_bpp = 8;
+            }
             break;
 
@@ -2274,5 +2399,5 @@
                     Dest[0] = green;
                     Dest[1] = red;
-                    Dest[2] = 1.0;
+                    Dest[2] = 1.0f;
                     Dest += 3;
                 }
@@ -2281,6 +2406,65 @@
         }
 
+        case CONVERT_D15S1:
+        {
+            unsigned int x, y;
+
+            for (y = 0; y < height; ++y)
+            {
+                const WORD *source = (const WORD *)(src + y * pitch);
+                DWORD *dest = (DWORD *)(dst + y * outpitch);
+
+                for (x = 0; x < width; ++x)
+                {
+                    /* The depth data is normalized, so needs to be scaled,
+                     * the stencil data isn't.  Scale depth data by
+                     *      (2^24-1)/(2^15-1) ~~ (2^9 + 2^-6). */
+                    WORD d15 = source[x] >> 1;
+                    DWORD d24 = (d15 << 9) + (d15 >> 6);
+                    dest[x] = (d24 << 8) | (source[x] & 0x1);
+                }
+            }
+            break;
+        }
+
+        case CONVERT_D24X4S4:
+        {
+            unsigned int x, y;
+
+            for (y = 0; y < height; ++y)
+            {
+                const DWORD *source = (const DWORD *)(src + y * pitch);
+                DWORD *dest = (DWORD *)(dst + y * outpitch);
+
+                for (x = 0; x < width; ++x)
+                {
+                    /* Just need to clear out the X4 part. */
+                    dest[x] = source[x] & ~0xf0;
+                }
+            }
+            break;
+        }
+
+        case CONVERT_D24FS8:
+        {
+            unsigned int x, y;
+
+            for (y = 0; y < height; ++y)
+            {
+                const DWORD *source = (const DWORD *)(src + y * pitch);
+                float *dest_f = (float *)(dst + y * outpitch);
+                DWORD *dest_s = (DWORD *)(dst + y * outpitch);
+
+                for (x = 0; x < width; ++x)
+                {
+                    dest_f[x * 2] = float_24_to_32((source[x] & 0xffffff00) >> 8);
+                    dest_s[x * 2 + 1] = source[x] & 0xff;
+                }
+            }
+            break;
+        }
+
         default:
-            ERR("Unsupported conversation type %d\n", convert);
+            ERR("Unsupported conversion type %#x.\n", convert);
     }
     return WINED3D_OK;
@@ -2291,4 +2475,5 @@
    extensions like ATI_fragment_shaders is possible.
 */
+/* Context activation is done by the caller. */
 static void d3dfmt_p8_upload_palette(IWineD3DSurface *iface, CONVERT_TYPES convert) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
@@ -2303,5 +2488,5 @@
         TRACE("Using GL_EXT_PALETTED_TEXTURE for 8-bit paletted texture support\n");
         ENTER_GL();
-        GL_EXTCALL(glColorTableEXT(This->glDescription.target,GL_RGBA,256,GL_RGBA,GL_UNSIGNED_BYTE, table));
+        GL_EXTCALL(glColorTableEXT(This->texture_target, GL_RGBA, 256, GL_RGBA, GL_UNSIGNED_BYTE, table));
         LEAVE_GL();
     }
@@ -2352,5 +2537,5 @@
 
         /* Rebind the texture because it isn't bound anymore */
-        glBindTexture(This->glDescription.target, This->glDescription.textureName);
+        glBindTexture(This->texture_target, This->texture_name);
 
         LEAVE_GL();
@@ -2428,5 +2613,6 @@
         ++gen;
         if ((gen % 10) == 0) {
-            snprintf(buffer, sizeof(buffer), "/tmp/surface%p_type%u_level%u_%u.ppm", This, This->glDescription.target, This->glDescription.level, gen);
+            snprintf(buffer, sizeof(buffer), "/tmp/surface%p_type%u_level%u_%u.ppm",
+                    This, This->texture_target, This->texture_level, gen);
             IWineD3DSurfaceImpl_SaveSnapshot(iface, buffer);
         }
@@ -2451,4 +2637,5 @@
 }
 
+/* Context activation is done by the caller. */
 static void WINAPI IWineD3DSurfaceImpl_BindTexture(IWineD3DSurface *iface, BOOL srgb) {
     /* TODO: check for locks */
@@ -2466,5 +2653,5 @@
         TRACE("(%p) : Binding surface\n", This);
 
-        name = srgb ? &This->glDescription.srgbTextureName : &This->glDescription.textureName;
+        name = srgb ? &This->texture_name_srgb : &This->texture_name;
         if(!device->isInDraw) {
             ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
@@ -2473,5 +2660,6 @@
         ENTER_GL();
 
-        if (!This->glDescription.level) {
+        if (!This->texture_level)
+        {
             if (!*name) {
                 glGenTextures(1, name);
@@ -2479,15 +2667,15 @@
                 TRACE("Surface %p given name %d\n", This, *name);
 
-                glBindTexture(This->glDescription.target, *name);
+                glBindTexture(This->texture_target, *name);
                 checkGLcall("glBindTexture");
-                glTexParameteri(This->glDescription.target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+                glTexParameteri(This->texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
                 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)");
-                glTexParameteri(This->glDescription.target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+                glTexParameteri(This->texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
                 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
-                glTexParameteri(This->glDescription.target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+                glTexParameteri(This->texture_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
                 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)");
-                glTexParameteri(This->glDescription.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+                glTexParameteri(This->texture_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
                 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
-                glTexParameteri(This->glDescription.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+                glTexParameteri(This->texture_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
                 checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
             }
@@ -2498,5 +2686,5 @@
         }
 
-        glBindTexture(This->glDescription.target, This->glDescription.textureName);
+        glBindTexture(This->texture_target, *name);
         checkGLcall("glBindTexture");
 
@@ -2581,10 +2769,6 @@
     allocatedMemory = HeapAlloc(GetProcessHeap(), 0, width  * height * 4);
     ENTER_GL();
-    FIXME("Saving texture level %d width %d height %d\n", This->glDescription.level, width, height);
-    glGetTexImage(GL_TEXTURE_2D,
-                This->glDescription.level,
-                GL_RGBA,
-                GL_UNSIGNED_INT_8_8_8_8_REV,
-                allocatedMemory);
+    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");
     if (tmpTexture) {
@@ -2788,7 +2972,13 @@
     /* Flip the opengl texture */
     {
-        glDescriptor tmp_desc = back->glDescription;
-        back->glDescription = front->glDescription;
-        front->glDescription = tmp_desc;
+        GLuint tmp;
+
+        tmp = back->texture_name;
+        back->texture_name = front->texture_name;
+        front->texture_name = tmp;
+
+        tmp = back->texture_name_srgb;
+        back->texture_name_srgb = front->texture_name_srgb;
+        front->texture_name_srgb = tmp;
     }
 
@@ -2877,5 +3067,5 @@
 
     /* Bind the target texture */
-    glBindTexture(This->glDescription.target, This->glDescription.textureName);
+    glBindTexture(This->texture_target, This->texture_name);
     checkGLcall("glBindTexture");
     if(!swapchain) {
@@ -2892,5 +3082,6 @@
     yrel = (float) (srect->y2 - srect->y1) / (float) (drect->y2 - drect->y1);
 
-    if( (xrel - 1.0 < -eps) || (xrel - 1.0 > eps)) {
+    if ((xrel - 1.0f < -eps) || (xrel - 1.0f > eps))
+    {
         FIXME("Doing a pixel by pixel copy from the framebuffer to a texture, expect major performance issues\n");
 
@@ -2898,18 +3089,21 @@
             ERR("Texture filtering not supported in direct blit\n");
         }
-    } else if((Filter != WINED3DTEXF_NONE && Filter != WINED3DTEXF_POINT) && ((yrel - 1.0 < -eps) || (yrel - 1.0 > eps))) {
+    }
+    else if ((Filter != WINED3DTEXF_NONE && Filter != WINED3DTEXF_POINT)
+            && ((yrel - 1.0f < -eps) || (yrel - 1.0f > eps)))
+    {
         ERR("Texture filtering not supported in direct blit\n");
     }
 
-    if(upsidedown &&
-       !((xrel - 1.0 < -eps) || (xrel - 1.0 > eps)) &&
-       !((yrel - 1.0 < -eps) || (yrel - 1.0 > eps))) {
+    if (upsidedown
+            && !((xrel - 1.0f < -eps) || (xrel - 1.0f > eps))
+            && !((yrel - 1.0f < -eps) || (yrel - 1.0f > eps)))
+    {
         /* Upside down copy without stretching is nice, one glCopyTexSubImage call will do */
 
-        glCopyTexSubImage2D(This->glDescription.target,
-                            This->glDescription.level,
-                            drect->x1, drect->y1, /* xoffset, yoffset */
-                            srect->x1, Src->currentDesc.Height - srect->y2,
-                            drect->x2 - drect->x1, drect->y2 - drect->y1);
+        glCopyTexSubImage2D(This->texture_target, This->texture_level,
+                drect->x1 /*xoffset */, drect->y1 /* y offset */,
+                srect->x1, Src->currentDesc.Height - srect->y2,
+                drect->x2 - drect->x1, drect->y2 - drect->y1);
     } else {
         UINT yoffset = Src->currentDesc.Height - srect->y1 + drect->y1 - 1;
@@ -2921,5 +3115,6 @@
          */
         for(row = drect->y1; row < drect->y2; row++) {
-            if( (xrel - 1.0 < -eps) || (xrel - 1.0 > eps)) {
+            if ((xrel - 1.0f < -eps) || (xrel - 1.0f > eps))
+            {
                 /* Well, that stuff works, but it's very slow.
                  * find a better way instead
@@ -2928,16 +3123,12 @@
 
                 for(col = drect->x1; col < drect->x2; col++) {
-                    glCopyTexSubImage2D(This->glDescription.target,
-                                        This->glDescription.level,
-                                        drect->x1 + col, row, /* xoffset, yoffset */
-                                        srect->x1 + col * xrel, yoffset - (int) (row * yrel),
-                                        1, 1);
+                    glCopyTexSubImage2D(This->texture_target, This->texture_level,
+                            drect->x1 + col /* x offset */, row /* y offset */,
+                            srect->x1 + col * xrel, yoffset - (int) (row * yrel), 1, 1);
                 }
             } else {
-                glCopyTexSubImage2D(This->glDescription.target,
-                                    This->glDescription.level,
-                                    drect->x1, row, /* xoffset, yoffset */
-                                    srect->x1, yoffset - (int) (row * yrel),
-                                    drect->x2-drect->x1, 1);
+                glCopyTexSubImage2D(This->texture_target, This->texture_level,
+                        drect->x1 /* x offset */, row /* y offset */,
+                        srect->x1, yoffset - (int) (row * yrel), drect->x2-drect->x1, 1);
             }
         }
@@ -2969,5 +3160,6 @@
 
     noBackBufferBackup = !swapchain && wined3d_settings.offscreen_rendering_mode == ORM_FBO;
-    if(!noBackBufferBackup && Src->glDescription.textureName == 0) {
+    if (!noBackBufferBackup && !Src->texture_name)
+    {
         /* Get it a description */
         surface_internal_preload(SrcSurface, SRGB_RGB);
@@ -2988,7 +3180,7 @@
     if(noBackBufferBackup) {
         glGenTextures(1, &backup);
-        checkGLcall("glGenTextures\n");
+        checkGLcall("glGenTextures");
         glBindTexture(GL_TEXTURE_2D, backup);
-        checkGLcall("glBindTexture(Src->glDescription.target, Src->glDescription.textureName)");
+        checkGLcall("glBindTexture(GL_TEXTURE_2D, backup)");
         texture_target = GL_TEXTURE_2D;
     } else {
@@ -2996,7 +3188,7 @@
          * we are reading from the back buffer, the backup can be used as source texture
          */
-        texture_target = Src->glDescription.target;
-        glBindTexture(texture_target, Src->glDescription.textureName);
-        checkGLcall("glBindTexture(texture_target, Src->glDescription.textureName)");
+        texture_target = Src->texture_target;
+        glBindTexture(texture_target, Src->texture_name);
+        checkGLcall("glBindTexture(texture_target, Src->texture_name)");
         glEnable(texture_target);
         checkGLcall("glEnable(texture_target)");
@@ -3032,5 +3224,5 @@
 
     if(!swapchain || (IWineD3DSurface *) Src == swapchain->backBuffer[0]) {
-        src = backup ? backup : Src->glDescription.textureName;
+        src = backup ? backup : Src->texture_name;
     } else {
         glReadBuffer(GL_FRONT);
@@ -3114,12 +3306,13 @@
     checkGLcall("glEnd and previous");
 
-    if(texture_target != This->glDescription.target) {
+    if (texture_target != This->texture_target)
+    {
         glDisable(texture_target);
-        glEnable(This->glDescription.target);
-        texture_target = This->glDescription.target;
+        glEnable(This->texture_target);
+        texture_target = This->texture_target;
     }
 
     /* Now read the stretched and upside down image into the destination texture */
-    glBindTexture(texture_target, This->glDescription.textureName);
+    glBindTexture(texture_target, This->texture_name);
     checkGLcall("glBindTexture");
     glCopyTexSubImage2D(texture_target,
@@ -3141,24 +3334,25 @@
             checkGLcall("glBindTexture(GL_TEXTURE_2D, backup)");
         } else {
-            if(texture_target != Src->glDescription.target) {
+            if (texture_target != Src->texture_target)
+            {
                 glDisable(texture_target);
-                glEnable(Src->glDescription.target);
-                texture_target = Src->glDescription.target;
-            }
-            glBindTexture(Src->glDescription.target, Src->glDescription.textureName);
-            checkGLcall("glBindTexture(Src->glDescription.target, Src->glDescription.textureName)");
+                glEnable(Src->texture_target);
+                texture_target = Src->texture_target;
+            }
+            glBindTexture(Src->texture_target, Src->texture_name);
+            checkGLcall("glBindTexture(Src->texture_target, Src->texture_name)");
         }
 
         glBegin(GL_QUADS);
             /* top left */
-            glTexCoord2f(0.0, (float) fbheight / (float) Src->pow2Height);
+            glTexCoord2f(0.0f, (float)fbheight / (float)Src->pow2Height);
             glVertex2i(0, 0);
 
             /* bottom left */
-            glTexCoord2f(0.0, 0.0);
+            glTexCoord2f(0.0f, 0.0f);
             glVertex2i(0, fbheight);
 
             /* bottom right */
-            glTexCoord2f((float) fbwidth / (float) Src->pow2Width, 0.0);
+            glTexCoord2f((float)fbwidth / (float)Src->pow2Width, 0.0f);
             glVertex2i(fbwidth, Src->currentDesc.Height);
 
@@ -3175,5 +3369,6 @@
 
     /* Cleanup */
-    if(src != Src->glDescription.textureName && src != backup) {
+    if (src != Src->texture_name && src != backup)
+    {
         glDeleteTextures(1, &src);
         checkGLcall("glDeleteTextures(1, &src)");
@@ -3560,22 +3755,34 @@
         }
 
+        if (!is_identity_fixup(This->resource.format_desc->color_fixup))
+        {
+            FIXME("Destination format %s has a fixup, this is not supported.\n",
+                    debug_d3dformat(This->resource.format_desc->format));
+            dump_color_fixup_desc(This->resource.format_desc->color_fixup);
+        }
+
+        if (!myDevice->blitter->color_fixup_supported(Src->resource.format_desc->color_fixup))
+        {
+            FIXME("Source format %s has an unsupported fixup:\n",
+                    debug_d3dformat(Src->resource.format_desc->format));
+            dump_color_fixup_desc(Src->resource.format_desc->color_fixup);
+        }
+
         myDevice->blitter->set_shader((IWineD3DDevice *) myDevice, Src->resource.format_desc,
-                Src->glDescription.target, Src->pow2Width, Src->pow2Height);
+                Src->texture_target, Src->pow2Width, Src->pow2Height);
 
         ENTER_GL();
 
         /* Bind the texture */
-        glBindTexture(Src->glDescription.target, Src->glDescription.textureName);
+        glBindTexture(Src->texture_target, Src->texture_name);
         checkGLcall("glBindTexture");
 
         /* Filtering for StretchRect */
-        glTexParameteri(Src->glDescription.target, GL_TEXTURE_MAG_FILTER,
-                        magLookup[Filter - WINED3DTEXF_NONE]);
+        glTexParameteri(Src->texture_target, GL_TEXTURE_MAG_FILTER, magLookup[Filter - WINED3DTEXF_NONE]);
         checkGLcall("glTexParameteri");
-        glTexParameteri(Src->glDescription.target, GL_TEXTURE_MIN_FILTER,
-                        minMipLookup[Filter].mip[WINED3DTEXF_NONE]);
+        glTexParameteri(Src->texture_target, GL_TEXTURE_MIN_FILTER, minMipLookup[Filter].mip[WINED3DTEXF_NONE]);
         checkGLcall("glTexParameteri");
-        glTexParameteri(Src->glDescription.target, GL_TEXTURE_WRAP_S, GL_CLAMP);
-        glTexParameteri(Src->glDescription.target, GL_TEXTURE_WRAP_T, GL_CLAMP);
+        glTexParameteri(Src->texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP);
+        glTexParameteri(Src->texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP);
         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
         checkGLcall("glTexEnvi");
@@ -3590,8 +3797,8 @@
              * should be masked away have alpha set to 0. */
             if(primary_render_target_is_p8(myDevice))
-                glAlphaFunc(GL_NOTEQUAL, (float)Src->SrcBltCKey.dwColorSpaceLowValue / 256.0);
+                glAlphaFunc(GL_NOTEQUAL, (float)Src->SrcBltCKey.dwColorSpaceLowValue / 256.0f);
             else
-                glAlphaFunc(GL_NOTEQUAL, 0.0);
-            checkGLcall("glAlphaFunc\n");
+                glAlphaFunc(GL_NOTEQUAL, 0.0f);
+            checkGLcall("glAlphaFunc");
         } else {
             glDisable(GL_ALPHA_TEST);
@@ -3603,22 +3810,17 @@
         glBegin(GL_QUADS);
 
-        glColor3d(1.0f, 1.0f, 1.0f);
+        glColor3f(1.0f, 1.0f, 1.0f);
         glTexCoord2f(glTexCoord[0], glTexCoord[2]);
-        glVertex3f(rect.x1,
-                    rect.y1,
-                    0.0);
+        glVertex3f(rect.x1, rect.y1, 0.0f);
 
         glTexCoord2f(glTexCoord[0], glTexCoord[3]);
-        glVertex3f(rect.x1, rect.y2, 0.0);
+        glVertex3f(rect.x1, rect.y2, 0.0f);
 
         glTexCoord2f(glTexCoord[1], glTexCoord[3]);
-        glVertex3f(rect.x2,
-                    rect.y2,
-                    0.0);
+        glVertex3f(rect.x2, rect.y2, 0.0f);
 
         glTexCoord2f(glTexCoord[1], glTexCoord[2]);
-        glVertex3f(rect.x2,
-                    rect.y1,
-                    0.0);
+        glVertex3f(rect.x2, rect.y1, 0.0f);
+
         glEnd();
         checkGLcall("glEnd");
@@ -3629,6 +3831,6 @@
         }
 
-        glBindTexture(Src->glDescription.target, 0);
-        checkGLcall("glBindTexture(Src->glDescription.target, 0)");
+        glBindTexture(Src->texture_target, 0);
+        checkGLcall("glBindTexture(Src->texture_target, 0)");
 
         /* Restore the color key parameters */
@@ -3718,9 +3920,6 @@
 
             TRACE("(%p) executing Render Target override, color = %x\n", This, color);
-            IWineD3DDeviceImpl_ClearSurface(myDevice, This,
-                                            1, /* Number of rectangles */
-                                            &rect, WINED3DCLEAR_TARGET, color,
-                                            0.0 /* Z */,
-                                            0 /* Stencil */);
+            IWineD3DDeviceImpl_ClearSurface(myDevice, This, 1 /* Number of rectangles */,
+                    &rect, WINED3DCLEAR_TARGET, color, 0.0f /* Z */, 0 /* Stencil */);
             return WINED3D_OK;
         }
@@ -3755,5 +3954,5 @@
                 break;
             default:
-                depth = 0.0;
+                depth = 0.0f;
                 ERR("Unexpected format for depth fill: %s\n", debug_d3dformat(This->resource.format_desc->format));
         }
@@ -3899,4 +4098,6 @@
         if((This->resource.usage & WINED3DUSAGE_RENDERTARGET) && (convert == NO_CONVERSION))
         {
+            IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+
             /* Make sure the texture is up to date. This call doesn't do anything if the texture is already up to date. */
             IWineD3DSurface_LoadLocation(iface, SFLAG_INTEXTURE, NULL);
@@ -3906,4 +4107,5 @@
 
             /* Re-upload the palette */
+            ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
             d3dfmt_p8_upload_palette(iface, convert);
         } else {
@@ -3940,6 +4142,6 @@
     unsigned int pow2Width, pow2Height;
 
-    This->glDescription.textureName      = 0;
-    This->glDescription.target           = GL_TEXTURE_2D;
+    This->texture_name = 0;
+    This->texture_target = GL_TEXTURE_2D;
 
     /* Non-power2 support */
@@ -3957,9 +4159,6 @@
 
     if (pow2Width > This->currentDesc.Width || pow2Height > This->currentDesc.Height) {
-        WINED3DFORMAT Format = This->resource.format_desc->format;
         /** TODO: add support for non power two compressed textures **/
-        if (Format == WINED3DFMT_DXT1 || Format == WINED3DFMT_DXT2 || Format == WINED3DFMT_DXT3
-            || Format == WINED3DFMT_DXT4 || Format == WINED3DFMT_DXT5
-            || Format == WINED3DFMT_ATI2N)
+        if (This->resource.format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED)
         {
             FIXME("(%p) Compressed non-power-two textures are not supported w(%d) h(%d)\n",
@@ -4002,5 +4201,5 @@
                 || wined3d_settings.rendertargetlock_mode == RTL_TEXTEX)))
         {
-            This->glDescription.target = GL_TEXTURE_RECTANGLE_ARB;
+            This->texture_target = GL_TEXTURE_RECTANGLE_ARB;
             This->pow2Width  = This->currentDesc.Width;
             This->pow2Height = This->currentDesc.Height;
@@ -4132,5 +4331,5 @@
 
     glDisable(GL_CULL_FACE);
-    glEnable(GL_BLEND);
+    glDisable(GL_BLEND);
     glDisable(GL_ALPHA_TEST);
     glDisable(GL_SCISSOR_TEST);
@@ -4139,5 +4338,5 @@
     glDepthFunc(GL_ALWAYS);
     glDepthMask(GL_TRUE);
-    glBlendFunc(GL_ZERO, GL_ONE);
+    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
     glViewport(0, 0, w, h);
 
@@ -4180,4 +4379,5 @@
 }
 
+/* Context activation is done by the caller. */
 void surface_load_ds_location(IWineD3DSurface *iface, DWORD location) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
@@ -4214,6 +4414,7 @@
             /* Note that we use depth_blt here as well, rather than glCopyTexImage2D
              * directly on the FBO texture. That's because we need to flip. */
-            GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
-            if (This->glDescription.target == GL_TEXTURE_RECTANGLE_ARB) {
+            context_bind_fbo(device->activeContext, GL_FRAMEBUFFER_EXT, NULL);
+            if (This->texture_target == GL_TEXTURE_RECTANGLE_ARB)
+            {
                 glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_binding);
                 bind_target = GL_TEXTURE_RECTANGLE_ARB;
@@ -4223,14 +4424,11 @@
             }
             glBindTexture(bind_target, device->depth_blt_texture);
-            glCopyTexImage2D(bind_target,
-                    This->glDescription.level,
-                    This->resource.format_desc->glInternal,
-                    0,
-                    0,
-                    This->currentDesc.Width,
-                    This->currentDesc.Height,
-                    0);
+            glCopyTexImage2D(bind_target, This->texture_level, This->resource.format_desc->glInternal,
+                    0, 0, This->currentDesc.Width, This->currentDesc.Height, 0);
             glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
             glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+            glTexParameteri(bind_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+            glTexParameteri(bind_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+            glTexParameteri(bind_target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
             glTexParameteri(bind_target, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
             glBindTexture(bind_target, old_binding);
@@ -4251,8 +4449,8 @@
             }
 
-            context_bind_fbo((IWineD3DDevice *)device, GL_FRAMEBUFFER_EXT, &device->activeContext->dst_fbo);
+            context_bind_fbo(device->activeContext, GL_FRAMEBUFFER_EXT, &device->activeContext->dst_fbo);
             GL_EXTCALL(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, device->depth_blt_rb));
             checkGLcall("glFramebufferRenderbufferEXT");
-            context_attach_depth_stencil_fbo(device, GL_FRAMEBUFFER_EXT, iface, FALSE);
+            context_attach_depth_stencil_fbo(device->activeContext, GL_FRAMEBUFFER_EXT, iface, FALSE);
 
             /* Do the actual blit */
@@ -4261,8 +4459,7 @@
 
             if (device->activeContext->current_fbo) {
-                context_bind_fbo((IWineD3DDevice *)device, GL_FRAMEBUFFER_EXT, &device->activeContext->current_fbo->id);
+                context_bind_fbo(device->activeContext, GL_FRAMEBUFFER_EXT, &device->activeContext->current_fbo->id);
             } else {
-                GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
-                checkGLcall("glBindFramebuffer()");
+                context_bind_fbo(device->activeContext, GL_FRAMEBUFFER_EXT, NULL);
             }
 
@@ -4277,12 +4474,11 @@
             ENTER_GL();
 
-            GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
-            checkGLcall("glBindFramebuffer()");
-            surface_depth_blt(This, This->glDescription.textureName, This->currentDesc.Width, This->currentDesc.Height, This->glDescription.target);
+            context_bind_fbo(device->activeContext, GL_FRAMEBUFFER_EXT, NULL);
+            surface_depth_blt(This, This->texture_name, This->currentDesc.Width,
+                    This->currentDesc.Height, This->texture_target);
             checkGLcall("depth_blt");
 
             if (device->activeContext->current_fbo) {
-                GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, device->activeContext->current_fbo->id));
-                checkGLcall("glBindFramebuffer()");
+                context_bind_fbo(device->activeContext, GL_FRAMEBUFFER_EXT, &device->activeContext->current_fbo->id);
             }
 
@@ -4388,5 +4584,5 @@
     }
 
-    switch(This->glDescription.target)
+    switch (This->texture_target)
     {
         case GL_TEXTURE_2D:
@@ -4473,5 +4669,5 @@
 
         default:
-            ERR("Unexpected texture target %#x\n", This->glDescription.target);
+            ERR("Unexpected texture target %#x\n", This->texture_target);
             return;
     }
@@ -4482,6 +4678,6 @@
     glEnable(bind_target);
     checkGLcall("glEnable(bind_target)");
-    glBindTexture(bind_target, This->glDescription.textureName);
-    checkGLcall("bind_target, This->glDescription.textureName)");
+    glBindTexture(bind_target, This->texture_name);
+    checkGLcall("bind_target, This->texture_name)");
     glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     checkGLcall("glTexParameteri");
@@ -4607,4 +4803,5 @@
             surface_download_data(This);
         } else {
+            /* Note: It might be faster to download into a texture first. */
             read_from_framebuffer(This, rect,
                                   This->resource.allocatedMemory,
@@ -4633,4 +4830,5 @@
             if((convert != NO_CONVERSION) && (This->Flags & SFLAG_PBO)) {
                 TRACE("Removing the pbo attached to surface %p\n", This);
+                if (!device->isInDraw) ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
                 surface_remove_pbo(This);
             }
@@ -4879,5 +5077,4 @@
     IWineD3DSurfaceImpl_SaveSnapshot,
     IWineD3DSurfaceImpl_SetContainer,
-    IWineD3DSurfaceImpl_GetGlDesc,
     IWineD3DBaseSurfaceImpl_GetData,
     IWineD3DSurfaceImpl_SetFormat,
@@ -4892,6 +5089,8 @@
 #define GLINFO_LOCATION device->adapter->gl_info
 static HRESULT ffp_blit_alloc(IWineD3DDevice *iface) { return WINED3D_OK; }
+/* Context activation is done by the caller. */
 static void ffp_blit_free(IWineD3DDevice *iface) { }
 
+/* Context activation is done by the caller. */
 static HRESULT ffp_blit_set(IWineD3DDevice *iface, const struct GlPixelFormatDesc *format_desc,
         GLenum textype, UINT width, UINT height)
@@ -4904,4 +5103,5 @@
 }
 
+/* Context activation is done by the caller. */
 static void ffp_blit_unset(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) iface;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c	(revision 21731)
@@ -40,6 +40,4 @@
 #include "wined3d_private.h"
 
-#include <assert.h>
-
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
 
@@ -53,12 +51,12 @@
 
     /* Deal with special numbers */
-    if(*in == 0.0) return 0x0000;
+    if (*in == 0.0f) return 0x0000;
     if(_isnan(*in)) return 0x7C01;
-    if(!_finite(*in)) return (*in < 0.0 ? 0xFC00 : 0x7c00);
+    if(!_finite(*in)) return (*in < 0.0f ? 0xFC00 : 0x7c00);
 
     if(tmp < pow(2, 10)) {
         do
         {
-            tmp = tmp * 2.0;
+            tmp = tmp * 2.0f;
             exp--;
         }while(tmp < pow(2, 10));
@@ -66,5 +64,5 @@
         do
         {
-            tmp /= 2.0;
+            tmp /= 2.0f;
             exp++;
         }while(tmp >= pow(2, 11));
@@ -72,5 +70,5 @@
 
     mantissa = (unsigned int) tmp;
-    if(tmp - mantissa >= 0.5) mantissa++; /* round to nearest, away from zero */
+    if(tmp - mantissa >= 0.5f) mantissa++; /* round to nearest, away from zero */
 
     exp += 10;  /* Normalize the mantissa */
@@ -90,5 +88,5 @@
     }
 
-    ret |= ((*in < 0.0 ? 1 : 0) << 15); /* Add the sign */
+    ret |= ((*in < 0.0f ? 1 : 0) << 15); /* Add the sign */
     return ret;
 }
@@ -191,13 +189,15 @@
 
     TRACE("(%p) : copying into %p\n", This, pDesc);
-    if(pDesc->Format != NULL)             *(pDesc->Format) = This->resource.format_desc->format;
-    if(pDesc->Type != NULL)               *(pDesc->Type)   = This->resource.resourceType;
-    if(pDesc->Usage != NULL)              *(pDesc->Usage)              = This->resource.usage;
-    if(pDesc->Pool != NULL)               *(pDesc->Pool)               = This->resource.pool;
-    if(pDesc->Size != NULL)               *(pDesc->Size)               = This->resource.size;   /* dx8 only */
-    if(pDesc->MultiSampleType != NULL)    *(pDesc->MultiSampleType)    = This->currentDesc.MultiSampleType;
-    if(pDesc->MultiSampleQuality != NULL) *(pDesc->MultiSampleQuality) = This->currentDesc.MultiSampleQuality;
-    if(pDesc->Width != NULL)              *(pDesc->Width)              = This->currentDesc.Width;
-    if(pDesc->Height != NULL)             *(pDesc->Height)             = This->currentDesc.Height;
+
+    pDesc->format = This->resource.format_desc->format;
+    pDesc->resource_type = This->resource.resourceType;
+    pDesc->usage = This->resource.usage;
+    pDesc->pool = This->resource.pool;
+    pDesc->size = This->resource.size; /* dx8 only */
+    pDesc->multisample_type = This->currentDesc.MultiSampleType;
+    pDesc->multisample_quality = This->currentDesc.MultiSampleQuality;
+    pDesc->width = This->currentDesc.Width;
+    pDesc->height = This->currentDesc.Height;
+
     return WINED3D_OK;
 }
@@ -342,17 +342,17 @@
 DWORD WINAPI IWineD3DBaseSurfaceImpl_GetPitch(IWineD3DSurface *iface) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *) iface;
-    WINED3DFORMAT format = This->resource.format_desc->format;
+    const struct GlPixelFormatDesc *format_desc = This->resource.format_desc;
     DWORD ret;
     TRACE("(%p)\n", This);
 
-    /* DXTn formats don't have exact pitches as they are to the new row of blocks,
-    where each block is 4x4 pixels, 8 bytes (dxt1) and 16 bytes (dxt2/3/4/5)
-    ie pitch = (width/4) * bytes per block                                  */
-    if (format == WINED3DFMT_DXT1) /* DXT1 is 8 bytes per block */
-        ret = ((This->currentDesc.Width + 3) >> 2) << 3;
-    else if (format == WINED3DFMT_DXT2 || format == WINED3DFMT_DXT3 ||
-             format == WINED3DFMT_DXT4 || format == WINED3DFMT_DXT5) /* DXT2/3/4/5 is 16 bytes per block */
-        ret = ((This->currentDesc.Width + 3) >> 2) << 4;
-    else {
+    if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED)
+    {
+        /* Since compressed formats are block based, pitch means the amount of
+         * bytes to the next row of block rather than the next row of pixels. */
+        UINT row_block_count = (This->currentDesc.Width + format_desc->block_width - 1) / format_desc->block_width;
+        ret = row_block_count * format_desc->block_byte_count;
+    }
+    else
+    {
         unsigned char alignment = This->resource.wineD3DDevice->surface_alignment;
         ret = This->resource.format_desc->byte_count * This->currentDesc.Width;  /* Bytes / row */
@@ -529,18 +529,7 @@
 
     TRACE("(%p) : Setting texture format to (%d,%s)\n", This, format, debug_d3dformat(format));
-    if (format == WINED3DFMT_UNKNOWN) {
-        This->resource.size = 0;
-    } else if (format == WINED3DFMT_DXT1) {
-        /* DXT1 is half byte per pixel */
-        This->resource.size = ((max(This->pow2Width, 4) * format_desc->byte_count) * max(This->pow2Height, 4)) >> 1;
-
-    } else if (format == WINED3DFMT_DXT2 || format == WINED3DFMT_DXT3 ||
-               format == WINED3DFMT_DXT4 || format == WINED3DFMT_DXT5) {
-        This->resource.size = ((max(This->pow2Width, 4) * format_desc->byte_count) * max(This->pow2Height, 4));
-    } else {
-        unsigned char alignment = This->resource.wineD3DDevice->surface_alignment;
-        This->resource.size = ((This->pow2Width * format_desc->byte_count) + alignment - 1) & ~(alignment - 1);
-        This->resource.size *= This->pow2Height;
-    }
+
+    This->resource.size = surface_calculate_size(format_desc, This->resource.wineD3DDevice->surface_alignment,
+            This->pow2Width, This->pow2Height);
 
     This->Flags |= (WINED3DFMT_D16_LOCKABLE == format) ? SFLAG_LOCKABLE : 0;
@@ -745,4 +734,23 @@
 }
 
+static void convert_a8r8g8b8_x8r8g8b8(const BYTE *src, BYTE *dst,
+        DWORD pitch_in, DWORD pitch_out, unsigned int w, unsigned int h)
+{
+    unsigned int x, y;
+
+    TRACE("Converting %ux%u pixels, pitches %u %u\n", w, h, pitch_in, pitch_out);
+
+    for (y = 0; y < h; ++y)
+    {
+        const DWORD *src_line = (const DWORD *)(src + y * pitch_in);
+        DWORD *dst_line = (DWORD *)(dst + y * pitch_out);
+
+        for (x = 0; x < w; ++x)
+        {
+            dst_line[x] = 0xff000000 | (src_line[x] & 0xffffff);
+        }
+    }
+}
+
 struct d3dfmt_convertor_desc {
     WINED3DFORMAT from, to;
@@ -754,4 +762,5 @@
     {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},
 };
 
@@ -791,8 +800,7 @@
     }
 
-    IWineD3DDevice_CreateSurface((IWineD3DDevice *)source->resource.wineD3DDevice,
-            source->currentDesc.Width, source->currentDesc.Height, to_fmt, TRUE /* lockable */,
-            TRUE /* discard  */, 0 /* level */, &ret, WINED3DRTYPE_SURFACE, 0 /* usage */,
-            WINED3DPOOL_SCRATCH, WINED3DMULTISAMPLE_NONE /* TODO: Multisampled conversion */,
+    IWineD3DDevice_CreateSurface((IWineD3DDevice *)source->resource.wineD3DDevice, source->currentDesc.Width,
+            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 */);
     if(!ret) {
@@ -1136,6 +1144,4 @@
     dstwidth = xdst.right - xdst.left;
     width = (xdst.right - xdst.left) * bpp;
-
-    assert(width <= dlock.Pitch);
 
     if (DestRect && Src != This)
@@ -1639,5 +1645,4 @@
 
         /* Since slock was originally copied from this surface's description, we can just reuse it */
-        assert(This->resource.allocatedMemory != NULL);
         sbuf = This->resource.allocatedMemory + lock_src.top * pitch + lock_src.left * bpp;
         dbuf = This->resource.allocatedMemory + lock_dst.top * pitch + lock_dst.left * bpp;
@@ -1660,49 +1665,25 @@
     }
 
-    /* Handle first the FOURCC surfaces... */
-    if (sEntry->Flags & dEntry->Flags & WINED3DFMT_FLAG_FOURCC)
-    {
-        UINT block_width;
-        UINT block_height;
-        UINT block_byte_size;
-
-        TRACE("Fourcc -> Fourcc copy\n");
+    /* Handle compressed surfaces first... */
+    if (sEntry->Flags & dEntry->Flags & WINED3DFMT_FLAG_COMPRESSED)
+    {
+        UINT row_block_count;
+
+        TRACE("compressed -> compressed copy\n");
         if (trans)
-            FIXME("trans arg not supported when a FOURCC surface is involved\n");
+            FIXME("trans arg not supported when a compressed surface is involved\n");
         if (dstx || dsty)
             FIXME("offset for destination surface is not supported\n");
         if (Src->resource.format_desc->format != This->resource.format_desc->format)
         {
-            FIXME("FOURCC->FOURCC copy only supported for the same type of surface\n");
+            FIXME("compressed -> compressed copy only supported for the same type of surface\n");
             ret = WINED3DERR_WRONGTEXTUREFORMAT;
             goto error;
         }
 
-        if (This->resource.format_desc->format == WINED3DFMT_DXT1)
-        {
-            block_width = 4;
-            block_height = 4;
-            block_byte_size = 8;
-        }
-        else if (This->resource.format_desc->format == WINED3DFMT_DXT2
-                || This->resource.format_desc->format == WINED3DFMT_DXT3
-                || This->resource.format_desc->format == WINED3DFMT_DXT4
-                || This->resource.format_desc->format == WINED3DFMT_DXT5)
-        {
-            block_width = 4;
-            block_height = 4;
-            block_byte_size = 16;
-        }
-        else
-        {
-            FIXME("Unsupported FourCC format %s.\n", debug_d3dformat(This->resource.format_desc->format));
-            block_width = 1;
-            block_height = 1;
-            block_byte_size = This->resource.format_desc->byte_count;
-        }
-
-        for (y = 0; y < h; y += block_height)
-        {
-            memcpy(dbuf, sbuf, (w / block_width) * block_byte_size);
+        row_block_count = (w + dEntry->block_width - 1) / dEntry->block_width;
+        for (y = 0; y < h; y += dEntry->block_height)
+        {
+            memcpy(dbuf, sbuf, row_block_count * dEntry->block_byte_count);
             dbuf += dlock.Pitch;
             sbuf += slock.Pitch;
@@ -1711,10 +1692,10 @@
         goto error;
     }
-    if ((sEntry->Flags & WINED3DFMT_FLAG_FOURCC) && !(dEntry->Flags & WINED3DFMT_FLAG_FOURCC))
+    if ((sEntry->Flags & WINED3DFMT_FLAG_COMPRESSED) && !(dEntry->Flags & WINED3DFMT_FLAG_COMPRESSED))
     {
         /* TODO: Use the libtxc_dxtn.so shared library to do
          * software decompression
          */
-        ERR("DXTC decompression not supported by now\n");
+        ERR("Software decompression not supported.\n");
         goto error;
     }
@@ -1854,24 +1835,16 @@
     else
     {
+        const struct GlPixelFormatDesc *format_desc = This->resource.format_desc;
+
         TRACE("Lock Rect (%p) = l %d, t %d, r %d, b %d\n",
               pRect, pRect->left, pRect->top, pRect->right, pRect->bottom);
 
-        /* DXTn textures are based on compressed blocks of 4x4 pixels, each
-         * 16 bytes large (8 bytes in case of DXT1). Because of that Pitch has
-         * slightly different meaning compared to regular textures. For DXTn
-         * textures Pitch is the size of a row of blocks, 4 high and "width"
-         * long. The x offset is calculated differently as well, since moving 4
-         * pixels to the right actually moves an entire 4x4 block to right, ie
-         * 16 bytes (8 in case of DXT1). */
-        if (This->resource.format_desc->format == WINED3DFMT_DXT1)
-        {
-            pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top / 4) + (pRect->left * 2);
-        }
-        else if (This->resource.format_desc->format == WINED3DFMT_DXT2
-                || This->resource.format_desc->format == WINED3DFMT_DXT3
-                || This->resource.format_desc->format == WINED3DFMT_DXT4
-                || This->resource.format_desc->format == WINED3DFMT_DXT5)
-        {
-            pLockedRect->pBits = This->resource.allocatedMemory + (pLockedRect->Pitch * pRect->top / 4) + (pRect->left * 4);
+        if (format_desc->Flags & WINED3DFMT_FLAG_COMPRESSED)
+        {
+            /* Compressed textures are block based, so calculate the offset of
+             * the block that contains the top-left pixel of the locked rectangle. */
+            pLockedRect->pBits = This->resource.allocatedMemory
+                    + ((pRect->top / format_desc->block_height) * pLockedRect->Pitch)
+                    + ((pRect->left / format_desc->block_width) * format_desc->block_byte_count);
         }
         else
@@ -1879,5 +1852,5 @@
             pLockedRect->pBits = This->resource.allocatedMemory +
                     (pLockedRect->Pitch * pRect->top) +
-                    (pRect->left * This->resource.format_desc->byte_count);
+                    (pRect->left * format_desc->byte_count);
         }
         This->lockedRect.left   = pRect->left;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_gdi.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_gdi.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_gdi.c	(revision 21731)
@@ -39,9 +39,31 @@
 #include "wined3d_private.h"
 
-#include <assert.h>
 #include <stdio.h>
 
 /* Use the d3d_surface debug channel to have one channel for all surfaces */
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_surface);
+
+void surface_gdi_cleanup(IWineD3DSurfaceImpl *This)
+{
+    TRACE("(%p) : Cleaning up.\n", This);
+
+    if (This->Flags & SFLAG_DIBSECTION)
+    {
+        /* Release the DC. */
+        SelectObject(This->hDC, This->dib.holdbitmap);
+        DeleteDC(This->hDC);
+        /* Release the DIB section. */
+        DeleteObject(This->dib.DIBsection);
+        This->dib.bitmap_data = NULL;
+        This->resource.allocatedMemory = NULL;
+    }
+
+    if (This->Flags & SFLAG_USERPTR) IWineD3DSurface_SetMem((IWineD3DSurface *)This, NULL);
+    if (This->overlay_dest) list_remove(&This->overlay_entry);
+
+    HeapFree(GetProcessHeap(), 0, This->palette9);
+
+    resource_cleanup((IWineD3DResource *)This);
+}
 
 /*****************************************************************************
@@ -56,30 +78,13 @@
     ULONG ref = InterlockedDecrement(&This->resource.ref);
     TRACE("(%p) : Releasing from %d\n", This, ref + 1);
-    if (ref == 0) {
-        TRACE("(%p) : cleaning up\n", This);
-
-        if(This->Flags & SFLAG_DIBSECTION) {
-            /* Release the DC */
-            SelectObject(This->hDC, This->dib.holdbitmap);
-            DeleteDC(This->hDC);
-            /* Release the DIB section */
-            DeleteObject(This->dib.DIBsection);
-            This->dib.bitmap_data = NULL;
-            This->resource.allocatedMemory = NULL;
-        }
-        if(This->Flags & SFLAG_USERPTR) IWineD3DSurface_SetMem(iface, NULL);
-
-        HeapFree(GetProcessHeap(), 0, This->palette9);
-
-        resource_cleanup((IWineD3DResource *)iface);
-
-        if(This->overlay_dest) {
-            list_remove(&This->overlay_entry);
-        }
-
-        TRACE("(%p) Released\n", This);
+
+    if (!ref)
+    {
+        surface_gdi_cleanup(This);
+
+        TRACE("(%p) Released.\n", This);
         HeapFree(GetProcessHeap(), 0, This);
-
-    }
+    }
+
     return ref;
 }
@@ -188,5 +193,6 @@
             ++gen;
             if ((gen % 10) == 0) {
-                snprintf(buffer, sizeof(buffer), "/tmp/surface%p_type%u_level%u_%u.ppm", This, This->glDescription.target, This->glDescription.level, gen);
+                snprintf(buffer, sizeof(buffer), "/tmp/surface%p_type%u_level%u_%u.ppm",
+                        This, This->texture_target, This->texture_level, gen);
                 IWineD3DSurfaceImpl_SaveSnapshot(iface, buffer);
             }
@@ -204,5 +210,8 @@
     if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapchain)))
     {
-        x11_copy_to_screen(swapchain, &This->lockedRect);
+        if(iface == swapchain->frontBuffer)
+        {
+            x11_copy_to_screen(swapchain, &This->lockedRect);
+        }
         IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
     }
@@ -495,5 +504,8 @@
     if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DSwapChain, (void **)&swapchain)))
     {
-        x11_copy_to_screen(swapchain, NULL);
+        if(iface == swapchain->frontBuffer)
+        {
+            x11_copy_to_screen(swapchain, NULL);
+        }
         IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
     }
@@ -544,10 +556,4 @@
 
     return WINED3D_OK;
-}
-
-static void WINAPI IWineGDISurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription) {
-    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-    FIXME("(%p) : Should not be called on a GDI surface\n", This);
-    *glDescription = NULL;
 }
 
@@ -681,5 +687,4 @@
     IWineGDISurfaceImpl_SaveSnapshot,
     IWineD3DBaseSurfaceImpl_SetContainer,
-    IWineGDISurfaceImpl_GetGlDesc,
     IWineD3DBaseSurfaceImpl_GetData,
     IWineD3DBaseSurfaceImpl_SetFormat,
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/swapchain.c	(revision 21731)
@@ -74,5 +74,22 @@
     }
 
-    for(i = 0; i < This->num_contexts; i++) {
+    for (i = 0; i < This->num_contexts; ++i)
+    {
+        if (This->context[i] == This->wineD3DDevice->activeContext)
+        {
+            IWineD3DSwapChainImpl *swapchain = (IWineD3DSwapChainImpl *)This->wineD3DDevice->swapchains[0];
+
+            /* Avoid destroying the currently active context for non-implicit swapchains. */
+            if (This != swapchain)
+            {
+                TRACE("Would destroy currently active context %p on a non-implicit swapchain.\n", This->context[i]);
+
+                if (swapchain->backBuffer)
+                    ActivateContext(This->wineD3DDevice, swapchain->backBuffer[0], CTXUSAGE_RESOURCELOAD);
+                else
+                    ActivateContext(This->wineD3DDevice, swapchain->frontBuffer, CTXUSAGE_RESOURCELOAD);
+            }
+        }
+
         DestroyContext(This->wineD3DDevice, This->context[i]);
     }
@@ -121,7 +138,7 @@
         cursor.resource.format_desc = getFormatDescEntry(WINED3DFMT_A8R8G8B8, &This->wineD3DDevice->adapter->gl_info);
         cursor.resource.resourceType = WINED3DRTYPE_SURFACE;
-        cursor.glDescription.textureName = This->wineD3DDevice->cursorTexture;
-        cursor.glDescription.target = GL_TEXTURE_2D;
-        cursor.glDescription.level = 0;
+        cursor.texture_name = This->wineD3DDevice->cursorTexture;
+        cursor.texture_target = GL_TEXTURE_2D;
+        cursor.texture_level = 0;
         cursor.currentDesc.Width = This->wineD3DDevice->cursorWidth;
         cursor.currentDesc.Height = This->wineD3DDevice->cursorHeight;
@@ -233,5 +250,5 @@
 
         IWineD3DDevice_Clear((IWineD3DDevice*)This->wineD3DDevice, 0, NULL,
-                              WINED3DCLEAR_TARGET, 0xff00ffff, 1.0, 0);
+                WINED3DCLEAR_TARGET, 0xff00ffff, 1.0f, 0);
     }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c	(revision 21731)
@@ -137,5 +137,5 @@
         IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
 {
-    const WineD3D_GL_Info *gl_info = &device->adapter->gl_info;
+    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;
@@ -224,8 +224,8 @@
     if (GL_SUPPORT(WINE_NORMALIZED_TEXRECT) && (width != pow2_width || height != pow2_height))
     {
-        texture->baseTexture.pow2Matrix[0] = 1.0;
-        texture->baseTexture.pow2Matrix[5] = 1.0;
-        texture->baseTexture.pow2Matrix[10] = 1.0;
-        texture->baseTexture.pow2Matrix[15] = 1.0;
+        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;
@@ -241,6 +241,6 @@
         texture->baseTexture.pow2Matrix[0] = (float)width;
         texture->baseTexture.pow2Matrix[5] = (float)height;
-        texture->baseTexture.pow2Matrix[10] = 1.0;
-        texture->baseTexture.pow2Matrix[15] = 1.0;
+        texture->baseTexture.pow2Matrix[10] = 1.0f;
+        texture->baseTexture.pow2Matrix[15] = 1.0f;
         texture->target = GL_TEXTURE_RECTANGLE_ARB;
         texture->cond_np2 = TRUE;
@@ -257,10 +257,10 @@
         else
         {
-            texture->baseTexture.pow2Matrix[0] = 1.0;
-            texture->baseTexture.pow2Matrix[5] = 1.0;
-        }
-
-        texture->baseTexture.pow2Matrix[10] = 1.0;
-        texture->baseTexture.pow2Matrix[15] = 1.0;
+            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;
@@ -432,4 +432,5 @@
 }
 
+/* Context activation is done by the caller. */
 static HRESULT WINAPI IWineD3DTextureImpl_BindTexture(IWineD3DTexture *iface, BOOL srgb) {
     IWineD3DTextureImpl *This = (IWineD3DTextureImpl *)iface;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/utils.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/utils.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/utils.c	(revision 21731)
@@ -101,12 +101,12 @@
     {WINED3DFMT_A8R3G3B2,           0x0000ff00, 0x000000e0, 0x0000001c, 0x00000003, 2,      0,      0,      FALSE},
     {WINED3DFMT_X4R4G4B4,           0x0,        0x00000f00, 0x000000f0, 0x0000000f, 2,      0,      0,      FALSE},
-    {WINED3DFMT_R10G10B10A2_UNORM,  0xb0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R10G10B10A2_UINT,   0xb0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      0,      0,      FALSE},
-    {WINED3DFMT_R10G10B10A2_SNORM,  0xb0000000, 0x000003ff, 0x000ffc00, 0x3ff00000, 4,      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,        0xb0000000, 0x3ff00000, 0x000ffc00, 0x000003ff, 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},
     /* Luminance */
@@ -142,4 +142,22 @@
     {WINED3DFMT_NVHU,               0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
     {WINED3DFMT_NVHS,               0x0,        0x0,        0x0,        0x0,        2,      0,      0,      TRUE },
+};
+
+struct wined3d_format_compression_info
+{
+    WINED3DFORMAT format;
+    UINT block_width;
+    UINT block_height;
+    UINT block_byte_count;
+};
+
+static const struct wined3d_format_compression_info format_compression_info[] =
+{
+    {WINED3DFMT_DXT1,   4,  4,  8},
+    {WINED3DFMT_DXT2,   4,  4,  16},
+    {WINED3DFMT_DXT3,   4,  4,  16},
+    {WINED3DFMT_DXT4,   4,  4,  16},
+    {WINED3DFMT_DXT5,   4,  4,  16},
+    {WINED3DFMT_ATI2N,  4,  4,  16},
 };
 
@@ -345,5 +363,5 @@
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_R16G16_UNORM,       GL_RGB16_EXT,                     GL_RGB16_EXT,                           0,
+    {WINED3DFMT_R16G16_UNORM,       GL_RGB16_EXT,                     GL_RGB16_EXT,                           GL_RGBA16_EXT,
             GL_RGB,                 GL_UNSIGNED_SHORT,
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
@@ -456,16 +474,12 @@
             WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING | WINED3DFMT_FLAG_FILTERING,
             WINED3D_GL_EXT_NONE},
-    {WINED3DFMT_D32F_LOCKABLE,      GL_DEPTH_COMPONENT32_ARB,         GL_DEPTH_COMPONENT32_ARB,               0,
+    {WINED3DFMT_D32F_LOCKABLE,      GL_DEPTH_COMPONENT32F,            GL_DEPTH_COMPONENT32F,                  0,
             GL_DEPTH_COMPONENT,     GL_FLOAT,
             WINED3DFMT_FLAG_DEPTH,
-            ARB_DEPTH_TEXTURE},
-    {WINED3DFMT_D24FS8,             GL_DEPTH_COMPONENT24_ARB,         GL_DEPTH_COMPONENT24_ARB,               0,
-            GL_DEPTH_COMPONENT,     GL_FLOAT,
-            WINED3DFMT_FLAG_DEPTH,
-            ARB_DEPTH_TEXTURE},
-    {WINED3DFMT_D24FS8,             GL_DEPTH24_STENCIL8_EXT,          GL_DEPTH24_STENCIL8_EXT,                0,
-            GL_DEPTH_STENCIL_EXT,   GL_UNSIGNED_INT_24_8_EXT,
+            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_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL,
-            EXT_PACKED_DEPTH_STENCIL},
+            ARB_DEPTH_BUFFER_FLOAT},
     /* Vendor-specific formats */
     {WINED3DFMT_ATI2N,              GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, 0,
@@ -496,5 +510,5 @@
 }
 
-static BOOL init_format_base_info(WineD3D_GL_Info *gl_info)
+static BOOL init_format_base_info(struct wined3d_gl_info *gl_info)
 {
     UINT format_count = sizeof(formats) / sizeof(*formats);
@@ -525,75 +539,196 @@
 }
 
+static BOOL init_format_compression_info(struct wined3d_gl_info *gl_info)
+{
+    unsigned int i;
+
+    for (i = 0; i < (sizeof(format_compression_info) / sizeof(*format_compression_info)); ++i)
+    {
+        struct GlPixelFormatDesc *format_desc;
+        int fmt_idx = getFmtIdx(format_compression_info[i].format);
+
+        if (fmt_idx == -1)
+        {
+            ERR("Format %s (%#x) not found.\n",
+                    debug_d3dformat(format_compression_info[i].format), format_compression_info[i].format);
+            return FALSE;
+        }
+
+        format_desc = &gl_info->gl_formats[fmt_idx];
+        format_desc->block_width = format_compression_info[i].block_width;
+        format_desc->block_height = format_compression_info[i].block_height;
+        format_desc->block_byte_count = format_compression_info[i].block_byte_count;
+        format_desc->Flags |= WINED3DFMT_FLAG_COMPRESSED;
+    }
+
+    return TRUE;
+}
+
 #define GLINFO_LOCATION (*gl_info)
 
-static BOOL check_fbo_compat(const WineD3D_GL_Info *gl_info, GLint internal_format, GLenum format, GLenum type)
-{
-    GLuint tex, fb;
+/* Context activation is done by the caller. */
+static void check_fbo_compat(const struct wined3d_gl_info *gl_info, struct GlPixelFormatDesc *format_desc)
+{
+    /* Check if the default internal format is supported as a frame buffer
+     * target, otherwise fall back to the render target internal.
+     *
+     * Try to stick to the standard format if possible, this limits precision differences. */
     GLenum status;
+    GLuint tex;
 
     ENTER_GL();
 
     while(glGetError());
+    glDisable(GL_BLEND);
+
     glGenTextures(1, &tex);
     glBindTexture(GL_TEXTURE_2D, tex);
-    glTexImage2D(GL_TEXTURE_2D, 0, internal_format, 16, 16, 0, format, type, NULL);
+
+    glTexImage2D(GL_TEXTURE_2D, 0, format_desc->glInternal, 16, 16, 0,
+            format_desc->glFormat, format_desc->glType, NULL);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
-    GL_EXTCALL(glGenFramebuffersEXT(1, &fb));
-    GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb));
     GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0));
 
     status = GL_EXTCALL(glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT));
-    GL_EXTCALL(glDeleteFramebuffersEXT(1, &fb));
-    glDeleteTextures(1, &tex);
-
     checkGLcall("Framebuffer format check");
 
-    LEAVE_GL();
-
-    return status == GL_FRAMEBUFFER_COMPLETE_EXT;
-}
-
-static void init_format_fbo_compat_info(WineD3D_GL_Info *gl_info)
-{
-    unsigned int i;
-
-    for (i = 0; i < sizeof(formats) / sizeof(*formats); ++i)
-    {
-        struct GlPixelFormatDesc *desc = &gl_info->gl_formats[i];
-
-        if (!desc->glInternal) continue;
-
-        if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
+    if (status == GL_FRAMEBUFFER_COMPLETE_EXT)
+    {
+        TRACE("Format %s is supported as FBO color attachment\n", debug_d3dformat(format_desc->format));
+        format_desc->Flags |= WINED3DFMT_FLAG_FBO_ATTACHABLE;
+        format_desc->rtInternal = format_desc->glInternal;
+    }
+    else
+    {
+        if (!format_desc->rtInternal)
         {
-            /* Check if the default internal format is supported as a frame buffer target, otherwise
-             * fall back to the render target internal.
-             *
-             * Try to stick to the standard format if possible, this limits precision differences. */
-            if (check_fbo_compat(gl_info, desc->glInternal, desc->glFormat, desc->glType))
+            if (format_desc->Flags & WINED3DFMT_FLAG_RENDERTARGET)
             {
-                TRACE("Format %s is supported as fbo target\n", debug_d3dformat(desc->format));
-                desc->Flags |= WINED3DFMT_FLAG_FBO_ATTACHABLE;
-                desc->rtInternal = desc->glInternal;
+                FIXME("Format %s with rendertarget flag is not supported as FBO color attachment,"
+                        " and no fallback specified.\n", debug_d3dformat(format_desc->format));
+                format_desc->Flags &= ~WINED3DFMT_FLAG_RENDERTARGET;
             }
             else
             {
-                if (!desc->rtInternal)
-                {
-                    if (desc->Flags & WINED3DFMT_FLAG_RENDERTARGET)
-                    {
-                        FIXME("Internal format of %s not supported as FBO target, and no fallback specified.\n",
-                                debug_d3dformat(desc->format));
-                        desc->Flags &= ~WINED3DFMT_FLAG_RENDERTARGET;
-                    }
-                    desc->rtInternal = desc->glInternal;
-                }
-                else
-                {
-                    TRACE("Internal format of %s not supported as FBO target, using render target internal instead.\n",
-                            debug_d3dformat(desc->format));
-                }
+                TRACE("Format %s is not supported as FBO color attachment.\n", debug_d3dformat(format_desc->format));
             }
+            format_desc->rtInternal = format_desc->glInternal;
+        }
+        else
+        {
+            TRACE("Format %s is not supported as FBO color attachment, trying rtInternal format as fallback.\n",
+                    debug_d3dformat(format_desc->format));
+
+            while(glGetError());
+
+            GL_EXTCALL(glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 0, 0));
+
+            glTexImage2D(GL_TEXTURE_2D, 0, format_desc->rtInternal, 16, 16, 0,
+                    format_desc->glFormat, format_desc->glType, NULL);
+            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+            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));
+            checkGLcall("Framebuffer format check");
+
+            if (status == GL_FRAMEBUFFER_COMPLETE_EXT)
+            {
+                TRACE("Format %s rtInternal format is supported as FBO color attachment\n",
+                        debug_d3dformat(format_desc->format));
+            }
+            else
+            {
+                FIXME("Format %s rtInternal format is not supported as FBO color attachment.\n",
+                        debug_d3dformat(format_desc->format));
+                format_desc->Flags &= ~WINED3DFMT_FLAG_RENDERTARGET;
+            }
+        }
+    }
+
+    if (status == GL_FRAMEBUFFER_COMPLETE_EXT && format_desc->Flags & WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING)
+    {
+        GLuint rb;
+
+        if (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));
+            checkGLcall("RB attachment");
+        }
+
+        glEnable(GL_BLEND);
+        glClear(GL_COLOR_BUFFER_BIT);
+        if (glGetError() == GL_INVALID_FRAMEBUFFER_OPERATION_EXT)
+        {
+            while(glGetError());
+            TRACE("Format doesn't support post-pixelshader blending.\n");
+            format_desc->Flags &= ~WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
+        }
+
+        if (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));
+            checkGLcall("RB cleanup");
+        }
+    }
+
+    glDeleteTextures(1, &tex);
+
+    LEAVE_GL();
+}
+
+/* Context activation is done by the caller. */
+static void init_format_fbo_compat_info(struct wined3d_gl_info *gl_info)
+{
+    unsigned int i;
+    GLuint fbo;
+
+    if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
+    {
+        ENTER_GL();
+
+        GL_EXTCALL(glGenFramebuffersEXT(1, &fbo));
+        GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo));
+
+        LEAVE_GL();
+    }
+
+    for (i = 0; i < sizeof(formats) / sizeof(*formats); ++i)
+    {
+        struct GlPixelFormatDesc *desc = &gl_info->gl_formats[i];
+
+        if (!desc->glInternal) continue;
+
+        if (desc->Flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
+        {
+            TRACE("Skipping format %s because it's a depth/stencil format.\n",
+                    debug_d3dformat(desc->format));
+            continue;
+        }
+
+        if (desc->Flags & WINED3DFMT_FLAG_COMPRESSED)
+        {
+            TRACE("Skipping format %s because it's a compressed format.\n",
+                    debug_d3dformat(desc->format));
+            continue;
+        }
+
+        if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
+        {
+            TRACE("Checking if format %s is supported as FBO color attachment...\n", debug_d3dformat(desc->format));
+            check_fbo_compat(gl_info, desc);
         }
         else
@@ -602,7 +737,16 @@
         }
     }
-}
-
-static BOOL init_format_texture_info(WineD3D_GL_Info *gl_info)
+
+    if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
+    {
+        ENTER_GL();
+
+        GL_EXTCALL(glDeleteFramebuffersEXT(1, &fbo));
+
+        LEAVE_GL();
+    }
+}
+
+static BOOL init_format_texture_info(struct wined3d_gl_info *gl_info)
 {
     unsigned int i;
@@ -630,5 +774,5 @@
         desc->color_fixup = COLOR_FIXUP_IDENTITY;
         desc->Flags |= gl_formats_template[i].Flags;
-        desc->heightscale = 1.0;
+        desc->heightscale = 1.0f;
     }
 
@@ -636,5 +780,5 @@
 }
 
-static void apply_format_fixups(WineD3D_GL_Info *gl_info)
+static void apply_format_fixups(struct wined3d_gl_info *gl_info)
 {
     int idx;
@@ -735,5 +879,5 @@
 
     idx = getFmtIdx(WINED3DFMT_YV12);
-    gl_info->gl_formats[idx].heightscale = 1.5;
+    gl_info->gl_formats[idx].heightscale = 1.5f;
     gl_info->gl_formats[idx].color_fixup = create_yuv_fixup_desc(YUV_FIXUP_YV12);
 
@@ -756,5 +900,5 @@
 }
 
-static BOOL init_format_vertex_info(WineD3D_GL_Info *gl_info)
+static BOOL init_format_vertex_info(struct wined3d_gl_info *gl_info)
 {
     unsigned int i;
@@ -784,14 +928,9 @@
 }
 
-BOOL initPixelFormatsNoGL(WineD3D_GL_Info *gl_info)
-{
-    return init_format_base_info(gl_info);
-}
-
-BOOL initPixelFormats(WineD3D_GL_Info *gl_info)
+BOOL initPixelFormatsNoGL(struct wined3d_gl_info *gl_info)
 {
     if (!init_format_base_info(gl_info)) return FALSE;
 
-    if (!init_format_texture_info(gl_info))
+    if (!init_format_compression_info(gl_info))
     {
         HeapFree(GetProcessHeap(), 0, gl_info->gl_formats);
@@ -799,9 +938,15 @@
     }
 
-    if (!init_format_vertex_info(gl_info))
-    {
-        HeapFree(GetProcessHeap(), 0, gl_info->gl_formats);
-        return FALSE;
-    }
+    return TRUE;
+}
+
+/* Context activation is done by the caller. */
+BOOL initPixelFormats(struct wined3d_gl_info *gl_info)
+{
+    if (!init_format_base_info(gl_info)) return FALSE;
+
+    if (!init_format_compression_info(gl_info)) goto fail;
+    if (!init_format_texture_info(gl_info)) goto fail;
+    if (!init_format_vertex_info(gl_info)) goto fail;
 
     apply_format_fixups(gl_info);
@@ -809,4 +954,8 @@
 
     return TRUE;
+
+fail:
+    HeapFree(GetProcessHeap(), 0, gl_info->gl_formats);
+    return FALSE;
 }
 
@@ -815,5 +964,5 @@
 #define GLINFO_LOCATION This->adapter->gl_info
 
-const struct GlPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, const WineD3D_GL_Info *gl_info)
+const struct GlPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, const struct wined3d_gl_info *gl_info)
 {
     int idx = getFmtIdx(fmt);
@@ -1890,5 +2039,6 @@
     if(!(This->Flags & SFLAG_OVERSIZE)) {
         /* Which rect from the texture do I need? */
-        if(This->glDescription.target == GL_TEXTURE_RECTANGLE_ARB) {
+        if (This->texture_target == GL_TEXTURE_RECTANGLE_ARB)
+        {
             glTexCoord[0] = (float) Rect->left;
             glTexCoord[2] = (float) Rect->top;
@@ -2028,4 +2178,5 @@
     DWORD ttff;
     DWORD cop, aop, carg0, carg1, carg2, aarg0, aarg1, aarg2;
+    IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
 
     for(i = 0; i < GL_LIMITS(texture_stages); i++) {
@@ -2081,6 +2232,5 @@
         carg0 = (args[cop] & ARG0) ? stateblock->textureState[i][WINED3DTSS_COLORARG0] : ARG_UNUSED;
 
-        if(is_invalid_op(stateblock->wineD3DDevice, i, cop,
-                         carg1, carg2, carg0)) {
+        if(is_invalid_op(device, i, cop, carg1, carg2, carg0)) {
             carg0 = ARG_UNUSED;
             carg2 = ARG_UNUSED;
@@ -2141,6 +2291,5 @@
         }
 
-        if(is_invalid_op(stateblock->wineD3DDevice, i, aop,
-           aarg1, aarg2, aarg0)) {
+        if(is_invalid_op(device, i, aop, aarg1, aarg2, aarg0)) {
                aarg0 = ARG_UNUSED;
                aarg2 = ARG_UNUSED;
@@ -2220,4 +2369,12 @@
     } else {
         settings->sRGB_write = 0;
+    }
+    if(device->vs_clipping || !use_vs(stateblock)) {
+        /* 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)
+         */
+        settings->emul_clipplanes = 0;
+    } else {
+        settings->emul_clipplanes = 1;
     }
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexshader.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexshader.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/vertexshader.c	(revision 21731)
@@ -72,8 +72,4 @@
         case WINED3D_SHADER_VERSION(2,1):
             This->baseShader.limits.temporary = 12;
-        case WINED3D_SHADER_VERSION(4,0):
-            FIXME("Using 3.0 limits for 4.0 shader\n");
-            /* Fall through */
-
             This->baseShader.limits.constant_bool = 16;
             This->baseShader.limits.constant_int = 16;
@@ -84,4 +80,8 @@
             This->baseShader.limits.constant_float = min(256, GL_LIMITS(vshader_constantsF));
             break;
+
+        case WINED3D_SHADER_VERSION(4,0):
+            FIXME("Using 3.0 limits for 4.0 shader\n");
+            /* Fall through */
 
         case WINED3D_SHADER_VERSION(3,0):
@@ -290,8 +290,8 @@
     vshader_set_limits(This);
 
-    if(deviceImpl->vs_selected_mode == SHADER_ARB &&
-       (GLINFO_LOCATION).arb_vs_offset_limit      &&
-       This->min_rel_offset <= This->max_rel_offset) {
-
+    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) {
             FIXME("The difference between the minimum and maximum relative offset is > 127\n");
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c	(revision 21731)
@@ -36,4 +36,5 @@
 #define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
 
+/* Context activation is done by the caller. */
 static void volume_bind_and_dirtify(IWineD3DVolume *iface) {
     IWineD3DVolumeImpl *This = (IWineD3DVolumeImpl *)iface;
@@ -206,12 +207,13 @@
     TRACE("(%p) : copying into %p\n", This, pDesc);
 
-    *(pDesc->Format)  = This->resource.format_desc->format;
-    *(pDesc->Type)    = This->resource.resourceType;
-    *(pDesc->Usage)   = This->resource.usage;
-    *(pDesc->Pool)    = This->resource.pool;
-    *(pDesc->Size)    = This->resource.size; /* dx8 only */
-    *(pDesc->Width)   = This->currentDesc.Width;
-    *(pDesc->Height)  = This->currentDesc.Height;
-    *(pDesc->Depth)   = This->currentDesc.Depth;
+    pDesc->Format = This->resource.format_desc->format;
+    pDesc->Type = This->resource.resourceType;
+    pDesc->Usage = This->resource.usage;
+    pDesc->Pool = This->resource.pool;
+    pDesc->Size = This->resource.size; /* dx8 only */
+    pDesc->Width = This->currentDesc.Width;
+    pDesc->Height = This->currentDesc.Height;
+    pDesc->Depth = This->currentDesc.Depth;
+
     return WINED3D_OK;
 }
@@ -310,4 +312,5 @@
 }
 
+/* Context activation is done by the caller. */
 static HRESULT WINAPI IWineD3DVolumeImpl_LoadTexture(IWineD3DVolume *iface, int gl_level, BOOL srgb_mode) {
     IWineD3DVolumeImpl *This     = (IWineD3DVolumeImpl *)iface;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volumetexture.c	(revision 21731)
@@ -42,5 +42,5 @@
     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
     IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
-    const WineD3D_GL_Info *gl_info = &device->adapter->gl_info;
+    const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
     BOOL srgb_mode = This->baseTexture.is_srgb;
     BOOL srgb_was_toggled = FALSE;
@@ -109,5 +109,5 @@
         IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool, IUnknown *parent)
 {
-    const WineD3D_GL_Info *gl_info = &device->adapter->gl_info;
+    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;
@@ -172,8 +172,8 @@
 
     /* Is NP2 support for volumes needed? */
-    texture->baseTexture.pow2Matrix[0] = 1.0;
-    texture->baseTexture.pow2Matrix[5] = 1.0;
-    texture->baseTexture.pow2Matrix[10] = 1.0;
-    texture->baseTexture.pow2Matrix[15] = 1.0;
+    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. */
@@ -341,4 +341,5 @@
 }
 
+/* Context activation is done by the caller. */
 static HRESULT WINAPI IWineD3DVolumeTextureImpl_BindTexture(IWineD3DVolumeTexture *iface, BOOL srgb) {
     IWineD3DVolumeTextureImpl *This = (IWineD3DVolumeTextureImpl *)iface;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_gl.h	(revision 21731)
@@ -1527,4 +1527,12 @@
 typedef void (WINE_GLAPI *PGLFNCLAMPCOLORARBPROC) (GLenum target, GLenum clamp);
 
+/* GL_ARB_depth_buffer_float */
+#ifndef GL_ARB_depth_buffer_float
+#define GL_ARB_depth_buffer_float 1
+#define GL_DEPTH_COMPONENT32F             0x8cac
+#define GL_DEPTH32F_STENCIL8              0x8cad
+#define GL_FLOAT_32_UNSIGNED_INT_24_8_REV 0x8dad
+#endif
+
 /* GL_ARB_depth_texture */
 #ifndef GL_ARB_depth_texture
@@ -1898,4 +1906,13 @@
 typedef void (WINE_GLAPI * PGLFNGLBLITFRAMEBUFFEREXTPROC) (GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter);
 
+/* GL_EXT_framebuffer_multisample */
+#ifndef GL_EXT_framebuffer_multisample
+#define GL_EXT_framebuffer_multisample 1
+#define GL_RENDERBUFFER_SAMPLES_EXT                 0x8cab
+#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT   0x8d56
+#define GL_MAX_SAMPLES_EXT                          0x8d57
+#endif
+typedef void (WINE_GLAPI * PGLFNRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
+
 /* GL_EXT_packed_depth_stencil */
 #ifndef GL_EXT_packed_depth_stencil
@@ -1906,13 +1923,4 @@
 #define GL_TEXTURE_STENCIL_SIZE_EXT         0x88f1
 #endif
-
-/* GL_EXT_framebuffer_multisample */
-#ifndef GL_EXT_framebuffer_multisample
-#define GL_EXT_framebuffer_multisample 1
-#define GL_RENDERBUFFER_SAMPLES_EXT                 0x8cab
-#define GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT   0x8d56
-#define GL_MAX_SAMPLES_EXT                          0x8d57
-#endif
-typedef void (WINE_GLAPI * PGLFNRENDERBUFFERSTORAGEMULTISAMPLEEXTPROC)(GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height);
 
 /* GL_EXT_secondary_color */
@@ -3090,11 +3098,4 @@
 #define GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI 0x8837
 #endif
-/* GL_NV_vertex_program2_option */
-#ifndef GL_NV_vertex_program2_option
-#define GL_NV_vertex_program2_option
-#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV               0x88F4
-#define GL_MAX_PROGRAM_CALL_DEPTH_NV                      0x88F5
-#endif
-
 /* GL_EXT_texture_compression_rgtc */
 #ifndef GL_EXT_texture_compression_rgtc
@@ -3104,4 +3105,11 @@
 #define GL_COMPRESSED_RED_GREEN_RGTC2_EXT                 0x8DBD
 #define GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT          0x8DBE
+#endif
+
+/* GL_NV_vertex_program2_option */
+#ifndef GL_NV_vertex_program2_option
+#define GL_NV_vertex_program2_option
+#define GL_MAX_PROGRAM_EXEC_INSTRUCTIONS_NV               0x88F4
+#define GL_MAX_PROGRAM_CALL_DEPTH_NV                      0x88F5
 #endif
 
@@ -3319,5 +3327,4 @@
   CARD_ATI_RAGE_128PRO            = 0x5246,
   CARD_ATI_RADEON_7200            = 0x5144,
-  CARD_ATI_RADEON_HD4800          = 0x944c,
   CARD_ATI_RADEON_8500            = 0x514c,
   CARD_ATI_RADEON_9500            = 0x4144,
@@ -3329,4 +3336,16 @@
   CARD_ATI_RADEON_HD2900          = 0x9400,
   CARD_ATI_RADEON_HD3200          = 0x9620,
+  CARD_ATI_RADEON_HD4350          = 0x954f,
+  CARD_ATI_RADEON_HD4550          = 0x9540,
+  CARD_ATI_RADEON_HD4600          = 0x9495,
+  CARD_ATI_RADEON_HD4650          = 0x9498,
+  CARD_ATI_RADEON_HD4670          = 0x9490,
+  CARD_ATI_RADEON_HD4700          = 0x944e,
+  CARD_ATI_RADEON_HD4770          = 0x94b3,
+  CARD_ATI_RADEON_HD4800          = 0x944c, /* picked one value between 9440,944c,9442,9460 */
+  CARD_ATI_RADEON_HD4830          = 0x944c,
+  CARD_ATI_RADEON_HD4850          = 0x9442,
+  CARD_ATI_RADEON_HD4870          = 0x9440,
+  CARD_ATI_RADEON_HD4890          = 0x9460,
 
   CARD_NVIDIA_RIVA_128            = 0x0018,
@@ -3369,4 +3388,5 @@
   CARD_INTEL_I915GM               = 0x2592,
   CARD_INTEL_I945GM               = 0x27a2, /* Same as GMA 950?? */
+  CARD_INTEL_X3100                = 0x2a02, /* found in macs. Same as GMA 965? */
 } GL_Cards;
 
@@ -3391,8 +3411,6 @@
   PS_VERSION_14 = 0x14,
   PS_VERSION_20 = 0x20,
-  WINED3D_GL_EXT_NONE,
   PS_VERSION_30 = 0x30,
   /*Force 32-bits*/
-  ARB_DEPTH_TEXTURE,
   PS_VERSION_FORCE_DWORD = 0x7FFFFFFF
 } GL_PSVersion;
@@ -3402,6 +3420,9 @@
 /* OpenGL Supported Extensions (ARB and EXT) */
 typedef enum _GL_SupportedExt {
+  WINED3D_GL_EXT_NONE,
   /* ARB */
   ARB_COLOR_BUFFER_FLOAT,
+  ARB_DEPTH_BUFFER_FLOAT,
+  ARB_DEPTH_TEXTURE,
   ARB_DRAW_BUFFERS,
   ARB_FRAGMENT_PROGRAM,
@@ -3434,5 +3455,4 @@
   ARB_SHADER_TEXTURE_LOD,
   ARB_HALF_FLOAT_VERTEX,
-  EXT_PACKED_DEPTH_STENCIL,
   /* EXT */
   EXT_BLEND_COLOR,
@@ -3444,4 +3464,5 @@
   EXT_FRAMEBUFFER_BLIT,
   EXT_FRAMEBUFFER_MULTISAMPLE,
+  EXT_PACKED_DEPTH_STENCIL,
   EXT_PALETTED_TEXTURE,
   EXT_PIXEL_BUFFER_OBJECT,
@@ -3470,7 +3491,5 @@
   NV_OCCLUSION_QUERY,
   NV_REGISTER_COMBINERS,
-  NV_VERTEX_PROGRAM2_OPTION,
   NV_REGISTER_COMBINERS2,
-  NV_FRAGMENT_PROGRAM_OPTION,
   NV_TEXGEN_REFLECTION,
   NV_TEXTURE_ENV_COMBINE4,
@@ -3481,5 +3500,7 @@
   NV_VERTEX_PROGRAM1_1,
   NV_VERTEX_PROGRAM2,
+  NV_VERTEX_PROGRAM2_OPTION,
   NV_VERTEX_PROGRAM3,
+  NV_FRAGMENT_PROGRAM_OPTION,
   NV_FENCE,
   NV_DEPTH_CLAMP,
@@ -3938,77 +3959,67 @@
 
 #define USE_GL_FUNC(type, pfn, ext, replace) type pfn;
-typedef struct _WineD3D_GL_Info {
-
-  DWORD  glx_version;
-  DWORD  gl_version;
-
-  GL_Vendors gl_vendor;
-  GL_Cards   gl_card;
-  UINT   vidmem;
-  DWORD  driver_version;
-  DWORD  driver_version_hipart;
-  CHAR   driver_description[255];
-  CHAR   gl_renderer[255];
-  /**
-   * CAPS Constants
-   */
-  UINT   max_buffers;
-  UINT   max_lights;
-  UINT   max_textures;
-  UINT   max_texture_stages;
-  UINT   max_fragment_samplers;
-  UINT   max_vertex_samplers;
-  UINT   max_combined_samplers;
-  UINT   max_sampler_stages;
-  UINT   max_clipplanes;
-  UINT   max_texture_size;
-  UINT   max_texture3d_size;
-  float  max_pointsize, max_pointsizemin;
-  UINT   max_point_sprite_units;
-  UINT   max_blends;
-  UINT   max_anisotropy;
-  UINT   max_glsl_varyings;
-  float  max_shininess;
-
-  unsigned max_vshader_constantsF;
-  unsigned max_pshader_constantsF;
-
-  unsigned vs_arb_constantsF;
-  unsigned vs_arb_max_instructions;
-  unsigned vs_arb_max_temps;
-  unsigned ps_arb_constantsF;
-  unsigned ps_arb_max_instructions;
-  unsigned ps_arb_max_temps;
-  unsigned vs_glsl_constantsF;
-  unsigned 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;
-
-  BOOL arb_vs_offset_limit;
-  BOOL set_texcoord_w;
-  DWORD reserved_glsl_constants;
-  BOOL glsl_clip_varying;
-
-  BOOL supported[WINED3D_GL_EXT_COUNT];
-
-  /** OpenGL EXT and ARB functions ptr */
-  GL_EXT_FUNCS_GEN
-  /** OpenGL WGL functions ptr */
-  WGL_EXT_FUNCS_GEN
-
-  struct GlPixelFormatDesc *gl_formats;
-} WineD3D_GL_Info;
+
+struct wined3d_gl_info
+{
+    GL_Vendors gl_vendor;
+    GL_Cards gl_card;
+    UINT vidmem;
+    DWORD driver_version;
+    DWORD driver_version_hipart;
+    const char *driver_description;
+
+    UINT max_buffers;
+    UINT max_lights;
+    UINT max_textures;
+    UINT max_texture_stages;
+    UINT max_fragment_samplers;
+    UINT max_vertex_samplers;
+    UINT max_combined_samplers;
+    UINT max_sampler_stages;
+    UINT max_clipplanes;
+    UINT max_texture_size;
+    UINT max_texture3d_size;
+    float max_pointsize, max_pointsizemin;
+    UINT max_point_sprite_units;
+    UINT max_blends;
+    UINT max_anisotropy;
+    UINT max_glsl_varyings;
+    float max_shininess;
+
+    unsigned int max_vshader_constantsF;
+    unsigned int max_pshader_constantsF;
+
+    unsigned int vs_arb_constantsF;
+    unsigned int vs_arb_max_instructions;
+    unsigned int vs_arb_max_temps;
+    unsigned int ps_arb_constantsF;
+    unsigned int ps_arb_max_local_constants;
+    unsigned int ps_arb_max_instructions;
+    unsigned int ps_arb_max_temps;
+    unsigned int vs_glsl_constantsF;
+    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;
+
+    DWORD quirks;
+
+    BOOL supported[WINED3D_GL_EXT_COUNT];
+
+    /* GL function pointers */
+    GL_EXT_FUNCS_GEN
+    /* WGL function pointers */
+    WGL_EXT_FUNCS_GEN
+
+    struct GlPixelFormatDesc *gl_formats;
+};
+
 #undef USE_GL_FUNC
 
-struct driver_quirk {
-    BOOL        (*match)(const WineD3D_GL_Info *gl_info);
-    void        (*apply)(WineD3D_GL_Info *gl_info);
-    const char  *description;
-};
-
 #endif /* __WINE_WINED3D_GL */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 21730)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 21731)
@@ -42,5 +42,4 @@
 #include "winbase.h"
 #include "winreg.h"
-#include "wine/rbtree.h"
 #include "wingdi.h"
 #include "winuser.h"
@@ -52,4 +51,11 @@
 #include "wined3d_gl.h"
 #include "wine/list.h"
+#include "wine/rbtree.h"
+
+/* Driver quirks */
+#define WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT       0x00000001
+#define WINED3D_QUIRK_SET_TEXCOORD_W            0x00000002
+#define WINED3D_QUIRK_GLSL_CLIP_VARYING         0x00000004
+#define WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA     0x00000008
 
 /* Texture format fixups */
@@ -202,15 +208,42 @@
     const unsigned short e = ((*in) & 0x7C00) >> 10;
     const unsigned short m = (*in) & 0x3FF;
-    const float sgn = (s ? -1.0 : 1.0);
+    const float sgn = (s ? -1.0f : 1.0f);
     unsigned long fNaN = 0x7fc00000;
+    unsigned long fNegInf = 0xff800000;
+    unsigned long fInf = 0x7f800000;
 
     if(e == 0) {
-        if(m == 0) return sgn * 0.0; /* +0.0 or -0.0 */
-        else return sgn * pow(2, -14.0) * ( (float) m / 1024.0);
+        if(m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
+        else return sgn * pow(2, -14.0f) * ((float)m / 1024.0f);
     } else if(e < 31) {
-        return sgn * pow(2, (float) e-15.0) * (1.0 + ((float) m / 1024.0));
+        return sgn * pow(2, (float)e - 15.0f) * (1.0f + ((float)m / 1024.0f));
     } else {
-        if(m == 0) return sgn / 0.0; /* +INF / -INF */
-        else return *(float*)(&fNaN); //0.0 / 0.0; /* NAN */
+        if(m == 0) return sgn>0? *(float*)(&fInf) : *(float*)(&fNegInf); //sgn / 0.0f; /* +INF / -INF */
+        else return *(float*)(&fNaN); //0.0f / 0.0f; /* NAN */
+    }
+}
+
+static inline float float_24_to_32(DWORD in)
+{
+    const float sgn = in & 0x800000 ? -1.0f : 1.0f;
+    const unsigned short e = (in & 0x780000) >> 19;
+    const unsigned short m = in & 0x7ffff;
+    unsigned long fNaN = 0x7fc00000;
+    unsigned long fNegInf = 0xff800000;
+    unsigned long fInf = 0x7f800000;
+
+    if (e == 0)
+    {
+        if (m == 0) return sgn * 0.0f; /* +0.0 or -0.0 */
+        else return sgn * pow(2, -6.0f) * ((float)m / 524288.0f);
+    }
+    else if (e < 15)
+    {
+        return sgn * pow(2, (float)e - 7.0f) * (1.0f + ((float)m / 524288.0f));
+    }
+    else
+    {
+        if (m == 0) return sgn>0? *(float*)(&fInf) : *(float*)(&fNegInf); //sgn / 0.0f; /* +INF / -INF */
+        else return *(float*)(&fNaN); //0.0f / 0.0f; /* NAN */
     }
 }
@@ -308,4 +341,5 @@
     WINED3DSPR_PREDICATE = 19,
     WINED3DSPR_IMMCONST,
+    WINED3DSPR_CONSTBUFFER,
 } WINED3DSHADER_PARAM_REGISTER_TYPE;
 
@@ -489,10 +523,12 @@
 
 #define SHADER_PGMSIZE 65535
-typedef struct SHADER_BUFFER {
-    char* buffer;
+
+struct wined3d_shader_buffer
+{
+    char *buffer;
     unsigned int bsize;
     unsigned int lineNo;
     BOOL newline;
-} SHADER_BUFFER;
+};
 
 enum WINED3D_SHADER_INSTRUCTION_HANDLER
@@ -613,16 +649,27 @@
     WORD integer_constants;                 /* MAX_CONST_I, 16 */
     WORD boolean_constants;                 /* MAX_CONST_B, 16 */
+    WORD local_int_consts;                  /* MAX_CONST_I, 16 */
     WORD local_bool_consts;                 /* MAX_CONST_B, 16 */
 
     WINED3DSAMPLER_TEXTURE_TYPE sampler_type[max(MAX_FRAGMENT_SAMPLERS, MAX_VERTEX_SAMPLERS)];
     BOOL bumpmat[MAX_TEXTURES], luminanceparams[MAX_TEXTURES];
-    char usesnrm, vpos, usesdsx, usesdsy, usestexldd, usesmova;
-    char usesrelconstF;
+
+    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;
 
     /* Whether or not loops are used in this shader, and nesting depth */
     unsigned loop_depth;
-
-    /* Whether or not this shader uses fog */
-    char fog;
+    unsigned highest_render_target;
 
 } shader_reg_maps;
@@ -632,5 +679,5 @@
     IWineD3DBaseShader *shader;
     const struct shader_reg_maps *reg_maps;
-    SHADER_BUFFER *buffer;
+    struct wined3d_shader_buffer *buffer;
     void *backend_data;
 };
@@ -640,4 +687,5 @@
     WINED3DSHADER_PARAM_REGISTER_TYPE type;
     UINT idx;
+    UINT array_idx;
     const struct wined3d_shader_src_param *rel_addr;
     enum wined3d_immconst_type immconst_type;
@@ -743,9 +791,4 @@
 
 #define WINED3D_CONST_NUM_UNUSED ~0U
-
-struct stb_const_desc {
-    unsigned char           texunit;
-    UINT                    const_num;
-};
 
 enum fogmode {
@@ -795,5 +838,5 @@
     void (*shader_free_private)(IWineD3DDevice *iface);
     BOOL (*shader_dirtifyable_constants)(IWineD3DDevice *iface);
-    void (*shader_get_caps)(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct shader_caps *caps);
+    void (*shader_get_caps)(WINED3DDEVTYPE devtype, const struct wined3d_gl_info *gl_info, struct shader_caps *caps);
     BOOL (*shader_color_fixup_supported)(struct color_fixup_desc fixup);
     void (*shader_add_instruction_modifiers)(const struct wined3d_shader_instruction *ins);
@@ -858,15 +901,17 @@
 /* --------------------- */
 #ifndef WINE_NO_DEBUG_MSGS
-#define checkGLcall(A)                                          \
-do {                                                            \
-    GLint err = glGetError();                                   \
-    if (err == GL_NO_ERROR) {                                   \
-       TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__);    \
-                                                                \
-    } else do {                                                 \
-        FIXME(">>>>>>>>>>>>>>>>> %s (%#x) from %s @ %s / %d\n", \
-            debug_glerror(err), err, A, __FILE__, __LINE__);    \
-       err = glGetError();                                      \
-    } while (err != GL_NO_ERROR);                               \
+#define checkGLcall(A)                                              \
+do {                                                                \
+    GLint err;                                                      \
+    if(!__WINE_IS_DEBUG_ON(_FIXME, __wine_dbch___default)) break;   \
+    err = glGetError();                                             \
+    if (err == GL_NO_ERROR) {                                       \
+       TRACE("%s call ok %s / %d\n", A, __FILE__, __LINE__);        \
+                                                                    \
+    } else do {                                                     \
+        FIXME(">>>>>>>>>>>>>>>>> %s (%#x) from %s @ %s / %d\n",     \
+            debug_glerror(err), err, A, __FILE__, __LINE__);        \
+       err = glGetError();                                          \
+    } while (err != GL_NO_ERROR);                                   \
 } while(0)
 #else
@@ -1117,5 +1162,5 @@
 struct fragment_pipeline {
     void (*enable_extension)(IWineD3DDevice *iface, BOOL enable);
-    void (*get_caps)(WINED3DDEVTYPE devtype, const WineD3D_GL_Info *gl_info, struct fragment_caps *caps);
+    void (*get_caps)(WINED3DDEVTYPE devtype, const struct wined3d_gl_info *gl_info, struct fragment_caps *caps);
     HRESULT (*alloc_private)(IWineD3DDevice *iface);
     void (*free_private)(IWineD3DDevice *iface);
@@ -1135,5 +1180,5 @@
 /* "Base" state table */
 HRESULT compile_state_table(struct StateEntry *StateTable, APPLYSTATEFUNC **dev_multistate_funcs,
-        const WineD3D_GL_Info *gl_info, const struct StateEntryTemplate *vertex,
+        const struct wined3d_gl_info *gl_info, const struct StateEntryTemplate *vertex,
         const struct fragment_pipeline *fragment, const struct StateEntryTemplate *misc);
 
@@ -1160,5 +1205,7 @@
 
 /* The new context manager that should deal with onscreen and offscreen rendering */
-struct WineD3DContext {
+struct WineD3DContext
+{
+    const struct wined3d_gl_info *gl_info;
     /* State dirtification
      * dirtyArray is an array that contains markers for dirty states. numDirtyEntries states are dirty, their numbers are in indices
@@ -1211,4 +1258,6 @@
     GLuint                  src_fbo;
     GLuint                  dst_fbo;
+    GLuint                  fbo_read_binding;
+    GLuint                  fbo_draw_binding;
 
     /* Extension emulation */
@@ -1231,7 +1280,10 @@
 void DestroyContext(IWineD3DDeviceImpl *This, WineD3DContext *context);
 void context_resource_released(IWineD3DDevice *iface, IWineD3DResource *resource, WINED3DRESOURCETYPE type);
-void context_bind_fbo(IWineD3DDevice *iface, GLenum target, GLuint *fbo);
-void context_attach_depth_stencil_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, IWineD3DSurface *depth_stencil, BOOL use_render_buffer);
-void context_attach_surface_fbo(IWineD3DDeviceImpl *This, GLenum fbo_target, DWORD idx, IWineD3DSurface *surface);
+void context_bind_fbo(struct WineD3DContext *context, GLenum target, GLuint *fbo);
+void context_attach_depth_stencil_fbo(struct WineD3DContext *context,
+        GLenum fbo_target, IWineD3DSurface *depth_stencil, BOOL use_render_buffer);
+void context_attach_surface_fbo(const struct WineD3DContext *context,
+        GLenum fbo_target, DWORD idx, IWineD3DSurface *surface);
+void context_set_last_device(IWineD3DDeviceImpl *device);
 
 void delete_opengl_contexts(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain);
@@ -1292,5 +1344,5 @@
     BOOL                    opengl;
     POINT                   monitorPoint;
-    WineD3D_GL_Info         gl_info;
+    struct wined3d_gl_info  gl_info;
     const char              *driver;
     const char              *description;
@@ -1303,8 +1355,8 @@
 };
 
-extern BOOL initPixelFormats(WineD3D_GL_Info *gl_info);
-BOOL initPixelFormatsNoGL(WineD3D_GL_Info *gl_info);
+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(WineD3D_GL_Info *gl_info);
+extern void add_gl_compat_wrappers(struct wined3d_gl_info *gl_info);
 
 /*****************************************************************************
@@ -1363,6 +1415,7 @@
     struct texture_stage_op     op[MAX_TEXTURES];
     enum fogmode fog;
-    /* Use an int instead of a char to get dword alignment */
-    unsigned int sRGB_write;
+    /* Use shorts instead of chars to get dword alignment */
+    unsigned short sRGB_write;
+    unsigned short emul_clipplanes;
 };
 
@@ -1898,4 +1951,8 @@
     /* PBO */
     GLuint                    pbo;
+    GLuint texture_name;
+    GLuint texture_name_srgb;
+    GLint texture_level;
+    GLenum texture_target;
 
     RECT                      lockedRect;
@@ -1903,6 +1960,4 @@
     int                       lockCount;
 #define MAXLOCKCOUNT          50 /* After this amount of locks do not free the sysmem copy */
-
-    glDescriptor              glDescription;
 
     /* For GetDC */
@@ -1935,4 +1990,11 @@
 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);
+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);
 
 /* Predeclare the shared Surface functions */
@@ -2062,4 +2124,7 @@
     CONVERT_R16G16F,
     CONVERT_R32G32F,
+    CONVERT_D15S1,
+    CONVERT_D24X4S4,
+    CONVERT_D24FS8,
 } CONVERT_TYPES;
 
@@ -2359,5 +2424,5 @@
 extern const IWineD3DBufferVtbl wined3d_buffer_vtbl;
 const BYTE *buffer_get_memory(IWineD3DBuffer *iface, UINT offset, GLuint *buffer_object);
-const BYTE *buffer_get_sysmem(struct wined3d_buffer *This);
+BYTE *buffer_get_sysmem(struct wined3d_buffer *This);
 
 /* IWineD3DRendertargetView */
@@ -2514,10 +2579,7 @@
 #endif
 
-/* Base Shader utility functions. 
- * (may move callers into the same file in the future) */
-extern int shader_addline(
-    SHADER_BUFFER* buffer,
-    const char* fmt, ...) PRINTF_ATTR(2,3);
-int shader_vaddline(SHADER_BUFFER *buffer, const char *fmt, va_list args);
+/* 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);
 
 /* Vertex shader utility functions */
@@ -2567,6 +2629,7 @@
 } IWineD3DBaseShaderImpl;
 
-void shader_buffer_init(struct SHADER_BUFFER *buffer);
-void shader_buffer_free(struct SHADER_BUFFER *buffer);
+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_dump_src_param(const struct wined3d_shader_src_param *param,
@@ -2574,5 +2637,5 @@
 void shader_dump_dst_param(const struct wined3d_shader_dst_param *param,
         const struct wined3d_shader_version *shader_version);
-void shader_generate_main(IWineD3DBaseShader *iface, SHADER_BUFFER *buffer,
+void shader_generate_main(IWineD3DBaseShader *iface, struct wined3d_shader_buffer *buffer,
         const shader_reg_maps *reg_maps, const DWORD *pFunction, void *backend_ctx);
 HRESULT shader_get_registers_used(IWineD3DBaseShader *iface, const struct wined3d_shader_frontend *fe,
@@ -2681,4 +2744,22 @@
  * IDirect3DPixelShader implementation structure
  */
+
+/* Using additional shader constants (uniforms in GLSL / program environment
+ * or local parameters in ARB) is costly:
+ * ARB only knows float4 parameters and GLSL compiler are not really smart
+ * when it comes to efficiently pack float2 uniforms, so no space is wasted
+ * (in fact most compilers map a float2 to a full float4 uniform).
+ *
+ * For NP2 texcoord fixup we only need 2 floats (width and height) for each
+ * 2D texture used in the shader. We therefore pack fixup info for 2 textures
+ * into a single shader constant (uniform / program parameter).
+ *
+ * This structure is shared between the GLSL and the ARB backend.*/
+struct ps_np2fixup_info {
+    unsigned char     idx[MAX_FRAGMENT_SAMPLERS]; /* indices to the real constant */
+    WORD              active; /* bitfield indicating if we can apply the fixup */
+    WORD              num_consts;
+};
+
 typedef struct IWineD3DPixelShaderImpl {
     /* IUnknown parts */
@@ -2695,5 +2776,5 @@
     DWORD                 input_reg_map[MAX_REG_INPUT];
     BOOL                  input_reg_used[MAX_REG_INPUT];
-    int                         declared_in_count;
+    unsigned int declared_in_count;
 
     /* The GL shader */
@@ -2701,7 +2782,4 @@
 
     /* Some information about the shader behavior */
-    struct stb_const_desc       bumpenvmatconst[MAX_TEXTURES];
-    unsigned char               numbumpenvmatconsts;
-    struct stb_const_desc       luminanceconst[MAX_TEXTURES];
     char                        vpos_uniform;
 
@@ -2716,9 +2794,9 @@
 
 /* sRGB correction constants */
-static const float srgb_cmp = 0.0031308;
-static const float srgb_mul_low = 12.92;
-static const float srgb_pow = 0.41666;
-static const float srgb_mul_high = 1.055;
-static const float srgb_sub_high = 0.055;
+static const float srgb_cmp = 0.0031308f;
+static const float srgb_mul_low = 12.92f;
+static const float srgb_pow = 0.41666f;
+static const float srgb_mul_high = 1.055f;
+static const float srgb_sub_high = 0.055f;
 
 /*****************************************************************************
@@ -2761,4 +2839,5 @@
 #define WINED3DFMT_FLAG_FOURCC                   0x20
 #define WINED3DFMT_FLAG_FBO_ATTACHABLE           0x40
+#define WINED3DFMT_FLAG_COMPRESSED               0x80
 
 struct GlPixelFormatDesc
@@ -2773,4 +2852,8 @@
     WORD stencil_size;
 
+    UINT block_width;
+    UINT block_height;
+    UINT block_byte_count;
+
     enum wined3d_ffp_emit_idx emit_idx;
     GLint component_count;
@@ -2790,5 +2873,5 @@
 };
 
-const struct GlPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, const WineD3D_GL_Info *gl_info);
+const struct GlPixelFormatDesc *getFormatDescEntry(WINED3DFORMAT fmt, const struct wined3d_gl_info *gl_info);
 
 static inline BOOL use_vs(IWineD3DStateBlockImpl *stateblock)
