X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fpost.cc;fp=src%2Fpost.cc;h=b675f5b77c127b788e52de4c11136d0af53922dc;hb=3aacec4aee795e703e8eb9d6852ca47a3be065ee;hp=0000000000000000000000000000000000000000;hpb=c5c29f4044110dd153ee5ca3b018c812d518a053;p=laserbrain_demo diff --git a/src/post.cc b/src/post.cc new file mode 100644 index 0000000..b675f5b --- /dev/null +++ b/src/post.cc @@ -0,0 +1,67 @@ +#include "opengl.h" +#include "app.h" + +static void update_fbtex(); + +static unsigned int fb_tex; +static int fb_tex_width, fb_tex_height; + +void slow_post(unsigned int sdr) +{ + update_fbtex(); + + glBindTexture(GL_TEXTURE_2D, fb_tex); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_width, win_height); + + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + + glUseProgram(sdr); + + float umax = (float)win_width / (float)fb_tex_width; + float vmax = (float)win_height / (float)fb_tex_height; + + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(-1, -1); + glTexCoord2f(umax, 0); + glVertex2f(1, -1); + glTexCoord2f(umax, vmax); + glVertex2f(1, 1); + glTexCoord2f(0, vmax); + glVertex2f(-1, 1); + glEnd(); + + glPopAttrib(); +} + +static int next_pow2(int x) +{ + x--; + x = (x >> 1) | x; + x = (x >> 2) | x; + x = (x >> 4) | x; + x = (x >> 8) | x; + x = (x >> 16) | x; + return x + 1; +} + +static void update_fbtex() +{ + if(win_width <= fb_tex_width && win_height <= fb_tex_height) { + return; // nothing to do + } + if(!fb_tex) { + glGenTextures(1, &fb_tex); + glBindTexture(GL_TEXTURE_2D, fb_tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } else { + glBindTexture(GL_TEXTURE_2D, fb_tex); + } + + fb_tex_width = next_pow2(win_width); + fb_tex_height = next_pow2(win_height); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, fb_tex_width, fb_tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, 0); +}