93 bool isAbsolute = (filename[0] ==
'/'
94#ifdef PTEX_PLATFORM_WINDOWS
95 || filename[0] ==
'\\'
96 || (isalpha(filename[0]) && filename[1] ==
':')
104 for (
size_t i = 0, size =
_searchdirs.size(); i < size; i++) {
108 if (stat(buffer.c_str(), &statbuf) == 0) {
109 filename = buffer.c_str();
114 std::string errstr =
"Can't find ptex file: ";
116 error = errstr.
c_str();
129 if (!reader->
ok())
return 0;
143 const char* pathToOpen = filename;
146 reader->
open(pathToOpen, error);
154 size_t newMemUsed = 0;
158 if (reader != newreader) {
182 if (maxFiles <= 0) maxFiles = 100;
184 return new PtexReaderCache(maxFiles, maxMem, premultiply, inputHandler, errorHandler);
194 mruList->
files[slot] = reader;
219 size_t memUsedChange = 0, filesOpenChange = 0;
222 do { reader = mruList->
files[i]; }
while (!reader);
223 mruList->
files[i] = 0;
227 filesOpenChange += opens;
228 if (opens || blockReads) {
244 if (shouldPruneFiles) {
247 if (shouldPruneData) {
257 if (numToClose > 0) {
272 size_t memUsedChangeTotal = 0;
274 while (memUsed + memUsedChangeTotal >
_maxMem) {
277 size_t memUsedChange;
278 if (reader->
tryPrune(memUsedChange)) {
280 memUsedChangeTotal += memUsedChange;
300 if (reader)
purge(reader);
305 size_t memUsedChange;
306 if (reader->
tryPurge(memUsedChange)) {
313 size_t memUsedChange;
314 if (reader->
tryPurge(memUsedChange)) {
#define PTEX_NAMESPACE_END
Public API classes for reading, writing, caching, and filtering Ptex files.
File-handle and memory cache for reading ptex files.
static PtexCache * create(int maxFiles, size_t maxMem, bool premultiply=false, PtexInputHandler *inputHandler=0, PtexErrorHandler *errorHandler=0)
Create a cache with the specified limits.
bool tryPurge(size_t &memUsedChange)
size_t getMemUsedChange()
bool tryPrune(size_t &memUsedChange)
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
size_t getBlockReadsChange()
Custom handler interface redirecting Ptex error messages.
Value tryInsert(Key &key, Value value, size_t &newMemUsed)
Cache for reading Ptex texture files.
PtexLruList< PtexCachedReader, &PtexCachedReader::_activeFilesItem > _activeFiles
void adjustFilesOpen(size_t amount)
void logRecentlyUsed(PtexCachedReader *reader)
MruList *volatile _prevMruList
void adjustMemUsed(size_t amount)
virtual PtexTexture * get(const char *path, Ptex::String &error)
Access a texture.
bool findFile(const char *&filename, std::string &buffer, Ptex::String &error)
virtual void getStats(Stats &stats)
Get stats.
static const int numMruFiles
PtexLruList< PtexCachedReader, &PtexCachedReader::_openFilesItem > _openFiles
virtual void purgeAll()
Remove all texture files from the cache.
volatile size_t _filesOpen
MruList *volatile _mruList
virtual void purge(PtexTexture *)
Remove a texture file from the cache.
std::vector< std::string > _searchdirs
bool pendingPurge() const
bool open(const char *path, Ptex::String &error)
Interface for reading data from a ptex file.
const char * c_str() const
PtexCachedReader *volatile files[numMruFiles]
void operator()(PtexCachedReader *reader)
size_t memUsedChangeTotal