示例#1
0
        internal X11GLControl(GraphicsMode mode, Control control)
        {

            if (mode == null)
                throw new ArgumentNullException("mode");
            if (control == null)
                throw new ArgumentNullException("control");
            if (!mode.Index.HasValue)
                throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
            this.mode = mode;
            // Use reflection to retrieve the necessary values from Mono's Windows.Forms implementation.
            Type xplatui = Type.GetType("System.Windows.Forms.XplatUIX11, System.Windows.Forms");
            if (xplatui == null)
                throw new PlatformNotSupportedException(
   "System.Windows.Forms.XplatUIX11 missing. Unsupported platform or Mono runtime version, aborting.");
            // get the required handles from the X11 API.
            display = (IntPtr)GetStaticFieldValue(xplatui, "DisplayHandle");
            IntPtr rootWindow = (IntPtr)GetStaticFieldValue(xplatui, "RootWindow");
            int screen = (int)GetStaticFieldValue(xplatui, "ScreenNo");
            // get the XVisualInfo for this GraphicsMode
            XVisualInfo info = new XVisualInfo();
            info.VisualID = mode.Index.Value;
            int dummy;
            IntPtr infoPtr = XGetVisualInfo(display, 1 /* VisualInfoMask.ID */, ref info, out dummy);
            info = (XVisualInfo)Marshal.PtrToStructure(infoPtr, typeof(XVisualInfo));
            // set the X11 colormap.
            SetStaticFieldValue(xplatui, "CustomVisual", info.Visual);
            SetStaticFieldValue(xplatui, "CustomColormap", XCreateColormap(display, rootWindow, info.Visual, 0));
            window_info = Utilities.CreateX11WindowInfo(display, screen, control.Handle, rootWindow, infoPtr);
            

        }
示例#2
0
 static extern IntPtr XGetVisualInfoInternal(IntPtr display, IntPtr vinfo_mask, ref XVisualInfo template, out int nitems);
示例#3
0
        // Called when the widget needs to be (fully or partially) redrawn.
        protected override bool OnExposeEvent(Gdk.EventExpose eventExpose)
        {
            if (!initialized)
            {
                initialized = true;

                // If this looks uninitialized...  initialize.
                if (ColorBPP == 0)
                {
                    ColorBPP = 32;

                    if (DepthBPP == 0)
                    {
                        DepthBPP = 16;
                    }
                }

                ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP);

                ColorFormat accumulationColorFormat = new ColorFormat(AccumulatorBPP);

                int buffers = 2;
                if (SingleBuffer)
                {
                    buffers--;
                }

                GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);

                // IWindowInfo
                if (Configuration.RunningOnWindows)
                {
                    IntPtr windowHandle = gdk_win32_drawable_get_handle(GdkWindow.Handle);
                    windowInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(windowHandle);
                }
                else if (Configuration.RunningOnMacOS)
                {
                    IntPtr windowHandle = gdk_quartz_window_get_nswindow(GdkWindow.Handle);
                    IntPtr contentView  = gdk_quartz_window_get_nsview(GdkWindow.Handle);

                    // Problem: gdk_window_ensure_native() crashes when used more than once.
                    // For now, just create a NSView in place and use that instead.
                    // Needs some care updating when resizing, hiding, etc, but seems to work.
                    // (I'd guess this is pretty much what gdk_window_ensure_native() does internally.)

                    var customView = Class.AllocateClass("CustomNSView" + uniqueId++, "NSView");
                    //Class.RegisterMethod(windowClass, new WindowKeyDownDelegate(WindowKeyDown), "keyDown:", "v@:@");
                    //Class.RegisterMethod(customView, new OnHitTestDelegate(OnHitTest), "hitTest:", "@@:{NSPoint=ff}");
                    Class.RegisterMethod(customView, new OnMouseDownDelegate(OnMouseDown), "mouseDown:", "v@:@");
                    Class.RegisterMethod(customView, new OnMouseDraggedDelegate(OnMouseDragged), "mouseDragged:", "v@:@");
                    Class.RegisterMethod(customView, new OnMouseUpDelegate(OnMouseUp), "mouseUp:", "v@:@");

                    Class.RegisterClass(customView);

                    nsView = SendIntPtr(SendIntPtr(customView, sel_registerName("alloc")), sel_registerName("initWithFrame:"), new RectangleF(0, 0, 100, 100));
                    SendVoid(contentView, sel_registerName("addSubview:"), nsView);


//					bool native = gdk_window_ensure_native(GdkWindow.Handle);
//					if (!native)
//					{
//						throw new PlatformNotSupportedException("Could not create native view.");
//					}
//
//					nsView = gdk_quartz_window_get_nsview(GdkWindow.Handle);

                    windowInfo = OpenTK.Platform.Utilities.CreateMacOSWindowInfo(windowHandle, nsView);
                    UpdateNSView();
                }
                else if (Configuration.RunningOnX11)
                {
                    IntPtr display      = gdk_x11_display_get_xdisplay(Display.Handle);
                    int    screen       = Screen.Number;
                    IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle);
                    IntPtr rootWindow   = gdk_x11_drawable_get_xid(RootWindow.Handle);

                    IntPtr visualInfo;
                    if (graphicsMode.Index.HasValue)
                    {
                        XVisualInfo info = new XVisualInfo();
                        info.VisualID = graphicsMode.Index.Value;
                        int dummy;
                        visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy);
                    }
                    else
                    {
                        visualInfo = GetVisualInfo(display);
                    }

                    windowInfo = OpenTK.Platform.Utilities.CreateX11WindowInfo(display, screen, windowHandle, rootWindow, visualInfo);
                    XFree(visualInfo);
                }
                else
                {
                    throw new PlatformNotSupportedException();
                }

                // GraphicsContext
                graphicsContext = new GraphicsContext(graphicsMode, windowInfo, GlVersionMajor, GlVersionMinor, graphicsContextFlags);
                graphicsContext.MakeCurrent(windowInfo);

                if (GraphicsContext.ShareContexts)
                {
                    Interlocked.Increment(ref graphicsContextCount);

                    if (!sharedContextInitialized)
                    {
                        sharedContextInitialized = true;
                        ((IGraphicsContextInternal)graphicsContext).LoadAll();
                        OnGraphicsContextInitialized();
                    }
                }
                else
                {
                    ((IGraphicsContextInternal)graphicsContext).LoadAll();
                    OnGraphicsContextInitialized();
                }

                OnInitialized();
            }
            else
            {
                try                 // Hack: Fix crash when returning from sleep mode on windows, using nvidia drivers. See: http://www.opentk.com/node/2634
                {
                    graphicsContext.MakeCurrent(windowInfo);
                }
                catch
                {
                }
            }

            bool result = base.OnExposeEvent(eventExpose);

            OnRenderFrame();
            eventExpose.Window.Display.Sync();             // Add Sync call to fix resize rendering problem (Jay L. T. Cornwall) - How does this affect VSync?
            graphicsContext.SwapBuffers();
            return(result);
        }
示例#4
0
 static public extern IntPtr XGetVisualInfo(IntPtr display, IntPtr vinfo_mask, ref XVisualInfo vinfo_template, out int nitems_return);
 static extern IntPtr XGetVisualInfoInternal(IntPtr display, IntPtr vinfo_mask, ref XVisualInfo template, out int nitems);
        /// <summary>
        /// Create Graphcis Context
        /// </summary>
        /// <returns></returns>
        public bool CreateGraphicsContext()
        {
            // If this looks uninitialized...  initialize.
            if (ColorBPP == 0)
            {
                ColorBPP = 32;

                if (DepthBPP == 0) DepthBPP = 16;
            }

            ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP);

            ColorFormat accumulationColorFormat = new ColorFormat(AccumulatorBPP);

            int buffers = 2;
            if (SingleBuffer) buffers--;

            GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);

            #if MAC
            IntPtr windowHandle = gdk_quartz_window_get_nswindow(GdkWindow.Handle);

            // Problem: gdk_window_ensure_native() crashes when used more than once.
            // For now, just create a NSView in place and use that instead.
            // Needs some care updating when resizing, hiding, etc, but seems to work.
            // (I'd guess this is pretty much what gdk_window_ensure_native() does internally.)

            var customView = NativeClass.AllocateClass("CustomNSView" + uniqueId++, "NSView");
            NativeClass.RegisterClass(customView);

            nsView = SendIntPtr(SendIntPtr(customView, sel_registerName("alloc")), sel_registerName("initWithFrame:"), new RectangleF(0, 0, 400, 400));

            bool native = gdk_window_ensure_native(GdkWindow.Handle);
            if (!native)
            {
                throw new PlatformNotSupportedException("Could not create native view.");
            }

            nsView = gdk_quartz_window_get_nsview(GdkWindow.Handle);

            windowInfo = OpenTK.Platform.Utilities.CreateMacOSWindowInfo(windowHandle, nsView);
            UpdateNSView();
            #elif LINUX
                IntPtr display = gdk_x11_display_get_xdisplay(Display.Handle);
                int screen = Screen.Number;
                IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle);
                IntPtr rootWindow = gdk_x11_drawable_get_xid(RootWindow.Handle);

                IntPtr visualInfo;
                if (graphicsMode.Index.HasValue)
                {
                    XVisualInfo info = new XVisualInfo();
                    info.VisualID = graphicsMode.Index.Value;
                    int dummy;
                    visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy);
                }
                else
                {
                    visualInfo = GetVisualInfo(display);
                }

                windowInfo = OpenTK.Platform.Utilities.CreateX11WindowInfo(display, screen, windowHandle, rootWindow, visualInfo);
                XFree(visualInfo);
            #endif

            // GraphicsContext
            graphicsContext = new GraphicsContext(graphicsMode, windowInfo, GlVersionMajor, GlVersionMinor, graphicsContextFlags);
            graphicsContext.MakeCurrent(windowInfo);

            if (GraphicsContext.ShareContexts)
            {
                Interlocked.Increment(ref graphicsContextCount);

                if (!sharedContextInitialized)
                {
                    sharedContextInitialized = true;
                    ((IGraphicsContextInternal)graphicsContext).LoadAll();
                    OnGraphicsContextInitialized();
                }
            }
            else
            {
                ((IGraphicsContextInternal)graphicsContext).LoadAll();
                OnGraphicsContextInitialized();
            }

            this.OnInitialized(this, null);

            this.timerId = GLib.Timeout.Add(16, new GLib.TimeoutHandler(this.Render));

            return false;
        }
