From 3f1632a1450a5879f337b4bd178e48880cd583f8 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 31 Mar 2021 11:35:17 -0700 Subject: `gfx` explicit transient resource management. (#1774) --- examples/example-base/example-base.h | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 examples/example-base/example-base.h (limited to 'examples/example-base/example-base.h') 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 gWindow; + uint32_t windowWidth; + uint32_t windowHeight; + + Slang::ComPtr gDevice; + + Slang::ComPtr gSwapchain; + Slang::ComPtr gFramebufferLayout; + Slang::List> gFramebuffers; + Slang::List> gTransientHeaps; + Slang::ComPtr gRenderPass; + Slang::ComPtr 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 +int innerMain() +{ + TApp app; + + if (SLANG_FAILED(app.initialize())) + { + return -1; + } + + platform::Application::run(app.getWindow()); + + app.finalize(); + return 0; +} -- cgit v1.2.3