public static bool CreateGraphicsDevice3D(GraphicsDeviceSettings settings, Control deviceTarget, out GraphicsDeviceSettings outSettings, out Device device, out PresentParameters pParams) { try { pParams = new PresentParameters(); if (settings.DepthFormat != DepthFormat.Unknown) { pParams.EnableAutoDepthStencil = true; pParams.AutoDepthStencilFormat = settings.DepthFormat; } if (settings.DisplayFormat != Format.Unknown) { pParams.BackBufferFormat = settings.DisplayFormat; } pParams.MultiSample = settings.MultiSample; pParams.SwapEffect = SwapEffect.Discard; pParams.Windowed = settings.Windowed; device = new Device(settings.Adapter, settings.Type, deviceTarget, settings.CreateFlags, pParams); // capture actual final output description outSettings = new GraphicsDeviceSettings(settings.Adapter, settings.Windowed, device.CreationParameters.DeviceType, device.DisplayMode.Format, device.GetBackBuffer(0, 0, BackBufferType.Mono).Description.MultiSampleType, device.PresentationParameters.AutoDepthStencilFormat, settings.CreateFlags); return(true); } catch (Exception) { } pParams = null; device = null; outSettings = null; return(false); }
public static GraphicsDeviceSettings CreateFromRequirements(GraphicsDeviceRequirements requirements, GraphicsDeviceCaps caps, GraphicsDeviceRequirements fallbacks, out bool fullyMatchReq) { if (caps == null) { caps = GraphicsDeviceCaps.GetDefaultAdapterCaps(requirements); } GraphicsDeviceSettings settings = new GraphicsDeviceSettings(); settings.adapter = caps.Adapter; Type type = typeof(GraphicsDeviceSettings); GraphicsDeviceCaps.OutputCapsCompatibility reqComp = caps.CheckCompatibility(requirements); GraphicsDeviceCaps.OutputCapsCompatibility fallbackComp = caps.CheckCompatibility(fallbacks); fullyMatchReq = reqComp.FullMatch; // check reqs against caps if (reqComp.SupportDeviceType) { settings.devType = requirements.DeviceType; } else if (fallbackComp.SupportDeviceType) { settings.devType = fallbacks.DeviceType; } else { throw new OutputSettingsException(type.GetProperty("DeviceType"), requirements.DeviceType, null); } if (reqComp.SupportDeviceFormat) { settings.devFormat = requirements.DisplayFormat; } else if (fallbackComp.SupportDeviceFormat) { settings.devFormat = fallbacks.DisplayFormat; } else { throw new OutputSettingsException(type.GetProperty("DeviceFormat"), requirements.DisplayFormat, null); } if (reqComp.SupportDepthFormat) { settings.depthFormat = requirements.DepthFormats[0]; } else if (fallbackComp.SupportDepthFormat) { settings.depthFormat = fallbacks.DepthFormats[0]; } else { throw new OutputSettingsException(type.GetProperty("DepthFormat"), requirements.DepthFormats[0], null); } if (caps.HardwareTnL && requirements.HardwareTnL) { settings.createFlags = CreateFlags.HardwareVertexProcessing; } else if (!requirements.HardwareTnL) { settings.createFlags = CreateFlags.SoftwareVertexProcessing; } else if (!fallbacks.HardwareTnL) { settings.createFlags = CreateFlags.SoftwareVertexProcessing; } else { throw new OutputSettingsException(type.GetProperty("CreateFlags"), requirements.HardwareTnL, null); } if (requirements.MultiSample <= caps.AntiAliasing.MaxSupported) { settings.multisample = requirements.MultiSample; } else if (fallbacks.MultiSample <= caps.AntiAliasing.MaxSupported) { settings.multisample = fallbacks.MultiSample; } else { throw new OutputSettingsException(type.GetProperty("AntiAliasing"), requirements.MultiSample, caps.AntiAliasing.MaxSupported); } return(settings); }
public static GraphicsDeviceSettings CreateFromRequirements(GraphicsDeviceRequirements requirements, GraphicsDeviceCaps caps, GraphicsDeviceRequirements fallbacks, out bool fullyMatchReq) { if (caps == null) caps = GraphicsDeviceCaps.GetDefaultAdapterCaps(requirements); GraphicsDeviceSettings settings = new GraphicsDeviceSettings(); settings.adapter = caps.Adapter; Type type = typeof(GraphicsDeviceSettings); GraphicsDeviceCaps.OutputCapsCompatibility reqComp = caps.CheckCompatibility(requirements); GraphicsDeviceCaps.OutputCapsCompatibility fallbackComp = caps.CheckCompatibility(fallbacks); fullyMatchReq = reqComp.FullMatch; // check reqs against caps if (reqComp.SupportDeviceType) settings.devType = requirements.DeviceType; else if (fallbackComp.SupportDeviceType) settings.devType = fallbacks.DeviceType; else throw new OutputSettingsException(type.GetProperty("DeviceType"), requirements.DeviceType, null); if (reqComp.SupportDeviceFormat) settings.devFormat = requirements.DisplayFormat; else if (fallbackComp.SupportDeviceFormat) settings.devFormat = fallbacks.DisplayFormat; else throw new OutputSettingsException(type.GetProperty("DeviceFormat"), requirements.DisplayFormat, null); if (reqComp.SupportDepthFormat) settings.depthFormat = requirements.DepthFormats[0]; else if (fallbackComp.SupportDepthFormat) settings.depthFormat = fallbacks.DepthFormats[0]; else throw new OutputSettingsException(type.GetProperty("DepthFormat"), requirements.DepthFormats[0], null); if (caps.HardwareTnL && requirements.HardwareTnL) settings.createFlags = CreateFlags.HardwareVertexProcessing; else if (!requirements.HardwareTnL) settings.createFlags = CreateFlags.SoftwareVertexProcessing; else if (!fallbacks.HardwareTnL) settings.createFlags = CreateFlags.SoftwareVertexProcessing; else throw new OutputSettingsException(type.GetProperty("CreateFlags"), requirements.HardwareTnL, null); if (requirements.MultiSample <= caps.AntiAliasing.MaxSupported) settings.multisample = requirements.MultiSample; else if (fallbacks.MultiSample <= caps.AntiAliasing.MaxSupported) settings.multisample = fallbacks.MultiSample; else throw new OutputSettingsException(type.GetProperty("AntiAliasing"), requirements.MultiSample, caps.AntiAliasing.MaxSupported); return settings; }
public static bool CreateGraphicsDevice3D(GraphicsDeviceSettings settings, Control deviceTarget, out GraphicsDeviceSettings outSettings, out Device device, out PresentParameters pParams) { try { pParams = new PresentParameters(); if (settings.DepthFormat != DepthFormat.Unknown) { pParams.EnableAutoDepthStencil = true; pParams.AutoDepthStencilFormat = settings.DepthFormat; } if (settings.DisplayFormat != Format.Unknown) pParams.BackBufferFormat = settings.DisplayFormat; pParams.MultiSample = settings.MultiSample; pParams.SwapEffect = SwapEffect.Discard; pParams.Windowed = settings.Windowed; device = new Device(settings.Adapter, settings.Type, deviceTarget, settings.CreateFlags, pParams); // capture actual final output description outSettings = new GraphicsDeviceSettings(settings.Adapter, settings.Windowed, device.CreationParameters.DeviceType, device.DisplayMode.Format, device.GetBackBuffer(0, 0, BackBufferType.Mono).Description.MultiSampleType, device.PresentationParameters.AutoDepthStencilFormat, settings.CreateFlags); return true; } catch (Exception) { } pParams = null; device = null; outSettings = null; return false; }
protected virtual void InitializeEnvironment(CommonDeviceInterface cdi, HashTableSettings localSettings) { // Get device settings if (outCaps == null) outCaps = GraphicsDeviceCaps.GetDefaultAdapterCaps(outProfile.RecommendedVariations[0]); // find first recommended settings with full match bool fullMatch = false; outSettings = GraphicsDeviceSettings.CreateFromRequirements(outProfile.RecommendedVariation, outCaps, outProfile.MinReqs, out fullMatch); // Set up the presentation parameters presentParams.Windowed = outProfile.RecommendedVariations[0].Windowed; presentParams.SwapEffect = SwapEffect.Discard; presentParams.AutoDepthStencilFormat = outSettings.DepthFormat; presentParams.EnableAutoDepthStencil = (outSettings.DepthFormat != DepthFormat.Unknown); presentParams.MultiSample = outSettings.MultiSample; CreateDevice(); devIf = new DeviceInterface(gDevice, cdi, localSettings); gPipeline = new GraphicsPipeline(gDevice); }