ddraw: Don't create a wastefully large index buffer.

This commit is contained in:
Stefan Dösinger 2012-11-27 00:00:30 +01:00 committed by Alexandre Julliard
parent fc847f868c
commit 4b95487bdd
2 changed files with 7 additions and 23 deletions

View File

@ -276,6 +276,7 @@ struct d3d_device
struct wined3d_device *wined3d_device;
struct ddraw *ddraw;
struct wined3d_buffer *indexbuffer;
UINT indexbuffer_size;
struct ddraw_surface *target;
/* Viewport management */

View File

@ -240,7 +240,7 @@ static ULONG WINAPI d3d_device_inner_Release(IUnknown *iface)
* care of that on uninit_3d(). */
/* Free the index buffer. */
wined3d_buffer_decref(This->indexbuffer);
if (This->indexbuffer) wined3d_buffer_decref(This->indexbuffer);
/* Set the device up to render to the front buffer since the back
* buffer will vanish soon. */
@ -4039,8 +4039,6 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
struct d3d_device *This = impl_from_IDirect3DDevice7(iface);
struct d3d_vertex_buffer *vb = unsafe_impl_from_IDirect3DVertexBuffer7(D3DVertexBuf);
DWORD stride = get_flexible_vertex_size(vb->fvf);
struct wined3d_resource *wined3d_resource;
struct wined3d_resource_desc desc;
WORD *LockedIndices;
HRESULT hr;
@ -4058,13 +4056,9 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
wined3d_device_set_vertex_declaration(This->wined3d_device, vb->wineD3DVertexDeclaration);
/* check that the buffer is large enough to hold the indices,
* reallocate if necessary. */
wined3d_resource = wined3d_buffer_get_resource(This->indexbuffer);
wined3d_resource_get_desc(wined3d_resource, &desc);
if (desc.size < IndexCount * sizeof(WORD))
if (This->indexbuffer_size < IndexCount * sizeof(WORD))
{
UINT size = max(desc.size * 2, IndexCount * sizeof(WORD));
UINT size = max(This->indexbuffer_size * 2, IndexCount * sizeof(WORD));
struct wined3d_buffer *buffer;
TRACE("Growing index buffer to %u bytes\n", size);
@ -4073,13 +4067,14 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
WINED3D_POOL_DEFAULT, NULL, &ddraw_null_wined3d_parent_ops, &buffer);
if (FAILED(hr))
{
ERR("(%p) IWineD3DDevice::CreateIndexBuffer failed with hr = %08x\n", This, hr);
ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", This, hr);
wined3d_mutex_unlock();
return hr;
}
wined3d_buffer_decref(This->indexbuffer);
if (This->indexbuffer) wined3d_buffer_decref(This->indexbuffer);
This->indexbuffer = buffer;
This->indexbuffer_size = size;
}
/* Copy the index stream into the index buffer. A new IWineD3DDevice
@ -6529,17 +6524,6 @@ static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw,
device->legacy_projection = ident;
device->legacy_clipspace = ident;
/* Create an index buffer, it's needed for indexed drawing */
hr = wined3d_buffer_create_ib(ddraw->wined3d_device, 0x40000 /* Length. Don't know how long it should be */,
WINED3DUSAGE_DYNAMIC /* Usage */, WINED3D_POOL_DEFAULT, NULL,
&ddraw_null_wined3d_parent_ops, &device->indexbuffer);
if (FAILED(hr))
{
ERR("Failed to create an index buffer, hr %#x.\n", hr);
ddraw_handle_table_destroy(&device->handle_table);
return hr;
}
/* This is for convenience. */
device->wined3d_device = ddraw->wined3d_device;
wined3d_device_incref(ddraw->wined3d_device);
@ -6549,7 +6533,6 @@ static HRESULT d3d_device_init(struct d3d_device *device, struct ddraw *ddraw,
if (FAILED(hr))
{
ERR("Failed to set render target, hr %#x.\n", hr);
wined3d_buffer_decref(device->indexbuffer);
ddraw_handle_table_destroy(&device->handle_table);
return hr;
}