Esempio 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));
        }
Esempio n. 2
0
        /// <summary>
        /// [NOT VALIDATED] Use with caution. No validation is performed by this method. Creates a vertex buffer from a raw data array, using a user specified <see cref="VertexElement"/> array.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="elements"></param>
        /// <returns></returns>
        /// <remarks>This method is only here to get around some limitations of the XNA content pipeline</remarks>
        public static Vertices <VertexType> CreateRawDataVertices(VertexType[] data, VertexElement[] elements)
        {
            if (typeof(byte) != typeof(VertexType))
            {
                throw new ArgumentException("Only byte[] raw vertices are supported at this time");
            }
            if (data == null || elements == null)
            {
                throw new ArgumentNullException();
            }
            if (elements.Length == 0)
            {
                throw new ArgumentException();
            }

            int stride = VertexElementAttribute.CalculateVertexStride(elements);

            return(new Vertices <VertexType>(data, elements, stride));
        }