Aether3D Game Engine
Material.hpp
1 #ifndef MATERIAL_H
2 #define MATERIAL_H
3 
4 #include <string>
5 #include <unordered_map>
6 #include "Vec3.hpp"
7 #include "Matrix.hpp"
8 
9 namespace ae3d
10 {
11  struct Matrix44;
12 
14  class Material
15  {
16  public:
18  enum DepthFunction { NoneWriteOff, LessOrEqualWriteOn };
19 
23  static void SetGlobalRenderTexture( const char* name, class RenderTexture* renderTexture );
24 
26  class Shader* GetShader() { return shader; }
27 
29  bool IsValidShader() const;
30 
32  void Apply();
33 
35  bool IsBackFaceCulled() const { return cullBackFaces; }
36 
38  void SetBackFaceCulling( bool enable ) { cullBackFaces = enable; }
39 
41  DepthFunction GetDepthFunction() const { return depthFunction; }
42 
44  void SetDepthFunction( DepthFunction aDepthFunction ) { depthFunction = aDepthFunction; }
45 
48  void SetMatrix( const char* name, const Matrix44& matrix );
49 
51  void SetShader( Shader* shader );
52 
55  void SetTexture( const char* name, class Texture2D* texture );
56 
59  void SetTexture( const char* name, class TextureCube* texture );
60 
63  void SetRenderTexture( const char* name, RenderTexture* renderTexture );
64 
67  void SetInt( const char* name, int value );
68 
71  void SetFloat( const char* name, float value );
72 
75  void SetVector( const char* name, const Vec3& vec3 );
76 
79  void SetVector( const char* name, const Vec4& vec );
80 
81  private:
82  // TODO: String hash instead of string and get rid of STL *map.
83  static std::unordered_map< std::string, RenderTexture* > sTexRTs;
84 
85  std::unordered_map< std::string, float > floats;
86  std::unordered_map< std::string, int > ints;
87  std::unordered_map< std::string, Vec3 > vec3s;
88  std::unordered_map< std::string, Vec4 > vec4s;
89  std::unordered_map< std::string, Texture2D* > tex2ds;
90  std::unordered_map< std::string, TextureCube* > texCubes;
91  std::unordered_map< std::string, RenderTexture* > texRTs;
92  std::unordered_map< std::string, Matrix44 > mat4s;
93  Shader* shader = nullptr;
94  DepthFunction depthFunction = DepthFunction::LessOrEqualWriteOn;
95  bool cullBackFaces = true;
96  };
97 }
98 
99 #endif
Material is used to render a mesh.
Definition: Material.hpp:14
void SetVector(const char *name, const Vec3 &vec3)
class Shader * GetShader()
Definition: Material.hpp:26
Definition: AudioClip.hpp:4
bool IsBackFaceCulled() const
Definition: Material.hpp:35
4-component vector.
Definition: Vec3.hpp:351
void Apply()
Applies the uniforms into the shader. Called internally.
3-component vector.
Definition: Vec3.hpp:12
void SetFloat(const char *name, float value)
void SetTexture(const char *name, class Texture2D *texture)
void SetDepthFunction(DepthFunction aDepthFunction)
Definition: Material.hpp:44
Render texture.
Definition: RenderTexture.hpp:12
DepthFunction GetDepthFunction() const
Definition: Material.hpp:41
void SetInt(const char *name, int value)
void SetBackFaceCulling(bool enable)
Definition: Material.hpp:38
static void SetGlobalRenderTexture(const char *name, class RenderTexture *renderTexture)
Cube Map texture.
Definition: TextureCube.hpp:18
Shader program containing a vertex and pixel shader.
Definition: Shader.hpp:26
void SetMatrix(const char *name, const Matrix44 &matrix)
void SetRenderTexture(const char *name, RenderTexture *renderTexture)
bool IsValidShader() const
2D texture.
Definition: Texture2D.hpp:17
DepthFunction
Depth function used when rendering a mesh using material.
Definition: Material.hpp:18
void SetShader(Shader *shader)