ProcessEvents() публичный Метод

Processes operating system events until the NativeWindow becomes idle.
public ProcessEvents ( ) : void
Результат void
Пример #1
0
        public void Run()
        {
            GraphicsMode gmode = new GraphicsMode(GraphicsMode.Default.ColorFormat, GraphicsMode.Default.Depth, GraphicsMode.Default.Stencil, 0);

            DisplayDevice dd = DisplayDevice.Default;

            NativeWindow nw = new NativeWindow(Width, Height, "Test", GameWindowFlags.Default, gmode, dd);

            GraphicsContext glContext = new GraphicsContext(gmode, nw.WindowInfo, 3, 0, GraphicsContextFlags.Default);
            glContext.LoadAll();

            glContext.MakeCurrent(nw.WindowInfo);

            if (Load())
            {
                nw.Visible = true;
                while (nw.Visible)
                {
                    Frame();

                    glContext.SwapBuffers();

                    Thread.Sleep(1000 / 60); //"60" fps (not really...)

                    nw.ProcessEvents();
                }

                nw.Visible = false;
            }

            Unload();
        }
Пример #2
0
        // Creates a context and starts processing the GL class.
        // The processing takes place in the background to avoid hanging the GUI.
        void StartAsync(object sender, EventArgs e)
        {
            Application.Idle -= StartAsync;

            // Create a context to load all GL entry points.
            // The loading part is handled automatically by OpenTK.
            using (INativeWindow window = new OpenTK.NativeWindow())
                using (IGraphicsContext context = new GraphicsContext(GraphicsMode.Default, window.WindowInfo, 3, 0, GraphicsContextFlags.Default))
                {
                    window.ProcessEvents();
                    context.MakeCurrent(window.WindowInfo);
                    (context as IGraphicsContextInternal).LoadAll();

                    TextBoxVendor.Text   = GL.GetString(StringName.Vendor);
                    TextBoxRenderer.Text = GL.GetString(StringName.Renderer);
                    TextBoxVersion.Text  = GL.GetString(StringName.Version);
                }

            backgroundWorker1.RunWorkerAsync();
            TextBoxSupport.Text = "processing... (please be patient)";
        }
Пример #3
0
        public void RunWindowLoop()
        {
            _nativeWindow.Visible = true;
            while (_nativeWindow.Exists)
            {
                _previousFrameStartTime = DateTime.UtcNow;

                RenderFrame();

                _nativeWindow.ProcessEvents();

                DateTime afterFrameTime = DateTime.UtcNow;
                double   elapsed        = (afterFrameTime - _previousFrameStartTime).TotalSeconds;
                double   sleepTime      = s_desiredFrameLength - elapsed;
                if (sleepTime > 0.0)
                {
                    DateTime finishTime = afterFrameTime + TimeSpan.FromSeconds(sleepTime);
                    while (DateTime.UtcNow < finishTime)
                    {
                        Thread.Sleep(0);
                    }
                }
            }
        }
        public void Run()
        {
            Window = new NativeWindow( 640, 400, Program.AppName, 0,
                                      GraphicsMode.Default, DisplayDevice.Default );
            Window.Visible = true;
            Drawer = new GdiPlusDrawer2D( null );
            Init();
            TryLoadTexturePack();
            platformDrawer.Init( Window.WindowInfo );

            string audioPath = Path.Combine( Program.AppDirectory, "audio" );
            BinUnpacker.Unpack( audioPath, "dig" );
            BinUnpacker.Unpack( audioPath, "step" );

            fetcher = new ResourceFetcher();
            fetcher.CheckResourceExistence();
            checkTask = new UpdateCheckTask();
            checkTask.CheckForUpdatesAsync();
            if( !fetcher.AllResourcesExist )
                SetScreen( new ResourcesScreen( this ) );
            else
                SetScreen( new MainScreen( this ) );

            while( true ) {
                Window.ProcessEvents();
                if( !Window.Exists ) break;
                if( ShouldExit ) {
                    if( Screen != null )
                        Screen.Dispose();
                    break;
                }

                Screen.Tick();
                if( Dirty || Screen.Dirty )
                    Display();
                Thread.Sleep( 1 );
            }

            if( Options.Load() ) {
                LauncherSkin.SaveToOptions();
                Options.Save();
            }

            if( ShouldUpdate )
                Updater.Patcher.LaunchUpdateScript();
            if( Window.Exists )
                Window.Close();
        }
