LCOV - code coverage report
Current view: top level - source/renderer - Renderer.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 4 0.0 %
Date: 2022-03-08 13:03:03 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2022 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef INCLUDED_RENDERER
      19             : #define INCLUDED_RENDERER
      20             : 
      21             : #include "graphics/Camera.h"
      22             : #include "graphics/ShaderDefines.h"
      23             : #include "graphics/ShaderProgramPtr.h"
      24             : #include "ps/Singleton.h"
      25             : #include "renderer/backend/gl/DeviceCommandContext.h"
      26             : #include "renderer/RenderingOptions.h"
      27             : #include "renderer/Scene.h"
      28             : 
      29             : #include <memory>
      30             : 
      31             : class CDebugRenderer;
      32             : class CFontManager;
      33             : class CPostprocManager;
      34             : class CSceneRenderer;
      35             : class CShaderManager;
      36             : class CTextureManager;
      37             : class CTimeManager;
      38             : 
      39             : #define g_Renderer CRenderer::GetSingleton()
      40             : 
      41             : /**
      42             :  * Higher level interface on top of the whole frame rendering. It does know
      43             :  * what should be rendered and via which renderer but shouldn't know how to
      44             :  * render a particular area, like UI or scene.
      45             :  */
      46             : class CRenderer : public Singleton<CRenderer>
      47             : {
      48             : public:
      49             :     // stats class - per frame counts of number of draw calls, poly counts etc
      50             :     struct Stats
      51             :     {
      52             :         // set all stats to zero
      53           0 :         void Reset() { memset(this, 0, sizeof(*this)); }
      54             :         // number of draw calls per frame - total DrawElements + Begin/End immediate mode loops
      55             :         size_t m_DrawCalls;
      56             :         // number of terrain triangles drawn
      57             :         size_t m_TerrainTris;
      58             :         // number of water triangles drawn
      59             :         size_t m_WaterTris;
      60             :         // number of (non-transparent) model triangles drawn
      61             :         size_t m_ModelTris;
      62             :         // number of overlay triangles drawn
      63             :         size_t m_OverlayTris;
      64             :         // number of splat passes for alphamapping
      65             :         size_t m_BlendSplats;
      66             :         // number of particles
      67             :         size_t m_Particles;
      68             :     };
      69             : 
      70             :     enum class ScreenShotType
      71             :     {
      72             :         NONE,
      73             :         DEFAULT,
      74             :         BIG
      75             :     };
      76             : 
      77             : public:
      78             :     CRenderer();
      79             :     ~CRenderer();
      80             : 
      81             :     // open up the renderer: performs any necessary initialisation
      82             :     bool Open(int width, int height);
      83             : 
      84             :     // resize renderer view
      85             :     void Resize(int width, int height);
      86             : 
      87             :     // return view width
      88           0 :     int GetWidth() const { return m_Width; }
      89             :     // return view height
      90           0 :     int GetHeight() const { return m_Height; }
      91             : 
      92             :     void RenderFrame(bool needsPresent);
      93             : 
      94             :     // signal frame start
      95             :     void BeginFrame();
      96             :     // signal frame end
      97             :     void EndFrame();
      98             : 
      99             :     // trigger a reload of shaders (when parameters they depend on have changed)
     100             :     void MakeShadersDirty();
     101             : 
     102             :     // set the viewport
     103             :     void SetViewport(const SViewPort &);
     104             : 
     105             :     // get the last viewport
     106             :     SViewPort GetViewport();
     107             : 
     108             :     // return stats accumulated for current frame
     109           0 :     Stats& GetStats() { return m_Stats; }
     110             : 
     111             :     CTextureManager& GetTextureManager();
     112             : 
     113             :     CShaderManager& GetShaderManager();
     114             : 
     115             :     CFontManager& GetFontManager();
     116             : 
     117             :     CTimeManager& GetTimeManager();
     118             : 
     119             :     CPostprocManager& GetPostprocManager();
     120             : 
     121             :     CSceneRenderer& GetSceneRenderer();
     122             : 
     123             :     CDebugRenderer& GetDebugRenderer();
     124             : 
     125             :     /**
     126             :      * Performs a complete frame without presenting to force loading all needed
     127             :      * resources. It's used for the first frame on a game start.
     128             :      * TODO: It might be better to preload resources without a complete frame
     129             :      * rendering.
     130             :      */
     131             :     void PreloadResourcesBeforeNextFrame();
     132             : 
     133             :     /**
     134             :      * Makes a screenshot on the next RenderFrame according of the given
     135             :      * screenshot type.
     136             :      */
     137             :     void MakeScreenShotOnNextFrame(ScreenShotType screenShotType);
     138             : 
     139             :     Renderer::Backend::GL::CDeviceCommandContext* GetDeviceCommandContext();
     140             : 
     141             : protected:
     142             :     friend class CPatchRData;
     143             :     friend class CDecalRData;
     144             :     friend class HWLightingModelRenderer;
     145             :     friend class ShaderModelVertexRenderer;
     146             :     friend class InstancingModelRenderer;
     147             :     friend class CRenderingOptions;
     148             : 
     149             :     bool ShouldRender() const;
     150             : 
     151             :     void RenderFrameImpl(const bool renderGUI, const bool renderLogger);
     152             :     void RenderFrame2D(const bool renderGUI, const bool renderLogger);
     153             :     void RenderScreenShot();
     154             :     void RenderBigScreenShot(const bool needsPresent);
     155             : 
     156             :     // SetRenderPath: Select the preferred render path.
     157             :     // This may only be called before Open(), because the layout of vertex arrays and other
     158             :     // data may depend on the chosen render path.
     159             :     void SetRenderPath(RenderPath rp);
     160             : 
     161             :     void ReloadShaders();
     162             : 
     163             :     // Private data that is not needed by inline functions.
     164             :     class Internals;
     165             :     std::unique_ptr<Internals> m;
     166             :     // view width
     167             :     int m_Width = 0;
     168             :     // view height
     169             :     int m_Height = 0;
     170             : 
     171             :     SViewPort m_Viewport;
     172             : 
     173             :     // per-frame renderer stats
     174             :     Stats m_Stats;
     175             : 
     176             :     bool m_ShouldPreloadResourcesBeforeNextFrame = false;
     177             : 
     178             :     ScreenShotType m_ScreenShotType = ScreenShotType::NONE;
     179             : };
     180             : 
     181             : #endif // INCLUDED_RENDERER

Generated by: LCOV version 1.13