Reads and writes index buffer data.
        public void ConvertIndexBuffer(RenderGeometryApiResourceDefinition resourceDefinition, Stream inputStream, Stream outputStream, int indexBufferIndex)
        {
            var indexBuffer = resourceDefinition.IndexBuffers[indexBufferIndex].Definition;

            var indexCount = indexBuffer.Data.Size / 2;

            var inIndexStream = new IndexBufferStream(
                inputStream,
                EndianFormat.BigEndian);

            var outIndexStream = new IndexBufferStream(
                outputStream,
                EndianFormat.LittleEndian);

            StreamUtil.Align(outputStream, 4);
            indexBuffer.Data.Address = new CacheAddress(CacheAddressType.Resource, (int)outputStream.Position);

            for (var j = 0; j < indexCount; j++)
            {
                outIndexStream.WriteIndex(inIndexStream.ReadIndex());
            }

            resourceDefinition.IndexBuffers[indexBufferIndex].DefinitionAddress = 0;
            resourceDefinition.IndexBuffers[indexBufferIndex].RuntimeAddress    = 0;
        }
Exemplo n.º 2
0
        private static void SerializeIndexBuffer(MeshData mesh, Stream outStream)
        {
            var indexStream = new IndexBufferStream(outStream, IndexBufferFormat.UInt16);

            foreach (var index in mesh.Indexes)
            {
                indexStream.WriteIndex(index);
            }
            StreamUtil.Align(outStream, 4);
        }
Exemplo n.º 3
0
        public static void ConvertIndexBuffer(CacheVersion inVersion, CacheVersion outVersion, IndexBufferDefinition indexBuffer)
        {
            using (var outputStream = new MemoryStream())
                using (var inputStream = new MemoryStream(indexBuffer.Data.Data))
                {
                    var inIndexStream  = new IndexBufferStream(inputStream, CacheVersionDetection.IsLittleEndian(inVersion) ? EndianFormat.LittleEndian : EndianFormat.BigEndian);
                    var outIndexStream = new IndexBufferStream(outputStream, CacheVersionDetection.IsLittleEndian(outVersion) ? EndianFormat.LittleEndian : EndianFormat.BigEndian);
                    var indexCount     = indexBuffer.Data.Data.Length / 2;
                    for (var j = 0; j < indexCount; j++)
                    {
                        outIndexStream.WriteIndex(inIndexStream.ReadIndex());
                    }

                    indexBuffer.Data.Data = outputStream.ToArray();
                }
        }