diff options
Diffstat (limited to 'src/rendering')
| -rw-r--r-- | src/rendering/renderer_backend.h | 56 | ||||
| -rw-r--r-- | src/rendering/rhi/rhi.h | 108 |
2 files changed, 164 insertions, 0 deletions
diff --git a/src/rendering/renderer_backend.h b/src/rendering/renderer_backend.h new file mode 100644 index 0000000..51da214 --- /dev/null +++ b/src/rendering/renderer_backend.h @@ -0,0 +1,56 @@ +#pragma once + +#include <glm/glm.hpp> +#include <functional> +#include <string> +#include <vector> + +namespace Donut +{ + struct SceneObject + { + glm::vec3 position = { 0.0f, 2.0f, 0.0f }; + float radius = 2.0f; + glm::vec3 color = { 0.85f, 0.35f, 0.2f }; + }; + + struct BlackHoleParams + { + float disk_inner_rs = 3.0f; + float disk_outer_rs = 12.0f; + float temperature = 4800.0f; + float brightness = 0.9f; + float turbulence = 0.4f; + int quality_steps = 15000; + float fov_degrees = 60.0f; + }; + + class RendererBackend + { + public: + virtual ~RendererBackend() = default; + + virtual auto init(void* glfwWindow, int width, int height) -> bool = 0; + + virtual auto init_ui() -> bool = 0; + virtual auto shutdown() -> void = 0; + virtual auto resize(int width, int height) -> void = 0; + + virtual auto draw_frame(const glm::vec4& clear_color, + const std::function<void()>& build_ui) -> void = 0; + + virtual auto set_scene_mode(bool enabled) -> void = 0; + virtual auto is_scene_mode() const -> bool = 0; + virtual auto set_free_fly(bool enabled) -> void = 0; + virtual auto is_free_fly() const -> bool = 0; + virtual auto reset_camera() -> void = 0; + + virtual auto set_hdri(const std::string& path) -> void = 0; + virtual auto current_hdri() const -> const std::string& = 0; + virtual auto scene_objects() -> std::vector<SceneObject>& = 0; + virtual auto set_selected_object(int index) -> void = 0; + virtual auto black_hole_params() -> BlackHoleParams& = 0; + + virtual auto device_name() const -> const std::string& = 0; + }; +} diff --git a/src/rendering/rhi/rhi.h b/src/rendering/rhi/rhi.h new file mode 100644 index 0000000..b32df14 --- /dev/null +++ b/src/rendering/rhi/rhi.h @@ -0,0 +1,108 @@ +#pragma once + +#include "core/memory.h" +#include <glm/glm.hpp> +#include <cstdint> +#include <string> +#include <vector> +#include <functional> + +namespace Donut::rhi +{ + enum class Format + { + RGBA8, + RGBA16F, + D32, + }; + + enum class BufferType { Vertex, Index, Uniform }; + enum class Topology { Triangles, Lines }; + enum class CullMode { None, Back, Front }; + enum class BlendMode { Opaque, AlphaBlend }; + enum class CompareOp { Always, Less, LessEqual }; + enum class Filter { Nearest, Linear }; + + struct VertexAttribute { uint32_t location; uint32_t components; uint32_t offset; }; + struct VertexLayout { uint32_t stride = 0; std::vector<VertexAttribute> attributes; }; + + enum class ResourceKind { UniformBuffer, Texture }; + struct ResourceSlot { ResourceKind kind; uint32_t binding; }; + + class Buffer { public: virtual ~Buffer() = default; virtual auto update(const void* data, size_t size) -> void = 0; }; + class Texture { public: virtual ~Texture() = default; }; + class Pipeline{ public: virtual ~Pipeline() = default; }; + + class RenderTarget + { + public: + virtual ~RenderTarget() = default; + virtual auto width() const -> int = 0; + virtual auto height() const -> int = 0; + virtual auto color_texture() -> Texture* = 0; + }; + + struct PipelineDesc + { + std::string shader; + VertexLayout vertex_layout; + std::vector<ResourceSlot> resources; + Topology topology = Topology::Triangles; + CullMode cull = CullMode::None; + BlendMode blend = BlendMode::Opaque; + bool depth_test = false; + bool depth_write = false; + CompareOp depth_op = CompareOp::Less; + Format color_format = Format::RGBA8; + bool has_depth = false; + }; + + class CommandList + { + public: + virtual ~CommandList() = default; + + virtual auto begin_render_pass(RenderTarget* target, const glm::vec4& clear) -> void = 0; + virtual auto end_render_pass() -> void = 0; + + virtual auto bind_pipeline(Pipeline* pipeline) -> void = 0; + virtual auto set_viewport(int x, int y, int w, int h, bool flip_y = false) -> void = 0; + + virtual auto bind_uniform(uint32_t binding, Buffer* ubo) -> void = 0; + virtual auto bind_texture(uint32_t binding, Texture* texture) -> void = 0; + + virtual auto bind_vertex_buffer(Buffer* vb) -> void = 0; + virtual auto bind_index_buffer(Buffer* ib) -> void = 0; + + virtual auto draw(uint32_t vertex_count) -> void = 0; + virtual auto draw_indexed(uint32_t index_count) -> void = 0; + }; + + class Device + { + public: + virtual ~Device() = default; + + virtual auto init(void* glfwWindow, int width, int height) -> bool = 0; + virtual auto shutdown() -> void = 0; + virtual auto resize(int width, int height) -> void = 0; + virtual auto wait_idle() -> void = 0; + + 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, + Filter sample_filter = Filter::Linear, int mip_levels = 1) -> Ref<RenderTarget> = 0; + virtual auto create_pipeline(const PipelineDesc& desc) -> Ref<Pipeline> = 0; + + virtual auto begin_frame(const glm::vec4& clear) -> CommandList* = 0; + virtual auto end_frame() -> void = 0; + virtual auto record_offscreen(const std::function<void(CommandList&)>& record) -> void = 0; + + virtual auto init_imgui() -> void = 0; + virtual auto imgui_new_frame() -> void = 0; + virtual auto imgui_render(CommandList& swapchain_cmds) -> void = 0; + + virtual auto device_name() const -> const std::string& = 0; + }; +} |
