Added support for setting light position in mesh renderer. 68/79968/19
authorAndrew Poor <andrew.poor@samsung.com>
Wed, 6 Jul 2016 09:23:08 +0000 (10:23 +0100)
committerAndrew Poor <andrew.poor@samsung.com>
Fri, 22 Jul 2016 15:11:28 +0000 (16:11 +0100)
Change-Id: Ie8eabe9c40d7d8dc72c81e088e619a4aa5c8d338

automated-tests/src/dali-toolkit/utc-Dali-ControlRenderer.cpp
automated-tests/src/dali-toolkit/utc-Dali-RendererFactory.cpp
dali-toolkit/internal/controls/renderers/mesh/mesh-renderer.cpp
dali-toolkit/internal/controls/renderers/mesh/mesh-renderer.h
dali-toolkit/internal/controls/renderers/primitive/primitive-renderer.cpp
dali-toolkit/internal/controls/renderers/primitive/primitive-renderer.h
dali-toolkit/internal/controls/renderers/renderer-string-constants.cpp
docs/content/shared-javascript-and-cpp-documentation/control-renderers.md

index e37b040..0fd96ce 100644 (file)
@@ -656,6 +656,7 @@ int UtcDaliControlRendererGetPropertyMap8(void)
   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_LOCATION );
   propertyMap.Insert( "shaderType", "TEXTURELESS" );
   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_LOCATION );
   propertyMap.Insert( "shaderType", "TEXTURELESS" );
+  propertyMap.Insert( "lightPosition", Vector3( 5.0f, 10.0f, 15.0f) );
   ControlRenderer meshRenderer = factory.CreateControlRenderer( propertyMap );
 
   Property::Map resultMap;
   ControlRenderer meshRenderer = factory.CreateControlRenderer( propertyMap );
 
   Property::Map resultMap;
@@ -682,6 +683,10 @@ int UtcDaliControlRendererGetPropertyMap8(void)
   DALI_TEST_CHECK( value );
   DALI_TEST_EQUALS( value->Get<std::string>(), "TEXTURELESS", TEST_LOCATION );
 
   DALI_TEST_CHECK( value );
   DALI_TEST_EQUALS( value->Get<std::string>(), "TEXTURELESS", TEST_LOCATION );
 
+  value = resultMap.Find( "lightPosition", Property::VECTOR3 );
+  DALI_TEST_CHECK( value );
+  DALI_TEST_EQUALS( value->Get<Vector3>(), Vector3( 5.0f, 10.0f, 15.0f), Math::MACHINE_EPSILON_100, TEST_LOCATION );
+
   END_TEST;
 }
 
   END_TEST;
 }
 
@@ -709,7 +714,7 @@ int UtcDaliControlRendererGetPropertyMap9(void)
   propertyMap.Insert( "scaleDimensions", dimensions );
   propertyMap.Insert( "bevelPercentage", 0.3f );
   propertyMap.Insert( "bevelSmoothness", 0.6f );
   propertyMap.Insert( "scaleDimensions", dimensions );
   propertyMap.Insert( "bevelPercentage", 0.3f );
   propertyMap.Insert( "bevelSmoothness", 0.6f );
-  propertyMap.Insert( "uLightPosition", Vector3( 5.0f, 10.0f, 15.0f) );
+  propertyMap.Insert( "lightPosition", Vector3( 5.0f, 10.0f, 15.0f) );
   ControlRenderer primitiveRenderer = factory.CreateControlRenderer( propertyMap );
 
   Property::Map resultMap;
   ControlRenderer primitiveRenderer = factory.CreateControlRenderer( propertyMap );
 
   Property::Map resultMap;
@@ -765,7 +770,7 @@ int UtcDaliControlRendererGetPropertyMap9(void)
   DALI_TEST_CHECK( value );
   DALI_TEST_EQUALS( value->Get<float>(), 0.6f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
 
   DALI_TEST_CHECK( value );
   DALI_TEST_EQUALS( value->Get<float>(), 0.6f, Math::MACHINE_EPSILON_100, TEST_LOCATION );
 
-  value = resultMap.Find( "uLightPosition", Property::VECTOR3 );
+  value = resultMap.Find( "lightPosition", Property::VECTOR3 );
   DALI_TEST_CHECK( value );
   DALI_TEST_EQUALS( value->Get<Vector3>(), Vector3( 5.0f, 10.0f, 15.0f), Math::MACHINE_EPSILON_100, TEST_LOCATION );
 
   DALI_TEST_CHECK( value );
   DALI_TEST_EQUALS( value->Get<Vector3>(), Vector3( 5.0f, 10.0f, 15.0f), Math::MACHINE_EPSILON_100, TEST_LOCATION );
 
index 3ec4f95..2f331b1 100644 (file)
@@ -950,34 +950,31 @@ int UtcDaliRendererFactoryGetSvgRenderer(void)
   END_TEST;
 }
 
   END_TEST;
 }
 
-//Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
-int UtcDaliRendererFactoryGetMeshRenderer1(void)
+//Creates a mesh renderer from the given propertyMap and tries to load it on stage in the given application.
+//This is expected to succeed, which will then pass the test.
+void MeshRendererLoadsCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
 {
 {
-  ToolkitTestApplication application;
-  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer1:  Request mesh renderer with a valid object file only" );
-
   RendererFactory factory = RendererFactory::Get();
   DALI_TEST_CHECK( factory );
 
   RendererFactory factory = RendererFactory::Get();
   DALI_TEST_CHECK( factory );
 
-  //Set up renderer properties.
-  Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "MESH" );
-  propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
-
+  //Create a mesh renderer.
   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
   DALI_TEST_CHECK( controlRenderer );
 
   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
   DALI_TEST_CHECK( controlRenderer );
 
+  //Create an actor on stage to house the renderer.
   Actor actor = Actor::New();
   actor.SetSize( 200.f, 200.f );
   Stage::GetCurrent().Add( actor );
   controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
   controlRenderer.SetOnStage( actor );
 
   Actor actor = Actor::New();
   actor.SetSize( 200.f, 200.f );
   Stage::GetCurrent().Add( actor );
   controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
   controlRenderer.SetOnStage( actor );
 
+  //Ensure set on stage.
+  DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
+
+  //Attempt to render to queue resource load requests.
   application.SendNotification();
   application.Render( 0 );
 
   application.SendNotification();
   application.Render( 0 );
 
-  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
-
   //Tell the platform abstraction that the required resources have been loaded.
   TestPlatformAbstraction& platform = application.GetPlatform();
   platform.SetAllResourceRequestsAsLoaded();
   //Tell the platform abstraction that the required resources have been loaded.
   TestPlatformAbstraction& platform = application.GetPlatform();
   platform.SetAllResourceRequestsAsLoaded();
@@ -986,49 +983,39 @@ int UtcDaliRendererFactoryGetMeshRenderer1(void)
   application.SendNotification();
   application.Render( 0 );
 
   application.SendNotification();
   application.Render( 0 );
 
-  TestGlAbstraction& gl = application.GetGlAbstraction();
-
   Matrix testScaleMatrix;
   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
   Matrix actualScaleMatrix;
 
   //Test to see if the object has been successfully loaded.
   Matrix testScaleMatrix;
   testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
   Matrix actualScaleMatrix;
 
   //Test to see if the object has been successfully loaded.
-  DALI_TEST_CHECK( gl.GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
+  DALI_TEST_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
 
   DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
 
+  //Finish by setting off stage, and ensuring this was successful.
   controlRenderer.SetOffStage( actor );
   controlRenderer.SetOffStage( actor );
-  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
-
-  END_TEST;
+  DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
 }
 
 }
 
