com.neovisionaries.android.opengl
Class Texture<TTexture extends Texture<TTexture>>

java.lang.Object
  extended by com.neovisionaries.android.opengl.Texture<TTexture>
Direct Known Subclasses:
Texture2D, TextureCubeMap

public abstract class Texture<TTexture extends Texture<TTexture>>
extends Object

OpenGL ES texture.

Author:
Takahiko Kawasaki

Constructor Summary
protected Texture(TextureType type)
          A constructor with a texture type.
 
Method Summary
 TTexture bind()
          Bind this texture using glBindTexture().
 TTexture delete()
          Delete this texture object using glDeleteTextures().
 TTexture generateMipmap()
          Generate mipmaps.
 int getId()
          Get the ID of this texture.
 TextureState getState()
          Get the state of this texture.
 TextureType getType()
          Get the type of this texture.
 int getUnit()
          Get the texture unit that this texture should be bound to.
abstract  boolean isBound()
          Check if this texture is bound.
 TTexture setMagFilter(MagFilter filter)
          Set a mag filter.
 TTexture setMinFilter(MinFilter filter)
          Set a min filter.
 TTexture setUnit(int textureUnit)
          Set the texture unit that this texture should be bound to.
 TTexture setWrapS(WrapMode mode)
          Set a wrap mode for S coordinates of textures.
 TTexture setWrapT(WrapMode mode)
          Set a wrap mode for T coordinates of textures.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Texture

protected Texture(TextureType type)
           throws GLESException
A constructor with a texture type. A texture object is assigned internally by glGenTextures(). If this constructor returns without any exception, the state of this instance is TextureState.CREATED.

Parameters:
type - A texture type.
Throws:
IllegalArgumentException - The given argument is null.
GLESException - glGenTextures() failed.
See Also:
Texture2D.Texture2D(), TextureCubeMap.TextureCubeMap(), glGenTextures
Method Detail

getType

public TextureType getType()
Get the type of this texture.

Returns:
The type of this texture.

getId

public int getId()
Get the ID of this texture.

Returns:
The ID of this texture assigned by glGenTextures().
See Also:
glGenTextures

getState

public TextureState getState()
Get the state of this texture.

Returns:
The state of this texture.

getUnit

public int getUnit()
Get the texture unit that this texture should be bound to. The default value is 0.

Returns:
The texture unit number. 0 means GL_TEXTURE0.
See Also:
glBindTexture

setUnit

public TTexture setUnit(int textureUnit)
Set the texture unit that this texture should be bound to. The default value before this method is called is 0.

Parameters:
textureUnit - A texture unit number. 0 means GL_TEXTURE0. The range of the number is from 0 to (GLESState.getMaxTextureImageUnits() - 1).
Returns:
This Texture object.
Throws:
IllegalArgumentException -
  • 'textureUnit' is less than 0.
  • 'textureUnit' is equal to or greater than the state value of GL_MAX_TEXTURE_IMAGE_UNITS.
See Also:
GLESState.getMaxTextureImageUnits(), glBindTexture

bind

public TTexture bind()
Bind this texture using glBindTexture().

If the current active texture unit is not the one that this texture should be bound to (= the one that has been set by setUnit(int)), glActiveTexture() is called before glBindTexture().

Returns:
This Texture object.
Throws:
IllegalStateException - This texture has already been deleted.
See Also:
GLESState.getActiveTexture(), glActiveTexture, glBindTexture

delete

public TTexture delete()
Delete this texture object using glDeleteTextures(). If the texture object has already been deleted, nothing is executed. After this method returns, the state of this instance is TextureState.DELETED.

Returns:
This Texture object.
See Also:
glDeleteTextures

isBound

public abstract boolean isBound()
Check if this texture is bound.

Returns:
True if this texture is bound.

setMagFilter

public TTexture setMagFilter(MagFilter filter)
Set a mag filter.

If this texture is not bound when this method is called, bind() is called before glTexParameter(GL_TEXTURE_MAG_FILTER, filter.getFilter()) is called.

Parameters:
filter - A mag filter.
Returns:
This Texture object.
Throws:
IllegalArgumentException - 'filter' is null.
IllegalStateException - This texture has already been deleted.
See Also:
glTexParameter

setMinFilter

public TTexture setMinFilter(MinFilter filter)
Set a min filter.

If this texture is not bound when this method is called, bind() is called before glTexParameter(GL_TEXTURE_MIN_FILTER, filter.getFilter()) is called.

Parameters:
filter - A min filter.
Returns:
This Texture object.
Throws:
IllegalArgumentException - 'filter' is null.
IllegalStateException - This texture has already been deleted.
See Also:
glTexParameter

setWrapS

public TTexture setWrapS(WrapMode mode)
Set a wrap mode for S coordinates of textures.

If this texture is not bound when this method is called, bind() is called before glTexParameter(GL_TEXTURE_WRAP_S, mode.getMode()) is called.

Parameters:
mode - A wrap mode.
Returns:
This Texture object.
Throws:
IllegalArgumentException - 'mode' is null.
IllegalStateException - This texture has already been deleted.
See Also:
glTexParameter

setWrapT

public TTexture setWrapT(WrapMode mode)
Set a wrap mode for T coordinates of textures.

If this texture is not bound when this method is called, bind() is called before glTexParameter(GL_TEXTURE_WRAP_T, mode.getMode()) is called.

Parameters:
mode - A wrap mode.
Returns:
This Texture object.
Throws:
IllegalArgumentException - 'mode' is null.
IllegalStateException - This texture has already been deleted.
See Also:
glTexParameter

generateMipmap

public TTexture generateMipmap()
Generate mipmaps.

If this texture is not bound when this method is called, bind() is called first. Then glGenerateMipmap() is called.

Returns:
This Texture object.
Throws:
IllegalStateException - This texture has already been deleted.
See Also:
glGenerateMipmap