Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static VertexBaseType GetArrayBaseType(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (type == typeof(Single))
            {
                return(VertexBaseType.Float);
            }
            if (type == typeof(HalfFloat))
            {
                return(VertexBaseType.Half);
            }
            if (type == typeof(Int32))
            {
                return(VertexBaseType.Int);
            }
            if (type == typeof(UInt32))
            {
                return(VertexBaseType.UInt);
            }
            if (type == typeof(Int16))
            {
                return(VertexBaseType.Short);
            }
            if (type == typeof(UInt16))
            {
                return(VertexBaseType.UShort);
            }
            if (type == typeof(Byte))
            {
                return(VertexBaseType.UByte);
            }
            if (type == typeof(SByte))
            {
                return(VertexBaseType.Byte);
            }

            ArrayBufferItemAttribute attribute = (ArrayBufferItemAttribute)Attribute.GetCustomAttribute(type, typeof(ArrayBufferItemAttribute));

            if (attribute != null)
            {
                return(attribute.ArrayBaseType);
            }

            throw new ArgumentException(String.Format("unable to match type {0}", type.Name));
        }
Пример #2
0
        /// <summary>
        /// Get the corresponding <see cref="ArrayBufferItemType"/> from a <see cref="ArrayType"/>.
        /// </summary>
        /// <param name="type">
        /// A <see cref="ArrayType"/> indicating the structure describing the vertex array buffer item.
        /// </param>
        /// <returns>
        /// It returns a <see cref="ArrayBufferItemType"/> corresponding to <paramref name="type"/>.
        /// </returns>
        public static ArrayBufferItemType GetArrayType(Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            // Support .NET Framework types
            // Support OpenGL.Net.Math types
            // Support unknown types using ArrayBufferItemAttribute

            // Single-Precision Floating-Point Types
            if (type == typeof(Single))
            {
                return(ArrayBufferItemType.Float);
            }
            else if (type == typeof(Vertex2f))
            {
                return(ArrayBufferItemType.Float2);
            }
            else if (type == typeof(Vertex3f) || type == typeof(ColorRGBF))
            {
                return(ArrayBufferItemType.Float3);
            }
            else if (type == typeof(Vertex4f) || type == typeof(ColorRGBAF))
            {
                return(ArrayBufferItemType.Float4);
            }

            // Signed Integer Types

            else if (type == typeof(Int16))
            {
                return(ArrayBufferItemType.Short);
            }
            else if (type == typeof(Vertex2s))
            {
                return(ArrayBufferItemType.Short2);
            }
            else if (type == typeof(Vertex3s))
            {
                return(ArrayBufferItemType.Short3);
            }
            else if (type == typeof(Vertex4s))
            {
                return(ArrayBufferItemType.Short4);
            }

            else if (type == typeof(Int32))
            {
                return(ArrayBufferItemType.Int);
            }
            else if (type == typeof(Vertex2i))
            {
                return(ArrayBufferItemType.Int2);
            }
            else if (type == typeof(Vertex3i))
            {
                return(ArrayBufferItemType.Int3);
            }
            else if (type == typeof(Vertex4i))
            {
                return(ArrayBufferItemType.Int4);
            }

            // Unsigned Integer Types

            else if (type == typeof(UInt16))
            {
                return(ArrayBufferItemType.UShort);
            }
            else if (type == typeof(Vertex2us))
            {
                return(ArrayBufferItemType.UShort2);
            }
            else if (type == typeof(Vertex3us))
            {
                return(ArrayBufferItemType.UShort3);
            }
            else if (type == typeof(Vertex4us))
            {
                return(ArrayBufferItemType.UShort4);
            }

            else if (type == typeof(UInt32))
            {
                return(ArrayBufferItemType.UInt);
            }
            else if (type == typeof(Vertex2ui))
            {
                return(ArrayBufferItemType.UInt2);
            }
            else if (type == typeof(Vertex3ui) || type == typeof(ColorRGB96))
            {
                return(ArrayBufferItemType.UInt3);
            }
            else if (type == typeof(Vertex4ui))
            {
                return(ArrayBufferItemType.UInt4);
            }

            // Half-Precision Floating-Point Types

            else if (type == typeof(HalfFloat))
            {
                return(ArrayBufferItemType.Half);
            }
            else if (type == typeof(Vertex2hf))
            {
                return(ArrayBufferItemType.Half2);
            }
            else if (type == typeof(Vertex3hf))
            {
                return(ArrayBufferItemType.Half3);
            }
            else if (type == typeof(Vertex4hf))
            {
                return(ArrayBufferItemType.Half4);
            }

            // Single-Precision Floating-Point Matrix Types

            else if (type == typeof(Matrix4x4f))
            {
                return(ArrayBufferItemType.Float4x4);
            }

            // Double-Precision Floating-Point Matrix Types

            else if (type == typeof(Matrix4x4d))
            {
                return(ArrayBufferItemType.Double4x4);
            }

            else if (type == typeof(SByte))
            {
                return(ArrayBufferItemType.Byte);
            }
            else if (type == typeof(Byte))
            {
                return(ArrayBufferItemType.UByte);
            }
            else if (type == typeof(Double))
            {
                return(ArrayBufferItemType.Double);
            }

            else
            {
                ArrayBufferItemAttribute attribute = (ArrayBufferItemAttribute)Attribute.GetCustomAttribute(type, typeof(ArrayBufferItemAttribute));
                if (attribute != null)
                {
                    return(attribute.ArrayType);
                }
            }

            throw new ArgumentException("not corresponding information", "type");
        }