com.badlogic.gdx.graphics.glutils
Class VertexBufferObjectSubData

java.lang.Object
  extended by com.badlogic.gdx.graphics.glutils.VertexBufferObjectSubData
All Implemented Interfaces:
VertexData, Disposable

public class VertexBufferObjectSubData
extends Object
implements VertexData

A VertexData implementation based on OpenGL vertex buffer objects.

If the OpenGL ES context was lost you can call invalidate() to recreate a new OpenGL vertex buffer object. This class can be used seamlessly with OpenGL ES 1.x and 2.0.

In case OpenGL ES 2.0 is used in the application the data is bound via glVertexAttribPointer() according to the attribute aliases specified via VertexAttributes in the constructor.

Uses indirect Buffers on Android 1.5/1.6 to fix GC invocation due to leaking PlatformAddress instances.

VertexBufferObjects must be disposed via the dispose() method when no longer needed

Author:
mzechner

Constructor Summary
VertexBufferObjectSubData(boolean isStatic, int numVertices, VertexAttribute... attributes)
          Constructs a new interleaved VertexBufferObject.
 
Method Summary
 void bind()
          Binds this VertexData for rendering via glDrawArrays or glDrawElements.
 void bind(ShaderProgram shader)
          Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElements
 void bind(ShaderProgram shader, int[] locations)
          Binds this VertexData for rendering via glDrawArrays or glDrawElements.
 void dispose()
          Disposes of all resources this VertexBufferObject uses.
 VertexAttributes getAttributes()
          
 FloatBuffer getBuffer()
           Returns the underlying FloatBuffer.
 int getBufferHandle()
          Returns the VBO handle
 int getNumMaxVertices()
          
 int getNumVertices()
          
 void invalidate()
          Invalidates the VertexBufferObject so a new OpenGL buffer handle is created.
 void setVertices(float[] vertices, int offset, int count)
           Sets the vertices of this VertexData, discarding the old vertex data.
 void unbind()
          Unbinds this VertexData.
 void unbind(ShaderProgram shader)
          Unbinds this VertexBufferObject.
 void unbind(ShaderProgram shader, int[] locations)
          Unbinds this VertexData.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VertexBufferObjectSubData

public VertexBufferObjectSubData(boolean isStatic,
                                 int numVertices,
                                 VertexAttribute... attributes)
Constructs a new interleaved VertexBufferObject.

Parameters:
isStatic - whether the vertex data is static.
numVertices - the maximum number of vertices
attributes - the VertexAttributes.
Method Detail

getAttributes

public VertexAttributes getAttributes()

Specified by:
getAttributes in interface VertexData
Returns:
the VertexAttributes as specified during construction.

getNumVertices

public int getNumVertices()

Specified by:
getNumVertices in interface VertexData
Returns:
the number of vertices this VertexData stores

getNumMaxVertices

public int getNumMaxVertices()

Specified by:
getNumMaxVertices in interface VertexData
Returns:
the number of vertices this VertedData can store

getBuffer

public FloatBuffer getBuffer()

Returns the underlying FloatBuffer. If you modify the buffer contents they will be uploaded on the next call to VertexData.bind(). If you need immediate uploading use VertexData.setVertices(float[], int, int);

Specified by:
getBuffer in interface VertexData
Returns:
the underlying FloatBuffer holding the vertex data.

setVertices

public void setVertices(float[] vertices,
                        int offset,
                        int count)

Sets the vertices of this VertexData, discarding the old vertex data. The count must equal the number of floats per vertex times the number of vertices to be copied to this VertexData. The order of the vertex attributes must be the same as specified at construction time via VertexAttributes.

This can be called in between calls to VertexData.bind() and VertexData.unbind(). The vertex data will be updated instantly.

Specified by:
setVertices in interface VertexData
Parameters:
vertices - the vertex data
offset - the offset to start copying the data from
count - the number of floats to copy

bind

public void bind()
Binds this VertexData for rendering via glDrawArrays or glDrawElements.

Specified by:
bind in interface VertexData

bind

public void bind(ShaderProgram shader)
Binds this VertexBufferObject for rendering via glDrawArrays or glDrawElements

Specified by:
bind in interface VertexData
Parameters:
shader - the shader

bind

public void bind(ShaderProgram shader,
                 int[] locations)
Description copied from interface: VertexData
Binds this VertexData for rendering via glDrawArrays or glDrawElements.

Specified by:
bind in interface VertexData
locations - array containing the attribute locations.

unbind

public void unbind()
Description copied from interface: VertexData
Unbinds this VertexData.

Specified by:
unbind in interface VertexData

unbind

public void unbind(ShaderProgram shader)
Unbinds this VertexBufferObject.

Specified by:
unbind in interface VertexData
Parameters:
shader - the shader

unbind

public void unbind(ShaderProgram shader,
                   int[] locations)
Description copied from interface: VertexData
Unbinds this VertexData.

Specified by:
unbind in interface VertexData
locations - array containing the attribute locations.

invalidate

public void invalidate()
Invalidates the VertexBufferObject so a new OpenGL buffer handle is created. Use this in case of a context loss.


dispose

public void dispose()
Disposes of all resources this VertexBufferObject uses.

Specified by:
dispose in interface VertexData
Specified by:
dispose in interface Disposable

getBufferHandle

public int getBufferHandle()
Returns the VBO handle

Returns:
the VBO handle


Copyright © 2013. All Rights Reserved.