public static NativeLibraryInterface <IOpenGl> Load()
        {
            var libraryHandle = NativeLibrary.Load("opengl32");

            if (libraryHandle.IsInvalid())
            {
                throw new Exception("Unable to load opengl32.");
            }

            try
            {
                var wglGetProcAddressPtr = NativeLibrary.GetExport(libraryHandle, "wglGetProcAddress");

                if (wglGetProcAddressPtr.IsInvalid())
                {
                    throw new Exception("You are not loading OpenGL today.");
                }

                var wglGetProcAddress = Marshal.GetDelegateForFunctionPointer <ModuleLoader>(wglGetProcAddressPtr);

                return(NativeLibraryInterface.Create <IOpenGl>(
                           "OpenGl",
                           libraryHandle,
                           mn => "gl" + mn,
                           (handle, name) => GetGlProcAddress(wglGetProcAddress, handle, name)));
            }
            catch
            {
                NativeLibrary.Free(libraryHandle);
                throw;
            }
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
 public static IServiceCollection AddSqlite3(
     this IServiceCollection services,
     string dll)
 {
     return(services.AddNativeLibrary <ISqlite3>(
                _ => NativeLibraryInterface.Create <ISqlite3>(dll, ResolveName)));
 }
Esempio n. 4
0
        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));
        }
Esempio n. 5
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;
            }
        }
Esempio n. 6
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;
            }
        }
Esempio n. 7
0
 public static IServiceCollection AddStb(this IServiceCollection services)
 {
     return(services.AddNativeLibrary <IStb>(
                _ => NativeLibraryInterface.FromFile <IStb>("PiranhaNative.dll", ResolveName)));
 }
Esempio n. 8
0
 public NativeLibraryInterface <IOpenGl> macOS()
 {
     return(NativeLibraryInterface.FromFile <IOpenGl>(
                "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib",
                name => "gl" + name));
 }