Commit cc85c6af authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

wined3d: Introduce a separate function for initializing a wined3d_state structure.

parent c192885d
...@@ -196,19 +196,10 @@ static HRESULT stateblock_allocate_shader_constants(struct wined3d_stateblock *o ...@@ -196,19 +196,10 @@ static HRESULT stateblock_allocate_shader_constants(struct wined3d_stateblock *o
{ {
const struct wined3d_d3d_info *d3d_info = &object->device->adapter->d3d_info; const struct wined3d_d3d_info *d3d_info = &object->device->adapter->d3d_info;
/* Allocate space for floating point constants */
object->state.ps_consts_f = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(float) * d3d_info->limits.ps_uniform_count * 4);
if (!object->state.ps_consts_f) goto fail;
object->changed.pixelShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, object->changed.pixelShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(BOOL) * d3d_info->limits.ps_uniform_count); sizeof(BOOL) * d3d_info->limits.ps_uniform_count);
if (!object->changed.pixelShaderConstantsF) goto fail; if (!object->changed.pixelShaderConstantsF) goto fail;
object->state.vs_consts_f = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(float) * d3d_info->limits.vs_uniform_count * 4);
if (!object->state.vs_consts_f) goto fail;
object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, object->changed.vertexShaderConstantsF = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(BOOL) * d3d_info->limits.vs_uniform_count); sizeof(BOOL) * d3d_info->limits.vs_uniform_count);
if (!object->changed.vertexShaderConstantsF) goto fail; if (!object->changed.vertexShaderConstantsF) goto fail;
...@@ -225,9 +216,7 @@ static HRESULT stateblock_allocate_shader_constants(struct wined3d_stateblock *o ...@@ -225,9 +216,7 @@ static HRESULT stateblock_allocate_shader_constants(struct wined3d_stateblock *o
fail: fail:
ERR("Failed to allocate memory\n"); ERR("Failed to allocate memory\n");
HeapFree(GetProcessHeap(), 0, object->state.ps_consts_f);
HeapFree(GetProcessHeap(), 0, object->changed.pixelShaderConstantsF); HeapFree(GetProcessHeap(), 0, object->changed.pixelShaderConstantsF);
HeapFree(GetProcessHeap(), 0, object->state.vs_consts_f);
HeapFree(GetProcessHeap(), 0, object->changed.vertexShaderConstantsF); HeapFree(GetProcessHeap(), 0, object->changed.vertexShaderConstantsF);
HeapFree(GetProcessHeap(), 0, object->contained_vs_consts_f); HeapFree(GetProcessHeap(), 0, object->contained_vs_consts_f);
HeapFree(GetProcessHeap(), 0, object->contained_ps_consts_f); HeapFree(GetProcessHeap(), 0, object->contained_ps_consts_f);
...@@ -609,6 +598,29 @@ static void state_cleanup(struct wined3d_state *state) ...@@ -609,6 +598,29 @@ static void state_cleanup(struct wined3d_state *state)
HeapFree(GetProcessHeap(), 0, state->ps_consts_f); HeapFree(GetProcessHeap(), 0, state->ps_consts_f);
} }
static HRESULT state_init(struct wined3d_state *state, const struct wined3d_d3d_info *d3d_info)
{
unsigned int i;
for (i = 0; i < LIGHTMAP_SIZE; i++)
{
list_init(&state->light_map[i]);
}
if (!(state->vs_consts_f = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4 * sizeof(float) * d3d_info->limits.vs_uniform_count)))
return E_OUTOFMEMORY;
if (!(state->ps_consts_f = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
4 * sizeof(float) * d3d_info->limits.ps_uniform_count)))
{
HeapFree(GetProcessHeap(), 0, state->vs_consts_f);
return E_OUTOFMEMORY;
}
return WINED3D_OK;
}
ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock) ULONG CDECL wined3d_stateblock_decref(struct wined3d_stateblock *stateblock)
{ {
ULONG refcount = InterlockedDecrement(&stateblock->ref); ULONG refcount = InterlockedDecrement(&stateblock->ref);
...@@ -1407,21 +1419,21 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock) ...@@ -1407,21 +1419,21 @@ void stateblock_init_default_state(struct wined3d_stateblock *stateblock)
static HRESULT stateblock_init(struct wined3d_stateblock *stateblock, static HRESULT stateblock_init(struct wined3d_stateblock *stateblock,
struct wined3d_device *device, enum wined3d_stateblock_type type) struct wined3d_device *device, enum wined3d_stateblock_type type)
{ {
unsigned int i;
HRESULT hr; HRESULT hr;
const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info; const struct wined3d_d3d_info *d3d_info = &device->adapter->d3d_info;
stateblock->ref = 1; stateblock->ref = 1;
stateblock->device = device; stateblock->device = device;
for (i = 0; i < LIGHTMAP_SIZE; i++) if (FAILED(hr = state_init(&stateblock->state, d3d_info)))
return hr;
if (FAILED(hr = stateblock_allocate_shader_constants(stateblock)))
{ {
list_init(&stateblock->state.light_map[i]); state_cleanup(&stateblock->state);
return hr;
} }
hr = stateblock_allocate_shader_constants(stateblock);
if (FAILED(hr)) return hr;
/* The WINED3D_SBT_INIT stateblock type is used during initialization to /* The WINED3D_SBT_INIT stateblock type is used during initialization to
* produce a placeholder stateblock so other functions called can update a * produce a placeholder stateblock so other functions called can update a
* state block. */ * state block. */
......
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