[PATCH 2/5] wined3d: Keep vertex declaration references in the stateblock.

Henri Verbeet hverbeet at codeweavers.com
Mon Sep 28 03:05:00 CDT 2009


---
 dlls/wined3d/device.c            |    3 +++
 dlls/wined3d/stateblock.c        |   12 +++++++++++-
 dlls/wined3d/vertexdeclaration.c |    3 ++-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 42d78ac..11d55a2 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -3328,6 +3328,9 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetVertexDeclaration(IWineD3DDevice* if
 
     TRACE("(%p) : pDecl=%p\n", This, pDecl);
 
+    if (pDecl) IWineD3DVertexDeclaration_AddRef(pDecl);
+    if (oldDecl) IWineD3DVertexDeclaration_Release(oldDecl);
+
     This->updateStateBlock->vertexDecl = pDecl;
     This->updateStateBlock->changed.vertexDecl = TRUE;
 
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index 0e097aa..d626bf9 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -279,6 +279,8 @@ static ULONG  WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) {
     if (!refCount) {
         int counter;
 
+        if (This->vertexDecl) IWineD3DVertexDeclaration_Release(This->vertexDecl);
+
         for (counter = 0; counter < MAX_COMBINED_SAMPLERS; counter++)
         {
             if (This->textures[counter]) IWineD3DBaseTexture_Release(This->textures[counter]);
@@ -511,6 +513,8 @@ static HRESULT  WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface)
         if(This->changed.vertexDecl && This->vertexDecl != targetStateBlock->vertexDecl){
             TRACE("Updating vertex declaration from %p to %p\n", This->vertexDecl, targetStateBlock->vertexDecl);
 
+            if (targetStateBlock->vertexDecl) IWineD3DVertexDeclaration_AddRef(targetStateBlock->vertexDecl);
+            if (This->vertexDecl) IWineD3DVertexDeclaration_Release(This->vertexDecl);
             This->vertexDecl = targetStateBlock->vertexDecl;
         }
 
@@ -624,7 +628,6 @@ static HRESULT  WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface)
 
         record_lights(This, targetStateBlock);
     } else if(This->blockType == WINED3DSBT_ALL) {
-        This->vertexDecl = targetStateBlock->vertexDecl;
         memcpy(This->vertexShaderConstantB, targetStateBlock->vertexShaderConstantB, sizeof(This->vertexShaderConstantI));
         memcpy(This->vertexShaderConstantI, targetStateBlock->vertexShaderConstantI, sizeof(This->vertexShaderConstantF));
         memcpy(This->vertexShaderConstantF, targetStateBlock->vertexShaderConstantF, sizeof(float) * GL_LIMITS(vshader_constantsF) * 4);
@@ -648,6 +651,13 @@ static HRESULT  WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface)
         memcpy(This->samplerState, targetStateBlock->samplerState, sizeof(This->samplerState));
         This->scissorRect = targetStateBlock->scissorRect;
 
+        if (This->vertexDecl != targetStateBlock->vertexDecl)
+        {
+            if (targetStateBlock->vertexDecl) IWineD3DVertexDeclaration_AddRef(targetStateBlock->vertexDecl);
+            if (This->vertexDecl) IWineD3DVertexDeclaration_Release(This->vertexDecl);
+            This->vertexDecl = targetStateBlock->vertexDecl;
+        }
+
         for (i = 0; i < MAX_COMBINED_SAMPLERS; ++i)
         {
             if (targetStateBlock->textures[i] != This->textures[i])
diff --git a/dlls/wined3d/vertexdeclaration.c b/dlls/wined3d/vertexdeclaration.c
index db595be..18ea03a 100644
--- a/dlls/wined3d/vertexdeclaration.c
+++ b/dlls/wined3d/vertexdeclaration.c
@@ -69,7 +69,8 @@ static ULONG WINAPI IWineD3DVertexDeclarationImpl_Release(IWineD3DVertexDeclarat
     TRACE("(%p) : Releasing from %d\n", This, This->ref);
     ref = InterlockedDecrement(&This->ref);
     if (ref == 0) {
-        if(iface == This->wineD3DDevice->stateBlock->vertexDecl) {
+        if (This->wineD3DDevice->stateBlock && iface == This->wineD3DDevice->stateBlock->vertexDecl)
+        {
             /* See comment in PixelShader::Release */
             IWineD3DDeviceImpl_MarkStateDirty(This->wineD3DDevice, STATE_VDECL);
         }
-- 
1.6.0.6




More information about the wine-patches mailing list