8 static unsigned int post_fbtex_gltexid[2];
9 static unsigned int rbuf_depth[2];
11 unsigned int post_fbo[2];
12 struct texture post_fbtex[2];
16 int vgn_uloc_color, vgn_uloc_offs, vgn_uloc_sharp;
22 if(!(sdr_vgn = create_program_load("sdr/post.v.glsl", "sdr/vignette.p.glsl"))) {
25 glUseProgram(sdr_vgn);
26 vgn_uloc_color = get_uniform_loc(sdr_vgn, "color");
27 vgn_uloc_offs = get_uniform_loc(sdr_vgn, "offset");
28 vgn_uloc_sharp = get_uniform_loc(sdr_vgn, "sharpness");
31 glGenTextures(2, post_fbtex_gltexid);
32 glGenRenderbuffers(2, rbuf_depth);
35 post_fbtex[i].id = post_fbtex_gltexid[i];
36 post_fbtex[i].width = 0;
37 post_fbtex[i].height = 0;
38 post_fbtex[i].pixels = 0;
40 glBindTexture(GL_TEXTURE_2D, post_fbtex[i].id);
41 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
42 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
47 void post_cleanup(void)
49 if(post_fbtex_gltexid[0]) {
50 glDeleteTextures(2, post_fbtex_gltexid);
53 glDeleteRenderbuffers(2, rbuf_depth);
56 glDeleteFramebuffers(2, post_fbo);
60 free_program(sdr_vgn);
64 void post_reshape(int x, int y)
68 if(x != post_fbtex[0].width || y != post_fbtex[0].height) {
69 ifmt = opt.srgb ? GL_SRGB_ALPHA : GL_RGBA;
72 glBindTexture(GL_TEXTURE_2D, post_fbtex[i].id);
73 glTexImage2D(GL_TEXTURE_2D, 0, ifmt, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
74 post_fbtex[i].width = x;
75 post_fbtex[i].height = y;
77 glBindRenderbuffer(GL_RENDERBUFFER, rbuf_depth[i]);
78 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, x, y);
82 glGenFramebuffers(2, post_fbo);
84 glBindFramebuffer(GL_FRAMEBUFFER, post_fbo[i]);
85 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, post_fbtex_gltexid[i], 0);
86 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbuf_depth[i]);
88 glBindFramebuffer(GL_FRAMEBUFFER, 0);
93 void overlay(unsigned int tex, float aspect, float alpha)
95 float xscale = aspect / win_aspect;
97 glMatrixMode(GL_MODELVIEW);
100 glMatrixMode(GL_PROJECTION);
103 glScalef(xscale, 1.0, 1.0);
105 glPushAttrib(GL_ENABLE_BIT);
106 glDisable(GL_DEPTH_TEST);
107 glDisable(GL_LIGHTING);
109 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
112 glEnable(GL_TEXTURE_2D);
113 glBindTexture(GL_TEXTURE_2D, tex);
115 glDisable(GL_TEXTURE_2D);
119 glColor4f(1, 1, 1, alpha);
133 glMatrixMode(GL_MODELVIEW);
137 void overlay_tex(struct texture *tex, float alpha)
143 aspect = (float)tex->width / tex->height;
148 overlay(tid, aspect, alpha);
151 void vignette(float r, float g, float b, float offs, float sharp)
153 glUseProgram(sdr_vgn);
154 if(vgn_uloc_color >= 0) {
155 glUniform3f(vgn_uloc_color, r, g, b);
157 if(vgn_uloc_offs >= 0) {
158 glUniform1f(vgn_uloc_offs, offs);
160 if(vgn_uloc_sharp >= 0) {
161 glUniform1f(vgn_uloc_sharp, sharp);
163 overlay(0, 1.0, 1.0);