public void Render(float blend = 1)
        {
            bool shouldrender = _invalidated ||
                                Canvas.NeedsRedraw ||
                                (Track.PlaybackMode) ||
                                Loading ||
                                Track.NeedsDraw ||
                                SelectedTool.NeedsRender;

            _invalidated = false;
            if (shouldrender)
            {
                BeginOrtho();
                var slider = Canvas.Scrubber;
                if (blend == 1 && Settings.SmoothPlayback && Track.Playing && !slider.Held)
                {
                    blend = Math.Min(1, (float)Scheduler.ElapsedPercent);
                    if (ReversePlayback)
                    {
                        blend = 1 - blend;
                    }
                    Track.Camera.BeginFrame(blend, Track.Zoom);
                }
                else
                {
                    Track.Camera.BeginFrame(blend, Track.Zoom);
                }
                GL.ClearColor(Settings.NightMode
                   ? Constants.ColorNightMode
                   : (Settings.WhiteBG ? Constants.ColorWhite : Constants.ColorOffwhite));
                MSAABuffer.Use(RenderSize.Width, RenderSize.Height);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                GL.Clear(ClearBufferMask.ColorBufferBit);
                GL.Enable(EnableCap.Blend);
                GL.Disable(EnableCap.Lighting);

#if debuggrid
                if (this.Keyboard.GetState().IsKeyDown(Key.C))
                {
                    GameRenderer.DbgDrawGrid();
                }
#endif
                Track.Render(blend);
#if debugcamera
                if (this.Keyboard.GetState().IsKeyDown(Key.C))
                {
                    GameRenderer.DbgDrawCamera();
                }
#endif
                SelectedTool.Render();
                Canvas.RenderCanvas();
                MSAABuffer.End();

                if (Settings.NightMode)
                {
                    StaticRenderer.RenderRect(new FloatRect(0, 0, RenderSize.Width, RenderSize.Height), Color.FromArgb(40, 0, 0, 0));
                }
                SwapBuffers();
                //there are machines and cases where a refresh may not hit the screen without calling glfinish...
                GL.Finish();
                var seconds = Track.FramerateWatch.Elapsed.TotalSeconds;
                Track.FramerateCounter.AddFrame(seconds);
                Track.FramerateWatch.Restart();
            }
            if (!Track.Playing &&
                !Canvas.NeedsRedraw &&
                !Track.NeedsDraw &&
                !SelectedTool.Active)//if nothing is waiting on us we can let the os breathe
            {
                Thread.Sleep(10);
            }
        }
Exemplo n.º 2
0
        public void Render()
        {
            if (Canvas.NeedsRedraw || (Track.Animating && AllowTrackRender) || Loading || Track.RequiresUpdate)
            {
                BeginOrtho();
                GL.ClearColor(Settings.Default.NightMode
                                        ? ColorNightMode
                                        : (Settings.Default.WhiteBG ? ColorWhite : ColorOffwhite));
                GL.Clear(ClearBufferMask.ColorBufferBit);
                MSAABuffer.Use(RenderSize.Width, RenderSize.Height);
                AllowTrackRender = false;
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                GL.Clear(ClearBufferMask.ColorBufferBit);
                GL.Enable(EnableCap.Blend);
                var seconds = Track.Fpswatch.Elapsed.TotalSeconds;
                Track.FpsCounter.AddFrame(seconds);
                Track.Fpswatch.Restart();
#if debuggrid
                int sqsize = 128;
                GL.PushMatrix();
                GL.Scale(Track.Zoom, Track.Zoom, 0);
                GL.Translate(new Vector3d(ScreenTranslation));
                GL.Begin(PrimitiveType.Quads);
                for (var x = -sqsize; x < (RenderSize.Width / Track.Zoom); x += sqsize)
                {
                    for (var y = -sqsize; y < (RenderSize.Height / Track.Zoom); y += sqsize)
                    {
                        var yv = new Vector2d(x + (ScreenPosition.X - (ScreenPosition.X % sqsize)), y + (ScreenPosition.Y - (ScreenPosition.Y % sqsize)));
                        if (Track.FastGridCheck(yv.X, yv.Y))
                        {
                            GL.Color3(Color.Yellow);
                            GL.Vertex2(yv);
                            yv.Y += sqsize;
                            GL.Vertex2(yv);
                            yv.X += sqsize;
                            GL.Vertex2(yv);
                            yv.Y -= sqsize;
                            GL.Vertex2(yv);
                        }
                    }
                }

                GL.End();
                GL.Begin(PrimitiveType.Lines);
                GL.Color3(Color.Red);
                for (var x = -sqsize; x < (RenderSize.Width / Track.Zoom); x += sqsize)
                {
                    var yv = new Vector2d(x + (ScreenPosition.X - (ScreenPosition.X % sqsize)), ScreenPosition.Y);
                    GL.Vertex2(yv);
                    yv.Y += RenderSize.Height / Track.Zoom;
                    GL.Vertex2(yv);
                }
                for (var y = -sqsize; y < (RenderSize.Height / Track.Zoom); y += sqsize)
                {
                    var yv = new Vector2d(ScreenPosition.X, y + (ScreenPosition.Y - (ScreenPosition.Y % sqsize)));
                    GL.Vertex2(yv);
                    yv.X += RenderSize.Width / Track.Zoom;
                    GL.Vertex2(yv);
                }
                GL.End();
                GL.PopMatrix();
#endif

                Track.Render();
                Canvas.RenderCanvas();

                SelectedTool.Render();
                MSAABuffer.End();

                if (Settings.Default.NightMode)
                {
                    StaticRenderer.RenderRect(new FloatRect(0, 0, RenderSize.Width, RenderSize.Height), Color.FromArgb(40, 0, 0, 0));
                }
                if (!TrackRecorder.Recording)
                {
                    SwapBuffers();
                }
            }
            LimitFPS();
        }