Example #1
0
        public byte[] TryLoadShaderBytesFromFile(ShaderFileInfo fileInfo)
        {
            var filePath = Path.Combine(fileInfo.Directory, $"{fileInfo.Name}.{fileInfo.Extension}");

            var shaderBytes = new byte[] { };

            if (_fileSystem.Exists(filePath))
            {
                shaderBytes = _fileSystem.ReadAllBytes(filePath);
            }
            else
            {
                _frameworkMessenger.Report(string.Concat("Error: Unable to find shader file from path: ", filePath));
            }

            return(shaderBytes);
        }
Example #2
0
        public byte[] TryLoadShaderBytesFromEmbeddedResource(ShaderFileInfo fileInfo)
        {
            var shaderBytes = new byte[] { };

            var commonPath = string.Concat(fileInfo.Directory, ".", fileInfo.Name, ".", fileInfo.Extension);

            var nameFoundInFrameworkAssembly = IsResourcePathInAssembly(_graphicsAssembly, commonPath);
            var nameFoundInAppAssembly       = IsResourcePathInAssembly(_applicationAssembly, commonPath);

            if (!(nameFoundInFrameworkAssembly || nameFoundInAppAssembly))
            {
                _frameworkMessenger.Report("Asset common path not found in framework or application assembly");
                return(shaderBytes);
            }

            if (nameFoundInFrameworkAssembly && nameFoundInAppAssembly)
            {
                _frameworkMessenger.Report(string.Concat("Warning: Asset common path found in both framework and application assemblies: using application assembly as override: ", commonPath));
            }

            var assembly = nameFoundInAppAssembly ? _applicationAssembly : _graphicsAssembly;

            var assemblyPath = string.Concat(assembly.Name,
                                             ".",
                                             commonPath);

            var stream = assembly.GetManifestResourceStream(assemblyPath);

            using (var memoryStream = new MemoryStream())
            {
                stream.CopyTo(memoryStream);
                shaderBytes = memoryStream.ToArray();
            }

            return(shaderBytes);
        }