OSDN Git Service

[moved] GdxRuntimeException to utils
authorbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sun, 31 Oct 2010 02:12:42 +0000 (02:12 +0000)
committerbadlogicgames <badlogicgames@6c4fd544-2939-11df-bb46-9574ba5d0bfa>
Sun, 31 Oct 2010 02:12:42 +0000 (02:12 +0000)
[added] VertexArray and VertexBufferObject class (both implement VertexData)
[added] tests for the new classes.

36 files changed:
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidAudio.java
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFileHandle.java
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidFiles.java
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidGraphics.java
backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/AndroidTexture.java
backends/gdx-backend-desktop/src/com/badlogic/gdx/backends/desktop/JoglAudio.java
backends/gdx-backend-desktop/src/com/badlogic/gdx/backends/desktop/JoglAudioDevice.java
backends/gdx-backend-desktop/src/com/badlogic/gdx/backends/desktop/JoglAudioRecorder.java
backends/gdx-backend-desktop/src/com/badlogic/gdx/backends/desktop/JoglFileHandle.java
backends/gdx-backend-desktop/src/com/badlogic/gdx/backends/desktop/JoglFiles.java
backends/gdx-backend-desktop/src/com/badlogic/gdx/backends/desktop/JoglFont.java
backends/gdx-backend-desktop/src/com/badlogic/gdx/backends/desktop/JoglGraphics.java
backends/gdx-backend-desktop/src/com/badlogic/gdx/backends/desktop/JoglTexture.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglApplication.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglAudio.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglAudioDevice.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglAudioRecorder.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglFileHandle.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglFiles.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglFont.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglGL10.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglGL20.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglGraphics.java
backends/gdx-backend-lwjgl/src/com/badlogic/gdx/backends/desktop/LwjglTexture.java
extensions/particle-editor/src/com/badlogic/gdx/graphics/particles/ParticleEditor.java
extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/GdxCacheContext.java
extensions/twl/gdx-twl/src/com/badlogic/gdx/twl/renderer/TwlRenderer.java
gdx/src/com/badlogic/gdx/graphics/glutils/ShaderProgram.java
gdx/src/com/badlogic/gdx/graphics/glutils/VertexArray.java [new file with mode: 0644]
gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java [new file with mode: 0644]
gdx/src/com/badlogic/gdx/graphics/glutils/VertexData.java [new file with mode: 0644]
tests/gdx-tests-desktop/src/com/badlogic/gdx/tests/desktop/JoglDebugStarter.java
tests/gdx-tests/src/com/badlogic/gdx/tests/VertexArrayClassTest.java [new file with mode: 0644]
tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectClassTest.java [new file with mode: 0644]
tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTest.java
tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java

index 878dbd9..de882cb 100644 (file)
@@ -25,12 +25,12 @@ import android.media.MediaPlayer;
 import android.media.SoundPool;\r
 \r
 import com.badlogic.gdx.Audio;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.audio.AudioDevice;\r
 import com.badlogic.gdx.audio.AudioRecorder;\r
 import com.badlogic.gdx.audio.Music;\r
 import com.badlogic.gdx.audio.Sound;\r
 import com.badlogic.gdx.files.FileHandle;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * An implementation of the {@link Audio} interface for Android.\r
index 017238b..0bc01f0 100644 (file)
@@ -18,8 +18,8 @@ import java.io.InputStream;
 \r
 import android.content.res.AssetManager;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.files.FileHandle;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * A {@link FileHandle} implementation for Android. Encapsulates assets and files on the external storage device.\r
index 6d82e07..a02f35b 100644 (file)
@@ -24,8 +24,8 @@ import android.content.res.AssetManager;
 import android.os.Environment;\r
 \r
 import com.badlogic.gdx.Files;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.files.FileHandle;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * An implementation of the {@link Files} interface for Android. External files are stored and accessed relative to\r
index db2ce26..c1da292 100644 (file)
@@ -29,7 +29,6 @@ import android.view.Display;
 import android.view.View;\r
 \r
 import com.badlogic.gdx.Gdx;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.Graphics;\r
 import com.badlogic.gdx.RenderListener;\r
 import com.badlogic.gdx.backends.android.surfaceview.GLSurfaceView20;\r
@@ -50,6 +49,7 @@ import com.badlogic.gdx.graphics.Texture.TextureWrap;
 import com.badlogic.gdx.graphics.glutils.FrameBuffer;\r
 import com.badlogic.gdx.graphics.glutils.ShaderProgram;\r
 import com.badlogic.gdx.math.WindowedMean;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * An implementation of {@link Graphics} for Android.\r
index d953d62..6289faa 100644 (file)
@@ -23,10 +23,10 @@ import android.opengl.GLUtils;
 import android.util.Log;\r
 \r
 import com.badlogic.gdx.Gdx;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.graphics.GL10;\r
 import com.badlogic.gdx.graphics.Pixmap;\r
 import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * An implementation of {@link Texture} for Android\r
index df28ccf..a726ca4 100644 (file)
@@ -22,12 +22,12 @@ import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.SourceDataLine;\r
 \r
 import com.badlogic.gdx.Audio;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.audio.AudioDevice;\r
 import com.badlogic.gdx.audio.AudioRecorder;\r
 import com.badlogic.gdx.audio.Music;\r
 import com.badlogic.gdx.audio.Sound;\r
 import com.badlogic.gdx.files.FileHandle;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * An implementation of the {@link Audio} interface for the desktop.\r
