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(); }
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; Renderer = new GuiRenderer(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); 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")); var fiBicubic = new FileInfo(Path.Combine(PathManager.GetExeDirectoryAbsolute(), "Shaders/BizHawk/bicubic-fast.cgp")); if (fiBicubic.Exists) using (var stream = fiBicubic.OpenRead()) 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(); }
public FontWrapper(StringRenderer font) { this.font = font; }
static unsafe void Main(string[] args) { BizHawk.Bizware.BizwareGL.IGL igl = new BizHawk.Bizware.BizwareGL.Drivers.OpenTK.IGL_TK(); List<Art> testArts = new List<Art>(); ArtManager am = new ArtManager(igl); foreach (var name in typeof(Program).Assembly.GetManifestResourceNames()) if (name.Contains("flame")) testArts.Add(am.LoadArt(typeof(Program).Assembly.GetManifestResourceStream(name))); var smile = am.LoadArt(typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Bizware.Test.TestImages.smile.png")); am.Close(true); StringRenderer sr; using (var xml = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Bizware.Test.TestImages.courier16px.fnt")) using (var tex = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Bizware.Test.TestImages.courier16px_0.png")) sr = new StringRenderer(igl, xml, tex); GuiRenderer gr = new GuiRenderer(igl); TestForm tf = new TestForm(); RetainedGraphicsControl c = new RetainedGraphicsControl(igl); tf.Controls.Add(c); c.Dock = System.Windows.Forms.DockStyle.Fill; tf.FormClosing += (object sender, System.Windows.Forms.FormClosingEventArgs e) => { tf.Controls.Remove(c); c.Dispose(); c = null; }; tf.Show(); //tf.Paint += (object sender, PaintEventArgs e) => c.Refresh(); c.SetVsync(false); //create a render target RenderTarget rt = igl.CreateRenderTarget(60, 60); rt.Bind(); igl.SetClearColor(Color.Blue); igl.Clear(ClearBufferMask.ColorBufferBit); gr.Begin(60, 60, true); gr.Draw(smile); gr.End(); rt.Unbind(); Texture2d rttex2d = igl.LoadTexture(rt.Texture2d.Resolve()); //test retroarch shader RenderTarget rt2 = igl.CreateRenderTarget(240, 240); rt2.Bind(); igl.SetClearColor(Color.CornflowerBlue); igl.Clear(ClearBufferMask.ColorBufferBit); RetroShader shader; using (var stream = typeof(Program).Assembly.GetManifestResourceStream("BizHawk.Bizware.Test.TestImages.4xSoft.glsl")) shader = new RetroShader(igl, new System.IO.StreamReader(stream).ReadToEnd()); igl.SetBlendState(igl.BlendNone); shader.Run(rttex2d, new Size(60, 60), new Size(240, 240), true); bool running = true; c.MouseClick += (object sender, MouseEventArgs e) => { if(e.Button == MouseButtons.Left) running ^= true; if (e.Button == MouseButtons.Right) c.Retain ^= true; }; DateTime start = DateTime.Now; int wobble = 0; for (; ; ) { if (c == null) break; if (running) { c.Begin(); igl.SetClearColor(Color.Red); igl.Clear(ClearBufferMask.ColorBufferBit); int frame = (int)((DateTime.Now - start).TotalSeconds) % testArts.Count; gr.Begin(c.ClientSize.Width, c.ClientSize.Height); gr.SetBlendState(igl.BlendNormal); gr.SetModulateColor(Color.Green); gr.RectFill(250, 0, 16, 16); gr.SetBlendState(igl.BlendNone); gr.Draw(rttex2d, 0, 20); gr.SetBlendState(igl.BlendNormal); sr.RenderString(gr, 0, 0, "?? fps"); gr.SetModulateColor(Color.FromArgb(255, 255, 255, 255)); gr.SetCornerColor(0, OpenTK.Graphics.Color4.Red); gr.Draw(rt2.Texture2d, 0, 0); gr.SetCornerColor(0, OpenTK.Graphics.Color4.White); gr.SetModulateColorWhite(); gr.Modelview.Translate((float)Math.Sin(wobble / 360.0f) * 50, 0); gr.Modelview.Translate(100, 100); gr.Modelview.Push(); gr.Modelview.Translate(testArts[frame].Width, 0); gr.Modelview.Scale(-1, 1); wobble++; gr.SetModulateColor(Color.Yellow); gr.DrawFlipped(testArts[frame], true, false); gr.SetModulateColorWhite(); gr.Modelview.Pop(); gr.SetBlendState(igl.BlendNormal); gr.Draw(smile); gr.End(); c.SwapBuffers(); c.End(); } System.Windows.Forms.Application.DoEvents(); System.Threading.Thread.Sleep(0); } }