public IGraphicsDevice CreateDevice(DeviceCreationFlags flags) { //SDL2 supported das Einbinden in ein Fenster nicht Toolkit toolkit = Toolkit.Init(new ToolkitOptions() { Backend = PlatformBackend.PreferNative }); if (OpenTK.Configuration.RunningOnWindows) { WindowInfo = Utilities.CreateWindowsWindowInfo(control.Handle); } else if (OpenTK.Configuration.RunningOnMacOS) { WindowInfo = Utilities.CreateMacOSWindowInfo(control.Handle); } GraphicsContextFlags contextFlags = GraphicsContextFlags.Default; if (flags.HasFlag(DeviceCreationFlags.Debug)) { contextFlags = GraphicsContextFlags.Debug; } GraphicsContext context = new GraphicsContext(GraphicsMode.Default, WindowInfo, 4, 5, contextFlags); context.LoadAll(); return(new GraphicsDevice(this, this, context, flags)); }
public void CreateDevice(object hostControl, DeviceCreationFlags flags) { OnDeviceChangeBegin(this, EventArgs.Empty); // SwapChain description var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(PreferredBackBufferWidth, PreferredBackBufferHeight, new Rational(60, 1), PreferredBackBufferFormat), IsWindowed = true, OutputHandle = (IntPtr)hostControl, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; IsDebugMode = flags.HasFlag(DeviceCreationFlags.Debug); var device = ToDispose(new Device(DriverType.Hardware, flags, PreferredGraphicsProfile[0])); this.device = ToDispose(device.QueryInterface <Device1>()); var factory = ToDispose(new Factory1()); swapChain = ToDispose(new SwapChain(factory, device, desc)); factory.MakeWindowAssociation(swapChain.Description.OutputHandle, WindowAssociationFlags.IgnoreAll); // New RenderTargetView from the backbuffer backBuffer = ToDispose(Resource.FromSwapChain <Texture2D>(swapChain, 0)); renderTargetView = ToDispose(new RenderTargetView(device, backBuffer)); context = ToDispose(this.device.ImmediateContext.QueryInterface <DeviceContext1>()); OnDeviceCreated(this, EventArgs.Empty); OnDeviceChangeEnd(this, EventArgs.Empty); }
internal static MyRenderDeviceSettings CreateDevice(IntPtr windowHandle, MyRenderDeviceSettings?settingsToTry) { if (Device != null) { Device.Dispose(); Device = null; } FeatureLevel[] featureLevels = { FeatureLevel.Level_11_0 }; DeviceCreationFlags flags = DeviceCreationFlags.None; #if DEBUG_DEVICE flags |= DeviceCreationFlags.Debug; #endif WinApi.DEVMODE mode = new WinApi.DEVMODE(); WinApi.EnumDisplaySettings(null, WinApi.ENUM_REGISTRY_SETTINGS, ref mode); var adapters = GetAdaptersList(); int adapterIndex = settingsToTry.HasValue ? settingsToTry.Value.AdapterOrdinal : -1; adapterIndex = ValidateAdapterIndex(adapterIndex); if (adapterIndex == -1) { throw new MyRenderException("No supporting device detected!", MyRenderExceptionEnum.GpuNotSupported); } var settings = settingsToTry ?? new MyRenderDeviceSettings() { AdapterOrdinal = adapterIndex, BackBufferHeight = mode.dmPelsHeight, BackBufferWidth = mode.dmPelsWidth, WindowMode = MyWindowModeEnum.Fullscreen, RefreshRate = 60000, VSync = false, }; m_settings = settings; Device = new Device(GetFactory().Adapters[adapters[m_settings.AdapterOrdinal].AdapterDeviceId], flags, FeatureLevel.Level_11_0); // HACK: This is required for Steam overlay to work. Apparently they hook only CreateDevice methods with DriverType argument. try { using (new Device(DriverType.Hardware, flags, FeatureLevel.Level_11_0)){} } catch { } if (flags.HasFlag(DeviceCreationFlags.Debug)) { if (DebugDevice != null) { DebugDevice.Dispose(); DebugDevice = null; } DebugDevice = new DeviceDebug(Device); DebugInfoQueue = DebugDevice.QueryInterface <InfoQueue>(); new System.Threading.Thread(ProcessDebugOutput).Start(); } if (ImmediateContext != null) { ImmediateContext.Dispose(); ImmediateContext = null; } ImmediateContext = Device.ImmediateContext; m_windowHandle = windowHandle; m_resolution = new Vector2I(m_settings.BackBufferWidth, m_settings.BackBufferHeight); if (!m_initialized) { InitSubsystems(); m_initialized = true; } if (m_swapchain != null) { m_swapchain.Dispose(); m_swapchain = null; } if (m_swapchain == null) { SharpDX.DXGI.Device d = Device.QueryInterface <SharpDX.DXGI.Device>(); Adapter a = d.GetParent <Adapter>(); var factory = a.GetParent <Factory>(); var scDesc = new SwapChainDescription(); scDesc.BufferCount = MyRender11Constants.BUFFER_COUNT; scDesc.Flags = SwapChainFlags.AllowModeSwitch; scDesc.IsWindowed = true; scDesc.ModeDescription.Format = MyRender11Constants.BACKBUFFER_FORMAT; scDesc.ModeDescription.Height = m_settings.BackBufferHeight; scDesc.ModeDescription.Width = m_settings.BackBufferWidth; scDesc.ModeDescription.RefreshRate.Numerator = m_settings.RefreshRate; scDesc.ModeDescription.RefreshRate.Denominator = 1000; scDesc.ModeDescription.Scaling = DisplayModeScaling.Unspecified; scDesc.ModeDescription.ScanlineOrdering = DisplayModeScanlineOrder.Progressive; scDesc.SampleDescription.Count = 1; scDesc.SampleDescription.Quality = 0; scDesc.OutputHandle = m_windowHandle; scDesc.Usage = Usage.RenderTargetOutput; scDesc.SwapEffect = SwapEffect.Discard; m_swapchain = new SwapChain(factory, Device, scDesc); m_swapchain.GetParent <Factory>().MakeWindowAssociation(m_windowHandle, WindowAssociationFlags.IgnoreAll); } // we start with window always (DXGI recommended) m_settings.WindowMode = MyWindowModeEnum.Window; ApplySettings(settings); return(m_settings); }