00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef RE_OGLTexture_h
00022 #define RE_OGLTexture_h
00023
00024 #include "RE_API.h"
00025 #include "RE_Types.h"
00026 #include "RE_TextureTypes.h"
00027 #include "RE_TextureFilter.h"
00028 #include <UT/UT_Rect.h>
00029 #include <IMG/IMG_FileTypes.h>
00030 class RE_Render;
00031
00032
00033 class RE_API RE_OGLTexture
00034 {
00035 public:
00036 virtual ~RE_OGLTexture();
00037
00038 virtual const char *className() const;
00039
00040
00041 RE_TextureDimension getTextureType() const;
00042
00043
00044 virtual bool hasTextureSupport(RE_Render *r);
00045
00046
00047 virtual bool hasMipMapSupport(RE_Render *);
00048
00049
00050 virtual int getMaxTextureSize(RE_Render *r) = 0;
00051
00052
00053 virtual int getMaxTextureIndex(RE_Render *r);
00054
00055
00056 bool hasAutoCompression(RE_Render *r);
00057
00058
00059
00060 static bool canUseInFixedFunction(RE_TextureDimension t);
00061
00062
00063 virtual bool isValid() const;
00064
00065
00066 RE_TextureID getID() const;
00067
00068
00069 unsigned long getVersion() const { return myVersion; }
00070
00071
00072 virtual void free();
00073
00074
00075 static RE_OGLTexture *newTexture(RE_TextureDimension t);
00076
00077
00078 RE_OGLTexture *copyAttributes() const;
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 void setDataType(RE_TextureDataType type);
00090 RE_TextureDataType getDataType() const;
00091
00092
00093
00094 void setFormat(RE_GPUType data, int vectorsize);
00095 RE_GPUType getFormatType() const;
00096 int getFormatSize() const;
00097
00098
00099
00100 void setClientFormat(RE_GPUType data, int vectorsize);
00101
00102
00103
00104
00105
00106 void setCompression(RE_TextureCompress comp,
00107 bool auto_compress);
00108 RE_TextureCompress getCompression() const;
00109 bool getAutoCompression() const;
00110
00111
00112
00113 void setResolution(int w, int h = 1, int depth = 1,
00114 bool force_pow2 = false);
00115 int getWidth() const;
00116 int getHeight() const;
00117 int getDepth() const;
00118
00119
00120
00121 int getGLWidth() const;
00122 int getGLHeight() const;
00123 int getGLDepth() const;
00124
00125
00126
00127 float getTexS() const;
00128 float getTexT() const;
00129 float getTexR() const;
00130
00131
00132 virtual void setSamples(int samples);
00133 int getSamples() const;
00134
00135
00136
00137
00138
00139 void setMipMap(bool m, bool autogen = true);
00140 bool getMipMap() const;
00141 bool getMipMapAutoGenerate() const;
00142
00143
00144
00145 bool isMipMapped() const;
00146
00147
00148
00149
00150
00151 bool queryTextureStats(RE_Render *r,
00152 int *width, int *height, int *depth,
00153 int *format);
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 virtual void setTexture(RE_Render *r, const void *data,
00174 int level=-1, int index=-1,
00175 bool proxy=false) = 0;
00176
00177
00178 int64 getSizeBytes() const;
00179
00180
00181
00182 int64 getScanBytes() const;
00183 int64 getScanBytes(int sublen) const;
00184
00185
00186 int64 getBitsPerPixel() const;
00187
00188
00189 int64 getTextureSize() const;
00190
00191
00192
00193
00194
00195 virtual void setSubTexture(RE_Render *r,
00196 const void *data, int level,
00197 int xoffset, int xsize,
00198 int yoffset=0, int ysize=1,
00199 int zoffset=0, int zsize=1) = 0;
00200
00201
00202
00203
00204
00205 virtual void getTexture(RE_Render *r, void *data,
00206 int level=0, int index=-1);
00207
00208
00209
00210
00211 virtual bool copyFromBuffer(RE_Render *r, int x, int y, int z = 0,
00212 const UT_DimRect *bufferarea = NULL,
00213 int level = 0) = 0;
00214
00215
00216
00217
00218
00219 void setMinFilter( RE_Render *r, RE_TexFiltType t );
00220 RE_TexFiltType getMinFilter() const;
00221
00222
00223 void setMagFilter( RE_Render *r, RE_TexFiltType t );
00224 RE_TexFiltType getMagFilter() const;
00225
00226 void setMaxAnisotropy(RE_Render *r, int atf);
00227 int getMaxAnisotropy() const;
00228
00229
00230 void setTextureWrap(RE_Render *r,
00231 RE_TexClampType clamp_s,
00232 RE_TexClampType clamp_t = RE_CLAMP_EDGE,
00233 RE_TexClampType clamp_r = RE_CLAMP_EDGE);
00234 bool getWrapS() const;
00235 bool getWrapT() const;
00236 bool getWrapR() const;
00237
00238
00239 void setTextureFilter(RE_Render *r,
00240 const RE_TextureFilter &filter);
00241
00242
00243
00244
00245
00246
00247 void setDepthCompareMode(RE_Render *r, bool enabled,
00248 RE_TextureCompare compare
00249 = RE_TEXTURE_COMPARE_LESS_EQUAL);
00250
00251 void setAlphaInfo(IMG_FileAlphaInfo a) { myAlphaInfo = a; }
00252 IMG_FileAlphaInfo getAlphaInfo() const { return myAlphaInfo;}
00253
00254 static int getGLTextureType(RE_TextureDimension t);
00255 static RE_OGLTexture *findTextureWithID(RE_TextureID id);
00256
00257 void inUse(bool inc);
00258 bool inUse() const { return myUsage>0; }
00259
00260
00261 void setCached(bool cached,const char *mapname);
00262 bool isCached() const;
00263 void setVersion(unsigned long v) { myVersion = v; }
00264
00265
00266
00267
00268 bool writeToFile(RE_Render *r, const char *name,
00269 int level = 0);
00270
00271
00272
00273 RE_OGLTexture * expandMultisampleTexture(RE_Render *r);
00274
00275 static void adjustPow2(int &w, int &h, int &d);
00276 protected:
00277
00278 RE_OGLTexture(RE_TextureDimension d);
00279
00280 void deleteObject();
00281 void setupTextureParameters(RE_Render *r, bool force);
00282 void validate();
00283
00284
00285
00286 virtual int getGLType() const = 0;
00287 virtual int getGLProxy() const = 0;
00288 virtual int getGLTypeBinding() const = 0;
00289 virtual int getGLCreateType() const { return getGLType(); }
00290
00291
00292 virtual bool buildMipMaps(RE_Render *r, const void *data) = 0;
00293
00294 bool createTextureID();
00295
00296 RE_GPUType getClientType() const;
00297
00298
00299
00300 void * compressTexData(const void *src, int &w, int &h);
00301 void determineCompressionInternal();
00302 void determineTextureSize(RE_Render *r);
00303
00304
00305 RE_TextureID myID;
00306 int myGLType;
00307 int myGLFormat;
00308 int myGLInternal;
00309 int myGLWidth;
00310 int myGLHeight;
00311 int myGLDepth;
00312 bool myCanMipMap;
00313
00314 void updateTextureWrap(RE_Render *r, bool force);
00315 void updateFilters(RE_Render *r, bool force);
00316
00317 private:
00318 void buildFormatTable();
00319
00320
00321 RE_TextureDataType myTextureDataType;
00322 RE_GPUType myDataType;
00323 RE_GPUType myClientType;
00324 RE_TextureDimension myTexDimension;
00325 short int myVectorSize;
00326 short int myUsage;
00327 int myWidth;
00328 int myHeight;
00329 int myDepth;
00330 RE_TextureCompress myCompression;
00331 bool myMipMapFlag;
00332 bool myMipMapAutoGenFlag;
00333 bool myAutoCompressFlag;
00334 bool myCompressFlag;
00335 bool myValidFlag;
00336 bool myCachedFlag;
00337 RE_TextureFilter myCurrentFilterState;
00338 RE_TextureFilter myFilter;
00339 char *myName;
00340 unsigned long myVersion;
00341 int64 myTexSize;
00342 IMG_FileAlphaInfo myAlphaInfo;
00343
00344 protected:
00345 int mySamples;
00346 friend class RE_OGLRender;
00347 friend class RE_OGLFramebuffer;
00348 };
00349
00350 inline RE_TextureDimension
00351 RE_OGLTexture::getTextureType() const
00352 {
00353 return myTexDimension;
00354 }
00355
00356 inline void
00357 RE_OGLTexture::setDataType(RE_TextureDataType type)
00358 {
00359 myTextureDataType = type;
00360 }
00361
00362 inline RE_TextureDataType
00363 RE_OGLTexture::getDataType() const
00364 {
00365 return myTextureDataType;
00366 }
00367
00368 inline bool
00369 RE_OGLTexture::isValid() const
00370 {
00371 return myID != 0 && myValidFlag;
00372 }
00373
00374 inline RE_TextureID
00375 RE_OGLTexture::getID() const
00376 {
00377 return myID;
00378 }
00379
00380 inline RE_GPUType
00381 RE_OGLTexture::getFormatType() const
00382 {
00383 return myDataType;
00384 }
00385
00386 inline RE_GPUType
00387 RE_OGLTexture::getClientType() const
00388 {
00389 return myClientType;
00390 }
00391
00392 inline int
00393 RE_OGLTexture::getFormatSize() const
00394 {
00395 return myVectorSize;
00396 }
00397
00398 inline int
00399 RE_OGLTexture::getWidth() const
00400 {
00401 return myWidth;
00402 }
00403
00404 inline int
00405 RE_OGLTexture::getHeight() const
00406 {
00407 return myHeight;
00408 }
00409
00410 inline int
00411 RE_OGLTexture::getDepth() const
00412 {
00413 return myDepth;
00414 }
00415
00416 inline int
00417 RE_OGLTexture::getGLWidth() const
00418 {
00419 return myGLWidth;
00420 }
00421
00422 inline int
00423 RE_OGLTexture::getGLHeight() const
00424 {
00425 return myGLHeight;
00426 }
00427
00428 inline int
00429 RE_OGLTexture::getGLDepth() const
00430 {
00431 return myGLDepth;
00432 }
00433
00434 inline RE_TextureCompress
00435 RE_OGLTexture::getCompression() const
00436 {
00437 return myCompression;
00438 }
00439
00440 inline bool
00441 RE_OGLTexture::getAutoCompression() const
00442 {
00443 return myAutoCompressFlag;
00444 }
00445
00446 inline bool
00447 RE_OGLTexture::hasMipMapSupport(RE_Render *)
00448 {
00449 return true;
00450 }
00451
00452 inline bool
00453 RE_OGLTexture::getMipMap() const
00454 {
00455 return myMipMapFlag;
00456 }
00457
00458 inline bool
00459 RE_OGLTexture::isMipMapped() const
00460 {
00461 return myMipMapFlag && myCanMipMap;
00462 }
00463
00464 inline bool
00465 RE_OGLTexture::getMipMapAutoGenerate() const
00466 {
00467 return myMipMapAutoGenFlag;
00468 }
00469
00470 inline RE_TexFiltType
00471 RE_OGLTexture::getMinFilter() const
00472 {
00473 return myCurrentFilterState.getMinFilter();
00474 }
00475
00476 inline RE_TexFiltType
00477 RE_OGLTexture::getMagFilter() const
00478 {
00479 return myCurrentFilterState.getMagFilter();
00480 }
00481
00482 inline int
00483 RE_OGLTexture::getMaxAnisotropy() const
00484 {
00485 return myCurrentFilterState.getMaxAnisotropy();
00486 }
00487
00488 inline bool
00489 RE_OGLTexture::getWrapS() const
00490 {
00491 return myCurrentFilterState.getWrapS();
00492 }
00493
00494 inline bool
00495 RE_OGLTexture::getWrapT() const
00496 {
00497 return myCurrentFilterState.getWrapT();
00498 }
00499
00500 inline bool
00501 RE_OGLTexture::getWrapR() const
00502 {
00503 return myCurrentFilterState.getWrapR();
00504 }
00505
00506 inline const char *
00507 RE_OGLTexture::className() const
00508 {
00509 return "RE_OGLTexture";
00510 }
00511
00512 inline bool
00513 RE_OGLTexture::hasTextureSupport(RE_Render *r)
00514 {
00515 return true;
00516 }
00517
00518 inline void
00519 RE_OGLTexture::validate()
00520 {
00521 myValidFlag = true;
00522 }
00523
00524 inline int
00525 RE_OGLTexture::getMaxTextureIndex(RE_Render *)
00526 {
00527 return 1;
00528 }
00529
00530 inline float
00531 RE_OGLTexture::getTexS() const
00532 {
00533 return float(myWidth) / float(myGLWidth);
00534 }
00535
00536 inline float
00537 RE_OGLTexture::getTexT() const
00538 {
00539 return float(myHeight) / float(myGLHeight);
00540 }
00541
00542 inline float
00543 RE_OGLTexture::getTexR() const
00544 {
00545 return float(myDepth) / float(myGLDepth);
00546 }
00547
00548 inline bool
00549 RE_OGLTexture::isCached() const
00550 {
00551 return myCachedFlag;
00552 }
00553
00554 inline int64
00555 RE_OGLTexture::getTextureSize() const
00556 {
00557 return myTexSize;
00558 }
00559
00560 inline int64
00561 RE_OGLTexture::getScanBytes() const
00562 {
00563 return getScanBytes(myGLWidth);
00564 }
00565
00566
00567 #endif