com.neovisionaries.android.opengl
Class ElementDrawer

java.lang.Object
  extended by com.neovisionaries.android.opengl.Drawer<ElementDrawer>
      extended by com.neovisionaries.android.opengl.ElementDrawer

public class ElementDrawer
extends Drawer<ElementDrawer>

Drawer to draw primitives using glDrawElements().

On Android 2.2 (API Level 8), the constructors that take ElementArrayBuffer and setIndices(ElementArrayBuffer) method should not be used. This is because android.opengl.GLES20 class of Android 2.2 does not have glDrawElements(int mode, int count, int type, int offset) method (note that the last argument is 'int offset') although it should have. Without the glDrawElements method, the element array buffer (represented by ElementArrayBuffer) cannot be used.

Author:
Takahiko Kawasaki
See Also:
glDrawElements

Constructor Summary
ElementDrawer()
          A constructor that just calls super().
ElementDrawer(DrawingMode mode)
          A constructor that just calls super(mode).
ElementDrawer(DrawingMode mode, Buffer indices)
          This constructor is an alias of ElementDrawer(mode, indices, 0).
ElementDrawer(DrawingMode mode, Buffer indices, int count)
          A constructor with indices data.
ElementDrawer(DrawingMode mode, ElementArrayBuffer indices)
          This constructor is an alias of ElementArrayBuffer(mode, indices, 0, 0).
ElementDrawer(DrawingMode mode, ElementArrayBuffer indices, int count)
          This constructor is an alias of ElementArrayBuffer(mode, indices, count, 0).
ElementDrawer(DrawingMode mode, ElementArrayBuffer indices, int count, int offset)
          A constructor with indices data held in the element array buffer.
 
Method Summary
 ElementDrawer draw()
          Draw primitives.
 int getCount()
          Get the number of indices used for drawing.
 Object getIndices()
          Get the indices that this drawer currently holds.
 int getOffset()
          Get the offset from the start of the element array buffer.
 ElementDrawer setCount(int count)
          Set the number of indices used for drawing.
 ElementDrawer setIndices(Buffer indices)
          Set the indices used for drawing.
 ElementDrawer setIndices(ElementArrayBuffer indices)
          Set the indices used for drawing.
 ElementDrawer setOffset(int offset)
          Set the offset from the start of the element array buffer.
 
Methods inherited from class com.neovisionaries.android.opengl.Drawer
getMode, setMode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ElementDrawer

public ElementDrawer()
A constructor that just calls super().


ElementDrawer

public ElementDrawer(DrawingMode mode)
A constructor that just calls super(mode).

Parameters:
mode - A drawing mode.
Throws:
IllegalArgumentException - The argument is null.

ElementDrawer

public ElementDrawer(DrawingMode mode,
                     Buffer indices)
This constructor is an alias of ElementDrawer(mode, indices, 0).


ElementDrawer

public ElementDrawer(DrawingMode mode,
                     Buffer indices,
                     int count)
A constructor with indices data.

Parameters:
mode - A drawing mode.
indices - Indices data. The actual class of 'indices' must be either ByteBuffer or ShortBuffer. If the extension OES_element_index_uint is supported, IntBuffer is also acceptable.
count - The number of indices.
Throws:
IllegalArgumentException -
  • 'mode' is null.
  • 'indices' is null.
  • 'count' is less than 0.
  • The actual class of 'indices' is not ByteBuffer or ShortBuffer. If OES_element_index_uint is supported, the actual class of 'indices' is allowed to be IntBuffer.

ElementDrawer

public ElementDrawer(DrawingMode mode,
                     ElementArrayBuffer indices)
This constructor is an alias of ElementArrayBuffer(mode, indices, 0, 0).


ElementDrawer

public ElementDrawer(DrawingMode mode,
                     ElementArrayBuffer indices,
                     int count)
This constructor is an alias of ElementArrayBuffer(mode, indices, count, 0).


ElementDrawer

public ElementDrawer(DrawingMode mode,
                     ElementArrayBuffer indices,
                     int count,
                     int offset)
A constructor with indices data held in the element array buffer.

It is necessary for 'indices' to have data before it is passed to this constructor. In other words, setData() method must have been called. Otherwise, this constructor throws IllegalArgumentException.

Note that this constructor should not be used in Android 2.2 (API Level 8).

Parameters:
indices -
count - The number of indices.
offset - The offset from the start of the element array buffer.
Throws:
IllegalArgumentException -
Method Detail

getIndices

public Object getIndices()
Get the indices that this drawer currently holds.

Returns:
The indices data. The returned object can be cast to either Buffer or ElementArrayBuffer. If neither setIndices(Buffer) nor setIndices(ElementArrayBuffer) has been called, null is returned.

setIndices

public ElementDrawer setIndices(Buffer indices)
Set the indices used for drawing.

Parameters:
indices -
Returns:
This ElementDrawer object.
Throws:
IllegalArgumentException -
  • The argument is null.
  • The actual class of the given object is not ByteBuffer or ShortBuffer. (IntBuffer is allowed if the extension OES_element_index_uint is supported.)

setIndices

public ElementDrawer setIndices(ElementArrayBuffer indices)
Set the indices used for drawing.

It is necessary for the given object to have data before it is passed to this method. In other words, setData() method must have been called. Otherwise, this setIndices() method throws IllegalArgumentException.

Note that this method should not be used in Android 2.2 (API Level 8).

Parameters:
indices -
Returns:
This ElementDrawer object.
Throws:
IllegalArgumentException -

getCount

public int getCount()
Get the number of indices used for drawing.

Returns:
The number of indices used for drawing.

setCount

public ElementDrawer setCount(int count)
Set the number of indices used for drawing.

Parameters:
count - The number of indices used for drawing.
Returns:
This ElementDrawer object.
Throws:
IllegalArgumentException - The argument is less than 0.

getOffset

public int getOffset()
Get the offset from the start of the element array buffer.

Returns:
The offset from the start of the element array buffer.

setOffset

public ElementDrawer setOffset(int offset)
Set the offset from the start of the element array buffer.

The value set by this method has a meaning only when indices are fed by the element array buffer. In other words, it has a meaning only if setIndices(ElementArrayBuffer) is used.

Parameters:
offset - The offset from the start of the element array buffer.
Returns:
This ElementDrawer object.

draw

public ElementDrawer draw()
Draw primitives.

If the index data this instance holds is an instance of Buffer and if the element array buffer holds some data, this method unbinds the element array buffer so that the index data can take effect.

On the contrary, the index data this instance holds is an instance of ElementArrayBuffer and if the ID of the data that is currently bound to the element array buffer is different from the ID of the index data (simply saying, if the index data's isBound() method returns false), this method binds the index data to the element array buffer (= this method calls the index data's bind() method) so that the index data can take effect.

Specified by:
draw in class Drawer<ElementDrawer>
Returns:
This ElementDrawer object.
Throws:
IllegalStateException - Indices are not set. That is, neither setIndices(Buffer) nor setIndices(ElementArrayBuffer) has been called.