Exemple #1
0
        public override void MakeCurrent(IWindowInfo window)
        {
            if (window == currentWindow && IsCurrent)
            {
                return;
            }

            if (window != null && ((X11WindowInfo)window).Display != Display)
            {
                throw new InvalidOperationException("MakeCurrent() may only be called on windows originating from the same display that spawned this GL context.");
            }

            if (window == null)
            {
                Debug.Write(String.Format("Releasing context {0} from thread {1} (Display: {2})... ",
                                          Handle, System.Threading.Thread.CurrentThread.ManagedThreadId, Display));

                bool result;
                result = Glx.MakeCurrent(Display, IntPtr.Zero, IntPtr.Zero);
                if (result)
                {
                    currentWindow = null;
                }

                Debug.Print("{0}", result ? "done!" : "failed.");
            }
            else
            {
                X11WindowInfo w = (X11WindowInfo)window;
                bool          result;

                Debug.Write(String.Format("Making context {0} current on thread {1} (Display: {2}, Screen: {3}, Window: {4})... ",
                                          Handle, System.Threading.Thread.CurrentThread.ManagedThreadId, Display, w.Screen, w.Handle));

                if (Display == IntPtr.Zero || w.Handle == IntPtr.Zero || Handle == ContextHandle.Zero)
                {
                    throw new InvalidOperationException("Invalid display, window or context.");
                }

                result = Glx.MakeCurrent(Display, w.Handle, Handle);
                if (result)
                {
                    currentWindow = w;
                }

                if (!result)
                {
                    throw new GraphicsContextException("Failed to make context current.");
                }
                else
                {
                    Debug.WriteLine("done!");
                }
            }

            currentWindow = (X11WindowInfo)window;
        }
Exemple #2
0
        protected override void Dispose(bool manuallyCalled)
        {
            if (!IsDisposed)
            {
                if (manuallyCalled)
                {
                    IntPtr display = Display;

                    if (IsCurrent)
                    {
                        Glx.MakeCurrent(display, IntPtr.Zero, IntPtr.Zero);
                    }
                    using (new XLock(display))
                    {
                        Glx.DestroyContext(display, Handle);
                    }
                }
            }
            else
            {
                Debug.Print("[Warning] {0} leaked.", this.GetType().Name);
            }
            IsDisposed = true;
        }