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
\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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
\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
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
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;
\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
/** 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
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
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
}\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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
\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
--- /dev/null
+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
--- /dev/null
+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
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
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
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