Index

zydeco / 5f524c5

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

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
703 Sep 2023 16:015f524c5OpenGL render abstractionsJosh Stockin1750G

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

text/plain1923 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;
15
16
17enum class glUniformType
18{
19 FLOAT, INT, UINT
20};
21
22struct glUniform
23{
24public:
25 enum glUniformType type;
26 uint8_t quantity;
27 void **data;
28};
29
30
31class GLRenderObject
32{
33private:
34 static std::map<uint64_t, std::list<GLRenderObject*>> s_renderObjects;
35
36protected:
37 friend class Renderer;
38
39 GLRenderObject(std::string gl_program_name, uint64_t render_priority);
40 ~GLRenderObject();
41
42 void RenderEnable();
43 void RenderDisable();
44
45public:
46 template<int N, typename T>
47 constexpr void RenderSetUniform(std::string name, std::array<void*, N> data)
48 {
49 glUniform uniform;
50 if (std::is_same<T, float>::value) { uniform.type = glUniformType::FLOAT; }
51 else if (std::is_same<T, int>::value) { uniform.type = glUniformType::INT; }
52 else if (std::is_same<T, long int>::value) { uniform.type = glUniformType::INT; }
53 else if (std::is_same<T, unsigned int>::value) { uniform.type = glUniformType::UINT; }
54 else if (std::is_same<T, long unsigned int>::value) { uniform.type = glUniformType::UINT; }
55 else { ZydecoFault("RenderSetUniform({}): Unknown data type {}", name, typeid(T).name()); }
56
57 uniform.quantity = N;
58 uniform.data = new void *[N];
59 std::copy(std::begin(data), std::end(data), uniform.data);
60
61
62 m_uniforms.insert(std::pair<std::string, glUniform>(name, uniform));
63 }
64
65 GLProgram *m_glProgram;
66 uint64_t m_renderPriority;
67 bool m_renderEnabled;
68 std::map<std::string, glUniform> m_uniforms;
69
70 void GLTargetSetup();
71 virtual void Render() = 0;
72 static std::map<uint64_t, std::list<GLRenderObject*>>& GetRenderObjects();
73};
74
75#endif /* GL_RENDER_OBJECT_HPP_ */
76