private void devices_OnDpiChanged(DeviceManager obj) { if (OnSizeChanged != null) OnSizeChanged(this); }
/// <summary> /// Initializes the model. /// </summary> /// <param name="deviceManager">The device manager.</param> private void Initialize(DeviceManager deviceManager) { foreach (Element3D e in this.Items) { e.Initialize(deviceManager); } }
/// <summary> /// Initializes this instance. /// </summary> /// <param name="deviceManager">The device manager</param> public virtual void Initialize(DeviceManager deviceManager) { this.DeviceManager = deviceManager; // If the DPI is changed, we need to perform a OnSizeChanged event deviceManager.OnDpiChanged -= devices_OnDpiChanged; deviceManager.OnDpiChanged += devices_OnDpiChanged; }
/// <summary> /// Creates the device manager and image source when the viewport is loaded. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="RoutedEventArgs" /> instance containing the event data.</param> private void Viewport3DXLoaded(object sender, RoutedEventArgs e) { var logicalDpi = DisplayInformation.GetForCurrentView().LogicalDpi; int pixelWidth = (int)(this.ActualWidth * logicalDpi / 96.0); int pixelHeight = (int)(this.ActualHeight * logicalDpi / 96.0); // Safely dispose any previous instance // Creates a new DeviceManager (Direct3D, Direct2D, DirectWrite, WIC) this.deviceManager = new DeviceManager(); // Use CoreWindowTarget as the rendering target (Initialize SwapChain, RenderTargetView, DepthStencilView, BitmapTarget) this.d3dTarget = new SurfaceImageSourceTarget(pixelWidth, pixelHeight); this.imageBrush = new ImageBrush(); this.imageBrush.ImageSource = this.d3dTarget.ImageSource; this.Background = this.imageBrush; this.deviceManager.OnInitialize += this.d3dTarget.Initialize; this.deviceManager.OnInitialize += this.Initialize; this.d3dTarget.OnRender += this.Render; // Initialize the device manager and all registered deviceManager.OnInitialize this.deviceManager.Initialize(DisplayInformation.GetForCurrentView().LogicalDpi); // Setup rendering callback CompositionTarget.Rendering += this.CompositionTargetRendering; // Callback on DpiChanged DisplayProperties.LogicalDpiChanged += this.DisplayPropertiesLogicalDpiChanged; }
/// <summary> /// Initializes the element. /// </summary> /// <param name="deviceManager">The device manager.</param> public virtual void Initialize(DeviceManager deviceManager) { }
/// <inveritdoc/> public override void Initialize(DeviceManager deviceManager) { base.Initialize(deviceManager); surfaceImageSourceNative.Device = ToDispose(DeviceManager.DeviceDirect3D.QueryInterface<SharpDX.DXGI.Device>()); }
public override void Initialize(DeviceManager deviceManager) { base.Initialize(deviceManager); // Remove previous buffer if (this.constantBuffer != null) { this.constantBuffer.Dispose(); } // RemoveAndDispose(ref constantBuffer); // Setup local variables var d3dDevice = deviceManager.DeviceDirect3D; var d3dContext = deviceManager.ContextDirect3D; var path = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "HelixToolkit.Win8"); // Loads vertex shader bytecode var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\MiniCube_VS.fxo"); this.vertexShader = new VertexShader(d3dDevice, vertexShaderByteCode); // Loads pixel shader bytecode this.pixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\MiniCube_PS.fxo")); // Layout from VertexShader input signature this.layout = new InputLayout( d3dDevice, vertexShaderByteCode, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) }); // Instantiate Vertex buffer from vertex data var vertices = SharpDX.Direct3D11.Buffer.Create( d3dDevice, BindFlags.VertexBuffer, new[] { 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), }); this.vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf<Vector4>() * 2, 0); // Create Constant Buffer this.constantBuffer = new SharpDX.Direct3D11.Buffer( d3dDevice, Utilities.SizeOf<SharpDX.Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0); this.clock = new Stopwatch(); this.clock.Start(); }
/// <inveritdoc/> public override void Initialize(DeviceManager deviceManager) { base.Initialize(deviceManager); surfaceImageSourceNative.Device = ToDispose(DeviceManager.DeviceDirect3D.QueryInterface <SharpDX.DXGI.Device>()); }