Esempio n. 1
0
        protected virtual void Render(Glorg2.Graphics.GraphicsDevice dev, float frame_time, float total_time)
        {
            if (scene.Background.w > 0)
            {
                dev.Clear(Glorg2.Graphics.ClearFlags.Color | Glorg2.Graphics.ClearFlags.Depth, scene.Background);
            }

            if (scene.Camera != null)
            {
                dev.ProjectionMatrix = scene.Camera.GetProjectionMatrix();
            }

            lock (scene.renderables)
            {
                foreach (var n in scene.renderables)
                {
                    (n as Scene.Node).InternalRender(frame_time, dev);
                }
            }
            dev.Present();
        }
Esempio n. 2
0
        private void RenderLoop()
        {
            long old_time = 0;

            // Wait for control to recieve a handle
            target.HandleCreated += (sender, e) => ready = true;

            while (!ready)
            {
                IntPtr h = (IntPtr)target.Invoke(new Func <IntPtr>(() => target.Handle));
                if (h != IntPtr.Zero)
                {
                    ready = true;
                }
                System.Threading.Thread.Sleep(0);
            }
            IntPtr handle = (IntPtr)target.Invoke(new Func <IntPtr>(() => target.Handle));

            dev = new Glorg2.Graphics.GraphicsDevice(handle);

            ResourceThread      = new Thread(new ThreadStart(ResourceLoop));
            ResourceThread.Name = "Resource thread";
            ResourceThread.Start();

            threads_ready |= ThreadReady.RenderThread;
            while (threads_ready != ThreadReady.All)
            {
                Thread.Sleep(0);
            }


            InitializeGraphics();
            old_time = System.Diagnostics.Stopwatch.GetTimestamp();

            dev.State.MultiSample = true;
            while (running)
            {
                long  new_time = System.Diagnostics.Stopwatch.GetTimestamp();
                float time     = (new_time - old_time) / ((float)System.Diagnostics.Stopwatch.Frequency);
                while (graphic_invoke.Count > 0)
                {
                    Action act = null;
                    lock (graphic_invoke)
                    {
                        act = graphic_invoke.Dequeue();
                    }
                    if (act != null)
                    {
                        act();
                    }
                }

                if (sort_render_list)
                {
                }
                var res = scene.Resources.Janitorial();
                if (res.Count > 0)
                {
                    foreach (var item in res)
                    {
                        item.Dispose();
                    }
                    lock (scene.Resources.resources)
                    {
                        scene.Resources.Remove(res);
                    }
                }
                // Wait until simulation thread has finished with one frame
                // or else it is not necessary to render the next frame (since nothing has happened)
                while (!provoke_render && running)
                {
                    System.Threading.Thread.Sleep(0);
                }

                Render(dev, frame_time, total_time);
                //System.Threading.Thread.Sleep(0);
                fps            = 1 / time;
                provoke_render = false;
                old_time       = new_time;
            }

            scene.Dispose();
            CleanupResources();
            CleanupResources();             // Do this again to ensure that resources which are referenced by other resources are freed
            GraphicsClosing();
            scene.GraphicsDispose();
            dev.Dispose();
        }
Esempio n. 3
0
        private void RenderLoop()
        {
            long old_time = 0;
            // Wait for control to recieve a handle
            target.HandleCreated += (sender, e) => ready = true;

            while (!ready)
            {
                IntPtr h = (IntPtr)target.Invoke(new Func<IntPtr>(() => target.Handle));
                if (h != IntPtr.Zero)
                    ready = true;
                System.Threading.Thread.Sleep(0);
            }
            IntPtr handle = (IntPtr)target.Invoke(new Func<IntPtr>(() => target.Handle));
            dev = new Glorg2.Graphics.GraphicsDevice(handle);

            ResourceThread = new Thread(new ThreadStart(ResourceLoop));
            ResourceThread.Name = "Resource thread";
            ResourceThread.Start();

            threads_ready |= ThreadReady.RenderThread;
            while (threads_ready != ThreadReady.All)
                Thread.Sleep(0);

            InitializeGraphics();
            old_time = System.Diagnostics.Stopwatch.GetTimestamp();

            dev.State.MultiSample = true;
            while (running)
            {
                long new_time = System.Diagnostics.Stopwatch.GetTimestamp();
                float time =  (new_time - old_time) / ((float)System.Diagnostics.Stopwatch.Frequency);
                    while (graphic_invoke.Count > 0)
                    {
                        Action act = null;
                        lock (graphic_invoke)
                        {
                            act = graphic_invoke.Dequeue();
                        }
                        if (act != null)
                            act();
                    }

                if (sort_render_list)
                {

                }
                var res = scene.Resources.Janitorial();
                if (res.Count > 0)
                {
                    foreach (var item in res)
                    {
                        item.Dispose();
                    }
                    lock (scene.Resources.resources)
                    {
                        scene.Resources.Remove(res);
                    }
                }
                // Wait until simulation thread has finished with one frame
                // or else it is not necessary to render the next frame (since nothing has happened)
                while (!provoke_render && running)
                {
                    System.Threading.Thread.Sleep(0);
                }

                Render(dev, frame_time, total_time);
                //System.Threading.Thread.Sleep(0);
                fps = 1 / time;
                provoke_render = false;
                old_time = new_time;
            }

            scene.Dispose();
            CleanupResources();
            CleanupResources(); // Do this again to ensure that resources which are referenced by other resources are freed
            GraphicsClosing();
            scene.GraphicsDispose();
            dev.Dispose();
        }