gdk-graphics  1b6d84e044c2c953fd7c9501e628a67e80f4da0d
webgl1es2_material.h
1 // © 2019 Joseph Cameron - All Rights Reserved
2 
3 #ifndef GDK_GFX_WEBGL1ES2_MATERIAL_H
4 #define GDK_GFX_WEBGL1ES2_MATERIAL_H
5 
6 #include <gdk/material.h>
7 #include <gdk/webgl1es2_shader_program.h>
8 
9 #include <unordered_map>
10 #include <array>
11 #include <optional>
12 
13 namespace gdk
14 {
18  {
19  public:
22  //
23  virtual void setTexture(const std::string& aName, texture_ptr_type aTexture) override;
24 
25  virtual void setFloat(const std::string& aName, float aValue) override;
26  virtual void setVector2(const std::string& aName, graphics_vector2_type aValue) override;
27  virtual void setVector3(const std::string &aName, graphics_vector3_type aValue) override;
28  virtual void setVector4(const std::string &aName, graphics_vector4_type aValue) override;
29 
30  virtual void setInteger(const std::string& aName, int aValue) override;
31  virtual void setInteger2(const std::string& aName, int aValue1, int aValue2) override;
32  virtual void setInteger3(const std::string& aName, int aValue1, int aValue2,
33  int aValue3) override;
34  virtual void setInteger4(const std::string& aName, int aValue1, int aValue2,
35  int aValue3, int aValue4) override;
37 
39  using shader_ptr_type = std::shared_ptr<gdk::webgl1es2_shader_program>;
40 
43  //
44  material::render_mode get_render_mode() const;
45 
46  shader_ptr_type getShaderProgram();
48  void activate();
54 
58  webgl1es2_material(const webgl1es2_material&) = default;
59 
69  material::FaceCullingMode aFaceCullingMode,
70  material::render_mode aRenderMode);
71 
73  ~webgl1es2_material() = default;
74 
75  private:
76  using texture_ptr_impl_type = std::shared_ptr<webgl1es2_texture>;
77 
79  using texture_uniform_collection_type =
80  std::unordered_map<std::string, texture_ptr_impl_type>;
81 
83  shader_ptr_type m_pShaderProgram;
84 
87 
90 
92  texture_uniform_collection_type m_Textures;
93 
95  std::unordered_map<std::string, float> m_Floats;
96 
98  std::unordered_map<std::string, graphics_vector2_type> m_Vector2s;
99 
101  std::unordered_map<std::string, graphics_vector3_type> m_Vector3s;
102 
104  std::unordered_map<std::string, graphics_vector4_type> m_Vector4s;
105 
107  std::unordered_map<std::string, int> m_Integers;
108 
110  std::unordered_map<std::string, std::array<int, 2>> m_Integer2s;
111 
113  std::unordered_map<std::string, std::array<int, 3>> m_Integer3s;
114 
116  std::unordered_map<std::string, std::array<int, 4>> m_Integer4s;
117  };
118 }
119 
120 #endif
121 
virtual void setInteger4(const std::string &aName, int aValue1, int aValue2, int aValue3, int aValue4) override
assigns a 4 integer array to the material.
void activate()
modifies the opengl state, assigning the program, assigning values to the program&#39;s uniforms etc...
Definition: webgl1es2_material.h:17
Definition: camera.h:9
webgl1es2_material(webgl1es2_material &&)=default
support move semantics
virtual void setTexture(const std::string &aName, texture_ptr_type aTexture) override
assigns a texture to the material.
do not cull any polygons
virtual void setVector4(const std::string &aName, graphics_vector4_type aValue) override
assigns a 4 component vector
virtual void setFloat(const std::string &aName, float aValue) override
assigns a float to the material.
webgl1es2_material & operator=(webgl1es2_material &&)=default
support move semantics
std::shared_ptr< gdk::texture > texture_ptr_type
textures can be shared among many webgl1es2_materials.
Definition: material.h:40
std::shared_ptr< gdk::webgl1es2_shader_program > shader_ptr_type
shaders can be shared among many webgl1es2_materials
Definition: webgl1es2_material.h:39
virtual void setVector2(const std::string &aName, graphics_vector2_type aValue) override
assigns a 2 component vector
decides how models using the material should be drawn.
Definition: material.h:20
virtual void setInteger(const std::string &aName, int aValue) override
assigns an integer to the material.
render_mode
render mode decides transparency etc
Definition: material.h:33
virtual void setInteger3(const std::string &aName, int aValue1, int aValue2, int aValue3) override
assigns a 3 integer array to the material.
FaceCullingMode
specify whether front- or back-facing polygons can be culled
Definition: material.h:24
virtual void setVector3(const std::string &aName, graphics_vector3_type aValue) override
assigns a 3 component vector
~webgl1es2_material()=default
trivial destructor
virtual void setInteger2(const std::string &aName, int aValue1, int aValue2) override
assigns a 2 integer array to the material.