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: 7 60 11.7 %
Date: 2026-12-03 01:19:39 Functions: 2 8 25.0 %

          Line data    Source code
       1             : /* Copyright (C) 2025 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 "RenderModifiers.h"
      21             : 
      22             : #include "graphics/Camera.h"
      23             : #include "graphics/LOSTexture.h"
      24             : #include "graphics/LightEnv.h"
      25             : #include "graphics/Model.h"
      26             : #include "maths/Matrix3D.h"
      27             : #include "maths/Vector3D.h"
      28             : #include "ps/CStrIntern.h"
      29             : #include "ps/CStrInternStatic.h"
      30             : #include "ps/Game.h"
      31             : #include "renderer/Renderer.h"
      32             : #include "renderer/Scene.h"
      33             : #include "renderer/SceneRenderer.h"
      34             : #include "renderer/ShadowMap.h"
      35             : #include "renderer/backend/IDeviceCommandContext.h"
      36             : #include "renderer/backend/IShaderProgram.h"
      37             : 
      38             : ///////////////////////////////////////////////////////////////////////////////////////////////
      39             : // LitRenderModifier implementation
      40             : 
      41          10 : LitRenderModifier::LitRenderModifier()
      42          10 :     : m_Shadow(0), m_LightEnv(0)
      43             : {
      44           0 : }
      45             : 
      46          10 : LitRenderModifier::~LitRenderModifier()
      47             : {
      48          10 : }
      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          10 : ShaderRenderModifier::ShaderRenderModifier()
      66          10 :     : m_ShadingColor(1.0f, 1.0f, 1.0f, 1.0f), m_PlayerColor(1.0f, 1.0f, 1.0f, 1.0f)
      67             : {
      68          10 : }
      69             : 
      70           0 : void ShaderRenderModifier::BeginPass(
      71             :     Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
      72             :     Renderer::Backend::IShaderProgram* shader)
      73             : {
      74           0 :     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           0 :         GetLightEnv()->Bind(deviceCommandContext, shader);
      87             : 
      88           0 :     if (shader->GetBindingSlot(str_losTex) >= 0)
      89             :     {
      90           0 :         CLOSTexture& los = g_Renderer.GetSceneRenderer().GetScene().GetLOSTexture();
      91           0 :         deviceCommandContext->SetTexture(
      92           0 :             shader->GetBindingSlot(str_losTex), los.GetTextureSmooth());
      93             :         // Don't bother sending the whole matrix, we just need two floats (scale and translation)
      94           0 :         deviceCommandContext->SetUniform(
      95           0 :             shader->GetBindingSlot(str_losTransform),
      96           0 :             los.GetTextureMatrix()[0], los.GetTextureMatrix()[12]);
      97             :     }
      98             : 
      99           0 :     m_BindingInstancingTransform = shader->GetBindingSlot(str_instancingTransform);
     100           0 :     m_BindingShadingColor = shader->GetBindingSlot(str_shadingColor);
     101           0 :     m_BindingPlayerColor = shader->GetBindingSlot(str_playerColor);
     102             : 
     103           0 :     if (m_BindingShadingColor >= 0)
     104             :     {
     105           0 :         m_ShadingColor = CColor(1.0f, 1.0f, 1.0f, 1.0f);
     106           0 :         deviceCommandContext->SetUniform(
     107           0 :             m_BindingShadingColor, m_ShadingColor.AsFloatArray());
     108             :     }
     109             : 
     110           0 :     if (m_BindingPlayerColor >= 0)
     111             :     {
     112           0 :         m_PlayerColor = g_Game->GetPlayerColor(0);
     113           0 :         deviceCommandContext->SetUniform(
     114           0 :             m_BindingPlayerColor, m_PlayerColor.AsFloatArray());
     115             :     }
     116           0 : }
     117             : 
     118           0 : void ShaderRenderModifier::PrepareModel(
     119             :     Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
     120             :     CModel* model)
     121             : {
     122           0 :     if (m_BindingInstancingTransform >= 0)
     123             :     {
     124           0 :         deviceCommandContext->SetUniform(
     125           0 :             m_BindingInstancingTransform, model->GetTransform().AsFloatArray());
     126             :     }
     127             : 
     128           0 :     if (m_BindingShadingColor >= 0 && m_ShadingColor != model->GetShadingColor())
     129             :     {
     130           0 :         m_ShadingColor = model->GetShadingColor();
     131           0 :         deviceCommandContext->SetUniform(
     132           0 :             m_BindingShadingColor, m_ShadingColor.AsFloatArray());
     133             :     }
     134             : 
     135           0 :     if (m_BindingPlayerColor >= 0)
     136             :     {
     137           0 :         const CColor& playerColor = g_Game->GetPlayerColor(model->GetPlayerID());
     138           0 :         if (m_PlayerColor != playerColor)
     139             :         {
     140           0 :             m_PlayerColor = playerColor;
     141           0 :             deviceCommandContext->SetUniform(
     142           0 :             m_BindingPlayerColor, m_PlayerColor.AsFloatArray());
     143             :         }
     144             :     }
     145           0 : }

Generated by: LCOV version 1.16