OSDN Git Service

added useful methods to VertexAttributes class to find VertexAttribute for a specifie...
authorAriel Coppes <ariel.coppes@gemserk.com>
Tue, 25 Sep 2012 18:50:58 +0000 (15:50 -0300)
committerAriel Coppes <ariel.coppes@gemserk.com>
Tue, 25 Sep 2012 18:50:58 +0000 (15:50 -0300)
gdx/src/com/badlogic/gdx/graphics/VertexAttributes.java

index a18ae35..6bd8ae6 100644 (file)
@@ -53,6 +53,23 @@ public final class VertexAttributes {
                vertexSize = calculateOffsets();\r
        }\r
 \r
+       /** Returns the offset for the first VertexAttribute with the specified usage.\r
+        * @param usage The usage of the VertexAttribute. */\r
+       public int getOffset (int usage) {\r
+               VertexAttribute vertexAttribute = findByUsage(usage);\r
+               if (vertexAttribute == null) return 0;\r
+               return vertexAttribute.offset / 4;\r
+       }\r
+\r
+       /** Returns the first VertexAttribute for the given usage.\r
+        * @param usage The usage of the VertexAttribute to find. */\r
+       public VertexAttribute findByUsage (int usage) {\r
+               int len = size();\r
+               for (int i = 0; i < len; i++)\r
+                       if (get(i).usage == usage) return get(i);\r
+               return null;\r
+       }\r
+\r
        private int calculateOffsets () {\r
                int count = 0;\r
                for (int i = 0; i < attributes.length; i++) {\r