This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
shader_utils.h
85 lines (69 loc) · 2.17 KB
/
shader_utils.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
#ifndef _SHADER_UTILS_H
#define _SHADER_UTILS_H
#include <optional>
namespace ShaderUtils
{
enum Type
{
FRAGMENT_SHADER_TYPE,
VERTEX_SHADER_TYPE,
};
struct Program
{
private:
/**
* @brief The vertex shader ID, as an optional
*/
std::optional<unsigned int> vertexShader = std::nullopt;
/**
* @brief The fragment shader ID, as an optional
*/
std::optional<unsigned int> fragmentShader = std::nullopt;
/**
* @brief The GPU program ID (or shader ID), as an optional
*/
std::optional<unsigned int> program = std::nullopt;
/**
* @brief Stores if the shader has been registered or not
*/
bool registered = false;
public:
/**
* @brief Constructor
*/
Program();
/**
* @brief Destructor
*/
~Program();
/**
* @brief Register a shader
*
* @param shader_type The type: fragment or vertex
* @param shader_source The source code as a string
* @return true The shader has been successfully registered
* @return false The shader has not been registered - error is logged
*/
bool registerShader(const Type shader_type, const char *shader_source);
/**
* @brief Register the GPU program (or shader), after compilation
* of the fragment and vertex shaders.
*
* @param erase_if_registered Erase the current program if one is already registered
* @return true The shader has been successfully registered
* @return false The shader has not been successfully registered - error is logged
*/
bool registerProgram(bool erase_if_registered);
/**
* @brief Returns the GPU program ID object, as optional
*
* @return std::optional<unsigned int>
*/
std::optional<unsigned int> getProgram() const;
/**
* @brief Returns if the GPU program object has been registered or not
*/
bool programIsRegistered() const;
};
}
#endif /* SHADER_UTILS_H */