Package playn.core

Class Texture

All Implemented Interfaces:
AutoCloseable, Closeable

public class Texture extends Tile implements Closeable
A handle to an OpenGL texture. A texture is also a Tile which contains the entire texture, which allows rendering methods to operate uniformly on tiles.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    Used to configure texture at creation time.

    Nested classes/interfaces inherited from interface react.Closeable

    Closeable.Set, Closeable.Util
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    This texture's configuration.
    final float
    The height of this texture in display units.
    final float
    The width of this texture in display units.
    final int
    The GL texture handle.
    final int
    The height of this texture in pixels.
    final int
    The width of this texture in pixels.
    final Scale
    The scale factor used by this texture.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Texture(Graphics gfx, int id, Texture.Config config, int pixWidth, int pixHeight, Scale scale, float dispWidth, float dispHeight)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addToBatch(QuadBatch batch, int tint, AffineTransform tx, float x, float y, float width, float height)
    Adds this tile to the supplied quad batch.
    void
    addToBatch(QuadBatch batch, int tint, AffineTransform tx, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh)
    Adds this tile to the supplied quad batch.
    void
    Deletes this texture's GPU resources and renders it unusable.
    boolean
    Returns whether this texture is been disposed.
    Returns a Slot that will dispose this texture when triggered.
    float
    The height of this tile (in display units).
    static int
    nextPOT(int value)
    Returns next largest power of two, or value if value is already a POT.
    void
    Increments this texture's reference count.
    void
    Decrements this texture's reference count.
    float
    sx()
    Returns the s texture coordinate for the x-axis.
    float
    sy()
    Returns the s texture coordinate for the y-axis.
    The texture which contains this tile.
    tile(float x, float y, float width, float height)
    Returns an instance that can be used to render a sub-region of this texture.
    tile(IRectangle region)
    Returns an instance that can be used to render a sub-region of this texture.
     
    float
    tx()
    Returns the t texture coordinate for the x-axis.
    float
    ty()
    Returns the t texture coordinate for the y-axis.
    void
    update(Image image)
    Uploads image to this texture's GPU memory.
    float
    The width of this tile (in display units).

    Methods inherited from class playn.core.Tile

    isLoaded, tile, tileAsync

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • id

      public final int id
      The GL texture handle.
    • config

      public final Texture.Config config
      This texture's configuration.
    • pixelWidth

      public final int pixelWidth
      The width of this texture in pixels.
    • pixelHeight

      public final int pixelHeight
      The height of this texture in pixels.
    • scale

      public final Scale scale
      The scale factor used by this texture.
    • displayWidth

      public final float displayWidth
      The width of this texture in display units.
    • displayHeight

      public final float displayHeight
      The height of this texture in display units.
  • Constructor Details

    • Texture

      public Texture(Graphics gfx, int id, Texture.Config config, int pixWidth, int pixHeight, Scale scale, float dispWidth, float dispHeight)
  • Method Details

    • nextPOT

      public static int nextPOT(int value)
      Returns next largest power of two, or value if value is already a POT. Note: this is limited to values less than 0x10000.
    • reference

      public void reference()
      Increments this texture's reference count. NOOP unless Texture.Config.managed.
    • release

      public void release()
      Decrements this texture's reference count. If the reference count of a managed texture goes to zero, the texture is disposed (and is no longer usable).
    • update

      public void update(Image image)
      Uploads image to this texture's GPU memory. image must have the exact same size as this texture and must be fully loaded. This is generally useful for updating a texture which was created from a canvas when the canvas has been changed.
    • tile

      public Tile tile(IRectangle region)
      Returns an instance that can be used to render a sub-region of this texture.
    • tile

      public Tile tile(float x, float y, float width, float height)
      Returns an instance that can be used to render a sub-region of this texture.
    • disposed

      public boolean disposed()
      Returns whether this texture is been disposed.
    • disposeSlot

      public UnitSlot disposeSlot()
      Returns a Slot that will dispose this texture when triggered.

      This is useful when you want to manually bind the lifecycle of an unmanaged texture to the lifecycle of a layer. Simply `layer.onDisposed(texture.disposeSlot())`.

    • texture

      public Texture texture()
      Description copied from class: Tile
      The texture which contains this tile.
      Specified by:
      texture in class Tile
    • width

      public float width()
      Description copied from class: Tile
      The width of this tile (in display units).
      Specified by:
      width in class Tile
    • height

      public float height()
      Description copied from class: Tile
      The height of this tile (in display units).
      Specified by:
      height in class Tile
    • sx

      public float sx()
      Description copied from class: Tile
      Returns the s texture coordinate for the x-axis.
      Specified by:
      sx in class Tile
    • sy

      public float sy()
      Description copied from class: Tile
      Returns the s texture coordinate for the y-axis.
      Specified by:
      sy in class Tile
    • tx

      public float tx()
      Description copied from class: Tile
      Returns the t texture coordinate for the x-axis.
      Specified by:
      tx in class Tile
    • ty

      public float ty()
      Description copied from class: Tile
      Returns the t texture coordinate for the y-axis.
      Specified by:
      ty in class Tile
    • addToBatch

      public void addToBatch(QuadBatch batch, int tint, AffineTransform tx, float x, float y, float width, float height)
      Description copied from class: Tile
      Adds this tile to the supplied quad batch.
      Specified by:
      addToBatch in class Tile
    • addToBatch

      public void addToBatch(QuadBatch batch, int tint, AffineTransform tx, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh)
      Description copied from class: Tile
      Adds this tile to the supplied quad batch.
      Specified by:
      addToBatch in class Tile
    • close

      public void close()
      Deletes this texture's GPU resources and renders it unusable.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • toString

      public String toString()
      Overrides:
      toString in class Tile