]> O.S.I.I.S - jp/vke.net.git/commitdiff
GetStreamFromPath: allow embedded ressource assembly with one dot v0.2.3-beta
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 16 Nov 2021 22:26:19 +0000 (23:26 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 16 Nov 2021 22:26:19 +0000 (23:26 +0100)
Directory.Build.props
README.md
samples/ClearScreen/README.md
samples/Triangle/README.md
samples/pbr/PbrPipeline.cs
samples/pbr/main.cs
vke/src/MemoryPool.cs
vke/src/Utils.cs

index 527f40a6426c25748fe307d1b48ccea76403ec63..8d90c98d899e18d5e84fb2f7f01d59bcc5377d7d 100644 (file)
@@ -4,7 +4,7 @@
                <RestoreAdditionalProjectSources Condition="Exists('$(SolutionDir)build\$(Configuration)\')">$(SolutionDir)build\$(Configuration)\</RestoreAdditionalProjectSources>
                <SpirVTasksReleaseVersion>0.1.45</SpirVTasksReleaseVersion>
                <SpirVTasksPackageVersion>$(SpirVTasksReleaseVersion)</SpirVTasksPackageVersion>
-               <VkeReleaseVersion>0.2.2</VkeReleaseVersion>
+               <VkeReleaseVersion>0.2.3</VkeReleaseVersion>
                <VkePackageVersion>$(VkeReleaseVersion)-beta</VkePackageVersion>
                <UseStbSharp>true</UseStbSharp>
                <UseMemoryPools>false</UseMemoryPools>
index 8808a458730208b771826b98fc87559015cf3e6a..0ffcbbcdc3350b4e8dd934b93abe223a1f9e8477 100644 (file)
--- a/README.md
+++ b/README.md
@@ -43,7 +43,6 @@ vke is in beta development stage.
 
 `vke.net` supports `netcoreapp3.0`.
 
-
 # Tutorials
 
 |                    Title                     |                    Screen shots                    |
index 3eeab4d804a50ef7703980910d95ae197747eeb1..4268d1d46fc0e476c45529edbb6d19147a0c9a50 100644 (file)
@@ -13,7 +13,7 @@ Create a new dotnet console project, and add the [vke nuget package](https://www
 ```
 # VkWindow class
 
-**vke** use [GLFW](https://www.glfw.org/) to interface with the windowing system of the OS. Derive your application from the `VkWindow` base class to start with a vulkan enabled window. **Validation** and **RenderDoc** layers loading may be control at startup with public static boolean properties from the `Instance`class.
+**vke** use [GLFW](https://www.glfw.org/) to interface with the windowing system of the OS. Derive your application from the `VkWindow` base class to start with a vulkan enabled window. **Validation** and **RenderDoc** layers loading may be control at startup with public static boolean properties from the `Instance` class.
 
 ```csharp
 class Program : VkWindow {
@@ -21,11 +21,8 @@ class Program : VkWindow {
 
     Instance.Validation = true;
 
-    using (Program vke = new Program ()) {
+    using (Program vke = new Program ())
       vke.Run ();
-    }
-  }
-}
 ```
 
 ### Vulkan Initialization
index d2bc07c5ff9fcc9f62d256c656a9e412adff3d3b..8bdcb08d246cbeb110249a4dae85375b54aa671d 100644 (file)
@@ -1,4 +1,4 @@
-# shaders
+# Shaders
 For this tutorials we'll need a `vertex` and a `fragment` shaders. Vulkan need them to be compiled into [SPIR-V](https://www.khronos.org/spir/). Install the [Vulkan Sdk](https://www.lunarg.com/vulkan-sdk/) and after building it, ensure the `VULKAN_SDK` environment variable points to its binary subdir.
 ```bash
 export VULKAN_SDK=/VulkanSDK/1.2.176.1/x86_64
index 80f02aca09c7ff2369482450d447bf64d3402067..cc2af4cd901089feaf2fdcb761e7b0ccd82614f6 100644 (file)
@@ -85,7 +85,7 @@ namespace pbrSample
                                new VkDescriptorSetLayoutBinding (1, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                new VkDescriptorSetLayoutBinding (2, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
                                new VkDescriptorSetLayoutBinding (3, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
-                               new VkDescriptorSetLayoutBinding (4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer));                             
+                               new VkDescriptorSetLayoutBinding (4, VkShaderStageFlags.Fragment, VkDescriptorType.UniformBuffer));
 
                        descLayoutTextures = new DescriptorSetLayout (Dev,
                                new VkDescriptorSetLayoutBinding (0, VkShaderStageFlags.Fragment, VkDescriptorType.CombinedImageSampler),
index 4c31ad307b7daba07250957e389bb2db7da5ba6b..a49b701d69509556df11a988d4fc160fe63cf49c 100644 (file)
@@ -145,7 +145,7 @@ namespace pbrSample {
                        } else if (GetButton (MouseButton.Right) == InputAction.Press) {
                                camera.SetZoom ((float)diffY);
                                updateViewRequested = true;
-                       }                       
+                       }
                }
 
                protected override void onKeyDown (Key key, int scanCode, Modifier modifiers) {
@@ -156,7 +156,7 @@ namespace pbrSample {
                                else
                                        curModelIndex = curModelIndex < (uint)vke.samples.Utils.GltfFiles.Length - 1 ? curModelIndex + 1 : 0;
                                reloadModel = true;
-                               break;                  
+                               break;
                        case Key.P:
                                showDebugImg = !showDebugImg;
                                queryUpdatePrefilCube = updateViewRequested = true;
index 492dd2f2d3e682a30ae48c2fd4ba611754675bc9..b5196e1a245c7142ef758c616305de60566a249d 100644 (file)
@@ -33,7 +33,7 @@ namespace vke {
                /// Return mapped memory pointer or null if not mapped.
                public IntPtr MappedData => mappedPointer;
                /// Last added resource, this is the entry element for the double linked list of ressource.
-               public Resource Last => lastResource;                                                                   
+               public Resource Last => lastResource;
 
                /// <summary>
                /// Initializes a new instance of the <see cref="T:vke.MemoryPool"/> class.
@@ -78,7 +78,7 @@ namespace vke {
 
                                        if (previous.next.poolOffset < previous.poolOffset) {
                                                limit = Size;
-                                               if (offset + resource.AllocatedDeviceMemorySize < Size) 
+                                               if (offset + resource.AllocatedDeviceMemorySize < Size)
                                                        break;
                                                offset = 0;
                                                limit = previous.next.poolOffset;
index 7e1303af80d9bc10fa46c6931fbfd257c64bfe52..c563a867af823abd5144549e8823f53b1cd0b891 100644 (file)
@@ -9,7 +9,7 @@ using System.Reflection;
 using System.Xml.Serialization;
 
 namespace Vulkan {
-       public static partial class Utils {             
+       public static partial class Utils {
                /// <summary>Throw an erro if VkResult != Success.</summary>
                public static void CheckResult (VkResult result, string errorString = "Call failed") {
             if (result != VkResult.Success)
@@ -27,34 +27,36 @@ namespace Vulkan {
                        xmlMakeTypeFieldsAsAttributes (typeof (VkDescriptorPoolSize), ref xmlAttributeOverrides);
                        return xmlAttributeOverrides;
                }
+               static bool tryFindResource (Assembly a, string resId, out Stream stream) {
+                       stream = null;
+                       if (a == null)
+                               return false;
+                       stream = a.GetManifestResourceStream (resId);
+                       return stream != null;
+               }
                /// <summary>
                /// Return a file or embedded resource stream.
                /// </summary>
                /// <returns>The stream from path.</returns>
                /// <param name="path">The file or stream path. Embedded resource path starts with '#'.</param>
                public static Stream GetStreamFromPath (string path) {
-                       Stream stream = null;
-
                        if (path.StartsWith ("#", StringComparison.Ordinal)) {
+                               Stream stream = null;
                                string resId = path.Substring (1);
-                               //first search entry assembly
-                               stream = Assembly.GetEntryAssembly ().GetManifestResourceStream (resId);
-                               if (stream != null)
+                               if (tryFindResource (Assembly.GetEntryAssembly (), resId, out stream))
                                        return stream;
-                               //if not found, search assembly named with the 1st element of the resId
-                               string assemblyName = resId.Split ('.')[0];
-                               Assembly a = AppDomain.CurrentDomain.GetAssemblies ().FirstOrDefault (aa => aa.GetName ().Name == assemblyName);
-                               if (a == null)
-                                       throw new Exception ($"Assembly '{assemblyName}' not found for ressource '{path}'.");
-                               stream = a.GetManifestResourceStream (resId);
-                               if (stream == null)
-                                       throw new Exception ("Resource not found: " + path);
-                       } else {
-                               if (!File.Exists (path))
-                                       throw new FileNotFoundException ("File not found: ", path);
-                               stream = new FileStream (path, FileMode.Open, FileAccess.Read);
+                               string[] assemblyNames = resId.Split ('.');
+                               Assembly assembly = AppDomain.CurrentDomain.GetAssemblies ().FirstOrDefault (aa => aa.GetName ().Name == assemblyNames[0]);
+                               if (assembly == null && assemblyNames.Length > 3)
+                                       assembly = AppDomain.CurrentDomain.GetAssemblies ()
+                                               .FirstOrDefault (aa => aa.GetName ().Name == $"{assemblyNames[0]}.{assemblyNames[1]}");
+                               if (assembly != null && tryFindResource (assembly, resId, out stream))
+                                       return stream;
+                               throw new Exception ("Resource not found: " + path);
                        }
-                       return stream;
+                       if (!File.Exists (path))
+                               throw new FileNotFoundException ("File not found: ", path);
+                       return new FileStream (path, FileMode.Open, FileAccess.Read);
                }
                /// <summary>Convert angle from degree to radian.</summary>
                public static float DegreesToRadians (float degrees) {
@@ -83,7 +85,7 @@ namespace Vulkan {
                        if (floats.Length > 2)
                                v.Z = floats[2];
                        if (floats.Length > 3)
-                               v.W = floats[3];            
+                               v.W = floats[3];
         }
                /// <summary>
                /// Populate a Quaternion with values from a float array
@@ -221,7 +223,7 @@ namespace Vulkan {
                     break;
 
                 case VkImageLayout.TransferSrcOptimal:
-                    // Image is a transfer source 
+                    // Image is a transfer source
                     // Make sure any reads from the image have been finished
                     imageMemoryBarrier.srcAccessMask = VkAccessFlags.TransferRead;
                     break;