first half-assed attempt at old wahsed-out post effect failed
[demo_prior] / src / post.c
index c1a2a23..91109b2 100644 (file)
@@ -2,6 +2,86 @@
 #include "texture.h"
 #include "post.h"
 #include "demo.h"
+#include "opt.h"
+#include "sdr.h"
+
+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 post_sdr[MAX_POST_SDR];
+
+int post_init(void)
+{
+       int i;
+       static const char *psdr_fname[] = {"sdr/oldfig.p.glsl"};
+
+       for(i=0; i<MAX_POST_SDR; i++) {
+               if(!(post_sdr[i] = create_program_load("sdr/post.v.glsl", psdr_fname[i]))) {
+                       return -1;
+               }
+       }
+
+       glGenTextures(2, post_fbtex_gltexid);
+       glGenRenderbuffers(2, rbuf_depth);
+
+       for(i=0; i<2; i++) {
+               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, post_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(post_fbtex_gltexid[0]) {
+               glDeleteTextures(2, post_fbtex_gltexid);
+       }
+       if(rbuf_depth[0]) {
+               glDeleteRenderbuffers(2, rbuf_depth);
+       }
+       if(post_fbo[0]) {
+               glDeleteFramebuffers(2, post_fbo);
+       }
+}
+
+void post_reshape(int x, int y)
+{
+       int i, ifmt;
+
+       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, post_fbtex[i].id);
+                       glTexImage2D(GL_TEXTURE_2D, 0, ifmt, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
+                       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(!post_fbo[0]) {
+                       glGenFramebuffers(2, post_fbo);
+                       for(i=0; i<2; i++) {
+                               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);
+               }
+       }
+}
 
 void overlay(unsigned int tex, float aspect, float alpha)
 {