Browse Source

Revert "Fixes to sceneless renderpath on OpenGL." to fix crash on minimize on Android.

Lasse Öörni 11 years ago
parent
commit
c8fe21f06a
3 changed files with 42 additions and 49 deletions
  1. 20 19
      Source/Engine/Graphics/Renderer.cpp
  2. 22 28
      Source/Engine/Graphics/View.cpp
  3. 0 2
      Source/Engine/Graphics/View.h

+ 20 - 19
Source/Engine/Graphics/Renderer.cpp

@@ -599,26 +599,27 @@ void Renderer::Update(float timeStep)
         
         
         const IntRect& viewRect = viewport->GetRect();
         const IntRect& viewRect = viewport->GetRect();
         Scene* scene = viewport->GetScene();
         Scene* scene = viewport->GetScene();
-        Octree* octree = scene ? scene->GetComponent<Octree>() : 0;
-        if (scene && octree)
+        if (!scene)
+            continue;
+        
+        Octree* octree = scene->GetComponent<Octree>();
+        
+        // Update octree (perform early update for drawables which need that, and reinsert moved drawables.)
+        // However, if the same scene is viewed from multiple cameras, update the octree only once
+        if (!updatedOctrees_.Contains(octree))
         {
         {
-            // Update octree (perform early update for drawables which need that, and reinsert moved drawables.)
-            // However, if the same scene is viewed from multiple cameras, update the octree only once
-            if (!updatedOctrees_.Contains(octree))
-            {
-                frame_.camera_ = viewport->GetCamera();
-                frame_.viewSize_ = viewRect.Size();
-                if (frame_.viewSize_ == IntVector2::ZERO)
-                    frame_.viewSize_ = IntVector2(graphics_->GetWidth(), graphics_->GetHeight());
-                octree->Update(frame_);
-                updatedOctrees_.Insert(octree);
-                
-                // Set also the view for the debug renderer already here, so that it can use culling
-                /// \todo May result in incorrect debug geometry culling if the same scene is drawn from multiple viewports
-                DebugRenderer* debug = scene->GetComponent<DebugRenderer>();
-                if (debug)
-                    debug->SetView(viewport->GetCamera());
-            }
+            frame_.camera_ = viewport->GetCamera();
+            frame_.viewSize_ = viewRect.Size();
+            if (frame_.viewSize_ == IntVector2::ZERO)
+                frame_.viewSize_ = IntVector2(graphics_->GetWidth(), graphics_->GetHeight());
+            octree->Update(frame_);
+            updatedOctrees_.Insert(octree);
+            
+            // Set also the view for the debug renderer already here, so that it can use culling
+            /// \todo May result in incorrect debug geometry culling if the same scene is drawn from multiple viewports
+            DebugRenderer* debug = scene->GetComponent<DebugRenderer>();
+            if (debug)
+                debug->SetView(viewport->GetCamera());
         }
         }
         
         
         // Update view. This may queue further views
         // Update view. This may queue further views

+ 22 - 28
Source/Engine/Graphics/View.cpp

@@ -315,7 +315,6 @@ bool View::Define(RenderSurface* renderTarget, Viewport* viewport)
         return false;
         return false;
     
     
     hasScenePasses_ = false;
     hasScenePasses_ = false;
-    flipVertical_ = false;
     
     
     // Make sure that all necessary batch queues exist
     // Make sure that all necessary batch queues exist
     scenePasses_.Clear();
     scenePasses_.Clear();
@@ -400,13 +399,6 @@ bool View::Define(RenderSurface* renderTarget, Viewport* viewport)
     litBasePassName_ = PASS_LITBASE;
     litBasePassName_ = PASS_LITBASE;
     litAlphaPassName_ = PASS_LITALPHA;
     litAlphaPassName_ = PASS_LITALPHA;
     
     
-    // On OpenGL, flip the projection if rendering to a texture so that the texture can be addressed in the same way
-    // as a render texture produced on Direct3D9
-    #ifdef URHO3D_OPENGL
-    if (renderTarget_)
-        flipVertical_ = true;
-    #endif
-    
     // Go through commands to check for deferred rendering and other flags
     // Go through commands to check for deferred rendering and other flags
     deferred_ = false;
     deferred_ = false;
     deferredAmbient_ = false;
     deferredAmbient_ = false;
@@ -502,12 +494,12 @@ void View::Update(const FrameInfo& frame)
     for (HashMap<StringHash, BatchQueue>::Iterator i = batchQueues_.Begin(); i != batchQueues_.End(); ++i)
     for (HashMap<StringHash, BatchQueue>::Iterator i = batchQueues_.Begin(); i != batchQueues_.End(); ++i)
         i->second_.Clear(maxSortedInstances);
         i->second_.Clear(maxSortedInstances);
     
     
-    if (camera_)
-    {
-        // Set automatic aspect ratio if required
-        if (camera_->GetAutoAspectRatio())
-            camera_->SetAspectRatioInternal((float)frame_.viewSize_.x_ / (float)frame_.viewSize_.y_);
-    }
+    if (hasScenePasses_ && (!camera_ || !octree_))
+        return;
+    
+    // Set automatic aspect ratio if required
+    if (camera_->GetAutoAspectRatio())
+        camera_->SetAspectRatioInternal((float)frame_.viewSize_.x_ / (float)frame_.viewSize_.y_);
     
     
     GetDrawables();
     GetDrawables();
     GetBatches();
     GetBatches();
