Factorise attribute location of simulation program.

This commit is contained in:
Vincent Lejeune 2014-08-13 22:26:52 +02:00
parent e6eac5b57f
commit 8117260bf6
4 changed files with 36 additions and 58 deletions

View File

@ -9,15 +9,15 @@ uniform float track_x_len;
uniform float track_z_len;
uniform samplerBuffer heightmap;
in vec3 particle_position_initial;
in float lifetime_initial;
in vec3 particle_velocity_initial;
in float size_initial;
layout (location = 4) in vec3 particle_position_initial;
layout (location = 5) in float lifetime_initial;
layout (location = 6) in vec3 particle_velocity_initial;
layout (location = 7) in float size_initial;
in vec3 particle_position;
in float lifetime;
in vec3 particle_velocity;
in float size;
layout (location = 0) in vec3 particle_position;
layout (location = 1) in float lifetime;
layout (location = 2) in vec3 particle_velocity;
layout (location = 3) in float size;
out vec3 new_particle_position;
out float new_lifetime;

View File

@ -3,15 +3,15 @@ uniform mat4 sourcematrix;
uniform int level;
uniform float size_increase_factor;
in vec3 particle_position_initial;
in float lifetime_initial;
in vec3 particle_velocity_initial;
in float size_initial;
layout (location = 4) in vec3 particle_position_initial;
layout (location = 5) in float lifetime_initial;
layout (location = 6) in vec3 particle_velocity_initial;
layout (location = 7) in float size_initial;
in vec3 particle_position;
in float lifetime;
in vec3 particle_velocity;
in float size;
layout (location = 0) in vec3 particle_position;
layout (location = 1) in float lifetime;
layout (location = 2) in vec3 particle_velocity;
layout (location = 3) in float size;
out vec3 new_particle_position;
out float new_lifetime;

View File

@ -286,44 +286,29 @@ void ParticleSystemProxy::AppendQuaternionRenderingVAO(GLuint QuaternionBuffer)
glVertexAttribDivisor(6, 1);
}
template<typename T>
void setSimulationBind(GLuint position_vbo, GLuint initialValues_vbo)
void ParticleSystemProxy::CommonSimulationVAO(GLuint position_vbo, GLuint initialValues_vbo)
{
glBindBuffer(GL_ARRAY_BUFFER, position_vbo);
glEnableVertexAttribArray(T::attrib_position);
glVertexAttribPointer(T::attrib_position, 3, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)0);
glEnableVertexAttribArray(T::attrib_lifetime);
glVertexAttribPointer(T::attrib_lifetime, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)(3 * sizeof(float)));
glEnableVertexAttribArray(T::attrib_velocity);
glVertexAttribPointer(T::attrib_velocity, 4, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)(4 * sizeof(float)));
if (T::attrib_size < 30)
{
glEnableVertexAttribArray(T::attrib_size);
glVertexAttribPointer(T::attrib_size, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)(7 * sizeof(float)));
}
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)(3 * sizeof(float)));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)(4 * sizeof(float)));
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)(7 * sizeof(float)));
glBindBuffer(GL_ARRAY_BUFFER, initialValues_vbo);
glEnableVertexAttribArray(T::attrib_initial_position);
glVertexAttribPointer(T::attrib_initial_position, 3, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)0);
glEnableVertexAttribArray(T::attrib_initial_lifetime);
glVertexAttribPointer(T::attrib_initial_lifetime, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)(3 * sizeof(float)));
glEnableVertexAttribArray(T::attrib_initial_velocity);
glVertexAttribPointer(T::attrib_initial_velocity, 4, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)(4 * sizeof(float)));
glEnableVertexAttribArray(T::attrib_initial_size);
glVertexAttribPointer(T::attrib_initial_size, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)(7 * sizeof(float)));
glEnableVertexAttribArray(4);
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)0);
glEnableVertexAttribArray(5);
glVertexAttribPointer(5, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)(3 * sizeof(float)));
glEnableVertexAttribArray(6);
glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)(4 * sizeof(float)));
glEnableVertexAttribArray(7);
glVertexAttribPointer(7, 1, GL_FLOAT, GL_FALSE, sizeof(ParticleSystemProxy::ParticleData), (GLvoid*)(7 * sizeof(float)));
}
void ParticleSystemProxy::SimpleSimulationBind(GLuint PositionBuffer, GLuint InitialValuesBuffer)
{
setSimulationBind<ParticleShader::SimpleSimulationShader>(PositionBuffer, InitialValuesBuffer);
}
void ParticleSystemProxy::HeightmapSimulationBind(GLuint PositionBuffer, GLuint InitialValuesBuffer)
{
setSimulationBind<ParticleShader::HeightmapSimulationShader>(PositionBuffer, InitialValuesBuffer);
}
void ParticleSystemProxy::simulateHeightmap()
{
int timediff = int(GUIEngine::getLatestDt() * 1000.f);
@ -453,15 +438,9 @@ void ParticleSystemProxy::generateVAOs()
glGenVertexArrays(1, &non_current_simulation_vao);
glBindVertexArray(current_simulation_vao);
if (has_height_map)
HeightmapSimulationBind(tfb_buffers[0], initial_values_buffer);
else
SimpleSimulationBind(tfb_buffers[0], initial_values_buffer);
CommonSimulationVAO(tfb_buffers[0], initial_values_buffer);
glBindVertexArray(non_current_simulation_vao);
if (has_height_map)
HeightmapSimulationBind(tfb_buffers[1], initial_values_buffer);
else
SimpleSimulationBind(tfb_buffers[1], initial_values_buffer);
CommonSimulationVAO(tfb_buffers[1], initial_values_buffer);
float *quaternions = new float[4 * count];
glBindVertexArray(0);

View File

@ -25,8 +25,7 @@ protected:
unsigned count;
static void CommonRenderingVAO(GLuint PositionBuffer);
static void AppendQuaternionRenderingVAO(GLuint QuaternionBuffer);
static void SimpleSimulationBind(GLuint PositionBuffer, GLuint InitialValuesBuffer);
static void HeightmapSimulationBind(GLuint PositionBuffer, GLuint InitialValuesBuffer);
static void CommonSimulationVAO(GLuint position_vbo, GLuint initialValues_vbo);
void generateVAOs();
void cleanGL();