Class 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 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 -
      • 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 image
        image - a BufferedImage to be loaded into the texture
        centerX - the center x pixel of the image
        centerY - 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 image
        image - 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 image
        width - the width of the image
        height - the height of the image
        drawer - 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 image
        width - the width of the image
        height - the height of the image
        centerX - the center x pixel of the image
        centerY - the center y pixel of the image
        drawer - 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 intervening TextureAtlas#beginRendering( ) must have been made before getImageData( 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 like IconPainter which 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, see IconPainter. For even more specific use cases, custom painters may be required.
        Parameters:
        gl - handle from the current OpenGL context
        id - an icon loaded into the atlas using a loadImage() method
        axis -
        positionX - the x position in axis space of the center pixel in the image
        positionY - the y position in axis space of the center pixel in the image
        scaleX - the scale factor in the x direction
        scaleY - the scale factor in the y direction
        offsetX - overrides the image x offset specified when the image was loaded
        offsetY - 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 a com.metsci.glimpse.painter.base.GlimpseDataPainter1D to paint onto a GlimpseAxisLayoutX.
        Parameters:
        gl - handle from the current OpenGL context
        id - an icon loaded into the atlas using a loadImage() method
        axis - the 1D horizontal axis
        positionX - the x position along the axis of the image center
        positionY - the y position in pixel space of the image center
        scaleX - the scale factor in the x direction
        scaleY - the scale factor in the y direction
        offsetX - overrides the image x offset specified when the image was loaded
        offsetY - 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 a com.metsci.glimpse.painter.base.GlimpseDataPainter1D to paint onto a GlimpseAxisLayoutY.
        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.GLException
        Disposes of the OpenGL resources associated with this TextureAtlas.
        Throws:
        com.jogamp.opengl.GLException
        See Also:
        com.sun.opengl.util.j2d.TextRenderer#disposeAttached( )