class GL.Texture
The Texture class in the GL submodule provides a context-independent
representation of an OpenGL texture. You can use a single Texture
object with multiple GLViews and/or GLPixmaps without being concerned
whether they are sharing texture spaces or not, and without having to
keep track of OpenGL texture numbers.
Texture is an abstract class. To use it, you subclass it and define the do_setup
method to make whatever OpenGL calls are necessary to set up the
texture. Then, when you want to draw with the texture, you call the bind
method to make it the current OpenGL texture. Whenever the Texture is
used in a context where it has not been used before, your do_setup method will be called to create a representation of the texture appropriate to that context.
Keep in mind that any call to bind can trigger allocation of a texture number and a call to your do_setup
method, and this will usually happen while you are in the middle of
doing OpenGL drawing. If this would be inconvenient, you may need to
"preload" the texture by calling the bind method once in each context where the texture might be used, before you start drawing.
Constructor
- Texture(texture_type)
- Constructs a texture of the given type. The texture_type should be one of the OpenGL texture type constants (GL_TEXTURE_2D etc).
Methods
- bind()
- Makes this
texture the current texture for the current context by calling
glBindTexture. If this texture has not previously been used
with the current context (or one with which it is sharing
textures), an OpenGL texture number is allocated and do_setup is called to initialise a representation of the texture.
- deallocate()
- Deallocates any OpenGL resources currently allocated to the Texture. If it is used again, new resources will be allocated.
Abstract methods
- do_setup()
- This method should be implemented to make the necessary OpenGL
calls to initialise the texture. When this method is called, a texture
number will already have been allocated and glBindTexture called to make it the current texture.