Merge pull request #93 from Psychtoolbox-3/master

Post-Release fix for BETA: Pull fix for OSX on Apple MacBookPro with Retina display.
Merge pull request #95 from Psychtoolbox-3/master

Post-Release fix for BETA: OSX support for NVidia GeForce 600 Kepler gpu's.

* On OSX by updating the PsychtoolboxKernelDriver for 64-Bit kernels.
* Also enable experimental support for 4 display heads on Kepler gpus.
* Small fixes to PsychDataPixx and panel scaler support for side-by-side stereo.
Merge pull request #97 from Psychtoolbox-3/master

Post-Release update "Aaron Swartz" for PTB BETA RELEASE "The fun in dysfunction"

This update is dedicated to Aaron Swartz.

Some improvements to M-Files:

* Full panelfitter high-level setup support via PsychImaging('AddTask', 'General', 'UsePanelFitter'): Selection of common scaling/fitting modes. Fully compatible with all stereo display modes, high-precision display modes and other PsychImaging tasks. Also fully compatible with RemapMouse() now.

* Cleanups to BeampositionTests by Ian A.

* Robustness improvements to GStreamer-SDK detection on 64-Bit Windows.

* Tiny fixes in moglmorpher() and LoadOBJFile().

* Minor tweaks to some demos.
Screen/Linux: Initial check-in of Waffle display backend.

PsychWindowGlueWaffle.c implements a Linux display glue
layer based on Chad Versace's Waffle rendering/display
backend selection library:

http://cgit.freedesktop.org/~chadversary/waffle

It will be used to run the Linux PTB with other display
backends than X11+GLX and other rendering backends than
OpenGL-2 desktop core. This is mostly useful for gently
testing out the waters with Wayland, and for porting to
embedded/mobile devices like Android tablets/phones and
things like Rasperry Pi et al.

It is unlikely that a pure Waffle backend, at least in
unmodified form, will be a good permanent fit. Likely
either Waffle needs to be customized/extended for our
use, or we need to implement our own backends. But as
a cheap and relatively pain-free starter it should
hopefully be good enough.

This is a backup commit: The file is just a copy of
our regular X11+GLX display glue, with indent run over
it to cleanup the white-space and formatting mess that
accumulated over the years.
glew: Expose glewInitContext(), which is usually static.

To allow us to bypass glewInit() which would wreak havoc
when called from the Waffle backend due to calling the GLX
specific code without the GLX backend initialized.

-> An ugly hack to get going. Better to upgrade GLEW in the future.
Screen/Linux: Make sure X11 mouse cursor shape setup is only called on X11 window.

Only with a X11 based backend can we change mouse pointer appearance.
Screen/Linux: Fix Waffle backend integration further.
Screen/Linux: Implement fully separate backends for X11/GLX and Waffle.

No intermixing anymore. Two separate implementation files, one
PsychWindowGlue.c for the classic X11/GLX implementation, as in
the past. One PsychWindowGlueWaffle.c for the Waffle based backend.

The #define PTB_USE_WAFFLE selects between both backends at compile
time, both implement all required function prototypes/implementations.
Some of the special GLX functions are no-ops if the Waffle backend is
in use, even if Waffle uses X11/GLX.

PsychRealtimePriority() and PsychOSProcessEvents() are shared between
both backends, and adapted accordingly.

Some other small adaptations are made to avoid compiler warnings.
Screen/Linux: One step further for waffle.

* Default to X11/GLX "classic" backend.
* Make backend selectable via environment variable PSYCH_USE_GFX_BACKEND.
* On failure, probe all available backends until success.

* Fix display init path and make display selectable via PSYCH_WAFFLE_DISPLAY
  for non-X11 display backend, and regular screenId for X11 backend.

* Enable special setup code for X11 backends/windows and for GLX backend.
  -> Some but not all stuff works so far.
Screen/Linux: Fix all Windowing modes for Waffle with X11/GLX backend.

These modifications to the waffle backend make sure that the
X11/GLX windows as created by waffle behave almost like their
counterparts created by our classic X11/GLX backend. Fullscreen
windows get properly excluded from desktop composition for proper
timing. Non-Fs windows show without decorations, fully opaque, and
left alone by the window manager, always unoccluded and on top of
all other windows. GUI windows show proper decorations, buttons and
interaction with regular desktop GUI. Transparent windows are properly
transparent to mouse and keyboard but stay at top of other windows.

This works fine with KDE's KWin, but causes random GUI hangs on
Unity+Compiz. Given how well all this stuff works on most desktop
GUI's and how fragile it has become lately even with the classic
backend on Unity i really doubt Unity is of any use for us -- or
any other compiz based GUI.
Screen/Linux: Use shared waffle display connection for all windows.

As an intermediate stepping stone until we have per-display
display handles like for x11. This allows creation of shared
OpenGL contexts, as shared contexts require shared connections,
at least for the X11/GLX backend.
Screen/Linux: Add vsync for EGL backend, Waffle OpenGL selection.

Allow selection of rendering backend via env variable PSYCH_USE_DISPLAY_BACKEND,
implement robust fallbacks, and make sure backend can be selected only once
per octave / matlab session, as this can be performed only once during a
process lifetime.

Allow selection of OpenGL API (OpenGL desktop, ES-1, ES-2, ES-3) via env variable
PSYCH_USE_GFX_BACKEND, and implement fallbacks if requested backend is not
available. Default to desktop OpenGL, then OpenGL-ES3/2/1.

