Text Atlas Renderer Fixes 40/38940/4
authorRichard Underhill <r.underhill@partner.samsung.com>
Thu, 30 Apr 2015 17:25:05 +0000 (18:25 +0100)
committerRichard Underhill <r.underhill@partner.samsung.com>
Tue, 5 May 2015 12:10:07 +0000 (13:10 +0100)
Change-Id: Id427d2be2c3cdc110ad4fba2ef3125ced62f7eca
Signed-off-by: Richard Underhill <r.underhill@partner.samsung.com>
dali-toolkit/internal/atlas-manager/atlas-manager-impl.cpp
dali-toolkit/internal/atlas-manager/atlas-manager-impl.h
dali-toolkit/internal/atlas-manager/atlas-manager.cpp
dali-toolkit/internal/atlas-manager/atlas-manager.h
dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp
dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.h
dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.cpp
dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager.h
dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp

index 4a55e59..d58daa9 100644 (file)
@@ -150,7 +150,6 @@ Toolkit::AtlasManager::AtlasId AtlasManager::CreateAtlas( const Toolkit::AtlasMa
   atlas.Upload( atlasDescriptor.mFilledPixelImage, 0, 0 );
 
   Sampler sampler = Sampler::New( atlas, "sTexture" );
-  sampler.SetFilterMode( Sampler::NEAREST, Sampler::NEAREST );
   sampler.SetProperty( Sampler::Property::AFFECTS_TRANSPARENCY, true );
   Shader shader;
   if ( pixelformat == Pixel::BGRA8888 )
@@ -163,6 +162,7 @@ Toolkit::AtlasManager::AtlasId AtlasManager::CreateAtlas( const Toolkit::AtlasMa
   }
   atlasDescriptor.mMaterial = Material::New( shader );
   atlasDescriptor.mMaterial.AddSampler( sampler );
+  atlasDescriptor.mSampler = sampler;
   atlasDescriptor.mMaterial.SetBlendMode( BlendingMode::ON );
   mAtlasList.push_back( atlasDescriptor );
   return mAtlasList.size();
@@ -840,6 +840,16 @@ Material AtlasManager::GetMaterial( AtlasId atlas ) const
   return null;
 }
 
+Sampler AtlasManager::GetSampler( AtlasId atlas ) const
+{
+  if ( atlas && atlas <= mAtlasList.size() )
+  {
+    return mAtlasList[ atlas -1u ].mSampler;
+  }
+  Sampler null;
+  return null;
+}
+
 } // namespace Internal
 
 } // namespace Toolkit
index 02a2e7d..8046f71 100644 (file)
@@ -67,6 +67,7 @@ public:
     BufferImage mFilledPixelImage;                                      // Image used by atlas for operations such as underline
     PixelBuffer* mStripBuffer;                                          // Blank image buffer used to pad upload
     Material mMaterial;                                                 // material used for atlas texture
+    Sampler mSampler;                                                   // sampler used for atlas texture
     SizeType mNextFreeBlock;                                            // next free block will be placed here ( actually +1 )
     Dali::Vector< SizeType > mFreeBlocksList;                           // unless there are any previously freed blocks
   };
@@ -183,6 +184,11 @@ public:
    */
   Material GetMaterial( AtlasId atlas ) const;
 
+/**
+   * @copydoc Toolkit::AtlasManager::GetSampler
+   */
+  Sampler GetSampler( AtlasId atlas ) const;
+
 private:
 
   std::vector< AtlasDescriptor > mAtlasList;        // List of atlases created
index 61c46f5..977c8dc 100644 (file)
@@ -136,6 +136,11 @@ Material AtlasManager::GetMaterial( AtlasId atlas ) const
   return GetImplementation(*this).GetMaterial( atlas );
 }
 
+Sampler AtlasManager::GetSampler( AtlasId atlas ) const
+{
+  return GetImplementation(*this).GetSampler( atlas );
+}
+
 } // namespace Toolkit
 
 } // namespace Dali
