mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Added GetDrawData() alternative to setting a Render function.
This commit is contained in:
parent
93f9ad9ddf
commit
dafad3903e
31
imgui.cpp
31
imgui.cpp
@ -96,6 +96,7 @@
|
|||||||
io.DisplaySize.y = 1280.0f;
|
io.DisplaySize.y = 1280.0f;
|
||||||
io.DeltaTime = 1.0f/60.0f;
|
io.DeltaTime = 1.0f/60.0f;
|
||||||
io.IniFilename = "imgui.ini";
|
io.IniFilename = "imgui.ini";
|
||||||
|
io.RenderDrawListsFn = my_render_function; // Setup a render function, or set to NULL and call GetDrawData() after Render() to access the render data.
|
||||||
// TODO: Fill others settings of the io structure
|
// TODO: Fill others settings of the io structure
|
||||||
|
|
||||||
// Load texture
|
// Load texture
|
||||||
@ -1769,6 +1770,12 @@ ImGuiStyle& ImGui::GetStyle()
|
|||||||
return GImGui->Style;
|
return GImGui->Style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Same value as passed to your RenderDrawListsFn() function. valid after Render() and until the next call to NewFrame()
|
||||||
|
ImDrawData* ImGui::GetDrawData()
|
||||||
|
{
|
||||||
|
return GImGui->RenderDrawData.Valid ? &GImGui->RenderDrawData : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
float ImGui::GetTime()
|
float ImGui::GetTime()
|
||||||
{
|
{
|
||||||
return GImGui->Time;
|
return GImGui->Time;
|
||||||
@ -1786,7 +1793,6 @@ void ImGui::NewFrame()
|
|||||||
// Check user data
|
// Check user data
|
||||||
IM_ASSERT(g.IO.DeltaTime >= 0.0f);
|
IM_ASSERT(g.IO.DeltaTime >= 0.0f);
|
||||||
IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f);
|
IM_ASSERT(g.IO.DisplaySize.x >= 0.0f && g.IO.DisplaySize.y >= 0.0f);
|
||||||
IM_ASSERT(g.IO.RenderDrawListsFn != NULL); // Must be implemented
|
|
||||||
IM_ASSERT(g.IO.Fonts->Fonts.Size > 0); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
|
IM_ASSERT(g.IO.Fonts->Fonts.Size > 0); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
|
||||||
IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded()); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
|
IM_ASSERT(g.IO.Fonts->Fonts[0]->IsLoaded()); // Font Atlas not created. Did you call io.Fonts->GetTexDataAsRGBA32 / GetTexDataAsAlpha8 ?
|
||||||
IM_ASSERT(g.Style.CurveTessellationTol > 0.0f); // Invalid
|
IM_ASSERT(g.Style.CurveTessellationTol > 0.0f); // Invalid
|
||||||
@ -1812,6 +1818,11 @@ void ImGui::NewFrame()
|
|||||||
g.OverlayDrawList.PushClipRectFullScreen();
|
g.OverlayDrawList.PushClipRectFullScreen();
|
||||||
g.OverlayDrawList.AddDrawCmd();
|
g.OverlayDrawList.AddDrawCmd();
|
||||||
|
|
||||||
|
// Mark rendering data as invalid to prevent user who may have a handle on it to use it
|
||||||
|
g.RenderDrawData.Valid = false;
|
||||||
|
g.RenderDrawData.CmdLists = NULL;
|
||||||
|
g.RenderDrawData.CmdListsCount = g.RenderDrawData.TotalVtxCount = g.RenderDrawData.TotalIdxCount = 0;
|
||||||
|
|
||||||
// Update inputs state
|
// Update inputs state
|
||||||
if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
|
if (g.IO.MousePos.x < 0 && g.IO.MousePos.y < 0)
|
||||||
g.IO.MousePos = ImVec2(-9999.0f, -9999.0f);
|
g.IO.MousePos = ImVec2(-9999.0f, -9999.0f);
|
||||||
@ -2366,15 +2377,17 @@ void ImGui::Render()
|
|||||||
if (!g.OverlayDrawList.VtxBuffer.empty())
|
if (!g.OverlayDrawList.VtxBuffer.empty())
|
||||||
AddDrawListToRenderList(g.RenderDrawLists[0], &g.OverlayDrawList);
|
AddDrawListToRenderList(g.RenderDrawLists[0], &g.OverlayDrawList);
|
||||||
|
|
||||||
// Render
|
// Setup draw data
|
||||||
if (!g.RenderDrawLists[0].empty())
|
g.RenderDrawData.Valid = true;
|
||||||
|
g.RenderDrawData.CmdLists = &g.RenderDrawLists[0][0];
|
||||||
|
g.RenderDrawData.CmdListsCount = g.RenderDrawLists[0].Size;
|
||||||
|
g.RenderDrawData.TotalVtxCount = g.IO.MetricsRenderVertices;
|
||||||
|
g.RenderDrawData.TotalIdxCount = g.IO.MetricsRenderIndices;
|
||||||
|
|
||||||
|
// Render. If user hasn't set a callback then they may retrieve the draw data via GetDrawData()
|
||||||
|
if (g.RenderDrawData.CmdListsCount > 0 && g.IO.RenderDrawListsFn != NULL)
|
||||||
{
|
{
|
||||||
ImDrawData data;
|
g.IO.RenderDrawListsFn(&g.RenderDrawData);
|
||||||
data.CmdLists = &g.RenderDrawLists[0][0];
|
|
||||||
data.CmdListsCount = g.RenderDrawLists[0].Size;
|
|
||||||
data.TotalVtxCount = g.IO.MetricsRenderVertices;
|
|
||||||
data.TotalIdxCount = g.IO.MetricsRenderIndices;
|
|
||||||
g.IO.RenderDrawListsFn(&data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
12
imgui.h
12
imgui.h
@ -105,6 +105,7 @@ namespace ImGui
|
|||||||
// Main
|
// Main
|
||||||
IMGUI_API ImGuiIO& GetIO();
|
IMGUI_API ImGuiIO& GetIO();
|
||||||
IMGUI_API ImGuiStyle& GetStyle();
|
IMGUI_API ImGuiStyle& GetStyle();
|
||||||
|
IMGUI_API ImDrawData* GetDrawData(); // same value as passed to your RenderDrawListsFn() function. valid after Render() and until the next call to NewFrame()
|
||||||
IMGUI_API void NewFrame();
|
IMGUI_API void NewFrame();
|
||||||
IMGUI_API void Render();
|
IMGUI_API void Render();
|
||||||
IMGUI_API void Shutdown();
|
IMGUI_API void Shutdown();
|
||||||
@ -694,8 +695,9 @@ struct ImGuiIO
|
|||||||
// User Functions
|
// User Functions
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
|
|
||||||
// REQUIRED: rendering function.
|
// Rendering function, will be called in Render().
|
||||||
// See example code if you are unsure of how to implement this.
|
// Alternatively you can keep this to NULL and call GetDrawData() after Render() to get the same pointer.
|
||||||
|
// See example applications if you are unsure of how to implement this.
|
||||||
void (*RenderDrawListsFn)(ImDrawData* data);
|
void (*RenderDrawListsFn)(ImDrawData* data);
|
||||||
|
|
||||||
// Optional: access OS clipboard
|
// Optional: access OS clipboard
|
||||||
@ -1149,14 +1151,16 @@ struct ImDrawList
|
|||||||
// All draw data to render an ImGui frame
|
// All draw data to render an ImGui frame
|
||||||
struct ImDrawData
|
struct ImDrawData
|
||||||
{
|
{
|
||||||
|
bool Valid; // Only valid after Render() is called and before the next NewFrame() is called.
|
||||||
ImDrawList** CmdLists;
|
ImDrawList** CmdLists;
|
||||||
int CmdListsCount;
|
int CmdListsCount;
|
||||||
int TotalVtxCount; // For convenience, sum of all cmd_lists vtx_buffer.Size
|
int TotalVtxCount; // For convenience, sum of all cmd_lists vtx_buffer.Size
|
||||||
int TotalIdxCount; // For convenience, sum of all cmd_lists idx_buffer.Size
|
int TotalIdxCount; // For convenience, sum of all cmd_lists idx_buffer.Size
|
||||||
|
|
||||||
// Functions
|
// Functions
|
||||||
void DeIndexAllBuffers(); // For backward compatibility: convert all buffers from indexed to de-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering!
|
IMGUI_API ImDrawData() { Valid = false; CmdLists = NULL; CmdListsCount = TotalVtxCount = TotalIdxCount = 0; }
|
||||||
void ScaleClipRects(const ImVec2& sc); // Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than ImGui expects, or if there is a difference between your window resolution and framebuffer resolution.
|
IMGUI_API void DeIndexAllBuffers(); // For backward compatibility: convert all buffers from indexed to de-indexed, in case you cannot render indexed. Note: this is slow and most likely a waste of resources. Always prefer indexed rendering!
|
||||||
|
IMGUI_API void ScaleClipRects(const ImVec2& sc); // Helper to scale the ClipRect field of each ImDrawCmd. Use if your final output buffer is at a different scale than ImGui expects, or if there is a difference between your window resolution and framebuffer resolution.
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ImFontConfig
|
struct ImFontConfig
|
||||||
|
@ -371,6 +371,7 @@ struct ImGuiState
|
|||||||
ImGuiSetCond SetNextTreeNodeOpenedCond;
|
ImGuiSetCond SetNextTreeNodeOpenedCond;
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
|
ImDrawData RenderDrawData; // Main ImDrawData instance to pass render information to the user
|
||||||
ImVector<ImDrawList*> RenderDrawLists[3];
|
ImVector<ImDrawList*> RenderDrawLists[3];
|
||||||
float ModalWindowDarkeningRatio;
|
float ModalWindowDarkeningRatio;
|
||||||
ImDrawList OverlayDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set + a few debug overlays
|
ImDrawList OverlayDrawList; // Optional software render of mouse cursors, if io.MouseDrawCursor is set + a few debug overlays
|
||||||
|
Loading…
Reference in New Issue
Block a user