void StartRenderLoop() { // If the render loop is already running then do not start another thread. if (mRenderLoopWorker != null && mRenderLoopWorker.Status == AsyncStatus.Started) { return; } //var throttler = new Helpers.EventThrottler<TextChangedEventArgs>(Constants.TypingTimeout, handler => SearchField.TextChanged += new TextChangedEventHandler(handler)); //throttler.Invoked += (s, args) => //{ // // s is SearchField // // args is TextChangedEventArgs //}; // Create a task for rendering that will be run on a background thread. var workItemHandler = new Windows.System.Threading.WorkItemHandler(action => { lock (mRenderSurfaceCriticalSection) { mOpenGLES.MakeCurrent(mRenderSurface); //var renderer = new RendererBase(); var renderer = RendererInit(); while (action.Status == AsyncStatus.Started) { int panelWidth = 0; int panelHeight = 0; mOpenGLES.GetSurfaceDimensions(mRenderSurface, ref panelWidth, ref panelHeight); // Logic to update the scene could go here renderer.UpdateWindowSize(panelWidth, panelHeight); renderer.Draw(); // The call to eglSwapBuffers might not be successful (i.e. due to Device Lost) // If the call fails, then we must reinitialize EGL and the GL resources. if (mOpenGLES.SwapBuffers(mRenderSurface) != EGL.TRUE) { // XAML objects like the SwapChainPanel must only be manipulated on the UI thread. #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed swapChainPanel.Dispatcher.RunAsync(CoreDispatcherPriority.High, new DispatchedHandler(() => { RecoverFromLostDevice(); })); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return; } } } }); // Run task on a dedicated high priority background thread. mRenderLoopWorker = Windows.System.Threading.ThreadPool.RunAsync(workItemHandler, Windows.System.Threading.WorkItemPriority.High, Windows.System.Threading.WorkItemOptions.TimeSliced); }
void StartRenderLoop() { // If the render loop is already running then do not start another thread. if (mRenderLoopWorker != null && mRenderLoopWorker.Status == Windows.Foundation.AsyncStatus.Started) { return; } // Create a task for rendering that will be run on a background thread. var workItemHandler = new Windows.System.Threading.WorkItemHandler(action => { lock (mRenderSurfaceCriticalSection) { mOpenGLES.MakeCurrent(mRenderSurface); SimpleRenderer renderer = new SimpleRenderer(); while (action.Status == Windows.Foundation.AsyncStatus.Started) { int panelWidth = 0; int panelHeight = 0; mOpenGLES.GetSurfaceDimensions(mRenderSurface, ref panelWidth, ref panelHeight); // Logic to update the scene could go here renderer.UpdateWindowSize(panelWidth, panelHeight); renderer.Draw(); // The call to eglSwapBuffers might not be successful (i.e. due to Device Lost) // If the call fails, then we must reinitialize EGL and the GL resources. if (mOpenGLES.SwapBuffers(mRenderSurface) != EGL.TRUE) { // XAML objects like the SwapChainPanel must only be manipulated on the UI thread. swapChainPanel.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, new Windows.UI.Core.DispatchedHandler(() => { RecoverFromLostDevice(); })); return; } } } }); // Run task on a dedicated high priority background thread. mRenderLoopWorker = Windows.System.Threading.ThreadPool.RunAsync(workItemHandler, Windows.System.Threading.WorkItemPriority.High, Windows.System.Threading.WorkItemOptions.TimeSliced); }