54 lines
1.3 KiB
C
54 lines
1.3 KiB
C
|
|
#pragma once
|
||
|
|
|
||
|
|
#include <renderer/rhi/rhi.h>
|
||
|
|
#include <glad/glad.h>
|
||
|
|
#include <vector>
|
||
|
|
|
||
|
|
namespace extra2d {
|
||
|
|
|
||
|
|
// 前向声明
|
||
|
|
class GLTexture;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief OpenGL 帧缓冲实现
|
||
|
|
*/
|
||
|
|
class GLFramebuffer : public RHIFramebuffer {
|
||
|
|
public:
|
||
|
|
GLFramebuffer();
|
||
|
|
explicit GLFramebuffer(const RenderPassDesc& desc);
|
||
|
|
~GLFramebuffer() override;
|
||
|
|
|
||
|
|
bool create();
|
||
|
|
void destroy();
|
||
|
|
|
||
|
|
void bind() override;
|
||
|
|
void unbind() override;
|
||
|
|
|
||
|
|
uint32_t getColorAttachmentCount() const override;
|
||
|
|
TextureHandle getColorAttachment(uint32_t index) const override;
|
||
|
|
TextureHandle getDepthStencilAttachment() const override;
|
||
|
|
|
||
|
|
uint32_t getWidth() const override { return width_; }
|
||
|
|
uint32_t getHeight() const override { return height_; }
|
||
|
|
|
||
|
|
bool hasDepthStencil() const override;
|
||
|
|
bool isValid() const override;
|
||
|
|
bool isDefault() const override;
|
||
|
|
|
||
|
|
void setSize(uint32_t width, uint32_t height);
|
||
|
|
GLuint getGLFramebuffer() const { return framebuffer_; }
|
||
|
|
|
||
|
|
const RenderPassDesc& getDesc() const { return desc_; }
|
||
|
|
void clear(ClearFlags flags, const Color& color, float depth, uint8_t stencil);
|
||
|
|
|
||
|
|
private:
|
||
|
|
RenderPassDesc desc_;
|
||
|
|
GLuint framebuffer_;
|
||
|
|
uint32_t width_;
|
||
|
|
uint32_t height_;
|
||
|
|
std::vector<std::unique_ptr<GLTexture>> colorAttachments_;
|
||
|
|
std::unique_ptr<GLTexture> depthStencilAttachment_;
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace extra2d
|