public override void GetTexture(Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RectangleF textureSubRectangle)
            {
                if (_synchronizedTexture == null)
                {
                    _drawingSurfaceUpdateHandler.CreateDeviceResources();
                    _drawingSurfaceUpdateHandler.CreateWindowSizeDependentResources(surfaceSize);
                    _synchronizedTexture = _host.CreateSynchronizedTexture(_drawingSurfaceUpdateHandler._renderTarget);
                }

                synchronizedTexture = _synchronizedTexture;
                textureSubRectangle = new RectangleF
                {
                    Right  = surfaceSize.Width,
                    Bottom = surfaceSize.Height
                };

                _surfaceUpdateHandler.UpdateGameWindowSize(surfaceSize);

                _synchronizedTexture.BeginDraw();

                _surfaceUpdateHandler.Draw(
                    _drawingSurfaceUpdateHandler._device,
                    _drawingSurfaceUpdateHandler._deviceContext,
                    _drawingSurfaceUpdateHandler._renderTargetView);

                _synchronizedTexture.EndDraw();
            }
示例#2
0
        /// <summary>
        /// Gets the texture.
        /// </summary>
        /// <param name="surfaceSize">Size of the surface.</param>
        /// <param name="synchronizedTexture">The synchronized texture.</param>
        /// <param name="textureSubRectangle">The texture sub rectangle.</param>
        public override void GetTexture(SDX.Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out SDX.RectangleF textureSubRectangle)
        {
            if (m_surfacePainter == null)
            {
                throw new ObjectDisposedException("WP8DrawingSurfaceInterop");
            }

            EngineDevice currentDevice = m_surfacePainter.RenderLoop.Device;
            Size2        pixelSize     = m_surfacePainter.GetCurrentRenderTargetSize();

            // Create the synchronized texture if needed
            if ((m_backBufferWP8Sync == null) ||
                (m_lastPixelSize != pixelSize) ||
                (m_lastDevice != currentDevice))
            {
                // Dispose previously created buffers
                GraphicsHelper.SafeDispose(ref m_backBufferWP8Sync);
                GraphicsHelper.SafeDispose(ref m_backBufferWP8);

                // Create backbuffers for xaml rendering
                m_backBufferWP8     = GraphicsHelper.CreateSharedTextureWP8Xaml(currentDevice, pixelSize.Width, pixelSize.Height);
                m_backBufferWP8Sync = m_runtimeHost.CreateSynchronizedTexture(m_backBufferWP8);

                m_lastPixelSize = pixelSize;
                m_lastDevice    = currentDevice;
            }

            // Copy contents of current back buffer to synchronized texture
            m_backBufferWP8Sync.BeginDraw();
            try
            {
                D3D11.Texture2D sourceRenderTarget = m_surfacePainter.RenderTargetForSynchronization;

                currentDevice.DeviceImmediateContextD3D11.ResolveSubresource(
                    sourceRenderTarget, 0, m_backBufferWP8, 0, GraphicsHelper.DEFAULT_TEXTURE_FORMAT_SHARING);
                currentDevice.DeviceImmediateContextD3D11.Flush();
            }
            finally
            {
                m_backBufferWP8Sync.EndDraw();
            }

            // Reset request counter
            m_frameRequestCount = 0;

            // Set return parameters
            synchronizedTexture = m_backBufferWP8Sync;
            textureSubRectangle = new SDX.RectangleF(0f, 0f, surfaceSize.Width, surfaceSize.Height);
        }
示例#3
0
 public void CreateSynchronizedTexture(SharpDX.Direct3D11.Texture2D texture2D)
 {
     synchronizedTexture = host.CreateSynchronizedTexture(texture2D);
 }