Beispiel #1
0
        /// <summary>
        /// Creates an OpenGL context from a Unix/Linux platform.
        /// </summary>
        /// <returns>
        /// A <see cref="IDeviceContext"/> that specify the device context.
        /// </returns>
        private static IntPtr CreateX11SimpleContext(IDeviceContext rDevice)
        {
            XServerDeviceContext x11DeviceCtx = (XServerDeviceContext)rDevice;
            IntPtr rContext;

            using (Glx.XLock xLock = new Glx.XLock(x11DeviceCtx.Display)) {
                int[] attributes = new int[] {
                    Glx.RENDER_TYPE, (int)Glx.RGBA_BIT,
                    0
                };

                // Get basic visual
                unsafe {
                    int[]   choosenConfigCount = new int[1];
                    IntPtr *choosenConfigs     = Glx.ChooseFBConfig(x11DeviceCtx.Display, x11DeviceCtx.Screen, attributes, choosenConfigCount);

                    if (choosenConfigCount[0] == 0)
                    {
                        throw new InvalidOperationException("unable to find basic visual");
                    }

                    IntPtr choosenConfig = *choosenConfigs;

                    x11DeviceCtx.XVisualInfo = Glx.GetVisualFromFBConfig(x11DeviceCtx.Display, choosenConfig);
                    x11DeviceCtx.FBConfig    = choosenConfig;

                    Glx.UnsafeNativeMethods.XFree((IntPtr)choosenConfigs);
                }

                // Create direct context
                rContext = x11DeviceCtx.CreateContext(IntPtr.Zero);
                if (rContext == IntPtr.Zero)
                {
                    // Fallback to not direct context
                    rContext = Glx.CreateContext(x11DeviceCtx.Display, x11DeviceCtx.XVisualInfo, IntPtr.Zero, false);
                }

                if (rContext == IntPtr.Zero)
                {
                    throw new InvalidOperationException("unable to create context");
                }

                return(rContext);
            }
        }
        /// <summary>
        /// Query OpenGL implementation extensions.
        /// </summary>
        /// <param name="ctx"></param>
        /// <returns></returns>
        public static GraphicsCapabilities Query(GraphicsContext ctx, IDeviceContext deviceContext)
        {
            GraphicsCapabilities graphicsCapabilities = new GraphicsCapabilities();

            KhronosApi.LogComment("Query OpenGL extensions.");

            #region Platform Extension Reload

            // Since at this point there's a current OpenGL context, it's possible to use
            // {glx|wgl}GetExtensionsString to retrieve platform specific extensions

            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
            case PlatformID.Win32Windows:
            case PlatformID.Win32S:
            case PlatformID.WinCE:
                // Wgl.SyncDelegates();
                break;
            }

            #endregion

            // OpenGL extensions
            graphicsCapabilities._GlExtensions.Query();
            // Windows OpenGL extensions
            WindowsDeviceContext windowsDeviceContext = deviceContext as WindowsDeviceContext;
            if (windowsDeviceContext != null)
            {
                graphicsCapabilities._WglExtensions.Query(windowsDeviceContext);
            }
            // GLX OpenGL extensions
            XServerDeviceContext xserverDeviceContext = deviceContext as XServerDeviceContext;
            if (xserverDeviceContext != null)
            {
                graphicsCapabilities._GlxExtensions.Query(xserverDeviceContext);
            }

            // Query implementation limits
            graphicsCapabilities._GraphicsLimits = GraphicsLimits.Query(graphicsCapabilities._GlExtensions);

            return(graphicsCapabilities);
        }
			/// <summary>
			/// Query the extensions supported by current platform.
			/// </summary>
			/// <param name="deviceContext">
			/// A <see cref="WindowsDeviceContext"/> that specifies the device context to query extensions for.
			/// </param>
			public void Query(XServerDeviceContext deviceContext)
			{
				if (deviceContext == null)
					throw new ArgumentNullException("deviceContext");

				LogComment("Query GLX extensions.");

				string glxExtensions = null;
				int[] majorArg = new int[1], minorArg = new int[1];

				using (Glx.XLock xLock = new Glx.XLock(deviceContext.Display)) {
					Glx.QueryVersion(deviceContext.Display, majorArg, minorArg);

					if ((majorArg[0] >= 1) && (minorArg[0] >= 1))
						glxExtensions = Glx.QueryExtensionsString(deviceContext.Display, 0);
				}

				Query(new KhronosVersion(majorArg[0], minorArg[1]), glxExtensions ?? String.Empty);
			}
Beispiel #4
0
            /// <summary>
            /// Query the extensions supported by current platform.
            /// </summary>
            /// <param name="deviceContext">
            /// A <see cref="XServerDeviceContext"/> that specifies the device context to query extensions for.
            /// </param>
            public void Query(XServerDeviceContext deviceContext)
            {
                if (deviceContext == null)
                {
                    throw new ArgumentNullException("deviceContext");
                }

                LogComment("Query GLX extensions.");

                string glxExtensions = null;

                int[] majorArg = new int[1], minorArg = new int[1];

                using (Glx.XLock xLock = new Glx.XLock(deviceContext.Display)) {
                    Glx.QueryVersion(deviceContext.Display, majorArg, minorArg);

                    if ((majorArg[0] >= 1) && (minorArg[0] >= 1))
                    {
                        glxExtensions = Glx.QueryExtensionsString(deviceContext.Display, 0);
                    }
                }

                Query(new KhronosVersion(majorArg[0], minorArg[1], KhronosVersion.ApiGlx), glxExtensions ?? String.Empty);
            }