fixed reflections in VR
[laserbrain_demo] / src / app.cc
index 96e92f3..44c65fd 100644 (file)
@@ -15,6 +15,7 @@
 #include "opt.h"
 #include "post.h"
 #include "renderer.h"
+#include "rtarg.h"
 #include "avatar.h"
 #include "vrinput.h"
 #include "exman.h"
@@ -82,6 +83,7 @@ static ExhibitSlot exslot_left, exslot_right;
 #define exslot_mouse exslot_right
 
 static Renderer *rend;
+static RenderTarget *goatvr_rtarg;
 
 static Ray last_pick_ray;
 
@@ -123,6 +125,8 @@ bool app_init(int argc, char **argv)
                have_handtracking = goatvr_have_handtracking();
 
                goatvr_recenter();
+
+               goatvr_rtarg = new RenderTarget;
        }
 
        if(fb_srgb) {
@@ -222,6 +226,7 @@ void app_cleanup()
 
        app_grab_mouse(false);
        if(opt.vr) {
+               delete goatvr_rtarg;
                goatvr_shutdown();
        }
        destroy_vrhands();
@@ -421,14 +426,20 @@ void app_display()
                goatvr_draw_start();
                glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
+               unsigned int gfbo = goatvr_get_fbo();
+
                update(dt);
 
                for(int i=0; i<2; i++) {
                        // for each eye
                        goatvr_draw_eye(i);
-                       if(goatvr_get_fb_texture()) {
+                       if(gfbo) {
                                vp_width = goatvr_get_fb_eye_width(i);
                                vp_height = goatvr_get_fb_eye_height(i);
+
+                               // this is a lightweight operation
+                               goatvr_rtarg->create_wrap_fbo(gfbo, vp_width, vp_height);
+                               push_render_target(goatvr_rtarg, RT_FAKE);
                        } else {
                                vp_width = win_width / 2;
                        }
@@ -449,7 +460,12 @@ void app_display()
                        if(debug_gui) {
                                ImGui::Render();
                        }
+
+                       if(gfbo) {
+                               pop_render_target(RT_FAKE);
+                       }
                }
+
                goatvr_draw_done();
 
                vp_width = win_width;