+ application.SendNotification();
+ application.Render(0);
+
+ /*
+ * Create the following hierarchy:
+ *
+ * actor2
+ * /
+ * /
+ * actor1
+ * /
+ * /
+ * actor0
+ * /
+ * /
+ * actor3
+ *
+ * Expected rendering order : actor2 - actor1 - actor0 - actor3
+ */
+ actor2.Add(actor1);
+ actor1.Add(actor0);
+ actor0.Add(actor3);
+ application.SendNotification();
+ application.Render(0);
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ gl.EnableTextureCallTrace(true);
+ application.SendNotification();
+ application.Render(0);
+
+ int textureBindIndex[4];
+ for( unsigned int i(0); i<4; ++i )
+ {
+ std::stringstream params;
+ params << GL_TEXTURE_2D<<", "<<i+1;
+ textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
+ }
+
+ //Check that actor1 has been rendered after actor2
+ DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[2], TEST_LOCATION );
+
+ //Check that actor0 has been rendered after actor1
+ DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
+
+ //Check that actor3 has been rendered after actor0
+ DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliRendererRenderOrder2DLayerMultipleRenderers(void)
+{
+ TestApplication application;
+ tet_infoline("Test the rendering order in a 2D layer is correct using multiple renderers per actor");
+
+ /*
+ * Creates the following hierarchy:
+ *
+ * actor0------------------------>actor1
+ * / | \ / | \
+ * / | \ / | \
+ * / | \ / | \
+ * renderer0 renderer1 renderer2 renderer3 renderer4 renderer5
+ *
+ * renderer0 has depth index 2
+ * renderer1 has depth index 0
+ * renderer2 has depth index 1
+ *
+ * renderer3 has depth index 1
+ * renderer4 has depth index 0
+ * renderer5 has depth index -1
+ *
+ * Expected rendering order: renderer1 - renderer2 - renderer0 - renderer5 - renderer4 - renderer3
+ */
+
+ Shader shader = Shader::New("VertexSource", "FragmentSource");
+ Geometry geometry = CreateQuadGeometry();
+
+ Actor root = Stage::GetCurrent().GetRootLayer();
+
+ Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
+ Actor actor1 = CreateActor( actor0, 0, TEST_LOCATION );
+ Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
+ Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
+ Renderer renderer2 = CreateRenderer( actor0, geometry, shader, 1 );
+ Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
+ Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 0 );
+ Renderer renderer5 = CreateRenderer( actor1, geometry, shader, -1 );
+
+ application.SendNotification();
+ application.Render(0);
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ gl.EnableTextureCallTrace(true);
+ application.SendNotification();
+ application.Render(0);
+
+ int textureBindIndex[6];
+ for( unsigned int i(0); i<6; ++i )
+ {
+ std::stringstream params;
+ params << GL_TEXTURE_2D<<", "<<i+1;
+ textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
+ }
+
+ //Check that renderer3 has been rendered after renderer4
+ DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[4], TEST_LOCATION );
+
+ //Check that renderer0 has been rendered after renderer2
+ DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[5], TEST_LOCATION );
+
+ //Check that renderer0 has been rendered after renderer2
+ DALI_TEST_GREATER( textureBindIndex[5], textureBindIndex[0], TEST_LOCATION );
+
+ //Check that renderer0 has been rendered after renderer2
+ DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[2], TEST_LOCATION );
+
+ //Check that renderer2 has been rendered after renderer1
+ DALI_TEST_GREATER( textureBindIndex[2], textureBindIndex[1], TEST_LOCATION );
+
+ END_TEST;
+}
+
+
+int UtcDaliRendererRenderOrder2DLayerSiblingOrder(void)
+{
+ TestApplication application;
+ tet_infoline("Test the rendering order in a 2D layer is correct using sibling order");
+
+ /*
+ * Creates the following hierarchy:
+ *
+ * Layer
+ * / \
+ * / \
+ * / \
+ * / \
+ * / \
+ * actor0 (SIBLING_ORDER:1) actor1 (SIBLING_ORDER:0)
+ * / | \ / | \
+ * / | \ / | \
+ * / | \ / | \
+ * renderer0 renderer1 actor2 renderer2 renderer3 renderer4
+ * DI:2 DI:0 | DI:0 DI:1 DI:2
+ * |
+ * renderer5
+ * DI:-1
+ *
+ * actor0 has sibling order 1
+ * actor1 has sibling order 0
+ * actor2 has sibling order 0
+ *
+ * renderer0 has depth index 2
+ * renderer1 has depth index 0
+ *
+ * renderer2 has depth index 0
+ * renderer3 has depth index 1
+ * renderer4 has depth index 2
+ *
+ * renderer5 has depth index -1
+ *
+ * Expected rendering order: renderer2 - renderer3 - renderer4 - renderer1 - renderer0 - renderer5
+ */
+
+ Shader shader = Shader::New("VertexSource", "FragmentSource");
+ Geometry geometry = CreateQuadGeometry();
+ Actor root = Stage::GetCurrent().GetRootLayer();
+ Actor actor0 = CreateActor( root, 1, TEST_LOCATION );
+ Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
+ Actor actor2 = CreateActor( actor0, 0, TEST_LOCATION );
+
+ Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 2 );
+ Renderer renderer1 = CreateRenderer( actor0, geometry, shader, 0 );
+ Renderer renderer2 = CreateRenderer( actor1, geometry, shader, 0 );
+ Renderer renderer3 = CreateRenderer( actor1, geometry, shader, 1 );
+ Renderer renderer4 = CreateRenderer( actor1, geometry, shader, 2 );
+ Renderer renderer5 = CreateRenderer( actor2, geometry, shader, -1 );
+
+ application.SendNotification();
+ application.Render();
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ gl.EnableTextureCallTrace(true);
+ application.SendNotification();
+ application.Render(0);
+
+ int textureBindIndex[6];
+ for( unsigned int i(0); i<6; ++i )
+ {
+ std::stringstream params;
+ params << GL_TEXTURE_2D<<", "<<i+1;
+ textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
+ }
+
+ DALI_TEST_EQUALS( textureBindIndex[2], 0, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureBindIndex[3], 1, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureBindIndex[4], 2, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureBindIndex[1], 3, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureBindIndex[0], 4, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureBindIndex[5], 5, TEST_LOCATION );
+
+ // Change sibling order of actor1
+ // New Expected rendering order: renderer1 - renderer0 - renderer 5 - renderer2 - renderer3 - renderer4
+ actor1.SetProperty( Dali::DevelActor::Property::SIBLING_ORDER, 2 );
+
+ gl.GetTextureTrace().Reset();
+ application.SendNotification();
+ application.Render(0);
+
+ for( unsigned int i(0); i<6; ++i )
+ {
+ std::stringstream params;
+ params << GL_TEXTURE_2D<<", "<<i+1;
+ textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
+ }
+
+ DALI_TEST_EQUALS( textureBindIndex[1], 0, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureBindIndex[0], 1, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureBindIndex[5], 2, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureBindIndex[2], 3, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureBindIndex[3], 4, TEST_LOCATION );
+ DALI_TEST_EQUALS( textureBindIndex[4], 5, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliRendererRenderOrder2DLayerOverlay(void)
+{
+ TestApplication application;
+ tet_infoline("Test the rendering order in a 2D layer is correct for overlays");
+
+ Shader shader = Shader::New("VertexSource", "FragmentSource");
+ Geometry geometry = CreateQuadGeometry();
+ Actor root = Stage::GetCurrent().GetRootLayer();
+
+ /*
+ * Create the following hierarchy:
+ *
+ * actor2
+ * (Regular actor)
+ * / \
+ * / \
+ * actor1 actor4
+ * (Overlay) (Regular actor)
+ * /
+ * /
+ * actor0
+ * (Overlay)
+ * /
+ * /
+ * actor3
+ * (Overlay)
+ *
+ * Expected rendering order : actor2 - actor4 - actor1 - actor0 - actor3
+ */
+
+ Actor actor0 = CreateActor( root, 0, TEST_LOCATION );
+ actor0.SetDrawMode( DrawMode::OVERLAY_2D );
+ Renderer renderer0 = CreateRenderer( actor0, geometry, shader, 0 );
+
+ Actor actor1 = CreateActor( root, 0, TEST_LOCATION );
+ actor1.SetDrawMode( DrawMode::OVERLAY_2D );
+ Renderer renderer1 = CreateRenderer( actor1, geometry, shader, 0 );
+
+ Actor actor2 = CreateActor( root, 0, TEST_LOCATION );
+ Renderer renderer2 = CreateRenderer( actor2, geometry, shader, 0 );
+
+ Actor actor3 = CreateActor( root, 0, TEST_LOCATION );
+ actor3.SetDrawMode( DrawMode::OVERLAY_2D );
+ Renderer renderer3 = CreateRenderer( actor3, geometry, shader, 0 );
+
+ Actor actor4 = CreateActor( root, 0, TEST_LOCATION );
+ Renderer renderer4 = CreateRenderer( actor4, geometry, shader, 0 );
+
+ application.SendNotification();
+ application.Render(0);
+
+ actor2.Add(actor1);
+ actor2.Add(actor4);
+ actor1.Add(actor0);
+ actor0.Add(actor3);
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ gl.EnableTextureCallTrace(true);
+ application.SendNotification();
+ application.Render(0);
+
+ int textureBindIndex[5];
+ for( unsigned int i(0); i<5; ++i )
+ {
+ std::stringstream params;
+ params << GL_TEXTURE_2D<<", "<<i+1;
+ textureBindIndex[i] = gl.GetTextureTrace().FindIndexFromMethodAndParams("BindTexture", params.str() );
+ }
+
+ //Check that actor4 has been rendered after actor2
+ DALI_TEST_GREATER( textureBindIndex[4], textureBindIndex[2], TEST_LOCATION );
+
+ //Check that actor1 has been rendered after actor4
+ DALI_TEST_GREATER( textureBindIndex[1], textureBindIndex[4], TEST_LOCATION );
+
+ //Check that actor0 has been rendered after actor1
+ DALI_TEST_GREATER( textureBindIndex[0], textureBindIndex[1], TEST_LOCATION );
+
+ //Check that actor3 has been rendered after actor0
+ DALI_TEST_GREATER( textureBindIndex[3], textureBindIndex[0], TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliRendererSetIndexRange(void)
+{
+ std::string
+ vertexShader(
+ "attribute vec2 aPosition;\n"
+ "void main()\n"
+ "{\n"
+ " gl_Position = aPosition;\n"
+ "}"
+ ),
+ fragmentShader(
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)\n"
+ "}\n"
+ );
+
+ TestApplication application;
+ tet_infoline("Test setting the range of indices to draw");
+
+ TestGlAbstraction& gl = application.GetGlAbstraction();
+ gl.EnableDrawCallTrace( true );
+
+ Actor actor = Actor::New();
+ actor.SetSize( 100, 100 );
+
+ // create geometry
+ Geometry geometry = Geometry::New();
+ geometry.SetType( Geometry::LINE_LOOP );
+
+ // --------------------------------------------------------------------------
+ // index buffer
+ unsigned short indices[] = { 0, 2, 4, 6, 8, // offset = 0, count = 5
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, // offset = 5, count = 10
+ 1, 3, 5, 7, 9, 1 }; // offset = 15, count = 6 // line strip
+
+ // --------------------------------------------------------------------------
+ // vertex buffer
+ struct Vertex
+ {
+ Vector2 position;
+ };
+ Vertex shapes[] =
+ {
+ // pentagon // star
+ { Vector2( 0.0f, 1.00f) }, { Vector2( 0.0f, -1.00f) },
+ { Vector2( -0.95f, 0.31f) }, { Vector2( 0.59f, 0.81f) },
+ { Vector2( -0.59f, -0.81f) }, { Vector2( -0.95f, -0.31f) },
+ { Vector2( 0.59f, -0.81f) }, { Vector2( 0.95f, -0.31f) },
+ { Vector2( 0.95f, 0.31f) }, { Vector2( -0.59f, 0.81f) },
+ };
+ Property::Map vertexFormat;
+ vertexFormat["aPosition"] = Property::VECTOR2;
+ PropertyBuffer vertexBuffer = PropertyBuffer::New( vertexFormat );
+ vertexBuffer.SetData( shapes, sizeof(shapes)/sizeof(shapes[0]));
+
+ // --------------------------------------------------------------------------
+ geometry.SetIndexBuffer( indices, sizeof(indices)/sizeof(indices[0]) );
+ geometry.AddVertexBuffer( vertexBuffer );
+
+ // create shader
+ Shader shader = Shader::New( vertexShader,fragmentShader );
+ Renderer renderer = Renderer::New( geometry, shader );
+ actor.AddRenderer( renderer );
+
+ Stage stage = Stage::GetCurrent();
+ stage.Add( actor );
+
+ char buffer[ 128 ];
+
+ // LINE_LOOP, first 0, count 5
+ {
+ renderer.SetIndexRange( 0, 5 );
+ application.SendNotification();
+ application.Render();
+ sprintf( buffer, "%u, 5, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
+ bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
+ DALI_TEST_CHECK( result );
+ }
+
+ // LINE_LOOP, first 5, count 10
+ {
+ renderer.SetIndexRange( 5, 10 );
+ sprintf( buffer, "%u, 10, %u, indices", GL_LINE_LOOP, GL_UNSIGNED_SHORT );
+ application.SendNotification();
+ application.Render();
+ bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
+ DALI_TEST_CHECK( result );
+ }
+
+ // LINE_STRIP, first 15, count 6
+ {
+ renderer.SetIndexRange( 15, 6 );
+ geometry.SetType( Geometry::LINE_STRIP );
+ sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
+ application.SendNotification();
+ application.Render();
+ bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
+ DALI_TEST_CHECK( result );
+ }
+
+ // Index out of bounds
+ {
+ renderer.SetIndexRange( 15, 30 );
+ geometry.SetType( Geometry::LINE_STRIP );
+ sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
+ application.SendNotification();
+ application.Render();
+ bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
+ DALI_TEST_CHECK( result );
+ }
+
+ // drawing whole buffer starting from 15 ( last valid primitive )
+ {
+ renderer.SetIndexRange( 15, 0 );
+ geometry.SetType( Geometry::LINE_STRIP );
+ sprintf( buffer, "%u, 6, %u, indices", GL_LINE_STRIP, GL_UNSIGNED_SHORT );
+ application.SendNotification();
+ application.Render();
+ bool result = gl.GetDrawTrace().FindMethodAndParams( "DrawElements" , buffer );
+ DALI_TEST_CHECK( result );
+ }
+
+ END_TEST;
+}
+
+
+int UtcDaliRendererSetDepthFunction(void)
+{
+ TestApplication application;
+
+ tet_infoline("Test setting the depth function");
+
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = CreateShader();
+ Renderer renderer = Renderer::New( geometry, shader );
+
+ Actor actor = Actor::New();
+ actor.AddRenderer(renderer);
+ actor.SetSize(400, 400);
+ Stage stage = Stage::GetCurrent();
+ stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
+ stage.Add(actor);
+
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace(true);
+ glAbstraction.EnableDepthFunctionCallTrace(true);
+
+ TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
+ TraceCallStack& glDepthFunctionStack = glAbstraction.GetDepthFunctionTrace();
+
+ std::ostringstream depthTestStr;
+ depthTestStr << GL_DEPTH_TEST;
+
+ //GL_NEVER
+ {
+ renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NEVER);
+
+ glEnableDisableStack.Reset();
+ glDepthFunctionStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", depthTestStr.str().c_str() ) );
+ std::ostringstream depthFunctionStr;
+ depthFunctionStr << GL_NEVER;
+ DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
+ }
+
+ //GL_ALWAYS
+ {
+ renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::ALWAYS);
+
+ glDepthFunctionStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ std::ostringstream depthFunctionStr;
+ depthFunctionStr << GL_ALWAYS;
+ DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
+ }
+
+ //GL_LESS
+ {
+ renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS);
+
+ glDepthFunctionStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ std::ostringstream depthFunctionStr;
+ depthFunctionStr << GL_LESS;
+ DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
+ }
+
+ //GL_GREATER
+ {
+ renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER);
+
+ glDepthFunctionStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ std::ostringstream depthFunctionStr;
+ depthFunctionStr << GL_GREATER;
+ DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
+ }
+
+ //GL_EQUAL
+ {
+ renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::EQUAL);
+
+ glDepthFunctionStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ std::ostringstream depthFunctionStr;
+ depthFunctionStr << GL_EQUAL;
+ DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
+ }
+
+ //GL_NOTEQUAL
+ {
+ renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::NOT_EQUAL);
+
+ glDepthFunctionStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ std::ostringstream depthFunctionStr;
+ depthFunctionStr << GL_NOTEQUAL;
+ DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
+ }
+
+ //GL_LEQUAL
+ {
+ renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS_EQUAL);
+
+ glDepthFunctionStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ std::ostringstream depthFunctionStr;
+ depthFunctionStr << GL_LEQUAL;
+ DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
+ }
+
+ //GL_GEQUAL
+ {
+ renderer.SetProperty( Renderer::Property::DEPTH_FUNCTION, DepthFunction::GREATER_EQUAL);
+
+ glDepthFunctionStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ std::ostringstream depthFunctionStr;
+ depthFunctionStr << GL_GEQUAL;
+ DALI_TEST_CHECK( glDepthFunctionStack.FindMethodAndParams( "DepthFunc", depthFunctionStr.str().c_str() ) );
+ }
+
+ END_TEST;
+}
+
+/**
+ * @brief This templatized function checks an enumeration property is setting and getting correctly.
+ * The checks performed are as follows:
+ * - Check the initial/default value.
+ * - Set a different value via enum.
+ * - Check it was set.
+ * - Set a different value via string.
+ * - Check it was set.
+ */
+template< typename T >
+void CheckEnumerationProperty( Renderer& renderer, Property::Index propertyIndex, T initialValue, T firstCheckEnumeration, T secondCheckEnumeration, std::string secondCheckString )
+{
+ DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( initialValue ) );
+ DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( initialValue ) );
+ renderer.SetProperty( propertyIndex, firstCheckEnumeration );
+ DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
+ DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( firstCheckEnumeration ) );
+ renderer.SetProperty( propertyIndex, secondCheckString );
+ DALI_TEST_CHECK( renderer.GetProperty<int>( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
+ DALI_TEST_CHECK( renderer.GetCurrentProperty< int >( propertyIndex ) == static_cast<int>( secondCheckEnumeration ) );
+}
+
+int UtcDaliRendererEnumProperties(void)
+{
+ TestApplication application;
+ tet_infoline( "Test Renderer enumeration properties can be set with both integer and string values" );
+
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = CreateShader();
+ Renderer renderer = Renderer::New( geometry, shader );
+
+ /*
+ * Here we use a templatized function to perform several checks on each enumeration property.
+ * @see CheckEnumerationProperty for details of the checks performed.
+ */
+
+ CheckEnumerationProperty< FaceCullingMode::Type >( renderer, Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::NONE, FaceCullingMode::FRONT, FaceCullingMode::BACK, "BACK" );
+ CheckEnumerationProperty< BlendMode::Type >( renderer, Renderer::Property::BLEND_MODE, BlendMode::AUTO, BlendMode::OFF, BlendMode::ON, "ON" );
+ CheckEnumerationProperty< BlendEquation::Type >( renderer, Renderer::Property::BLEND_EQUATION_RGB, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
+ CheckEnumerationProperty< BlendEquation::Type >( renderer, Renderer::Property::BLEND_EQUATION_ALPHA, BlendEquation::ADD, BlendEquation::SUBTRACT, BlendEquation::REVERSE_SUBTRACT, "REVERSE_SUBTRACT" );
+ CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_SRC_RGB, BlendFactor::SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
+ CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_DEST_RGB, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
+ CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_SRC_ALPHA, BlendFactor::ONE, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::SRC_COLOR, "SRC_COLOR" );
+ CheckEnumerationProperty< BlendFactor::Type >( renderer, Renderer::Property::BLEND_FACTOR_DEST_ALPHA, BlendFactor::ONE_MINUS_SRC_ALPHA, BlendFactor::ONE, BlendFactor::SRC_COLOR, "SRC_COLOR" );
+ CheckEnumerationProperty< DepthWriteMode::Type >( renderer, Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO, DepthWriteMode::OFF, DepthWriteMode::ON, "ON" );
+ CheckEnumerationProperty< DepthFunction::Type >( renderer, Renderer::Property::DEPTH_FUNCTION, DepthFunction::LESS, DepthFunction::ALWAYS, DepthFunction::GREATER, "GREATER" );
+ CheckEnumerationProperty< DepthTestMode::Type >( renderer, Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO, DepthTestMode::OFF, DepthTestMode::ON, "ON" );
+ CheckEnumerationProperty< StencilFunction::Type >( renderer, Renderer::Property::STENCIL_FUNCTION, StencilFunction::ALWAYS, StencilFunction::LESS, StencilFunction::EQUAL, "EQUAL" );
+ CheckEnumerationProperty< RenderMode::Type >( renderer, Renderer::Property::RENDER_MODE, RenderMode::AUTO, RenderMode::NONE, RenderMode::STENCIL, "STENCIL" );
+ CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
+ CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
+ CheckEnumerationProperty< StencilOperation::Type >( renderer, Renderer::Property::STENCIL_OPERATION_ON_Z_PASS, StencilOperation::KEEP, StencilOperation::REPLACE, StencilOperation::INCREMENT, "INCREMENT" );
+
+ END_TEST;
+}
+
+Renderer RendererTestFixture( TestApplication& application )
+{
+ Geometry geometry = CreateQuadGeometry();
+ Shader shader = CreateShader();
+ Renderer renderer = Renderer::New( geometry, shader );
+
+ Actor actor = Actor::New();
+ actor.AddRenderer( renderer );
+ actor.SetSize( 400.0f, 400.0f );
+ Stage stage = Stage::GetCurrent();
+ stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
+ stage.Add( actor );
+
+ return renderer;
+}
+
+int UtcDaliRendererSetDepthTestMode(void)
+{
+ TestApplication application;
+ tet_infoline("Test setting the DepthTestMode");
+
+ Renderer renderer = RendererTestFixture( application );
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace( true );
+ TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
+
+ glEnableDisableStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ // Check depth-test is enabled by default.
+ DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
+ DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
+
+ // Turn off depth-testing. We want to check if the depth buffer has been disabled, so we need to turn off depth-write as well for this case.
+ renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::OFF );
+ renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
+
+ glEnableDisableStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ // Check the depth buffer was disabled.
+ DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
+
+ // Turn on automatic mode depth-testing.
+ // Layer behavior is currently set to LAYER_3D so AUTO should enable depth-testing.
+ renderer.SetProperty( Renderer::Property::DEPTH_TEST_MODE, DepthTestMode::AUTO );
+
+ glEnableDisableStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ // Check depth-test is now enabled.
+ DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
+ DALI_TEST_CHECK( !glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
+
+ // Change the layer behavior to LAYER_2D.
+ // Note this will also disable depth testing for the layer by default, we test this first.
+ Stage::GetCurrent().GetRootLayer().SetBehavior( Layer::LAYER_2D );
+
+ glEnableDisableStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ // Check depth-test is disabled.
+ DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Disable", GetDepthTestString() ) );
+
+ // Turn the layer depth-test flag back on, and confirm that depth testing is now on.
+ Stage::GetCurrent().GetRootLayer().SetDepthTestDisabled( false );
+
+ glEnableDisableStack.Reset();
+ application.SendNotification();
+ application.Render();
+
+ // Check depth-test is *still* disabled.
+ DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetDepthTestString() ) );
+
+ END_TEST;
+}
+
+int UtcDaliRendererSetDepthWriteMode(void)
+{
+ TestApplication application;
+ tet_infoline("Test setting the DepthWriteMode");
+
+ Renderer renderer = RendererTestFixture( application );
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+
+ application.SendNotification();
+ application.Render();
+
+ // Check the default depth-write status first.
+ DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
+
+ // Turn off depth-writing.
+ renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::OFF );
+
+ application.SendNotification();
+ application.Render();
+
+ // Check depth-write is now disabled.
+ DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
+
+ // Test the AUTO mode for depth-writing.
+ // As our renderer is opaque, depth-testing should be enabled.
+ renderer.SetProperty( Renderer::Property::DEPTH_WRITE_MODE, DepthWriteMode::AUTO );
+
+ application.SendNotification();
+ application.Render();
+
+ // Check depth-write is now enabled.
+ DALI_TEST_CHECK( glAbstraction.GetLastDepthMask() );
+
+ // Now make the renderer be treated as translucent by enabling blending.
+ // The AUTO depth-write mode should turn depth-write off in this scenario.
+ renderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
+
+ application.SendNotification();
+ application.Render();
+
+ // Check depth-write is now disabled.
+ DALI_TEST_CHECK( !glAbstraction.GetLastDepthMask() );
+
+ END_TEST;
+}
+
+int UtcDaliRendererCheckStencilDefaults(void)
+{
+ TestApplication application;
+ tet_infoline("Test the stencil defaults");
+
+ Renderer renderer = RendererTestFixture( application );
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace( true );
+ glAbstraction.EnableStencilFunctionCallTrace( true );
+ TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
+ TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
+
+ ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
+
+ // Check the defaults:
+ DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::ALWAYS ), TEST_LOCATION );
+ DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
+ DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION_REFERENCE ).Get<int>() ), 0x00, TEST_LOCATION );
+ DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_MASK ).Get<int>() ), 0xFF, TEST_LOCATION );
+ DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
+ DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_FAIL ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
+ DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_OPERATION_ON_Z_PASS ).Get<int>() ), static_cast<int>( StencilOperation::KEEP ), TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliRendererSetRenderModeToUseStencilBuffer(void)
+{
+ TestApplication application;
+ tet_infoline("Test setting the RenderMode to use the stencil buffer");
+
+ Renderer renderer = RendererTestFixture( application );
+ TestGlAbstraction& glAbstraction = application.GetGlAbstraction();
+ glAbstraction.EnableEnableDisableCallTrace( true );
+ glAbstraction.EnableStencilFunctionCallTrace( true );
+ TraceCallStack& glEnableDisableStack = glAbstraction.GetEnableDisableTrace();
+ TraceCallStack& glStencilFunctionStack = glAbstraction.GetStencilFunctionTrace();
+
+ // Set the StencilFunction to something other than the default, to confirm it is set as a property,
+ // but NO GL call has been made while the RenderMode is set to not use the stencil buffer.
+ renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::NONE );
+ ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
+
+ renderer.SetProperty( Renderer::Property::STENCIL_FUNCTION, StencilFunction::NEVER );
+ DALI_TEST_EQUALS<int>( static_cast<int>( renderer.GetProperty( Renderer::Property::STENCIL_FUNCTION ).Get<int>() ), static_cast<int>( StencilFunction::NEVER ), TEST_LOCATION );
+
+ ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
+ std::string methodString( "StencilFunc" );
+ DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
+
+ // Test the other RenderModes that will not enable the stencil buffer.
+ renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::AUTO );
+ ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
+ DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
+
+ renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::COLOR );
+ ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
+ DALI_TEST_CHECK( !glStencilFunctionStack.FindMethod( methodString ) );
+
+ // Now set the RenderMode to modes that will use the stencil buffer, and check the StencilFunction has changed.
+ renderer.SetProperty( Renderer::Property::RENDER_MODE, RenderMode::STENCIL );
+ ResetDebugAndFlush( application, glEnableDisableStack, glStencilFunctionStack );
+
+ DALI_TEST_CHECK( glEnableDisableStack.FindMethodAndParams( "Enable", GetStencilTestString() ) );
+ DALI_TEST_CHECK( glStencilFunctionStack.FindMethod( methodString ) );