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  class Shader;
12  class Texture2D;
13  class TextureCube;
14  class RenderTexture;
15  struct Matrix44;
16 
18  class Material
19  {
20  public:
24  static void SetGlobalRenderTexture( const char* name, RenderTexture* renderTexture );
25 
27  Shader* GetShader() const { return shader; }
28 
30  bool IsValidShader() const;
31 
33  void Apply();
34 
36  void SetBackFaceCulling( bool enable ) { cullBackFaces = enable; }
37 
40  void SetMatrix( const char* name, const Matrix44& matrix );
41 
43  void SetShader( Shader* shader );
44 
47  void SetTexture( const char* name, Texture2D* texture );
48 
51  void SetTexture( const char* name, TextureCube* texture );
52 
55  void SetRenderTexture( const char* name, RenderTexture* renderTexture );
56 
59  void SetInt( const char* name, int value );
60 
63  void SetFloat( const char* name, float value );
64 
67  void SetVector( const char* name, const Vec3& vec3 );
68 
71  void SetVector( const char* name, const Vec4& vec );
72 
73  private:
74  // TODO: String hash instead of string and get rid of STL *map.
75  static std::unordered_map< std::string, RenderTexture* > sTexRTs;
76 
77  std::unordered_map< std::string, float > floats;
78  std::unordered_map< std::string, int > ints;
79  std::unordered_map< std::string, Vec3 > vec3s;
80  std::unordered_map< std::string, Vec4 > vec4s;
81  std::unordered_map< std::string, Texture2D* > tex2ds;
82  std::unordered_map< std::string, TextureCube* > texCubes;
83  std::unordered_map< std::string, RenderTexture* > texRTs;
84  std::unordered_map< std::string, Matrix44 > mat4s;
85  Shader* shader = nullptr;
86  bool cullBackFaces = true;
87  };
88 }
89 
90 #endif
Material is used to render a mesh.
Definition: Material.hpp:18
void SetVector(const char *name, const Vec3 &vec3)
Definition: AudioClip.hpp:4
4-component vector.
Definition: Vec3.hpp:351
void SetTexture(const char *name, Texture2D *texture)
void Apply()
Applies the uniforms into the shader. Called internally.
Shader * GetShader() const
Definition: Material.hpp:27
3-component vector.
Definition: Vec3.hpp:12
void SetFloat(const char *name, float value)
Render texture.
Definition: RenderTexture.hpp:10
void SetInt(const char *name, int value)
void SetBackFaceCulling(bool enable)
Definition: Material.hpp:36
Cube Map texture.
Definition: TextureCube.hpp:15
Shader program containing a vertex and pixel shader.
Definition: Shader.hpp:22
void SetMatrix(const char *name, const Matrix44 &matrix)
void SetRenderTexture(const char *name, RenderTexture *renderTexture)
bool IsValidShader() const
2D texture.
Definition: Texture2D.hpp:15
static void SetGlobalRenderTexture(const char *name, RenderTexture *renderTexture)
void SetShader(Shader *shader)