• Create Account

### #Actualsaman_artorious

Posted 02 July 2013 - 04:33 AM

Bingo, it works. Now I need to reduce memory. currently, it is 46%, if I clean vertices with

vertices.clear();

it will jump down to 26%. However, When I free colors with

free (colors);

the memory will not reduce and still remains at 26%, why?

Besides, I have a problem modifying the color array.

       GLuint vboId = ppi->getVBOID();

glBindBuffer(GL_ARRAY_BUFFER, vboId);

glBufferData( GL_ARRAY_BUFFER, ( 100 * 6 * sizeof( float ) ), buffer0, GL_DYNAMIC_DRAW );


it jumps outta program when it comes to glBindBuffer. The getVBOID() function simply return VBO_ID[1], dedicated for colors.

how could I resolve this?

### #3saman_artorious

Posted 02 July 2013 - 02:07 AM

Bingo, it works. Now I need to reduce memory. currently, it is 46%, if I clean vertices with

vertices.clear();

it will jump down to 26%. However, When I free colors with

free (colors);

the memory will not reduce and still remains at 26%, why?

### #2saman_artorious

Posted 02 July 2013 - 12:49 AM

Bingo! : )    I reduced the CPU usage from 100% to 1% by using this method. This is my code, updated:

void PlanPositionIndicator::render(QGLShaderProgram* shaderProgram)
{
qDebug() << vertices.size() << " " << sizeof(QVector3D);

if(!initialized)
{

glGenBuffers(2, VBO_ID);

glGenVertexArrays(1, &VAO_ID);
glBindVertexArray(VAO_ID);

glBindBuffer(GL_ARRAY_BUFFER, VBO_ID[0]);
glBufferData(GL_ARRAY_BUFFER, sizeof(QVector3D)*verticesSize, vertices.constData(), GL_STATIC_DRAW);
glVertexAttribPointer(vertexId, 3, GL_FLOAT, GL_FALSE, 0, 0);// param - 1 ->0
glEnableVertexAttribArray(vertexId);

glBindBuffer(GL_ARRAY_BUFFER, VBO_ID[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*verticesSize, colors, GL_DYNAMIC_DRAW);
glVertexAttribPointer(colorId, 1, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(colorId);

glBindBuffer(GL_ARRAY_BUFFER, 0);

initialized = true;
}

glBindVertexArray(VAO_ID);

//    shaderProgram->setAttributeBuffer(vertexLocation, GL_FLOAT , 0, 3, 0);
//    shaderProgram->setAttributeBuffer(colorLocation , GL_FLOAT , 0, 1, 0);

glEnableClientState(GL_VERTEX_ARRAY);

glEnable    (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDrawArrays(GL_TRIANGLES, 0, 6*numVerts);

glFlush();

glBindVertexArray(0);

glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);

//        glDeleteBuffers(2, VBO_ID);
//        glDeleteVertexArrays(1, &VAO_ID);

//        vertices.clear();
//     free(colors);

//    glDrawElements(GL_TRIANGLES, vertices.size(), GL_FLOAT, vertices.constData());
}


However, the memory is at 40% now. I am sure this is because the vertices built in the memory are not cleared after gone to GPU.

The question I have now is that if I remove the vertices completely from memory,the function:

        glBufferData(GL_ARRAY_BUFFER, sizeof(QVector3D)*verticesSize, vertices.constData(), GL_STATIC_DRAW);


gives me a segmentation fault, because vertices.constData() does not exist!

I tried replacing it with &VBO_ID[0], but it gives segmentation fault when it arrives to this line.

how can I resolve this?

### #1saman_artorious

Posted 02 July 2013 - 12:04 AM

right now you are generating a vbo every time you draw them. on top of that from the code you gave it doesnt look like you release them.so sooner or later you should run out of VRAM.

call glBufferData or similiar whenever you want to update the data

If I do this after drawing:

    glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);

glDeleteBuffers(2, VBO_ID);
glDeleteVertexArrays(1, &VAO_ID);



The program would work fine.But, right after that, I cannot delete vertices and colors array! If I do, it jumps out.


vertices.clear();
free(colors);


I create vertices once in the initialization and use it everytime for rendering. If I clean up vertices and colors, then how am I supposed to render the scene?

besides, the whole idea of using vbo's was to reduce cpu usage, but, with what I did here, again, it consumes the same as the case without using vbo's.

PARTNERS