three.js: Renderer state.reset() no longer resets attributes
We perform some WebGL computation using the raw WebGL context (i.e. inside our animation frame callback but before our calls to Three to render the scene etc. We need to use the same context since we use some of the output from that work in three (e.g. some textures). In order to ensure that GL state is in a relatively predictable state before and after our raw context use, we call renderer.state.reset()
.
This was working great before r118, but it looks like that revision moved the management of attributes out of WebGLState and into WebGLBindingStates, and this means our call to renderer.state.reset()
no longer disables the enabled attributes.
We were wondering if there was a way to clear these attributes with the new structure or, failing that, if you’d be open to us taking a look at how to introduce it with a PR?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 17 (7 by maintainers)
Unfortunately we need to be careful to add this type of API as written in the above. So I’d like to suggest making your fork for now and revisiting in the core if we get the same feature request more.
I agree with @Mugen87. The Renderer inside (WebGL resource management) is complex. Exposing an API which affects internal WebGL resources can make it harder to maintain. Once we expose an API, we should keep the API unchanged as much as possible, then I think there my be a chance that exposing such an API can block the change (optimization) of the renderer inside.
But, on the other hand, I know we sometimes have requests from users that they want to finely control WebGL resources by themselves. So I think it might be acceptable if the change is very simple and easy, and many users want this feature.
Yeah, I think so, too. But just in case I want to hear @cgauld 's comment because I’m not sure the use case.
Hi, I’d like to vote for resetting the binding state since I also encountered an issue with binding state not being reset after an upgrade to three.js 123.
In Potree, I’m rendering point clouds with custom WebGL code using the same context as three.js. Previously,
renderer.state.reset();
did the trick. Now, I also have to callbindingStates.reset()
but the main issue for me is that bindingStates is not accessible without modifying the three.js source code.As a workaround, I’ve added
this.bindingStates = bindingStates;
to the WebGLRenderer so that I can userenderer.bindingStates.reset()
.Would it be okay to make bindingStates publicly accessible like that? It’s still up to me to make sure that whatever I do with custom WebGL code doesn’t break three.js, but at least it would allow me to do custom stuff.
Edit: Btw, a workaround that doesn’t require changes to three.js is to render a dummy scene with at least one object, just to make sure that the vertex array object state gets reset. This requires that the object is actually renderer to work, i.e., no frustum culling.
Indeed - I agree 🙂 We’d only expose it on WebGLRenderer/WebGL1Renderer so there’s no expectation it would be a concept that applied to or was exposed by other renderers.