Пример #1
0
        public override void GetTexture(SharpDX.Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out SharpDX.RectangleF textureSubRectangle)
        {
            if (_synchronizedTexture == null)
            {
                _synchronizedTexture = _host.CreateSynchronizedTexture(_controller.GetTexture());
            }

            // Set output parameters.
            _textureSubRectangle.Left   = 0.0f;
            _textureSubRectangle.Top    = 0.0f;
            _textureSubRectangle.Right  = surfaceSize.Width;
            _textureSubRectangle.Bottom = surfaceSize.Height;


            //HOW DO YOU DO A Microsoft::WRL::ComPtr<T>   CopyTo ?????
            //m_synchronizedTexture.CopyTo(synchronizedTexture);
            synchronizedTexture = _synchronizedTexture;

            textureSubRectangle = _textureSubRectangle;

            //something is going wrong here as the second time thru the BeginDraw consumes
            //the call and controlnever returns back to this method, thus GetTexture
            //(the call after begindraw) never fires again... ??????
            synchronizedTexture.BeginDraw();

            _controller.GetTexture(surfaceSize, synchronizedTexture, textureSubRectangle);

            synchronizedTexture.EndDraw();
        }
            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();
            }
Пример #3
0
 public override void GetTexture(Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RectangleF textureSubRectangle)
 {
     lock (this.lockObject)
     {
         if (this.sharpDXContext == null || this.sharpDXContext.IsDisposed)
         {
             synchronizedTexture = this.synchronizedTexture;
             textureSubRectangle = new RectangleF(0.0f, 0.0f, surfaceSize.Width, surfaceSize.Height);
         }
         else
         {
             if (this.synchronizedTexture == null)
             {
                 this.sharpDXContext.BackBufferSize = new Size((double)surfaceSize.Width, (double)surfaceSize.Height);
                 this.sharpDXContext.RecreateBackBuffer(this.sharpDXContext.BackBufferSize);
                 this.sharpDXContext.D3DContext.Rasterizer.SetViewport(new ViewportF(0.0f, 0.0f, surfaceSize.Width, surfaceSize.Height));
                 this.synchronizedTexture = this.runtimeHost.CreateSynchronizedTexture(this.sharpDXContext.BackBuffer);
             }
             synchronizedTexture = this.synchronizedTexture;
             textureSubRectangle = new RectangleF(0.0f, 0.0f, surfaceSize.Width, surfaceSize.Height);
             this.synchronizedTexture.BeginDraw();
             this.sharpDXContext.OnRender();
             this.synchronizedTexture.EndDraw();
             this.runtimeHost.RequestAdditionalFrame();
         }
     }
 }
Пример #4
0
        public override void GetTexture(SharpDX.Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out SharpDX.RectangleF textureSubRectangle)
        {
            if (_synchronizedTexture == null)
            {
                _synchronizedTexture = _host.CreateSynchronizedTexture(_controller.GetTexture());
            }
            
            // Set output parameters.
            _textureSubRectangle.Left = 0.0f;
            _textureSubRectangle.Top = 0.0f;
            _textureSubRectangle.Right = surfaceSize.Width;
            _textureSubRectangle.Bottom = surfaceSize.Height;


            //HOW DO YOU DO A Microsoft::WRL::ComPtr<T>   CopyTo ?????
            //m_synchronizedTexture.CopyTo(synchronizedTexture);
            synchronizedTexture = _synchronizedTexture;

            textureSubRectangle = _textureSubRectangle;     

            //something is going wrong here as the second time thru the BeginDraw consumes 
            //the call and controlnever returns back to this method, thus GetTexture 
            //(the call after begindraw) never fires again... ??????
            synchronizedTexture.BeginDraw();

            _controller.GetTexture(surfaceSize, synchronizedTexture, textureSubRectangle);

            synchronizedTexture.EndDraw();
        }
Пример #5
0
        internal void GetTexture(Size2F surfaceSize, DrawingSurfaceSynchronizedTexture synchronizedTexture, RectangleF textureSubRectangle)
        {
            _timer.Update();
            _renderer.Update(_timer.Total, _timer.Delta);
            _renderer.Render();

            if (RequestAdditionalFrame != null)
            {
                RequestAdditionalFrame();
            }
        }
Пример #6
0
        void IDrawingSurfaceContentProviderNative.GetTexture(Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RawRectangleF textureSubRectangle)
        {
            try
            {
                if (!Exiting)
                {
                    // TODO Check if surfaceSize changed to reinitialize the buffers?
                    currentSize = surfaceSize;

                    if (!isInitialized)
                    {
                        InitCallback();
                        isInitialized = true;
                    }
                    else if (this.synchronizedTexture == null)
                    {
                        // Dispose the graphics device
                        if (graphicsDeviceService.GraphicsDevice != null)
                        {
                            graphicsDeviceService.GraphicsDevice.Dispose();
                        }

                        // Make sure that the graphics device is created
                        // This will create indirectly the synchronizedTexture on this instance.
                        graphicsDeviceManager.CreateDevice();
                    }

                    this.synchronizedTexture.BeginDraw();

                    RunCallback();

                    host.RequestAdditionalFrame();

                    this.synchronizedTexture.EndDraw();
                }
            }
            catch (Exception ex)
            {
                // TODO: As we are in a callback from a native code, we cannot pass back this exception,
                // so how to pass back this exception to the user at an appropriate time?
                drawException = ex;
                Debug.WriteLine(drawException);
            }

            // Set output parameters.
            var output = new RectangleF(0f, 0f, surfaceSize.Width, surfaceSize.Height);

            textureSubRectangle = new RawRectangleF {
                Left = output.Left, Top = output.Top, Right = output.Right, Bottom = output.Bottom
            };
            synchronizedTexture = this.synchronizedTexture;
        }
Пример #7
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);
        }
Пример #8
0
        internal override void Switch(GameContext context)
        {
            drawingSurface.Loaded -= DrawingSurfaceOnLoaded;
            drawingSurface.Unloaded -= DrawingSurfaceUnloaded;
            drawingSurface.SetContentProvider(null);

            drawingSurface = (DrawingSurface)context.Control;
            isInitialized = false;
            synchronizedTexture.Dispose();
            synchronizedTexture = null;

            drawingSurface.Loaded += DrawingSurfaceOnLoaded;
            drawingSurface.Unloaded += DrawingSurfaceUnloaded;

            drawingSurface.SetContentProvider(this);
        }
Пример #9
0
        public SharpDXContentProvider(SharpDXInterop controller)
        {
            _controller = controller;

            _controller.RequestAdditionalFrame +=()=>{
                if (_host!=null)
                {
                    _host.RequestAdditionalFrame();
                }
            };

            _controller.RecreateSynchronizedTexture +=()=>{
                if (_host!=null)
                {
                    _synchronizedTexture = _host.CreateSynchronizedTexture(_controller.GetTexture());
                }
            };
        }
Пример #10
0
 public void CreateSynchronizedTexture(SharpDX.Direct3D11.Texture2D texture2D)
 {
     synchronizedTexture = host.CreateSynchronizedTexture(texture2D);
 }
        internal override void Switch(GameContext context)
        {
            drawingSurface.Loaded -= DrawingSurfaceOnLoaded;
            drawingSurface.Unloaded -= DrawingSurfaceUnloaded;
            drawingSurface.SetContentProvider(null);

            drawingSurface = (DrawingSurface)context.Control;
            isInitialized = false;
            synchronizedTexture.Dispose();
            synchronizedTexture = null;

            drawingSurface.Loaded += DrawingSurfaceOnLoaded;
            drawingSurface.Unloaded += DrawingSurfaceUnloaded;

            drawingSurface.SetContentProvider(this);
        }
        void IDrawingSurfaceContentProviderNative.GetTexture(Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RectangleF textureSubRectangle)
        {
            try
            {
                if (!Exiting)
                {
                    // TODO Check if surfaceSize changed to reinitialize the buffers?
                    currentSize = surfaceSize;

                    if (!isInitialized)
                    {
                        InitCallback();
                        isInitialized = true;
                    }
                    else if (this.synchronizedTexture == null)
                    {
                        // Dispose the graphics device
                        if (graphicsDeviceService.GraphicsDevice != null)
                        {
                            graphicsDeviceService.GraphicsDevice.Dispose();
                        }

                        // Make sure that the graphics device is created
                        // This will create indirectly the synchronizedTexture on this instance.
                        graphicsDeviceManager.CreateDevice();
                    }

                    this.synchronizedTexture.BeginDraw();

                    RunCallback();

                    host.RequestAdditionalFrame();

                    this.synchronizedTexture.EndDraw();
                }
            }
            catch (Exception ex)
            {
                // TODO: As we are in a callback from a native code, we cannot pass back this exception,
                // so how to pass back this exception to the user at an appropriate time?
                drawException = ex;
                Debug.WriteLine(drawException);
            }

            // Set output parameters.
            textureSubRectangle = new RectangleF(0f, 0f, surfaceSize.Width, surfaceSize.Height);
            synchronizedTexture = this.synchronizedTexture;
        }
        void IDrawingSurfaceContentProviderNative.GetTexture(DrawingSizeF surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RectangleF textureSubRectangle)
        {
            try
            {
                if (!Exiting)
                {
                    if (GraphicsDevice == null)
                    {
                        GraphicsDevice = GraphicsDevice.New();

                        var renderTargetDesc = new Texture2DDescription
                                               {
                                                   Format = DXGI.Format.B8G8R8A8_UNorm,
                                                   Width = (int)surfaceSize.Width,
                                                   Height = (int)surfaceSize.Height,
                                                   ArraySize = 1,
                                                   MipLevels = 1,
                                                   BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                                                   Usage = ResourceUsage.Default,
                                                   CpuAccessFlags = CpuAccessFlags.None,
                                                   OptionFlags = ResourceOptionFlags.SharedKeyedmutex | ResourceOptionFlags.SharedNthandle,
                                                   SampleDescription = new DXGI.SampleDescription(1, 0)
                                               };

                        renderTarget = ToDispose(Graphics.Texture2D.New(GraphicsDevice, renderTargetDesc));
                        BackBuffer = ToDispose(RenderTarget2D.New(GraphicsDevice, new RenderTargetView(GraphicsDevice, renderTarget)));

                        graphicsPresenter = new RenderTargetGraphicsPresenter(GraphicsDevice, BackBuffer);
                        GraphicsDevice.Presenter = graphicsPresenter;
                        InitCallback();
                    }

                    if(this.synchronizedTexture == null)
                        this.synchronizedTexture = host.CreateSynchronizedTexture((Texture2D)renderTarget);

                    this.synchronizedTexture.BeginDraw();

                    RunCallback();

                    host.RequestAdditionalFrame();

                    this.synchronizedTexture.EndDraw();
                }
            }
            catch (Exception ex)
            {
                // TODO: As we are in a callback from a native code, we cannot pass back this exception,
                // so how to pass back this exception to the user at an appropriate time?
                drawException = ex;
                Debug.WriteLine(drawException);
            }

            // Set output parameters.
            textureSubRectangle = new RectangleF(0f, 0f, surfaceSize.Width, surfaceSize.Height);
            synchronizedTexture = this.synchronizedTexture;
        }
