[PATCH 3/4] wined3d: Move index buffer state to wined3d_state.
Henri Verbeet
hverbeet at codeweavers.com
Mon Sep 20 12:41:23 CDT 2010
---
dlls/wined3d/device.c | 41 ++++++++++++++++++++-------------------
dlls/wined3d/drawprim.c | 4 +-
dlls/wined3d/state.c | 8 ++++--
dlls/wined3d/stateblock.c | 22 +++++++++++---------
dlls/wined3d/wined3d_private.h | 5 +--
5 files changed, 42 insertions(+), 38 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index da1737f..ad54e58 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -2922,11 +2922,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetIndexBuffer(IWineD3DDevice *iface,
IWineD3DBuffer *oldIdxs;
TRACE("(%p) : Setting to %p\n", This, pIndexData);
- oldIdxs = This->updateStateBlock->pIndexData;
+ oldIdxs = (IWineD3DBuffer *)This->updateStateBlock->state.index_buffer;
This->updateStateBlock->changed.indices = TRUE;
- This->updateStateBlock->pIndexData = pIndexData;
- This->updateStateBlock->IndexFmt = fmt;
+ This->updateStateBlock->state.index_buffer = (struct wined3d_buffer *)pIndexData;
+ This->updateStateBlock->state.index_format = fmt;
/* Handle recording of state blocks */
if (This->isRecordingState) {
@@ -2955,7 +2955,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_GetIndexBuffer(IWineD3DDevice *iface, I
{
IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
- *ppIndexData = This->stateBlock->pIndexData;
+ *ppIndexData = (IWineD3DBuffer *)This->stateBlock->state.index_buffer;
/* up ref count on ppindexdata */
if (*ppIndexData) {
@@ -4699,13 +4699,14 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitive(IWineD3DDevice *iface, UI
static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitive(IWineD3DDevice *iface, UINT startIndex, UINT index_count)
{
- IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+ IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
+ struct wined3d_buffer *index_buffer;
UINT idxStride = 2;
- IWineD3DBuffer *pIB;
GLuint vbo;
- pIB = This->stateBlock->pIndexData;
- if (!pIB) {
+ index_buffer = This->stateBlock->state.index_buffer;
+ if (!index_buffer)
+ {
/* D3D9 returns D3DERR_INVALIDCALL when DrawIndexedPrimitive is called
* without an index buffer set. (The first time at least...)
* D3D8 simply dies, but I doubt it can do much harm to return
@@ -4725,15 +4726,14 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitive(IWineD3DDevice *if
IWineD3DDeviceImpl_MarkStateDirty(This, STATE_INDEXBUFFER);
This->stateBlock->state.user_stream = FALSE;
}
- vbo = ((struct wined3d_buffer *) pIB)->buffer_object;
+ vbo = index_buffer->buffer_object;
TRACE("(%p) : startIndex %u, index count %u.\n", This, startIndex, index_count);
- if (This->stateBlock->IndexFmt == WINED3DFMT_R16_UINT) {
+ if (This->stateBlock->state.index_format == WINED3DFMT_R16_UINT)
idxStride = 2;
- } else {
+ else
idxStride = 4;
- }
if(This->stateBlock->loadBaseVertexIndex != This->stateBlock->baseVertexIndex) {
This->stateBlock->loadBaseVertexIndex = This->stateBlock->baseVertexIndex;
@@ -4741,7 +4741,7 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitive(IWineD3DDevice *if
}
drawPrimitive(iface, index_count, startIndex, idxStride,
- vbo ? NULL : ((struct wined3d_buffer *)pIB)->resource.allocatedMemory);
+ vbo ? NULL : index_buffer->resource.allocatedMemory);
return WINED3D_OK;
}
@@ -4832,10 +4832,11 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitiveUP(IWineD3DDevice *
/* MSDN specifies stream zero settings and index buffer must be set to NULL */
stream->buffer = NULL;
stream->stride = 0;
- ib = This->stateBlock->pIndexData;
- if(ib) {
+ ib = (IWineD3DBuffer *)This->stateBlock->state.index_buffer;
+ if (ib)
+ {
IWineD3DBuffer_Release(ib);
- This->stateBlock->pIndexData = NULL;
+ This->stateBlock->state.index_buffer = NULL;
}
/* No need to mark the stream source state dirty here. Either the app calls UP drawing again, or it has to call
* SetStreamSource to specify a vertex buffer
@@ -6640,19 +6641,19 @@ void device_resource_released(IWineD3DDeviceImpl *device, IWineD3DResource *reso
}
- if (device->stateBlock && device->stateBlock->pIndexData == (IWineD3DBuffer *)resource)
+ if (device->stateBlock && device->stateBlock->state.index_buffer == (struct wined3d_buffer *)resource)
{
ERR("Buffer %p is still in use by stateblock %p as index buffer.\n",
resource, device->stateBlock);
- device->stateBlock->pIndexData = NULL;
+ device->stateBlock->state.index_buffer = NULL;
}
if (device->updateStateBlock != device->stateBlock
- && device->updateStateBlock->pIndexData == (IWineD3DBuffer *)resource)
+ && device->updateStateBlock->state.index_buffer == (struct wined3d_buffer *)resource)
{
ERR("Buffer %p is still in use by stateblock %p as index buffer.\n",
resource, device->updateStateBlock);
- device->updateStateBlock->pIndexData = NULL;
+ device->updateStateBlock->state.index_buffer = NULL;
}
break;
diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index f6cc44d..4149f8b 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -91,7 +91,7 @@ static void drawStridedSlow(IWineD3DDevice *iface, const struct wined3d_context
* supported or other reason), or with user pointer drawing idxData
* will be non-NULL. */
if (!idxData)
- idxData = buffer_get_sysmem((struct wined3d_buffer *)This->stateBlock->pIndexData, gl_info);
+ idxData = buffer_get_sysmem(This->stateBlock->state.index_buffer, gl_info);
if (idxSize == 2) pIdxBufS = idxData;
else pIdxBufL = idxData;
@@ -437,7 +437,7 @@ static void drawStridedSlowVs(IWineD3DDevice *iface, const struct wined3d_stream
* supported or other reason), or with user pointer drawing idxData
* will be non-NULL. */
if (!idxData)
- idxData = buffer_get_sysmem((struct wined3d_buffer *)This->stateBlock->pIndexData, gl_info);
+ idxData = buffer_get_sysmem(This->stateBlock->state.index_buffer, gl_info);
if (idxSize == 2) pIdxBufS = idxData;
else pIdxBufL = idxData;
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index d9ceea4..a4ce867 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -4950,11 +4950,13 @@ static void indexbuffer(DWORD state, IWineD3DStateBlockImpl *stateblock, struct
{
const struct wined3d_gl_info *gl_info = context->gl_info;
- if (stateblock->state.user_stream || !stateblock->pIndexData)
+ if (stateblock->state.user_stream || !stateblock->state.index_buffer)
{
GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
- } else {
- struct wined3d_buffer *ib = (struct wined3d_buffer *) stateblock->pIndexData;
+ }
+ else
+ {
+ struct wined3d_buffer *ib = stateblock->state.index_buffer;
GL_EXTCALL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ib->buffer_object));
}
}
diff --git a/dlls/wined3d/stateblock.c b/dlls/wined3d/stateblock.c
index dd5793c..d9bb34c 100644
--- a/dlls/wined3d/stateblock.c
+++ b/dlls/wined3d/stateblock.c
@@ -512,7 +512,7 @@ static ULONG WINAPI IWineD3DStateBlockImpl_Release(IWineD3DStateBlock *iface) {
}
}
}
- if(This->pIndexData) IWineD3DBuffer_Release(This->pIndexData);
+ if (This->state.index_buffer) IWineD3DBuffer_Release((IWineD3DBuffer *)This->state.index_buffer);
if (This->state.vertex_shader) IWineD3DVertexShader_Release((IWineD3DVertexShader *)This->state.vertex_shader);
if (This->state.pixel_shader) IWineD3DPixelShader_Release((IWineD3DPixelShader *)This->state.pixel_shader);
@@ -721,18 +721,20 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Capture(IWineD3DStateBlock *iface)
if (This->changed.primitive_type) This->gl_primitive_type = targetStateBlock->gl_primitive_type;
if (This->changed.indices
- && ((This->pIndexData != targetStateBlock->pIndexData)
+ && ((This->state.index_buffer != targetStateBlock->state.index_buffer)
|| (This->baseVertexIndex != targetStateBlock->baseVertexIndex)
- || (This->IndexFmt != targetStateBlock->IndexFmt)))
+ || (This->state.index_format != targetStateBlock->state.index_format)))
{
- TRACE("Updating pIndexData to %p, baseVertexIndex to %d.\n",
- targetStateBlock->pIndexData, targetStateBlock->baseVertexIndex);
-
- if (targetStateBlock->pIndexData) IWineD3DBuffer_AddRef(targetStateBlock->pIndexData);
- if (This->pIndexData) IWineD3DBuffer_Release(This->pIndexData);
- This->pIndexData = targetStateBlock->pIndexData;
+ TRACE("Updating index buffer to %p, baseVertexIndex to %d.\n",
+ targetStateBlock->state.index_buffer, targetStateBlock->baseVertexIndex);
+
+ if (targetStateBlock->state.index_buffer)
+ IWineD3DBuffer_AddRef((IWineD3DBuffer *)targetStateBlock->state.index_buffer);
+ if (This->state.index_buffer)
+ IWineD3DBuffer_Release((IWineD3DBuffer *)This->state.index_buffer);
+ This->state.index_buffer = targetStateBlock->state.index_buffer;
This->baseVertexIndex = targetStateBlock->baseVertexIndex;
- This->IndexFmt = targetStateBlock->IndexFmt;
+ This->state.index_format = targetStateBlock->state.index_format;
}
if (This->changed.vertexDecl && This->state.vertex_declaration != targetStateBlock->state.vertex_declaration)
@@ -998,7 +1000,7 @@ static HRESULT WINAPI IWineD3DStateBlockImpl_Apply(IWineD3DStateBlock *iface)
if (This->changed.indices)
{
- IWineD3DDevice_SetIndexBuffer(device, This->pIndexData, This->IndexFmt);
+ IWineD3DDevice_SetIndexBuffer(device, (IWineD3DBuffer *)This->state.index_buffer, This->state.index_format);
IWineD3DDevice_SetBaseVertexIndex(device, This->baseVertexIndex);
}
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 87d40ee..ea4f83a 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2352,6 +2352,8 @@ struct wined3d_state
IWineD3DVertexDeclarationImpl *vertex_declaration;
struct wined3d_stream_state streams[MAX_STREAMS + 1 /* tesselated pseudo-stream */];
BOOL user_stream;
+ struct wined3d_buffer *index_buffer;
+ enum wined3d_format_id index_format;
struct IWineD3DVertexShaderImpl *vertex_shader;
BOOL vs_consts_b[MAX_CONST_B];
@@ -2393,9 +2395,6 @@ struct IWineD3DStateBlockImpl
/* primitive type */
GLenum gl_primitive_type;
- /* Indices */
- IWineD3DBuffer* pIndexData;
- enum wined3d_format_id IndexFmt;
INT baseVertexIndex;
INT loadBaseVertexIndex; /* non-indexed drawing needs 0 here, indexed baseVertexIndex */
--
1.7.2.2
More information about the wine-patches
mailing list