Implement SetMatrix/SetMatrixArray and SetMatrixTranspose/SetMatrixTransposeArray methods for the matrix effect variable interface.
Signed-off-by: Connor McAdams conmanx360@gmail.com --- dlls/d3d10/d3d10_private.h | 5 ++ dlls/d3d10/effect.c | 107 ++++++++++++++++++++++++++++++++++--- 2 files changed, 104 insertions(+), 8 deletions(-)
diff --git a/dlls/d3d10/d3d10_private.h b/dlls/d3d10/d3d10_private.h index 5c6c7a2d72..2be381f608 100644 --- a/dlls/d3d10/d3d10_private.h +++ b/dlls/d3d10/d3d10_private.h @@ -61,6 +61,11 @@ enum d3d10_effect_object_operation D3D10_EOO_ANONYMOUS_SHADER = 7, };
+struct d3d10_effect_matrix +{ + float m[4][4]; +}; + struct d3d10_effect_object { struct d3d10_effect_pass *pass; diff --git a/dlls/d3d10/effect.c b/dlls/d3d10/effect.c index 93be257b81..1bc7968499 100644 --- a/dlls/d3d10/effect.c +++ b/dlls/d3d10/effect.c @@ -4967,8 +4967,87 @@ static const struct ID3D10EffectVectorVariableVtbl d3d10_effect_vector_variable_ d3d10_effect_vector_variable_GetFloatVectorArray, };
+static void write_matrix_to_buffer(struct d3d10_effect_variable *variable, float *buf, + struct d3d10_effect_matrix *matrix, BOOL transpose) +{ + unsigned int 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++) + { + if (transpose) + buf[(col * 4) + row] = matrix->m[col][row]; + else + buf[(col * 4) + row] = matrix->m[row][col]; + } + } + } + else + { + for (col = 0; col < variable->type->column_count; col++) + { + for (row = 0; row < variable->type->row_count; row++) + { + if (transpose) + buf[(row * 4) + col] = matrix->m[col][row]; + else + buf[(row * 4) + col] = matrix->m[row][col]; + } + } + } +} + +static void write_matrix_variable_to_buffer(struct d3d10_effect_variable *variable, void *data, BOOL transpose) +{ + char *buf = variable->buffer->u.buffer.local_buffer + variable->buffer_offset; + + write_matrix_to_buffer(variable, (float *)buf, data, transpose); + + variable->buffer->u.buffer.changed = 1; +} + +static void write_matrix_variable_array_to_buffer(struct d3d10_effect_variable *variable, void *data, UINT offset, + UINT count, BOOL transpose) +{ + char *buf = variable->buffer->u.buffer.local_buffer + variable->buffer_offset; + struct d3d10_effect_matrix *input_data = data; + unsigned int i; + + if (!variable->type->element_count) + { + write_matrix_variable_to_buffer(variable, data, transpose); + return; + } + + if (offset >= variable->type->element_count) + return; + + if (count > variable->type->element_count - offset) + count = variable->type->element_count - offset; + + if (offset) + buf += variable->type->stride * offset; + + for (i = 0; i < count; i++) + { + write_matrix_to_buffer(variable, (float *)buf, &input_data[i], transpose); + + buf += variable->type->stride; + } + + variable->buffer->u.buffer.changed = 1; +} + /* ID3D10EffectVariable methods */
+static inline struct d3d10_effect_variable *impl_from_ID3D10EffectMatrixVariable(ID3D10EffectMatrixVariable *iface) +{ + return CONTAINING_RECORD(iface, struct d3d10_effect_variable, ID3D10EffectVariable_iface); +} + static BOOL STDMETHODCALLTYPE d3d10_effect_matrix_variable_IsValid(ID3D10EffectMatrixVariable *iface) { TRACE("iface %p\n", iface); @@ -5125,9 +5204,12 @@ static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetRawValue(ID3D10 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrix(ID3D10EffectMatrixVariable *iface, float *data) { - FIXME("iface %p, data %p stub!\n", iface, data); + struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectMatrixVariable(iface);
- return E_NOTIMPL; + TRACE("iface %p, data %p.\n", iface, data); + write_matrix_variable_to_buffer(effect_var, data, FALSE); + + return S_OK; }
static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrix(ID3D10EffectMatrixVariable *iface, @@ -5141,9 +5223,12 @@ static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrix(ID3D10Ef static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixArray(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_ID3D10EffectMatrixVariable(iface);
- return E_NOTIMPL; + TRACE("iface %p, data %p, offset %u, count %u.\n", iface, data, offset, count); + write_matrix_variable_array_to_buffer(effect_var, data, offset, count, FALSE); + + return S_OK; }
static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixArray(ID3D10EffectMatrixVariable *iface, @@ -5157,9 +5242,12 @@ static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixArray(ID3 static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixTranspose(ID3D10EffectMatrixVariable *iface, float *data) { - FIXME("iface %p, data %p stub!\n", iface, data); + struct d3d10_effect_variable *effect_var = impl_from_ID3D10EffectMatrixVariable(iface);
- return E_NOTIMPL; + TRACE("iface %p, data %p.\n", iface, data); + write_matrix_variable_to_buffer(effect_var, data, TRUE); + + return S_OK; }
static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixTranspose(ID3D10EffectMatrixVariable *iface, @@ -5173,9 +5261,12 @@ static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixTranspose static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_SetMatrixTransposeArray(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_ID3D10EffectMatrixVariable(iface);
- return E_NOTIMPL; + TRACE("iface %p, data %p, offset %u, count %u.\n", iface, data, offset, count); + write_matrix_variable_array_to_buffer(effect_var, data, offset, count, TRUE); + + return S_OK; }
static HRESULT STDMETHODCALLTYPE d3d10_effect_matrix_variable_GetMatrixTransposeArray(ID3D10EffectMatrixVariable *iface,