From 8ea451013bfdb875efe4c176a2bd8ce0514f6442 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Tue, 4 Aug 2009 23:46:28 +0200
Subject: [PATCH 5/9] WineD3D: Replace the dxVersion with behavior flags

---
 dlls/d3d8/d3d8_main.c            |    3 ++-
 dlls/d3d8/device.c               |    1 +
 dlls/d3d8/directx.c              |    8 ++++++++
 dlls/d3d9/d3d9_main.c            |    2 +-
 dlls/ddraw/direct3d.c            |    8 ++++++++
 dlls/ddraw/main.c                |    5 ++++-
 dlls/dxgi/dxgi_main.c            |    2 +-
 dlls/wined3d/buffer.c            |    2 +-
 dlls/wined3d/device.c            |   10 +++++-----
 dlls/wined3d/directx.c           |    8 +++-----
 dlls/wined3d/resource.c          |    2 +-
 dlls/wined3d/stateblock.c        |    2 +-
 dlls/wined3d/surface.c           |    6 +++---
 dlls/wined3d/vertexdeclaration.c |    1 -
 dlls/wined3d/wined3d_main.c      |   10 +++++-----
 dlls/wined3d/wined3d_private.h   |    2 +-
 include/wine/wined3d.idl         |   11 ++++++++++-
 17 files changed, 55 insertions(+), 28 deletions(-)

