mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 01:04:06 +00:00
Updates a model color uniform in RenderModifier only if it was changed.
This was SVN commit r26653.
This commit is contained in:
@@ -156,7 +156,7 @@ public:
|
||||
virtual player_id_t GetPlayerID() const { return m_PlayerID; }
|
||||
|
||||
virtual void SetShadingColor(const CColor& color) { m_ShadingColor = color; }
|
||||
virtual CColor GetShadingColor() const { return m_ShadingColor; }
|
||||
virtual const CColor& GetShadingColor() const { return m_ShadingColor; }
|
||||
|
||||
protected:
|
||||
void CalcSelectionBox();
|
||||
|
||||
+1
-2
@@ -447,8 +447,7 @@ void CGame::CachePlayerColors()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CColor CGame::GetPlayerColor(player_id_t player) const
|
||||
const CColor& CGame::GetPlayerColor(player_id_t player) const
|
||||
{
|
||||
if (player < 0 || player >= (int)m_PlayerColors.size())
|
||||
return BrokenColor;
|
||||
|
||||
+1
-1
@@ -130,7 +130,7 @@ public:
|
||||
*/
|
||||
void CachePlayerColors();
|
||||
|
||||
CColor GetPlayerColor(player_id_t player) const;
|
||||
const CColor& GetPlayerColor(player_id_t player) const;
|
||||
|
||||
/**
|
||||
* Get m_GameStarted.
|
||||
|
||||
@@ -64,6 +64,7 @@ void LitRenderModifier::SetLightEnv(const CLightEnv* lightenv)
|
||||
// ShaderRenderModifier implementation
|
||||
|
||||
ShaderRenderModifier::ShaderRenderModifier()
|
||||
: m_ShadingColor(1.0f, 1.0f, 1.0f, 1.0f), m_PlayerColor(1.0f, 1.0f, 1.0f, 1.0f)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -96,6 +97,18 @@ void ShaderRenderModifier::BeginPass(Renderer::Backend::GL::CShaderProgram* shad
|
||||
m_BindingInstancingTransform = shader->GetUniformBinding(str_instancingTransform);
|
||||
m_BindingShadingColor = shader->GetUniformBinding(str_shadingColor);
|
||||
m_BindingPlayerColor = shader->GetUniformBinding(str_playerColor);
|
||||
|
||||
if (m_BindingShadingColor.Active())
|
||||
{
|
||||
m_ShadingColor = CColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
shader->Uniform(m_BindingShadingColor, m_ShadingColor);
|
||||
}
|
||||
|
||||
if (m_BindingPlayerColor.Active())
|
||||
{
|
||||
m_PlayerColor = g_Game->GetPlayerColor(0);
|
||||
shader->Uniform(m_BindingPlayerColor, m_PlayerColor);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderRenderModifier::PrepareModel(Renderer::Backend::GL::CShaderProgram* shader, CModel* model)
|
||||
@@ -103,9 +116,19 @@ void ShaderRenderModifier::PrepareModel(Renderer::Backend::GL::CShaderProgram* s
|
||||
if (m_BindingInstancingTransform.Active())
|
||||
shader->Uniform(m_BindingInstancingTransform, model->GetTransform());
|
||||
|
||||
if (m_BindingShadingColor.Active())
|
||||
shader->Uniform(m_BindingShadingColor, model->GetShadingColor());
|
||||
if (m_BindingShadingColor.Active() && m_ShadingColor != model->GetShadingColor())
|
||||
{
|
||||
m_ShadingColor = model->GetShadingColor();
|
||||
shader->Uniform(m_BindingShadingColor, m_ShadingColor);
|
||||
}
|
||||
|
||||
if (m_BindingPlayerColor.Active())
|
||||
shader->Uniform(m_BindingPlayerColor, g_Game->GetPlayerColor(model->GetPlayerID()));
|
||||
{
|
||||
const CColor& playerColor = g_Game->GetPlayerColor(model->GetPlayerID());
|
||||
if (m_PlayerColor != playerColor)
|
||||
{
|
||||
m_PlayerColor = playerColor;
|
||||
shader->Uniform(m_BindingPlayerColor, m_PlayerColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#define INCLUDED_RENDERMODIFIERS
|
||||
|
||||
#include "ModelRenderer.h"
|
||||
#include "graphics/Color.h"
|
||||
#include "graphics/ShaderProgram.h"
|
||||
#include "graphics/ShaderTechnique.h"
|
||||
#include "graphics/Texture.h"
|
||||
@@ -128,6 +129,8 @@ private:
|
||||
Renderer::Backend::GL::CShaderProgram::Binding m_BindingInstancingTransform;
|
||||
Renderer::Backend::GL::CShaderProgram::Binding m_BindingShadingColor;
|
||||
Renderer::Backend::GL::CShaderProgram::Binding m_BindingPlayerColor;
|
||||
|
||||
CColor m_ShadingColor, m_PlayerColor;
|
||||
};
|
||||
|
||||
#endif // INCLUDED_RENDERMODIFIERS
|
||||
|
||||
Reference in New Issue
Block a user