90 lines
1.9 KiB
C++
90 lines
1.9 KiB
C++
#pragma once
|
|
|
|
// Must be the first include
|
|
#include <glad/glad.h>
|
|
|
|
// Other includes
|
|
#include "Gedeng/Camera.h"
|
|
#include "Gedeng/Shader.h"
|
|
#include "Gedeng/Texture.h"
|
|
#include <GLFW/glfw3.h>
|
|
#include <glm/glm.hpp>
|
|
|
|
namespace Gedeng {
|
|
|
|
class ParticleSystem {
|
|
public:
|
|
enum { PARTICLE_TYPE_GENERATOR = 0, PARTICLE_TYPE_NORMAL = 1 };
|
|
|
|
ParticleSystem();
|
|
|
|
void render();
|
|
|
|
void update(float delta);
|
|
|
|
void set_position(glm::vec3 position);
|
|
void set_velocity(glm::vec3 min, glm::vec3 max);
|
|
void set_gravity(glm::vec3 gravity);
|
|
void set_color(glm::vec3 color);
|
|
void set_lifetime(float min, float max);
|
|
void set_size(float size);
|
|
void set_interval(float interval);
|
|
void set_number_of_particles(int number);
|
|
void set_textures(Texture *texture1, Texture *texture2, Texture *texture3);
|
|
|
|
void clear();
|
|
void release();
|
|
|
|
int get_particle_count();
|
|
|
|
void set_camera(const Camera &camera);
|
|
|
|
private:
|
|
bool is_valid;
|
|
|
|
GLuint transform_feedback_buffer;
|
|
|
|
GLuint particle_buffer[2];
|
|
GLuint vao[2];
|
|
|
|
GLuint query;
|
|
|
|
Texture *texture1;
|
|
Texture *texture2;
|
|
Texture *texture3;
|
|
|
|
int current_read_buffer;
|
|
int current_particle_count;
|
|
const int max_particle_count = 1000000;
|
|
|
|
glm::mat4 projection_matrix, view_matrix;
|
|
glm::vec3 quad1, quad2;
|
|
|
|
float elapsed_time;
|
|
float next_generation_time;
|
|
|
|
glm::vec3 spawn_position;
|
|
glm::vec3 spawn_velocity_min, spawn_velocity_range;
|
|
glm::vec3 spawn_gravity_vector;
|
|
glm::vec3 spawn_color;
|
|
|
|
float spawn_lifetime_min, spawn_lifetime_range;
|
|
float spawn_size;
|
|
|
|
int target_particle_count;
|
|
|
|
Shader render_shader;
|
|
Shader update_shader;
|
|
|
|
class Particle {
|
|
public:
|
|
glm::vec3 position;
|
|
glm::vec3 velocity;
|
|
glm::vec3 color;
|
|
float lifetime;
|
|
float size;
|
|
float type;
|
|
};
|
|
};
|
|
|
|
} // namespace Gedeng
|