#include <stdlib.h>
#include <dali/public-api/dali-core.h>
-#include <dali/devel-api/object/handle-devel.h>
#include <dali-test-suite-utils.h>
#include <mesh-builder.h>
END_TEST;
}
+int UtcDaliShaderDefaultProperties(void)
+{
+ TestApplication application;
+// from shader-impl.cpp
+// DALI_PROPERTY( "program", MAP, true, false, false, Dali::Shader::Property::PROGRAM )
+
+ Shader shader = Shader::New(VertexSource, FragmentSource);
+ DALI_TEST_EQUALS( shader.GetPropertyCount(), 1, TEST_LOCATION );
+
+ DALI_TEST_EQUALS( shader.GetPropertyName( Shader::Property::PROGRAM ), "program", TEST_LOCATION );
+ DALI_TEST_EQUALS( shader.GetPropertyIndex( "program" ), (Property::Index)Shader::Property::PROGRAM, TEST_LOCATION );
+ DALI_TEST_EQUALS( shader.GetPropertyType( Shader::Property::PROGRAM ), Property::MAP, TEST_LOCATION );
+ DALI_TEST_EQUALS( shader.IsPropertyWritable( Shader::Property::PROGRAM ), true, TEST_LOCATION );
+ DALI_TEST_EQUALS( shader.IsPropertyAnimatable( Shader::Property::PROGRAM ), false, TEST_LOCATION );
+ DALI_TEST_EQUALS( shader.IsPropertyAConstraintInput( Shader::Property::PROGRAM ), false, TEST_LOCATION );
+
+ END_TEST;
+}
+
int UtcDaliShaderConstraint01(void)
{
TestApplication application;
application.Render(0);
// Expect no blue component in either buffer - yellow
- DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( shader, colorIndex ), Color::YELLOW, TEST_LOCATION );
+ DALI_TEST_EQUALS( shader.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
application.Render(0);
- DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( shader, colorIndex ), Color::YELLOW, TEST_LOCATION );
+ DALI_TEST_EQUALS( shader.GetCurrentProperty< Vector4 >( colorIndex ), Color::YELLOW, TEST_LOCATION );
shader.RemoveConstraints();
shader.SetProperty(colorIndex, Color::WHITE );
application.SendNotification();
application.Render(0);
- DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( shader, colorIndex ), Color::WHITE, TEST_LOCATION );
+ DALI_TEST_EQUALS( shader.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE, TEST_LOCATION );
END_TEST;
}
application.SendNotification();
application.Render(500);
- DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( shader, colorIndex ), Color::WHITE * 0.5f, TEST_LOCATION );
+ DALI_TEST_EQUALS( shader.GetCurrentProperty< Vector4 >( colorIndex ), Color::WHITE * 0.5f, TEST_LOCATION );
application.Render(500);
- DALI_TEST_EQUALS( DevelHandle::GetCurrentProperty< Vector4 >( shader, colorIndex ), Color::TRANSPARENT, TEST_LOCATION );
+ DALI_TEST_EQUALS( shader.GetCurrentProperty< Vector4 >( colorIndex ), Color::TRANSPARENT, TEST_LOCATION );
END_TEST;
}
DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
+ // change shader program
+ Property::Map map;
+ map["vertex"] = VertexSource;
+ map["fragment"] = FragmentSource;
+ map["hints"] = "MODIFIES_GEOMETRY";
+ shader.SetProperty( Shader::Property::PROGRAM, Property::Value(map) );
+ application.SendNotification();
+ application.Render(100);
+
+ // register another custom property as well
+ Property::Index customIndex = shader.RegisterProperty( "uCustom", Vector3(1,2,3) );
+ DALI_TEST_EQUALS( shader.GetProperty<Vector3>( customIndex ), Vector3(1,2,3), TEST_LOCATION );
+
+ application.SendNotification();
+ application.Render(100);
+
+ DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
+ DALI_TEST_EQUALS( actualValue, Color::TRANSPARENT, TEST_LOCATION );
+
+ Vector3 customValue;
+ DALI_TEST_CHECK( gl.GetUniformValue<Vector3>( "uCustom", customValue ) );
+ DALI_TEST_EQUALS( customValue, Vector3(1,2,3), TEST_LOCATION );
END_TEST;
}
map["hints"] = hintSet;
shader.SetProperty( Shader::Property::PROGRAM, Property::Value(map) );
+ // register a custom property as well
+ Property::Index customIndex = shader.RegisterProperty( "custom", Vector3(1,2,3) );
+ DALI_TEST_EQUALS( shader.GetProperty<Vector3>( customIndex ), Vector3(1,2,3), TEST_LOCATION );
Property::Value value = shader.GetProperty(Shader::Property::PROGRAM);
DALI_TEST_CHECK( value.GetType() == Property::MAP);
DALI_TEST_CHECK( f == FragmentSource );
DALI_TEST_CHECK( h == hintSet );
+ value = shader.GetCurrentProperty( Shader::Property::PROGRAM );
+ DALI_TEST_CHECK( value.GetType() == Property::MAP);
+ outMap = value.GetMap();
+ // check that changing the shader did not cause us to loose custom property
+ DALI_TEST_EQUALS( shader.GetProperty<Vector3>( customIndex ), Vector3(1,2,3), TEST_LOCATION );
+ using Dali::Animation;
+ Animation animation = Animation::New( 0.1f );
+ animation.AnimateTo( Property( shader, customIndex ), Vector3(4,5,6) );
+ animation.Play();
+ application.SendNotification();
+ application.Render(100);
+ DALI_TEST_EQUALS( shader.GetProperty<Vector3>( customIndex ), Vector3(4,5,6), TEST_LOCATION );
+
+ v = (*outMap)["vertex"].Get<std::string>();
+ f = (*outMap)["fragment"].Get<std::string>();
+ h = (*outMap)["hints"].Get<std::string>();
+
+ DALI_TEST_CHECK( v == VertexSource );
+ DALI_TEST_CHECK( f == FragmentSource );
+ DALI_TEST_CHECK( h == hintSet );
+
std::string hintGot;
hintSet = "OUTPUT_IS_TRANSPARENT,MODIFIES_GEOMETRY";