Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Material.cpp
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 #include "precompiled.h"
19 
20 #include "Material.h"
21 
22 static CColor BrokenColor(0.3f, 0.3f, 0.3f, 1.0f);
23 
25  m_AlphaBlending(false),
26  m_PlayerID(INVALID_PLAYER)
27 {
28 }
29 
30 void CMaterial::SetShaderEffect(const CStr& effect)
31 {
32  m_ShaderEffect = CStrIntern(effect);
33 }
34 
36 {
37  m_ShaderDefines.Add(key, value);
39 }
40 
41 void CMaterial::AddConditionalDefine(const char* defname, const char* defvalue, int type, std::vector<float> &args)
42 {
43  m_ConditionalDefines.Add(defname, defvalue, type, args);
45 }
46 
47 void CMaterial::AddStaticUniform(const char* key, const CVector4D& value)
48 {
49  m_StaticUniforms.Add(key, value);
50 }
51 
53 {
54  m_Samplers.push_back(texture);
55  if (texture.Name == str_baseTex)
56  m_DiffuseTexture = texture.Sampler;
57 }
58 
59 void CMaterial::AddRenderQuery(const char* key)
60 {
61  m_RenderQueries.Add(key);
62 }
63 
64 // Set up m_CombinedShaderDefines so that index i contains m_ShaderDefines, plus
65 // the extra defines from m_ConditionalDefines[j] for all j where bit j is set in i.
66 // This lets GetShaderDefines() cheaply return the defines for any combination of conditions.
67 //
68 // (This might scale badly if we had a large number of conditional defines per material,
69 // but currently we don't expect to have many.)
71 {
73  int size = m_ConditionalDefines.GetSize();
74 
75  // Loop over all 2^n combinations of flags
76  for (int i = 0; i < (1 << size); i++)
77  {
79  for (int j = 0; j < size; j++)
80  {
81  if (i & (1 << j))
82  {
84  defs.Add(def.m_DefName, def.m_DefValue);
85  }
86  }
87  m_CombinedShaderDefines.push_back(defs);
88  }
89 }
void Add(CStrIntern name, CStrIntern value)
Add a name and associated value to the map of defines.
void AddShaderDefine(CStrIntern key, CStrIntern value)
Definition: Material.cpp:35
void Add(const char *name, const CVector4D &value)
Add a name and associated value to the map of uniforms.
Definition: Overlay.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
std::vector< CShaderDefines > m_CombinedShaderDefines
Definition: Material.h:91
void SetShaderEffect(const CStr &effect)
Definition: Material.cpp:30
Interned 8-bit strings.
Definition: CStrIntern.h:37
CTexturePtr m_DiffuseTexture
Definition: Material.h:84
static CColor BrokenColor(0.3f, 0.3f, 0.3f, 1.0f)
CStrIntern m_ShaderEffect
Definition: Material.h:88
pthread_key_t key
Definition: wpthread.cpp:140
void Add(const char *name)
Represents a mapping of name strings to value strings, for use with #if and #ifdef and similar condit...
CShaderConditionalDefines m_ConditionalDefines
Definition: Material.h:90
const CondDefine & GetItem(size_t i) const
SamplersVector m_Samplers
Definition: Material.h:86
CShaderUniforms m_StaticUniforms
Definition: Material.h:92
void AddRenderQuery(const char *key)
Definition: Material.cpp:59
void RecomputeCombinedShaderDefines()
Definition: Material.cpp:70
static const player_id_t INVALID_PLAYER
Definition: Player.h:26
void Add(const char *defname, const char *defvalue, int type, std::vector< float > &args)
void AddStaticUniform(const char *key, const CVector4D &value)
Definition: Material.cpp:47
CShaderDefines m_ShaderDefines
Definition: Material.h:89