Make sure debug output respects verbosity levels.

Implement GLX vsync control support (SGI/MESA sync control extensions).
Implement vsync control for EGL based backends via eglSwapInterval(). This
does not have an effect on my test machine with nouveau, but the api does
not report errors, so this seems to be a missing feature of my graphics stack,
not a bug in EGL or our backend code.

The whole display backend selection & setup, rendering api selection and setup
should be reasonably ok for the first iteration now.

Need to pass info about selected backend/api to higher-level code, so it
can make different selection of rendering pathways etc. depending on this.
This is tbd.
Screen/Linux: Store backend/api types in windowRecord.

Define new windowRecord->specialFlags to signal to higher level
code if a window is using a X11 backend, and the GLX or EGL api
for display control. Use new field glApiType to define type of
rendering api in use: 0 = Desktop OpenGL, 10=ES-1, 20=ES-2, 30=ES-3,
so higher level code can select different rendering pathways as
appropriate.

Disable all OpenGL error checking and handling for OpenGL-ES api's
for now during bringup, where we need to keep going.
Screen/Linux: Make display backend and graphics backend selection human friendly.

Use human friendly namestrings for env vars instead of hex codes:

PSYCH_USE_DISPLAY_BACKEND accepts: glx, x11egl, wayland, gbm, android.
PSYCH_USE_GFX_BACKEND accepts: gl, gles1, gles2, gles3.
Screen: Factor out classic swapbuffersdone-wait into PsychWaitPixelSyncToken().

Our classic draw-pixel-as-a-sync-token-and-wait-for-it trick to wait
for doublebuffer swap completion is now factored out into a shared
function PsychWaitPixelSyncToken(). This allowed to implement a version
of the trick that works on OpenGL-ES.
Add PsychAllocInFloatMatArg() and make PsychAllocInFloatMat64Arg() more accepting.

PsychAllocInFloatMatArg() wraps around PsychAllocInFloatMat64Arg() and allows
use of size arguments of type int (aka 32-Bit signed integer) instead of
psych_int64.

PsychAllocInFloatMat64Arg() (and in extension PsychAllocInFloatMatArg()) will
convert an input matrix of double() type automatically into single() type,
ie. from C-Type double to C-Type float. It does this transparently to calling
code by allocating a temporary buffer and copying double input data into it,
after casting the double data to float data.

-> Simplifies calling code that absolutely needs float input, but from
usercode which is designed to deliver double input. E.g, for transparent
porting of code from OpenGL to OpenGL-ES target systems.
Screen: Upgrade GLEW to current latest version 1.9.0

This is needed to pull in function definitions for needed
OpenGL-ES API and corresponding OES extensions.

This makes our own typdef of glXGetSwapIntervalMESA() redundant,
as GLEW 1.9.0 defines this, so remove our own defs from Linux
Windowglue.
Screen: Rudimentary enablement for OpenGL-ES1.1 rendering.

PsychSetupView() must use glOrthofOES() instead of gluOrtho2D(),
as the latter is not supported on OpenGL-ES.

PsychGLGlue.c gets new helper functions for detecting if
we're executing on embedded subset, and adapting to it:

* glVertex/Color/TexCoordPointer() et al. only accept GL_FLOAT and
  sometimes GL_UNSIGNED_BYTE data, but not GL_DOUBLE. Therefore
  PsychSetupRenderBatch() must convert any double input data into
  float data, if neccessary by use of a temporary memory copy and
  lots of expensive copy + casting, but ideally by simply accepting
  input in single() data type which is already GL_FLOAT, or input
  in uint8 data type.

* glColorPointer() only accepts 4-component RGBA input data, not RGB
  3-component data, so PsychSetupRenderBatch() must again do a copy-
  conversion via temporary buffers to accomodate this.

* PsychSetGLColor() must accomodate that glColor4dv et al. don't exist
  in OpenGL-ES, but only glColor4f().

The new helpers are:

- PsychIsGLClassic(windowRecord): True on Desktop OpenGL 1/2, false otherwise.
- PsychIsGLES(windowRecord): True on OpenGL-ES.
- PsychGLFloatType(windowRecord) and PSYCHGLFLOAT - Returns GL_FLOAT on
  embedded subset, GL_DOUBLE on desktop OpenGL. The latter is a macro,
  assuming the windowRecord is stored in a variable named "windowRecord".
- PSYCHEXECNONGLES(x): Macro which executes command "x" only on desktop
  OpenGL, but skips/no-ops it on OpenGL-ES.

=> This does not provide full compatibility, but at least brings in
   minimal functionality.
Screen: Make Screen('DrawDots') functional on OpenGL-ES 1.x

By making use of the new functions defined in previous commit.

Also required replacing glTranslated() with glTranslatef() but
that should not incur any relevant loss of precision in Screen(),
as double precision might only be helpful when concatenating many
matrix transforms - something that never happens inside Screen(),
only possibly by 3rd party rendering code in MOGL et al.

-> DotDemo now works in non-sprite mode, ie. when drawing actual
   dots via fixed-function pipeline under EGL + OpenGL-ES 1.1.

=> Screen for 64-Bit Octave on Linux rebuilt and tested.
Screen: Make Screen('DrawLines') functional on OpenGL-ES 1.

Changes analog to Screen('DrawDots') in previous commit.
Additionally implement smooth type 2 for GL_NICEST smoothing and
fix a bug in aliased line width query.