index bd63b98..ac73730 100644 (file)
@@ -17,8 +17,8 @@ import javax.sound.sampled.AudioFormat;
 import javax.sound.sampled.AudioSystem;\r
 import javax.sound.sampled.SourceDataLine;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.audio.AudioDevice;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * Implementation of the {@link AudioDevice} interface for the desktop using Java Sound.\r
index 8429989..999af69 100644 (file)
@@ -18,8 +18,8 @@ import javax.sound.sampled.AudioFormat.Encoding;
 import javax.sound.sampled.AudioSystem;\r
 import javax.sound.sampled.TargetDataLine;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.audio.AudioRecorder;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * {@link AudioRecorder} implementation for the desktop using the java sound API.\r
index 8b46a24..93e7619 100644 (file)
@@ -18,8 +18,8 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;\r
 import java.io.InputStream;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.files.FileHandle;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * A {@link FileHandle} implementation for the desktop.\r
index 916050f..acfa892 100644 (file)
@@ -21,8 +21,8 @@ import java.io.InputStream;
 import java.io.OutputStream;\r
 \r
 import com.badlogic.gdx.Files;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.files.FileHandle;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * Implementation for a desktop application of {@link Files}. Internal resources are relative to the application root directory,\r
index a7eaf12..d979f41 100644 (file)
@@ -21,10 +21,10 @@ import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;\r
 import java.io.InputStream;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.graphics.Font;\r
 import com.badlogic.gdx.graphics.Pixmap;\r
 import com.badlogic.gdx.math.Rectangle;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * An implementation of {@link Font} based on the java graphics framework.\r
index ab7327a..8b2d9bc 100644 (file)
@@ -26,7 +26,6 @@ import javax.media.opengl.GL;
 import javax.swing.JFrame;\r
 \r
 import com.badlogic.gdx.Gdx;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.Graphics;\r
 import com.badlogic.gdx.RenderListener;\r
 import com.badlogic.gdx.files.FileHandle;\r
@@ -42,6 +41,7 @@ import com.badlogic.gdx.graphics.Texture;
 import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
 import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
 import com.badlogic.gdx.math.WindowedMean;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * An implementation of the {@link Graphics} interface based on Jogl.\r
index 7f34169..7a001f8 100644 (file)
@@ -20,9 +20,9 @@ import javax.imageio.ImageIO;
 import javax.media.opengl.GL;\r
 import javax.media.opengl.GLContext;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.graphics.Pixmap;\r
 import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 import com.sun.opengl.util.texture.TextureData;\r
 import com.sun.opengl.util.texture.TextureIO;\r
 \r
