Skip to content

Commit

Permalink
Convert from XNAMath to DirectXMath for C++ compilation (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
walbourn authored Apr 2, 2021
1 parent 2b2bc9c commit 8d5b770
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 42 deletions.
67 changes: 25 additions & 42 deletions D3DX_DXGIFormatConvert.inl
Original file line number Diff line number Diff line change
Expand Up @@ -229,55 +229,33 @@ typedef uint4 XMUINT4;
#error C++ compilation required
#endif

#include <float.h>
#include <xnamath.h>
#ifndef D3DX11INLINE
#define D3DX11INLINE inline
#endif

#include <DirectXMath.h>

#include <algorithm>
#include <cfloat>
#include <cmath>

#define hlsl_precise

D3DX11INLINE FLOAT D3DX_Saturate_FLOAT(FLOAT _V)
namespace DirectX
{
return min(max(_V, 0), 1);
}
D3DX11INLINE bool D3DX_IsNan(FLOAT _V)

D3DX11INLINE float D3DX_Saturate_FLOAT(float _V)
{
return _V != _V;
return std::min<float>(std::max<float>(_V, 0), 1);
}
D3DX11INLINE FLOAT D3DX_Truncate_FLOAT(FLOAT _V)
D3DX11INLINE bool D3DX_IsNan(float _V)
{
return _V >= 0 ? floor(_V) : ceil(_V);
return isnan(_V);
}

// 2D Vector; 32 bit signed integer components
typedef struct _XMINT2
{
INT x;
INT y;
} XMINT2;

// 2D Vector; 32 bit unsigned integer components
typedef struct _XMUINT2
D3DX11INLINE float D3DX_Truncate_FLOAT(float _V)
{
UINT x;
UINT y;
} XMUINT2;

// 4D Vector; 32 bit signed integer components
typedef struct _XMINT4
{
INT x;
INT y;
INT z;
INT w;
} XMINT4;

// 4D Vector; 32 bit unsigned integer components
typedef struct _XMUINT4
{
UINT x;
UINT y;
UINT z;
UINT w;
} XMUINT4;
return _V >= 0 ? floorf(_V) : ceilf(_V);
}

#endif // HLSL_VERSION > 0

Expand Down Expand Up @@ -337,7 +315,7 @@ D3DX11INLINE FLOAT D3DX_SRGB_to_FLOAT(UINT val)
#if HLSL_VERSION > 0
return asfloat(D3DX_SRGBTable[val]);
#else
return *(FLOAT*)&D3DX_SRGBTable[val];
return *reinterpret_cast<const FLOAT*>(&D3DX_SRGBTable[val]);
#endif
}

Expand Down Expand Up @@ -800,4 +778,9 @@ D3DX11INLINE UINT D3DX_INT2_to_R16G16_SINT(XMINT2 unpackedInput)
return packedOutput;
}

#endif // __D3DX_DXGI_FORMAT_CONVERT_INL___
#if HLSL_VERSION > 0
#else
} // namespace DirectX;
#endif

#endif // __D3DX_DXGI_FORMAT_CONVERT_INL___
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
## Trademarks

This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies.

# Version History

April 2021 - Updated to use DirectXMath in the Windows SDK instead of legacy XNAMath from the DirectX SDK for C++ support

June 2010 - Release in legacy DirectX SDK

0 comments on commit 8d5b770

Please sign in to comment.