Panda3D
Static Public Member Functions
MaterialPool Class Reference

The MaterialPool (there is only one in the universe) serves to unify different pointers to the same Material, so we do not (a) waste memory with many different Material objects that are all equivalent, and (b) waste time switching the graphics engine between different Material states that are really the same thing. More...

#include "materialPool.h"

List of all members.

Static Public Member Functions

static int garbage_collect ()
 Releases only those materials in the pool that have a reference count of exactly 1; i.e.
static Materialget_material (Material *temp)
 Returns a Material pointer that represents the same material described by temp, except that it is a shared pointer.
static void list_contents (ostream &out)
 Lists the contents of the material pool to the indicated output stream.
static void release_all_materials ()
 Releases all materials in the pool and restores the pool to the empty state.
static void release_material (Material *temp)
 Removes the indicated material from the pool.
static void write (ostream &out)
 Lists the contents of the material pool to the indicated output stream.

Detailed Description

The MaterialPool (there is only one in the universe) serves to unify different pointers to the same Material, so we do not (a) waste memory with many different Material objects that are all equivalent, and (b) waste time switching the graphics engine between different Material states that are really the same thing.

The idea is to create a temporary Material representing the lighting state you want to apply, then call get_material(), passing in your temporary Material. The return value will either be a new Material object, or it may be the the same object you supplied; in either case, it will have the same value.

Definition at line 42 of file materialPool.h.


Member Function Documentation

int MaterialPool::garbage_collect ( ) [inline, static]

Releases only those materials in the pool that have a reference count of exactly 1; i.e.

only those materials that are not being used outside of the pool. Returns the number of materials released.

Definition at line 71 of file materialPool.I.

Material * MaterialPool::get_material ( Material temp) [inline, static]

Returns a Material pointer that represents the same material described by temp, except that it is a shared pointer.

Each call to get_material() passing an equivalent Material pointer will return the same shared pointer.

If you modify the shared pointer, it will automatically disassociate it from the pool.

Also, the return value may be a different pointer than that passed in, or it may be the same pointer. In either case, the passed in pointer has now been sacrificed to the greater good and should not be used again (like any other PointerTo, it will be freed when the last reference count is removed).

Definition at line 37 of file materialPool.I.

void MaterialPool::list_contents ( ostream &  out) [inline, static]

Lists the contents of the material pool to the indicated output stream.

Definition at line 82 of file materialPool.I.

void MaterialPool::release_all_materials ( ) [inline, static]

Releases all materials in the pool and restores the pool to the empty state.

Definition at line 58 of file materialPool.I.

void MaterialPool::release_material ( Material temp) [inline, static]

Removes the indicated material from the pool.

Definition at line 47 of file materialPool.I.

void MaterialPool::write ( ostream &  out) [static]

Lists the contents of the material pool to the indicated output stream.

Definition at line 29 of file materialPool.cxx.


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations