From 39dd5196e6fa126b5fd4bfd23b665c105ddbf95c Mon Sep 17 00:00:00 2001 From: Michal Krol Date: Sat, 29 Jul 2006 09:42:03 +0000 Subject: Optimize shaders. Use frame counter. --- progs/demos/glslnoise.c | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'progs/demos') diff --git a/progs/demos/glslnoise.c b/progs/demos/glslnoise.c index 2adb114e66..4ee1292816 100755 --- a/progs/demos/glslnoise.c +++ b/progs/demos/glslnoise.c @@ -30,6 +30,9 @@ static GLhandleARB program; static GLint uTime; +static GLint t0 = 0; +static GLint frames = 0; + static GLfloat u_time = 0.0f; static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL; @@ -44,15 +47,27 @@ static PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL; static void Redisplay (void) { + GLint t; + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glUniform1fARB (uTime, u_time); + glUniform1fARB (uTime, 0.5f * u_time); glPushMatrix (); glutSolidSphere (2.0, 20, 10); glPopMatrix (); glutSwapBuffers(); + frames++; + + t = glutGet (GLUT_ELAPSED_TIME); + if (t - t0 >= 5000) { + GLfloat seconds = (GLfloat) (t - t0) / 1000.0f; + GLfloat fps = frames / seconds; + printf ("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps); + t0 = t; + frames = 0; + } } static void Idle (void) @@ -88,20 +103,20 @@ static void Key (unsigned char key, int x, int y) static void Init (void) { - static const char *fragShaderText = - "uniform float time;\n" - "void main () {\n" - " gl_FragColor = gl_Color * vec4 ((0.5 + 0.5 * vec3 (noise1 (\n" - " vec4 (4.0 * gl_TexCoord[0].xyz, 0.5 * time)))), 1.0);\n" - "}\n" - ; - static const char *vertShaderText = - "void main () {\n" - " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" - " gl_TexCoord[0] = gl_Vertex;\n" - " gl_FrontColor = gl_Color;\n" - "}\n" - ; + static const char *fragShaderText = + "uniform float time;\n" + "varying vec3 position;\n" + "void main () {\n" + " gl_FragColor = vec4 (vec3 (0.5 + 0.5 * noise1 (vec4 (position, time))), 1.0);\n" + "}\n" + ; + static const char *vertShaderText = + "varying vec3 position;\n" + "void main () {\n" + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + " position = 4.0 * gl_Vertex.xyz;\n" + "}\n" + ; if (!glutExtensionSupported ("GL_ARB_fragment_shader")) { -- cgit v1.2.3