OSDN Git Service

Use int[] instead of IntIntMap
authorXoppa <contact@xoppa.nl>
Tue, 9 Jul 2013 15:35:48 +0000 (17:35 +0200)
committerXoppa <contact@xoppa.nl>
Tue, 9 Jul 2013 15:35:48 +0000 (17:35 +0200)
backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/emu/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java
gdx/src/com/badlogic/gdx/graphics/Mesh.java
gdx/src/com/badlogic/gdx/graphics/glutils/VertexArray.java
gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java
gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObjectSubData.java
gdx/src/com/badlogic/gdx/graphics/glutils/VertexData.java

index a39363e..2b3381d 100644 (file)
@@ -194,8 +194,17 @@ public class VertexBufferObject implements VertexData {
        /** Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElements\r
         * \r
         * @param shader the shader */\r
+       /** Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElements\r
+        * \r
+        * @param shader the shader */\r
+       @Override\r
        public void bind (ShaderProgram shader) {\r
-               GL20 gl = Gdx.gl20;\r
+               bind(shader, null);\r
+       }\r
+       \r
+       @Override\r
+       public void bind (ShaderProgram shader, int[] locations) {\r
+               final GL20 gl = Gdx.gl20;\r
 \r
                gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, bufferHandle);\r
                if (isDirty) {\r
@@ -203,18 +212,37 @@ public class VertexBufferObject implements VertexData {
                        isDirty = false;\r
                }\r
 \r
-               int numAttributes = attributes.size();\r
-               for (int i = 0; i < numAttributes; i++) {\r
-                       VertexAttribute attribute = attributes.get(i);\r
-                       shader.enableVertexAttribute(attribute.alias);\r
-                       int colorType = GL20.GL_FLOAT;\r
-                       boolean normalize = false;\r
-                       if (attribute.usage == Usage.ColorPacked) {\r
-                               colorType = GL20.GL_UNSIGNED_BYTE;\r
-                               normalize = true;\r
+               final int numAttributes = attributes.size();\r
+               if (locations == null) {\r
+                       for (int i = 0; i < numAttributes; i++) {\r
+                               final VertexAttribute attribute = attributes.get(i);\r
+                               final int location = shader.getAttributeLocation(attribute.alias);\r
+                               if (location < 0)\r
+                                       continue;\r
+                               shader.enableVertexAttribute(location);\r
+       \r
+                               if (attribute.usage == Usage.ColorPacked)\r
+                                       shader.setVertexAttribute(location, attribute.numComponents, GL20.GL_UNSIGNED_BYTE, true, attributes.vertexSize,\r
+                                               attribute.offset);\r
+                               else\r
+                                       shader.setVertexAttribute(location, attribute.numComponents, GL20.GL_FLOAT, false, attributes.vertexSize,\r
+                                               attribute.offset);\r
+                       }\r
+               } else {\r
+                       for (int i = 0; i < numAttributes; i++) {\r
+                               final VertexAttribute attribute = attributes.get(i);\r
+                               final int location = locations[i];\r
+                               if (location < 0)\r
+                                       continue;\r
+                               shader.enableVertexAttribute(location);\r
+       \r
+                               if (attribute.usage == Usage.ColorPacked)\r
+                                       shader.setVertexAttribute(location, attribute.numComponents, GL20.GL_UNSIGNED_BYTE, true, attributes.vertexSize,\r
+                                               attribute.offset);\r
+                               else\r
+                                       shader.setVertexAttribute(location, attribute.numComponents, GL20.GL_FLOAT, false, attributes.vertexSize,\r
+                                               attribute.offset);\r
                        }\r
-                       shader.setVertexAttribute(attribute.alias, attribute.numComponents, colorType, normalize, attributes.vertexSize,\r
-                               attribute.offset);\r
                }\r
                isBound = true;\r
        }\r
@@ -252,16 +280,29 @@ public class VertexBufferObject implements VertexData {
                gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);\r
                isBound = false;\r
        }\r
-\r
+       \r
        /** Unbinds this VertexBufferObject.\r
         * \r
         * @param shader the shader */\r
-       public void unbind (ShaderProgram shader) {\r
-               GL20 gl = Gdx.gl20;\r
-               int numAttributes = attributes.size();\r
-               for (int i = 0; i < numAttributes; i++) {\r
-                       VertexAttribute attribute = attributes.get(i);\r
-                       shader.disableVertexAttribute(attribute.alias);\r
+       @Override\r
+       public void unbind (final ShaderProgram shader) {\r
+               unbind(shader, null);\r
+       }\r
+       \r
+       @Override\r
+       public void unbind (final ShaderProgram shader, final int[] locations) {\r
+               final GL20 gl = Gdx.gl20;\r
+               final int numAttributes = attributes.size();\r
+               if (locations == null) {\r
+                       for (int i = 0; i < numAttributes; i++) {\r
+                               shader.disableVertexAttribute(attributes.get(i).alias);\r
+                       }\r
+               } else {\r
+                       for (int i = 0; i < numAttributes; i++) {\r
+                               final int location = locations[i];\r
+                               if (location >= 0)\r
+                                       shader.disableVertexAttribute(location);\r
+                       }\r
                }\r
                gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);\r
                isBound = false;\r
index 0751a71..dff092b 100644 (file)
@@ -42,7 +42,6 @@ import com.badlogic.gdx.math.Vector3;
 import com.badlogic.gdx.math.collision.BoundingBox;\r
 import com.badlogic.gdx.utils.Disposable;\r
 import com.badlogic.gdx.utils.GdxRuntimeException;\r
-import com.badlogic.gdx.utils.IntIntMap;\r
 \r
 /** <p>\r
  * A Mesh holds vertices composed of attributes specified by a {@link VertexAttributes} instance. The vertices are held either in\r
@@ -466,8 +465,8 @@ public class Mesh implements Disposable {
         * ES 2.0 and when auto-bind is disabled.\r
         * \r
         * @param shader the shader (does not bind the shader) \r
-        * @param locations map containing the attribute locations. */\r
-       public void bind (final ShaderProgram shader, final IntIntMap locations) {\r
+        * @param locations array containing the attribute locations. */\r
+       public void bind (final ShaderProgram shader, final int[] locations) {\r
                if (!Gdx.graphics.isGL20Available()) throw new IllegalStateException("can't use this render method with OpenGL ES 1.x");\r
 \r
                vertices.bind(shader, locations);\r
@@ -486,8 +485,8 @@ public class Mesh implements Disposable {
         * ES 1.x and when auto-bind is disabled.\r
         * \r
         * @param shader the shader (does not unbind the shader)\r
-        * @param locations map containing the attribute locations. */\r
-       public void unbind (final ShaderProgram shader, final IntIntMap locations) {\r
+        * @param locations array containing the attribute locations. */\r
+       public void unbind (final ShaderProgram shader, final int[] locations) {\r
                if (!Gdx.graphics.isGL20Available()) {\r
                        throw new IllegalStateException("can't use this render method with OpenGL ES 1.x");\r
                }\r
index 0e4261b..afef1b6 100644 (file)
@@ -28,7 +28,6 @@ import com.badlogic.gdx.graphics.VertexAttribute;
 import com.badlogic.gdx.graphics.VertexAttributes;\r
 import com.badlogic.gdx.graphics.VertexAttributes.Usage;\r
 import com.badlogic.gdx.utils.BufferUtils;\r
-import com.badlogic.gdx.utils.IntIntMap;\r
 \r
 /** <p>\r
  * Convenience class for working with OpenGL vertex arrays. It interleaves all data in the order you specified in the constructor\r
@@ -184,7 +183,7 @@ public class VertexArray implements VertexData {
        }\r
        \r
        @Override\r
-       public void bind (final ShaderProgram shader, final IntIntMap locations) {\r
+       public void bind (final ShaderProgram shader, final int[] locations) {\r
                final GL20 gl = Gdx.gl20;\r
                final int numAttributes = attributes.size();\r
                byteBuffer.limit(buffer.limit() * 4);\r
@@ -207,7 +206,7 @@ public class VertexArray implements VertexData {
                } else {\r
                        for (int i = 0; i < numAttributes; i++) {\r
                                final VertexAttribute attribute = attributes.get(i);\r
-                               final int location = locations.get(attribute.getKey(), -1);\r
+                               final int location = locations[i];\r
                                if (location < 0)\r
                                        continue;\r
                                shader.enableVertexAttribute(location);\r
@@ -233,7 +232,7 @@ public class VertexArray implements VertexData {
        }\r
        \r
        @Override\r
-       public void unbind (ShaderProgram shader, IntIntMap locations) {\r
+       public void unbind (ShaderProgram shader, int[] locations) {\r
                final GL20 gl = Gdx.gl20;\r
                final int numAttributes = attributes.size();\r
                if (locations == null) {\r
@@ -242,7 +241,7 @@ public class VertexArray implements VertexData {
                        }\r
                } else {\r
                        for (int i = 0; i < numAttributes; i++) {\r
-                               final int location = locations.get(attributes.get(i).getKey(), -1);\r
+                               final int location = locations[i];\r
                                if (location >= 0)\r
                                        shader.disableVertexAttribute(location);\r
                        }\r
index d161bef..4f8cfee 100644 (file)
@@ -28,7 +28,6 @@ import com.badlogic.gdx.graphics.VertexAttribute;
 import com.badlogic.gdx.graphics.VertexAttributes;\r
 import com.badlogic.gdx.graphics.VertexAttributes.Usage;\r
 import com.badlogic.gdx.utils.BufferUtils;\r
-import com.badlogic.gdx.utils.IntIntMap;\r
 \r
 /** <p>\r
  * A {@link VertexData} implementation based on OpenGL vertex buffer objects.\r
@@ -199,11 +198,13 @@ public class VertexBufferObject implements VertexData {
        /** Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElements\r
         * \r
         * @param shader the shader */\r
+       @Override\r
        public void bind (ShaderProgram shader) {\r
                bind(shader, null);\r
        }\r
        \r
-       public void bind (ShaderProgram shader, IntIntMap locations) {\r
+       @Override\r
+       public void bind (ShaderProgram shader, int[] locations) {\r
                final GL20 gl = Gdx.gl20;\r
 \r
                gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, bufferHandle);\r
@@ -232,7 +233,7 @@ public class VertexBufferObject implements VertexData {
                } else {\r
                        for (int i = 0; i < numAttributes; i++) {\r
                                final VertexAttribute attribute = attributes.get(i);\r
-                               final int location = locations.get(attribute.getKey(), -1);\r
+                               final int location = locations[i];\r
                                if (location < 0)\r
                                        continue;\r
                                shader.enableVertexAttribute(location);\r
@@ -248,7 +249,6 @@ public class VertexBufferObject implements VertexData {
                isBound = true;\r
        }\r
 \r
-       /** {@inheritDoc} */\r
        @Override\r
        public void unbind () {\r
                GL11 gl = Gdx.gl11;\r
@@ -291,7 +291,7 @@ public class VertexBufferObject implements VertexData {
        }\r
        \r
        @Override\r
-       public void unbind (final ShaderProgram shader, final IntIntMap locations) {\r
+       public void unbind (final ShaderProgram shader, final int[] locations) {\r
                final GL20 gl = Gdx.gl20;\r
                final int numAttributes = attributes.size();\r
                if (locations == null) {\r
@@ -300,7 +300,7 @@ public class VertexBufferObject implements VertexData {
                        }\r
                } else {\r
                        for (int i = 0; i < numAttributes; i++) {\r
-                               final int location = locations.get(attributes.get(i).getKey(), -1);\r
+                               final int location = locations[i];\r
                                if (location >= 0)\r
                                        shader.disableVertexAttribute(location);\r
                        }\r
index 331e3f8..3535ab4 100644 (file)
@@ -29,7 +29,6 @@ import com.badlogic.gdx.graphics.VertexAttributes;
 import com.badlogic.gdx.graphics.VertexAttributes.Usage;\r
 import com.badlogic.gdx.utils.BufferUtils;\r
 import com.badlogic.gdx.utils.GdxRuntimeException;\r
-import com.badlogic.gdx.utils.IntIntMap;\r
 \r
 /** <p>\r
  * A {@link VertexData} implementation based on OpenGL vertex buffer objects.\r
@@ -223,7 +222,7 @@ public class VertexBufferObjectSubData implements VertexData {
        }\r
        \r
        @Override\r
-       public void bind (final ShaderProgram shader, final IntIntMap locations) {\r
+       public void bind (final ShaderProgram shader, final int[] locations) {\r
                final GL20 gl = Gdx.gl20;\r
 \r
                gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, bufferHandle);\r
@@ -252,7 +251,7 @@ public class VertexBufferObjectSubData implements VertexData {
                } else {\r
                        for (int i = 0; i < numAttributes; i++) {\r
                                final VertexAttribute attribute = attributes.get(i);\r
-                               final int location = locations.get(attribute.getKey(), -1);\r
+                               final int location = locations[i];\r
                                if (location < 0)\r
                                        continue;\r
                                shader.enableVertexAttribute(location);\r
@@ -310,7 +309,7 @@ public class VertexBufferObjectSubData implements VertexData {
        }\r
        \r
        @Override\r
-       public void unbind (final ShaderProgram shader, final IntIntMap locations) {\r
+       public void unbind (final ShaderProgram shader, final int[] locations) {\r
                final GL20 gl = Gdx.gl20;\r
                final int numAttributes = attributes.size();\r
                if (locations == null) {\r
@@ -319,7 +318,7 @@ public class VertexBufferObjectSubData implements VertexData {
                        }\r
                } else {\r
                        for (int i = 0; i < numAttributes; i++) {\r
-                               final int location = locations.get(attributes.get(i).getKey(), -1);\r
+                               final int location = locations[i];\r
                                if (location >= 0)\r
                                        shader.disableVertexAttribute(location);\r
                        }\r
index ae16ba5..ac9161b 100644 (file)
@@ -69,15 +69,15 @@ public interface VertexData extends Disposable {
        public void bind (ShaderProgram shader);\r
        \r
        /** Binds this VertexData for rendering via glDrawArrays or glDrawElements.\r
-        * @param locations map containing the attribute locations. */\r
-       public void bind (ShaderProgram shader, IntIntMap locations);\r
+        * @param locations array containing the attribute locations. */\r
+       public void bind (ShaderProgram shader, int[] locations);\r
 \r
        /** Unbinds this VertexData. */\r
        public void unbind (ShaderProgram shader);\r
        \r
        /** Unbinds this VertexData. \r
-        * @param locations map containing the attribute locations. */\r
-       public void unbind (ShaderProgram shader, IntIntMap locations);\r
+        * @param locations array containing the attribute locations. */\r
+       public void unbind (ShaderProgram shader, int[] locations);\r
 \r
        /** Disposes this VertexData and all its associated OpenGL resources. */\r
        public void dispose ();\r