/// <summary>
        /// Creates the input operand.
        /// </summary>
        /// <remarks>Must always first create components with lower values,
        /// to ensure correct input layout.</remarks>
        /// <param name="fmt">The format.</param>
        /// <param name="component">The component.</param>
        /// <returns>The operand.</returns>
        public Operand CreateInput(PinFormat fmt, PinComponent component)
        {
            Operand op = new Operand(fmt, GenerateNextUniqueName());

            compiler.RegisterInput(op.Name, fmt, component);
            return(op);
        }
 /// <summary>
 /// Outputs the specified op as component.
 /// </summary>
 /// <remarks>Must always first output components with lower values,
 /// to ensure correct input layers.</remarks>
 /// <param name="op">The op.</param>
 /// <param name="component">The component.</param>
 public void Output(Operand op, PinComponent component)
 {
     if (op.IsArray)
     {
         throw new IncompatibleOperandsException("Output operands must be non-array.");
     }
     compiler.Output(component, op.Format, op.Name);
 }
Beispiel #3
0
 /// <summary>
 /// Does this format contain the component.
 /// </summary>
 /// <param name="c">Component to check.</param>
 /// <returns>Indication if it is in format.</returns>
 public bool HasComponent(PinComponent c)
 {
     if ((Components & (int)c) != 0)
     {
         return(true);
     }
     return(false);
 }
Beispiel #4
0
        /// <summary>
        /// Obtains pin matching component.
        /// </summary>
        /// <param name="c">The component.</param>
        /// <returns>The actual pin.</returns>
        public Pin PinAsOutput(PinComponent c)
        {
            Pin value;

            if (outputs.TryGetValue(c, out value))
            {
                return(value);
            }
            return(null);
        }
        /// <summary>
        /// A fallthrough shader, copies all inputs to outputs (the same name).
        /// </summary>
        /// <param name="inputPinComponents">Input components that must be provided.</param>
        /// <param name="outputPinComponents">Output components of shader.</param>
        /// <remarks>
        /// All output compononents must have inputs, if too many inputs are provided, they are simply discarded.
        /// </remarks>
        /// <returns>The ShaderCode matching description.</returns>
        public static ShaderCode FallTroughShader(BindingStage stage, PinComponent inputPinComponents, PinComponent outputPinComponents)
        {
            if ((outputPinComponents & inputPinComponents) != outputPinComponents)
            {
                throw new ArgumentException("Invalid bindings, some output pins do not have input components.");
            }

            // TODO:
            return(null);
        }
Beispiel #6
0
        /// <summary>
        /// Adds pins as output.
        /// </summary>
        /// <param name="c">The component link.</param>
        /// <param name="format">The pin format.</param>
        public void AddInput(PinComponent c, PinFormat format)
        {
            if (PinAsOutput(c) != null)
            {
                throw new ArgumentException("The component is already a part of input.");
            }

            Pin pin = new Pin(format, Pin.NotArray, this);

            outputs.Add(c, pin);
            UpdateDesc();
        }
Beispiel #7
0
        /// <summary>
        /// Unlinks the component.
        /// </summary>
        /// <param name="c"></param>
        public void UnlinkComponent(PinComponent c)
        {
            if (!HasComponent(c))
            {
                throw new InvalidOperationException("The component " + c.ToString() + " does not exist.");
            }

            components &= ~c;
            inputs.Remove(c);

            UpdateDesc();
        }
Beispiel #8
0
 /// <summary>
 /// Obtains elelemt with component.
 /// </summary>
 /// <param name="component">The component.</param>
 public Element GetElement(PinComponent component)
 {
     for (int i = 0; i < elements.Length; i++)
     {
         if (elements[i].Component == component)
         {
             return(elements[i]);
         }
     }
     throw new ArgumentException("The component " + component.ToString() + " does not exist in vertex " +
                                 "  format " + ToString());
 }
Beispiel #9
0
        /// <summary>
        /// Adds component and links.
        /// </summary>
        /// <param name="c"></param>
        /// <param name="pin"></param>
        public void AddComponentAndLink(PinComponent c, [NotNull] Pin pin)
        {
            if (HasComponent(c))
            {
                throw new InvalidOperationException("The component " + c.ToString() + " already exists.");
            }

            components |= c;
            inputs.Add(c, pin);

            UpdateDesc();
        }
Beispiel #10
0
        /// <summary>
        /// Adds a component.
        /// </summary>
        /// <param name="c"></param>
        public void AddComponent(PinComponent c, PinFormat format)
        {
            if (HasComponent(c))
            {
                throw new InvalidOperationException("The component " + c.ToString() + " already exists.");
            }

            components |= c;
            inputs.Add(c, new Pin(format, Pin.NotArray, null));

            UpdateDesc();
        }
