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

Get Old Draw Data To Display If Not Rendered New Data #5252

Closed
pegvin opened this issue Apr 28, 2022 · 4 comments
Closed

Get Old Draw Data To Display If Not Rendered New Data #5252

pegvin opened this issue Apr 28, 2022 · 4 comments

Comments

@pegvin
Copy link

pegvin commented Apr 28, 2022

Version/Branch of Dear ImGui:

Version: 1.87
Branch: master

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler: Clang++
Operating System: Manjaro Linux

Question:
I am drawing UI for my pixel art tool using ImGui, but since UI isn't updated very often i want to use the old render data to display until and unless new data is rendered, for example:

unsigned char uiShouldRender = 1; // Global Variable
...
// Here's some code anyone can copy and paste to reproduce your issue
if (uiShouldRender == 1) {
	ImGui_ImplOpenGL3_NewFrame();
	ImGui_ImplGlfw_NewFrame();
	ImGui::NewFrame();

	ImGui::Begin("SelectedToolWindow", NULL, window_flags);
	ImGui::SetWindowPos({0, 0});
	ImGui::Text("Square Eraser - (Size: %d)", brush_size);
	ImGui::End();

	ImGui::Render();
	uiShouldRender = 0;
}
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

In this code the if statement is executed atleast once causing ImGui to draw the data, now this statement will only run again when in event handler the uiShouldRender is set to 1 again,

This whole code is inside my window loop:

while (!glfwWindowShouldClose(window)) {
	glfwPollEvents();
	process_input(window);
	glClearColor(0.075, 0.075, 0.1, 1.0);
	...
	glfwSwapBuffers(window);
}

Problem is i see everything normal on my screen except my UI, my canvas and etc are working Normally except the UI doesn't show up.

I am doing this so that i won't need render everytime even when it is not needed, i know ImGui is a immediate mode rendering UI system but it would be help full if it was possible to use the old draw data if new isn't rendered.

Output I Get:
image

Output I Get When I Just Draw The UI Every Frame:
image

@ocornut
Copy link
Owner

ocornut commented Apr 28, 2022

but since UI isn't updated very often i want to use the old render data to display until and unless new data is rendered,
[...] I am doing this so that i won't need render everytime even when it is not needed, i know ImGui is a immediate mode rendering UI system but it would be help full if it was possible to use the old draw data if new isn't rendered.

But what ? What is the reason you want to do that ? Serious question.
Could you simply skip rendering your entire app (not just UI) on idle ?

If I look at your repro / pseudo code it looks correct: if you don't call NewFrame/Render the draw data won't elapse. So I presume there's something else in your code that's different from that piece of code.

We will eventually probably merge #2749 / #4076 but I don't have visibility on when.

@pegvin
Copy link
Author

pegvin commented Apr 28, 2022

For idle state i know, but when using the application the UI isn't updated until and unless user selects a new tool or pans around or zooms in or out, so i don't want to render the same thing again, i want to use the old render data to display and render again only when the user selects a tool or something like that.

@ocornut
Copy link
Owner

ocornut commented Apr 30, 2022

so i don't want to render the same thing again

You haven't answered my question "why?" but I suspect you are over-engineering for a non-problem here.
As stated above you repro should be correct since the draw data won't be changed if you don't call any function, so you are omitting something and I cannot magically guess what it is and debug your code.

@ocornut ocornut closed this as completed Apr 30, 2022
@pegvin
Copy link
Author

pegvin commented Apr 30, 2022

Hey @ocornut Sorry for the mess i created, I basically didn't want to render the same thing again because i thought it might cost me some performance, but i ran some tests and didn't found any major performance difference.
I figured out how to render only when i need to but it wasn't worth it.
I am sorry.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants