📄 renderbin.java
字号:
/* * $RCSfile: RenderBin.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.16 $ * $Date: 2007/04/27 15:27:23 $ * $State: Exp $ */package javax.media.j3d;import javax.vecmath.*;import java.util.*;/** * The RenderBin is a structure that optimizes rendering by doing efficient * state sorting of objects to be rendered. */class RenderBin extends J3dStructure implements ObjectUpdate { /** * The list of RenderAtoms */ ArrayList renderAtoms = new ArrayList(5); /** * A couple ArrayLists used during light Processing */ ArrayList lightMessageList = new ArrayList(5); // Messges retrieved when a message is sent to RenderingEnv Structure J3dMessage[] m; /** * List of renderMolecules that are soleUser * have to do a 2 pass, first update values * then sort based on equivalent material */ ArrayList rmUpdateList = new ArrayList(); ArrayList aBinUpdateList = new ArrayList(); /** * List of ShaderBin that are soleUser that * needs to have its components updated @updateObject time */ ArrayList sBinUpdateList = new ArrayList(); /** * List of TextureBin that are soleUser that * needs to have its components updated @updateObject time */ ArrayList tbUpdateList = new ArrayList(); /** * List of Bins that are soleUser that have new renderAtom * added into, which requires a pre-update screening to * check if any of its node component changes could have been * missed because the changes happen when all the render atoms * are temporarily removed from the bin. */ ArrayList updateCheckList = new ArrayList(); /** * The number of lights supported by the underlying context. */ int maxLights; /** * The opaque objects */ LightBin opaqueBin = null; /** * OpaqueBins to be added for the next frame */ LightBin addOpaqueBin = null; // This is a list of textureBins to be rendered, if the transpSortPolicy // is NONE, otherwise, if the transpSortPolicy is geometry, then // this is the list of renderAtoms to be rendered ArrayList allTransparentObjects = new ArrayList(5); TransparentRenderingInfo transparentInfo; /** * List of RenderAtoms whose postion have changed - only used for * depth sorted transparency */ ArrayList positionDirtyList = new ArrayList(5); /** * Used when ColoringAttributes is null */ Color3f white = new Color3f(1.0f, 1.0f, 1.0f); /** * Used when Background is null */ Color3f black = new Color3f(0.0f, 0.0f, 0.0f); /** * The backgound color data. */ BackgroundRetained background = new BackgroundRetained(); /** * The view platform transforms. */ // used for rendering - lights and fog modelling Transform3D vworldToVpc = new Transform3D(); // used for updating vpSchedSphere Transform3D vpcToVworld = new Transform3D(); /** * Two bounding spheres to track the scheduling region of * the view platform. */ BoundingSphere vpSchedSphereInVworld = new BoundingSphere(); /** * To cache the view frustum bounding box. */ BoundingBox viewFrustumBBox = new BoundingBox(); BoundingBox canvasFrustumBBox = new BoundingBox(); /** * To ensure that vpcToVworld is valid (not null) for the first pass */ boolean afterFirst = false; /** * back clip distance in vworld */ double backClipDistanceInVworld; boolean backClipActive = false; /** * These variables control when compaction occurs */ int frameCount = 0; int frameCountCutoff = 150; int notVisibleCount = 75; long removeCutoffTime = -1; /** * variables to process transform messages */ boolean transformMsg = false; UpdateTargets targets = null; ArrayList blUsers = null; /** * The View for this render bin */ View view = null; private Comparator transparencySortComparator = null; private ArrayList toBeAddedTextureResourceFreeList = new ArrayList(5); private ArrayList displayListResourceFreeList = new ArrayList(5); // a list of top level OrderedGroups ArrayList orderedBins = new ArrayList(5); // List of changed elements in the environment that needs to // be reloaded ArrayList changedLts = new ArrayList(5); ArrayList changedFogs = new ArrayList(5); ArrayList changedModelClips = new ArrayList(5); // Flag to indicate whether the canvas should be marked static int REEVALUATE_LIGHTS = 0x1; static int REEVALUATE_FOG = 0x2; static int REEVALUATE_MCLIP = 0x4; static int REEVALUATE_ALL_ENV = REEVALUATE_LIGHTS | REEVALUATE_FOG | REEVALUATE_MCLIP; int envDirty = 0; private boolean reEvaluateBg = true; private boolean reloadBgTexture = true; boolean reEvaluateClip = true; boolean reEvaluateSortMode = false; // list of renderMolecule // RenderBin will not reused in two different universe, so it is // safe to pass null in last parameters in new IndexedUnorderSet() IndexedUnorderSet renderMoleculeList = new IndexedUnorderSet(RenderMolecule.class, RenderMolecule.RENDER_MOLECULE_LIST, null); // List of renderAtoms that have a shared dlist (due to geo.refCount > 1) // Fix for Issue 5: change this to a Set rather than a list to // avoid duplicates entried Collection sharedDList = new HashSet(); ArrayList dirtyRenderMoleculeList = new ArrayList(5); /** * ArrayList of objects to be updated */ ArrayList objUpdateList = new ArrayList(5); ArrayList raLocaleVwcBoundsUpdateList = new ArrayList(5); /** * remove the bins first before adding them to new ones */ IndexedUnorderSet removeRenderAtomInRMList = new IndexedUnorderSet(RenderMolecule.class, RenderMolecule.REMOVE_RENDER_ATOM_IN_RM_LIST, null); /** * list of affect OrderedGroups with childIndexOrder changed. */ ArrayList ogCIOList = new ArrayList(5); /** * list of ordered bins from which orderedCollection are added/removed */ ArrayList obList = new ArrayList(5); /** * Ordered Bin processing */ ArrayList orderedBinsList = new ArrayList(5); ArrayList toBeAddedBinList = new ArrayList(5); /** * arraylist of geometry that should be locked to ensure * that the same snapshot of the geometry is rendered * across all canvases */ ArrayList lockGeometryList = new ArrayList(5); /** * arraylist of dlist that will be rebuilt */ ArrayList dlistLockList = new ArrayList(5); // Background node that contains geometry BackgroundRetained geometryBackground = null; // background geometry processing LightBin bgOpaqueBin = null; LightBin bgAddOpaqueBin = null; ArrayList bgOrderedBins = new ArrayList(5); TransparentRenderingInfo bgTransparentInfo; // vworldToVpc for background geometry Transform3D infVworldToVpc = new Transform3D(); // true if vpcToVworld has been modified boolean vpcToVworldDirty = true; // current active background BackgroundRetained currentActiveBackground = new BackgroundRetained(); // Flag to indicate that alternate app is dirty boolean altAppearanceDirty = true; // List of node components that need special processing, due to // extensions ArrayList nodeComponentList = new ArrayList(5); // List of node components ***for this frame*** that need special // processing due to extension ArrayList newNodeComponentList = new ArrayList(5); ArrayList removeNodeComponentList = new ArrayList(5); ArrayList dirtyNodeComponentList = new ArrayList(5); ArrayList textureBinList = new ArrayList(5); /** * arraylist of refernce geometry that should be locked when transparency * is on, so that we can make a mirror copy of the colors safely */ ArrayList dirtyReferenceGeomList = new ArrayList(5); // list of all Oriented RenderAtoms ArrayList orientedRAs = new ArrayList(5); // list of Oriented RenderAtoms whose orientedTransforms require update ArrayList dirtyOrientedRAs = new ArrayList(5); // Cached copy of dirty oriented RAs to be updated in MasterControl ArrayList cachedDirtyOrientedRAs = null; // list of offScreen message that ArrayList offScreenMessage = new ArrayList(5); // Vector used for locale translation Vector3d localeTranslation = new Vector3d(); // Separate dlists that were added/removed in this snapshot private HashSet addDlist = new HashSet(); private HashSet removeDlist = new HashSet(); // Separate dlists per rinfo that were added/removed in this snapshot ArrayList addDlistPerRinfo = new ArrayList(5); ArrayList removeDlistPerRinfo = new ArrayList(5); Locale locale = null; // Set to true if locale changes as part of UPDATE_VIEW message boolean localeChanged = false; // Cached copy to be used by all RenderMolecules DisplayListRenderMethod dlistRenderMethod = null; // Need to query BHTree again with visibility policy change boolean reactivateView = false; /** * A flag indicates that the cached visible GeometryAtoms for this RenderBin might * be invalid. */ private boolean visGAIsDirty = false; /** * A flag indicates that a visibility query to the GeometryStructure is needed. */ private boolean visQuery = false; // Temporary dirtylist ArrayList dirtyList = new ArrayList(5); // Transaprency sort mode int transpSortMode = View.TRANSPARENCY_SORT_NONE; int cachedTranspSortMode = View.TRANSPARENCY_SORT_NONE; // Temporary dirtylist private LinkedHashSet dirtyDepthSortRenderAtom = new LinkedHashSet(); private int numDirtyTinfo = 0; // Eye position in vworld Point3d eyeInVworld = new Point3d(); // Number of RenderAtomListInfo in the depthSortedList int nElements = 0; /** * Constructs a new RenderBin */ RenderBin(VirtualUniverse u, View v) { super(u, J3dThread.UPDATE_RENDER); vworldToVpc.setIdentity(); universe = u; view = v; transpSortMode = v.transparencySortingPolicy; cachedTranspSortMode = v.transparencySortingPolicy; maxLights = VirtualUniverse.mc.maxLights; ViewPlatform vp = view.getViewPlatform(); if (vp != null) { locale = ((ViewPlatformRetained) (vp.retained)).locale; } dlistRenderMethod = (DisplayListRenderMethod) VirtualUniverse.mc.getDisplayListRenderMethod(); } /** * updateObject */ 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; // System.err.println("dirtyRenderMoleculeList.size = "+dirtyRenderMoleculeList.size()); // System.err.println("reEvaluateBg = "+reEvaluateBg); // System.err.println("reEvaluateClip = "+reEvaluateClip); // System.err.println("<========+End All Cached Values===========>"); // Add the new lightBins that have been created // System.err.println("objUpdateList.size = "+objUpdateList.size()); // System.err.println("addOpaqueBin = "+addOpaqueBin); // System.err.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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -