Changed view frustum culling to ignore mesh extents and instead use actor extents. 91/44291/4
authorChu Hoang <c.hoang@samsung.com>
Mon, 20 Jul 2015 15:55:39 +0000 (16:55 +0100)
committerChu Hoang <c.hoang@samsung.com>
Tue, 21 Jul 2015 12:32:22 +0000 (13:32 +0100)
Removed Geometry::mHalfExtents and mRadius since they are no longer relevant.

Change-Id: I3d262e157bc30f7d999c0f73ba23469f7eac37a6

automated-tests/src/dali-internal/utc-Dali-Internal-FrustumCulling.cpp
dali/devel-api/rendering/geometry.h
dali/internal/event/rendering/geometry-impl.cpp
dali/internal/update/manager/prepare-render-instructions.cpp
dali/internal/update/rendering/scene-graph-geometry.cpp
dali/internal/update/rendering/scene-graph-geometry.h

index 5a65c6d95794eb38e2aaac486f72c7d4441e4ea0..e3053e1f6fef8debcc2197f9a00196b8e1cb48f7 100644 (file)
@@ -106,7 +106,7 @@ int UtcFrustumCullN(void)
 
   Actor meshActor = Actor::New();
   meshActor.AddRenderer( renderer );
-  meshActor.SetSize(400, 400);
+  meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
   drawTrace.Reset();
 
   meshActor.SetParentOrigin( ParentOrigin::CENTER );
@@ -137,11 +137,13 @@ int UtcFrustumLeftCullP(void)
 
   Actor meshActor = Actor::New();
   meshActor.AddRenderer( renderer );
-  meshActor.SetSize(400, 400);
+  meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
   drawTrace.Reset();
 
-  meshActor.SetParentOrigin( Vector3( -0.42f, 0.5f, 0.5f ) );
-  meshActor.SetAnchorPoint( AnchorPoint::CENTER );
+  float offset = -0.01f;
+
+  meshActor.SetParentOrigin( Vector3( offset, 0.5f, 0.5f ) );
+  meshActor.SetAnchorPoint( AnchorPoint::CENTER_RIGHT );
   Stage::GetCurrent().Add( meshActor );
 
   application.SendNotification();
@@ -150,13 +152,18 @@ int UtcFrustumLeftCullP(void)
   // This will be box culled
   DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
 
+  float radius = meshActor.GetTargetSize().Length() * 0.5f;
+  Vector2 stageSize = Stage::GetCurrent().GetSize();
+
   drawTrace.Reset();
-  meshActor.SetParentOrigin( Vector3( -0.5f, 0.5f, 0.5f ) );
+  meshActor.SetParentOrigin( Vector3( -radius/stageSize.width + offset, 0.5f, 0.5f ) );
+  meshActor.SetAnchorPoint( AnchorPoint::CENTER );
   application.SendNotification();
   application.Render(16);
 
   // This will be sphere culled
   DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
+
   END_TEST;
 }
 
@@ -178,26 +185,33 @@ int UtcFrustumRightCullP(void)
 
   Actor meshActor = Actor::New();
   meshActor.AddRenderer( renderer );
-  meshActor.SetSize(400, 400);
+  meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
   drawTrace.Reset();
 
-  meshActor.SetParentOrigin( Vector3( 1.42f, 0.5f, 0.5f ) );
-  meshActor.SetAnchorPoint( AnchorPoint::CENTER );
+  float offset = 1.01f;
+
+  meshActor.SetParentOrigin( Vector3( offset, 0.5f, 0.5f ) );
+  meshActor.SetAnchorPoint( AnchorPoint::CENTER_LEFT );
   Stage::GetCurrent().Add( meshActor );
 
   application.SendNotification();
   application.Render(16);
 
-  // This should be box culled
+  // This will be box culled
   DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
 
+  float radius = meshActor.GetTargetSize().Length() * 0.5f;
+  Vector2 stageSize = Stage::GetCurrent().GetSize();
+
   drawTrace.Reset();
-  meshActor.SetParentOrigin( Vector3( 1.5f, 0.0f, 0.5f ) );
+  meshActor.SetParentOrigin( Vector3( radius/stageSize.width + offset, 0.5f, 0.5f ) );
+  meshActor.SetAnchorPoint( AnchorPoint::CENTER );
   application.SendNotification();
   application.Render(16);
 
-  // This should be sphere culled
+  // This will be sphere culled
   DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
+
   END_TEST;
 }
 
@@ -219,26 +233,33 @@ int UtcFrustumTopCullP(void)
 
   Actor meshActor = Actor::New();
   meshActor.AddRenderer( renderer );
-  meshActor.SetSize(400, 400);
+  meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
   drawTrace.Reset();
 
-  meshActor.SetParentOrigin( Vector3( 0.5f, -0.32f, 0.5f ) );
-  meshActor.SetAnchorPoint( AnchorPoint::CENTER );
+  float offset = -0.01f;
+
+  meshActor.SetParentOrigin( Vector3( 0.5f, offset, 0.5f ) );
+  meshActor.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
   Stage::GetCurrent().Add( meshActor );
 
   application.SendNotification();
   application.Render(16);
 
-  // This should be box culled
+  // This will be box culled
   DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
 
+  float radius = meshActor.GetTargetSize().Length() * 0.5f;
+  Vector2 stageSize = Stage::GetCurrent().GetSize();
+
   drawTrace.Reset();
-  meshActor.SetParentOrigin( Vector3( 0.5f, -0.5f, 0.5f ) );
+  meshActor.SetParentOrigin( Vector3( 0.5f, -radius/stageSize.width + offset, 0.5f ) );
+  meshActor.SetAnchorPoint( AnchorPoint::CENTER );
   application.SendNotification();
   application.Render(16);
 
   // This will be sphere culled
   DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
+
   END_TEST;
 }
 
@@ -260,26 +281,33 @@ int UtcFrustumBottomCullP(void)
 
   Actor meshActor = Actor::New();
   meshActor.AddRenderer( renderer );
-  meshActor.SetSize(400, 400);
+  meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
   drawTrace.Reset();
 
-  meshActor.SetParentOrigin( Vector3( 0.5f, 1.32f, 0.5f ) );
-  meshActor.SetAnchorPoint( AnchorPoint::CENTER );
+  float offset = 1.01f;
+
+  meshActor.SetParentOrigin( Vector3( 0.5f, offset, 0.5f ) );
+  meshActor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
   Stage::GetCurrent().Add( meshActor );
 
   application.SendNotification();
   application.Render(16);
 
-  // This should be box culled
+  // This will be box culled
   DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
 
+  float radius = meshActor.GetTargetSize().Length() * 0.5f;
+  Vector2 stageSize = Stage::GetCurrent().GetSize();
+
   drawTrace.Reset();
-  meshActor.SetParentOrigin( Vector3( 0.5f, 1.5f, 0.5f ) );
+  meshActor.SetParentOrigin( Vector3( 0.5f, radius/stageSize.width + offset, 0.5f ) );
+  meshActor.SetAnchorPoint( AnchorPoint::CENTER );
   application.SendNotification();
   application.Render(16);
 
   // This will be sphere culled
   DALI_TEST_CHECK( !drawTrace.FindMethod( "DrawElements" ) );
+
   END_TEST;
 }
 
@@ -301,7 +329,7 @@ int UtcFrustumNearCullP(void)
 
   Actor meshActor = Actor::New();
   meshActor.AddRenderer( renderer );
-  meshActor.SetSize(400, 400);
+  meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
   drawTrace.Reset();
 
   meshActor.SetParentOrigin( Vector3( 0.5f, 0.5f, 7.0f ) );
@@ -334,7 +362,7 @@ int UtcFrustumFarCullP(void)
 
   Actor meshActor = Actor::New();
   meshActor.AddRenderer( renderer );
-  meshActor.SetSize(400, 400);
+  meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
   drawTrace.Reset();
 
   meshActor.SetParentOrigin( Vector3( 0.5f, 0.5f, -7.0f ) );
@@ -367,10 +395,10 @@ int UtcFrustumCullDisabledP(void)
 
   Actor meshActor = Actor::New();
   meshActor.AddRenderer( renderer );
-  meshActor.SetSize(400, 400);
+  meshActor.SetSize( Vector3( 400.0f, 400.0f, 0.1f) );
   drawTrace.Reset();
 
