private static DepthFormat SelectStencilMode() { // Check stencil formats GraphicsAdapter adapter = GraphicsAdapter.DefaultAdapter; SurfaceFormat format = adapter.CurrentDisplayMode.Format; if (adapter.CheckDepthStencilMatch(DeviceType.Hardware, format, format, DepthFormat.Depth24Stencil8)) { return(DepthFormat.Depth24Stencil8); } else if (adapter.CheckDepthStencilMatch(DeviceType.Hardware, format, format, DepthFormat.Depth24Stencil8Single)) { return(DepthFormat.Depth24Stencil8Single); } else if (adapter.CheckDepthStencilMatch(DeviceType.Hardware, format, format, DepthFormat.Depth24Stencil4)) { return(DepthFormat.Depth24Stencil4); } else if (adapter.CheckDepthStencilMatch(DeviceType.Hardware, format, format, DepthFormat.Depth15Stencil1)) { return(DepthFormat.Depth15Stencil1); } else { throw new InvalidOperationException( "Could Not Find Stencil Buffer for Default Adapter"); } }
public static SurfaceFormat SelectRenderTargetMode(bool preferFloat) { // Check stencil formats GraphicsAdapter adapter = GraphicsAdapter.DefaultAdapter; SurfaceFormat displayFormat = adapter.CurrentDisplayMode.Format; DepthFormat depthFormat = SelectStencilMode(displayFormat); SurfaceFormat surfaceFormat = SurfaceFormat.Color; if (preferFloat) { if (adapter.CheckDepthStencilMatch( DeviceType.Hardware, displayFormat, SurfaceFormat.Single, depthFormat)) { surfaceFormat = SurfaceFormat.Single; } else if (adapter.CheckDepthStencilMatch( DeviceType.Hardware, displayFormat, SurfaceFormat.HalfSingle, depthFormat)) { surfaceFormat = SurfaceFormat.HalfSingle; } else if (adapter.CheckDepthStencilMatch( DeviceType.Hardware, displayFormat, SurfaceFormat.Color, depthFormat)) { surfaceFormat = SurfaceFormat.Color; } else if (adapter.CheckDepthStencilMatch( DeviceType.Reference, displayFormat, SurfaceFormat.Single, depthFormat)) { surfaceFormat = SurfaceFormat.Single; } else if (adapter.CheckDepthStencilMatch( DeviceType.Reference, displayFormat, SurfaceFormat.HalfSingle, depthFormat)) { surfaceFormat = SurfaceFormat.HalfSingle; } else if (adapter.CheckDepthStencilMatch( DeviceType.Reference, displayFormat, SurfaceFormat.Color, depthFormat)) { surfaceFormat = SurfaceFormat.Color; } else { surfaceFormat = SurfaceFormat.Unknown; } } return(surfaceFormat); }
private void ValidateGraphicsDeviceInformation(GraphicsDeviceInformation devInfo) { SurfaceFormat format; GraphicsAdapter adapter = devInfo.Adapter; DeviceType deviceType = devInfo.DeviceType; bool enableAutoDepthStencil = devInfo.PresentationParameters.EnableAutoDepthStencil; DepthFormat autoDepthStencilFormat = devInfo.PresentationParameters.AutoDepthStencilFormat; SurfaceFormat backBufferFormat = devInfo.PresentationParameters.BackBufferFormat; int backBufferWidth = devInfo.PresentationParameters.BackBufferWidth; int backBufferHeight = devInfo.PresentationParameters.BackBufferHeight; PresentationParameters presentationParameters = devInfo.PresentationParameters; SurfaceFormat format4 = presentationParameters.BackBufferFormat; if (!presentationParameters.IsFullScreen) { format = adapter.CurrentDisplayMode.Format; if (SurfaceFormat.Unknown == presentationParameters.BackBufferFormat) { format4 = format; } } else { SurfaceFormat format5 = presentationParameters.BackBufferFormat; if (format5 != SurfaceFormat.Color) { if (format5 != SurfaceFormat.Bgra5551) { format = presentationParameters.BackBufferFormat; } else { format = SurfaceFormat.Bgr555; } } else { format = SurfaceFormat.Bgr32; } } if (-1 == Array.IndexOf <SurfaceFormat>(ValidBackBufferFormats, format4)) { throw new ArgumentException(Resources.ValidateBackBufferFormatIsInvalid); } if ( !adapter.CheckDeviceType(deviceType, format, presentationParameters.BackBufferFormat, presentationParameters.IsFullScreen)) { throw new ArgumentException(Resources.ValidateDeviceType); } if ((presentationParameters.BackBufferCount < 0) || (presentationParameters.BackBufferCount > 3)) { throw new ArgumentException(Resources.ValidateBackBufferCount); } if ((presentationParameters.BackBufferCount > 1) && (presentationParameters.SwapEffect == SwapEffect.Copy)) { throw new ArgumentException(Resources.ValidateBackBufferCountSwapCopy); } switch (presentationParameters.SwapEffect) { case SwapEffect.Default: case SwapEffect.Flip: case SwapEffect.Copy: { int num3; if ( !adapter.CheckDeviceMultiSampleType(deviceType, format4, presentationParameters.IsFullScreen, presentationParameters.MultiSampleType, out num3)) { throw new ArgumentException(Resources.ValidateMultiSampleTypeInvalid); } if (presentationParameters.MultiSampleQuality >= num3) { throw new ArgumentException(Resources.ValidateMultiSampleQualityInvalid); } if ((presentationParameters.MultiSampleType != MultiSampleType.None) && (presentationParameters.SwapEffect != SwapEffect.Default)) { throw new ArgumentException(Resources.ValidateMultiSampleSwapEffect); } if (((presentationParameters.PresentOptions & PresentOptions.DiscardDepthStencil) != PresentOptions.None) && !presentationParameters.EnableAutoDepthStencil) { throw new ArgumentException(Resources.ValidateAutoDepthStencilMismatch); } if (presentationParameters.EnableAutoDepthStencil) { if ( !adapter.CheckDeviceFormat(deviceType, format, ResourceUsage.None, QueryUsages.None, ResourceType.DepthStencilBuffer, presentationParameters.AutoDepthStencilFormat)) { throw new ArgumentException(Resources.ValidateAutoDepthStencilFormatInvalid); } if ( !adapter.CheckDepthStencilMatch(deviceType, format, format4, presentationParameters.AutoDepthStencilFormat)) { throw new ArgumentException(Resources.ValidateAutoDepthStencilFormatIncompatible); } } if (!presentationParameters.IsFullScreen) { if (presentationParameters.FullScreenRefreshRateInHz != 0) { throw new ArgumentException(Resources.ValidateRefreshRateInWindow); } switch (presentationParameters.PresentationInterval) { case PresentInterval.Default: case PresentInterval.One: case PresentInterval.Immediate: return; } throw new ArgumentException(Resources.ValidatePresentationIntervalInWindow); } if (presentationParameters.FullScreenRefreshRateInHz == 0) { throw new ArgumentException(Resources.ValidateRefreshRateInFullScreen); } GraphicsDeviceCapabilities capabilities = adapter.GetCapabilities(deviceType); switch (presentationParameters.PresentationInterval) { case PresentInterval.Default: case PresentInterval.One: case PresentInterval.Immediate: goto Label_02E5; case PresentInterval.Two: case PresentInterval.Three: case PresentInterval.Four: if ((capabilities.PresentInterval & presentationParameters.PresentationInterval) == PresentInterval.Default) { throw new ArgumentException( Resources.ValidatePresentationIntervalIncompatibleInFullScreen); } goto Label_02E5; } break; } default: throw new ArgumentException(Resources.ValidateSwapEffectInvalid); } throw new ArgumentException(Resources.ValidatePresentationIntervalInFullScreen); Label_02E5: if (presentationParameters.IsFullScreen) { if ((presentationParameters.BackBufferWidth == 0) || (presentationParameters.BackBufferHeight == 0)) { throw new ArgumentException(Resources.ValidateBackBufferDimsFullScreen); } bool flag2 = true; bool flag3 = false; DisplayMode currentDisplayMode = adapter.CurrentDisplayMode; if (((currentDisplayMode.Format != format) && (currentDisplayMode.Width != presentationParameters.BackBufferHeight)) && ((currentDisplayMode.Height != presentationParameters.BackBufferHeight) && (currentDisplayMode.RefreshRate != presentationParameters.FullScreenRefreshRateInHz))) { flag2 = false; foreach (DisplayMode mode2 in adapter.SupportedDisplayModes[format]) { if ((mode2.Width == presentationParameters.BackBufferWidth) && (mode2.Height == presentationParameters.BackBufferHeight)) { flag3 = true; if (mode2.RefreshRate == presentationParameters.FullScreenRefreshRateInHz) { flag2 = true; break; } } } } if (!flag2 && flag3) { throw new ArgumentException(Resources.ValidateBackBufferDimsModeFullScreen); } if (!flag2) { throw new ArgumentException(Resources.ValidateBackBufferHzModeFullScreen); } } if (presentationParameters.EnableAutoDepthStencil != enableAutoDepthStencil) { throw new ArgumentException(Resources.ValidateAutoDepthStencilAdapterGroup); } if (presentationParameters.EnableAutoDepthStencil) { if (presentationParameters.AutoDepthStencilFormat != autoDepthStencilFormat) { throw new ArgumentException(Resources.ValidateAutoDepthStencilAdapterGroup); } if (presentationParameters.BackBufferFormat != backBufferFormat) { throw new ArgumentException(Resources.ValidateAutoDepthStencilAdapterGroup); } if (presentationParameters.BackBufferWidth != backBufferWidth) { throw new ArgumentException(Resources.ValidateAutoDepthStencilAdapterGroup); } if (presentationParameters.BackBufferHeight != backBufferHeight) { throw new ArgumentException(Resources.ValidateAutoDepthStencilAdapterGroup); } } }
public static DepthFormat SelectStencilMode( SurfaceFormat renderTargetFormat) { // Check stencil formats GraphicsAdapter adapter = GraphicsAdapter.DefaultAdapter; SurfaceFormat format = adapter.CurrentDisplayMode.Format; DepthFormat depthFormat = DepthFormat.Unknown; if (adapter.CheckDepthStencilMatch( DeviceType.Hardware, format, renderTargetFormat, DepthFormat.Depth24Stencil8)) { depthFormat = DepthFormat.Depth24Stencil8; } else if (adapter.CheckDepthStencilMatch( DeviceType.Hardware, format, renderTargetFormat, DepthFormat.Depth24Stencil8Single)) { depthFormat = DepthFormat.Depth24Stencil8Single; } else if (adapter.CheckDepthStencilMatch( DeviceType.Hardware, format, renderTargetFormat, DepthFormat.Depth24Stencil4)) { depthFormat = DepthFormat.Depth24Stencil4; } else if (adapter.CheckDepthStencilMatch( DeviceType.Hardware, format, renderTargetFormat, DepthFormat.Depth15Stencil1)) { depthFormat = DepthFormat.Depth15Stencil1; } else if (adapter.CheckDepthStencilMatch( DeviceType.Reference, format, renderTargetFormat, DepthFormat.Depth24Stencil8)) { depthFormat = DepthFormat.Depth24Stencil8; } else if (adapter.CheckDepthStencilMatch( DeviceType.Reference, format, renderTargetFormat, DepthFormat.Depth24Stencil8Single)) { depthFormat = DepthFormat.Depth24Stencil8Single; } else if (adapter.CheckDepthStencilMatch( DeviceType.Reference, format, renderTargetFormat, DepthFormat.Depth24Stencil4)) { depthFormat = DepthFormat.Depth24Stencil4; } else if (adapter.CheckDepthStencilMatch( DeviceType.Reference, format, renderTargetFormat, DepthFormat.Depth15Stencil1)) { depthFormat = DepthFormat.Depth15Stencil1; } return(depthFormat); }