llimagegl.h

Go to the documentation of this file.
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         // Size calculation
00047         static S32 dataFormatBits(S32 dataformat);
00048         static S32 dataFormatBytes(S32 dataformat, S32 width, S32 height);
00049         static S32 dataFormatComponents(S32 dataformat);
00050 
00051         // Wrapper for glBindTexture that keeps LLImageGL in sync.
00052         // Usually you want stage = 0 and bind_target = GL_TEXTURE_2D
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); // Uses GL_TEXTURE_2D (not a default arg to avoid gl.h dependency)
00056 
00057         // needs to be called every frame
00058         static void updateStats(F32 current_time);
00059 
00060         // Save off / restore GL textures
00061         static void destroyGL(BOOL save_state = TRUE);
00062         static void restoreGL();
00063 
00064         // Sometimes called externally for textures not using LLImageGL (should go away...)
00065         static S32 updateBoundTexMem(const S32 delta);
00066 
00067         static bool checkSize(S32 width, S32 height);
00068         
00069         // Not currently necessary for LLImageGL, but required in some derived classes,
00070         // so include for compatability
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();    // debugging info to llinfos
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         // Read back a raw image for this discard level, if it exists
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); // not const
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(); // Clean up the LLImageGL so it can be reinitialized.  Be careful when using this in derived class destructors
00137 
00138 public:
00139         // Various GL/Rendering options
00140         S32 mTextureMemory;
00141         mutable F32  mLastBindTime;     // last time this was bound, by discard level
00142 
00143 private:
00144         LLPointer<LLImageRaw> mSaveData; // used for destroyGL/restoreGL
00145         S8 mUseMipMaps;
00146         S8 mHasMipMaps;
00147         S8 mHasExplicitFormat; // If false (default), GL format is f(mComponents)
00148         S8 mAutoGenMips;
00149         
00150 protected:
00151         LLGLenum mTarget;               // Normally GL_TEXTURE2D, sometimes something else (ex. cube maps)
00152         LLGLenum mBindTarget;   // NOrmally GL_TEXTURE2D, sometimes something else (ex. cube maps)
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;                        // Keep full res version of this image (for UI, etc)
00165 
00166         S8 mClampS;                                     // Need to save clamp state
00167         S8 mClampT;
00168         S8 mMipFilterNearest;           // if TRUE, set magfilter to GL_NEAREST
00169         
00170         LLGLint  mFormatInternal; // = GL internalformat
00171         LLGLenum mFormatPrimary;  // = GL format (pixel data format)
00172         LLGLenum mFormatType;
00173         BOOL     mFormatSwapBytes;// if true, use glPixelStorei(GL_UNPACK_SWAP_BYTES, 1)
00174 
00175         // STATICS
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]; // Currently bound texture ID
00183 
00184         // Global memory statistics
00185         static S32 sGlobalTextureMemory;                // Tracks main memory texmem
00186         static S32 sBoundTextureMemory;                 // Tracks bound texmem for last completed frame
00187         static S32 sCurBoundTextureMemory;              // Tracks bound texmem for current frame
00188 
00189         static BOOL sGlobalUseAnisotropic;
00190 
00191 #if DEBUG_MISS
00192         BOOL mMissed; // Missed on last bind?
00193         BOOL getMissed() const { return mMissed; };
00194 #else
00195         BOOL getMissed() const { return FALSE; };
00196 #endif
00197 };
00198 
00199 //RN: maybe this needs to moved elsewhere?
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

Generated on Thu Jul 1 06:08:43 2010 for Second Life Viewer by  doxygen 1.4.7