Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ drawcalls之间的glBufferData同步_C++_Ios_Opengl Es - Fatal编程技术网

C++ drawcalls之间的glBufferData同步

C++ drawcalls之间的glBufferData同步,c++,ios,opengl-es,C++,Ios,Opengl Es,我发现自己在使用openGl es时遇到了麻烦,尤其是向VBO提供数据。 以下是导致问题的代码: void Renderer::DrawCurrentData() { glBufferData(GL_ARRAY_BUFFER, (currentVertexIndex) * sizeof(Vertex), vertices, GL_STREAM_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, (currentIndexIndex) * si

我发现自己在使用openGl es时遇到了麻烦,尤其是向VBO提供数据。 以下是导致问题的代码:

void Renderer::DrawCurrentData()
{
    glBufferData(GL_ARRAY_BUFFER, (currentVertexIndex) * sizeof(Vertex), vertices, GL_STREAM_DRAW);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, (currentIndexIndex) * sizeof(GLushort), indices, GL_STREAM_DRAW);

    glDrawElements(GL_TRIANGLE_STRIP, currentIndexIndex, GL_UNSIGNED_SHORT, 0);

    currentVertexIndex = 0;
    currentIndexIndex = 0;
    bufVertex = &vertices[currentVertexIndex];
}
它可以正常工作,直到每帧只有一个draw调用,因此在调用
gldrawerelements
之前,每帧每个缓冲区只调用一次
glBufferData
。但是如果我想每帧调用几个draw,比如

  • 帧开始
  • glBufferData
  • gldrawerelements
  • 。。重复步骤2,3
  • 预离心缓冲
  • 然后我在
    glBufferData
    中崩溃了。这可能是因为当我尝试向缓冲区提供新数据时,缓冲区仍然被前一个draw调用锁定。我知道我应该在这里使用同步,但我不确定如何以正确的方式做到这一点。 在提供新数据之前,我尝试使用
    glBufferData
    NULL
    数据指针孤立缓冲区,但没有帮助。在这种情况下,我在演示帧缓冲时崩溃了。问题是如何在旧数据仍在使用的情况下管理新数据的缓冲区馈送?
    我尝试使用
    GL\u STREAM\u DRAW
    GL\u DYNAMIC\u DRAW
    这两种方法都显示出相同的结果

    在这种情况下,您不必考虑同步。如果在您描述的场景中发生崩溃,这可能是驱动程序错误,也可能是代码中的其他问题(例如,您传入的大小大于数据的实际大小)。我使用的是测试环境,在该环境中,我创建的缓冲区具有相当大的数据存储(大约10000个顶点)但是,在每个绘制调用中为它提供100个顶点的小部分,整个场景需要大约200-300个顶点来渲染。因此
    currentVertexIndex
    始终是
    顶点
    大小,因此缓冲区不太可能过满。