Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/FNA-XNA/FNA
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirsario committed Mar 2, 2022
2 parents 5c516e5 + 74bba92 commit 81148b7
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 51 deletions.
26 changes: 25 additions & 1 deletion src/DrawableGameComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

#region Using Statements
using System;

using Microsoft.Xna.Framework.Graphics;
#endregion

namespace Microsoft.Xna.Framework
Expand Down Expand Up @@ -97,7 +99,20 @@ public override void Initialize()
if (!_initialized)
{
_initialized = true;
LoadContent();

IGraphicsDeviceService graphicsDeviceService = (IGraphicsDeviceService)
Game.Services.GetService(typeof(IGraphicsDeviceService));
if (graphicsDeviceService != null)
{
if (graphicsDeviceService.GraphicsDevice != null)
{
LoadContent();
}
else
{
graphicsDeviceService.DeviceCreated += OnDeviceCreated;
}
}
}
}

Expand All @@ -116,6 +131,15 @@ protected override void Dispose(bool disposing)

#endregion

#region Private Methods

private void OnDeviceCreated(object sender, EventArgs e)
{
LoadContent();
}

#endregion

#region Public Virtual Methods

public virtual void Draw(GameTime gameTime)
Expand Down
11 changes: 11 additions & 0 deletions src/FNAPlatform/FNAPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,18 @@ static FNAPlatform()
"1"
);
}
if (args.TryGetValue("nukesteaminput", out arg) && arg == "1")
{
Environment.SetEnvironmentVariable(
"FNA_NUKE_STEAM_INPUT",
"1"
);
}

CreateWindow = SDL2_FNAPlatform.CreateWindow;
DisposeWindow = SDL2_FNAPlatform.DisposeWindow;
ApplyWindowChanges = SDL2_FNAPlatform.ApplyWindowChanges;
ScaleForWindow = SDL2_FNAPlatform.ScaleForWindow;
GetWindowBounds = SDL2_FNAPlatform.GetWindowBounds;
GetWindowResizable = SDL2_FNAPlatform.GetWindowResizable;
SetWindowResizable = SDL2_FNAPlatform.SetWindowResizable;
Expand Down Expand Up @@ -193,6 +201,9 @@ static FNAPlatform()
);
public static readonly ApplyWindowChangesFunc ApplyWindowChanges;

public delegate void ScaleForWindowFunc(IntPtr window, bool invert, ref int w, ref int h);
public static readonly ScaleForWindowFunc ScaleForWindow;

public delegate Rectangle GetWindowBoundsFunc(IntPtr window);
public static readonly GetWindowBoundsFunc GetWindowBounds;

Expand Down
114 changes: 75 additions & 39 deletions src/FNAPlatform/SDL2_FNAPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ internal static class SDL2_FNAPlatform

private static bool SupportsGlobalMouse;

// For iOS high dpi support
private static int RetinaWidth;
private static int RetinaHeight;

#endregion

#region Game Objects
Expand Down Expand Up @@ -142,6 +138,28 @@ out prevUserData
SDL.SDL_HintPriority.SDL_HINT_OVERRIDE
);

// Are you even surprised this is necessary?
if (Environment.GetEnvironmentVariable("FNA_NUKE_STEAM_INPUT") == "1")
{
SDL.SDL_SetHintWithPriority(
"SDL_GAMECONTROLLER_IGNORE_DEVICES",
"0x28DE/0x11FF",
SDL.SDL_HintPriority.SDL_HINT_OVERRIDE
);
SDL.SDL_SetHintWithPriority(
"SDL_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT",
"",
SDL.SDL_HintPriority.SDL_HINT_OVERRIDE
);

// This should be redundant, but who knows...
SDL.SDL_SetHintWithPriority(
"SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD",
"0",
SDL.SDL_HintPriority.SDL_HINT_OVERRIDE
);
}

