Browse Source

Remove custom material from Drawable2D, Renderer2D will get all Drawable2D when HandleBeginViewUpdate.

aster2013 11 years ago
parent
commit
511d6f461f

+ 0 - 2
Source/Engine/Script/Urho2DAPI.cpp

@@ -99,8 +99,6 @@ template <class T> void RegisterDrawable2D(asIScriptEngine* engine, const char*
     engine->RegisterObjectMethod(className, "Texture2D@+ get_texture() const", asMETHOD(T, GetTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "Texture2D@+ get_texture() const", asMETHOD(T, GetTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_blendMode(BlendMode)", asMETHOD(T, SetBlendMode), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_blendMode(BlendMode)", asMETHOD(T, SetBlendMode), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "BlendMode get_blendMode() const", asMETHOD(T, GetBlendMode), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "BlendMode get_blendMode() const", asMETHOD(T, GetBlendMode), asCALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void set_material(Material@+)", asMETHOD(T, SetMaterial), asCALL_THISCALL);
-    engine->RegisterObjectMethod(className, "Material@+ get_material() const", asMETHOD(T, GetMaterial), asCALL_THISCALL);
 }
 }
 
 
 static void RegisterDrawable2D(asIScriptEngine* engine)
 static void RegisterDrawable2D(asIScriptEngine* engine)

+ 8 - 79
Source/Engine/Urho2D/Drawable2D.cpp

@@ -58,8 +58,6 @@ Drawable2D::Drawable2D(Context* context) :
 
 
 Drawable2D::~Drawable2D()
 Drawable2D::~Drawable2D()
 {
 {
-    if (renderer_)
-        renderer_->RemoveDrawable(this);
 }
 }
 
 
 void Drawable2D::RegisterObject(Context* context)
 void Drawable2D::RegisterObject(Context* context)
@@ -67,30 +65,9 @@ void Drawable2D::RegisterObject(Context* context)
     ACCESSOR_ATTRIBUTE("Layer", GetLayer, SetLayer, int, 0, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Layer", GetLayer, SetLayer, int, 0, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Order in Layer", GetOrderInLayer, SetOrderInLayer, int, 0, AM_DEFAULT);
     ACCESSOR_ATTRIBUTE("Order in Layer", GetOrderInLayer, SetOrderInLayer, int, 0, AM_DEFAULT);
     ENUM_ACCESSOR_ATTRIBUTE("Blend Mode", GetBlendMode, SetBlendModeAttr, BlendMode, blendModeNames, BLEND_ALPHA, AM_DEFAULT);
     ENUM_ACCESSOR_ATTRIBUTE("Blend Mode", GetBlendMode, SetBlendModeAttr, BlendMode, blendModeNames, BLEND_ALPHA, AM_DEFAULT);
-    MIXED_ACCESSOR_ATTRIBUTE("Material", GetMaterialAttr, SetMaterialAttr, ResourceRef, ResourceRef(Material::GetTypeStatic()), AM_DEFAULT);
     COPY_BASE_ATTRIBUTES(Drawable);
     COPY_BASE_ATTRIBUTES(Drawable);
 }
 }
 
 
-void Drawable2D::ApplyAttributes()
-{
-    if (materialUpdatePending_)
-    {
-        materialUpdatePending_ = false;
-        UpdateDefaultMaterial();
-    }
-}
-
-void Drawable2D::OnSetEnabled()
-{
-    if (!renderer_)
-        return;
-
-    if (IsEnabledEffective())
-        renderer_->AddDrawable(this);
-    else
-        renderer_->RemoveDrawable(this);
-}
-
 void Drawable2D::SetLayer(int layer)
 void Drawable2D::SetLayer(int layer)
 {
 {
     if (layer == layer_)
     if (layer == layer_)
@@ -98,9 +75,6 @@ void Drawable2D::SetLayer(int layer)
 
 
     layer_ = layer;
     layer_ = layer;
 
 
-    if (renderer_)
-        renderer_->MarkOrderDirty();
-
     MarkNetworkUpdate();
     MarkNetworkUpdate();
 }
 }
 
 
