开发者

glDrawArrays: when has it finished?

Pseudocode:

void draw()
{
    Vertex* vertices = scene.GetVertexArray();
    glEnableClientState(...);
    glVertexPointer(..., vertices);
    glDrawArrays(...);
    glDisableClientState(...);
    delete vertices;
}

I'm not using VBO since I want to support older OpenGL implementations.

After calling glDrawArrays, I want to:

  • deallocate my vertex array ("delete vertices;")
  • perhaps modify some of the vertices
  • 开发者_Go百科

However, GL is free to perform the glDrawArrays asynchronously, and it's not safe to deallocate or modify my array until it has finished.

I could do a glFinish to ensure that, but it'd slow down the app.

So at what moment am I free to deallocate/modify my vertex array?


OpenGL guarantees you, that once any function that actually access some memory returns, you can change or deallocate it's contents. Those functions are:

  • glDrawArrays (after it returns, the memory gl{Normal,Color,TexCoord,Attrib,Vertex}Pointer was set to can be disposed)
  • glDrawElements (after it returns, the memory gl{Normal,Color,TexCoord,Attrib,Vertex}Pointer was set to and the element array can be disposed)
  • glTexImage (memory data points to)
  • glTexSubImage (memory data points to)
  • glBufferData (memory data points to)
  • glBufferSubData (memory data points to)

It is important to know that gl{Normal,Color,TexCoord,Attrib,Vertex}Pointer just set a pointer and don't create a copy. However a copy of sort of the data is made by glDrawElements and glDrawArrays calls (depending on the driver a physical copy is not made immediately but the memory management adjusted for a copy-on-write scheme — in case the buffer doesn't get modified or deallocated by the user programm this saves crucial bandwidth and CPU cycles).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