diff --git a/src/simulacrum-dalamud-av/MpvRender.cs b/src/simulacrum-dalamud-av/MpvRender.cs index f3a21ba..b41225a 100644 --- a/src/simulacrum-dalamud-av/MpvRender.cs +++ b/src/simulacrum-dalamud-av/MpvRender.cs @@ -23,11 +23,4 @@ public static partial class MpvRender internal static partial void FreeContext(nint context); public delegate void MpvRenderUpdateCallback(nint ctx); - - [StructLayout(LayoutKind.Sequential)] - public struct MpvRenderParam - { - public int Type; - public nint Data; - } } \ No newline at end of file diff --git a/src/simulacrum-dalamud-av/MpvRenderContext.cs b/src/simulacrum-dalamud-av/MpvRenderContext.cs index 8f3295f..8b9fd59 100644 --- a/src/simulacrum-dalamud-av/MpvRenderContext.cs +++ b/src/simulacrum-dalamud-av/MpvRenderContext.cs @@ -1,13 +1,23 @@ -namespace Simulacrum.AV; +using System.Runtime.CompilerServices; + +namespace Simulacrum.AV; public class MpvRenderContext : IDisposable { private nint _context; - public MpvRenderContext(MpvHandle handle) + public unsafe MpvRenderContext(MpvHandle handle) { - var result = MpvRender.CreateContext(_context, handle._handle, ReadOnlySpan.Empty); - MpvException.ThrowMpvError(result); + Span contextParams = stackalloc MpvRenderParam[2]; + + var apiType = "sw"u8.ToArray().AsSpan(); + fixed (byte* apiTypePtr = apiType) + { + contextParams[0] = new MpvRenderParam { Type = MpvRenderParamType.ApiType, Data = (nint)apiTypePtr }; + + var result = MpvRender.CreateContext(_context, handle._handle, contextParams); + MpvException.ThrowMpvError(result); + } } private void ReleaseUnmanagedResources() diff --git a/src/simulacrum-dalamud-av/MpvRenderParam.cs b/src/simulacrum-dalamud-av/MpvRenderParam.cs new file mode 100644 index 0000000..3628f5e --- /dev/null +++ b/src/simulacrum-dalamud-av/MpvRenderParam.cs @@ -0,0 +1,10 @@ +using System.Runtime.InteropServices; + +namespace Simulacrum.AV; + +[StructLayout(LayoutKind.Sequential)] +public struct MpvRenderParam +{ + public MpvRenderParamType Type; + public nint Data; +} \ No newline at end of file diff --git a/src/simulacrum-dalamud-av/MpvRenderParamType.cs b/src/simulacrum-dalamud-av/MpvRenderParamType.cs new file mode 100644 index 0000000..a0bb506 --- /dev/null +++ b/src/simulacrum-dalamud-av/MpvRenderParamType.cs @@ -0,0 +1,27 @@ +namespace Simulacrum.AV; + +// https://github.com/mpv-player/mpv/blob/665a47209869d7a0c4ea860b28910fcd6ca874c8/libmpv/render.h#L171 +public enum MpvRenderParamType +{ + Invalid, + ApiType, + OpenGLInitParams, + OpenGLFrameBufferObject, + FlipY, + Depth, + IccProfile, + AmbientLight, + X11Display, + WaylandDisplay, + AdvancedControl, + NextFrameInfo, + BlockForTargetTime, + SkipRendering, + DrmDisplay, + DrmDrawSurfaceSize, + DrmDisplayV2, + SoftwareSize, + SoftwareFormat, + SoftwareStride, + SoftwarePointer, +} \ No newline at end of file