diff options
| author | Yong He <yonghe@outlook.com> | 2021-03-31 11:35:17 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-31 11:35:17 -0700 |
| commit | 3f1632a1450a5879f337b4bd178e48880cd583f8 (patch) | |
| tree | db4adc2ac0f6113dfd4a97a0e2f7a0c4312ef48b /examples/example-base/example-base.h | |
| parent | 5fde038b1a6b3c8b335cd5b380c3ee8d15403052 (diff) | |
`gfx` explicit transient resource management. (#1774)
Diffstat (limited to 'examples/example-base/example-base.h')
| -rw-r--r-- | examples/example-base/example-base.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/examples/example-base/example-base.h b/examples/example-base/example-base.h new file mode 100644 index 000000000..ab7522f06 --- /dev/null +++ b/examples/example-base/example-base.h @@ -0,0 +1,52 @@ +#pragma once + +#include "slang-gfx.h" +#include "tools/platform/window.h" +#include "source/core/slang-basic.h" + +struct WindowedAppBase +{ +protected: + static const int kSwapchainImageCount = 2; + + Slang::RefPtr<platform::Window> gWindow; + uint32_t windowWidth; + uint32_t windowHeight; + + Slang::ComPtr<gfx::IDevice> gDevice; + + Slang::ComPtr<gfx::ISwapchain> gSwapchain; + Slang::ComPtr<gfx::IFramebufferLayout> gFramebufferLayout; + Slang::List<Slang::ComPtr<gfx::IFramebuffer>> gFramebuffers; + Slang::List<Slang::ComPtr<gfx::ITransientResourceHeap>> gTransientHeaps; + Slang::ComPtr<gfx::IRenderPassLayout> gRenderPass; + Slang::ComPtr<gfx::ICommandQueue> gQueue; + + Slang::Result initializeBase(const char* titile, int width, int height); + void createSwapchainFramebuffers(); + void mainLoop(); + + virtual void windowSizeChanged(); + +protected: + virtual void renderFrame(int framebufferIndex) = 0; +public: + platform::Window* getWindow() { return gWindow.Ptr(); } + virtual void finalize() { gQueue->wait(); } +}; + +template<typename TApp> +int innerMain() +{ + TApp app; + + if (SLANG_FAILED(app.initialize())) + { + return -1; + } + + platform::Application::run(app.getWindow()); + + app.finalize(); + return 0; +} |
