@@ -21,45 +21,32 @@ std::shared_ptr<IResource> ResourceFactoryBinaryTextureV0::ReadResource(std::sha
21
21
22
22
auto texture = std::make_shared<Texture>(initData);
23
23
24
-
25
-
26
- std::shared_ptr<ResourceVersionFactory> factory = nullptr ;
27
-
28
- switch (resource->GetInitData ()->ResourceVersion ) {
29
- case 0 :
30
- factory = std::make_shared<TextureFactoryV0>();
31
- break ;
32
- case 1 :
33
- factory = std::make_shared<TextureFactoryV1>();
34
- break ;
35
- }
36
-
37
- if (factory == nullptr ) {
38
- SPDLOG_ERROR (" Failed to load Texture with version {}" , resource->GetInitData ()->ResourceVersion );
39
- return nullptr ;
40
- }
41
-
42
- factory->ParseFileBinary (reader, resource);
43
-
44
- return resource;
45
- }
46
-
47
- void TextureFactoryV0::ParseFileBinary (std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) {
48
- // std::shared_ptr<Texture> texture = std::static_pointer_cast<Texture>(resource);
49
- ResourceVersionFactory::ParseFileBinary (reader, texture);
50
-
51
24
texture->Type = (TextureType)reader->ReadUInt32 ();
52
25
texture->Width = reader->ReadUInt32 ();
53
26
texture->Height = reader->ReadUInt32 ();
54
27
texture->ImageDataSize = reader->ReadUInt32 ();
55
28
texture->ImageData = new uint8_t [texture->ImageDataSize ];
56
29
57
30
reader->Read ((char *)texture->ImageData , texture->ImageDataSize );
31
+
32
+ return texture;
58
33
}
59
34
60
- void TextureFactoryV1::ParseFileBinary (std::shared_ptr<BinaryReader> reader, std::shared_ptr<IResource> resource) {
61
- std::shared_ptr<Texture> texture = std::static_pointer_cast<Texture>(resource);
62
- ResourceVersionFactory::ParseFileBinary (reader, texture);
35
+ std::shared_ptr<IResource> ResourceFactoryBinaryTextureV1::ReadResource (std::shared_ptr<ResourceInitData> initData,
36
+ std::shared_ptr<ReaderBox> readerBox) {
37
+ auto binaryReaderBox = std::dynamic_pointer_cast<BinaryReaderBox>(readerBox);
38
+ if (binaryReaderBox == nullptr ) {
39
+ SPDLOG_ERROR (" ReaderBox must be a BinaryReaderBox." );
40
+ return nullptr ;
41
+ }
42
+
43
+ auto reader = binaryReaderBox->GetReader ();
44
+ if (reader == nullptr ) {
45
+ SPDLOG_ERROR (" null reader in box." );
46
+ return nullptr ;
47
+ }
48
+
49
+ auto texture = std::make_shared<Texture>(initData);
63
50
64
51
texture->Type = (TextureType)reader->ReadUInt32 ();
65
52
texture->Width = reader->ReadUInt32 ();
@@ -71,5 +58,7 @@ void TextureFactoryV1::ParseFileBinary(std::shared_ptr<BinaryReader> reader, std
71
58
texture->ImageData = new uint8_t [texture->ImageDataSize ];
72
59
73
60
reader->Read ((char *)texture->ImageData , texture->ImageDataSize );
61
+
62
+ return texture;
74
63
}
75
64
} // namespace LUS
0 commit comments