Copperfield Engine 0.1
C++ Game Engine
Loading...
Searching...
No Matches
renderer.hpp
1#pragma once
2#include <array>
3#include <memory>
4#include <vector>
5#include "math/matrix_4.h"
6
7#include "frame_buffer.hpp"
8#include "editor.hpp"
9#include "renderer.hpp"
10
11struct RenderTreeCmp;
12struct LightCmp;
13struct TransformCmp;
14struct RenderCmp;
15
17class Window;
18class Engine;
19
20struct CameraData {
21 coma::Vec3 position_;
22 coma::Mat4 view_;
23 coma::Mat4 projection_;
24};
25struct LightData {
26 std::array<coma::Mat4, 6> projections_;
27 coma::Mat4 projection_;
28 coma::Vec3 position_;
29 coma::Vec3 color_;
30 coma::Vec3 direction_;
31 float intensity_ = 0.0f;
32
33 float max_distance_ = 0.0f;
34 float inner_cutoff_ = 0.0f;
35 float outer_cutoff_ = 0.0f;
36
37 float constant_= 0.0f;
38 float linear_= 0.0f;
39 float quadratic_= 0.0f;
40};
41struct ObjectData {
42 coma::Vec3 color_;
43 float roughness_= 0.0f;
44 float shininess_= 0.0f;
45 coma::Mat4 transform_;
46};
47
49class Renderer {
50public:
51
56 Renderer(Engine& engine, Window& window, float ambient_strength = 0.2f);
57
59 void render();
60
62 struct Settings {
64 float ambient_strength = 0.1f;
65 };
66
67private:
68 void setLightData(float width, float height, const LightCmp& light_cmp,
69 const TransformCmp& transform_cmp);
70 void setCameraData();
71 void renderScene(unsigned shader);
72 void showBoxColliderData(ComponentManager& component_manager) const;
73 void updateTransformTree(std::vector<const RenderTreeCmp*>& component_stack,
74 std::vector<coma::Mat4>& transform_stack,
75 RenderTreeCmp& node_cmp,
76 TransformCmp& transform_cmp) const;
77 void QuadRender() const;
78
79 void uploadCameraData() const;
80 void uploadDirectional() const;
81 void uploadSpot() const;
82 void uploadPoint() const;
83 void showAudioData(ComponentManager& component_manager) const;
84
85 std::unique_ptr<Editor> editor_;
86 Engine* engine_;
87 Window* window_;
88 Settings settings_;
89 int window_width_;
90 int window_height_;
91
92 std::unique_ptr<FrameBuffer> color_frame_buffer_;
93 std::unique_ptr<FrameBuffer> light_frame_buffer_;
94 std::unique_ptr<FrameBuffer> point_frame_buffer_;
95
96 CameraData camera_data_;
97 LightData light_data_;
98 ObjectData object_data_;
99};
Handles anything related to entities and components in the engine.
Definition: component_manager.hpp:29
Intiliazes the ComponentManager and the ResourceManager and ofers functions to retrieve them.
Definition: engine.hpp:12
Class used to render the scene.
Definition: renderer.hpp:49
Renderer(Engine &engine, Window &window, float ambient_strength=0.2f)
Constructor of the renderer.
void render()
Used to render the entire scene with all the entities.
Creates and updates a window.
Definition: window.hpp:20
represents mathematical matrix with 4 cols and 4 rows
Definition: matrix_4.h:11
represents mathematical vector with 3 components
Definition: vector_3.h:12
Component used to simulate different types of lights.
Definition: default_components.hpp:69
Component used to render an object.
Definition: default_components.hpp:237
Struct with basic information that affects all rendered entities.
Definition: renderer.hpp:62
float ambient_strength
Base light intensity that affects all objects from all directions.
Definition: renderer.hpp:64
Component used to give a position, rotation, and scale to an entity.
Definition: default_components.hpp:284