Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ToyMaker::Framebuffer Class Reference

A wrapper class over OpenGL framebuffers. More...

#include <framebuffer.hpp>

Inheritance diagram for ToyMaker::Framebuffer:
ToyMaker::Resource< Framebuffer > ToyMaker::IResource

Public Member Functions

 Framebuffer (GLuint framebuffer, glm::vec2 dimensions, GLuint nColorAttachments, const std::vector< std::shared_ptr< Texture > > &colorBuffers, std::unique_ptr< RBO > rbo)
 Assuming an allocated OpenGL framebuffer already exists, constructs a Framebuffer object and hands over resources passed as arguments.
 
 ~Framebuffer () override
 Destroys the framebuffer object.
 
 Framebuffer (const Framebuffer &other)
 
 Framebuffer (Framebuffer &&other)
 
Framebufferoperator= (const Framebuffer &other)
 
Framebufferoperator= (Framebuffer &&other)
 
std::size_t addTargetColorBufferHandle (std::shared_ptr< Texture > colorBufferHandle)
 Attaches a new color buffer to this framebuffer.
 
std::vector< std::shared_ptr< const Texture > > getTargetColorBufferHandles () const
 Returns a vector of handles to this framebuffer's color buffers.
 
const std::vector< std::shared_ptr< Texture > > & getTargetColorBufferHandles ()
 Returns a constant vector of handles to this framebuffer's color buffers.
 
bool hasAttachedRBO () const
 Answers whether this framebuffer has an RBO attached.
 
bool hasOwnRBO () const
 Answers whether an RBO description was specified when creating this framebuffer.
 
RBOgetOwnRBO ()
 Gets the RBO owned by this framebuffer.
 
void attachRBO (RBO &rbo)
 Attaches the RBO (of possibly another framebuffer) to this framebuffer object.
 
void detachRBO ()
 Detaches any RBOs currently attached to this framebuffer.
 
void bind ()
 Makes this framebuffer the currently active framebuffer in this OpenGL context.
 
glm::u16vec2 getDimensions () const
 Gets the dimensions specified for this framebuffer.
 
void unbind ()
 Unbind this framebuffer (or in other words, bind the default framebuffer)
 
- Public Member Functions inherited from ToyMaker::Resource< Framebuffer >
std::string getResourceTypeName_ () const override
 Get the resource type string for this resource.
 
- Public Member Functions inherited from ToyMaker::IResource
virtual ~IResource ()=default
 Destroy the IResource object.
 

Static Public Member Functions

static std::string getResourceTypeName ()
 Gets the resource type string associated with the Framebuffer resource.
 

Private Member Functions

void attachRBO_ (RBO &rbo)
 Attaches an RBO associated with another Framebuffer to this object.
 
void detachRBO_ ()
 Unbinds any RBO currently attached to this framebuffer.
 
void destroyResource ()
 Destroys resources associated with this framebuffer.
 
void releaseResource ()
 Releases resources associated with this framebuffer, allowing other object(s) to manage them instead.
 
void copyResource (const Framebuffer &other)
 Copies resources associated with another framebuffer.
 
void stealResource (Framebuffer &other)
 Steals resources associated with another framebuffer.
 

Private Attributes

GLuint mID {}
 The ID corresponding to this framebuffer.
 
std::unique_ptr< RBOmOwnRBO {}
 The RBO owned by this framebuffer, if such a one exists.
 
GLuint mNColorAttachments {}
 The number of color attachments active on this framebuffer when render is called.
 
glm::vec2 mDimensions {}
 The dimensions, in pixels, for textures attached to this framebuffer.
 
std::vector< std::shared_ptr< Texture > > mTextureHandles {}
 All color buffers associated with this framebuffer, owned by this framebuffer.
 
