-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Support for separate blend states per render target on OpenGL #6343
Conversation
I'm worried about a potential issue that could arise: The PlatformApplyState function in BlendState.OpenGL.cs has a comparison with _lastBlendState that aims to reduce unnecessary OpenGL calls, which needs to take into account whether the previous blend state had Independent Blending enabled when it was applied. I'm not entirely sure how best to address this. I still feel this is an improvement from the previous version, which could not apply different blend states to separate render targets. |
This is great @minimalism! :) I think the caching problem is solved if you set the blendstate of all targets when |
You mean set _targetBlendState 0 through 3 in the BlendState class? That could be a solution though I'm not sure how this would interact with the DirectX BlendState class. And it would then maybe be kind to generate an exception if the user tries to access the
Here I would expect to still have the ReverseSubtract AlphaBlendFunction on target blend state 0, but would actually have Add on all four. I think setting device._lastBlendState._independentBlendEnable in PlatformApplyState and taking its value into consideration in that same function would avoid the ordering issue above, but would also be slightly more complex. Hopefully I'll have some time to check this solution out this week. |
Yes.
There is no interaction. The caching only happens for the OpenGL backend and the code you're changing only exists in OpenGL builds.
The blend state is only applied (and the last blend state stored) when PlatformApplyState is called. That doesn't happen in your example. When it is called after your code, the cached value for all targets would still be whatever blendState[0] was before any of your code (assuming |
True, I didn't think about waiting until the PlatformApplyState call :) I think that is a good solution. |
There were also some other bugs (obvious in hindsight) in my PR that I fixed |
@minimalism It seems the Blend*Separatei functions are only core since GL 4.0. We'd need to add a flag to GraphicsCapabilities to indicate if the |
Awesome :) I'm curious what those are. |
The |
@minimalism Do you know how to tackle the GraphicsCapabilities part of this? |
Looking at the sites you linked, for DesktopGL I would just compare glMajorVersion <= 4. For the other platforms, I don't know |
There's also an extension for lower gl versions: https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_draw_buffers_blend.txt For DirectX you can set the flag to true since separate blending is supported in all feature levels we support. For mobile and web set it to false, I don't think GL ES supports the indexed variants for blending. |
Not sure about that failing Mac test. Does the test device have independent blend state support? The other platforms certainly appear to. I don't have the appropriate hardware to test this myself. |
Mac GL drivers are notoriously bad. We can just ignore the test on the Mac build bot by changing this line
to
This is almost good to go, after the above fix can you revert the submodule change from 7b044f0? |
Well let's see if that did it, I don't know how the submodule commit slipped in to begin with. |
Oops, I think the Mac build bot runs the Linux test project for some reason. I edited it, hope it passes now. @minimalism You'd best do a pull before you make any local changes now. |
Looking good! Would be good if someone can give this a test. I'll hold off for a bit, but if no one has the time I'll merge this anyway because the changes to the working codepath are minor and are well tested. Though it would be nice to get a unit test in for this. @minimalism If you're not up for that I'll open an issue for it. |
You're probably right.. I think it would be good if someone with an older device could test the ARB_draw_buffers_blend extensions because that code has literally never been run. Unit tests wouldn't hurt either, would be nice to get this wrapped up, but I can't today. |
Oops, made some commits on my own branch that weren't intended for this PR. Reverted, and will put my future questionable commits on a separate branch |
@Jjagg - Might want to do a "Squash and Merge" on this one once it is ready. |
Yeah word. I guess we're waiting for some test coverage to come along |
I'm gonna merge this one. Thanks @minimalism, this is a great PR. Sorry for the long wait! |
…me#6343) * Implemented IndependentBlendEnable for OpenGL * Consistent naming * Fixed issue with independent blend states * Independent BlendFunc is now set correctly * Third party deps * removed debug printouts * LoadEntryPoint is now LoadFunction * adhering to monogame newline standard * whitespace cleanup * removed redundant state changes * GraphicsCapabilities support for separate blend states * Moved blendstate support check to GraphicsDevice * corrected GLES GraphicsCapabilities variable name * corrected tests, dependencies * Looks like Mac build bot runs the Linux generated project * hacked in SRGBA texture support * Revert "hacked in SRGBA texture support" This reverts commit a29820d.
BlendState.IndependentBlendEnable was not implemented on OpenGL platforms.
This fix unfortunately does not account for _lastBlendState only storing the previous state of index 0.