/// <summary> /// Saves the current DXConfiguration /// </summary> private void SaveDxConfiguration() { Stream stream = null; try { Cursor = Cursors.WaitCursor; string configFile = server_.ServerName + ".dxconfig"; // create the configuartion file. stream = new FileStream(configFile, FileMode.Create, FileAccess.Write, FileShare.None); // populate the user settings object. DxConfiguration configuration = new DxConfiguration(); configuration.Target = mTarget_; // serialize the user settings object. new BinaryFormatter().Serialize(stream, configuration); } catch { // ignore errors. } finally { // close the stream. if (stream != null) { stream.Close(); } Cursor = Cursors.Default; } }
internal unsafe NativeConfiguration(DxConfiguration *configuration, string symbol) : base(symbol) { DxConfiguration c = *configuration; Version = c.version; Attachment = new string((char *)c.string_object.ToPointer()); }
protected override void Initialize(DxConfiguration demoConfiguration) { // SwapChain description var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription = new ModeDescription(demoConfiguration.Width, demoConfiguration.Height, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = DisplayHandle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; // Create Device and SwapChain SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, new[] { FeatureLevel.Level_10_0 }, desc, out _device, out _swapChain); // Ignore all windows events var factory = _swapChain.GetParent <Factory>(); factory.MakeWindowAssociation(DisplayHandle, WindowAssociationFlags.IgnoreAll); // New RenderTargetView from the backbuffer _backBuffer = Texture2D.FromSwapChain <Texture2D>(_swapChain, 0); _backBufferView = new RenderTargetView(_device, _backBuffer); }
/// <summary> /// Runs the demo. /// </summary> public void Run(DxConfiguration dx_configuration) { this.Config = dx_configuration ?? new DxConfiguration(); form = CreateForm(this.Config); Initialize(Config); var isFormClosed = false; var formIsResizing = false; form.MouseClick += HandleMouseClick; form.KeyDown += HandleKeyDown; form.KeyUp += HandleKeyUp; form.Resize += (o, args) => { if (form.WindowState != _currentFormWindowState) { HandleResize(o, args); } _currentFormWindowState = form.WindowState; }; form.ResizeBegin += (o, args) => formIsResizing = true; form.ResizeEnd += (o, args) => { formIsResizing = false; HandleResize(o, args); }; form.Closed += (o, args) => isFormClosed = true; LoadContent(); clock.Start(); BeginRun(); RenderLoop.Run(form, () => { if (isFormClosed) { return; } OnUpdate(); if (!formIsResizing) { Render(); } }); UnloadContent(); EndRun(); // Dispose explicity Dispose(); }
/// <summary> /// Create Form for this demo. /// </summary> /// <param name="config"></param> /// <returns></returns> protected virtual Form CreateForm(DxConfiguration config) { return(new RenderForm(config.Title) { ClientSize = new System.Drawing.Size(config.Width, config.Height), Icon = null, FormBorderStyle = FormBorderStyle.FixedSingle, ShowIcon = false, MaximizeBox = false }); }
protected override void Initialize(DxConfiguration demoConfiguration) { base.Initialize(demoConfiguration); Factory2D = new Factory(); using (var surface = BackBuffer.QueryInterface <Surface>()) { RenderTarget2D = new RenderTarget(Factory2D, surface, new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied))); } RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive; FactoryDWrite = new SharpDX.DirectWrite.Factory(); SceneColorBrush = new SolidColorBrush(RenderTarget2D, Color.White); }
/// <summary> /// In a derived class, implements logic to initialize the sample. /// </summary> protected abstract void Initialize(DxConfiguration dx_configuration);