diff --git a/include/eepp/graphics/batchrenderer.hpp b/include/eepp/graphics/batchrenderer.hpp index f0c59efbf..50c6c1d6d 100644 --- a/include/eepp/graphics/batchrenderer.hpp +++ b/include/eepp/graphics/batchrenderer.hpp @@ -95,6 +95,10 @@ class EE_API BatchRenderer { * so if you were using another one will Draw all the batched vertexs first ) */ void batchQuad( const Float& x, const Float& y, const Float& width, const Float& height ); + /** Add to the batch a quad ( this will change your batch rendering method to PRIMITIVE_QUADS, + * so if you were using another one will Draw all the batched vertexs first ) */ + void batchQuad( const Rectf& rect ); + /** Add to the batch a quad with the vertex freely seted ( this will change your batch rendering * method to PRIMITIVE_QUADS, so if you were using another one will Draw all the batched vertexs * first ) */ diff --git a/include/eepp/graphics/fonttruetype.hpp b/include/eepp/graphics/fonttruetype.hpp index 7331873bd..237380ec5 100644 --- a/include/eepp/graphics/fonttruetype.hpp +++ b/include/eepp/graphics/fonttruetype.hpp @@ -174,7 +174,7 @@ class EE_API FontTrueType : public Font { Page& getPage( unsigned int characterSize ) const; - typedef std::map> + typedef UnorderedMap> PageTable; ///< Table mapping a character size to its page (texture) void* mLibrary; ///< Pointer to the internal library interface (it is typeless to avoid exposing diff --git a/src/eepp/graphics/batchrenderer.cpp b/src/eepp/graphics/batchrenderer.cpp index 36354173d..7147f0d5d 100644 --- a/src/eepp/graphics/batchrenderer.cpp +++ b/src/eepp/graphics/batchrenderer.cpp @@ -230,6 +230,77 @@ void BatchRenderer::batchQuad( const Float& x, const Float& y, const Float& widt } } +void BatchRenderer::batchQuad( const Rectf& rect ) { + if ( mNumVertex + ( GLi->quadsSupported() ? 3 : 5 ) >= mVertexSize ) + return; + + setDrawMode( PRIMITIVE_QUADS, mForceBlendMode ); + + if ( GLi->quadsSupported() ) { + mTVertex = &mVertex[mNumVertex]; + mTVertex->pos.x = rect.Left; + mTVertex->pos.y = rect.Top; + mTVertex->tex = mTexCoord[0]; + mTVertex->color = mVerColor[0]; + + mTVertex = &mVertex[mNumVertex + 1]; + mTVertex->pos.x = rect.Left; + mTVertex->pos.y = rect.Bottom; + mTVertex->tex = mTexCoord[1]; + mTVertex->color = mVerColor[1]; + + mTVertex = &mVertex[mNumVertex + 2]; + mTVertex->pos.x = rect.Right; + mTVertex->pos.y = rect.Bottom; + mTVertex->tex = mTexCoord[2]; + mTVertex->color = mVerColor[2]; + + mTVertex = &mVertex[mNumVertex + 3]; + mTVertex->pos.x = rect.Right; + mTVertex->pos.y = rect.Top; + mTVertex->tex = mTexCoord[3]; + mTVertex->color = mVerColor[3]; + + addVertexs( 4 ); + } else { + mTVertex = &mVertex[mNumVertex]; + mTVertex->pos.x = rect.Left; + mTVertex->pos.y = rect.Bottom; + mTVertex->tex = mTexCoord[1]; + mTVertex->color = mVerColor[1]; + + mTVertex = &mVertex[mNumVertex + 1]; + mTVertex->pos.x = rect.Left; + mTVertex->pos.y = rect.Top; + mTVertex->tex = mTexCoord[0]; + mTVertex->color = mVerColor[0]; + + mTVertex = &mVertex[mNumVertex + 2]; + mTVertex->pos.x = rect.Right; + mTVertex->pos.y = rect.Top; + mTVertex->tex = mTexCoord[3]; + mTVertex->color = mVerColor[3]; + + mTVertex = &mVertex[mNumVertex + 3]; + mTVertex->pos = mVertex[mNumVertex].pos; + mTVertex->tex = mTexCoord[1]; + mTVertex->color = mVerColor[1]; + + mTVertex = &mVertex[mNumVertex + 4]; + mTVertex->pos.x = rect.Right; + mTVertex->pos.y = rect.Bottom; + mTVertex->tex = mTexCoord[2]; + mTVertex->color = mVerColor[2]; + + mTVertex = &mVertex[mNumVertex + 5]; + mTVertex->pos = mVertex[mNumVertex + 2].pos; + mTVertex->tex = mTexCoord[3]; + mTVertex->color = mVerColor[3]; + + addVertexs( 6 ); + } +} + void BatchRenderer::batchQuadEx( Float x, Float y, Float width, Float height, Float angle, Vector2f scale, OriginPoint originPoint ) { if ( mNumVertex + ( GLi->quadsSupported() ? 3 : 5 ) >= mVertexSize ) diff --git a/src/eepp/graphics/fonttruetype.cpp b/src/eepp/graphics/fonttruetype.cpp index 920e640ef..86c5d4804 100644 --- a/src/eepp/graphics/fonttruetype.cpp +++ b/src/eepp/graphics/fonttruetype.cpp @@ -49,6 +49,7 @@ template inline T reinterpret( const U& input ) { } // namespace namespace EE { namespace Graphics { +using std::move; static std::unordered_map fontsInternalIds; static std::atomic fontInternalIdCounter{ 0 }; @@ -1163,8 +1164,7 @@ FontTrueType::Page& FontTrueType::getPage( unsigned int characterSize ) const { name += ":bold"; if ( mIsItalic ) name += ":italic"; - mPages.insert( - std::make_pair( characterSize, std::make_unique( mFontInternalId, name ) ) ); + mPages[characterSize] = std::make_unique( mFontInternalId, name ); pageIt = mPages.find( characterSize ); } return *pageIt->second; diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 7ced5a51b..27851003e 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -3415,20 +3416,22 @@ void UICodeEditor::drawMinimap( const Vector2f& start, minimapStartLine = eemax( 0, eemin( minimapStartLine, lineCount - maxMinmapLines ) ); } - Primitives primitives; - primitives.setForceDraw( false ); + GlobalBatchRenderer* BR = GlobalBatchRenderer::instance(); + BR->setTexture( nullptr ); + BR->setBlendMode( BlendMode::Alpha() ); + BR->quadsBegin(); if ( mMinimapConfig.drawBackground ) { - primitives.setColor( Color( mMinimapBackgroundColor ).blendAlpha( mAlpha ) ); - primitives.drawRectangle( rect ); + BR->quadsSetColor( Color( mMinimapBackgroundColor ).blendAlpha( mAlpha ) ); + BR->batchQuad( rect ); } - primitives.setColor( Color( mMinimapVisibleAreaColor ).blendAlpha( mAlpha ) ); - primitives.drawRectangle( + BR->quadsSetColor( Color( mMinimapVisibleAreaColor ).blendAlpha( mAlpha ) ); + BR->batchQuad( { { rect.Left, visibleY }, Sizef( rect.getWidth(), scrollerHeight ) } ); if ( mMinimapHover || mMinimapDragging ) { - primitives.setColor( Color( mMinimapHoverColor ).blendAlpha( mAlpha ) ); - primitives.drawRectangle( + BR->quadsSetColor( Color( mMinimapHoverColor ).blendAlpha( mAlpha ) ); + BR->batchQuad( { { rect.Left, visibleY }, Sizef( rect.getWidth(), scrollerHeight ) } ); } @@ -3452,8 +3455,8 @@ void UICodeEditor::drawMinimap( const Vector2f& start, } if ( batchWidth > 0 ) { - primitives.setColor( color.blendAlpha( mAlpha ) ); - primitives.drawRectangle( { { batchStart, lineY }, { batchWidth, charHeight } } ); + BR->quadsSetColor( color.blendAlpha( mAlpha ) ); + BR->batchQuad( { { batchStart, lineY }, { batchWidth, charHeight } } ); } batchSyntaxType = &type; @@ -3469,7 +3472,7 @@ void UICodeEditor::drawMinimap( const Vector2f& start, const String& line( mDoc->line( ln ).getText() ); if ( line.size() > 300 ) return; - primitives.setColor( Color( mMinimapHighlightColor ).blendAlpha( mAlpha ) ); + BR->quadsSetColor( Color( mMinimapHighlightColor ).blendAlpha( mAlpha ) ); do { pos = line.find( text, pos ); @@ -3482,7 +3485,7 @@ void UICodeEditor::drawMinimap( const Vector2f& start, selRect.Left = batchStart + getXOffsetCol( { ln, startCol } ) * widthScale; selRect.Right = batchStart + getXOffsetCol( { ln, endCol } ) * widthScale; if ( selRect.Left < minimapCutoffX ) - primitives.drawRectangle( selRect ); + BR->batchQuad( selRect ); pos = endCol; } else { break; @@ -3496,7 +3499,7 @@ void UICodeEditor::drawMinimap( const Vector2f& start, if ( !( ln >= range.start().line() && ln <= range.end().line() ) ) return; - primitives.setColor( backgroundColor ); + BR->quadsSetColor( backgroundColor ); const String& line = mDoc->line( ln ).getText(); Rectf selRect; @@ -3524,11 +3527,11 @@ void UICodeEditor::drawMinimap( const Vector2f& start, getXOffsetCol( { ln, static_cast( line.length() ) } ) * widthScale; } - primitives.drawRectangle( selRect ); + BR->batchQuad( selRect ); }; auto drawWordRanges = [&]( const TextRanges& ranges ) { - primitives.setColor( Color( mMinimapHighlightColor ).blendAlpha( mAlpha ) ); + BR->quadsSetColor( Color( mMinimapHighlightColor ).blendAlpha( mAlpha ) ); Int64 lineSkip = -1; for ( const auto& range : ranges ) { if ( !( range.start().line() >= minimapStartLine && range.end().line() <= endidx ) || @@ -3546,7 +3549,7 @@ void UICodeEditor::drawMinimap( const Vector2f& start, selRect.Bottom = selRect.Top + charHeight; selRect.Left = minimapStart + getXOffsetCol( range.start() ) * widthScale; selRect.Right = minimapStart + getXOffsetCol( range.end() ) * widthScale; - primitives.drawRectangle( selRect ); + BR->batchQuad( selRect ); if ( selRect.Left > minimapCutoffX ) lineSkip = range.start().line(); @@ -3679,10 +3682,11 @@ void UICodeEditor::drawMinimap( const Vector2f& start, Float selectionY = rect.Top + ( mDoc->getSelectionIndex( i ).start().line() - minimapStartLine ) * lineSpacing; - primitives.setColor( Color( mMinimapCurrentLineColor ).blendAlpha( mAlpha ) ); - primitives.drawRectangle( { { rect.Left, selectionY }, { rect.getWidth(), lineSpacing } } ); + BR->quadsSetColor( Color( mMinimapCurrentLineColor ).blendAlpha( mAlpha ) ); + BR->batchQuad( { { rect.Left, selectionY }, { rect.getWidth(), lineSpacing } } ); } - primitives.setForceDraw( true ); + + BR->draw(); } Vector2f UICodeEditor::getScreenStart() const {