A buffer for two-dimensional pixel data, stored in inverted row order (bottom row first, top row last) as expected by OpenGL.
More...
|
| | Pixmap (Format format, uint_t width, uint_t height, uint_t alignment=DEFAULT_ALIGNMENT) |
| | Construct a new pixmap with the specified pixel format, size, and alignment. More...
|
| |
| | ~Pixmap () throw () |
| | Destructor. More...
|
| |
| uint_t | getWidth () const throw () |
| | Get the width of the Pixmap, in pixels. More...
|
| |
| uint_t | getHeight () const throw () |
| | Get the height of the Pixmap, in pixels. More...
|
| |
| Size | getSize () const throw () |
| | Get the size of the pixmap. More...
|
| |
| void | setImageSize (const Size &imageSize) throw () |
| | Set the size of the image that is currently being stored in the Pixmap. More...
|
| |
| const Size & | getImageSize () const throw () |
| | Get the size of the image that is currently being stored in the Pixmap. More...
|
| |
| int | getImageWidth () const throw () |
| | Get the width of the image that is currently being stored in the Pixmap, in pixels. More...
|
| |
| int | getImageHeight () const throw () |
| | Get the height of the image that is currently being stored in the Pixmap, in pixels. More...
|
| |
| uint_t | getRowStride () const throw () |
| | Get the row stride for the Pixmap, i.e., the number of bytes occupied by one row of pixel data, including any padding bytes as dictated by the alignment. More...
|
| |
| Format | getFormat () const throw () |
| | Get the image format. More...
|
| |
| const byte_t * | getData () const throw () |
| | Get a pointer to the beginning (the bottom-left corner) of the pixel data. More...
|
| |
| byte_t * | getData () throw () |
| | Get a pointer to the beginning (the bottom-left corner) of the pixel data. More...
|
| |
| const size_t | getDataLength () const throw () |
| | Get the length of the pixel data, in bytes. More...
|
| |
| uint_t | getAlignment () const throw () |
| | Get the storage alignment. More...
|
| |
| void | clear () throw () |
| | Clear the Pixmap. More...
|
| |
| bool | isNull () const throw () |
| | Test if the Pixmap is null, that is, a Pixmap with 0x0 size. More...
|
| |
A buffer for two-dimensional pixel data, stored in inverted row order (bottom row first, top row last) as expected by OpenGL.
The format of the pixel data may be either 32-bit RGBA (corresponding to GL_RGBA) or 8-bit alpha channel (corresponding to GL_ALPHA).
A Pixmap cannot be resized once it has been created; however, the Pixmap may be used to store images that are smaller than itself. The image size is the size of the image currently stored in the pixmap. Unless otherwise specified via a call to setImageSize(), this will be equal to the Pixmap's size.
When passing the Pixmap's data to an OpenGL routine such as glTexImage2D(), care must be taken to first set the pixel storage modes to match the characteristics of the pixmap, and to pass the width and height of the image within the pixmap (rather than the width and height of the pixmap itself, which may be larger than the image data it contains) to the function that receives the pixel data, e.g.:
GLint oldAlignment;
glGetIntegerv(GL_UNPACK_ALIGNMENT, &oldAlignment);
glPixelStorei(GL_UNPACK_ALIGNMENT, pixmap->getAlignment());
glPixelStorei(GL_UNPACK_ROW_LENGTH, pixmap->getWidth());
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap->getImageWidth(),
pixmap->getImageHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,
pixmap->getData());
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, oldAlignment);
OpenGL ES does not support GL_UNPACK_ROW_LENGTH. An alternative approach is:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pixmap->getImageWidth(),
pixmap->getImageHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE,
NULL);
const byte_t* row = pixmap->getData();
int h = pixmap->getImageHeight();
for(int y = 0; y < h; ++y)
{
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, y, pixmap->getImageWidth(), 1,
GL_RGBA, GL_UNSIGNED_BYTE, row);
row += pixmap->getRowStride();
}
- Author
- Mark Lindner