Store bit-depth for reuse, replace loop with shift
authorCampbell Barton <ideasman42@gmail.com>
Tue, 28 Apr 2015 19:30:30 +0000 (05:30 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 28 Apr 2015 19:32:25 +0000 (05:32 +1000)
source/blender/editors/screen/glutil.c

index f29ba785180697393d66c101dd4d33f3cbaf0868..ca0047b202a88426b345c11eb7127c77d00035a0 100644 (file)
@@ -1008,16 +1008,22 @@ void bglPolygonOffset(float UNUSED(viewdist), float dist)
                /* dist is from camera to center point */
                
                if (winmat[15] > 0.5f) {
-                       int depthbits, i, depthmax = 1;
-                       glGetIntegerv(GL_DEPTH_BITS, &depthbits);
-
-                       for (i = 1; i < depthbits; i++) {
-                               depthmax = (depthmax << 1) + 1;
+#if 0
+                       offs = 0.00001f * dist * viewdist;  // ortho tweaking
+#else
+                       static float depth_fac = 0.0f;
+                       if (depth_fac == 0.0f) {
+                               int depthbits;
+                               glGetIntegerv(GL_DEPTH_BITS, &depthbits);
+                               depth_fac = 1.0f / (float)(depthbits - 1);
                        }
-                       offs = (-1.0 / winmat[10]) * dist / (double) depthmax;
-                       //offs = 0.00001f * dist * viewdist;  // ortho tweaking
+                       offs = (-1.0 / winmat[10]) * dist * depth_fac;
+#endif
+               }
+               else {
+                       /* should be clipping value or so... */
+                       offs = 0.0001f * dist;
                }
-               else offs = 0.0001f * dist;  // should be clipping value or so...
                
                winmat[14] -= offs;
                offset += offs;