X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=vrfileman;a=blobdiff_plain;f=src%2Fapp.cc;h=f0757618ebcbacef0660cd8ec54acdc344778489;hp=f5b98947a863a2ea5d9e07a533bbcc91be85e41e;hb=ebd0d12fd6cbfc6bc76f14a1746c46dd47ae5243;hpb=d032f000a796aab8654fa13bcb84f2393f16cb65 diff --git a/src/app.cc b/src/app.cc index f5b9894..f075761 100644 --- a/src/app.cc +++ b/src/app.cc @@ -9,6 +9,9 @@ #include "goatvr.h" #include "opt.h" #include "fs.h" +#include "rtarg.h" +#include "texture.h" +#include "sdr.h" static void draw_scene(); @@ -18,16 +21,21 @@ long time_msec; double time_sec; Mat4 view_matrix; -static bool should_swap; +float cam_height = 1.65; static float cam_theta, cam_phi; -static float cam_height = 1.65; +static bool should_swap; static bool bnstate[16]; static int prev_x, prev_y; static float fov = 60.0; +static RenderTarget *rtarg; +static bool rtarg_valid; +static unsigned int post_sdr; + + bool app_init(int argc, char **argv) { if(!init_options(argc, argv, "vrfileman.conf")) { @@ -56,6 +64,9 @@ bool app_init(int argc, char **argv) glEnable(GL_FRAMEBUFFER_SRGB); } + rtarg = new RenderTarget; + rtarg->create(GL_RGB16F); + if(opt.vr) { if(goatvr_init() == -1) { return false; @@ -65,7 +76,19 @@ bool app_init(int argc, char **argv) goatvr_startvr(); should_swap = goatvr_should_swap() != 0; cam_height = goatvr_get_eye_height(); + + RenderTarget::default_fbo = goatvr_get_fbo(); + } + + if(opt.srgb) { + add_shader_header(GL_FRAGMENT_SHADER, "#define set_pixel set_pixel_linear"); + } else { + add_shader_header(GL_FRAGMENT_SHADER, "#define set_pixel set_pixel_srgb"); + } + if(!(post_sdr = create_program_load("sdr/post.v.glsl", "sdr/post.p.glsl"))) { + return false; } + clear_shader_header(0); Mesh::use_custom_sdr_attr = false; @@ -85,11 +108,22 @@ void app_cleanup() if(opt.vr) { goatvr_shutdown(); } + delete rtarg; + free_program(post_sdr); cleanup_backdrop(); } +static void update() +{ + if(!rtarg_valid) { + rtarg->resize(win_width, win_height); + } +} + void app_draw() { + update(); + if(opt.vr) { // VR mode goatvr_draw_start(); @@ -145,13 +179,47 @@ void app_draw() static void draw_scene() { + if(!opt.vr) { + set_render_target(rtarg); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + draw_backdrop(); draw_fs(); + + if(!opt.vr) { + set_render_target(0); + + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_DEPTH_TEST); + + glUseProgram(post_sdr); + set_uniform_matrix4(post_sdr, "texmat", rtarg->get_texture_matrix()[0]); + + bind_texture(rtarg->get_texture()); + + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(-1, -1); + glTexCoord2f(1, 0); + glVertex2f(1, -1); + glTexCoord2f(1, 1); + glVertex2f(1, 1); + glTexCoord2f(0, 1); + glVertex2f(-1, 1); + glEnd(); + + bind_texture(0); + glUseProgram(0); + + glPopAttrib(); + } } void app_reshape(int x, int y) { glViewport(0, 0, x, y); + rtarg_valid = false; if(opt.vr) { goatvr_set_fb_size(x, y, 1.0);