Пример #14
0
        internal void GetTexture(Size2F surfaceSize, DrawingSurfaceSynchronizedTexture synchronizedTexture, RectangleF textureSubRectangle)
        {
            _timer.Update();
            _renderer.Update(_timer.Total, _timer.Delta);
            _renderer.Render();

            if (RequestAdditionalFrame!=null) RequestAdditionalFrame();
        }
            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();
            }
Пример #16
0
 public abstract void GetTexture(Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RectangleF textureSubRectangle);
Пример #17
0
 public override void Disconnect()
 {
     controller.Disconnect();
     host = null;
     synchronizedTexture = null;
 }
        /// <summary>
        /// Gets the synchronized texture used for drawing.
        /// </summary>
        /// <param name="surfaceSize">Size of the drawing surface.</param>
        /// <param name="synchronizedTexture">Synchronized texture object.</param>
        /// <param name="textureSubRectangle">Area of the texture that has changed.</param>
        public override void GetTexture(Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RectangleF textureSubRectangle)
        {
            if (this.synchronizedTexture == null)
            {
                this.sharpDXContext.BackBufferSize = new Size(surfaceSize.Width, surfaceSize.Height);

                this.sharpDXContext.RecreateBackBuffer(this.sharpDXContext.BackBufferSize);
                this.sharpDXContext.RecreateDepthStencil(this.sharpDXContext.BackBufferSize);

                ViewportF viewport = new ViewportF(0, 0, surfaceSize.Width, surfaceSize.Height);
                this.sharpDXContext.D3DContext.Rasterizer.SetViewport(viewport);

                this.synchronizedTexture = this.runtimeHost.CreateSynchronizedTexture(this.sharpDXContext.BackBuffer);
            }

            synchronizedTexture = this.synchronizedTexture;
            textureSubRectangle = new RectangleF(0, 0, surfaceSize.Width, surfaceSize.Height);

            this.synchronizedTexture.BeginDraw();
            this.sharpDXContext.OnRender();
            this.synchronizedTexture.EndDraw();

            this.runtimeHost.RequestAdditionalFrame();
        }
 public abstract void GetTexture(DrawingSizeF surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RectangleF textureSubRectangle);
 public void CreateSynchronizedTexture(SharpDX.Direct3D11.Texture2D texture2D)
 {
     synchronizedTexture = host.CreateSynchronizedTexture(texture2D);
 }