From 06f0dac7d893274a7f5765f060e683b07d6b03b8 Mon Sep 17 00:00:00 2001 From: DMP9 Date: Fri, 2 Aug 2019 14:25:08 +0100 Subject: [PATCH 01/10] Adjust constructors in NativeAPI/NativeExtension --- src/Core/Silk.NET.Core/Native/NativeAPI.cs | 12 ++++++++++-- src/Core/Silk.NET.Core/Native/NativeExtension.cs | 11 ++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Core/Silk.NET.Core/Native/NativeAPI.cs b/src/Core/Silk.NET.Core/Native/NativeAPI.cs index 751dbc952b..6129f69b00 100644 --- a/src/Core/Silk.NET.Core/Native/NativeAPI.cs +++ b/src/Core/Silk.NET.Core/Native/NativeAPI.cs @@ -4,6 +4,7 @@ // of the MIT license. See the LICENSE file for details. using AdvancedDLSupport; +using AdvancedDLSupport.Loaders; using Silk.NET.Core.Loader; namespace Silk.NET.Core.Native @@ -12,7 +13,14 @@ namespace Silk.NET.Core.Native public abstract class NativeAPI : NativeLibraryBase { /// - protected NativeAPI(string path, ImplementationOptions options) : base(path, options) + protected NativeAPI + ( + string path, + ImplementationOptions options, + ILibraryLoader libLoader = null, + ISymbolLoader symLoader = null + ) + : base(path, options, libLoader, symLoader) { } @@ -20,4 +28,4 @@ protected NativeAPI(string path, ImplementationOptions options) : base(path, opt public abstract bool IsExtensionPresent(string name); } -} \ No newline at end of file +} diff --git a/src/Core/Silk.NET.Core/Native/NativeExtension.cs b/src/Core/Silk.NET.Core/Native/NativeExtension.cs index facd4f5c82..ae2f13302a 100644 --- a/src/Core/Silk.NET.Core/Native/NativeExtension.cs +++ b/src/Core/Silk.NET.Core/Native/NativeExtension.cs @@ -4,12 +4,21 @@ // of the MIT license. See the LICENSE file for details. using AdvancedDLSupport; +using AdvancedDLSupport.Loaders; namespace Silk.NET.Core.Native { public abstract class NativeExtension : NativeLibraryBase where T : NativeAPI { - protected NativeExtension(string path, ImplementationOptions options) : base(path, options) + /// + protected NativeExtension + ( + string path, + ImplementationOptions options, + ILibraryLoader libLoader = null, + ISymbolLoader symLoader = null + ) + : base(path, options, libLoader, symLoader) { } } From 5a7dd85cb224e4240a619c63c93296448e435374 Mon Sep 17 00:00:00 2001 From: DMP9 Date: Fri, 2 Aug 2019 14:25:20 +0100 Subject: [PATCH 02/10] Use our private fork of ADL --- src/Core/Silk.NET.Core/Silk.NET.Core.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Silk.NET.Core/Silk.NET.Core.csproj b/src/Core/Silk.NET.Core/Silk.NET.Core.csproj index fc74409eed..8032814d89 100644 --- a/src/Core/Silk.NET.Core/Silk.NET.Core.csproj +++ b/src/Core/Silk.NET.Core/Silk.NET.Core.csproj @@ -6,7 +6,7 @@ - + From 29c27ea6dbc6257c9fa0b2bedaf3630cf18ee1dc Mon Sep 17 00:00:00 2001 From: DMP9 Date: Fri, 2 Aug 2019 14:25:55 +0100 Subject: [PATCH 03/10] OpenAL loader --- src/OpenAL/Silk.NET.OpenAL/AL/AL.cs | 2 +- src/OpenAL/Silk.NET.OpenAL/AL/ALLoader.cs | 42 +++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/OpenAL/Silk.NET.OpenAL/AL/ALLoader.cs diff --git a/src/OpenAL/Silk.NET.OpenAL/AL/AL.cs b/src/OpenAL/Silk.NET.OpenAL/AL/AL.cs index e438e8573f..71fc0e8d3a 100644 --- a/src/OpenAL/Silk.NET.OpenAL/AL/AL.cs +++ b/src/OpenAL/Silk.NET.OpenAL/AL/AL.cs @@ -19,7 +19,7 @@ public abstract class AL : NativeAPI, IAL { /// protected AL(string path, ImplementationOptions options) - : base(path, options) + : base(path, options, ALLoader.Instance, ALLoader.Instance) { } diff --git a/src/OpenAL/Silk.NET.OpenAL/AL/ALLoader.cs b/src/OpenAL/Silk.NET.OpenAL/AL/ALLoader.cs new file mode 100644 index 0000000000..98067999e3 --- /dev/null +++ b/src/OpenAL/Silk.NET.OpenAL/AL/ALLoader.cs @@ -0,0 +1,42 @@ +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +using System; +using AdvancedDLSupport; +using AdvancedDLSupport.Loaders; + +namespace Silk.NET.OpenAL +{ + public class ALLoader : IPlatformLoader + { + [NativeSymbols(Prefix = "al")] + public interface IInternalAL + { + IntPtr GetProcAddress(string proc); + } + + private static IInternalAL _al = NativeLibraryBuilder.Default.ActivateInterface + ( + new OpenALLibraryNameContainer().GetLibraryName() + ); + + public static ALLoader Instance { get; } = new ALLoader(); + + public IntPtr LoadSymbol(IntPtr library, string symbolName) + { + return _al.GetProcAddress(symbolName); + } + + public IntPtr LoadLibrary(string path) + { + return IntPtr.Zero; + } + + public bool CloseLibrary(IntPtr library) + { + return true; + } + } +} From 66d8873ea090623cdce946a021832cd65a416fce Mon Sep 17 00:00:00 2001 From: DMP9 Date: Sat, 3 Aug 2019 15:52:36 +0100 Subject: [PATCH 04/10] Start working on custom symbol loaders --- examples/Triangle/Game.cs | 12 ++++-- src/Core/BuildTools/Bind/ProfileWriter.cs | 14 ++++++- src/Core/BuildTools/Common/Profile.cs | 5 +++ .../Convert/Baking/ProfileBakery.cs | 3 +- .../Baking/ProfileBakeryInformation.cs | 8 ++++ .../Baking/ProfileBakeryInformationBuilder.cs | 6 +++ ...k.NET.OpenAL.Extensions.Enumeration.csproj | 1 - src/OpenAL/Silk.NET.OpenAL/ALC/ALContext.cs | 2 +- .../Interfaces/ISilkPlatform.cs | 10 +++++ .../GlfwPlatform.cs | 7 ++++ .../Silk.NET.Windowing/SilkLoader.cs | 38 +++++++++++++++++++ 11 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 src/Windowing/Silk.NET.Windowing/SilkLoader.cs diff --git a/examples/Triangle/Game.cs b/examples/Triangle/Game.cs index 9de1866c42..11e4aaa40b 100644 --- a/examples/Triangle/Game.cs +++ b/examples/Triangle/Game.cs @@ -3,6 +3,7 @@ // You may modify and distribute Silk.NET under the terms // of the MIT license. See the LICENSE file for details. +using System; using System.Drawing; using Silk.NET.OpenGL; using Silk.NET.Windowing; @@ -48,11 +49,14 @@ public void OnLoad() { gl.ClearColor(1.0f, 0.4f, 0.3f, 1.0f); - vbo = gl.GenBuffer(1); - gl.BindBuffer((int)GLEnum.ArrayBuffer, vbo); + vbo = gl.GenBuffer(); + gl.BindBuffer(GLEnum.ArrayBuffer, vbo); - //var size = (uint)vertices.Length * sizeof(float); - //gl.BufferData((int)GLEnum.ArrayBuffer, new UIntPtr(size), vertices, (int)GLEnum.StaticDraw); + var size = (uint)vertices.Length * sizeof(float); + fixed (float* floats = vertices) + { + gl.BufferData(GLEnum.ArrayBuffer, new UIntPtr(size), floats, GLEnum.StaticDraw); + } } public void OnRender(double delta) diff --git a/src/Core/BuildTools/Bind/ProfileWriter.cs b/src/Core/BuildTools/Bind/ProfileWriter.cs index 560f72c866..069a1f469b 100644 --- a/src/Core/BuildTools/Bind/ProfileWriter.cs +++ b/src/Core/BuildTools/Bind/ProfileWriter.cs @@ -267,7 +267,12 @@ public static void WriteMixedModeClasses(this Project project, Profile profile, ); sw.WriteLine(); sw.WriteLine($" public {profile.ClassName}(string path, ImplementationOptions opts)"); - sw.WriteLine(" : base(path, opts)"); + sw.WriteLine + ( + profile.SymbolLoaderName == null + ? " : base(path, opts)" + : $" : base(path, opts, {profile.SymbolLoaderName}, {profile.SymbolLoaderName})" + ); sw.WriteLine(" {"); sw.WriteLine(" }"); sw.WriteLine(" }"); @@ -377,7 +382,12 @@ public static void WriteMixedModeClasses(this Project project, Profile profile, } sw.WriteLine($" public {name}(string path, ImplementationOptions opts)"); - sw.WriteLine(" : base(path, opts)"); + sw.WriteLine + ( + profile.SymbolLoaderName == null + ? " : base(path, opts)" + : $" : base(path, opts, {profile.SymbolLoaderName}, {profile.SymbolLoaderName})" + ); sw.WriteLine(" {"); sw.WriteLine(" }"); sw.WriteLine(" }"); diff --git a/src/Core/BuildTools/Common/Profile.cs b/src/Core/BuildTools/Common/Profile.cs index b29dd3375e..8e16c2eac9 100644 --- a/src/Core/BuildTools/Common/Profile.cs +++ b/src/Core/BuildTools/Common/Profile.cs @@ -55,6 +55,11 @@ public class Profile /// public string FunctionPrefix { get; set; } + /// + /// Gets or sets the name of the symbol loader. + /// + public string SymbolLoaderName { get; set; } + /// /// Gets or sets the name container for this profile. /// diff --git a/src/Core/BuildTools/Convert/Baking/ProfileBakery.cs b/src/Core/BuildTools/Convert/Baking/ProfileBakery.cs index 896b7a1868..e44f6c3ade 100644 --- a/src/Core/BuildTools/Convert/Baking/ProfileBakery.cs +++ b/src/Core/BuildTools/Convert/Baking/ProfileBakery.cs @@ -44,7 +44,8 @@ public static void Bake(ProfileBakeryInformation information, string folder, boo Namespace = information.Namespace, ExtensionsNamespace = information.ExtensionsNamespace, OutputFolder = information.OutputFolder, - ClassName = information.ClassName + ClassName = information.ClassName, + SymbolLoaderName = information.SymbolLoader }; profile.Projects.Add ( diff --git a/src/Core/BuildTools/Convert/Baking/ProfileBakeryInformation.cs b/src/Core/BuildTools/Convert/Baking/ProfileBakeryInformation.cs index 810d6d12b6..67a69f4903 100644 --- a/src/Core/BuildTools/Convert/Baking/ProfileBakeryInformation.cs +++ b/src/Core/BuildTools/Convert/Baking/ProfileBakeryInformation.cs @@ -52,6 +52,11 @@ public class ProfileBakeryInformation /// Gets or sets the class name for this profile. /// public string ClassName { get; set; } + + /// + /// Gets or sets the symbol loader for this profile. + /// + public string SymbolLoader { get; set; } // ReSharper disable InconsistentNaming /// @@ -64,6 +69,7 @@ public class ProfileBakeryInformation .WithName("GLES") .WithOutputFolder("OpenGL") .WithClassName("GL") + .WithSymbolLoader("Silk.NET.Windowing.SilkLoader.OpenGLES") .WithLibraries ( "OpenGLESLibraryNameContainer", @@ -89,6 +95,7 @@ public class ProfileBakeryInformation .WithName("OpenGL (Compatibility Profile)") .WithOutputFolder("OpenGL") .WithClassName("GL") + .WithSymbolLoader("Silk.NET.Windowing.SilkLoader.OpenGL") .WithLibraries ( "OpenGLLibraryNameContainer", @@ -114,6 +121,7 @@ public class ProfileBakeryInformation .WithNamespaces("Silk.NET.OpenGL", "Silk.NET.OpenGL.Extensions") .WithName("OpenGL") .WithOutputFolder("OpenGL") + .WithSymbolLoader("Silk.NET.Windowing.SilkLoader.OpenGL") .WithClassName("GL") .WithLibraries ( diff --git a/src/Core/BuildTools/Convert/Baking/ProfileBakeryInformationBuilder.cs b/src/Core/BuildTools/Convert/Baking/ProfileBakeryInformationBuilder.cs index 2e467f3255..7ee339edec 100644 --- a/src/Core/BuildTools/Convert/Baking/ProfileBakeryInformationBuilder.cs +++ b/src/Core/BuildTools/Convert/Baking/ProfileBakeryInformationBuilder.cs @@ -119,5 +119,11 @@ public ProfileBakeryInformationBuilder WithClassName(string className) Result.ClassName = className; return this; } + + public ProfileBakeryInformationBuilder WithSymbolLoader(string loader) + { + Result.SymbolLoader = loader; + return this; + } } } diff --git a/src/OpenAL/Extensions/Silk.NET.OpenAL.Extensions.Enumeration/Silk.NET.OpenAL.Extensions.Enumeration.csproj b/src/OpenAL/Extensions/Silk.NET.OpenAL.Extensions.Enumeration/Silk.NET.OpenAL.Extensions.Enumeration.csproj index a9ae45f96a..43023bba42 100644 --- a/src/OpenAL/Extensions/Silk.NET.OpenAL.Extensions.Enumeration/Silk.NET.OpenAL.Extensions.Enumeration.csproj +++ b/src/OpenAL/Extensions/Silk.NET.OpenAL.Extensions.Enumeration/Silk.NET.OpenAL.Extensions.Enumeration.csproj @@ -12,7 +12,6 @@ - diff --git a/src/OpenAL/Silk.NET.OpenAL/ALC/ALContext.cs b/src/OpenAL/Silk.NET.OpenAL/ALC/ALContext.cs index cae31f1104..abba8b1edf 100644 --- a/src/OpenAL/Silk.NET.OpenAL/ALC/ALContext.cs +++ b/src/OpenAL/Silk.NET.OpenAL/ALC/ALContext.cs @@ -19,7 +19,7 @@ public abstract class ALContext : NativeAPI, IALC { /// protected ALContext(string path, ImplementationOptions options) - : base(path, options) + : base(path, options, ALLoader.Instance, ALLoader.Instance) { } diff --git a/src/Windowing/Silk.NET.Windowing.Common/Interfaces/ISilkPlatform.cs b/src/Windowing/Silk.NET.Windowing.Common/Interfaces/ISilkPlatform.cs index 42644b9f91..d863e2ce4d 100644 --- a/src/Windowing/Silk.NET.Windowing.Common/Interfaces/ISilkPlatform.cs +++ b/src/Windowing/Silk.NET.Windowing.Common/Interfaces/ISilkPlatform.cs @@ -3,6 +3,8 @@ // You may modify and distribute Silk.NET under the terms // of the MIT license. See the LICENSE file for details. +using System; + namespace Silk.NET.Windowing.Common { /// @@ -22,5 +24,13 @@ public interface ISilkPlatform /// The initial settings this window should open with. /// An implementation of IWindow GetWindow(WindowOptions options); + + /// + /// Gets a function pointer for the given function in the given API. + /// + /// The API to which the function belongs. + /// The function name. + /// The function pointer. + IntPtr GetProcAddress(ContextAPI api, string name); } } diff --git a/src/Windowing/Silk.NET.Windowing.Desktop/GlfwPlatform.cs b/src/Windowing/Silk.NET.Windowing.Desktop/GlfwPlatform.cs index 6d3b3be454..45323c4a64 100644 --- a/src/Windowing/Silk.NET.Windowing.Desktop/GlfwPlatform.cs +++ b/src/Windowing/Silk.NET.Windowing.Desktop/GlfwPlatform.cs @@ -3,6 +3,7 @@ // You may modify and distribute Silk.NET under the terms // of the MIT license. See the LICENSE file for details. +using System; using Silk.NET.GLFW; using Silk.NET.Windowing.Common; @@ -34,5 +35,11 @@ public IWindow GetWindow(WindowOptions options) { return new GlfwWindow(options); } + + /// + public IntPtr GetProcAddress(ContextAPI api, string name) + { + return GlfwProvider.GLFW.Value.GetProcAddress(name); + } } } \ No newline at end of file diff --git a/src/Windowing/Silk.NET.Windowing/SilkLoader.cs b/src/Windowing/Silk.NET.Windowing/SilkLoader.cs new file mode 100644 index 0000000000..dd08667fc2 --- /dev/null +++ b/src/Windowing/Silk.NET.Windowing/SilkLoader.cs @@ -0,0 +1,38 @@ +// This file is part of Silk.NET. +// +// You may modify and distribute Silk.NET under the terms +// of the MIT license. See the LICENSE file for details. + +using System; +using AdvancedDLSupport.Loaders; +using Silk.NET.Windowing.Common; + +namespace Silk.NET.Windowing +{ + public class SilkLoader : IPlatformLoader + { + ContextAPI _api; + public SilkLoader(ContextAPI api) + { + _api = api; + } + + public static SilkLoader OpenGL { get; } = new SilkLoader(ContextAPI.OpenGL); + public static SilkLoader OpenGLES { get; } = new SilkLoader(ContextAPI.OpenGLES); + + public IntPtr LoadSymbol(IntPtr library, string symbolName) + { + return Silk.CurrentPlatform.GetProcAddress(_api, symbolName); + } + + public IntPtr LoadLibrary(string path) + { + return IntPtr.Zero; + } + + public bool CloseLibrary(IntPtr library) + { + return true; + } + } +} From de3c1cde2466e6c13badb9cda46ec15b4da575c5 Mon Sep 17 00:00:00 2001 From: DMP9 Date: Sat, 3 Aug 2019 15:56:16 +0100 Subject: [PATCH 05/10] Update specs --- build/binder_specifications/GLES.json | 1 + build/binder_specifications/OpenGL (Compatibility Profile).json | 1 + build/binder_specifications/OpenGL.json | 1 + 3 files changed, 3 insertions(+) diff --git a/build/binder_specifications/GLES.json b/build/binder_specifications/GLES.json index f0be97c730..fc00ee5020 100644 --- a/build/binder_specifications/GLES.json +++ b/build/binder_specifications/GLES.json @@ -81977,6 +81977,7 @@ "ClassName": "GL", "Version": null, "FunctionPrefix": "gl", + "SymbolLoaderName": null, "Names": { "Linux": "libGLESv2.so", "Windows": "libGLESv2.dll", diff --git a/build/binder_specifications/OpenGL (Compatibility Profile).json b/build/binder_specifications/OpenGL (Compatibility Profile).json index ae80050aa9..4ecd84628e 100644 --- a/build/binder_specifications/OpenGL (Compatibility Profile).json +++ b/build/binder_specifications/OpenGL (Compatibility Profile).json @@ -288881,6 +288881,7 @@ "ClassName": "GL", "Version": null, "FunctionPrefix": "gl", + "SymbolLoaderName": null, "Names": { "Linux": "libGL.so.1", "Windows": "opengl32.dll", diff --git a/build/binder_specifications/OpenGL.json b/build/binder_specifications/OpenGL.json index ce1c9b4a16..53f0ff2b24 100644 --- a/build/binder_specifications/OpenGL.json +++ b/build/binder_specifications/OpenGL.json @@ -155897,6 +155897,7 @@ "ClassName": "GL", "Version": null, "FunctionPrefix": "gl", + "SymbolLoaderName": null, "Names": { "Linux": "libGL.so.1", "Windows": "opengl32.dll", From d681a9e81e6ca89ccf93ead390641f28a3455399 Mon Sep 17 00:00:00 2001 From: DMP9 Date: Sat, 3 Aug 2019 16:03:31 +0100 Subject: [PATCH 06/10] Adjust bakery scripts --- build/binder_bakery_info/GL-All.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/build/binder_bakery_info/GL-All.json b/build/binder_bakery_info/GL-All.json index d09250ef88..2b33c9fc1d 100644 --- a/build/binder_bakery_info/GL-All.json +++ b/build/binder_bakery_info/GL-All.json @@ -35,7 +35,8 @@ "ClassName": "GLCoreLibraryNameContainer" }, "FunctionPrefix": "gl", - "ClassName": "GL" + "ClassName": "GL", + "SymbolLoader": "Silk.NET.Windowing.SilkLoader.OpenGL" }, { "Name": "OpenGL (Compatibility Profile)", @@ -73,7 +74,8 @@ "ClassName": "OpenGLLibraryNameContainer" }, "FunctionPrefix": "gl", - "ClassName": "GL" + "ClassName": "GL", + "SymbolLoader": "Silk.NET.Windowing.SilkLoader.OpenGL" }, { "Name": "GLES", @@ -96,6 +98,7 @@ "ClassName": "OpenGLESLibraryNameContainer" }, "FunctionPrefix": "gl", - "ClassName": "GL" + "ClassName": "GL", + "SymbolLoader": "Silk.NET.Windowing.SilkLoader.OpenGLES" } ] \ No newline at end of file From 7900bf24306c54d6418e074c113e9f237e577b4a Mon Sep 17 00:00:00 2001 From: DMP9 Date: Sat, 3 Aug 2019 16:06:06 +0100 Subject: [PATCH 07/10] Fix specs --- build/binder_specifications/GLES.json | 2 +- build/binder_specifications/OpenGL (Compatibility Profile).json | 2 +- build/binder_specifications/OpenGL.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/binder_specifications/GLES.json b/build/binder_specifications/GLES.json index fc00ee5020..19eeaf9fc0 100644 --- a/build/binder_specifications/GLES.json +++ b/build/binder_specifications/GLES.json @@ -81977,7 +81977,7 @@ "ClassName": "GL", "Version": null, "FunctionPrefix": "gl", - "SymbolLoaderName": null, + "SymbolLoaderName": "Silk.NET.Windowing.SilkLoader.OpenGLES", "Names": { "Linux": "libGLESv2.so", "Windows": "libGLESv2.dll", diff --git a/build/binder_specifications/OpenGL (Compatibility Profile).json b/build/binder_specifications/OpenGL (Compatibility Profile).json index 4ecd84628e..397f185374 100644 --- a/build/binder_specifications/OpenGL (Compatibility Profile).json +++ b/build/binder_specifications/OpenGL (Compatibility Profile).json @@ -288881,7 +288881,7 @@ "ClassName": "GL", "Version": null, "FunctionPrefix": "gl", - "SymbolLoaderName": null, + "SymbolLoaderName": "Silk.NET.Windowing.SilkLoader.OpenGL", "Names": { "Linux": "libGL.so.1", "Windows": "opengl32.dll", diff --git a/build/binder_specifications/OpenGL.json b/build/binder_specifications/OpenGL.json index 53f0ff2b24..d9ac7b0e95 100644 --- a/build/binder_specifications/OpenGL.json +++ b/build/binder_specifications/OpenGL.json @@ -155897,7 +155897,7 @@ "ClassName": "GL", "Version": null, "FunctionPrefix": "gl", - "SymbolLoaderName": null, + "SymbolLoaderName": "Silk.NET.Windowing.SilkLoader.OpenGL", "Names": { "Linux": "libGL.so.1", "Windows": "opengl32.dll", From fd7c0b0517dd4356006c8eee218c744e0358d457 Mon Sep 17 00:00:00 2001 From: DMP9 Date: Sat, 3 Aug 2019 16:06:13 +0100 Subject: [PATCH 08/10] Fix project references --- .../Silk.NET.OpenGL.Legacy/Silk.NET.OpenGL.Legacy.csproj | 3 ++- src/OpenGL/Silk.NET.OpenGL/Silk.NET.OpenGL.csproj | 3 ++- src/OpenGL/Silk.NET.OpenGLES/Silk.NET.OpenGLES.csproj | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/OpenGL/Silk.NET.OpenGL.Legacy/Silk.NET.OpenGL.Legacy.csproj b/src/OpenGL/Silk.NET.OpenGL.Legacy/Silk.NET.OpenGL.Legacy.csproj index 37f54e5fde..ce91f92d9a 100644 --- a/src/OpenGL/Silk.NET.OpenGL.Legacy/Silk.NET.OpenGL.Legacy.csproj +++ b/src/OpenGL/Silk.NET.OpenGL.Legacy/Silk.NET.OpenGL.Legacy.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -7,6 +7,7 @@ + diff --git a/src/OpenGL/Silk.NET.OpenGL/Silk.NET.OpenGL.csproj b/src/OpenGL/Silk.NET.OpenGL/Silk.NET.OpenGL.csproj index 37f54e5fde..ce91f92d9a 100644 --- a/src/OpenGL/Silk.NET.OpenGL/Silk.NET.OpenGL.csproj +++ b/src/OpenGL/Silk.NET.OpenGL/Silk.NET.OpenGL.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -7,6 +7,7 @@ + diff --git a/src/OpenGL/Silk.NET.OpenGLES/Silk.NET.OpenGLES.csproj b/src/OpenGL/Silk.NET.OpenGLES/Silk.NET.OpenGLES.csproj index 37f54e5fde..ce91f92d9a 100644 --- a/src/OpenGL/Silk.NET.OpenGLES/Silk.NET.OpenGLES.csproj +++ b/src/OpenGL/Silk.NET.OpenGLES/Silk.NET.OpenGLES.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 @@ -7,6 +7,7 @@ + From ac1d56c824148b987d8d3b8291aca8ebbbaf2fa3 Mon Sep 17 00:00:00 2001 From: DMP9 Date: Sat, 3 Aug 2019 17:29:36 +0100 Subject: [PATCH 09/10] This is the #22 fix --- src/Core/BuildTools/Bind/ProfileWriter.cs | 22 +++++++-------- .../Silk.NET.Core/Loader/LibraryLoader.cs | 28 +++++++++++++------ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/Core/BuildTools/Bind/ProfileWriter.cs b/src/Core/BuildTools/Bind/ProfileWriter.cs index 069a1f469b..d14af529bc 100644 --- a/src/Core/BuildTools/Bind/ProfileWriter.cs +++ b/src/Core/BuildTools/Bind/ProfileWriter.cs @@ -267,14 +267,17 @@ public static void WriteMixedModeClasses(this Project project, Profile profile, ); sw.WriteLine(); sw.WriteLine($" public {profile.ClassName}(string path, ImplementationOptions opts)"); - sw.WriteLine - ( - profile.SymbolLoaderName == null - ? " : base(path, opts)" - : $" : base(path, opts, {profile.SymbolLoaderName}, {profile.SymbolLoaderName})" - ); + sw.WriteLine(" : base(path, opts)"); sw.WriteLine(" {"); sw.WriteLine(" }"); + if (profile.SymbolLoaderName != null) + { + sw.WriteLine(); + sw.WriteLine($" static {profile.ClassName}()"); + sw.WriteLine(" {"); + sw.WriteLine($" LibraryLoader.CreateBuilder<{profile.ClassName}>({profile.SymbolLoaderName});"); + sw.WriteLine(" }"); + } sw.WriteLine(" }"); sw.WriteLine("}"); sw.WriteLine(); @@ -382,12 +385,7 @@ public static void WriteMixedModeClasses(this Project project, Profile profile, } sw.WriteLine($" public {name}(string path, ImplementationOptions opts)"); - sw.WriteLine - ( - profile.SymbolLoaderName == null - ? " : base(path, opts)" - : $" : base(path, opts, {profile.SymbolLoaderName}, {profile.SymbolLoaderName})" - ); + sw.WriteLine(" : base(path, opts)"); sw.WriteLine(" {"); sw.WriteLine(" }"); sw.WriteLine(" }"); diff --git a/src/Core/Silk.NET.Core/Loader/LibraryLoader.cs b/src/Core/Silk.NET.Core/Loader/LibraryLoader.cs index 25b89dcfbb..cdf493f2b1 100644 --- a/src/Core/Silk.NET.Core/Loader/LibraryLoader.cs +++ b/src/Core/Silk.NET.Core/Loader/LibraryLoader.cs @@ -3,8 +3,11 @@ // You may modify and distribute Silk.NET under the terms // of the MIT license. See the LICENSE file for details. +using System; +using System.Collections.Generic; using System.Reflection; using AdvancedDLSupport; +using AdvancedDLSupport.Loaders; using Silk.NET.Core.Attributes; using Silk.NET.Core.Native; @@ -16,26 +19,33 @@ public static class LibraryLoader ImplementationOptions.UseLazyBinding | ImplementationOptions.SuppressSecurity | ImplementationOptions.EnableOptimizations; - - private static readonly NativeLibraryBuilder _builder; - - static LibraryLoader() - { - _builder = new NativeLibraryBuilder(Options); - } + + private static Dictionary _builders = new Dictionary(); public static T1 Load(SearchPathContainer nameContainer) where T1 : NativeAPI { - return _builder.ActivateClass(nameContainer.GetLibraryName()); + CreateBuilder(); + return _builders[typeof(T1)].ActivateClass(nameContainer.GetLibraryName()); } public static T1 Load(T2 baseApi) where T1 : NativeExtension where T2 : NativeAPI { + CreateBuilder(); return baseApi.IsExtensionPresent(GetExtensionAttribute(typeof(T1)).Name) - ? _builder.ActivateClass(baseApi.SearchPaths.GetLibraryName()) + ? _builders[typeof(T2)].ActivateClass(baseApi.SearchPaths.GetLibraryName()) : null; } + public static void CreateBuilder(IPlatformLoader loader = null) where T1:NativeAPI + { + if (!_builders.ContainsKey(typeof(T1)) || loader != null) + { + _builders[typeof(T1)] = new NativeLibraryBuilder(Options) + .WithLibraryLoader(x => loader ?? x) + .WithSymbolLoader(x => loader ?? x); + } + } + private static ExtensionAttribute GetExtensionAttribute(MemberInfo type) { return type.GetCustomAttribute(); From 14527b4aca90f8ec7609985f4fcac77e701d00bd Mon Sep 17 00:00:00 2001 From: DMP9 Date: Sat, 3 Aug 2019 17:37:21 +0100 Subject: [PATCH 10/10] Fix a mistake in OpenAL --- src/OpenAL/Silk.NET.OpenAL/AL/AL.cs | 7 ++++++- src/OpenAL/Silk.NET.OpenAL/ALC/ALContext.cs | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/OpenAL/Silk.NET.OpenAL/AL/AL.cs b/src/OpenAL/Silk.NET.OpenAL/AL/AL.cs index 71fc0e8d3a..f344192331 100644 --- a/src/OpenAL/Silk.NET.OpenAL/AL/AL.cs +++ b/src/OpenAL/Silk.NET.OpenAL/AL/AL.cs @@ -17,9 +17,14 @@ namespace Silk.NET.OpenAL /// public abstract class AL : NativeAPI, IAL { + static AL() + { + LibraryLoader.CreateBuilder(ALLoader.Instance); + } + /// protected AL(string path, ImplementationOptions options) - : base(path, options, ALLoader.Instance, ALLoader.Instance) + : base(path, options) { } diff --git a/src/OpenAL/Silk.NET.OpenAL/ALC/ALContext.cs b/src/OpenAL/Silk.NET.OpenAL/ALC/ALContext.cs index abba8b1edf..2de459e0dd 100644 --- a/src/OpenAL/Silk.NET.OpenAL/ALC/ALContext.cs +++ b/src/OpenAL/Silk.NET.OpenAL/ALC/ALContext.cs @@ -17,9 +17,15 @@ namespace Silk.NET.OpenAL /// public abstract class ALContext : NativeAPI, IALC { + static ALContext() + { + LibraryLoader.CreateBuilder(ALLoader.Instance); + } + + /// protected ALContext(string path, ImplementationOptions options) - : base(path, options, ALLoader.Instance, ALLoader.Instance) + : base(path, options) { }