Beispiel #1
0
        public RetroShaderChain(IGL owner, RetroShaderPreset preset, string baseDirectory, bool debug = false)
        {
            Owner       = owner;
            this.Preset = preset;
            Passes      = preset.Passes.ToArray();

            bool ok = true;

            //load up the shaders
            Shaders = new RetroShader[preset.Passes.Count];
            for (int i = 0; i < preset.Passes.Count; i++)
            {
                RetroShaderPreset.ShaderPass pass = preset.Passes[i];

                //acquire content
                string path = Path.Combine(baseDirectory, pass.ShaderPath);
                if (!File.Exists(path))
                {
                    ok = false;
                    break;
                }
                string content = File.ReadAllText(path);

                var shader = new RetroShader(Owner, content, debug);
                Shaders[i] = shader;
                if (!shader.Pipeline.Available)
                {
                    ok = false;
                }
            }

            Available = ok;
        }
Beispiel #2
0
		public RetroShaderChain(IGL owner, RetroShaderPreset preset, string baseDirectory, bool debug = false)
		{
			Owner = owner;
			this.Preset = preset;
			Passes = preset.Passes.ToArray();

			bool ok = true;

			//load up the shaders
			Shaders = new RetroShader[preset.Passes.Count];
			for (int i = 0; i < preset.Passes.Count; i++)
			{
				RetroShaderPreset.ShaderPass pass = preset.Passes[i];

				//acquire content
				string path = Path.Combine(baseDirectory, pass.ShaderPath);
				if (!File.Exists(path))
				{
					ok = false;
					break;
				}
				string content = File.ReadAllText(path);

				var shader = new RetroShader(Owner, content, debug);
				Shaders[i] = shader;
				if (!shader.Pipeline.Available)
					ok = false;
				if (!shader.Available)
					ok = false;
			}

			Available = ok;
		}
Beispiel #3
0
        public RetroShaderChain(IGL owner, RetroShaderPreset preset, string baseDirectory, bool debug = false)
        {
            Owner  = owner;
            Preset = preset;
            Passes = preset.Passes.ToArray();
            Errors = "";

            //load up the shaders
            var shaders = new RetroShader[preset.Passes.Count];

            for (var i = 0; i < preset.Passes.Count; i++)
            {
                //acquire content. we look for it in any reasonable filename so that one preset can bind to multiple shaders
                string content;
                var    path = Path.Combine(baseDirectory, preset.Passes[i].ShaderPath);
                if (!File.Exists(path))
                {
                    if (!Path.HasExtension(path))
                    {
                        path += ".cg";
                    }
                    if (!File.Exists(path))
                    {
                        if (owner.API == "OPENGL")
                        {
                            path = Path.ChangeExtension(path, ".glsl");
                        }
                        else
                        {
                            path = Path.ChangeExtension(path, ".hlsl");
                        }
                    }
                }
                try
                {
                    content = ResolveIncludes(File.ReadAllText(path), Path.GetDirectoryName(path));
                }
                catch (DirectoryNotFoundException e)
                {
                    Errors += $"caught {nameof(DirectoryNotFoundException)}: {e.Message}\n";
                    return;
                }
                catch (FileNotFoundException e)
                {
                    Errors += $"could not read file {e.FileName}\n";
                    return;
                }

                var shader = shaders[i] = new RetroShader(Owner, content, debug);
                if (!shader.Available)
                {
                    Errors += $"===================\r\nPass {i}:\r\n{(shader.Errors??"").Replace("\n","\r\n")}\n";
                    return;
                }
            }

            Shaders   = shaders;
            Available = true;
        }
Beispiel #4
0
        public RetroShaderChain(IGL owner, RetroShaderPreset preset, string baseDirectory, bool debug = false)
        {
            Owner       = owner;
            this.Preset = preset;
            Passes      = preset.Passes.ToArray();
            Errors      = "";

            //load up the shaders
            Shaders = new RetroShader[preset.Passes.Count];
            for (var i = 0; i < preset.Passes.Count; i++)
            {
                //acquire content
                var    path = Path.Combine(baseDirectory, preset.Passes[i].ShaderPath);
                string content;
                try
                {
                    content = ResolveIncludes(File.ReadAllText(path), Path.GetDirectoryName(path));
                }
                catch (DirectoryNotFoundException e)
                {
                    Errors += $"caught {nameof(DirectoryNotFoundException)}: {e.Message}\n";
                    return;
                }
                catch (FileNotFoundException e)
                {
                    Errors += $"could not read file {e.FileName}\n";
                    return;
                }

                var shader = Shaders[i] = new RetroShader(Owner, content, debug);
                if (!shader.Available)
                {
                    Errors += $"===================\r\nPass {i}:\r\n{shader.Errors}\n";
                    return;
                }
            }

            Available = true;
        }
Beispiel #5
0
        public RetroShaderChain(IGL owner, RetroShaderPreset preset, string baseDirectory, bool debug = false)
        {
            Owner       = owner;
            this.Preset = preset;
            Passes      = preset.Passes.ToArray();

            bool ok = true;

            Errors = "";

            //load up the shaders
            Shaders = new RetroShader[preset.Passes.Count];
            for (int i = 0; i < preset.Passes.Count; i++)
            {
                RetroShaderPreset.ShaderPass pass = preset.Passes[i];

                //acquire content
                string path = Path.Combine(baseDirectory, pass.ShaderPath);
                if (!File.Exists(path))
                {
                    ok = false;
                    break;
                }
                string content = ResolveIncludes(File.ReadAllText(path), Path.GetDirectoryName(path));


                var shader = new RetroShader(Owner, content, debug);
                Shaders[i] = shader;
                if (!shader.Available)
                {
                    Errors += string.Format("===================\r\nPass {0}:\r\n{1}", i, shader.Errors);
                    ok      = false;
                }
            }

            Available = ok;
        }
Beispiel #6
0
		public RetroShaderChain(IGL owner, RetroShaderPreset preset, string baseDirectory, bool debug = false)
		{
			Owner = owner;
			this.Preset = preset;
			Passes = preset.Passes.ToArray();

			bool ok = true;
			Errors = "";

			//load up the shaders
			Shaders = new RetroShader[preset.Passes.Count];
			for (int i = 0; i < preset.Passes.Count; i++)
			{
				RetroShaderPreset.ShaderPass pass = preset.Passes[i];

				//acquire content
				string path = Path.Combine(baseDirectory, pass.ShaderPath);
				if (!File.Exists(path))
				{
					ok = false;
					break;
				}
				string content = ResolveIncludes(File.ReadAllText(path), Path.GetDirectoryName(path));


				var shader = new RetroShader(Owner, content, debug);
				Shaders[i] = shader;
				if (!shader.Available)
				{
					Errors += string.Format("===================\r\nPass {0}:\r\n{1}",i,shader.Errors);
					ok = false;
				}
			}

			Available = ok;
		}
Beispiel #7
0
        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.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);
            }
        }
Beispiel #8
0
		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);
			}
		}