⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 geometryarrayretained.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * $RCSfile: GeometryArrayRetained.java,v $ * * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Use is subject to license terms. * * $Revision: 1.10 $ * $Date: 2007/04/20 00:54:41 $ * $State: Exp $ */package javax.media.j3d;import com.sun.j3d.internal.Distance;import javax.vecmath.*;import java.lang.Math;import java.util.ArrayList;import java.util.Set;import java.util.HashSet;import java.util.HashMap;import java.util.Vector;import java.util.Enumeration;import com.sun.j3d.internal.ByteBufferWrapper;import com.sun.j3d.internal.BufferWrapper;import com.sun.j3d.internal.FloatBufferWrapper;import com.sun.j3d.internal.DoubleBufferWrapper;/** * The GeometryArray object contains arrays of positional coordinates, * colors, normals and/or texture coordinates that describe * point, line, or surface geometry.  It is extended to create * the various primitive types (e.g., lines, triangle_strips, etc.) */abstract class GeometryArrayRetained extends GeometryRetained{    // XXXX: Memory footprint reduction. Should have separate object to    //       to contain specific data such as a ByRef object for    //       all ByRef related data. So that incases where no    //       ByRef is needed, the ByRef object reference is    //       set to null. Hence saving memory!    //       Need object such as Texture, D3d and ByRef ...    //     // Contains a bitset indicating which components are present    int vertexFormat;    // Whether this geometry was ever rendered as transparent    int c4fAllocated =  0;    // Total Number of vertices    int vertexCount;    // number of vertices used in rendering    int validVertexCount;    // The vertex data in packed format    float vertexData[];    // vertex data in packed format for each screen in multi-screen situation    // if alpha values of each vertex are to be updated    private float mvertexData[][];    //    // The following offset/stride values are internally computed    // from the format    //    // Stride (in words) from one vertex to the next    int stride;    // Stride (in words) from one texture coordinate to the next    int texCoordStride;       // Offset (in words) within each vertex of the coordinate position    int coordinateOffset;    // Offset (in words) within each vertex of the normal    int normalOffset;    // Offset (in words) within each vertex of the color    int colorOffset;    // Offset (in words) within each vertex of the texture coordinate    int textureOffset;    // Offset (in words) within each vertex of each vertex attribute    int[] vertexAttrOffsets;        // Stride (size) of all vertex attributes    int vertexAttrStride;    // alpha value for transparency and texture blending    private float[] lastAlpha = new float[1];    float lastScreenAlpha = -1;    int colorChanged = 0;    // byte to float scale factor    static final float ByteToFloatScale = 1.0f/255.0f;    // float to byte scale factor    static final float FloatToByteScale = 255.0f;    // Set flag indicating that we are in the updater.  This flag    // can be used by the various setRef methods to inhibit any    // update messages    boolean inUpdater = false;    // Array List used for messages    ArrayList gaList = new ArrayList(1);    // Target threads to be notified when morph changes    static final int targetThreads = (J3dThread.UPDATE_RENDER |				      J3dThread.UPDATE_GEOMETRY);    // used for byReference geometry    float[] floatRefCoords = null;    double[] doubleRefCoords = null;    Point3d[] p3dRefCoords = null;    Point3f[] p3fRefCoords = null;    // Used for NIO buffer geometry    J3DBuffer coordRefBuffer = null;    FloatBufferWrapper floatBufferRefCoords = null;    DoubleBufferWrapper doubleBufferRefCoords = null;    // Initial index to use for rendering    int initialCoordIndex = 0;    int initialColorIndex = 0;    int initialNormalIndex = 0;    int[] initialTexCoordIndex = null;    int[] initialVertexAttrIndex = null;    int initialVertexIndex = 0;    // used for byReference colors    float[] floatRefColors = null;    byte[] byteRefColors = null;    Color3f[] c3fRefColors = null;    Color4f[] c4fRefColors = null;    Color3b[] c3bRefColors = null;    Color4b[] c4bRefColors = null;    // Used for NIO buffer colors    J3DBuffer colorRefBuffer = null;    FloatBufferWrapper floatBufferRefColors = null;    ByteBufferWrapper byteBufferRefColors = null;    // flag to indicate if the "by reference" component is already set    int vertexType = 0;    static  final int PF    = 0x1;    static  final int PD    = 0x2;    static  final int P3F   = 0x4;    static  final int P3D   = 0x8;    static final int VERTEX_DEFINED = PF | PD | P3F | P3D;    static final int CF  = 0x10;    static final int CUB = 0x20;    static final int C3F = 0x40;    static final int C4F = 0x80;    static final int C3UB  = 0x100;    static final int C4UB = 0x200;    static final int COLOR_DEFINED = CF | CUB | C3F | C4F| C3UB | C4UB;    static final int NF = 0x400;    static final int N3F = 0x800;    static final int NORMAL_DEFINED = NF | N3F;    static final int TF = 0x1000;    static final int T2F = 0x2000;    static final int T3F = 0x4000;    static final int TEXCOORD_DEFINED = TF | T2F | T3F;    static final int AF = 0x8000;    static final int VATTR_DEFINED = AF;    // Flag word indicating the type of by-ref texCoord. We will copy this to    // the vertexType field only when the references for all texture coordinate    // sets are set to non-null values.    private int texCoordType = 0;        // Flag word indicating the type of by-ref vertex attr. We will copy this to    // the vertexType field only when the references for all vertex attrs    // are set to non-null values.    private int vertexAttrType = 0;    // flag for execute geometry array when by reference    static final int COORD_FLOAT  = 0x01;    static final int COORD_DOUBLE = 0x02;    static final int COLOR_FLOAT  = 0x04;    static final int COLOR_BYTE   = 0x08;    static final int NORMAL_FLOAT = 0x10;    static final int TEXCOORD_FLOAT = 0x20;     static final int VATTR_FLOAT = 0x40;    // used by "by reference" normals    float[] floatRefNormals = null;    Vector3f[] v3fRefNormals = null;    // Used for NIO buffer normals    J3DBuffer normalRefBuffer = null;    FloatBufferWrapper floatBufferRefNormals = null;    // used for "by reference" vertex attrs    float[][] floatRefVertexAttrs = null;    // Used for NIO buffer vertex attrs    J3DBuffer[] vertexAttrsRefBuffer = null;    FloatBufferWrapper[] floatBufferRefVertexAttrs = null;    Object[] nioFloatBufferRefVertexAttrs = null;    // used by "by reference" tex coords    Object[] refTexCoords = null;    TexCoord2f[] t2fRefTexCoords = null;    TexCoord3f[] t3fRefTexCoords = null;    // Used for NIO buffer tex coords    Object[] refTexCoordsBuffer = null;    //FloatBufferWrapper[] floatBufferRefTexCoords = null;    // used by interleaved array    float[] interLeavedVertexData = null;    // used by interleaved NIO buffer    J3DBuffer interleavedVertexBuffer = null;    FloatBufferWrapper interleavedFloatBufferImpl = null;    // pointers used, when transparency is turned on    // or when its an object such as C3F, P3F etc ..    float[] mirrorFloatRefCoords = null;    double[] mirrorDoubleRefCoords = null;    float[] mirrorFloatRefNormals = null;    float[][] mirrorFloatRefVertexAttrs = null;    float[] mirrorFloatRefTexCoords = null;    Object[] mirrorRefTexCoords = null;    float[][] mirrorFloatRefColors = new float[1][];    byte[][] mirrorUnsignedByteRefColors= new byte[1][];    float[][] mirrorInterleavedColorPointer = null;    // boolean to determine if a mirror was allocated    int mirrorVertexAllocated = 0;    int mirrorColorAllocated = 0;    boolean mirrorNormalAllocated = false;    // Some dirty bits for GeometryArrays    static final int COORDINATE_CHANGED 	= 0x01;    static final int NORMAL_CHANGED 		= 0x02;    static final int COLOR_CHANGED 		= 0x04;    static final int TEXTURE_CHANGED 		= 0x08;    static final int BOUNDS_CHANGED 		= 0x10;    static final int INDEX_CHANGED 		= 0x20;        static final int STRIPCOUNT_CHANGED 	= 0x40;    static final int VATTR_CHANGED 		= 0x80;    static final int VERTEX_CHANGED             = COORDINATE_CHANGED |                                                  NORMAL_CHANGED |                                                  COLOR_CHANGED |                                                  TEXTURE_CHANGED |                                                  VATTR_CHANGED;    static final int defaultTexCoordSetMap[] = {0};    int texCoordSetCount = 0;    int [] texCoordSetMap = null;    // this array contains offset to the texCoord data for each    // texture unit.  -1 means no corresponding texCoord data offset    int [] texCoordSetMapOffset = null;    // Vertex attribute information    int vertexAttrCount = 0;    int[] vertexAttrSizes = null;    // This point to a list of VertexBuffers in a Vector structure    // Each element correspond to a D3D context that create this VB.    // Note that this GeometryArray can be used by multiple ctx.    long pVertexBuffers = 0;    int dirtyFlag;    // each bit corresponds to a unique renderer if shared context    // or a unique canvas otherwise    int resourceCreationMask = 0x0;    // Fix for Issue 5    //    // Replace the per-canvas reference count with a per-RenderBin set    // of users.  The per-RenderBin set of users of this display list    // is defined as a HashMap where:    //    //   key   = the RenderBin    //   value = a set of RenderAtomListInfo objects using this    //           geometry array for display list purposes    private HashMap dlistUsers = null;    // timestamp used to create display list. This is either    // one per renderer for useSharedCtx, or one per Canvas for non-shared    // ctx    private long[] timeStampPerDlist = new long[2];    // Unique display list Id, if this geometry is shared    int dlistId = -1;    Integer dlistObj = null;        // A list of pre-defined bits to indicate which component    // in this Texture object changed.    //    static final int DLIST_CREATE_CHANGED      = 0x01;    static final int INIT_MIRROR_GEOMETRY      = 0x02;    // A list of Universes that this Geometry is referenced in Morph from    ArrayList morphUniverseList = null;    // A list of ArrayLists which contain all the MorphRetained objects    // refering to this geometry.  Each list corresponds to the universe    // above.    ArrayList morphUserLists = null;    // The following variables are only used in compile mode    // Offset of a geometry array into the merged array    int[] geoOffset;        // vertexcount of a geometry array in a merge array    int[] compileVcount;    boolean isCompiled = false;    boolean isShared = false;    IndexedGeometryArrayRetained cloneSourceArray = null;    static final double EPS = 1.0e-13;    void freeD3DArray(boolean deleteVB) {        assert VirtualUniverse.mc.isD3D();        Pipeline.getPipeline().freeD3DArray(this, deleteVB);    }    GeometryArrayRetained() {	dirtyFlag = INDEX_CHANGED|VERTEX_CHANGED;         lastAlpha[0] = 1.0f;    }    void setLive(boolean inBackgroundGroup, int refCount) {	dirtyFlag = VERTEX_CHANGED|INDEX_CHANGED;	            isEditable = !isWriteStatic();        super.doSetLive(inBackgroundGroup, refCount);	super.markAsLive();	// Send message to RenderingAttribute structure to obtain a dlistId	//	System.err.println("Geometry - "+this+"refCount = "+this.refCount);	if (this.refCount > 1) {	    // Send to rendering attribute structure,	    /*	    J3dMessage createMessage = new J3dMessage();	    createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES;	    createMessage.type = J3dMessage.GEOMETRYARRAY_CHANGED;	    createMessage.universe = null;	    createMessage.args[0] = this;	    createMessage.args[1]= new Integer(DLIST_CREATE_CHANGED);	    VirtualUniverse.mc.processMessage(createMessage);	    	    */	    isShared = true;	} // Clone geometry only for the first setLive	else {	    // If geometry is indexed and use_index_coord is false, unindexify	    // otherwise, set mirrorGeometry to null (from previous clearLive)	    if (this instanceof IndexedGeometryArrayRetained) { 		// Send to rendering attribute structure,		J3dMessage createMessage = new J3dMessage();		createMessage.threads = J3dThread.UPDATE_RENDERING_ATTRIBUTES;		createMessage.type = J3dMessage.GEOMETRY_CHANGED;		createMessage.universe = null;		createMessage.args[0] = null;		createMessage.args[1]= this;		createMessage.args[2]= new Integer(INIT_MIRROR_GEOMETRY);		VirtualUniverse.mc.processMessage(createMessage);	    }	}	        }    void clearLive(int refCount) {	super.clearLive(refCount);	if (this.refCount <= 0) {	    if (pVertexBuffers != 0) {		J3dMessage renderMessage = new J3dMessage();		renderMessage.threads = J3dThread.RENDER_THREAD;		renderMessage.type = J3dMessage.RENDER_IMMEDIATE;		renderMessage.universe = null;		renderMessage.view = null;		renderMessage.args[0] = null;		renderMessage.args[1] = this;		// Any one renderer is fine since VB store the ctx		// where it is created.		Enumeration e = Screen3D.deviceRendererMap.elements();		Renderer rdr = (Renderer) e.nextElement();		rdr.rendererStructure.addMessage(renderMessage);		VirtualUniverse.mc.setWorkForRequestRenderer();	    }	    isShared = false;	}    }    void computeBoundingBox() {	//	System.err.println("computeBoundingBox ....");        if (boundsDirty && VirtualUniverse.mc.cacheAutoComputedBounds) {            for(ArrayList<Shape3DRetained> users : userLists) {                for(Shape3DRetained shape : users)                    shape.dirtyBoundsCache();            }        }        	if ((vertexFormat & GeometryArray.BY_REFERENCE) == 0) {	    // by copy	    	    computeBoundingBox(initialVertexIndex, vertexData);	    	} else if ((vertexFormat & GeometryArray.USE_NIO_BUFFER) != 0) { // USE_NIO_BUFFER 	    //System.err.println("vertexFormat & GeometryArray.USE_NIO_BUFFER");	    if((vertexFormat & GeometryArray.INTERLEAVED) != 0) {		computeBoundingBox(initialCoordIndex, interleavedFloatBufferImpl);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -