summaryrefslogtreecommitdiff
path: root/indra/llrender/llfontbitmapcache.cpp
diff options
context:
space:
mode:
authorKitty Barnett <develop@catznip.com>2022-11-09 22:55:29 +0100
committerKitty Barnett <develop@catznip.com>2022-11-09 23:25:02 +0100
commit7ebaa2d2e55c6a9b7feeb684190628e340ad7920 (patch)
tree506c00c18a41846d77f171fa4940c534cabf9060 /indra/llrender/llfontbitmapcache.cpp
parent6e79ca4959d98c0305ff1c158b5402f56aba5430 (diff)
parentb5033a8859b38df045cc74e074aaee864985f145 (diff)
Merge branch contribution/emoji into DRTVWR-489-emoji
Diffstat (limited to 'indra/llrender/llfontbitmapcache.cpp')
-rw-r--r--indra/llrender/llfontbitmapcache.cpp147
1 files changed, 77 insertions, 70 deletions
diff --git a/indra/llrender/llfontbitmapcache.cpp b/indra/llrender/llfontbitmapcache.cpp
index c71e24c83a..8809f9f475 100644
--- a/indra/llrender/llfontbitmapcache.cpp
+++ b/indra/llrender/llfontbitmapcache.cpp
@@ -30,14 +30,7 @@
#include "llfontbitmapcache.h"
LLFontBitmapCache::LLFontBitmapCache()
-: mNumComponents(0),
- mBitmapWidth(0),
- mBitmapHeight(0),
- mBitmapNum(-1),
- mMaxCharWidth(0),
- mMaxCharHeight(0),
- mCurrentOffsetX(1),
- mCurrentOffsetY(1)
+
{
}
@@ -45,121 +38,135 @@ LLFontBitmapCache::~LLFontBitmapCache()
{
}
-void LLFontBitmapCache::init(S32 num_components,
- S32 max_char_width,
+void LLFontBitmapCache::init(S32 max_char_width,
S32 max_char_height)
{
reset();
- mNumComponents = num_components;
mMaxCharWidth = max_char_width;
mMaxCharHeight = max_char_height;
+
+ S32 image_width = mMaxCharWidth * 20;
+ S32 pow_iw = 2;
+ while (pow_iw < image_width)
+ {
+ pow_iw <<= 1;
+ }
+ image_width = pow_iw;
+ image_width = llmin(512, image_width); // Don't make bigger than 512x512, ever.
+
+ mBitmapWidth = image_width;
+ mBitmapHeight = image_width;
}
-LLImageRaw *LLFontBitmapCache::getImageRaw(U32 bitmap_num) const
+LLImageRaw *LLFontBitmapCache::getImageRaw(EFontGlyphType bitmap_type, U32 bitmap_num) const
{
- if (bitmap_num >= mImageRawVec.size())
- return NULL;
+ const U32 bitmap_idx = static_cast<U32>(bitmap_type);
+ if (bitmap_type >= EFontGlyphType::Count || bitmap_num >= mImageRawVec[bitmap_idx].size())
+ return nullptr;
- return mImageRawVec[bitmap_num];
+ return mImageRawVec[bitmap_idx][bitmap_num];
}
-LLImageGL *LLFontBitmapCache::getImageGL(U32 bitmap_num) const
+LLImageGL *LLFontBitmapCache::getImageGL(EFontGlyphType bitmap_type, U32 bitmap_num) const
{
- if (bitmap_num >= mImageGLVec.size())
- return NULL;
+ const U32 bitmap_idx = static_cast<U32>(bitmap_type);
+ if (bitmap_type >= EFontGlyphType::Count || bitmap_num >= mImageGLVec[bitmap_idx].size())
+ return nullptr;
- return mImageGLVec[bitmap_num];
+ return mImageGLVec[bitmap_idx][bitmap_num];
}
-BOOL LLFontBitmapCache::nextOpenPos(S32 width, S32 &pos_x, S32 &pos_y, S32& bitmap_num)
+BOOL LLFontBitmapCache::nextOpenPos(S32 width, S32& pos_x, S32& pos_y, EFontGlyphType bitmap_type, U32& bitmap_num)
{
- if ((mBitmapNum<0) || (mCurrentOffsetX + width + 1) > mBitmapWidth)
+ if (bitmap_type >= EFontGlyphType::Count)
+ {
+ return FALSE;
+ }
+
+ const U32 bitmap_idx = static_cast<U32>(bitmap_type);
+ if (mImageRawVec[bitmap_idx].empty() || (mCurrentOffsetX[bitmap_idx] + width + 1) > mBitmapWidth)
{
- if ((mBitmapNum<0) || (mCurrentOffsetY + 2*mMaxCharHeight + 2) > mBitmapHeight)
+ if ((mImageRawVec[bitmap_idx].empty()) || (mCurrentOffsetY[bitmap_idx] + 2*mMaxCharHeight + 2) > mBitmapHeight)
{
// We're out of space in the current image, or no image
// has been allocated yet. Make a new one.
-
- mImageRawVec.push_back(new LLImageRaw);
- mBitmapNum = mImageRawVec.size()-1;
- LLImageRaw *image_raw = getImageRaw(mBitmapNum);
+ S32 num_components = getNumComponents(bitmap_type);
+ mImageRawVec[bitmap_idx].push_back(new LLImageRaw(mBitmapWidth, mBitmapHeight, num_components));
+ bitmap_num = mImageRawVec[bitmap_idx].size() - 1;
- // Make corresponding GL image.
- mImageGLVec.push_back(new LLImageGL(FALSE));
- LLImageGL *image_gl = getImageGL(mBitmapNum);
-
- S32 image_width = mMaxCharWidth * 20;
- S32 pow_iw = 2;
- while (pow_iw < image_width)
+ LLImageRaw* image_raw = getImageRaw(bitmap_type, bitmap_num);
+ if (EFontGlyphType::Grayscale == bitmap_type)
{
- pow_iw *= 2;
+ image_raw->clear(255, 0);
}
- image_width = pow_iw;
- image_width = llmin(512, image_width); // Don't make bigger than 512x512, ever.
- S32 image_height = image_width;
- image_raw->resize(image_width, image_height, mNumComponents);
-
- mBitmapWidth = image_width;
- mBitmapHeight = image_height;
-
- switch (mNumComponents)
- {
- case 1:
- image_raw->clear();
- break;
- case 2:
- image_raw->clear(255, 0);
- break;
- }
+ // Make corresponding GL image.
+ mImageGLVec[bitmap_idx].push_back(new LLImageGL(image_raw, false));
+ LLImageGL* image_gl = getImageGL(bitmap_type, bitmap_num);
// Start at beginning of the new image.
- mCurrentOffsetX = 1;
- mCurrentOffsetY = 1;
+ mCurrentOffsetX[bitmap_idx] = 1;
+ mCurrentOffsetY[bitmap_idx] = 1;
- // Attach corresponding GL texture.
- image_gl->createGLTexture(0, image_raw);
+ // Attach corresponding GL texture. (*TODO: is this needed?)
gGL.getTexUnit(0)->bind(image_gl);
image_gl->setFilteringOption(LLTexUnit::TFO_POINT); // was setMipFilterNearest(TRUE, TRUE);
}
else
{
// Move to next row in current image.
- mCurrentOffsetX = 1;
- mCurrentOffsetY += mMaxCharHeight + 1;
+ mCurrentOffsetX[bitmap_idx] = 1;
+ mCurrentOffsetY[bitmap_idx] += mMaxCharHeight + 1;
}
}
- pos_x = mCurrentOffsetX;
- pos_y = mCurrentOffsetY;
- bitmap_num = mBitmapNum;
+ pos_x = mCurrentOffsetX[bitmap_idx];
+ pos_y = mCurrentOffsetY[bitmap_idx];
+ bitmap_num = getNumBitmaps(bitmap_type) - 1;
- mCurrentOffsetX += width + 1;
+ mCurrentOffsetX[bitmap_idx] += width + 1;
return TRUE;
}
void LLFontBitmapCache::destroyGL()
{
- for (std::vector<LLPointer<LLImageGL> >::iterator it = mImageGLVec.begin();
- it != mImageGLVec.end(); ++it)
+ for (U32 idx = 0, cnt = static_cast<U32>(EFontGlyphType::Count); idx < cnt; idx++)
{
- (*it)->destroyGLTexture();
+ for (LLImageGL* image_gl : mImageGLVec[idx])
+ {
+ image_gl->destroyGLTexture();
+ }
}
}
void LLFontBitmapCache::reset()
{
- mImageRawVec.clear();
-
- mImageGLVec.clear();
+ for (U32 idx = 0, cnt = static_cast<U32>(EFontGlyphType::Count); idx < cnt; idx++)
+ {
+ mImageRawVec[idx].clear();
+ mImageGLVec[idx].clear();
+ mCurrentOffsetX[idx] = 1;
+ mCurrentOffsetY[idx] = 1;
+ }
mBitmapWidth = 0;
mBitmapHeight = 0;
- mBitmapNum = -1;
- mCurrentOffsetX = 1;
- mCurrentOffsetY = 1;
}
+//static
+U32 LLFontBitmapCache::getNumComponents(EFontGlyphType bitmap_type)
+{
+ switch (bitmap_type)
+ {
+ case EFontGlyphType::Grayscale:
+ return 2;
+ case EFontGlyphType::Color:
+ return 4;
+ default:
+ llassert(false);
+ return 2;
+ }
+}