Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
ModelRenderer Class Referenceabstract

Class ModelRenderer: Abstract base class for all model renders. More...

#include <ModelRenderer.h>

Inheritance diagram for ModelRenderer:

Public Member Functions

 ModelRenderer ()
 
virtual ~ModelRenderer ()
 
virtual void Submit (int cullGroup, CModel *model)=0
 Submit: Submit a model for rendering this frame. More...
 
virtual void PrepareModels ()=0
 PrepareModels: Calculate renderer data for all previously submitted models. More...
 
virtual void UploadModels (Renderer::Backend::IDeviceCommandContext *deviceCommandContext)=0
 Upload renderer data for all previously submitted models to backend. More...
 
virtual void EndFrame ()=0
 EndFrame: Remove all models from the list of submitted models. More...
 
virtual void Render (Renderer::Backend::IDeviceCommandContext *deviceCommandContext, const RenderModifierPtr &modifier, const CShaderDefines &context, int cullGroup, int flags)=0
 Render: Render submitted models, using the given RenderModifier to setup the fragment stage. More...
 

Static Public Member Functions

static void Init ()
 Initialise global settings. More...
 
static void CopyPositionAndNormals (const CModelDefPtr &mdef, const VertexArrayIterator< CVector3D > &Position, const VertexArrayIterator< CVector3D > &Normal)
 CopyPositionAndNormals: Copy unanimated object-space vertices and normals into the given vertex array. More...
 
static void BuildPositionAndNormals (CModel *model, const VertexArrayIterator< CVector3D > &Position, const VertexArrayIterator< CVector3D > &Normal)
 BuildPositionAndNormals: Build animated vertices and normals, transformed into world space. More...
 
static void BuildColor4ub (CModel *model, const VertexArrayIterator< CVector3D > &Normal, const VertexArrayIterator< SColor4ub > &Color)
 BuildColor4ub: Build lighting colors for the given model, based on previously calculated world space normals. More...
 
static void BuildUV (const CModelDefPtr &mdef, const VertexArrayIterator< float[2]> &UV, int UVset)
 BuildUV: Copy UV coordinates into the given vertex array. More...
 
static void BuildIndices (const CModelDefPtr &mdef, const VertexArrayIterator< u16 > &Indices)
 BuildIndices: Create the indices array for the given CModelDef. More...
 
static void GenTangents (const CModelDefPtr &mdef, std::vector< float > &newVertices, bool gpuSkinning)
 GenTangents: Generate tangents for the given CModelDef. More...
 

Detailed Description

Class ModelRenderer: Abstract base class for all model renders.

A ModelRenderer manages a per-frame list of models.

It is supposed to be derived in order to create new ways in which the per-frame list of models can be managed (for batching, for transparent rendering, etc.) or potentially for rarely used special effects.

A typical ModelRenderer will delegate vertex transformation/setup to a ModelVertexRenderer. It will delegate fragment stage setup to a RenderModifier.

For most purposes, you should use a BatchModelRenderer with specialized ModelVertexRenderer and RenderModifier implementations.

It is suggested that a derived class implement the provided generic Render function, however in some cases it may be necessary to supply a Render function with a different prototype.

ModelRenderer also contains a number of static helper functions for building vertex arrays.

Constructor & Destructor Documentation

◆ ModelRenderer()

ModelRenderer::ModelRenderer ( )
inline

◆ ~ModelRenderer()

virtual ModelRenderer::~ModelRenderer ( )
inlinevirtual

Member Function Documentation

◆ BuildColor4ub()

void ModelRenderer::BuildColor4ub ( CModel model,
const VertexArrayIterator< CVector3D > &  Normal,
const VertexArrayIterator< SColor4ub > &  Color 
)
static

BuildColor4ub: Build lighting colors for the given model, based on previously calculated world space normals.

Parameters
modelThe model that is to be lit.
NormalArray of the model's normal vectors, animated and transformed into world space.
ColorPoints to the array that will receive the lit vertex color. The array behind the iterator must large enough to hold model->GetModelDef()->GetNumVertices() vertices.

◆ BuildIndices()

void ModelRenderer::BuildIndices ( const CModelDefPtr mdef,
const VertexArrayIterator< u16 > &  Indices 
)
static

BuildIndices: Create the indices array for the given CModelDef.

Parameters
mdefThe model definition object.
IndicesThe index array, must be able to hold mdef->GetNumFaces()*3 elements.

