Exemplo n.º 1
0
        public static TAsset[] LoadAll <TAsset>(this IAssetSource source, string dir) where TAsset : IBasicAsset
        {
            var paths   = source.ListAll <TAsset>(dir).ToArray();
            var results = new TAsset[paths.Length];

            for (int i = 0; i < paths.Length; ++i)
            {
                var path = paths[i];
                results[i] = source.Load <TAsset>(path);
            }
            return(results);
        }
Exemplo n.º 2
0
        public async Task LoadAssets(IAssetSource assetSource)
        {
            var shaderFileName = assetSource.GetAbsolutePath(ShaderFilename);
            var shaderFilenameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(shaderFileName);
            var compiledShadersExist           = new string[] {
                $"{shaderFilenameWithoutExtension}.vs.spirv",
                $"{shaderFilenameWithoutExtension}.fs.spirv"
            }.Aggregate(true, (shadersExist, fileName) =>
                        shadersExist && assetSource.Exists(assetSource.GetAbsolutePath(fileName))
                        );

            var isVulkan = Game.Services.Resolve <Services.GraphicsDeviceFeatures>().BackendType == GraphicsBackend.Vulkan;

            if ((!_isWindows || isVulkan) && compiledShadersExist)
            {
                // TODO: Wait for https://github.com/mellinoe/veldrid-spirv/pull/2 and remove this? Or keep em for mobile?
                _vertexShaderSource = await ShaderImporter.Instance.Import(assetSource.Load(
                                                                               AssetType.Shader,
                                                                               assetSource.GetAbsolutePath($"{shaderFilenameWithoutExtension}.vs.spirv")
                                                                               ));

                _fragmentShaderSource = await ShaderImporter.Instance.Import(assetSource.Load(
                                                                                 AssetType.Shader,
                                                                                 assetSource.GetAbsolutePath($"{shaderFilenameWithoutExtension}.fs.spirv")
                                                                                 ));
            }
            else if (assetSource.Exists(shaderFileName))
            {
                var shaderSource = await ShaderImporter.Instance.Import(
                    assetSource.Load(AssetType.Shader, shaderFileName)
                    );

                _vertexShaderSource = _fragmentShaderSource = shaderSource;
            }
            else
            {
                throw new FileNotFoundException($"Shader not found: {ShaderFilename}");
            }
        }