Пример #1
0
        /// <summary>Allocates GPU drawing meta now.</summary>
        public virtual DrawStackNode Allocate(DrawInfo info, SurfaceTexture tex, ref int stackID)
        {
            // If the source is a constant or a graph
            // then we don't allocate a material for it.
            // We do, however, create a texture:

            // CONSTANT: 1 * 1 (Texture)
            // GRAPH   : info.ImageX * 1 (Texture)
            // ELSE    : info.ImageX * info.ImageY (Stack)

            int dimensions = OutputDimensions;

            if (dimensions == 2)
            {
                // Stack required.

                // Allocate a target stack now:
                int       targetStack = stackID;
                DrawStack stack       = tex.GetStack(targetStack, info);
                stackID++;

                // Create the material:
                Material material = GetMaterial(MaterialID, SubMaterialID);

                if (Sources != null)
                {
                    int inputStacks = (targetStack == 0)?1:0;

                    for (int i = 0; i < Sources.Length; i++)
                    {
                        // Get the input node:
                        TextureNode input = Sources[i];

                        // Allocate it now (must not allocate targetStack in the direct kids):

                        DrawStackNode drawNode = input.Allocate(info, tex, ref inputStacks);

                        if (inputStacks == targetStack)
                        {
                            // Skip:
                            inputStacks++;
                        }

                        // Apply it to our material:
                        material.SetTexture("_Src" + i, drawNode.Texture);
                    }
                }

                // Create our node:
                MaterialStackNode matNode = DrawStore as MaterialStackNode;

                if (matNode == null)
                {
                    matNode      = new MaterialStackNode();
                    DrawStore    = matNode;
                    matNode.Mesh = info.Mesh;
                }

                matNode.Material = material;
                matNode.Stack    = stack;

                return(matNode);
            }

            // It'll be baked/ drawn by the CPU.

            // Get the width of the texture:
            int width = (dimensions == 1)?info.ImageX : 1;

            TextureStackNode constNode = DrawStore as TextureStackNode;

            if (constNode == null)
            {
                constNode = new TextureStackNode(this, info.HDR, width);
                DrawStore = constNode;
            }

            // Ok:
            return(constNode);
        }