示例#1
0
 private void InitializeImageSource()
 {
     _d3D11Image = new D3D11Image();
     _d3D11Image.IsFrontBufferAvailableChanged += OnIsFrontBufferAvailableChanged;
     CreateBackBuffer();
     Source = _d3D11Image;
 }
示例#2
0
            public static RenderData Find(D3D11Image d3D11Image, bool createIfNotFound = true)
            {
                if (d3D11Image == null)
                {
                    return(null);
                }

                lock (s_aRenderData)
                {
                    RenderData renderData = s_aRenderData.FirstOrDefault(rd => rd.D3D11Image == d3D11Image);
                    if (renderData != null)
                    {
                        return(renderData);
                    }

                    if (createIfNotFound == false)
                    {
                        return(null);
                    }

                    s_aRenderData.Add(renderData = new RenderData(d3D11Image));

                    return(renderData);
                }
            }
示例#3
0
        public void Initialize(IntPtr hWnd, D3D11Image dxImage)
        {
            if (hWnd == IntPtr.Zero)
            {
                MessageBox.Show("");
            }
            _hWnd    = hWnd;
            _dxImage = dxImage;

            _dxImage.WindowOwner = hWnd;
            _dxImage.OnRender    = Render;
        }
示例#4
0
        public LaigeRenderer(double dpi, double width, double height, IntPtr owner)
        {
            _Initialize();

            d3d11Image             = new D3D11Image();
            d3d11Image.WindowOwner = owner;

            enableGraphicsDebugger = false;

            SizeChanged(width, height, dpi);
            d3d11Image.OnRender += Draw;
        }
示例#5
0
        /// <summary>Set the render target size of this D3D11Image from the given visual</summary>
        public static void SetRenderTargetSize(this D3D11Image d3d_image, FrameworkElement element)
        {
            // Set the screen render target size, accounting for DPI
            var win        = PresentationSource.FromVisual(element)?.CompositionTarget as HwndTarget;
            var dpi_scaleX = win?.TransformToDevice.M11 ?? 1.0;
            var dpi_scaleY = win?.TransformToDevice.M22 ?? 1.0;

            // Determine the texture size
            var width  = Math.Max(1, (int)Math.Ceiling(element.ActualWidth * dpi_scaleX));
            var height = Math.Max(1, (int)Math.Ceiling(element.ActualHeight * dpi_scaleY));

            d3d_image.SetRenderTargetSize(width, height, dpi_scaleX, dpi_scaleY);
        }
示例#6
0
        public View3dControl()
        {
            InitializeComponent();
            Stretch           = Stretch.Fill;
            StretchDirection  = StretchDirection.Both;
            UseLayoutRounding = true;
            Focusable         = true;

            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            try
            {
                // Initialise View3d in off-screen only mode (i.e. no window handle)
                View3d        = View3d.Create();
                Window        = new View3d.Window(View3d, IntPtr.Zero);
                Window.Error += (s, a) => OnReportError(new ReportErrorEventArgs(a.Message));
                Camera.Lookat(new v4(0, 0, 10, 1), v4.Origin, v4.YAxis);
                Camera.ClipPlanes(0.01f, 1000f, true);

                // Create a D3D11 off-screen render target image source
                Source = D3DImage = new D3D11Image();

                // Set defaults
                BackgroundColour         = Window.BackgroundColour;
                DesiredPixelAspect       = 1;
                ClickTimeMS              = 180;
                MouseNavigation          = true;
                DefaultKeyboardShortcuts = true;
                ViewPreset = EViewPreset.Current;

                // Default context menu implementation
                if (ContextMenu != null && ContextMenu.DataContext == null)
                {
                    ContextMenu.DataContext = this;
                }

                InitCommands();
                DataContext = this;
            }
            catch
            {
                Dispose();
                throw;
            }
        }
示例#7
0
        private void UnitializeImageSource()
        {
            Source = null;

            if (_d3D11Image != null)
            {
                _d3D11Image.IsFrontBufferAvailableChanged -= OnIsFrontBufferAvailableChanged;
                _d3D11Image.Dispose();
                _d3D11Image = null;
            }
            if (_sharedRenderTarget != null)
            {
                _sharedRenderTarget.Dispose();
                _sharedRenderTarget = null;
            }
            if (_cachedRenderTarget != null)
            {
                _cachedRenderTarget.Dispose();
                _cachedRenderTarget = null;
            }
        }
示例#8
0
        static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            D3D11Image d3D11Image = d as D3D11Image;

            if (d3D11Image == null)
            {
                return;
            }

            d3D11Image.OnRender = null;

            ICommandListFactory commandListFactory = e.NewValue as ICommandListFactory;

            if (commandListFactory == null)
            {
                return;
            }

            RenderData _renderData = RenderData.Find(d3D11Image, true);

            if (_renderData == null)
            {
                return;
            }

            GraphicsDevice _graphicsDevice = _renderData.graphicsDevice;

            if (_graphicsDevice == null)
            {
                return;
            }

            SharpDX.Direct3D11.Device _device = _renderData.device;
            if (_device == null)
            {
                return;
            }

            d3D11Image.OnRender = (IntPtr surface, bool isNewSurface) =>
            {
                #region --- OnRender
                Framebuffer _framebuffer = _renderData.FrameBuffer(surface, isNewSurface);
                if (_framebuffer == null)
                {
                    return;
                }

                Veldrid.CommandList commandList = null;
                try
                {
                    commandList = commandListFactory.BuildCommandList(_graphicsDevice, _framebuffer);
                    if (commandList == null)
                    {
                        return;
                    }
                    _graphicsDevice.SubmitCommands(commandList);
                }
                finally
                {
                    commandList?.Dispose();
                }

                _device.ImmediateContext.Flush();
                #endregion
            };
        }
示例#9
0
 RenderData(D3D11Image d3D11Image)
 {
     m_d3D11Image = d3D11Image;
 }