Files
Seele/src/Engine/Graphics/RenderTarget.h
T

177 lines
5.4 KiB
C++
Raw Normal View History

2023-10-26 18:37:29 +02:00
#pragma once
#include "Resources.h"
#include "Texture.h"
namespace Seele
{
namespace Gfx
{
class Window
{
public:
Window(const WindowCreateInfo &createInfo);
virtual ~Window();
virtual void beginFrame() = 0;
virtual void endFrame() = 0;
virtual void onWindowCloseEvent() = 0;
2023-11-01 23:12:30 +01:00
virtual PTexture2D getBackBuffer() = 0;
2023-10-26 18:37:29 +02:00
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) = 0;
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) = 0;
virtual void setMouseButtonCallback(std::function<void(MouseButton, InputAction, KeyModifier)> callback) = 0;
virtual void setScrollCallback(std::function<void(double, double)> callback) = 0;
virtual void setFileCallback(std::function<void(int, const char**)> callback) = 0;
virtual void setCloseCallback(std::function<void()> callback) = 0;
2023-11-15 00:06:00 +01:00
constexpr SeFormat getSwapchainFormat() const
2023-10-26 18:37:29 +02:00
{
return windowState.pixelFormat;
}
2023-11-15 00:06:00 +01:00
constexpr SeSampleCountFlags getNumSamples() const
2023-10-26 18:37:29 +02:00
{
return windowState.numSamples;
}
2023-11-15 00:06:00 +01:00
constexpr uint32 getWidth() const
2023-10-26 18:37:29 +02:00
{
return windowState.width;
}
2023-11-15 00:06:00 +01:00
constexpr uint32 getHeight() const
2023-10-26 18:37:29 +02:00
{
return windowState.height;
}
protected:
WindowCreateInfo windowState;
};
DEFINE_REF(Window)
class Viewport
{
public:
Viewport(PWindow owner, const ViewportCreateInfo &createInfo);
virtual ~Viewport();
virtual void resize(uint32 newX, uint32 newY) = 0;
virtual void move(uint32 newOffsetX, uint32 newOffsetY) = 0;
constexpr PWindow getOwner() const {return owner;}
2023-11-15 00:06:00 +01:00
constexpr uint32 getWidth() const {return sizeX;}
constexpr uint32 getHeight() const {return sizeY;}
2023-10-26 18:37:29 +02:00
constexpr uint32 getOffsetX() const {return offsetX;}
constexpr uint32 getOffsetY() const {return offsetY;}
Matrix4 getProjectionMatrix() const;
protected:
uint32 sizeX;
uint32 sizeY;
uint32 offsetX;
uint32 offsetY;
float fieldOfView;
PWindow owner;
};
DEFINE_REF(Viewport)
class RenderTargetAttachment
{
public:
RenderTargetAttachment(PTexture2D texture,
2023-11-15 00:06:00 +01:00
SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_LOAD,
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE,
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE);
virtual ~RenderTargetAttachment();
2023-10-26 18:37:29 +02:00
virtual PTexture2D getTexture()
{
return texture;
}
virtual SeFormat getFormat() const
{
return texture->getFormat();
}
virtual SeSampleCountFlags getNumSamples() const
{
return texture->getNumSamples();
}
2023-11-15 00:06:00 +01:00
virtual uint32 getWidth() const
2023-10-26 18:37:29 +02:00
{
2023-11-15 00:06:00 +01:00
return texture->getWidth();
2023-10-26 18:37:29 +02:00
}
2023-11-15 00:06:00 +01:00
virtual uint32 getHeight() const
2023-10-26 18:37:29 +02:00
{
2023-11-15 00:06:00 +01:00
return texture->getHeight();
2023-10-26 18:37:29 +02:00
}
inline SeAttachmentLoadOp getLoadOp() const { return loadOp; }
inline SeAttachmentStoreOp getStoreOp() const { return storeOp; }
inline SeAttachmentLoadOp getStencilLoadOp() const { return stencilLoadOp; }
inline SeAttachmentStoreOp getStencilStoreOp() const { return stencilStoreOp; }
SeClearValue clear;
SeColorComponentFlags componentFlags;
SeAttachmentLoadOp loadOp;
SeAttachmentStoreOp storeOp;
SeAttachmentLoadOp stencilLoadOp;
SeAttachmentStoreOp stencilStoreOp;
protected:
PTexture2D texture;
};
DEFINE_REF(RenderTargetAttachment)
class SwapchainAttachment : public RenderTargetAttachment
{
public:
SwapchainAttachment(PWindow owner,
2023-11-15 00:06:00 +01:00
SeAttachmentLoadOp loadOp = SE_ATTACHMENT_LOAD_OP_LOAD,
SeAttachmentStoreOp storeOp = SE_ATTACHMENT_STORE_OP_STORE,
SeAttachmentLoadOp stencilLoadOp = SE_ATTACHMENT_LOAD_OP_DONT_CARE,
SeAttachmentStoreOp stencilStoreOp = SE_ATTACHMENT_STORE_OP_DONT_CARE);
virtual ~SwapchainAttachment();
2023-10-26 18:37:29 +02:00
virtual PTexture2D getTexture() override
{
return owner->getBackBuffer();
}
virtual SeFormat getFormat() const override
{
return owner->getSwapchainFormat();
}
virtual SeSampleCountFlags getNumSamples() const override
{
return owner->getNumSamples();
}
2023-11-15 00:06:00 +01:00
virtual uint32 getWidth() const
2023-10-26 18:37:29 +02:00
{
2023-11-15 00:06:00 +01:00
return owner->getWidth();
2023-10-26 18:37:29 +02:00
}
2023-11-15 00:06:00 +01:00
virtual uint32 getHeight() const
2023-10-26 18:37:29 +02:00
{
2023-11-15 00:06:00 +01:00
return owner->getHeight();
2023-10-26 18:37:29 +02:00
}
private:
PWindow owner;
};
DEFINE_REF(SwapchainAttachment)
class RenderTargetLayout
{
public:
RenderTargetLayout();
2023-11-05 10:36:01 +01:00
RenderTargetLayout(PRenderTargetAttachment depthAttachment);
RenderTargetLayout(PRenderTargetAttachment colorAttachment, PRenderTargetAttachment depthAttachment);
RenderTargetLayout(Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachmet);
RenderTargetLayout(Array<PRenderTargetAttachment> inputAttachments, Array<PRenderTargetAttachment> colorAttachments, PRenderTargetAttachment depthAttachment);
Array<PRenderTargetAttachment> inputAttachments;
Array<PRenderTargetAttachment> colorAttachments;
PRenderTargetAttachment depthAttachment;
2023-10-26 18:37:29 +02:00
uint32 width;
uint32 height;
};
DEFINE_REF(RenderTargetLayout)
class RenderPass
{
public:
2023-11-01 23:12:30 +01:00
RenderPass(ORenderTargetLayout layout) : layout(std::move(layout)) {}
2023-10-26 18:37:29 +02:00
virtual ~RenderPass() {}
2023-11-05 10:36:01 +01:00
RenderPass(RenderPass&&) = default;
RenderPass& operator=(RenderPass&&) = default;
PRenderTargetLayout getLayout() const { return layout; }
2023-10-26 18:37:29 +02:00
protected:
2023-11-01 23:12:30 +01:00
ORenderTargetLayout layout;
2023-10-26 18:37:29 +02:00
};
DEFINE_REF(RenderPass)
}
}