public bool Init(DXForm form, bool autostart = true) { dxform = form; autoStartLoop = autostart; try { SwapChainDescription scd = new SwapChainDescription() { BufferCount = 2, Flags = SwapChainFlags.None, IsWindowed = true, ModeDescription = new ModeDescription( form.Form.ClientSize.Width, form.Form.ClientSize.Height, new Rational(0, 0), Format.R8G8B8A8_UNorm), OutputHandle = form.Form.Handle, SampleDescription = new SampleDescription(multisamplecount, multisamplequality), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; FeatureLevel[] levels = new FeatureLevel[] { FeatureLevel.Level_11_0, FeatureLevel.Level_10_1, FeatureLevel.Level_10_0 }; DeviceCreationFlags flags = DeviceCreationFlags.None; //#if DEBUG // flags = DeviceCreationFlags.Debug; //#endif Device dev = null; SwapChain sc = null; Exception exc = null; bool success = false; try { Device.CreateWithSwapChain(DriverType.Hardware, flags, levels, scd, out dev, out sc); success = true; } catch (Exception ex) { exc = ex; } if (!success) { multisamplecount = 1; multisamplequality = 0; scd.SampleDescription = new SampleDescription(1, 0); //try no AA try { Device.CreateWithSwapChain(DriverType.Hardware, flags, levels, scd, out dev, out sc); success = true; } catch (Exception ex) { exc = ex; } } if (!success) { var msg = "CodeWalker was unable to initialise the graphics device. Please ensure your system meets the minimum requirements and that your graphics drivers and DirectX are up to date."; if (exc != null) { msg += "\n\nException info: " + exc.ToString(); } throw new Exception(msg); } device = dev; swapchain = sc; var factory = swapchain.GetParent <Factory>(); //ignore windows events... factory.MakeWindowAssociation(form.Form.Handle, WindowAssociationFlags.IgnoreAll); context = device.ImmediateContext; CreateRenderBuffers(); dxform.Form.Load += Dxform_Load; dxform.Form.FormClosing += Dxform_FormClosing; dxform.Form.ClientSizeChanged += Dxform_ClientSizeChanged; dxform.Form.ResizeBegin += DxForm_ResizeBegin; dxform.Form.ResizeEnd += DxForm_ResizeEnd; if (autostart) { dxform.InitScene(device); } return(true); } catch (Exception ex) { MessageBox.Show("Unable to initialise DirectX11.\n" + ex.Message, "CodeWalker - Error!"); return(false); } }
public void Start() { dxform.InitScene(device); StartRenderLoop(); }