I took a functional code which just receives a new pointcloud at each time and draws it using a very similar architecture as here. Now if the pointcloud grows incrementally i thought of allocating memory into buffers first and then filling them in gradually with glBufferSubData. Somehow I am not getting anything drawn into the screen. Could anyone help me to find out the reason?
I leave here some pseudocode.
m_primitiveMode = GL_POINTS;
//VAO creation
glGenVertexArrays(1, &m_vertexArrayObject);
glGenBuffers(1, &m_bufferDataObject);
glGenBuffers(1, &m_bufferColorDataObject);
glBindVertexArray(m_vertexArrayObject);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, m_bufferDataObject);
glVertexAttribPointer(
0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
3, // size
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*) 0 // array buffer offset
);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, m_bufferColorDataObject);
glVertexAttribPointer(
1, // attribute. No particular reason for 1, but must match the layout in the shader.
3, // sizesettings.showOriginalPointCloud
GL_FLOAT, // type
GL_FALSE, // normalized?
0, // stride
(void*) 0 // array buffer offset
);
glBindVertexArray(0);
int cummNumPoints = 0;
first_iter = true;
for each iter:
pVertexData, pColorData, numVertices, numColors <--- vectors filled in with coordinates (x,y,z) and colors (r,g,b) // both should be of same size
m_nbVerticesVertexArray = numberVerticesVertexArray;
m_nbVerticesColorArray = numberVerticesColorArray;
glBindVertexArray(m_vertexArrayObject);
if(firstIter){
glBindBuffer(GL_ARRAY_BUFFER, m_bufferDataObject);
// ALLOCATE HUGE MEMORY AT ONCE FOR BOTH BUFFERS!
// (x,y,z), 15000 points assumed per pc, 10 pcs per second, in 10 minutes of recordings
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 15000 * 10 * 60 * 10, NULL, GL_DYNAMIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, m_bufferColorDataObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 3 * 15000 * 10 * 60 * 10, NULL, GL_DYNAMIC_DRAW);
firstIter = false;
}
glBindBuffer(GL_ARRAY_BUFFER, m_bufferDataObject);
glBufferSubData(GL_ARRAY_BUFFER, actualOffset, 3 * sizeof(GLfloat) * numberVerticesVertexArray, pVertexData);
//glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, m_bufferColorDataObject);
glBufferSubData(GL_ARRAY_BUFFER, actualOffset, 3 * sizeof(GLfloat) * numberVerticesColorArray, pColorData);
//glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
actualOffset = actualOffset + 3 * sizeof(GLfloat) * numberVerticesColorArray;
cummNumPoints += numberVerticesVertexArray;
glBindVertexArray(m_vertexArrayObject);
glDrawArrays(m_primitiveMode, 0, cummNumPoints); // 3 indices starting at 0 -> 1 triangle
glBindVertexArray(0);