From: Jean-Philippe Bruyère Date: Fri, 27 Sep 2019 01:11:40 +0000 (+0200) Subject: handle includes in SpirVTasks for emiting line of error X-Git-Tag: v0.1.21~31 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=c0ecf520da6206731e2d58897d8b290ede86930c;p=jp%2Fvke.net.git handle includes in SpirVTasks for emiting line of error --- diff --git a/SpirVTasks/CompileGLSLTask.cs b/SpirVTasks/CompileGLSLTask.cs index d6f0741..f66d959 100644 --- a/SpirVTasks/CompileGLSLTask.cs +++ b/SpirVTasks/CompileGLSLTask.cs @@ -1,13 +1,21 @@ // Copyright (c) 2019 Jean-Philippe Bruyère // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - using System; +using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.Linq; using Microsoft.Build.Framework; namespace SpirVTasks { + /// + /// Record include position and path in produced glsl file before compilation + /// + internal class IncludePosition { + public int line; //include position in final glsl file + public string path; //path to the included file + } public class IncludeFileNotFound : FileNotFoundException { public string SourceFile; @@ -37,6 +45,9 @@ namespace SpirVTasks { get; set; } + /// + /// Optional, Specify the comple glslc executable path. + /// public ITaskItem SpirVCompilerPath { get; set; @@ -49,6 +60,10 @@ namespace SpirVTasks { } volatile bool success; + //due to includes mechanic, file inclusion position has to be recorded + int currentCompiledLine = -1;//current line produced of the unified glsl file with all includes + List includesPositions = new List(); //each included file has en entry in this list + //to emit correct error location for logger. bool tryFindInclude (string include, out string incFile) { if (!string.IsNullOrEmpty (AdditionalIncludeDirectories?.ItemSpec)) { @@ -61,8 +76,10 @@ namespace SpirVTasks { incFile = ""; return false; } - - void build_source (string src, StreamWriter temp) { + /// + /// produce a single glsl file with main glsl and all its includes in the temp directory + /// + void concatenate_sources (string src, StreamWriter temp) { using (StreamReader sr = new StreamReader (File.OpenRead (src))) { int srcLine = 0; while (!sr.EndOfStream) { @@ -74,14 +91,30 @@ namespace SpirVTasks { if (!tryFindInclude(include, out incFile)) throw new IncludeFileNotFound (src, srcLine, include); } - build_source (incFile, temp); + //store position when entering an included file + includesPositions.Add(new IncludePosition { + line = currentCompiledLine, + path = incFile + }); + + concatenate_sources (incFile, temp); + + //store current position when include parsing is finished + includesPositions.Add(new IncludePosition { + line = currentCompiledLine, + path = src + }); } else temp.WriteLine (line); + currentCompiledLine++; srcLine++; } } } + /// + /// Use the SpirVCompilerPath element if present. if not search 'VULKAN_SDK' environment, then PATH. + /// bool tryFindGlslcExecutable (out string glslcPath) { if (!string.IsNullOrEmpty (SpirVCompilerPath?.ItemSpec)) { glslcPath = SpirVCompilerPath.ItemSpec; @@ -114,6 +147,9 @@ namespace SpirVTasks { success = true; + includesPositions.Clear(); + currentCompiledLine = 0; + if (!tryFindGlslcExecutable(out string glslcPath)) { BuildErrorEventArgs err = new BuildErrorEventArgs ("execute", "VK001", BuildEngine.ProjectFileOfTaskNode, 0, 0, 0, 0, $"glslc command not found: {glslcPath}", "Set 'VULKAN_SDK' environment variable", "SpirVTasks"); BuildEngine.LogErrorEvent (err); @@ -127,7 +163,7 @@ namespace SpirVTasks { Directory.CreateDirectory (Path.GetDirectoryName (tempFile)); using (StreamWriter sw = new StreamWriter (File.OpenWrite(tempFile))) { string src = SourceFile.ItemSpec; - build_source (SourceFile.ItemSpec, sw); + concatenate_sources (SourceFile.ItemSpec, sw); } } catch (IncludeFileNotFound ex) { BuildErrorEventArgs err = new BuildErrorEventArgs ("include", "VK002", ex.SourceFile, ex.SourceLine, 0, 0, 0, $"include file not found: {ex.FileName}", "", "SpirVTasks"); @@ -180,7 +216,13 @@ namespace SpirVTasks { if (tmp.Length == 5) { string srcFile = SourceFile.ItemSpec; - int line = Math.Max (0, int.Parse (tmp[1]) - 1); + int line = Math.Max (0, int.Parse (tmp[1])); + + IncludePosition ip = includesPositions.LastOrDefault(p => p.line < line); + if (ip != null) { + line -= ip.line; + srcFile = ip.path; + } BuildErrorEventArgs err = new BuildErrorEventArgs ("compile", tmp[2], srcFile, line, 0, 0, 0, $"{tmp[3]} {tmp[4]}", "no help", "SpirVTasks"); BuildEngine.LogErrorEvent (err); diff --git a/SpirVTasks/SpirVTasks.csproj b/SpirVTasks/SpirVTasks.csproj index 2c6a7f5..171380d 100644 --- a/SpirVTasks/SpirVTasks.csproj +++ b/SpirVTasks/SpirVTasks.csproj @@ -1,12 +1,14 @@ netstandard2.0 - 0.1.10 + 0.1.11 + false + $(ReleaseVersion) MSBuild addon to compile and embed spirV shaders SpirVTasks vulkan msbuild spirv glsl addons - $(AssemblyVersion)-beta + $(ReleaseVersion)-beta True False https://github.com/jpbruyere/vk.net/blob/master/SpirVTasks/README.md diff --git a/addons/Directory.Build.props b/addons/Directory.Build.props index 20d44d4..c86d07c 100644 --- a/addons/Directory.Build.props +++ b/addons/Directory.Build.props @@ -29,8 +29,7 @@ - - + diff --git a/addons/gltfLoader/PbrModel.cs b/addons/gltfLoader/PbrModel.cs index 7fe2d84..d5e04a8 100644 --- a/addons/gltfLoader/PbrModel.cs +++ b/addons/gltfLoader/PbrModel.cs @@ -10,21 +10,7 @@ using System.Collections.Generic; namespace vke.glTF { //TODO:stride in buffer views? - public abstract class PbrModel : Model { - //public new struct Vertex { - // [VertexAttribute (VertexAttributeType.Position, VkFormat.R32g32b32Sfloat)] - // public Vector3 pos; - // [VertexAttribute (VertexAttributeType.Normal, VkFormat.R32g32b32Sfloat)] - // public Vector3 normal; - // [VertexAttribute (VertexAttributeType.UVs, VkFormat.R32g32Sfloat)] - // public Vector2 uv0; - // [VertexAttribute (VertexAttributeType.UVs, VkFormat.R32g32Sfloat)] - // public Vector2 uv1; - // public override string ToString () { - // return pos.ToString () + ";" + normal.ToString () + ";" + uv0.ToString () + ";" + uv1.ToString (); - // } - //}; - + public abstract class PbrModel : Model { protected DescriptorPool descriptorPool; public GPUBuffer vbo; public GPUBuffer ibo; diff --git a/samples/Directory.Build.props b/samples/Directory.Build.props index 31d7523..3648b3c 100644 --- a/samples/Directory.Build.props +++ b/samples/Directory.Build.props @@ -28,7 +28,7 @@ - + diff --git a/samples/compute/delaunay.cs b/samples/compute/delaunay.cs index 8867302..7b90ca8 100644 --- a/samples/compute/delaunay.cs +++ b/samples/compute/delaunay.cs @@ -8,7 +8,6 @@ namespace delaunay { static void Main (string[] args) { #if DEBUG Instance.VALIDATION = true; - Instance.DEBUG_UTILS = true; Instance.RENDER_DOC_CAPTURE = false; #endif using (Program vke = new Program ()) { @@ -54,14 +53,6 @@ namespace delaunay { public Program () : base () { - if (Instance.DEBUG_UTILS) - dbgReport = new DebugReport (instance, - VkDebugReportFlagsEXT.ErrorEXT - | VkDebugReportFlagsEXT.DebugEXT - | VkDebugReportFlagsEXT.WarningEXT - | VkDebugReportFlagsEXT.PerformanceWarningEXT - - ); imgResult = new Image (dev, VkFormat.R32g32b32a32Sfloat, VkImageUsageFlags.TransferDst | VkImageUsageFlags.Sampled, VkMemoryPropertyFlags.DeviceLocal, imgDim, imgDim); imgResult.CreateView (); diff --git a/vke/src/Camera.cs b/vke/src/Camera.cs index ac6aa29..c897cf2 100644 --- a/vke/src/Camera.cs +++ b/vke/src/Camera.cs @@ -59,7 +59,7 @@ namespace vke { public void Rotate (float x, float y, float z = 0) { rotation.Y += rotSpeed * x; rotation.X += rotSpeed * y; - //Update (); + Update (); } public float Zoom { get { return zoom; } diff --git a/vke/src/FixedUtf8String.cs b/vke/src/FixedUtf8String.cs index e8d9bb7..bdf6574 100644 --- a/vke/src/FixedUtf8String.cs +++ b/vke/src/FixedUtf8String.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) 2019 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +using System; using System.Runtime.InteropServices; using System.Text; diff --git a/vke/src/ResourceManager.cs b/vke/src/ResourceManager.cs index c8b2028..5f059b2 100644 --- a/vke/src/ResourceManager.cs +++ b/vke/src/ResourceManager.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) 2019 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +using System; using Vulkan; namespace vke { diff --git a/vke/src/SpecializationConstant.cs b/vke/src/SpecializationConstant.cs index aca290f..b434bcb 100644 --- a/vke/src/SpecializationConstant.cs +++ b/vke/src/SpecializationConstant.cs @@ -1,28 +1,6 @@ -// -// SpecializationConstant.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Collections.Generic; using System.Runtime.InteropServices; diff --git a/vke/src/StbImage.cs b/vke/src/StbImage.cs index 208b4a5..1ae1e42 100644 --- a/vke/src/StbImage.cs +++ b/vke/src/StbImage.cs @@ -1,7 +1,6 @@ // Copyright (c) 2019 Jean-Philippe Bruyère // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - using System; using System.Runtime.InteropServices; diff --git a/vke/src/Utils.cs b/vke/src/Utils.cs index 3cbd039..3a8d34e 100644 --- a/vke/src/Utils.cs +++ b/vke/src/Utils.cs @@ -2,7 +2,10 @@ // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; +using System.IO; +using System.Linq; using System.Numerics; +using System.Reflection; namespace Vulkan { public static partial class Utils { @@ -12,6 +15,35 @@ namespace Vulkan { if (result != VkResult.Success) throw new InvalidOperationException (errorString + ": " + result.ToString ()); } + /// + /// Return a file or embedded resource stream. + /// + /// The stream from path. + /// The file or stream path. Embedded resource path starts with '#'. + public static Stream GetStreamFromPath (string path) { + Stream stream = null; + + if (path.StartsWith ("#", StringComparison.Ordinal)) { + string resId = path.Substring (1); + //first search entry assembly + stream = Assembly.GetEntryAssembly ().GetManifestResourceStream (resId); + if (stream != null) + 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); + } + return stream; + } /// Convert angle from degree to radian. public static float DegreesToRadians (float degrees) { return degrees * (float)Math.PI / 180f; diff --git a/vke/src/VkWindow.cs b/vke/src/VkWindow.cs index fc40cb4..5a8b761 100644 --- a/vke/src/VkWindow.cs +++ b/vke/src/VkWindow.cs @@ -185,13 +185,14 @@ namespace vke { protected virtual void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[0]) { + if (MouseButton[(int)Glfw.MouseButton.Left]) { camera.Rotate ((float)-diffX, (float)-diffY); - } else if (MouseButton[1]) { - camera.Move (0, 0, (float)diffY); + updateViewRequested = true; + } else if (MouseButton[(int)Glfw.MouseButton.Right]) { + camera.Move ((float)diffX,0,0); + camera.Move (0, 0, (float)-diffY); + updateViewRequested = true; } - - updateViewRequested = true; } protected virtual void onMouseButtonDown (Glfw.MouseButton button) { } protected virtual void onMouseButtonUp (Glfw.MouseButton button) { } diff --git a/vke/src/base/CommandBuffer.cs b/vke/src/base/CommandBuffer.cs index 83e2f9b..3066f81 100644 --- a/vke/src/base/CommandBuffer.cs +++ b/vke/src/base/CommandBuffer.cs @@ -1,7 +1,6 @@ // Copyright (c) 2019 Jean-Philippe Bruyère // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - using System; using System.Runtime.InteropServices; using Vulkan; diff --git a/vke/src/base/CommandPool.cs b/vke/src/base/CommandPool.cs index d31605a..01888e6 100644 --- a/vke/src/base/CommandPool.cs +++ b/vke/src/base/CommandPool.cs @@ -1,7 +1,6 @@ // Copyright (c) 2019 Jean-Philippe Bruyère // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - using System; using System.Runtime.InteropServices; using Vulkan; diff --git a/vke/src/base/ComputePipeline.cs b/vke/src/base/ComputePipeline.cs index 3aeca89..876aee6 100644 --- a/vke/src/base/ComputePipeline.cs +++ b/vke/src/base/ComputePipeline.cs @@ -1,28 +1,7 @@ // -// ComputePipeline.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using Vulkan; using static Vulkan.Vk; diff --git a/vke/src/base/DebuDrawPipeline.cs b/vke/src/base/DebuDrawPipeline.cs index 60eda5b..3ebc71a 100644 --- a/vke/src/base/DebuDrawPipeline.cs +++ b/vke/src/base/DebuDrawPipeline.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) 2019 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +using System; using System.Numerics; using System.Runtime.InteropServices; using Vulkan; diff --git a/vke/src/base/DebugUtilsMessenger.cs b/vke/src/base/DebugUtilsMessenger.cs index 419e140..eb042d1 100644 --- a/vke/src/base/DebugUtilsMessenger.cs +++ b/vke/src/base/DebugUtilsMessenger.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) 2019 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +using System; using System.Runtime.InteropServices; using Vulkan; using static Vulkan.Vk; diff --git a/vke/src/base/DescriptorPool.cs b/vke/src/base/DescriptorPool.cs index ad8dba7..38fba54 100644 --- a/vke/src/base/DescriptorPool.cs +++ b/vke/src/base/DescriptorPool.cs @@ -1,7 +1,6 @@ // Copyright (c) 2019 Jean-Philippe Bruyère // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) - using System; using System.Collections.Generic; using Vulkan; diff --git a/vke/src/base/DescriptorSetWrites.cs b/vke/src/base/DescriptorSetWrites.cs index 227ea0d..058dfc7 100644 --- a/vke/src/base/DescriptorSetWrites.cs +++ b/vke/src/base/DescriptorSetWrites.cs @@ -1,28 +1,7 @@ // -// DescriptorSetWrites.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Collections.Generic; using System.Runtime.InteropServices; diff --git a/vke/src/base/Device.cs b/vke/src/base/Device.cs index a925625..2e287e4 100644 --- a/vke/src/base/Device.cs +++ b/vke/src/base/Device.cs @@ -228,7 +228,7 @@ namespace vke { public VkShaderModule LoadSPIRVShader (string filename) { VkShaderModule shaderModule; - using (Stream stream = StaticGetStreamFromPath (filename)) { + using (Stream stream = Utils.GetStreamFromPath (filename)) { using (BinaryReader br = new BinaryReader (stream)) { byte[] shaderCode = br.ReadBytes ((int)stream.Length); ulong shaderSize = (ulong)shaderCode.Length; @@ -246,32 +246,7 @@ namespace vke { } return shaderModule; - } - - public static Stream StaticGetStreamFromPath (string path) { - Stream stream = null; - - if (path.StartsWith ("#", StringComparison.Ordinal)) { - string resId = path.Substring (1); - //first search entry assembly - stream = Assembly.GetEntryAssembly ().GetManifestResourceStream (resId); - if (stream != null) - 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); - } - return stream; - } + } #region IDisposable Support private bool disposedValue = false; // Pour détecter les appels redondants diff --git a/vke/src/base/FrameBuffer.cs b/vke/src/base/FrameBuffer.cs index 3260e15..7ba3d00 100644 --- a/vke/src/base/FrameBuffer.cs +++ b/vke/src/base/FrameBuffer.cs @@ -1,28 +1,6 @@ -// -// FrameBuffer.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Collections.Generic; using System.Linq; diff --git a/vke/src/base/GPUBuffer.cs b/vke/src/base/GPUBuffer.cs index bebc21b..50280ba 100644 --- a/vke/src/base/GPUBuffer.cs +++ b/vke/src/base/GPUBuffer.cs @@ -1,28 +1,6 @@ -// -// GPUBuffer.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Runtime.InteropServices; using Vulkan; diff --git a/vke/src/base/GraphicPipeline.cs b/vke/src/base/GraphicPipeline.cs index 7f94316..1c0c877 100644 --- a/vke/src/base/GraphicPipeline.cs +++ b/vke/src/base/GraphicPipeline.cs @@ -1,28 +1,6 @@ -// -// FrameBuffer.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Collections.Generic; using Vulkan; diff --git a/vke/src/base/GraphicPipelineConfig.cs b/vke/src/base/GraphicPipelineConfig.cs index 848a378..f1e3875 100644 --- a/vke/src/base/GraphicPipelineConfig.cs +++ b/vke/src/base/GraphicPipelineConfig.cs @@ -1,28 +1,6 @@ -// -// PipelineConfig.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Collections.Generic; using System.Numerics; @@ -32,22 +10,22 @@ using Vulkan; using static Vulkan.Vk; namespace vke { - public class GraphicPipelineConfig { + public class GraphicPipelineConfig { public uint SubpassIndex; - public PipelineLayout Layout; + public PipelineLayout Layout; public RenderPass RenderPass; public PipelineCache Cache; public VkPipelineBindPoint bindPoint = VkPipelineBindPoint.Graphics; - public VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = VkPipelineInputAssemblyStateCreateInfo.New(); - public VkPipelineRasterizationStateCreateInfo rasterizationState = VkPipelineRasterizationStateCreateInfo.New(); - public VkPipelineViewportStateCreateInfo viewportState = VkPipelineViewportStateCreateInfo.New(); - public VkPipelineDepthStencilStateCreateInfo depthStencilState = VkPipelineDepthStencilStateCreateInfo.New(); - public VkPipelineMultisampleStateCreateInfo multisampleState = VkPipelineMultisampleStateCreateInfo.New(); - public List blendAttachments = new List(); - public List dynamicStates = new List (); - public List vertexBindings = new List (); - public List vertexAttributes = new List (); - public readonly List shaders = new List(); + public VkPipelineInputAssemblyStateCreateInfo inputAssemblyState = VkPipelineInputAssemblyStateCreateInfo.New (); + public VkPipelineRasterizationStateCreateInfo rasterizationState = VkPipelineRasterizationStateCreateInfo.New (); + public VkPipelineViewportStateCreateInfo viewportState = VkPipelineViewportStateCreateInfo.New (); + public VkPipelineDepthStencilStateCreateInfo depthStencilState = VkPipelineDepthStencilStateCreateInfo.New (); + public VkPipelineMultisampleStateCreateInfo multisampleState = VkPipelineMultisampleStateCreateInfo.New (); + public List blendAttachments = new List (); + public List dynamicStates = new List (); + public List vertexBindings = new List (); + public List vertexAttributes = new List (); + public readonly List shaders = new List (); public VkBool32 ColorBlendLogicOpEnable = false; public VkLogicOp ColorBlendLogicOp; public Vector4 ColorBlendConstants; @@ -65,28 +43,27 @@ namespace vke { /// added automatically with blending disabled. (cfg.blendAttachments[0]) /// public static GraphicPipelineConfig CreateDefault (VkPrimitiveTopology topology = VkPrimitiveTopology.TriangleList, - VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1, bool depthTestEnabled = true) - { + VkSampleCountFlags samples = VkSampleCountFlags.SampleCount1, bool depthTestEnabled = true) { GraphicPipelineConfig cfg = new GraphicPipelineConfig (); cfg.inputAssemblyState.topology = topology; - cfg.multisampleState.rasterizationSamples = samples; + cfg.multisampleState.rasterizationSamples = samples; - cfg.rasterizationState.polygonMode = VkPolygonMode.Fill; - cfg.rasterizationState.cullMode = (uint)VkCullModeFlags.None; - cfg.rasterizationState.frontFace = VkFrontFace.CounterClockwise; - cfg.rasterizationState.depthClampEnable = False; - cfg.rasterizationState.rasterizerDiscardEnable = False; - cfg.rasterizationState.depthBiasEnable = False; - cfg.rasterizationState.lineWidth = 1.0f; + cfg.rasterizationState.polygonMode = VkPolygonMode.Fill; + cfg.rasterizationState.cullMode = (uint)VkCullModeFlags.None; + cfg.rasterizationState.frontFace = VkFrontFace.CounterClockwise; + cfg.rasterizationState.depthClampEnable = False; + cfg.rasterizationState.rasterizerDiscardEnable = False; + cfg.rasterizationState.depthBiasEnable = False; + cfg.rasterizationState.lineWidth = 1.0f; - cfg.viewportState.viewportCount = 1; - cfg.viewportState.scissorCount = 1; + cfg.viewportState.viewportCount = 1; + cfg.viewportState.scissorCount = 1; - cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false)); + cfg.blendAttachments.Add (new VkPipelineColorBlendAttachmentState (false)); - cfg.dynamicStates.Add (VkDynamicState.Viewport); - cfg.dynamicStates.Add (VkDynamicState.Scissor); + cfg.dynamicStates.Add (VkDynamicState.Viewport); + cfg.dynamicStates.Add (VkDynamicState.Scissor); if (depthTestEnabled) { cfg.depthStencilState.depthTestEnable = True; @@ -103,21 +80,21 @@ namespace vke { return cfg; } - uint currentAttributeIndex = 0; - public void AddVertexAttributes (uint binding, params VkFormat[] attribsDesc) { - uint currentAttributeoffset = 0; - for (uint i = 0; i < attribsDesc.Length; i++) { + uint currentAttributeIndex = 0; + public void AddVertexAttributes (uint binding, params VkFormat[] attribsDesc) { + uint currentAttributeoffset = 0; + for (uint i = 0; i < attribsDesc.Length; i++) { vertexAttributes.Add (new VkVertexInputAttributeDescription (binding, i + currentAttributeIndex, attribsDesc[i], currentAttributeoffset)); VkFormatSize fs; Utils.vkGetFormatSize (attribsDesc[i], out fs); - currentAttributeoffset += fs.blockSizeInBits/8; + currentAttributeoffset += fs.blockSizeInBits / 8; } - currentAttributeIndex += (uint)attribsDesc.Length; + currentAttributeIndex += (uint)attribsDesc.Length; } - public void AddVertexBinding (uint binding, uint stride, VkVertexInputRate inputRate = VkVertexInputRate.Vertex) { + public void AddVertexBinding (uint binding, uint stride, VkVertexInputRate inputRate = VkVertexInputRate.Vertex) { vertexBindings.Add (new VkVertexInputBindingDescription (binding, stride, inputRate)); } - public void AddVertexBinding (uint binding = 0, VkVertexInputRate inputRate = VkVertexInputRate.Vertex) { + public void AddVertexBinding (uint binding = 0, VkVertexInputRate inputRate = VkVertexInputRate.Vertex) { vertexBindings.Add (new VkVertexInputBindingDescription (binding, (uint)Marshal.SizeOf (), inputRate)); } /// @@ -127,7 +104,7 @@ namespace vke { vertexBindings.Add (new VkVertexInputBindingDescription (binding, (uint)Marshal.SizeOf (), inputRate)); FieldInfo[] fields = typeof (T).GetFields (); VkFormat[] attribs = new VkFormat[fields.Length]; - for (int i = 0; i < fields.Length; i++) + for (int i = 0; i < fields.Length; i++) attribs[i] = fields[i].GetCustomAttribute ().Format; AddVertexAttributes (binding, attribs); } @@ -136,11 +113,14 @@ namespace vke { } public void ResetShadersAndVerticesInfos () { - foreach (ShaderInfo shader in shaders) - shader.Dispose (); - currentAttributeIndex = 0; - vertexBindings.Clear (); + currentAttributeIndex = 0; + vertexBindings.Clear (); vertexAttributes.Clear (); + ResetShaders (); + } + public void ResetShaders () { + foreach (ShaderInfo shader in shaders) + shader.Dispose (); shaders.Clear (); } } diff --git a/vke/src/base/HostBuffer.cs b/vke/src/base/HostBuffer.cs index 65dc53e..2ce0094 100644 --- a/vke/src/base/HostBuffer.cs +++ b/vke/src/base/HostBuffer.cs @@ -1,28 +1,6 @@ -// -// HostBuffer.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Collections.Generic; using System.Runtime.InteropServices; diff --git a/vke/src/base/Image.cs b/vke/src/base/Image.cs index 5238fa7..c84fadb 100644 --- a/vke/src/base/Image.cs +++ b/vke/src/base/Image.cs @@ -1,28 +1,6 @@ -// -// Buffer.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Diagnostics; using Vulkan; diff --git a/vke/src/base/Instance.cs b/vke/src/base/Instance.cs index 71e9c9d..dbc9673 100644 --- a/vke/src/base/Instance.cs +++ b/vke/src/base/Instance.cs @@ -1,28 +1,6 @@ -// -// Instance.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Collections.Generic; using System.Linq; diff --git a/vke/src/base/Pipeline.cs b/vke/src/base/Pipeline.cs index 19c62de..329e555 100644 --- a/vke/src/base/Pipeline.cs +++ b/vke/src/base/Pipeline.cs @@ -1,28 +1,6 @@ -// -// Pipeline.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using Vulkan; using static Vulkan.Vk; diff --git a/vke/src/base/PipelineCache.cs b/vke/src/base/PipelineCache.cs index 0129cac..f38764d 100644 --- a/vke/src/base/PipelineCache.cs +++ b/vke/src/base/PipelineCache.cs @@ -1,28 +1,6 @@ -// -// SpecializationConstant.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Collections.Generic; using System.IO; diff --git a/vke/src/base/PipelineLayout.cs b/vke/src/base/PipelineLayout.cs index ba5c257..2f932e7 100644 --- a/vke/src/base/PipelineLayout.cs +++ b/vke/src/base/PipelineLayout.cs @@ -1,28 +1,6 @@ -// -// PipelineLayout.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Collections.Generic; using System.Linq; diff --git a/vke/src/base/QueryPool.cs b/vke/src/base/QueryPool.cs index 6dfad44..7a5edd3 100644 --- a/vke/src/base/QueryPool.cs +++ b/vke/src/base/QueryPool.cs @@ -1,28 +1,6 @@ -// -// CommandPool.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Collections.Generic; using Vulkan; diff --git a/vke/src/base/RenderPass.cs b/vke/src/base/RenderPass.cs index f93ddcd..95c0baf 100644 --- a/vke/src/base/RenderPass.cs +++ b/vke/src/base/RenderPass.cs @@ -1,28 +1,6 @@ -// -// RenderPass.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.Collections.Generic; using System.Linq; diff --git a/vke/src/base/Resource.cs b/vke/src/base/Resource.cs index 1b559ed..e489e35 100644 --- a/vke/src/base/Resource.cs +++ b/vke/src/base/Resource.cs @@ -1,4 +1,7 @@ -using System; +// Copyright (c) 2019 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) +using System; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; diff --git a/vke/src/base/SubPass.cs b/vke/src/base/SubPass.cs index ca91424..9a7fbb6 100644 --- a/vke/src/base/SubPass.cs +++ b/vke/src/base/SubPass.cs @@ -1,28 +1,6 @@ -// -// SubPass.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System.Collections.Generic; using Vulkan; diff --git a/vke/src/base/SwapChain.cs b/vke/src/base/SwapChain.cs index d49dd54..c752696 100644 --- a/vke/src/base/SwapChain.cs +++ b/vke/src/base/SwapChain.cs @@ -1,28 +1,7 @@ // -// SwapChain.cs +// Copyright (c) 2019 Jean-Philippe Bruyère // -// Author: -// Jean-Philippe Bruyère -// -// Copyright (c) 2019 jp -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using Vulkan; using static Vulkan.Vk; diff --git a/vke/src/model/Model.cs b/vke/src/model/Model.cs index 52fbbe9..c66601b 100644 --- a/vke/src/model/Model.cs +++ b/vke/src/model/Model.cs @@ -70,12 +70,24 @@ namespace vke { public class Primitive { public string name; - public UInt32 indexBase; - public Int32 vertexBase; - public UInt32 vertexCount; - public UInt32 indexCount; - public UInt32 material; + public uint indexBase; + public int vertexBase; + public uint vertexCount; + public uint indexCount; + public uint material; public BoundingBox bb; + + public Primitive () { } + public Primitive (uint vertexCount, uint indexCount, int vertexBase = 0, uint indexBase = 0) { + this.vertexCount = vertexCount; + this.indexCount = indexCount; + this.vertexBase = vertexBase; + this.indexBase = indexBase; + } + + public void Draw (CommandBuffer cmd, uint instanceCount = 1, uint firstInstance = 0) { + cmd.DrawIndexed (indexCount, instanceCount, indexBase, vertexBase, firstInstance); + } } public class Mesh { diff --git a/vke/src/model/ObjMesh.cs b/vke/src/model/ObjMesh.cs new file mode 100644 index 0000000..c2944c3 --- /dev/null +++ b/vke/src/model/ObjMesh.cs @@ -0,0 +1,162 @@ +// +// Mesh.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2015 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System.Collections.Generic; +using System.IO; +using System.Numerics; +using System.Threading; + +namespace vke +{ + public class ObjMesh { + public Model.Vertex[] vertices; + public ushort[] indices; + + public ObjMesh(string path) { + OBJMeshLoader loader = new OBJMeshLoader (path); + vertices = new Model.Vertex[loader.VertexCount]; + for (int i = 0; i < loader.VertexCount; i++) { + vertices[i] = new Model.Vertex { + pos = loader.lPositions[i], + normal = loader.lNormals[i], + uv = loader.lTexCoords[i] + }; + } + indices = loader.lIndices.ToArray (); + } + + #region .OBJ Loading + class OBJMeshLoader { + public int VertexCount => objPositions.Count; + + public List objPositions = new List (); + public List objNormals = new List (); + public List objTexCoords = new List (); + public List lPositions = new List (); + public List lNormals = new List (); + public List lTexCoords = new List (); + public List lIndices = new List (); + + public OBJMeshLoader (string fileName) { + string name = "unamed"; + using (Stream stream = new FileStream (fileName, FileMode.Open, FileAccess.Read)) { + using (StreamReader Reader = new StreamReader (stream)) { + System.Globalization.CultureInfo savedCulture = Thread.CurrentThread.CurrentCulture; + Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; + + string line; + while ((line = Reader.ReadLine ()) != null) { + line = line.Trim (' '); + line = line.Replace (" ", " "); + + string[] parameters = line.Split (' '); + + switch (parameters[0]) { + case "o": + name = parameters[1]; + break; + case "p": // Point + break; + case "v": // Vertex + float x = float.Parse (parameters[1]); + float y = float.Parse (parameters[2]); + float z = float.Parse (parameters[3]); + + objPositions.Add (new Vector3 (x, y, z)); + break; + case "vt": // TexCoord + float u = float.Parse (parameters[1]); + float v = float.Parse (parameters[2]); + objTexCoords.Add (new Vector2 (u, v)); + break; + + case "vn": // Normal + float nx = float.Parse (parameters[1]); + float ny = float.Parse (parameters[2]); + float nz = float.Parse (parameters[3]); + objNormals.Add (new Vector3 (nx, ny, nz)); + break; + + case "f": + switch (parameters.Length) { + case 4: + + lIndices.Add (ParseFaceParameter (parameters[1])); + lIndices.Add (ParseFaceParameter (parameters[2])); + lIndices.Add (ParseFaceParameter (parameters[3])); + break; + + case 5: + lIndices.Add (ParseFaceParameter (parameters[1])); + lIndices.Add (ParseFaceParameter (parameters[2])); + lIndices.Add (ParseFaceParameter (parameters[3])); + lIndices.Add (ParseFaceParameter (parameters[4])); + break; + } + break; + } + } + Thread.CurrentThread.CurrentCulture = savedCulture; + } + } + } + + TIdx ParseFaceParameter (string faceParameter) { + Vector3 vertex = new Vector3 (); + Vector2 texCoord = new Vector2 (); + Vector3 normal = new Vector3 (); + + string[] parameters = faceParameter.Split ('/'); + + int vertexIndex = int.Parse (parameters[0]); + if (vertexIndex < 0) vertexIndex = objPositions.Count + vertexIndex; + else vertexIndex = vertexIndex - 1; + vertex = objPositions[vertexIndex]; + + if (parameters.Length > 1) { + int texCoordIndex; + if (int.TryParse (parameters[1], out texCoordIndex)) { + if (texCoordIndex < 0) texCoordIndex = objTexCoords.Count + texCoordIndex; + else texCoordIndex = texCoordIndex - 1; + texCoord = objTexCoords[texCoordIndex]; + } + } + + if (parameters.Length > 2) { + int normalIndex; + if (int.TryParse (parameters[2], out normalIndex)) { + if (normalIndex < 0) normalIndex = objNormals.Count + normalIndex; + else normalIndex = normalIndex - 1; + normal = objNormals[normalIndex]; + } + } + + lPositions.Add (vertex); + lTexCoords.Add (texCoord); + lNormals.Add (normal); + + TIdx index = (TIdx)(object)(lPositions.Count - 1); + return index; + } + } + #endregion + } +} + diff --git a/vke/vke.csproj b/vke/vke.csproj index 7e4158a..538540e 100644 --- a/vke/vke.csproj +++ b/vke/vke.csproj @@ -48,7 +48,7 @@ - +