- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我目前正在尝试在从文件加载后使用 SetData<> 在 Texture2D 对象上手动设置纹理数据。已在启用 MipMap 的情况下创建 Texture2D。数据已从使用 DXT1 压缩保存的 .dds 文件加载,大小为 512x512。
这是负责创建纹理并将数据加载到其中的代码。
texture = new Texture2D(graphics, (int)ddsHeader.Width, (int)ddsHeader.Height, mipMapCount > 1, sFormat);
for (int i = 0; i < (int)mipMapCount; i++)
{
int pow = (int)Math.Pow(2, i);
int width = (int)ddsHeader.Width / pow;
int height = (int)ddsHeader.Height / pow;
Rectangle? rect = null;
// get image size
int blockSize = GetBlockSize(width, height);
Console.WriteLine(string.Format("Width {0} Height {1}", width, height));
Console.WriteLine("Block size: " + blockSize + " " + (int)ddsHeader.PitchOrLinearSize);
// read the texture
byte[] textureData = reader.ReadBytes(blockSize);
rect = new Rectangle(0, 0, width, height);
// set the color into the appropriate level of the texture
if (sFormat == SurfaceFormat.Color && dxFormat == DXGIFormat.A8B8G8R8)
{
Color[] colors = ProcessUncompressedTexture(textureData, width, height);
texture.SetData<Color>(i, rect, colors, 0, width * height);
}
else
{
texture.SetData<byte>(i, rect, textureData, 0, blockSize);
}
}
它工作正常,数据被正确加载并正确设置到每个 mip 级别 - 直到它到达第 9 级别,它抛出以下内容:ArgumentException 未处理:传入的数据的大小太大或对于这个资源来说太小了。
这是输出。
Width 512 Height 512 // level 0
Block size: 262144 262144
Width 256 Height 256 // level 1
Block size: 65536 262144
Width 128 Height 128 // level 2
Block size: 16384 262144
Width 64 Height 64 // level 3
Block size: 4096 262144
Width 32 Height 32 // level 4
Block size: 1024 262144
Width 16 Height 16 // level 5
Block size: 256 262144
Width 8 Height 8 // level 6
Block size: 64 262144
Width 4 Height 4 // level 7
Block size: 16 262144
Width 2 Height 2 // level 8
Block size: 4 262144
现在,textureData 的计数为 4。此 mip 级别的宽度和高度为 2。矩形的大小也为 2 个单位。我看不出是什么导致了这个错误的发生,因为之前的 8 个级别都设置好了。
有谁知道这里可能发生了什么导致这种情况?
最佳答案
好吧,我想我已经找到了答案,而且有点道理。
本主题 here似乎表明 DXT 压缩 mipmap 的最小允许大小是 4x4 block 。这与我所看到的相符,因为上面的 DXT1 和 5 错误,但如果我切换到说 DXGIFormat.A8B8G8R8,它会下降到 1x1 mip-mapped 大小的 block 。
最小 4x4 block 大小的原因是 DXT 压缩算法将 block 压缩到最小 4x1。
无论如何,如果我使用的是 DXT 压缩纹理,我已经修改了我的代码以将要读取的 block 的大小调整为至少 4x4,并且它有效。
为了下一个遇到同样问题的人(无论他们是谁),这是我更新的 mipmap 集代码:
// create the texture
texture = new Texture2D(graphics, (int)ddsHeader.Width, (int)ddsHeader.Height, mipMapCount > 1, sFormat);
Console.WriteLine(texture.LevelCount);
for (int i = 0; i < (int)mipMapCount; i++)
{
int pow = (int)Math.Pow(2, i);
int width = (int)ddsHeader.Width / pow;
int height = (int)ddsHeader.Height / pow;
Rectangle? rect = new Rectangle(0, 0, width, height);
if (dxFormat == DXGIFormat.DXT1 || dxFormat == DXGIFormat.DXT5)
{
if (width < 4 && height < 4)
{
width = 4;
height = 4;
}
}
// get image size
int blockSize = GetBlockSize(width, height);
Console.WriteLine(string.Format("Width {0} Height {1} // level {2}", width, height, i));
Console.WriteLine("Block size: " + blockSize + " " + (int)ddsHeader.PitchOrLinearSize);
// read the texture
byte[] textureData = reader.ReadBytes(blockSize);
Console.WriteLine("Data size: " + textureData.Length);
// set the color into the appropriate level of the texture
if (sFormat == SurfaceFormat.Color && dxFormat == DXGIFormat.A8B8G8R8)
{
Color[] colors = ProcessUncompressedTexture(textureData, width, height);
texture.SetData<Color>(i, rect, colors, 0, width * height);
}
else
{
texture.SetData<byte>(i, rect, textureData, 0, blockSize);
}
}
我移动了矩形? rect = ...
调用,并将 DXT 小于 4x4 block 检测放在其下方。它不是最整洁的,但它确实有效。
关于c# - Texture2D SetData 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27560496/
我创建了一个类来保存我的模型信息。我必须正确渲染模型并正确包裹纹理,但出于某种原因,如果我有多个模型,它会将我的所有模型纹理化为仅 1 个纹理,如您在此图像中所见:http://imgur.com/d
是否有可能,如果有,如何在 OpenGL4.x 中的不同 channel 上创建和读取具有不同压缩算法的 RGBA 纹理: 没有实际意义的例子A: RG channel 存储以 3Dc 编码的法线贴图
我需要将浮点数据提供给计算着色器。 我看到的 3 种方法是: 着色器存储缓冲区对象 缓冲纹理 “经典”纹理(使用 PBO 将数据上传到 GPU,然后使用 glTexSubImage2D 将数据复制到纹
我会保持简单:本文末尾列出的代码在我的项目中按从上到下的顺序排列。我有一个 OGLES2.0 框架,可以完美渲染除纹理之外的所有内容。渲染单个纹理时,我看到的只是一个尺寸正确的黑盒子。 这是我已验证的
我在 Android 平台上编码。我正在尝试为三角形使用纹理(从 Assets 文件夹加载图像)。当我的应用程序运行时,它只是三角形中的空白白色(不是我想要的纹理)。 我读过一些其他资料,说图像必须是
我有道路的纹理。具有此纹理的线(由三角形条表示)如下所示: 当然,道路可以与其他道路重叠。在这种情况下,我想隐藏道路边界。道路边界具有 alpha 0.6,同时道路具有 alpha 1。那么当它们与具
我正在画一个到 webgl Canvas 上。我可以在 Chrome 和 Firefox 中使用它,但 IE11 似乎会抛出错误。错误指出: drawElements: The texture is
我想使用自定义着色器将纹理渲染到平面上。这个纹理有一个“偏移”属性集,当我使用标准的 threejs Material 时它可以正常工作。但是,我不知道如何在我的自定义片段着色器中访问这些偏移量。它只
导入项目后,Unity 中不断出现此错误。 这是代码: public static void CameraFadeSwap(Texture2D texture){ if(cameraFade)
这就是我在片段着色器中渲染画笔的方式: gl_FragColor.rgb = Color.rgb; gl_FragColor.a = Texture.a * Color.a; 在 (0, 0, 0,
我目前正在尝试在 Android 上开发视频播放器,但在颜色格式方面遇到困难。 上下文:我通过 MediaExtractor/MediaCodec 的标准组合提取和解码视频。因为我需要将提取的帧用作
在 Xcode 13 beta 中运行模拟器,我遇到了崩溃,我该怎么办? _validateTextureView:557: failed assertion `Texture View Valida
在我目前制作的游戏中,我有两个着色器: 一个用于纹理图集上的 Sprite 一个单独加载的粒子形状纹理。 (我决定将此纹理保留在图集之外,因为我的生成器中的粒子是 GL_POINTS)。 目前,我将其
我正在创建两个渲染目标,两者都必须共享后台缓冲区的深度缓冲区,因此我将它们设置为具有相同的多重采样参数很重要,但是 pDevice->CreateTexture(..) 没有给出任何参数设置多重采样类
如何在 POV-Ray 中创建一个看起来像地球的球体?据推测,答案将涉及获取某种地球 map 并以某种方式将其包裹在球体周围作为纹理。谷歌搜索让我找到了http://www.physics.sfasu
是否可以从 中的纹理读取顶点带 WebGL 的着色器? 我写了一个 WebGL page (只是为了尝试一下)并使用 Chrome 7 对其进行测试。一旦我升级到 Chrome 8,它就停止工作。我仔
我正在为一个模型的多个网格渲染不同的纹理,但是我对程序没有太多的了解。有人建议为每个网格创建自己的描述符集,并调用vkCmdBindDescriptorSets()和vkCmdDrawIndexed(
我有一个简单的 Vulkan 设置,它加载了一个相当大的网格文件(女性)并应用了漫反射和法线贴图纹理。 顶点着色器: #version 450 core layout (set = 0, bindin
Apple 现在在其许多产品中都使用了这种纹理: 仔细看看: 您可以看到它不仅仅是一堆线条:它具有随机性元素。一般来说,如何才能做到这一点?我对实现不像对概念那么感兴趣。我在网上看过,但找不到任何提示
我知道这是一个非常常见的问题。我收到无法从未定义中读取属性“纹理”的消息。抱歉,我对 javascript 还很陌生。 我的代码的javascript部分如下 this.createTexture=f
我是一名优秀的程序员,十分优秀!