diff options
Diffstat (limited to 'src/rendering/rhi.h')
| -rw-r--r-- | src/rendering/rhi.h | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/src/rendering/rhi.h b/src/rendering/rhi.h index 65f10b5..2110926 100644 --- a/src/rendering/rhi.h +++ b/src/rendering/rhi.h @@ -18,11 +18,33 @@ namespace Donut::RHI { enum class Format { - RGBA8, // 8-bit unorm colour (swapchain / LDR targets) + None, // no attachment (e.g. a target/pipeline with no depth) + Swapchain, // a pipeline's colour target = the presented image (resolved per backend) + RGBA8, // 8-bit unorm colour (LDR / off-screen) RGBA16F, // half-float colour (HDR / cubemap) D32, // 32-bit depth }; + // The attachment signature of a render pass / target: a colour format plus an + // optional depth format. A pipeline is compatible with any target sharing this + // signature, so this is what replaces "which render pass" as an explicit value. + struct RenderTargetFormat + { + Format color = Format::RGBA8; + Format depth = Format::None; + }; + + // The window the device presents into. GLFW is the windowing layer for every + // backend, so this carries the GLFWwindow*; each backend derives what it needs + // (a GL context, a Vulkan surface, later a CAMetalLayer / HWND) from it. The + // RHI names the concept "native window" rather than baking GLFW into its API. + struct NativeWindow + { + void* glfw_handle = nullptr; + int width = 0; + int height = 0; + }; + enum class BufferType { Vertex, Index, Uniform }; enum class Topology { Triangles, Lines }; enum class CullMode { None, Back, Front }; @@ -68,8 +90,7 @@ namespace Donut::RHI bool depth_test = false; bool depth_write = false; CompareOp depth_op = CompareOp::Less; - Format color_format = Format::RGBA8; // format of the target it renders into - bool has_depth = false; // target has a depth attachment + RenderTargetFormat target; // attachment signature of the pass it draws into }; // Records draws for one frame. Obtained from Device::begin_frame (targets the @@ -102,8 +123,7 @@ namespace Donut::RHI public: virtual ~Device() = default; - // glfwWindow: opaque GLFW handle (GL context for OpenGL, NO_API otherwise). - virtual auto init(void* glfwWindow, int width, int height) -> bool = 0; + virtual auto init(const NativeWindow& window) -> bool = 0; virtual auto shutdown() -> void = 0; virtual auto resize(int width, int height) -> void = 0; virtual auto wait_idle() -> void = 0; @@ -111,7 +131,7 @@ namespace Donut::RHI virtual auto create_buffer(BufferType type, size_t size, const void* data = nullptr) -> Ref<Buffer> = 0; virtual auto create_texture(int width, int height, Format format, Filter filter, const void* data = nullptr) -> Ref<Texture> = 0; virtual auto create_cubemap_from_hdri(const std::string& equirect_path) -> Ref<Texture> = 0; - virtual auto create_render_target(int width, int height, Format color, bool with_depth, + virtual auto create_render_target(int width, int height, Format color, Format depth = Format::None, Filter sample_filter = Filter::Linear, int mip_levels = 1) -> Ref<RenderTarget> = 0; virtual auto create_pipeline(const PipelineDesc& desc) -> Ref<Pipeline> = 0; |
