5e1caabde6
Add a RenderTarget resource so the scene can render offscreen instead of straight to the swapchain. The editor uses it to show the scene inside the Viewport panel. - Rename AssetRegistry to ResourceRegistry (AssetTraits -> ResourceTraits, assets() -> resources()) and move the pools from engine/src/assets to engine/src/resources. It now covers non-asset GPU resources as well. - Replace loadMesh() with create<T>(...), and add create<RenderTarget>(), requestResize(), getExtent() and isAlive(). - Add RenderTarget and RenderTargetPool with RenderTargetHandle. Resizes are deferred and applied at the start of the next frame, when the GPU is idle. - Add Application::setSceneTarget(). With no target set, the scene still renders to the swapchain. With a target set, the scene renders offscreen and the swapchain receives only the UI. Frame extent and camera projection follow the target's size. - Add sophia::UI (Application::ui()) with image() and getTextureId() to draw a render target in an ImGui window, sizing the target to the available space. ImGuiRenderer now registers the target textures for this. - ViewportPanel takes the UI and a target, and draws the scene image in place of the flat background fill. - Update the testbed, the boids example, and the glossary for the rename.
52 lines
1.1 KiB
C++
52 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <sophia/types.hpp>
|
|
#include <vulkan/vulkan.hpp>
|
|
|
|
#include "device.hpp"
|
|
#include "image.hpp"
|
|
|
|
namespace sophia {
|
|
|
|
/**
|
|
* A place rendering can go. Currently always backed by an offscreen color
|
|
* image.
|
|
*
|
|
* Owned by the ResourceRegistry and addressed through a RenderTargetHandle.
|
|
*/
|
|
class RenderTarget {
|
|
public:
|
|
RenderTarget(Device& device, vk::Format format, u32 width, u32 height);
|
|
~RenderTarget();
|
|
|
|
RenderTarget(const RenderTarget&) = delete;
|
|
RenderTarget& operator=(const RenderTarget&) = delete;
|
|
|
|
Image& getImage() const { return *this->image; }
|
|
|
|
vk::Extent2D getExtent() const;
|
|
|
|
void requestResize(u32 width, u32 height);
|
|
|
|
/**
|
|
* Applies a pending resize. Waits for the GPU, so it must run before any of
|
|
* the frame's work (or any UI reference to the image) is recorded.
|
|
*/
|
|
void applyPendingResize();
|
|
|
|
private:
|
|
void create(u32 width, u32 height);
|
|
void destroy();
|
|
|
|
Device& device;
|
|
vk::Format format;
|
|
|
|
std::unique_ptr<Image> image;
|
|
|
|
std::optional<vk::Extent2D> pendingExtent;
|
|
};
|
|
|
|
} // namespace sophia
|