*We* know that these enums are equivalent, but Clang doesn't.
The remaining warnings are due to a bug in Clang around unions with enum
types.
Signed-off-by: Chip Davis <cdavis(a)codeweavers.com>
---
v2: Hide the casts behind functions. Reduce duplicated code.
---
dlls/ddraw/device.c | 124 +++++++++++++++++---------------------------
1 file changed, 47 insertions(+), 77 deletions(-)
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index 048ba7fba66..a03b531f5bc 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -72,6 +72,40 @@ static inline WORD d3d_fpu_setup(void)
return oldcw;
}
+static inline enum wined3d_render_state wined3d_render_state_from_d3d(D3DRENDERSTATETYPE state)
+{
+ if (state == D3DRENDERSTATE_ZBIAS)
+ return WINED3D_RS_DEPTHBIAS;
+ return (enum wined3d_render_state)state;
+}
+
+static inline enum wined3d_transform_state wined3d_transform_state_from_d3d(D3DTRANSFORMSTATETYPE state)
+{
+ switch (state)
+ {
+ case D3DTRANSFORMSTATE_WORLD:
+ return WINED3D_TS_WORLD_MATRIX(0);
+ case D3DTRANSFORMSTATE_WORLD1:
+ return WINED3D_TS_WORLD_MATRIX(1);
+ case D3DTRANSFORMSTATE_WORLD2:
+ return WINED3D_TS_WORLD_MATRIX(2);
+ case D3DTRANSFORMSTATE_WORLD3:
+ return WINED3D_TS_WORLD_MATRIX(3);
+ default:
+ return (enum wined3d_transform_state)state;
+ }
+}
+
+static inline enum wined3d_primitive_type wined3d_primitive_type_from_d3d(D3DPRIMITIVETYPE type)
+{
+ return (enum wined3d_primitive_type)type;
+}
+
+static inline enum wined3d_stateblock_type wined3d_stateblock_type_from_d3d(D3DSTATEBLOCKTYPE type)
+{
+ return (enum wined3d_stateblock_type)type;
+}
+
static inline struct d3d_device *impl_from_IUnknown(IUnknown *iface)
{
return CONTAINING_RECORD(iface, struct d3d_device, IUnknown_inner);
@@ -2396,10 +2430,6 @@ static HRESULT d3d_device7_GetRenderState(IDirect3DDevice7 *iface,
hr = DDERR_INVALIDPARAMS;
break;
- case D3DRENDERSTATE_ZBIAS:
- *value = device_state->rs[WINED3D_RS_DEPTHBIAS];
- break;
-
default:
if (state >= D3DRENDERSTATE_STIPPLEPATTERN00
&& state <= D3DRENDERSTATE_STIPPLEPATTERN31)
@@ -2408,7 +2438,7 @@ static HRESULT d3d_device7_GetRenderState(IDirect3DDevice7 *iface,
hr = E_NOTIMPL;
break;
}
- *value = device_state->rs[state];
+ *value = device_state->rs[wined3d_render_state_from_d3d(state)];
}
wined3d_mutex_unlock();
@@ -2622,10 +2652,6 @@ static HRESULT d3d_device7_SetRenderState(IDirect3DDevice7 *iface,
hr = DDERR_INVALIDPARAMS;
break;
- case D3DRENDERSTATE_ZBIAS:
- wined3d_stateblock_set_render_state(device->update_state, WINED3D_RS_DEPTHBIAS, value);
- break;
-
default:
if (state >= D3DRENDERSTATE_STIPPLEPATTERN00
&& state <= D3DRENDERSTATE_STIPPLEPATTERN31)
@@ -2635,7 +2661,7 @@ static HRESULT d3d_device7_SetRenderState(IDirect3DDevice7 *iface,
break;
}
- wined3d_stateblock_set_render_state(device->update_state, state, value);
+ wined3d_stateblock_set_render_state(device->update_state, wined3d_render_state_from_d3d(state), value);
break;
}
wined3d_mutex_unlock();
@@ -3097,34 +3123,16 @@ static HRESULT d3d_device7_SetTransform(IDirect3DDevice7 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
- enum wined3d_transform_state wined3d_state;
TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
- switch (state)
- {
- case D3DTRANSFORMSTATE_WORLD:
- wined3d_state = WINED3D_TS_WORLD_MATRIX(0);
- break;
- case D3DTRANSFORMSTATE_WORLD1:
- wined3d_state = WINED3D_TS_WORLD_MATRIX(1);
- break;
- case D3DTRANSFORMSTATE_WORLD2:
- wined3d_state = WINED3D_TS_WORLD_MATRIX(2);
- break;
- case D3DTRANSFORMSTATE_WORLD3:
- wined3d_state = WINED3D_TS_WORLD_MATRIX(3);
- break;
- default:
- wined3d_state = state;
- }
-
if (!matrix)
return DDERR_INVALIDPARAMS;
/* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
wined3d_mutex_lock();
- wined3d_stateblock_set_transform(device->update_state, wined3d_state, (const struct wined3d_matrix *)matrix);
+ wined3d_stateblock_set_transform(device->update_state, wined3d_transform_state_from_d3d(state),
+ (const struct wined3d_matrix *)matrix);
wined3d_mutex_unlock();
return D3D_OK;
@@ -3206,34 +3214,15 @@ static HRESULT d3d_device7_GetTransform(IDirect3DDevice7 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
- enum wined3d_transform_state wined3d_state;
TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
- switch (state)
- {
- case D3DTRANSFORMSTATE_WORLD:
- wined3d_state = WINED3D_TS_WORLD_MATRIX(0);
- break;
- case D3DTRANSFORMSTATE_WORLD1:
- wined3d_state = WINED3D_TS_WORLD_MATRIX(1);
- break;
- case D3DTRANSFORMSTATE_WORLD2:
- wined3d_state = WINED3D_TS_WORLD_MATRIX(2);
- break;
- case D3DTRANSFORMSTATE_WORLD3:
- wined3d_state = WINED3D_TS_WORLD_MATRIX(3);
- break;
- default:
- wined3d_state = state;
- }
-
if (!matrix)
return DDERR_INVALIDPARAMS;
/* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
wined3d_mutex_lock();
- memcpy(matrix, &device->stateblock_state->transforms[wined3d_state], sizeof(*matrix));
+ memcpy(matrix, &device->stateblock_state->transforms[wined3d_transform_state_from_d3d(state)], sizeof(*matrix));
wined3d_mutex_unlock();
return D3D_OK;
@@ -3310,32 +3299,13 @@ static HRESULT d3d_device7_MultiplyTransform(IDirect3DDevice7 *iface,
D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
{
struct d3d_device *device = impl_from_IDirect3DDevice7(iface);
- enum wined3d_transform_state wined3d_state;
TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
- switch (state)
- {
- case D3DTRANSFORMSTATE_WORLD:
- wined3d_state = WINED3D_TS_WORLD_MATRIX(0);
- break;
- case D3DTRANSFORMSTATE_WORLD1:
- wined3d_state = WINED3D_TS_WORLD_MATRIX(1);
- break;
- case D3DTRANSFORMSTATE_WORLD2:
- wined3d_state = WINED3D_TS_WORLD_MATRIX(2);
- break;
- case D3DTRANSFORMSTATE_WORLD3:
- wined3d_state = WINED3D_TS_WORLD_MATRIX(3);
- break;
- default:
- wined3d_state = state;
- }
-
/* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
wined3d_mutex_lock();
wined3d_stateblock_multiply_transform(device->state,
- wined3d_state, (struct wined3d_matrix *)matrix);
+ wined3d_transform_state_from_d3d(state), (struct wined3d_matrix *)matrix);
wined3d_mutex_unlock();
return D3D_OK;
@@ -3504,7 +3474,7 @@ static HRESULT d3d_device7_DrawPrimitive(IDirect3DDevice7 *iface,
goto done;
wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, fvf));
- wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
+ wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_d3d(primitive_type), 0);
wined3d_device_apply_stateblock(device->wined3d_device, device->state);
hr = wined3d_device_draw_primitive(device->wined3d_device, vb_pos / stride, vertex_count);
@@ -3715,7 +3685,7 @@ static HRESULT d3d_device7_DrawIndexedPrimitive(IDirect3DDevice7 *iface,
wined3d_stateblock_set_index_buffer(device->state, device->index_buffer, WINED3DFMT_R16_UINT);
wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, fvf));
- wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
+ wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_d3d(primitive_type), 0);
wined3d_stateblock_set_base_vertex_index(device->state, vb_pos / stride);
wined3d_device_apply_stateblock(device->wined3d_device, device->state);
hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / sizeof(*indices), index_count);
@@ -4042,7 +4012,7 @@ static HRESULT d3d_device7_DrawPrimitiveStrided(IDirect3DDevice7 *iface, D3DPRIM
goto done;
wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, fvf));
- wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
+ wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_d3d(primitive_type), 0);
wined3d_device_apply_stateblock(device->wined3d_device, device->state);
hr = wined3d_device_draw_primitive(device->wined3d_device, vb_pos / dst_stride, vertex_count);
@@ -4178,7 +4148,7 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveStrided(IDirect3DDevice7 *iface,
wined3d_stateblock_set_base_vertex_index(device->state, vb_pos / vtx_dst_stride);
wined3d_stateblock_set_vertex_declaration(device->state, ddraw_find_decl(device->ddraw, fvf));
- wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
+ wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_d3d(primitive_type), 0);
wined3d_device_apply_stateblock(device->wined3d_device, device->state);
hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / sizeof(WORD), index_count);
@@ -4300,7 +4270,7 @@ static HRESULT d3d_device7_DrawPrimitiveVB(IDirect3DDevice7 *iface, D3DPRIMITIVE
}
/* Now draw the primitives */
- wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
+ wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_d3d(primitive_type), 0);
wined3d_device_apply_stateblock(device->wined3d_device, device->state);
hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex, vertex_count);
@@ -4454,7 +4424,7 @@ static HRESULT d3d_device7_DrawIndexedPrimitiveVB(IDirect3DDevice7 *iface,
return hr;
}
- wined3d_device_set_primitive_type(device->wined3d_device, primitive_type, 0);
+ wined3d_device_set_primitive_type(device->wined3d_device, wined3d_primitive_type_from_d3d(primitive_type), 0);
wined3d_device_apply_stateblock(device->wined3d_device, device->state);
hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / sizeof(WORD), index_count);
@@ -6005,7 +5975,7 @@ static HRESULT d3d_device7_CreateStateBlock(IDirect3DDevice7 *iface,
}
/* The D3DSTATEBLOCKTYPE enum is fine here. */
- hr = wined3d_stateblock_create(device->wined3d_device, device->state, type, &wined3d_sb);
+ hr = wined3d_stateblock_create(device->wined3d_device, device->state, wined3d_stateblock_type_from_d3d(type), &wined3d_sb);
if (FAILED(hr))
{
WARN("Failed to create stateblock, hr %#x.\n", hr);
--
2.24.0