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::BaseRenderStage Class Referenceabstract

Represents a single render stage or a render step that applies to the default (window) framebuffer. More...

#include <render_stage.hpp>

Inheritance diagram for ToyMaker::BaseRenderStage:
ToyMaker::BaseOffscreenRenderStage ToyMaker::ScreenRenderStage ToyMaker::AdditionRenderStage ToyMaker::BlurRenderStage ToyMaker::GeometryRenderStage ToyMaker::LightingRenderStage ToyMaker::ResizeRenderStage ToyMaker::SkyboxRenderStage ToyMaker::TonemappingRenderStage

Public Member Functions

 BaseRenderStage (const std::string &shaderFilepath)
 Constructs a new BaseRenderStage object.
 
 BaseRenderStage (const BaseRenderStage &other)=delete
 
 BaseRenderStage (BaseRenderStage &&other)=delete
 
BaseRenderStageoperator= (const BaseRenderStage &other)=delete
 
BaseRenderStageoperator= (BaseRenderStage &&other)=delete
 
virtual ~BaseRenderStage ()
 Destroys the Base Render Stage object.
 
virtual void setup (const glm::u16vec2 &targetDimensions)=0
 Sets up the program per its configuration.
 
virtual void validate ()=0
 Validates this stage by checking for availability of required resources, connections with adjacent render stages.
 
virtual void execute ()=0
 Executes this render stage, presumably after preceding render stages have been executed.
 
void attachTexture (const std::string &name, std::shared_ptr< Texture > textureHandle)
 Attaches a named texture to this rendering stage.
 
void attachMesh (const std::string &name, std::shared_ptr< StaticMesh > meshHandle)
 Attaches a named texture to this rendering stage.
 
void attachMaterial (const std::string &name, std::shared_ptr< Material > materialHandle)
 Attaches a named material to this rendering stage.
 
std::shared_ptr< TexturegetTexture (const std::string &name)
 Gets a reference to an attached texture by its name.
 
std::shared_ptr< StaticMeshgetMesh (const std::string &name)
 Gets a reference to an attached mesh by its name.
 
std::shared_ptr< MaterialgetMaterial (const std::string &name)
 Gets a reference to an attached material by its name.
 
void useViewport ()
 Should be called once this stage's shader is made active; applies the viewport config associated with this render stage.
 
void setTargetViewport (const SDL_Rect &targetViewport)
 Sets the rendering area for this stage, a rectangular sub-region of the target texture.
 
void submitToRenderQueue (OpaqueRenderUnit renderUnit)
 Adds an opaque render unit expected by this stage to its associated render queue.
 
void submitToRenderQueue (LightRenderUnit lightRenderUnit)
 Adds a light render unit expected by this stage to its associated render queue.
 

Protected Attributes

GLuint mVertexArrayObject {}
 The OpenGL vertex array object associated with this object.
 
std::shared_ptr< ShaderProgrammShaderHandle
 A handle to the compiled and uploaded shader program associated with this render stage.
 
std::map< std::string, std::shared_ptr< Texture > > mTextureAttachments {}
 This stage's named texture attachments.
 
std::map< std::string, std::shared_ptr< StaticMesh > > mMeshAttachments {}
 This stage's named mesh attachments.
 
std::map< std::string, std::shared_ptr< Material > > mMaterialAttachments {}
 This stage's named material attachments.
 
std::priority_queue< OpaqueRenderUnitmOpaqueMeshQueue {}
 A queue containing all the opaque meshes to be rendered this frame by this stage.
 
std::priority_queue< LightRenderUnitmLightQueue {}
 A queue containing all the light units to be rendered this frame by this stage.
 
SDL_Rect mTargetViewport {0, 0, 800, 600}
 The rectangle defining the sub-region of its target texture to which this render stage renders.
 

Detailed Description

Represents a single render stage or a render step that applies to the default (window) framebuffer.

Also contains handles to the various resources required by it, the first of which is the OpenGL shader program it uses.

Constructor & Destructor Documentation

◆ BaseRenderStage()

BaseRenderStage::BaseRenderStage ( const std::string & shaderFilepath)

Constructs a new BaseRenderStage object.

Parameters
shaderFilepathThe path to the JSON header for the shader program it uses.

Member Function Documentation

◆ attachMaterial()

void BaseRenderStage::attachMaterial ( const std::string & name,
std::shared_ptr< Material > materialHandle )

Attaches a named material to this rendering stage.

The usage of this attachment depends on the implementation of the stage, but it can be used to specify, for example, render-stage-level configurations.

Parameters
nameThe name of this material attachment.
materialHandleThe actual handle to the attached material.

◆ attachMesh()

void BaseRenderStage::attachMesh ( const std::string & name,
std::shared_ptr< StaticMesh > meshHandle )

