Skip to content
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 DrawList #4879

Closed
ghost opened this issue Jan 8, 2022 · 3 comments
Closed

Custom DrawList #4879

ghost opened this issue Jan 8, 2022 · 3 comments

Comments

@ghost
Copy link

ghost commented Jan 8, 2022

Version/Branch of Dear ImGui:

Version: 1.86
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: DX9 + Win32
Compiler: C++ / Visual Studio
Operating System: Windows 11

My Issue/Question:

How do I render a custom draw list like for example,I can just call ImGui::Render(custom_drawlist);
I was using an old program and that was how it rendered custom drawlist,not sure if it's a specific implementation by the program to render custom draw list.But after I recently update the files to 1.86,the ImGui::Render() function doesn't take any parameters anymore and now I don't know how to render the custom draw list

@ghost
Copy link
Author

ghost commented Jan 8, 2022

I tried editing the Render function myself and added the bolded part

for (int n = 0; n != g.Viewports.Size; n++)
    {
        ImGuiViewportP* viewport = g.Viewports[n];
        viewport->DrawDataBuilder.Clear();
        if (viewport->DrawLists[0] != NULL)
            AddDrawListToDrawData(&viewport->DrawDataBuilder.Layers[0], GetBackgroundDrawList(viewport));
        **if (our_list && !our_list->VtxBuffer.empty() && !our_list->CmdBuffer.empty() && !our_list->IdxBuffer.empty())
            AddDrawListToDrawData(&viewport->DrawDataBuilder.Layers[0], our_list);**
    }

But it didn't pass this assert :
IM_ASSERT(draw_list->VtxBuffer.Size == 0 || draw_list->_VtxWritePtr == draw_list->VtxBuffer.Data + draw_list->VtxBuffer.Size);

So I'm guessing I did something wrong and have no idea how any of this works I just want to render menus please help this stuff is giving me headaches

@ghost
Copy link
Author

ghost commented Jan 8, 2022

I tried again,the code above worked,just had to comment out the assert (probably not the best thing to do) and changed the code to

if (our_list && !our_list->VtxBuffer.empty())
            AddDrawListToDrawData(&viewport->DrawDataBuilder.Layers[0], our_list);

Please suggest any alternative other than commenting out the assert

@sturnclaw
Copy link

You will want to build an ImDrawData object that you can pass into an example render backend or your own custom render backend. This is the way we generate DrawData objects to pass to our custom render backend in Pioneer Space Sim when using the low-level ImDrawList API:

ImDrawData drawData{};
ImDrawList *dl = m_drawList.get();

drawData.Valid = true;
drawData.CmdLists = &dl;
drawData.CmdListsCount = 1;
drawData.TotalVtxCount = dl->VtxBuffer.size();
drawData.TotalIdxCount = dl->IdxBuffer.size();

drawData.DisplayPos = ImVec2(0.0f, 0.0f);
drawData.DisplaySize = ImVec2(Graphics::GetScreenWidth(), Graphics::GetScreenHeight());
drawData.FramebufferScale = ImVec2(1.0f, 1.0f);

Pi::pigui->GetRenderer()->RenderDrawData(&drawData);

I don't make any guarantees that this code works verbatim with a vanilla ImGui render backend, we do things slightly differently to make drawing as efficient as possible, but it should be a good jumping-off point.

@ghost ghost closed this as completed Feb 14, 2022
ocornut added a commit that referenced this issue Jul 12, 2023
…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
ocornut added a commit that referenced this issue Jul 12, 2023
…rawList(). (#6406, #4879, #1878)

# Conflicts:
#	imgui.cpp
#	imgui_internal.h
ocornut added a commit that referenced this issue Jul 12, 2023
…s() rely on a valid command being there (especially in docking branch). (#6406, #4879, #1878)

Amend/fix dbeeeae for docking.
+ Build fix when using IMGUI_DISABLE_DEBUG_TOOLS
ocornut added a commit that referenced this issue Jul 12, 2023
…s() rely on a valid command being there (especially in docking branch). (#6406, #4879, #1878)

Amend/fix dbeeeae for docking.
+ Build fix when using IMGUI_DISABLE_DEBUG_TOOLS
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants