/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/internal/update/nodes/node.h>
#include <dali/internal/update/nodes/scene-graph-layer.h>
-#include <dali/internal/update/node-attachments/node-attachment.h>
-#include <dali/internal/update/node-attachments/scene-graph-camera-attachment.h>
-
#include <dali/internal/update/rendering/scene-graph-renderer.h>
#include <dali/internal/update/resources/texture-metadata.h>
#include <dali/internal/render/renderers/render-property-buffer.h>
#include <dali/internal/render/renderers/render-renderer.h>
#include <dali/internal/render/renderers/render-sampler.h>
+#include <dali/internal/update/render-tasks/scene-graph-camera.h>
using Dali::Internal::GestureEventProcessor;
using Dali::Internal::ThreadLocalStorage;
sizeof( Internal::SceneGraph::Constraint<float, Internal::PropertyAccessor<float> > ) );
const int ACTOR_MEMORY_SIZE(
sizeof( Internal::Actor ) +
- sizeof( Internal::SceneGraph::Node ) +
- sizeof( Internal::SceneGraph::NodeAttachment ));
+ sizeof( Internal::SceneGraph::Node ) );
const int CAMERA_ACTOR_MEMORY_SIZE(
sizeof( Internal::CameraActor ) +
sizeof( Internal::SceneGraph::Node ) +
- sizeof( Internal::SceneGraph::CameraAttachment ) );
+ sizeof( Internal::SceneGraph::Camera ) );
const int IMAGE_ACTOR_MEMORY_SIZE(
sizeof( Internal::ImageActor ) +
sizeof( Internal::SceneGraph::Node ) +
sizeof( Internal::Render::Renderer ));
const int LAYER_MEMORY_SIZE(
sizeof( Internal::Layer ) +
- sizeof( Internal::SceneGraph::Layer ) +
- sizeof( Internal::SceneGraph::NodeAttachment ) );
+ sizeof( Internal::SceneGraph::Layer ) );
const int IMAGE_MEMORY_SIZE(
sizeof( Internal::Image ) +
sizeof( Internal::ImageFactoryCache::Request ) +
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/internal/event/render-tasks/render-task-impl.h>
#include <dali/internal/event/render-tasks/render-task-list-impl.h>
#include <dali/internal/event/common/projection.h>
-#include <dali/internal/update/node-attachments/scene-graph-camera-attachment.h>
+#include <dali/internal/update/render-tasks/scene-graph-camera.h>
namespace Dali
{
actor->SetName("DefaultCamera");
// Create scene-object and transfer ownership through message
- SceneGraph::CameraAttachment* sceneObject = SceneGraph::CameraAttachment::New();
- AttachToNodeMessage( actor->GetEventThreadServices().GetUpdateManager(), *actor->mNode, sceneObject );
+ SceneGraph::Camera* sceneObject = SceneGraph::Camera::New();
+ AddCameraMessage( actor->GetEventThreadServices().GetUpdateManager(), sceneObject );
// Keep raw pointer for message passing
actor->mSceneObject = sceneObject;
CameraActor::CameraActor()
: Actor( Actor::BASIC ),
mSceneObject( NULL ),
- mTarget( SceneGraph::CameraAttachment::DEFAULT_TARGET_POSITION ),
- mType( SceneGraph::CameraAttachment::DEFAULT_TYPE ),
- mProjectionMode( SceneGraph::CameraAttachment::DEFAULT_MODE ),
- mFieldOfView( SceneGraph::CameraAttachment::DEFAULT_FIELD_OF_VIEW ),
- mAspectRatio( SceneGraph::CameraAttachment::DEFAULT_ASPECT_RATIO ),
- mNearClippingPlane( SceneGraph::CameraAttachment::DEFAULT_NEAR_CLIPPING_PLANE ),
- mFarClippingPlane( SceneGraph::CameraAttachment::DEFAULT_FAR_CLIPPING_PLANE ),
- mLeftClippingPlane( SceneGraph::CameraAttachment::DEFAULT_LEFT_CLIPPING_PLANE ),
- mRightClippingPlane( SceneGraph::CameraAttachment::DEFAULT_RIGHT_CLIPPING_PLANE ),
- mTopClippingPlane( SceneGraph::CameraAttachment::DEFAULT_TOP_CLIPPING_PLANE ),
- mBottomClippingPlane( SceneGraph::CameraAttachment::DEFAULT_BOTTOM_CLIPPING_PLANE ),
- mInvertYAxis( SceneGraph::CameraAttachment::DEFAULT_INVERT_Y_AXIS )
+ mTarget( SceneGraph::Camera::DEFAULT_TARGET_POSITION ),
+ mType( SceneGraph::Camera::DEFAULT_TYPE ),
+ mProjectionMode( SceneGraph::Camera::DEFAULT_MODE ),
+ mFieldOfView( SceneGraph::Camera::DEFAULT_FIELD_OF_VIEW ),
+ mAspectRatio( SceneGraph::Camera::DEFAULT_ASPECT_RATIO ),
+ mNearClippingPlane( SceneGraph::Camera::DEFAULT_NEAR_CLIPPING_PLANE ),
+ mFarClippingPlane( SceneGraph::Camera::DEFAULT_FAR_CLIPPING_PLANE ),
+ mLeftClippingPlane( SceneGraph::Camera::DEFAULT_LEFT_CLIPPING_PLANE ),
+ mRightClippingPlane( SceneGraph::Camera::DEFAULT_RIGHT_CLIPPING_PLANE ),
+ mTopClippingPlane( SceneGraph::Camera::DEFAULT_TOP_CLIPPING_PLANE ),
+ mBottomClippingPlane( SceneGraph::Camera::DEFAULT_BOTTOM_CLIPPING_PLANE ),
+ mInvertYAxis( SceneGraph::Camera::DEFAULT_INVERT_Y_AXIS )
{
}
CameraActor::~CameraActor()
{
+ if( EventThreadServices::IsCoreRunning() )
+ {
+ // Create scene-object and transfer ownership through message
+ RemoveCameraMessage( GetEventThreadServices().GetUpdateManager(), mSceneObject );
+ }
}
void CameraActor::SetTarget( const Vector3& target )
return Matrix::IDENTITY;
}
}
+const SceneGraph::Camera* CameraActor::GetCamera() const
+{
+ return mSceneObject;
+}
unsigned int CameraActor::GetDefaultPropertyCount() const
{
namespace SceneGraph
{
-class CameraAttachment;
+class Camera;
}
/**
- * An actor with CameraAttachment.
+ * An actor with Camera.
*/
class CameraActor : public Actor
{
*/
const Matrix& GetProjectionMatrix() const;
+ /**
+ * Return the scene graph camera (for RenderTask)
+ * @return The scene graph camera.
+ */
+ const SceneGraph::Camera* GetCamera() const;
+
public: // properties
/**
private: // Data
- const SceneGraph::CameraAttachment* mSceneObject; ///< Not owned
+ const SceneGraph::Camera* mSceneObject; ///< Not owned
Vector3 mTarget;
Dali::Camera::Type mType;
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void RenderTask::SetCameraActor( CameraActor* cameraActor )
{
+ if( cameraActor )
+ {
+ mCameraConnector.mCamera = cameraActor->GetCamera();
+ }
+ else
+ {
+ mCameraConnector.mCamera = NULL;
+ }
mCameraConnector.SetActor( cameraActor );
}
RenderTask::Connector::Connector( Type type, RenderTask& renderTask )
: mType( type ),
mRenderTask( renderTask ),
- mActor( NULL )
+ mActor( NULL ),
+ mCamera( NULL )
{
}
}
mActor = NULL;
+ mCamera = NULL; // only meaningful for the camera connector but no simple way to distinguish
UpdateRenderTask();
}
}
else if( CAMERA_CONNECTOR == mType )
{
- SetCameraNodeMessage( mRenderTask.GetEventThreadServices(), *(mRenderTask.mSceneObject), node );
+ SetCameraMessage( mRenderTask.GetEventThreadServices(), *(mRenderTask.mSceneObject), node, mCamera );
}
}
}
#define __DALI_INTERNAL_RENDER_TASK_H__
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
namespace SceneGraph
{
class RenderTask;
+class Camera;
}
class RenderTask : public Object
RenderTask& mRenderTask;
Actor* mActor; ///< Raw-pointer to the actor; not owned.
+ const SceneGraph::Camera* mCamera; ///< Raw-pointer to camera scene-graph object; not owned.
};
private:
Connector mSourceConnector; ///< Responsible for connecting/disconnecting source Nodes
Connector mCameraConnector; ///< Responsible for connecting/disconnecting camera Nodes
- Connector mMappingConnector; /// Responsible for connecting/disconnection actor node, which used to mapping screen to frame buffer coordinate
+ Connector mMappingConnector; /// Responsible for connecting/disconnecting actor node, which used to mapping screen to frame buffer coordinate
Vector4 mClearColor; ///< Optional clear color
$(internal_src_dir)/update/manager/update-algorithms.cpp \
$(internal_src_dir)/update/manager/update-manager.cpp \
$(internal_src_dir)/update/manager/update-manager-debug.cpp \
- $(internal_src_dir)/update/node-attachments/node-attachment.cpp \
- $(internal_src_dir)/update/node-attachments/scene-graph-camera-attachment.cpp \
+ $(internal_src_dir)/update/render-tasks/scene-graph-camera.cpp \
$(internal_src_dir)/update/nodes/node.cpp \
$(internal_src_dir)/update/nodes/node-messages.cpp \
$(internal_src_dir)/update/nodes/scene-graph-layer.cpp \
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
mIsViewportSet( false ),
mIsClearColorSet( false ),
mOffscreenTextureId( 0 ),
- mCameraAttachment( 0 ),
+ mCamera( 0 ),
mNextFreeRenderList( 0 )
{
// reserve 6 lists, which is enough for three layers with opaque and transparent things on
return mRenderLists[ index ];
}
-void RenderInstruction::Reset( CameraAttachment* cameraAttachment,
- unsigned int offscreenTextureId,
- const Viewport* viewport,
- const Vector4* clearColor )
+void RenderInstruction::Reset( Camera* camera,
+ unsigned int offscreenTextureId,
+ const Viewport* viewport,
+ const Vector4* clearColor )
{
- mCameraAttachment = cameraAttachment;
+ mCamera = camera;
mViewport = viewport ? *viewport : Viewport();
mIsViewportSet = NULL != viewport;
mClearColor = clearColor ? *clearColor : Color::BLACK;
#define __DALI_INTERNAL_SCENE_GRAPH_RENDER_INSTRUCTION_H__
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// INTERNAL INCLUDES
#include <dali/public-api/math/matrix.h>
#include <dali/public-api/math/viewport.h>
-#include <dali/internal/update/node-attachments/scene-graph-camera-attachment.h>
+#include <dali/internal/update/render-tasks/scene-graph-camera.h>
#include <dali/internal/render/common/render-list.h>
namespace Dali
namespace SceneGraph
{
-class CameraAttachment;
/**
* A set of rendering instructions consisting of:
* render-lists are cleared but not released, while matrices and other settings reset in
* preparation for building a set of instructions for the renderer.
*
- * @param[in] cameraAttachment to use to get view and projection matrices.
+ * @param[in] camera to use to get view and projection matrices.
* @param[in] offscreenId A resource Id of an off-screen render target, or 0
* @param[in] viewport A pointer to a viewport, of NULL.
* @param[in] clearColor A pointer to a color to clear with, or NULL if no clear is required.
*/
- void Reset( CameraAttachment* cameraAttachment,
+ void Reset( Camera* camera,
unsigned int offscreenId,
const Viewport* viewport,
const Vector4* clearColor );
const Matrix* GetViewMatrix( BufferIndex index ) const
{
// inlined as this is called once per frame per render instruction
- return &mCameraAttachment->GetViewMatrix( index );
+ return &mCamera->GetViewMatrix( index );
}
/**
const Matrix* GetProjectionMatrix( BufferIndex index ) const
{
// inlined as this is called once per frame per render instruction
- return &mCameraAttachment->GetProjectionMatrix( index );
+ return &mCamera->GetProjectionMatrix( index );
}
private:
private: // Data
- CameraAttachment* mCameraAttachment; ///< camera that is used
+ Camera* mCamera; ///< camera that is used
RenderListContainer mRenderLists; ///< container of all render lists
RenderListContainer::SizeType mNextFreeRenderList; ///< index for the next free render list
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/internal/render/queue/render-queue.h>
#include <dali/internal/render/renderers/render-renderer.h>
#include <dali/internal/render/shaders/scene-graph-shader.h>
+#include <dali/internal/update/render-tasks/scene-graph-camera.h>
namespace Dali
{
}
}
+void DiscardQueue::Add( BufferIndex updateBufferIndex, Shader* shader )
+{
+ DALI_ASSERT_DEBUG( NULL != shader );
+
+ // Programs are cached for the lifetime of DALi so no need for GL cleanup for shader for now.
+
+ // The GL resources will now be freed in frame N
+ // The Update for frame N+1 may occur in parallel with the rendering of frame N
+ // Queue the node for destruction in frame N+2
+ if ( 0u == updateBufferIndex )
+ {
+ mShaderQueue0.PushBack( shader );
+ }
+ else
+ {
+ mShaderQueue1.PushBack( shader );
+ }
+}
+
void DiscardQueue::Add( BufferIndex updateBufferIndex, Renderer* renderer )
{
DALI_ASSERT_DEBUG( NULL != renderer );
}
}
-void DiscardQueue::Add( BufferIndex updateBufferIndex, Shader* shader )
+void DiscardQueue::Add( BufferIndex updateBufferIndex, Camera* camera )
{
- DALI_ASSERT_DEBUG( NULL != shader );
+ DALI_ASSERT_DEBUG( NULL != camera );
- // Programs are cached for the lifetime of DALi so no need for GL cleanup for shader for now.
-
- // The GL resources will now be freed in frame N
- // The Update for frame N+1 may occur in parallel with the rendering of frame N
- // Queue the node for destruction in frame N+2
if ( 0u == updateBufferIndex )
{
- mShaderQueue0.PushBack( shader );
+ mCameraQueue0.PushBack( camera );
}
else
{
- mShaderQueue1.PushBack( shader );
+ mCameraQueue1.PushBack( camera );
}
}
mNodeQueue0.Clear();
mShaderQueue0.Clear();
mRendererQueue0.Clear();
+ mCameraQueue0.Clear();
}
else
{
mNodeQueue1.Clear();
mShaderQueue1.Clear();
mRendererQueue1.Clear();
+ mCameraQueue1.Clear();
}
}
#define __DALI_INTERNAL_DISCARD_QUEUE_H__
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
namespace Internal
{
-class Texture;
-
namespace SceneGraph
{
-class Node;
class RenderQueue;
class Shader;
+class Camera;
/**
typedef OwnerContainer< Shader* > ShaderQueue;
typedef OwnerContainer< Renderer* > RendererQueue;
+ typedef OwnerContainer< Camera* > CameraQueue;
/**
* Create a new DiscardQueue.
*/
void Add( BufferIndex updateBufferIndex, Renderer* renderer );
+ /**
+ * Adds an unwanted Camera to the discard queue.
+ * This is done because Render thread may use Matrices from the camera
+ * @param[in] updateBufferIndex The current update buffer index.
+ * @param[in] camera The discarded renderer; DiscardQueue takes ownership.
+ */
+ void Add( BufferIndex updateBufferIndex, Camera* camera );
+
/**
* Release the nodes which were queued in the frame N-2.
* @pre This method should be called (once) at the beginning of every Update.
NodeOwnerContainer mNodeQueue0;
ShaderQueue mShaderQueue0;
RendererQueue mRendererQueue0;
+ CameraQueue mCameraQueue0;
// Messages are queued here when the update buffer index == 1
NodeOwnerContainer mNodeQueue1;
ShaderQueue mShaderQueue1;
RendererQueue mRendererQueue1;
+ CameraQueue mCameraQueue1;
};
} // namespace SceneGraph
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
SceneControllerImpl::SceneControllerImpl( RenderMessageDispatcher& renderMessageDispatcher,
RenderQueue& renderQueue,
- DiscardQueue& discardQueue,
- TextureCache& textureCache )
+ DiscardQueue& discardQueue )
: mRenderMessageDispatcher( renderMessageDispatcher ),
mRenderQueue( renderQueue ),
- mDiscardQueue( discardQueue ),
- mTextureCache( textureCache )
+ mDiscardQueue( discardQueue )
{
}
#define __DALI_INTERNAL_SCENE_GRAPH_SCENE_CONTROLLER_IMPL_H__
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* @param[in] rendererDispatcher Used for passing ownership of renderers to the render-thread.
* @param[in] renderQueue The renderQueue
* @param[in] discardQueue The discardQueue
- * @param[in] textureCache
*/
SceneControllerImpl( RenderMessageDispatcher& renderMessageDispatcher,
RenderQueue& renderQueue,
- DiscardQueue& discardQueue,
- TextureCache& textureCache );
+ DiscardQueue& discardQueue );
/**
* Destructor
*/
virtual DiscardQueue& GetDiscardQueue() { return mDiscardQueue; }
- /**
- * @copydoc SceneController::GetTextureCache()
- */
- virtual TextureCache& GetTextureCache() { return mTextureCache; }
-
private:
// Undefined copy constructor.
RenderMessageDispatcher& mRenderMessageDispatcher; ///< Used for passing messages to the render-thread
RenderQueue& mRenderQueue; ///< render queue
DiscardQueue& mDiscardQueue; ///< discard queue
- TextureCache& mTextureCache; ///< texture cache
};
#define __DALI_INTERNAL_SCENE_GRAPH_SCENE_CONTROLLER_H__
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
namespace SceneGraph
{
-class CameraController;
class RenderMessageDispatcher;
class RenderQueue;
class DiscardQueue;
-class TextureCache;
/**
* Abstract interface for the scene controller
*/
virtual DiscardQueue& GetDiscardQueue() = 0;
- /**
- * Return the texture cache
- * TODO: Remove this method when renderer's & shader's second stage initialization
- * is done by RenderManager rather than by the attachments in the Update thread.
- * DO NOT USE THIS IN THE UPDATE THREAD!
- * @return A reference to the texture cache
- */
- virtual TextureCache& GetTextureCache() = 0;
-
private:
// Undefined copy constructor.
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* @param renderList to add the item to
* @param renderable Node-Renderer pair
* @param viewMatrix used to calculate modelview matrix for the item
- * @param cameraAttachment The camera used to render
+ * @param camera The camera used to render
* @param isLayer3d Whether we are processing a 3D layer or not
* @param cull Whether frustum culling is enabled or not
*/
RenderList& renderList,
Renderable& renderable,
const Matrix& viewMatrix,
- SceneGraph::CameraAttachment& cameraAttachment,
+ SceneGraph::Camera& camera,
bool isLayer3d,
bool cull )
{
{
const Vector4& boundingSphere = renderable.mNode->GetBoundingSphere();
inside = (boundingSphere.w > Math::MACHINE_EPSILON_1000) &&
- (cameraAttachment.CheckSphereInFrustum( updateBufferIndex, Vector3(boundingSphere), boundingSphere.w ) );
+ (camera.CheckSphereInFrustum( updateBufferIndex, Vector3(boundingSphere), boundingSphere.w ) );
}
if ( inside )
* Add all renderers to the list
* @param updateBufferIndex to read the model matrix from
* @param renderList to add the items to
- * @param renderable attachments
+ * @param renderers to render
* NodeRendererContainer Node-Renderer pairs
* @param viewMatrix used to calculate modelview matrix for the items
- * @param cameraAttachment The camera used to render
+ * @param camera The camera used to render
* @param isLayer3d Whether we are processing a 3D layer or not
* @param cull Whether frustum culling is enabled or not
*/
inline void AddRenderersToRenderList( BufferIndex updateBufferIndex,
RenderList& renderList,
- RenderableContainer& renderables,
+ RenderableContainer& renderers,
const Matrix& viewMatrix,
- SceneGraph::CameraAttachment& cameraAttachment,
+ SceneGraph::Camera& camera,
bool isLayer3d,
bool cull)
{
DALI_LOG_INFO( gRenderListLogFilter, Debug::Verbose, "AddRenderersToRenderList()\n");
- unsigned int rendererCount( renderables.Size() );
+ unsigned int rendererCount( renderers.Size() );
for( unsigned int i(0); i<rendererCount; ++i )
{
- AddRendererToRenderList( updateBufferIndex, renderList, renderables[i], viewMatrix, cameraAttachment, isLayer3d, cull );
+ AddRendererToRenderList( updateBufferIndex, renderList, renderers[i], viewMatrix, camera, isLayer3d, cull );
}
}
if( ( renderList.GetSourceLayer() == &layer )&&
( renderList.GetCachedItemCount() == renderableCount ) )
{
- // check that all the same renderers are there. This gives us additional security in avoiding rendering the wrong attachments
- // Attachments are not sorted, but render list is so at this stage renderers may be in different order
+ // check that all the same renderers are there. This gives us additional security in avoiding rendering the wrong things
+ // Render list is sorted so at this stage renderers may be in different order
// therefore we check a combined sum of all renderer addresses
size_t checkSumNew = 0;
size_t checkSumOld = 0;
* @param updateBufferIndex to use
* @param layer to get the renderers from
* @param viewmatrix for the camera from rendertask
- * @param cameraAttachment to use the view frustum
+ * @param camera to use the view frustum
* @param stencilRenderablesExist is true if there are stencil renderers on this layer
* @param instruction to fill in
* @param sortingHelper to use for sorting the renderitems (to avoid reallocating)
inline void AddColorRenderers( BufferIndex updateBufferIndex,
Layer& layer,
const Matrix& viewMatrix,
- SceneGraph::CameraAttachment& cameraAttachment,
+ SceneGraph::Camera& camera,
bool stencilRenderablesExist,
RenderInstruction& instruction,
RendererSortingHelper& sortingHelper,
}
}
- AddRenderersToRenderList( updateBufferIndex, renderList, layer.colorRenderables, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D, cull );
+ AddRenderersToRenderList( updateBufferIndex, renderList, layer.colorRenderables, viewMatrix, camera, layer.GetBehavior() == Dali::Layer::LAYER_3D, cull );
SortRenderItems( updateBufferIndex, renderList, layer, sortingHelper );
//Set render flags
* @param updateBufferIndex to use
* @param layer to get the renderers from
* @param viewmatrix for the camera from rendertask
+ * @param camera to use
* @param stencilRenderablesExist is true if there are stencil renderers on this layer
* @param instruction to fill in
* @param tryReuseRenderList whether to try to reuse the cached items from the instruction
inline void AddOverlayRenderers( BufferIndex updateBufferIndex,
Layer& layer,
const Matrix& viewMatrix,
- SceneGraph::CameraAttachment& cameraAttachment,
+ SceneGraph::Camera& camera,
bool stencilRenderablesExist,
RenderInstruction& instruction,
RendererSortingHelper& sortingHelper,
return;
}
}
- AddRenderersToRenderList( updateBufferIndex, overlayRenderList, layer.overlayRenderables, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D, cull );
+ AddRenderersToRenderList( updateBufferIndex, overlayRenderList, layer.overlayRenderables, viewMatrix, camera, layer.GetBehavior() == Dali::Layer::LAYER_3D, cull );
SortRenderItems( updateBufferIndex, overlayRenderList, layer, sortingHelper );
}
* @param updateBufferIndex to use
* @param layer to get the renderers from
* @param viewmatrix for the camera from rendertask
+ * @param camera to use
* @param instruction to fill in
* @param tryReuseRenderList whether to try to reuse the cached items from the instruction
* @param cull Whether frustum culling is enabled or not
inline void AddStencilRenderers( BufferIndex updateBufferIndex,
Layer& layer,
const Matrix& viewMatrix,
- SceneGraph::CameraAttachment& cameraAttachment,
+ SceneGraph::Camera& camera,
RenderInstruction& instruction,
bool tryReuseRenderList,
bool cull )
return;
}
}
- AddRenderersToRenderList( updateBufferIndex, stencilRenderList, layer.stencilRenderables, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D, cull );
+ AddRenderersToRenderList( updateBufferIndex, stencilRenderList, layer.stencilRenderables, viewMatrix, camera, layer.GetBehavior() == Dali::Layer::LAYER_3D, cull );
}
void PrepareRenderInstruction( BufferIndex updateBufferIndex,
bool viewMatrixHasNotChanged = !renderTask.ViewMatrixUpdated();
const Matrix& viewMatrix = renderTask.GetViewMatrix( updateBufferIndex );
- SceneGraph::CameraAttachment& cameraAttachment = renderTask.GetCameraAttachment();
+ SceneGraph::Camera& camera = renderTask.GetCamera();
const SortedLayersIter endIter = sortedLayers.end();
for ( SortedLayersIter iter = sortedLayers.begin(); iter != endIter; ++iter )
const bool stencilRenderablesExist( !layer.stencilRenderables.Empty() );
const bool colorRenderablesExist( !layer.colorRenderables.Empty() );
const bool overlayRenderablesExist( !layer.overlayRenderables.Empty() );
- const bool tryReuseRenderList( viewMatrixHasNotChanged && layer.CanReuseRenderers(renderTask.GetCamera()) );
+ const bool tryReuseRenderList( viewMatrixHasNotChanged && layer.CanReuseRenderers( &renderTask.GetCamera() ) );
// Ignore stencils if there's nothing to test
if( stencilRenderablesExist &&
( colorRenderablesExist || overlayRenderablesExist ) )
{
- AddStencilRenderers( updateBufferIndex, layer, viewMatrix, cameraAttachment, instruction, tryReuseRenderList, cull );
+ AddStencilRenderers( updateBufferIndex, layer, viewMatrix, camera, instruction, tryReuseRenderList, cull );
}
if ( colorRenderablesExist )
AddColorRenderers( updateBufferIndex,
layer,
viewMatrix,
- cameraAttachment,
+ camera,
stencilRenderablesExist,
instruction,
sortingHelper,
if ( overlayRenderablesExist )
{
- AddOverlayRenderers( updateBufferIndex, layer, viewMatrix, cameraAttachment, stencilRenderablesExist,
+ AddOverlayRenderers( updateBufferIndex, layer, viewMatrix, camera, stencilRenderablesExist,
instruction, sortingHelper, tryReuseRenderList, cull );
}
}
#define __DALI_INTERNAL_SCENE_GRAPH_PREPARE_RENDER_INSTRUCTIONS_H__
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
class RenderInstructionContainer;
/**
- * Sorts and prepares the list of opaque/transparent renderable
- * attachments for each layer. Whilst iterating through each layer,
- * update the attachments ModelView matrices
+ * Sorts and prepares the list of opaque/transparent renderers for each layer.
+ * Whilst iterating through each layer, update the renderitems ModelView matrices
*
* The opaque and transparent render lists are sorted first by depth
* index, then by Z (for transparent only), then by shader, texture
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// For each render-task:
// 1) Prepare the render-task
- // 2) Clear the layer-stored lists of attachments (TODO check if the layer is not changed and don't clear in this case)
+ // 2) Clear the layer-stored lists of renderers (TODO check if the layer is not changed and don't clear in this case)
// 3) Traverse the scene-graph, filling the lists for the current render-task
// 4) Prepare render-instructions
#define __DALI_INTERNAL_SCENE_GRAPH_PROCESS_RENDER_TASKS_H__
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/**
* Process the list of render-tasks; the output is a series of render instructions.
- * @note When ProcessRenderTasks is called, the layers should already the transparent/opaque attachments which are ready to render.
+ * @note When ProcessRenderTasks is called, the layers should already the transparent/opaque renderers which are ready to render.
* If there is only one default render-task, then no further processing is required.
* @param[in] updateBufferIndex The current update buffer index.
* @param[in] renderTasks The list of render-tasks.
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/public-api/math/vector3.h>
#include <dali/internal/update/resources/resource-manager.h>
#include <dali/internal/update/nodes/node.h>
-#include <dali/internal/update/node-attachments/node-attachment.h>
#include <dali/internal/update/animation/scene-graph-constraint-base.h>
#include <dali/internal/update/nodes/scene-graph-layer.h>
#include <dali/internal/render/renderers/render-renderer.h>
/**
* This is called recursively for all children of the root Node
*/
-inline int UpdateNodesAndAttachments( Node& node,
- int parentFlags,
- BufferIndex updateBufferIndex,
- ResourceManager& resourceManager,
- RenderQueue& renderQueue,
- Layer& currentLayer,
- int inheritedDrawMode )
+inline int UpdateNodes( Node& node,
+ int parentFlags,
+ BufferIndex updateBufferIndex,
+ ResourceManager& resourceManager,
+ RenderQueue& renderQueue,
+ Layer& currentLayer,
+ int inheritedDrawMode )
{
//Apply constraints to the node
ConstrainPropertyOwner( node, updateBufferIndex );
for ( NodeIter iter = children.Begin(); iter != endIter; ++iter )
{
Node& child = **iter;
- cumulativeDirtyFlags |=UpdateNodesAndAttachments( child,
- nodeDirtyFlags,
- updateBufferIndex,
- resourceManager,
- renderQueue,
- *layer,
- inheritedDrawMode );
+ cumulativeDirtyFlags |=UpdateNodes( child,
+ nodeDirtyFlags,
+ updateBufferIndex,
+ resourceManager,
+ renderQueue,
+ *layer,
+ inheritedDrawMode );
}
return cumulativeDirtyFlags;
/**
* The root node is treated separately; it cannot inherit values since it has no parent
*/
-int UpdateNodesAndAttachments( Layer& rootNode,
- BufferIndex updateBufferIndex,
- ResourceManager& resourceManager,
- RenderQueue& renderQueue )
+int UpdateNodeTree( Layer& rootNode,
+ BufferIndex updateBufferIndex,
+ ResourceManager& resourceManager,
+ RenderQueue& renderQueue )
{
DALI_ASSERT_DEBUG( rootNode.IsRoot() );
for ( NodeIter iter = children.Begin(); iter != endIter; ++iter )
{
Node& child = **iter;
- cumulativeDirtyFlags |= UpdateNodesAndAttachments( child,
- nodeDirtyFlags,
- updateBufferIndex,
- resourceManager,
- renderQueue,
- rootNode,
- drawMode );
+ cumulativeDirtyFlags |= UpdateNodes( child,
+ nodeDirtyFlags,
+ updateBufferIndex,
+ resourceManager,
+ renderQueue,
+ rootNode,
+ drawMode );
}
return cumulativeDirtyFlags;
#define __DALI_INTERNAL_SCENE_GRAPH_UPDATE_ALGORITHMS_H__
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
void ConstrainPropertyOwner( PropertyOwner& propertyOwner, BufferIndex updateBufferIndex );
/**
- * Update a tree of nodes, and attached objects.
+ * Update a tree of nodes
* The inherited properties of each node are recalculated if necessary.
- * When a renderable attachment is ready to render, PrepareResources() is called and
- * it is added to the list for its Layer.
* @param[in] rootNode The root of a tree of nodes.
* @param[in] updateBufferIndex The current update buffer index.
* @param[in] resourceManager The resource manager.
* @param[in] renderQueue Used to query messages for the next Render.
* @return The cumulative (ORed) dirty flags for the updated nodes
*/
-int UpdateNodesAndAttachments( Layer& rootNode,
- BufferIndex updateBufferIndex,
- ResourceManager& resourceManager,
- RenderQueue& renderQueue );
+int UpdateNodeTree( Layer& rootNode,
+ BufferIndex updateBufferIndex,
+ ResourceManager& resourceManager,
+ RenderQueue& renderQueue );
} // namespace SceneGraph
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/internal/update/manager/update-algorithms.h>
#include <dali/internal/update/manager/update-manager-debug.h>
#include <dali/internal/update/manager/transform-manager.h>
-#include <dali/internal/update/node-attachments/scene-graph-camera-attachment.h>
#include <dali/internal/update/nodes/node.h>
#include <dali/internal/update/nodes/scene-graph-layer.h>
#include <dali/internal/update/queue/update-message-queue.h>
#include <dali/internal/render/gl-resources/texture-cache.h>
#include <dali/internal/render/shaders/scene-graph-shader.h>
#include <dali/internal/render/renderers/render-sampler.h>
+#include <dali/internal/update/render-tasks/scene-graph-camera.h>
// Un-comment to enable node tree debug logging
//#define NODE_TREE_LOGGING 1
renderSortingHelper(),
renderTaskWaiting( false )
{
- sceneController = new SceneControllerImpl( renderMessageDispatcher, renderQueue, discardQueue, textureCache );
+ sceneController = new SceneControllerImpl( renderMessageDispatcher, renderQueue, discardQueue );
renderers.SetSceneController( *sceneController );
systemLevelRoot = NULL;
}
- sceneController->GetTextureCache().SetBufferIndices(NULL); // TODO - Remove
delete sceneController;
}
SortedLayerPointers sortedLayers; ///< A container of Layer pointers sorted by depth
SortedLayerPointers systemLevelSortedLayers; ///< A separate container of system-level Layers
+ OwnerContainer< Camera* > cameras; ///< A container of cameras
OwnerContainer< PropertyOwner* > customObjects; ///< A container of owned objects (with custom properties)
AnimationContainer animations; ///< A container of owned animations
node->OnDestroy();
}
-//@todo MESH_REWORK Extend to allow arbitrary scene objects to connect to each other
-void UpdateManager::AttachToNode( Node* node, NodeAttachment* attachment )
+void UpdateManager::AddCamera( Camera* camera )
{
- DALI_ASSERT_DEBUG( node != NULL );
- DALI_ASSERT_DEBUG( attachment != NULL );
+ DALI_ASSERT_DEBUG( camera != NULL );
+
+ mImpl->cameras.PushBack( camera ); // takes ownership
+}
+
+void UpdateManager::RemoveCamera( const Camera* camera )
+{
+ // Find the camera
+ OwnerContainer<Camera*>::Iterator iter = mImpl->cameras.Begin();
+ OwnerContainer<Camera*>::ConstIterator end = mImpl->cameras.End();
+ for ( ; iter != end; ++iter )
+ {
+ Camera* value = *iter;
+ if ( camera == value )
+ {
+ // Transfer ownership to the discard queue
+ mImpl->discardQueue.Add( mSceneGraphBuffers.GetUpdateBufferIndex(), mImpl->cameras.Release( iter ) );
+
+ return;
+ }
+ }
- // attach node to attachment first so that parent is known by the time attachment is connected
- node->Attach( *attachment ); // node takes ownership
}
void UpdateManager::AddObject( PropertyOwner* object )
return;
}
- // Prepare resources, update shaders, update attachments, for each node
+ // Prepare resources, update shaders, for each node
// And add the renderers to the sorted layers. Start from root, which is also a layer
- mImpl->nodeDirtyFlags = UpdateNodesAndAttachments( *( mImpl->root ),
- bufferIndex,
- mImpl->resourceManager,
- mImpl->renderQueue );
+ mImpl->nodeDirtyFlags = UpdateNodeTree( *( mImpl->root ),
+ bufferIndex,
+ mImpl->resourceManager,
+ mImpl->renderQueue );
if ( mImpl->systemLevelRoot )
{
- mImpl->nodeDirtyFlags |= UpdateNodesAndAttachments( *( mImpl->systemLevelRoot ),
- bufferIndex,
- mImpl->resourceManager,
- mImpl->renderQueue );
+ mImpl->nodeDirtyFlags |= UpdateNodeTree( *( mImpl->systemLevelRoot ),
+ bufferIndex,
+ mImpl->resourceManager,
+ mImpl->renderQueue );
}
}
//Prepare texture sets and apply constraints to them
PrepareTextureSets( bufferIndex );
- //Clear the lists of renderable-attachments from the previous update
+ //Clear the lists of renderers from the previous update
for( size_t i(0); i<mImpl->sortedLayers.size(); ++i )
{
mImpl->sortedLayers[i]->ClearRenderables();
#define __DALI_INTERNAL_SCENE_GRAPH_UPDATE_MANAGER_H__
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/internal/update/common/scene-graph-buffers.h>
#include <dali/internal/update/common/scene-graph-property-notification.h>
#include <dali/internal/update/manager/object-owner-container.h>
-#include <dali/internal/update/node-attachments/node-attachment.h>
#include <dali/internal/update/nodes/node.h>
#include <dali/internal/update/nodes/scene-graph-layer.h>
#include <dali/internal/update/rendering/scene-graph-renderer.h>
class TextureCache;
class PropertyBuffer;
class TextureSet;
+class Camera;
/**
- * UpdateManager maintains a scene graph i.e. a tree of nodes and attachments and
- * other property owner objects.
+ * UpdateManager maintains a scene graph i.e. a tree of nodes as well as
+ * other scene graph property owning objects.
* It controls the Update traversal, in which nodes are repositioned/animated,
* and organizes the the culling and rendering of the scene.
* It also maintains the lifecycle of nodes and other property owners that are
void DestroyNode( Node* node );
/**
- * Attach an object to a Node.
- * The UpdateManager is responsible for calling NodeAttachment::Initialize().
- * @param[in] node The node which will own the attachment.
- * @param[in] attachment The object to attach.
+ * Add a camera on scene
+ * @param[in] camera to add
*/
- void AttachToNode( Node* node, NodeAttachment* attachment );
+ void AddCamera( Camera* camera );
+
+ /**
+ * Remove a camera from scene
+ * @param[in] camera to remove
+ */
+ void RemoveCamera( const Camera* camera );
/**
* Add a newly created object.
*/
unsigned int KeepUpdatingCheck( float elapsedSeconds ) const;
- /**
- * Helper to calculate new camera setup when root node resizes.
- * @param[in] updateBuffer The buffer to read the root node size from.
- */
- void UpdateProjectionAndViewMatrices(int updateBuffer);
-
/**
* Post process resources that have been updated by renderer
*/
*/
void ForwardCompiledShadersToEventThread();
- /**
- * Update the default camera.
- * This must be altered to match the root Node for 2D layouting.
- * @param[in] updateBuffer The buffer to read the root node size from.
- */
- void UpdateDefaultCamera( int updateBuffer );
-
/**
* Update node shaders, opacity, geometry etc.
* @param[in] bufferIndex to use
new (slot) LocalType( &manager, &UpdateManager::DestroyNode, &node );
}
-inline void AttachToNodeMessage( UpdateManager& manager, const Node& constParent, NodeAttachment* attachment )
+inline void AddCameraMessage( UpdateManager& manager, const Camera* constCamera )
{
- // Scene graph thread can modify this object.
- Node& parent = const_cast< Node& >( constParent );
+ typedef MessageValue1< UpdateManager, Camera* > LocalType;
+
+ Camera* camera = const_cast<Camera*>( constCamera );
+ // Reserve some memory inside the message queue
+ unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
- typedef MessageValue2< UpdateManager, Node*, NodeAttachmentOwner > LocalType;
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &manager, &UpdateManager::AddCamera, camera );
+}
+
+inline void RemoveCameraMessage( UpdateManager& manager, const Camera* camera )
+{
+ typedef MessageValue1< UpdateManager, const Camera* > LocalType;
// Reserve some memory inside the message queue
unsigned int* slot = manager.ReserveMessageSlot( sizeof( LocalType ) );
// Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &manager, &UpdateManager::AttachToNode, &parent, attachment );
+ new (slot) LocalType( &manager, &UpdateManager::RemoveCamera, camera );
}
inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
+++ /dev/null
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_DECLARATIONS_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_DECLARATIONS_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/devel-api/common/owner-container.h>
-#include <dali/internal/common/owner-pointer.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace SceneGraph
-{
-
-class NodeAttachment;
-typedef OwnerPointer<NodeAttachment> NodeAttachmentOwner;
-
-typedef OwnerContainer< NodeAttachment* > NodeAttachmentOwnerContainer;
-typedef NodeAttachmentOwnerContainer::Iterator NodeAttachmentIter;
-typedef NodeAttachmentOwnerContainer::ConstIterator NodeAttachmentConstIter;
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
-
-#endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_DECLARATIONS_H__
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// CLASS HEADER
-#include <dali/internal/update/node-attachments/node-attachment.h>
-
-// INTERNAL INCLUDES
-#include <dali/internal/update/nodes/node.h>
-#include <dali/public-api/common/dali-common.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace SceneGraph
-{
-
-NodeAttachment::NodeAttachment()
-: mParent(NULL)
-{
-}
-
-NodeAttachment::~NodeAttachment()
-{
-}
-
-void NodeAttachment::SetParent( Node& parent )
-{
- DALI_ASSERT_DEBUG(mParent == NULL);
-
- mParent = &parent;
-}
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
+++ /dev/null
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// EXTERNAL INCLUDES
-#include <cstddef> // NULL
-
-// INTERNAL INCLUDES
-#include <dali/internal/common/message.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace SceneGraph
-{
-
-class Node;
-class SceneController;
-
-/**
- * NodeAttachment is a base class for objects attached to Nodes in the scene graph.
- * The position of the object is provided by its parent node.
- * NodeAttachment data is double-buffered. This allows an update thread to modify node data, without interferring
- * with another thread reading the values from the previous update traversal.
- */
-class NodeAttachment
-{
-public:
-
- /**
- * Virtual destructor
- */
- virtual ~NodeAttachment();
-
- /**
- * Second-phase construction.
- * This is called by the UpdateManager when the attachment is attached to the scene-graph.
- * @param[in] sceneController Allows attachments to get camera controllers.
- * @param[in] updateBufferIndex The current update buffer index.
- */
- virtual void Initialize( SceneController& sceneController, BufferIndex updateBufferIndex ) = 0;
-
- /**
- * Called shortly before destruction.
- * After this method has been called, the SceneController cannot be safely accessed.
- */
- virtual void OnDestroy() = 0;
-
- /**
- * Called when the parent node is connected to the SceneGraph
- */
- virtual void ConnectedToSceneGraph() = 0;
-
- /**
- * Called when the parent node is disconnected from the SceneGraph
- */
- virtual void DisconnectedFromSceneGraph( ) = 0;
-
- /**
- * Set the parent of a NodeAttachment.
- * @param[in] parent the new parent.
- */
- void SetParent( Node& parent );
-
- /**
- * Retrieve the parent node of a NodeAttachment.
- * @return The parent node, or NULL if the NodeAttachment has not been added to the scene-graph.
- */
- Node& GetParent()
- {
- DALI_ASSERT_DEBUG( mParent != NULL );
- return *mParent;
- }
-
- /**
- * Retrieve the parent node of a NodeAttachment.
- * @return The parent node, or NULL if the NodeAttachment has not been added to the scene-graph.
- */
- Node& GetParent() const
- {
- DALI_ASSERT_DEBUG( mParent != NULL );
- return *mParent;
- }
-
-protected:
-
- /**
- * Derived versions of NodeAttachment should be constructed.
- */
- NodeAttachment();
-
-private:
-
- // Undefined
- NodeAttachment( const NodeAttachment& );
-
- // Undefined
- NodeAttachment& operator=( const NodeAttachment& rhs );
-
-protected:
-
- Node* mParent; ///< Pointer to parent node which owns the attachment.
-};
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
-
-#endif // __DALI_INTERNAL_SCENE_GRAPH_NODE_ATTACHMENT_H__
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// CLASS HEADER
-#include <dali/internal/update/node-attachments/scene-graph-camera-attachment.h>
-
-// INTERNAL HEADERS
-#include <dali/integration-api/debug.h>
-#include <dali/internal/update/controllers/scene-controller.h>
-#include <dali/internal/update/nodes/node.h>
-#include <dali/internal/update/resources/resource-manager.h>
-#include <dali/public-api/common/dali-common.h>
-#include <dali/public-api/math/math-utils.h>
-
-namespace // unnamed namespace
-{
-const unsigned int UPDATE_COUNT = 2u; // Update projection or view matrix this many frames after a change
-const unsigned int COPY_PREVIOUS_MATRIX = 1u; // Copy view or projection matrix from previous frame
-}
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace SceneGraph
-{
-
-namespace
-{
-
-void LookAt(Matrix& result, const Vector3& eye, const Vector3& target, const Vector3& up)
-{
- Vector3 vZ = target - eye;
- vZ.Normalize();
-
- Vector3 vX = up.Cross(vZ);
- vX.Normalize();
-
- Vector3 vY = vZ.Cross(vX);
- vY.Normalize();
-
- result.SetInverseTransformComponents(vX, vY, vZ, eye);
-}
-
-
-void Frustum(Matrix& result, float left, float right, float bottom, float top, float near, float far, bool invertYAxis)
-{
- float deltaZ = far - near;
- if ((near <= 0.0f) || (far <= 0.0f) || Equals(right, left) || Equals(bottom, top) || (deltaZ <= 0.0f))
- {
- DALI_LOG_ERROR("Invalid parameters passed into Frustum!");
- DALI_ASSERT_DEBUG("Invalid parameters passed into Frustum!");
- return;
- }
-
- float deltaX = right - left;
- float deltaY = invertYAxis ? bottom - top : top - bottom;
-
- result.SetIdentity();
-
- float* m = result.AsFloat();
- m[0] = -2.0f * near / deltaX;
- m[1] = m[2] = m[3] = 0.0f;
-
- m[5] = -2.0f * near / deltaY;
- m[4] = m[6] = m[7] = 0.0f;
-
- m[8] = (right + left) / deltaX;
- m[9] = (top + bottom) / deltaY;
- m[10] = (near + far) / deltaZ;
- m[11] = 1.0f;
-
- m[14] = -2.0f * near * far / deltaZ;
- m[12] = m[13] = m[15] = 0.0f;
-}
-
-void Perspective(Matrix& result, float fovy, float aspect, float near, float far, bool invertYAxis, const Vector2& stereoBias )
-{
- float frustumH = tanf( fovy * 0.5f ) * near;
- float frustumW = frustumH * aspect;
- Vector2 bias = stereoBias * 0.5f;
-
- Frustum(result, -(frustumW + bias.x), frustumW - bias.x, -(frustumH + bias.y), frustumH - bias.y, near, far, invertYAxis);
-}
-
-void Orthographic(Matrix& result, float left, float right, float bottom, float top, float near, float far, bool invertYAxis)
-{
- if ( Equals(right, left) || Equals(top, bottom) || Equals(far, near) )
- {
- DALI_LOG_ERROR( "Cannot create orthographic projection matrix with a zero dimension." );
- DALI_ASSERT_DEBUG( "Cannot create orthographic projection matrix with a zero dimension." );
- return;
- }
-
- float deltaX = right - left;
- float deltaY = invertYAxis ? bottom - top : top - bottom;
- float deltaZ = far - near;
-
- float *m = result.AsFloat();
- m[0] = -2.0f / deltaX;
- m[1] = 0.0f;
- m[2] = 0.0f;
- m[3] = 0.0f;
-
- m[4] = 0.0f;
- m[5] = -2.0f / deltaY;
- m[6] = 0.0f;
- m[7] = 0.0f;
-
- m[8] = 0.0f;
- m[9] = 0.0f;
- m[10] = 2.0f / deltaZ;
- m[11] = 0.0f;
- m[12] = -(right + left) / deltaX;
- m[13] = -(top + bottom) / deltaY;
- m[14] = -(near + far) / deltaZ;
- m[15] = 1.0f;
-}
-
-} // unnamed namespace
-
-const Dali::Camera::Type CameraAttachment::DEFAULT_TYPE( Dali::Camera::FREE_LOOK );
-const Dali::Camera::ProjectionMode CameraAttachment::DEFAULT_MODE( Dali::Camera::PERSPECTIVE_PROJECTION );
-const bool CameraAttachment::DEFAULT_INVERT_Y_AXIS( false );
-const float CameraAttachment::DEFAULT_FIELD_OF_VIEW( 45.0f*(M_PI/180.0f) );
-const float CameraAttachment::DEFAULT_ASPECT_RATIO( 4.0f/3.0f );
-const float CameraAttachment::DEFAULT_LEFT_CLIPPING_PLANE(-240.0f);
-const float CameraAttachment::DEFAULT_RIGHT_CLIPPING_PLANE(240.0f);
-const float CameraAttachment::DEFAULT_TOP_CLIPPING_PLANE(-400.0f);
-const float CameraAttachment::DEFAULT_BOTTOM_CLIPPING_PLANE(400.0f);
-const float CameraAttachment::DEFAULT_NEAR_CLIPPING_PLANE( 800.0f ); // default height of the screen
-const float CameraAttachment::DEFAULT_FAR_CLIPPING_PLANE( DEFAULT_NEAR_CLIPPING_PLANE + 2.f * DEFAULT_NEAR_CLIPPING_PLANE );
-const Vector2 CameraAttachment::DEFAULT_STEREO_BIAS( 0.0f, 0.0f );
-const Vector3 CameraAttachment::DEFAULT_TARGET_POSITION( 0.0f, 0.0f, 0.0f );
-
-
-CameraAttachment::CameraAttachment()
-: NodeAttachment(),
- mUpdateViewFlag( UPDATE_COUNT ),
- mUpdateProjectionFlag( UPDATE_COUNT ),
- mType( DEFAULT_TYPE ),
- mProjectionMode( DEFAULT_MODE ),
- mInvertYAxis( DEFAULT_INVERT_Y_AXIS ),
- mFieldOfView( DEFAULT_FIELD_OF_VIEW ),
- mAspectRatio( DEFAULT_ASPECT_RATIO ),
- mLeftClippingPlane( DEFAULT_LEFT_CLIPPING_PLANE ),
- mRightClippingPlane( DEFAULT_RIGHT_CLIPPING_PLANE ),
- mTopClippingPlane( DEFAULT_TOP_CLIPPING_PLANE ),
- mBottomClippingPlane( DEFAULT_BOTTOM_CLIPPING_PLANE ),
- mNearClippingPlane( DEFAULT_NEAR_CLIPPING_PLANE ),
- mFarClippingPlane( DEFAULT_FAR_CLIPPING_PLANE ),
- mStereoBias( DEFAULT_STEREO_BIAS ),
- mTargetPosition( DEFAULT_TARGET_POSITION ),
- mViewMatrix(),
- mProjectionMatrix(),
- mInverseViewProjection( Matrix::IDENTITY )
-{
-}
-
-CameraAttachment* CameraAttachment::New()
-{
- return new CameraAttachment();
-}
-
-void CameraAttachment::Initialize( SceneController& sceneController, BufferIndex updateBufferIndex )
-{
- // do nothing
-}
-
-void CameraAttachment::OnDestroy()
-{
- // do nothing
-}
-
-void CameraAttachment::ConnectedToSceneGraph()
-{
- // do nothing
-}
-
-void CameraAttachment::DisconnectedFromSceneGraph()
-{
- // do nothing
-}
-
-CameraAttachment::~CameraAttachment()
-{
-}
-
-void CameraAttachment::SetType( Dali::Camera::Type type )
-{
- mType = type;
-}
-
-void CameraAttachment::SetProjectionMode( Dali::Camera::ProjectionMode mode )
-{
- mProjectionMode = mode;
- mUpdateProjectionFlag = UPDATE_COUNT;
-}
-
-void CameraAttachment::SetInvertYAxis( bool invertYAxis )
-{
- mInvertYAxis = invertYAxis;
- mUpdateProjectionFlag = UPDATE_COUNT;
-}
-
-void CameraAttachment::SetFieldOfView( float fieldOfView )
-{
- mFieldOfView = fieldOfView;
- mUpdateProjectionFlag = UPDATE_COUNT;
-}
-
-void CameraAttachment::SetAspectRatio( float aspectRatio )
-{
- mAspectRatio = aspectRatio;
- mUpdateProjectionFlag = UPDATE_COUNT;
-}
-
-void CameraAttachment::SetStereoBias( const Vector2& stereoBias )
-{
- mStereoBias = stereoBias;
- mUpdateProjectionFlag = UPDATE_COUNT;
-}
-
-void CameraAttachment::SetLeftClippingPlane( float leftClippingPlane )
-{
- mLeftClippingPlane = leftClippingPlane;
- mUpdateProjectionFlag = UPDATE_COUNT;
-}
-
-void CameraAttachment::SetRightClippingPlane( float rightClippingPlane )
-{
- mRightClippingPlane = rightClippingPlane;
- mUpdateProjectionFlag = UPDATE_COUNT;
-}
-
-void CameraAttachment::SetTopClippingPlane( float topClippingPlane )
-{
- mTopClippingPlane = topClippingPlane;
- mUpdateProjectionFlag = UPDATE_COUNT;
-}
-
-void CameraAttachment::SetBottomClippingPlane( float bottomClippingPlane )
-{
- mBottomClippingPlane = bottomClippingPlane;
- mUpdateProjectionFlag = UPDATE_COUNT;
-}
-
-void CameraAttachment::SetNearClippingPlane( float nearClippingPlane )
-{
- mNearClippingPlane = nearClippingPlane;
- mUpdateProjectionFlag = UPDATE_COUNT;
-}
-
-void CameraAttachment::SetFarClippingPlane( float farClippingPlane )
-{
- mFarClippingPlane = farClippingPlane;
- mUpdateProjectionFlag = UPDATE_COUNT;
-}
-
-void CameraAttachment::SetTargetPosition( const Vector3& targetPosition )
-{
- mTargetPosition = targetPosition;
- mUpdateViewFlag = UPDATE_COUNT;
-}
-
-const Matrix& CameraAttachment::GetProjectionMatrix( BufferIndex bufferIndex ) const
-{
- return mProjectionMatrix[ bufferIndex ];
-}
-
-const Matrix& CameraAttachment::GetViewMatrix( BufferIndex bufferIndex ) const
-{
- return mViewMatrix[ bufferIndex ];
-}
-
-const Matrix& CameraAttachment::GetInverseViewProjectionMatrix( BufferIndex bufferIndex ) const
-{
- return mInverseViewProjection[ bufferIndex ];
-}
-
-const PropertyInputImpl* CameraAttachment::GetProjectionMatrix() const
-{
- return &mProjectionMatrix;
-}
-
-const PropertyInputImpl* CameraAttachment::GetViewMatrix() const
-{
- return &mViewMatrix;
-}
-
-void CameraAttachment::Update( BufferIndex updateBufferIndex, const Node& owningNode )
-{
- // if owning node has changes in world position we need to update camera for next 2 frames
- if( owningNode.IsLocalMatrixDirty() )
- {
- mUpdateViewFlag = UPDATE_COUNT;
- }
- if( owningNode.GetDirtyFlags() & VisibleFlag )
- {
- // If the visibility changes, the projection matrix needs to be re-calculated.
- // It may happen the first time an actor is rendered it's rendered only once and becomes invisible,
- // in the following update the node will be skipped leaving the projection matrix (double buffered)
- // with the Identity.
- mUpdateProjectionFlag = UPDATE_COUNT;
- }
-
- // if either matrix changed, we need to recalculate the inverse matrix for hit testing to work
- unsigned int viewUpdateCount = UpdateViewMatrix( updateBufferIndex, owningNode );
- unsigned int projectionUpdateCount = UpdateProjection( updateBufferIndex );
-
- // if model or view matrix changed we need to either recalculate the inverse VP or copy previous
- if( viewUpdateCount > COPY_PREVIOUS_MATRIX || projectionUpdateCount > COPY_PREVIOUS_MATRIX )
- {
- // either has actually changed so recalculate
- Matrix::Multiply( mInverseViewProjection[ updateBufferIndex ], mViewMatrix[ updateBufferIndex ], mProjectionMatrix[ updateBufferIndex ] );
- UpdateFrustum( updateBufferIndex );
-
- // ignore the error, if the view projection is incorrect (non inversible) then you will have tough times anyways
- static_cast< void >( mInverseViewProjection[ updateBufferIndex ].Invert() );
- }
- else if( viewUpdateCount == COPY_PREVIOUS_MATRIX || projectionUpdateCount == COPY_PREVIOUS_MATRIX )
- {
- // neither has actually changed, but we might copied previous frames value so need to
- // copy the previous inverse and frustum as well
- mInverseViewProjection[updateBufferIndex] = mInverseViewProjection[updateBufferIndex ? 0 : 1];
- mFrustum[ updateBufferIndex ] = mFrustum[ updateBufferIndex ? 0 : 1 ];
- }
-}
-
-bool CameraAttachment::ViewMatrixUpdated()
-{
- return 0u != mUpdateViewFlag;
-}
-
-unsigned int CameraAttachment::UpdateViewMatrix( BufferIndex updateBufferIndex, const Node& owningNode )
-{
- unsigned int retval( mUpdateViewFlag );
- if( 0u != mUpdateViewFlag )
- {
- if( COPY_PREVIOUS_MATRIX == mUpdateViewFlag )
- {
- // The projection matrix was updated in the previous frame; copy it
- mViewMatrix.CopyPrevious( updateBufferIndex );
- }
- else // UPDATE_COUNT == mUpdateViewFlag
- {
- switch( mType )
- {
- // camera orientation taken from node - i.e. look in abitrary, unconstrained direction
- case Dali::Camera::FREE_LOOK:
- {
- Matrix& viewMatrix = mViewMatrix.Get( updateBufferIndex );
- viewMatrix = owningNode.GetWorldMatrix(updateBufferIndex);
- viewMatrix.Invert();
- mViewMatrix.SetDirty( updateBufferIndex );
- break;
- }
- // camera orientation constrained to look at a target
- case Dali::Camera::LOOK_AT_TARGET:
- {
- const Matrix& owningNodeMatrix( owningNode.GetWorldMatrix(updateBufferIndex) );
- Vector3 position, scale;
- Quaternion orientation;
- owningNodeMatrix.GetTransformComponents( position, orientation, scale );
- Matrix& viewMatrix = mViewMatrix.Get( updateBufferIndex );
- LookAt( viewMatrix, position, mTargetPosition,
- orientation.Rotate( Vector3::YAXIS ) );
- mViewMatrix.SetDirty( updateBufferIndex );
- break;
- }
- }
- }
- --mUpdateViewFlag;
- }
- return retval;
-}
-
-void CameraAttachment::UpdateFrustum( BufferIndex updateBufferIndex, bool normalize )
-{
-
- // Extract the clip matrix planes
- Matrix clipMatrix;
- Matrix::Multiply( clipMatrix, mViewMatrix[ updateBufferIndex ], mProjectionMatrix[ updateBufferIndex ] );
-
- const float* cm = clipMatrix.AsFloat();
- FrustumPlanes& planes = mFrustum[ updateBufferIndex ];
-
- // Left
- planes.mPlanes[ 0 ].mNormal.x = cm[ 3 ] + cm[ 0 ]; // column 4 + column 1
- planes.mPlanes[ 0 ].mNormal.y = cm[ 7 ] + cm[ 4 ];
- planes.mPlanes[ 0 ].mNormal.z = cm[ 11 ] + cm[ 8 ];
- planes.mPlanes[ 0 ].mDistance = cm[ 15 ] + cm[ 12 ];
-
- // Right
- planes.mPlanes[ 1 ].mNormal.x = cm[ 3 ] - cm[ 0 ]; // column 4 - column 1
- planes.mPlanes[ 1 ].mNormal.y = cm[ 7 ] - cm[ 4 ];
- planes.mPlanes[ 1 ].mNormal.z = cm[ 11 ] - cm[ 8 ];
- planes.mPlanes[ 1 ].mDistance = cm[ 15 ] - cm[ 12 ];
-
- // Bottom
- planes.mPlanes[ 2 ].mNormal.x = cm[ 3 ] + cm[ 1 ]; // column 4 + column 2
- planes.mPlanes[ 2 ].mNormal.y = cm[ 7 ] + cm[ 5 ];
- planes.mPlanes[ 2 ].mNormal.z = cm[ 11 ] + cm[ 9 ];
- planes.mPlanes[ 2 ].mDistance = cm[ 15 ] + cm[ 13 ];
-
- // Top
- planes.mPlanes[ 3 ].mNormal.x = cm[ 3 ] - cm[ 1 ]; // column 4 - column 2
- planes.mPlanes[ 3 ].mNormal.y = cm[ 7 ] - cm[ 5 ];
- planes.mPlanes[ 3 ].mNormal.z = cm[ 11 ] - cm[ 9 ];
- planes.mPlanes[ 3 ].mDistance = cm[ 15 ] - cm[ 13 ];
-
- // Near
- planes.mPlanes[ 4 ].mNormal.x = cm[ 3 ] + cm[ 2 ]; // column 4 + column 3
- planes.mPlanes[ 4 ].mNormal.y = cm[ 7 ] + cm[ 6 ];
- planes.mPlanes[ 4 ].mNormal.z = cm[ 11 ] + cm[ 10 ];
- planes.mPlanes[ 4 ].mDistance = cm[ 15 ] + cm[ 14 ];
-
- // Far
- planes.mPlanes[ 5 ].mNormal.x = cm[ 3 ] - cm[ 2 ]; // column 4 - column 3
- planes.mPlanes[ 5 ].mNormal.y = cm[ 7 ] - cm[ 6 ];
- planes.mPlanes[ 5 ].mNormal.z = cm[ 11 ] - cm[ 10 ];
- planes.mPlanes[ 5 ].mDistance = cm[ 15 ] - cm[ 14 ];
-
- if ( normalize )
- {
- for ( unsigned int i = 0; i < 6; ++i )
- {
- // Normalize planes to ensure correct bounding distance checking
- Plane& plane = planes.mPlanes[ i ];
- float l = 1.0f / plane.mNormal.Length();
- plane.mNormal *= l;
- plane.mDistance *= l;
-
- planes.mSign[i] = Vector3( Sign(plane.mNormal.x), Sign(plane.mNormal.y), Sign(plane.mNormal.z) );
- }
- }
- else
- {
- for ( unsigned int i = 0; i < 6; ++i )
- {
- planes.mSign[i] = Vector3( Sign(planes.mPlanes[ i ].mNormal.x), Sign(planes.mPlanes[ i ].mNormal.y), Sign(planes.mPlanes[ i ].mNormal.z) );
- }
- }
- mFrustum[ updateBufferIndex ? 0 : 1 ] = planes;
-}
-
-bool CameraAttachment::CheckSphereInFrustum( BufferIndex bufferIndex, const Vector3& origin, float radius )
-{
- const FrustumPlanes& planes = mFrustum[ bufferIndex ];
- for ( uint32_t i = 0; i < 6; ++i )
- {
- if ( ( planes.mPlanes[ i ].mDistance + planes.mPlanes[ i ].mNormal.Dot( origin ) ) < -radius )
- {
- return false;
- }
- }
- return true;
-}
-
-bool CameraAttachment::CheckAABBInFrustum( BufferIndex bufferIndex, const Vector3& origin, const Vector3& halfExtents )
-{
- const FrustumPlanes& planes = mFrustum[ bufferIndex ];
- for ( uint32_t i = 0; i < 6; ++i )
- {
- if( planes.mPlanes[ i ].mNormal.Dot( origin + (halfExtents * planes.mSign[i]) ) > -(planes.mPlanes[ i ].mDistance) )
- {
- continue;
- }
-
- return false;
- }
- return true;
-}
-
-unsigned int CameraAttachment::UpdateProjection( BufferIndex updateBufferIndex )
-{
- unsigned int retval( mUpdateProjectionFlag );
- // Early-exit if no update required
- if ( 0u != mUpdateProjectionFlag )
- {
- if ( COPY_PREVIOUS_MATRIX == mUpdateProjectionFlag )
- {
- // The projection matrix was updated in the previous frame; copy it
- mProjectionMatrix.CopyPrevious( updateBufferIndex );
- }
- else // UPDATE_COUNT == mUpdateProjectionFlag
- {
- switch( mProjectionMode )
- {
- case Dali::Camera::PERSPECTIVE_PROJECTION:
- {
- Matrix &projectionMatrix = mProjectionMatrix.Get(updateBufferIndex);
- Perspective( projectionMatrix,
- mFieldOfView,
- mAspectRatio,
- mNearClippingPlane,
- mFarClippingPlane,
- mInvertYAxis,
- mStereoBias );
- break;
- }
- case Dali::Camera::ORTHOGRAPHIC_PROJECTION:
- {
- Matrix &projectionMatrix = mProjectionMatrix.Get(updateBufferIndex);
- Orthographic( projectionMatrix,
- mLeftClippingPlane, mRightClippingPlane,
- mBottomClippingPlane, mTopClippingPlane,
- mNearClippingPlane, mFarClippingPlane,
- mInvertYAxis );
- break;
- }
- }
-
- mProjectionMatrix.SetDirty(updateBufferIndex);
- }
- --mUpdateProjectionFlag;
- }
- return retval;
-}
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
+++ /dev/null
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// INTERNAL INCLUDES
-#include <dali/public-api/math/rect.h>
-#include <dali/public-api/actors/camera-actor.h>
-#include <dali/internal/common/message.h>
-#include <dali/internal/event/common/event-thread-services.h>
-#include <dali/internal/update/common/double-buffered.h>
-#include <dali/internal/update/node-attachments/node-attachment.h>
-#include <dali/internal/update/common/animatable-property.h>
-#include <dali/internal/update/common/inherited-property.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-// value types used by messages
-template <> struct ParameterType< Dali::Camera::Type >
-: public BasicType< Dali::Camera::Type > {};
-template <> struct ParameterType< Dali::Camera::ProjectionMode >
-: public BasicType< Dali::Camera::ProjectionMode > {};
-
-namespace SceneGraph
-{
-
-class SceneController;
-
-/**
- * An attachment for camera objects and their properties.
- */
-class CameraAttachment : public NodeAttachment
-{
-public:
- static const Dali::Camera::Type DEFAULT_TYPE;
- static const Dali::Camera::ProjectionMode DEFAULT_MODE;
- static const bool DEFAULT_INVERT_Y_AXIS;
- static const float DEFAULT_FIELD_OF_VIEW;
- static const float DEFAULT_ASPECT_RATIO;
- static const float DEFAULT_LEFT_CLIPPING_PLANE;
- static const float DEFAULT_RIGHT_CLIPPING_PLANE;
- static const float DEFAULT_TOP_CLIPPING_PLANE;
- static const float DEFAULT_BOTTOM_CLIPPING_PLANE;
- static const float DEFAULT_NEAR_CLIPPING_PLANE;
- static const float DEFAULT_FAR_CLIPPING_PLANE;
- static const Vector2 DEFAULT_STEREO_BIAS;
- static const Vector3 DEFAULT_TARGET_POSITION;
-
- /**
- * Plane equation container for a plane of the view frustum
- */
- struct Plane
- {
- Vector3 mNormal;
- float mDistance;
- };
-
- /**
- * @brief Container for six planes in a view frustum
- */
- struct FrustumPlanes
- {
- Plane mPlanes[ 6 ];
- Vector3 mSign[ 6 ];
- };
-
- /**
- * Construct a new CameraAttachment.
- * @return a new camera.
- */
- static CameraAttachment* New();
-
- /**
- * @copydoc NodeAttachment::Initialize().
- */
- virtual void Initialize( SceneController& sceneController, BufferIndex updateBufferIndex );
-
- /**
- * @copydoc NodeAttachment::OnDestroy().
- */
- virtual void OnDestroy();
-
- /**
- * @copydoc NodeAttachment::ConnectedToSceneGraph()
- */
- virtual void ConnectedToSceneGraph();
-
- /**
- * @copydoc NodeAttachment::DisconnectedFromSceneGraph()
- */
- virtual void DisconnectedFromSceneGraph();
-
- /**
- * Virtual destructor
- */
- virtual ~CameraAttachment();
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetType
- */
- void SetType( Dali::Camera::Type type );
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetInvertYAxis
- */
- void SetInvertYAxis( bool invertYAxis );
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetProjectionMode
- */
- void SetProjectionMode( Dali::Camera::ProjectionMode projectionMode );
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetFieldOfView
- */
- void SetFieldOfView( float fieldOfView );
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetAspectRatio
- */
- void SetAspectRatio( float aspectRatio );
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetStereoBias
- */
- void SetStereoBias(const Vector2& stereoBias);
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetLeftClippingPlane
- */
- void SetLeftClippingPlane( float leftClippingPlane );
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetRightClippingPlane
- */
- void SetRightClippingPlane( float rightClippingPlane );
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetTopClippingPlane
- */
- void SetTopClippingPlane( float topClippingPlane );
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetBottomClippingPlane
- */
- void SetBottomClippingPlane( float bottomClippingPlane );
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetNearClippingPlane
- */
- void SetNearClippingPlane( float nearClippingPlane );
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetFarClippingPlane
- */
- void SetFarClippingPlane( float farClippingPlane );
-
- /**
- * @copydoc Dali::Internal::CameraAttachment::SetTarget
- */
- void SetTargetPosition( const Vector3& targetPosition );
-
- /**
- * Get Camera Target
- */
- Vector3 GetTargetPosition() const;
-
- /**
- * Retrieve the view-matrix; this is double buffered for input handling.
- * @param[in] bufferIndex The buffer to read from.
- * @return The view-matrix.
- */
- const Matrix& GetViewMatrix( BufferIndex bufferIndex ) const;
-
- /**
- * @brief Check to see if a sphere lies within the view frustum.
- *
- * @param bufferIndex The buffer to read from.
- * @param origin The world position center of the sphere to check.
- * @param radius The length of the sphere radius in world scale.
- *
- * @return false if the sphere lies outside of the frustum.
- */
- bool CheckSphereInFrustum( BufferIndex bufferIndex, const Vector3& origin, float radius );
-
- /**
- * @brief Check to see if a bounding box lies within the view frustum.
- *
- * @param bufferIndex The buffer to read from.
- * @param origin the world position center of the cubeoid to check.
- * @param halfExtents The half length of the cubeoid in world co-ordinates in each axis.
- *
- * @return false if the cubeoid lies completely outside of the frustum, true otherwise
- */
- bool CheckAABBInFrustum( BufferIndex bufferIndex, const Vector3& origin, const Vector3& halfExtents );
-
- /**
- * Retrieve the projection-matrix; this is double buffered for input handling.
- * @param[in] bufferIndex The buffer to read from.
- * @return The projection-matrix.
- */
- const Matrix& GetProjectionMatrix( BufferIndex bufferIndex ) const;
-
- /**
- * Retrieve the inverted view-projection-matrix; this is double buffered for input handling.
- * @param[in] bufferIndex The buffer to read from.
- * @return The inverse view-projection-matrix.
- */
- const Matrix& GetInverseViewProjectionMatrix( BufferIndex bufferIndex ) const;
-
- /**
- * Retrieve the projection-matrix property querying interface.
- * @pre The attachment is on-stage.
- * @return The projection-matrix property querying interface.
- */
- const PropertyInputImpl* GetProjectionMatrix() const;
-
- /**
- * Retrieve the viewMatrix property querying interface.
- * @pre The attachment is on-stage.
- * @return The viewMatrix property querying interface.
- */
- const PropertyInputImpl* GetViewMatrix() const;
-
- /**
- * @copydoc NodeAttachment::Update
- */
- virtual void Update( BufferIndex updateBufferIndex, const Node& owningNode, int nodeDirtyFlags ){};
-
- /**
- * Updates view and projection matrices.
- * Called by the render task using the camera attachment
- * @param[in] updateBufferIndex The buffer to read from.
- * @param[in] owningNode The node that owns the camera
- */
- void Update( BufferIndex updateBufferIndex, const Node& owningNode );
-
- /**
- * @return true if the view matrix of camera is updated this or the previous frame
- */
- bool ViewMatrixUpdated();
-
-protected:
-
- /**
- * Protected constructor, see New().
- */
- CameraAttachment();
-
-private:
-
- // Undefined
- CameraAttachment(const CameraAttachment&);
-
- // Undefined
- CameraAttachment& operator=(const CameraAttachment& rhs);
-
- /**
- * Recalculates the view matrix.
- * @param[in] bufferIndex The current update buffer index.
- * @param[in] owningNode to use for calculations.
- * @return count how many frames ago the matrix was changed.
- */
- unsigned int UpdateViewMatrix( BufferIndex updateBufferIndex, const Node& owningNode );
-
- /**
- * Recalculates the projection matrix.
- * @param[in] bufferIndex The current update buffer index.
- * @return count how many frames ago the matrix was changed.
- */
- unsigned int UpdateProjection( BufferIndex updateBufferIndex );
-
-private:
-
- /**
- * @brief Extracts the frustum planes.
- *
- * @param[in] bufferIndex The current update buffer index.
- * @param[in] normalize will normalize plane equation coefficients by default.
- */
- void UpdateFrustum( BufferIndex updateBufferIndex, bool normalize = true );
-
-
- unsigned int mUpdateViewFlag; ///< This is non-zero if the view matrix requires an update
- unsigned int mUpdateProjectionFlag; ///< This is non-zero if the projection matrix requires an update
-
-public: // PROPERTIES
- Dali::Camera::Type mType; // Non-animatable
- Dali::Camera::ProjectionMode mProjectionMode; // Non-animatable
- bool mInvertYAxis; // Non-animatable
-
- float mFieldOfView;
- float mAspectRatio;
- float mLeftClippingPlane;
- float mRightClippingPlane;
- float mTopClippingPlane;
- float mBottomClippingPlane;
- float mNearClippingPlane;
- float mFarClippingPlane;
- Vector2 mStereoBias;
- Vector3 mTargetPosition;
-
- InheritedMatrix mViewMatrix; ///< The viewMatrix; this is double buffered for input handling.
- InheritedMatrix mProjectionMatrix; ///< The projectionMatrix; this is double buffered for input handling.
-
- DoubleBuffered< FrustumPlanes > mFrustum; ///< Clipping frustum; double buffered for input handling
- DoubleBuffered< Matrix > mInverseViewProjection; ///< Inverted viewprojection; double buffered for input handling
-
-};
-
-// Messages for CameraAttachment
-
-inline void SetTypeMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, Dali::Camera::Type parameter )
-{
- typedef MessageValue1< CameraAttachment, Dali::Camera::Type > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &CameraAttachment::SetType, parameter );
-}
-
-inline void SetProjectionModeMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, Dali::Camera::ProjectionMode parameter )
-{
- typedef MessageValue1< CameraAttachment, Dali::Camera::ProjectionMode > LocalProjectionMode;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalProjectionMode ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalProjectionMode( &attachment, &CameraAttachment::SetProjectionMode, parameter );
-}
-
-
-inline void SetFieldOfViewMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
-{
- typedef MessageValue1< CameraAttachment, float > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &CameraAttachment::SetFieldOfView, parameter );
-}
-
-inline void SetAspectRatioMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
-{
- typedef MessageValue1< CameraAttachment, float > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &CameraAttachment::SetAspectRatio, parameter );
-}
-
-inline void SetStereoBiasMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, const Vector2& parameter )
-{
- typedef MessageValue1< CameraAttachment, Vector2 > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &CameraAttachment::SetStereoBias, parameter );
-}
-
-inline void SetLeftClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
-{
- typedef MessageValue1< CameraAttachment, float > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &CameraAttachment::SetLeftClippingPlane, parameter );
-}
-
-inline void SetRightClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
-{
- typedef MessageValue1< CameraAttachment, float > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &CameraAttachment::SetRightClippingPlane, parameter );
-}
-
-inline void SetTopClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
-{
- typedef MessageValue1< CameraAttachment, float > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &CameraAttachment::SetTopClippingPlane, parameter );
-}
-
-inline void SetBottomClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
-{
- typedef MessageValue1< CameraAttachment, float > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &CameraAttachment::SetBottomClippingPlane, parameter );
-}
-
-inline void SetNearClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
-{
- typedef MessageValue1< CameraAttachment, float > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &CameraAttachment::SetNearClippingPlane, parameter );
-}
-
-inline void SetFarClippingPlaneMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, float parameter )
-{
- typedef MessageValue1< CameraAttachment, float > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &CameraAttachment::SetFarClippingPlane, parameter );
-}
-
-inline void SetTargetPositionMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, const Vector3& parameter )
-{
- typedef MessageValue1< CameraAttachment, Vector3 > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &CameraAttachment::SetTargetPosition, parameter );
-}
-
-
-inline void SetInvertYAxisMessage( EventThreadServices& eventThreadServices, const CameraAttachment& attachment, bool parameter )
-{
- typedef MessageValue1< CameraAttachment, bool > LocalType;
-
- // Reserve some memory inside the message queue
- unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
-
- // Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &CameraAttachment::SetInvertYAxis, parameter );
-}
-
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
-
-#endif // __DALI_INTERNAL_SCENE_GRAPH_CAMERA_ATTACHMENT_H__
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
// INTERNAL INCLUDES
#include <dali/internal/common/internal-constants.h>
#include <dali/internal/common/memory-pool-object-allocator.h>
-#include <dali/internal/update/node-attachments/node-attachment.h>
#include <dali/internal/update/common/discard-queue.h>
#include <dali/public-api/common/dali-common.h>
#include <dali/public-api/common/constants.h>
mWorldColor( Color::WHITE ),
mParent( NULL ),
mExclusiveRenderTask( NULL ),
- mAttachment( NULL ),
mChildren(),
mRegenerateUniformMap( 0 ),
mDepth(0u),
void Node::OnDestroy()
{
- // Node attachments should be notified about the disconnection.
- if ( mAttachment )
- {
- mAttachment->OnDestroy();
- }
-
// Animators, Constraints etc. should be disconnected from the child's properties.
PropertyOwner::Destroy();
}
mWorldMatrix.Initialize( transformManager, mTransformId );
}
-void Node::Attach( NodeAttachment& object )
-{
- DALI_ASSERT_DEBUG(!mAttachment);
-
- object.SetParent(*this);
-
- mAttachment = &object;
- SetAllDirtyFlags();
-
- mAttachment->ConnectedToSceneGraph();
-}
-
void Node::SetRoot(bool isRoot)
{
DALI_ASSERT_DEBUG(!isRoot || mParent == NULL); // Root nodes cannot have a parent
// Inform property observers of new connection
childNode->ConnectToSceneGraph();
-
- // Inform child node attachment that the node has been added to the stage
- if( childNode->mAttachment )
- {
- childNode->mAttachment->ConnectedToSceneGraph();
- }
}
void Node::DisconnectChild( BufferIndex updateBufferIndex, Node& childNode )
// Remove all child pointers
mChildren.Clear();
- // Inform child node attachment that the node has been removed from the stage
- if( mAttachment )
- {
- mAttachment->DisconnectedFromSceneGraph();
- }
-
if( mTransformId != INVALID_TRANSFORM_ID )
{
mTransformManager->SetParent( mTransformId, INVALID_TRANSFORM_ID );
#define __DALI_INTERNAL_SCENE_GRAPH_NODE_H__
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <dali/internal/update/manager/transform-manager.h>
#include <dali/internal/update/manager/transform-manager-property.h>
#include <dali/internal/update/nodes/node-declarations.h>
-#include <dali/internal/update/node-attachments/node-attachment-declarations.h>
#include <dali/internal/update/rendering/scene-graph-renderer.h>
namespace Dali
class DiscardQueue;
class Layer;
-class NodeAttachment;
class RenderTask;
class UpdateManager;
static const int AllFlags = ( ChildDeletedFlag << 1 ) - 1; // all the flags
/**
- * Size is not inherited.
- * VisibleFlag is inherited so that attachments can be synchronized with nodes after they become visible
+ * Size is not inherited. VisibleFlag is inherited
*/
static const int InheritedDirtyFlags = TransformFlag | VisibleFlag | ColorFlag | OverlayFlag;
return NULL;
}
- // Attachments
-
- /**
- * Attach an object to this Node; This should only be done by UpdateManager::AttachToNode.
- * @pre The Node does not already have an attachment.
- * @param[in] attachment The object to attach.
- */
- void Attach( NodeAttachment& attachment );
-
- /**
- * Query the node if it has an attachment.
- * @return True if it has an attachment.
- */
- bool HasAttachment() const
- {
- return mAttachment;
- }
-
/**
* Add a renderer to the node
* @param[in] renderer The renderer added to the node
return mRenderer.Size();
}
- /**
- * Retreive the object attached to this node.
- * @return The attachment.
- */
- NodeAttachment& GetAttachment() const
- {
- return *mAttachment;
- }
-
// Containment methods
/**
Node* mParent; ///< Pointer to parent node (a child is owned by its parent)
RenderTask* mExclusiveRenderTask; ///< Nodes can be marked as exclusive to a single RenderTask
- NodeAttachmentOwner mAttachment; ///< Optional owned attachment
RendererContainer mRenderer; ///< Container of renderers; not owned
NodeContainer mChildren; ///< Container of children; not owned
#define __DALI_INTERNAL_SCENE_GRAPH_LAYER_H__
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
namespace SceneGraph
{
+class Camera;
/**
* Pair of node-renderer
/**
* Layers have a "depth" relative to all other layers in the scene-graph.
- * Non-layer child nodes (and their attachments) are considered part of the layer.
+ * Non-layer child nodes are considered part of the layer.
*
- * Layers are rendered separately, and the depth buffer is cleared before each layer is rendered.
+ * Layers are rendered separately, and by default the depth buffer is cleared before each layer is rendered.
* Objects in higher layers, are rendered after (in front of) objects in lower layers.
*/
class Layer : public Node
* to use is the same than the one used before ( Otherwise View transform will be different )
*
*/
- bool CanReuseRenderers(Node* camera)
+ bool CanReuseRenderers( Camera* camera )
{
bool bReturn( mAllChildTransformsClean[ 0 ] && mAllChildTransformsClean[ 1 ] && camera == mLastCamera );
mLastCamera = camera;
SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
ClippingBox mClippingBox; ///< The clipping box, in window coordinates
- Node* mLastCamera; ///< Pointer to the last camera that has rendered the layer
+ Camera* mLastCamera; ///< Pointer to the last camera that has rendered the layer
Dali::Layer::Behavior mBehavior; ///< The behavior of the layer
--- /dev/null
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali/internal/update/render-tasks/scene-graph-camera.h>
+
+// EXTERNAL INCLUDES
+#include <stdint.h>
+
+// INTERNAL INCLUDES
+#include <dali/integration-api/debug.h>
+#include <dali/public-api/common/dali-common.h>
+#include <dali/public-api/math/math-utils.h>
+#include <dali/internal/update/nodes/node.h>
+
+namespace // unnamed namespace
+{
+const unsigned int UPDATE_COUNT = 2u; // Update projection or view matrix this many frames after a change
+const unsigned int COPY_PREVIOUS_MATRIX = 1u; // Copy view or projection matrix from previous frame
+}
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+namespace SceneGraph
+{
+
+namespace
+{
+
+void LookAt(Matrix& result, const Vector3& eye, const Vector3& target, const Vector3& up)
+{
+ Vector3 vZ = target - eye;
+ vZ.Normalize();
+
+ Vector3 vX = up.Cross(vZ);
+ vX.Normalize();
+
+ Vector3 vY = vZ.Cross(vX);
+ vY.Normalize();
+
+ result.SetInverseTransformComponents(vX, vY, vZ, eye);
+}
+
+
+void Frustum(Matrix& result, float left, float right, float bottom, float top, float near, float far, bool invertYAxis)
+{
+ float deltaZ = far - near;
+ if ((near <= 0.0f) || (far <= 0.0f) || Equals(right, left) || Equals(bottom, top) || (deltaZ <= 0.0f))
+ {
+ DALI_LOG_ERROR("Invalid parameters passed into Frustum!");
+ DALI_ASSERT_DEBUG("Invalid parameters passed into Frustum!");
+ return;
+ }
+
+ float deltaX = right - left;
+ float deltaY = invertYAxis ? bottom - top : top - bottom;
+
+ result.SetIdentity();
+
+ float* m = result.AsFloat();
+ m[0] = -2.0f * near / deltaX;
+ m[1] = m[2] = m[3] = 0.0f;
+
+ m[5] = -2.0f * near / deltaY;
+ m[4] = m[6] = m[7] = 0.0f;
+
+ m[8] = (right + left) / deltaX;
+ m[9] = (top + bottom) / deltaY;
+ m[10] = (near + far) / deltaZ;
+ m[11] = 1.0f;
+
+ m[14] = -2.0f * near * far / deltaZ;
+ m[12] = m[13] = m[15] = 0.0f;
+}
+
+void Perspective(Matrix& result, float fovy, float aspect, float near, float far, bool invertYAxis, const Vector2& stereoBias )
+{
+ float frustumH = tanf( fovy * 0.5f ) * near;
+ float frustumW = frustumH * aspect;
+ Vector2 bias = stereoBias * 0.5f;
+
+ Frustum(result, -(frustumW + bias.x), frustumW - bias.x, -(frustumH + bias.y), frustumH - bias.y, near, far, invertYAxis);
+}
+
+void Orthographic(Matrix& result, float left, float right, float bottom, float top, float near, float far, bool invertYAxis)
+{
+ if ( Equals(right, left) || Equals(top, bottom) || Equals(far, near) )
+ {
+ DALI_LOG_ERROR( "Cannot create orthographic projection matrix with a zero dimension." );
+ DALI_ASSERT_DEBUG( "Cannot create orthographic projection matrix with a zero dimension." );
+ return;
+ }
+
+ float deltaX = right - left;
+ float deltaY = invertYAxis ? bottom - top : top - bottom;
+ float deltaZ = far - near;
+
+ float *m = result.AsFloat();
+ m[0] = -2.0f / deltaX;
+ m[1] = 0.0f;
+ m[2] = 0.0f;
+ m[3] = 0.0f;
+
+ m[4] = 0.0f;
+ m[5] = -2.0f / deltaY;
+ m[6] = 0.0f;
+ m[7] = 0.0f;
+
+ m[8] = 0.0f;
+ m[9] = 0.0f;
+ m[10] = 2.0f / deltaZ;
+ m[11] = 0.0f;
+ m[12] = -(right + left) / deltaX;
+ m[13] = -(top + bottom) / deltaY;
+ m[14] = -(near + far) / deltaZ;
+ m[15] = 1.0f;
+}
+
+} // unnamed namespace
+
+const Dali::Camera::Type Camera::DEFAULT_TYPE( Dali::Camera::FREE_LOOK );
+const Dali::Camera::ProjectionMode Camera::DEFAULT_MODE( Dali::Camera::PERSPECTIVE_PROJECTION );
+const bool Camera::DEFAULT_INVERT_Y_AXIS( false );
+const float Camera::DEFAULT_FIELD_OF_VIEW( 45.0f*(M_PI/180.0f) );
+const float Camera::DEFAULT_ASPECT_RATIO( 4.0f/3.0f );
+const float Camera::DEFAULT_LEFT_CLIPPING_PLANE(-240.0f);
+const float Camera::DEFAULT_RIGHT_CLIPPING_PLANE(240.0f);
+const float Camera::DEFAULT_TOP_CLIPPING_PLANE(-400.0f);
+const float Camera::DEFAULT_BOTTOM_CLIPPING_PLANE(400.0f);
+const float Camera::DEFAULT_NEAR_CLIPPING_PLANE( 800.0f ); // default height of the screen
+const float Camera::DEFAULT_FAR_CLIPPING_PLANE( DEFAULT_NEAR_CLIPPING_PLANE + 2.f * DEFAULT_NEAR_CLIPPING_PLANE );
+const Vector2 Camera::DEFAULT_STEREO_BIAS( 0.0f, 0.0f );
+const Vector3 Camera::DEFAULT_TARGET_POSITION( 0.0f, 0.0f, 0.0f );
+
+
+Camera::Camera()
+: mUpdateViewFlag( UPDATE_COUNT ),
+ mUpdateProjectionFlag( UPDATE_COUNT ),
+ mType( DEFAULT_TYPE ),
+ mProjectionMode( DEFAULT_MODE ),
+ mInvertYAxis( DEFAULT_INVERT_Y_AXIS ),
+ mFieldOfView( DEFAULT_FIELD_OF_VIEW ),
+ mAspectRatio( DEFAULT_ASPECT_RATIO ),
+ mLeftClippingPlane( DEFAULT_LEFT_CLIPPING_PLANE ),
+ mRightClippingPlane( DEFAULT_RIGHT_CLIPPING_PLANE ),
+ mTopClippingPlane( DEFAULT_TOP_CLIPPING_PLANE ),
+ mBottomClippingPlane( DEFAULT_BOTTOM_CLIPPING_PLANE ),
+ mNearClippingPlane( DEFAULT_NEAR_CLIPPING_PLANE ),
+ mFarClippingPlane( DEFAULT_FAR_CLIPPING_PLANE ),
+ mStereoBias( DEFAULT_STEREO_BIAS ),
+ mTargetPosition( DEFAULT_TARGET_POSITION ),
+ mViewMatrix(),
+ mProjectionMatrix(),
+ mInverseViewProjection( Matrix::IDENTITY )
+{
+}
+
+Camera* Camera::New()
+{
+ return new Camera();
+}
+
+Camera::~Camera()
+{
+}
+
+void Camera::SetType( Dali::Camera::Type type )
+{
+ mType = type;
+}
+
+void Camera::SetProjectionMode( Dali::Camera::ProjectionMode mode )
+{
+ mProjectionMode = mode;
+ mUpdateProjectionFlag = UPDATE_COUNT;
+}
+
+void Camera::SetInvertYAxis( bool invertYAxis )
+{
+ mInvertYAxis = invertYAxis;
+ mUpdateProjectionFlag = UPDATE_COUNT;
+}
+
+void Camera::SetFieldOfView( float fieldOfView )
+{
+ mFieldOfView = fieldOfView;
+ mUpdateProjectionFlag = UPDATE_COUNT;
+}
+
+void Camera::SetAspectRatio( float aspectRatio )
+{
+ mAspectRatio = aspectRatio;
+ mUpdateProjectionFlag = UPDATE_COUNT;
+}
+
+void Camera::SetStereoBias( const Vector2& stereoBias )
+{
+ mStereoBias = stereoBias;
+ mUpdateProjectionFlag = UPDATE_COUNT;
+}
+
+void Camera::SetLeftClippingPlane( float leftClippingPlane )
+{
+ mLeftClippingPlane = leftClippingPlane;
+ mUpdateProjectionFlag = UPDATE_COUNT;
+}
+
+void Camera::SetRightClippingPlane( float rightClippingPlane )
+{
+ mRightClippingPlane = rightClippingPlane;
+ mUpdateProjectionFlag = UPDATE_COUNT;
+}
+
+void Camera::SetTopClippingPlane( float topClippingPlane )
+{
+ mTopClippingPlane = topClippingPlane;
+ mUpdateProjectionFlag = UPDATE_COUNT;
+}
+
+void Camera::SetBottomClippingPlane( float bottomClippingPlane )
+{
+ mBottomClippingPlane = bottomClippingPlane;
+ mUpdateProjectionFlag = UPDATE_COUNT;
+}
+
+void Camera::SetNearClippingPlane( float nearClippingPlane )
+{
+ mNearClippingPlane = nearClippingPlane;
+ mUpdateProjectionFlag = UPDATE_COUNT;
+}
+
+void Camera::SetFarClippingPlane( float farClippingPlane )
+{
+ mFarClippingPlane = farClippingPlane;
+ mUpdateProjectionFlag = UPDATE_COUNT;
+}
+
+void Camera::SetTargetPosition( const Vector3& targetPosition )
+{
+ mTargetPosition = targetPosition;
+ mUpdateViewFlag = UPDATE_COUNT;
+}
+
+const Matrix& Camera::GetProjectionMatrix( BufferIndex bufferIndex ) const
+{
+ return mProjectionMatrix[ bufferIndex ];
+}
+
+const Matrix& Camera::GetViewMatrix( BufferIndex bufferIndex ) const
+{
+ return mViewMatrix[ bufferIndex ];
+}
+
+const Matrix& Camera::GetInverseViewProjectionMatrix( BufferIndex bufferIndex ) const
+{
+ return mInverseViewProjection[ bufferIndex ];
+}
+
+const PropertyInputImpl* Camera::GetProjectionMatrix() const
+{
+ return &mProjectionMatrix;
+}
+
+const PropertyInputImpl* Camera::GetViewMatrix() const
+{
+ return &mViewMatrix;
+}
+
+void Camera::Update( BufferIndex updateBufferIndex, const Node& owningNode )
+{
+ // if owning node has changes in world position we need to update camera for next 2 frames
+ if( owningNode.IsLocalMatrixDirty() )
+ {
+ mUpdateViewFlag = UPDATE_COUNT;
+ }
+ if( owningNode.GetDirtyFlags() & VisibleFlag )
+ {
+ // If the visibility changes, the projection matrix needs to be re-calculated.
+ // It may happen the first time an actor is rendered it's rendered only once and becomes invisible,
+ // in the following update the node will be skipped leaving the projection matrix (double buffered)
+ // with the Identity.
+ mUpdateProjectionFlag = UPDATE_COUNT;
+ }
+
+ // if either matrix changed, we need to recalculate the inverse matrix for hit testing to work
+ unsigned int viewUpdateCount = UpdateViewMatrix( updateBufferIndex, owningNode );
+ unsigned int projectionUpdateCount = UpdateProjection( updateBufferIndex );
+
+ // if model or view matrix changed we need to either recalculate the inverse VP or copy previous
+ if( viewUpdateCount > COPY_PREVIOUS_MATRIX || projectionUpdateCount > COPY_PREVIOUS_MATRIX )
+ {
+ // either has actually changed so recalculate
+ Matrix::Multiply( mInverseViewProjection[ updateBufferIndex ], mViewMatrix[ updateBufferIndex ], mProjectionMatrix[ updateBufferIndex ] );
+ UpdateFrustum( updateBufferIndex );
+
+ // ignore the error, if the view projection is incorrect (non inversible) then you will have tough times anyways
+ static_cast< void >( mInverseViewProjection[ updateBufferIndex ].Invert() );
+ }
+ else if( viewUpdateCount == COPY_PREVIOUS_MATRIX || projectionUpdateCount == COPY_PREVIOUS_MATRIX )
+ {
+ // neither has actually changed, but we might copied previous frames value so need to
+ // copy the previous inverse and frustum as well
+ mInverseViewProjection[updateBufferIndex] = mInverseViewProjection[updateBufferIndex ? 0 : 1];
+ mFrustum[ updateBufferIndex ] = mFrustum[ updateBufferIndex ? 0 : 1 ];
+ }
+}
+
+bool Camera::ViewMatrixUpdated()
+{
+ return 0u != mUpdateViewFlag;
+}
+
+unsigned int Camera::UpdateViewMatrix( BufferIndex updateBufferIndex, const Node& owningNode )
+{
+ unsigned int retval( mUpdateViewFlag );
+ if( 0u != mUpdateViewFlag )
+ {
+ if( COPY_PREVIOUS_MATRIX == mUpdateViewFlag )
+ {
+ // The projection matrix was updated in the previous frame; copy it
+ mViewMatrix.CopyPrevious( updateBufferIndex );
+ }
+ else // UPDATE_COUNT == mUpdateViewFlag
+ {
+ switch( mType )
+ {
+ // camera orientation taken from node - i.e. look in abitrary, unconstrained direction
+ case Dali::Camera::FREE_LOOK:
+ {
+ Matrix& viewMatrix = mViewMatrix.Get( updateBufferIndex );
+ viewMatrix = owningNode.GetWorldMatrix( updateBufferIndex );
+ viewMatrix.Invert();
+ mViewMatrix.SetDirty( updateBufferIndex );
+ break;
+ }
+ // camera orientation constrained to look at a target
+ case Dali::Camera::LOOK_AT_TARGET:
+ {
+ const Matrix& owningNodeMatrix( owningNode.GetWorldMatrix( updateBufferIndex ) );
+ Vector3 position, scale;
+ Quaternion orientation;
+ owningNodeMatrix.GetTransformComponents( position, orientation, scale );
+ Matrix& viewMatrix = mViewMatrix.Get( updateBufferIndex );
+ LookAt( viewMatrix, position, mTargetPosition, orientation.Rotate( Vector3::YAXIS ) );
+ mViewMatrix.SetDirty( updateBufferIndex );
+ break;
+ }
+ }
+ }
+ --mUpdateViewFlag;
+ }
+ return retval;
+}
+
+void Camera::UpdateFrustum( BufferIndex updateBufferIndex, bool normalize )
+{
+
+ // Extract the clip matrix planes
+ Matrix clipMatrix;
+ Matrix::Multiply( clipMatrix, mViewMatrix[ updateBufferIndex ], mProjectionMatrix[ updateBufferIndex ] );
+
+ const float* cm = clipMatrix.AsFloat();
+ FrustumPlanes& planes = mFrustum[ updateBufferIndex ];
+
+ // Left
+ planes.mPlanes[ 0 ].mNormal.x = cm[ 3 ] + cm[ 0 ]; // column 4 + column 1
+ planes.mPlanes[ 0 ].mNormal.y = cm[ 7 ] + cm[ 4 ];
+ planes.mPlanes[ 0 ].mNormal.z = cm[ 11 ] + cm[ 8 ];
+ planes.mPlanes[ 0 ].mDistance = cm[ 15 ] + cm[ 12 ];
+
+ // Right
+ planes.mPlanes[ 1 ].mNormal.x = cm[ 3 ] - cm[ 0 ]; // column 4 - column 1
+ planes.mPlanes[ 1 ].mNormal.y = cm[ 7 ] - cm[ 4 ];
+ planes.mPlanes[ 1 ].mNormal.z = cm[ 11 ] - cm[ 8 ];
+ planes.mPlanes[ 1 ].mDistance = cm[ 15 ] - cm[ 12 ];
+
+ // Bottom
+ planes.mPlanes[ 2 ].mNormal.x = cm[ 3 ] + cm[ 1 ]; // column 4 + column 2
+ planes.mPlanes[ 2 ].mNormal.y = cm[ 7 ] + cm[ 5 ];
+ planes.mPlanes[ 2 ].mNormal.z = cm[ 11 ] + cm[ 9 ];
+ planes.mPlanes[ 2 ].mDistance = cm[ 15 ] + cm[ 13 ];
+
+ // Top
+ planes.mPlanes[ 3 ].mNormal.x = cm[ 3 ] - cm[ 1 ]; // column 4 - column 2
+ planes.mPlanes[ 3 ].mNormal.y = cm[ 7 ] - cm[ 5 ];
+ planes.mPlanes[ 3 ].mNormal.z = cm[ 11 ] - cm[ 9 ];
+ planes.mPlanes[ 3 ].mDistance = cm[ 15 ] - cm[ 13 ];
+
+ // Near
+ planes.mPlanes[ 4 ].mNormal.x = cm[ 3 ] + cm[ 2 ]; // column 4 + column 3
+ planes.mPlanes[ 4 ].mNormal.y = cm[ 7 ] + cm[ 6 ];
+ planes.mPlanes[ 4 ].mNormal.z = cm[ 11 ] + cm[ 10 ];
+ planes.mPlanes[ 4 ].mDistance = cm[ 15 ] + cm[ 14 ];
+
+ // Far
+ planes.mPlanes[ 5 ].mNormal.x = cm[ 3 ] - cm[ 2 ]; // column 4 - column 3
+ planes.mPlanes[ 5 ].mNormal.y = cm[ 7 ] - cm[ 6 ];
+ planes.mPlanes[ 5 ].mNormal.z = cm[ 11 ] - cm[ 10 ];
+ planes.mPlanes[ 5 ].mDistance = cm[ 15 ] - cm[ 14 ];
+
+ if ( normalize )
+ {
+ for ( unsigned int i = 0; i < 6; ++i )
+ {
+ // Normalize planes to ensure correct bounding distance checking
+ Plane& plane = planes.mPlanes[ i ];
+ float l = 1.0f / plane.mNormal.Length();
+ plane.mNormal *= l;
+ plane.mDistance *= l;
+
+ planes.mSign[i] = Vector3( Sign(plane.mNormal.x), Sign(plane.mNormal.y), Sign(plane.mNormal.z) );
+ }
+ }
+ else
+ {
+ for ( unsigned int i = 0; i < 6; ++i )
+ {
+ planes.mSign[i] = Vector3( Sign(planes.mPlanes[ i ].mNormal.x), Sign(planes.mPlanes[ i ].mNormal.y), Sign(planes.mPlanes[ i ].mNormal.z) );
+ }
+ }
+ mFrustum[ updateBufferIndex ? 0 : 1 ] = planes;
+}
+
+bool Camera::CheckSphereInFrustum( BufferIndex bufferIndex, const Vector3& origin, float radius )
+{
+ const FrustumPlanes& planes = mFrustum[ bufferIndex ];
+ for ( uint32_t i = 0; i < 6; ++i )
+ {
+ if ( ( planes.mPlanes[ i ].mDistance + planes.mPlanes[ i ].mNormal.Dot( origin ) ) < -radius )
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool Camera::CheckAABBInFrustum( BufferIndex bufferIndex, const Vector3& origin, const Vector3& halfExtents )
+{
+ const FrustumPlanes& planes = mFrustum[ bufferIndex ];
+ for ( uint32_t i = 0; i < 6; ++i )
+ {
+ if( planes.mPlanes[ i ].mNormal.Dot( origin + (halfExtents * planes.mSign[i]) ) > -(planes.mPlanes[ i ].mDistance) )
+ {
+ continue;
+ }
+
+ return false;
+ }
+ return true;
+}
+
+unsigned int Camera::UpdateProjection( BufferIndex updateBufferIndex )
+{
+ unsigned int retval( mUpdateProjectionFlag );
+ // Early-exit if no update required
+ if ( 0u != mUpdateProjectionFlag )
+ {
+ if ( COPY_PREVIOUS_MATRIX == mUpdateProjectionFlag )
+ {
+ // The projection matrix was updated in the previous frame; copy it
+ mProjectionMatrix.CopyPrevious( updateBufferIndex );
+ }
+ else // UPDATE_COUNT == mUpdateProjectionFlag
+ {
+ switch( mProjectionMode )
+ {
+ case Dali::Camera::PERSPECTIVE_PROJECTION:
+ {
+ Matrix &projectionMatrix = mProjectionMatrix.Get( updateBufferIndex );
+ Perspective( projectionMatrix,
+ mFieldOfView,
+ mAspectRatio,
+ mNearClippingPlane,
+ mFarClippingPlane,
+ mInvertYAxis,
+ mStereoBias );
+ break;
+ }
+ case Dali::Camera::ORTHOGRAPHIC_PROJECTION:
+ {
+ Matrix &projectionMatrix = mProjectionMatrix.Get( updateBufferIndex );
+ Orthographic( projectionMatrix,
+ mLeftClippingPlane, mRightClippingPlane,
+ mBottomClippingPlane, mTopClippingPlane,
+ mNearClippingPlane, mFarClippingPlane,
+ mInvertYAxis );
+ break;
+ }
+ }
+
+ mProjectionMatrix.SetDirty( updateBufferIndex );
+ }
+ --mUpdateProjectionFlag;
+ }
+ return retval;
+}
+
+} // namespace SceneGraph
+
+} // namespace Internal
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_INTERNAL_SCENE_GRAPH_CAMERA_H__
+#define __DALI_INTERNAL_SCENE_GRAPH_CAMERA_H__
+
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// INTERNAL INCLUDES
+#include <dali/public-api/math/rect.h>
+#include <dali/public-api/actors/camera-actor.h>
+#include <dali/internal/common/message.h>
+#include <dali/internal/event/common/event-thread-services.h>
+#include <dali/internal/update/common/double-buffered.h>
+#include <dali/internal/update/common/inherited-property.h>
+
+namespace Dali
+{
+
+namespace Internal
+{
+
+// value types used by messages
+template <> struct ParameterType< Dali::Camera::Type >
+: public BasicType< Dali::Camera::Type > {};
+template <> struct ParameterType< Dali::Camera::ProjectionMode >
+: public BasicType< Dali::Camera::ProjectionMode > {};
+
+namespace SceneGraph
+{
+
+class Node;
+class SceneController;
+
+/**
+ * Scene-graph camera object
+ */
+class Camera
+{
+public:
+ static const Dali::Camera::Type DEFAULT_TYPE;
+ static const Dali::Camera::ProjectionMode DEFAULT_MODE;
+ static const bool DEFAULT_INVERT_Y_AXIS;
+ static const float DEFAULT_FIELD_OF_VIEW;
+ static const float DEFAULT_ASPECT_RATIO;
+ static const float DEFAULT_LEFT_CLIPPING_PLANE;
+ static const float DEFAULT_RIGHT_CLIPPING_PLANE;
+ static const float DEFAULT_TOP_CLIPPING_PLANE;
+ static const float DEFAULT_BOTTOM_CLIPPING_PLANE;
+ static const float DEFAULT_NEAR_CLIPPING_PLANE;
+ static const float DEFAULT_FAR_CLIPPING_PLANE;
+ static const Vector2 DEFAULT_STEREO_BIAS;
+ static const Vector3 DEFAULT_TARGET_POSITION;
+
+ /**
+ * Plane equation container for a plane of the view frustum
+ */
+ struct Plane
+ {
+ Vector3 mNormal;
+ float mDistance;
+ };
+
+ /**
+ * @brief Container for six planes in a view frustum
+ */
+ struct FrustumPlanes
+ {
+ Plane mPlanes[ 6 ];
+ Vector3 mSign[ 6 ];
+ };
+
+ /**
+ * Construct a new Camera.
+ * @return a new camera.
+ */
+ static Camera* New();
+
+ /**
+ * Destructor
+ */
+ ~Camera();
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetType
+ */
+ void SetType( Dali::Camera::Type type );
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetInvertYAxis
+ */
+ void SetInvertYAxis( bool invertYAxis );
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetProjectionMode
+ */
+ void SetProjectionMode( Dali::Camera::ProjectionMode projectionMode );
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetFieldOfView
+ */
+ void SetFieldOfView( float fieldOfView );
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetAspectRatio
+ */
+ void SetAspectRatio( float aspectRatio );
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetStereoBias
+ */
+ void SetStereoBias(const Vector2& stereoBias);
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetLeftClippingPlane
+ */
+ void SetLeftClippingPlane( float leftClippingPlane );
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetRightClippingPlane
+ */
+ void SetRightClippingPlane( float rightClippingPlane );
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetTopClippingPlane
+ */
+ void SetTopClippingPlane( float topClippingPlane );
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetBottomClippingPlane
+ */
+ void SetBottomClippingPlane( float bottomClippingPlane );
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetNearClippingPlane
+ */
+ void SetNearClippingPlane( float nearClippingPlane );
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetFarClippingPlane
+ */
+ void SetFarClippingPlane( float farClippingPlane );
+
+ /**
+ * @copydoc Dali::Internal::CameraActor::SetTarget
+ */
+ void SetTargetPosition( const Vector3& targetPosition );
+
+ /**
+ * Retrieve the view-matrix; this is double buffered for input handling.
+ * @param[in] bufferIndex The buffer to read from.
+ * @return The view-matrix.
+ */
+ const Matrix& GetViewMatrix( BufferIndex bufferIndex ) const;
+
+ /**
+ * @brief Check to see if a sphere lies within the view frustum.
+ *
+ * @param bufferIndex The buffer to read from.
+ * @param origin The world position center of the sphere to check.
+ * @param radius The length of the sphere radius in world scale.
+ *
+ * @return false if the sphere lies outside of the frustum.
+ */
+ bool CheckSphereInFrustum( BufferIndex bufferIndex, const Vector3& origin, float radius );
+
+ /**
+ * @brief Check to see if a bounding box lies within the view frustum.
+ *
+ * @param bufferIndex The buffer to read from.
+ * @param origin the world position center of the cubeoid to check.
+ * @param halfExtents The half length of the cubeoid in world co-ordinates in each axis.
+ *
+ * @return false if the cubeoid lies completely outside of the frustum, true otherwise
+ */
+ bool CheckAABBInFrustum( BufferIndex bufferIndex, const Vector3& origin, const Vector3& halfExtents );
+
+ /**
+ * Retrieve the projection-matrix; this is double buffered for input handling.
+ * @param[in] bufferIndex The buffer to read from.
+ * @return The projection-matrix.
+ */
+ const Matrix& GetProjectionMatrix( BufferIndex bufferIndex ) const;
+
+ /**
+ * Retrieve the inverted view-projection-matrix; this is double buffered for input handling.
+ * @param[in] bufferIndex The buffer to read from.
+ * @return The inverse view-projection-matrix.
+ */
+ const Matrix& GetInverseViewProjectionMatrix( BufferIndex bufferIndex ) const;
+
+ /**
+ * Retrieve the projection-matrix property querying interface.
+ * @pre The camera is on-stage.
+ * @return The projection-matrix property querying interface.
+ */
+ const PropertyInputImpl* GetProjectionMatrix() const;
+
+ /**
+ * Retrieve the viewMatrix property querying interface.
+ * @pre The camera is on-stage.
+ * @return The viewMatrix property querying interface.
+ */
+ const PropertyInputImpl* GetViewMatrix() const;
+
+ /**
+ * Updates view and projection matrices.
+ * Called by the render task using the camera
+ * @param[in] updateBufferIndex The buffer to read from.
+ * @param[in] owningNode The node that owns the camera
+ */
+ void Update( BufferIndex updateBufferIndex, const Node& owningNode );
+
+ /**
+ * @return true if the view matrix of camera is updated this or the previous frame
+ */
+ bool ViewMatrixUpdated();
+
+private:
+
+ /**
+ * Constructor
+ */
+ Camera();
+
+ // Non copyable
+ // Undefined
+ Camera(const Camera&);
+ // Undefined
+ Camera& operator=(const Camera& rhs);
+
+ /**
+ * Recalculates the view matrix.
+ * @param[in] bufferIndex The current update buffer index.
+ * @param[in] owningNode to use for calculations.
+ * @return count how many frames ago the matrix was changed.
+ */
+ unsigned int UpdateViewMatrix( BufferIndex updateBufferIndex, const Node& owningNode );
+
+ /**
+ * Recalculates the projection matrix.
+ * @param[in] bufferIndex The current update buffer index.
+ * @return count how many frames ago the matrix was changed.
+ */
+ unsigned int UpdateProjection( BufferIndex updateBufferIndex );
+
+private:
+
+ /**
+ * @brief Extracts the frustum planes.
+ *
+ * @param[in] bufferIndex The current update buffer index.
+ * @param[in] normalize will normalize plane equation coefficients by default.
+ */
+ void UpdateFrustum( BufferIndex updateBufferIndex, bool normalize = true );
+
+ unsigned int mUpdateViewFlag; ///< This is non-zero if the view matrix requires an update
+ unsigned int mUpdateProjectionFlag; ///< This is non-zero if the projection matrix requires an update
+
+public: // PROPERTIES
+ Dali::Camera::Type mType; // Non-animatable
+ Dali::Camera::ProjectionMode mProjectionMode; // Non-animatable
+ bool mInvertYAxis; // Non-animatable
+
+ float mFieldOfView;
+ float mAspectRatio;
+ float mLeftClippingPlane;
+ float mRightClippingPlane;
+ float mTopClippingPlane;
+ float mBottomClippingPlane;
+ float mNearClippingPlane;
+ float mFarClippingPlane;
+ Vector2 mStereoBias;
+ Vector3 mTargetPosition;
+
+ InheritedMatrix mViewMatrix; ///< The viewMatrix; this is double buffered for input handling.
+ InheritedMatrix mProjectionMatrix; ///< The projectionMatrix; this is double buffered for input handling.
+
+ DoubleBuffered< FrustumPlanes > mFrustum; ///< Clipping frustum; double buffered for input handling
+ DoubleBuffered< Matrix > mInverseViewProjection; ///< Inverted viewprojection; double buffered for input handling
+
+};
+
+// Messages for Camera
+
+inline void SetTypeMessage( EventThreadServices& eventThreadServices, const Camera& camera, Dali::Camera::Type parameter )
+{
+ typedef MessageValue1< Camera, Dali::Camera::Type > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &camera, &Camera::SetType, parameter );
+}
+
+inline void SetProjectionModeMessage( EventThreadServices& eventThreadServices, const Camera& camera, Dali::Camera::ProjectionMode parameter )
+{
+ typedef MessageValue1< Camera, Dali::Camera::ProjectionMode > LocalProjectionMode;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalProjectionMode ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalProjectionMode( &camera, &Camera::SetProjectionMode, parameter );
+}
+
+inline void SetFieldOfViewMessage( EventThreadServices& eventThreadServices, const Camera& camera, float parameter )
+{
+ typedef MessageValue1< Camera, float > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &camera, &Camera::SetFieldOfView, parameter );
+}
+
+inline void SetAspectRatioMessage( EventThreadServices& eventThreadServices, const Camera& camera, float parameter )
+{
+ typedef MessageValue1< Camera, float > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &camera, &Camera::SetAspectRatio, parameter );
+}
+
+inline void SetStereoBiasMessage( EventThreadServices& eventThreadServices, const Camera& camera, const Vector2& parameter )
+{
+ typedef MessageValue1< Camera, Vector2 > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &camera, &Camera::SetStereoBias, parameter );
+}
+
+inline void SetLeftClippingPlaneMessage( EventThreadServices& eventThreadServices, const Camera& camera, float parameter )
+{
+ typedef MessageValue1< Camera, float > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &camera, &Camera::SetLeftClippingPlane, parameter );
+}
+
+inline void SetRightClippingPlaneMessage( EventThreadServices& eventThreadServices, const Camera& camera, float parameter )
+{
+ typedef MessageValue1< Camera, float > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &camera, &Camera::SetRightClippingPlane, parameter );
+}
+
+inline void SetTopClippingPlaneMessage( EventThreadServices& eventThreadServices, const Camera& camera, float parameter )
+{
+ typedef MessageValue1< Camera, float > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &camera, &Camera::SetTopClippingPlane, parameter );
+}
+
+inline void SetBottomClippingPlaneMessage( EventThreadServices& eventThreadServices, const Camera& camera, float parameter )
+{
+ typedef MessageValue1< Camera, float > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &camera, &Camera::SetBottomClippingPlane, parameter );
+}
+
+inline void SetNearClippingPlaneMessage( EventThreadServices& eventThreadServices, const Camera& camera, float parameter )
+{
+ typedef MessageValue1< Camera, float > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &camera, &Camera::SetNearClippingPlane, parameter );
+}
+
+inline void SetFarClippingPlaneMessage( EventThreadServices& eventThreadServices, const Camera& camera, float parameter )
+{
+ typedef MessageValue1< Camera, float > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &camera, &Camera::SetFarClippingPlane, parameter );
+}
+
+inline void SetTargetPositionMessage( EventThreadServices& eventThreadServices, const Camera& camera, const Vector3& parameter )
+{
+ typedef MessageValue1< Camera, Vector3 > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &camera, &Camera::SetTargetPosition, parameter );
+}
+
+inline void SetInvertYAxisMessage( EventThreadServices& eventThreadServices, const Camera& camera, bool parameter )
+{
+ typedef MessageValue1< Camera, bool > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
+
+ // Construct message in the message queue memory; note that delete should not be called on the return value
+ new (slot) LocalType( &camera, &Camera::SetInvertYAxis, parameter );
+}
+
+} // namespace SceneGraph
+
+} // namespace Internal
+
+} // namespace Dali
+
+#endif // __DALI_INTERNAL_SCENE_GRAPH_CAMERA_H__
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return mExclusive;
}
-void RenderTask::SetCameraNode( Node* cameraNode )
+void RenderTask::SetCamera( Node* cameraNode, Camera* camera )
{
- // if camera changed
- if( cameraNode != mCameraNode )
- {
- if( cameraNode )
- {
- // get attachment. when camera node is changed we will get a message from event thread object
- // so no need to observe the node here
- mCameraAttachment = dynamic_cast< CameraAttachment* >( &cameraNode->GetAttachment() );
- DALI_ASSERT_DEBUG( mCameraAttachment && "Camera without attachment" );
- }
- mCameraNode = cameraNode;
- }
+ mCameraNode = cameraNode;
+ mCamera = camera;
}
void RenderTask::SetFrameBufferId( unsigned int resourceId, bool isNativeFBO )
// Check camera node
if ( NULL == mCameraNode ||
NULL == mCameraNode->GetParent() ||
- NULL == mCameraAttachment )
+ NULL == mCamera )
{
// Camera node is missing or disconnected
TASK_LOG_FMT(Debug::General, " =F No Camera FC:%d\n", mFrameCounter );
return false;
}
- mCameraAttachment->Update( updateBufferIndex, *mCameraNode );
+ mCamera->Update( updateBufferIndex, *mCameraNode );
TASK_LOG_FMT(Debug::General, " =T (FBO ID:%d) FC:%d\n", mFrameBufferResourceId , mFrameCounter );
return true;
const Matrix& RenderTask::GetViewMatrix( BufferIndex bufferIndex ) const
{
- DALI_ASSERT_DEBUG( NULL != mCameraAttachment );
+ DALI_ASSERT_DEBUG( NULL != mCamera );
- return mCameraAttachment->GetViewMatrix( bufferIndex );
+ return mCamera->GetViewMatrix( bufferIndex );
}
-SceneGraph::CameraAttachment& RenderTask::GetCameraAttachment() const
+SceneGraph::Camera& RenderTask::GetCamera() const
{
- DALI_ASSERT_DEBUG( NULL != mCameraAttachment );
- return *mCameraAttachment;
+ DALI_ASSERT_DEBUG( NULL != mCamera );
+ return *mCamera;
}
const Matrix& RenderTask::GetProjectionMatrix( BufferIndex bufferIndex ) const
{
- DALI_ASSERT_DEBUG( NULL != mCameraAttachment );
+ DALI_ASSERT_DEBUG( NULL != mCamera );
- return mCameraAttachment->GetProjectionMatrix( bufferIndex );
+ return mCamera->GetProjectionMatrix( bufferIndex );
}
void RenderTask::PrepareRenderInstruction( RenderInstruction& instruction, BufferIndex updateBufferIndex )
{
- DALI_ASSERT_DEBUG( NULL != mCameraAttachment );
+ DALI_ASSERT_DEBUG( NULL != mCamera );
TASK_LOG(Debug::General);
Viewport viewport;
bool viewportSet = QueryViewport( updateBufferIndex, viewport );
- instruction.Reset( mCameraAttachment,
+ instruction.Reset( mCamera,
GetFrameBufferId(),
viewportSet ? &viewport : NULL,
mClearEnabled ? &GetClearColor( updateBufferIndex ) : NULL );
bool RenderTask::ViewMatrixUpdated()
{
bool retval = false;
- if( mCameraAttachment )
+ if( mCamera )
{
- retval = mCameraAttachment->ViewMatrixUpdated();
+ retval = mCamera->ViewMatrixUpdated();
}
return retval;
}
return false;
}
-Node* RenderTask::GetCamera() const
-{
- return mCameraNode;
-}
-
void RenderTask::SetSyncRequired( bool requiresSync )
{
mRequiresSync = requiresSync;
mRenderSyncTracker( NULL ),
mSourceNode( NULL ),
mCameraNode( NULL ),
- mCameraAttachment( NULL ),
+ mCamera( NULL ),
mFrameBufferResourceId( 0 ),
mResourcesFinished( false ),
mWaitingToRender( false ),
#define __DALI_INTERNAL_SCENE_GRAPH_RENDER_TASK_H__
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
namespace SceneGraph
{
class Node;
-class CameraAttachment;
+class Camera;
class RenderInstruction;
class RenderMessageDispatcher;
bool IsExclusive() const;
/**
- * Set the node from which the scene is viewed.
- * @param[in] node The scene is viewed from the perspective of this node.
+ * Set the camera from which the scene is viewed.
+ * @param[in] cameraNode that camera is connected with
+ * @param[in] camera to use.
*/
- void SetCameraNode( Node* node );
+ void SetCamera( Node* cameraNode, Camera* camera );
/**
* Set the frame-buffer used as a render target.
/**
* Retrieve the view-matrix; this is double buffered for input handling.
- * @pre GetCameraNode() returns a node with valid CameraAttachment.
+ * @pre GetCameraNode() returns a node with valid Camera.
* @param[in] bufferIndex The buffer to read from.
* @return The view-matrix.
*/
const Matrix& GetViewMatrix( BufferIndex bufferIndex ) const;
/**
- * @brief Retrieve the camera attachment.
- * @pre GetCameraNode() returns a node with valid CameraAttachment.
+ * @brief Retrieve the camera.
+ * @pre GetCameraNode() returns a node with valid Camera.
*
- * @return The camera attachment.
+ * @return The camera.
*/
- SceneGraph::CameraAttachment& GetCameraAttachment() const;
+ SceneGraph::Camera& GetCamera() const;
/**
* Retrieve the projection-matrix; this is double buffered for input handling.
- * @pre GetCameraNode() returns a node with valid CameraAttachment.
+ * @pre GetCameraNode() returns a node with valid Camera.
* @param[in] bufferIndex The buffer to read from.
* @return The projection-matrix.
*/
*/
bool ViewMatrixUpdated();
- /**
- * @return A pointer to the camera used by the RenderTask
- */
- Node* GetCamera() const;
-
/**
* Set whether GL sync is required for native render target.
* @param[in] whether GL sync is required for native render target
Render::RenderTracker* mRenderSyncTracker;
Node* mSourceNode;
Node* mCameraNode;
- CameraAttachment* mCameraAttachment;
+ SceneGraph::Camera* mCamera;
unsigned int mFrameBufferResourceId;
bool mResourcesFinished:1; ///< True if all resources were available when the render-task was processed
new (slot) LocalType( &task, &RenderTask::SetSourceNode, node );
}
-inline void SetCameraNodeMessage( EventThreadServices& eventThreadServices, RenderTask& task, const Node* constNode )
+inline void SetCameraMessage( EventThreadServices& eventThreadServices, RenderTask& task, const Node* constNode, const Camera* constCamera )
{
- // Scene graph thread can destroy this object.
- Node* node = const_cast< Node* >( constNode );
+ typedef MessageValue2< RenderTask, Node*, Camera* > LocalType;
- typedef MessageValue1< RenderTask, Node* > LocalType;
-
- // Reserve some memory inside the message queue
+ Node* node = const_cast< Node* >( constNode );
+ Camera* camera = const_cast< Camera* >( constCamera );
+ // Reserve memory inside the message queue
unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
// Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &task, &RenderTask::SetCameraNode, node );
+ new (slot) LocalType( &task, &RenderTask::SetCamera, node, camera );
}
inline void SetExclusiveMessage( EventThreadServices& eventThreadServices, RenderTask& task, bool exclusive )
#define DALI_INTERNAL_SCENE_GRAPH_RENDERER2_H
/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
private:
- SceneController* mSceneController; ///< Used for initializing renderers whilst attached
- Render::Renderer* mRenderer; ///< Raw pointer to the renderer (that's owned by RenderManager)
- TextureSet* mTextureSet; ///< The texture set this renderer uses. (Not owned)
- Render::Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
+ SceneController* mSceneController; ///< Used for initializing renderers
+ Render::Renderer* mRenderer; ///< Raw pointer to the renderer (that's owned by RenderManager)
+ TextureSet* mTextureSet; ///< The texture set this renderer uses. (Not owned)
+ Render::Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
Shader* mShader;
Vector4* mBlendColor; ///< The blend color for blending operation
unsigned int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
unsigned char mResendFlag; ///< Indicate whether data should be resent to the renderer
bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
- bool mResourcesReady; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
+ bool mResourcesReady; ///< Set during the Update algorithm; true if the renderer has resources ready for the current frame.
bool mFinishedResourceAcquisition; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
bool mPremultipledAlphaEnabled : 1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
new (slot) LocalType( &renderer, &Renderer::SetShader, &shader );
}
-inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Renderer& attachment, int depthIndex )
+inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, int depthIndex )
{
typedef MessageValue1< Renderer, int > LocalType;
unsigned int* slot = eventThreadServices.ReserveMessageSlot( sizeof( LocalType ) );
// Construct message in the message queue memory; note that delete should not be called on the return value
- new (slot) LocalType( &attachment, &Renderer::SetDepthIndex, depthIndex );
+ new (slot) LocalType( &renderer, &Renderer::SetDepthIndex, depthIndex );
}
inline void SetFaceCullingModeMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, Dali::FaceCullingMode::Type faceCullingMode )