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 const int GETSOURCE_BUFFER_SIZE = 0x10000;
50 struct TestConstraintToVector3
52 TestConstraintToVector3(Vector3 target)
57 void operator()( Vector3& current, const PropertyInputContainer& /* inputs */ )
65 struct TestConstraintFromPositionToVector3
67 TestConstraintFromPositionToVector3()
71 void operator()( Vector3& current, const PropertyInputContainer& inputs )
73 current = inputs[0]->GetVector3();
77 struct TestConstraintToVector3Double
79 TestConstraintToVector3Double(Vector3 target)
84 void operator()( Vector3& current, const PropertyInputContainer& /* inputs */ )
86 current = mTarget * 2.0f;
92 static const char* TestImageFilename = "icon_wrt.png";
94 Integration::Bitmap* CreateBitmap( unsigned int imageHeight, unsigned int imageWidth, unsigned int initialColor )
96 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
97 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGBA8888, imageWidth,imageHeight,imageWidth,imageHeight );
98 unsigned int bytesPerPixel = GetBytesPerPixel( Pixel::RGBA8888 );
100 memset( pixbuffer, initialColor , imageHeight*imageWidth*bytesPerPixel);
108 int UtcDaliShaderEffectMethodNew01(void)
110 TestApplication application;
112 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
113 DALI_TEST_CHECK(effect);
117 int UtcDaliShaderEffectMethodNew02(void)
119 TestApplication application;
125 // New must be called to create a ShaderEffect or it wont be valid.
126 effect.SetUniform( "uUniform", 0 );
127 DALI_TEST_CHECK( false );
129 catch (Dali::DaliException& e)
131 // Tests that a negative test of an assertion succeeds
132 DALI_TEST_PRINT_ASSERT( e );
133 DALI_TEST_CHECK( !effect );
138 int UtcDaliShaderEffectMethodNew05(void)
140 TestApplication application;
142 // heap constructor / destructor
143 DefaultFunctionCoverage<ShaderEffect> shaderEffect;
148 int UtcDaliShaderEffectMethodDownCast(void)
150 TestApplication application;
151 tet_infoline("Testing Dali::ShaderEffect::DownCast()");
153 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
155 BaseHandle object(effect);
157 ShaderEffect effect2 = ShaderEffect::DownCast(object);
158 DALI_TEST_CHECK(effect2);
160 ShaderEffect effect3 = DownCast< ShaderEffect >(object);
161 DALI_TEST_CHECK(effect3);
163 BaseHandle unInitializedObject;
164 ShaderEffect effect4 = ShaderEffect::DownCast(unInitializedObject);
165 DALI_TEST_CHECK(!effect4);
167 ShaderEffect effect5 = DownCast< ShaderEffect >(unInitializedObject);
168 DALI_TEST_CHECK(!effect5);
172 int UtcDaliShaderEffectMethodDelete01(void)
174 TestApplication application;
176 // get the default shaders built, this is not required but makes it
177 // easier to debug the TET case and isolate the custom shader compilation.
178 application.SendNotification();
179 application.Render();
181 GLuint beforeShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled();
183 // create a new shader effect
184 // the vertex and fragment shader will be cached in the ShaderFactory
185 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
187 // destroy the shader effect
190 // Create the same shader effect again, this should now use the cached version
191 // held in the shader factory
192 effect= ShaderEffect::New( VertexSource, FragmentSource );
194 // Compile the shader effect
195 application.SendNotification();
196 application.Render();
198 GLuint lastShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled();
199 // no shaders were compiled as they are now compiled on demand and this shader was not used
200 DALI_TEST_EQUALS( beforeShaderCompiled, lastShaderCompiled, TEST_LOCATION );
205 int UtcDaliShaderEffectMethodSetUniformFloat(void)
207 TestApplication application;
209 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
210 DALI_TEST_CHECK( effect );
212 BufferImage image = CreateBufferImage();
214 effect.SetUniform( "uFloat", 1.0f );
216 ImageActor actor = ImageActor::New( image );
217 actor.SetSize( 100.0f, 100.0f );
218 actor.SetName("TestImageFilenameActor");
219 actor.SetShaderEffect(effect);
220 Stage::GetCurrent().Add(actor);
222 application.SendNotification();
223 application.Render();
226 application.GetGlAbstraction().CheckUniformValue(
231 int UtcDaliShaderEffectMethodSetUniformVector2(void)
233 TestApplication application;
235 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
236 DALI_TEST_CHECK( effect );
238 BufferImage image = CreateBufferImage();
240 effect.SetUniform( "uVec2", Vector2( 2.0f, 3.0f ) );
242 ImageActor actor = ImageActor::New( image );
243 actor.SetSize( 100.0f, 100.0f );
244 actor.SetName("TestImageFilenameActor");
245 actor.SetShaderEffect(effect);
246 Stage::GetCurrent().Add(actor);
248 application.SendNotification();
249 application.Render();
252 application.GetGlAbstraction().CheckUniformValue(
253 "uVec2", Vector2( 2.0f, 3.0f ) ) );
257 int UtcDaliShaderEffectMethodSetUniformVector3(void)
259 TestApplication application;
261 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
262 DALI_TEST_CHECK( effect );
264 BufferImage image = CreateBufferImage();
266 effect.SetUniform( "uVec3", Vector3( 4.0f, 5.0f, 6.0f ) );
268 ImageActor actor = ImageActor::New( image );
269 actor.SetSize( 100.0f, 100.0f );
270 actor.SetName("TestImageFilenameActor");
271 actor.SetShaderEffect(effect);
272 Stage::GetCurrent().Add(actor);
274 application.SendNotification();
275 application.Render();
278 application.GetGlAbstraction().CheckUniformValue(
279 "uVec3", Vector3( 4.0f, 5.0f, 6.0f ) ) );
283 int UtcDaliShaderEffectMethodSetUniformVector4(void)
285 TestApplication application;
287 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
288 DALI_TEST_CHECK( effect );
290 BufferImage image = CreateBufferImage();
292 effect.SetUniform( "uVec4", Vector4( 7.0f, 8.0f, 9.0f, 10.0f ) );
294 ImageActor actor = ImageActor::New( image );
295 actor.SetSize( 100.0f, 100.0f );
296 actor.SetName("TestImageFilenameActor");
297 actor.SetShaderEffect(effect);
298 Stage::GetCurrent().Add(actor);
300 application.SendNotification();
301 application.Render();
304 application.GetGlAbstraction().CheckUniformValue(
305 "uVec4", Vector4( 7.0f, 8.0f, 9.0f, 10.0f ) ) );
309 int UtcDaliShaderEffectMethodSetUniformMatrix(void)
311 TestApplication application;
313 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
314 DALI_TEST_CHECK( effect );
316 BufferImage image = CreateBufferImage();
318 effect.SetUniform( "uModelView", Matrix::IDENTITY );
320 ImageActor actor = ImageActor::New( image );
321 actor.SetSize( 100.0f, 100.0f );
322 actor.SetName("TestImageFilenameActor");
323 actor.SetShaderEffect(effect);
324 Stage::GetCurrent().Add(actor);
326 application.SendNotification();
327 application.Render();
330 application.GetGlAbstraction().CheckUniformValue(
331 "uModelView", Matrix::IDENTITY ) );
335 int UtcDaliShaderEffectMethodSetUniformMatrix3(void)
337 TestApplication application;
339 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
340 DALI_TEST_CHECK( effect );
342 BufferImage image = CreateBufferImage();
344 Matrix3 matIdentity(1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
345 effect.SetUniform( "uMatrix3", matIdentity );
347 ImageActor actor = ImageActor::New( image );
348 actor.SetSize( 100.0f, 100.0f );
349 actor.SetName("TestImageFilenameActor");
350 actor.SetShaderEffect(effect);
351 Stage::GetCurrent().Add(actor);
353 application.SendNotification();
354 application.Render();
356 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue("uMatrix3", matIdentity) );
360 int UtcDaliShaderEffectMethodSetUniformViewport(void)
362 TestApplication application;
364 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
365 DALI_TEST_CHECK( effect );
367 BufferImage image = CreateBufferImage();
369 ImageActor actor = ImageActor::New( image );
370 actor.SetSize( 100.0f, 100.0f );
371 actor.SetName("TestImageFilenameActor");
372 actor.SetShaderEffect(effect);
373 Stage::GetCurrent().Add(actor);
375 effect.SetUniform( "uVec2", Vector2( 0.0f, 0.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION );
376 effect.SetUniform( "uVec2Dir", Vector2( 1.0f, 2.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_DIRECTION );
378 application.SendNotification();
379 application.Render();
381 const Vector2& stageSize(Stage::GetCurrent().GetSize());
383 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uVec2", Vector2( stageSize.x/2, -stageSize.y/2 ) ) );
385 DALI_TEST_CHECK( application.GetGlAbstraction().CheckUniformValue( "uVec2Dir", Vector2( -1.0f, 2.0f ) ) );
387 // change coordinate types
388 effect.SetUniform( "uVec2", Vector2( 0.1f, 0.2f ), ShaderEffect::COORDINATE_TYPE_DEFAULT );
389 effect.SetUniform( "uVec2Dir", Vector2( 1.0f, 2.0f ), ShaderEffect::COORDINATE_TYPE_VIEWPORT_POSITION );
390 actor.SetPixelArea( ImageActor::PixelArea( 0, 0, 10, 10 ) );
392 application.SendNotification();
393 application.Render();
396 application.GetGlAbstraction().GetUniformValue( "uVec2", outValue );
397 DALI_TEST_EQUALS( outValue, Vector2( 0.1f, 0.2f ), TEST_LOCATION );
399 application.GetGlAbstraction().GetUniformValue( "uVec2Dir", outValue );
400 DALI_TEST_EQUALS( outValue, Vector2( stageSize.x *.5f - 1.f, -stageSize.y * .5f + 2.f), TEST_LOCATION );
405 int UtcDaliShaderEffectMethodSetEffectImage(void)
407 TestApplication application;
409 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
410 DALI_TEST_CHECK( effect );
412 BufferImage image = CreateBufferImage();
414 effect.SetEffectImage(image);
416 ImageActor actor = ImageActor::New( image );
417 actor.SetSize( 100.0f, 100.0f );
418 actor.SetName("TestImageFilenameActor");
419 actor.SetShaderEffect(effect);
420 Stage::GetCurrent().Add(actor);
422 application.SendNotification();
423 application.Render(16);
424 application.SendNotification();
425 application.Render(16);
426 application.SendNotification();
428 GLuint programId, uniformId;
429 bool uniformWasSet = application.GetGlAbstraction().GetUniformIds( "sEffect", programId, uniformId );
430 // we dont care about the value of the sampler uniform as thats internal to DALi core and subject to change
431 DALI_TEST_CHECK( uniformWasSet );
435 int UtcDaliShaderEffectMethodSetEffectImageAndDelete(void)
437 TestApplication application;
439 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
441 BufferImage effectImage = CreateBufferImage();
442 effect.SetEffectImage(effectImage);
444 ImageActor actor = ImageActor::New();
446 actor.SetShaderEffect(effect);
449 Stage::GetCurrent().Add(actor);
451 // do an update / render cycle
452 application.SendNotification();
453 application.Render(16);
454 application.SendNotification();
455 application.Render(16);
456 application.SendNotification();
457 application.Render(16);
459 printf("removing image actor from stage and Reseting handle\n");
460 Stage::GetCurrent().Remove(actor);
463 tet_printf("### Update & Render \n");
465 application.SendNotification();
466 application.Render(16);
468 tet_printf("#### Update Only \n");
470 tet_printf("effectImage.Reset \n");
472 // this releases the effect texture resource,
473 // Update will send a DispatchDiscardTexture message to render
475 application.SendNotification();
476 application.UpdateOnly(16);
478 tet_printf("#### Update Only \n");
480 // at this point shader is deleted, during clear discard queue
481 // and it sends a Shader:: DispatchRemoveObserver message to render thread
482 application.UpdateOnly(16);
484 tet_printf("#### Render Only \n");
485 // This is where it used to crash, there is a message in the queue to perform DispatchDiscardTexture
486 // which tries to call observer->TextureDiscarded, where observer == shader that was deleted
487 // in previous update.
488 application.RenderOnly();
491 // process the discard texture message
492 application.RenderOnly();
493 application.SendNotification();
494 application.Render(16);
496 tet_result(TET_PASS);
501 int UtcDaliShaderEffectMethodApplyConstraint(void)
503 // Test whether Shader's uniform can be constrained to a stationary constraint.
504 TestApplication application;
506 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
507 DALI_TEST_CHECK( effect );
509 BufferImage image = CreateBufferImage();
511 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
513 ImageActor actor = ImageActor::New( image );
514 actor.SetSize( 100.0f, 100.0f );
515 actor.SetName("TestImageFilenameActor");
516 actor.SetShaderEffect(effect);
517 Stage::GetCurrent().Add(actor);
519 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
521 application.SendNotification();
522 application.Render();
524 // Test effects of SetUniform...
526 application.GetGlAbstraction().CheckUniformValue(
527 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
529 Constraint constraint = Constraint::New<Vector3>( effect, uVecProperty, TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
532 application.SendNotification();
533 application.Render();
535 // Test effects of Constraint.
537 application.GetGlAbstraction().CheckUniformValue(
538 "uVec3", Vector3( 4.0f, 9.0f, 16.0f ) ) );
543 int UtcDaliShaderEffectMethodApplyConstraintFromActor(void)
545 // Test whether Shader's uniform can be constrained to Actor's position.
546 TestApplication application;
548 const Vector3 targetPosition = Vector3( 100.0f, 70.0f, 20.0f);
550 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
551 DALI_TEST_CHECK( effect );
553 BufferImage image = CreateBufferImage();
555 effect.SetUniform( "uVec3", Vector3( 50.0f, 25.0f, 0.0f ) );
557 ImageActor actor = ImageActor::New( image );
558 actor.SetPosition(targetPosition);
559 actor.SetSize( 100.0f, 100.0f );
560 actor.SetName("TestImageFilenameActor");
561 actor.SetShaderEffect(effect);
562 Stage::GetCurrent().Add(actor);
564 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
566 Constraint constraint = Constraint::New<Vector3>( effect, uVecProperty, TestConstraintFromPositionToVector3() );
567 constraint.AddSource( Source( actor, Actor::Property::POSITION ) );
570 application.SendNotification();
571 application.Render();
573 // Test effects of Constraint.
575 application.GetGlAbstraction().CheckUniformValue(
576 "uVec3", targetPosition ) );
580 int UtcDaliShaderEffectMethodApplyConstraintFromActor2(void)
582 // Test whether Shader's uniform can be constrained to Actor's position.
583 // While Actor's position is constrained to another point * 2.0f
584 TestApplication application;
586 const Vector3 targetPosition = Vector3( 25.0f, 36.0f, 49.0f );
588 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
589 DALI_TEST_CHECK( effect );
591 BufferImage image = CreateBufferImage();
593 effect.SetUniform( "uVec3", Vector3( 50.0f, 25.0f, 0.0f ) );
595 ImageActor actor = ImageActor::New( image );
596 actor.SetPosition(Vector3( 100.0f, 70.0f, 20.0f));
597 actor.SetSize( 100.0f, 100.0f );
598 actor.SetName("TestImageFilenameActor");
599 actor.SetShaderEffect(effect);
600 Stage::GetCurrent().Add(actor);
602 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
604 Constraint shaderConstraint = Constraint::New<Vector3>( effect, uVecProperty, TestConstraintFromPositionToVector3() );
605 shaderConstraint.AddSource( Source(actor, Actor::Property::POSITION) );
606 shaderConstraint.Apply();
608 Constraint actorConstraint = Constraint::New<Vector3>( actor, Actor::Property::POSITION, TestConstraintToVector3Double(targetPosition) );
609 actorConstraint.Apply();
611 application.SendNotification();
612 application.Render();
614 // Test effects of Constraint.
616 application.GetGlAbstraction().CheckUniformValue(
617 "uVec3", targetPosition * 2.0f ) );
621 int UtcDaliShaderEffectMethodRemoveConstraints(void)
623 // Test if constrains can be removed before they are ever applyed.
624 TestApplication application;
626 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
627 DALI_TEST_CHECK( effect );
629 BufferImage image = CreateBufferImage();
631 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
633 ImageActor actor = ImageActor::New( image );
634 actor.SetSize( 100.0f, 100.0f );
635 actor.SetName("TestImageFilenameActor");
636 actor.SetShaderEffect(effect);
637 Stage::GetCurrent().Add(actor);
639 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
641 application.SendNotification();
642 application.Render();
644 // Test effects of SetUniform...
646 application.GetGlAbstraction().CheckUniformValue(
647 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
649 Constraint constraint = Constraint::New<Vector3>( effect, uVecProperty, TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
652 // Remove the constraints
653 effect.RemoveConstraints();
655 application.SendNotification();
656 application.Render();
658 // Test effects of Constraint.
660 application.GetGlAbstraction().CheckUniformValue(
661 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
665 int UtcDaliShaderEffectMethodRemoveConstraints2(void)
667 // Test whether Shader's uniform constrains can be removed after they are applyed.
668 TestApplication application;
670 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
671 DALI_TEST_CHECK( effect );
673 BufferImage image = CreateBufferImage();
675 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
677 ImageActor actor = ImageActor::New( image );
678 actor.SetSize( 100.0f, 100.0f );
679 actor.SetName("TestImageFilenameActor");
680 actor.SetShaderEffect(effect);
681 Stage::GetCurrent().Add(actor);
683 Property::Index uVecProperty = effect.GetPropertyIndex("uVec3");
685 application.SendNotification();
686 application.Render();
688 // Test effects of SetUniform...
690 application.GetGlAbstraction().CheckUniformValue(
691 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
693 Constraint constraint = Constraint::New<Vector3>( effect, uVecProperty, TestConstraintToVector3(Vector3(4.0f, 9.0f, 16.0f)) );
696 application.SendNotification();
697 application.Render();
699 // Reset the value and remove the constraints
700 effect.SetUniform( "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) );
701 effect.RemoveConstraints();
703 application.SendNotification();
704 application.Render();
706 // Test effects of Constraint.
708 application.GetGlAbstraction().CheckUniformValue(
709 "uVec3", Vector3( 1.0f, 2.0f, 3.0f ) ) );
713 int UtcDaliShaderEffectPropertyIndices(void)
715 TestApplication application;
716 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
718 Property::IndexContainer indices;
719 effect.GetPropertyIndices( indices );
720 DALI_TEST_CHECK( indices.Size() );
721 DALI_TEST_EQUALS( indices.Size(), effect.GetPropertyCount(), TEST_LOCATION );
725 int UtcDaliShaderBinaries(void)
727 TestApplication application;
728 // these will not affect the "first round" of dali render as core is already initialized and it has queried the defaults
729 application.GetGlAbstraction().SetBinaryFormats( 1 );
730 application.GetGlAbstraction().SetNumBinaryFormats( 1 );
731 application.GetGlAbstraction().SetProgramBinaryLength( 1 );
733 GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
735 ShaderEffect effect = ShaderEffect::New( VertexSource, FragmentSource );
736 DALI_TEST_CHECK( effect );
738 BufferImage image = CreateBufferImage();
739 ImageActor actor = ImageActor::New( image );
740 actor.SetSize( 100.0f, 100.0f );
741 actor.SetName("TestImageFilenameActor");
742 actor.SetShaderEffect(effect);
743 Stage::GetCurrent().Add(actor);
745 application.SendNotification();
746 application.Render(16);
747 // binary was not requested by DALi
748 DALI_TEST_CHECK( !(application.GetGlAbstraction().GetProgramBinaryCalled()) );
750 GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
752 // check that the shader was compiled
753 DALI_TEST_EQUALS( lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION );
755 // simulate context loss to get core to re-initialize its GL
756 application.GetCore().ContextDestroyed();
757 application.GetCore().ContextCreated();
759 application.SendNotification();
760 application.Render(16);
762 // shader is recompiled
763 GLuint finalShaderCompiled = application.GetGlAbstraction().GetLastShaderCompiled();
764 // check that the shader was compiled
765 DALI_TEST_EQUALS( lastShaderCompiledAfter + 2, finalShaderCompiled, TEST_LOCATION );
767 // binary was requested by DALi
768 DALI_TEST_CHECK( application.GetGlAbstraction().GetProgramBinaryCalled() );
773 int UtcDaliShaderEffectFromPropertiesP(void)
775 TestApplication application;
776 tet_infoline("UtcDaliShaderEffectFromProperties01()");
778 std::string fragmentShaderPrefix = "#define TEST_FS 1\n#extension GL_OES_standard_derivatives : enable";
779 std::string vertexShaderPrefix = "#define TEST_VS 1";
780 std::string vertexShader(VertexSource);
781 std::string fragmentShader(FragmentSource);
783 // Call render to compile default shaders.
784 application.SendNotification();
785 application.Render();
787 GLuint lastShaderCompiledBefore = application.GetGlAbstraction().GetLastShaderCompiled();
789 // create from type registry
791 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "ShaderEffect" );
792 DALI_TEST_CHECK( typeInfo );
793 ShaderEffect effect = ShaderEffect::DownCast( typeInfo.CreateInstance() );
794 DALI_TEST_CHECK( effect );
796 Property::Value programValue = Property::Value(Property::MAP);
797 Property::Map* programMap = programValue.GetMap();
798 DALI_TEST_CHECK( programMap );
800 programMap->Insert("vertex", vertexShader);
801 programMap->Insert("fragment", fragmentShader);
803 programMap->Insert("vertex-prefix", vertexShaderPrefix);
804 programMap->Insert("fragment-prefix", fragmentShaderPrefix);
806 effect.SetProperty(effect.GetPropertyIndex("program"), programValue);
808 Property::Value imageValue = Property::Value(Property::MAP);
809 Property::Map* imageMap = imageValue.GetMap();
810 DALI_TEST_CHECK( imageMap );
811 imageMap->Insert("filename", Property::Value(TestImageFilename));
812 effect.SetProperty(effect.GetPropertyIndex("image"), imageValue);
814 // do a update & render to get the image request
815 application.SendNotification();
816 application.Render();
818 Integration::ResourceRequest* request = application.GetPlatform().GetRequest();
820 Integration::Bitmap* bitmap = CreateBitmap( 10, 10, 0xFF );
821 Integration::ResourcePointer resourcePtr(bitmap);
822 TestPlatformAbstraction& platform = application.GetPlatform();
823 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, resourcePtr);
825 BufferImage image(CreateBufferImage());
826 ImageActor actor = ImageActor::New( image );
827 actor.SetSize( 100.0f, 100.0f );
828 actor.SetName("TestImageFilenameActor");
829 actor.SetShaderEffect(effect);
830 Stage::GetCurrent().Add(actor);
832 application.SendNotification();
833 application.Render();
834 GLuint lastShaderCompiledAfter = application.GetGlAbstraction().GetLastShaderCompiled();
836 // we should have compiled 2 shaders.
837 DALI_TEST_EQUALS(lastShaderCompiledAfter, lastShaderCompiledBefore + 2, TEST_LOCATION );
839 std::string actualVertexShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 1 );
840 DALI_TEST_EQUALS( vertexShaderPrefix, actualVertexShader.substr( 0, vertexShaderPrefix.length() ), TEST_LOCATION );
841 DALI_TEST_EQUALS( vertexShader, actualVertexShader.substr( actualVertexShader.length() - vertexShader.length() ), TEST_LOCATION );
843 std::string actualFragmentShader = application.GetGlAbstraction().GetShaderSource( lastShaderCompiledBefore + 2 );
844 DALI_TEST_EQUALS( fragmentShaderPrefix, actualFragmentShader.substr( 0, fragmentShaderPrefix.length() ), TEST_LOCATION );
845 DALI_TEST_EQUALS( fragmentShader, actualFragmentShader.substr( actualFragmentShader.length() - fragmentShader.length() ), TEST_LOCATION );
850 int UtcDaliShaderEffectFromPropertiesN(void)
854 TestApplication application;
855 tet_infoline("UtcDaliShaderEffectFromProperties02()");
857 // Call render to compile default shaders.
858 application.SendNotification();
859 application.Render();
861 // create from type registry (currently only way to get ShaderEffect with no shader setup in constructor
862 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "ShaderEffect" );
863 DALI_TEST_CHECK( typeInfo );
864 ShaderEffect effect = ShaderEffect::DownCast( typeInfo.CreateInstance() );
865 DALI_TEST_CHECK( effect );
867 Property::Value programValue = Property::Value(Property::MAP);
868 Property::Map* programMap = programValue.GetMap();
869 DALI_TEST_CHECK( programMap );
871 programMap->Insert("vertex", std::string(VertexSource));
872 programMap->Insert("fragment", std::string(FragmentSource));
874 // use wrong index on purpose
875 effect.SetProperty(effect.GetPropertyIndex("program") + 1, programValue );
877 tet_result( TET_FAIL );
879 catch(Dali::DaliException& e)
881 DALI_TEST_PRINT_ASSERT( e );
886 int UtcDaliShaderEffectFromProperties2N(void)
890 TestApplication application;
891 tet_infoline("UtcDaliShaderEffectFromProperties03()");
893 // Call render to compile default shaders.
894 application.SendNotification();
895 application.Render();
897 // create from type registry (currently only way to get ShaderEffect with no shader setup in constructor
898 TypeInfo typeInfo = TypeRegistry::Get().GetTypeInfo( "ShaderEffect" );
899 DALI_TEST_CHECK( typeInfo );
900 ShaderEffect effect = ShaderEffect::DownCast( typeInfo.CreateInstance() );
901 DALI_TEST_CHECK( effect );
904 effect.SetProperty( effect.GetPropertyIndex("geometry-hints"), "HINT_2" );
906 tet_result( TET_FAIL );
908 catch(Dali::DaliException& e)
910 DALI_TEST_PRINT_ASSERT( e );