Ptex
|
File-handle and memory cache for reading ptex files. More...
#include <Ptexture.h>
Public Member Functions | |
virtual void | release ()=0 |
Release resources held by this pointer (pointer becomes invalid). | |
virtual void | setSearchPath (const char *path)=0 |
Set a search path for finding textures. More... | |
virtual const char * | getSearchPath ()=0 |
Query the search path. More... | |
virtual PtexTexture * | get (const char *path, Ptex::String &error)=0 |
Open a texture. More... | |
virtual void | purge (PtexTexture *texture)=0 |
Remove a texture file from the cache. More... | |
virtual void | purge (const char *path)=0 |
Remove a texture file from the cache by pathname. More... | |
virtual void | purgeAll ()=0 |
Remove all texture files from the cache. More... | |
Static Public Member Functions | |
static PtexCache * | create (int maxFiles=0, int maxMem=0, bool premultiply=false, PtexInputHandler *handler=0) |
Create a cache with the specified limits. More... | |
Protected Member Functions | |
virtual | ~PtexCache () |
Destructor not for public use. Use release() instead. | |
File-handle and memory cache for reading ptex files.
The PtexCache class allows cached read access to multiple ptex files while constraining the open file count and memory usage to specified limits. File and data objects accessed via the cache are added back to the cache when their release method is called. Released objects are maintained in an LRU list and only destroyed when the specified resource limits are exceeded.
The cache is fully multi-threaded. Cached data will be shared among all threads that have access to the cache, and the data are protected with internal locks. See PtexCache.cpp for details about the caching and locking implementation.
|
static |
Create a cache with the specified limits.
maxFiles | Maximum open file handles. If unspecified, limit is set to 100 open files. |
maxMem | Maximum allocated memory, in bytes. If unspecified, limit is set to 100MB. |
premultiply | If true, textures will be premultiplied by the alpha channel (if any) when read from disk. See PtexTexture and PtexWriter for more details. |
handler | If specified, all input calls made through this cache will be directed through the handler. |
|
pure virtual |
Open a texture.
If the specified path was previously opened, and the open file limit hasn't been exceeded, then a pointer to the already open file will be returned.
If the specified path hasn't been opened yet or was closed, either to maintain the open file limit or because the file was explicitly purged from the cache, then the file will be newly opened. If the path is relative (i.e. doesn't begin with a '/') then the search path will be used to locate the file.
The texture file will stay open until the PtexTexture::release method is called, at which point the texture will be returned to the cache. Once released, the file will be closed when either the file handle limit is reached, the cached is released, or when the texture is purged (see purge methods below).
If texture could not be opened, null will be returned and an error string will be set.
path | File path. If path is relative, search path will be used to find the file. |
error | Error string set if texture could not be opened. |
|
pure virtual |
Query the search path.
Returns string set via setSearchPath.
|
pure virtual |
Remove a texture file from the cache.
The texture file will remain open and accessible until the file handle is released, but any future cache accesses for that file will open the file anew.
|
pure virtual |
Remove a texture file from the cache by pathname.
The path must match the full path as opened. This function will not search for the file, but if a search path was used, the path must match the path as found by the search path.
|
pure virtual |
Remove all texture files from the cache.
Open files with active PtexTexture* handles remain open until released.
|
pure virtual |
Set a search path for finding textures.
Note: if an input handler is installed the search path will be ignored.
path | colon-delimited search path. |