如何将较大的图像替换小图像在金属中。

huangapple go评论57阅读模式
英文:

how larger image replace small image in metal

问题

这是一个非常愚蠢的问题。我想播放一个视频。根据苹果的官方指南,我应该重用纹理资源,所以我选择了replaceRegion,但我选择的图片大小不一致。有没有办法将较大的图片放入以前的小纹理中,或者我应该在创建纹理时从一开始就使用最大的作为标准?

我是一个初学者。我之前学过一点Vulkan,这是我第一次使用Swift和Metal。你能推荐给我一条好的学习路径吗?谢谢!

if (changeRequest) {
    changeRequest = false
    let region = MTLRegionMake2D(0, 0, Int(stagingBuffer.size.width), Int(stagingBuffer.size.height))
    textures[currentFrame].replace(region: region, mipmapLevel: 0, withBytes: &stagingBuffer, bytesPerRow: Int(stagingBuffer.size.width * stagingBuffer.size.height) * 4)
}
英文:

It's a very stupid question. I want to play a video. According to Apple's official guide, I should reuse texture resources, so I choose replaceRegion, but the size of the pictures I choose is not consistent. Is there any way to put a bigger breakthrough into the previous small texture? , or I suppose to use the largest as the standard when creating textures from the beginning?

I am a beginner. I have learned a little bit of vulkan before, and it's my first time to use swift and metal. Is there any good learning path that you can recommend to me? Thanks!

        if(changeRequest){
            changeRequest = false
            let region = MTLRegionMake2D(0, 0, Int(stagingBuffer.size.width), Int(stagingBuffer.size.height))
            textures[currentFrame].replace(region: region, mipmapLevel: 0, withBytes: &stagingBuffer, bytesPerRow: Int(stagingBuffer.size.width * stagingBuffer.size.height) * 4)
            }

答案1

得分: 0

如果您想重新使用纹理,您将不得不为您计划使用的最大纹理创建它。一旦分配了MTLTexture,就无法扩大其范围。

因此,创建所需大小的纹理或纹理系列(例如512x512、768x768、1024x1024)可能更有意义。

请注意,您可以使用MPSImageLanczosScale来缩放MTLTexture,但它会创建一个新的纹理,所以我不认为这是您想要做的。

英文:

If you want to reuse the texture, you will have to create it for the largest you texture plan on using. There is no way to enlarge the extent of a MTLTexture once it has been allocated.

Therefore it may make more sense to create textures the size needed, or a family of textures (eg 512x512, 768x768, 1024x1024).

Note that you can scale a MTLTexture using MPSImageLanczosScale, but it creates a new texture, so I don't think that is what you want to do.

huangapple
  • 本文由 发表于 2023年7月11日 12:29:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76658721.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定