@@ -111,9 +85,6 @@ void Drawable2D::SetOrderInLayer(int orderInLayer)
 
 
     orderInLayer_ = orderInLayer;
     orderInLayer_ = orderInLayer;
 
 
-    if (renderer_)
-        renderer_->MarkOrderDirty();
-
     MarkNetworkUpdate();
     MarkNetworkUpdate();
 }
 }
 
 
@@ -125,8 +96,9 @@ void Drawable2D::SetTexture(Texture2D* texture)
     texture_ = texture;
     texture_ = texture;
 
 
     verticesDirty_ = true;
     verticesDirty_ = true;
+    defaultMaterial_ = 0;
+    
     OnMarkedDirty(node_);
     OnMarkedDirty(node_);
-    UpdateDefaultMaterial();
     MarkNetworkUpdate();
     MarkNetworkUpdate();
 }
 }
 
 
@@ -136,20 +108,7 @@ void Drawable2D::SetBlendMode(BlendMode blendMode)
         return;
         return;
 
 
     blendMode_ = blendMode;
     blendMode_ = blendMode;
-
-    UpdateDefaultMaterial();
-    MarkNetworkUpdate();
-}
-
-void Drawable2D::SetMaterial(Material* material)
-{
-    if (material == material_)
-        return;
-
-    material_ = material;
-
-    if (renderer_)
-        renderer_->MarkOrderDirty();
+    defaultMaterial_ = 0;
 
 
     MarkNetworkUpdate();
     MarkNetworkUpdate();
 }
 }
@@ -159,14 +118,14 @@ Texture2D* Drawable2D::GetTexture() const
     return texture_;
     return texture_;
 }
 }
 
 
-Material* Drawable2D::GetMaterial() const
+void Drawable2D::SetDefaultMaterial(Material* material)
 {
 {
-    return material_;
+    defaultMaterial_ = material;
 }
 }
 
 
-Material* Drawable2D::GetUsedMaterial() const
+Material* Drawable2D::GetDefaultMaterial() const
 {
 {
-    return material_ ? material_ : defaultMaterial_;
+    return defaultMaterial_;
 }
 }
 
 
 const Vector<Vertex2D>& Drawable2D::GetVertices()
 const Vector<Vertex2D>& Drawable2D::GetVertices()
@@ -184,20 +143,6 @@ void Drawable2D::SetBlendModeAttr(BlendMode mode)
     SetBlendMode(mode);
     SetBlendMode(mode);
 }
 }
 
 
-void Drawable2D::SetMaterialAttr(const ResourceRef& value)
-{
-    // Delay applying material update
-    materialUpdatePending_ = true;
-
-    ResourceCache* cache = GetSubsystem<ResourceCache>();
-    SetMaterial(cache->GetResource<Material>(value.name_));
-}
-
-ResourceRef Drawable2D::GetMaterialAttr() const
-{
-    return GetResourceRef(material_, Material::GetTypeStatic());
-}
-
 void Drawable2D::OnNodeSet(Node* node)
 void Drawable2D::OnNodeSet(Node* node)
 {
 {
     Drawable::OnNodeSet(node);
     Drawable::OnNodeSet(node);
@@ -206,11 +151,7 @@ void Drawable2D::OnNodeSet(Node* node)
     {
     {
         Scene* scene = GetScene();
         Scene* scene = GetScene();
         if (scene)
         if (scene)
-        {
-            renderer_ = scene->GetOrCreateComponent<Renderer2D>();
-            if (IsEnabledEffective())
-                renderer_->AddDrawable(this);
-        }
+            scene->GetOrCreateComponent<Renderer2D>();
     }
     }
 }
 }
 
 
@@ -221,16 +162,4 @@ void Drawable2D::OnMarkedDirty(Node* node)
     verticesDirty_ = true;
     verticesDirty_ = true;
 }
 }
 
 