示例#7
0
        public X11GLNative(int x, int y, int width, int height, string title,
            GraphicsMode mode,GameWindowFlags options, DisplayDevice device)
            : this()
        {
            if (width <= 0)
                throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
            if (height <= 0)
                throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");

            XVisualInfo info = new XVisualInfo();

            Debug.Indent();

            lock (API.Lock)
            {
                if (!mode.Index.HasValue)
                    throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");

                info.VisualID = mode.Index.Value;
                int dummy;
                window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(
                    Functions.XGetVisualInfo(window.Display, XVisualInfoMask.ID, ref info, out dummy), typeof(XVisualInfo));

                // Create a window on this display using the visual above
                Debug.Write("Opening render window... ");

                XSetWindowAttributes attributes = new XSetWindowAttributes();
                attributes.background_pixel = IntPtr.Zero;
                attributes.border_pixel = IntPtr.Zero;
                attributes.colormap = Functions.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0/*AllocNone*/);
                window.EventMask = EventMask.StructureNotifyMask | EventMask.SubstructureNotifyMask | EventMask.ExposureMask |
                                   EventMask.KeyReleaseMask | EventMask.KeyPressMask |
                                   EventMask.PointerMotionMask | EventMask.FocusChangeMask |
                                   EventMask.ButtonPressMask | EventMask.ButtonReleaseMask;
                attributes.event_mask = (IntPtr)window.EventMask;

                uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask |
                    (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel;

                window.WindowHandle = Functions.XCreateWindow(window.Display, window.RootWindow,
                    x, y, width, height, 0, window.VisualInfo.Depth/*(int)CreateWindowArgs.CopyFromParent*/,
                    (int)CreateWindowArgs.InputOutput, window.VisualInfo.Visual, (UIntPtr)mask, ref attributes);

                if (window.WindowHandle == IntPtr.Zero)
                    throw new ApplicationException("XCreateWindow call failed (returned 0).");
            }

            // Set the window hints
            SetWindowMinMax(_min_width, _min_height, -1, -1);

            XSizeHints hints = new XSizeHints();
            hints.base_width = width;
            hints.base_height = height;
            hints.flags = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition);
            lock (API.Lock)
            {
                Functions.XSetWMNormalHints(window.Display, window.WindowHandle, ref hints);

                // Register for window destroy notification
                Functions.XSetWMProtocols(window.Display, window.WindowHandle, new IntPtr[] { _atom_wm_destroy }, 1);

                API.MapRaised(window.Display, window.WindowHandle);
            }

            driver = new X11Input(window);

            Debug.WriteLine(String.Format("X11GLNative window created successfully (id: {0}).", Handle));
            Debug.Unindent();

            exists = true;
        }
        public X11GLNative(int x, int y, int width, int height, string title,
            GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
        {
            if (width <= 0)
                throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
            if (height <= 0)
                throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");

            Debug.Print("Creating X11GLNative window.");
            // Open a display connection to the X server, and obtain the screen and root window.
            window.Display = API.DefaultDisplay;
            window.Screen = API.XDefaultScreen(window.Display); //API.DefaultScreen;
            window.RootWindow = API.XRootWindow(window.Display, window.Screen); // API.RootWindow;

            Debug.Print("Display: {0}, Screen {1}, Root window: {2}", window.Display, window.Screen, window.RootWindow);
            RegisterAtoms(window);
            XVisualInfo info = new XVisualInfo();
            mode = X11GLContext.SelectGraphicsMode( mode, out info );
            window.VisualInfo = info;
            // Create a window on this display using the visual above
            Debug.Print("Opening render window... ");

            XSetWindowAttributes attributes = new XSetWindowAttributes();
            attributes.background_pixel = IntPtr.Zero;
            attributes.border_pixel = IntPtr.Zero;
            attributes.colormap = API.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0/*AllocNone*/);
            window.EventMask = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask |
                EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask |
                EventMask.PointerMotionMask | EventMask.FocusChangeMask |
                EventMask.ButtonPressMask | EventMask.ButtonReleaseMask |
                EventMask.EnterWindowMask | EventMask.LeaveWindowMask |
                EventMask.PropertyChangeMask;
            attributes.event_mask = (IntPtr)window.EventMask;

            uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask |
                (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel;

            window.WindowHandle = API.XCreateWindow(window.Display, window.RootWindow,
                                                    x, y, width, height, 0, window.VisualInfo.Depth/*(int)CreateWindowArgs.CopyFromParent*/,
                                                    (int)CreateWindowArgs.InputOutput, window.VisualInfo.Visual, (IntPtr)mask, ref attributes);

            if (window.WindowHandle == IntPtr.Zero)
                throw new ApplicationException("XCreateWindow call failed (returned 0).");

            if (title != null)
                API.XStoreName(window.Display, window.WindowHandle, title);

            // Set the window hints
            SetWindowMinMax(_min_width, _min_height, -1, -1);

            XSizeHints hints = new XSizeHints();
            hints.base_width = width;
            hints.base_height = height;
            hints.flags = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition);
            API.XSetWMNormalHints(window.Display, window.WindowHandle, ref hints);
            // Register for window destroy notification
            API.XSetWMProtocols(window.Display, window.WindowHandle, new IntPtr[] { wm_destroy }, 1);

            // Set the initial window size to ensure X, Y, Width, Height and the rest
            // return the correct values inside the constructor and the Load event.
            XEvent e = new XEvent();
            e.ConfigureEvent.x = x;
            e.ConfigureEvent.y = y;
            e.ConfigureEvent.width = width;
            e.ConfigureEvent.height = height;
            RefreshWindowBounds(ref e);

            Debug.Print("X11GLNative window created successfully (id: {0}).", Handle);
            SetupInput();
            exists = true;
        }
示例#9
0
		private IWindowInfo InitializeX(GraphicsMode mode)
		{
			IntPtr display = gdk_x11_display_get_xdisplay(Display.Handle);
			int screen = Screen.Number;

			IntPtr windowHandle = gdk_x11_window_get_xid(Window.Handle);
			IntPtr rootWindow = gdk_x11_window_get_xid(RootWindow.Handle);

			IntPtr visualInfo;
			if (mode.Index.HasValue)
			{
				XVisualInfo info = new XVisualInfo();
				info.VisualID = mode.Index.Value;
				int dummy;
				visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy);
			}
			else
			{
				visualInfo = GetVisualInfo(display);
			}

			IWindowInfo retval = Utilities.CreateX11WindowInfo(display, screen, windowHandle, rootWindow, visualInfo);
			XFree(visualInfo);

			return retval;
		}
示例#10
0
 public static extern IntPtr XGetVisualInfo(IntPtr display, int mask, ref XVisualInfo visInfo, out int nItems);
示例#11
0
文件: Glx.cs 项目: swoolcock/opentk
 public static extern int GetConfig(IntPtr dpy, ref XVisualInfo vis, GLXAttribute attrib, out int value);
示例#12
0
文件: Glx.cs 项目: swoolcock/opentk
 public static extern IntPtr CreateContext(IntPtr dpy, ref XVisualInfo vis, IntPtr shareList, bool direct);
