2022-01-11 17:02:27 +01:00
|
|
|
/* Copyright (C) 2022 Wildfire Games.
|
2023-07-27 22:54:46 +02:00
|
|
|
* This file is part of 0 A.D.
|
2011-03-26 21:17:21 +01:00
|
|
|
*
|
2023-07-27 22:54:46 +02:00
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
2011-03-26 21:17:21 +01: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 22:54:46 +02:00
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
2011-03-26 21:17:21 +01: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 22:54:46 +02:00
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
2011-03-26 21:17:21 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_SHADERTECHNIQUE
|
|
|
|
#define INCLUDED_SHADERTECHNIQUE
|
|
|
|
|
2022-05-10 14:54:57 +02:00
|
|
|
#include "graphics/ShaderDefines.h"
|
2022-03-14 23:16:14 +01:00
|
|
|
#include "graphics/ShaderProgram.h"
|
2020-11-21 12:20:29 +01:00
|
|
|
#include "graphics/ShaderTechniquePtr.h"
|
2022-12-31 19:29:44 +01:00
|
|
|
#include "lib/code_annotation.h"
|
2022-05-10 14:54:57 +02:00
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
2022-01-19 18:28:47 +01:00
|
|
|
#include "renderer/backend/PipelineState.h"
|
2011-03-26 21:17:21 +01:00
|
|
|
|
2022-12-31 19:29:44 +01:00
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
2020-12-09 15:39:14 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2011-03-26 21:17:21 +01:00
|
|
|
/**
|
2022-12-31 19:29:44 +01:00
|
|
|
* Implements a render pass consisting of a pipeline state and a shader,
|
2012-04-03 20:44:46 +02:00
|
|
|
* used by CShaderTechnique.
|
2011-03-26 21:17:21 +01:00
|
|
|
*/
|
|
|
|
class CShaderPass
|
|
|
|
{
|
|
|
|
public:
|
2022-12-31 19:29:44 +01:00
|
|
|
CShaderPass(
|
|
|
|
std::unique_ptr<Renderer::Backend::IGraphicsPipelineState> pipelineState,
|
|
|
|
const CShaderProgramPtr& shader);
|
|
|
|
MOVABLE(CShaderPass);
|
2012-02-25 16:38:38 +01:00
|
|
|
|
2022-12-31 19:29:44 +01:00
|
|
|
const CShaderProgramPtr& GetShaderProgram() const noexcept { return m_Shader; }
|
2011-03-26 21:17:21 +01:00
|
|
|
|
2022-12-31 19:29:44 +01:00
|
|
|
Renderer::Backend::IGraphicsPipelineState*
|
|
|
|
GetPipelineState() const noexcept { return m_PipelineState.get(); }
|
2022-01-19 18:28:47 +01:00
|
|
|
|
2011-03-26 21:17:21 +01:00
|
|
|
private:
|
|
|
|
CShaderProgramPtr m_Shader;
|
|
|
|
|
2022-12-31 19:29:44 +01:00
|
|
|
std::unique_ptr<Renderer::Backend::IGraphicsPipelineState> m_PipelineState;
|
2011-03-26 21:17:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements a render technique consisting of a sequence of passes.
|
2012-04-03 20:44:46 +02:00
|
|
|
* CShaderManager loads these from shader effect XML files.
|
2011-03-26 21:17:21 +01:00
|
|
|
*/
|
|
|
|
class CShaderTechnique
|
|
|
|
{
|
|
|
|
public:
|
2022-12-31 19:29:44 +01:00
|
|
|
using PipelineStateDescCallback =
|
|
|
|
std::function<void(Renderer::Backend::SGraphicsPipelineStateDesc& pipelineStateDesc)>;
|
|
|
|
|
|
|
|
CShaderTechnique(const VfsPath& path, const CShaderDefines& defines, const PipelineStateDescCallback& callback);
|
2022-05-10 14:54:57 +02:00
|
|
|
|
2022-01-13 18:50:28 +01:00
|
|
|
void SetPasses(std::vector<CShaderPass>&& passes);
|
2011-03-26 21:17:21 +01:00
|
|
|
|
2012-04-03 20:44:46 +02:00
|
|
|
int GetNumPasses() const;
|
2011-03-26 21:17:21 +01:00
|
|
|
|
2022-05-02 22:57:22 +02:00
|
|
|
Renderer::Backend::IShaderProgram* GetShader(int pass = 0) const;
|
2012-04-03 20:44:46 +02:00
|
|
|
|
2022-12-31 19:29:44 +01:00
|
|
|
Renderer::Backend::IGraphicsPipelineState*
|
|
|
|
GetGraphicsPipelineState(int pass = 0) const;
|
2022-01-19 18:28:47 +01:00
|
|
|
|
2012-04-03 20:44:46 +02:00
|
|
|
/**
|
|
|
|
* Whether this technique uses alpha blending that requires objects to be
|
|
|
|
* drawn from furthest to nearest.
|
|
|
|
*/
|
|
|
|
bool GetSortByDistance() const;
|
|
|
|
|
|
|
|
void SetSortByDistance(bool enable);
|
2011-03-26 21:17:21 +01:00
|
|
|
|
2022-05-10 14:54:57 +02:00
|
|
|
const VfsPath& GetPath() { return m_Path; }
|
|
|
|
|
|
|
|
const CShaderDefines& GetShaderDefines() { return m_Defines; }
|
|
|
|
|
2022-12-31 19:29:44 +01:00
|
|
|
const PipelineStateDescCallback& GetPipelineStateDescCallback() const { return m_PipelineStateDescCallback; };
|
|
|
|
|
2011-03-26 21:17:21 +01:00
|
|
|
private:
|
|
|
|
std::vector<CShaderPass> m_Passes;
|
2012-04-03 20:44:46 +02:00
|
|
|
|
2022-01-13 18:50:28 +01:00
|
|
|
bool m_SortByDistance = false;
|
2022-05-10 14:54:57 +02:00
|
|
|
|
|
|
|
// We need additional data to reload the technique.
|
|
|
|
VfsPath m_Path;
|
|
|
|
CShaderDefines m_Defines;
|
2022-12-31 19:29:44 +01:00
|
|
|
|
|
|
|
PipelineStateDescCallback m_PipelineStateDescCallback;
|
2011-03-26 21:17:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // INCLUDED_SHADERTECHNIQUE
|