Beispiel #1
0
        private void Init(Type[] types)
        {
            this.types = types;

            usageIndices = new byte[types.Length];
            int index = 0;

            VertexElement[] vertexElements = new VertexElement[types.Length];
            semantics = new Semantic[types.Length];

            SortedList usages = new SortedList( );

            foreach (Type type in types)
            {
                VertexElement element = StreamFactory.Instance.VertexElement(type);
                element.Stream = (short)index;
                element.Offset = 0;
                if (!usages.Contains(element.DeclarationUsage))
                {
                    usages[element.DeclarationUsage] = (byte)0;
                }
                element.UsageIndex = usageIndices[index] = (byte)usages[element.DeclarationUsage];
                usages[element.DeclarationUsage] = (byte)((byte)usages[element.DeclarationUsage] + 1);
                vertexElements[index]            = element;
                semantics[index] = new Semantic(element.DeclarationUsage, element.UsageIndex);
                index++;
            }
            vertexDeclaration = Device.Instance.CreateVertexDeclaration(vertexElements);
        }
Beispiel #2
0
        /// <summary>
        /// Returns the index of the <see cref="IVertexStream"/> for a given <see cref="Semantic"/> description.
        /// </summary>
        /// <param name="sem">The <see cref="Semantic"/> to get stream for.</param>
        /// <returns>The index of the <see cref="IVertexStream"/> for a given <see cref="Semantic"/> description.</returns>
        public int GetIndex(Semantic sem)
        {
            int counter = 0;

            for (int i = 0; i < types.Length; i++)
            {
                if (StreamFactory.Instance.VertexElement(types[i]).DeclarationUsage == sem.Usage)
                {
                    if (counter == sem.UsageIndex)
                    {
                        return(i);
                    }
                    counter++;
                }
            }
            throw new System.IndexOutOfRangeException("The number of streams of " + sem.ToString() + " are less then the requested number!");
        }
Beispiel #3
0
 /// <summary>
 /// Returns an <see cref="IVertexStream"/> via its semantic.
 /// </summary>
 public IVertexStream this[Semantic sem] {
     get {
         return(this[format.GetIndex(sem)]);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Returns true if a stream with the given semantic is contained by this <see cref="VertexFormat"/>.
 /// </summary>
 /// <param name="sem"><see cref="Semantic"/> to test for.</param>
 /// <returns>True if a stream with the given semantic is contained by this <see cref="VertexFormat"/>.</returns>
 public bool Contains(Semantic sem)
 {
     return(Count(sem.Usage) > sem.UsageIndex);
 }