X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fdemo.c;h=a4bb0c70fd8f7462638b11c90f6343ddcaeb2942;hb=5eefe7b94c8d6c6caa2c10e3835ab0831a3c42a1;hp=d0b11271e08f0c789c4525a1e3d44c5c2ef7c690;hpb=6a752049e496c93a61e0130348f71888583d743c;p=demo_prior diff --git a/src/demo.c b/src/demo.c index d0b1127..a4bb0c7 100644 --- a/src/demo.c +++ b/src/demo.c @@ -2,6 +2,9 @@ #include "opengl.h" #include "demo.h" #include "part.h" +#include "post.h" +#include "sdr.h" +#include "opt.h" void reg_whitted(void); @@ -9,6 +12,8 @@ int win_width, win_height; float win_aspect; long time_msec; +static int reshape_pending; +static unsigned int sdr_gamma; int demo_init(void) { @@ -20,8 +25,18 @@ int demo_init(void) glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); - glEnable(GL_FRAMEBUFFER_SRGB); - glEnable(GL_MULTISAMPLE); + if(opt.srgb) { + glEnable(GL_FRAMEBUFFER_SRGB); + } + if(opt.msaa) { + glEnable(GL_MULTISAMPLE); + } + + post_init(); + + if(!(sdr_gamma = create_program_load("sdr/post.v.glsl", "sdr/gamma.p.glsl"))) { + fprintf(stderr, "Warning: failed to load the gamma correction shader\n"); + } reg_whitted(); @@ -40,6 +55,11 @@ void demo_cleanup(void) { int i; + if(sdr_gamma) { + glDeleteProgram(sdr_gamma); + } + post_cleanup(); + for(i=0; idestroy(); } @@ -49,6 +69,11 @@ void demo_display(void) { long part_time; + if(reshape_pending) { + post_reshape(win_width, win_height); + reshape_pending = 0; + } + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(!cur_part) return; @@ -75,10 +100,21 @@ void demo_display(void) prev_part = 0; cur_part->draw(part_time); } + + /* no-srgb gamma correction fallback */ + if(!opt.srgb) { + glBindTexture(GL_TEXTURE_2D, post_fbtex[0].id); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_width, win_height); + + glUseProgram(sdr_gamma); + overlay_tex(post_fbtex, 1.0); + } } void demo_reshape(int x, int y) { + reshape_pending = 1; + win_width = x; win_height = y; win_aspect = (float)x / (float)y;