index 6f654ff..2b0c851 100644 (file)
@@ -196,7 +196,7 @@ public:
   struct Mesh2D
   {
     Vector< Vertex2D > mVertices;
-    Vector< unsigned short> mIndices;
+    Vector< unsigned int> mIndices;
   };
 
   /**
@@ -391,6 +391,14 @@ public:
    */
   Material GetMaterial( AtlasId atlas ) const;
 
+ /**
+   * @brief Get Sampler used by atlas
+   *
+   * @param atlas[in] atlas AtlasId
+   *
+   * @return Sampler used by atlas
+   */
+  Sampler GetSampler( AtlasId atlas ) const;
 private:
 
   explicit DALI_INTERNAL AtlasManager(Internal::AtlasManager *impl);
index 7bd8f18..3c21923 100644 (file)
@@ -149,6 +149,11 @@ Material AtlasGlyphManager::GetMaterial( uint32_t atlasId ) const
   return mAtlasManager.GetMaterial( atlasId );
 }
 
+Sampler AtlasGlyphManager::GetSampler( uint32_t atlasId ) const
+{
+  return mAtlasManager.GetSampler( atlasId );
+}
+
 const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics()
 {
   mMetrics.mGlyphCount = mGlyphRecords.Size();
index b6b31a1..20abcd2 100644 (file)
@@ -118,6 +118,11 @@ public:
   Material GetMaterial( uint32_t atlasId ) const;
 
   /**
+   * @copydoc Toolkit::AtlasGlyphManager::GetMaterial
+   */
+  Sampler GetSampler( uint32_t atlasId ) const;
+
+  /**
    * @copydoc Toolkit::AtlasGlyphManager::GetMetrics
    */
   const Toolkit::AtlasGlyphManager::Metrics& GetMetrics();
index d7a6a1b..f7ff0be 100644 (file)
@@ -123,11 +123,17 @@ Material AtlasGlyphManager::GetMaterial( uint32_t atlasId ) const
   return GetImplementation(*this).GetMaterial( atlasId );
 }
 
+Sampler AtlasGlyphManager::GetSampler( uint32_t atlasId ) const
+{
+  return GetImplementation(*this).GetSampler( atlasId );
+}
+
 const Toolkit::AtlasGlyphManager::Metrics& AtlasGlyphManager::GetMetrics()
 {
   return GetImplementation(*this).GetMetrics();
 }
 
+
 } // namespace Toolkit
 
 } // namespace Dali
