Bug 1203

Summary: Fix EGL Backend (EGLDrawableFactory) for general Desktop OpenGL Context
Product: [JogAmp] Jogl Reporter: Sven Gothel <sgothel>
Component: coreAssignee: Sven Gothel <sgothel>
Status: RESOLVED FIXED    
Severity: major CC: sgothel
Priority: ---    
Version: 2.3.2   
Hardware: All   
OS: all   
Type: --- SCM Refs:
e8d66b1cd2b48899b7a012d54ba83d5c2a449b0a 618f6380b6eb6a96f8f1829c1dfb621a71209711 c835cdddfb37c5e8df424f984b821163b5645198 390ccc3e549e4cc13b7dab91387e72c1f10b77a9 09b269423f11d0f867831b91d989a6bebbd87738 45e58f4884108a300f08fd9af6aee82121376974 50d4fd0210a417ba0fcbf73a90e50a86ef076cad b8ba30a0bc7cbd36abba37d72b45f78eb989e994 99a064327bf991318841c858d21d13e55d6b39db 472d97e821520235eb006f3c135df2f629494326 da4d07c2bc633a4660a3ad2b67600fa8b4cb8506 08217de7bc0e0ffd09bd6c85d8c6d55ac63cfa33 cda92c2cc066c18ab30b828592e1979ab535441c 365d273115a98ab38c454608448c6639c45b5f74 3ac457a3a9074a70bf428bb6a5674b8f70d268b1 18e487fdfe6f27564d976aa3a568d0ddc272d8ba 5acb70d3d301fe66e4d03037325a91528e4c2c1d
Workaround: ---
Bug Depends on: 896, 1207    
Bug Blocks:    

Description Sven Gothel 2015-08-27 19:38:52 CEST
Fixes applied for Bug 896 were not satisfactory
to allow using the EGL backend (EGLDrawableFactory)
to seamlessly handle ES1, ES2 _and_ desktop OpenGL profiles/context.

- GLContextImpl.mapGLVersions(..) must handle EGL based context as well.

- Desktop OpenGL shall be supported by EGL only
  if 'OpenGL API' _and_ EGL_KHR_create_context is supported.

- State-less operation during profile probing (mapGLVersions).
  While probing the GLDrawable/GLProfile and GL instance
  may not reflect the currently probed OpenGL profile.
  Hence stateless operation by passing required information
  is required for:
  - GLDynamicLookupHelper must be fetched via 
    'major-version and contextOptions'.
  - GLContextImpl.resetProcAddress(..)
  - GLContextImpl.updateGLXProcAddressTable()
  - GLContextImpl.setGLFunctionAvailability(..) 
  - ExtensionAvailabilityCache

- Last but not least, EGLDrawableFactory.mapAvailableEGLESConfig(..)
  shall be reduced to just choose the shared-instance
  and perform GLContextImpl.mapGLVersions(..).

  If the shared-instance simply reused the dummy-instance (default),
  all mapped profiles shall also be mapped to the actual requested device
  to avoid a GLContextImpl.mapGLVersions(..) re-run.

  The shared-instance may reuse the dummy-instance for:
    - EGL devices
    - Default upstream devices:
      - Any Windows or OSX
      - Any X11 default display connections

  The dummy-instance shall not being used for remote network connections (X11)
  or the like, here a dedicated GLContextImpl.mapGLVersions(..) run is required.
Comment 1 Sven Gothel 2015-08-28 01:08:31 CEST
Bug 1207, supporting GL_KHR_debug, 
shall ensure GLDebugMessageHandler is also well supported 
for both world (desktop/es).
Comment 2 Sven Gothel 2015-08-30 02:50:20 CEST
commit e8d66b1cd2b48899b7a012d54ba83d5c2a449b0a
Bug 1203: Properly format DEBUG output related to mapGLVersions: Use '-MapGLVersions' suffix.

commit 618f6380b6eb6a96f8f1829c1dfb621a71209711
Bug 1203: SharedResourceRunner.Implementation impl. shall use AbstractGraphicsDevice's uniqueID instead of connection

AbstractGraphicsDevice's uniqueID supports multiple device types and units while including the connection.
This is required for proper EGLDrawableFactory's profile probing on different native platform devices.

Using common abstract implementation 'AImplementation'
for WindowsWGL's, X11GLX's and EGL's DrawableFactory.

commit c835cdddfb37c5e8df424f984b821163b5645198
Bug 1203: Use platform native default display connection

