Example #1
0
        /// <summary>
        /// Updates DirectX objects and calls.
        /// Layers are updated first, then the derived control is updated.
        /// </summary>
        protected virtual void UpdateDx(RenderTime updateTime)
        {
            OnUpdating(updateTime);

            lock (Layers)
            {
                Stopwatch sw = Stopwatch.StartNew();
                foreach (var layer in Layers)
                {
                    RenderProfile profile;
                    if (!ProfileStats.TryGetValue(layer.Name, out profile))
                    {
                        profile = new RenderProfile();
                        ProfileStats.Add(layer.Name, profile);
                    }

                    var start = sw.Elapsed;
                    layer.Update(updateTime);
                    profile.UpdateTime = (float)(sw.Elapsed - start).TotalMilliseconds;
                }
            }

            // Update our derived control
            OnUpdated(updateTime);
        }
Example #2
0
        /// <summary>
        /// Local render. Performs timing calculations and debug rendering if required then calls <see cref="OnRendering"/> for inheriting controls. Presents the swap chain when ready.
        /// </summary>
        protected void Render(RenderTime renderTime)
        {
            if (!PresenterReady)
            {
                return;
            }
            // Update our derived control

            RenderTarget2D.BeginDraw();
            OnRendering(renderTime);

            lock (Layers)
            {
                Stopwatch sw = Stopwatch.StartNew();
                foreach (var layer in Layers)
                {
                    RenderProfile profile;
                    if (!ProfileStats.TryGetValue(layer.Name, out profile))
                    {
                        profile = new RenderProfile();
                        ProfileStats.Add(layer.Name, profile);
                    }

                    var start = sw.Elapsed;
                    layer.Render(renderTime);
                    profile.RenderTime = (float)(sw.Elapsed - start).TotalMilliseconds;
                }
                sw.Stop();
            }

            OnRendered(renderTime);
            RenderTarget2D.EndDraw();

            OnRender3D();

            _swapChain.Present(0, PresentFlags.None);
        }