Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Material.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 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/ShaderDefines.h"
22 #include "graphics/Texture.h"
23 #include "ps/CStr.h"
24 #include "ps/CStrIntern.h"
25 #include "ps/Overlay.h"
27 
28 class CMaterial
29 {
30 public:
31 
33  {
34  TextureSampler(CStr &n, CTexturePtr t) : Name(n), Sampler(t) {}
35 
38  };
39 
40  typedef std::vector<TextureSampler> SamplersVector;
41 
42  CMaterial();
43 
44  // Whether this material's shaders use alpha blending, in which case
45  // models using this material need to be rendered in a special order
46  // relative to the alpha-blended water plane
47  void SetUsesAlphaBlending(bool flag) { m_AlphaBlending = flag; }
49 
50  const CTexturePtr& GetDiffuseTexture() const { return m_DiffuseTexture; }
51 
52  void SetShaderEffect(const CStr& effect);
54 
55  // Must call RecomputeCombinedShaderDefines after this, before rendering with this material
57 
58  // conditionFlags is a bitmask representing which indexes of the
59  // GetConditionalDefines() list are currently matching.
60  // Use 0 if you don't care about conditional defines.
61  const CShaderDefines& GetShaderDefines(uint32_t conditionFlags) const { return m_CombinedShaderDefines.at(conditionFlags); }
62 
63  // Must call RecomputeCombinedShaderDefines after this, before rendering with this material
64  void AddConditionalDefine(const char* defname, const char* defvalue, int type, std::vector<float> &args);
65 
67 
68  void AddStaticUniform(const char* key, const CVector4D& value);
70 
71  void AddSampler(const TextureSampler& texture);
72  const SamplersVector& GetSamplers() const { return m_Samplers; }
73 
74  void AddRenderQuery(const char* key);
76 
77  // Must be called after all AddShaderDefine and AddConditionalDefine
79 
80 private:
81 
82  // This pointer is kept to make it easier for the fixed pipeline to
83  // access the only texture it's interested in.
85 
87 
91  std::vector<CShaderDefines> m_CombinedShaderDefines;
94 
96 
98 };
99 
100 #endif
const CShaderRenderQueries & GetRenderQueries() const
Definition: Material.h:75
void AddShaderDefine(CStrIntern key, CStrIntern value)
Definition: Material.cpp:35
bool UsesAlphaBlending()
Definition: Material.h:48
TextureSampler(CStr &n, CTexturePtr t)
Definition: Material.h:34
void AddSampler(const TextureSampler &texture)
Definition: Material.cpp:52
void AddConditionalDefine(const char *defname, const char *defvalue, int type, std::vector< float > &args)
Definition: Material.cpp:41
CShaderRenderQueries m_RenderQueries
Definition: Material.h:93
bool m_AlphaBlending
Definition: Material.h:95
void SetUsesAlphaBlending(bool flag)
Definition: Material.h:47
std::vector< CShaderDefines > m_CombinedShaderDefines
Definition: Material.h:91
Uniform values that need to be evaluated in the renderer.
const CTexturePtr & GetDiffuseTexture() const
Definition: Material.h:50
int32_t player_id_t
valid player IDs are non-negative (see ICmpOwnership)
Definition: Player.h:24
void SetShaderEffect(const CStr &effect)
Definition: Material.cpp:30
Interned 8-bit strings.
Definition: CStrIntern.h:37
CTexturePtr m_DiffuseTexture
Definition: Material.h:84
CStrIntern m_ShaderEffect
Definition: Material.h:88
pthread_key_t key
Definition: wpthread.cpp:140
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
Represents a mapping of name strings to value CVector4Ds, for use with uniforms in shaders...
CShaderConditionalDefines m_ConditionalDefines
Definition: Material.h:90
const SamplersVector & GetSamplers() const
Definition: Material.h:72
unsigned int uint32_t
Definition: wposix_types.h:53
const CShaderUniforms & GetStaticUniforms() const
Definition: Material.h:69
std::vector< TextureSampler > SamplersVector
Definition: Material.h:40
SamplersVector m_Samplers
Definition: Material.h:86
CShaderUniforms m_StaticUniforms
Definition: Material.h:92
const CShaderDefines & GetShaderDefines(uint32_t conditionFlags) const
Definition: Material.h:61
void AddRenderQuery(const char *key)
Definition: Material.cpp:59
const CShaderConditionalDefines & GetConditionalDefines() const
Definition: Material.h:66
CStrIntern GetShaderEffect() const
Definition: Material.h:53
void RecomputeCombinedShaderDefines()
Definition: Material.cpp:70
void AddStaticUniform(const char *key, const CVector4D &value)
Definition: Material.cpp:47
CShaderDefines m_ShaderDefines
Definition: Material.h:89
player_id_t m_PlayerID
Definition: Material.h:97
shared_ptr< CTexture > CTexturePtr
Definition: Texture.h:22