// Built-in SDL2 command line arguments
string arg;
if (args.TryGetValue("glprofile", out arg))
Expand Down Expand Up @@ -195,19 +213,31 @@ out prevUserData
SDL.SDL_INIT_HAPTIC
);

string videoDriver = SDL.SDL_GetCurrentVideoDriver();

/* A number of platforms don't support global mouse, but
* this really only matters on desktop where the game
* screen may not be covering the whole display.
*/
if ( OSVersion.Equals("Windows") ||
OSVersion.Equals("Mac OS X") ||
SDL.SDL_GetCurrentVideoDriver() == "x11" )
{
SupportsGlobalMouse = true;
}
else
SupportsGlobalMouse = ( OSVersion.Equals("Windows") ||
OSVersion.Equals("Mac OS X") ||
videoDriver.Equals("x11") );

/* High-DPI is really annoying and only some platforms
* actually let you control the drawable surface.
*/
if ( !videoDriver.Equals("wayland") &&
!videoDriver.Equals("cocoa") &&
!videoDriver.Equals("uikit") )
{
SupportsGlobalMouse = false;
/* Note that this is NOT an override.
* We can be overruled, just in case.
*/
SDL.SDL_SetHintWithPriority(
SDL.SDL_HINT_VIDEO_HIGHDPI_DISABLED,
"1",
SDL.SDL_HintPriority.SDL_HINT_NORMAL
);
}

/* We need to change the Windows default here, as the
Expand Down Expand Up @@ -367,19 +397,11 @@ public static GameWindow CreateWindow()
* This is our way to communicate that it failed...
* -flibit
*/
int drawX, drawY;
FNA3D.FNA3D_GetDrawableSize(window, out drawX, out drawY);
if ( drawX == GraphicsDeviceManager.DefaultBackBufferWidth &&
drawY == GraphicsDeviceManager.DefaultBackBufferHeight )
initFlags = (SDL.SDL_WindowFlags) SDL.SDL_GetWindowFlags(window);
if ((initFlags & SDL.SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI) == 0)
{
Environment.SetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI", "0");
}
else
{
// Store the full retina resolution of the display
RetinaWidth = drawX;
RetinaHeight = drawY;
}

return new FNAWindow(
window,
Expand Down Expand Up @@ -424,16 +446,12 @@ public static void DisposeWindow(GameWindow window)
ref string resultDeviceName
) {
bool center = false;
if (Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1")
{
/* For high-DPI windows, halve the size!
* The drawable size is now the primary width/height, so
* the window needs to accommodate the GL viewport.
* -flibit
*/
clientWidth /= 2;
clientHeight /= 2;
}

/* The drawable size is now the primary width/height, so
* the window needs to accommodate the GL viewport.
* -flibit
*/
ScaleForWindow(window, false, ref clientWidth, ref clientHeight);

// When windowed, set the size before moving
if (!wantsFullscreen)
Expand Down Expand Up @@ -524,6 +542,30 @@ out mode
}
}

public static void ScaleForWindow(IntPtr window, bool invert, ref int w, ref int h)
{
int ww, wh, dw, dh;
SDL.SDL_GetWindowSize(window, out ww, out wh);
FNA3D.FNA3D_GetDrawableSize(window, out dw, out dh);
if ( ww != 0 &&
wh != 0 &&
dw != 0 &&
dh != 0 &&
(ww != dw || wh != dh) )
{
if (invert)
{
w = (int) (w * ((float) dw / (float) ww));
h = (int) (h * ((float) dh / (float) wh));
}
else
{
w = (int) (w / ((float) dw / (float) ww));
h = (int) (h / ((float) dh / (float) wh));
}
}
}

