hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/src/rendering
diff options
context:
space:
mode:
Diffstat (limited to 'src/rendering')
-rw-r--r--src/rendering/framebuffer.cpp17
-rw-r--r--src/rendering/framebuffer.h65
-rw-r--r--src/rendering/renderer.h9
3 files changed, 91 insertions, 0 deletions
diff --git a/src/rendering/framebuffer.cpp b/src/rendering/framebuffer.cpp
new file mode 100644
index 0000000..e227dcf
--- /dev/null
+++ b/src/rendering/framebuffer.cpp
@@ -0,0 +1,17 @@
+#include "framebuffer.h"
+#include "renderer.h"
+
+#include "platform/opengl/opengl_framebuffer.h"
+
+namespace Donut
+{
+ Ref<Framebuffer> Framebuffer::create(const FramebufferSpecification& spec)
+ {
+ switch (Renderer::get_api())
+ {
+ case RendererAPI::API::OpenGL: return create_ref<OpenGLFramebuffer>(spec);
+ }
+
+ return nullptr;
+ }
+};
diff --git a/src/rendering/framebuffer.h b/src/rendering/framebuffer.h
new file mode 100644
index 0000000..1d42d85
--- /dev/null
+++ b/src/rendering/framebuffer.h
@@ -0,0 +1,65 @@
+#pragma once
+
+#include "core/memory.h"
+#include "texture.h"
+
+namespace Donut
+{
+ enum class FramebufferTextureFormat
+ {
+ None = 0,
+
+ RGBA8,
+ RED_INTEGER,
+
+ DEPTH24STENCIL8,
+
+ Depth = DEPTH24STENCIL8
+ };
+
+ struct FramebufferTextureSpecification
+ {
+ FramebufferTextureSpecification() = default;
+ FramebufferTextureSpecification(FramebufferTextureFormat format)
+ : texture_format(format) {}
+
+ FramebufferTextureFormat texture_format = FramebufferTextureFormat::None;
+ };
+
+ struct FramebufferAttachmentSpecification
+ {
+ FramebufferAttachmentSpecification() = default;
+ FramebufferAttachmentSpecification(std::initializer_list<FramebufferTextureSpecification> attachments)
+ : attachments(attachments) {}
+
+ std::vector<FramebufferTextureSpecification> attachments;
+ };
+
+ struct FramebufferSpecification
+ {
+ uint32_t Width = 0, Height = 0;
+ FramebufferAttachmentSpecification attachments;
+ uint32_t Samples = 1;
+
+ bool SwapChainTarget = false;
+ };
+
+ class Framebuffer
+ {
+ public:
+ virtual ~Framebuffer() = default;
+
+ virtual void bind() = 0;
+ virtual void unbind() = 0;
+
+ virtual void resize(uint32_t width, uint32_t height) = 0;
+ virtual int read_pixel(uint32_t attachment_index, int x, int y) = 0;
+
+ virtual void clear_attachment(uint32_t attachment_index, int value) = 0;
+ virtual uint32_t get_color_attachment_renderer_id(uint32_t index = 0) const = 0;
+
+ virtual const FramebufferSpecification& get_specification() const = 0;
+
+ static Ref<Framebuffer> create(const FramebufferSpecification& spec);
+ };
+};
diff --git a/src/rendering/renderer.h b/src/rendering/renderer.h
index 67ad998..ea200db 100644
--- a/src/rendering/renderer.h
+++ b/src/rendering/renderer.h
@@ -3,6 +3,7 @@
#include "core/memory.h"
#include "vertex_array.h"
#include "shader.h"
+#include "framebuffer.h"
#include <glm/glm.hpp>
@@ -41,6 +42,8 @@ namespace Donut
virtual void bind_image_texture(uint32_t texture_id,
uint32_t slot = 0,
bool read_only = false) = 0;
+ virtual void read_pixels(uint32_t x, uint32_t y, uint32_t width, uint32_t height,
+ uint32_t format, uint32_t type, void* pixels) = 0;
inline static API get_api() { return s_api; }
inline static void set_api(API api) { s_api = api; }
@@ -122,6 +125,12 @@ namespace Donut
s_renderer_api->bind_image_texture(texture_id, slot, read_only);
}
+ inline static void read_pixels(uint32_t x, uint32_t y, uint32_t width, uint32_t height,
+ uint32_t format, uint32_t type, void* pixels)
+ {
+ s_renderer_api->read_pixels(x, y, width, height, format, type, pixels);
+ }
+
private:
static Scope<RendererAPI> s_renderer_api;
};