On networking windowing systems (X11), we shall utilize the real
native default display connection.

On X11, this is X11Util.getNullDisplayName(),
for other non networking types, this is AbstractGraphicsDevice.DEFAULT_CONNECTION.

commit 390ccc3e549e4cc13b7dab91387e72c1f10b77a9
Bug 1203: GLDrawable-Stateless operations in GLContextImpl, using ctxVersion and ctxOptions

- State-less operation during profile probing (mapGLVersions).
  While probing the GLDrawable/GLProfile and GL instance
  may not reflect the currently probed OpenGL profile.
  Hence stateless operation by passing required information
  is required for:
  - GLDynamicLookupHelper must be fetched via
    'major-version and contextOptions'.
  - GLContextImpl.resetProcAddress(..)
  - GLContextImpl.updateGLXProcAddressTable()
  - GLContextImpl.setGLFunctionAvailability(..)
  - ExtensionAvailabilityCache

TODO: Add replacement for GLProfile validation,
which is disabled right now.:
  drawable.getGLProfile().verifyEquality(gl.getGLProfile())

The GLDrawable.GLProfile maybe less than GL's GLProfile
due to current context-version and options.
Hence we would need a 'GLProfile.bwCompatibleWith(GLProfile)'.

commit 09b269423f11d0f867831b91d989a6bebbd87738
Bug 1203: Fix GLES3Impl.getGLES3(): Test _isES3 and throw GLException if not.

commit 45e58f4884108a300f08fd9af6aee82121376974
Bug 1203: EGLGraphicsDevice.nativeDisplayID: Differentiate upstream device's native handle via own ctor, reducing redundancy

commit 50d4fd0210a417ba0fcbf73a90e50a86ef076cad
Bug 1203: Refine DEBUG output

commit b8ba30a0bc7cbd36abba37d72b45f78eb989e994
Bug 1203: Cleanup and Prepare for regular EGL Profile probing

- GLContextImpl
  - add 'MappedGLVersion' type, preserving information from GL profile mapping

  - add 'MappedGLVersion mapAvailableGLVersion(..)'

  - add 'setMappedGLVersionListener(final MappedGLVersionListener mvl)',
    allowing implementations to register successfully mapped profiled.

  - add 'void remapAvailableGLVersions(final AbstractGraphicsDevice fromDevice, final AbstractGraphicsDevice toDevice)',
    allowing implementations to fully map one-devices profiles to another one
    avoiding a redundant profile mapping (probe operation).

  - 'mapGLVersions(..)'
    - disable desktop-core profile mapping if GLProfile.disableOpenGLDesktop
    - disable desktop-desktop profile mapping if GLProfile.disableOpenGLDesktop

- EGLDrawableFactory
  - remove jogl.debug.EGLDrawableFactory.QueryNativeTK,
    since it shall not be used anymore.

  - Use 'NativeWindowFactory.getDefaultDisplayConnection(..)'
    for default EGLGraphicsDevcie

  - add 'hasFullOpenGLAPISupport()'

  - Use 'EGLSurface' return type if appropriate.

commit 99a064327bf991318841c858d21d13e55d6b39db
Bug 1203: Implement regular EGL OpenGL Profile probing (ES* + GL*)

- GLProfile
  - Add 'hasGL234OnEGLImpl' handling, i.e. GL* profiles on EGL devices

  - Properly handle EGL's 'GLDynamicLookupHelper' queries for ES2, ES1 and GL* profiles,
    i.e. allow each one to fail seperately.

  - Merge computed EGL-Profile-Map (1) and Desktop-Profile-Map (2)
    per device, instead of just using the last computation,
    preserving and favoratizing the Desktop-Profile-Map.

- GLContextImpl.mapGLVersions(..): Map ES* profiles if having an EGLGraphicsDevice
  and not disabled via GLProfile.disableOpenGLES.

- EGLContext
  - createContextARBImpl(..): Use the EGL_CONTEXT_MINOR_VERSION_KHR if supported

  - GLContext* accessibility: Remove unused entries, add newly used ones

