OSDN Git Service

(no commit message)
authornathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sun, 6 Feb 2011 13:21:49 +0000 (13:21 +0000)
committernathan.sweet <nathan.sweet@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sun, 6 Feb 2011 13:21:49 +0000 (13:21 +0000)
gdx/src/com/badlogic/gdx/graphics/Texture.java
tests/gdx-tests-android/assets/data/raw.bin [new file with mode: 0644]
tests/gdx-tests-jogl/data/raw.bin [new file with mode: 0644]
tests/gdx-tests-lwjgl/data/raw.bin [new file with mode: 0644]
tests/gdx-tests/src/com/badlogic/gdx/tests/TextureDataTest.java [new file with mode: 0644]
tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java

index 2c3e8bf..5397384 100644 (file)
@@ -21,6 +21,7 @@ import com.badlogic.gdx.files.FileHandle;
 import com.badlogic.gdx.graphics.Pixmap.Format;\r
 import com.badlogic.gdx.utils.BufferUtils;\r
 import com.badlogic.gdx.utils.GdxRuntimeException;\r
+import com.badlogic.gdx.utils.MathUtils;\r
 \r
 /**\r
  * <p>\r
@@ -238,7 +239,7 @@ public class Texture {
        private void uploadImageData(Pixmap pixmap) {                                   \r
                this.width = pixmap.getWidth();\r
                this.height = pixmap.getHeight();\r
-               if(!isPowerOfTwo(width) || !isPowerOfTwo(height))\r
+               if(!MathUtils.isPowerOfTwo(width) || !MathUtils.isPowerOfTwo(height))\r
                        throw new GdxRuntimeException("texture width and height must be powers of two");\r
                Gdx.gl.glBindTexture(GL10.GL_TEXTURE_2D, glHandle);\r
                Gdx.gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels());\r
@@ -264,10 +265,6 @@ public class Texture {
                        pixmap.dispose();\r
                }               \r
        }\r
-       \r
-       private static boolean isPowerOfTwo (int value) {\r
-               return ((value != 0) && (value & (value - 1)) == 0);\r
-       }\r
 \r
        /**\r
         * Binds this texture. The texture will be bound to the currently active texture unit specified via\r
diff --git a/tests/gdx-tests-android/assets/data/raw.bin b/tests/gdx-tests-android/assets/data/raw.bin
new file mode 100644 (file)
index 0000000..de4a0d5
Binary files /dev/null and b/tests/gdx-tests-android/assets/data/raw.bin differ
diff --git a/tests/gdx-tests-jogl/data/raw.bin b/tests/gdx-tests-jogl/data/raw.bin
new file mode 100644 (file)
index 0000000..de4a0d5
Binary files /dev/null and b/tests/gdx-tests-jogl/data/raw.bin differ
diff --git a/tests/gdx-tests-lwjgl/data/raw.bin b/tests/gdx-tests-lwjgl/data/raw.bin
new file mode 100644 (file)
index 0000000..de4a0d5
Binary files /dev/null and b/tests/gdx-tests-lwjgl/data/raw.bin differ
diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/TextureDataTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/TextureDataTest.java
new file mode 100644 (file)
index 0000000..2c3d9cb
--- /dev/null
@@ -0,0 +1,78 @@
+/*\r
+ * Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the\r
+ * License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS"\r
+ * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language\r
+ * governing permissions and limitations under the License.\r
+ */\r
+\r
+package com.badlogic.gdx.tests;\r
+\r
+import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.nio.ByteBuffer;\r
+import java.nio.ByteOrder;\r
+\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.files.FileHandle;\r
+import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.graphics.TextureData;\r
+import com.badlogic.gdx.graphics.g2d.Sprite;\r
+import com.badlogic.gdx.graphics.g2d.SpriteBatch;\r
+import com.badlogic.gdx.tests.utils.GdxTest;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
+\r
+public class TextureDataTest extends GdxTest {\r
+       private SpriteBatch spriteBatch;\r
+       private Sprite sprite;\r
+\r
+       public void create () {\r
+               spriteBatch = new SpriteBatch();\r
+\r
+               sprite = new Sprite(new Texture(new TextureData() {\r
+                       public void load () {\r
+                               FileHandle file = Gdx.files.internal("data/raw.bin");\r
+                               InputStream input = file.read();\r
+                               ByteBuffer buffer = ByteBuffer.allocateDirect((int)file.length());\r
+                               buffer.order(ByteOrder.nativeOrder());\r
+                               byte[] bytes = new byte[1024];\r
+                               try {\r
+                                       while (true) {\r
+                                               int length = input.read(bytes);\r
+                                               if (length == -1) break;\r
+                                               buffer.put(bytes, 0, length);\r
+                                       }\r
+                               } catch (IOException ex) {\r
+                                       throw new GdxRuntimeException(ex);\r
+                               }\r
+                               buffer.flip();\r
+                               Gdx.gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, getWidth(), getHeight(), 0, GL10.GL_RGBA,\r
+                                       GL10.GL_UNSIGNED_SHORT_4_4_4_4, buffer);\r
+                       }\r
+\r
+                       public int getWidth () {\r
+                               return 512;\r
+                       }\r
+\r
+                       public int getHeight () {\r
+                               return 512;\r
+                       }\r
+               }));\r
+       }\r
+\r
+       public void render () {\r
+               spriteBatch.begin();\r
+               sprite.draw(spriteBatch);\r
+               spriteBatch.end();\r
+       }\r
+\r
+       public boolean needsGL20 () {\r
+               return false;\r
+       }\r
+}\r
index 31e4fa1..0eeddf3 100644 (file)
@@ -69,6 +69,7 @@ import com.badlogic.gdx.tests.StageTest;
 import com.badlogic.gdx.tests.TerrainTest;\r
 import com.badlogic.gdx.tests.TextInputDialogTest;\r
 import com.badlogic.gdx.tests.TextureAtlasTest;\r
+import com.badlogic.gdx.tests.TextureDataTest;\r
 import com.badlogic.gdx.tests.TextureRenderTest;\r
 import com.badlogic.gdx.tests.TileTest;\r
 import com.badlogic.gdx.tests.TiledMapTest;\r
@@ -147,6 +148,7 @@ public class GdxTests
                SpritePerformanteTest2.class,\r
                StageTest.class,\r
                TerrainTest.class,              \r
+               TextureDataTest.class,\r
                TextureAtlasTest.class,\r
                TextInputDialogTest.class,\r
                TextureRenderTest.class,\r