コード例 #1
0
ファイル: MainForm.cs プロジェクト: hammerforgegames/Gorgon
        /// <summary>
        /// Function called after a swap chain is resized.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="AfterSwapChainResizedEventArgs"/> instance containing the event data.</param>
        private void AfterSwapChainResized(object sender, AfterSwapChainResizedEventArgs e)
        {
            // Restore the render target buffer and restore the contents of it.
            _backBuffer = GorgonRenderTarget2DView.CreateRenderTarget(_graphics,
                                                                      new GorgonTexture2DInfo("Backbuffer")
            {
                Width  = ClientSize.Width,
                Height = ClientSize.Height,
                Format = BufferFormat.R8G8B8A8_UNorm
            });
            _backBuffer.Clear(Color.White);
            _backupImage.CopyTo(_backBuffer.Texture, new DX.Rectangle(0, 0, _backBuffer.Width, _backBuffer.Height));

            _backBufferView = _backBuffer.GetShaderResourceView();
        }
コード例 #2
0
        /// <summary>
        /// Handles the ValueChanged event of the TrackThreshold control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void TrackThreshold_ValueChanged(object sender, EventArgs e)
        {
            if (_sourceTexture == null)
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                // Unfortunately, because the two interfaces are disconnected, we need to ensure that we're not using a resource on the graphics side
                // when we want access to it on the compute side. This needs to be fixed as it can be a bit on the slow side to constantly do this
                // every frame.
                _sobel.Process(_sourceTexture, _outputUav, TrackThickness.Value, TrackThreshold.Value / 100.0f);

                var png = new GorgonCodecPng();
                using (var tempTexture = new GorgonTexture2D(_graphics, new GorgonTexture2DInfo(_outputTexture)
                {
                    Format = BufferFormat.R8G8B8A8_UNorm
                }))
                {
                    _outputTexture.CopyTo(tempTexture);
                    using (IGorgonImage image = tempTexture.ToImage())
                    {
                        png.SaveToFile(image, @"D:\unpak\uav.png");
                    }
                }
            }
            catch (Exception ex)
            {
                GorgonDialogs.ErrorBox(this, ex);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }