com.neovisionaries.android.opengl
Class VertexBuffer<TVertexBuffer extends VertexBuffer<TVertexBuffer>>

java.lang.Object
  extended by com.neovisionaries.android.opengl.VertexBuffer<TVertexBuffer>
Direct Known Subclasses:
ArrayBuffer, ElementArrayBuffer

public abstract class VertexBuffer<TVertexBuffer extends VertexBuffer<TVertexBuffer>>
extends Object

OpenGL ES vertex buffer.

 // E X A M P L E   1

 // Create a vertex buffer.
 VertexBuffer vb = new ArrayBuffer();
 //VertexBuffer vb = new ElementArrayBuffer();

 // Bind the vertex buffer.
 vb.bind();

 // Prepare data to set to the vertex buffer.
 Buffer data = ...;

 // Set the data to the vertex buffer.
 vb.setData(data);
 

Author:
Takahiko Kawasaki

Constructor Summary
protected VertexBuffer(VertexBufferType type)
          A constructor with a vertex buffer type.
 
Method Summary
 TVertexBuffer bind()
          Bind this vertex buffer using glBindBuffer().
 TVertexBuffer delete()
          Delete the buffer object using glDeleteBuffers().
 int getId()
          Get the ID of the buffer object assigned to this instance.
 VertexBufferState getState()
          Get the state of this vertex buffer.
 VertexBufferType getType()
          Get the type of this vertex buffer.
abstract  boolean isBound()
          Check if this vertex buffer is bound.
 TVertexBuffer setData(Buffer data)
          This method calls setData(data, -1, null).
 TVertexBuffer setData(Buffer data, int count)
          This method calls setData(data, count, null).
 TVertexBuffer setData(Buffer data, int count, VertexBufferUsage usage)
          Set data to this vertex buffer.
 TVertexBuffer setData(Buffer data, VertexBufferUsage usage)
          This method calls setData(data, -1, usage).
 TVertexBuffer setSubData(Buffer data)
          This method calls setSubData(data, -1, 0).
 TVertexBuffer setSubData(Buffer data, int count)
          This method calls setSubData(data, count, 0).
 TVertexBuffer setSubData(Buffer data, int count, int offset)
          Set sub data to this vertex buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VertexBuffer

protected VertexBuffer(VertexBufferType type)
                throws GLESException
A constructor with a vertex buffer type. A buffer object is assigned internally by glGenBuffers(). If this constructor returns without any exception, the state of this instance is VertexBufferState.CREATED.

Parameters:
type - VertexBufferType.ARRAY or VertexBufferType.ELEMENT_ARRAY.
Throws:
IllegalArgumentException - The given argument is null.
GLESException - glGenBuffers() failed.
See Also:
ArrayBuffer.ArrayBuffer(), ElementArrayBuffer.ElementArrayBuffer(), glGenBuffers
Method Detail

getType

public VertexBufferType getType()
Get the type of this vertex buffer.

Returns:
The type of this vertex buffer.

getId

public int getId()
Get the ID of the buffer object assigned to this instance.

Returns:
The ID of the buffer object assigned by glGenBuffers().
See Also:
glGenBuffers

getState

public VertexBufferState getState()
Get the state of this vertex buffer.

Returns:
The current state of this vertex buffer.

bind

public TVertexBuffer bind()
Bind this vertex buffer using glBindBuffer().

Returns:
This VertexBuffer object.
Throws:
IllegalStateException - This vertex buffer has already been deleted.
See Also:
glBindBuffer

delete

public TVertexBuffer delete()
Delete the buffer object using glDeleteBuffers(). If the buffer object has already been deleted, nothing is executed. After this method returns, the state of this instance is VertexBufferState.DELETED.

Returns:
This VertexBuffer object.
See Also:
glDeleteBuffers

setData

public TVertexBuffer setData(Buffer data,
                             int count,
                             VertexBufferUsage usage)
Set data to this vertex buffer.

As a side effect, if this vertex buffer has not been bound yet, bind() is executed before glBufferData().

Parameters:
data - Data to pass to glBufferData().
count - The number of elements to pass to glBufferData(). Note that the unit is not 'bytes'. The size (in bytes) to pass to glBufferData() is calculated in this method based on the type of the given data. If 'count' is a negative value, data.remaining() is used.
usage - Usage of the data. If null is given, VertexBufferUsage.STATIC is used.
Returns:
This VertexBuffer object.
Throws:
IllegalArgumentException - 'data' is null, or 'count' exceeds data.remaining().
See Also:
glBufferData

setData

public TVertexBuffer setData(Buffer data,
                             VertexBufferUsage usage)
This method calls setData(data, -1, usage).

Parameters:
data - Data to pass to glBufferData().
usage - Usage of the data.
Returns:
This VertexBuffer object.
See Also:
setData(Buffer, int, VertexBufferUsage)

setData

public TVertexBuffer setData(Buffer data,
                             int count)
This method calls setData(data, count, null).

Parameters:
data - Data to pass to glBufferData().
count - The number of elements to pass to glBufferData().
Returns:
This VertexBuffer object.
See Also:
setData(Buffer, int, VertexBufferUsage)

setData

public TVertexBuffer setData(Buffer data)
This method calls setData(data, -1, null).

Parameters:
data - Data to pass to glBufferData().
Returns:
This VertexBuffer object.
See Also:
setData(Buffer, int, VertexBufferUsage)

setSubData

public TVertexBuffer setSubData(Buffer data,
                                int count,
                                int offset)
Set sub data to this vertex buffer.

Parameters:
data - Data to pass to glBufferSubData().
count - The number of elements to pass to glBufferSubData(). Note that the unit is not 'bytes'. The size (in bytes) to pass to glBufferSubData() is calculated in this method based on the type of the given data. If 'count' is a negative value, data.remaining() is used.
offset - The number of elements to skip. Note that the unit is not 'bytes'. The offset (in bytes) to pass to glBufferSubData() is calculated in this method based on the type of the given data.
Returns:
This VertexBuffer object.
Throws:
IllegalArgumentException - 'data' is null, or 'count' exceeds data.remaining().
See Also:
glBufferSubData

setSubData

public TVertexBuffer setSubData(Buffer data,
                                int count)
This method calls setSubData(data, count, 0).

Parameters:
data - Data to pass to glBufferSubData().
count - The number of elements to pass to glBufferSubData().
Returns:
This VertexBuffer object.
See Also:
setSubData(Buffer, int, int)

setSubData

public TVertexBuffer setSubData(Buffer data)
This method calls setSubData(data, -1, 0).

Parameters:
data - Data to pass to glBufferSubData().
Returns:
This VertexBuffer object.
See Also:
setSubData(Buffer, int, int)

isBound

public abstract boolean isBound()
Check if this vertex buffer is bound.

Returns:
True if this vertex buffer is bound.