예제 #1
0
        static void GenerateDrawCalls(Compiler compiler, Method initMethod, Method freeMethod, DrawBlock drawBlock, HashSet <Scope> drawScopes)
        {
            foreach (var drawable in drawBlock.Drawables)
            {
                new ShaderGenerator(compiler, drawable, initMethod.Body, freeMethod.Body, drawBlock.DrawScope).Generate();
                FixedArrayProcessor.Process(compiler.Pass, drawable.DrawState.VertexShader);
                FixedArrayProcessor.Process(compiler.Pass, drawable.DrawState.PixelShader);
                VariableInliner.Process(compiler.Pass, drawable.DrawState.VertexShader);
                VariableInliner.Process(compiler.Pass, drawable.DrawState.PixelShader);
            }

            foreach (var drawable in drawBlock.Drawables)
            {
                drawBlock.DrawScope.Statements.Add(new Draw(drawable.Source, drawable.DrawState));
                drawScopes.Add(drawBlock.DrawScope);
            }
        }
예제 #2
0
        public static void GenerateDrawCalls(Compiler compiler, DataType dt)
        {
            var initMethod = new Method(
                dt.Source, dt, null, Modifiers.Private | Modifiers.Generated, "init_DrawCalls",
                DataType.Void, ParameterList.Empty, new Scope(dt.Source));

            dt.Methods.Add(initMethod);

            foreach (var ctor in dt.Constructors)
            {
                if (ctor.Body == null)
                {
                    compiler.Log.Warning(ctor.Source, ErrorCode.I0000, "Can't call 'init_DrawCalls()' from bodyless constructor");
                }
                else
                {
                    ctor.Body.Statements.Add(new CallMethod(initMethod.Source, new This(initMethod.Source, ctor.DeclaringType), initMethod));
                }
            }

            var freeMethod = new Method(
                dt.Source, dt, null, Modifiers.Private | Modifiers.Generated, "free_DrawCalls",
                DataType.Void, ParameterList.Empty, new Scope(dt.Source));

            dt.Methods.Add(freeMethod);

            var drawScopes = new HashSet <Scope>();

            for (int m = 0, l = dt.Methods.Count; m < l; m++)
            {
                var drawMethod = dt.Methods[m];

                for (int i = 0; i < drawMethod.DrawBlocks.Count; i++)
                {
                    var drawBlock = drawMethod.DrawBlocks[i];

                    if (!DrawableFinder.VerifyCircularReferences(compiler, drawBlock, new List <Block>()))
                    {
                        continue;
                    }

                    int drawBlockIndex = i;
                    if (TrySplitVirtualAppliesInDrawBlockRecursive(compiler, drawBlock, ref drawBlockIndex, drawScopes))
                    {
                        var foundDrawables = false;

                        for (int j = i; j <= drawBlockIndex; j++)
                        {
                            var virtualBlock = drawMethod.DrawBlocks[j];
                            DrawableFinder.FindDrawables(compiler, virtualBlock, false);

                            if (!foundDrawables)
                            {
                                foundDrawables = virtualBlock.Drawables.Length > 0;
                            }
                        }

                        for (int j = i; j <= drawBlockIndex; j++)
                        {
                            var virtualBlock = drawMethod.DrawBlocks[j];

                            if (!foundDrawables)
                            {
                                DrawableFinder.FindDrawables(compiler, virtualBlock, true);
                            }

                            GenerateDrawCalls(compiler, initMethod, freeMethod, virtualBlock, drawScopes);
                        }

                        //compiler.Log.Message(drawBlock.Source, ErrorCode.M0000, "Created " + (drawBlockIndex + i + 1) + " draw blocks from virtual " + drawBlock.Quote());
                        i += drawBlockIndex - i;
                    }
                    else
                    {
                        DrawableFinder.FindDrawables(compiler, drawBlock, true);
                        GenerateDrawCalls(compiler, initMethod, freeMethod, drawBlock, drawScopes);
                    }
                }
            }

            FixedArrayProcessor.Process(compiler.Pass, dt, initMethod.Body, drawScopes);
            VariableInliner.Process(compiler.Pass, initMethod.Body);

            foreach (var s in drawScopes)
            {
                VariableInliner.Process(compiler.Pass, s);
            }

            foreach (var m in dt.Methods)
            {
                if (m.DrawBlocks.Count > 0)
                {
                    ScopeInliner.Process(compiler.Pass, m.Body, drawScopes);
                }
            }
        }