Browse Source

Check for device/context loss instead of window minimization for when not to render. Apply pending GPU resource updates on iOS after app has been restored.

Lasse Öörni 13 years ago
parent
commit
1603349120

+ 2 - 3
Engine/Engine/Engine.cpp

@@ -431,10 +431,9 @@ void Engine::Render()
 {
     PROFILE(Render);
     
-    // Do not render if device lost or if minimized
+    // Do not render if device lost
     Graphics* graphics = GetSubsystem<Graphics>();
-    Input* input = GetSubsystem<Input>();
-    if (!graphics || (input && input->IsMinimized()) || !graphics->BeginFrame())
+    if (!graphics || !graphics->BeginFrame())
         return;
     
     GetSubsystem<Renderer>()->Render();

+ 18 - 1
Engine/Graphics/OpenGL/OGLGraphics.cpp

@@ -144,6 +144,7 @@ Graphics::Graphics(Context* context_) :
     dxtTextureSupport_(false),
     etcTextureSupport_(false),
     pvrtcTextureSupport_(false),
+    wasMinimized_(false),
     numPrimitives_(0),
     numBatches_(0),
     defaultTextureFilterMode_(FILTER_BILINEAR),
@@ -385,8 +386,24 @@ bool Graphics::TakeScreenShot(Image& destImage)
 
 bool Graphics::BeginFrame()
 {
-    if (!IsInitialized() || !impl_->context_)
+    bool minimized = impl_->window_ && (SDL_GetWindowFlags(impl_->window_) & SDL_WINDOW_MINIMIZED);
+    
+    if (!IsInitialized() || IsDeviceLost())
+    {
+        wasMinimized_ = minimized;
         return false;
+    }
+
+    #ifdef IOS
+    // On iOS, check for end of minimization and apply pending GPU resource updates
+    if (wasMinimized_ && !minimized)
+    {
+        LOGDEBUG("Application restored, updating pending GPU resources");
+        for (Vector<GPUObject*>::Iterator i = gpuObjects_.Begin(); i != gpuObjects_.End(); ++i)
+            (*i)->OnDeviceReset();
+    }
+    #endif
+    wasMinimized_ = minimized;
     
     // Set default rendertarget and depth buffer
     ResetRenderTargets();

+ 2 - 0
Engine/Graphics/OpenGL/OGLGraphics.h

@@ -394,6 +394,8 @@ private:
     bool etcTextureSupport_;
     /// PVRTC formats support flag.
     bool pvrtcTextureSupport_;
+    /// Minimized flag for detecting end of minimization.
+    bool wasMinimized_;
     /// Number of primitives this frame.
     unsigned numPrimitives_;
     /// Number of batches this frame.

+ 2 - 4
Engine/Graphics/OpenGL/OGLIndexBuffer.cpp

@@ -152,8 +152,7 @@ bool IndexBuffer::SetData(const void* data)
         else
         {
             LOGWARNING("Index buffer data assignment while device is lost");
-            if (shadowData_)
-                dataPending_ = true;
+            dataPending_ = true;
         }
     }
     
@@ -204,8 +203,7 @@ bool IndexBuffer::SetDataRange(const void* data, unsigned start, unsigned count,
         else
         {
             LOGWARNING("Index buffer data assignment while device is lost");
-            if (shadowData_)
-                dataPending_ = true;
+            dataPending_ = true;
         }
     }
     

+ 2 - 4
Engine/Graphics/OpenGL/OGLVertexBuffer.cpp

@@ -242,8 +242,7 @@ bool VertexBuffer::SetData(const void* data)
         else
         {
             LOGWARNING("Vertex buffer data assignment while device is lost");
-            if (shadowData_)
-                dataPending_ = true;
+            dataPending_ = true;
         }
     }
     
@@ -293,8 +292,7 @@ bool VertexBuffer::SetDataRange(const void* data, unsigned start, unsigned count
         else
         {
             LOGWARNING("Vertex buffer data assignment while device is lost");
-            if (shadowData_)
-                dataPending_ = true;
+            dataPending_ = true;
         }
     }