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
00028 class RE_Render;
00029
00030
00031 class RE_API RE_OGLTexture
00032 {
00033 public:
00034 RE_OGLTexture();
00035 virtual ~RE_OGLTexture();
00036
00037 virtual const char *className() const;
00038
00039
00040 virtual RE_TextureDimension getTextureType() const = 0;
00041
00042
00043 virtual bool hasTextureSupport(RE_Render *r);
00044
00045
00046 virtual bool hasMipMapSupport(RE_Render *);
00047
00048
00049 virtual int getMaxTextureSize(RE_Render *r) = 0;
00050
00051
00052 virtual int getMaxTextureIndex(RE_Render *r);
00053
00054
00055 bool hasAutoCompression(RE_Render *r);
00056
00057
00058 virtual bool isValid() const;
00059
00060
00061 RE_TextureID getID() const;
00062
00063
00064 virtual void free(RE_Render *r);
00065
00066
00067
00068 void assignToUnit(RE_Render *r,
00069 int texunit,
00070 RE_TextureMode mode = RE_TEXTURE_UNKNOWN);
00071
00072
00073
00074
00075
00076
00077
00078 void setFormat(RE_GPUType data, int vectorsize);
00079 RE_GPUType getFormatType() const;
00080 int getFormatSize() const;
00081
00082
00083
00084
00085
00086 void setCompression(RE_TextureCompress comp,
00087 bool auto_compress);
00088 RE_TextureCompress getCompression() const;
00089 bool getAutoCompression() const;
00090
00091
00092
00093 void setResolution(int w, int h = 1, int depth = 1);
00094 int getWidth() const;
00095 int getHeight() const;
00096 int getDepth() const;
00097
00098
00099
00100 int getGLWidth() const;
00101 int getGLHeight() const;
00102 int getGLDepth() const;
00103
00104
00105
00106
00107
00108 void setMipMap(bool m, bool autogen = true);
00109 bool getMipMap() const;
00110 bool getMipMapAutoGenerate() const;
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 virtual void setTexture(RE_Render *r, const void *data,
00127 int level=0, int index=-1) = 0;
00128
00129
00130 int64 getSizeBytes() const;
00131
00132
00133 int64 getScanBytes() const;
00134
00135
00136
00137
00138
00139 virtual void setSubTexture(RE_Render *r,
00140 void *data, int level,
00141 int xoffset, int xsize,
00142 int yoffset=0, int ysize=1,
00143 int zoffset=0, int zsize=1) = 0;
00144
00145
00146
00147 virtual void getTexture(RE_Render *r, void *data,
00148 int level=0, int index=-1);
00149
00150
00151
00152
00153
00154 void setMinFilter( RE_Render *r, RE_TexFiltType t );
00155 RE_TexFiltType getMinFilter() const;
00156
00157
00158 void setMagFilter( RE_Render *r, RE_TexFiltType t );
00159 RE_TexFiltType getMagFilter() const;
00160
00161
00162 void setTextureWrap(RE_Render *r,
00163 bool clamp_x,
00164 bool clamp_y = true,
00165 bool clamp_z = true);
00166 bool getWrapX() const;
00167 bool getWrapY() const;
00168 bool getWrapZ() const;
00169
00170
00171 protected:
00172 void deleteObject(RE_Render *r);
00173 void adjustPow2(int &w, int &h, int &d);
00174 void setupTextureParameters(RE_Render *r);
00175 void validate();
00176
00177 virtual int getGLType() const = 0;
00178 virtual int getGLTypeBinding() const = 0;
00179
00180
00181 virtual void buildMipMaps(const void *data) = 0;
00182 void pushPixelAlignment(bool write, int &pixel);
00183 void popPixelAlignment(bool write, int pixel);
00184 bool createTextureID();
00185
00186
00187
00188 void * compressTexData(const void *src, int w, int h);
00189 void determineCompressionInternal();
00190
00191
00192 RE_TextureID myID;
00193 int myGLType;
00194 int myGLFormat;
00195 int myGLInternal;
00196 int myGLWidth;
00197 int myGLHeight;
00198 int myGLDepth;
00199
00200 private:
00201
00202
00203 RE_GPUType myDataType;
00204 int myVectorSize;
00205 int myWidth;
00206 int myHeight;
00207 int myDepth;
00208 RE_TexFiltType myMinFilter;
00209 RE_TexFiltType myMagFilter;
00210 RE_TextureCompress myCompression;
00211 bool myMipMapFlag;
00212 bool myMipMapAutoGenFlag;
00213 bool myWrap[3];
00214 bool myAutoCompressFlag;
00215 bool myCompressFlag;
00216 bool myValidFlag;
00217 };
00218
00219
00220
00221 inline bool
00222 RE_OGLTexture::isValid() const
00223 {
00224 return myID != 0 && myValidFlag;
00225 }
00226
00227 inline RE_TextureID
00228 RE_OGLTexture::getID() const
00229 {
00230 return myID;
00231 }
00232
00233 inline RE_GPUType
00234 RE_OGLTexture::getFormatType() const
00235 {
00236 return myDataType;
00237 }
00238
00239 inline int
00240 RE_OGLTexture::getFormatSize() const
00241 {
00242 return myVectorSize;
00243 }
00244
00245 inline int
00246 RE_OGLTexture::getWidth() const
00247 {
00248 return myWidth;
00249 }
00250
00251 inline int
00252 RE_OGLTexture::getHeight() const
00253 {
00254 return myHeight;
00255 }
00256
00257 inline int
00258 RE_OGLTexture::getDepth() const
00259 {
00260 return myDepth;
00261 }
00262
00263 inline int
00264 RE_OGLTexture::getGLWidth() const
00265 {
00266 return myGLWidth;
00267 }
00268
00269 inline int
00270 RE_OGLTexture::getGLHeight() const
00271 {
00272 return myGLHeight;
00273 }
00274
00275 inline int
00276 RE_OGLTexture::getGLDepth() const
00277 {
00278 return myGLDepth;
00279 }
00280
00281 inline RE_TextureCompress
00282 RE_OGLTexture::getCompression() const
00283 {
00284 return myCompression;
00285 }
00286
00287 inline bool
00288 RE_OGLTexture::getAutoCompression() const
00289 {
00290 return myAutoCompressFlag;
00291 }
00292
00293 inline bool
00294 RE_OGLTexture::hasMipMapSupport(RE_Render *)
00295 {
00296 return true;
00297 }
00298
00299 inline bool
00300 RE_OGLTexture::getMipMap() const
00301 {
00302 return myMipMapFlag;
00303 }
00304
00305 inline bool
00306 RE_OGLTexture::getMipMapAutoGenerate() const
00307 {
00308 return myMipMapAutoGenFlag;
00309 }
00310
00311 inline RE_TexFiltType
00312 RE_OGLTexture::getMinFilter() const
00313 {
00314 return myMinFilter;
00315 }
00316
00317 inline RE_TexFiltType
00318 RE_OGLTexture::getMagFilter() const
00319 {
00320 return myMagFilter;
00321 }
00322
00323 inline bool
00324 RE_OGLTexture::getWrapX() const
00325 {
00326 return myWrap[0];
00327 }
00328
00329 inline bool
00330 RE_OGLTexture::getWrapY() const
00331 {
00332 return myWrap[1];
00333 }
00334
00335 inline bool
00336 RE_OGLTexture::getWrapZ() const
00337 {
00338 return myWrap[2];
00339 }
00340
00341 inline const char *
00342 RE_OGLTexture::className() const
00343 {
00344 return "RE_OGLTexture";
00345 }
00346
00347 inline bool
00348 RE_OGLTexture::hasTextureSupport(RE_Render *r)
00349 {
00350 return true;
00351 }
00352
00353 inline void
00354 RE_OGLTexture::validate()
00355 {
00356 myValidFlag = true;
00357 }
00358
00359 inline int
00360 RE_OGLTexture::getMaxTextureIndex(RE_Render *)
00361 {
00362 return 1;
00363 }
00364
00365
00366 #endif