-//Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
-int UtcDaliRendererFactoryGetMeshRenderer2(void)
+//Creates a mesh renderer from the given propertyMap and tries to load it on stage in the given application.
+//This is expected to fail, which will then pass the test.
+void MeshRendererDoesNotLoadCorrectlyTest( Property::Map& propertyMap, ToolkitTestApplication& application )
 {
 {
-  ToolkitTestApplication application;
-  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer2:  Request mesh renderer with blank material file and images directory" );
-
   RendererFactory factory = RendererFactory::Get();
   DALI_TEST_CHECK( factory );
 
   RendererFactory factory = RendererFactory::Get();
   DALI_TEST_CHECK( factory );
 
-  //Set up renderer properties.
-  Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "MESH" );
-  propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
-  propertyMap.Insert( "materialUrl", "" );
-  propertyMap.Insert( "texturesPath", "" );
-
+  //Create a mesh renderer.
   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
   DALI_TEST_CHECK( controlRenderer );
 
   ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
   DALI_TEST_CHECK( controlRenderer );
 
-  //Add renderer to an actor on stage.
+  //Create an actor on stage to house the renderer.
   Actor actor = Actor::New();
   actor.SetSize( 200.f, 200.f );
   Stage::GetCurrent().Add( actor );
   controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
   controlRenderer.SetOnStage( actor );
 
   Actor actor = Actor::New();
   actor.SetSize( 200.f, 200.f );
   Stage::GetCurrent().Add( actor );
   controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
   controlRenderer.SetOnStage( actor );
 
-  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+  //Ensure set on stage.
+  DALI_TEST_EQUALS( actor.GetRendererCount(), 1u, TEST_LOCATION );
 
   //Attempt to render to queue resource load requests.
   application.SendNotification();
 
   //Attempt to render to queue resource load requests.
   application.SendNotification();
@@ -1042,74 +1029,72 @@ int UtcDaliRendererFactoryGetMeshRenderer2(void)
   application.SendNotification();
   application.Render( 0 );
 
   application.SendNotification();
   application.Render( 0 );
 
-  TestGlAbstraction& gl = application.GetGlAbstraction();
-
-  Matrix testScaleMatrix;
-  testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
-  Matrix actualScaleMatrix;
-
-  //Test to see if the object has been successfully loaded.
-  DALI_TEST_CHECK( gl.GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
-  DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
+  //Test to see if the object has not been loaded, as expected.
+  Matrix scaleMatrix;
+  DALI_TEST_CHECK( !application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
 
 
+  //Finish by setting off stage, and ensuring this was successful.
   controlRenderer.SetOffStage( actor );
   controlRenderer.SetOffStage( actor );
-  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
-
-  END_TEST;
+  DALI_TEST_EQUALS( actor.GetRendererCount(), 0u, TEST_LOCATION );
 }
 
 }
 
-//Test if mesh loads correctly when supplied with all parameters, an object file, a material file and a directory location.
-int UtcDaliRendererFactoryGetMeshRenderer3(void)
+//Test if mesh loads correctly when supplied with only the bare minimum requirements, an object file.
+int UtcDaliRendererFactoryGetMeshRenderer1(void)
 {
 {
+  //Set up test application first, so everything else can be handled.
   ToolkitTestApplication application;
   ToolkitTestApplication application;
-  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer3:  Request mesh renderer with all parameters correct" );
 
 
-  RendererFactory factory = RendererFactory::Get();
-  DALI_TEST_CHECK( factory );
+  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer1:  Request mesh renderer with a valid object file only" );
 
   //Set up renderer properties.
   Property::Map propertyMap;
   propertyMap.Insert( "rendererType",  "MESH" );
   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
 
   //Set up renderer properties.
   Property::Map propertyMap;
   propertyMap.Insert( "rendererType",  "MESH" );
   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
-  propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
-  propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
 
 
-  ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
-  DALI_TEST_CHECK( controlRenderer );
+  //Test to see if mesh loads correctly.
+  MeshRendererLoadsCorrectlyTest( propertyMap, application );
 
 
-  //Add renderer to an actor on stage.
-  Actor actor = Actor::New();
-  actor.SetSize( 200.f, 200.f );
-  Stage::GetCurrent().Add( actor );
-  controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
-  controlRenderer.SetOnStage( actor );
+  END_TEST;
+}
 
 
-  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+//Test if mesh loads correctly when supplied with an object file as well as a blank material file and images directory.
+int UtcDaliRendererFactoryGetMeshRenderer2(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
 
 
-  //Attempt to render to queue resource load requests.
-  application.SendNotification();
-  application.Render( 0 );
+  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer2:  Request mesh renderer with blank material file and images directory" );
 
 
-  //Tell the platform abstraction that the required resources have been loaded.
-  TestPlatformAbstraction& platform = application.GetPlatform();
-  platform.SetAllResourceRequestsAsLoaded();
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "MESH" );
+  propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
+  propertyMap.Insert( "materialUrl", "" );
+  propertyMap.Insert( "texturesPath", "" );
 
 
-  //Render again to upload the now-loaded textures.
-  application.SendNotification();
-  application.Render( 0 );
+  //Test to see if mesh loads correctly.
+  MeshRendererLoadsCorrectlyTest( propertyMap, application );
 
 
-  TestGlAbstraction& gl = application.GetGlAbstraction();
+  END_TEST;
+}
 
 
-  Matrix testScaleMatrix;
-  testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
-  Matrix actualScaleMatrix;
+//Test if mesh loads correctly when supplied with all main parameters, an object file, a material file and a directory location.
+int UtcDaliRendererFactoryGetMeshRenderer3(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
 
 
-  //Test to see if the object has been successfully loaded.
-  DALI_TEST_CHECK( gl.GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
-  DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
+  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer3:  Request mesh renderer with all parameters correct" );
 
 
-  controlRenderer.SetOffStage( actor );
-  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "MESH" );
+  propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
+  propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
+  propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
+
+  //Test to see if mesh loads correctly.
+  MeshRendererLoadsCorrectlyTest( propertyMap, application );
 
   END_TEST;
 }
 
   END_TEST;
 }
@@ -1117,112 +1102,107 @@ int UtcDaliRendererFactoryGetMeshRenderer3(void)
 //Test if mesh renderer can load a correctly supplied mesh without a normal map or gloss map in the material file.
 int UtcDaliRendererFactoryGetMeshRenderer4(void)
 {
 //Test if mesh renderer can load a correctly supplied mesh without a normal map or gloss map in the material file.
 int UtcDaliRendererFactoryGetMeshRenderer4(void)
 {
+  //Set up test application first, so everything else can be handled.
   ToolkitTestApplication application;
   ToolkitTestApplication application;
-  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer4:  Request mesh renderer with diffuse texture but not normal or gloss." );
 
 
-  RendererFactory factory = RendererFactory::Get();
-  DALI_TEST_CHECK( factory );
+  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer4:  Request mesh renderer with diffuse texture but not normal or gloss." );
 
   //Set up renderer properties.
   Property::Map propertyMap;
 
   //Set up renderer properties.
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "MESH" );
+  propertyMap.Insert( "rendererType", "MESH" );
   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
   propertyMap.Insert( "materialUrl", TEST_SIMPLE_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
 
   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
   propertyMap.Insert( "materialUrl", TEST_SIMPLE_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
 
-  ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
-  DALI_TEST_CHECK( controlRenderer );
-
-  //Add renderer to an actor on stage.
-  Actor actor = Actor::New();
-  actor.SetSize( 200.f, 200.f );
-  Stage::GetCurrent().Add( actor );
-  controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
-  controlRenderer.SetOnStage( actor );
-
-  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+  //Test to see if mesh loads correctly.
+  MeshRendererLoadsCorrectlyTest( propertyMap, application );
 
 
-  //Attempt to render to queue resource load requests.
-  application.SendNotification();
-  application.Render( 0 );
-
-  //Tell the platform abstraction that the required resources have been loaded.
-  TestPlatformAbstraction& platform = application.GetPlatform();
-  platform.SetAllResourceRequestsAsLoaded();
-
-  //Render again to upload the now-loaded textures.
-  application.SendNotification();
-  application.Render( 0 );
+  END_TEST;
+}
 
 
-  TestGlAbstraction& gl = application.GetGlAbstraction();
+//Test if mesh renderer can load when made to use diffuse textures only.
+int UtcDaliRendererFactoryGetMeshRenderer5(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
 
 
-  Matrix testScaleMatrix;
-  testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
-  Matrix actualScaleMatrix;
+  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer5:  Request mesh renderer and make it only use diffuse textures." );
 
 
-  //Test to see if the object has been successfully loaded.
-  DALI_TEST_CHECK( gl.GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
-  DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "MESH" );
+  propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
+  propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
+  propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
+  propertyMap.Insert( "shaderType", "DIFFUSE_TEXTURE" );
 
 
-  controlRenderer.SetOffStage( actor );
-  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+  //Test to see if mesh loads correctly.
+  MeshRendererLoadsCorrectlyTest( propertyMap, application );
 
   END_TEST;
 }
 
 
   END_TEST;
 }
 
-//Test if mesh renderer loads correctly when supplied an object file without face normals or texture points.
-//Note that this notably tests object loader functionality.
-int UtcDaliRendererFactoryGetMeshRenderer5(void)
+//Test if mesh renderer can load when made to not use the supplied textures.
+int UtcDaliRendererFactoryGetMeshRenderer6(void)
 {
 {
+  //Set up test application first, so everything else can be handled.
   ToolkitTestApplication application;
   ToolkitTestApplication application;
-  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer5:  Request mesh renderer with normal-less object file." );
 
 
-  RendererFactory factory = RendererFactory::Get();
-  DALI_TEST_CHECK( factory );
+  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer6:  Request mesh renderer and make it not use any textures." );
 
   //Set up renderer properties.
   Property::Map propertyMap;
   propertyMap.Insert( "rendererType", "MESH" );
 
   //Set up renderer properties.
   Property::Map propertyMap;
   propertyMap.Insert( "rendererType", "MESH" );
-  propertyMap.Insert( "objectUrl", TEST_SIMPLE_OBJ_FILE_NAME );
+  propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
+  propertyMap.Insert( "shaderType", "TEXTURELESS" );
 
 
-  ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
-  DALI_TEST_CHECK( controlRenderer );
+  //Test to see if mesh loads correctly.
+  MeshRendererLoadsCorrectlyTest( propertyMap, application );
 
 
-  //Add renderer to an actor on stage.
-  Actor actor = Actor::New();
-  actor.SetSize( 200.f, 200.f );
-  Stage::GetCurrent().Add( actor );
-  controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
-  controlRenderer.SetOnStage( actor );
+  END_TEST;
+}
+//Test if mesh renderer loads correctly when light position is manually set.
+int UtcDaliRendererFactoryGetMeshRenderer7(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
 
 
-  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
+  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer7:  Request mesh renderer with custom light position." );
 
 
-  //Attempt to render to queue resource load requests.
-  application.SendNotification();
-  application.Render( 0 );
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "MESH" );
+  propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
+  propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
+  propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
+  propertyMap.Insert( "lightPosition", Vector3( 0.0, 1.0, 2.0 ) );
 
 
-  //Tell the platform abstraction that the required resources have been loaded.
-  TestPlatformAbstraction& platform = application.GetPlatform();
-  platform.SetAllResourceRequestsAsLoaded();
+  //Test to see if mesh loads correctly.
+  MeshRendererLoadsCorrectlyTest( propertyMap, application );
 
 
-  //Render again to upload the now-loaded textures.
-  application.SendNotification();
-  application.Render( 0 );
+  END_TEST;
+}
 
 
-  TestGlAbstraction& gl = application.GetGlAbstraction();
+//Test if mesh renderer loads correctly when supplied an object file without face normals or texture points.
+//Note that this notably tests object loader functionality.
+int UtcDaliRendererFactoryGetMeshRenderer8(void)
+{
+  //Set up test application first, so everything else can be handled.
+  ToolkitTestApplication application;
 
 
-  Matrix testScaleMatrix;
-  testScaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
-  Matrix actualScaleMatrix;
+  tet_infoline( "UtcDaliRendererFactoryGetMeshRenderer5:  Request mesh renderer with normal-less object file." );
 
 
-  //Test to see if the object has been successfully loaded.
-  DALI_TEST_CHECK( gl.GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
-  DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
+  //Set up renderer properties.
+  Property::Map propertyMap;
+  propertyMap.Insert( "rendererType", "MESH" );
+  propertyMap.Insert( "objectUrl", TEST_SIMPLE_OBJ_FILE_NAME );
+  propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
+  propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
 
 
-  controlRenderer.SetOffStage( actor );
-  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+  //Test to see if mesh loads correctly.
+  MeshRendererLoadsCorrectlyTest( propertyMap, application );
 
   END_TEST;
 }
 
   END_TEST;
 }
@@ -1230,50 +1210,19 @@ int UtcDaliRendererFactoryGetMeshRenderer5(void)
 //Test if mesh renderer handles the case of lacking an object file.
 int UtcDaliRendererFactoryGetMeshRendererN1(void)
 {
 //Test if mesh renderer handles the case of lacking an object file.
 int UtcDaliRendererFactoryGetMeshRendererN1(void)
 {
+  //Set up test application first, so everything else can be handled.
   ToolkitTestApplication application;
   ToolkitTestApplication application;
-  tet_infoline( "UtcDaliRendererFactoryGetMeshRendererN1:  Request mesh renderer without object file" );
 
 
-  RendererFactory factory = RendererFactory::Get();
-  DALI_TEST_CHECK( factory );
+  tet_infoline( "UtcDaliRendererFactoryGetMeshRendererN1:  Request mesh renderer without object file" );
 
   //Set up renderer properties.
   Property::Map propertyMap;
 
   //Set up renderer properties.
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "MESH" );
+  propertyMap.Insert( "rendererType", "MESH" );
   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
 
   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
 
-  ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
-  DALI_TEST_CHECK( controlRenderer );
-
-  //Add renderer to an actor on stage.
-  Actor actor = Actor::New();
-  actor.SetSize( 200.f, 200.f );
-  Stage::GetCurrent().Add( actor );
-  controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
-  controlRenderer.SetOnStage( actor );
-
-  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
-
-  //Attempt to render to queue resource load requests.
-  application.SendNotification();
-  application.Render( 0 );
-
-  //Tell the platform abstraction that the required resources have been loaded.
-  TestPlatformAbstraction& platform = application.GetPlatform();
-  platform.SetAllResourceRequestsAsLoaded();
-
-  //Render again to upload the now-loaded textures.
-  application.SendNotification();
-  application.Render( 0 );
-
-  TestGlAbstraction& gl = application.GetGlAbstraction();
-
-  //Test to see if the object has not been loaded, as expected.
-  Matrix scaleMatrix;
-  DALI_TEST_CHECK( ! gl.GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
-
-  controlRenderer.SetOffStage( actor );
-  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+  //Test to see if mesh doesn't load with these properties, as expected.
+  MeshRendererDoesNotLoadCorrectlyTest( propertyMap, application );
 
   END_TEST;
 }
 
   END_TEST;
 }
@@ -1281,51 +1230,20 @@ int UtcDaliRendererFactoryGetMeshRendererN1(void)
 //Test if mesh renderer handles the case of being passed invalid material and images urls.
 int UtcDaliRendererFactoryGetMeshRendererN2(void)
 {
 //Test if mesh renderer handles the case of being passed invalid material and images urls.
 int UtcDaliRendererFactoryGetMeshRendererN2(void)
 {
+  //Set up test application first, so everything else can be handled.
   ToolkitTestApplication application;
   ToolkitTestApplication application;
-  tet_infoline( "UtcDaliRendererFactoryGetMeshRendererN2:  Request mesh renderer with invalid material and images urls" );
 
 
-  RendererFactory factory = RendererFactory::Get();
-  DALI_TEST_CHECK( factory );
+  tet_infoline( "UtcDaliRendererFactoryGetMeshRendererN2:  Request mesh renderer with invalid material and images urls" );
 
   //Set up renderer properties.
   Property::Map propertyMap;
 
   //Set up renderer properties.
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "MESH" );
+  propertyMap.Insert( "rendererType", "MESH" );
   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
   propertyMap.Insert( "materialUrl", "invalid" );
   propertyMap.Insert( "texturesPath", "also invalid" );
 
   propertyMap.Insert( "objectUrl", TEST_OBJ_FILE_NAME );
   propertyMap.Insert( "materialUrl", "invalid" );
   propertyMap.Insert( "texturesPath", "also invalid" );
 
-  ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
-  DALI_TEST_CHECK( controlRenderer );
-
-  //Add renderer to an actor on stage.
-  Actor actor = Actor::New();
-  actor.SetSize( 200.f, 200.f );
-  Stage::GetCurrent().Add( actor );
-  controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
-  controlRenderer.SetOnStage( actor );
-
-  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
-
-  //Attempt to render to queue resource load requests.
-  application.SendNotification();
-  application.Render( 0 );
-
-  //Tell the platform abstraction that the required resources have been loaded.
-  TestPlatformAbstraction& platform = application.GetPlatform();
-  platform.SetAllResourceRequestsAsLoaded();
-
-  //Render again to upload the now-loaded textures.
-  application.SendNotification();
-  application.Render( 0 );
-
-  TestGlAbstraction& gl = application.GetGlAbstraction();
-
-  //Test to see if the object has not been loaded, as expected.
-  Matrix scaleMatrix;
-  DALI_TEST_CHECK( ! gl.GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
-
-  controlRenderer.SetOffStage( actor );
-  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+  //Test to see if mesh doesn't load with these properties, as expected.
+  MeshRendererDoesNotLoadCorrectlyTest( propertyMap, application );
 
   END_TEST;
 }
 
   END_TEST;
 }
@@ -1333,51 +1251,20 @@ int UtcDaliRendererFactoryGetMeshRendererN2(void)
 //Test if mesh renderer handles the case of being passed an invalid object url
 int UtcDaliRendererFactoryGetMeshRendererN3(void)
 {
 //Test if mesh renderer handles the case of being passed an invalid object url
 int UtcDaliRendererFactoryGetMeshRendererN3(void)
 {
+  //Set up test application first, so everything else can be handled.
   ToolkitTestApplication application;
   ToolkitTestApplication application;
-  tet_infoline( "UtcDaliRendererFactoryGetMeshRendererN3:  Request mesh renderer with invalid object url" );
 
 
-  RendererFactory factory = RendererFactory::Get();
-  DALI_TEST_CHECK( factory );
+  tet_infoline( "UtcDaliRendererFactoryGetMeshRendererN3:  Request mesh renderer with invalid object url" );
 
   //Set up renderer properties.
   Property::Map propertyMap;
 
   //Set up renderer properties.
   Property::Map propertyMap;
-  propertyMap.Insert( "rendererType",  "MESH" );
+  propertyMap.Insert( "rendererType", "MESH" );
   propertyMap.Insert( "objectUrl", "invalid" );
   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
 
   propertyMap.Insert( "objectUrl", "invalid" );
   propertyMap.Insert( "materialUrl", TEST_MTL_FILE_NAME );
   propertyMap.Insert( "texturesPath", TEST_RESOURCE_DIR "/" );
 
-  ControlRenderer controlRenderer = factory.CreateControlRenderer( propertyMap );
-  DALI_TEST_CHECK( controlRenderer );
-
-  //Add renderer to an actor on stage.
-  Actor actor = Actor::New();
-  actor.SetSize( 200.f, 200.f );
-  Stage::GetCurrent().Add( actor );
-  controlRenderer.SetSize( Vector2( 200.f, 200.f ) );
-  controlRenderer.SetOnStage( actor );
-
-  DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
-
-  //Attempt to render to queue resource load requests.
-  application.SendNotification();
-  application.Render( 0 );
-
-  //Tell the platform abstraction that the required resources have been loaded.
-  TestPlatformAbstraction& platform = application.GetPlatform();
-  platform.SetAllResourceRequestsAsLoaded();
-
-  //Render again to upload the now-loaded textures.
-  application.SendNotification();
-  application.Render( 0 );
-
-  TestGlAbstraction& gl = application.GetGlAbstraction();
-
-  //Test to see if the object has not been loaded, as expected.
-  Matrix scaleMatrix;
-  DALI_TEST_CHECK( ! gl.GetUniformValue<Matrix>( "uObjectMatrix", scaleMatrix ) );
-
-  controlRenderer.SetOffStage( actor );
-  DALI_TEST_CHECK( actor.GetRendererCount() == 0u );
+  //Test to see if mesh doesn't load with these properties, as expected.
+  MeshRendererDoesNotLoadCorrectlyTest( propertyMap, application );
 
   END_TEST;
 }
 
   END_TEST;
 }
@@ -1458,6 +1345,8 @@ int UtcDaliRendererFactoryGetPrimitiveRenderer2(void)
   propertyMap.Insert( "scaleHeight", 50.0f );
   propertyMap.Insert( "scaleRadius", 60.0f );
   propertyMap.Insert( "bevelPercentage", 0.7f );
   propertyMap.Insert( "scaleHeight", 50.0f );
   propertyMap.Insert( "scaleRadius", 60.0f );
   propertyMap.Insert( "bevelPercentage", 0.7f );
+  propertyMap.Insert( "bevelSmoothness", 0.8f );
+  propertyMap.Insert( "lightPosition", Vector3( 0.9, 1.0, 1.1 ) );
 
   //Test to see if shape loads correctly.
   TestPrimitiveRendererWithProperties( propertyMap, application );
 
   //Test to see if shape loads correctly.
   TestPrimitiveRendererWithProperties( propertyMap, application );
@@ -1588,7 +1477,7 @@ int UtcDaliRendererFactoryGetPrimitiveRenderer8(void)
   propertyMap.Insert( "rendererType", "PRIMITIVE" );
   propertyMap.Insert( "shape", "SPHERE" );
   propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
   propertyMap.Insert( "rendererType", "PRIMITIVE" );
   propertyMap.Insert( "shape", "SPHERE" );
   propertyMap.Insert( "shapeColor", Vector4( 0.5, 0.5, 0.5, 1.0 ) );
-  propertyMap.Insert( "uLightPosition", Vector3( 0.0, 1.0, 2.0 ) );
+  propertyMap.Insert( "lightPosition", Vector3( 0.0, 1.0, 2.0 ) );
 
   //Test to see if shape loads correctly.
   TestPrimitiveRendererWithProperties( propertyMap, application );
 
   //Test to see if shape loads correctly.
   TestPrimitiveRendererWithProperties( propertyMap, application );
index 350b8a1..c2316af 100644 (file)
@@ -20,7 +20,6 @@
 
 // EXTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
 
 // EXTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
-#include <dali/public-api/images/resource-image.h>
 #include <dali/public-api/common/stage.h>
 #include <dali/devel-api/adaptor-framework/bitmap-loader.h>
 #include <dali/devel-api/adaptor-framework/file-loader.h>
 #include <dali/public-api/common/stage.h>
 #include <dali/devel-api/adaptor-framework/bitmap-loader.h>
 #include <dali/devel-api/adaptor-framework/file-loader.h>
@@ -81,8 +80,9 @@ enum TextureIndex
   GLOSS_INDEX = 2u
 };
 
   GLOSS_INDEX = 2u
 };
 
