Esempio n. 1
0
        internal static bool TryFetch(MyShaderIdentity identity, out byte[] cache)
        {
            bool found;
            found = TryFetch(identity, MyFileSystem.ContentPath, out cache);
            if (found)
                return true;

            found = TryFetch(identity, MyFileSystem.UserDataPath, out cache);
            if (found)
                return true;

            return false;
        }
Esempio n. 2
0
        internal static bool TryFetch(MyShaderIdentity identity, out byte[] cache)
        {
            bool found;

            found = TryFetch(identity, MyFileSystem.ContentPath, out cache);
            if (found)
            {
                return(true);
            }

            found = TryFetch(identity, MyFileSystem.UserDataPath, out cache);
            if (found)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 3
0
        internal static void Store(MyShaderIdentity identity, byte[] compiled)
        {
            // Store first the compiled code assuming no I/O error, so we can just check compressed source later
            string fileName = Path.Combine(MyFileSystem.UserDataPath, MyShadersDefines.CachePath, identity.CacheFilename);
            using (var writer = new FileStream(fileName, FileMode.CreateNew))
            {
                writer.Write(compiled, 0, compiled.Length);
            }

            fileName = Path.Combine(MyFileSystem.UserDataPath, MyShadersDefines.CachePath, identity.SourceFilename);
            if (!File.Exists(fileName))
            {
                using (var stream = new FileStream(fileName, FileMode.CreateNew))
                {
                    stream.Write(identity.Source, 0, identity.Source.Length);
                }
            }
        }
Esempio n. 4
0
        internal static void Store(MyShaderIdentity identity, byte[] compiled)
        {
            // Store first the compiled code assuming no I/O error, so we can just check compressed source later
            string fileName = Path.Combine(MyFileSystem.UserDataPath, MyShadersDefines.CachePath, identity.CacheFilename);

            using (var writer = new FileStream(fileName, FileMode.CreateNew))
            {
                writer.Write(compiled, 0, compiled.Length);
            }

            fileName = Path.Combine(MyFileSystem.UserDataPath, MyShadersDefines.CachePath, identity.SourceFilename);
            if (!File.Exists(fileName))
            {
                using (var stream = new FileStream(fileName, FileMode.CreateNew))
                {
                    stream.Write(identity.Source, 0, identity.Source.Length);
                }
            }
        }
Esempio n. 5
0
        private static bool TryFetch(MyShaderIdentity identity, string basePath, out byte[] cache)
        {
            cache = null;
            var sourceFilename = Path.Combine(basePath, MyShadersDefines.CachePath, identity.SourceFilename);
            var cacheFilename = Path.Combine(basePath, MyShadersDefines.CachePath, identity.CacheFilename);
            if (File.Exists(sourceFilename) && File.Exists(cacheFilename))
            {
                byte[] compressed = File.ReadAllBytes(sourceFilename);
                if (compressed.Compare(identity.Source))
                {
                    cache = File.ReadAllBytes(cacheFilename);
                    return true;
                }
                else
                {
                    // Non match should happen in case of I/O error or extremely unlikely occurrence
                    MyRender11.Log.WriteLine("Shader with hash " + identity.Hash + " didn't mach on cache");
                }
            }

            return false;
        }
        private static bool TryFetch(MyShaderIdentity identity, string basePath, out byte[] cache)
        {
            cache = null;
            var sourceFilename = Path.Combine(basePath, MyShadersDefines.CachePath, identity.SourceFilename);
            var cacheFilename  = Path.Combine(basePath, MyShadersDefines.CachePath, identity.CacheFilename);

            if (File.Exists(sourceFilename) && File.Exists(cacheFilename))
            {
                byte[] compressed = File.ReadAllBytes(sourceFilename);
                if (compressed.Compare(identity.Source))
                {
                    cache = File.ReadAllBytes(cacheFilename);
                    return(true);
                }
                else
                {
                    // Non match should happen in case of I/O error or extremely unlikely occurrence
                    MyRender11.Log.WriteLine("Shader with hash " + identity.Hash + " didn't mach on cache");
                }
            }

            return(false);
        }