KhronosGroup / KhronosGroup/WebGL
Clarification regarding deleting buffers attached to active TransformFeedback object
- Dominant language
- HTML
- Stars
- 2.9k
- Forks
- 703
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 4
Description
I have a two part question, looking for clarification on the semantics for deleting an attached buffer to an active XFB object.
#### Part 1: Deleting buffers attached to active XFB
Take the following example code:
```
var tf = gl.createTransformFeedback();
gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, tf);
var buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, sumBuffer);
gl.bufferData(gl.ARRAY_BUFFER, 24, gl.STATIC_DRAW);
// bind buffer to XFB index 0
gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, buffer);
gl.beginTransformFeedback(gl.TRIANGLES);
// XFB is now active and writing output into buffer
gl.deleteBuffer(buffer); //free buffer object
```
The OpenGL ES 3.2 spec states (_2.6.11 Transform Feedback Objects_, pg 29)[1]:
> Transform feedback objects are container objects including references to buffer objects, [...]
So it would seem that _5.1.3 Delete Object and Object Name Lifetimes_, pg 45 [1] applies (emphasise is mine):
> 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**.
A buffer, renderbuffer, sampler, or texture object **is in use** if any of the following conditions are satisfied:
• the **object is attached to any container object** (such as a buffer object attached to a vertex array object, or a renderbuffer or texture attached to a framebuffer object)
So `buffer` in the sample code should become invalid but the underlying storage kept until the the XFB object is no longer using it. What does _not longer in use_ mean in this case? Until the XFB is inactive? Until a new buffer is attached to the index with `BindBufferBase` or `BindBufferRange`?
#### Part 2: Semantics of gl.deleteBuffer when unbind XFB attachments
When deleting a buffer that is attached, _5.1.2 Automatic Unbinding of Deleted Objects_, pg 45 [1] states:
> 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 [...]
Is this equivalent of calling `gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, null)`?
If so, isn't this an error that should result in `gl.INVALID_OPERATION` per _12.2 Transform Feedback_, pg 344 [1]:
> • by BindBufferRange or BindBufferBase if target is `TRANSFORM_FEEDBACK_BUFFER` and transform feedback is currently active.
[1]: https://www.khronos.org/registry/OpenGL/specs/es/3.2/es_spec_3.2.pdf
Contributor guide
Research direction
Read the cited OpenGL ES 3.2 sections 2.6.11, 5.1.2, 5.1.3, and 12.2 alongside the example in the issue. Trace the lifetime and automatic-unbinding rules for the active transform feedback attachment, then document whether deletion preserves the underlying buffer and how active-state restrictions apply. Done means both questions have an unambiguous specification-based answer.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- computer-graphics
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100