BARE2D
BARE2D::FBORenderer Class Reference

The FBORenderer represents and manages an entire FrameBufferObject. This allows one to draw entire scenes first to a texture, then perform some operations on that texture, then draw that texture to the screen. Shaders have uniforms projectionMatrix (mat4), colourTexture (sampler2D), and depthTexture (sampler2D) More...

#include <FBORenderer.hpp>

+ Inheritance diagram for BARE2D::FBORenderer:
+ Collaboration diagram for BARE2D::FBORenderer:

Public Member Functions

 FBORenderer (std::string &fragShader, std::string &vertShader, unsigned int windowWidth, unsigned int windowHeight, unsigned int numColourAttachments=1)
 
virtual ~FBORenderer ()
 
virtual void init () override
 Initializes all necessary bits of the renderer. More...
 
virtual void initUniforms () override
 Initializes all uniforms, such as colour attachments, depth attachments, etc. More...
 
void setCamera (std::shared_ptr< Camera2D > &cam)
 
std::shared_ptr< Camera2DgetCamera ()
 
void disableAttachment (unsigned int index)
 
void enableAttachment (unsigned int index)
 
void disableAttachments ()
 
void enableAttachments ()
 
virtual void render () override
 Actually renders the contents to the screen! More...
 
virtual void begin () override
 Clears the necessary vectors, etc. to prepare for draw() calls, etc. More...
 
virtual void end () override
 Creates the renderbatches, does necessary stuff before render() call. More...
 
virtual void destroy () override
 Frees all necessary memory. More...
 
- Public Member Functions inherited from BARE2D::Renderer
 Renderer ()
 
virtual ~Renderer ()
 
ShaderProgramgetShader ()
 

Protected Member Functions

virtual void preRender () override
 Does stuff inside of the render function, within the shader's use. More...
 
virtual void createRenderBatches () override
 Constructs all of the render batches from data given by, say, draw() calls. More...
 
virtual void bind ()
 Binds the FBO and appropriate texture attachments. More...
 
virtual void unbind ()
 Unbinds the FBO + textures. More...
 
virtual void createTextures ()
 Creates all of the OpenGL textures, and takes their handles into m_colourTextureID, and m_depthTextureID. More...
 
virtual void createFBO ()
 Creates the OpenGL FBO instance and holds its handle in m_fboID;. More...
 
- Protected Member Functions inherited from BARE2D::Renderer
virtual void link (std::initializer_list< std::string > attributes)
 

Protected Attributes

GLuint m_fboID
 
GLuint * m_textureIDs = nullptr
 
unsigned int m_numTextures
 
std::shared_ptr< Camera2Dm_camera
 
std::string m_fragmentShaderPath
 
std::string m_vertexShaderPath
 
bool m_shaderHasDepth = false
 
- Protected Attributes inherited from BARE2D::Renderer
ShaderProgram m_shader
 
VAO m_vertexArrayObject
 
std::vector< RenderBatchm_batches
 

Detailed Description

The FBORenderer represents and manages an entire FrameBufferObject. This allows one to draw entire scenes first to a texture, then perform some operations on that texture, then draw that texture to the screen. Shaders have uniforms projectionMatrix (mat4), colourTexture (sampler2D), and depthTexture (sampler2D)

Definition at line 17 of file FBORenderer.hpp.

Constructor & Destructor Documentation

◆ FBORenderer()

BARE2D::FBORenderer::FBORenderer ( std::string &  fragShader,
std::string &  vertShader,
unsigned int  windowWidth,
unsigned int  windowHeight,
unsigned int  numColourAttachments = 1 
)

Definition at line 15 of file FBORenderer.cpp.

References m_camera, and m_numTextures.

◆ ~FBORenderer()

BARE2D::FBORenderer::~FBORenderer ( )
virtual

Definition at line 30 of file FBORenderer.cpp.

References m_textureIDs.

Member Function Documentation

◆ begin()

void BARE2D::FBORenderer::begin ( )
overridevirtual

Clears the necessary vectors, etc. to prepare for draw() calls, etc.

Reimplemented from BARE2D::Renderer.

Definition at line 134 of file FBORenderer.cpp.

References BARE2D::Renderer::begin(), bind(), BARE2D::Renderer::m_shader, and BARE2D::ShaderProgram::use().

+ Here is the call graph for this function:

◆ bind()

void BARE2D::FBORenderer::bind ( )
protectedvirtual

Binds the FBO and appropriate texture attachments.

Definition at line 363 of file FBORenderer.cpp.

References BARE2D::GLContext::bindTexture(), BARE2D::GLContextManager::getContext(), m_fboID, m_numTextures, m_textureIDs, and BARE2D::GLContext::setActiveTexture().

Referenced by begin(), and init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createFBO()

void BARE2D::FBORenderer::createFBO ( )
protectedvirtual

Creates the OpenGL FBO instance and holds its handle in m_fboID;.

Definition at line 341 of file FBORenderer.cpp.

References createTextures(), BARE2D::FBO_FAILURE, m_fboID, and BARE2D::throwFatalError().

Referenced by init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createRenderBatches()

void BARE2D::FBORenderer::createRenderBatches ( )
overrideprotectedvirtual

Constructs all of the render batches from data given by, say, draw() calls.

Implements BARE2D::Renderer.

Definition at line 192 of file FBORenderer.cpp.

