Open swoolcock opened 5 years ago
We haven't yet decided a path forward as for what we are going to do about the backend, but SDL (+veldrid), OpenTK 4.0 etc. are possibilities.
While this isn't an imminent focus for us (would rather get android pushed out and continue game implementation) you are more than welcome to continuing abstracting the remaining opentk links we have, as I see this as a good move regardless of the path forward.
As part of reorganising the exposed events and bindables, I’m thinking that key and mouse events should not be part of the IWindow
interface, as we expose those through input handlers. The concrete window implementation would delegate OS input events through to the handlers automatically.
Additionally, I'm going to try to do this in bite-sized chunks or it will become a huge PR that's impossible to review. Note that there may be breaking changes along the way, but I'll make sure to keep osu! up to date with them.
Pushed WIP branch for discussion: https://github.com/swoolcock/osu-framework/tree/gamehost-refactor
After some more work on this I've successfully split the window/audio/input/video initialisations and encapsulated them mostly within the backend implementations.
As for graphics, most of the current OpenGL references are within the osu.Framework.Graphics.OpenGL
namespace, and already wrapped by the framework. I'm hesitant to redirect it through an abstraction layer, as we would essentially be cloning what Veldrid does already.
Replacing the graphics API is already going to require rewriting shaders to a degree, so I feel it would be better to just make a decision on which path we are taking and replace osuTK in one go.
Note that Veldrid uses System.Numerics
for vector primitives, and has its own RgbaFloat
and RgbaByte
colour structs.
Note: several primitive types in System.Drawing
(including Color
, Rectangle
) are a part of .NET Standard since 2.0. (https://docs.microsoft.com/en-us/dotnet/api/system.drawing?view=netstandard-2.0) Unlike other apis under System.Drawing
that actually "draw" something, they are totally platform-agnostic.
I'm not sure if Color
is serialisation-friendly for us. RectangleF
seems to be, but I'm not entirely sure we should be relying on using netstandard types for the purposes of drawing in general, and we may still need our own types that have the structure which the graphics API expects.
I've been trying to expose all two-dimensional measurements with System.Numerics.Vector2
in my SDL2 PR, even for size measurements. As for colours, we potentially have the option of going with Veldrid's RgbaFloat
which is backed by a System.Numerics.Vector4
.
Have you also considered using GLFW rather than SDL? GLFW is a more modern alternative and it's more lightweight if you only need to handle input and window stuff.
I believe GLFW does not have mainline support for mobile platforms which makes it unsuitable. Furthermore, the graphics that wraps library in use that wraps SDL2, Veldrid, allows for use of multiple Graphics backends such as DirectX and Vulkan as well as OpenGL support which is a feature that may play into optimisations into the future.
I've tried GLFW before, and while it's certainly a possibility, Veldrid has SDL2 bindings built-in and is the preferred window shell.
I have updated the issue description to better represent the current state of migration.
Proposal to decouple the framework from osuTK, eventually removing it entirely.
Color4
Vector2
etc. withSystem.Numerics
At this point it is possible to create a branch entirely removing the osuTK libraries, so that we can focus on testing and implementation parity.
Regarding
Color4
, @smoogipoo has suggested we migrate the existing type from osuTK. If this is the path we take, it may be an opportunity to migrate the functionality into a newRGBColour
orLinearColour
type to go alongside the existingSRGBColour
. This would also avoid the issue of needingusing Color4 = osu.Framework.Graphics.Colour.Color4
in the interim (since there will be a conflict in any files currently importing theosuTK.Graphics
namespace).Regarding OpenGL, the SDL
PassthroughGraphicsBackend
currently injects GL functions into the osuTKGL
class, so we should be able to do something similar in the reverse direction.Regarding
System.Numerics
, there may be some type massaging required as it does not include aMatrix2x2
orMatrix3x3
type, onlyMatrix3x2
andMatrix4x4
. We may need to use SNMatrix4x4
to represent osuTKMatrix3
, and either SNMatrix4x4
or SNMatrix3x2
to represent osuTKMatrix2
.