NASA World Wind

gov.nasa.worldwind.util
Class CompoundVecBuffer

java.lang.Object
  extended by gov.nasa.worldwind.util.CompoundBuffer<VecBuffer,VecBuffer>
      extended by gov.nasa.worldwind.util.CompoundVecBuffer

public class CompoundVecBuffer
extends CompoundBuffer<VecBuffer,VecBuffer>

An implementation of CompoundBuffer which manages a collection of VecBuffer buffers in a single VecBuffer.


Nested Class Summary
protected  class CompoundVecBuffer.CompoundIterator<T>
           
protected  class CompoundVecBuffer.CoordIterable
           
protected  class CompoundVecBuffer.LocationIterable
           
protected  class CompoundVecBuffer.PositionIterable
           
protected  class CompoundVecBuffer.ReverseCompoundIterator<T>
           
protected static interface CompoundVecBuffer.SubBufferIterable<T>
           
protected  class CompoundVecBuffer.VectorIterable
           
 
Field Summary
protected  BufferFactory bufferFactory
           
 
Fields inherited from class gov.nasa.worldwind.util.CompoundBuffer
buffer, DEFAULT_INITIAL_CAPACITY, numSubBuffers, size, subLengthBuffer, subPositionBuffer
 
Constructor Summary
CompoundVecBuffer(int coordsPerVec, BufferFactory factory, int initialCapacity, int subBufferLength)
          Constructs a CompoundVecBuffer with the specified coordsPerElem, bufferFactory, and initial capacity.
CompoundVecBuffer(VecBuffer buffer, java.nio.IntBuffer subPositionBuffer, java.nio.IntBuffer subLengthBuffer, int numSubBuffers, BufferFactory factory)
          Creates a CompoundBuffer with the specified backing buffer, sub-buffer starting positions, sub-buffer lengths, and number of sub-buffers.
 
Method Summary
protected  void append(VecBuffer buffer)
           
 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 drawArrays(DrawContext dc, int drawMode)
          Renders getTotalBufferSize() elements from the currently bounds OpenGL coordinate buffers, beginning with element 0.
static CompoundVecBuffer fromSubset(CompoundVecBuffer buffer, int subBufferOffset, int length)
          Creates a CompoundVecBuffer from a subset of another CompoundVecBuffer.
 BufferFactory getBufferFactory()
          Returns the BufferFactory which creates backing data for the internal VecBuffer.
 java.lang.Iterable<double[]> getCoords()
          Returns an iterator over this buffer's logical vectors, as double[] coordinate arrays.
 java.lang.Iterable<double[]> getCoords(int minCoordsPerVec)
          Returns an iterator over this buffer's logical vectors, as double[] coordinate arrays.
 int getCoordsPerVec()
          Returns the number of coordinates per logical vector element.
 java.lang.Iterable<? extends LatLon> getLocations()
          Returns an iterator over this buffer's logical vectors, as LatLon locations.
 java.lang.Iterable<? extends Position> getPositions()
          Returns an iterator over this buffer's logical vectors, as geographic Positions.
 java.lang.Iterable<double[]> getReverseCoords(int minCoordsPerVec)
          Returns a reverse iterator over this buffer's logical vectors, as double[] coordinate arrays.
 java.lang.Iterable<? extends LatLon> getReverseLocations()
          Returns a reverse iterator over this buffer's logical vectors, as LatLon locations.
 java.lang.Iterable<? extends Position> getReversePositions()
          Returns a reverse iterator over this buffer's logical vectors, as geographic Positions.
 java.lang.Iterable<? extends Vec4> getReverseVectors()
          Returns a reverse iterator over this buffer's logical vectors, as Vec4 references.
protected  int getSize(VecBuffer buffer)
           
protected  VecBuffer getSubBuffer(int position, int length)
           
 java.lang.Iterable<? extends Vec4> getVectors()
          Returns an iterator over this buffer's logical vectors, as Vec4 references.
protected  boolean haveMultiDrawArrays(DrawContext dc)
           
 void multiDrawArrays(DrawContext dc, int drawMode)
          Renders elements from the currently bounds OpenGL coordinate buffers.
 
Methods inherited from class gov.nasa.worldwind.util.CompoundBuffer
appendEmptyBuffer, appendSubBuffer, clear, computeNewSize, getBackingBuffer, getNumSubBuffers, getSubBuffer, getSubLengthBuffer, getSubPositionBuffer, getTotalBufferSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bufferFactory

protected BufferFactory bufferFactory
Constructor Detail

CompoundVecBuffer

public CompoundVecBuffer(int coordsPerVec,
                         BufferFactory factory,
                         int initialCapacity,
                         int subBufferLength)
Constructs a CompoundVecBuffer with the specified coordsPerElem, bufferFactory, and initial capacity.

Parameters:
coordsPerVec - the number of coordinates per logical vector.
factory - the BufferFactory which creates backing data for the internal VecBuffer.
initialCapacity - the compound buffer's initial capacity.
subBufferLength - an estimate of the size of each sub-sequence.
Throws:
java.lang.IllegalArgumentException - if the initialCapacity is negative, or if the factory is null.

CompoundVecBuffer

