# HG changeset patch # User John Tsiombikas # Date 1349174538 -10800 # Node ID fc2b3d06d07c00daefcc39f77e8b4d9fa17d9922 # Parent 0b130c6e534d6e14562e909311b55a9e83879b34 made the deferred renderer draw into a texture, so that I can reuse the depth buffer for geometric post effects (particles), and implement other per-pixel post effects eventually diff -r 0b130c6e534d -r fc2b3d06d07c prototype/sdr/post.p.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/prototype/sdr/post.p.glsl Tue Oct 02 13:42:18 2012 +0300 @@ -0,0 +1,6 @@ +uniform sampler2D fbtex; + +void main() +{ + gl_FragColor = texture2D(fbtex, gl_TexCoord[0].st); +} diff -r 0b130c6e534d -r fc2b3d06d07c prototype/sdr/post.v.glsl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/prototype/sdr/post.v.glsl Tue Oct 02 13:42:18 2012 +0300 @@ -0,0 +1,5 @@ +void main() +{ + gl_Position = gl_Vertex; + gl_TexCoord[0] = gl_MultiTexCoord0; +} diff -r 0b130c6e534d -r fc2b3d06d07c prototype/src/renderer_deferred.cc --- a/prototype/src/renderer_deferred.cc Tue Oct 02 05:03:26 2012 +0300 +++ b/prototype/src/renderer_deferred.cc Tue Oct 02 13:42:18 2012 +0300 @@ -9,17 +9,18 @@ #include "datapath.h" static unsigned int load_sdr(const char *vfname, const char *pfname); +static void attach_color_buffer(unsigned int fbo, int count, const unsigned int *tex); static int round_pow2(int x); DeferredRenderer::DeferredRenderer() { - fbo = rbuf_depth = 0; + fbo = rbuf_depth = rend_tex = 0; for(int i=0; idraw(); - glBindFramebufferEXT(GL_FRAMEBUFFER, 0); + + attach_color_buffer(fbo, 1, &rend_tex); + glClear(GL_COLOR_BUFFER_BIT); // post-process lighting light_pass(level); @@ -151,11 +172,30 @@ curr_prog = 0; render_post(level); + + glBindFramebufferEXT(GL_FRAMEBUFFER, 0); + + // XXX this should be moved to render_post + glBindTexture(GL_TEXTURE_2D, rend_tex); + glEnable(GL_TEXTURE_2D); + + glUseProgram(post_sdr); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2f(-1, -1); + glTexCoord2f((float)width / tex_xsz, 0); + glVertex2f(1, -1); + glTexCoord2f((float)width / tex_xsz, (float)height / tex_ysz); + glVertex2f(1, 1); + glTexCoord2f(0, (float)height / tex_ysz); + glVertex2f(-1, 1); + glEnd(); + glUseProgram(0); } void DeferredRenderer::light_pass(const Level *level) const { - glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT); + glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT | GL_TEXTURE_BIT); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); @@ -212,6 +252,15 @@ glGenFramebuffersEXT(1, &fbo); glBindFramebufferEXT(GL_FRAMEBUFFER, fbo); + // create the result render target + glGenTextures(1, &rend_tex); + glBindTexture(GL_TEXTURE_2D, rend_tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, clamp); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_xsz, tex_ysz, 0, GL_RGBA, GL_FLOAT, 0); + glGenTextures(MRT_COUNT, mrt_tex); for(int i=0; i