diff options
author | Andrey Kleshchev <andreykproductengine@lindenlab.com> | 2024-08-29 18:49:10 +0300 |
---|---|---|
committer | Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> | 2024-09-04 10:16:46 +0300 |
commit | a638d9610d9f369eca6dff74e8860ca466c253c7 (patch) | |
tree | e65ff848bd186e761891b2ca9d95c8026ed96274 /indra/llrender | |
parent | 2bae8dfb815cf4d04cb4882c2fb889e3fb9666b2 (diff) |
viewer#2411 LLFontGL::render optimizations #2
Diffstat (limited to 'indra/llrender')
-rw-r--r-- | indra/llrender/llfontgl.cpp | 3 | ||||
-rw-r--r-- | indra/llrender/llfontvertexbuffer.cpp | 119 | ||||
-rw-r--r-- | indra/llrender/llfontvertexbuffer.h | 15 |
3 files changed, 92 insertions, 45 deletions
diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp index 481e35c16a..701ab4d060 100644 --- a/indra/llrender/llfontgl.cpp +++ b/indra/llrender/llfontgl.cpp @@ -490,6 +490,9 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons if (draw_ellipses) { + // signal a separate context + buffer_list->emplace_back(nullptr, nullptr, 0, 0); + // recursively render ellipses at end of string // we've already reserved enough room gGL.pushUIMatrix(); diff --git a/indra/llrender/llfontvertexbuffer.cpp b/indra/llrender/llfontvertexbuffer.cpp index 3ff0771795..c4b68c4a6c 100644 --- a/indra/llrender/llfontvertexbuffer.cpp +++ b/indra/llrender/llfontvertexbuffer.cpp @@ -53,7 +53,8 @@ S32 LLFontVertexBuffer::render( F32 x, F32 y, const LLColor4& color, LLFontGL::HAlign halign, LLFontGL::VAlign valign, - U8 style, LLFontGL::ShadowType shadow, + U8 style, + LLFontGL::ShadowType shadow, S32 max_chars , S32 max_pixels, F32* right_x, bool use_ellipses, @@ -64,62 +65,33 @@ S32 LLFontVertexBuffer::render( genBuffers(fontp, text, begin_offset, x, y, color, halign, valign, style, shadow, max_chars, max_pixels, right_x, use_ellipses, use_color); } - else if (mLastX != x || mLastY != y || mLastColor != color) // always track position and alphs + else if (mLastX != x || mLastY != y + || mLastFont != fontp + || mLastColor != color // alphas change often + || mLastHalign != halign + || mLastValign != valign + || mLastOffset != begin_offset + || mLastMaxChars != max_chars + || mLastMaxPixels != max_pixels + || mLastStyle != style + || mLastShadow != shadow) // ex: buttons change shadow state { genBuffers(fontp, text, begin_offset, x, y, color, halign, valign, style, shadow, max_chars, max_pixels, right_x, use_ellipses, use_color); } - else if (true //mTrackStringChanges - && (mLastOffset != begin_offset - || mLastMaxChars != max_chars - || mLastMaxPixels != max_pixels - || mLastStringHash != sStringHasher._Do_hash(text))) // todo, track all parameters? + else if (mTrackStringChanges && mLastStringHash != sStringHasher._Do_hash(text)) { genBuffers(fontp, text, begin_offset, x, y, color, halign, valign, style, shadow, max_chars, max_pixels, right_x, use_ellipses, use_color); } else { + renderBuffers(); - gGL.flush(); // deliberately empty pending verts - gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE); - gGL.pushUIMatrix(); - - gGL.loadUIIdentity(); - - // Depth translation, so that floating text appears 'in-world' - // and is correctly occluded. - gGL.translatef(0.f, 0.f, LLFontGL::sCurDepth); - - gGL.setSceneBlendType(LLRender::BT_ALPHA); - - for (auto &buf_data : mBufferList) - { - if (buf_data.mImage) - { - gGL.getTexUnit(0)->bind(buf_data.mImage); - } - else - { - gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); - } - buf_data.mBuffer->setBuffer(); - - if (LLRender::sGLCoreProfile && buf_data.mMode == LLRender::QUADS) - { - buf_data.mBuffer->drawArrays(LLRender::TRIANGLES, 0, buf_data.mCount); - } - else - { - buf_data.mBuffer->drawArrays(buf_data.mMode, 0, buf_data.mCount); - } - } if (right_x) { *right_x = mLastRightX; } - - gGL.popUIMatrix(); } return mChars; } @@ -141,6 +113,7 @@ void LLFontVertexBuffer::genBuffers( mChars = fontp->render(text, begin_offset, x, y, color, halign, valign, style, shadow, max_chars, max_pixels, right_x, use_ellipses, use_color, &mBufferList); + mLastFont = fontp; mLastOffset = begin_offset; mLastMaxChars = max_chars; mLastMaxPixels = max_pixels; @@ -148,6 +121,10 @@ void LLFontVertexBuffer::genBuffers( mLastX = x; mLastY = y; mLastColor = color; + mLastHalign = halign; + mLastValign = valign; + mLastStyle = style; + mLastShadow = shadow; if (right_x) { @@ -155,3 +132,61 @@ void LLFontVertexBuffer::genBuffers( } } +void render_buffers(LLFontVertexBuffer::buffer_list_t::iterator iter, LLFontVertexBuffer::buffer_list_t::iterator end) +{ + gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE); + gGL.pushUIMatrix(); + + gGL.loadUIIdentity(); + + // Depth translation, so that floating text appears 'in-world' + // and is correctly occluded. + gGL.translatef(0.f, 0.f, LLFontGL::sCurDepth); + + gGL.setSceneBlendType(LLRender::BT_ALPHA); + + while (iter != end) + { + if (iter->mBuffer == nullptr) + { + // elipses indicator + iter++; + break; + } + if (iter->mImage) + { + gGL.getTexUnit(0)->bind(iter->mImage); + } + else + { + gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); + } + iter->mBuffer->setBuffer(); + + if (LLRender::sGLCoreProfile && iter->mMode == LLRender::QUADS) + { + iter->mBuffer->drawArrays(LLRender::TRIANGLES, 0, iter->mCount); + } + else + { + iter->mBuffer->drawArrays(iter->mMode, 0, iter->mCount); + } + iter++; + } + + if (iter != end) + { + gGL.pushUIMatrix(); + render_buffers(iter, end); + gGL.popUIMatrix(); + } + + gGL.popUIMatrix(); +} + +void LLFontVertexBuffer::renderBuffers() +{ + gGL.flush(); // deliberately empty pending verts + render_buffers(mBufferList.begin(), mBufferList.end()); +} + diff --git a/indra/llrender/llfontvertexbuffer.h b/indra/llrender/llfontvertexbuffer.h index bd42cf6c2d..458b0a91bb 100644 --- a/indra/llrender/llfontvertexbuffer.h +++ b/indra/llrender/llfontvertexbuffer.h @@ -46,12 +46,14 @@ public: F32 x, F32 y, const LLColor4& color, LLFontGL::HAlign halign = LLFontGL::LEFT, LLFontGL::VAlign valign = LLFontGL::BASELINE, - U8 style = LLFontGL::NORMAL, LLFontGL::ShadowType shadow = LLFontGL::NO_SHADOW, + U8 style = LLFontGL::NORMAL, + LLFontGL::ShadowType shadow = LLFontGL::NO_SHADOW, S32 max_chars = S32_MAX, S32 max_pixels = S32_MAX, F32* right_x = NULL, bool use_ellipses = false, bool use_color = true); + typedef std::list<LLFontGL::LLVertexBufferData> buffer_list_t; private: void genBuffers(const LLFontGL* fontp, @@ -60,15 +62,18 @@ private: F32 x, F32 y, const LLColor4& color, LLFontGL::HAlign halign, LLFontGL::VAlign valign, - U8 style, LLFontGL::ShadowType shadow, + U8 style, + LLFontGL::ShadowType shadow, S32 max_chars, S32 max_pixels, F32* right_x, bool use_ellipses, bool use_color); + void renderBuffers(); - std::list<LLFontGL::LLVertexBufferData> mBufferList; + buffer_list_t mBufferList; S32 mChars = 0; + const LLFontGL *mLastFont = nullptr; S32 mLastOffset = 0; S32 mLastMaxChars = 0; S32 mLastMaxPixels = 0; @@ -76,6 +81,10 @@ private: F32 mLastX = 0.f; F32 mLastY = 0.f; LLColor4 mLastColor; + LLFontGL::HAlign mLastHalign = LLFontGL::LEFT; + LLFontGL::VAlign mLastValign = LLFontGL::BASELINE; + U8 mLastStyle = LLFontGL::NORMAL; + LLFontGL::ShadowType mLastShadow = LLFontGL::NO_SHADOW; F32 mLastRightX = 0.f; bool mTrackStringChanges = true; |