Provides input and output facilities for both loading OpenGL textures from disk and streams as well as writing textures already in memory back to disk.
The TextureIO class supports an arbitrary number of plug-in readers and writers via TextureProviders and TextureWriters. TextureProviders know how to produce TextureData objects from files, InputStreams and URLs. TextureWriters know how to write TextureData objects to disk in various file formats. The TextureData class represents the raw data of the texture before it has been converted to an OpenGL texture object. The Texture class represents the OpenGL texture object and provides easy facilities for using the texture.
There are several built-in TextureProviders and TextureWriters supplied with the TextureIO implementation. The most basic provider uses the platform's Image I/O facilities to read in a BufferedImage and convert it to a texture. This is the baseline provider and is registered so that it is the last one consulted. All others are asked first to open a given file.
There are three other providers registered by default as of the time of this writing. One handles SGI RGB (".sgi", ".rgb") images from both files and streams. One handles DirectDraw Surface (".dds") images read from files, though can not read these images from streams. One handles Targa (".tga") images read from both files and streams. These providers are executed in an arbitrary order. Some of these providers require the file's suffix to either be specified via the newTextureData methods or for the file to be named with the appropriate suffix. In general a file suffix should be provided to the newTexture and newTextureData methods if at all possible.
Note that additional TextureProviders, if reading images from InputStreams, must use the mark()/reset() methods on InputStream when probing for e.g. magic numbers at the head of the file to make sure not to disturb the state of the InputStream for downstream TextureProviders.
There are analogous TextureWriters provided for writing textures back to disk if desired. As of this writing, there are four TextureWriters registered by default: one for Targa files, one for SGI RGB files, one for DirectDraw surface (.dds) files, and one for ImageIO-supplied formats such as .jpg and .png. Some of these writers have certain limitations such as only being able to write out textures stored in GL_RGB or GL_RGBA format. The DDS writer supports fetching and writing to disk of texture data in DXTn compressed format. Whether this will occur is dependent on whether the texture's internal format is one of the DXTn compressed formats and whether the target file is .dds format.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv abstract static class | |
| pack-priv static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| public static final String | DDS
Constant which can be used as a file suffix to indicate a DirectDraw Surface file, value . |
| private static final boolean | |
| public static final String | GIF
Constant which can be used as a file suffix to indicate a GIF file, value . |
| private static Map | |
| public static final String | JPG
Constant which can be used as a file suffix to indicate a JPEG file, value . |
| public static final String | PAM
Constant which can be used as a file suffix to indicate a PAM file, NetPbm magic 7 - binary RGB and RGBA. |
| public static final String | PNG
Constant which can be used as a file suffix to indicate a PNG file, value . |
| public static final String | PPM
Constant which can be used as a file suffix to indicate a PAM file, NetPbm magic 6 - binary RGB. |
| public static final String | SGI
Constant which can be used as a file suffix to indicate an SGI RGB file, value . |
| public static final String | SGI_RGB
Constant which can be used as a file suffix to indicate an SGI RGB file, value . |
| private static boolean | |
| private static List | |
| private static List | |
| public static final String | TGA
Constant which can be used as a file suffix to indicate a Targa file, value . |
| public static final String | TIFF
Constant which can be used as a file suffix to indicate a TIFF file, value . |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static void | addTextureProvider(final TextureProvider provider)
Adds a |
| public static void | addTextureWriter(final TextureWriter writer)
Adds a TextureWriter to support writing of a new file format. |
| private static int | |
| public static boolean | isTexRectEnabled()
Indicates whether the GL_ARB_texture_rectangle extension is
allowed to be used for non-power-of-two textures; see |
| public static Texture | newTexture(final TextureData
the texture data to turn into an OpenGL texture data)Creates an OpenGL texture object from the specified TextureData using the current OpenGL context. |
| public static Texture | newTexture(final GL gl, final TextureData
the texture data to turn into an OpenGL texture data)Creates an OpenGL texture object from the specified TextureData using the given OpenGL context. |
| public static Texture | newTexture(final File
the file from which to read the texture data file, final boolean whether mipmaps should be produced for this
texture either by autogenerating them or
reading them from the file. Some file formats
support multiple mipmaps in a single file in
which case those mipmaps will be used rather
than generating them. mipmap)Creates an OpenGL texture object from the specified file using the current OpenGL context. |
| public static Texture | newTexture(final InputStream
the stream from which to read the texture data stream, final boolean whether mipmaps should be produced for this
texture either by autogenerating them or
reading them from the file. Some file formats
support multiple mipmaps in a single file in
which case those mipmaps will be used rather
than generating them. mipmap, final String the suffix of the file name to be used as a
hint of the file format to the underlying
texture provider, or null if none and should be
auto-detected (some texture providers do not
support this) fileSuffix)Creates an OpenGL texture object from the specified stream using the current OpenGL context. |
| public static Texture | newTexture(final URL
the URL from which to read the texture data url, final boolean whether mipmaps should be produced for this
texture either by autogenerating them or
reading them from the file. Some file formats
support multiple mipmaps in a single file in
which case those mipmaps will be used rather
than generating them. mipmap, String the suffix of the file name to be used as a
hint of the file format to the underlying
texture provider, or null if none and should be
auto-detected (some texture providers do not
support this) fileSuffix)Creates an OpenGL texture object from the specified URL using the current OpenGL context. |
| public static Texture | newTexture(final int
the OpenGL target type, eg GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_RECTANGLE_ARB target)Creates an OpenGL texture object associated with the given OpenGL texture target. |
| public static TextureData | Returns: the texture data from the file, or null if none of the registered texture providers could read the filethe OpenGL Profile this texture data should be
created for. glp, final File the file from which to read the texture data file, final boolean whether mipmaps should be produced for this
texture either by autogenerating them or
reading them from the file. Some file formats
support multiple mipmaps in a single file in
which case those mipmaps will be used rather
than generating them. mipmap, String the suffix of the file name to be used as a
hint of the file format to the underlying
texture provider, or null if none and should be
auto-detected (some texture providers do not
support this) fileSuffix)Creates a TextureData from the given file. |
| public static TextureData | Returns: the texture data from the stream, or null if none of the registered texture providers could read the streamthe OpenGL Profile this texture data should be
created for. glp, final InputStream the stream from which to read the texture data stream, final boolean whether mipmaps should be produced for this
texture either by autogenerating them or
reading them from the file. Some file formats
support multiple mipmaps in a single file in
which case those mipmaps will be used rather
than generating them. mipmap, final String the suffix of the file name to be used as a
hint of the file format to the underlying
texture provider, or null if none and should be
auto-detected (some texture providers do not
support this) fileSuffix)Creates a TextureData from the given stream. |
| public static TextureData | Returns: the texture data from the URL, or null if none of the registered texture providers could read the URLthe OpenGL Profile this texture data should be
created for. glp, final URL the URL from which to read the texture data url, final boolean whether mipmaps should be produced for this
texture either by autogenerating them or
reading them from the file. Some file formats
support multiple mipmaps in a single file in
which case those mipmaps will be used rather
than generating them. mipmap, String the suffix of the file name to be used as a
hint of the file format to the underlying
texture provider, or null if none and should be
auto-detected (some texture providers do not
support this) fileSuffix)Creates a TextureData from the given URL. |
| public static TextureData | Returns: the texture data from the file, or null if none of the registered texture providers could read the filethe OpenGL Profile this texture data should be
created for. glp, final File the file from which to read the texture data file, final int the OpenGL internal format of the texture
which will eventually result from the TextureData internalFormat, final int the OpenGL pixel format of the texture
which will eventually result from the TextureData pixelFormat, final boolean whether mipmaps should be produced for this
texture either by autogenerating them or
reading them from the file. Some file formats
support multiple mipmaps in a single file in
which case those mipmaps will be used rather
than generating them. mipmap, String the suffix of the file name to be used as a
hint of the file format to the underlying
texture provider, or null if none and should be
auto-detected (some texture providers do not
support this) fileSuffix)Creates a TextureData from the given file, using the specified OpenGL internal format and pixel format for the texture which will eventually result. |
| public static TextureData | Returns: the texture data from the stream, or null if none of the registered texture providers could read the streamthe OpenGL Profile this texture data should be
created for. glp, final InputStream the stream from which to read the texture data stream, final int the OpenGL internal format of the texture
which will eventually result from the TextureData internalFormat, final int the OpenGL pixel format of the texture
which will eventually result from the TextureData pixelFormat, final boolean whether mipmaps should be produced for this
texture either by autogenerating them or
reading them from the file. Some file formats
support multiple mipmaps in a single file in
which case those mipmaps will be used rather
than generating them. mipmap, final String the suffix of the file name to be used as a
hint of the file format to the underlying
texture provider, or null if none and should be
auto-detected (some texture providers do not
support this) fileSuffix)Creates a TextureData from the given stream, using the specified OpenGL internal format and pixel format for the texture which will eventually result. |
| public static TextureData | Returns: the texture data from the URL, or null if none of the registered texture providers could read the URLthe OpenGL Profile this texture data should be
created for. glp, final URL the URL from which to read the texture data url, final int the OpenGL internal format of the texture
which will eventually result from the TextureData internalFormat, final int the OpenGL pixel format of the texture
which will eventually result from the TextureData pixelFormat, final boolean whether mipmaps should be produced for this
texture either by autogenerating them or
reading them from the file. Some file formats
support multiple mipmaps in a single file in
which case those mipmaps will be used rather
than generating them. mipmap, String the suffix of the file name to be used as a
hint of the file format to the underlying
texture provider, or null if none and should be
auto-detected (some texture providers do not
support this) fileSuffix)Creates a TextureData from the given URL, using the specified OpenGL internal format and pixel format for the texture which will eventually result. |
| private static TextureData | newTextureDataImpl(final GLProfile glp, InputStream stream, final int internalFormat, final int pixelFormat, final boolean mipmap, String fileSuffix)
|
| private static TextureData | newTextureDataImpl(final GLProfile glp, final File file, final int internalFormat, final int pixelFormat, final boolean mipmap, final String fileSuffix)
|
| private static TextureData | newTextureDataImpl(final GLProfile glp, final URL url, final int internalFormat, final int pixelFormat, final boolean mipmap, final String fileSuffix)
|
| public static void | setTexRectEnabled(final boolean enabled)
Toggles the use of the GL_ARB_texture_rectangle extension by the TextureIO classes. |
| private static String | |
| public static void | |
| public static void |