Esempio n. 1
0
        public static Vertices <TVertexType> CreateSingleElementVertices(DeviceContext context, TVertexType[] data, DeclarationUsage elementUsage, int index)
        {
            if (typeof(float) != typeof(TVertexType) &&
                typeof(Vector2) != typeof(TVertexType) &&
                typeof(Vector3) != typeof(TVertexType) &&
                typeof(Vector4) != typeof(TVertexType) &&
                typeof(Half2) != typeof(TVertexType) &&
                typeof(Half4) != typeof(TVertexType))
            {
                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");
            }

            DeclarationType format = VertexDeclarationBuilder.DetermineFormat(typeof(TVertexType));

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

            int stride = VertexElementAttribute.CalculateVertexStride(elements);

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