Attaches a named texture to this rendering stage.

The meaning of this attachment is defined according to this stage's implementation.

Parameters
nameThe name of the mesh being attached, from this stage's point-of-view.
meshHandleThe actual handle to the attached mesh.

◆ attachTexture()

void BaseRenderStage::attachTexture ( const std::string & name,
std::shared_ptr< Texture > textureHandle )

Attaches a named texture to this rendering stage.

The purpose of this attachment is defined by the pipeline it's being used in. It could be the texture holding the output for a previous stage, or could be where the results of this stage should be written.

Parameters
nameThe name of the texture being attached, from this stage's point-of-view.
textureHandleThe actual handle to the attached texture.

◆ execute()

virtual void ToyMaker::BaseRenderStage::execute ( )
pure virtual

Executes this render stage, presumably after preceding render stages have been executed.

Mostly anything can happen here, where this stage's behaviour is assumed to be defined in the material properties of the things it renders.

Implemented in ToyMaker::AdditionRenderStage, ToyMaker::BlurRenderStage, ToyMaker::GeometryRenderStage, ToyMaker::LightingRenderStage, ToyMaker::ResizeRenderStage, ToyMaker::ScreenRenderStage, ToyMaker::SkyboxRenderStage, and ToyMaker::TonemappingRenderStage.

◆ getMaterial()

std::shared_ptr< Material > BaseRenderStage::getMaterial ( const std::string & name)

Gets a reference to an attached material by its name.

Parameters
nameThe name of an attached material.
Returns
std::shared_ptr<Material> A handle to the attached material.

◆ getMesh()

std::shared_ptr< StaticMesh > BaseRenderStage::getMesh ( const std::string & name)

Gets a reference to an attached mesh by its name.

Parameters
nameThe name of an attached mesh.
Returns
std::shared_ptr<StaticMesh> A handle to the attached mesh.

◆ getTexture()

std::shared_ptr< Texture > BaseRenderStage::getTexture ( const std::string & name)

Gets a reference to an attached texture by its name.

Parameters
nameThe name of an attached texture.
Returns
std::shared_ptr<Texture> A handle to the attached texture.

◆ setTargetViewport()

void BaseRenderStage::setTargetViewport ( const SDL_Rect & targetViewport)

Sets the rendering area for this stage, a rectangular sub-region of the target texture.

Parameters
targetViewportThe definition of the sub-region.

◆ setup()

virtual void ToyMaker::BaseRenderStage::setup ( const glm::u16vec2 & targetDimensions)
pure virtual

Sets up the program per its configuration.

A part of this process includes creating and storing needed resources, and registering material properties used by this render stage.

Parameters
targetDimensionsThe dimensions of the texture to which this stage will render.
Todo
Much of this is finicky and poorly defined. Stricter requirements needed.

Implemented in ToyMaker::AdditionRenderStage, ToyMaker::BlurRenderStage, ToyMaker::GeometryRenderStage, ToyMaker::LightingRenderStage, ToyMaker::ResizeRenderStage, ToyMaker::ScreenRenderStage, ToyMaker::SkyboxRenderStage, and ToyMaker::TonemappingRenderStage.

◆ submitToRenderQueue() [1/2]

void BaseRenderStage::submitToRenderQueue ( LightRenderUnit lightRenderUnit)

Adds a light render unit expected by this stage to its associated render queue.

Parameters
lightRenderUnit

◆ submitToRenderQueue() [2/2]

void BaseRenderStage::submitToRenderQueue ( OpaqueRenderUnit renderUnit)

Adds an opaque render unit expected by this stage to its associated render queue.

Parameters
renderUnitThe opaque render unit being added.

◆ useViewport()

void BaseRenderStage::useViewport ( )

Should be called once this stage's shader is made active; applies the viewport config associated with this render stage.

See also
setTargetViewport()

◆ validate()

virtual void ToyMaker::BaseRenderStage::validate ( )
pure virtual

Validates this stage by checking for availability of required resources, connections with adjacent render stages.

Todo
Much of this is finicky and poorly defined. Stricter requirements needed.

Implemented in ToyMaker::AdditionRenderStage, ToyMaker::BlurRenderStage, ToyMaker::GeometryRenderStage, ToyMaker::LightingRenderStage, ToyMaker::ResizeRenderStage, ToyMaker::ScreenRenderStage, ToyMaker::SkyboxRenderStage, and ToyMaker::TonemappingRenderStage.

Member Data Documentation

◆ mVertexArrayObject

GLuint ToyMaker::BaseRenderStage::mVertexArrayObject {}
protected

The OpenGL vertex array object associated with this object.

In theory it saves this stage's shader from having to respecify where its associated buffers are on the GPU.

Todo
In practice, we end up doing that anyway because I'm an idiot.

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