Thanks for the replies. I have noted the references as well.
OK here are the actual codes and shaders.
Vertex shader:<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… (warning) <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
#version 330 core
layout( location = 0 ) in ivec4 vVertex;
void main()
{
gl_Position = vVertex;
}
[/QUOTE]</div>
Geometry shader:<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… (warning) <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
#version 330 core
#extension EXT_gpu_shader4 : require
uniform samplerBuffer positionTex;
uniform samplerBuffer velocityTex;
layout (points) in;
layout (triangle_strip) out;
layout (max_vertices = 12) out;
uniform mat4 MVP;
out vec4 out_position; //Transform feedback attributes
out vec3 out_velocity;
void main(void)
{
ivec4 index = ivec4(gl_in[0].gl_Position);
//extract tetrahedra positions
vec4 p0 = texelFetchBuffer(positionTex, index.x);
vec4 p1 = texelFetchBuffer(positionTex, index.y);
vec4 p2 = texelFetchBuffer(positionTex, index.z);
vec4 p3 = texelFetchBuffer(positionTex, index.w);
//extract tetrahedra velocities
vec3 v0 = texelFetchBuffer(velocityTex, index.x).xyz;
vec3 v1 = texelFetchBuffer(velocityTex, index.y).xyz;
vec3 v2 = texelFetchBuffer(velocityTex, index.z).xyz;
vec3 v3 = texelFetchBuffer(velocityTex, index.w).xyz;
//do some processing using p0,p1,p2,p3 & v0,v1,v2,v3
gl_Position = MVP*p0;
out_position = p0;
out_velocity = v0;
EmitVertex();
gl_Position = MVP*p1;
out_position = p1;
out_velocity = v1;
EmitVertex();
gl_Position = MVP*p3;
out_position = p3;
out_velocity = v3;
EmitVertex();
gl_Position = MVP*p2;
out_position = p2;
out_velocity = v2;
EmitVertex();
gl_Position = MVP*p0;
out_position = p0;
out_velocity = v0;
EmitVertex();
gl_Position = MVP*p1;
out_position = p1;
out_velocity = v1;
EmitVertex();
EndPrimitive();
}
[/QUOTE]</div>
Shader loading is through a custom class and the attributes/uniforms are setup like this
<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… (warning) <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
shader.LoadFromFile(GL_VERTEX_SHADER, “shaders/shader.vert”);
shader.LoadFromFile(GL_FRAGMENT_SHADER, “shaders/shader.frag”);
shader.LoadFromFile(GL_GEOMETRY_SHADER, “shaders/shader.geom”);
shader.CreateAndLinkProgram();
shader.Use();
shader.AddAttribute(“vVertex”);
shader.AddUniform(“MVP”);
shader.AddUniform(“positionTex”);
shader.AddUniform(“velocityTex”);
glUniform1i(shader(“positionTex”), 0);
glUniform1i(shader(“velocityTex”), 1);
shader.UnUse();
[/QUOTE]</div>
Setup code for vbo/vao
<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… (warning) <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
glGenVertexArrays(2, updateVAOID);
glGenBuffers (2, vboPosID);
glGenBuffers (2, vboVelID);
glGenBuffers (1, &vboIndicesID);
for(int i=0;i<2;i++) {
glBindVertexArray(updateVAOID[i]);
glBindBuffer (GL_ARRAY_BUFFER, vboPosID[i]);
glBufferData (GL_ARRAY_BUFFER, sizeof(glm::vec4)*positions.size(), &positions[0], GL_DYNAMIC_COPY);
glBindBuffer( GL_ARRAY_BUFFER, vboVelID[i]);
glBufferData( GL_ARRAY_BUFFER, velocities.size()*sizeof(glm::vec3), &(velocities[0].x), GL_DYNAMIC_COPY);
glBindBuffer (GL_ARRAY_BUFFER, vboIndicesID);
glBufferData (GL_ARRAY_BUFFER, sizeof(glm::ivec4)*indices.size(), &indices[0], GL_STATIC_DRAW);
GL_CHECK_ERRORS
glEnableVertexAttribArray(0);
glVertexAttribIPointer(0, 4, GL_INT, 0,0);
}
//setup texture buffer object
glGenTextures(2,positionTexID);
glGenTextures(2,velocityTexID);
for(int i=0;i<2;i++) {
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_BUFFER, vboPosID[i]);
glTexBuffer( GL_TEXTURE_BUFFER, GL_RGBA32F, vboPosID[i]);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_BUFFER, vboVelID[i]);
glTexBuffer( GL_TEXTURE_BUFFER, GL_RGBA32F, vboVelID[i]);
}
//setup transform feedback
const char* varying_names[]={“out_position”, “out_velocity”};
glTransformFeedbackVaryings(shader.GetProgram(), 2, varying_names, GL_SEPARATE_ATTRIBS);
glLinkProgram(shader.GetProgram());
[/QUOTE]</div>
Transform feedback code
<div class=“ubbcode-block”><div class=“ubbcode-header”>Click to reveal… (warning) <input type=“button” class=“form-button” value=“Show me!” onclick=“toggle_spoiler(this, ‘Yikes, my eyes!’, ‘Show me!’)” />]<div style=“display: none;”>
shader.Use();
//set uniforms
//bind TBOs
glActiveTexture( GL_TEXTURE0);
glBindTexture( GL_TEXTURE_BUFFER, positionTexID[writeID]);
glActiveTexture( GL_TEXTURE1);
glBindTexture( GL_TEXTURE_BUFFER, velocityTexID[writeID]);
glBindVertexArray( updateVAOID[writeID]);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, vboPosID[readID]);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 1, vboVelID[readID]);
glEnable(GL_RASTERIZER_DISCARD);
glBeginQuery(GL_TIME_ELAPSED,t_query);
glBeginTransformFeedback(GL_POINTS);
glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, query);
glDrawArrays(GL_POINTS, 0, indices.size());
glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
glEndTransformFeedback();
glFlush();
glEndQuery(GL_TIME_ELAPSED);
glDisable(GL_RASTERIZER_DISCARD);
glGetQueryObjectui64v(t_query, GL_QUERY_RESULT, &elapsed_time);
delta_time = elapsed_time / 1000000.0f;
glGetQueryObjectuiv(query, GL_QUERY_RESULT, &primitives_written);
//swap the buffers
int tmp = readID;
readID=writeID;
writeID = tmp;
glutSwapBuffers();
[/QUOTE]</div>