/// <summary> /// Initializes a new instance of the <see cref="GraphicsPresenter" /> class. /// </summary> /// <param name="device">The device.</param> /// <param name="presentationParameters"> </param> protected GraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) { GraphicsDevice = device.MainDevice; Description = presentationParameters.Clone(); // Creates a default DepthStencilBuffer. CreateDepthStencilBuffer(); }
public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters) { PresentInterval = presentationParameters.PresentationInterval; // Initialize the swap chain swapChain = ToDispose(CreateSwapChain()); backBuffer = ToDispose(RenderTarget2D.New(device, swapChain.GetBackBuffer<Direct3D11.Texture2D>(0))); }
/// <summary> /// Initializes a new instance of the <see cref="GraphicsPresenter" /> class. /// </summary> /// <param name="device">The device.</param> /// <param name="presentationParameters"> </param> protected GraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) { GraphicsDevice = device.MainDevice; Description = presentationParameters.Clone(); DefaultViewport = new ViewportF(0, 0, Description.BackBufferWidth, Description.BackBufferHeight); // Creates a default DepthStencilBuffer. CreateDepthStencilBuffer(); }
protected virtual void CreateOrUpdatePresenter() { if (Presenter == null) { PixelFormat resizeFormat; var size = GetRequestedSize(out resizeFormat); var presentationParameters = new PresentationParameters(size.Width, size.Height, Window.NativeWindow, resizeFormat) { DepthStencilFormat = PreferredDepthStencilFormat }; presentationParameters.PresentationInterval = PresentInterval.One; Presenter = new SwapChainGraphicsPresenter(GraphicsDevice, presentationParameters); isBackBufferToResize = false; } }
protected override void CreatePresenter(GraphicsDevice device, PresentationParameters parameters, object newControl = null) { if(!(gameWindow is GameWindowPhoneXaml)) return; parameters = TryGetParameters(device, parameters); DisposeGraphicsPresenter(device); var renderTargetDesc = new Texture2DDescription { Format = Format.B8G8R8A8_UNorm, Width = parameters.BackBufferWidth, Height = parameters.BackBufferHeight, 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) }; var backBuffer = RenderTarget2D.New(device, renderTargetDesc); var graphicsPresenter = new RenderTargetGraphicsPresenter(device, backBuffer, parameters.DepthStencilFormat, true); device.Presenter = graphicsPresenter; var gameWindowXaml = (GameWindowPhoneXaml)gameWindow; gameWindowXaml.CreateSynchronizedTexture(backBuffer); }
/// <summary> /// Allows derived classes to create a custom graphics presenter /// </summary> /// <param name="device">The graphics device to use for renderer creation</param> /// <param name="parameters">The desired presentation parameters to use for renderer creation</param> /// <returns>Default implementation returns null</returns> internal virtual GraphicsPresenter CreateGraphicsPresenter(GraphicsDevice device, PresentationParameters parameters) { return null; }
internal override GraphicsPresenter CreateGraphicsPresenter(GraphicsDevice device, PresentationParameters parameters) { var backbufferDesc = RenderTarget2D.CreateDescription(device, parameters.BackBufferWidth, parameters.BackBufferHeight, Graphics.PixelFormat.B8G8R8A8.UNorm); // mandatory to share the surface with D3D9 backbufferDesc.OptionFlags |= ResourceOptionFlags.Shared; RemoveAndDispose(ref presenter); RemoveAndDispose(ref queryForCompletion); presenter = ToDispose(new RenderTargetGraphicsPresenter(device, backbufferDesc, parameters.DepthStencilFormat, false, true)); // used to indicate if all drawing operations have completed queryForCompletion = ToDispose(new Query(presenter.GraphicsDevice, new QueryDescription { Type = QueryType.Event, Flags = QueryFlags.None })); // device context will be used to query drawing operations status deviceContext = ((Device)presenter.GraphicsDevice).ImmediateContext; element.SetBackbuffer(presenter.BackBuffer); return presenter; }
protected virtual void CreatePresenter(GraphicsDevice device, PresentationParameters parameters, object newControl = null) { if (device == null) throw new ArgumentNullException("device"); parameters = TryGetParameters(device, parameters); DisposeGraphicsPresenter(device); // override the device window, if available if (newControl != null) parameters.DeviceWindowHandle = newControl; // Give a chance to gameWindow to create desired graphics presenter, otherwise - create our own. device.Presenter = gameWindow.CreateGraphicsPresenter(device, parameters) ?? new SwapChainGraphicsPresenter(device, parameters); }
protected PresentationParameters TryGetParameters(GraphicsDevice device, PresentationParameters parameters) { var oldPresenter = device.Presenter; if (parameters == null) { if (oldPresenter == null) throw new InvalidOperationException("Cannot retrieve PresentationParameters."); // preserve the parameters from old GraphicsPresenter parameters = oldPresenter.Description.Clone(); } return parameters; }
/// <summary> /// Initializes a new instance of the <see cref="GraphicsDeviceInformation" /> class. /// </summary> public GraphicsDeviceInformation() { Adapter = GraphicsAdapter.Default; PresentationParameters = new PresentationParameters(); }
public void ResizePresenter() { int width = m_host.HostedWindowWidth; int height = m_host.HostedWindowHeight; if (width == 0 || height == 0) { RemoveAndDispose(ref m_presenter); return; } bool sizeChanged; if (m_presenter == null) { var presentParams = new PresentationParameters(width, height, m_host.Handle, m_pixelFormat) { PresentationInterval = PresentInterval.Immediate, }; m_presenter = ToDispose(new SwapChainGraphicsPresenter(m_device, presentParams)); sizeChanged = true; } else { // Resize is a no-op if the size hasn't changed sizeChanged = m_presenter.Resize(width, height, m_pixelFormat); } if (sizeChanged) { if (this.SizeChanged != null) this.SizeChanged(width, height); } }
internal override GraphicsPresenter CreateGraphicsPresenter(GraphicsDevice device, PresentationParameters parameters) { var backbufferDesc = RenderTarget2D.CreateDescription(device, parameters.BackBufferWidth, parameters.BackBufferHeight, Graphics.PixelFormat.B8G8R8A8.UNorm); // mandatory to share the surface with D3D9 backbufferDesc.OptionFlags |= ResourceOptionFlags.Shared; if (presenter != null) RemoveAndDispose(ref presenter); presenter = ToDispose(new RenderTargetGraphicsPresenter(device, backbufferDesc, DepthFormat.None, false, true)); element.SetBackbuffer(presenter.BackBuffer); return presenter; }
/// <summary> /// Prepares control surface for rendering. /// </summary> private void StartRendering() { Debug.Assert(_presenter == null); Debug.Assert(_graphicsDevice.Presenter == null); Debug.Assert(_graphicsDevice != null); Redraw(); var parameters = new PresentationParameters((int)ActualWidth, (int)ActualHeight, swapChainPanel); _presenter = _disposeCollector.Collect(new SwapChainGraphicsPresenter(_graphicsDevice, parameters)); _graphicsDevice.Presenter = _presenter; Debug.Assert(_bitmapTarget == null); CreateD2DRenderTarget(); CompositionTarget.Rendering += HandleRendering; }
/// <summary> /// Initializes a new instance of the <see cref="GraphicsPresenter" /> class. /// </summary> /// <param name="device">The device.</param> /// <param name="presentationParameters"> </param> protected GraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) { GraphicsDevice = device.MainDevice; Description = presentationParameters.Clone(); }