66// NOTE: 本来resourceはcoreにのみ依存したいが、attachmentだけは例外的にwindowを知って良いとする。
77#include " ../window/swapchain.hpp"
88
9+ #include < memory>
910#include < unordered_map>
1011
1112namespace graphics ::resource {
1213
13- std::vector<std::unordered_map<std::string, Image>> g_attachmentImages;
14+ // NOTE: MSVCだと謎のコンパイルエラーが発生するので、unique_ptrで管理する。
15+ std::vector<std::unordered_map<std::string, std::unique_ptr<Image>>> g_attachmentImages;
1416
1517void destroyAllAttachmentImages () noexcept {
1618 g_attachmentImages.clear ();
@@ -25,15 +27,15 @@ void initializeAllAttachmentImages() {
2527 const auto &extent = swapchain.getExtent ();
2628 g_attachmentImages.reserve (images.size ());
2729 for (size_t i = 0 ; i < images.size (); ++i) {
28- std::unordered_map<std::string, Image> m;
30+ std::unordered_map<std::string, std::unique_ptr< Image> > m;
2931 for (const auto &[id, n]: config::config ().attachments ) {
3032 const auto format = config::convertFormat (n.format , swapchain.getFormat ());
3133 const auto aspect = config::getImageAspectFromFormat (n.format );
3234 if (n.format == config::Format::RenderTarget) {
33- m.try_emplace (id, images[i], format, aspect, 4 );
35+ m.emplace (id, std::make_unique<Image>( images[i], format, aspect, 4 ) );
3436 } else {
3537 const auto usage = config::getImageUsageFromFormat (n.format );
36- m.try_emplace (id, extent.width , extent.height , nullptr , format, usage, aspect, 4 );
38+ m.emplace (id, std::make_unique<Image>( extent.width , extent.height , nullptr , format, usage, aspect, 4 ) );
3739 }
3840 }
3941 g_attachmentImages.emplace_back (std::move (m));
@@ -43,7 +45,7 @@ void initializeAllAttachmentImages() {
4345const Image &getAttachmentImage (uint32_t index, const std::string &id) {
4446 const auto &images = error::at (g_attachmentImages, index, " attachments" );
4547 const auto &image = error::at (images, id, " attachments" );
46- return image;
48+ return * image;
4749}
4850
4951} // namespace graphics::resource
0 commit comments