2016-09-28 19:26:11 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <glm/vec2.hpp>
|
2016-09-30 19:24:06 +00:00
|
|
|
#include <glm/vec3.hpp>
|
2016-09-28 19:26:11 +00:00
|
|
|
|
|
|
|
#include "glclasses.hpp"
|
|
|
|
|
|
|
|
namespace endofthejedi {
|
|
|
|
class ParticleBatch {
|
|
|
|
public:
|
2016-09-30 19:48:15 +00:00
|
|
|
ParticleBatch(size_t id, size_t numParticles, float particleRadius, float halfAge);
|
2016-09-28 19:26:11 +00:00
|
|
|
|
|
|
|
// deallocate opengl stuff on destroy
|
|
|
|
~ParticleBatch();
|
|
|
|
|
|
|
|
size_t numParticles() const { return m_numParticles; }
|
|
|
|
|
2016-09-30 19:24:06 +00:00
|
|
|
void setParticle(size_t index, const glm::vec3 &p, const glm::vec3 &v);
|
|
|
|
|
|
|
|
void setCenter(const glm::vec3 ¢er);
|
|
|
|
void setMaxVelocity(float maxVelocity);
|
2016-09-28 19:26:11 +00:00
|
|
|
|
|
|
|
void bind();
|
|
|
|
void upload();
|
|
|
|
void render();
|
|
|
|
|
2016-09-29 06:28:56 +00:00
|
|
|
void tick(float dt);
|
|
|
|
bool done() const;
|
|
|
|
|
2016-09-28 19:26:11 +00:00
|
|
|
Shader *shader() { return &m_shader; }
|
|
|
|
|
2016-09-30 18:19:10 +00:00
|
|
|
size_t id() const { return m_id; }
|
|
|
|
|
2016-09-28 19:26:11 +00:00
|
|
|
private:
|
|
|
|
size_t dataSizeForIndex(int i);
|
|
|
|
void *dataSourceForIndex(int i);
|
|
|
|
|
|
|
|
private:
|
2016-09-30 18:19:10 +00:00
|
|
|
size_t m_id;
|
2016-09-28 19:26:11 +00:00
|
|
|
size_t m_numParticles;
|
2016-09-28 22:50:14 +00:00
|
|
|
float m_particleRadius;
|
2016-09-30 19:48:15 +00:00
|
|
|
const float m_halfAge;
|
2016-09-29 06:28:56 +00:00
|
|
|
float m_age;
|
2016-09-30 19:24:06 +00:00
|
|
|
float m_maxVelocity;
|
|
|
|
glm::vec3 m_center;
|
2016-09-28 22:50:14 +00:00
|
|
|
|
|
|
|
GLuint m_data_vbos[5];
|
2016-09-28 19:26:11 +00:00
|
|
|
|
2016-09-28 22:50:14 +00:00
|
|
|
std::vector<float> m_data_quad;
|
2016-09-30 19:24:06 +00:00
|
|
|
std::vector<glm::vec3> m_data_position;
|
|
|
|
std::vector<glm::vec3> m_data_velocity;
|
2016-09-28 19:26:11 +00:00
|
|
|
std::vector<float> m_data_kind;
|
|
|
|
std::vector<float> m_data_max_age;
|
|
|
|
|
2016-09-30 18:19:10 +00:00
|
|
|
GLuint m_attr_locations[5];
|
|
|
|
|
2016-09-28 19:26:11 +00:00
|
|
|
Shader m_shader;
|
|
|
|
};
|
|
|
|
}
|