openscad/openscad — pull request #318 by nico (2013-03-23 22:41:19+00:00)
Title: Make the OpenGL display look good on retina displays.

DO NOT MERGE: This breaks "save as image" (this now only saves the lower left 1/4th of the viewport), and may have other issues. It's useful as a proof-of-concept though.

Qt doesn't support an official API for opting in to retina mode for GL
views yet. Behind the scenes, a QGLView uses an NSOpenGLView, which
needs a call to -setWantsBestResolutionOpenGLSurface:YES to opt in to
this mode.

This CL pokes at Qt internals to do this call -- due to QGLView.cc only
allowing C++ code, this is done by explicitly calling out to the
Objective-C runtime.

The reason this mode needs an explicit opt-in is because it requires
expicit code to support retina mode in OpenGL. OpenGL is pixel-based,
while Cocoa (and possibly Qt) use logical view coordinates, where one
coordinate corresponds to two physical pixels on retina displays.
Because of this, several parameters passed to OpenGL need to explicitly
be scaled by the view scale factor.

I did this in the visually obvious places in this patch, but I fairly
certainly missed a few places. I also didn't test image saving, which
might be broken to. (I also didn't test with a 32 bit build, which has
to use a slightly different Obj-C API, but that part has a chance of
being correct.)

Another thing this patch doesn't handle is dynamic scale factor changes,
which happen when dragging an OpenSCAD window from a retina display to
an external display. It's possible that it happens to work, but I
haven't tested it.