public class SurfaceObjectTileBuilder
extends java.lang.Object
SurfaceTile
instances who's content is defined by a specified set
of SurfaceRenderable
instances. It's typically not necessary to use
SurfaceObjectTileBuilder directly. WorldWind's default scene controller automatically batches instances of
SurfaceRenderable in a single SurfaceObjectTileBuilder. Applications that need to draw basic surface shapes should
use or extend SurfaceShape
instead of using SurfaceObjectTileBuilder directly.
Surface tiles are built by calling buildTiles(DrawContext, Iterable)
with an iterable of surface
renderables. This assembles a set of surface tiles that meet the resolution requirements for the specified draw
context, then draws the surface renderables into those offscreen surface tiles by calling render on each instance.
This process may temporarily use the framebuffer to perform offscreen rendering, and therefore should be called
during the preRender method of a WorldWind layer. See the PreRenderable
interface
for details. Once built, the surface tiles can be rendered by a SurfaceTileRenderer
.
By default, SurfaceObjectTileBuilder creates texture tiles with a width and height of 512 pixels, and with internal
format GL_RGBA
. These parameters are configurable by calling setTileDimension(java.awt.Dimension)
or setTileTextureFormat(int)
.
The most common usage pattern for SurfaceObjectTileBuilder is to build the surface tiles from a set of surface renderables during the preRender phase, then draw those surface tiles during the render phase. For example, a renderable can use SurfaceObjectTileBuilder to draw a set of surface renderables as follows:
class MyRenderable implements Renderable, PreRenderable
{
protected SurfaceObjectTileBuilder tileBuilder = new SurfaceObjectTileBuilder();
public void preRender(DrawContext dc)
{
List<?> surfaceRenderables = Arrays.asList(
new SurfaceCircle(LatLon.fromDegrees(0, 100), 10000),
new SurfaceSquare(LatLon.fromDegrees(0, 101), 10000));
this.tileBuilder.buildSurfaceTiles(dc, surfaceRenderables);
}
public void render(DrawContext dc)
{
dc.getGeographicSurfaceTileRenderer().renderTiles(dc, this.tileBuilder.getTiles(dc));
}
}
Modifier and Type | Class and Description |
---|---|
protected static class |
SurfaceObjectTileBuilder.SurfaceObjectTile
Represents a
TextureTile who's contents is constructed by a set of surface
objects. |
protected static class |
SurfaceObjectTileBuilder.SurfaceObjectTileStateKey
Represents a surface renderable tile's current state.
|
protected static class |
SurfaceObjectTileBuilder.TileInfo |
protected static class |
SurfaceObjectTileBuilder.TileInfoKey |
Modifier and Type | Field and Description |
---|---|
protected SurfaceObjectTileBuilder.TileInfo |
currentInfo
The currently active TileInfo.
|
protected java.util.List<SurfaceRenderable> |
currentSurfaceObjects
List of currently assembled surface renderables.
|
protected static LatLon |
DEFAULT_LEVEL_ZERO_TILE_DELTA
The default level zero tile delta used to construct a LevelSet.
|
protected static int |
DEFAULT_NUM_LEVELS
The default number of levels used to construct a LevelSet.
|
protected static double |
DEFAULT_SPLIT_SCALE
The default split scale.
|
protected static int |
DEFAULT_TEXTURE_DIMENSION
The default surface tile texture dimension, in pixels.
|
protected static int |
DEFAULT_TEXTURE_INTERNAL_FORMAT
The default OpenGL internal format used to create surface tile textures.
|
protected static int |
DEFAULT_TEXTURE_PIXEL_FORMAT
The default OpenGL pixel format used to create surface tile textures.
|
protected boolean |
forceTileUpdates
Controls if tiles are forced to update during
buildTiles(DrawContext, Iterable) . |
protected static java.util.Map<java.awt.Dimension,LevelSet> |
levelSetMap
Map associating a tile texture dimension to its corresponding LevelSet.
|
protected static long |
nextUniqueId
The next unique ID.
|
protected OGLRenderToTextureSupport |
rttSupport
Support class used to render to an offscreen surface tile.
|
protected double |
splitScale
Controls the tile resolution as distance changes between the globe's surface and the eye point.
|
protected java.awt.Dimension |
tileDimension
Indicates the desired tile texture width and height, in pixels.
|
protected java.util.Map<java.lang.Object,SurfaceObjectTileBuilder.TileInfo> |
tileInfoMap
List of currently assembled surface tiles.
|
protected int |
tileTextureFormat
The surface tile OpenGL texture format.
|
protected boolean |
useLinearFilter
Controls if surface tiles are rendered using a linear filter or a nearest-neighbor filter.
|
protected boolean |
useMipmaps
Controls if mip-maps are generated for surface tile textures.
|
Constructor and Description |
---|
SurfaceObjectTileBuilder()
Constructs a new SurfaceObjectTileBuilder with a tile width and height of
512 , with the default tile
texture format, with linear filtering enabled, and with mip-mapping disabled. |
SurfaceObjectTileBuilder(java.awt.Dimension tileTextureDimension,
int tileTextureFormat,
boolean useLinearFilter,
boolean useMipmaps)
Constructs a new SurfaceObjectTileBuilder width the specified tile dimension, tile texture format, and flags
specifying if linear filtering and mip-mapping are enabled.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addIntersectingObjects(DrawContext dc,
SurfaceObjectTileBuilder.SurfaceObjectTile parent,
SurfaceObjectTileBuilder.SurfaceObjectTile tile)
Adds surface renderables from the parent's object list to the specified tile's object list.
|
protected void |
addTile(SurfaceObjectTileBuilder.SurfaceObjectTile tile)
Adds the specified tile to this tile builder's
currentInfo and the TextureTile memory cache. |
protected void |
addTileOrDescendants(DrawContext dc,
LevelSet levelSet,
SurfaceObjectTileBuilder.SurfaceObjectTile parent,
SurfaceObjectTileBuilder.SurfaceObjectTile tile)
Potentially adds the specified tile or its descendants to the tile builder's
currentInfo . |
protected void |
assembleSurfaceObjects(java.lang.Iterable<?> iterable)
Adds any SurfaceRenderables in the specified Iterable to the tile builder's
currentSurfaceObjects list. |
protected void |
assembleTiles(DrawContext dc)
Assembles a set of surface tiles that are visible in the specified DrawContext and meet the tile builder's
resolution criteria.
|
void |
buildTiles(DrawContext dc,
java.lang.Iterable<?> iterable)
Assembles the surface tiles and draws any surface renderables in the iterable into those offscreen tiles.
|
protected boolean |
canAssembleTiles(DrawContext dc)
Returns true if the draw context's viewport width and height are greater than zero.
|
void |
clearPickCandidates(DrawContext dc)
Removes all entries from the list of pickable object candidates assembled during the last call to
buildTiles(DrawContext, Iterable) . |
void |
clearTiles(DrawContext dc)
Removes all entries from the list of SurfaceTiles assembled during the last call to
buildTiles(DrawContext, Iterable) . |
protected java.awt.Dimension |
computeTextureTileDimension(DrawContext dc)
Returns the tile dimension used to create the tile textures for the specified
DrawContext . |
protected static LevelSet |
createLevelSet(int tileWidth,
int tileHeight)
Returns a new LevelSet with the specified tile width and height.
|
protected java.lang.Object |
createSurfaceTileDrawContext(SurfaceObjectTileBuilder.SurfaceObjectTile tile)
Returns a new Object representing the drawing context for the specified tile.
|
protected SurfaceObjectTileBuilder.SurfaceObjectTile |
createTile(Sector sector,
Level level,
int row,
int column,
java.lang.String cacheName)
Returns a new SurfaceObjectTile corresponding to the specified
sector , level , row , column , and cacheName . |
protected SurfaceObjectTileBuilder.TileInfo |
createTileInfo(DrawContext dc)
Creates a tile info associated with the specified draw context.
|
protected SurfaceObjectTileBuilder.TileInfoKey |
createTileInfoKey(DrawContext dc)
Creates a key to address the tile information associated with the specified draw context.
|
protected java.lang.Object |
createTileKey(Level level,
int row,
int column,
java.lang.String cacheName)
Returns a new tile key corresponding to the tile with the specified
level , row , column ,
and cacheName . |
protected com.jogamp.opengl.util.texture.Texture |
createTileTexture(DrawContext dc,
int width,
int height)
Returns a new surface tile texture for use on the specified draw context with the specified width and height.
|
protected LevelSet |
getLevelSet(int tileWidth,
int tileHeight)
Returns a shared
LevelSet for the specified tileDimension . |
java.util.Collection<PickedObject> |
getPickCandidates(DrawContext dc)
Returns the list of pickable object candidates associated with the SurfaceTiles assembled during the last call to
buildTiles(DrawContext, Iterable) . |
double |
getSplitScale()
Returns the split scale value controlling the tile's surface texel resolution relative to the distance between
the globe's surface at the image position and the eye point.
|
int |
getTileCount(DrawContext dc)
Returns the number of SurfaceTiles assembled during the last call to
buildTiles(DrawContext, Iterable) . |
java.awt.Dimension |
getTileDimension()
Returns the surface tile dimension.
|
java.util.Collection<? extends SurfaceTile> |
getTiles(DrawContext dc)
Returns the list of SurfaceTiles assembled during the last call to
buildTiles(DrawContext, Iterable) . |
int |
getTileTextureFormat()
Returns the surface tile's OpenGL texture format, or 0 to indicate that the default format is used.
|
protected boolean |
intersectsFrustum(DrawContext dc,
TextureTile tile)
Test if the tile intersects the specified draw context's frustum.
|
protected boolean |
intersectsVisibleSector(DrawContext dc,
TextureTile tile)
Test if the specified tile intersects the draw context's visible sector.
|
boolean |
isForceTileUpdates()
Indicates whether or not tiles textures are forced to update during
buildTiles(DrawContext, Iterable) . |
boolean |
isUseLinearFilter()
Returns if linear filtering is used when rendering surface tiles.
|
boolean |
isUseMipmaps()
Returns if mip-maps are generated for surface tile textures.
|
protected boolean |
meetsRenderCriteria(DrawContext dc,
LevelSet levelSet,
Tile tile)
Tests if the specified tile meets the rendering criteria on the specified draw context.
|
protected boolean |
needToSplit(DrawContext dc,
Tile tile)
Tests if the specified tile must be split to meets the desired resolution on the specified draw context.
|
void |
setForceTileUpdates(boolean forceTileUpdates)
Specifies whether or not tiles textures are forced to update during
buildTiles(DrawContext, Iterable) . |
void |
setSplitScale(double splitScale)
Sets the parameter controlling the tile resolution as distance changes between the globe's surface and the eye
point.
|
void |
setTileDimension(java.awt.Dimension dimension)
Specifies the preferred surface tile texture dimension.
|
void |
setTileTextureFormat(int textureFormat)
Specifies the surface tile's OpenGL texture format.
|
void |
setUseLinearFilter(boolean useLinearFilter)
Specifies if linear filtering should be used when rendering surface tiles.
|
void |
setUseMipmaps(boolean useMipmaps)
Specifies if mip-maps should be generated for surface tile textures.
|
protected java.lang.String |
uniqueCacheName()
Returns a unique name appropriate for use as part of a cache name.
|
protected void |
updateTile(DrawContext dc,
SurfaceObjectTileBuilder.SurfaceObjectTile tile)
Draws the current list of surface renderables into the specified surface tile.
|
protected void |
updateTiles(DrawContext dc)
Updates each
SurfaceObjectTileBuilder.SurfaceObjectTile in the currentInfo . |
protected SurfaceObjectTileBuilder.TileInfo currentInfo
buildTiles(DrawContext, Iterable)
.protected java.util.List<SurfaceRenderable> currentSurfaceObjects
buildTiles(DrawContext, Iterable)
.protected static final LatLon DEFAULT_LEVEL_ZERO_TILE_DELTA
protected static final int DEFAULT_NUM_LEVELS
protected static final double DEFAULT_SPLIT_SCALE
protected static final int DEFAULT_TEXTURE_DIMENSION
protected static final int DEFAULT_TEXTURE_INTERNAL_FORMAT
protected static final int DEFAULT_TEXTURE_PIXEL_FORMAT
protected boolean forceTileUpdates
buildTiles(DrawContext, Iterable)
.protected static java.util.Map<java.awt.Dimension,LevelSet> levelSetMap
protected static long nextUniqueId
protected OGLRenderToTextureSupport rttSupport
protected double splitScale
protected java.awt.Dimension tileDimension
DEFAULT_TEXTURE_DIMENSION
.protected java.util.Map<java.lang.Object,SurfaceObjectTileBuilder.TileInfo> tileInfoMap
protected int tileTextureFormat
protected boolean useLinearFilter
protected boolean useMipmaps
public SurfaceObjectTileBuilder()
512
, with the default tile
texture format, with linear filtering enabled, and with mip-mapping disabled.public SurfaceObjectTileBuilder(java.awt.Dimension tileTextureDimension, int tileTextureFormat, boolean useLinearFilter, boolean useMipmaps)
tileTextureDimension
- the surface tile texture dimension, in pixels.tileTextureFormat
- the surface tile OpenGL texture format, or 0 to use the default format.useLinearFilter
- true to use linear filtering while rendering surface tiles; false to use
nearest-neighbor filtering.useMipmaps
- true to generate mip-maps for surface tile textures; false otherwise.java.lang.IllegalArgumentException
- if the tile dimension is null.protected void addIntersectingObjects(DrawContext dc, SurfaceObjectTileBuilder.SurfaceObjectTile parent, SurfaceObjectTileBuilder.SurfaceObjectTile tile)
dc
- the current DrawContext.parent
- the tile's parent.tile
- the tile to add intersecting surface renderables to.protected void addTile(SurfaceObjectTileBuilder.SurfaceObjectTile tile)
currentInfo
and the TextureTile memory cache.tile
- the tile to add.protected void addTileOrDescendants(DrawContext dc, LevelSet levelSet, SurfaceObjectTileBuilder.SurfaceObjectTile parent, SurfaceObjectTileBuilder.SurfaceObjectTile tile)
currentInfo
. The tile and
its descendants are discarded if the tile is not visible or does not intersect any surface renderables in the
parent's surface renderable list. See SurfaceObjectTileBuilder.SurfaceObjectTile.getObjectList()
.
If the tile meet the tile builder's resolution criteria it's added to the tile builder's
currentTiles
list. Otherwise, it's split into four sub-tiles and each tile is recursively processed.
See meetsRenderCriteria(DrawContext, gov.nasa.worldwind.util.LevelSet, gov.nasa.worldwind.util.Tile)
.
dc
- the current DrawContext.levelSet
- the tile's LevelSet.parent
- the tile's parent, or null if the tile is a top level tile.tile
- the tile to add.protected void assembleSurfaceObjects(java.lang.Iterable<?> iterable)
currentSurfaceObjects
list.iterable
- the Iterable to gather SurfaceRenderables from.protected void assembleTiles(DrawContext dc)
currentInfo
.
During assembly each surface renderable in currentSurfaceObjects
is sorted into the tiles they
intersect. The top level tiles are used as an index to quickly determine which tiles each renderable intersects.
Surface renderables are sorted into sub-tiles by simple intersection tests, and are added to each tile's surface
renderable list at most once. See SurfaceObjectTileBuilder.SurfaceObjectTile.addSurfaceObject(SurfaceRenderable,
gov.nasa.worldwind.geom.Sector)
. Tiles that don't intersect any surface renderables are discarded.
dc
- the DrawContext to assemble tiles for.public void buildTiles(DrawContext dc, java.lang.Iterable<?> iterable)
View
. This may temporarily use the framebuffer to perform offscreen rendering, and therefore
should be called during the preRender method of a WorldWind Layer
.
This does nothing if the specified iterable is null, is empty or contains no surface renderables.
dc
- the draw context to build tiles for.iterable
- the iterable to gather surface renderables from.java.lang.IllegalArgumentException
- if the draw context is null.protected boolean canAssembleTiles(DrawContext dc)
dc
- the DrawContext to test.public void clearPickCandidates(DrawContext dc)
buildTiles(DrawContext, Iterable)
.dc
- the draw context used to build tiles.java.lang.IllegalArgumentException
- if the draw context is null.public void clearTiles(DrawContext dc)
buildTiles(DrawContext, Iterable)
.dc
- the draw context used to build tiles.java.lang.IllegalArgumentException
- if the draw context is null.protected java.awt.Dimension computeTextureTileDimension(DrawContext dc)
DrawContext
. This
attempts to use this tile builder's tileDimension
, but always returns a dimension that is is a power of
two, is square, and fits in the DrawContext
's viewport.dc
- the DrawContext
to compute a texture tile dimension for.DrawContext
.protected static LevelSet createLevelSet(int tileWidth, int tileHeight)
DEFAULT_LEVEL_ZERO_TILE_DELTA
, has number of levels equal to DEFAULT_NUM_LEVELS
(with no empty levels). The LevelSets' cache name and dataset name dummy values, and should
not be used.tileWidth
- the LevelSet's tile width, in pixels.tileHeight
- the LevelSet's tile height, in pixels.protected java.lang.Object createSurfaceTileDrawContext(SurfaceObjectTileBuilder.SurfaceObjectTile tile)
tile
- The tile to create a context for.protected SurfaceObjectTileBuilder.SurfaceObjectTile createTile(Sector sector, Level level, int row, int column, java.lang.String cacheName)
sector
, level
, row
, column
, and cacheName
.sector
- The tile's Sector.level
- The tile's Level in a LevelSet
.row
- The tile's row in the Level, starting from 0 and increasing to the right.column
- The tile's column in the Level, starting from 0 and increasing upward.cacheName
- Tile tile's cache name.protected SurfaceObjectTileBuilder.TileInfo createTileInfo(DrawContext dc)
dc
- the draw context to create the tile info for.protected SurfaceObjectTileBuilder.TileInfoKey createTileInfoKey(DrawContext dc)
In practices, there are at most 10 dimensions we'll use (512, 256, 128, 64, 32, 16, 8, 4, 2, 1) and 3 globe offsets (-1, 0, 1). Therefore there are at most 30 sets of tile information for each instance of SurfaceObjectTileBuilder.
dc
- the draw context to create the tile info key for.protected java.lang.Object createTileKey(Level level, int row, int column, java.lang.String cacheName)
level
, row
, column
,
and cacheName
.level
- The tile's Level in a LevelSet
.row
- The tile's row in the Level, starting from 0 and increasing to the right.column
- The tile's column in the Level, starting from 0 and increasing upward.cacheName
- Tile tile's cache name.protected com.jogamp.opengl.util.texture.Texture createTileTexture(DrawContext dc, int width, int height)
The returned texture's internal format is specified by tilePixelFormat
. If
tilePixelFormat
is zero, this returns a texture with internal format GL_RGBA8
.
The returned texture's parameters are configured as follows:
Parameter Name | Value |
---|---|
GL.GL_TEXTURE_MIN_FILTER | GL_LINEAR_MIPMAP_LINEAR
if useLinearFilter and useMipmaps are both true, GL_LINEAR if
useLinearFilter is true and useMipmaps is false, and GL_NEAREST if
useLinearFilter is false. |
GL.GL_TEXTURE_MAG_FILTER | GL_LINEAR
if useLinearFilter is true, GL_NEAREST if useLinearFilter is
false. |
GL.GL_TEXTURE_WRAP_S | GL_CLAMP_TO_EDGE |
GL.GL_TEXTURE_WRAP_T | GL_CLAMP_TO_EDGE |
dc
- the draw context to create a texture for.width
- the texture's width, in pixels.height
- the texture's height, in pixels.protected LevelSet getLevelSet(int tileWidth, int tileHeight)
LevelSet
for the specified tileDimension
. All instances of
SurfaceObjectTileBuilder
share common LevelSets to determine which tiles are visible, but create
unique tile instances and uses a unique tile cache name. Since all instances use the same tile structure to
determine visible tiles, this saves memory while ensuring that each instance stores its own tiles in the cache.
The returned LevelSet's cache name and dataset name are dummy values, and should not be used. Use this tile
builder's cache name for the specified tileDimension
instead.
In practice, there are at most 10 dimensions we use: 512, 256, 128, 64, 32, 16, 8, 4, 2, 1. Therefore keeping the
LevelSet
s in a map requires little memory overhead, and ensures each LevelSet
is
retained once constructed. Retaining references to the LevelSet
s means we're able to re-use the
texture resources associated with each LevelSet
in the DrawContext
's texture cache.
Subsequent calls are guaranteed to return the same LevelSet
for the same
tileDimension
.
tileWidth
- the tile width, in pixels.tileHeight
- the tile height, in pixels.public java.util.Collection<PickedObject> getPickCandidates(DrawContext dc)
buildTiles(DrawContext, Iterable)
.dc
- the draw context used to build tiles.java.lang.IllegalArgumentException
- if the draw context is null.public double getSplitScale()
setSplitScale(double)
public int getTileCount(DrawContext dc)
buildTiles(DrawContext, Iterable)
.dc
- the draw context used to build tiles.java.lang.IllegalArgumentException
- if the draw context is null.public java.awt.Dimension getTileDimension()
public java.util.Collection<? extends SurfaceTile> getTiles(DrawContext dc)
buildTiles(DrawContext, Iterable)
.dc
- the draw context used to build tiles.java.lang.IllegalArgumentException
- if the draw context is null.public int getTileTextureFormat()
setTileTextureFormat(int)
protected boolean intersectsFrustum(DrawContext dc, TextureTile tile)
dc
- the draw context the surface renderable is related to.tile
- the tile to test for intersection.protected boolean intersectsVisibleSector(DrawContext dc, TextureTile tile)
dc
- the current draw context.tile
- the tile to test for intersection.public boolean isForceTileUpdates()
buildTiles(DrawContext, Iterable)
.
When true, tile textures always update their contents with the current surface renderables. When false, tile
textures only update their contents when the surface renderables change. Initially false.public boolean isUseLinearFilter()
public boolean isUseMipmaps()
protected boolean meetsRenderCriteria(DrawContext dc, LevelSet levelSet, Tile tile)
dc
- the current draw context.levelSet
- the level set the tile belongs to.tile
- the tile to test.protected boolean needToSplit(DrawContext dc, Tile tile)
View
attached to the draw context.dc
- the current draw context.tile
- the tile to test.public void setForceTileUpdates(boolean forceTileUpdates)
buildTiles(DrawContext, Iterable)
.
When true, tile textures always update their contents with the current surface renderables. When false, tile
textures only update their contents when the surface renderables change.forceTileUpdates
- true if tile textures should always update their contents, false if tile textures should
only update when the surface renderables change.public void setSplitScale(double splitScale)
splitScale
- a value near 1.0 that controls the tile's surface texel resolution as the distance between the
globe's surface and the eye point change. Increasing values select higher resolution,
decreasing values select lower resolution. The default value is 2.9.public void setTileDimension(java.awt.Dimension dimension)
dimension
- the surface tile dimension, in pixels.java.lang.IllegalArgumentException
- if the dimension is null.public void setTileTextureFormat(int textureFormat)
If the texture format is any of GL_RGB, GL_RGB8, GL_RGBA, or GL_RGBA8
, the tile builder attempts to
use OpenGL framebuffer objects to render shapes to the texture tiles. Otherwise, this renders shapes to the
framebuffer and copies the framebuffer contents to the texture tiles.
textureFormat
- the OpenGL texture format, or 0 to use the default format.public void setUseLinearFilter(boolean useLinearFilter)
useLinearFilter
- true to use linear filtering; false to use nearest-neighbor filtering.public void setUseMipmaps(boolean useMipmaps)
useMipmaps
- true to generate mip-maps; false otherwise.protected java.lang.String uniqueCacheName()
protected void updateTile(DrawContext dc, SurfaceObjectTileBuilder.SurfaceObjectTile tile)
dc
- the draw context the tile relates to.tile
- the tile to update.protected void updateTiles(DrawContext dc)
SurfaceObjectTileBuilder.SurfaceObjectTile
in the currentInfo
. This is typically
called after assembleTiles(DrawContext)
to update the assembled tiles.
This method does nothing if currentTiles
is empty.
dc
- the draw context the tiles relate to.