RendererAttachmentPtr attachment( new RendererAttachment( stage ) );
// Transfer object ownership of scene-object to message
- SceneGraph::RendererAttachment* sceneObject = CreateSceneObject();
+ SceneGraph::RendererAttachment* sceneObject = renderer.GetRendererSceneObject();
AttachToNodeMessage( stage.GetUpdateManager(), parentNode, sceneObject );
// Keep raw pointer for message passing
#include <dali/public-api/actors/renderer.h> // Dali::Renderer
#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/stage-impl.h>
#include <dali/internal/update/node-attachments/scene-graph-renderer-attachment.h>
namespace Dali
RendererPtr Renderer::New()
{
- return RendererPtr( new Renderer() );
+ RendererPtr rendererPtr( new Renderer() );
+ rendererPtr->Initialize();
+ return rendererPtr;
}
void Renderer::SetGeometry( Geometry& geometry )
{
mGeometryConnector.Set( geometry, OnStage() );
+ const SceneGraph::Geometry* geometrySceneObject = geometry.GetGeometrySceneObject();
+ SetGeometryMessage( Stage::GetCurrent()->GetUpdateInterface(), *mSceneObject, *geometrySceneObject );
}
void Renderer::SetMaterial( Material& material )
{
mMaterialConnector.Set( material, OnStage() );
+ const SceneGraph::Material* materialSceneObject = material.GetMaterialSceneObject();
+ SetMaterialMessage( Stage::GetCurrent()->GetUpdateInterface(), *mSceneObject, *materialSceneObject );
}
void Renderer::SetDepthIndex( int depthIndex )
DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
}
+SceneGraph::RendererAttachment* Renderer::GetRendererSceneObject()
+{
+ return mSceneObject;
+}
+
unsigned int Renderer::GetDefaultPropertyCount() const
{
return RENDERER_IMPL.GetDefaultPropertyCount();
bool Renderer::OnStage() const
{
// TODO: MESH_REWORK
- DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
- return false;
+ //DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
+ return mOnStage;
}
void Renderer::Connect()
// TODO: MESH_REWORK : check this
mGeometryConnector.OnStageConnect();
mMaterialConnector.OnStageConnect();
+ mOnStage = true;
}
void Renderer::Disconnect()
// TODO: MESH_REWORK : check this
mGeometryConnector.OnStageDisconnect();
mMaterialConnector.OnStageDisconnect();
+ mOnStage = false;
}
Renderer::Renderer()
-: mSceneObject(NULL)
+: mSceneObject(NULL),
+ mOnStage(false)
{
}
+void Renderer::Initialize()
+{
+ // Transfer object ownership of scene-object to message
+ mSceneObject = SceneGraph::RendererAttachment::New();
+
+ // Send message to update to connect to scene graph:
+ AttachToSceneGraphMessage( Stage::GetCurrent()->GetUpdateManager(), mSceneObject );
+}
+
+
} // namespace Internal
} // namespace Dali
*/
void SetDepthIndex( int depthIndex );
+ /**
+ * @brief Get the scene graph object ( the node attachment )
+ *
+ * @return the scene object
+ */
+ SceneGraph::RendererAttachment* GetRendererSceneObject();
+
public: // Default property extensions from Object
/**
private: // implementation
Renderer();
+ void Initialize();
+
private: // unimplemented methods
Renderer( const Renderer& );
Renderer& operator=( const Renderer& );
SceneGraph::RendererAttachment* 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
-
+ bool mOnStage;
};
} // namespace Internal
#include <dali/public-api/object/property-buffer.h> // Dali::Internal::PropertyBuffer
#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/stage-impl.h>
#include <dali/internal/update/common/scene-graph-property-buffer.h>
namespace Dali
return 0;
}
+const SceneGraph::PropertyBuffer* PropertyBuffer::GetPropertyBufferSceneObject() const
+{
+ return mSceneObject;
+}
+
unsigned int PropertyBuffer::GetDefaultPropertyCount() const
{
return PROPERTY_BUFFER_IMPL.GetDefaultPropertyCount();
*/
Dali::Property::Index GetPropertyIndex( const std::string name, std::size_t index );
+ /**
+ * @brief Get the propertyBuffer scene object
+ *
+ * @return the propertyBuffer scene object
+ */
+ const SceneGraph::PropertyBuffer* GetPropertyBufferSceneObject() const;
+
public: // Default property extensions from Object
/**
return Color::WHITE;
}
+const SceneGraph::Material* Material::GetMaterialSceneObject() const
+{
+ return mSceneObject;
+}
+
unsigned int Material::GetDefaultPropertyCount() const
{
return MATERIAL_IMPL.GetDefaultPropertyCount();
*/
const Vector4& GetBlendColor() const;
+ /**
+ * @brief Get the material scene object
+ *
+ * @return the material scene object
+ */
+ const SceneGraph::Material* GetMaterialSceneObject() const;
+
public: // Default property extensions from Object
/**
DALI_ASSERT_ALWAYS( false && "TODO: MESH_REWORK" );
}
+const SceneGraph::Sampler* Sampler::GetSamplerSceneObject() const
+{
+ return mSceneObject;
+}
+
unsigned int Sampler::GetDefaultPropertyCount() const
{
return SAMPLER_IMPL.GetDefaultPropertyCount();
*/
void SetAffectsTransparency( bool affectsTransparency );
+ /**
+ * @brief Get the sampler scene object
+ *
+ * @return the sampler scene object
+ */
+ const SceneGraph::Sampler* GetSamplerSceneObject() const;
+
public: // Default property extensions from Object
/**
return shader;
}
+const SceneGraph::Shader* Shader::GetShaderSceneObject() const
+{
+ return mSceneObject;
+}
+
unsigned int Shader::GetDefaultPropertyCount() const
{
return SHADER_IMPL.GetDefaultPropertyCount();
const std::string& fragmentShader,
Dali::Shader::ShaderHints hints );
+ /**
+ * @brief Get the shader scene object
+ *
+ * @return the shader scene object
+ */
+ const SceneGraph::Shader* GetShaderSceneObject() const;
+
public: // Default property extensions from Object
/**
return false;
}
+const SceneGraph::Geometry* Geometry::GetGeometrySceneObject() const
+{
+ return mSceneObject;
+}
+
unsigned int Geometry::GetDefaultPropertyCount() const
{
return GEOMETRY_IMPL.GetDefaultPropertyCount();
*/
bool GetRequiresDepthTesting() const;
+ /**
+ * @brief Get the geometry scene object
+ *
+ * @return the geometry scene object
+ */
+ const SceneGraph::Geometry* GetGeometrySceneObject() const;
+
public: // Default property extensions from Object
/**
namespace SceneGraph
{
class SamplerDataProvider;
+class Shader;
class MaterialDataProvider
}
/**
+ * Returns the shader
+ * @return The shader
+ */
+ virtual Shader* GetShader() const = 0;
+
+ /**
* Returns the list of samplers that this material provides
* @return The list of samplers
*/
{
case Dali::Geometry::TRIANGLES:
{
- context->DrawElements(GL_TRIANGLES, numIndices/3, GL_UNSIGNED_SHORT, 0);
+ context->DrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, 0);
break;
}
case Dali::Geometry::LINES:
{
- context->DrawElements(GL_LINES, numIndices/2, GL_UNSIGNED_SHORT, 0);
+ context->DrawElements(GL_LINES, numIndices, GL_UNSIGNED_SHORT, 0);
break;
}
case Dali::Geometry::POINTS:
const SamplerDataProvider& sampler );
-private:
+public:
+ // @todo MESH_REWORK Make private - add getters
//const NodeDataProvider& mNodeDataProvider;
//const ShaderDataProvider& mShaderDataProvider;
const MaterialDataProvider* mMaterialDataProvider;
const GeometryDataProvider* mGeometryDataProvider;
+private:
+
RenderGeometry mRenderGeometry;
struct TextureUnitUniformIndex
#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
{
{
DALI_ASSERT_DEBUG( mContext && "Renderer::Render. Renderer not initialised!! (mContext == NULL)." );
- // @todo
+ // @todo MESH_REWORK Fix when merging! :D
+ NewRenderer* renderer = dynamic_cast<NewRenderer*>(this);
+ if( renderer )
+ {
+ // Get the shader from the material:
+ mShader = renderer->mMaterialDataProvider->GetShader();
+ }
// if mShader is NULL it means we're set to default
if( !mShader )
PropertyBuffer* propertyBuffer = new PropertyBuffer();
propertyBuffer->mElementSize = sizeof(Vector4);
propertyBuffer->mData.Resize( propertyBuffer->mElementSize * 4 );
- Vector4* vertices = reinterpret_cast<Vector4*>(propertyBuffer->mData[0]);
+ Vector4* vertices = reinterpret_cast<Vector4*>(&propertyBuffer->mData[0]);
- vertices[ 0 ] = Vector4( -0.5f, -0.5f, 1.0f, 0.0f );
- vertices[ 1 ] = Vector4( 0.5f, -0.5f, 1.0f, 1.0f );
- vertices[ 2 ] = Vector4( -0.5f, 0.5f, 0.0f, 0.0f );
- vertices[ 3 ] = Vector4( 0.5f, 0.5f, 0.0f, 1.0f );
+ vertices[ 0 ] = Vector4( -0.5f, -0.5f, 0.0f, 0.0f );
+ vertices[ 1 ] = Vector4( 0.5f, -0.5f, 1.0f, 0.0f );
+ vertices[ 2 ] = Vector4( -0.5f, 0.5f, 0.0f, 1.0f );
+ vertices[ 3 ] = Vector4( 0.5f, 0.5f, 1.0f, 1.0f );
return propertyBuffer;
}
propertyBuffer->mElementSize = sizeof( unsigned short );
propertyBuffer->mData.Resize( propertyBuffer->mElementSize * 6 );
- unsigned short* indices = reinterpret_cast<unsigned short*>(propertyBuffer->mData[0]);
+ unsigned short* indices = reinterpret_cast<unsigned short*>(&propertyBuffer->mData[0]);
indices[0] = 0; indices[1] = 3; indices[2] = 1;
indices[3] = 0; indices[4] = 2; indices[5] = 3;
const void* PropertyBuffer::GetData( BufferIndex bufferIndex ) const
{
// @todo MESH_REWORK mData should be double buffered
- return reinterpret_cast< const void* >(mData[0]);
+ return reinterpret_cast< const void* >(&mData[0]);
}
// Need to inform renderer in render thread about this shader
}
-const Shader* Material::GetShader() const
+Shader* Material::GetShader() const
{
- return mShader;
+ // @todo - Fix this - move shader setup to the Renderer connect to stage... or summit
+ return const_cast<Shader*>(mShader);
}
void Material::AddSampler( const Sampler* sampler )
* Get the shader effect of this material
* @return the shader effect;
*/
- const Shader* GetShader() const;
+ virtual Shader* GetShader() const;
/**
* Add a sampler (image + sampler modes) to the material
// INTERNAL INCLUDES
#include <dali/internal/common/owner-container.h>
#include <dali/internal/update/common/discard-queue.h>
+#include <dali/internal/update/controllers/scene-controller.h>
namespace Dali
{
* @param[in] discardQueue Queue to discard objects that might still be in use in the render thread.
**/
ObjectOwnerContainer( SceneGraphBuffers& sceneGraphBuffers, DiscardQueue& discardQueue )
- : mSceneGraphBuffers( sceneGraphBuffers ),
+ : mSceneController( NULL ),
+ mSceneGraphBuffers( sceneGraphBuffers ),
mDiscardQueue( discardQueue )
{
}
/**
+ * @brief Set the SceneController on this owner
+ *
+ * @param[in] sceneController The SceneController
+ **/
+ void SetSceneController( SceneController& sceneController )
+ {
+ mSceneController = &sceneController;
+ }
+
+ /**
* @brief Add an object to the owner
*
* @param[in] object Pointer to the object that will be owned
DALI_ASSERT_DEBUG( pointer && "Pointer should not be null" );
mObjectContainer.PushBack( pointer );
+
+ // @todo MESH_REWORK FIX ME NOW!
+ //pointer->ConnectToSceneGraph(*mSceneController, mSceneGraphBuffers.GetUpdateBufferIndex() );
}
/**
DALI_ASSERT_DEBUG( match != mObjectContainer.End() && "Should always find a match" );
mDiscardQueue.Add( mSceneGraphBuffers.GetUpdateBufferIndex(), mObjectContainer.Release( match ) );
+ pointer->DisconnectFromSceneGraph(*mSceneController, mSceneGraphBuffers.GetUpdateBufferIndex() );
}
/**
}
private:
+ SceneController* mSceneController; ///< SceneControler 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/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/nodes/node.h>
#include <dali/internal/update/nodes/scene-graph-layer.h>
#include <dali/internal/update/queue/update-message-queue.h>
systemLevelTaskList ( completeStatusManager ),
root( NULL ),
systemLevelRoot( NULL ),
- geometries( sceneGraphBuffers, discardQueue ),
+ geometries( sceneGraphBuffers, discardQueue ),
materials( sceneGraphBuffers, discardQueue ),
samplers( sceneGraphBuffers, discardQueue ),
propertyBuffers( sceneGraphBuffers, discardQueue ),
renderTaskWaiting( false )
{
sceneController = new SceneControllerImpl( renderMessageDispatcher, renderQueue, discardQueue, textureCache, completeStatusManager );
+
+ geometries.SetSceneController( *sceneController );
+ materials.SetSceneController( *sceneController );
+ propertyBuffers.SetSceneController( *sceneController );
+ samplers.SetSceneController( *sceneController );
}
~Impl()
node->OnDestroy();
}
+//@todo MESH_REWORK Extend to allow arbitrary scene objects to connect to each other
void UpdateManager::AttachToNode( Node* node, NodeAttachment* attachment )
{
DALI_ASSERT_DEBUG( node != NULL );
attachment->ConnectToSceneGraph( *mImpl->sceneController, mSceneGraphBuffers.GetUpdateBufferIndex() );
}
+void UpdateManager::AttachToSceneGraph( RendererAttachment* renderer )
+{
+ renderer->AttachToSceneGraph( *(mImpl->sceneController), mSceneGraphBuffers.GetUpdateBufferIndex() );
+}
+
void UpdateManager::AddObject( PropertyOwner* object )
{
DALI_ASSERT_DEBUG( NULL != object );
#include <dali/internal/render/shaders/scene-graph-shader.h>
-
namespace Dali
{
class PropertyBuffer;
class Material;
class Sampler;
+class RendererAttachment;
/**
* UpdateManager holds a scene graph i.e. a tree of nodes.
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.
new (slot) LocalType( &manager, &UpdateManager::AttachToNode, &parent, attachment );
}
+inline void AttachToSceneGraphMessage( UpdateManager& manager, RendererAttachment* renderer )
+{
+ typedef MessageValue1< UpdateManager, RendererAttachment* > LocalType;
+
+ // Reserve some memory inside the message queue
+ unsigned int* slot = manager.GetEventToUpdate().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;
}
RenderableAttachment::RenderableAttachment( bool usesGeometryScaling )
-: mSceneController(NULL),
+: mSceneController(NULL), //@todo MESH_REWORK Pass in where required rather than store
mShader( NULL ),
mTrackedResources(),
mSortModifier( 0.0f ),
#include <dali/internal/render/queue/render-queue.h>
#include <dali/internal/render/renderers/render-renderer.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)
+
+#else
+
+#define ATTACHMENT_LOG(level)
+#define ATTACHMENT_LOG_FMT(level, format, args...)
+
+#endif
+
+
namespace Dali
{
namespace Internal
mMaterial = material;
// Tell renderer about a new provider
+ if( mRenderer )
{
typedef MessageValue1< NewRenderer, const MaterialDataProvider*> DerivedType;
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
mGeometry = geometry;
// Tell renderer about a new provider
+ if( mRenderer )
{
typedef MessageValue1< NewRenderer, const GeometryDataProvider*> DerivedType;
unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) );
opaque = mParent->GetWorldColor( updateBufferIndex ).a >= FULLY_OPAQUE;
}
- // Require that all affecting samplers are opaque
- unsigned int opaqueCount=0;
- unsigned int affectingCount=0;
- const Material::Samplers& samplers = mMaterial->GetSamplers();
- for( Material::Samplers::ConstIterator iter = samplers.Begin();
- iter != samplers.End(); ++iter )
+ if( mMaterial != NULL )
{
- const Sampler* sampler = static_cast<const Sampler*>(*iter);
- if( sampler->AffectsTransparency( updateBufferIndex ) )
+ // Require that all affecting samplers are opaque
+ unsigned int opaqueCount=0;
+ unsigned int affectingCount=0;
+
+ const Material::Samplers& samplers = mMaterial->GetSamplers();
+ for( Material::Samplers::ConstIterator iter = samplers.Begin();
+ iter != samplers.End(); ++iter )
{
- affectingCount++;
- if( sampler->IsFullyOpaque( updateBufferIndex ) )
+ const Sampler* sampler = static_cast<const Sampler*>(*iter);
+ if( sampler != NULL )
{
- opaqueCount++;
+ if( sampler->AffectsTransparency( updateBufferIndex ) )
+ {
+ affectingCount++;
+ if( sampler->IsFullyOpaque( updateBufferIndex ) )
+ {
+ opaqueCount++;
+ }
+ }
}
}
+ opaque = (opaqueCount == affectingCount);
}
- opaque = (opaqueCount == affectingCount);
return opaque;
}
// Do nothing.
}
+void RendererAttachment::AttachToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex )
+{
+ mSceneController = &sceneController;
+}
+
void RendererAttachment::ConnectToSceneGraph2( BufferIndex updateBufferIndex )
{
DALI_ASSERT_DEBUG( mSceneController );
*/
int GetDepthIndex() const ;
+ /**
+ * Initial setup on attaching to the scene graph
+ */
+ void AttachToSceneGraph( SceneController& sceneController, BufferIndex updateBufferIndex );
+
protected: // From RenderableAttachment
/**
* @copydoc RenderableAttachment::GetRenderer().
*/
virtual void SizeChanged( BufferIndex updateBufferIndex );
- /**
+/**
* @copydoc RenderableAttachment::ConnectToSceneGraph2().
*/
virtual void ConnectToSceneGraph2( BufferIndex updateBufferIndex );