// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// 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 {
+ /// <summary>
+ /// Record include position and path in produced glsl file before compilation
+ /// </summary>
+ 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;
get;
set;
}
+ /// <summary>
+ /// Optional, Specify the comple glslc executable path.
+ /// </summary>
public ITaskItem SpirVCompilerPath {
get;
set;
}
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<IncludePosition> includesPositions = new List<IncludePosition>(); //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)) {
incFile = "";
return false;
}
-
- void build_source (string src, StreamWriter temp) {
+ /// <summary>
+ /// produce a single glsl file with main glsl and all its includes in the temp directory
+ /// </summary>
+ void concatenate_sources (string src, StreamWriter temp) {
using (StreamReader sr = new StreamReader (File.OpenRead (src))) {
int srcLine = 0;
while (!sr.EndOfStream) {
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++;
}
}
}
+ /// <summary>
+ /// Use the SpirVCompilerPath element if present. if not search 'VULKAN_SDK' environment, then PATH.
+ /// </summary>
bool tryFindGlslcExecutable (out string glslcPath) {
if (!string.IsNullOrEmpty (SpirVCompilerPath?.ItemSpec)) {
glslcPath = SpirVCompilerPath.ItemSpec;
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);
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");
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);
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
- <AssemblyVersion>0.1.10</AssemblyVersion>
+ <ReleaseVersion>0.1.11</ReleaseVersion>
+ <SynchReleaseVersion>false</SynchReleaseVersion>
+ <AssemblyVersion>$(ReleaseVersion)</AssemblyVersion>
<Description>MSBuild addon to compile and embed spirV shaders</Description>
<PackageId>SpirVTasks</PackageId>
<PackageTags>vulkan msbuild spirv glsl addons</PackageTags>
- <PackageVersion>$(AssemblyVersion)-beta</PackageVersion>
+ <PackageVersion>$(ReleaseVersion)-beta</PackageVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
<PackageProjectUrl>https://github.com/jpbruyere/vk.net/blob/master/SpirVTasks/README.md</PackageProjectUrl>
<ItemGroup>
<!--<PackageReference Include="vke" Version="0.1.8-beta" />-->
<ProjectReference Include="..\..\vke\vke.csproj" />
- <PackageReference Include="SpirVTasks" Version="0.1.10-beta" />
- <!--<PackageReference Include="Vulkan" Version="0.1.4" />-->
+ <PackageReference Include="SpirVTasks" Version="0.1.11-beta" />
</ItemGroup>
<ItemGroup>
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;
<ItemGroup>
<!--<PackageReference Include="vke" Version="0.1.8-beta" />-->
<ProjectReference Include="..\..\vke\vke.csproj" />
- <PackageReference Include="SpirVTasks" Version="0.1.10-beta" />
+ <PackageReference Include="SpirVTasks" Version="0.1.11-beta" />
<!--<PackageReference Include="Vulkan" Version="0.1.4" /> -->
</ItemGroup>
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 ()) {
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 ();
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; }
-using System;
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
using System.Runtime.InteropServices;
using System.Text;
-using System;
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+using System;
using Vulkan;
namespace vke {
-//
-// SpecializationConstant.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
using System;
using System.Runtime.InteropServices;
//
// 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 {
if (result != VkResult.Success)
throw new InvalidOperationException (errorString + ": " + result.ToString ());
}
+ /// <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)) {
+ 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;
+ }
/// <summary>Convert angle from degree to radian.</summary>
public static float DegreesToRadians (float degrees) {
return degrees * (float)Math.PI / 180f;
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) { }
// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
using System;
using System.Runtime.InteropServices;
using Vulkan;
// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
using System;
using System.Runtime.InteropServices;
using Vulkan;
//
-// ComputePipeline.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
-using System;
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// 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;
-using System;
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// 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;
// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
-
using System;
using System.Collections.Generic;
using Vulkan;
//
-// DescriptorSetWrites.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
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;
}
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
-//
-// FrameBuffer.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
-//
-// GPUBuffer.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
-//
-// FrameBuffer.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
-//
-// PipelineConfig.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
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<VkPipelineColorBlendAttachmentState> blendAttachments = new List<VkPipelineColorBlendAttachmentState>();
- public List<VkDynamicState> dynamicStates = new List<VkDynamicState> ();
- public List<VkVertexInputBindingDescription> vertexBindings = new List<VkVertexInputBindingDescription> ();
- public List<VkVertexInputAttributeDescription> vertexAttributes = new List<VkVertexInputAttributeDescription> ();
- public readonly List<ShaderInfo> shaders = new List<ShaderInfo>();
+ 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<VkPipelineColorBlendAttachmentState> blendAttachments = new List<VkPipelineColorBlendAttachmentState> ();
+ public List<VkDynamicState> dynamicStates = new List<VkDynamicState> ();
+ public List<VkVertexInputBindingDescription> vertexBindings = new List<VkVertexInputBindingDescription> ();
+ public List<VkVertexInputAttributeDescription> vertexAttributes = new List<VkVertexInputAttributeDescription> ();
+ public readonly List<ShaderInfo> shaders = new List<ShaderInfo> ();
public VkBool32 ColorBlendLogicOpEnable = false;
public VkLogicOp ColorBlendLogicOp;
public Vector4 ColorBlendConstants;
/// added automatically with blending disabled. (cfg.blendAttachments[0])
/// </summary>
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;
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<T> (uint binding = 0, VkVertexInputRate inputRate = VkVertexInputRate.Vertex) {
+ public void AddVertexBinding<T> (uint binding = 0, VkVertexInputRate inputRate = VkVertexInputRate.Vertex) {
vertexBindings.Add (new VkVertexInputBindingDescription (binding, (uint)Marshal.SizeOf<T> (), inputRate));
}
/// <summary>
vertexBindings.Add (new VkVertexInputBindingDescription (binding, (uint)Marshal.SizeOf<T> (), 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<VertexAttributeAttribute> ().Format;
AddVertexAttributes (binding, attribs);
}
}
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 ();
}
}
-//
-// HostBuffer.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
-//
-// Buffer.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
-//
-// Instance.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
-//
-// Pipeline.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
-//
-// SpecializationConstant.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
-//
-// PipelineLayout.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
-//
-// CommandPool.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
-//
-// RenderPass.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
-using System;
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// 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;
-//
-// SubPass.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
//
-// SwapChain.cs
+// Copyright (c) 2019 Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
//
-// Author:
-// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
-//
-// 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;
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 {
--- /dev/null
+//
+// Mesh.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+// 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 <http://www.gnu.org/licenses/>.
+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<ushort> loader = new OBJMeshLoader<ushort> (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<TIdx> {
+ public int VertexCount => objPositions.Count;
+
+ public List<Vector3> objPositions = new List<Vector3> ();
+ public List<Vector3> objNormals = new List<Vector3> ();
+ public List<Vector2> objTexCoords = new List<Vector2> ();
+ public List<Vector3> lPositions = new List<Vector3> ();
+ public List<Vector3> lNormals = new List<Vector3> ();
+ public List<Vector2> lTexCoords = new List<Vector2> ();
+ public List<TIdx> lIndices = new List<TIdx> ();
+
+ 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
+ }
+}
+
</ItemGroup>
<ItemGroup>
- <PackageReference Include="SpirVTasks" Version="0.1.10-beta" />
+ <PackageReference Include="SpirVTasks" Version="0.1.11-beta" />
<PackageReference Include="Vulkan" Version="0.1.7" />
</ItemGroup>
<ItemGroup>