dungeon_crawler

changeset 72:a27528035e20

- re-organized the renderer classes a bit wrt final render-target - implemented identity color-grading palette for now - broke particle systems.... - removed multipass renderer
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 19 Oct 2012 02:45:57 +0300
parents e198e94435c8
children 67d330038629
files prototype/sdr/post.p.glsl prototype/src/colgrade.cc prototype/src/colgrade.h prototype/src/main.cc prototype/src/renderer.cc prototype/src/renderer.h prototype/src/renderer_deferred.cc prototype/src/renderer_deferred.h prototype/src/renderer_multipass.cc prototype/src/renderer_multipass.h
diffstat 10 files changed, 286 insertions(+), 258 deletions(-) [+]
line diff
     1.1 --- a/prototype/sdr/post.p.glsl	Tue Oct 16 04:08:35 2012 +0300
     1.2 +++ b/prototype/sdr/post.p.glsl	Fri Oct 19 02:45:57 2012 +0300
     1.3 @@ -1,6 +1,10 @@
     1.4  uniform sampler2D fbtex;
     1.5 +uniform sampler3D paltex;
     1.6  
     1.7  void main()
     1.8  {
     1.9 -	gl_FragColor = texture2D(fbtex, gl_TexCoord[0].st);
    1.10 +	// lookup the render output color for this pixel
    1.11 +	vec4 color = texture2D(fbtex, gl_TexCoord[0].st);
    1.12 +	// use that color as an index into the palette
    1.13 +	gl_FragColor = vec4(texture3D(paltex, color.xyz).xyz, color.a);
    1.14  }
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/prototype/src/colgrade.cc	Fri Oct 19 02:45:57 2012 +0300
     2.3 @@ -0,0 +1,74 @@
     2.4 +#include <stdio.h>
     2.5 +#include "opengl.h"
     2.6 +#include "colgrade.h"
     2.7 +
     2.8 +GradePalette::GradePalette()
     2.9 +{
    2.10 +	tex = 0;
    2.11 +}
    2.12 +
    2.13 +GradePalette::~GradePalette()
    2.14 +{
    2.15 +	destroy();
    2.16 +}
    2.17 +
    2.18 +bool GradePalette::create(int sz)
    2.19 +{
    2.20 +	unsigned int clamp = GLEW_ARB_texture_border_clamp ? GL_CLAMP_TO_EDGE : GL_CLAMP;
    2.21 +
    2.22 +	destroy();
    2.23 +
    2.24 +	glGenTextures(1, &tex);
    2.25 +	glBindTexture(GL_TEXTURE_3D, tex);
    2.26 +	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    2.27 +	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    2.28 +	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, clamp);
    2.29 +	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, clamp);
    2.30 +	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, clamp);
    2.31 +	glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, sz, sz, sz, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
    2.32 +
    2.33 +	unsigned char *scanline = new unsigned char[sz * 3];
    2.34 +
    2.35 +	size = sz;
    2.36 +	for(int i=0; i<sz; i++) {	// for each slice...
    2.37 +		int b = 255 * i / (sz - 1);
    2.38 +		for(int j=0; j<sz; j++) {	// for each scanline...
    2.39 +			int g = 255 * j / (sz - 1);
    2.40 +
    2.41 +			for(int k=0; k<sz; k++) {
    2.42 +				int r = 255 * k / (sz - 1);
    2.43 +
    2.44 +				scanline[k * 3] = r;
    2.45 +				scanline[k * 3 + 1] = g;
    2.46 +				scanline[k * 3 + 2] = b;
    2.47 +			}
    2.48 +			glTexSubImage3D(GL_TEXTURE_3D, 0, 0, j, i, sz, 1, 1, GL_RGB,
    2.49 +					GL_UNSIGNED_BYTE, scanline);
    2.50 +		}
    2.51 +	}
    2.52 +
    2.53 +	delete [] scanline;
    2.54 +	return true;
    2.55 +}
    2.56 +
    2.57 +void GradePalette::destroy()
    2.58 +{
    2.59 +	if(tex) {
    2.60 +		glDeleteTextures(1, &tex);
    2.61 +	}
    2.62 +}
    2.63 +
    2.64 +bool GradePalette::save_shot(const char *fname) const
    2.65 +{
    2.66 +	return false;	// TODO
    2.67 +}
    2.68 +
    2.69 +bool GradePalette::load_shot(const char *fname)
    2.70 +{
    2.71 +	return false;	// TODO
    2.72 +}
    2.73 +
    2.74 +unsigned int GradePalette::get_texture() const
    2.75 +{
    2.76 +	return tex;
    2.77 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/prototype/src/colgrade.h	Fri Oct 19 02:45:57 2012 +0300
     3.3 @@ -0,0 +1,22 @@
     3.4 +#ifndef COLGRADE_H_
     3.5 +#define COLGRADE_H_
     3.6 +
     3.7 +class GradePalette {
     3.8 +private:
     3.9 +	unsigned int tex;
    3.10 +	int size;
    3.11 +
    3.12 +public:
    3.13 +	GradePalette();
    3.14 +	~GradePalette();
    3.15 +
    3.16 +	bool create(int sz = 16);
    3.17 +	void destroy();
    3.18 +
    3.19 +	bool save_shot(const char *fname) const;
    3.20 +	bool load_shot(const char *fname);
    3.21 +
    3.22 +	unsigned int get_texture() const;
    3.23 +};
    3.24 +
    3.25 +#endif	// COLGRADE_H_
     4.1 --- a/prototype/src/main.cc	Tue Oct 16 04:08:35 2012 +0300
     4.2 +++ b/prototype/src/main.cc	Fri Oct 19 02:45:57 2012 +0300
     4.3 @@ -10,7 +10,6 @@
     4.4  #include "tileset.h"
     4.5  #include "renderer.h"
     4.6  #include "renderer_deferred.h"
     4.7 -#include "renderer_multipass.h"
     4.8  #include "cmdcon.h"
     4.9  #include "cfg.h"
    4.10  #include "timer.h"
    4.11 @@ -127,15 +126,6 @@
    4.12  		}
    4.13  		break;
    4.14  
    4.15 -	case Config::Renderer::multipass:
    4.16 -		rend = new MultipassRenderer;
    4.17 -		if(!rend->init(xsz, ysz)) {
    4.18 -			fprintf(stderr, "failed to initialize multipass deferred renderer\n");
    4.19 -			delete rend;
    4.20 -			return false;
    4.21 -		}
    4.22 -		break;
    4.23 -
    4.24  	case Config::Renderer::fwd:
    4.25  		rend = new FwdRenderer;
    4.26  		if(!rend->init(xsz, ysz)) {
    4.27 @@ -152,15 +142,10 @@
    4.28  			printf("falling back to multipass renderer...\n");
    4.29  
    4.30  			delete rend;
    4.31 -			rend = new MultipassRenderer();
    4.32 +			rend = new FwdRenderer();
    4.33  			if(!rend->init(xsz, ysz)) {
    4.34 -				printf("falling back to crappy renderer...\n");
    4.35 -
    4.36 -				rend = new FwdRenderer();
    4.37 -				if(!rend->init(xsz, ysz)) {
    4.38 -					fprintf(stderr, "failed to create renderer\n");
    4.39 -					return false;
    4.40 -				}
    4.41 +				fprintf(stderr, "failed to create renderer\n");
    4.42 +				return false;
    4.43  			}
    4.44  		}
    4.45  	}
     5.1 --- a/prototype/src/renderer.cc	Tue Oct 16 04:08:35 2012 +0300
     5.2 +++ b/prototype/src/renderer.cc	Fri Oct 19 02:45:57 2012 +0300
     5.3 @@ -6,17 +6,34 @@
     5.4  #include "datapath.h"
     5.5  
     5.6  static unsigned int load_sdr(const char *vfname, const char *pfname);
     5.7 +static int round_pow2(int x);
     5.8  
     5.9  Renderer *rend;
    5.10  
    5.11  
    5.12  Renderer::Renderer()
    5.13  {
    5.14 +	fbo = 0;
    5.15 +	rend_tex = rend_depth = 0;
    5.16  	width = height = 0;
    5.17 +	tex_xsz = tex_ysz = 0;
    5.18 +	post_sdr = 0;
    5.19  }
    5.20  
    5.21  Renderer::~Renderer()
    5.22  {
    5.23 +	if(post_sdr) {
    5.24 +		free_program(post_sdr);
    5.25 +	}
    5.26 +	if(rend_tex) {
    5.27 +		glDeleteTextures(1, &rend_tex);
    5.28 +	}
    5.29 +	if(rend_depth) {
    5.30 +		glDeleteRenderbuffersEXT(1, &rend_depth);
    5.31 +	}
    5.32 +	if(fbo) {
    5.33 +		glDeleteFramebuffersEXT(1, &fbo);
    5.34 +	}
    5.35  }
    5.36  
    5.37  bool Renderer::init(int xsz, int ysz)
    5.38 @@ -24,6 +41,18 @@
    5.39  	width = xsz;
    5.40  	height = ysz;
    5.41  
    5.42 +	if(!create_rtarg()) {
    5.43 +		return false;
    5.44 +	}
    5.45 +
    5.46 +	if(!(post_sdr = load_sdr("post.v.glsl", "post.p.glsl"))) {
    5.47 +		return false;
    5.48 +	}
    5.49 +
    5.50 +	if(!gradepal.create()) {
    5.51 +		return false;
    5.52 +	}
    5.53 +
    5.54  	rend = this;
    5.55  	return true;
    5.56  }
    5.57 @@ -42,6 +71,20 @@
    5.58  {
    5.59  	width = xsz;
    5.60  	height = ysz;
    5.61 +
    5.62 +	// if we need a bigger rendertarget ...
    5.63 +	if(xsz > tex_xsz || ysz > tex_ysz) {
    5.64 +		tex_xsz = round_pow2(xsz);
    5.65 +		tex_ysz = round_pow2(ysz);
    5.66 +
    5.67 +		// ... resize the render target
    5.68 +		glBindTexture(GL_TEXTURE_2D, rend_tex);
    5.69 +		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_xsz, tex_ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
    5.70 +
    5.71 +		// ... resize the depth buffer
    5.72 +		glBindRenderbufferEXT(GL_RENDERBUFFER, rend_depth);
    5.73 +		glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, tex_xsz, tex_ysz);
    5.74 +	}
    5.75  }
    5.76  
    5.77  void Renderer::render_pre(const Level *level) const
    5.78 @@ -51,11 +94,106 @@
    5.79  	glFogf(GL_FOG_START, 3.0f);
    5.80  	glFogf(GL_FOG_END, 6.0f);
    5.81  	// TODO level->draw_pre();
    5.82 +
    5.83 +	// bind the render target
    5.84 +	glBindFramebufferEXT(GL_FRAMEBUFFER, fbo);
    5.85 +	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rend_tex, 0);
    5.86 +	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    5.87 +
    5.88 +	CHECKGLERR;
    5.89  }
    5.90  
    5.91  void Renderer::render_post(const Level *level) const
    5.92  {
    5.93  	level->draw_post();
    5.94 +	CHECKGLERR;
    5.95 +
    5.96 +	glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
    5.97 +
    5.98 +	// draw the rendered output
    5.99 +	glActiveTextureARB(GL_TEXTURE0);
   5.100 +	glBindTexture(GL_TEXTURE_2D, rend_tex);
   5.101 +	glEnable(GL_TEXTURE_2D);
   5.102 +
   5.103 +	// use the color-grading palette
   5.104 +	glActiveTextureARB(GL_TEXTURE1);
   5.105 +	glBindTexture(GL_TEXTURE_3D, gradepal.get_texture());
   5.106 +	glEnable(GL_TEXTURE_3D);
   5.107 +
   5.108 +	glUseProgram(post_sdr);
   5.109 +	set_uniform_int(post_sdr, "fbtex", 0);
   5.110 +	set_uniform_int(post_sdr, "paltex", 1);
   5.111 +
   5.112 +	glBegin(GL_QUADS);
   5.113 +	glTexCoord2f(0, 0);
   5.114 +	glVertex2f(-1, -1);
   5.115 +	glTexCoord2f((float)width / tex_xsz, 0);
   5.116 +	glVertex2f(1, -1);
   5.117 +	glTexCoord2f((float)width / tex_xsz, (float)height / tex_ysz);
   5.118 +	glVertex2f(1, 1);
   5.119 +	glTexCoord2f(0, (float)height / tex_ysz);
   5.120 +	glVertex2f(-1, 1);
   5.121 +	glEnd();
   5.122 +	glUseProgram(0);
   5.123 +
   5.124 +	glActiveTextureARB(GL_TEXTURE0);
   5.125 +
   5.126 +	CHECKGLERR;
   5.127 +}
   5.128 +
   5.129 +static const char *fbstname[] = {
   5.130 +	"GL_FRAMEBUFFER_COMPLETE",
   5.131 +	"GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT",
   5.132 +	"GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT",
   5.133 +	"no such fbo error",
   5.134 +	"GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS",
   5.135 +	"GL_FRAMEBUFFER_INCOMPLETE_FORMATS",
   5.136 +	"GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER",
   5.137 +	"GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER",
   5.138 +	"GL_FRAMEBUFFER_UNSUPPORTED"
   5.139 +};
   5.140 +
   5.141 +bool Renderer::create_rtarg()
   5.142 +{
   5.143 +	unsigned int clamp = GLEW_ARB_texture_border_clamp ? GL_CLAMP_TO_EDGE : GL_CLAMP;
   5.144 +
   5.145 +	tex_xsz = round_pow2(width);
   5.146 +	tex_ysz = round_pow2(height);
   5.147 +
   5.148 +	if(!glGenFramebuffersEXT) {
   5.149 +		fprintf(stderr, "FBO support missing!\n");
   5.150 +		return false;
   5.151 +	}
   5.152 +	glGenFramebuffersEXT(1, &fbo);
   5.153 +	glBindFramebufferEXT(GL_FRAMEBUFFER, fbo);
   5.154 +
   5.155 +	// create the render target
   5.156 +	glGenTextures(1, &rend_tex);
   5.157 +	glBindTexture(GL_TEXTURE_2D, rend_tex);
   5.158 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp);
   5.159 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, clamp);
   5.160 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   5.161 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   5.162 +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_xsz, tex_ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
   5.163 +
   5.164 +	glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rend_tex, 0);
   5.165 +
   5.166 +	// create depth buffer
   5.167 +	glGenRenderbuffersEXT(1, &rend_depth);
   5.168 +	glBindRenderbufferEXT(GL_RENDERBUFFER, rend_depth);
   5.169 +	glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, tex_xsz, tex_ysz);
   5.170 +
   5.171 +	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rend_depth);
   5.172 +
   5.173 +	int fbst = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
   5.174 +	if(fbst != GL_FRAMEBUFFER_COMPLETE) {
   5.175 +		fprintf(stderr, "incomplete fbo: %u (%s)\n", fbo, fbstname[fbst - GL_FRAMEBUFFER_COMPLETE]);
   5.176 +		return false;
   5.177 +	}
   5.178 +	CHECKGLERR;
   5.179 +
   5.180 +	glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
   5.181 +	return true;
   5.182  }
   5.183  
   5.184  
   5.185 @@ -75,8 +213,9 @@
   5.186  
   5.187  bool FwdRenderer::init(int xsz, int ysz)
   5.188  {
   5.189 -	width = xsz;
   5.190 -	height = ysz;
   5.191 +	if(!Renderer::init(xsz, ysz)) {
   5.192 +		return false;
   5.193 +	}
   5.194  
   5.195  	if(glUseProgram && (sdrprog = load_sdr("fallback.v.glsl", "fallback.p.glsl"))) {
   5.196  		tang_attr = get_attrib_loc(sdrprog, "attr_tangent");
   5.197 @@ -128,3 +267,15 @@
   5.198  	}
   5.199  	return prog;
   5.200  }
   5.201 +
   5.202 +static int round_pow2(int x)
   5.203 +{
   5.204 +	x--;
   5.205 +	x = (x >> 1) | x;
   5.206 +	x = (x >> 2) | x;
   5.207 +	x = (x >> 4) | x;
   5.208 +	x = (x >> 8) | x;
   5.209 +	x = (x >> 16) | x;
   5.210 +	return x + 1;
   5.211 +}
   5.212 +
     6.1 --- a/prototype/src/renderer.h	Tue Oct 16 04:08:35 2012 +0300
     6.2 +++ b/prototype/src/renderer.h	Fri Oct 19 02:45:57 2012 +0300
     6.3 @@ -1,11 +1,22 @@
     6.4  #ifndef RENDERER_H_
     6.5  #define RENDERER_H_
     6.6  
     6.7 +#include "colgrade.h"
     6.8 +
     6.9  class Level;
    6.10  
    6.11  class Renderer {
    6.12  protected:
    6.13 +	// render target
    6.14 +	unsigned int fbo;
    6.15 +	unsigned int rend_tex, rend_depth;
    6.16  	int width, height;
    6.17 +	int tex_xsz, tex_ysz;
    6.18 +
    6.19 +	GradePalette gradepal;
    6.20 +	unsigned int post_sdr;
    6.21 +
    6.22 +	virtual bool create_rtarg();
    6.23  
    6.24  public:
    6.25  	Renderer();
     7.1 --- a/prototype/src/renderer_deferred.cc	Tue Oct 16 04:08:35 2012 +0300
     7.2 +++ b/prototype/src/renderer_deferred.cc	Fri Oct 19 02:45:57 2012 +0300
     7.3 @@ -10,17 +10,14 @@
     7.4  
     7.5  static unsigned int load_sdr(const char *vfname, const char *pfname);
     7.6  static void attach_color_buffer(unsigned int fbo, int count, const unsigned int *tex);
     7.7 -static int round_pow2(int x);
     7.8  
     7.9  DeferredRenderer::DeferredRenderer()
    7.10  {
    7.11 -	fbo = rbuf_depth = rend_tex = 0;
    7.12 +	fbo = 0;
    7.13  	for(int i=0; i<MRT_COUNT; i++) {
    7.14  		mrt_tex[i] = 0;
    7.15  	}
    7.16 -	tex_xsz = tex_ysz = 0;
    7.17 -
    7.18 -	mrt_prog = deferred_debug = deferred_omni = post_sdr = 0;
    7.19 +	mrt_prog = deferred_debug = deferred_omni = 0;
    7.20  
    7.21  	curr_prog = 0;
    7.22  	num_draw_bufs = 1;
    7.23 @@ -37,28 +34,17 @@
    7.24  	if(deferred_debug) {
    7.25  		free_program(deferred_debug);
    7.26  	}
    7.27 -	if(post_sdr) {
    7.28 -		free_program(post_sdr);
    7.29 -	}
    7.30  
    7.31  	if(mrt_tex[0]) {
    7.32  		glDeleteTextures(MRT_COUNT, mrt_tex);
    7.33  	}
    7.34 -	if(rend_tex) {
    7.35 -		glDeleteTextures(1, &rend_tex);
    7.36 -	}
    7.37 -	if(rbuf_depth) {
    7.38 -		glDeleteRenderbuffersEXT(1, &rbuf_depth);
    7.39 -	}
    7.40 -	if(fbo) {
    7.41 -		glDeleteFramebuffersEXT(1, &fbo);
    7.42 -	}
    7.43  }
    7.44  
    7.45  bool DeferredRenderer::init(int xsz, int ysz)
    7.46  {
    7.47 -	width = xsz;
    7.48 -	height = ysz;
    7.49 +	if(!Renderer::init(xsz, ysz)) {
    7.50 +		return false;
    7.51 +	}
    7.52  
    7.53  	if(!GLEW_ARB_texture_float) {
    7.54  		fprintf(stderr, "%s: error: no floating point texture support\n", __FUNCTION__);
    7.55 @@ -78,10 +64,6 @@
    7.56  	}
    7.57  	num_draw_bufs = MRT_COUNT;
    7.58  
    7.59 -	if(!create_fbo()) {
    7.60 -		return false;
    7.61 -	}
    7.62 -
    7.63  	if(!(mrt_prog = load_sdr("mrt.v.glsl", "mrt.p.glsl"))) {
    7.64  		return false;
    7.65  	}
    7.66 @@ -97,11 +79,6 @@
    7.67  		set_uniform_int(deferred_omni, uname, i);
    7.68  	}
    7.69  
    7.70 -	if(!(post_sdr = load_sdr("post.v.glsl", "post.p.glsl"))) {
    7.71 -		return false;
    7.72 -	}
    7.73 -
    7.74 -	rend = this;
    7.75  	return true;
    7.76  }
    7.77  
    7.78 @@ -117,27 +94,20 @@
    7.79  
    7.80  void DeferredRenderer::resize(int xsz, int ysz)
    7.81  {
    7.82 -	width = xsz;
    7.83 -	height = ysz;
    7.84 +	// keep a copy of the previous texture size because Renderer::resize may change it
    7.85 +
    7.86 +	int prev_tex_xsz = tex_xsz;
    7.87 +	int prev_tex_ysz = tex_ysz;
    7.88 +
    7.89 +	Renderer::resize(xsz, ysz);
    7.90  
    7.91  	// if we need a bigger rendertarget ...
    7.92 -	if(xsz > tex_xsz || ysz > tex_ysz) {
    7.93 -		tex_xsz = round_pow2(xsz);
    7.94 -		tex_ysz = round_pow2(ysz);
    7.95 -
    7.96 +	if(xsz > prev_tex_xsz || ysz > prev_tex_ysz) {
    7.97  		// ... resize all the color buffers
    7.98  		for(int i=0; i<MRT_COUNT; i++) {
    7.99  			glBindTexture(GL_TEXTURE_2D, mrt_tex[i]);
   7.100  			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, tex_xsz, tex_ysz, 0, GL_RGBA, GL_FLOAT, 0);
   7.101  		}
   7.102 -
   7.103 -		// ... resize the render texture
   7.104 -		glBindTexture(GL_TEXTURE_2D, rend_tex);
   7.105 -		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_xsz, tex_ysz, 0, GL_RGBA, GL_FLOAT, 0);
   7.106 -
   7.107 -		// ... resize the depth buffer
   7.108 -		glBindRenderbufferEXT(GL_RENDERBUFFER, rbuf_depth);
   7.109 -		glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, tex_xsz, tex_ysz);
   7.110  	}
   7.111  
   7.112  	// update the texture coordinate scaling factors
   7.113 @@ -174,23 +144,6 @@
   7.114  	render_post(level);
   7.115  
   7.116  	glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
   7.117 -
   7.118 -	// XXX this should be moved to render_post
   7.119 -	glBindTexture(GL_TEXTURE_2D, rend_tex);
   7.120 -	glEnable(GL_TEXTURE_2D);
   7.121 -
   7.122 -	glUseProgram(post_sdr);
   7.123 -	glBegin(GL_QUADS);
   7.124 -	glTexCoord2f(0, 0);
   7.125 -	glVertex2f(-1, -1);
   7.126 -	glTexCoord2f((float)width / tex_xsz, 0);
   7.127 -	glVertex2f(1, -1);
   7.128 -	glTexCoord2f((float)width / tex_xsz, (float)height / tex_ysz);
   7.129 -	glVertex2f(1, 1);
   7.130 -	glTexCoord2f(0, (float)height / tex_ysz);
   7.131 -	glVertex2f(-1, 1);
   7.132 -	glEnd();
   7.133 -	glUseProgram(0);
   7.134  }
   7.135  
   7.136  void DeferredRenderer::light_pass(const Level *level) const
   7.137 @@ -237,30 +190,16 @@
   7.138  	"GL_FRAMEBUFFER_UNSUPPORTED"
   7.139  };
   7.140  
   7.141 -bool DeferredRenderer::create_fbo()
   7.142 +bool DeferredRenderer::create_rtarg()
   7.143  {
   7.144 +	if(!Renderer::create_rtarg()) {
   7.145 +		return false;
   7.146 +	}
   7.147 +
   7.148  	unsigned int clamp = GLEW_ARB_texture_border_clamp ? GL_CLAMP_TO_EDGE : GL_CLAMP;
   7.149  
   7.150 -	// round the texture size up to the next power of 2
   7.151 -	tex_xsz = round_pow2(width);
   7.152 -	tex_ysz = round_pow2(height);
   7.153 -
   7.154 -	if(!glGenFramebuffersEXT) {
   7.155 -		fprintf(stderr, "FBO support missing\n");
   7.156 -		return false;
   7.157 -	}
   7.158 -	glGenFramebuffersEXT(1, &fbo);
   7.159  	glBindFramebufferEXT(GL_FRAMEBUFFER, fbo);
   7.160  
   7.161 -	// create the result render target
   7.162 -	glGenTextures(1, &rend_tex);
   7.163 -	glBindTexture(GL_TEXTURE_2D, rend_tex);
   7.164 -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, clamp);
   7.165 -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, clamp);
   7.166 -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   7.167 -	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   7.168 -	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex_xsz, tex_ysz, 0, GL_RGBA, GL_FLOAT, 0);
   7.169 -
   7.170  	glGenTextures(MRT_COUNT, mrt_tex);
   7.171  	for(int i=0; i<MRT_COUNT; i++) {
   7.172  		glBindTexture(GL_TEXTURE_2D, mrt_tex[i]);
   7.173 @@ -276,11 +215,6 @@
   7.174  		CHECKGLERR;
   7.175  	}
   7.176  
   7.177 -	glGenRenderbuffersEXT(1, &rbuf_depth);
   7.178 -	glBindRenderbufferEXT(GL_RENDERBUFFER, rbuf_depth);
   7.179 -	glRenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, tex_xsz, tex_ysz);
   7.180 -	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rbuf_depth);
   7.181 -
   7.182  	int fbst = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER);
   7.183  	if(fbst != GL_FRAMEBUFFER_COMPLETE) {
   7.184  		fprintf(stderr, "incomplete fbo: %u (%s)\n", fbo, fbstname[fbst - GL_FRAMEBUFFER_COMPLETE]);
   7.185 @@ -328,17 +262,6 @@
   7.186  	glDrawBuffersARB(count, draw_bufs);
   7.187  }
   7.188  
   7.189 -static int round_pow2(int x)
   7.190 -{
   7.191 -	x--;
   7.192 -	x = (x >> 1) | x;
   7.193 -	x = (x >> 2) | x;
   7.194 -	x = (x >> 4) | x;
   7.195 -	x = (x >> 8) | x;
   7.196 -	x = (x >> 16) | x;
   7.197 -	return x + 1;
   7.198 -}
   7.199 -
   7.200  #ifdef DBG_VIS_MRT
   7.201  // visualize the MRT buffers
   7.202  static void draw_deferred_debug()
     8.1 --- a/prototype/src/renderer_deferred.h	Tue Oct 16 04:08:35 2012 +0300
     8.2 +++ b/prototype/src/renderer_deferred.h	Fri Oct 19 02:45:57 2012 +0300
     8.3 @@ -8,20 +8,17 @@
     8.4  class DeferredRenderer : public Renderer {
     8.5  protected:
     8.6  	// render targets
     8.7 -	unsigned int fbo, rend_tex, rbuf_depth;
     8.8  	unsigned int mrt_tex[MRT_COUNT];
     8.9 -	int tex_xsz, tex_ysz;
    8.10  
    8.11  	// shaders
    8.12  	unsigned int mrt_prog;
    8.13  	unsigned int deferred_omni, deferred_debug;
    8.14 -	unsigned int post_sdr;
    8.15  
    8.16  	mutable unsigned int curr_prog;
    8.17  
    8.18  	int num_draw_bufs;
    8.19  
    8.20 -	virtual bool create_fbo();
    8.21 +	virtual bool create_rtarg();
    8.22  
    8.23  public:
    8.24  	DeferredRenderer();
     9.1 --- a/prototype/src/renderer_multipass.cc	Tue Oct 16 04:08:35 2012 +0300
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,118 +0,0 @@
     9.4 -#include <stdio.h>
     9.5 -#include <stdlib.h>
     9.6 -#include <string.h>
     9.7 -#include "opengl.h"
     9.8 -#include "renderer_multipass.h"
     9.9 -#include "level.h"
    9.10 -#include "sdr.h"
    9.11 -#include "datapath.h"
    9.12 -
    9.13 -static unsigned int load_sdr(const char *vfname, const char *pfname);
    9.14 -
    9.15 -
    9.16 -MultipassRenderer::MultipassRenderer()
    9.17 -{
    9.18 -	for(int i=0; i<MRT_COUNT; i++) {
    9.19 -		rt_prog[i] = 0;
    9.20 -	}
    9.21 -}
    9.22 -
    9.23 -MultipassRenderer::~MultipassRenderer()
    9.24 -{
    9.25 -	for(int i=0; i<MRT_COUNT; i++) {
    9.26 -		if(rt_prog[i]) {
    9.27 -			free_program(rt_prog[i]);
    9.28 -		}
    9.29 -	}
    9.30 -}
    9.31 -
    9.32 -bool MultipassRenderer::init(int xsz, int ysz)
    9.33 -{
    9.34 -	width = xsz;
    9.35 -	height = ysz;
    9.36 -
    9.37 -	if(!GLEW_ARB_texture_float) {
    9.38 -		fprintf(stderr, "%s: error: no floating point texture support\n", __FUNCTION__);
    9.39 -		return false;
    9.40 -	}
    9.41 -
    9.42 -	if(!create_fbo()) {
    9.43 -		return false;
    9.44 -	}
    9.45 -
    9.46 -	for(int i=0; i<MRT_COUNT; i++) {
    9.47 -		char fname[128];
    9.48 -		sprintf(fname, "multi%d.p.glsl", i);
    9.49 -
    9.50 -		if(!(rt_prog[i] = load_sdr("mrt.v.glsl", fname))) {
    9.51 -			return false;
    9.52 -		}
    9.53 -		set_uniform_int(rt_prog[i], "tex_dif", 0);
    9.54 -		set_uniform_int(rt_prog[i], "tex_norm", 1);
    9.55 -	}
    9.56 -
    9.57 -	if(!(deferred_omni = load_sdr("deferred_omni.v.glsl", "deferred_omni.p.glsl"))) {
    9.58 -		return false;
    9.59 -	}
    9.60 -	for(int i=0; i<MRT_COUNT; i++) {
    9.61 -		char uname[32];
    9.62 -		sprintf(uname, "mrt%d", i);
    9.63 -		set_uniform_int(deferred_omni, uname, i);
    9.64 -	}
    9.65 -
    9.66 -	rend = this;
    9.67 -	return true;
    9.68 -}
    9.69 -
    9.70 -int MultipassRenderer::get_tangent_location() const
    9.71 -{
    9.72 -	if(!curr_prog) {
    9.73 -		return -1;
    9.74 -	}
    9.75 -	return get_attrib_loc(curr_prog, "attr_tangent");
    9.76 -}
    9.77 -
    9.78 -void MultipassRenderer::render(const Level *level) const
    9.79 -{
    9.80 -	render_pre(level);
    9.81 -
    9.82 -	// render into the MRT buffers
    9.83 -	glBindFramebufferEXT(GL_FRAMEBUFFER, fbo);
    9.84 -
    9.85 -	for(int i=0; i<MRT_COUNT; i++) {
    9.86 -		glUseProgram(rt_prog[i]);
    9.87 -		curr_prog = rt_prog[i];
    9.88 -
    9.89 -		glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
    9.90 -				mrt_tex[i], 0);
    9.91 -
    9.92 -		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    9.93 -		level->draw();
    9.94 -	}
    9.95 -	glBindFramebufferEXT(GL_FRAMEBUFFER, 0);
    9.96 -
    9.97 -	// post-process lighting
    9.98 -	light_pass(level);
    9.99 -
   9.100 -	glUseProgram(0);
   9.101 -	curr_prog = 0;
   9.102 -
   9.103 -	render_post(level);
   9.104 -}
   9.105 -
   9.106 -static unsigned int load_sdr(const char *vfname, const char *pfname)
   9.107 -{
   9.108 -	unsigned int prog;
   9.109 -
   9.110 -	std::string vsfile = datafile_path(vfname);
   9.111 -	std::string psfile = datafile_path(pfname);
   9.112 -
   9.113 -	const char *vs = vsfile.empty() ? 0 : vsfile.c_str();
   9.114 -	const char *ps = psfile.empty() ? 0 : psfile.c_str();
   9.115 -
   9.116 -	if(!(prog = create_program_load(vs, ps))) {
   9.117 -		fprintf(stderr, "failed to load shader program (%s, %s)\n", vs, ps);
   9.118 -		return 0;
   9.119 -	}
   9.120 -	return prog;
   9.121 -}
    10.1 --- a/prototype/src/renderer_multipass.h	Tue Oct 16 04:08:35 2012 +0300
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,21 +0,0 @@
    10.4 -#ifndef RENDERER_MULTIPASS_H_
    10.5 -#define RENDERER_MULTIPASS_H_
    10.6 -
    10.7 -#include "renderer_deferred.h"
    10.8 -
    10.9 -class MultipassRenderer : public DeferredRenderer {
   10.10 -private:
   10.11 -	unsigned int rt_prog[MRT_COUNT];
   10.12 -
   10.13 -public:
   10.14 -	MultipassRenderer();
   10.15 -	virtual ~MultipassRenderer();
   10.16 -
   10.17 -	virtual bool init(int xsz, int ysz);
   10.18 -
   10.19 -	virtual int get_tangent_location() const;
   10.20 -
   10.21 -	virtual void render(const Level *level) const;
   10.22 -};
   10.23 -
   10.24 -#endif	// RENDERER_MULTIPASS_H_