From: Jean-Philippe Bruyère Date: Sun, 30 Aug 2020 11:52:38 +0000 (+0200) Subject: wip X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=7ef7d9dd8d85a65627166d057cdbb79dc29a13ef;p=jp%2Fvke.net.git wip --- diff --git a/addons/Directory.Build.props b/addons/Directory.Build.props index c9d2565..709ac07 100644 --- a/addons/Directory.Build.props +++ b/addons/Directory.Build.props @@ -19,13 +19,6 @@ $(SolutionDir)build\$(Configuration)\ - - TRACE;DEBUG;NETSTANDARD;NETSTANDARD2_0;_WITH_SHADOWS;WITH_VKVG - - - NETSTANDARD;NETSTANDARD2_0;WITH_SHADOWS;_WITH_VKVG - - diff --git a/addons/VkvgPipeline/VkvgPipeline.cs b/addons/VkvgPipeline/VkvgPipeline.cs index a2df026..6aa5ca3 100644 --- a/addons/VkvgPipeline/VkvgPipeline.cs +++ b/addons/VkvgPipeline/VkvgPipeline.cs @@ -1,8 +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.Numerics; using vke; using Vulkan; @@ -60,6 +58,7 @@ namespace VkvgPipeline { cmd.Draw (3, 1, 0, 0); } +#if MEMORY_POOLs public void DrawResources (vkvg.Context ctx, int width, int height) { ResourceManager rm = Dev.resourceManager; @@ -121,6 +120,7 @@ namespace VkvgPipeline { y += memPoolHeight; } } +#endif protected override void Dispose (bool disposing) { Texture?.Dispose (); vkvgSurf?.Dispose (); diff --git a/samples/ClearScreen/README.md b/samples/ClearScreen/README.md index 8a342fd..2e4cd68 100644 --- a/samples/ClearScreen/README.md +++ b/samples/ClearScreen/README.md @@ -4,8 +4,10 @@ To build a minimal vulkan application, add the [vke](https://www.nuget.org/packa ```xml - net472 - Exe + + net472 + Exe + @@ -24,6 +26,7 @@ To build a minimal vulkan application, add the [vke](https://www.nuget.org/packa ```csharp class Program : VkWindow { static void Main (string[] args) { + Instance.VALIDATION = true; using (Program vke = new Program ()) { vke.Run (); } @@ -33,7 +36,7 @@ class Program : VkWindow { ### Vulkan Initialization -`initVulkan` is the first method called by the 'Run' method. Default initialization will provide a vulkan window, a default swap chain bound to it, and a draw and present semaphore to sync the rendering. +**`initVulkan`** is the first method called by the **`Run`** method. Default initialization will provide a vulkan window, a default swap chain bound to it, and a draw and present semaphore to sync the rendering. ```csharp protected override void initVulkan () { base.initVulkan (); @@ -52,7 +55,7 @@ Note that because we only reset the command buffers when rebuilding these, we ne ### Frame buffer creation -The resize method is called at least once before any rendering, so it's a safe place to initialize output size related vulkan objects like the frame buffers. vke provide a FrameBuffer collection object to ease handling of multiple related buffers like those used for a swap chain for example.. +The **`OnResize`** method is called at least once before any rendering, so it's a safe place to initialize output size related vulkan objects like the frame buffers. vke provide a FrameBuffer collection object to ease handling of multiple related buffers like those used for a swap chain for example.. ```csharp FrameBuffers frameBuffers; @@ -67,8 +70,6 @@ protected override void OnResize () { ``` It's common to rebuild the command buffers targeting the swap chain images after a resize so that the drawing is scaled. So it's a good idea to build/rebuild your commands here. - - ### The command buffers The `VkWindow` class has a default array of command buffers, one for each swap chain image. But it's up to you to allocate and populate them. diff --git a/samples/ClearScreen/main.cs b/samples/ClearScreen/main.cs index 3e11384..c343e99 100644 --- a/samples/ClearScreen/main.cs +++ b/samples/ClearScreen/main.cs @@ -15,7 +15,7 @@ namespace ClearScreen { } } - //frame buffer collection to handle on fb per swapchain image. + //frame buffer collection to handle one frame buffer per swapchain image. FrameBuffers frameBuffers; RenderPass renderPass; diff --git a/samples/DistanceFieldFontTest/Program.cs b/samples/DistanceFieldFontTest/Program.cs index d59227c..de274e5 100644 --- a/samples/DistanceFieldFontTest/Program.cs +++ b/samples/DistanceFieldFontTest/Program.cs @@ -249,10 +249,10 @@ namespace DistanceFieldFontTest { protected override void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[0]) { + if (GetButton (MouseButton.Left) == InputAction.Press) { rotY -= rotSpeed * (float)diffX; rotX += rotSpeed * (float)diffY; - } else if (MouseButton[1]) { + } else if (GetButton (MouseButton.Right) == InputAction.Press) { zoom += zoomSpeed * (float)diffY; } diff --git a/samples/Textured/README.md b/samples/Textured/README.md index 331e752..143de57 100644 --- a/samples/Textured/README.md +++ b/samples/Textured/README.md @@ -1,21 +1,30 @@ ### Enabling extensions -The `VkWindow` class provides two properties that you may override to enable additional extensions. +The **`VkWindow`** class provides two properties that you may override to enable additional extensions. +```csharp +public override string[] EnabledInstanceExtensions => new string[] { + Ext.I.VK_EXT_debug_utils +}; +public override string[] EnabledDeviceExtensions => new string[] { + Ext.D.VK_KHR_swapchain, +}; +``` +Extension's names are organized in two subclasses of the `Ext` static class, one for the instance extensions (**`Ext.I`**) and one for the device ones (**`Ext.D`**). ### Enabling features -Override the `configureEnabledFeatures` method of `VkWindow` to enable features. +Override the **`configureEnabledFeatures`** method of **`VkWindow`** to enable features. ```csharp protected override void configureEnabledFeatures ( - VkPhysicalDeviceFeatures available_features, - ref VkPhysicalDeviceFeatures enabled_features) -{ - enabled_features.samplerAnisotropy = available_features.samplerAnisotropy; + VkPhysicalDeviceFeatures available_features, + ref VkPhysicalDeviceFeatures enabled_features) { + + enabled_features.samplerAnisotropy = available_features.samplerAnisotropy; } ``` ### Creating queues -To create queues, override the `createQueues` method of `VkWindow`. This function is called before the logical device creation and will take care of physically available queues, creating duplicates if count exceed availability. The `base` method will create a default presentable queue. +To create queues, override the **`createQueues`** method of **`VkWindow`**. This function is called before the logical device creation and will take care of physically available queues, creating duplicates if count exceed availability. The `base` method will create a default presentable queue. ```csharp protected override void createQueues () { diff --git a/samples/Textured/main.cs b/samples/Textured/main.cs index bf903f1..e23d443 100644 --- a/samples/Textured/main.cs +++ b/samples/Textured/main.cs @@ -19,10 +19,10 @@ namespace Textured { vke.Run (); } } - protected override void configureEnabledFeatures (VkPhysicalDeviceFeatures available_features, ref VkPhysicalDeviceFeatures features) { - base.configureEnabledFeatures (available_features, ref features); - features.textureCompressionBC = available_features.textureCompressionBC; - features.textureCompressionASTC_LDR = available_features.textureCompressionASTC_LDR; + protected override void configureEnabledFeatures (VkPhysicalDeviceFeatures available_features, ref VkPhysicalDeviceFeatures enabled_features) { + base.configureEnabledFeatures (available_features, ref enabled_features); + enabled_features.textureCompressionBC = available_features.textureCompressionBC; + enabled_features.textureCompressionASTC_LDR = available_features.textureCompressionASTC_LDR; } float rotSpeed = 0.01f, zoomSpeed = 0.01f; @@ -59,7 +59,6 @@ namespace Textured { ushort[] indices = { 0, 1, 2, 2, 0, 3 }; int currentImgIndex = 0; string[] imgPathes = { - vke.samples.Utils.DataDirectory + "models/Bricks16_col.jpg", vke.samples.Utils.DataDirectory + "textures/texturearray_rocks_bc3_unorm.ktx", vke.samples.Utils.DataDirectory + "textures/texture.jpg", vke.samples.Utils.DataDirectory + "textures/tex256.jpg", @@ -98,9 +97,7 @@ namespace Textured { pipeline = new GraphicPipeline (cfg); - - uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices); - uboMats.Map ();//permanent map + uboMats = new HostBuffer (dev, VkBufferUsageFlags.UniformBuffer, matrices, true); descriptorSet = descriptorPool.Allocate (dsLayout); @@ -198,10 +195,10 @@ namespace Textured { protected override void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[0]) { + if (GetButton (MouseButton.Left) == InputAction.Press) { rotY -= rotSpeed * (float)diffX; rotX += rotSpeed * (float)diffY; - } else if (MouseButton[1]) { + } else if (GetButton (MouseButton.Right) == InputAction.Press) { zoom += zoomSpeed * (float)diffY; } diff --git a/samples/Textured/shaders/main.vert b/samples/Textured/shaders/main.vert index 3b395bf..9efd033 100644 --- a/samples/Textured/shaders/main.vert +++ b/samples/Textured/shaders/main.vert @@ -4,7 +4,7 @@ #extension GL_ARB_shading_language_420pack : enable layout (location = 0) in vec3 inPos; -layout (location = 1) in vec3 inColor; +layout (location = 1) in vec2 inTex; layout (binding = 0) uniform UBO { @@ -13,7 +13,7 @@ layout (binding = 0) uniform UBO mat4 modelMatrix; } ubo; -layout (location = 0) out vec3 outColor; +layout (location = 0) out vec2 outTex; out gl_PerVertex { @@ -23,6 +23,6 @@ out gl_PerVertex void main() { - outColor = inColor; + outTex = inTex; gl_Position = ubo.projectionMatrix * ubo.viewMatrix * ubo.modelMatrix * vec4(inPos.xyz, 1.0); } diff --git a/samples/TexturedCube/main.cs b/samples/TexturedCube/main.cs index b42ec9d..ab32327 100644 --- a/samples/TexturedCube/main.cs +++ b/samples/TexturedCube/main.cs @@ -265,10 +265,10 @@ namespace TextureCube { protected override void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[0]) { + if (GetButton (MouseButton.Left) == InputAction.Press) { rotY -= rotSpeed * (float)diffX; rotX += rotSpeed * (float)diffY; - } else if (MouseButton[1]) { + } else if (GetButton (MouseButton.Right) == InputAction.Press) { zoom += zoomSpeed * (float)diffY; } diff --git a/samples/Triangle/README.md b/samples/Triangle/README.md index fc76714..3f7f02d 100644 --- a/samples/Triangle/README.md +++ b/samples/Triangle/README.md @@ -36,7 +36,7 @@ cfg.AddVertexBinding (0); cfg.AddVertexAttributes (0, VkFormat.R32g32b32Sfloat, //position VkFormat.R32g32b32Sfloat);//color ``` -shader are automatically compiled by [`SpirVTacks`](../../SpirVTasks/README.md) if added to the project. The resulting shaders are automatically embedded in the assembly. To specifiy that the shader path is a resource name, put the **'#'** prefix. Else the path will be search on disk. +shader are automatically compiled by [`SpirVTasks`](../../SpirVTasks/README.md) if added to the project. The resulting shaders are automatically embedded in the assembly. To specifiy that the shader path is a resource name, put the **'#'** prefix. Else the path will be search on disk. ```csharp cfg.AddShader (VkShaderStageFlags.Vertex, "#shaders.main.vert.spv"); cfg.AddShader (VkShaderStageFlags.Fragment, "#shaders.main.frag.spv"); diff --git a/samples/Triangle/main.cs b/samples/Triangle/main.cs index 12007df..6914623 100644 --- a/samples/Triangle/main.cs +++ b/samples/Triangle/main.cs @@ -16,6 +16,7 @@ namespace Triangle { vke.Run (); } } + Program () : base ("triangle", 800, 600, false) { } const float rotSpeed = 0.01f, zoomSpeed = 0.01f; float rotX, rotY, zoom = 1f; @@ -119,10 +120,10 @@ namespace Triangle { protected override void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton [0]) { + if (GetButton(Glfw.MouseButton.Left) == Glfw.InputAction.Press) { rotY -= rotSpeed * (float)diffX; rotX += rotSpeed * (float)diffY; - } else if (MouseButton [1]) { + } else if (GetButton (Glfw.MouseButton.Right) == Glfw.InputAction.Press) { zoom += zoomSpeed * (float)diffY; } else return; diff --git a/samples/crowWin/Program.cs b/samples/crowWin/Program.cs index 096f5ce..d5adf88 100644 --- a/samples/crowWin/Program.cs +++ b/samples/crowWin/Program.cs @@ -79,7 +79,7 @@ namespace vkeEditor { GraphicPipelineConfig cfg = GraphicPipelineConfig.CreateDefault (VkPrimitiveTopology.TriangleList, VkSampleCountFlags.SampleCount1, true); - Program () : base () {} + Program () : base ("crow", 800,600, false) {} protected override void initVulkan () { base.initVulkan (); @@ -182,10 +182,10 @@ namespace vkeEditor { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton [0]) { + if (GetButton (MouseButton.Left) == InputAction.Press) { rotY -= rotSpeed * (float)diffX; rotX += rotSpeed * (float)diffY; - } else if (MouseButton [1]) { + } else if (GetButton (MouseButton.Right) == InputAction.Press) { zoom += zoomSpeed * (float)diffY; } else return; diff --git a/samples/deferred/DeferredPbrRenderer.cs b/samples/deferred/DeferredPbrRenderer.cs index 0c9d079..6c59d82 100644 --- a/samples/deferred/DeferredPbrRenderer.cs +++ b/samples/deferred/DeferredPbrRenderer.cs @@ -58,13 +58,13 @@ namespace deferred { }; public Light[] lights = { new Light { - position = new Vector4(1.5f,2.5f,1.5f,0f), + position = new Vector4(1.5f,0.5f,0.5f,0f), color = new Vector4(1,1.0f,1.0f,1) - }, + }/*, new Light { position = new Vector4(-1.5f,2.5f,1.5f,0f), color = new Vector4(0.8f,0.8f,1,1) - } + }*/ }; FrameBuffer frameBuffer; diff --git a/samples/deferred/main.cs b/samples/deferred/main.cs index a735ee9..7ae0dc3 100644 --- a/samples/deferred/main.cs +++ b/samples/deferred/main.cs @@ -18,7 +18,7 @@ namespace deferred { static void Main (string[] args) { #if DEBUG Instance.VALIDATION = true; - Instance.RENDER_DOC_CAPTURE = true; + Instance.RENDER_DOC_CAPTURE = false; #endif SwapChain.PREFERED_FORMAT = VkFormat.B8g8r8a8Srgb; DeferredPbrRenderer.TEXTURE_ARRAY = true; @@ -221,9 +221,9 @@ namespace deferred { protected override void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[0]) { + if (GetButton (MouseButton.Left) == InputAction.Press) { camera.Rotate ((float)-diffY, (float)-diffX, 0); - } else if (MouseButton[1]) { + } else if (GetButton (MouseButton.Right) == InputAction.Press) { camera.SetZoom ((float)diffY); } else return; diff --git a/samples/deferred/shaders/tone_mapping.frag b/samples/deferred/shaders/tone_mapping.frag index 98f4a69..a2e354c 100644 --- a/samples/deferred/shaders/tone_mapping.frag +++ b/samples/deferred/shaders/tone_mapping.frag @@ -14,21 +14,7 @@ layout (location = 0) out vec4 outColor; void main() { - ivec2 ts = textureSize(samplerHDR); - vec4 hdrColor = texelFetch (samplerHDR, ivec2(gl_FragCoord.xy), gl_SampleID); - //vec4 hdrColor = texelFetch (samplerHDR, inUV); - //vec4 c = texture (bloom, inUV); - //float lum = (0.299*c.r + 0.587*c.g + 0.114*c.b); - //if (lum>1.0) - // hdrColor.rgb += c.rgb * 0.05; - //outColor = SRGBtoLINEAR(tonemap(hdrColor, exposure, gamma)); - outColor = tonemap(hdrColor, exposure, gamma); - - - /* - outColor = vec4(SRGBtoLINEAR(tonemap(hdrColor.rgb)), hdrColor.a);;*/ - -/* vec3 mapped = vec3(1.0) - exp(-hdrColor.rgb * pc.exposure); - mapped = pow(mapped, vec3(1.0 / pc.gamma)); - outColor = vec4(mapped, hdrColor.a);*/ + ivec2 ts = textureSize(samplerHDR); + vec4 hdrColor = texelFetch (samplerHDR, ivec2(gl_FragCoord.xy), gl_SampleID); + outColor = tonemap(hdrColor, exposure, gamma); } \ No newline at end of file diff --git a/samples/pbr/PbrPipeline.cs b/samples/pbr/PbrPipeline.cs index 28e3760..c4ee105 100644 --- a/samples/pbr/PbrPipeline.cs +++ b/samples/pbr/PbrPipeline.cs @@ -43,13 +43,7 @@ namespace vke { public PbrModel2 model; public vke.Environment.EnvironmentCube envCube; - string[] cubemapPathes = { - Utils.DataDirectory + "textures/papermill.ktx", - Utils.DataDirectory + "textures/cubemap_yokohama_bc3_unorm.ktx", - Utils.DataDirectory + "textures/gcanyon_cube.ktx", - Utils.DataDirectory + "textures/pisa_cube.ktx", - Utils.DataDirectory + "textures/uffizi_cube.ktx", - }; + string[] cubemapPathes = samples.Utils.CubeMaps; public PBRPipeline (Queue staggingQ, RenderPass renderPass, PipelineCache pipelineCache = null) : base (renderPass, pipelineCache, "pbr pipeline") { diff --git a/samples/pbr/main.cs b/samples/pbr/main.cs index 9ce48eb..453fc0a 100644 --- a/samples/pbr/main.cs +++ b/samples/pbr/main.cs @@ -49,29 +49,7 @@ namespace pbrSample { roughness } - string[] modelPathes = { - Utils.DataDirectory + "models/DamagedHelmet/glTF/DamagedHelmet.gltf", - Utils.DataDirectory + "models/Hubble.glb", - Utils.DataDirectory + "models/ISS_stationary.glb", - Utils.DataDirectory + "models/MER_static.glb", - Utils.DataDirectory + "models/Box.gltf", - - /*"/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/Avocado/glTF/Avocado.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/BarramundiFish/glTF/BarramundiFish.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/BoomBoxWithAxes/glTF/BoomBoxWithAxes.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/Box/glTF/Box.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/EnvironmentTest/glTF/EnvironmentTest.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/MetalRoughSpheres/glTF/MetalRoughSpheres.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/OrientationTest/glTF/OrientationTest.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/Buggy/glTF/Buggy.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/2CylinderEngine/glTF-Embedded/2CylinderEngine.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/FlightHelmet/glTF/FlightHelmet.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/GearboxAssy/glTF/GearboxAssy.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/Lantern/glTF/Lantern.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/SciFiHelmet/glTF/SciFiHelmet.gltf", - "/mnt/devel/vulkan/glTF-Sample-Models-master/2.0/Sponza/glTF/Sponza.gltf", - "/mnt/devel/vkChess/data/chess.gltf"*/ - }; + string[] modelPathes = vke.samples.Utils.GltfFiles; DebugView currentDebugView = DebugView.none; @@ -198,6 +176,7 @@ namespace pbrSample { bool rebuildBuffers, reloadModel; void buildCommandBuffers () { + dev.WaitIdle (); for (int i = 0; i < swapChain.ImageCount; ++i) { cmds[i]?.Free (); cmds[i] = cmdPool.AllocateAndStart (); @@ -248,6 +227,8 @@ namespace pbrSample { pbrPipeline.matrices.camPos = new Vector4 (inv.M41, inv.M42, inv.M43, 0); pbrPipeline.matrices.debugViewInputs = (float)currentDebugView; + dev.WaitIdle (); + pbrPipeline.uboMats.Update (pbrPipeline.matrices, (uint)Marshal.SizeOf ()); updateViewRequested = false; @@ -295,9 +276,9 @@ namespace pbrSample { protected override void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[0]) { - camera.Rotate ((float)-diffY, (float)-diffX,0); - } else if (MouseButton[1]) { + if (GetButton(MouseButton.Left)== InputAction.Press) { + camera.Rotate ((float)-diffY, (float)-diffX, 0); + } else if (GetButton (MouseButton.Right) == InputAction.Press) { camera.SetZoom ((float)diffY); } else return; diff --git a/samples/pbr/pbr.csproj b/samples/pbr/pbr.csproj index 1648b09..1d92e8e 100644 --- a/samples/pbr/pbr.csproj +++ b/samples/pbr/pbr.csproj @@ -1,9 +1,9 @@ - + vke.simpletexture.frag.spv diff --git a/samples/vkeEditor/Program.cs b/samples/vkeEditor/Program.cs index 9eeec69..0e94860 100644 --- a/samples/vkeEditor/Program.cs +++ b/samples/vkeEditor/Program.cs @@ -223,10 +223,10 @@ namespace vkeEditor { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton [0]) { + if (GetButton (MouseButton.Left) == InputAction.Press) { rotY -= rotSpeed * (float)diffX; rotX += rotSpeed * (float)diffY; - } else if (MouseButton [1]) { + } else if (GetButton (MouseButton.Right) == InputAction.Press) { zoom += zoomSpeed * (float)diffY; } else return; diff --git a/vke/src/VkWindow.cs b/vke/src/VkWindow.cs index 54424d8..e30d359 100644 --- a/vke/src/VkWindow.cs +++ b/vke/src/VkWindow.cs @@ -41,7 +41,6 @@ namespace vke { protected bool updateViewRequested = true; protected double lastMouseX { get; private set; } protected double lastMouseY { get; private set; } - protected bool[] MouseButton => buttons; /// readonly GLFW window handle public IntPtr WindowHandle => hWin; @@ -49,7 +48,6 @@ namespace vke { /**Default camera initialized with a Field of view of 40° and and aspect ratio of 1. */ protected Camera camera = new Camera (Utils.DegreesToRadians (45f), 1f); - bool[] buttons = new bool[10]; public Modifier KeyModifiers = 0; IntPtr currentCursor; uint frameCount; @@ -155,8 +153,9 @@ namespace vke { configureEnabledFeatures (phy.Features, ref enabledFeatures); //First create the c# device class - dev = new Device (phy); - dev.debugUtilsEnabled = instance.debugUtilsEnabled;//store a boolean to prevent testing against the extension string presence. + dev = new Device (phy) { + debugUtilsEnabled = instance.debugUtilsEnabled//store a boolean to prevent testing against the extension string presence. + }; //create queue class createQueues (); @@ -207,8 +206,8 @@ namespace vke { } /// - /// Main render method called each frame. get next swapchain image, process resize if needed, submit and present to the presentQueue. - /// Wait QueueIdle after presenting. + /// Main render method called each frame. + /// First get next swapchain image, process resize if needed, submit and present to the presentQueue. /// protected virtual void render () { int idx = swapChain.GetNextImage (); @@ -225,18 +224,16 @@ namespace vke { presentQueue.Submit (cmds[idx], swapChain.presentComplete, drawComplete[idx], drawFence); presentQueue.Present (swapChain, drawComplete[idx]); - - //presentQueue.WaitIdle (); } protected virtual void onScroll (double xOffset, double yOffset) { } protected virtual void onMouseMove (double xPos, double yPos) { double diffX = lastMouseX - xPos; double diffY = lastMouseY - yPos; - if (MouseButton[(int)Glfw.MouseButton.Left]) { + if (GetButton(MouseButton.Left) == InputAction.Press) { camera.Rotate ((float)-diffX, (float)-diffY); updateViewRequested = true; - } else if (MouseButton[(int)Glfw.MouseButton.Right]) { + } else if (GetButton (MouseButton.Right) == InputAction.Press) { camera.Move ((float)diffX,0,0); camera.Move (0, 0, (float)-diffY); updateViewRequested = true; @@ -283,32 +280,30 @@ namespace vke { protected virtual void onKeyUp (Key key, int scanCode, Modifier modifiers) { } protected virtual void onChar (CodePoint cp) { } - #region events delegates + protected InputAction GetButton (MouseButton button) => + Glfw3.GetMouseButton (hWin, button); + #region events delegates static CursorPosDelegate HandleCursorPosDelegate = (window, xPosition, yPosition) => { windows[window].onMouseMove (xPosition, yPosition); windows[window].lastMouseX = xPosition; windows[window].lastMouseY = yPosition; }; static MouseButtonDelegate HandleMouseButtonDelegate = (IntPtr window, Glfw.MouseButton button, InputAction action, Modifier mods) => { - if (action == InputAction.Press) { - windows[window].buttons[(int)button] = true; + if (action == InputAction.Press) windows[window].onMouseButtonDown (button); - } else { - windows[window].buttons[(int)button] = false; + else windows[window].onMouseButtonUp (button); - } }; static ScrollDelegate HandleScrollDelegate = (IntPtr window, double xOffset, double yOffset) => { windows[window].onScroll (xOffset, yOffset); }; static KeyDelegate HandleKeyDelegate = (IntPtr window, Key key, int scanCode, InputAction action, Modifier modifiers) => { windows[window].KeyModifiers = modifiers; - if (action == InputAction.Press || action == InputAction.Repeat) { + if (action == InputAction.Press || action == InputAction.Repeat) windows[window].onKeyDown (key, scanCode, modifiers); - } else { + else windows[window].onKeyUp (key, scanCode, modifiers); - } }; static CharDelegate HandleCharDelegate = (IntPtr window, CodePoint codepoint) => { windows[window].onChar (codepoint); diff --git a/vke/src/base/Buffer.cs b/vke/src/base/Buffer.cs index aa25004..2139b70 100644 --- a/vke/src/base/Buffer.cs +++ b/vke/src/base/Buffer.cs @@ -115,7 +115,7 @@ namespace vke { /// an offset in the destination buffer for the copy operation. public void CopyTo (CommandBuffer cmd, Buffer buff, ulong size = 0, ulong srcOffset = 0, ulong dstOffset = 0) { VkBufferCopy bufferCopy = new VkBufferCopy { - size = (size == 0) ? AllocatedDeviceMemorySize : size, + size = (size == 0) ? createInfo.size: size, srcOffset = srcOffset, dstOffset = dstOffset }; diff --git a/vke/src/base/ComputePipeline.cs b/vke/src/base/ComputePipeline.cs index 1d61ad8..b3c6ec5 100644 --- a/vke/src/base/ComputePipeline.cs +++ b/vke/src/base/ComputePipeline.cs @@ -39,8 +39,6 @@ namespace vke { info.basePipelineIndex = 0; Utils.CheckResult (Vk.vkCreateComputePipelines (Dev.VkDev, Cache == null ? VkPipelineCache.Null : Cache.handle, 1, ref info, IntPtr.Zero, out handle)); - - Dev.DestroyShaderModule (info.stage.module); } } base.Activate (); diff --git a/vke/src/ktx.cs b/vke/src/ktx.cs index c9a8ccf..2c38068 100644 --- a/vke/src/ktx.cs +++ b/vke/src/ktx.cs @@ -97,7 +97,7 @@ namespace KTX { uint blockSize = blockW * blockH; if (memoryProperty.HasFlag (VkMemoryPropertyFlags.DeviceLocal)) { - ulong staggingSize = (ulong)ktxStream.Length + 256;//img.AllocatedDeviceMemorySize; + ulong staggingSize = img.AllocatedDeviceMemorySize; Console.WriteLine ($"KtxStream size = {ktxStream.Length}, img Allocation = {img.AllocatedDeviceMemorySize}"); using (HostBuffer stagging = new HostBuffer (staggingQ.Dev, VkBufferUsageFlags.TransferSrc, staggingSize)) { diff --git a/vke/vke.csproj b/vke/vke.csproj index 8def075..4544111 100644 --- a/vke/vke.csproj +++ b/vke/vke.csproj @@ -49,7 +49,7 @@ - +