/** * @return true if this GLContext is current on this thread */ public final boolean isCurrent() { return getCurrent() == this ; }
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); } }
/** * @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); } }
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(); }
public void releaseCurrentContext() { if (_context.equals(GLContext.getCurrent())) { try { _context.release(); } catch (final GLException gle) { gle.printStackTrace(); } } }
private void checkContext() { GLContext currentContext = GLContext.getCurrent(); if (currentContext == null) { throw new GLException("No OpenGL context is current on this thread"); } if ((_context != null) && (_context != currentContext)) { throw new GLException("This GL object is being incorrectly used with a different GLContext than that which created it"); } } private GLContext _context;
private void checkContext() { GLContext currentContext = GLContext.getCurrent(); if (currentContext == null) { throw new GLException("No OpenGL context is current on this thread"); } if ((_context != null) && (_context != currentContext)) { throw new GLException("This GL object is being incorrectly used with a different GLContext than that which created it"); } } private GLContext _context;
private void checkContext() { GLContext currentContext = GLContext.getCurrent(); if (currentContext == null) { throw new GLException("No OpenGL context is current on this thread"); } if ((_context != null) && (_context != currentContext)) { throw new GLException("This GL object is being incorrectly used with a different GLContext than that which created it"); } } private GLContext _context;
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(); }
public static final GL2ES1 getCurrentGL2ES1() throws GLException { GLContext curContext = GLContext.getCurrent(); if (curContext == null) { throw new GLException("No OpenGL context current on this thread"); } return curContext.getGL().getGL2ES1(); }
public static final GL2 getCurrentGL2() throws GLException { GLContext curContext = GLContext.getCurrent(); if (curContext == null) { throw new GLException("No OpenGL context current on this thread"); } return curContext.getGL().getGL2(); }
/** * 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(); }
/** * 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); } }
private void setupImage24_32(final GLProfile glp) { bpp = header.pixelDepth / 8; switch (header.pixelDepth) { case 24: format = glp.isGL2GL3() ? GL2GL3.GL_BGR : GL.GL_RGB; break; case 32: boolean useBGRA = glp.isGL2GL3(); if(!useBGRA) { final GLContext ctx = GLContext.getCurrent(); useBGRA = null != ctx && ctx.isTextureFormatBGRA8888Available(); } format = useBGRA ? GL.GL_BGRA : GL.GL_RGBA; break; default: assert false; } }
@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); } }
@Override public void applyInternalTransform( DrawContext dc, boolean textureIdentityActive ) { GL2 gl = GLContext.getCurrent( ).getGL( ).getGL2( ); if ( !textureIdentityActive ) { gl.glMatrixMode( GL2.GL_TEXTURE ); gl.glLoadIdentity( ); } gl.glScaled( scaleX, scaleY, 1 ); }
private static final GLUgl2ProcAddressTable getGLUProcAddressTable() { if (gluProcAddressTable == null) { GLContext curContext = GLContext.getCurrent(); if (curContext == null) { throw new GLException("No OpenGL context current on this thread"); } GLDynamicLookupHelper glLookupHelper = ((GLDrawableImpl) curContext.getGLDrawable()).getGLDynamicLookupHelper(); glLookupHelper.loadGLULibrary(); GLUgl2ProcAddressTable tmp = new GLUgl2ProcAddressTable(new GLProcAddressResolver()); tmp.reset(glLookupHelper); gluProcAddressTable = tmp; } return gluProcAddressTable; } // ---- End CustomJavaCode .cfg declarations
@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()); }
if( null!=sr && sr.isGLXVendorATI() && null == GLContext.getCurrent() ) { sr.getContext().makeCurrent(); try {
private void debug(final GL gl) { dbgFrame = new Frame("TextRenderer Debug Output"); final GLCanvas dbgCanvas = new GLCanvas(new GLCapabilities(gl.getGLProfile())); dbgCanvas.setSharedContext(GLContext.getCurrent()); dbgCanvas.addGLEventListener(new DebugListener(gl, dbgFrame)); dbgFrame.add(dbgCanvas); final FPSAnimator anim = new FPSAnimator(dbgCanvas, 10); dbgFrame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { // Run this on another thread than the AWT event queue to // make sure the call to Animator.stop() completes before // exiting new Thread(new Runnable() { @Override public void run() { anim.stop(); } }).start(); } }); dbgFrame.setSize(kSize, kSize); dbgFrame.setVisible(true); anim.start(); debugged = true; }