Commit 902630ef authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Move index buffer state to wined3d_state.

parent 153d8d43
......@@ -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) {
......@@ -4700,12 +4700,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_DrawPrimitive(IWineD3DDevice *iface, UI
static HRESULT WINAPI IWineD3DDeviceImpl_DrawIndexedPrimitive(IWineD3DDevice *iface, UINT startIndex, UINT index_count)
{
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;
......
......@@ -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;
......
......@@ -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));
}
}
......
......@@ -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);
TRACE("Updating index buffer to %p, baseVertexIndex to %d.\n",
targetStateBlock->state.index_buffer, targetStateBlock->baseVertexIndex);
if (targetStateBlock->pIndexData) IWineD3DBuffer_AddRef(targetStateBlock->pIndexData);
if (This->pIndexData) IWineD3DBuffer_Release(This->pIndexData);
This->pIndexData = targetStateBlock->pIndexData;
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);
}
......
......@@ -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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment