summaryrefslogtreecommitdiff
path: root/indra/llrender/llgltexture.cpp
blob: 3a6eebebbafef5b399376fce6dc1e16fa6c25f83 (plain)
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/** 
 * @file llgltexture.cpp
 * @brief Opengl texture implementation
 *
 * $LicenseInfo:firstyear=2000&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$
 */
#include "linden_common.h"
#include "llgltexture.h"


// static
S32 LLGLTexture::getTotalNumOfCategories() 
{
	return MAX_GL_IMAGE_CATEGORY - (BOOST_HIGH - BOOST_SCULPTED) + 2 ;
}

// static
//index starts from zero.
S32 LLGLTexture::getIndexFromCategory(S32 category) 
{
	return (category < BOOST_HIGH) ? category : category - (BOOST_HIGH - BOOST_SCULPTED) + 1 ;
}

//static 
S32 LLGLTexture::getCategoryFromIndex(S32 index)
{
	return (index < BOOST_HIGH) ? index : index + (BOOST_HIGH - BOOST_SCULPTED) - 1 ;
}

LLGLTexture::LLGLTexture(BOOL usemipmaps)
{
	init();
	mUseMipMaps = usemipmaps;
}

LLGLTexture::LLGLTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps)
{
	init();
	mFullWidth = width ;
	mFullHeight = height ;
	mUseMipMaps = usemipmaps;
	mComponents = components ;
	setTexelsPerImage();
}

LLGLTexture::LLGLTexture(const LLImageRaw* raw, BOOL usemipmaps)
{
	init();
	mUseMipMaps = usemipmaps ;
	// Create an empty image of the specified size and width
	mGLTexturep = new LLImageGL(raw, usemipmaps) ;
}

LLGLTexture::~LLGLTexture()
{
	cleanup();
}

void LLGLTexture::init()
{
	mBoostLevel = LLGLTexture::BOOST_NONE;

	mFullWidth = 0;
	mFullHeight = 0;
	mTexelsPerImage = 0 ;
	mUseMipMaps = FALSE ;
	mComponents = 0 ;

	mTextureState = NO_DELETE ;
	mDontDiscard = FALSE;
	mNeedsGLTexture = FALSE ;
}

void LLGLTexture::cleanup()
{
	if(mGLTexturep)
	{
		mGLTexturep->cleanup();
	}
}

// virtual
void LLGLTexture::dump()
{
	if(mGLTexturep)
	{
		mGLTexturep->dump();
	}
}

void LLGLTexture::setBoostLevel(S32 level)
{
	if(mBoostLevel != level)
	{
		mBoostLevel = level ;
		if(mBoostLevel != LLGLTexture::BOOST_NONE
		   && mBoostLevel != LLGLTexture::BOOST_ICON)
		{
			setNoDelete() ;		
		}
	}
}

void LLGLTexture::forceActive()
{
	mTextureState = ACTIVE ; 
}

void LLGLTexture::setActive() 
{ 
	if(mTextureState != NO_DELETE)
	{
		mTextureState = ACTIVE ; 
	}
}

//set the texture to stay in memory
void LLGLTexture::setNoDelete() 
{ 
	mTextureState = NO_DELETE ;
}

void LLGLTexture::generateGLTexture() 
{	
	if(mGLTexturep.isNull())
	{
		mGLTexturep = new LLImageGL(mFullWidth, mFullHeight, mComponents, mUseMipMaps) ;
	}
}

LLImageGL* LLGLTexture::getGLTexture() const
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep ;
}

BOOL LLGLTexture::createGLTexture() 
{
	if(mGLTexturep.isNull())
	{
		generateGLTexture() ;
	}

	return mGLTexturep->createGLTexture() ;
}

BOOL LLGLTexture::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename, BOOL to_create, S32 category)
{
	llassert(mGLTexturep.notNull()) ;	

	BOOL ret = mGLTexturep->createGLTexture(discard_level, imageraw, usename, to_create, category) ;

	if(ret)
	{
		mFullWidth = mGLTexturep->getCurrentWidth() ;
		mFullHeight = mGLTexturep->getCurrentHeight() ; 
		mComponents = mGLTexturep->getComponents() ;	
		setTexelsPerImage();
	}

	return ret ;
}

void LLGLTexture::setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format, BOOL swap_bytes)
{
	llassert(mGLTexturep.notNull()) ;
	
	mGLTexturep->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes) ;
}
void LLGLTexture::setAddressMode(LLTexUnit::eTextureAddressMode mode)
{
	llassert(mGLTexturep.notNull()) ;
	mGLTexturep->setAddressMode(mode) ;
}
void LLGLTexture::setFilteringOption(LLTexUnit::eTextureFilterOptions option)
{
	llassert(mGLTexturep.notNull()) ;
	mGLTexturep->setFilteringOption(option) ;
}

