-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Multi-Viewports + SDL Renderer? #5835
Comments
You aren't doing anything wrong or missing something, the |
It may be a relatively easy PR to work on, if anyone is i interested in investigating it. |
I'd love to see this being addressed, because SDL_Renderer is hardware accelerated and I'd get imgui's (awesome) viewports at the same time! |
(I originally commented this on #5874 but realized it made more sense here.) TL;DR: Adding multi-viewport support to
So I started to look into adding this, and it turns out it actually might not be trivial. I started writing some advice to @Vin789 on how they might do it, then I decided to just do it myself, and then I found what might be a showstopper. Each If you want a quick copy+pastable smoke test: // Add this to the initialization of example_sdl_sdlrenderer's main
SDL_Window* window2;
SDL_Renderer* renderer2;
SDL_CreateWindowAndRenderer(300, 300, window_flags, &window2, &renderer2);
// ...
// And this to the end of the main loop
SDL_SetRenderDrawColor(renderer2, 255, 0, 0, 255);
SDL_RenderClear(renderer2);
if (SDL_RenderCopy(renderer2, (SDL_Texture*)io.Fonts->TexID, nullptr, nullptr) != 0)
SDL_Log("Error rendering texture: %s", SDL_GetError());
SDL_RenderPresent(renderer2); The second window will be blank red and the log will be spammed with errors about the texture and renderer not matching. I see the following solutions to this problem:
|
Hello @PathogenDavid, I have forwarded your message to the SDL Discord. Let's see what the SDL devs have to say on this matter :) |
Hey, I kinda wish you hadn't. My message was pretty explicitly intended to share my findings with Omar (and to save someone else time investigating in the future.) I'm capable of reaching out to the SDL developers myself and IMO it is premature to do so at this time. 2023 edit: This was a little excessively grumpy. I was pretty stressed out by life stuff at the time and I think I perceived your sharing as indirectly creating an obligation for me. Sorry about that! |
For clarification, the SDL discord is much more of just a community for learning and using SDL. There's one maintainer there, but they're not particularly active (I'm sure they're incredibly busy!). So don't worry too much about the SDL maintainers getting premature information. Thanks for the write up though! I'm sure this will be interesting to those of us who've delved into the SDL source :) |
Thanks David for investigating and thoroughly reporting those. I think the best path is to get multiple SDL_Renderer windows to support shared resources. But I also think "Put in the effort to figure out how to properly use imgui_impl_opengl3 with SDL_Renderer" should be possible to solve, maybe investigating SDL_Renderer sources we can find which states are clashing. |
If SDL_Renderer if using OpenGL, wouldn't calling this after creating the first window be enough?
|
How would that work though? AFAIK SDL_Renderer uses DX11 by default, |
@ocornut nice catch. Calling this before SDL_CreateWindow/SDL_CreateRenderer/SDL_GL_CreateContext:
Seems to works (not working after SDL_GL_CreateContext however): |
Oups sorry I must precise it's the OpenGL3 example not the SDL_Renderer example. But at least it's working fine with the additional line (mixing SDL image and ImGui + viewports). I guess for the SDL_Renderer it still need more code. |
Ok I'm stupid sorry for all these comments. My example was indeed the example_sdl_opengl3 but WITH the usage of the SDL_Renderer. So it seems that with:
@sam20908 to force the usage of opengl and :
it's working. |
@Vin789 Can you provide a complete minimal code of it working? I'm confused on the details like do I need to call |
Sure. Line 110 you need to set the path to your own image for testing. It's an updated version of main.cpp inside example_sdl_opengl3.
|
Assuming SDL_Renderer only has this sharing issue when using OpenGL and we can detect that SDL_Renderer is using OpenGL we can do perform the call ourselves; meaning with build that backend. |
Is it an issue with D3D11? I'm kind of hoping I don't have to use OpenGL + Renderer it just seems bad |
@Vin789 Thanks for that example. How is the performance for you when you use that? I hope it's around 1% CPU usage |
@sam20908 well it's look ok on the task manager (~2%) but I'm not really sure looking at this is really useful. I don't know what's your usage of ImGui but if performance is important to you I guess you should probably use specific tool to monitor Ram/CPU/GPU depending on your case. In my case I'm working on a 2D Game editor so performance in the editor himself are not my top priority. The game running in the viewport window with multi threading on the other hand is my priority, I need to keep good performance for Render Thread / Update thread (but it's not ImGui related). |
Yes, I understand, I use it to judge whether the program is running in a normal range of resource usage. If it's 10% then something is very wrong. |
The ideal situation I think still is to have it work for SDL_Renderer without needing to rely on OpenGL 3. |
Hi @PathogenDavid ! It's been nearly one year since the creation of this thread. I found some times to work again on my personal editor. I was wondering if you know if the situation changed with ImGui + SDL + Multi viewport. I'm still able to draw the main window with ImGui + SDL and others windows with ImGui. But I can't draw SDL in an other window than the main one. I guess it still the issue with the texture sharing between SDL_Renderer ? Do you know if SDL3 (I'm still on 2) improve the issue you mentioned with SDL_Renderer ? Or there is still no proper way to mix severals SDL_Window/SDL_Renderer with ImGui ? Thx for your time. Vincent |
Hey @Vin789
Sorry to say the situation has not changed.
The same check still exists in SDL 3, so I assume the answer is no. I believe the path forward is someone needs to do a deeper investigation into the various solutions I proposed and determine which are good candidates to propose to the SDL team. Alternatively though, since SDL 3 is still in flux now might be a good idea to make a more general feature request to allow either allow SDL_Renderer instances to be associated with multiple windows or to allow textures to be shared between multiple renderers. (At the time I think I was mainly concerned with finding a solution that didn't have too much of an impact on SDL, but that might be less of a concern with SDL 3.) |
I see. Thx a lot for the update. I was waiting because I had works and others stuffs to do on my project. But one of my 3D programmer friend is pushing me to use GLFW + OpenGL directly instead of the SDL. I saw that ImGui seems to have a nice backend for it (and this time it's works fine with multi viewports). So I may just jump on this. Thx again for your time. |
I don't imagine it is particularly difficult to add support for multi-window in SDL_Renderer, someone just has to do it... |
My bad I was hasty and have brain-farted, I forgot the crux of discussion was about portably supporting texture sharing across graphical contexts regardless of what backend SDL_Renderer uses. I apologize for confusion. David summed it up well above. It's mostly a problem of pushing this to SDL developer and I assume it would be a small change for them. Maybe we can setup a basic impl for them to test? |
Today I thought I would try to push this a little further, by trying to implement (broken) support in our backend so it would be easier to make missing changes to SDL. I pushed a branch: It's currently not working, because of two issues which would need work on SDL side: (1) As discussed, textures are not shared so things appears black. (2) Another unexpected issues is that SDL_Renderer doesn't seem to support a projection matrix. Seeing SDL3 progressing toward more general GPU support, I assumed SDL_Renderer was relying on this base already, but it's not since the earlier is not ready yet. So SDL_Renderer is still an API with a handful of CPU side transforms, checks etc. I would assume the natural path for SDL would be that once better GPU support is in, SDL_Renderer will take natural advantage of it, and then it might become trivial for them to add projection matrix etc. in which case it may make sense for them to extend their renderscale concept and add e.g. renderoffset, or a full blown matrix. I'll poke them about this. |
Version/Branch of Dear ImGui:
Version: 1.88
Branch: docking
Back-end/Renderer/Compiler/OS
Back-ends: imgui_impl_sdl.cpp + imgui_impl_sdlrenderer.cpp
Compiler: XXX (if the question is related to building or platform specific features)
Operating System: Windows 11
My Issue/Question:
It seems there's no officially documented way to setup mult-viewports with SDL_Renderer. I am aware that I can enable multi-viewports with SDL + OpenGL3, but I not really good with OpenGL and yet I want the hardware acceleration, so SDL_Renderer API is the best choice for me right now. I also thought about just creating the renderer, but then I wasn't sure how to render the viewports because there isn't any way shown in https://github.com/ocornut/imgui/blob/docking/examples/example_sdl_sdlrenderer/main.cpp.
If there's a way to setup multi-viewports with SDL_Renderer, LMK!
Screenshots/Video
Standalone, minimal, complete and verifiable example:
The text was updated successfully, but these errors were encountered: