yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Theresa FoleyCleanups related to RIFF support (#7041)4c76b2759

master
3.5 KiB102 linesraw
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{
14    static const FourCC::RawValue kContainerFourCC = SLANG_FOUR_CC('S', 'c', 'o', 'n');
15    static const FourCC::RawValue kEntryFourCC = SLANG_FOUR_CC('S', 'f', 'i', 'l');
16    static const FourCC::RawValue kHeaderFourCC = SLANG_FOUR_CC('S', 'h', 'e', 'a');
17
18    struct Header
19    {
20        uint32_t compressionSystemType; /// One of CompressionSystemType
21    };
22
23    struct Entry
24    {
25        uint32_t compressedSize;
26        uint32_t uncompressedSize;
27        uint32_t pathSize; ///< The size of the path in bytes, including terminating 0
28        uint32_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:
56    typedef MemoryFileSystem Super;
57
58    // ISlangUnknown
59    SLANG_COM_BASE_IUNKNOWN_ALL
60
61    // ISlangCastable
62    virtual SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE;
63
64    // ISlangFileSystem
65    virtual SLANG_NO_THROW SlangResult SLANG_MCALL loadFile(char const* path, ISlangBlob** outBlob)
66        SLANG_OVERRIDE;
67
68    // ISlangModifyableFileSystem
69    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
70    saveFile(const char* path, const void* data, size_t size) SLANG_OVERRIDE;
71    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
72    saveFileBlob(const char* path, ISlangBlob* dataBlob) SLANG_OVERRIDE;
73
74    // IArchiveFileSystem
75    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
76    loadArchive(const void* archive, size_t archiveSizeInBytes) SLANG_OVERRIDE;
77    virtual SLANG_NO_THROW SlangResult SLANG_MCALL
78    storeArchive(bool blobOwnsContent, ISlangBlob** outBlob) SLANG_OVERRIDE;
79    virtual SLANG_NO_THROW void SLANG_MCALL setCompressionStyle(const CompressionStyle& style)
80        SLANG_OVERRIDE
81    {
82        m_compressionStyle = style;
83    }
84
85    /// Pass in nullptr, if no compression is wanted.
86    explicit RiffFileSystem(ICompressionSystem* compressionSystem);
87
88    /// True if this appears to be Riff archive
89    static bool isArchive(const void* data, size_t sizeInBytes);
90
91protected:
92    void* getInterface(const Guid& guid);
93    void* getObject(const Guid& guid);
94
95    ComPtr<ICompressionSystem> m_compressionSystem;
96
97    CompressionStyle m_compressionStyle;
98};
99
100} // namespace Slang
101
102#endif