yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
4c76b2759
master
1#ifndef SLANG_RIFF_FILE_SYSTEM_H 2#define SLANG_RIFF_FILE_SYSTEM_H 3 4#include "slang-archive-file-system.h" 5#include "slang-memory-file-system.h" 6#include "slang-riff.h" 7 8namespace Slang 9{ 10 11// The riff information used for RiffArchiveFileSystem 12struct RiffFileSystemBinary 13{ 14static const FourCC ::RawValue kContainerFourCC = SLANG_FOUR_CC ('S ', 'c ', 'o ', 'n '); 15static const FourCC ::RawValue kEntryFourCC = SLANG_FOUR_CC ('S ', 'f ', 'i ', 'l '); 16static const FourCC ::RawValue kHeaderFourCC = SLANG_FOUR_CC ('S ', 'h ', 'e ', 'a '); 17 18struct Header 19 { 20uint32_t compressionSystemType ;/// One of CompressionSystemType 21 }; 22 23struct Entry 24 { 25uint32_t compressedSize ; 26uint32_t uncompressedSize ; 27uint32_t pathSize ;///< The size of the path in bytes, including terminating 0 28uint32_t pathType ;///< One of SlangPathType 29 30// Followed by the path (including terminating 0) 31// Followed by the compressed data 32 }; 33}; 34 35/* RiffFileSystem implements ISlangMutableFileSystem and can be used to save and load the whole of 36it's contents as an 'archive' blob. 37 38The 'RIFF' part provides the structure to store out the contents. The data is only accessed in the 39RIFF format when being read/written to an archive. Normal operations on the file system act in 40memory. 41 42A RiffFileSystem allows for compression to be used on files. To use compression pass in a suitable 43ICompressionSystem implementation on construction. If constructed without an ICompressionSystem, 44data is stored uncompressed. When compression is used, files 'contents' blob is actually the 45*compressed* version of the contents. Calling loadFile/saveFile will uncompress/compress as need. If 46there is no compression contents is identical to the file contents. 47 48NOTE: 49* The RIFF chunk IDs are *slang specific*. It conforms to RIFF but is unlikely to be usable with 50other tooling. 51* The RIFF chunk IDs are in RiffFileSystemBinary struct 52*/ 53class RiffFileSystem :public MemoryFileSystem ,public IArchiveFileSystem 54{ 55public : 56typedef MemoryFileSystem Super ; 57 58// ISlangUnknown 59SLANG_COM_BASE_IUNKNOWN_ALL 60 61// ISlangCastable 62virtual SLANG_NO_THROW void * SLANG_MCALL castAs (const Guid & guid )SLANG_OVERRIDE ; 63 64// ISlangFileSystem 65virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile (char const * path ,ISlangBlob ** outBlob ) 66SLANG_OVERRIDE ; 67 68// ISlangModifyableFileSystem 69virtual SLANG_NO_THROW SlangResult SLANG_MCALL 70saveFile (const char * path ,const void * data ,size_t size )SLANG_OVERRIDE ; 71virtual SLANG_NO_THROW SlangResult SLANG_MCALL 72saveFileBlob (const char * path ,ISlangBlob * dataBlob )SLANG_OVERRIDE ; 73 74// IArchiveFileSystem 75virtual SLANG_NO_THROW SlangResult SLANG_MCALL 76loadArchive (const void * archive ,size_t archiveSizeInBytes )SLANG_OVERRIDE ; 77virtual SLANG_NO_THROW SlangResult SLANG_MCALL 78storeArchive (bool blobOwnsContent ,ISlangBlob ** outBlob )SLANG_OVERRIDE ; 79virtual SLANG_NO_THROW void SLANG_MCALL setCompressionStyle (const CompressionStyle & style ) 80SLANG_OVERRIDE 81 { 82m_compressionStyle = style ; 83 } 84 85/// Pass in nullptr, if no compression is wanted. 86explicit RiffFileSystem (ICompressionSystem * compressionSystem ); 87 88/// True if this appears to be Riff archive 89static bool isArchive (const void * data ,size_t sizeInBytes ); 90 91protected : 92void * getInterface (const Guid & guid ); 93void * getObject (const Guid & guid ); 94 95ComPtr < ICompressionSystem > m_compressionSystem ; 96 97CompressionStyle m_compressionStyle ; 98}; 99 100}// namespace Slang 101 102#endif