dungeon_crawler
diff prototype/src/renderer.cc @ 35:d0e93b4d9ec9
normal mapping
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 28 Aug 2012 06:28:22 +0300 |
parents | 0357994effe2 |
children | 84a56fb24850 |
line diff
1.1 --- a/prototype/src/renderer.cc Tue Aug 28 03:34:56 2012 +0300 1.2 +++ b/prototype/src/renderer.cc Tue Aug 28 06:28:22 2012 +0300 1.3 @@ -9,13 +9,18 @@ 1.4 #include "sdr.h" 1.5 #include "datapath.h" 1.6 1.7 +#undef DBG_VIS_MRT 1.8 + 1.9 +#ifdef DBG_VIS_MRT 1.10 +static void deferred_debug(); 1.11 +#endif 1.12 1.13 static bool create_fbo(int xsz, int ysz); 1.14 static unsigned int load_sdr(const char *vfname, const char *pfname); 1.15 static int round_pow2(int x); 1.16 1.17 1.18 -#define MRT_COUNT 4 1.19 +#define MRT_COUNT 3 1.20 static unsigned int mrt_tex[MRT_COUNT]; 1.21 1.22 static unsigned int mrt_prog; 1.23 @@ -102,6 +107,11 @@ 1.24 return deferred_omni; 1.25 } 1.26 1.27 +int get_tangent_location(void) 1.28 +{ 1.29 + return get_attrib_loc(mrt_prog, "attr_tangent"); 1.30 +} 1.31 + 1.32 void resize_renderer(int xsz, int ysz) 1.33 { 1.34 fb_xsz = xsz; 1.35 @@ -143,6 +153,9 @@ 1.36 1.37 glBindFramebufferEXT(GL_FRAMEBUFFER, 0); 1.38 1.39 +#ifdef DBG_VIS_MRT 1.40 + deferred_debug(); 1.41 +#else 1.42 1.43 // post-process lighting 1.44 glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT); 1.45 @@ -172,12 +185,14 @@ 1.46 1.47 glUseProgram(0); 1.48 glPopAttrib(); 1.49 +#endif // DBG_VIS_MRT 1.50 } 1.51 1.52 static bool create_fbo(int xsz, int ysz) 1.53 { 1.54 - unsigned int clamp = GL_ARB_texture_border_clamp ? GL_CLAMP_TO_EDGE : GL_CLAMP; 1.55 + unsigned int clamp = GLEW_ARB_texture_border_clamp ? GL_CLAMP_TO_EDGE : GL_CLAMP; 1.56 1.57 + // round the texture size up to the next power of 2 1.58 tex_xsz = round_pow2(xsz); 1.59 tex_ysz = round_pow2(ysz); 1.60 fb_xsz = xsz; 1.61 @@ -262,3 +277,50 @@ 1.62 x = (x >> 16) | x; 1.63 return x + 1; 1.64 } 1.65 + 1.66 +#ifdef DBG_VIS_MRT 1.67 +// visualize the MRT buffers 1.68 +static void deferred_debug() 1.69 +{ 1.70 + glPushAttrib(GL_ENABLE_BIT | GL_POLYGON_BIT); 1.71 + glUseProgram(deferred_debug); 1.72 + glDisable(GL_DEPTH_TEST); 1.73 + 1.74 + glMatrixMode(GL_PROJECTION); 1.75 + glPushMatrix(); 1.76 + glLoadIdentity(); 1.77 + glMatrixMode(GL_MODELVIEW); 1.78 + glPushMatrix(); 1.79 + glLoadIdentity(); 1.80 + 1.81 + for(int i=0; i<MRT_COUNT; i++) { 1.82 + glActiveTexture(GL_TEXTURE0 + i); 1.83 + glBindTexture(GL_TEXTURE_2D, mrt_tex[i]); 1.84 + glEnable(GL_TEXTURE_2D); 1.85 + } 1.86 + 1.87 + glBegin(GL_QUADS); 1.88 + glTexCoord2f(0, 0); 1.89 + glVertex2f(-1, -1); 1.90 + glTexCoord2f(1, 0); 1.91 + glVertex2f(1, -1); 1.92 + glTexCoord2f(1, 1); 1.93 + glVertex2f(1, 1); 1.94 + glTexCoord2f(0, 1); 1.95 + glVertex2f(-1, 1); 1.96 + glEnd(); 1.97 + 1.98 + for(int i=0; i<MRT_COUNT; i++) { 1.99 + glActiveTexture(GL_TEXTURE0 + MRT_COUNT - i - 1); 1.100 + glDisable(GL_TEXTURE_2D); 1.101 + } 1.102 + 1.103 + glMatrixMode(GL_PROJECTION); 1.104 + glPopMatrix(); 1.105 + glMatrixMode(GL_MODELVIEW); 1.106 + glPopMatrix(); 1.107 + 1.108 + glUseProgram(0); 1.109 + glPopAttrib(); 1.110 +} 1.111 +#endif