-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add additional resets for culling state #10412
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@@ -755,6 +755,8 @@ class Painter { | |||
// The default values for this state is meaningful and often expected. | |||
// Leaving this state dirty could cause a lot of confusion for users. | |||
this.context.cullFace.setDefault(); | |||
this.context.frontFace.setDefault(); | |||
this.context.cullFaceSide.setDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks good, this exhausts the missing one and I don't think it is necessary to add any other states to reset here. Just to confirm, the one not defaulted here are blending, clearColor, depthTest, depthMask, depthFunc, stencilTest, stencilMask, current program & fbo.
color modes are overridden here:
mapbox-gl-js/src/render/draw_custom.js
Line 34 in ef7b2cb
context.setColorMode(painter.colorModeForRenderPass()); |
stencil here:
mapbox-gl-js/src/render/draw_custom.js
Line 35 in ef7b2cb
context.setStencilMode(StencilMode.disabled); |
depth here:
mapbox-gl-js/src/render/draw_custom.js
Line 41 in ef7b2cb
context.setDepthMode(depthMode); |
And custom layer should override the program.
This, perhaps inadvertently, seems to have fixed an issue I was having where custom layer elements added through Three.js were simply disappearing along with a WebGL warning. Thanks for fixing that (even on accident)! |
@karta-solutions Solving unexpected custom layer interactions was exactly the intent! 🎉 But I'm intrigued that it resulted in a warning rather than simply undesirable/unexpected state. Do you happen to have the warning handy? Though don't bother if you don't have it handy—that it's solved is the main thing 😄 |
@rreusser Yes, the error in the console read "ERROR: GL_INVALID_OPERATION: glDrawElements: range out of bounds for buffer". Not very descriptive, not sure if that helps. |
Resolves: #10372
Sky rendering may change the culling state. @astojilj pointed out that this code which ought to put WebGL in a predictable state before handing rendering off to custom layers doesn't apply consistent frontFace and cullFaceSide state, depending on whether the sky is rendered or not.
mapbox-gl-js/src/render/painter.js
Lines 756 to 758 in 63f39e5
This PR additionally resets
context.frontFace
andcontext.cullFaceSide
to their defaults incontext.reset()
. It wasn't obvious to me how to test this, though I did check that it solves the codepen from #10372.I'm a bit ambivalent about this change. It makes things more predictable, but it feels it risks snowballing into setting all of the WebGL state before handing off to a custom layer. Three.js has a new method called
resetState()
(as a result of buggy Mapbox interactions!) which fixes this problem by performing a more complete reset. I've updated the Mapbox GL-JS/Three.js example to use that function since it seems like the most robust way moving forward to minimize problems.There are two options, I guess:
I think my preference is for 1 for this particular issue, but with an eye on this getting out of hand when third party libraries can perfectly well enforce the state they require.
cc @astojilj @karimnaaji @arindam1993 @mourner
(cc's probably not spot on; still trying to figure out how best to identify the most interested parties)
Launch Checklist
@mapbox/map-design-team
@mapbox/static-apis
if this PR includes style spec API or visual changes@mapbox/gl-native
if this PR includes shader changes or needs a native portmapbox-gl-js
changelog:<changelog>Reset WebGL culling state before drawing custom layers</changelog>