/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // how does this work on android? // https://www.shadertoy.com/view/MdfSRj# #region += Launched chrome.app.window dynamic self = Native.self; dynamic self_chrome = self.chrome; object self_chrome_socket = self_chrome.socket; if (self_chrome_socket != null) { if (!(Native.window.opener == null && Native.window.parent == Native.window.self)) { Console.WriteLine("chrome.app.window.create, is that you?"); // pass thru } else { // should jsc send a copresence udp message? chrome.runtime.UpdateAvailable += delegate { new chrome.Notification(title: "UpdateAvailable"); }; Console.WriteLine("awaiting Launch"); //new chrome.Notification(title: "awaiting Launch"); chrome.app.runtime.Launched += async delegate { // 0:12094ms chrome.app.window.create {{ href = chrome-extension://aemlnmcokphbneegoefdckonejmknohh/_generated_background_page.html }} Console.WriteLine("chrome.app.window.create " + new { Native.document.location.href }); //new chrome.Notification(title: "ChromeUDPSendAsync"); var xappwindow = await chrome.app.window.create( Native.document.location.pathname, options: null ); //xappwindow.setAlwaysOnTop xappwindow.show(); await xappwindow.contentWindow.async.onload; Console.WriteLine("chrome.app.window loaded!"); }; return; } } #endregion Console.WriteLine("getting ready...?"); new Shaders.ProgramFragmentShader().With( async vs => { Console.WriteLine("getting ready..."); Native.body.style.margin = "0px"; //Native.document.documentElement.style.overflow = IStyle.OverflowEnum.auto; var mAudioContext = new AudioContext(); var gl = new WebGLRenderingContext(alpha: true); var c = gl.canvas.AttachToDocument(); c.style.SetSize(460, 237); c.width = 460; c.height = 237; var mEffect = new ChromeShaderToyColumns.Library.ShaderToy.Effect( mAudioContext, gl, callback: delegate { new IHTMLPre { "at callback" }.AttachToDocument(); }, obj: null, forceMuted: false, forcePaused: false ); #region CaptureMouse var mMouseOriX = 0; var mMouseOriY = 0; var mMousePosX = 0; var mMousePosY = 0; c.onmousedown += async ev => { mMouseOriX = ev.CursorX; mMouseOriY = ev.CursorY; mMousePosX = mMouseOriX; mMousePosY = mMouseOriY; // why aint it canvas? //ev.Element //ev.CaptureMouse(); // using ? ev.Element.requestPointerLock(); await ev.Element.async.onmouseup; Native.document.exitPointerLock(); mMouseOriX = -Math.Abs(mMouseOriX); mMouseOriY = -Math.Abs(mMouseOriY); }; c.onmousemove += ev => { if (ev.MouseButton == IEvent.MouseButtonEnum.Left) { mMousePosX += ev.movementX; mMousePosY += ev.movementY; } }; #endregion mEffect.mPasses[0].mInputs[0] = new ChromeShaderToyColumns.Library.ShaderToy.samplerCube { }; mEffect.mPasses[0].MakeHeader_Image(); mEffect.mPasses[0].NewShader_Image(vs); #region onresize new { }.With( async delegate { do { c.width = Native.window.Width; //c.height = Native.window.Height / 2; c.height = Native.window.Height; c.style.SetSize(c.width, c.height); } while (await Native.window.async.onresize); } ); #endregion Console.WriteLine("can you see any?"); var sw = Stopwatch.StartNew(); do { mEffect.mPasses[0].Paint_Image( sw.ElapsedMilliseconds / 1000.0f, mMouseOriX, mMouseOriY, mMousePosX, mMousePosY ); // what does it do? gl.flush(); } while (await Native.window.async.onframe); } ); }
public static async void AttachToDocument(FragmentShader vs) { Native.body.style.margin = "0px"; Native.body.style.backgroundColor = "blue"; var mAudioContext = new AudioContext(); var gl = new WebGLRenderingContext(alpha: true); if (gl == null) { new IHTMLPre { // https://code.google.com/p/chromium/issues/detail?id=294207 "Rats! WebGL hit a snag. \n WebGL: Unavailable.\n GPU process was unable to boot. \n restart chrome.", // chrome sends us to about:blank? //new IHTMLAnchor { // target = "_blank", // href = "about:gpu", innerText = "about:gpu", // // http://tirania.org/blog/archive/2009/Jul-27-1.html // //onclick += de //} //.With(a => { a.onclick += e => { e.preventDefault(); Native.window.open("about:gpu"); }; } ) }.AttachToDocument(); return; } Native.body.Clear(); Native.body.style.overflow = IStyle.OverflowEnum.hidden; var c = gl.canvas.AttachToDocument(); #region oncontextlost gl.oncontextlost += e => { //[12144:10496:0311 / 120850:ERROR: gpu_watchdog_thread.cc(314)] : The GPU process hung. Terminating after 10000 ms. // GpuProcessHostUIShim: The GPU process crashed! gl.canvas.Orphanize(); new IHTMLPre { // https://code.google.com/p/chromium/issues/detail?id=294207 @"Rats! WebGL hit a snag. oncontextlost. The GPU process hung. Terminating. check chrome://gpu for log messages. do we have a stack trace? " + new { e.statusMessage } , // chrome sends us to about:blank? //new IHTMLAnchor { // target = "_blank", // href = "about:gpu", innerText = "about:gpu", // // http://tirania.org/blog/archive/2009/Jul-27-1.html // //onclick += de //} //.With(a => { a.onclick += e => { e.preventDefault(); Native.window.open("about:gpu"); }; } ) }.AttachToDocument(); }; #endregion #region onresize new { }.With( async delegate { do { c.width = Native.window.Width; c.height = Native.window.Height; c.style.SetSize(c.width, c.height); } while (await Native.window.async.onresize); } ); #endregion #region CaptureMouse var mMouseOriX = 0; var mMouseOriY = 0; var mMousePosX = 0; var mMousePosY = 0; c.onmousedown += ev => { mMouseOriX = ev.CursorX; mMouseOriY = c.height - ev.CursorY; mMousePosX = mMouseOriX; mMousePosY = mMouseOriY; ev.CaptureMouse(); }; c.onmousemove += ev => { if (ev.MouseButton == IEvent.MouseButtonEnum.Left) { mMousePosX = ev.CursorX; // X:\jsc.svn\examples\javascript\chrome\apps\WebGL\synergy\InputMouseByIq\InputMouseByIq\Shaders\Program.frag //mMousePosY = ev.CursorY; mMousePosY = c.height - ev.CursorY; } }; c.onmouseup += ev => { mMouseOriX = -Math.Abs(mMouseOriX); mMouseOriY = -Math.Abs(mMouseOriY); }; #endregion var mEffect = new ChromeShaderToyColumns.Library.ShaderToy.Effect( mAudioContext, gl, callback: delegate { new IHTMLPre { "at callback" }.AttachToDocument(); }, obj: null, forceMuted: false, forcePaused: false ); mEffect.mPasses[0].MakeHeader_Image(); mEffect.mPasses[0].NewShader_Image(vs); var sw = Stopwatch.StartNew(); do { mEffect.mPasses[0].Paint_Image( sw.ElapsedMilliseconds / 1000.0f, mMouseOriX, mMouseOriY, mMousePosX, mMousePosY ); // what does it do? gl.flush(); } while (await Native.window.async.onframe); }
/// <summary> /// This is a javascript application. /// </summary> /// <param name="page">HTML document rendered by the web server which can now be enhanced.</param> public Application(IApp page) { // https://www.shadertoy.com/view/Xds3zN // X:\jsc.svn\examples\javascript\chrome\apps\WebGL\ChromeShaderToyColumns\ChromeShaderToyColumns\Application.cs // X:\jsc.svn\examples\javascript\chrome\apps\WebGL\ChromeShaderToySeascapeByTDM\ChromeShaderToySeascapeByTDM\Application.cs // https://www.shadertoy.com/view/Ms2SD1 #region += Launched chrome.app.window dynamic self = Native.self; dynamic self_chrome = self.chrome; object self_chrome_socket = self_chrome.socket; if (self_chrome_socket != null) { if (!(Native.window.opener == null && Native.window.parent == Native.window.self)) { Console.WriteLine("chrome.app.window.create, is that you?"); // pass thru } else { // should jsc send a copresence udp message? chrome.runtime.UpdateAvailable += delegate { new chrome.Notification(title: "UpdateAvailable"); }; chrome.app.runtime.Launched += async delegate { // 0:12094ms chrome.app.window.create {{ href = chrome-extension://aemlnmcokphbneegoefdckonejmknohh/_generated_background_page.html }} Console.WriteLine("chrome.app.window.create " + new { Native.document.location.href }); new chrome.Notification(title: "ChromeUDPSendAsync"); var xappwindow = await chrome.app.window.create( Native.document.location.pathname, options: null ); //xappwindow.setAlwaysOnTop xappwindow.show(); await xappwindow.contentWindow.async.onload; Console.WriteLine("chrome.app.window loaded!"); }; return; } } #endregion new { }.With( async delegate { Native.body.style.margin = "0px"; var vs = new Shaders.ProgramFragmentShader(); var mAudioContext = new AudioContext(); var gl = new WebGLRenderingContext(alpha: true); var c = gl.canvas.AttachToDocument(); #region onresize new { }.With( async delegate { do { c.width = Native.window.Width; c.height = Native.window.Height; c.style.SetSize(c.width, c.height); } while (await Native.window.async.onresize); } ); #endregion #region CaptureMouse var mMouseOriX = 0; var mMouseOriY = 0; var mMousePosX = 0; var mMousePosY = 0; c.onmousedown += ev => { mMouseOriX = ev.CursorX; mMouseOriY = ev.CursorY; mMousePosX = mMouseOriX; mMousePosY = mMouseOriY; ev.CaptureMouse(); }; c.onmousemove += ev => { if (ev.MouseButton == IEvent.MouseButtonEnum.Left) { mMousePosX = ev.CursorX; mMousePosY = c.height - ev.CursorY; } }; c.onmouseup += ev => { mMouseOriX = -Math.Abs(mMouseOriX); mMouseOriY = -Math.Abs(mMouseOriY); }; #endregion var mEffect = new ChromeShaderToyColumns.Library.ShaderToy.Effect( mAudioContext, gl, callback: delegate { new IHTMLPre { "at callback" }.AttachToDocument(); }, obj: null, forceMuted: false, forcePaused: false ); mEffect.mPasses[0].MakeHeader_Image(); mEffect.mPasses[0].NewShader_Image(vs); var sw = Stopwatch.StartNew(); do { mEffect.mPasses[0].Paint_Image( sw.ElapsedMilliseconds / 1000.0f, mMouseOriX, mMouseOriY, mMousePosX, mMousePosY ); // what does it do? gl.flush(); } while (await Native.window.async.onframe); } ); }