//virtual
S32	LLGLTexture::getWidth(S32 discard_level) const
{
	llassert(mGLTexturep.notNull()) ;
	return mGLTexturep->getWidth(discard_level) ;
}

//virtual
S32	LLGLTexture::getHeight(S32 discard_level) const
{
	llassert(mGLTexturep.notNull()) ;
	return mGLTexturep->getHeight(discard_level) ;
}

S32 LLGLTexture::getMaxDiscardLevel() const
{
	llassert(mGLTexturep.notNull()) ;
	return mGLTexturep->getMaxDiscardLevel() ;
}
S32 LLGLTexture::getDiscardLevel() const
{
	llassert(mGLTexturep.notNull()) ;
	return mGLTexturep->getDiscardLevel() ;
}
S8  LLGLTexture::getComponents() const 
{ 
	llassert(mGLTexturep.notNull()) ;
	
	return mGLTexturep->getComponents() ;
}

LLGLuint LLGLTexture::getTexName() const 
{ 
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->getTexName() ; 
}

BOOL LLGLTexture::hasGLTexture() const 
{
	if(mGLTexturep.notNull())
	{
		return mGLTexturep->getHasGLTexture() ;
	}
	return FALSE ;
}

BOOL LLGLTexture::getBoundRecently() const
{
	if(mGLTexturep.notNull())
	{
		return mGLTexturep->getBoundRecently() ;
	}
	return FALSE ;
}

LLTexUnit::eTextureType LLGLTexture::getTarget(void) const
{
	llassert(mGLTexturep.notNull()) ;
	return mGLTexturep->getTarget() ;
}

BOOL LLGLTexture::setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height)
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->setSubImage(imageraw, x_pos, y_pos, width, height) ;
}

BOOL LLGLTexture::setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height)
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->setSubImage(datap, data_width, data_height, x_pos, y_pos, width, height) ;
}

void LLGLTexture::setGLTextureCreated (bool initialized)
{
	llassert(mGLTexturep.notNull()) ;

	mGLTexturep->setGLTextureCreated (initialized) ;
}

void  LLGLTexture::setCategory(S32 category) 
{
	llassert(mGLTexturep.notNull()) ;

	mGLTexturep->setCategory(category) ;
}

LLTexUnit::eTextureAddressMode LLGLTexture::getAddressMode(void) const
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->getAddressMode() ;
}

S32Bytes LLGLTexture::getTextureMemory() const
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->mTextureMemory ;
}

LLGLenum LLGLTexture::getPrimaryFormat() const
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->getPrimaryFormat() ;
}

BOOL LLGLTexture::getIsAlphaMask() const
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->getIsAlphaMask() ;
}

BOOL LLGLTexture::getMask(const LLVector2 &tc)
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->getMask(tc) ;
}

F32 LLGLTexture::getTimePassedSinceLastBound()
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->getTimePassedSinceLastBound() ;
}
BOOL LLGLTexture::getMissed() const 
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->getMissed() ;
}

BOOL LLGLTexture::isJustBound() const
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->isJustBound() ;
}

void LLGLTexture::forceUpdateBindStats(void) const
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->forceUpdateBindStats() ;
}

U32 LLGLTexture::getTexelsInAtlas() const
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->getTexelsInAtlas() ;
}

U32 LLGLTexture::getTexelsInGLTexture() const
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->getTexelsInGLTexture() ;
}

BOOL LLGLTexture::isGLTextureCreated() const
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->isGLTextureCreated() ;
}

S32  LLGLTexture::getDiscardLevelInAtlas() const
{
	llassert(mGLTexturep.notNull()) ;

	return mGLTexturep->getDiscardLevelInAtlas() ;
}

void LLGLTexture::destroyGLTexture() 
{
	if(mGLTexturep.notNull() && mGLTexturep->getHasGLTexture())
	{
		mGLTexturep->destroyGLTexture() ;
		mTextureState = DELETED ;
	}
}

void LLGLTexture::setTexelsPerImage()
{
	S32 fullwidth = llmin(mFullWidth,(S32)MAX_IMAGE_SIZE_DEFAULT);
	S32 fullheight = llmin(mFullHeight,(S32)MAX_IMAGE_SIZE_DEFAULT);
	mTexelsPerImage = (F32)fullwidth * fullheight;
}