示例#13
0
 public X11GLNative(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
   : this()
 {
   if (width <= 0)
     throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
   if (height <= 0)
     throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");
   XVisualInfo template = new XVisualInfo();
   using (new XLock(this.window.Display))
   {
     if (!mode.Index.HasValue)
       throw new GraphicsModeException("Invalid or unsupported GraphicsMode.");
     template.VisualID = mode.Index.Value;
     int nitems;
     this.window.VisualInfo = (XVisualInfo) Marshal.PtrToStructure(Functions.XGetVisualInfo(this.window.Display, XVisualInfoMask.ID, ref template, out nitems), typeof (XVisualInfo));
     XSetWindowAttributes attributes = new XSetWindowAttributes();
     attributes.background_pixel = IntPtr.Zero;
     attributes.border_pixel = IntPtr.Zero;
     attributes.colormap = Functions.XCreateColormap(this.window.Display, this.window.RootWindow, this.window.VisualInfo.Visual, 0);
     this.window.EventMask = EventMask.KeyPressMask | EventMask.KeyReleaseMask | EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterWindowMask | EventMask.LeaveWindowMask | EventMask.PointerMotionMask | EventMask.KeymapStateMask | EventMask.ExposureMask | EventMask.StructureNotifyMask | EventMask.FocusChangeMask | EventMask.PropertyChangeMask;
     attributes.event_mask = (IntPtr) ((long) this.window.EventMask);
     uint num = 10250U;
     this.window.WindowHandle = Functions.XCreateWindow(this.window.Display, this.window.RootWindow, x, y, width, height, 0, this.window.VisualInfo.Depth, 1, this.window.VisualInfo.Visual, (UIntPtr) num, ref attributes);
     if (this.window.WindowHandle == IntPtr.Zero)
       throw new ApplicationException("XCreateWindow call failed (returned 0).");
     if (title != null)
       Functions.XStoreName(this.window.Display, this.window.WindowHandle, title);
   }
   this.SetWindowMinMax((short) 30, (short) 30, (short) -1, (short) -1);
   XSizeHints hints = new XSizeHints();
   hints.base_width = width;
   hints.base_height = height;
   hints.flags = (IntPtr) 12L;
   using (new XLock(this.window.Display))
   {
     Functions.XSetWMNormalHints(this.window.Display, this.window.WindowHandle, ref hints);
     Functions.XSetWMProtocols(this.window.Display, this.window.WindowHandle, new IntPtr[1]
     {
       this._atom_wm_destroy
     }, 1);
   }
   this.RefreshWindowBounds(ref new XEvent()
   {
     ConfigureEvent = {
       x = x,
       y = y,
       width = width,
       height = height
     }
   });
   this.driver = new X11Input((IWindowInfo) this.window);
   this.mouse = this.driver.Mouse[0];
   this.EmptyCursor = X11GLNative.CreateEmptyCursor(this.window);
   this.exists = true;
 }
示例#14
0
 static IntPtr XGetVisualInfo(IntPtr display, XVisualInfoMask vinfo_mask, ref XVisualInfo template, out int nitems)
 {
     return(XGetVisualInfoInternal(display, (IntPtr)(int)vinfo_mask, ref template, out nitems));
 }
        void HandleRealized(object sender, EventArgs eventArgs)
        {
            if (renderingContextHandle.Handle != IntPtr.Zero)
            {
                return;
            }

            switch (platformID)
            {
            case PlatformID.Win32NT:
            case PlatformID.Win32S:
            case PlatformID.Win32Windows:
            case PlatformID.WinCE:
                LoadLibrary("opengl32.dll");

                IntPtr windowHandle  = gdk_win32_drawable_get_handle(GdkWindow.Handle);
                IntPtr deviceContext = GetDC(windowHandle);

                PIXELFORMATDESCRIPTOR pixelFormatDescriptor = new PIXELFORMATDESCRIPTOR();
                pixelFormatDescriptor.nSize      = (short)System.Runtime.InteropServices.Marshal.SizeOf(pixelFormatDescriptor);
                pixelFormatDescriptor.nVersion   = 1;
                pixelFormatDescriptor.iPixelType = PFD_TYPE_RGBA;
                pixelFormatDescriptor.dwFlags    = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
                if (doubleBuffer)
                {
                    pixelFormatDescriptor.dwFlags |= PFD_DOUBLEBUFFER;
                }
                pixelFormatDescriptor.cColorBits   = colorBits;
                pixelFormatDescriptor.cAlphaBits   = alphaBits;
                pixelFormatDescriptor.cDepthBits   = depthBits;
                pixelFormatDescriptor.cStencilBits = stencilBits;

                int pixelFormat = ChoosePixelFormat(deviceContext, ref pixelFormatDescriptor);
                if (!SetPixelFormat(deviceContext, pixelFormat, ref pixelFormatDescriptor))
                {
                    throw new Exception("Cannot SetPixelFormat!");
                }

                IntPtr renderingContext = wglCreateContext(deviceContext);
                renderingContextHandle = new HandleRef(this, renderingContext);

                ReleaseDC(windowHandle, deviceContext);

                if (sharedContextWidget != null)
                {
                    GLWidget primaryWidget = sharedContextWidget;
                    while (primaryWidget.sharedContextWidget != null)
                    {
                        primaryWidget = primaryWidget.sharedContextWidget;
                    }

                    if (primaryWidget.RenderingContextHandle.Handle != IntPtr.Zero)
                    {
                        wglShareLists(primaryWidget.RenderingContextHandle.Handle, RenderingContextHandle.Handle);
                    }
                    else
                    {
                        this.sharedContextWidget          = null;
                        primaryWidget.sharedContextWidget = this;
                    }
                }

                break;

            case PlatformID.Unix:
            default:
                int[] attributeList  = new int[24];
                int   attributeIndex = 0;

                attributeList[attributeIndex++] = GLX_RGBA;
                if (doubleBuffer)
                {
                    attributeList[attributeIndex++] = GLX_DOUBLEBUFFER;
                }

                attributeList[attributeIndex++] = GLX_RED_SIZE;
                attributeList[attributeIndex++] = 1;

                attributeList[attributeIndex++] = GLX_GREEN_SIZE;
                attributeList[attributeIndex++] = 1;

                attributeList[attributeIndex++] = GLX_BLUE_SIZE;
                attributeList[attributeIndex++] = 1;

                if (alphaBits != 0)
                {
                    attributeList[attributeIndex++] = GLX_ALPHA_SIZE;
                    attributeList[attributeIndex++] = 1;
                }

                if (depthBits != 0)
                {
                    attributeList[attributeIndex++] = GLX_DEPTH_SIZE;
                    attributeList[attributeIndex++] = 1;
                }

                if (stencilBits != 0)
                {
                    attributeList[attributeIndex++] = GLX_STENCIL_SIZE;
                    attributeList[attributeIndex++] = 1;
                }

                attributeList[attributeIndex++] = GLX_NONE;

                IntPtr xDisplay     = gdk_x11_display_get_xdisplay(Screen.Display.Handle);
                IntPtr visualIntPtr = IntPtr.Zero;

                try
                {
                    visualIntPtr = glXChooseVisual(xDisplay, Screen.Number, attributeList);
                }
                catch (DllNotFoundException e)
                {
                    throw new Exception("OpenGL dll not found!", e);
                }
                catch (EntryPointNotFoundException enf)
                {
                    throw new Exception("Glx entry point not found!", enf);
                }

                if (visualIntPtr == IntPtr.Zero)
                {
                    throw new Exception("Visual");
                }

                XVisualInfo xVisualInfo = (XVisualInfo)Marshal.PtrToStructure(visualIntPtr, typeof(XVisualInfo));

                IntPtr xRenderingContext = IntPtr.Zero;


                if (sharedContextWidget != null)
                {
                    GLWidget primaryWidget = sharedContextWidget;
                    while (primaryWidget.sharedContextWidget != null)
                    {
                        primaryWidget = primaryWidget.sharedContextWidget;
                    }

                    if (primaryWidget.RenderingContextHandle.Handle != IntPtr.Zero)
                    {
                        xRenderingContext = glXCreateContext(xDisplay, visualIntPtr, primaryWidget.RenderingContextHandle, true);
                    }
                    else
                    {
                        xRenderingContext                 = glXCreateContext(xDisplay, visualIntPtr, new HandleRef(null, IntPtr.Zero), true);
                        this.sharedContextWidget          = null;
                        primaryWidget.sharedContextWidget = this;
                    }
                }
                else
                {
                    xRenderingContext = glXCreateContext(xDisplay, visualIntPtr, new HandleRef(null, IntPtr.Zero), true);
                }

                if (xRenderingContext == IntPtr.Zero)
                {
                    throw new Exception("Unable to create rendering context");
                }

                renderingContextHandle = new HandleRef(this, xRenderingContext);

                visual = (Gdk.Visual)GLib.Object.GetObject(gdk_x11_screen_lookup_visual(Screen.Handle, xVisualInfo.visualid));

                if (visualIntPtr != IntPtr.Zero)
                {
                    XFree(visualIntPtr);
                }
                break;
            }
        }
示例#16
0
        public X11GLNative(int x, int y, int width, int height, string title,
            GraphicsMode mode,GameWindowFlags options, DisplayDevice device)
            : this()
        {
            if (width <= 0)
                throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
            if (height <= 0)
                throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");

            XVisualInfo info = new XVisualInfo();

            Debug.Indent();
            
            using (new XLock(window.Display))
            {
                if (!mode.Index.HasValue)
                {
                    mode = new X11GraphicsMode().SelectGraphicsMode(
                        mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
                        mode.AccumulatorFormat, mode.Buffers, mode.Stereo);
                }

                info.VisualID = mode.Index.Value;
                int dummy;
                window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(
                    Functions.XGetVisualInfo(window.Display, XVisualInfoMask.ID, ref info, out dummy), typeof(XVisualInfo));

                // Create a window on this display using the visual above
                Debug.Write("Opening render window... ");

                XSetWindowAttributes attributes = new XSetWindowAttributes();
                attributes.background_pixel = IntPtr.Zero;
                attributes.border_pixel = IntPtr.Zero;
                attributes.colormap = Functions.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0/*AllocNone*/);
                window.EventMask = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask |
                                   EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask |
                                   EventMask.PointerMotionMask | EventMask.FocusChangeMask |
                                   EventMask.ButtonPressMask | EventMask.ButtonReleaseMask |
                                   EventMask.EnterWindowMask | EventMask.LeaveWindowMask |
                                   EventMask.PropertyChangeMask;
                attributes.event_mask = (IntPtr)window.EventMask;

                uint mask = (uint)SetWindowValuemask.ColorMap | (uint)SetWindowValuemask.EventMask |
                    (uint)SetWindowValuemask.BackPixel | (uint)SetWindowValuemask.BorderPixel;

                window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow,
                    x, y, width, height, 0, window.VisualInfo.Depth/*(int)CreateWindowArgs.CopyFromParent*/,
                    (int)CreateWindowArgs.InputOutput, window.VisualInfo.Visual, (UIntPtr)mask, ref attributes);

                if (window.Handle == IntPtr.Zero)
                    throw new ApplicationException("XCreateWindow call failed (returned 0).");

                if (title != null)
                    Functions.XStoreName(window.Display, window.Handle, title);
            }

            // Set the window hints
            SetWindowMinMax(_min_width, _min_height, -1, -1);            
            
            XSizeHints hints = new XSizeHints();
            hints.base_width = width;
            hints.base_height = height;
            hints.flags = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition);
            using (new XLock(window.Display))
            {
                Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints);

                // Register for window destroy notification
                Functions.XSetWMProtocols(window.Display, window.Handle, new IntPtr[] { _atom_wm_destroy }, 1);
            }

            // Set the initial window size to ensure X, Y, Width, Height and the rest
            // return the correct values inside the constructor and the Load event.
            XEvent e = new XEvent();
            e.ConfigureEvent.x = x;
            e.ConfigureEvent.y = y;
            e.ConfigureEvent.width = width;
            e.ConfigureEvent.height = height;
            RefreshWindowBounds(ref e);

            driver = new X11Input(window);
            keyboard = driver.Keyboard[0];
            mouse = driver.Mouse[0];

            EmptyCursor = CreateEmptyCursor(window);

            Debug.WriteLine(String.Format("X11GLNative window created successfully (id: {0}).", Handle));
            Debug.Unindent();

            exists = true;
        }
