private static void dumpGLInfo(final GLDrawableFactoryImpl factory, final AbstractGraphicsDevice device) { final GLContext ctx = factory.getOrCreateSharedContext(device); if(null != ctx) { System.err.println("GLProfile.dumpGLInfo: "+ctx); ctx.makeCurrent(); try { System.err.println(JoglVersion.getGLInfo(ctx.getGL(), null)); } finally { ctx.release(); } } else { System.err.println("GLProfile.dumpGLInfo: shared context n/a"); } }
if( null != oldCtx ) { if( destroyOldCtx ) { oldCtx.destroy(); } else { oldCtx.setGLDrawable(null, true); // dis-associate old pair newCtx.setContextCreationFlags(newCtxCreationFlags); newCtx.setGLDrawable(drawable, true); // re-associate new pair
public static final GL getCurrentGL() throws GLException { GLContext curContext = GLContext.getCurrent(); if (curContext == null) { throw new GLException("No OpenGL context current on this thread"); } return curContext.getGL(); }
/** * @throws GLException if this GLContext is not current on this thread */ public final void validateCurrent() throws GLException { if(getCurrent() != this) { throw new GLException(getThreadName()+": This context is not current. Current context: "+getCurrent()+", this context "+this); } }
/** * Returns the GL object bound to this thread current context. * If no context is current, throw an GLException * * @return the current context's GL object on this thread * @throws GLException if no context is current */ public static GL getCurrentGL() throws GLException { final GLContext glc = getCurrent(); if(null==glc) { throw new GLException(getThreadName()+": No OpenGL context current on this thread"); } return glc.getGL(); }
GLContext lastContext = GLContext.getCurrent(); Runnable lastInitAction = null; if (lastContext != null) { lastContext.release(); final boolean releaseContext; if( GLContext.CONTEXT_NOT_CURRENT == res ) { res = context.makeCurrent(); releaseContext = !_isExclusiveThread; ctxClaimed = true; context.release(); ctxReleased = true; } catch (final Throwable t) { final int res2 = lastContext.makeCurrent(); if (null != lastInitAction && res2 == GLContext.CONTEXT_CURRENT_NEW) { lastInitAction.run();
j2dContext.makeCurrent(); final GL gl = j2dContext.getGL(); if ((getGLInteger(gl, GL.GL_RED_BITS) < reqOffscreenCaps.getRedBits()) || (getGLInteger(gl, GL.GL_GREEN_BITS) < reqOffscreenCaps.getGreenBits()) || java2DGLPipelineOK = false; handleReshape = true; j2dContext.destroy(); j2dContext = null; return; j2dContext.makeCurrent(); captureJ2DState(j2dContext.getGL(), g); final Object curSurface = Java2D.getOGLSurfaceIdentifier(g); if (curSurface != null) { if (j2dSurface != curSurface) { if (joglContext != null) { joglContext.destroy(); joglContext = null; joglDrawable = null; final AbstractGraphicsDevice device = j2dContext.getGLDrawable().getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(); if (factory.canCreateExternalGLDrawable(device)) { joglDrawable = factory.createExternalGLDrawable(); j2dContext.release();
public final StringBuilder append(final StringBuilder sb) { sb.append("Version ").append(getGLVersion()).append(" [GL ").append(getGLVersionNumber()).append(", vendor ").append(getGLVendorVersionNumber()); sb.append("], options 0x"); sb.append(Integer.toHexString(ctxOptions)); sb.append(", this "); sb.append(toHexString(hashCode())); sb.append(", handle "); sb.append(toHexString(contextHandle)); sb.append(", isShared "+isShared()+", "); sb.append(getGL()); sb.append(",\n\t quirks: "); if(null != glRendererQuirks) { glRendererQuirks.toString(sb); } else { sb.append("n/a"); } if(getGLDrawable()!=getGLReadDrawable()) { sb.append(",\n\tRead Drawable : "); sb.append(getGLReadDrawable()); sb.append(",\n\tWrite Drawable: "); sb.append(getGLDrawable()); } else { sb.append(",\n\tDrawable: "); sb.append(getGLDrawable()); } return sb; }
GLContext lastContext = GLContext.getCurrent(); Runnable lastInitAction = null; if (lastContext != null) { lastContext.release(); res = context.makeCurrent(); if (GLContext.CONTEXT_NOT_CURRENT != res) { if(GLContext.CONTEXT_CURRENT_NEW == res) { try { if(destroyContext) { context.destroy(); } else { forceNativeRelease(context); final int res2 = lastContext.makeCurrent(); if (null != lastInitAction && res2 == GLContext.CONTEXT_CURRENT_NEW) { lastInitAction.run();
public void flushFrame(final boolean doSwap) { final GL gl = GLContext.getCurrentGL(); renderBuckets(); gl.glFlush(); if (doSwap) { doApplyState(defaultStateList.get(RenderState.StateType.ColorMask)); if (Constants.stats) { StatCollector.startStat(StatType.STAT_DISPLAYSWAP_TIMER); } checkCardError(); GLContext.getCurrent().getGLDrawable().swapBuffers(); if (Constants.stats) { StatCollector.endStat(StatType.STAT_DISPLAYSWAP_TIMER); } } if (Constants.stats) { StatCollector.addStat(StatType.STAT_FRAMES, 1); } }
@Override public final void swapBuffers() throws GLException { if( !realized ) { // volatile OK (locked below) return; // destroyed already } final int lockRes = lockSurface(); // it's recursive, so it's ok within [makeCurrent .. release] if (NativeSurface.LOCK_SURFACE_NOT_READY == lockRes) { return; } try { if( realized ) { // volatile OK final GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable)surface.getGraphicsConfiguration().getChosenCapabilities(); if ( caps.getDoubleBuffered() ) { if(!surface.surfaceSwap()) { swapBuffersImpl(true); } } else { final GLContext ctx = GLContext.getCurrent(); if(null!=ctx && ctx.getGLDrawable()==this) { ctx.getGL().glFlush(); } swapBuffersImpl(false); } } } finally { unlockSurface(); } surface.surfaceUpdated(this, surface, System.currentTimeMillis()); }
@Override public final GL getGL() { final GLContext _context = context; if (_context == null) { return null; } return _context.getGL(); }
@Override public void onPaint(CefBrowser browser, boolean popup, Rectangle[] dirtyRects, ByteBuffer buffer, int width, int height) { canvas_.getContext().makeCurrent(); renderer_.onPaint(canvas_.getGL().getGL2(), popup, dirtyRects, buffer, width, height); canvas_.getContext().release(); SwingUtilities.invokeLater(new Runnable() { public void run() { canvas_.display(); } }); }
/** * Since GLContext's {@link GLContext#makeCurrent()} and {@link GLContext#release()} * is recursive, a call to {@link GLContext#release()} may not natively release the context. * <p> * This methods continues calling {@link GLContext#release()} until the context has been natively released. * </p> * @param ctx */ public static final void forceNativeRelease(final GLContext ctx) { int releaseCount = 0; do { ctx.release(); releaseCount++; if (DEBUG) { System.err.println("GLDrawableHelper.forceNativeRelease() #"+releaseCount+" -- currentThread "+Thread.currentThread()+" -> "+GLContext.getCurrent()); } } while( MAX_RELEASE_ITER > releaseCount && ctx.isCurrent() ); if( ctx.isCurrent() ) { throw new GLException("Context still current after "+MAX_RELEASE_ITER+" releases: "+ctx); } }
@Override protected void swapBuffersImpl(final boolean doubleBuffered) { final GLContext ctx = GLContext.getCurrent(); boolean doPostSwap; if( null != ctx && ctx.getGLDrawable() == this && fboBound ) { swapFBOImpl(ctx); doPostSwap = true; fboSwapped = true; if(DEBUG_SWAP) { System.err.println("Post FBO swap(@swap): done"); } } else { doPostSwap = false; } if( null != swapBufferContext ) { swapBufferContext.swapBuffers(doubleBuffered); } if(doPostSwap) { swapFBOImplPost(ctx); } }
protected void drawOffscreen( GLContext glContext ) { OGLStackHandler stack = new OGLStackHandler( ); GL2 gl = glContext.getGL( ).getGL2( ); stack.pushAttrib( gl, GL2.GL_ALL_ATTRIB_BITS ); stack.pushClientAttrib( gl, ( int ) GL2.GL_ALL_CLIENT_ATTRIB_BITS ); stack.pushTexture( gl ); stack.pushModelview( gl ); stack.pushProjection( gl ); GLContext c = offscreenCanvas.getGLContext( ); if ( c != null ) { c.makeCurrent( ); try { offscreenCanvas.paint( ); } catch ( Exception e ) { logWarning( logger, "Trouble drawing to offscreen buffer", e ); } finally { glContext.makeCurrent( ); stack.pop( gl ); } } }
/** * @return true if this GLContext is current on this thread */ public final boolean isCurrent() { return getCurrent() == this ; }
return drawable; final GLContext currentContext = GLContext.getCurrent(); final GLDrawableFactory factory = drawable.getFactory(); final NativeSurface surface = drawable.getNativeSurface(); context.makeCurrent(); context.setGLDrawable(null, true); // dis-associate context.setGLDrawable(drawable, true); // re-association, implicit glFinish() ctx/drawable sync currentContext.makeCurrent();
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() {
public void close() { try { if (GLContext.getCurrent() != null) { // Release the OpenGL resources. GLContext.getCurrent().release(); } } catch (final GLException releaseFailure) { logger.log(Level.WARNING, "Failed to release OpenGL Context: " + _glCanvas, releaseFailure); } finally { _glCanvas = null; } // Dispose of any window resources. dispose(); }