Beispiel #11
0
        /// <summary>
        /// Removes pin as input.
        /// </summary>
        /// <param name="c">The component.</param>
        /// <remarks>Pin must not be used by anyone (it is tagged as invalid).</remarks>
        public void RemoveInput(PinComponent c)
        {
            Pin p = PinAsOutput(c);

            if (p != null)
            {
                // TODO: Must unlink it.

                components &= ~c;
                outputs.Remove(c);
                UpdateDesc();
            }
        }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InAttribute"/> class.
 /// </summary>
 public InAttribute(PinComponent component)
 {
     this.component = component;
 }
Beispiel #13
0
            /// <summary>
            /// Constructor with string symbolicName.
            /// </summary>
            /// <param name="desc">The symbolicName.</param>
            internal Element(string desc)
            {
                string[] split = desc.Split('.');
                if (split.Length != 2)
                {
                    throw new InvalidVertexFormatException("The vertex format is malformed.");
                }
                offset = 0;

                // We check component first.
                switch (split[0])
                {
                case "B":
                    component = PinComponent.BiNormal;
                    break;

                case "P":
                    component = PinComponent.Position;
                    break;

                case "N":
                    component = PinComponent.Normal;
                    break;

                case "C":
                    component = PinComponent.Colour;
                    break;

                case "SC":
                    component = PinComponent.SecondaryColour;
                    break;

                case "T":
                    component = PinComponent.Tangent;
                    break;

                case "BW":
                    component = PinComponent.BlendWeights;
                    break;

                case "BI":
                    component = PinComponent.BlendIndices;
                    break;

                case "T0":
                    component = PinComponent.TexCoord0;
                    break;

                case "T1":
                    component = PinComponent.TexCoord1;
                    break;

                case "T2":
                    component = PinComponent.TexCoord2;
                    break;

                case "T3":
                    component = PinComponent.TexCoord3;
                    break;

                case "T4":
                    component = PinComponent.TexCoord4;
                    break;

                case "T5":
                    component = PinComponent.TexCoord5;
                    break;

                case "T6":
                    component = PinComponent.TexCoord6;
                    break;

                case "T7":
                    component = PinComponent.TexCoord7;
                    break;

                case "T8":
                    component = PinComponent.TexCoord8;
                    break;

                case "T9":
                    component = PinComponent.TexCoord9;
                    break;

                case "T10":
                    component = PinComponent.TexCoord10;
                    break;

                case "T11":
                    component = PinComponent.TexCoord11;
                    break;

                case "T12":
                    component = PinComponent.TexCoord12;
                    break;

                case "T13":
                    component = PinComponent.TexCoord13;
                    break;

                case "T14":
                    component = PinComponent.TexCoord14;
                    break;

                case "T15":
                    component = PinComponent.TexCoord15;
                    break;

                case "U0":
                    component = PinComponent.User0;
                    break;

                case "U1":
                    component = PinComponent.User1;
                    break;

                case "U2":
                    component = PinComponent.User2;
                    break;

                case "U3":
                    component = PinComponent.User3;
                    break;

                case "U4":
                    component = PinComponent.User4;
                    break;

                case "U5":
                    component = PinComponent.User5;
                    break;

                default:
                    throw new InvalidVertexFormatException("Unknown component.");
                }

                // We first extract attributes.
                string f = split[1];


                // We extact format.
                switch (f)
                {
                case "I":
                    format = PinFormat.Integer;
                    break;

                case "Ix2":
                    format = PinFormat.Integerx2;
                    break;

                case "Ix3":
                    format = PinFormat.Integerx3;
                    break;

                case "Ix4":
                    format = PinFormat.Integerx4;
                    break;

                case "UI":
                    format = PinFormat.UInteger;
                    break;

                case "UIx2":
                    format = PinFormat.UIntegerx2;
                    break;

                case "UIx3":
                    format = PinFormat.UIntegerx3;
                    break;

                case "UIx4":
                    format = PinFormat.UIntegerx4;
                    break;

                case "F":
                    format = PinFormat.Float;
                    break;

                case "Fx2":
                    format = PinFormat.Floatx2;
                    break;

                case "Fx3":
                    format = PinFormat.Floatx3;
                    break;

                case "Fx4":
                    format = PinFormat.Floatx4;
                    break;

                // TODO: add others
                default:
                    throw new InvalidVertexFormatException("The vertex format not recognised.");
                }
            }
