Ejemplo n.º 1
0
        /// <summary>
        /// <para>Creates a vertex buffer that will map an array of float or vector primitives to a specified Vertex Usage and index</para>
        /// </summary>
        /// <param name="data"></param>
        /// <param name="elementUsage"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static Vertices <VertexType> CreateSingleElementVertices(VertexType[] data, VertexElementUsage elementUsage, int index)
        {
            if (typeof(float) != typeof(VertexType) &&
                typeof(Vector2) != typeof(VertexType) &&
                typeof(Vector3) != typeof(VertexType) &&
                typeof(Vector4) != typeof(VertexType) &&
                typeof(Microsoft.Xna.Framework.Graphics.PackedVector.HalfVector2) != typeof(VertexType) &&
                typeof(Microsoft.Xna.Framework.Graphics.PackedVector.HalfVector4) != typeof(VertexType))
            {
                throw new ArgumentException("Only float and vector types are supported for single element vertex buffers");
            }

            if (data == null)
            {
                throw new ArgumentNullException();
            }
            if (index >= 16 || index < 0)
            {
                throw new ArgumentException("index");
            }

            VertexElementFormat format = VertexDeclarationBuilder.DetermineFormat(typeof(VertexType));

            VertexElement[] elements = new VertexElement[] { new VertexElement(0, 0, format, VertexElementMethod.Default, elementUsage, (byte)index) };

            int stride = VertexElementAttribute.CalculateVertexStride(elements);

            return(new Vertices <VertexType>(data, elements, stride));
        }
Ejemplo n.º 2
0
 public VertexDeclarationBuilder()
 {
     declarationMapping = new Dictionary <Type, VertexElement[]>();
     typeHash           = new Dictionary <Type, short>();
     hashingDecl        = new DeclarationHash(typeof(Vector3), typeHash, ref typeIndex);   //static to keep from GC messing
     Instance           = this;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets the size (in bytes) of a vertex element format
 /// </summary>
 /// <param name="format"></param>
 /// <returns></returns>
 public static int SizeOfFormatType(VertexElementFormat format)
 {
     return(VertexDeclarationBuilder.SizeOfFormatType(format));
 }