Implement SetMatrix/SetMatrixArray and
SetMatrixTranspose/SetMatrixTransposeArray methods for the matrix effect
variable interface.
Signed-off-by: Connor McAdams <conmanx360(a)gmail.com>
---
dlls/d3d10/d3d10_private.h | 5 ++
dlls/d3d10/effect.c | 110 ++++++++++++++++++++++++++++++++++---
2 files changed, 107 insertions(+), 8 deletions(-)
diff --git a/dlls/d3d10/d3d10_private.h b/dlls/d3d10/d3d10_private.h
index f83ff0d4c9..e02ea376bb 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_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 9f92b590bc..f49c5d656f 100644
--- a/dlls/d3d10/effect.c
+++ b/dlls/d3d10/effect.c
@@ -5073,8 +5073,90 @@ 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 *dst,
+ struct d3d10_matrix *src, BOOL transpose)
+{
+ int row, col;
+ int col_count = !transpose ? variable->type->column_count : variable->type->row_count;
+ int row_count = !transpose ? variable->type->row_count : variable->type->column_count;
+ BOOL major = variable->type->type_class == D3D10_SVC_MATRIX_COLUMNS ? TRUE : FALSE;
+
+ if (transpose)
+ major = !major;
+
+ if (major)
+ {
+ for (col = 0; col < col_count; ++col)
+ {
+ for (row = 0; row < row_count; ++row)
+ dst[(col * 4) + row] = src->m[row][col];
+ }
+ }
+ else
+ {
+ for (row = 0; row < row_count; ++row)
+ {
+ for (col = 0; col < col_count; ++col)
+ dst[(row * 4) + col] = src->m[row][col];
+ }
+ }
+}
+
+static void write_matrix_variable_to_buffer(struct d3d10_effect_variable *variable, void *src_data, BOOL transpose)
+{
+ BYTE *dst = variable->buffer->u.buffer.local_buffer + variable->buffer_offset;
+
+ write_matrix_to_buffer(variable, (float *)dst, src_data, transpose);
+
+ variable->buffer->u.buffer.changed = TRUE;
+}
+
+static void write_matrix_variable_array_to_buffer(struct d3d10_effect_variable *variable, void *src_data, UINT offset,
+ UINT count, BOOL transpose)
+{
+ BYTE *dst = variable->buffer->u.buffer.local_buffer + variable->buffer_offset;
+ struct d3d10_matrix *src = src_data;
+ unsigned int i;
+
+ if (!variable->type->element_count)
+ {
+ write_matrix_variable_to_buffer(variable, src_data, transpose);
+ return;
+ }
+
+ if (offset >= variable->type->element_count)
+ {
+ WARN("Offset %u larger than element count %u, ignoring.\n", offset, variable->type->element_count);
+ return;
+ }
+
+ if (count > variable->type->element_count - offset)
+ {
+ WARN("Offset %u, count %u overruns the variable (element count %u), fixing up.\n",
+ offset, count, variable->type->element_count);
+ count = variable->type->element_count - offset;
+ }
+
+ if (offset)
+ dst += variable->type->stride * offset;
+
+ for (i = 0; i < count; ++i)
+ {
+ write_matrix_to_buffer(variable, (float *)dst, &src[i], transpose);
+
+ dst += variable->type->stride;
+ }
+
+ variable->buffer->u.buffer.changed = TRUE;
+}
+
/* 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);
@@ -5231,9 +5313,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,
@@ -5247,9 +5332,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,
@@ -5263,9 +5351,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,
@@ -5279,9 +5370,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,
--
2.20.1