@@ -25,6 +25,19 @@ using namespace SimpleMath;
2525
2626namespace
2727{
28+ #if defined(__d3d12_h__) || defined(__d3d12_x_h__)
29+ enum Descriptors
30+ {
31+ Segoe18 = 0 ,
32+ Segoe22,
33+ Segoe36,
34+ CircleTex,
35+ GamepadTex,
36+ BackgroundTex,
37+ Count,
38+ };
39+ #endif
40+
2841 enum HelpFonts
2942 {
3043 SEGOE_UI_18PT = 0 ,
@@ -172,7 +185,12 @@ struct ATG::Help::CalloutBox
172185 if (type == CalloutType::LINE_TO_ANCHOR)
173186 {
174187 // callout circle is 12x12 so -6 from x and y to get top left coordinates
188+ #if defined(__d3d12_h__) || defined(__d3d12_x_h__)
189+ batch->Draw (help.m_descriptorHeap ->GetGpuHandle (Descriptors::CircleTex), help.m_circleTexSize ,
190+ Vector2 (calloutLine.x - 6 , calloutLine.y - 6 ));
191+ #elif defined(__d3d11_h__) || defined(__d3d11_x_h__)
175192 batch->Draw (help.m_circleTex .Get (), Vector2 (calloutLine.x - 6 , calloutLine.y - 6 ));
193+ #endif
176194 }
177195
178196 SpriteFont* spriteFont = help.m_spriteFonts [font].get ();
@@ -724,6 +742,57 @@ ATG::Help::~Help()
724742 }
725743}
726744
745+ #if defined(__d3d12_h__) || defined(__d3d12_x_h__)
746+ void ATG::Help::Render (ID3D12GraphicsCommandList* commandList)
747+ {
748+ // Set the descriptor heaps
749+ ID3D12DescriptorHeap* descriptorHeaps[] =
750+ {
751+ m_descriptorHeap->Heap ()
752+ };
753+ commandList->SetDescriptorHeaps (_countof (descriptorHeaps), descriptorHeaps);
754+
755+ D3D12_VIEWPORT vp1{ 0 .0f , 0 .0f , static_cast <float >(m_screenSize.right ), static_cast <float >(m_screenSize.bottom ),
756+ D3D12_MIN_DEPTH, D3D12_MAX_DEPTH };
757+
758+ m_spriteBatch->SetViewport (vp1);
759+ m_spriteBatch->Begin (commandList, SpriteSortMode_Immediate);
760+
761+ // Draw background image
762+ m_spriteBatch->Draw (m_descriptorHeap->GetGpuHandle (Descriptors::BackgroundTex), m_backgroundTexSize, m_screenSize);
763+
764+ // Draw gamepad controller
765+ m_spriteBatch->Draw (m_descriptorHeap->GetGpuHandle (Descriptors::GamepadTex), m_gamepadTexSize, m_screenSize);
766+
767+ m_spriteBatch->End ();
768+
769+ D3D12_VIEWPORT vp2{ 0 .0f , 0 .f , 1920 .f , 1080 .f , D3D12_MIN_DEPTH, D3D12_MAX_DEPTH };
770+ m_spriteBatch->SetViewport (vp2);
771+ m_spriteBatch->Begin (commandList, SpriteSortMode_Deferred);
772+
773+ // Process sprites
774+ for (size_t j = 0 ; j < m_calloutCount; ++j)
775+ {
776+ m_callouts[j].Render (*this , m_spriteBatch.get ());
777+ }
778+
779+ m_spriteBatch->End ();
780+
781+ XMMATRIX proj = XMMatrixOrthographicOffCenterRH (0 .f , 1920 .f , 1080 .f , 0 .f , 0 .f , 1 .f );
782+ m_lineEffect->SetProjection (proj);
783+
784+ m_lineEffect->Apply (commandList);
785+
786+ m_primBatch->Begin (commandList);
787+
788+ for (size_t j = 0 ; j < m_calloutCount; ++j)
789+ {
790+ m_callouts[j].Render (m_primBatch.get ());
791+ }
792+
793+ m_primBatch->End ();
794+ }
795+ #elif defined(__d3d11_h__) || defined(__d3d11_x_h__)
727796void ATG::Help::Render ()
728797{
729798 CD3D11_VIEWPORT vp1 (0 .0f , 0 .0f , static_cast <float >(m_screenSize.right ), static_cast <float >(m_screenSize.bottom ));
@@ -769,11 +838,11 @@ void ATG::Help::Render()
769838
770839 m_primBatch->End ();
771840}
841+ #endif
772842
773843void ATG::Help::ReleaseDevice ()
774844{
775845 m_spriteBatch.reset ();
776- m_states.reset ();
777846 m_primBatch.reset ();
778847 m_lineEffect.reset ();
779848
@@ -782,13 +851,71 @@ void ATG::Help::ReleaseDevice()
782851 m_spriteFonts[i].reset ();
783852 }
784853
785- m_lineLayout.Reset ();
786854 m_circleTex.Reset ();
787855 m_gamepadTex.Reset ();
788856 m_backgroundTex.Reset ();
857+
858+ #if defined(__d3d12_h__) || defined(__d3d12_x_h__)
859+ m_descriptorHeap.reset ();
860+ #elif defined(__d3d11_h__) || defined(__d3d11_x_h__)
861+ m_states.reset ();
862+ m_lineLayout.Reset ();
789863 m_context.Reset ();
864+ #endif
790865}
791866
867+ #if defined(__d3d12_h__) || defined(__d3d12_x_h__)
868+ void ATG::Help::RestoreDevice (ID3D12Device* device, ResourceUploadBatch& uploadBatch, const RenderTargetState& rtState)
869+ {
870+ m_descriptorHeap = std::make_unique<DescriptorHeap>(device, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, Descriptors::Count);
871+
872+ SpriteBatchPipelineStateDescription sbPsoDesc (rtState, &CommonStates::AlphaBlend);
873+ m_spriteBatch = std::make_unique<SpriteBatch>(device, uploadBatch, sbPsoDesc);
874+
875+ m_primBatch = std::make_unique<PrimitiveBatch<VertexPositionColor>>(device);
876+
877+ EffectPipelineStateDescription fxPsoDesc (&VertexPositionColor::InputLayout, CommonStates::Opaque,
878+ CommonStates::DepthNone, CommonStates::CullNone, rtState, D3D12_PRIMITIVE_TOPOLOGY_TYPE_LINE);
879+ m_lineEffect = std::make_unique<BasicEffect>(device, EffectFlags::VertexColor, fxPsoDesc);
880+
881+ #if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
882+ wchar_t buff[MAX_PATH];
883+ DX::FindMediaFile (buff, MAX_PATH, L" Media//Fonts//SegoeUI_18.spritefont" );
884+ m_spriteFonts[SEGOE_UI_18PT] = std::make_unique<SpriteFont>(device, uploadBatch, buff, m_descriptorHeap->GetCpuHandle (Descriptors::Segoe18), m_descriptorHeap->GetGpuHandle (Descriptors::Segoe18));
885+
886+ DX::FindMediaFile (buff, MAX_PATH, L" Media//Fonts//SegoeUI_22.spritefont" );
887+ m_spriteFonts[SEGOE_UI_22PT] = std::make_unique<SpriteFont>(device, uploadBatch, buff, m_descriptorHeap->GetCpuHandle (Descriptors::Segoe22), m_descriptorHeap->GetGpuHandle (Descriptors::Segoe22));
888+
889+ DX::FindMediaFile (buff, MAX_PATH, L" Media//Fonts//SegoeUI_36.spritefont" );
890+ m_spriteFonts[SEGOE_UI_36PT] = std::make_unique<SpriteFont>(device, uploadBatch, buff, m_descriptorHeap->GetCpuHandle (Descriptors::Segoe36), m_descriptorHeap->GetGpuHandle (Descriptors::Segoe36));
891+
892+ DX::FindMediaFile (buff, MAX_PATH, L" Media//Textures//callout_circle.dds" );
893+ DX::ThrowIfFailed (CreateDDSTextureFromFileEx (device, uploadBatch, buff, 0 , D3D12_RESOURCE_FLAG_NONE, m_linearColors, false , m_circleTex.ReleaseAndGetAddressOf ()));
894+
895+ DX::FindMediaFile (buff, MAX_PATH, L" Media//Textures//gamepad.dds" );
896+ DX::ThrowIfFailed (CreateDDSTextureFromFileEx (device, uploadBatch, buff, 0 , D3D12_RESOURCE_FLAG_NONE, m_linearColors, false , m_gamepadTex.ReleaseAndGetAddressOf ()));
897+
898+ DX::FindMediaFile (buff, MAX_PATH, L" Media//Textures//ATGSampleBackground.DDS" );
899+ DX::ThrowIfFailed (CreateDDSTextureFromFileEx (device, uploadBatch, buff, 0 , D3D12_RESOURCE_FLAG_NONE, m_linearColors, false , m_backgroundTex.ReleaseAndGetAddressOf ()));
900+ #else
901+ m_spriteFonts[SEGOE_UI_18PT] = std::make_unique<SpriteFont>(device, uploadBatch, L" SegoeUI_18.spritefont" , m_descriptorHeap->GetCpuHandle (Descriptors::Segoe18), m_descriptorHeap->GetGpuHandle (Descriptors::Segoe18));
902+ m_spriteFonts[SEGOE_UI_22PT] = std::make_unique<SpriteFont>(device, uploadBatch, L" SegoeUI_22.spritefont" , m_descriptorHeap->GetCpuHandle (Descriptors::Segoe22), m_descriptorHeap->GetGpuHandle (Descriptors::Segoe22));
903+ m_spriteFonts[SEGOE_UI_36PT] = std::make_unique<SpriteFont>(device, uploadBatch, L" SegoeUI_36.spritefont" , m_descriptorHeap->GetCpuHandle (Descriptors::Segoe36), m_descriptorHeap->GetGpuHandle (Descriptors::Segoe36));
904+
905+ DX::ThrowIfFailed (CreateDDSTextureFromFileEx (device, uploadBatch, L" callout_circle.dds" , 0 , D3D12_RESOURCE_FLAG_NONE, m_linearColors, false , m_circleTex.ReleaseAndGetAddressOf ()));
906+ DX::ThrowIfFailed (CreateDDSTextureFromFileEx (device, uploadBatch, L" gamepad.dds" , 0 , D3D12_RESOURCE_FLAG_NONE, m_linearColors, false , m_gamepadTex.ReleaseAndGetAddressOf ()));
907+ DX::ThrowIfFailed (CreateDDSTextureFromFileEx (device, uploadBatch, L" ATGSampleBackground.DDS" , 0 , D3D12_RESOURCE_FLAG_NONE, m_linearColors, false , m_backgroundTex.ReleaseAndGetAddressOf ()));
908+ #endif
909+
910+ DirectX::CreateShaderResourceView (device, m_circleTex.Get (), m_descriptorHeap->GetCpuHandle (Descriptors::CircleTex), false );
911+ DirectX::CreateShaderResourceView (device, m_gamepadTex.Get (), m_descriptorHeap->GetCpuHandle (Descriptors::GamepadTex), false );
912+ DirectX::CreateShaderResourceView (device, m_backgroundTex.Get (), m_descriptorHeap->GetCpuHandle (Descriptors::BackgroundTex), false );
913+
914+ m_circleTexSize = XMUINT2 (uint32_t (m_circleTex->GetDesc ().Width ), uint32_t (m_circleTex->GetDesc ().Height ));
915+ m_gamepadTexSize = XMUINT2 (uint32_t (m_gamepadTex->GetDesc ().Width ), uint32_t (m_gamepadTex->GetDesc ().Height ));
916+ m_backgroundTexSize = XMUINT2 (uint32_t (m_backgroundTex->GetDesc ().Width ), uint32_t (m_backgroundTex->GetDesc ().Height ));
917+ }
918+ #elif defined(__d3d11_h__) || defined(__d3d11_x_h__)
792919void ATG::Help::RestoreDevice (ID3D11DeviceContext* context)
793920{
794921 m_context = context;
@@ -847,6 +974,7 @@ void ATG::Help::RestoreDevice(ID3D11DeviceContext* context)
847974 DX::ThrowIfFailed (CreateDDSTextureFromFileEx (device.Get (), L" ATGSampleBackground.DDS" , 0 , D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0 , 0 , m_linearColors, nullptr , m_backgroundTex.ReleaseAndGetAddressOf ()));
848975#endif
849976}
977+ #endif
850978
851979void ATG::Help::SetWindow (const RECT& output)
852980{
0 commit comments