- EGLDrawableFactory
  - Fix a bug regarding detection of 'OpenGL' API for EGL

  - SharedResource: Use detailed knowledge of each profile

  - Only create one drawable and context for probing maximum,
    utilizing 'GLContextImpl.MappedGLVersionListener'
    to detect all mapped profiles for 'SharedResource' instance.

  - Detect whether the probed/mapped device
    can be mapped to the default-EGL-device, i.e.:
      - current device is not the default-EGL-device
      - default-EGL-device is valid and could be mapped (beforehand)
      - same connection
    In this case, no probing/mapping is performed
    and the default-EGL-device mapped data being reused and remapped
    to the requested device.

  - When mapping/probing, attempt to use a surfaceless context first,
    allowing same codepath for default-EGL-device and native-device (X11, ..).
    This avoids using pbuffer if using default-EGL-device
    and a dummy onscreen window if using a native-device (X11, ..).
    If this fails, continue as usual ..
      - default-EGL-device -> pbuffer
      - native-device (X11, ..) -> dummy onscreen window

commit 472d97e821520235eb006f3c135df2f629494326
Bug 1203: EGLDrawableFactory.mapAvailableEGLESConfig(..): Add missing close on device (surfaceless); Remove one try-finally block

commit da4d07c2bc633a4660a3ad2b67600fa8b4cb8506
Bug 1203: Adding factory-offscreen unit test, validating ES/GL usage with EGL and Desktop GLDrawableFactory

commit 08217de7bc0e0ffd09bd6c85d8c6d55ac63cfa33
Bug 1203: Fix regression of ES3 minMajor constraint lack (commit b8ba30a0bc7cbd36abba37d72b45f78eb989e994)

commit b8ba30a0bc7cbd36abba37d72b45f78eb989e994's
GLContextImpl.createContextARBMapVersionsAvailable(..)
accepted minMajor=2 for ES3 detection -> wrong of course.

commit cda92c2cc066c18ab30b828592e1979ab535441c
Bug 1203: Fix TestGLAutoDrawableFactoryGLProfileDeviceNEWT: Do not assume EGL/Desktop factories are available!

commit 365d273115a98ab38c454608448c6639c45b5f74
Bug 1203: Fix regression: Handle GLRendererQuirks.GLES3ViaEGLES2Config

Need to handle GLRendererQuirks.GLES3ViaEGLES2Config,
i.e. a created ES3 context via ES2 request must result in
mapping ES3 as well.

commit 3ac457a3a9074a70bf428bb6a5674b8f70d268b1
Bug 1203: Optimize OpenGL Profile probing/mapping (Skip redundant queries)

Via GLDrawableFactory[Impl] the following details are considered
while GLContextImpl.mapGLVersions(..):
  - hasOpenGLDesktopSupport
    If false, skip OpenGL Desktop queries

  - hasOpenGLESSupport
    If false, skip OpenGL ES queries

  - hasMajorMinorCreateContextARB
    If false, reduce [maxMajor.maxMinor..minMajor.minMinor]
    iteration, reducing to [maxMajor..minMajor],
    usually only one query.
Comment 3 Sven Gothel 2015-08-30 05:05:22 CEST
commit 18e487fdfe6f27564d976aa3a568d0ddc272d8ba
    Bug 1203: OpenGL ES 3.1 NVIDIA 355.06's EGL impl. is unstable requires GLRendererQuirk.SingletonEGLDisplayOnly
    
    Test cases with multiple EGLDisplay init/terminate result to crashes
    due to NVidia's 355.06 driver.
    
    Hence enable GLRendererQuirk.SingletonEGLDisplayOnly
    if EGL vendor is NVIDIA until a good driver version is known.
Comment 4 Sven Gothel 2015-08-30 06:28:11 CEST
5acb70d3d301fe66e4d03037325a91528e4c2c1d

    Bug 1203: Add missing constraints in desktop *GLContext.create* methods: Bail out if GL ES is requested ; Fix test case
    
    *GLContext.createImpl(..) shall throw an GLException:
    *GLContext.createContextARBImpl(..) shall return 0:
      - Desktop implementation: if GL ES is requested
      - EGL implementation: if GL Desktop is requested, but not available
    
    Otherwise GLContextImpl may mistake a desktop context for an ES one.
    
    +++
    
    Fix unit test TestGLAutoDrawableFactoryGLProfileDeviceNEWT.test11ES2OnDesktop():
      We have to query the factory by desired profile,
      since the desktop factory cannot produce an GL ES context.
Comment 5 Sven Gothel 2015-08-30 07:01:17 CEST
Implementation passed on desktop (X11, Windows, OSX) 
and embedded (Android) platforms.

The former w/ and w/o Desktop-OpenGL via EGL.

In case this work causes regressions due to quirky drivers
or even a bug.
Followup bugs shall be filed referencing this one.