-const char * const LIGHT_POSITION( "uLightPosition" ); //Shader property
-const char * const OBJECT_MATRIX( "uObjectMatrix" ); //Shader property
+//Shader properties
+const char * const OBJECT_MATRIX_UNIFORM_NAME( "uObjectMatrix" );
+const char * const STAGE_OFFSET_UNIFORM_NAME( "uStageOffset" );
 
 const char * const SHADER_TYPE_TEXTURELESS( "TEXTURELESS" );
 const char * const SHADER_TYPE_DIFFUSE_TEXTURE( "DIFFUSE_TEXTURE" );
 
 const char * const SHADER_TYPE_TEXTURELESS( "TEXTURELESS" );
 const char * const SHADER_TYPE_DIFFUSE_TEXTURE( "DIFFUSE_TEXTURE" );
@@ -100,24 +100,27 @@ const char* SIMPLE_VERTEX_SHADER = DALI_COMPOSE_SHADER(
   uniform mediump vec3 uSize;\n
   uniform mediump mat4 uMvpMatrix;\n
   uniform mediump mat4 uModelView;\n
   uniform mediump vec3 uSize;\n
   uniform mediump mat4 uMvpMatrix;\n
   uniform mediump mat4 uModelView;\n
+  uniform mediump mat4 uViewMatrix;\n
   uniform mediump mat3 uNormalMatrix;
   uniform mediump mat4 uObjectMatrix;\n
   uniform mediump mat3 uNormalMatrix;
   uniform mediump mat4 uObjectMatrix;\n
-  uniform mediump vec3 uLightPosition;\n
+  uniform mediump vec3 lightPosition;\n
+  uniform mediump vec2 uStageOffset;\n
 
   void main()\n
   {\n
 
   void main()\n
   {\n
-    vec4 vertexPosition = vec4( aPosition * min( uSize.x, uSize.y ), 1.0 );\n
-    vertexPosition = uObjectMatrix * vertexPosition;\n
+    vec4 normalisedVertexPosition = vec4( aPosition * min( uSize.x, uSize.y ), 1.0 );\n
+    vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n
     vertexPosition = uMvpMatrix * vertexPosition;\n
 
     //Illumination in Model-View space - Transform attributes and uniforms\n
     vertexPosition = uMvpMatrix * vertexPosition;\n
 
     //Illumination in Model-View space - Transform attributes and uniforms\n
-    vec4 vertPos = uModelView * vec4( aPosition.xyz, 1.0 );\n
+    vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
     vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;\n
     vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;\n
-    vec4 center = uModelView * vec4( 0.0, 0.0, 0.0, 1.0 );\n
-    vec4 lightPos = vec4( center.x, center.y, uLightPosition.z, 1.0 );\n
-    vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );\n
 
 
-    float lightDiffuse = max( dot( vecToLight, normal ), 0.0 );\n
+    vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n
+    mvLightPosition = uViewMatrix * mvLightPosition;\n
+    vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n
+
+    float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );\n
     vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n
 
     gl_Position = vertexPosition;\n
     vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n
 
     gl_Position = vertexPosition;\n
@@ -147,33 +150,34 @@ const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
   uniform mediump vec3 uSize;\n
   uniform mediump mat4 uMvpMatrix;\n
   uniform mediump mat4 uModelView;
   uniform mediump vec3 uSize;\n
   uniform mediump mat4 uMvpMatrix;\n
   uniform mediump mat4 uModelView;
+  uniform mediump mat4 uViewMatrix;\n
   uniform mediump mat3 uNormalMatrix;
   uniform mediump mat4 uObjectMatrix;\n
   uniform mediump mat3 uNormalMatrix;
   uniform mediump mat4 uObjectMatrix;\n
-  uniform mediump vec3 uLightPosition;\n
+  uniform mediump vec3 lightPosition;\n
+  uniform mediump vec2 uStageOffset;\n
 
   void main()
   {\n
 
   void main()
   {\n
-    vec4 vertexPosition = vec4( aPosition * min( uSize.x, uSize.y ), 1.0 );\n
-    vertexPosition = uObjectMatrix * vertexPosition;\n
+    vec4 normalisedVertexPosition = vec4( aPosition * min( uSize.x, uSize.y ), 1.0 );\n
+    vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n
     vertexPosition = uMvpMatrix * vertexPosition;\n
 
     //Illumination in Model-View space - Transform attributes and uniforms\n
     vertexPosition = uMvpMatrix * vertexPosition;\n
 
     //Illumination in Model-View space - Transform attributes and uniforms\n
-    vec4 vertPos = uModelView * vec4( aPosition.xyz, 1.0 );\n
-    vec4 center = uModelView * vec4( 0.0, 0.0, 0.0, 1.0 );\n
-    vec4 lightPos = vec4( center.x, center.y, uLightPosition.z, 1.0 );\n
+    vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
     vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );\n
 
     vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );\n
 
-    vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );\n
-    vec3 viewDir = normalize( -vertPos.xyz );
+    vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n
+    mvLightPosition = uViewMatrix * mvLightPosition;\n
+    vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n
 
 
-    vec3 halfVector = normalize( viewDir + vecToLight );
+    vec3 viewDirection = normalize( -mvVertexPosition.xyz );
 
 
-    float lightDiffuse = dot( vecToLight, normal );\n
+    float lightDiffuse = dot( vectorToLight, normal );\n
     lightDiffuse = max( 0.0,lightDiffuse );\n
     vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n
 
     lightDiffuse = max( 0.0,lightDiffuse );\n
     vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n
 
