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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
26 void utc_dali_shader_effect_startup(void)
28 test_return_value = TET_UNDEF;
31 void utc_dali_shader_effect_cleanup(void)
33 test_return_value = TET_PASS;
39 static const char* VertexSource =
40 "This is a custom vertex shader\n"
41 "made on purpose to look nothing like a normal vertex shader inside dali\n";
43 static const char* FragmentSource =
44 "This is a custom fragment shader\n"
45 "made on purpose to look nothing like a normal fragment shader inside dali\n";
47 static const char* FragmentSourceUsingExtensions =
48 "This is a custom fragment shader using extensions\n"
49 "made on purpose to look nothing like a normal fragment shader inside dali\n";
51 const int GETSOURCE_BUFFER_SIZE = 0x10000;
54 struct TestConstraintToVector3
56 TestConstraintToVector3(Vector3 target)
61 Vector3 operator()(const Vector3& current)
69 struct TestConstraintFromPositionToVector3
71 TestConstraintFromPositionToVector3()
75 Vector3 operator()(const Vector3& current, const PropertyInput& position)
78 return position.GetVector3();
82 struct TestConstraintToVector3Double
84 TestConstraintToVector3Double(Vector3 target)
89 Vector3 operator()(const Vector3& current)
91 return mTarget * 2.0f;
97 class ShaderEffectExtension : public ShaderEffect::Extension {};
100 class TestExtension : public ShaderEffect::Extension
103 TestExtension( bool& deleted )
123 int UtcDaliShaderEffectMethodNew01(void)
125 TestApplication application;
127 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
128 DALI_TEST_CHECK(effect);
132 int UtcDaliShaderEffectMethodNew02(void)
134 TestApplication application;
140 // New must be called to create a ShaderEffect or it wont be valid.
141 effect.SetUniform( "uUniform", 0 );
142 DALI_TEST_CHECK( false );
144 catch (Dali::DaliException& e)
146 // Tests that a negative test of an assertion succeeds
147 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
148 DALI_TEST_CHECK( !effect );
153 int UtcDaliShaderEffectMethodNew03(void)
155 TestApplication application;
157 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource, VertexSource, FragmentSource, ShaderEffect::HINT_NONE );
158 DALI_TEST_CHECK(effect);
162 int UtcDaliShaderEffectMethodNew04(void)
164 TestApplication application;
165 tet_infoline("Testing prefixed version of Dali::ShaderEffect::New()");
167 std::string fragmentShaderPrefix = "#define TEST_FS 1\n#extension GL_OES_standard_derivatives : enable";
168 std::string vertexShaderPrefix = "#define TEST_VS 1";
172 // Call render to compile default shaders.
173 application.SendNotification();
174 application.Render();
175 application.Render();
176 application.Render();
178 GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
179 ShaderEffect effect = ShaderEffect::NewWithPrefix( vertexShaderPrefix, VertexSource,
180 fragmentShaderPrefix, FragmentSourceUsingExtensions,
181 GEOMETRY_TYPE_IMAGE, ShaderEffect::HINT_NONE );
183 BitmapImage image = CreateBitmapImage();
184 ImageActor actor = ImageActor::New( image );
185 actor.SetSize( 100.0f, 100.0f );
186 actor.SetName("TestImageFilenameActor");
187 actor.SetShaderEffect(effect);
188 Stage::GetCurrent().Add(actor);
190 application.SendNotification();
191 application.Render();
192 GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
193 bool testResult = false;
195 // we should have compiled 2 shaders.
196 DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION );
198 char testVertexSourceResult[GETSOURCE_BUFFER_SIZE];
199 char testFragmentSourceResult[GETSOURCE_BUFFER_SIZE];
201 // we are interested in the first two.
202 GLuint vertexShaderId = lastShaderCompiledBefore + 1;
203 GLuint fragmentShaderId = lastShaderCompiledBefore + 2;
205 GLsizei lengthVertexResult;
206 GLsizei lengthFragmentResult;
208 application.GetGlAbstraction().GetShaderSource(vertexShaderId, GETSOURCE_BUFFER_SIZE, &lengthVertexResult, testVertexSourceResult);
209 application.GetGlAbstraction().GetShaderSource(fragmentShaderId, GETSOURCE_BUFFER_SIZE, &lengthFragmentResult, testFragmentSourceResult);
211 int vertexShaderHasPrefix = strncmp(testVertexSourceResult, "#define ", strlen("#define "));
212 int fragmentShaderHasPrefix = strncmp(testFragmentSourceResult, "#define ", strlen("#define "));
213 testResult = (vertexShaderHasPrefix == 0) && (fragmentShaderHasPrefix == 0);
215 DALI_TEST_CHECK(testResult);
217 catch(Dali::DaliException& e)
219 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
220 tet_result( TET_FAIL );
225 int UtcDaliShaderEffectMethodNew05(void)
227 TestApplication application;
229 // heap constructor / destructor
230 DefaultFunctionCoverage<ShaderEffect> shaderEffect;
231 DefaultFunctionCoverage<ShaderEffectExtension> shaderEffectExtension;
236 int UtcDaliShaderEffectMethodNew06(void)
238 TestApplication application;
239 tet_infoline("Testing Dali::ShaderEffect::New() with shader sources for different geometry types");
241 ShaderEffect effect = ShaderEffect::New( "imageVertexShader", "imageFragmentShader",
242 "textVertexShader", "textFragmentShader",
243 "texturedMeshVertexShader", "texturedMeshFragmentShader",
244 "meshVertexShader", "meshFragmentShader",
245 ShaderEffect::HINT_NONE );
246 DALI_TEST_CHECK(effect);
251 int UtcDaliShaderEffectMethodDownCast(void)
253 TestApplication application;
254 tet_infoline("Testing Dali::ShaderEffect::DownCast()");
256 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
258 BaseHandle object(effect);
260 ShaderEffect effect2 = ShaderEffect::DownCast(object);
261 DALI_TEST_CHECK(effect2);
263 ShaderEffect effect3 = DownCast< ShaderEffect >(object);
264 DALI_TEST_CHECK(effect3);
266 BaseHandle unInitializedObject;
267 ShaderEffect effect4 = ShaderEffect::DownCast(unInitializedObject);
268 DALI_TEST_CHECK(!effect4);
270 ShaderEffect effect5 = DownCast< ShaderEffect >(unInitializedObject);
271 DALI_TEST_CHECK(!effect5);
275 int UtcDaliShaderEffectMethodDelete01(void)
277 TestApplication application;
279 // get the default shaders built, this is not required but makes it
280 // easier to debug the TET case and isolate the custom shader compilation.
281 application.SendNotification();
282 application.Render();
284 GLuint beforeShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled();
286 // create a new shader effect
287 // the vertex and fragment shader will be cached in the ShaderFactory
288 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
290 // destroy the shader effect
293 // Create the same shader effect again, this should now use the cached version
294 // held in the shader factory
295 effect= ShaderEffect::New( VertexSource, FragmentSource );
297 // Compile the shader effect
298 application.SendNotification();
299 application.Render();
301 GLuint lastShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled();
302 // no shaders were compiled as they are now compiled on demand and this shader was not used
303 DALI_TEST_EQUALS( beforeShaderCompiled, lastShaderCompiled, TEST_LOCATION );
308 int UtcDaliShaderEffectMethodSetUniformFloat(void)
310 TestApplication application;
312 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
313 DALI_TEST_CHECK( effect );
315 BitmapImage image = CreateBitmapImage();
317 effect.SetUniform( "uFloat", 1.0f );
319 ImageActor actor = ImageActor::New( image );
320 actor.SetSize( 100.0f, 100.0f );
321 actor.SetName("TestImageFilenameActor");
322 actor.SetShaderEffect(effect);
323 Stage::GetCurrent().Add(actor);
325 application.SendNotification();
326 application.Render();
329 application.GetGlAbstraction().CheckUniformValue(
334 int UtcDaliShaderEffectMethodSetUniformVector2(void)
336 TestApplication application;
338 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
339 DALI_TEST_CHECK( effect );
341 BitmapImage image = CreateBitmapImage();
343 effect.SetUniform( "uVec2", Vector2( 2.0f, 3.0f ) );
345 ImageActor actor = ImageActor::New( image );
346 actor.SetSize( 100.0f, 100.0f );
347 actor.SetName("TestImageFilenameActor");
348 actor.SetShaderEffect(effect);
349 Stage::GetCurrent().Add(actor);
351 application.SendNotification();
352 application.Render();
355 application.GetGlAbstraction().CheckUniformValue(
356 "uVec2", Vector2( 2.0f, 3.0f ) ) );
360 int UtcDaliShaderEffectMethodSetUniformVector3(void)
362 TestApplication application;
364 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
365 DALI_TEST_CHECK( effect );
367 BitmapImage image = CreateBitmapImage();
369 effect.SetUniform( "uVec3", Vector3( 4.0f, 5.0f, 6.0f ) );
371 ImageActor actor = ImageActor::New( image );
372 actor.SetSize( 100.0f, 100.0f );
373 actor.SetName("TestImageFilenameActor");
374 actor.SetShaderEffect(effect);
375 Stage::GetCurrent().Add(actor);
377 application.SendNotification();
378 application.Render();
381 application.GetGlAbstraction().CheckUniformValue(
382 "uVec3", Vector3( 4.0f, 5.0f, 6.0f ) ) );
386 int UtcDaliShaderEffectMethodSetUniformVector4(void)
388 TestApplication application;
390 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
391 DALI_TEST_CHECK( effect );
393 BitmapImage image = CreateBitmapImage();
395 effect.SetUniform( "uVec4", Vector4( 7.0f, 8.0f, 9.0f, 10.0f ) );
397 ImageActor actor = ImageActor::New( image );
398 actor.SetSize( 100.0f, 100.0f );
399 actor.SetName("TestImageFilenameActor");
400 actor.SetShaderEffect(effect);
401 Stage::GetCurrent().Add(actor);
403 application.SendNotification();
404 application.Render();
407 application.GetGlAbstraction().CheckUniformValue(
408 "uVec4", Vector4( 7.0f, 8.0f, 9.0f, 10.0f ) ) );
412 int UtcDaliShaderEffectMethodSetUniformMatrix(void)
414 TestApplication application;
416 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
417 DALI_TEST_CHECK( effect );
419 BitmapImage image = CreateBitmapImage();
421 effect.SetUniform( "uModelView", Matrix::IDENTITY );
423 ImageActor actor = ImageActor::New( image );
424 actor.SetSize( 100.0f, 100.0f );
425 actor.SetName("TestImageFilenameActor");
426 actor.SetShaderEffect(effect);
427 Stage::GetCurrent().Add(actor);
429 application.SendNotification();
430 application.Render();
433 application.GetGlAbstraction().CheckUniformValue(
434 "uModelView", Matrix::IDENTITY ) );
438 int UtcDaliShaderEffectMethodSetUniformMatrix3(void)
440 TestApplication application;
442 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
443 DALI_TEST_CHECK( effect );
445 BitmapImage image = CreateBitmapImage();
447 Matrix3 matIdentity(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
448 effect.SetUniform( "uMatrix3", matIdentity );
450 ImageActor actor = ImageActor::New( image );
451 actor.SetSize( 100.0f, 100.0f );
452 actor.SetName("TestImageFilenameActor");
453 actor.SetShaderEffect(effect);
454 Stage::GetCurrent().Add(actor);
456 application.SendNotification();
457 application.Render();
459 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue("uMatrix3", matIdentity) );
463 int UtcDaliShaderEffectMethodSetUniformViewport(void)
465 TestApplication application;
467 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
468 DALI_TEST_CHECK( effect );
470 BitmapImage image = CreateBitmapImage();
472 ImageActor actor = ImageActor::New( image );
473 actor.SetSize( 100.0f, 100.0f );
474 actor.SetName("TestImageFilenameActor");
475 actor.SetShaderEffect(effect);
476 Stage::GetCurrent().Add(actor);
478 effect.SetUniform( "uVec2", Vector2( 0.0f, 0.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION );
479 effect.SetUniform( "uVec2Dir", Vector2( 1.0f, 2.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION );
481 application.SendNotification();
482 application.Render();
484 const Vector2& stageSize(Stage::GetCurrent().GetSize());
487 application.GetGlAbstraction().CheckUniformValue(
488 "uVec2", Vector2( stageSize.x/2, -stageSize.y/2 ) ) );
491 application.GetGlAbstraction().CheckUniformValue(
492 "uVec2Dir", Vector2( -1.0f, 2.0f ) ) );
496 int UtcDaliShaderEffectMethodSetEffectImage(void)
498 TestApplication application;
500 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
501 DALI_TEST_CHECK( effect );
503 BitmapImage image = CreateBitmapImage();
505 effect.SetEffectImage(image);
507 ImageActor actor = ImageActor::New( image );
508 actor.SetSize( 100.0f, 100.0f );
509 actor.SetName("TestImageFilenameActor");
510 actor.SetShaderEffect(effect);
511 Stage::GetCurrent().Add(actor);
513 application.SendNotification();
514 application.Render(16);
515 application.SendNotification();
516 application.Render(16);
517 application.SendNotification();
519 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "sEffect", 1 ) );
523 int UtcDaliShaderEffectMethodSetEffectImageAndDelete(void)
525 TestApplication application;
527 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
529 BitmapImage effectImage = CreateBitmapImage();
530 effect.SetEffectImage(effectImage);
532 ImageActor actor = ImageActor::New();
534 actor.SetShaderEffect(effect);
537 Stage::GetCurrent().Add(actor);
539 // do an update / render cycle
540 application.SendNotification();
541 application.Render(16);
542 application.SendNotification();
543 application.Render(16);
544 application.SendNotification();
545 application.Render(16);
547 printf("removing image actor from stage and Reseting handle\n");
548 Stage::GetCurrent().Remove(actor);
551 tet_printf("### Update & Render \n");
553 application.SendNotification();
554 application.Render(16);
556 tet_printf("#### Update Only \n");
558 tet_printf("effectImage.Reset \n");
560 // this releases the effect texture resource,
561 // Update will send a DispatchDiscardTexture message to render
563 application.SendNotification();
564 application.UpdateOnly(16);
566 tet_printf("#### Update Only \n");
568 // at this point shader is deleted, during clear discard queue
569 // and it sends a Shader:: DispatchRemoveObserver message to render thread
570 application.UpdateOnly(16);
572 tet_printf("#### Render Only \n");
573 // This is where it used to crash, there is a message in the queue to perform DispatchDiscardTexture
574 // which tries to call observer->TextureDiscarded, where observer == shader that was deleted
575 // in previous update.
576 application.RenderOnly();
579 // process the discard texture message
580 application.RenderOnly();
581 application.SendNotification();
582 application.Render(16);
584 tet_result(TET_PASS);
589 int UtcDaliShaderEffectMethodApplyConstraint(void)
591 // Test whether Shader's uniform can be constrained to a stationary constraint.
592 TestApplication application;
594 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
595 DALI_TEST_CHECK( effect );
597 BitmapImage image = CreateBitmapImage();
599 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
601 ImageActor actor = ImageActor::New( image );
602 actor.SetSize( 100.0f, 100.0f );
603 actor.SetName("TestImageFilenameActor");
604 actor.SetShaderEffect(effect);
605 Stage::GetCurrent().Add(actor);
607 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
609 application.SendNotification();
610 application.Render();
612 // Test effects of SetUniform...
614 application.GetGlAbstraction().CheckUniformValue(
615 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
617 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
618 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
620 effect.ApplyConstraint(constraint);
622 application.SendNotification();
623 application.Render();
625 // Test effects of Constraint.
627 application.GetGlAbstraction().CheckUniformValue(
628 "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) );
633 int UtcDaliShaderEffectMethodApplyConstraintFromActor(void)
635 // Test whether Shader's uniform can be constrained to Actor's position.
636 TestApplication application;
638 const Vector3 targetPosition = Vector3( 100.0f, 70.0f, 20.0f);
640 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
641 DALI_TEST_CHECK( effect );
643 BitmapImage image = CreateBitmapImage();
645 effect.SetUniform( "uVec3", Vector3( 50.0f, 25.0f, 0.0f ) );
647 ImageActor actor = ImageActor::New( image );
648 actor.SetPosition(targetPosition);
649 actor.SetSize( 100.0f, 100.0f );
650 actor.SetName("TestImageFilenameActor");
651 actor.SetShaderEffect(effect);
652 Stage::GetCurrent().Add(actor);
654 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
656 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
657 Source(actor, Actor::POSITION),
658 TestConstraintFromPositionToVector3() );
660 effect.ApplyConstraint(constraint);
662 application.SendNotification();
663 application.Render();
665 // Test effects of Constraint.
667 application.GetGlAbstraction().CheckUniformValue(
668 "uVec3", targetPosition ) );
672 int UtcDaliShaderEffectMethodApplyConstraintFromActor2(void)
674 // Test whether Shader's uniform can be constrained to Actor's position.
675 // While Actor's position is constrained to another point * 2.0f
676 TestApplication application;
678 const Vector3 targetPosition = Vector3( 25.0f, 36.0f, 49.0f );
680 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
681 DALI_TEST_CHECK( effect );
683 BitmapImage image = CreateBitmapImage();
685 effect.SetUniform( "uVec3", Vector3( 50.0f, 25.0f, 0.0f ) );
687 ImageActor actor = ImageActor::New( image );
688 actor.SetPosition(Vector3( 100.0f, 70.0f, 20.0f));
689 actor.SetSize( 100.0f, 100.0f );
690 actor.SetName("TestImageFilenameActor");
691 actor.SetShaderEffect(effect);
692 Stage::GetCurrent().Add(actor);
694 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
696 Constraint shaderConstraint = Constraint::New<Vector3>( uVecProperty,
697 Source(actor, Actor::POSITION),
698 TestConstraintFromPositionToVector3() );
700 effect.ApplyConstraint(shaderConstraint);
702 Constraint actorConstraint = Constraint::New<Vector3>( Actor::POSITION,
703 TestConstraintToVector3Double(targetPosition) );
705 actor.ApplyConstraint(actorConstraint);
707 application.SendNotification();
708 application.Render();
710 // Test effects of Constraint.
712 application.GetGlAbstraction().CheckUniformValue(
713 "uVec3", targetPosition * 2.0f ) );
717 int UtcDaliShaderEffectMethodApplyConstraintCallback(void)
719 // Test whether Shader's uniform can be constrained to a stationary constraint.
720 TestApplication application;
722 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
723 DALI_TEST_CHECK( effect );
725 BitmapImage image = CreateBitmapImage();
727 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
729 ImageActor actor = ImageActor::New( image );
730 actor.SetSize( 100.0f, 100.0f );
731 actor.SetName("TestImageFilenameActor");
732 actor.SetShaderEffect(effect);
733 Stage::GetCurrent().Add(actor);
735 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
737 application.SendNotification();
738 application.Render();
740 // Test effects of SetUniform...
742 application.GetGlAbstraction().CheckUniformValue(
743 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
745 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
746 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
748 constraint.SetApplyTime( 10.0f );
750 bool constraintCheck( false );
751 ConstraintAppliedCheck appliedCheck( constraintCheck );
753 // We should receive the "Applied" signal after 10 seconds
754 ActiveConstraint active = effect.ApplyConstraint(constraint);
755 active.AppliedSignal().Connect( &application, appliedCheck );
757 application.SendNotification();
758 application.Render(static_cast<unsigned int>(1000.0f)); // 1 elapsed second
760 // Check signal has not fired
761 application.SendNotification();
762 appliedCheck.CheckSignalNotReceived();
764 application.Render(static_cast<unsigned int>(4000.0f)); // 5 elapsed seconds
766 // Check signal has not fired
767 application.SendNotification();
768 appliedCheck.CheckSignalNotReceived();
770 application.Render(static_cast<unsigned int>(5000.0f - 1.0f)); // <10 elapsed seconds
772 // Check signal has not fired
773 application.SendNotification();
774 appliedCheck.CheckSignalNotReceived();
776 application.Render(static_cast<unsigned int>(2.0f)); // >10 elapsed seconds
778 // Signal should have fired
779 application.SendNotification();
780 appliedCheck.CheckSignalReceived();
782 // Test effects of Constraint.
784 application.GetGlAbstraction().CheckUniformValue(
785 "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) );
789 int UtcDaliShaderEffectMethodRemoveConstraints(void)
791 // Test if constrains can be removed before they are ever applyed.
792 TestApplication application;
794 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
795 DALI_TEST_CHECK( effect );
797 BitmapImage image = CreateBitmapImage();
799 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
801 ImageActor actor = ImageActor::New( image );
802 actor.SetSize( 100.0f, 100.0f );
803 actor.SetName("TestImageFilenameActor");
804 actor.SetShaderEffect(effect);
805 Stage::GetCurrent().Add(actor);
807 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
809 application.SendNotification();
810 application.Render();
812 // Test effects of SetUniform...
814 application.GetGlAbstraction().CheckUniformValue(
815 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
817 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
818 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
820 effect.ApplyConstraint(constraint);
822 // Remove the constraints
823 effect.RemoveConstraints();
825 application.SendNotification();
826 application.Render();
828 // Test effects of Constraint.
830 application.GetGlAbstraction().CheckUniformValue(
831 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
835 int UtcDaliShaderEffectMethodRemoveConstraints2(void)
837 // Test whether Shader's uniform constrains can be removed after they are applyed.
838 TestApplication application;
840 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
841 DALI_TEST_CHECK( effect );
843 BitmapImage image = CreateBitmapImage();
845 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
847 ImageActor actor = ImageActor::New( image );
848 actor.SetSize( 100.0f, 100.0f );
849 actor.SetName("TestImageFilenameActor");
850 actor.SetShaderEffect(effect);
851 Stage::GetCurrent().Add(actor);
853 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
855 application.SendNotification();
856 application.Render();
858 // Test effects of SetUniform...
860 application.GetGlAbstraction().CheckUniformValue(
861 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
863 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
864 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
866 effect.ApplyConstraint(constraint);
868 application.SendNotification();
869 application.Render();
871 // Reset the value and remove the constraints
872 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
873 effect.RemoveConstraints();
875 application.SendNotification();
876 application.Render();
878 // Test effects of Constraint.
880 application.GetGlAbstraction().CheckUniformValue(
881 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
885 int UtcDaliShaderEffectMethodCreateExtension(void)
887 // Test creation of a shader extension
888 TestApplication aplication;
892 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
893 DALI_TEST_CHECK( effect );
895 TestExtension* extension = new TestExtension ( deleted );
897 effect.AttachExtension( extension );
899 DALI_TEST_CHECK( static_cast<TestExtension&>(effect.GetExtension()).IsAlive() );
902 DALI_TEST_CHECK( deleted );
906 int UtcDaliShaderEffectMethodCreateExtension2(void)
908 // Test creation of a shader extension
911 TestApplication application;
913 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
914 DALI_TEST_CHECK( effect );
916 BitmapImage image = CreateBitmapImage();
918 effect.SetUniform( "uFloat", 1.0f );
920 ImageActor actor = ImageActor::New( image );
921 actor.SetSize( 100.0f, 100.0f );
922 actor.SetName("TestImageFilenameActor");
923 actor.SetShaderEffect(effect);
924 Stage::GetCurrent().Add(actor);
926 application.SendNotification();
927 application.Render();
929 TestExtension* extension = new TestExtension ( deleted );
931 effect.AttachExtension( extension );
933 const ShaderEffect& constEffect(effect);
934 const TestExtension& ext( static_cast<const TestExtension&>(constEffect.GetExtension()) );
936 DALI_TEST_CHECK( ext.IsAlive() );
939 DALI_TEST_CHECK( deleted );
943 int UtcDaliShaderEffectMethodNoExtension(void)
945 TestApplication application;
951 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
952 DALI_TEST_CHECK( effect );
954 // Don't attach extension
955 ShaderEffect::Extension& extension = effect.GetExtension();
958 DALI_TEST_CHECK( false );
960 catch (Dali::DaliException& e)
962 // Tests that a negative test of an assertion succeeds
963 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
964 DALI_TEST_CHECK( !effect );
970 int UtcDaliShaderEffectPropertyIndices(void)
972 TestApplication application;
973 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
975 Property::IndexContainer indices;
976 effect.GetPropertyIndices( indices );
977 DALI_TEST_CHECK( ! indices.empty() );
978 DALI_TEST_EQUALS( indices.size(), effect.GetPropertyCount(), TEST_LOCATION );