3#include "structure/design_pattern/spk_activable_object.hpp"
4#include "structure/design_pattern/spk_synchronizable_object.hpp"
5#include "structure/graphics/spk_color.hpp"
6#include "structure/math/spk_vector2.hpp"
7#include "structure/opengl/spk_opengl_includes.hpp"
8#include "structure/opengl/spk_texture_object.hpp"
9#include "structure/opengl/spk_view_region.hpp"
10#include "utils/spk_opengl_utils.hpp"
18#include <unordered_map>
39 friend class FrameBufferObject;
76 case Attachment::Type::GreyScale:
77 setFormat(spk::OpenGL::TextureObject::Format::GreyLevel);
80 case Attachment::Type::TwoChannelColor:
81 setFormat(spk::OpenGL::TextureObject::Format::DualChannel);
84 case Attachment::Type::ThreeChannelColor:
85 setFormat(spk::OpenGL::TextureObject::Format::RGB);
88 case Attachment::Type::Color:
89 setFormat(spk::OpenGL::TextureObject::Format::RGBA);
92 case Attachment::Type::Depth:
93 setFormat(spk::OpenGL::TextureObject::Format::DepthComponent);
96 case Attachment::Type::DepthStencil:
97 setFormat(spk::OpenGL::TextureObject::Format::DepthStencil);
116 void _ensureAttachmentTypeAvailability(GLuint p_index,
Attachment::Type p_type)
const;
117 void _ensureAttachmentsValidity();
118 void _activateAttachment(GLuint p_index, Attachment &p_attachment);
119 void _activateAttachments();
120 void _attachTexture(GLuint p_index, Attachment &p_attachment);
121 void _attachAllTextures();
122 void _configureDrawBuffers();
127 void _onSynchronize()
override;
128 void _registerCallbacks();
132 GLuint _activeFrameBufferWhenActivating = 0;
134 spk::CachedData<GLuint> _id{OpenGLUtils::generateFrameBufferObjectID, OpenGLUtils::releaseFrameBufferObjectID};
135 std::unordered_map<GLuint, Attachment> _attachments;
136 spk::Vector2UInt _size = {0, 0};
186 void resize(
const spk::Vector2UInt &p_size);
192 const spk::Vector2UInt &
size()
const;
198 const spk::OpenGL::ViewRegion &
viewRegion()
const;
Stateful helper toggling between activated/deactivated states.
Definition spk_activable_object.hpp:20
Lazily generates and caches a value with optional custom destructor.
Definition spk_cached_data.hpp:26
Texture attachment with basic format presets for FBOs.
Definition spk_frame_buffer_object.hpp:38
Attachment(Type p_type=Type::Color)
Creates a texture attachment with a preset texture format.
Definition spk_frame_buffer_object.hpp:69
Type type() const noexcept
Returns the underlying attachment category.
Definition spk_frame_buffer_object.hpp:106
Type
Attachment storage format used for the framebuffer slot.
Definition spk_frame_buffer_object.hpp:46
const spk::Vector2UInt & size() const
Returns current framebuffer size.
Definition spk_frame_buffer_object.cpp:341
FrameBufferObject()
Constructs an empty framebuffer.
Definition spk_frame_buffer_object.cpp:242
FrameBufferObject & operator=(const FrameBufferObject &p_other)
Assigns framebuffer content from another instance.
Definition spk_frame_buffer_object.cpp:267
void addAttachment(const GLuint &p_index, Attachment::Type p_type)
Adds an attachment at the given color index.
Definition spk_frame_buffer_object.cpp:297
Attachment & attachment(const GLuint &p_index)
Accesses an attachment by index.
Definition spk_frame_buffer_object.cpp:311
bool hasAttachment(const GLuint &p_index) const
Checks if an attachment exists.
Definition spk_frame_buffer_object.cpp:321
void resize(const spk::Vector2UInt &p_size)
Resizes all attachments and viewport to the given size.
Definition spk_frame_buffer_object.cpp:326
const spk::OpenGL::ViewRegion & viewRegion() const
Returns the view region associated with this framebuffer.
Definition spk_frame_buffer_object.cpp:346
spk::OpenGL::TextureObject exportAttachmentTexture(GLuint p_index)
Exports an attachment texture by value (copy).
Definition spk_frame_buffer_object.cpp:363
void clear(const spk::Color &p_color, const ViewRegion::ClearMask &p_clearMask)
Clears the framebuffer with the given color and mask.
Definition spk_frame_buffer_object.cpp:351
void clearData()
Clears CPU data and marks for sync.
Definition spk_texture_object.cpp:351
void setData(const uint8_t *p_data, const spk::Vector2UInt &p_size, Format p_format=Format::RGBA)
Uploads pixel data from raw pointer.
Definition spk_texture_object.cpp:340
void resize(const spk::Vector2UInt &p_size)
Resizes CPU data and marks for sync.
Definition spk_texture_object.cpp:358
TextureObject(Format p_format=Format::RGBA, Filter p_filter={Filtering::Linear, Filtering::Linear}, Wrapper p_wrapper={Wrap::Repeat, Wrap::Repeat}, Mipmap p_mipmap=Mipmap::Activated)
Constructs a texture with format, filtering, and wrapping options.
Definition spk_texture_object.cpp:130
size_t sizeAsBytes() const
Returns CPU data size in bytes.
Definition spk_texture_object.cpp:330
Format
Supported GPU pixel formats.
Definition spk_texture_object.hpp:29
void setFormat(Format p_format)
Sets the texture format (affects upload interpretation).
Definition spk_texture_object.cpp:279
Manages viewport and scissor rectangles and clearing.
Definition spk_view_region.hpp:26
spk::Flags< ClearMode > ClearMask
Mask of buffers to clear at once.
Definition spk_view_region.hpp:41
Base for objects requiring deferred synchronization hooks.
Definition spk_synchronizable_object.hpp:10
void forceSynchronization()
Forces synchronization regardless of current flag.
Definition spk_synchronizable_object.hpp:54
void synchronize()
Performs synchronization if requested.
Definition spk_synchronizable_object.hpp:40
Axis-aligned rectangle defined by an anchor point and size.
Definition spk_extend_2d.hpp:24