-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMaterial.h
95 lines (90 loc) · 5.67 KB
/
Material.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef MATERIAL_H
#define MATERIAL_H
#include <array>
#include <mat4x4.hpp>
#include <memory>
#include <QKeyEvent>
#include "ShaderLib.h"
#include "Camera.h"
class Material
{
public:
//-----------------------------------------------------------------------------------------------------
/// @brief Constructor
/// @param [io] io_camera is the camera that is viewing the material
/// @param [io] io_shaderLib contains the shader program that this material affects.
/// @param [io] io_matrices is a pointer to the scene matrices used for the vertex shader.
//-----------------------------------------------------------------------------------------------------
Material(
const std::shared_ptr<Camera> &io_camera,
const std::shared_ptr<ShaderLib> &io_shaderLib,
std::array<glm::mat4, 3>* io_matrices
) :
m_shaderLib(io_shaderLib),
m_matrices(io_matrices),
m_cam(io_camera)
{}
//-----------------------------------------------------------------------------------------------------
/// @brief Default copy constructor.
//-----------------------------------------------------------------------------------------------------
Material(const Material&) = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default copy assignment operator.
//-----------------------------------------------------------------------------------------------------
Material& operator=(const Material&) = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default move constructor.
//-----------------------------------------------------------------------------------------------------
Material(Material&&) = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default move assignment operator.
//-----------------------------------------------------------------------------------------------------
Material& operator=(Material&&) = default;
//-----------------------------------------------------------------------------------------------------
/// @brief Default virtual destructor.
//-----------------------------------------------------------------------------------------------------
virtual ~Material();
//-----------------------------------------------------------------------------------------------------
/// @brief Used to intialise a passed shader, subclasses must call this base function.
//-----------------------------------------------------------------------------------------------------
virtual void init() = 0;
//-----------------------------------------------------------------------------------------------------
/// @brief Used to set the name of the shader that this material should be applied to.
//-----------------------------------------------------------------------------------------------------
void setShaderName(const std::string &_name);
//-----------------------------------------------------------------------------------------------------
/// @brief Used to get the name of the shader that this material should be applied to.
//-----------------------------------------------------------------------------------------------------
std::string getShaderName() const noexcept;
//-----------------------------------------------------------------------------------------------------
/// @brief Used to update shader values.
//-----------------------------------------------------------------------------------------------------
virtual void update() = 0;
//-----------------------------------------------------------------------------------------------------
/// @brief Used to set this as the active shader, and pass the uniform values stored in this material.
//-----------------------------------------------------------------------------------------------------
void apply();
//-----------------------------------------------------------------------------------------------------
/// @brief The file name of the json shader file that this material works with.
//-----------------------------------------------------------------------------------------------------
virtual const char* shaderFileName() const = 0;
virtual void handleKey(QKeyEvent* io_event, QOpenGLContext* io_context);
protected:
//-----------------------------------------------------------------------------------------------------
/// @brief A pointer to the central Shader Library.
//-----------------------------------------------------------------------------------------------------
std::shared_ptr<ShaderLib> m_shaderLib = nullptr;
//-----------------------------------------------------------------------------------------------------
/// @brief Unique id of the shader within the shader library, that this material affects.
//-----------------------------------------------------------------------------------------------------
std::string m_shaderName;
//-----------------------------------------------------------------------------------------------------
/// @brief A pointer to matrices this material should use for the vertex shader.
//-----------------------------------------------------------------------------------------------------
std::array<glm::mat4, 3>* m_matrices = nullptr;
//-----------------------------------------------------------------------------------------------------
/// @brief A pointer to the camera that is viewing the material.
//-----------------------------------------------------------------------------------------------------
std::shared_ptr<Camera> m_cam = nullptr;
};
#endif // MATERIAL_H