示例#17
0
文件: XLib.cs 项目: wjk/Avalonia
 public static extern void XMatchVisualInfo(IntPtr display, int screen, int depth, int klass, out XVisualInfo info);
示例#18
0
        public IGraphicsContext CreateContext(int major, int minor, GraphicsContextFlags flags)
        {
            GraphicsContext context =  new GraphicsContext(mode, this.WindowInfo, major, minor, flags);
            mode = context.GraphicsMode;

            // get the XVisualInfo for this GraphicsMode
            XVisualInfo info = new XVisualInfo();
            info.VisualID = mode.Index.Value;
            int dummy;
            IntPtr infoPtr = XGetVisualInfo(display, 1 /* VisualInfoMask.ID */, ref info, out dummy);
            info = (XVisualInfo)Marshal.PtrToStructure(infoPtr, typeof(XVisualInfo));

            // set the X11 colormap.
            // Note: this only affects windows created in the future
            // (do we even need this here?)
            SetStaticFieldValue(xplatui, "CustomVisual", info.Visual);
            SetStaticFieldValue(xplatui, "CustomColormap", XCreateColormap(display, rootWindow, info.Visual, 0));

            return context;
        }
        private void SetupWindowInfo()
        {
            // IWindowInfo
            var platform = DetectPlatform();
            if (platform == "Windows")
            {
                IntPtr windowHandle = gdk_win32_drawable_get_handle(GdkWindow.Handle);
                windowInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(windowHandle);
            }
            else if (platform == "MacOS")
            {
                IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle);
                bool ownHandle = true;
                bool isControl = true;
                windowInfo = OpenTK.Platform.Utilities.CreateMacOSCarbonWindowInfo(windowHandle, ownHandle, isControl);
            }
            else if (platform == "Linux")
            {
                XSetErrorHandler((a, b) =>
                {
                    Console.WriteLine("Got X window system error; resetting initialized status.");
                    initialized = false;
                    return IntPtr.Zero;
                });

                IntPtr display = gdk_x11_display_get_xdisplay(Display.Handle);
                int screen = Screen.Number;
                IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle);
                IntPtr rootWindow = gdk_x11_drawable_get_xid(RootWindow.Handle);

                IntPtr visualInfo;
                if (graphicsMode.Index.HasValue)
                {
                    XVisualInfo info = new XVisualInfo();
                    info.VisualID = graphicsMode.Index.Value;
                    int dummy;
                    visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy);
                }
                else
                {
                    visualInfo = GetVisualInfo(display);
                }

                windowInfo = OpenTK.Platform.Utilities.CreateX11WindowInfo(display, screen, windowHandle, rootWindow, visualInfo);
                XFree(visualInfo);
            }
            else throw new PlatformNotSupportedException();
        }