public static Rectangle GetWindowBounds(IntPtr window)
{
Rectangle result;
Expand Down Expand Up @@ -1202,13 +1244,7 @@ public static DisplayMode GetCurrentDisplayMode(int adapterIndex)
SDL.SDL_DisplayMode filler = new SDL.SDL_DisplayMode();
SDL.SDL_GetCurrentDisplayMode(adapterIndex, out filler);

if ( OSVersion.Equals("iOS") &&
Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1" )
{
// Provide the actual resolution in pixels, not points.
filler.w = RetinaWidth;
filler.h = RetinaHeight;
}
// FIXME: iOS needs to factor in the DPI!

return new DisplayMode(
filler.w,
Expand Down
12 changes: 9 additions & 3 deletions src/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,17 @@ protected virtual void Initialize()
*/
graphicsDeviceService = (IGraphicsDeviceService)
Services.GetService(typeof(IGraphicsDeviceService));
if ( graphicsDeviceService != null &&
graphicsDeviceService.GraphicsDevice != null )
if (graphicsDeviceService != null)
{
graphicsDeviceService.DeviceDisposing += (o, e) => UnloadContent();
LoadContent();
if (graphicsDeviceService.GraphicsDevice != null)
{
LoadContent();
}
else
{
graphicsDeviceService.DeviceCreated += (o, e) => LoadContent();
}
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/Graphics/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ SurfaceFormat format
{
return (((width * 32) + 7) / 8) * height;
}
else if (format == SurfaceFormat.HalfVector4)
{
return (((width * 64) + 7) / 8) * height;
}
else if (format == SurfaceFormat.Vector4)
{
return (((width * 128) + 7) / 8) * height;
}
else
{
int blockSize = 16;
Expand Down Expand Up @@ -290,6 +298,12 @@ SurfaceFormat format
{
switch (formatFourCC)
{
case 0x71: // D3DFMT_A16B16G16R16F
format = SurfaceFormat.HalfVector4;
break;
case 0x74: // D3DFMT_A32B32G32R32F
format = SurfaceFormat.Vector4;
break;
case FOURCC_DXT1:
format = SurfaceFormat.Dxt1;
break;
Expand Down
19 changes: 13 additions & 6 deletions src/GraphicsDeviceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
game.Services.RemoveService(typeof(IGraphicsDeviceManager));
game.Services.RemoveService(typeof(IGraphicsDeviceService));
if (disposing)
{
if (graphicsDevice != null)
Expand Down Expand Up @@ -397,14 +399,19 @@ List<GraphicsDeviceInformation> foundDevices

private void INTERNAL_OnClientSizeChanged(object sender, EventArgs e)
{
Rectangle size = (sender as GameWindow).ClientBounds;
GameWindow window = (sender as GameWindow);

Rectangle size = window.ClientBounds;
resizedBackBufferWidth = size.Width;
resizedBackBufferHeight = size.Height;
if (Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1")
{
resizedBackBufferWidth *= 2;
resizedBackBufferHeight *= 2;
}

FNAPlatform.ScaleForWindow(
window.Handle,
true,
ref resizedBackBufferWidth,
ref resizedBackBufferHeight
);

useResizedBackBuffer = true;
ApplyChanges();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Input/TextInputEXT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static class TextInputEXT
/// <summary>
/// This event notifies you of in-progress text composition happening in an IME or other tool
/// and allows you to display the draft text appropriately before it has become input.
/// For more information, see SDL's tutorial: https://wiki.libsdl.org/Tutorials/TextInput
/// For more information, see SDL's tutorial: https://wiki.libsdl.org/Tutorials-TextInput
/// </summary>
public static event Action<string, int, int> TextEditing;

Expand Down
2 changes: 1 addition & 1 deletion src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("22.01.0.0")]
[assembly: AssemblyVersion("22.03.0.0")]
7 changes: 7 additions & 0 deletions src/Utilities/FNADllMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ private static string GetPlatformName()
[ModuleInitializer]
public static void Init()
{
// Ignore NativeAOT platforms since they don't perform dynamic loading.
// FIXME: Is the iOS check needed?
if (!RuntimeFeature.IsDynamicCodeSupported && !OperatingSystem.IsIOS())
{
return;
}

// Get the platform and architecture
string os = GetPlatformName();
string cpu = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
Expand Down

0 comments on commit 81148b7

Please sign in to comment.