-
-
Notifications
You must be signed in to change notification settings - Fork 9.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
Draw Quad with custom shader DrawCallback #7744
Comments
I'm not sure how we can help, it's seems likely a problem with your use of DX11.
It doesn't seem simpler to me IMHO because you are going to need lots of shader variants. |
If it's dx11 problem I can work on it. I never saw a proper usage of draw callback I'm not sure of the proper use.
True! More shader variant, but traded for more flexibility, for a simple linear gradient I need lot of vertices (based on where the gradient start end). |
You should probably use RenderDoc or another gpu debugger to understand why your code is crashing.
DrawQuadWithCustomShader output a simple quad which can already be output by ImDrawList, so maybe you can simply your callback logic to set shader + some uniforms for your shader, and not attempt to create/bind buffers. AddCallback(bind your shader and data) |
[Fixed] ImGui::Begin( "Custom Shader" );
ImDrawList* draw = ImGui::GetWindowDrawList();
ImVec2 cur = ImGui::GetCursorScreenPos();
draw->AddCallback( &DrawCustomShaderQuad, &shader );
ImRect bb( cur, cur + ImGui::GetContentRegionAvail() );
draw->AddImageQuad( img, bb.GetBL(), bb.GetBR(), bb.GetTR(), bb.GetTL(), ImVec2( 0, 0 ), ImVec2( 1, 0 ), ImVec2( 1, 1 ), ImVec2( 0, 1 ), IM_COL32_WHITE );
draw->AddCallback( ImDrawCallback_ResetRenderState, NULL );
ImGui::End(); Your second recommendation is much simple, it simplify the memory management etc. And rely on unique Vertex Buffer. void DrawCustomShaderQuad( const ImDrawList* parent_list, const ImDrawCmd* cmd )
{
ImPlatform::ImShader* shaders = ( ImPlatform::ImShader* )cmd->UserCallbackData;
ImGui_ImplDX11_Data* bd = ImGui_ImplDX11_GetBackendData();
ID3D11DeviceContext* ctx = bd->pd3dDeviceContext;
ctx->PSSetShader( ( ID3D11PixelShader* )( shaders->ps ), nullptr, 0 );
} |
I guess you’ll need to pass some extra data to your shader but that’s the general idea yes (as long as the vertex format used by ImDrawList is sufficient for you). |
Yes indeed It need extra for to add more data etc. |
Sidenote to have it portable for GLSL and GLSL I prefix all shaders with: |
Good to hear. Do you need anything else on my end or can we close this? |
Version/Branch of Dear ImGui:
master
Back-ends:
imgui_impl_dx11.cpp + imgui_impl_win32.cpp
Compiler, OS:
MSVC 2022
Full config/build information:
No response
Details:
Attempt to render a quad with a custom shader. I wasn't able to see how to hook my code with DrawCall back and the reset of RenderStates.
Here an example I tried with win32/dx11 backend.
This code is not working, and produce a gpu hang.
XY Problem: Various rendering function I had on DearWidgets rely on vertex shader interpolation, so for a given gradient I need lot of vertices. It will be a simpler (no brainer) to have a trivial pixel shader with 4 vertices instead.
Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
The text was updated successfully, but these errors were encountered: