The AbstractImage hierarchy
The following sections deal with the various concrete image classes. All
images subclass AbstractImage, which provides the basic interface described
in previous sections.
An image of any class can be converted into a Texture or ImageData using
the get_texture and get_image_data methods defined on AbstractImage. For
example, to load an image and work with it as an OpenGL texture:
kitten = pyglet.image.load('kitten.png').get_texture()
There is no penalty for accessing one of these methods if object is already
of the requested class. The following table shows how concrete classes are
converted into other classes:
Original class |
.get_texture() |
.get_image_data() |
Texture |
No change |
glGetTexImage2D |
TextureRegion |
No change |
glGetTexImage2D, crop resulting image. |
ImageData |
glTexImage2D |
No change |
ImageDataRegion |
glTexImage2D |
No change |
CompressedImageData |
glCompressedTexImage2D |
N/A |
BufferImage |
glCopyTexSubImage2D |
glReadPixels |
You should try to avoid conversions which use glGetTexImage2D or
glReadPixels, as these can impose a substantial performance penalty by
transferring data in the "wrong" direction of the video bus, especially on
older hardware.