if (addDlist.size() > 0 && removeDlist.size() > 0) { RenderAtomListInfo arr[] = new RenderAtomListInfo[addDlist.size()]; arr = (RenderAtomListInfo []) addDlist.toArray(arr); for (i = 0; i < arr.length; i++) { if (removeDlist.contains(arr[i])) { addDlist.remove(arr[i]); removeDlist.remove(arr[i]); } } }
    public void updateObject() {	int i, j, k;	RenderMolecule rm;	RenderAtomListInfo ra;	LightBin tmp;	float radius;	BackgroundRetained bg;	ObjectUpdate ob;	OrderedBin orderBin;	TextureRetained tex;	Integer texIdObj;	int size;	DetailTextureImage dtex;		//	System.out.println("dirtyRenderMoleculeList.size = "+dirtyRenderMoleculeList.size());	//	System.out.println("reEvaluateBg = "+reEvaluateBg);	//	System.out.println("reEvaluateClip = "+reEvaluateClip);		//	System.out.println("<========+End All Cached Values===========>");	// Add the new lightBins that have been created	//	System.out.println("objUpdateList.size = "+objUpdateList.size());	//	System.out.println("addOpaqueBin = "+addOpaqueBin);	//	System.out.println("opaqueBin = "+opaqueBin);		// List of renderMolecule from which renderAtoms have been removed        size = removeRenderAtomInRMList.size();	if (size > 0) {            RenderMolecule[] rmArr = (RenderMolecule[])		removeRenderAtomInRMList.toArray(false);            for (i=0 ; i<size; i++) {                rmArr[i].updateRemoveRenderAtoms();            }	}	// Add any OGs that need to be added to this frame	// List of Ordered Groups that have been removed	size = obList.size();	if ( size > 0) {	    for (i = 0 ; i < size; i++) {		orderBin = (OrderedBin)obList.get(i);		orderBin.addRemoveOrderedCollection();	    }	}		size = ogCIOList.size();	if(size > 0) { 	    J3dMessage m;	    for(i=0; i<size; i++) {		m = (J3dMessage) ogCIOList.get(i);				switch(m.type) {		case J3dMessage.ORDERED_GROUP_TABLE_CHANGED:		    OrderedGroupRetained og = (OrderedGroupRetained)m.args[3];		    if(og != null) {			og.childIndexOrder = ((int[])m.args[4]);		    }		    break;		    		    		case J3dMessage.ORDERED_GROUP_INSERTED:                case J3dMessage.ORDERED_GROUP_REMOVED:		    if(m.args[3] != null) {			Object[] ogArr = (Object[]) m.args[3];			Object[] ogTableArr = (Object[]) m.args[4];			for(j=0; j<ogArr.length; j++) {			    if(ogArr[j] != null) {				((OrderedGroupRetained)ogArr[j]).childIndexOrder =				    ((int[])ogTableArr[j]);			    }			}		    }		    		    break;		}		m.decRefcount();	    }	}			if (addOpaqueBin != null) {	    if (opaqueBin != null) {		tmp = opaqueBin;		while (tmp.next != null) {		    tmp = tmp.next;		}		addOpaqueBin.prev = tmp;		tmp.next = addOpaqueBin;	    }	    else {		opaqueBin = addOpaqueBin;	    }	}        if (bgAddOpaqueBin != null) {            if (bgOpaqueBin != null) {		tmp = bgOpaqueBin;		while (tmp.next != null) {		    tmp = tmp.next;		}                bgAddOpaqueBin.prev = tmp;                tmp.next = bgAddOpaqueBin;            }            else {                bgOpaqueBin = bgAddOpaqueBin;            }        }		size = orderedBinsList.size();	if (size > 0 ) {	    	    for (i = 0; i < size; i++) {		ArrayList obs= (ArrayList) orderedBinsList.get(i);		ArrayList list = (ArrayList) toBeAddedBinList.get(i);				int lSize = list.size();		for (j = 0; j < lSize; j++) {		    obs.add(list.get(j));		}	    }	}		size = raLocaleVwcBoundsUpdateList.size();         if ( size > 0) {            RenderAtom renderAtom;            for (i = 0; i < size; i++) {                renderAtom = (RenderAtom)raLocaleVwcBoundsUpdateList.get(i);                renderAtom.updateLocaleVwcBounds();            }        }		if ((size = aBinUpdateList.size()) > 0) {	    for (i = 0; i < size; i++) {		AttributeBin abin = (AttributeBin)aBinUpdateList.get(i);		abin.updateNodeComponent();			    }	}	// Update the sole user TextureBins.	if (tbUpdateList.size() > 0) {	    TextureBin tb;	    size = tbUpdateList.size();	    for (i = 0; i < size; i++) {		tb = (TextureBin) tbUpdateList.get(i);		tb.updateNodeComponent();	    }	    // do another pass to re-sort TextureBin based on the	    // texture in the first texture unit state	    for (i = 0; i < size; i++) {		tb = (TextureBin) tbUpdateList.get(i);		// Bug Id : 4701430 - Have to be sure tb.attributeBin is		// not equal to null. This is a temporary fix for j3d1.3.		if (((tb.tbFlag & TextureBin.RESORT) != 0) && 		    (tb.attributeBin != null)) {		    tb.attributeBin.reInsertTextureBin(tb);		    tb.tbFlag &= ~TextureBin.RESORT;		}	    }	}	// Update the soleUser node  components first	// This way material equivalence during insertion	// of new RMs is based on the updated ones	if ((size = rmUpdateList.size()) > 0) {	    for (i = 0; i < size; i++) {		rm = (RenderMolecule)rmUpdateList.get(i);				boolean changeLists = rm.updateNodeComponent();		// If an existing rm went from opaque to transparent or vice-versa		// and has not been removed, then switch the RM		if (changeLists && rm.textureBin != null) {		    rm.textureBin.changeLists(rm);		}	    }	    for (i = 0; i < size; i++) {		rm = (RenderMolecule)rmUpdateList.get(i);		rm.reEvaluateEquivalence();	    }	}		size = objUpdateList.size(); 	if ( size > 0) {	    for (i = 0; i < size; i++) {		ob = (ObjectUpdate)objUpdateList.get(i);		ob.updateObject();	    }	}		size = dirtyReferenceGeomList.size(); 	if ( size > 0) {	    GeometryArrayRetained   geo;	    Canvas3D canvases[] = view.getCanvases();	    	    for (i = 0; i < size; i++) {		geo = (GeometryArrayRetained) dirtyReferenceGeomList.get(i);		// Evaluate the nodeComponentList for all the canvases		geo.geomLock.getLock();		j = 0;		// Do the setup  only once{if necessary} for each geometry		boolean found = false;		while(j < canvases.length && !found) {		    if ((canvases[j].extensionsSupported & Canvas3D.SUN_GLOBAL_ALPHA) == 0) {			if ((geo.vertexFormat & GeometryArray.INTERLEAVED) != 0) {			    geo.setupMirrorInterleavedColorPointer(true);			    found = true;			}			else {			    geo.setupMirrorColorPointer((geo.vertexType & GeometryArrayRetained.COLOR_DEFINED),true);			    found = true;			}		    }		    j++;		}		geo.geomLock.unLock();	    }	    	}		if (reEvaluateBg) {	    setBackground(currentActiveBackground);		}	size = textureBinList.size();//System.out.println("textureBinList.size= " + size);	if (size > 0) {	    Canvas3D canvasList[][] = view.getCanvasList(false);	    Canvas3D cv;	    boolean useSharedCtx = false;	    TextureRetained texture;	    	    // do a quick check to see if there is any canvas using	    // shared context	    for (j = 0; j < canvasList.length && !useSharedCtx; j++) {		cv = canvasList[j][0];		if (cv.useSharedCtx) {		    useSharedCtx = true;		}	    }	    	    for (int m = 0; m <size; m++) { 		k = 0;		TextureBin tb = (TextureBin) textureBinList.get(m);		tb.tbFlag |= TextureBin.ON_RENDER_BIN_LIST;		if (tb.texUnitState == null)		    continue;		for (i = 0; i < tb.texUnitState.length; i++) {		    if (tb.texUnitState[i] != null &&			tb.texUnitState[i].texture != null) {						texture = tb.texUnitState[i].texture;						// for all the textures in this texture bin list that			// need to be reloaded, add the textures to the			// corresponding resource reload list if the 			// resource uses shared context,			// so that the texture can be reloaded up front, and			// we don't need to do make context current for			// each texture reload. Make Context current isn't			// cheap.						if (useSharedCtx) {			    synchronized (texture.resourceLock) {				for (j = 0; j < canvasList.length; j++) {				    cv = canvasList[j][0];				    if (cv.useSharedCtx && 					cv.screen.renderer != null &&					((cv.screen.renderer.rendererBit &					  (texture.resourceCreationMask |					   texture.resourceInReloadList)) == 0)) {										cv.screen.renderer.textureReloadList.add(										 texture);										texture.resourceInReloadList |=					    cv.screen.renderer.rendererBit;				    }				}			    }			}		    }		}	    }	}		size = newNodeComponentList.size(); 	if ( size > 0) {//System.out.println("newNodeComponentlist.size= " + size);	    Canvas3D canvases[] = view.getCanvases();	    for (i = 0; i < size; i++) {		// Evaluate the nodeComponentList for all the canvases		ImageComponentRetained nc = (ImageComponentRetained)newNodeComponentList.get(i);		// Only evalaute extension for by-ref Images		if (nc.isByReference()) {		    nc.geomLock.getLock();		    for (j = 0; j <canvases.length; j++) {		        // If the context is null, then the extension		        // will be evaluated during context creation in		        // the renderer		        if (canvases[j].ctx != 0) {			    nc.evaluateExtensions(canvases[j].extensionsSupported);		        }		    }		    nc.geomLock.unLock();		}		nodeComponentList.add(nc);	    }	}		size = removeNodeComponentList.size(); 	if ( size > 0) {	    for (i = 0; i < size; i++) {		nodeComponentList.remove(removeNodeComponentList.get(i));	    }	}		// reevaluate dirty node component 	size = dirtyNodeComponentList.size();	if (size > 0) {            Canvas3D canvases[] = view.getCanvases();            for (i = 0; i < size; i++) {                // Evaluate the nodeComponentList for all the canvases                ImageComponentRetained nc = 			(ImageComponentRetained)dirtyNodeComponentList.get(i);                // Only evalaute extension for by-ref Images                if (nc.isByReference()) {                    nc.geomLock.getLock();                    for (j = 0; j <canvases.length; j++) {                        // If the context is null, then the extension                        // will be evaluated during context creation in                        // the renderer                        if (canvases[j].ctx != 0) {                            nc.evaluateExtensions(					canvases[j].extensionsSupported);                        }                    }                    nc.geomLock.unLock();                }            }	}		if (reEvaluateClip) {	    double[] retVal = null;	    if ((retVal = universe.renderingEnvironmentStructure.backClipDistanceInVworld(vpSchedSphereInVworld, view)) != null) {		backClipDistanceInVworld = retVal[0];		backClipActive = true;			    }	    else {		backClipActive = false;	    }	    view.vDirtyMask |= View.CLIP_DIRTY;	}		multiScreen = ((view.getScreens()).length > 1);		// renderBin is ready now, so send the offScreen message	size = offScreenMessage.size(); 	if ( size > 0) {	    J3dMessage m;	    for (i=size-1; i>=0; i--) {		m = (J3dMessage) offScreenMessage.get(i);		m.threads = J3dThread.RENDER_THREAD;		((Canvas3D)m.args[0]).screen.renderer.rendererStructure.addMessage(m);				// the above call will increment the reference count again		m.decRefcount();	    }	}		// called from renderBin when there are dirtyOrientedRAs	// This routin cache the dirtyOrintedRAs to be updated	// by mastercontrol	if (dirtyOrientedRAs.size() > 0) {	    // Keep a copy to be handled by mastercontrol	    cachedDirtyOrientedRAs = (ArrayList)dirtyOrientedRAs.clone();	}	boolean sortAll = false;	if (reEvaluateSortMode && transpSortMode != cachedTranspSortMode) {	    convertTransparentRenderingStruct(transpSortMode, cachedTranspSortMode);	    transpSortMode = cachedTranspSortMode;	    if (transpSortMode == View.TRANSPARENCY_SORT_GEOMETRY) {		if (transparentInfo != null){		    sortAll = true;		}	    }	}		if (vpcToVworldDirty) {	    vworldToVpc.invert(vpcToVworld);	    // Have the send down the lights, so set the canvas	    // lightbin to null	    Canvas3D canvases[] = view.getCanvases();	    for (i = 0; i < canvases.length; i++) {		canvases[i].lightBin = null;	    }	    if (canvases.length > 0) {		Transform3D xform;		canvases[0].getCenterEyeInImagePlate(eyeInVworld);		// xform is imagePlateToLocal		xform = canvases[0].canvasViewCache.getImagePlateToVworld(); 		xform.transform(eyeInVworld);	    }	    if (transpSortMode == View.TRANSPARENCY_SORT_GEOMETRY && transparentInfo != null) {		//		System.out.println("sortAll 1");		sortAll = true;	    }	}	size = dirtyDepthSortRenderAtom.size();		if (sortAll || size > 0) {	    int tsize = allTransparentObjects.size();	    	    double zVal;	    for (i = 0; i < tsize; i++) {		RenderAtom renderAtom = (RenderAtom)allTransparentObjects.get(i);		for (k = 0; k < renderAtom.rListInfo.length; k++) {		    if (renderAtom.rListInfo[k].geometry() == null)			continue;		    zVal = renderAtom.geometryAtom.centroid[k].distanceSquared(eyeInVworld);		    renderAtom.parentTInfo[k].zVal = zVal;		    		}	    }	    	    // Check to see if a majority of the transparent Objects have changed	    // If less than 66% of all transparentStructs are dirty	    // then, remove and insert, otherwise resort everything	    	    	    if (size  > 0 &&  1.5f * numDirtyTinfo >  nElements) {		// System.out.println("sortAll 3, size = "+size);		sortAll = true;	    }	    	    if (size > 0) {		TransparentRenderingInfo dirtyList = null, rList;		Iterator dirtyDepthSortIterator = dirtyDepthSortRenderAtom.iterator();		while (dirtyDepthSortIterator.hasNext()) {		    RenderAtom renderAtom = (RenderAtom)dirtyDepthSortIterator.next();		    if (!renderAtom.inRenderBin())			continue;		    renderAtom.dirtyMask &= ~RenderAtom.IN_SORTED_POS_DIRTY_TRANSP_LIST;		    if (!sortAll) {			dirtyList = collectDirtyTRInfo(dirtyList, renderAtom);		    }		}		if (dirtyList != null) {		    // System.out.println("====> sort Some");		    dirtyList = depthSortAll(dirtyList);		    // Now merge the newly sorted list with the old one		    transparentInfo = mergeDepthSort(transparentInfo, dirtyList);		}	    }	    // Sort all the transparent renderAtoms	    if (sortAll) {		transparentInfo = depthSortAll(transparentInfo);	    }	}	if (addDlist.size() > 0 || removeDlist.size() > 0) {	    Canvas3D canvasList[][] = view.getCanvasList(false);	    Canvas3D cv;	    ArrayList rlist = new ArrayList(5);	    	    for (i = 0; i < canvasList.length; i++) {		cv = canvasList[i][0];		if (cv.useSharedCtx) {		    // Do this only once per renderer for this view		    if (!rlist.contains(cv.screen.renderer)) {			rlist.add(cv.screen.renderer);			updateDlistRendererResource(cv.screen.renderer);		    }		} else {		    updateDlistCanvasResource(canvasList[i]);		}	    }	    	}		if (dirtyRenderMoleculeList.size() > 0 ||	    addDlistPerRinfo.size() > 0 ||	    removeDlistPerRinfo.size() > 0 ||	    displayListResourceFreeList.size() > 0 ||	    toBeAddedTextureResourceFreeList.size() > 0 ) {	    	    Canvas3D canvasList[][] = view.getCanvasList(false);	    Canvas3D cv;	    	    for (i = 0; i < canvasList.length; i++) {		cv = canvasList[i][0];		if (cv.useSharedCtx && (cv.screen.renderer != null)) {		    updateRendererResource(cv.screen.renderer);		} else {		    updateCanvasResource(canvasList[i]);		}	    }	    Integer id;	    size = displayListResourceFreeList.size();	    for (i = 0; i < size; i++) {		id = (Integer)displayListResourceFreeList.get(i);		VirtualUniverse.mc.freeDisplayListId(id);	    }	    	    // lock list of dlist	    // TODO: Instead of copying could we keep 2 arrays	    // and just toggle?	    size = dirtyRenderMoleculeList.size();	    for (i = 0; i < size; i++) {		rm = (RenderMolecule)dirtyRenderMoleculeList.get(i);		rm.onUpdateList = 0;		ra = rm.primaryRenderAtomList;		while (ra != null) {		    dlistLockList.add(ra.geometry());		    ra = ra.next;		}	    }	    size = addDlistPerRinfo.size();	    for (i = 0; i < size; i++) {		ra = (RenderAtomListInfo)addDlistPerRinfo.get(i);		if (ra.geometry() != null) {		    dlistLockList.add(ra.geometry());		}	    }	    	}		clearAllUpdateObjectState();	/*	if (opaqueBin != null) {	    System.out.println(this + "***** Begin Dumping OpaqueBin *****");	    dumpBin(opaqueBin);	    System.out.println("***** End Dumping OpaqueBin *****");	}	*/	    }