Class TextureUtils

java.lang.Object
com.blackrook.gloop.opengl.util.TextureUtils

public final class TextureUtils extends Object
Texture utility class.

All of these methods can be called outside of the graphics thread.

Author:
Matthew Tropiano
  • Constructor Details

    • TextureUtils

      public TextureUtils()
  • Method Details

    • closestPowerOfTwo

      public static int closestPowerOfTwo(int x)
      Finds the closest power of two to an integer value, larger than the initial value.

      Examples:

      • If x is 19, this returns 32.
      • If x is 4, this returns 4.
      • If x is 99, this returns 128.
      • If x is 129, this returns 256.
      Parameters:
      x - the input value.
      Returns:
      the closest power of two.
    • isPowerOfTwo

      public static boolean isPowerOfTwo(int x)
      Checks if an integer is a valid power of two.
      Parameters:
      x - the input value.
      Returns:
      true if it is, false if not.
    • hasPowerOfTwoDimensions

      public static boolean hasPowerOfTwoDimensions(BufferedImage image)
      Checks if a texture has power-of-two dimensions.
      Parameters:
      image - the image to check.
      Returns:
      true if so, false if not.
    • getRawSize

      public static int getRawSize(BufferedImage image)
      Returns the raw size in bytes that this image will need for byte buffer/array storage.
      Parameters:
      image - the image to inspect.
      Returns:
      the size in pixels for the image.
    • getBGRAByteData

      public static ByteBuffer getBGRAByteData(BufferedImage image)
      Gets the byte data for a texture in BGRA color information per pixel.
      Parameters:
      image - the input image.
      Returns:
      a new direct ByteBuffer of the image's byte data.
    • getBGRAByteData

      public static ByteBuffer getBGRAByteData(BufferedImage... image)
      Gets the byte data for a contiguous series of textures in BGRA color information per pixel. Works best if all of the textures are the same size.
      Parameters:
      image - the image list.
      Returns:
      a new direct ByteBuffer of the image's byte data.
    • getARGBByteData

      public static ByteBuffer getARGBByteData(BufferedImage image)
      Gets the byte data for a texture in ARGB color information per pixel.
      Parameters:
      image - the input image.
      Returns:
      a new direct ByteBuffer of the image's byte data.
    • getARGBByteData

      public static ByteBuffer getARGBByteData(BufferedImage... image)
      Gets the byte data for a contiguous series of textures in ARGB color information per pixel. Works best if all of the textures are the same size.
      Parameters:
      image - the image list.
      Returns:
      a new direct ByteBuffer of the image's byte data.
    • getRGBAByteData

      public static ByteBuffer getRGBAByteData(BufferedImage image)
      Gets the byte data for a texture in ARGB color information per pixel.
      Parameters:
      image - the input image.
      Returns:
      a new direct ByteBuffer of the image's byte data.
    • getRGBAByteData

      public static ByteBuffer getRGBAByteData(BufferedImage... image)
      Gets the byte data for a texture in ARGB color information per pixel.
      Parameters:
      image - the input image.
      Returns:
      a new direct ByteBuffer of the image's byte data.
    • setImageData

      public static BufferedImage setImageData(ByteBuffer imageBGRAData, int width, int height)
      Converts color byte data to a BufferedImage.
      Parameters:
      imageBGRAData - the input BGRA byte data.
      width - the width of the resultant image.
      height - the height of the resultant image.
      Returns:
      a new direct ByteBuffer of the image's byte data.