Exemple #1
0
 public IGlContext MakeCurrent()
 {
     if (GLX.glXMakeCurrent(Display, WindowHandle, Context))
     {
         return(this);
     }
     GL.CheckError();
     Console.Error.WriteLineColored(ConsoleColor.Red, "glXMakeCurrent failed");
     return(this);
 }
Exemple #2
0
        private LinuxGlContext(IntPtr windowHandle)
        {
            Console.Out.WriteLineColored(ConsoleColor.Yellow, "InitialWindowHandle:{0:X8}",
                                         new UIntPtr(windowHandle.ToPointer()).ToUInt64());
            const int width  = 128;
            const int height = 128;
            int       fbcount;
            var       visualAttributes = new List <int>();

#if false
            visualAttributes.AddRange(new[] { (int)GLXAttribute.RGBA });
            visualAttributes.AddRange(new[] { (int)GLXAttribute.RED_SIZE, 1 });
            visualAttributes.AddRange(new[] { (int)GLXAttribute.GREEN_SIZE, 1 });
            visualAttributes.AddRange(new[] { (int)GLXAttribute.BLUE_SIZE, 1 });
            visualAttributes.AddRange(new[] { (int)GLXAttribute.DOUBLEBUFFER, 1 });
            visualAttributes.AddRange(new[] { (int)0, 0 });
#else
            visualAttributes.AddRange(new[] { (int)GLXAttribute.DRAWABLE_TYPE, 1 });
            visualAttributes.AddRange(new[] { (int)GLXAttribute.RENDER_TYPE, 1 });
            visualAttributes.AddRange(new[] { (int)GLXAttribute.RED_SIZE, 8 });
            visualAttributes.AddRange(new[] { (int)GLXAttribute.GREEN_SIZE, 8 });
            visualAttributes.AddRange(new[] { (int)GLXAttribute.BLUE_SIZE, 8 });
            visualAttributes.AddRange(new[] { (int)GLXAttribute.ALPHA_SIZE, 8 });
            visualAttributes.AddRange(new[] { (int)GLXAttribute.DEPTH_SIZE, 24 });
            visualAttributes.AddRange(new[] { (int)GLXAttribute.STENCIL_SIZE, 8 });
            visualAttributes.AddRange(new[] { (int)GLXAttribute.DOUBLEBUFFER, 1 });
            visualAttributes.AddRange(new[] { 0, 0 });
#endif

            Console.WriteLine("++++++++++++++++++++++++");

            if (DefaultDisplay == IntPtr.Zero)
            {
                DefaultDisplay = XOpenDisplay(IntPtr.Zero);
                DefaultScreen  = XDefaultScreen(DefaultDisplay);
                //DefaultRootWindow = XRootWindow(Display, DefaultScreen);
                //DefaultRootWindow = IntPtr.Zero;
            }

            Display = DefaultDisplay;
            _screen = DefaultScreen;

            //Console.WriteLine("{0}", GLX.ChooseVisual(Display, Screen, visualAttributes.ToArray()));

            Console.WriteLine("------------------------");
#if false
            var visinfo = (XVisualInfo *)GLX.ChooseVisual(Display, Screen, visualAttributes.ToArray()).ToPointer();
            //Console.WriteLine("------------------------");

            Console.WriteLine("++++++++++++++++++++++++");
#else
            var fbconfigs = GLX.glXChooseFBConfig(Display, _screen, visualAttributes.ToArray(), out fbcount);
            var visinfo   = GLX.glXGetVisualFromFBConfig(Display, *fbconfigs);
#endif
            var root = XRootWindow(Display, visinfo->Screen);


            Console.WriteLine("++++++++++++++++++++++++");

            var info = *visinfo;
            //Console.WriteLine(info.VisualID);
            //info = default(XVisualInfo);
            //info.VisualID = new IntPtr(33); int nitems; XGetVisualInfo(Display, (IntPtr)XVisualInfoMask.ID, ref info, out nitems);

            if (windowHandle == IntPtr.Zero)
            {
                //var attr = default(XSetWindowAttributes);
                ///* window attributes */
                //attr.background_pixel = 0;
                //attr.border_pixel = 0;
                //attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
                //attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
                //mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
                //
                //win = XCreateWindow(dpy, root, 0, 0, width, height,
                //			 0, visinfo->depth, InputOutput,
                //			 visinfo->visual, mask, &attr);

                var attr = default(XSetWindowAttributes);
                attr.background_pixel = IntPtr.Zero;
                attr.border_pixel     = IntPtr.Zero;
                attr.colormap         = XCreateColormap(Display, root, info.Visual, 0);
                attr.event_mask       =
                    (IntPtr)(EventMask.StructureNotifyMask | EventMask.ExposureMask | EventMask.KeyPressMask);
                //var mask = (IntPtr)(CreateWindowMask.CWBackPixel | CreateWindowMask.CWBorderPixel | CreateWindowMask.CWColormap | CreateWindowMask.CWEventMask);

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

                Console.WriteLine("{0}, {1}", info.Visual, info.VisualID);

                windowHandle = XCreateWindow(
                    Display,
                    root,
                    0, 0, width, height,
                    0,
                    info.Depth, (int)XWindowClass.InputOutput,
                    info.Visual, (IntPtr)mask, ref attr
                    );
            }

            this.WindowHandle = windowHandle;

            //XMapWindow(Display, WindowHandle);


            //var Info = (XVisualInfo*)GLX.ChooseVisual(Display, Screen, visualAttributes.ToArray()).ToPointer();

            //GLX.glXCreateContextAttribsARB(
            Context = GLX.glXCreateContext(Display, &info, _sharedContext, false);
            GL.CheckError();

            // Just for >= 3.0
            //if (true)
            //{
            //	var CreateContextAttribsARB = (CreateContextAttribsARB)Marshal.GetDelegateForFunctionPointer(GLX.glXGetProcAddress("glXCreateContextAttribsARB"), typeof(CreateContextAttribsARB));
            //
            //	List<int> attributes = new List<int>();
            //	attributes.AddRange(new int[] { (int)ArbCreateContext.MajorVersion, 2 });
            //	attributes.AddRange(new int[] { (int)ArbCreateContext.MinorVersion, 1 });
            //	attributes.AddRange(new int[] { 0, 0 });
            //
            //	fixed (int* attributesPtr = attributes.ToArray())
            //	{
            //		var fbconfigs2 = GLX.glXChooseFBConfig(Display, Screen, new int[] {
            //			(int)GLXAttribute.VISUAL_ID, (int)visinfo->VisualID,
            //			0, 0,
            //		}, out fbcount);
            //
            //		Console.WriteLine("{0}", new IntPtr(fbconfigs2));
            //		Console.WriteLine("{0}", *fbconfigs2);
            //
            //		GLX.glXDestroyContext(Display, this.Context);
            //		this.Context = CreateContextAttribsARB(Display, *fbconfigs, SharedContext, false, attributesPtr);
            //	}
            //}

            if (_sharedContext == IntPtr.Zero)
            {
                _sharedContext = Context;
            }

            MakeCurrent();
            GL.LoadAllOnce();

            Console.Out.WriteLineColored(ConsoleColor.Yellow, "VisualID:{0}", info.VisualID);
            Console.Out.WriteLineColored(ConsoleColor.Yellow, "Display:{0:X8}",
                                         new UIntPtr(Display.ToPointer()).ToUInt64());
            Console.Out.WriteLineColored(ConsoleColor.Yellow, "WindowHandle:{0:X8}",
                                         new UIntPtr(windowHandle.ToPointer()).ToUInt64());
            Console.Out.WriteLineColored(ConsoleColor.Yellow, "Context:{0:X8}",
                                         new UIntPtr(Context.ToPointer()).ToUInt64());
            Console.Out.WriteLineColored(ConsoleColor.Yellow, "Version:{0}", GL.GetString(GL.GL_VERSION));
            Console.Out.WriteLineColored(ConsoleColor.Yellow, "Version:{0}.{1}", GL.glGetInteger(GL.GL_MAJOR_VERSION),
                                         GL.glGetInteger(GL.GL_MINOR_VERSION));
            Console.Out.WriteLineColored(ConsoleColor.Yellow, "Vendor:{0}", GL.GetString(GL.GL_VENDOR));
            Console.Out.WriteLineColored(ConsoleColor.Yellow, "Renderer:{0}", GL.GetString(GL.GL_RENDERER));
        }
Exemple #3
0
 public void Dispose() => GLX.glXDestroyContext(Display, Context);
Exemple #4
0
 public IGlContext SwapBuffers()
 {
     GLX.glXSwapBuffers(Display, WindowHandle);
     return(this);
 }
Exemple #5
0
 public IGlContext ReleaseCurrent()
 {
     GLX.glXMakeCurrent(Display, IntPtr.Zero, IntPtr.Zero);
     GL.CheckError();
     return(this);
 }