@@ -515,6 +507,9 @@ void View::Update(const FrameInfo& frame)
 
 
 void View::Render()
 void View::Render()
 {
 {
+    if (hasScenePasses_ && (!octree_ || !camera_))
+        return;
+    
     // Actually update geometry data now
     // Actually update geometry data now
     UpdateGeometries();
     UpdateGeometries();
     
     
@@ -546,15 +541,20 @@ void View::Render()
     }
     }
     #endif
     #endif
     
     
-    #ifdef URHO3D_OPENGL
-    if (camera_)
-        camera_->SetFlipVertical(flipVertical_);
-    #endif
+    if (renderTarget_)
+    {
+        // On OpenGL, flip the projection if rendering to a texture so that the texture can be addressed in the same way
+        // as a render texture produced on Direct3D9
+        #ifdef URHO3D_OPENGL
+        if (camera_)
+            camera_->SetFlipVertical(true);
+        #endif
+    }
     
     
     // Render
     // Render
     ExecuteRenderPathCommands();
     ExecuteRenderPathCommands();
     
     
-    #ifdef URHO3D_OPENGL
+    #ifdef URHO_OPENGL
     if (camera_)
     if (camera_)
         camera_->SetFlipVertical(false);
         camera_->SetFlipVertical(false);
     #endif
     #endif
@@ -569,7 +569,7 @@ void View::Render()
         BlitFramebuffer(static_cast<Texture2D*>(currentRenderTarget_->GetParentTexture()), renderTarget_, true);
         BlitFramebuffer(static_cast<Texture2D*>(currentRenderTarget_->GetParentTexture()), renderTarget_, true);
     
     
     // If this is a main view, draw the associated debug geometry now
     // If this is a main view, draw the associated debug geometry now
-    if (!renderTarget_ && camera_ && octree_)
+    if (!renderTarget_ && octree_ && camera_)
     {
     {
         DebugRenderer* debug = octree_->GetComponent<DebugRenderer>();
         DebugRenderer* debug = octree_->GetComponent<DebugRenderer>();
         if (debug && debug->IsEnabledEffective())
         if (debug && debug->IsEnabledEffective())
@@ -669,9 +669,6 @@ void View::SetCameraShaderParameters(Camera* camera, bool setProjection, bool ov
 
 
 void View::GetDrawables()
 void View::GetDrawables()
 {
 {
-    if (!camera_ || !octree_)
-        return;
-    
     PROFILE(GetDrawables);
     PROFILE(GetDrawables);
     
     
     WorkQueue* queue = GetSubsystem<WorkQueue>();
     WorkQueue* queue = GetSubsystem<WorkQueue>();
@@ -838,9 +835,6 @@ void View::GetDrawables()
 
 
 void View::GetBatches()
 void View::GetBatches()
 {
 {
-    if (!camera_ || !octree_)
-        return;
-    
     WorkQueue* queue = GetSubsystem<WorkQueue>();
     WorkQueue* queue = GetSubsystem<WorkQueue>();
     PODVector<Light*> vertexLights;
     PODVector<Light*> vertexLights;
     BatchQueue* alphaQueue = batchQueues_.Contains(alphaPassName_) ? &batchQueues_[alphaPassName_] : (BatchQueue*)0;
     BatchQueue* alphaQueue = batchQueues_.Contains(alphaPassName_) ? &batchQueues_[alphaPassName_] : (BatchQueue*)0;
@@ -1934,8 +1928,8 @@ void View::DrawFullscreenQuad(bool nearQuad)
     Matrix3x4 model = Matrix3x4::IDENTITY;
     Matrix3x4 model = Matrix3x4::IDENTITY;
     Matrix4 projection = Matrix4::IDENTITY;
     Matrix4 projection = Matrix4::IDENTITY;
     
     
-    #ifdef URHO3D_OPENGL
-    if (flipVertical_)
+    #ifdef URHO_OPENGL
+    if (camera_ && camera_->GetFlipVertical())
         projection.m11_ = -1.0f;
         projection.m11_ = -1.0f;
     model.m23_ = nearQuad ? -1.0f : 1.0f;
     model.m23_ = nearQuad ? -1.0f : 1.0f;
     #else
     #else

+ 0 - 2
Source/Engine/Graphics/View.h

@@ -310,8 +310,6 @@ private:
     bool useLitBase_;
     bool useLitBase_;
     /// Has scene passes flag. If no scene passes, view can be defined without a valid scene or camera to only perform quad rendering.
     /// Has scene passes flag. If no scene passes, view can be defined without a valid scene or camera to only perform quad rendering.
     bool hasScenePasses_;
     bool hasScenePasses_;
-    /// Flip vertical flag.
-    bool flipVertical_;
     /// Renderpath.
     /// Renderpath.
     RenderPath* renderPath_;
     RenderPath* renderPath_;
     /// Per-thread octree query results.
     /// Per-thread octree query results.