英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论