首页 > 解决方案 > 如何使用金属绘制压缩的 16 位像素格式纹理?

问题描述

我是金属新手,我设法绘制了简单的 32 位 rgba 纹理,但我找不到任何关于如何绘制 16 位纹理(5_5_5_1 bgra、5_6_5 bgr 或 4_4_4_4 bgra)的示例。

我认为纹理的创建是可以的:

textureDescriptor.pixelFormat = MTLPixelFormatB5G6R5Unorm;
bytesPerRow = 2*textureDescriptor.width;

我猜问题出在片段函数中:

fragment float4 fragmentShaderTexture(VertexTexTriangleOut in [[stage_in]],
                                 texture2d<ushort> colorTexture [[ texture(0) ]])
{



constexpr sampler textureSampler;

const ushort4 colorSample = colorTexture.sample(textureSampler, in.texCoords);

float4 colors = float4(colorSample);

return  colors;
}

标签: texturesmetalfragment-shader

解决方案


推荐阅读