-
Notifications
You must be signed in to change notification settings - Fork 23
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
ImGui full integration #17
Comments
At this point in time
|
Just detected a problem with activating DSP, it must be something related with the instantiation of the audio device object, probably because of his "different" nature (system object), but need further analysis. it's crashing here: PatchObject::drawImGuiNode(ImGuiEx::NodeCanvas&) + 944 can be because this object is inited with zero inlets/outlets, then in the setup connect with the audio config and dynamically add the required inlets/outlets? if i avoid calling the drawImGuiNode method just for this object (for testing) it doesn't crash until i mouse over the object. Do you have some suggestions? |
Yes, it is related with dynamic inlets/outlet creation! Using other objects with this kind of feature (osc receiving/sending, shader object, etc...) crashes Mosaic! |
I got the same crash, looks like a call to |
Yes, i see, my mistake, i added those vector in the last changes while porting links rendering to imgui. easy to fix! |
I'm checking imgui extensions and i found this: https://github.com/AirGuanZ/imgui-filebrowser Do you think it would be good idea to integrate file dialogs in imgui too? Right now i'm using the tinyfiledialogs libs wrappes in an addon: https://github.com/d3cod3/ofxThreadedFileDialog that works a lot smoother than the standard OF file dialogs, plus it's non-blocking, so the patch is still running while opening/saving some file from/to disk. Leaving aside the design (i would like it more to have imgui themed file dialogs windows), what is your opinion about that? I think we need to consider two main points:
|
Having some compile issues with the previous filebrowser repo testing this: https://github.com/gallickgunner/ImGui-Addons |
[first ImGuiEx link] :: "C++17 is required" ==> I recently read that OF doesn't compile out of the box with C++17 (C++14 yes). Maybe this has changed, just noticing. But it's a good idea to do file dialogs only with ImGui, yes. Although current implementation is fine too. Now, personally, I both like and dislike native system dialogs. So, yes and no. I'd say yes, specially batch file-dialog usage can become faster, with a better integration. And we can always provide an optional native file dialog fallback as an ImGui Button. Note: upcoming ImGui versions will have native support for file drag/drop; and there's already something official working. Can also help to make a choice. Another file browser : ImGuiAddons / imguifilesystem (web live demo (filesystem section) ) This ImGuiEx looks great too : https://bitbucket.org/wolfpld/tracy/src/master/ (ofxTimeMesurements is fine too) |
I'm using the code from https://github.com/gallickgunner/ImGui-Addons I needed to update imgui to 1.76 (pushed commit on my ofxImGui fork), and it seems to work real smooth, and this is the temp testing code: // TESTING ImGui FileDialog
if(ImGui::Begin("dummy window"))
{
bool open = false, save = false;
// open file dialog when user clicks this button
if(ImGui::Button("open file dialog"))
open = true;
if(ImGui::Button("save file dialog"))
save = true;
//Remember the name to ImGui::OpenPopup() and showFileDialog() must be same...
if(open)
ImGui::OpenPopup("Open File");
if(save)
ImGui::OpenPopup("Save File");
if( imguiFileDialog.showFileDialog("Open File", imgui_addons::ImGuiFileBrowser::DialogMode::OPEN, ImVec2(700, 310)) )
{
std::cout << imguiFileDialog.selected_fn << std::endl; // The name of the selected file or directory in case of Select Directory dialog mode
std::cout << imguiFileDialog.selected_path << std::endl; // The absolute path to the selected file
}
if( imguiFileDialog.showFileDialog("Save File", imgui_addons::ImGuiFileBrowser::DialogMode::SAVE, ImVec2(700, 310)) )
{
std::cout << imguiFileDialog.selected_fn << std::endl; // The name of the selected file or directory in case of Select Directory dialog mode
std::cout << imguiFileDialog.selected_path << std::endl; // The absolute path to the selected file
std::cout << imguiFileDialog.ext << std::endl; // Access ext separately (For SAVE mode)
//Do writing of files based on extension here
}
}
ImGui::End(); The source code seams neat, and there are three modes implemented, OPEN DIRECTORY, OPEN FILE and SAVE FILE. With that we can substitute the actual implementation without problems, then we'll be able to add drag&drop functionalities. I think it seems a good codebase to include in ofxVP, i'm going to test it a little deeper. |
I'm still working on specific objects graphics/interface with imgui, porting all the OF stuff i made before, file dialogs are completely ported, textures are working in some cases (images YES, video NO, it broke after updating imgui to 1.76), variable plotting and audio signal plotting are working fine, and right now i'm with area constrained draggable points editor for Audio Envelope editing for sound objects. |
Checking this for advanced data plot: https://github.com/epezent/implot maybe for some new objects? we'll see |
Yes, looks useful. There's a lot of interesting ImGuiExtensions, good idea to start listing some. |
Just integrated a profiler, so less future unmantained ofxaddons modified from https://github.com/Raikiri/LegitProfiler |
About the textures drawing between OF and ImGui, i had it solved from some time now, but testing some bigger patches i've found ( and already solved ) a problem: The core of the problem is the same one related with the plugin system #16 , the openGL limitation to share GPU stuff in the same thread only. Basically we have:
So, there is a way of share data between openGL threads, and it is using pixels data ( meaning, leave the GPU and passing through the CPU ) GPU (thread 1) --> texture to pixels --> CPU --> pixels to texture --> GPU (thread 2) Reference: https://openframeworks.cc/ofBook/chapters/threads.html Another way is using PBO, i absolutely have no experience with that, but is never late for learning, so i found this: http://www.songho.ca/opengl/gl_pbo.html#unpack with time i'll check it and try to implement it! In the meantime, having all this bridging via pixels: OF --> texture to pixels --> CPU --> pixel to texture --> ImGui, was costing a lot in computation, and with dense patches, especially the patches with DSP stuff, it was causing problems and sound glitches so i temporarily fixed it with a trick, for all the texture visualizing objects i draw the background of the ImGui node transparent: // Node BG fill
if(curNodeData.zoomName < ImGuiExNodeZoom_Small || !isTextureNode){
nodeDrawList->AddRectFilled( curNodeData.outerContentBox.Min, curNodeData.outerContentBox.Max, ImGui::GetColorU32(ImGuiCol_FrameBg, 999.f));
}else{
nodeDrawList->AddRectFilled( curNodeData.outerContentBox.Min, curNodeData.outerContentBox.Max, IM_COL32(0,0,0,0));
nodeDrawList->AddRectFilled( curNodeData.outerContentBox.Min, ImVec2(curNodeData.outerContentBox.Min.x+curNodeData.leftPins.region.GetSize().x,curNodeData.outerContentBox.Max.y), ImGui::GetColorU32(ImGuiCol_FrameBg, 999.f));
nodeDrawList->AddRectFilled( curNodeData.rightPins.region.Min, curNodeData.outerContentBox.Max, ImGui::GetColorU32(ImGuiCol_FrameBg, 999.f));
} and then i draw from OF the texture directly in the correct node position: inline void drawNodeOFTexture(ofTexture &tex, float &px, float &py, float &w, float &h, float originX, float originY, float scaledW, float scaledH, float zoom, float footerH){
if(tex.isAllocated()){
if(tex.getWidth()/tex.getHeight() >= scaledW/scaledH){
if(tex.getWidth() > tex.getHeight()){ // horizontal texture
w = scaledW;
h = (scaledW/tex.getWidth())*tex.getHeight();
px = 0;
py = (scaledH-h)/2.0f;
}else{ // vertical texture
w = (tex.getWidth()*scaledH)/tex.getHeight();
h = scaledH;
px = (scaledW-w)/2.0f;
py = 0;
}
}else{ // always considered vertical texture
w = (tex.getWidth()*scaledH)/tex.getHeight();
h = scaledH;
px = (scaledW-w)/2.0f;
py = 0;
}
if(scaledW*zoom >= 90.0f){
// background
ofSetColor(34,34,34);
ofDrawRectangle(originX,originY,scaledW-2,scaledH+(footerH/zoom));
// texture
ofSetColor(255);
tex.draw(px+originX,py+originY,w-2,h);
}
}else{
if(scaledW*zoom >= 90.0f){
// background
ofSetColor(34,34,34);
ofDrawRectangle(originX,originY,scaledW-2,scaledH+(footerH/zoom));
}
}
} with that, Mosaic performance is back to the previous version, a lot better Do you have experience with PBO? We can try to solve this later, right now is a hacky solution, but is working perfectly, with one quirk, over texture objects, cables appear in front! No sweat, i mean, better this than loosing performance at 4 texture objects running in the same patch! |
I have looked into PBOs some time ago; don't know it well enough. Sounds like an accelerated version of pixels2texture. Anyways, it's really not a good idea to do useless pixel2texture (or vice-versa) operations. What about this ? I see void nodeObject::drawObjectContent(ofxFontStash *font, shared_ptr<ofBaseGLRenderer>& glRenderer){
glRenderer->begin();
ofPushStyle();
ofSetColor(255,0,0);
ofNoFill();
ofDrawRectangle(100,100,100,100);
glRenderer->end();
} Another (dummy?) question : Is it possible to load plugins on the GL thread so they don't interfere with it ? |
Yes, glRenderer is there exactly for the plugins, for basic drawing routines as the Is not crashing or anything, just the texture loose the reference and remain black, or with artifacts from last memory region access. Of built in texture to pixels didn't use PBO, is a heavy load CPU routine, but there is this, from an addon and included in ofxVisualProgramming: I've tested it as it is, but is not working in this particular case yet ( access from two threads ) And no, for the plugin structure as it is, i didn't see the option of loading it inside the openGL thread, but i'll search the web for some info |
If the plugin system brings a big performance loss (forcing useless GPU<-->CPU operations), is it worth having plugins ? So here, it's more about the issue of drawing textures from ImGui for previewing purposes, if I understand correctly. |
This problem is only related to "texture" nodes, basically every objects that works with image in some way, so all the other type of objects do not have problems, hence is still worth having a plugin system, even is "texture" type objects will be discarded. Probably this problem will appear in the future surface nodes #24 , but we'll see when we get there The hack with transparency is working great, performance is back at good levels, so for now it doesn't worry me, but i'm going to check this http://www.songho.ca/opengl/gl_pbo.html#unpack, to see if i find a way of optimize the code and passing from this to this and end up implementig this And that could be even the solution for the plugin problem ( not 100% sure, but... ) |
Yes, the hack is fine in terms of performance. Eventually, if we come back on this, there seems to be ways to do it by passing a function pointer callback (to |
I like the option of function pointer callback, i'll give it a try |
function pointer callback not working! same problem, the texture id is not being shared correctly so texture will not appear |
Removing the subpatches/abstraction idea, i tested something and i didn't like the multiple patches windows that will end appearing inevitably, it will lead to visual confusion due to the highly graphics nature of Mosaic ( while it works fine in PD due to the really minimal graphical style ). So leaving this option, for now at least. |
Instead of opening new windows we could "zoom into" objects to view their sub-patches. Manually mouse-zooming and/or a trigger button to zoom an object full screen. Another solution that could be great is to replace the root canvas (gui) by the child canvas, together with a sub-patch-navigation-bar like |
YES!!! great idea the navigation-bar one! Substitute the root canvas to the current one it can works perfectly. amazing, i'll add it to the todo list! |
Ok then, maybe we wait for your merge on jvcleave, and then after testing we merge the ofximgui-next changes to Mosaic master, feels right? |
Could make the switch easier for others, yes, I just hope it won't take too long. |
there is no rush |
One question, i'm trying again to draw textures from imgui and not OF, as it is now, i have checked in your repo advanced example how to load and draw one, but it seems that in order to have the right texture ID it needs to be loaded in the ImGui gui? doing just this: ImGui::Image((ImTextureID)(uintptr_t)static_cast<ofTexture *>(_outletParams[0])->getTextureData().textureID, ImVec2(scaledObjW, scaledObjH)); will result into this: can you point me in some direction? |
It looks like the texture ID is overwritten by the fontatlas texture. Is your texture correct if you draw it in OF (in a liverpatcher...) ? I guess you already load the texture after loading the custom fonts ? |
Yes, the texture is loaded with the object, in this case the video viewer, so always after the custom fonts ( loaded in the Mosaic setup ) And yes, drawing the texture in OF works perfect ( as is working now in all the image objects ) |
I'll have a look later, I think currently ofxImGui needs to own the textures, so it's probably grabbing the texID in GLFW "namespace", not the OF GPU "namespace". What happens when there's a 2nd OF textureID ? |
Ok, found the issue. When loading textures trough ofxImGui, it disables ARBTex, copies the texture internally (taking ownership of it). Ownership is not particularly needed, you can render your own texture, but the TexID needs to remain allocated until the end of the frame (no problem here).
Does |
Fantastic!!! I'm going to test it right now, thanks! ImGui::Image() worked with my branch, yes |
Ok, I guess the legacy branch uses OF as renderer backend... otherwise I might have stripped something needed. Checking. Better: (also possible with texture instead of fbo)
|
I'm still testing it, the image now is working fine, but i'm seeing some jittering on texture objects ( still image objects works completely fine ), the video framerate is jumpy, so i'll dig a little deeper, i'll let you know how is going |
…supported by ImGui. Thanks to d3cod3 for reporting this: d3cod3/Mosaic#17
With the latest changes that I pushed, single clicks don't work correctly on the ImGui node objects, no idea why. Edit: ImGui has done some changes in the IO API, introducing some kind of priority routing that lets widgets catch exclusive mouse access... I fear that this breaks the nodal implementation as we're calling multiple times Example: // This works (standalone ofxImGui)
ImGui::Button("#");
if(ImGui::IsItemActivated()){
ImGui::SameLine();ImGui::Text("Activated!");
} While here the condition is never triggered: Edit2: Mosaic-Engine-Tester also works correctly, so again, I suspect the new event ownership API to break some functions where Mosaic adds custom functionality to the node canvas... |
Hey, i have been afk, i'm checking right now the issue, yes, it stops working and it seems as you say it, i'm going to take a deep dive in the imgui_node_canvas file and come back with a solution... or not... Edit1: i've managed to solve some basic stuff, click on nodes menus and dragging from the header, removing Edit2: |
Yes, the nodes are a big mess and I don't understand what's wrong. Some of the broken items can be (semi-)triggered using a double-click. |
It seems like this line ( in ofxVisualProgramming setup ): |
That line should do absolutely nothing: it sets the current context to the current context. I just tested |
With this, ofxVP compiles and works, but not yet Mosaic ... b543a77 |
Ok, but there has to be something because the Mosaic theme was not loading with |
Ok, I found it, we're mixing the new master/slave shared-context setup with a custom shared gui instance, confusing ofxImGui (see warning messages about incorrect orchestration of begin/end calls). So we need to clean up some old code. Edit: As for the theme, it can to be set like you did, or ideally set the theme and fonts before calling |
YES!!!! b543a77 solved it!!! Now it's working fine! Edit1: I'm going to check the |
Ok, i've checked Mosaic/ofxVisualProgramming theme and font loading, it is the same as the Now it's working everything fine Just uploaded last changes on Mosaic and ofxVisualProgramming, compiling and running fine on macOS, next station, try it on linux... |
Merged, thanks ! For fixing this correctly, we'd need to remove the |
…ew ofxImGui API. BREAKING : setup() doesn't take a Gui argument anymore ! d3cod3/Mosaic#17
…ew ofxImGui API. BREAKING : setup() doesn't take a Gui argument anymore ! #17
I pushed some commits to fix this properly, see note about breaking changes. Edit: I'm compiling Mosaic with the following defines, You don't need to set them but I think it's the best configuration for Mosaic. defs = defs.concat(['OFXIMGUI_GLFW_EVENTS_REPLACE_OF_CALLBACKS=1']); // Replace GFLW callbacks (Default value)
defs = defs.concat(['OFXIMGUI_GLFW_FIX_MULTICONTEXT_PRIMARY_VP=0']); // Disable multicontext tweaks
defs = defs.concat(['OFXIMGUI_GLFW_FIX_MULTICONTEXT_SECONDARY_VP=0']); // Disable multicontext tweaks (bis) |
OK, i'm compiling with the last commits, and your suggested defs, i'll test it on linux and windows too, and i'll come back with some results |
A small hotfix for linux compiling |
Thanks, merged ;) |
The text was updated successfully, but these errors were encountered: