17 SCL_CORE_INFO(
"OpenGL Frame Buffer with id {} props changed.", Id);
27 return ColorAttachments[Index];
32 return DepthAttachment;
35void scl::gl_frame_buffer::Invalidate()
37 if (Id != 0) this->Free();
39 if (Props.IsSwapChainTarget) {
41 ClearConfig = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
42 SCL_CORE_INFO(
"OpenGL Frame Buffer swap chain target invalidated.");
47 glGenFramebuffers(1, &Id);
48 glBindFramebuffer(GL_FRAMEBUFFER, Id);
51 SCL_CORE_ASSERT(Props.ColorAttachmentsCount > 0 || Props.DepthAttachmentsCount > 0,
"At least one of attachments count must be > 0.");
52 SCL_CORE_ASSERT(Props.DepthAttachmentsCount <= 8,
"OpenGL support max 8 collor attachments per frame buffer.");
53 SCL_CORE_ASSERT(Props.DepthAttachmentsCount <= 1,
"OpenGL support max 1 depth attachment per frame buffer.");
56 std::vector<GLenum> active_color_attachments {};
57 image viewport(Props.Width, Props.Height, 4,
false);
58 ColorAttachments.resize(Props.ColorAttachmentsCount);
59 for (
int i = 0; i < Props.ColorAttachmentsCount; i++) {
62 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, ColorAttachments[i]->GetHandle(), 0);
63 active_color_attachments.push_back(GL_COLOR_ATTACHMENT0 + i);
65 if (Props.ColorAttachmentsCount == 0) glDrawBuffer(GL_NONE), glReadBuffer(GL_NONE);
66 else glDrawBuffers(Props.ColorAttachmentsCount, active_color_attachments.data());
68 if (Props.DepthAttachmentsCount == 1) {
70 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, DepthAttachment->GetHandle(), 0);
74 ClearConfig = ((Props.ColorAttachmentsCount > 0) * GL_COLOR_BUFFER_BIT) |
75 ((Props.DepthAttachmentsCount > 0) * GL_DEPTH_BUFFER_BIT);
78 SCL_CORE_ASSERT(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE,
"Frame buffer creation error!");
79 glBindFramebuffer(GL_FRAMEBUFFER, 0);
81 SCL_CORE_INFO(
"OpenGL Frame Buffer with id {}, width {}, height {}, color attachments {}, depth attachments invalidated.",
82 Id, Props.Width, Props.Height, Props.ColorAttachmentsCount, Props.DepthAttachmentsCount);
99 glBindFramebuffer(GL_FRAMEBUFFER, Id);
100 glViewport(0, 0, Props.Width, Props.Height);
105 glBindFramebuffer(GL_FRAMEBUFFER, 0);
111 Props.Height = Height;
117 if (Id != 0) glDeleteFramebuffers(1, &Id);
119 for (
auto &color_attachment : ColorAttachments) color_attachment.reset();
120 ColorAttachments.clear();
122 if (DepthAttachment) DepthAttachment.reset();
131 glClear(ClearConfig);
#define SCL_CORE_ASSERT(expr,...)
const shared< texture_2d > & GetColorAttachment(int Index) const override
void SetFrameBufferProps(const frame_buffer_props &Props)
void Bind() const override
gl_frame_buffer(const frame_buffer_props &Props)
void Resize(int Width, int Height) override
const frame_buffer_props & GetFrameBufferProps() const
void Unbind() const override
const shared< texture_2d > & GetDepthAttachment(int Index) const override
~gl_frame_buffer() override
static shared< texture_2d > Create(const image &Image, texture_type Type=texture_type::COLOR)
OpenGL frame buffer class definition class.
OpenGL texture class definition module.
#define SCL_CORE_SUCCES(...)
#define SCL_CORE_INFO(...)
std::shared_ptr< T > shared
Sculpto library prehompiled header. Defines common definitions, includes commonly used modules.