Brenta Engine 1.2
Loading...
Searching...
No Matches
particles.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#ifndef BRENTA_MAX_PARTICLES
9 #define BRENTA_MAX_PARTICLES 1000
10#endif
11
12#include <brenta/renderer/opengl/texture.hpp>
13#include <brenta/renderer/opengl/ubo.hpp>
14#include <brenta/renderer/opengl/vao.hpp>
15
16#include <glm/vec3.hpp>
17
18#include <filesystem>
19
20namespace brenta
21{
22
23class Camera;
24
25//
26// Particle Emitter class
27// ----------------------
28//
29// This class is used to define a particle emitter, update and render
30// its particles. This class provides a builder pattern to create a
31// ParticleEmitter object. The particles ban be updated and rendered
32// using the updateParticles and renderParticles methods.
33//
35{
36public:
37
38 struct Config;
39 class Builder;
40
41 // Particle variables
42 glm::vec3 starting_position;
43 glm::vec3 starting_velocity;
44 glm::vec3 starting_spread;
45 float starting_time_to_live;
46 int num_particles;
47 float spawn_rate;
48 float scale;
49
50 Vao vao;
51 // We have two fbo which get swapped when rendered
52 // Feedback buffer
53 Fbo fbo[2];
54 int current_fbo_index;
55 Ubo ubo;
56
57 Texture atlas;
58 int atlas_width;
59 int atlas_height;
60 int atlas_index;
61
64
65 ParticleEmitter(const ParticleEmitter&) = delete;
66 ParticleEmitter &operator=(const ParticleEmitter&) = delete;
67
68 ~ParticleEmitter() = default;
69
70 void update(float delta_time);
71 void render(int width, int height);
72
73private:
74
75 tenno::weak_ptr<Camera> cam;
76 tenno::shared_ptr<Shader> shader_update;
77 tenno::shared_ptr<Shader> shader_render;
78
79};
80
82{
83 glm::vec3 starting_position = {};
84 glm::vec3 starting_velocity = {};
85 glm::vec3 starting_spread = {};
86 float starting_time_to_live = 1.0f;
87 int num_particles = BRENTA_MAX_PARTICLES;
88 float spawn_rate = 0.99f;
89 float scale = 1.0f;
90 std::filesystem::path atlas_path = "";
91 int atlas_width = 8;
92 int atlas_height = 8;
93 int atlas_index = 0;
94 tenno::weak_ptr<Camera> cam = {};
95};
96
98{
99private:
100
101 ParticleEmitter::Config conf = {};
102
103public:
104
105 Builder &starting_position(glm::vec3 starting_position);
106 Builder &starting_velocity(glm::vec3 starting_velocity);
107 Builder &starting_spread(glm::vec3 starting_spread);
108 Builder &starting_time_to_live(float starting_time_to_live);
109 Builder &num_particles(int num_particles);
110 Builder &spawn_rate(float spawn_rate);
111 Builder &scale(float scale);
112 Builder &atlas_path(const std::filesystem::path &atlas_path);
113 Builder &atlas_width(int atlas_width);
114 Builder &atlas_height(int atlas_height);
115 Builder &atlas_index(int atlas_index);
116 Builder &with_camera(tenno::weak_ptr<Camera> cam);
117
118 ParticleEmitter build();
119};
120
121} // namespace brenta