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 );
- //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 );
+ //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 );
+ //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 );
- DALI_TEST_CHECK( actor.GetRendererCount() == 1u );
-
//Tell the platform abstraction that the required resources have been loaded.
TestPlatformAbstraction& platform = application.GetPlatform();
platform.SetAllResourceRequestsAsLoaded();
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_CHECK( application.GetGlAbstraction().GetUniformValue<Matrix>( "uObjectMatrix", actualScaleMatrix ) );
DALI_TEST_EQUALS( actualScaleMatrix, testScaleMatrix, Math::MACHINE_EPSILON_100, TEST_LOCATION );
+ //Finish by setting off stage, and ensuring this was successful.
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 );
- //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 );
- //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 );
- 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();
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 );
- 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;
- 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 );
- 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;
}
//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;
- 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;
- 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 "/" );
- 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;
}
-//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;
- 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" );
- 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( "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;
}
//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;
- 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;
- propertyMap.Insert( "rendererType", "MESH" );
+ propertyMap.Insert( "rendererType", "MESH" );
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;
}
//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;
- 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;
- propertyMap.Insert( "rendererType", "MESH" );
+ propertyMap.Insert( "rendererType", "MESH" );
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;
}
//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;
- 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;
- 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 "/" );
- 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;
}
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 );
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 );
// 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>
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" );
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 vec3 uLightPosition;\n
+ uniform mediump vec3 lightPosition;\n
+ uniform mediump vec2 uStageOffset;\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
- vec4 vertPos = uModelView * vec4( aPosition.xyz, 1.0 );\n
+ vec4 mvVertexPosition = uModelView * normalisedVertexPosition;\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
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 vec3 uLightPosition;\n
+ uniform mediump vec3 lightPosition;\n
+ uniform mediump vec2 uStageOffset;\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
- 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 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
- 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
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 vec3 uLightPosition;\n
-
+ uniform mediump vec3 lightPosition;\n
+ uniform mediump vec2 uStageOffset;\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
- 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 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 );
}
Property::Value* materialUrl = propertyMap.Find( MATERIAL_URL );
-
if( !materialUrl || !materialUrl->Get( mMaterialUrl ) || mMaterialUrl.empty() )
{
mUseTexture = false;
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* 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* 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 )
map.Insert( USE_MIPMAPPING, mUseMipmapping );
map.Insert( USE_SOFT_NORMALS, mUseSoftNormals );
+ map.Insert( LIGHT_POSITION_UNIFORM_NAME, mLightPosition );
}
void MeshRenderer::InitializeRenderer()
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 ) );
- 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()