Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

3 changes: 1 addition & 2 deletions src/BizHawk.Client.EmuHawk/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ public CoreComm CreateCoreComm()
message => this.ModalMessageBox(message, "Warning", EMsgBoxIcon.Warning),
AddOnScreenMessage,
cfp,
prefs,
new OpenGLProvider());
prefs);
}

private void SetImages()
Expand Down
9 changes: 1 addition & 8 deletions src/BizHawk.Emulation.Common/CoreComms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ public CoreComm(
ModalMessageBoxCallback showMessage,
AddOnScreenMessageCallback notifyMessage,
ICoreFileProvider coreFileProvider,
CorePreferencesFlags prefs,
IOpenGLProvider oglProvider
CorePreferencesFlags prefs
)
{
ShowMessage = showMessage;
Notify = notifyMessage;
CoreFileProvider = coreFileProvider;
CorePreferences = prefs;
OpenGLProvider = oglProvider;
}

public ICoreFileProvider CoreFileProvider { get; }
Expand All @@ -53,10 +51,5 @@ public enum CorePreferencesFlags
/// Yeah, I put more stuff in corecomm. If you don't like it, change the settings/syncsettings stuff to support multiple "settings sets" to act like ini file sections kind of, so that we can hand a generic settings object to cores instead of strictly ones defined by the cores
/// </summary>
public CorePreferencesFlags CorePreferences { get; }

/// <summary>
/// Interface to provide OpenGL resources to the core
/// </summary>
public IOpenGLProvider OpenGLProvider { get; }
}
}
44 changes: 0 additions & 44 deletions src/BizHawk.Emulation.Common/Interfaces/IOpenGLProvider.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Analyzer Include="$(ProjectDir)../../References/BizHawk.SrcGen.SettingsUtil.dll" Private="true" />
<Reference Include="FlatBuffers.GenOutput" HintPath="$(ProjectDir)../../References/FlatBuffers.GenOutput.dll" Private="true" />
<Reference Include="Virtu" HintPath="$(ProjectDir)../../References/Virtu.dll" Private="true" />
<ProjectReference Include="$(ProjectDir)../BizHawk.Bizware.Graphics/BizHawk.Bizware.Graphics.csproj" />
<ProjectReference Include="$(ProjectDir)../BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj" />
<ProjectReference Include="$(ProjectDir)../BizHawk.Emulation.DiscSystem/BizHawk.Emulation.DiscSystem.csproj" />
<EmbeddedResource Include="Resources/**/*" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using BizHawk.Common;

using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BizHawk.Common.CollectionExtensions;
using BizHawk.Common;
using BizHawk.Common.StringExtensions;
using CollectionExtensions = BizHawk.Common.CollectionExtensions.CollectionExtensions;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this to avoid a name collision or something?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, BizHawk.Common.CollectionExtensions and System.Collections.Generic.CollectionExtensions.

@YoshiRulz YoshiRulz Jun 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cause is an explicit (non-Source Generator) backport... BY MS https://github.com/dotnet/runtime/blob/c369fd627a26b606f36e6b3cbef6f25f3c00bbac/src/libraries/Microsoft.Extensions.DependencyModel/ref/Microsoft.Extensions.DependencyModel.cs#L221-L223 -_-
which we depend on via Silk.NET, hence no collisions before adding the dep on Bizware.Graphics.
edit: dotnet/runtime#129881


namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using BizHawk.Common;

using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BizHawk.Common.CollectionExtensions;
using BizHawk.Common;
using BizHawk.Common.StringExtensions;
using CollectionExtensions = BizHawk.Common.CollectionExtensions.CollectionExtensions;

namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void Dispose()

foreach (var glContext in _glContexts)
{
_openGLProvider.ReleaseGLContext(glContext);
glContext.Dispose();
}

_glContexts.Clear();
Expand Down
23 changes: 10 additions & 13 deletions src/BizHawk.Emulation.Cores/Consoles/Nintendo/3DS/Encore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text;

using BizHawk.BizInvoke;
using BizHawk.Bizware.Graphics;
using BizHawk.Common;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
Expand Down Expand Up @@ -39,9 +40,8 @@ private static void ResetEncoreResolver()

private static Encore CurrentCore;

