Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/renderer/Renderer.h
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 17 Lines | |||||
#include "graphics/SColor.h" | #include "graphics/SColor.h" | ||||
#include "graphics/ShaderProgramPtr.h" | #include "graphics/ShaderProgramPtr.h" | ||||
#include "lib/file/vfs/vfs_path.h" | #include "lib/file/vfs/vfs_path.h" | ||||
#include "lib/res/handle.h" | #include "lib/res/handle.h" | ||||
#include "ps/Singleton.h" | #include "ps/Singleton.h" | ||||
#include "graphics/ShaderDefines.h" | #include "graphics/ShaderDefines.h" | ||||
#include "renderer/Scene.h" | #include "renderer/Scene.h" | ||||
#include "renderer/RenderingOptions.h" | |||||
// necessary declarations | // necessary declarations | ||||
class CFontManager; | class CFontManager; | ||||
class CLightEnv; | class CLightEnv; | ||||
class CMaterial; | class CMaterial; | ||||
class CMaterialManager; | class CMaterialManager; | ||||
class CModel; | class CModel; | ||||
class CParticleManager; | class CParticleManager; | ||||
Show All 24 Lines | |||||
class CRenderer : | class CRenderer : | ||||
public Singleton<CRenderer>, | public Singleton<CRenderer>, | ||||
private SceneCollector | private SceneCollector | ||||
{ | { | ||||
public: | public: | ||||
// various enumerations and renderer related constants | // various enumerations and renderer related constants | ||||
enum { NumAlphaMaps=14 }; | enum { NumAlphaMaps=14 }; | ||||
enum Option { | |||||
OPT_NOVBO, | |||||
OPT_SHADOWS, | |||||
OPT_WATEREFFECTS, | |||||
OPT_WATERFANCYEFFECTS, | |||||
OPT_WATERREALDEPTH, | |||||
OPT_WATERREFLECTION, | |||||
OPT_WATERREFRACTION, | |||||
OPT_SHADOWSONWATER, | |||||
OPT_SHADOWPCF, | |||||
OPT_PARTICLES, | |||||
OPT_PREFERGLSL, | |||||
OPT_FOG, | |||||
OPT_SILHOUETTES, | |||||
OPT_SHOWSKY, | |||||
OPT_SMOOTHLOS, | |||||
OPT_POSTPROC, | |||||
OPT_DISPLAYFRUSTUM, | |||||
}; | |||||
enum CullGroup { | enum CullGroup { | ||||
CULL_DEFAULT, | CULL_DEFAULT, | ||||
CULL_SHADOWS, | CULL_SHADOWS, | ||||
CULL_REFLECTIONS, | CULL_REFLECTIONS, | ||||
CULL_REFRACTIONS, | CULL_REFRACTIONS, | ||||
CULL_SILHOUETTE_OCCLUDER, | CULL_SILHOUETTE_OCCLUDER, | ||||
CULL_SILHOUETTE_CASTER, | CULL_SILHOUETTE_CASTER, | ||||
CULL_MAX | CULL_MAX | ||||
}; | }; | ||||
enum RenderPath { | |||||
// If no rendering path is configured explicitly, the renderer | |||||
// will choose the path when Open() is called. | |||||
RP_DEFAULT, | |||||
// Classic fixed function. | |||||
RP_FIXED, | |||||
// Use new ARB/GLSL system | |||||
RP_SHADER | |||||
}; | |||||
// stats class - per frame counts of number of draw calls, poly counts etc | // stats class - per frame counts of number of draw calls, poly counts etc | ||||
struct Stats { | struct Stats { | ||||
// set all stats to zero | // set all stats to zero | ||||
void Reset() { memset(this, 0, sizeof(*this)); } | void Reset() { memset(this, 0, sizeof(*this)); } | ||||
// number of draw calls per frame - total DrawElements + Begin/End immediate mode loops | // number of draw calls per frame - total DrawElements + Begin/End immediate mode loops | ||||
size_t m_DrawCalls; | size_t m_DrawCalls; | ||||
// number of terrain triangles drawn | // number of terrain triangles drawn | ||||
size_t m_TerrainTris; | size_t m_TerrainTris; | ||||
// number of water triangles drawn | // number of water triangles drawn | ||||
size_t m_WaterTris; | size_t m_WaterTris; | ||||
// number of (non-transparent) model triangles drawn | // number of (non-transparent) model triangles drawn | ||||
size_t m_ModelTris; | size_t m_ModelTris; | ||||
// number of overlay triangles drawn | // number of overlay triangles drawn | ||||
size_t m_OverlayTris; | size_t m_OverlayTris; | ||||
// number of splat passes for alphamapping | // number of splat passes for alphamapping | ||||
size_t m_BlendSplats; | size_t m_BlendSplats; | ||||
// number of particles | // number of particles | ||||
size_t m_Particles; | size_t m_Particles; | ||||
}; | }; | ||||
// renderer options | |||||
struct Options { | |||||
bool m_NoVBO; | |||||
bool m_Shadows; | |||||
bool m_WaterEffects; | |||||
bool m_WaterFancyEffects; | |||||
bool m_WaterRealDepth; | |||||
bool m_WaterRefraction; | |||||
bool m_WaterReflection; | |||||
bool m_WaterShadows; | |||||
RenderPath m_RenderPath; | |||||
bool m_ShadowAlphaFix; | |||||
bool m_ARBProgramShadow; | |||||
bool m_ShadowPCF; | |||||
bool m_Particles; | |||||
bool m_PreferGLSL; | |||||
bool m_ForceAlphaTest; | |||||
bool m_GPUSkinning; | |||||
bool m_Fog; | |||||
bool m_Silhouettes; | |||||
bool m_SmoothLOS; | |||||
bool m_ShowSky; | |||||
bool m_Postproc; | |||||
bool m_DisplayFrustum; | |||||
} m_Options; | |||||
struct Caps { | struct Caps { | ||||
bool m_VBO; | bool m_VBO; | ||||
bool m_ARBProgram; | bool m_ARBProgram; | ||||
bool m_ARBProgramShadow; | bool m_ARBProgramShadow; | ||||
bool m_VertexShader; | bool m_VertexShader; | ||||
bool m_FragmentShader; | bool m_FragmentShader; | ||||
bool m_Shadows; | bool m_Shadows; | ||||
bool m_PrettyWater; | bool m_PrettyWater; | ||||
}; | }; | ||||
public: | public: | ||||
// constructor, destructor | // constructor, destructor | ||||
CRenderer(); | CRenderer(); | ||||
~CRenderer(); | ~CRenderer(); | ||||
// open up the renderer: performs any necessary initialisation | // open up the renderer: performs any necessary initialisation | ||||
bool Open(int width,int height); | bool Open(int width,int height); | ||||
// resize renderer view | // resize renderer view | ||||
void Resize(int width,int height); | void Resize(int width,int height); | ||||
// set/get boolean renderer option | |||||
void SetOptionBool(enum Option opt, bool value); | |||||
bool GetOptionBool(enum Option opt) const; | |||||
void SetRenderPath(RenderPath rp); | |||||
RenderPath GetRenderPath() const { return m_Options.m_RenderPath; } | |||||
static CStr GetRenderPathName(RenderPath rp); | |||||
static RenderPath GetRenderPathByName(const CStr& name); | |||||
// return view width | // return view width | ||||
int GetWidth() const { return m_Width; } | int GetWidth() const { return m_Width; } | ||||
// return view height | // return view height | ||||
int GetHeight() const { return m_Height; } | int GetHeight() const { return m_Height; } | ||||
// return view aspect ratio | // return view aspect ratio | ||||
float GetAspect() const { return float(m_Width)/float(m_Height); } | float GetAspect() const { return float(m_Width)/float(m_Height); } | ||||
// signal frame start | // signal frame start | ||||
▲ Show 20 Lines • Show All 153 Lines • ▼ Show 20 Lines | protected: | ||||
friend class SortModelRenderer; | friend class SortModelRenderer; | ||||
friend class RenderPathVertexShader; | friend class RenderPathVertexShader; | ||||
friend class HWLightingModelRenderer; | friend class HWLightingModelRenderer; | ||||
friend class ShaderModelVertexRenderer; | friend class ShaderModelVertexRenderer; | ||||
friend class InstancingModelRenderer; | friend class InstancingModelRenderer; | ||||
friend class ShaderInstancingModelRenderer; | friend class ShaderInstancingModelRenderer; | ||||
friend class TerrainRenderer; | friend class TerrainRenderer; | ||||
friend class WaterRenderer; | friend class WaterRenderer; | ||||
friend struct SRenderingOptions; | |||||
//BEGIN: Implementation of SceneCollector | //BEGIN: Implementation of SceneCollector | ||||
void Submit(CPatch* patch); | void Submit(CPatch* patch); | ||||
void Submit(SOverlayLine* overlay); | void Submit(SOverlayLine* overlay); | ||||
void Submit(SOverlayTexturedLine* overlay); | void Submit(SOverlayTexturedLine* overlay); | ||||
void Submit(SOverlaySprite* overlay); | void Submit(SOverlaySprite* overlay); | ||||
void Submit(SOverlayQuad* overlay); | void Submit(SOverlayQuad* overlay); | ||||
void Submit(CModelDecal* decal); | void Submit(CModelDecal* decal); | ||||
Show All 27 Lines | protected: | ||||
void ComputeRefractionCamera(CCamera& camera, const CBoundingBoxAligned& scissor) const; | void ComputeRefractionCamera(CCamera& camera, const CBoundingBoxAligned& scissor) const; | ||||
// debugging | // debugging | ||||
void DisplayFrustum(); | void DisplayFrustum(); | ||||
// enable oblique frustum clipping with the given clip plane | // enable oblique frustum clipping with the given clip plane | ||||
void SetObliqueFrustumClipping(CCamera& camera, const CVector4D& clipPlane) const; | void SetObliqueFrustumClipping(CCamera& camera, const CVector4D& clipPlane) const; | ||||
void SetRenderPath(RenderPath rp); | |||||
void ReloadShaders(); | void ReloadShaders(); | ||||
void RecomputeSystemShaderDefines(); | void RecomputeSystemShaderDefines(); | ||||
// hotloading | // hotloading | ||||
static Status ReloadChangedFileCB(void* param, const VfsPath& path); | static Status ReloadChangedFileCB(void* param, const VfsPath& path); | ||||
// RENDERER DATA: | // RENDERER DATA: | ||||
/// Private data that is not needed by inline functions | /// Private data that is not needed by inline functions | ||||
▲ Show 20 Lines • Show All 97 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator