CG-Project2
Loading...
Searching...
No Matches
Renderer.hpp
1#pragma once
2
3#include "../Buffer/ElementBuffer.hpp"
4#include "../Buffer/VertexArray.hpp"
5#include "../Buffer/VertexBuffer.hpp"
6
7#include "../Shader/Shader.hpp"
8
9#include "Utils.hpp"
10
11#include <cstddef>
12#include <vector>
13
14namespace ogl {
15 struct Primitive {
16 VertexArray vao{};
17 VertexBuffer vbog{};
18 std::vector<glm::vec3> vertex{};
19 VertexBuffer vboc{};
20 std::vector<glm::vec4> colors{};
21 ElementBuffer ebo{};
22 std::vector<unsigned int> index{};
23 VertexBuffer vbot{};
24 std::vector<glm::vec2> texCoords{};
25 VertexBuffer vbon{};
26 std::vector<glm::vec3> normals{};
27
28 std::vector<unsigned int> ids{};
29 VertexBuffer vbomo{};
30 std::vector<glm::mat4> modelOffset{};
31 VertexBuffer vboco{};
32 std::vector<glm::vec4> colorOffset{};
33 };
34
36 int drawCalls = 0;
37 unsigned int numCubes = 0;
38 unsigned int numPyramids = 0;
39 unsigned int numSpheres = 0;
40 unsigned int numThorus = 0;
41 };
42
43 enum RenderPrimitiveType {
44 PRIMITIVE_CUBE,
45 PRIMITIVE_SPHERE,
46 PRIMITIVE_PYRAMID,
47 PRIMITIVE_THORUS,
48 };
49
50 class Renderer {
51 public:
52 void init();
53
54 void appendSphere(const unsigned int &id, const glm::mat4 &model, const glm::vec4 &color);
55 void appendCube(const unsigned int &id, const glm::mat4 &model, const glm::vec4 &color);
56 void appendPyramid(const unsigned int &id, const glm::mat4 &model, const glm::vec4 &color);
57 void appendThorus(const unsigned int &id, const glm::mat4 &model, const glm::vec4 &color);
58
59 void drawArrays(const unsigned int &vao, const unsigned int &mode, const int &first, const size_t &size);
60
61 void drawElements(const unsigned int &vao, const unsigned int &mode, const size_t &size, const unsigned int &type, const void *indices = 0);
62
63 void drawAllInstanced();
64
65 void prepareBuffers(const std::vector<glm::mat4> &models, const std::vector<glm::vec4> &colors);
66
67 RendererStats getRendererStats() const { return this->m_stats; }
68
69 void resetDrawStats() {
70 this->m_stats.numCubes = 0;
71 this->m_stats.numPyramids = 0;
72 this->m_stats.numSpheres = 0;
73 this->m_stats.numThorus = 0;
74 }
75
76 Renderer(Renderer &other) = delete;
77
78 void operator=(const Renderer &other) = delete;
79
80 inline static Shared<Renderer> instance() {
81 if (s_pointer == nullptr) {
82 Shared<Renderer> copy(new Renderer());
83 copy.swap(s_pointer);
84 }
85 return s_pointer;
86 }
87
88 ~Renderer() = default;
89
90 private:
91 Renderer() = default;
92
93 inline static Shared<Renderer> s_pointer = nullptr;
94
95 RendererStats m_stats{};
96
97 Primitive m_cube{};
98 Primitive m_pyramid{};
99 Primitive m_sphere{};
100 Primitive m_thorus{};
101 bool m_init = false;
102 };
103
104} // namespace ogl
Definition ElementBuffer.hpp:7
Definition VertexArray.hpp:6
Definition VertexBuffer.hpp:7
Definition Renderer.hpp:15
Definition Renderer.hpp:35