private readonly IOpenGLProvider _openGLProvider;
private readonly bool _supportsOpenGL43;
private readonly List<object> _glContexts = new();
private readonly List<SDL2OpenGLContext> _glContexts = new();
private readonly LibEncore.ConfigCallbackInterface _configCallbackInterface;
private readonly LibEncore.GLCallbackInterface _glCallbackInterface;
private readonly LibEncore.InputCallbackInterface _inputCallbackInterface;
Expand Down Expand Up @@ -100,8 +100,7 @@ public Encore(CoreLoadParameters<EncoreSettings, EncoreSyncSettings> lp)
_configCallbackInterface.GetFloat = GetFloatSettingCallback;
_configCallbackInterface.GetString = GetStringSettingCallback;

_openGLProvider = lp.Comm.OpenGLProvider;
_supportsOpenGL43 = _openGLProvider.SupportsGLVersion(4, 3);
_supportsOpenGL43 = OpenGLVersion.SupportsVersion(4, 3);
if (!_supportsOpenGL43/* && _syncSettings.GraphicsApi == EncoreSyncSettings.EGraphicsApi.OpenGL*/)
{
throw new PlatformNotSupportedException("OpenGL 4.3 is required, but it is not supported on this machine");
Expand All @@ -111,7 +110,7 @@ public Encore(CoreLoadParameters<EncoreSettings, EncoreSyncSettings> lp)
_glCallbackInterface.RequestGLContext = RequestGLContextCallback;
_glCallbackInterface.ReleaseGLContext = ReleaseGLContextCallback;
_glCallbackInterface.ActivateGLContext = ActivateGLContextCallback;
_glCallbackInterface.GetGLProcAddress = GetGLProcAddressCallback;
_glCallbackInterface.GetGLProcAddress = SDL2OpenGLContext.GetGLProcAddress;

_inputCallbackInterface.GetButton = GetButtonCallback;
_inputCallbackInterface.GetAxis = GetAxisCallback;
Expand Down Expand Up @@ -209,7 +208,7 @@ public Encore(CoreLoadParameters<EncoreSettings, EncoreSyncSettings> lp)

private IntPtr RequestGLContextCallback()
{
var context = _openGLProvider.RequestGLContext(4, 3, true);
var context = new SDL2OpenGLContext(4, 3, true);
_glContexts.Add(context);
var handle = GCHandle.Alloc(context, GCHandleType.Weak);
return GCHandle.ToIntPtr(handle);
Expand All @@ -218,18 +217,16 @@ private IntPtr RequestGLContextCallback()
private void ReleaseGLContextCallback(IntPtr context)
{
var handle = GCHandle.FromIntPtr(context);
_openGLProvider.ReleaseGLContext(handle.Target);
_glContexts.Remove(handle.Target);
var glContext = (SDL2OpenGLContext) handle.Target;
glContext.Dispose();
_glContexts.Remove(glContext);
handle.Free();
}

private void ActivateGLContextCallback(IntPtr context)
{
var handle = GCHandle.FromIntPtr(context);
_openGLProvider.ActivateGLContext(handle.Target);
var glContext = (SDL2OpenGLContext) GCHandle.FromIntPtr(context).Target;
glContext.MakeContextCurrent();
}

private IntPtr GetGLProcAddressCallback(string proc)
=> _openGLProvider.GetGLProcAddress(proc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ private void RefreshScreenSettings(NDSSettings settings)
ScreenSwap = settings.ScreenInvert
};

_openGLProvider.ActivateGLContext(_glContext); // SetScreenSettings will re-present the frame, so needs OpenGL context active
_glContext.MakeContextCurrent(); // SetScreenSettings will re-present the frame, so needs OpenGL context active
_core.SetScreenSettings(_console, ref screenSettings, out var w , out var h);

BufferWidth = w;
Expand Down
34 changes: 12 additions & 22 deletions src/BizHawk.Emulation.Cores/Consoles/Nintendo/NDS/MelonDS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Threading;

using BizHawk.BizInvoke;
using BizHawk.Bizware.Graphics;
using BizHawk.Common;
using BizHawk.Common.IOExtensions;
using BizHawk.Common.NumberExtensions;
Expand Down Expand Up @@ -47,13 +48,9 @@ private void LogCallback(LibMelonDS.LogLevel level, string message)
}

private readonly MelonDSGLTextureProvider _glTextureProvider;
private readonly IOpenGLProvider _openGLProvider;
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
private readonly LibMelonDS.GetGLProcAddressCallback _getGLProcAddressCallback;
private object _glContext;

private IntPtr GetGLProcAddressCallback(string proc)
=> _openGLProvider.GetGLProcAddress(proc);
private SDL2OpenGLContext _glContext;

// TODO: Probably can make these into an interface (ITouchScreen with UntransformPoint/TransformPoint methods?)
// Which case the hackiness of the current screen controls wouldn't be as bad
Expand Down Expand Up @@ -315,8 +312,7 @@ static void InitIv(Span<byte> iv, ReadOnlySpan<byte> nonce)

_logCallback = LogCallback;

_openGLProvider = CoreComm.OpenGLProvider;
_getGLProcAddressCallback = GetGLProcAddressCallback;
_getGLProcAddressCallback = SDL2OpenGLContext.GetGLProcAddress;

if (lp.DeterministicEmulationRequested)
{
Expand All @@ -333,14 +329,14 @@ static void InitIv(Span<byte> iv, ReadOnlySpan<byte> nonce)
_ => throw new InvalidOperationException($"Invalid {nameof(NDSSyncSettings.ThreeDeeRenderer)}")
};

if (!_openGLProvider.SupportsGLVersion(majorGlVersion, minorGlVersion))
if (!OpenGLVersion.SupportsVersion(majorGlVersion, minorGlVersion))
{
lp.Comm.Notify($"OpenGL {majorGlVersion}.{minorGlVersion} is not supported on this machine, falling back to software renderer");
_activeSyncSettings.ThreeDeeRenderer = NDSSyncSettings.ThreeDeeRendererType.Software;
}
else
{
_glContext = _openGLProvider.RequestGLContext(majorGlVersion, minorGlVersion, true);
_glContext = new SDL2OpenGLContext(majorGlVersion, minorGlVersion, true);
// reallocate video buffer for scaling
if (_activeSyncSettings.GLScaleFactor > 1)
{
Expand All @@ -353,13 +349,13 @@ static void InitIv(Span<byte> iv, ReadOnlySpan<byte> nonce)

if (_activeSyncSettings.ThreeDeeRenderer == NDSSyncSettings.ThreeDeeRendererType.Software)
{
if (!_openGLProvider.SupportsGLVersion(3, 1))
if (!OpenGLVersion.SupportsVersion(3, 1))
{
lp.Comm.Notify("OpenGL 3.1 is not supported on this machine, screen control options will not work.");
}
else
{
_glContext = _openGLProvider.RequestGLContext(3, 1, true);
_glContext = new SDL2OpenGLContext(3, 1, true);
}
}

Expand Down Expand Up @@ -626,7 +622,7 @@ static void InitIv(Span<byte> iv, ReadOnlySpan<byte> nonce)

if (_glContext != null)
{
_glTextureProvider = new(this, _core, () => _openGLProvider.ActivateGLContext(_glContext));
_glTextureProvider = new(this, _core, () => _glContext.MakeContextCurrent());
_serviceProvider.Register<IVideoProvider>(_glTextureProvider);
RefreshScreenSettings(_settings);
}
Expand Down Expand Up @@ -788,10 +784,7 @@ private static LibMelonDS.Buttons GetButtons(IController c)

protected override LibWaterboxCore.FrameInfo FrameAdvancePrep(IController controller, bool render, bool rendersound)
{
if (_glContext != null)
{
_openGLProvider.ActivateGLContext(_glContext);
}
_glContext?.MakeContextCurrent();

var isTracing = Tracer?.IsEnabled() ?? false;
_core.SetTraceCallback(isTracing ? _traceCallback : null, _settings.GetTraceMask());
Expand Down Expand Up @@ -840,11 +833,8 @@ public override void Dispose()
_frameThreadStartEvent.Dispose();
_frameThreadEndEvent.Dispose();

if (_glContext != null)
{
_openGLProvider.ReleaseGLContext(_glContext);
_glContext = null;
}
_glContext?.Dispose();
_glContext = null;

_memoryCallbacks.ActiveChanged -= SetMemoryCallbacks;

Expand Down Expand Up @@ -906,7 +896,7 @@ protected override void LoadStateBinaryInternal(BinaryReader reader)
// But at least width and height will be corrected (since base LoadStateBinary overrides them)
if (_glTextureProvider != null)
{
_openGLProvider.ActivateGLContext(_glContext);
_glContext.MakeContextCurrent();
_core.PresentGL(_console, out var w , out var h);
BufferWidth = w;
BufferHeight = h;
Expand Down
Loading