Index

zydeco / 5a717fe

Experiment in graphics programming, C++, OpenGL, simulation techniques.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1008 Dec 2023 15:215a717feFractal renderer update for articleJosh Stockin1580G

Blob @ zydeco / include / render / gl / GLUniformUploader.hpp

text/plain1734 bytesdownload raw
1#ifndef GL_UNIFORM_UPLOADER_HPP_
2#define GL_UNIFORM_UPLOADER_HPP_
3
4
5#include <string>
6#include <array>
7#include <map>
8
9
10enum class glUniformType
11{
12 FLOAT, DOUBLE, INT, UINT, MAT4
13};
14
15struct glUniform
16{
17public:
18 enum glUniformType type;
19 uint8_t quantity;
20 void **data;
21};
22
23
24class GLUniformUploader
25{
26public:
27 GLUniformUploader() = default;
28 ~GLUniformUploader() = default;
29
30 // todo: interface for removing/updating uniform pointer?
31 template<int N, typename T>
32 void AssignUniformPointer(std::string name, std::array<void*, N> data)
33 {
34 glUniform uniform;
35 if (std::is_same<T, float>::value) { uniform.type = glUniformType::FLOAT; }
36 else if (std::is_same<T, double>::value) { uniform.type = glUniformType::DOUBLE; }
37 else if (std::is_same<T, int>::value) { uniform.type = glUniformType::INT; }
38 else if (std::is_same<T, long int>::value) { uniform.type = glUniformType::INT; }
39 else if (std::is_same<T, unsigned int>::value) { uniform.type = glUniformType::UINT; }
40 else if (std::is_same<T, unsigned long int>::value) { uniform.type = glUniformType::UINT; }
41 else if (std::is_same<T, glm::mat4>::value) { uniform.type = glUniformType::MAT4; }
42 else { ZydecoFault("RenderSetUniform('{}'): Unknown data type {}", name, typeid(T).name()); }
43
44 uniform.quantity = N;
45 uniform.data = new void *[N];
46 std::copy(std::begin(data), std::end(data), uniform.data);
47
48 m_uniforms.insert(std::pair<std::string, glUniform>(name, uniform));
49 }
50
51 void UploadUniforms(uint64_t program_id);
52
53public:
54 std::map<std::string, glUniform> m_uniforms;
55};
56
57
58#endif
59