Inheritance: IWindowInfo, IDisposable
        public X11GLContext(GraphicsMode mode, IWindowInfo window)
        {
            if (mode == null)
                throw new ArgumentNullException("mode");
            if (window == null)
                throw new ArgumentNullException("window");

            Debug.Print( "Creating X11GLContext context: " );
            currentWindow = (X11WindowInfo)window;
            Display = API.DefaultDisplay;
            XVisualInfo info = currentWindow.VisualInfo;
            Mode = GetGraphicsMode( info );
            // Cannot pass a Property by reference.
            ContextHandle = Glx.glXCreateContext(Display, ref info, IntPtr.Zero, true);

            if (ContextHandle == IntPtr.Zero) {
                Debug.Print("failed. Trying indirect... ");
                ContextHandle = Glx.glXCreateContext(Display, ref info, IntPtr.Zero, false);
            }

            if (ContextHandle != IntPtr.Zero)
                Debug.Print("Context created (id: {0}).", ContextHandle);
            else
                throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");

            if (!Glx.glXIsDirect(Display, ContextHandle))
                Debug.Print("Warning: Context is not direct.");
        }
示例#2
0
 public X11WindowInfo(IntPtr handle, X11WindowInfo parent)
 {
     this.handle = handle;
       this.parent = parent;
       if (parent == null)
     return;
       this.rootWindow = parent.rootWindow;
       this.display = parent.display;
       this.screen = parent.screen;
       this.visualInfo = parent.visualInfo;
 }
示例#3
0
 public X11GLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shared, bool direct,
     int major, int minor, GraphicsContextFlags flags)
     : base(DesktopBackend.OpenGL)
 {
     if (handle == ContextHandle.Zero)
         throw new ArgumentException("handle");
     if (window == null)
         throw new ArgumentNullException("window");
     Handle = handle;
     currentWindow = (X11WindowInfo)window;
     Display = currentWindow.Display;
 }
示例#4
0
文件: Functions.cs 项目: Zeludon/FEZ
 public static void SendNetClientMessage(X11WindowInfo window, IntPtr message_type, IntPtr l0, IntPtr l1, IntPtr l2)
 {
     Functions.XSendEvent(window.Display, window.WindowHandle, false, new IntPtr(0), ref new XEvent()
       {
     ClientMessageEvent = {
       type = XEventName.ClientMessage,
       send_event = true,
       window = window.WindowHandle,
       message_type = message_type,
       format = 32,
       ptr1 = l0,
       ptr2 = l1,
       ptr3 = l2
     }
       });
 }
示例#5
0
        public X11GLContext(GraphicsMode mode, IWindowInfo window)
        {
            if (mode == null)
            {
                throw new ArgumentNullException("mode");
            }
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            Debug.Print("Creating X11GLContext context: ");
            currentWindow = (X11WindowInfo)window;
            Display       = API.DefaultDisplay;
            XVisualInfo info = currentWindow.VisualInfo;

            Mode = GetGraphicsMode(info);
            // Cannot pass a Property by reference.
            ContextHandle = Glx.glXCreateContext(Display, ref info, IntPtr.Zero, true);

            if (ContextHandle == IntPtr.Zero)
            {
                Debug.Print("failed. Trying indirect... ");
                ContextHandle = Glx.glXCreateContext(Display, ref info, IntPtr.Zero, false);
            }

            if (ContextHandle != IntPtr.Zero)
            {
                Debug.Print("Context created (id: {0}).", ContextHandle);
            }
            else
            {
                throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");
            }

            if (!Glx.glXIsDirect(Display, ContextHandle))
            {
                Debug.Print("Warning: Context is not direct.");
            }
        }
示例#6
0
        XVisualInfo SelectVisual(GraphicsMode mode, X11WindowInfo currentWindow)
        {
            XVisualInfo info = new XVisualInfo();

            info.VisualID = (IntPtr)mode.Index;
            info.Screen   = currentWindow.Screen;
            int items;

            lock (API.Lock)
            {
                IntPtr vs = Functions.XGetVisualInfo(currentWindow.Display, XVisualInfoMask.ID | XVisualInfoMask.Screen, ref info, out items);
                if (items == 0)
                {
                    throw new GraphicsModeException(String.Format("Invalid GraphicsMode specified ({0}).", mode));
                }

                info = (XVisualInfo)Marshal.PtrToStructure(vs, typeof(XVisualInfo));
                Functions.XFree(vs);
            }

            return(info);
        }
示例#7
0
        bool SupportsExtension(X11WindowInfo window, string e)
        {
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }
            if (window.Display != Display)
            {
                throw new InvalidOperationException();
            }
            string extensions = null;

            using (new XLock(Display))
            {
                extensions = Glx.QueryExtensionsString(Display, window.Screen);
            }
            return(!String.IsNullOrEmpty(extensions) && extensions.Contains(e));
        }
示例#8
0
        public XI2MouseKeyboard()
        {
            window = new X11WindowInfo();

            window.Display = Functions.XOpenDisplay(IntPtr.Zero);
            using (new XLock(window.Display))
            {
                window.Screen     = Functions.XDefaultScreen(window.Display);
                window.RootWindow = Functions.XRootWindow(window.Display, window.Screen);
                window.Handle     = window.RootWindow;

                KeyMap = new X11KeyMap(window.Display);
            }

            if (!IsSupported(window.Display))
            {
                throw new NotSupportedException("XInput2 not supported.");
            }

            using (new XLock(window.Display))
                using (XIEventMask mask = new XIEventMask(1,
                                                          XIEventMasks.RawKeyPressMask |
                                                          XIEventMasks.RawKeyReleaseMask |
                                                          XIEventMasks.RawButtonPressMask |
                                                          XIEventMasks.RawButtonReleaseMask |
                                                          XIEventMasks.RawMotionMask |
                                                          XIEventMasks.MotionMask |
                                                          XIEventMasks.DeviceChangedMask |
                                                          (XIEventMasks)(1 << (int)ExitEvent)))
                {
                    XI.SelectEvents(window.Display, window.Handle, mask);
                    UpdateDevices();
                }

            ProcessingThread = new Thread(ProcessEvents);
            ProcessingThread.IsBackground = true;
            ProcessingThread.Start();
        }
示例#9
0
 private void Dispose(bool manuallyCalled)
 {
     if (disposed)
     {
         return;
     }
     if (manuallyCalled)
     {
         if (window != null && window.WindowHandle != IntPtr.Zero)
         {
             if (Exists)
             {
                 DestroyWindow();
             }
             window.Dispose();
             window = null;
         }
     }
     else
     {
         Debug.Print("[Warning] {0} leaked.", this.GetType().Name);
     }
     disposed = true;
 }
