Пример #1
0
        public override unsafe void LoadLibraries()
        {
            base.LoadLibraries();
            if (!(Instance is null))
            {
                throw new InvalidOperationException("Only one SilkActivity may be present throughout the whole application.");
            }

            Instance = this;
            SetupMain(SilkMarshal.DelegateToPtr(CurrentMain));
        }
Пример #2
0
    public static unsafe Func <string, nint> GetLoader(bool alwaysPresent, out nint loaderPtr, out nint ctxLoaderPtr)
    {
        var wrapper     = new nint[2];
        var theDelegate = (LoaderDelegate)Loader;

        // The wrapper array is so the delegates can use eachothers resources without having to worry about
        // modifications outside of the delegate's scope.
        wrapper[0] = loaderPtr = SilkMarshal.DelegateToPtr(theDelegate);
        wrapper[1] = ctxLoaderPtr = SilkMarshal.DelegateToPtr((ContextLoaderDelegate)((_, x) => theDelegate(x)));

        return(x => theDelegate((byte *)SilkMarshal.StringToPtr(x)));

        nint Loader(byte *x) => SilkMarshal.PtrToString((nint)x) switch
        {
            "alcIsExtensionPresent" or "alIsExtensionPresent" => alwaysPresent
                ? (nint)(delegate * unmanaged[Cdecl] < byte *, int >) & AlwaysOne
                : (nint)(delegate * unmanaged[Cdecl] < byte *, int >) & AlwaysZero,
            "alGetProcAddress" => wrapper[0],
            "alcGetProcAddress" => wrapper[1],
            "alGetEnumValue" => (nint)(delegate * unmanaged[Cdecl] < byte *, int >) & AlwaysZero,
            _ => 0
        };
    }