1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
|
/**
* @file llgltexture.h
* @brief Object for managing opengl textures
*
* $LicenseInfo:firstyear=2012&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
#ifndef LL_GL_TEXTURE_H
#define LL_GL_TEXTURE_H
#include "lltexture.h"
#include "llgl.h"
class LLImageRaw;
//
//this the parent for the class LLViewerTexture
//through the following virtual functions, the class LLViewerTexture can be reached from /llrender.
//
class LLGLTexture : public LLTexture
{
public:
enum
{
MAX_IMAGE_SIZE_DEFAULT = 2048,
INVALID_DISCARD_LEVEL = 0x7fff
};
enum EBoostLevel
{
BOOST_NONE = 0,
BOOST_AVATAR ,
BOOST_AVATAR_BAKED ,
BOOST_TERRAIN , // Needed for minimap generation for now. Lower than BOOST_HIGH so the texture stats don't get forced, i.e. texture stats are manually managed by minimap/terrain instead.
BOOST_HIGH = 10,
BOOST_SCULPTED ,
BOOST_BUMP ,
BOOST_UNUSED_1 , // Placeholder to avoid disrupting habits around texture debug
BOOST_SELECTED ,
BOOST_AVATAR_BAKED_SELF ,
BOOST_AVATAR_SELF , // needed for baking avatar
BOOST_SUPER_HIGH , //textures higher than this need to be downloaded at the required resolution without delay.
BOOST_HUD ,
BOOST_ICON ,
BOOST_THUMBNAIL ,
BOOST_UI ,
BOOST_PREVIEW ,
BOOST_MAP ,
BOOST_MAP_VISIBLE ,
BOOST_MAX_LEVEL,
//other texture Categories
LOCAL = BOOST_MAX_LEVEL,
AVATAR_SCRATCH_TEX,
DYNAMIC_TEX,
MEDIA,
OTHER,
MAX_GL_IMAGE_CATEGORY
};
typedef enum
{
DELETED = 0, //removed from memory
DELETION_CANDIDATE, //ready to be removed from memory
INACTIVE, //not be used for the last certain period (i.e., 30 seconds).
ACTIVE, //just being used, can become inactive if not being used for a certain time (10 seconds).
NO_DELETE = 99 //stay in memory, can not be removed.
} LLGLTextureState;
protected:
virtual ~LLGLTexture();
LOG_CLASS(LLGLTexture);
public:
LLGLTexture(bool usemipmaps = true);
LLGLTexture(const LLImageRaw* raw, bool usemipmaps) ;
LLGLTexture(const U32 width, const U32 height, const U8 components, bool usemipmaps) ;
virtual void dump(); // debug info to LL_INFOS()
virtual const LLUUID& getID() const;
void setBoostLevel(S32 level);
S32 getBoostLevel() { return mBoostLevel; }
S32 getFullWidth() const { return mFullWidth; }
S32 getFullHeight() const { return mFullHeight; }
void generateGLTexture() ;
void destroyGLTexture() ;
//---------------------------------------------------------------------------------------------
//functions to access LLImageGL
//---------------------------------------------------------------------------------------------
/*virtual*/S32 getWidth(S32 discard_level = -1) const;
/*virtual*/S32 getHeight(S32 discard_level = -1) const;
bool hasGLTexture() const ;
LLGLuint getTexName() const ;
bool createGLTexture() ;
// Create a GL Texture from an image raw
// discard_level - mip level, 0 for highest resultion mip
// imageraw - the image to copy from
// usename - explicit GL name override
// to_create - set to false to force gl texture to not be created
// category - LLGLTexture category for this LLGLTexture
// defer_copy - set to true to allocate GL texture but NOT initialize with imageraw data
// tex_name - if not null, will be set to the GL name of the texture created
bool createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename = 0, bool to_create = true, S32 category = LLGLTexture::OTHER, bool defer_copy = false, LLGLuint* tex_name = nullptr);
void setFilteringOption(LLTexUnit::eTextureFilterOptions option);
void setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format = 0, bool swap_bytes = false);
void setAddressMode(LLTexUnit::eTextureAddressMode mode);
bool setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height, LLGLuint use_name = 0);
bool setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height, LLGLuint use_name = 0);
void setGLTextureCreated (bool initialized);
void setCategory(S32 category) ;
void setTexName(LLGLuint); // for forcing w/ externally created textures only
void setTarget(const LLGLenum target, const LLTexUnit::eTextureType bind_target);
LLTexUnit::eTextureAddressMode getAddressMode(void) const ;
S32 getMaxDiscardLevel() const;
S32 getDiscardLevel() const;
S8 getComponents() const;
bool getBoundRecently() const;
S32Bytes getTextureMemory() const ;
LLGLenum getPrimaryFormat() const;
bool getIsAlphaMask() const ;
LLTexUnit::eTextureType getTarget(void) const ;
bool getMask(const LLVector2 &tc);
F32 getTimePassedSinceLastBound();
bool getMissed() const ;
bool isJustBound()const ;
void forceUpdateBindStats(void) const;
bool isGLTextureCreated() const ;
LLGLTextureState getTextureState() const { return mTextureState; }
//---------------------------------------------------------------------------------------------
//end of functions to access LLImageGL
//---------------------------------------------------------------------------------------------
//-----------------
/*virtual*/ void setActive() ;
void forceActive() ;
void setNoDelete() ;
void dontDiscard() { mDontDiscard = 1; mTextureState = NO_DELETE; }
bool getDontDiscard() const { return mDontDiscard; }
//-----------------
private:
void cleanup();
void init();
protected:
void setTexelsPerImage();
public:
/*virtual*/ LLImageGL* getGLTexture() const ;
protected:
S32 mBoostLevel; // enum describing priority level
U32 mFullWidth;
U32 mFullHeight;
bool mUseMipMaps;
S8 mComponents;
U32 mTexelsPerImage; // Texels per image.
mutable S8 mNeedsGLTexture;
//GL texture
LLPointer<LLImageGL> mGLTexturep ;
S8 mDontDiscard; // Keep full res version of this image (for UI, etc)
protected:
LLGLTextureState mTextureState ;
};
#endif // LL_GL_TEXTURE_H
|