X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fpost.c;h=994c93e12c16f674861cf3070e731e2596896a66;hb=7f33f4df3bdd41375f215548adc8016a55f03472;hp=b78284af298775818c6e2bb1c95a155b53bb9ef4;hpb=ca5ddcfae04b0c10505325629d8a59e626811433;p=demo_prior diff --git a/src/post.c b/src/post.c index b78284a..994c93e 100644 --- a/src/post.c +++ b/src/post.c @@ -1,29 +1,43 @@ -#include #include "opengl.h" #include "texture.h" #include "post.h" #include "demo.h" #include "opt.h" +#include "sdr.h" -static unsigned int fbtex_gltexid[2]; -static unsigned int fbo[2], rbuf_depth[2]; -struct texture fbtex[2]; -int fbtex_cur; +static unsigned int post_fbtex_gltexid[2]; +static unsigned int rbuf_depth[2]; + +unsigned int post_fbo[2]; +struct texture post_fbtex[2]; +int post_fbtex_cur; + +unsigned int sdr_vgn; +int vgn_uloc_color, vgn_uloc_offs, vgn_uloc_sharp; int post_init(void) { int i; - glGenTextures(2, fbtex_gltexid); + if(!(sdr_vgn = create_program_load("sdr/post.v.glsl", "sdr/vignette.p.glsl"))) { + return -1; + } + glUseProgram(sdr_vgn); + vgn_uloc_color = get_uniform_loc(sdr_vgn, "color"); + vgn_uloc_offs = get_uniform_loc(sdr_vgn, "offset"); + vgn_uloc_sharp = get_uniform_loc(sdr_vgn, "sharpness"); + + + glGenTextures(2, post_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; + post_fbtex[i].id = post_fbtex_gltexid[i]; + post_fbtex[i].width = 0; + post_fbtex[i].height = 0; + post_fbtex[i].pixels = 0; - glBindTexture(GL_TEXTURE_2D, fbtex[i].id); + glBindTexture(GL_TEXTURE_2D, post_fbtex[i].id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } @@ -32,14 +46,18 @@ int post_init(void) void post_cleanup(void) { - if(fbtex_gltexid[0]) { - glDeleteTextures(2, fbtex_gltexid); + if(post_fbtex_gltexid[0]) { + glDeleteTextures(2, post_fbtex_gltexid); } if(rbuf_depth[0]) { glDeleteRenderbuffers(2, rbuf_depth); } - if(fbo[0]) { - glDeleteFramebuffers(2, fbo); + if(post_fbo[0]) { + glDeleteFramebuffers(2, post_fbo); + } + + if(sdr_vgn) { + free_program(sdr_vgn); } } @@ -47,24 +65,24 @@ void post_reshape(int x, int y) { int i, ifmt; - if(x != fbtex[0].width || y != fbtex[0].height) { + if(x != post_fbtex[0].width || y != post_fbtex[0].height) { ifmt = opt.srgb ? GL_SRGB_ALPHA : GL_RGBA; for(i=0; i<2; i++) { - glBindTexture(GL_TEXTURE_2D, fbtex[i].id); + glBindTexture(GL_TEXTURE_2D, post_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; + post_fbtex[i].width = x; + post_fbtex[i].height = y; glBindRenderbuffer(GL_RENDERBUFFER, rbuf_depth[i]); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, x, y); } - if(!fbo[0]) { - glGenFramebuffers(2, fbo); + if(!post_fbo[0]) { + glGenFramebuffers(2, post_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); + glBindFramebuffer(GL_FRAMEBUFFER, post_fbo[i]); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, post_fbtex_gltexid[i], 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbuf_depth[i]); } glBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -89,19 +107,23 @@ void overlay(unsigned int tex, float aspect, float alpha) glDisable(GL_LIGHTING); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, tex); + if(tex) { + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, tex); + } else { + glDisable(GL_TEXTURE_2D); + } glBegin(GL_QUADS); glColor4f(1, 1, 1, alpha); - glTexCoord2f(0, 1); + glTexCoord2f(0, 0); glVertex2f(-1, -1); - glTexCoord2f(1, 1); - glVertex2f(1, -1); glTexCoord2f(1, 0); + glVertex2f(1, -1); + glTexCoord2f(1, 1); glVertex2f(1, 1); - glTexCoord2f(0, 0); + glTexCoord2f(0, 1); glVertex2f(-1, 1); glEnd(); @@ -114,5 +136,29 @@ void overlay(unsigned int tex, float aspect, float alpha) void overlay_tex(struct texture *tex, float alpha) { - overlay(tex->id, (float)tex->width / tex->height, alpha); + unsigned int tid; + float aspect; + if(tex) { + tid = tex->id; + aspect = (float)tex->width / tex->height; + } else { + tid = 0; + aspect = 1.0f; + } + overlay(tid, aspect, alpha); +} + +void vignette(float r, float g, float b, float offs, float sharp) +{ + glUseProgram(sdr_vgn); + if(vgn_uloc_color >= 0) { + glUniform3f(vgn_uloc_color, r, g, b); + } + if(vgn_uloc_offs >= 0) { + glUniform1f(vgn_uloc_offs, offs); + } + if(vgn_uloc_sharp >= 0) { + glUniform1f(vgn_uloc_sharp, sharp); + } + overlay(0, 1.0, 1.0); }