예제 #1
0
 public ContextRef GetContextForGraphicsControl(GraphicsControl gc)
 {
     return new ContextRef
     {
         gc = gc
     };
 }
예제 #2
0
        public DisplayManager(PresentationPanel presentationPanel)
        {
            GL = GlobalWin.GL;
            this.presentationPanel = presentationPanel;
            GraphicsControl = this.presentationPanel.GraphicsControl;
            CR_GraphicsControl = GlobalWin.GLManager.GetContextForGraphicsControl(GraphicsControl);

            //it's sort of important for these to be initialized to something nonzero
            currEmuWidth = currEmuHeight = 1;

            if (GL is BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK)
                Renderer = new GuiRenderer(GL);
            else if (GL is BizHawk.Bizware.BizwareGL.Drivers.SlimDX.IGL_SlimDX9)
                Renderer = new GuiRenderer(GL);
            else
                Renderer = new GDIPlusGuiRenderer((BizHawk.Bizware.BizwareGL.Drivers.GdiPlus.IGL_GdiPlus)GL);

            VideoTextureFrugalizer = new TextureFrugalizer(GL);

            ShaderChainFrugalizers = new RenderTargetFrugalizer[16]; //hacky hardcoded limit.. need some other way to manage these
            for (int i = 0; i < 16; i++)
            {
                ShaderChainFrugalizers[i] = new RenderTargetFrugalizer(GL);
            }

            using (var xml = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.courier16px.fnt"))
            using (var tex = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.courier16px_0.png"))
                TheOneFont = new StringRenderer(GL, xml, tex);

            using (var gens = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.gens.ttf"))
                LoadCustomFont(gens);
            using (var fceux = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Client.EmuHawk.Resources.fceux.ttf"))
                LoadCustomFont(fceux);

            if (GL is BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK || GL is BizHawk.Bizware.BizwareGL.Drivers.SlimDX.IGL_SlimDX9)
            {
                var fiHq2x = new FileInfo(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk/hq2x.cgp"));
                if (fiHq2x.Exists)
                    using (var stream = fiHq2x.OpenRead())
                        ShaderChain_hq2x = new Filters.RetroShaderChain(GL, new Filters.RetroShaderPreset(stream), Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk"));
                var fiScanlines = new FileInfo(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk/BizScanlines.cgp"));
                if (fiScanlines.Exists)
                    using (var stream = fiScanlines.OpenRead())
                        ShaderChain_scanlines = new Filters.RetroShaderChain(GL, new Filters.RetroShaderPreset(stream), Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk"));
                string bicubic_path = "Shaders/BizHawk/bicubic-fast.cgp";
                if(GL is BizHawk.Bizware.BizwareGL.Drivers.SlimDX.IGL_SlimDX9)
                    bicubic_path = "Shaders/BizHawk/bicubic-normal.cgp";
                var fiBicubic = new FileInfo(Path.Combine(PathManager.GetExeDirectoryAbsolute(), bicubic_path));
                if (fiBicubic.Exists)
                    using (var stream = fiBicubic.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
                        ShaderChain_bicubic = new Filters.RetroShaderChain(GL, new Filters.RetroShaderPreset(stream), Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk"));
            }

            LuaSurfaceSets["emu"] = new SwappableDisplaySurfaceSet();
            LuaSurfaceSets["native"] = new SwappableDisplaySurfaceSet();
            LuaSurfaceFrugalizers["emu"] = new TextureFrugalizer(GL);
            LuaSurfaceFrugalizers["native"] = new TextureFrugalizer(GL);

            RefreshUserShader();
        }
예제 #3
0
        public DisplayManager(PresentationPanel presentationPanel, IGL gl, GLManager glManager)
        {
            GL = gl;
            this.presentationPanel = presentationPanel;
            GraphicsControl = this.presentationPanel.GraphicsControl;
            CR_GraphicsControl = glManager.GetContextForGraphicsControl(GraphicsControl);
            _glManager = glManager;

            //it's sort of important for these to be initialized to something nonzero
            currEmuWidth = currEmuHeight = 1;

            if (GL is BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK)
                Renderer = new GuiRenderer(GL);
            else if (GL is BizHawk.Bizware.BizwareGL.Drivers.SlimDX.IGL_SlimDX9)
                Renderer = new GuiRenderer(GL);
            else
                Renderer = new GDIPlusGuiRenderer((BizHawk.Bizware.BizwareGL.Drivers.GdiPlus.IGL_GdiPlus)GL);

            VideoTextureFrugalizer = new BizHawk.Client.EmuHawk.TextureFrugalizer(GL);

            ShaderChainFrugalizers = new RenderTargetFrugalizer[16]; //hacky hardcoded limit.. need some other way to manage these
            for (int i = 0; i < 16; i++)
            {
                ShaderChainFrugalizers[i] = new RenderTargetFrugalizer(GL);
            }

            RefreshUserShader();
        }
예제 #4
0
		public PresentationPanel()
		{
			GL = GlobalWin.GL;

			GraphicsControl = new GraphicsControl(GL);
			GraphicsControl.Dock = DockStyle.Fill;
			GraphicsControl.BackColor = Color.Black;

			//pass through these events to the form. we might need a more scalable solution for mousedown etc. for zapper and whatnot.
			//http://stackoverflow.com/questions/547172/pass-through-mouse-events-to-parent-control (HTTRANSPARENT)
			GraphicsControl.MouseDoubleClick += (o, e) => HandleFullscreenToggle(o, e);
			GraphicsControl.MouseClick += (o, e) => GlobalWin.MainForm.MainForm_MouseClick(o, e);
		}
예제 #5
0
        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();

                NeedsToPaint = false; //??
            }
        }
예제 #6
0
        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(); //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));

            GlobalWin.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);
                //apply the vsync setting (should probably try to avoid repeating this)
                bool vsync = Global.Config.VSyncThrottle || Global.Config.VSync;

                //only used by alternate vsync
                var dx9 = GlobalWin.GL as BizHawk.Bizware.BizwareGL.Drivers.SlimDX.IGL_SlimDX9;

                //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
                bool alternateVsync = false;
                if (dx9 != null)
                {
                    alternateVsync = Global.Config.DispAlternateVsync && vsync && Global.Config.VSyncThrottle;
                    //unset normal vsync if we've chosen the alternate vsync
                    if (alternateVsync)
                        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;
                }

                //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();
            }
        }