| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #include "pch.h"
- #include "TemplateAppMain.h"
- #include "Common\DirectXHelper.h"
- using namespace TemplateApp;
- using namespace Windows::Foundation;
- using namespace Windows::System::Threading;
- using namespace Concurrency;
- // The DirectX 12 Application template is documented at http://go.microsoft.com/fwlink/?LinkID=613670&clcid=0x409
- // Loads and initializes application assets when the application is loaded.
- TemplateAppMain::TemplateAppMain()
- {
- // TODO: Change the timer settings if you want something other than the default variable timestep mode.
- // e.g. for 60 FPS fixed timestep update logic, call:
- /*
- m_timer.SetFixedTimeStep(true);
- m_timer.SetTargetElapsedSeconds(1.0 / 60);
- */
- }
- // Creates and initializes the renderers.
- void TemplateAppMain::CreateRenderers(const std::shared_ptr<DX::DeviceResources>& deviceResources)
- {
- // TODO: Replace this with your app's content initialization.
- m_sceneRenderer = std::unique_ptr<Sample3DSceneRenderer>(new Sample3DSceneRenderer(deviceResources));
- OnWindowSizeChanged();
- }
- // Updates the application state once per frame.
- void TemplateAppMain::Update()
- {
- // Update scene objects.
- m_timer.Tick([&]()
- {
- // TODO: Replace this with your app's content update functions.
- m_sceneRenderer->Update(m_timer);
- });
- }
- // Renders the current frame according to the current application state.
- // Returns true if the frame was rendered and is ready to be displayed.
- bool TemplateAppMain::Render()
- {
- // Don't try to render anything before the first Update.
- if (m_timer.GetFrameCount() == 0)
- {
- return false;
- }
- // Render the scene objects.
- // TODO: Replace this with your app's content rendering functions.
- return m_sceneRenderer->Render();
- }
- // Updates application state when the window's size changes (e.g. device orientation change)
- void TemplateAppMain::OnWindowSizeChanged()
- {
- // TODO: Replace this with the size-dependent initialization of your app's content.
- m_sceneRenderer->CreateWindowSizeDependentResources();
- }
- // Notifies the app that it is being suspended.
- void TemplateAppMain::OnSuspending()
- {
- // TODO: Replace this with your app's suspending logic.
- // Process lifetime management may terminate suspended apps at any time, so it is
- // good practice to save any state that will allow the app to restart where it left off.
- m_sceneRenderer->SaveState();
- // If your application uses video memory allocations that are easy to re-create,
- // consider releasing that memory to make it available to other applications.
- }
- // Notifes the app that it is no longer suspended.
- void TemplateAppMain::OnResuming()
- {
- // TODO: Replace this with your app's resuming logic.
- }
- // Notifies renderers that device resources need to be released.
- void TemplateAppMain::OnDeviceRemoved()
- {
- // TODO: Save any necessary application or renderer state and release the renderer
- // and its resources which are no longer valid.
- m_sceneRenderer->SaveState();
- m_sceneRenderer = nullptr;
- }
|