◆ BuildPositionAndNormals()

void ModelRenderer::BuildPositionAndNormals ( CModel model,
const VertexArrayIterator< CVector3D > &  Position,
const VertexArrayIterator< CVector3D > &  Normal 
)
static

BuildPositionAndNormals: Build animated vertices and normals, transformed into world space.

Parameters
modelThe model that is to be transformed.
PositionPoints to the array that will receive transformed position vectors. The array behind the iterator must be large enough to hold model->GetModelDef()->GetNumVertices() vertices. It must allow 16 bytes to be written to each element (i.e. provide 4 bytes of padding after each CVector3D).
NormalPoints to the array that will receive transformed normal vectors. The array behind the iterator must be as large as the Position array.

◆ BuildUV()

void ModelRenderer::BuildUV ( const CModelDefPtr mdef,
const VertexArrayIterator< float[2]> &  UV,
int  UVset 
)
static

BuildUV: Copy UV coordinates into the given vertex array.

Parameters
mdefThe model def.
UVPoints to the array that will receive UV coordinates. The array behind the iterator must large enough to hold mdef->GetNumVertices() vertices.

◆ CopyPositionAndNormals()

void ModelRenderer::CopyPositionAndNormals ( const CModelDefPtr mdef,
const VertexArrayIterator< CVector3D > &  Position,
const VertexArrayIterator< CVector3D > &  Normal 
)
static

CopyPositionAndNormals: Copy unanimated object-space vertices and normals into the given vertex array.

Parameters
mdefThe underlying CModelDef that contains mesh data.
PositionPoints to the array that will receive position vectors. The array behind the iterator must be large enough to hold model->GetModelDef()->GetNumVertices() vertices.
NormalPoints to the array that will receive normal vectors. The array behind the iterator must be as large as the Position array.

◆ EndFrame()

virtual void ModelRenderer::EndFrame ( )
pure virtual

EndFrame: Remove all models from the list of submitted models.

Implemented in ShaderModelRenderer.

◆ GenTangents()

void ModelRenderer::GenTangents ( const CModelDefPtr mdef,
std::vector< float > &  newVertices,
bool  gpuSkinning 
)
static

GenTangents: Generate tangents for the given CModelDef.

Parameters
mdefThe model definition object.
newVerticesAn out vector of the unindexed vertices with tangents added. The new vertices cannot be used with existing face index and must be welded/reindexed.

◆ Init()

void ModelRenderer::Init ( )
static

Initialise global settings.

Should be called before using the class.

◆ PrepareModels()

virtual void ModelRenderer::PrepareModels ( )
pure virtual

PrepareModels: Calculate renderer data for all previously submitted models.

Must be called before any rendering calls and after all models for this frame have been submitted.

Implemented in ShaderModelRenderer.

◆ Render()

virtual void ModelRenderer::Render ( Renderer::Backend::IDeviceCommandContext deviceCommandContext,
const RenderModifierPtr modifier,
const CShaderDefines context,
int  cullGroup,
int  flags 
)
pure virtual

Render: Render submitted models, using the given RenderModifier to setup the fragment stage.

Note
It is suggested that derived model renderers implement and use this Render functions. However, a highly specialized model renderer may need to "disable" this function and provide its own Render function with a different prototype.

preconditions : PrepareModels must be called after all models have been submitted and before calling Render.

Parameters
modifierThe RenderModifier that specifies the fragment stage.
flagsIf flags is 0, all submitted models are rendered. If flags is non-zero, only models that contain flags in their CModel::GetFlags() are rendered.

Implemented in ShaderModelRenderer.

◆ Submit()

virtual void ModelRenderer::Submit ( int  cullGroup,
CModel model 
)
pure virtual

Submit: Submit a model for rendering this frame.

preconditions : The model must not have been submitted to any ModelRenderer in this frame. Submit may only be called after EndFrame and before PrepareModels.

Parameters
modelThe model that will be added to the list of models submitted this frame.

Implemented in ShaderModelRenderer.

◆ UploadModels()

virtual void ModelRenderer::UploadModels ( Renderer::Backend::IDeviceCommandContext deviceCommandContext)
pure virtual

Upload renderer data for all previously submitted models to backend.

Must be called before any rendering calls and after all models for this frame have been prepared.

Implemented in ShaderModelRenderer.


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