-void Drawable2D::UpdateDefaultMaterial()
-{
-    // Delay the material update
-    if (materialUpdatePending_)
-        return;
-
-    defaultMaterial_ = renderer_->GetMaterial(GetTexture(), blendMode_);
-
-    if (renderer_)
-        renderer_->MarkOrderDirty();
-}
-
 }
 }

+ 8 - 25
Source/Engine/Urho2D/Drawable2D.h

@@ -61,11 +61,6 @@ public:
     /// Register object factory. Drawable must be registered first.
     /// Register object factory. Drawable must be registered first.
     static void RegisterObject(Context* context);
     static void RegisterObject(Context* context);
 
 
-    /// Apply attribute changes that can not be applied immediately.
-    virtual void ApplyAttributes();
-    /// Handle enabled/disabled state change.
-    virtual void OnSetEnabled();
-
     /// Set layer.
     /// Set layer.
     void SetLayer(int layer);
     void SetLayer(int layer);
     /// Set order in layer.
     /// Set order in layer.
@@ -74,9 +69,7 @@ public:
     void SetTexture(Texture2D* texture);
     void SetTexture(Texture2D* texture);
     /// Set blend mode.
     /// Set blend mode.
     void SetBlendMode(BlendMode mode);
     void SetBlendMode(BlendMode mode);
-    /// Set material.
-    void SetMaterial(Material* material);
-
+    
     /// Return layer.
     /// Return layer.
     int GetLayer() const { return layer_; }
     int GetLayer() const { return layer_; }
     /// Return order in layer.
     /// Return order in layer.
@@ -85,24 +78,20 @@ public:
     Texture2D* GetTexture() const;
     Texture2D* GetTexture() const;
     /// Return blend mode.
     /// Return blend mode.
     BlendMode GetBlendMode() const { return blendMode_; }
     BlendMode GetBlendMode() const { return blendMode_; }
-    /// Return material.
-    Material* GetMaterial() const;
 
 
-    /// Return used material.
-    Material* GetUsedMaterial() const;
-    /// Return all vertices.
-    const Vector<Vertex2D>& GetVertices();
+    /// Set default material.
+    void SetDefaultMaterial(Material* material);
+    /// Return default material.
+    Material* GetDefaultMaterial() const;
     /// Set visibility.
     /// Set visibility.
     void SetVisibility(bool visibility) { visibility_ = visibility; }
     void SetVisibility(bool visibility) { visibility_ = visibility; }
     /// Return visibility.
     /// Return visibility.
     bool GetVisibility() const { return visibility_; }
     bool GetVisibility() const { return visibility_; }
+    /// Return all vertices.
+    const Vector<Vertex2D>& GetVertices();
 
 
     /// Set blend mode attribute.
     /// Set blend mode attribute.
     void SetBlendModeAttr(BlendMode mode);
     void SetBlendModeAttr(BlendMode mode);
-    /// Set material attribute.
-    void SetMaterialAttr(const ResourceRef& value);
-    /// Return material attribute.
-    ResourceRef GetMaterialAttr() const;
 
 
 protected:
 protected:
     /// Handle node being assigned.
     /// Handle node being assigned.
@@ -111,17 +100,13 @@ protected:
     virtual void OnMarkedDirty(Node* node);
     virtual void OnMarkedDirty(Node* node);
     /// Update vertices.
     /// Update vertices.
     virtual void UpdateVertices() = 0;
     virtual void UpdateVertices() = 0;
-    /// Update the material's properties (blend mode and texture).
-    void UpdateDefaultMaterial();
-
+    
     /// Layer.
     /// Layer.
     int layer_;
     int layer_;
     /// Order in layer.
     /// Order in layer.
     int orderInLayer_;
     int orderInLayer_;
     /// Texture.
     /// Texture.
     SharedPtr<Texture2D> texture_;
     SharedPtr<Texture2D> texture_;