示例#10
0
 public override void MakeCurrent(IWindowInfo window)
 {
     if (window == this.currentWindow && this.IsCurrent)
     return;
       if (window != null && ((X11WindowInfo) window).Display != this.Display)
     throw new InvalidOperationException("MakeCurrent() may only be called on windows originating from the same display that spawned this GL context.");
       if (window == null)
       {
     using (new XLock(this.Display))
     {
       if (Glx.MakeCurrent(this.Display, IntPtr.Zero, IntPtr.Zero))
     this.currentWindow = (X11WindowInfo) null;
     }
       }
       else
       {
     X11WindowInfo x11WindowInfo = (X11WindowInfo) window;
     if (this.Display == IntPtr.Zero || x11WindowInfo.WindowHandle == IntPtr.Zero || this.Handle == ContextHandle.Zero)
       throw new InvalidOperationException("Invalid display, window or context.");
     bool flag;
     using (new XLock(this.Display))
     {
       flag = Glx.MakeCurrent(this.Display, x11WindowInfo.WindowHandle, this.Handle);
       if (flag)
     this.currentWindow = x11WindowInfo;
     }
     if (!flag)
       throw new GraphicsContextException("Failed to make context current.");
       }
       this.currentWindow = (X11WindowInfo) window;
 }
 void DrawDirect( FastBitmap bmp, uint bits, X11WindowInfo x11Info )
 {
     IntPtr image = API.XCreateImage( API.DefaultDisplay, x11Info.VisualInfo.Visual,
                                     bits, ImageFormat.ZPixmap, 0, bmp.Scan0,
                                     bmp.Width, bmp.Height, 32, 0 );
     API.XPutImage( API.DefaultDisplay, x11Info.WindowHandle, gc, image,
                   0, 0, 0, 0, bmp.Width, bmp.Height );
     API.XFree( image );
 }
示例#12
0
 static IntPtr CreateEmptyCursor(X11WindowInfo window)
 {
     IntPtr cursor = IntPtr.Zero;
     using (new XLock(window.Display))
     {
         XColor black, dummy;
         IntPtr cmap = Functions.XDefaultColormap(window.Display, window.Screen);
         Functions.XAllocNamedColor(window.Display, cmap, "black", out black, out dummy);
         IntPtr bmp_empty = Functions.XCreateBitmapFromData(window.Display,
             window.Handle, new byte[,] { { 0 } });
         cursor = Functions.XCreatePixmapCursor(window.Display,
             bmp_empty, bmp_empty, ref black, ref black, 0, 0);
     }
     return cursor;
 }
示例#13
0
        public X11GLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shared, bool direct,
                            int major, int minor, GraphicsContextFlags flags)
            : base(DesktopBackend.OpenGL)
        {
            if (mode == null)
            {
                throw new ArgumentNullException("mode");
            }
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }
            Mode = mode;
            // Do not move this lower, as almost everything requires the Display
            // property to be correctly set.
            Display                  = ((X11WindowInfo)window).Display;
            currentWindow            = (X11WindowInfo)window;
            currentWindow.VisualInfo = SelectVisual(mode, currentWindow);
            ContextHandle shareHandle = shared != null ?
                                        (shared as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;

            Debug.Write("Creating X11GLContext context: ");
            Debug.Write(direct ? "direct, " : "indirect, ");
            Debug.WriteLine(shareHandle.Handle == IntPtr.Zero ? "not shared... " :
                            String.Format("shared with ({0})... ", shareHandle));
            if (!glx_loaded)
            {
                Debug.WriteLine("Creating temporary context to load GLX extensions.");
                // Create a temporary context to obtain the necessary function pointers.
                XVisualInfo visual = currentWindow.VisualInfo;
                IntPtr      ctx    = IntPtr.Zero;
                using (new XLock(Display))
                {
                    ctx = Glx.CreateContext(Display, ref visual, IntPtr.Zero, true);
                    if (ctx == IntPtr.Zero)
                    {
                        ctx = Glx.CreateContext(Display, ref visual, IntPtr.Zero, false);
                    }
                }

                if (ctx != IntPtr.Zero)
                {
                    new Glx().LoadEntryPoints();
                    using (new XLock(Display))
                    {
                        Glx.MakeCurrent(Display, IntPtr.Zero, IntPtr.Zero);
                        //Glx.DestroyContext(Display, ctx);
                    }
                    glx_loaded = true;
                }
            }

            // Try using the new context creation method. If it fails, fall back to the old one.
            // For each of these methods, we try two times to create a context:
            // one with the "direct" flag intact, the other with the flag inversed.
            // HACK: It seems that Catalyst 9.1 - 9.4 on Linux have problems with contexts created through
            // GLX_ARB_create_context, including hideous input lag, no vsync and other. Use legacy context
            // creation if the user doesn't request a 3.0+ context.
            if ((major * 10 + minor >= 30) && Glx.Delegates.glXCreateContextAttribsARB != null)
            {
                Debug.Write("Using GLX_ARB_create_context... ");
                unsafe
                {
                    // We need the FB config for the current GraphicsMode.
                    int     count;
                    IntPtr *fbconfigs = Glx.ChooseFBConfig(Display, currentWindow.Screen,
                                                           new int[] {
                        (int)GLXAttribute.VISUAL_ID,
                        (int)mode.Index,
                        0
                    }, out count);
                    if (count > 0)
                    {
                        List <int> attributes = new List <int>();
                        attributes.Add((int)ArbCreateContext.MajorVersion);
                        attributes.Add(major);
                        attributes.Add((int)ArbCreateContext.MinorVersion);
                        attributes.Add(minor);
                        if (flags != 0)
                        {
#warning "This is not entirely correct: Embedded is not a valid flag! We need to add a GetARBContextFlags(GraphicsContextFlags) method."
                            attributes.Add((int)ArbCreateContext.Flags);
                            attributes.Add((int)flags);
                        }
                        // According to the docs, " <attribList> specifies a list of attributes for the context.
                        // The list consists of a sequence of <name,value> pairs terminated by the
                        // value 0. [...]"
                        // Is this a single 0, or a <0, 0> pair? (Defensive coding: add two zeroes just in case).
                        attributes.Add(0);
                        attributes.Add(0);
                        using (new XLock(Display))
                        {
                            Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(Display, *fbconfigs,
                                                                                    shareHandle.Handle, direct, attributes.ToArray()));
                            if (Handle == ContextHandle.Zero)
                            {
                                Debug.Write(String.Format("failed. Trying direct: {0}... ", !direct));
                                Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(Display, *fbconfigs,
                                                                                        shareHandle.Handle, !direct, attributes.ToArray()));
                            }
                        }

                        if (Handle == ContextHandle.Zero)
                        {
                            Debug.WriteLine("failed.");
                        }
                        else
                        {
                            Debug.WriteLine("success!");
                        }
                        using (new XLock(Display))
                        {
                            Functions.XFree((IntPtr)fbconfigs);
                        }
                    }
                }
            }

            if (Handle == ContextHandle.Zero)
            {
                Debug.Write("Using legacy context creation... ");
                XVisualInfo info = currentWindow.VisualInfo;
                using (new XLock(Display))
                {
                    // Cannot pass a Property by reference.
                    Handle = new ContextHandle(Glx.CreateContext(Display, ref info, shareHandle.Handle, direct));
                    if (Handle == ContextHandle.Zero)
                    {
                        Debug.WriteLine(String.Format("failed. Trying direct: {0}... ", !direct));
                        Handle = new ContextHandle(Glx.CreateContext(Display, ref info, IntPtr.Zero, !direct));
                    }
                }
            }

            if (Handle != ContextHandle.Zero)
            {
                Debug.Print("Context created (id: {0}).", Handle);
            }
            else
            {
                throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");
            }
            using (new XLock(Display))
            {
                if (!Glx.IsDirect(Display, Handle.Handle))
                {
                    Debug.Print("Warning: Context is not direct.");
                }
            }
        }
