Index: branches/HTM-8.2-dev0-MediaTek/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/HTM-8.2-dev0-MediaTek/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 628)
+++ branches/HTM-8.2-dev0-MediaTek/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 629)
@@ -1372,4 +1372,5 @@
      xConfirmPara( allEqual , "Each layer shall have a different position in scalability space." );
 
+#if !H_3D_FCO
      if ( numDiff  == 1 ) 
      {
@@ -1390,4 +1391,5 @@
 #endif
      }
+#endif
    }
  }
Index: branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TComDataCU.cpp	(revision 628)
+++ branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TComDataCU.cpp	(revision 629)
@@ -3569,7 +3569,18 @@
     UInt uiPartIdxCenter;
     xDeriveCenterIdx( uiPUIdx, uiPartIdxCenter );    
+#if H_3D_FCO
+    TComPic * pcTexturePic = m_pcSlice->getTexturePic();
+    TComDataCU *pcTextureCU = 0;
+    if ( pcTexturePic )
+        pcTextureCU = pcTexturePic->getCU( getAddr() );
+#else
     TComDataCU *pcTextureCU = m_pcSlice->getTexturePic()->getCU( getAddr() );
+#endif
  
+#if H_3D_FCO
+    if ( pcTextureCU && pcTexturePic->getReconMark() && !pcTextureCU->isIntra( uiPartIdxCenter ) )
+#else
     if ( pcTextureCU && !pcTextureCU->isIntra( uiPartIdxCenter ) )
+#endif
     {
       pcTextureCU->getMvField( pcTextureCU, uiPartIdxCenter, REF_PIC_LIST_0, pcMvFieldNeighbours[iCount<<1] );
@@ -5562,7 +5573,21 @@
 
 #if H_3D_NBDV_REF
-          TComPic* picDepth = NULL;          
+          TComPic* picDepth = NULL;   
+#if H_3D_FCO_VSP_DONBDV
+          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
+          if ( picDepth->getPicYuvRec() != NULL  )  
+          {
+            cColMv.setZero();
+          }
+          else // Go back with virtual depth
+          {
+            picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
+          }
+
+          assert(picDepth != NULL);
+#else
           picDepth = getSlice()->getIvPic( true, iTargetViewIdx );
           assert(picDepth != NULL);
+#endif
           if (picDepth && bDepthRefine)
             estimateDVFromDM(iTargetViewIdx, uiPartIdx, picDepth, uiPartAddr, &cColMv );
@@ -5662,6 +5687,22 @@
           pDInfo->m_aVIdxCan = cIDVInfo.m_aVIdxCan[iList][ curPos ];
 #if H_3D_NBDV_REF
+#if H_3D_FCO_VSP_DONBDV
+          TComPic* picDepth  = NULL;
+
+          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
+          if ( picDepth->getPicYuvRec() != NULL )  
+          {
+            cDispVec.setZero();
+          }
+          else // Go back with virtual depth
+          {
+            picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
+          }
+
+          assert(picDepth != NULL);
+#else
           TComPic* picDepth = getSlice()->getIvPic( true, pDInfo->m_aVIdxCan );
           assert(picDepth!=NULL);
+#endif
 
           if (picDepth && bDepthRefine)
@@ -5707,7 +5748,20 @@
 #if H_3D_NBDV_REF
     TComPic* picDepth = NULL;
+#if H_3D_FCO_VSP_DONBDV
+    picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
+    if ( picDepth->getPicYuvRec() != NULL )  
+    {
+      defaultDV.setZero();
+    }
+    else // Go back with virtual depth
+    {
+      picDepth = getSlice()->getIvPic( true, viewIndex );
+    }
+
+    assert(picDepth != NULL);
+#else
     picDepth = getSlice()->getIvPic( true, viewIndex );
     assert(picDepth!=NULL);
-
+#endif
     if (picDepth && bDepthRefine)
     {
@@ -5812,7 +5866,19 @@
           TComPic* picDepth = NULL;
           assert(getSlice()->getRefPic(eRefPicList, refId)->getPOC() == getSlice()->getPOC());          
+#if H_3D_FCO_VSP_DONBDV
+          picDepth  = getSlice()->getIvPic(true, getSlice()->getViewIndex() );
+          if ( picDepth->getPicYuvRec() != NULL )  
+          {
+            cMvPred.setZero();
+          }
+          else// Go back with virtual depth
+          {
+            picDepth = getSlice()->getIvPic (true, refViewIdx );
+          }
+          assert(picDepth != NULL);
+#else
           picDepth   = getSlice()->getIvPic (true, refViewIdx );
           assert(picDepth != NULL);
-
+#endif
           UInt uiPartIdx = 0;   //Notes from MTK: Please confirm that using 0 as partition index and partition address is correct for CU-level DoNBDV
           UInt uiPartAddr = 0;  //QC: confirmed
Index: branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TComPic.cpp	(revision 628)
+++ branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TComPic.cpp	(revision 629)
@@ -118,4 +118,15 @@
   memcpy(m_numReorderPics, numReorderPics, MAX_TLAYER*sizeof(Int));
 
+  /* initialize the texture to depth reference status */
+#if H_3D_FCO
+  for (int j=0; j<2; j++)
+  {
+      for (int i=0; i<MAX_NUM_REF; i++)
+      {
+          m_aiTexToDepRef[j][i] = -1;
+      }
+  }
+#endif
+
   return;
 }
@@ -722,4 +733,9 @@
   TComSlice* pcCurrSlice = getSlice(getCurrSliceIdx());
   TComPic* pcTextPic = pcCurrSlice->getTexturePic();
+#if H_3D_FCO
+  if ( pcTextPic )
+  {
+#endif
+
   TComSlice* pcTextSlice = pcTextPic->getSlice(0); // currently only support single slice
 
@@ -743,4 +759,8 @@
 
   }
+#if H_3D_FCO
+  }
+#endif
+
 }
 
Index: branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TComPrediction.cpp	(revision 628)
+++ branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TComPrediction.cpp	(revision 629)
@@ -731,5 +731,19 @@
   // Get depth reference
   Int       depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
+#if H_3D_FCO_VSP_DONBDV
+  TComPic* pRefPicBaseDepth = 0;
+  Bool     bIsCurrDepthCoded = false;
+  pRefPicBaseDepth  = pcCU->getSlice()->getIvPic( true, pcCU->getSlice()->getViewIndex() );
+  if ( pRefPicBaseDepth->getPicYuvRec() != NULL  ) 
+  {
+    bIsCurrDepthCoded = true;
+  }
+  else 
+  {
+    pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
+  }
+#else
   TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
+#endif
   assert(pRefPicBaseDepth != NULL);
   TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
@@ -751,4 +765,11 @@
   TComMv cDv  = pcCU->getDvInfo(uiPartAddr).m_acNBDV;
   pcCU->clipMv(cDv);
+
+#if H_3D_FCO_VSP_DONBDV
+  if ( bIsCurrDepthCoded )
+  {
+      cDv.setZero();
+  }
+#endif
 
 #if NTT_VSP_COMMON_E0207_E0208
Index: branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TypeDef.h	(revision 628)
+++ branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibCommon/TypeDef.h	(revision 629)
@@ -139,5 +139,5 @@
                                               // FIX_SDC_ENC_RD_WVSO_D0163
                                               // MTK_SAMPLE_BASED_SDC_D0110
-
+#define H_3D_FCO                          1   // Flexible coding order for 3D
 
 
@@ -186,4 +186,10 @@
 #define NTT_VSP_ADAPTIVE_SPLIT_E0207      1 // adaptive sub-PU partitioning in VSP, JCT3V-E0207
 #endif
+#endif
+
+#if H_3D_FCO
+#define H_3D_FCO_VSP_DONBDV               0   // Adaptive depth reference for flexible coding order
+#else
+#define H_3D_FCO_VSP_DONBDV               0   // Adaptive depth reference for flexible coding order
 #endif
 
Index: branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibDecoder/TDecTop.cpp	(revision 628)
+++ branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibDecoder/TDecTop.cpp	(revision 629)
@@ -978,6 +978,10 @@
 #if H_3D
     pcSlice->setIvPicLists( m_ivPicLists );         
-#if H_3D_IV_MERGE    
+#if H_3D_IV_MERGE
+#if H_3D_FCO
+    //assert( !getIsDepth() );
+#else
     assert( !getIsDepth() || ( pcSlice->getTexturePic() != 0 ) );
+#endif
 #endif    
 #endif
Index: branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 628)
+++ branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 629)
@@ -913,6 +913,13 @@
 
     // SAIT_VSO_EST_A0033
+#if H_3D_FCO
+    Bool flagRec;
+    flagRec =  ((m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false, pcSlice->getPOC(), true) == NULL) ? false: true);
+    pcRdCost->setVideoRecPicYuv( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false, pcSlice->getPOC(), flagRec ) );
+    pcRdCost->setDepthPicYuv   ( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), true, pcSlice->getPOC(), false ) );
+#else
     pcRdCost->setVideoRecPicYuv( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false , pcSlice->getPOC(), true ) );
     pcRdCost->setDepthPicYuv   ( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), true  , pcSlice->getPOC(), false ) );
+#endif
 
     // LGE_WVSO_A0119
Index: branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 628)
+++ branches/HTM-8.2-dev0-MediaTek/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 629)
@@ -2866,4 +2866,11 @@
         for( UInt dmmType = 0; dmmType < DMM_NUM_TYPE; dmmType++ )
         {
+#if H_3D_FCO
+            TComPic* picTexture  = pcCU->getSlice()->getIvPic(false, pcCU->getSlice()->getViewIndex() );
+            if ( !picTexture->getReconMark() && (DMM3_IDX == dmmType || DMM4_IDX == dmmType ) )
+            {
+                continue;
+            }
+#endif
           UInt uiTabIdx = 0;
           TComWedgelet* biSegmentation = NULL;
