From edbd09fb4521a98692bc29b3afd1e7f17d7568dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Tue, 21 Aug 2012 14:52:17 +0200 Subject: [PATCH] d3dx9: Implement ID3DXConstantTable::SetMatrixTransposeArray. --- dlls/d3dx9_36/shader.c | 108 +++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 37 deletions(-) diff --git a/dlls/d3dx9_36/shader.c b/dlls/d3dx9_36/shader.c index 33e3aeb2977..11835ebc9a6 100644 --- a/dlls/d3dx9_36/shader.c +++ b/dlls/d3dx9_36/shader.c @@ -961,15 +961,47 @@ static HRESULT set_vector_array(ID3DXConstantTable *iface, IDirect3DDevice9 *dev return D3D_OK; } +static HRESULT set_float_matrix(FLOAT *matrix, const D3DXCONSTANT_DESC *desc, + UINT row_offset, UINT column_offset, UINT rows, UINT columns, + const void *data, D3DXPARAMETER_TYPE type, UINT src_columns) +{ + UINT i, j; + + switch (type) + { + case D3DXPT_FLOAT: + for (i = 0; i < rows; i++) + { + for (j = 0; j < columns; j++) + matrix[i * row_offset + j * column_offset] = ((FLOAT *)data)[i * src_columns + j]; + } + break; + case D3DXPT_INT: + for (i = 0; i < rows; i++) + { + for (j = 0; j < columns; j++) + matrix[i * row_offset + j * column_offset] = ((INT *)data)[i * src_columns + j]; + } + break; + default: + FIXME("Unhandled type %#x", type); + return D3DERR_INVALIDCALL; + } + + return D3D_OK; +} + static HRESULT set_matrix_array(ID3DXConstantTable *iface, IDirect3DDevice9 *device, D3DXHANDLE constant, const void *data, - UINT count, D3DXPARAMETER_TYPE type, UINT rows, UINT columns) + UINT count, D3DXPARAMETER_CLASS class, D3DXPARAMETER_TYPE type, UINT rows, UINT columns) { struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface); D3DXCONSTANT_DESC desc; HRESULT hr; UINT registers_per_matrix; - UINT i, j, k, desc_count = 1; + UINT i, desc_count = 1; + UINT num_rows, num_columns; UINT row_offset, column_offset; + const DWORD *data_ptr; FLOAT matrix[16] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, @@ -982,22 +1014,38 @@ static HRESULT set_matrix_array(ID3DXConstantTable *iface, IDirect3DDevice9 *dev return D3DERR_INVALIDCALL; } - if (desc.Class == D3DXPC_MATRIX_COLUMNS) + if (desc.Class == D3DXPC_MATRIX_ROWS || desc.Class == D3DXPC_MATRIX_COLUMNS) { - column_offset = 4; - row_offset = 1; - registers_per_matrix = desc.Columns; - } - else if (desc.Class == D3DXPC_MATRIX_ROWS) - { - column_offset = 1; - row_offset = 4; - registers_per_matrix = desc.Rows; + if (desc.Class == class) + { + column_offset = 1; + row_offset = 4; + } + else + { + column_offset = 4; + row_offset = 1; + } + + if (class == D3DXPC_MATRIX_ROWS) + { + num_rows = min(desc.Rows, rows); + num_columns = min(desc.Columns, columns); + } + else + { + num_rows = min(desc.Columns, columns); + num_columns = min(desc.Rows, rows); + } + + registers_per_matrix = (desc.Class == D3DXPC_MATRIX_ROWS) ? desc.Rows : desc.Columns; } else if (desc.Class == D3DXPC_SCALAR) { column_offset = 1; row_offset = 1; + num_rows = min(desc.Rows, rows); + num_columns = min(desc.Columns, columns); registers_per_matrix = 1; } else @@ -1009,33 +1057,18 @@ static HRESULT set_matrix_array(ID3DXConstantTable *iface, IDirect3DDevice9 *dev switch (desc.RegisterSet) { case D3DXRS_FLOAT4: + data_ptr = data; for (i = 0; i < count; i++) { if (registers_per_matrix * (i + 1) > desc.RegisterCount) break; - switch (type) - { - case D3DXPT_FLOAT: - for (j = 0; j < min(desc.Rows, rows); j++) - { - for (k = 0; k < min(desc.Columns, columns); k++) - matrix[j * row_offset + k * column_offset] = ((float *)data)[i * rows * columns + j * columns + k]; - } - break; - case D3DXPT_INT: - for (j = 0; j < min(desc.Rows, rows); j++) - { - for (k = 0; k < min(desc.Columns, columns); k++) - matrix[j * row_offset + k * column_offset] = (float)((int *)data)[i * rows * columns + j * columns + k]; - } - break; - default: - FIXME("Unhandled type %#x", type); - return D3DERR_INVALIDCALL; - } + hr = set_float_matrix(matrix, &desc, row_offset, column_offset, num_rows, num_columns, data_ptr, type, columns); + if (FAILED(hr)) return hr; set_float_shader_constant(This, device, desc.RegisterIndex + i * registers_per_matrix, matrix, registers_per_matrix); + + data_ptr += rows * columns; } break; default: @@ -1097,7 +1130,8 @@ static HRESULT WINAPI ID3DXConstantTableImpl_SetValue(ID3DXConstantTable *iface, return set_vector_array(iface, device, constant, data,elements, desc.Type); case D3DXPC_MATRIX_ROWS: case D3DXPC_MATRIX_COLUMNS: - return set_matrix_array(iface, device, constant, data, elements, desc.Type, desc.Rows, desc.Columns); + return set_matrix_array(iface, device, constant, data, elements, + D3DXPC_MATRIX_ROWS, desc.Type, desc.Rows, desc.Columns); default: FIXME("Unhandled parameter class %#x", desc.Class); return D3DERR_INVALIDCALL; @@ -1190,7 +1224,7 @@ static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrix(ID3DXConstantTable *iface TRACE("(%p)->(%p, %p, %p)\n", This, device, constant, matrix); - return set_matrix_array(iface, device, constant, matrix, 1, D3DXPT_FLOAT, 4, 4); + return set_matrix_array(iface, device, constant, matrix, 1, D3DXPC_MATRIX_ROWS, D3DXPT_FLOAT, 4, 4); } static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixArray(ID3DXConstantTable *iface, LPDIRECT3DDEVICE9 device, @@ -1200,7 +1234,7 @@ static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixArray(ID3DXConstantTable * TRACE("(%p)->(%p, %p, %p, %d)\n", This, device, constant, matrix, count); - return set_matrix_array(iface, device, constant, matrix, count, D3DXPT_FLOAT, 4, 4); + return set_matrix_array(iface, device, constant, matrix, count, D3DXPC_MATRIX_ROWS, D3DXPT_FLOAT, 4, 4); } static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixPointerArray(ID3DXConstantTable *iface, LPDIRECT3DDEVICE9 device, @@ -1228,9 +1262,9 @@ static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixTransposeArray(ID3DXConsta { struct ID3DXConstantTableImpl *This = impl_from_ID3DXConstantTable(iface); - FIXME("(%p)->(%p, %p, %p, %d): stub\n", This, device, constant, matrix, count); + TRACE("(%p)->(%p, %p, %p, %d)\n", This, device, constant, matrix, count); - return E_NOTIMPL; + return set_matrix_array(iface, device, constant, matrix, count, D3DXPC_MATRIX_COLUMNS, D3DXPT_FLOAT, 4, 4); } static HRESULT WINAPI ID3DXConstantTableImpl_SetMatrixTransposePointerArray(ID3DXConstantTable *iface, LPDIRECT3DDEVICE9 device,