Beispiel #14
0
            /// <summary>
            /// Obtains short name of component.
            /// </summary>
            /// <param name="component">The component.</param>
            /// <returns>Components name.</returns>
            public static string ToString(PinComponent component)
            {
                string c = null;

                switch (component)
                {
                case PinComponent.Position:
                    c = "P";
                    break;

                case PinComponent.Normal:
                    c = "N";
                    break;

                case PinComponent.Colour:
                    c = "C";
                    break;

                case PinComponent.SecondaryColour:
                    c = "SC";
                    break;

                case PinComponent.BlendWeights:
                    c = "BW";
                    break;

                case PinComponent.BlendIndices:
                    c = "BI";
                    break;

                case PinComponent.BiNormal:
                    c = "B";
                    break;

                case PinComponent.Tangent:
                    c = "T";
                    break;

                case PinComponent.TexCoord0:
                    c = "T0";
                    break;

                case PinComponent.TexCoord1:
                    c = "T1";
                    break;

                case PinComponent.TexCoord2:
                    c = "T2";
                    break;

                case PinComponent.TexCoord3:
                    c = "T3";
                    break;

                case PinComponent.TexCoord4:
                    c = "T4";
                    break;

                case PinComponent.TexCoord5:
                    c = "T5";
                    break;

                case PinComponent.TexCoord6:
                    c = "T6";
                    break;

                case PinComponent.TexCoord7:
                    c = "T7";
                    break;

                case PinComponent.TexCoord8:
                    c = "T8";
                    break;

                case PinComponent.TexCoord9:
                    c = "T9";
                    break;

                case PinComponent.TexCoord10:
                    c = "T10";
                    break;

                case PinComponent.TexCoord11:
                    c = "T11";
                    break;

                case PinComponent.TexCoord12:
                    c = "T12";
                    break;

                case PinComponent.TexCoord13:
                    c = "T13";
                    break;

                case PinComponent.TexCoord14:
                    c = "T14";
                    break;

                case PinComponent.TexCoord15:
                    c = "T15";
                    break;

                case PinComponent.User0:
                    c = "U0";
                    break;

                case PinComponent.User1:
                    c = "U1";
                    break;

                case PinComponent.User2:
                    c = "U2";
                    break;

                case PinComponent.User3:
                    c = "U3";
                    break;

                case PinComponent.User4:
                    c = "U4";
                    break;

                case PinComponent.User5:
                    c = "U5";
                    break;

                default:
                    break;
                }
                return(c);
            }
Beispiel #15
0
 /// <summary>
 /// Input int4.
 /// </summary>
 /// <param name="component"></param>
 /// <returns></returns>
 public Integerx4 InputInteger4(PinComponent component)
 {
     dag.InputOperation.AddInput(component, PinFormat.Integerx4);
     return(new Integerx4(dag.InputOperation.PinAsOutput(component), this));
 }
Beispiel #16
0
 /// <summary>
 /// Outputs data.
 /// </summary>
 public void Output(PinComponent component, PinBinder binder)
 {
     dag.OutputOperation.AddComponentAndLink(component, binder.Pin);
 }
Beispiel #17
0
 /// <summary>
 /// Is component available.
 /// </summary>
 /// <param name="c"></param>
 /// <returns></returns>
 public bool HasComponent(PinComponent c)
 {
     return((c & components) != 0);
 }
Beispiel #18
0
 /// <summary>
 /// Input uint.
 /// </summary>
 /// <param name="component"></param>
 /// <returns></returns>
 public UIntegerx1 InputUInteger1(PinComponent component)
 {
     dag.InputOperation.AddInput(component, PinFormat.UInteger);
     return(new UIntegerx1(dag.InputOperation.PinAsOutput(component), this));
 }
Beispiel #19
0
 /// <summary>
 /// Construction of element.
 /// </summary>
 /// <param name="c">The component.</param>
 /// <param name="fmt">The format.</param>
 internal Element(PinComponent c, PinFormat fmt)
 {
     component = c;
     format    = fmt;
     offset    = 0;
 }
Beispiel #20
0
 /// <summary>
 /// Input float2x2.
 /// </summary>
 /// <param name="component"></param>
 /// <returns></returns>
 public Float2x2 InputFloat2x2(PinComponent component)
 {
     dag.InputOperation.AddInput(component, PinFormat.Float2x2);
     return(new Float2x2(dag.InputOperation.PinAsOutput(component), this));
 }
Beispiel #21
0
 /// <summary>
 /// One format descriptor.
 /// </summary>
 public PinDescriptor(PinFormat fmt, [NotNull] string desc, PinComponent c)
 {
     formats      = new PinFormat[] { fmt };
     symbolicName = desc;
     component    = c;
 }