Commit cc88fb0b authored by Zebediah Figura's avatar Zebediah Figura Committed by Alexandre Julliard

wined3d: Store the index buffer in the wined3d_stateblock_state structure.

parent 26fce5ed
...@@ -1865,24 +1865,32 @@ void CDECL wined3d_device_set_index_buffer(struct wined3d_device *device, ...@@ -1865,24 +1865,32 @@ void CDECL wined3d_device_set_index_buffer(struct wined3d_device *device,
TRACE("device %p, buffer %p, format %s, offset %u.\n", TRACE("device %p, buffer %p, format %s, offset %u.\n",
device, buffer, debug_d3dformat(format_id), offset); device, buffer, debug_d3dformat(format_id), offset);
prev_buffer = device->update_state->index_buffer; prev_buffer = device->state.index_buffer;
prev_format = device->update_state->index_format; prev_format = device->state.index_format;
prev_offset = device->update_state->index_offset; prev_offset = device->state.index_offset;
device->update_state->index_buffer = buffer; if (buffer)
device->update_state->index_format = format_id; wined3d_buffer_incref(buffer);
device->update_state->index_offset = offset; if (device->update_stateblock_state->index_buffer)
wined3d_buffer_decref(device->update_stateblock_state->index_buffer);
device->update_stateblock_state->index_buffer = buffer;
device->update_stateblock_state->index_format = format_id;
if (device->recording) if (device->recording)
{
device->recording->changed.indices = TRUE; device->recording->changed.indices = TRUE;
return;
}
if (prev_buffer == buffer && prev_format == format_id && prev_offset == offset) if (prev_buffer == buffer && prev_format == format_id && prev_offset == offset)
return; return;
if (buffer) if (buffer)
wined3d_buffer_incref(buffer); wined3d_buffer_incref(buffer);
if (!device->recording) device->state.index_buffer = buffer;
wined3d_cs_emit_set_index_buffer(device->cs, buffer, format_id, offset); device->state.index_format = format_id;
device->state.index_offset = offset;
wined3d_cs_emit_set_index_buffer(device->cs, buffer, format_id, offset);
if (prev_buffer) if (prev_buffer)
wined3d_buffer_decref(prev_buffer); wined3d_buffer_decref(prev_buffer);
} }
...@@ -1902,7 +1910,9 @@ void CDECL wined3d_device_set_base_vertex_index(struct wined3d_device *device, I ...@@ -1902,7 +1910,9 @@ void CDECL wined3d_device_set_base_vertex_index(struct wined3d_device *device, I
{ {
TRACE("device %p, base_index %d.\n", device, base_index); TRACE("device %p, base_index %d.\n", device, base_index);
device->update_state->base_vertex_index = base_index; device->update_stateblock_state->base_vertex_index = base_index;
if (!device->recording)
device->state.base_vertex_index = base_index;
} }
INT CDECL wined3d_device_get_base_vertex_index(const struct wined3d_device *device) INT CDECL wined3d_device_get_base_vertex_index(const struct wined3d_device *device)
...@@ -5232,11 +5242,11 @@ void device_resource_released(struct wined3d_device *device, struct wined3d_reso ...@@ -5232,11 +5242,11 @@ void device_resource_released(struct wined3d_device *device, struct wined3d_reso
device->state.index_buffer = NULL; device->state.index_buffer = NULL;
} }
if (device->recording && &device->update_state->index_buffer->resource == resource) if (device->recording && &device->update_stateblock_state->index_buffer->resource == resource)
{ {
ERR("Buffer resource %p is still in use by stateblock %p as index buffer.\n", ERR("Buffer resource %p is still in use by stateblock %p as index buffer.\n",
resource, device->recording); resource, device->recording);
device->update_state->index_buffer = NULL; device->update_stateblock_state->index_buffer = NULL;
} }
break; break;
......
...@@ -524,9 +524,16 @@ void state_unbind_resources(struct wined3d_state *state) ...@@ -524,9 +524,16 @@ void state_unbind_resources(struct wined3d_state *state)
void wined3d_stateblock_state_cleanup(struct wined3d_stateblock_state *state) void wined3d_stateblock_state_cleanup(struct wined3d_stateblock_state *state)
{ {
struct wined3d_texture *texture; struct wined3d_texture *texture;
struct wined3d_buffer *buffer;
struct wined3d_shader *shader; struct wined3d_shader *shader;
unsigned int i; unsigned int i;
if ((buffer = state->index_buffer))
{
state->index_buffer = NULL;
wined3d_buffer_decref(buffer);
}
if ((shader = state->vs)) if ((shader = state->vs))
{ {
state->vs = NULL; state->vs = NULL;
...@@ -791,22 +798,20 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock) ...@@ -791,22 +798,20 @@ void CDECL wined3d_stateblock_capture(struct wined3d_stateblock *stateblock)
} }
if (stateblock->changed.indices if (stateblock->changed.indices
&& ((stateblock->state.index_buffer != src_state->index_buffer) && ((stateblock->stateblock_state.index_buffer != state->index_buffer)
|| (stateblock->state.base_vertex_index != src_state->base_vertex_index) || (stateblock->stateblock_state.base_vertex_index != state->base_vertex_index)
|| (stateblock->state.index_format != src_state->index_format) || (stateblock->stateblock_state.index_format != state->index_format)))
|| (stateblock->state.index_offset != src_state->index_offset)))
{ {
TRACE("Updating index buffer to %p, base vertex index to %d.\n", TRACE("Updating index buffer to %p, base vertex index to %d.\n",
src_state->index_buffer, src_state->base_vertex_index); state->index_buffer, state->base_vertex_index);
if (src_state->index_buffer) if (state->index_buffer)
wined3d_buffer_incref(src_state->index_buffer); wined3d_buffer_incref(state->index_buffer);
if (stateblock->state.index_buffer) if (stateblock->stateblock_state.index_buffer)
wined3d_buffer_decref(stateblock->state.index_buffer); wined3d_buffer_decref(stateblock->stateblock_state.index_buffer);
stateblock->state.index_buffer = src_state->index_buffer; stateblock->stateblock_state.index_buffer = state->index_buffer;
stateblock->state.base_vertex_index = src_state->base_vertex_index; stateblock->stateblock_state.base_vertex_index = state->base_vertex_index;
stateblock->state.index_format = src_state->index_format; stateblock->stateblock_state.index_format = state->index_format;
stateblock->state.index_offset = src_state->index_offset;
} }
if (stateblock->changed.vertexDecl && stateblock->state.vertex_declaration != src_state->vertex_declaration) if (stateblock->changed.vertexDecl && stateblock->state.vertex_declaration != src_state->vertex_declaration)
...@@ -1106,9 +1111,17 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock) ...@@ -1106,9 +1111,17 @@ void CDECL wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock)
if (stateblock->changed.indices) if (stateblock->changed.indices)
{ {
wined3d_device_set_index_buffer(device, stateblock->state.index_buffer, if (stateblock->stateblock_state.index_buffer)
stateblock->state.index_format, stateblock->state.index_offset); wined3d_buffer_incref(stateblock->stateblock_state.index_buffer);
wined3d_device_set_base_vertex_index(device, stateblock->state.base_vertex_index); if (state->index_buffer)
wined3d_buffer_decref(state->index_buffer);
state->index_buffer = stateblock->stateblock_state.index_buffer;
state->index_format = stateblock->stateblock_state.index_format;
state->base_vertex_index = stateblock->stateblock_state.base_vertex_index;
wined3d_device_set_index_buffer(device, stateblock->stateblock_state.index_buffer,
stateblock->stateblock_state.index_format, 0);
wined3d_device_set_base_vertex_index(device, stateblock->stateblock_state.base_vertex_index);
} }
if (stateblock->changed.vertexDecl && stateblock->state.vertex_declaration) if (stateblock->changed.vertexDecl && stateblock->state.vertex_declaration)
......
...@@ -2970,6 +2970,10 @@ struct wined3d_dummy_textures ...@@ -2970,6 +2970,10 @@ struct wined3d_dummy_textures
struct wined3d_stateblock_state struct wined3d_stateblock_state
{ {
struct wined3d_buffer *index_buffer;
enum wined3d_format_id index_format;
int base_vertex_index;
struct wined3d_shader *vs; struct wined3d_shader *vs;
struct wined3d_vec4 vs_consts_f[WINED3D_MAX_VS_CONSTS_F]; struct wined3d_vec4 vs_consts_f[WINED3D_MAX_VS_CONSTS_F];
struct wined3d_ivec4 vs_consts_i[WINED3D_MAX_CONSTS_I]; struct wined3d_ivec4 vs_consts_i[WINED3D_MAX_CONSTS_I];
......
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