diff --git a/Samples/SampleControl/SampleControl.csproj b/Samples/SampleControl/SampleControl.csproj index b867316..b89fc47 100644 --- a/Samples/SampleControl/SampleControl.csproj +++ b/Samples/SampleControl/SampleControl.csproj @@ -36,21 +36,17 @@ 4 - - ..\packages\SharpDX.3.0.2\lib\net45\SharpDX.dll - True + + ..\..\WpfSharpDxControl\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll - - ..\packages\SharpDX.Direct2D1.3.0.2\lib\net45\SharpDX.Direct2D1.dll - True + + ..\..\WpfSharpDxControl\packages\SharpDX.Direct2D1.4.2.0\lib\net45\SharpDX.Direct2D1.dll - - ..\packages\SharpDX.DXGI.3.0.2\lib\net45\SharpDX.DXGI.dll - True + + ..\..\WpfSharpDxControl\packages\SharpDX.DXGI.4.2.0\lib\net45\SharpDX.DXGI.dll - - ..\packages\SharpDX.Mathematics.3.0.2\lib\net45\SharpDX.Mathematics.dll - True + + ..\..\WpfSharpDxControl\packages\SharpDX.Mathematics.4.2.0\lib\net45\SharpDX.Mathematics.dll diff --git a/Samples/SampleControl/packages.config b/Samples/SampleControl/packages.config index a3c3d1c..2361da6 100644 --- a/Samples/SampleControl/packages.config +++ b/Samples/SampleControl/packages.config @@ -1,7 +1,7 @@  - - - - + + + + \ No newline at end of file diff --git a/Samples/SampleControl3d/App.config b/Samples/SampleControl3d/App.config new file mode 100644 index 0000000..84fba31 --- /dev/null +++ b/Samples/SampleControl3d/App.config @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Samples/SampleControl3d/App.xaml b/Samples/SampleControl3d/App.xaml new file mode 100644 index 0000000..f7e0349 --- /dev/null +++ b/Samples/SampleControl3d/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/Samples/SampleControl3d/App.xaml.cs b/Samples/SampleControl3d/App.xaml.cs new file mode 100644 index 0000000..f05e39e --- /dev/null +++ b/Samples/SampleControl3d/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace SampleControl3d +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/Samples/SampleControl3d/MainWindow.xaml b/Samples/SampleControl3d/MainWindow.xaml new file mode 100644 index 0000000..f65413e --- /dev/null +++ b/Samples/SampleControl3d/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/Samples/SampleControl3d/MainWindow.xaml.cs b/Samples/SampleControl3d/MainWindow.xaml.cs new file mode 100644 index 0000000..ad777f2 --- /dev/null +++ b/Samples/SampleControl3d/MainWindow.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace SampleControl3d +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + } +} diff --git a/Samples/SampleControl3d/Properties/AssemblyInfo.cs b/Samples/SampleControl3d/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..81c06d6 --- /dev/null +++ b/Samples/SampleControl3d/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SampleControl3d")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SampleControl3d")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +//In order to begin building localizable applications, set +//CultureYouAreCodingWith in your .csproj file +//inside a . For example, if you are using US english +//in your source files, set the to en-US. Then uncomment +//the NeutralResourceLanguage attribute below. Update the "en-US" in +//the line below to match the UICulture setting in the project file. + +//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] + + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] + + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Samples/SampleControl3d/Properties/Resources.Designer.cs b/Samples/SampleControl3d/Properties/Resources.Designer.cs new file mode 100644 index 0000000..96846cc --- /dev/null +++ b/Samples/SampleControl3d/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SampleControl3d.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SampleControl3d.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/Samples/SampleControl3d/Properties/Resources.resx b/Samples/SampleControl3d/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/Samples/SampleControl3d/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/Samples/SampleControl3d/Properties/Settings.Designer.cs b/Samples/SampleControl3d/Properties/Settings.Designer.cs new file mode 100644 index 0000000..dc1c329 --- /dev/null +++ b/Samples/SampleControl3d/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SampleControl3d.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/Samples/SampleControl3d/Properties/Settings.settings b/Samples/SampleControl3d/Properties/Settings.settings new file mode 100644 index 0000000..033d7a5 --- /dev/null +++ b/Samples/SampleControl3d/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Samples/SampleControl3d/Sample3DRenderer.cs b/Samples/SampleControl3d/Sample3DRenderer.cs new file mode 100644 index 0000000..c02a6a2 --- /dev/null +++ b/Samples/SampleControl3d/Sample3DRenderer.cs @@ -0,0 +1,131 @@ +/* + * MIT License + * + * Copyright 2018 Marvin Neurath + * 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. + */ + +using System; +using System.Diagnostics; +using SharpDX; +using SharpDX.D3DCompiler; +using SharpDX.Direct3D; +using SharpDX.Direct3D11; +using SharpDX.DXGI; +using WpfSharpDxControl; +using Buffer = SharpDX.Direct3D11.Buffer; + +namespace SampleControl3d { + /// + /// A sample implementation showcasing how to implement 3d DirectX11 rendering in a WPF UserControl. + /// Influenced by + /// + /// + public class Sample3DRenderer : DirectXComponent { + //unit cube, read as [vertex1_position,vertex1_color,vertex2_position,vertex2_color,....] + private static readonly Vector4[] vertsPosColor = { + new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), // Front + new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), new Vector4(1.0f, 1.0f, -1.0f, 1.0f), + new Vector4(1.0f, 0.0f, 0.0f, 1.0f), new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), + new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 0.0f, 1.0f), new Vector4(1.0f, -1.0f, -1.0f, 1.0f), + new Vector4(1.0f, 0.0f, 0.0f, 1.0f), new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), + new Vector4(0.0f, 1.0f, 0.0f, 1.0f), // BACK + new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), + new Vector4(0.0f, 1.0f, 0.0f, 1.0f), new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), + new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 0.0f, 1.0f), new Vector4(1.0f, 1.0f, 1.0f, 1.0f), + new Vector4(0.0f, 1.0f, 0.0f, 1.0f), new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), + new Vector4(0.0f, 0.0f, 1.0f, 1.0f), // Top + new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 1.0f, 1.0f), + new Vector4(0.0f, 0.0f, 1.0f, 1.0f), new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), + new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 0.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, -1.0f, 1.0f), + new Vector4(0.0f, 0.0f, 1.0f, 1.0f), new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), + new Vector4(1.0f, 1.0f, 0.0f, 1.0f), // Bottom + new Vector4(1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), + new Vector4(1.0f, 1.0f, 0.0f, 1.0f), new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), + new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 1.0f, 0.0f, 1.0f), new Vector4(1.0f, -1.0f, 1.0f, 1.0f), + new Vector4(1.0f, 1.0f, 0.0f, 1.0f), new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), + new Vector4(1.0f, 0.0f, 1.0f, 1.0f), // Left + new Vector4(-1.0f, -1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f), new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), + new Vector4(1.0f, 0.0f, 1.0f, 1.0f), new Vector4(-1.0f, -1.0f, -1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f), + new Vector4(-1.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 0.0f, 1.0f, 1.0f), new Vector4(-1.0f, 1.0f, -1.0f, 1.0f), + new Vector4(1.0f, 0.0f, 1.0f, 1.0f), new Vector4(1.0f, -1.0f, -1.0f, 1.0f), + new Vector4(0.0f, 1.0f, 1.0f, 1.0f), // Right + new Vector4(1.0f, 1.0f, 1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, -1.0f, 1.0f, 1.0f), + new Vector4(0.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, -1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f), + new Vector4(1.0f, 1.0f, -1.0f, 1.0f), new Vector4(0.0f, 1.0f, 1.0f, 1.0f), new Vector4(1.0f, 1.0f, 1.0f, 1.0f), + new Vector4(0.0f, 1.0f, 1.0f, 1.0f) + }; + + //clock to keep track of time passed + private Stopwatch clock; + + //mvp const buffer + private Buffer constantBuffer; + + protected override void InternalInitialize() { + base.InternalInitialize(); + CreateResources(); + } + + private void CreateResources() { + //compile and set vertexbuffer + using (var shaderBytecode = ShaderBytecode.CompileFromFile("./Shaders/shader.hlsl", "VS", "vs_4_0")) { + var signature = ShaderSignature.GetInputSignature(shaderBytecode); + // Layout from VertexShader input signature + var layout = new InputLayout(Device, signature, + new[] { + new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), + new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) + }); + + + Device.ImmediateContext.InputAssembler.InputLayout = layout; + Device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; + + //create & set vertex buffer + var vertexBuffer = Buffer.Create(Device, BindFlags.VertexBuffer, vertsPosColor); + //stride here position+color = SizeOf * 2 + Device.ImmediateContext.InputAssembler.SetVertexBuffers(0, + new VertexBufferBinding(vertexBuffer, Utilities.SizeOf() * 2, 0)); + Device.ImmediateContext.VertexShader.Set(new VertexShader(Device, shaderBytecode)); + } + + //compile and set vertexshader + using (var bytecode = ShaderBytecode.CompileFromFile("./Shaders/shader.hlsl", "PS", "ps_4_0")) { + Device.ImmediateContext.PixelShader.Set(new PixelShader(Device, bytecode)); + } + + //setup constant buffer for mvp matrix + constantBuffer = new Buffer(Device, Utilities.SizeOf(), ResourceUsage.Default, BindFlags.ConstantBuffer, + CpuAccessFlags.None, ResourceOptionFlags.None, 0); + Device.ImmediateContext.VertexShader.SetConstantBuffer(0, constantBuffer); + + //create a clock to animate in render call + clock = new Stopwatch(); + clock.Start(); + } + + protected override void Render() { + //reset render target + Device.ImmediateContext.ClearRenderTargetView(RenderTargetView, Color.Black); + + //create model-view-projection matrix + var viewMat = Matrix.LookAtLH(new Vector3(0, 0, -5), new Vector3(0, 0, 0), Vector3.UnitY); + var projMat = Matrix.PerspectiveFovLH((float) Math.PI / 4.0f, SurfaceWidth / (float) SurfaceHeight, 0.1f, 100.0f); + + var time = clock.ElapsedMilliseconds / 1000f; + var modelMat = Matrix.RotationY(time) * Matrix.RotationX(time * 2) * Matrix.RotationZ(time * 0.7f); + var mvpMat = modelMat * viewMat * projMat; + + Device.ImmediateContext.UpdateSubresource(ref mvpMat, constantBuffer); + Device.ImmediateContext.Draw(36, 0); + } + } +} \ No newline at end of file diff --git a/Samples/SampleControl3d/SampleControl3d.csproj b/Samples/SampleControl3d/SampleControl3d.csproj new file mode 100644 index 0000000..66e40b7 --- /dev/null +++ b/Samples/SampleControl3d/SampleControl3d.csproj @@ -0,0 +1,126 @@ + + + + + Debug + AnyCPU + {8413C38D-174C-4DB9-AA55-D2A4AFA7B37B} + WinExe + SampleControl3d + SampleControl3d + v4.6.1 + 512 + {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 4 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\WpfSharpDxControl\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll + + + ..\WpfSharpDxControl\packages\SharpDX.D3DCompiler.3.1.1\lib\net45\SharpDX.D3DCompiler.dll + + + ..\WpfSharpDxControl\packages\SharpDX.Direct3D11.4.2.0\lib\net45\SharpDX.Direct3D11.dll + + + ..\WpfSharpDxControl\packages\SharpDX.DXGI.4.2.0\lib\net45\SharpDX.DXGI.dll + + + ..\WpfSharpDxControl\packages\SharpDX.Mathematics.4.2.0\lib\net45\SharpDX.Mathematics.dll + + + + + + + + + + + 4.0 + + + + + + + + MSBuild:Compile + Designer + + + + MSBuild:Compile + Designer + + + App.xaml + Code + + + MainWindow.xaml + Code + + + + + Code + + + True + True + Resources.resx + + + True + Settings.settings + True + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + + + + {1728D4D2-0F6F-4CB9-A834-1CBB5E545890} + WpfSharpDxControl + + + + + Always + + + + \ No newline at end of file diff --git a/Samples/SampleControl3d/Shaders/shader.hlsl b/Samples/SampleControl3d/Shaders/shader.hlsl new file mode 100644 index 0000000..9a06f7f --- /dev/null +++ b/Samples/SampleControl3d/Shaders/shader.hlsl @@ -0,0 +1,28 @@ +struct VS_IN +{ + float4 pos : POSITION; + float4 col : COLOR; +}; + +struct PS_IN +{ + float4 pos : SV_POSITION; + float4 col : COLOR; +}; + +float4x4 mvpMat; + +PS_IN VS(VS_IN input) +{ + PS_IN output = (PS_IN)0; + + output.pos = mul(mvpMat,input.pos); + output.col = input.col; + + return output; +} + +float4 PS(PS_IN input) : SV_Target +{ + return input.col; +} \ No newline at end of file diff --git a/Samples/SampleControl3d/packages.config b/Samples/SampleControl3d/packages.config new file mode 100644 index 0000000..a333119 --- /dev/null +++ b/Samples/SampleControl3d/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/WpfSharpDxControl/DirectXComponent.cs b/WpfSharpDxControl/DirectXComponent.cs index 666a966..6156acd 100644 --- a/WpfSharpDxControl/DirectXComponent.cs +++ b/WpfSharpDxControl/DirectXComponent.cs @@ -110,7 +110,7 @@ protected virtual void InternalInitialize() Usage = Usage.RenderTargetOutput | Usage.Shared }; - SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, swapChainDescription, out _device, out _swapChain); + Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, swapChainDescription, out _device, out _swapChain); // Ignore all windows events using (var factory = _swapChain.GetParent()) @@ -157,7 +157,7 @@ protected virtual void BeginRender() /// protected virtual void EndRender() { - _swapChain.Present(1, PresentFlags.None); + _swapChain.Present(0, PresentFlags.None); } /// diff --git a/WpfSharpDxControl/Win32HwndControl.cs b/WpfSharpDxControl/Win32HwndControl.cs index 1b81261..2d2421c 100644 --- a/WpfSharpDxControl/Win32HwndControl.cs +++ b/WpfSharpDxControl/Win32HwndControl.cs @@ -32,19 +32,13 @@ protected Win32HwndControl() private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { Initialize(); - HwndInitialized = true; - - Loaded -= OnLoaded; + HwndInitialized = true; } private void OnUnloaded(object sender, RoutedEventArgs routedEventArgs) { Uninitialize(); HwndInitialized = false; - - Unloaded -= OnUnloaded; - - Dispose(); } protected abstract void Initialize(); diff --git a/WpfSharpDxControl/WpfSharpDxControl.csproj b/WpfSharpDxControl/WpfSharpDxControl.csproj index 017af25..806312e 100644 --- a/WpfSharpDxControl/WpfSharpDxControl.csproj +++ b/WpfSharpDxControl/WpfSharpDxControl.csproj @@ -33,25 +33,20 @@ - - packages\SharpDX.3.0.2\lib\net45\SharpDX.dll - True + + packages\SharpDX.4.2.0\lib\net45\SharpDX.dll - - packages\SharpDX.Direct2D1.3.0.2\lib\net45\SharpDX.Direct2D1.dll - True + + packages\SharpDX.Direct2D1.4.2.0\lib\net45\SharpDX.Direct2D1.dll - - packages\SharpDX.Direct3D11.3.0.2\lib\net45\SharpDX.Direct3D11.dll - True + + packages\SharpDX.Direct3D11.4.2.0\lib\net45\SharpDX.Direct3D11.dll - - packages\SharpDX.DXGI.3.0.2\lib\net45\SharpDX.DXGI.dll - True + + packages\SharpDX.DXGI.4.2.0\lib\net45\SharpDX.DXGI.dll - - packages\SharpDX.Mathematics.3.0.2\lib\net45\SharpDX.Mathematics.dll - True + + packages\SharpDX.Mathematics.4.2.0\lib\net45\SharpDX.Mathematics.dll diff --git a/WpfSharpDxControl/WpfSharpDxControl.sln b/WpfSharpDxControl/WpfSharpDxControl.sln index d959549..9df2090 100644 --- a/WpfSharpDxControl/WpfSharpDxControl.sln +++ b/WpfSharpDxControl/WpfSharpDxControl.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2003 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfSharpDxControl", "WpfSharpDxControl.csproj", "{1728D4D2-0F6F-4CB9-A834-1CBB5E545890}" EndProject @@ -9,6 +9,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{807F EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleControl", "..\Samples\SampleControl\SampleControl.csproj", "{C6FB58ED-8931-4845-9688-B2052BF17BEC}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleControl3d", "..\Samples\SampleControl3d\SampleControl3d.csproj", "{8413C38D-174C-4DB9-AA55-D2A4AFA7B37B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -23,11 +25,19 @@ Global {C6FB58ED-8931-4845-9688-B2052BF17BEC}.Debug|Any CPU.Build.0 = Debug|Any CPU {C6FB58ED-8931-4845-9688-B2052BF17BEC}.Release|Any CPU.ActiveCfg = Release|Any CPU {C6FB58ED-8931-4845-9688-B2052BF17BEC}.Release|Any CPU.Build.0 = Release|Any CPU + {8413C38D-174C-4DB9-AA55-D2A4AFA7B37B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8413C38D-174C-4DB9-AA55-D2A4AFA7B37B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8413C38D-174C-4DB9-AA55-D2A4AFA7B37B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8413C38D-174C-4DB9-AA55-D2A4AFA7B37B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {C6FB58ED-8931-4845-9688-B2052BF17BEC} = {807F3657-0D0E-4AE4-A3D4-88578E24ADF6} + {8413C38D-174C-4DB9-AA55-D2A4AFA7B37B} = {807F3657-0D0E-4AE4-A3D4-88578E24ADF6} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6F1B28A3-D951-47A1-B52D-C89FB216BCD1} EndGlobalSection EndGlobal diff --git a/WpfSharpDxControl/packages.config b/WpfSharpDxControl/packages.config index c757b51..1770d0c 100644 --- a/WpfSharpDxControl/packages.config +++ b/WpfSharpDxControl/packages.config @@ -1,8 +1,8 @@  - - - - - + + + + + \ No newline at end of file