Browse Source

Removed GetVisibility / SetVisibility from Drawable2D. Instead they are marked for view similarly as other drawables. Fixes #636.

Lasse Öörni 11 years ago
parent
commit
988d77f06c

+ 4 - 0
Source/Urho3D/Graphics/GraphicsEvents.h

@@ -67,6 +67,7 @@ EVENT(E_ENDRENDERING, EndRendering)
 /// Update of a view started.
 EVENT(E_BEGINVIEWUPDATE, BeginViewUpdate)
 {
+    PARAM(P_VIEW, View);                    // View pointer
     PARAM(P_TEXTURE, Texture);              // Texture pointer
     PARAM(P_SURFACE, Surface);              // RenderSurface pointer
     PARAM(P_SCENE, Scene);                  // Scene pointer
@@ -76,6 +77,7 @@ EVENT(E_BEGINVIEWUPDATE, BeginViewUpdate)
 /// Update of a view ended.
 EVENT(E_ENDVIEWUPDATE, EndViewUpdate)
 {
+    PARAM(P_VIEW, View);                    // View pointer
     PARAM(P_TEXTURE, Texture);              // Texture pointer
     PARAM(P_SURFACE, Surface);              // RenderSurface pointer
     PARAM(P_SCENE, Scene);                  // Scene pointer
@@ -85,6 +87,7 @@ EVENT(E_ENDVIEWUPDATE, EndViewUpdate)
 /// Render of a view started.
 EVENT(E_BEGINVIEWRENDER, BeginViewRender)
 {
+    PARAM(P_VIEW, View);                    // View pointer
     PARAM(P_TEXTURE, Texture);              // Texture pointer
     PARAM(P_SURFACE, Surface);              // RenderSurface pointer
     PARAM(P_SCENE, Scene);                  // Scene pointer
@@ -94,6 +97,7 @@ EVENT(E_BEGINVIEWRENDER, BeginViewRender)
 /// Render of a view ended.
 EVENT(E_ENDVIEWRENDER, EndViewRender)
 {
+    PARAM(P_VIEW, View);                    // View pointer
     PARAM(P_TEXTURE, Texture);              // Texture pointer
     PARAM(P_SURFACE, Surface);              // RenderSurface pointer
     PARAM(P_SCENE, Scene);                  // Scene pointer

+ 2 - 12
Source/Urho3D/Graphics/Renderer.cpp

@@ -632,20 +632,9 @@ void Renderer::Update(float timeStep)
                 debug->SetView(viewport->GetCamera());
         }
         
-        // Update view. This may queue further views
-        using namespace BeginViewUpdate;
-        
-        VariantMap& eventData = GetEventDataMap();
-        eventData[P_SURFACE] = renderTarget.Get();
-        eventData[P_TEXTURE] = (renderTarget ? renderTarget->GetParentTexture() : 0);
-        eventData[P_SCENE] = scene;
-        eventData[P_CAMERA] = viewport->GetCamera();
-        SendEvent(E_BEGINVIEWUPDATE, eventData);
-        
+        // Update view. This may queue further views. View will send update begin/end events once its state is set
         ResetShadowMapAllocations(); // Each view can reuse the same shadow maps
         view->Update(frame_);
-        
-        SendEvent(E_ENDVIEWUPDATE, eventData);
     }
     
     // Reset update flag from queued render surfaces. At this point no new views can be added on this frame
@@ -702,6 +691,7 @@ void Renderer::Render()
             RenderSurface* renderTarget = views_[i]->GetRenderTarget();
             
             VariantMap& eventData = GetEventDataMap();
+            eventData[P_VIEW] = views_[i];
             eventData[P_SURFACE] = renderTarget;
             eventData[P_TEXTURE] = (renderTarget ? renderTarget->GetParentTexture() : 0);
             eventData[P_SCENE] = views_[i]->GetScene();

+ 17 - 1
Source/Urho3D/Graphics/View.cpp

@@ -26,6 +26,7 @@
 #include "../IO/FileSystem.h"
 #include "../Graphics/Geometry.h"
 #include "../Graphics/Graphics.h"
+#include "../Graphics/GraphicsEvents.h"
 #include "../Graphics/GraphicsImpl.h"
 #include "../IO/Log.h"
 #include "../Graphics/Material.h"
@@ -509,6 +510,16 @@ void View::Update(const FrameInfo& frame)
     frame_.frameNumber_ = frame.frameNumber_;
     frame_.viewSize_ = viewSize_;
     
+    using namespace BeginViewUpdate;
+
+    VariantMap& eventData = GetEventDataMap();
+    eventData[P_VIEW] = this;
+    eventData[P_SURFACE] = renderTarget_;
+    eventData[P_TEXTURE] = (renderTarget_ ? renderTarget_->GetParentTexture() : 0);
+    eventData[P_SCENE] = scene_;
+    eventData[P_CAMERA] = camera_;
+    SendEvent(E_BEGINVIEWUPDATE, eventData);
+
     int maxSortedInstances = renderer_->GetMaxSortedInstances();
     
     // Clear buffers, geometry, light, occluder & batch list
@@ -522,14 +533,19 @@ void View::Update(const FrameInfo& frame)
         i->second_.Clear(maxSortedInstances);
     
     if (hasScenePasses_ && (!camera_ || !octree_))
+    {
+        SendEvent(E_ENDVIEWUPDATE, eventData);
         return;
-    
+    }
+
     // Set automatic aspect ratio if required
     if (camera_ && camera_->GetAutoAspectRatio())
         camera_->SetAspectRatioInternal((float)frame_.viewSize_.x_ / (float)frame_.viewSize_.y_);
     
     GetDrawables();
     GetBatches();
+
+    SendEvent(E_ENDVIEWUPDATE, eventData);
 }
 
 void View::Render()

+ 1 - 2
Source/Urho3D/Urho2D/Drawable2D.cpp

@@ -42,8 +42,7 @@ Drawable2D::Drawable2D(Context* context) :
     layer_(0),
     orderInLayer_(0),
     blendMode_(BLEND_ALPHA),
-    verticesDirty_(true),
-    visibility_(true)
+    verticesDirty_(true)
 {
 }
 

+ 0 - 6
Source/Urho3D/Urho2D/Drawable2D.h

@@ -90,10 +90,6 @@ public:
     void SetMaterial(Material* material);
     /// Return custom material or material (called by Renderer2D).
     Material* GetMaterial() const;
-    /// Set visibility (called by Renderer2D).
-    void SetVisibility(bool visibility) { visibility_ = visibility; }
-    /// Return visibility (called by Renderer2D).
-    bool GetVisibility() const { return visibility_; }
     /// Return all vertices (called by Renderer2D).
     const Vector<Vertex2D>& GetVertices();
 
@@ -129,8 +125,6 @@ protected:
     SharedPtr<Material> material_;
     /// Renderer2D.
     WeakPtr<Renderer2D> renderer_;
-    /// Test visible.
-    bool visibility_;
 };
 
 }

