Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webgl: destroy or reuse buffer/texture?

Tags:

webgl

I am a newbie in WebGL here. :) I understand vertex data and texture should not not be updated very often BUT when they do change, which one is preferred: - Destroy previous buffer (static_draw) by calling gl.deleteBuffer and create a new one. - Reuse the same one (Dynamic_Draw to begin with)

(NO i am not using any library, just webgl directly)

Does the same rule apply to texture? Thanks

Interesting enough I cannot find existing discussions ..or maybe just missed them.

like image 287
Yi Zhang Avatar asked Sep 04 '26 08:09

Yi Zhang


1 Answers

Lets first look at when we would want to delete a resource:

Since OpenGL is a C-Style API it's assumed that the user is tasked to manage memory, part of that is to also manage GPU memory. Due to encapsulation and other design principles one is not always able to share and reuse resources so the delete* functions exists to free up the allocated resources. In javascript the garbage collector makes sure that WebGL resources that go out of scope are flagged for deletion just like calling delete* does¹ resulting in the delete* functions to become rather superfluous in the context of WebGL.

With that cleared up you'd always want to update your resources where possible since you'll also have to redo all the setup that you've already done to them, e.g. setting vertex attribute pointers or filter and wrapping modes for textures.

like image 116
LJᛃ Avatar answered Sep 06 '26 17:09

LJᛃ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!