From: Connor McAdams Subject: [PATCH 07/10] d3d10: Implement matrix effect variable get methods. Message-Id: <20191207182300.3084-8-conmanx360@gmail.com> Date: Sat, 7 Dec 2019 13:22:57 -0500 In-Reply-To: <20191207182300.3084-1-conmanx360@gmail.com> References: <20191207182300.3084-1-conmanx360@gmail.com> Implement GetMatrix/GetMatrixArray and GetMatrixTranspose/GetMatrixTransposeArray methods for the matrix effect variable interface. Signed-off-by: Connor McAdams --- dlls/d3d10/effect.c | 85 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 8 deletions(-) diff --git a/dlls/d3d10/effect.c b/dlls/d3d10/effect.c index 0f08fb11e9..1e1d5d7f4c 100644 --- a/dlls/d3d10/effect.c +++ b/dlls/d3d10/effect.c @@ -5026,6 +5026,63 @@ static void write_matrix_variable_array_to_cbuffer(struct d3d10_effect_variable variable->buffer->u.buffer.changed = 1; } +static void read_matrix_from_cbuffer(struct d3d10_effect_variable *variable, float *cbuf, D3DMATRIX *matrix) +{ + UINT row, col; + + if (variable->type->type_class == D3D10_SVC_MATRIX_COLUMNS) + { + for (col = 0; col < variable->type->column_count; col++) + { + for (row = 0; row < variable->type->row_count; row++) + { + memcpy(&matrix->m[row][col], cbuf + ((col * 4) + row), sizeof(float)); + } + } + } + else + { + for (col = 0; col < variable->type->column_count; col++) + { + for (row = 0; row < variable->type->row_count; row++) + { + memcpy(&matrix->m[row][col], cbuf + ((row * 4) + col), sizeof(float)); + } + } + } +} + +static void read_matrix_variable_from_cbuffer(struct d3d10_effect_variable *variable, void *data, BOOL transpose) +{ + char *cbuf = variable->buffer->u.buffer.local_buffer + variable->buffer_offset; + + read_matrix_from_cbuffer(variable, (float *)cbuf, data); + + if (transpose) + transpose_matrix(data); +} + +static void read_matrix_variable_array_from_cbuffer(struct d3d10_effect_variable *variable, void *data, UINT offset, + UINT count, BOOL transpose) +{ + char *cbuf = variable->buffer->u.buffer.local_buffer + variable->buffer_offset; + D3DMATRIX *input_data = data; + UINT i; + + if (offset) + cbuf += variable->type->stride * offset; + + for (i = 0; i < count; i++) + { + read_matrix_from_cbuffer(variable, (float *)cbuf, &input_data[i]); + + if (transpose) + transpose_matrix(&input_data[i]); + + cbuf += variable->type->stride; + } +} + /* ID3D10EffectVariable methods */ static BOOL STDMETHODCALLTYPE d3d10_effect_matrix_variable_IsValid(ID3D10EffectMatrixVariable *iface) @@ -5195,9 +5252,12 @@ static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrix(ID3D10Ef static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrix(ID3D10EffectMatrixVariable *iface, float *data) { - FIXME("iface %p, data %p stub!\n", iface, data); + struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVariable((ID3D10EffectVariable *)iface); - return E_NOTIMPL; + TRACE("iface %p, data %p.\n", iface, data); + read_matrix_variable_from_cbuffer(effect_var, data, FALSE); + + return S_OK; } static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixArray(ID3D10EffectMatrixVariable *iface, @@ -5214,9 +5274,12 @@ static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixArray(ID3 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixArray(ID3D10EffectMatrixVariable *iface, float *data, UINT offset, UINT count) { - FIXME("iface %p, data %p, offset %u, count %u stub!\n", iface, data, offset, count); + struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVariable((ID3D10EffectVariable *)iface); - return E_NOTIMPL; + TRACE("iface %p, data %p, offset %u, count %u.\n", iface, data, offset, count); + read_matrix_variable_array_from_cbuffer(effect_var, data, offset, count, FALSE); + + return S_OK; } static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixTranspose(ID3D10EffectMatrixVariable *iface, @@ -5235,9 +5298,12 @@ static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixTranspose static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixTranspose(ID3D10EffectMatrixVariable *iface, float *data) { - FIXME("iface %p, data %p stub!\n", iface, data); + struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVariable((ID3D10EffectVariable *)iface); - return E_NOTIMPL; + TRACE("iface %p, data %p.\n", iface, data); + read_matrix_variable_from_cbuffer(effect_var, data, TRUE); + + return S_OK; } static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixTransposeArray(ID3D10EffectMatrixVariable *iface, @@ -5254,9 +5320,12 @@ static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixTranspose static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixTransposeArray(ID3D10EffectMatrixVariable *iface, float *data, UINT offset, UINT count) { - FIXME("iface %p, data %p, offset %u, count %u stub!\n", iface, data, offset, count); + struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectVariable((ID3D10EffectVariable *)iface); - return E_NOTIMPL; + TRACE("iface %p, data %p, offset %u, count %u.\n", iface, data, offset, count); + read_matrix_variable_array_from_cbuffer(effect_var, data, offset, count, TRUE); + + return S_OK; } -- 2.20.1