Example #1
0
 private void SavePool(VertexBufferPool pool, string name, bool isBigEndian)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         pool.WriteToFile(stream, isBigEndian);
         File.WriteAllBytes(name, stream.ToArray());
         loadedPoolNames.Add(new FileInfo(name));
     }
 }
Example #2
0
        public void ReadFiles(bool isBigEndian)
        {
            for (int i = 0; i != loadedPoolNames.Count; i++)
            {
                VertexBufferPool pool = null;
                using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(loadedPoolNames[i].FullName), false))
                {
                    pool = new VertexBufferPool(stream, isBigEndian);
                }

                foreach (var buff in pool.Buffers)
                {
                    if (!buffers.ContainsKey(buff.Key))
                    {
                        buffers.Add(buff.Key, buff.Value);
                    }
                    else
                    {
                        Console.WriteLine("Skipped a buffer {0}", buff.Key);
                    }
                }
            }
        }
Example #3
0
        public void WriteToFile(bool isBigEndian = false)
        {
            int numPool           = 0;
            int poolSize          = 0;
            VertexBufferPool pool = new VertexBufferPool();

            foreach (var loaded in loadedPoolNames)
            {
                File.Delete(loaded.FullName);
            }
            loadedPoolNames.Clear();
            var buffArray = buffers.Values.ToArray();

            //var sorted = buffArray.OrderBy(buff => buff.Data.Length);
            foreach (var buffer in buffArray)
            {
                int prePoolSize = (poolSize) + (buffer.Data.Length);
                if (pool.Buffers.Count == 128 || prePoolSize > ToolkitSettings.VertexMemorySizePerBuffer)
                {
                    string name = Path.Combine(root.FullName, string.Format("VertexBufferPool_{0}.vbp", numPool));
                    SavePool(pool, name, isBigEndian);
                    pool = new VertexBufferPool();
                    numPool++;
                    prePoolSize = 0;
                }

                pool.Buffers.Add(buffer.Hash, buffer);
                poolSize = prePoolSize;
            }

            if (pool != null)
            {
                string name = Path.Combine(root.FullName, string.Format("VertexBufferPool_{0}.vbp", numPool));
                SavePool(pool, name, isBigEndian);
            }
        }