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.
Screen: Make all standard Screen() drawing functions OpenGL-ES-1 compatible.

PsychGLGlue.c now provides helper functions which allow to
emulate the basic behaviour of classic immediate mode rendering
via commands like glBegin()/glEnd()/glVertex2f/... on top of
vertex array support.

We maintain our own fixed size buffer for vertex position, color and
texture coordinates and point the vertex array functions to it and
glDrawArrays() from it. We provide reimplementations of glBegin/glEnd/
glVertex etc. which fill provided data into the buffer. Each glEnd
will trigger a glDrawArrays op from the buffer, effectively flushing
its primitives to the pipeline. Rinse, wash, repeat...

Some helper macros in Screen.h make this even simpler for the common
case that our windowRecord is stored in a variable named 'windowRecord'.

PsychSetGLColor(), PsychSetArrayColor(), PsychPrepareRenderBatch() et al.
have been reworked again to update the state of this cache "as if" it were
immediate mode state.

glRectd() has been reimplemented as a triangle strip draw with two
triangles forming a axis aligned quad, as glRectd() or GL_QUADS don't
exist anymore.

gluDisc/gluPartialDisc have been reimplemented for 'Frame/Fill/DrawArc' and
'Frame/FillOval' and 'gluDisk' drawing with our own code.

'FillPoly' now always uses the slow-path via GLU tesselator, because
GLU tesselator only emits GL_TRIANGLE primitives (strips, fans, singles),
not the unsupported GL_POLYGON which our fast-path would need.

The code dynamically switches rendering pathes: On classic desktop OpenGL
it uses the native implementations to stay compatible and at same level
or performance to existing ptb and avoid regressions as much as possible.

On OpenGL-ES, the new - sometimes somewhat slower, as unoptimized - rendering
pathes are used.

Todo: DrawTexture, DrawText, CopyWindow etc.
Screen: Make textures functional on OpenGL-ES-1

Screen('Maketexture/DrawTexture/DrawTextures') as well as video capture
and movie playback works. Drawing into classic offscreen windows and
Screen('CopyWindow') work as well.

ES is limited to 8-Bit textures, or more specifically, to Luminance,
Luminance+Alpha, RGB or RGBA textures of unspecified precision. But
the assumption is that usually 8-Bit fixed point storage for 256 levels
per color component are supported by the underlying hardware.

This also enables use of non-power-of-two GL_TEXTURE_2D textures if
the GL_OES_texture_npot extension is available - Usually only on
ES-2, not ES-1 though.
Screen: Make stereomodes 4 and 5 work, 2 and 3 fail, and clearmode 1 work on ES.

Stereomodes 2 and 3 can't work due to lack of AUX buffer support on OpenGL-ES1.
Make sure this fails gracefully with a helpful error message.

Make modes 4 and 5 for side-by-side stereo work by using OES specific
glOrthofOES() function for projection setup.

Make clearmode 1 "don't clear" work by use of non-AUX-Buffers fallback.

-> StereoDemo now either works (modes 0,4,5,6,7,8,9) or fails with
   meaningful error message (1,2,3,11,...).

-> MouseTraceDemo2 now works.