#pragma once

#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <vector>
#include <random>

#include "Shader.h"


class ParticleEmitter
{
public:
	const int NUM_PARTICLES = 100000;
	const float TTL = 5.0f;

private:

	glm::vec3 startPosition;
	std::vector<glm::vec4> velocities; // dx, dy, dz, nothing
	std::vector<glm::vec4> positions; // x, y, z, TTL
	std::vector<glm::vec3> rocket_colors{ glm::vec3(1.0f, 0.7f, 0.2f), glm::vec3(0.2f, 0.1f, 0.8f), glm::vec3(0.3f, 0.8f, 0.1f)};
	int color_index = 0;
	bool is_emitting;

	unsigned int SSBO_velocities[2];
	unsigned int SSBO_positions[2];

	unsigned int VAOs[2]; 

	unsigned int atomic_counter;
	unsigned int particle_count;

	bool current_vao_index = 0;
	const int position_location = 0;
	Shader render_shader;
	Shader compute_shader;

public:
	ParticleEmitter(glm::vec3 initialPosition);
	~ParticleEmitter();
	void simulate(float timeDelta);
	void update_shader(glm::mat4 viewMatrix, glm::mat4 projectionMatrix);
	void draw();
	void reset(bool generate_buffers);
	glm::vec3 current_color;

private:
	void enableBlendMode();
	void disableBlendMode();

};

