From: Paul Wisbey
Date: Fri, 11 Dec 2015 17:05:13 +0000 (-0800)
Subject: Merge "Text - Add the color to the vertex info." into devel/master
X-Git-Tag: dali_1.1.15~9
X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=90925e62266ce32a326ba2458e9c3d1107244218;hp=538dde4e25666ad8658201f1dd3d6b6d226013cc
Merge "Text - Add the color to the vertex info." into devel/master
---
diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp
index f2c328e..0a90ef2 100644
--- a/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp
+++ b/dali-toolkit/internal/text/rendering/atlas/atlas-glyph-manager-impl.cpp
@@ -32,27 +32,30 @@ namespace
const char* VERTEX_SHADER = MAKE_SHADER(
attribute mediump vec2 aPosition;
attribute mediump vec2 aTexCoord;
+attribute mediump vec4 aColor;
uniform mediump vec2 uOffset;
uniform mediump mat4 uMvpMatrix;
varying mediump vec2 vTexCoord;
+varying mediump vec4 vColor;
void main()
{
mediump vec4 position = vec4( aPosition.xy + uOffset, 0.0, 1.0 );
gl_Position = uMvpMatrix * position;
vTexCoord = aTexCoord;
+ vColor = aColor;
}
);
const char* FRAGMENT_SHADER_L8 = MAKE_SHADER(
-uniform lowp vec4 uColor;
uniform sampler2D sTexture;
varying mediump vec2 vTexCoord;
+varying mediump vec4 vColor;
void main()
{
mediump vec4 color = texture2D( sTexture, vTexCoord );
- gl_FragColor = vec4( uColor.rgb, uColor.a * color.r );
+ gl_FragColor = vec4( vColor.rgb, vColor.a * color.r );
}
);
diff --git a/dali-toolkit/internal/text/rendering/atlas/atlas-manager.h b/dali-toolkit/internal/text/rendering/atlas/atlas-manager.h
index cf774b3..3449362 100644
--- a/dali-toolkit/internal/text/rendering/atlas/atlas-manager.h
+++ b/dali-toolkit/internal/text/rendering/atlas/atlas-manager.h
@@ -84,6 +84,7 @@ public:
{
Vector2 mPosition; ///< Vertex posiiton
Vector2 mTexCoords; ///< Vertex texture co-ordinates
+ Vector4 mColor; ///< Vertex color
};
struct Mesh2D
diff --git a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp
index e336e0b..33423eb 100644
--- a/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp
+++ b/dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp
@@ -59,12 +59,10 @@ struct AtlasRenderer::Impl
struct MeshRecord
{
MeshRecord()
- : mColor( Color::BLACK ),
- mAtlasId( 0 )
+ : mAtlasId( 0u )
{
}
- Vector4 mColor;
uint32_t mAtlasId;
AtlasManager::Mesh2D mMesh;
FrameBufferImage mBuffer;
@@ -82,7 +80,7 @@ struct AtlasRenderer::Impl
mRight( 0.0f ),
mUnderlinePosition( 0.0f ),
mUnderlineThickness( 0.0f ),
- mMeshRecordIndex( 0 )
+ mMeshRecordIndex( 0u )
{
}
@@ -142,6 +140,7 @@ struct AtlasRenderer::Impl
mQuadVertexFormat[ "aPosition" ] = Property::VECTOR2;
mQuadVertexFormat[ "aTexCoord" ] = Property::VECTOR2;
+ mQuadVertexFormat[ "aColor" ] = Property::VECTOR4;
mQuadIndexFormat[ "indices" ] = Property::INTEGER;
}
@@ -167,6 +166,7 @@ struct AtlasRenderer::Impl
void AddGlyphs( Text::ViewInterface& view,
const Vector& positions,
const Vector& glyphs,
+ const Vector& colors,
int depth )
{
AtlasManager::AtlasSlot slot;
@@ -177,7 +177,6 @@ struct AtlasRenderer::Impl
const Vector2& actorSize( view.GetControlSize() );
const Vector2 halfActorSize( actorSize * 0.5f );
- const Vector4& textColor( view.GetTextColor() );
const Vector2& shadowOffset( view.GetShadowOffset() );
const Vector4& shadowColor( view.GetShadowColor() );
const bool underlineEnabled( view.IsUnderlineEnabled() );
@@ -212,6 +211,7 @@ struct AtlasRenderer::Impl
Vector< TextCacheEntry > newTextCache;
const GlyphInfo* const glyphsBuffer = glyphs.Begin();
const Vector2* const positionsBuffer = positions.Begin();
+ const Vector4* const colorsBuffer = colors.Begin();
for( uint32_t i = 0, glyphSize = glyphs.Size(); i < glyphSize; ++i )
{
@@ -350,11 +350,23 @@ struct AtlasRenderer::Impl
}
}
+ // Get the color of the character.
+ const Vector4& color = *( colorsBuffer + i );
+
+ for( unsigned int index = 0u, size = newMesh.mVertices.Count();
+ index < size;
+ ++index )
+ {
+ AtlasManager::Vertex2D& vertex = *( verticesBuffer + index );
+
+ // Set the color of the vertex.
+ vertex.mColor = color;
+ }
+
// Find an existing mesh data object to attach to ( or create a new one, if we can't find one using the same atlas)
StitchTextMesh( meshContainer,
newMesh,
extents,
- textColor,
position.y + glyph.yBearing,
underlineGlyph,
currentUnderlinePosition,
@@ -371,7 +383,7 @@ struct AtlasRenderer::Impl
if( thereAreUnderlinedGlyphs )
{
// Check to see if any of the text needs an underline
- GenerateUnderlines( meshContainer, extents, underlineColor, textColor );
+ GenerateUnderlines( meshContainer, extents, underlineColor );
}
// For each MeshData object, create a mesh actor and add to the renderable actor
@@ -388,12 +400,23 @@ struct AtlasRenderer::Impl
// Create an effect if necessary
if( style == STYLE_DROP_SHADOW )
{
+ // Change the color of the vertices.
+ for( Vector::Iterator vIt = meshRecord.mMesh.mVertices.Begin(),
+ vEndIt = meshRecord.mMesh.mVertices.End();
+ vIt != vEndIt;
+ ++vIt )
+ {
+ AtlasManager::Vertex2D& vertex = *vIt;
+
+ vertex.mColor = shadowColor;
+ }
+
// Create a container actor to act as a common parent for text and shadow, to avoid color inheritence issues.
Actor containerActor = Actor::New();
containerActor.SetParentOrigin( ParentOrigin::CENTER );
containerActor.SetSize( actorSize );
- Actor shadowActor = Actor::New();
+ Actor shadowActor = CreateMeshActor( meshRecord, actorSize );
#if defined(DEBUG_ENABLED)
shadowActor.SetName( "Text Shadow renderable actor" );
#endif
@@ -401,16 +424,10 @@ struct AtlasRenderer::Impl
shadowActor.RegisterProperty("uOffset", shadowOffset );
if( actor.GetRendererCount() )
{
- Dali::Renderer renderer( actor.GetRendererAt( 0 ) );
- Geometry geometry = renderer.GetGeometry();
- Material material = renderer.GetMaterial();
-
- Dali::Renderer shadowRenderer = Dali::Renderer::New( geometry, material );
- shadowRenderer.SetDepthIndex( renderer.GetDepthIndex() - 1 );
- shadowActor.AddRenderer( shadowRenderer );
+ Dali::Renderer renderer( shadowActor.GetRendererAt( 0 ) );
+ renderer.SetDepthIndex( renderer.GetDepthIndex() - 1 );
shadowActor.SetParentOrigin( ParentOrigin::CENTER );
shadowActor.SetSize( actorSize );
- shadowActor.SetColor( shadowColor );
containerActor.Add( shadowActor );
containerActor.Add( actor );
actor = containerActor;
@@ -481,7 +498,6 @@ struct AtlasRenderer::Impl
actor.AddRenderer( renderer );
actor.SetParentOrigin( ParentOrigin::CENTER ); // Keep all of the origins aligned
actor.SetSize( actorSize );
- actor.SetColor( meshRecord.mColor );
actor.RegisterProperty("uOffset", Vector2::ZERO );
return actor;
}
@@ -489,7 +505,6 @@ struct AtlasRenderer::Impl
void StitchTextMesh( std::vector< MeshRecord >& meshContainer,
AtlasManager::Mesh2D& newMesh,
Vector< Extent >& extents,
- const Vector4& color,
float baseLine,
bool underlineGlyph,
float underlinePosition,
@@ -508,7 +523,7 @@ struct AtlasRenderer::Impl
mIt != mEndIt;
++mIt, ++index )
{
- if( slot.mAtlasId == mIt->mAtlasId && color == mIt->mColor )
+ if( slot.mAtlasId == mIt->mAtlasId )
{
// Append the mesh to the existing mesh and adjust any extents
Toolkit::Internal::AtlasMeshFactory::AppendMesh( mIt->mMesh, newMesh );
@@ -533,7 +548,6 @@ struct AtlasRenderer::Impl
MeshRecord meshRecord;
meshRecord.mAtlasId = slot.mAtlasId;
meshRecord.mMesh = newMesh;
- meshRecord.mColor = color;
meshContainer.push_back( meshRecord );
if( underlineGlyph )
@@ -640,8 +654,7 @@ struct AtlasRenderer::Impl
void GenerateUnderlines( std::vector< MeshRecord >& meshRecords,
Vector< Extent >& extents,
- const Vector4& underlineColor,
- const Vector4& textColor )
+ const Vector4& underlineColor )
{
AtlasManager::Mesh2D newMesh;
unsigned short faceIndex = 0;
@@ -693,18 +706,9 @@ struct AtlasRenderer::Impl
newMesh.mIndices.PushBack( faceIndex + 1u );
faceIndex += 4;
- if( underlineColor == textColor )
- {
- Toolkit::Internal::AtlasMeshFactory::AppendMesh( meshRecords[ index ].mMesh, newMesh );
- }
- else
- {
- MeshRecord record;
- record.mMesh = newMesh;
- record.mAtlasId = meshRecords[ index ].mAtlasId;
- record.mColor = underlineColor;
- meshRecords.push_back( record );
- }
+ vert.mColor = underlineColor;
+
+ Toolkit::Internal::AtlasMeshFactory::AppendMesh( meshRecords[ index ].mMesh, newMesh );
}
}
@@ -739,16 +743,23 @@ Actor AtlasRenderer::Render( Text::ViewInterface& view, int depth )
Vector positions;
positions.Resize( numberOfGlyphs );
+ Vector colors;
+ colors.Resize( numberOfGlyphs, view.GetTextColor() );
+
numberOfGlyphs = view.GetGlyphs( glyphs.Begin(),
positions.Begin(),
+ colors.Begin(),
0u,
numberOfGlyphs );
+
glyphs.Resize( numberOfGlyphs );
positions.Resize( numberOfGlyphs );
+ colors.Resize( numberOfGlyphs );
mImpl->AddGlyphs( view,
positions,
glyphs,
+ colors,
depth );
/* In the case where AddGlyphs does not create a renderable Actor for example when glyphs are all whitespace create a new Actor. */
diff --git a/dali-toolkit/internal/text/text-view-interface.h b/dali-toolkit/internal/text/text-view-interface.h
index 56439d2..409f9d7 100644
--- a/dali-toolkit/internal/text/text-view-interface.h
+++ b/dali-toolkit/internal/text/text-view-interface.h
@@ -78,7 +78,8 @@ public:
* @note The returned number of glyphs may be less than @p numberOfGlyphs if a line has ellipsis.
*
* @param[out] glyphs Pointer to a buffer where the glyphs are copied.
- * @param[out] glyphPositions Pointer to a buffer where the glyph positions are copied.
+ * @param[out] glyphPositions Pointer to a buffer where the glyph's positions are copied.
+ * @param[out] colors Pointer to a buffer where the glyph's colors are copied.
* @param[in] glyphIndex Index to the first glyph.
* @param[in] numberOfGlyphs Number of glyphs to be copied.
*
@@ -86,6 +87,7 @@ public:
*/
virtual Length GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
+ Vector4* glyphColors,
GlyphIndex glyphIndex,
Length numberOfGlyphs ) const = 0;
diff --git a/dali-toolkit/internal/text/text-view.cpp b/dali-toolkit/internal/text/text-view.cpp
index 8d10b2a..88ab012 100644
--- a/dali-toolkit/internal/text/text-view.cpp
+++ b/dali-toolkit/internal/text/text-view.cpp
@@ -84,6 +84,7 @@ Length View::GetNumberOfGlyphs() const
Length View::GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
+ Vector4* glyphColors,
GlyphIndex glyphIndex,
Length numberOfGlyphs ) const
{
diff --git a/dali-toolkit/internal/text/text-view.h b/dali-toolkit/internal/text/text-view.h
index 058ca9c..899474d 100644
--- a/dali-toolkit/internal/text/text-view.h
+++ b/dali-toolkit/internal/text/text-view.h
@@ -70,6 +70,7 @@ public:
*/
virtual Length GetGlyphs( GlyphInfo* glyphs,
Vector2* glyphPositions,
+ Vector4* glyphColors,
GlyphIndex glyphIndex,
Length numberOfGlyphs ) const;