Class TextureAtlas
- java.lang.Object
-
- com.metsci.glimpse.core.support.atlas.TextureAtlas
-
public class TextureAtlas extends Object
Stores a large number of images or icons which are packed into a single OpenGL texture. This allows VBO draw methods like glDrawArrays to be used to draw thousands of images from the TextureAtlas simultaneously.- Author:
- ulman
-
-
Constructor Summary
Constructors Constructor Description TextureAtlas()Constructs a new TextureAtlas with default initial width and height, with smoothing enabled.TextureAtlas(int initialWidth, int initialHeight)Constructs a new TextureAtlas with the provided initial width and height in pixels, with smoothing enabled.TextureAtlas(int initialWidth, int initialHeight, boolean smoothing)Constructs a new TextureAtlas with the provided initial width and height in pixels.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(TextureAtlasUpdateListener listener)Registers a TextureAtlasUpdateListener with the TextureAtlas.voidbeginRendering(GlimpseContext context)voidbeginRendering(GlimpseContext context, float xMin, float xMax, float yMin, float yMax)voidbeginRenderingAxisOrtho(GlimpseContext context)voidbeginRenderingAxisOrtho(GlimpseContext context, Axis2D axis)voidbeginRenderingPixelOrtho(GlimpseContext context)voidbeginRenderingPixelOrtho(GlimpseContext context, GlimpseBounds bounds)voiddeleteImage(Object id)Removes an image from the TextureAtlas based on its unique identifier (which is often a String).voiddispose()Disposes of the OpenGL resources associated with this TextureAtlas.voiddrawImage(GlimpseContext context, double ppvX, double ppvY, ImageDataInternal data, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY)voiddrawImage(GlimpseContext context, Object id, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY, float[] rgba)voiddrawImage(GlimpseContext context, Object id, int positionX, int positionY)voiddrawImage(GlimpseContext context, Object id, int positionX, int positionY, double scaleX, double scaleY)voiddrawImage(GlimpseContext context, Object id, int positionX, int positionY, double scaleX, double scaleY, double centerX, double centerY)voiddrawImage(GlimpseContext context, Object id, Axis2D axis, double positionX, double positionY)voiddrawImage(GlimpseContext context, Object id, Axis2D axis, double positionX, double positionY, double scale)voiddrawImage(GlimpseContext context, Object id, Axis2D axis, double positionX, double positionY, double scaleX, double scaleY)voiddrawImage(GlimpseContext context, Object id, Axis2D axis, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY)Draws an image from the TextureAtlas using the given GL handle.voiddrawImage(GlimpseContext context, Object id, Axis2D axis, double positionX, double positionY, double scaleX, double scaleY, float[] rgba)voiddrawImageAxisX(GlimpseContext context, Object id, Axis1D axis, double positionX, double positionY)voiddrawImageAxisX(GlimpseContext context, Object id, Axis1D axis, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY)Draws an image from the TextureAtlas with the x position specified in axis space and the y position specified in pixel space.voiddrawImageAxisX(GlimpseContext context, Object id, Axis1D axis, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY, float[] rgba)voiddrawImageAxisY(GlimpseContext context, Object id, Axis1D axis, double positionX, double positionY)Draws an image from the TextureAtlas with the y position specified in axis space and the x position specified in pixel space.voiddrawImageAxisY(GlimpseContext context, Object id, Axis1D axis, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY)voiddrawImageAxisY(GlimpseContext context, Object id, Axis1D axis, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY, float[] rgba)voidendRendering(GlimpseContext context)Resets OpenGL state.ImageDatagetImageData(Object id)Returns information about an image in the TextureAtlas.booleanisImageLoaded(Object id)Verifies whether or not an image has been loaded into the TextureAtlas.voidloadImage(Object id, int width, int height, double centerX, double centerY, ImageDrawer drawer)Adds an image, defined by an arbitrary Java2D drawing routine, to the TextureAtlas.voidloadImage(Object id, int width, int height, ImageDrawer drawer)Adds an image, defined by an arbitrary Java2D drawing routine, to the TextureAtlas.voidloadImage(Object id, BufferedImage image)Adds an image, defined by a BufferedImage, to the TextureAtlas.voidloadImage(Object id, BufferedImage image, double centerX, double centerY)Adds an image, defined by a BufferedImage, to the TextureAtlas.voidremoveListener(TextureAtlasUpdateListener listener)
-
-
-
Constructor Detail
-
TextureAtlas
public TextureAtlas(int initialWidth, int initialHeight, boolean smoothing)Constructs a new TextureAtlas with the provided initial width and height in pixels. The TextureAtlas will grow in height automatically as needed, up to the maximum texture size supported by the graphics hardware. Note: the TextureAtlas will not currently grow in width. If the smoothing parameter is true, rendered pixel colors will be interpolated among adjacent texels. Otherwise, pixel colors will be assigned from the nearest texel.- Parameters:
initalWidth-initialHeight-smoothing-
-
TextureAtlas
public TextureAtlas(int initialWidth, int initialHeight)Constructs a new TextureAtlas with the provided initial width and height in pixels, with smoothing enabled.- See Also:
TextureAtlas( int, int, boolean )
-
TextureAtlas
public TextureAtlas()
Constructs a new TextureAtlas with default initial width and height, with smoothing enabled.- See Also:
TextureAtlas( int, int, boolean )
-
-
Method Detail
-
addListener
public void addListener(TextureAtlasUpdateListener listener)
Registers a TextureAtlasUpdateListener with the TextureAtlas. This listener is notified when the TextureAtlas compacts itself. This compaction, done to make space in the TextureAtlas for additional images/icons, may cause images to change location within the atlas. This may require updates to external data structures storing texture coordinates that reference locations in the atlas.- Parameters:
listener-
-
removeListener
public void removeListener(TextureAtlasUpdateListener listener)
-
loadImage
public void loadImage(Object id, BufferedImage image, double centerX, double centerY)
Adds an image, defined by a BufferedImage, to the TextureAtlas. The icon id can be any object (most often a String) which uniquely identifies the image. When an icon is displayed at a fixed point in data/axis space, that point must be fixed to a specific pixel on the image. The centerX and centerY arguments specify this center pixel. A centerX/centerY of (0,0) indicates that the icon should be centered on the lower left pixel.- Parameters:
id- the unique identifier for the imageimage- a BufferedImage to be loaded into the texturecenterX- the center x pixel of the imagecenterY- the center y pixel of the image
-
loadImage
public void loadImage(Object id, BufferedImage image)
Adds an image, defined by a BufferedImage, to the TextureAtlas. The icon id can be any object (most often a String) which uniquely identifies the image.- Parameters:
id- the unique identifier for the imageimage- a BufferedImage to be loaded into the texture- See Also:
#loadImage( Object, BufferedImage, int, int )
-
loadImage
public void loadImage(Object id, int width, int height, ImageDrawer drawer)
Adds an image, defined by an arbitrary Java2D drawing routine, to the TextureAtlas. The width and height arguments define a canvas size, and the ImageDrawer defines a routine which will be used to draw icon graphics onto the canvas.- Parameters:
id- the unique identifier for the imagewidth- the width of the imageheight- the height of the imagedrawer- a Java2D drawing routine which defines the image
-
loadImage
public void loadImage(Object id, int width, int height, double centerX, double centerY, ImageDrawer drawer)
Adds an image, defined by an arbitrary Java2D drawing routine, to the TextureAtlas. The width and height arguments define a canvas size, and the ImageDrawer defines a routine which will be used to draw icon graphics onto the canvas.- Parameters:
id- the unique identifier for the imagewidth- the width of the imageheight- the height of the imagecenterX- the center x pixel of the imagecenterY- the center y pixel of the imagedrawer- a Java2D drawing routine which defines the image- See Also:
#loadImage( Object, int, int, int, int, ImageDrawer )
-
deleteImage
public void deleteImage(Object id)
Removes an image from the TextureAtlas based on its unique identifier (which is often a String). The space used by the image will be automatically reclaimed and available for other images.- Parameters:
id- the unique identifier for the image to be deleted
-
isImageLoaded
public boolean isImageLoaded(Object id)
Verifies whether or not an image has been loaded into the TextureAtlas. An image is not available immediately after loadImage( ) has been called. At least one interveningTextureAtlas#beginRendering( )must have been made beforegetImageData( Object )will return data for the image.- Parameters:
id- the unique identifier for the image- Returns:
- true if the image has been loaded into the atlas
-
getImageData
public ImageData getImageData(Object id)
Returns information about an image in the TextureAtlas. This information includes texture coordinates, which can be used to manually draw icons from the atlas. This information can also be used by external painters likeIconPainterwhich are backed by a TextureAtlas.- Parameters:
id- the unique identifier for the image- Returns:
- a ImageData handle with size and texture coordinate information about the image
-
drawImage
public void drawImage(GlimpseContext context, Object id, Axis2D axis, double positionX, double positionY)
- See Also:
#drawImage( GL, Object, Axis2D, float, float, float, float, int, int )
-
drawImage
public void drawImage(GlimpseContext context, Object id, Axis2D axis, double positionX, double positionY, double scale)
- See Also:
#drawImage( GL, Object, Axis2D, float, float, float, float, int, int )
-
drawImage
public void drawImage(GlimpseContext context, Object id, Axis2D axis, double positionX, double positionY, double scaleX, double scaleY)
- See Also:
#drawImage( GL, Object, Axis2D, float, float, float, float, int, int )
-
drawImage
public void drawImage(GlimpseContext context, Object id, Axis2D axis, double positionX, double positionY, double scaleX, double scaleY, float[] rgba)
-
drawImage
public void drawImage(GlimpseContext context, Object id, Axis2D axis, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY)
Draws an image from the TextureAtlas using the given GL handle. The icon is centered on the provided positionX, positionY in axis space. Note: this OpenGL immediate-mode icon drawing directly from the TextureAtlas is provided as a convenience, but is slow and inefficient when drawing many icons (thousands or more). For those cases, seeIconPainter. For even more specific use cases, custom painters may be required.- Parameters:
gl- handle from the current OpenGL contextid- an icon loaded into the atlas using a loadImage() methodaxis-positionX- the x position in axis space of the center pixel in the imagepositionY- the y position in axis space of the center pixel in the imagescaleX- the scale factor in the x directionscaleY- the scale factor in the y directionoffsetX- overrides the image x offset specified when the image was loadedoffsetY- overrides the image y offset specified when the image was loaded
-
drawImageAxisX
public void drawImageAxisX(GlimpseContext context, Object id, Axis1D axis, double positionX, double positionY)
- See Also:
#drawImageAxisX( GL, Object, Axis1D, float, float, float, float, int, int )
-
drawImageAxisX
public void drawImageAxisX(GlimpseContext context, Object id, Axis1D axis, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY)
Draws an image from the TextureAtlas with the x position specified in axis space and the y position specified in pixel space. This is most often used by acom.metsci.glimpse.painter.base.GlimpseDataPainter1Dto paint onto aGlimpseAxisLayoutX.- Parameters:
gl- handle from the current OpenGL contextid- an icon loaded into the atlas using a loadImage() methodaxis- the 1D horizontal axispositionX- the x position along the axis of the image centerpositionY- the y position in pixel space of the image centerscaleX- the scale factor in the x directionscaleY- the scale factor in the y directionoffsetX- overrides the image x offset specified when the image was loadedoffsetY- overrides the image y offset specified when the image was loaded
-
drawImageAxisX
public void drawImageAxisX(GlimpseContext context, Object id, Axis1D axis, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY, float[] rgba)
-
drawImageAxisY
public void drawImageAxisY(GlimpseContext context, Object id, Axis1D axis, double positionX, double positionY)
Draws an image from the TextureAtlas with the y position specified in axis space and the x position specified in pixel space. This is most often used by acom.metsci.glimpse.painter.base.GlimpseDataPainter1Dto paint onto aGlimpseAxisLayoutY.- See Also:
#drawImageAxisX( GL, Object, Axis1D, float, float, float, float, int, int )
-
drawImage
public void drawImage(GlimpseContext context, Object id, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY, float[] rgba)
-
drawImageAxisY
public void drawImageAxisY(GlimpseContext context, Object id, Axis1D axis, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY)
- See Also:
#drawImageAxisX( GL, Object, Axis1D, float, float, float, float, int, int )
-
drawImageAxisY
public void drawImageAxisY(GlimpseContext context, Object id, Axis1D axis, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY, float[] rgba)
-
drawImage
public void drawImage(GlimpseContext context, Object id, int positionX, int positionY, double scaleX, double scaleY, double centerX, double centerY)
-
drawImage
public void drawImage(GlimpseContext context, Object id, int positionX, int positionY, double scaleX, double scaleY)
-
drawImage
public void drawImage(GlimpseContext context, Object id, int positionX, int positionY)
-
drawImage
public void drawImage(GlimpseContext context, double ppvX, double ppvY, ImageDataInternal data, double positionX, double positionY, double scaleX, double scaleY, double centerX, double centerY)
-
beginRenderingAxisOrtho
public void beginRenderingAxisOrtho(GlimpseContext context) throws com.jogamp.opengl.GLException
- Throws:
com.jogamp.opengl.GLException
-
beginRenderingAxisOrtho
public void beginRenderingAxisOrtho(GlimpseContext context, Axis2D axis) throws com.jogamp.opengl.GLException
- Throws:
com.jogamp.opengl.GLException
-
beginRenderingPixelOrtho
public void beginRenderingPixelOrtho(GlimpseContext context) throws com.jogamp.opengl.GLException
- Throws:
com.jogamp.opengl.GLException
-
beginRenderingPixelOrtho
public void beginRenderingPixelOrtho(GlimpseContext context, GlimpseBounds bounds) throws com.jogamp.opengl.GLException
- Throws:
com.jogamp.opengl.GLException
-
beginRendering
public void beginRendering(GlimpseContext context, float xMin, float xMax, float yMin, float yMax) throws com.jogamp.opengl.GLException
- Throws:
com.jogamp.opengl.GLException
-
beginRendering
public void beginRendering(GlimpseContext context) throws com.jogamp.opengl.GLException
- Throws:
com.jogamp.opengl.GLException
-
endRendering
public void endRendering(GlimpseContext context) throws com.jogamp.opengl.GLException
Resets OpenGL state. Every call to should be followed by a call to {endRendering()}.- Throws:
com.jogamp.opengl.GLException- See Also:
com.sun.opengl.util.j2d.TextRenderer#end3DRendering( )
-
dispose
public void dispose() throws com.jogamp.opengl.GLExceptionDisposes of the OpenGL resources associated with this TextureAtlas.- Throws:
com.jogamp.opengl.GLException- See Also:
com.sun.opengl.util.j2d.TextRenderer#disposeAttached( )
-
-