NASA World Wind

gov.nasa.worldwind.util
Class VecBufferSequence

java.lang.Object
  extended by gov.nasa.worldwind.util.CompoundVecBuffer
      extended by gov.nasa.worldwind.util.VecBufferSequence

public class VecBufferSequence
extends CompoundVecBuffer

VecBufferSequence provides storage and retrieval of a sequence of logical VecBuffers in a single VecBuffer that expands when more capacity is needed. VecBuffers added to a VecBufferSequence by calling append(VecBuffer). This copies the specified VecBuffer's data to the VecBuffer backing the VecBufferSequence, and expands the backing VecBuffer if necessary.


Nested Class Summary
 
Nested classes/interfaces inherited from class gov.nasa.worldwind.util.CompoundVecBuffer
CompoundVecBuffer.CompoundIterator<T>, CompoundVecBuffer.CoordIterable, CompoundVecBuffer.EmptyCompoundVecBuffer, CompoundVecBuffer.LocationIterable, CompoundVecBuffer.PositionIterable, CompoundVecBuffer.ReverseCompoundIterator<T>, CompoundVecBuffer.SubBufferIterable<T>, CompoundVecBuffer.VectorIterable
 
Field Summary
protected  VecBuffer buffer
           
protected  int vecCount
           
 
Fields inherited from class gov.nasa.worldwind.util.CompoundVecBuffer
ALLOCATE_DIRECT_BUFFERS, capacity, count, DEFAULT_INITIAL_CAPACITY, lengths, offsets
 
Constructor Summary
  VecBufferSequence(VecBuffer buffer)
          Constructs a PackedCompoundVecBuffer with the specified backing VecBuffer and the default initial capacity.
  VecBufferSequence(VecBuffer buffer, int capacity)
          Constructs a PackedCompoundVecBuffer with the specified backing VecBuffer and the specified initial capacity.
protected VecBufferSequence(VecBufferSequence that, int[] indices, int offset, int length)
           
protected VecBufferSequence(VecBufferSequence that, int beginIndex, int endIndex)
           
 
Method Summary
 int append(VecBuffer buffer)
          Appends the contents of the specified sub-buffer to the end of this PackedCompoundVecBuffer, incrementing the number of sub-buffers by one.
 void bindAsNormalBuffer(DrawContext dc)
          Binds this buffer as the source of normal coordinates to use when rendering OpenGL primitives.
 void bindAsTexCoordBuffer(DrawContext dc)
          Binds this buffer as the source of texture coordinates to use when rendering OpenGL primitives.
 void bindAsVertexBuffer(DrawContext dc)
          Binds this buffer as the source of vertex coordinates to use when rendering OpenGL primitives.
 void clear()
          Sets the number sub-buffers to zero.
protected  CompoundVecBuffer createSlice(int[] indices, int offset, int length)
           
protected  CompoundVecBuffer createSlice(int beginIndex, int endIndex)
           
protected  VecBuffer createSubBuffer(int offset, int length)
           
 void drawArrays(DrawContext dc, int drawMode)
          Renders getTotalBufferSize() elements from the currently bounds OpenGL coordinate buffers, beginning with element 0.
static VecBufferSequence emptyVecBufferSequence(int coordsPerVec)
          Returns an empty VecBufferSequence.
protected  void expandBufferCapacity(int minCapacity)
           
 int getCoordsPerVec()
          Returns the number of coordinates per logical vector element.
 VecBuffer getVecBuffer()
          Returns the VecBuffer that stores this PackedCompoundVecBuffer's sub-buffers.
protected  boolean haveMultiDrawArrays(DrawContext dc)
           
 void multiDrawArrays(DrawContext dc, int drawMode)
          Renders elements from the currently bounds OpenGL coordinate buffers.
 int subBufferSize(int index)
          Returns the size in logical vectors of the VecBuffer with the specified index.
 
Methods inherited from class gov.nasa.worldwind.util.CompoundVecBuffer
addSubBuffer, emptyCompoundVecBuffer, expandCapacity, getCoords, getCoords, getLocations, getPositions, getReverseCoords, getReverseLocations, getReversePositions, getReverseVectors, getVectors, size, slice, slice, slice, subBuffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

protected VecBuffer buffer

vecCount

protected int vecCount
Constructor Detail

VecBufferSequence

public VecBufferSequence(VecBuffer buffer)
Constructs a PackedCompoundVecBuffer with the specified backing VecBuffer and the default initial capacity.

Parameters:
buffer - the backing VecBuffer.
Throws:
IllegalArgumentException - if the buffer is null.

VecBufferSequence

public VecBufferSequence(VecBuffer buffer,
                         int capacity)
Constructs a PackedCompoundVecBuffer with the specified backing VecBuffer and the specified initial capacity.

Parameters:
buffer - the backing VecBuffer.
capacity - the PackedCompoundVecBuffer's initial capacity, in number of sub-buffers.
Throws:
IllegalArgumentException - if the buffer is null, or if the capacity is less than 1.

VecBufferSequence

protected VecBufferSequence(VecBufferSequence that,
                            int[] indices,
                            int offset,
                            int length)

VecBufferSequence

protected VecBufferSequence(VecBufferSequence that,
                            int beginIndex,
                            int endIndex)
Method Detail

append

public int append(VecBuffer buffer)
Appends the contents of the specified sub-buffer to the end of this PackedCompoundVecBuffer, incrementing the number of sub-buffers by one. The backing buffer grows to accomodate the sub-buffer if it does not already have enough capacity to hold it.

Parameters:
buffer - the sub-buffer to append.
Returns:
the sub-buffer's index.
Throws:
IllegalArgumentException - if the subBuffer is null.

bindAsNormalBuffer

public void bindAsNormalBuffer(DrawContext dc)
Binds this buffer as the source of normal coordinates to use when rendering OpenGL primitives. The normal type is equal to buffer's underlying BufferWrapper GL type, the stride is 0, and the vertex data itself is this buffer's backing NIO Buffer. This buffer's vector size must be 3.

Parameters:
dc - the current DrawContext.
Throws:
IllegalArgumentException - if the DrawContext is null, or if this buffer is not compatible as a normal buffer.

bindAsTexCoordBuffer

public void bindAsTexCoordBuffer(DrawContext dc)
Binds this buffer as the source of texture coordinates to use when rendering OpenGL primitives. The texture coordinate size is equal to coordsPerVertex, the texture coordinate type is equal to buffer's underlying BufferWrapper GL type, the stride is 0, and the texture coordinate data itself is this buffer's backing NIO Buffer. This buffer's vector size must be 1, 2, 3, or 4.

Parameters:
dc - the current DrawContext.
Throws:
IllegalArgumentException - if the DrawContext is null, or if this buffer is not compatible as a normal buffer.

bindAsVertexBuffer

public void bindAsVertexBuffer(DrawContext dc)
Binds this buffer as the source of vertex coordinates to use when rendering OpenGL primitives. The vertex size is equal to coordsPerVertex, the vertex type is equal to buffer's underlying BufferWrapper GL type, the stride is 0, and the normal data itself is this buffer's backing NIO Buffer. This buffer's vector size must be 2, 3, or 4.

Parameters:
dc - the current DrawContext.
Throws:
IllegalArgumentException - if the DrawContext is null, or if this buffer is not compatible as a vertex buffer.

clear

public void clear()
Sets the number sub-buffers to zero. This does not free any memory associated with this CompoundVecBuffer.

Overrides:
clear in class CompoundVecBuffer

createSlice

protected CompoundVecBuffer createSlice(int[] indices,
                                        int offset,
                                        int length)
Specified by:
createSlice in class CompoundVecBuffer

createSlice

protected CompoundVecBuffer createSlice(int beginIndex,
                                        int endIndex)
Specified by:
createSlice in class CompoundVecBuffer

createSubBuffer

protected VecBuffer createSubBuffer(int offset,
                                    int length)
Specified by:
createSubBuffer in class CompoundVecBuffer

drawArrays

public void drawArrays(DrawContext dc,
                       int drawMode)
Renders getTotalBufferSize() elements from the currently bounds OpenGL coordinate buffers, beginning with element 0. The specified drawMode indicates which type of OpenGL primitives to render.

Parameters:
dc - the current DrawContext.
drawMode - the type of OpenGL primtives to render.
Throws:
IllegalArgumentException - if the DrawContext is null.

emptyVecBufferSequence

public static VecBufferSequence emptyVecBufferSequence(int coordsPerVec)
Returns an empty VecBufferSequence. The returned VecBufferSequence has a size of zero and contains no sub-buffers.

Parameters:
coordsPerVec - the number of coordinates per logical vector.
Returns:
the empty VecBufferSequence.

expandBufferCapacity

protected void expandBufferCapacity(int minCapacity)

getCoordsPerVec

public int getCoordsPerVec()
Returns the number of coordinates per logical vector element.

Specified by:
getCoordsPerVec in class CompoundVecBuffer
Returns:
the cardinality of a logical vector element.

getVecBuffer

public VecBuffer getVecBuffer()
Returns the VecBuffer that stores this PackedCompoundVecBuffer's sub-buffers.

Returns:
this PackedCompoundVecBuffer's backing VecBuffer.

haveMultiDrawArrays

protected boolean haveMultiDrawArrays(DrawContext dc)

multiDrawArrays

public void multiDrawArrays(DrawContext dc,
                            int drawMode)
Renders elements from the currently bounds OpenGL coordinate buffers. This behaves exactly like drawArrays(gov.nasa.worldwind.render.DrawContext, int), except that each sub-buffer is rendered independently. The specified drawMode indicates which type of OpenGL primitives to render.

Parameters:
dc - the current DrawContext.
drawMode - the type of OpenGL primtives to render.
Throws:
IllegalArgumentException - if the DrawContext is null.

subBufferSize

public int subBufferSize(int index)
Returns the size in logical vectors of the VecBuffer with the specified index.

Specified by:
subBufferSize in class CompoundVecBuffer
Parameters:
index - the index for the VecBuffer who's size is returned.
Returns:
the size of the specified VecBuffer.

NASA World Wind