示例#14
0
        private void Dispose(bool manuallyCalled)
        {
            if (!disposed)
            {
                if (manuallyCalled)
                {
                    if (window != null && window.WindowHandle != IntPtr.Zero)
                    {
                        if (Exists)
                        {
                            try
                            {
                                Functions.XLockDisplay(window.Display);
                                Functions.XDestroyWindow(window.Display, window.WindowHandle);
                            }
                            finally
                            {
                                Functions.XUnlockDisplay(window.Display);
                            }

                            while (Exists)
                                ProcessEvents();
                        }

                        if (GraphicsContext.CurrentContext != null)
                            GraphicsContext.CurrentContext.MakeCurrent(null);

                        window.Dispose();
                        window = null;
                    }
                }
                else
                {
                    Debug.Print("[Warning] {0} leaked.", this.GetType().Name);
                }
                disposed = true;
            }
        }
        public override void MakeCurrent(IWindowInfo window)
        {
            if (window == currentWindow && IsCurrent)
                return;

            if (window == null) {
                Debug.Print("Releasing context {0} (Display: {1})... ", ContextHandle, Display);
                if (!Glx.glXMakeCurrent(Display, IntPtr.Zero, IntPtr.Zero))
                    Debug.Print("failed to release context");
            } else {
                X11WindowInfo w = (X11WindowInfo)window;
                Debug.Print("Making context {0} current (Display: {1}, Screen: {2}, Window: {3})... ", ContextHandle, Display, w.Screen, w.WindowHandle);

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

                if (!Glx.glXMakeCurrent(Display, w.WindowHandle, ContextHandle))
                    throw new GraphicsContextException("Failed to make context current.");

            }
            currentWindow = (X11WindowInfo)window;
        }
示例#16
0
 public unsafe X11GLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shared, bool direct, int major, int minor, GraphicsContextFlags flags)
 {
     if (mode == null)
     throw new ArgumentNullException("mode");
       if (window == null)
     throw new ArgumentNullException("window");
       this.Mode = mode;
       this.Display = ((X11WindowInfo) window).Display;
       this.currentWindow = (X11WindowInfo) window;
       this.currentWindow.VisualInfo = this.SelectVisual(mode, this.currentWindow);
       ContextHandle contextHandle = shared != null ? (shared as IGraphicsContextInternal).Context : (ContextHandle) IntPtr.Zero;
       if (!this.glx_loaded)
       {
     XVisualInfo visualInfo = this.currentWindow.VisualInfo;
     IntPtr num = IntPtr.Zero;
     using (new XLock(this.Display))
     {
       num = Glx.CreateContext(this.Display, ref visualInfo, IntPtr.Zero, true);
       if (num == IntPtr.Zero)
     num = Glx.CreateContext(this.Display, ref visualInfo, IntPtr.Zero, false);
     }
     if (num != IntPtr.Zero)
     {
       new Glx().LoadEntryPoints();
       using (new XLock(this.Display))
     Glx.MakeCurrent(this.Display, IntPtr.Zero, IntPtr.Zero);
       this.glx_loaded = true;
     }
       }
       if (major * 10 + minor >= 30 && Glx.Delegates.glXCreateContextAttribsARB != null)
       {
     int fbount;
     IntPtr* numPtr = Glx.ChooseFBConfig(this.Display, this.currentWindow.Screen, new int[3]
     {
       32779,
       (int) mode.Index.Value,
       0
     }, out fbount);
     if (fbount > 0)
     {
       List<int> list = new List<int>();
       list.Add(8337);
       list.Add(major);
       list.Add(8338);
       list.Add(minor);
       if (flags != GraphicsContextFlags.Default)
       {
     list.Add(8340);
     list.Add((int) flags);
       }
       list.Add(0);
       list.Add(0);
       using (new XLock(this.Display))
       {
     this.Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(this.Display, *numPtr, contextHandle.Handle, direct, list.ToArray()));
     if (this.Handle == ContextHandle.Zero)
       this.Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(this.Display, *numPtr, contextHandle.Handle, !direct, list.ToArray()));
       }
       int num = this.Handle == ContextHandle.Zero ? 1 : 0;
       using (new XLock(this.Display))
     Functions.XFree((IntPtr) ((void*) numPtr));
     }
       }
       if (this.Handle == ContextHandle.Zero)
       {
     XVisualInfo visualInfo = this.currentWindow.VisualInfo;
     using (new XLock(this.Display))
     {
       this.Handle = new ContextHandle(Glx.CreateContext(this.Display, ref visualInfo, contextHandle.Handle, direct));
       if (this.Handle == ContextHandle.Zero)
     this.Handle = new ContextHandle(Glx.CreateContext(this.Display, ref visualInfo, IntPtr.Zero, !direct));
     }
       }
       if (!(this.Handle != ContextHandle.Zero))
     throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");
       using (new XLock(this.Display))
     Glx.IsDirect(this.Display, this.Handle.Handle);
 }
示例#17
0
        private void Dispose(bool manuallyCalled)
        {
            if (!disposed)
            {
                if (manuallyCalled)
                {
                    if (window != null && window.WindowHandle != IntPtr.Zero)
                    {
                        if (Exists)
                        {
                            using (new XLock(window.Display))
                            {
                                Functions.XDestroyWindow(window.Display, window.WindowHandle);
                            }

                            while (Exists)
                                ProcessEvents();
                        }

                        window.Dispose();
                        window = null;
                    }
                }
                else
                {
                    Debug.Print("[Warning] {0} leaked.", this.GetType().Name);
                }
                disposed = true;
            }
        }
 /// <summary> Registers the necessary atoms for GameWindow. </summary>
 void RegisterAtoms(X11WindowInfo window)
 {
     wm_destroy = API.XInternAtom(window.Display, "WM_DELETE_WINDOW", true);
     net_wm_state = API.XInternAtom(window.Display, "_NET_WM_STATE", false);
     net_wm_state_minimized = API.XInternAtom(window.Display, "_NET_WM_STATE_MINIMIZED", false);
     net_wm_state_fullscreen = API.XInternAtom(window.Display, "_NET_WM_STATE_FULLSCREEN", false);
     net_wm_state_maximized_horizontal = API.XInternAtom(window.Display, "_NET_WM_STATE_MAXIMIZED_HORZ", false);
     net_wm_state_maximized_vertical = API.XInternAtom(window.Display, "_NET_WM_STATE_MAXIMIZED_VERT", false);
     net_wm_icon = API.XInternAtom(window.Display, "_NEW_WM_ICON", false);
     net_frame_extents = API.XInternAtom(window.Display, "_NET_FRAME_EXTENTS", false);
 }
