Beispiel #1
0
        /// <summary>
        /// Create all view resources.
        /// </summary>
        Tuple <D3D11.Texture2D, D3D11.RenderTargetView, D3D11.Texture2D, D3D11.DepthStencilView, SharpDX.Mathematics.Interop.RawViewportF, Size2, DpiScaling> IRenderLoopHost.OnRenderLoop_CreateViewResources(EngineDevice engineDevice)
        {
            // Calculate pixel with and high of this visual
            Size pixelSize = this.GetPixelSize(new Size(100.0, 100.0));
            int  width     = (int)pixelSize.Width;
            int  height    = (int)pixelSize.Height;

            //Get references to current render device
            D3D11.Device        renderDevice        = engineDevice.DeviceD3D11_1;
            D3D11.DeviceContext renderDeviceContext = renderDevice.ImmediateContext;

            //Create the swap chain and the render target
            m_backBufferD3D11  = GraphicsHelper.CreateRenderTargetTexture(engineDevice, width, height, m_renderLoop.ViewConfiguration);
            m_backBufferForWpf = GraphicsHelper.CreateSharedTexture(engineDevice, width, height);
            m_renderTarget     = new D3D11.RenderTargetView(renderDevice, m_backBufferD3D11);

            //Create the depth buffer
            m_depthBuffer       = GraphicsHelper.CreateDepthBufferTexture(engineDevice, width, height, m_renderLoop.ViewConfiguration);
            m_renderTargetDepth = new D3D11.DepthStencilView(renderDevice, m_depthBuffer);

            //Apply render target size values
            m_renderTargetWidth  = width;
            m_renderTargetHeight = height;

            //Define the viewport for rendering
            SharpDX.Mathematics.Interop.RawViewportF viewPort = GraphicsHelper.CreateDefaultViewport(width, height);

            //Apply new width and height values of the viewport
            m_viewportWidth  = width;
            m_viewportHeight = height;

            //Create and apply the image source object
            m_d3dImageSource = new HigherD3DImageSource(engineDevice);
            m_d3dImageSource.SetRenderTarget(m_backBufferForWpf);
            if (this.Source == m_dummyBitmap)
            {
                this.Source = m_d3dImageSource;
            }

            m_lastRecreateWidth  = width;
            m_lastRecreateHeight = height;

            //Return all generated objects
            return(Tuple.Create(m_backBufferD3D11, m_renderTarget, m_depthBuffer, m_renderTargetDepth, viewPort, new Size2(width, height), GetDpiScaling()));
        }
Beispiel #2
0
        /// <summary>
        /// Disposes all loaded view resources.
        /// </summary>
        void IRenderLoopHost.OnRenderLoop_DisposeViewResources(EngineDevice engineDevice)
        {
            if (m_d3dImageSource != null)
            {
                this.Source = m_dummyBitmap;

                // Dispose the render target
                m_d3dImageSource.SetRenderTarget(null);
                m_d3dImageSource.Dispose();
                m_d3dImageSource = null;
            }

            // Dispose all other resources
            m_renderTarget2DDxgi = GraphicsHelper.DisposeObject(m_renderTarget2DDxgi);
            m_renderTargetDepth  = GraphicsHelper.DisposeObject(m_renderTargetDepth);
            m_depthBuffer        = GraphicsHelper.DisposeObject(m_depthBuffer);
            m_renderTarget       = GraphicsHelper.DisposeObject(m_renderTarget);
            m_backBufferForWpf   = GraphicsHelper.DisposeObject(m_backBufferForWpf);
            m_backBufferD3D11    = GraphicsHelper.DisposeObject(m_backBufferD3D11);
        }