Index

zydeco / a4d3636

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
916 Nov 2023 11:11a4d3636Fractal ViewerJosh Stockin193G

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

text/plain2264 bytesdownload raw
1#ifndef GL_RENDER_OBJECT_HPP_
2#define GL_RENDER_OBJECT_HPP_
3
4
5#include <list>
6#include <map>
7
8#include <GL/gl3w.h>
9#include <glm/glm.hpp>
10
11#include "ZydecoCommon.hpp"
12
13
14class GLProgram;
15class GLTexture;
16
17
18enum class glUniformType
19{
20 FLOAT, DOUBLE, INT, UINT, MAT4
21};
22
23struct glUniform
24{
25public:
26 enum glUniformType type;
27 uint8_t quantity;
28 void **data;
29};
30
31
32class GLRenderObject
33{
34public:
35 void RenderEnable();
36 void RenderDisable();
37
38 template<int N, typename T>
39 constexpr void RenderSetUniform(std::string name, std::array<void*, N> data)
40 {
41 glUniform uniform;
42 if (std::is_same<T, float>::value) { uniform.type = glUniformType::FLOAT; }
43 else if (std::is_same<T, double>::value) { uniform.type = glUniformType::DOUBLE; }
44 else if (std::is_same<T, int>::value) { uniform.type = glUniformType::INT; }
45 else if (std::is_same<T, long int>::value) { uniform.type = glUniformType::INT; }
46 else if (std::is_same<T, unsigned int>::value) { uniform.type = glUniformType::UINT; }
47 else if (std::is_same<T, unsigned long int>::value) { uniform.type = glUniformType::UINT; }
48 else if (std::is_same<T, glm::mat4>::value) { uniform.type = glUniformType::MAT4; }
49 else { ZydecoFault("RenderSetUniform('{}'): Unknown data type {}", name, typeid(T).name()); }
50
51 uniform.quantity = N;
52 uniform.data = new void *[N];
53 std::copy(std::begin(data), std::end(data), uniform.data);
54
55
56 m_uniforms.insert(std::pair<std::string, glUniform>(name, uniform));
57 }
58
59 void AddTexture(uint64_t texture_unit, GLTexture *texture);
60
61protected:
62 friend class Renderer;
63
64 GLRenderObject(std::string gl_program_name, uint64_t render_order);
65 ~GLRenderObject();
66
67 virtual void Render() = 0;
68 static std::map<uint64_t, std::list<GLRenderObject*>>& GetRenderObjects();
69 void GLTargetSetup();
70 bool m_renderEnabled;
71
72private:
73 static std::map<uint64_t, std::list<GLRenderObject*>> s_renderObjects;
74
75 GLProgram *m_glProgram;
76 uint64_t m_renderOrder;
77 std::map<std::string, glUniform> m_uniforms;
78 std::map<uint64_t, GLTexture*> m_textures;
79};
80
81#endif /* GL_RENDER_OBJECT_HPP_ */
82