VR: Refactor to remove vr-engine custom property system 61/92361/4
authorTom Robinson <tom.robinson@samsung.com>
Fri, 14 Oct 2016 15:52:18 +0000 (16:52 +0100)
committerTom Robinson <tom.robinson@samsung.com>
Mon, 17 Oct 2016 11:16:42 +0000 (12:16 +0100)
Change-Id: Id3a71207f7b310c6dd66d5efeace95007b410092

dali/integration-api/vr-engine.h
dali/internal/common/vr-manager-impl.cpp
dali/internal/common/vr-manager-impl.h

index e36a94d..8d093a3 100644 (file)
@@ -3,9 +3,6 @@
 
 //todor licence
 #include <dali/public-api/math/quaternion.h>
-
-//#include <adaptors/common/tizen-vr-platform-header.h>
-
 #include <stdint.h>
 
 namespace Dali
@@ -19,29 +16,26 @@ namespace Integration
 namespace Vr
 {
 
-struct VrEngineInitializeParams
+struct VrEngineEyePose
 {
-  // Screen settings
-  int           screenWidth;
-  int           screenHeight;
-
-  // Eye settings
-  uint32_t*     frameBufferObjects; ///< 2 values
-  uint32_t*     colorTextures;
-  uint32_t*     depthTextures;      ///< May be null
+  Quaternion    rotation;
+  double        timestamp;
 };
 
-struct VrEngineEyePose
+struct VrEngineRenderTargetInfo
 {
-  Quaternion rotation;
-  double timestamp;
+  int           frameBufferObjects[2];
+  int           colorTextures[2];      ///< if -1, then engine will create these buffers
+  int           depthTextures[2];
 };
 
-struct VrEngineRenderTargetInfo
+struct Eye
 {
-  int frameBufferObjects[2];
-  int colorTextures[2]; ///< if -1, then engine will create these buffers
-  int depthTextures[2];
+  enum Type
+  {
+    LEFT =  0,
+    RIGHT = 1
+  };
 };
 
 } // Vr
@@ -53,60 +47,37 @@ class VrEngine
 {
 public:
 
-    //todor move to vr-defaults?
-  struct Eye
+  struct VrProperty
   {
     enum Type
     {
-      LEFT =  0,
-      RIGHT = 1
+      ENABLED,                                                ///< todor
+      EYE_BUFFER_COUNT,                                       ///< (int) Number of buffers ( 1 buffer for both eyes )
+
+      // Render target by data structure
+      EYE_RENDER_TARGETS,                                     ///< (VrEngineRenderTargetInfo*)
+      EYE_CURRENT_POSE,                                       ///< (struct VrEngineEyePose)
+
+      // Framebuffers per eye getter properties
+      EYE_LEFT_TEXTURE_ID =         1000,                     ///< (int) Left eye texture id for buffer ( must be passed as EYE_LEFT_TEXTURE_ID + N )
+      EYE_RIGHT_TEXTURE_ID =        1065,                     ///< (int) Right eye texture id for buffer ( must be passed as EYE_RIGHT_TEXTURE_ID + N )
     };
   };
 
-  struct VrProperty
+  /**
+   * @brief todor
+   */
+  struct EyeBufferInfo
   {
-    enum Type
+    struct EyeInfo
     {
-      ENABLED,                        ///< todor
-
-      CURRENT_POSE_QUATERNION,        // outputs float[4], rw
-      EYE_BUFFER_COUNT,               // int, number of buffers ( 1 buffer for both eyes ), rw
-
-      // render target by data structure
-      EYE_RENDER_TARGETS,             // [VrEngineRenderTargetInfo*]
-
-      EYE_BUFFER_WIDTH,               // [int] width of single eye renderable area
-      EYE_BUFFER_HEIGHT,              // [int] height of single eye renderable area
-
-      EYE_CURRENT_POSE,               // [ structure VrEngineEyePose ]
-
-      /**
-       * Framebuffers per eye getter properties
-       */
-      EYE_LEFT_CURRENT_TEXTURE_ID,    // [int] ro, texture id to be written to ( updated with frame index )
-      EYE_LEFT_TEXTURE_ID = 1000,     // [int] rw, left eye texture id for buffer ( must be passed as EYE_LEFT_TEXTURE_ID+N )
-      // helper enums
-      EYE_LEFT_TEXTURE0_ID = EYE_LEFT_TEXTURE_ID,
-      EYE_LEFT_TEXTURE1_ID = EYE_LEFT_TEXTURE_ID+1,
-      EYE_LEFT_TEXTURE2_ID = EYE_LEFT_TEXTURE_ID+2,
-      EYE_LEFT_TEXTURE3_ID = EYE_LEFT_TEXTURE_ID+3,
-
-      EYE_RIGHT_CURRENT_TEXTURE_ID,    // [int] ro, texture id to be written to ( updated with frame index )
-      EYE_RIGHT_TEXTURE_ID = 1065,     // [int] rw, right eye texture id for buffer ( must be passed as EYE_RIGHT_TEXTURE_ID+N )
-      // helper enums
-      EYE_RIGHT_TEXTURE0_ID = EYE_RIGHT_TEXTURE_ID,
-      EYE_RIGHT_TEXTURE1_ID = EYE_RIGHT_TEXTURE_ID+1,
-      EYE_RIGHT_TEXTURE2_ID = EYE_RIGHT_TEXTURE_ID+2,
-      EYE_RIGHT_TEXTURE3_ID = EYE_RIGHT_TEXTURE_ID+3,
-
-      EYE_LEFT_CURRENT_FBO_ID = 1999,
-      EYE_LEFT_FBO_ID = 2000, // [int] left eye fbo for buffer (EYE_LEFT_FBO_ID+N)
-      EYE_RIGHT_CURRENT_FBO_ID = 2099,
-      EYE_RIGHT_FBO_ID = 2100,// [int] right eye fbo for buffer (EYE_RIGHT_FBO_ID+N)
-
-      EYE_LEFT_DEPTH_TEXTURE_ID = 3000, // [int] left eye depth texture for buffer (EYE_LEFT_FBO_ID+N)
-      EYE_RIGHT_DEPTH_TEXTURE_ID = 3064,// [int] right eye depth texture for buffer (EYE_RIGHT_FBO_ID+N)
+      int frameBufferObject;
+      int texture;
     };
+
+    EyeInfo eye[2];
+    int bufferWidth;
+    int bufferHeight;
   };
 
   //todor doxygen all below
@@ -118,49 +89,14 @@ public:
   {
   }
 
-  virtual bool Initialize( Vr::VrEngineInitializeParams* initializeParams ) = 0;
+  virtual bool Initialize( unsigned int screenWidth, unsigned int screenHeight ) = 0;
   virtual void Start() = 0;
   virtual void Stop() = 0;
   virtual void PreRender() = 0;
   virtual void PostRender() = 0;
   virtual void SubmitFrame() = 0;
-
-  // Client must perform output validation if necessary
-  virtual bool Get( const int property, void* output, int count ) = 0;
-  virtual bool Set( const int property, const void* input, int count ) = 0;
-
-  // Helper functions
-  bool Get( int property, void* output )
-  {
-    return Get( property, output, 1 );
-  }
-
-  bool Set( int property, void* input )
-  {
-    return Set( property, input, 1 );
-  }
-
-  inline bool Get( const int* properties, void** outputs, int count )
-  {
-    // Fill output array
-    for( int i = 0; i < count; ++i )
-    {
-      Get( properties[i], outputs[i], 1 );
-    }
-    return true;
-  }
-
-  inline bool Set( const int* properties, const void** inputs, int count )
-  {
-    // Fill output array
-    for( int i = 0; i < count; ++i )
-    {
-      return Set( properties[i], inputs[i], 1 );
-    }
-    return true;
-  }
-
-private:
+  virtual bool Get( const int property, void* output ) = 0;
+  virtual void GetEyeBufferInfo( EyeBufferInfo& eyeBufferInfo ) = 0;
 
 };
 
@@ -168,4 +104,4 @@ private:
 
 } // Dali
 
-#endif
+#endif // DALI_VR_ENGINE_H
index a1c2547..70f9ab7 100644 (file)
@@ -22,8 +22,6 @@
 #include <dali/integration-api/vr-defaults.h>
 #include <stdio.h>
 #include <stdlib.h>
-//todor
-#include <iostream>
 
 namespace Dali
 {
@@ -39,7 +37,6 @@ VrManager::VrManager( Dali::Integration::VrEngine* vrEngine )
   mEnabled( false ),
   mEngineInitialized( false )
 {
-  std::cout << "todor: ##################################### VRMANAGER CTOR" << std::endl;
   // We get the enabled state from the VR Engine in adaptor.
   vrEngine->Get( Integration::VrEngine::VrProperty::ENABLED, &mEnabled );
 }
@@ -70,12 +67,10 @@ void VrManager::UpdateHeadOrientation()
 
     if( mVrEngine->Get( Dali::Integration::VrEngine::VrProperty::EYE_CURRENT_POSE, &eyePose ) )
     {
-      //std::cout << "todor: VRMANAGER: UpdateHeadOrientation: Setting orientation: " << eyePose.rotation << std::endl;
       mHeadNode->SetOrientation( eyePose.rotation );
     }
     else
     {
-      //std::cout << "todor: VRMANAGER: UpdateHeadOrientation: Setting orientation: DEFAULT" << std::endl;
       mHeadNode->SetOrientation( Quaternion( 1.0f, 0.0f, 0.0f, 0.0f ) );
     }
   }
@@ -89,12 +84,7 @@ void VrManager::PrepareRender( unsigned int surfaceWidth, unsigned int surfaceHe
     if( !mEngineInitialized )
     {
       // Initialise VR engine.
-      Dali::Integration::Vr::VrEngineInitializeParams params;
-      memset( &params, 0, sizeof( Dali::Integration::Vr::VrEngineInitializeParams ) );
-      params.screenWidth = surfaceWidth;
-      params.screenHeight = surfaceHeight;
-
-      mVrEngine->Initialize( &params );
+      mVrEngine->Initialize( surfaceWidth, surfaceHeight );
       mEngineInitialized = true;
 
       // Start VR engine.
@@ -114,43 +104,27 @@ bool VrManager::RenderEyes( Context& context, Dali::Camera::Type cameraType )
   {
     context.GetError();
 
-    // This reads all the required VR information in one go.
-    int leftFrameBufferObject( -1 );
-    int rightFrameBufferObject( -1 );
-    int leftTexture( -1 );
-    int rightTexture( -1 );
-    int bufferWidth( -1 );
-    int bufferHeight( -1 );
-
-    static const int properties[] =
-    {
-      Dali::Integration::VrEngine::VrProperty::EYE_LEFT_CURRENT_FBO_ID,     Dali::Integration::VrEngine::VrProperty::EYE_RIGHT_CURRENT_FBO_ID,
-      Dali::Integration::VrEngine::VrProperty::EYE_LEFT_CURRENT_TEXTURE_ID, Dali::Integration::VrEngine::VrProperty::EYE_RIGHT_CURRENT_TEXTURE_ID,
-      Dali::Integration::VrEngine::VrProperty::EYE_BUFFER_WIDTH,            Dali::Integration::VrEngine::VrProperty::EYE_BUFFER_HEIGHT
-    };
-
-    void* values[] =
-    {
-      &leftFrameBufferObject, &rightFrameBufferObject, &leftTexture, &rightTexture, &bufferWidth, &bufferHeight
-    };
+    Dali::Integration::VrEngine::EyeBufferInfo eyeBufferInfo;
+    mVrEngine->GetEyeBufferInfo( eyeBufferInfo );
 
+    Dali::Integration::Vr::Eye::Type eye;
     if( cameraType == Dali::Camera::VR_EYE_LEFT )
     {
+      eye = Dali::Integration::Vr::Eye::LEFT;
       vrEye = true;
-      mVrEngine->Get( properties, values, 6 );
-
-      context.BindFramebuffer( GL_FRAMEBUFFER, leftFrameBufferObject );
-      context.Bind2dTexture( leftTexture );
-      context.TexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, bufferWidth, bufferHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
     }
     else if( cameraType == Dali::Camera::VR_EYE_RIGHT )
     {
+      eye = Dali::Integration::Vr::Eye::RIGHT;
       vrEye = true;
-      mVrEngine->Get( properties, values, 6 );
+    }
+
+    if( vrEye )
+    {
+      context.BindFramebuffer( GL_FRAMEBUFFER, eyeBufferInfo.eye[eye].frameBufferObject );
+      context.Bind2dTexture( eyeBufferInfo.eye[eye].texture );
 
-      context.BindFramebuffer( GL_FRAMEBUFFER, rightFrameBufferObject);
-      context.Bind2dTexture( rightTexture );
-      context.TexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, bufferWidth, bufferHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
+      context.TexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, eyeBufferInfo.bufferWidth, eyeBufferInfo.bufferHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL );
     }
   }
 
@@ -166,7 +140,7 @@ void VrManager::SubmitFrame( Context& context )
   }
 }
 
-void VrManager::GetVrViewportDimensions( Rect<int>& viewportDimensions )
+void VrManager::GetVrViewportDimensions( Viewport& viewportDimensions )
 {
   viewportDimensions = mViewportDimensions;
 }
index b690880..c0f38e9 100644 (file)
@@ -5,6 +5,7 @@
 #include <dali/integration-api/vr-engine.h>
 #include <dali/internal/update/nodes/node.h>
 #include <dali/public-api/actors/camera-actor.h>
+#include <dali/public-api/math/viewport.h>
 #include <cstring>
 
 namespace Dali
@@ -13,7 +14,6 @@ namespace Dali
 namespace Internal
 {
 
-
 /**
  * Object managing access to VR abstraction.
  */
@@ -65,7 +65,7 @@ class VrManager
     /**
      * @brief todor
      */
-    void GetVrViewportDimensions( Rect<int>& viewportDimensions );
+    void GetVrViewportDimensions( Viewport& viewportDimensions );
 
   private:
 
@@ -83,5 +83,3 @@ class VrManager
 } // Dali
 
 #endif // DALI_VR_MANAGER_H
-
-