Example #1
0
 public HlslWriter(HlslWriter writer)
     : base(writer)
 {
 }
Example #2
0
        protected override void CompileInvocationExpression(InvocationExpressionSyntax expression)
        {
            var symbol = GetSymbol(expression.Expression);

            if (symbol != null)
            {
                var special = symbol.GetAttribute("Special");

                if (special != null)
                {
                    var name = (Special)special.ConstructorArguments.First().Value;

                    switch (name)
                    {
                        case Special.rgba_hex:
                            // If the funciton has a special compilation, do that special compilation.
                            var hex_literal = expression.ArgumentList.Arguments[0].Expression as LiteralExpressionSyntax;
                            var float_literal = expression.ArgumentList.Arguments[1].Expression as LiteralExpressionSyntax;
                            //Write("float4({0}, {1})", HexToVec4(hex_literal.ToString()), float_literal.ToString());

                            Write("float4(");
                            Write(HexToVec4(hex_literal.ToString()));
                            Write(", ");
                            CompileLiteralExpression(float_literal);
                            Write(")");

                            break;

                        case Special.rgb_hex:
                            // If the funciton has a special compilation, do that special compilation.
                            var _hex_literal = expression.ArgumentList.Arguments[0].Expression as LiteralExpressionSyntax;
                            Write("float4({0}, 1.0)", HexToVec4(_hex_literal.ToString()));
                            break;
                    }
                }
                else if (TranslationLookup.SymbolMap.ContainsKey(symbol))
                {
                    // If the function has a tranlsation, use that tranlsation
                    var translation_info = TranslationLookup.SymbolMap[symbol];
                    Write(translation_info.Translation);

                    Write("(");
                    CompileArgumentList(expression.ArgumentList, false);
                    Write(")");
                }
                else
                {
                    // Otherwise compile the function and note that we are using it.
                    var writer = new HlslWriter(this);
                    var result = writer.CompileMethod(symbol);

                    ReferencedMethods.AddUnique(SymbolCompilation[symbol].ReferencedMethods);
                    ReferencedMethods.AddUnique(symbol);

                    ReferencedForeignVars.AddUnique(writer.ReferencedForeignVars);

                    CompileExpression(expression.Expression);

                    Write("(");
                    CompileArgumentList(expression.ArgumentList, result.UsesSampler);
                    Write(")");
                }
            }
            else
            {
                Write("ERROR(Unknown function : {0})", expression);
            }
        }