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());
486 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uVec2", Vector2( stageSize.x/2, -stageSize.y/2 ) ) );
488 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uVec2Dir", Vector2( -1.0f, 2.0f ) ) );
490 // change coordinate types
491 effect.SetUniform( "uVec2", Vector2( 0.1f, 0.2f ), ShaderEffect::COORDINATE_TYPE_DEFAULT );
492 effect.SetUniform( "uVec2Dir", Vector2( 1.0f, 2.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION );
493 actor.SetPixelArea( ImageActor::PixelArea( 0, 0, 10, 10 ) );
495 application.SendNotification();
496 application.Render();
499 application.GetGlAbstraction().GetUniformValue( "uVec2", outValue );
500 DALI_TEST_EQUALS( outValue, Vector2( 0.1f, 0.2f ), TEST_LOCATION );
502 application.GetGlAbstraction().GetUniformValue( "uVec2Dir", outValue );
503 DALI_TEST_EQUALS( outValue, Vector2( stageSize.x *.5f - 1.f, -stageSize.y * .5f + 2.f), TEST_LOCATION );
508 int UtcDaliShaderEffectMethodSetEffectImage(void)
510 TestApplication application;
512 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
513 DALI_TEST_CHECK( effect );
515 BitmapImage image = CreateBitmapImage();
517 effect.SetEffectImage(image);
519 ImageActor actor = ImageActor::New( image );
520 actor.SetSize( 100.0f, 100.0f );
521 actor.SetName("TestImageFilenameActor");
522 actor.SetShaderEffect(effect);
523 Stage::GetCurrent().Add(actor);
525 application.SendNotification();
526 application.Render(16);
527 application.SendNotification();
528 application.Render(16);
529 application.SendNotification();
531 GLuint programId, uniformId;
532 bool uniformWasSet = application.GetGlAbstraction().GetUniformIds( "sEffect", programId, uniformId );
533 // we dont care about the value of the sampler uniform as thats internal to DALi core and subject to change
534 DALI_TEST_CHECK( uniformWasSet );
538 int UtcDaliShaderEffectMethodSetEffectImageAndDelete(void)
540 TestApplication application;
542 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
544 BitmapImage effectImage = CreateBitmapImage();
545 effect.SetEffectImage(effectImage);
547 ImageActor actor = ImageActor::New();
549 actor.SetShaderEffect(effect);
552 Stage::GetCurrent().Add(actor);
554 // do an update / render cycle
555 application.SendNotification();
556 application.Render(16);
557 application.SendNotification();
558 application.Render(16);
559 application.SendNotification();
560 application.Render(16);
562 printf("removing image actor from stage and Reseting handle\n");
563 Stage::GetCurrent().Remove(actor);
566 tet_printf("### Update & Render \n");
568 application.SendNotification();
569 application.Render(16);
571 tet_printf("#### Update Only \n");
573 tet_printf("effectImage.Reset \n");
575 // this releases the effect texture resource,
576 // Update will send a DispatchDiscardTexture message to render
578 application.SendNotification();
579 application.UpdateOnly(16);
581 tet_printf("#### Update Only \n");
583 // at this point shader is deleted, during clear discard queue
584 // and it sends a Shader:: DispatchRemoveObserver message to render thread
585 application.UpdateOnly(16);
587 tet_printf("#### Render Only \n");
588 // This is where it used to crash, there is a message in the queue to perform DispatchDiscardTexture
589 // which tries to call observer->TextureDiscarded, where observer == shader that was deleted
590 // in previous update.
591 application.RenderOnly();
594 // process the discard texture message
595 application.RenderOnly();
596 application.SendNotification();
597 application.Render(16);
599 tet_result(TET_PASS);
604 int UtcDaliShaderEffectMethodApplyConstraint(void)
606 // Test whether Shader's uniform can be constrained to a stationary constraint.
607 TestApplication application;
609 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
610 DALI_TEST_CHECK( effect );
612 BitmapImage image = CreateBitmapImage();
614 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
616 ImageActor actor = ImageActor::New( image );
617 actor.SetSize( 100.0f, 100.0f );
618 actor.SetName("TestImageFilenameActor");
619 actor.SetShaderEffect(effect);
620 Stage::GetCurrent().Add(actor);
622 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
624 application.SendNotification();
625 application.Render();
627 // Test effects of SetUniform...
629 application.GetGlAbstraction().CheckUniformValue(
630 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
632 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
633 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
635 effect.ApplyConstraint(constraint);
637 application.SendNotification();
638 application.Render();
640 // Test effects of Constraint.
642 application.GetGlAbstraction().CheckUniformValue(
643 "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) );
648 int UtcDaliShaderEffectMethodApplyConstraintFromActor(void)
650 // Test whether Shader's uniform can be constrained to Actor's position.
651 TestApplication application;
653 const Vector3 targetPosition = Vector3( 100.0f, 70.0f, 20.0f);
655 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
656 DALI_TEST_CHECK( effect );
658 BitmapImage image = CreateBitmapImage();
660 effect.SetUniform( "uVec3", Vector3( 50.0f, 25.0f, 0.0f ) );
662 ImageActor actor = ImageActor::New( image );
663 actor.SetPosition(targetPosition);
664 actor.SetSize( 100.0f, 100.0f );
665 actor.SetName("TestImageFilenameActor");
666 actor.SetShaderEffect(effect);
667 Stage::GetCurrent().Add(actor);
669 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
671 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
672 Source(actor, Actor::POSITION),
673 TestConstraintFromPositionToVector3() );
675 effect.ApplyConstraint(constraint);
677 application.SendNotification();
678 application.Render();
680 // Test effects of Constraint.
682 application.GetGlAbstraction().CheckUniformValue(
683 "uVec3", targetPosition ) );
687 int UtcDaliShaderEffectMethodApplyConstraintFromActor2(void)
689 // Test whether Shader's uniform can be constrained to Actor's position.
690 // While Actor's position is constrained to another point * 2.0f
691 TestApplication application;
693 const Vector3 targetPosition = Vector3( 25.0f, 36.0f, 49.0f );
695 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
696 DALI_TEST_CHECK( effect );
698 BitmapImage image = CreateBitmapImage();
700 effect.SetUniform( "uVec3", Vector3( 50.0f, 25.0f, 0.0f ) );
702 ImageActor actor = ImageActor::New( image );
703 actor.SetPosition(Vector3( 100.0f, 70.0f, 20.0f));
704 actor.SetSize( 100.0f, 100.0f );
705 actor.SetName("TestImageFilenameActor");
706 actor.SetShaderEffect(effect);
707 Stage::GetCurrent().Add(actor);
709 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
711 Constraint shaderConstraint = Constraint::New<Vector3>( uVecProperty,
712 Source(actor, Actor::POSITION),
713 TestConstraintFromPositionToVector3() );
715 effect.ApplyConstraint(shaderConstraint);
717 Constraint actorConstraint = Constraint::New<Vector3>( Actor::POSITION,
718 TestConstraintToVector3Double(targetPosition) );
720 actor.ApplyConstraint(actorConstraint);
722 application.SendNotification();
723 application.Render();
725 // Test effects of Constraint.
727 application.GetGlAbstraction().CheckUniformValue(
728 "uVec3", targetPosition * 2.0f ) );
732 int UtcDaliShaderEffectMethodApplyConstraintCallback(void)
734 // Test whether Shader's uniform can be constrained to a stationary constraint.
735 TestApplication application;
737 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
738 DALI_TEST_CHECK( effect );
740 BitmapImage image = CreateBitmapImage();
742 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
744 ImageActor actor = ImageActor::New( image );
745 actor.SetSize( 100.0f, 100.0f );
746 actor.SetName("TestImageFilenameActor");
747 actor.SetShaderEffect(effect);
748 Stage::GetCurrent().Add(actor);
750 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
752 application.SendNotification();
753 application.Render();
755 // Test effects of SetUniform...
757 application.GetGlAbstraction().CheckUniformValue(
758 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
760 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
761 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
763 constraint.SetApplyTime( 10.0f );
765 bool constraintCheck( false );
766 ConstraintAppliedCheck appliedCheck( constraintCheck );
768 // We should receive the "Applied" signal after 10 seconds
769 ActiveConstraint active = effect.ApplyConstraint(constraint);
770 active.AppliedSignal().Connect( &application, appliedCheck );
772 application.SendNotification();
773 application.Render(static_cast<unsigned int>(1000.0f)); // 1 elapsed second
775 // Check signal has not fired
776 application.SendNotification();
777 appliedCheck.CheckSignalNotReceived();
779 application.Render(static_cast<unsigned int>(4000.0f)); // 5 elapsed seconds
781 // Check signal has not fired
782 application.SendNotification();
783 appliedCheck.CheckSignalNotReceived();
785 application.Render(static_cast<unsigned int>(5000.0f - 1.0f)); // <10 elapsed seconds
787 // Check signal has not fired
788 application.SendNotification();
789 appliedCheck.CheckSignalNotReceived();
791 application.Render(static_cast<unsigned int>(2.0f)); // >10 elapsed seconds
793 // Signal should have fired
794 application.SendNotification();
795 appliedCheck.CheckSignalReceived();
797 // Test effects of Constraint.
799 application.GetGlAbstraction().CheckUniformValue(
800 "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) );
804 int UtcDaliShaderEffectMethodRemoveConstraints(void)
806 // Test if constrains can be removed before they are ever applyed.
807 TestApplication application;
809 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
810 DALI_TEST_CHECK( effect );
812 BitmapImage image = CreateBitmapImage();
814 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
816 ImageActor actor = ImageActor::New( image );
817 actor.SetSize( 100.0f, 100.0f );
818 actor.SetName("TestImageFilenameActor");
819 actor.SetShaderEffect(effect);
820 Stage::GetCurrent().Add(actor);
822 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
824 application.SendNotification();
825 application.Render();
827 // Test effects of SetUniform...
829 application.GetGlAbstraction().CheckUniformValue(
830 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
832 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
833 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
835 effect.ApplyConstraint(constraint);
837 // Remove the constraints
838 effect.RemoveConstraints();
840 application.SendNotification();
841 application.Render();
843 // Test effects of Constraint.
845 application.GetGlAbstraction().CheckUniformValue(
846 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
850 int UtcDaliShaderEffectMethodRemoveConstraints2(void)
852 // Test whether Shader's uniform constrains can be removed after they are applyed.
853 TestApplication application;
855 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
856 DALI_TEST_CHECK( effect );
858 BitmapImage image = CreateBitmapImage();
860 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
862 ImageActor actor = ImageActor::New( image );
863 actor.SetSize( 100.0f, 100.0f );
864 actor.SetName("TestImageFilenameActor");
865 actor.SetShaderEffect(effect);
866 Stage::GetCurrent().Add(actor);
868 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
870 application.SendNotification();
871 application.Render();
873 // Test effects of SetUniform...
875 application.GetGlAbstraction().CheckUniformValue(
876 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
878 Constraint constraint = Constraint::New<Vector3>( uVecProperty,
879 TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
881 effect.ApplyConstraint(constraint);
883 application.SendNotification();
884 application.Render();
886 // Reset the value and remove the constraints
887 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
888 effect.RemoveConstraints();
890 application.SendNotification();
891 application.Render();
893 // Test effects of Constraint.
895 application.GetGlAbstraction().CheckUniformValue(
896 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
900 int UtcDaliShaderEffectMethodCreateExtension(void)
902 // Test creation of a shader extension
903 TestApplication aplication;
907 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
908 DALI_TEST_CHECK( effect );
910 TestExtension* extension = new TestExtension ( deleted );
912 effect.AttachExtension( extension );
914 DALI_TEST_CHECK( static_cast<TestExtension&>(effect.GetExtension()).IsAlive() );
917 DALI_TEST_CHECK( deleted );
921 int UtcDaliShaderEffectMethodCreateExtension2(void)
923 // Test creation of a shader extension
926 TestApplication application;
928 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
929 DALI_TEST_CHECK( effect );
931 BitmapImage image = CreateBitmapImage();
933 effect.SetUniform( "uFloat", 1.0f );
935 ImageActor actor = ImageActor::New( image );
936 actor.SetSize( 100.0f, 100.0f );
937 actor.SetName("TestImageFilenameActor");
938 actor.SetShaderEffect(effect);
939 Stage::GetCurrent().Add(actor);
941 application.SendNotification();
942 application.Render();
944 TestExtension* extension = new TestExtension ( deleted );
946 effect.AttachExtension( extension );
948 const ShaderEffect& constEffect(effect);
949 const TestExtension& ext( static_cast<const TestExtension&>(constEffect.GetExtension()) );
951 DALI_TEST_CHECK( ext.IsAlive() );
954 DALI_TEST_CHECK( deleted );
958 int UtcDaliShaderEffectMethodNoExtension(void)
960 TestApplication application;
966 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
967 DALI_TEST_CHECK( effect );
969 // Don't attach extension
970 ShaderEffect::Extension& extension = effect.GetExtension();
973 DALI_TEST_CHECK( false );
975 catch (Dali::DaliException& e)
977 // Tests that a negative test of an assertion succeeds
978 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
979 DALI_TEST_CHECK( !effect );
985 int UtcDaliShaderEffectPropertyIndices(void)
987 TestApplication application;
988 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
990 Property::IndexContainer indices;
991 effect.GetPropertyIndices( indices );
992 DALI_TEST_CHECK( ! indices.empty() );
993 DALI_TEST_EQUALS( indices.size(), effect.GetPropertyCount(), TEST_LOCATION );
997 int UtcDaliShaderBinaries(void)
999 TestApplication application;
1000 // these will not affect the "first round" of dali render as core is already initialized and it has queried the defaults
1001 application.GetGlAbstraction().SetBinaryFormats( 1 );
1002 application.GetGlAbstraction().SetNumBinaryFormats( 1 );
1003 application.GetGlAbstraction().SetProgramBinaryLength( 1 );
1005 GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
1007 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
1008 DALI_TEST_CHECK( effect );
1010 BitmapImage image = CreateBitmapImage();
1011 ImageActor actor = ImageActor::New( image );
1012 actor.SetSize( 100.0f, 100.0f );
1013 actor.SetName("TestImageFilenameActor");
1014 actor.SetShaderEffect(effect);
1015 Stage::GetCurrent().Add(actor);
1017 application.SendNotification();
1018 application.Render(16);
1019 // binary was not requested by DALi
1020 DALI_TEST_CHECK( !(application.GetGlAbstraction().GetProgramBinaryCalled()) );
1022 GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
1024 // check that the shader was compiled
1025 DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION );
1027 // simulate context loss to get core to re-initialize its GL
1028 application.GetCore().ContextDestroyed();
1029 application.GetCore().ContextCreated();
1031 application.SendNotification();
1032 application.Render(16);
1034 // shader is recompiled
1035 GLuint finalShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled();
1036 // check that the shader was compiled
1037 DALI_TEST_EQUALS( lastShaderCompiledAfter + 2, finalShaderCompiled, TEST_LOCATION );
1039 // binary was requested by DALi
1040 DALI_TEST_CHECK( application.GetGlAbstraction().GetProgramBinaryCalled() );