00001
00033 #ifndef LL_LLIMAGEGL_H
00034 #define LL_LLIMAGEGL_H
00035
00036 #include "llimage.h"
00037
00038 #include "llgltypes.h"
00039 #include "llmemory.h"
00040
00041
00042
00043 class LLImageGL : public LLRefCount
00044 {
00045 public:
00046
00047 static S32 dataFormatBits(S32 dataformat);
00048 static S32 dataFormatBytes(S32 dataformat, S32 width, S32 height);
00049 static S32 dataFormatComponents(S32 dataformat);
00050
00051
00052
00053 static void bindExternalTexture( LLGLuint gl_name, S32 stage, LLGLenum bind_target);
00054 static void unbindTexture(S32 stage, LLGLenum target);
00055 static void unbindTexture(S32 stage);
00056
00057
00058 static void updateStats(F32 current_time);
00059
00060
00061 static void destroyGL(BOOL save_state = TRUE);
00062 static void restoreGL();
00063
00064
00065 static S32 updateBoundTexMem(const S32 delta);
00066
00067 static bool checkSize(S32 width, S32 height);
00068
00069
00070
00071 static BOOL create(LLPointer<LLImageGL>& dest, BOOL usemipmaps = TRUE);
00072 static BOOL create(LLPointer<LLImageGL>& dest, U32 width, U32 height, U8 components, BOOL usemipmaps = TRUE);
00073 static BOOL create(LLPointer<LLImageGL>& dest, const LLImageRaw* imageraw, BOOL usemipmaps = TRUE);
00074
00075 public:
00076 LLImageGL(BOOL usemipmaps = TRUE);
00077 LLImageGL(U32 width, U32 height, U8 components, BOOL usemipmaps = TRUE);
00078 LLImageGL(const LLImageRaw* imageraw, BOOL usemipmaps = TRUE);
00079
00080 protected:
00081 virtual ~LLImageGL();
00082 BOOL bindTextureInternal(const S32 stage = 0) const;
00083
00084 public:
00085 virtual void dump();
00086 virtual BOOL bind(const S32 stage = 0) const;
00087
00088 void setSize(S32 width, S32 height, S32 ncomponents);
00089
00090 BOOL createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename = 0);
00091 BOOL createGLTexture(S32 discard_level, const U8* data, BOOL data_hasmips = FALSE, S32 usename = 0);
00092 void setImage(const LLImageRaw* imageraw);
00093 void setImage(const U8* data_in, BOOL data_hasmips = FALSE);
00094 BOOL setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height);
00095 BOOL setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height);
00096 BOOL setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_pos, S32 width, S32 height);
00097 BOOL setDiscardLevel(S32 discard_level);
00098
00099 BOOL readBackRaw(S32 discard_level, LLImageRaw* imageraw, bool compressed_ok);
00100 void destroyGLTexture();
00101
00102 void setClamp(BOOL clamps, BOOL clampt);
00103 void setMipFilterNearest(BOOL nearest, BOOL min_nearest = FALSE);
00104 void setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format = 0, BOOL swap_bytes = FALSE);
00105 void dontDiscard() { mDontDiscard = 1; }
00106
00107 S32 getDiscardLevel() const { return mCurrentDiscardLevel; }
00108 S32 getMaxDiscardLevel() const { return mMaxDiscardLevel; }
00109
00110 S32 getWidth(S32 discard_level = -1) const;
00111 S32 getHeight(S32 discard_level = -1) const;
00112 U8 getComponents() const { return mComponents; }
00113 S32 getBytes(S32 discard_level = -1) const;
00114 S32 getMipBytes(S32 discard_level = -1) const;
00115 BOOL getBoundRecently() const;
00116 LLGLenum getPrimaryFormat() const { return mFormatPrimary; }
00117
00118 BOOL getClampS() const { return mClampS; }
00119 BOOL getClampT() const { return mClampT; }
00120 BOOL getMipFilterNearest() const { return mMipFilterNearest; }
00121
00122 BOOL getHasGLTexture() const { return mTexName != 0; }
00123 LLGLuint getTexName() const { return mTexName; }
00124
00125 BOOL getIsResident(BOOL test_now = FALSE);
00126
00127 void setTarget(const LLGLenum target, const LLGLenum bind_target);
00128
00129 BOOL getUseMipMaps() const { return mUseMipMaps; }
00130 void setUseMipMaps(BOOL usemips) { mUseMipMaps = usemips; }
00131 BOOL getUseDiscard() const { return mUseMipMaps && !mDontDiscard; }
00132 BOOL getDontDiscard() const { return mDontDiscard; }
00133
00134 protected:
00135 void init(BOOL usemipmaps);
00136 virtual void cleanup();
00137
00138 public:
00139
00140 S32 mTextureMemory;
00141 mutable F32 mLastBindTime;
00142
00143 private:
00144 LLPointer<LLImageRaw> mSaveData;
00145 S8 mUseMipMaps;
00146 S8 mHasMipMaps;
00147 S8 mHasExplicitFormat;
00148 S8 mAutoGenMips;
00149
00150 protected:
00151 LLGLenum mTarget;
00152 LLGLenum mBindTarget;
00153
00154 LLGLuint mTexName;
00155
00156 LLGLboolean mIsResident;
00157
00158 U16 mWidth;
00159 U16 mHeight;
00160
00161 S8 mComponents;
00162 S8 mMaxDiscardLevel;
00163 S8 mCurrentDiscardLevel;
00164 S8 mDontDiscard;
00165
00166 S8 mClampS;
00167 S8 mClampT;
00168 S8 mMipFilterNearest;
00169
00170 LLGLint mFormatInternal;
00171 LLGLenum mFormatPrimary;
00172 LLGLenum mFormatType;
00173 BOOL mFormatSwapBytes;
00174
00175
00176 public:
00177 static std::set<LLImageGL*> sImageList;
00178 static S32 sCount;
00179
00180 static F32 sLastFrameTime;
00181
00182 static LLGLuint sCurrentBoundTextures[MAX_GL_TEXTURE_UNITS];
00183
00184
00185 static S32 sGlobalTextureMemory;
00186 static S32 sBoundTextureMemory;
00187 static S32 sCurBoundTextureMemory;
00188
00189 static BOOL sGlobalUseAnisotropic;
00190
00191 #if DEBUG_MISS
00192 BOOL mMissed;
00193 BOOL getMissed() const { return mMissed; };
00194 #else
00195 BOOL getMissed() const { return FALSE; };
00196 #endif
00197 };
00198
00199
00200 class LLImageProviderInterface
00201 {
00202 public:
00203 LLImageProviderInterface() {};
00204 virtual ~LLImageProviderInterface() {};
00205
00206 virtual LLImageGL* getUIImageByID(const LLUUID& id, BOOL clamped = TRUE) = 0;
00207 };
00208
00209 #endif // LL_LLIMAGEGL_H