-    /// Material. If null, use a default material. If non-null, use a clone of this for updating the diffuse texture.
-    SharedPtr<Material> material_;
     /// Blend mode.
     /// Blend mode.
     BlendMode blendMode_;
     BlendMode blendMode_;
 
 
@@ -133,8 +118,6 @@ protected:
     bool materialUpdatePending_;
     bool materialUpdatePending_;
     /// Default material.
     /// Default material.
     SharedPtr<Material> defaultMaterial_;
     SharedPtr<Material> defaultMaterial_;
-    /// 2D rendererer.
-    WeakPtr<Renderer2D> renderer_;
     /// Test visible.
     /// Test visible.
     bool visibility_;
     bool visibility_;
 };
 };

+ 56 - 52
Source/Engine/Urho2D/Renderer2D.cpp

@@ -50,7 +50,6 @@ Renderer2D::Renderer2D(Context* context) :
     Drawable(context, DRAWABLE_PROXYGEOMETRY),
     Drawable(context, DRAWABLE_PROXYGEOMETRY),
     indexBuffer_(new IndexBuffer(context_)),
     indexBuffer_(new IndexBuffer(context_)),
     vertexBuffer_(new VertexBuffer(context_)),
     vertexBuffer_(new VertexBuffer(context_)),
-    orderDirty_(true),
     frustum_(0),
     frustum_(0),
     indexCount_(0),
     indexCount_(0),
     vertexCount_(0)
     vertexCount_(0)
@@ -161,27 +160,6 @@ UpdateGeometryType Renderer2D::GetUpdateGeometryType()
     return UPDATE_MAIN_THREAD;
     return UPDATE_MAIN_THREAD;
 }
 }
 
 
-void Renderer2D::AddDrawable(Drawable2D* drawable)
-{
-    if (!drawable)
-        return;
-
-    if (drawables_.Contains(drawable))
-        return;
-
-    drawables_.Push(drawable);
-    orderDirty_ = true;
-}
-
-void Renderer2D::RemoveDrawable(Drawable2D* drawable)
-{
-    if (!drawable)
-        return;
-
-    drawables_.Remove(drawable);
-    orderDirty_ = true;
-}
-
 bool Renderer2D::CheckVisibility(Drawable2D* drawable) const
 bool Renderer2D::CheckVisibility(Drawable2D* drawable) const
 {
 {
     const BoundingBox& box = drawable->GetWorldBoundingBox();
     const BoundingBox& box = drawable->GetWorldBoundingBox();
@@ -191,27 +169,6 @@ bool Renderer2D::CheckVisibility(Drawable2D* drawable) const
     return frustumBoundingBox_.IsInsideFast(box) != OUTSIDE;
     return frustumBoundingBox_.IsInsideFast(box) != OUTSIDE;
 }
 }
 
 
-Material* Renderer2D::GetMaterial(Texture2D* texture, BlendMode blendMode)
-{
-    HashMap<Texture2D*, HashMap<int, SharedPtr<Material> > >::Iterator t = cachedMaterials_.Find(texture);
-    if (t == cachedMaterials_.End())
-    {
-        SharedPtr<Material> material(CreateMaterial(texture, blendMode));
-        cachedMaterials_[texture][blendMode] = material;
-        return material;
-    }
-
-    HashMap<int, SharedPtr<Material> >& materials = t->second_;
-    HashMap<int, SharedPtr<Material> >::Iterator b = materials.Find(blendMode);
-    if (b != materials.End())
-        return b->second_;
-
-    SharedPtr<Material> material(CreateMaterial(texture, blendMode));
-    materials[blendMode] = material;
-
-    return material;
-}
-
 void Renderer2D::OnWorldBoundingBoxUpdate()
 void Renderer2D::OnWorldBoundingBoxUpdate()
 {
 {
     // Set a large dummy bounding box to ensure the renderer is rendered
     // Set a large dummy bounding box to ensure the renderer is rendered
@@ -219,7 +176,7 @@ void Renderer2D::OnWorldBoundingBoxUpdate()
     worldBoundingBox_ = boundingBox_;
     worldBoundingBox_ = boundingBox_;
 }
 }
 
 
-void CheckDrawableVisibility(const WorkItem* item, unsigned threadIndex)
+static void CheckDrawableVisibility(const WorkItem* item, unsigned threadIndex)
 {
 {
     Renderer2D* renderer = reinterpret_cast<Renderer2D*>(item->aux_);
     Renderer2D* renderer = reinterpret_cast<Renderer2D*>(item->aux_);
     Drawable2D** start = reinterpret_cast<Drawable2D**>(item->start_);
     Drawable2D** start = reinterpret_cast<Drawable2D**>(item->start_);
@@ -228,7 +185,7 @@ void CheckDrawableVisibility(const WorkItem* item, unsigned threadIndex)
     while (start != end)
     while (start != end)
     {
     {
         Drawable2D* drawable = *start++;
         Drawable2D* drawable = *start++;
-        if (renderer->CheckVisibility(drawable) && drawable->GetUsedMaterial() && drawable->GetVertices().Size())
+        if (renderer->CheckVisibility(drawable) && drawable->GetDefaultMaterial() && drawable->GetVertices().Size())
             drawable->SetVisibility(true);
             drawable->SetVisibility(true);
         else
         else
             drawable->SetVisibility(false);
             drawable->SetVisibility(false);
@@ -243,8 +200,8 @@ static inline bool CompareDrawable2Ds(Drawable2D* lhs, Drawable2D* rhs)
     if (lhs->GetOrderInLayer() != rhs->GetOrderInLayer())
     if (lhs->GetOrderInLayer() != rhs->GetOrderInLayer())
         return lhs->GetOrderInLayer() < rhs->GetOrderInLayer();
         return lhs->GetOrderInLayer() < rhs->GetOrderInLayer();
 
 
-    Material* lhsUsedMaterial = lhs->GetUsedMaterial();
-    Material* rhsUsedMaterial = rhs->GetUsedMaterial();
+    Material* lhsUsedMaterial = lhs->GetDefaultMaterial();
+    Material* rhsUsedMaterial = rhs->GetDefaultMaterial();
     if (lhsUsedMaterial != rhsUsedMaterial)
     if (lhsUsedMaterial != rhsUsedMaterial)
         return lhsUsedMaterial->GetNameHash() < rhsUsedMaterial->GetNameHash();
         return lhsUsedMaterial->GetNameHash() < rhsUsedMaterial->GetNameHash();
 
 
@@ -255,18 +212,26 @@ void Renderer2D::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventDa
 {
 {
     using namespace BeginViewUpdate;
     using namespace BeginViewUpdate;
 
 
+    Scene* scene = GetScene();
     // Check that we are updating the correct scene
     // Check that we are updating the correct scene
-    if (GetScene() != eventData[P_SCENE].GetPtr())
+    if (scene != eventData[P_SCENE].GetPtr())
         return;
         return;
 
 
     PROFILE(UpdateRenderer2D);
     PROFILE(UpdateRenderer2D);
 
 
-    if (orderDirty_)
+    drawables_.Clear();
+    GetDrawables(drawables_, scene);
+
+    // Set default material for Drawable2D.
+    for (unsigned i = 0; i < drawables_.Size(); ++i)
     {
     {
-        Sort(drawables_.Begin(), drawables_.End(), CompareDrawable2Ds);
-        orderDirty_ = false;
+        Drawable2D* drawable = drawables_[i];
+        if (!drawable->GetDefaultMaterial())
+            drawable->SetDefaultMaterial(CreateMaterial(drawable->GetTexture(), drawable->GetBlendMode()));
     }
     }
 
 
+    Sort(drawables_.Begin(), drawables_.End(), CompareDrawable2Ds);
+    
     Camera* camera = static_cast<Camera*>(eventData[P_CAMERA].GetPtr());
     Camera* camera = static_cast<Camera*>(eventData[P_CAMERA].GetPtr());
     frustum_ = &camera->GetFrustum();
     frustum_ = &camera->GetFrustum();
     if (camera->IsOrthographic() && camera->GetNode()->GetWorldDirection() == Vector3::FORWARD)
     if (camera->IsOrthographic() && camera->GetNode()->GetWorldDirection() == Vector3::FORWARD)
@@ -327,7 +292,7 @@ void Renderer2D::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventDa
         if (!drawables_[d]->GetVisibility())
         if (!drawables_[d]->GetVisibility())
             continue;
             continue;
 
 
-        Material* usedMaterial = drawables_[d]->GetUsedMaterial();
+        Material* usedMaterial = drawables_[d]->GetDefaultMaterial();
         const Vector<Vertex2D>& vertices = drawables_[d]->GetVertices();
         const Vector<Vertex2D>& vertices = drawables_[d]->GetVertices();
 
 
         if (material != usedMaterial)
         if (material != usedMaterial)
@@ -363,6 +328,24 @@ void Renderer2D::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventDa
     }
     }
 }
 }
 
 
+void Renderer2D::GetDrawables(PODVector<Drawable2D*>& dest, Node* node)
+{
+    if (!node)
+        return;
+
+    const Vector<SharedPtr<Component> >& components = node->GetComponents();
+    for (Vector<SharedPtr<Component> >::ConstIterator i = components.Begin(); i != components.End(); ++i)
+    {
+        Drawable2D* drawable = dynamic_cast<Drawable2D*>(i->Get());
+        if (drawable)
+            dest.Push(drawable);
+    }
+
+    const Vector<SharedPtr<Node> >& children = node->GetChildren();
+    for (Vector<SharedPtr<Node> >::ConstIterator i = children.Begin(); i != children.End(); ++i)
+        GetDrawables(dest, i->Get());
+}
+
 void Renderer2D::AddBatch(Material* material, unsigned indexStart, unsigned indexCount, unsigned vertexStart, unsigned vertexCount)
 void Renderer2D::AddBatch(Material* material, unsigned indexStart, unsigned indexCount, unsigned vertexStart, unsigned vertexCount)
 {
 {
     if (!material || indexCount == 0 || vertexCount == 0)
     if (!material || indexCount == 0 || vertexCount == 0)
@@ -382,6 +365,27 @@ void Renderer2D::AddBatch(Material* material, unsigned indexStart, unsigned inde
     geometries_[batchSize - 1]->SetDrawRange(TRIANGLE_LIST, indexStart, indexCount, vertexStart, vertexCount, false);
     geometries_[batchSize - 1]->SetDrawRange(TRIANGLE_LIST, indexStart, indexCount, vertexStart, vertexCount, false);
 }
 }
 
 
+Material* Renderer2D::GetMaterial(Texture2D* texture, BlendMode blendMode)
+{
+    HashMap<Texture2D*, HashMap<int, SharedPtr<Material> > >::Iterator t = cachedMaterials_.Find(texture);
+    if (t == cachedMaterials_.End())
+    {
+        SharedPtr<Material> material(CreateMaterial(texture, blendMode));
+        cachedMaterials_[texture][blendMode] = material;
+        return material;
+    }
+
+    HashMap<int, SharedPtr<Material> >& materials = t->second_;
+    HashMap<int, SharedPtr<Material> >::Iterator b = materials.Find(blendMode);
+    if (b != materials.End())
+        return b->second_;
+
+    SharedPtr<Material> material(CreateMaterial(texture, blendMode));
+    materials[blendMode] = material;
+
+    return material;
+}
+
 Material* Renderer2D::CreateMaterial(Texture2D* texture, BlendMode blendMode)
 Material* Renderer2D::CreateMaterial(Texture2D* texture, BlendMode blendMode)
 {
 {
     Material* material = new Material(context_);
     Material* material = new Material(context_);

+ 7 - 13
Source/Engine/Urho2D/Renderer2D.h

@@ -52,24 +52,20 @@ public:
     /// Return whether a geometry update is necessary, and if it can happen in a worker thread.
     /// Return whether a geometry update is necessary, and if it can happen in a worker thread.
     virtual UpdateGeometryType GetUpdateGeometryType();
     virtual UpdateGeometryType GetUpdateGeometryType();
 
 
-    /// Add drawable.
-    void AddDrawable(Drawable2D* drawable);
-    /// Remove drawable.
-    void RemoveDrawable(Drawable2D* drawable);
-    /// Mark order dirty.
-    void MarkOrderDirty() { orderDirty_ = true; }
     /// Check visibility.
     /// Check visibility.
     bool CheckVisibility(Drawable2D* drawable) const;
     bool CheckVisibility(Drawable2D* drawable) const;
-    /// Return material by texture and blend mode.
-    Material* GetMaterial(Texture2D* texture, BlendMode blendMode);
 
 
 private:
 private:
     /// Recalculate the world-space bounding box.
     /// Recalculate the world-space bounding box.
     virtual void OnWorldBoundingBoxUpdate();
     virtual void OnWorldBoundingBoxUpdate();
     /// Handle view update begin event. Determine Drawable2D's and their batches here.
     /// Handle view update begin event. Determine Drawable2D's and their batches here.
     void HandleBeginViewUpdate(StringHash eventType, VariantMap& eventData);
     void HandleBeginViewUpdate(StringHash eventType, VariantMap& eventData);
+    /// Get all drawables in node.
+    void GetDrawables(PODVector<Drawable2D*>& drawables, Node* node);
     /// Add batch.
     /// Add batch.
     void AddBatch(Material* material, unsigned indexStart, unsigned indexCount, unsigned vertexStart, unsigned vertexCount);
     void AddBatch(Material* material, unsigned indexStart, unsigned indexCount, unsigned vertexStart, unsigned vertexCount);
+    /// Return material by texture and blend mode.
+    Material* GetMaterial(Texture2D* texture, BlendMode blendMode);
     /// Create material by texture and blend mode.
     /// Create material by texture and blend mode.
     Material* CreateMaterial(Texture2D* Texture, BlendMode blendMode);
     Material* CreateMaterial(Texture2D* Texture, BlendMode blendMode);
 
 
@@ -77,14 +73,12 @@ private:
     SharedPtr<IndexBuffer> indexBuffer_;
     SharedPtr<IndexBuffer> indexBuffer_;
     /// Vertex buffer.
     /// Vertex buffer.
     SharedPtr<VertexBuffer> vertexBuffer_;
     SharedPtr<VertexBuffer> vertexBuffer_;
+    /// Drawables.
+    PODVector<Drawable2D*> drawables_;
     /// Materials.
     /// Materials.
     Vector<SharedPtr<Material> > materials_;
     Vector<SharedPtr<Material> > materials_;
     /// Geometries.
     /// Geometries.
     Vector<SharedPtr<Geometry> > geometries_;
     Vector<SharedPtr<Geometry> > geometries_;
-    /// Drawables.
-    PODVector<Drawable2D*> drawables_;
-    /// Order dirty.
-    bool orderDirty_;
     /// Frustum for current frame.
     /// Frustum for current frame.
     const Frustum* frustum_;
     const Frustum* frustum_;
     /// Frustum bounding box for current frame.
     /// Frustum bounding box for current frame.
@@ -93,7 +87,7 @@ private:
     unsigned indexCount_;
     unsigned indexCount_;
     /// Total vertex count for the current frame.
     /// Total vertex count for the current frame.
     unsigned vertexCount_;
     unsigned vertexCount_;
-    /// Materials.
+    /// Cached materials.
     HashMap<Texture2D*, HashMap<int, SharedPtr<Material> > > cachedMaterials_;
     HashMap<Texture2D*, HashMap<int, SharedPtr<Material> > > cachedMaterials_;
 };
 };