@@ -1638,15 +1638,28 @@ std::vector<std::byte> VTF::bake() const {
16381638 std::vector<std::byte> out;
16391639 BufferStream writer{out};
16401640
1641- static constexpr auto writeNonLocalResource = [](BufferStream& writer_, Resource::Type type, std::span<const std::byte> data, VTF::Platform platform) {
1642- if (platform != VTF::PLATFORM_PC) {
1641+ static auto writeNonLocalResource = [this ](BufferStream& writer_, Resource::Type type, std::span<const std::byte> data, VTF::Platform platform) {
1642+ if (platform != VTF::PLATFORM_PC && std::endian::native == std::endian::little ) {
16431643 BufferStream::swap_endian (reinterpret_cast <uint32_t *>(&type));
16441644 }
16451645 writer_.write <uint32_t >(type);
16461646 const auto resourceOffsetPos = writer_.tell ();
16471647 writer_.seek (0 , std::ios::end);
16481648 const auto resourceOffsetValue = writer_.tell ();
1649- writer_.write (data);
1649+
1650+ int8_t bpc = 8 ;
1651+ bpc = std::max (bpc, vtfpp::ImageFormatDetails::alpha (this ->getFormat ()));
1652+ bpc = std::max (bpc, vtfpp::ImageFormatDetails::red (this ->getFormat ()));
1653+ switch (bpc) {
1654+ case 16 :
1655+ writer_.write (std::span{reinterpret_cast <const uint16_t *>(data.data ()), data.size_bytes () / 2 });
1656+ break ;
1657+ case 32 :
1658+ writer_.write (std::span{reinterpret_cast <const uint32_t *>(data.data ()), data.size_bytes () / 4 });
1659+ break ;
1660+ default :
1661+ writer_.write (data);
1662+ }
16501663 writer_.seek_u (resourceOffsetPos).write <uint32_t >(resourceOffsetValue);
16511664 };
16521665
@@ -1681,7 +1694,9 @@ std::vector<std::byte> VTF::bake() const {
16811694 .write (this ->frameCount )
16821695 .write (this ->startFrame )
16831696 .write <uint32_t >(0 ) // padding
1684- .write (this ->reflectivity )
1697+ .write (this ->reflectivity [0 ])
1698+ .write (this ->reflectivity [1 ])
1699+ .write (this ->reflectivity [2 ])
16851700 .write <uint32_t >(0 ) // padding
16861701 .write (this ->bumpMapScale )
16871702 .write (bakeFormat)
0 commit comments