-    vec3 reflectDir = reflect( -vecToLight, normal );
-    vSpecular = pow( max( dot( reflectDir, viewDir ), 0.0 ), 4.0 );
+    vec3 reflectDirection = reflect( -vectorToLight, normal );
+    vSpecular = pow( max( dot( reflectDirection, viewDirection ), 0.0 ), 4.0 );
 
     vTexCoord = aTexCoord;\n
     gl_Position = vertexPosition;\n
 
     vTexCoord = aTexCoord;\n
     gl_Position = vertexPosition;\n
@@ -210,31 +214,32 @@ const char* NORMAL_MAP_VERTEX_SHADER = DALI_COMPOSE_SHADER(
   uniform mediump vec3 uSize;\n
   uniform mediump mat4 uMvpMatrix;\n
   uniform mediump mat4 uModelView;
   uniform mediump vec3 uSize;\n
   uniform mediump mat4 uMvpMatrix;\n
   uniform mediump mat4 uModelView;
+  uniform mediump mat4 uViewMatrix;\n
   uniform mediump mat3 uNormalMatrix;
   uniform mediump mat4 uObjectMatrix;\n
   uniform mediump mat3 uNormalMatrix;
   uniform mediump mat4 uObjectMatrix;\n
-  uniform mediump vec3 uLightPosition;\n
-
+  uniform mediump vec3 lightPosition;\n
+  uniform mediump vec2 uStageOffset;\n
   void main()
   {\n
   void main()
   {\n
-    vec4 vertexPosition = vec4( aPosition * min( uSize.x, uSize.y ), 1.0 );\n
-    vertexPosition = uObjectMatrix * vertexPosition;\n
+    vec4 normalisedVertexPosition = vec4( aPosition * min( uSize.x, uSize.y ), 1.0 );\n
+    vec4 vertexPosition = uObjectMatrix * normalisedVertexPosition;\n
     vertexPosition = uMvpMatrix * vertexPosition;\n
 
     vertexPosition = uMvpMatrix * vertexPosition;\n
 
-    vec4 vertPos = uModelView * vec4( aPosition.xyz, 1.0 );\n
-    vec4 center = uModelView * vec4( 0.0, 0.0, 0.0, 1.0 );\n
-    vec4 lightPos = vec4( center.x, center.y, uLightPosition.z, 1.0 );\n
+    vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
 
 
-    vec3 tangent = normalize( uNormalMatrix * aTangent );
-    vec3 binormal = normalize( uNormalMatrix * aBiNormal );
+    vec3 tangent = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aTangent );
+    vec3 binormal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aBiNormal );
     vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );
 
     vec3 normal = normalize( uNormalMatrix * mat3( uObjectMatrix ) * aNormal );
 
