14 const void* mtl_texture,
15 std::function<
void()> deletion_proc) {
17 std::move(deletion_proc));
24 :
Texture(p_desc), aquire_proc_(aquire_proc), is_drawable_(drawable) {
27 if (!desc.
IsValid() || !aquire_proc) {
31 if (desc.
size != GetSize()) {
32 VALIDATION_LOG <<
"The texture and its descriptor disagree about its size.";
36 is_wrapped_ = wrapped;
42 id<MTLTexture> texture,
43 std::function<
void()> deletion_proc) {
45 return std::shared_ptr<TextureMTL>(
47 desc, [texture]() {
return texture; },
true),
48 [deletion_proc = std::move(deletion_proc)](
TextureMTL* t) {
53 return std::shared_ptr<TextureMTL>(
54 new TextureMTL(desc, [texture]() {
return texture; },
true));
58 id<MTLTexture> texture) {
59 return std::make_shared<TextureMTL>(desc, [texture]() {
return texture; });
64 void TextureMTL::SetLabel(std::string_view label) {
68 [aquire_proc_() setLabel:@(label.data())];
72 bool TextureMTL::OnSetContents(
std::shared_ptr<const fml::Mapping> mapping,
76 return OnSetContents(mapping->GetMapping(), mapping->GetSize(), slice);
80 bool TextureMTL::OnSetContents(
const uint8_t* contents,
83 if (!
IsValid() || !contents || is_wrapped_ || is_drawable_) {
96 [aquire_proc_() replaceRegion:region
100 bytesPerRow:desc.GetBytesPerRow()
101 bytesPerImage:desc.GetByteSizeOfBaseMipLevel()
111 const auto& texture = aquire_proc_();
117 return aquire_proc_();
137 auto texture = aquire_proc_();
142 [encoder generateMipmapsForTexture:texture];