admin管理员组文章数量:1289496
I've got a Texture2DArray object that's storing a bunch of textures used by my terrain via Shader. Within the UI I'm planning to have a series of buttons that show each of these textures for use in a map-editor style interface. The 2d array is 7x7 and I plan to have several different arrays for each biome. So I'd rather re-use the same set of buttons and just refresh the images on each button as needed.
So the basic plan is to pull the Texture2DArray into a List of Texture2D objects and then just assign those Texture2D's as the background images on my buttons.
However when I try to convert from the Texture2DArray to a Texture2D I get an error:
Graphics.CopyTexture called with mismatching texture types (src=5 dst=2)
I've tried a few things to get this value to even change, I've updated the format on my Texture2DArray from default to RGBA 32 bit. I've tried to ensure the generated Texture2D is using this value (see code below) but the values in the error never change. I always get src=5 and dst=2, even when switching the formats to other values such as DXT1.
Here's what I'm trying:
Texture2DArray texture2DArray = Resources.Load<Texture2DArray>("Textures/BiomeArrays/Default_Temperate/Default_Temperate_baseColor");
int arrayLength = texture2DArray.depth;
textures = new Texture2D[arrayLength];
Debug.Log("Length of Texture2DArray = " + arrayLength);
for (int i =0; i < arrayLength; i++) {
Texture2D tex = new Texture2D(texture2DArray.width, texture2DArray.height, TextureFormat.RGBA32, false);
Graphics.CopyTexture(texture2DArray, tex);
}
Debugging this code I do see that both objects have the same texture format (RGBA32), and the length of the array from that Debug.Log state is correct so it appears to be loading the array correctly. What is the error actually complaining about if not texture format?
I've got a Texture2DArray object that's storing a bunch of textures used by my terrain via Shader. Within the UI I'm planning to have a series of buttons that show each of these textures for use in a map-editor style interface. The 2d array is 7x7 and I plan to have several different arrays for each biome. So I'd rather re-use the same set of buttons and just refresh the images on each button as needed.
So the basic plan is to pull the Texture2DArray into a List of Texture2D objects and then just assign those Texture2D's as the background images on my buttons.
However when I try to convert from the Texture2DArray to a Texture2D I get an error:
Graphics.CopyTexture called with mismatching texture types (src=5 dst=2)
I've tried a few things to get this value to even change, I've updated the format on my Texture2DArray from default to RGBA 32 bit. I've tried to ensure the generated Texture2D is using this value (see code below) but the values in the error never change. I always get src=5 and dst=2, even when switching the formats to other values such as DXT1.
Here's what I'm trying:
Texture2DArray texture2DArray = Resources.Load<Texture2DArray>("Textures/BiomeArrays/Default_Temperate/Default_Temperate_baseColor");
int arrayLength = texture2DArray.depth;
textures = new Texture2D[arrayLength];
Debug.Log("Length of Texture2DArray = " + arrayLength);
for (int i =0; i < arrayLength; i++) {
Texture2D tex = new Texture2D(texture2DArray.width, texture2DArray.height, TextureFormat.RGBA32, false);
Graphics.CopyTexture(texture2DArray, tex);
}
Debugging this code I do see that both objects have the same texture format (RGBA32), and the length of the array from that Debug.Log state is correct so it appears to be loading the array correctly. What is the error actually complaining about if not texture format?
Share Improve this question edited Feb 21 at 12:56 derHugo 90.9k9 gold badges90 silver badges134 bronze badges asked Feb 20 at 18:16 CulyxCulyx 53910 silver badges18 bronze badges1 Answer
Reset to default 0As you are dealing with a Texture2DArray
I think it is not directly compatible with a plain Texture2D
using
Graphics.CopyTexture(texture2DArray, tex);
also what would your expected outcome be? It is the very same call for each iteration.
According to the API you would rather have to specify which exact element from the Texture2DArray
you want to copy from using e.g. (example snippet from the API without mipmap limits)
// Texture2DArray -> Texture2D // Global Mipmap Limit: "1: Half Resolution" => errors, since we try to copy into mips that are now too small for (int mip = 0; mip < outArray.mipmapCount; ++mip) { int copyWidth = width >> mip; int copyHeight = height >> mip; Graphics.CopyTexture(outArray, 0, mip, 0, 0, copyWidth, copyHeight, outTex, 0, mip, 0, 0); }
Now in your case where those are not mip levels but individual textures probably something like
Graphics.CopyTexture(outArray, 0, mip, 0, 0, texture2DArray.width, texture2DArray.height, tex, 0, 0, 0, 0);
本文标签: cGraphicsCopyTexture called with mismatching texture types (src5 dst2)Stack Overflow
版权声明:本文标题:c# - Graphics.CopyTexture called with mismatching texture types (src=5 dst=2) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741414464a2377429.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论