xoreos  0.0.5
shadersurface.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_SHADERSURFACE_H
26 #define GRAPHICS_SHADER_SHADERSURFACE_H
27 
28 #include "glm/mat4x4.hpp"
29 
31 
32 namespace Graphics {
33 
34 namespace Shader {
35 
36 #define SHADER_SURFACE_WIREFRAME (0x00000001) // Surface should be rendered in wireframe mode.
37 #define SHADER_SURFACE_INSTANCED (0x00000002) // Surface is used for mesh instancing.
38 #define SHADER_SURFACE_NOCULL (0x00000004) // No face culling is applied.
39 
41 public:
42  ShaderSurface(Shader::ShaderObject *vertShader, const Common::UString &name = "unnamed");
44 
45  const Common::UString &getName() const;
46 
48 
49  uint32 getFlags() const;
50  void setFlags(uint32 flags);
51 
52  uint32 getVariableCount() const;
53 
55 
56  void *getVariableData(uint32 index) const;
57  void *getVariableData(const Common::UString &name) const;
58 
59  const Common::UString &getVariableName(uint32 index) const;
60 
61  uint32 getVariableFlags(uint32 index) const;
62 
63  // Do not use this function to set sampler data. Instead, get the the variable data and modify
64  // it directly; the texture unit associated with the texture id might be incorrect otherwise.
65  // (Note: at the time of writing, vertex shader samplers are not supported).
66  void setVariableExternal(uint32 index, void *loc);
67  void setVariableExternal(const Common::UString &name, void *loc);
68  void setVariableInternal(uint32 index);
69  void setVariableInternal(const Common::UString &name);
70 
71  bool isVariableOwned(uint32 index) const;
72  bool isVariableOwned(const Common::UString &name) const;
73 
74  // UBOs (Uniform Buffer Objects) are only for >= GL3.x.
75  void addUBO(uint32 index, GLuint glid);
76 
77  void bindProgram(Shader::ShaderProgram *program);
78  void bindProgram(Shader::ShaderProgram *program, const glm::mat4 *t);
79  void bindObjectModelview(Shader::ShaderProgram *program, const glm::mat4 *t);
80  void bindTextureView(Shader::ShaderProgram *program, const glm::mat4 *t);
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<ShaderSurfaceVariable> _variableData;
97  std::vector<Shader::ShaderUBO> _uboArray;
100 
103 
106 
107  void *genSurfaceVar(uint32 index);
108  void delSurfaceVar(uint32 index);
109 };
110 
111 } // End of namespace Shader
112 
113 } // End of namespace Graphics
114 
115 #endif // GRAPHICS_SHADER_SHADERSURFACE_H
void * getVariableData(uint32 index) const
Shader::ShaderVariableType getVariableType(uint32 index) const
A class holding an UTF-8 string.
Definition: ustring.h:48
void bindTextureView(Shader::ShaderProgram *program, const glm::mat4 *t)
void setVariableExternal(uint32 index, void *loc)
Shader::ShaderObject * _vertShader
Definition: shadersurface.h:98
void bindProgram(Shader::ShaderProgram *program)
void setVariableInternal(uint32 index)
The global shader manager.
ShaderSurface(Shader::ShaderObject *vertShader, const Common::UString &name="unnamed")
ShaderVariableType
Enum of all supported shader variable parsing and automatic binding.
Definition: shader.h:85
void addUBO(uint32 index, GLuint glid)
std::vector< ShaderSurfaceVariable > _variableData
Definition: shadersurface.h:96
void * genSurfaceVar(uint32 index)
uint32_t uint32
Definition: types.h:204
bool isVariableOwned(uint32 index) const
Shader::ShaderObject * getVertexShader() const
uint32 getVariableFlags(uint32 index) const
const Common::UString & getName() const
std::vector< Shader::ShaderUBO > _uboArray
Definition: shadersurface.h:97
const Common::UString & getVariableName(uint32 index) const
void bindObjectModelview(Shader::ShaderProgram *program, const glm::mat4 *t)