application.SendNotification();
application.Render(0);
- // Expect that the renderer's fade color property is accessed
+ // Expect that the actor's fade color property is accessed
Vector4 actualValue(Vector4::ZERO);
DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
- DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
+ DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
// Animate material's fade color property. Should be no change to uniform
Animation animation = Animation::New(1.0f);
application.Render(500);
DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
- DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
+ DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
application.Render(500);
DALI_TEST_CHECK( gl.GetUniformValue<Vector4>( "uFadeColor", actualValue ) );
- DALI_TEST_EQUALS( actualValue, Color::RED, TEST_LOCATION );
+ DALI_TEST_EQUALS( actualValue, Color::GREEN, TEST_LOCATION );
END_TEST;
}
#include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
#include <dali/internal/event/actor-attachments/camera-attachment-impl.h>
#include <dali/internal/event/actor-attachments/image-attachment-impl.h>
-#include <dali/internal/event/actor-attachments/renderer-attachment-impl.h>
#include <dali/internal/event/animation/animation-impl.h>
#include <dali/internal/event/animation/animator-connector.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/node-attachments/scene-graph-image-attachment.h>
-#include <dali/internal/update/node-attachments/scene-graph-renderer-attachment.h>
+#include <dali/internal/update/rendering/scene-graph-renderer.h>
#include <dali/internal/update/resources/bitmap-metadata.h>
#include <dali/internal/render/gl-resources/bitmap-texture.h>
-#include <dali/internal/render/renderers/scene-graph-image-renderer.h>
+#include <dali/internal/render/renderers/render-geometry.h>
+#include <dali/internal/render/renderers/render-image-renderer.h>
+#include <dali/internal/render/renderers/render-new-renderer.h>
#include <dali/internal/render/renderers/render-renderer.h>
using Dali::Internal::GestureEventProcessor;
sizeof( Internal::ImageAttachment ) +
sizeof( Internal::SceneGraph::Node ) +
sizeof( Internal::SceneGraph::ImageAttachment ) +
- sizeof( Internal::SceneGraph::ImageRenderer ));
+ sizeof( Internal::Render::ImageRenderer ));
const int LAYER_MEMORY_SIZE(
sizeof( Internal::Layer ) +
sizeof( Internal::ActorAttachment ) +
sizeof( Internal::ImageTicket ) );
const int RENDERER_MEMORY_SIZE(
sizeof( Internal::Renderer ) +
- sizeof( Internal::RendererAttachment ) +
- sizeof( Internal::SceneGraph::RendererAttachment ) +
sizeof( Internal::SceneGraph::Renderer ) +
- sizeof( Internal::SceneGraph::NewRenderer ) );
+ sizeof( Internal::Render::NewRenderer ) );
const int GEOMETRY_MEMORY_SIZE(
sizeof( Internal::Geometry ) +
- sizeof( Internal::SceneGraph::Geometry ) );
+ sizeof( Internal::SceneGraph::Geometry ) +
+ sizeof( Internal::SceneGraph::RenderGeometry) );
const int PROPERTY_BUFFER_MEMORY_SIZE(
sizeof( Internal::PropertyBuffer ) +
sizeof( Internal::SceneGraph::PropertyBuffer ) );
+++ /dev/null
-/*
- * Copyright (c) 2015 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/event/actor-attachments/renderer-attachment-impl.h>
-
-// INTERNAL INCLUDES
-#include <dali/internal/event/common/event-thread-services.h>
-#include <dali/internal/update/manager/update-manager.h>
-#include <dali/internal/update/node-attachments/scene-graph-renderer-attachment.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-RendererAttachmentPtr RendererAttachment::New( EventThreadServices& eventThreadServices, const SceneGraph::Node& parentNode, Renderer& renderer )
-{
- RendererAttachmentPtr attachment( new RendererAttachment( eventThreadServices ) );
-
- if( attachment )
- {
- attachment->Initialize( eventThreadServices, parentNode, renderer );
- }
- return attachment;
-}
-
-void RendererAttachment::Initialize( EventThreadServices& eventThreadServices, const SceneGraph::Node& parentNode, Renderer& renderer )
-{
- SceneGraph::RendererAttachment* sceneObject = renderer.GetRendererSceneObject();
-
- // Takes ownership of scene object
- AttachToNodeMessage( eventThreadServices.GetUpdateManager(), parentNode, sceneObject );
-
- // Connect to renderer
- mRendererConnector.Set( renderer, false );
-
- // Keep raw pointer for message passing
- mSceneObject = sceneObject;
-}
-
-RendererAttachment::RendererAttachment( EventThreadServices& eventThreadServices )
-: RenderableAttachment(eventThreadServices),
- mSceneObject(NULL)
-{
-}
-
-RendererAttachment::~RendererAttachment()
-{
-}
-
-const SceneGraph::RendererAttachment& RendererAttachment::GetSceneObject() const
-{
- DALI_ASSERT_DEBUG( mSceneObject != NULL );
- return *mSceneObject;
-}
-
-void RendererAttachment::OnStageConnection2()
-{
- mRendererConnector.OnStageConnect();
-}
-
-void RendererAttachment::OnStageDisconnection2()
-{
- mRendererConnector.OnStageDisconnect();
-}
-
-} // namespace Internal
-
-} // namespace Dali
+++ /dev/null
-#ifndef DALI_INTERNAL_RENDERER_ATTACHMENT_H
-#define DALI_INTERNAL_RENDERER_ATTACHMENT_H
-
-/*
- * Copyright (c) 2015 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/internal/event/actor-attachments/renderable-attachment-impl.h>
-#include <dali/internal/event/common/object-connector.h>
-#include <dali/internal/event/rendering/renderer-impl.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace SceneGraph
-{
-class Node;
-class RendererAttachment;
-}
-
-class RendererAttachment;
-typedef IntrusivePtr<RendererAttachment> RendererAttachmentPtr;
-
-/**
- * An attachment for rendering renderers.
- *
- * Currently, the Renderer object creates the SceneGraph::RendererAttachment object, not this. It is attached
- * here as needed.
- */
-class RendererAttachment : public RenderableAttachment
-{
-public:
-
- /**
- * Create a new RendererAttachment.
- * @param[in] eventThreadServices Used for messaging to and reading from the SceneGraph
- * @param[in] parentNode The node to attach a scene-object to.
- * @poaram[in] renderer The renderer for this attachment
- * @return A smart-pointer to the newly allocated RendererAttachment.
- */
- static RendererAttachmentPtr New( EventThreadServices& eventThreadServices, const SceneGraph::Node& parentNode, Renderer& renderer );
-
-
- /**
- * Second stage initialization
- *
- * @param[in] eventThreadServices Used for messaging to and reading from the SceneGraph
- * @param[in] parentNode The node to attach a scene-object to.
- * @poaram[in] renderer The renderer for this attachment
- */
- void Initialize( EventThreadServices& eventThreadServices, const SceneGraph::Node& parentNode, Renderer& renderer );
-
- /**
- * Get the renderer
- *
- * @return The renderer
- */
- Renderer& GetRenderer()
- {
- return *mRendererConnector.Get();
- }
-
-private:
-
- /**
- * First stage construction of a RendererAttachment.
- * @param[in] eventThreadServices Used for messaging to and reading from the SceneGraph
- */
- RendererAttachment( EventThreadServices& eventThreadServices );
-
- /**
- * @copydoc Dali::Internal::RenderableAttachment::GetSceneObject()
- */
- virtual const SceneGraph::RendererAttachment& GetSceneObject() const;
-
- /**
- * @copydoc Dali::Internal::RenderableAttachment::OnStageConnection2()
- */
- virtual void OnStageConnection2();
-
- /**
- * @copydoc Dali::Internal::RenderableAttachment::OnStageDisconnection2()
- */
- virtual void OnStageDisconnection2();
-
-protected:
-
- /**
- * A reference counted object may only be deleted by calling Unreference()
- */
- virtual ~RendererAttachment();
-
-private:
- const SceneGraph::RendererAttachment* mSceneObject; ///< Not owned
-
- ObjectConnector<Renderer> mRendererConnector;
-};
-
-} // namespace Internal
-
-} // namespace Dali
-
-#endif // DALI_INTERNAL_RENDERER_ATTACHMENT_H
#include <dali/internal/event/common/stage-impl.h>
#include <dali/internal/event/common/type-info-impl.h>
#include <dali/internal/event/actor-attachments/actor-attachment-impl.h>
-#include <dali/internal/event/actor-attachments/renderer-attachment-impl.h>
#include <dali/internal/event/animation/constraint-impl.h>
#include <dali/internal/event/common/projection.h>
#include <dali/internal/event/size-negotiation/relayout-controller-impl.h>
unsigned int Actor::AddRenderer( Renderer& renderer )
{
- //TODO: MESH_REWORK : Add support for multiple renderers
- if ( ! mAttachment )
+ if( !mRenderers )
{
- mAttachment = RendererAttachment::New( GetEventThreadServices(), *mNode, renderer );
- if( mIsOnStage )
- {
- mAttachment->Connect();
- }
+ mRenderers = new RendererContainer;
}
- return 0;
+ unsigned int index = mRenderers->size();
+ RendererPtr rendererPtr = RendererPtr( &renderer );
+ mRenderers->push_back( rendererPtr );
+ AddRendererMessage( GetEventThreadServices(), *mNode, renderer.GetRendererSceneObject() );
+
+ if( mIsOnStage)
+ {
+ rendererPtr->Connect();
+ }
+
+ return index;
}
unsigned int Actor::GetRendererCount() const
{
- //TODO: MESH_REWORK : Add support for multiple renderers
- RendererAttachment* attachment = dynamic_cast<RendererAttachment*>(mAttachment.Get());
- return attachment ? 1u : 0u;
+ unsigned int rendererCount(0);
+ if( mRenderers )
+ {
+ rendererCount = mRenderers->size();
+ }
+
+ return rendererCount;
}
-Renderer& Actor::GetRendererAt( unsigned int index )
+RendererPtr Actor::GetRendererAt( unsigned int index )
{
- //TODO: MESH_REWORK : Add support for multiple renderers
- DALI_ASSERT_DEBUG( index == 0 && "Only one renderer is supported." );
-
- //TODO: MESH_REWORK : Temporary code
- RendererAttachment* attachment = dynamic_cast<RendererAttachment*>(mAttachment.Get());
- DALI_ASSERT_ALWAYS( attachment && "Actor doesn't have a renderer" );
+ RendererPtr renderer;
+ if( index < GetRendererCount() )
+ {
+ renderer = ( *mRenderers )[ index ];
+ }
- return attachment->GetRenderer();
+ return renderer;
}
void Actor::RemoveRenderer( Renderer& renderer )
{
- //TODO: MESH_REWORK : Add support for multiple renderers
- mAttachment = NULL;
+ if( mRenderers )
+ {
+ RendererIter end = mRenderers->end();
+ for( RendererIter iter = mRenderers->begin(); iter != end; ++iter )
+ {
+ if( (*iter).Get() == &renderer )
+ {
+ mRenderers->erase( iter );
+ RemoveRendererMessage( GetEventThreadServices(), *mNode, renderer.GetRendererSceneObject() );
+ break;
+ }
+ }
+ }
}
void Actor::RemoveRenderer( unsigned int index )
{
- //TODO: MESH_REWORK : Add support for multiple renderers
- mAttachment = NULL;
+ if( index < GetRendererCount() )
+ {
+ RendererPtr renderer = ( *mRenderers )[ index ];
+ RemoveRendererMessage( GetEventThreadServices(), *mNode, renderer.Get()->GetRendererSceneObject() );
+ mRenderers->erase( mRenderers->begin()+index );
+ }
}
void Actor::SetOverlay( bool enable )
Actor::Actor( DerivedType derivedType )
: mParent( NULL ),
mChildren( NULL ),
+ mRenderers( NULL ),
mNode( NULL ),
mParentOrigin( NULL ),
mAnchorPoint( NULL ),
}
}
delete mChildren;
+ delete mRenderers;
// Guard to allow handle destruction after Core has been destroyed
if( EventThreadServices::IsCoreRunning() )
mAttachment->Connect();
}
+ unsigned int rendererCount( GetRendererCount() );
+ for( unsigned int i(0); i<rendererCount; ++i )
+ {
+ GetRendererAt(i)->Connect();
+ }
+
// Request relayout on all actors that are added to the scenegraph
RelayoutRequest();
{
mAttachment->Disconnect();
}
+
+ unsigned int rendererCount( GetRendererCount() );
+ for( unsigned int i(0); i<rendererCount; ++i )
+ {
+ GetRendererAt(i)->Disconnect();
+ }
}
void Actor::NotifyStageDisconnection()
typedef ActorContainer::iterator ActorIter;
typedef ActorContainer::const_iterator ActorConstIter;
+typedef std::vector< RendererPtr > RendererContainer;
+typedef RendererContainer::iterator RendererIter;
+
/**
* Actor is the primary object which Dali applications interact with.
* UI controls can be built by combining multiple actors.
/**
* @copydoc Dali::Actor::GetRendererAt()
*/
- Renderer& GetRendererAt( unsigned int index );
+ RendererPtr GetRendererAt( unsigned int index );
/**
* @copydoc Dali::Actor::RemoveRenderer()
Actor* mParent; ///< Each actor (except the root) can have one parent
ActorContainer* mChildren; ///< Container of referenced actors
+ RendererContainer* mRenderers; ///< Renderer container
+
const SceneGraph::Node* mNode; ///< Not owned
Vector3* mParentOrigin; ///< NULL means ParentOrigin::DEFAULT. ParentOrigin is non-animatable
Vector3* mAnchorPoint; ///< NULL means AnchorPoint::DEFAULT. AnchorPoint is non-animatable
{
hit.depth += imageActor->GetDepthIndex();
}
- else if ( actor.GetRendererCount() )
+ else if ( actor.GetRendererCount() > 0 )
{
- hit.depth += actor.GetRendererAt( 0 ).GetDepthIndex();
+ //Get renderer with maximum depth
+ int rendererMaxDepth(actor.GetRendererAt( 0 ).Get()->GetDepthIndex());
+ for( unsigned int i(1); i<actor.GetRendererCount(); ++i)
+ {
+ int depth = actor.GetRendererAt( i ).Get()->GetDepthIndex();
+ if( depth > rendererMaxDepth )
+ {
+ rendererMaxDepth = depth;
+ }
+ }
+ hit.depth += rendererMaxDepth;
}
}
}
#include <dali/internal/event/common/object-impl-helper.h> // Dali::Internal::ObjectHelper
#include <dali/internal/event/common/property-helper.h> // DALI_PROPERTY_TABLE_BEGIN, DALI_PROPERTY, DALI_PROPERTY_TABLE_END
#include <dali/internal/event/common/property-input-impl.h>
-#include <dali/internal/update/node-attachments/scene-graph-renderer-attachment.h>
+#include <dali/internal/update/rendering/scene-graph-renderer.h>
#include <dali/internal/update/manager/update-manager.h>
namespace Dali
return mDepthIndex;
}
-SceneGraph::RendererAttachment* Renderer::GetRendererSceneObject()
+SceneGraph::Renderer* Renderer::GetRendererSceneObject()
{
return mSceneObject;
}
void Renderer::Connect()
{
- // @todo: MESH_REWORK : check this
+ OnStageConnectMessage( GetEventThreadServices(), *mSceneObject );
mGeometryConnector.OnStageConnect();
mMaterialConnector.OnStageConnect();
mOnStage = true;
void Renderer::Disconnect()
{
- // @todo: MESH_REWORK : check this
+ OnStageDisconnectMessage( GetEventThreadServices(), *mSceneObject);
mGeometryConnector.OnStageDisconnect();
mMaterialConnector.OnStageDisconnect();
mOnStage = false;
EventThreadServices& eventThreadServices = GetEventThreadServices();
SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
- // Transfer object ownership of scene-object to message
- mSceneObject = SceneGraph::RendererAttachment::New();
-
- // Send message to update to connect to scene graph:
- AttachToSceneGraphMessage( updateManager, mSceneObject );
+ mSceneObject = new SceneGraph::Renderer();
+ AddMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
eventThreadServices.RegisterObject( this );
}
if( EventThreadServices::IsCoreRunning() )
{
EventThreadServices& eventThreadServices = GetEventThreadServices();
+ SceneGraph::UpdateManager& updateManager = eventThreadServices.GetUpdateManager();
+ RemoveMessage( updateManager, updateManager.GetRendererOwner(), *mSceneObject );
+
eventThreadServices.UnregisterObject( this );
}
}
#include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
#include <dali/internal/event/rendering/material-impl.h> // Dali::Internal::Material
#include <dali/internal/event/rendering/geometry-impl.h> // Dali::Internal::Geometry
+#include <dali/internal/update/nodes/node.h>
namespace Dali
{
{
namespace SceneGraph
{
-class RendererAttachment;
+class Renderer;
}
+
class Renderer;
typedef IntrusivePtr<Renderer> RendererPtr;
/**
* Renderer is an object that can be used to show content by combining a Geometry with a material.
*/
-class Renderer : public Object, public Connectable
+class Renderer : public Object
{
public:
*
* @return the scene object
*/
- SceneGraph::RendererAttachment* GetRendererSceneObject();
+ SceneGraph::Renderer* GetRendererSceneObject();
public: // Default property extensions from Object
Renderer& operator=( const Renderer& );
private: // data
- SceneGraph::RendererAttachment* mSceneObject;
+ SceneGraph::Renderer* mSceneObject;
ObjectConnector<Geometry> mGeometryConnector; ///< Connector that holds the geometry used by this renderer
ObjectConnector<Material> mMaterialConnector; ///< Connector that holds the material used by this renderer
int mDepthIndex;
$(internal_src_dir)/event/actor-attachments/camera-attachment-impl.cpp \
$(internal_src_dir)/event/actor-attachments/image-attachment-impl.cpp \
$(internal_src_dir)/event/actor-attachments/renderable-attachment-impl.cpp \
- $(internal_src_dir)/event/actor-attachments/renderer-attachment-impl.cpp \
$(internal_src_dir)/event/actors/actor-impl.cpp \
$(internal_src_dir)/event/actors/custom-actor-internal.cpp \
$(internal_src_dir)/event/actors/image-actor-impl.cpp \
$(internal_src_dir)/render/gl-resources/texture-cache.cpp \
$(internal_src_dir)/render/queue/render-queue.cpp \
$(internal_src_dir)/render/renderers/render-geometry.cpp \
- $(internal_src_dir)/render/renderers/render-renderer.cpp \
+ $(internal_src_dir)/render/renderers/render-new-renderer.cpp \
$(internal_src_dir)/render/renderers/render-renderer-property-buffer.cpp \
- $(internal_src_dir)/render/renderers/scene-graph-image-renderer.cpp \
- $(internal_src_dir)/render/renderers/scene-graph-renderer.cpp \
- $(internal_src_dir)/render/renderers/scene-graph-renderer-debug.cpp \
+ $(internal_src_dir)/render/renderers/render-image-renderer.cpp \
+ $(internal_src_dir)/render/renderers/render-renderer.cpp \
$(internal_src_dir)/render/shaders/custom-uniform.cpp \
$(internal_src_dir)/render/shaders/program.cpp \
$(internal_src_dir)/render/shaders/program-controller.cpp \
$(internal_src_dir)/update/node-attachments/scene-graph-camera-attachment.cpp \
$(internal_src_dir)/update/node-attachments/scene-graph-image-attachment.cpp \
$(internal_src_dir)/update/node-attachments/scene-graph-renderable-attachment.cpp \
- $(internal_src_dir)/update/node-attachments/scene-graph-renderer-attachment.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 \
$(internal_src_dir)/update/render-tasks/scene-graph-render-task-list.cpp \
$(internal_src_dir)/update/rendering/scene-graph-geometry.cpp \
$(internal_src_dir)/update/rendering/scene-graph-material.cpp \
+ $(internal_src_dir)/update/rendering/scene-graph-renderer.cpp \
$(internal_src_dir)/update/rendering/scene-graph-sampler.cpp \
$(internal_src_dir)/update/resources/bitmap-metadata.cpp \
$(internal_src_dir)/update/resources/resource-manager.cpp \
namespace SceneGraph
{
-bool Is2dBoxOutsideClipSpace(const Matrix& modelMatrix,
- const Matrix& modelViewProjectionMatrix,
+bool Is2dBoxOutsideClipSpace(const Matrix& modelViewProjectionMatrix,
const Rect<float>& boundingBox )
{
// First, calculate if the center is inside clip space:
#define _DALI_INTERNAL_SCENE_GRAPH_CULLING_ALGORITHMS_H_
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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.
/**
* Determine if the given bounding box is outside clip space (given by the
* model view projection matrix).
- * @param[in] modelMatrix The world matrix of the bounding box.
* @param[in] modelViewProjectionMatrix The clip space matrix
* @param[in] boundingBox The bounding box of the geometry in object space
* @return true if the bounding box is outside clip space
*/
-bool Is2dBoxOutsideClipSpace(const Matrix& modelMatrix,
- const Matrix& modelViewProjectionMatrix,
+bool Is2dBoxOutsideClipSpace(const Matrix& modelViewProjectionMatrix,
const Rect<float>& boundingBox );
} // SceneGraph
} // Internal
#include <dali/internal/render/common/render-list.h>
#include <dali/internal/render/common/render-instruction.h>
#include <dali/internal/render/gl-resources/context.h>
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
+#include <dali/internal/render/renderers/render-renderer.h>
using Dali::Internal::SceneGraph::RenderItem;
using Dali::Internal::SceneGraph::RenderList;
//Enable depth writes if depth buffer is enabled and item is opaque
context.DepthMask( depthBufferEnabled && item.IsOpaque() );
- SceneGraph::Renderer* renderer = const_cast< SceneGraph::Renderer* >( item.GetRenderer() );
- renderer->Render( context, textureCache, bufferIndex, defaultShader, item.GetModelViewMatrix(), viewMatrix, projectionMatrix, frameTime, cullMode );
+ item.GetRenderer().Render( context, textureCache, bufferIndex, item.GetNode(), defaultShader, item.GetModelViewMatrix(), viewMatrix, projectionMatrix, frameTime, cullMode, !item.IsOpaque() );
}
}
else
const RenderItem& item = renderList.GetItem( index );
DALI_PRINT_RENDER_ITEM( item );
- SceneGraph::Renderer* renderer = const_cast< SceneGraph::Renderer* >( item.GetRenderer() );
- renderer->Render( context, textureCache, bufferIndex, defaultShader, item.GetModelViewMatrix(), viewMatrix, projectionMatrix, frameTime, cullMode );
+ item.GetRenderer().Render( context, textureCache, bufferIndex, item.GetNode(), defaultShader, item.GetModelViewMatrix(), viewMatrix, projectionMatrix, frameTime, cullMode, !item.IsOpaque() );
}
}
if( renderItem.GetDepthIndex() == depthIndex )
{
- SceneGraph::Renderer* renderer = const_cast< SceneGraph::Renderer* >( renderItem.GetRenderer() );
const Matrix& modelViewMatrix = renderItem.GetModelViewMatrix();
- renderer->Render( context, textureCache, bufferIndex, defaultShader, modelViewMatrix, viewMatrix, projectionMatrix, frameTime, cullMode );
+ renderItem.GetRenderer().Render( context, textureCache, bufferIndex, renderItem.GetNode(), defaultShader, modelViewMatrix, viewMatrix, projectionMatrix, frameTime, cullMode, !renderItem.IsOpaque() );
}
else
#include <dali/internal/render/common/render-item.h>
// INTERNAL INCLUDES
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
+#include <dali/internal/render/renderers/render-renderer.h>
namespace Dali
{
mRenderer = NULL;
}
-void RenderItem::SetRenderer( Renderer* renderer )
+void RenderItem::SetRenderer( Render::Renderer* renderer )
{
mRenderer = renderer;
}
-const Renderer* RenderItem::GetRenderer() const
+void RenderItem::SetNode( Node* node )
{
- return mRenderer;
+ mNode = node;
+}
+
+Render::Renderer& RenderItem::GetRenderer() const
+{
+ return *mRenderer;
}
Matrix& RenderItem::GetModelViewMatrix()
#include <dali/public-api/common/vector-wrapper.h>
#include <dali/public-api/actors/layer.h>
#include <dali/public-api/math/matrix.h>
+#include <dali/internal/update/nodes/node.h>
namespace Dali
{
namespace Internal
{
+namespace Render
+{
+class Renderer;
+}
+
namespace SceneGraph
{
-class Renderer;
class RenderItem;
typedef std::vector< RenderItem > RendererItemContainer;
* Retrieve the renderer.
* @return The renderer.
*/
- const Renderer* GetRenderer() const;
+ Render::Renderer& GetRenderer() const;
/**
* Set the renderer
* @param[in] renderer The renderer
*/
- void SetRenderer( Renderer* renderer );
+ void SetRenderer( Render::Renderer* renderer );
/**
+ * Set the node
+ * @param[in] node The node
+ */
+ void SetNode( Node* node );
+
+ /**
+ * Retrieve the node
+ * @return The node
+ */
+ const Node& GetNode() const
+ {
+ return *mNode;
+ }
+ /**
* Retrieve the modelView matrix.
* @return The modelView matrix.
*/
RenderItem( const RenderItem& item );
RenderItem& operator = ( const RenderItem& item );
- Matrix mModelViewMatrix;
- Renderer* mRenderer;
- int mDepthIndex;
- bool mIsOpaque:1;
+ Matrix mModelViewMatrix;
+ Render::Renderer* mRenderer;
+ Node* mNode;
+ int mDepthIndex;
+ bool mIsOpaque:1;
};
} // namespace SceneGraph
namespace Internal
{
+namespace Render
+{
+class Renderer;
+}
+
namespace SceneGraph
{
class Layer;
-class Renderer;
+
class RenderItem;
typedef OwnerContainer< RenderItem* > RenderItemContainer;
/**
* Get renderer from an item in the list
*/
- const Renderer* GetRenderer( RenderItemContainer::SizeType index ) const
+ const Render::Renderer& GetRenderer( RenderItemContainer::SizeType index ) const
{
DALI_ASSERT_DEBUG( index < GetCachedItemCount() );
return mItems[ index ]->GetRenderer();
#include <dali/internal/render/gl-resources/context.h>
#include <dali/internal/render/gl-resources/frame-buffer-texture.h>
#include <dali/internal/render/gl-resources/texture-cache.h>
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
+#include <dali/internal/render/renderers/render-renderer.h>
#include <dali/internal/render/renderers/render-geometry.h>
#include <dali/internal/render/shaders/program-controller.h>
#ifdef FRAME_SNAPSHOT_LOGGING
-using namespace Dali::Internal::Render;
namespace // unnamed namespace
{
namespace SceneGraph
{
-typedef OwnerContainer< Renderer* > RendererOwnerContainer;
+typedef OwnerContainer< Render::Renderer* > RendererOwnerContainer;
typedef RendererOwnerContainer::Iterator RendererOwnerIter;
typedef OwnerContainer< RenderGeometry* > RenderGeometryOwnerContainer;
mImpl->defaultSurfaceRect = rect;
}
-void RenderManager::AddRenderer( Renderer* renderer )
+void RenderManager::AddRenderer( Render::Renderer* renderer )
{
// Initialize the renderer as we are now in render thread
renderer->Initialize( mImpl->context, mImpl->textureCache );
}
}
-void RenderManager::RemoveRenderer( Renderer* renderer )
+void RenderManager::RemoveRenderer( Render::Renderer* renderer )
{
DALI_ASSERT_DEBUG( NULL != renderer );
class ProgramCache;
class ShaderSaver;
-namespace SceneGraph
+namespace Render
{
class Renderer;
+}
+
+namespace SceneGraph
+{
class RenderQueue;
class TextureCache;
class RenderInstruction;
* @param[in] renderer The renderer to add.
* @post renderer is owned by RenderManager
*/
- void AddRenderer( Renderer* renderer );
+ void AddRenderer( Render::Renderer* renderer );
/**
* Remove a Renderer from the render manager.
* @param[in] renderer The renderer to remove.
* @post renderer is destroyed.
*/
- void RemoveRenderer( Renderer* renderer );
+ void RemoveRenderer( Render::Renderer* renderer );
/**
* Add a geometry to the render manager.
*
*/
+#include <dali/internal/render/data-providers/uniform-map-data-provider.h>
+
namespace Dali
{
struct Vector4;
/**
* An interface to provide data for a Renderer
*/
-class NodeDataProvider
+class NodeDataProvider : UniformMapDataProvider
{
public:
* @param bufferId to use
* @return a reference to the model matrix
*/
- virtual const Matrix& GetModelMatrix( unsigned int bufferId ) = 0;
+ virtual const Matrix& GetModelMatrix( unsigned int bufferId ) const = 0;
/**
* @param bufferId to use
* @return a reference to the color
*/
- virtual const Vector4& GetRenderColor( unsigned int bufferId ) = 0;
+ virtual const Vector4& GetRenderColor( unsigned int bufferId ) const = 0;
/**
* @param[in] bufferIndex The buffer index to use
* @return the actor size
*/
- virtual const Vector3& GetRenderSize( unsigned int bufferIndex ) = 0;
+ virtual const Vector3& GetRenderSize( unsigned int bufferIndex ) const = 0;
+
+ /**
+ * @copydoc Dali::Internal::SceneGraph::UniformMapDataProvider::GetUniformMapChanged()
+ */
+ virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const = 0;
+
+ /**
+ * @copydoc Dali::Internal::SceneGraph::UniformMapDataProvider::GetUniformMap()
+ */
+ virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const = 0;
protected:
/**
RenderDataProvider::RenderDataProvider()
: mMaterialDataProvider( NULL ),
mUniformMapDataProvider( NULL ),
- mShader( NULL ),
- mUseBlend( false )
+ mShader( NULL )
{
}
return mSamplers;
}
-void RenderDataProvider::SetUseBlend( bool useBlend )
-{
- mUseBlend = useBlend;
-}
-
-bool RenderDataProvider::GetUseBlend( BufferIndex bufferIndex ) const
-{
- return mUseBlend;
-}
-
} // SceneGraph
} // Internal
} // Dali
*/
const Samplers& GetSamplers() const;
- /**
- * Set the use blend flag to decide if the renderer will perform blending
- * @param[in] useBlend The flag to decide if the renderer will perform blending
- */
- void SetUseBlend( bool useBlend );
-
- /**
- * Get the use blend flag that decides if the renderer will perform blending
- * @param[in] buffer index
- * @return The use blend flag that decides if the renderer will perform blending
- */
- bool GetUseBlend( BufferIndex bufferIndex ) const;
-
private:
const MaterialDataProvider* mMaterialDataProvider;
const UniformMapDataProvider* mUniformMapDataProvider;
Shader* mShader;
Samplers mSamplers;
- bool mUseBlend;
-// Give RendererAttachment access to our private data to reduce copying vectors on construction.
- friend class RendererAttachment;
+// Give Renderer access to our private data to reduce copying vectors on construction.
+ friend class Renderer;
};
} // SceneGraph
context.DrawArrays(GL_POINTS, 0, numVertices );
break;
}
+ case Dali::Geometry::TRIANGLE_STRIP:
+ {
+ const PropertyBufferDataProvider& firstVertexBuffer = mVertexBuffers[0]->GetDataProvider();
+ unsigned int numVertices = firstVertexBuffer.GetElementCount( bufferIndex );
+ context.DrawArrays(GL_TRIANGLE_STRIP, 0, numVertices );
+ break;
+ }
+ case Dali::Geometry::TRIANGLE_FAN:
+ {
+ const PropertyBufferDataProvider& firstVertexBuffer = mVertexBuffers[0]->GetDataProvider();
+ unsigned int numVertices = firstVertexBuffer.GetElementCount( bufferIndex );
+ context.DrawArrays(GL_TRIANGLE_FAN, 0, numVertices );
+ break;
+ }
default:
{
DALI_ASSERT_ALWAYS( 0 && "Geometry type not supported (yet)" );
*/
// CLASS HEADER
-#include <dali/internal/render/renderers/scene-graph-image-renderer.h>
+#include <dali/internal/render/renderers/render-image-renderer.h>
// EXTERNAL INCLUDES
#include <dali/public-api/common/dali-common.h>
#include <dali/internal/render/gl-resources/texture.h>
#include <dali/internal/render/gl-resources/texture-cache.h>
#include <dali/internal/render/gl-resources/texture-units.h>
-#include <dali/internal/render/renderers/scene-graph-renderer-debug.h>
#include <dali/internal/render/shaders/program.h>
#include <dali/internal/render/shaders/scene-graph-shader.h>
#include <dali/internal/update/controllers/scene-controller.h>
+
namespace
{
#if defined(DEBUG_ENABLED)
namespace Internal
{
-namespace SceneGraph
+namespace Render
{
-ImageRenderer* ImageRenderer::New( NodeDataProvider& dataProvider )
+ImageRenderer* ImageRenderer::New()
{
- return new ImageRenderer( dataProvider );
+ return new ImageRenderer();
}
ImageRenderer::~ImageRenderer()
{
if ( mTextureId > 0 )
{
- mTextureCacheDELETEME->RemoveObserver(mTextureId, this);
+ mTextureCache->RemoveObserver(mTextureId, this);
}
GlCleanup();
{
if ( mTextureId > 0 )
{
- mTextureCacheDELETEME->RemoveObserver(mTextureId, this);
+ mTextureCache->RemoveObserver(mTextureId, this);
}
mTextureId = textureId;
if ( textureId > 0 )
{
- mTextureCacheDELETEME->AddObserver(textureId, this);
+ mTextureCache->AddObserver(textureId, this);
}
}
{
if( mTexture == NULL )
{
- if ( mTextureCacheDELETEME )
+ if ( mTextureCache )
{
- mTexture = mTextureCacheDELETEME->GetTexture( mTextureId );
+ mTexture = mTextureCache->GetTexture( mTextureId );
}
}
Integration::ResourceId shaderTextureId = mShader->GetTextureIdToRender() ;
- if( shaderTextureId && mTextureCacheDELETEME->GetTexture( shaderTextureId ) == NULL )
+ if( shaderTextureId && mTextureCache->GetTexture( shaderTextureId ) == NULL )
{
return false;
}
return true;
}
-bool ImageRenderer::IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
+bool ImageRenderer::IsOutsideClipSpace( Context& context, const Matrix& modelViewProjectionMatrix )
{
context.IncrementRendererCount();
Rect<float> boundingBox( mGeometrySize.x * -0.5f, mGeometrySize.y * -0.5f, mGeometrySize.x, mGeometrySize.y );
- DEBUG_BOUNDING_BOX( *mContext, boundingBox, modelViewProjectionMatrix );
-
- if(Is2dBoxOutsideClipSpace( modelMatrix, modelViewProjectionMatrix, boundingBox ) )
+ if(SceneGraph::Is2dBoxOutsideClipSpace( modelViewProjectionMatrix, boundingBox ) )
{
context.IncrementCulledCount();
return true;
return false;
}
-void ImageRenderer::DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
+void ImageRenderer::DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
{
DALI_LOG_INFO( gImageRenderFilter, Debug::Verbose, "DoRender() textureId=%d texture:%p\n", mTextureId, mTexture);
DALI_ASSERT_DEBUG( mVertexBuffer );
- mTextureCacheDELETEME->BindTexture( mTexture, mTextureId, GL_TEXTURE_2D, TEXTURE_UNIT_IMAGE );
+ mTextureCache->BindTexture( mTexture, mTextureId, GL_TEXTURE_2D, TEXTURE_UNIT_IMAGE );
if( mTexture->GetTextureId() == 0 )
{
}
}
-void ImageRenderer::DoSetBlending(Context& context, BufferIndex bufferIndex )
+void ImageRenderer::DoSetBlending(Context& context, BufferIndex bufferIndex, bool blend )
{
// Enables/disables blending mode.
- context.SetBlend( mUseBlend );
+ context.SetBlend( blend );
// Set the blend color
const Vector4* const customColor = mBlendingOptions.GetBlendColor();
texture->MapUV( sizeof(verts)/sizeof(Vertex2D), verts, pixelArea );
- UpdateVertexBuffer( *mContextDELETEME, sizeof(verts), verts );
- UpdateIndexBuffer( *mContextDELETEME, 0, NULL );
+ UpdateVertexBuffer( *mContext, sizeof(verts), verts );
+ UpdateIndexBuffer( *mContext, 0, NULL );
}
void ImageRenderer::SetNinePatchMeshData( Texture* texture, const Vector2& size, const Vector4& border, bool borderInPixels, const PixelArea* pixelArea, bool noCenter )
const size_t vertsSize = sizeof( vertsWithCenter );
const unsigned int vertexCount = vertsSize / sizeof( vertsWithCenter[0] );
texture->MapUV( vertexCount, vertsWithCenter, pixelArea );
- UpdateVertexBuffer( *mContextDELETEME, vertsSize, vertsWithCenter );
+ UpdateVertexBuffer( *mContext, vertsSize, vertsWithCenter );
}
else
{
const size_t vertsSize = sizeof( vertsWithNoCenter );
const unsigned int vertexCount = vertsSize / sizeof( vertsWithNoCenter[0] );
texture->MapUV( vertexCount, vertsWithNoCenter, pixelArea );
- UpdateVertexBuffer( *mContextDELETEME, vertsSize, vertsWithNoCenter );
+ UpdateVertexBuffer( *mContext, vertsSize, vertsWithNoCenter );
}
// not using an index buffer
- UpdateIndexBuffer( *mContextDELETEME, 0, NULL );
+ UpdateIndexBuffer( *mContext, 0, NULL );
}
texture->MapUV( totalVertices, vertices, pixelArea );
- UpdateVertexBuffer( *mContextDELETEME, totalVertices * sizeof(Vertex2D) , vertices );
- UpdateIndexBuffer( *mContextDELETEME, totalIndices * sizeof(GLushort), indices );
+ UpdateVertexBuffer( *mContext, totalVertices * sizeof(Vertex2D) , vertices );
+ UpdateIndexBuffer( *mContext, totalIndices * sizeof(GLushort), indices );
delete[] vertices;
delete[] indices;
}
}
-ImageRenderer::ImageRenderer( NodeDataProvider& dataProvider )
-: Renderer( dataProvider ),
+ImageRenderer::ImageRenderer()
+: Renderer(),
mTexture( NULL ),
mBorder( 0.45, 0.45, 0.1, 0.1 ),
mPixelArea(),
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_IMAGE_RENDERER_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_IMAGE_RENDERER_H__
+#ifndef __DALI_INTERNAL_RENDER_IMAGE_RENDERER_H__
+#define __DALI_INTERNAL_RENDER_IMAGE_RENDERER_H__
/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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/resources/resource-manager-declarations.h>
#include <dali/internal/render/gl-resources/context.h>
#include <dali/internal/render/gl-resources/texture-observer.h>
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
+#include <dali/internal/render/renderers/render-renderer.h>
namespace Dali
{
namespace SceneGraph
{
class NodeDataProvider;
+class TextureCache;
+}
+namespace Render
+{
/**
* Used to render an image.
*/
/**
* Create a new ImageRenderer.
- * @param dataprovider to render
* @return The newly allocated ImageRenderer.
*/
- static ImageRenderer* New( NodeDataProvider& dataprovider );
+ static ImageRenderer* New();
/**
* Virtual destructor
/**
* @copydoc Dali::Internal::SceneGraph::Renderer::IsOutsideClipSpace()
*/
- virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix );
+ virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelViewProjectionMatrix );
/**
* @copydoc Dali::Internal::SceneGraph::Renderer::DoRender()
*/
- virtual void DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix );
+ virtual void DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix );
/**
* @copydoc Dali::Internal::SceneGraph::Renderer::DoSetBlending()
*/
- virtual void DoSetBlending( Context& context, BufferIndex bufferIndex );
+ virtual void DoSetBlending( Context& context, BufferIndex bufferIndex, bool blend );
protected: // TextureObserver implementation
/**
* Private constructor. @see New()
*/
- ImageRenderer( NodeDataProvider& dataprovider );
+ ImageRenderer();
// Undefined
ImageRenderer( const ImageRenderer& );
} // namespace Dali
-#endif // __DALI_INTERNAL_SCENE_GRAPH_IMAGE_RENDERER_H__
+#endif // __DALI_INTERNAL_RENDER_IMAGE_RENDERER_H__
--- /dev/null
+/*
+ * Copyright (c) 2015 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.
+ */
+
+#include "render-new-renderer.h"
+
+#include <dali/internal/common/image-sampler.h>
+#include <dali/internal/event/common/property-input-impl.h>
+#include <dali/internal/update/common/uniform-map.h>
+#include <dali/internal/render/data-providers/render-data-provider.h>
+#include <dali/internal/render/gl-resources/texture.h>
+#include <dali/internal/render/gl-resources/texture-cache.h>
+#include <dali/internal/render/shaders/program.h>
+
+namespace Dali
+{
+namespace Internal
+{
+namespace Render
+{
+
+NewRenderer* NewRenderer::New( SceneGraph::RenderDataProvider* dataProvider,
+ SceneGraph::RenderGeometry* renderGeometry )
+{
+ return new NewRenderer( dataProvider, renderGeometry);
+}
+
+
+NewRenderer::NewRenderer( SceneGraph::RenderDataProvider* dataProvider,
+ SceneGraph::RenderGeometry* renderGeometry )
+: Renderer(),
+ mRenderDataProvider( dataProvider ),
+ mRenderGeometry( renderGeometry ),
+ mUpdateAttributesLocation( true )
+{
+}
+
+NewRenderer::~NewRenderer()
+{
+}
+
+void NewRenderer::SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProvider )
+{
+ mRenderDataProvider = dataProvider;
+ mUpdateAttributesLocation = true;
+}
+
+void NewRenderer::SetGeometry( SceneGraph::RenderGeometry* renderGeometry )
+{
+ mRenderGeometry = renderGeometry;
+ mUpdateAttributesLocation = true;
+}
+
+// Note - this is currently called from UpdateThread, PrepareRenderInstructions,
+// as an optimisation.
+// @todo MESH_REWORK Should use Update thread objects only in PrepareRenderInstructions.
+bool NewRenderer::RequiresDepthTest() const
+{
+ return true;
+}
+
+bool NewRenderer::CheckResources()
+{
+ // Query material to check it has texture pointers & image has size
+ // Query geometry to check it has vertex buffers
+
+ // General point though - why would we have a render item in RenderThread with no ready
+ // resources in UpdateThread?
+ return true;
+}
+
+bool NewRenderer::IsOutsideClipSpace( Context& context, const Matrix& modelViewProjectionMatrix )
+{
+ // @todo MESH_REWORK Add clipping
+ return false;
+}
+
+void NewRenderer::DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program, unsigned int programIndex )
+{
+ // Do nothing, we're going to set up the uniforms with our own code instead
+}
+
+void NewRenderer::DoSetCullFaceMode( Context& context, BufferIndex bufferIndex )
+{
+}
+
+void NewRenderer::DoSetBlending( Context& context, BufferIndex bufferIndex, bool blend )
+{
+ context.SetBlend( blend );
+ if( blend )
+ {
+ const SceneGraph::MaterialDataProvider& material = mRenderDataProvider->GetMaterial();
+
+ context.SetCustomBlendColor( material.GetBlendColor( bufferIndex ) );
+
+ // Set blend source & destination factors
+ context.BlendFuncSeparate( material.GetBlendSrcFactorRgb( bufferIndex ),
+ material.GetBlendDestFactorRgb( bufferIndex ),
+ material.GetBlendSrcFactorAlpha( bufferIndex ),
+ material.GetBlendDestFactorAlpha( bufferIndex ) );
+
+ // Set blend equations
+ context.BlendEquationSeparate( material.GetBlendEquationRgb( bufferIndex ),
+ material.GetBlendEquationAlpha( bufferIndex ) );
+ }
+}
+
+void NewRenderer::DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
+{
+ BindTextures( textureCache, bufferIndex, program, mRenderDataProvider->GetSamplers() );
+
+ SetUniforms( bufferIndex, node, program );
+
+ if( mUpdateAttributesLocation || mRenderGeometry->AttributesChanged() )
+ {
+ mRenderGeometry->GetAttributeLocationFromProgram( mAttributesLocation, program, bufferIndex );
+ mUpdateAttributesLocation = false;
+ }
+
+ mRenderGeometry->UploadAndDraw( context, bufferIndex, mAttributesLocation );
+}
+
+void NewRenderer::GlContextDestroyed()
+{
+ mRenderGeometry->GlContextDestroyed();
+}
+
+void NewRenderer::GlCleanup()
+{
+}
+
+void NewRenderer::SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program )
+{
+ // Check if the map has changed
+ DALI_ASSERT_DEBUG( mRenderDataProvider && "No Uniform map data provider available" );
+
+ const SceneGraph::UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMap();
+
+ if( uniformMapDataProvider.GetUniformMapChanged( bufferIndex ) ||
+ node.GetUniformMapChanged(bufferIndex))
+ {
+ const SceneGraph::CollectedUniformMap& uniformMap = uniformMapDataProvider.GetUniformMap( bufferIndex );
+ const SceneGraph::CollectedUniformMap& uniformMapNode = node.GetUniformMap( bufferIndex );
+
+ unsigned int maxMaps = uniformMap.Count() + uniformMapNode.Count();
+ mUniformIndexMap.Clear(); // Clear contents, but keep memory if we don't change size
+ mUniformIndexMap.Resize( maxMaps );
+
+ unsigned int mapIndex(0);
+ for(; mapIndex < uniformMap.Count() ; ++mapIndex )
+ {
+ mUniformIndexMap[mapIndex].propertyValue = uniformMap[mapIndex]->propertyPtr;
+ mUniformIndexMap[mapIndex].uniformIndex = program.RegisterUniform( uniformMap[mapIndex]->uniformName );
+ }
+
+ for( unsigned int nodeMapIndex = 0; nodeMapIndex < uniformMapNode.Count() ; ++nodeMapIndex )
+ {
+ unsigned int uniformIndex = program.RegisterUniform( uniformMapNode[nodeMapIndex]->uniformName );
+ bool found(false);
+ for( unsigned int i(0); i<uniformMap.Count(); ++i )
+ {
+ if( mUniformIndexMap[i].uniformIndex == uniformIndex )
+ {
+ mUniformIndexMap[i].propertyValue = uniformMapNode[nodeMapIndex]->propertyPtr;
+ found = true;
+ break;
+ }
+ }
+
+ if( !found )
+ {
+ mUniformIndexMap[mapIndex].propertyValue = uniformMapNode[nodeMapIndex]->propertyPtr;
+ mUniformIndexMap[mapIndex].uniformIndex = uniformIndex;
+ ++mapIndex;
+ }
+ }
+
+ mUniformIndexMap.Resize( mapIndex );
+ }
+
+ // Set uniforms in local map
+ for( UniformIndexMappings::Iterator iter = mUniformIndexMap.Begin(),
+ end = mUniformIndexMap.End() ;
+ iter != end ;
+ ++iter )
+ {
+ SetUniformFromProperty( bufferIndex, program, *iter );
+ }
+
+ // @todo MESH_REWORK On merge, copy code from renderer to setup standard matrices and color
+
+ GLint sizeLoc = program.GetUniformLocation( Program::UNIFORM_SIZE );
+ if( -1 != sizeLoc )
+ {
+ Vector3 size = node.GetRenderSize( bufferIndex );
+ program.SetUniform3f( sizeLoc, size.x, size.y, size.z );
+ }
+}
+
+void NewRenderer::SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map )
+{
+ GLint location = program.GetUniformLocation(map.uniformIndex);
+ if( Program::UNIFORM_UNKNOWN != location )
+ {
+ // switch based on property type to use correct GL uniform setter
+ switch ( map.propertyValue->GetType() )
+ {
+ case Property::INTEGER:
+ {
+ program.SetUniform1i( location, map.propertyValue->GetInteger( bufferIndex ) );
+ break;
+ }
+ case Property::FLOAT:
+ {
+ program.SetUniform1f( location, map.propertyValue->GetFloat( bufferIndex ) );
+ break;
+ }
+ case Property::VECTOR2:
+ {
+ Vector2 value( map.propertyValue->GetVector2( bufferIndex ) );
+ program.SetUniform2f( location, value.x, value.y );
+ break;
+ }
+
+ case Property::VECTOR3:
+ {
+ Vector3 value( map.propertyValue->GetVector3( bufferIndex ) );
+ program.SetUniform3f( location, value.x, value.y, value.z );
+ break;
+ }
+
+ case Property::VECTOR4:
+ {
+ Vector4 value( map.propertyValue->GetVector4( bufferIndex ) );
+ program.SetUniform4f( location, value.x, value.y, value.z, value.w );
+ break;
+ }
+
+ case Property::ROTATION:
+ {
+ Quaternion value( map.propertyValue->GetQuaternion( bufferIndex ) );
+ program.SetUniform4f( location, value.mVector.x, value.mVector.y, value.mVector.z, value.mVector.w );
+ break;
+ }
+
+ case Property::MATRIX:
+ {
+ const Matrix& value = map.propertyValue->GetMatrix(bufferIndex);
+ program.SetUniformMatrix4fv(location, 1, value.AsFloat() );
+ break;
+ }
+
+ case Property::MATRIX3:
+ {
+ const Matrix3& value = map.propertyValue->GetMatrix3(bufferIndex);
+ program.SetUniformMatrix3fv(location, 1, value.AsFloat() );
+ break;
+ }
+
+ default:
+ {
+ // Other property types are ignored
+ break;
+ }
+ }
+ }
+}
+
+void NewRenderer::BindTextures(
+ SceneGraph::TextureCache& textureCache,
+ BufferIndex bufferIndex,
+ Program& program,
+ const SceneGraph::RenderDataProvider::Samplers& samplers )
+{
+ // @todo MESH_REWORK Write a cache of texture units to commonly used sampler textures
+ unsigned int textureUnit = 0;
+
+ for( SceneGraph::RenderDataProvider::Samplers::Iterator iter = samplers.Begin();
+ iter != samplers.End();
+ ++iter )
+ {
+ const SceneGraph::SamplerDataProvider* sampler = *iter;
+ ResourceId textureId = sampler->GetTextureId(bufferIndex);
+ Texture* texture = textureCache.GetTexture( textureId );
+ if( texture != NULL )
+ {
+ unsigned int textureUnitUniformIndex = GetTextureUnitUniformIndex( program, *sampler );
+ TextureUnit theTextureUnit = static_cast<TextureUnit>(textureUnit);
+ BindTexture( textureCache, program, textureId, texture, theTextureUnit, textureUnitUniformIndex );
+ ApplySampler( bufferIndex, texture, theTextureUnit, *sampler );
+ }
+
+ ++textureUnit;
+ }
+}
+
+void NewRenderer::BindTexture(
+ SceneGraph::TextureCache& textureCache,
+ Program& program,
+ ResourceId id,
+ Texture* texture,
+ TextureUnit textureUnit,
+ unsigned int textureUnitUniformIndex )
+{
+ if( texture != NULL )
+ {
+ textureCache.BindTexture( texture, id, GL_TEXTURE_2D, textureUnit );
+
+ // Set sampler uniform location for the texture
+ GLint textureUnitLoc = program.GetUniformLocation( textureUnitUniformIndex );
+ if( Program::UNIFORM_UNKNOWN != textureUnitLoc )
+ {
+ program.SetUniform1i( textureUnitLoc, textureUnit );
+ }
+ }
+}
+
+void NewRenderer::ApplySampler(
+ BufferIndex bufferIndex,
+ Texture* texture,
+ TextureUnit textureUnit,
+ const SceneGraph::SamplerDataProvider& sampler )
+{
+ unsigned int samplerBitfield = ImageSampler::PackBitfield(
+ static_cast< FilterMode::Type >(sampler.GetMinifyFilterMode(bufferIndex)),
+ static_cast< FilterMode::Type >(sampler.GetMagnifyFilterMode(bufferIndex)) );
+
+ texture->ApplySampler( textureUnit, samplerBitfield );
+
+ // @todo MESH_REWORK add support for wrap modes
+}
+
+unsigned int NewRenderer::GetTextureUnitUniformIndex(
+ Program& program,
+ const SceneGraph::SamplerDataProvider& sampler )
+{
+ // Find sampler in mSamplerNameCache
+ // If it doesn't exist,
+ // get the index by calling program.RegisterUniform and store it
+ // If it exists, it's index should be set.
+ // @todo Cache should be reset on scene change
+
+ unsigned int uniformIndex = 0;
+ bool found = false;
+
+ for( unsigned int i=0; i< mTextureUnitUniforms.Count(); ++i )
+ {
+ if( mTextureUnitUniforms[i].sampler == &sampler )
+ {
+ uniformIndex = mTextureUnitUniforms[i].index;
+ found = true;
+ }
+ }
+
+ if( ! found )
+ {
+ TextureUnitUniformIndex textureUnitUniformIndex;
+ textureUnitUniformIndex.sampler = &sampler;
+ textureUnitUniformIndex.index = program.RegisterUniform( sampler.GetTextureUnitUniformName() );
+ mTextureUnitUniforms.PushBack( textureUnitUniformIndex );
+ uniformIndex = textureUnitUniformIndex.index;
+ }
+
+ return uniformIndex;
+}
+
+
+} // SceneGraph
+} // Internal
+} // Dali
--- /dev/null
+#ifndef __DALI_INTERNAL_RENDER_NEW_RENDERER_H__
+#define __DALI_INTERNAL_RENDER_NEW_RENDERER_H__
+
+/*
+ * Copyright (c) 2015 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.
+ *
+ */
+
+#include <dali/integration-api/resource-declarations.h> // For resource id
+#include <dali/internal/common/owner-pointer.h>
+#include <dali/internal/render/data-providers/render-data-provider.h>
+#include <dali/internal/render/gl-resources/texture-units.h>
+#include <dali/internal/render/renderers/render-renderer.h>
+#include <dali/internal/render/renderers/render-geometry.h>
+#include <dali/internal/update/manager/prepare-render-instructions.h>
+
+namespace Dali
+{
+namespace Internal
+{
+class PropertyInputImpl;
+
+namespace Render
+{
+
+/**
+ * The new geometry renderer.
+ *
+ * @todo MESH_REWORK It will be merged into the base class eventually
+ */
+class NewRenderer : public Renderer
+{
+public:
+ typedef Integration::ResourceId ResourceId;
+
+public:
+ /**
+ * Create a new renderer instance
+ * @param[in] dataProviders The data providers for the renderer
+ * @param[in] renderGeometry The geometry for the renderer
+ */
+ static NewRenderer* New( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
+
+ /**
+ * Constructor.
+ * @param[in] dataProviders The data providers for the renderer
+ * @param[in] renderGeometry The geometry for the renderer
+ */
+ NewRenderer( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
+
+ virtual ~NewRenderer();
+
+ /**
+ * Change the data providers of the renderer
+ * @param[in] dataProviders The data providers
+ */
+ void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
+
+ /**
+ * Change the geometry used by the renderer
+ * @param[in] renderGeometry The new geometry
+ */
+ void SetGeometry( SceneGraph::RenderGeometry* renderGeometry );
+
+ /**
+ * Write the renderer's sort attributes to the passed in reference.
+ * @param[in] bufferIndex The buffer index
+ * @param[out] sortAttributes
+ */
+ void SetSortAttributes( SceneGraph::RendererWithSortAttributes& sortAttributes ) const
+ {
+ sortAttributes.shader = &(mRenderDataProvider->GetShader());
+ sortAttributes.material = &(mRenderDataProvider->GetMaterial());
+ sortAttributes.geometry = mRenderGeometry;
+ }
+
+public: // Implementation of Renderer
+ /**
+ * @copydoc SceneGraph::Renderer::RequiresDepthTest()
+ */
+ virtual bool RequiresDepthTest() const;
+
+ /**
+ * @copydoc SceneGraph::Renderer::CheckResources()
+ */
+ virtual bool CheckResources();
+
+ /**
+ * @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
+ */
+ virtual bool IsOutsideClipSpace( Context& context,
+ const Matrix& modelViewProjectionMatrix );
+
+ /**
+ * @copydoc SceneGraph::Renderer::DoSetUniforms()
+ */
+ virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program, unsigned int programIndex );
+
+ /**
+ * @copydoc SceneGraph::Renderer::DoSetCullFaceMode
+ */
+ virtual void DoSetCullFaceMode(Context& context, BufferIndex bufferIndex );
+
+ /**
+ * @copydoc SceneGraph::Renderer::DoSetBlending
+ */
+ virtual void DoSetBlending(Context& context, BufferIndex bufferIndex, bool blend );
+
+ /**
+ * @copydoc SceneGraph::Renderer::DoRender()
+ */
+ virtual void DoRender( Context& context,
+ SceneGraph::TextureCache& textureCache,
+ const SceneGraph::NodeDataProvider& node,
+ BufferIndex bufferIndex,
+ Program& program,
+ const Matrix& modelViewMatrix,
+ const Matrix& viewMatrix );
+
+public: // Implementation of GlResourceOwner
+
+ /**
+ * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
+ */
+ virtual void GlContextDestroyed();
+
+ /**
+ * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
+ */
+ virtual void GlCleanup();
+
+private:
+ struct UniformIndexMap;
+
+ /**
+ * Set the uniforms from properties according to the uniform map
+ * @param[in] node The node using the renderer
+ * @param[in] program The shader program on which to set the uniforms.
+ */
+ void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program );
+
+ /**
+ * Set the program uniform in the map from the mapped property
+ */
+ void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
+
+ /**
+ * Bind the material textures in the samplers and setup the samplers
+ * @param[in] textureCache The texture cache
+ * @param[in] bufferIndex The buffer index
+ * @param[in] program The shader program
+ * @param[in] samplers The samplers to bind
+ */
+ void BindTextures( SceneGraph::TextureCache& textureCache,
+ BufferIndex bufferIndex,
+ Program& program,
+ const SceneGraph::RenderDataProvider::Samplers& samplers );
+
+ /**
+ * Bind a material texture to a texture unit, and set the sampler's texture uniform
+ * to that texture unit.
+ * @param[in] textureCache The texture cache
+ * @param[in] program The shader program
+ * @param[in] id The resource id of the texture to bind
+ * @param[in] texture The texture to bind
+ * @param[in] textureUnit The texture unit index to use
+ * @param[in] nameIndex The index of the texture uniform in the program
+ */
+ void BindTexture( SceneGraph::TextureCache& textureCache,
+ Program& program,
+ ResourceId id,
+ Texture* texture,
+ TextureUnit textureUnit,
+ unsigned int nameIndex );
+
+ /**
+ * Apply the sampler modes to the texture.
+ * @param[in] bufferIndex The current buffer index
+ * @param[in] texture The texture to which to apply the sampler modes
+ * @param[in] textureUnit The texture unit of the texture
+ * @param[in] sampler The sampler from which to get the modes.
+ */
+ void ApplySampler( BufferIndex bufferIndex,
+ Texture* texture,
+ TextureUnit textureUnit,
+ const SceneGraph::SamplerDataProvider& sampler );
+
+ /**
+ * Get the texture uniform index of the name sampler in the program.
+ * If not already registered in the program, then this performs the registration
+ * @param[in] program The shader program
+ * @param[in] sampler The sampler holding a texture unit uniform name to search for
+ * @return The texture uniform index in the program
+ */
+ unsigned int GetTextureUnitUniformIndex( Program& program,
+ const SceneGraph::SamplerDataProvider& sampler );
+
+
+
+public: //@todo MESH_REWORK make private after merge with SceneGraph::Renderer
+ OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
+
+private:
+ SceneGraph::RenderGeometry* mRenderGeometry;
+
+ struct TextureUnitUniformIndex
+ {
+ const SceneGraph::SamplerDataProvider* sampler;
+ unsigned int index;
+ };
+
+ typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms;
+ TextureUnitUniforms mTextureUnitUniforms;
+
+ struct UniformIndexMap
+ {
+ unsigned int uniformIndex; // The index of the cached location in the Program
+ const PropertyInputImpl* propertyValue;
+ };
+
+ typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
+ UniformIndexMappings mUniformIndexMap;
+
+ Vector<GLint> mAttributesLocation;
+ bool mUpdateAttributesLocation;
+
+};
+
+
+} // SceneGraph
+} // Internal
+} // Dali
+
+#endif // __DALI_INTERNAL_RENDER_NEW_RENDERER_H__
class Context;
class Program;
-namespace SceneGraph
+namespace Render
{
class NewRenderer;
+}
+
+namespace SceneGraph
+{
+
/**
* This class encapsulates the GPU buffers. It is used to upload vertex data
* to it's GPU buffers, to bind all the buffers and to setup/teardown vertex attribute
* 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.
+ *
*/
-#include "render-renderer.h"
+// CLASS HEADER
+#include <dali/internal/render/renderers/render-renderer.h>
-#include <dali/internal/common/image-sampler.h>
-#include <dali/internal/event/common/property-input-impl.h>
-#include <dali/internal/update/common/uniform-map.h>
-#include <dali/internal/render/data-providers/render-data-provider.h>
-#include <dali/internal/render/gl-resources/texture.h>
-#include <dali/internal/render/gl-resources/texture-cache.h>
+
+// INTERNAL INCLUDES
+#include <dali/internal/render/gl-resources/context.h>
+#include <dali/internal/render/shaders/scene-graph-shader.h>
#include <dali/internal/render/shaders/program.h>
+#include <dali/internal/render/data-providers/node-data-provider.h>
+#include <dali/public-api/actors/blending.h>
+#include <dali/internal/common/image-sampler.h>
+#include <dali/internal/render/renderers/render-new-renderer.h>
namespace Dali
{
+
namespace Internal
{
-namespace SceneGraph
-{
-NewRenderer* NewRenderer::New( NodeDataProvider& nodeDataProvider,
- RenderDataProvider* dataProvider,
- RenderGeometry* renderGeometry )
+namespace
{
- return new NewRenderer(nodeDataProvider, dataProvider, renderGeometry);
-}
-
-NewRenderer::NewRenderer( NodeDataProvider& nodeDataProvider,
- RenderDataProvider* dataProvider,
- RenderGeometry* renderGeometry )
-: Renderer( nodeDataProvider ),
- mRenderDataProvider( dataProvider ),
- mRenderGeometry( renderGeometry ),
- mUpdateAttributesLocation( true )
+static Matrix gModelViewProjectionMatrix( false ); ///< a shared matrix to calculate the MVP matrix, dont want to store it in object to reduce storage overhead
+static Matrix3 gNormalMatrix; ///< a shared matrix to calculate normal matrix, dont want to store it in object to reduce storage overhead
+
+/**
+ * Helper to set view and projection matrices once per program
+ * @param program to set the matrices to
+ * @param modelMatrix to set
+ * @param viewMatrix to set
+ * @param projectionMatrix to set
+ * @param modelViewMatrix to set
+ * @param modelViewProjectionMatrix to set
+ */
+inline void SetMatrices( Program& program,
+ const Matrix& modelMatrix,
+ const Matrix& viewMatrix,
+ const Matrix& projectionMatrix,
+ const Matrix& modelViewMatrix,
+ const Matrix& modelViewProjectionMatrix )
{
-}
+ GLint loc = program.GetUniformLocation(Program::UNIFORM_MODEL_MATRIX);
+ if( Program::UNIFORM_UNKNOWN != loc )
+ {
+ program.SetUniformMatrix4fv( loc, 1, modelMatrix.AsFloat() );
+ }
+ loc = program.GetUniformLocation( Program::UNIFORM_VIEW_MATRIX );
+ if( Program::UNIFORM_UNKNOWN != loc )
+ {
+ if( program.GetViewMatrix() != &viewMatrix )
+ {
+ program.SetViewMatrix( &viewMatrix );
+ program.SetUniformMatrix4fv( loc, 1, viewMatrix.AsFloat() );
+ }
+ }
+ // set projection matrix if program has not yet received it this frame or if it is dirty
+ loc = program.GetUniformLocation( Program::UNIFORM_PROJECTION_MATRIX );
+ if( Program::UNIFORM_UNKNOWN != loc )
+ {
+ if( program.GetProjectionMatrix() != &projectionMatrix )
+ {
+ program.SetProjectionMatrix( &projectionMatrix );
+ program.SetUniformMatrix4fv( loc, 1, projectionMatrix.AsFloat() );
+ }
+ }
+ loc = program.GetUniformLocation(Program::UNIFORM_MODELVIEW_MATRIX);
+ if( Program::UNIFORM_UNKNOWN != loc )
+ {
+ program.SetUniformMatrix4fv( loc, 1, modelViewMatrix.AsFloat() );
+ }
-NewRenderer::~NewRenderer()
-{
-}
+ loc = program.GetUniformLocation( Program::UNIFORM_MVP_MATRIX );
+ if( Program::UNIFORM_UNKNOWN != loc )
+ {
+ program.SetUniformMatrix4fv( loc, 1, modelViewProjectionMatrix.AsFloat() );
+ }
-void NewRenderer::SetRenderDataProvider( RenderDataProvider* dataProvider )
-{
- mRenderDataProvider = dataProvider;
- mUpdateAttributesLocation = true;
+ loc = program.GetUniformLocation( Program::UNIFORM_NORMAL_MATRIX );
+ if( Program::UNIFORM_UNKNOWN != loc )
+ {
+ gNormalMatrix = modelViewMatrix;
+ gNormalMatrix.Invert();
+ gNormalMatrix.Transpose();
+ program.SetUniformMatrix3fv( loc, 1, gNormalMatrix.AsFloat() );
+ }
}
-void NewRenderer::SetGeometry( RenderGeometry* renderGeometry )
-{
- mRenderGeometry = renderGeometry;
- mUpdateAttributesLocation = true;
}
-// Note - this is currently called from UpdateThread, PrepareRenderInstructions,
-// as an optimisation.
-// @todo MESH_REWORK Should use Update thread objects only in PrepareRenderInstructions.
-bool NewRenderer::RequiresDepthTest() const
+namespace Render
{
- return true;
-}
-bool NewRenderer::CheckResources()
+void Renderer::Initialize( Context& context, SceneGraph::TextureCache& textureCache )
{
- // Query material to check it has texture pointers & image has size
- // Query geometry to check it has vertex buffers
-
- // General point though - why would we have a render item in RenderThread with no ready
- // resources in UpdateThread?
- return true;
+ mContext = &context;
+ mTextureCache = &textureCache;
}
-bool NewRenderer::IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix )
+Renderer::~Renderer()
{
- // @todo MESH_REWORK Add clipping
- return false;
}
-void NewRenderer::DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex )
+void Renderer::SetShader( SceneGraph::Shader* shader )
{
- // Do nothing, we're going to set up the uniforms with our own code instead
+ mShader = shader;
}
-void NewRenderer::DoSetCullFaceMode( Context& context, BufferIndex bufferIndex )
+void Renderer::SetCullFace( CullFaceMode mode )
{
+ DALI_ASSERT_DEBUG(mode >= CullNone && mode <= CullFrontAndBack);
+ mCullFaceMode = mode;
}
-void NewRenderer::DoSetBlending( Context& context, BufferIndex bufferIndex )
+void Renderer::SetSampler( unsigned int samplerBitfield )
{
- bool blend = mRenderDataProvider->GetUseBlend( bufferIndex );
- context.SetBlend( blend );
- if( blend )
- {
- const MaterialDataProvider& material = mRenderDataProvider->GetMaterial();
-
- context.SetCustomBlendColor( material.GetBlendColor( bufferIndex ) );
-
- // Set blend source & destination factors
- context.BlendFuncSeparate( material.GetBlendSrcFactorRgb( bufferIndex ),
- material.GetBlendDestFactorRgb( bufferIndex ),
- material.GetBlendSrcFactorAlpha( bufferIndex ),
- material.GetBlendDestFactorAlpha( bufferIndex ) );
-
- // Set blend equations
- context.BlendEquationSeparate( material.GetBlendEquationRgb( bufferIndex ),
- material.GetBlendEquationAlpha( bufferIndex ) );
- }
+ mSamplerBitfield = samplerBitfield;
}
-void NewRenderer::DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix )
+void Renderer::Render( Context& context,
+ SceneGraph::TextureCache& textureCache,
+ BufferIndex bufferIndex,
+ const SceneGraph::NodeDataProvider& node,
+ SceneGraph::Shader& defaultShader,
+ const Matrix& modelViewMatrix,
+ const Matrix& viewMatrix,
+ const Matrix& projectionMatrix,
+ float frametime,
+ bool cull,
+ bool blend)
{
- BindTextures( textureCache, bufferIndex, program, mRenderDataProvider->GetSamplers() );
+ // @todo MESH_REWORK Fix when merging! :D
- SetUniforms( bufferIndex, program );
+ NewRenderer* renderer = dynamic_cast<NewRenderer*>(this);
- if( mUpdateAttributesLocation || mRenderGeometry->AttributesChanged() )
+ if( renderer )
{
- mRenderGeometry->GetAttributeLocationFromProgram( mAttributesLocation, program, bufferIndex );
- mUpdateAttributesLocation = false;
+ // Get the shader from the material:
+ mShader = &renderer->mRenderDataProvider->GetShader();
}
- mRenderGeometry->UploadAndDraw( context, bufferIndex, mAttributesLocation );
-}
-
-void NewRenderer::GlContextDestroyed()
-{
- mRenderGeometry->GlContextDestroyed();
-}
-
-void NewRenderer::GlCleanup()
-{
-}
-
-void NewRenderer::SetUniforms( BufferIndex bufferIndex, Program& program )
-{
- // Check if the map has changed
- DALI_ASSERT_DEBUG( mRenderDataProvider && "No Uniform map data provider available" );
-
- const UniformMapDataProvider& uniformMapDataProvider = mRenderDataProvider->GetUniformMap();
-
- if( uniformMapDataProvider.GetUniformMapChanged( bufferIndex ) )
+ // if mShader is NULL it means we're set to default
+ if( !mShader )
{
- const CollectedUniformMap& uniformMap = uniformMapDataProvider.GetUniformMap( bufferIndex );
-
- unsigned int numberOfMaps = uniformMap.Count();
- mUniformIndexMap.Clear(); // Clear contents, but keep memory if we don't change size
- mUniformIndexMap.Resize( numberOfMaps );
-
- // Remap uniform indexes to property value addresses
- for( unsigned int mapIndex = 0 ; mapIndex < numberOfMaps ; ++mapIndex )
- {
- mUniformIndexMap[mapIndex].propertyValue = uniformMap[mapIndex]->propertyPtr;
- mUniformIndexMap[mapIndex].uniformIndex = program.RegisterUniform( uniformMap[mapIndex]->uniformName );
- }
+ mShader = &defaultShader;
}
- // Set uniforms in local map
- for( UniformIndexMappings::Iterator iter = mUniformIndexMap.Begin(),
- end = mUniformIndexMap.End() ;
- iter != end ;
- ++iter )
+ if( !CheckResources() )
{
- SetUniformFromProperty( bufferIndex, program, *iter );
+ // CheckResources() is overriden in derived classes.
+ // Prevents modify the GL state if resources are not ready and nothing is to be rendered.
+ return;
}
- // @todo MESH_REWORK On merge, copy code from renderer to setup standard matrices and color
+ // Calculate the MVP matrix first so we can do the culling test
+ const Matrix& modelMatrix = node.GetModelMatrix( bufferIndex );
+ Matrix::Multiply( gModelViewProjectionMatrix, modelViewMatrix, projectionMatrix );
- GLint sizeLoc = program.GetUniformLocation( Program::UNIFORM_SIZE );
- if( -1 != sizeLoc )
+ // Get the program to use:
+ Program* program = mShader->GetProgram();
+ if( !program )
{
- Vector3 size = mDataProvider.GetRenderSize( bufferIndex );
- program.SetUniform3f( sizeLoc, size.x, size.y, size.z );
+ // if program is NULL it means this is a custom shader with non matching geometry type so we need to use default shaders program
+ program = defaultShader.GetProgram();
+ DALI_ASSERT_DEBUG( program && "Default shader should always have a program available." );
+ if( !program )
+ {
+ DALI_LOG_ERROR( "Failed to get program for shader at address %p.", (void*) &*mShader );
+ return;
+ }
+
}
-}
-void NewRenderer::SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map )
-{
- GLint location = program.GetUniformLocation(map.uniformIndex);
- if( Program::UNIFORM_UNKNOWN != location )
+ // Check culling (does not need the program to be in use)
+ if( cull && ! program->ModifiesGeometry() )
{
- // switch based on property type to use correct GL uniform setter
- switch ( map.propertyValue->GetType() )
+ if( IsOutsideClipSpace( context, gModelViewProjectionMatrix ) )
{
- case Property::INTEGER:
- {
- program.SetUniform1i( location, map.propertyValue->GetInteger( bufferIndex ) );
- break;
- }
- case Property::FLOAT:
- {
- program.SetUniform1f( location, map.propertyValue->GetFloat( bufferIndex ) );
- break;
- }
- case Property::VECTOR2:
- {
- Vector2 value( map.propertyValue->GetVector2( bufferIndex ) );
- program.SetUniform2f( location, value.x, value.y );
- break;
- }
-
- case Property::VECTOR3:
- {
- Vector3 value( map.propertyValue->GetVector3( bufferIndex ) );
- program.SetUniform3f( location, value.x, value.y, value.z );
- break;
- }
-
- case Property::VECTOR4:
- {
- Vector4 value( map.propertyValue->GetVector4( bufferIndex ) );
- program.SetUniform4f( location, value.x, value.y, value.z, value.w );
- break;
- }
-
- case Property::ROTATION:
- {
- Quaternion value( map.propertyValue->GetQuaternion( bufferIndex ) );
- program.SetUniform4f( location, value.mVector.x, value.mVector.y, value.mVector.z, value.mVector.w );
- break;
- }
-
- case Property::MATRIX:
- {
- const Matrix& value = map.propertyValue->GetMatrix(bufferIndex);
- program.SetUniformMatrix4fv(location, 1, value.AsFloat() );
- break;
- }
-
- case Property::MATRIX3:
- {
- const Matrix3& value = map.propertyValue->GetMatrix3(bufferIndex);
- program.SetUniformMatrix3fv(location, 1, value.AsFloat() );
- break;
- }
-
- default:
- {
- // Other property types are ignored
- break;
- }
+ // don't do any further gl state changes as this renderer is not visible
+ return;
}
}
-}
-void NewRenderer::BindTextures(
- TextureCache& textureCache,
- BufferIndex bufferIndex,
- Program& program,
- const RenderDataProvider::Samplers& samplers )
-{
- // @todo MESH_REWORK Write a cache of texture units to commonly used sampler textures
- unsigned int textureUnit = 0;
+ // Take the program into use so we can send uniforms to it
+ program->Use();
- for( RenderDataProvider::Samplers::Iterator iter = samplers.Begin();
- iter != samplers.End();
- ++iter )
- {
- const SamplerDataProvider* sampler = *iter;
- ResourceId textureId = sampler->GetTextureId(bufferIndex);
- Texture* texture = textureCache.GetTexture( textureId );
- if( texture != NULL )
- {
- unsigned int textureUnitUniformIndex = GetTextureUnitUniformIndex( program, *sampler );
- TextureUnit theTextureUnit = static_cast<TextureUnit>(textureUnit);
- BindTexture( textureCache, program, textureId, texture, theTextureUnit, textureUnitUniformIndex );
- ApplySampler( bufferIndex, texture, theTextureUnit, *sampler );
- }
+ DoSetCullFaceMode( context, bufferIndex );
- ++textureUnit;
- }
-}
+ DoSetBlending( context, bufferIndex, blend );
-void NewRenderer::BindTexture(
- TextureCache& textureCache,
- Program& program,
- ResourceId id,
- Texture* texture,
- TextureUnit textureUnit,
- unsigned int textureUnitUniformIndex )
-{
- if( texture != NULL )
- {
- textureCache.BindTexture( texture, id, GL_TEXTURE_2D, textureUnit );
+ // Ignore missing uniforms - custom shaders and flat color shaders don't have SAMPLER
+ // set projection and view matrix if program has not yet received them yet this frame
+ SetMatrices( *program, modelMatrix, viewMatrix, projectionMatrix, modelViewMatrix, gModelViewProjectionMatrix );
- // Set sampler uniform location for the texture
- GLint textureUnitLoc = program.GetUniformLocation( textureUnitUniformIndex );
- if( Program::UNIFORM_UNKNOWN != textureUnitLoc )
- {
- program.SetUniform1i( textureUnitLoc, textureUnit );
- }
+ // set color uniform
+ GLint loc = program->GetUniformLocation( Program::UNIFORM_COLOR );
+ if( Program::UNIFORM_UNKNOWN != loc )
+ {
+ const Vector4& color = node.GetRenderColor( bufferIndex );
+ program->SetUniform4f( loc, color.r, color.g, color.b, color.a );
+ }
+ loc = program->GetUniformLocation(Program::UNIFORM_TIME_DELTA);
+ if( Program::UNIFORM_UNKNOWN != loc )
+ {
+ program->SetUniform1f( loc, frametime );
}
-}
-
-void NewRenderer::ApplySampler(
- BufferIndex bufferIndex,
- Texture* texture,
- TextureUnit textureUnit,
- const SamplerDataProvider& sampler )
-{
- unsigned int samplerBitfield = ImageSampler::PackBitfield(
- static_cast< FilterMode::Type >(sampler.GetMinifyFilterMode(bufferIndex)),
- static_cast< FilterMode::Type >(sampler.GetMagnifyFilterMode(bufferIndex)) );
- texture->ApplySampler( textureUnit, samplerBitfield );
+ //@todo MESH_REWORK Remove after removing ImageRenderer
+ DoSetUniforms(context, bufferIndex, mShader, program );
- // @todo MESH_REWORK add support for wrap modes
+ // subclass rendering and actual draw call
+ DoRender( context, textureCache, node, bufferIndex, *program, modelViewMatrix, viewMatrix );
}
-unsigned int NewRenderer::GetTextureUnitUniformIndex(
- Program& program,
- const SamplerDataProvider& sampler )
+void Renderer::SetSortAttributes( SceneGraph::RendererWithSortAttributes& sortAttributes ) const
{
- // Find sampler in mSamplerNameCache
- // If it doesn't exist,
- // get the index by calling program.RegisterUniform and store it
- // If it exists, it's index should be set.
- // @todo Cache should be reset on scene change
-
- unsigned int uniformIndex = 0;
- bool found = false;
+ sortAttributes.shader = mShader;
+ sortAttributes.material = NULL;
+ sortAttributes.geometry = NULL;
+}
- for( unsigned int i=0; i< mTextureUnitUniforms.Count(); ++i )
- {
- if( mTextureUnitUniforms[i].sampler == &sampler )
- {
- uniformIndex = mTextureUnitUniforms[i].index;
- found = true;
- }
- }
+// can be overridden by deriving class
+void Renderer::DoSetUniforms(Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program )
+{
+ shader->SetUniforms( context, *program, bufferIndex );
+}
- if( ! found )
- {
- TextureUnitUniformIndex textureUnitUniformIndex;
- textureUnitUniformIndex.sampler = &sampler;
- textureUnitUniformIndex.index = program.RegisterUniform( sampler.GetTextureUnitUniformName() );
- mTextureUnitUniforms.PushBack( textureUnitUniformIndex );
- uniformIndex = textureUnitUniformIndex.index;
- }
+// can be overridden by deriving class
+void Renderer::DoSetCullFaceMode(Context& context, BufferIndex bufferIndex )
+{
+ // Set face culling mode
+ context.CullFace( mCullFaceMode );
+}
- return uniformIndex;
+Renderer::Renderer()
+: mContext(NULL),
+ mTextureCache( NULL ),
+ mShader( NULL ),
+ mSamplerBitfield( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ),
+ mCullFaceMode( CullNone )
+{
}
+} // namespace SceneGraph
+
+} // namespace Internal
-} // SceneGraph
-} // Internal
-} // Dali
+} // namespace Dali
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__
+#ifndef __DALI_INTERNAL_RENDER_RENDERER_H__
+#define __DALI_INTERNAL_RENDER_RENDERER_H__
/*
* Copyright (c) 2015 Samsung Electronics Co., Ltd.
*
*/
-#include <dali/integration-api/resource-declarations.h> // For resource id
-#include <dali/internal/common/owner-pointer.h>
-#include <dali/internal/render/data-providers/render-data-provider.h>
-#include <dali/internal/render/gl-resources/texture-units.h>
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
-#include <dali/internal/render/renderers/render-geometry.h>
+// INTERNAL INCLUDES
+#include <dali/public-api/math/matrix.h>
+#include <dali/public-api/math/vector4.h>
+#include <dali/internal/common/blending-options.h>
+#include <dali/internal/common/message.h>
+#include <dali/internal/event/effects/shader-declarations.h>
+#include <dali/internal/render/gl-resources/gl-resource-owner.h>
+#include <dali/integration-api/debug.h>
+#include <dali/internal/common/type-abstraction-enums.h>
+#include <dali/internal/update/manager/prepare-render-instructions.h>
namespace Dali
{
+
namespace Internal
{
-class PropertyInputImpl;
+class Context;
+class Texture;
+class Program;
namespace SceneGraph
{
+class SceneController;
+class Shader;
+class TextureCache;
+class NodeDataProvider;
+}
+
+
+namespace Render
+{
+
/**
- * The new geometry renderer.
- *
- * @todo MESH_REWORK It will be merged into the base class eventually
+ * Renderers are used to render meshes
+ * These objects are used during RenderManager::Render(), so properties modified during
+ * the Update must either be double-buffered, or set via a message added to the RenderQueue.
*/
-class NewRenderer : public Renderer
+class Renderer : public GlResourceOwner
{
public:
- typedef Integration::ResourceId ResourceId;
-public:
/**
- * Create a new renderer instance
- * @param[in] nodeDataProvider The node data provider
- * @param[in] dataProviders The data providers for the renderer
- * @param[in] renderGeometry The geometry for the renderer
+ * Second-phase construction.
+ * This is called when the renderer is inside render thread
+ * @param[in] textureCache to use
*/
- static NewRenderer* New( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders, RenderGeometry* renderGeometry );
- /**
- * Constructor.
- * @param[in] nodeDataProvider The node data provider
- * @param[in] dataProviders The data providers for the renderer
- * @param[in] renderGeometry The geometry for the renderer
- */
- NewRenderer( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders, RenderGeometry* renderGeometry );
-
- virtual ~NewRenderer();
+ void Initialize( Context& context, SceneGraph::TextureCache& textureCache );
/**
- * Change the data providers of the renderer
- * @param[in] dataProviders The data providers
+ * Virtual destructor
*/
- void SetRenderDataProvider( RenderDataProvider* dataProviders );
+ virtual ~Renderer();
/**
- * Change the geometry used by the renderer
- * @param[in] renderGeometry The new geometry
+ * Set the Shader used to render.
+ * @param[in] shader The shader used to render.
*/
- void SetGeometry( RenderGeometry* renderGeometry );
+ void SetShader( SceneGraph::Shader* shader );
-public: // Implementation of Renderer
/**
- * @copydoc SceneGraph::Renderer::RequiresDepthTest()
+ * Set the face-culling mode.
+ * @param[in] mode The face-culling mode.
*/
- virtual bool RequiresDepthTest() const;
+ void SetCullFace( CullFaceMode mode );
/**
- * @copydoc SceneGraph::Renderer::CheckResources()
+ * Set the sampler used to render the set texture.
+ * @param[in] samplerBitfield The packed sampler options used to render.
*/
- virtual bool CheckResources();
+ void SetSampler( unsigned int samplerBitfield );
/**
- * @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
+ * Query whether the derived type of Renderer requires depth testing.
+ * @return True if the renderer requires depth testing.
*/
- virtual bool IsOutsideClipSpace( Context& context,
- const Matrix& modelMatrix,
- const Matrix& modelViewProjectionMatrix );
+ virtual bool RequiresDepthTest() const = 0;
/**
- * @copydoc SceneGraph::Renderer::DoSetUniforms()
+ * Called to render during RenderManager::Render().
+ * @param[in] context The context used for rendering
+ * @param[in] textureCache The texture cache used to get textures
+ * @param[in] bufferIndex The index of the previous update buffer.
+ * @param[in] node The node using this renderer
+ * @param[in] defaultShader in case there is no custom shader
+ * @param[in] modelViewMatrix The model-view matrix.
+ * @param[in] viewMatrix The view matrix.
+ * @param[in] projectionMatrix The projection matrix.
+ * @param[in] frametime The elapsed time between the last two updates.
+ * @param[in] cull Whether to frustum cull this renderer
*/
- virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex );
+ void Render( Context& context,
+ SceneGraph::TextureCache& textureCache,
+ BufferIndex bufferIndex,
+ const SceneGraph::NodeDataProvider& node,
+ SceneGraph::Shader& defaultShader,
+ const Matrix& modelViewMatrix,
+ const Matrix& viewMatrix,
+ const Matrix& projectionMatrix,
+ float frametime,
+ bool cull,
+ bool blend);
/**
- * @copydoc SceneGraph::Renderer::DoSetCullFaceMode
+ * Write the renderer's sort attributes to the passed in reference
+ *
+ * @param[in] bufferIndex The current update buffer index.
+ * @param[out] sortAttributes
*/
- virtual void DoSetCullFaceMode(Context& context, BufferIndex bufferIndex );
+ virtual void SetSortAttributes( SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
+protected:
/**
- * @copydoc SceneGraph::Renderer::DoSetBlending
+ * Protected constructor; only derived classes can be instantiated.
+ * @param dataprovider for rendering
*/
- virtual void DoSetBlending(Context& context, BufferIndex bufferIndex );
+ Renderer();
- /**
- * @copydoc SceneGraph::Renderer::DoRender()
- */
- virtual void DoRender( Context& context,
- TextureCache& textureCache,
- BufferIndex bufferIndex,
- Program& program,
- const Matrix& modelViewMatrix,
- const Matrix& viewMatrix );
+private:
-public: // Implementation of GlResourceOwner
+ // Undefined
+ Renderer( const Renderer& );
- /**
- * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
- */
- virtual void GlContextDestroyed();
+ // Undefined
+ Renderer& operator=( const Renderer& rhs );
/**
- * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
+ * Checks if renderer's resources are ready to be used.
+ *
+ * @return \e true if they are. Otherwise \e false.
*/
- virtual void GlCleanup();
-
-private:
- struct UniformIndexMap;
+ virtual bool CheckResources() = 0;
/**
- * Set the uniforms from properties according to the uniform map
- * @param[in] program The shader program on which to set the uniforms.
+ * Checks if renderer is culled.
+ * @param[in] modelViewProjectionMatrix The MVP matrix.
+ * @return \e true if it is. Otherwise \e false.
*/
- void SetUniforms( BufferIndex bufferIndex, Program& program );
+ virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelViewProjectionMatrix ) = 0;
/**
- * Set the program uniform in the map from the mapped property
+ * Called from Render prior to DoRender().
+ * @todo MESH_REWORK Remove after merge
*/
- void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
+ virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program );
/**
- * Bind the material textures in the samplers and setup the samplers
- * @param[in] textureCache The texture cache
- * @param[in] bufferIndex The buffer index
- * @param[in] program The shader program
- * @param[in] samplers The samplers to bind
+ * Called from Render prior to DoRender(). Default method to set CullFaceMode
+ * @todo MESH_REWORK Remove after merge
*/
- void BindTextures( TextureCache& textureCache,
- BufferIndex bufferIndex,
- Program& program,
- const RenderDataProvider::Samplers& samplers );
+ virtual void DoSetCullFaceMode( Context& context, BufferIndex bufferIndex );
/**
- * Bind a material texture to a texture unit, and set the sampler's texture uniform
- * to that texture unit.
- * @param[in] textureCache The texture cache
- * @param[in] program The shader program
- * @param[in] id The resource id of the texture to bind
- * @param[in] texture The texture to bind
- * @param[in] textureUnit The texture unit index to use
- * @param[in] nameIndex The index of the texture uniform in the program
+ * Called from Render prior to DoRender(). Default method to set blending options
+ * @todo MESH_REWORK Remove after merge
*/
- void BindTexture( TextureCache& textureCache,
- Program& program,
- ResourceId id,
- Texture* texture,
- TextureUnit textureUnit,
- unsigned int nameIndex );
+ virtual void DoSetBlending( Context& context, BufferIndex bufferIndex, bool blend ) = 0;
/**
- * Apply the sampler modes to the texture.
- * @param[in] bufferIndex The current buffer index
- * @param[in] texture The texture to which to apply the sampler modes
- * @param[in] textureUnit The texture unit of the texture
- * @param[in] sampler The sampler from which to get the modes.
+ * Called from Render; implemented in derived classes.
+ * @param[in] context The context used for rendering
+ * @param[in] textureCache The texture cache used to get textures
+ * @param[in] bufferIndex The index of the previous update buffer.
+ * @param[in] program to use.
+ * @param[in] modelViewMatrix The model-view matrix.
+ * @param[in] viewMatrix The view matrix.
*/
- void ApplySampler( BufferIndex bufferIndex,
- Texture* texture,
- TextureUnit textureUnit,
- const SamplerDataProvider& sampler );
+ virtual void DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
- /**
- * Get the texture uniform index of the name sampler in the program.
- * If not already registered in the program, then this performs the registration
- * @param[in] program The shader program
- * @param[in] sampler The sampler holding a texture unit uniform name to search for
- * @return The texture uniform index in the program
- */
- unsigned int GetTextureUnitUniformIndex( Program& program,
- const SamplerDataProvider& sampler );
+protected:
-public: //@todo MESH_REWORK make private after merge with SceneGraph::Renderer
- OwnerPointer< RenderDataProvider > mRenderDataProvider;
+ Context* mContext;
+ SceneGraph::TextureCache* mTextureCache;
+ SceneGraph::Shader* mShader;
+ unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering
private:
- RenderGeometry* mRenderGeometry;
- struct TextureUnitUniformIndex
- {
- const SamplerDataProvider* sampler;
- unsigned int index;
- };
-
- typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms;
- TextureUnitUniforms mTextureUnitUniforms;
-
- struct UniformIndexMap
- {
- unsigned int uniformIndex; // The index of the cached location in the Program
- const PropertyInputImpl* propertyValue;
- };
-
- typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
- UniformIndexMappings mUniformIndexMap;
-
- Vector<GLint> mAttributesLocation;
- bool mUpdateAttributesLocation;
-
- bool mUseBlend:1; ///< True if blending should be enabled, 1 bit is enough
+ CullFaceMode mCullFaceMode:3; ///< cullface enum, 3 bits is enough
};
+} // namespace SceneGraph
+
+} // namespace Internal
-} // SceneGraph
-} // Internal
-} // Dali
+} // namespace Dali
-#endif // __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__
+#endif // __DALI_INTERNAL_RENDER_RENDERER_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.
- */
-
-#include "scene-graph-renderer-debug.h"
-#include <dali/internal/common/shader-data.h>
-#include <dali/integration-api/resource-declarations.h>
-#include <dali/internal/render/shaders/program.h>
-#include <dali/internal/render/gl-resources/context.h>
-#include <dali/internal/render/data-providers/node-data-provider.h>
-#include <dali/internal/render/gl-resources/gpu-buffer.h>
-
-namespace Dali
-{
-namespace Internal
-{
-namespace SceneGraph
-{
-
-namespace
-{
-/* rewritten in another patch
-#if defined ( DEBUG_ENABLED )
-
-// Create shader for debug drawing
-const std::string DEBUG_DRAW_VERTEX_SHADER(
- "attribute mediump vec3 aPosition;\n"
- "uniform mediump mat4 uMvpMatrix;\n"
- "void main()\n"
- "{\n"
- " gl_Position = uMvpMatrix * vec4(aPosition, 1.0);\n"
- "}\n" );
-
-const std::string DEBUG_DRAW_FRAGMENT_SHADER(
- "uniform lowp vec4 uColor;\n"
- "void main()\n"
- "{\n"
- " gl_FragColor = uColor;\n"
- "}\n" );
-
-static Program* gDebugProgram(NULL); ///< a simple debug shader
-
-#endif
-*/
-} // anonymous namespace
-
-void DebugBoundingBox(Context& context, Rect<float> boundingBox, const Matrix& mvp)
-{
-/* rewritten in another patch
-#if defined ( DEBUG_ENABLED )
- if( gDebugProgram == NULL )
- {
- Internal::ShaderDataPtr shaderData( new Internal::ShaderData( DEBUG_DRAW_VERTEX_SHADER, DEBUG_DRAW_FRAGMENT_SHADER ) );
- gDebugProgram = Program::New( shaderData.Get(), context, true );
- }
-
- context.SetBlend( false );
- context.CullFace( CullNone );
-
- const unsigned int numPoints=8;
- GLfloat vertices[numPoints*3] = {
- boundingBox.x, boundingBox.y, 0.0f,
- boundingBox.x, boundingBox.y + boundingBox.height, 0.0f,
-
- boundingBox.x, boundingBox.y + boundingBox.height, 0.0f,
- boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height, 0.0f,
-
- boundingBox.x + boundingBox.width, boundingBox.y + boundingBox.height, 0.0f,
- boundingBox.x + boundingBox.width, boundingBox.y, 0.0f,
-
- boundingBox.x + boundingBox.width, boundingBox.y, 0.0f,
- boundingBox.x, boundingBox.y, 0.0f,
- };
-
- gDebugProgram->Use();
-
- GpuBuffer vertexBuffer(context,GpuBuffer::ARRAY_BUFFER, GpuBuffer::STATIC_DRAW);
- vertexBuffer.UpdateDataBuffer(numPoints * 3 * sizeof(float), &vertices[0]);
- vertexBuffer.Bind();
-
- GLint positionLoc = gDebugProgram->GetAttribLocation(Program::ATTRIB_POSITION);
- context.VertexAttribPointer( positionLoc, 3, GL_FLOAT, GL_FALSE, 3*sizeof(float), 0 );
- context.EnableVertexAttributeArray( positionLoc );
-
- GLint mvpLoc = gDebugProgram->GetUniformLocation(Program::UNIFORM_MVP_MATRIX);
- if( mvpLoc != Program::UNIFORM_UNKNOWN )
- {
- gDebugProgram->SetUniformMatrix4fv( mvpLoc, 1, mvp.AsFloat() );
- }
- GLint colorLoc = gDebugProgram->GetUniformLocation(Program::UNIFORM_COLOR);
- if( colorLoc != Program::UNIFORM_UNKNOWN )
- {
- gDebugProgram->SetUniform4f( colorLoc, 0.0f, 1.0f, 1.0f, 1.0f );
- }
-
- context.DrawArrays(GL_LINES, 0, numPoints);
-
- context.DisableVertexAttributeArray( positionLoc );
-#endif
-*/
-}
-
-
-} // SceneGraph
-} // Internal
-} // Dali
+++ /dev/null
-#ifndef __DALI_INTERNAL_SCENEGRAPH_RENDERER_DEBUG_H__
-#define __DALI_INTERNAL_SCENEGRAPH_RENDERER_DEBUG_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.
- */
-
-#include <dali/public-api/math/matrix.h>
-#include <dali/public-api/math/rect.h>
-
-// Uncomment to debug bounding boxes of objects
-//#define DEBUG_DISPLAY_BOUNDING_BOX 1
-
-namespace Dali
-{
-namespace Internal
-{
-class Context;
-
-namespace SceneGraph
-{
-class NodeDataProvider;
-
-void DebugBoundingBox(Context& context, Rect<float> boundingBox, const Matrix& mvp);
-
-#if defined(DEBUG_ENABLED) && defined(DEBUG_DISPLAY_BOUNDING_BOX)
-#define DEBUG_BOUNDING_BOX( context, boundingBox, mvp ) \
- DebugBoundingBox( context, boundingBox, mvp )
-#else
-#define DEBUG_BOUNDING_BOX( context, boundingBox, mvp )
-#endif
-
-} // SceneGraph
-} // Internal
-} // Dali
-
-
-#endif // __DALI_INTERNAL_SCENEGRAPH_RENDERER_DEBUG_H__
+++ /dev/null
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDERER_DECLARATIONS_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_RENDERER_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/public-api/common/vector-wrapper.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace SceneGraph
-{
-
-class Renderer;
-
-typedef std::vector<Renderer*> RendererContainer;
-typedef RendererContainer::iterator RendererIter;
-
-enum EffectType
-{
- NO_EFFECT,
- SHADOW_EFFECT,
- REFLECT_EFFECT
-};
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
-
-#endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERER_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/render/renderers/scene-graph-renderer.h>
-#include <dali/internal/render/renderers/scene-graph-renderer-declarations.h>
-
-// INTERNAL INCLUDES
-#include <dali/internal/render/gl-resources/context.h>
-#include <dali/internal/render/shaders/scene-graph-shader.h>
-#include <dali/internal/render/shaders/program.h>
-#include <dali/internal/render/renderers/scene-graph-renderer-debug.h>
-#include <dali/internal/render/data-providers/node-data-provider.h>
-#include <dali/public-api/actors/blending.h>
-#include <dali/internal/common/image-sampler.h>
-#include <dali/internal/render/renderers/render-renderer.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-
-namespace
-{
-
-static Matrix gModelViewProjectionMatrix( false ); ///< a shared matrix to calculate the MVP matrix, dont want to store it in object to reduce storage overhead
-static Matrix3 gNormalMatrix; ///< a shared matrix to calculate normal matrix, dont want to store it in object to reduce storage overhead
-
-/**
- * Helper to set view and projection matrices once per program
- * @param program to set the matrices to
- * @param modelMatrix to set
- * @param viewMatrix to set
- * @param projectionMatrix to set
- * @param modelViewMatrix to set
- * @param modelViewProjectionMatrix to set
- */
-inline void SetMatrices( Program& program,
- const Matrix& modelMatrix,
- const Matrix& viewMatrix,
- const Matrix& projectionMatrix,
- const Matrix& modelViewMatrix,
- const Matrix& modelViewProjectionMatrix )
-{
- GLint loc = program.GetUniformLocation(Program::UNIFORM_MODEL_MATRIX);
- if( Program::UNIFORM_UNKNOWN != loc )
- {
- program.SetUniformMatrix4fv( loc, 1, modelMatrix.AsFloat() );
- }
- loc = program.GetUniformLocation( Program::UNIFORM_VIEW_MATRIX );
- if( Program::UNIFORM_UNKNOWN != loc )
- {
- if( program.GetViewMatrix() != &viewMatrix )
- {
- program.SetViewMatrix( &viewMatrix );
- program.SetUniformMatrix4fv( loc, 1, viewMatrix.AsFloat() );
- }
- }
- // set projection matrix if program has not yet received it this frame or if it is dirty
- loc = program.GetUniformLocation( Program::UNIFORM_PROJECTION_MATRIX );
- if( Program::UNIFORM_UNKNOWN != loc )
- {
- if( program.GetProjectionMatrix() != &projectionMatrix )
- {
- program.SetProjectionMatrix( &projectionMatrix );
- program.SetUniformMatrix4fv( loc, 1, projectionMatrix.AsFloat() );
- }
- }
- loc = program.GetUniformLocation(Program::UNIFORM_MODELVIEW_MATRIX);
- if( Program::UNIFORM_UNKNOWN != loc )
- {
- program.SetUniformMatrix4fv( loc, 1, modelViewMatrix.AsFloat() );
- }
-
- loc = program.GetUniformLocation( Program::UNIFORM_MVP_MATRIX );
- if( Program::UNIFORM_UNKNOWN != loc )
- {
- program.SetUniformMatrix4fv( loc, 1, modelViewProjectionMatrix.AsFloat() );
- }
-
- loc = program.GetUniformLocation( Program::UNIFORM_NORMAL_MATRIX );
- if( Program::UNIFORM_UNKNOWN != loc )
- {
- gNormalMatrix = modelViewMatrix;
- gNormalMatrix.Invert();
- gNormalMatrix.Transpose();
- program.SetUniformMatrix3fv( loc, 1, gNormalMatrix.AsFloat() );
- }
-}
-
-}
-
-namespace SceneGraph
-{
-
-void Renderer::Initialize( Context& context, TextureCache& textureCache )
-{
- mContextDELETEME = &context;
- mTextureCacheDELETEME = &textureCache;
-}
-
-Renderer::~Renderer()
-{
-}
-
-void Renderer::SetShader( Shader* shader )
-{
- mShader = shader;
-}
-
-void Renderer::SetCullFace( CullFaceMode mode )
-{
- DALI_ASSERT_DEBUG(mode >= CullNone && mode <= CullFrontAndBack);
- mCullFaceMode = mode;
-}
-
-void Renderer::SetSampler( unsigned int samplerBitfield )
-{
- mSamplerBitfield = samplerBitfield;
-}
-
-void Renderer::Render( Context& context,
- TextureCache& textureCache,
- BufferIndex bufferIndex,
- Shader& defaultShader,
- const Matrix& modelViewMatrix,
- const Matrix& viewMatrix,
- const Matrix& projectionMatrix,
- float frametime,
- bool cull )
-{
- // @todo MESH_REWORK Fix when merging! :D
- NewRenderer* renderer = dynamic_cast<NewRenderer*>(this);
- if( renderer )
- {
- // Get the shader from the material:
- mShader = &renderer->mRenderDataProvider->GetShader();
- }
-
- // if mShader is NULL it means we're set to default
- if( !mShader )
- {
- mShader = &defaultShader;
- }
-
- if( !CheckResources() )
- {
- // CheckResources() is overriden in derived classes.
- // Prevents modify the GL state if resources are not ready and nothing is to be rendered.
- return;
- }
-
- // Calculate the MVP matrix first so we can do the culling test
- const Matrix& modelMatrix = mDataProvider.GetModelMatrix( bufferIndex );
- Matrix::Multiply( gModelViewProjectionMatrix, modelViewMatrix, projectionMatrix );
-
- // Get the program to use:
- Program* program = mShader->GetProgram();
- if( !program )
- {
- // if program is NULL it means this is a custom shader with non matching geometry type so we need to use default shaders program
- program = defaultShader.GetProgram();
- DALI_ASSERT_DEBUG( program && "Default shader should always have a program available." );
- if( !program )
- {
- DALI_LOG_ERROR( "Failed to get program for shader at address %p.", (void*) &*mShader );
- return;
- }
-
- }
-
- // Check culling (does not need the program to be in use)
- if( cull && ! program->ModifiesGeometry() )
- {
- if( IsOutsideClipSpace( context, modelMatrix, gModelViewProjectionMatrix ) )
- {
- // don't do any further gl state changes as this renderer is not visible
- return;
- }
- }
-
- // Take the program into use so we can send uniforms to it
- program->Use();
-
- DoSetCullFaceMode( context, bufferIndex );
-
- DoSetBlending( context, bufferIndex );
-
- // Ignore missing uniforms - custom shaders and flat color shaders don't have SAMPLER
- // set projection and view matrix if program has not yet received them yet this frame
- SetMatrices( *program, modelMatrix, viewMatrix, projectionMatrix, modelViewMatrix, gModelViewProjectionMatrix );
-
- // set color uniform
- GLint loc = program->GetUniformLocation( Program::UNIFORM_COLOR );
- if( Program::UNIFORM_UNKNOWN != loc )
- {
- const Vector4& color = mDataProvider.GetRenderColor( bufferIndex );
- program->SetUniform4f( loc, color.r, color.g, color.b, color.a );
- }
- loc = program->GetUniformLocation(Program::UNIFORM_TIME_DELTA);
- if( Program::UNIFORM_UNKNOWN != loc )
- {
- program->SetUniform1f( loc, frametime );
- }
-
- //@todo MESH_REWORK Remove after removing ImageRenderer
- DoSetUniforms(context, bufferIndex, mShader, program );
-
- // subclass rendering and actual draw call
- DoRender( context, textureCache, bufferIndex, *program, modelViewMatrix, viewMatrix );
-}
-
-// can be overridden by deriving class
-void Renderer::DoSetUniforms(Context& context, BufferIndex bufferIndex, Shader* shader, Program* program )
-{
- shader->SetUniforms( context, *program, bufferIndex );
-}
-
-// can be overridden by deriving class
-void Renderer::DoSetCullFaceMode(Context& context, BufferIndex bufferIndex )
-{
- // Set face culling mode
- context.CullFace( mCullFaceMode );
-}
-
-Renderer::Renderer( NodeDataProvider& dataprovider )
-: mDataProvider( dataprovider ),
- mContextDELETEME(NULL),
- mTextureCacheDELETEME( NULL ),
- mShader( NULL ),
- mSamplerBitfield( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ),
- mCullFaceMode( CullNone )
-{
-}
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
+++ /dev/null
-#ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__
-#define __DALI_INTERNAL_SCENE_GRAPH_RENDERER_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/matrix.h>
-#include <dali/public-api/math/vector4.h>
-#include <dali/internal/common/blending-options.h>
-#include <dali/internal/common/message.h>
-#include <dali/internal/event/effects/shader-declarations.h>
-#include <dali/internal/render/gl-resources/gl-resource-owner.h>
-#include <dali/internal/render/renderers/scene-graph-renderer-declarations.h>
-#include <dali/integration-api/debug.h>
-#include <dali/internal/common/type-abstraction-enums.h>
-
-namespace Dali
-{
-
-namespace Internal
-{
-class Context;
-class Texture;
-class Program;
-
-namespace SceneGraph
-{
-class SceneController;
-class Shader;
-class TextureCache;
-class NodeDataProvider;
-
-/**
- * Renderers are used to render images, text, & meshes etc.
- * These objects are used during RenderManager::Render(), so properties modified during
- * the Update must either be double-buffered, or set via a message added to the RenderQueue.
- */
-class Renderer : public GlResourceOwner
-{
-public:
-
- /**
- * Second-phase construction.
- * This is called when the renderer is inside render thread
- * @param[in] textureCache to use
- */
- void Initialize( Context& context, TextureCache& textureCache );
-
- /**
- * Virtual destructor
- */
- virtual ~Renderer();
-
- /**
- * Set the Shader used to render.
- * @param[in] shader The shader used to render.
- */
- void SetShader( Shader* shader );
-
- /**
- * Set the face-culling mode.
- * @param[in] mode The face-culling mode.
- */
- void SetCullFace( CullFaceMode mode );
-
- /**
- * Set the sampler used to render the set texture.
- * @param[in] samplerBitfield The packed sampler options used to render.
- */
- void SetSampler( unsigned int samplerBitfield );
-
- /**
- * Query whether the derived type of Renderer requires depth testing.
- * @return True if the renderer requires depth testing.
- */
- virtual bool RequiresDepthTest() const = 0;
-
- /**
- * Called to render during RenderManager::Render().
- * @param[in] context The context used for rendering
- * @param[in] textureCache The texture cache used to get textures
- * @param[in] bufferIndex The index of the previous update buffer.
- * @param[in] defaultShader in case there is no custom shader
- * @param[in] modelViewMatrix The model-view matrix.
- * @param[in] viewMatrix The view matrix.
- * @param[in] projectionMatrix The projection matrix.
- * @param[in] frametime The elapsed time between the last two updates.
- * @param[in] cull Whether to frustum cull this renderer
- */
- void Render( Context& context,
- TextureCache& textureCache,
- BufferIndex bufferIndex,
- Shader& defaultShader,
- const Matrix& modelViewMatrix,
- const Matrix& viewMatrix,
- const Matrix& projectionMatrix,
- float frametime,
- bool cull );
-
-protected:
- /**
- * Protected constructor; only derived classes can be instantiated.
- * @param dataprovider for rendering
- */
- Renderer( NodeDataProvider& dataprovider );
-
-private:
-
- // Undefined
- Renderer( const Renderer& );
-
- // Undefined
- Renderer& operator=( const Renderer& rhs );
-
- /**
- * Checks if renderer's resources are ready to be used.
- *
- * @return \e true if they are. Otherwise \e false.
- */
- virtual bool CheckResources() = 0;
-
- /**
- * Checks if renderer is culled.
- * @param[in] modelMatrix The model matrix.
- * @param[in] modelViewProjectionMatrix The MVP matrix.
- * @return \e true if it is. Otherwise \e false.
- */
- virtual bool IsOutsideClipSpace( Context& context, const Matrix& modelMatrix, const Matrix& modelViewProjectionMatrix ) = 0;
-
- /**
- * Called from Render prior to DoRender().
- * @todo MESH_REWORK Remove after merge
- */
- virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program );
-
- /**
- * Called from Render prior to DoRender(). Default method to set CullFaceMode
- * @todo MESH_REWORK Remove after merge
- */
- virtual void DoSetCullFaceMode( Context& context, BufferIndex bufferIndex );
-
- /**
- * Called from Render prior to DoRender(). Default method to set blending options
- * @todo MESH_REWORK Remove after merge
- */
- virtual void DoSetBlending( Context& context, BufferIndex bufferIndex ) = 0;
-
- /**
- * Called from Render; implemented in derived classes.
- * @param[in] context The context used for rendering
- * @param[in] textureCache The texture cache used to get textures
- * @param[in] bufferIndex The index of the previous update buffer.
- * @param[in] program to use.
- * @param[in] modelViewMatrix The model-view matrix.
- * @param[in] viewMatrix The view matrix.
- */
- virtual void DoRender( Context& context, TextureCache& textureCache, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0;
-
-protected:
-
- NodeDataProvider& mDataProvider; // @todo MESH_REWORK rename to mNodeDataProvider. Shouldn't it be const?
-
- Context* mContextDELETEME; // TODO: MESH_REWORK DELETE THIS
- TextureCache* mTextureCacheDELETEME; // TODO: MESH_REWORK DELETE THIS
- Shader* mShader;
- unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering
-
-private:
-
- CullFaceMode mCullFaceMode:3; ///< cullface enum, 3 bits is enough
-};
-
-} // namespace SceneGraph
-
-} // namespace Internal
-
-} // namespace Dali
-
-#endif // __DALI_INTERNAL_SCENE_GRAPH_RENDERER_H__
#include <dali/internal/update/nodes/node.h>
#include <dali/internal/render/queue/render-queue.h>
#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
+#include <dali/internal/render/renderers/render-renderer.h>
#include <dali/internal/render/shaders/scene-graph-shader.h>
namespace Dali
}
}
+void DiscardQueue::Add( BufferIndex updateBufferIndex, Renderer* renderer )
+{
+ DALI_ASSERT_DEBUG( NULL != renderer );
+
+ // 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 )
+ {
+ mRendererQueue0.PushBack( renderer );
+ }
+ else
+ {
+ mRendererQueue1.PushBack( renderer );
+ }
+}
+
void DiscardQueue::Add( BufferIndex updateBufferIndex, NodeAttachment* attachment )
{
DALI_ASSERT_DEBUG( NULL != attachment );
mMaterialQueue0.Clear();
mSamplerQueue0.Clear();
mPropertyBufferQueue0.Clear();
+ mRendererQueue0.Clear();
}
else
{
mMaterialQueue1.Clear();
mSamplerQueue1.Clear();
mPropertyBufferQueue1.Clear();
+ mRendererQueue1.Clear();
}
}
#include <dali/internal/update/rendering/scene-graph-geometry.h>
#include <dali/internal/update/rendering/scene-graph-material.h>
#include <dali/internal/update/rendering/scene-graph-sampler.h>
+#include <dali/internal/update/rendering/scene-graph-renderer.h>
namespace Dali
{
typedef OwnerContainer< Material* > MaterialQueue;
typedef OwnerContainer< Sampler* > SamplerQueue;
typedef OwnerContainer< PropertyBuffer* > PropertyBufferQueue;
+ typedef OwnerContainer< Renderer* > RendererQueue;
/**
* Create a new DiscardQueue.
void Add( BufferIndex bufferIndex, Shader* shader );
/**
+ * Adds an unwanted Renderer to the discard queue.
+ * A message will be sent to clean up GL resources in the next Render.
+ * @param[in] updateBufferIndex The current update buffer index.
+ * @param[in] renderer The discarded renderer; DiscardQueue takes ownership.
+ */
+ void Add( BufferIndex updateBufferIndex, Renderer* renderer );
+
+ /**
* Release the nodes which were queued in the frame N-2.
* @pre This method should be called (once) at the beginning of every Update.
* @param[in] updateBufferIndex The current update buffer index.
MaterialQueue mMaterialQueue0;
SamplerQueue mSamplerQueue0;
PropertyBufferQueue mPropertyBufferQueue0;
+ RendererQueue mRendererQueue0;
// Messages are queued here when the update buffer index == 1
NodeOwnerContainer mNodeQueue1;
MaterialQueue mMaterialQueue1;
SamplerQueue mSamplerQueue1;
PropertyBufferQueue mPropertyBufferQueue1;
+ RendererQueue mRendererQueue1;
};
} // namespace SceneGraph
/**
* @copydoc UniformMap::Add
*/
- void AddUniformMapping( UniformPropertyMapping* map );
+ virtual void AddUniformMapping( UniformPropertyMapping* map );
/**
* @copydoc UniformMap::Remove
*/
- void RemoveUniformMapping( const std::string& uniformName );
+ virtual void RemoveUniformMapping( const std::string& uniformName );
/**
* Get the mappings table
}
}
+void ConnectionChangePropagator::Destroy( PropertyOwner& object )
+{
+ // Inform observers that the object's children have changed
+ for( ObserversIterator iter = mObservers.Begin(); iter != mObservers.End(); ++iter )
+ {
+ Observer* observer = (*iter);
+ observer->ObservedObjectDestroyed( object );
+ }
+}
+
} // SceneGraph
} // Internal
} // Dali
* changed it's uniform map in some way.
*/
virtual void ConnectedUniformMapChanged() = 0;
+
+ /**
+ * Inform the observer of the object that the object is about to be destroyed
+ */
+ virtual void ObservedObjectDestroyed(PropertyOwner& object){}
};
/**
*/
void ConnectedUniformMapChanged();
+ /**
+ * Inform the observers that the object is about to be destroyed
+ * @param[in] object The connection owner
+ */
+ void Destroy( PropertyOwner& object );
+
private:
typedef Dali::Vector<Observer*> Observers;
typedef Observers::Iterator ObserversIterator;
{
}
-void RenderMessageDispatcher::AddRenderer( Renderer& renderer )
+void RenderMessageDispatcher::AddRenderer( Render::Renderer& renderer )
{
- typedef MessageValue1< RenderManager, Renderer* > DerivedType;
+ typedef MessageValue1< RenderManager, Render::Renderer* > DerivedType;
// Reserve some memory inside the render queue
unsigned int* slot = mRenderQueue.ReserveMessageSlot( mBuffers.GetUpdateBufferIndex(), sizeof( DerivedType ) );
new (slot) DerivedType( &mRenderManager, &RenderManager::AddRenderer, &renderer );
}
-void RenderMessageDispatcher::RemoveRenderer( Renderer& renderer )
+void RenderMessageDispatcher::RemoveRenderer( Render::Renderer& renderer )
{
- typedef MessageValue1< RenderManager, Renderer* > DerivedType;
+ typedef MessageValue1< RenderManager, Render::Renderer* > DerivedType;
// Reserve some memory inside the render queue
unsigned int* slot = mRenderQueue.ReserveMessageSlot( mBuffers.GetUpdateBufferIndex(), sizeof( DerivedType ) );
{
class MessageBase;
-namespace SceneGraph
+namespace Render
{
class Renderer;
+}
+namespace SceneGraph
+{
+
class RenderManager;
class RenderQueue;
class RenderTracker;
* @param[in] renderer The renderer to add.
* @post renderer ownership is transferred.
*/
- void AddRenderer( Renderer& renderer );
+ void AddRenderer( Render::Renderer& renderer );
/**
* Remove a Renderer.
* @param[in] renderer The renderer to remove.
* @post renderer will be destroyed in the next Render.
*/
- void RemoveRenderer( Renderer& renderer );
+ void RemoveRenderer( Render::Renderer& renderer );
/**
* Add a Geometry
}
}
+ const ObjectContainer& GetObjectContainer()
+ {
+ return mObjectContainer;
+ }
+
private:
- SceneController* mSceneController; ///< SceneControler used to send messages
+ SceneController* mSceneController; ///< SceneController used to send messages
ObjectContainer mObjectContainer; ///< Container for the objects owned
SceneGraphBuffers& mSceneGraphBuffers; ///< Reference to a SceneGraphBuffers to get the indexBuffer
DiscardQueue& mDiscardQueue; ///< Discard queue used for removed objects
#include <dali/internal/update/manager/sorted-layers.h>
#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
#include <dali/internal/update/nodes/scene-graph-layer.h>
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
+#include <dali/internal/render/renderers/render-renderer.h>
#include <dali/internal/render/common/render-instruction.h>
#include <dali/internal/render/shaders/scene-graph-shader.h>
(*iter)->stencilRenderables.clear();
(*iter)->colorRenderables.clear();
(*iter)->overlayRenderables.clear();
+
+ (*iter)->stencilRenderers.Clear();
+ (*iter)->colorRenderers.Clear();
+ (*iter)->overlayRenderers.Clear();
+
}
}
#include <dali/public-api/actors/layer.h>
#include <dali/integration-api/debug.h>
#include <dali/internal/event/actors/layer-impl.h> // for the default sorting function
-#include <dali/internal/update/node-attachments/scene-graph-renderer-attachment.h>
#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
#include <dali/internal/update/nodes/scene-graph-layer.h>
#include <dali/internal/update/manager/sorted-layers.h>
#include <dali/internal/render/common/render-instruction.h>
#include <dali/internal/render/common/render-instruction-container.h>
#include <dali/internal/render/shaders/scene-graph-shader.h>
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
+#include <dali/internal/render/renderers/render-renderer.h>
namespace
{
* @param renderList to add the item to
* @param renderable attachment
* @param viewMatrix used to calculate modelview matrix for the item
+ * @param cameraAttachment The camera used to render
+ * @param isLayer3d Whether we are processing a 3D layer or not
*/
inline void AddRendererToRenderList( BufferIndex updateBufferIndex,
RenderList& renderList,
SceneGraph::CameraAttachment& cameraAttachment,
bool isLayer3d )
{
- // Check for cull against view frustum
- bool inside = true;
-
const Node& parentNode = renderable.GetParent();
const Matrix& worldMatrix = parentNode.GetWorldMatrix( updateBufferIndex );
- if ( RendererAttachment* rendererAttachment = dynamic_cast< RendererAttachment* >( &renderable ) )
+ // Get the next free RenderItem and initialization
+ RenderItem& item = renderList.GetNextFreeItem();
+ const Render::Renderer& renderer = renderable.GetRenderer();
+ item.SetRenderer( const_cast< Render::Renderer* >( &renderer ) );
+ item.SetNode( const_cast< Node* >( &parentNode ) );
+
+ item.SetIsOpaque( renderable.IsFullyOpaque(updateBufferIndex) );
+ if( isLayer3d )
{
- if ( rendererAttachment->GetMaterial().GetShader()->GeometryHintEnabled( Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY ) )
- {
- const Vector3& position = worldMatrix.GetTranslation3();
- const Vector3& scale = parentNode.GetScale( updateBufferIndex );
- const Vector3& halfSize = parentNode.GetSize( updateBufferIndex ) * scale * 0.5f;
+ item.SetDepthIndex( renderable.GetDepthIndex() );
+ }
+ else
+ {
+ item.SetDepthIndex( renderable.GetDepthIndex() + static_cast<int>( parentNode.GetDepth() ) * Dali::Layer::TREE_DEPTH_MULTIPLIER );
+ }
- // Do a fast sphere check
- if ( cameraAttachment.CheckSphereInFrustum( updateBufferIndex, position, halfSize.Length() ) )
- {
- // Check geometry AABB
- //TODO: Take into account orientation
- if ( !cameraAttachment.CheckAABBInFrustum( updateBufferIndex, position, halfSize ) )
- {
- inside = false;
- }
- }
- else
+ // save MV matrix onto the item
+ Matrix::Multiply( item.GetModelViewMatrix(), worldMatrix, viewMatrix );
+}
+
+/**
+ * Add a renderer to the list
+ * @param updateBufferIndex to read the model matrix from
+ * @param renderList to add the item to
+ * @param NodeRenderer NodeRenderer pair
+ * @param viewMatrix used to calculate modelview matrix for the item
+ * @param cameraAttachment The camera used to render
+ * @param isLayer3d Whether we are processing a 3D layer or not
+ */
+inline void AddRendererToRenderList( BufferIndex updateBufferIndex,
+ RenderList& renderList,
+ NodeRenderer& renderable,
+ const Matrix& viewMatrix,
+ SceneGraph::CameraAttachment& cameraAttachment,
+ bool isLayer3d )
+{
+ // Check for cull against view frustum
+ const Matrix& worldMatrix = renderable.mNode->GetWorldMatrix( updateBufferIndex );
+ bool inside = true;
+
+ if ( renderable.mRenderer->GetMaterial().GetShader()->GeometryHintEnabled( Dali::ShaderEffect::HINT_DOESNT_MODIFY_GEOMETRY ) )
+ {
+ const Vector3& position = worldMatrix.GetTranslation3();
+ const Vector3& scale = renderable.mNode->GetScale( updateBufferIndex );
+ const Vector3& halfSize = renderable.mNode->GetSize( updateBufferIndex ) * scale * 0.5f;
+
+ // Do a fast sphere check
+ if ( cameraAttachment.CheckSphereInFrustum( updateBufferIndex, position, halfSize.Length() ) )
+ {
+ // Check geometry AABB
+ //TODO: Take into account orientation
+ if ( !cameraAttachment.CheckAABBInFrustum( updateBufferIndex, position, halfSize ) )
{
inside = false;
}
}
+ else
+ {
+ inside = false;
+ }
}
if ( inside )
{
- // Get the next free RenderItem and initialization
+ // Get the next free RenderItem
RenderItem& item = renderList.GetNextFreeItem();
- const Renderer& renderer = renderable.GetRenderer();
- item.SetRenderer( const_cast< Renderer* >( &renderer ) );
- item.SetIsOpaque( renderable.IsFullyOpaque(updateBufferIndex) );
+ item.SetRenderer( &renderable.mRenderer->GetRenderer() );
+ item.SetNode( renderable.mNode );
+ item.SetIsOpaque( renderable.mRenderer->IsFullyOpaque(updateBufferIndex, *renderable.mNode ) );
+
if( isLayer3d )
{
- item.SetDepthIndex( renderable.GetDepthIndex() );
+ item.SetDepthIndex( renderable.mRenderer->GetDepthIndex() );
}
else
{
- item.SetDepthIndex( renderable.GetDepthIndex() + static_cast<int>( parentNode.GetDepth() ) * Dali::Layer::TREE_DEPTH_MULTIPLIER );
+ item.SetDepthIndex( renderable.mRenderer->GetDepthIndex() + static_cast<int>( renderable.mNode->GetDepth() ) * Dali::Layer::TREE_DEPTH_MULTIPLIER );
}
// save MV matrix onto the item
* @param updateBufferIndex to read the model matrix from
* @param renderList to add the items to
* @param renderable attachments
+ * NodeRendererContainer Node-Renderer pairs
* @param viewMatrix used to calculate modelview matrix for the items
+ * @param cameraAttachment The camera used to render
+ * @param isLayer3d Whether we are processing a 3D layer or not
*/
inline void AddRenderersToRenderList( BufferIndex updateBufferIndex,
RenderList& renderList,
RenderableAttachmentContainer& attachments,
+ NodeRendererContainer& renderers,
const Matrix& viewMatrix,
SceneGraph::CameraAttachment& cameraAttachment,
bool isLayer3d )
DALI_LOG_INFO( gRenderListLogFilter, Debug::Verbose, "AddRenderersToRenderList()\n");
// Add renderer for each attachment
- int index=0;
+ unsigned int index(0);
const RenderableAttachmentIter endIter = attachments.end();
for ( RenderableAttachmentIter iter = attachments.begin(); iter != endIter; ++iter )
{
AddRendererToRenderList( updateBufferIndex, renderList, attachment, viewMatrix, cameraAttachment, isLayer3d );
DALI_LOG_INFO( gRenderListLogFilter, Debug::Verbose, " List[%d].renderer = %p\n", index, &(attachment.GetRenderer()));
- index++;
+ ++index;
+ }
+
+ unsigned int rendererCount( renderers.Size() );
+ for( unsigned int i(0); i<rendererCount; ++i )
+ {
+ AddRendererToRenderList( updateBufferIndex, renderList, renderers[i], viewMatrix, cameraAttachment, isLayer3d );
}
}
for( size_t index = 0; index < renderableCount; ++index )
{
RenderableAttachment* attachment = attachmentList[ index ];
- const Renderer& renderer = attachment->GetRenderer();
+ const Render::Renderer& renderer = attachment->GetRenderer();
checkSumNew += size_t( &renderer );
- checkSumOld += size_t( renderList.GetRenderer( index ) );
+ checkSumOld += size_t( &renderList.GetRenderer( index ) );
}
if( checkSumNew == checkSumOld )
{
{
RenderItem& item = renderList.GetItem( index );
- //@todo MESH_REWORK After merge of RenderableAttachment and RendererAttachment, should instead store the renderable ptr and get the fields directly
- layer.colorRenderables[index]->SetSortAttributes( bufferIndex, sortingHelper[ index ] );
+ item.GetRenderer().SetSortAttributes(sortingHelper[ index ]);
// the default sorting function should get inlined here
sortingHelper[ index ].zValue = Internal::Layer::ZValue( item.GetModelViewMatrix().GetTranslation3() ) - item.GetDepthIndex();
{
RenderItem& item = renderList.GetItem( index );
- layer.colorRenderables[index]->SetSortAttributes( bufferIndex, sortingHelper[ index ] );
+ item.GetRenderer().SetSortAttributes(sortingHelper[ index ]);
sortingHelper[ index ].zValue = (*sortFunction)( item.GetModelViewMatrix().GetTranslation3() ) - item.GetDepthIndex();
// keep the renderitem pointer in the helper so we can quickly reorder items after sort
for( unsigned int index = 0; index < renderableCount; ++index, ++renderListIter )
{
*renderListIter = sortingHelper[ index ].renderItem;
- DALI_LOG_INFO( gRenderListLogFilter, Debug::Verbose, " sortedList[%d] = %p\n", index, sortingHelper[ index ].renderItem->GetRenderer() );
+ DALI_LOG_INFO( gRenderListLogFilter, Debug::Verbose, " sortedList[%d] = %p\n", index, &sortingHelper[ index ].renderItem->GetRenderer() );
}
}
}
}
- AddRenderersToRenderList( updateBufferIndex, renderList, layer.colorRenderables, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D );
+ AddRenderersToRenderList( updateBufferIndex, renderList, layer.colorRenderables, layer.colorRenderers, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D );
SortColorRenderItems( updateBufferIndex, renderList, layer, sortingHelper );
//Set render flags
// and if this layer has got exactly one opaque renderer
// and this renderer is not interested in depth testing
// (i.e. is an image and not a mesh)
+
if ( ( renderList.Count() == 1 ) &&
- ( !renderList.GetRenderer( 0 )->RequiresDepthTest() ) &&
+ ( !renderList.GetRenderer( 0 ).RequiresDepthTest() ) &&
( !renderList.GetItem(0).IsOpaque() ) )
{
//Nothing to do here
return;
}
}
- AddRenderersToRenderList( updateBufferIndex, overlayRenderList, layer.overlayRenderables, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D );
+ AddRenderersToRenderList( updateBufferIndex, overlayRenderList, layer.overlayRenderables, layer.overlayRenderers, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D );
}
/**
return;
}
}
- AddRenderersToRenderList( updateBufferIndex, stencilRenderList, layer.stencilRenderables, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D );
+ AddRenderersToRenderList( updateBufferIndex, stencilRenderList, layer.stencilRenderables, layer.stencilRenderers, viewMatrix, cameraAttachment, layer.GetBehavior() == Dali::Layer::LAYER_3D );
}
/**
{
Layer& layer = **iter;
- const bool stencilRenderablesExist( !layer.stencilRenderables.empty() );
- const bool colorRenderablesExist( !layer.colorRenderables.empty() );
- const bool overlayRenderablesExist( !layer.overlayRenderables.empty() );
+ const bool stencilRenderablesExist( !layer.stencilRenderables.empty() || !layer.stencilRenderers.Empty() );
+ const bool colorRenderablesExist( !layer.colorRenderables.empty() || !layer.colorRenderers.Empty() );
+ const bool overlayRenderablesExist( !layer.overlayRenderables.empty() || !layer.overlayRenderers.Empty() );
const bool tryReuseRenderList( viewMatrixHasNotChanged && layer.CanReuseRenderers(renderTask.GetCamera()) );
// Ignore stencils if there's nothing to test
class RenderTracker;
class RenderItem;
class Shader;
-class Material;
-class Geometry;
+class RenderGeometry;
+class MaterialDataProvider;
/**
* Structure to store information for sorting the renderers.
{
}
- RenderItem* renderItem; ///< The render item that is being sorted (includes depth index)
- Shader* shader; ///< The shader instance
- Material* material; ///< The material instance
- Geometry* geometry; ///< The geometry instance
- float zValue; // The zValue of the given renderer (either distance from camera, or a custom calculated value)
+ RenderItem* renderItem; ///< The render item that is being sorted (includes depth index)
+ const Shader* shader; ///< The shader instance
+ const MaterialDataProvider* material; ///< The material instance
+ const RenderGeometry* geometry; ///< The geometry instance
+ float zValue; // The zValue of the given renderer (either distance from camera, or a custom calculated value)
};
typedef std::vector< RendererWithSortAttributes > RendererSortingHelper;
#include <dali/internal/render/common/render-tracker.h>
#include <dali/internal/render/common/render-instruction.h>
#include <dali/internal/render/common/render-instruction-container.h>
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
+#include <dali/internal/render/renderers/render-renderer.h>
#include <dali/integration-api/debug.h>
#if defined(DEBUG_ENABLED)
inheritedDrawMode |= node.GetDrawMode();
+
if ( node.HasAttachment() )
{
RenderableAttachment* renderable = node.GetAttachment().GetRenderable(); // not all attachments render
}
}
+ if( node.ResolveVisibility( updateBufferIndex ) )
+ {
+ for( unsigned int i(0); i<node.GetRendererCount(); ++i )
+ {
+ Renderer* renderer = node.GetRendererAt( i );
+ bool ready = false;
+ bool complete = false;
+ renderer->GetReadyAndComplete(ready, complete);
+
+ DALI_LOG_INFO(gRenderTaskLogFilter, Debug::General, "Testing renderable:%p ready:%s complete:%s\n", renderer, ready?"T":"F", complete?"T":"F");
+
+ resourcesFinished = !complete ? complete : resourcesFinished;
+
+ resourcesFinished = !complete ? complete : resourcesFinished;
+
+ if( ready ) // i.e. some resources are ready
+ {
+ if( DrawMode::STENCIL == inheritedDrawMode )
+ {
+ layer->stencilRenderers.PushBack( NodeRenderer(&node, renderer ) );
+ }
+ else if( DrawMode::OVERLAY_2D == inheritedDrawMode )
+ {
+ layer->overlayRenderers.PushBack( NodeRenderer(&node, renderer ) );
+ }
+ else
+ {
+ layer->colorRenderers.PushBack( NodeRenderer(&node, renderer ) );
+ }
+ }
+
+
+
+ }
+ }
+
+
// Recurse children
NodeContainer& children = node.GetChildren();
const NodeIter endIter = children.End();
#include <dali/internal/update/node-attachments/scene-graph-renderable-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/scene-graph-renderer.h>
+#include <dali/internal/render/renderers/render-renderer.h>
#include <dali/integration-api/debug.h>
AddRenderableToLayer( *layer, *renderable, updateBufferIndex, inheritedDrawMode );
}
}
- else if( node.IsObserved() )
+ else if( node.IsObserved() || node.GetRendererCount() )
{
// This node is being used as a property input for an animation, constraint,
// camera or bone. Ensure it's matrix is updated
UpdateNodeWorldMatrix( node, nodeDirtyFlags, updateBufferIndex );
}
+ if( node.ResolveVisibility(updateBufferIndex) )
+ {
+ node.PrepareRender( updateBufferIndex );
+ }
+
+
// if any child node has moved or had its sort modifier changed, layer is not clean and old frame cannot be reused
// also if node has been deleted, dont reuse old render items
if( nodeDirtyFlags & RenderableUpdateFlags )
#include <dali/internal/update/manager/update-algorithms.h>
#include <dali/internal/update/manager/update-manager-debug.h>
#include <dali/internal/update/node-attachments/scene-graph-camera-attachment.h>
-#include <dali/internal/update/node-attachments/scene-graph-renderer-attachment.h>
#include <dali/internal/update/node-attachments/scene-graph-image-attachment.h>
#include <dali/internal/update/nodes/node.h>
#include <dali/internal/update/nodes/scene-graph-layer.h>
systemLevelTaskList ( completeStatusManager ),
root( NULL ),
systemLevelRoot( NULL ),
- geometries( sceneGraphBuffers, discardQueue ),
+ renderers( sceneGraphBuffers, discardQueue ),
+ geometries( sceneGraphBuffers, discardQueue ),
materials( sceneGraphBuffers, discardQueue ),
samplers( sceneGraphBuffers, discardQueue ),
propertyBuffers( sceneGraphBuffers, discardQueue ),
{
sceneController = new SceneControllerImpl( renderMessageDispatcher, renderQueue, discardQueue, textureCache, completeStatusManager );
+ renderers.SetSceneController( *sceneController );
geometries.SetSceneController( *sceneController );
materials.SetSceneController( *sceneController );
propertyBuffers.SetSceneController( *sceneController );
AnimationContainer animations; ///< A container of owned animations
PropertyNotificationContainer propertyNotifications; ///< A container of owner property notifications.
+ ObjectOwnerContainer<Renderer> renderers;
ObjectOwnerContainer<Geometry> geometries; ///< A container of geometries
ObjectOwnerContainer<Material> materials; ///< A container of materials
ObjectOwnerContainer<Sampler> samplers; ///< A container of samplers
}
}
-void UpdateManager::AttachToSceneGraph( RendererAttachment* renderer )
-{
- // @todo MESH_REWORK Take ownership of this object after merge with SceneGraph::RenderableAttachment
-
- SceneGraph::NodeAttachment* attachment = static_cast<SceneGraph::NodeAttachment*>(renderer);
- attachment->Initialize( *mImpl->sceneController, mSceneGraphBuffers.GetUpdateBufferIndex() );
-}
-
void UpdateManager::AddObject( PropertyOwner* object )
{
DALI_ASSERT_DEBUG( NULL != object );
return mImpl->geometries;
}
+ObjectOwnerContainer<Renderer>& UpdateManager::GetRendererOwner()
+{
+ return mImpl->renderers;
+}
+
+
ObjectOwnerContainer<Material>& UpdateManager::GetMaterialOwner()
{
return mImpl->materials;
mImpl->geometries.ResetToBaseValues( bufferIndex );
mImpl->propertyBuffers.ResetToBaseValues( bufferIndex );
mImpl->samplers.ResetToBaseValues( bufferIndex );
+ mImpl->renderers.ResetToBaseValues( bufferIndex );
// Reset animatable shader properties to base values
mImpl->geometries.ConstrainObjects( bufferIndex );
mImpl->samplers.ConstrainObjects( bufferIndex );
mImpl->propertyBuffers.ConstrainObjects( bufferIndex );
+ mImpl->renderers.ConstrainObjects( bufferIndex );
// constrain shaders... (in construction order)
ShaderContainer& shaders = mImpl->shaders;
}
}
+void UpdateManager::UpdateRenderers( BufferIndex bufferIndex )
+{
+ const Internal::OwnerContainer<Renderer*>& rendererContainer( mImpl->renderers.GetObjectContainer() );
+ unsigned int rendererCount( rendererContainer.Size() );
+ for( unsigned int i(0); i<rendererCount; ++i )
+ {
+ if( rendererContainer[i]->IsReferenced() )
+ {
+ rendererContainer[i]->PrepareResources(bufferIndex, mImpl->resourceManager);
+ rendererContainer[i]->PrepareRender( bufferIndex );
+ }
+ }
+}
+
void UpdateManager::UpdateNodes( BufferIndex bufferIndex )
{
mImpl->nodeDirtyFlags = NothingFlag;
mImpl->touchResampler.Update();
const bool gestureUpdated = ProcessGestures( bufferIndex, lastVSyncTimeMilliseconds, nextVSyncTimeMilliseconds );
- const bool updateScene = // The scene-graph requires an update if..
- (mImpl->nodeDirtyFlags & RenderableUpdateFlags) || // ..nodes were dirty in previous frame OR
- IsAnimationRunning() || // ..at least one animation is running OR
- mImpl->messageQueue.IsSceneUpdateRequired() || // ..a message that modifies the scene graph node tree is queued OR
- resourceChanged || // ..one or more resources were updated/changed OR
- gestureUpdated; // ..a gesture property was updated
+ const bool updateScene = // The scene-graph requires an update if..
+ (mImpl->nodeDirtyFlags & RenderableUpdateFlags) || // ..nodes were dirty in previous frame OR
+ IsAnimationRunning() || // ..at least one animation is running OR
+ mImpl->messageQueue.IsSceneUpdateRequired() || // ..a message that modifies the scene graph node tree is queued OR
+ resourceChanged || // ..one or more resources were updated/changed OR
+ gestureUpdated; // ..a gesture property was updated
+
// Although the scene-graph may not require an update, we still need to synchronize double-buffered
// values if the scene was updated in the previous frame.
// 11) Update node hierarchy and perform sorting / culling.
// This will populate each Layer with a list of renderers which are ready.
UpdateNodes( bufferIndex );
+ UpdateRenderers( bufferIndex );
+
// 12) Prepare for the next render
PERF_MONITOR_START(PerformanceMonitor::PREPARE_RENDERABLES);
#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>
#include <dali/internal/render/shaders/scene-graph-shader.h>
namespace Dali
class PropertyBuffer;
class Material;
class Sampler;
-class RendererAttachment;
/**
* UpdateManager maintains a scene graph i.e. a tree of nodes and attachments and
void AttachToNode( Node* node, NodeAttachment* attachment );
/**
- * Attach a renderer to the scene graph
- */
- void AttachToSceneGraph( RendererAttachment* renderer );
-
-
- /**
* Add a newly created object.
* @param[in] object The object to add.
* @post The object is owned by UpdateManager.
*/
ObjectOwnerContainer< Geometry >& GetGeometryOwner();
+ ObjectOwnerContainer< Renderer >& GetRendererOwner();
/**
* @brief Get the material owner
*
*/
void UpdateNodes( BufferIndex bufferIndex );
+ /**
+ * Update Renderers
+ * @param[in] bufferIndex to use
+ */
+ void UpdateRenderers( BufferIndex bufferIndex );
+
private:
// needs to be direct member so that getter for event buffer can be inlined
new (slot) LocalType( &manager, &UpdateManager::AttachToNode, &parent, attachment );
}
-inline void AttachToSceneGraphMessage( UpdateManager& manager, RendererAttachment* renderer )
-{
- // @todo MESH_REWORK Pass by owner pointer after merge with SceneGraph::RenderableAttachment
- typedef MessageValue1< UpdateManager, RendererAttachment* > 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::AttachToSceneGraph, renderer );
-}
-
inline void AddObjectMessage( UpdateManager& manager, PropertyOwner* object )
{
typedef MessageValue1< UpdateManager, OwnerPointer<PropertyOwner> > LocalType;
#include <dali/internal/render/queue/render-queue.h>
#include <dali/internal/render/common/vertex.h>
#include <dali/internal/render/common/performance-monitor.h>
-#include <dali/internal/render/renderers/scene-graph-image-renderer.h>
-#include <dali/internal/render/renderers/scene-graph-renderer-declarations.h>
+#include <dali/internal/render/renderers/render-image-renderer.h>
#include <dali/internal/render/shaders/scene-graph-shader.h>
#include <dali/internal/update/node-attachments/scene-graph-image-attachment-debug.h>
{
// value types used by messages
-template <> struct ParameterType< SceneGraph::ImageRenderer::MeshType >
-: public BasicType< SceneGraph::ImageRenderer::MeshType > {};
+template <> struct ParameterType< Render::ImageRenderer::MeshType >
+: public BasicType< Render::ImageRenderer::MeshType > {};
namespace SceneGraph
{
mIsPixelAreaSet( false ),
mPreviousRefreshHints( 0 ),
mStyle( Dali::ImageActor::STYLE_QUAD ),
- mCullFaceMode( CullNone ),
- mUseBlend( false )
+ mCullFaceMode( CullNone )
{
}
DALI_ASSERT_DEBUG( NULL != mSceneController );
// Create main renderer, passing ownership to the render-thread
- mImageRenderer = ImageRenderer::New( *mParent );
+ mImageRenderer = Render::ImageRenderer::New();
mSceneController->GetRenderMessageDispatcher().AddRenderer( *mImageRenderer );
if( mTextureId != 0 )
{
- typedef MessageValue1< ImageRenderer, ResourceId > DerivedType;
+ typedef MessageValue1< Render::ImageRenderer, ResourceId > DerivedType;
// Reserve some memory inside the render queue
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
// Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( mImageRenderer, &ImageRenderer::SetTextureId, mTextureId );
+ new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::SetTextureId, mTextureId );
}
// After derived classes have (potentially) created their renderer
- Renderer& renderer = GetRenderer();
+ Render::Renderer& renderer = GetRenderer();
renderer.SetCullFace( mCullFaceMode );
// set the default shader here as well
{
}
-Renderer& ImageAttachment::GetRenderer()
+Render::Renderer& ImageAttachment::GetRenderer()
{
return *mImageRenderer;
}
-const Renderer& ImageAttachment::GetRenderer() const
+const Render::Renderer& ImageAttachment::GetRenderer() const
{
return *mImageRenderer;
}
if( mImageRenderer )
{
- typedef MessageValue1< ImageRenderer, ResourceId > DerivedType;
+ typedef MessageValue1< Render::ImageRenderer, ResourceId > DerivedType;
// Reserve some memory inside the render queue
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
// Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( mImageRenderer, &ImageRenderer::SetTextureId, mTextureId );
+ new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::SetTextureId, mTextureId );
}
}
mIsPixelAreaSet = true;
{
- typedef MessageValue1< ImageRenderer, ImageRenderer::PixelArea > DerivedType;
+ typedef MessageValue1< Render::ImageRenderer, Render::ImageRenderer::PixelArea > DerivedType;
// Reserve some memory inside the render queue
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
// Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( mImageRenderer, &ImageRenderer::SetPixelArea, pixelArea );
+ new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::SetPixelArea, pixelArea );
}
// we rely on attachment to not call us unless it actually did change
{
// update the 9 patch border information
- typedef MessageValue2< ImageRenderer, Vector4, bool > DerivedType;
+ typedef MessageValue2< Render::ImageRenderer, Vector4, bool > DerivedType;
// Reserve some memory inside the render queue
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
// Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( mImageRenderer, &ImageRenderer::SetNinePatchBorder, border, inPixels );
+ new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::SetNinePatchBorder, border, inPixels );
if (mStyle != Dali::ImageActor::STYLE_QUAD)
{
void ImageAttachment::SetBlendingOptions( BufferIndex updateBufferIndex, unsigned int options )
{
// Blending options are forwarded to renderer in render-thread
- typedef MessageValue1< ImageRenderer, unsigned int > DerivedType;
+ typedef MessageValue1< Render::ImageRenderer, unsigned int > DerivedType;
// Reserve some memory inside the render queue
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
// Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( mImageRenderer, &ImageRenderer::SetBlendingOptions, options );
+ new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::SetBlendingOptions, options );
}
void ImageAttachment::SetBlendColor( BufferIndex updateBufferIndex, const Vector4& color )
{
// Blend color is forwarded to renderer in render-thread
- typedef MessageValue1< ImageRenderer, Vector4 > DerivedType;
+ typedef MessageValue1< Render::ImageRenderer, Vector4 > DerivedType;
// Reserve some memory inside the render queue
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
// Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( mImageRenderer, &ImageRenderer::SetBlendColor, color );
+ new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::SetBlendColor, color );
}
void ImageAttachment::SetCullFace( BufferIndex updateBufferIndex, CullFaceMode mode )
mCullFaceMode = mode;
- typedef MessageValue1< Renderer, CullFaceMode > DerivedType;
+ typedef MessageValue1< Render::Renderer, CullFaceMode > DerivedType;
// Reserve some memory inside the render queue
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
// Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( &GetRenderer(), &Renderer::SetCullFace, mode );
+ new (slot) DerivedType( &GetRenderer(), &Render::Renderer::SetCullFace, mode );
}
void ImageAttachment::SetSampler( BufferIndex updateBufferIndex, unsigned int samplerBitfield )
{
DALI_ASSERT_DEBUG(mSceneController);
- typedef MessageValue1< Renderer, unsigned int > DerivedType;
+ typedef MessageValue1< Render::Renderer, unsigned int > DerivedType;
// Reserve some memory inside the render queue
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
// Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( &GetRenderer(), &Renderer::SetSampler, samplerBitfield );
+ new (slot) DerivedType( &GetRenderer(), &Render::Renderer::SetSampler, samplerBitfield );
}
void ImageAttachment::ApplyShader( BufferIndex updateBufferIndex, Shader* shader )
mGeometrySize.x = actorSize.x;
mGeometrySize.y = actorSize.y;
- ImageRenderer::MeshType meshType = ImageRenderer::GRID_QUAD;
+ Render::ImageRenderer::MeshType meshType = Render::ImageRenderer::GRID_QUAD;
if ( !PreviousHintEnabled( Dali::ShaderEffect::HINT_GRID ) )
{
if ( mStyle == Dali::ImageActor::STYLE_NINE_PATCH )
{
- meshType = ImageRenderer::NINE_PATCH;
+ meshType = Render::ImageRenderer::NINE_PATCH;
}
else if ( mStyle == Dali::ImageActor::STYLE_NINE_PATCH_NO_CENTER )
{
- meshType = ImageRenderer::NINE_PATCH_NO_CENTER;
+ meshType = Render::ImageRenderer::NINE_PATCH_NO_CENTER;
}
else
{
- meshType = ImageRenderer::QUAD;
+ meshType = Render::ImageRenderer::QUAD;
}
}
else
{
if ( mStyle == Dali::ImageActor::STYLE_NINE_PATCH )
{
- meshType = ImageRenderer::GRID_NINE_PATCH;
+ meshType = Render::ImageRenderer::GRID_NINE_PATCH;
}
else if ( mStyle == Dali::ImageActor::STYLE_NINE_PATCH_NO_CENTER )
{
- meshType = ImageRenderer::GRID_NINE_PATCH_NO_CENTER;
+ meshType = Render::ImageRenderer::GRID_NINE_PATCH_NO_CENTER;
}
else
{
- meshType = ImageRenderer::GRID_QUAD;
+ meshType = Render::ImageRenderer::GRID_QUAD;
}
}
// Recalculate the mesh data in the next render
{
- typedef MessageValue3< ImageRenderer, ImageRenderer::MeshType, Vector2, bool > DerivedType;
+ typedef MessageValue3< Render::ImageRenderer, Render::ImageRenderer::MeshType, Vector2, bool > DerivedType;
// Reserve some memory inside the render queue
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
// Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( mImageRenderer, &ImageRenderer::CalculateMeshData, meshType, mGeometrySize, mIsPixelAreaSet );
+ new (slot) DerivedType( mImageRenderer, &Render::ImageRenderer::CalculateMeshData, meshType, mGeometrySize, mIsPixelAreaSet );
}
mRefreshMeshData = false;
}
-
- bool blend = !IsFullyOpaque( updateBufferIndex );
-
- if ( mUseBlend != blend )
- {
- mUseBlend = blend;
-
- // Enable/disable blending in the next render
- typedef MessageValue1< ImageRenderer, bool > DerivedType;
-
- // Reserve some memory inside the render queue
- unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
-
- // Construct message in the render queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( mImageRenderer, &ImageRenderer::SetUseBlend, blend );
- }
}
void RenderableAttachment::SetBlendingMode( BlendingMode::Type mode )
void ImageAttachment::SendShaderChangeMessage( BufferIndex updateBufferIndex )
{
- typedef MessageValue1< Renderer, Shader* > DerivedType;
+ typedef MessageValue1< Render::Renderer, Shader* > DerivedType;
// Reserve memory inside the render queue
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
// Construct message in the mRenderer queue memory; note that delete should not be called on the return value
- new (slot) DerivedType( &GetRenderer(), &Renderer::SetShader, mShader );
+ new (slot) DerivedType( &GetRenderer(), &Render::Renderer::SetShader, mShader );
}
template <> struct ParameterType< Dali::ImageActor::Style >
: public BasicType< Dali::ImageActor::Style > {};
-namespace SceneGraph
+namespace Render
{
class ImageRenderer;
+}
+
+namespace SceneGraph
+{
class Shader;
class RenderQueue;
/**
* @copydoc RenderableAttachment::GetRenderer().
*/
- virtual Renderer& GetRenderer();
+ virtual Render::Renderer& GetRenderer();
/**
* @copydoc RenderableAttachment::GetRenderer().
*/
- virtual const Renderer& GetRenderer() const;
+ virtual const Render::Renderer& GetRenderer() const;
/**
* Set the ID used to retrieve a texture from ResourceManager.
private: // Data
- ImageRenderer* mImageRenderer; ///< Raw-pointers to renderer that is owned by RenderManager
+ Render::ImageRenderer* mImageRenderer; ///< Raw-pointers to renderer that is owned by RenderManager
unsigned int mTextureId; ///< The resource ID for a texture
// bitfields to fit in single byte
int mPreviousRefreshHints : 4; ///< The shader geometry hints, when the vertex buffer was last refreshed, 4 bits is enough as there's 4 flags
Style mStyle : 2; ///< rendering style, 2 bits is enough as only 2 values in the enum
CullFaceMode mCullFaceMode : 3; ///< Cullface mode, 3 bits is enough for 4 values
- bool mUseBlend : 1; ///< True if the attachment & renderer should be considered opaque for sorting and blending.
BitmapMetadata mBitmapMetadata;///< The bitmap metadata
Vector2 mGeometrySize; ///< The size of the currently used geometry
#include <dali/internal/update/resources/complete-status-manager.h>
#include <dali/internal/update/resources/resource-tracker.h>
#include <dali/internal/render/queue/render-queue.h>
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
+#include <dali/internal/render/renderers/render-renderer.h>
#include <dali/internal/render/shaders/scene-graph-shader.h>
#include <dali/internal/common/image-sampler.h>
bool RenderableAttachment::ResolveVisibility( BufferIndex updateBufferIndex )
{
- mHasSizeAndColorFlag = false;
- const Vector4& color = mParent->GetWorldColor( updateBufferIndex );
- if( color.a > FULLY_TRANSPARENT ) // not fully transparent
- {
- const float MAX_NODE_SIZE = float(1u<<30);
- const Vector3& size = mParent->GetSize( updateBufferIndex );
- if( ( size.width > Math::MACHINE_EPSILON_1000 ) && // width is greater than a very small number
- ( size.height > Math::MACHINE_EPSILON_1000 ) ) // height is greater than a very small number
- {
- if( ( size.width < MAX_NODE_SIZE ) && // width is smaller than the maximum allowed size
- ( size.height < MAX_NODE_SIZE ) ) // height is smaller than the maximum allowed size
- {
- mHasSizeAndColorFlag = true;
- }
- else
- {
- DALI_LOG_ERROR("Actor size should not be bigger than %f.\n", MAX_NODE_SIZE );
- DALI_LOG_ACTOR_TREE( mParent );
- }
- }
- }
+ mHasSizeAndColorFlag = mParent->ResolveVisibility(updateBufferIndex);
return mHasSizeAndColorFlag;
}
#include <dali/internal/update/nodes/node.h>
#include <dali/internal/update/node-attachments/node-attachment.h>
#include <dali/internal/update/resources/resource-manager-declarations.h>
-#include <dali/internal/render/renderers/scene-graph-renderer-declarations.h>
namespace Dali
{
class ResourceManager;
class ResourceTracker;
-namespace SceneGraph
+namespace Render
{
class Renderer;
+}
+namespace SceneGraph
+{
class Shader;
class SortAttributes;
struct RendererWithSortAttributes;
* should always exist during the lifetime of the RenderableAttachment.
* @return A Renderer.
*/
- virtual Renderer& GetRenderer() = 0;
+ virtual Render::Renderer& GetRenderer() = 0;
/**
* Retrieve a Renderer used by this attachment.
* Other renderers are for effects such as shadows and reflections.
* @return A Renderer.
*/
- virtual const Renderer& GetRenderer() const = 0;
+ virtual const Render::Renderer& GetRenderer() const = 0;
/**
* Prepare the object resources.
+++ /dev/null
-#ifndef DALI_INTERNAL_SCENE_GRAPH_RENDERER_ATTACHMENT_H
-#define DALI_INTERNAL_SCENE_GRAPH_RENDERER_ATTACHMENT_H
-
-/*
- * Copyright (c) 2015 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.
- */
-
-#include <dali/internal/event/common/event-thread-services.h>
-#include <dali/internal/update/common/double-buffered.h>
-#include <dali/internal/update/common/property-owner.h>
-#include <dali/internal/update/common/animatable-property.h>
-#include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
-#include <dali/internal/update/controllers/render-message-dispatcher.h>
-#include <dali/internal/update/controllers/scene-controller.h>
-#include <dali/internal/update/node-attachments/scene-graph-renderable-attachment.h>
-#include <dali/internal/render/data-providers/render-data-provider.h>
-
-namespace Dali
-{
-namespace Internal
-{
-namespace SceneGraph
-{
-class Material;
-class Geometry;
-class NewRenderer;
-struct RendererWithSortAttributes;
-
-/**
- * The renderer attachment is the SceneGraph equivalent of Dali::Renderer. It is used to create an instance of a geometry and material for rendering, and is attached to an actor.
- *
- * It observes it's children (Material and Geometry) for connection change and for uniform map change, and observer's it's actor parent for uniform map change - this allows it to re-generate the uniform maps used by its RenderThread equivalent class.
- *
- * Lifetime and ownership
- * It is created when a Dali::Renderer is created, and sent to UpdateManager. At this point
- * Initialize is called on the object, but ownership is NOT taken by UpdateManager.
-
- * When a Dali::Renderer is added to an actor, then this object becomes the node attachment
- * for that actor, and the node takes ownership. It will create the Render::NewRenderer object
- * in the Update thread on reciept of the connection message.
-
- * When it's not attached to an actor, it is still possible to send messages to this
- * object, to, e.g., set the material, or a property.
- *
- * @todo MESH_REWORK On merge with RenderableAttachment, change owner of all attachments to UpdateManager.
- */
-class RendererAttachment : public RenderableAttachment,
- public PropertyOwner,
- public UniformMapDataProvider,
- public UniformMap::Observer,
- public ConnectionChangePropagator::Observer
-{
-public:
- /**
- * Create a new renderer attachment.
- * @return The newly allocated RendererAttachment
- */
- static RendererAttachment* New();
-
- /**
- * Constructor
- */
- RendererAttachment();
-
- /**
- * Destructor
- */
- virtual ~RendererAttachment();
-
- /**
- * @copydoc RenderableAttachment::Initialize2().
- */
- virtual void Initialize2( BufferIndex updateBufferIndex );
-
- /**
- * @copydoc RenderableAttachment::OnDestroy2().
- */
- virtual void OnDestroy2();
-
- /**
- * @copydoc NodeAttachment::ConnectedToSceneGraph()
- */
- virtual void ConnectedToSceneGraph();
-
- /**
- * @copydoc NodeAttachment::DisconnectedFromSceneGraph()
- */
- virtual void DisconnectedFromSceneGraph();
-
- /**
- * Set the material for the renderer
- * @param[in] bufferIndex The current frame's buffer index
- * @param[in] material The material this renderer will use
- */
- void SetMaterial( BufferIndex bufferIndex, Material* material);
-
- /**
- * Get the material of this renderer
- * @return the material this renderer uses
- */
- Material& GetMaterial();
-
- /**
- * Set the geometry for the renderer
- * @param[in] bufferIndex The current frame's buffer index
- * @param[in] geometry The geometry this renderer will use
- */
- void SetGeometry( BufferIndex bufferIndex, Geometry* geometry);
-
- /**
- * Get the geometry of this renderer
- * @return the geometry this renderer uses
- */
- Geometry& GetGeometry();
-
- /**
- * Set the depth index
- * @param[in] depthIndex the new depth index to use
- */
- void SetDepthIndex( int depthIndex );
-
-protected: // From NodeAttachment
- /**
- * @brief Get the depth index
- * @return The depth index
- */
- virtual int GetDepthIndex()
- {
- return mDepthIndex;
- }
-
- /**
- * Write the attachment's sort attributes to the passed in reference.
- * @param[in] bufferIndex The buffer index
- * @param[out] sortAttributes
- */
- virtual void SetSortAttributes( BufferIndex bufferIndex, RendererWithSortAttributes& sortAttributes );
-
-protected: // From RenderableAttachment
- /**
- * @copydoc RenderableAttachment::GetRenderer().
- */
- virtual Renderer& GetRenderer();
-
- /**
- * @copydoc RenderableAttachment::GetRenderer().
- */
- virtual const Renderer& GetRenderer() const;
-
- /**
- * @copydoc RenderableAttachment::DoPrepareResources()
- */
- virtual bool DoPrepareResources( BufferIndex updateBufferIndex,
- ResourceManager& resourceManager );
-
- /**
- * @copydoc RenderableAttachment::DoPrepareRender()
- */
- virtual void DoPrepareRender( BufferIndex updateBufferIndex );
-
- /**
- * @copydoc RenderableAttachment::IsFullyOpaque()
- */
- virtual bool IsFullyOpaque( BufferIndex updateBufferIndex );
-
- /**
- * @copydoc RenderableAttachment::SizeChanged()
- */
- virtual void SizeChanged( BufferIndex updateBufferIndex );
-
-protected: // From ConnectionObserver
- /**
- * @copydoc ConnectionObservers::Observer::ConnectionsChanged
- */
- virtual void ConnectionsChanged(PropertyOwner& object);
-
- /**
- * @copydoc ConnectionObservers::Observer::ConnectedUniformMapChanged
- */
- virtual void ConnectedUniformMapChanged();
-
-protected: // From UniformMap::Observer
- /**
- * @copydoc UniformMap::Observer::UniformMappingsChanged
- */
- virtual void UniformMappingsChanged( const UniformMap& mappings );
-
-protected: // From UniformMapDataProvider
- /**
- * @copydoc UniformMapDataProvider::GetUniformMapChanged
- */
- virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const;
-
- /**
- * @copydoc UniformMapDataProvider::GetUniformMap
- */
- virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const;
-
-private:
- /**
- * Add any new mappings from map into the current map.
- * This doesn't override any existing mappings.
- * @param[in] localMap The map of collected uniforms.
- * @param[in] map The map to import into the local map
- */
- void AddMappings( CollectedUniformMap& localMap, const UniformMap& map );
-
- /**
- * Create a new render data provider
- * @return the new (initialized) data provider
- */
- RenderDataProvider* NewRenderDataProvider();
-
-private:
- NewRenderer* mRenderer; ///< Raw pointer to the new renderer (that's owned by RenderManager)
-
- Material* mMaterial; ///< The material this renderer uses. (Not owned)
- Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
-
- CollectedUniformMap mCollectedUniformMap[2];
- int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
- bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
- bool mResendDataProviders : 1; ///< True if the data providers should be resent to the renderer
- bool mResendGeometry : 1; ///< True if geometry should be resent to the renderer
- bool mUseBlend : 1; ///< True if the attachment & renderer should be considered opaque for sorting and blending.
-public: // Properties
-
- int mDepthIndex; ///< Used only in PrepareRenderInstructions
-};
-
-// Messages for RendererAttachment
-
-inline void SetMaterialMessage( EventThreadServices& eventThreadServices, const RendererAttachment& attachment, const Material& material )
-{
- typedef MessageDoubleBuffered1< RendererAttachment, Material* > 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, &RendererAttachment::SetMaterial, const_cast<Material*>(&material) );
-}
-
-inline void SetGeometryMessage( EventThreadServices& eventThreadServices, const RendererAttachment& attachment, const Geometry& geometry )
-{
- typedef MessageDoubleBuffered1< RendererAttachment, Geometry* > 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, &RendererAttachment::SetGeometry, const_cast<Geometry*>(&geometry) );
-}
-
-inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const RendererAttachment& attachment, int depthIndex )
-{
- typedef MessageValue1< RendererAttachment, int > 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, &RendererAttachment::SetDepthIndex, depthIndex );
-}
-
-} // namespace SceneGraph
-} // namespace Internal
-} // namespace Dali
-
-
-#endif // DALI_INTERNAL_SCENE_GRAPH_RENDERER_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>
+#include <dali/internal/common/internal-constants.h>
namespace Dali
{
mExclusiveRenderTask( NULL ),
mAttachment( NULL ),
mChildren(),
+ mRegenerateUniformMap( 0 ),
mDepth(0u),
mDirtyFlags(AllFlags),
mIsRoot( false ),
mPositionInheritanceMode( DEFAULT_POSITION_INHERITANCE_MODE ),
mColorMode( DEFAULT_COLOR_MODE )
{
+ mUniformMapChanged[0] = 0u;
+ mUniformMapChanged[1] = 0u;
}
Node::~Node()
mIsRoot = isRoot;
}
+bool Node::ResolveVisibility( BufferIndex updateBufferIndex )
+{
+ bool result = false;
+ const Vector4& color = GetWorldColor( updateBufferIndex );
+ if( color.a > FULLY_TRANSPARENT ) // not fully transparent
+ {
+ const float MAX_NODE_SIZE = float(1u<<30);
+ const Vector3& size = GetSize( updateBufferIndex );
+ if( ( size.width > Math::MACHINE_EPSILON_1000 ) && // width is greater than a very small number
+ ( size.height > Math::MACHINE_EPSILON_1000 ) ) // height is greater than a very small number
+ {
+ if( ( size.width < MAX_NODE_SIZE ) && // width is smaller than the maximum allowed size
+ ( size.height < MAX_NODE_SIZE ) ) // height is smaller than the maximum allowed size
+ {
+ result = true;
+ }
+ else
+ {
+ DALI_LOG_ERROR("Actor size should not be bigger than %f.\n", MAX_NODE_SIZE );
+ DALI_LOG_ACTOR_TREE( mParent );
+ }
+ }
+ }
+ return result;
+}
+
+void Node::AddUniformMapping( UniformPropertyMapping* map )
+{
+ PropertyOwner::AddUniformMapping( map );
+ mRegenerateUniformMap = 2;
+}
+
+void Node::RemoveUniformMapping( const std::string& uniformName )
+{
+ PropertyOwner::RemoveUniformMapping( uniformName );
+ mRegenerateUniformMap = 2;
+}
+
+void Node::PrepareRender( BufferIndex bufferIndex )
+{
+ if(mRegenerateUniformMap != 0 )
+ {
+ if( mRegenerateUniformMap == 2 )
+ {
+ CollectedUniformMap& localMap = mCollectedUniformMap[ bufferIndex ];
+ localMap.Resize(0);
+
+ for( unsigned int i=0, count=mUniformMaps.Count(); i<count; ++i )
+ {
+ localMap.PushBack( &mUniformMaps[i] );
+ }
+ }
+ else if( mRegenerateUniformMap == 1 )
+ {
+ CollectedUniformMap& localMap = mCollectedUniformMap[ bufferIndex ];
+ CollectedUniformMap& oldMap = mCollectedUniformMap[ 1-bufferIndex ];
+
+ localMap.Resize( oldMap.Count() );
+
+ unsigned int index=0;
+ for( CollectedUniformMap::Iterator iter = oldMap.Begin(), end = oldMap.End() ; iter != end ; ++iter, ++index )
+ {
+ localMap[index] = *iter;
+ }
+ }
+ --mRegenerateUniformMap;
+ mUniformMapChanged[bufferIndex] = 1u;
+ }
+}
+
void Node::ConnectChild( Node* childNode )
{
DALI_ASSERT_ALWAYS( this != childNode );
found->RecursiveDisconnectFromSceneGraph( updateBufferIndex, connectedNodes, disconnectedNodes );
}
+void Node::RemoveRenderer( Renderer* renderer )
+{
+ unsigned int rendererCount( mRenderer.Size() );
+ for( unsigned int i(0); i<rendererCount; ++i )
+ {
+ if( mRenderer[i] == renderer )
+ {
+ mRenderer.Erase( mRenderer.Begin()+i);
+ return;
+ }
+ }
+}
+
int Node::GetDirtyFlags() const
{
// get initial dirty flags, they are reset ResetDefaultProperties, but setters may have made the node dirty already
#include <dali/internal/update/nodes/node-declarations.h>
#include <dali/internal/update/node-attachments/node-attachment-declarations.h>
#include <dali/internal/render/data-providers/node-data-provider.h>
+#include <dali/internal/update/rendering/scene-graph-renderer.h>
namespace Dali
{
}
/**
+ * Add a renderer to the node
+ * @param[in] renderer The renderer added to the node
+ */
+ void AddRenderer( Renderer* renderer )
+ {
+ //Check that it has not been already added
+ unsigned int rendererCount( mRenderer.Size() );
+ for( unsigned int i(0); i<rendererCount; ++i )
+ {
+ if( mRenderer[i] == renderer )
+ {
+ mRenderer.Erase( mRenderer.Begin()+i);
+ return;
+ }
+ }
+ mRenderer.PushBack( renderer );
+ }
+
+ /**
+ * Remove a renderer from the node
+ * @param[in] renderer The renderer to be removed
+ */
+ void RemoveRenderer( Renderer* renderer );
+
+ /*
+ * Get the renderer at the given index
+ * @param[in] index
+ */
+ Renderer* GetRendererAt( unsigned int index )
+ {
+ return mRenderer[index];
+ }
+
+ /**
+ * Retrieve the number of renderers for the node
+ */
+ unsigned int GetRendererCount()
+ {
+ return mRenderer.Size();
+ }
+
+ /**
* Retreive the object attached to this node.
* @return The attachment.
*/
}
/**
+ * Check if the node is visible i.e Is not fully transparent and has valid size
+ */
+ bool ResolveVisibility( BufferIndex updateBufferIndex );
+
+ /**
* Set the world-matrix of a node, with scale + rotation + translation.
* Scale and rotation are centered at the origin.
* Translation is applied independently of the scale or rotatation axis.
return mDepth;
}
+public:
+ /**
+ * @copydoc UniformMap::Add
+ */
+ void AddUniformMapping( UniformPropertyMapping* map );
+
+ /**
+ * @copydoc UniformMap::Remove
+ */
+ void RemoveUniformMapping( const std::string& uniformName );
+
+ /**
+ * Prepare the node for rendering.
+ * This is called by the UpdateManager when an object is due to be rendered in the current frame.
+ * @param[in] updateBufferIndex The current update buffer index.
+ */
+ void PrepareRender( BufferIndex bufferIndex );
+
protected:
/**
/**
* @copydoc NodeDataProvider::GetModelMatrix
*/
- virtual const Matrix& GetModelMatrix( unsigned int bufferId )
+ virtual const Matrix& GetModelMatrix( unsigned int bufferId ) const
{
return GetWorldMatrix( bufferId );
}
/**
* @copydoc NodeDataProvider::GetRenderColor
*/
- virtual const Vector4& GetRenderColor( unsigned int bufferId )
+ virtual const Vector4& GetRenderColor( unsigned int bufferId ) const
{
return GetWorldColor( bufferId );
}
- virtual const Vector3& GetRenderSize( unsigned int bufferId )
+ virtual const Vector3& GetRenderSize( unsigned int bufferId ) const
{
return GetSize( bufferId );
}
+public: // From UniformMapDataProvider
+ /**
+ * @copydoc UniformMapDataProvider::GetUniformMapChanged
+ */
+ virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const
+ {
+ return mUniformMapChanged[bufferIndex];
+ }
+
+ /**
+ * @copydoc UniformMapDataProvider::GetUniformMap
+ */
+ virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const
+ {
+ return mCollectedUniformMap[bufferIndex];
+ }
private:
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
+ CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps of the node
+ unsigned int mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
+ unsigned int mRegenerateUniformMap : 2; ///< Indicate if the uniform map has to be regenerated this frame
// flags, compressed to bitfield
unsigned short mDepth: 12; ///< Depth in the hierarchy
new (slot) LocalType( &node, &Node::SetInheritOrientation, inherit );
}
-
-
inline void SetParentOriginMessage( EventThreadServices& eventThreadServices, const Node& node, const Vector3& origin )
{
typedef MessageValue1< Node, Vector3 > LocalType;
new (slot) LocalType( &node, &Node::SetDrawMode, drawMode );
}
+inline void AddRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer )
+{
+ typedef MessageValue1< Node, Renderer* > 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( &node, &Node::AddRenderer, renderer );
+}
+
+inline void RemoveRendererMessage( EventThreadServices& eventThreadServices, const Node& node, Renderer* renderer )
+{
+ typedef MessageValue1< Node, Renderer* > 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( &node, &Node::RemoveRenderer, renderer );
+}
} // namespace SceneGraph
} // namespace Internal
{
/**
+ * Pair of node-renderer
+ */
+struct NodeRenderer
+{
+ NodeRenderer()
+ :mNode(0),
+ mRenderer(0)
+ {}
+
+ NodeRenderer( Node* node, Renderer* renderer )
+ :mNode(node),
+ mRenderer(renderer)
+ {}
+
+ Node* mNode;
+ Renderer* mRenderer;
+};
+
+typedef Dali::Vector< NodeRenderer > NodeRendererContainer;
+
+/**
* 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.
*
RenderableAttachmentContainer colorRenderables;
RenderableAttachmentContainer overlayRenderables;
+ NodeRendererContainer stencilRenderers;
+ NodeRendererContainer colorRenderers;
+ NodeRendererContainer overlayRenderers;
+
private:
SortFunctionType mSortFunction; ///< Used to sort semi-transparent geometry
Geometry::~Geometry()
{
- // @todo Inform renderers of deletion of buffers?
-
- // could remove self from own uniform map observer, but it's about to be destroyed.
+ mConnectionObservers.Destroy( *this );
}
void Geometry::AddVertexBuffer( PropertyBuffer* vertexBuffer )
Material::~Material()
{
+ mConnectionObservers.Destroy( *this );
}
void Material::SetShader( Shader* shader )
* limitations under the License.
*/
-#include "scene-graph-renderer-attachment.h"
-#include <dali/internal/update/common/uniform-map.h>
-#include <dali/internal/update/manager/prepare-render-instructions.h>
+// CLASS HEADER
+#include "scene-graph-renderer.h"
+
+// INTERNAL HEADERS
+#include <dali/internal/update/controllers/scene-controller.h>
+#include <dali/internal/render/renderers/render-geometry.h>
+#include <dali/internal/update/controllers/render-message-dispatcher.h>
#include <dali/internal/update/rendering/scene-graph-geometry.h>
#include <dali/internal/update/rendering/scene-graph-material.h>
#include <dali/internal/update/rendering/scene-graph-sampler.h>
+#include <dali/internal/render/shaders/scene-graph-shader.h>
+#include <dali/internal/render/renderers/render-new-renderer.h>
+#include <dali/internal/render/data-providers/node-data-provider.h>
#include <dali/internal/update/resources/complete-status-manager.h>
-#include <dali/internal/update/resources/resource-manager.h>
-#include <dali/internal/render/data-providers/render-data-provider.h>
+#include <dali/internal/update/nodes/node.h>
+#include <dali/internal/update/resources/resource-tracker.h>
#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/common/internal-constants.h>
-#if defined(DEBUG_ENABLED)
-Debug::Filter* gImageAttachmentLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_SCENE_GRAPH_IMAGE_ATTACHMENT");
-#define ATTACHMENT_LOG(level) \
- DALI_LOG_INFO(gImageAttachmentLogFilter, level, "SceneGraph::ImageAttachment::%s: this:%p\n", __FUNCTION__, this)
-#define ATTACHMENT_LOG_FMT(level, format, args...) \
- DALI_LOG_INFO(gImageAttachmentLogFilter, level, "SceneGraph::ImageAttachment::%s: this:%p " format, __FUNCTION__, this, ## args)
+namespace // unnamed namespace
+{
+
+const unsigned int UNIFORM_MAP_READY = 0;
+const unsigned int COPY_UNIFORM_MAP = 1;
+const unsigned int REGENERATE_UNIFORM_MAP = 2;
-#else
+void AddMappings( Dali::Internal::SceneGraph::CollectedUniformMap& localMap, const Dali::Internal::SceneGraph::UniformMap& uniformMap )
+{
+ // Iterate thru uniformMap.
+ // Any maps that aren't in localMap should be added in a single step
+ Dali::Internal::SceneGraph::CollectedUniformMap newUniformMappings;
-#define ATTACHMENT_LOG(level)
-#define ATTACHMENT_LOG_FMT(level, format, args...)
+ for( unsigned int i=0, count=uniformMap.Count(); i<count; ++i )
+ {
+ Dali::Internal::SceneGraph::UniformPropertyMapping::Hash nameHash = uniformMap[i].uniformNameHash;
+ bool found = false;
-#endif
+ for( Dali::Internal::SceneGraph::CollectedUniformMap::Iterator iter = localMap.Begin() ; iter != localMap.End() ; ++iter )
+ {
+ const Dali::Internal::SceneGraph::UniformPropertyMapping* map = (*iter);
+ if( map->uniformNameHash == nameHash )
+ {
+ if( map->uniformName == uniformMap[i].uniformName )
+ {
+ found = true;
+ break;
+ }
+ }
+ }
+ if( !found )
+ {
+ // it's a new mapping. Add raw ptr to temporary list
+ newUniformMappings.PushBack( &uniformMap[i] );
+ }
+ }
+ if( newUniformMappings.Count() > 0 )
+ {
+ localMap.Reserve( localMap.Count() + newUniformMappings.Count() );
-namespace // unnamed namespace
-{
-const int REGENERATE_UNIFORM_MAP = 2;
-const int COPY_UNIFORM_MAP = 1;
+ for( Dali::Internal::SceneGraph::CollectedUniformMap::Iterator iter = newUniformMappings.Begin(),
+ end = newUniformMappings.End() ;
+ iter != end ;
+ ++iter )
+ {
+ const Dali::Internal::SceneGraph::UniformPropertyMapping* map = (*iter);
+ localMap.PushBack( map );
+ }
+ //@todo MESH_REWORK Use memcpy to copy ptrs from one array to the other
+ }
+}
}
namespace Dali
namespace SceneGraph
{
-RendererAttachment* RendererAttachment::New()
-{
- return new RendererAttachment();
-}
-
-
-RendererAttachment::RendererAttachment()
-: RenderableAttachment( false ),
- mRenderer(NULL),
- mMaterial(NULL),
- mGeometry(NULL),
- mRegenerateUniformMap(REGENERATE_UNIFORM_MAP),
- mResendDataProviders(false),
- mResendGeometry(false),
- mUseBlend( false ),
- mDepthIndex(0)
+Renderer::Renderer()
+:mSceneController(0),
+ mRenderer(NULL),
+ mMaterial(NULL),
+ mGeometry(NULL),
+ mReferenceCount(0),
+ mRegenerateUniformMap(0),
+ mResendDataProviders(false),
+ mResendGeometry(false),
+ mHasUntrackedResources(false),
+ mFinishedResourceAcquisition(false),
+ mResourcesReady(false),
+ mDepthIndex(0)
{
mUniformMapChanged[0]=false;
mUniformMapChanged[1]=false;
AddUniformMapObserver( *this );
}
-
-RendererAttachment::~RendererAttachment()
+Renderer::~Renderer()
{
if (mMaterial)
{
}
}
-void RendererAttachment::Initialize2( BufferIndex updateBufferIndex )
+void Renderer::PrepareRender( BufferIndex updateBufferIndex )
{
- DALI_ASSERT_DEBUG( mSceneController );
-}
+ mMaterial->PrepareRender( updateBufferIndex );
-void RendererAttachment::OnDestroy2()
-{
-}
+ if( mRegenerateUniformMap > UNIFORM_MAP_READY )
+ {
+ DALI_ASSERT_DEBUG( mGeometry != NULL && "No geometry available in DoPrepareRender()" );
+ DALI_ASSERT_DEBUG( mMaterial != NULL && "No geometry available in DoPrepareRender()" );
-void RendererAttachment::ConnectedToSceneGraph()
-{
- mRegenerateUniformMap = REGENERATE_UNIFORM_MAP;
- mParent->AddUniformMapObserver( *this ); // Watch actor's uniform maps
+ if( mRegenerateUniformMap == REGENERATE_UNIFORM_MAP)
+ {
+ CollectedUniformMap& localMap = mCollectedUniformMap[ updateBufferIndex ];
+ localMap.Resize(0);
- DALI_ASSERT_DEBUG( mParent != NULL );
+ const UniformMap& rendererUniformMap = PropertyOwner::GetUniformMap();
+ AddMappings( localMap, rendererUniformMap );
- RenderDataProvider* dataProvider = NewRenderDataProvider();
+ AddMappings( localMap, mMaterial->GetUniformMap() );
+ Vector<Sampler*>& samplers = mMaterial->GetSamplers();
+ unsigned int samplerCount( samplers.Size() );
+ for( unsigned int i(0); i<samplerCount; ++i )
+ {
+ AddMappings( localMap, samplers[i]->GetUniformMap() );
+ }
- RenderGeometry* renderGeometry = mGeometry->GetRenderGeometry(mSceneController);
- mRenderer = NewRenderer::New( *mParent, dataProvider, renderGeometry );
- mSceneController->GetRenderMessageDispatcher().AddRenderer( *mRenderer );
-}
+ AddMappings( localMap, mMaterial->GetShader()->GetUniformMap() );
+ AddMappings( localMap, mGeometry->GetUniformMap() );
-void RendererAttachment::DisconnectedFromSceneGraph()
-{
- mRegenerateUniformMap = 0;
- mParent->RemoveUniformMapObserver( *this );
+ Vector<PropertyBuffer*>& vertexBuffers = mGeometry->GetVertexBuffers();
+ unsigned int vertexBufferCount( vertexBuffers.Size() );
+ for( unsigned int i(0); i<vertexBufferCount; ++i )
+ {
+ AddMappings( localMap, vertexBuffers[i]->GetUniformMap() );
+ }
+
+ PropertyBuffer* indexBuffer = mGeometry->GetIndexBuffer();
+ if( indexBuffer )
+ {
+ AddMappings( localMap, indexBuffer->GetUniformMap() );
+ }
+ }
+ else if( mRegenerateUniformMap == COPY_UNIFORM_MAP )
+ {
+ // Copy old map into current map
+ CollectedUniformMap& localMap = mCollectedUniformMap[ updateBufferIndex ];
+ CollectedUniformMap& oldMap = mCollectedUniformMap[ 1-updateBufferIndex ];
- mGeometry->OnRendererDisconnect();
+ localMap.Resize( oldMap.Count() );
- DALI_ASSERT_DEBUG( mSceneController );
- mSceneController->GetRenderMessageDispatcher().RemoveRenderer( *mRenderer );
- mRenderer = NULL;
+ unsigned int index=0;
+ for( CollectedUniformMap::Iterator iter = oldMap.Begin(), end = oldMap.End() ; iter != end ; ++iter, ++index )
+ {
+ localMap[index] = *iter;
+ }
+ }
+
+ mUniformMapChanged[updateBufferIndex] = true;
+ mRegenerateUniformMap--;
+ }
+
+ if( mResendDataProviders )
+ {
+ RenderDataProvider* dataProvider = NewRenderDataProvider();
+
+ // Tell renderer about a new provider
+ // @todo MESH_REWORK Should we instead create a new renderer when these change?
+
+ typedef MessageValue1< Render::NewRenderer, OwnerPointer<RenderDataProvider> > DerivedType;
+ unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
+ new (slot) DerivedType( mRenderer, &Render::NewRenderer::SetRenderDataProvider, dataProvider );
+ mResendDataProviders = false;
+ }
+
+ if( mResendGeometry )
+ {
+ // The first call to GetRenderGeometry() creates the geometry and sends it in a message
+ RenderGeometry* geometry = mGeometry->GetRenderGeometry( mSceneController );
+
+ typedef MessageValue1< Render::NewRenderer, RenderGeometry* > DerivedType;
+ unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
+
+ new (slot) DerivedType( mRenderer, &Render::NewRenderer::SetGeometry, geometry );
+ mResendGeometry = false;
+ }
}
-void RendererAttachment::SetMaterial( BufferIndex updateBufferIndex, Material* material)
+void Renderer::SetMaterial( BufferIndex bufferIndex, Material* material)
{
DALI_ASSERT_DEBUG( material != NULL && "Material pointer is NULL" );
mResendDataProviders = true;
}
-Material& RendererAttachment::GetMaterial()
-{
- return *mMaterial;
-}
-
-void RendererAttachment::SetGeometry( BufferIndex updateBufferIndex, Geometry* geometry)
+void Renderer::SetGeometry( BufferIndex bufferIndex, Geometry* geometry)
{
DALI_ASSERT_DEBUG( geometry != NULL && "Geometry pointer is NULL");
if( mGeometry)
}
}
-Geometry& RendererAttachment::GetGeometry()
+void Renderer::SetDepthIndex( int depthIndex )
{
- return *mGeometry;
+ mDepthIndex = depthIndex;
}
-void RendererAttachment::SetSortAttributes( BufferIndex bufferIndex, RendererWithSortAttributes& sortAttributes )
+//Called when a node with this renderer is added to the stage
+void Renderer::OnStageConnect()
{
- sortAttributes.shader = mMaterial->GetShader();
- sortAttributes.material = mMaterial;
- sortAttributes.geometry = mGeometry;
+ ++mReferenceCount;
+ if( !mRenderer)
+ {
+ RenderDataProvider* dataProvider = NewRenderDataProvider();
+
+ RenderGeometry* renderGeometry = mGeometry->GetRenderGeometry(mSceneController);
+ mRenderer = Render::NewRenderer::New( dataProvider, renderGeometry );
+ mSceneController->GetRenderMessageDispatcher().AddRenderer( *mRenderer );
+ mResendDataProviders = false;
+ mResendGeometry = false;
+ }
}
-void RendererAttachment::SetDepthIndex( int depthIndex )
+//Called when the node with this renderer has gone out of the stage
+void Renderer::OnStageDisconnect()
{
- mDepthIndex = depthIndex;
-
- if( mParent )
+ --mReferenceCount;
+ if( mReferenceCount == 0 )
{
- // only do this if we are on-stage. Ensures the render lists are re-sorted
- mParent->SetDirtyFlag( SortModifierFlag );
+ mSceneController->GetRenderMessageDispatcher().RemoveRenderer( *mRenderer );
+ mRenderer = NULL;
}
}
-Renderer& RendererAttachment::GetRenderer()
+//Called when SceneGraph::Renderer is added to update manager ( that happens when an "event-thread renderer" is created )
+void Renderer::ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
{
- return *mRenderer;
+ mRegenerateUniformMap = REGENERATE_UNIFORM_MAP;
+ mSceneController = &sceneController;
}
-const Renderer& RendererAttachment::GetRenderer() const
+
+//Called just before destroying the scene-graph renderer ( when the "event-thread renderer" is no longer referenced )
+void Renderer::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex )
{
- return *mRenderer;
+ //Remove renderer from RenderManager
+ if( mRenderer )
+ {
+ mSceneController->GetRenderMessageDispatcher().RemoveRenderer( *mRenderer );
+ mRenderer = NULL;
+ mSceneController = NULL;
+ }
}
-// Called by ProcessRenderTasks after DoPrepareRender
-bool RendererAttachment::IsFullyOpaque( BufferIndex updateBufferIndex )
+RenderDataProvider* Renderer::NewRenderDataProvider()
{
- bool opaque = false;
+ RenderDataProvider* dataProvider = new RenderDataProvider();
- if( mMaterial != NULL )
+ dataProvider->mMaterialDataProvider = mMaterial;
+ dataProvider->mUniformMapDataProvider = this;
+ dataProvider->mShader = mMaterial->GetShader();
+
+ Vector<Sampler*>& samplers = mMaterial->GetSamplers();
+ unsigned int sampleCount( samplers.Count() );
+ dataProvider->mSamplers.Resize( sampleCount );
+ for( unsigned int i(0); i<sampleCount; ++i )
{
- Material::BlendPolicy blendPolicy = mMaterial->GetBlendPolicy();
- switch( blendPolicy )
- {
- case Material::OPAQUE:
- {
- opaque = true;
- break;
- }
- case Material::TRANSPARENT:
- {
- opaque = false;
- break;
- }
- case Material::USE_ACTOR_COLOR:
- {
- if( mParent )
- {
- opaque = mParent->GetWorldColor( updateBufferIndex ).a >= FULLY_OPAQUE;
- }
- break;
- }
- }
+ dataProvider->mSamplers[i] = samplers[i]; // Convert from derived type to base type
}
- return opaque;
+ return dataProvider;
}
-void RendererAttachment::SizeChanged( BufferIndex updateBufferIndex )
+Render::Renderer& Renderer::GetRenderer()
{
- // Do nothing.
+ return *mRenderer;
}
-bool RendererAttachment::DoPrepareResources(
- BufferIndex updateBufferIndex,
- ResourceManager& resourceManager )
+const CollectedUniformMap& Renderer::GetUniformMap( BufferIndex bufferIndex ) const
+{
+ return mCollectedUniformMap[bufferIndex];
+};
+
+void Renderer::PrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager )
{
+ mHasUntrackedResources = false;
+ mTrackedResources.Clear(); // Resource trackers are only needed if not yet completea
+
DALI_ASSERT_DEBUG( mSceneController );
CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager();
- bool ready = false;
+ mResourcesReady = false;
+
+
mFinishedResourceAcquisition = false;
// Can only be considered ready when all the scene graph objects are connected to the renderer
- if( ( mGeometry ) &&
- ( mGeometry->GetVertexBuffers().Count() > 0 ) &&
- ( mMaterial ) &&
- ( mMaterial->GetShader() != NULL ) )
+ if( ( mGeometry ) && ( mGeometry->GetVertexBuffers().Count() > 0 ) &&
+ ( mMaterial ) && ( mMaterial->GetShader() != NULL ) )
{
unsigned int completeCount = 0;
unsigned int neverCount = 0;
unsigned int frameBufferCount = 0;
Vector<Sampler*>& samplers = mMaterial->GetSamplers();
- for( Vector<Sampler*>::ConstIterator iter = samplers.Begin();
- iter != samplers.End(); ++iter )
+ unsigned int samplerCount( samplers.Size() );
+ for( unsigned int i(0); i<samplerCount; ++i )
{
- Sampler* sampler = *iter;
-
- ResourceId textureId = sampler->GetTextureId( updateBufferIndex );
+ ResourceId textureId = samplers[i]->GetTextureId( updateBufferIndex );
BitmapMetadata metaData = resourceManager.GetBitmapMetadata( textureId );
- sampler->SetFullyOpaque( metaData.IsFullyOpaque() );
+ samplers[i]->SetFullyOpaque( metaData.IsFullyOpaque() );
switch( completeStatusManager.GetStatus( textureId ) )
{
{
frameBufferCount++;
}
- FollowTracker( textureId ); // @todo MESH_REWORK Trackers per sampler rather than per actor?
+ if( completeStatusManager.FindResourceTracker(textureId) != NULL )
+ {
+ bool found = false;
+ std::size_t numTrackedResources = mTrackedResources.Count();
+ for( size_t i=0; i < numTrackedResources; ++i )
+ {
+ if(mTrackedResources[i] == textureId)
+ {
+ found = true;
+ break;
+ }
+ }
+ if( ! found )
+ {
+ mTrackedResources.PushBack( textureId );
+ }
+ }
+ else
+ {
+ mHasUntrackedResources = true;
+ }
}
break;
}
// We are ready if all samplers are complete, or those that aren't are framebuffers
- // We are complete if all samplers are either complete or will never complete
-
- ready = ( completeCount + frameBufferCount >= samplers.Count() ) ;
+ // We are complete if all samplers are either complete or will nmResendGeometryever complete
+ mResourcesReady = ( completeCount + frameBufferCount >= samplers.Count() ) ;
mFinishedResourceAcquisition = ( completeCount + neverCount >= samplers.Count() );
}
-
- return ready;
}
-
-// Uniform maps are checked in the following priority order:
-// Renderer (this object)
-// Actor
-// Material
-// Samplers
-// Shader
-// Geometry
-// VertexBuffers
-void RendererAttachment::DoPrepareRender( BufferIndex updateBufferIndex )
+void Renderer::GetReadyAndComplete(bool& ready, bool& complete) const
{
- // @todo MESH_REWORK - call DoPrepareRender on all scene objects? in caller class?
- mMaterial->PrepareRender( updateBufferIndex );
+ ready = mResourcesReady;
+ complete = false;
+
+ CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager();
- if( mRegenerateUniformMap > 0)
+ std::size_t numTrackedResources = mTrackedResources.Count();
+ if( mHasUntrackedResources || numTrackedResources == 0 )
{
- if( mRegenerateUniformMap == REGENERATE_UNIFORM_MAP)
+ complete = mFinishedResourceAcquisition;
+ }
+ else
+ {
+ // If there are tracked resources and no untracked resources, test the trackers
+ bool trackersComplete = true;
+ for( size_t i=0; i < numTrackedResources; ++i )
{
- DALI_ASSERT_DEBUG( mGeometry != NULL && "No geometry available in DoPrepareRender()" );
- DALI_ASSERT_DEBUG( mMaterial != NULL && "No geometry available in DoPrepareRender()" );
-
- CollectedUniformMap& localMap = mCollectedUniformMap[ updateBufferIndex ];
- localMap.Resize(0);
-
- const UniformMap& rendererUniformMap = PropertyOwner::GetUniformMap();
- AddMappings( localMap, rendererUniformMap );
-
- const UniformMap& actorUniformMap = mParent->GetUniformMap();
- AddMappings( localMap, actorUniformMap );
-
- AddMappings( localMap, mMaterial->GetUniformMap() );
- Vector<Sampler*>& samplers = mMaterial->GetSamplers();
- for( Vector<Sampler*>::ConstIterator iter = samplers.Begin(), end = samplers.End();
- iter != end ;
- ++iter )
+ ResourceId id = mTrackedResources[i];
+ ResourceTracker* tracker = completeStatusManager.FindResourceTracker(id);
+ if( tracker && ! tracker->IsComplete() )
{
- const SceneGraph::Sampler* sampler = (*iter);
- AddMappings( localMap, sampler->GetUniformMap() );
+ trackersComplete = false;
+ break;
}
+ }
- AddMappings( localMap, mMaterial->GetShader()->GetUniformMap() );
+ complete = mFinishedResourceAcquisition || trackersComplete;
+ }
+}
- AddMappings( localMap, mGeometry->GetUniformMap() );
+// Called by ProcessRenderTasks after DoPrepareRender
+bool Renderer::IsFullyOpaque( BufferIndex updateBufferIndex, const Node& node ) const
+{
+ bool opaque = false;
- Vector<PropertyBuffer*>& vertexBuffers = mGeometry->GetVertexBuffers();
- for( Vector<PropertyBuffer*>::ConstIterator iter = vertexBuffers.Begin(), end = vertexBuffers.End() ;
- iter != end ;
- ++iter )
+ if( mMaterial != NULL )
+ {
+ Material::BlendPolicy blendPolicy = mMaterial->GetBlendPolicy();
+ switch( blendPolicy )
+ {
+ case Material::OPAQUE:
{
- const SceneGraph::PropertyBuffer* vertexBuffer = *iter;
- AddMappings( localMap, vertexBuffer->GetUniformMap() );
+ opaque = true;
+ break;
}
-
- PropertyBuffer* indexBuffer = mGeometry->GetIndexBuffer();
- if( indexBuffer )
+ case Material::TRANSPARENT:
{
- AddMappings( localMap, indexBuffer->GetUniformMap() );
+ opaque = false;
+ break;
}
-
- mUniformMapChanged[updateBufferIndex] = true;
- }
- else if( mRegenerateUniformMap == COPY_UNIFORM_MAP )
- {
- // Copy old map into current map
- CollectedUniformMap& localMap = mCollectedUniformMap[ updateBufferIndex ];
- CollectedUniformMap& oldMap = mCollectedUniformMap[ 1-updateBufferIndex ];
-
- localMap.Resize( oldMap.Count() );
-
- unsigned int index=0;
- for( CollectedUniformMap::Iterator iter = oldMap.Begin(), end = oldMap.End() ; iter != end ; ++iter, ++index )
+ case Material::USE_ACTOR_COLOR:
{
- localMap[index] = *iter;
+ opaque = node.GetWorldColor( updateBufferIndex ).a >= FULLY_OPAQUE;
+ break;
}
-
- mUniformMapChanged[updateBufferIndex] = true;
}
-
- mRegenerateUniformMap--;
- }
-
- bool blend = !IsFullyOpaque( updateBufferIndex );
- if( mUseBlend != blend )
- {
- mUseBlend = blend;
- mResendDataProviders = true;
- }
-
- if( mResendDataProviders )
- {
- RenderDataProvider* dataProvider = NewRenderDataProvider();
-
- // Tell renderer about a new provider
- // @todo MESH_REWORK Should we instead create a new renderer when these change?
-
- typedef MessageValue1< NewRenderer, OwnerPointer<RenderDataProvider> > DerivedType;
- unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
- new (slot) DerivedType( mRenderer, &NewRenderer::SetRenderDataProvider, dataProvider );
- mResendDataProviders = false;
}
- if( mResendGeometry )
- {
- // The first call to GetRenderGeometry() creates the geometry and sends it in a message
- RenderGeometry* geometry = mGeometry->GetRenderGeometry( mSceneController );
-
- typedef MessageValue1< NewRenderer, RenderGeometry* > DerivedType;
- unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
-
- new (slot) DerivedType( mRenderer, &NewRenderer::SetGeometry, geometry );
- mResendGeometry = false;
- }
+ return opaque;
}
-void RendererAttachment::ConnectionsChanged( PropertyOwner& object )
+void Renderer::ConnectionsChanged( PropertyOwner& object )
{
// One of our child objects has changed it's connections. Ensure the uniform
// map gets regenerated during PrepareRender
mResendDataProviders = true;
}
-void RendererAttachment::ConnectedUniformMapChanged()
+void Renderer::ConnectedUniformMapChanged()
{
mRegenerateUniformMap = REGENERATE_UNIFORM_MAP;
}
-void RendererAttachment::UniformMappingsChanged( const UniformMap& mappings )
+void Renderer::UniformMappingsChanged( const UniformMap& mappings )
{
// The mappings are either from PropertyOwner base class, or the Actor
mRegenerateUniformMap = REGENERATE_UNIFORM_MAP;
}
-bool RendererAttachment::GetUniformMapChanged( BufferIndex bufferIndex ) const
+void Renderer::ObservedObjectDestroyed(PropertyOwner& owner)
{
- return mUniformMapChanged[bufferIndex];
-}
-
-const CollectedUniformMap& RendererAttachment::GetUniformMap( BufferIndex bufferIndex ) const
-{
- return mCollectedUniformMap[ bufferIndex ];
-}
-
-void RendererAttachment::AddMappings( CollectedUniformMap& localMap, const UniformMap& uniformMap )
-{
- // Iterate thru uniformMap.
- // Any maps that aren't in localMap should be added in a single step
- CollectedUniformMap newUniformMappings;
-
- for( unsigned int i=0, count=uniformMap.Count(); i<count; ++i )
- {
- UniformPropertyMapping::Hash nameHash = uniformMap[i].uniformNameHash;
- bool found = false;
-
- for( CollectedUniformMap::Iterator iter = localMap.Begin() ; iter != localMap.End() ; ++iter )
- {
- const UniformPropertyMapping* map = (*iter);
- if( map->uniformNameHash == nameHash )
- {
- if( map->uniformName == uniformMap[i].uniformName )
- {
- found = true;
- break;
- }
- }
- }
- if( !found )
- {
- // it's a new mapping. Add raw ptr to temporary list
- newUniformMappings.PushBack( &uniformMap[i] );
- }
- }
-
- if( newUniformMappings.Count() > 0 )
+ if( reinterpret_cast<PropertyOwner*>(mGeometry) == &owner )
{
- localMap.Reserve( localMap.Count() + newUniformMappings.Count() );
-
- for( CollectedUniformMap::Iterator iter = newUniformMappings.Begin(),
- end = newUniformMappings.End() ;
- iter != end ;
- ++iter )
- {
- const UniformPropertyMapping* map = (*iter);
- localMap.PushBack( map );
- }
- //@todo MESH_REWORK Use memcpy to copy ptrs from one array to the other
+ mGeometry = NULL;
}
-}
-
-RenderDataProvider* RendererAttachment::NewRenderDataProvider()
-{
- RenderDataProvider* dataProvider = new RenderDataProvider();
-
- dataProvider->mMaterialDataProvider = mMaterial;
- dataProvider->mUniformMapDataProvider = this;
- dataProvider->mShader = mMaterial->GetShader();
- dataProvider->mUseBlend = mUseBlend;
-
- Vector<Sampler*>& samplers = mMaterial->GetSamplers();
- dataProvider->mSamplers.Reserve( samplers.Count() );
- for( Vector<Sampler*>::Iterator iter = samplers.Begin() ;
- iter != samplers.End();
- ++iter )
+ else if( reinterpret_cast<PropertyOwner*>(mMaterial) == &owner )
{
- dataProvider->mSamplers.PushBack(*iter); // Convert from derived type to base type
+ mMaterial = NULL;
}
- return dataProvider;
}
-
} // namespace SceneGraph
} // namespace Internal
} // namespace Dali
--- /dev/null
+#ifndef DALI_INTERNAL_SCENE_GRAPH_RENDERER2_H
+#define DALI_INTERNAL_SCENE_GRAPH_RENDERER2_H
+
+/*
+ * Copyright (c) 2015 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.
+ */
+
+
+#include <dali/devel-api/rendering/geometry.h>
+#include <dali/internal/event/common/event-thread-services.h>
+#include <dali/internal/update/common/animatable-property.h>
+#include <dali/internal/update/common/double-buffered.h>
+#include <dali/internal/update/common/double-buffered-property.h>
+#include <dali/internal/update/common/property-owner.h>
+#include <dali/internal/update/common/property-boolean.h>
+#include <dali/internal/update/common/uniform-map.h>
+#include <dali/internal/update/common/scene-graph-connection-change-propagator.h>
+#include <dali/internal/update/common/scene-graph-property-buffer.h>
+#include <dali/internal/render/data-providers/geometry-data-provider.h>
+#include <dali/internal/render/data-providers/render-data-provider.h>
+#include <dali/internal/render/renderers/render-new-renderer.h>
+#include <dali/internal/update/resources/resource-manager.h>
+
+namespace Dali
+{
+namespace Internal
+{
+
+namespace Render
+{
+class NewRenderer;
+}
+
+namespace SceneGraph
+{
+
+class Renderer;
+typedef Dali::Vector< Renderer* > RendererContainer;
+typedef RendererContainer::Iterator RendererIter;
+typedef RendererContainer::ConstIterator RendererConstIter;
+
+class Material;
+class Geometry;
+
+class Renderer : public PropertyOwner,
+ public UniformMapDataProvider,
+ public UniformMap::Observer,
+ public ConnectionChangePropagator::Observer
+{
+public:
+
+ /**
+ * Default constructor
+ */
+ Renderer();
+
+ /**
+ * Destructor
+ */
+ virtual ~Renderer();
+
+ /**
+ * Set the material for the renderer
+ * @param[in] bufferIndex The current frame's buffer index
+ * @param[in] material The material this renderer will use
+ */
+ void SetMaterial( BufferIndex bufferIndex, Material* material);
+
+ /**
+ * Get the material of this renderer
+ * @return the material this renderer uses
+ */
+ Material& GetMaterial()
+ {
+ return *mMaterial;
+ }
+
+ /**
+ * Set the geometry for the renderer
+ * @param[in] bufferIndex The current frame's buffer index
+ * @param[in] geometry The geometry this renderer will use
+ */
+ void SetGeometry( BufferIndex bufferIndex, Geometry* material);
+
+ /**
+ * Get the geometry of this renderer
+ * @return the geometry this renderer uses
+ */
+ Geometry& GetGeometry()
+ {
+ return *mGeometry;
+ }
+
+ /**
+ * Set the depth index
+ * @param[in] depthIndex the new depth index to use
+ */
+ void SetDepthIndex( int depthIndex );
+
+ /**
+ * @brief Get the depth index
+ * @return The depth index
+ */
+ int GetDepthIndex() const
+ {
+ return mDepthIndex;
+ }
+
+ /**
+ * Called when an actor with this renderer is added to the stage
+ */
+ void OnStageConnect();
+
+ /*
+ * Called when an actor with this renderer is removed from the stage
+ */
+ void OnStageDisconnect();
+
+ /**
+ * Prepare the object for rendering.
+ * This is called by the UpdateManager when an object is due to be rendered in the current frame.
+ * @param[in] updateBufferIndex The current update buffer index.
+ */
+ void PrepareRender( BufferIndex updateBufferIndex );
+
+ /*
+ * Retrieve the Render thread renderer
+ * @return The associated render thread renderer
+ */
+ Render::Renderer& GetRenderer();
+
+ /**
+ * Prepare the object resources.
+ * This must be called by the UpdateManager before calling PrepareRender, for each frame.
+ * @param[in] updateBufferIndex The current update buffer index.
+ * @param[in] resourceManager The resource manager.
+ */
+ void PrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager );
+
+ /**
+ * Check whether the renderer has been marked as ready to render
+ * @param[out] ready TRUE if the renderer has resources to render
+ * @param[out] complete TRUE if the renderer resources are complete
+ * (e.g. image has finished loading, framebuffer is ready to render, native image
+ * framebuffer has been rendered)
+ */
+ void GetReadyAndComplete(bool& ready, bool& complete) const;
+
+ /**
+ * Query whether the renderer is fully opaque.
+ * @param[in] updateBufferIndex The current update buffer index.
+ * @return True if fully opaque.
+ */
+ bool IsFullyOpaque( BufferIndex updateBufferIndex, const Node& node ) const;
+
+ /**
+ * Query whether the renderer is currently in use by an actor on the stage
+ */
+ bool IsReferenced() const
+ {
+ return mReferenceCount > 0;
+ }
+
+
+public: // Implementation of ObjectOwnerContainer template methods
+ /**
+ * Connect the object to the scene graph
+ *
+ * @param[in] sceneController The scene controller - used for sending messages to render thread
+ * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
+ */
+ void ConnectToSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
+
+ /**
+ * Disconnect the object from the scene graph
+ * @param[in] sceneController The scene controller - used for sending messages to render thread
+ * @param[in] bufferIndex The current buffer index - used for sending messages to render thread
+ */
+ void DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex );
+
+public: // Implementation of ConnectionChangePropagator
+ /**
+ * @copydoc ConnectionChangePropagator::AddObserver
+ */
+ void AddConnectionObserver(ConnectionChangePropagator::Observer& observer){};
+
+ /**
+ * @copydoc ConnectionChangePropagator::RemoveObserver
+ */
+ void RemoveConnectionObserver(ConnectionChangePropagator::Observer& observer){};
+
+public:
+
+
+public: // UniformMap::Observer
+ /**
+ * @copydoc UniformMap::Observer::UniformMappingsChanged
+ */
+ virtual void UniformMappingsChanged( const UniformMap& mappings );
+
+public: // ConnectionChangePropagator::Observer
+
+ /**
+ * @copydoc ConnectionChangePropagator::ConnectionsChanged
+ */
+ virtual void ConnectionsChanged( PropertyOwner& owner );
+
+ /**
+ * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
+ */
+ virtual void ConnectedUniformMapChanged( );
+
+ /**
+ * @copydoc ConnectionChangePropagator::ConnectedUniformMapChanged
+ */
+ virtual void ObservedObjectDestroyed(PropertyOwner& owner);
+
+public: // PropertyOwner implementation
+ /**
+ * @copydoc Dali::Internal::SceneGraph::PropertyOwner::ResetDefaultProperties()
+ */
+ virtual void ResetDefaultProperties( BufferIndex updateBufferIndex ){};
+
+public: // From UniformMapDataProvider
+
+ /**
+ * @copydoc UniformMapDataProvider::GetUniformMapChanged
+ */
+ virtual bool GetUniformMapChanged( BufferIndex bufferIndex ) const{ return mUniformMapChanged[bufferIndex];}
+
+ /**
+ * @copydoc UniformMapDataProvider::GetUniformMap
+ */
+ virtual const CollectedUniformMap& GetUniformMap( BufferIndex bufferIndex ) const;
+
+private:
+
+ /**
+ * Helper function to create a new render data provider
+ * @return the new (initialized) data provider
+ */
+ RenderDataProvider* NewRenderDataProvider();
+
+ SceneController* mSceneController; ///< Used for initializing renderers whilst attached
+ Render::NewRenderer* mRenderer; ///< Raw pointer to the new renderer (that's owned by RenderManager)
+ Material* mMaterial; ///< The material this renderer uses. (Not owned)
+ Geometry* mGeometry; ///< The geometry this renderer uses. (Not owned)
+
+ Dali::Vector< Integration::ResourceId > mTrackedResources; ///< Filled during PrepareResources if there are uncomplete, tracked resources.
+
+ CollectedUniformMap mCollectedUniformMap[2]; ///< Uniform maps collected by the renderer
+ unsigned int mReferenceCount; ///< Number of nodes currently using this renderer
+ unsigned int mRegenerateUniformMap; ///< 2 if the map should be regenerated, 1 if it should be copied.
+ bool mUniformMapChanged[2]; ///< Records if the uniform map has been altered this frame
+ bool mResendDataProviders : 1; ///< True if the data providers should be resent to the renderer
+ bool mResendGeometry : 1; ///< True if geometry should be resent to the renderer
+ bool mHasUntrackedResources : 1; ///< Set during PrepareResources, true if have tried to follow untracked resources
+ bool mFinishedResourceAcquisition : 1; ///< Set during DoPrepareResources; true if ready & all resource acquisition has finished (successfully or otherwise)
+ bool mResourcesReady : 1; ///< Set during the Update algorithm; true if the attachment has resources ready for the current frame.
+
+public:
+ int mDepthIndex; ///< Used only in PrepareRenderInstructions
+};
+
+
+/// Messages
+inline void SetMaterialMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Material& material )
+{
+ typedef MessageDoubleBuffered1< Renderer, Material* > 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( &renderer, &Renderer::SetMaterial, const_cast<Material*>(&material) );
+}
+
+inline void SetGeometryMessage( EventThreadServices& eventThreadServices, const Renderer& renderer, const Geometry& geometry )
+{
+ typedef MessageDoubleBuffered1< Renderer, Geometry* > 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( &renderer, &Renderer::SetGeometry, const_cast<Geometry*>(&geometry) );
+}
+
+inline void SetDepthIndexMessage( EventThreadServices& eventThreadServices, const Renderer& attachment, int depthIndex )
+{
+ typedef MessageValue1< Renderer, int > 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, &Renderer::SetDepthIndex, depthIndex );
+}
+
+inline void OnStageConnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
+{
+ typedef Message< Renderer > 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( &renderer, &Renderer::OnStageConnect );
+}
+
+inline void OnStageDisconnectMessage( EventThreadServices& eventThreadServices, const Renderer& renderer )
+{
+ typedef Message< Renderer > 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( &renderer, &Renderer::OnStageDisconnect );
+}
+
+} // namespace SceneGraph
+} // namespace Internal
+} // namespace Dali
+
+#endif // DALI_INTERNAL_SCENE_GRAPH_RENDERER_H
Renderer Actor::GetRendererAt( unsigned int index )
{
- return Renderer( &GetImplementation(*this).GetRendererAt( index ) );
+ Internal::RendererPtr renderer = GetImplementation(*this).GetRendererAt( index );
+ return Renderer( renderer.Get() );
}
void Actor::RemoveRenderer( Renderer& renderer )
}
/**
+ * @ return If the vector is empty
+ */
+ bool Empty() const
+ {
+ return Count() == 0u;
+ }
+
+ /**
* @return The capacity of this vector.
*/
SizeType Capacity() const;