2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.h>
22 #include <dali/dali.h>
23 #include <dali/integration-api/debug.h>
24 //#include <dali/public-api/actors/renderer.h>
25 #include <dali/public-api/text-abstraction/text-abstraction.h>
28 #include <dali-toolkit/internal/atlas-manager/atlas-manager.h>
29 #include <dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h>
30 #include <dali-toolkit/internal/text/rendering/shaders/text-basic-shader.h>
31 #if defined(DEBUG_ENABLED)
32 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Concise, true, "LOG_TEXT_ATLAS_RENDERER");
36 using namespace Dali::Toolkit;
37 using namespace Dali::Toolkit::Text;
41 const float ZERO( 0.0f );
42 const float HALF( 0.5f );
43 const float ONE( 1.0f );
44 const float TWO( 2.0f );
45 const uint32_t DEFAULT_ATLAS_WIDTH = 512u;
46 const uint32_t DEFAULT_ATLAS_HEIGHT = 512u;
48 #define MAKE_SHADER(A)#A
50 const char* VERTEX_SHADER = MAKE_SHADER(
51 attribute mediump vec2 aPosition;
52 attribute mediump vec2 aTexCoord;
53 uniform mediump mat4 uMvpMatrix;
54 uniform mediump vec3 uSize;
55 varying mediump vec2 vTexCoord;
59 mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
60 position.xyz *= uSize;
61 gl_Position = uMvpMatrix * position;
62 vTexCoord = aTexCoord;
66 const char* FRAGMENT_SHADER = MAKE_SHADER(
67 uniform sampler2D sTexture;
68 varying mediump vec2 vTexCoord;
72 //gl_FragColor = vec4( 1.0 );
73 gl_FragColor = texture2D( sTexture, vTexCoord );
77 const char* VERTEX_SHADER_SHADOW = MAKE_SHADER(
78 attribute mediump vec2 aPosition;
79 attribute mediump vec2 aTexCoord;
80 uniform mediump vec3 uSize;
81 varying mediump vec2 vTexCoord;
85 mediump vec4 position = vec4( aPosition, 0.0, 1.0 );
86 position.xyz *= uSize;
87 gl_Position = position;
88 vTexCoord = aTexCoord;
92 const char* FRAGMENT_SHADER_SHADOW = MAKE_SHADER(
93 uniform sampler2D sTexture;
94 uniform lowp vec4 uColor;
95 varying mediump vec2 vTexCoord;
99 mediump vec4 color = texture2D( sTexture, vTexCoord );
100 gl_FragColor = vec4(uColor.rgb, uColor.a*color.r);
105 struct AtlasRenderer::Impl : public ConnectionTracker
118 AtlasManager::Mesh2D mMesh;
119 FrameBufferImage mBuffer;
128 float mUnderlinePosition;
129 float mUnderlineThickness;
130 uint32_t mMeshRecordIndex;
136 Text::GlyphIndex mIndex;
142 uint32_t mNeededBlockWidth;
143 uint32_t mNeededBlockHeight;
148 mGlyphManager = AtlasGlyphManager::Get();
149 mFontClient = TextAbstraction::FontClient::Get();
151 mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
152 mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2;
153 mQuadIndexFormat[ "indices" ] = Property::UNSIGNED_INTEGER;
155 mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER );
156 mShadowShader = Shader::New( VERTEX_SHADER_SHADOW, FRAGMENT_SHADER_SHADOW );
159 void AddGlyphs( const std::vector<Vector2>& positions,
160 const Vector<GlyphInfo>& glyphs,
161 const Vector4& textColor,
162 const Vector2& shadowOffset,
163 const Vector4& shadowColor,
164 bool underlineEnabled,
165 const Vector4& underlineColor,
166 float underlineHeight )
168 AtlasManager::AtlasSlot slot;
169 std::vector< MeshRecord > meshContainer;
170 Vector< Extent > extents;
172 float currentUnderlinePosition = ZERO;
173 float currentUnderlineThickness = underlineHeight;
174 uint32_t currentBlockSize = 0;
175 FontId lastFontId = 0;
176 Style style = STYLE_NORMAL;
178 if ( fabsf( shadowOffset.x ) > Math::MACHINE_EPSILON_1 || fabsf( shadowOffset.y ) > Math::MACHINE_EPSILON_1 )
180 style = STYLE_DROP_SHADOW;
183 if ( mImageIds.Size() )
185 // Unreference any currently used glyphs
189 CalculateBlocksSize( glyphs );
191 for ( uint32_t i = 0; i < glyphs.Size(); ++i )
193 GlyphInfo glyph = glyphs[ i ];
195 // No operation for white space
196 if ( glyph.width && glyph.height )
198 // Are we still using the same fontId as previous
199 if ( glyph.fontId != lastFontId )
201 // We need to fetch fresh font underline metrics
202 FontMetrics fontMetrics;
203 mFontClient.GetFontMetrics( glyph.fontId, fontMetrics );
204 currentUnderlinePosition = ceil( fabsf( fontMetrics.underlinePosition ) );
205 float descender = ceil( fabsf( fontMetrics.descender ) );
207 if ( underlineHeight == ZERO )
209 currentUnderlineThickness = fontMetrics.underlineThickness;
211 // Ensure underline will be at least a pixel high
212 if ( currentUnderlineThickness < ONE )
214 currentUnderlineThickness = ONE;
218 currentUnderlineThickness = ceil( currentUnderlineThickness );
222 // Clamp the underline position at the font descender and check for ( as EFL describes it ) a broken font
223 if ( currentUnderlinePosition > descender )
225 currentUnderlinePosition = descender;
227 if ( ZERO == currentUnderlinePosition )
229 // Move offset down by one ( EFL behavior )
230 currentUnderlinePosition = ONE;
234 Vector2 position = positions[ i ];
235 AtlasManager::Mesh2D newMesh;
236 mGlyphManager.Cached( glyph.fontId, glyph.index, slot );
240 // This glyph already exists so generate mesh data plugging in our supplied position
241 mGlyphManager.GenerateMeshData( slot.mImageId, position, newMesh );
242 mImageIds.PushBack( slot.mImageId );
247 // Select correct size for new atlas if needed....?
248 if ( lastFontId != glyph.fontId )
250 for ( uint32_t j = 0; j < mBlockSizes.size(); ++j )
252 if ( mBlockSizes[ j ].mFontId == glyph.fontId )
254 currentBlockSize = j;
255 mGlyphManager.SetNewAtlasSize( DEFAULT_ATLAS_WIDTH,
256 DEFAULT_ATLAS_HEIGHT,
257 mBlockSizes[ j ].mNeededBlockWidth,
258 mBlockSizes[ j ].mNeededBlockHeight );
263 // Create a new image for the glyph
264 BufferImage bitmap = mFontClient.CreateBitmap( glyph.fontId, glyph.index );
266 // Ensure that the next image will fit into the current block size
267 bool setSize = false;
268 if ( bitmap.GetWidth() > mBlockSizes[ currentBlockSize ].mNeededBlockWidth )
271 mBlockSizes[ currentBlockSize ].mNeededBlockWidth = bitmap.GetWidth();
273 if ( bitmap.GetHeight() > mBlockSizes[ currentBlockSize ].mNeededBlockHeight )
276 mBlockSizes[ currentBlockSize ].mNeededBlockHeight = bitmap.GetHeight();
281 mGlyphManager.SetNewAtlasSize( DEFAULT_ATLAS_WIDTH,
282 DEFAULT_ATLAS_HEIGHT,
283 mBlockSizes[ currentBlockSize ].mNeededBlockWidth,
284 mBlockSizes[ currentBlockSize ].mNeededBlockHeight );
287 // Locate a new slot for our glyph
288 mGlyphManager.Add( glyph, bitmap, slot );
290 // Generate mesh data for this quad, plugging in our supplied position
293 mGlyphManager.GenerateMeshData( slot.mImageId, position, newMesh );
294 mImageIds.PushBack( slot.mImageId );
297 // Find an existing mesh data object to attach to ( or create a new one, if we can't find one using the same atlas)
298 StitchTextMesh( meshContainer,
302 position.y + glyph.yBearing,
303 currentUnderlinePosition,
304 currentUnderlineThickness,
306 lastFontId = glyph.fontId;
310 if ( underlineEnabled )
312 // Check to see if any of the text needs an underline
313 GenerateUnderlines( meshContainer, extents, underlineColor, textColor );
316 // For each MeshData object, create a mesh actor and add to the renderable actor
317 if ( meshContainer.size() )
319 for ( std::vector< MeshRecord >::iterator mIt = meshContainer.begin(); mIt != meshContainer.end(); ++mIt )
321 Actor actor = CreateMeshActor( *mIt );
323 // Create an effect if necessary
324 if ( style == STYLE_DROP_SHADOW )
326 actor.Add( GenerateShadow( *mIt, shadowOffset, shadowColor ) );
338 mActor.OffStageSignal().Connect( this, &AtlasRenderer::Impl::OffStageDisconnect );
340 #if defined(DEBUG_ENABLED)
341 Toolkit::AtlasGlyphManager::Metrics metrics = mGlyphManager.GetMetrics();
342 DALI_LOG_INFO( gLogFilter, Debug::Concise, "TextAtlasRenderer::GlyphManager::GlyphCount: %i, AtlasCount: %i, TextureMemoryUse: %iK\n",
344 metrics.mAtlasMetrics.mAtlasCount,
345 metrics.mAtlasMetrics.mTextureMemoryUsed / 1024 );
346 for ( uint32_t i = 0; i < metrics.mAtlasMetrics.mAtlasCount; ++i )
348 DALI_LOG_INFO( gLogFilter, Debug::Verbose, "Atlas [%i] %sPixels: %s Size: %ix%i, BlockSize: %ix%i, BlocksUsed: %i/%i\n",
349 i + 1, i > 8 ? "" : " ",
350 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mPixelFormat == Pixel::L8 ? "L8 " : "BGRA",
351 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mWidth,
352 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mHeight,
353 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mBlockWidth,
354 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mSize.mBlockHeight,
355 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mBlocksUsed,
356 metrics.mAtlasMetrics.mAtlasMetrics[ i ].mTotalBlocks );
361 Actor CreateMeshActor( const MeshRecord& meshRecord )
363 PropertyBuffer quadVertices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadVertexFormat, meshRecord.mMesh.mVertices.Size() );
364 PropertyBuffer quadIndices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadIndexFormat, meshRecord.mMesh.mIndices.Size() >> 1 );
365 quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ) );
366 quadIndices.SetData( const_cast< unsigned short* >( &meshRecord.mMesh.mIndices[ 0 ] ) );
368 Geometry quadGeometry = Geometry::New();
369 quadGeometry.AddVertexBuffer( quadVertices );
370 quadGeometry.SetIndexBuffer( quadIndices );
372 Material material = mGlyphManager.GetMaterial( meshRecord.mAtlasId );
373 Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material );
374 renderer.SetDepthIndex( 0 );
375 Actor actor = Actor::New();
376 actor.AddRenderer( renderer );
377 actor.SetSize( 1.0f, 1.0f );
378 actor.SetColor( meshRecord.mColor );
380 if ( meshRecord.mIsUnderline )
382 actor.SetColorMode( USE_OWN_COLOR );
386 actor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
391 void StitchTextMesh( std::vector< MeshRecord >& meshContainer,
392 AtlasManager::Mesh2D& newMesh,
393 Vector< Extent >& extents,
394 const Vector4& color,
396 float underlinePosition,
397 float underlineThickness,
398 AtlasManager::AtlasSlot& slot )
402 float left = newMesh.mVertices[ 0 ].mPosition.x;
403 float right = newMesh.mVertices[ 1 ].mPosition.x;
405 // Check to see if there's a mesh data object that references the same atlas ?
407 for ( std::vector< MeshRecord >::iterator mIt = meshContainer.begin(); mIt != meshContainer.end(); ++mIt, ++index )
409 if ( slot.mAtlasId == mIt->mAtlasId && color == mIt->mColor )
411 // Stitch the mesh to the existing mesh and adjust any extents
412 mGlyphManager.StitchMesh( mIt->mMesh, newMesh );
413 AdjustExtents( extents,
420 underlineThickness );
425 // No mesh data object currently exists that references this atlas, so create a new one
426 MeshRecord meshRecord;
427 meshRecord.mAtlasId = slot.mAtlasId;
428 meshRecord.mMesh = newMesh;
429 meshRecord.mColor = color;
430 meshRecord.mIsUnderline = false;
431 meshContainer.push_back( meshRecord );
433 // Adjust extents for this new meshrecord
434 AdjustExtents( extents,
436 meshContainer.size() - 1u,
441 underlineThickness );
446 void AdjustExtents( Vector< Extent >& extents,
447 std::vector< MeshRecord>& meshRecords,
452 float underlinePosition,
453 float underlineThickness )
455 bool foundExtent = false;
456 for ( Vector< Extent >::Iterator eIt = extents.Begin(); eIt != extents.End(); ++eIt )
458 if ( Equals( baseLine, eIt->mBaseLine ) )
461 if ( left < eIt->mLeft )
465 if ( right > eIt->mRight )
470 if ( underlinePosition > eIt->mUnderlinePosition )
472 eIt->mUnderlinePosition = underlinePosition;
474 if ( underlineThickness > eIt->mUnderlineThickness )
476 eIt->mUnderlineThickness = underlineThickness;
484 extent.mRight = right;
485 extent.mBaseLine = baseLine;
486 extent.mUnderlinePosition = underlinePosition;
487 extent.mUnderlineThickness = underlineThickness;
488 extent.mMeshRecordIndex = index;
489 extents.PushBack( extent );
493 // Unreference any glyphs that were used with this actor
494 void OffStageDisconnect( Dali::Actor actor )
501 for ( uint32_t i = 0; i < mImageIds.Size(); ++i )
503 mGlyphManager.Remove( mImageIds[ i ] );
505 mImageIds.Resize( 0 );
508 void CalculateBlocksSize( const Vector<GlyphInfo>& glyphs )
510 MaxBlockSize maxBlockSize;
511 for ( uint32_t i = 0; i < glyphs.Size(); ++i )
513 FontId fontId = glyphs[ i ].fontId;
514 bool foundFont = false;
515 for ( uint32_t j = 0; j < mBlockSizes.size(); ++j )
517 if ( mBlockSizes[ j ].mFontId == fontId )
524 FontMetrics fontMetrics;
525 mFontClient.GetFontMetrics( fontId, fontMetrics );
526 maxBlockSize.mNeededBlockWidth = static_cast< uint32_t >( fontMetrics.height );
527 maxBlockSize.mNeededBlockHeight = static_cast< uint32_t >( fontMetrics.height );
528 maxBlockSize.mFontId = fontId;
529 mBlockSizes.push_back( maxBlockSize );
534 void GenerateUnderlines( std::vector< MeshRecord>& meshRecords,
535 Vector< Extent >& extents,
536 const Vector4& underlineColor,
537 const Vector4& textColor )
539 AtlasManager::Mesh2D newMesh;
540 unsigned short faceIndex = 0;
541 for ( Vector< Extent >::ConstIterator eIt = extents.Begin(); eIt != extents.End(); ++eIt )
543 AtlasManager::Vertex2D vert;
544 uint32_t index = eIt->mMeshRecordIndex;
545 Vector2 uv = mGlyphManager.GetAtlasSize( meshRecords[ index ].mAtlasId );
547 // Make sure we don't hit texture edge for single pixel texture ( filled pixel is in top left of every atlas )
548 float u = HALF / uv.x;
549 float v = HALF / uv.y;
550 float thickness = eIt->mUnderlineThickness;
551 float baseLine = eIt->mBaseLine + eIt->mUnderlinePosition - ( thickness * HALF );
552 float tlx = eIt->mLeft;
553 float brx = eIt->mRight;
555 vert.mPosition.x = tlx;
556 vert.mPosition.y = baseLine;
557 vert.mTexCoords.x = ZERO;
558 vert.mTexCoords.y = ZERO;
559 newMesh.mVertices.PushBack( vert );
561 vert.mPosition.x = brx;
562 vert.mPosition.y = baseLine;
563 vert.mTexCoords.x = u;
564 newMesh.mVertices.PushBack( vert );
566 vert.mPosition.x = tlx;
567 vert.mPosition.y = baseLine + thickness;
568 vert.mTexCoords.x = ZERO;
569 vert.mTexCoords.y = v;
570 newMesh.mVertices.PushBack( vert );
572 vert.mPosition.x = brx;
573 vert.mPosition.y = baseLine + thickness;
574 vert.mTexCoords.x = u;
575 newMesh.mVertices.PushBack( vert );
577 // Six indices in counter clockwise winding
578 newMesh.mIndices.PushBack( faceIndex + 1u );
579 newMesh.mIndices.PushBack( faceIndex );
580 newMesh.mIndices.PushBack( faceIndex + 2u );
581 newMesh.mIndices.PushBack( faceIndex + 2u );
582 newMesh.mIndices.PushBack( faceIndex + 3u );
583 newMesh.mIndices.PushBack( faceIndex + 1u );
586 if ( underlineColor == textColor )
588 mGlyphManager.StitchMesh( meshRecords[ index ].mMesh, newMesh );
593 record.mMesh = newMesh;
594 record.mAtlasId = meshRecords[ index ].mAtlasId;
595 record.mColor = underlineColor;
596 record.mIsUnderline = true;
597 meshRecords.push_back( record );
602 Actor GenerateShadow( MeshRecord& meshRecord,
603 const Vector2& shadowOffset,
604 const Vector4& shadowColor )
606 // Scan vertex buffer to determine width and height of effect buffer needed
607 const Vector< AtlasManager::Vertex2D >& verts = meshRecord.mMesh.mVertices;
608 float tlx = verts[ 0 ].mPosition.x;
609 float tly = verts[ 0 ].mPosition.y;
613 for ( uint32_t i = 0; i < verts.Size(); ++i )
615 if ( verts[ i ].mPosition.x < tlx )
617 tlx = verts[ i ].mPosition.x;
619 if ( verts[ i ].mPosition.y < tly )
621 tly = verts[ i ].mPosition.y;
623 if ( verts[ i ].mPosition.x > brx )
625 brx = verts[ i ].mPosition.x;
627 if ( verts[ i ].mPosition.y > bry )
629 bry = verts[ i ].mPosition.y;
633 float width = brx - tlx;
634 float height = bry - tly;
635 float divWidth = TWO / width;
636 float divHeight = TWO / height;
638 // Create a buffer to render to
639 meshRecord.mBuffer = FrameBufferImage::New( width, height );
641 // We will render a quad into this buffer
642 unsigned short indices[ 6 ] = { 1, 0, 2, 2, 3, 1 };
643 PropertyBuffer quadVertices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadVertexFormat, 4u );
644 PropertyBuffer quadIndices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadIndexFormat, 3u );
646 AtlasManager::Vertex2D vertices[ 4 ] = {
647 { Vector2( tlx + shadowOffset.x, tly + shadowOffset.y ), Vector2( ZERO, ZERO ) },
648 { Vector2( brx + shadowOffset.x, tly + shadowOffset.y ), Vector2( ONE, ZERO ) },
649 { Vector2( tlx + shadowOffset.x, bry + shadowOffset.y ), Vector2( ZERO, ONE ) },
650 { Vector2( brx + shadowOffset.x, bry + shadowOffset.y ), Vector2( ONE, ONE ) } };
652 quadVertices.SetData( vertices );
653 quadIndices.SetData( indices );
655 Geometry quadGeometry = Geometry::New();
656 quadGeometry.AddVertexBuffer( quadVertices );
657 quadGeometry.SetIndexBuffer( quadIndices );
659 Sampler sampler = Sampler::New( meshRecord.mBuffer, "sTexture" );
660 Material material = Material::New( mShader );
661 material.AddSampler( sampler );
663 Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material );
664 renderer.SetDepthIndex( 0.1f );
665 Actor actor = Actor::New();
666 actor.AddRenderer( renderer );
667 actor.SetSize( 1.0f, 1.0f );
669 // Create a sub actor to render the source with normalized vertex positions
670 Vector< AtlasManager::Vertex2D > normVertexList;
671 Vector< unsigned short > normIndexList;
672 for ( uint32_t i = 0; i < verts.Size(); ++i )
674 AtlasManager::Vertex2D vertex = verts[ i ];
675 vertex.mPosition.x = ( ( vertex.mPosition.x - tlx ) * divWidth ) - ONE;
676 vertex.mPosition.y = ( ( vertex.mPosition.y - tly ) * divHeight ) - ONE;
677 normVertexList.PushBack( vertex );
681 for ( uint32_t i = 0; i < meshRecord.mMesh.mIndices.Size() / 3; ++i )
683 uint32_t index = i * 3;
684 normIndexList.PushBack( meshRecord.mMesh.mIndices[ index + 2 ] );
685 normIndexList.PushBack( meshRecord.mMesh.mIndices[ index + 1 ] );
686 normIndexList.PushBack( meshRecord.mMesh.mIndices[ index ] );
689 PropertyBuffer normVertices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadVertexFormat, normVertexList.Size() );
690 PropertyBuffer normIndices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadIndexFormat, normIndexList.Size() >> 1 );
691 normVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &normVertexList[ 0 ] ) );
692 normIndices.SetData( const_cast< unsigned short* >( &normIndexList[ 0 ] ) );
694 Geometry normGeometry = Geometry::New();
695 normGeometry.AddVertexBuffer( normVertices );
696 normGeometry.SetIndexBuffer( normIndices );
698 Material normMaterial = mGlyphManager.GetMaterial( meshRecord.mAtlasId );
699 normMaterial.SetShader( mShadowShader );
700 Dali::Renderer normRenderer = Dali::Renderer::New( normGeometry, normMaterial );
701 Actor subActor = Actor::New();
702 subActor.AddRenderer( normRenderer );
703 subActor.SetSize( 1.0f, 1.0f );
704 subActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR );
705 subActor.SetColor( shadowColor );
707 // Create a render task to render the effect
708 RenderTask task = Stage::GetCurrent().GetRenderTaskList().CreateTask();
709 task.SetTargetFrameBuffer( meshRecord.mBuffer );
710 task.SetSourceActor( subActor );
711 task.SetClearEnabled( true );
712 task.SetClearColor( Vector4( 0.0f, 0.0f, 0.0f, 1.0f ) );
713 //task.SetClearColor( Color::BLUE );
714 task.SetExclusive( true );
715 task.SetRefreshRate( RenderTask::REFRESH_ONCE );
716 task.FinishedSignal().Connect( this, &AtlasRenderer::Impl::RenderComplete );
717 actor.Add( subActor );
721 void RenderComplete( RenderTask& renderTask )
723 // Disconnect and remove this single shot render task
724 renderTask.FinishedSignal().Disconnect( this, &AtlasRenderer::Impl::RenderComplete );
725 Stage::GetCurrent().GetRenderTaskList().RemoveTask( renderTask );
727 // Get the actor used for render to buffer and remove it from the parent
728 Actor renderActor = renderTask.GetSourceActor();
731 Actor parent = renderActor.GetParent();
734 parent.Remove( renderActor );
739 Actor mActor; ///< The actor parent which renders the text
740 AtlasGlyphManager mGlyphManager; ///< Glyph Manager to handle upload and caching
741 Vector< uint32_t > mImageIds; ///< A list of imageIDs used by the renderer
742 TextAbstraction::FontClient mFontClient; ///> The font client used to supply glyph information
743 Shader mShader; ///> Shader used to render drop shadow buffer textures
744 Shader mShadowShader; ///> Shader used to render drop shadow into buffer
745 std::vector< MaxBlockSize > mBlockSizes; ///> Maximum size needed to contain a glyph in a block within a new atlas
746 std::vector< uint32_t > mFace; ///> Face indices for a quad
747 Property::Map mQuadVertexFormat;
748 Property::Map mQuadIndexFormat;
751 Text::RendererPtr AtlasRenderer::New()
753 return Text::RendererPtr( new AtlasRenderer() );
756 Actor AtlasRenderer::Render( Text::ViewInterface& view )
759 UnparentAndReset( mImpl->mActor );
761 Text::Length numberOfGlyphs = view.GetNumberOfGlyphs();
763 if( numberOfGlyphs > 0 )
765 Vector<GlyphInfo> glyphs;
766 glyphs.Resize( numberOfGlyphs );
768 view.GetGlyphs( &glyphs[0], 0, numberOfGlyphs );
770 std::vector<Vector2> positions;
771 positions.resize( numberOfGlyphs );
772 view.GetGlyphPositions( &positions[0], 0, numberOfGlyphs );
773 mImpl->AddGlyphs( positions,
776 view.GetShadowOffset(),
777 view.GetShadowColor(),
778 view.IsUnderlineEnabled(),
779 view.GetUnderlineColor(),
780 view.GetUnderlineHeight() );
782 return mImpl->mActor;
785 AtlasRenderer::AtlasRenderer()
791 AtlasRenderer::~AtlasRenderer()