References BARE2D::VAO::bindVBO(), BARE2D::Glyph::bottomLeft, BARE2D::Glyph::bottomRight, BARE2D::Renderer::m_batches, m_textureIDs, BARE2D::Renderer::m_vertexArrayObject, BARE2D::Glyph::texture, BARE2D::Glyph::topLeft, BARE2D::Glyph::topRight, and BARE2D::VAO::unbindVBO().

Referenced by render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createTextures()

void BARE2D::FBORenderer::createTextures ( )
protectedvirtual

Creates all of the OpenGL textures, and takes their handles into m_colourTextureID, and m_depthTextureID.

Definition at line 267 of file FBORenderer.cpp.

References BARE2D::GLContext::bindTexture(), BARE2D::GLContextManager::getContext(), m_camera, m_numTextures, m_shaderHasDepth, m_textureIDs, and BARE2D::GLContext::setActiveTexture().

Referenced by createFBO().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ destroy()

void BARE2D::FBORenderer::destroy ( )
overridevirtual

Frees all necessary memory.

Reimplemented from BARE2D::Renderer.

Definition at line 124 of file FBORenderer.cpp.

References BARE2D::Renderer::destroy(), m_fboID, m_numTextures, and m_textureIDs.

+ Here is the call graph for this function:

◆ disableAttachment()

void BARE2D::FBORenderer::disableAttachment ( unsigned int  index)

Definition at line 42 of file FBORenderer.cpp.

◆ disableAttachments()

void BARE2D::FBORenderer::disableAttachments ( )

Definition at line 50 of file FBORenderer.cpp.

References m_numTextures.

◆ enableAttachment()

void BARE2D::FBORenderer::enableAttachment ( unsigned int  index)

Definition at line 46 of file FBORenderer.cpp.

◆ enableAttachments()

void BARE2D::FBORenderer::enableAttachments ( )

Definition at line 56 of file FBORenderer.cpp.

References m_numTextures.

◆ end()

void BARE2D::FBORenderer::end ( )
overridevirtual

Creates the renderbatches, does necessary stuff before render() call.

Reimplemented from BARE2D::Renderer.

Definition at line 165 of file FBORenderer.cpp.

References BARE2D::Renderer::m_shader, unbind(), and BARE2D::ShaderProgram::unuse().

+ Here is the call graph for this function:

◆ getCamera()

std::shared_ptr< Camera2D > BARE2D::FBORenderer::getCamera ( )

Definition at line 38 of file FBORenderer.cpp.

References m_camera.

◆ init()

◆ initUniforms()

void BARE2D::FBORenderer::initUniforms ( )
overridevirtual

Initializes all uniforms, such as colour attachments, depth attachments, etc.

Reimplemented from BARE2D::Renderer.

Definition at line 110 of file FBORenderer.cpp.

References BARE2D::ShaderProgram::doesUniformExist(), m_numTextures, BARE2D::Renderer::m_shader, m_shaderHasDepth, and BARE2D::ShaderProgram::setUniform().

Referenced by init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ preRender()

void BARE2D::FBORenderer::preRender ( )
overrideprotectedvirtual

Does stuff inside of the render function, within the shader's use.

The camera should only be used to actually draw the FBO.

Reimplemented from BARE2D::Renderer.

Definition at line 172 of file FBORenderer.cpp.

References BARE2D::GLContext::bindTexture(), BARE2D::GLContextManager::getContext(), m_camera, m_numTextures, BARE2D::Renderer::m_shader, m_textureIDs, BARE2D::GLContext::setActiveTexture(), and BARE2D::ShaderProgram::setUniformMatrix().

Referenced by render().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ render()

void BARE2D::FBORenderer::render ( )
overridevirtual

◆ setCamera()

void BARE2D::FBORenderer::setCamera ( std::shared_ptr< Camera2D > &  cam)

Definition at line 34 of file FBORenderer.cpp.

References m_camera.

◆ unbind()

void BARE2D::FBORenderer::unbind ( )
protectedvirtual

Unbinds the FBO + textures.

Definition at line 375 of file FBORenderer.cpp.

References BARE2D::GLContextManager::getContext(), m_numTextures, and BARE2D::GLContext::unbindTexture().

Referenced by end(), and init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ m_camera

std::shared_ptr<Camera2D> BARE2D::FBORenderer::m_camera
protected

Definition at line 78 of file FBORenderer.hpp.

Referenced by createTextures(), FBORenderer(), getCamera(), preRender(), and setCamera().

◆ m_fboID

GLuint BARE2D::FBORenderer::m_fboID
protected

Definition at line 69 of file FBORenderer.hpp.

Referenced by bind(), createFBO(), destroy(), and init().

◆ m_fragmentShaderPath

std::string BARE2D::FBORenderer::m_fragmentShaderPath
protected

Definition at line 81 of file FBORenderer.hpp.

Referenced by init().

◆ m_numTextures

unsigned int BARE2D::FBORenderer::m_numTextures
protected

◆ m_shaderHasDepth

bool BARE2D::FBORenderer::m_shaderHasDepth = false
protected

Definition at line 84 of file FBORenderer.hpp.

Referenced by createTextures(), and initUniforms().

◆ m_textureIDs

GLuint* BARE2D::FBORenderer::m_textureIDs = nullptr
protected

◆ m_vertexShaderPath

std::string BARE2D::FBORenderer::m_vertexShaderPath
protected

Definition at line 81 of file FBORenderer.hpp.

Referenced by init().


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