Ejemplo n.º 1
0
        /// <summary>
        /// Creates a default delegate for an OpenGL function in the event that it is not implemented by the driver.
        /// </summary>
        /// <param name="type">The OpenGL delegate type.</param>
        /// <param name="function">The name of the OpenGL function.</param>
        /// <param name="requirements">The OpenGL function's specified requirements.</param>
        /// <returns>The default delegate that was created.</returns>
        private static Delegate CreateDefaultDelegate(Type type, String function, RequireAttribute requirements)
        {
            var valFunction = Expression.Constant(function);
            var valHasReqs  = Expression.Constant(requirements != null);
            var valIsCore   = Expression.Constant(requirements != null && requirements.IsCore(majorVersion, minorVersion, isGLES));
            var valExt      = Expression.Constant(requirements == null ? null : requirements.Extension);
            var valExtFn    = Expression.Constant(requirements == null ? null : requirements.ExtensionFunction);

            var delegateInvoke     = type.GetMethod("Invoke");
            var delegateParameters = delegateInvoke.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name));

            var throwExpression = Expression.Throw(Expression.Call(miCreateDefaultDelegateException,
                                                                   valFunction,
                                                                   valIsCore,
                                                                   valHasReqs,
                                                                   Expression.Convert(valExt, typeof(String)),
                                                                   Expression.Convert(valExtFn, typeof(String))), delegateInvoke.ReturnType);
            var throwLambda = Expression.Lambda(type, throwExpression, delegateParameters);

            return(throwLambda.Compile());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Loads the default delegate for the specified field.
 /// </summary>
 /// <param name="field">The field for which to load a default delegate.</param>
 /// <param name="requirements">The OpenGL function's specified requirements.</param>
 private static void LoadDefaultDelegate(FieldInfo field, RequireAttribute requirements)
 {
     var fndefault = CreateDefaultDelegate(field.FieldType, field.Name, requirements);
     field.SetValue(null, fndefault);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the default delegate for the specified field.
        /// </summary>
        /// <param name="field">The field for which to load a default delegate.</param>
        /// <param name="requirements">The OpenGL function's specified requirements.</param>
        private static void LoadDefaultDelegate(FieldInfo field, RequireAttribute requirements)
        {
            var fndefault = CreateDefaultDelegate(field.FieldType, field.Name, requirements);

            field.SetValue(null, fndefault);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a default delegate for an OpenGL function in the event that it is not implemented by the driver.
        /// </summary>
        /// <param name="type">The OpenGL delegate type.</param>
        /// <param name="function">The name of the OpenGL function.</param>
        /// <param name="requirements">The OpenGL function's specified requirements.</param>
        /// <returns>The default delegate that was created.</returns>
        private static Delegate CreateDefaultDelegate(Type type, String function, RequireAttribute requirements)
        {
            var valFunction = Expression.Constant(function);
            var valHasReqs = Expression.Constant(requirements != null);
            var valIsCore = Expression.Constant(requirements != null && requirements.IsCore(majorVersion, minorVersion, isGLES));
            var valExt = Expression.Constant(requirements == null ? null : requirements.Extension);
            var valExtFn = Expression.Constant(requirements == null ? null : requirements.ExtensionFunction);

            var delegateInvoke = type.GetMethod("Invoke");
            var delegateParameters = delegateInvoke.GetParameters().Select(x => Expression.Parameter(x.ParameterType, x.Name));

            var throwExpression = Expression.Throw(Expression.Call(miCreateDefaultDelegateException,
                valFunction,
                valIsCore,
                valHasReqs,
                Expression.Convert(valExt, typeof(String)),
                Expression.Convert(valExtFn, typeof(String))), delegateInvoke.ReturnType);
            var throwLambda = Expression.Lambda(type, throwExpression, delegateParameters);

            return throwLambda.Compile();
        }