Skip to content
Snippets Groups Projects
Commit 4a23bae0 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Re order frame rendering and fix fps

parent 8fac622e
No related branches found
No related tags found
1 merge request!266Resolve VR performance problems
Pipeline #21568 passed
......@@ -80,6 +80,7 @@ ftl::gui::Camera::Camera(ftl::gui::Screen *screen, int fsmask, int fid, ftl::cod
stereo_ = false;
rx_ = 0;
ry_ = 0;
framesets_ = nullptr;
colouriser_ = ftl::create<ftl::render::Colouriser>(screen->root(), "colouriser");
......@@ -385,6 +386,8 @@ void ftl::gui::Camera::update(int fsid, const ftl::codecs::Channels<0> &c) {
void ftl::gui::Camera::update(std::vector<ftl::rgbd::FrameSet*> &fss) {
UNIQUE_LOCK(mutex_, lk);
framesets_ = &fss;
//if (fss.size() <= fsid_) return;
if (fid_ == 255) {
name_ = "Virtual Camera";
......@@ -587,16 +590,21 @@ void ftl::gui::Camera::active(bool a) {
}
}
const GLTexture &ftl::gui::Camera::captureFrame() {
const void ftl::gui::Camera::captureFrame() {
float now = (float)glfwGetTime();
if (!screen_->isVR() && (now - ftime_) < 0.04f) return;
delta_ = now - ftime_;
ftime_ = now;
LOG(INFO) << "Frame delta: " << delta_;
//if (src_ && src_->isReady()) {
if (width_ > 0 && height_ > 0) {
if (screen_->isVR()) {
#ifdef HAVE_OPENVR
vr::VRCompositor()->SetTrackingSpace(vr::TrackingUniverseStanding);
vr::VRCompositor()->WaitGetPoses(rTrackedDevicePose_, vr::k_unMaxTrackedDeviceCount, NULL, 0 );
if (isStereo() && rTrackedDevicePose_[vr::k_unTrackedDeviceIndex_Hmd].bPoseIsValid )
......@@ -637,8 +645,8 @@ const GLTexture &ftl::gui::Camera::captureFrame() {
} else {
// Use mouse to move camera
float rrx = ((float)ry_ * 1.0f * delta_);
float rry = (float)rx_ * 1.0f * delta_;
float rrx = ((float)ry_ * 0.2f * delta_);
float rry = (float)rx_ * 0.2f * delta_;
float rrz = 0.0;
......@@ -657,6 +665,7 @@ const GLTexture &ftl::gui::Camera::captureFrame() {
Eigen::Affine3d t(trans);
Eigen::Matrix4d viewPose = t.matrix() * rotmat_;
{
UNIQUE_LOCK(mutex_, lk);
if (isVirtual()) {
......@@ -666,8 +675,12 @@ const GLTexture &ftl::gui::Camera::captureFrame() {
transforms_[transform_ix_] = viewPose;
}
}
}
if (framesets_) draw(*framesets_);
if (!new_frame_.test_and_set()) {
{
//UNIQUE_LOCK(mutex_, lk);
if (im1_.rows != 0) {
texture1_.update(im1_);
}
......@@ -677,7 +690,7 @@ const GLTexture &ftl::gui::Camera::captureFrame() {
}
}
return texture1_;
//return texture1_;
}
void ftl::gui::Camera::snapshot(const std::string &filename) {
......
......@@ -74,7 +74,7 @@ class Camera {
*/
void active(bool);
const GLTexture &captureFrame();
const void captureFrame();
const GLTexture &getLeft() const { return texture1_; }
const GLTexture &getRight() const { return texture2_; }
......@@ -132,6 +132,7 @@ class Camera {
std::atomic_flag new_frame_;
int rx_;
int ry_;
std::vector<ftl::rgbd::FrameSet*> *framesets_;
ftl::render::CUDARender *renderer_;
ftl::render::CUDARender *renderer2_;
......
......@@ -56,11 +56,13 @@ int main(int argc, char **argv) {
float now = (float)glfwGetTime();
float delta = now - last_draw_time;
// Do VR update here, as fast as possible.
// Generate poses and render and virtual frame here
// at full FPS (25 without VR and 90 with VR currently)
app->drawFast();
last_vr_time = now;
if (delta >= 0.05f) {
// Only draw the GUI at 25fps
if (delta >= 0.04f) {
last_draw_time = now;
app->drawAll();
}
......
......@@ -48,6 +48,8 @@ class SourceWindow : public nanogui::Window {
void recordVideo(const std::string &filename);
void stopRecordingVideo();
inline std::vector<ftl::rgbd::FrameSet*> &getFramesets() { return framesets_; }
inline void paused(bool p) { paused_ = p; }
private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment