64 if (iptexture ==
nullptr || iptexture->embedded_image() ==
nullptr ||
65 iptexture->embedded_image()->bytes() ==
nullptr) {
69 auto embedded = iptexture->embedded_image();
71 uint8_t bytes_per_component = 0;
72 switch (embedded->component_type()) {
73 case fb::ComponentType::k8Bit:
74 bytes_per_component = 1;
76 case fb::ComponentType::k16Bit:
78 FML_LOG(WARNING) <<
"16 bit textures not yet supported.";
82 switch (embedded->component_count()) {
89 FML_LOG(WARNING) <<
"Textures with " << embedded->component_count()
90 <<
" components are not supported." << std::endl;
93 if (embedded->bytes()->size() != bytes_per_component *
94 embedded->component_count() *
95 embedded->width() * embedded->height()) {
96 FML_LOG(WARNING) <<
"Embedded texture has an unexpected size. Skipping."
101 auto image_mapping = std::make_shared<fml::NonOwnedMapping>(
102 embedded->bytes()->Data(), embedded->bytes()->size());
104 auto texture_descriptor = TextureDescriptor{};
105 texture_descriptor.storage_mode = StorageMode::kHostVisible;
106 texture_descriptor.format = PixelFormat::kR8G8B8A8UNormInt;
107 texture_descriptor.size =
ISize(embedded->width(), embedded->height());
109 texture_descriptor.mip_count = 1u;
111 auto texture = allocator.CreateTexture(texture_descriptor);
113 FML_LOG(ERROR) <<
"Could not allocate texture.";
117 auto uploaded = texture->SetContents(image_mapping);
119 FML_LOG(ERROR) <<
"Could not upload texture to device memory.";