pex-gl / pex-context

Modern WebGL state wrapper for PEX: allocate GPU resources (textures, buffers), setup state pipelines and passes, and combine them into commands.
http://pex-gl.github.io/pex-context/
MIT License
160 stars 12 forks source link

Cleaning up buffers #56

Open simonharrisco opened 5 years ago

simonharrisco commented 5 years ago

In the book I'm reading, along with at this SO answer buffers are cleaned up by nulling them before deletion.

The book is quite unhelpful in just saying that this is 'best practice' without explaining why, but the SO answer also included it.

I cant find anywhere that this is done in pex-context

Is this because when loading lots of things it could cause some issues of emptying a say ARRAY_BUFFER that is being used elsewhere.

Would this cause memory leaks in pex nodes when switching between graphs?

vorg commented 5 years ago

Currently we only delete the buffers and they indeed stay bound the the attribute forever (or until next buffer is bound).

By cleaned up by nulling i think you mix two concept. You can clean texture/buffer binding gl.bindBuffer(gl.ARRAY_BUFFER, null). Then you delete the buffer gl.deleteBuffer(someBuffer).

As for attributes i've never heard about creating empty buffer and binding it to clear previous bindings. It does make sense but would love to know what are the implications of not doing that. Same with "set a buffer to 1 byte before deleting". Currently we only disable unused attributes.

@simonharrisco Anything in your WebGL 2 rendering book?

One good piece of advice is resizing canvas when you are done with webgl context. Added an issue for it https://github.com/pex-gl/pex-context/issues/57

vorg commented 5 years ago

Another thing i've seen is people using WEBGL_lose_context.loseContext() to force resources release although it's not an official way.

dmnsgn commented 5 years ago

WEBGL_lose_context.loseContext is hard to reason about because implementations varies. I'd keep it in user land.