blip
0.1
|
A buffer for two-dimensional pixel data, stored in inverted row order (bottom row first, top row last) as expected by OpenGL. More...
#include <Pixmap.hpp>
Public Types | |
enum | Format { Format_RGBA_32, Format_Alpha_8 } |
Public Member Functions | |
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... | |
Static Public Attributes | |
static const uint_t | DEFAULT_ALIGNMENT = sizeof(void*) |
The default alignment for pixel data for the host platform. 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(); }
enum Format |
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.
format | The image format. |
width | The width of the Pixmap, in pixels. |
height | The width of the Pixmap, in pixels. |
alignment | The alignment; each row of pixel data will have a length that is an even multiple of the alignment. Allowed values are 1, 2, 4, and 8. If an invalid value is specified, DEFAULT_ALIGNMENT is used instead. |
~Pixmap | ( | ) | ||
throw | ( | |||
) |
Destructor.
void clear | ( | ) | ||
throw | ( | |||
) |
Clear the Pixmap.
Zeroes the pixmap data.
|
inline |
Get the storage alignment.
|
inline |
Get a pointer to the beginning (the bottom-left corner) of the pixel data.
|
inline |
Get a pointer to the beginning (the bottom-left corner) of the pixel data.
|
inline |
Get the length of the pixel data, in bytes.
|
inline |
Get the image format.
|
inline |
Get the height of the Pixmap, in pixels.
|
inline |
Get the height of the image that is currently being stored in the Pixmap, in pixels.
|
inline |
Get the size of the image that is currently being stored in the Pixmap.
If an image size has not been explicitly set with setImageSize()
, this will be equal to the Pixmap's size.
|
inline |
Get the width of the image that is currently being stored in the Pixmap, in pixels.
|
inline |
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.
|
inline |
Get the size of the pixmap.
|
inline |
Get the width of the Pixmap, in pixels.
void setImageSize | ( | const Size & | imageSize | ) | |
throw | ( | ||||
) |
|
static |
The default alignment for pixel data for the host platform.