Line data Source code
1 : /* Copyright (C) 2022 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 :
21 : #include "graphics/Color.h"
22 : #include "graphics/ShaderDefines.h"
23 : #include "graphics/Texture.h"
24 : #include "ps/CStr.h"
25 : #include "ps/CStrIntern.h"
26 : #include "simulation2/helpers/Player.h"
27 :
28 0 : class CMaterial
29 : {
30 : public:
31 :
32 0 : struct TextureSampler
33 : {
34 0 : TextureSampler(const CStr &n, CTexturePtr t) : Name(n), Sampler(t) {}
35 0 : TextureSampler(const CStrIntern &n, CTexturePtr t) : Name(n), Sampler(t) {}
36 :
37 : CStrIntern Name;
38 : CTexturePtr Sampler;
39 : };
40 :
41 : typedef std::vector<TextureSampler> SamplersVector;
42 :
43 : CMaterial();
44 :
45 : // Whether this material's shaders use alpha blending, in which case
46 : // models using this material need to be rendered in a special order
47 : // relative to the alpha-blended water plane
48 0 : void SetUsesAlphaBlending(bool flag) { m_AlphaBlending = flag; }
49 0 : bool UsesAlphaBlending() const { return m_AlphaBlending; }
50 :
51 0 : const CTexturePtr& GetDiffuseTexture() const { return m_DiffuseTexture; }
52 :
53 : void SetShaderEffect(const CStr& effect);
54 0 : CStrIntern GetShaderEffect() const { return m_ShaderEffect; }
55 :
56 : // Must call RecomputeCombinedShaderDefines after this, before rendering with this material
57 : void AddShaderDefine(CStrIntern key, CStrIntern value);
58 :
59 0 : const CShaderDefines& GetShaderDefines() const { return m_ShaderDefines; }
60 :
61 : void AddStaticUniform(const char* key, const CVector4D& value);
62 0 : const CShaderUniforms& GetStaticUniforms() const { return m_StaticUniforms; }
63 :
64 : void AddSampler(const TextureSampler& texture);
65 0 : const SamplersVector& GetSamplers() const { return m_Samplers; }
66 :
67 : void AddRenderQuery(const char* key);
68 0 : const CShaderRenderQueries& GetRenderQueries() const { return m_RenderQueries; }
69 :
70 : void AddRequiredSampler(const CStr& samplerName);
71 0 : const std::vector<CStrIntern>& GetRequiredSampler() const { return m_RequiredSamplers; }
72 :
73 : private:
74 :
75 : // This pointer is kept to make it easier for the fixed pipeline to
76 : // access the only texture it's interested in.
77 : CTexturePtr m_DiffuseTexture;
78 :
79 : SamplersVector m_Samplers;
80 : std::vector<CStrIntern> m_RequiredSamplers;
81 :
82 : CStrIntern m_ShaderEffect;
83 : CShaderDefines m_ShaderDefines;
84 : CShaderUniforms m_StaticUniforms;
85 : CShaderRenderQueries m_RenderQueries;
86 :
87 : bool m_AlphaBlending;
88 : };
89 :
90 : #endif // INCLUDED_MATERIAL
|