Commits

Cliff Biffle committed 9184096

Mesh renderer now draws only two sides of each square and calls glColor3f half as often, for a small performance win.

Comments (0)

Files changed (1)

 }
 
 - (void) drawDepthFieldAsMesh {
+  /*
+   * Implementation note: each iteration needs only draw the top and left lines.
+   */
   axes();
   
   const GLfloat *depths = [linearDepthField bytes];
   glBegin(GL_LINES);
   for (int y = 0; y < 479; y++) {
     for (int x = 0; x < 639; x++) {
-      int xs[4] = { x, x, x + 1, x + 1 };
-      int ys[4] = { y, y + 1, y + 1, y };
+      int xs[3] = { x,     x, x + 1 };
+      int ys[3] = { y + 1, y, y     };
     
       BOOL skip = NO;
-      vec3f_t coords[4];
-      GLfloat colors[4];
-      for (int i = 0; i < 4; i++) {
+      vec3f_t coords[3];
+      GLfloat colors[3];
+      for (int i = 0; i < 3; i++) {
         GLfloat d = depths[ys[i] * 640 + xs[i]];
         if (d < 0.1F) skip = YES;
         
       
       if (skip) continue;
 
-      for (int i = 0; i < 4; i++) {
+      for (int i = 0; i < 2; i++) {
         int i2 = (i + 1) % 4;
-        glColor3f(colors[i], colors[i], colors[i]);
+        // Reuse color from previous iteration for first vertex.
         glVertex3fv(&coords[i].x);
-        
         glColor3f(colors[i2], colors[i2], colors[i2]);
         glVertex3fv(&coords[i2].x);
       }