Ejemplo n.º 1
0
        public HardwareRenderTargetData([NotNull] HardwareRenderTarget renderTarget)
        {
            if (renderTarget == null)
            {
                throw new ArgumentNullException(nameof(renderTarget));
            }

            mTexture = renderTarget.GetTexture2D();
            mBox     = renderTarget.Device.ImmediateContext.MapSubresource(mTexture, 0, MapMode.Read, MapFlags.None);
            mMemory  = new ReadOnlyMemoryWindow(mBox.Data.DataPointer, mBox.Data.Length);
        }
Ejemplo n.º 2
0
        private void Destroy()
        {
            mOffScreenWindow?.Close();
            mSwapChain?.Dispose();
            mPixelShader?.Dispose();
            mVertexShader?.Dispose();
            mVertexBuffer?.Dispose();
            mVertices?.Dispose();
            mRenderTarget?.Dispose();

            mOffScreenWindow = null;
            mSwapChain       = null;
            mPixelShader     = null;
            mVertexShader    = null;
            mVertexBuffer    = null;
            mVertices        = null;
            mRenderTarget    = null;
        }
Ejemplo n.º 3
0
        private void CreateView(int width, int height)
        {
            if (width <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(width));
            }

            if (height <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(height));
            }

            Destroy();

            mWidth  = width;
            mHeight = height;

            Execution.ExecuteOnUiThread(() =>
            {
                mOffScreenWindow                 = new Form();
                mOffScreenWindow.Left            = -65535;
                mOffScreenWindow.Top             = -65535;
                mOffScreenWindow.FormBorderStyle = FormBorderStyle.None;
                mOffScreenWindow.Width           = 1;
                mOffScreenWindow.Height          = 1;
                mOffScreenWindow.ShowInTaskbar   = false;
                mOffScreenWindow.Show();
                mOffScreenWindow.Hide();
            });

            var description = new SwapChainDescription
            {
                BufferCount       = 1,
                IsWindowed        = true,
                ModeDescription   = new ModeDescription(0, 0, new Rational(60, 1), Format.B8G8R8A8_UNorm),
                SampleDescription = new SampleDescription(1, 0),
                Usage             = Usage.RenderTargetOutput | Usage.Shared,
                OutputHandle      = mOffScreenWindow.Handle
            };

            mSwapChain    = mDevice.CreateSwapChain(description);
            mPixelShader  = new PixelShader(Device, Bytecode);
            mVertexShader = new VertexShader(Device, mVertexShaderBytecode);
            mVertexBuffer = CreateVertexBuffer(out mVertices);

            Execution.ExecuteOnUiThread(() =>
            {
                mOffScreenWindow.Width  = mWidth;
                mOffScreenWindow.Height = mHeight;
            });

            mSwapChain.ResizeBuffers(1, mWidth, mHeight, Format.B8G8R8A8_UNorm, SwapChainFlags.None);
            Device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0.0f, 0.0f, mWidth, mHeight));

            Device.ImmediateContext.Rasterizer.State =
                RasterizerState.FromDescription(Device,
                                                new RasterizerStateDescription
            {
                CullMode = CullMode.None,
                FillMode = FillMode.Solid
            });

            mRenderTarget = new HardwareRenderTarget(mDevice, mSwapChain);
        }