Exemple #1
0
 /// <summary>
 /// Create Form for this demo.
 /// </summary>
 /// <param name="config"></param>
 /// <returns></returns>
 protected virtual Form CreateForm(DemoConfiguration config)
 {
     return(new RenderForm(config.Title)
     {
         ClientSize = new Size(config.Width, config.Height)
     });
 }
Exemple #2
0
        /// <summary>
        /// Runs the demo.
        /// </summary>
        public void Run(DemoConfiguration demoConfiguration)
        {
            this.demoConfiguration = demoConfiguration ?? new DemoConfiguration();
            this.form = this.CreateForm(this.demoConfiguration);
            this.Initialize(this.demoConfiguration);

            var isFormClosed   = false;
            var formIsResizing = false;

            this.form.MouseClick += this.HandleMouseClick;
            this.form.KeyDown    += this.HandleKeyDown;
            this.form.KeyUp      += this.HandleKeyUp;
            this.form.Resize     += (o, args) =>
            {
                if (this.form.WindowState != this.currentFormWindowState)
                {
                    this.HandleResize(o, args);
                }

                this.currentFormWindowState = this.form.WindowState;
            };

            this.form.ResizeBegin += (o, args) => { formIsResizing = true; };
            this.form.ResizeEnd   += (o, args) =>
            {
                formIsResizing = false;
                this.HandleResize(o, args);
            };

            this.form.Closed += (o, args) => { isFormClosed = true; };

            this.LoadContent();

            this.clock.Start();
            this.BeginRun();
            RenderLoop.Run(
                this.form,
                () =>
            {
                if (isFormClosed)
                {
                    return;
                }

                this.OnUpdate();
                if (!formIsResizing)
                {
                    this.Render();
                }
            });

            this.UnloadContent();
            this.EndRun();

            // Dispose explicity
            this.Dispose();
        }
        protected override void Initialize(DemoConfiguration 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      = this.DisplayHandle,
                SampleDescription = new SampleDescription(1, 0),
                SwapEffect        = SwapEffect.Discard,
                Usage             = Usage.RenderTargetOutput
            };

            // Create Device and SwapChain
            FeatureLevel featureLevel = new Device(DriverType.Hardware).FeatureLevel;

            if (featureLevel > FeatureLevel.Level_11_0)
            {
                featureLevel = FeatureLevel.Level_11_0;
            }

            Device.CreateWithSwapChain(
                DriverType.Hardware,
                DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug,
                new[] { featureLevel },
                desc,
                out this.device,
                out this.swapChain);

            // Ignore all windows events
            var factory = this.swapChain.GetParent <Factory>();

            factory.MakeWindowAssociation(this.DisplayHandle, WindowAssociationFlags.IgnoreAll);

            this.CreateBackBuffer();
        }
Exemple #4
0
 /// <summary>
 /// In a derived class, implements logic to initialize the sample.
 /// </summary>
 protected abstract void Initialize(DemoConfiguration demoConfiguration);