// Copyright 2014 Intel Corporation All Rights Reserved // // Intel makes no representations about the suitability of this software for any purpose. // THIS SOFTWARE IS PROVIDED ""AS IS."" INTEL SPECIFICALLY DISCLAIMS ALL WARRANTIES, // EXPRESS OR IMPLIED, AND ALL LIABILITY, INCLUDING CONSEQUENTIAL AND OTHER INDIRECT DAMAGES, // FOR THE USE OF THIS SOFTWARE, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PROPRIETARY // RIGHTS, AND INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. // Intel does not assume any responsibility for any errors which may appear in this software // nor any responsibility to update it. #pragma once #include "RenderDevice.h" #include "SwapChain.h" #include "DeviceContext.h" #include "RefCntAutoPtr.hpp" #include "ThreadSignal.hpp" #include #include #include #include "camera.h" #include "settings.h" #include "simulation.h" #include "util.h" #include "gui.h" namespace AsteroidsDE { class Asteroids { public: Asteroids(const Settings &settings, AsteroidsSimulation* asteroids, GUI* gui, HWND hWnd, Diligent::RENDER_DEVICE_TYPE DevType); ~Asteroids(); void Render(float frameTime, const OrbitCamera& camera, const Settings& settings); void ResizeSwapChain(HWND outputWindow, unsigned int width, unsigned int height); void GetPerfCounters(float &UpdateTime, float &RenderTime); private: void CreateMeshes(); void InitializeTextureData(); void CreateGUIResources(); void RenderSubset(Diligent::Uint32 SubsetNum, Diligent::IDeviceContext *pCtx, const OrbitCamera& camera, Diligent::Uint32 startIdx, Diligent::Uint32 numAsteroids); void InitDevice(HWND hWnd, Diligent::RENDER_DEVICE_TYPE DevType); enum class BindingMode { Dynamic = 0, Mutable, TextureMutable, Bindless }m_BindingMode = BindingMode::TextureMutable; AsteroidsSimulation* mAsteroids = nullptr; GUI* mGUI = nullptr; Diligent::RefCntAutoPtr mSwapChain; Diligent::RefCntAutoPtr mDevice; Diligent::RefCntAutoPtr mDeviceCtxt; std::vector< Diligent::RefCntAutoPtr > mDeferredCtxt; std::vector< Diligent::RefCntAutoPtr > mCmdLists; std::vector< Diligent::ICommandList* > mCmdListPtrs; Diligent::Uint32 mBackBufferWidth, mBackBufferHeight; Diligent::Uint32 mNumSubsets = 0; std::vector mWorkerThreads; std::mutex mMutex; std::condition_variable mCondVar; ThreadingTools::Signal mUpdateSubsetsSignal; ThreadingTools::Signal mRenderSubsetsSignal; std::atomic_int m_NumThreadsCompleted; static void WorkerThreadFunc(Asteroids *pThis, Diligent::Uint32 ThreadNum); struct FrameAttribs { float frameTime; const OrbitCamera* camera; const Settings* settings; }mFrameAttribs; Diligent::RefCntAutoPtr mIndexBuffer; Diligent::RefCntAutoPtr mVertexBuffer; Diligent::RefCntAutoPtr mInstanceIDBuffer; std::vector> mAsteroidsDataBuffers; Diligent::RefCntAutoPtr mDrawConstantBuffer; Diligent::RefCntAutoPtr mSpriteVertexBuffer; Diligent::RefCntAutoPtr mSkyboxConstantBuffer; Diligent::RefCntAutoPtr mSkyboxVertexBuffer; Diligent::RefCntAutoPtr mAsteroidsPSO; std::vector< Diligent::RefCntAutoPtr > mAsteroidsSRBs; Diligent::RefCntAutoPtr mFontPSO; Diligent::RefCntAutoPtr mSpritePSO; Diligent::RefCntAutoPtr mSpriteSRB; Diligent::RefCntAutoPtr mFontSRB; Diligent::RefCntAutoPtr mSkyboxPSO; Diligent::RefCntAutoPtr mSkyboxSRB; std::map> mSpriteTextures; Diligent::RefCntAutoPtr mSkyboxSRV; Diligent::RefCntAutoPtr mFontTextureSRV; Diligent::RefCntAutoPtr mTextures[NUM_UNIQUE_TEXTURES]; Diligent::RefCntAutoPtr mTextureSRVs[NUM_UNIQUE_TEXTURES]; Diligent::RefCntAutoPtr mSamplerState; std::unique_ptr mSprite; UINT64 mPerfCounterFreq = 0; volatile LONG64 mUpdateTicks = 0, mRenderTicks = 0; }; } // namespace AsteroidsD3D11