From fcec1c59bc4dac50e3ea2398f24c484dc8f172d1 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sat, 6 Jun 2026 13:49:08 -0700 Subject: [PATCH 1/2] GetViewportTransform made a public method for SpriteBatch --- Inc/SpriteBatch.h | 3 +++ Src/SpriteBatch.cpp | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Inc/SpriteBatch.h b/Inc/SpriteBatch.h index 52dee3f9..14db7b8d 100644 --- a/Inc/SpriteBatch.h +++ b/Inc/SpriteBatch.h @@ -135,6 +135,9 @@ namespace DirectX // Set viewport for sprite transformation DIRECTX_TOOLKIT_API void __cdecl SetViewport(const D3D11_VIEWPORT& viewPort); + // Gets transform matrix based on viewport (which may be read from the device context) and rotation mode + DIRECTX_TOOLKIT_API void GetViewportTransform(_In_ ID3D11DeviceContext* deviceContext, XMMATRIX& transformMatrix) const; + private: // Private implementation. struct Impl; diff --git a/Src/SpriteBatch.cpp b/Src/SpriteBatch.cpp index 35aaa068..4057d940 100644 --- a/Src/SpriteBatch.cpp +++ b/Src/SpriteBatch.cpp @@ -109,6 +109,8 @@ XM_ALIGNED_STRUCT(16) SpriteBatch::Impl : public AlignedNew bool mSetViewport; D3D11_VIEWPORT mViewPort; + XMMATRIX GetViewportTransform(_In_ ID3D11DeviceContext* deviceContext, DXGI_MODE_ROTATION rotation); + private: // Implementation helper methods. void GrowSpriteQueue(); @@ -125,7 +127,6 @@ XM_ALIGNED_STRUCT(16) SpriteBatch::Impl : public AlignedNew FXMVECTOR inverseTextureSize); static XMVECTOR GetTextureSize(_In_ ID3D11ShaderResourceView* texture); - XMMATRIX GetViewportTransform(_In_ ID3D11DeviceContext* deviceContext, DXGI_MODE_ROTATION rotation); // Constants. @@ -1192,3 +1193,10 @@ void SpriteBatch::SetViewport(const D3D11_VIEWPORT& viewPort) pImpl->mSetViewport = true; pImpl->mViewPort = viewPort; } + + +_Use_decl_annotations_ +void SpriteBatch::GetViewportTransform(ID3D11DeviceContext* deviceContext, XMMATRIX& transformMatrix) const +{ + transformMatrix = pImpl->GetViewportTransform(deviceContext,pImpl->mRotation); +} From ab633c940eef0ae0b5f1aa21269342d94a753e2b Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sat, 6 Jun 2026 13:53:35 -0700 Subject: [PATCH 2/2] Minor code review --- Src/SpriteBatch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/SpriteBatch.cpp b/Src/SpriteBatch.cpp index 4057d940..6cb18b28 100644 --- a/Src/SpriteBatch.cpp +++ b/Src/SpriteBatch.cpp @@ -1198,5 +1198,5 @@ void SpriteBatch::SetViewport(const D3D11_VIEWPORT& viewPort) _Use_decl_annotations_ void SpriteBatch::GetViewportTransform(ID3D11DeviceContext* deviceContext, XMMATRIX& transformMatrix) const { - transformMatrix = pImpl->GetViewportTransform(deviceContext,pImpl->mRotation); + transformMatrix = pImpl->GetViewportTransform(deviceContext, pImpl->mRotation); }