WebGL 2.0:即使 VBO 被删除,绘制调用也会成功

WebGL 2.0: Draw call succeeds even VBO is deleted

所以我正在使用 VAO 来存储来自 VBO 的指针。我想测试在绑定 VAO 和调用绘图之前删除数据缓冲区(vbo、ibo 等)时会发生什么。由于 VAO 将指向数据的指针存储在相应的数据缓冲区中,因此我预计渲染器会崩溃。然而,一切都在继续工作。这怎么可能?我正在使用 WebGL 2.0 上下文。文档指出 VAO 是根据 OpenGL 文档实现的。这与 JavaScript 如何处理对象有关吗?也许我的 vbo 在调用 deleteBuffer 之前(不知不觉地)缓存在某个地方。这可能吗?这里发生了什么?

如果缓冲区对象试图被gl.DeleteBuffers删除,那么缓冲区对象不会被删除,如果它附加到顶点数组对象,这是未绑定。在这种情况下,对象的名称变得无效并且它被标记为未使用:

gl.bindVertexArray( vao );
gl.bindBuffer( gl.ARRAY_BUFFER, vbo );
gl.vertexAttribPointer( ... );
.....
gl.bindVertexArray( 0 );
gl.deleteBuffers( 1, vbo );


但是如果绑定了顶点数组对象,那么buffer对象就会被detach并删除:

gl.bindVertexArray( vao );
gl.bindBuffer( gl.ARRAY_BUFFER, vbo );
gl.vertexAttribPointer( ... );
.....
gl.deleteBuffers( 1, vbo );
gl.bindVertexArray( 0 ); 


OpenGL ES Specification 3.2 - 5.1.3 Deleted Object and Object Name Lifetimes, page 45:

When a buffer, texture, transform feedback or renderbuffer object is successfully deleted, it is unbound from any bind points it is bound to in the current context, and detached from any attachments of container objects that are bound to the current context ....

Attachments to unbound container objects, such as deletion of a buffer attached to a vertex array object which is not bound to the context, are not affected and continue to act as references on the deleted object ....

When a buffer, query, renderbuffer, sampler, sync, or texture object is deleted, its name immediately becomes invalid (e.g. is marked unused), but the underlying object will not be deleted until it is no longer in use.