Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbind Attributes after use #1515

Merged
merged 1 commit into from
Oct 3, 2018
Merged

Conversation

hugoam
Copy link
Contributor

@hugoam hugoam commented Oct 2, 2018

This pursue (and finishes, I presume) the work from previous pull request #1512 to make bgfx play nice with WebGL 2.0
In some cases, WebGL will produce errors because some attributes are still bound, but they are not bound to any buffers anymore.

This is due to bgfx not unbinding them after finishing with a program. This patch fixes it by always unbinding attributes when binding a new program, and the last bound program at the end of the draw loop.

I hesitated to add this behavior under #IF BX_PLATFORM_EMSCRIPTEN guards, but I assumed the performance would be more than negligible so it would not hurt to add it to the general path.

(Some reference of browser code enforcing this:
https://dxr.mozilla.org/mozilla-central/rev/a461fe03fdb07218b7f50e92c59dde64b8f8a5b0/dom/canvas/WebGLProgram.cpp#480)

@bkaradzic
Copy link
Owner

Where do you update m_unboundUsedAttrib?

@hugoam
Copy link
Contributor Author

hugoam commented Oct 2, 2018

We use the same m_unboundUsedAttrib that were setup in bindAttributes. It's the same logic used by bindAttributesEnd except in reverse, if it equals Attrib::Count then we know they were bound so we need to unbind/disable them.

m_unboundUsedAttrib is erased in bindAttributesBegin when the same program is used again, so it's safe to use it when unbinding it since that happens before. Unless I'm mistaken, bindAttributesBegin cannot logically be called in between.

@bkaradzic bkaradzic merged commit 71a1d65 into bkaradzic:master Oct 3, 2018
pigpigyyy added a commit to pigpigyyy/bgfx that referenced this pull request Nov 29, 2018
* master: (63 commits)
  Updated glslang.
  shaderc: Updated version.
  Updated docs.
  Added frame buffer resolve control.
  Updated ImGui.
  Add Unbind Attributes (bkaradzic#1515)
  Added numBackBuffers to initialization parameters.
  01-cubes: Fixed topology to match combo box.
  Updated glslang.
  Fix webgl2 instancing bug (bkaradzic#1512)
  Updated ImGui.
  Updated docs.
  Cleanup.
  Fixed caps.
  Fixed depth format validation.
  Fixed bkaradzic#1431.
  Cleanup.
  Metal: Added magnification filter setting.
  Updated ImGui.
  Updated ImGui.
  ...
pigpigyyy added a commit to pigpigyyy/bgfx that referenced this pull request Oct 14, 2022
* master: (161 commits)
  Updated glslang.
  shaderc: Updated version.
  Updated docs.
  Added frame buffer resolve control.
  Updated ImGui.
  Add Unbind Attributes (bkaradzic#1515)
  Added numBackBuffers to initialization parameters.
  01-cubes: Fixed topology to match combo box.
  Updated glslang.
  Fix webgl2 instancing bug (bkaradzic#1512)
  Updated ImGui.
  Updated docs.
  Cleanup.
  Fixed caps.
  Fixed depth format validation.
  Fixed bkaradzic#1431.
  Cleanup.
  Metal: Added magnification filter setting.
  Updated ImGui.
  Updated ImGui.
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants