LCOV - code coverage report
Current view: top level - source/renderer - RenderModifiers.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 4 0.0 %
Date: 2021-09-24 14:46:47 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2021 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             : /*
      19             :  * RenderModifiers can affect the fragment stage behaviour of some
      20             :  * ModelRenderers. This file defines some common RenderModifiers in
      21             :  * addition to the base class.
      22             :  *
      23             :  * TODO: See comment in CRendererInternals::Models - we no longer use multiple
      24             :  * subclasses of RenderModifier, so most of the stuff here is unnecessary
      25             :  * abstraction which should probably be cleaned up.
      26             :  */
      27             : 
      28             : #ifndef INCLUDED_RENDERMODIFIERS
      29             : #define INCLUDED_RENDERMODIFIERS
      30             : 
      31             : #include "ModelRenderer.h"
      32             : #include "graphics/ShaderProgram.h"
      33             : #include "graphics/ShaderTechnique.h"
      34             : #include "graphics/Texture.h"
      35             : 
      36             : class CLightEnv;
      37             : class CModel;
      38             : class ShadowMap;
      39             : 
      40             : /**
      41             :  * Class RenderModifier: Some ModelRenderer implementations provide vertex
      42             :  * management behaviour but allow fragment stages to be modified by a plugged in
      43             :  * RenderModifier.
      44             :  *
      45             :  * You should use RenderModifierPtr when referencing RenderModifiers.
      46             :  */
      47             : class RenderModifier
      48             : {
      49             : public:
      50           0 :     RenderModifier() { }
      51           0 :     virtual ~RenderModifier() { }
      52             : 
      53             :     /**
      54             :      * BeginPass: Setup OpenGL for the given rendering pass.
      55             :      *
      56             :      * Must be implemented by derived classes.
      57             :      *
      58             :      * @param pass The current pass number (pass == 0 is the first pass)
      59             :      *
      60             :      * @return The streamflags that indicate which vertex components
      61             :      * are required by the fragment stages (see STREAM_XYZ constants).
      62             :      */
      63             :     virtual void BeginPass(const CShaderProgramPtr& shader) = 0;
      64             : 
      65             :     /**
      66             :      * PrepareModel: Called before rendering the given model.
      67             :      *
      68             :      * Default behaviour does nothing.
      69             :      *
      70             :      * @param pass The current pass number (pass == 0 is the first pass)
      71             :      * @param model The model that is about to be rendered.
      72             :      */
      73             :     virtual void PrepareModel(const CShaderProgramPtr& shader, CModel* model) = 0;
      74             : };
      75             : 
      76             : 
      77             : /**
      78             :  * Class LitRenderModifier: Abstract base class for RenderModifiers that apply
      79             :  * a shadow map.
      80             :  * LitRenderModifiers expect the diffuse brightness in the primary color (instead of ambient + diffuse).
      81             :  */
      82             : class LitRenderModifier : public RenderModifier
      83             : {
      84             : public:
      85             :     LitRenderModifier();
      86             :     ~LitRenderModifier();
      87             : 
      88             :     /**
      89             :      * SetShadowMap: Set the shadow map that will be used for rendering.
      90             :      * Must be called by the user of the RenderModifier.
      91             :      *
      92             :      * The shadow map must be non-null and use depth texturing, or subsequent rendering
      93             :      * using this RenderModifier will fail.
      94             :      *
      95             :      * @param shadow the shadow map
      96             :      */
      97             :     void SetShadowMap(const ShadowMap* shadow);
      98             : 
      99             :     /**
     100             :      * SetLightEnv: Set the light environment that will be used for rendering.
     101             :      * Must be called by the user of the RenderModifier.
     102             :      *
     103             :      * @param lightenv the light environment (must be non-null)
     104             :      */
     105             :     void SetLightEnv(const CLightEnv* lightenv);
     106             : 
     107           0 :     const ShadowMap* GetShadowMap() const { return m_Shadow; }
     108           0 :     const CLightEnv* GetLightEnv() const { return m_LightEnv; }
     109             : 
     110             : private:
     111             :     const ShadowMap* m_Shadow;
     112             :     const CLightEnv* m_LightEnv;
     113             : };
     114             : 
     115             : /**
     116             :  * A RenderModifier that sets uniforms and textures appropriately for rendering models.
     117             :  */
     118             : class ShaderRenderModifier : public LitRenderModifier
     119             : {
     120             : public:
     121             :     ShaderRenderModifier();
     122             : 
     123             :     // Implementation
     124             :     void BeginPass(const CShaderProgramPtr& shader);
     125             :     void PrepareModel(const CShaderProgramPtr& shader, CModel* model);
     126             : 
     127             : private:
     128             :     CShaderProgram::Binding m_BindingInstancingTransform;
     129             :     CShaderProgram::Binding m_BindingShadingColor;
     130             :     CShaderProgram::Binding m_BindingPlayerColor;
     131             : };
     132             : 
     133             : #endif // INCLUDED_RENDERMODIFIERS

Generated by: LCOV version 1.13