diff options
author | Sven Gothel <[email protected]> | 2012-02-20 18:03:36 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-02-20 18:03:36 +0100 |
commit | a4c7bf0420e369e71561d2847f2fc444ce5abafa (patch) | |
tree | eaf13946a0ef653fc9de163a911484be10f33379 /src/jogl/classes/jogamp | |
parent | 505525c857bc4d62815a69463e263d0c2c847ac1 (diff) |
API Change [GLProfile/GLContext]: Add notion of hardware acceleration in GLProfile.get<Profile>() methods.
We need to distinguish between software and hardware accelerated OpenGL profiles
to allow choosing the proper profiles [default, GL2ES1, GL2ES2, ..]
on platforms where both, software and hardware implementations exist (GL, GLES2, ..).
Where no preference is being requested, hardware acceleration is favored:
GLProfile.getDefault()
GLProfile.getGL2ES1()
GLProfile.getGL2ES2()
Some method signatures needed to change
GLProfile:
getMaxProgrammable(AbstractGraphicsDevice device) ->
getMaxProgrammable(AbstractGraphicsDevice device, boolean favorHardwareRasterizer)
GLProfile adds: isHardwareRasterizer()
Determination whether a hardware acceleration is being used or not
is extended in GLContextImpl by querying the current context's
GL_RENDERER string. If the latter contains 'software' (case insensitive)
it is not hardware accelerated. At least this works w/ newer Mesa3D impl,
where GLX_SLOW_CONFIG is not set!
Diffstat (limited to 'src/jogl/classes/jogamp')
4 files changed, 64 insertions, 15 deletions
diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index 1924ba409..08a9baeb9 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -514,14 +514,43 @@ public abstract class GLContextImpl extends GLContext { } if (DEBUG) { if(created) { - System.err.println(getThreadName() + ": !!! Create GL context OK: " + toHexString(contextHandle) + " for " + getClass().getName()); + System.err.println(getThreadName() + ": !!! Create GL context OK: " + toHexString(contextHandle) + " for " + getClass().getName()+" - "+getGLVersion()); } else { System.err.println(getThreadName() + ": !!! Create GL context FAILED for " + getClass().getName()); } - } + } if(!created) { return CONTEXT_NOT_CURRENT; } + + // finalize mapping the available GLVersions, in case it's not done yet + { + final AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration(); + final AbstractGraphicsDevice device = config.getScreen().getDevice(); + + if( !GLContext.getAvailableGLVersionsSet(device) ) { + final int reqMajor; + final int reqProfile; + if( 0 != ( ctxOptions & GLContext.CTX_PROFILE_ES) ) { + // ES1 or ES2 + reqMajor = ctxMajorVersion; + reqProfile = GLContext.CTX_PROFILE_ES; + } else { + // Only GL2 actually + if(ctxMajorVersion>2 || 0 != ( ctxOptions & GLContext.CTX_PROFILE_CORE)) { + throw new InternalError("XXX: "+getGLVersion()); + } + reqMajor = 2; + reqProfile = GLContext.CTX_PROFILE_COMPAT; + } + GLContext.mapAvailableGLVersion(device, reqMajor, reqProfile, + ctxMajorVersion, ctxMinorVersion, ctxOptions); + GLContext.setAvailableGLVersionsSet(device); + if (DEBUG) { + System.err.println(getThreadName() + ": !!! createContextOLD-MapVersionsAvailable HAVE: " +reqMajor+"."+reqProfile+ " -> "+getGLVersion()); + } + } + } GLContextShareSet.contextCreated(this); return CONTEXT_CURRENT_NEW; } @@ -714,7 +743,7 @@ public abstract class GLContextImpl extends GLContext { } } if(0!=_context) { - AbstractGraphicsDevice device = drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(); + AbstractGraphicsDevice device = drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(); // ctxMajorVersion, ctxMinorVersion, ctxOptions is being set by // createContextARBVersions(..) -> setGLFunctionAvailbility(..) -> setContextVersion(..) GLContext.mapAvailableGLVersion(device, reqMajor, reqProfile, ctxMajorVersion, ctxMinorVersion, ctxOptions); @@ -729,10 +758,10 @@ public abstract class GLContextImpl extends GLContext { }*/ destroyContextARBImpl(_context); if (DEBUG) { - System.err.println(getThreadName() + ": !!! createContextARBMapVersionsAvailable HAVE: " + getGLVersion()); + System.err.println(getThreadName() + ": !!! createContextARB-MapVersionsAvailable HAVE: " +reqMajor+"."+reqProfile+ " -> "+getGLVersion()); } } else if (DEBUG) { - System.err.println(getThreadName() + ": !!! createContextARBMapVersionsAvailable NOPE: "+reqMajor+"."+reqProfile); + System.err.println(getThreadName() + ": !!! createContextARB-MapVersionsAvailable NOPE: "+reqMajor+"."+reqProfile); } resetStates(); } @@ -951,11 +980,12 @@ public abstract class GLContextImpl extends GLContext { } updateGLXProcAddressTable(); - AbstractGraphicsConfiguration aconfig = drawable.getNativeSurface().getGraphicsConfiguration(); - AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); - if(!drawable.getChosenGLCapabilities().getHardwareAccelerated()) { + if(!isCurrentContextHardwareRasterizer()) { ctxProfileBits |= GLContext.CTX_IMPL_ACCEL_SOFT; - } + } + final AbstractGraphicsConfiguration aconfig = drawable.getNativeSurface().getGraphicsConfiguration(); + final AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); + contextFQN = getContextFQN(adevice, major, minor, ctxProfileBits); if (DEBUG) { System.err.println(getThreadName() + ": !!! Context FQN: "+contextFQN+" - "+GLContext.getGLVersion(major, minor, ctxProfileBits, null)); @@ -1024,11 +1054,12 @@ public abstract class GLContextImpl extends GLContext { } protected final void removeCachedVersion(int major, int minor, int ctxProfileBits) { - AbstractGraphicsConfiguration aconfig = drawable.getNativeSurface().getGraphicsConfiguration(); - AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); - if(!drawable.getChosenGLCapabilities().getHardwareAccelerated()) { + if(!isCurrentContextHardwareRasterizer()) { ctxProfileBits |= GLContext.CTX_IMPL_ACCEL_SOFT; } + final AbstractGraphicsConfiguration aconfig = drawable.getNativeSurface().getGraphicsConfiguration(); + final AbstractGraphicsDevice adevice = aconfig.getScreen().getDevice(); + contextFQN = getContextFQN(adevice, major, minor, ctxProfileBits); if (DEBUG) { System.err.println(getThreadName() + ": !!! RM Context FQN: "+contextFQN+" - "+GLContext.getGLVersion(major, minor, ctxProfileBits, null)); @@ -1049,6 +1080,21 @@ public abstract class GLContextImpl extends GLContext { } } + private final boolean isCurrentContextHardwareRasterizer() { + boolean isHardwareRasterizer = true; + + if(!drawable.getChosenGLCapabilities().getHardwareAccelerated()) { + isHardwareRasterizer = false; + } else { + // On some platforms (eg. X11), a software GL impl. does not properly declare itself properly. + final GLDynamicLookupHelper glDynLookupHelper = getDrawableImpl().getGLDynamicLookupHelper(); + final long _glGetString = glDynLookupHelper.dynamicLookupFunction("glGetString"); + final String glRenderer = glGetStringInt(GL.GL_RENDERER, _glGetString).toLowerCase(); + isHardwareRasterizer = !glRenderer.contains("software"); + } + return isHardwareRasterizer; + } + /** * Updates the platform's 'GLX' function cache */ @@ -1259,4 +1305,7 @@ public abstract class GLContextImpl extends GLContext { gl.getGL2GL3().glDebugMessageInsertAMD(GLDebugMessage.translateARB2AMDCategory(source, type), severity, id, len, buf); } } + + /** Internal bootstraping glGetString(GL_RENDERER) */ + protected static native String glGetStringInt(int name, long procAddress); } diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java index c412bbe1d..91d05f945 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -205,7 +205,7 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { boolean hasRECTTextures = false; boolean hasAppleFloatPixels = false; { - GLProfile glp = GLProfile.get(sharedDevice, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP); + GLProfile glp = GLProfile.get(sharedDevice, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false); if (null == glp) { throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice); } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java index f40a5f0bf..5eafebc11 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLDrawableFactory.java @@ -292,7 +292,7 @@ public class WindowsWGLDrawableFactory extends GLDrawableFactoryImpl { sharedDevice.lock(); try { AbstractGraphicsScreen absScreen = new DefaultGraphicsScreen(sharedDevice, 0); - GLProfile glp = GLProfile.get(sharedDevice, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP); + GLProfile glp = GLProfile.get(sharedDevice, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false); if (null == glp) { throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice); } diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java index 4e8a35fa5..70e22476b 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXDrawableFactory.java @@ -229,7 +229,7 @@ public class X11GLXDrawableFactory extends GLDrawableFactoryImpl { } X11GraphicsScreen sharedScreen = new X11GraphicsScreen(sharedDevice, 0); - GLProfile glp = GLProfile.get(sharedDevice, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP); + GLProfile glp = GLProfile.get(sharedDevice, GLProfile.GL_PROFILE_LIST_MIN_DESKTOP, false); if (null == glp) { throw new GLException("Couldn't get default GLProfile for device: "+sharedDevice); } |