/// <summary> /// Creates a new instance of <see cref="SwapChain"/>. /// </summary> /// <param name="renderSystem">Render system used to create the underlying implementation.</param> /// <param name="windowHandle">The handle to the window the swap chain is to bounded to. This is the window that the swap chain /// presents to.</param> /// <exception cref="System.ArgumentNullException">Thrown if the render system is null.</exception> /// <param name="presentParams">The presentation parameters defining how the swap chain should be setup..</param> /// <exception cref="System.ArgumentException">Thrown if the presentation parameters are invalid, e.g. bad format or multi sample values.</exception> /// <exception cref="Tesla.Core.TeslaException">Thrown if the implementation failed to be created.</exception> public SwapChain(IRenderSystemProvider renderSystem, IntPtr windowHandle, PresentationParameters presentParams) { if (renderSystem == null) { Dispose(); throw new ArgumentNullException("renderSystem", "Render system cannot be null."); } base.RenderSystem = renderSystem; //Check format compatibility bool goodFormat = renderSystem.DefaultAdapter.QueryBackBufferFormat(presentParams.BackBufferFormat, presentParams.DepthStencilFormat, presentParams.MultiSampleCount); int sampleQual = renderSystem.DefaultAdapter.QueryMultiSampleQualityLevels(presentParams.BackBufferFormat, presentParams.MultiSampleQuality); int levels = presentParams.MultiSampleQuality; if (goodFormat && (levels >= 0 && levels <= sampleQual)) { try { _impl = renderSystem.CreateSwapChainImplementation(windowHandle, presentParams); } catch (Exception e) { Dispose(); throw new TeslaException("Error creating underlying implementation, see inner exception for details.", e); } } else { Dispose(); throw new ArgumentException("Invalid presentation parameters."); } }