Exemple #1
0
        void UpdateSourceDrawingWork(JobInfo job)
        {
            bool vsync          = false;
            bool alternateVsync = false;
            //only used by alternate vsync
            IGL_SlimDX9 dx9 = null;

            if (!job.offscreen)
            {
                //apply the vsync setting (should probably try to avoid repeating this)
                vsync = Global.Config.VSyncThrottle || Global.Config.VSync;

                //ok, now this is a bit undesireable.
                //maybe the user wants vsync, but not vsync throttle.
                //this makes sense... but we dont have the infrastructure to support it now (we'd have to enable triple buffering or something like that)
                //so what we're gonna do is disable vsync no matter what if throttling is off, and maybe nobody will notice.
                //update 26-mar-2016: this upsets me. When fastforwarding and skipping frames, vsync should still work. But I'm not changing it yet
                if (Global.DisableSecondaryThrottling)
                {
                    vsync = false;
                }

                //for now, it's assumed that the presentation panel is the main window, but that may not always be true
                if (vsync && Global.Config.DispAlternateVsync && Global.Config.VSyncThrottle)
                {
                    dx9 = GL as IGL_SlimDX9;
                    if (dx9 != null)
                    {
                        alternateVsync = true;
                        //unset normal vsync if we've chosen the alternate vsync
                        vsync = false;
                    }
                }

                //TODO - whats so hard about triple buffering anyway? just enable it always, and change api to SetVsync(enable,throttle)
                //maybe even SetVsync(enable,throttlemethod) or just SetVsync(enable,throttle,advanced)

                if (LastVsyncSetting != vsync || LastVsyncSettingGraphicsControl != presentationPanel.GraphicsControl)
                {
                    if (LastVsyncSetting == null && vsync)
                    {
                        // Workaround for vsync not taking effect at startup (Intel graphics related?)
                        presentationPanel.GraphicsControl.SetVsync(false);
                    }
                    presentationPanel.GraphicsControl.SetVsync(vsync);
                    LastVsyncSettingGraphicsControl = presentationPanel.GraphicsControl;
                    LastVsyncSetting = vsync;
                }
            }

            //begin rendering on this context
            //should this have been done earlier?
            //do i need to check this on an intel video card to see if running excessively is a problem? (it used to be in the FinalTarget command below, shouldnt be a problem)
            //GraphicsControl.Begin(); //CRITICAL POINT for yabause+GL

            //TODO - auto-create and age these (and dispose when old)
            int rtCounter = 0;

            CurrentFilterProgram.RenderTargetProvider = new DisplayManagerRenderTargetProvider((size) => ShaderChainFrugalizers[rtCounter++].Get(size));

            GL.BeginScene();

            //run filter chain
            Texture2d    texCurr       = null;
            RenderTarget rtCurr        = null;
            bool         inFinalTarget = false;

            foreach (var step in CurrentFilterProgram.Program)
            {
                switch (step.Type)
                {
                case FilterProgram.ProgramStepType.Run:
                {
                    int fi = (int)step.Args;
                    var f  = CurrentFilterProgram.Filters[fi];
                    f.SetInput(texCurr);
                    f.Run();
                    var orec = f.FindOutput();
                    if (orec != null)
                    {
                        if (orec.SurfaceDisposition == SurfaceDisposition.Texture)
                        {
                            texCurr = f.GetOutput();
                            rtCurr  = null;
                        }
                    }
                    break;
                }

                case FilterProgram.ProgramStepType.NewTarget:
                {
                    var size = (Size)step.Args;
                    rtCurr = ShaderChainFrugalizers[rtCounter++].Get(size);
                    rtCurr.Bind();
                    CurrentFilterProgram.CurrRenderTarget = rtCurr;
                    break;
                }

                case FilterProgram.ProgramStepType.FinalTarget:
                {
                    var size = (Size)step.Args;
                    inFinalTarget = true;
                    rtCurr        = null;
                    CurrentFilterProgram.CurrRenderTarget = null;
                    GL.BindRenderTarget(null);
                    break;
                }
                }
            }

            GL.EndScene();

            if (job.offscreen)
            {
                job.offscreenBB = rtCurr.Texture2d.Resolve();
                job.offscreenBB.DiscardAlpha();
            }
            else
            {
                Debug.Assert(inFinalTarget);

                //wait for vsync to begin
                if (alternateVsync)
                {
                    dx9.AlternateVsyncPass(0);
                }

                //present and conclude drawing
                presentationPanel.GraphicsControl.SwapBuffers();

                //wait for vsync to end
                if (alternateVsync)
                {
                    dx9.AlternateVsyncPass(1);
                }

                //nope. dont do this. workaround for slow context switching on intel GPUs. just switch to another context when necessary before doing anything
                //presentationPanel.GraphicsControl.End();
            }
        }
        void UpdateSourceDrawingWork(JobInfo job)
        {
            //begin rendering on this context
            //should this have been done earlier?
            //do i need to check this on an intel video card to see if running excessively is a problem? (it used to be in the FinalTarget command below, shouldnt be a problem)
            //GraphicsControl.Begin();

            //run filter chain
            Texture2d    texCurr       = null;
            RenderTarget rtCurr        = null;
            int          rtCounter     = 0;
            bool         inFinalTarget = false;

            foreach (var step in CurrentFilterProgram.Program)
            {
                switch (step.Type)
                {
                case FilterProgram.ProgramStepType.Run:
                {
                    int fi = (int)step.Args;
                    var f  = CurrentFilterProgram.Filters[fi];
                    f.SetInput(texCurr);
                    f.Run();
                    var orec = f.FindOutput();
                    if (orec != null)
                    {
                        if (orec.SurfaceDisposition == SurfaceDisposition.Texture)
                        {
                            texCurr = f.GetOutput();
                            rtCurr  = null;
                        }
                    }
                    break;
                }

                case FilterProgram.ProgramStepType.NewTarget:
                {
                    var size = (Size)step.Args;
                    rtCurr = ShaderChainFrugalizers[rtCounter++].Get(size);
                    rtCurr.Bind();
                    CurrentFilterProgram.CurrRenderTarget = rtCurr;
                    break;
                }

                case FilterProgram.ProgramStepType.FinalTarget:
                {
                    var size = (Size)step.Args;
                    inFinalTarget = true;
                    rtCurr        = null;
                    CurrentFilterProgram.CurrRenderTarget = null;
                    GL.BindRenderTarget(null);
                    break;
                }
                }
            }

            if (job.offscreen)
            {
                job.offscreenBB = rtCurr.Texture2d.Resolve();
            }
            else
            {
                Debug.Assert(inFinalTarget);
                //apply the vsync setting (should probably try to avoid repeating this)
                bool vsync = Global.Config.VSyncThrottle || Global.Config.VSync;

                //ok, now this is a bit undesireable.
                //maybe the user wants vsync, but not vsync throttle.
                //this makes sense... but we dont have the infrastructure to support it now (we'd have to enable triple buffering or something like that)
                //so what we're gonna do is disable vsync no matter what if throttling is off, and maybe nobody will notice.
                if (Global.DisableSecondaryThrottling)
                {
                    vsync = false;
                }

                if (LastVsyncSetting != vsync || LastVsyncSettingGraphicsControl != presentationPanel.GraphicsControl)
                {
                    if (LastVsyncSetting == null && vsync)
                    {
                        // Workaround for vsync not taking effect at startup (Intel graphics related?)
                        presentationPanel.GraphicsControl.SetVsync(false);
                    }
                    presentationPanel.GraphicsControl.SetVsync(vsync);
                    LastVsyncSettingGraphicsControl = presentationPanel.GraphicsControl;
                    LastVsyncSetting = vsync;
                }

                //present and conclude drawing
                presentationPanel.GraphicsControl.SwapBuffers();

                //nope. dont do this. workaround for slow context switching on intel GPUs. just switch to another context when necessary before doing anything
                //presentationPanel.GraphicsControl.End();
            }
        }