Browse Source

togl/togles: set D3DMATRIX alignment to 16

mathlib-optimize
nillerusr 2 years ago
parent
commit
965ef97212
  1. 47
      public/mathlib/vmatrix.h
  2. 2
      public/togl/linuxwin/dxabstract_types.h
  3. 2
      public/togles/linuxwin/dxabstract_types.h

47
public/mathlib/vmatrix.h

@ -114,11 +114,15 @@ public:
const matrix3x4_t& As3x4() const; const matrix3x4_t& As3x4() const;
void CopyFrom3x4( const matrix3x4_t &m3x4 ); void CopyFrom3x4( const matrix3x4_t &m3x4 );
void Set3x4( matrix3x4_t& matrix3x4 ) const; void Set3x4( const matrix3x4_t& matrix3x4 );
bool operator==( const VMatrix& src ) const { bool operator==( const VMatrix& src ) const {
return !memcmp( src.m, m, sizeof(m) ); return src.m[0][0] == m[0][0] && src.m[0][1] == m[0][1] && src.m[0][2] == m[0][2] && src.m[0][3] == m[0][3] &&
src.m[1][0] == m[1][0] && src.m[1][1] == m[1][1] && src.m[1][2] == m[1][2] && src.m[1][3] == m[1][3] &&
src.m[2][0] == m[2][0] && src.m[2][1] == m[2][1] && src.m[2][2] == m[2][2] && src.m[2][3] == m[2][3] &&
src.m[3][0] == m[3][0] && src.m[3][1] == m[3][1] && src.m[3][2] == m[3][2] && src.m[3][3] == m[3][3];
} }
bool operator!=( const VMatrix& src ) const { return !( *this == src ); } bool operator!=( const VMatrix& src ) const { return !( *this == src ); }
#ifndef VECTOR_NO_SLOW_OPERATIONS #ifndef VECTOR_NO_SLOW_OPERATIONS
@ -512,14 +516,12 @@ inline void VMatrix::Init(
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Initialize from a 3x4 // Initialize from a 3x4
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline void VMatrix::Init( const matrix3x4_t& matrix3x4 ) inline void VMatrix::Init( const matrix3x4_t& _m )
{ {
memcpy(m, matrix3x4.Base(), sizeof( matrix3x4_t ) ); m[0][0] = _m[0][0]; m[0][1] = _m[0][1]; m[0][2] = _m[0][2]; m[0][3] = _m[0][3];
m[1][0] = _m[1][0]; m[1][1] = _m[1][1]; m[1][2] = _m[1][2]; m[1][3] = _m[1][3];
m[3][0] = 0.0f; m[2][0] = _m[2][0]; m[2][1] = _m[2][1]; m[2][2] = _m[2][2]; m[2][3] = _m[2][3];
m[3][1] = 0.0f; m[3][0] = 0.0f; m[3][1] = 0.0f; m[3][2] = 0.0f; m[3][3] = 1.0f;
m[3][2] = 0.0f;
m[3][3] = 1.0f;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -837,14 +839,14 @@ inline const matrix3x4_t& VMatrix::As3x4() const
inline void VMatrix::CopyFrom3x4( const matrix3x4_t &m3x4 ) inline void VMatrix::CopyFrom3x4( const matrix3x4_t &m3x4 )
{ {
memcpy( m, m3x4.Base(), sizeof( matrix3x4_t ) ); Init(m3x4);
m[3][0] = m[3][1] = m[3][2] = 0; }
m[3][3] = 1;
}
inline void VMatrix::Set3x4( matrix3x4_t& matrix3x4 ) const inline void VMatrix::Set3x4( const matrix3x4_t& _m )
{ {
memcpy(matrix3x4.Base(), m, sizeof( matrix3x4_t ) ); m[0][0] = _m[0][0]; m[0][1] = _m[0][1]; m[0][2] = _m[0][2]; m[0][3] = _m[0][3];
m[1][0] = _m[1][0]; m[1][1] = _m[1][1]; m[1][2] = _m[1][2]; m[1][3] = _m[1][3];
m[2][0] = _m[2][0]; m[2][1] = _m[2][1]; m[2][2] = _m[2][2]; m[2][3] = _m[2][3];
} }
#ifndef VECTOR_NO_SLOW_OPERATIONS #ifndef VECTOR_NO_SLOW_OPERATIONS
@ -1805,18 +1807,19 @@ inline void MatrixBuildScale( VMatrix &dst, const Vector& scale )
MatrixBuildScale( dst, scale.x, scale.y, scale.z ); MatrixBuildScale( dst, scale.x, scale.y, scale.z );
} }
// nillerusr: optimize this bruh later
inline void MatrixBuildPerspective( VMatrix &dst, float fovX, float fovY, float zNear, float zFar ) inline void MatrixBuildPerspective( VMatrix &dst, float fovX, float fovY, float zNear, float zFar )
{ {
// FIXME: collapse all of this into one matrix after we figure out what all should be in here. // FIXME: collapse all of this into one matrix after we figure out what all should be in here.
float width = 2 * zNear * tan( fovX * ( M_PI/180.0f ) * 0.5f ); float width = 2 * zNear * tan( fovX * ( M_PI/180.0f ) * 0.5f );
float height = 2 * zNear * tan( fovY * ( M_PI/180.0f ) * 0.5f ); float height = 2 * zNear * tan( fovY * ( M_PI/180.0f ) * 0.5f );
memset( dst.Base(), 0, sizeof( dst ) ); dst. Init(
dst[0][0] = 2.0F * zNear / width; 2.0f * zNear / width, 0.f, 0.f, 0.f,
dst[1][1] = 2.0F * zNear / height; 0.f, 2.0f * zNear / height, 0.f, 0.f,
dst[2][2] = -zFar / ( zNear - zFar ); 0.f, 0.f, -zFar / ( zNear - zFar ), zNear * zFar / ( zNear - zFar ),
dst[3][2] = 1.0f; 0.f, 0.f, 1.f, 0.f
dst[2][3] = zNear * zFar / ( zNear - zFar ); );
// negate X and Y so that X points right, and Y points up. // negate X and Y so that X points right, and Y points up.
VMatrix negateXY; VMatrix negateXY;
@ -1824,7 +1827,7 @@ inline void MatrixBuildPerspective( VMatrix &dst, float fovX, float fovY, float
negateXY[0][0] = -1.0f; negateXY[0][0] = -1.0f;
negateXY[1][1] = -1.0f; negateXY[1][1] = -1.0f;
MatrixMultiply( negateXY, dst, dst ); MatrixMultiply( negateXY, dst, dst );
VMatrix addW; VMatrix addW;
addW.Identity(); addW.Identity();
addW[0][3] = 1.0f; addW[0][3] = 1.0f;

2
public/togl/linuxwin/dxabstract_types.h

@ -1042,7 +1042,7 @@ typedef enum _D3DSHADER_PARAM_REGISTER_TYPE
D3DSPR_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum D3DSPR_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
} D3DSHADER_PARAM_REGISTER_TYPE; } D3DSHADER_PARAM_REGISTER_TYPE;
struct D3DMATRIX struct alignas(16) D3DMATRIX
{ {
union union
{ {

2
public/togles/linuxwin/dxabstract_types.h

@ -1042,7 +1042,7 @@ typedef enum _D3DSHADER_PARAM_REGISTER_TYPE
D3DSPR_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum D3DSPR_FORCE_DWORD = 0x7fffffff, // force 32-bit size enum
} D3DSHADER_PARAM_REGISTER_TYPE; } D3DSHADER_PARAM_REGISTER_TYPE;
struct D3DMATRIX struct alignas(16) D3DMATRIX
{ {
union union
{ {

Loading…
Cancel
Save