LCOV - code coverage report
Current view: top level - source/renderer - RenderModifiers.cpp (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 1 73 1.4 %
Date: 2023-01-19 00:18:29 Functions: 2 10 20.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             : #include "precompiled.h"
      19             : 
      20             : #include "renderer/RenderModifiers.h"
      21             : 
      22             : #include "graphics/GameView.h"
      23             : #include "graphics/LightEnv.h"
      24             : #include "graphics/LOSTexture.h"
      25             : #include "graphics/Model.h"
      26             : #include "graphics/TextureManager.h"
      27             : #include "maths/Vector3D.h"
      28             : #include "maths/Vector4D.h"
      29             : #include "maths/Matrix3D.h"
      30             : #include "ps/CStrInternStatic.h"
      31             : #include "ps/Game.h"
      32             : #include "renderer/Renderer.h"
      33             : #include "renderer/SceneRenderer.h"
      34             : #include "renderer/ShadowMap.h"
      35             : 
      36             : #include <boost/algorithm/string.hpp>
      37             : 
      38             : ///////////////////////////////////////////////////////////////////////////////////////////////
      39             : // LitRenderModifier implementation
      40             : 
      41           0 : LitRenderModifier::LitRenderModifier()
      42           0 :     : m_Shadow(0), m_LightEnv(0)
      43             : {
      44           0 : }
      45             : 
      46           0 : LitRenderModifier::~LitRenderModifier()
      47             : {
      48           0 : }
      49             : 
      50             : // Set the shadow map for subsequent rendering
      51           0 : void LitRenderModifier::SetShadowMap(const ShadowMap* shadow)
      52             : {
      53           0 :     m_Shadow = shadow;
      54           0 : }
      55             : 
      56             : // Set the light environment for subsequent rendering
      57           0 : void LitRenderModifier::SetLightEnv(const CLightEnv* lightenv)
      58             : {
      59           0 :     m_LightEnv = lightenv;
      60           0 : }
      61             : 
      62             : ///////////////////////////////////////////////////////////////////////////////////////////////
      63             : // ShaderRenderModifier implementation
      64             : 
      65           0 : ShaderRenderModifier::ShaderRenderModifier()
      66           0 :     : m_ShadingColor(1.0f, 1.0f, 1.0f, 1.0f), m_PlayerColor(1.0f, 1.0f, 1.0f, 1.0f)
      67             : {
      68           0 : }
      69             : 
      70           0 : void ShaderRenderModifier::BeginPass(
      71             :     Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
      72             :     Renderer::Backend::IShaderProgram* shader)
      73             : {
      74             :     const CMatrix3D transform =
      75           0 :         g_Renderer.GetSceneRenderer().GetViewCamera().GetViewProjection();
      76           0 :     deviceCommandContext->SetUniform(
      77           0 :         shader->GetBindingSlot(str_transform), transform.AsFloatArray());
      78           0 :     deviceCommandContext->SetUniform(
      79           0 :         shader->GetBindingSlot(str_cameraPos),
      80           0 :         g_Renderer.GetSceneRenderer().GetViewCamera().GetOrientation().GetTranslation().AsFloatArray());
      81             : 
      82           0 :     if (GetShadowMap())
      83           0 :         GetShadowMap()->BindTo(deviceCommandContext, shader);
      84             : 
      85           0 :     if (GetLightEnv())
      86             :     {
      87           0 :         deviceCommandContext->SetUniform(
      88           0 :             shader->GetBindingSlot(str_ambient),
      89           0 :             GetLightEnv()->m_AmbientColor.AsFloatArray());
      90           0 :         deviceCommandContext->SetUniform(
      91           0 :             shader->GetBindingSlot(str_sunDir),
      92           0 :             GetLightEnv()->GetSunDir().AsFloatArray());
      93           0 :         deviceCommandContext->SetUniform(
      94           0 :             shader->GetBindingSlot(str_sunColor),
      95           0 :             GetLightEnv()->m_SunColor.AsFloatArray());
      96             : 
      97           0 :         deviceCommandContext->SetUniform(
      98           0 :             shader->GetBindingSlot(str_fogColor),
      99           0 :             GetLightEnv()->m_FogColor.AsFloatArray());
     100           0 :         deviceCommandContext->SetUniform(
     101           0 :             shader->GetBindingSlot(str_fogParams),
     102           0 :             GetLightEnv()->m_FogFactor, GetLightEnv()->m_FogMax);
     103             :     }
     104             : 
     105           0 :     if (shader->GetBindingSlot(str_losTex) >= 0)
     106             :     {
     107           0 :         CLOSTexture& los = g_Renderer.GetSceneRenderer().GetScene().GetLOSTexture();
     108           0 :         deviceCommandContext->SetTexture(
     109           0 :             shader->GetBindingSlot(str_losTex), los.GetTextureSmooth());
     110             :         // Don't bother sending the whole matrix, we just need two floats (scale and translation)
     111           0 :         deviceCommandContext->SetUniform(
     112           0 :             shader->GetBindingSlot(str_losTransform),
     113           0 :             los.GetTextureMatrix()[0], los.GetTextureMatrix()[12]);
     114             :     }
     115             : 
     116           0 :     m_BindingInstancingTransform = shader->GetBindingSlot(str_instancingTransform);
     117           0 :     m_BindingShadingColor = shader->GetBindingSlot(str_shadingColor);
     118           0 :     m_BindingPlayerColor = shader->GetBindingSlot(str_playerColor);
     119             : 
     120           0 :     if (m_BindingShadingColor >= 0)
     121             :     {
     122           0 :         m_ShadingColor = CColor(1.0f, 1.0f, 1.0f, 1.0f);
     123           0 :         deviceCommandContext->SetUniform(
     124           0 :             m_BindingShadingColor, m_ShadingColor.AsFloatArray());
     125             :     }
     126             : 
     127           0 :     if (m_BindingPlayerColor >= 0)
     128             :     {
     129           0 :         m_PlayerColor = g_Game->GetPlayerColor(0);
     130           0 :         deviceCommandContext->SetUniform(
     131           0 :             m_BindingPlayerColor, m_PlayerColor.AsFloatArray());
     132             :     }
     133           0 : }
     134             : 
     135           0 : void ShaderRenderModifier::PrepareModel(
     136             :     Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
     137             :     CModel* model)
     138             : {
     139           0 :     if (m_BindingInstancingTransform >= 0)
     140             :     {
     141           0 :         deviceCommandContext->SetUniform(
     142           0 :             m_BindingInstancingTransform, model->GetTransform().AsFloatArray());
     143             :     }
     144             : 
     145           0 :     if (m_BindingShadingColor >= 0 && m_ShadingColor != model->GetShadingColor())
     146             :     {
     147           0 :         m_ShadingColor = model->GetShadingColor();
     148           0 :         deviceCommandContext->SetUniform(
     149           0 :             m_BindingShadingColor, m_ShadingColor.AsFloatArray());
     150             :     }
     151             : 
     152           0 :     if (m_BindingPlayerColor >= 0)
     153             :     {
     154           0 :         const CColor& playerColor = g_Game->GetPlayerColor(model->GetPlayerID());
     155           0 :         if (m_PlayerColor != playerColor)
     156             :         {
     157           0 :             m_PlayerColor = playerColor;
     158           0 :             deviceCommandContext->SetUniform(
     159           0 :             m_BindingPlayerColor, m_PlayerColor.AsFloatArray());
     160             :         }
     161             :     }
     162           3 : }

Generated by: LCOV version 1.13