示例#20
0
        // Called when the widget needs to be (fully or partially) redrawn.
        protected override bool OnExposeEvent(Gdk.EventExpose eventExpose)
        {
            if (!initialized) {
                initialized = true;

                // If this looks uninitialized...  initialize.
                if (ColorBPP == 0) {
                    ColorBPP = 32;

                    if (DepthBPP == 0)
                        DepthBPP = 16;
                }

                ColorFormat colorBufferColorFormat = new ColorFormat (ColorBPP);

                ColorFormat accumulationColorFormat = new ColorFormat (AccumulatorBPP);

                int buffers = 2;
                if (SingleBuffer)
                    buffers--;

                GraphicsMode graphicsMode = new GraphicsMode (colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);

                // IWindowInfo
                if (Configuration.RunningOnWindows) {
                    IntPtr windowHandle = gdk_win32_drawable_get_handle (GdkWindow.Handle);
                    windowInfo = Utilities.CreateWindowsWindowInfo (windowHandle);
                } else if (Configuration.RunningOnMacOS) {
                    IntPtr windowHandle = gdk_x11_drawable_get_xid (GdkWindow.Handle);
                    const bool ownHandle = true;
                    const bool isControl = true;
                    windowInfo = Utilities.CreateMacOSCarbonWindowInfo (windowHandle, ownHandle, isControl);
                } else if (Configuration.RunningOnX11) {
                    IntPtr display = gdk_x11_display_get_xdisplay (Display.Handle);
                    int screen = Screen.Number;
                    IntPtr windowHandle = gdk_x11_drawable_get_xid (GdkWindow.Handle);
                    IntPtr rootWindow = gdk_x11_drawable_get_xid (RootWindow.Handle);

                    IntPtr visualInfo;
                    if (graphicsMode.Index.HasValue) {
                        XVisualInfo info = new XVisualInfo ();
                        info.VisualID = graphicsMode.Index.Value;
                        int dummy;
                        visualInfo = XGetVisualInfo (display, XVisualInfoMask.ID, ref info, out dummy);
                    } else {
                        visualInfo = GetVisualInfo (display);
                    }

                    windowInfo = Utilities.CreateX11WindowInfo (display, screen, windowHandle, rootWindow, visualInfo);
                    XFree (visualInfo);
                } else
                    throw new PlatformNotSupportedException ();

                // GraphicsContext
                graphicsContext = new GraphicsContext (graphicsMode, windowInfo, GlVersionMajor, GlVersionMinor, GraphicsContextFlags);
                graphicsContext.MakeCurrent (windowInfo);

                if (GraphicsContext.ShareContexts) {
                    Interlocked.Increment (ref graphicsContextCount);

                    if (!sharedContextInitialized) {
                        sharedContextInitialized = true;
                        ((IGraphicsContextInternal)graphicsContext).LoadAll ();
                        OnGraphicsContextInitialized ();
                    }
                } else {
                    ((IGraphicsContextInternal)graphicsContext).LoadAll ();
                    OnGraphicsContextInitialized ();
                }

                OnInitialized ();
            } else {
                graphicsContext.MakeCurrent (windowInfo);
            }

            bool result = base.OnExposeEvent (eventExpose);
            OnRenderFrame ();
            eventExpose.Window.Display.Sync (); // Add Sync call to fix resize rendering problem (Jay L. T. Cornwall) - How does this affect VSync?
            graphicsContext.SwapBuffers ();
            return result;
        }
示例#21
0
        // Called when the widget needs to be (fully or partially) redrawn.
        protected override bool OnExposeEvent(Gdk.EventExpose eventExpose)
        {
            if (!initialized)
            {
                initialized = true;

                // If this looks uninitialized...  initialize.
                if (ColorBPP == 0)
                {
                    ColorBPP = 32;

                    if (DepthBPP == 0)
                    {
                        DepthBPP = 16;
                    }
                }

                ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP);

                ColorFormat accumulationColorFormat = new ColorFormat(AccumulatorBPP);

                int buffers = 2;
                if (SingleBuffer)
                {
                    buffers--;
                }

                GraphicsMode graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);

                // IWindowInfo
                if (Configuration.RunningOnWindows)
                {
                    IntPtr windowHandle = gdk_win32_drawable_get_handle(GdkWindow.Handle);
                    windowInfo = OpenTK.Platform.Utilities.CreateWindowsWindowInfo(windowHandle);
                }
                else if (Configuration.RunningOnMacOS)
                {
                    IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle);
                    bool   ownHandle    = true;
                    bool   isControl    = true;
                    windowInfo = OpenTK.Platform.Utilities.CreateMacOSCarbonWindowInfo(windowHandle, ownHandle, isControl);
                }
                else if (Configuration.RunningOnX11)
                {
                    IntPtr display      = gdk_x11_display_get_xdisplay(Display.Handle);
                    int    screen       = Screen.Number;
                    IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle);
                    IntPtr rootWindow   = gdk_x11_drawable_get_xid(RootWindow.Handle);

                    IntPtr visualInfo;
                    if (graphicsMode.Index.HasValue)
                    {
                        XVisualInfo info = new XVisualInfo();
                        info.VisualID = graphicsMode.Index.Value;
                        int dummy;
                        visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy);
                    }
                    else
                    {
                        visualInfo = GetVisualInfo(display);
                    }

                    windowInfo = OpenTK.Platform.Utilities.CreateX11WindowInfo(display, screen, windowHandle, rootWindow, visualInfo);
                    XFree(visualInfo);
                }
                else
                {
                    throw new PlatformNotSupportedException();
                }

                // GraphicsContext
                graphicsContext = new GraphicsContext(graphicsMode, windowInfo, GlVersionMajor, GlVersionMinor, graphicsContextFlags);
                graphicsContext.MakeCurrent(windowInfo);

                if (GraphicsContext.ShareContexts)
                {
                    Interlocked.Increment(ref graphicsContextCount);

                    if (!sharedContextInitialized)
                    {
                        sharedContextInitialized = true;
                        ((IGraphicsContextInternal)graphicsContext).LoadAll();
                        OnGraphicsContextInitialized();
                    }
                }
                else
                {
                    ((IGraphicsContextInternal)graphicsContext).LoadAll();
                    OnGraphicsContextInitialized();
                }

                OnInitialized();
            }
            else
            {
                graphicsContext.MakeCurrent(windowInfo);
            }

            bool result = base.OnExposeEvent(eventExpose);

            OnRenderFrame();
            eventExpose.Window.Display.Sync();             // Add Sync call to fix resize rendering problem (Jay L. T. Cornwall) - How does this affect VSync?
            graphicsContext.SwapBuffers();
            return(result);
        }
 static IntPtr XGetVisualInfo(IntPtr display, XVisualInfoMask vinfo_mask, ref XVisualInfo template, out int nitems)
 {
     return XGetVisualInfoInternal(display, (IntPtr)(int)vinfo_mask, ref template, out nitems);
 }
