コード例 #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));
        }
コード例 #2
0
        public static Vertices <TVertexType> CreateRawDataVertices(DeviceContext context, TVertexType[] data, VertexElement[] elements)
        {
            if (typeof(byte) != typeof(TVertexType))
            {
                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 <TVertexType>(context, data, elements, stride));
        }