コード例 #1
0
ファイル: MeshDataPool.cs プロジェクト: anegostudios/vsapi
        /// <summary>
        /// Allocates a new pool for mesh data.
        /// </summary>
        /// <param name="capi">The core client API</param>
        /// <param name="verticesPoolSize">The vertices pool size.</param>
        /// <param name="indicesPoolSize">The index pool size.</param>
        /// <param name="maxPartsPerPool">The maximum parts per pool.</param>
        /// <param name="customFloats">The custom floats of the pool.</param>
        /// <param name="customBytes">The custom bytes of the pool.</param>
        /// <param name="customInts">The custom ints of the pool.</param>
        /// <returns>The resulting mesh data pool.</returns>
        public static MeshDataPool AllocateNewPool(ICoreClientAPI capi, int verticesPoolSize, int indicesPoolSize, int maxPartsPerPool, CustomMeshDataPartFloat customFloats = null, CustomMeshDataPartShort customShorts = null, CustomMeshDataPartByte customBytes = null, CustomMeshDataPartInt customInts = null)
        {
            MeshDataPool pool = new MeshDataPool(verticesPoolSize, indicesPoolSize, maxPartsPerPool);

            if (IntPtr.Size == 8)
            {
                // 64 bit builds require 64 bit memory addresses (should be long[] really, but GL.MultiDrawElements only accepts int[])
                pool.indicesStartsByte = new int[maxPartsPerPool * 2];
            }
            else
            {
                pool.indicesStartsByte = new int[maxPartsPerPool];
            }

            pool.indicesSizes = new int[maxPartsPerPool];

            // Allocate the right amount of bytes for custom data
            if (customFloats != null)
            {
                customFloats.SetAllocationSize(verticesPoolSize * customFloats.InterleaveStride / 4);
            }
            if (customShorts != null)
            {
                customShorts.SetAllocationSize(verticesPoolSize * customShorts.InterleaveStride / 2);
            }
            if (customBytes != null)
            {
                customBytes.SetAllocationSize(verticesPoolSize * customBytes.InterleaveStride);
            }
            if (customInts != null)
            {
                customInts.SetAllocationSize(verticesPoolSize * customInts.InterleaveStride / 4);
            }

            pool.modelRef = capi.Render.AllocateEmptyMesh(
                MeshData.XyzSize * verticesPoolSize,
                0,
                MeshData.UvSize * verticesPoolSize,
                MeshData.RgbaSize * verticesPoolSize,
                MeshData.FlagsSize * verticesPoolSize,
                MeshData.IndexSize * indicesPoolSize,
                customFloats,
                customShorts,
                customBytes,
                customInts,
                EnumDrawMode.Triangles,
                false
                );


            return(pool);
        }
コード例 #2
0
 /// <summary>
 /// Creates a new Mesh Data Pool
 /// </summary>
 /// <param name="masterPool">The master mesh data pool manager</param>
 /// <param name="frustumCuller">the Frustum Culler for the Pool</param>
 /// <param name="capi">The Client API</param>
 /// <param name="defaultVertexPoolSize">Size allocated for the Vertices.</param>
 /// <param name="defaultIndexPoolSize">Size allocated for the Indices</param>
 /// <param name="maxPartsPerPool">The maximum number of parts for this pool.</param>
 /// <param name="customFloats">Additional float data</param>
 /// <param name="customBytes">Additional byte data</param>
 /// <param name="customInts">additional int data</param>
 public MeshDataPoolManager(MeshDataPoolMasterManager masterPool, FrustumCulling frustumCuller, ICoreClientAPI capi, int defaultVertexPoolSize, int defaultIndexPoolSize, int maxPartsPerPool, CustomMeshDataPartFloat customFloats = null, CustomMeshDataPartShort customShorts = null, CustomMeshDataPartByte customBytes = null, CustomMeshDataPartInt customInts = null)
 {
     this.masterPool            = masterPool;
     this.frustumCuller         = frustumCuller;
     this.capi                  = capi;
     this.customFloats          = customFloats;
     this.customBytes           = customBytes;
     this.customInts            = customInts;
     this.customShorts          = customShorts;
     this.defaultIndexPoolSize  = defaultIndexPoolSize;
     this.defaultVertexPoolSize = defaultVertexPoolSize;
     this.maxPartsPerPool       = maxPartsPerPool;
 }