Ptex
|
Cache for reading Ptex texture files. More...
Public Member Functions | |
PtexReaderCache (int maxFiles, int maxMem, bool premultiply, PtexInputHandler *handler) | |
~PtexReaderCache () | |
virtual void | setSearchPath (const char *path) |
Set a search path for finding textures. More... | |
virtual const char * | getSearchPath () |
Query the search path. More... | |
virtual PtexTexture * | get (const char *path, Ptex::String &error) |
Open a texture. More... | |
virtual void | purge (PtexTexture *texture) |
Remove a texture file from the cache. More... | |
virtual void | purge (const char *filename) |
Remove a texture file from the cache by pathname. More... | |
virtual void | purgeAll () |
Remove all texture files from the cache. More... | |
void | removeBlankEntries () |
![]() | |
PtexCacheImpl (int maxFiles, int maxMem) | |
virtual void | release () |
Release resources held by this pointer (pointer becomes invalid). More... | |
void | setPendingDelete () |
void | handlePendingDelete () |
void | setFileInUse (PtexLruItem *file) |
void | setFileUnused (PtexLruItem *file) |
void | removeFile () |
void | setDataInUse (PtexLruItem *data, int size) |
void | setDataUnused (PtexLruItem *data, int size) |
void | removeData (int size) |
void | purgeFiles () |
void | purgeData () |
Private Types | |
typedef PtexDict< PtexReader * > | FileMap |
Private Attributes | |
PtexInputHandler * | _io |
std::string | _searchpath |
std::vector< std::string > | _searchdirs |
FileMap | _files |
int | _cleanupCount |
bool | _premultiply |
Additional Inherited Members | |
![]() | |
static void | addFile () |
static void | addData () |
![]() | |
static PtexCache * | create (int maxFiles=0, int maxMem=0, bool premultiply=false, PtexInputHandler *handler=0) |
Create a cache with the specified limits. More... | |
![]() | |
Mutex | openlock |
CacheLock | cachelock |
![]() | |
~PtexCacheImpl () | |
![]() | |
virtual | ~PtexCache () |
Destructor not for public use. Use release() instead. More... | |
Cache for reading Ptex texture files.
Definition at line 201 of file PtexCache.cpp.
|
private |
Definition at line 304 of file PtexCache.cpp.
|
inline |
Definition at line 204 of file PtexCache.cpp.
|
inline |
Definition at line 209 of file PtexCache.cpp.
References purgeAll().
|
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. |
Implements PtexCache.
Definition at line 311 of file PtexCache.cpp.
References _cleanupCount, _files, _io, _premultiply, _searchdirs, Ptex::String::c_str(), PtexCacheImpl::cachelock, PtexInternal::_SpinLock::lock(), PtexReader::open(), PtexCacheImpl::openlock, PtexLruItem::orphan(), PtexCacheImpl::purgeFiles(), PtexCachedFile::ref(), removeBlankEntries(), PtexInternal::_SpinLock::unlock(), and PtexCachedFile::unref().
|
inlinevirtual |
Query the search path.
Returns string set via setSearchPath.
Implements PtexCache.
Definition at line 242 of file PtexCache.cpp.
References _searchpath, and PtexCacheImpl::openlock.
|
inlinevirtual |
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.
Implements PtexCache.
Definition at line 251 of file PtexCache.cpp.
References PtexReader::path().
|
inlinevirtual |
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.
Implements PtexCache.
Definition at line 261 of file PtexCache.cpp.
References _files, PtexCacheImpl::cachelock, PtexDict< T >::end(), PtexDict< T >::erase(), PtexDict< T >::find(), PtexDict< PtexReader * >::iterator, and PtexLruItem::orphan().
|
inlinevirtual |
Remove all texture files from the cache.
Open files with active PtexTexture* handles remain open until released.
Implements PtexCache.
Definition at line 275 of file PtexCache.cpp.
References _files, PtexDict< T >::begin(), PtexCacheImpl::cachelock, PtexDict< T >::end(), PtexDict< T >::erase(), PtexDict< PtexReader * >::iterator, and PtexLruItem::orphan().
Referenced by ~PtexReaderCache().
|
inline |
Definition at line 290 of file PtexCache.cpp.
References _files, PtexDict< T >::begin(), PtexDict< T >::end(), PtexDict< T >::erase(), and PtexDict< PtexReader * >::iterator.
Referenced by get().
|
inlinevirtual |
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. |
Implements PtexCache.
Definition at line 216 of file PtexCache.cpp.
References _searchdirs, _searchpath, and PtexCacheImpl::openlock.
|
private |
Definition at line 306 of file PtexCache.cpp.
Referenced by get().
|
private |
Definition at line 305 of file PtexCache.cpp.
Referenced by get(), purge(), purgeAll(), and removeBlankEntries().
|
private |
Definition at line 301 of file PtexCache.cpp.
Referenced by get().
|
private |
Definition at line 307 of file PtexCache.cpp.
Referenced by get().
|
private |
Definition at line 303 of file PtexCache.cpp.
Referenced by get(), and setSearchPath().
|
private |
Definition at line 302 of file PtexCache.cpp.
Referenced by getSearchPath(), and setSearchPath().