示例#19
0
 bool SupportsCreateContextAttribs(IntPtr display, X11WindowInfo window)
 {
     return
         SupportsExtension(display, window, "GLX_ARB_create_context") &&
         SupportsExtension(display, window, "GLX_ARB_create_context_profile");
 }
 private void Dispose(bool manuallyCalled)
 {
     if (disposed) return;
     if (manuallyCalled) {
         if (window != null && window.WindowHandle != IntPtr.Zero) {
             if (Exists) {
                 DestroyWindow();
             }
             window.Dispose();
             window = null;
         }
     } else {
         Debug.Print("[Warning] {0} leaked.", this.GetType().Name);
     }
     disposed = true;
 }
示例#21
0
        public X11GLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shared, bool direct,
            int major, int minor, GraphicsContextFlags flags)
        {
            if (mode == null)
                throw new ArgumentNullException("mode");
            if (window == null)
                throw new ArgumentNullException("window");

            Mode = mode;

            currentWindow = (X11WindowInfo)window;
            currentWindow.VisualInfo = SelectVisual(mode, currentWindow);

            ContextHandle shareHandle = shared != null ?
                (shared as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;

            Debug.Write("Creating X11GLContext context: ");
            Debug.Write(direct ? "direct, " : "indirect, ");
            Debug.WriteLine(shareHandle.Handle == IntPtr.Zero ? "not shared... " :
                String.Format("shared with ({0})... ", shareHandle));

            if (!glx_loaded)
            {
                Debug.WriteLine("Creating temporary context to load GLX extensions.");

                // Create a temporary context to obtain the necessary function pointers.
                XVisualInfo visual = currentWindow.VisualInfo;
                IntPtr ctx = Glx.CreateContext(currentWindow.Display, ref visual, IntPtr.Zero, true);
                if (ctx == IntPtr.Zero)
                    ctx = Glx.CreateContext(currentWindow.Display, ref visual, IntPtr.Zero, false);

                if (ctx != IntPtr.Zero)
                {
                    new Glx().LoadAll();
                    Glx.MakeCurrent(currentWindow.Display, IntPtr.Zero, IntPtr.Zero);
                    //Glx.DestroyContext(currentWindow.Display, ctx);
                    glx_loaded = true;
                }
            }

            // Try using the new context creation method. If it fails, fall back to the old one.
            // For each of these methods, we try two times to create a context:
            // one with the "direct" flag intact, the other with the flag inversed.
            // HACK: It seems that Catalyst 9.1 - 9.4 on Linux have problems with contexts created through
            // GLX_ARB_create_context, including hideous input lag, no vsync and other. Use legacy context
            // creation if the user doesn't request a 3.0+ context.
            if ((major * 10 + minor >= 30) && Glx.Delegates.glXCreateContextAttribsARB != null)
            {
                Debug.Write("Using GLX_ARB_create_context... ");

                unsafe
                {
                    // We need the FB config for the current GraphicsMode.
                    int count;
                    IntPtr* fbconfigs = Glx.ChooseFBConfig(currentWindow.Display, currentWindow.Screen,
                        new int[] { (int)GLXAttribute.VISUAL_ID, (int)mode.Index, 0 }, out count);

                    if (count > 0)
                    {
                        List<int> attributes = new List<int>();
                        attributes.Add((int)ArbCreateContext.MajorVersion);
                        attributes.Add(major);
                        attributes.Add((int)ArbCreateContext.MinorVersion);
                        attributes.Add(minor);
                        if (flags != 0)
                        {
                            attributes.Add((int)ArbCreateContext.Flags);
                            attributes.Add((int)flags);
                        }
                        attributes.Add(0);

                        Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(currentWindow.Display, *fbconfigs,
                                shareHandle.Handle, direct, attributes.ToArray()));

                        if (Handle == ContextHandle.Zero)
                        {
                            Debug.Write(String.Format("failed. Trying direct: {0}... ", !direct));
                            Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(currentWindow.Display, *fbconfigs,
                                    shareHandle.Handle, !direct, attributes.ToArray()));
                        }

                        if (Handle == ContextHandle.Zero)
                            Debug.WriteLine("failed.");
                        else
                            Debug.WriteLine("success!");

                        Functions.XFree((IntPtr)fbconfigs);
                    }
                }
            }

            if (Handle == ContextHandle.Zero)
            {
                Debug.Write("Using legacy context creation... ");

                XVisualInfo info = currentWindow.VisualInfo;   // Cannot pass a Property by reference.
                Handle = new ContextHandle(Glx.CreateContext(currentWindow.Display, ref info, shareHandle.Handle, direct));

                if (Handle == ContextHandle.Zero)
                {
                    Debug.WriteLine(String.Format("failed. Trying direct: {0}... ", !direct));
                    Handle = new ContextHandle(Glx.CreateContext(currentWindow.Display, ref info, IntPtr.Zero, !direct));
                }
            }

            if (Handle != ContextHandle.Zero)
                Debug.Print("Context created (id: {0}).", Handle);
            else
                throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");

            if (!Glx.IsDirect(currentWindow.Display, Handle.Handle))
                Debug.Print("Warning: Context is not direct.");
        }
示例#22
0
 bool SupportsExtension(X11WindowInfo window, string e)
 {
     string extensions = Glx.QueryExtensionsString(window.Display, window.Screen);
     return !String.IsNullOrEmpty(extensions) && extensions.Contains(e);
 }
示例#23
0
 private XVisualInfo SelectVisual(GraphicsMode mode, X11WindowInfo currentWindow)
 {
     XVisualInfo template = new XVisualInfo();
       template.VisualID = mode.Index.Value;
       template.Screen = currentWindow.Screen;
       lock (API.Lock)
       {
     int local_1;
     IntPtr local_2 = Functions.XGetVisualInfo(this.Display, XVisualInfoMask.ID | XVisualInfoMask.Screen, ref template, out local_1);
     if (local_1 == 0)
       throw new GraphicsModeException(string.Format("Invalid GraphicsMode specified ({0}).", (object) mode));
     template = (XVisualInfo) Marshal.PtrToStructure(local_2, typeof (XVisualInfo));
     Functions.XFree(local_2);
       }
       return template;
 }
示例#24
0
        static bool SupportsExtension(IntPtr display, X11WindowInfo window, string e)
        {
            if (window == null)
                throw new ArgumentNullException("window");
            if (e == null)
                throw new ArgumentNullException("e");
            if (window.Display != display)
                throw new InvalidOperationException();

            string extensions = null;
            using (new XLock(display))
            {
                extensions = Glx.QueryExtensionsString(display, window.Screen);
            }
            return !String.IsNullOrEmpty(extensions) && extensions.Contains(e);
        }
示例#25
0
 private bool SupportsExtension(X11WindowInfo window, string e)
 {
     if (window == null)
     throw new ArgumentNullException("window");
       if (e == null)
     throw new ArgumentNullException("e");
       if (window.Display != this.Display)
     throw new InvalidOperationException();
       string str = (string) null;
       using (new XLock(this.Display))
     str = Glx.QueryExtensionsString(this.Display, window.Screen);
       if (!string.IsNullOrEmpty(str))
     return str.Contains(e);
       else
     return false;
 }
