0

I'm using the Boost Graph Library to organize points linked by edges in a graph, and now I'm working on their display.

I'm a newbie in OpenGL ES 2/GLKit and Vertex Array Objects / Vertex Buffer Objects. I followed this tutorial which is really good, but at the end of what I guess I should do is :

  • Create vertices only once for a "model "instance of a Shape class (the "sprite" representing my boost point position) ;
  • Use this model to feed VBOs ;
  • Bind VBOs to a unique VAO ;
  • Draw everything in a single draw call, changing the matrix for each "sprite".

I've read that accessing VBOs is really bad for performances, and that I should use swapping VBOs.

My questions are :

  • is the matrix translation/scaling/rotation possible in a single call ?
  • then, if it is: is my logic good ?
  • finally: it would be great to have some code examples :-)
Benoît Lahoz
  • 1,270
  • 1
  • 18
  • 43

1 Answers1

0

If you just want to draw charts, there are much easier libraries to use besides OpenGL ES. But assuming you have your reasons:

Just take a stab at what you've described and test it. If it's good enough then congratulations: you're done.

You don't mention how many graphs, how many points per graph, how often the points are modified, and the frame rate you desire.

If you're updating a few hundred vertices, and they don't change frequently, you might not even need VBOs. Recent hardware can render a lot of sprites even without them. Depends on how many verts and how often they change.

To start, try this:

// Bind the shader
glUseProgram(defaultShaderProgram);

// Set the projection (camera) matrix.
glUniformMatrix4fv(uProjectionMatrix, 1, GL_FALSE, (GLfloat*)projectionMatrix[0]);

for ( /* each chart */ ) 
{
    // Set the sprite (scale/rotate/translate) matrix.
    glUniformMatrix4fv(uModelViewMatrix,  1, GL_FALSE, (GLfloat*)spriteViewMatrix[0]);

    // Set the vertices.
    glVertexAttribPointer(ATTRIBUTE_VERTEX_POSITION, 3, GL_FLOAT,         GL_FALSE, sizeof(Vertex), &pVertices->x));
    glVertexAttribPointer(ATTRIBUTE_VERTEX_DIFFUSE,  4, GL_UNSIGNED_BYTE, GL_TRUE,  sizeof(Vertex), &pVertices->color));

    // Render.  Assumes your shader does not use a texture, 
    // since we did not set one.
    glDrawArrays(GL_TRIANGLES, 0, numVertices);
}
  • If this is too slow, first confirm that you only draw vertices when they are modified. Then confirm that the vertex and fragment shaders are optimized. Fragment shading is usually a bottleneck on OpenGL ES 2.0. Assuming the shaders are trivial, and this is still too slow, then you could try VBOs. Again: implement and test. If it's STILL too slow, then worry about VBO swapping. – Sean Kelleher Jan 09 '14 at 20:47