void initGl() { GlfwApp::initGl(); frameBuffer.init(eyeSize); quadGeometry = GlUtils::getQuadGeometry(); distortProgram = GlUtils::getProgram( Resource::SHADERS_VERTEXTORIFT_VS, Resource::SHADERS_DIRECTDISTORT_FS); distortProgram->use(); distortProgram->setUniform("Aspect", eyeAspect); distortProgram->setUniform("PostDistortionScale", postDistortionScale); distortProgram->setUniform("K", distortionCoefficients); gl::Program::clear(); }
void draw() { glClearColor(0, 1, 0, 1); glClear(GL_COLOR_BUFFER_BIT); GL_CHECK_ERROR; for (int i = 0; i < 2; ++i) { const EyeArg & eyeArg = eyeArgs[i]; frameBuffer.activate(); renderScene(eyeArg); frameBuffer.deactivate(); glDisable(GL_DEPTH_TEST); glDisable(GL_BLEND); gl::viewport(eyeArg.viewportLocation, eyeSize); distortProgram->use(); distortProgram->setUniform("LensOffset", eyeArg.lensOffset); frameBuffer.color->bind(); quadGeometry->bindVertexArray(); quadGeometry->draw(); gl::Geometry::unbindVertexArray(); gl::Program::clear(); } }
void draw() { static int frameIndex = 0; ovrFrameTiming timing = ovrHmd_BeginFrameTiming(hmd, frameIndex++); for (int i = 0; i < 2; ++i) { const ovrEyeType eye = hmdDesc.EyeRenderOrder[i]; const EyeArg & eyeArg = eyeArgs[eye]; // Set up the per-eye projection matrix gl::Stacks::projection().top() = eyeArg.projection; eyeArg.frameBuffer.activate(); gl::MatrixStack & mv = gl::Stacks::modelview(); gl::Stacks::with_push([&]{ ovrSensorState ss = ovrHmd_GetSensorState(hmd, timing.EyeScanoutSeconds[eye]); // Set up the per-eye modelview matrix // Apply the head pose mv.preMultiply(glm::inverse(Rift::fromOvr(ss.Predicted.Pose))); // Apply the per-eye offset mv.preMultiply(eyeArg.viewOffset); renderScene(); }); eyeArg.frameBuffer.deactivate(); } glClearColor(0, 0, 1, 1); glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_BLEND); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); distortionProgram->use(); glViewport(0, 0, windowSize.x, windowSize.y); for_each_eye([&](ovrEyeType eye) { const EyeArg & eyeArg = eyeArgs[eye]; distortionProgram->setUniform(0, eyeArg.scale); distortionProgram->setUniform(1, eyeArg.offset); eyeArg.frameBuffer.color->bind(); eyeArg.meshVao->bind(); glDrawElements(GL_TRIANGLES, eyeArg.mesh.IndexCount, GL_UNSIGNED_SHORT, nullptr); }); gl::Texture2d::unbind(); gl::Program::clear(); ovrHmd_EndFrameTiming(hmd); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); }
void renderLatencyTestSquare() { OVR::Color colorToDisplay; // If this returns a non-0 value, we're performing a latency // test and must render a colored square underneath the tester // (On the lens axis) if (ovrLatencyTest.DisplayScreenColor(colorToDisplay)) { latencyTestProgram->use(); latencyTestProgram->setUniform("Color", Rift::fromOvr(colorToDisplay)); gl::MatrixStack & mv = gl::Stacks::modelview(); glDisable(GL_DEPTH_TEST); mv.with_push([&]{ mv.identity().translate(glm::vec3(0, 0, -0.1f)).scale(0.005f); GlUtils::renderGeometry(latencyTestQuad, latencyTestProgram); }); glEnable(GL_DEPTH_TEST); } }