xoreos  0.0.5
shadermaterial.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef GRAPHICS_SHADER_SHADERMATERIAL_H
26 #define GRAPHICS_SHADER_SHADERMATERIAL_H
27 
29 
30 namespace Graphics {
31 
32 namespace Shader {
33 
35 public:
36  enum {
37  MATERIAL_OPAQUE = 0x0001,
40  MATERIAL_DECAL = 0x0008,
42  };
43 
44  ShaderMaterial(Shader::ShaderObject *fragShader, const Common::UString &name = "unnamed");
46 
47  const Common::UString &getName() const;
48 
49  uint32 getFlags() const;
50  void setFlags(uint32 flags);
51 
53 
54  uint32 getVariableCount() const;
55 
57 
58  void *getVariableData(uint32 index) const;
59  void *getVariableData(const Common::UString &name) const;
60 
61  const Common::UString &getVariableName(uint32 index) const;
62 
63  uint32 getVariableFlags(uint32 index) const;
64 
65  // Do not use this function to set sampler data. Instead, get the the variable data and modify
66  // it directly; the texture unit associated with the texture id might be incorrect otherwise.
67  void setVariableExternal(uint32 index, void *loc, bool textureUnitRecalc = true);
68  void setVariableExternal(const Common::UString &name, void *loc, bool textureUnitRecalc = true);
69  void setVariableInternal(uint32 index, bool textureUnitRecalc = true);
70  void setVariableInternal(const Common::UString &name, bool textureUnitRecalc = true);
71 
72  void recalcTextureUnits();
73 
74  bool isVariableOwned(uint32 index) const;
75  bool isVariableOwned(const Common::UString &name) const;
76 
77  void bindProgram(Shader::ShaderProgram *program);
79  void bindProgram(Shader::ShaderProgram *program, float fade);
80  void bindFade(Shader::ShaderProgram *program, float fade);
81 
82  void bindGLState();
83  void unbindGLState();
84  void restoreGLState();
85 
86  void useIncrement();
87  void useDecrement();
88  uint32 useCount() const;
89 
90 private:
92  void *data;
93  uint32 flags; // Full flags may or may not be required here.
94  };
95 
96  std::vector<ShaderMaterialVariable> _variableData;
99 
102 
104 
105  void *genMaterialVar(uint32 index);
106  void delMaterialVar(uint32 index);
107 };
108 
109 } // End of namespace Shader
110 
111 } // End of namespace Graphics
112 
113 #endif // GRAPHICS_SHADER_SHADERMATERIAL_H
A class holding an UTF-8 string.
Definition: ustring.h:48
bool isVariableOwned(uint32 index) const
Shader::ShaderVariableType getVariableType(uint32 index) const
Shader::ShaderObject * getFragmentShader() const
void * getVariableData(uint32 index) const
ShaderMaterial(Shader::ShaderObject *fragShader, const Common::UString &name="unnamed")
Render hint; material has no transparency.
Different to default blending. Maybe this should be extended one day.
void bindFade(Shader::ShaderProgram *program, float fade)
const Common::UString & getName() const
The global shader manager.
ShaderVariableType
Enum of all supported shader variable parsing and automatic binding.
Definition: shader.h:85
Shader::ShaderObject * _fragShader
Material definitely has transparency.
void * genMaterialVar(uint32 index)
void bindProgram(Shader::ShaderProgram *program)
Material definitely has transparency.
uint32_t uint32
Definition: types.h:204
void bindProgramNoFade(Shader::ShaderProgram *program)
void setVariableExternal(uint32 index, void *loc, bool textureUnitRecalc=true)
const Common::UString & getVariableName(uint32 index) const
std::vector< ShaderMaterialVariable > _variableData
void setVariableInternal(uint32 index, bool textureUnitRecalc=true)
uint32 getVariableFlags(uint32 index) const