bool mHasAttachedRBO { false }
 Tracks whether an RBO was attached to this framebuffer (including ones that aren't owned by it).
 

Additional Inherited Members

- Protected Member Functions inherited from ToyMaker::Resource< Framebuffer >
 Resource (int explicitlyInitializeMe)
 Construct a new resource object.
 
- Protected Member Functions inherited from ToyMaker::IResource
 IResource ()=default
 Construct a new IResource object.
 
- Static Protected Member Functions inherited from ToyMaker::IResource
template<typename TResource>
static void RegisterResource ()
 Registers this resource as a Resource type with the ResourceDatabase.
 

Detailed Description

A wrapper class over OpenGL framebuffers.

Framebuffers are, in essence, a collection of buffers that relate to each other in some way. Each framebuffer must have either an RBO or color buffer or both, and may have multiple color buffers. Their actual usage depends on the requirements of the program or module using them.

The window to which an application renders is also a texture belonging to a special framebuffer, managed by default by OpenGL itself, with an ID of 0.

Constructor & Destructor Documentation

◆ Framebuffer()

Framebuffer::Framebuffer ( GLuint framebuffer,
glm::vec2 dimensions,
GLuint nColorAttachments,
const std::vector< std::shared_ptr< Texture > > & colorBuffers,
std::unique_ptr< RBO > rbo )

Assuming an allocated OpenGL framebuffer already exists, constructs a Framebuffer object and hands over resources passed as arguments.

Parameters
framebufferThe ID of the framebuffer being given to this object.
dimensionsThe dimensions of the framebuffer, in pixels.
nColorAttachmentsThe number of color attachments in use by this framebuffer.
colorBuffersHandles to the actual color buffers in use by this framebuffer.
rboA reference to the RBO being used by this framebuffer.

Member Function Documentation

◆ addTargetColorBufferHandle()

std::size_t Framebuffer::addTargetColorBufferHandle ( std::shared_ptr< Texture > colorBufferHandle)

Attaches a new color buffer to this framebuffer.

Parameters
colorBufferHandleA handle to the color buffer being attached.
Returns
std::size_t The index corresponding to the attached color buffer.

◆ attachRBO()

void Framebuffer::attachRBO ( RBO & rbo)

Attaches the RBO (of possibly another framebuffer) to this framebuffer object.

Parameters
rboReference to the RBO being attached to this framebuffer.

◆ attachRBO_()

void Framebuffer::attachRBO_ ( RBO & rbo)
private

Attaches an RBO associated with another Framebuffer to this object.

Parameters
rboThe RBO being attached.

◆ copyResource()

void Framebuffer::copyResource ( const Framebuffer & other)
private

Copies resources associated with another framebuffer.

Parameters
otherThe framebuffer being copied from.

◆ getDimensions()

glm::u16vec2 ToyMaker::Framebuffer::getDimensions ( ) const
inline

Gets the dimensions specified for this framebuffer.

Returns
glm::u16vec2 The dimensions, in pixels, for this framebuffer object.

◆ getOwnRBO()

RBO & Framebuffer::getOwnRBO ( )

Gets the RBO owned by this framebuffer.

Returns
RBO& Reference to the RBO owned by this framebuffer.

◆ getResourceTypeName()

static std::string ToyMaker::Framebuffer::getResourceTypeName ( )
inlinestatic

Gets the resource type string associated with the Framebuffer resource.

Returns
std::string The resource type string for Framebuffers.

◆ getTargetColorBufferHandles() [1/2]

const std::vector< std::shared_ptr< Texture > > & Framebuffer::getTargetColorBufferHandles ( )

Returns a constant vector of handles to this framebuffer's color buffers.

Returns
const std::vector<std::shared_ptr<Texture>>& Const reference to the vector of color buffer handles.

◆ getTargetColorBufferHandles() [2/2]

std::vector< std::shared_ptr< const Texture > > Framebuffer::getTargetColorBufferHandles ( ) const

Returns a vector of handles to this framebuffer's color buffers.

Returns
std::vector<std::shared_ptr<const Texture>> Vector of color buffer handles.

◆ hasAttachedRBO()

bool Framebuffer::hasAttachedRBO ( ) const

Answers whether this framebuffer has an RBO attached.

Return values
trueAn RBO corresponding to this framebuffer exists.
falseAn RBO corresponding to this framebuffer does not exist.

◆ hasOwnRBO()

bool Framebuffer::hasOwnRBO ( ) const

Answers whether an RBO description was specified when creating this framebuffer.

This would mean that the RBO with this framebuffer is owned by this framebuffer.

Return values
true
false

◆ stealResource()

void Framebuffer::stealResource ( Framebuffer & other)
private

Steals resources associated with another framebuffer.

Parameters
otherThe framebuffer being stolen from.

The documentation for this class was generated from the following files: