[SOLVED]Rendering lags if no double commit texture swap chain in the render pass
Hi,
I got something strange since I upgraded my Engine to support the new SDK 1.3. I'm working with the DK2.
When I move my head, the tracking randomly lags. I fix it by calling twice "ovr_CommitTextureSwapChain(session, textureChain);" before to submit the frame to the Rift. It's quite strange because the OculusRoomTinyGL works well with just one commit. :/
I have two differences with the Oculus' sample:
- I render stereo views in the same buffer instead of two separated;
- I call "ovr_Initialize", "ovr_Create" and "ovr_GetHmdDesc" from the main thread and everything else from another thread (the "engine's thread")
To retrieve the Pose, I tried two methods:
I checked if the compositor was dropping some frames during lags, but not, everything is fine at 75Hz.
My code is wrong somewhere but I don't understand where. Any suggestions, please?
Here's my rendering code:
Here's my code to submit my frames:
I got something strange since I upgraded my Engine to support the new SDK 1.3. I'm working with the DK2.
When I move my head, the tracking randomly lags. I fix it by calling twice "ovr_CommitTextureSwapChain(session, textureChain);" before to submit the frame to the Rift. It's quite strange because the OculusRoomTinyGL works well with just one commit. :/
I have two differences with the Oculus' sample:
- I render stereo views in the same buffer instead of two separated;
- I call "ovr_Initialize", "ovr_Create" and "ovr_GetHmdDesc" from the main thread and everything else from another thread (the "engine's thread")
To retrieve the Pose, I tried two methods:
#ifdef POSE_METHOD1
double ftiming = ovr_GetPredictedDisplayTime(session_, frameIndex_);
ovrTrackingState hmdState = ovr_GetTrackingState(session_, ftiming, ovrTrue);
ovr_CalcEyePoses(hmdState.HeadPose.ThePose, hmdToEyeOffset, eyeRenderPose);
#else
double sensorSampleTime;no difference.
ovr_GetEyePoses(session_, frameIndex_, ovrTrue, hmdToEyeOffset, eyeRenderPose, &sensorSampleTime);
#endif
I checked if the compositor was dropping some frames during lags, but not, everything is fine at 75Hz.
My code is wrong somewhere but I don't understand where. Any suggestions, please?
Here's my rendering code:
GLuint curTexId;
int curIndex;
ovr_GetTextureSwapChainCurrentIndex(session, textureChain, &curIndex);
ovr_GetTextureSwapChainBufferGL(session, textureChain, curIndex, &curTexId);
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, curTexId, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, dbuffer->texId, 0);
glViewport(0, 0, texSize.w, texSize.h);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// ... do render stereo views
glBindFramebuffer(GL_FRAMEBUFFER, fboId);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
ovr_CommitTextureSwapChain(session, textureChain);
//ovr_CommitTextureSwapChain(session, textureChain); // two commits fix the issue..
Here's my code to submit my frames:
ovrLayerEyeFov ld;
ld.Header.Type = ovrLayerType_EyeFov;
ld.Header.Flags = ovrLayerFlag_HighQuality | ovrLayerFlag_TextureOriginAtBottomLeft;
OVR::Sizei size = eyeRenderTexture_->getSize();
OVR::Recti vpL(0, 0, size.w / 2, size.h);
OVR::Recti vpR(vpL.w, 0, vpL.w, vpL.h);
for (int eye = 0; eye < 2; ++eye)
{
ld.ColorTexture[eye] = eyeRenderTexture_->textureChain;
ld.Viewport[eye] = eye == ovrEye_Left ? vpL : vpR;
ld.Fov[eye] = hmdDesc_.DefaultEyeFov[eye];
ld.RenderPose[eye] = eyeRenderPose[eye];
#ifdef POSE_METHOD1
ld.SensorSampleTime = ovr_GetTimeInSeconds();
#else
ld.SensorSampleTime = sensorSampleTime;
#endif
}
ovrLayerHeader* layers = &ld.Header;
ovrResult result = ovr_SubmitFrame(session_, frameIndex_, nullptr, &layers, 1);
