aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llrender/llfontbitmapcache.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2009-04-30 13:04:20 -0500
committerJacek Antonelli2009-04-30 13:07:16 -0500
commitca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e (patch)
tree8348301d0ac44a524f1819b777686bf086907d76 /linden/indra/llrender/llfontbitmapcache.cpp
parentSecond Life viewer sources 1.22.11 (diff)
downloadmeta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.zip
meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.gz
meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.bz2
meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.xz
Second Life viewer sources 1.23.0-RC
Diffstat (limited to 'linden/indra/llrender/llfontbitmapcache.cpp')
-rw-r--r--linden/indra/llrender/llfontbitmapcache.cpp169
1 files changed, 169 insertions, 0 deletions
diff --git a/linden/indra/llrender/llfontbitmapcache.cpp b/linden/indra/llrender/llfontbitmapcache.cpp
new file mode 100644
index 0000000..052510e
--- /dev/null
+++ b/linden/indra/llrender/llfontbitmapcache.cpp
@@ -0,0 +1,169 @@
1/**
2 * @file llfontbitmapcache.cpp
3 * @brief Storage for previously rendered glyphs.
4 *
5 * $LicenseInfo:firstyear=2008&license=viewergpl$
6 *
7 * Copyright (c) 2008-2009, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at
21 * http://secondlifegrid.net/programs/open_source/licensing/flossexception
22 *
23 * By copying, modifying or distributing this software, you acknowledge
24 * that you have read and understood your obligations described above,
25 * and agree to abide by those obligations.
26 *
27 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
28 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
29 * COMPLETENESS OR PERFORMANCE.
30 * $/LicenseInfo$
31 */
32
33#include "linden_common.h"
34
35#include "llgl.h"
36#include "llfontbitmapcache.h"
37
38LLFontBitmapCache::LLFontBitmapCache():
39 mNumComponents(0),
40 mMaxCharWidth(0),
41 mMaxCharHeight(0),
42 mBitmapWidth(0),
43 mBitmapHeight(0),
44 mCurrentOffsetX(1),
45 mCurrentOffsetY(1),
46 mCurrentBitmapNum(-1)
47{
48}
49
50LLFontBitmapCache::~LLFontBitmapCache()
51{
52}
53
54void LLFontBitmapCache::init(S32 num_components,
55 S32 max_char_width,
56 S32 max_char_height)
57{
58 reset();
59
60 mNumComponents = num_components;
61 mMaxCharWidth = max_char_width;
62 mMaxCharHeight = max_char_height;
63}
64
65LLImageRaw *LLFontBitmapCache::getImageRaw(U32 bitmap_num) const
66{
67 if ((bitmap_num < 0) || (bitmap_num >= mImageRawVec.size()))
68 return NULL;
69
70 return mImageRawVec[bitmap_num];
71}
72
73LLImageGL *LLFontBitmapCache::getImageGL(U32 bitmap_num) const
74{
75 if ((bitmap_num < 0) || (bitmap_num >= mImageGLVec.size()))
76 return NULL;
77
78 return mImageGLVec[bitmap_num];
79}
80
81
82BOOL LLFontBitmapCache::nextOpenPos(S32 width, S32 &pos_x, S32 &pos_y, S32& bitmap_num)
83{
84 if ((mBitmapNum<0) || (mCurrentOffsetX + width + 1) > mBitmapWidth)
85 {
86 if ((mBitmapNum<0) || (mCurrentOffsetY + 2*mMaxCharHeight + 2) > mBitmapHeight)
87 {
88 // We're out of space in the current image, or no image
89 // has been allocated yet. Make a new one.
90 mImageRawVec.push_back(new LLImageRaw);
91 mBitmapNum = mImageRawVec.size()-1;
92 LLImageRaw *image_raw = getImageRaw(mBitmapNum);
93
94 // Make corresponding GL image.
95 mImageGLVec.push_back(new LLImageGL(FALSE));
96 LLImageGL *image_gl = getImageGL(mBitmapNum);
97
98 S32 image_width = mMaxCharWidth * 20;
99 S32 pow_iw = 2;
100 while (pow_iw < image_width)
101 {
102 pow_iw *= 2;
103 }
104 image_width = pow_iw;
105 image_width = llmin(512, image_width); // Don't make bigger than 512x512, ever.
106 S32 image_height = image_width;
107
108 image_raw->resize(image_width, image_height, mNumComponents);
109
110 mBitmapWidth = image_width;
111 mBitmapHeight = image_height;
112
113 switch (mNumComponents)
114 {
115 case 1:
116 image_raw->clear();
117 break;
118 case 2:
119 image_raw->clear(255, 0);
120 break;
121 }
122
123 // Start at beginning of the new image.
124 mCurrentOffsetX = 1;
125 mCurrentOffsetY = 1;
126
127 // Attach corresponding GL texture.
128 image_gl->createGLTexture(0, image_raw);
129 gGL.getTexUnit(0)->bind(image_gl);
130 image_gl->setFilteringOption(LLTexUnit::TFO_POINT); // was setMipFilterNearest(TRUE, TRUE);
131 }
132 else
133 {
134 // Move to next row in current image.
135 mCurrentOffsetX = 1;
136 mCurrentOffsetY += mMaxCharHeight + 1;
137 }
138 }
139
140 pos_x = mCurrentOffsetX;
141 pos_y = mCurrentOffsetY;
142 bitmap_num = mBitmapNum;
143
144 mCurrentOffsetX += width + 1;
145
146 return TRUE;
147}
148
149void LLFontBitmapCache::destroyGL()
150{
151 for (std::vector<LLPointer<LLImageGL> >::iterator it = mImageGLVec.begin();
152 it != mImageGLVec.end(); ++it)
153 {
154 (*it)->destroyGLTexture();
155 }
156}
157
158void LLFontBitmapCache::reset()
159{
160 mImageRawVec.clear();
161 mImageGLVec.clear();
162
163 mBitmapWidth = 0,
164 mBitmapHeight = 0,
165 mCurrentOffsetX = 0,
166 mCurrentOffsetY = 0,
167 mCurrentBitmapNum = -1;
168}
169