Go to the documentation of this file.
71 #include <sys/types.h>
93 bool isAbsolute = (filename[0] ==
'/'
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)) {
Value tryInsert(Key &key, Value value, size_t &newMemUsed)
static PtexCache * create(int maxFiles, size_t maxMem, bool premultiply=false, PtexInputHandler *inputHandler=0, PtexErrorHandler *errorHandler=0)
Create a cache with the specified limits.
virtual void getStats(Stats &stats)
Get stats.
void adjustMemUsed(size_t amount)
PtexLruList< PtexCachedReader, &PtexCachedReader::_activeFilesItem > _activeFiles
#define PTEX_NAMESPACE_END
File-handle and memory cache for reading ptex files.
PtexCachedReader *volatile files[numMruFiles]
PtexLruList< PtexCachedReader, &PtexCachedReader::_openFilesItem > _openFiles
virtual void release()
Release resources held by this pointer (pointer becomes invalid).
bool tryPrune(size_t &memUsedChange)
virtual void purgeAll()
Remove all texture files from the cache.
Custom handler interface redirecting Ptex error messages.
MruList *volatile _prevMruList
size_t getMemUsedChange()
find_package(Doxygen) if(DOXYGEN_FOUND) add_custom_command(OUTPUT $
size_t getBlockReadsChange()
if(WIN32) add_definitions(/DPTEX_EXPORTS) endif(WIN32) configure_file(PtexVersion.h.in $
Half-precision (16-bit) floating-point type.
void operator()(PtexCachedReader *reader)
bool pendingPurge() const
Triangle filter kernel (in normalized triangle coords)
Cache for reading Ptex texture files.
bool open(const char *path, Ptex::String &error)
virtual PtexTexture * get(const char *path, Ptex::String &error)
Access a texture.
std::vector< std::string > _searchdirs
Interface for writing data to a ptex file.
Common data structures and enums used throughout the API.
void logRecentlyUsed(PtexCachedReader *reader)
Interface for reading data from a ptex file.
MruList *volatile _mruList
size_t memUsedChangeTotal
volatile size_t _filesOpen
void adjustFilesOpen(size_t amount)
bool findFile(const char *&filename, std::string &buffer, Ptex::String &error)
Public API classes for reading, writing, caching, and filtering Ptex files.
PtexVersion h ONLY set(SRCS PtexCache.cpp PtexFilters.cpp PtexHalf.cpp PtexReader.cpp PtexSeparableFilter.cpp PtexSeparableKernel.cpp PtexTriangleFilter.cpp PtexTriangleKernel.cpp PtexUtils.cpp PtexWriter.cpp) if(PTEX_BUILD_STATIC_LIBS) add_library(Ptex_static STATIC $
const char * c_str() const
bool tryPurge(size_t &memUsedChange)
set_target_properties(Ptex_static PROPERTIES OUTPUT_NAME Ptex) target_include_directories(Ptex_static PUBLIC $< INSTALL_INTERFACE
virtual void purge(PtexTexture *)
Remove a texture file from the cache.
static const int numMruFiles