tgsi: added tgsi_full_instruction::Flags field
[mesa.git] / progs / demos / ray.c
index 24f27a05393b84815ca6da0b5e3f44c2734ab938..c2d8e4f545e352207f7628e470388eb97a73b828 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <math.h>
 
 #ifdef WIN32
@@ -24,7 +25,8 @@ static int fullscreen = 1;
 static int WIDTH = 640;
 static int HEIGHT = 480;
 
-#define FRAME 50
+static GLint T0 = 0;
+static GLint Frames = 0;
 
 #define BASESIZE 7.5f
 #define SPHERE_RADIUS 0.75f
@@ -47,7 +49,9 @@ static int HEIGHT = 480;
 
 #define clamp255(a)  ( (a)<(0.0f) ? (0.0f) : ((a)>(255.0f) ? (255.0f) : (a)) )
 
+#ifndef fabs
 #define fabs(x) ((x)<0.0f?-(x):(x))
+#endif
 
 #define vequ(a,b) { (a)[0]=(b)[0]; (a)[1]=(b)[1]; (a)[2]=(b)[2]; }
 #define vsub(a,b,c) { (a)[0]=(b)[0]-(c)[0]; (a)[1]=(b)[1]-(c)[1]; (a)[2]=(b)[2]-(c)[2]; }
@@ -94,21 +98,6 @@ static int showreflectmap = 1;
 static int joyavailable = 0;
 static int joyactive = 0;
 
-static float
-gettime(void)
-{
-   static float told = 0.0f;
-   float tnew, ris;
-
-   tnew = glutGet(GLUT_ELAPSED_TIME);
-
-   ris = tnew - told;
-
-   told = tnew;
-
-   return ris / 1000.0;
-}
-
 static void
 calcposobs(void)
 {
@@ -116,6 +105,13 @@ calcposobs(void)
    dir[1] = cos(alpha * M_PI / 180.0) * sin(beta * M_PI / 180.0);
    dir[2] = cos(beta * M_PI / 180.0);
 
+   if (dir[0] < 1.0e-5 && dir[0] > -1.0e-5)
+      dir[0] = 0;
+   if (dir[1] < 1.0e-5 && dir[1] > -1.0e-5)
+      dir[1] = 0;
+   if (dir[2] < 1.0e-5 && dir[2] > -1.0e-5)
+      dir[2] = 0;
+
    obs[0] += v * dir[0];
    obs[1] += v * dir[1];
    obs[2] += v * dir[2];
@@ -275,13 +271,13 @@ printhelp(void)
    printstring(GLUT_BITMAP_HELVETICA_18, "Help");
 
    glRasterPos2i(60, 390);
-   printstring(GLUT_BITMAP_HELVETICA_12, "h - Togle Help");
+   printstring(GLUT_BITMAP_HELVETICA_12, "h - Toggle Help");
    glRasterPos2i(60, 370);
-   printstring(GLUT_BITMAP_HELVETICA_12, "f - Togle Fog");
+   printstring(GLUT_BITMAP_HELVETICA_12, "f - Toggle Fog");
    glRasterPos2i(60, 350);
-   printstring(GLUT_BITMAP_HELVETICA_12, "b - Togle Back face culling");
+   printstring(GLUT_BITMAP_HELVETICA_12, "b - Toggle Back face culling");
    glRasterPos2i(60, 330);
-   printstring(GLUT_BITMAP_HELVETICA_12, "p - Togle Wire frame");
+   printstring(GLUT_BITMAP_HELVETICA_12, "p - Toggle Wire frame");
    glRasterPos2i(60, 310);
    printstring(GLUT_BITMAP_HELVETICA_12, "Arrow Keys - Rotate");
    glRasterPos2i(60, 290);
@@ -292,7 +288,7 @@ printhelp(void)
    glRasterPos2i(60, 250);
    if (joyavailable)
       printstring(GLUT_BITMAP_HELVETICA_12,
-                 "j - Togle jostick control (Joystick control available)");
+                 "j - Toggle jostick control (Joystick control available)");
    else
       printstring(GLUT_BITMAP_HELVETICA_12,
                  "(No Joystick control available)");
@@ -306,11 +302,11 @@ printhelp(void)
 
    glRasterPos2i(60, 190);
    printstring(GLUT_BITMAP_HELVETICA_12,
-              "1 - Togle the plane texture map window");
+              "1 - Toggle the plane texture map window");
 
    glRasterPos2i(60, 170);
    printstring(GLUT_BITMAP_HELVETICA_12,
-              "2 - Togle the sphere texture map window");
+              "2 - Toggle the sphere texture map window");
 }
 
 static GLboolean
@@ -393,8 +389,7 @@ colorcheckmap(float ppos[3], float c[3])
    h[1] = 0.5f * (vdir[1] + ldir[1]);
    h[2] = 0.5f * (vdir[2] + ldir[2]);
    kfact = dprod(h, norm);
-   kfact =
-      kfact * kfact * kfact * kfact * kfact * kfact * kfact * 7.0f * 255.0f;
+   kfact = pow(kfact, 6.0) * 7.0 * 255.0;
 
    r = r * dfact + kfact;
    g = g * dfact + kfact;
@@ -494,12 +489,10 @@ updatereflectmap(int slot)
            h[1] = 0.5f * (vdir[1] + ldir[1]);
            h[2] = 0.5f * (vdir[2] + ldir[2]);
            kfact = dprod(h, norm);
-           kfact *= kfact;
-           kfact *= kfact;
-           kfact *= kfact;
-           kfact *= kfact;
-           kfact *= 10.0f;
-        }
+            kfact = pow(kfact, 4.0);
+            if (kfact < 1.0e-10)
+               kfact = 0.0;
+         }
 
         r = dfact + kfact;
         g = dfact + kfact;
@@ -622,9 +615,7 @@ updatemaps(void)
 static void
 draw(void)
 {
-   static int count = 0;
-   static char frbuf[80];
-   float fr;
+   static char frbuf[80] = "";
 
    dojoy();
 
@@ -657,11 +648,6 @@ draw(void)
 
    glPopMatrix();
 
-   if ((count % FRAME) == 0) {
-      fr = gettime();
-      sprintf(frbuf, "Frame rate: %f", FRAME / fr);
-   }
-
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_FOG);
 
@@ -746,7 +732,17 @@ draw(void)
 
    glutSwapBuffers();
 
-   count++;
+   Frames++;
+   {
+      GLint t = glutGet(GLUT_ELAPSED_TIME);
+      if (t - T0 >= 2000) {
+         GLfloat seconds = (t - T0) / 1000.0;
+         GLfloat fps = Frames / seconds;
+         sprintf(frbuf, "Frame rate: %f", fps);
+         T0 = t;
+         Frames = 0;
+      }
+   }
 }
 
 static void