-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Custom draw list - shape isn't rendered #6406
Comments
Hello Pavle, You are creating your own This works: {
// Create once
static ImDrawList* drawList = new ImDrawList(ImGui::GetDrawListSharedData());
// Init for the frame
// (no need to PopTextureID()/PopClipRect()) since we reset every frame
drawList->_ResetForNewFrame();
drawList->PushClipRectFullScreen();
drawList->PushTextureID(io.Fonts->TexID);
// Submit contents
drawList->AddText(ImGui::GetFont(), 13, ImVec2(10, 200), IM_COL32_WHITE, "Test Standalone ImGui DrawList");
drawList->AddCircleFilled(ImVec2(100, 100), 100, ImColor(122, 110, 80, 255));
// Create ImDrawData
static ImDrawData drawData = ImDrawData();
drawData.DisplayPos = ImGui::GetMainViewport()->Pos;
drawData.DisplaySize = ImGui::GetMainViewport()->Size;
drawData.FramebufferScale = ImVec2(1.0f, 1.0f);
drawData.CmdLists = &drawList;
drawData.CmdListsCount = 1;
drawData.TotalIdxCount = drawList->IdxBuffer.size();
drawData.TotalVtxCount = drawList->VtxBuffer.size();
drawData.Valid = true;
ImGui_ImplDX11_RenderDrawData(&drawData);
} Note that:
I think we should later aim to make this simpler, by e.g. making it easier to create a ImDrawData or even append to an existing ImDrawData. Will post here if we can bring further simplications. |
I made changes in IMGUI_VERSION = "1.89.8 WIP", IMGUI_VERSION_NUM = 18973 The example suggested above in #6406 (comment) won't compile anymore as one cannot assign ImDrawList::CmdLists directly, however the new version is now simpler: {
// Create once
static ImDrawList* drawList = new ImDrawList(ImGui::GetDrawListSharedData());
// Init for the frame
// (no need to PopTextureID()/PopClipRect()) since we reset every frame
drawList->_ResetForNewFrame();
drawList->PushClipRectFullScreen();
drawList->PushTextureID(io.Fonts->TexID);
// Submit contents
drawList->AddText(ImGui::GetFont(), 13, ImVec2(10, 200), IM_COL32_WHITE, "Test Standalone ImGui DrawList");
drawList->AddCircleFilled(ImVec2(100, 100), 100, ImColor(122, 110, 80, 255));
// Create ImDrawData
static ImDrawData drawData = ImDrawData();
drawData.Clear();
drawData.Valid = true;
drawData.DisplayPos = ImGui::GetMainViewport()->Pos;
drawData.DisplaySize = ImGui::GetMainViewport()->Size;
drawData.FramebufferScale = ImVec2(1.0f, 1.0f);
drawData.AddDrawList(drawList);
ImGui_ImplDX11_RenderDrawData(&drawData);
} That's a create a full entire separate ImDrawData and renders it. However you can also add to the existing ImDrawData: {
ImDrawData* draw_data = ImGui::GetDrawData();
// Create once
static ImDrawList* drawList = new ImDrawList(ImGui::GetDrawListSharedData());
// Init for the frame
// (no need to PopTextureID()/PopClipRect()) since we reset every frame
drawList->_ResetForNewFrame();
drawList->PushClipRectFullScreen();
drawList->PushTextureID(io.Fonts->TexID);
// Submit contents
drawList->AddText(ImGui::GetFont(), 13, ImVec2(10, 200), IM_COL32_WHITE, "Test Standalone ImGui DrawList");
drawList->AddCircleFilled(ImVec2(100, 100), 100, ImColor(122, 110, 80, 255));
draw_data->AddDrawList(drawList);
ImGui_ImplDX11_RenderDrawData(draw_data);
} |
…DrawData itself. Faclitate user-manipulation of the array (#6406, #4879, #1878) + deep swap. (#6597, #6475, #6167, #5776, #5109, #4763, #3515, #1860) + Metrics: avoid misleadingly iterating all layers of DrawDataBuilder as everything is flattened into Layers[0] at this point. # Conflicts: # imgui.cpp # imgui_internal.h
Hello, i want to swap one custom drawlist data to another and im using ImGui 18990 on win32_dx9 backend and this code result both linked below assertions for me after i use operator= on the drawlists, i guess there is a more proper way to do it? https://github.com/ocornut/imgui/blob/master/imgui_draw.cpp#L1873-L1874 // init drawlists once
static ImDrawList* pThreadDrawList = new ImDrawList(ImGui::GetDrawListSharedData( ));
static ImDrawList* pSafeDrawList = new ImDrawList(ImGui::GetDrawListSharedData( ));
// should be somewhere, but now its in main function
{
pThreadDrawList->_ResetForNewFrame( );
pThreadDrawList->PushClipRectFullScreen( );
pThreadDrawList->PushTextureID(io.Fonts->TexID);
// draw things
pThreadDrawList->AddText(ImGui::GetFont( ), 13, ImVec2(10, 200), IM_COL32_WHITE, "Test Standalone ImGui DrawList");
pThreadDrawList->AddCircleFilled(ImVec2(100, 100), 100, ImColor(122, 110, 80, 255));
*pSafeDrawList = *pThreadDrawList; // results assertion, otherwise drawlist not being rendered obviously
};
ImDrawData* pDrawData= ImGui::GetDrawData( );
pDrawData->AddDrawList(pSafeDrawList);
ImGui_ImplDX9_RenderDrawData(pDrawData); Thanks! |
There’s no = operator and you shouldn’t have to deep copy a ImDrawList this is going to be wasteful.
You always need to explain yourself and others WHY you are intending to do this. I’m making guesses since you are not explaining your actual problem, but I believe your approach should be reworked as : when you are done with a drawlist and want to pass it to another thread, stop writing into it. In that situation you may eg instead swap pointers. But you may need better synchronization mechanism if those threads are working in parallel. |
Sorry, im trying to implement thread-safe rendering drawlist, but for now, as im getting those assertions, im using single threaded imgui's backend test application. |
Version/Branch of Dear ImGui:
Version: 1.89.2
Branch: docking
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_win32.cpp + imgui_impl_dx11.cpp
Compiler: VS2022
Operating System: Windows 10
My Issue/Question:
I am trying to create custom draw list and I took code from here #1878 and I modified it for directx 11 but when I run app I don't see circle. Why it doesn't render circle?
The text was updated successfully, but these errors were encountered: