FNA-XNA / FNA3D

FNA3D - 3D Graphics Library for FNA
http://fna-xna.github.io/
Other
287 stars 48 forks source link

Add support for multiple windows (for real) #133

Closed flibitijibibo closed 2 years ago

flibitijibibo commented 3 years ago

FNA3D_SwapBuffers has a parameter for a window handle...

https://github.com/FNA-XNA/FNA3D/blob/master/include/FNA3D.h#L532

... but even though it dates all the way back to the original IGLDevice, it doesn't actually do much other than validate.

Like much of what FNA3D supports and doesn't support, it roots back to OpenGL. You can hypothetically have a shared context and blit a faux-backbuffer to multiple window surfaces, but it's a whole lot of MakeCurrent calls and, assuming it worked (it absolutely would not), would be horrifically slow. So I included the parameter to be complete but in reality it doesn't do anything.

We have Vulkan and Direct3D11 now, and both can absolutely do this with no problems. The important detail is how we support it. The easiest way is via the following:

Vulkan unconditionally has a faux-backbuffer for various reasons, D3D11's is optional but it wouldn't be hard to unconditionally have one the moment it sees two or more windows. We will need to specify that the BackBufferWidth/Height values in PresentationParameters should be set to the maximum size needed across all windows, because as long as you do that you can use the src/dest parameters of SwapBuffers to ensure you're rendering the correct size for each swapchain. I'm hesitant to take the SwapchainRenderTarget idea from MonoGame because it would mean exposing that whole component of the renderer, which leaves OpenGL a little too far behind the other renderers. Plus, once you have a single device for multiple windows the device "backbuffer" basically becomes that target anyway...

This is a pretty high priority because developers need this for their editors; the GameMaker team have expressed interest in this (and have been giving this a try over here) and I've received requests for this from other studios as well.

thatcosmonaut commented 3 years ago

Got an upcoming SG2 release this December but I'll take a crack at implementing this for Vulkan after that. If someone wants to write a quick and dirty FNA app for me to test this behavior that would be great for me!

flibitijibibo commented 2 years ago

Vulkan support is in, D3D11 should be able to model its support like VK does. We should let YoYo try this out and get feedback. CLag will probably want to see this too.

flibitijibibo commented 2 years ago

Forgot to link to the Vulkan commit... this should be used as a reference for D3D11 (don't worry, it will not be nearly as complicated):

https://github.com/FNA-XNA/FNA3D/commit/c588093d62f18099e961b219a1d436f1eb81d6d3

flibitijibibo commented 2 years ago

D3D11: https://github.com/FNA-XNA/FNA3D/commit/5fe609faf9966507c2a0b0f7c70d685b04b4c418