APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.graphics

public Class Texture

extends GLTexture
Class Inheritance
Imports
java.util.HashMap, .Map, com.badlogic.gdx.Application, .Gdx, com.badlogic.gdx.assets.AssetLoaderParameters.LoadedCallback, .AssetManager, com.badlogic.gdx.assets.loaders.AssetLoader, .TextureLoader.TextureParameter, com.badlogic.gdx.files.FileHandle, com.badlogic.gdx.graphics.Pixmap.Format, com.badlogic.gdx.graphics.glutils.FileTextureData, .PixmapTextureData, com.badlogic.gdx.utils.Array, .GdxRuntimeException

A Texture wraps a standard OpenGL ES texture.

A Texture can be managed. If the OpenGL context is lost all managed textures get invalidated. This happens when a user switches to another application or receives an incoming call. Managed textures get reloaded automatically.

A Texture has to be bound via the Texture#bind() method in order for it to be applied to geometry. The texture will be bound to the currently active texture unit specified via GL20#glActiveTexture(int).

You can draw Pixmaps to a texture at any time. The changes will be automatically uploaded to texture memory. This is of course not extremely fast so use it with care. It also only works with unmanaged textures.

A Texture must be disposed when it is no longer used

Author
[email protected]

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
public static enum

Field Summary

Modifier and TypeField and Description
private static AssetManager
pack-priv TextureData
pack-priv static final Map<Application, Array<Texture>>
Inherited from com.badlogic.gdx.graphics.GLTexture:
anisotropicFilterLevelglHandleglTargetmagFilterminFilteruWrapvWrap

Constructor Summary

AccessConstructor and Description
protected
public
Texture(String internalPath)

public
public
Texture(FileHandle file, boolean useMipMaps)

public
Texture(FileHandle file, Pixmap.Format format, boolean useMipMaps)

public
Texture(Pixmap pixmap)

public
Texture(Pixmap pixmap, boolean useMipMaps)

public
Texture(Pixmap pixmap, Pixmap.Format format, boolean useMipMaps)

public
Texture(int width, int height, Pixmap.Format format)

public
protected
Texture(int glTarget, int glHandle, TextureData data)

Method Summary

Modifier and TypeMethod and Description
private static void
public static void
clearAllTextures(Application app)

Clears all managed textures.

public void
dispose()

Overrides com.badlogic.gdx.graphics.GLTexture.dispose.

Implements com.badlogic.gdx.utils.Disposable.dispose.

Disposes all resources associated with the texture

public void
draw(Pixmap
The Pixmap
pixmap
,
int
The x coordinate in pixels
x
,
int
The y coordinate in pixels
y
)

Draws the given Pixmap to the texture at position x, y.

public int
public int
public static String
public static int
getNumManagedTextures()

Returns: the number of managed textures currently loaded

public TextureData
public int
public static void
invalidateAllTextures(Application app)

Invalidate all managed textures.

public boolean
isManaged()

Implements abstract com.badlogic.gdx.graphics.GLTexture.isManaged.

Returns: whether this texture is managed or not.

public void
protected void
reload()

Implements abstract com.badlogic.gdx.graphics.GLTexture.reload.

Used internally to reload after context loss.

public static void
setAssetManager(AssetManager
the asset manager.
manager
)

Sets the AssetManager.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from com.badlogic.gdx.graphics.GLTexture:
bindbinddeletegetAnisotropicFiltergetMagFiltergetMaxAnisotropicFilterLevelgetMinFiltergetTextureObjectHandlegetUWrapgetVWrapsetAnisotropicFiltersetFiltersetWrapunsafeSetAnisotropicFilterunsafeSetAnisotropicFilterunsafeSetFilterunsafeSetFilterunsafeSetWrapunsafeSetWrapuploadImageDatauploadImageData

Field Detail

assetManagerback to summary
private static AssetManager assetManager
databack to summary
pack-priv TextureData data
managedTexturesback to summary
pack-priv static final Map<Application, Array<Texture>> managedTextures

Constructor Detail

Textureback to summary
protected Texture()
Textureback to summary
public Texture(String internalPath)
Textureback to summary
public Texture(FileHandle file)
Textureback to summary
public Texture(FileHandle file, boolean useMipMaps)
Textureback to summary
public Texture(FileHandle file, Pixmap.Format format, boolean useMipMaps)
Textureback to summary
public Texture(Pixmap pixmap)
Textureback to summary
public Texture(Pixmap pixmap, boolean useMipMaps)
Textureback to summary
public Texture(Pixmap pixmap, Pixmap.Format format, boolean useMipMaps)
Textureback to summary
public Texture(int width, int height, Pixmap.Format format)
Textureback to summary
public Texture(TextureData data)
Textureback to summary
protected Texture(int glTarget, int glHandle, TextureData data)

Method Detail

addManagedTextureback to summary
private static void addManagedTexture(Application app, Texture texture)
clearAllTexturesback to summary
public static void clearAllTextures(Application app)

Clears all managed textures. This is an internal method. Do not use it!

disposeback to summary
public void dispose()

Overrides com.badlogic.gdx.graphics.GLTexture.dispose.

Implements com.badlogic.gdx.utils.Disposable.dispose.

Disposes all resources associated with the texture

drawback to summary
public void draw(Pixmap pixmap, int x, int y)

Draws the given Pixmap to the texture at position x, y. No clipping is performed so you have to make sure that you draw only inside the texture region. Note that this will only draw to mipmap level 0!

Parameters
pixmap:Pixmap

The Pixmap

x:int

The x coordinate in pixels

y:int

The y coordinate in pixels

getDepthback to summary
public int getDepth()