-    vec3 vecToLight = normalize( lightPos.xyz - vertPos.xyz );\n
-    vLightDirection.x = dot( vecToLight, tangent );
-    vLightDirection.y = dot( vecToLight, binormal );
-    vLightDirection.z = dot( vecToLight, normal );
+    vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n
+    mvLightPosition = uViewMatrix * mvLightPosition;\n
+    vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n
+    vLightDirection.x = dot( vectorToLight, tangent );
+    vLightDirection.y = dot( vectorToLight, binormal );
+    vLightDirection.z = dot( vectorToLight, normal );
 
 
-    vec3 viewDir = normalize( -vertPos.xyz );
-    vec3 halfVector = normalize( viewDir + vecToLight );
+    vec3 viewDirection = normalize( -mvVertexPosition.xyz );
+    vec3 halfVector = normalize( viewDirection + vectorToLight );
     vHalfVector.x = dot( halfVector, tangent );
     vHalfVector.y = dot( halfVector, binormal );
     vHalfVector.z = dot( halfVector, normal );
     vHalfVector.x = dot( halfVector, tangent );
     vHalfVector.y = dot( halfVector, binormal );
     vHalfVector.z = dot( halfVector, normal );
@@ -294,7 +299,6 @@ void MeshRenderer::DoInitialize( Actor& actor, const Property::Map& propertyMap
   }
 
   Property::Value* materialUrl = propertyMap.Find( MATERIAL_URL );
   }
 
   Property::Value* materialUrl = propertyMap.Find( MATERIAL_URL );