Пример #5
0
        public void RunWindowLoop()
        {
            var io = ImGui.GetIO();

            _nativeWindow.Visible = true;
            while (_nativeWindow.Exists)
            {
                _previousFrameStartTime = DateTime.UtcNow;

                RenderFrame();

                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.Enter)))
                {
                    editor.CharKey('\n');
                }
                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.Delete)))
                {
                    editor.Delete();
                }
                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.Tab)))
                {
                    editor.CharKey('\t');
                }
                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.Backspace)))
                {
                    editor.Backspace();
                }
                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.UpArrow)))
                {
                    editor.Move(MoveDirective.Up, io.ShiftPressed);
                }
                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.DownArrow)))
                {
                    editor.Move(MoveDirective.Down, io.ShiftPressed);
                }
                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.LeftArrow)))
                {
                    editor.Move(io.CtrlPressed ? MoveDirective.StartOfWord : MoveDirective.Left, io.ShiftPressed);
                }
                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.RightArrow)))
                {
                    editor.Move(io.CtrlPressed ? MoveDirective.EndOfWord : MoveDirective.Right, io.ShiftPressed);
                }

                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.Home)))
                {
                    editor.Move(io.CtrlPressed ? MoveDirective.StartOfDocument : MoveDirective.Home, io.ShiftPressed);
                }

                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.End)))
                {
                    editor.Move(io.CtrlPressed ? MoveDirective.EndOfDocument : MoveDirective.End, io.ShiftPressed);
                }

                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.A)) && io.CtrlPressed)
                {
                    editor.SelectAll();
                }
                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.C)) && io.CtrlPressed)
                {
                    editor.Copy();
                }
                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.X)) && io.CtrlPressed)
                {
                    editor.Cut();
                }
                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.V)) && io.CtrlPressed)
                {
                    editor.Paste();
                }
                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.PageUp)))
                {
                    editor.Move(MoveDirective.PageUp, io.ShiftPressed, Renderer.FirstVisibleLine, Renderer.LastVisibleLine);
                }
                if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(GuiKey.PageDown)))
                {
                    editor.Move(MoveDirective.PageDown, io.ShiftPressed, Renderer.FirstVisibleLine, Renderer.LastVisibleLine);
                }

                _nativeWindow.ProcessEvents();

                DateTime afterFrameTime = DateTime.UtcNow;
                double   elapsed        = (afterFrameTime - _previousFrameStartTime).TotalSeconds;
                double   sleepTime      = s_desiredFrameLength - elapsed;
                if (sleepTime > 0.0)
                {
                    DateTime finishTime = afterFrameTime + TimeSpan.FromSeconds(sleepTime);
                    while (DateTime.UtcNow < finishTime)
                    {
                        Thread.Sleep(0);
                    }
                }
            }
        }
Пример #6
0
        public void Run()
        {
            Window = new NativeWindow( 480, 480, Program.AppName, 0,
                                      GraphicsMode.Default, DisplayDevice.Default );
            Window.Visible = true;
            Drawer = new GdiPlusDrawer2D( null );
            Init();
            platformDrawer.Init( Window.WindowInfo );

            if( !ResourceFetcher.CheckAllResourcesExist() ) {
                SetScreen( new ResourcesScreen( this ) );
            } else {
                SetScreen( new MainScreen( this ) );
            }

            while( true ) {
                Window.ProcessEvents();
                if( !Window.Exists ) break;

                screen.Tick();
                if( Dirty || screen.Dirty )
                    Display();
                Thread.Sleep( 1 );
            }
        }
