Fix ortho part of T44505
authorAntony Riakiotakis <kalast@gmail.com>
Tue, 28 Apr 2015 18:41:37 +0000 (20:41 +0200)
committerAntony Riakiotakis <kalast@gmail.com>
Tue, 28 Apr 2015 18:41:49 +0000 (20:41 +0200)
In this case we can calculate an offset without worrying about
perspective correction. Unfortunately if looking from a camera we still
have depth issues here. There's no really general case that can fix this
so I'm leaving this as is.

source/blender/editors/screen/glutil.c

index 618d6906b7647d1f22b10a8d44906f27a4965c01..1ab03bfb7efcc701c46047f89b56656754c23b88 100644 (file)
@@ -991,7 +991,7 @@ void bgl_get_mats(bglMats *mats)
 /**
  * \note \a viewdist is only for ortho at the moment.
  */
-void bglPolygonOffset(float viewdist, float dist) 
+void bglPolygonOffset(float viewdist, float dist)
 {
        static float winmat[16], offset = 0.0;
        
@@ -1007,7 +1007,16 @@ void bglPolygonOffset(float viewdist, float dist)
                
                /* dist is from camera to center point */
                
-               if (winmat[15] > 0.5f) offs = 0.00001f * dist * viewdist;  // ortho tweaking
+               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;
+                       }
+                       offs = (-1.0 / winmat[10]) * dist / (double) depthmax;
+                       //offs = 0.00001f * dist * viewdist;  // ortho tweaking
+               }
                else offs = 0.0001f * dist;  // should be clipping value or so...
                
                winmat[14] -= offs;