示例#23
0
        public static System.Drawing.Bitmap CopyFromScreenX11(int sourceX, int sourceY,
                                                              System.Drawing.Size blockRegionSize
                                                              , System.Drawing.CopyPixelOperation copyPixelOperation)
        {
            System.UIntPtr window;
            System.IntPtr  image, defvisual, vPtr;
            int            AllPlanes = ~0, nitems = 0, pixel;

            System.UIntPtr AllPlanes2 = new System.UIntPtr((uint)AllPlanes);


            if (copyPixelOperation != System.Drawing.CopyPixelOperation.SourceCopy)
            {
                throw new System.NotImplementedException("Operation not implemented under X11");
            }

            if (Gdip.Display == System.IntPtr.Zero)
            {
                Gdip.Display = LibX11Functions.XOpenDisplay(System.IntPtr.Zero);
            }

            window    = LibX11Functions.XRootWindow(Gdip.Display, 0);
            defvisual = LibX11Functions.XDefaultVisual(Gdip.Display, 0);
            XVisualInfo visual = new XVisualInfo();

            // Get XVisualInfo for this visual
            visual.visualid = LibX11Functions.XVisualIDFromVisual(defvisual);
            vPtr            = LibX11Functions.XGetVisualInfo(Gdip.Display, VisualIDMask, ref visual, ref nitems);
            visual          = (XVisualInfo)System.Runtime.InteropServices.Marshal.PtrToStructure(vPtr, typeof(XVisualInfo));
            image           = LibX11Functions.XGetImage(Gdip.Display, window, sourceX, sourceY, (uint)blockRegionSize.Width,
                                                        (uint)blockRegionSize.Height, AllPlanes2, ZPixmap);
            if (image == System.IntPtr.Zero)
            {
                string s = string.Format("XGetImage returned NULL when asked to for a {0}x{1} region block",
                                         blockRegionSize.Width, blockRegionSize.Height);
                throw new System.InvalidOperationException(s);
            }

            System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(blockRegionSize.Width, blockRegionSize.Height);
            int red, blue, green;
            int red_mask = (int)visual.red_mask;
            int blue_mask  = (int)visual.blue_mask;
            int green_mask = (int)visual.green_mask;

            for (int y = 0; y < blockRegionSize.Height; y++)
            {
                for (int x = 0; x < blockRegionSize.Width; x++)
                {
                    pixel = LibX11Functions.XGetPixel(image, x, y);

                    switch (visual.depth)
                    {
                    case 16:     /* 16bbp pixel transformation */
                        red   = (int)((pixel & red_mask) >> 8) & 0xff;
                        green = (int)(((pixel & green_mask) >> 3)) & 0xff;
                        blue  = (int)((pixel & blue_mask) << 3) & 0xff;
                        break;

                    case 24:
                    case 32:
                        // int a = (int)((pixel ) >> 24) & 0xff;
                        red   = (int)((pixel & red_mask) >> 16) & 0xff;
                        green = (int)(((pixel & green_mask) >> 8)) & 0xff;
                        blue  = (int)((pixel & blue_mask)) & 0xff;
                        break;

                    default:
                        string text = string.Format("{0}bbp depth not supported.", visual.depth);
                        throw new System.NotImplementedException(text);
                    }

                    bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(255, red, green, blue));
                }
            }

            // DrawImage(bmp, destinationX, destinationY);
            // bmp.Dispose();
            LibX11Functions.XDestroyImage(image);
            LibX11Functions.XFree(vPtr);

            return(bmp);
        }
