-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.hpp
More file actions
141 lines (118 loc) · 7.3 KB
/
Copy pathProgram.hpp
File metadata and controls
141 lines (118 loc) · 7.3 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#pragma once
#include <cstddef>
#include <cstdint>
#include <optional>
#include <span>
#include <string>
#include <vector>
#include "easygl/Export.hpp"
#include "easygl/Types.hpp"
#include "easygl/detail/GenerationTracked.hpp"
#include "easygl/detail/NonCopyable.hpp"
namespace easygl
{
class Shader;
class EASYGL_API Program : public detail::NonCopyable, public detail::GenerationTracked
{
public:
Program();
Program(const std::string& vertex_source, const std::string& fragment_source);
~Program();
Program(Program&& other) noexcept;
Program& operator=(Program&& other) noexcept;
void create();
void destroy() noexcept;
void attach(const Shader& shader);
void attach_owned(Shader& shader);
void detach(const Shader& shader);
void link();
void compile_from_sources(const std::string& vertex_source, const std::string& fragment_source);
[[nodiscard]] static Program from_sources(const std::string& vertex_source,
const std::string& fragment_source);
[[nodiscard]] static Program from_sources(const std::string& vertex_source,
const std::string& geometry_source,
const std::string& fragment_source);
void use() const;
void validate() const;
void set_parameter(ProgramParameter pname, int value);
void load_binary(ProgramBinaryFormat format, const void* data, std::size_t length);
[[nodiscard]] static Program create_separable(ShaderType type, const std::string& source);
[[nodiscard]] std::string info_log() const;
// Attribute locations
[[nodiscard]] int attrib_location(const std::string& name) const;
void bind_attrib_location(unsigned int index, const std::string& name);
// Uniforms — location lookup
[[nodiscard]] int uniform_location(const std::string& name) const;
// float uniforms
void set_uniform(int location, float value);
void set_uniform(int location, float x, float y);
void set_uniform(int location, float x, float y, float z);
void set_uniform(int location, float x, float y, float z, float w);
void set_uniform_fv(int location, std::span<const float> values, int components = 1);
void set_uniform_iv(int location, std::span<const int> values, int components = 1);
void set_uniform_uiv(int location, std::span<const unsigned int> values, int components = 1);
// int uniforms
void set_uniform(int location, int value);
void set_uniform(int location, int x, int y);
void set_uniform(int location, int x, int y, int z);
void set_uniform(int location, int x, int y, int z, int w);
// unsigned int uniforms
void set_uniform(int location, unsigned int value);
void set_uniform(int location, unsigned int x, unsigned int y);
void set_uniform(int location, unsigned int x, unsigned int y, unsigned int z);
void set_uniform(int location, unsigned int x, unsigned int y, unsigned int z, unsigned int w);
// matrix uniforms
void set_uniform_matrix2(int location, const float* data, bool transpose = false);
void set_uniform_matrix3(int location, const float* data, bool transpose = false);
void set_uniform_matrix4(int location, const float* data, bool transpose = false);
void set_uniform_matrix2x3(int location, const float* data, bool transpose = false);
void set_uniform_matrix3x2(int location, const float* data, bool transpose = false);
void set_uniform_matrix2x4(int location, const float* data, bool transpose = false);
void set_uniform_matrix4x2(int location, const float* data, bool transpose = false);
void set_uniform_matrix3x4(int location, const float* data, bool transpose = false);
void set_uniform_matrix4x3(int location, const float* data, bool transpose = false);
// Separable program uniforms (no bind required, for use with ProgramPipeline)
void set_program_uniform(int location, float value) const;
void set_program_uniform(int location, float x, float y) const;
void set_program_uniform(int location, float x, float y, float z) const;
void set_program_uniform(int location, float x, float y, float z, float w) const;
void set_program_uniform_fv(int location, std::span<const float> values, int components = 1) const;
void set_program_uniform(int location, int value) const;
void set_program_uniform(int location, int x, int y) const;
void set_program_uniform(int location, int x, int y, int z) const;
void set_program_uniform(int location, int x, int y, int z, int w) const;
void set_program_uniform_iv(int location, std::span<const int> values, int components = 1) const;
void set_program_uniform(int location, unsigned int value) const;
void set_program_uniform(int location, unsigned int x, unsigned int y) const;
void set_program_uniform(int location, unsigned int x, unsigned int y, unsigned int z) const;
void set_program_uniform(int location, unsigned int x, unsigned int y, unsigned int z, unsigned int w) const;
void set_program_uniform_uiv(int location, std::span<const unsigned int> values, int components = 1) const;
void set_program_uniform_matrix2(int location, const float* data, bool transpose = false) const;
void set_program_uniform_matrix3(int location, const float* data, bool transpose = false) const;
void set_program_uniform_matrix4(int location, const float* data, bool transpose = false) const;
void set_program_uniform_matrix2x3(int location, const float* data, bool transpose = false) const;
void set_program_uniform_matrix3x2(int location, const float* data, bool transpose = false) const;
void set_program_uniform_matrix2x4(int location, const float* data, bool transpose = false) const;
void set_program_uniform_matrix4x2(int location, const float* data, bool transpose = false) const;
void set_program_uniform_matrix3x4(int location, const float* data, bool transpose = false) const;
void set_program_uniform_matrix4x3(int location, const float* data, bool transpose = false) const;
// Program introspection
[[nodiscard]] int active_attrib_count() const;
[[nodiscard]] int active_uniform_count() const;
[[nodiscard]] std::string uniform_block_name(unsigned int block_index) const;
[[nodiscard]] int frag_data_location(const std::string& name) const;
// Uniform value getters
void get_uniform_fv(int location, float* out) const;
void get_uniform_iv(int location, int* out) const;
void get_uniform_uiv(int location, unsigned int* out) const;
// Uniform blocks
[[nodiscard]] std::optional<unsigned int> uniform_block_index(const std::string& name) const;
void set_uniform_block_binding(unsigned int block_index, unsigned int binding_point);
[[nodiscard]] bool is_valid_gl_object() const;
[[nodiscard]] bool is_linked() const noexcept;
void reset_handle_no_gl() noexcept;
private:
bool linked_ = false;
std::vector<unsigned int> owned_shader_handles_;
};
}