-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
Access to command buffer to modify ImGui DrawList through ImDrawList::AddCallback #5834
Comments
Even if we exposed the command buffer it'd be impractical to change the blend state independently since you'd also need to clone the entire pipeline and have the information needed to do so. (At least that's true for D3D12, I'm less familiar with Vulkan but I believe this applies there as well.) I think the proper solution here would be to just clear the alpha channel of the image yourself after you're done rendering it like you mentioned. |
It's the same for Vulkan, since it's the way these API works. But it's possible, and it's fine, because the HLSL and GLSL used is available in both ImGui_Impl_XXX files and we can re-create the whole pipeline object and modify it for our needs. However, it seems to me that The way I see it would be to simply discard the I believe that low level access like that could be added to the |
Is there a reason why clearing the alpha channel doesn't work for you? |
I think it would be reasonable to expose a backend-dependant structure including a pointer to dx12/vulkan command buffer. Question is where to add this void* without breaking api, as changing the draw callback signature would break existing backend (because function pointers types can’t specify defaut parameters). |
For this specific case, not really. Apart from the fact that codes that don't belong at one place, will be there with a big ol' comment. However, I believe the issue is deeper than that, because it prevents any usage of
Not sure to fully understand. You mean changing the structure that is received in parameter ( |
See #6969 (comment) I have pushed a change e94f95d (+ f890d85 to fix typos in the comments) to start exposing selected backend specific render state. // [BETA] Selected render state data shared with callbacks.
// This is temporarily stored in platform_io.Renderer_RenderState during the ImGui_ImplDX11_RenderDrawData() call.
// (Please open an issue if you feel you need access to more data)
struct ImGui_ImplDX11_RenderState
{
ID3D11Device* Device;
ID3D11DeviceContext* DeviceContext;
ID3D11SamplerState* SamplerDefault;
}; Access with: ImGui_ImplDX11_RenderState* render_state = (ImGui_ImplDX11_RenderState*)ImGui::GetPlatformIO().Renderer_RenderState; I will close this issue and other related ones to focus on whatever arise from this. |
Version/Branch of Dear ImGui:
Version: 1.88
Branch: docking
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_Vulkan.cpp
Compiler: MSVC_2019
Operating System: Windows
My Issue/Question:
How do you access the currently bound command buffer?
Currently, there is no way to access a command buffer during a ImDrawList::AddCallback. This is because the moment the draw call is actually made (ImGui_ImplVulkan_RenderDrawData) is called much later than when ImGui start rendering the whole frame. At least, that the reason I believe for that.
However, it makes it impossible for the user to modify the currently bound pipeline/shader to let it affect the next ImGui rendering commands if the user wants to. Such example could be activating and removing blending on the currently bound pipeline ( the default is always active) or rendering with custom shaders ImGui's text, headers, etc...
For example, I have a simple image rendered before and I want to display it in a viewport. This is the end result.
Here, the text has been rendered with a pipeline that had blending active and so the final texture has an alpha component that varies between 0 and 1. However, when rendered, since the default pipeline has blending enabled and we can't access the command buffer, it's impossible to change that there.
As proof, here is the rendered texture in renderdoc.
At the moment, my only way to patch that is to run one more pipeline BEFORE IMGUI to remove the alpha channel. Using OpenGL would be a different story because it works as a state machine. That is not the case with Vulkan and the way it's currently made, there is, as far as I know, no other possibilities.
If you DO know a way to bypass that limitation, please let me know.
Here is the culprit code, probably the same for most modern backend (meaning metal, DX12 and Vulkan).
Standalone, minimal, complete and verifiable example:
The text was updated successfully, but these errors were encountered: