Code drop from //branches/cupcake/...@124589
diff --git a/opengl/libagl/matrix.cpp b/opengl/libagl/matrix.cpp
index 441da38..f175cda 100644
--- a/opengl/libagl/matrix.cpp
+++ b/opengl/libagl/matrix.cpp
@@ -98,8 +98,9 @@
     c->arrays.perspective = (c->clipPlanes.enable) ?
         ogles_vertex_clipAllPerspective3D : ogles_vertex_perspective3D;
     if (enables & (GGL_ENABLE_DEPTH_TEST|GGL_ENABLE_FOG)) {
-        c->arrays.perspective = (c->clipPlanes.enable) ?
-            ogles_vertex_clipAllPerspective3DZ : ogles_vertex_perspective3DZ;
+        c->arrays.perspective = ogles_vertex_perspective3DZ;
+        if (c->clipPlanes.enable || (enables&GGL_ENABLE_FOG))
+            c->arrays.perspective = ogles_vertex_clipAllPerspective3DZ;
     }
     if ((c->arrays.vertex.size != 4) &&
         (c->transforms.mvp4.flags & transform_t::FLAGS_2D_PROJECTION)) {