示例#26
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;
                using (new XLock(Display))
                {
                    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.");

                using (new XLock(Display))
                {
                    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;
        }
示例#27
0
        XVisualInfo SelectVisual(GraphicsMode mode, X11WindowInfo currentWindow)
        {
            XVisualInfo info = new XVisualInfo();
            info.VisualID = (IntPtr)mode.Index;
            info.Screen = currentWindow.Screen;
            int items;
            
            lock (API.Lock)
            {
                IntPtr vs = Functions.XGetVisualInfo(Display, XVisualInfoMask.ID | XVisualInfoMask.Screen, ref info, out items);
                if (items == 0)
                    throw new GraphicsModeException(String.Format("Invalid GraphicsMode specified ({0}).", mode));

                info = (XVisualInfo)Marshal.PtrToStructure(vs, typeof(XVisualInfo));
                Functions.XFree(vs);
            }

            return info;
        }
示例#28
0
        public unsafe X11GLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shared, bool direct, int major, int minor, GraphicsContextFlags flags)
        {
            if (mode == null)
            {
                throw new ArgumentNullException("mode");
            }
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }
            this.Mode                     = mode;
            this.Display                  = ((X11WindowInfo)window).Display;
            this.currentWindow            = (X11WindowInfo)window;
            this.currentWindow.VisualInfo = this.SelectVisual(mode, this.currentWindow);
            ContextHandle contextHandle = shared != null ? (shared as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;

            if (!this.glx_loaded)
            {
                XVisualInfo visualInfo = this.currentWindow.VisualInfo;
                IntPtr      num        = IntPtr.Zero;
                using (new XLock(this.Display))
                {
                    num = Glx.CreateContext(this.Display, ref visualInfo, IntPtr.Zero, true);
                    if (num == IntPtr.Zero)
                    {
                        num = Glx.CreateContext(this.Display, ref visualInfo, IntPtr.Zero, false);
                    }
                }
                if (num != IntPtr.Zero)
                {
                    new Glx().LoadEntryPoints();
                    using (new XLock(this.Display))
                        Glx.MakeCurrent(this.Display, IntPtr.Zero, IntPtr.Zero);
                    this.glx_loaded = true;
                }
            }
            if (major * 10 + minor >= 30 && Glx.Delegates.glXCreateContextAttribsARB != null)
            {
                int     fbount;
                IntPtr *numPtr = Glx.ChooseFBConfig(this.Display, this.currentWindow.Screen, new int[3]
                {
                    32779,
                    (int)mode.Index.Value,
                    0
                }, out fbount);
                if (fbount > 0)
                {
                    List <int> list = new List <int>();
                    list.Add(8337);
                    list.Add(major);
                    list.Add(8338);
                    list.Add(minor);
                    if (flags != GraphicsContextFlags.Default)
                    {
                        list.Add(8340);
                        list.Add((int)flags);
                    }
                    list.Add(0);
                    list.Add(0);
                    using (new XLock(this.Display))
                    {
                        this.Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(this.Display, *numPtr, contextHandle.Handle, direct, list.ToArray()));
                        if (this.Handle == ContextHandle.Zero)
                        {
                            this.Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(this.Display, *numPtr, contextHandle.Handle, !direct, list.ToArray()));
                        }
                    }
                    int num = this.Handle == ContextHandle.Zero ? 1 : 0;
                    using (new XLock(this.Display))
                        Functions.XFree((IntPtr)((void *)numPtr));
                }
            }
            if (this.Handle == ContextHandle.Zero)
            {
                XVisualInfo visualInfo = this.currentWindow.VisualInfo;
                using (new XLock(this.Display))
                {
                    this.Handle = new ContextHandle(Glx.CreateContext(this.Display, ref visualInfo, contextHandle.Handle, direct));
                    if (this.Handle == ContextHandle.Zero)
                    {
                        this.Handle = new ContextHandle(Glx.CreateContext(this.Display, ref visualInfo, IntPtr.Zero, !direct));
                    }
                }
            }
            if (!(this.Handle != ContextHandle.Zero))
            {
                throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");
            }
            using (new XLock(this.Display))
                Glx.IsDirect(this.Display, this.Handle.Handle);
        }
示例#29
0
 static bool SupportsCreateContextAttribs(IntPtr display, X11WindowInfo window)
 {
     return
         SupportsExtension(display, window, "GLX_ARB_create_context") &&
         SupportsExtension(display, window, "GLX_ARB_create_context_profile") &&
         Glx.Delegates.glXCreateContextAttribsARB != null;
 }
        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;
                using (new XLock(Display))
                {
                    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.");
                }

                using (new XLock(Display))
                {
                    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;
        }
示例#31
0
        public X11GLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shared, bool direct,
            int major, int minor, GraphicsContextFlags flags)
        {
            if (mode == null)
                throw new ArgumentNullException("mode");
            if (window == null)
                throw new ArgumentNullException("window");

            Mode = ModeSelector.SelectGraphicsMode(
                mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
                mode.AccumulatorFormat, mode.Buffers, mode.Stereo);

            // Do not move this lower, as almost everything requires the Display
            // property to be correctly set.
            Display = ((X11WindowInfo)window).Display;
            
            currentWindow = (X11WindowInfo)window;
            currentWindow.VisualInfo = SelectVisual(Mode, currentWindow);
            
            ContextHandle shareHandle = shared != null ?
                (shared as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;
            
            Debug.Write("Creating X11GLContext context: ");
            Debug.Write(direct ? "direct, " : "indirect, ");
            Debug.WriteLine(shareHandle.Handle == IntPtr.Zero ? "not shared... " :
                String.Format("shared with ({0})... ", shareHandle));
            
            // Try using the new context creation method. If it fails, fall back to the old one.
            // For each of these methods, we try two times to create a context:
            // one with the "direct" flag intact, the other with the flag inversed.
            // HACK: It seems that Catalyst 9.1 - 9.4 on Linux have problems with contexts created through
            // GLX_ARB_create_context, including hideous input lag, no vsync and other madness.
            // Use legacy context creation if the user doesn't request a 3.0+ context.
            if ((major * 10 + minor >= 30) && SupportsCreateContextAttribs(Display, currentWindow))
            {
                Debug.Write("Using GLX_ARB_create_context... ");
                
                unsafe
                {
                    // We need the FB config for the current GraphicsMode.
                    int count;
                    IntPtr* fbconfigs = Glx.ChooseFBConfig(Display, currentWindow.Screen,
                        new int[] {
                        (int)GLXAttribute.VISUAL_ID,
                        (int)Mode.Index,
                        0
                    }, out count);
                    
                    if (count > 0)
                    {
                        List<int> attributes = new List<int>();
                        attributes.Add((int)ArbCreateContext.MajorVersion);
                        attributes.Add(major);
                        attributes.Add((int)ArbCreateContext.MinorVersion);
                        attributes.Add(minor);
                        if (flags != 0)
                        {
                            attributes.Add((int)ArbCreateContext.Flags);
                            attributes.Add((int)GetARBContextFlags(flags));
                            attributes.Add((int)ArbCreateContext.ProfileMask);
                            attributes.Add((int)GetARBProfileFlags(flags));
                        }
                        // According to the docs, " <attribList> specifies a list of attributes for the context.
                        // The list consists of a sequence of <name,value> pairs terminated by the
                        // value 0. [...]"
                        // Is this a single 0, or a <0, 0> pair? (Defensive coding: add two zeroes just in case).
                        attributes.Add(0);
                        attributes.Add(0);

                        using (new XLock(Display))
                        {
                            Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(Display, *fbconfigs,
                                    shareHandle.Handle, direct, attributes.ToArray()));

                            if (Handle == ContextHandle.Zero)
                            {
                                Debug.Write(String.Format("failed. Trying direct: {0}... ", !direct));
                                Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(Display, *fbconfigs,
                                        shareHandle.Handle, !direct, attributes.ToArray()));
                            }
                        }
                        
                        if (Handle == ContextHandle.Zero)
                            Debug.WriteLine("failed.");
                        else
                            Debug.WriteLine("success!");
                        
                        using (new XLock(Display))
                        {
                            Functions.XFree((IntPtr)fbconfigs);
                        }
                    }
                }
            }
            
            if (Handle == ContextHandle.Zero)
            {
                Debug.Write("Using legacy context creation... ");
                
                XVisualInfo info = currentWindow.VisualInfo;
                using (new XLock(Display))
                {
                    // Cannot pass a Property by reference.
                    Handle = new ContextHandle(Glx.CreateContext(Display, ref info, shareHandle.Handle, direct));

                    if (Handle == ContextHandle.Zero)
                    {
                        Debug.WriteLine(String.Format("failed. Trying direct: {0}... ", !direct));
                        Handle = new ContextHandle(Glx.CreateContext(Display, ref info, IntPtr.Zero, !direct));
                    }
                }
            }
            
            if (Handle != ContextHandle.Zero)
                Debug.Print("Context created (id: {0}).", Handle);
            else
                throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");

            using (new XLock(Display))
            {
                if (!Glx.IsDirect(Display, Handle.Handle))
                    Debug.Print("Warning: Context is not direct.");
            }
        }
