-
Notifications
You must be signed in to change notification settings - Fork 29
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
Unrelated texture operations mess up texture bindings #1773
Comments
@PathogenDavid this is an unfortunate consequence of OpenGL itself being a globally accessible mutable state machine. It is not just texture bindings interacting, but pretty much everything that you can possibly do with OpenGL, including changing render states, enabling / disabling blending, changing point sizes, viewports, etc. I tried quite a few different designs when the
The idea was somewhat that this package would not be used directly most of the times other than for simple, direct access stuff, but rather would provide a foundation for other high-level engines such as The reason for specifying everything as an This simple approach did allow us to build some pretty interesting and powerful abstractions using a reasonably small architecture, even if they probably look strange to both OpenGL and render engine developers. We could have provided more principled, opinionated, and sanitized abstractions, but the goal was more to try and expose a minimal boilerplate version of OpenGL 4, warts and all. That said, the fact that the package is still in The point about the name "shaders" is well taken, although to be fair the kind of programs you can register with the manager includes not only materials, but also compute shaders, which imply compiling a different pipeline altogether. If we went strictly with OpenGL parlance, the correct name might be I'm not opposed to completely redesigning the shaders package, or possibly even creating an entirely new package altogether. Especially when we plan on migrating to the new OpenTK or any other .NET Core compatible backend we are sure to need breaking changes, but most likely for the .NET Framework world this slightly wonky Shaders package will remain as a lesson on how not to build a game engine. |
The API that Bonsai presents for binding textures implies that the texture will be durably bound to the specified shader, however OpenGL textures slots are global application state.
Binding a shader essentially just schedules a
glBindTexture
to be called when the shader is bound for rendering.This means texture bindings for a given shader will change unexpectedly in situations where a texture slot is used for something else and nothing in the workflow is constantly scheduling a rebind for the shader.
Repro
To reproduce this issue:
UpdateTexture
node (Note that this node is updating theTestDynamic
texture, which is not bound by anything within the workflow.)This happens because the
UpdateTexture
node has to bind the texture in order to update it. This texture hangs around in the texture slot for the remainder of the run since the delegate scheduled by theBindTexture
node is executed only once ever.Proposed fix
I haven't investigated thoroughly, but I think ideally rather than blindly scheduling
Action
s to be executed when the shader is bound, we should instead maintain a proper table of texture bindings and ensure they're rebound every time the shader is bound.As an aside, I find the naming of shaders to be a bit unfortunate since I think the term "material" more accurately represents the abstraction they provide. (The
ShaderResources
node even calls them materials.)The text was updated successfully, but these errors were encountered: