[6/13]D3D: Index buffer fixes

Stefan Dösinger stefan at codeweavers.com
Tue Feb 20 15:46:31 CST 2007


The ddraw index buffer handling needs a proper fix somewhen, either by an VB + 
up Indices drawing method(but there are already too many of them) or my a 
SetMem method in index buffers

This patch should(hopefully) fix the regressions introduced with my former 
index buffer patch
-------------- next part --------------
From fadece932e1ff556a4434545d7bf6753aaabdaf1 Mon Sep 17 00:00:00 2001
From: Stefan Doesinger <stefan at codeweavers.com>
Date: Tue, 20 Feb 2007 16:15:04 +0100
Subject: [PATCH] D3D: Index buffer fixes

Some things that missed in my former patch. Do not unset the index buffer in _Release, that
is not needed. Dirtify the  index buffer state in unlock because the bound buffer is changed.
GL vbos are GLuints. The index buffer used by ddraw should have dynamic usage, and preferably
be locked only on the size that has to be locked
---
 dlls/ddraw/device.c        |    2 +-
 dlls/ddraw/direct3d.c      |    2 +-
 dlls/wined3d/device.c      |    2 +-
 dlls/wined3d/indexbuffer.c |    9 +++++++--
 4 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index c201df7..0814921 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -3691,7 +3691,7 @@ IDirect3DDeviceImpl_7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
      */
     hr = IWineD3DIndexBuffer_Lock(This->indexbuffer,
                                   0 /* OffSetToLock */,
-                                  0 /* SizeToLock - doesn't matter */,
+                                  IndexCount * sizeof(WORD),
                                   (BYTE **) &LockedIndices,
                                   0 /* Flags */);
     assert(IndexCount < 0x100000);
diff --git a/dlls/ddraw/direct3d.c b/dlls/ddraw/direct3d.c
index 4896ba7..b716a60 100644
--- a/dlls/ddraw/direct3d.c
+++ b/dlls/ddraw/direct3d.c
@@ -804,7 +804,7 @@ IDirect3DImpl_7_CreateDevice(IDirect3D7 *iface,
      */
     hr = IWineD3DDevice_CreateIndexBuffer(This->wineD3DDevice,
                                           0x40000, /* Length. Don't know how long it should be */
-                                          0, /* Usage */
+                                          WINED3DUSAGE_DYNAMIC, /* Usage */
                                           WINED3DFMT_INDEX16, /* Format. D3D7 uses WORDS */
                                           WINED3DPOOL_DEFAULT,
                                           &object->indexbuffer,
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index c039798..2ac8797 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -4294,7 +4294,7 @@ static HRESULT  WINAPI  IWineD3DDeviceImpl_DrawIndexedPrimitive(IWineD3DDevice *
     UINT                 idxStride = 2;
     IWineD3DIndexBuffer *pIB;
     WINED3DINDEXBUFFER_DESC  IdxBufDsc;
-    GLint vbo;
+    GLuint vbo;
 
     pIB = This->stateBlock->pIndexData;
     This->stateBlock->streamIsUP = FALSE;
diff --git a/dlls/wined3d/indexbuffer.c b/dlls/wined3d/indexbuffer.c
index b16ddd0..ae2294a 100644
--- a/dlls/wined3d/indexbuffer.c
+++ b/dlls/wined3d/indexbuffer.c
@@ -60,8 +60,11 @@ static ULONG WINAPI IWineD3DIndexBufferImpl_Release(IWineD3DIndexBuffer *iface)
     if (ref == 0) {
         if(This->vbo) {
             ENTER_GL();
-            GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
-            checkGLcall("glBindBufferARB");
+            /* No need to manually unset the buffer. glDeleteBuffers unsets it for the current context,
+             * but not for other contexts. However, because the d3d buffer is destroyed the app has to
+             * unset it before doing the next draw, thus dirtifying the index buffer state and forcing
+             * binding a new buffer
+             */
             GL_EXTCALL(glDeleteBuffersARB(1, &This->vbo));
             checkGLcall("glDeleteBuffersARB");
             LEAVE_GL();
@@ -159,6 +162,8 @@ static HRESULT WINAPI IWineD3DIndexBufferImpl_Unlock(IWineD3DIndexBuffer *iface)
         LEAVE_GL();
         This->dirtystart = 0;
         This->dirtyend = 0;
+        /* TODO: Move loading into preload when the buffer is used, that avoids dirtifying the state */
+        IWineD3DDeviceImpl_MarkStateDirty(This->resource.wineD3DDevice, STATE_INDEXBUFFER);
     }
     return WINED3D_OK;
 }
-- 
1.4.4.3



More information about the wine-patches mailing list