aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llrender/llimagegl.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llrender/llimagegl.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/llrender/llimagegl.h204
1 files changed, 204 insertions, 0 deletions
diff --git a/linden/indra/llrender/llimagegl.h b/linden/indra/llrender/llimagegl.h
new file mode 100644
index 0000000..6356703
--- /dev/null
+++ b/linden/indra/llrender/llimagegl.h
@@ -0,0 +1,204 @@
1/**
2 * @file llimagegl.h
3 * @brief Object for managing images and their textures
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28
29#ifndef LL_LLIMAGEGL_H
30#define LL_LLIMAGEGL_H
31
32#include "llimage.h"
33
34#include "llgltypes.h"
35#include "llmemory.h"
36
37//============================================================================
38
39class LLImageGL : public LLThreadSafeRefCount
40{
41public:
42 // Size calculation
43 static S32 dataFormatBits(S32 dataformat);
44 static S32 dataFormatBytes(S32 dataformat, S32 width, S32 height);
45 static S32 dataFormatComponents(S32 dataformat);
46
47 // Wrapper for glBindTexture that keeps LLImageGL in sync.
48 // Usually you want stage = 0 and bind_target = GL_TEXTURE_2D
49 static void bindExternalTexture( LLGLuint gl_name, S32 stage, LLGLenum bind_target);
50 static void unbindTexture(S32 stage, LLGLenum target);
51
52 // needs to be called every frame
53 static void updateStats(F32 current_time);
54
55 // Save off / restore GL textures
56 static void destroyGL(BOOL save_state = TRUE);
57 static void restoreGL();
58
59 // Sometimes called externally for textures not using LLImageGL (should go away...)
60 static S32 updateBoundTexMem(const S32 delta);
61
62 static bool checkSize(S32 width, S32 height);
63
64 // Not currently necessary for LLImageGL, but required in some derived classes,
65 // so include for compatability
66 static BOOL create(LLPointer<LLImageGL>& dest, BOOL usemipmaps = TRUE);
67 static BOOL create(LLPointer<LLImageGL>& dest, U32 width, U32 height, U8 components, BOOL usemipmaps = TRUE);
68 static BOOL create(LLPointer<LLImageGL>& dest, const LLImageRaw* imageraw, BOOL usemipmaps = TRUE);
69
70public:
71 LLImageGL(BOOL usemipmaps = TRUE);
72 LLImageGL(U32 width, U32 height, U8 components, BOOL usemipmaps = TRUE);
73 LLImageGL(const LLImageRaw* imageraw, BOOL usemipmaps = TRUE);
74
75protected:
76 virtual ~LLImageGL();
77 BOOL bindTextureInternal(const S32 stage = 0) const;
78
79public:
80 virtual void dump(); // debugging info to llinfos
81 virtual BOOL bind(const S32 stage = 0) const;
82
83 void setSize(S32 width, S32 height, S32 ncomponents);
84
85 BOOL createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename = 0);
86 BOOL createGLTexture(S32 discard_level, const U8* data, BOOL data_hasmips = FALSE, S32 usename = 0);
87 void setImage(const LLImageRaw* imageraw);
88 void setImage(const U8* data_in, BOOL data_hasmips = FALSE);
89 BOOL setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height);
90 BOOL setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height);
91 BOOL setSubImageFromFrameBuffer(S32 fb_x, S32 fb_y, S32 x_pos, S32 y_pos, S32 width, S32 height);
92 BOOL setDiscardLevel(S32 discard_level);
93 BOOL readBackRaw(S32 discard_level, LLImageRaw* imageraw); // Read back a raw image for this discard level, if it exists
94 void destroyGLTexture();
95
96 void setClamp(BOOL clamps, BOOL clampt);
97 void setMipFilterNearest(BOOL nearest, BOOL min_nearest = FALSE);
98 void setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format = 0, BOOL swap_bytes = FALSE);
99 void dontDiscard() { mDontDiscard = 1; }
100
101 S32 getDiscardLevel() const { return mCurrentDiscardLevel; }
102 S32 getMaxDiscardLevel() const { return mMaxDiscardLevel; }
103
104 S32 getWidth(S32 discard_level = -1) const;
105 S32 getHeight(S32 discard_level = -1) const;
106 U8 getComponents() const { return mComponents; }
107 S32 getBytes(S32 discard_level = -1) const;
108 S32 getMipBytes(S32 discard_level = -1) const;
109 BOOL getBoundRecently() const;
110 LLGLenum getPrimaryFormat() const { return mFormatPrimary; }
111
112 BOOL getClampS() const { return mClampS; }
113 BOOL getClampT() const { return mClampT; }
114 BOOL getMipFilterNearest() const { return mMipFilterNearest; }
115
116 BOOL getHasGLTexture() const { return mTexName != 0; }
117 LLGLuint getTexName() const { return mTexName; }
118
119 BOOL getIsResident(BOOL test_now = FALSE); // not const
120
121 void setTarget(const LLGLenum target, const LLGLenum bind_target);
122
123 BOOL getUseMipMaps() const { return mUseMipMaps; }
124 void setUseMipMaps(BOOL usemips) { mUseMipMaps = usemips; }
125 BOOL getUseDiscard() const { return mUseMipMaps && !mDontDiscard; }
126 BOOL getDontDiscard() const { return mDontDiscard; }
127
128protected:
129 void init(BOOL usemipmaps);
130 virtual void cleanup(); // Clean up the LLImageGL so it can be reinitialized. Be careful when using this in derived class destructors
131
132public:
133 // Various GL/Rendering options
134 S32 mTextureMemory;
135 mutable F32 mLastBindTime; // last time this was bound, by discard level
136 mutable F32 mLastBindAttempt; // last time bindTexture was called on this texture
137
138private:
139 LLPointer<LLImageRaw> mSaveData; // used for destroyGL/restoreGL
140 S8 mUseMipMaps;
141 S8 mHasMipMaps;
142 S8 mHasExplicitFormat; // If false (default), GL format is f(mComponents)
143 S8 mAutoGenMips;
144
145protected:
146 LLGLenum mTarget; // Normally GL_TEXTURE2D, sometimes something else (ex. cube maps)
147 LLGLenum mBindTarget; // NOrmally GL_TEXTURE2D, sometimes something else (ex. cube maps)
148
149 LLGLuint mTexName;
150
151 LLGLboolean mIsResident;
152
153 U16 mWidth;
154 U16 mHeight;
155
156 S8 mComponents;
157 S8 mMaxDiscardLevel;
158 S8 mCurrentDiscardLevel;
159 S8 mDontDiscard; // Keep full res version of this image (for UI, etc)
160
161 S8 mClampS; // Need to save clamp state
162 S8 mClampT;
163 S8 mMipFilterNearest; // if TRUE, set magfilter to GL_NEAREST
164
165 LLGLint mFormatInternal; // = GL internalformat
166 LLGLenum mFormatPrimary; // = GL format (pixel data format)
167 LLGLenum mFormatType;
168 BOOL mFormatSwapBytes;// if true, use glPixelStorei(GL_UNPACK_SWAP_BYTES, 1)
169
170 // STATICS
171public:
172 static std::set<LLImageGL*> sImageList;
173 static S32 sCount;
174
175 static F32 sLastFrameTime;
176
177 static LLGLuint sCurrentBoundTextures[MAX_GL_TEXTURE_UNITS]; // Currently bound texture ID
178
179 // Global memory statistics
180 static S32 sGlobalTextureMemory; // Tracks main memory texmem
181 static S32 sBoundTextureMemory; // Tracks bound texmem for last completed frame
182 static S32 sCurBoundTextureMemory; // Tracks bound texmem for current frame
183
184 static BOOL sGlobalUseAnisotropic;
185
186#if DEBUG_MISS
187 BOOL mMissed; // Missed on last bind?
188 BOOL getMissed() const { return mMissed; };
189#else
190 BOOL getMissed() const { return FALSE; };
191#endif
192};
193
194//RN: maybe this needs to moved elsewhere?
195class LLImageProviderInterface
196{
197public:
198 LLImageProviderInterface() {};
199 virtual ~LLImageProviderInterface() {};
200
201 virtual LLImageGL* getUIImageByID(const LLUUID& id, BOOL clamped = TRUE) = 0;
202};
203
204#endif // LL_LLIMAGEGL_H