public StartForm() { this.BackgroundImage = null; bool FileFail = false; InitializeComponent(); FileStream fs = null; try { fs = new FileStream("Config.bin", FileMode.Open, FileAccess.Read); config = Serializer.Deserialize<Config>(fs); fs.Close(); } catch(Exception ex) { FileFail = true; if (fs != null) fs.Close(); System.Windows.Forms.MessageBox.Show("Error! Небыл найден файл настроек\n" + ex.Message); } ModeDescription[] DML = null; using (SharpDX.DXGI.Factory myFactory = new SharpDX.DXGI.Factory()) { int MyAdapterCount = myFactory.GetAdapterCount(); try { using (SharpDX.DXGI.Adapter MyAdapter = myFactory.GetAdapter(MyAdapterCount - 1)) { using (Output OP = MyAdapter.Outputs[0]) DML = OP.GetDisplayModeList(Format.R8G8B8A8_UNorm, DisplayModeEnumerationFlags.Interlaced); } } catch (System.Exception ex) { using (SharpDX.DXGI.Adapter MyAdapter = myFactory.GetAdapter(MyAdapterCount - 0)) { using (Output OP = MyAdapter.Outputs[0]) DML = OP.GetDisplayModeList(Format.R8G8B8A8_UNorm, DisplayModeEnumerationFlags.Interlaced); } } } int mw = 0, mh = 0; foreach (ModeDescription dm in DML) { bool cor = true; foreach (DisplayMode dmd in LDM) { if (dmd.Width == dm.Width && dmd.Height == dm.Height) { cor = false; } } if (cor && dm.Width >= 1024 && dm.Height >= 768) LDM.Add(new DisplayMode(dm.Width, dm.Height)); if (dm.Width > mw) mw = dm.Width; if (dm.Height > mh) mh = dm.Height; } if (LDM.Count < 1) { System.Windows.Forms.MessageBox.Show("Error! Минимальное поддерживаемое разрешение экрана 1024х768"); this.Close(); } if (config.Width > mw || config.Height > mh) { FileFail = true; } if (GetResIndex(config.Width, config.Height, LDM) < 0) FileFail = true; if (FileFail) { config = new Config(); SaveC(config, "Config.bin"); } SetData(); for (int num = 0; num < LDM.Count; num++) { comboBox1.Items.Add(LDM[num].Width.ToString() + "x" + LDM[num].Height.ToString()); } int Res = GetResIndex(config.Width, config.Height, LDM); if (Res > -1) { comboBox1.SelectedIndex = Res; } if (config.VSync>0) { checkBox1.Checked = true; } else { checkBox1.Checked = false; } if (config.InvAlt > 0) { checkBox3.Checked = true; } else { checkBox3.Checked = false; } comboBox2.Items.Add("High"); comboBox2.Items.Add("Medium"); comboBox2.Items.Add("Low"); comboBox2.Items.Add("Disable"); if (config.Shadow < 1) { comboBox2.SelectedIndex = 3; } else { comboBox2.SelectedIndex = config.ShadowQuality; } comboBox3.Items.Add("Disable"); comboBox3.Items.Add("Low"); comboBox3.Items.Add("Medium"); comboBox3.Items.Add("High"); if (config.MultiSample > -1 && config.MultiSample < 2) { comboBox3.SelectedIndex = 0; } if (config.MultiSample > 1 && config.MultiSample < 4) { comboBox3.SelectedIndex = 1; } if (config.MultiSample > 3 && config.MultiSample < 8) { comboBox3.SelectedIndex = 2; } if (config.MultiSample > 7) { comboBox3.SelectedIndex = 3; } comboBox4.Items.Add("Disable"); comboBox4.Items.Add("4"); comboBox4.Items.Add("8"); comboBox4.Items.Add("12"); if (config.Light > -1 && config.Light < 4) { comboBox4.SelectedIndex = 0; } if (config.Light > 3 && config.Light < 7) { comboBox4.SelectedIndex = 1; } if (config.Light > 7 && config.Light < 11) { comboBox4.SelectedIndex = 2; } if (config.Light > 11) { comboBox4.SelectedIndex = 3; } if (config.FullScr > 0) { checkBox2.Checked = true; } else { checkBox2.Checked = false; } if (config.Refract > 0) { checkBox4.Checked = true; } else { checkBox4.Checked = false; } }
/// <summary> /// Initializes a new engine, sets view , tex manager /// camera , mesh manager , texture manager , line manager /// volume manager /// </summary> /// <param name="width">The width of the Render target</param> /// <param name="height">The height of the Render target</param> public Engine(int Width, int Height, Form form) { // pass the settings of resolution Settings.Resolution = new System.Drawing.Size(Width, Height); /// set the handles for full screen or windows this.form = form; this.FormHandle = form.Handle; /// Create the factory which manages general graphics resources g_factory = new Factory(); g_factory.MakeWindowAssociation(this.FormHandle, WindowAssociationFlags.IgnoreAll); // find correct adapter int adapterCount = g_factory.GetAdapterCount(); //MessageBox.Show(adapterCount.ToString()); // we try to select the PerfHUD adapter for (int i = 0; i < adapterCount; i++) { Adapter adapt = g_factory.GetAdapter(i); //MessageBox.Show(adapt.Description.Description); if (adapt.Description.Description == "NVIDIA PerfHUD") { g_device = new Device( adapt, DeviceCreationFlags.Debug); } Console.WriteLine(i.ToString() + adapt.Description.Description); } if (g_device == null) { #if true /// Create the DirectX Device g_device = new Device(g_factory.GetAdapter(1), (Settings.Debug) ? DeviceCreationFlags.Debug : DeviceCreationFlags.None, new FeatureLevel[] { FeatureLevel.Level_11_0 }); #else g_device = new Device(DriverType.Warp, (Settings.Debug) ? DeviceCreationFlags.Debug : DeviceCreationFlags.None, new FeatureLevel[] { FeatureLevel.Level_11_0 }); #endif // check if we have one device to our system if (!(((g_device.FeatureLevel & FeatureLevel.Level_10_0) != 0) || ((g_device.FeatureLevel & FeatureLevel.Level_10_1) != 0) || ((g_device.FeatureLevel & FeatureLevel.Level_11_0) != 0))) { // if we don't have we just simulate #region Create the device base on swapChain /// Create a description of the display mode g_modeDesc = new ModeDescription(); /// Standard 32-bit RGBA g_modeDesc.Format = Format.R8G8B8A8_UNorm; /// Refresh rate of 60Hz (60 / 1 = 60) g_modeDesc.RefreshRate = new Rational(60, 1); /// Default g_modeDesc.Scaling = DisplayModeScaling.Unspecified; g_modeDesc.ScanlineOrdering = DisplayModeScanlineOrder.Progressive; /// ClientSize is the size of the /// form without the title and borders g_modeDesc.Width = Width; g_modeDesc.Height = Height; /// Create a description of the samping /// for multisampling or antialiasing g_sampleDesc = new SampleDescription(); /// No multisampling g_sampleDesc.Count = 1; g_sampleDesc.Quality = 0; /// Create a description of the swap /// chain or front and back buffers g_swapDesc = new SwapChainDescription(); /// link the ModeDescription g_swapDesc.ModeDescription = g_modeDesc; /// link the SampleDescription g_swapDesc.SampleDescription = g_sampleDesc; /// Number of buffers (including the front buffer) g_swapDesc.BufferCount = 1; g_swapDesc.Flags = SwapChainFlags.AllowModeSwitch; g_swapDesc.IsWindowed = true; /// The output window (the windows being rendered to) g_swapDesc.OutputHandle = this.FormHandle; /// Scrap the contents of the buffer every frame g_swapDesc.SwapEffect = SwapEffect.Discard; /// Indicate that this SwapChain /// is going to be a Render target g_swapDesc.Usage = Usage.RenderTargetOutput; //g_swapChain = new SwapChain(g_factory, g_device, g_swapDesc); try { /// Create the actual swap chain /// Here we set and the device type Device.CreateWithSwapChain(DriverType.Warp, (Settings.Debug) ? DeviceCreationFlags.Debug : DeviceCreationFlags.None, new FeatureLevel[] { Settings.FeatureLevel }, g_swapDesc, out g_device, out g_swapChain); } catch (Exception ex) { /// Create the actual swap chain /// Here we set and the device type Device.CreateWithSwapChain(DriverType.Reference, (Settings.Debug) ? DeviceCreationFlags.Debug : DeviceCreationFlags.None, new FeatureLevel[] { Settings.FeatureLevel }, g_swapDesc, out g_device, out g_swapChain); } /// Create the factory which manages general graphics resources g_factory = g_swapChain.GetParent<Factory>(); g_factory.MakeWindowAssociation(this.FormHandle, WindowAssociationFlags.IgnoreAll); #endregion } else { #if false #region Create the device base on swapChain /// Create a description of the display mode g_modeDesc = new ModeDescription(); /// Standard 32-bit RGBA g_modeDesc.Format = Format.R8G8B8A8_UNorm; /// Refresh rate of 60Hz (60 / 1 = 60) g_modeDesc.RefreshRate = new Rational(60, 1); /// Default g_modeDesc.Scaling = DisplayModeScaling.Unspecified; g_modeDesc.ScanlineOrdering = DisplayModeScanlineOrdering.Progressive; /// ClientSize is the size of the /// form without the title and borders g_modeDesc.Width = Width; g_modeDesc.Height = Height; /// Create a description of the samping /// for multisampling or antialiasing g_sampleDesc = new SampleDescription(); /// No multisampling g_sampleDesc.Count = 1; g_sampleDesc.Quality = 0; /// Create a description of the swap /// chain or front and back buffers g_swapDesc = new SwapChainDescription(); /// link the ModeDescription g_swapDesc.ModeDescription = g_modeDesc; /// link the SampleDescription g_swapDesc.SampleDescription = g_sampleDesc; /// Number of buffers (including the front buffer) g_swapDesc.BufferCount = 1; g_swapDesc.Flags = SwapChainFlags.None; g_swapDesc.IsWindowed = true; /// The output window (the windows being rendered to) g_swapDesc.OutputHandle = FormHandle; /// Scrap the contents of the buffer every frame g_swapDesc.SwapEffect = SwapEffect.Discard; /// Indicate that this SwapChain /// is going to be a Render target g_swapDesc.Usage = Usage.RenderTargetOutput; g_swapChain = new SwapChain(g_factory, g_device, g_swapDesc); #endregion #endif } // set the feature level Settings.FeatureLevel = g_device.FeatureLevel; } /// init mesh manager g_MeshManager = new Object3DManager(); /// init deferred device //DeferredDev1 = new DeviceContext( Engine.g_device ); //DeferredDev2 = new DeviceContext( Engine.g_device ); // init the image factory... g_image_factory = new ImagingFactory(); /// Set flag to indicate that engine is running g_Running = true; Logger.WriteLine("The Graphing Engine have be start "); // set the event handler RenderLoopHandler = new EventHandler(RenderLoop); var rtb = new RenderTargetBlendDescription() { IsBlendEnabled = true, BlendOperation = BlendOperation.Add, AlphaBlendOperation = BlendOperation.Add, DestinationBlend = BlendOption.One, DestinationAlphaBlend = BlendOption.Zero, SourceBlend = BlendOption.One, SourceAlphaBlend = BlendOption.One, RenderTargetWriteMask = ColorWriteMaskFlags.All }; BlendStateDescription blendDesc = new BlendStateDescription(); blendDesc.AlphaToCoverageEnable = false; blendDesc.IndependentBlendEnable = false; blendDesc.RenderTarget[0] = rtb; g_blendState = new BlendState(g_device, blendDesc); DepthStencilStateDescription dssd = new DepthStencilStateDescription(); dssd.DepthComparison = Comparison.Less; dssd.IsDepthEnabled = true; g_depthStencilState = new DepthStencilState(g_device, new DepthStencilStateDescription()); }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { LDM.Clear(); ModeDescription[] DML = null; using (SharpDX.DXGI.Factory myFactory = new SharpDX.DXGI.Factory()) { int MyAdapterCount = myFactory.GetAdapterCount(); try { using (SharpDX.DXGI.Adapter MyAdapter = myFactory.GetAdapter(MyAdapterCount - 1)) { using (Output OP = MyAdapter.Outputs[0]) DML = OP.GetDisplayModeList(Format.R8G8B8A8_UNorm, DisplayModeEnumerationFlags.Interlaced); } } catch (System.Exception ex) { using (SharpDX.DXGI.Adapter MyAdapter = myFactory.GetAdapter(MyAdapterCount - 0)) { using (Output OP = MyAdapter.Outputs[0]) DML = OP.GetDisplayModeList(Format.R8G8B8A8_UNorm, DisplayModeEnumerationFlags.Interlaced); } } } foreach (ModeDescription dm in DML) { bool cor = true; foreach (DisplayMode dmd in LDM) { if (dmd.Width == dm.Width && dmd.Height == dm.Height) { cor = false; } } if (cor && dm.Width >= 1024 && dm.Height >= 768) LDM.Add(new DisplayMode(dm.Width, dm.Height)); } config.Width = LDM[comboBox1.SelectedIndex].Width; config.Height = LDM[comboBox1.SelectedIndex].Height; SetData(); }