mosra / magnum

Lightweight and modular C++11 graphics middleware for games and data visualization
https://magnum.graphics/
Other
4.77k stars 439 forks source link

Multi-window support in Platform::Application classes #124

Open mosra opened 8 years ago

mosra commented 8 years ago

As requested by @LB--, it would be great to have multi-window support in the application classes (two windows sharing the same GL context). I have two and half mutually incompatible ideas how to handle it and it would be great to hear some opinions on these:

LB-- commented 8 years ago

I definitely do not like option 2 - it feels really awkward to both have a class for the main window and then just a set of arbitrary functions for other windows.

I like both option 1 and option 3 - is there maybe some way to combine them? It makes sense to have one Application instance and multiple Window instances - maybe we could take advantage of multiple inheritance somehow? For example, maybe MyApplication can inherit from both Platform::Application and Platform::Window, which would make it very easy to update existing code (just inherit Platform::Window to fix all or most compilation errors) and also allow for additional windows to have their own class by only inheriting Platform::Window and thus keep only one application instance.

mosra commented 8 years ago

Maybe I wasn't very clear: option 3 won't involve any backwards-incompatible changes for the user. The Platform::Application gets split into Platform::ApplicationWindow and Platform::Application, but Platform::Application: would inherit from Platform::ApplicationWindows so the default behavior stays the same -- when you instantiate an application, you get also one window by default (because it makes sense to do so).

I guess that's the cleanest option, then :)

LB-- commented 8 years ago

Ah, I see - yes, option 3 sounds the best then :)

mosra commented 8 years ago

Because other tasks got more priority recently, I'm not able to work on this right now. The in-progress implementation was pushed into multiwindow branch, a few crucial pieces are still missing.

LB-- commented 8 years ago

No worries :)

staticfloat commented 8 years ago

Any update on this? I'm currently using Magnum to do realtime plotting of large amounts of data for scientific research (probably not something you expected Magnum to be used for, but such is life!) and it'd be very useful to have multiple windows available to a process. My solution right now is to have multiple processes that communicate the data to eachother with zmq, but that's certainly more work (for me) than just having multiple windows.

mosra commented 8 years ago

I'll try to look into it this week. Because such code is hardly testable in an automatic manner, I wanted to create also some example for it to verify usability of the APIs.

mosra commented 8 years ago

168 now contains a WIP implementation. There are still some things to iron out, will merge once all boxes are ticked.

mosra commented 5 years ago

For the record, random internet info that proved to be very useful recently when making a two-window app on Windows run 60 FPS and not 30:

In particular:

LB-- commented 5 years ago

I wonder what happens when two windows are created on different monitors and one of the monitors has a different refresh rate? I have such a setup myself, it'll be interesting to see which one it considers to be the vsync one.

mosra commented 5 years ago

I have no idea, frankly :) If one is let's say 60 Hz and the other is 90 Hz, then rendering at 90 Hz would make the 60 Hz display stutter every second frame, if rendering at 60 Hz, the 90 Hz would stutter every frame.

williamjcm commented 5 years ago

I have a 75Hz VGA monitor, but sadly, the only two laptops I own that have a VGA connector can't be used for testing. :/

BoyeGuillaume commented 4 years ago

Hello, and thank you for quick response on issue #426.

As said in this issue, I have been working with Magnum library for an application and I need to use multiple windows interface. I have made a interface bypassing the Sdl2Application class, using directly the SDL APIs. When my software continue after my windows creation and the openGL context configuration and creation, I have got GL::Context::current(): no current context error raised by the CORRADE_ASSERT, within Context.cpp line 560. I wonder how to link the SDL library with the Magnum ones using the Platform::GLContext.

Is it possible then to get only one openGL context and switching between multiples windows, as if we were in normal SDL APIs implementation like in the forum https://stackoverflow.com/questions/22227811/sdl2-and-opengl-functions-with-two-windows

mosra commented 4 years ago

You have two options:

Hope this helps! :)

BoyeGuillaume commented 4 years ago

Thank you

visigoth commented 2 years ago

i couldn't find stuff in the docs about this: if multi-window support is still NYI, what exactly is a Screen in Magnum? is it just a unique viewport that is to be drawn within the application window?

mosra commented 2 years ago

@visigoth you mean this, right? The docs are quite lacking there, sorry for that.

It allows the application to switch between independent ... uhh, screens, (such as a loading screen, settings screen or pause screen) inside a single window, and redirect events to just one of them at a time without the application logic having to manage that via giant if cascades on its own.