gdk-graphics 0b051eb9b5c1eaa0658babaa4463dd7a80aa9d2c
Loading...
Searching...
No Matches
webgl1es2_material.h
1// © 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 <array>
10#include <optional>
11#include <unordered_map>
12
13namespace gdk {
17 public:
20 //
21 virtual void set_texture(const std::string_view aName, const texture_ptr_type aTexture) override;
22
23 virtual void set_float(const std::string_view aName, float aValue) override;
24 virtual void set_vector2(const std::string_view aName, graphics_vector2_type aValue) override;
25 virtual void set_vector3(const std::string_view aName, graphics_vector3_type aValue) override;
26 virtual void set_vector4(const std::string_view aName, graphics_vector4_type aValue) override;
27
28 virtual void set_integer(const std::string_view aName, int aValue) override;
29 virtual void set_integer2(const std::string_view aName, int aValue1, int aValue2) override;
30 virtual void set_integer3(const std::string_view aName, int aValue1, int aValue2, int aValue3) override;
31 virtual void set_integer4(const std::string_view aName, int aValue1, int aValue2, int aValue3, int aValue4) override;
32
33 virtual void set_int_vector2_array(const std::string_view aName, const std::vector<graphics_intvector2_type> &aValue) override;
35
37 using shader_ptr_type = std::shared_ptr<gdk::webgl1es2_shader_program>;
38
41 //
42 material::render_mode get_render_mode() const;
43
44 shader_ptr_type getShaderProgram();
46 void activate();
52
57
67 material::face_culling_mode aface_culling_mode,
68 material::render_mode aRenderMode);
69
72
73 private:
74 using texture_ptr_impl_type = std::shared_ptr<webgl1es2_texture>;
75
77 using texture_uniform_collection_type =
78 std::unordered_map<std::string, texture_ptr_impl_type>;
79
81 shader_ptr_type m_pShaderProgram;
82
85
88
90 texture_uniform_collection_type m_Textures;
91
93 std::unordered_map<std::string, float> m_Floats;
94
96 std::unordered_map<std::string, graphics_vector2_type> m_Vector2s;
97
99 std::unordered_map<std::string, graphics_vector3_type> m_vector3s;
100
102 std::unordered_map<std::string, graphics_vector4_type> m_vector4s;
103
105 std::unordered_map<std::string, int> m_Integers;
106
108 std::unordered_map<std::string, graphics_intvector2_type> m_Integer2s;
109
111 std::unordered_map<std::string, graphics_intvector3_type> m_Integer3s;
112
114 std::unordered_map<std::string, graphics_intvector4_type> m_Integer4s;
115
116 std::unordered_map<std::string, std::vector<graphics_intvector2_type>> m_IntVector2Arrays;
117 };
118}
119
120#endif
121
decides how models using the material should be drawn.
Definition material.h:22
std::shared_ptr< gdk::texture > texture_ptr_type
textures can be shared among many webgl1es2_materials.
Definition material.h:39
face_culling_mode
specify whether front- or back-facing polygons can be culled
Definition material.h:25
@ none
do not cull any polygons
Definition material.h:29
render_mode
render mode decides transparency etc
Definition material.h:33
@ opaque
no transparency
Definition material.h:34
virtual void set_texture(const std::string_view aName, const texture_ptr_type aTexture) override
assigns a texture to the material.
virtual void set_float(const std::string_view aName, float aValue) override
assigns a float to the material.
virtual void set_integer(const std::string_view aName, int aValue) override
assigns an integer to the material.
virtual void set_vector4(const std::string_view aName, graphics_vector4_type aValue) override
assigns a 4 component vector
~webgl1es2_material()=default
trivial destructor
std::shared_ptr< gdk::webgl1es2_shader_program > shader_ptr_type
shaders can be shared among many webgl1es2_materials
Definition webgl1es2_material.h:37
webgl1es2_material(webgl1es2_material &&)=default
support move semantics
webgl1es2_material(const webgl1es2_material &)=default
support copy semantics
webgl1es2_material(shader_ptr_type pShader, material::face_culling_mode aface_culling_mode, material::render_mode aRenderMode)
virtual void set_integer2(const std::string_view aName, int aValue1, int aValue2) override
assigns a 2 integer array to the material.
virtual void set_vector3(const std::string_view aName, graphics_vector3_type aValue) override
assigns a 3 component vector
webgl1es2_material & operator=(const webgl1es2_material &)=default
support copy semantics
void activate()
modifies the opengl state, assigning the program, assigning values to the program's uniforms etc.
virtual void set_integer4(const std::string_view aName, int aValue1, int aValue2, int aValue3, int aValue4) override
assigns a 4 integer array to the material.
virtual void set_int_vector2_array(const std::string_view aName, const std::vector< graphics_intvector2_type > &aValue) override
assigns an array of integer vector2s to the material
virtual void set_integer3(const std::string_view aName, int aValue1, int aValue2, int aValue3) override
assigns a 3 integer array to the material.
webgl1es2_material & operator=(webgl1es2_material &&)=default
support move semantics
virtual void set_vector2(const std::string_view aName, graphics_vector2_type aValue) override
assigns a 2 component vector