44 #if defined(_WIN32) || defined(_WINDOWS) || defined(_MSC_VER) 48 # define PTEXAPI __declspec(dllexport) 50 # define PTEXAPI __declspec(dllimport) 61 # define PTEX_USE_STDSTRING 144 static const int sizes[] = { 1,2,2,4 };
150 static const float one[] = { 255.f, 65535.f, 1.f, 1.f };
156 static const float one[] = { 1.f/255.f, 1.f/65535.f, 1.f, 1.f };
177 Res() : ulog2(0), vlog2(0) {}
180 Res(int8_t ulog2_, int8_t vlog2_) : ulog2(ulog2_), vlog2(vlog2_) {}
183 Res(uint16_t value) : ulog2(int8_t(value&0xff)), vlog2(int8_t((value>>8)&0xff)) {}
186 int u()
const {
return 1<<(unsigned)ulog2; }
189 int v()
const {
return 1<<(unsigned)vlog2; }
192 uint16_t
val()
const {
return uint16_t(ulog2 | (vlog2<<8)); }
251 adjfaces[0] = adjfaces[1] = adjfaces[2] = adjfaces[3] = -1;
257 adjfaces[0] = adjfaces[1] = adjfaces[2] = adjfaces[3] = -1;
261 FaceInfo(
Res res_,
int adjfaces_[4],
int adjedges_[4],
bool isSubface_=
false)
262 : res(res_), flags(isSubface_ ? flag_subface : 0)
264 setadjfaces(adjfaces_[0], adjfaces_[1], adjfaces_[2], adjfaces_[3]);
265 setadjedges(adjedges_[0], adjedges_[1], adjedges_[2], adjedges_[3]);
272 int adjface(
int eid)
const {
return adjfaces[eid]; }
275 bool isConstant()
const {
return (flags & flag_constant) != 0; }
281 bool hasEdits()
const {
return (flags & flag_hasedits) != 0; }
284 bool isSubface()
const {
return (flags & flag_subface) != 0; }
288 { adjfaces[0] = f0, adjfaces[1] = f1, adjfaces[2] = f2; adjfaces[3] = f3; }
292 { adjedges = (uint8_t)((e0&3) | ((e1&3)<<2) | ((e2&3)<<4) | ((e3&3)<<6)); }
295 enum { flag_constant = 1, flag_hasedits = 2, flag_nbconstant = 4, flag_subface = 8 };
305 #ifdef PTEX_USE_STDSTRING 306 typedef std::string
String;
312 String(
const String& str) : _str(0) { *
this = str; }
314 PTEXAPI String& operator=(
const char* str);
317 const char*
c_str()
const {
return _str ? _str :
""; }
318 bool empty()
const {
return _str == 0 || _str[0] ==
'\0'; }
326 #ifndef PTEX_USE_STDSTRING 348 virtual void release() = 0;
351 virtual int numKeys() = 0;
361 virtual void getValue(
const char* key,
const char*& value) = 0;
365 virtual void getValue(
int index,
const char*& value) = 0;
369 virtual void getValue(
const char* key,
const int8_t*& value,
int& count) = 0;
373 virtual void getValue(
int index,
const int8_t*& value,
int& count) = 0;
377 virtual void getValue(
const char* key,
const int16_t*& value,
int& count) = 0;
381 virtual void getValue(
int index,
const int16_t*& value,
int& count) = 0;
385 virtual void getValue(
const char* key,
const int32_t*& value,
int& count) = 0;
389 virtual void getValue(
int index,
const int32_t*& value,
int& count) = 0;
393 virtual void getValue(
const char* key,
const float*& value,
int& count) = 0;
397 virtual void getValue(
int index,
const float*& value,
int& count) = 0;
401 virtual void getValue(
const char* key,
const double*& value,
int& count) = 0;
405 virtual void getValue(
int index,
const double*& value,
int& count) = 0;
426 virtual void release() = 0;
439 virtual void getPixel(
int u,
int v,
void* result) = 0;
447 virtual void* getData() = 0;
451 virtual bool isTiled() = 0;
491 virtual void release() = 0;
496 virtual const char* path() = 0;
509 virtual Info getInfo() = 0;
529 virtual int alphaChannel() = 0;
532 virtual int numChannels() = 0;
535 virtual int numFaces() = 0;
538 virtual bool hasEdits() = 0;
541 virtual bool hasMipMaps() = 0;
564 virtual void getData(
int faceid,
void* buffer,
int stride) = 0;
577 virtual void getData(
int faceid,
void* buffer,
int stride,
Ptex::Res res) = 0;
605 virtual void getPixel(
int faceid,
int u,
int v,
606 float* result,
int firstchan,
int nchannels) = 0;
619 virtual void getPixel(
int faceid,
int u,
int v,
620 float* result,
int firstchan,
int nchannels,
643 virtual Handle open(
const char* path) = 0;
646 virtual void seek(Handle handle, int64_t pos) = 0;
653 virtual size_t read(
void* buffer,
size_t size, Handle handle) = 0;
657 virtual bool close(Handle handle) = 0;
660 virtual const char* lastError() = 0;
676 virtual void reportError(
const char* error) = 0;
726 bool premultiply=
false,
731 virtual void release() = 0;
738 virtual void setSearchPath(
const char* path) = 0;
741 virtual const char* getSearchPath() = 0;
784 virtual void purge(
const char* path) = 0;
790 virtual void purgeAll() = 0;
803 virtual void getStats(
Stats& stats) = 0;
842 int nchannels,
int alphachan,
int nfaces,
863 static PtexWriter* edit(
const char* path,
bool incremental,
865 int nchannels,
int alphachan,
int nfaces,
877 static bool applyEdits(
const char* path,
Ptex::String& error);
880 virtual void release() = 0;
889 virtual void writeMeta(
const char* key,
const char*
string) = 0;
892 virtual void writeMeta(
const char* key,
const int8_t* value,
int count) = 0;
895 virtual void writeMeta(
const char* key,
const int16_t* value,
int count) = 0;
898 virtual void writeMeta(
const char* key,
const int32_t* value,
int count) = 0;
901 virtual void writeMeta(
const char* key,
const float* value,
int count) = 0;
904 virtual void writeMeta(
const char* key,
const double* value,
int count) = 0;
920 virtual bool writeFace(
int faceid,
const Ptex::FaceInfo& info,
const void* data,
int stride=0) = 0;
927 virtual bool writeConstantFace(
int faceid,
const Ptex::FaceInfo& info,
const void* data) = 0;
935 virtual bool writeFaceReduction(
int faceid,
const Ptex::Res& res,
const void* data,
int stride=0) = 0;
936 virtual bool writeConstantFaceReduction(
int faceid,
const Ptex::Res& res,
const void* data) = 0;
979 filter(filter_), lerp(lerp_), sharpness(sharpness_), noedgeblend(noedgeblend_) {}
987 virtual void release() = 0;
1010 virtual void eval(
float* result,
int firstchan,
int nchannels,
1011 int faceid,
float u,
float v,
float uw1,
float vw1,
float uw2,
float vw2,
1012 float width=1,
float blur=0) = 0;
1055 operator T* ()
const {
return _ptr; }
1058 T* operator-> ()
const {
return _ptr; }
1061 T*
get()
const {
return _ptr; }
1073 if (_ptr) _ptr->release();
1090 using Ptex::PtexMetaData;
1091 using Ptex::PtexFaceData;
1092 using Ptex::PtexTexture;
1093 using Ptex::PtexInputHandler;
1094 using Ptex::PtexErrorHandler;
1095 using Ptex::PtexCache;
1096 using Ptex::PtexWriter;
1097 using Ptex::PtexFilter;
1098 using Ptex::PtexPtr;
int v() const
V resolution in texels.
EdgeFilterMode edgeFilterMode
PtexPtr(T *ptr=0)
Constructor.
bool isConstant(const void *data, int stride, int ures, int vres, int pixelSize)
FaceInfo()
Default constructor.
Interface for writing data to a ptex file.
bool operator==(const Res &r) const
Comparison operator.
void setadjedges(int e0, int e1, int e2, int e3)
Set the adjedges data.
Half-precision (16-bit) floating point.
Don't do anything with the values.
int ntilesv(Res tileres) const
Determine the number of tiles in the v direction for the given tile res.
bool noedgeblend
Disable cross-face filtering. Useful for debugging or rendering on polys.
int size() const
Total size of specified texture in texels (u * v).
void reset(T *ptr=0)
Deallocate object pointed to, and optionally set to new value.
void ConvertFromFloat(void *dst, const float *src, Ptex::DataType dt, int numChannels)
Convert a number of data values from float to the given data type.
FaceInfo(Res res_)
Constructor.
texel access is clamped to border
Top edge, from UV (1,1) to (0,1)
bool isSubface() const
Determine if face is a subface (by checking a flag).
File-handle and memory cache for reading ptex files.
Single-precision (32-bit) floating point.
const char * DataTypeName(DataType dt)
Look up name of given data type.
EdgeFilterMode
How to handle transformation across edges when filtering.
Get most commonly used info in a single call for convenience / efficiency.
uint16_t val() const
Resolution as a single 16-bit integer value.
texel beyond border are assumed to be black
const char * c_str() const
virtual ~PtexFaceData()
Destructor not for public use. Use release() instead.
Double-precision (32-bit) floating point.
EdgeId
Edge IDs used in adjacency data in the Ptex::FaceInfo struct.
Values are vectors in tangent space; rotate values.
virtual ~PtexWriter()
Destructor not for public use. Use release() instead.
Per-face texture data accessor.
Custom handler interface redirecting Ptex error messages.
int8_t vlog2
log base 2 of v resolution, in texels
int adjface(int eid) const
Access an adjacent face id. The eid value must be 0..3.
MeshType
Type of base mesh for which the textures are defined.
Unsigned, 16-bit integer.
int u() const
U resolution in texels.
int ntilesu(Res tileres) const
Determine the number of tiles in the u direction for the given tile res.
bool isConstant() const
Determine if face is constant (by checking a flag).
const char * EdgeIdName(EdgeId eid)
Look up name of given edge ID.
BorderMode
How to handle mesh border when filtering.
String & operator=(const String &str)
Options(FilterType filter_=f_box, bool lerp_=0, float sharpness_=0, bool noedgeblend_=0)
Constructor - sets defaults.
virtual ~PtexFilter()
Destructor not for public use. Use release() instead.
Common data structures and enums used throughout the API.
~PtexPtr()
Destructor, calls ptr->release().
bool operator>=(const Res &r) const
True if res is >= given res in both u and v directions.
Point-sampled (no filtering)
virtual ~PtexTexture()
Destructor not for public use. Use release() instead.
String(const String &str)
Right edge, from UV (1,0) to (1,1)
Bottom edge, from UV (0,0) to (1,0)
FilterType filter
Filter type.
FaceInfo(Res res_, int adjfaces_[4], int adjedges_[4], bool isSubface_=false)
Constructor.
void setadjfaces(int f0, int f1, int f2, int f3)
Set the adjfaces data.
String & operator=(const std::string &str)
float OneValueInv(DataType dt)
Lookup up inverse value of given data type that corresponds to the normalized value of 1...
Res swappeduv() const
Get value of resolution with u and v swapped.
Catmull-Rom (equivalent to bi-cubic w/ sharpness=1)
Res()
Default constructor, sets res to 0 (1x1 texel).
void swapuv()
Swap the u and v resolution values in place.
BSpline (equivalent to bi-cubic w/ sharpness=0)
Res(int8_t ulog2_, int8_t vlog2_)
Constructor.
Smart-pointer for acquiring and releasing API objects.
int8_t ulog2
log base 2 of u resolution, in texels
const char * MeshTypeName(MeshType mt)
Look up name of given mesh type.
float sharpness
Filter sharpness, 0..1 (for general bi-cubic filter only).
Interface for reading data from a ptex file.
texel access wraps to other side of face
bool isNeighborhoodConstant() const
Determine if neighborhood of face is constant (by checking a flag).
virtual ~PtexErrorHandler()
Pixel resolution of a given texture.
Left edge, from UV (0,1) to (0,0)
bool operator!=(const Res &r) const
Comparison operator.
Single-precision (32-bit) floating point.
int DataSize(DataType dt)
Look up size of given data type (in bytes).
Res res
Resolution of face.
uint8_t adjedges
Adjacent edges, 2 bits per edge.
MetaDataType
Type of meta data entry.
Information about a face, as stored in the Ptex file header.
int ntiles(Res tileres) const
Determine the total number of tiles for the given tile res.
const char * BorderModeName(BorderMode m)
Look up name of given border mode.
DataType
Type of data stored in texture file.
Res(uint16_t value)
Constructor.
float OneValue(DataType dt)
Look up value of given data type that corresponds to the normalized value of 1.0. ...
Portable fixed-width integer types.
#define PTEX_NAMESPACE_END
const char * EdgeFilterModeName(EdgeFilterMode m)
Look up name of given edge filter mode.
bool hasEdits() const
Determine if face has edits in the file (by checking a flag).
void swap(PtexPtr &p)
Swap pointer values.
std::ostream & operator<<(std::ostream &stream, const String &str)
void clamp(const Res &r)
Clamp the resolution value against the given value.
virtual ~PtexCache()
Destructor not for public use. Use release() instead.
int __structSize
(for internal use only)
bool lerp
Interpolate between mipmap levels.
void ConvertToFloat(float *dst, const void *src, Ptex::DataType dt, int numChannels)
Convert a number of data values from the given data type to float.
EdgeId adjedge(int eid) const
Access an adjacent edge id. The eid value must be 0..3.
const char * MetaDataTypeName(MetaDataType mdt)
Look up name of given meta data type.
General bi-cubic filter (uses sharpness option)
Interface for filtered sampling of ptex data files.