2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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/dali.h>
21 #include <dali-test-suite-utils.h>
25 void utc_dali_shader_effect_startup(void)
27 test_return_value = TET_UNDEF;
30 void utc_dali_shader_effect_cleanup(void)
32 test_return_value = TET_PASS;
38 static const char* VertexSource =
41 " gl_Position = uProjection * uModelView * vec4(aPosition, 1.0);\n"
42 " vTexCoord = aTexCoord;\n"
45 static const char* FragmentSource =
48 " gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n"
51 static const char* FragmentSourceUsingExtensions =
54 " float floatValue = 0.5f;\n"
55 " float test = fwidth(floatValue);\n"
56 " gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;\n"
57 " gl_FragColor.a *= test;\n"
60 const int GETSOURCE_BUFFER_SIZE = 0x10000;
63 struct TestConstraintToVector3
65 TestConstraintToVector3(Vector3 target)
70 Vector3 operator()(const Vector3& current)
78 struct TestConstraintFromPositionToVector3
80 TestConstraintFromPositionToVector3()
84 Vector3 operator()(const Vector3& current, const PropertyInput& position)
87 return position.GetVector3();
91 struct TestConstraintToVector3Double
93 TestConstraintToVector3Double(Vector3 target)
98 Vector3 operator()(const Vector3& current)
100 return mTarget * 2.0f;
106 class ShaderEffectExtension : public ShaderEffect::Extension {};
109 class TestExtension : public ShaderEffect::Extension
112 TestExtension( bool& deleted )
132 int UtcDaliShaderEffectMethodNew01(void)
134 TestApplication application;
136 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
137 DALI_TEST_CHECK(effect);
141 int UtcDaliShaderEffectMethodNew02(void)
143 TestApplication application;
149 // New must be called to create a ShaderEffect or it wont be valid.
150 effect.SetUniform( "uUniform", 0 );
151 DALI_TEST_CHECK( false );
153 catch (Dali::DaliException& e)
155 // Tests that a negative test of an assertion succeeds
156 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
157 DALI_TEST_CHECK( !effect );
162 int UtcDaliShaderEffectMethodNew03(void)
164 TestApplication application;
166 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource, VertexSource, FragmentSource, ShaderEffect::HINT_NONE );
167 DALI_TEST_CHECK(effect);
171 int UtcDaliShaderEffectMethodNew04(void)
173 TestApplication application;
174 tet_infoline("Testing prefixed version of Dali::ShaderEffect::New()");
176 std::string fragmentShaderPrefix = "#define TEST_FS 1\n#extension GL_OES_standard_derivatives : enable";
177 std::string vertexShaderPrefix = "#define TEST_VS 1";
181 // Call render to compile default shaders.
182 application.SendNotification();
183 application.Render();
184 application.Render();
185 application.Render();
187 GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
188 ShaderEffect effect = ShaderEffect::NewWithPrefix( vertexShaderPrefix, VertexSource,
189 fragmentShaderPrefix, FragmentSourceUsingExtensions,
190 GEOMETRY_TYPE_IMAGE, ShaderEffect::HINT_NONE );
192 BitmapImage image = CreateBitmapImage();
193 ImageActor actor = ImageActor::New( image );
194 actor.SetSize( 100.0f, 100.0f );
195 actor.SetName("TestImageFilenameActor");
196 actor.SetShaderEffect(effect);
197 Stage::GetCurrent().Add(actor);
199 application.SendNotification();
200 application.Render();
201 GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
202 bool testResult = false;
204 // we should have compiled 4 shaders.
205 if (lastShaderCompiledAfter - lastShaderCompiledBefore == 4)
207 char testVertexSourceResult[GETSOURCE_BUFFER_SIZE];
208 char testFragmentSourceResult[GETSOURCE_BUFFER_SIZE];
210 // we are interested in the first two.
211 GLuint vertexShaderId = lastShaderCompiledBefore + 1;
212 GLuint fragmentShaderId = lastShaderCompiledBefore + 2;
214 GLsizei lengthVertexResult;
215 GLsizei lengthFragmentResult;
217 application.GetGlAbstraction().GetShaderSource(vertexShaderId, GETSOURCE_BUFFER_SIZE, &lengthVertexResult, testVertexSourceResult);
218 application.GetGlAbstraction().GetShaderSource(fragmentShaderId, GETSOURCE_BUFFER_SIZE, &lengthFragmentResult, testFragmentSourceResult);
220 int vertexShaderHasPrefix = strncmp(testVertexSourceResult, "#define ", strlen("#define "));
221 int fragmentShaderHasPrefix = strncmp(testFragmentSourceResult, "#define ", strlen("#define "));
222 testResult = (vertexShaderHasPrefix == 0) && (fragmentShaderHasPrefix == 0);
225 DALI_TEST_CHECK(testResult);
227 catch(Dali::DaliException& e)
229 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
230 tet_result( TET_FAIL );
235 int UtcDaliShaderEffectMethodNew05(void)
237 TestApplication application;
239 // heap constructor / destructor
240 DefaultFunctionCoverage<ShaderEffect> shaderEffect;
241 DefaultFunctionCoverage<ShaderEffectExtension> shaderEffectExtension;
246 int UtcDaliShaderEffectMethodNew06(void)
248 TestApplication application;
249 tet_infoline("Testing Dali::ShaderEffect::New() with shader sources for different geometry types");
251 ShaderEffect effect = ShaderEffect::New( "imageVertexShader", "imageFragmentShader",
252 "textVertexShader", "textFragmentShader",
253 "texturedMeshVertexShader", "texturedMeshFragmentShader",
254 "meshVertexShader", "meshFragmentShader",
255 ShaderEffect::HINT_NONE );
256 DALI_TEST_CHECK(effect);
261 int UtcDaliShaderEffectMethodDownCast(void)
263 TestApplication application;
264 tet_infoline("Testing Dali::ShaderEffect::DownCast()");
266 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
268 BaseHandle object(effect);
270 ShaderEffect effect2 = ShaderEffect::DownCast(object);
271 DALI_TEST_CHECK(effect2);
273 ShaderEffect effect3 = DownCast< ShaderEffect >(object);
274 DALI_TEST_CHECK(effect3);
276 BaseHandle unInitializedObject;
277 ShaderEffect effect4 = ShaderEffect::DownCast(unInitializedObject);
278 DALI_TEST_CHECK(!effect4);
280 ShaderEffect effect5 = DownCast< ShaderEffect >(unInitializedObject);
281 DALI_TEST_CHECK(!effect5);
285 int UtcDaliShaderEffectMethodDelete01(void)
287 TestApplication application;
289 // Only want to test the first few characters
290 std::string customFontPrefixVertShader =
292 " attribute mediump vec3 aPosition;\n"
293 " attribute mediump vec2 aTexCoord;\n";
296 // get the default shaders built, this is not required but makes it
297 // easier to debug the TET case and isolate the custom shader compilation.
298 application.SendNotification();
299 application.Render();
301 application.SendNotification();
302 application.Render();
304 // create a new shader effect
305 // the vertex and fragment shader will be cached in the ShaderFactory
306 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource);
308 // destroy the shader effect
311 // Create the same shader effect again, this should now use the cached version
312 // held in the shader factory
313 effect= ShaderEffect::New( VertexSource, FragmentSource );
315 // Compile the shader effect
316 application.SendNotification();
317 application.Render();
319 GLuint lastShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled();
321 // get the vertex shader (compiled before fragment shader).
322 // this last shaders compiled is for text.
323 GLuint vertexShaderId = lastShaderCompiled-1;
324 GLsizei lengthVertexResult;
326 char testVertexSourceResult[GETSOURCE_BUFFER_SIZE];
327 application.GetGlAbstraction().GetShaderSource(vertexShaderId, GETSOURCE_BUFFER_SIZE, &lengthVertexResult, testVertexSourceResult);
329 // compare the first 40 bytes of the vertex shader sent to be compiled, with
330 // the shader string that ended up being compiled (in the render task)
331 // this is to confirm the string hasn't been deleted / corrupted.
332 int testPassed = strncmp( testVertexSourceResult , customFontPrefixVertShader.c_str(), 40 ) ;
334 DALI_TEST_CHECK( testPassed == 0 );
339 int UtcDaliShaderEffectMethodSetUniformFloat(void)
341 TestApplication application;
343 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
344 DALI_TEST_CHECK( effect );
346 BitmapImage image = CreateBitmapImage();
348 effect.SetUniform( "uFloat", 1.0f );
350 ImageActor actor = ImageActor::New( image );
351 actor.SetSize( 100.0f, 100.0f );
352 actor.SetName("TestImageFilenameActor");
353 actor.SetShaderEffect(effect);
354 Stage::GetCurrent().Add(actor);
356 application.SendNotification();
357 application.Render();
360 application.GetGlAbstraction().CheckUniformValue(
365 int UtcDaliShaderEffectMethodSetUniformVector2(void)
367 TestApplication application;
369 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
370 DALI_TEST_CHECK( effect );
372 BitmapImage image = CreateBitmapImage();
374 effect.SetUniform( "uVec2", Vector2( 2.0f, 3.0f ) );
376 ImageActor actor = ImageActor::New( image );
377 actor.SetSize( 100.0f, 100.0f );
378 actor.SetName("TestImageFilenameActor");
379 actor.SetShaderEffect(effect);
380 Stage::GetCurrent().Add(actor);
382 application.SendNotification();
383 application.Render();
386 application.GetGlAbstraction().CheckUniformValue(
387 "uVec2", Vector2( 2.0f, 3.0f ) ) );
391 int UtcDaliShaderEffectMethodSetUniformVector3(void)
393 TestApplication application;
395 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
396 DALI_TEST_CHECK( effect );
398 BitmapImage image = CreateBitmapImage();
400 effect.SetUniform( "uVec3", Vector3( 4.0f, 5.0f, 6.0f ) );
402 ImageActor actor = ImageActor::New( image );
403 actor.SetSize( 100.0f, 100.0f );
404 actor.SetName("TestImageFilenameActor");
405 actor.SetShaderEffect(effect);
406 Stage::GetCurrent().Add(actor);
408 application.SendNotification();
409 application.Render();
412 application.GetGlAbstraction().CheckUniformValue(
413 "uVec3", Vector3( 4.0f, 5.0f, 6.0f ) ) );
417 int UtcDaliShaderEffectMethodSetUniformVector4(void)
419 TestApplication application;
421 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
422 DALI_TEST_CHECK( effect );
424 BitmapImage image = CreateBitmapImage();
426 effect.SetUniform( "uVec4", Vector4( 7.0f, 8.0f, 9.0f, 10.0f ) );
428 ImageActor actor = ImageActor::New( image );
429 actor.SetSize( 100.0f, 100.0f );
430 actor.SetName("TestImageFilenameActor");
431 actor.SetShaderEffect(effect);
432 Stage::GetCurrent().Add(actor);
434 application.SendNotification();
435 application.Render();
438 application.GetGlAbstraction().CheckUniformValue(
439 "uVec4", Vector4( 7.0f, 8.0f, 9.0f, 10.0f ) ) );
443 int UtcDaliShaderEffectMethodSetUniformMatrix(void)
445 TestApplication application;
447 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
448 DALI_TEST_CHECK( effect );
450 BitmapImage image = CreateBitmapImage();
452 effect.SetUniform( "uModelView", Matrix::IDENTITY );
454 ImageActor actor = ImageActor::New( image );
455 actor.SetSize( 100.0f, 100.0f );
456 actor.SetName("TestImageFilenameActor");
457 actor.SetShaderEffect(effect);
458 Stage::GetCurrent().Add(actor);
460 application.SendNotification();
461 application.Render();
464 application.GetGlAbstraction().CheckUniformValue(
465 "uModelView", Matrix::IDENTITY ) );
469 int UtcDaliShaderEffectMethodSetUniformMatrix3(void)
471 TestApplication application;
473 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
474 DALI_TEST_CHECK( effect );
476 BitmapImage image = CreateBitmapImage();
478 Matrix3 matIdentity(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
479 effect.SetUniform( "uMatrix3", matIdentity );
481 ImageActor actor = ImageActor::New( image );
482 actor.SetSize( 100.0f, 100.0f );
483 actor.SetName("TestImageFilenameActor");
484 actor.SetShaderEffect(effect);
485 Stage::GetCurrent().Add(actor);
487 application.SendNotification();
488 application.Render();
490 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue("uMatrix3", matIdentity) );
494 int UtcDaliShaderEffectMethodSetUniformViewport(void)
496 TestApplication application;
498 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
499 DALI_TEST_CHECK( effect );
501 BitmapImage image = CreateBitmapImage();
503 ImageActor actor = ImageActor::New( image );
504 actor.SetSize( 100.0f, 100.0f );
505 actor.SetName("TestImageFilenameActor");
506 actor.SetShaderEffect(effect);
507 Stage::GetCurrent().Add(actor);
509 effect.SetUniform( "uVec2", Vector2( 0.0f, 0.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION );
510 effect.SetUniform( "uVec2Dir", Vector2( 1.0f, 2.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION );
512 application.SendNotification();
513 application.Render();
515 const Vector2& stageSize(Stage::GetCurrent().GetSize());
518 application.GetGlAbstraction().CheckUniformValue(
519 "uVec2", Vector2( stageSize.x/2, -stageSize.y/2 ) ) );
522 application.GetGlAbstraction().CheckUniformValue(
523 "uVec2Dir", Vector2( -1.0f, 2.0f ) ) );
527 int UtcDaliShaderEffectMethodSetEffectImage(void)
529 TestApplication application;
531 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
532 DALI_TEST_CHECK( effect );
534 BitmapImage image = CreateBitmapImage();
536 effect.SetEffectImage(image);
538 ImageActor actor = ImageActor::New( image );
539 actor.SetSize( 100.0f, 100.0f );
540 actor.SetName("TestImageFilenameActor");
541 actor.SetShaderEffect(effect);
542 Stage::GetCurrent().Add(actor);
544 application.SendNotification();
545 application.Render(16);
546 application.SendNotification();
547 application.Render(16);
548 application.SendNotification();
550 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "sEffect", 1 ) );
554 int UtcDaliShaderEffectMethodSetEffectImageAndDelete(void)
556 TestApplication application;
558 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
560 BitmapImage effectImage = CreateBitmapImage();
561 effect.SetEffectImage(effectImage);
563 ImageActor actor = ImageActor::New();
565 actor.SetShaderEffect(effect);
568 Stage::GetCurrent().Add(actor);
570 // do an update / render cycle
571 application.SendNotification();
572 application.Render(16);
573 application.SendNotification();
574 application.Render(16);
575 application.SendNotification();
576 application.Render(16);
578 printf("removing image actor from stage and Reseting handle\n");
579 Stage::GetCurrent().Remove(actor);
582 tet_printf("### Update & Render \n");
584 application.SendNotification();
585 application.Render(16);
587 tet_printf("#### Update Only \n");
589 tet_printf("effectImage.Reset \n");
591 // this releases the effect texture resource,
592 // Update will send a DispatchDiscardTexture message to render
594 application.SendNotification();
595 application.UpdateOnly(16);
597 tet_printf("#### Update Only \n");
599 // at this point shader is deleted, during clear discard queue
600 // and it sends a Shader:: DispatchRemoveObserver message to render thread
601 application.UpdateOnly(16);
603 tet_printf("#### Render Only \n");
604 // This is where it used to crash, there is a message in the queue to perform DispatchDiscardTexture
605 // which tries to call observer->TextureDiscarded, where observer == shader that was deleted
606 // in previous update.
607 application.RenderOnly();
610 // process the discard texture message
611 application.RenderOnly();
612 application.SendNotification();
613 application.Render(16);
615 tet_result(TET_PASS);
620 int UtcDaliShaderEffectMethodApplyConstraint(void)
622 // Test whether Shader's uniform can be constrained to a stationary constraint.
623 TestApplication application;
625 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
626 DALI_TEST_CHECK( effect );
628 BitmapImage image = CreateBitmapImage();
630 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
632 ImageActor actor = ImageActor::New( image );
633 actor.SetSize( 100.0f, 100.0f );
634 actor.SetName("TestImageFilenameActor");
635 actor.SetShaderEffect(effect);
636 Stage::GetCurrent().Add(actor);
638 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
640 application.SendNotification();
641 application.Render();
643 // Test effects of SetUniform...
645 application.GetGlAbstraction().CheckUniformValue(
646 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
648 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
649 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
651 effect.ApplyConstraint(constraint);
653 application.SendNotification();
654 application.Render();
656 // Test effects of Constraint.
658 application.GetGlAbstraction().CheckUniformValue(
659 "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) );
664 int UtcDaliShaderEffectMethodApplyConstraintFromActor(void)
666 // Test whether Shader's uniform can be constrained to Actor's position.
667 TestApplication application;
669 const Vector3 targetPosition = Vector3( 100.0f, 70.0f, 20.0f);
671 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
672 DALI_TEST_CHECK( effect );
674 BitmapImage image = CreateBitmapImage();
676 effect.SetUniform( "uVec3", Vector3( 50.0f, 25.0f, 0.0f ) );
678 ImageActor actor = ImageActor::New( image );
679 actor.SetPosition(targetPosition);
680 actor.SetSize( 100.0f, 100.0f );
681 actor.SetName("TestImageFilenameActor");
682 actor.SetShaderEffect(effect);
683 Stage::GetCurrent().Add(actor);
685 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
687 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
688 Source(actor, Actor::POSITION),
689 TestConstraintFromPositionToVector3() );
691 effect.ApplyConstraint(constraint);
693 application.SendNotification();
694 application.Render();
696 // Test effects of Constraint.
698 application.GetGlAbstraction().CheckUniformValue(
699 "uVec3", targetPosition ) );
703 int UtcDaliShaderEffectMethodApplyConstraintFromActor2(void)
705 // Test whether Shader's uniform can be constrained to Actor's position.
706 // While Actor's position is constrained to another point * 2.0f
707 TestApplication application;
709 const Vector3 targetPosition = Vector3( 25.0f, 36.0f, 49.0f );
711 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
712 DALI_TEST_CHECK( effect );
714 BitmapImage image = CreateBitmapImage();
716 effect.SetUniform( "uVec3", Vector3( 50.0f, 25.0f, 0.0f ) );
718 ImageActor actor = ImageActor::New( image );
719 actor.SetPosition(Vector3( 100.0f, 70.0f, 20.0f));
720 actor.SetSize( 100.0f, 100.0f );
721 actor.SetName("TestImageFilenameActor");
722 actor.SetShaderEffect(effect);
723 Stage::GetCurrent().Add(actor);
725 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
727 Constraint shaderConstraint = Constraint::New<Vector3>( uVecProperty,
728 Source(actor, Actor::POSITION),
729 TestConstraintFromPositionToVector3() );
731 effect.ApplyConstraint(shaderConstraint);
733 Constraint actorConstraint = Constraint::New<Vector3>( Actor::POSITION,
734 TestConstraintToVector3Double(targetPosition) );
736 actor.ApplyConstraint(actorConstraint);
738 application.SendNotification();
739 application.Render();
741 // Test effects of Constraint.
743 application.GetGlAbstraction().CheckUniformValue(
744 "uVec3", targetPosition * 2.0f ) );
748 int UtcDaliShaderEffectMethodApplyConstraintCallback(void)
750 // Test whether Shader's uniform can be constrained to a stationary constraint.
751 TestApplication application;
753 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
754 DALI_TEST_CHECK( effect );
756 BitmapImage image = CreateBitmapImage();
758 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
760 ImageActor actor = ImageActor::New( image );
761 actor.SetSize( 100.0f, 100.0f );
762 actor.SetName("TestImageFilenameActor");
763 actor.SetShaderEffect(effect);
764 Stage::GetCurrent().Add(actor);
766 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
768 application.SendNotification();
769 application.Render();
771 // Test effects of SetUniform...
773 application.GetGlAbstraction().CheckUniformValue(
774 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
776 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
777 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
779 constraint.SetApplyTime( 10.0f );
781 bool constraintCheck( false );
782 ConstraintAppliedCheck appliedCheck( constraintCheck );
784 // We should receive the "Applied" signal after 10 seconds
785 ActiveConstraint active = effect.ApplyConstraint(constraint);
786 active.AppliedSignal().Connect( &application, appliedCheck );
788 application.SendNotification();
789 application.Render(static_cast<unsigned int>(1000.0f)); // 1 elapsed second
791 // Check signal has not fired
792 application.SendNotification();
793 appliedCheck.CheckSignalNotReceived();
795 application.Render(static_cast<unsigned int>(4000.0f)); // 5 elapsed seconds
797 // Check signal has not fired
798 application.SendNotification();
799 appliedCheck.CheckSignalNotReceived();
801 application.Render(static_cast<unsigned int>(5000.0f - 1.0f)); // <10 elapsed seconds
803 // Check signal has not fired
804 application.SendNotification();
805 appliedCheck.CheckSignalNotReceived();
807 application.Render(static_cast<unsigned int>(2.0f)); // >10 elapsed seconds
809 // Signal should have fired
810 application.SendNotification();
811 appliedCheck.CheckSignalReceived();
813 // Test effects of Constraint.
815 application.GetGlAbstraction().CheckUniformValue(
816 "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) );
820 int UtcDaliShaderEffectMethodRemoveConstraints(void)
822 // Test if constrains can be removed before they are ever applyed.
823 TestApplication application;
825 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
826 DALI_TEST_CHECK( effect );
828 BitmapImage image = CreateBitmapImage();
830 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
832 ImageActor actor = ImageActor::New( image );
833 actor.SetSize( 100.0f, 100.0f );
834 actor.SetName("TestImageFilenameActor");
835 actor.SetShaderEffect(effect);
836 Stage::GetCurrent().Add(actor);
838 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
840 application.SendNotification();
841 application.Render();
843 // Test effects of SetUniform...
845 application.GetGlAbstraction().CheckUniformValue(
846 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
848 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
849 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
851 effect.ApplyConstraint(constraint);
853 // Remove the constraints
854 effect.RemoveConstraints();
856 application.SendNotification();
857 application.Render();
859 // Test effects of Constraint.
861 application.GetGlAbstraction().CheckUniformValue(
862 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
866 int UtcDaliShaderEffectMethodRemoveConstraints2(void)
868 // Test whether Shader's uniform constrains can be removed after they are applyed.
869 TestApplication application;
871 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
872 DALI_TEST_CHECK( effect );
874 BitmapImage image = CreateBitmapImage();
876 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
878 ImageActor actor = ImageActor::New( image );
879 actor.SetSize( 100.0f, 100.0f );
880 actor.SetName("TestImageFilenameActor");
881 actor.SetShaderEffect(effect);
882 Stage::GetCurrent().Add(actor);
884 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
886 application.SendNotification();
887 application.Render();
889 // Test effects of SetUniform...
891 application.GetGlAbstraction().CheckUniformValue(
892 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
894 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
895 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
897 effect.ApplyConstraint(constraint);
899 application.SendNotification();
900 application.Render();
902 // Reset the value and remove the constraints
903 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
904 effect.RemoveConstraints();
906 application.SendNotification();
907 application.Render();
909 // Test effects of Constraint.
911 application.GetGlAbstraction().CheckUniformValue(
912 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
916 int UtcDaliShaderEffectMethodCreateExtension(void)
918 // Test creation of a shader extension
919 TestApplication aplication;
923 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
924 DALI_TEST_CHECK( effect );
926 TestExtension* extension = new TestExtension ( deleted );
928 effect.AttachExtension( extension );
930 DALI_TEST_CHECK( static_cast<TestExtension&>(effect.GetExtension()).IsAlive() );
933 DALI_TEST_CHECK( deleted );
937 int UtcDaliShaderEffectMethodCreateExtension2(void)
939 // Test creation of a shader extension
942 TestApplication application;
944 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
945 DALI_TEST_CHECK( effect );
947 BitmapImage image = CreateBitmapImage();
949 effect.SetUniform( "uFloat", 1.0f );
951 ImageActor actor = ImageActor::New( image );
952 actor.SetSize( 100.0f, 100.0f );
953 actor.SetName("TestImageFilenameActor");
954 actor.SetShaderEffect(effect);
955 Stage::GetCurrent().Add(actor);
957 application.SendNotification();
958 application.Render();
960 TestExtension* extension = new TestExtension ( deleted );
962 effect.AttachExtension( extension );
964 const ShaderEffect& constEffect(effect);
965 const TestExtension& ext( static_cast<const TestExtension&>(constEffect.GetExtension()) );
967 DALI_TEST_CHECK( ext.IsAlive() );
970 DALI_TEST_CHECK( deleted );
974 int UtcDaliShaderEffectMethodNoExtension(void)
976 TestApplication application;
982 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
983 DALI_TEST_CHECK( effect );
985 // Don't attach extension
986 ShaderEffect::Extension& extension = effect.GetExtension();
989 DALI_TEST_CHECK( false );
991 catch (Dali::DaliException& e)
993 // Tests that a negative test of an assertion succeeds
994 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
995 DALI_TEST_CHECK( !effect );
1001 int UtcDaliShaderEffectPropertyIndices(void)
1003 TestApplication application;
1004 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
1006 Property::IndexContainer indices;
1007 effect.GetPropertyIndices( indices );
1008 DALI_TEST_CHECK( ! indices.empty() );
1009 DALI_TEST_EQUALS( indices.size(), effect.GetPropertyCount(), TEST_LOCATION );