Contents / Previous / Next


Texture Objects

A texture object stores texture data and makes it readily available. Using texture objects is usually the fastest way to apply textures. It is much faster to bind (reuse) an existing texture object than it is to reload a texture image.

To use texture objects for your texture data, take these steps.

0) Check if you have enough space for all your texture objects.

1) Generate texture names.

2) Initially bind (create) texture objects to texture data, including the image arrays and texture properties.

3) Bind and rebind texture objects, making their data currently available for rendering textured models.

4) Delete Texture Objects


1) Naming A Texture Object

Any nonzero unsigned integer may be used as a texture name. To avoid accidentally reusing names, consistently use glGenTextures() to provide unused texture names:

  void glGenTextures(GLsizei n, GLuint *textureNames);
Returns n currently unused names for texture objects in the array textureNames. The names returned in textureNames do not have to be a contiguous set of integers.

Zero is a reserved texture name and is never returned as a texture name by glGenTextures().

glIsTexture() determines if a texture name is actually in use (Returns GL_TRUE).
If a texture name was returned by glGenTextures() but has not yet been bound (calling glBindTexture() with the name at least once), then glIsTexture() returns GL_FALSE.

  GLboolean glIsTexture(GLuint textureName);


2+3) Creating and Using Texture Objects

The same routine, glBindTexture(), both creates and uses texture objects. When a texture name is initially bound (used with glBindTexture()), a new texture object is created with default values for the texture image and texture properties.

Subsequent calls to glTexImage*(), glTexSubImage*(), glCopyTexImage*(), glCopyTexSubImage*(), glTexParameter*(), and glPrioritizeTextures() store data in the texture object.

The texture object may contain a texture image and associated mipmap images (if any), including associated data such as width, height, border width, internal format, resolution of components, and texture properties. Saved texture properties include minification and magnification filters, wrapping modes, border color, and texture priority.

When a texture object is subsequently bound once again, its data becomes the current texture state. (The state of the previously bound texture is replaced.)

  void glBindTexture(GLenum target, GLuinttextureName);
target is the dimensionality of the texture: either GL_TEXTURE_1D or GL_TEXTURE_2D.

When binding to a textureName value of zero, OpenGL stops using texture objects and returns to the unnamed default texture.

Whenever a texture object is bound once again, you may edit the contents of the bound texture object, i.e., change the texture image or other properties.

 int[] textureId = new int[nbTexture];
 ... 

 gl.glGenTextures( nbTexture, textureId, 0 );
 ...

 gl.glBindTexture( GL.GL_TEXTURE_2D, textureId[4] );

 // Load Texture
 // or
 // Change Texture Paramter
 // or 
 // Use Texture

 gl.glDeleteTextures( nbTexture, textureId, 0 );


4) Delete Texture Objects

As you bind and unbind texture objects, their data still sits around somewhere among your texture resources. If texture resources are limited, deleting textures may be one way to free up resources.
void glDeleteTextures(GLsizei n, const GLuint*textureNames);
Deletes n texture objects, named by elements in the array textureNames. The freed texture names may now be reused.

If a texture that is currently bound is deleted, the binding reverts to the default texture, as if glBindTexture() were called with zero for the value of textureName. Attempts to delete nonexistent texture names or the texture name of zero are ignored without generating an error.


0) Check

GL_MAX_TEXTURE_SIZE