示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PrimitiveBatch{T}" /> class.
        /// </summary>
        /// <param name="graphicsDevice">The device.</param>
        /// <param name="maxIndices">The max indices.</param>
        /// <param name="maxVertices">The max vertices.</param>
        public PrimitiveBatch(GraphicsDevice graphicsDevice, int maxIndices = DefaultBatchSize * 3, int maxVertices = DefaultBatchSize)
            : base(graphicsDevice, maxIndices, maxVertices, Utilities.SizeOf <T>())
        {
            var vertexElements = VertexElement.FromType <T>();

            // If the type has some VertexElement description, we can use them directly to setup the vertex input layout.
            if (vertexElements != null)
            {
                vertexInputLayout = VertexInputLayout.New(0, vertexElements);
            }
        }
示例#2
0
        protected virtual void ReadVertexBuffer(ref VertexBufferBinding vertexBufferBinding)
        {
            // Read the number of vertices
            int count = Reader.ReadInt32();

            // Read vertex elements
            int vertexElementCount = Reader.ReadInt32();
            var elements           = new VertexElement[vertexElementCount];

            for (int i = 0; i < vertexElementCount; i++)
            {
                elements[i].Serialize(this);
            }
            vertexBufferBinding.Layout = VertexInputLayout.New(0, elements);

            // Read Vertex Buffer
            int sizeInBytes = Reader.ReadInt32();

            SerializeMemoryRegion(SharedMemoryPointer, sizeInBytes);
            vertexBufferBinding.Buffer = Buffer.New(GraphicsDevice, new DataPointer(SharedMemoryPointer, sizeInBytes), sizeInBytes / count, BufferFlags.VertexBuffer, ResourceUsage.Immutable);
        }