-
   if( !materialUrl || !materialUrl->Get( mMaterialUrl ) || mMaterialUrl.empty() )
   {
     mUseTexture = false;
   if( !materialUrl || !materialUrl->Get( mMaterialUrl ) || mMaterialUrl.empty() )
   {
     mUseTexture = false;
@@ -308,12 +312,6 @@ void MeshRenderer::DoInitialize( Actor& actor, const Property::Map& propertyMap
     mTexturesPath.clear();
   }
 
     mTexturesPath.clear();
   }
 
-  Property::Value* useMipmapping = propertyMap.Find( USE_MIPMAPPING );
-  if( useMipmapping )
-  {
-    useMipmapping->Get( mUseMipmapping );
-  }
-
   Property::Value* shaderType = propertyMap.Find( SHADER_TYPE );
   if( shaderType )
   {
   Property::Value* shaderType = propertyMap.Find( SHADER_TYPE );
   if( shaderType )
   {
@@ -339,11 +337,35 @@ void MeshRenderer::DoInitialize( Actor& actor, const Property::Map& propertyMap
     }
   }
 
     }
   }
 
+  Property::Value* useMipmapping = propertyMap.Find( USE_MIPMAPPING );
+  if( useMipmapping )
+  {
+    useMipmapping->Get( mUseMipmapping );
+  }
+
   Property::Value* useSoftNormals = propertyMap.Find( USE_SOFT_NORMALS );
   if( useSoftNormals )
   {
     useSoftNormals->Get( mUseSoftNormals );
   }
   Property::Value* useSoftNormals = propertyMap.Find( USE_SOFT_NORMALS );
   if( useSoftNormals )
   {
     useSoftNormals->Get( mUseSoftNormals );
   }
+
+  Property::Value* lightPosition = propertyMap.Find( LIGHT_POSITION_UNIFORM_NAME );
+  if( lightPosition )
+  {
+    if( !lightPosition->Get( mLightPosition ) )
+    {
+      DALI_LOG_ERROR( "Invalid value passed for light position in MeshRenderer object.\n" );
+      mLightPosition = Vector3::ZERO;
+    }
+  }
+  else
+  {
+    //Default behaviour is to place the light directly in front of the object,
+    // at a reasonable distance to light everything on screen.
+    Stage stage = Stage::GetCurrent();
+
+    mLightPosition = Vector3( stage.GetSize().width / 2, stage.GetSize().height / 2, stage.GetSize().width * 5 );
+  }
 }
 
 void MeshRenderer::SetSize( const Vector2& size )
 }
 
 void MeshRenderer::SetSize( const Vector2& size )
@@ -403,6 +425,7 @@ void MeshRenderer::DoCreatePropertyMap( Property::Map& map ) const
 
   map.Insert( USE_MIPMAPPING, mUseMipmapping );
   map.Insert( USE_SOFT_NORMALS, mUseSoftNormals );
 
   map.Insert( USE_MIPMAPPING, mUseMipmapping );
   map.Insert( USE_SOFT_NORMALS, mUseSoftNormals );
+  map.Insert( LIGHT_POSITION_UNIFORM_NAME, mLightPosition );
 }
 
 void MeshRenderer::InitializeRenderer()
 }
 
 void MeshRenderer::InitializeRenderer()
@@ -457,13 +480,15 @@ void MeshRenderer::SupplyEmptyGeometry()
 void MeshRenderer::UpdateShaderUniforms()
 {
   Stage stage = Stage::GetCurrent();
 void MeshRenderer::UpdateShaderUniforms()
 {
   Stage stage = Stage::GetCurrent();
-
-  Vector3 lightPosition( 0, 0, stage.GetSize().width );
-  mShader.RegisterProperty( LIGHT_POSITION, lightPosition );
+  float width = stage.GetSize().width;
+  float height = stage.GetSize().height;
 
   Matrix scaleMatrix;
   scaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
 
   Matrix scaleMatrix;
   scaleMatrix.SetIdentityAndScale( Vector3( 1.0, -1.0, 1.0 ) );
-  mShader.RegisterProperty( OBJECT_MATRIX, scaleMatrix );
+
+  mShader.RegisterProperty( STAGE_OFFSET_UNIFORM_NAME, Vector2( width, height ) / 2.0f );
+  mShader.RegisterProperty( LIGHT_POSITION_UNIFORM_NAME, mLightPosition );
+  mShader.RegisterProperty( OBJECT_MATRIX_UNIFORM_NAME, scaleMatrix );
 }
 
 void MeshRenderer::CreateShader()
 }
 
 void MeshRenderer::CreateShader()
index ea324fc..2407a09 100644 (file)
@@ -48,6 +48,7 @@ namespace Internal
  * | shaderType      | STRING      | An enum of shader types                                               |
  * | useMipmapping   | BOOLEAN     | If true, use mipmaps for textures. Default true.                      |
  * | useSoftNormals  | BOOLEAN     | If true, average normals at points for smooth textures. Default true. |
  * | shaderType      | STRING      | An enum of shader types                                               |
  * | useMipmapping   | BOOLEAN     | If true, use mipmaps for textures. Default true.                      |
  * | useSoftNormals  | BOOLEAN     | If true, average normals at points for smooth textures. Default true. |