Пример #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <see cref="http://www.opentk.com/doc/graphics/graphicscontext"/>
        public override void InitSynchronizedOnce()
        {
            if (!AlreadyInitialized)
            {
                AlreadyInitialized = true;
                AutoResetEvent CompletedEvent = new AutoResetEvent(false);
                var CThread = new Thread(() =>
                {
                    Thread.CurrentThread.CurrentCulture = new CultureInfo(PspConfig.CultureName);

                    var UsedGraphicsMode = new GraphicsMode(
                        color: new OpenTK.Graphics.ColorFormat(8, 8, 8, 8),
                        depth: 16,
                        stencil: 8,
                        samples: 0,
                        accum: new OpenTK.Graphics.ColorFormat(16, 16, 16, 16),
                        //accum: new OpenTK.Graphics.ColorFormat(0, 0, 0, 0),
                        buffers: 2,
                        stereo: false
                    );

                    var UsedGameWindowFlags = GameWindowFlags.Default;

                    //Console.Error.WriteLine(UsedGraphicsMode);
                    //Console.ReadKey();
            #if USE_GL_CONTROL
                    GLControl = new GLControl(UsedGraphicsMode, 3, 0, GraphicsContextFlags.Default);
            #else
                    NativeWindow = new NativeWindow(512, 272, "PspGraphicEngine", UsedGameWindowFlags, UsedGraphicsMode, DisplayDevice.GetDisplay(DisplayIndex.Default));
            #endif

            #if SHOW_WINDOW
                    NativeWindow.Visible = true;
            #endif
                    //Utilities.CreateWindowsWindowInfo(handle);

                    GraphicsContext = new GraphicsContext(UsedGraphicsMode, WindowInfo);
                    GraphicsContext.MakeCurrent(WindowInfo);
                    {
                        GraphicsContext.LoadAll();
                        Initialize();
                    }
                    GraphicsContext.SwapInterval = 0;

            #if true
                    //Console.WriteLine("## {0}", UsedGraphicsMode);
                    Console.WriteLine("## UsedGraphicsMode: {0}", UsedGraphicsMode);
                    Console.WriteLine("## GraphicsContext.GraphicsMode: {0}", GraphicsContext.GraphicsMode);

                    Console.WriteLine("## OpenGL Context Version: {0}.{1}", GlGetInteger(GetPName.MajorVersion), GlGetInteger(GetPName.MinorVersion));

                    Console.WriteLine("## Depth Bits: {0}", GlGetInteger(GetPName.DepthBits));
                    Console.WriteLine("## Stencil Bits: {0}", GlGetInteger(GetPName.StencilBits));
                    Console.WriteLine("## Accum Bits: {0},{1},{2},{3}", GlGetInteger(GetPName.AccumRedBits), GlGetInteger(GetPName.AccumGreenBits), GlGetInteger(GetPName.AccumBlueBits), GlGetInteger(GetPName.AccumAlphaBits));

                    if (GlGetInteger(GetPName.StencilBits) <= 0)
                    {
                        ConsoleUtils.SaveRestoreConsoleState(() =>
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Error.WriteLine("No stencil bits available!");
                        });
                    }

                    /*
                    GL.Enable(EnableCap.StencilTest);
                    GL.StencilMask(0xFF);
                    GL.ClearColor(new Color4(Color.FromArgb(0x11, 0x22, 0x33, 0x44)));
                    GL.ClearStencil(0x7F);
                    GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit);

                    var TestData = new uint[16 * 16];
                    TestData[0] = 0x12345678;
                    GL.ReadPixels(0, 0, 16, 16, PixelFormat.Rgba, PixelType.UnsignedInt8888Reversed, TestData);
                    Console.WriteLine(GL.GetError());
                    for (int n = 0; n < TestData.Length; n++) Console.Write("{0:X}", TestData[n]);
                    */
            #endif

                    GraphicsContext.MakeCurrent(null);
                    CompletedEvent.Set();
                    while (Running)
                    {
            #if !USE_GL_CONTROL
                        NativeWindow.ProcessEvents();
            #endif
                        Thread.Sleep(1);
                    }
                    StopEvent.Set();
                });
                CThread.Name = "GpuImplEventHandling";
                CThread.IsBackground = true;
                CThread.Start();
                CompletedEvent.WaitOne();
            }
        }
Пример #8
0
        public WaitHandle GenerateOccluder(Action <VoxelizationProgress> progress, Action done)
        {
            ManualResetEvent waitHandle = new ManualResetEvent(false);

            if (Context == null || Context.OriginalMesh == null)
            {
                Logger.DisplayError("Please Open a mesh first.");
                waitHandle.Set();
                return(waitHandle);
            }

            Input.Octree       = Context.Octree;
            Input.OriginalMesh = Context.OriginalMesh;

            VoxelizationInput  input  = Input.Clone();
            VoxelizationOutput output = null;

            IOccluderGenerator occluder;

            switch (input.Type)
            {
            case OcclusionType.Octree:
                occluder = new OccluderOctree();
                break;

            case OcclusionType.BoxExpansion:
                occluder = new OccluderBoxExpansion();
                break;

            //case OcclusionType.SimulatedAnnealing:
            //    occluder = new OccluderBoxExpansion();
            //    break;
            case OcclusionType.BruteForce:
                occluder = new OccluderBoxExpansion();
                break;

            default:
                throw new Exception("Unknown occluder type.");
            }

            Thread thread = new Thread(() =>
            {
                INativeWindow window = new OpenTK.NativeWindow();
                IGraphicsContext gl  = new GraphicsContext(new GraphicsMode(32, 24, 8), window.WindowInfo);
                gl.MakeCurrent(window.WindowInfo);

                while (window.Exists)
                {
                    window.ProcessEvents();

                    try
                    {
                        RobustVoxelizer voxelizer = new RobustVoxelizer(512, 512);
                        output = voxelizer.Voxelize(input, progress);
                        voxelizer.Dispose();

                        output = occluder.Generate(input, progress);
                    }
                    catch (System.Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }

                    window.Close();
                    break;
                }

                gl.MakeCurrent(null);

                if (Context.OccluderMesh != null)
                {
                    Context.OccluderMesh.Dispose();
                }

                Context.Octree             = output.Octree;
                Context.OccluderMesh       = output.OccluderMesh;
                Context.VoxelizationOutput = output;

                waitHandle.Set();

                done();
            });

            thread.IsBackground = true;
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();

            return(waitHandle);
        }