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 GLuint programId, uniformId;
520 bool uniformWasSet = application.GetGlAbstraction().GetUniformIds( "sEffect", programId, uniformId );
521 // we dont care about the value of the sampler uniform as thats internal to DALi core and subject to change
522 DALI_TEST_CHECK( uniformWasSet );
526 int UtcDaliShaderEffectMethodSetEffectImageAndDelete(void)
528 TestApplication application;
530 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
532 BitmapImage effectImage = CreateBitmapImage();
533 effect.SetEffectImage(effectImage);
535 ImageActor actor = ImageActor::New();
537 actor.SetShaderEffect(effect);
540 Stage::GetCurrent().Add(actor);
542 // do an update / render cycle
543 application.SendNotification();
544 application.Render(16);
545 application.SendNotification();
546 application.Render(16);
547 application.SendNotification();
548 application.Render(16);
550 printf("removing image actor from stage and Reseting handle\n");
551 Stage::GetCurrent().Remove(actor);
554 tet_printf("### Update & Render \n");
556 application.SendNotification();
557 application.Render(16);
559 tet_printf("#### Update Only \n");
561 tet_printf("effectImage.Reset \n");
563 // this releases the effect texture resource,
564 // Update will send a DispatchDiscardTexture message to render
566 application.SendNotification();
567 application.UpdateOnly(16);
569 tet_printf("#### Update Only \n");
571 // at this point shader is deleted, during clear discard queue
572 // and it sends a Shader:: DispatchRemoveObserver message to render thread
573 application.UpdateOnly(16);
575 tet_printf("#### Render Only \n");
576 // This is where it used to crash, there is a message in the queue to perform DispatchDiscardTexture
577 // which tries to call observer->TextureDiscarded, where observer == shader that was deleted
578 // in previous update.
579 application.RenderOnly();
582 // process the discard texture message
583 application.RenderOnly();
584 application.SendNotification();
585 application.Render(16);
587 tet_result(TET_PASS);
592 int UtcDaliShaderEffectMethodApplyConstraint(void)
594 // Test whether Shader's uniform can be constrained to a stationary constraint.
595 TestApplication application;
597 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
598 DALI_TEST_CHECK( effect );
600 BitmapImage image = CreateBitmapImage();
602 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
604 ImageActor actor = ImageActor::New( image );
605 actor.SetSize( 100.0f, 100.0f );
606 actor.SetName("TestImageFilenameActor");
607 actor.SetShaderEffect(effect);
608 Stage::GetCurrent().Add(actor);
610 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
612 application.SendNotification();
613 application.Render();
615 // Test effects of SetUniform...
617 application.GetGlAbstraction().CheckUniformValue(
618 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
620 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
621 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
623 effect.ApplyConstraint(constraint);
625 application.SendNotification();
626 application.Render();
628 // Test effects of Constraint.
630 application.GetGlAbstraction().CheckUniformValue(
631 "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) );
636 int UtcDaliShaderEffectMethodApplyConstraintFromActor(void)
638 // Test whether Shader's uniform can be constrained to Actor's position.
639 TestApplication application;
641 const Vector3 targetPosition = Vector3( 100.0f, 70.0f, 20.0f);
643 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
644 DALI_TEST_CHECK( effect );
646 BitmapImage image = CreateBitmapImage();
648 effect.SetUniform( "uVec3", Vector3( 50.0f, 25.0f, 0.0f ) );
650 ImageActor actor = ImageActor::New( image );
651 actor.SetPosition(targetPosition);
652 actor.SetSize( 100.0f, 100.0f );
653 actor.SetName("TestImageFilenameActor");
654 actor.SetShaderEffect(effect);
655 Stage::GetCurrent().Add(actor);
657 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
659 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
660 Source(actor, Actor::POSITION),
661 TestConstraintFromPositionToVector3() );
663 effect.ApplyConstraint(constraint);
665 application.SendNotification();
666 application.Render();
668 // Test effects of Constraint.
670 application.GetGlAbstraction().CheckUniformValue(
671 "uVec3", targetPosition ) );
675 int UtcDaliShaderEffectMethodApplyConstraintFromActor2(void)
677 // Test whether Shader's uniform can be constrained to Actor's position.
678 // While Actor's position is constrained to another point * 2.0f
679 TestApplication application;
681 const Vector3 targetPosition = Vector3( 25.0f, 36.0f, 49.0f );
683 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
684 DALI_TEST_CHECK( effect );
686 BitmapImage image = CreateBitmapImage();
688 effect.SetUniform( "uVec3", Vector3( 50.0f, 25.0f, 0.0f ) );
690 ImageActor actor = ImageActor::New( image );
691 actor.SetPosition(Vector3( 100.0f, 70.0f, 20.0f));
692 actor.SetSize( 100.0f, 100.0f );
693 actor.SetName("TestImageFilenameActor");
694 actor.SetShaderEffect(effect);
695 Stage::GetCurrent().Add(actor);
697 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
699 Constraint shaderConstraint = Constraint::New<Vector3>( uVecProperty,
700 Source(actor, Actor::POSITION),
701 TestConstraintFromPositionToVector3() );
703 effect.ApplyConstraint(shaderConstraint);
705 Constraint actorConstraint = Constraint::New<Vector3>( Actor::POSITION,
706 TestConstraintToVector3Double(targetPosition) );
708 actor.ApplyConstraint(actorConstraint);
710 application.SendNotification();
711 application.Render();
713 // Test effects of Constraint.
715 application.GetGlAbstraction().CheckUniformValue(
716 "uVec3", targetPosition * 2.0f ) );
720 int UtcDaliShaderEffectMethodApplyConstraintCallback(void)
722 // Test whether Shader's uniform can be constrained to a stationary constraint.
723 TestApplication application;
725 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
726 DALI_TEST_CHECK( effect );
728 BitmapImage image = CreateBitmapImage();
730 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
732 ImageActor actor = ImageActor::New( image );
733 actor.SetSize( 100.0f, 100.0f );
734 actor.SetName("TestImageFilenameActor");
735 actor.SetShaderEffect(effect);
736 Stage::GetCurrent().Add(actor);
738 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
740 application.SendNotification();
741 application.Render();
743 // Test effects of SetUniform...
745 application.GetGlAbstraction().CheckUniformValue(
746 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
748 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
749 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
751 constraint.SetApplyTime( 10.0f );
753 bool constraintCheck( false );
754 ConstraintAppliedCheck appliedCheck( constraintCheck );
756 // We should receive the "Applied" signal after 10 seconds
757 ActiveConstraint active = effect.ApplyConstraint(constraint);
758 active.AppliedSignal().Connect( &application, appliedCheck );
760 application.SendNotification();
761 application.Render(static_cast<unsigned int>(1000.0f)); // 1 elapsed second
763 // Check signal has not fired
764 application.SendNotification();
765 appliedCheck.CheckSignalNotReceived();
767 application.Render(static_cast<unsigned int>(4000.0f)); // 5 elapsed seconds
769 // Check signal has not fired
770 application.SendNotification();
771 appliedCheck.CheckSignalNotReceived();
773 application.Render(static_cast<unsigned int>(5000.0f - 1.0f)); // <10 elapsed seconds
775 // Check signal has not fired
776 application.SendNotification();
777 appliedCheck.CheckSignalNotReceived();
779 application.Render(static_cast<unsigned int>(2.0f)); // >10 elapsed seconds
781 // Signal should have fired
782 application.SendNotification();
783 appliedCheck.CheckSignalReceived();
785 // Test effects of Constraint.
787 application.GetGlAbstraction().CheckUniformValue(
788 "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) );
792 int UtcDaliShaderEffectMethodRemoveConstraints(void)
794 // Test if constrains can be removed before they are ever applyed.
795 TestApplication application;
797 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
798 DALI_TEST_CHECK( effect );
800 BitmapImage image = CreateBitmapImage();
802 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
804 ImageActor actor = ImageActor::New( image );
805 actor.SetSize( 100.0f, 100.0f );
806 actor.SetName("TestImageFilenameActor");
807 actor.SetShaderEffect(effect);
808 Stage::GetCurrent().Add(actor);
810 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
812 application.SendNotification();
813 application.Render();
815 // Test effects of SetUniform...
817 application.GetGlAbstraction().CheckUniformValue(
818 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
820 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
821 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
823 effect.ApplyConstraint(constraint);
825 // Remove the constraints
826 effect.RemoveConstraints();
828 application.SendNotification();
829 application.Render();
831 // Test effects of Constraint.
833 application.GetGlAbstraction().CheckUniformValue(
834 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
838 int UtcDaliShaderEffectMethodRemoveConstraints2(void)
840 // Test whether Shader's uniform constrains can be removed after they are applyed.
841 TestApplication application;
843 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
844 DALI_TEST_CHECK( effect );
846 BitmapImage image = CreateBitmapImage();
848 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
850 ImageActor actor = ImageActor::New( image );
851 actor.SetSize( 100.0f, 100.0f );
852 actor.SetName("TestImageFilenameActor");
853 actor.SetShaderEffect(effect);
854 Stage::GetCurrent().Add(actor);
856 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
858 application.SendNotification();
859 application.Render();
861 // Test effects of SetUniform...
863 application.GetGlAbstraction().CheckUniformValue(
864 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
866 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
867 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
869 effect.ApplyConstraint(constraint);
871 application.SendNotification();
872 application.Render();
874 // Reset the value and remove the constraints
875 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
876 effect.RemoveConstraints();
878 application.SendNotification();
879 application.Render();
881 // Test effects of Constraint.
883 application.GetGlAbstraction().CheckUniformValue(
884 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
888 int UtcDaliShaderEffectMethodCreateExtension(void)
890 // Test creation of a shader extension
891 TestApplication aplication;
895 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
896 DALI_TEST_CHECK( effect );
898 TestExtension* extension = new TestExtension ( deleted );
900 effect.AttachExtension( extension );
902 DALI_TEST_CHECK( static_cast<TestExtension&>(effect.GetExtension()).IsAlive() );
905 DALI_TEST_CHECK( deleted );
909 int UtcDaliShaderEffectMethodCreateExtension2(void)
911 // Test creation of a shader extension
914 TestApplication application;
916 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
917 DALI_TEST_CHECK( effect );
919 BitmapImage image = CreateBitmapImage();
921 effect.SetUniform( "uFloat", 1.0f );
923 ImageActor actor = ImageActor::New( image );
924 actor.SetSize( 100.0f, 100.0f );
925 actor.SetName("TestImageFilenameActor");
926 actor.SetShaderEffect(effect);
927 Stage::GetCurrent().Add(actor);
929 application.SendNotification();
930 application.Render();
932 TestExtension* extension = new TestExtension ( deleted );
934 effect.AttachExtension( extension );
936 const ShaderEffect& constEffect(effect);
937 const TestExtension& ext( static_cast<const TestExtension&>(constEffect.GetExtension()) );
939 DALI_TEST_CHECK( ext.IsAlive() );
942 DALI_TEST_CHECK( deleted );
946 int UtcDaliShaderEffectMethodNoExtension(void)
948 TestApplication application;
954 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
955 DALI_TEST_CHECK( effect );
957 // Don't attach extension
958 ShaderEffect::Extension& extension = effect.GetExtension();
961 DALI_TEST_CHECK( false );
963 catch (Dali::DaliException& e)
965 // Tests that a negative test of an assertion succeeds
966 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
967 DALI_TEST_CHECK( !effect );
973 int UtcDaliShaderEffectPropertyIndices(void)
975 TestApplication application;
976 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
978 Property::IndexContainer indices;
979 effect.GetPropertyIndices( indices );
980 DALI_TEST_CHECK( ! indices.empty() );
981 DALI_TEST_EQUALS( indices.size(), effect.GetPropertyCount(), TEST_LOCATION );