Implements abstract com.badlogic.gdx.graphics.GLTexture.getDepth.

Annotations
@Override
getHeightback to summary
public int getHeight()

Implements abstract com.badlogic.gdx.graphics.GLTexture.getHeight.

Annotations
@Override
getManagedStatusback to summary
public static String getManagedStatus()
getNumManagedTexturesback to summary
public static int getNumManagedTextures()
Returns:int

the number of managed textures currently loaded

getTextureDataback to summary
public TextureData getTextureData()
getWidthback to summary
public int getWidth()

Implements abstract com.badlogic.gdx.graphics.GLTexture.getWidth.

Annotations
@Override
invalidateAllTexturesback to summary
public static void invalidateAllTextures(Application app)

Invalidate all managed textures. This is an internal method. Do not use it!

isManagedback to summary
public boolean isManaged()

Implements abstract com.badlogic.gdx.graphics.GLTexture.isManaged.

Returns:boolean

whether this texture is managed or not.

loadback to summary
public void load(TextureData data)
reloadback to summary
protected void reload()

Implements abstract com.badlogic.gdx.graphics.GLTexture.reload.

Used internally to reload after context loss. Creates a new GL handle then calls load(TextureData). Use this only if you know what you do!

Annotations
@Override
setAssetManagerback to summary
public static void setAssetManager(AssetManager manager)

Sets the AssetManager. When the context is lost, textures managed by the asset manager are reloaded by the manager on a separate thread (provided that a suitable AssetLoader is registered with the manager). Textures not managed by the AssetManager are reloaded via the usual means on the rendering thread.

Parameters
manager:AssetManager

the asset manager.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

com.badlogic.gdx.graphics back to summary

public final Enum Texture.TextureFilter

extends Enum<Texture.TextureFilter>
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv final int
public static final Texture.TextureFilter
Linear

Fetch four nearest texels that best maps to the pixel on screen.

public static final Texture.TextureFilter
public static final Texture.TextureFilter
MipMapLinearLinear

Fetch the two best fitting images from the mip map chain and then sample the four nearest texels from each of the two images, combining them to the final output pixel.

public static final Texture.TextureFilter
MipMapLinearNearest

Fetch the best fitting image from the mip map chain based on the pixel/texel ratio and then sample the texels with a linear filter.

public static final Texture.TextureFilter
MipMapNearestLinear

Fetch the two best fitting images from the mip map chain and then sample the nearest texel from each of the two images, combining them to the final output pixel.

public static final Texture.TextureFilter
MipMapNearestNearest

Fetch the best fitting image from the mip map chain based on the pixel/texel ratio and then sample the texels with a nearest filter.

public static final Texture.TextureFilter
Nearest

Fetch the nearest texel that best maps to the pixel on screen.

Constructor Summary

AccessConstructor and Description
private
TextureFilter(int glEnum)

Method Summary

Modifier and TypeMethod and Description
public int
public boolean
public static Texture.TextureFilter
public static Texture.TextureFilter[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

glEnumback to summary
pack-priv final int glEnum
Linearback to summary
public static final Texture.TextureFilter Linear

Fetch four nearest texels that best maps to the pixel on screen.

MipMapback to summary
public static final Texture.TextureFilter MipMap
See Also
TextureFilter#MipMapLinearLinear
MipMapLinearLinearback to summary
public static final Texture.TextureFilter MipMapLinearLinear

Fetch the two best fitting images from the mip map chain and then sample the four nearest texels from each of the two images, combining them to the final output pixel.

MipMapLinearNearestback to summary
public static final Texture.TextureFilter MipMapLinearNearest

Fetch the best fitting image from the mip map chain based on the pixel/texel ratio and then sample the texels with a linear filter.

MipMapNearestLinearback to summary
public static final Texture.TextureFilter MipMapNearestLinear

Fetch the two best fitting images from the mip map chain and then sample the nearest texel from each of the two images, combining them to the final output pixel.

MipMapNearestNearestback to summary
public static final Texture.TextureFilter MipMapNearestNearest

Fetch the best fitting image from the mip map chain based on the pixel/texel ratio and then sample the texels with a nearest filter.

Nearestback to summary
public static final Texture.TextureFilter Nearest

Fetch the nearest texel that best maps to the pixel on screen.

Constructor Detail

TextureFilterback to summary
private TextureFilter(int glEnum)

Method Detail

getGLEnumback to summary
public int getGLEnum()
isMipMapback to summary
public boolean isMipMap()
valueOfback to summary
public static Texture.TextureFilter valueOf(String name)
valuesback to summary
public static Texture.TextureFilter[] values()
com.badlogic.gdx.graphics back to summary

public final Enum Texture.TextureWrap

extends Enum<Texture.TextureWrap>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final Texture.TextureWrap
pack-priv final int
public static final Texture.TextureWrap
public static final Texture.TextureWrap

Constructor Summary

AccessConstructor and Description
private
TextureWrap(int glEnum)

Method Summary

Modifier and TypeMethod and Description
public int
public static Texture.TextureWrap
public static Texture.TextureWrap[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ClampToEdgeback to summary
public static final Texture.TextureWrap ClampToEdge
glEnumback to summary
pack-priv final int glEnum
MirroredRepeatback to summary
public static final Texture.TextureWrap MirroredRepeat
Repeatback to summary
public static final Texture.TextureWrap Repeat

Constructor Detail

TextureWrapback to summary
private TextureWrap(int glEnum)

Method Detail

getGLEnumback to summary
public int getGLEnum()
valueOfback to summary
public static Texture.TextureWrap valueOf(String name)
valuesback to summary
public static Texture.TextureWrap[] values()