//private long frameCount = 0; IEnumerator EndOfFrame() { //frameCount = 0; MojingLog.LogTrace("Enter Mojing.EndOfFrame thread"); while (true) { yield return(new WaitForEndOfFrame()); if ((!bWaitForMojingWord) && VRModeEnabled && NeedDistortion) { if (m_bResetTextureId) { int tID = MojingRender.StereoScreen[0].GetNativeTextureID(); int sID = MojingRender.StereoScreen[1].GetNativeTextureID(); if (tID == 0 || sID == 0) { // Skip a frame, the old texture id is invalid and no new texture id to use //MojingLog.LogTrace("Skip a frame since texture id is zero: " + tID + "," + sID); m_bResetTextureId = true; } else { if (_Last_left_TextureID != tID || _Last_right_TextureID != sID) { _Last_left_TextureID = tID; _Last_right_TextureID = sID; } //MojingLog.LogTrace("Set Texture ID: " + _Last_left_TextureID + "," + _Last_right_TextureID); MojingSDK.SetTextureID(_Last_left_TextureID, _Last_right_TextureID); MojingSDK.Unity_DistortFrame(); if (--m_ResetCount == 0) { m_bResetTextureId = false; } } } else { //MojingLog.LogTrace("Read Texture ID = " + tID + ", " + sID + " while set Texture ID: " + _Last_left_TextureID + "," + _Last_right_TextureID); MojingSDK.SetTextureID(_Last_left_TextureID, _Last_right_TextureID); MojingSDK.Unity_DistortFrame(); } } } //MojingLog.LogTrace("Leave Mojing.EndOfFrame thread"); }
IEnumerator EndOfFrame() { MojingLog.LogTrace("Enter Mojing.EndOfFrame thread"); while (true) { yield return(waitForEndOfFrame); if ((!bWaitForMojingWord) && MojingVRHead.Instance.VRModeEnabled && NeedDistortion) { getTextureID(iFrameIndex); MojingSDK.SetTextureID(tID, sID); MojingSDK.Unity_DistortFrame(); #if UNITY_ANDROID // iOS 不启用三缓冲 iFrameIndex = ++iFrameIndex % (screenNum / 2); #endif } } //MojingLog.LogTrace("Leave Mojing.EndOfFrame thread"); }
//private long frameCount = 0; IEnumerator EndOfFrame() { //frameCount = 0; MojingLog.LogTrace("Enter Mojing.EndOfFrame thread"); while (true) { yield return(new WaitForEndOfFrame()); if ((!bWaitForMojingWord) && VRModeEnabled && NeedDistortion) { LCamera.Render(); RCamera.Render(); if (MojingSDK.Unity_IsATW_ON() || m_bResetTextureId) { int iFrameIndex = 0; if (MojingSDK.Unity_IsATW_ON()) { iFrameIndex = MojingSDK.Unity_ATW_GetModelFrameIndex(); MojingLog.LogTrace("ATW: get iFrameIndex = " + iFrameIndex); } int tID = (int)MojingRender.StereoScreen[iFrameIndex * 2].GetNativeTexturePtr(); int sID = (int)MojingRender.StereoScreen[iFrameIndex * 2 + 1].GetNativeTexturePtr(); IntPtr tID_Metal = MojingRender.StereoScreen[iFrameIndex * 2].colorBuffer.GetNativeRenderBufferPtr(); IntPtr sID_Metal = MojingRender.StereoScreen[iFrameIndex * 2 + 1].colorBuffer.GetNativeRenderBufferPtr(); if (tID == 0 || sID == 0 || tID_Metal == IntPtr.Zero || sID_Metal == IntPtr.Zero) { // Skip a frame, the old texture id is invalid and no new texture id to use //MojingLog.LogTrace("Skip a frame since texture id is zero: " + tID + "," + sID); m_bResetTextureId = true; } else { if (_Last_left_TextureID != tID || _Last_right_TextureID != sID) { _Last_left_TextureID = tID; _Last_right_TextureID = sID; } if (_Last_left_TextureID_Metal != tID_Metal || _Last_right_TextureID_Metal != sID_Metal) { _Last_left_TextureID_Metal = tID_Metal; _Last_right_TextureID_Metal = sID_Metal; } //MojingLog.LogTrace("Set Texture ID: " + _Last_left_TextureID + "," + _Last_right_TextureID); #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_ANDROID if (MojingSDK.Unity_IsATW_ON() || MojingSDK.Unity_IsInterFBRPlatform()) { MojingSDK.ATW_SetTextureID(_Last_left_TextureID, _Last_right_TextureID, headView); } else { MojingSDK.SetTextureID(_Last_left_TextureID, _Last_right_TextureID); } #elif UNITY_IOS if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Metal) { MojingSDK.SetTextureID_Metal(tID_Metal, sID_Metal); } else { MojingSDK.SetTextureID(tID, sID); } #endif MojingSDK.Unity_DistortFrame(); if (!MojingSDK.Unity_IsATW_ON() && --m_ResetCount == 0) { m_bResetTextureId = false; } } } else { //MojingLog.LogTrace("Read Texture ID = " + tID + ", " + sID + " while set Texture ID: " + _Last_left_TextureID + "," + _Last_right_TextureID); #if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_ANDROID if (MojingSDK.Unity_IsATW_ON() || MojingSDK.Unity_IsInterFBRPlatform()) { MojingSDK.ATW_SetTextureID(_Last_left_TextureID, _Last_right_TextureID, headView); } else { MojingSDK.SetTextureID(_Last_left_TextureID, _Last_right_TextureID); } #elif UNITY_IOS if (SystemInfo.graphicsDeviceType == UnityEngine.Rendering.GraphicsDeviceType.Metal) { MojingSDK.SetTextureID_Metal(_Last_left_TextureID_Metal, _Last_right_TextureID_Metal); } else { MojingSDK.SetTextureID(_Last_left_TextureID, _Last_right_TextureID); } #endif MojingSDK.Unity_DistortFrame(); } } } //MojingLog.LogTrace("Leave Mojing.EndOfFrame thread"); }