mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-29 17:46:29 +03:00
Optimizations.
This commit is contained in:
@@ -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 ) */
|
||||
|
||||
@@ -174,7 +174,7 @@ class EE_API FontTrueType : public Font {
|
||||
|
||||
Page& getPage( unsigned int characterSize ) const;
|
||||
|
||||
typedef std::map<unsigned int, std::unique_ptr<Page>>
|
||||
typedef UnorderedMap<unsigned int, std::unique_ptr<Page>>
|
||||
PageTable; ///< Table mapping a character size to its page (texture)
|
||||
|
||||
void* mLibrary; ///< Pointer to the internal library interface (it is typeless to avoid exposing
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -49,6 +49,7 @@ template <typename T, typename U> inline T reinterpret( const U& input ) {
|
||||
} // namespace
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
using std::move;
|
||||
|
||||
static std::unordered_map<std::string, Uint32> fontsInternalIds;
|
||||
static std::atomic<Uint32> 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<Page>( mFontInternalId, name ) ) );
|
||||
mPages[characterSize] = std::make_unique<Page>( mFontInternalId, name );
|
||||
pageIt = mPages.find( characterSize );
|
||||
}
|
||||
return *pageIt->second;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <algorithm>
|
||||
#include <eepp/graphics/fontmanager.hpp>
|
||||
#include <eepp/graphics/fonttruetype.hpp>
|
||||
#include <eepp/graphics/globalbatchrenderer.hpp>
|
||||
#include <eepp/graphics/primitives.hpp>
|
||||
#include <eepp/scene/scenemanager.hpp>
|
||||
#include <eepp/system/luapattern.hpp>
|
||||
@@ -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<Int64>( 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 {
|
||||
|
||||
Reference in New Issue
Block a user