X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=demo_prior;a=blobdiff_plain;f=src%2Fpost.c;h=b78284af298775818c6e2bb1c95a155b53bb9ef4;hp=c1a2a2304df540cc2aa47e0c99a1f3b01bafac34;hb=ca5ddcfae04b0c10505325629d8a59e626811433;hpb=f949c0b80e6e55b95f9fd5a2949eb644e8356dba diff --git a/src/post.c b/src/post.c index c1a2a23..b78284a 100644 --- a/src/post.c +++ b/src/post.c @@ -1,7 +1,76 @@ +#include #include "opengl.h" #include "texture.h" #include "post.h" #include "demo.h" +#include "opt.h" + +static unsigned int fbtex_gltexid[2]; +static unsigned int fbo[2], rbuf_depth[2]; +struct texture fbtex[2]; +int fbtex_cur; + +int post_init(void) +{ + int i; + + glGenTextures(2, fbtex_gltexid); + glGenRenderbuffers(2, rbuf_depth); + + for(i=0; i<2; i++) { + fbtex[i].id = fbtex_gltexid[i]; + fbtex[i].width = 0; + fbtex[i].height = 0; + fbtex[i].pixels = 0; + + glBindTexture(GL_TEXTURE_2D, fbtex[i].id); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } + return 0; +} + +void post_cleanup(void) +{ + if(fbtex_gltexid[0]) { + glDeleteTextures(2, fbtex_gltexid); + } + if(rbuf_depth[0]) { + glDeleteRenderbuffers(2, rbuf_depth); + } + if(fbo[0]) { + glDeleteFramebuffers(2, fbo); + } +} + +void post_reshape(int x, int y) +{ + int i, ifmt; + + if(x != fbtex[0].width || y != fbtex[0].height) { + ifmt = opt.srgb ? GL_SRGB_ALPHA : GL_RGBA; + + for(i=0; i<2; i++) { + glBindTexture(GL_TEXTURE_2D, fbtex[i].id); + glTexImage2D(GL_TEXTURE_2D, 0, ifmt, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); + fbtex[i].width = x; + fbtex[i].height = y; + + glBindRenderbuffer(GL_RENDERBUFFER, rbuf_depth[i]); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, x, y); + } + + if(!fbo[0]) { + glGenFramebuffers(2, fbo); + for(i=0; i<2; i++) { + glBindFramebuffer(GL_FRAMEBUFFER, fbo[i]); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbtex_gltexid[i], 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbuf_depth[i]); + } + glBindFramebuffer(GL_FRAMEBUFFER, 0); + } + } +} void overlay(unsigned int tex, float aspect, float alpha) {