+ 6 - 6
Source/Urho3D/Urho2D/Renderer2D.cpp

@@ -37,6 +37,7 @@
 #include "../Graphics/Technique.h"
 #include "../Graphics/Texture2D.h"
 #include "../Graphics/VertexBuffer.h"
+#include "../Graphics/View.h"
 #include "../Core/WorkQueue.h"
 
 #include "../DebugNew.h"
@@ -173,7 +174,7 @@ void Renderer2D::UpdateGeometry(const FrameInfo& frame)
         {
             for (unsigned d = 0; d < drawables_.Size(); ++d)
             {
-                if (!drawables_[d]->GetVisibility() || drawables_[d]->GetVertices().Empty())
+                if (!drawables_[d]->IsInView(frame) || drawables_[d]->GetVertices().Empty())
                     continue;
 
                 const Vector<Vertex2D>& vertices = drawables_[d]->GetVertices();
@@ -246,9 +247,7 @@ static void CheckDrawableVisibility(const WorkItem* item, unsigned threadIndex)
     {
         Drawable2D* drawable = *start++;
         if (renderer->CheckVisibility(drawable) && drawable->GetVertices().Size())
-            drawable->SetVisibility(true);
-        else
-            drawable->SetVisibility(false);
+            drawable->MarkInView(*renderer->frame_);
     }
 }
 
@@ -260,6 +259,7 @@ void Renderer2D::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventDa
     // Check that we are updating the correct scene
     if (scene != eventData[P_SCENE].GetPtr())
         return;
+    frame_ = const_cast<FrameInfo*>(&static_cast<View*>(eventData[P_VIEW].GetPtr())->GetFrameInfo());
 
     PROFILE(UpdateRenderer2D);
 
@@ -322,7 +322,7 @@ void Renderer2D::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventDa
     vertexCount_ = 0;
     for (unsigned i = 0; i < drawables_.Size(); ++i)
     {
-        if (drawables_[i]->GetVisibility())
+        if (drawables_[i]->IsInView(*frame_))
             vertexCount_ += drawables_[i]->GetVertices().Size();
     }
     indexCount_ = vertexCount_ / 4 * 6;
@@ -338,7 +338,7 @@ void Renderer2D::HandleBeginViewUpdate(StringHash eventType, VariantMap& eventDa
 
     for (unsigned d = 0; d < drawables_.Size(); ++d)
     {
-        if (!drawables_[d]->GetVisibility())
+        if (!drawables_[d]->IsInView(*frame_))
             continue;
 
         Material* usedMaterial = drawables_[d]->GetMaterial();

+ 5 - 0
Source/Urho3D/Urho2D/Renderer2D.h

@@ -31,12 +31,15 @@ class Drawable2D;
 class IndexBuffer;
 class Material;
 class VertexBuffer;
+struct FrameInfo;
 
 /// 2D renderer components.
 class URHO3D_API Renderer2D : public Drawable
 {
     OBJECT(Renderer2D);
 
+    friend void CheckDrawableVisibility(const WorkItem* item, unsigned threadIndex);
+
 public:
     /// Construct.
     Renderer2D(Context* context);
@@ -93,6 +96,8 @@ private:
     Vector<SharedPtr<Material> > materials_;
     /// Geometries.
     Vector<SharedPtr<Geometry> > geometries_;
+    /// View frameinfo for current frame. Valid only inside HandleBeginViewUpdate().
+    FrameInfo* frame_;
     /// Frustum for current frame.
     const Frustum* frustum_;
     /// Frustum bounding box for current frame.