示例#24
0
        public X11GLNative(int x, int y, int width, int height, string title,
            GraphicsMode mode,GameWindowFlags options, DisplayDevice device)
            : this()
        {
            if (width <= 0)
                throw new ArgumentOutOfRangeException("width", "Must be higher than zero.");
            if (height <= 0)
                throw new ArgumentOutOfRangeException("height", "Must be higher than zero.");

            XVisualInfo info = new XVisualInfo();

            Debug.Indent();
            
            using (new XLock(window.Display))
            {
                if (!mode.Index.HasValue)
                {
                    mode = new X11GraphicsMode().SelectGraphicsMode(
                        mode.ColorFormat, mode.Depth, mode.Stencil, mode.Samples,
                        mode.AccumulatorFormat, mode.Buffers, mode.Stereo);
                }

                info.VisualID = mode.Index.Value;
                int dummy;
                window.VisualInfo = (XVisualInfo)Marshal.PtrToStructure(
                    Functions.XGetVisualInfo(window.Display, XVisualInfoMask.ID, ref info, out dummy), typeof(XVisualInfo));

                // Create a window on this display using the visual above
                Debug.Write("Opening render window... ");

                XSetWindowAttributes attributes = new XSetWindowAttributes();
                attributes.background_pixel = IntPtr.Zero;
                attributes.border_pixel = IntPtr.Zero;
                attributes.colormap = Functions.XCreateColormap(window.Display, window.RootWindow, window.VisualInfo.Visual, 0/*AllocNone*/);
                window.EventMask = EventMask.StructureNotifyMask /*| EventMask.SubstructureNotifyMask*/ | EventMask.ExposureMask |
                                   EventMask.KeyReleaseMask | EventMask.KeyPressMask | EventMask.KeymapStateMask |
                                   EventMask.PointerMotionMask | EventMask.FocusChangeMask |
                                   EventMask.ButtonPressMask | EventMask.ButtonReleaseMask |
                                   EventMask.EnterWindowMask | EventMask.LeaveWindowMask |
                                   EventMask.PropertyChangeMask;
                attributes.event_mask = (IntPtr)window.EventMask;

                SetWindowValuemask mask =
                    SetWindowValuemask.ColorMap | SetWindowValuemask.EventMask |
                    SetWindowValuemask.BackPixel | SetWindowValuemask.BorderPixel;

                window.Handle = Functions.XCreateWindow(window.Display, window.RootWindow,
                    x, y, width, height, 0, window.VisualInfo.Depth/*(int)CreateWindowArgs.CopyFromParent*/,
                    CreateWindowArgs.InputOutput, window.VisualInfo.Visual, mask, attributes);

                if (window.Handle == IntPtr.Zero)
                    throw new ApplicationException("XCreateWindow call failed (returned 0).");

                if (title != null)
                    Functions.XStoreName(window.Display, window.Handle, title);
            }

            XSizeHints hints = new XSizeHints();
            hints.base_width = width;
            hints.base_height = height;
            hints.flags = (IntPtr)(XSizeHintsFlags.PSize | XSizeHintsFlags.PPosition);

            XClassHint class_hint = new XClassHint();
            class_hint.Name = Assembly.GetEntryAssembly().GetName().Name.ToLower();
            class_hint.Class = Assembly.GetEntryAssembly().GetName().Name;

            using (new XLock(window.Display))
            {
                Functions.XSetWMNormalHints(window.Display, window.Handle, ref hints);

                // Register for window destroy notification
                Functions.XSetWMProtocols(window.Display, window.Handle, new IntPtr[] { _atom_wm_destroy }, 1);

                // Set the window class hints
                Functions.XSetClassHint(window.Display, window.Handle, ref class_hint);
            }

            SetWindowMinMax(_min_width, _min_height, -1, -1);

            // Set the initial window size to ensure X, Y, Width, Height and the rest
            // return the correct values inside the constructor and the Load event.
            XEvent e = new XEvent();
            e.ConfigureEvent.x = x;
            e.ConfigureEvent.y = y;
            e.ConfigureEvent.width = width;
            e.ConfigureEvent.height = height;
            RefreshWindowBounds(ref e);

            EmptyCursor = CreateEmptyCursor(window);

            Debug.WriteLine(String.Format("X11GLNative window created successfully (id: {0}).", Handle));
            Debug.Unindent();

            using (new XLock(window.Display))
            {
                // Request that auto-repeat is only set on devices that support it physically.
                // This typically means that it's turned off for keyboards (which is what we want).
                // We prefer this method over XAutoRepeatOff/On, because the latter needs to
                // be reset before the program exits.
                if (Xkb.IsSupported(window.Display))
                {
                    bool supported;
                    Xkb.SetDetectableAutoRepeat(window.Display, true, out supported);
                }
            }

            // The XInput2 extension makes keyboard and mouse handling much easier.
            // Check whether it is available.
            xi2_supported = XI2MouseKeyboard.IsSupported(window.Display);
            if (xi2_supported)
            {
                xi2_opcode = XI2MouseKeyboard.XIOpCode;
                xi2_version = XI2MouseKeyboard.XIVersion;
            }

            exists = true;
        }
示例#25
0
        void InitializeContext()
        {
            Toolkit.Init();

            // If this looks uninitialized...  initialize.
            if (ColorBPP == 0)
            {
                ColorBPP = 24;

                if (DepthBPP == 0)
                {
                    DepthBPP = 16;
                }
            }

            ColorFormat colorBufferColorFormat = new ColorFormat(ColorBPP);

            ColorFormat accumulationColorFormat = new ColorFormat(AccumulatorBPP);

            int buffers = 2;

            if (SingleBuffer)
            {
                buffers--;
            }

            var graphicsMode = new GraphicsMode(colorBufferColorFormat, DepthBPP, StencilBPP, Samples, accumulationColorFormat, buffers, Stereo);

            // IWindowInfo
            if (Configuration.RunningOnWindows)
            {
                IntPtr windowHandle = gdk_win32_drawable_get_handle(GdkWindow.Handle);
                windowInfo = Utilities.CreateWindowsWindowInfo(windowHandle);
            }
            else if (Configuration.RunningOnMacOS)
            {
                /* doesn't seem to work.. takes up whole window for now, but better than just crashing?
                 * if (!gdk_window_ensure_native(GdkWindow.Handle))
                 *  throw new InvalidOperationException("Couldn't create native NSView");
                 */

                IntPtr windowHandle = gdk_quartz_window_get_nswindow(GdkWindow.Handle);

                IntPtr viewHandle = gdk_quartz_window_get_nsview(GdkWindow.Handle);
                windowInfo = Utilities.CreateMacOSWindowInfo(windowHandle, viewHandle);
            }
            else if (Configuration.RunningOnX11)
            {
                IntPtr display      = gdk_x11_display_get_xdisplay(Display.Handle);
                int    screen       = Screen.Number;
                IntPtr windowHandle = gdk_x11_drawable_get_xid(GdkWindow.Handle);
                IntPtr rootWindow   = gdk_x11_drawable_get_xid(RootWindow.Handle);

                IntPtr visualInfo;
                if (graphicsMode.Index.HasValue)
                {
                    XVisualInfo info = new XVisualInfo();
                    info.VisualID = graphicsMode.Index.Value;
                    int dummy;
                    visualInfo = XGetVisualInfo(display, XVisualInfoMask.ID, ref info, out dummy);
                }
                else
                {
                    visualInfo = GetVisualInfo(display);
                }

                windowInfo = Utilities.CreateX11WindowInfo(display, screen, windowHandle, rootWindow, visualInfo);
                XFree(visualInfo);
            }
            else
            {
                throw new PlatformNotSupportedException();
            }

            // GraphicsContext
            graphicsContext = new GraphicsContext(graphicsMode, windowInfo, GlVersionMajor, GlVersionMinor, graphicsContextFlags);
            graphicsContext.MakeCurrent(windowInfo);

            if (GraphicsContext.ShareContexts)
            {
                Interlocked.Increment(ref graphicsContextCount);

                if (!sharedContextInitialized)
                {
                    sharedContextInitialized = true;
                    ((IGraphicsContextInternal)graphicsContext).LoadAll();
                    OnGraphicsContextInitialized();
                }
            }
            else
            {
                ((IGraphicsContextInternal)graphicsContext).LoadAll();
                OnGraphicsContextInitialized();
            }

            initialized = true;
            OnInitialized();
            //QueueDraw();
        }