From 2badc1c79c873b2d4682328c8b305315b3ae026b Mon Sep 17 00:00:00 2001 From: Shyotl Date: Mon, 18 Nov 2013 09:55:15 -0600 Subject: [PATCH 1/4] Initialize LLListener_OpenAL::mRolloffFactor just to be safe. --- indra/llaudio/lllistener_openal.cpp | 7 +++++++ indra/llaudio/lllistener_openal.h | 1 + 2 files changed, 8 insertions(+) diff --git a/indra/llaudio/lllistener_openal.cpp b/indra/llaudio/lllistener_openal.cpp index b3d4b02f0..41a40caf7 100644 --- a/indra/llaudio/lllistener_openal.cpp +++ b/indra/llaudio/lllistener_openal.cpp @@ -39,6 +39,13 @@ LLListener_OpenAL::~LLListener_OpenAL() { } +LLListener_OpenAL::init() +{ + // do inherited + LLListener::init(); + mRolloffFactor = 1.0f; +} + void LLListener_OpenAL::translate(LLVector3 offset) { //llinfos << "LLListener_OpenAL::translate() : " << offset << llendl; diff --git a/indra/llaudio/lllistener_openal.h b/indra/llaudio/lllistener_openal.h index cb163b11a..96af86d99 100644 --- a/indra/llaudio/lllistener_openal.h +++ b/indra/llaudio/lllistener_openal.h @@ -38,6 +38,7 @@ class LLListener_OpenAL : public LLListener public: LLListener_OpenAL(); virtual ~LLListener_OpenAL(); + virtual void init(); virtual void translate(LLVector3 offset); virtual void setPosition(LLVector3 pos); From be249ac8a18a3d02a8971e0509a12de55ba5b28f Mon Sep 17 00:00:00 2001 From: Shyotl Date: Mon, 18 Nov 2013 09:56:49 -0600 Subject: [PATCH 2/4] Font update. Minor refactor, and removed some pointless code that was leaking. --- indra/llrender/llfontfreetype.cpp | 208 +++++++++++++++++------------ indra/llrender/llfontfreetype.h | 131 ++++++++---------- indra/llrender/llfontgl.cpp | 161 +++++++++++----------- indra/llrender/llfontgl.h | 33 ++--- indra/llrender/llfontregistry.cpp | 22 +-- indra/llui/llresmgr.cpp | 1 + indra/llui/llstyle.cpp | 2 + indra/newview/llappviewerwin32.cpp | 3 +- indra/newview/llviewerwindow.cpp | 1 + 9 files changed, 298 insertions(+), 264 deletions(-) diff --git a/indra/llrender/llfontfreetype.cpp b/indra/llrender/llfontfreetype.cpp index 36515c48a..a0322846a 100644 --- a/indra/llrender/llfontfreetype.cpp +++ b/indra/llrender/llfontfreetype.cpp @@ -2,37 +2,32 @@ * @file llfontfreetype.cpp * @brief Freetype font library wrapper * - * $LicenseInfo:firstyear=2002&license=viewergpl$ - * - * Copyright (c) 2002-2009, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2002&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * 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. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * 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. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * 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 "llfontfreetype.h" +#include "llfontgl.h" // Freetype stuff #include @@ -103,36 +98,18 @@ LLFontGlyphInfo::LLFontGlyphInfo(U32 index) mYBitmapOffset(0), // Offset to the origin in the bitmap mXBearing(0), // Distance from baseline to left in pixels mYBearing(0), // Distance from baseline to top in pixels + mBitmapNum(0), // Which bitmap in the bitmap cache contains this glyph mIsRendered(FALSE), mMetricsValid(FALSE) -{} - -LLFontList::LLFontList() { } -LLFontList::~LLFontList() -{ - LLFontList::iterator iter; - for(iter = this->begin(); iter != this->end(); iter++) - { - delete *iter; - // The (now dangling) pointers in the vector will be cleaned up when the vector is deleted by the superclass destructor. - } -} -void LLFontList::addAtEnd(LLFontFreetype *font) -{ - // Purely a convenience function - this->push_back(font); -} - LLFontFreetype::LLFontFreetype() : mFontBitmapCachep(new LLFontBitmapCache), mValid(FALSE), mAscender(0.f), mDescender(0.f), mLineHeight(0.f), - mFallbackFontp(NULL), mIsFallback(FALSE), mFTFace(NULL), mRenderGlyphCount(0), @@ -222,8 +199,8 @@ BOOL LLFontFreetype::loadFace(const std::string& filename, const F32 point_size, if (!mIsFallback || !sOpenGLcrashOnRestart) // because this often crashes under Linux... { - // Add the empty glyph`5 - addGlyph(0, 0); + // Add the default glyph + addGlyphFromFont(this, 0, 0); } mName = filename; @@ -232,19 +209,26 @@ BOOL LLFontFreetype::loadFace(const std::string& filename, const F32 point_size, return TRUE; } -//virtual +void LLFontFreetype::setFallbackFonts(const font_vector_t &font) +{ + mFallbackFonts = font; +} + +const LLFontFreetype::font_vector_t &LLFontFreetype::getFallbackFonts() const +{ + return mFallbackFonts; +} + F32 LLFontFreetype::getLineHeight() const { return mLineHeight; } -//virtual F32 LLFontFreetype::getAscenderHeight() const { return mAscender; } -//virtual F32 LLFontFreetype::getDescenderHeight() const { return mDescender; @@ -256,7 +240,7 @@ F32 LLFontFreetype::getXAdvance(const llwchar wch) const return 0.0; llassert(!mIsFallback); - U32 glyph_index; + //U32 glyph_index; // Return existing info only if it is current LLFontGlyphInfo* gi = getGlyphInfo(wch); @@ -264,18 +248,26 @@ F32 LLFontFreetype::getXAdvance(const llwchar wch) const { return gi->mXAdvance; } - - const LLFontFreetype* fontp = this; + //new + else + { + char_glyph_info_map_t::iterator found_it = mCharGlyphInfoMap.find((llwchar)0); + if (found_it != mCharGlyphInfoMap.end()) + { + return found_it->second->mXAdvance; + } + } + /*const LLFontFreetype* fontp = this; // Initialize char to glyph map glyph_index = FT_Get_Char_Index(mFTFace, wch); - if (glyph_index == 0 && mFallbackFontp) + if (glyph_index == 0) { - LLFontList::iterator iter; - for(iter = mFallbackFontp->begin(); (iter != mFallbackFontp->end()) && (glyph_index == 0); iter++) + font_vector_t::const_iterator iter; + for(iter = mFallbackFonts.begin(); iter != mFallbackFonts.end(); iter++) { glyph_index = FT_Get_Char_Index((*iter)->mFTFace, wch); - if(glyph_index) + if (glyph_index) { fontp = *iter; } @@ -306,6 +298,7 @@ F32 LLFontFreetype::getXAdvance(const llwchar wch) const gi->mXAdvance = fontp->mFTFace->glyph->advance.x / 64.f; gi->mYAdvance = fontp->mFTFace->glyph->advance.y / 64.f; gi->mMetricsValid = TRUE; + //gi->mIsRendered = TRUE; return gi->mXAdvance; } else @@ -315,7 +308,7 @@ F32 LLFontFreetype::getXAdvance(const llwchar wch) const { return gi->mXAdvance; } - } + }*/ // Last ditch fallback - no glyphs defined at all. return (F32)mFontBitmapCachep->getMaxCharWidth(); @@ -343,7 +336,8 @@ F32 LLFontFreetype::getXKerning(const llwchar char_left, const llwchar char_righ BOOL LLFontFreetype::hasGlyph(const llwchar wch) const { llassert(!mIsFallback); - const LLFontGlyphInfo* gi = getGlyphInfo(wch); + return(mCharGlyphInfoMap.find(wch) != mCharGlyphInfoMap.end()); + /*const LLFontGlyphInfo* gi = getGlyphInfo(wch); if (gi && gi->mIsRendered) { return TRUE; @@ -351,10 +345,10 @@ BOOL LLFontFreetype::hasGlyph(const llwchar wch) const else { return FALSE; - } + }*/ } -BOOL LLFontFreetype::addChar(const llwchar wch) const +BOOL LLFontFreetype::addGlyph(const llwchar wch) const { if (mFTFace == NULL) return FALSE; @@ -368,19 +362,15 @@ BOOL LLFontFreetype::addChar(const llwchar wch) const glyph_index = FT_Get_Char_Index(mFTFace, wch); if (glyph_index == 0) { - // Try looking it up in the backup Unicode font - if (mFallbackFontp) + //llinfos << "Trying to add glyph from fallback font!" << llendl; + font_vector_t::const_iterator iter; + for(iter = mFallbackFonts.begin(); iter != mFallbackFonts.end(); iter++) { - //llinfos << "Trying to add glyph from fallback font!" << llendl; - LLFontList::iterator iter; - for(iter = mFallbackFontp->begin(); iter != mFallbackFontp->end(); iter++) + glyph_index = FT_Get_Char_Index((*iter)->mFTFace, wch); + if (glyph_index) { - glyph_index = FT_Get_Char_Index((*iter)->mFTFace, wch); - if (glyph_index) - { - addGlyphFromFont(*iter, wch, glyph_index); - return TRUE; - } + addGlyphFromFont(*iter, wch, glyph_index); + return TRUE; } } } @@ -388,8 +378,7 @@ BOOL LLFontFreetype::addChar(const llwchar wch) const char_glyph_info_map_t::iterator iter = mCharGlyphInfoMap.find(wch); if (iter == mCharGlyphInfoMap.end() || !(iter->second->mIsRendered)) { - BOOL result = addGlyph(wch, glyph_index); - return result; + return addGlyphFromFont(this, wch, glyph_index); } return FALSE; } @@ -492,6 +481,11 @@ BOOL LLFontFreetype::addGlyphFromFont(const LLFontFreetype *fontp, const llwchar // omit it from the font-image. } + //new + LLImageGL *image_gl = mFontBitmapCachep->getImageGL(bitmap_num); + LLImageRaw *image_raw = mFontBitmapCachep->getImageRaw(bitmap_num); + image_gl->setSubImage(image_raw, 0, 0, image_gl->getWidth(), image_gl->getHeight()); + return TRUE; } @@ -502,6 +496,15 @@ LLFontGlyphInfo* LLFontFreetype::getGlyphInfo(const llwchar wch) const { return iter->second; } + else if(addGlyph(wch))//new + { + // this glyph doesn't yet exist, so render it and return the result + char_glyph_info_map_t::iterator iter = mCharGlyphInfoMap.find(wch); + if (iter != mCharGlyphInfoMap.end()) + { + return iter->second; + } + } return NULL; } @@ -519,11 +522,6 @@ void LLFontFreetype::insertGlyphInfo(llwchar wch, LLFontGlyphInfo* gi) const } } -BOOL LLFontFreetype::addGlyph(const llwchar wch, const U32 glyph_index) const -{ - return addGlyphFromFont(this, wch, glyph_index); -} - void LLFontFreetype::renderGlyph(const U32 glyph_index) const { if (mFTFace == NULL) @@ -536,34 +534,74 @@ void LLFontFreetype::renderGlyph(const U32 glyph_index) const mRenderGlyphCount++; } +void LLFontFreetype::reset(F32 vert_dpi, F32 horz_dpi) +{ + //new + resetBitmapCache(); + loadFace(mName,mPointSize,vert_dpi,horz_dpi,mFontBitmapCachep->getNumComponents(),mIsFallback); + if (!mIsFallback) + { + // This is the head of the list - need to rebuild ourself and all fallbacks. + //loadFace(mName,mPointSize,vert_dpi,horz_dpi,mFontBitmapCachep->getNumComponents(),mIsFallback); + if (mFallbackFonts.empty()) + { + llwarns << "LLFontGL::reset(), no fallback fonts present" << llendl; + } + else + { + for(font_vector_t::iterator it = mFallbackFonts.begin(); + it != mFallbackFonts.end(); + ++it) + { + (*it)->reset(vert_dpi, horz_dpi); + } + } + } + //resetBitmapCache(); +} + void LLFontFreetype::resetBitmapCache() { // Iterate through glyphs and clear the mIsRendered flag - for (char_glyph_info_map_t::iterator iter = mCharGlyphInfoMap.begin(); + /*for (char_glyph_info_map_t::iterator iter = mCharGlyphInfoMap.begin(); iter != mCharGlyphInfoMap.end(); ++iter) { iter->second->mIsRendered = FALSE; //FIXME: this is only strictly necessary when resetting the entire font, //not just flushing the bitmap iter->second->mMetricsValid = FALSE; - } + }*/ + //new + for_each(mCharGlyphInfoMap.begin(), mCharGlyphInfoMap.end(), DeletePairedPointer()); + mCharGlyphInfoMap.clear(); + mFontBitmapCachep->reset(); + // Adding default glyph is skipped for fallback fonts here as well as in loadFace(). + // This if was added as fix for EXT-4971. if (!mIsFallback || !sOpenGLcrashOnRestart) // because this often crashes under Linux... { - // Add the empty glyph`5 - addGlyph(0, 0); + // Add the empty glyph + addGlyphFromFont(this, 0, 0); } } +void LLFontFreetype::destroyGL() +{ + mFontBitmapCachep->destroyGL(); +} -void LLFontFreetype::setSubImageLuminanceAlpha(const U32 x, - const U32 y, - const U32 bitmap_num, - const U32 width, - const U32 height, - const U8 *data, - S32 stride) const +const std::string &LLFontFreetype::getName() const +{ + return mName; +} + +const LLPointer LLFontFreetype::getFontBitmapCache() const +{ + return mFontBitmapCachep; +} + +void LLFontFreetype::setSubImageLuminanceAlpha(const U32 x, const U32 y, const U32 bitmap_num, const U32 width, const U32 height, const U8 *data, S32 stride) const { LLImageRaw *image_raw = mFontBitmapCachep->getImageRaw(bitmap_num); diff --git a/indra/llrender/llfontfreetype.h b/indra/llrender/llfontfreetype.h index 1a7dfb9ad..5e29e3fbb 100644 --- a/indra/llrender/llfontfreetype.h +++ b/indra/llrender/llfontfreetype.h @@ -1,32 +1,26 @@ /** - * @file llfont.h + * @file llfontfreetype.h * @brief Font library wrapper * - * $LicenseInfo:firstyear=2002&license=viewergpl$ - * - * Copyright (c) 2002-2009, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2002&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * 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. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * 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. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * 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$ */ @@ -34,7 +28,7 @@ #define LL_LLFONTFREETYPE_H #include -#include "llmemory.h" +#include "llpointer.h" #include "llstl.h" #include "llimagegl.h" @@ -51,25 +45,23 @@ class LLFontFreetype; struct FT_FaceRec_; typedef struct FT_FaceRec_* LLFT_Face; -extern LLFontManager *gFontManagerp; - class LLFontManager { public: static void initClass(); static void cleanupClass(); -public: +private: LLFontManager(); - virtual ~LLFontManager(); + ~LLFontManager(); }; -class LLFontGlyphInfo +struct LLFontGlyphInfo { -public: LLFontGlyphInfo(U32 index); -public: + U32 mGlyphIndex; + // Metrics S32 mWidth; // In pixels S32 mHeight; // In pixels @@ -86,37 +78,29 @@ public: S32 mBitmapNum; // Which bitmap in the bitmap cache contains this glyph }; -// Used for lists of fallback fonts -class LLFontList : public std::vector -{ -public: - LLFontList(); - ~LLFontList(); - void addAtEnd(LLFontFreetype *font); -}; +extern LLFontManager *gFontManagerp; -class LLFontFreetype +class LLFontFreetype : public LLRefCount { public: LLFontFreetype(); - virtual ~LLFontFreetype(); + ~LLFontFreetype(); // is_fallback should be true for fallback fonts that aren't used // to render directly (Unicode backup, primarily) - virtual BOOL loadFace(const std::string& filename, - const F32 point_size, - const F32 vert_dpi, - const F32 horz_dpi, - const S32 components, - BOOL is_fallback); - void setFallbackFont(LLFontList *fontp) { mFallbackFontp = fontp; } + BOOL loadFace(const std::string& filename, const F32 point_size, const F32 vert_dpi, const F32 horz_dpi, const S32 components, BOOL is_fallback); + + typedef std::vector > font_vector_t; + + void setFallbackFonts(const font_vector_t &font); + const font_vector_t &getFallbackFonts() const; void setCharToGlyphMap(llwchar wch, U32 glyph_index) const; // Global font metrics - in units of pixels - virtual F32 getLineHeight() const; - virtual F32 getAscenderHeight() const; - virtual F32 getDescenderHeight() const; + F32 getLineHeight() const; + F32 getAscenderHeight() const; + F32 getDescenderHeight() const; // For a lowercase "g": @@ -148,48 +132,49 @@ public: const LLFontGlyphInfo &getMetrics(const llwchar wc) const; F32 getXAdvance(const llwchar wc) const; F32 getXKerning(const llwchar char_left, const llwchar char_right) const; // Get the kerning between the two characters - virtual void reset() = 0; + LLFontGlyphInfo* getGlyphInfo(const llwchar wch) const; + + void reset(F32 vert_dpi, F32 horz_dpi); + + void destroyGL(); + + const std::string& getName() const; + + const LLPointer getFontBitmapCache() const; static bool sOpenGLcrashOnRestart; -protected: - virtual BOOL hasGlyph(const llwchar wch) const; // Has a glyph for this character - virtual BOOL addChar(const llwchar wch) const; // Add a new character to the font if necessary - virtual BOOL addGlyph(const llwchar wch, const U32 glyph_index) const; // Add a new glyph to the existing font - virtual BOOL addGlyphFromFont(const LLFontFreetype *fontp, const llwchar wch, const U32 glyph_index) const; // Add a glyph from this font to the other (returns the glyph_index, 0 if not found) - - virtual LLFontGlyphInfo* getGlyphInfo(const llwchar wch) const; - - void insertGlyphInfo(llwchar wch, LLFontGlyphInfo* gi) const; +private: + void resetBitmapCache(); + void setSubImageLuminanceAlpha(const U32 x, const U32 y, const U32 bitmap_num, const U32 width, const U32 height, const U8 *data, S32 stride = 0) const; +public: + BOOL hasGlyph(const llwchar wch) const; // Has a glyph for this character + BOOL addGlyph(const llwchar wch) const; // Add a new character to the font if necessary +private: + BOOL addGlyphFromFont(const LLFontFreetype *fontp, const llwchar wch, const U32 glyph_index) const; // Add a glyph from this font to the other (returns the glyph_index, 0 if not found) void renderGlyph(const U32 glyph_index) const; - void resetBitmapCache(); + void insertGlyphInfo(llwchar wch, LLFontGlyphInfo* gi) const; -protected: std::string mName; + F32 mPointSize; F32 mAscender; F32 mDescender; F32 mLineHeight; - mutable LLPointer mFontBitmapCachep; - LLFT_Face mFTFace; BOOL mIsFallback; - LLFontList *mFallbackFontp; // A list of fallback fonts to look for glyphs in (for Unicode chars) + font_vector_t mFallbackFonts; // A list of fallback fonts to look for glyphs in (for Unicode chars) + + BOOL mValid; typedef std::map char_glyph_info_map_t; mutable char_glyph_info_map_t mCharGlyphInfoMap; // Information about glyph location in bitmap - BOOL mValid; - void setSubImageLuminanceAlpha(const U32 x, - const U32 y, - const U32 bitmap_num, - const U32 width, - const U32 height, - const U8 *data, - S32 stride = 0) const; + mutable LLPointer mFontBitmapCachep; + mutable S32 mRenderGlyphCount; mutable S32 mAddGlyphCount; }; diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp index 010dcf940..d3cac8628 100644 --- a/indra/llrender/llfontgl.cpp +++ b/indra/llrender/llfontgl.cpp @@ -84,7 +84,6 @@ F32 llfont_round_y(F32 y) } LLFontGL::LLFontGL() - : LLFontFreetype() { clearEmbeddedChars(); } @@ -96,66 +95,22 @@ LLFontGL::~LLFontGL() void LLFontGL::reset() { - if (!mIsFallback) - { - // This is the head of the list - need to rebuild ourself and all fallbacks. - loadFace(mName,mPointSize,sVertDPI,sHorizDPI,mFontBitmapCachep->getNumComponents(),mIsFallback); - if (mFallbackFontp==NULL) - { - llwarns << "LLFontGL::reset(), no fallback fonts present" << llendl; - } - else - { - for (LLFontList::iterator it = mFallbackFontp->begin(); - it != mFallbackFontp->end(); - ++it) - { - (*it)->reset(); - } - } - } - resetBitmapCache(); + mFontFreetype->reset(sVertDPI, sHorizDPI); } -bool findOrCreateFont(LLFontGL*& fontp, const LLFontDescriptor& desc) -{ - // Don't delete existing fonts, if any, here, because they've - // already been deleted by LLFontRegistry::clear() - fontp = LLFontGL::getFont(desc); - return (fontp != NULL); -} - - void LLFontGL::destroyGL() { - mFontBitmapCachep->destroyGL(); + mFontFreetype->destroyGL(); } BOOL LLFontGL::loadFace(const std::string& filename, const F32 point_size, const F32 vert_dpi, const F32 horz_dpi, const S32 components, BOOL is_fallback) { - if (!LLFontFreetype::loadFace(filename, point_size, vert_dpi, horz_dpi, components, is_fallback)) + if(mFontFreetype == reinterpret_cast(NULL)) { - return FALSE; - } - return TRUE; -} - - -BOOL LLFontGL::addChar(const llwchar wch) const -{ - if (!LLFontFreetype::addChar(wch)) - { - return FALSE; + mFontFreetype = new LLFontFreetype; } - stop_glerror(); - - LLFontGlyphInfo *glyph_info = getGlyphInfo(wch); - U32 bitmap_num = glyph_info->mBitmapNum; - LLImageGL *image_gl = mFontBitmapCachep->getImageGL(bitmap_num); - LLImageRaw *image_raw = mFontBitmapCachep->getImageRaw(bitmap_num); - image_gl->setSubImage(image_raw, 0, 0, image_gl->getWidth(), image_gl->getHeight()); - return TRUE; + return mFontFreetype->loadFace(filename, point_size, vert_dpi, horz_dpi, components, is_fallback); } static LLFastTimer::DeclareTimer FTM_RENDER_FONTS("Fonts"); @@ -255,13 +210,13 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons switch (valign) { case TOP: - cur_y -= llceil(mAscender); + cur_y -= llceil(mFontFreetype->getAscenderHeight()); break; case BOTTOM: - cur_y += llceil(mDescender); + cur_y += llceil(mFontFreetype->getDescenderHeight()); break; case VCENTER: - cur_y -= llceil((llceil(mAscender) - llceil(mDescender))/2.f); + cur_y -= llceil((llceil(mFontFreetype->getAscenderHeight()) - llceil(mFontFreetype->getDescenderHeight())) / 2.f); break; case BASELINE: // Baseline, do nothing. @@ -289,7 +244,7 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons F32 start_x = (F32)llround(cur_x); - const LLFontBitmapCache* font_bitmap_cache = mFontBitmapCachep; + const LLFontBitmapCache* font_bitmap_cache = mFontFreetype->getFontBitmapCache(); F32 inv_width = 1.f / font_bitmap_cache->getBitmapWidth(); F32 inv_height = 1.f / font_bitmap_cache->getBitmapHeight(); @@ -351,7 +306,7 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons // snap origin to whole screen pixel const F32 ext_x = (F32)llround(cur_render_x + (EXT_X_BEARING * sScaleX)); - const F32 ext_y = (F32)llround(cur_render_y + (EXT_Y_BEARING * sScaleY + mAscender - mLineHeight)); + const F32 ext_y = (F32)llround(cur_render_y + (EXT_Y_BEARING * sScaleY + mFontFreetype->getAscenderHeight() - mFontFreetype->getLineHeight())); LLRectf uv_rect(0.f, 1.f, 1.f, 0.f); LLRectf screen_rect(ext_x, ext_y + ext_height, ext_x + ext_width, ext_y); @@ -381,19 +336,20 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons } else { - if (!hasGlyph(wch)) + //new + /*if (!mFontFreetype->hasGlyph(wch)) { addChar(wch); - } + }*/ - const LLFontGlyphInfo* fgi= getGlyphInfo(wch); + const LLFontGlyphInfo* fgi= mFontFreetype->getGlyphInfo(wch); if (!fgi) { llerrs << "Missing Glyph Info" << llendl; break; } // Per-glyph bitmap texture. - LLImageGL *image_gl = mFontBitmapCachep->getImageGL(fgi->mBitmapNum); + LLImageGL *image_gl = font_bitmap_cache->getImageGL(fgi->mBitmapNum); if (last_bound_texture != image_gl) { gGL.getTexUnit(0)->bind(image_gl); @@ -428,11 +384,13 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons if (next_char && (next_char < LAST_CHARACTER)) { // Kern this puppy. - if (!hasGlyph(next_char)) + //new + /*if (!mFontFreetype->hasGlyph(next_char)) { addChar(next_char); - } - cur_x += getXKerning(wch, next_char); + }*/ + mFontFreetype->getGlyphInfo(next_char); + cur_x += mFontFreetype->getXKerning(wch, next_char); } // Round after kerning. @@ -454,7 +412,7 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons if (style & UNDERLINE) { - F32 descender = (F32)llfloor(mDescender); + F32 descender = (F32)llfloor(mFontFreetype->getDescenderHeight()); gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); gGL.begin(LLRender::LINES); @@ -507,6 +465,22 @@ S32 LLFontGL::renderUTF8(const std::string &text, S32 begin_offset, S32 x, S32 y return renderUTF8(text, begin_offset, (F32)x, (F32)y, color, halign, valign, style, shadow, S32_MAX, S32_MAX, NULL, FALSE); } +// font metrics - override for LLFontFreetype that returns units of virtual pixels +F32 LLFontGL::getAscenderHeight() const +{ + return mFontFreetype->getAscenderHeight() / sScaleY; +} + +F32 LLFontGL::getDescenderHeight() const +{ + return mFontFreetype->getDescenderHeight() / sScaleY; +} + +F32 LLFontGL::getLineHeight() const +{ + return (F32)llround(mFontFreetype->getLineHeight() / sScaleY); +} + S32 LLFontGL::getWidth(const std::string& utf8text) const { LLWString wtext = utf8str_to_wstring(utf8text); @@ -573,7 +547,7 @@ F32 LLFontGL::getWidthF32(const llwchar* wchars, const S32 begin_offset, const S } else { - cur_x += getXAdvance(wch); + cur_x += mFontFreetype->getXAdvance(wch); llwchar next_char = wchars[i+1]; if (((i + 1) < begin_offset + max_chars) @@ -581,7 +555,7 @@ F32 LLFontGL::getWidthF32(const llwchar* wchars, const S32 begin_offset, const S && (next_char < LAST_CHARACTER)) { // Kern this puppy. - cur_x += getXKerning(wch, next_char); + cur_x += mFontFreetype->getXKerning(wch, next_char); } } // Round after kerning. @@ -677,7 +651,7 @@ S32 LLFontGL::maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_ch } } - cur_x += getXAdvance(wch); + cur_x += mFontFreetype->getXAdvance(wch); if (scaled_max_pixels < cur_x) { @@ -688,7 +662,7 @@ S32 LLFontGL::maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_ch if (((i+1) < max_chars) && wchars[i+1]) { // Kern this puppy. - cur_x += getXKerning(wch, wchars[i+1]); + cur_x += mFontFreetype->getXKerning(wch, wchars[i+1]); } } // Round after kerning. @@ -743,7 +717,27 @@ S32 LLFontGL::firstDrawableChar(const llwchar* wchars, F32 max_pixels, S32 text_ llwchar wch = wchars[i]; const embedded_data_t* ext_data = getEmbeddedCharData(wch); - F32 char_width = ext_data ? getEmbeddedCharAdvance(ext_data) : getXAdvance(wch); + F32 char_width = 0; + + if(ext_data) + { + char_width = getEmbeddedCharAdvance(ext_data); + } + else + { + //new + const LLFontGlyphInfo* fgi= mFontFreetype->getGlyphInfo(wch); + + // last character uses character width, since the whole character needs to be visible + // other characters just use advance + char_width = (i == start) + ? (F32)(fgi->mWidth + fgi->mXBearing) // use actual width for last character + : fgi->mXAdvance; // use advance for all other characters + + //old + //const LLFontGlyphInfo* fgi= mFontFreetype->getGlyphInfo(wch); + //mFontFreetype->getXAdvance(wch); + } if( scaled_max_pixels < (total_width + char_width) ) { @@ -761,7 +755,7 @@ S32 LLFontGL::firstDrawableChar(const llwchar* wchars, F32 max_pixels, S32 text_ if ( i > 0 ) { // kerning - total_width += ext_data ? (EXT_KERNING * sScaleX) : getXKerning(wchars[i-1], wch); + total_width += ext_data ? (EXT_KERNING * sScaleX) : mFontFreetype->getXKerning(wchars[i-1], wch); } // Round after kerning. @@ -780,7 +774,6 @@ S32 LLFontGL::charFromPixelOffset(const llwchar* wchars, const S32 begin_offset, } F32 cur_x = 0; - S32 pos = 0; target_x *= sScaleX; @@ -789,9 +782,10 @@ S32 LLFontGL::charFromPixelOffset(const llwchar* wchars, const S32 begin_offset, F32 scaled_max_pixels = max_pixels * sScaleX; - for (S32 i = begin_offset; (i < max_index); i++) + S32 pos; + for (pos = begin_offset; pos < max_index; pos++) { - llwchar wch = wchars[i]; + llwchar wch = wchars[pos]; if (!wch) { break; // done @@ -826,8 +820,8 @@ S32 LLFontGL::charFromPixelOffset(const llwchar* wchars, const S32 begin_offset, pos++; cur_x += ext_advance; - if (((i + 1) < max_index) - && (wchars[(i + 1)])) + if (((pos + 1) < max_index) + && (wchars[(pos + 1)])) { cur_x += EXT_KERNING * sScaleX; } @@ -836,7 +830,7 @@ S32 LLFontGL::charFromPixelOffset(const llwchar* wchars, const S32 begin_offset, } else { - F32 char_width = getXAdvance(wch); + F32 char_width = mFontFreetype->getXAdvance(wch); if (round) { @@ -860,12 +854,11 @@ S32 LLFontGL::charFromPixelOffset(const llwchar* wchars, const S32 begin_offset, pos++; cur_x += char_width; - if (((i + 1) < max_index) - && (wchars[(i + 1)])) + if (((pos + 1) < max_index) + && (wchars[(pos + 1)])) { - llwchar next_char = wchars[i + 1]; // Kern this puppy. - cur_x += getXKerning(wch, next_char); + cur_x += mFontFreetype->getXKerning(wch, wchars[pos + 1]); } // Round after kerning. @@ -876,6 +869,10 @@ S32 LLFontGL::charFromPixelOffset(const llwchar* wchars, const S32 begin_offset, return pos; } +const LLFontDescriptor& LLFontGL::getFontDesc() const +{ + return mFontDescriptor; +} const LLFontGL::embedded_data_t* LLFontGL::getEmbeddedCharData(const llwchar wch) const { @@ -1041,9 +1038,11 @@ std::string LLFontGL::getStringFromStyle(U8 style) } return style_string; } + +// static std::string LLFontGL::nameFromFont(const LLFontGL* fontp) { - return fontp->getFontDesc().getName(); + return fontp->mFontDescriptor.getName(); } // static @@ -1249,7 +1248,7 @@ void LLFontGL::renderQuad(const LLRectf& screen_rect, const LLRectf& uv_rect, F3 void LLFontGL::drawGlyph(const LLRectf& screen_rect, const LLRectf& uv_rect, const LLColor4& color, U8 style, ShadowType shadow, F32 drop_shadow_strength) const { F32 slant_offset; - slant_offset = ((style & ITALIC) ? ( -mAscender * 0.2f) : 0.f); + slant_offset = ((style & ITALIC) ? ( -mFontFreetype->getAscenderHeight() * 0.2f) : 0.f); gGL.begin(LLRender::QUADS); { diff --git a/indra/llrender/llfontgl.h b/indra/llrender/llfontgl.h index 9476382eb..d7c47995d 100644 --- a/indra/llrender/llfontgl.h +++ b/indra/llrender/llfontgl.h @@ -28,23 +28,24 @@ #ifndef LL_LLFONTGL_H #define LL_LLFONTGL_H -#include "llfontfreetype.h" -#include "lltexture.h" -#include "v2math.h" #include "llcoord.h" -#include "llrect.h" - #include "llfontregistry.h" +#include "lltexture.h" +#include "llpointer.h" +#include "llrect.h" +#include "v2math.h" + +class LLImageGL; class LLColor4; - // Key used to request a font. class LLFontDescriptor; +class LLFontFreetype; // Structure used to store previously requested fonts. class LLFontRegistry; -class LLFontGL : public LLFontFreetype +class LLFontGL { public: enum HAlign @@ -88,7 +89,7 @@ public: void destroyGL(); - /* virtual*/ BOOL loadFace(const std::string& filename, const F32 point_size, const F32 vert_dpi, const F32 horz_dpi, const S32 components, BOOL is_fallback); + BOOL loadFace(const std::string& filename, const F32 point_size, const F32 vert_dpi, const F32 horz_dpi, const S32 components, BOOL is_fallback); S32 render(const LLWString &text, S32 begin_offset, const LLRect& rect, @@ -118,9 +119,9 @@ public: S32 renderUTF8(const std::string &text, S32 begin_offset, S32 x, S32 y, const LLColor4 &color, HAlign halign, VAlign valign, U8 style = NORMAL, ShadowType shadow = NO_SHADOW) const; // font metrics - override for LLFont that returns units of virtual pixels - /*virtual*/ F32 getLineHeight() const { return (F32)llround(mLineHeight / sScaleY); } - /*virtual*/ F32 getAscenderHeight() const { return (F32)llround(mAscender / sScaleY); } - /*virtual*/ F32 getDescenderHeight() const { return (F32)llround(mDescender / sScaleY); } + F32 getAscenderHeight() const; + F32 getDescenderHeight() const; + F32 getLineHeight() const; S32 getWidth(const std::string& utf8text) const; S32 getWidth(const llwchar* wchars) const; @@ -151,8 +152,7 @@ public: // Returns the index of the character closest to pixel position x (ignoring text to the right of max_pixels and max_chars) S32 charFromPixelOffset(const llwchar* wchars, const S32 char_offset, F32 x, F32 max_pixels=F32_MAX, S32 max_chars = S32_MAX, BOOL round = TRUE, BOOL use_embedded = FALSE) const; - const LLFontDescriptor &getFontDesc() const { return mFontDesc; } - void setFontDesc(const LLFontDescriptor& font_desc) { mFontDesc = font_desc; } + const LLFontDescriptor& getFontDesc() const; LLTexture *getTexture() const; @@ -217,19 +217,20 @@ public: static F32 sScaleY; static BOOL sDisplayFont ; static std::string sAppDir; // For loading fonts +private: + friend class LLFontRegistry; friend class LLTextBillboard; friend class LLHUDText; LLFontGL(const LLFontGL &source); LLFontGL &operator=(const LLFontGL &source); -protected: - /*virtual*/ BOOL addChar(const llwchar wch) const; protected: typedef std::map embedded_map_t; mutable embedded_map_t mEmbeddedChars; - LLFontDescriptor mFontDesc; + LLFontDescriptor mFontDescriptor; + LLPointer mFontFreetype; void renderQuad(const LLRectf& screen_rect, const LLRectf& uv_rect, F32 slant_amt) const; void drawGlyph(const LLRectf& screen_rect, const LLRectf& uv_rect, const LLColor4& color, U8 style, ShadowType shadow, F32 drop_shadow_fade) const; diff --git a/indra/llrender/llfontregistry.cpp b/indra/llrender/llfontregistry.cpp index fcfbc4c84..6f56a463e 100644 --- a/indra/llrender/llfontregistry.cpp +++ b/indra/llrender/llfontregistry.cpp @@ -421,7 +421,8 @@ LLFontGL *LLFontRegistry::createFont(const LLFontDescriptor& desc) llwarns << "createFont failed, no file names specified" << llendl; return NULL; } - LLFontList *fontlistp = new LLFontList; + + LLFontFreetype::font_vector_t fontlist; LLFontGL *result = NULL; // Snarf all fonts we can into fontlistp. First will get pulled @@ -466,19 +467,24 @@ LLFontGL *LLFontRegistry::createFont(const LLFontDescriptor& desc) is_first_found = false; } else - fontlistp->addAtEnd(fontp); + { + fontlist.push_back(fontp->mFontFreetype); + delete fontp; + fontp = NULL; + } } } - if (result && !fontlistp->empty()) + + if (result && !fontlist.empty()) { - result->setFallbackFont(fontlistp); + result->mFontFreetype->setFallbackFonts(fontlist); } - norm_desc.setStyle(match_desc->getStyle()); if (result) - result->setFontDesc(norm_desc); - - if (!result) + { + result->mFontDescriptor = desc; + } + else { llwarns << "createFont failed in some way" << llendl; } diff --git a/indra/llui/llresmgr.cpp b/indra/llui/llresmgr.cpp index 334ead62a..76cd4a5e3 100644 --- a/indra/llui/llresmgr.cpp +++ b/indra/llui/llresmgr.cpp @@ -36,6 +36,7 @@ #include "linden_common.h" #include "llresmgr.h" +#include "llimagegl.h" #include "llfontgl.h" #include "llerror.h" #include "llstring.h" diff --git a/indra/llui/llstyle.cpp b/indra/llui/llstyle.cpp index 90e538807..9551c98b8 100644 --- a/indra/llui/llstyle.cpp +++ b/indra/llui/llstyle.cpp @@ -33,6 +33,8 @@ #include "linden_common.h" #include "llstyle.h" + +#include "llfontgl.h" #include "llstring.h" #include "llui.h" diff --git a/indra/newview/llappviewerwin32.cpp b/indra/newview/llappviewerwin32.cpp index 5758fb5c4..a61f617c0 100644 --- a/indra/newview/llappviewerwin32.cpp +++ b/indra/newview/llappviewerwin32.cpp @@ -40,7 +40,8 @@ #include "llappviewerwin32.h" -#include "llwindowwin32.cpp" // *FIX: for setting gIconResource. +#include "llwindowwin32.h" // *FIX: for setting gIconResource. +#include "llgl.h" #include "res/resource.h" // *FIX: for setting gIconResource. #include //_O_APPEND diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp index 894b01b79..2a03092e1 100644 --- a/indra/newview/llviewerwindow.cpp +++ b/indra/newview/llviewerwindow.cpp @@ -60,6 +60,7 @@ #include "llaudioengine.h" // mute on minimize #include "llassetstorage.h" #include "llfontgl.h" +#include "llfontfreetype.h" #include "llmousehandler.h" #include "llrect.h" #include "llsky.h" From 030588caafa092e4f15532ba9cd25cac5355b4b8 Mon Sep 17 00:00:00 2001 From: Shyotl Date: Mon, 18 Nov 2013 09:57:35 -0600 Subject: [PATCH 3/4] Underwater shadows. --- .../shaders/class1/deferred/underWaterF.glsl | 2 +- indra/newview/llviewerdisplay.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl index 78f841c73..692df8b10 100644 --- a/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl +++ b/indra/newview/app_settings/shaders/class1/deferred/underWaterF.glsl @@ -151,7 +151,7 @@ void main() vec4 fb = texture2D(screenTex, distort); - frag_data[0] = vec4(linear_to_srgb(fb.rgb), 1.0); // diffuse + frag_data[0] = vec4(/*linear_to_srgb*/(fb.rgb), 1.0); // diffuse frag_data[1] = vec4(0.5,0.5,0.5, 0.95); // speccolor*spec, spec frag_data[2] = vec4(encode_normal(wavef), 0.0, 0.0); // normalxyz, displace } diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp index 92278c941..093f61d4f 100644 --- a/indra/newview/llviewerdisplay.cpp +++ b/indra/newview/llviewerdisplay.cpp @@ -725,6 +725,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo static LLCullResult result; LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD; + LLPipeline::sUnderWaterRender = LLViewerCamera::getInstance()->cameraUnderWater() ? TRUE : FALSE; gPipeline.updateCull(*LLViewerCamera::getInstance(), result, water_clip); stop_glerror(); @@ -949,7 +950,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo { gGL.setColorMask(true, true); - if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender) + if (LLPipeline::sRenderDeferred) { gPipeline.mDeferredScreen.bindTarget(); glClearColor(1,0,1,1); @@ -1035,7 +1036,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo } gGL.setColorMask(true, false); - if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender) + if (LLPipeline::sRenderDeferred) { gPipeline.renderGeomDeferred(*LLViewerCamera::getInstance()); } @@ -1071,7 +1072,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo if (to_texture) { - if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender) + if (LLPipeline::sRenderDeferred) { gPipeline.mDeferredScreen.flush(); if(gPipeline.mDeferredScreen.getFBO()) @@ -1098,7 +1099,7 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot, boo } //gGL.flush(); - if (LLPipeline::sRenderDeferred && !LLPipeline::sUnderWaterRender) + if (LLPipeline::sRenderDeferred) { gPipeline.renderDeferredLighting(); } From 8aa4d0fd27a5cfeec6d6b4203e3b4925dca20df1 Mon Sep 17 00:00:00 2001 From: Shyotl Date: Mon, 18 Nov 2013 09:58:21 -0600 Subject: [PATCH 4/4] Removed fasttimer that was hurting perf a tiny bit. --- indra/llrender/llvertexbuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp index 0c59d99c0..6b60481eb 100644 --- a/indra/llrender/llvertexbuffer.cpp +++ b/indra/llrender/llvertexbuffer.cpp @@ -2109,7 +2109,7 @@ bool LLVertexBuffer::bindGLBuffer(bool force_bind) if (useVBOs() && (force_bind || (mGLBuffer && (mGLBuffer != sGLRenderBuffer || !sVBOActive)))) { - LLFastTimer t(FTM_BIND_GL_BUFFER); + //LLFastTimer t(FTM_BIND_GL_BUFFER); /*if (sMapped) { llerrs << "VBO bound while another VBO mapped!" << llendl;