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
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
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
--- /dev/null
+/*\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
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
SpritePerformanteTest2.class,\r
StageTest.class,\r
TerrainTest.class, \r
+ TextureDataTest.class,\r
TextureAtlasTest.class,\r
TextInputDialogTest.class,\r
TextureRenderTest.class,\r