- sync wined3d, d3d8, d3d9 to wine HEAD part 1/2
authorKamil Hornicek <kamil.hornicek@reactos.org>
Thu, 27 Nov 2008 09:20:16 +0000 (09:20 +0000)
committerKamil Hornicek <kamil.hornicek@reactos.org>
Thu, 27 Nov 2008 09:20:16 +0000 (09:20 +0000)
svn path=/trunk/; revision=37683

60 files changed:
reactos/dll/directx/wine/d3d8/Makefile.in
reactos/dll/directx/wine/d3d8/d3d8_main.c
reactos/dll/directx/wine/d3d8/device.c
reactos/dll/directx/wine/d3d8/directx.c
reactos/dll/directx/wine/d3d8/vertexshader.c
reactos/dll/directx/wine/d3d9/basetexture.c
reactos/dll/directx/wine/d3d9/cubetexture.c
reactos/dll/directx/wine/d3d9/d3d9_main.c
reactos/dll/directx/wine/d3d9/device.c
reactos/dll/directx/wine/d3d9/directx.c
reactos/dll/directx/wine/d3d9/indexbuffer.c
reactos/dll/directx/wine/d3d9/pixelshader.c
reactos/dll/directx/wine/d3d9/query.c
reactos/dll/directx/wine/d3d9/resource.c
reactos/dll/directx/wine/d3d9/stateblock.c
reactos/dll/directx/wine/d3d9/surface.c
reactos/dll/directx/wine/d3d9/swapchain.c
reactos/dll/directx/wine/d3d9/texture.c
reactos/dll/directx/wine/d3d9/vertexbuffer.c
reactos/dll/directx/wine/d3d9/vertexdeclaration.c
reactos/dll/directx/wine/d3d9/vertexshader.c
reactos/dll/directx/wine/d3d9/volume.c
reactos/dll/directx/wine/d3d9/volumetexture.c
reactos/dll/directx/wine/wined3d/Makefile.in
reactos/dll/directx/wine/wined3d/arb_program_shader.c
reactos/dll/directx/wine/wined3d/ati_fragment_shader.c
reactos/dll/directx/wine/wined3d/baseshader.c
reactos/dll/directx/wine/wined3d/basetexture.c
reactos/dll/directx/wine/wined3d/clipper.c
reactos/dll/directx/wine/wined3d/context.c
reactos/dll/directx/wine/wined3d/cubetexture.c
reactos/dll/directx/wine/wined3d/device.c
reactos/dll/directx/wine/wined3d/directx.c
reactos/dll/directx/wine/wined3d/drawprim.c
reactos/dll/directx/wine/wined3d/glsl_shader.c
reactos/dll/directx/wine/wined3d/indexbuffer.c
reactos/dll/directx/wine/wined3d/nvidia_texture_shader.c
reactos/dll/directx/wine/wined3d/palette.c
reactos/dll/directx/wine/wined3d/pixelshader.c
reactos/dll/directx/wine/wined3d/query.c
reactos/dll/directx/wine/wined3d/resource.c
reactos/dll/directx/wine/wined3d/state.c
reactos/dll/directx/wine/wined3d/stateblock.c
reactos/dll/directx/wine/wined3d/surface.c
reactos/dll/directx/wine/wined3d/surface_base.c
reactos/dll/directx/wine/wined3d/surface_gdi.c
reactos/dll/directx/wine/wined3d/swapchain.c
reactos/dll/directx/wine/wined3d/swapchain_base.c
reactos/dll/directx/wine/wined3d/swapchain_gdi.c
reactos/dll/directx/wine/wined3d/texture.c
reactos/dll/directx/wine/wined3d/utils.c
reactos/dll/directx/wine/wined3d/vertexbuffer.c
reactos/dll/directx/wine/wined3d/vertexdeclaration.c
reactos/dll/directx/wine/wined3d/vertexshader.c
reactos/dll/directx/wine/wined3d/volume.c
reactos/dll/directx/wine/wined3d/volumetexture.c
reactos/dll/directx/wine/wined3d/wined3d.def
reactos/dll/directx/wine/wined3d/wined3d.spec
reactos/dll/directx/wine/wined3d/wined3d_main.c
reactos/dll/directx/wine/wined3d/wined3d_private.h

index 15bc92a..11a46fc 100644 (file)
@@ -3,9 +3,8 @@ TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = d3d8.dll
-IMPORTLIB = libd3d8.$(IMPLIBEXT)
-IMPORTS   = wined3d user32 gdi32 advapi32 kernel32
-EXTRALIBS = -ldxguid -luuid
+IMPORTLIB = d3d8
+IMPORTS   = dxguid uuid wined3d kernel32
 
 C_SRCS = \
        basetexture.c \
index 56de60d..8e32dc3 100644 (file)
@@ -53,7 +53,7 @@ IDirect3D8* WINAPI Direct3DCreate8(UINT SDKVersion) {
 
     object->lpVtbl = &Direct3D8_Vtbl;
     object->ref = 1;
-    object->WineD3D = WineDirect3DCreate(SDKVersion, 8, (IUnknown *)object);
+    object->WineD3D = WineDirect3DCreate(8, (IUnknown *)object);
 
     TRACE("Created Direct3D object @ %p, WineObj @ %p\n", object, object->WineD3D);
     LeaveCriticalSection(&d3d8_cs);
index 976d7dd..64e3b60 100644 (file)
@@ -305,9 +305,10 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DD
     localParameters.Flags                                       = pPresentationParameters->Flags;
     localParameters.FullScreen_RefreshRateInHz                  = pPresentationParameters->FullScreen_RefreshRateInHz;
     localParameters.PresentationInterval                        = pPresentationParameters->FullScreen_PresentationInterval;
+    localParameters.AutoRestoreDisplayMode                      = TRUE;
 
     EnterCriticalSection(&d3d8_cs);
-    hrc = IWineD3DDevice_CreateAdditionalSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D8CB_CreateRenderTarget, D3D8CB_CreateDepthStencilSurface, SURFACE_OPENGL);
+    hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D8CB_CreateRenderTarget, D3D8CB_CreateDepthStencilSurface, SURFACE_OPENGL);
     LeaveCriticalSection(&d3d8_cs);
 
     pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
