Example #1
0
 private GlInterface(GlContextInfo info, Func <string, IntPtr> getProcAddress) : base(getProcAddress, info)
 {
     ContextInfo = info;
     Version     = GetString(GlConsts.GL_VERSION);
     Renderer    = GetString(GlConsts.GL_RENDERER);
     Vendor      = GetString(GlConsts.GL_VENDOR);
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="contextGl"></param>
        public static void LoadAllExtensions(object contextGl)
        {
            GlContextInfo gci = GetContextInfo(contextGl);

            foreach (string ext in gci.AvailableExtensions.Keys)
            {
                LoadExtension(contextGl, ext, false);
            }
        }
        /// <summary>
        /// Returns true if the extension with the given name is supported
        /// in the given context.
        /// </summary>
        /// <param name="contextGl">The context which to query.</param>
        /// <param name="extname">The extension name.</param>
        /// <returns></returns>
        public static bool IsExtensionSupported(object contextGl, string extname)
        {
            GlContextInfo gci = GetContextInfo(contextGl);

            if (gci.AvailableExtensions.ContainsKey(extname))
            {
                return(true);
            }
            return(false);
        }
        internal static GlContextInfo GetContextInfo(object ctx)
        {
            // use "0" to mean no context
            if (ctx == null)
            {
                ctx = 0;
            }

            if (!ContextInfo.ContainsKey(ctx))
            {
                ContextInfo[ctx] = new GlContextInfo();
            }

            return(ContextInfo[ctx] as GlContextInfo);
        }
Example #5
0
 public GlInterface(GlVersion version, Func <string, IntPtr> getProcAddress) : this(
         GlContextInfo.Create(version, getProcAddress), getProcAddress)
 {
 }
        //
        // LoadExtension
        //
        // Attempt to load the extension with the specified name into the
        // given context, which must have already been made current.  The
        // object passed in ought to be an instance of
        // Tao.OpenGl.ContextGl, or null. If forceLoad is set, attempt
        // to obtain function pointers even if the runtime claims that the
        // extension is not supported.
        //
        /// <summary>
        ///
        /// </summary>
        /// <param name="contextGl"></param>
        /// <param name="extname"></param>
        /// <param name="forceLoad"></param>
        /// <returns></returns>
        public static bool LoadExtension(object contextGl, string extname, bool forceLoad)
        {
            GlContextInfo gci = GetContextInfo(contextGl);

            if (gci.LoadedExtensions.ContainsKey(extname))
            {
                return((bool)gci.LoadedExtensions[extname]);
            }

            if (!forceLoad && !gci.AvailableExtensions.ContainsKey(extname))
            {
                return(false);
            }

            // this will get us either the Tao.OpenGl.Gl or
            // Tao.OpenGl.ContextGl class
            Type glt;

            if (contextGl != null)
            {
                glt = contextGl.GetType();
            }
            else
            {
                glt = StaticGlType;
                if (glt == null)
                {
                    Console.WriteLine("GL type is null!");
                }
            }

            FieldInfo[] fis = glt.GetFields(BindingFlags.Public |
                                            BindingFlags.DeclaredOnly |
                                            BindingFlags.Static |
                                            BindingFlags.Instance);

            foreach (FieldInfo fi in fis)
            {
                object[] attrs = fi.GetCustomAttributes(typeof(OpenGLExtensionImport), false);
                if (attrs.Length == 0)
                {
                    continue;
                }

                OpenGLExtensionImport oglext = attrs[0] as OpenGLExtensionImport;
                if (oglext.ExtensionName == extname)
                {
                    // did we already load this somehow?
                    if (((IntPtr)fi.GetValue(contextGl)) != IntPtr.Zero)
                    {
                        continue;
                    }

                    //Console.WriteLine ("Loading " + oglext.EntryPoint + " for " + extname);
                    IntPtr procaddr = GetProcAddress(oglext.EntryPoint);
                    if (procaddr == IntPtr.Zero)
                    {
                        Console.WriteLine("OpenGL claimed that '{0}' was supported, but couldn't find '{1}' entry point",
                                          extname, oglext.EntryPoint);
                        // we crash if anyone tries to call this method, but that's ok
                        continue;
                    }

                    fi.SetValue(contextGl, procaddr);
                }
            }

            gci.LoadedExtensions[extname] = true;
            return(true);
        }
Example #7
0
        internal static GlContextInfo GetContextInfo(object ctx)
        {
            // use "0" to mean no context
            if (ctx == null)
                ctx = 0;

            if (!ContextInfo.ContainsKey(ctx))
            {
                ContextInfo[ctx] = new GlContextInfo();
            }

            return ContextInfo[ctx] as GlContextInfo;
        }