Subversion Repositories AndroidProjects

Rev

Blame | Last modification | View Log | RSS feed

package com.gebauz.bauzoid.graphics.model;

public class VertexAttribute
{
        // we only support a subset of the full SUX attribute list since OpenGL ES 2.0 can
        // only have 8 attributes per vertex
       
        public static final int POSITION = 0;
        public static final int COLOR = 1;
        public static final int NORMAL = 2;
        public static final int TEXCOORD0 = 3;
        public static final int TEXCOORD1 = 4;
        public static final int BLENDINDICES = 5;
        public static final int BLENDWEIGHTS = 6;
        public static final int GENERIC = 7;
       
        private int mAttribType = -1;
        private int mCoordsPerElement = 0;
        private int mByteOffset = 0;
       
        /** Constructor. */
        public VertexAttribute(int attribType, int coordsPerElement, int byteOffset)
        {
                mAttribType = attribType;
                mCoordsPerElement = coordsPerElement;
                mByteOffset = byteOffset;
        }
       
        /** Get the attribute type. */
        public final int getAttribType()
        {
                return mAttribType;
        }
       
        /** Get the number of coordinates per element - 2, 3 or 4. */
        public final int getCoordsPerElement()
        {
                return mCoordsPerElement;              
        }
       
        /** Get the byte offset within an element - the first one (or the only one in an individual stream) is always 0. */
        public final int getByteOffset()
        {
                return mByteOffset;
        }
       
        /** Check if valid attribute type. */
        public static final boolean isValidType(int type)
        {
                switch (type)
                {
                case 0: // Generic
                case 1: // Position
                case 2: // Normal
                case 3: // Color
                case 7: // TexCoord0
                case 8: // TexCoord1;
                case 15: // Blend Indices
                case 16: // Blend Weights
                        return true;
                default:
                        return false;          
                }
        }
       
        /** Convert SUX attribute type to internal. */
        public static final int toInternalType(int suxType)
        {
                switch (suxType)
                {
                case 0: return GENERIC;
                case 1: return POSITION;
                case 2: return NORMAL;
                case 3: return COLOR;
                case 7: return TEXCOORD0;
                case 8: return TEXCOORD1;
                case 15: return BLENDINDICES;
                case 16: return BLENDWEIGHTS;
                default: return -1;            
                }
        }
}