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