2022-01-11 08:02:27 -08:00
|
|
|
|
/* Copyright (C) 2022 Wildfire Games.
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* This file is part of 0 A.D.
|
2011-03-26 13:17:21 -07:00
|
|
|
|
*
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2011-03-26 13:17:21 -07:00
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
|
*
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2011-03-26 13:17:21 -07:00
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
*
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2023-07-27 13:54:46 -07:00
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2011-03-26 13:17:21 -07:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "ShaderTechnique.h"
|
|
|
|
|
|
|
2014-07-02 15:36:45 -07:00
|
|
|
|
#include "graphics/ShaderProgram.h"
|
2022-12-31 10:29:44 -08:00
|
|
|
|
#include "renderer/backend/IDevice.h"
|
2014-07-02 15:36:45 -07:00
|
|
|
|
|
2022-03-14 15:16:14 -07:00
|
|
|
|
CShaderPass::CShaderPass(
|
2022-12-31 10:29:44 -08:00
|
|
|
|
std::unique_ptr<Renderer::Backend::IGraphicsPipelineState> pipelineState,
|
2022-03-14 15:16:14 -07:00
|
|
|
|
const CShaderProgramPtr& shader)
|
2022-12-31 10:29:44 -08:00
|
|
|
|
: m_Shader(shader), m_PipelineState(std::move(pipelineState))
|
2011-03-26 13:17:21 -07:00
|
|
|
|
{
|
2022-12-31 10:29:44 -08:00
|
|
|
|
ENSURE(shader);
|
2022-01-19 09:28:47 -08:00
|
|
|
|
}
|
2011-03-26 13:17:21 -07:00
|
|
|
|
|
2022-12-31 10:29:44 -08:00
|
|
|
|
CShaderTechnique::CShaderTechnique(
|
|
|
|
|
|
const VfsPath& path, const CShaderDefines& defines,
|
|
|
|
|
|
const PipelineStateDescCallback& callback)
|
|
|
|
|
|
: m_Path(path), m_Defines(defines), m_PipelineStateDescCallback(callback)
|
2022-05-10 05:54:57 -07:00
|
|
|
|
{
|
|
|
|
|
|
}
|
2012-01-28 17:22:22 -08:00
|
|
|
|
|
2022-01-13 09:50:28 -08:00
|
|
|
|
void CShaderTechnique::SetPasses(std::vector<CShaderPass>&& passes)
|
2011-03-26 13:17:21 -07:00
|
|
|
|
{
|
2022-01-13 09:50:28 -08:00
|
|
|
|
m_Passes = std::move(passes);
|
2011-03-26 13:17:21 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-04-03 11:44:46 -07:00
|
|
|
|
int CShaderTechnique::GetNumPasses() const
|
2011-03-26 13:17:21 -07:00
|
|
|
|
{
|
|
|
|
|
|
return m_Passes.size();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-02 13:57:22 -07:00
|
|
|
|
Renderer::Backend::IShaderProgram* CShaderTechnique::GetShader(int pass) const
|
2011-03-26 13:17:21 -07:00
|
|
|
|
{
|
2011-04-30 06:01:45 -07:00
|
|
|
|
ENSURE(0 <= pass && pass < (int)m_Passes.size());
|
2022-12-31 10:29:44 -08:00
|
|
|
|
return m_Passes[pass].GetPipelineState()->GetShaderProgram();
|
2011-03-26 13:17:21 -07:00
|
|
|
|
}
|
2012-02-02 14:58:42 -08:00
|
|
|
|
|
2022-12-31 10:29:44 -08:00
|
|
|
|
Renderer::Backend::IGraphicsPipelineState*
|
|
|
|
|
|
CShaderTechnique::GetGraphicsPipelineState(int pass) const
|
2022-01-19 09:28:47 -08:00
|
|
|
|
{
|
|
|
|
|
|
ENSURE(0 <= pass && pass < static_cast<int>(m_Passes.size()));
|
2022-12-31 10:29:44 -08:00
|
|
|
|
return m_Passes[pass].GetPipelineState();
|
2022-01-19 09:28:47 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-04-03 11:44:46 -07:00
|
|
|
|
bool CShaderTechnique::GetSortByDistance() const
|
|
|
|
|
|
{
|
|
|
|
|
|
return m_SortByDistance;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CShaderTechnique::SetSortByDistance(bool enable)
|
|
|
|
|
|
{
|
|
|
|
|
|
m_SortByDistance = enable;
|
|
|
|
|
|
}
|