示例#32
0
        public static void SendNetClientMessage(X11WindowInfo window, IntPtr message_type,
                                                IntPtr l0, IntPtr l1, IntPtr l2)
        {
            XEvent xev;

            xev = new XEvent();
            xev.ClientMessageEvent.type = XEventName.ClientMessage;
            xev.ClientMessageEvent.send_event = true;
            xev.ClientMessageEvent.window = window.WindowHandle;
            xev.ClientMessageEvent.message_type = message_type;
            xev.ClientMessageEvent.format = 32;
            xev.ClientMessageEvent.ptr1 = l0;
            xev.ClientMessageEvent.ptr2 = l1;
            xev.ClientMessageEvent.ptr3 = l2;

            XSendEvent(window.Display, window.WindowHandle, false, new IntPtr((int)EventMask.NoEventMask), ref xev);
        }
示例#33
0
        public X11GLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shared, bool direct,
                            int major, int minor, GraphicsContextFlags flags)
        {
            if (mode == null)
            {
                throw new ArgumentNullException("mode");
            }
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            // Do not move this lower, as almost everything requires the Display
            // property to be correctly set.
            Display = ((X11WindowInfo)window).Display;

            // Check that GLX is supported. We cannot proceed to create
            // an OpenGL context without the GLX extension.
            int error_base;
            int event_base;
            int glx_major;
            int glx_minor;

            using (new XLock(Display))
            {
                bool supported = Glx.QueryExtension(Display, out error_base, out event_base);
                supported &= Glx.QueryVersion(Display, out glx_major, out glx_minor);
                if (supported)
                {
                    Debug.Print("[X11] GLX supported. Version is {0}.{1}", glx_major, glx_minor);
                }
                else
                {
                    throw new NotSupportedException("[X11] GLX extension is not supported.");
                }
            }

            IntPtr visual   = IntPtr.Zero;
            IntPtr fbconfig = IntPtr.Zero;

            // Once a window has a visual, we cannot use a different
            // visual on the OpenGL context, or glXMakeCurrent might fail.
            // Note: we should only check X11WindowInfo.Visual, as that
            // is the only property that can be set by Utilities.CreateX11WindowInfo.
            currentWindow = (X11WindowInfo)window;
            if (currentWindow.Visual != IntPtr.Zero)
            {
                visual   = currentWindow.Visual;
                fbconfig = currentWindow.FBConfig;
                Mode     = currentWindow.GraphicsMode;
            }

            if (Mode == null || !Mode.Index.HasValue)
            {
                Mode = ModeSelector.SelectGraphicsMode(mode, out visual, out fbconfig);
            }

            ContextHandle shareHandle = shared != null ?
                                        (shared as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;

            Debug.Write("Creating X11GLContext context: ");
            Debug.Write(direct ? "direct, " : "indirect, ");
            Debug.WriteLine(shareHandle.Handle == IntPtr.Zero ? "not shared... " :
                            String.Format("shared with ({0})... ", shareHandle));

            // Try using the new context creation method. If it fails, fall back to the old one.
            // For each of these methods, we try two times to create a context:
            // one with the "direct" flag intact, the other with the flag inversed.
            // HACK: It seems that Catalyst 9.1 - 9.4 on Linux have problems with contexts created through
            // GLX_ARB_create_context, including hideous input lag, no vsync and other madness.
            // Use legacy context creation if the user doesn't request a 3.0+ context.
            if (fbconfig != IntPtr.Zero && (major * 10 + minor >= 30) && SupportsCreateContextAttribs(Display, currentWindow))
            {
                Handle = CreateContextAttribs(Display, currentWindow.Screen,
                                              fbconfig, direct, major, minor, flags, shareHandle);
            }

            if (Handle == ContextHandle.Zero)
            {
                Handle = CreateContextLegacy(Display, visual, direct, shareHandle);
            }

            if (Handle != ContextHandle.Zero)
            {
                Debug.Print("Context created (id: {0}).", Handle);
            }
            else
            {
                throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");
            }

            using (new XLock(Display))
            {
                if (!Glx.IsDirect(Display, Handle.Handle))
                {
                    Debug.Print("Warning: Context is not direct.");
                }
            }
        }
示例#34
0
        public XI2MouseKeyboard()
        {
            window = new X11WindowInfo();

            window.Display = Functions.XOpenDisplay(IntPtr.Zero);
            using (new XLock(window.Display))
            {
                window.Screen = Functions.XDefaultScreen(window.Display);
                window.RootWindow = Functions.XRootWindow(window.Display, window.Screen);
                window.Handle = window.RootWindow;

                KeyMap = new X11KeyMap(window.Display);
            }

            if (!IsSupported(window.Display))
                throw new NotSupportedException("XInput2 not supported.");

            using (new XLock(window.Display))
            using (XIEventMask mask = new XIEventMask(1,
                XIEventMasks.RawKeyPressMask |
                XIEventMasks.RawKeyReleaseMask |
                XIEventMasks.RawButtonPressMask |
                XIEventMasks.RawButtonReleaseMask |
                XIEventMasks.RawMotionMask |
                XIEventMasks.MotionMask |
                XIEventMasks.DeviceChangedMask |
                (XIEventMasks)(1 << (int)ExitEvent)))
            {
                XI.SelectEvents(window.Display, window.Handle, mask);
                UpdateDevices();
            }

            ProcessingThread = new Thread(ProcessEvents);
            ProcessingThread.IsBackground = true;
            ProcessingThread.Start();
        }
示例#35
0
        /// <summary>
        /// Not used yet.
        /// Registers the necessary atoms for GameWindow.
        /// </summary>
        private void RegisterAtoms(X11WindowInfo window)
        {
            using (new XLock(window.Display))
            {
                Debug.WriteLine("Registering atoms.");
                _atom_wm_destroy = Functions.XInternAtom(window.Display, "WM_DELETE_WINDOW", true);
            
                _atom_net_wm_state = Functions.XInternAtom(window.Display, "_NET_WM_STATE", false);
                _atom_net_wm_state_minimized = Functions.XInternAtom(window.Display, "_NET_WM_STATE_MINIMIZED", false);
                _atom_net_wm_state_fullscreen = Functions.XInternAtom(window.Display, "_NET_WM_STATE_FULLSCREEN", false);
                _atom_net_wm_state_maximized_horizontal =
                    Functions.XInternAtom(window.Display, "_NET_WM_STATE_MAXIMIZED_HORZ", false);
                _atom_net_wm_state_maximized_vertical =
                    Functions.XInternAtom(window.Display, "_NET_WM_STATE_MAXIMIZED_VERT", false);
            
                _atom_net_wm_allowed_actions =
                    Functions.XInternAtom(window.Display, "_NET_WM_ALLOWED_ACTIONS", false);
                _atom_net_wm_action_resize =
                    Functions.XInternAtom(window.Display, "_NET_WM_ACTION_RESIZE", false);
                _atom_net_wm_action_maximize_horizontally =
                    Functions.XInternAtom(window.Display, "_NET_WM_ACTION_MAXIMIZE_HORZ", false);
                _atom_net_wm_action_maximize_vertically =
                    Functions.XInternAtom(window.Display, "_NET_WM_ACTION_MAXIMIZE_VERT", false);

                _atom_net_wm_icon =
                    Functions.XInternAtom(window.Display, "_NEW_WM_ICON", false);

                _atom_net_frame_extents =
                    Functions.XInternAtom(window.Display, "_NET_FRAME_EXTENTS", false);

//            string[] atom_names = new string[]
//            {
//                //"WM_TITLE",
//                //"UTF8_STRING"
//            };
//            IntPtr[] atoms = new IntPtr[atom_names.Length];
//            //Functions.XInternAtoms(window.Display, atom_names, atom_names.Length, false, atoms);
//
//            int offset = 0;
//            //WMTitle = atoms[offset++];
//            //UTF8String = atoms[offset++];
            }
        }
示例#36
0
 public X11GLContext(ContextHandle handle, IWindowInfo window, IGraphicsContext shared, bool direct, int major, int minor, GraphicsContextFlags flags)
 {
     if (handle == ContextHandle.Zero)
     throw new ArgumentException("handle");
       if (window == null)
     throw new ArgumentNullException("window");
       this.Handle = handle;
       this.currentWindow = (X11WindowInfo) window;
       this.Display = this.currentWindow.Display;
 }
示例#37
0
        public static void SendNetWMMessage(X11WindowInfo window, IntPtr message_type, IntPtr l0, IntPtr l1, IntPtr l2)
        {
            XEvent xev;

            xev = new XEvent();
            xev.ClientMessageEvent.type = XEventName.ClientMessage;
            xev.ClientMessageEvent.send_event = true;
            xev.ClientMessageEvent.window = window.WindowHandle;
            xev.ClientMessageEvent.message_type = message_type;
            xev.ClientMessageEvent.format = 32;
            xev.ClientMessageEvent.ptr1 = l0;
            xev.ClientMessageEvent.ptr2 = l1;
            xev.ClientMessageEvent.ptr3 = l2;

            XSendEvent(window.Display, window.RootWindow, false,
                       new IntPtr((int)(EventMask.SubstructureRedirectMask | EventMask.SubstructureNotifyMask)),
                       ref xev);
        }
示例#38
0
        public X11GLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shared, bool direct,
            int major, int minor, GraphicsContextFlags flags)
        {
            if (mode == null)
                throw new ArgumentNullException("mode");
            if (window == null)
                throw new ArgumentNullException("window");

            // Do not move this lower, as almost everything requires the Display
            // property to be correctly set.
            Display = ((X11WindowInfo)window).Display;

            // Check that GLX is supported. We cannot proceed to create
            // an OpenGL context without the GLX extension.
            int error_base;
            int event_base;
            int glx_major;
            int glx_minor;
            using (new XLock(Display))
            {
                bool supported = Glx.QueryExtension(Display, out error_base, out event_base);
                supported &= Glx.QueryVersion(Display, out glx_major, out glx_minor);
                if (supported)
                {
                    Debug.Print("[X11] GLX supported. Version is {0}.{1}", glx_major, glx_minor);
                }
                else
                {
                    throw new NotSupportedException("[X11] GLX extension is not supported.");
                }
            }

            IntPtr visual = IntPtr.Zero;
            IntPtr fbconfig = IntPtr.Zero;

            // Once a window has a visual, we cannot use a different
            // visual on the OpenGL context, or glXMakeCurrent might fail.
            // Note: we should only check X11WindowInfo.Visual, as that
            // is the only property that can be set by Utilities.CreateX11WindowInfo.
            currentWindow = (X11WindowInfo)window;
            if (currentWindow.Visual != IntPtr.Zero)
            {
                visual = currentWindow.Visual;
                fbconfig = currentWindow.FBConfig;
                Mode = currentWindow.GraphicsMode;
            }

            if (Mode == null || !Mode.Index.HasValue)
            {
                Mode = ModeSelector.SelectGraphicsMode(mode, out visual, out fbconfig);
            }

            ContextHandle shareHandle = shared != null ?
                (shared as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;
            
            Debug.Write("Creating X11GLContext context: ");
            Debug.Write(direct ? "direct, " : "indirect, ");
            Debug.WriteLine(shareHandle.Handle == IntPtr.Zero ? "not shared... " :
                String.Format("shared with ({0})... ", shareHandle));
            
            // Try using the new context creation method. If it fails, fall back to the old one.
            // For each of these methods, we try two times to create a context:
            // one with the "direct" flag intact, the other with the flag inversed.
            // HACK: It seems that Catalyst 9.1 - 9.4 on Linux have problems with contexts created through
            // GLX_ARB_create_context, including hideous input lag, no vsync and other madness.
            // Use legacy context creation if the user doesn't request a 3.0+ context.
            if (fbconfig != IntPtr.Zero && (major * 10 + minor >= 30) && SupportsCreateContextAttribs(Display, currentWindow))
            {
                Handle = CreateContextAttribs(Display, currentWindow.Screen,
                    fbconfig, direct, major, minor, flags, shareHandle);
            }
            
            if (Handle == ContextHandle.Zero)
            {
                Handle = CreateContextLegacy(Display, visual, direct, shareHandle);
            }
            
            if (Handle != ContextHandle.Zero)
                Debug.Print("Context created (id: {0}).", Handle);
            else
                throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");

            using (new XLock(Display))
            {
                if (!Glx.IsDirect(Display, Handle.Handle))
                    Debug.Print("Warning: Context is not direct.");
            }
        }
示例#39
0
 private bool SupportsCreateContextAttribs(IntPtr display, X11WindowInfo window)
 {
     return
         (SupportsExtension(display, window, "GLX_ARB_create_context") &&
          SupportsExtension(display, window, "GLX_ARB_create_context_profile"));
 }
示例#40
0
        bool SupportsExtension(X11WindowInfo window, string e)
        {
            string extensions = Glx.QueryExtensionsString(window.Display, window.Screen);

            return(!String.IsNullOrEmpty(extensions) && extensions.Contains(e));
        }
示例#41
0
        public XI2MouseKeyboard()
        {
            window = new X11WindowInfo();

            window.Display = Functions.XOpenDisplay(IntPtr.Zero);
            using (new XLock(window.Display))
            {
                XSetWindowAttributes attr = new XSetWindowAttributes();

                window.Screen = Functions.XDefaultScreen(window.Display);
                window.RootWindow = Functions.XRootWindow(window.Display, window.Screen);
                window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow,
                    0, 0, 1, 1, 0, 0,
                    CreateWindowArgs.InputOnly, IntPtr.Zero,
                    SetWindowValuemask.Nothing, attr);

                KeyMap = new X11KeyMap(window.Display);
            }

            if (!IsSupported(window.Display))
                throw new NotSupportedException("XInput2 not supported.");

            // Enable XI2 mouse/keyboard events
            // Note: the input event loop blocks waiting for these events
            // *or* a custom ClientMessage event that instructs us to exit.
            // See SendExitEvent() below.
            using (new XLock(window.Display))
            using (XIEventMask mask = new XIEventMask(1,
                XIEventMasks.RawKeyPressMask |
                XIEventMasks.RawKeyReleaseMask |
                XIEventMasks.RawButtonPressMask |
                XIEventMasks.RawButtonReleaseMask |
                XIEventMasks.RawMotionMask |
                XIEventMasks.MotionMask |
                XIEventMasks.DeviceChangedMask))
            {
                XI.SelectEvents(window.Display, window.RootWindow, mask);
                UpdateDevices();
            }

            ProcessingThread = new Thread(ProcessEvents);
            ProcessingThread.IsBackground = true;
            ProcessingThread.Start();
        }
