📄 renderer.java
字号:
Canvas3D.FIELD_ALL, canvas.useDoubleBuffer); // handle postRender callback if (VirtualUniverse.mc.doDsiRenderLock) { canvas.drawingSurfaceObject.unLock(); } canvas.view.inCanvasCallback = true; try { canvas.postRender(); } catch (RuntimeException e) { System.err.println("Exception occurred during Canvas3D callback:"); e.printStackTrace(); } catch (Error e) { // Issue 264 - catch Error so Renderer doesn't die System.err.println("Error occurred during Canvas3D callback:"); e.printStackTrace(); } canvas.view.inCanvasCallback = false; // end offscreen rendering if (canvas.offScreenRendering) { canvas.syncRender(canvas.ctx, true); canvas.endOffScreenRendering(); canvas.offScreenRendering = false; // Issue 489 - don't call postSwap here for auto-offscreen, // since it will be called later by the SWAP operation if (canvas.manualRendering) { // do the postSwap for offscreen here canvas.view.inCanvasCallback = true; try { canvas.postSwap(); } catch (RuntimeException e) { System.err.println("Exception occurred during Canvas 3D callback:"); e.printStackTrace(); } catch (Error e) { // Issue 264 - catch Error so Renderer doesn't die System.err.println("Error occurred during Canvas3D callback:"); e.printStackTrace(); } if (offBufRetained.isByReference()) { offBufRetained.geomLock.unLock(); } canvas.view.inCanvasCallback = false; canvas.releaseCtx(); } } canvas.endScene(); if (MasterControl.isStatsLoggable(Level.INFO)) { // Instrumentation of Java 3D renderer long deltaTime = System.nanoTime() - startRenderTime; VirtualUniverse.mc.recordTime(MasterControl.TimeType.RENDER, deltaTime); } } else { // if (renderBin != null) if ((offBufRetained != null) && offBufRetained.isByReference()) { offBufRetained.geomLock.unLock(); } } } } // clear array to prevent memory leaks if (opArg == RENDER) { m[0] = null; } else { Arrays.fill(m, 0, totalMessages, null); } } } catch (NullPointerException ne) { // Print NPE, but otherwise ignore it ne.printStackTrace(); if (canvas != null) { if (canvas.ctx != null) { canvas.endScene(); } // drawingSurfaceObject will safely ignore // this request if this is not lock before canvas.drawingSurfaceObject.unLock(); } } catch (RuntimeException ex) { ex.printStackTrace(); if (canvas != null) { if (canvas.ctx != null) { canvas.endScene(); } // drawingSurfaceObject will safely ignore // this request if this is not lock before canvas.drawingSurfaceObject.unLock(); } // Issue 260 : indicate fatal error and notify error listeners canvas.setFatalError(); RenderingError err = new RenderingError(RenderingError.UNEXPECTED_RENDERING_ERROR, J3dI18N.getString("Renderer8")); err.setCanvas3D(canvas); if (canvas != null) { err.setGraphicsDevice(canvas.graphicsConfiguration.getDevice()); } notifyErrorListeners(err); } } // resource clean up void shutdown() { removeAllCtxs(); Pipeline.getPipeline().cleanupRenderer(); } void cleanup() { super.cleanup(); renderMessage = new J3dMessage[1]; rendererStructure = new RendererStructure(); bgVworldToVpc = new Transform3D(); sharedCtx = null; sharedCtxTimeStamp = 0; sharedCtxDisplay = 0; sharedCtxDrawable = null; dirtyRenderMoleculeList.clear(); dirtyRenderAtomList.clear(); dirtyDlistPerRinfoList.clear(); textureIdResourceFreeList.clear(); displayListResourceFreeList.clear(); onScreen = null; offScreen = null; m = null; nmesg = 0; } // This is only invoked from removeCtx()/removeAllCtxs() // with drawingSurface already lock final void makeCtxCurrent(Context sharedCtx, long display, Drawable drawable) { if (sharedCtx != currentCtx || drawable != currentDrawable) { Canvas3D.useCtx(sharedCtx, display, drawable); /* if(!Canvas3D.useCtx(sharedCtx, display, drawable)) { Thread.dumpStack(); System.err.println("useCtx Fail"); } */ currentCtx = sharedCtx; currentDrawable = drawable; } } // No need to free graphics2d and background if it is from // Canvas3D postRequest() offScreen rendering since the // user thread will not wait for it. Also we can just // reuse it as Canvas3D did not destroy. private void removeCtx(Canvas3D cv, long display, Drawable drawable, Context ctx, boolean resetCtx, boolean freeBackground, boolean destroyOffScreenBuffer) { synchronized (VirtualUniverse.mc.contextCreationLock) { if (ctx != null) { int idx = listOfCtxs.indexOf(ctx); if (idx >= 0) { listOfCtxs.remove(idx); listOfCanvases.remove(idx); // Issue 326 : don't check display variable here if ((drawable != null) && cv.added) { // cv.ctx may reset to -1 here so we // always use the ctx pass in. if (cv.drawingSurfaceObject.renderLock()) { // if it is the last one, free shared resources if (sharedCtx != null) { if (listOfCtxs.isEmpty()) { makeCtxCurrent(sharedCtx, sharedCtxDisplay, sharedCtxDrawable); freeResourcesInFreeList(null); freeContextResources(); Canvas3D.destroyContext(sharedCtxDisplay, sharedCtxDrawable, sharedCtx); currentCtx = null; currentDrawable = null; } else { freeResourcesInFreeList(cv); } cv.makeCtxCurrent(ctx, display, drawable); } else { cv.makeCtxCurrent(ctx, display, drawable); cv.freeResourcesInFreeList(ctx); } cv.freeContextResources(this, freeBackground, ctx); Canvas3D.destroyContext(display, drawable, ctx); currentCtx = null; currentDrawable = null; cv.drawingSurfaceObject.unLock(); } } } if (resetCtx) { cv.ctx = null; } if ((sharedCtx != null) && listOfCtxs.isEmpty()) { sharedCtx = null; sharedCtxTimeStamp = 0; } cv.ctxTimeStamp = 0; } // Fix for issue 18. // Since we are now the renderer thread, // we can safely execute destroyOffScreenBuffer. if(destroyOffScreenBuffer) { cv.destroyOffScreenBuffer(ctx, display, cv.fbConfig, drawable); cv.offScreenBufferPending = false; } } } void removeAllCtxs() { Canvas3D cv; synchronized (VirtualUniverse.mc.contextCreationLock) { for (int i=listOfCanvases.size()-1; i >=0; i--) { cv = (Canvas3D) listOfCanvases.get(i); if ((cv.screen != null) && (cv.ctx != null)) { // Issue 326 : don't check display variable here if ((cv.drawable != null) && cv.added) { if (cv.drawingSurfaceObject.renderLock()) { // We need to free sharedCtx resource // first before last non-sharedCtx to // workaround Nvidia driver bug under Linux // that crash on freeTexture ID:4685156 if ((i == 0) && (sharedCtx != null)) { makeCtxCurrent(sharedCtx, sharedCtxDisplay, sharedCtxDrawable); freeResourcesInFreeList(null); freeContextResources(); Canvas3D.destroyContext(sharedCtxDisplay, sharedCtxDrawable, sharedCtx); currentCtx = null; currentDrawable = null; } cv.makeCtxCurrent(); cv.freeResourcesInFreeList(cv.ctx); cv.freeContextResources(this, true, cv.ctx); Canvas3D.destroyContext(cv.screen.display, cv.drawable, cv.ctx); currentCtx = null; currentDrawable = null; cv.drawingSurfaceObject.unLock(); } } } cv.ctx = null; cv.ctxTimeStamp = 0; } if (sharedCtx != null) { sharedCtx = null; sharedCtxTimeStamp = 0; } listOfCanvases.clear(); listOfCtxs.clear(); } } // handle free resource in the FreeList void freeResourcesInFreeList(Canvas3D cv) { Iterator it; boolean isFreeTex = (textureIdResourceFreeList.size() > 0); boolean isFreeDL = (displayListResourceFreeList.size() > 0); ArrayList list; int i, val; GeometryArrayRetained geo; if (isFreeTex || isFreeDL) { if (cv != null) { cv.makeCtxCurrent(sharedCtx); } if (isFreeDL) { for (it = displayListResourceFreeList.iterator(); it.hasNext();) { val = ((Integer) it.next()).intValue(); if (val <= 0) { continue; } Canvas3D.freeDisplayList(sharedCtx, val); } displayListResourceFreeList.clear(); } if (isFreeTex) { for (it = textureIdResourceFreeList.iterator(); it.hasNext();) { val = ((Integer) it.next()).intValue(); if (val <= 0) { continue; } if (val >= textureIDResourceTable.size()) { MasterControl.getCoreLogger().severe( "Error in freeResourcesInFreeList : ResourceIDTableSize = " + textureIDResourceTable.size() + " val = " + val); } else { Object obj = textureIDResourceTable.get(val); if (obj instanceof TextureRetained) { TextureRetained tex = (TextureRetained) obj; synchronized (tex.resourceLock) { tex.resourceCreationMask &= ~rendererBit; if (tex.resourceCreationMask == 0) { tex.freeTextureId(val); } } } textureIDResourceTable.set(val, null); } Canvas3D.freeTexture(sharedCtx, val); } textureIdResourceFreeList.clear(); } if (cv != null) { cv.makeCtxCurrent(cv.ctx); } } } final void addTextureResource(int id, Object obj) { if (textureIDResourceTable.size() <= id) { for (int i=textureIDResourceTable.size(); i < id; i++) { textureIDResourceTable.add(null); } textureIDResourceTable.add(obj); } else { textureIDResourceTable.set(id, obj); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -