aboutsummaryrefslogtreecommitdiff
path: root/src/rendering
diff options
context:
space:
mode:
Diffstat (limited to 'src/rendering')
-rw-r--r--src/rendering/black_hole_renderer.cpp8
-rw-r--r--src/rendering/rhi.h32
-rw-r--r--src/rendering/scene_renderer.cpp6
3 files changed, 33 insertions, 13 deletions
diff --git a/src/rendering/black_hole_renderer.cpp b/src/rendering/black_hole_renderer.cpp
index 46b002c..e4bc2a4 100644
--- a/src/rendering/black_hole_renderer.cpp
+++ b/src/rendering/black_hole_renderer.cpp
@@ -27,8 +27,8 @@ namespace Donut
{
m_device = &device;
- m_geo_lo = device.create_render_target(GEO_LO_W, GEO_LO_H, Format::RGBA8, false, Filter::Linear);
- m_geo_hi = device.create_render_target(GEO_HI_W, GEO_HI_H, Format::RGBA8, false, Filter::Linear);
+ m_geo_lo = device.create_render_target(GEO_LO_W, GEO_LO_H, Format::RGBA8, Format::None, Filter::Linear);
+ m_geo_hi = device.create_render_target(GEO_HI_W, GEO_HI_H, Format::RGBA8, Format::None, Filter::Linear);
// Fullscreen quad shared by the geodesic and present passes: pos.xy + uv.
const float quad[] = {
@@ -61,7 +61,7 @@ namespace Donut
{ ResourceKind::Texture, 4, "u_HDRIEnvironment" },
};
d.topology = Topology::Triangles;
- d.has_depth = false; // color-only off-screen target
+ d.target = { Format::RGBA8, Format::None }; // colour-only off-screen target
m_geo_pipeline = device.create_pipeline(d);
}
{
@@ -70,7 +70,7 @@ namespace Donut
d.vertex_layout = { 16, { { 0, 2, 0 }, { 1, 2, 8 } } };
d.resources = { { ResourceKind::Texture, 0, "u_ScreenTexture" } };
d.topology = Topology::Triangles;
- d.has_depth = true; // swapchain target carries depth (unused here)
+ d.target = { Format::Swapchain, Format::D32 }; // swapchain target (depth unused)
m_present_pipeline = device.create_pipeline(d);
}
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;
diff --git a/src/rendering/scene_renderer.cpp b/src/rendering/scene_renderer.cpp
index e276074..5ee7657 100644
--- a/src/rendering/scene_renderer.cpp
+++ b/src/rendering/scene_renderer.cpp
@@ -71,7 +71,7 @@ namespace Donut
d.topology = Topology::Lines;
d.blend = BlendMode::AlphaBlend;
d.depth_test = true; d.depth_write = false; d.depth_op = CompareOp::LessEqual;
- d.has_depth = true;
+ d.target = { Format::Swapchain, Format::D32 };
m_grid_pipeline = device.create_pipeline(d);
}
@@ -108,7 +108,7 @@ namespace Donut
{ ResourceKind::Texture, 1, "u_HDRIEnvironment" } };
d.topology = Topology::Triangles;
d.depth_test = true; d.depth_write = true; d.depth_op = CompareOp::Less;
- d.has_depth = true;
+ d.target = { Format::Swapchain, Format::D32 };
m_sphere_pipeline = device.create_pipeline(d);
}
@@ -133,7 +133,7 @@ namespace Donut
{ ResourceKind::Texture, 1, "u_Skybox" } };
d.topology = Topology::Triangles;
d.depth_test = false; d.depth_write = false;
- d.has_depth = true;
+ d.target = { Format::Swapchain, Format::D32 };
m_skybox_pipeline = device.create_pipeline(d);
}