Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
Material.h
Go to the documentation of this file.
1/* Copyright (C) 2026 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#ifndef INCLUDED_MATERIAL
19#define INCLUDED_MATERIAL
20
22#include "graphics/Texture.h"
23#include "ps/CStr.h"
24#include "ps/CStrIntern.h"
25
26#include <array>
27#include <vector>
28
29class CVector4D;
30
32{
33public:
34 enum class Pass : uint8_t
35 {
36 MAIN,
37 SHADOW_CASTER,
38 REFLECTIONS,
39 REFRACTIONS,
40 SILHOUETTE_OCCLUDER,
41 SILHOUETTE_CASTER,
43 WIREFRAME_SOLID,
44 COUNT
45 };
46
48 {
49 TextureSampler(const CStr &n, CTexturePtr t) : Name(n), Sampler(t) {}
51
54 };
55
57 {
59 bool sRGB;
60 };
61
62 typedef std::vector<TextureSampler> SamplersVector;
63
64 CMaterial();
65
66 // Whether this material's shaders use alpha blending, in which case
67 // models using this material need to be rendered in a special order
68 // relative to the alpha-blended water plane
69 void SetUsesAlphaBlending(bool flag) { m_AlphaBlending = flag; }
70 bool UsesAlphaBlending() const { return m_AlphaBlending; }
71
73
74 void SetShaderEffect(const Pass pass, CStrIntern effect);
75 CStrIntern GetShaderEffect(const Pass pass) const;
76
77 // Must call RecomputeCombinedShaderDefines after this, before rendering with this material
79
81
82 void AddStaticUniform(const char* key, const CVector4D& value);
84
85 void AddSampler(const TextureSampler& texture);
86 const SamplersVector& GetSamplers() const { return m_Samplers; }
87
88 void AddRenderQuery(const char* key);
90
91 void AddRequiredSampler(RequiredSampler sampler);
92 const std::vector<RequiredSampler>& GetRequiredSamplers() const { return m_RequiredSamplers; }
93
94private:
95
96 // This pointer is kept to make it easier for the fixed pipeline to
97 // access the only texture it's interested in.
99
101 std::vector<RequiredSampler> m_RequiredSamplers;
102
103 std::array<CStrIntern, static_cast<size_t>(Pass::COUNT)> m_ShaderEffects;
107
109};
110
111#endif // INCLUDED_MATERIAL
@ WIREFRAME
Definition: SceneRenderer.h:42
Definition: Material.h:32
const CShaderDefines & GetShaderDefines() const
Definition: Material.h:80
SamplersVector m_Samplers
Definition: Material.h:100
CShaderRenderQueries m_RenderQueries
Definition: Material.h:106
void AddRenderQuery(const char *key)
Definition: Material.cpp:60
const std::vector< RequiredSampler > & GetRequiredSamplers() const
Definition: Material.h:92
const CShaderUniforms & GetStaticUniforms() const
Definition: Material.h:83
std::array< CStrIntern, static_cast< size_t >(Pass::COUNT)> m_ShaderEffects
Definition: Material.h:103
void AddRequiredSampler(RequiredSampler sampler)
Definition: Material.cpp:65
bool UsesAlphaBlending() const
Definition: Material.h:70
const SamplersVector & GetSamplers() const
Definition: Material.h:86
std::vector< TextureSampler > SamplersVector
Definition: Material.h:62
CShaderUniforms m_StaticUniforms
Definition: Material.h:105
std::vector< RequiredSampler > m_RequiredSamplers
Definition: Material.h:101
CTexturePtr m_DiffuseTexture
Definition: Material.h:98
Pass
Definition: Material.h:35
void SetUsesAlphaBlending(bool flag)
Definition: Material.h:69
const CTexturePtr & GetDiffuseTexture() const
Definition: Material.h:72
void SetShaderEffect(const Pass pass, CStrIntern effect)
Definition: Material.cpp:37
CStrIntern GetShaderEffect(const Pass pass) const
Definition: Material.cpp:31
void AddSampler(const TextureSampler &texture)
Definition: Material.cpp:53
bool m_AlphaBlending
Definition: Material.h:108
CShaderDefines m_ShaderDefines
Definition: Material.h:104
void AddStaticUniform(const char *key, const CVector4D &value)
Definition: Material.cpp:48
void AddShaderDefine(CStrIntern key, CStrIntern value)
Definition: Material.cpp:43
CMaterial()
Definition: Material.cpp:26
const CShaderRenderQueries & GetRenderQueries() const
Definition: Material.h:89
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
Definition: ShaderDefines.h:153
Uniform values that need to be evaluated in the renderer.
Definition: ShaderDefines.h:209
Represents a mapping of name strings to value CVector4Ds, for use with uniforms in shaders.
Definition: ShaderDefines.h:174
Interned 8-bit strings.
Definition: CStrIntern.h:42
Definition: Vector4D.h:30
std::shared_ptr< CTexture > CTexturePtr
Definition: Texture.h:25
Definition: Material.h:57
bool sRGB
Definition: Material.h:59
CStrIntern name
Definition: Material.h:58
Definition: Material.h:48
CTexturePtr Sampler
Definition: Material.h:53
CStrIntern Name
Definition: Material.h:52
TextureSampler(const CStr &n, CTexturePtr t)
Definition: Material.h:49
TextureSampler(const CStrIntern &n, CTexturePtr t)
Definition: Material.h:50
pthread_key_t key
Definition: wpthread.cpp:141