VL: Switch to Xenko MathAugust 23, 2019
In preparation for the Xenko game engine integration we decided to change the default math library of VL from SharpDX to Xenko. The decision was particularly easy since both math libraries have the same origin and most types and methods are identical. And thanks to the VL import layer it’s easy to switch out the types, without any noticeable changes for the VL user.
What you get:
- Existing VL patches will continue to work as before
- No conversion needed when working with Xenko
- Faster matrix uploads to GPU (see below)
We are (again) in luck with Xenko since it just so happened that Alexandre Mutel, who developed SharpDX, was a core developer at Xenko. We actually didn’t know that at the time we started to work on the VL core library. We chose SharpDX mainly because it was well established, complete and open source. So it was quite a nice surprise when we browsed the Xenko source code for the first time and saw that they basically use the same math code.
This section is only relevant for library developers.
Transposed Matrix Memory Layout
Xenko’s 4x4 matrices have a transposed memory layout compared to SharpDX. This is not to be confused with transposed matrix elements (M11, M12, M13 etc.), it is only relevant when doing low-level operations with memory and pointers, such as uploading them to the GPU. The big advantage of it is, that Xenko’s matrices can directly be uploaded to the GPU without the overhead of transposing them.
Changes on C# Projects
Most C# projects written for VL don’t need to be changed. Only if they use the SharpDX.Mathematics nuget to work with vectors, matrices, rectangles etc.:
- Must switch to Xenko math
- Must use the new SDK style project format
//old: using SharpDX;
//new: using Xenko.Core.Mathematics;
If you then get an error on compilation, your project might be in the old format. Upgrading is quite easy, it just involves changing the header and deleting most lines in the project file. Follow this guide or join our chat if you need help.
Please give the new version a spin and send us a report if anything doesn’t work as before. Happy calculations!