Esempio n. 1
0
        private Expression WidenType <T>(Expression source)
        {
            var tref = ShaderDefinition.ToCecil(typeof(T));
            var n    = new ObjectCreateExpression(AstBuilder.ConvertType(tref), new[] { source.Clone() });

            return(n);
        }
Esempio n. 2
0
        /// <summary>
        /// Redirects the invocation to the explicitly specified method
        /// </summary>
        protected Func <MethodDefinition, InvocationExpression, StringBuilder> Redirect(Expression <Action> wrapper)
        {
            var fun = ShaderDefinition.ToCecil(((MethodCallExpression)wrapper.Body).Method);

            CheckWarnings(fun);
            return((m, i) =>
            {
                // replace the current node with a call to fun and process again
                i.RemoveAnnotations(typeof(MethodDefinition));
                i.RemoveAnnotations(typeof(MethodReference));
                i.AddAnnotation(fun);
                return i.AcceptVisitor(this, 0);
            });
        }
Esempio n. 3
0
        /// <summary>
        /// Redirects the invocation to the specified class, by searching for a
        /// method with the specified name if given or same name otherwise
        /// matching the original method signature.
        /// </summary>
        /// <returns></returns>
        protected Func <MethodDefinition, InvocationExpression, StringBuilder> Redirect <T>(string name = null)
        {
            var t = ShaderDefinition.ToCecil(typeof(T));

            return((m, i) =>
            {
                var redirected = t.Methods.Single(j => j.Name == (name ?? m.Name) &&
                                                  SameSignature(j, m));
                CheckWarnings(redirected);
                i.RemoveAnnotations(typeof(MethodDefinition));
                i.RemoveAnnotations(typeof(MethodReference));
                i.AddAnnotation(redirected);
                return i.AcceptVisitor(this, 0);
            });
        }
Esempio n. 4
0
        private StringBuilder TextureLod(MethodDefinition m, InvocationExpression i)
        {
            Debug.Assert(i.Arguments.Count == 3);
            var args    = i.Arguments.ToArray();
            var sampler = args[0];
            var pos     = args[1];
            var lod     = args[2];

            var tref   = ShaderDefinition.ToCecil(typeof(ShaderDefinition.vec4));
            var zero   = new PrimitiveExpression("0.0f");
            var newPos = new ObjectCreateExpression(AstBuilder.ConvertType(tref), new[] { pos.Clone(), zero, lod.Clone() });

            var result = new StringBuilder();

            return(result.Append("tex2Dlod(").Append(ArgsToString(new[] { sampler, newPos })).Append(")"));
        }