From 2d057cd6009bc79e106c8001238b07871d5e6b97 Mon Sep 17 00:00:00 2001 From: Chu Hoang Date: Mon, 20 Jul 2015 16:55:39 +0100 Subject: [PATCH] Changed view frustum culling to ignore mesh extents and instead use actor extents. Removed Geometry::mHalfExtents and mRadius since they are no longer relevant. Change-Id: I3d262e157bc30f7d999c0f73ba23469f7eac37a6 --- .../utc-Dali-Internal-FrustumCulling.cpp | 78 +++++++++++++++------- dali/devel-api/rendering/geometry.h | 1 - dali/internal/event/rendering/geometry-impl.cpp | 27 -------- .../update/manager/prepare-render-instructions.cpp | 13 ++-- .../update/rendering/scene-graph-geometry.cpp | 14 ---- .../update/rendering/scene-graph-geometry.h | 2 - 6 files changed, 58 insertions(+), 77 deletions(-) diff --git a/automated-tests/src/dali-internal/utc-Dali-Internal-FrustumCulling.cpp b/automated-tests/src/dali-internal/utc-Dali-Internal-FrustumCulling.cpp index 5a65c6d..e3053e1 100644 --- a/automated-tests/src/dali-internal/utc-Dali-Internal-FrustumCulling.cpp +++ b/automated-tests/src/dali-internal/utc-Dali-Internal-FrustumCulling.cpp @@ -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 ); diff --git a/dali/devel-api/rendering/geometry.h b/dali/devel-api/rendering/geometry.h index cb8986e..ea9196b 100644 --- a/dali/devel-api/rendering/geometry.h +++ b/dali/devel-api/rendering/geometry.h @@ -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 }; }; diff --git a/dali/internal/event/rendering/geometry-impl.cpp b/dali/internal/event/rendering/geometry-impl.cpp index 60081f2..5e90873 100644 --- a/dali/internal/event/rendering/geometry-impl.cpp +++ b/dali/internal/event/rendering/geometry-impl.cpp @@ -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::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mCenter, &SceneGraph::AnimatableProperty::Bake, propertyValue.Get() ); break; } - - case Dali::Geometry::Property::GEOMETRY_HALF_EXTENTS : - { - SceneGraph::AnimatablePropertyMessage::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mHalfExtents, &SceneGraph::AnimatableProperty::Bake, propertyValue.Get() ); - break; - } - case Dali::Geometry::Property::REQUIRES_DEPTH_TEST : { SceneGraph::DoubleBufferedPropertyMessage::Send( GetEventThreadServices(), mSceneObject, &mSceneObject->mRequiresDepthTest, &SceneGraph::DoubleBufferedProperty::Set, propertyValue.Get() ); @@ -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; diff --git a/dali/internal/update/manager/prepare-render-instructions.cpp b/dali/internal/update/manager/prepare-render-instructions.cpp index b59a409..68eea4a 100644 --- a/dali/internal/update/manager/prepare-render-instructions.cpp +++ b/dali/internal/update/manager/prepare-render-instructions.cpp @@ -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 diff --git a/dali/internal/update/rendering/scene-graph-geometry.cpp b/dali/internal/update/rendering/scene-graph-geometry.cpp index 59c16e8..14fbb36 100644 --- a/dali/internal/update/rendering/scene-graph-geometry.cpp +++ b/dali/internal/update/rendering/scene-graph-geometry.cpp @@ -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 ); } } } diff --git a/dali/internal/update/rendering/scene-graph-geometry.h b/dali/internal/update/rendering/scene-graph-geometry.h index 5f6d02b..c457f6c 100644 --- a/dali/internal/update/rendering/scene-graph-geometry.h +++ b/dali/internal/update/rendering/scene-graph-geometry.h @@ -182,8 +182,6 @@ private: public: // Properties AnimatableProperty mCenter; - AnimatableProperty mHalfExtents; - AnimatableProperty mRadius; DoubleBufferedProperty mGeometryType; DoubleBufferedProperty mRequiresDepthTest; }; -- 2.7.4