示例#42
0
        public X11GLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shared, bool direct,
                            int major, int minor, GraphicsContextFlags flags)
        {
            if (mode == null)
            {
                throw new ArgumentNullException("mode");
            }
            if (window == null)
            {
                throw new ArgumentNullException("window");
            }

            Mode = mode;

            currentWindow            = (X11WindowInfo)window;
            currentWindow.VisualInfo = SelectVisual(mode, currentWindow);

            ContextHandle shareHandle = shared != null ?
                                        (shared as IGraphicsContextInternal).Context : (ContextHandle)IntPtr.Zero;

            Debug.Write("Creating X11GLContext context: ");
            Debug.Write(direct ? "direct, " : "indirect, ");
            Debug.WriteLine(shareHandle.Handle == IntPtr.Zero ? "not shared... " :
                            String.Format("shared with ({0})... ", shareHandle));

            if (!glx_loaded)
            {
                Debug.WriteLine("Creating temporary context to load GLX extensions.");

                // Create a temporary context to obtain the necessary function pointers.
                XVisualInfo visual = currentWindow.VisualInfo;
                IntPtr      ctx    = Glx.CreateContext(currentWindow.Display, ref visual, IntPtr.Zero, true);
                if (ctx == IntPtr.Zero)
                {
                    ctx = Glx.CreateContext(currentWindow.Display, ref visual, IntPtr.Zero, false);
                }

                if (ctx != IntPtr.Zero)
                {
                    new Glx().LoadAll();
                    Glx.MakeCurrent(currentWindow.Display, IntPtr.Zero, IntPtr.Zero);
                    //Glx.DestroyContext(currentWindow.Display, ctx);
                    glx_loaded = true;
                }
            }

            // Try using the new context creation method. If it fails, fall back to the old one.
            // For each of these methods, we try two times to create a context:
            // one with the "direct" flag intact, the other with the flag inversed.
            // HACK: It seems that Catalyst 9.1 - 9.4 on Linux have problems with contexts created through
            // GLX_ARB_create_context, including hideous input lag, no vsync and other. Use legacy context
            // creation if the user doesn't request a 3.0+ context.
            if ((major * 10 + minor >= 30) && Glx.Delegates.glXCreateContextAttribsARB != null)
            {
                Debug.Write("Using GLX_ARB_create_context... ");

                unsafe
                {
                    // We need the FB config for the current GraphicsMode.
                    int     count;
                    IntPtr *fbconfigs = Glx.ChooseFBConfig(currentWindow.Display, currentWindow.Screen,
                                                           new int[] { (int)GLXAttribute.VISUAL_ID, (int)mode.Index, 0 }, out count);

                    if (count > 0)
                    {
                        List <int> attributes = new List <int>();
                        attributes.Add((int)ArbCreateContext.MajorVersion);
                        attributes.Add(major);
                        attributes.Add((int)ArbCreateContext.MinorVersion);
                        attributes.Add(minor);
                        if (flags != 0)
                        {
                            attributes.Add((int)ArbCreateContext.Flags);
                            attributes.Add((int)flags);
                        }
                        attributes.Add(0);

                        Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(currentWindow.Display, *fbconfigs,
                                                                                shareHandle.Handle, direct, attributes.ToArray()));

                        if (Handle == ContextHandle.Zero)
                        {
                            Debug.Write(String.Format("failed. Trying direct: {0}... ", !direct));
                            Handle = new ContextHandle(Glx.Arb.CreateContextAttribs(currentWindow.Display, *fbconfigs,
                                                                                    shareHandle.Handle, !direct, attributes.ToArray()));
                        }

                        if (Handle == ContextHandle.Zero)
                        {
                            Debug.WriteLine("failed.");
                        }
                        else
                        {
                            Debug.WriteLine("success!");
                        }

                        Functions.XFree((IntPtr)fbconfigs);
                    }
                }
            }

            if (Handle == ContextHandle.Zero)
            {
                Debug.Write("Using legacy context creation... ");

                XVisualInfo info = currentWindow.VisualInfo;   // Cannot pass a Property by reference.
                Handle = new ContextHandle(Glx.CreateContext(currentWindow.Display, ref info, shareHandle.Handle, direct));

                if (Handle == ContextHandle.Zero)
                {
                    Debug.WriteLine(String.Format("failed. Trying direct: {0}... ", !direct));
                    Handle = new ContextHandle(Glx.CreateContext(currentWindow.Display, ref info, IntPtr.Zero, !direct));
                }
            }

            if (Handle != ContextHandle.Zero)
            {
                Debug.Print("Context created (id: {0}).", Handle);
            }
            else
            {
                throw new GraphicsContextException("Failed to create OpenGL context. Glx.CreateContext call returned 0.");
            }

            if (!Glx.IsDirect(currentWindow.Display, Handle.Handle))
            {
                Debug.Print("Warning: Context is not direct.");
            }
        }