1

I use glVertexAttribPointer to load my vertex data each frame(~242kb) it takes about 8ms.
Will I gain any performance increase by employing VBO?
I think the answer is NO since I still have to load whole data.
The only way it can get performance gain is if glBufferData loads data faster than glVertexAttribPointer
Is this is the case?

undefined
  • 623
  • 7
  • 27

1 Answers1

2

If you have static vertex data then VBO has very clear performance advantage because data is kept in GPU accessible memory.

When you use glVertexAttribPointer without VBOs driver has to copy your vertex data to GPU accessible memory every frame. There is two reason why client arrays require copy

  1. GPU doesn't have access to all your memory. It can only see pages that GPU driver has mapped to it.
  2. OpenGL promises that you are free to change client array memory after glDraw* returns but GPU rendering happens asynchronously after return.

VBO data is allocated by driver and mapped to GPU. That avoids copies if you keep same vertex data. Updates also can be optimized if you only update part of vertex array with glBufferSubData. (eg. only update texture coordinates without vertex position update)

Pauli Nieminen
  • 1,100
  • 8
  • 7
  • The problem is my vertex data could change significantly(mostly by changes in order of drawing) >That avoids copies if you keep same vertex data.
    Does this mean that glBufferData doesn't actually copy data to gpu memory and I can modify my vertex data on client side and then call glBufferData which will be extra fast?
    – undefined Oct 27 '16 at 15:16
  • 1
    @undefined No. You will have to do copy at some point when ever you move data from software memory to GPU memory. But glBufferSubData and glMapBuffer can let your update less. But changes in drawing order shouldn't change vertex data. You can use indeces with glDrawElements to tell about vertex order. Modern GPU rendering basic idea is use static data as much as possible and let shaders transform that to dynamic cotent with minimal dynamic input (minimal dynamic input can be uniforms only or a few vertex attributes). Every time data changes you risk copies, allocations and pipeline stalls. – Pauli Nieminen Oct 27 '16 at 15:23
  • What is glMapBuffer?There is no such method inside GLES20 class.I think this is what I need to avoid unecessary copying of vertex data – undefined Oct 27 '16 at 15:33
  • http://stackoverflow.com/questions/30641095/glmapbuffer-is-missing-from-opengl-es-2.glMapBuffer is extension in es2. But remember thatr glMapBuffer risks pipeline stalls because mapping has to wait GPU complete reading (or writing to) from the buffer before driver can give pointer for you. If you really need dynamic vertex data then you might be better of using two VBOs for same data in round robin fashion. – Pauli Nieminen Oct 27 '16 at 15:35
  • Thanks but this thread is for ios.Is there way to use it on android? – undefined Oct 27 '16 at 15:38
  • OpenGL API is same in different OS but difference is what extensions are supported. To access extensions you to check if it is supported and query pointer to extension function. In C code that is done with glGetString(GL_EXTENSIONS) and {egl,glx,wgl}GetProcAddress. – Pauli Nieminen Oct 27 '16 at 15:43
  • Don't think such trick is allowed in Java.Looks like I'd better rearrange my code to draw by manipulating with vertex indices+glBufferData.Thanks! – undefined Oct 27 '16 at 15:56
  • True. http://stackoverflow.com/questions/22565195/opengles-extension-in-android has some comment about limited access to extensions. There is GLES11Ext and GLES31Ext but no GLES20Ext class. It seems like GLES20 extensions require jni components. But I hope you can use indices to reduce number of VBO updates required. Then for updates it is better to allocate a new VBO than try to reuse same VBO. glBufferData could implement multi-buffered VBO but GLES drivers don't usually implement multi-buffering. – Pauli Nieminen Oct 27 '16 at 16:09
  • damn looks like I can't use indices juggling.I'm developing classic jigsaw puzzle game where each piece is 2 polygons.Therefore when user had completed puzzle and drag it over the screen all vertices will be changing.Looks like I still have to reupload all vertices each frame.I wonder in 3d games when complex model is animating one can't express these changes by modification part of the model. – undefined Oct 27 '16 at 18:00
  • https://www.opengl.org/wiki/Skeletal_Animation has some idea how complex animation is done in games. Basic idea is to keep vertex data static and use bone structure information to transform vertices differently depending on which part of model the vertex is. – Pauli Nieminen Oct 27 '16 at 18:48
  • this makes sense.Thanks again – undefined Oct 27 '16 at 19:04