@@ -325,7 +326,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DD
     pPresentationParameters->FullScreen_PresentationInterval    = localParameters.PresentationInterval;
 
     if (hrc != D3D_OK) {
-        FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
+        FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
         HeapFree(GetProcessHeap(), 0 , object);
         *pSwapChain = NULL;
     }else{
@@ -358,6 +359,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRE
     localParameters.Flags                                       = pPresentationParameters->Flags;
     localParameters.FullScreen_RefreshRateInHz                  = pPresentationParameters->FullScreen_RefreshRateInHz;
     localParameters.PresentationInterval                        = pPresentationParameters->FullScreen_PresentationInterval;
+    localParameters.AutoRestoreDisplayMode                      = TRUE;
 
     EnterCriticalSection(&d3d8_cs);
     hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
@@ -1950,7 +1952,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetPixelShader(LPDIRECT3DDEVICE8 ifac
         IWineD3DPixelShader_Release(object);
         *ppShader = d3d8_shader->handle;
     } else {
-        *ppShader = (DWORD)NULL;
+        *ppShader = 0;
     }
 
     TRACE("(%p) : returning %#x\n", This, *ppShader);
index afcb0fe..3efbab0 100644 (file)
@@ -444,6 +444,7 @@ static HRESULT WINAPI IDirect3D8Impl_CreateDevice(LPDIRECT3D8 iface, UINT Adapte
     localParameters.Flags                                       = pPresentationParameters->Flags;
     localParameters.FullScreen_RefreshRateInHz                  = pPresentationParameters->FullScreen_RefreshRateInHz;
     localParameters.PresentationInterval                        = pPresentationParameters->FullScreen_PresentationInterval;
+    localParameters.AutoRestoreDisplayMode                      = TRUE;
 
     if(BehaviourFlags & D3DCREATE_MULTITHREADED) {
         IWineD3DDevice_SetMultithreaded(object->WineD3DDevice);
index 89555bd..16a809e 100644 (file)
@@ -67,10 +67,11 @@ static ULONG WINAPI IDirect3DVertexShader8Impl_Release(IDirect3DVertexShader8 *i
 static HRESULT WINAPI IDirect3DVertexShader8Impl_GetDevice(IDirect3DVertexShader8 *iface, IDirect3DDevice8** ppDevice) {
     IDirect3DVertexShader8Impl *This = (IDirect3DVertexShader8Impl *)iface;
     IWineD3DDevice *myDevice = NULL;
-    HRESULT hr = D3D_OK;
+    HRESULT hr;
     TRACE("(%p) : Relay\n", This);
 
-    if (D3D_OK == (hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice) && myDevice != NULL)) {
+    hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice);
+    if (WINED3D_OK == hr && myDevice != NULL) {
         hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
         IWineD3DDevice_Release(myDevice);
     } else {
index f80eb78..b349f51 100644 (file)
@@ -31,7 +31,7 @@ static HRESULT WINAPI IDirect3DBaseTexture9Impl_QueryInterface(LPDIRECT3DBASETEX
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource9)
         || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DBaseTexture9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
index 9369fa5..bf88995 100644 (file)
@@ -33,7 +33,7 @@ static HRESULT WINAPI IDirect3DCubeTexture9Impl_QueryInterface(LPDIRECT3DCUBETEX
         || IsEqualGUID(riid, &IID_IDirect3DResource9)
         || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
         || IsEqualGUID(riid, &IID_IDirect3DCubeTexture9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DCubeTexture9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
@@ -63,7 +63,7 @@ static ULONG WINAPI IDirect3DCubeTexture9Impl_Release(LPDIRECT3DCUBETEXTURE9 ifa
 
         EnterCriticalSection(&d3d9_cs);
         IWineD3DCubeTexture_Destroy(This->wineD3DCubeTexture, D3D9CB_DestroySurface);
-        IUnknown_Release(This->parentDevice);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
         LeaveCriticalSection(&d3d9_cs);
 
         HeapFree(GetProcessHeap(), 0, This);
@@ -365,7 +365,7 @@ HRESULT  WINAPI  IDirect3DDevice9Impl_CreateCubeTexture(LPDIRECT3DDEVICE9EX ifac
         FIXME("(%p) call to IWineD3DDevice_CreateCubeTexture failed\n", This);
         HeapFree(GetProcessHeap(), 0, object);
     } else {
-        IUnknown_AddRef(iface);
+        IDirect3DDevice9Ex_AddRef(iface);
         object->parentDevice = iface;
         *ppCubeTexture = (LPDIRECT3DCUBETEXTURE9) object;
         TRACE("(%p) : Created cube texture %p\n", This, object);
index 03c75a4..40d73a5 100644 (file)
@@ -48,7 +48,7 @@ IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion) {
     object->lpVtbl = &Direct3D9_Vtbl;
     object->ref = 1;
     EnterCriticalSection(&d3d9_cs);
-    object->WineD3D = WineDirect3DCreate(SDKVersion, 9, (IUnknown *)object);
+    object->WineD3D = WineDirect3DCreate(9, (IUnknown *)object);
     LeaveCriticalSection(&d3d9_cs);
 
     TRACE("SDKVersion = %x, Created Direct3D object @ %p, WineObj @ %p\n", SDKVersion, object, object->WineD3D);
index 8aab230..697c202 100644 (file)
@@ -34,7 +34,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_QueryInterface(LPDIRECT3DDEVICE9EX if
 
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DDevice9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DDevice9Ex_AddRef(iface);
         *ppobj = This;
         TRACE("Returning IDirect3DDevice9 interface at %p\n", *ppobj);
         return S_OK;
@@ -266,6 +266,7 @@ static HRESULT WINAPI reset_enum_callback(IWineD3DResource *resource, void *data
     WINED3DINDEXBUFFER_DESC index_desc;
     WINED3DVERTEXBUFFER_DESC vertex_desc;
     WINED3DFORMAT dummy_format;
+    WINED3DMULTISAMPLE_TYPE dummy_multisampletype;
     DWORD dummy_dword;
     WINED3DPOOL pool = WINED3DPOOL_SCRATCH; /* a harmless pool */
     IUnknown *parent;
@@ -278,7 +279,7 @@ static HRESULT WINAPI reset_enum_callback(IWineD3DResource *resource, void *data
             surface_desc.Usage = &dummy_dword;
             surface_desc.Pool = &pool;
             surface_desc.Size = &dummy_dword;
-            surface_desc.MultiSampleType = &dummy_dword;
+            surface_desc.MultiSampleType = &dummy_multisampletype;
             surface_desc.MultiSampleQuality = &dummy_dword;
             surface_desc.Width = &dummy_dword;
             surface_desc.Height = &dummy_dword;
@@ -376,6 +377,7 @@ static HRESULT  WINAPI  IDirect3DDevice9Impl_Reset(LPDIRECT3DDEVICE9EX iface, D3
     localParameters.Flags                               = pPresentationParameters->Flags;
     localParameters.FullScreen_RefreshRateInHz          = pPresentationParameters->FullScreen_RefreshRateInHz;
     localParameters.PresentationInterval                = pPresentationParameters->PresentationInterval;
+    localParameters.AutoRestoreDisplayMode              = TRUE;
 
     EnterCriticalSection(&d3d9_cs);
     hr = IWineD3DDevice_Reset(This->WineD3DDevice, &localParameters);
@@ -513,7 +515,7 @@ static HRESULT  WINAPI IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX if
         FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
         HeapFree(GetProcessHeap(), 0, object);
     } else {
-        IUnknown_AddRef(iface);
+        IDirect3DDevice9Ex_AddRef(iface);
         object->parentDevice = iface;
         TRACE("(%p) : Created surface %p\n", This, object);
         *ppSurface = (LPDIRECT3DSURFACE9) object;
@@ -988,11 +990,13 @@ static HRESULT  WINAPI  IDirect3DDevice9Impl_GetTexture(LPDIRECT3DDEVICE9EX ifac
 
     EnterCriticalSection(&d3d9_cs);
     rc = IWineD3DDevice_GetTexture(This->WineD3DDevice, Stage, &retTexture);
-    if (rc == D3D_OK && NULL != retTexture) {
+    if (SUCCEEDED(rc) && NULL != retTexture) {
         IWineD3DBaseTexture_GetParent(retTexture, (IUnknown **)ppTexture);
         IWineD3DBaseTexture_Release(retTexture);
-    }else{
-        FIXME("Call to get texture  (%d) failed (%p)\n", Stage, retTexture);
+    } else {
+        if(FAILED(rc)) {
+            WARN("Call to get texture  (%d) failed (%p)\n", Stage, retTexture);
+        }
         *ppTexture = NULL;
     }
     LeaveCriticalSection(&d3d9_cs);
@@ -1720,7 +1724,7 @@ HRESULT WINAPI D3D9CB_CreateSurface(IUnknown *device, IUnknown *pSuperior, UINT
     if (SUCCEEDED(res)) {
         *ppSurface = d3dSurface->wineD3DSurface;
         d3dSurface->container = pSuperior;
-        IUnknown_Release(d3dSurface->parentDevice);
+        IDirect3DDevice9Ex_Release(d3dSurface->parentDevice);
         d3dSurface->parentDevice = NULL;
         d3dSurface->forwardReference = pSuperior;
     } else {
index b605f44..cb04b1f 100644 (file)
@@ -31,7 +31,7 @@ static HRESULT WINAPI IDirect3D9Impl_QueryInterface(LPDIRECT3D9EX iface, REFIID
 
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3D9)) {
-        IUnknown_AddRef(iface);
+        IDirect3D9Ex_AddRef(iface);
         *ppobj = This;
         TRACE("Returning IDirect3D9 interface at %p\n", *ppobj);
         return S_OK;
@@ -346,7 +346,7 @@ HRESULT WINAPI D3D9CB_CreateRenderTarget(IUnknown *device, IUnknown *pSuperior,
         d3dSurface->container = pSuperior;
         d3dSurface->isImplicit = TRUE;
         /* Implicit surfaces are created with an refcount of 0 */
-        IUnknown_Release((IUnknown *)d3dSurface);
+        IDirect3DSurface9_Release((IDirect3DSurface9 *)d3dSurface);
     } else {
         *ppSurface = NULL;
     }
@@ -393,7 +393,7 @@ static HRESULT WINAPI D3D9CB_CreateAdditionalSwapChain(IUnknown *device,
         *ppSwapChain = d3dSwapChain->wineD3DSwapChain;
         d3dSwapChain->isImplicit = TRUE;
         /* Implicit swap chains are created with an refcount of 0 */
-        IUnknown_Release((IUnknown *)d3dSwapChain);
+        IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3dSwapChain);
     } else {
         *ppSwapChain = NULL;
     }
@@ -444,7 +444,7 @@ HRESULT WINAPI D3D9CB_CreateDepthStencilSurface(IUnknown *device, IUnknown *pSup
         d3dSurface->container = device;
         d3dSurface->isImplicit = TRUE;
         /* Implicit surfaces are created with an refcount of 0 */
-        IUnknown_Release((IUnknown *)d3dSurface);
+        IDirect3DSurface9_Release((IDirect3DSurface9 *)d3dSurface);
     }
     return res;
 }
@@ -515,6 +515,7 @@ static HRESULT WINAPI IDirect3D9Impl_CreateDevice(LPDIRECT3D9EX iface, UINT Adap
     localParameters.Flags                               = pPresentationParameters->Flags;
     localParameters.FullScreen_RefreshRateInHz          = pPresentationParameters->FullScreen_RefreshRateInHz;
     localParameters.PresentationInterval                = pPresentationParameters->PresentationInterval;
+    localParameters.AutoRestoreDisplayMode              = TRUE;
 
     if(BehaviourFlags & D3DCREATE_MULTITHREADED) {
         IWineD3DDevice_SetMultithreaded(object->WineD3DDevice);
index 1193c6a..c1860ff 100644 (file)
@@ -31,7 +31,7 @@ static HRESULT WINAPI IDirect3DIndexBuffer9Impl_QueryInterface(LPDIRECT3DINDEXBU
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource9)
         || IsEqualGUID(riid, &IID_IDirect3DIndexBuffer9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DIndexBuffer9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
@@ -60,7 +60,7 @@ static ULONG WINAPI IDirect3DIndexBuffer9Impl_Release(LPDIRECT3DINDEXBUFFER9 ifa
         EnterCriticalSection(&d3d9_cs);
         IWineD3DIndexBuffer_Release(This->wineD3DIndexBuffer);
         LeaveCriticalSection(&d3d9_cs);
-        IUnknown_Release(This->parentDevice);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
         HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -237,7 +237,7 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(LPDIRECT3DDEVICE9EX iface,
         FIXME("(%p) call to IWineD3DDevice_CreateIndexBuffer failed\n", This);
         HeapFree(GetProcessHeap(), 0, object);
     } else {
-        IUnknown_AddRef(iface);
+        IDirect3DDevice9Ex_AddRef(iface);
         object->parentDevice = iface;
         *ppIndexBuffer = (LPDIRECT3DINDEXBUFFER9) object;
         TRACE("(%p) : Created index buffer %p\n", This, object);
index 919b5a7..059116a 100644 (file)
@@ -30,7 +30,7 @@ static HRESULT WINAPI IDirect3DPixelShader9Impl_QueryInterface(LPDIRECT3DPIXELSH
 
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DPixelShader9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DPixelShader9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
@@ -59,7 +59,7 @@ static ULONG WINAPI IDirect3DPixelShader9Impl_Release(LPDIRECT3DPIXELSHADER9 ifa
         EnterCriticalSection(&d3d9_cs);
         IWineD3DPixelShader_Release(This->wineD3DPixelShader);
         LeaveCriticalSection(&d3d9_cs);
-        IUnknown_Release(This->parentDevice);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
         HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -136,7 +136,7 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(LPDIRECT3DDEVICE9EX iface,
         FIXME("(%p) call to IWineD3DDevice_CreatePixelShader failed\n", This);
         HeapFree(GetProcessHeap(), 0 , object);
     } else {
-        IUnknown_AddRef(iface);
+        IDirect3DDevice9Ex_AddRef(iface);
         object->parentDevice = iface;
         *ppShader = (IDirect3DPixelShader9*) object;
         TRACE("(%p) : Created pixel shader %p\n", This, object);
index 9eeabc8..9a15164 100644 (file)
@@ -32,7 +32,7 @@ static HRESULT WINAPI IDirect3DQuery9Impl_QueryInterface(LPDIRECT3DQUERY9 iface,
 
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DQuery9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DQuery9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
@@ -60,7 +60,7 @@ static ULONG WINAPI IDirect3DQuery9Impl_Release(LPDIRECT3DQUERY9 iface) {
         EnterCriticalSection(&d3d9_cs);
         IWineD3DQuery_Release(This->wineD3DQuery);
         LeaveCriticalSection(&d3d9_cs);
-        IUnknown_Release(This->parentDevice);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
         HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -179,7 +179,7 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(LPDIRECT3DDEVICE9EX iface, D3DQU
         FIXME("(%p) call to IWineD3DDevice_CreateQuery failed\n", This);
         HeapFree(GetProcessHeap(), 0, object);
     } else {
-        IUnknown_AddRef(iface);
+        IDirect3DDevice9Ex_AddRef(iface);
         object->parentDevice = iface;
         *ppQuery = (LPDIRECT3DQUERY9) object;
         TRACE("(%p) : Created query %p\n", This , object);
index d07d1da..fac2570 100644 (file)
@@ -30,7 +30,7 @@ static HRESULT WINAPI IDirect3DResource9Impl_QueryInterface(LPDIRECT3DRESOURCE9
 
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DResource9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
index 89e992c..22e1926 100644 (file)
@@ -31,7 +31,7 @@ static HRESULT WINAPI IDirect3DStateBlock9Impl_QueryInterface(LPDIRECT3DSTATEBLO
 
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DStateBlock9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DStateBlock9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
@@ -58,9 +58,9 @@ static ULONG WINAPI IDirect3DStateBlock9Impl_Release(LPDIRECT3DSTATEBLOCK9 iface
 
     if (ref == 0) {
         EnterCriticalSection(&d3d9_cs);
-        IWineD3DStateBlock_Release(This->wineD3DStateBlock);    
+        IWineD3DStateBlock_Release(This->wineD3DStateBlock);
         LeaveCriticalSection(&d3d9_cs);
-        IUnknown_Release(This->parentDevice);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
         HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -140,7 +140,7 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateStateBlock(LPDIRECT3DDEVICE9EX iface,
        FIXME("(%p) Call to IWineD3DDevice_CreateStateBlock failed.\n", This);
        HeapFree(GetProcessHeap(), 0, object);
    } else {
-        IUnknown_AddRef(iface);
+        IDirect3DDevice9Ex_AddRef(iface);
         object->parentDevice = iface;
         *ppStateBlock = (IDirect3DStateBlock9*)object;
         TRACE("(%p) : Created stateblock %p\n", This, object);
@@ -185,7 +185,7 @@ HRESULT  WINAPI  IDirect3DDevice9Impl_EndStateBlock(LPDIRECT3DDEVICE9EX iface, I
     object->lpVtbl = &Direct3DStateBlock9_Vtbl;
     object->wineD3DStateBlock = wineD3DStateBlock;
 
-    IUnknown_AddRef(iface);
+    IDirect3DDevice9Ex_AddRef(iface);
     object->parentDevice = iface;
     *ppSB=(IDirect3DStateBlock9*)object;
     TRACE("(%p)Returning %p %p\n", This, *ppSB, wineD3DStateBlock);
index 54558b4..bdede77 100644 (file)
@@ -31,7 +31,7 @@ static HRESULT WINAPI IDirect3DSurface9Impl_QueryInterface(LPDIRECT3DSURFACE9 if
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource9)
         || IsEqualGUID(riid, &IID_IDirect3DSurface9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DSurface9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
@@ -53,7 +53,7 @@ static ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) {
     } else {
         /* No container, handle our own refcounting */
         ULONG ref = InterlockedIncrement(&This->ref);
-        if(ref == 1 && This->parentDevice) IUnknown_AddRef(This->parentDevice);
+        if(ref == 1 && This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
         TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
         return ref;
@@ -76,7 +76,7 @@ static ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) {
         TRACE("(%p) : ReleaseRef to %d\n", This, ref);
 
         if (ref == 0) {
-            if (This->parentDevice) IUnknown_Release(This->parentDevice);
+            if (This->parentDevice) IDirect3DDevice9Ex_Release(This->parentDevice);
             if (!This->isImplicit) {
                 EnterCriticalSection(&d3d9_cs);
                 IWineD3DSurface_Release(This->wineD3DSurface);
index 0dd9b8f..eabe366 100644 (file)
@@ -32,7 +32,7 @@ static HRESULT WINAPI IDirect3DSwapChain9Impl_QueryInterface(LPDIRECT3DSWAPCHAIN
 
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DSwapChain9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DSwapChain9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
@@ -48,7 +48,7 @@ static ULONG WINAPI IDirect3DSwapChain9Impl_AddRef(LPDIRECT3DSWAPCHAIN9 iface) {
 
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
-    if(ref == 1 && This->parentDevice) IUnknown_AddRef(This->parentDevice);
+    if(ref == 1 && This->parentDevice) IDirect3DDevice9Ex_AddRef(This->parentDevice);
 
     return ref;
 }
@@ -60,7 +60,7 @@ static ULONG WINAPI IDirect3DSwapChain9Impl_Release(LPDIRECT3DSWAPCHAIN9 iface)
     TRACE("(%p) : ReleaseRef to %d\n", This, ref);
 
     if (ref == 0) {
-        if (This->parentDevice) IUnknown_Release(This->parentDevice);
+        if (This->parentDevice) IDirect3DDevice9Ex_Release(This->parentDevice);
         if (!This->isImplicit) {
             EnterCriticalSection(&d3d9_cs);
             IWineD3DSwapChain_Destroy(This->wineD3DSwapChain, D3D9CB_DestroyRenderTarget);
@@ -229,7 +229,7 @@ HRESULT  WINAPI  IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE
     localParameters.PresentationInterval                = pPresentationParameters->PresentationInterval;
 
     EnterCriticalSection(&d3d9_cs);
-    hrc = IWineD3DDevice_CreateAdditionalSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D9CB_CreateRenderTarget, D3D9CB_CreateDepthStencilSurface, SURFACE_OPENGL);
+    hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D9CB_CreateRenderTarget, D3D9CB_CreateDepthStencilSurface, SURFACE_OPENGL);
     LeaveCriticalSection(&d3d9_cs);
 
     pPresentationParameters->BackBufferWidth            = localParameters.BackBufferWidth;
@@ -248,10 +248,10 @@ HRESULT  WINAPI  IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE
     pPresentationParameters->PresentationInterval       = localParameters.PresentationInterval;
 
     if (hrc != D3D_OK) {
-        FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
+        FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
         HeapFree(GetProcessHeap(), 0 , object);
     } else {
-        IUnknown_AddRef(iface);
+        IDirect3DDevice9Ex_AddRef(iface);
         object->parentDevice = iface;
         *pSwapChain = (IDirect3DSwapChain9 *)object;
         TRACE("(%p) : Created swapchain %p\n", This, *pSwapChain);
index a8a525a..71e1be3 100644 (file)
@@ -33,7 +33,7 @@ static HRESULT WINAPI IDirect3DTexture9Impl_QueryInterface(LPDIRECT3DTEXTURE9 if
         || IsEqualGUID(riid, &IID_IDirect3DResource9)
         || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
         || IsEqualGUID(riid, &IID_IDirect3DTexture9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DTexture9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
@@ -62,7 +62,7 @@ static ULONG WINAPI IDirect3DTexture9Impl_Release(LPDIRECT3DTEXTURE9 iface) {
         EnterCriticalSection(&d3d9_cs);
         IWineD3DTexture_Destroy(This->wineD3DTexture, D3D9CB_DestroySurface);
         LeaveCriticalSection(&d3d9_cs);
-        IUnknown_Release(This->parentDevice);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
         HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -356,7 +356,7 @@ HRESULT  WINAPI  IDirect3DDevice9Impl_CreateTexture(LPDIRECT3DDEVICE9EX iface, U
         FIXME("(%p) call to IWineD3DDevice_CreateTexture failed\n", This);
         HeapFree(GetProcessHeap(), 0, object);
    } else {
-        IUnknown_AddRef(iface);
+        IDirect3DDevice9Ex_AddRef(iface);
         object->parentDevice = iface;
         *ppTexture= (LPDIRECT3DTEXTURE9) object;
         TRACE("(%p) Created Texture %p, %p\n", This, object, object->wineD3DTexture);
index 12ecd0b..002052e 100644 (file)
@@ -32,7 +32,7 @@ static HRESULT WINAPI IDirect3DVertexBuffer9Impl_QueryInterface(LPDIRECT3DVERTEX
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DResource9)
         || IsEqualGUID(riid, &IID_IDirect3DVertexBuffer9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DVertexBuffer9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
@@ -61,7 +61,7 @@ static ULONG WINAPI IDirect3DVertexBuffer9Impl_Release(LPDIRECT3DVERTEXBUFFER9 i
         EnterCriticalSection(&d3d9_cs);
         IWineD3DVertexBuffer_Release(This->wineD3DVertexBuffer);
         LeaveCriticalSection(&d3d9_cs);
-        IUnknown_Release(This->parentDevice);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
         HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -234,7 +234,7 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(LPDIRECT3DDEVICE9EX iface
         WARN("(%p) call to IWineD3DDevice_CreateVertexBuffer failed\n", This);
         HeapFree(GetProcessHeap(), 0, object);
     } else {
-        IUnknown_AddRef(iface);
+        IDirect3DDevice9Ex_AddRef(iface);
         object->parentDevice = iface;
         TRACE("(%p) : Created vertex buffer %p\n", This, object);
         *ppVertexBuffer = (LPDIRECT3DVERTEXBUFFER9) object;
index 327c741..4631248 100644 (file)
@@ -106,8 +106,16 @@ HRESULT vdecl_convert_fvf(
     if (has_blend && (num_blends > 0)) {
         if (((fvf & D3DFVF_XYZB5) == D3DFVF_XYZB2) && (fvf & D3DFVF_LASTBETA_D3DCOLOR))
             elements[idx].Type = D3DDECLTYPE_D3DCOLOR;
-        else
-            elements[idx].Type = D3DDECLTYPE_FLOAT1 + num_blends - 1;
+        else {
+            switch(num_blends) {
+                case 1: elements[idx].Type = D3DDECLTYPE_FLOAT1; break;
+                case 2: elements[idx].Type = D3DDECLTYPE_FLOAT2; break;
+                case 3: elements[idx].Type = D3DDECLTYPE_FLOAT3; break;
+                case 4: elements[idx].Type = D3DDECLTYPE_FLOAT4; break;
+                default:
+                    ERR("Unexpected amount of blend values: %u\n", num_blends);
+            }
+        }
         elements[idx].Usage = D3DDECLUSAGE_BLENDWEIGHT;
         elements[idx].UsageIndex = 0;
         idx++;
@@ -187,7 +195,7 @@ static HRESULT WINAPI IDirect3DVertexDeclaration9Impl_QueryInterface(LPDIRECT3DV
 
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DVertexDeclaration9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DVertexDeclaration9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
@@ -204,7 +212,7 @@ static ULONG WINAPI IDirect3DVertexDeclaration9Impl_AddRef(LPDIRECT3DVERTEXDECLA
     TRACE("(%p) : AddRef from %d\n", This, ref - 1);
 
     if(ref == 1) {
-        IUnknown_AddRef(This->parentDevice);
+        IDirect3DDevice9Ex_AddRef(This->parentDevice);
     }
 
     return ref;
@@ -236,7 +244,7 @@ static ULONG WINAPI IDirect3DVertexDeclaration9Impl_Release(LPDIRECT3DVERTEXDECL
         if(!This->convFVF) {
             IDirect3DVertexDeclaration9Impl_Release(iface);
         }
-        IUnknown_Release(parentDevice);
+        IDirect3DDevice9Ex_Release(parentDevice);
     }
     return ref;
 }
@@ -374,7 +382,7 @@ HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVertexDeclaration(LPDIRECT3DDEVICE9E
     } else {
         object->parentDevice = iface;
         *ppDecl = (LPDIRECT3DVERTEXDECLARATION9) object;
-        IUnknown_AddRef(*ppDecl);
+        IDirect3DVertexDeclaration9_AddRef(*ppDecl);
          TRACE("(%p) : Created vertex declaration %p\n", This, object);
     }
     return hr;
index c41b2c4..66ce286 100644 (file)
@@ -30,7 +30,7 @@ static HRESULT WINAPI IDirect3DVertexShader9Impl_QueryInterface(LPDIRECT3DVERTEX
 
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DVertexShader9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DVertexShader9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
@@ -59,7 +59,7 @@ static ULONG WINAPI IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 i
         EnterCriticalSection(&d3d9_cs);
         IWineD3DVertexShader_Release(This->wineD3DVertexShader);
         LeaveCriticalSection(&d3d9_cs);
-        IUnknown_Release(This->parentDevice);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
         HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -69,11 +69,12 @@ static ULONG WINAPI IDirect3DVertexShader9Impl_Release(LPDIRECT3DVERTEXSHADER9 i
 static HRESULT WINAPI IDirect3DVertexShader9Impl_GetDevice(LPDIRECT3DVERTEXSHADER9 iface, IDirect3DDevice9** ppDevice) {
     IDirect3DVertexShader9Impl *This = (IDirect3DVertexShader9Impl *)iface;
     IWineD3DDevice *myDevice = NULL;
-    HRESULT hr = D3D_OK;
+    HRESULT hr;
     TRACE("(%p) : Relay\n", This);
 
     EnterCriticalSection(&d3d9_cs);
-    if (D3D_OK == (hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice) && myDevice != NULL)) {
+    hr = IWineD3DVertexShader_GetDevice(This->wineD3DVertexShader, &myDevice);
+    if (WINED3D_OK == hr && myDevice != NULL) {
         hr = IWineD3DDevice_GetParent(myDevice, (IUnknown **)ppDevice);
         IWineD3DDevice_Release(myDevice);
     } else {
@@ -134,7 +135,7 @@ HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(LPDIRECT3DDEVICE9EX iface
         FIXME("Call to IWineD3DDevice_CreateVertexShader failed\n");
         HeapFree(GetProcessHeap(), 0, object);
     }else{
-        IUnknown_AddRef(iface);
+        IDirect3DDevice9Ex_AddRef(iface);
         object->parentDevice = iface;
         *ppShader = (IDirect3DVertexShader9 *)object;
         TRACE("(%p) : Created vertex shader %p\n", This, object);
index 2af611d..80146f9 100644 (file)
@@ -30,7 +30,7 @@ static HRESULT WINAPI IDirect3DVolume9Impl_QueryInterface(LPDIRECT3DVOLUME9 ifac
 
     if (IsEqualGUID(riid, &IID_IUnknown)
         || IsEqualGUID(riid, &IID_IDirect3DVolume9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DVolume9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
index 28a7460..3069771 100644 (file)
@@ -32,7 +32,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_QueryInterface(LPDIRECT3DVOLUM
     || IsEqualGUID(riid, &IID_IDirect3DResource9)
     || IsEqualGUID(riid, &IID_IDirect3DBaseTexture9)
     || IsEqualGUID(riid, &IID_IDirect3DVolumeTexture9)) {
-        IUnknown_AddRef(iface);
+        IDirect3DVolumeTexture9_AddRef(iface);
         *ppobj = This;
         return S_OK;
     }
@@ -59,7 +59,7 @@ static ULONG WINAPI IDirect3DVolumeTexture9Impl_Release(LPDIRECT3DVOLUMETEXTURE9
 
     if (ref == 0) {
         IWineD3DVolumeTexture_Destroy(This->wineD3DVolumeTexture, D3D9CB_DestroyVolume);
-        IUnknown_Release(This->parentDevice);
+        IDirect3DDevice9Ex_Release(This->parentDevice);
         HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -269,7 +269,7 @@ HRESULT  WINAPI  IDirect3DDevice9Impl_CreateVolumeTexture(LPDIRECT3DDEVICE9EX if
         FIXME("(%p) call to IWineD3DDevice_CreateVolumeTexture failed\n", This);
         HeapFree(GetProcessHeap(), 0, object);
     } else {
-        IUnknown_AddRef(iface);
+        IDirect3DDevice9Ex_AddRef(iface);
         object->parentDevice = iface;
         *ppVolumeTexture = (LPDIRECT3DVOLUMETEXTURE9) object;
         TRACE("(%p) : Created volume texture %p\n", This, object);
index 9ec6494..dd0984e 100644 (file)
@@ -3,12 +3,12 @@ TOPOBJDIR = ../..
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = wined3d.dll
-IMPORTLIB = libwined3d.$(IMPLIBEXT)
-IMPORTS   = user32 gdi32 advapi32 kernel32
-EXTRALIBS = -luuid
+IMPORTLIB = wined3d
+IMPORTS   = uuid user32 gdi32 advapi32 kernel32
 
 C_SRCS = \
        arb_program_shader.c \
+       ati_fragment_shader.c \
        baseshader.c \
        basetexture.c \
        clipper.c \
@@ -19,6 +19,7 @@ C_SRCS = \
        drawprim.c \
        glsl_shader.c \
        indexbuffer.c \
+       nvidia_texture_shader.c \
        palette.c \
        pixelshader.c \
        query.c \
@@ -29,6 +30,8 @@ C_SRCS = \
        surface.c \
        surface_gdi.c \
        swapchain.c \
+       swapchain_gdi.c \
+       swapchain_base.c \
        texture.c \
        utils.c \
        vertexbuffer.c \
index 2bb70c3..12148e6 100644 (file)
@@ -9,7 +9,7 @@
  * Copyright 2006 Ivan Gyurdiev
  * Copyright 2006 Jason Green
  * Copyright 2006 Henri Verbeet
- * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -50,7 +50,7 @@ struct shader_arb_priv {
     GLuint                  current_vprogram_id;
     GLuint                  current_fprogram_id;
     GLuint                  depth_blt_vprogram_id;
-    GLuint                  depth_blt_fprogram_id;
+    GLuint                  depth_blt_fprogram_id[tex_type_count];
     BOOL                    use_arbfp_fixed_func;
     struct hash_table_t     *fragment_shaders;
 };
@@ -659,8 +659,7 @@ static void gen_color_correction(SHADER_BUFFER *buffer, const char *reg, const c
     switch(fmt) {
         case WINED3DFMT_V8U8:
         case WINED3DFMT_V16U16:
-            if(GL_SUPPORT(NV_TEXTURE_SHADER) ||
-              (GL_SUPPORT(ATI_ENVMAP_BUMPMAP) && fmt == WINED3DFMT_V8U8)) {
+            if(GL_SUPPORT(NV_TEXTURE_SHADER) && fmt == WINED3DFMT_V8U8) {
                 if(0) {
                     /* The 3rd channel returns 1.0 in d3d, but 0.0 in gl. Fix this while we're at it :-)
                      * disabled until an application that needs it is found because it causes unneeded
@@ -722,9 +721,9 @@ static void gen_color_correction(SHADER_BUFFER *buffer, const char *reg, const c
                     /* Swap y and z (U and L), and do a sign conversion on x and the new y(V and U) */
                     shader_addline(buffer, "MOV TMP.g, %s.%c;\n",
                                    reg, writemask[2]);
-                    shader_addline(buffer, "MAD %s.%c%c, %s.%c%c, %s, -%s;\n",
-                                   reg, writemask[1], writemask[1],
-                                   reg, writemask[1], writemask[3],
+                    shader_addline(buffer, "MAD %s.%c%c, %s.%c%c%c%c, %s, -%s;\n",
+                                   reg, writemask[1], writemask[2],
+                                   reg, writemask[3], writemask[1], writemask[3], writemask[1],
                                    two, one);
                     shader_addline(buffer, "MOV %s.%c, TMP.g;\n", reg,
                                    writemask[3]);
@@ -956,7 +955,7 @@ static inline void pshader_gen_output_modifier_line(
         regstr, write_mask, regstr, shift_tab[shift]);
 }
 
-void pshader_hw_bem(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_bem(SHADER_OPCODE_ARG* arg) {
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
 
     SHADER_BUFFER* buffer = arg->buffer;
@@ -994,7 +993,7 @@ void pshader_hw_bem(SHADER_OPCODE_ARG* arg) {
     }
 }
 
-void pshader_hw_cnd(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_cnd(SHADER_OPCODE_ARG* arg) {
 
     IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader;
     SHADER_BUFFER* buffer = arg->buffer;
@@ -1028,7 +1027,7 @@ void pshader_hw_cnd(SHADER_OPCODE_ARG* arg) {
         pshader_gen_output_modifier_line(buffer, FALSE, dst_wmask, shift, dst_name);
 }
 
-void pshader_hw_cmp(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_cmp(SHADER_OPCODE_ARG* arg) {
 
     SHADER_BUFFER* buffer = arg->buffer;
     char dst_wmask[20];
@@ -1057,7 +1056,7 @@ void pshader_hw_cmp(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_DP2ADD instruction in ARB.
  * dst = dot2(src0, src1) + src2 */
-void pshader_hw_dp2add(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_dp2add(SHADER_OPCODE_ARG* arg) {
     SHADER_BUFFER* buffer = arg->buffer;
     char dst_wmask[20];
     char dst_name[50];
@@ -1083,74 +1082,138 @@ void pshader_hw_dp2add(SHADER_OPCODE_ARG* arg) {
 }
 
 /* Map the opcode 1-to-1 to the GL code */
-void pshader_hw_map2gl(SHADER_OPCODE_ARG* arg) {
+static void shader_hw_map2gl(SHADER_OPCODE_ARG* arg)
+{
+    IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl*)arg->shader;
+    CONST SHADER_OPCODE* curOpcode = arg->opcode;
+    SHADER_BUFFER* buffer = arg->buffer;
+    DWORD dst = arg->dst;
+    DWORD* src = arg->src;
+    char arguments[256];
+    unsigned int i;
 
-     CONST SHADER_OPCODE* curOpcode = arg->opcode;
-     SHADER_BUFFER* buffer = arg->buffer;
-     DWORD dst = arg->dst;
-     DWORD* src = arg->src;
-
-     unsigned int i;
-     char tmpLine[256];
-
-     /* Output token related */
-     char output_rname[256];
-     char output_wmask[20];
-     BOOL saturate = FALSE;
-     BOOL centroid = FALSE;
-     BOOL partialprecision = FALSE;
-     DWORD shift;
-
-     strcpy(tmpLine, curOpcode->glname);
-
-     /* Process modifiers */
-     if (0 != (dst & WINED3DSP_DSTMOD_MASK)) {
-         DWORD mask = dst & WINED3DSP_DSTMOD_MASK;
-
-         saturate = mask & WINED3DSPDM_SATURATE;
-         centroid = mask & WINED3DSPDM_MSAMPCENTROID;
-         partialprecision = mask & WINED3DSPDM_PARTIALPRECISION;
-         mask &= ~(WINED3DSPDM_MSAMPCENTROID | WINED3DSPDM_PARTIALPRECISION | WINED3DSPDM_SATURATE);
-         if (mask)
-            FIXME("Unrecognized modifier(%#x)\n", mask >> WINED3DSP_DSTMOD_SHIFT);
-
-         if (centroid)
-             FIXME("Unhandled modifier(%#x)\n", mask >> WINED3DSP_DSTMOD_SHIFT);
-     }
-     shift = (dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
-
-      /* Generate input and output registers */
-      if (curOpcode->num_params > 0) {
-          char operands[4][100];
-
-          /* Generate input register names (with modifiers) */
-          for (i = 1; i < curOpcode->num_params; ++i)
-              pshader_gen_input_modifier_line(arg->shader, buffer, src[i-1], i-1, operands[i]);
-
-          /* Handle output register */
-          pshader_get_register_name(arg->shader, dst, output_rname);
-          strcpy(operands[0], output_rname);
-          shader_arb_get_write_mask(arg, dst, output_wmask);
-          strcat(operands[0], output_wmask);
-
-          if (saturate && (shift == 0))
-             strcat(tmpLine, "_SAT");
-          strcat(tmpLine, " ");
-          strcat(tmpLine, operands[0]);
-          for (i = 1; i < curOpcode->num_params; i++) {
-              strcat(tmpLine, ", ");
-              strcat(tmpLine, operands[i]);
-          }
-          strcat(tmpLine,";\n");
-          shader_addline(buffer, tmpLine);
+    if (shader_is_pshader_version(shader->baseShader.hex_version))
+    {
+        /* Output token related */
+        char output_rname[256];
+        char output_wmask[20];
+        char operands[4][100];
+        BOOL saturate = FALSE;
+        BOOL centroid = FALSE;
+        BOOL partialprecision = FALSE;
+        const char *modifier;
+        DWORD shift;
+
+        if (!curOpcode->num_params)
+        {
+            ERR("Opcode \"%s\" has no parameters\n", curOpcode->name);
+            return;
+        }
 
-          /* A shift requires another line. */
-          if (shift != 0)
-              pshader_gen_output_modifier_line(buffer, saturate, output_wmask, shift, output_rname);
-      }
+        /* Process modifiers */
+        if (dst & WINED3DSP_DSTMOD_MASK)
+        {
+            DWORD mask = dst & WINED3DSP_DSTMOD_MASK;
+
+            saturate = mask & WINED3DSPDM_SATURATE;
+            centroid = mask & WINED3DSPDM_MSAMPCENTROID;
+            partialprecision = mask & WINED3DSPDM_PARTIALPRECISION;
+            mask &= ~(WINED3DSPDM_MSAMPCENTROID | WINED3DSPDM_PARTIALPRECISION | WINED3DSPDM_SATURATE);
+            if (mask)
+                FIXME("Unrecognized modifier(%#x)\n", mask >> WINED3DSP_DSTMOD_SHIFT);
+
+            if (centroid)
+                FIXME("Unhandled modifier(%#x)\n", mask >> WINED3DSP_DSTMOD_SHIFT);
+        }
+        shift = (dst & WINED3DSP_DSTSHIFT_MASK) >> WINED3DSP_DSTSHIFT_SHIFT;
+        modifier = (saturate && !shift) ? "_SAT" : "";
+
+        /* Generate input register names (with modifiers) */
+        for (i = 1; i < curOpcode->num_params; ++i)
+            pshader_gen_input_modifier_line(arg->shader, buffer, src[i-1], i-1, operands[i]);
+
+        /* Handle output register */
+        pshader_get_register_name(arg->shader, dst, output_rname);
+        strcpy(operands[0], output_rname);
+        shader_arb_get_write_mask(arg, dst, output_wmask);
+        strcat(operands[0], output_wmask);
+
+        arguments[0] = '\0';
+        strcat(arguments, operands[0]);
+        for (i = 1; i < curOpcode->num_params; i++)
+        {
+            strcat(arguments, ", ");
+            strcat(arguments, operands[i]);
+        }
+        shader_addline(buffer, "%s%s %s;\n", curOpcode->glname, modifier, arguments);
+
+        /* A shift requires another line. */
+        if (shift) pshader_gen_output_modifier_line(buffer, saturate, output_wmask, shift, output_rname);
+    } else {
+        /* Note that vshader_program_add_param() adds spaces. */
+
+        arguments[0] = '\0';
+        if (curOpcode->num_params > 0)
+        {
+            vshader_program_add_param(arg, dst, FALSE, arguments);
+            for (i = 1; i < curOpcode->num_params; ++i)
+            {
+                strcat(arguments, ",");
+                vshader_program_add_param(arg, src[i-1], TRUE, arguments);
+            }
+        }
+        shader_addline(buffer, "%s%s;\n", curOpcode->glname, arguments);
+    }
+}
+
+static void shader_hw_mov(SHADER_OPCODE_ARG *arg)
+{
+    IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl*)arg->shader;
+
+    if ((WINED3DSHADER_VERSION_MAJOR(shader->baseShader.hex_version) == 1
+            && !shader_is_pshader_version(shader->baseShader.hex_version)
+            && shader_get_regtype(arg->dst) == WINED3DSPR_ADDR)
+            || arg->opcode->opcode == WINED3DSIO_MOVA)
+    {
+        SHADER_BUFFER *buffer = arg->buffer;
+        char src0_param[256];
+
+        if (arg->opcode->opcode == WINED3DSIO_MOVA)
+            FIXME("mova should round\n");
+
+        src0_param[0] = '\0';
+        if (((IWineD3DVertexShaderImpl *)shader)->rel_offset)
+        {
+            vshader_program_add_param(arg, arg->src[0], TRUE, src0_param);
+            shader_addline(buffer, "ADD TMP.x, %s, helper_const.z;\n", src0_param);
+            shader_addline(buffer, "ARL A0.x, TMP.x;\n");
+        }
+        else
+        {
+            /* Apple's ARB_vertex_program implementation does not accept an ARL source argument
+             * with more than one component. Thus replicate the first source argument over all
+             * 4 components. For example, .xyzw -> .x (or better: .xxxx), .zwxy -> .z, etc)
+             */
+            DWORD parm = arg->src[0] & ~(WINED3DVS_SWIZZLE_MASK);
+            if((arg->src[0] & WINED3DVS_X_W) == WINED3DVS_X_W)
+                parm |= WINED3DVS_X_W | WINED3DVS_Y_W | WINED3DVS_Z_W | WINED3DVS_W_W;
+            else if((arg->src[0] & WINED3DVS_X_Z) == WINED3DVS_X_Z)
+                parm |= WINED3DVS_X_Z | WINED3DVS_Y_Z | WINED3DVS_Z_Z | WINED3DVS_W_Z;
+            else if((arg->src[0] & WINED3DVS_X_Y) == WINED3DVS_X_Y)
+                parm |= WINED3DVS_X_Y | WINED3DVS_Y_Y | WINED3DVS_Z_Y | WINED3DVS_W_Y;
+            else if((arg->src[0] & WINED3DVS_X_X) == WINED3DVS_X_X)
+                parm |= WINED3DVS_X_X | WINED3DVS_Y_X | WINED3DVS_Z_X | WINED3DVS_W_X;
+            vshader_program_add_param(arg, parm, TRUE, src0_param);
+            shader_addline(buffer, "ARL A0.x, %s;\n", src0_param);
+        }
+    }
+    else
+    {
+        shader_hw_map2gl(arg);
+    }
 }
 
-void pshader_hw_texkill(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texkill(SHADER_OPCODE_ARG* arg) {
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     DWORD hex_version = This->baseShader.hex_version;
     SHADER_BUFFER* buffer = arg->buffer;
@@ -1174,7 +1237,7 @@ void pshader_hw_texkill(SHADER_OPCODE_ARG* arg) {
     }
 }
 
-void pshader_hw_tex(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_tex(SHADER_OPCODE_ARG* arg) {
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
 
@@ -1238,7 +1301,7 @@ void pshader_hw_tex(SHADER_OPCODE_ARG* arg) {
   shader_hw_sample(arg, reg_sampler_code, reg_dest, reg_coord, projected, bias);
 }
 
-void pshader_hw_texcoord(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texcoord(SHADER_OPCODE_ARG* arg) {
 
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     DWORD dst = arg->dst;
@@ -1259,7 +1322,7 @@ void pshader_hw_texcoord(SHADER_OPCODE_ARG* arg) {
    }
 }
 
-void pshader_hw_texreg2ar(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texreg2ar(SHADER_OPCODE_ARG* arg) {
 
      SHADER_BUFFER* buffer = arg->buffer;
      IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
@@ -1278,7 +1341,7 @@ void pshader_hw_texreg2ar(SHADER_OPCODE_ARG* arg) {
      shader_hw_sample(arg, reg1, dst_str, "TMP", flags & WINED3DTTFF_PROJECTED, FALSE);
 }
 
-void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg) {
 
      SHADER_BUFFER* buffer = arg->buffer;
 
@@ -1293,7 +1356,7 @@ void pshader_hw_texreg2gb(SHADER_OPCODE_ARG* arg) {
      shader_hw_sample(arg, reg1, dst_str, "TMP", FALSE, FALSE);
 }
 
-void pshader_hw_texreg2rgb(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texreg2rgb(SHADER_OPCODE_ARG* arg) {
 
     SHADER_BUFFER* buffer = arg->buffer;
     DWORD reg1 = arg->dst & WINED3DSP_REGNUM_MASK;
@@ -1305,7 +1368,7 @@ void pshader_hw_texreg2rgb(SHADER_OPCODE_ARG* arg) {
     shader_hw_sample(arg, reg1, dst_str, src_str, FALSE, FALSE);
 }
 
-void pshader_hw_texbem(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texbem(SHADER_OPCODE_ARG* arg) {
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     BOOL has_bumpmat = FALSE;
     BOOL has_luminance = FALSE;
@@ -1376,7 +1439,7 @@ void pshader_hw_texbem(SHADER_OPCODE_ARG* arg) {
     }
 }
 
-void pshader_hw_texm3x2pad(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texm3x2pad(SHADER_OPCODE_ARG* arg) {
 
     DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
     SHADER_BUFFER* buffer = arg->buffer;
@@ -1386,7 +1449,7 @@ void pshader_hw_texm3x2pad(SHADER_OPCODE_ARG* arg) {
     shader_addline(buffer, "DP3 TMP.x, T%u, %s;\n", reg, src0_name);
 }
 
-void pshader_hw_texm3x2tex(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texm3x2tex(SHADER_OPCODE_ARG* arg) {
 
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
@@ -1403,7 +1466,7 @@ void pshader_hw_texm3x2tex(SHADER_OPCODE_ARG* arg) {
     shader_hw_sample(arg, reg, dst_str, "TMP", flags & WINED3DTTFF_PROJECTED, FALSE);
 }
 
-void pshader_hw_texm3x3pad(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texm3x3pad(SHADER_OPCODE_ARG* arg) {
 
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
@@ -1416,7 +1479,7 @@ void pshader_hw_texm3x3pad(SHADER_OPCODE_ARG* arg) {
     current_state->texcoord_w[current_state->current_row++] = reg;
 }
 
-void pshader_hw_texm3x3tex(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texm3x3tex(SHADER_OPCODE_ARG* arg) {
 
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
@@ -1437,7 +1500,7 @@ void pshader_hw_texm3x3tex(SHADER_OPCODE_ARG* arg) {
     current_state->current_row = 0;
 }
 
-void pshader_hw_texm3x3vspec(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texm3x3vspec(SHADER_OPCODE_ARG* arg) {
 
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
@@ -1473,7 +1536,7 @@ void pshader_hw_texm3x3vspec(SHADER_OPCODE_ARG* arg) {
     current_state->current_row = 0;
 }
 
-void pshader_hw_texm3x3spec(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texm3x3spec(SHADER_OPCODE_ARG* arg) {
 
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
@@ -1510,7 +1573,7 @@ void pshader_hw_texm3x3spec(SHADER_OPCODE_ARG* arg) {
     current_state->current_row = 0;
 }
 
-void pshader_hw_texdepth(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texdepth(SHADER_OPCODE_ARG* arg) {
     SHADER_BUFFER* buffer = arg->buffer;
     char dst_name[50];
 
@@ -1539,7 +1602,7 @@ void pshader_hw_texdepth(SHADER_OPCODE_ARG* arg) {
 /** Process the WINED3DSIO_TEXDP3TEX instruction in ARB:
  * Take a 3-component dot product of the TexCoord[dstreg] and src,
  * then perform a 1D texture lookup from stage dstregnum, place into dst. */
-void pshader_hw_texdp3tex(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texdp3tex(SHADER_OPCODE_ARG* arg) {
     SHADER_BUFFER* buffer = arg->buffer;
     DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
     char src0[50];
@@ -1555,7 +1618,7 @@ void pshader_hw_texdp3tex(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_TEXDP3 instruction in ARB:
  * Take a 3-component dot product of the TexCoord[dstreg] and src. */
-void pshader_hw_texdp3(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texdp3(SHADER_OPCODE_ARG* arg) {
     char src0[50];
     char dst_str[50];
     char dst_mask[6];
@@ -1574,7 +1637,7 @@ void pshader_hw_texdp3(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_TEXM3X3 instruction in ARB
  * Perform the 3rd row of a 3x3 matrix multiply */
-void pshader_hw_texm3x3(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texm3x3(SHADER_OPCODE_ARG* arg) {
     SHADER_BUFFER* buffer = arg->buffer;
     char dst_str[50];
     char dst_mask[6];
@@ -1596,7 +1659,7 @@ void pshader_hw_texm3x3(SHADER_OPCODE_ARG* arg) {
  * Calculate tmp0.y = TexCoord[dstreg] . src.xyz;  (tmp0.x has already been calculated)
  * depth = (tmp0.y == 0.0) ? 1.0 : tmp0.x / tmp0.y
  */
-void pshader_hw_texm3x2depth(SHADER_OPCODE_ARG* arg) {
+static void pshader_hw_texm3x2depth(SHADER_OPCODE_ARG* arg) {
     SHADER_BUFFER* buffer = arg->buffer;
     DWORD dst_reg = arg->dst & WINED3DSP_REGNUM_MASK;
     char src0[50];
@@ -1616,7 +1679,7 @@ void pshader_hw_texm3x2depth(SHADER_OPCODE_ARG* arg) {
 
 /** Handles transforming all WINED3DSIO_M?x? opcodes for
     Vertex/Pixel shaders to ARB_vertex_program codes */
-void shader_hw_mnxn(SHADER_OPCODE_ARG* arg) {
+static void shader_hw_mnxn(SHADER_OPCODE_ARG* arg) {
 
     int i;
     int nComponents = 0;
@@ -1660,11 +1723,11 @@ void shader_hw_mnxn(SHADER_OPCODE_ARG* arg) {
     for (i = 0; i < nComponents; i++) {
         tmpArg.dst = ((arg->dst) & ~WINED3DSP_WRITEMASK_ALL)|(WINED3DSP_WRITEMASK_0<<i);
         tmpArg.src[1] = arg->src[1]+i;
-        vshader_hw_map2gl(&tmpArg);
+        shader_hw_map2gl(&tmpArg);
     }
 }
 
-void vshader_hw_rsq_rcp(SHADER_OPCODE_ARG* arg) {
+static void vshader_hw_rsq_rcp(SHADER_OPCODE_ARG* arg) {
     CONST SHADER_OPCODE* curOpcode = arg->opcode;
     SHADER_BUFFER* buffer = arg->buffer;
     DWORD dst = arg->dst;
@@ -1687,7 +1750,7 @@ void vshader_hw_rsq_rcp(SHADER_OPCODE_ARG* arg) {
     shader_addline(buffer, "%s;\n", tmpLine);
 }
 
-void shader_hw_nrm(SHADER_OPCODE_ARG* arg) {
+static void shader_hw_nrm(SHADER_OPCODE_ARG* arg) {
     SHADER_BUFFER* buffer = arg->buffer;
     char dst_name[50];
     char src_name[50];
@@ -1709,7 +1772,7 @@ void shader_hw_nrm(SHADER_OPCODE_ARG* arg) {
         pshader_gen_output_modifier_line(buffer, FALSE, dst_wmask, shift, dst_name);
 }
 
-void shader_hw_sincos(SHADER_OPCODE_ARG* arg) {
+static void shader_hw_sincos(SHADER_OPCODE_ARG* arg) {
     /* This instruction exists in ARB, but the d3d instruction takes two extra parameters which
      * must contain fixed constants. So we need a separate function to filter those constants and
      * can't use map2gl
@@ -1733,58 +1796,6 @@ void shader_hw_sincos(SHADER_OPCODE_ARG* arg) {
 
 }
 
-/* TODO: merge with pixel shader */
-/* Map the opcode 1-to-1 to the GL code */
-void vshader_hw_map2gl(SHADER_OPCODE_ARG* arg) {
-
-    IWineD3DVertexShaderImpl *shader = (IWineD3DVertexShaderImpl*) arg->shader;
-    CONST SHADER_OPCODE* curOpcode = arg->opcode;
-    SHADER_BUFFER* buffer = arg->buffer;
-    DWORD dst = arg->dst;
-    DWORD* src = arg->src;
-
-    DWORD dst_regtype = shader_get_regtype(dst);
-    char tmpLine[256];
-    unsigned int i;
-
-    if ((curOpcode->opcode == WINED3DSIO_MOV && dst_regtype == WINED3DSPR_ADDR) || curOpcode->opcode == WINED3DSIO_MOVA) {
-        memset(tmpLine, 0, sizeof(tmpLine));
-        if(shader->rel_offset) {
-            vshader_program_add_param(arg, src[0], TRUE, tmpLine);
-            shader_addline(buffer, "ADD TMP.x, %s, helper_const.z;\n", tmpLine);
-            shader_addline(buffer, "ARL A0.x, TMP.x;\n");
-        } else {
-            /* Apple's ARB_vertex_program implementation does not accept an ARL source argument
-             * with more than one component. Thus replicate the first source argument over all
-             * 4 components. For example, .xyzw -> .x (or better: .xxxx), .zwxy -> .z, etc)
-             */
-            DWORD parm = src[0] & ~(WINED3DVS_SWIZZLE_MASK);
-                   if((src[0] & WINED3DVS_X_W) == WINED3DVS_X_W) {
-                parm |= WINED3DVS_X_W | WINED3DVS_Y_W | WINED3DVS_Z_W | WINED3DVS_W_W;
-            } else if((src[0] & WINED3DVS_X_Z) == WINED3DVS_X_Z) {
-                parm |= WINED3DVS_X_Z | WINED3DVS_Y_Z | WINED3DVS_Z_Z | WINED3DVS_W_Z;
-            } else if((src[0] & WINED3DVS_X_Y) == WINED3DVS_X_Y) {
-                parm |= WINED3DVS_X_Y | WINED3DVS_Y_Y | WINED3DVS_Z_Y | WINED3DVS_W_Y;
-            } else if((src[0] & WINED3DVS_X_X) == WINED3DVS_X_X) {
-                parm |= WINED3DVS_X_X | WINED3DVS_Y_X | WINED3DVS_Z_X | WINED3DVS_W_X;
-            }
-            vshader_program_add_param(arg, parm, TRUE, tmpLine);
-            shader_addline(buffer, "ARL A0.x, %s;\n", tmpLine);
-        }
-        return;
-    } else
-        strcpy(tmpLine, curOpcode->glname);
-
-    if (curOpcode->num_params > 0) {
-        vshader_program_add_param(arg, dst, FALSE, tmpLine);
-        for (i = 1; i < curOpcode->num_params; ++i) {
-           strcat(tmpLine, ",");
-           vshader_program_add_param(arg, src[i-1], TRUE, tmpLine);
-        }
-    }
-   shader_addline(buffer, "%s;\n", tmpLine);
-}
-
 static GLuint create_arb_blt_vertex_program(WineD3D_GL_Info *gl_info) {
     GLuint program_id = 0;
     const char *blt_vprogram =
@@ -1792,8 +1803,7 @@ static GLuint create_arb_blt_vertex_program(WineD3D_GL_Info *gl_info) {
         "PARAM c[1] = { { 1, 0.5 } };\n"
         "MOV result.position, vertex.position;\n"
         "MOV result.color, c[0].x;\n"
-        "MAD result.texcoord[0].y, -vertex.position, c[0], c[0];\n"
-        "MAD result.texcoord[0].x, vertex.position, c[0].y, c[0].y;\n"
+        "MOV result.texcoord[0], vertex.texcoord[0];\n"
         "END\n";
 
     GL_EXTCALL(glGenProgramsARB(1, &program_id));
@@ -1810,18 +1820,44 @@ static GLuint create_arb_blt_vertex_program(WineD3D_GL_Info *gl_info) {
     return program_id;
 }
 
-static GLuint create_arb_blt_fragment_program(WineD3D_GL_Info *gl_info) {
+static GLuint create_arb_blt_fragment_program(WineD3D_GL_Info *gl_info, enum tex_types tex_type)
+{
     GLuint program_id = 0;
-    const char *blt_fprogram =
+    const char *blt_fprograms[tex_type_count] =
+    {
+        /* tex_1d */
+        NULL,
+        /* tex_2d */
         "!!ARBfp1.0\n"
         "TEMP R0;\n"
         "TEX R0.x, fragment.texcoord[0], texture[0], 2D;\n"
         "MOV result.depth.z, R0.x;\n"
-        "END\n";
+        "END\n",
+        /* tex_3d */
+        NULL,
+        /* tex_cube */
+        "!!ARBfp1.0\n"
+        "TEMP R0;\n"
+        "TEX R0.x, fragment.texcoord[0], texture[0], CUBE;\n"
+        "MOV result.depth.z, R0.x;\n"
+        "END\n",
+        /* tex_rect */
+        "!!ARBfp1.0\n"
+        "TEMP R0;\n"
+        "TEX R0.x, fragment.texcoord[0], texture[0], RECT;\n"
+        "MOV result.depth.z, R0.x;\n"
+        "END\n",
+    };
+
+    if (!blt_fprograms[tex_type])
+    {
+        FIXME("tex_type %#x not supported\n", tex_type);
+        tex_type = tex_2d;
+    }
 
     GL_EXTCALL(glGenProgramsARB(1, &program_id));
     GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, program_id));
-    GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(blt_fprogram), blt_fprogram));
+    GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(blt_fprograms[tex_type]), blt_fprograms[tex_type]));
 
     if (glGetError() == GL_INVALID_OPERATION) {
         GLint pos;
@@ -1866,35 +1902,35 @@ static void shader_arb_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {
         GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, priv->current_fprogram_id));
         checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, pixelShader->prgId);");
 
-        /* Enable OpenGL fragment programs */
-        glEnable(GL_FRAGMENT_PROGRAM_ARB);
-        checkGLcall("glEnable(GL_FRAGMENT_PROGRAM_ARB);");
+        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);
-    } else {
+    } 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(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)");
-        }
     }
 }
 
-static void shader_arb_select_depth_blt(IWineD3DDevice *iface) {
+static void shader_arb_select_depth_blt(IWineD3DDevice *iface, enum tex_types tex_type) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     struct shader_arb_priv *priv = (struct shader_arb_priv *) This->shader_priv;
+    GLuint *blt_fprogram = &priv->depth_blt_fprogram_id[tex_type];
     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);
     GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, priv->depth_blt_vprogram_id));
     glEnable(GL_VERTEX_PROGRAM_ARB);
 
-    if (!priv->depth_blt_fprogram_id) priv->depth_blt_fprogram_id = create_arb_blt_fragment_program(gl_info);
-    GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, priv->depth_blt_fprogram_id));
+    if (!*blt_fprogram) *blt_fprogram = create_arb_blt_fragment_program(gl_info, tex_type);
+    GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, *blt_fprogram));
     glEnable(GL_FRAGMENT_PROGRAM_ARB);
 }
 
@@ -1924,7 +1960,7 @@ static void shader_arb_deselect_depth_blt(IWineD3DDevice *iface) {
         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 if(!priv->use_arbfp_fixed_func) {
+    } else {
         glDisable(GL_FRAGMENT_PROGRAM_ARB);
         checkGLcall("glDisable(GL_FRAGMENT_PROGRAM_ARB)");
     }
@@ -1959,12 +1995,15 @@ static void shader_arb_free(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
     struct shader_arb_priv *priv = (struct shader_arb_priv *) This->shader_priv;
+    int i;
 
     if(priv->depth_blt_vprogram_id) {
         GL_EXTCALL(glDeleteProgramsARB(1, &priv->depth_blt_vprogram_id));
     }
-    if(priv->depth_blt_fprogram_id) {
-        GL_EXTCALL(glDeleteProgramsARB(1, &priv->depth_blt_fprogram_id));
+    for (i = 0; i < tex_type_count; ++i) {
+        if (priv->depth_blt_fprogram_id[i]) {
+            GL_EXTCALL(glDeleteProgramsARB(1, &priv->depth_blt_fprogram_id[i]));
+        }
     }
 
     HeapFree(GetProcessHeap(), 0, This->shader_priv);
@@ -2219,7 +2258,95 @@ static BOOL shader_arb_conv_supported(WINED3DFORMAT fmt) {
     }
 }
 
+static const SHADER_HANDLER shader_arb_instruction_handler_table[WINED3DSIH_TABLE_SIZE] =
+{
+    /* WINED3DSIH_ABS           */ shader_hw_map2gl,
+    /* WINED3DSIH_ADD           */ shader_hw_map2gl,
+    /* WINED3DSIH_BEM           */ pshader_hw_bem,
+    /* WINED3DSIH_BREAK         */ NULL,
+    /* WINED3DSIH_BREAKC        */ NULL,
+    /* WINED3DSIH_BREAKP        */ NULL,
+    /* WINED3DSIH_CALL          */ NULL,
+    /* WINED3DSIH_CALLNZ        */ NULL,
+    /* WINED3DSIH_CMP           */ pshader_hw_cmp,
+    /* WINED3DSIH_CND           */ pshader_hw_cnd,
+    /* WINED3DSIH_CRS           */ shader_hw_map2gl,
+    /* WINED3DSIH_DCL           */ NULL,
+    /* WINED3DSIH_DEF           */ NULL,
+    /* WINED3DSIH_DEFB          */ NULL,
+    /* WINED3DSIH_DEFI          */ NULL,
+    /* WINED3DSIH_DP2ADD        */ pshader_hw_dp2add,
+    /* WINED3DSIH_DP3           */ shader_hw_map2gl,
+    /* WINED3DSIH_DP4           */ shader_hw_map2gl,
+    /* WINED3DSIH_DST           */ shader_hw_map2gl,
+    /* WINED3DSIH_DSX           */ NULL,
+    /* 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_FRC           */ shader_hw_map2gl,
+    /* WINED3DSIH_IF            */ NULL,
+    /* WINED3DSIH_IFC           */ NULL,
+    /* WINED3DSIH_LABEL         */ NULL,
+    /* WINED3DSIH_LIT           */ shader_hw_map2gl,
+    /* WINED3DSIH_LOG           */ shader_hw_map2gl,
+    /* WINED3DSIH_LOGP          */ shader_hw_map2gl,
+    /* WINED3DSIH_LOOP          */ NULL,
+    /* WINED3DSIH_LRP           */ shader_hw_map2gl,
+    /* WINED3DSIH_M3x2          */ shader_hw_mnxn,
+    /* WINED3DSIH_M3x3          */ shader_hw_mnxn,
+    /* WINED3DSIH_M3x4          */ shader_hw_mnxn,
+    /* WINED3DSIH_M4x3          */ shader_hw_mnxn,
+    /* WINED3DSIH_M4x4          */ shader_hw_mnxn,
+    /* WINED3DSIH_MAD           */ shader_hw_map2gl,
+    /* WINED3DSIH_MAX           */ shader_hw_map2gl,
+    /* WINED3DSIH_MIN           */ shader_hw_map2gl,
+    /* WINED3DSIH_MOV           */ shader_hw_mov,
+    /* WINED3DSIH_MOVA          */ shader_hw_mov,
+    /* WINED3DSIH_MUL           */ shader_hw_map2gl,
+    /* WINED3DSIH_NOP           */ shader_hw_map2gl,
+    /* WINED3DSIH_NRM           */ shader_hw_nrm,
+    /* WINED3DSIH_PHASE         */ NULL,
+    /* WINED3DSIH_POW           */ shader_hw_map2gl,
+    /* WINED3DSIH_RCP           */ vshader_hw_rsq_rcp,
+    /* WINED3DSIH_REP           */ NULL,
+    /* WINED3DSIH_RET           */ NULL,
+    /* WINED3DSIH_RSQ           */ vshader_hw_rsq_rcp,
+    /* WINED3DSIH_SETP          */ NULL,
+    /* WINED3DSIH_SGE           */ shader_hw_map2gl,
+    /* WINED3DSIH_SGN           */ NULL,
+    /* WINED3DSIH_SINCOS        */ shader_hw_sincos,
+    /* WINED3DSIH_SLT           */ shader_hw_map2gl,
+    /* WINED3DSIH_SUB           */ shader_hw_map2gl,
+    /* WINED3DSIH_TEX           */ pshader_hw_tex,
+    /* WINED3DSIH_TEXBEM        */ pshader_hw_texbem,
+    /* WINED3DSIH_TEXBEML       */ pshader_hw_texbem,
+    /* WINED3DSIH_TEXCOORD      */ pshader_hw_texcoord,
+    /* WINED3DSIH_TEXDEPTH      */ pshader_hw_texdepth,
+    /* WINED3DSIH_TEXDP3        */ pshader_hw_texdp3,
+    /* WINED3DSIH_TEXDP3TEX     */ pshader_hw_texdp3tex,
+    /* WINED3DSIH_TEXKILL       */ pshader_hw_texkill,
+    /* WINED3DSIH_TEXLDD        */ NULL,
+    /* WINED3DSIH_TEXLDL        */ NULL,
+    /* WINED3DSIH_TEXM3x2DEPTH  */ pshader_hw_texm3x2depth,
+    /* WINED3DSIH_TEXM3x2PAD    */ pshader_hw_texm3x2pad,
+    /* WINED3DSIH_TEXM3x2TEX    */ pshader_hw_texm3x2tex,
+    /* WINED3DSIH_TEXM3x3       */ pshader_hw_texm3x3,
+    /* WINED3DSIH_TEXM3x3DIFF   */ NULL,
+    /* WINED3DSIH_TEXM3x3PAD    */ pshader_hw_texm3x3pad,
+    /* WINED3DSIH_TEXM3x3SPEC   */ pshader_hw_texm3x3spec,
+    /* WINED3DSIH_TEXM3x3TEX    */ pshader_hw_texm3x3tex,
+    /* WINED3DSIH_TEXM3x3VSPEC  */ pshader_hw_texm3x3vspec,
+    /* WINED3DSIH_TEXREG2AR     */ pshader_hw_texreg2ar,
+    /* WINED3DSIH_TEXREG2GB     */ pshader_hw_texreg2gb,
+    /* WINED3DSIH_TEXREG2RGB    */ pshader_hw_texreg2rgb,
+};
+
 const shader_backend_t arb_program_shader_backend = {
+    shader_arb_instruction_handler_table,
     shader_arb_select,
     shader_arb_select_depth_blt,
     shader_arb_deselect_depth_blt,
@@ -2245,7 +2372,7 @@ const shader_backend_t arb_program_shader_backend = {
 
 struct arbfp_ffp_desc
 {
-    struct ffp_desc parent;
+    struct ffp_frag_desc parent;
     GLuint shader;
     unsigned int num_textures_used;
 };
@@ -2274,7 +2401,7 @@ static HRESULT arbfp_alloc(IWineD3DDevice *iface) {
         if(!This->fragment_priv) return E_OUTOFMEMORY;
     }
     priv = (struct shader_arb_priv *) This->fragment_priv;
-    priv->fragment_shaders = hash_table_create(ffp_program_key_hash, ffp_program_key_compare);
+    priv->fragment_shaders = hash_table_create(ffp_frag_program_key_hash, ffp_frag_program_key_compare);
     priv->use_arbfp_fixed_func = TRUE;
     return WINED3D_OK;
 }
@@ -2343,26 +2470,37 @@ static void state_texfactor_arbfp(DWORD state, IWineD3DStateBlockImpl *statebloc
     float col[4];
     IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
 
-    /* Do not overwrite pixel shader constants if a pshader is in use */
-    if(use_ps(device)) return;
-
-    D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_TEXTUREFACTOR], col);
-    GL_EXTCALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_TFACTOR, col));
-    checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_TFACTOR, col)");
-
+    /* Don't load the parameter if we're using an arbfp pixel shader, otherwise we'll overwrite
+     * application provided constants
+     */
     if(device->shader_backend == &arb_program_shader_backend) {
+        if(use_ps(device)) return;
+
         device = stateblock->wineD3DDevice;
         device->activeContext->pshader_const_dirty[ARB_FFP_CONST_TFACTOR] = 1;
         device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_TFACTOR + 1);
     }
+
+    D3DCOLORTOGLFLOAT4(stateblock->renderState[WINED3DRS_TEXTUREFACTOR], col);
+    GL_EXTCALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_TFACTOR, col));
+    checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_TFACTOR, col)");
+
 }
 
 static void state_arb_specularenable(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
     float col[4];
     IWineD3DDeviceImpl *device = stateblock->wineD3DDevice;
 
-    /* Do not overwrite pixel shader constants if a pshader is in use */
-    if(use_ps(device)) return;
+    /* Don't load the parameter if we're using an arbfp pixel shader, otherwise we'll overwrite
+     * application provided constants
+     */
+    if(device->shader_backend == &arb_program_shader_backend) {
+        if(use_ps(device)) return;
+
+        device = stateblock->wineD3DDevice;
+        device->activeContext->pshader_const_dirty[ARB_FFP_CONST_SPECULAR_ENABLE] = 1;
+        device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_SPECULAR_ENABLE + 1);
+    }
 
     if(stateblock->renderState[WINED3DRS_SPECULARENABLE]) {
         /* The specular color has no alpha */
@@ -2374,12 +2512,6 @@ static void state_arb_specularenable(DWORD state, IWineD3DStateBlockImpl *stateb
     }
     GL_EXTCALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_SPECULAR_ENABLE, col));
     checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_SPECULAR_ENABLE, col)");
-
-    if(device->shader_backend == &arb_program_shader_backend) {
-        device = stateblock->wineD3DDevice;
-        device->activeContext->pshader_const_dirty[ARB_FFP_CONST_SPECULAR_ENABLE] = 1;
-        device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_SPECULAR_ENABLE + 1);
-    }
 }
 
 static void set_bumpmat_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
@@ -2397,8 +2529,14 @@ static void set_bumpmat_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock, W
                 device->StateTable[STATE_PIXELSHADERCONSTANT].apply(STATE_PIXELSHADERCONSTANT, stateblock, context);
             }
         }
-        /* Exit now, don't set the bumpmat below, otherwise we may overwrite pixel shader constants */
-        return;
+
+        if(device->shader_backend == &arb_program_shader_backend) {
+            /* Exit now, don't set the bumpmat below, otherwise we may overwrite pixel shader constants */
+            return;
+        }
+    } else if(device->shader_backend == &arb_program_shader_backend) {
+        device->activeContext->pshader_const_dirty[ARB_FFP_CONST_BUMPMAT(stage)] = 1;
+        device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_BUMPMAT(stage) + 1);
     }
 
     mat[0][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT00]);
@@ -2408,11 +2546,6 @@ static void set_bumpmat_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock, W
 
     GL_EXTCALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_BUMPMAT(stage), &mat[0][0]));
     checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_BUMPMAT(stage), &mat[0][0])");
-
-    if(device->shader_backend == &arb_program_shader_backend) {
-        device->activeContext->pshader_const_dirty[ARB_FFP_CONST_BUMPMAT(stage)] = 1;
-        device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_BUMPMAT(stage) + 1);
-    }
 }
 
 static void tex_bumpenvlum_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
@@ -2430,8 +2563,14 @@ static void tex_bumpenvlum_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock
                 device->StateTable[STATE_PIXELSHADERCONSTANT].apply(STATE_PIXELSHADERCONSTANT, stateblock, context);
             }
         }
-        /* Exit now, don't set the bumpmat below, otherwise we may overwrite pixel shader constants */
-        return;
+
+        if(device->shader_backend == &arb_program_shader_backend) {
+            /* Exit now, don't set the bumpmat below, otherwise we may overwrite pixel shader constants */
+            return;
+        }
+    } else if(device->shader_backend == &arb_program_shader_backend) {
+        device->activeContext->pshader_const_dirty[ARB_FFP_CONST_LUMINANCE(stage)] = 1;
+        device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_LUMINANCE(stage) + 1);
     }
 
     param[0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVLSCALE]);
@@ -2441,11 +2580,6 @@ static void tex_bumpenvlum_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock
 
     GL_EXTCALL(glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_LUMINANCE(stage), param));
     checkGLcall("glProgramEnvParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, ARB_FFP_CONST_LUMINANCE(stage), param)");
-
-    if(device->shader_backend == &arb_program_shader_backend) {
-        device->activeContext->pshader_const_dirty[ARB_FFP_CONST_LUMINANCE(stage)] = 1;
-        device->highest_dirty_ps_const = max(device->highest_dirty_ps_const, ARB_FFP_CONST_LUMINANCE(stage) + 1);
-    }
 }
 
 static const char *get_argreg(SHADER_BUFFER *buffer, DWORD argnum, unsigned int stage, DWORD arg) {
@@ -2496,7 +2630,10 @@ static const char *get_argreg(SHADER_BUFFER *buffer, DWORD argnum, unsigned int
                 case 5: ret = "const5"; break;
                 case 6: ret = "const6"; break;
                 case 7: ret = "const7"; break;
+                default: ret = "unknown constant";
             }
+            break;
+
         default:
             return "unknown";
     }
@@ -2655,7 +2792,7 @@ static void gen_ffp_instr(SHADER_BUFFER *buffer, unsigned int stage, BOOL color,
 }
 
 /* The stateblock is passed for GLINFO_LOCATION */
-static GLuint gen_arbfp_ffp_shader(struct ffp_settings *settings, IWineD3DStateBlockImpl *stateblock) {
+static GLuint gen_arbfp_ffp_shader(struct ffp_frag_settings *settings, IWineD3DStateBlockImpl *stateblock) {
     unsigned int stage;
     SHADER_BUFFER buffer;
     BOOL tex_read[MAX_TEXTURES] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
@@ -2736,6 +2873,7 @@ static GLuint gen_arbfp_ffp_shader(struct ffp_settings *settings, IWineD3DStateB
     }
 
     shader_addline(&buffer, "PARAM const = {1, 2, 4, 0.5};\n");
+    shader_addline(&buffer, "TEMP TMP;\n");
     shader_addline(&buffer, "TEMP ret;\n");
     if(tempreg_used || settings->sRGB_write) shader_addline(&buffer, "TEMP tempreg;\n");
     shader_addline(&buffer, "TEMP arg0;\n");
@@ -2922,7 +3060,7 @@ static void fragment_prog_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock,
     struct shader_arb_priv *priv = (struct shader_arb_priv *) device->fragment_priv;
     BOOL use_pshader = use_ps(device);
     BOOL use_vshader = use_vs(device);
-    struct ffp_settings settings;
+    struct ffp_frag_settings settings;
     struct arbfp_ffp_desc *desc;
     unsigned int i;
 
@@ -2944,8 +3082,8 @@ static void fragment_prog_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock,
         IWineD3DPixelShader_CompileShader(stateblock->pixelShader);
     } else {
         /* Find or create a shader implementing the fixed function pipeline settings, then activate it */
-        gen_ffp_op(stateblock, &settings, FALSE);
-        desc = (struct arbfp_ffp_desc *) find_ffp_shader(priv->fragment_shaders, &settings);
+        gen_ffp_frag_op(stateblock, &settings, FALSE);
+        desc = (struct arbfp_ffp_desc *) find_ffp_frag_shader(priv->fragment_shaders, &settings);
         if(!desc) {
             desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
             if(!desc) {
@@ -2960,7 +3098,7 @@ static void fragment_prog_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock,
 
             memcpy(&desc->parent.settings, &settings, sizeof(settings));
             desc->shader = gen_arbfp_ffp_shader(&settings, stateblock);
-            add_ffp_shader(priv->fragment_shaders, &desc->parent);
+            add_ffp_frag_shader(priv->fragment_shaders, &desc->parent);
             TRACE("Allocated fixed function replacement shader descriptor %p\n", desc);
         }
 
@@ -2970,6 +3108,7 @@ static void fragment_prog_arbfp(DWORD state, IWineD3DStateBlockImpl *stateblock,
          */
         GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, desc->shader));
         checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, desc->shader)");
+        priv->current_fprogram_id = desc->shader;
 
         if(device->shader_backend == &arb_program_shader_backend && context->last_was_pshader) {
             /* Reload fixed function constants since they collide with the pixel shader constants */
@@ -3454,10 +3593,12 @@ static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, WINED3DFORMAT fmt, GLen
     buffer.newline = TRUE;
     buffer.buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, SHADER_PGMSIZE);
 
+    ENTER_GL();
     GL_EXTCALL(glGenProgramsARB(1, &shader));
     checkGLcall("GL_EXTCALL(glGenProgramsARB(1, &shader))");
     GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader));
     checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader)");
+    LEAVE_GL();
     if(!shader) {
         HeapFree(GetProcessHeap(), 0, buffer.buffer);
         return 0;
@@ -3532,6 +3673,7 @@ static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, WINED3DFORMAT fmt, GLen
     shader_addline(&buffer, "MAD result.color.b, chroma.g, yuv_coef.w, luminance.%c;\n", luminance_component);
     shader_addline(&buffer, "END\n");
 
+    ENTER_GL();
     GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(buffer.buffer), buffer.buffer));
 
     if (glGetError() == GL_INVALID_OPERATION) {
@@ -3541,6 +3683,7 @@ static GLuint gen_yuv_shader(IWineD3DDeviceImpl *device, WINED3DFORMAT fmt, GLen
               debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
     }
     HeapFree(GetProcessHeap(), 0, buffer.buffer);
+    LEAVE_GL();
 
     if(fmt == WINED3DFMT_YUY2) {
         if(textype == GL_TEXTURE_RECTANGLE_ARB) {
@@ -3577,8 +3720,10 @@ static HRESULT arbfp_blit_set(IWineD3DDevice *iface, WINED3DFORMAT fmt, GLenum t
        glDesc->conversion_group != WINED3DFMT_YV12) {
         TRACE("Format: %s\n", debug_d3dformat(glDesc->conversion_group));
         /* Don't bother setting up a shader for unconverted formats */
+        ENTER_GL();
         glEnable(textype);
         checkGLcall("glEnable(textype)");
+        LEAVE_GL();
         return WINED3D_OK;
     }
 
@@ -3606,18 +3751,22 @@ static HRESULT arbfp_blit_set(IWineD3DDevice *iface, WINED3DFORMAT fmt, GLenum t
         shader = gen_yuv_shader(device, glDesc->conversion_group, textype);
     }
 
+    ENTER_GL();
     glEnable(GL_FRAGMENT_PROGRAM_ARB);
     checkGLcall("glEnable(GL_FRAGMENT_PROGRAM_ARB)");
     GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader));
     checkGLcall("glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader)");
     GL_EXTCALL(glProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB, 0, size));
     checkGLcall("glProgramLocalParameter4fvARB");
+    LEAVE_GL();
 
     return WINED3D_OK;
 }
 
 static void arbfp_blit_unset(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) iface;
+
+    ENTER_GL();
     glDisable(GL_FRAGMENT_PROGRAM_ARB);
     checkGLcall("glDisable(GL_FRAGMENT_PROGRAM_ARB)");
     glDisable(GL_TEXTURE_2D);
@@ -3630,6 +3779,7 @@ static void arbfp_blit_unset(IWineD3DDevice *iface) {
         glDisable(GL_TEXTURE_RECTANGLE_ARB);
         checkGLcall("glDisable(GL_TEXTURE_RECTANGLE_ARB)");
     }
+    LEAVE_GL();
 }
 
 static BOOL arbfp_blit_conv_supported(WINED3DFORMAT fmt) {
index 20c4ebe..a53108e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Fixed function pipeline replacement using GL_ATI_fragment_shader
  *
- * Copyright 2008 Stefan Dösinger(for CodeWeavers)
+ * Copyright 2008 Stefan Dösinger(for CodeWeavers)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -43,7 +43,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d_shader);
 /* GL_ATI_fragment_shader specific fixed function pipeline description. "Inherits" from the common one */
 struct atifs_ffp_desc
 {
-    struct ffp_desc parent;
+    struct ffp_frag_desc parent;
     GLuint shader;
     unsigned int num_textures_used;
 };
@@ -163,7 +163,11 @@ static GLuint register_for_arg(DWORD arg, WineD3D_GL_Info *gl_info, unsigned int
     GLenum ret;
 
     if(mod) *mod = GL_NONE;
-    if(arg == ARG_UNUSED) return -1; /* This is the marker for unused registers */
+    if(arg == ARG_UNUSED)
+    {
+        if (rep) *rep = GL_NONE;
+        return -1; /* This is the marker for unused registers */
+    }
 
     switch(arg & WINED3DTA_SELECTMASK) {
         case WINED3DTA_DIFFUSE:
@@ -799,13 +803,13 @@ static GLuint gen_ati_shader(struct texture_stage_op op[MAX_TEXTURES], WineD3D_G
 static void set_tex_op_atifs(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
     IWineD3DDeviceImpl          *This = stateblock->wineD3DDevice;
     struct atifs_ffp_desc       *desc;
-    struct ffp_settings settings;
+    struct ffp_frag_settings     settings;
     struct atifs_private_data   *priv = (struct atifs_private_data *) This->fragment_priv;
     DWORD mapped_stage;
     unsigned int i;
 
-    gen_ffp_op(stateblock, &settings, TRUE);
-    desc = (struct atifs_ffp_desc *) find_ffp_shader(priv->fragment_shaders, &settings);
+    gen_ffp_frag_op(stateblock, &settings, TRUE);
+    desc = (struct atifs_ffp_desc *) find_ffp_frag_shader(priv->fragment_shaders, &settings);
     if(!desc) {
         desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*desc));
         if(!desc) {
@@ -820,7 +824,7 @@ static void set_tex_op_atifs(DWORD state, IWineD3DStateBlockImpl *stateblock, Wi
 
         memcpy(&desc->parent.settings, &settings, sizeof(settings));
         desc->shader = gen_ati_shader(settings.op, &GLINFO_LOCATION);
-        add_ffp_shader(priv->fragment_shaders, &desc->parent);
+        add_ffp_frag_shader(priv->fragment_shaders, &desc->parent);
         TRACE("Allocated fixed function replacement shader descriptor %p\n", desc);
     }
 
@@ -1070,7 +1074,7 @@ static HRESULT atifs_alloc(IWineD3DDevice *iface) {
         return E_OUTOFMEMORY;
     }
     priv = (struct atifs_private_data *) This->fragment_priv;
-    priv->fragment_shaders = hash_table_create(ffp_program_key_hash, ffp_program_key_compare);
+    priv->fragment_shaders = hash_table_create(ffp_frag_program_key_hash, ffp_frag_program_key_compare);
     return WINED3D_OK;
 }
 
index 82187fc..f7c8d35 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright 2004 Christian Costa
  * Copyright 2005 Oliver Stieber
  * Copyright 2006 Ivan Gyurdiev
- * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -790,6 +790,7 @@ void shader_generate_main(
 
     IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*) iface;
     IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *) This->baseShader.device; /* To access shader backend callbacks */
+    const SHADER_HANDLER *handler_table = device->shader_backend->shader_instruction_handler_table;
     const DWORD *pToken = pFunction;
     const SHADER_OPCODE *curOpcode = NULL;
     SHADER_HANDLER hw_fct = NULL;
@@ -828,10 +829,8 @@ void shader_generate_main(
             /* Select handler */
             if (curOpcode == NULL)
                 hw_fct = NULL;
-            else if (This->baseShader.shader_mode == SHADER_GLSL)
-                hw_fct = curOpcode->hw_glsl_fct;
-            else if (This->baseShader.shader_mode == SHADER_ARB)
-                hw_fct = curOpcode->hw_fct;
+            else
+                hw_fct = handler_table[curOpcode->handler_idx];
 
             /* Unknown opcode and its parameters */
             if (NULL == curOpcode) {
@@ -883,6 +882,8 @@ void shader_generate_main(
                 device->shader_backend->shader_color_correction(&hw_arg);
 
                 /* Process instruction modifiers for GLSL apps ( _sat, etc. ) */
+                /* FIXME: This should be internal to the shader backend.
+                 * Also, right now this is the only reason "shader_mode" exists. */
                 if (This->baseShader.shader_mode == SHADER_GLSL)
                     shader_glsl_add_instruction_modifiers(&hw_arg);
 
@@ -936,7 +937,7 @@ void shader_trace_init(
     unsigned int len = 0;
     DWORD i;
 
-    TRACE("(%p) : Parsing programme\n", This);
+    TRACE("(%p) : Parsing program\n", This);
 
     if (NULL != pToken) {
         while (WINED3DVS_END() != *pToken) {
@@ -1089,8 +1090,9 @@ void shader_trace_init(
     }
 }
 
+static const SHADER_HANDLER shader_none_instruction_handler_table[WINED3DSIH_TABLE_SIZE] = {0};
 static void shader_none_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {}
-static void shader_none_select_depth_blt(IWineD3DDevice *iface) {}
+static void shader_none_select_depth_blt(IWineD3DDevice *iface, enum tex_types tex_type) {}
 static void shader_none_deselect_depth_blt(IWineD3DDevice *iface) {}
 static void shader_none_load_constants(IWineD3DDevice *iface, char usePS, char useVS) {}
 static void shader_none_cleanup(IWineD3DDevice *iface) {}
@@ -1132,6 +1134,7 @@ static BOOL shader_none_conv_supported(WINED3DFORMAT fmt) {
 }
 
 const shader_backend_t none_shader_backend = {
+    shader_none_instruction_handler_table,
     shader_none_select,
     shader_none_select_depth_blt,
     shader_none_deselect_depth_blt,
index ffc01e8..69574b2 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright 2002-2004 Jason Edmeades
  * Copyright 2002-2004 Raphael Junqueira
  * Copyright 2005 Oliver Stieber
- * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
index 75bbbd0..feb6e23 100644 (file)
@@ -2,7 +2,7 @@
  *
  * Copyright 2000 (c) Marcus Meissner
  * Copyright 2000 (c) TransGaming Technologies Inc.
- * Copyright 2006 (c) Stefan Dösinger
+ * Copyright 2006 (c) Stefan Dösinger
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
index 76d449a..acfe36b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Context and render target management in wined3d
  *
- * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -77,14 +77,17 @@ static void context_apply_attachment_filter_states(IWineD3DDevice *iface, IWineD
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     const IWineD3DSurfaceImpl *surface_impl = (IWineD3DSurfaceImpl *)surface;
     IWineD3DBaseTextureImpl *texture_impl;
-    BOOL update_minfilter, update_magfilter;
+    BOOL update_minfilter = FALSE;
+    BOOL update_magfilter = FALSE;
 
     /* Update base texture states array */
     if (SUCCEEDED(IWineD3DSurface_GetContainer(surface, &IID_IWineD3DBaseTexture, (void **)&texture_impl)))
     {
-        if (texture_impl->baseTexture.states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_POINT)
+        if (texture_impl->baseTexture.states[WINED3DTEXSTA_MINFILTER] != WINED3DTEXF_POINT
+            || texture_impl->baseTexture.states[WINED3DTEXSTA_MIPFILTER] != WINED3DTEXF_NONE)
         {
             texture_impl->baseTexture.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
+            texture_impl->baseTexture.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
             update_minfilter = TRUE;
         }
 
@@ -188,7 +191,7 @@ static void context_check_fbo_status(IWineD3DDevice *iface)
         TRACE("FBO complete\n");
     } else {
         IWineD3DSurfaceImpl *attachment;
-        int i;
+        unsigned int i;
         FIXME("FBO status %s (%#x)\n", debug_fbostatus(status), status);
 
         /* Dump the FBO attachments */
@@ -225,7 +228,7 @@ static struct fbo_entry *context_create_fbo_entry(IWineD3DDevice *iface)
     return entry;
 }
 
-void context_destroy_fbo_entry(IWineD3DDeviceImpl *This, struct fbo_entry *entry)
+static void context_destroy_fbo_entry(IWineD3DDeviceImpl *This, struct fbo_entry *entry)
 {
     if (entry->id)
     {
@@ -319,6 +322,46 @@ static void context_apply_fbo_state(IWineD3DDevice *iface)
     context_check_fbo_status(iface);
 }
 
+void context_resource_released(IWineD3DDevice *iface, IWineD3DResource *resource, WINED3DRESOURCETYPE type)
+{
+    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+    UINT i;
+
+    switch(type)
+    {
+        case WINED3DRTYPE_SURFACE:
+        {
+            for (i = 0; i < This->numContexts; ++i)
+            {
+                struct fbo_entry *entry, *entry2;
+
+                LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->contexts[i]->fbo_list, struct fbo_entry, entry)
+                {
+                    BOOL destroyed = FALSE;
+                    UINT j;
+
+                    for (j = 0; !destroyed && j < GL_LIMITS(buffers); ++j)
+                    {
+                        if (entry->render_targets[j] == (IWineD3DSurface *)resource)
+                        {
+                            context_destroy_fbo_entry(This, entry);
+                            destroyed = TRUE;
+                        }
+                    }
+
+                    if (!destroyed && entry->depth_stencil == (IWineD3DSurface *)resource)
+                        context_destroy_fbo_entry(This, entry);
+                }
+            }
+
+            break;
+        }
+
+        default:
+            break;
+    }
+}
+
 /*****************************************************************************
  * Context_MarkStateDirty
  *
@@ -403,7 +446,8 @@ static WineD3DContext *AddContextToArray(IWineD3DDeviceImpl *This, HWND win_hand
 /* This function takes care of WineD3D pixel format selection. */
 static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc, WINED3DFORMAT ColorFormat, WINED3DFORMAT DepthStencilFormat, BOOL auxBuffers, int numSamples, BOOL pbuffer, BOOL findCompatible)
 {
-    int iPixelFormat=0, matchtry;
+    int iPixelFormat=0;
+    unsigned int matchtry;
     short redBits, greenBits, blueBits, alphaBits, colorBits;
     short depthBits=0, stencilBits=0;
 
@@ -429,7 +473,6 @@ static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc, WINED3DF
 
     int i = 0;
     int nCfgs = This->adapter->nCfgs;
-    WineD3D_PixelFormat *cfgs = This->adapter->cfgs;
 
     TRACE("ColorFormat=%s, DepthStencilFormat=%s, auxBuffers=%d, numSamples=%d, pbuffer=%d, findCompatible=%d\n",
           debug_d3dformat(ColorFormat), debug_d3dformat(DepthStencilFormat), auxBuffers, numSamples, pbuffer, findCompatible);
@@ -462,64 +505,64 @@ static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc, WINED3DF
     for(matchtry = 0; matchtry < (sizeof(matches) / sizeof(matches[0])) && !iPixelFormat; matchtry++) {
         for(i=0; i<nCfgs; i++) {
             BOOL exactDepthMatch = TRUE;
-            cfgs = &This->adapter->cfgs[i];
+            WineD3D_PixelFormat *cfg = &This->adapter->cfgs[i];
 
             /* For now only accept RGBA formats. Perhaps some day we will
              * allow floating point formats for pbuffers. */
-            if(cfgs->iPixelType != WGL_TYPE_RGBA_ARB)
+            if(cfg->iPixelType != WGL_TYPE_RGBA_ARB)
                 continue;
 
             /* In window mode (!pbuffer) we need a window drawable format and double buffering. */
-            if(!pbuffer && !(cfgs->windowDrawable && cfgs->doubleBuffer))
+            if(!pbuffer && !(cfg->windowDrawable && cfg->doubleBuffer))
                 continue;
 
             /* We like to have aux buffers in backbuffer mode */
-            if(auxBuffers && !cfgs->auxBuffers && matches[matchtry].require_aux)
+            if(auxBuffers && !cfg->auxBuffers && matches[matchtry].require_aux)
                 continue;
 
             /* In pbuffer-mode we need a pbuffer-capable format but we don't want double buffering */
-            if(pbuffer && (!cfgs->pbufferDrawable || cfgs->doubleBuffer))
+            if(pbuffer && (!cfg->pbufferDrawable || cfg->doubleBuffer))
                 continue;
 
             if(matches[matchtry].exact_color) {
-                if(cfgs->redSize != redBits)
+                if(cfg->redSize != redBits)
                     continue;
-                if(cfgs->greenSize != greenBits)
+                if(cfg->greenSize != greenBits)
                     continue;
-                if(cfgs->blueSize != blueBits)
+                if(cfg->blueSize != blueBits)
                     continue;
             } else {
-                if(cfgs->redSize < redBits)
+                if(cfg->redSize < redBits)
                     continue;
-                if(cfgs->greenSize < greenBits)
+                if(cfg->greenSize < greenBits)
                     continue;
-                if(cfgs->blueSize < blueBits)
+                if(cfg->blueSize < blueBits)
                     continue;
             }
             if(matches[matchtry].exact_alpha) {
-                if(cfgs->alphaSize != alphaBits)
+                if(cfg->alphaSize != alphaBits)
                     continue;
             } else {
-                if(cfgs->alphaSize < alphaBits)
+                if(cfg->alphaSize < alphaBits)
                     continue;
             }
 
             /* We try to locate a format which matches our requirements exactly. In case of
              * depth it is no problem to emulate 16-bit using e.g. 24-bit, so accept that. */
-            if(cfgs->depthSize < depthBits)
+            if(cfg->depthSize < depthBits)
                 continue;
-            else if(cfgs->depthSize > depthBits)
+            else if(cfg->depthSize > depthBits)
                 exactDepthMatch = FALSE;
 
             /* In all cases make sure the number of stencil bits matches our requirements
              * even when we don't need stencil because it could affect performance EXCEPT
              * on cards which don't offer depth formats without stencil like the i915 drivers
              * on Linux. */
-            if(stencilBits != cfgs->stencilSize && !(This->adapter->brokenStencil && stencilBits <= cfgs->stencilSize))
+            if(stencilBits != cfg->stencilSize && !(This->adapter->brokenStencil && stencilBits <= cfg->stencilSize))
                 continue;
 
             /* Check multisampling support */
-            if(cfgs->numSamples != numSamples)
+            if(cfg->numSamples != numSamples)
                 continue;
 
             /* When we have passed all the checks then we have found a format which matches our
@@ -530,13 +573,13 @@ static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc, WINED3DF
 
             /* Exit the loop as we have found a format :) */
             if(exactDepthMatch) {
-                iPixelFormat = cfgs->iPixelFormat;
+                iPixelFormat = cfg->iPixelFormat;
                 break;
             } else if(!iPixelFormat) {
                 /* In the end we might end up with a format which doesn't exactly match our depth
                  * requirements. Accept the first format we found because formats with higher iPixelFormat
                  * values tend to have more extended capabilities (e.g. multisampling) which we don't need. */
-                iPixelFormat = cfgs->iPixelFormat;
+                iPixelFormat = cfg->iPixelFormat;
             }
         }
     }
@@ -1014,6 +1057,13 @@ static inline void SetupForBlit(IWineD3DDeviceImpl *This, WineD3DContext *contex
     Context_MarkStateDirty(context, STATE_VSHADER, StateTable);
     Context_MarkStateDirty(context, STATE_PIXELSHADER, StateTable);
 
+    /* Call ENTER_GL() once for all gl calls below. In theory we should not call
+     * helper functions in between gl calls. This function is full of Context_MarkStateDirty
+     * which can safely be called from here, we only lock once instead locking/unlocking
+     * after each GL call.
+     */
+    ENTER_GL();
+
     /* Disable all textures. The caller can then bind a texture it wants to blit
      * from
      */
@@ -1146,6 +1196,7 @@ static inline void SetupForBlit(IWineD3DDeviceImpl *This, WineD3DContext *contex
     glDisable(GL_CLIP_PLANE4); checkGLcall("glDisable(clip plane 4)");
     glDisable(GL_CLIP_PLANE5); checkGLcall("glDisable(clip plane 5)");
     Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_CLIPPING), StateTable);
+    LEAVE_GL();
 
     set_blit_dimension(width, height);
     context->blit_w = width; context->blit_h = height;
@@ -1164,7 +1215,7 @@ static inline void SetupForBlit(IWineD3DDeviceImpl *This, WineD3DContext *contex
  *
  *****************************************************************************/
 static WineD3DContext *findThreadContextForSwapChain(IWineD3DSwapChain *swapchain, DWORD tid) {
-    int i;
+    unsigned int i;
 
     for(i = 0; i < ((IWineD3DSwapChainImpl *) swapchain)->num_contexts; i++) {
         if(((IWineD3DSwapChainImpl *) swapchain)->context[i]->tid == tid) {
@@ -1191,7 +1242,6 @@ static WineD3DContext *findThreadContextForSwapChain(IWineD3DSwapChain *swapchai
  *****************************************************************************/
 static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, DWORD tid) {
     IWineD3DSwapChain *swapchain = NULL;
-    HRESULT hr;
     BOOL readTexture = wined3d_settings.offscreen_rendering_mode != ORM_FBO && This->render_offscreen;
     WineD3DContext *context = This->activeContext;
     BOOL oldRenderOffscreen = This->render_offscreen;
@@ -1213,8 +1263,7 @@ static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurf
         }
     }
 
-    hr = IWineD3DSurface_GetContainer(target, &IID_IWineD3DSwapChain, (void **) &swapchain);
-    if(hr == WINED3D_OK && swapchain) {
+    if (SUCCEEDED(IWineD3DSurface_GetContainer(target, &IID_IWineD3DSwapChain, (void **)&swapchain))) {
         TRACE("Rendering onscreen\n");
 
         context = findThreadContextForSwapChain(swapchain, tid);
@@ -1371,18 +1420,19 @@ static inline WineD3DContext *FindContext(IWineD3DDeviceImpl *This, IWineD3DSurf
 
 static void apply_draw_buffer(IWineD3DDeviceImpl *This, IWineD3DSurface *target, BOOL blit)
 {
-    HRESULT hr;
     IWineD3DSwapChain *swapchain;
 
-    hr = IWineD3DSurface_GetContainer(target, &IID_IWineD3DSwapChain, (void **)&swapchain);
-    if (SUCCEEDED(hr))
+    if (SUCCEEDED(IWineD3DSurface_GetContainer(target, &IID_IWineD3DSwapChain, (void **)&swapchain)))
     {
         IWineD3DSwapChain_Release((IUnknown *)swapchain);
+        ENTER_GL();
         glDrawBuffer(surface_get_gl_buffer(target, swapchain));
         checkGLcall("glDrawBuffers()");
+        LEAVE_GL();
     }
     else
     {
+        ENTER_GL();
         if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
         {
             if (!blit)
@@ -1407,6 +1457,7 @@ static void apply_draw_buffer(IWineD3DDeviceImpl *This, IWineD3DSurface *target,
             glDrawBuffer(This->offscreenBuffer);
             checkGLcall("glDrawBuffer()");
         }
+        LEAVE_GL();
     }
 }
 
@@ -1425,8 +1476,7 @@ static void apply_draw_buffer(IWineD3DDeviceImpl *This, IWineD3DSurface *target,
  *****************************************************************************/
 void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextUsage usage) {
     DWORD                         tid = GetCurrentThreadId();
-    int                           i;
-    DWORD                         dirtyState, idx;
+    DWORD                         i, dirtyState, idx;
     BYTE                          shift;
     WineD3DContext                *context;
     const struct StateEntry       *StateTable = This->StateTable;
@@ -1453,12 +1503,13 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
         else {
             TRACE("Switching gl ctx to %p, hdc=%p ctx=%p\n", context, context->hdc, context->glCtx);
 
-            This->frag_pipe->enable_extension((IWineD3DDevice *) This, FALSE);
             ret = pwglMakeCurrent(context->hdc, context->glCtx);
             if(ret == FALSE) {
                 ERR("Failed to activate the new context\n");
             } else if(!context->last_was_blit) {
                 This->frag_pipe->enable_extension((IWineD3DDevice *) This, TRUE);
+            } else {
+                This->frag_pipe->enable_extension((IWineD3DDevice *) This, FALSE);
             }
         }
         if(This->activeContext->vshader_const_dirty) {
@@ -1473,9 +1524,6 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
         last_device = This;
     }
 
-    /* We only need ENTER_GL for the gl calls made below and for the helper functions which make GL calls */
-    ENTER_GL();
-
     switch (usage) {
         case CTXUSAGE_CLEAR:
         case CTXUSAGE_DRAWPRIM:
@@ -1494,11 +1542,16 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
                     FIXME("Activating for CTXUSAGE_BLIT for an offscreen target with ORM_FBO. This should be avoided.\n");
                     context_bind_fbo((IWineD3DDevice *)This, GL_FRAMEBUFFER_EXT, &context->dst_fbo);
                     context_attach_surface_fbo(This, GL_FRAMEBUFFER_EXT, 0, target);
+
+                    ENTER_GL();
                     GL_EXTCALL(glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0));
                     checkGLcall("glFramebufferRenderbufferEXT");
+                    LEAVE_GL();
                 } else {
+                    ENTER_GL();
                     GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
                     checkGLcall("glFramebufferRenderbufferEXT");
+                    LEAVE_GL();
                 }
                 context->draw_buffer_dirty = TRUE;
             }
@@ -1527,11 +1580,15 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
             /* Blending and clearing should be orthogonal, but tests on the nvidia driver show that disabling
              * blending when clearing improves the clearing performance incredibly.
              */
+            ENTER_GL();
             glDisable(GL_BLEND);
+            LEAVE_GL();
             Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_ALPHABLENDENABLE), StateTable);
 
+            ENTER_GL();
             glEnable(GL_SCISSOR_TEST);
             checkGLcall("glEnable GL_SCISSOR_TEST");
+            LEAVE_GL();
             context->last_was_blit = FALSE;
             Context_MarkStateDirty(context, STATE_RENDER(WINED3DRS_SCISSORTESTENABLE), StateTable);
             Context_MarkStateDirty(context, STATE_SCISSORRECT, StateTable);
@@ -1565,5 +1622,4 @@ void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextU
         default:
             FIXME("Unexpected context usage requested\n");
     }
-    LEAVE_GL();
 }
index d84dcbc..9ccb2d1 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright 2002-2005 Jason Edmeades
  * Copyright 2002-2005 Raphael Junqueira
  * Copyright 2005 Oliver Stieber
- * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 WINE_DEFAULT_DEBUG_CHANNEL(d3d_texture);
 #define GLINFO_LOCATION This->resource.wineD3DDevice->adapter->gl_info
 
-static const GLenum cube_targets[6] = {
-  GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
-  GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
-  GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
-  GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
-  GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
-  GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
-};
-
 /* *******************************************
    IWineD3DCubeTexture IUnknown parts follow
    ******************************************* */
@@ -156,7 +147,7 @@ static void WINAPI IWineD3DCubeTextureImpl_PreLoad(IWineD3DCubeTexture *iface) {
         for (i = 0; i < This->baseTexture.levels; i++) {
             for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z ; j++) {
                 IWineD3DSurface_AddDirtyRect(This->surfaces[j][i], NULL);
-                IWineD3DSurface_SetGlTextureDesc(This->surfaces[j][i], This->baseTexture.textureName, cube_targets[j]);
+                surface_force_reload(This->surfaces[j][i]);
                 IWineD3DSurface_LoadTexture(This->surfaces[j][i], srgb_mode);
             }
         }
@@ -181,7 +172,7 @@ static void WINAPI IWineD3DCubeTextureImpl_UnLoad(IWineD3DCubeTexture *iface) {
     for (i = 0; i < This->baseTexture.levels; i++) {
         for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z ; j++) {
             IWineD3DSurface_UnLoad(This->surfaces[j][i]);
-            IWineD3DSurface_SetGlTextureDesc(This->surfaces[j][i], 0, IWineD3DTexture_GetTextureDimensions(iface));
+            surface_set_texture_name(This->surfaces[j][i], 0);
         }
     }
 
@@ -245,7 +236,7 @@ static HRESULT WINAPI IWineD3DCubeTextureImpl_BindTexture(IWineD3DCubeTexture *i
         UINT i, j;
         for (i = 0; i < This->baseTexture.levels; ++i) {
             for (j = WINED3DCUBEMAP_FACE_POSITIVE_X; j <= WINED3DCUBEMAP_FACE_NEGATIVE_Z; ++j) {
-                IWineD3DSurface_SetGlTextureDesc(This->surfaces[j][i], This->baseTexture.textureName, cube_targets[j]);
+                surface_set_texture_name(This->surfaces[j][i], This->baseTexture.textureName);
             }
         }
     }
@@ -285,8 +276,10 @@ static void WINAPI IWineD3DCubeTextureImpl_Destroy(IWineD3DCubeTexture *iface, D
     for (i = 0; i < This->baseTexture.levels; i++) {
         for (j = 0; j < 6; j++) {
             if (This->surfaces[j][i] != NULL) {
+                IWineD3DSurface *surface = This->surfaces[j][i];
                 /* Clean out the texture name we gave to the surface so that the surface doesn't try and release it */
-                IWineD3DSurface_SetGlTextureDesc(This->surfaces[j][i], 0, 0);
+                surface_set_texture_name(surface, 0);
+                surface_set_texture_target(surface, 0);
                 /* Cleanup the container */
                 IWineD3DSurface_SetContainer(This->surfaces[j][i], 0);
                 D3DCB_DestroySurface(This->surfaces[j][i]);
index 4ca96e6..0cb539b 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright 2003-2004 Raphael Junqueira
  * Copyright 2004 Christian Costa
  * Copyright 2005 Oliver Stieber
- * Copyright 2006-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2006-2008 Stefan Dösinger for CodeWeavers
  * Copyright 2006-2008 Henri Verbeet
  * Copyright 2007 Andrew Riedi
  *
@@ -90,6 +90,7 @@ static void WINAPI IWineD3DDeviceImpl_AddResource(IWineD3DDevice *iface, IWineD3
     object->resource.format          = Format; \
     object->resource.usage           = Usage; \
     object->resource.size            = _size; \
+    object->resource.priority        = 0; \
     list_init(&object->resource.privateData); \
     /* Check that we have enough video ram left */ \
     if (Pool == WINED3DPOOL_DEFAULT) { \
@@ -820,8 +821,6 @@ static HRESULT  WINAPI IWineD3DDeviceImpl_CreateTexture(IWineD3DDevice *iface, U
         object->baseTexture.pow2Matrix[15] = 1.0;
         object->target = GL_TEXTURE_2D;
         object->cond_np2 = TRUE;
-        pow2Width = Width;
-        pow2Height = Height;
         object->baseTexture.minMipLookup = &minMipLookup_noFilter;
     } else if(GL_SUPPORT(ARB_TEXTURE_RECTANGLE) &&
        (Width != pow2Width || Height != pow2Height) &&
@@ -887,6 +886,7 @@ static HRESULT  WINAPI IWineD3DDeviceImpl_CreateTexture(IWineD3DDevice *iface, U
 
         IWineD3DSurface_SetContainer(object->surfaces[i], (IWineD3DBase *)object);
         TRACE("Created surface level %d @ %p\n", i, object->surfaces[i]);
+        surface_set_texture_target(object->surfaces[i], object->target);
         /* calculate the next mipmap level */
         tmpW = max(1, tmpW >> 1);
         tmpH = max(1, tmpH >> 1);
@@ -960,7 +960,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVolumeTexture(IWineD3DDevice *ifa
             WARN("D3DUSAGE_AUTOGENMIPMAP is set, and level count > 1, returning D3DERR_INVALIDCALL\n");
             return WINED3DERR_INVALIDCALL;
         }
-        Levels = 1;
+        object->baseTexture.levels = 1;
     } else if (Levels == 0) {
         object->baseTexture.levels++;
         tmpW = Width;
@@ -1056,7 +1056,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateCubeTexture(IWineD3DDevice *iface
     unsigned int             i, j;
     UINT                     tmpW;
     HRESULT                  hr;
-    unsigned int pow2EdgeLength  = EdgeLength;
+    unsigned int pow2EdgeLength;
     const GlPixelFormatDesc *glDesc;
     getFormatDescEntry(Format, &GLINFO_LOCATION, &glDesc);
 
@@ -1077,19 +1077,25 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateCubeTexture(IWineD3DDevice *iface
 
     TRACE("(%p) Create Cube Texture\n", This);
 
-    /** Non-power2 support **/
-
     /* Find the nearest pow2 match */
     pow2EdgeLength = 1;
     while (pow2EdgeLength < EdgeLength) pow2EdgeLength <<= 1;
 
     object->edgeLength           = EdgeLength;
-    /* TODO: support for native non-power 2 */
-    /* Precalculated scaling for 'faked' non power of two texture coords */
-    object->baseTexture.pow2Matrix[ 0] = ((float)EdgeLength) / ((float)pow2EdgeLength);
-    object->baseTexture.pow2Matrix[ 5] = ((float)EdgeLength) / ((float)pow2EdgeLength);
-    object->baseTexture.pow2Matrix[10] = ((float)EdgeLength) / ((float)pow2EdgeLength);
-    object->baseTexture.pow2Matrix[15] = 1.0;
+
+    if (GL_SUPPORT(ARB_TEXTURE_NON_POWER_OF_TWO)) {
+        /* Precalculated scaling for 'faked' non power of two texture coords */
+        object->baseTexture.pow2Matrix[ 0] = 1.0;
+        object->baseTexture.pow2Matrix[ 5] = 1.0;
+        object->baseTexture.pow2Matrix[10] = 1.0;
+        object->baseTexture.pow2Matrix[15] = 1.0;
+    } else {
+        /* Precalculated scaling for 'faked' non power of two texture coords */
+        object->baseTexture.pow2Matrix[ 0] = ((float)EdgeLength) / ((float)pow2EdgeLength);
+        object->baseTexture.pow2Matrix[ 5] = ((float)EdgeLength) / ((float)pow2EdgeLength);
+        object->baseTexture.pow2Matrix[10] = ((float)EdgeLength) / ((float)pow2EdgeLength);
+        object->baseTexture.pow2Matrix[15] = 1.0;
+    }
 
     if(glDesc->Flags & WINED3DFMT_FLAG_FILTERING) {
         object->baseTexture.minMipLookup = &minMipLookup;
@@ -1115,7 +1121,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateCubeTexture(IWineD3DDevice *iface
 
             return WINED3DERR_INVALIDCALL;
         }
-        Levels = 1;
+        object->baseTexture.levels = 1;
     } else if (Levels == 0) {
         object->baseTexture.levels++;
         tmpW = EdgeLength;
@@ -1132,14 +1138,22 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateCubeTexture(IWineD3DDevice *iface
 
         /* Create the 6 faces */
         for (j = 0; j < 6; j++) {
+            static const GLenum cube_targets[6] = {
+                GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
+                GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
+                GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
+                GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
+                GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
+                GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
+            };
 
             hr=D3DCB_CreateSurface(This->parent, parent, tmpW, tmpW, Format, Usage, Pool,
                                    i /* Level */, j, &object->surfaces[j][i],pSharedHandle);
 
             if(hr!= WINED3D_OK) {
                 /* clean up */
-                int k;
-                int l;
+                unsigned int k;
+                unsigned int l;
                 for (l = 0; l < j; l++) {
                     IWineD3DSurface_Release(object->surfaces[l][i]);
                 }
@@ -1156,6 +1170,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateCubeTexture(IWineD3DDevice *iface
             }
             IWineD3DSurface_SetContainer(object->surfaces[j][i], (IWineD3DBase *)object);
             TRACE("Created surface level %d @ %p,\n", i, object->surfaces[j][i]);
+            surface_set_texture_target(object->surfaces[j][i], cube_targets[j]);
         }
         tmpW = max(1, tmpW >> 1);
     }
@@ -1376,16 +1391,16 @@ static void WINAPI IWineD3DDeviceImpl_RestoreWindow(IWineD3DDevice *iface, HWND
 }
 
 /* example at http://www.fairyengine.com/articles/dxmultiviews.htm */
-static HRESULT WINAPI IWineD3DDeviceImpl_CreateAdditionalSwapChain(IWineD3DDevice* iface, WINED3DPRESENT_PARAMETERS*  pPresentationParameters,                                                                   IWineD3DSwapChain** ppSwapChain,
-                                                            IUnknown* parent,
-                                                            D3DCB_CREATERENDERTARGETFN D3DCB_CreateRenderTarget,
-                                                            D3DCB_CREATEDEPTHSTENCILSURFACEFN D3DCB_CreateDepthStencil,
-                                                            WINED3DSURFTYPE surface_type) {
+static HRESULT WINAPI IWineD3DDeviceImpl_CreateSwapChain(IWineD3DDevice* iface,
+        WINED3DPRESENT_PARAMETERS* pPresentationParameters, IWineD3DSwapChain** ppSwapChain,
+        IUnknown* parent, D3DCB_CREATERENDERTARGETFN D3DCB_CreateRenderTarget,
+        D3DCB_CREATEDEPTHSTENCILSURFACEFN D3DCB_CreateDepthStencil, WINED3DSURFTYPE surface_type)
+{
     IWineD3DDeviceImpl      *This = (IWineD3DDeviceImpl *)iface;
 
     HDC                     hDc;
     IWineD3DSwapChainImpl  *object; /** NOTE: impl ref allowed since this is a create function **/
-    HRESULT                 hr = WINED3D_OK;
+    HRESULT                 hr;
     IUnknown               *bufferParent;
     BOOL                    displaymode_set = FALSE;
     WINED3DDISPLAYMODE      Mode;
@@ -1491,7 +1506,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateAdditionalSwapChain(IWineD3DDevic
                              TRUE /* Lockable */,
                              &object->frontBuffer,
                              NULL /* pShared (always null)*/);
-    if (object->frontBuffer != NULL) {
+    if (SUCCEEDED(hr)) {
         IWineD3DSurface_SetContainer(object->frontBuffer, (IWineD3DBase *)object);
         if(surface_type == SURFACE_OPENGL) {
             IWineD3DSurface_ModifyLocation(object->frontBuffer, SFLAG_INDRAWABLE, TRUE);
@@ -1535,8 +1550,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateAdditionalSwapChain(IWineD3DDevic
     /** FIXME: Handle stencil appropriately via EnableAutoDepthStencil / AutoDepthStencilFormat **/
 
     object->context = HeapAlloc(GetProcessHeap(), 0, sizeof(object->context));
-    if(!object->context)
-        return E_OUTOFMEMORY;
+    if(!object->context) {
+        ERR("Failed to create the context array\n");
+        hr = E_OUTOFMEMORY;
+        goto error;
+    }
     object->num_contexts = 1;
 
     if(surface_type == SURFACE_OPENGL) {
@@ -1555,7 +1573,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateAdditionalSwapChain(IWineD3DDevic
    * Create the back, front and stencil buffers
    *******************/
     if(object->presentParms.BackBufferCount > 0) {
-        int i;
+        UINT i;
 
         object->backBuffer = HeapAlloc(GetProcessHeap(), 0, sizeof(IWineD3DSurface *) * object->presentParms.BackBufferCount);
         if(!object->backBuffer) {
@@ -1576,7 +1594,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateAdditionalSwapChain(IWineD3DDevic
                                     TRUE /* Lockable */,
                                     &object->backBuffer[i],
                                     NULL /* pShared (always null)*/);
-            if(hr == WINED3D_OK && object->backBuffer[i]) {
+            if(SUCCEEDED(hr)) {
                 IWineD3DSurface_SetContainer(object->backBuffer[i], (IWineD3DBase *)object);
             } else {
                 ERR("Cannot create new back buffer\n");
@@ -1602,7 +1620,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateAdditionalSwapChain(IWineD3DDevic
     }
 
     /* Under directX swapchains share the depth stencil, so only create one depth-stencil */
-    if (pPresentationParameters->EnableAutoDepthStencil && hr == WINED3D_OK && surface_type == SURFACE_OPENGL) {
+    if (pPresentationParameters->EnableAutoDepthStencil && surface_type == SURFACE_OPENGL) {
         TRACE("Creating depth stencil buffer\n");
         if (This->auto_depth_stencil_buffer == NULL ) {
             hr = D3DCB_CreateDepthStencil(This->parent,
@@ -1615,22 +1633,19 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateAdditionalSwapChain(IWineD3DDevic
                                     FALSE /* FIXME: Discard */,
                                     &This->auto_depth_stencil_buffer,
                                     NULL /* pShared (always null)*/  );
-            if (This->auto_depth_stencil_buffer != NULL)
+            if (SUCCEEDED(hr)) {
                 IWineD3DSurface_SetContainer(This->auto_depth_stencil_buffer, 0);
+            } else {
+                ERR("Failed to create the auto depth stencil\n");
+                goto error;
+            }
         }
-
-        /** TODO: A check on width, height and multisample types
-        *(since the zbuffer must be at least as large as the render target and have the same multisample parameters)
-         ****************************/
-        object->wantsDepthStencilBuffer = TRUE;
-    } else {
-        object->wantsDepthStencilBuffer = FALSE;
     }
 
     IWineD3DSwapChain_GetGammaRamp((IWineD3DSwapChain *) object, &object->orig_gamma);
 
     TRACE("Created swapchain %p\n", object);
-    TRACE("FrontBuf @ %p, BackBuf @ %p, DepthStencil %d\n",object->frontBuffer, object->backBuffer ? object->backBuffer[0] : NULL, object->wantsDepthStencilBuffer);
+    TRACE("FrontBuf @ %p, BackBuf @ %p, DepthStencil %d\n",object->frontBuffer, object->backBuffer ? object->backBuffer[0] : NULL, pPresentationParameters->EnableAutoDepthStencil);
     return WINED3D_OK;
 
 error:
@@ -1652,7 +1667,7 @@ error:
     }
 
     if (object->backBuffer) {
-        int i;
+        UINT i;
         for(i = 0; i < object->presentParms.BackBufferCount; i++) {
             if(object->backBuffer[i]) {
                 IWineD3DSurface_GetParent(object->backBuffer[i], &bufferParent);
@@ -1665,7 +1680,7 @@ error:
         HeapFree(GetProcessHeap(), 0, object->backBuffer);
         object->backBuffer = NULL;
     }
-    if(object->context[0])
+    if(object->context && object->context[0])
         DestroyContext(This, object->context[0]);
     if(object->frontBuffer) {
         IWineD3DSurface_GetParent(object->frontBuffer, &bufferParent);
@@ -1718,8 +1733,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexDeclaration(IWineD3DDevice*
 
     hr = IWineD3DVertexDeclaration_SetDeclaration((IWineD3DVertexDeclaration *)object, elements, element_count);
     if(FAILED(hr)) {
+        IWineD3DVertexDeclaration_Release((IWineD3DVertexDeclaration *)object);
         *ppVertexDeclaration = NULL;
-        HeapFree(GetProcessHeap(), 0, object);
     }
 
     return hr;
@@ -1777,8 +1792,16 @@ static unsigned int ConvertFvfToDeclaration(IWineD3DDeviceImpl *This, /* For the
     if (has_blend && (num_blends > 0)) {
         if (((fvf & WINED3DFVF_XYZB5) == WINED3DFVF_XYZB2) && (fvf & WINED3DFVF_LASTBETA_D3DCOLOR))
             elements[idx].Type = WINED3DDECLTYPE_D3DCOLOR;
-        else
-            elements[idx].Type = WINED3DDECLTYPE_FLOAT1 + num_blends - 1;
+        else {
+            switch(num_blends) {
+                case 1: elements[idx].Type = WINED3DDECLTYPE_FLOAT1; break;
+                case 2: elements[idx].Type = WINED3DDECLTYPE_FLOAT2; break;
+                case 3: elements[idx].Type = WINED3DDECLTYPE_FLOAT3; break;
+                case 4: elements[idx].Type = WINED3DDECLTYPE_FLOAT4; break;
+                default:
+                    ERR("Unexpected amount of blend values: %u\n", num_blends);
+            }
+        }
         elements[idx].Usage = WINED3DDECLUSAGE_BLENDWEIGHT;
         elements[idx].UsageIndex = 0;
         idx++;
@@ -2054,14 +2077,14 @@ static void create_dummy_textures(IWineD3DDeviceImpl *This) {
     LEAVE_GL();
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_Init3D(IWineD3DDevice *iface, WINED3DPRESENT_PARAMETERS* pPresentationParameters, D3DCB_CREATEADDITIONALSWAPCHAIN D3DCB_CreateAdditionalSwapChain) {
+static HRESULT WINAPI IWineD3DDeviceImpl_Init3D(IWineD3DDevice *iface, WINED3DPRESENT_PARAMETERS* pPresentationParameters, D3DCB_CREATESWAPCHAIN D3DCB_CreateSwapChain) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
     IWineD3DSwapChainImpl *swapchain = NULL;
     HRESULT hr;
     DWORD state;
     unsigned int i;
 
-    TRACE("(%p)->(%p,%p)\n", This, pPresentationParameters, D3DCB_CreateAdditionalSwapChain);
+    TRACE("(%p)->(%p,%p)\n", This, pPresentationParameters, D3DCB_CreateSwapChain);
     if(This->d3d_initialized) return WINED3DERR_INVALIDCALL;
     if(!This->adapter->opengl) return WINED3DERR_INVALIDCALL;
 
@@ -2121,7 +2144,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Init3D(IWineD3DDevice *iface, WINED3DPR
 
     /* Setup the implicit swapchain */
     TRACE("Creating implicit swapchain\n");
-    hr=D3DCB_CreateAdditionalSwapChain(This->parent, pPresentationParameters, (IWineD3DSwapChain **)&swapchain);
+    hr=D3DCB_CreateSwapChain(This->parent, pPresentationParameters, (IWineD3DSwapChain **)&swapchain);
     if (FAILED(hr) || !swapchain) {
         WARN("Failed to create implicit swapchain\n");
         goto err_out;
@@ -2260,14 +2283,14 @@ err_out:
     return hr;
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_InitGDI(IWineD3DDevice *iface, WINED3DPRESENT_PARAMETERS* pPresentationParameters, D3DCB_CREATEADDITIONALSWAPCHAIN D3DCB_CreateAdditionalSwapChain) {
+static HRESULT WINAPI IWineD3DDeviceImpl_InitGDI(IWineD3DDevice *iface, WINED3DPRESENT_PARAMETERS* pPresentationParameters, D3DCB_CREATESWAPCHAIN D3DCB_CreateSwapChain) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
     IWineD3DSwapChainImpl *swapchain = NULL;
     HRESULT hr;
 
     /* Setup the implicit swapchain */
     TRACE("Creating implicit swapchain\n");
-    hr=D3DCB_CreateAdditionalSwapChain(This->parent, pPresentationParameters, (IWineD3DSwapChain **)&swapchain);
+    hr=D3DCB_CreateSwapChain(This->parent, pPresentationParameters, (IWineD3DSwapChain **)&swapchain);
     if (FAILED(hr) || !swapchain) {
         WARN("Failed to create implicit swapchain\n");
         goto err_out;
@@ -2993,7 +3016,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLightEnable(IWineD3DDevice *iface, D
                 IWineD3DDeviceImpl_MarkStateDirty(This, STATE_ACTIVELIGHT(lightInfo->glIndex));
             }
 
-            This->stateBlock->activeLights[lightInfo->glIndex] = NULL;
+            This->updateStateBlock->activeLights[lightInfo->glIndex] = NULL;
             lightInfo->glIndex = -1;
         } else {
             TRACE("Light already disabled, nothing to do\n");
@@ -3008,8 +3031,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetLightEnable(IWineD3DDevice *iface, D
             int i;
             /* Find a free gl light */
             for(i = 0; i < This->maxConcurrentLights; i++) {
-                if(This->stateBlock->activeLights[i] == NULL) {
-                    This->stateBlock->activeLights[i] = lightInfo;
+                if(This->updateStateBlock->activeLights[i] == NULL) {
+                    This->updateStateBlock->activeLights[i] = lightInfo;
                     lightInfo->glIndex = i;
                     break;
                 }
@@ -3600,7 +3623,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetVertexShaderConstantF(
     UINT count) {
 
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    int i;
+    UINT i;
 
     TRACE("(iface %p, srcData %p, start %d, count %d)\n",
             iface, srcData, start, count);
@@ -3640,7 +3663,7 @@ CONST float *srcData,
 UINT count) {
 
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    int i;
+    UINT i;
 
     TRACE("(iface %p, srcData %p, start %d, count %d)\n",
             iface, srcData, start, count);
@@ -4029,7 +4052,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantF(
     UINT count) {
 
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    int i;
+    UINT i;
 
     TRACE("(iface %p, srcData %p, start %d, count %d)\n",
             iface, srcData, start, count);
@@ -4069,7 +4092,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetPixelShaderConstantF_DirtyConst(
     UINT count) {
 
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    int i;
+    UINT i;
 
     TRACE("(iface %p, srcData %p, start %d, count %d)\n",
             iface, srcData, start, count);
@@ -4125,7 +4148,7 @@ process_vertices_strided(IWineD3DDeviceImpl *This, DWORD dwDestIndex, DWORD dwCo
     WINED3DVIEWPORT vp;
     WINED3DMATRIX mat, proj_mat, view_mat, world_mat;
     BOOL doClip;
-    int numTextures;
+    DWORD numTextures;
 
     if (lpStrideData->u.s.normal.lpData) {
         WARN(" lighting state not saved yet... Some strange stuff may happen !\n");
@@ -5164,8 +5187,7 @@ HRESULT IWineD3DDeviceImpl_ClearSurface(IWineD3DDeviceImpl *This,  IWineD3DSurfa
 
     LEAVE_GL();
 
-    IWineD3DSurface_GetContainer( (IWineD3DSurface *) target, &IID_IWineD3DSwapChain, (void **)&swapchain);
-    if (swapchain) {
+    if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *)target, &IID_IWineD3DSwapChain, (void **)&swapchain))) {
         if (target == (IWineD3DSurfaceImpl*) swapchain->frontBuffer) {
             glFlush();
         }
@@ -5866,11 +5888,11 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface,
 
     ActivateContext(This, This->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
 
-    ENTER_GL();
-
     if (GL_SUPPORT(ARB_MULTITEXTURE)) {
+        ENTER_GL();
         GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB));
         checkGLcall("glActiveTextureARB");
+        LEAVE_GL();
     }
 
     /* Make sure the surface is loaded and up to date */
@@ -5899,17 +5921,9 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface,
     if(pSourceRect != NULL && pSourceRect->top != 0){
        offset +=  pSourceRect->top * srcSurfaceWidth * pSrcSurface->bytesPerPixel;
     }
-    TRACE("(%p) glTexSubImage2D, Level %d, left %d, top %d, width %d, height %d , ftm %d, type %d, memory %p\n"
-    ,This
-    ,glDescription->level
-    ,destLeft
-    ,destTop
-    ,srcWidth
-    ,srcHeight
-    ,glDescription->glFormat
-    ,glDescription->glType
-    ,IWineD3DSurface_GetData(pSourceSurface)
-    );
+    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, glDescription->glFormat,
+            glDescription->glType, IWineD3DSurface_GetData(pSourceSurface), offset);
 
     /* Sanity check */
     if (IWineD3DSurface_GetData(pSourceSurface) == NULL) {
@@ -5918,6 +5932,8 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface,
         FIXME("Surfaces has no allocated memory, but should be an in memory only surface\n");
     }
 
+    ENTER_GL();
+
     /* TODO: Cube and volume support */
     if(rowoffset != 0){
         /* not a whole row so we have to do it a line at a time */
@@ -5942,6 +5958,7 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface,
         }
 
     } else { /* Full width, so just write out the whole texture */
+        const unsigned char* data = ((const unsigned char *)IWineD3DSurface_GetData(pSourceSurface)) + offset;
 
         if (WINED3DFMT_DXT1 == destFormat ||
             WINED3DFMT_DXT2 == destFormat ||
@@ -5955,14 +5972,8 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface,
                 } if (destFormat != srcFormat) {
                     FIXME("Updating mixed format compressed texture is not curretly support\n");
                 } else {
-                    GL_EXTCALL(glCompressedTexImage2DARB)(glDescription->target,
-                                                        glDescription->level,
-                                                        glDescription->glFormatInternal,
-                                                        srcWidth,
-                                                        srcHeight,
-                                                        0,
-                                                        destSize,
-                                                        IWineD3DSurface_GetData(pSourceSurface));
+                    GL_EXTCALL(glCompressedTexImage2DARB(glDescription->target, glDescription->level,
+                            glDescription->glFormatInternal, srcWidth, srcHeight, 0, destSize, data));
                 }
             } else {
                 FIXME("Attempting to update a DXT compressed texture without hardware support\n");
@@ -5970,16 +5981,8 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_UpdateSurface(IWineD3DDevice *iface,
 
 
         } else {
-            glTexSubImage2D(glDescription->target
-                    ,glDescription->level
-                    ,destLeft
-                    ,destTop
-                    ,srcWidth
-                    ,srcHeight
-                    ,glDescription->glFormat
-                    ,glDescription->glType
-                    ,IWineD3DSurface_GetData(pSourceSurface)
-                );
+            glTexSubImage2D(glDescription->target, glDescription->level, destLeft, destTop,
+                    srcWidth, srcHeight, glDescription->glFormat, glDescription->glType, data);
         }
      }
     checkGLcall("glTexSubImage2D");
@@ -6653,9 +6656,14 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetDepthStencilSurface(IWineD3DDevice *
          ******************************************************/
 
         if (This->stencilBufferTarget) {
-            ActivateContext(This, This->render_targets[0], CTXUSAGE_RESOURCELOAD);
-            surface_load_ds_location(This->stencilBufferTarget, SFLAG_DS_OFFSCREEN);
-            surface_modify_ds_location(This->stencilBufferTarget, SFLAG_DS_OFFSCREEN);
+            if (((IWineD3DSwapChainImpl *)This->swapchains[0])->presentParms.Flags & WINED3DPRESENTFLAG_DISCARD_DEPTHSTENCIL
+                    || ((IWineD3DSurfaceImpl *)This->stencilBufferTarget)->Flags & SFLAG_DISCARD) {
+                surface_modify_ds_location(This->stencilBufferTarget, SFLAG_DS_DISCARDED);
+            } else {
+                ActivateContext(This, This->render_targets[0], CTXUSAGE_RESOURCELOAD);
+                surface_load_ds_location(This->stencilBufferTarget, SFLAG_DS_OFFSCREEN);
+                surface_modify_ds_location(This->stencilBufferTarget, SFLAG_DS_OFFSCREEN);
+            }
         }
 
         tmp = This->stencilBufferTarget;
@@ -7017,10 +7025,13 @@ void delete_opengl_contexts(IWineD3DDevice *iface, IWineD3DSwapChain *swapchain_
         This->depth_blt_rb_w = 0;
         This->depth_blt_rb_h = 0;
     }
+    LEAVE_GL();
+
     This->blitter->free_private(iface);
     This->frag_pipe->free_private(iface);
     This->shader_backend->shader_free_private(iface);
 
+    ENTER_GL();
     for (i = 0; i < GL_LIMITS(textures); i++) {
         /* Textures are recreated below */
         glDeleteTextures(1, &This->dummyTextureName[i]);
@@ -7176,7 +7187,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_Reset(IWineD3DDevice* iface, WINED3DPRE
         pPresentationParameters->BackBufferHeight != swapchain->presentParms.BackBufferHeight))
     {
         WINED3DVIEWPORT vp;
-        int i;
+        UINT i;
 
         vp.X = 0;
         vp.Y = 0;
@@ -7325,10 +7336,14 @@ static void WINAPI IWineD3DDeviceImpl_RemoveResource(IWineD3DDevice *iface, IWin
 
 static void WINAPI IWineD3DDeviceImpl_ResourceReleased(IWineD3DDevice *iface, IWineD3DResource *resource){
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *) iface;
+    WINED3DRESOURCETYPE type = IWineD3DResource_GetType(resource);
     int counter;
 
     TRACE("(%p) : resource %p\n", This, resource);
-    switch(IWineD3DResource_GetType(resource)){
+
+    context_resource_released(iface, resource, type);
+
+    switch (type) {
         /* TODO: check front and back buffers, rendertargets etc..  possibly swapchains? */
         case WINED3DRTYPE_SURFACE: {
             unsigned int i;
@@ -7374,24 +7389,6 @@ static void WINAPI IWineD3DDeviceImpl_ResourceReleased(IWineD3DDevice *iface, IW
                 if (This->stencilBufferTarget == (IWineD3DSurface *)resource) {
                     This->stencilBufferTarget = NULL;
                 }
-
-                for (i = 0; i < This->numContexts; ++i) {
-                    struct fbo_entry *entry, *entry2;
-                    int j;
-
-                    LIST_FOR_EACH_ENTRY_SAFE(entry, entry2, &This->contexts[i]->fbo_list, struct fbo_entry, entry) {
-                        BOOL destroyed = FALSE;
-                        for (j = 0; !destroyed && j < GL_LIMITS(buffers); ++j) {
-                            if (entry->render_targets[j] == (IWineD3DSurface *)resource) {
-                                context_destroy_fbo_entry(This, entry);
-                                destroyed = TRUE;
-                            }
-                        }
-                        if (!destroyed && entry->depth_stencil == (IWineD3DSurface *)resource) {
-                            context_destroy_fbo_entry(This, entry);
-                        }
-                    }
-                }
             }
 
             break;
@@ -7508,7 +7505,7 @@ const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl =
     IWineD3DDeviceImpl_CreateVolume,
     IWineD3DDeviceImpl_CreateCubeTexture,
     IWineD3DDeviceImpl_CreateQuery,
-    IWineD3DDeviceImpl_CreateAdditionalSwapChain,
+    IWineD3DDeviceImpl_CreateSwapChain,
     IWineD3DDeviceImpl_CreateVertexDeclaration,
     IWineD3DDeviceImpl_CreateVertexDeclarationFromFVF,
     IWineD3DDeviceImpl_CreateVertexShader,
@@ -7653,7 +7650,7 @@ const IWineD3DDeviceVtbl IWineD3DDevice_DirtyConst_Vtbl =
     IWineD3DDeviceImpl_CreateVolume,
     IWineD3DDeviceImpl_CreateCubeTexture,
     IWineD3DDeviceImpl_CreateQuery,
-    IWineD3DDeviceImpl_CreateAdditionalSwapChain,
+    IWineD3DDeviceImpl_CreateSwapChain,
     IWineD3DDeviceImpl_CreateVertexDeclaration,
     IWineD3DDeviceImpl_CreateVertexDeclarationFromFVF,
     IWineD3DDeviceImpl_CreateVertexShader,
index 4e3249e..4a1846a 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright 2003-2004 Raphael Junqueira
  * Copyright 2004 Christian Costa
  * Copyright 2005 Oliver Stieber
- * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -56,7 +56,6 @@ static const struct {
     {"GL_ATI_separate_stencil",             ATI_SEPARATE_STENCIL,           0                           },
     {"GL_ATI_texture_env_combine3",         ATI_TEXTURE_ENV_COMBINE3,       0                           },
     {"GL_ATI_texture_mirror_once",          ATI_TEXTURE_MIRROR_ONCE,        0                           },
-    {"GL_ATI_envmap_bumpmap",               ATI_ENVMAP_BUMPMAP,             0                           },
     {"GL_ATI_fragment_shader",              ATI_FRAGMENT_SHADER,            0                           },
     {"GL_ATI_texture_compression_3dc",      ATI_TEXTURE_COMPRESSION_3DC,    0                           },
 
@@ -96,6 +95,7 @@ static const struct {
     {"GL_EXT_blend_func_separate",          EXT_BLEND_FUNC_SEPARATE,        0                           },
     {"GL_EXT_fog_coord",                    EXT_FOG_COORD,                  0                           },
     {"GL_EXT_framebuffer_blit",             EXT_FRAMEBUFFER_BLIT,           0                           },
+    {"GL_EXT_framebuffer_multisample",      EXT_FRAMEBUFFER_MULTISAMPLE,    0                           },
     {"GL_EXT_framebuffer_object",           EXT_FRAMEBUFFER_OBJECT,         0                           },
     {"GL_EXT_paletted_texture",             EXT_PALETTED_TEXTURE,           0                           },
     {"GL_EXT_point_parameters",             EXT_POINT_PARAMETERS,           0                           },
@@ -176,7 +176,8 @@ glAttribFunc position_funcs[WINED3DDECLTYPE_UNUSED];
 glAttribFunc diffuse_funcs[WINED3DDECLTYPE_UNUSED];
 glAttribFunc specular_funcs[WINED3DDECLTYPE_UNUSED];
 glAttribFunc normal_funcs[WINED3DDECLTYPE_UNUSED];
-glTexAttribFunc texcoord_funcs[WINED3DDECLTYPE_UNUSED];
+glMultiTexCoordFunc multi_texcoord_funcs[WINED3DDECLTYPE_UNUSED];
+glAttribFunc texcoord_funcs[WINED3DDECLTYPE_UNUSED];
 
 /**
  * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created,
@@ -836,10 +837,6 @@ BOOL IWineD3DImpl_FillGLCaps(WineD3D_GL_Info *gl_info) {
             gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
         }
         if (gl_info->supported[NV_TEXTURE_SHADER2]) {
-            /* GL_ATI_envmap_bumpmap won't play nice with texture shaders, so disable it
-             * Won't occur in any real world situation though
-             */
-            gl_info->supported[ATI_ENVMAP_BUMPMAP] = FALSE;
             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
@@ -2005,7 +2002,6 @@ static BOOL CheckBumpMapCapability(UINT Adapter, WINED3DDEVTYPE DeviceType, WINE
 static BOOL CheckDepthStencilCapability(UINT Adapter, WINED3DFORMAT DisplayFormat, WINED3DFORMAT DepthStencilFormat)
 {
     int it=0;
-    WineD3D_PixelFormat *cfgs = Adapters[Adapter].cfgs;
     const GlPixelFormatDesc *glDesc;
     const StaticPixelFormatDesc *desc = getFormatDescEntry(DepthStencilFormat, &GLINFO_LOCATION, &glDesc);
 
@@ -2018,10 +2014,10 @@ static BOOL CheckDepthStencilCapability(UINT Adapter, WINED3DFORMAT DisplayForma
         return FALSE;
 
     /* Walk through all WGL pixel formats to find a match */
-    cfgs = Adapters[Adapter].cfgs;
     for (it = 0; it < Adapters[Adapter].nCfgs; ++it) {
-        if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&cfgs[it], DisplayFormat)) {
-            if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&cfgs[it], DepthStencilFormat)) {
+        WineD3D_PixelFormat *cfg = &Adapters[Adapter].cfgs[it];
+        if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(cfg, DisplayFormat)) {
+            if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(cfg, DepthStencilFormat)) {
                 return TRUE;
             }
         }
@@ -2915,7 +2911,7 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapt
             break;
 
             case WINED3DFMT_V8U8:
-            if(!GL_SUPPORT(NV_TEXTURE_SHADER) || !GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
+            if(!GL_SUPPORT(NV_TEXTURE_SHADER)) {
                 TRACE_(d3d_caps)("[FAILED] - No converted formats on volumes\n");
                 return WINED3DERR_NOTAVAILABLE;
             }
@@ -3067,7 +3063,11 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
     if(GL_SUPPORT(SGIS_GENERATE_MIPMAP)) {
         pCaps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
     }
-    pCaps->Caps3                   = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD;
+
+    pCaps->Caps3                   = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
+                                     WINED3DCAPS3_COPY_TO_VIDMEM                   |
+                                     WINED3DCAPS3_COPY_TO_SYSTEMMEM;
+
     pCaps->PresentationIntervals   = WINED3DPRESENT_INTERVAL_IMMEDIATE  |
                                      WINED3DPRESENT_INTERVAL_ONE;
 
@@ -3969,6 +3969,11 @@ static void WINE_GLAPI invalid_func(void *data) {
     DebugBreak();
 }
 
+static void WINE_GLAPI invalid_texcoord_func(GLenum unit, void * data) {
+    ERR("Invalid texcoord function called\n");
+    DebugBreak();
+}
+
 #define GLINFO_LOCATION (Adapters[0].gl_info)
 
 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
@@ -4099,6 +4104,54 @@ void fillGLAttribFuncs(WineD3D_GL_Info *gl_info) {
     normal_funcs[WINED3DDECLTYPE_DEC3N]          = (void *) invalid_func;
     normal_funcs[WINED3DDECLTYPE_FLOAT16_2]      = (void *) invalid_func;
     normal_funcs[WINED3DDECLTYPE_FLOAT16_4]      = (void *) invalid_func;
+
+    multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT1]    = (void *) GL_EXTCALL(glMultiTexCoord1fvARB);
+    multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT2]    = (void *) GL_EXTCALL(glMultiTexCoord2fvARB);
+    multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT3]    = (void *) GL_EXTCALL(glMultiTexCoord3fvARB);
+    multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT4]    = (void *) GL_EXTCALL(glMultiTexCoord4fvARB);
+    multi_texcoord_funcs[WINED3DDECLTYPE_D3DCOLOR]  = (void *) invalid_texcoord_func;
+    multi_texcoord_funcs[WINED3DDECLTYPE_UBYTE4]    = (void *) invalid_texcoord_func;
+    multi_texcoord_funcs[WINED3DDECLTYPE_SHORT2]    = (void *) GL_EXTCALL(glMultiTexCoord2svARB);
+    multi_texcoord_funcs[WINED3DDECLTYPE_SHORT4]    = (void *) GL_EXTCALL(glMultiTexCoord4svARB);
+    multi_texcoord_funcs[WINED3DDECLTYPE_UBYTE4N]   = (void *) invalid_texcoord_func;
+    multi_texcoord_funcs[WINED3DDECLTYPE_SHORT2N]   = (void *) invalid_texcoord_func;
+    multi_texcoord_funcs[WINED3DDECLTYPE_SHORT4N]   = (void *) invalid_texcoord_func;
+    multi_texcoord_funcs[WINED3DDECLTYPE_USHORT2N]  = (void *) invalid_texcoord_func;
+    multi_texcoord_funcs[WINED3DDECLTYPE_USHORT4N]  = (void *) invalid_texcoord_func;
+    multi_texcoord_funcs[WINED3DDECLTYPE_UDEC3]     = (void *) invalid_texcoord_func;
+    multi_texcoord_funcs[WINED3DDECLTYPE_DEC3N]     = (void *) invalid_texcoord_func;
+    if (GL_SUPPORT(NV_HALF_FLOAT))
+    {
+        multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) GL_EXTCALL(glMultiTexCoord2hvNV);
+        multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) GL_EXTCALL(glMultiTexCoord4hvNV);
+    } else {
+        multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT16_2] = (void *) invalid_texcoord_func;
+        multi_texcoord_funcs[WINED3DDECLTYPE_FLOAT16_4] = (void *) invalid_texcoord_func;
+    }
+
+    texcoord_funcs[WINED3DDECLTYPE_FLOAT1]      = (void *) glTexCoord1fv;
+    texcoord_funcs[WINED3DDECLTYPE_FLOAT2]      = (void *) glTexCoord2fv;
+    texcoord_funcs[WINED3DDECLTYPE_FLOAT3]      = (void *) glTexCoord3fv;
+    texcoord_funcs[WINED3DDECLTYPE_FLOAT4]      = (void *) glTexCoord4fv;
+    texcoord_funcs[WINED3DDECLTYPE_D3DCOLOR]    = (void *) invalid_func;
+    texcoord_funcs[WINED3DDECLTYPE_UBYTE4]      = (void *) invalid_func;
+    texcoord_funcs[WINED3DDECLTYPE_SHORT2]      = (void *) glTexCoord2sv;
+    texcoord_funcs[WINED3DDECLTYPE_SHORT4]      = (void *) glTexCoord4sv;
+    texcoord_funcs[WINED3DDECLTYPE_UBYTE4N]     = (void *) invalid_func;
+    texcoord_funcs[WINED3DDECLTYPE_SHORT2N]     = (void *) invalid_func;
+    texcoord_funcs[WINED3DDECLTYPE_SHORT4N]     = (void *) invalid_func;
+    texcoord_funcs[WINED3DDECLTYPE_USHORT2N]    = (void *) invalid_func;
+    texcoord_funcs[WINED3DDECLTYPE_USHORT4N]    = (void *) invalid_func;
+    texcoord_funcs[WINED3DDECLTYPE_UDEC3]       = (void *) invalid_func;
+    texcoord_funcs[WINED3DDECLTYPE_DEC3N]       = (void *) invalid_func;
+    if (GL_SUPPORT(NV_HALF_FLOAT))
+    {
+        texcoord_funcs[WINED3DDECLTYPE_FLOAT16_2]   = (void *) GL_EXTCALL(glTexCoord2hvNV);
+        texcoord_funcs[WINED3DDECLTYPE_FLOAT16_4]   = (void *) GL_EXTCALL(glTexCoord4hvNV);
+    } else {
+        texcoord_funcs[WINED3DDECLTYPE_FLOAT16_2]   = (void *) invalid_func;
+        texcoord_funcs[WINED3DDECLTYPE_FLOAT16_4]   = (void *) invalid_func;
+    }
 }
 
 #define PUSH1(att)        attribs[nAttribs++] = (att);
index 37cbe19..545bad1 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright 2004 Christian Costa
  * Copyright 2005 Oliver Stieber
  * Copyright 2006, 2008 Henri Verbeet
- * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -219,17 +219,22 @@ void primitiveDeclarationConvertToStridedData(
             stride_used = fixed_get_input(element->Usage, element->UsageIndex, &idx);
 
         if (stride_used) {
-            TRACE("Loaded %s array %u [usage=%s, usage_idx=%u, "
+            TRACE("Load %s array %u [usage=%s, usage_idx=%u, "
                     "stream=%u, offset=%u, stride=%u, type=%s, VBO=%u]\n",
                     useVertexShaderFunction? "shader": "fixed function", idx,
                     debug_d3ddeclusage(element->Usage), element->UsageIndex,
                     element->Stream, element->Offset, stride, debug_d3ddecltype(element->Type), streamVBO);
 
-            strided->u.input[idx].lpData = data;
-            strided->u.input[idx].dwType = element->Type;
-            strided->u.input[idx].dwStride = stride;
-            strided->u.input[idx].VBO = streamVBO;
-            strided->u.input[idx].streamNo = element->Stream;
+            if (!useVertexShaderFunction && !vertexDeclaration->ffp_valid[i]) {
+                WARN("Skipping unsupported fixed function element of type %s and usage %s\n",
+                    debug_d3ddecltype(element->Type), debug_d3ddeclusage(element->Usage));
+            } else {
+                strided->u.input[idx].lpData = data;
+                strided->u.input[idx].dwType = element->Type;
+                strided->u.input[idx].dwStride = stride;
+                strided->u.input[idx].VBO = streamVBO;
+                strided->u.input[idx].streamNo = element->Stream;
+            }
         }
     }
     /* Now call PreLoad on all the vertex buffers. In the very rare case
@@ -289,8 +294,6 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData
     const WORD                *pIdxBufS     = NULL;
     const DWORD               *pIdxBufL     = NULL;
     LONG                       vx_index;
-    DWORD diffuseColor = 0xFFFFFFFF;       /* Diffuse Color              */
-    DWORD specularColor = 0;               /* Specular Color             */
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     UINT *streamOffset = This->stateBlock->streamOffset;
     long                      SkipnStrides = startVertex + This->stateBlock->loadBaseVertexIndex;
@@ -313,6 +316,9 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData
 
         if (idxSize == 2) pIdxBufS = (const WORD *) idxData;
         else pIdxBufL = (const DWORD *) idxData;
+    } else if (idxData) {
+        ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
+        return;
     }
 
     /* Adding the stream offset once is cheaper than doing it every iteration. Do not modify the strided data, it is a pointer
@@ -338,20 +344,7 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData
         position = sd->u.s.position.lpData + streamOffset[sd->u.s.position.streamNo];
     }
 
-    /* The texture coordinate types are not so easy to map into a common function signature - we're
-     * not using the vector functions here
-     */
     if(FIXME_ON(d3d_draw)) {
-        for (textureNo = 0; textureNo < GL_LIMITS(textures); ++textureNo) {
-            DWORD type = sd->u.s.texCoords[textureNo].dwType;
-            if (sd->u.s.texCoords[textureNo].lpData &&
-                type != WINED3DDECLTYPE_FLOAT1 &&
-                type != WINED3DDECLTYPE_FLOAT2 &&
-                type != WINED3DDECLTYPE_FLOAT3 &&
-                type != WINED3DDECLTYPE_FLOAT4) {
-                FIXME("Implement fixed function texture coordinates from %s\n", debug_d3ddecltype(type));
-            }
-        }
         if(specular && This->stateBlock->renderState[WINED3DRS_FOGENABLE] &&
            (This->stateBlock->renderState[WINED3DRS_FOGVERTEXMODE] == WINED3DFOG_NONE || sd->u.s.position_transformed )&&
            This->stateBlock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) {
@@ -387,10 +380,6 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData
 
     /* For each primitive */
     for (vx_index = 0; vx_index < NumVertexes; ++vx_index) {
-
-        /* Initialize diffuse color */
-        diffuseColor = 0xFFFFFFFF;
-
         /* Blending data and Point sizes are not supported by this function. They are not supported by the fixed
          * function pipeline at all. A Fixme for them is printed after decoding the vertex declaration
          */
@@ -418,11 +407,9 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData
 
             /* Query tex coords */
             if (This->stateBlock->textures[textureNo] != NULL || pixelShader) {
-
                 int    coordIdx = This->stateBlock->textureState[textureNo][WINED3DTSS_TEXCOORDINDEX];
                 int texture_idx = This->texUnitMap[textureNo];
-                float *ptrToCoords = NULL;
-                float  s = 0.0, t = 0.0, r = 0.0, q = 0.0;
+                void *ptrToCoords;
 
                 if (coordIdx > 7) {
                     VTRACE(("tex: %d - Skip tex coords, as being system generated\n", textureNo));
@@ -432,7 +419,8 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData
                     continue;
                 }
 
-                ptrToCoords = (float *)(texCoords[coordIdx] + (SkipnStrides * sd->u.s.texCoords[coordIdx].dwStride));
+                if (texture_idx == -1) continue;
+
                 if (texCoords[coordIdx] == NULL) {
                     TRACE("tex: %d - Skipping tex coords, as no data supplied\n", textureNo);
                     if (GL_SUPPORT(ARB_MULTITEXTURE)) {
@@ -441,56 +429,13 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData
                         glTexCoord4f(0, 0, 0, 1);
                     }
                     continue;
-                } else {
-                    int coordsToUse = sd->u.s.texCoords[coordIdx].dwType + 1; /* 0 == WINED3DDECLTYPE_FLOAT1 etc */
-
-                    if (texture_idx == -1) continue;
-
-                    /* The coords to supply depend completely on the fvf / vertex shader */
-                    switch (coordsToUse) {
-                    case 4: q = ptrToCoords[3]; /* drop through */
-                    case 3: r = ptrToCoords[2]; /* drop through */
-                    case 2: t = ptrToCoords[1]; /* drop through */
-                    case 1: s = ptrToCoords[0];
-                    }
-
-                    switch (coordsToUse) {   /* Supply the provided texture coords */
-                    case WINED3DTTFF_COUNT1:
-                        VTRACE(("tex:%d, s=%f\n", textureNo, s));
-                        if (GL_SUPPORT(ARB_MULTITEXTURE)) {
-                            GL_EXTCALL(glMultiTexCoord1fARB(GL_TEXTURE0_ARB + texture_idx, s));
-                        } else {
-                            glTexCoord1f(s);
-                        }
-                        break;
-                    case WINED3DTTFF_COUNT2:
-                        VTRACE(("tex:%d, s=%f, t=%f\n", textureNo, s, t));
-                        if (GL_SUPPORT(ARB_MULTITEXTURE)) {
-                            GL_EXTCALL(glMultiTexCoord2fARB(GL_TEXTURE0_ARB + texture_idx, s, t));
-                        } else {
-                            glTexCoord2f(s, t);
-                        }
-                        break;
-                    case WINED3DTTFF_COUNT3:
-                        VTRACE(("tex:%d, s=%f, t=%f, r=%f\n", textureNo, s, t, r));
-                        if (GL_SUPPORT(ARB_MULTITEXTURE)) {
-                            GL_EXTCALL(glMultiTexCoord3fARB(GL_TEXTURE0_ARB + texture_idx, s, t, r));
-                        } else {
-                            glTexCoord3f(s, t, r);
-                        }
-                        break;
-                    case WINED3DTTFF_COUNT4:
-                        VTRACE(("tex:%d, s=%f, t=%f, r=%f, q=%f\n", textureNo, s, t, r, q));
-                        if (GL_SUPPORT(ARB_MULTITEXTURE)) {
-                            GL_EXTCALL(glMultiTexCoord4fARB(GL_TEXTURE0_ARB + texture_idx, s, t, r, q));
-                        } else {
-                            glTexCoord4f(s, t, r, q);
-                        }
-                        break;
-                    default:
-                        FIXME("Should not get here as coordsToUse is two bits only (%x)!\n", coordsToUse);
-                    }
                 }
+
+                ptrToCoords = texCoords[coordIdx] + (SkipnStrides * sd->u.s.texCoords[coordIdx].dwStride);
+                if (GL_SUPPORT(ARB_MULTITEXTURE))
+                    multi_texcoord_funcs[sd->u.s.texCoords[coordIdx].dwType](GL_TEXTURE0_ARB + texture_idx, ptrToCoords);
+                else
+                    texcoord_funcs[sd->u.s.texCoords[coordIdx].dwType](ptrToCoords);
             }
         } /* End of textures */
 
@@ -500,10 +445,10 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData
 
             diffuse_funcs[sd->u.s.diffuse.dwType]((void *) ptrToCoords);
             if(This->activeContext->num_untracked_materials) {
+                DWORD diffuseColor = ptrToCoords[0];
                 unsigned char i;
                 float color[4];
 
-                diffuseColor = ptrToCoords[0];
                 color[0] = D3DCOLOR_B_R(diffuseColor) / 255.0;
                 color[1] = D3DCOLOR_B_G(diffuseColor) / 255.0;
                 color[2] = D3DCOLOR_B_B(diffuseColor) / 255.0;
@@ -524,7 +469,7 @@ static void drawStridedSlow(IWineD3DDevice *iface, WineDirect3DVertexStridedData
               (This->stateBlock->renderState[WINED3DRS_FOGVERTEXMODE] == WINED3DFOG_NONE || sd->u.s.position.dwType == WINED3DDECLTYPE_FLOAT4 )&&
               This->stateBlock->renderState[WINED3DRS_FOGTABLEMODE] == WINED3DFOG_NONE) {
                 if(GL_SUPPORT(EXT_FOG_COORD)) {
-                    specularColor = ptrToCoords[0];
+                    DWORD specularColor = ptrToCoords[0];
                     GL_EXTCALL(glFogCoordfEXT(specularColor >> 24));
                 } else {
                     static BOOL warned = FALSE;
@@ -674,6 +619,9 @@ static void drawStridedSlowVs(IWineD3DDevice *iface, WineDirect3DVertexStridedDa
 
         if (idxSize == 2) pIdxBufS = (const WORD *) idxData;
         else pIdxBufL = (const DWORD *) idxData;
+    } else if (idxData) {
+        ERR("non-NULL idxData with 0 idxSize, this should never happen\n");
+        return;
     }
 
     /* Start drawing in GL */
@@ -708,44 +656,6 @@ static void drawStridedSlowVs(IWineD3DDevice *iface, WineDirect3DVertexStridedDa
     glEnd();
 }
 
-void depth_blt(IWineD3DDevice *iface, GLuint texture, GLsizei w, GLsizei h) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    GLint old_binding = 0;
-
-    glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT);
-
-    glDisable(GL_CULL_FACE);
-    glEnable(GL_BLEND);
-    glDisable(GL_ALPHA_TEST);
-    glDisable(GL_SCISSOR_TEST);
-    glDisable(GL_STENCIL_TEST);
-    glEnable(GL_DEPTH_TEST);
-    glDepthFunc(GL_ALWAYS);
-    glDepthMask(GL_TRUE);
-    glBlendFunc(GL_ZERO, GL_ONE);
-    glViewport(0, 0, w, h);
-
-    GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB));
-    glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
-    glBindTexture(GL_TEXTURE_2D, texture);
-    glEnable(GL_TEXTURE_2D);
-
-    This->shader_backend->shader_select_depth_blt(iface);
-
-    glBegin(GL_TRIANGLE_STRIP);
-    glVertex2f(-1.0f, -1.0f);
-    glVertex2f(1.0f, -1.0f);
-    glVertex2f(-1.0f, 1.0f);
-    glVertex2f(1.0f, 1.0f);
-    glEnd();
-
-    glBindTexture(GL_TEXTURE_2D, old_binding);
-
-    glPopAttrib();
-
-    This->shader_backend->shader_deselect_depth_blt(iface);
-}
-
 static inline void drawStridedInstanced(IWineD3DDevice *iface, WineDirect3DVertexStridedData *sd, UINT numberOfVertices,
                                  GLenum glPrimitiveType, const void *idxData, short idxSize, ULONG minIndex,
                                  ULONG startIdx, ULONG startVertex) {
index 3ce8188..bb9a871 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2006 Jason Green 
  * Copyright 2006-2007 Henri Verbeet
- * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -57,7 +57,7 @@ typedef struct {
 struct shader_glsl_priv {
     struct hash_table_t *glsl_program_lookup;
     struct glsl_shader_prog_link *glsl_program;
-    GLhandleARB             depth_blt_glsl_program_id;
+    GLhandleARB depth_blt_program[tex_type_count];
 };
 
 /* Struct to maintain data about a linked GLSL program */
@@ -1219,6 +1219,7 @@ static void shader_glsl_get_sample_function(DWORD sampler_type, BOOL projected,
             break;
         default:
             sample_function->name = "";
+            sample_function->coord_mask = 0;
             FIXME("Unrecognized sampler type: %#x;\n", sampler_type);
             break;
     }
@@ -1295,8 +1296,7 @@ static void shader_glsl_color_correction(SHADER_OPCODE_ARG* arg) {
     switch(fmt) {
         case WINED3DFMT_V8U8:
         case WINED3DFMT_V16U16:
-            if(GL_SUPPORT(NV_TEXTURE_SHADER) ||
-              (GL_SUPPORT(ATI_ENVMAP_BUMPMAP) && fmt == WINED3DFMT_V8U8)) {
+            if(GL_SUPPORT(NV_TEXTURE_SHADER) && fmt == WINED3DFMT_V8U8) {
                 /* The 3rd channel returns 1.0 in d3d, but 0.0 in gl. Fix this while we're at it :-) */
                 mask = shader_glsl_add_dst_param(arg, arg->dst, WINED3DSP_WRITEMASK_2, &dst_param);
                 mask_size = shader_glsl_get_write_mask_size(mask);
@@ -1426,7 +1426,7 @@ static void shader_glsl_color_correction(SHADER_OPCODE_ARG* arg) {
  ****************************************************************************/
 
 /* Generate GLSL arithmetic functions (dst = src1 + src2) */
-void shader_glsl_arith(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_arith(SHADER_OPCODE_ARG* arg) {
     CONST SHADER_OPCODE* curOpcode = arg->opcode;
     SHADER_BUFFER* buffer = arg->buffer;
     glsl_src_param_t src0_param;
@@ -1452,7 +1452,7 @@ void shader_glsl_arith(SHADER_OPCODE_ARG* arg) {
 }
 
 /* Process the WINED3DSIO_MOV opcode using GLSL (dst = src) */
-void shader_glsl_mov(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_mov(SHADER_OPCODE_ARG* arg) {
     IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader;
     SHADER_BUFFER* buffer = arg->buffer;
     glsl_src_param_t src0_param;
@@ -1487,7 +1487,7 @@ void shader_glsl_mov(SHADER_OPCODE_ARG* arg) {
 }
 
 /* Process the dot product operators DP3 and DP4 in GLSL (dst = dot(src0, src1)) */
-void shader_glsl_dot(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_dot(SHADER_OPCODE_ARG* arg) {
     CONST SHADER_OPCODE* curOpcode = arg->opcode;
     SHADER_BUFFER* buffer = arg->buffer;
     glsl_src_param_t src0_param;
@@ -1517,7 +1517,7 @@ void shader_glsl_dot(SHADER_OPCODE_ARG* arg) {
 
 /* Note that this instruction has some restrictions. The destination write mask
  * can't contain the w component, and the source swizzles have to be .xyzw */
-void shader_glsl_cross(SHADER_OPCODE_ARG *arg) {
+static void shader_glsl_cross(SHADER_OPCODE_ARG *arg) {
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
@@ -1533,7 +1533,7 @@ void shader_glsl_cross(SHADER_OPCODE_ARG *arg) {
 /* Process the WINED3DSIO_POW instruction in GLSL (dst = |src0|^src1)
  * Src0 and src1 are scalars. Note that D3D uses the absolute of src0, while
  * GLSL uses the value as-is. */
-void shader_glsl_pow(SHADER_OPCODE_ARG *arg) {
+static void shader_glsl_pow(SHADER_OPCODE_ARG *arg) {
     SHADER_BUFFER *buffer = arg->buffer;
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
@@ -1556,7 +1556,7 @@ void shader_glsl_pow(SHADER_OPCODE_ARG *arg) {
 /* Process the WINED3DSIO_LOG instruction in GLSL (dst = log2(|src0|))
  * Src0 is a scalar. Note that D3D uses the absolute of src0, while
  * GLSL uses the value as-is. */
-void shader_glsl_log(SHADER_OPCODE_ARG *arg) {
+static void shader_glsl_log(SHADER_OPCODE_ARG *arg) {
     SHADER_BUFFER *buffer = arg->buffer;
     glsl_src_param_t src0_param;
     DWORD dst_write_mask;
@@ -1575,7 +1575,7 @@ void shader_glsl_log(SHADER_OPCODE_ARG *arg) {
 }
 
 /* Map the opcode 1-to-1 to the GL code (arg->dst = instruction(src0, src1, ...) */
-void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg) {
     CONST SHADER_OPCODE* curOpcode = arg->opcode;
     SHADER_BUFFER* buffer = arg->buffer;
     glsl_src_param_t src_param;
@@ -1592,8 +1592,6 @@ void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg) {
         case WINED3DSIO_ABS: instruction = "abs"; break;
         case WINED3DSIO_FRC: instruction = "fract"; break;
         case WINED3DSIO_NRM: instruction = "normalize"; break;
-        case WINED3DSIO_LOGP:
-        case WINED3DSIO_LOG: instruction = "log2"; break;
         case WINED3DSIO_EXP: instruction = "exp2"; break;
         case WINED3DSIO_SGN: instruction = "sign"; break;
         case WINED3DSIO_DSX: instruction = "dFdx"; break;
@@ -1628,7 +1626,7 @@ void shader_glsl_map2gl(SHADER_OPCODE_ARG* arg) {
  * For 2.0 shaders, just do this (honoring writemask and swizzle):
  *   dst = 2^src;    (partial precision is allowed, but optional)
  */
-void shader_glsl_expp(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_expp(SHADER_OPCODE_ARG* arg) {
     IWineD3DBaseShaderImpl *shader = (IWineD3DBaseShaderImpl *)arg->shader;
     glsl_src_param_t src_param;
 
@@ -1661,7 +1659,7 @@ void shader_glsl_expp(SHADER_OPCODE_ARG* arg) {
 }
 
 /** Process the RCP (reciprocal or inverse) opcode in GLSL (dst = 1 / src) */
-void shader_glsl_rcp(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_rcp(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src_param;
     DWORD write_mask;
     unsigned int mask_size;
@@ -1677,7 +1675,7 @@ void shader_glsl_rcp(SHADER_OPCODE_ARG* arg) {
     }
 }
 
-void shader_glsl_rsq(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_rsq(SHADER_OPCODE_ARG* arg) {
     SHADER_BUFFER* buffer = arg->buffer;
     glsl_src_param_t src_param;
     DWORD write_mask;
@@ -1696,7 +1694,7 @@ void shader_glsl_rsq(SHADER_OPCODE_ARG* arg) {
 }
 
 /** Process signed comparison opcodes in GLSL. */
-void shader_glsl_compare(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_compare(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
     DWORD write_mask;
@@ -1743,7 +1741,7 @@ void shader_glsl_compare(SHADER_OPCODE_ARG* arg) {
 }
 
 /** Process CMP instruction in GLSL (dst = src0 >= 0.0 ? src1 : src2), per channel */
-void shader_glsl_cmp(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_cmp(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
     glsl_src_param_t src2_param;
@@ -1819,7 +1817,7 @@ void shader_glsl_cmp(SHADER_OPCODE_ARG* arg) {
 /** Process the CND opcode in GLSL (dst = (src0 > 0.5) ? src1 : src2) */
 /* For ps 1.1-1.3, only a single component of src0 is used. For ps 1.4
  * the compare is done per component of src0. */
-void shader_glsl_cnd(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_cnd(SHADER_OPCODE_ARG* arg) {
     IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader;
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
@@ -1865,7 +1863,7 @@ void shader_glsl_cnd(SHADER_OPCODE_ARG* arg) {
 }
 
 /** GLSL code generation for WINED3DSIO_MAD: Multiply the first 2 opcodes, then add the last */
-void shader_glsl_mad(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_mad(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
     glsl_src_param_t src2_param;
@@ -1881,7 +1879,7 @@ void shader_glsl_mad(SHADER_OPCODE_ARG* arg) {
 
 /** Handles transforming all WINED3DSIO_M?x? opcodes for 
     Vertex shaders to GLSL codes */
-void shader_glsl_mnxn(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_mnxn(SHADER_OPCODE_ARG* arg) {
     int i;
     int nComponents = 0;
     SHADER_OPCODE_ARG tmpArg;
@@ -1934,7 +1932,7 @@ void shader_glsl_mnxn(SHADER_OPCODE_ARG* arg) {
     blend factor.  Equation:  (dst = src2 + src0 * (src1 - src2))
     This is equivalent to mix(src2, src1, src0);
 */
-void shader_glsl_lrp(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_lrp(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
     glsl_src_param_t src2_param;
@@ -1956,7 +1954,7 @@ void shader_glsl_lrp(SHADER_OPCODE_ARG* arg) {
  * dst.z = (src0.x > 0) ? ((src0.y > 0) ? pow(src0.y, src.w) : 0) : 0
  *                                        where src.w is clamped at +- 128
  */
-void shader_glsl_lit(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_lit(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
     glsl_src_param_t src3_param;
@@ -2000,7 +1998,7 @@ void shader_glsl_lit(SHADER_OPCODE_ARG* arg) {
  * dst.z = src0.z
  * dst.w = src1.w
  */
-void shader_glsl_dst(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_dst(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0y_param;
     glsl_src_param_t src0z_param;
     glsl_src_param_t src1y_param;
@@ -2028,7 +2026,7 @@ void shader_glsl_dst(SHADER_OPCODE_ARG* arg) {
  * dst.z = dst.z
  * dst.w = dst.w
  */
-void shader_glsl_sincos(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_sincos(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     DWORD write_mask;
 
@@ -2060,7 +2058,7 @@ void shader_glsl_sincos(SHADER_OPCODE_ARG* arg) {
  *  Need to use a temporary variable for this operation.
  */
 /* FIXME: I don't think nested loops will work correctly this way. */
-void shader_glsl_loop(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_loop(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src1_param;
     IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader;
     DWORD regtype = shader_get_regtype(arg->src[1]);
@@ -2112,7 +2110,7 @@ void shader_glsl_loop(SHADER_OPCODE_ARG* arg) {
     shader->baseShader.cur_loop_regno++;
 }
 
-void shader_glsl_end(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_end(SHADER_OPCODE_ARG* arg) {
     IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader;
 
     shader_addline(arg->buffer, "}\n");
@@ -2126,7 +2124,7 @@ void shader_glsl_end(SHADER_OPCODE_ARG* arg) {
     }
 }
 
-void shader_glsl_rep(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_rep(SHADER_OPCODE_ARG* arg) {
     IWineD3DBaseShaderImpl* shader = (IWineD3DBaseShaderImpl*) arg->shader;
     glsl_src_param_t src0_param;
 
@@ -2137,14 +2135,14 @@ void shader_glsl_rep(SHADER_OPCODE_ARG* arg) {
     shader->baseShader.cur_loop_depth++;
 }
 
-void shader_glsl_if(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_if(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
 
     shader_glsl_add_src_param(arg, arg->src[0], arg->src_addr[0], WINED3DSP_WRITEMASK_0, &src0_param);
     shader_addline(arg->buffer, "if (%s) {\n", src0_param.param_str);
 }
 
-void shader_glsl_ifc(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_ifc(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
 
@@ -2155,16 +2153,16 @@ void shader_glsl_ifc(SHADER_OPCODE_ARG* arg) {
             src0_param.param_str, shader_get_comp_op(arg->opcode_token), src1_param.param_str);
 }
 
-void shader_glsl_else(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_else(SHADER_OPCODE_ARG* arg) {
     shader_addline(arg->buffer, "} else {\n");
 }
 
-void shader_glsl_break(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_break(SHADER_OPCODE_ARG* arg) {
     shader_addline(arg->buffer, "break;\n");
 }
 
 /* FIXME: According to MSDN the compare is done per component. */
-void shader_glsl_breakc(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_breakc(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
 
@@ -2175,19 +2173,19 @@ void shader_glsl_breakc(SHADER_OPCODE_ARG* arg) {
             src0_param.param_str, shader_get_comp_op(arg->opcode_token), src1_param.param_str);
 }
 
-void shader_glsl_label(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_label(SHADER_OPCODE_ARG* arg) {
 
     DWORD snum = (arg->src[0]) & WINED3DSP_REGNUM_MASK;
     shader_addline(arg->buffer, "}\n");
     shader_addline(arg->buffer, "void subroutine%u () {\n",  snum);
 }
 
-void shader_glsl_call(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_call(SHADER_OPCODE_ARG* arg) {
     DWORD snum = (arg->src[0]) & WINED3DSP_REGNUM_MASK;
     shader_addline(arg->buffer, "subroutine%u();\n", snum);
 }
 
-void shader_glsl_callnz(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_callnz(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src1_param;
 
     DWORD snum = (arg->src[0]) & WINED3DSP_REGNUM_MASK;
@@ -2198,7 +2196,7 @@ void shader_glsl_callnz(SHADER_OPCODE_ARG* arg) {
 /*********************************************
  * Pixel Shader Specific Code begins here
  ********************************************/
-void pshader_glsl_tex(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_tex(SHADER_OPCODE_ARG* arg) {
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
     DWORD hex_version = This->baseShader.hex_version;
@@ -2214,13 +2212,18 @@ void pshader_glsl_tex(SHADER_OPCODE_ARG* arg) {
 
     /* 1.0-1.4: Use destination register as sampler source.
      * 2.0+: Use provided sampler source. */
-    if (hex_version < WINED3DPS_VERSION(1,4)) {
-        DWORD flags;
-
+    if (hex_version < WINED3DPS_VERSION(2,0)) {
         sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
-        flags = deviceImpl->stateBlock->textureState[sampler_idx][WINED3DTSS_TEXTURETRANSFORMFLAGS];
+    } else {
+        sampler_idx = arg->src[1] & WINED3DSP_REGNUM_MASK;
+    }
+    sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK;
 
-        if (flags & WINED3DTTFF_PROJECTED) {
+    if (hex_version < WINED3DPS_VERSION(1,4)) {
+        DWORD flags = deviceImpl->stateBlock->textureState[sampler_idx][WINED3DTSS_TEXTURETRANSFORMFLAGS];
+
+        /* Projected cube textures don't make a lot of sense, the resulting coordinates stay the same. */
+        if (flags & WINED3DTTFF_PROJECTED && sampler_type != WINED3DSTT_CUBE) {
             projected = TRUE;
             switch (flags & ~WINED3DTTFF_PROJECTED) {
                 case WINED3DTTFF_COUNT1: FIXME("WINED3DTTFF_PROJECTED with WINED3DTTFF_COUNT1?\n"); break;
@@ -2234,7 +2237,6 @@ void pshader_glsl_tex(SHADER_OPCODE_ARG* arg) {
         }
     } else if (hex_version < WINED3DPS_VERSION(2,0)) {
         DWORD src_mod = arg->src[0] & WINED3DSP_SRCMOD_MASK;
-        sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
 
         if (src_mod == WINED3DSPSM_DZ) {
             projected = TRUE;
@@ -2246,7 +2248,6 @@ void pshader_glsl_tex(SHADER_OPCODE_ARG* arg) {
             projected = FALSE;
         }
     } else {
-        sampler_idx = arg->src[1] & WINED3DSP_REGNUM_MASK;
         if(arg->opcode_token & WINED3DSI_TEXLD_PROJECT) {
                 /* ps 2.0 texldp instruction always divides by the fourth component. */
                 projected = TRUE;
@@ -2261,7 +2262,6 @@ void pshader_glsl_tex(SHADER_OPCODE_ARG* arg) {
         texrect = TRUE;
     }
 
-    sampler_type = arg->reg_maps->samplers[sampler_idx] & WINED3DSP_TEXTURETYPE_MASK;
     shader_glsl_get_sample_function(sampler_type, projected, texrect, &sample_function);
     mask |= sample_function.coord_mask;
 
@@ -2295,7 +2295,7 @@ void pshader_glsl_tex(SHADER_OPCODE_ARG* arg) {
     }
 }
 
-void shader_glsl_texldl(SHADER_OPCODE_ARG* arg) {
+static void shader_glsl_texldl(SHADER_OPCODE_ARG* arg) {
     IWineD3DBaseShaderImpl* This = (IWineD3DBaseShaderImpl*)arg->shader;
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
     glsl_sample_function_t sample_function;
@@ -2330,7 +2330,7 @@ void shader_glsl_texldl(SHADER_OPCODE_ARG* arg) {
     }
 }
 
-void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg) {
 
     /* FIXME: Make this work for more than just 2D textures */
     
@@ -2382,7 +2382,7 @@ void pshader_glsl_texcoord(SHADER_OPCODE_ARG* arg) {
 /** Process the WINED3DSIO_TEXDP3TEX instruction in GLSL:
  * Take a 3-component dot product of the TexCoord[dstreg] and src,
  * then perform a 1D texture lookup from stage dstregnum, place into dst. */
-void pshader_glsl_texdp3tex(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texdp3tex(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     char dst_mask[6];
     glsl_sample_function_t sample_function;
@@ -2424,7 +2424,7 @@ void pshader_glsl_texdp3tex(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_TEXDP3 instruction in GLSL:
  * Take a 3-component dot product of the TexCoord[dstreg] and src. */
-void pshader_glsl_texdp3(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texdp3(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     DWORD dstreg = arg->dst & WINED3DSP_REGNUM_MASK;
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
@@ -2444,7 +2444,7 @@ void pshader_glsl_texdp3(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_TEXDEPTH instruction in GLSL:
  * Calculate the depth as dst.x / dst.y   */
-void pshader_glsl_texdepth(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texdepth(SHADER_OPCODE_ARG* arg) {
     glsl_dst_param_t dst_param;
 
     shader_glsl_add_dst_param(arg, arg->dst, 0, &dst_param);
@@ -2463,7 +2463,7 @@ void pshader_glsl_texdepth(SHADER_OPCODE_ARG* arg) {
  * Calculate tmp0.y = TexCoord[dstreg] . src.xyz;  (tmp0.x has already been calculated)
  * depth = (tmp0.y == 0.0) ? 1.0 : tmp0.x / tmp0.y
  */
-void pshader_glsl_texm3x2depth(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texm3x2depth(SHADER_OPCODE_ARG* arg) {
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
     DWORD dstreg = arg->dst & WINED3DSP_REGNUM_MASK;
     glsl_src_param_t src0_param;
@@ -2476,7 +2476,7 @@ void pshader_glsl_texm3x2depth(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_TEXM3X2PAD instruction in GLSL
  * Calculate the 1st of a 2-row matrix multiplication. */
-void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG* arg) {
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
     DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
     SHADER_BUFFER* buffer = arg->buffer;
@@ -2488,7 +2488,7 @@ void pshader_glsl_texm3x2pad(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_TEXM3X3PAD instruction in GLSL
  * Calculate the 1st or 2nd row of a 3-row matrix multiplication. */
-void pshader_glsl_texm3x3pad(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texm3x3pad(SHADER_OPCODE_ARG* arg) {
 
     IWineD3DPixelShaderImpl* shader = (IWineD3DPixelShaderImpl*) arg->shader;
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
@@ -2502,7 +2502,7 @@ void pshader_glsl_texm3x3pad(SHADER_OPCODE_ARG* arg) {
     current_state->texcoord_w[current_state->current_row++] = reg;
 }
 
-void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG* arg) {
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
     DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
     SHADER_BUFFER* buffer = arg->buffer;
@@ -2521,7 +2521,7 @@ void pshader_glsl_texm3x2tex(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_TEXM3X3TEX instruction in GLSL
  * Perform the 3rd row of a 3x3 matrix multiply, then sample the texture using the calculated coordinates */
-void pshader_glsl_texm3x3tex(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texm3x3tex(SHADER_OPCODE_ARG* arg) {
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
     glsl_src_param_t src0_param;
     char dst_mask[6];
@@ -2547,7 +2547,7 @@ void pshader_glsl_texm3x3tex(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_TEXM3X3 instruction in GLSL
  * Perform the 3rd row of a 3x3 matrix multiply */
-void pshader_glsl_texm3x3(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texm3x3(SHADER_OPCODE_ARG* arg) {
     DWORD src_mask = WINED3DSP_WRITEMASK_0 | WINED3DSP_WRITEMASK_1 | WINED3DSP_WRITEMASK_2;
     glsl_src_param_t src0_param;
     char dst_mask[6];
@@ -2565,8 +2565,8 @@ void pshader_glsl_texm3x3(SHADER_OPCODE_ARG* arg) {
 }
 
 /** Process the WINED3DSIO_TEXM3X3SPEC instruction in GLSL 
- * Peform the final texture lookup based on the previous 2 3x3 matrix multiplies */
-void pshader_glsl_texm3x3spec(SHADER_OPCODE_ARG* arg) {
+ * Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */
+static void pshader_glsl_texm3x3spec(SHADER_OPCODE_ARG* arg) {
 
     IWineD3DPixelShaderImpl* shader = (IWineD3DPixelShaderImpl*) arg->shader;
     DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
@@ -2599,8 +2599,8 @@ void pshader_glsl_texm3x3spec(SHADER_OPCODE_ARG* arg) {
 }
 
 /** Process the WINED3DSIO_TEXM3X3VSPEC instruction in GLSL 
- * Peform the final texture lookup based on the previous 2 3x3 matrix multiplies */
-void pshader_glsl_texm3x3vspec(SHADER_OPCODE_ARG* arg) {
+ * Perform the final texture lookup based on the previous 2 3x3 matrix multiplies */
+static void pshader_glsl_texm3x3vspec(SHADER_OPCODE_ARG* arg) {
 
     IWineD3DPixelShaderImpl* shader = (IWineD3DPixelShaderImpl*) arg->shader;
     DWORD reg = arg->dst & WINED3DSP_REGNUM_MASK;
@@ -2637,7 +2637,7 @@ void pshader_glsl_texm3x3vspec(SHADER_OPCODE_ARG* arg) {
  * Apply a fake bump map transform.
  * texbem is pshader <= 1.3 only, this saves a few version checks
  */
-void pshader_glsl_texbem(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texbem(SHADER_OPCODE_ARG* arg) {
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     IWineD3DDeviceImpl* deviceImpl = (IWineD3DDeviceImpl*) This->baseShader.device;
     char dst_swizzle[6];
@@ -2692,7 +2692,7 @@ void pshader_glsl_texbem(SHADER_OPCODE_ARG* arg) {
     }
 }
 
-void pshader_glsl_bem(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_bem(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param, src1_param;
     DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
 
@@ -2706,7 +2706,7 @@ void pshader_glsl_bem(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_TEXREG2AR instruction in GLSL
  * Sample 2D texture at dst using the alpha & red (wx) components of src as texture coordinates */
-void pshader_glsl_texreg2ar(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texreg2ar(SHADER_OPCODE_ARG* arg) {
 
     glsl_src_param_t src0_param;
     DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
@@ -2721,7 +2721,7 @@ void pshader_glsl_texreg2ar(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_TEXREG2GB instruction in GLSL
  * Sample 2D texture at dst using the green & blue (yz) components of src as texture coordinates */
-void pshader_glsl_texreg2gb(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texreg2gb(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
     char dst_mask[6];
@@ -2735,7 +2735,7 @@ void pshader_glsl_texreg2gb(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_TEXREG2RGB instruction in GLSL
  * Sample texture at dst using the rgb (xyz) components of src as texture coordinates */
-void pshader_glsl_texreg2rgb(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texreg2rgb(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     char dst_mask[6];
     DWORD sampler_idx = arg->dst & WINED3DSP_REGNUM_MASK;
@@ -2753,7 +2753,7 @@ void pshader_glsl_texreg2rgb(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_TEXKILL instruction in GLSL.
  * If any of the first 3 components are < 0, discard this pixel */
-void pshader_glsl_texkill(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_texkill(SHADER_OPCODE_ARG* arg) {
     IWineD3DPixelShaderImpl* This = (IWineD3DPixelShaderImpl*) arg->shader;
     DWORD hex_version = This->baseShader.hex_version;
     glsl_dst_param_t dst_param;
@@ -2774,7 +2774,7 @@ void pshader_glsl_texkill(SHADER_OPCODE_ARG* arg) {
 
 /** Process the WINED3DSIO_DP2ADD instruction in GLSL.
  * dst = dot2(src0, src1) + src2 */
-void pshader_glsl_dp2add(SHADER_OPCODE_ARG* arg) {
+static void pshader_glsl_dp2add(SHADER_OPCODE_ARG* arg) {
     glsl_src_param_t src0_param;
     glsl_src_param_t src1_param;
     glsl_src_param_t src2_param;
@@ -3042,7 +3042,7 @@ static GLhandleARB generate_param_reorder_function(IWineD3DVertexShader *vertexs
     IWineD3DVertexShaderImpl *vs = (IWineD3DVertexShaderImpl *) vertexshader;
     IWineD3DPixelShaderImpl *ps = (IWineD3DPixelShaderImpl *) pixelshader;
     IWineD3DDeviceImpl *device;
-    DWORD vs_major = vs ? WINED3DSHADER_VERSION_MAJOR(vs->baseShader.hex_version) : 0;
+    DWORD vs_major = WINED3DSHADER_VERSION_MAJOR(vs->baseShader.hex_version);
     DWORD ps_major = ps ? WINED3DSHADER_VERSION_MAJOR(ps->baseShader.hex_version) : 0;
     unsigned int i;
     SHADER_BUFFER buffer;
@@ -3380,7 +3380,7 @@ static void set_glsl_shader_program(IWineD3DDevice *iface, BOOL use_ps, BOOL use
     }
 }
 
-static GLhandleARB create_glsl_blt_shader(WineD3D_GL_Info *gl_info) {
+static GLhandleARB create_glsl_blt_shader(WineD3D_GL_Info *gl_info, enum tex_types tex_type) {
     GLhandleARB program_id;
     GLhandleARB vshader_id, pshader_id;
     const char *blt_vshader[] = {
@@ -3389,26 +3389,51 @@ static GLhandleARB create_glsl_blt_shader(WineD3D_GL_Info *gl_info) {
         "{\n"
         "    gl_Position = gl_Vertex;\n"
         "    gl_FrontColor = vec4(1.0);\n"
-        "    gl_TexCoord[0].x = (gl_Vertex.x * 0.5) + 0.5;\n"
-        "    gl_TexCoord[0].y = (-gl_Vertex.y * 0.5) + 0.5;\n"
+        "    gl_TexCoord[0] = gl_MultiTexCoord0;\n"
         "}\n"
     };
 
-    const char *blt_pshader[] = {
+    const char *blt_pshaders[tex_type_count] = {
+        /* tex_1d */
+        NULL,
+        /* tex_2d */
         "#version 120\n"
         "uniform sampler2D sampler;\n"
         "void main(void)\n"
         "{\n"
         "    gl_FragDepth = texture2D(sampler, gl_TexCoord[0].xy).x;\n"
-        "}\n"
+        "}\n",
+        /* tex_3d */
+        NULL,
+        /* tex_cube */
+        "#version 120\n"
+        "uniform samplerCube sampler;\n"
+        "void main(void)\n"
+        "{\n"
+        "    gl_FragDepth = textureCube(sampler, gl_TexCoord[0].xyz).x;\n"
+        "}\n",
+        /* tex_rect */
+        "#version 120\n"
+        "#extension GL_ARB_texture_rectangle : enable\n"
+        "uniform sampler2DRect sampler;\n"
+        "void main(void)\n"
+        "{\n"
+        "    gl_FragDepth = texture2DRect(sampler, gl_TexCoord[0].xy).x;\n"
+        "}\n",
     };
 
+    if (!blt_pshaders[tex_type])
+    {
+        FIXME("tex_type %#x not supported\n", tex_type);
+        tex_type = tex_2d;
+    }
+
     vshader_id = GL_EXTCALL(glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB));
     GL_EXTCALL(glShaderSourceARB(vshader_id, 1, blt_vshader, NULL));
     GL_EXTCALL(glCompileShaderARB(vshader_id));
 
     pshader_id = GL_EXTCALL(glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB));
-    GL_EXTCALL(glShaderSourceARB(pshader_id, 1, blt_pshader, NULL));
+    GL_EXTCALL(glShaderSourceARB(pshader_id, 1, &blt_pshaders[tex_type], NULL));
     GL_EXTCALL(glCompileShaderARB(pshader_id));
 
     program_id = GL_EXTCALL(glCreateProgramObjectARB());
@@ -3455,19 +3480,21 @@ static void shader_glsl_select(IWineD3DDevice *iface, BOOL usePS, BOOL useVS) {
     checkGLcall("glUseProgramObjectARB");
 }
 
-static void shader_glsl_select_depth_blt(IWineD3DDevice *iface) {
+static void shader_glsl_select_depth_blt(IWineD3DDevice *iface, enum tex_types tex_type) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
     struct shader_glsl_priv *priv = (struct shader_glsl_priv *) This->shader_priv;
-    static GLhandleARB loc = -1;
-
-    if (!priv->depth_blt_glsl_program_id) {
-        priv->depth_blt_glsl_program_id = create_glsl_blt_shader(gl_info);
-        loc = GL_EXTCALL(glGetUniformLocationARB(priv->depth_blt_glsl_program_id, "sampler"));
+    GLhandleARB *blt_program = &priv->depth_blt_program[tex_type];
+
+    if (!*blt_program) {
+        GLhandleARB loc;
+        *blt_program = create_glsl_blt_shader(gl_info, tex_type);
+        loc = GL_EXTCALL(glGetUniformLocationARB(*blt_program, "sampler"));
+        GL_EXTCALL(glUseProgramObjectARB(*blt_program));
+        GL_EXTCALL(glUniform1iARB(loc, 0));
+    } else {
+        GL_EXTCALL(glUseProgramObjectARB(*blt_program));
     }
-
-    GL_EXTCALL(glUseProgramObjectARB(priv->depth_blt_glsl_program_id));
-    GL_EXTCALL(glUniform1iARB(loc, 0));
 }
 
 static void shader_glsl_deselect_depth_blt(IWineD3DDevice *iface) {
@@ -3559,9 +3586,14 @@ static void shader_glsl_free(IWineD3DDevice *iface) {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
     WineD3D_GL_Info *gl_info = &This->adapter->gl_info;
     struct shader_glsl_priv *priv = (struct shader_glsl_priv *)This->shader_priv;
+    int i;
 
-    if(priv->depth_blt_glsl_program_id) {
-        GL_EXTCALL(glDeleteObjectARB(priv->depth_blt_glsl_program_id));
+    for (i = 0; i < tex_type_count; ++i)
+    {
+        if (priv->depth_blt_program[i])
+        {
+            GL_EXTCALL(glDeleteObjectARB(priv->depth_blt_program[i]));
+        }
     }
 
     hash_table_destroy(priv->glsl_program_lookup, NULL, NULL);
@@ -3785,7 +3817,95 @@ static BOOL shader_glsl_conv_supported(WINED3DFORMAT fmt) {
     }
 }
 
+static const SHADER_HANDLER shader_glsl_instruction_handler_table[WINED3DSIH_TABLE_SIZE] =
+{
+    /* WINED3DSIH_ABS           */ shader_glsl_map2gl,
+    /* WINED3DSIH_ADD           */ shader_glsl_arith,
+    /* WINED3DSIH_BEM           */ pshader_glsl_bem,
+    /* WINED3DSIH_BREAK         */ shader_glsl_break,
+    /* WINED3DSIH_BREAKC        */ shader_glsl_breakc,
+    /* WINED3DSIH_BREAKP        */ NULL,
+    /* WINED3DSIH_CALL          */ shader_glsl_call,
+    /* WINED3DSIH_CALLNZ        */ shader_glsl_callnz,
+    /* WINED3DSIH_CMP           */ shader_glsl_cmp,
+    /* WINED3DSIH_CND           */ shader_glsl_cnd,
+    /* WINED3DSIH_CRS           */ shader_glsl_cross,
+    /* WINED3DSIH_DCL           */ NULL,
+    /* WINED3DSIH_DEF           */ NULL,
+    /* WINED3DSIH_DEFB          */ NULL,
+    /* WINED3DSIH_DEFI          */ NULL,
+    /* WINED3DSIH_DP2ADD        */ pshader_glsl_dp2add,
+    /* WINED3DSIH_DP3           */ shader_glsl_dot,
+    /* WINED3DSIH_DP4           */ shader_glsl_dot,
+    /* WINED3DSIH_DST           */ shader_glsl_dst,
+    /* WINED3DSIH_DSX           */ shader_glsl_map2gl,
+    /* WINED3DSIH_DSY           */ shader_glsl_map2gl,
+    /* WINED3DSIH_ELSE          */ shader_glsl_else,
+    /* WINED3DSIH_ENDIF         */ shader_glsl_end,
+    /* WINED3DSIH_ENDLOOP       */ shader_glsl_end,
+    /* WINED3DSIH_ENDREP        */ shader_glsl_end,
+    /* WINED3DSIH_EXP           */ shader_glsl_map2gl,
+    /* WINED3DSIH_EXPP          */ shader_glsl_expp,
+    /* WINED3DSIH_FRC           */ shader_glsl_map2gl,
+    /* WINED3DSIH_IF            */ shader_glsl_if,
+    /* WINED3DSIH_IFC           */ shader_glsl_ifc,
+    /* WINED3DSIH_LABEL         */ shader_glsl_label,
+    /* WINED3DSIH_LIT           */ shader_glsl_lit,
+    /* WINED3DSIH_LOG           */ shader_glsl_log,
+    /* WINED3DSIH_LOGP          */ shader_glsl_log,
+    /* WINED3DSIH_LOOP          */ shader_glsl_loop,
+    /* WINED3DSIH_LRP           */ shader_glsl_lrp,
+    /* WINED3DSIH_M3x2          */ shader_glsl_mnxn,
+    /* WINED3DSIH_M3x3          */ shader_glsl_mnxn,
+    /* WINED3DSIH_M3x4          */ shader_glsl_mnxn,
+    /* WINED3DSIH_M4x3          */ shader_glsl_mnxn,
+    /* WINED3DSIH_M4x4          */ shader_glsl_mnxn,
+    /* WINED3DSIH_MAD           */ shader_glsl_mad,
+    /* WINED3DSIH_MAX           */ shader_glsl_map2gl,
+    /* WINED3DSIH_MIN           */ shader_glsl_map2gl,
+    /* WINED3DSIH_MOV           */ shader_glsl_mov,
+    /* WINED3DSIH_MOVA          */ shader_glsl_mov,
+    /* WINED3DSIH_MUL           */ shader_glsl_arith,
+    /* WINED3DSIH_NOP           */ NULL,
+    /* WINED3DSIH_NRM           */ shader_glsl_map2gl,
+    /* WINED3DSIH_PHASE         */ NULL,
+    /* WINED3DSIH_POW           */ shader_glsl_pow,
+    /* WINED3DSIH_RCP           */ shader_glsl_rcp,
+    /* WINED3DSIH_REP           */ shader_glsl_rep,
+    /* WINED3DSIH_RET           */ NULL,
+    /* WINED3DSIH_RSQ           */ shader_glsl_rsq,
+    /* WINED3DSIH_SETP          */ NULL,
+    /* WINED3DSIH_SGE           */ shader_glsl_compare,
+    /* WINED3DSIH_SGN           */ shader_glsl_map2gl,
+    /* WINED3DSIH_SINCOS        */ shader_glsl_sincos,
+    /* WINED3DSIH_SLT           */ shader_glsl_compare,
+    /* WINED3DSIH_SUB           */ shader_glsl_arith,
+    /* WINED3DSIH_TEX           */ pshader_glsl_tex,
+    /* WINED3DSIH_TEXBEM        */ pshader_glsl_texbem,
+    /* WINED3DSIH_TEXBEML       */ pshader_glsl_texbem,
+    /* WINED3DSIH_TEXCOORD      */ pshader_glsl_texcoord,
+    /* WINED3DSIH_TEXDEPTH      */ pshader_glsl_texdepth,
+    /* WINED3DSIH_TEXDP3        */ pshader_glsl_texdp3,
+    /* WINED3DSIH_TEXDP3TEX     */ pshader_glsl_texdp3tex,
+    /* WINED3DSIH_TEXKILL       */ pshader_glsl_texkill,
+    /* WINED3DSIH_TEXLDD        */ NULL,
+    /* WINED3DSIH_TEXLDL        */ shader_glsl_texldl,
+    /* WINED3DSIH_TEXM3x2DEPTH  */ pshader_glsl_texm3x2depth,
+    /* WINED3DSIH_TEXM3x2PAD    */ pshader_glsl_texm3x2pad,
+    /* WINED3DSIH_TEXM3x2TEX    */ pshader_glsl_texm3x2tex,
+    /* WINED3DSIH_TEXM3x3       */ pshader_glsl_texm3x3,
+    /* WINED3DSIH_TEXM3x3DIFF   */ NULL,
+    /* WINED3DSIH_TEXM3x3PAD    */ pshader_glsl_texm3x3pad,
+    /* WINED3DSIH_TEXM3x3SPEC   */ pshader_glsl_texm3x3spec,
+    /* WINED3DSIH_TEXM3x3TEX    */ pshader_glsl_texm3x3tex,
+    /* WINED3DSIH_TEXM3x3VSPEC  */ pshader_glsl_texm3x3vspec,
+    /* WINED3DSIH_TEXREG2AR     */ pshader_glsl_texreg2ar,
+    /* WINED3DSIH_TEXREG2GB     */ pshader_glsl_texreg2gb,
+    /* WINED3DSIH_TEXREG2RGB    */ pshader_glsl_texreg2rgb,
+};
+
 const shader_backend_t glsl_shader_backend = {
+    shader_glsl_instruction_handler_table,
     shader_glsl_select,
     shader_glsl_select_depth_blt,
     shader_glsl_deselect_depth_blt,
index a93f8fe..79423a1 100644 (file)
@@ -5,7 +5,7 @@
  * Copyright 2003-2004 Raphael Junqueira
  * Copyright 2004 Christian Costa
  * Copyright 2005 Oliver Stieber
- * Copyright 2007 Stefan Dösinger for CodeWeavers
+ * Copyright 2007 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
index 9ebb17b..29c4e98 100644 (file)
@@ -3,7 +3,7 @@
  * and GL_NV_texture_shader
  *
  * Copyright 2006 Henri Verbeet
- * Copyright 2008 Stefan Dösinger(for CodeWeavers)
+ * Copyright 2008 Stefan Dösinger(for CodeWeavers)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
index 95b8da9..ff98333 100644 (file)
@@ -2,7 +2,7 @@
  *
  * Copyright 1997-2000 Marcus Meissner
  * Copyright 2000-2001 TransGaming Technologies Inc.
- * Copyright 2006 Stefan Dösinger for CodeWeavers
+ * Copyright 2006 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
index 29cd368..246b58a 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright 2004 Christian Costa
  * Copyright 2005 Oliver Stieber
  * Copyright 2006 Ivan Gyurdiev
- * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -99,96 +99,96 @@ static HRESULT  WINAPI IWineD3DPixelShaderImpl_GetFunction(IWineD3DPixelShader*
 
 CONST SHADER_OPCODE IWineD3DPixelShaderImpl_shader_ins[] = {
     /* Arithmetic */
-    {WINED3DSIO_NOP,  "nop", "NOP", 0, 0, pshader_hw_map2gl, NULL, 0, 0},
-    {WINED3DSIO_MOV,  "mov", "MOV", 1, 2, pshader_hw_map2gl, shader_glsl_mov, 0, 0},
-    {WINED3DSIO_ADD,  "add", "ADD", 1, 3, pshader_hw_map2gl, shader_glsl_arith, 0, 0},
-    {WINED3DSIO_SUB,  "sub", "SUB", 1, 3, pshader_hw_map2gl, shader_glsl_arith, 0, 0},
-    {WINED3DSIO_MAD,  "mad", "MAD", 1, 4, pshader_hw_map2gl, shader_glsl_mad, 0, 0},
-    {WINED3DSIO_MUL,  "mul", "MUL", 1, 3, pshader_hw_map2gl, shader_glsl_arith, 0, 0},
-    {WINED3DSIO_RCP,  "rcp", "RCP",  1, 2, pshader_hw_map2gl, shader_glsl_rcp, 0, 0},
-    {WINED3DSIO_RSQ,  "rsq",  "RSQ", 1, 2, pshader_hw_map2gl, shader_glsl_rsq, 0, 0},
-    {WINED3DSIO_DP3,  "dp3",  "DP3", 1, 3, pshader_hw_map2gl, shader_glsl_dot, 0, 0},
-    {WINED3DSIO_DP4,  "dp4",  "DP4", 1, 3, pshader_hw_map2gl, shader_glsl_dot, 0, 0},
-    {WINED3DSIO_MIN,  "min",  "MIN", 1, 3, pshader_hw_map2gl, shader_glsl_map2gl, 0, 0},
-    {WINED3DSIO_MAX,  "max",  "MAX", 1, 3, pshader_hw_map2gl, shader_glsl_map2gl, 0, 0},
-    {WINED3DSIO_SLT,  "slt",  "SLT", 1, 3, pshader_hw_map2gl, shader_glsl_compare, 0, 0},
-    {WINED3DSIO_SGE,  "sge",  "SGE", 1, 3, pshader_hw_map2gl, shader_glsl_compare, 0, 0},
-    {WINED3DSIO_ABS,  "abs",  "ABS", 1, 2, pshader_hw_map2gl, shader_glsl_map2gl, 0, 0},
-    {WINED3DSIO_EXP,  "exp",  "EX2", 1, 2, pshader_hw_map2gl, shader_glsl_map2gl, 0, 0},
-    {WINED3DSIO_LOG,  "log",  "LG2", 1, 2, pshader_hw_map2gl, shader_glsl_log, 0, 0},
-    {WINED3DSIO_EXPP, "expp", "EXP", 1, 2, pshader_hw_map2gl, shader_glsl_expp, 0, 0},
-    {WINED3DSIO_LOGP, "logp", "LOG", 1, 2, pshader_hw_map2gl, shader_glsl_map2gl, 0, 0},
-    {WINED3DSIO_DST,  "dst",  "DST", 1, 3, pshader_hw_map2gl, shader_glsl_dst, 0, 0},
-    {WINED3DSIO_LRP,  "lrp",  "LRP", 1, 4, pshader_hw_map2gl, shader_glsl_lrp, 0, 0},
-    {WINED3DSIO_FRC,  "frc",  "FRC", 1, 2, pshader_hw_map2gl, shader_glsl_map2gl, 0, 0},
-    {WINED3DSIO_CND,  "cnd",  NULL, 1, 4, pshader_hw_cnd, shader_glsl_cnd, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,4)},
-    {WINED3DSIO_CMP,  "cmp",  NULL, 1, 4, pshader_hw_cmp, shader_glsl_cmp, WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(3,0)},
-    {WINED3DSIO_POW,  "pow",  "POW", 1, 3, pshader_hw_map2gl, shader_glsl_pow, 0, 0},
-    {WINED3DSIO_CRS,  "crs",  "XPD", 1, 3, pshader_hw_map2gl, shader_glsl_cross, 0, 0},
-    {WINED3DSIO_NRM,      "nrm",      NULL, 1, 2, shader_hw_nrm, shader_glsl_map2gl, 0, 0},
-    {WINED3DSIO_SINCOS,   "sincos",   NULL, 1, 4, shader_hw_sincos, shader_glsl_sincos, WINED3DPS_VERSION(2,0), WINED3DPS_VERSION(2,1)},
-    {WINED3DSIO_SINCOS,   "sincos",   "SCS", 1, 2, shader_hw_sincos, shader_glsl_sincos, WINED3DPS_VERSION(3,0), -1},
-    {WINED3DSIO_DP2ADD,   "dp2add",   NULL, 1, 4, pshader_hw_dp2add, pshader_glsl_dp2add, WINED3DPS_VERSION(2,0), -1},
+    {WINED3DSIO_NOP,          "nop",          "NOP",               0, 0, WINED3DSIH_NOP,          0,                      0                     },
+    {WINED3DSIO_MOV,          "mov",          "MOV",               1, 2, WINED3DSIH_MOV,          0,                      0                     },
+    {WINED3DSIO_ADD,          "add",          "ADD",               1, 3, WINED3DSIH_ADD,          0,                      0                     },
+    {WINED3DSIO_SUB,          "sub",          "SUB",               1, 3, WINED3DSIH_SUB,          0,                      0                     },
+    {WINED3DSIO_MAD,          "mad",          "MAD",               1, 4, WINED3DSIH_MAD,          0,                      0                     },
+    {WINED3DSIO_MUL,          "mul",          "MUL",               1, 3, WINED3DSIH_MUL,          0,                      0                     },
+    {WINED3DSIO_RCP,          "rcp",          "RCP",               1, 2, WINED3DSIH_RCP,          0,                      0                     },
+    {WINED3DSIO_RSQ,          "rsq",          "RSQ",               1, 2, WINED3DSIH_RSQ,          0,                      0                     },
+    {WINED3DSIO_DP3,          "dp3",          "DP3",               1, 3, WINED3DSIH_DP3,          0,                      0                     },
+    {WINED3DSIO_DP4,          "dp4",          "DP4",               1, 3, WINED3DSIH_DP4,          0,                      0                     },
+    {WINED3DSIO_MIN,          "min",          "MIN",               1, 3, WINED3DSIH_MIN,          0,                      0                     },
+    {WINED3DSIO_MAX,          "max",          "MAX",               1, 3, WINED3DSIH_MAX,          0,                      0                     },
+    {WINED3DSIO_SLT,          "slt",          "SLT",               1, 3, WINED3DSIH_SLT,          0,                      0                     },
+    {WINED3DSIO_SGE,          "sge",          "SGE",               1, 3, WINED3DSIH_SGE,          0,                      0                     },
+    {WINED3DSIO_ABS,          "abs",          "ABS",               1, 2, WINED3DSIH_ABS,          0,                      0                     },
+    {WINED3DSIO_EXP,          "exp",          "EX2",               1, 2, WINED3DSIH_EXP,          0,                      0                     },
+    {WINED3DSIO_LOG,          "log",          "LG2",               1, 2, WINED3DSIH_LOG,          0,                      0                     },
+    {WINED3DSIO_EXPP,         "expp",         "EXP",               1, 2, WINED3DSIH_EXPP,         0,                      0                     },
+    {WINED3DSIO_LOGP,         "logp",         "LOG",               1, 2, WINED3DSIH_LOGP,         0,                      0                     },
+    {WINED3DSIO_DST,          "dst",          "DST",               1, 3, WINED3DSIH_DST,          0,                      0                     },
+    {WINED3DSIO_LRP,          "lrp",          "LRP",               1, 4, WINED3DSIH_LRP,          0,                      0                     },
+    {WINED3DSIO_FRC,          "frc",          "FRC",               1, 2, WINED3DSIH_FRC,          0,                      0                     },
+    {WINED3DSIO_CND,          "cnd",          NULL,                1, 4, WINED3DSIH_CND,          WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,4)},
+    {WINED3DSIO_CMP,          "cmp",          NULL,                1, 4, WINED3DSIH_CMP,          WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(3,0)},
+    {WINED3DSIO_POW,          "pow",          "POW",               1, 3, WINED3DSIH_POW,          0,                      0                     },
+    {WINED3DSIO_CRS,          "crs",          "XPD",               1, 3, WINED3DSIH_CRS,          0,                      0                     },
+    {WINED3DSIO_NRM,          "nrm",          NULL,                1, 2, WINED3DSIH_NRM,          0,                      0                     },
+    {WINED3DSIO_SINCOS,       "sincos",       NULL,                1, 4, WINED3DSIH_SINCOS,       WINED3DPS_VERSION(2,0), WINED3DPS_VERSION(2,1)},
+    {WINED3DSIO_SINCOS,       "sincos",       "SCS",               1, 2, WINED3DSIH_SINCOS,       WINED3DPS_VERSION(3,0), -1                    },
+    {WINED3DSIO_DP2ADD,       "dp2add",       NULL,                1, 4, WINED3DSIH_DP2ADD,       WINED3DPS_VERSION(2,0), -1                    },
     /* Matrix */
-    {WINED3DSIO_M4x4, "m4x4", "undefined", 1, 3, shader_hw_mnxn, shader_glsl_mnxn, 0, 0},
-    {WINED3DSIO_M4x3, "m4x3", "undefined", 1, 3, shader_hw_mnxn, shader_glsl_mnxn, 0, 0},
-    {WINED3DSIO_M3x4, "m3x4", "undefined", 1, 3, shader_hw_mnxn, shader_glsl_mnxn, 0, 0},
-    {WINED3DSIO_M3x3, "m3x3", "undefined", 1, 3, shader_hw_mnxn, shader_glsl_mnxn, 0, 0},
-    {WINED3DSIO_M3x2, "m3x2", "undefined", 1, 3, shader_hw_mnxn, shader_glsl_mnxn, 0, 0},
+    {WINED3DSIO_M4x4,         "m4x4",         "undefined",         1, 3, WINED3DSIH_M4x4,         0,                      0                     },
+    {WINED3DSIO_M4x3,         "m4x3",         "undefined",         1, 3, WINED3DSIH_M4x3,         0,                      0                     },
+    {WINED3DSIO_M3x4,         "m3x4",         "undefined",         1, 3, WINED3DSIH_M3x4,         0,                      0                     },
+    {WINED3DSIO_M3x3,         "m3x3",         "undefined",         1, 3, WINED3DSIH_M3x3,         0,                      0                     },
+    {WINED3DSIO_M3x2,         "m3x2",         "undefined",         1, 3, WINED3DSIH_M3x2,         0,                      0                     },
     /* Register declarations */
-    {WINED3DSIO_DCL,      "dcl",      NULL, 0, 2, NULL, NULL, 0, 0},
+    {WINED3DSIO_DCL,          "dcl",          NULL,                0, 2, WINED3DSIH_DCL,          0,                      0                     },
     /* Flow control - requires GLSL or software shaders */
-    {WINED3DSIO_REP ,     "rep",      NULL, 0, 1, NULL, shader_glsl_rep,    WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_ENDREP,   "endrep",   NULL, 0, 0, NULL, shader_glsl_end,    WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_IF,       "if",       NULL, 0, 1, NULL, shader_glsl_if,     WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_IFC,      "ifc",      NULL, 0, 2, NULL, shader_glsl_ifc,    WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_ELSE,     "else",     NULL, 0, 0, NULL, shader_glsl_else,   WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_ENDIF,    "endif",    NULL, 0, 0, NULL, shader_glsl_end,    WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_BREAK,    "break",    NULL, 0, 0, NULL, shader_glsl_break,  WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_BREAKC,   "breakc",   NULL, 0, 2, NULL, shader_glsl_breakc, WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_BREAKP,   "breakp",   GLNAME_REQUIRE_GLSL, 0, 1, NULL, NULL, 0, 0},
-    {WINED3DSIO_CALL,     "call",     NULL, 0, 1, NULL, shader_glsl_call, WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_CALLNZ,   "callnz",   NULL, 0, 2, NULL, shader_glsl_callnz, WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_LOOP,     "loop",     NULL, 0, 2, NULL, shader_glsl_loop,   WINED3DPS_VERSION(3,0), -1},
-    {WINED3DSIO_RET,      "ret",      NULL, 0, 0, NULL, NULL,               WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_ENDLOOP,  "endloop",  NULL, 0, 0, NULL, shader_glsl_end,    WINED3DPS_VERSION(3,0), -1},
-    {WINED3DSIO_LABEL,    "label",    NULL, 0, 1, NULL, shader_glsl_label,  WINED3DPS_VERSION(2,1), -1},
+    {WINED3DSIO_REP ,         "rep",          NULL,                0, 1, WINED3DSIH_REP,          WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_ENDREP,       "endrep",       NULL,                0, 0, WINED3DSIH_ENDREP,       WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_IF,           "if",           NULL,                0, 1, WINED3DSIH_IF,           WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_IFC,          "ifc",          NULL,                0, 2, WINED3DSIH_IFC,          WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_ELSE,         "else",         NULL,                0, 0, WINED3DSIH_ELSE,         WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_ENDIF,        "endif",        NULL,                0, 0, WINED3DSIH_ENDIF,        WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_BREAK,        "break",        NULL,                0, 0, WINED3DSIH_BREAK,        WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_BREAKC,       "breakc",       NULL,                0, 2, WINED3DSIH_BREAKC,       WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_BREAKP,       "breakp",       GLNAME_REQUIRE_GLSL, 0, 1, WINED3DSIH_BREAKP,       0,                      0                     },
+    {WINED3DSIO_CALL,         "call",         NULL,                0, 1, WINED3DSIH_CALL,         WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_CALLNZ,       "callnz",       NULL,                0, 2, WINED3DSIH_CALLNZ,       WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_LOOP,         "loop",         NULL,                0, 2, WINED3DSIH_LOOP,         WINED3DPS_VERSION(3,0), -1                    },
+    {WINED3DSIO_RET,          "ret",          NULL,                0, 0, WINED3DSIH_RET,          WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_ENDLOOP,      "endloop",      NULL,                0, 0, WINED3DSIH_ENDLOOP,      WINED3DPS_VERSION(3,0), -1                    },
+    {WINED3DSIO_LABEL,        "label",        NULL,                0, 1, WINED3DSIH_LABEL,        WINED3DPS_VERSION(2,1), -1                    },
     /* Constant definitions */
-    {WINED3DSIO_DEF,      "def",      "undefined",         1, 5, NULL, NULL, 0, 0},
-    {WINED3DSIO_DEFB,     "defb",     GLNAME_REQUIRE_GLSL, 1, 2, NULL, NULL, 0, 0},
-    {WINED3DSIO_DEFI,     "defi",     GLNAME_REQUIRE_GLSL, 1, 5, NULL, NULL, 0, 0},
+    {WINED3DSIO_DEF,          "def",          "undefined",         1, 5, WINED3DSIH_DEF,          0,                      0                     },
+    {WINED3DSIO_DEFB,         "defb",         GLNAME_REQUIRE_GLSL, 1, 2, WINED3DSIH_DEFB,         0,                      0                     },
+    {WINED3DSIO_DEFI,         "defi",         GLNAME_REQUIRE_GLSL, 1, 5, WINED3DSIH_DEFI,         0,                      0                     },
     /* Texture */
-    {WINED3DSIO_TEXCOORD, "texcoord", "undefined", 1, 1, pshader_hw_texcoord, pshader_glsl_texcoord, 0, WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXCOORD, "texcrd",   "undefined", 1, 2, pshader_hw_texcoord, pshader_glsl_texcoord, WINED3DPS_VERSION(1,4), WINED3DPS_VERSION(1,4)},
-    {WINED3DSIO_TEXKILL,  "texkill",  "KIL",       1, 1, pshader_hw_texkill, pshader_glsl_texkill, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(3,0)},
-    {WINED3DSIO_TEX,      "tex",      "undefined", 1, 1, pshader_hw_tex, pshader_glsl_tex, 0, WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEX,      "texld",    "undefined", 1, 2, pshader_hw_tex, pshader_glsl_tex, WINED3DPS_VERSION(1,4), WINED3DPS_VERSION(1,4)},
-    {WINED3DSIO_TEX,      "texld",    "undefined", 1, 3, pshader_hw_tex, pshader_glsl_tex, WINED3DPS_VERSION(2,0), -1},
-    {WINED3DSIO_TEXBEM,   "texbem",   "undefined", 1, 2, pshader_hw_texbem, pshader_glsl_texbem, 0, WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXBEML,  "texbeml",  GLNAME_REQUIRE_GLSL, 1, 2, pshader_hw_texbem, pshader_glsl_texbem, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXREG2AR,"texreg2ar","undefined", 1, 2, pshader_hw_texreg2ar, pshader_glsl_texreg2ar, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXREG2GB,"texreg2gb","undefined", 1, 2, pshader_hw_texreg2gb, pshader_glsl_texreg2gb, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXREG2RGB,   "texreg2rgb",   "undefined", 1, 2, pshader_hw_texreg2rgb, pshader_glsl_texreg2rgb, WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x2PAD,   "texm3x2pad",   "undefined", 1, 2, pshader_hw_texm3x2pad, pshader_glsl_texm3x2pad, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x2TEX,   "texm3x2tex",   "undefined", 1, 2, pshader_hw_texm3x2tex, pshader_glsl_texm3x2tex, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x3PAD,   "texm3x3pad",   "undefined", 1, 2, pshader_hw_texm3x3pad, pshader_glsl_texm3x3pad, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x3DIFF,  "texm3x3diff",  GLNAME_REQUIRE_GLSL, 1, 2, NULL, NULL, WINED3DPS_VERSION(0,0), WINED3DPS_VERSION(0,0)},
-    {WINED3DSIO_TEXM3x3SPEC,  "texm3x3spec",  "undefined", 1, 3, pshader_hw_texm3x3spec, pshader_glsl_texm3x3spec, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x3VSPEC, "texm3x3vspec",  "undefined", 1, 2, pshader_hw_texm3x3vspec, pshader_glsl_texm3x3vspec, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x3TEX,   "texm3x3tex",   "undefined", 1, 2, pshader_hw_texm3x3tex, pshader_glsl_texm3x3tex, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXDP3TEX,    "texdp3tex",    NULL, 1, 2, pshader_hw_texdp3tex, pshader_glsl_texdp3tex, WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x2DEPTH, "texm3x2depth", GLNAME_REQUIRE_GLSL, 1, 2, pshader_hw_texm3x2depth, pshader_glsl_texm3x2depth, WINED3DPS_VERSION(1,3), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXDP3,   "texdp3",   NULL, 1, 2, pshader_hw_texdp3, pshader_glsl_texdp3, WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXM3x3,  "texm3x3",  NULL, 1, 2, pshader_hw_texm3x3, pshader_glsl_texm3x3, WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(1,3)},
-    {WINED3DSIO_TEXDEPTH, "texdepth", NULL, 1, 1, pshader_hw_texdepth, pshader_glsl_texdepth, WINED3DPS_VERSION(1,4), WINED3DPS_VERSION(1,4)},
-    {WINED3DSIO_BEM,      "bem",      "undefined",         1, 3, pshader_hw_bem, pshader_glsl_bem, WINED3DPS_VERSION(1,4), WINED3DPS_VERSION(1,4)},
-    {WINED3DSIO_DSX,      "dsx",      NULL, 1, 2, NULL, shader_glsl_map2gl, WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_DSY,      "dsy",      NULL, 1, 2, NULL, shader_glsl_map2gl, WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_TEXLDD,   "texldd",   GLNAME_REQUIRE_GLSL, 1, 5, NULL, NULL, WINED3DPS_VERSION(2,1), -1},
-    {WINED3DSIO_SETP,     "setp",     GLNAME_REQUIRE_GLSL, 1, 3, NULL, NULL, 0, 0},
-    {WINED3DSIO_TEXLDL,   "texldl",   NULL, 1, 3, NULL, shader_glsl_texldl, WINED3DPS_VERSION(3,0), -1},
-    {WINED3DSIO_PHASE,    "phase",    GLNAME_REQUIRE_GLSL, 0, 0, NULL, NULL, 0, 0},
-    {0,               NULL,       NULL,   0, 0, NULL,            NULL, 0, 0}
+    {WINED3DSIO_TEXCOORD,     "texcoord",     "undefined",         1, 1, WINED3DSIH_TEXCOORD,     0,                      WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXCOORD,     "texcrd",       "undefined",         1, 2, WINED3DSIH_TEXCOORD,     WINED3DPS_VERSION(1,4), WINED3DPS_VERSION(1,4)},
+    {WINED3DSIO_TEXKILL,      "texkill",      "KIL",               1, 1, WINED3DSIH_TEXKILL,      WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(3,0)},
+    {WINED3DSIO_TEX,          "tex",          "undefined",         1, 1, WINED3DSIH_TEX,          0,                      WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEX,          "texld",        "undefined",         1, 2, WINED3DSIH_TEX,          WINED3DPS_VERSION(1,4), WINED3DPS_VERSION(1,4)},
+    {WINED3DSIO_TEX,          "texld",        "undefined",         1, 3, WINED3DSIH_TEX,          WINED3DPS_VERSION(2,0), -1                    },
+    {WINED3DSIO_TEXBEM,       "texbem",       "undefined",         1, 2, WINED3DSIH_TEXBEM,       0,                      WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXBEML,      "texbeml",      GLNAME_REQUIRE_GLSL, 1, 2, WINED3DSIH_TEXBEML,      WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXREG2AR,    "texreg2ar",    "undefined",         1, 2, WINED3DSIH_TEXREG2AR,    WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXREG2GB,    "texreg2gb",    "undefined",         1, 2, WINED3DSIH_TEXREG2GB,    WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXREG2RGB,   "texreg2rgb",   "undefined",         1, 2, WINED3DSIH_TEXREG2RGB,   WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXM3x2PAD,   "texm3x2pad",   "undefined",         1, 2, WINED3DSIH_TEXM3x2PAD,   WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXM3x2TEX,   "texm3x2tex",   "undefined",         1, 2, WINED3DSIH_TEXM3x2TEX,   WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXM3x3PAD,   "texm3x3pad",   "undefined",         1, 2, WINED3DSIH_TEXM3x3PAD,   WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXM3x3DIFF,  "texm3x3diff",  GLNAME_REQUIRE_GLSL, 1, 2, WINED3DSIH_TEXM3x3DIFF,  WINED3DPS_VERSION(0,0), WINED3DPS_VERSION(0,0)},
+    {WINED3DSIO_TEXM3x3SPEC,  "texm3x3spec",  "undefined",         1, 3, WINED3DSIH_TEXM3x3SPEC,  WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXM3x3VSPEC, "texm3x3vspec", "undefined",         1, 2, WINED3DSIH_TEXM3x3VSPEC, WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXM3x3TEX,   "texm3x3tex",   "undefined",         1, 2, WINED3DSIH_TEXM3x3TEX,   WINED3DPS_VERSION(1,0), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXDP3TEX,    "texdp3tex",    NULL,                1, 2, WINED3DSIH_TEXDP3TEX,    WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXM3x2DEPTH, "texm3x2depth", GLNAME_REQUIRE_GLSL, 1, 2, WINED3DSIH_TEXM3x2DEPTH, WINED3DPS_VERSION(1,3), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXDP3,       "texdp3",       NULL,                1, 2, WINED3DSIH_TEXDP3,       WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXM3x3,      "texm3x3",      NULL,                1, 2, WINED3DSIH_TEXM3x3,      WINED3DPS_VERSION(1,2), WINED3DPS_VERSION(1,3)},
+    {WINED3DSIO_TEXDEPTH,     "texdepth",     NULL,                1, 1, WINED3DSIH_TEXDEPTH,     WINED3DPS_VERSION(1,4), WINED3DPS_VERSION(1,4)},
+    {WINED3DSIO_BEM,          "bem",          "undefined",         1, 3, WINED3DSIH_BEM,          WINED3DPS_VERSION(1,4), WINED3DPS_VERSION(1,4)},
+    {WINED3DSIO_DSX,          "dsx",          NULL,                1, 2, WINED3DSIH_DSX,          WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_DSY,          "dsy",          NULL,                1, 2, WINED3DSIH_DSY,          WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_TEXLDD,       "texldd",       GLNAME_REQUIRE_GLSL, 1, 5, WINED3DSIH_TEXLDD,       WINED3DPS_VERSION(2,1), -1                    },
+    {WINED3DSIO_SETP,         "setp",         GLNAME_REQUIRE_GLSL, 1, 3, WINED3DSIH_SETP,         0,                      0                     },
+    {WINED3DSIO_TEXLDL,       "texldl",       NULL,                1, 3, WINED3DSIH_TEXLDL,       WINED3DPS_VERSION(3,0), -1                    },
+    {WINED3DSIO_PHASE,        "phase",        GLNAME_REQUIRE_GLSL, 0, 0, WINED3DSIH_PHASE,        0,                      0                     },
+    {0,                       NULL,           NULL,                0, 0, 0,                       0,                      0                     }
 };
 
 static void pshader_set_limits(
index 45e35b7..7826325 100644 (file)
@@ -2,7 +2,7 @@
  * IWineD3DQuery implementation
  *
  * Copyright 2005 Oliver Stieber
- * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
index 17e540b..c75e09d 100644 (file)
@@ -217,16 +217,18 @@ HRESULT WINAPI IWineD3DResourceImpl_FreePrivateData(IWineD3DResource *iface, REF
     return WINED3D_OK;
 }
 
-/* Priority support is not implemented yet */
 DWORD    WINAPI        IWineD3DResourceImpl_SetPriority(IWineD3DResource *iface, DWORD PriorityNew) {
     IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
-    FIXME("(%p) : stub\n", This);
-    return 0;
+    DWORD PriorityOld = This->resource.priority;
+    This->resource.priority = PriorityNew;
+    TRACE("(%p) : new priority %d, returning old priority %d\n", This, PriorityNew, PriorityOld );
+    return PriorityOld;
 }
+
 DWORD    WINAPI        IWineD3DResourceImpl_GetPriority(IWineD3DResource *iface) {
     IWineD3DResourceImpl *This = (IWineD3DResourceImpl *)iface;
-    FIXME("(%p) : stub\n", This);
-    return 0;
+    TRACE("(%p) : returning %d\n", This, This->resource.priority );
+    return This->resource.priority;
 }
 
 /* Preloading of resources is not supported yet */
index 77b7a86..b9d28d4 100644 (file)
@@ -8,7 +8,7 @@
  * Copyright 2004 Christian Costa
  * Copyright 2005 Oliver Stieber
  * Copyright 2006 Henri Verbeet
- * Copyright 2006-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2006-2008 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1410,16 +1410,30 @@ static void state_psizemin_w(DWORD state, IWineD3DStateBlockImpl *stateblock, Wi
     if(tmpvalue.f != 1.0) {
         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) {
+        FIXME("WINED3DRS_POINTSIZE_MAX not supported on this opengl, value is %f\n", tmpvalue.f);
+    }
+
 }
 
 static void state_psizemin_ext(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
     union {
         DWORD d;
         float f;
-    } tmpvalue;
+    } min, max;
 
-    tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MIN];
-    GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MIN_EXT, tmpvalue.f);
+    min.d = stateblock->renderState[WINED3DRS_POINTSIZE_MIN];
+    max.d = stateblock->renderState[WINED3DRS_POINTSIZE_MAX];
+
+    /* Max point size trumps min point size */
+    if(min.f > max.f) {
+        min.f = max.f;
+    }
+
+    GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MIN_EXT, min.f);
+    checkGLcall("glPointParameterfEXT(...)");
+    GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MAX_EXT, max.f);
     checkGLcall("glPointParameterfEXT(...)");
 }
 
@@ -1427,45 +1441,20 @@ static void state_psizemin_arb(DWORD state, IWineD3DStateBlockImpl *stateblock,
     union {
         DWORD d;
         float f;
-    } tmpvalue;
+    } min, max;
 
-    tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MIN];
-    GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MIN_ARB, tmpvalue.f);
-    checkGLcall("glPointParameterfARB(...)");
-}
+    min.d = stateblock->renderState[WINED3DRS_POINTSIZE_MIN];
+    max.d = stateblock->renderState[WINED3DRS_POINTSIZE_MAX];
 
-static void state_psizemax_arb(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
-    union {
-        DWORD d;
-        float f;
-    } tmpvalue;
+    /* Max point size trumps min point size */
+    if(min.f > max.f) {
+        min.f = max.f;
+    }
 
-    tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MAX];
-    GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MAX_ARB, tmpvalue.f);
+    GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MIN_ARB, min.f);
+    checkGLcall("glPointParameterfARB(...)");
+    GL_EXTCALL(glPointParameterfARB)(GL_POINT_SIZE_MAX_ARB, max.f);
     checkGLcall("glPointParameterfARB(...)");
-}
-
-static void state_psizemax_ext(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
-    union {
-        DWORD d;
-        float f;
-    } tmpvalue;
-
-    tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MAX];
-    GL_EXTCALL(glPointParameterfEXT)(GL_POINT_SIZE_MAX_EXT, tmpvalue.f);
-    checkGLcall("glPointParameterfEXT(...)");
-}
-
-static void state_psizemax_w(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
-    union {
-        DWORD d;
-        float f;
-    } tmpvalue;
-
-    tmpvalue.d = stateblock->renderState[WINED3DRS_POINTSIZE_MAX];
-    if(tmpvalue.f != 64.0) {
-        FIXME("WINED3DRS_POINTSIZE_MAX not supported on this opengl, value is %f\n", tmpvalue.f);
-    }
 }
 
 static void state_pscale(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
@@ -2860,40 +2849,8 @@ static void set_tex_op(IWineD3DDevice *iface, BOOL isAlpha, int Stage, WINED3DTE
                 Handled = FALSE;
                 break;
         case WINED3DTOP_BUMPENVMAPLUMINANCE:
-            if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
-                    /* Some apps use BUMPENVMAPLUMINANCE instead of D3DTOP_BUMPENVMAP, although
-                * they check for the non-luminance cap flag. Well, give them what they asked
-                * for :-)
-                    */
-                WARN("Application uses WINED3DTOP_BUMPENVMAPLUMINANCE\n");
-            } else {
-                Handled = FALSE;
-                break;
-            }
-            /* Fall through */
         case WINED3DTOP_BUMPENVMAP:
-            if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
-                TRACE("Using ati bumpmap on stage %d, target %d\n", Stage, Stage + 1);
-                glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_BUMP_ENVMAP_ATI);
-                checkGLcall("glTexEnvi(GL_TEXTURE_ENV, comb_target, GL_BUMP_ENVMAP_ATI)");
-                glTexEnvi(GL_TEXTURE_ENV, GL_BUMP_TARGET_ATI, GL_TEXTURE0_ARB + Stage + 1);
-                checkGLcall("glTexEnvi(GL_TEXTURE_ENV, GL_BUMP_TARGET_ATI, GL_TEXTURE0_ARB + Stage + 1)");
-                glTexEnvi(GL_TEXTURE_ENV, src0_target, src3);
-                checkGLcall("GL_TEXTURE_ENV, src0_target, src3");
-                glTexEnvi(GL_TEXTURE_ENV, opr0_target, opr3);
-                checkGLcall("GL_TEXTURE_ENV, opr0_target, opr3");
-                glTexEnvi(GL_TEXTURE_ENV, src1_target, src1);
-                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
-                glTexEnvi(GL_TEXTURE_ENV, opr1_target, opr1);
-                checkGLcall("GL_TEXTURE_ENV, opr1_target, opr1");
-                glTexEnvi(GL_TEXTURE_ENV, src2_target, src2);
-                checkGLcall("GL_TEXTURE_ENV, src0_target, src1");
-                glTexEnvi(GL_TEXTURE_ENV, opr2_target, opr2);
-                checkGLcall("GL_TEXTURE_ENV, opr2_target, opr2");
-
-                Handled = TRUE;
-                break;
-            } else if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
+            if(GL_SUPPORT(NV_TEXTURE_SHADER2)) {
                 /* Technically texture shader support without register combiners is possible, but not expected to occur
                  * on real world cards, so for now a fixme should be enough
                  */
@@ -3434,7 +3391,7 @@ static void sampler_texmatrix(DWORD state, IWineD3DStateBlockImpl *stateblock, W
      * IWineD3DBaseTexture::ApplyStateChanges multiplies the set matrix with a fixup matrix. Before the
      * scaling is reapplied or removed, the texture matrix has to be reapplied
      *
-     * The mapped stage is alrady active because the sampler() function below, which is part of the
+     * The mapped stage is already active because the sampler() function below, which is part of the
      * misc pipeline
      */
     if(sampler < MAX_TEXTURES) {
@@ -3599,24 +3556,6 @@ static void shader_bumpenvmat(DWORD state, IWineD3DStateBlockImpl *stateblock, W
     }
 }
 
-static void tex_bumpenvmat(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
-    DWORD stage = (state - STATE_TEXTURESTAGE(0, 0)) / WINED3D_HIGHEST_TEXTURE_STATE;
-    float mat[2][2];
-
-    if(stage >= GL_LIMITS(texture_stages)) {
-        WARN("Bump env matrix of unsupported stage set\n");
-    } else if(GL_SUPPORT(ARB_MULTITEXTURE)) {
-        GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + stage));
-        checkGLcall("GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB + stage))");
-    }
-    mat[0][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT00]);
-    mat[1][0] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT01]);
-    mat[0][1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT10]);
-    mat[1][1] = *((float *) &stateblock->textureState[stage][WINED3DTSS_BUMPENVMAT11]);
-    GL_EXTCALL(glTexBumpParameterfvATI(GL_BUMP_ROT_MATRIX_ATI, (float *) mat));
-    checkGLcall("glTexBumpParameterfvATI");
-}
-
 static void transform_world(DWORD state, IWineD3DStateBlockImpl *stateblock, WineD3DContext *context) {
     /* This function is called by transform_view below if the view matrix was changed too
      *
@@ -3681,7 +3620,7 @@ static void transform_worldex(DWORD state, IWineD3DStateBlockImpl *stateblock, W
     }
 
     /* GL_MODELVIEW0_ARB:  0x1700
-     * GL_MODELVIEW1_ARB:  0x0x850a
+     * GL_MODELVIEW1_ARB:  0x850a
      * GL_MODELVIEW2_ARB:  0x8722
      * GL_MODELVIEW3_ARB:  0x8723
      * etc
@@ -5370,9 +5309,9 @@ const struct StateEntryTemplate ffp_vertexstate_template[] = {
     { STATE_RENDER(WINED3DRS_POINTSCALE_A),               { STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        }, 0                               },
     { STATE_RENDER(WINED3DRS_POINTSCALE_B),               { STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        }, 0                               },
     { STATE_RENDER(WINED3DRS_POINTSCALE_C),               { STATE_RENDER(WINED3DRS_POINTSCALEENABLE),           state_pscale        }, 0                               },
-    { STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              { STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              state_psizemax_arb  }, ARB_POINT_PARAMETERS            },
-    { STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              { STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              state_psizemax_ext  }, EXT_POINT_PARAMETERS            },
-    { STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              { STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              state_psizemax_w    }, 0                               },
+    { STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              { STATE_RENDER(WINED3DRS_POINTSIZE_MIN),              state_psizemin_arb  }, ARB_POINT_PARAMETERS            },
+    { STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              { STATE_RENDER(WINED3DRS_POINTSIZE_MIN),              state_psizemin_ext  }, EXT_POINT_PARAMETERS            },
+    { STATE_RENDER(WINED3DRS_POINTSIZE_MAX),              { STATE_RENDER(WINED3DRS_POINTSIZE_MIN),              state_psizemin_w    }, 0                               },
     /* pixel shaders need a different fog input */
     { STATE_PIXELSHADER,                                  { STATE_PIXELSHADER,                                  apply_pshader_fog   }, 0                               },
     /* Samplers for NP2 texture matrix adjustions. They are not needed if GL_ARB_texture_non_power_of_two is supported,
@@ -5413,10 +5352,6 @@ static const struct StateEntryTemplate ffp_fragmentstate_template[] = {
     { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
-    { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(0, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
     { STATE_TEXTURESTAGE(0, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
     { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(0, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(0, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(0, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
@@ -5427,10 +5362,6 @@ static const struct StateEntryTemplate ffp_fragmentstate_template[] = {
     { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
-    { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(1, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
     { STATE_TEXTURESTAGE(1, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
     { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(1, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(1, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(1, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
@@ -5441,10 +5372,6 @@ static const struct StateEntryTemplate ffp_fragmentstate_template[] = {
     { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
-    { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(2, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
     { STATE_TEXTURESTAGE(2, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
     { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(2, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(2, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(2, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
@@ -5455,10 +5382,6 @@ static const struct StateEntryTemplate ffp_fragmentstate_template[] = {
     { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
-    { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(3, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
     { STATE_TEXTURESTAGE(3, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
     { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(3, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(3, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(3, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
@@ -5469,10 +5392,6 @@ static const struct StateEntryTemplate ffp_fragmentstate_template[] = {
     { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
-    { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(4, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
     { STATE_TEXTURESTAGE(4, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
     { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(4, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(4, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(4, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
@@ -5483,10 +5402,6 @@ static const struct StateEntryTemplate ffp_fragmentstate_template[] = {
     { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
-    { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(5, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
     { STATE_TEXTURESTAGE(5, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
     { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(5, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(5, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(5, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
@@ -5497,10 +5412,6 @@ static const struct StateEntryTemplate ffp_fragmentstate_template[] = {
     { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
-    { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(6, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
     { STATE_TEXTURESTAGE(6, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
     { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(6, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(6, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(6, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
@@ -5511,10 +5422,6 @@ static const struct StateEntryTemplate ffp_fragmentstate_template[] = {
     { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG1),        { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG2),        { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
-    { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT01),     { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT10),     { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
-    { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT11),     { STATE_TEXTURESTAGE(7, WINED3DTSS_BUMPENVMAT00),     tex_bumpenvmat      }, ATI_ENVMAP_BUMPMAP              },
     { STATE_TEXTURESTAGE(7, WINED3DTSS_COLORARG0),        { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
     { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAARG0),        { STATE_TEXTURESTAGE(7, WINED3DTSS_ALPHAOP),          tex_alphaop         }, 0                               },
     { STATE_TEXTURESTAGE(7, WINED3DTSS_RESULTARG),        { STATE_TEXTURESTAGE(7, WINED3DTSS_COLOROP),          tex_colorop         }, 0                               },
@@ -5570,10 +5477,6 @@ static void ffp_fragment_get_caps(WINED3DDEVTYPE devtype, WineD3D_GL_Info *gl_in
     if (GL_SUPPORT(ARB_TEXTURE_ENV_DOT3))
         pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_DOTPRODUCT3;
 
-    if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
-        pCaps->TextureOpCaps |= WINED3DTEXOPCAPS_BUMPENVMAP;
-    }
-
     pCaps->MaxTextureBlendStages   = GL_LIMITS(texture_stages);
     pCaps->MaxSimultaneousTextures = GL_LIMITS(textures);
 }
index 78268d8..0d99134 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright 2002 Raphael Junqueira
  * Copyright 2004 Jason Edmeades
  * Copyright 2005 Oliver Stieber
- * Copyright 2007 Stefan Dösinger for CodeWeavers
+ * Copyright 2007 Stefan Dösinger for CodeWeavers
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1206,13 +1206,13 @@ static HRESULT  WINAPI IWineD3DStateBlockImpl_InitStartupStateBlock(IWineD3DStat
         This->textureState[i][WINED3DTSS_ALPHAOP               ] = (i==0)? WINED3DTOP_SELECTARG1 :  WINED3DTOP_DISABLE;
         This->textureState[i][WINED3DTSS_ALPHAARG1             ] = WINED3DTA_TEXTURE;
         This->textureState[i][WINED3DTSS_ALPHAARG2             ] = WINED3DTA_CURRENT;
-        This->textureState[i][WINED3DTSS_BUMPENVMAT00          ] = (DWORD) 0.0;
-        This->textureState[i][WINED3DTSS_BUMPENVMAT01          ] = (DWORD) 0.0;
-        This->textureState[i][WINED3DTSS_BUMPENVMAT10          ] = (DWORD) 0.0;
-        This->textureState[i][WINED3DTSS_BUMPENVMAT11          ] = (DWORD) 0.0;
+        This->textureState[i][WINED3DTSS_BUMPENVMAT00          ] = 0;
+        This->textureState[i][WINED3DTSS_BUMPENVMAT01          ] = 0;
+        This->textureState[i][WINED3DTSS_BUMPENVMAT10          ] = 0;
+        This->textureState[i][WINED3DTSS_BUMPENVMAT11          ] = 0;
         This->textureState[i][WINED3DTSS_TEXCOORDINDEX         ] = i;
-        This->textureState[i][WINED3DTSS_BUMPENVLSCALE         ] = (DWORD) 0.0;
-        This->textureState[i][WINED3DTSS_BUMPENVLOFFSET        ] = (DWORD) 0.0;
+        This->textureState[i][WINED3DTSS_BUMPENVLSCALE         ] = 0;
+        This->textureState[i][WINED3DTSS_BUMPENVLOFFSET        ] = 0;
         This->textureState[i][WINED3DTSS_TEXTURETRANSFORMFLAGS ] = WINED3DTTFF_DISABLE;
         This->textureState[i][WINED3DTSS_ADDRESSW              ] = WINED3DTADDRESS_WRAP;
         This->textureState[i][WINED3DTSS_COLORARG0             ] = WINED3DTA_CURRENT;
index be6ffb3..1849b83 100644 (file)
@@ -7,7 +7,7 @@
  * Copyright 2002-2003 Raphael Junqueira
  * Copyright 2004 Christian Costa
  * Copyright 2005 Oliver Stieber
- * Copyright 2006-2008 Stefan Dösinger for CodeWeavers
+ * Copyright 2006-2008 Stefan Dösinger for CodeWeavers
  * Copyright 2007-2008 Henri Verbeet
  * Copyright 2006-2008 Roderick Colenbrander
  *
@@ -39,6 +39,53 @@ static void d3dfmt_p8_upload_palette(IWineD3DSurface *iface, CONVERT_TYPES conve
 static inline void clear_unused_channels(IWineD3DSurfaceImpl *This);
 static void surface_remove_pbo(IWineD3DSurfaceImpl *This);
 
+void surface_force_reload(IWineD3DSurface *iface)
+{
+    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
+
+    This->Flags &= ~SFLAG_ALLOCATED;
+}
+
+void surface_set_texture_name(IWineD3DSurface *iface, GLuint name)
+{
+    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
+
+    TRACE("(%p) : setting texture name %u\n", This, name);
+
+    if (!This->glDescription.textureName && name)
+    {
+        /* FIXME: We shouldn't need to remove SFLAG_INTEXTURE if the
+         * surface has no texture name yet. See if we can get rid of this. */
+        if (This->Flags & SFLAG_INTEXTURE)
+            ERR("Surface has SFLAG_INTEXTURE set, but no texture name\n");
+        IWineD3DSurface_ModifyLocation(iface, SFLAG_INTEXTURE, FALSE);
+    }
+
+    This->glDescription.textureName = name;
+    surface_force_reload(iface);
+}
+
+void surface_set_texture_target(IWineD3DSurface *iface, GLenum target)
+{
+    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
+
+    TRACE("(%p) : setting target %#x\n", This, target);
+
+    if (This->glDescription.target != target)
+    {
+        if (target == GL_TEXTURE_RECTANGLE_ARB)
+        {
+            This->Flags &= ~SFLAG_NORMCOORD;
+        }
+        else if (This->glDescription.target == GL_TEXTURE_RECTANGLE_ARB)
+        {
+            This->Flags |= SFLAG_NORMCOORD;
+        }
+    }
+    This->glDescription.target = target;
+    surface_force_reload(iface);
+}
+
 static void surface_bind_and_dirtify(IWineD3DSurfaceImpl *This) {
     int active_sampler;
 
@@ -627,32 +674,6 @@ static void WINAPI IWineD3DSurfaceImpl_UnLoad(IWineD3DSurface *iface) {
    IWineD3DSurface IWineD3DSurface parts follow
    ****************************************************** */
 
-void WINAPI IWineD3DSurfaceImpl_SetGlTextureDesc(IWineD3DSurface *iface, UINT textureName, int target) {
-    IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
-    TRACE("(%p) : setting textureName %u, target %#x\n", This, textureName, target);
-    if (This->glDescription.textureName == 0 && textureName != 0) {
-        IWineD3DSurface_ModifyLocation(iface, SFLAG_INTEXTURE, FALSE);
-        if((This->Flags & SFLAG_LOCATIONS) == 0) {
-            /* In 1.0-rc4 and earlier, AddDirtyRect was called in the place of this if condition.
-             * This had the problem that a correctly set INDRAWABLE flag was removed if the PreLoad
-             * during the offscreen rendering readback triggered the creation of the GL texture.
-             * The change intended to keep the INDRAWABLE intact. To prevent unintended side effects
-             * before release, set the INSYSMEM flag like the old AddDirtyRect did.
-             */
-            WARN("Wine 1.0 safety path hit\n");
-            This->Flags |= SFLAG_INSYSMEM;
-        }
-    }
-    if(target == GL_TEXTURE_RECTANGLE_ARB && This->glDescription.target != target) {
-        This->Flags &= ~SFLAG_NORMCOORD;
-    } else if(This->glDescription.target == GL_TEXTURE_RECTANGLE_ARB && target != GL_TEXTURE_RECTANGLE_ARB) {
-        This->Flags |= SFLAG_NORMCOORD;
-    }
-    This->glDescription.textureName = textureName;
-    This->glDescription.target      = target;
-    This->Flags &= ~SFLAG_ALLOCATED;
-}
-
 void WINAPI IWineD3DSurfaceImpl_GetGlDesc(IWineD3DSurface *iface, glDescriptor **glDescription) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
     TRACE("(%p) : returning %p\n", This, &This->glDescription);
@@ -691,7 +712,6 @@ static void read_from_framebuffer(IWineD3DSurfaceImpl *This, CONST RECT *rect, v
         return;
     }
 
-    IWineD3DSurface_GetContainer((IWineD3DSurface *) This, &IID_IWineD3DSwapChain, (void **)&swapchain);
     /* Activate the surface. Set it up for blitting now, although not necessarily needed for LockRect.
      * Certain graphics drivers seem to dislike some enabled states when reading from opengl, the blitting usage
      * should help here. Furthermore unlockrect will need the context set up for blitting. The context manager will find
@@ -704,14 +724,8 @@ static void read_from_framebuffer(IWineD3DSurfaceImpl *This, CONST RECT *rect, v
      * There is no need to keep track of the current read buffer or reset it, every part of the code
      * that reads sets the read buffer as desired.
      */
-    if(!swapchain) {
-        /* Locking the primary render target which is not on a swapchain(=offscreen render target).
-         * Read from the back buffer
-         */
-        TRACE("Locking offscreen render target\n");
-        glReadBuffer(myDevice->offscreenBuffer);
-        srcIsUpsideDown = TRUE;
-    } else {
+    if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *) This, &IID_IWineD3DSwapChain, (void **)&swapchain)))
+    {
         GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *) This, (IWineD3DSwapChain *)swapchain);
         TRACE("Locking %#x buffer\n", buffer);
         glReadBuffer(buffer);
@@ -719,6 +733,13 @@ static void read_from_framebuffer(IWineD3DSurfaceImpl *This, CONST RECT *rect, v
 
         IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
         srcIsUpsideDown = FALSE;
+    } else {
+        /* Locking the primary render target which is not on a swapchain(=offscreen render target).
+         * Read from the back buffer
+         */
+        TRACE("Locking offscreen render target\n");
+        glReadBuffer(myDevice->offscreenBuffer);
+        srcIsUpsideDown = TRUE;
     }
 
     /* TODO: Get rid of the extra rectangle comparison and construction of a full surface rectangle */
@@ -889,34 +910,40 @@ static void read_from_framebuffer_texture(IWineD3DSurfaceImpl *This)
 
     d3dfmt_get_conv(This, TRUE /* We need color keying */, TRUE /* We will use textures */, &format, &internal, &type, &convert, &bpp, This->srgb);
 
-    IWineD3DSurface_GetContainer((IWineD3DSurface *) This, &IID_IWineD3DSwapChain, (void **)&swapchain);
     /* Activate the surface to read from. In some situations it isn't the currently active target(e.g. backbuffer
      * locking during offscreen rendering). RESOURCELOAD is ok because glCopyTexSubImage2D isn't affected by any
      * states in the stateblock, and no driver was found yet that had bugs in that regard.
      */
     ActivateContext(device, (IWineD3DSurface *) This, CTXUSAGE_RESOURCELOAD);
     surface_bind_and_dirtify(This);
-    ENTER_GL();
 
+    ENTER_GL();
     glGetIntegerv(GL_READ_BUFFER, &prevRead);
+    LEAVE_GL();
 
     /* Select the correct read buffer, and give some debug output.
      * There is no need to keep track of the current read buffer or reset it, every part of the code
      * that reads sets the read buffer as desired.
      */
-    if(!swapchain) {
-        /* Locking the primary render target which is not on a swapchain(=offscreen render target).
-         * Read from the back buffer
-         */
-        TRACE("Locking offscreen render target\n");
-        glReadBuffer(device->offscreenBuffer);
-    } else {
+    if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *)This, &IID_IWineD3DSwapChain, (void **)&swapchain)))
+    {
         GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *) This, (IWineD3DSwapChain *)swapchain);
         TRACE("Locking %#x buffer\n", buffer);
+
+        ENTER_GL();
         glReadBuffer(buffer);
         checkGLcall("glReadBuffer");
+        LEAVE_GL();
 
         IWineD3DSwapChain_Release((IWineD3DSwapChain *) swapchain);
+    } else {
+        /* Locking the primary render target which is not on a swapchain(=offscreen render target).
+         * Read from the back buffer
+         */
+        TRACE("Locking offscreen render target\n");
+        ENTER_GL();
+        glReadBuffer(device->offscreenBuffer);
+        LEAVE_GL();
     }
 
     if(!(This->Flags & SFLAG_ALLOCATED)) {
@@ -926,6 +953,7 @@ static void read_from_framebuffer_texture(IWineD3DSurfaceImpl *This)
 
     clear_unused_channels(This);
 
+    ENTER_GL();
     /* If !SrcIsUpsideDown we should flip the surface.
      * This can be done using glCopyTexSubImage2D but this
      * is VERY slow, so don't do that. We should prevent
@@ -1081,7 +1109,7 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LockRect(IWineD3DSurface *iface, WINED
             case RTL_AUTO:
             case RTL_READDRAW:
             case RTL_READTEX:
-                IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, pRect);
+                IWineD3DSurface_LoadLocation(iface, SFLAG_INSYSMEM, pass_rect);
                 break;
 
             case RTL_DISABLE:
@@ -1149,7 +1177,7 @@ lock_end:
         IWineD3DSurface_AddDirtyRect(iface, pRect);
 
         /** Dirtify Container if needed */
-        if (WINED3D_OK == IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&pBaseTexture) && pBaseTexture != NULL) {
+        if (SUCCEEDED(IWineD3DSurface_GetContainer(iface, &IID_IWineD3DBaseTexture, (void **)&pBaseTexture))) {
             TRACE("Making container dirty\n");
             IWineD3DBaseTexture_SetDirty(pBaseTexture, TRUE);
             IWineD3DBaseTexture_Release(pBaseTexture);
@@ -1173,19 +1201,18 @@ static void flush_to_framebuffer_drawpixels(IWineD3DSurfaceImpl *This, GLenum fm
     ActivateContext(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
     ENTER_GL();
 
-    IWineD3DSurface_GetContainer((IWineD3DSurface *) This, &IID_IWineD3DSwapChain, (void **)&swapchain);
-    if(!swapchain) {
-        /* Primary offscreen render target */
-        TRACE("Offscreen render target\n");
-        glDrawBuffer(myDevice->offscreenBuffer);
-        checkGLcall("glDrawBuffer(myDevice->offscreenBuffer)");
-    } else {
+    if (SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface *)This, &IID_IWineD3DSwapChain, (void **)&swapchain))) {
         GLenum buffer = surface_get_gl_buffer((IWineD3DSurface *) This, (IWineD3DSwapChain *)swapchain);
         TRACE("Unlocking %#x buffer\n", buffer);
         glDrawBuffer(buffer);
         checkGLcall("glDrawBuffer");
 
         IWineD3DSwapChain_Release((IWineD3DSwapChain *)swapchain);
+    } else {
+        /* Primary offscreen render target */
+        TRACE("Offscreen render target\n");
+        glDrawBuffer(myDevice->offscreenBuffer);
+        checkGLcall("glDrawBuffer(myDevice->offscreenBuffer)");
     }
 
     glGetIntegerv(GL_PACK_SWAP_BYTES, &prev_store);
@@ -1612,13 +1639,6 @@ HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_
 
         case WINED3DFMT_V8U8:
             if(GL_SUPPORT(NV_TEXTURE_SHADER3)) break;
-            else if(GL_SUPPORT(ATI_ENVMAP_BUMPMAP)) {
-                *format = GL_DUDV_ATI;
-                *internal = GL_DU8DV8_ATI;
-                *type = GL_BYTE;
-                /* No conversion - Just change the gl type */
-                break;
-            }
             *convert = CONVERT_V8U8;
             *format = GL_BGR;
             *internal = GL_RGB8;
@@ -1651,7 +1671,6 @@ HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_
                  * 4th component, which is returned as alpha
                  */
             } else {
-                /* Not supported by GL_ATI_envmap_bumpmap */
                 *format = GL_BGRA;
                 *internal = GL_RGB8;
                 *type = GL_UNSIGNED_INT_8_8_8_8_REV;
@@ -1665,7 +1684,6 @@ HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_
             *internal = GL_RGBA8;
             *type = GL_UNSIGNED_BYTE;
             *target_bpp = 4;
-            /* Not supported by GL_ATI_envmap_bumpmap */
             break;
 
         case WINED3DFMT_V16U16:
@@ -1675,9 +1693,6 @@ HRESULT d3dfmt_get_conv(IWineD3DSurfaceImpl *This, BOOL need_alpha_ck, BOOL use_
             *internal = GL_RGB16_EXT;
             *type = GL_UNSIGNED_SHORT;
             *target_bpp = 6;
-            /* What should I do here about GL_ATI_envmap_bumpmap?
-             * Convert it or allow data loss by loading it into a 8 bit / channel texture?
-             */
             break;
 
         case WINED3DFMT_A4L4:
@@ -2196,7 +2211,6 @@ static void d3dfmt_p8_upload_palette(IWineD3DSurface *iface, CONVERT_TYPES conve
         GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, device->paletteConversionShader));
 
         GL_EXTCALL(glActiveTextureARB(GL_TEXTURE1));
-        glEnable(GL_TEXTURE_1D);
         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
 
         glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -2358,13 +2372,24 @@ static void WINAPI IWineD3DSurfaceImpl_BindTexture(IWineD3DSurface *iface) {
 
         ENTER_GL();
 
-        glEnable(This->glDescription.target);
-
         if (!This->glDescription.level) {
             if (!This->glDescription.textureName) {
                 glGenTextures(1, &This->glDescription.textureName);
                 checkGLcall("glGenTextures");
                 TRACE("Surface %p given name %d\n", This, This->glDescription.textureName);
+
+                glBindTexture(This->glDescription.target, This->glDescription.textureName);
+                checkGLcall("glBindTexture");
+                glTexParameteri(This->glDescription.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);
+                checkGLcall("glTexParameteri(dimension, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)");
+                glTexParameteri(This->glDescription.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);
+                checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MIN_FILTER, GL_NEAREST)");
+                glTexParameteri(This->glDescription.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+                checkGLcall("glTexParameteri(dimension, GL_TEXTURE_MAG_FILTER, GL_NEAREST)");
             }
             /* This is where we should be reducing the amount of GLMemoryUsed */
         } else if (This->glDescription.textureName) {
@@ -2418,7 +2443,6 @@ HRESULT WINAPI IWineD3DSurfaceImpl_SaveSnapshot(IWineD3DSurface *iface, const ch
         GLint prevRead;
         ENTER_GL();
         TRACE("(%p) Reading render target into texture\n", This);
-        glEnable(GL_TEXTURE_2D);
 
         glGenTextures(1, &tmpTexture);
         glBindTexture(GL_TEXTURE_2D, tmpTexture);
@@ -2784,10 +2808,6 @@ static inline void fb_copy_to_texture_direct(IWineD3DSurfaceImpl *This, IWineD3D
     IWineD3DSurface_PreLoad((IWineD3DSurface *) This);
     ENTER_GL();
 
-    /* TODO: Do we need GL_TEXTURE_2D enabled fpr copyteximage? */
-    glEnable(This->glDescription.target);
-    checkGLcall("glEnable(This->glDescription.target)");
-
     /* Bind the target texture */
     glBindTexture(This->glDescription.target, This->glDescription.textureName);
     checkGLcall("glBindTexture");
@@ -2857,10 +2877,6 @@ static inline void fb_copy_to_texture_direct(IWineD3DSurfaceImpl *This, IWineD3D
     }
     vcheckGLcall("glCopyTexSubImage2D");
 
-    /* Leave the opengl state valid for blitting */
-    glDisable(This->glDescription.target);
-    checkGLcall("glDisable(This->glDescription.target)");
-
     LEAVE_GL();
 }
 
@@ -3446,6 +3462,12 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
         /* Activate the destination context, set it up for blitting */
         ActivateContext(myDevice, (IWineD3DSurface *) This, CTXUSAGE_BLIT);
 
+        /* The coordinates of the ddraw front buffer are always fullscreen ('screen coordinates',
+         * while OpenGL coordinates are window relative.
+         * Also beware of the origin difference(top left vs bottom left).
+         * Also beware that the front buffer's surface size is screen width x screen height,
+         * whereas the real gl drawable size is the size of the window.
+         */
         if (dstSwapchain && (IWineD3DSurface *)This == dstSwapchain->frontBuffer) {
             RECT windowsize;
             POINT offset = {0,0};
@@ -3458,10 +3480,11 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
             rect.y1 += This->currentDesc.Height - h; rect.y2 += This->currentDesc.Height - h;
         }
 
-        ENTER_GL();
         myDevice->blitter->set_shader((IWineD3DDevice *) myDevice, Src->resource.format,
                                        Src->glDescription.target, Src->pow2Width, Src->pow2Height);
 
+        ENTER_GL();
+
         /* Bind the texture */
         glBindTexture(Src->glDescription.target, Src->glDescription.textureName);
         checkGLcall("glBindTexture");
@@ -3528,8 +3551,6 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
 
         glBindTexture(Src->glDescription.target, 0);
         checkGLcall("glBindTexture(Src->glDescription.target, 0)");
-        /* Leave the opengl state valid for blitting */
-        myDevice->blitter->unset_shader((IWineD3DDevice *) myDevice);
 
         /* Restore the color key parameters */
         Src->CKeyFlags = oldCKeyFlags;
@@ -3541,6 +3562,9 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *This, RECT *
 
         LEAVE_GL();
 
+        /* Leave the opengl state valid for blitting */
+        myDevice->blitter->unset_shader((IWineD3DDevice *) myDevice);
+
         /* Flush in case the drawable is used by multiple GL contexts */
         if(dstSwapchain && (This == (IWineD3DSurfaceImpl *) dstSwapchain->frontBuffer || dstSwapchain->num_contexts >= 2))
             glFlush();
@@ -3918,6 +3942,143 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_PrivateSetup(IWineD3DSurface *iface) {
     return WINED3D_OK;
 }
 
+struct depth_blt_info
+{
+    GLenum binding;
+    GLenum bind_target;
+    enum tex_types tex_type;
+    GLfloat coords[4][3];
+};
+
+static void surface_get_depth_blt_info(GLenum target, GLsizei w, GLsizei h, struct depth_blt_info *info)
+{
+    GLfloat (*coords)[3] = info->coords;
+
+    switch (target)
+    {
+        default:
+            FIXME("Unsupported texture target %#x\n", target);
+            /* Fall back to GL_TEXTURE_2D */
+        case GL_TEXTURE_2D:
+            info->binding = GL_TEXTURE_BINDING_2D;
+            info->bind_target = GL_TEXTURE_2D;
+            info->tex_type = tex_2d;
+            coords[0][0] = 0.0f;    coords[0][1] = 1.0f;    coords[0][2] = 0.0f;
+            coords[1][0] = 1.0f;    coords[1][1] = 1.0f;    coords[1][2] = 0.0f;
+            coords[2][0] = 0.0f;    coords[2][1] = 0.0f;    coords[2][2] = 0.0f;
+            coords[3][0] = 1.0f;    coords[3][1] = 0.0f;    coords[3][2] = 0.0f;
+            break;
+
+        case GL_TEXTURE_RECTANGLE_ARB:
+            info->binding = GL_TEXTURE_BINDING_RECTANGLE_ARB;
+            info->bind_target = GL_TEXTURE_RECTANGLE_ARB;
+            info->tex_type = tex_rect;
+            coords[0][0] = 0.0f;    coords[0][1] = h;       coords[0][2] = 0.0f;
+            coords[1][0] = w;       coords[1][1] = h;       coords[1][2] = 0.0f;
+            coords[2][0] = 0.0f;    coords[2][1] = 0.0f;    coords[2][2] = 0.0f;
+            coords[3][0] = w;       coords[3][1] = 0.0f;    coords[3][2] = 0.0f;
+            break;
+
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+            info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
+            info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+            info->tex_type = tex_cube;
+            coords[0][0] =  1.0f;   coords[0][1] = -1.0f;   coords[0][2] =  1.0f;
+            coords[1][0] =  1.0f;   coords[1][1] = -1.0f;   coords[1][2] = -1.0f;
+            coords[2][0] =  1.0f;   coords[2][1] =  1.0f;   coords[2][2] =  1.0f;
+            coords[3][0] =  1.0f;   coords[3][1] =  1.0f;   coords[3][2] = -1.0f;
+
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+            info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
+            info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+            info->tex_type = tex_cube;
+            coords[0][0] = -1.0f;   coords[0][1] = -1.0f;   coords[0][2] = -1.0f;
+            coords[1][0] = -1.0f;   coords[1][1] = -1.0f;   coords[1][2] =  1.0f;
+            coords[2][0] = -1.0f;   coords[2][1] =  1.0f;   coords[2][2] = -1.0f;
+            coords[3][0] = -1.0f;   coords[3][1] =  1.0f;   coords[3][2] =  1.0f;
+
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+            info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
+            info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+            info->tex_type = tex_cube;
+            coords[0][0] = -1.0f;   coords[0][1] =  1.0f;   coords[0][2] =  1.0f;
+            coords[1][0] =  1.0f;   coords[1][1] =  1.0f;   coords[1][2] =  1.0f;
+            coords[2][0] = -1.0f;   coords[2][1] =  1.0f;   coords[2][2] = -1.0f;
+            coords[3][0] =  1.0f;   coords[3][1] =  1.0f;   coords[3][2] = -1.0f;
+
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+            info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
+            info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+            info->tex_type = tex_cube;
+            coords[0][0] = -1.0f;   coords[0][1] = -1.0f;   coords[0][2] = -1.0f;
+            coords[1][0] =  1.0f;   coords[1][1] = -1.0f;   coords[1][2] = -1.0f;
+            coords[2][0] = -1.0f;   coords[2][1] = -1.0f;   coords[2][2] =  1.0f;
+            coords[3][0] =  1.0f;   coords[3][1] = -1.0f;   coords[3][2] =  1.0f;
+
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+            info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
+            info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+            info->tex_type = tex_cube;
+            coords[0][0] = -1.0f;   coords[0][1] = -1.0f;   coords[0][2] =  1.0f;
+            coords[1][0] =  1.0f;   coords[1][1] = -1.0f;   coords[1][2] =  1.0f;
+            coords[2][0] = -1.0f;   coords[2][1] =  1.0f;   coords[2][2] =  1.0f;
+            coords[3][0] =  1.0f;   coords[3][1] =  1.0f;   coords[3][2] =  1.0f;
+
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+            info->binding = GL_TEXTURE_BINDING_CUBE_MAP_ARB;
+            info->bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+            info->tex_type = tex_cube;
+            coords[0][0] =  1.0f;   coords[0][1] = -1.0f;   coords[0][2] = -1.0f;
+            coords[1][0] = -1.0f;   coords[1][1] = -1.0f;   coords[1][2] = -1.0f;
+            coords[2][0] =  1.0f;   coords[2][1] =  1.0f;   coords[2][2] = -1.0f;
+            coords[3][0] = -1.0f;   coords[3][1] =  1.0f;   coords[3][2] = -1.0f;
+    }
+}
+
+static void surface_depth_blt(IWineD3DSurfaceImpl *This, GLuint texture, GLsizei w, GLsizei h, GLenum target)
+{
+    IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    struct depth_blt_info info;
+    GLint old_binding = 0;
+
+    glPushAttrib(GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_VIEWPORT_BIT);
+
+    glDisable(GL_CULL_FACE);
+    glEnable(GL_BLEND);
+    glDisable(GL_ALPHA_TEST);
+    glDisable(GL_SCISSOR_TEST);
+    glDisable(GL_STENCIL_TEST);
+    glEnable(GL_DEPTH_TEST);
+    glDepthFunc(GL_ALWAYS);
+    glDepthMask(GL_TRUE);
+    glBlendFunc(GL_ZERO, GL_ONE);
+    glViewport(0, 0, w, h);
+
+    surface_get_depth_blt_info(target, w, h, &info);
+    GL_EXTCALL(glActiveTextureARB(GL_TEXTURE0_ARB));
+    glGetIntegerv(info.binding, &old_binding);
+    glBindTexture(info.bind_target, texture);
+
+    device->shader_backend->shader_select_depth_blt((IWineD3DDevice *)device, info.tex_type);
+
+    glBegin(GL_TRIANGLE_STRIP);
+    glTexCoord3fv(info.coords[0]);
+    glVertex2f(-1.0f, -1.0f);
+    glTexCoord3fv(info.coords[1]);
+    glVertex2f(1.0f, -1.0f);
+    glTexCoord3fv(info.coords[2]);
+    glVertex2f(-1.0f, 1.0f);
+    glTexCoord3fv(info.coords[3]);
+    glVertex2f(1.0f, 1.0f);
+    glEnd();
+
+    glBindTexture(info.bind_target, old_binding);
+
+    glPopAttrib();
+
+    device->shader_backend->shader_deselect_depth_blt((IWineD3DDevice *)device);
+}
+
 void surface_modify_ds_location(IWineD3DSurface *iface, DWORD location) {
     IWineD3DSurfaceImpl *This = (IWineD3DSurfaceImpl *)iface;
 
@@ -3953,6 +4114,7 @@ void surface_load_ds_location(IWineD3DSurface *iface, DWORD location) {
     if (location == SFLAG_DS_OFFSCREEN) {
         if (This->Flags & SFLAG_DS_ONSCREEN) {
             GLint old_binding = 0;
+            GLenum bind_target;
 
             TRACE("(%p) Copying onscreen depth buffer to depth texture\n", This);
 
@@ -3965,9 +4127,15 @@ void surface_load_ds_location(IWineD3DSurface *iface, DWORD location) {
             /* 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));
-            glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
-            glBindTexture(GL_TEXTURE_2D, device->depth_blt_texture);
-            glCopyTexImage2D(This->glDescription.target,
+            if (This->glDescription.target == GL_TEXTURE_RECTANGLE_ARB) {
+                glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, &old_binding);
+                bind_target = GL_TEXTURE_RECTANGLE_ARB;
+            } else {
+                glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_binding);
+                bind_target = GL_TEXTURE_2D;
+            }
+            glBindTexture(bind_target, device->depth_blt_texture);
+            glCopyTexImage2D(bind_target,
                     This->glDescription.level,
                     This->glDescription.glFormatInternal,
                     0,
@@ -3975,10 +4143,10 @@ void surface_load_ds_location(IWineD3DSurface *iface, DWORD location) {
                     This->currentDesc.Width,
                     This->currentDesc.Height,
                     0);
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-            glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
-            glBindTexture(GL_TEXTURE_2D, old_binding);
+            glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+            glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+            glTexParameteri(bind_target, GL_DEPTH_TEXTURE_MODE_ARB, GL_LUMINANCE);
+            glBindTexture(bind_target, old_binding);
 
             /* Setup the destination */
             if (!device->depth_blt_rb) {
@@ -4001,7 +4169,7 @@ void surface_load_ds_location(IWineD3DSurface *iface, DWORD location) {
             context_attach_depth_stencil_fbo(device, GL_FRAMEBUFFER_EXT, iface, FALSE);
 
             /* Do the actual blit */
-            depth_blt((IWineD3DDevice *)device, device->depth_blt_texture, This->currentDesc.Width, This->currentDesc.Height);
+            surface_depth_blt(This, device->depth_blt_texture, This->currentDesc.Width, This->currentDesc.Height, bind_target);
             checkGLcall("depth_blt");
 
             if (device->activeContext->current_fbo) {
@@ -4023,7 +4191,7 @@ void surface_load_ds_location(IWineD3DSurface *iface, DWORD location) {
 
             GL_EXTCALL(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0));
             checkGLcall("glBindFramebuffer()");
-            depth_blt((IWineD3DDevice *)device, This->glDescription.textureName, This->currentDesc.Width, This->currentDesc.Height);
+            surface_depth_blt(This, This->glDescription.textureName, This->currentDesc.Width, This->currentDesc.Height, This->glDescription.target);
             checkGLcall("depth_blt");
 
             if (device->activeContext->current_fbo) {
@@ -4097,13 +4265,30 @@ struct coords {
     GLfloat x, y, z;
 };
 
+struct float_rect
+{
+    float l;
+    float t;
+    float r;
+    float b;
+};
+
+static inline void cube_coords_float(const RECT *r, UINT w, UINT h, struct float_rect *f)
+{
+    f->l = ((r->left * 2.0f) / w) - 1.0f;
+    f->t = ((r->top * 2.0f) / h) - 1.0f;
+    f->r = ((r->right * 2.0f) / w) - 1.0f;
+    f->b = ((r->bottom * 2.0f) / h) - 1.0f;
+}
+
 static inline void surface_blt_to_drawable(IWineD3DSurfaceImpl *This, const RECT *rect_in) {
     struct coords coords[4];
     RECT rect;
-    IWineD3DSwapChain *swapchain = NULL;
-    IWineD3DBaseTexture *texture = NULL;
-    HRESULT hr;
+    IWineD3DSwapChain *swapchain;
+    IWineD3DBaseTexture *texture;
     IWineD3DDeviceImpl *device = This->resource.wineD3DDevice;
+    GLenum bind_target;
+    struct float_rect f;
 
     if(rect_in) {
         rect = *rect_in;
@@ -4114,148 +4299,136 @@ static inline void surface_blt_to_drawable(IWineD3DSurfaceImpl *This, const RECT
         rect.bottom = This->currentDesc.Height;
     }
 
-    ActivateContext(device, (IWineD3DSurface*)This, CTXUSAGE_BLIT);
-    ENTER_GL();
-
-    if(This->glDescription.target == GL_TEXTURE_RECTANGLE_ARB) {
-        glEnable(GL_TEXTURE_RECTANGLE_ARB);
-        checkGLcall("glEnable(GL_TEXTURE_RECTANGLE_ARB)");
-        glBindTexture(GL_TEXTURE_RECTANGLE_ARB, This->glDescription.textureName);
-        checkGLcall("GL_TEXTURE_RECTANGLE_ARB, This->glDescription.textureName)");
-        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-        checkGLcall("glTexParameteri");
-        glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-        checkGLcall("glTexParameteri");
-
-        coords[0].x = rect.left;
-        coords[0].z = 0;
-
-        coords[1].x = rect.left;
-        coords[1].z = 0;
+    switch(This->glDescription.target)
+    {
+        case GL_TEXTURE_2D:
+            bind_target = GL_TEXTURE_2D;
 
-        coords[2].x = rect.right;
-        coords[2].z = 0;
+            coords[0].x = (float)rect.left / This->pow2Width;
+            coords[0].y = (float)rect.top / This->pow2Height;
+            coords[0].z = 0;
 
-        coords[3].x = rect.right;
-        coords[3].z = 0;
+            coords[1].x = (float)rect.left / This->pow2Width;
+            coords[1].y = (float)rect.bottom / This->pow2Height;
+            coords[1].z = 0;
 
-        coords[0].y = rect.top;
-        coords[1].y = rect.bottom;
-        coords[2].y = rect.bottom;
-        coords[3].y = rect.top;
-    } else if(This->glDescription.target == GL_TEXTURE_2D) {
-        glEnable(GL_TEXTURE_2D);
-        checkGLcall("glEnable(GL_TEXTURE_2D)");
-        glBindTexture(GL_TEXTURE_2D, This->glDescription.textureName);
-        checkGLcall("GL_TEXTURE_2D, This->glDescription.textureName)");
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-        checkGLcall("glTexParameteri");
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-        checkGLcall("glTexParameteri");
+            coords[2].x = (float)rect.right / This->pow2Width;
+            coords[2].y = (float)rect.bottom / This->pow2Height;
+            coords[2].z = 0;
 
-        coords[0].x = (float)rect.left   / This->pow2Width;
-        coords[0].z = 0;
+            coords[3].x = (float)rect.right / This->pow2Width;
+            coords[3].y = (float)rect.top / This->pow2Height;
+            coords[3].z = 0;
+            break;
 
-        coords[1].x = (float)rect.left   / This->pow2Width;
-        coords[1].z = 0;
+        case GL_TEXTURE_RECTANGLE_ARB:
+            bind_target = GL_TEXTURE_RECTANGLE_ARB;
+            coords[0].x = rect.left;    coords[0].y = rect.top;     coords[0].z = 0;
+            coords[1].x = rect.left;    coords[1].y = rect.bottom;  coords[1].z = 0;
+            coords[2].x = rect.right;   coords[2].y = rect.bottom;  coords[2].z = 0;
+            coords[3].x = rect.right;   coords[3].y = rect.top;     coords[3].z = 0;
+            break;
 
-        coords[2].x = (float)rect.right  / This->pow2Width;
-        coords[2].z = 0;
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
+            bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+            cube_coords_float(&rect, This->pow2Width, This->pow2Height, &f);
+            coords[0].x =    1; coords[0].y = -f.t; coords[0].z = -f.l;
+            coords[1].x =    1; coords[1].y = -f.b; coords[1].z = -f.l;
+            coords[2].x =    1; coords[2].y = -f.b; coords[2].z = -f.r;
+            coords[3].x =    1; coords[3].y = -f.t; coords[3].z = -f.r;
+            break;
 
-        coords[3].x = (float)rect.right  / This->pow2Width;
-        coords[3].z = 0;
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
+            bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+            cube_coords_float(&rect, This->pow2Width, This->pow2Height, &f);
+            coords[0].x =   -1; coords[0].y = -f.t; coords[0].z =  f.l;
+            coords[1].x =   -1; coords[1].y = -f.b; coords[1].z =  f.l;
+            coords[2].x =   -1; coords[2].y = -f.b; coords[2].z =  f.r;
+            coords[3].x =   -1; coords[3].y = -f.t; coords[3].z =  f.r;
+            break;
 
-        coords[0].y = (float)rect.top    / This->pow2Height;
-        coords[1].y = (float)rect.bottom / This->pow2Height;
-        coords[2].y = (float)rect.bottom / This->pow2Height;
-        coords[3].y = (float)rect.top    / This->pow2Height;
-    } else {
-        /* Must be a cube map */
-        glEnable(GL_TEXTURE_CUBE_MAP_ARB);
-        checkGLcall("glEnable(GL_TEXTURE_CUBE_MAP_ARB)");
-        glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, This->glDescription.textureName);
-        checkGLcall("GL_TEXTURE_CUBE_MAP_ARB, This->glDescription.textureName)");
-        glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-        checkGLcall("glTexParameteri");
-        glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-        checkGLcall("glTexParameteri");
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
+            bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+            cube_coords_float(&rect, This->pow2Width, This->pow2Height, &f);
+            coords[0].x =  f.l; coords[0].y =    1; coords[0].z =  f.t;
+            coords[1].x =  f.l; coords[1].y =    1; coords[1].z =  f.b;
+            coords[2].x =  f.r; coords[2].y =    1; coords[2].z =  f.b;
+            coords[3].x =  f.r; coords[3].y =    1; coords[3].z =  f.t;
+            break;
 
-        switch(This->glDescription.target) {
-            case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
-                coords[0].x =  1;   coords[0].y = -1;   coords[0].z =  1;
-                coords[1].x =  1;   coords[1].y =  1;   coords[1].z =  1;
-                coords[2].x =  1;   coords[2].y =  1;   coords[2].z = -1;
-                coords[3].x =  1;   coords[3].y = -1;   coords[3].z = -1;
-                break;
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
+            bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+            cube_coords_float(&rect, This->pow2Width, This->pow2Height, &f);
+            coords[0].x =  f.l; coords[0].y =   -1; coords[0].z = -f.t;
+            coords[1].x =  f.l; coords[1].y =   -1; coords[1].z = -f.b;
+            coords[2].x =  f.r; coords[2].y =   -1; coords[2].z = -f.b;
+            coords[3].x =  f.r; coords[3].y =   -1; coords[3].z = -f.t;
+            break;
 
-            case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
-                coords[0].x = -1;   coords[0].y = -1;   coords[0].z =  1;
-                coords[1].x = -1;   coords[1].y =  1;   coords[1].z =  1;
-                coords[2].x = -1;   coords[2].y =  1;   coords[2].z = -1;
-                coords[3].x = -1;   coords[3].y = -1;   coords[3].z = -1;
-                break;
+        case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
+            bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+            cube_coords_float(&rect, This->pow2Width, This->pow2Height, &f);
+            coords[0].x =  f.l; coords[0].y = -f.t; coords[0].z =    1;
+            coords[1].x =  f.l; coords[1].y = -f.b; coords[1].z =    1;
+            coords[2].x =  f.r; coords[2].y = -f.b; coords[2].z =    1;
+            coords[3].x =  f.r; coords[3].y = -f.t; coords[3].z =    1;
+            break;
 
-            case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
-                coords[0].x = -1;   coords[0].y =  1;   coords[0].z =  1;
-                coords[1].x =  1;   coords[1].y =  1;   coords[1].z =  1;
-                coords[2].x =  1;   coords[2].y =  1;   coords[2].z = -1;
-                coords[3].x = -1;   coords[3].y =  1;   coords[3].z = -1;
-                break;
+        case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+            bind_target = GL_TEXTURE_CUBE_MAP_ARB;
+            cube_coords_float(&rect, This->pow2Width, This->pow2Height, &f);
+            coords[0].x = -f.l; coords[0].y = -f.t; coords[0].z =   -1;
+            coords[1].x = -f.l; coords[1].y = -f.b; coords[1].z =   -1;
+            coords[2].x = -f.r; coords[2].y = -f.b; coords[2].z =   -1;
+            coords[3].x = -f.r; coords[3].y = -f.t; coords[3].z =   -1;
+            break;
 
-            case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
-                coords[0].x = -1;   coords[0].y = -1;   coords[0].z =  1;
-                coords[1].x =  1;   coords[1].y = -1;   coords[1].z =  1;
-                coords[2].x =  1;   coords[2].y = -1;   coords[2].z = -1;
-                coords[3].x = -1;   coords[3].y = -1;   coords[3].z = -1;
-                break;
+        default:
+            ERR("Unexpected texture target %#x\n", This->glDescription.target);
+            return;
+    }
 
-            case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
-                coords[0].x = -1;   coords[0].y = -1;   coords[0].z =  1;
-                coords[1].x =  1;   coords[1].y = -1;   coords[1].z =  1;
-                coords[2].x =  1;   coords[2].y = -1;   coords[2].z =  1;
-                coords[3].x = -1;   coords[3].y = -1;   coords[3].z =  1;
-                break;
+    ActivateContext(device, (IWineD3DSurface*)This, CTXUSAGE_BLIT);
+    ENTER_GL();
 
-            case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
-                coords[0].x = -1;   coords[0].y = -1;   coords[0].z = -1;
-                coords[1].x =  1;   coords[1].y = -1;   coords[1].z = -1;
-                coords[2].x =  1;   coords[2].y = -1;   coords[2].z = -1;
-                coords[3].x = -1;   coords[3].y = -1;   coords[3].z = -1;
-                break;
+    glEnable(bind_target);
+    checkGLcall("glEnable(bind_target)");
+    glBindTexture(bind_target, This->glDescription.textureName);
+    checkGLcall("bind_target, This->glDescription.textureName)");
+    glTexParameteri(bind_target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+    checkGLcall("glTexParameteri");
+    glTexParameteri(bind_target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+    checkGLcall("glTexParameteri");
 
-            default:
-                ERR("Unexpected texture target\n");
-                LEAVE_GL();
-                return;
-        }
+    if (device->render_offscreen)
+    {
+        LONG tmp = rect.top;
+        rect.top = rect.bottom;
+        rect.bottom = tmp;
     }
 
     glBegin(GL_QUADS);
     glTexCoord3fv(&coords[0].x);
-    glVertex2i(rect.left, device->render_offscreen ? rect.bottom : rect.top);
+    glVertex2i(rect.left, rect.top);
 
     glTexCoord3fv(&coords[1].x);
-    glVertex2i(rect.left, device->render_offscreen ? rect.top : rect.bottom);
+    glVertex2i(rect.left, rect.bottom);
 
     glTexCoord3fv(&coords[2].x);
-    glVertex2i(rect.right, device->render_offscreen ? rect.top : rect.bottom);
+    glVertex2i(rect.right, rect.bottom);
 
     glTexCoord3fv(&coords[3].x);
-    glVertex2i(rect.right, device->render_offscreen ? rect.bottom : rect.top);
+    glVertex2i(rect.right, rect.top);
     glEnd();
     checkGLcall("glEnd");
 
-    if(This->glDescription.target != GL_TEXTURE_2D) {
-        glDisable(GL_TEXTURE_CUBE_MAP_ARB);
-        checkGLcall("glDisable(GL_TEXTURE_CUBE_MAP_ARB)");
-    } else {
-        glDisable(GL_TEXTURE_2D);
-        checkGLcall("glDisable(GL_TEXTURE_2D)");
-    }
+    glDisable(bind_target);
+    checkGLcall("glDisable(bind_target)");
+
     LEAVE_GL();
 
-    hr = IWineD3DSurface_GetContainer((IWineD3DSurface*)This, &IID_IWineD3DSwapChain, (void **) &swapchain);
-    if(hr == WINED3D_OK && swapchain) {
+    if(SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface*)This, &IID_IWineD3DSwapChain, (void **) &swapchain)))
+    {
         /* Make sure to flush the buffers. This is needed in apps like Red Alert II and Tiberian SUN that use multiple WGL contexts. */
         if(((IWineD3DSwapChainImpl*)swapchain)->frontBuffer == (IWineD3DSurface*)This ||
            ((IWineD3DSwapChainImpl*)swapchain)->num_contexts >= 2)
@@ -4266,8 +4439,8 @@ static inline void surface_blt_to_drawable(IWineD3DSurfaceImpl *This, const RECT
         /* We changed the filtering settings on the texture. Inform the container about this to get the filters
          * reset properly next draw
          */
-        hr = IWineD3DSurface_GetContainer((IWineD3DSurface*)This, &IID_IWineD3DBaseTexture, (void **) &texture);
-        if(hr == WINED3D_OK && texture) {
+        if(SUCCEEDED(IWineD3DSurface_GetContainer((IWineD3DSurface*)This, &IID_IWineD3DBaseTexture, (void **) &texture)))
+        {
             ((IWineD3DBaseTextureImpl *) texture)->baseTexture.states[WINED3DTEXSTA_MAGFILTER] = WINED3DTEXF_POINT;
             ((IWineD3DBaseTextureImpl *) texture)->baseTexture.states[WINED3DTEXSTA_MINFILTER] = WINED3DTEXF_POINT;
             ((IWineD3DBaseTextureImpl *) texture)->baseTexture.states[WINED3DTEXSTA_MIPFILTER] = WINED3DTEXF_NONE;
@@ -4402,7 +4575,6 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, D
 
             if(!device->isInDraw) ActivateContext(device, device->lastActiveRenderTarget, CTXUSAGE_RESOURCELOAD);
             surface_bind_and_dirtify(This);
-            ENTER_GL();
 
             /* The only place where LoadTexture() might get called when isInDraw=1
              * is ActivateContext where lastActiveRenderTarget is preloaded.
@@ -4454,7 +4626,9 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, D
             }
 
             /* Make sure the correct pitch is used */
+            ENTER_GL();
             glPixelStorei(GL_UNPACK_ROW_LENGTH, width);
+            LEAVE_GL();
 
             if ((This->Flags & SFLAG_NONPOW2) && !(This->Flags & SFLAG_OVERSIZE)) {
                 TRACE("non power of two support\n");
@@ -4477,6 +4651,7 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_LoadLocation(IWineD3DSurface *iface, D
             }
 
             /* Restore the default pitch */
+            ENTER_GL();
             glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
             LEAVE_GL();