How do I properly update a vertex array in OpenGL Es 2.0?

后端 未结 2 1508
心在旅途
心在旅途 2021-02-08 02:51

When I update my vertex array on iOS in OpenGL 2.0, the original vertex data is staying on the screen -- ie the 1st flush is persistent (the initial set of points I sent down to

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-08 03:03

    Misfire #1

    I found an answer here which pointed me to using glSubBufferData for parking data in the array, and to use glBufferData only for the initial allocation. Ultimately this did not work (if the vb was too big, only the first 3 elements would be updated),

    So,

    glBufferData( glBufferData(
      GL_ARRAY_BUFFER, //Specifies the target buffer object.
      rawDynamicData.size() * sizeof( VertexType ),
      0, // NO INITIAL DATA
      GL_DYNAMIC_DRAW  // I plan to update the data every frame
    ) ;  CHECK_GL ; 
    

    Then for the first and subsequent updates:

    // Update the whole buffer
    glBufferSubData(GL_ARRAY_BUFFER, 0,
      rawDynamicData.size()*sizeof(VertexType), &rawDynamicData[0]) ;
    

    That seemed to work.

    Seemed. But it didn't.

    The only thing I could do to make it work was quit using vertex buffers and use client memory vertex arrays.

    This looks as follows:

    // do all your vertex attrib/glVertexAttrib enable commands:
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexPC), &debugPoints->data[0].pos.x) ;
    CHECK_GL ;
    glEnableVertexAttribArray(0);  CHECK_GL ;
    
    // ..do glVertexAttrib* for all attributes you have..
    
    // then just flush your draw command
    glDrawArrays(GL_POINTS, 0, debugPoints->data.size());  
    

    So in short, I have found that using vertex buffers for dynamic data is either challenging or not supported.

提交回复
热议问题