Refactor OpenGL window handling and update project output type to Library

This commit is contained in:
moonpower 2025-04-09 05:23:46 +03:00
parent a59234f5ca
commit 330ea68174
5 changed files with 28 additions and 15 deletions

0
distribution/macos/create_app_bundle.sh Normal file → Executable file
View File

View File

@ -65,8 +65,8 @@ namespace Ryujinx.Headless.SDL2.OpenGL
// Ensure we share our contexts. // Ensure we share our contexts.
SetupOpenGLAttributes(true, GraphicsDebugLevel.None); SetupOpenGLAttributes(true, GraphicsDebugLevel.None);
IntPtr windowHandle = SDL_CreateWindow("Ryujinx background context window", 0, 0, 1, 1, SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL_WindowFlags.SDL_WINDOW_HIDDEN); IntPtr windowHandle = SDL_GL_GetCurrentWindow();
IntPtr context = SDL_GL_CreateContext(windowHandle); IntPtr context = SDL_GL_GetCurrentContext();
GL.LoadBindings(new OpenToolkitBindingsContext()); GL.LoadBindings(new OpenToolkitBindingsContext());

View File

@ -34,11 +34,13 @@ using Silk.NET.Vulkan;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
using ConfigGamepadInputId = Ryujinx.Common.Configuration.Hid.Controller.GamepadInputId; using ConfigGamepadInputId = Ryujinx.Common.Configuration.Hid.Controller.GamepadInputId;
using ConfigStickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId; using ConfigStickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;
using Key = Ryujinx.Common.Configuration.Hid.Key; using Key = Ryujinx.Common.Configuration.Hid.Key;
using static SDL2.SDL;
namespace Ryujinx.Headless.SDL2 namespace Ryujinx.Headless.SDL2
{ {
@ -100,6 +102,18 @@ namespace Ryujinx.Headless.SDL2
.WithNotParsed(errors => errors.Output()); .WithNotParsed(errors => errors.Output());
} }
[UnmanagedCallersOnly(EntryPoint = "external_main")]
public static int ExternalMain(IntPtr rawWindow, IntPtr rawGlContext, int argc, IntPtr argv)
{
Console.WriteLine("external_main: host provided window: " + rawWindow);
Console.WriteLine("external_main: host provided GL context: " + rawGlContext);
SDL_GL_MakeCurrent(rawWindow, rawGlContext);
Main(new string[0]);
return 0;
}
private static InputConfig HandlePlayerConfiguration(string inputProfileName, string inputId, PlayerIndex index) private static InputConfig HandlePlayerConfiguration(string inputProfileName, string inputId, PlayerIndex index)
{ {
if (inputId == null) if (inputId == null)
@ -354,8 +368,8 @@ namespace Ryujinx.Headless.SDL2
{ {
if (option.GraphicsBackend == GraphicsBackend.OpenGl) if (option.GraphicsBackend == GraphicsBackend.OpenGl)
{ {
option.GraphicsBackend = GraphicsBackend.Vulkan; //option.GraphicsBackend = GraphicsBackend.Vulkan;
Logger.Warning?.Print(LogClass.Application, "OpenGL is not supported on macOS, switching to Vulkan!"); Logger.Warning?.Print(LogClass.Application, "OpenGL is not supported on macOS, switching to Vulkan!"); // fuck you!
} }
} }
@ -507,9 +521,7 @@ namespace Ryujinx.Headless.SDL2
private static WindowBase CreateWindow(Options options) private static WindowBase CreateWindow(Options options)
{ {
return options.GraphicsBackend == GraphicsBackend.Vulkan return new OpenGLWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursorMode);
? new VulkanWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursorMode)
: new OpenGLWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursorMode);
} }
private static IRenderer CreateRenderer(Options options, WindowBase window) private static IRenderer CreateRenderer(Options options, WindowBase window)

View File

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers> <RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<OutputType>Exe</OutputType> <OutputType>Library</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Version>1.0.0-dirty</Version> <Version>1.0.0-dirty</Version>
<DefineConstants Condition=" '$(ExtraDefineConstants)' != '' ">$(DefineConstants);$(ExtraDefineConstants)</DefineConstants> <DefineConstants Condition=" '$(ExtraDefineConstants)' != '' ">$(DefineConstants);$(ExtraDefineConstants)</DefineConstants>
@ -16,7 +16,7 @@
<PackageReference Include="Ryujinx.Graphics.Nvdec.Dependencies" /> <PackageReference Include="Ryujinx.Graphics.Nvdec.Dependencies" />
</ItemGroup> </ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="$([MSBuild]::IsOSPlatform('OSX'))"> <Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="$([MSBuild]::IsOSPlatform('OSX')) and '$(OutputType)'=='Exe'">
<Exec Command="codesign --entitlements '$(ProjectDir)..\..\distribution\macos\entitlements.xml' -f --deep -s $(SigningCertificate) '$(TargetDir)$(TargetName)'" /> <Exec Command="codesign --entitlements '$(ProjectDir)..\..\distribution\macos\entitlements.xml' -f --deep -s $(SigningCertificate) '$(TargetDir)$(TargetName)'" />
</Target> </Target>
@ -64,9 +64,9 @@
<ApplicationIcon>..\Ryujinx\Ryujinx.ico</ApplicationIcon> <ApplicationIcon>..\Ryujinx\Ryujinx.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(RuntimeIdentifier)' != ''"> <PropertyGroup Condition="'$(OutputType)'=='Exe' and '$(RuntimeIdentifier)' != ''">
<PublishSingleFile>true</PublishSingleFile> <PublishSingleFile>true</PublishSingleFile>
<PublishTrimmed>true</PublishTrimmed> <PublishTrimmed>true</PublishTrimmed>
<TrimMode>partial</TrimMode> <TrimMode>partial</TrimMode>
</PropertyGroup> </PropertyGroup>
</Project> </Project>

View File

@ -142,6 +142,7 @@ namespace Ryujinx.Headless.SDL2
} }
iconStream.Close(); iconStream.Close();
unsafe unsafe
{ {
@ -184,7 +185,7 @@ namespace Ryujinx.Headless.SDL2
FullscreenFlag = SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP; FullscreenFlag = SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
} }
WindowHandle = SDL_CreateWindow($"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}", SDL_WINDOWPOS_CENTERED_DISPLAY(DisplayId), SDL_WINDOWPOS_CENTERED_DISPLAY(DisplayId), Width, Height, DefaultFlags | FullscreenFlag | GetWindowFlags()); WindowHandle = SDL_GL_GetCurrentWindow();
if (WindowHandle == IntPtr.Zero) if (WindowHandle == IntPtr.Zero)
{ {