index 613f4cf..847d9a3 100644 (file)
@@ -20,11 +20,11 @@ import com.badlogic.gdx.ApplicationListener;
 import com.badlogic.gdx.Audio;\r
 import com.badlogic.gdx.Files;\r
 import com.badlogic.gdx.Gdx;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.Graphics;\r
 import com.badlogic.gdx.Input;\r
 import com.badlogic.gdx.RenderListener;\r
 import com.badlogic.gdx.Version;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 @SuppressWarnings("unchecked") public class LwjglApplication implements Application {\r
        static {\r
index 0a68294..d893128 100644 (file)
@@ -22,12 +22,12 @@ import javax.sound.sampled.AudioSystem;
 import javax.sound.sampled.SourceDataLine;\r
 \r
 import com.badlogic.gdx.Audio;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.audio.AudioDevice;\r
 import com.badlogic.gdx.audio.AudioRecorder;\r
 import com.badlogic.gdx.audio.Music;\r
 import com.badlogic.gdx.audio.Sound;\r
 import com.badlogic.gdx.files.FileHandle;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * An implementation of the {@link Audio} interface for the desktop.\r
index 41e8d62..da9a8f2 100644 (file)
@@ -17,8 +17,8 @@ import javax.sound.sampled.AudioFormat;
 import javax.sound.sampled.AudioSystem;\r
 import javax.sound.sampled.SourceDataLine;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.audio.AudioDevice;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * Implementation of the {@link AudioDevice} interface for the desktop using Java Sound.\r
index dfb0531..38b4c23 100644 (file)
@@ -18,8 +18,8 @@ import javax.sound.sampled.AudioFormat.Encoding;
 import javax.sound.sampled.AudioSystem;\r
 import javax.sound.sampled.TargetDataLine;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.audio.AudioRecorder;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * {@link AudioRecorder} implementation for the desktop using the java sound API.\r
index 4a332d3..a6b5505 100644 (file)
@@ -18,8 +18,8 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;\r
 import java.io.InputStream;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.files.FileHandle;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * A {@link FileHandle} implementation for the desktop.\r
index 2f289b0..0104a5a 100644 (file)
@@ -21,8 +21,8 @@ import java.io.InputStream;
 import java.io.OutputStream;\r
 \r
 import com.badlogic.gdx.Files;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.files.FileHandle;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * Implementation for a desktop application of {@link Files}. Internal resources are relative to the application root directory,\r
index 8cbdebd..090c0b8 100644 (file)
@@ -21,10 +21,10 @@ import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;\r
 import java.io.InputStream;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.graphics.Font;\r
 import com.badlogic.gdx.graphics.Pixmap;\r
 import com.badlogic.gdx.math.Rectangle;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * An implementation of {@link Font} based on the java graphics framework.\r
index 7b6c7be..1248fa8 100644 (file)
@@ -25,8 +25,8 @@ import org.lwjgl.BufferUtils;
 import org.lwjgl.opengl.GL11;\r
 import org.lwjgl.opengl.GL13;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * An implementation of the {@link GL10} interface based on Jogl. Fixed point vertex arrays are emulated.\r
index c3a8096..673de91 100644 (file)
@@ -28,8 +28,8 @@ import org.lwjgl.opengl.GL14;
 import org.lwjgl.opengl.GL15;\r
 import org.lwjgl.opengl.GL20;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * An implementation of the {@link GL20} interface based on Jogl. Note that Jogl shaders and OpenGL ES shaders will not be 100%\r
index ea93b58..1600440 100644 (file)
@@ -20,7 +20,6 @@ import java.io.InputStream;
 import javax.imageio.ImageIO;\r
 \r
 import com.badlogic.gdx.Gdx;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.Graphics;\r
 import com.badlogic.gdx.RenderListener;\r
 import com.badlogic.gdx.files.FileHandle;\r
@@ -35,6 +34,7 @@ import com.badlogic.gdx.graphics.Pixmap.Format;
 import com.badlogic.gdx.graphics.Texture;\r
 import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
 import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * An implementation of the {@link Graphics} interface based on Jogl.\r
index 7530656..0d21101 100644 (file)
@@ -23,10 +23,10 @@ import org.lwjgl.opengl.GL11;
 import org.lwjgl.opengl.GL12;\r
 \r
 import com.badlogic.gdx.Gdx;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.files.FileHandle;\r
 import com.badlogic.gdx.graphics.Pixmap;\r
 import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 /**\r
  * I apologize for this class. It is a big fucking mess which can be attributed to the late hour i created this piece of shit in.\r
index 4d84743..ead59b1 100644 (file)
@@ -35,7 +35,6 @@ import org.lwjgl.opengl.Display;
 \r
 import com.badlogic.gdx.Files.FileType;\r
 import com.badlogic.gdx.Gdx;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.InputListener;\r
 import com.badlogic.gdx.RenderListener;\r
 import com.badlogic.gdx.backends.desktop.LwjglApplication;\r
@@ -47,6 +46,7 @@ import com.badlogic.gdx.graphics.SpriteBatch;
 import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
 import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
 import com.badlogic.gdx.math.Matrix4;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 public class ParticleEditor extends JFrame {\r
        LwjglApplication app;\r
index 5805bea..5841f52 100644 (file)
@@ -9,9 +9,9 @@ import java.util.HashMap;
 
 import com.badlogic.gdx.Files.FileType;
 import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.GdxRuntimeException;
 import com.badlogic.gdx.files.FileHandle;
 import com.badlogic.gdx.graphics.BitmapFont;
+import com.badlogic.gdx.utils.GdxRuntimeException;
 
 import de.matthiasmann.twl.renderer.CacheContext;
 
index 8d95a58..195f0c8 100644 (file)
@@ -33,13 +33,13 @@ import java.util.Map;
 \r
 import com.badlogic.gdx.Files.FileType;\r
 import com.badlogic.gdx.Gdx;\r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.files.FileHandle;\r
 import com.badlogic.gdx.graphics.BitmapFont;\r
 import com.badlogic.gdx.graphics.Color;\r
 import com.badlogic.gdx.graphics.GL10;\r
 import com.badlogic.gdx.graphics.SpriteBatch;\r
 import com.badlogic.gdx.math.Matrix4;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 import de.matthiasmann.twl.GUI;\r
 import de.matthiasmann.twl.Rect;\r
index 8125552..d66eec2 100644 (file)
@@ -84,9 +84,6 @@ public class ShaderProgram {
        /** matrix float buffer **/\r
        private final FloatBuffer matrix;\r
 \r
-       /** managed? **/\r
-       private final boolean managed;\r
-\r
        /** vertex shader source **/\r
        private final String vertexShaderSource;\r
 \r
@@ -108,7 +105,6 @@ public class ShaderProgram {
                if (vertexShader == null) throw new IllegalArgumentException("vertex shader must not be null");\r
                if (fragmentShader == null) throw new IllegalArgumentException("fragment shader must not be null");\r
 \r
-               this.managed = true;\r
                this.vertexShaderSource = vertexShader;\r
                this.fragmentShaderSource = fragmentShader;\r
 \r
@@ -117,7 +113,7 @@ public class ShaderProgram {
                ByteBuffer buffer = ByteBuffer.allocateDirect(4 * 16);\r
                buffer.order(ByteOrder.nativeOrder());\r
                matrix = buffer.asFloatBuffer();\r
-               if (managed) shaders.add(this);\r
+               shaders.add(this);\r
        }\r
 \r
        /**\r
@@ -465,10 +461,10 @@ public class ShaderProgram {
        }\r
 \r
        private void checkManaged () {\r
-               if (!managed) return;\r
-\r
-               if (invalidated) compileShaders(vertexShaderSource, fragmentShaderSource);\r
-               invalidated = false;\r
+               if (invalidated) {\r
+                       compileShaders(vertexShaderSource, fragmentShaderSource);\r
+                       invalidated = false;\r
+               }               \r
        }\r
 \r
        /**\r
diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexArray.java b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexArray.java
new file mode 100644 (file)
index 0000000..1dc4c41
--- /dev/null
@@ -0,0 +1,156 @@
+package com.badlogic.gdx.graphics.glutils;\r
+\r
+import java.nio.ByteBuffer;\r
+import java.nio.ByteOrder;\r
+import java.nio.FloatBuffer;\r
+\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.graphics.GL11;\r
+import com.badlogic.gdx.graphics.VertexAttribute;\r
+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.GdxRuntimeException;\r
+\r
+/**\r
+ * <p>\r
+ * Convenience class for working with OpenGL vertex arrays. It interleaves all\r
+ * data in the order you specified in the constructor via\r
+ * {@link VertexAttribute}.\r
+ * </p>\r
+ * \r
+ * <p>\r
+ * This class does not support shaders and for that matter OpenGL ES 2.0. For\r
+ * this {@link VertexBufferObject}s are needed.\r
+ * </p>\r
+ * \r
+ * @author mzechner\r
+ * \r
+ */\r
+public class VertexArray implements VertexData {\r
+       final VertexAttributes attributes;\r
+       final FloatBuffer buffer;\r
+       final ByteBuffer byteBuffer;\r
+\r
+       public VertexArray(int numVertices, VertexAttribute... attributes) {\r
+               this.attributes = new VertexAttributes(attributes);\r
+               byteBuffer = ByteBuffer.allocateDirect(this.attributes.vertexSize\r
+                               * numVertices);\r
+               byteBuffer.order(ByteOrder.nativeOrder());\r
+               buffer = byteBuffer.asFloatBuffer();\r
+       }\r
+\r
+       @Override\r
+       public void dispose() {\r
+\r
+       }\r
+\r
+       @Override\r
+       public FloatBuffer getBuffer() {\r
+               return buffer;\r
+       }\r
+\r
+       @Override\r
+       public int getNumVertices() {\r
+               return byteBuffer.limit() / attributes.vertexSize;\r
+       }\r
+\r
+       public int getNumMaxVertices() {\r
+               return byteBuffer.capacity() / attributes.vertexSize;\r
+       }\r
+\r
+       @Override\r
+       public void setVertices(float[] vertices, int offset, int count) {\r
+               BufferUtils.copy(vertices, byteBuffer, count, offset);\r
+               buffer.position(0);\r
+               buffer.limit(count);\r
+       }\r
+\r
+       @Override\r
+       public void bind() {\r
+               GL10 gl = Gdx.gl10;\r
+               int textureUnit = 0;\r
+               int numAttributes = attributes.size();\r
+\r
+               for (int i = 0; i < numAttributes; i++) {\r
+                       VertexAttribute attribute = attributes.get(i);\r
+\r
+                       switch (attribute.usage) {\r
+                       case Usage.Position:\r
+                               byteBuffer.position(attribute.offset);\r
+                               gl.glEnableClientState(GL11.GL_VERTEX_ARRAY);\r
+                               gl.glVertexPointer(attribute.numComponents, GL10.GL_FLOAT,\r
+                                               attributes.vertexSize, byteBuffer);\r
+                               break;\r
+\r
+                       case Usage.Color:\r
+                       case Usage.ColorPacked:\r
+                               int colorType = GL10.GL_FLOAT;\r
+                               if (attribute.usage == Usage.ColorPacked)\r
+                                       colorType = GL11.GL_UNSIGNED_BYTE;\r
+                               byteBuffer.position(attribute.offset);\r
+                               gl.glEnableClientState(GL10.GL_COLOR_ARRAY);\r
+                               gl.glColorPointer(attribute.numComponents, colorType,\r
+                                               attributes.vertexSize, byteBuffer);\r
+                               break;\r
+\r
+                       case Usage.Normal:\r
+                               byteBuffer.position(attribute.offset);\r
+                               gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);\r
+                               gl.glNormalPointer(GL10.GL_FLOAT, attributes.vertexSize,\r
+                                               byteBuffer);\r
+                               break;\r
+\r
+                       case Usage.TextureCoordinates:\r
+                               gl.glClientActiveTexture(GL10.GL_TEXTURE0 + textureUnit);\r
+                               gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);\r
+                               byteBuffer.position(attribute.offset);\r
+                               gl.glTexCoordPointer(attribute.numComponents, GL10.GL_FLOAT,\r
+                                               attributes.vertexSize, byteBuffer);\r
+                               textureUnit++;\r
+                               break;\r
+\r
+                       default:\r
+                               throw new GdxRuntimeException("unkown vertex attribute type: "\r
+                                               + attribute.usage);\r
+                       }\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void unbind() {\r
+               GL10 gl = Gdx.gl10;\r
+               int textureUnit = 0;\r
+               int numAttributes = attributes.size();\r
+\r
+               for (int i = 0; i < numAttributes; i++) {\r
+\r
+                       VertexAttribute attribute = attributes.get(i);\r
+                       switch (attribute.usage) {\r
+                       case Usage.Position:\r
+                               break; // no-op, we also need a position bound in gles\r
+                       case Usage.Color:\r
+                       case Usage.ColorPacked:\r
+                               gl.glDisableClientState(GL11.GL_COLOR_ARRAY);\r
+                               break;\r
+                       case Usage.Normal:\r
+                               gl.glDisableClientState(GL11.GL_NORMAL_ARRAY);\r
+                               break;\r
+                       case Usage.TextureCoordinates:\r
+                               gl.glClientActiveTexture(GL11.GL_TEXTURE0 + textureUnit);\r
+                               gl.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);\r
+                               textureUnit++;\r
+                               break;\r
+                       default:\r
+                               throw new GdxRuntimeException("unkown vertex attribute type: "\r
+                                               + attribute.usage);\r
+                       }\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public VertexAttributes getAttributes() {\r
+               return attributes;\r
+       }\r
+}\r
diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexBufferObject.java
new file mode 100644 (file)
index 0000000..16be058
--- /dev/null
@@ -0,0 +1,272 @@
+package com.badlogic.gdx.graphics.glutils;\r
+\r
+import java.nio.ByteBuffer;\r
+import java.nio.ByteOrder;\r
+import java.nio.FloatBuffer;\r
+import java.nio.IntBuffer;\r
+\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.Application.ApplicationType;\r
+import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.graphics.GL11;\r
+import com.badlogic.gdx.graphics.GL20;\r
+import com.badlogic.gdx.graphics.VertexAttribute;\r
+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.GdxRuntimeException;\r
+\r
+/**\r
+ * <p>\r
+ * A {@link VertexData} implementation based on OpenGL vertex buffer objects.\r
+ * </p>\r
+ * \r
+ * <p>\r
+ * If the OpenGL ES context was lost you can call {@link #invalidate()} to recreate\r
+ * a new OpenGL vertex buffer object. \r
+ * </p>\r
+ * \r
+ * <p>\r
+ * In case OpenGL ES 2.0 is used in the application the data is bound via\r
+ * glVertexAttribPointer() according to the attribute aliases specified via\r
+ * {@link VertexAttributes} in the constructor.\r
+ * </p>\r
+ * \r
+ * <p>\r
+ * Uses indirect Buffers on Android 1.5/1.6 to fix GC invocation due to leaking\r
+ * PlatformAddress instances.\r
+ * </p>\r
+ * \r
+ * @author mzechner\r
+ * \r
+ */\r
+public class VertexBufferObject implements VertexData {\r
+       final static IntBuffer tmpHandle = BufferUtils.newIntBuffer(1);\r
+       \r
+       final VertexAttributes attributes;      \r
+       final FloatBuffer buffer;       \r
+       final ByteBuffer byteBuffer;\r
+       int bufferHandle;\r
+       final boolean isDirect;\r
+       final boolean isStatic;\r
+       final int usage;\r
+       boolean isDirty=false;\r
+       \r
+       /**\r
+        * Constructs a new interleaved VertexBufferObject. \r
+        * @param isStatic whether the vertex data is static.\r
+        * @param numVertices the maximum number of vertices\r
+        * @param attributes the {@link VertexAttribute}s.\r
+        */\r
+       public VertexBufferObject (boolean isStatic, int numVertices, VertexAttribute ... attributes) {\r
+               this.isStatic = isStatic;\r
+               this.attributes = new VertexAttributes(attributes);\r
+               if( Gdx.app.getType() == ApplicationType.Android && Gdx.app.getVersion() < 5 ) {\r
+                       byteBuffer = ByteBuffer.allocate(this.attributes.vertexSize * numVertices);\r
+                       byteBuffer.order(ByteOrder.nativeOrder());\r
+                       isDirect = true;\r
+               }\r
+               else {\r
+                       byteBuffer = ByteBuffer.allocateDirect(this.attributes.vertexSize * numVertices);\r
+                       byteBuffer.order(ByteOrder.nativeOrder());\r
+                       isDirect = false;\r
+               }               \r
+               buffer = byteBuffer.asFloatBuffer();\r
+               bufferHandle = createBufferObject();\r
+               usage = isStatic?GL11.GL_STATIC_DRAW:GL11.GL_DYNAMIC_DRAW;\r
+       }\r
+       \r
+       private int createBufferObject () {                                     \r
+               if(Gdx.gl20!=null)\r
+                       Gdx.gl20.glGenBuffers(1, tmpHandle);                                    \r
+               else \r
+                       Gdx.gl11.glGenBuffers(1, tmpHandle);            \r
+               return tmpHandle.get(0);\r
+       }       \r
+\r
+       @Override\r
+       public VertexAttributes getAttributes() {\r
+               return attributes;\r
+       }\r
+\r
+       @Override\r
+       public int getNumVertices() {\r
+               return byteBuffer.limit() / attributes.vertexSize;\r
+       }\r
+\r
+       public int getNumMaxVertices() {\r
+               return byteBuffer.capacity() / attributes.vertexSize;\r
+       }\r
+       \r
+       @Override\r
+       public FloatBuffer getBuffer() {\r
+               isDirty = true;\r
+               return buffer;\r
+       }\r
+\r
+       @Override\r
+       public void setVertices(float[] vertices, int offset, int count) {\r
+               isDirty = true;\r
+               if( isDirect ) {\r
+                       BufferUtils.copy(vertices, byteBuffer, count, offset);\r
+                       buffer.position(0);\r
+                       buffer.limit(count);\r
+               }\r
+               else {\r
+                       buffer.clear();\r
+                       buffer.put( vertices, offset, count );\r
+                       buffer.flip();\r
+                       byteBuffer.position(0);\r
+                       byteBuffer.limit(buffer.limit() << 2);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void bind() {\r
+               GL11 gl = Gdx.gl11;\r
+               \r
+               gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, bufferHandle);\r
+               if( isDirty ) {\r
+                       gl.glBufferData(GL11.GL_ARRAY_BUFFER, byteBuffer.limit(), null, usage);\r
+                       gl.glBufferData(GL11.GL_ARRAY_BUFFER, byteBuffer.limit(), byteBuffer, usage);\r
+                       isDirty = false;\r
+               }\r
+               \r
+               int textureUnit = 0;\r
+               int numAttributes = attributes.size();\r
+\r
+               for (int i = 0; i < numAttributes; i++) {\r
+                       VertexAttribute attribute = attributes.get(i);\r
+\r
+                       switch (attribute.usage) {\r
+                       case Usage.Position:                            \r
+                               gl.glEnableClientState(GL11.GL_VERTEX_ARRAY);\r
+                               gl.glVertexPointer(attribute.numComponents, GL10.GL_FLOAT,\r
+                                               attributes.vertexSize, attribute.offset);\r
+                               break;\r
+\r
+                       case Usage.Color:\r
+                       case Usage.ColorPacked:\r
+                               int colorType = GL10.GL_FLOAT;\r
+                               if (attribute.usage == Usage.ColorPacked)\r
+                                       colorType = GL11.GL_UNSIGNED_BYTE;\r
+                               \r
+                               gl.glEnableClientState(GL10.GL_COLOR_ARRAY);\r
+                               gl.glColorPointer(attribute.numComponents, colorType,\r
+                                               attributes.vertexSize, attribute.offset);\r
+                               break;\r
+\r
+                       case Usage.Normal:                              \r
+                               gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);\r
+                               gl.glNormalPointer(GL10.GL_FLOAT, attributes.vertexSize,\r
+                                               attribute.offset);\r
+                               break;\r
+\r
+                       case Usage.TextureCoordinates:\r
+                               gl.glClientActiveTexture(GL10.GL_TEXTURE0 + textureUnit);\r
+                               gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);\r
+                               gl.glTexCoordPointer(attribute.numComponents, GL10.GL_FLOAT,\r
+                                               attributes.vertexSize, attribute.offset);\r
+                               textureUnit++;\r
+                               break;\r
+\r
+                       default:\r
+                               throw new GdxRuntimeException("unkown vertex attribute type: "\r
+                                               + attribute.usage);\r
+                       }\r
+               }\r
+       }\r
+       \r
+       public void bind(ShaderProgram shader) {\r
+               GL20 gl = Gdx.gl20;\r
+               \r
+               gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, bufferHandle);\r
+               if( isDirty ) {\r
+                       gl.glBufferData(GL20.GL_ARRAY_BUFFER, byteBuffer.limit(), null, usage);\r
+                       gl.glBufferData(GL20.GL_ARRAY_BUFFER, byteBuffer.limit(), byteBuffer, usage);\r
+                       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
+                       }\r
+                       shader.setVertexAttribute(attribute.alias, attribute.numComponents, colorType, normalize, attributes.vertexSize, attribute.offset);\r
+               }\r
+       }       \r
+       \r
+       @Override\r
+       public void unbind() {\r
+               GL11 gl = Gdx.gl11;\r
+               int textureUnit = 0;\r
+               int numAttributes = attributes.size();\r
+\r
+               gl.glBindBuffer(GL11.GL_ARRAY_BUFFER, 0);\r
+               \r
+               for (int i = 0; i < numAttributes; i++) {\r
+\r
+                       VertexAttribute attribute = attributes.get(i);\r
+                       switch (attribute.usage) {\r
+                       case Usage.Position:\r
+                               break; // no-op, we also need a position bound in gles\r
+                       case Usage.Color:\r
+                       case Usage.ColorPacked:\r
+                               gl.glDisableClientState(GL11.GL_COLOR_ARRAY);\r
+                               break;\r
+                       case Usage.Normal:\r
+                               gl.glDisableClientState(GL11.GL_NORMAL_ARRAY);\r
+                               break;\r
+                       case Usage.TextureCoordinates:\r
+                               gl.glClientActiveTexture(GL11.GL_TEXTURE0 + textureUnit);\r
+                               gl.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);\r
+                               textureUnit++;\r
+                               break;\r
+                       default:\r
+                               throw new GdxRuntimeException("unkown vertex attribute type: "\r
+                                               + attribute.usage);\r
+                       }\r
+               }\r
+       }\r
+       \r
+       private 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
+               }\r
+               gl.glBindBuffer(GL20.GL_ARRAY_BUFFER, 0);\r
+       }\r
+       \r
+       public void invalidate() {\r
+               bufferHandle = createBufferObject();\r
+               isDirty = true;\r
+       }\r
+       \r
+       @Override\r
+       public void dispose() {\r
+               if( Gdx.gl20!=null) {\r
+                       tmpHandle.clear();\r
+                       tmpHandle.put(bufferHandle);\r
+                       GL20 gl = Gdx.gl20;\r
+                       gl.glBindBuffer( GL20.GL_ARRAY_BUFFER, 0);                      \r
+                       gl.glDeleteBuffers(1, tmpHandle);\r
+                       bufferHandle = 0;\r
+               }\r
+               else {\r
+                       tmpHandle.clear();\r
+                       tmpHandle.put(bufferHandle);\r
+                       GL11 gl = Gdx.gl11;\r
+                       gl.glBindBuffer( GL11.GL_ARRAY_BUFFER, 0);                      \r
+                       gl.glDeleteBuffers(1, tmpHandle);\r
+                       bufferHandle = 0;                       \r
+               }\r
+                       \r
+       }\r
+}\r
diff --git a/gdx/src/com/badlogic/gdx/graphics/glutils/VertexData.java b/gdx/src/com/badlogic/gdx/graphics/glutils/VertexData.java
new file mode 100644 (file)
index 0000000..9b98dcc
--- /dev/null
@@ -0,0 +1,66 @@
+package com.badlogic.gdx.graphics.glutils;\r
+\r
+import java.nio.FloatBuffer;\r
+\r
+import com.badlogic.gdx.graphics.VertexAttributes;\r
+\r
+/**\r
+ * A VertexData instance holds vertices for rendering with OpenGL. It\r
+ * is implemented as either a {@link VertexArray} or a {@link VertexBufferObject}. Only\r
+ * the later supports OpenGL ES 2.0.\r
+ *  \r
+ * @author mzechner\r
+ *\r
+ */\r
+public interface VertexData {\r
+       /**\r
+        * @return the number of vertices this VertexData stores\r
+        */\r
+       public int getNumVertices ();\r
+       \r
+       /**\r
+        * @return the number of vertices this VertedData can store\r
+        */\r
+       public int getNumMaxVertices ();\r
+       \r
+       /**\r
+        * @return the {@link VertexAttributes} as specified during construction.\r
+        */\r
+       public VertexAttributes getAttributes ();       \r
+       \r
+       /**\r
+        * Sets the vertices of this VertexData, discarding the old vertex data. The\r
+        * count must equal the number of floats per vertex times the number of vertices to\r
+        * be copied to this VertexData. The order of the vertex attributes must be the same\r
+        * as specified at construction time via {@link VertexAttributes}.\r
+        * \r
+        * @param vertices the vertex data\r
+        * @param offset the offset to start copying the data from\r
+        * @param count the number of floats to copy\r
+        */\r
+       public void setVertices (float[] vertices, int offset, int count);      \r
+       \r
+       /**\r
+        * Returns the underlying FloatBuffer. If this is called an internal dirty\r
+        * flag is set and the VertexData is reuploaded to OpenGL on the next bind. The\r
+        * data is therefore considered dirty.\r
+        * \r
+        * @return the underlying FloatBuffer holding the vertex data.\r
+        */\r
+       public FloatBuffer getBuffer ();\r
+       \r
+       /**\r
+        * Binds this VertexData for rendering via glDrawArrays or glDrawElements.\r
+        */\r
+       public void bind ();\r
+       \r
+       /**\r
+        * Unbinds this VertexData.\r
+        */\r
+       public void unbind ();  \r
+       \r
+       /**\r
+        * Disposes this VertexData and all its associated OpenGL resources.\r
+        */\r
+       public void dispose ();\r
+}\r
index e6f05fc..ade34ee 100644 (file)
@@ -6,6 +6,6 @@ public class JoglDebugStarter {
        \r
        public static void main( String[] argv ) {\r
                JoglApplication app = new JoglApplication( "Debug Test", 480, 320, false );\r
-               app.getGraphics().setRenderListener( new com.badlogic.gdx.tests.SoundTest() );\r
+               app.getGraphics().setRenderListener( new com.badlogic.gdx.tests.VertexBufferObjectClassTest() );\r
        }\r
 }\r
diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexArrayClassTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexArrayClassTest.java
new file mode 100644 (file)
index 0000000..1a2b42c
--- /dev/null
@@ -0,0 +1,76 @@
+package com.badlogic.gdx.tests;\r
+\r
+import java.nio.ShortBuffer;\r
+\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.Files.FileType;\r
+import com.badlogic.gdx.graphics.Color;\r
+import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.graphics.VertexAttribute;\r
+import com.badlogic.gdx.graphics.VertexAttributes;\r
+import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
+import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.graphics.glutils.VertexArray;\r
+import com.badlogic.gdx.tests.utils.GdxTest;\r
+import com.badlogic.gdx.utils.BufferUtils;\r
+\r
+public class VertexArrayClassTest implements GdxTest {\r
+       Texture texture;\r
+       VertexArray va;\r
+       ShortBuffer indices;\r
+       \r
+       @Override\r
+       public boolean needsGL20() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void dispose() {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void render() {\r
+               GL10 gl = Gdx.gl10;             \r
+               gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
+               gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
+               \r
+               gl.glEnable(GL10.GL_TEXTURE_2D);\r
+               texture.bind();\r
+               va.bind();\r
+               gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);\r
+               \r
+               gl.glMatrixMode(GL10.GL_MODELVIEW);\r
+               gl.glPushMatrix();\r
+               gl.glTranslatef( 0.5f, 0.5f, 0);\r
+               gl.glDrawElements(GL10.GL_TRIANGLES,3,GL10.GL_UNSIGNED_SHORT,indices);\r
+               gl.glPopMatrix();\r
+               va.unbind();\r
+       }\r
+\r
+       @Override\r
+       public void surfaceChanged(int width, int height) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void surfaceCreated() {\r
+               va = new VertexArray(3, new VertexAttribute(VertexAttributes.Usage.Position, 2, "a_Position"),\r
+                                                               new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "a_TexCoords"),\r
+                                                               new VertexAttribute(VertexAttributes.Usage.ColorPacked, 4, "a_Color" ));\r
+               float[] vertices = new float[]{ -1, -1, 0, 0, Color.toFloatBits(1f, 0f, 0f, 1f ),\r
+                                                                                0,  1, 0.5f, 1.0f, Color.toFloatBits(0f, 1f, 0f, 1f ),\r
+                                                                                1, -1, 1, 0, Color.toFloatBits(0f, 0f, 1f, 1f ) };\r
+               va.setVertices(vertices, 0, vertices.length);\r
+               indices = BufferUtils.newShortBuffer(3);\r
+               indices.put( new short[] { 0, 1, 2 } );\r
+               indices.flip();\r
+               \r
+               if( texture == null ) {\r
+                       texture = Gdx.graphics.newTexture(Gdx.files.getFileHandle("data/badlogic.jpg", FileType.Internal),\r
+                                                                                         TextureFilter.Linear, TextureFilter.Linear, \r
+                                                                                         TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);\r
+               }\r
+       }\r
+}\r
diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectClassTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/VertexBufferObjectClassTest.java
new file mode 100644 (file)
index 0000000..8b2682c
--- /dev/null
@@ -0,0 +1,76 @@
+package com.badlogic.gdx.tests;\r
+\r
+import java.nio.ShortBuffer;\r
+\r
+import com.badlogic.gdx.Gdx;\r
+import com.badlogic.gdx.Files.FileType;\r
+import com.badlogic.gdx.graphics.Color;\r
+import com.badlogic.gdx.graphics.GL10;\r
+import com.badlogic.gdx.graphics.Texture;\r
+import com.badlogic.gdx.graphics.VertexAttribute;\r
+import com.badlogic.gdx.graphics.VertexAttributes;\r
+import com.badlogic.gdx.graphics.Texture.TextureFilter;\r
+import com.badlogic.gdx.graphics.Texture.TextureWrap;\r
+import com.badlogic.gdx.graphics.glutils.VertexBufferObject;\r
+import com.badlogic.gdx.tests.utils.GdxTest;\r
+import com.badlogic.gdx.utils.BufferUtils;\r
+\r
+public class VertexBufferObjectClassTest implements GdxTest {\r
+       Texture texture;\r
+       VertexBufferObject vbo;\r
+       ShortBuffer indices;\r
+       \r
+       @Override\r
+       public boolean needsGL20() {\r
+               return false;\r
+       }\r
+\r
+       @Override\r
+       public void dispose() {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void render() {\r
+               GL10 gl = Gdx.gl10;             \r
+               gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());\r
+               gl.glClear(GL10.GL_COLOR_BUFFER_BIT);\r
+               \r
+               gl.glEnable(GL10.GL_TEXTURE_2D);\r
+               texture.bind();\r
+               vbo.bind();\r
+               gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);\r
+               \r
+               gl.glMatrixMode(GL10.GL_MODELVIEW);\r
+               gl.glPushMatrix();\r
+               gl.glTranslatef( 0.5f, 0.5f, 0);\r
+               gl.glDrawElements(GL10.GL_TRIANGLES,3,GL10.GL_UNSIGNED_SHORT,indices);\r
+               gl.glPopMatrix();\r
+               vbo.unbind();\r
+       }\r
+\r
+       @Override\r
+       public void surfaceChanged(int width, int height) {\r
+               \r
+       }\r
+\r
+       @Override\r
+       public void surfaceCreated() {\r
+               vbo = new VertexBufferObject(true, 3, new VertexAttribute(VertexAttributes.Usage.Position, 2, "a_Position"),\r
+                                                               new VertexAttribute(VertexAttributes.Usage.TextureCoordinates, 2, "a_TexCoords"),\r
+                                                               new VertexAttribute(VertexAttributes.Usage.ColorPacked, 4, "a_Color" ));\r
+               float[] vertices = new float[]{ -1, -1, 0, 0, Color.toFloatBits(1f, 0f, 0f, 1f ),\r
+                                                                                0,  1, 0.5f, 1.0f, Color.toFloatBits(0f, 1f, 0f, 1f ),\r
+                                                                                1, -1, 1, 0, Color.toFloatBits(0f, 0f, 1f, 1f ) };\r
+               vbo.setVertices(vertices, 0, vertices.length);\r
+               indices = BufferUtils.newShortBuffer(3);\r
+               indices.put( new short[] { 0, 1, 2 } );\r
+               indices.flip();\r
+               \r
+               if( texture == null ) {\r
+                       texture = Gdx.graphics.newTexture(Gdx.files.getFileHandle("data/badlogic.jpg", FileType.Internal),\r
+                                                                                         TextureFilter.Linear, TextureFilter.Linear, \r
+                                                                                         TextureWrap.ClampToEdge, TextureWrap.ClampToEdge);\r
+               }\r
+       }\r
+}\r
index ff32aa7..27384ea 100644 (file)
@@ -1,7 +1,7 @@
 package com.badlogic.gdx.tests.utils;\r
 \r
