00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _TIL_TextureMap_h_
00035 #define _TIL_TextureMap_h_
00036
00037 #include "TIL_API.h"
00038 #include <iostream.h>
00039 #include <UT/UT_Vector4.h>
00040 #include <UT/UT_FilterType.h>
00041 #include <UT/UT_String.h>
00042 #include <IMG/IMG_FileTypes.h>
00043
00044 class TIL_Raster;
00045 class TIL_TextureMap;
00046 class IMG_TTFilterInfo;
00047 class IMG_FileTTMap;
00048 class UT_Vector3;
00049 class UT_Options;
00050 class ut_Map;
00051 class UT_Filter;
00052 class UT_OpCaller;
00053
00054
00055
00056
00057
00058 typedef enum {
00059 TIL_BUMP_PRECOMPUTE,
00060 TIL_BUMP_COMPUTE_R,
00061 TIL_BUMP_COMPUTE_G,
00062 TIL_BUMP_COMPUTE_B,
00063 TIL_BUMP_COMPUTE_A,
00064 TIL_BUMP_COMPUTE_LUM
00065 } TIL_BUMP_COMPUTE_TYPE;
00066
00067
00068
00069 typedef enum {
00070 IMG_DEEP_DISCRETE = 0,
00071 IMG_DEEP_LINEAR = 1
00072 } IMG_DEEP_INTERP;
00073
00074
00075
00076 typedef void (*TIL_COLORLUF)(const TIL_TextureMap *map, void *data,
00077 float u, float v, float *result, int validate);
00078 typedef void (*TIL_AACOLORLUF)(const TIL_TextureMap *map, void *data,
00079 float u[4], float v[4], float *result,
00080 int ns, int);
00081 typedef void (*TIL_DEPTHLUF)(const TIL_TextureMap *map, void *data,
00082 float u, float v, float *result,
00083 float farVal, int validate);
00084 typedef void (*TIL_BUMPLUF)(const TIL_TextureMap *map, void *data,
00085 float u, float v, float *dx, float *dy,
00086 int validate);
00087
00088
00089 typedef void *(*TIL_AllocateFunc)(int size);
00090 typedef void (*TIL_FreeFunc)(void *data);
00091 typedef int (*TIL_TexRenderIndexFunc)();
00092 typedef void (*TIL_TexRenderAllocateFunc)(int idx, TIL_Raster *rp);
00093 typedef void (*TIL_TexRenderFreeFunc)(int idx);
00094
00095 class TIL_API TIL_TextureMapStat {
00096 public:
00097 const char *myFilename;
00098 int myXres, myYres;
00099 int myRampNodes;
00100 int myImageCount;
00101 int myMemory;
00102 int myOwnership;
00103 };
00104
00105
00106
00107
00108
00109 class TIL_API TIL_TextureCache
00110 {
00111 public:
00112
00113
00114 static int getMaxWidth(void);
00115 static int getMaxHeight(void);
00116 static void setMaxSize(int w=256, int h=256);
00117
00118
00119
00120 static int getCacheSize(void);
00121 static void setCacheSize(int size=100);
00122
00123
00124 static int getCacheMemSize();
00125 static void setCacheMemSize(int sizeinmb);
00126
00127
00128
00129
00130 static int getImageCount();
00131 static int getImageStat(TIL_TextureMapStat stats[]);
00132
00133
00134 static int64 getMemoryUsage();
00135
00136
00137
00138
00139 static int getVersion();
00140
00141
00142
00143
00144 static void clearCache(int only_out_of_date=0);
00145
00146
00147
00148 static void clearCache(const char *mapname);
00149
00150
00151
00152
00153
00154 static int getAutoFlush(void);
00155 static void setAutoFlush(int onOff);
00156
00157
00158
00159 static void setVerbose(ostream *os);
00160
00161
00162
00163 static void setRenderAllocator(TIL_TexRenderIndexFunc mapper,
00164 TIL_TexRenderAllocateFunc allocfunc,
00165 TIL_TexRenderFreeFunc freefunc);
00166
00167
00168
00169 static void rasterDied(TIL_Raster *raster);
00170 static void imageDataDied(void *imagedata);
00171
00172
00173
00174
00175 static void clearRenderIndices();
00176
00177
00178
00179 static void setRATConvert(bool on);
00180 static bool getRATConvert();
00181
00182 };
00183
00184
00185 class TIL_API TIL_TextureMap {
00186 public:
00187 TIL_TextureMap(const char *mapname = 0, const char *relativeTo = 0,
00188 TIL_Raster *rp = 0);
00189 virtual ~TIL_TextureMap();
00190
00191 void setOpCaller(UT_OpCaller *c) { myCaller = c; }
00192 void setMap(const char *name, const char *relativeTo,
00193 TIL_Raster *rp = 0, bool always_resolve = true);
00194
00195
00196 void setRenderFlag(int on) { myRenderFlag = on; }
00197
00198 void clearRaster();
00199 void forceReload(void);
00200 const char *getMap(void) const;
00201 TIL_Raster *getOGLRaster();
00202 const UT_Options *getTextureOptions() const;
00203 int getRenderIndex();
00204 void clearRenderIndex();
00205 int queryCurrentRenderIndex() const;
00206 int getIdealSamples(float du, float dv);
00207 void getResolution(int &x, int &y);
00208 int getNChannels() const;
00209
00210
00211 void setColorChannelName(const char *name);
00212 const char *getColorChannelName() const;
00213
00214 void setFilter(UT_FilterType filter, float xw, float yw);
00215 void setXFilter(UT_FilterType filter);
00216 void setYFilter(UT_FilterType filter);
00217 void setFilterWidths(float xwidth, float ywidth);
00218 void setFilterBlurs(float xblur, float yblur);
00219 void setMipInterpolate(int onoff);
00220 void setWrapMode(UT_FilterWrap uwrap, UT_FilterWrap vwrap,
00221 const UT_Vector4 &border);
00222 void setDeepInterp(IMG_DEEP_INTERP interp);
00223 void setZSkew(float zskew);
00224
00225
00226 const UT_Filter *getXFilter() const { return myXFilter; };
00227 const UT_Filter *getYFilter() const { return myYFilter; };
00228 float getXFilterWidth() const { return myFilterX; }
00229 float getYFilterWidth() const { return myFilterY; }
00230
00231
00232
00233 void setColorLookup(int nointerp = 0, int needAlpha = 1)
00234 {
00235 myInterpRequired = !nointerp;
00236 myAlphaRequired = needAlpha;
00237 myColorLookup = 0;
00238 myAAColorLookup = 0;
00239 }
00240 void setBumpLookup(int interp = 1,
00241 TIL_BUMP_COMPUTE_TYPE type=TIL_BUMP_PRECOMPUTE)
00242 {
00243 myInterpRequired = !interp;
00244 myBumpType = type;
00245 myBumpLookup = 0;
00246 }
00247
00248
00249
00250 void setColorModel(int abgr=0);
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263 UT_FilterWrap getUWrap() const { return myUWrap; }
00264 UT_FilterWrap getVWrap() const { return myVWrap; }
00265 const UT_Vector4 &getBorderColor() const { return myBorderColor; }
00266 const UT_Vector4 &getBorderBase() const { return myBaseBorder; }
00267
00268
00269
00270 bool isDefault() const;
00271 int isRAT() const;
00272 int isDSM() const;
00273
00274 void colorLookup(float u, float v, UT_Vector4 &clr,
00275 int validate=1) const;
00276 void colorLookup(float u[4], float v[4], int maxsamples,
00277 UT_Vector4 &clr, int validate=1) const;
00278 float depthLookup(float u, float v, float farValue=1E6,
00279 int validate=1) const;
00280 void bumpLookup(float u, float v,
00281 float *du, float *dv, int validate=1) const;
00282
00283 void envLookup(const UT_Vector3 &R, UT_Vector4 &clr,
00284 float uscale=1, float vscale=1,
00285 int validate=1) const;
00286
00287 void envLookup(const UT_Vector3 &r00, const UT_Vector3 &r10,
00288 const UT_Vector3 &r11, const UT_Vector3 &r01,
00289 UT_Vector4 &clr, int maxsamples,
00290 float uscale=1, float vscale=1,
00291 int validate=1) const;
00292
00293
00294
00295 void deepLookup(UT_Vector3 &clr,
00296 const UT_Vector3 &p,
00297 const UT_Vector3 &du,
00298 const UT_Vector3 &dv,
00299 float quality, int maxsamples,
00300 int validate);
00301 void deepLookup(UT_Vector3 &clr,
00302 const UT_Vector3 &p,
00303 float du, float dv,
00304 float quality, int maxsamples,
00305 int validate);
00306
00307 const IMG_TTFilterInfo &getFilterInfo() const { return *myRATFilter; }
00308
00309
00310 void adjustScales(float scale);
00311 TIL_BUMP_COMPUTE_TYPE getBumpCompute() const
00312 {
00313 return myBumpType;
00314 }
00315
00316 int getInterpRequired() const { return myInterpRequired; }
00317 int getAlphaRequired() const { return myAlphaRequired; }
00318
00319
00320
00321 bool isVolatileTexture() const;
00322
00323
00324
00325 bool hasTextureChanged(const TIL_Raster **newraster = 0);
00326
00327
00328 IMG_FileTTMap *getRawTexture();
00329
00330
00331 int getColorChannelIndex(IMG_FileTTMap *map) const;
00332
00333 private:
00334 float shadowLookup(const UT_Vector3 &p,
00335 const UT_Vector3 &du,
00336 const UT_Vector3 &dv,
00337 float quality, int maxsamples,
00338 int validate) const;
00339
00340
00341
00342 float shadowLookup(const UT_Vector3 &Ps,
00343 float du, float dv,
00344 float quality, int maxsamples,
00345 int validate) const;
00346
00347 private:
00348 ut_Map *myMap;
00349 UT_OpCaller *myCaller;
00350 TIL_COLORLUF myColorLookup;
00351 TIL_AACOLORLUF myAAColorLookup;
00352 TIL_DEPTHLUF myDepthLookup;
00353 TIL_BUMPLUF myBumpLookup;
00354
00355 IMG_TTFilterInfo *myRATFilter;
00356 UT_Filter *myXFilter, *myYFilter;
00357 float myFilterX, myFilterY;
00358 UT_FilterType myXFilterType, myYFilterType;
00359 UT_Vector4 myBorderColor;
00360 UT_Vector4 myBaseBorder;
00361
00362 int myInterpRequired, myAlphaRequired;
00363 TIL_BUMP_COMPUTE_TYPE myBumpType;
00364 UT_FilterWrap myUWrap, myVWrap;
00365 UT_String myColorChannel;
00366 int myRenderFlag;
00367 short myBorderScaled;
00368 friend class ut_Map;
00369 };
00370
00371
00372 #endif