KlassischeKeplerKriege/game/renderer_polygon_3d/particle_batch.hpp

77 lines
2.2 KiB
C++
Raw Normal View History

#pragma once
#include <vector>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include "glclasses.hpp"
//class VertexAttribute {
// std::string nameInShader;
// Guint attributeIndex;
// Type type;
// modifictaion
// void *dataSource;
//};
namespace endofthejedi {
class ParticleBatch {
public:
ParticleBatch(size_t id, size_t numParticles, float particleRadius, float halfAge);
// deallocate opengl stuff on destroy
~ParticleBatch();
size_t numParticles() const { return m_numParticles; }
void setParticle(size_t index, const glm::vec3 &p, const glm::vec3 &v, float maxDistance);
void setCenter(const glm::vec3 &center);
void setMaxVelocity(float maxVelocity);
void setup(Shader *shader);
void bind();
void upload();
void render(Shader *shader);
2016-09-29 06:28:56 +00:00
void tick(float dt);
2016-10-03 08:47:02 +00:00
float ageNormalized() const { return m_age / (m_maxNumHalfAges*m_halfAge); }
float age() const { return m_age; }
2016-09-29 06:28:56 +00:00
bool done() const;
2016-09-30 18:19:10 +00:00
size_t id() const { return m_id; }
2016-10-03 08:47:02 +00:00
const glm::vec3 &explosionCenter() const { return m_center; }
private:
size_t dataSizeForIndex(size_t index);
void *dataSourceForIndex(size_t index);
private:
// id of explosion
2016-09-30 18:19:10 +00:00
size_t m_id;
// uniforms for the shader
size_t m_numParticles;
2016-09-28 22:50:14 +00:00
float m_particleRadius;
2016-09-29 06:28:56 +00:00
float m_age;
2016-10-03 08:47:02 +00:00
const float m_halfAge;
const float m_maxNumHalfAges;
float m_maxVelocity;
glm::vec3 m_center;
2016-09-28 22:50:14 +00:00
// meta data
size_t m_num_vertex_buffers;
std::vector<GLuint> m_data_vbos;
std::vector<GLuint> m_attr_locations;
// vertex attributes
std::vector<float> m_data_geometry;
std::vector<glm::vec3> m_data_position;
std::vector<glm::vec3> m_data_velocity;
std::vector<float> m_data_max_distance;
};
}