public static IServiceCollection AddSdl2(
            this IServiceCollection services,
            uint flags)
        {
            var isVideoEnabled = (flags & SdlInit.Video) == SdlInit.Video;

            if (isVideoEnabled && RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && File.Exists(BcmLibrary))
            {
                services.AddNativeLibrary <IBcm>(
                    _ => NativeLibraryInterface.FromFile <IBcm>(
                        BcmLibrary, name => name));
            }

            return(services
                   .AddSingleton <SdlLibrary>(
                       serviceProvider =>
            {
                var bcm = serviceProvider.GetService <IBcm>();
                bcm?.HostInit();

                var library = new SdlLibrary(flags);
                return library;
            })
                   .AddSingleton <ISdl2>(
                       serviceProvider => serviceProvider.GetRequiredService <SdlLibrary>().Library));
        }
        public NativeLibraryInterface <IOpenGl> Linux()
        {
            var lib = "/usr/lib/libGL.so";

            if (Directory.Exists(Platform.PiLibFolder))
            {
                lib = Directory.EnumerateFiles(
                    Platform.PiLibFolder,
                    "libGLESv2.so*").First();
            }
            else
            {
                lib = Platform.FindLib("libGL.so*") ?? throw new NullReferenceException();
            }

            return(NativeLibraryInterface.FromFile <IOpenGl>(
                       lib,
                       name => "gl" + name));
        }
Exemple #3
0
        public SdlLibrary(uint flags)
        {
            var path = this.CurrentPlatform() ?? throw new NullReferenceException("Failed to load SDL path.");

            _nativeLibraryInterface = NativeLibraryInterface.FromFile <ISdl2>(path, ResolveName);

            try
            {
                int result = Library.Init(flags);

                if (result != 0)
                {
                    throw new SdlException("Failed to initialize SDL: " + Library.GetError());
                }
            }
            catch
            {
                _nativeLibraryInterface.Dispose();
                throw;
            }
        }
Exemple #4
0
        public SqliteLibrary(string file)
        {
            _nativeLibraryInterface = NativeLibraryInterface.FromFile <ISqlite3>(file, ResolveName);

            try
            {
                // https://www.sqlite.org/c3ref/initialize.html
                var result = Library.Initialize();

                if (result != SqliteResult.Ok)
                {
                    throw new SqliteException(
                              "Error on sqlite3_initialize().",
                              KeyValuePair.Create(result, result.ToString()));
                }
            }
            catch
            {
                _nativeLibraryInterface.Dispose();
                throw;
            }
        }
 public static IServiceCollection AddStb(this IServiceCollection services)
 {
     return(services.AddNativeLibrary <IStb>(
                _ => NativeLibraryInterface.FromFile <IStb>("PiranhaNative.dll", ResolveName)));
 }
 public NativeLibraryInterface <IOpenGl> macOS()
 {
     return(NativeLibraryInterface.FromFile <IOpenGl>(
                "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib",
                name => "gl" + name));
 }