flyover / imgui-js

JavaScript bindings for Dear ImGui using Emscripten and TypeScript
https://flyover.github.io/imgui-js/example/
MIT License
915 stars 98 forks source link

save the attribute state that is being trashed #41

Closed greggman closed 3 years ago

greggman commented 3 years ago

See issue #40

PS: This is not a real PR, it's just an example. I didn't even try to compile it. I'm not actually using the library.

The attribute state is not being saved and restored. And even this is not actually 100%. To be 100% you'd need to check for the ANGLE_instanced_arrays extension and if it exists, enable it and save and restore the divisor as in

  // save
      if (extension)
        last_attr0_divisor = gl.getVertexAttrib(attriblocation, extension.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE);

  // restore
      if (extension) {
         extension.vertexAttribDivisorANGLE(attriblocation, last_attr0_divisor);

And worse, this only handles WebGL1. In WebGL2 you'd arguably want to skip all the code in the PR, make a vertex array, save the current one, bind yours, then restore

const oldVao = gl.getParameter(gl.VERTEX_ARRAY_BINDING);
gl.bindVertexArray(imguiVao);

gl.bindVertexArray(oldVao);