diff --git a/dlls/d3d8/d3d8_main.c b/dlls/d3d8/d3d8_main.c
index 8e32dc3..0dd825d 100644
--- a/dlls/d3d8/d3d8_main.c
+++ b/dlls/d3d8/d3d8_main.c
@@ -53,7 +53,8 @@ IDirect3D8* WINAPI Direct3DCreate8(UINT SDKVersion) {
 
     object->lpVtbl = &Direct3D8_Vtbl;
     object->ref = 1;
-    object->WineD3D = WineDirect3DCreate(8, (IUnknown *)object);
+    object->WineD3D = WineDirect3DCreate(WINED3D_NO_R8G8B8 | WINED3D_PRIVDATA_ADDREF | WINED3D_REQUIRE_3D,
+                                         (IUnknown *)object);
 
     TRACE("Created Direct3D object @ %p, WineObj @ %p\n", object, object->WineD3D);
     LeaveCriticalSection(&d3d8_cs);
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index ee41ab4..838c965 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -394,6 +394,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(LPDIRECT3DDEVICE8 iface
     EnterCriticalSection(&d3d8_cs);
     hrc = IWineD3DDevice_GetDeviceCaps(This->WineD3DDevice, pWineCaps);
     LeaveCriticalSection(&d3d8_cs);
+    pWineCaps->StencilCaps &= ~WINED3DSTENCILCAPS_TWOSIDED;
     WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
     HeapFree(GetProcessHeap(), 0, pWineCaps);
 
diff --git a/dlls/d3d8/directx.c b/dlls/d3d8/directx.c
index 33abe84..c113777 100644
--- a/dlls/d3d8/directx.c
+++ b/dlls/d3d8/directx.c
@@ -259,6 +259,7 @@ static HRESULT  WINAPI  IDirect3D8Impl_GetDeviceCaps(LPDIRECT3D8 iface, UINT Ada
     EnterCriticalSection(&d3d8_cs);
     hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
     LeaveCriticalSection(&d3d8_cs);
+    pWineCaps->StencilCaps &= ~WINED3DSTENCILCAPS_TWOSIDED;
     WINECAPSTOD3D8CAPS(pCaps, pWineCaps)
     HeapFree(GetProcessHeap(), 0, pWineCaps);
 
@@ -402,6 +403,13 @@ static HRESULT WINAPI IDirect3D8Impl_CreateDevice(LPDIRECT3D8 iface, UINT Adapte
         FIXME("(%p) D3D Initialization failed for WineD3DDevice %p\n", This, object->WineD3DDevice);
         HeapFree(GetProcessHeap(), 0, object);
         *ppReturnedDeviceInterface = NULL;
+    } else {
+        union {
+            float f;
+            DWORD d;
+        } tmpfloat;
+        tmpfloat.f = 0.0;
+        IWineD3DDevice_SetRenderState(object->WineD3DDevice, WINED3DRS_POINTSIZE_MIN, tmpfloat.d);
     }
 
     object->declArraySize = 16;
diff --git a/dlls/d3d9/d3d9_main.c b/dlls/d3d9/d3d9_main.c
index 40d73a5..654f7af 100644
--- a/dlls/d3d9/d3d9_main.c
+++ b/dlls/d3d9/d3d9_main.c
@@ -48,7 +48,7 @@ IDirect3D9* WINAPI Direct3DCreate9(UINT SDKVersion) {
     object->lpVtbl = &Direct3D9_Vtbl;
     object->ref = 1;
     EnterCriticalSection(&d3d9_cs);
-    object->WineD3D = WineDirect3DCreate(9, (IUnknown *)object);
+    object->WineD3D = WineDirect3DCreate(WINED3D_NO_R8G8B8 | WINED3D_PRIVDATA_ADDREF | WINED3D_REQUIRE_3D, (IUnknown *)object);
     LeaveCriticalSection(&d3d9_cs);
 
     TRACE("SDKVersion = %x, Created Direct3D object @ %p, WineObj @ %p\n", SDKVersion, object, object->WineD3D);
diff --git a/dlls/ddraw/direct3d.c b/dlls/ddraw/direct3d.c
index 9ce0d36..5711b2d 100644
--- a/dlls/ddraw/direct3d.c
+++ b/dlls/ddraw/direct3d.c
@@ -749,6 +749,10 @@ IDirect3DImpl_7_CreateDevice(IDirect3D7 *iface,
     IDirect3DDeviceImpl *object;
     IParentImpl *IndexBufferParent;
     HRESULT hr;
+    union {
+        float f;
+        DWORD d;
+    } tmpfloat;
     IDirectDrawSurfaceImpl *target = (IDirectDrawSurfaceImpl *)Surface;
     TRACE("(%p)->(%s,%p,%p)\n", iface, debugstr_guid(refiid), Surface, Device);
 
@@ -907,6 +911,10 @@ IDirect3DImpl_7_CreateDevice(IDirect3D7 *iface,
     IWineD3DDevice_SetRenderState(This->wineD3DDevice,
                                   WINED3DRS_ZENABLE,
                                   IDirect3DDeviceImpl_UpdateDepthStencil(object));
+    tmpfloat.f = 0.0;
+    IWineD3DDevice_SetRenderState(This->wineD3DDevice,
+                                  WINED3DRS_POINTSIZE_MIN,
+                                  tmpfloat.d);
     LeaveCriticalSection(&ddraw_cs);
     return D3D_OK;
 }
diff --git a/dlls/ddraw/main.c b/dlls/ddraw/main.c
index 6908a62..1343900 100644
--- a/dlls/ddraw/main.c
+++ b/dlls/ddraw/main.c
@@ -130,6 +130,7 @@ DDRAW_Create(const GUID *guid,
     IWineD3DDevice *wineD3DDevice = NULL;
     HDC hDC;
     WINED3DDEVTYPE devicetype;
+    DWORD behavior;
 
     TRACE("(%s,%p,%p)\n", debugstr_guid(guid), DD, UnkOuter);
 
@@ -208,7 +209,9 @@ DDRAW_Create(const GUID *guid,
      * but DirectDraw specific management, like DDSURFACEDESC and DDPIXELFORMAT
      * structure handling is handled in this lib.
      */
-    wineD3D = pWineDirect3DCreate(7 /* DXVersion */, (IUnknown *) This /* Parent */);
+    behavior = WINED3D_STATIC_VB_DECL | WINED3D_NO_PARTIAL_VB_LOCK | WINED3D_DDRAW_ALIGNMENT |
+               WINED3D_EXTRA_GETDC_FMTS | WINED3D_NO_DEVICE_PALETTE;
+    wineD3D = pWineDirect3DCreate(behavior, (IUnknown *) This /* Parent */);
     if(!wineD3D)
     {
         ERR("Failed to initialise WineD3D\n");
diff --git a/dlls/dxgi/dxgi_main.c b/dlls/dxgi/dxgi_main.c
index f4acef3..dca9a2d 100644
--- a/dlls/dxgi/dxgi_main.c
+++ b/dlls/dxgi/dxgi_main.c
@@ -96,7 +96,7 @@ HRESULT WINAPI CreateDXGIFactory(REFIID riid, void **factory)
     object->refcount = 1;
 
     EnterCriticalSection(&dxgi_cs);
-    object->wined3d = WineDirect3DCreate(10, (IUnknown *)object);
+    object->wined3d = WineDirect3DCreate(WINED3D_REQUIRE_3D | WINED3D_PRIVDATA_ADDREF, (IUnknown *)object);
     if(!object->wined3d)
     {
         hr = DXGI_ERROR_UNSUPPORTED;
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index 157b218..aa3f9ef 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -317,7 +317,7 @@ static BOOL buffer_find_decl(struct wined3d_buffer *This)
      */
     if (This->flags & WINED3D_BUFFER_HASDESC)
     {
-        if(((IWineD3DImpl *)device->wineD3D)->dxVersion == 7 ||
+        if((((IWineD3DImpl *)device->wineD3D)->behavior_flags & WINED3D_STATIC_VB_DECL) ||
              This->resource.format_desc->format != WINED3DFMT_VERTEXDATA) return FALSE;
     }
 
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 9035a19..fc2bf2a 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -512,7 +512,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexBuffer(IWineD3DDevice *ifac
     /* Dummy format for now */
     const struct GlPixelFormatDesc *format_desc = getFormatDescEntry(WINED3DFMT_VERTEXDATA, &This->adapter->gl_info);
     struct wined3d_buffer *object;
-    int dxVersion = ( (IWineD3DImpl *) This->wineD3D)->dxVersion;
+    DWORD behavior_flags = ( (IWineD3DImpl *) This->wineD3D)->behavior_flags;
     HRESULT hr;
     BOOL conv;
 
@@ -575,8 +575,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexBuffer(IWineD3DDevice *ifac
         TRACE("Not creating a vbo because the vertex buffer is in system memory\n");
     } else if(Usage & WINED3DUSAGE_DYNAMIC) {
         TRACE("Not creating a vbo because the buffer has dynamic usage\n");
-    } else if(dxVersion <= 7 && conv) {
-        TRACE("Not creating a vbo because dxVersion is 7 and the fvf needs conversion\n");
+    } else if((behavior_flags & WINED3D_NO_PARTIAL_VB_LOCK) && conv) {
+        TRACE("Not creating a vbo because client lib cannot do partial locks and conversion is needed\n");
     } else {
         object->flags |= WINED3D_BUFFER_CREATEBO;
     }
@@ -1659,8 +1659,8 @@ static HRESULT WINAPI IWineD3DDeviceImpl_CreateVertexDeclaration(IWineD3DDevice*
     IWineD3DVertexDeclarationImpl *object = NULL;
     HRESULT hr = WINED3D_OK;
 
-    TRACE("(%p) : directXVersion %u, elements %p, element_count %d, ppDecl=%p\n",
-            This, ((IWineD3DImpl *)This->wineD3D)->dxVersion, elements, element_count, ppVertexDeclaration);
+    TRACE("(%p) : elements %p, element_count %d, ppDecl=%p\n",
+            This, elements, element_count, ppVertexDeclaration);
 
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if(!object)
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index dc9ba04..e5bddc5 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -3663,7 +3663,7 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapt
      * So do the same as Windows drivers and pretend not to support it on dx8 and 9
      * Enable it on dx7. It will need additional checking on dx10 when we support it.
      */
-    if(This->dxVersion > 7 && CheckFormat == WINED3DFMT_R8G8B8) {
+    if((This->behavior_flags & WINED3D_NO_R8G8B8) && CheckFormat == WINED3DFMT_R8G8B8) {
         TRACE_(d3d_caps)("[FAILED]\n");
         return WINED3DERR_NOTAVAILABLE;
     }
@@ -4074,9 +4074,7 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
         pCaps->StencilCaps |= WINED3DSTENCILCAPS_DECR  |
                               WINED3DSTENCILCAPS_INCR;
     }
-    if ( This->dxVersion > 8 &&
-        ( GL_SUPPORT(EXT_STENCIL_TWO_SIDE) ||
-            GL_SUPPORT(ATI_SEPARATE_STENCIL) ) ) {
+    if (GL_SUPPORT(EXT_STENCIL_TWO_SIDE) || GL_SUPPORT(ATI_SEPARATE_STENCIL)) {
         pCaps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
     }
 
@@ -4366,7 +4364,7 @@ static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT Adapter,
     list_init(&object->resources);
     list_init(&object->shaders);
 
-    if(This->dxVersion == 7) {
+    if(This->behavior_flags & WINED3D_DDRAW_ALIGNMENT) {
         object->surface_alignment = DDRAW_PITCH_ALIGNMENT;
     } else {
         object->surface_alignment = D3D8_PITCH_ALIGNMENT;
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index 89ea7f3..da4ff98 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -186,7 +186,7 @@ HRESULT resource_get_private_data(IWineD3DResource *iface, REFGUID refguid, void
 
     if (data->flags & WINED3DSPD_IUNKNOWN) {
         *(LPUNKNOWN *)pData = data->ptr.object;
-        if(((IWineD3DImpl *) This->resource.wineD3DDevice->wineD3D)->dxVersion != 7) {
+        if(((IWineD3DImpl *) This->resource.wineD3DDevice->wineD3D)->behavior_flags & WINED3D_PRIVDATA_ADDREF) {
             /* D3D8 and D3D9 addref the private data, DDraw does not. This can't be handled in
              * ddraw because it doesn't know if the pointer returned is an IUnknown * or just a
              * Blob
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index a8e53f0..744aec6 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -1173,7 +1173,7 @@ static HRESULT  WINAPI IWineD3DStateBlockImpl_InitStartupStateBlock(IWineD3DStat
     IWineD3DDevice_SetRenderState(device, WINED3DRS_SOFTWAREVERTEXPROCESSING, FALSE);
     tmpfloat.f = 1.0f;
     IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE,                tmpfloat.d);
-    tmpfloat.f = ((IWineD3DImpl *)This->wineD3DDevice->wineD3D)->dxVersion < 9 ? 0.0f : 1.0f;
+    tmpfloat.f = 1.0f;
     IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSIZE_MIN,            tmpfloat.d);
     IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSPRITEENABLE,        FALSE);
     IWineD3DDevice_SetRenderState(device, WINED3DRS_POINTSCALEENABLE,         FALSE);
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 67a116b..86eecd1 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -1592,7 +1592,7 @@ static HRESULT WINAPI IWineD3DSurfaceImpl_GetDC(IWineD3DSurface *iface, HDC *pHD
         return WINED3DERR_INVALIDCALL;
 
     /* According to Direct3D9 docs, only these formats are supported */
-    if (((IWineD3DImpl *)This->resource.wineD3DDevice->wineD3D)->dxVersion > 7) {
+    if (!(((IWineD3DImpl *)This->resource.wineD3DDevice->wineD3D)->behavior_flags & WINED3D_EXTRA_GETDC_FMTS)) {
         if (This->resource.format_desc->format != WINED3DFMT_R5G6B5
                 && This->resource.format_desc->format != WINED3DFMT_X1R5G5B5
                 && This->resource.format_desc->format != WINED3DFMT_R8G8B8
@@ -1938,10 +1938,10 @@ static void d3dfmt_p8_init_palette(IWineD3DSurfaceImpl *This, BYTE table[256][4]
 
     if (!pal)
     {
-        UINT dxVersion = ((IWineD3DImpl *)device->wineD3D)->dxVersion;
+        DWORD behavior_flags = ((IWineD3DImpl *)device->wineD3D)->behavior_flags;
 
         /* In DirectDraw the palette is a property of the surface, there are no such things as device palettes. */
-        if (dxVersion <= 7)
+        if (behavior_flags & WINED3D_NO_DEVICE_PALETTE)
         {
             ERR("This code should never get entered for DirectDraw!, expect problems\n");
             if (index_in_alpha)
diff --git a/dlls/wined3d/vertexdeclaration.c b/dlls/wined3d/vertexdeclaration.c
index 2c2b763..2713648 100644
--- a/dlls/wined3d/vertexdeclaration.c
+++ b/dlls/wined3d/vertexdeclaration.c
@@ -197,7 +197,6 @@ HRESULT vertexdeclaration_init(IWineD3DVertexDeclarationImpl *This,
     unsigned int i;
     char isPreLoaded[MAX_STREAMS];
 
-    TRACE("(%p) : d3d version %d\n", This, ((IWineD3DImpl *)This->wineD3DDevice->wineD3D)->dxVersion);
     memset(isPreLoaded, 0, sizeof(isPreLoaded));
 
     if (TRACE_ON(d3d_decl)) {
diff --git a/dlls/wined3d/wined3d_main.c b/dlls/wined3d/wined3d_main.c
index 045eea0..7b3c023 100644
--- a/dlls/wined3d/wined3d_main.c
+++ b/dlls/wined3d/wined3d_main.c
@@ -50,27 +50,27 @@ wined3d_settings_t wined3d_settings =
     FALSE           /* Disable multisampling for now due to Nvidia driver bugs which happens for some users */
 };
 
-IWineD3D* WINAPI WineDirect3DCreate(UINT dxVersion, IUnknown *parent) {
+IWineD3D* WINAPI WineDirect3DCreate(DWORD Flags, IUnknown *parent) {
     IWineD3DImpl* object;
 
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IWineD3DImpl));
     object->lpVtbl = &IWineD3D_Vtbl;
-    object->dxVersion = dxVersion;
+    object->behavior_flags = Flags;
     object->ref = 1;
     object->parent = parent;
 
     if (!InitAdapters(object))
     {
         WARN("Failed to initialize direct3d adapters, Direct3D will not be available\n");
-        if (dxVersion > 7)
+        if (Flags & WINED3D_REQUIRE_3D)
         {
-            ERR("Direct3D%d is not available without opengl\n", dxVersion);
+            ERR("Direct3D is not available without opengl\n");
             HeapFree(GetProcessHeap(), 0, object);
             return NULL;
         }
     }
 
-    TRACE("Created WineD3D object @ %p for d3d%d support\n", object, dxVersion);
+    TRACE("Created WineD3D object @ %p\n", object);
 
     return (IWineD3D *)object;
 }
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 1a3314a..74029be 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1464,7 +1464,7 @@ typedef struct IWineD3DImpl
 
     /* WineD3D Information */
     IUnknown               *parent;
-    UINT                    dxVersion;
+    DWORD                   behavior_flags;
 
     UINT adapter_count;
     struct WineD3DAdapter adapters[1];
diff --git a/include/wine/wined3d.idl b/include/wine/wined3d.idl
index 0e87d7f..1b3ba06 100644
--- a/include/wine/wined3d.idl
+++ b/include/wine/wined3d.idl
@@ -3466,5 +3466,14 @@ interface IWineD3DDevice : IWineD3DBase
     );
 }
 
-IWineD3D *WineDirect3DCreate(UINT dxVersion, IUnknown *parent);
+const unsigned int WINED3D_NO_PARTIAL_VB_LOCK       = 0x00000001;
+const unsigned int WINED3D_STATIC_VB_DECL           = 0x00000002;
+const unsigned int WINED3D_NO_R8G8B8                = 0x00000004;
+const unsigned int WINED3D_DDRAW_ALIGNMENT          = 0x00000008;
+const unsigned int WINED3D_PRIVDATA_ADDREF          = 0x00000010;
+const unsigned int WINED3D_EXTRA_GETDC_FMTS         = 0x00000020;
+const unsigned int WINED3D_NO_DEVICE_PALETTE        = 0x00000040;
+const unsigned int WINED3D_REQUIRE_3D               = 0x00000080;
+
+IWineD3D *WineDirect3DCreate(DWORD Flags, IUnknown *parent);
 IWineD3DClipper *WineDirect3DCreateClipper(IUnknown *parent);
-- 
1.6.3.3


