OSDN Git Service

[fixed] SpriteCache to not use autobind. Messes up the test tho!
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Mon, 15 Nov 2010 03:03:13 +0000 (03:03 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Mon, 15 Nov 2010 03:03:13 +0000 (03:03 +0000)
gdx/src/com/badlogic/gdx/graphics/SpriteCache.java
gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObject.java
gdx/src/com/badlogic/gdx/graphics/glutils/IndexBufferObjectSubData.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

index 0f3dc52..5c04a87 100644 (file)
@@ -28,8 +28,9 @@ public class SpriteCache {
        }\r
 \r
        public SpriteCache (int size) {\r
-               this.mesh = new Mesh(true, size * 4, size * 6, new VertexAttribute(Usage.Position, 2, "a_position"), new VertexAttribute(\r
+               mesh = new Mesh(true, size * 4, size * 6, new VertexAttribute(Usage.Position, 2, "a_position"), new VertexAttribute(\r
                        Usage.ColorPacked, 4, "a_color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));\r
+               mesh.setAutoBind(false);\r
 \r
                short[] indices = new short[size * 6];\r
                int len = size * 6;\r
@@ -366,6 +367,8 @@ public class SpriteCache {
                        gl.glLoadMatrixf(projectionMatrix.val, 0);\r
                        gl.glMatrixMode(GL10.GL_MODELVIEW);\r
                        gl.glLoadMatrixf(transformMatrix.val, 0);\r
+                       \r
+                       mesh.bind();\r
                } else {\r
                        combinedMatrix.set(projectionMatrix).mul(transformMatrix);\r
 \r
@@ -381,6 +384,8 @@ public class SpriteCache {
                        shader.begin();\r
                        shader.setUniformMatrix("u_projectionViewMatrix", combinedMatrix);\r
                        shader.setUniformi("u_texture", 0);\r
+\r
+                       mesh.bind(shader);\r
                }\r
                drawing = true;\r
        }\r
@@ -401,6 +406,7 @@ public class SpriteCache {
                        gl.glDisable(GL20.GL_BLEND);\r
                        gl.glDisable(GL20.GL_TEXTURE_2D);\r
                }\r
+               mesh.unbind();\r
        }\r
 \r
        public void draw (Cache cache) {\r
index b540e81..0e22a4e 100644 (file)
@@ -73,6 +73,7 @@ public class IndexBufferObject {
                        isDirect = true;\r
 //             }\r
                buffer = byteBuffer.asShortBuffer();\r
+               buffer.flip();\r
                bufferHandle = createBufferObject();\r
                usage = isStatic ? GL11.GL_STATIC_DRAW : GL11.GL_DYNAMIC_DRAW;\r
        }\r
index 5c3441e..fbb28b4 100644 (file)
@@ -74,6 +74,7 @@ public class IndexBufferObjectSubData {
 //             }\r
                usage = isStatic ? GL11.GL_STATIC_DRAW : GL11.GL_DYNAMIC_DRAW;\r
                buffer = byteBuffer.asShortBuffer();\r
+               buffer.flip();\r
                bufferHandle = createBufferObject();\r
        }\r
 \r
index 678d8a9..85b3def 100644 (file)
@@ -48,6 +48,7 @@ public class VertexArray implements VertexData {
                                * numVertices);\r
                byteBuffer.order(ByteOrder.nativeOrder());\r
                buffer = byteBuffer.asFloatBuffer();\r
+               buffer.flip();\r
        }\r
 \r
        /**\r
@@ -71,7 +72,7 @@ public class VertexArray implements VertexData {
         */\r
        @Override\r
        public int getNumVertices() {\r
-               return byteBuffer.limit() / attributes.vertexSize;\r
+               return buffer.limit();\r
        }\r
 \r
        /**\r
index 59a5465..f846174 100644 (file)
@@ -118,7 +118,7 @@ public class VertexBufferObject implements VertexData {
         * {@inheritDoc}\r
         */\r
        public int getNumMaxVertices() {\r
-               return byteBuffer.capacity() / attributes.vertexSize;\r
+               return buffer.capacity();\r
        }\r
 \r
        /**\r
index 5b98b1c..1ca0ce3 100644 (file)
@@ -86,6 +86,7 @@ public class VertexBufferObjectSubData implements VertexData {
 //             }\r
                usage = isStatic ? GL11.GL_STATIC_DRAW : GL11.GL_DYNAMIC_DRAW;\r
                buffer = byteBuffer.asFloatBuffer();\r
+               buffer.flip();\r
                bufferHandle = createBufferObject();\r
        }\r
 \r
@@ -118,14 +119,14 @@ public class VertexBufferObjectSubData implements VertexData {
         */\r
        @Override\r
        public int getNumVertices() {\r
-               return byteBuffer.limit() / attributes.vertexSize;\r
+               return buffer.limit();\r
        }\r
 \r
        /**\r
         * {@inheritDoc}\r
         */\r
        public int getNumMaxVertices() {\r
-               return byteBuffer.capacity() / attributes.vertexSize;\r
+               return buffer.capacity();\r
        }\r
 \r
        /**\r