-  meshActor.SetParentOrigin( Vector3( 0.5f, 0.5f, -7.0f ) );
+  meshActor.SetParentOrigin( ParentOrigin::CENTER );
   meshActor.SetAnchorPoint( AnchorPoint::CENTER );
   Stage::GetCurrent().Add( meshActor );
 
index cb8986ee5023b2077e37669c845b1e200773dde3..ea9196b436ef4878239faa9d5556fd5027d7ef7d 100644 (file)
@@ -61,7 +61,6 @@ public:
     {
       GEOMETRY_TYPE = DEFAULT_OBJECT_PROPERTY_START_INDEX,  ///< name "depth-index",            type STRING
       GEOMETRY_CENTER,                                      ///< name "geometry-center",        type VECTOR3
-      GEOMETRY_HALF_EXTENTS,                                ///< name "geometry-half-extents",  type VECTOR3
       REQUIRES_DEPTH_TEST,                                  ///< name "requires-depth-testing", type BOOLEAN
     };
   };
index 60081f291ea2946be3695723666000cef8e359d8..5e90873f06e65108e5ecb4049a7ecd8bae274386 100644 (file)
@@ -40,7 +40,6 @@ namespace
 DALI_PROPERTY_TABLE_BEGIN
 DALI_PROPERTY( "geometry-type",         STRING,   true, false,  true, Dali::Geometry::Property::GEOMETRY_TYPE )
 DALI_PROPERTY( "geometry-center",       VECTOR3,  true, true,   true, Dali::Geometry::Property::GEOMETRY_CENTER )
-DALI_PROPERTY( "geometry-half-extents", VECTOR3,  true, true,   true, Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS )
 DALI_PROPERTY( "requires-depth-test",   BOOLEAN,  true, false,  true, Dali::Geometry::Property::REQUIRES_DEPTH_TEST )
 DALI_PROPERTY_TABLE_END( DEFAULT_ACTOR_PROPERTY_START_INDEX )
 
@@ -193,13 +192,6 @@ void Geometry::SetDefaultProperty( Property::Index index,
       SceneGraph::AnimatablePropertyMessage<Vector3>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mCenter, &SceneGraph::AnimatableProperty<Vector3>::Bake, propertyValue.Get<Vector3>() );
       break;
     }
-
-    case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS :
-    {
-      SceneGraph::AnimatablePropertyMessage<Vector3>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mHalfExtents, &SceneGraph::AnimatableProperty<Vector3>::Bake, propertyValue.Get<Vector3>() );
-      break;
-    }
-
     case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
     {
       SceneGraph::DoubleBufferedPropertyMessage<bool>::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mRequiresDepthTest, &SceneGraph::DoubleBufferedProperty<bool>::Set, propertyValue.Get<bool>() );
@@ -239,15 +231,6 @@ Property::Value Geometry::GetDefaultProperty( Property::Index index ) const
       break;
     }
 
