2 * Copyright (c) 2014 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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/shader-effects/distance-field-effect.h>
26 void utc_distance_field_effect_startup(void)
28 test_return_value = TET_UNDEF;
31 void utc_distance_field_effect_cleanup(void)
33 test_return_value = TET_PASS;
38 // Create buffer image
39 BufferImage CreateDistanceField()
41 BufferImage image = BufferImage::New(256, 256, Pixel::RGBA8888);
42 BufferImage distanceFieldImage = BufferImage::New(256, 256, Pixel::L8);
44 PixelBuffer* pixbuf = image.GetBuffer();
46 for(size_t i=0; i<16; i++)
54 // GenerateDistanceFieldMap(distanceFieldImage.GetBuffer(), Size(256, 256), pixbuf, Size(256, 256), 8, 4);
56 return distanceFieldImage;
60 int UtcDaliDistanceFieldEffectUninitialized(void)
62 ToolkitTestApplication application;
64 Toolkit::DistanceFieldEffect effect;
68 // New() must be called to create a DistanceField effect or it wont be valid.
69 effect.SetShadow( true );
70 DALI_TEST_CHECK( false );
72 catch (Dali::DaliException& e)
74 // Tests that a negative test of an assertion succeeds
75 DALI_TEST_PRINT_ASSERT( e );
76 DALI_TEST_CHECK(!effect);
81 int UtcDaliDistanceFieldEffectPropertyNames(void)
83 ToolkitTestApplication application;
85 Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
87 // Check the names, this names are used in the shaders code,
88 // if they change the shader code has to be updated
89 DALI_TEST_EQUALS( effect.GetColorPropertyName(), "uColor", TEST_LOCATION );
90 DALI_TEST_EQUALS( effect.GetSmoothingPropertyName(), "uSmoothing", TEST_LOCATION );
93 DALI_TEST_EQUALS( effect.GetOutlineEnablePropertyName(), "uDoOutline", TEST_LOCATION );
94 DALI_TEST_EQUALS( effect.GetGlowEnablePropertyName(), "uDoGlow", TEST_LOCATION );
95 DALI_TEST_EQUALS( effect.GetShadowEnablePropertyName(), "uDoShadow", TEST_LOCATION );
97 DALI_TEST_EQUALS( effect.GetGlowBoundaryPropertyName(), "uGlowBoundary", TEST_LOCATION );
98 DALI_TEST_EQUALS( effect.GetGlowColorPropertyName(), "uGlowColor", TEST_LOCATION );
100 DALI_TEST_EQUALS( effect.GetOutlineColorPropertyName(), "uOutlineColor", TEST_LOCATION );
101 DALI_TEST_EQUALS( effect.GetOutlineSizePropertyName(), "uOutlineParams", TEST_LOCATION );
103 DALI_TEST_EQUALS( effect.GetShadowColorPropertyName(), "uShadowColor", TEST_LOCATION );
104 DALI_TEST_EQUALS( effect.GetShadowOffsetPropertyName(), "uShadowOffset", TEST_LOCATION );
109 int UtcDaliDistanceFieldEffectDefaultValues(void)
111 ToolkitTestApplication application;
113 Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
114 DALI_TEST_CHECK( effect );
116 BufferImage image = CreateDistanceField();
118 ImageActor actor = ImageActor::New( image );
119 actor.SetSize( 100.0f, 100.0f );
120 actor.SetShaderEffect( effect );
121 Stage::GetCurrent().Add( actor );
123 application.SendNotification();
124 application.Render();
127 application.GetGlAbstraction().CheckUniformValue(
128 effect.GetOutlineEnablePropertyName().c_str(),
132 application.GetGlAbstraction().CheckUniformValue(
133 effect.GetGlowEnablePropertyName().c_str(),
137 application.GetGlAbstraction().CheckUniformValue(
138 effect.GetShadowEnablePropertyName().c_str(),
143 int UtcDaliDistanceFieldEffectCustomValues(void)
145 ToolkitTestApplication application;
147 Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
148 DALI_TEST_CHECK( effect );
150 BufferImage image = CreateDistanceField();
152 ImageActor actor = ImageActor::New( image );
153 actor.SetSize( 100.0f, 100.0f );
155 effect.SetShadowColor(Color::YELLOW);
156 effect.SetGlowColor(Color::BLUE);
158 actor.SetShaderEffect( effect );
159 Stage::GetCurrent().Add( actor );
161 application.SendNotification();
162 application.Render();
164 // Gets converted to opengl viewport coordinates
166 application.GetGlAbstraction().CheckUniformValue(
167 effect.GetShadowColorPropertyName().c_str(),
171 application.GetGlAbstraction().CheckUniformValue(
172 effect.GetGlowColorPropertyName().c_str(),