diff options
Diffstat (limited to 'src/Rendering')
| -rw-r--r-- | src/Rendering/Framebuffer.cpp | 17 | ||||
| -rw-r--r-- | src/Rendering/Framebuffer.h | 65 | ||||
| -rw-r--r-- | src/Rendering/Renderer.h | 9 |
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..1e95c6d --- /dev/null +++ b/src/Rendering/Framebuffer.cpp @@ -0,0 +1,17 @@ +#include "Framebuffer.h" +#include "Renderer.h" + +#include "Platform/OpenGL/OpenGLFramebuffer.h" + +namespace Donut +{ + Ref<Framebuffer> Framebuffer::Create(const FramebufferSpecification& spec) + { + switch (Renderer::GetAPI()) + { + case RendererAPI::API::OpenGL: return CreateRef<OpenGLFramebuffer>(spec); + } + + return nullptr; + } +}; diff --git a/src/Rendering/Framebuffer.h b/src/Rendering/Framebuffer.h new file mode 100644 index 0000000..e4c1481 --- /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) + : TextureFormat(format) {} + + FramebufferTextureFormat TextureFormat = 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 ReadPixel(uint32_t attachmentIndex, int x, int y) = 0; + + virtual void ClearAttachment(uint32_t attachmentIndex, int value) = 0; + virtual uint32_t GetColorAttachmentRendererID(uint32_t index = 0) const = 0; + + virtual const FramebufferSpecification& GetSpecification() const = 0; + + static Ref<Framebuffer> Create(const FramebufferSpecification& spec); + }; +}; diff --git a/src/Rendering/Renderer.h b/src/Rendering/Renderer.h index d6c4154..6e87411 100644 --- a/src/Rendering/Renderer.h +++ b/src/Rendering/Renderer.h @@ -3,6 +3,7 @@ #include "Core/Memory.h" #include "VertexArray.h" #include "Shader.h" +#include "Framebuffer.h" #include <glm/glm.hpp> @@ -41,6 +42,8 @@ namespace Donut virtual void BindImageTexture(uint32_t textureID, uint32_t slot = 0, bool readOnly = false) = 0; + virtual void ReadPixels(uint32_t x, uint32_t y, uint32_t width, uint32_t height, + uint32_t format, uint32_t type, void* pixels) = 0; inline static API GetAPI() { return s_API; } inline static void SetAPI(API api) { s_API = api; } @@ -122,6 +125,12 @@ namespace Donut s_RendererAPI->BindImageTexture(textureID, slot, readOnly); } + inline static void ReadPixels(uint32_t x, uint32_t y, uint32_t width, uint32_t height, + uint32_t format, uint32_t type, void* pixels) + { + s_RendererAPI->ReadPixels(x, y, width, height, format, type, pixels); + } + private: static Scope<RendererAPI> s_RendererAPI; }; |
