X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=demo_prior;a=blobdiff_plain;f=src%2Fdemo.c;fp=src%2Fdemo.c;h=97da53671ab39de8ed363d4cb04671f9a0ce6592;hp=d0b11271e08f0c789c4525a1e3d44c5c2ef7c690;hb=8d209f332b7ac731aae8b7b46fc3b5622b713100;hpb=428b43168541e68f3fef76daa90153ee2e126c9a diff --git a/src/demo.c b/src/demo.c index d0b1127..97da536 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,9 @@ int win_width, win_height; float win_aspect; long time_msec; +static int reshape_pending; +static unsigned int fbtex; +static unsigned int sdr_gamma; int demo_init(void) { @@ -23,6 +29,18 @@ int demo_init(void) glEnable(GL_FRAMEBUFFER_SRGB); glEnable(GL_MULTISAMPLE); + glGenTextures(1, &fbtex); + glBindTexture(GL_TEXTURE_2D, fbtex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + if(win_width) { + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win_width, win_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); + } + + if(!(sdr_gamma = create_program_load("sdr/gamma.v.glsl", "sdr/gamma.p.glsl"))) { + fprintf(stderr, "Warning: failed to load the gamma correction shader\n"); + } + reg_whitted(); for(i=0; idestroy(); } @@ -49,6 +74,13 @@ void demo_display(void) { long part_time; + if(reshape_pending) { + /* reshape fbtex */ + glBindTexture(GL_TEXTURE_2D, fbtex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win_width, win_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); + reshape_pending = 1; + } + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(!cur_part) return; @@ -75,10 +107,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, fbtex); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_width, win_height); + + glUseProgram(sdr_gamma); + overlay(fbtex, win_aspect, 1.0); + } } void demo_reshape(int x, int y) { + reshape_pending = 1; + win_width = x; win_height = y; win_aspect = (float)x / (float)y;