+ * | lightPosition   | VECTOR3     | The position (on stage) of the light                                  |
  */
 class MeshRenderer: public ControlRenderer
 {
  */
 class MeshRenderer: public ControlRenderer
 {
@@ -193,6 +194,8 @@ private:
   ObjLoader mObjLoader;
   Vector3 mSceneCenter;
   Vector3 mSceneSize;
   ObjLoader mObjLoader;
   Vector3 mSceneCenter;
   Vector3 mSceneSize;
+
+  Vector3 mLightPosition;
   ShaderType mShaderType;
 
   bool mUseTexture;
   ShaderType mShaderType;
 
   bool mUseTexture;
index 8f30a74..33aa60c 100644 (file)
@@ -94,7 +94,7 @@ const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
   uniform   mediump mat4 uViewMatrix;\n
   uniform   mediump mat3 uNormalMatrix;\n
   uniform   mediump mat4 uObjectMatrix;\n
   uniform   mediump mat4 uViewMatrix;\n
   uniform   mediump mat3 uNormalMatrix;\n
   uniform   mediump mat4 uObjectMatrix;\n
-  uniform   mediump vec3 uLightPosition;\n
+  uniform   mediump vec3 lightPosition;\n
   uniform   mediump vec2 uStageOffset;\n
 
   void main()\n
   uniform   mediump vec2 uStageOffset;\n
 
   void main()\n
@@ -111,9 +111,9 @@ const char* VERTEX_SHADER = DALI_COMPOSE_SHADER(
     vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
     vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;\n
 
     vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\n
     vec3 normal = uNormalMatrix * mat3( uObjectMatrix ) * aNormal;\n
 
-    vec4 lightPosition = vec4( ( uLightPosition.xy - uStageOffset ), uLightPosition.z, 1.0 );\n
-    lightPosition = uViewMatrix * lightPosition;\n
-    vec3 vectorToLight = normalize( lightPosition.xyz - mvVertexPosition.xyz );\n
+    vec4 mvLightPosition = vec4( ( lightPosition.xy - uStageOffset ), lightPosition.z, 1.0 );\n
+    mvLightPosition = uViewMatrix * mvLightPosition;\n
+    vec3 vectorToLight = normalize( mvLightPosition.xyz - mvVertexPosition.xyz );\n
 
     float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );\n
     vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n
 
     float lightDiffuse = max( dot( vectorToLight, normal ), 0.0 );\n
     vIllumination = vec3( lightDiffuse * 0.5 + 0.5 );\n
index 9e92945..555f478 100644 (file)
@@ -87,7 +87,7 @@ namespace Internal
  *
  * | %Property Name  | Type        | Representing                            |
  * |-----------------|-------------|-----------------------------------------|
  *
  * | %Property Name  | Type        | Representing                            |
  * |-----------------|-------------|-----------------------------------------|
- * | uLightPosition  | VECTOR3     | The position (on stage) of the light    |
+ * | lightPosition   | VECTOR3     | The position (on stage) of the light    |
  */
 class PrimitiveRenderer: public ControlRenderer
 {
  */
 class PrimitiveRenderer: public ControlRenderer
 {
index 319b596..a37d413 100644 (file)
@@ -38,7 +38,7 @@ const char * const DEBUG_RENDERER("DEBUG");
 
 const char * const IMAGE_URL_NAME("url");
 const char * const ATLAS_RECT_UNIFORM_NAME ( "uAtlasRect" );
 
 const char * const IMAGE_URL_NAME("url");
 const char * const ATLAS_RECT_UNIFORM_NAME ( "uAtlasRect" );
-const char * const LIGHT_POSITION_UNIFORM_NAME( "uLightPosition" );
+const char * const LIGHT_POSITION_UNIFORM_NAME( "lightPosition" );
 
 //Mesh properties
 const char * const OBJECT_URL( "objectUrl" );
 
 //Mesh properties
 const char * const OBJECT_URL( "objectUrl" );
index 1e79656..fd60f06 100644 (file)
@@ -446,6 +446,7 @@ Renders a mesh using a .obj file, optionally with textures provided by a mtl fil
 | [shaderType](@ref mesh-renderer-shader-type) | STRING  | No                 | Sets the type of shader to be used with the mesh.                                          |
 | useMipmapping                                | BOOLEAN | No                 | Flag for whether to use mipmaps for textures or not. Default true.                         |
 | useSoftNormals                               | BOOLEAN | No                 | Flag for whether to average normals at each point to smooth textures or not. Default true. |
 | [shaderType](@ref mesh-renderer-shader-type) | STRING  | No                 | Sets the type of shader to be used with the mesh.                                          |
 | useMipmapping                                | BOOLEAN | No                 | Flag for whether to use mipmaps for textures or not. Default true.                         |
 | useSoftNormals                               | BOOLEAN | No                 | Flag for whether to average normals at each point to smooth textures or not. Default true. |
+| lightPosition                                | VECTOR3 | No                 | The position, in stage space, of the point light that applies lighting to the model. This is based off the stage's dimensions, so using the width and height of the stage halved will correspond to the center, and using all zeroes will place the light at the upper left corner. Note that this corresponds to a shader property, so it can be registered and set in the actor as well. |
 
 ### Shader Type {#mesh-renderer-shader-type}
 
 
 ### Shader Type {#mesh-renderer-shader-type}
 
@@ -463,14 +464,15 @@ When specifying the shader type, if anything the shader requires is missing, a s
 
 ~~~{.cpp}
 // C++
 
 ~~~{.cpp}
 // C++
+Dali::Stage stage = Dali::Stage::GetCurrent();
 Dali::Toolkit::Control control = Dali::Toolkit::Control::New();
 
 Dali::Property::Map map;
 
 Dali::Toolkit::Control control = Dali::Toolkit::Control::New();
 
 Dali::Property::Map map;
 
-map[ "rendererType" ] = "MESH";
-map[ "objectUrl"    ] = "home/models/Dino.obj";
-map[ "materialUrl"  ] = "home/models/Dino.mtl";
-map[ "texturesPath" ] = "home/images/";
+map[ "rendererType"  ] = "MESH";
+map[ "objectUrl"     ] = "home/models/Dino.obj";
+map[ "materialUrl"   ] = "home/models/Dino.mtl";
+map[ "texturesPath"  ] = "home/images/";
 
 control.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map );
 ~~~
 
 control.SetProperty( Dali::Toolkit::Control::Property::BACKGROUND, map );
 ~~~
@@ -501,7 +503,7 @@ Renders a simple 3D shape, such as a cube or sphere. Scaled to fit the control.
 | scaleDimensions                       | VECTOR3 | The dimensions of a cuboid. Scales in the same fashion as a 9-patch image.      | (1.0, 1.0, 1.0)      | > 0.0 for each                 |
 | [bevelPercentage](@ref bevel-details) | FLOAT   | Determines how bevelled the cuboid should be, based off the smallest dimension. | 0.0 (no bevel)       | 0.0 - 1.0                      |
 | bevelSmoothness                       | FLOAT   | Defines how smooth the bevelled edges should be.                                | 0.0 (sharp edges)    | 0.0 - 1.0                      |
 | scaleDimensions                       | VECTOR3 | The dimensions of a cuboid. Scales in the same fashion as a 9-patch image.      | (1.0, 1.0, 1.0)      | > 0.0 for each                 |
 | [bevelPercentage](@ref bevel-details) | FLOAT   | Determines how bevelled the cuboid should be, based off the smallest dimension. | 0.0 (no bevel)       | 0.0 - 1.0                      |
 | bevelSmoothness                       | FLOAT   | Defines how smooth the bevelled edges should be.                                | 0.0 (sharp edges)    | 0.0 - 1.0                      |
-| uLightPosition                        | VECTOR3 | The position, in stage space, of the point light that applies lighting to the model. This is based off the stage's dimensions, so using the width and height of the stage halved will correspond to the center, and using all zeroes will place the light at the upper left back corner. Note that this corresponds to a shader property, so it can be registered and set in the actor as well. | (Offset outwards from the center of the screen.) | Unlimited |
+| lightPosition                        | VECTOR3 | The position, in stage space, of the point light that applies lighting to the model. This is based off the stage's dimensions, so using the width and height of the stage halved will correspond to the center, and using all zeroes will place the light at the upper left back corner. Note that this corresponds to a shader property, so it can be registered and set in the actor as well. | (Offset outwards from the center of the screen.) | Unlimited |
 
 ### Shapes {#shape-details}
 
 
 ### Shapes {#shape-details}