Skip to content

Commit

Permalink
First SDL2->SDL3 pass
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Feb 5, 2025
1 parent 5fb7c7c commit 4d35735
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 31 deletions.
4 changes: 2 additions & 2 deletions docs/0:-FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _All_ other environments and runtimes are unsupported and should not be used.
## Where is the NuGet package?
FNA and its sublibraries do not use NuGet in any capacity. We _strongly_ recommend avoiding NuGet in general, and for FNA we recommend adding FNA.csproj (or FNA.Core.csproj) directly to your solution. FNA itself compiles almost instantly, and debug builds are incredibly valuable to have during development.

Any and all NuGet packages for any of our code (FNA, SDL2#, etc.) are unauthorized and should be avoided. If the package claims that we're the authors, please report the package as it is misrepresenting its authors and potentially violating the copyright license (i.e. "... must not be misrepresented as being the original software").
Any and all NuGet packages for any of our code (FNA, SDL3#, etc.) are unauthorized and should be avoided. If the package claims that we're the authors, please report the package as it is misrepresenting its authors and potentially violating the copyright license (i.e. "... must not be misrepresented as being the original software").

## What is the FNA content system?
FNA supports the XNA content pipeline for preservation reasons, but we _strongly_ recommend against using it on new projects. FNA supports loading common data formats like PNG, WAV and OGG directly, and the community maintains a few libraries for font loading and rendering. For anything more specialized you can bring in an external library or write your own processing and importing tools. Your content system does not have to be complex and there is nothing wrong with simple approaches like loading textures from PNG files.
Expand Down Expand Up @@ -74,7 +74,7 @@ The bug is that you are using VirtualBox. Please use [VMware Player](https://www
Your LD_LIBRARY_PATH is busted. You can do one of three things:

- Preserve the lib64 folder (like you're supposed to anyway) and set LD_LIBRARY_PATH to include that folder
- Delete your output's copy of libSDL2-2.0.so.0, keeping the rest of the libs next to your exe, and be sure your distribution provides the latest stable SDL release (maybe don't do this one since it's not the official build)
- Delete your output's copy of libSDL3.so.0, keeping the rest of the libs next to your exe, and be sure your distribution provides the latest stable SDL release (maybe don't do this one since it's not the official build)
- Throw the fnalibs into /usr/local/lib (definitely don't do this one)

For shipping builds, [use MonoKickstart](3:-Distributing-FNA-Games.md#gnulinux), do NOT use system dependencies!
Expand Down
4 changes: 2 additions & 2 deletions docs/1:-Setting-Up-FNA.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ We strongly recommend using Git to download and update FNA. This tutorial will g
If you are using an official zipped release of FNA, you only need to worry about step 2.

### Step 1: Clone FNA
FNA uses several Git submodules to access the source to additional libraries, such as SDL2# and FAudio. To fully download FNA, add the `--recursive` parameter to your `git clone` command:
FNA uses several Git submodules to access the source to additional libraries, such as SDL3# and FAudio. To fully download FNA, add the `--recursive` parameter to your `git clone` command:

```
git clone --recursive https://github.com/FNA-XNA/FNA
Expand All @@ -65,7 +65,7 @@ FNA uses several native libraries for various pieces of functionality, such as w

Here's what we use and why:

* SDL2: Used for window management, input, image I/O, etc.
* SDL: Used for window management, input, image I/O, etc.
* FNA3D: Only required if you use the Graphics namespace.
* FAudio: Only required if you use the Audio or Media namespaces.
* Theorafile: Only required if you use VideoPlayer.
Expand Down
4 changes: 2 additions & 2 deletions docs/2a:-Building-XNA-Games-with-FNA.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ One thing you will NOT need to recreate is the content projects. When deploying

(As an aside, if you are creating _new_ content instead of porting existing content, you should not feel pressured to use processing tools like the XNA/MonoGame content pipeline tools! It is perfectly reasonable to develop your own content system that can be designed and optimized to work well with you and your development team, and in fact that is what we recommend doing for new projects.)

Once you've remade your solution with all of your game's subprojects, add FNA.csproj into your solution. FNA, despite using many different C# wrappers, is just a single project file. This simplifies project generation and quickly gives you access to, for example, SDL2# if you need it in your game code.
Once you've remade your solution with all of your game's subprojects, add FNA.csproj into your solution. FNA, despite using many different C# wrappers, is just a single project file. This simplifies project generation and quickly gives you access to, for example, SDL3# if you need it in your game code.

Your projects' references are going to be the same as they were in XNA4, except now you will reference FNA instead of the XNA libraries.

Expand Down Expand Up @@ -46,4 +46,4 @@ Once the FNA version has been built, copy over your Content folder and native li

This exact output will be what you run on Linux and macOS. The only difference will be the native libraries in addition to `FNA.dll.config`, which should be in your output folder even if you're on Windows. `FNA.dll.config` is what remaps the native DLL names to the proper names of the native libraries on non-Windows operating systems. Aside from this, everything else should work - the C# assemblies, the Content, everything. [Push this output to a Linux/macOS box and try them out!](3:-Distributing-FNA-Games.md)

When using a developer environment on macOS, you will want to add an environment variable that sets `DYLD_LIBRARY_PATH=./osx/`, so that the IDE's runtime environment will find the fnalibs binaries.
When using a developer environment on macOS, you will want to add an environment variable that sets `DYLD_LIBRARY_PATH=./osx/`, so that the IDE's runtime environment will find the fnalibs binaries.
12 changes: 6 additions & 6 deletions docs/4:-FNA-and-Windows-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Here's an example for determining the save location at runtime:
```
using System;
using System.IO;
using SDL2;
using SDL3;
public const string GameName = "flibitGame";
public static readonly string SaveDirectory = GetSaveDirectory();
Expand All @@ -124,7 +124,7 @@ private static string GetSaveDirectory()
GameName
);
}
else if (platform.Equals("Mac OS X"))
else if (platform.Equals("macOS"))
{
string osConfigDir = Environment.GetEnvironmentVariable("HOME");
if (String.IsNullOrEmpty(osConfigDir))
Expand Down Expand Up @@ -187,7 +187,7 @@ https://wiki.libsdl.org/CategorySurface
### System.Windows.Forms
In many XNA games, there is frequent use of the `System.Windows.Forms` namespace for various operations, mostly related to window management.

We strongly recommend replacing this with SDL2 when moving to FNA. The SDL2 documentation can be found here:
We strongly recommend replacing this with SDL when moving to FNA. The SDL documentation can be found here:

https://wiki.libsdl.org/APIByCategory

Expand All @@ -196,9 +196,9 @@ Subsystems like SDL_Video, SDL_Cursor, and SDL_Clipboard should be able to provi
For example, if you want to use a messagebox:

```
#if SDL2
SDL2.SDL.SDL_ShowSimpleMessageBox(
SDL2.SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR,
#if SDL3
SDL3.SDL.SDL_ShowSimpleMessageBox(
SDL3.SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_ERROR,
title,
message,
game.Window.Handle
Expand Down
5 changes: 2 additions & 3 deletions docs/5:-FNA-Extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,12 @@ public void AssignDefaultKeys()
To use the TextInputEXT extension:
```
using Microsoft.Xna.Framework.Input;
using SDL2;
private void OnTextInput(char c)
{
if (c == (char) 22)
{
System.Console.WriteLine("PASTED: " + SDL.SDL_GetClipboardText());
System.Console.WriteLine("PASTED: " + SDL3.SDL.SDL_GetClipboardText());
}
System.Console.WriteLine("TEXT ENTERED: " + c.ToString());
}
Expand Down Expand Up @@ -433,4 +432,4 @@ while (TouchPanel.IsGestureAvailable)
PinchFinger2 = gesture.FingerId2EXT;
}
}
```
```
10 changes: 5 additions & 5 deletions docs/7:-FNA-Environment-Variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ For some reason they didn't expose a quality parameter to SaveAsJpeg, so we adde
### FNA_KEYBOARD_USE_SCANCODES
XNA keys are based on keycodes, rather than scancodes.

With SDL2, for example, you can actually pick between SDL_Keycode and SDL_Scancode, but scancodes will not be accurate to XNA4. The benefit is that scancodes will ignore "foreign" keyboard layouts, making default keyboard layouts work out of the box everywhere (unless the actual symbol for the keys matters in your game).
With SDL, for example, you can actually pick between SDL_Keycode and SDL_Scancode, but scancodes will not be accurate to XNA4. The benefit is that scancodes will ignore "foreign" keyboard layouts, making default keyboard layouts work out of the box everywhere (unless the actual symbol for the keys matters in your game).

While FNA provides the [GetKeyFromScancodeEXT](5:-FNA-Extensions.md#getkeyfromscancodeext) extension and developers are encouraged to use it, this is not a required function and users may benefit from this environment variable in the event that layouts are not checked in-game.

Expand All @@ -75,7 +75,7 @@ To use scancodes instead of keycodes, set this variable to "1" before starting t
This variable is accessible to users by passing `/usescancodes:1` as a launch option.

### FNA_GAMEPAD_NUM_GAMEPADS
XNA4 supports four controllers, per XInput's limitations. However, SDL2 gives us the ability to support more controllers when available. You can set this environment variable on/before program startup to set a controller count without modifying FNA:
XNA4 supports four controllers, per XInput's limitations. However, SDL gives us the ability to support more controllers when available. You can set this environment variable on/before program startup to set a controller count without modifying FNA:

```
Environment.SetEnvironmentVariable("FNA_GAMEPAD_NUM_GAMEPADS", "8");
Expand Down Expand Up @@ -121,10 +121,10 @@ This variable is accessible to users by passing `/backbufferscalenearest:1` as a
OpenGL contexts are very clunky and require the RGB/Depth/Stencil sizes at window creation time rather than context creation time, and cannot be reset without destroying the window and GL context. By default we play it safe and create a window with a `Depth24Stencil8` backbuffer, but if you want to optimize on this you can set this environment variable to a `DepthFormat` enum value at program startup to override our settings. For example:

```
SDL2.SDL.SDL_SetHintWithPriority(
SDL3.SDL.SDL_SetHintWithPriority(
"FNA3D_OPENGL_WINDOW_DEPTHSTENCILFORMAT",
"None",
SDL2.SDL.SDL_HintPriority.SDL_HINT_OVERRIDE
SDL3.SDL.SDL_HintPriority.SDL_HINT_OVERRIDE
);
```

Expand Down Expand Up @@ -162,4 +162,4 @@ For debug builds we save to the game folder, and for release builds we save to a
### FNA3D_VULKAN_DEVICE_LOCAL_HEAP_USAGE_FACTOR
Vulkan puts 100% of the memory management responsibilities on the application, rather than the driver. Because of this, we also have to manage memory from all of its possible locations, including memory on the "host" (CPU memory) and memory that is "device-local" (GPU memory). This distinction has a dramatic effect on the behavior of games, particularly the variations in available device-local memory, so this variable exists to emulate low-VRAM situations for debugging possible issues with the memory allocator and defragmenter.

This value can be set between 0.0 and 1.0 (exclusive), representing the percentage of VRAM that you want to restrict the FNA3D device to. Note that this is _very_ much a developer-only tool, do not use this unless you're trying to diagnose Vulkan memory allocation bugs!
This value can be set between 0.0 and 1.0 (exclusive), representing the percentage of VRAM that you want to restrict the FNA3D device to. Note that this is _very_ much a developer-only tool, do not use this unless you're trying to diagnose Vulkan memory allocation bugs!
4 changes: 2 additions & 2 deletions docs/8:-Contributing-to-FNA.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ A major rule for FNA is that we do NOT fork external libraries! Anything we chan

The sources can be found here:

- [SDL2](https://github.com/libsdl-org/SDL)
- [SDL](https://github.com/libsdl-org/SDL)
- [FNA3D](https://github.com/FNA-XNA/FNA3D)
- [FAudio](https://github.com/FNA-XNA/FAudio)
- [Theorafile](https://github.com/FNA-XNA/Theorafile)

All libraries are built with the default settings.
All libraries are built with the default settings.
14 changes: 5 additions & 9 deletions docs/appendix/Appendix-A:-NativeAOT-on-PC.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ To make your .csproj compatible with NativeAOT, add the following:
</ItemGroup>
<ItemGroup Condition="'$(OS)' != 'Windows_NT'">
<NativeLibrary Include="-lSDL2" />
<NativeLibrary Include="-lSDL3" />
<NativeLibrary Include="-lFNA3D" />
<NativeLibrary Include="-lFAudio" />
<NativeLibrary Include="-ltheorafile" />
</ItemGroup>
<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
<NativeLibrary Include="SDL2.lib" />
<NativeLibrary Include="SDL3.lib" />
<NativeLibrary Include="FNA3D.lib" />
<NativeLibrary Include="FAudio.lib" />
<NativeLibrary Include="libtheorafile.lib" />
Expand Down Expand Up @@ -62,20 +62,16 @@ The rd.xml file informs the compiler of any types it should preserve during the

Even though we're AOT-compiling the project, we still recommend dynamically linking the native libraries rather than statically linking them. Note that this does _not_ mean dynamic loading; the NativeLibrary and DirectPInvoke items in the .csproj ensure that native calls are inlined directly into the executable, rather than requiring a `dlopen` call to load the library at runtime. This is more performant and reliable than the standard .NET PInvoke system, and is only possible with AOT.

FNA3D, FAudio, and Theorafile can be linked in their entirety, but SDL2 is a special case, since some of its public APIs that are only available on particular platforms. In order to ensure we don't link with any platform-specific SDL APIs, we have written [a small program](https://gist.github.com/flibitijibibo/ff5b81326573fb60ced8ed93b6d75485) that automatically generates a list of all cross-platform functions. The NativeAOT toolchain will consume this and only link the functions listed.

If you don't want to run the program yourself, you can just download the latest list that we've generated from here: [SDLApis.txt](https://gist.github.com/TheSpydog/53ce4216a1ed5455dbb99d25ed2c6c6c). Then place the file in the same directory as the .csproj.

Finally, to actually link the fnalibs, follow these platform-specific instructions:

* **Windows:**
* Download the MSVC development build of SDL2, then use it to build the other libraries from source.
* Grab the .lib files from SDL2, FNA3D, FAudio, and Theorafile and place them in your app's .csproj directory.
* Download the MSVC development build of SDL3, then use it to build the other libraries from source.
* Grab the .lib files from SDL3, FNA3D, FAudio, and Theorafile and place them in your app's .csproj directory.
* Build the application.
* Copy the contents of `fnalibs/x64` into the generated output directory.
* **Linux:**
* NOTE: For maximum compatibility, we recommend you build using a distro with a low glibc version, like Rocky Linux 8.
* Build SDL2 from source or install the SDL2 development package from a package manager, then use it to build FNA3D, FAudio, and Theorafile from source.
* Build SDL3 from source or install the SDL3 development package from a package manager, then use it to build FNA3D, FAudio, and Theorafile from source.
* Copy all the resulting \*.so files into your LD_LIBRARY_PATH (e.g. `/usr/local/lib64`). Make sure the symversioning is preserved during the copy!
* Build the application.
* Copy the contents of `fnalibs/lib64` into the generated output directory.

0 comments on commit 4d35735

Please sign in to comment.