-    case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS :
-    {
-      if( mSceneObject )
-      {
-        value = mSceneObject->mHalfExtents[bufferIndex];
-      }
-      break;
-    }
-
     case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
     {
       if( mSceneObject )
@@ -291,11 +274,6 @@ const SceneGraph::PropertyBase* Geometry::GetSceneObjectAnimatableProperty( Prop
           property = &mSceneObject->mCenter;
           break;
         }
-        case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS :
-        {
-          property = &mSceneObject->mHalfExtents;
-          break;
-        }
         default:
         {
           DALI_ASSERT_ALWAYS( 0 && "Property is not animatable" );
@@ -335,11 +313,6 @@ const PropertyInputImpl* Geometry::GetSceneObjectInputProperty( Property::Index
           property = &mSceneObject->mCenter;
           break;
         }
-        case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS :
-        {
-          property = &mSceneObject->mHalfExtents;
-          break;
-        }
         case Dali::Geometry::Property::REQUIRES_DEPTH_TEST :
         {
           property = &mSceneObject->mRequiresDepthTest;
index b59a409370c7e2ae8a7945be95f8d711e7a6f8ac..68eea4a58bac9f17bfd4384d8359180bb642f639 100644 (file)
@@ -176,20 +176,16 @@ inline void AddRendererToRenderList( BufferIndex updateBufferIndex,
   {
     if ( rendererAttachment->GetMaterial().GetShader()->GeometryHintEnabled( Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY ) )
     {
-      // Get the geometry extents for frustum checking
       const Vector3& position = worldMatrix.GetTranslation3();
-      const Geometry& geometry = rendererAttachment->GetGeometry();
       const Vector3& scale = parentNode.GetScale( updateBufferIndex );
-
-      Vector3 center( geometry.mCenter[ updateBufferIndex ] );
-      center *= scale;
-      center += position;
+      const Vector3& halfSize = parentNode.GetSize( updateBufferIndex ) * scale * 0.5f;
 
       // Do a fast sphere check
-      if ( cameraAttachment.CheckSphereInFrustum( updateBufferIndex, center, geometry.mRadius[ updateBufferIndex ] * scale.Length() ) )
+      if ( cameraAttachment.CheckSphereInFrustum( updateBufferIndex, position, halfSize.Length() ) )
       {
         // Check geometry AABB
-        if ( !cameraAttachment.CheckAABBInFrustum( updateBufferIndex, center, geometry.mHalfExtents[ updateBufferIndex ] * scale ) )
+        //TODO: Take into account orientation
+        if ( !cameraAttachment.CheckAABBInFrustum( updateBufferIndex, position, halfSize ) )
         {
           inside = false;
         }
@@ -200,6 +196,7 @@ inline void AddRendererToRenderList( BufferIndex updateBufferIndex,
       }
     }
   }
+
   if ( inside )
   {
     // Get the next free RenderItem
index 59c16e83bdcb52357dd9d234341877012f8a855e..14fbb36f19bd46f2242603e047d4af548904c4cb 100644 (file)
@@ -35,8 +35,6 @@ Geometry::Geometry()
   mSceneController(0),
   mRendererRefCount(0u),
   mCenter(),
-  mHalfExtents(),
-  mRadius( 0.0f ),
   mGeometryType(Dali::Geometry::TRIANGLES),
   mRequiresDepthTest(false)
 {
@@ -149,8 +147,6 @@ void Geometry::ResetDefaultProperties( BufferIndex updateBufferIndex )
 {
   // Reset the animated properties
   mCenter.ResetToBaseValue( updateBufferIndex );
-  mHalfExtents.ResetToBaseValue( updateBufferIndex );
-  mRadius.ResetToBaseValue( updateBufferIndex );
 
   // Age the double buffered properties
   mGeometryType.CopyPrevious(updateBufferIndex);
@@ -159,7 +155,6 @@ void Geometry::ResetDefaultProperties( BufferIndex updateBufferIndex )
 
 void Geometry::CalculateExtents( PropertyBuffer* vertexBuffer )
 {
-  // TODO calculate extents for all vertex buffers attached to geometry
   unsigned int elementIndex = 0;
   unsigned int elementCount = vertexBuffer->GetElementCount( 0 );
   unsigned int elementCount1 = vertexBuffer->GetElementCount( 1 );
@@ -271,15 +266,6 @@ void Geometry::CalculateExtents( PropertyBuffer* vertexBuffer )
       }
       mCenter.Bake( 0, center );
       mCenter.Bake( 1, center );
-      mHalfExtents.Bake( 0, halfExtents );
-      mHalfExtents.Bake( 1, halfExtents );
-
-      float radius = halfExtents.x;
-      if ( radius < halfExtents.y )
-      {
-        radius = halfExtents.y;
-      }
-      mRadius.SetInitial( radius );
     }
   }
 }
index 5f6d02b6fb06e4f10b7580efa426e8e9526a5b5f..c457f6c9a9e8cc1c9af7722fb51ae1cf63ce3b70 100644 (file)
@@ -182,8 +182,6 @@ private:
 
 public: // Properties
   AnimatableProperty<Vector3>   mCenter;
-  AnimatableProperty<Vector3>   mHalfExtents;
-  AnimatableProperty<float>     mRadius;
   DoubleBufferedProperty<int>   mGeometryType;
   DoubleBufferedProperty<bool>  mRequiresDepthTest;
 };