VR: VR viewport size fetched from VR Manager 79/90679/1
authorTom Robinson <tom.robinson@samsung.com>
Mon, 3 Oct 2016 18:06:37 +0000 (19:06 +0100)
committerTom Robinson <tom.robinson@samsung.com>
Mon, 3 Oct 2016 18:06:37 +0000 (19:06 +0100)
Change-Id: I55f19834af1cb8fccc2bb4785407702302e5d0fb

dali/internal/common/vr-manager-impl.cpp
dali/internal/common/vr-manager-impl.h
dali/internal/render/common/render-manager.cpp

index f3c398f..55fa16e 100644 (file)
@@ -30,7 +30,13 @@ namespace Internal
 
 namespace
 {
+
 #define GL(x) { x; int err = context.GetError(); if(err) { DALI_LOG_ERROR( "GL_ERROR: [%d] '%s', %x\n", __LINE__, #x, (unsigned)err);fflush(stderr);fflush(stdout);} else { /*DALI_LOG_ERROR("GL Call: %s\n", #x); fflush(stdout);*/} }
+
+// These dimensions must match those used by the Tizen VR engine.
+// TODO: Get these from the Tizen VR engine when such an API is implemented.
+const Rect<int> DEFAULT_VR_VIEWPORT_DIMENSIONS( 0, 0, 1024, 1024 );
+
 } // Anonymous namespace
 
 
@@ -169,6 +175,11 @@ void VrManager::SubmitFrame( Context& context )
   }
 }
 
+void VrManager::GetVrViewportDimensions( Rect<int>& viewportDimensions )
+{
+  viewportDimensions = DEFAULT_VR_VIEWPORT_DIMENSIONS;
+}
+
 
 } // Internal
 
index 7193552..874860d 100644 (file)
@@ -22,11 +22,12 @@ class VrManager
   public:
 
     /**
-     * @brief todor
+     * @brief Constructor.
+     * @param[in] vrEngine The VR engine abstraction object
      */
     VrManager( Dali::Integration::VrEngine* vrEngine );
     /**
-     * @brief todor
+     * @brief Destructor.
      */
     ~VrManager();
 
@@ -65,12 +66,17 @@ class VrManager
      */
     void SubmitFrame( Context& context );
 
+    /**
+     * @brief todor
+     */
+    void GetVrViewportDimensions( Rect<int>& viewportDimensions );
+
   private:
 
     Dali::Integration::VrEngine*  mVrEngine;          ///< todor
-    SceneGraph::Node*             mHeadNode;
-    bool                          mEnabled;
-    bool                          mEngineInitialized;
+    SceneGraph::Node*             mHeadNode;          ///< todor
+    bool                          mEnabled;           ///< todor
+    bool                          mEngineInitialized; ///< todor
 
 };
 
index 1c21ebd..c6bf827 100644 (file)
@@ -46,9 +46,6 @@
 #include <cstdio>
 #include <string.h>
 
-//TODOVR
-//#define DEBUG_DISABLE_BARREL_DISTORTION
-
 using namespace Dali::Integration::Vr;
 using Dali::Integration::VrEngine;
 
@@ -235,7 +232,6 @@ void RenderManager::ContextCreated()
   mImpl->context.GlContextCreated();
   mImpl->programController.GlContextCreated();
 
-
   // renderers, textures and gpu buffers cannot reinitialize themselves
   // so they rely on someone reloading the data for them
 }
@@ -546,10 +542,9 @@ bool RenderManager::Render( Integration::RenderStatus& status )
   if( !mImpl->firstRenderCompleted || mImpl->renderersAdded )
   {
     // This will perform pre-render steps with the Tizen VR Engine IF using Tizen VR.
-    VrManager& vrManager = mImpl->vrManager;
-    vrManager.PrepareRender( mImpl->defaultSurfaceRect.width, mImpl->defaultSurfaceRect.height );
+    mImpl->vrManager.PrepareRender( mImpl->defaultSurfaceRect.width, mImpl->defaultSurfaceRect.height );
 
-    if( !vrManager.IsEnabled() )
+    if( !mImpl->vrManager.IsEnabled() )
     {
       // switch rendering to adaptor provided (default) buffer
       GL( mImpl->context.BindFramebuffer( GL_FRAMEBUFFER, 0 ) );
@@ -599,7 +594,7 @@ bool RenderManager::Render( Integration::RenderStatus& status )
     }
 
     // This will Submit frame to the Tizen VR Engine IF using Tizen VR.
-    vrManager.SubmitFrame( mImpl->context );
+    mImpl->vrManager.SubmitFrame( mImpl->context );
   }
 
   //Notify RenderGeometries that rendering has finished
@@ -690,15 +685,20 @@ void RenderManager::DoRender( RenderInstruction& instruction, Shader& defaultSha
     }
     // switch rendering to adaptor provided (default) buffer
 
-
     // Check whether a viewport is specified, otherwise the full surface size is used
     if ( instruction.mIsViewportSet )
     {
       // For glViewport the lower-left corner is (0,0)
-      // TODOVR: using 2 buffers, vieport Y starts with 0
-      //const int y = 0;//( mImpl->defaultSurfaceRect.height - instruction.mViewport.height ) - instruction.mViewport.y;
-      //viewportRect.Set( instruction.mViewport.x,  y, instruction.mViewport.width, instruction.mViewport.height );
-      viewportRect.Set( 0, 0, 1024, 1024 );
+      if( mImpl->vrManager.IsEnabled() )
+      {
+        // If using VR, get the dimensions from the VR manager.
+        mImpl->vrManager.GetVrViewportDimensions( viewportRect );
+      }
+      else
+      {
+        const int viewPortY = ( mImpl->defaultSurfaceRect.height - instruction.mViewport.height ) - instruction.mViewport.y;
+        viewportRect.Set( instruction.mViewport.x, viewPortY, instruction.mViewport.width, instruction.mViewport.height );
+      }
     }
     else
     {