Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
|
Represents a single render stage or a render step that applies to the default (window) framebuffer. More...
#include <render_stage.hpp>
Public Member Functions | |
BaseRenderStage (const std::string &shaderFilepath) | |
Constructs a new BaseRenderStage object. | |
BaseRenderStage (const BaseRenderStage &other)=delete | |
BaseRenderStage (BaseRenderStage &&other)=delete | |
BaseRenderStage & | operator= (const BaseRenderStage &other)=delete |
BaseRenderStage & | operator= (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< Texture > | getTexture (const std::string &name) |
Gets a reference to an attached texture by its name. | |
std::shared_ptr< StaticMesh > | getMesh (const std::string &name) |
Gets a reference to an attached mesh by its name. | |
std::shared_ptr< Material > | getMaterial (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< ShaderProgram > | mShaderHandle |
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< OpaqueRenderUnit > | mOpaqueMeshQueue {} |
A queue containing all the opaque meshes to be rendered this frame by this stage. | |
std::priority_queue< LightRenderUnit > | mLightQueue {} |
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. | |
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.
BaseRenderStage::BaseRenderStage | ( | const std::string & | shaderFilepath | ) |
Constructs a new BaseRenderStage object.
shaderFilepath | The path to the JSON header for the shader program it uses. |
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.
name | The name of this material attachment. |
materialHandle | The actual handle to the attached material. |
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.
name | The name of the mesh being attached, from this stage's point-of-view. |
meshHandle | The actual handle to the attached mesh. |
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.
name | The name of the texture being attached, from this stage's point-of-view. |
textureHandle | The actual handle to the attached texture. |
|
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.
std::shared_ptr< Material > BaseRenderStage::getMaterial | ( | const std::string & | name | ) |
Gets a reference to an attached material by its name.
name | The name of an attached material. |
std::shared_ptr< StaticMesh > BaseRenderStage::getMesh | ( | const std::string & | name | ) |
Gets a reference to an attached mesh by its name.
name | The name of an attached mesh. |
std::shared_ptr< Texture > BaseRenderStage::getTexture | ( | const std::string & | name | ) |
Gets a reference to an attached texture by its name.
name | The name of an attached texture. |
void BaseRenderStage::setTargetViewport | ( | const SDL_Rect & | targetViewport | ) |
Sets the rendering area for this stage, a rectangular sub-region of the target texture.
targetViewport | The definition of the sub-region. |
|
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.
targetDimensions | The dimensions of the texture to which this stage will render. |
Implemented in ToyMaker::AdditionRenderStage, ToyMaker::BlurRenderStage, ToyMaker::GeometryRenderStage, ToyMaker::LightingRenderStage, ToyMaker::ResizeRenderStage, ToyMaker::ScreenRenderStage, ToyMaker::SkyboxRenderStage, and ToyMaker::TonemappingRenderStage.
void BaseRenderStage::submitToRenderQueue | ( | LightRenderUnit | lightRenderUnit | ) |
Adds a light render unit expected by this stage to its associated render queue.
lightRenderUnit |
void BaseRenderStage::submitToRenderQueue | ( | OpaqueRenderUnit | renderUnit | ) |
Adds an opaque render unit expected by this stage to its associated render queue.
renderUnit | The opaque render unit being added. |
void BaseRenderStage::useViewport | ( | ) |
Should be called once this stage's shader is made active; applies the viewport config associated with this render stage.
|
pure virtual |
Validates this stage by checking for availability of required resources, connections with adjacent render stages.
Implemented in ToyMaker::AdditionRenderStage, ToyMaker::BlurRenderStage, ToyMaker::GeometryRenderStage, ToyMaker::LightingRenderStage, ToyMaker::ResizeRenderStage, ToyMaker::ScreenRenderStage, ToyMaker::SkyboxRenderStage, and ToyMaker::TonemappingRenderStage.
|
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.