pfuPalettizer(3pf) OpenGL Performer 3.2.2 libpfutil C++ Reference Pages
NAMEpfuPalettizer - Class for creating one or more texture palettes of
multiple textures
FUNCTION SPECIFICATION
#include <Performer/pfutil/pfuPalettizer.h>
pfuPalettizer::pfuPalettizer(void);
pfList * pfuPalettizer::getPaletteList(void);
pfList * pfuPalettizer::getCompleteList(void);
int pfuPalettizer::palettize(pfNode *node);
void pfuPalettizer::setST(uint s, uint t);
void pfuPalettizer::setMargin(uint margin);
void pfuPalettizer::setTexturePrefix(const char *prefix);
void pfuPalettizer::setBackground(float r, float g, float b);
void pfuPalettizer::setMode(int mode, int val);
void pfuPalettizer::getMode(int mode);
DESCRIPTION
The purpose of the palettizer is to consolidate textures into a single or
a smaller group of textures, thus reducing expensive texture binds during
rendering. This is beneficial to databases that use many textures.
There are two cases in which the palettizer is of no use: 1) Textures
that are referred to by GeoSets that contain texture coordinates outside
the range of 0.0 - 1.0. That is, geosets that intend to "repeat"
textures. 2) Textures that use detail. There is currently no practical
way to produce detail textures for a palette of multiple textures.
pfuPalettizer::getPaletteList(void) returns a list of newly created
palettes after palettize has been called.
pfuPalettizer::getCompleteList(void) returns the list of textures
including the newly created palette that are referred to under 'node'
after palettize has been called.
pfuPalettizer::palettize(pfNode *node) does the actual work of
palettization. node is traversed and all textures are found. Textures
too large to fit in s or t, textures with detail, or with pfGeoSets with
texture coordinates outside of the range 0.0-1.0 are passed over. The
remaining textures are bin-packed (allowing for margins), using a
multipass bin-packing algorithm into the larger texture. If all binable
textures do not fit within s and t, multiple textures are created until
all textures are either palettized or left alone.
Page 1
pfuPalettizer(3pf) OpenGL Performer 3.2.2 libpfutil C++ Reference Pages
pfuPalettizer::setST(uint s, uint t) allows the setting of maximum width
(s) and maximum height (t) of newly created palettes. Actual s and t
dimensions may change if space is wasted.
pfuPalettizer::setMargin(uint margin) allows the setting of the margin
around texture tiles. margin is the number of pixels of value 0 to be
placed around each original texture. The space between adjacent textures
then becomes 2 * margin.
pfuPalettizer::setTexturePrefix(const char *prefix) allows the
specification of a file prefix prefix to be used when naming the newly
created texture palettes. Palette names are prepended with prefix and
extended with ###.rgba, where ### is a sequence of numbers.
pfuPalettizer::setMode(int mode, int val) specifies a mode for creating
the palette texture. mode is a token to specify which mode to set and
val is a boolean value. Currently, the only mode supported is
PFUPAL_MODE_MIPMAP and val is a boolean. By default, val is 1. Force
non-mipmapped palettes by seting BPFUPAL_MODE_MIPMAP to 0.
Example 1 :
pfInit();
pfConfig();
...
// Load a database
pfNode *node;
if( (node = pfdLoadFile( mydatabase )) == (pfNode *)0L )
exit(1);
// Create a palettizer
p = new pfuPalettizer;
// Set the prefix of the palette to be created
p->setTexturePrefix( "myPalette" );
// Use a margin of 32 pixels between textures
p->setMargin( 32 );
// Allow mipmapping
p->setMode( PFUPAL_MODE_MIPMAP, 1 );
// Set maximum width and height of palette
p->setST( 512, 512 );
// palettize!
p->palettize( node );
// store the altered scene graph
pfdStoreFile( node, "mydatabase.pfb" );
// Store the new textures
pfList *texlist = p->getPaletteList();
for( int i = 0; i < texlist->getNum(); i++ )
{
Page 2
pfuPalettizer(3pf) OpenGL Performer 3.2.2 libpfutil C++ Reference Pages
pfTexture *tex = (pfTexture *)texlist->get( i );
tex->saveFile( tex->getName() );
}
...
SEE ALSOpfTexture(3pf)
Page 3