-import com.badlogic.gdx.GdxRuntimeException;\r
 import com.badlogic.gdx.RenderListener;\r
+import com.badlogic.gdx.utils.GdxRuntimeException;\r
 \r
 public interface GdxTest extends RenderListener\r
 {\r
index 512548f..fb79184 100644 (file)
@@ -36,7 +36,9 @@ import com.badlogic.gdx.tests.TerrainTest;
 import com.badlogic.gdx.tests.TextTest;\r
 import com.badlogic.gdx.tests.TextureRenderTest;\r
 import com.badlogic.gdx.tests.UITest;\r
+import com.badlogic.gdx.tests.VertexArrayClassTest;\r
 import com.badlogic.gdx.tests.VertexArrayTest;\r
+import com.badlogic.gdx.tests.VertexBufferObjectClassTest;\r
 import com.badlogic.gdx.tests.VertexBufferObjectTest;\r
 import com.badlogic.gdx.tests.VorbisTest;\r
 import com.badlogic.gdx.tests.WaterRipples;\r
@@ -84,8 +86,10 @@ public class GdxTests
                TextTest.class,\r
                TextureRenderTest.class,\r
                UITest.class,\r
-               VertexArrayTest.class,\r
+               VertexArrayTest.class,          \r
                VertexBufferObjectTest.class,\r
+               VertexArrayClassTest.class,\r
+               VertexBufferObjectClassTest.class,\r
                VorbisTest.class,\r
                WaterRipples.class\r
        };\r