index cf663c3..7a516e3 100644 (file)
@@ -155,6 +155,15 @@ public:
   Material GetMaterial( uint32_t atlasId ) const;
 
   /**
+   * @brief Get the sampler used by an atlas
+   *
+   * @param[in] atlasId Id of an atlas
+   *
+   * @return The sampler used by the atlas
+   */
+  Sampler GetSampler( uint32_t atlasId ) const;
+
+  /**
    * @brief Get Glyph Manager metrics
    *
    * @return const reference to glyph manager metrics
index f966dec..e3b4827 100644 (file)
@@ -361,9 +361,9 @@ struct AtlasRenderer::Impl : public ConnectionTracker
   Actor CreateMeshActor( const MeshRecord& meshRecord )
   {
     PropertyBuffer quadVertices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadVertexFormat, meshRecord.mMesh.mVertices.Size() );
-    PropertyBuffer quadIndices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadIndexFormat, meshRecord.mMesh.mIndices.Size() >> 1 );
+    PropertyBuffer quadIndices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadIndexFormat, meshRecord.mMesh.mIndices.Size() );
     quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ) );
-    quadIndices.SetData( const_cast< unsigned short* >( &meshRecord.mMesh.mIndices[ 0 ] ) );
+    quadIndices.SetData( const_cast< unsigned int* >( &meshRecord.mMesh.mIndices[ 0 ] ) );
 
     Geometry quadGeometry = Geometry::New();
     quadGeometry.AddVertexBuffer( quadVertices );
@@ -639,9 +639,9 @@ struct AtlasRenderer::Impl : public ConnectionTracker
     meshRecord.mBuffer = FrameBufferImage::New( width, height );
 
     // We will render a quad into this buffer
-    unsigned short indices[ 6 ] = { 1, 0, 2, 2, 3, 1 };
+    unsigned int indices[ 6 ] = { 1, 0, 2, 2, 3, 1 };
     PropertyBuffer quadVertices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadVertexFormat, 4u );
-    PropertyBuffer quadIndices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadIndexFormat, 3u );
+    PropertyBuffer quadIndices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadIndexFormat, sizeof(indices)/sizeof(indices[0]) );
 
     AtlasManager::Vertex2D vertices[ 4 ] = {
     { Vector2( tlx + shadowOffset.x, tly + shadowOffset.y ), Vector2( ZERO, ZERO ) },
@@ -661,14 +661,13 @@ struct AtlasRenderer::Impl : public ConnectionTracker
     material.AddSampler( sampler );
 
     Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, material );
-    renderer.SetDepthIndex( 0.1f );
+    renderer.SetDepthIndex( 1.0f );
     Actor actor = Actor::New();
     actor.AddRenderer( renderer );
     actor.SetSize( 1.0f, 1.0f );
 
     // Create a sub actor to render the source with normalized vertex positions
     Vector< AtlasManager::Vertex2D > normVertexList;
-    Vector< unsigned short > normIndexList;
     for ( uint32_t i = 0; i < verts.Size(); ++i )
     {
       AtlasManager::Vertex2D vertex = verts[ i ];
@@ -677,26 +676,18 @@ struct AtlasRenderer::Impl : public ConnectionTracker
       normVertexList.PushBack( vertex );
     }
 
-    // Reverse winding
-    for ( uint32_t i = 0; i < meshRecord.mMesh.mIndices.Size() / 3; ++i )
-    {
-      uint32_t index = i * 3;
-      normIndexList.PushBack( meshRecord.mMesh.mIndices[ index + 2 ] );
-      normIndexList.PushBack( meshRecord.mMesh.mIndices[ index + 1 ] );
-      normIndexList.PushBack( meshRecord.mMesh.mIndices[ index ] );
-    }
-
     PropertyBuffer normVertices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadVertexFormat, normVertexList.Size() );
-    PropertyBuffer normIndices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadIndexFormat, normIndexList.Size() >> 1 );
+    PropertyBuffer normIndices = PropertyBuffer::New( PropertyBuffer::STATIC, mQuadIndexFormat, meshRecord.mMesh.mIndices.Size() );
     normVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &normVertexList[ 0 ] ) );
-    normIndices.SetData( const_cast< unsigned short* >( &normIndexList[ 0 ] ) );
+    normIndices.SetData( const_cast< unsigned int* >( &meshRecord.mMesh.mIndices[ 0 ] ) );
 
     Geometry normGeometry = Geometry::New();
     normGeometry.AddVertexBuffer( normVertices );
     normGeometry.SetIndexBuffer( normIndices );
 
-    Material normMaterial = mGlyphManager.GetMaterial( meshRecord.mAtlasId );
-    normMaterial.SetShader( mShadowShader );
+    Material normMaterial = Material::New( mShadowShader );
+    Sampler normSampler =  mGlyphManager.GetSampler( meshRecord.mAtlasId );
+    normMaterial.AddSampler( normSampler );
     Dali::Renderer normRenderer = Dali::Renderer::New( normGeometry, normMaterial );
     Actor subActor = Actor::New();
     subActor.AddRenderer( normRenderer );
@@ -709,12 +700,12 @@ struct AtlasRenderer::Impl : public ConnectionTracker
     task.SetTargetFrameBuffer( meshRecord.mBuffer );
     task.SetSourceActor( subActor );
     task.SetClearEnabled( true );
-    task.SetClearColor( Vector4( 0.0f, 0.0f, 0.0f, 1.0f ) );
-    //task.SetClearColor( Color::BLUE );
+    task.SetClearColor( Vector4::ZERO );
     task.SetExclusive( true );
     task.SetRefreshRate( RenderTask::REFRESH_ONCE );
     task.FinishedSignal().Connect( this, &AtlasRenderer::Impl::RenderComplete );
     actor.Add( subActor );
+
     return actor;
   }