public CompoundVecBuffer(VecBuffer buffer,
                         java.nio.IntBuffer subPositionBuffer,
                         java.nio.IntBuffer subLengthBuffer,
                         int numSubBuffers,
                         BufferFactory factory)
Creates a CompoundBuffer with the specified backing buffer, sub-buffer starting positions, sub-buffer lengths, and number of sub-buffers.

Parameters:
buffer - the backing buffer,
subPositionBuffer - the sub-buffer logical starting positions.
subLengthBuffer - the sub-buffer logical sizes.
numSubBuffers - the number of sub-buffers.
factory - the BufferFactory which creates backing data for the internal VecBuffer.
Throws:
java.lang.IllegalArgumentException - if any of the buffer, subPositionBuffer, subLengthBuffer are null, if numSubBuffers is negative.
Method Detail

append

protected void append(VecBuffer buffer)
Specified by:
append in class CompoundBuffer<VecBuffer,VecBuffer>

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:
java.lang.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:
java.lang.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:
java.lang.IllegalArgumentException - if the DrawContext is null, or if this buffer is not compatible as a vertex buffer.

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:
java.lang.IllegalArgumentException - if the DrawContext is null.

fromSubset

public static CompoundVecBuffer fromSubset(CompoundVecBuffer buffer,
                                           int subBufferOffset,
                                           int length)
Creates a CompoundVecBuffer from a subset of another CompoundVecBuffer. The new buffer shares the source buffer backing VecBuffer.

Parameters:
buffer - the source CompoundVecBuffer.
subBufferOffset - the index of the first sub-buffer to include in the subset.
length - the number of sub-buffers to include in the subset.
Returns:
a CompoundVecBuffer from a subset of the given CompoundVecBuffer.

getBufferFactory

public BufferFactory getBufferFactory()
Returns the BufferFactory which creates backing data for the internal VecBuffer.

Returns:
the BufferFactory which creates backing data for the internal VecBuffer.

getCoords

public java.lang.Iterable<double[]> getCoords()
Returns an iterator over this buffer's logical vectors, as double[] coordinate arrays. The array returned from each call to Iterator.next() will be newly allocated, and will have length equal to coordsPerVec.

Returns:
iterator over this buffer's vectors, as double[] arrays.

getCoords

public java.lang.Iterable<double[]> getCoords(int minCoordsPerVec)
Returns an iterator over this buffer's logical vectors, as double[] coordinate arrays. The array returned from a call to Iterator.next() will be newly allocated, and will have length equal to coordsPerVec or minCoordsPerVec, whichever is larger. If minCoordsPerVec is larger than coordsPerVec, then the elements in the returned array will after index "coordsPerVec - 1" will be undefined.

Parameters:
minCoordsPerVec - the minimum number of coordinates returned in each double[] array.
Returns:
iterator over this buffer's vectors, as double[] arrays.

getCoordsPerVec

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

Returns:
the cardinality of a logical vector element.

getLocations

public java.lang.Iterable<? extends LatLon> getLocations()
Returns an iterator over this buffer's logical vectors, as LatLon locations.

Returns:
iterator over this buffer's vectors, as LatLon locations.

getPositions

public java.lang.Iterable<? extends Position> getPositions()
Returns an iterator over this buffer's logical vectors, as geographic Positions.

Returns:
iterator over this buffer's vectors, as geographic Positions.

getReverseCoords

public java.lang.Iterable<double[]> getReverseCoords(int minCoordsPerVec)
Returns a reverse iterator over this buffer's logical vectors, as double[] coordinate arrays. The array returned from a call to Iterator.next() will be newly allocated, and will have length equal to coordsPerVec or minCoordsPerVec, whichever is larger. If minCoordsPerVec is larger than coordsPerVec, then the elements in the returned array will after index "coordsPerVec - 1" will be undefined.

Parameters:
minCoordsPerVec - the minimum number of coordinates returned in each double[] array.
Returns:
reverse iterator over this buffer's vectors, as double[] arrays.

getReverseLocations

public java.lang.Iterable<? extends LatLon> getReverseLocations()
Returns a reverse iterator over this buffer's logical vectors, as LatLon locations.

Returns:
reverse iterator over this buffer's vectors, as LatLon locations.

getReversePositions

public java.lang.Iterable<? extends Position> getReversePositions()
Returns a reverse iterator over this buffer's logical vectors, as geographic Positions.

Returns:
reverse iterator over this buffer's vectors, as geographic Positions.

getReverseVectors

public java.lang.Iterable<? extends Vec4> getReverseVectors()
Returns a reverse iterator over this buffer's logical vectors, as Vec4 references.

Returns:
reverse iterator over this buffer's vectors, as Vec4 references.

getSize

protected int getSize(VecBuffer buffer)
Specified by:
getSize in class CompoundBuffer<VecBuffer,VecBuffer>

getSubBuffer

protected VecBuffer getSubBuffer(int position,
                                 int length)
Specified by:
getSubBuffer in class CompoundBuffer<VecBuffer,VecBuffer>

getVectors

public java.lang.Iterable<? extends Vec4> getVectors()
Returns an iterator over this buffer's logical vectors, as Vec4 references.

Returns:
iterator over this buffer's vectors, as Vec4 references.

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:
java.lang.IllegalArgumentException - if the DrawContext is null.

NASA World Wind