Пример #1
0
        /// <summary>
        /// Create a device context on the specified window.
        /// </summary>
        /// <param name="display">
        /// A <see cref="IntPtr"/> that specifies the display handle associated to <paramref name="windowHandle"/>. Some platforms
        /// ignore this parameter (i.e. Windows or EGL implementation).
        /// </param>
        /// <param name='windowHandle'>
        /// A <see cref="IntPtr"/> that specifies the window handle used to create the device context.
        /// </param>
        /// <exception cref='ArgumentException'>
        /// Is thrown when <paramref name="windowHandle"/> is <see cref="IntPtr.Zero"/>.
        /// </exception>
        /// <exception cref='NotSupportedException'>
        /// Exception thrown if the current platform is not supported.
        /// </exception>
        public static DeviceContext Create(IntPtr display, IntPtr windowHandle)
        {
            DeviceContext deviceContext = null;

            if (IsEglRequired == false)
            {
                switch (Platform.CurrentPlatformId)
                {
                case Platform.Id.WindowsNT:
                    deviceContext = new DeviceContextWGL(windowHandle);
                    break;

                case Platform.Id.Linux:
                    deviceContext = new DeviceContextGLX(display, windowHandle);
                    break;

                case Platform.Id.MacOS:
                    if (Glx.IsRequired)
                    {
                        deviceContext = new DeviceContextGLX(display, windowHandle);
                    }
                    else
                    {
                        throw new NotSupportedException("platform MacOS not supported without Glx.IsRequired=true");
                    }
                    break;

                default:
                    throw new NotSupportedException(String.Format("platform {0} not supported", Environment.OSVersion));
                }
            }
            else
            {
                deviceContext = new DeviceContextEGL(windowHandle);
            }

            deviceContext._Api = _DefaultApi;

            return(deviceContext);
        }
Пример #2
0
            /// <summary>
            /// Query the extensions supported by current platform.
            /// </summary>
            /// <param name="deviceContext">
            /// A <see cref="DeviceContextGLX"/> that specifies the device context to query extensions for.
            /// </param>
            internal void Query(DeviceContextGLX 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[0], KhronosVersion.ApiGlx), glxExtensions ?? String.Empty);
            }
Пример #3
0
        /// <summary>
        /// Create a device context without a specific window.
        /// </summary>
        /// <exception cref='NotSupportedException'>
        /// Exception thrown if the current platform is not supported.
        /// </exception>
        public static DeviceContext Create()
        {
            Debug.Assert(Gl._NativeWindow != null);

            DeviceContext deviceContext = null;

            if (IsEglRequired == false)
            {
                switch (Platform.CurrentPlatformId)
                {
                case Platform.Id.WindowsNT:
                    deviceContext = new DeviceContextWGL();
                    break;

                case Platform.Id.Linux:
                    deviceContext = new DeviceContextGLX();
                    break;

                case Platform.Id.MacOS:
                    if (Glx.IsRequired)
                    {
                        deviceContext = new DeviceContextGLX();
                    }
                    else
                    {
                        throw new NotSupportedException("platform MacOS not supported without Glx.IsRequired=true");
                    }
                    break;

                default:
                    throw new NotSupportedException(String.Format("platform {0} not supported", Platform.CurrentPlatformId));
                }
            }
            else
            {
                if (deviceContext == null)
                {
                    INativePBuffer nativeBuffer = Gl._NativeWindow as INativePBuffer;
                    if (nativeBuffer != null)
                    {
                        deviceContext = new DeviceContextEGL(nativeBuffer);
                    }
                }

                if (deviceContext == null)
                {
                    INativeWindow nativeWindow = Gl._NativeWindow as INativeWindow;
                    if (nativeWindow != null)
                    {
                        deviceContext = new DeviceContextEGL(nativeWindow.Handle);
                    }
                }

                if (deviceContext == null)
                {
                    Debug.Fail("unsupported EGL surface");
                    throw new NotSupportedException("EGL surface not supported");
                }
            }

            return(deviceContext);
        }