sdrblurtest

changeset 1:e8fc0c9754c9 tip

added fps counter
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 14 Oct 2015 17:46:02 +0300
parents 26513fdda566
children
files sdr/hblur.glsl sdr/vblur.glsl src/main.cc
diffstat 3 files changed, 23 insertions(+), 6 deletions(-) [+]
line diff
     1.1 --- a/sdr/hblur.glsl	Thu Oct 17 08:19:56 2013 +0300
     1.2 +++ b/sdr/hblur.glsl	Wed Oct 14 17:46:02 2015 +0300
     1.3 @@ -8,12 +8,13 @@
     1.4  void main()
     1.5  {
     1.6  	float pixw = 1.0 / texsize.x;
     1.7 +	vec2 maxuv = size / texsize;
     1.8  
     1.9  	vec3 texel = vec3(0.0, 0.0, 0.0);
    1.10  	for(int i=0; i<KSZ; i++) {
    1.11  		float x = float(i - HALF_KSZ) * pixw;
    1.12  		vec2 uv = gl_TexCoord[0].st + vec2(x, 0.0);
    1.13 -		texel += texture2D(tex, uv).rgb;
    1.14 +		texel += texture2D(tex, min(uv, maxuv)).rgb;
    1.15  	}
    1.16  
    1.17  	gl_FragColor.rgb = texel / SCALE;
     2.1 --- a/sdr/vblur.glsl	Thu Oct 17 08:19:56 2013 +0300
     2.2 +++ b/sdr/vblur.glsl	Wed Oct 14 17:46:02 2015 +0300
     2.3 @@ -8,12 +8,13 @@
     2.4  void main()
     2.5  {
     2.6  	float pixh = 1.0 / texsize.y;
     2.7 +	vec2 maxuv = size / texsize;
     2.8  
     2.9  	vec3 texel = vec3(0.0, 0.0, 0.0);
    2.10  	for(int i=0; i<KSZ; i++) {
    2.11  		float y = float(i - HALF_KSZ) * pixh;
    2.12  		vec2 uv = gl_TexCoord[0].st + vec2(0.0, y);
    2.13 -		texel += texture2D(tex, uv).rgb;
    2.14 +		texel += texture2D(tex, min(uv, maxuv)).rgb;
    2.15  	}
    2.16  
    2.17  	gl_FragColor.rgb = texel / SCALE;
     3.1 --- a/src/main.cc	Thu Oct 17 08:19:56 2013 +0300
     3.2 +++ b/src/main.cc	Wed Oct 14 17:46:02 2015 +0300
     3.3 @@ -22,7 +22,7 @@
     3.4  static bool init();
     3.5  static void cleanup();
     3.6  static void disp();
     3.7 -static void print_string(const char *str);
     3.8 +static void print_string(int x, int y, const char *str);
     3.9  static void idle();
    3.10  static void reshape(int x, int y);
    3.11  static void keyb(unsigned char key, int x, int y);
    3.12 @@ -96,6 +96,9 @@
    3.13  
    3.14  static void disp()
    3.15  {
    3.16 +	static int nframes;
    3.17 +	static char fpsstr[64] = "fps: ???";
    3.18 +
    3.19  	glMatrixMode(GL_MODELVIEW);
    3.20  	glLoadIdentity();
    3.21  	glTranslatef(0, 0, -cam_dist);
    3.22 @@ -142,13 +145,25 @@
    3.23  	}
    3.24  	bind_program(0);
    3.25  
    3.26 -	print_string(blur_type == BLUR_REG ? "Regular blur" : "Seperable blur");
    3.27 +	++nframes;
    3.28 +	static unsigned int prev_fps_upd;
    3.29 +	unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
    3.30 +	unsigned int dt = msec - prev_fps_upd;
    3.31 +	if(dt > 1500) {
    3.32 +		float fps = 1000.0 * (float)nframes / (float)dt;
    3.33 +		prev_fps_upd = msec;
    3.34 +		nframes = 0;
    3.35 +		sprintf(fpsstr, "fps: %.1f", fps);
    3.36 +	}
    3.37 +
    3.38 +	print_string(1, 30, blur_type == BLUR_REG ? "Regular blur" : "Seperable blur");
    3.39 +	print_string(1, 5, fpsstr);
    3.40  
    3.41  	glutSwapBuffers();
    3.42  	assert(glGetError() == GL_NO_ERROR);
    3.43  }
    3.44  
    3.45 -static void print_string(const char *str)
    3.46 +static void print_string(int x, int y, const char *str)
    3.47  {
    3.48  	glPushAttrib(GL_ENABLE_BIT);
    3.49  
    3.50 @@ -163,7 +178,7 @@
    3.51  	glDisable(GL_LIGHTING);
    3.52  	glDisable(GL_DEPTH_TEST);
    3.53  
    3.54 -	glRasterPos2f(1, 1);
    3.55 +	glRasterPos2f(x, y);
    3.56  	glColor3f(1, 1, 0);
    3.57  	while(*str) {
    3.58  		glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *str++);