Beispiel #1
0
        /// <summary>
        /// Checks if a Wgl extension is supported by the given context.
        /// </summary>
        /// <param name="dc">The device context.</param>
        /// <param name="name">The extension to check.</param>
        /// <returns>True if the extension is supported by the given context, false otherwise</returns>
        public static bool SupportsExtension(IntPtr dc, string name)
        {
            lock (sync)
            {
                if (extensions.Count == 0)
                {
                    // We cache this locally, as another thread might create a context which doesn't support  this method.
                    // The design is far from ideal, but there's no good solution to this issue as long as we are using
                    // static WGL/GL classes. Fortunately, this issue is extremely unlikely to arise in practice, as you'd
                    // have to create one accelerated and one non-accelerated context in the same application, with the
                    // non-accelerated context coming second.
                    bool   get_arb = SupportsFunction("wglGetExtensionsStringARB");
                    bool   get_ext = SupportsFunction("wglGetExtensionsStringEXT");
                    string str     =
                        get_arb ? Wgl.GetExtensionsStringARB(dc) :
                        get_ext?Wgl.GetExtensionsStringEXT() :
                            String.Empty;

                    if (!String.IsNullOrEmpty(str))
                    {
                        foreach (string ext in str.Split(' '))
                        {
                            extensions.Add(ext, true);
                        }
                    }
                }
            }

            if (extensions.Count > 0)
            {
                return(extensions.ContainsKey(name));
            }
            return(false);
        }