public EGLWrappedSurface(final NativeSurface surface) { super(surface.getGraphicsConfiguration(), EGL.EGL_NO_SURFACE, new EGLUpstreamSurfaceHook(surface), false /* tbd in UpstreamSurfaceHook */); if(EGLDrawableFactory.DEBUG) { System.err.println("EGLWrappedSurface.ctor(): "+this); } }
@Override public final GLCapabilitiesImmutable getChosenGLCapabilities() { return (GLCapabilitiesImmutable) surface.getGraphicsConfiguration().getChosenCapabilities(); }
protected GLDrawableImpl(final GLDrawableFactory factory, final NativeSurface comp, final boolean realized) { this(factory, comp, (GLCapabilitiesImmutable) comp.getGraphicsConfiguration().getRequestedCapabilities(), realized); }
@Override protected void setRealizedImpl() { if(realized) { final X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)getNativeSurface().getGraphicsConfiguration(); config.updateGraphicsConfiguration(); if (DEBUG) { System.err.println(getThreadName()+": X11GLXDrawable.setRealized(true): "+config); } } }
@Override protected void setRealizedImpl() { if(realized) { final NativeSurface ns = getNativeSurface(); final WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration)ns.getGraphicsConfiguration(); config.updateGraphicsConfiguration(getFactory(), ns, null); if (DEBUG) { System.err.println(getThreadName()+": WindowsWGLDrawable.setRealized(true): "+config); } } }
public static StringBuilder getGLInfo(final GL gl, StringBuilder sb, final boolean withCapabilitiesAndExtensionInfo) { final AbstractGraphicsDevice device = gl.getContext().getGLDrawable().getNativeSurface() .getGraphicsConfiguration().getScreen().getDevice(); if(null==sb) { sb = new StringBuilder(); } sb.append(VersionUtil.SEPERATOR).append(Platform.getNewline()); sb.append(device.getClass().getSimpleName()).append("[type ") .append(device.getType()).append(", connection ").append(device.getConnection()).append("]: ").append(Platform.getNewline()); GLProfile.glAvailabilityToString(device, sb, "\t", 1); sb.append(Platform.getNewline()); sb = getGLStrings(gl, sb, withCapabilitiesAndExtensionInfo); if( withCapabilitiesAndExtensionInfo ) { sb = getAllAvailableCapabilitiesInfo(device, sb); } return sb; }
@Override protected GLDrawableImpl createOffscreenDrawableImpl(final NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); } final AbstractGraphicsConfiguration config = target.getGraphicsConfiguration(); final GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); if(!caps.isPBuffer()) { throw new GLException("Non pbuffer not yet implemented"); } // PBuffer GLDrawable Creation return new EGLPbufferDrawable(this, EGLWrappedSurface.get(target)); }
@Override public String toString() { return getClass().getName()+"[realized "+isRealized()+ ",\n\tfactory "+getFactory()+ ",\n\tsurface "+getNativeSurface()+ ",\n\teglSurface "+toHexString(surface.getSurfaceHandle())+ ",\n\teglConfig "+surface.getGraphicsConfiguration()+ ",\n\trequested "+getRequestedGLCapabilities()+ ",\n\tchosen "+getChosenGLCapabilities()+"]"; } }
@Override public String toString() { return getClass().getSimpleName()+"[Initialized "+initialized+", realized "+isRealized()+", texUnit "+texUnit+", samples "+samples+ ",\n\tFactory "+getFactory()+ ",\n\tHandle "+toHexString(getHandle())+ ",\n\tCaps "+surface.getGraphicsConfiguration().getChosenCapabilities()+ ",\n\tfboI back "+fboIBack+", front "+fboIFront+", num "+(initialized ? fbos.length : 0)+ ",\n\tFBO front read "+getDefaultReadFramebuffer()+", "+getFBObject(GL.GL_FRONT)+ ",\n\tFBO back write "+getDefaultDrawFramebuffer()+", "+getFBObject(GL.GL_BACK)+ ",\n\tSurface "+surface+ "]"; }
protected final boolean isGLXVersionGreaterEqualOneThree() { // fast-path: use cached boolean if(null != glXServerVersion) { return isGLXVersionGreaterEqualOneThree; } glXServerVersion = ((X11GLXDrawableFactory)drawable.getFactoryImpl()).getGLXVersionNumber(drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice()); isGLXVersionGreaterEqualOneThree = null != glXServerVersion ? glXServerVersion.compareTo(X11GLXDrawableFactory.versionOneThree) >= 0 : false; return isGLXVersionGreaterEqualOneThree; } protected final void forceGLXVersionOneOne() {
@Override public synchronized final void resetDisplayGamma(final NativeSurface surface) { if( NativeSurface.LOCK_SURFACE_NOT_READY >= surface.lockSurface() ) { return; } try { final AbstractGraphicsScreen screen = surface.getGraphicsConfiguration().getScreen(); final DeviceScreenID deviceScreenID = new DeviceScreenID(screen.getDevice().getConnection(), screen.getIndex()); final Buffer originalGammaRamp = screen2OrigGammaRamp.remove(deviceScreenID); if( null != originalGammaRamp ) { resetGammaRamp(surface, originalGammaRamp); } } finally { surface.unlockSurface(); } }
@Override public final boolean isGLReadDrawableAvailable() { if(!wglGLReadDrawableAvailableSet && null != getWGLExtProcAddressTable()) { final WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl(); final AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration(); final AbstractGraphicsDevice device = config.getScreen().getDevice(); switch( factory.isReadDrawableAvailable(device) ) { case 1: wglGLReadDrawableAvailable = true; wglGLReadDrawableAvailableSet=true; break; case 0: wglGLReadDrawableAvailable = false; wglGLReadDrawableAvailableSet=true; break; } } return wglGLReadDrawableAvailable; }
@Override protected final void swapBuffersImpl(final boolean doubleBuffered) { if(doubleBuffered) { final EGLGraphicsDevice eglDevice = (EGLGraphicsDevice) surface.getGraphicsConfiguration().getScreen().getDevice(); // single-buffer is already filtered out @ GLDrawableImpl#swapBuffers() if(!EGL.eglSwapBuffers(eglDevice.getHandle(), surface.getSurfaceHandle())) { throw new GLException("Error swapping buffers, eglError "+toHexString(EGL.eglGetError())+", "+this); } } }
private final void swapFBOImplPost(final GLContext glc) { // Safely reset the previous front FBO - after completing propagating swap if(0 <= pendingFBOReset) { final GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) surface.getGraphicsConfiguration().getChosenCapabilities(); reset(glc.getGL(), pendingFBOReset, getSurfaceWidth(), getSurfaceHeight(), samples, caps.getAlphaBits()>0, caps.getDepthBits(), caps.getStencilBits()); pendingFBOReset = -1; } }
@Override protected final void setRealizedImpl() { final MutableGraphicsConfiguration msConfig = (MutableGraphicsConfiguration) surface.getGraphicsConfiguration(); if(realized) { parent.setRealized(true); origParentChosenCaps = (GLCapabilitiesImmutable) msConfig.getChosenCapabilities(); final GLCapabilities chosenFBOCaps = (GLCapabilities) origParentChosenCaps.cloneMutable(); // incl. <Type>GLCapabilities, e.g. X11GLCapabilities chosenFBOCaps.copyFrom(getRequestedGLCapabilities()); // copy user values msConfig.setChosenCapabilities(chosenFBOCaps); } else { msConfig.setChosenCapabilities(origParentChosenCaps); parent.setRealized(false); } }
@Override protected GLDrawableImpl createOffscreenDrawableImpl(final NativeSurface target) { final MutableGraphicsConfiguration config = (MutableGraphicsConfiguration) target.getGraphicsConfiguration(); final GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); if(!caps.isPBuffer()) { // Actual implementation is using PBuffer ... final GLCapabilities modCaps = (GLCapabilities) caps.cloneMutable(); modCaps.setPBuffer(true); modCaps.setBitmap(false); config.setChosenCapabilities(modCaps); return new MacOSXOffscreenCGLDrawable(this, target); } return new MacOSXPbufferCGLDrawable(this, target); }
protected static WindowsBitmapWGLDrawable create(final GLDrawableFactory factory, final NativeSurface comp) { final WindowsWGLGraphicsConfiguration config = (WindowsWGLGraphicsConfiguration)comp.getGraphicsConfiguration(); final AbstractGraphicsDevice aDevice = config.getScreen().getDevice(); if( !GLProfile.isAvailable(aDevice, GLProfile.GL2) ) { throw new GLException("GLProfile GL2 n/a on "+aDevice+" but required for Windows BITMAP"); } final GLProfile glp = GLProfile.get(GLProfile.GL2); final GLCapabilitiesImmutable capsChosen0 = (GLCapabilitiesImmutable)config.getChosenCapabilities(); // RGB555 and also alpha channel is experienced to fail on some Windows machines final GLCapabilitiesImmutable capsChosen1 = GLGraphicsConfigurationUtil.clipRGBAGLCapabilities(capsChosen0, false /* allowRGB555 */, false /* allowAlpha */); final GLCapabilitiesImmutable capsChosen2 = GLGraphicsConfigurationUtil.fixGLProfile(capsChosen1, glp); if( capsChosen0 != capsChosen2 ) { config.setChosenCapabilities(capsChosen2); if(DEBUG) { System.err.println("WindowsBitmapWGLDrawable: "+capsChosen0+" -> "+capsChosen2); } } return new WindowsBitmapWGLDrawable(factory, comp); }
private void destroySharedGL() { if( null != sharedGLCtx ) { if( sharedGLCtx.isCreated() ) { // Catch dispose GLExceptions by GLEventListener, just 'print' them // so we can continue with the destruction. try { sharedGLCtx.destroy(); } catch (final GLException gle) { gle.printStackTrace(); } } sharedGLCtx = null; } if( null != dummyDrawable ) { final AbstractGraphicsDevice device = dummyDrawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(); dummyDrawable.setRealized(false); dummyDrawable = null; device.close(); } }
@Override protected boolean createImpl(final long shareWithHandle) throws GLException { final MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration(); final GLCapabilitiesImmutable capabilitiesChosen = (GLCapabilitiesImmutable) config.getChosenCapabilities(); final GLProfile glp = capabilitiesChosen.getGLProfile(); if( glp.isGLES() || ( glp.isGL3() && !isLionOrLater ) || ( glp.isGL4() && !isMavericksOrLater ) ) { throw new GLException("OpenGL profile not supported on MacOSX "+Platform.getOSVersionNumber()+": "+glp); } if( 0 != shareWithHandle && GLBackendType.NSOPENGL != getOpenGLMode() ) { throw new GLException("Context sharing only supported in mode "+GLBackendType.NSOPENGL+": "+this); } contextHandle = createContextARB(shareWithHandle, true); return 0 != contextHandle; }
public final synchronized void initGL(final GL gl) { final GLContext glCtx = gl.getContext(); final boolean glCtxCurrent = glCtx.isCurrent(); final GLProfile glp = gl.getGLProfile(); final GLDrawableFactory factory = GLDrawableFactory.getFactory(glp); final AbstractGraphicsDevice device = glCtx.getGLDrawable().getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(); dummyDrawable = factory.createDummyDrawable(device, true, glCtx.getGLDrawable().getChosenGLCapabilities(), null); // own device! dummyDrawable.setRealized(true); sharedGLCtx = dummyDrawable.createContext(glCtx); makeCurrent(sharedGLCtx); if( glCtxCurrent ) { makeCurrent(glCtx); } else { sharedGLCtx.release(); } } public final synchronized void doPause() {