18 const void* mtl_texture,
19 std::function<
void()> deletion_proc) {
21 std::move(deletion_proc));
28 :
Texture(p_desc), aquire_proc_(aquire_proc), is_drawable_(drawable) {
31 if (!desc.
IsValid() || !aquire_proc) {
35 if (desc.
size != GetSize()) {
36 VALIDATION_LOG <<
"The texture and its descriptor disagree about its size.";
40 is_wrapped_ = wrapped;
47 std::function<
void()> deletion_proc) {
49 return std::shared_ptr<TextureMTL>(
52 [deletion_proc = std::move(deletion_proc)](
TextureMTL* t) {
57 return std::shared_ptr<TextureMTL>(
63 return std::make_shared<TextureMTL>(desc, [
texture]() {
return texture; });
68 if (debug_allocator_) {
78void TextureMTL::SetLabel(std::string_view label) {
83 [aquire_proc_() setLabel:@(label.
data())];
87void TextureMTL::SetLabel(std::string_view label, std::string_view trailing) {
92 std::string combined = std::format(
"{} {}", label, trailing);
93 [aquire_proc_() setLabel:@(combined.
data())];
98bool TextureMTL::OnSetContents(std::shared_ptr<const fml::Mapping> mapping,
102 return OnSetContents(mapping->GetMapping(), mapping->GetSize(), slice);
106void TextureMTL::SetDebugAllocator(
107 const std::shared_ptr<DebugAllocatorStats>& debug_allocator) {
108 debug_allocator_ = debug_allocator;
113bool TextureMTL::OnSetContents(
const uint8_t* contents,
116 if (!
IsValid() || !contents || is_wrapped_ || is_drawable_) {
129 [aquire_proc_() replaceRegion:region
133 bytesPerRow:desc.GetBytesPerRow()
134 bytesPerImage:desc.GetByteSizeOfBaseMipLevel()
140ISize TextureMTL::GetSize()
const {
144 const auto&
texture = aquire_proc_();
150 return aquire_proc_();
175 [encoder generateMipmapsForTexture:
texture];
const TextureDescriptor & GetTextureDescriptor() const
id< MTLTexture > GetMTLTexture() const
TextureMTL(TextureDescriptor desc, const AcquireTextureProc &aquire_proc, bool wrapped=false, bool drawable=false)
bool IsDrawable() const
Whether or not this texture is wrapping a Metal drawable.
bool IsValid() const override
std::function< id< MTLTexture >()> AcquireTextureProc
This callback needs to always return the same texture when called multiple times.
bool GenerateMipmap(id< MTLBlitCommandEncoder > encoder)
static std::shared_ptr< TextureMTL > Wrapper(TextureDescriptor desc, id< MTLTexture > texture, std::function< void()> deletion_proc=nullptr)
static std::shared_ptr< TextureMTL > Create(TextureDescriptor desc, id< MTLTexture > texture)
std::shared_ptr< Texture > WrapperMTL(TextureDescriptor desc, const void *mtl_texture, std::function< void()> deletion_proc)
A lightweight object that describes the attributes of a texture that can then used an allocator to cr...
constexpr size_t GetByteSizeOfBaseMipLevel() const
constexpr bool IsValid() const
std::shared_ptr< const fml::Mapping > data