Browse Source

Allow Camera::SetFlipVertical to be used externally for OpenGL (#2643)

* Allow Camera::FlipVertical to be used externally for OpenGL by toggling it either side of render to texture, i.e. instead of "set and clear" either side of render to texture.

(cherry picked from commit 434739d62c99e9328b66c338b7dc57c963b586c6)

* #1 Add explanation comment to previous commit.

(cherry picked from commit 4f1ca6cf8595b230e7ab2473fc37d1c0325a481a)

Co-authored-by: Chris Denham <[email protected]>
ChrisDenham 5 years ago
parent
commit
6fb55fa498
1 changed files with 13 additions and 5 deletions
  1. 13 5
      Source/Urho3D/Graphics/View.cpp

+ 13 - 5
Source/Urho3D/Graphics/View.cpp

@@ -596,15 +596,19 @@ void View::Render()
     }
     }
 #endif
 #endif
 
 
+#ifdef URHO3D_OPENGL
     if (renderTarget_)
     if (renderTarget_)
     {
     {
         // On OpenGL, flip the projection if rendering to a texture so that the texture can be addressed in the same way
         // 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
         // as a render texture produced on Direct3D9
-#ifdef URHO3D_OPENGL
+        // Note that the state of the FlipVertical mode is toggled here rather than enabled
+        // The reason for this is that we want the mode to be the opposite of what the user has currently set for the
+        // camera when rendering to texture for OpenGL
+        // This mode is returned to the original state by toggling it again below, after the render
         if (camera_)
         if (camera_)
-            camera_->SetFlipVertical(true);
-#endif
+            camera_->SetFlipVertical(!camera_->GetFlipVertical());
     }
     }
+#endif
 
 
     // Render
     // Render
     ExecuteRenderPathCommands();
     ExecuteRenderPathCommands();
@@ -651,8 +655,12 @@ void View::Render()
     }
     }
 
 
 #ifdef URHO3D_OPENGL
 #ifdef URHO3D_OPENGL
-    if (camera_)
-        camera_->SetFlipVertical(false);
+    if (renderTarget_)
+    {
+        // Restores original setting of FlipVertical when flipped by code above.
+        if (camera_)
+            camera_->SetFlipVertical(!camera_->GetFlipVertical());
+    }
 #endif
 #endif
 
 
     // Run framebuffer blitting if necessary. If scene was resolved from backbuffer, do not touch depth
     // Run framebuffer blitting if necessary. If scene was resolved from backbuffer, do not touch depth