DXGI_FORMAT_R10G10B10A2_UNORM DXGI_FORMAT_R8G8B8A8_UNORM 转换

不同unorm格式转换

// xxxxxxxx yyyyyyyy zzzzzzzz wwwwwwww DXGI_FORMAT_R8G8B8A8_UNORM 
// RRRRRRRR RRGGGGGG GGGGBBBB BBBBBBAA DXGI_FORMAT_R10G10B10A2_UNORM 
    int r = x << 2 | y >> 6;
    int g = (y & 0x3F) << 4 | z >> 4;
    int b = (z & 0xF) << 6 | w >> 2;
    int a = w & 0x3;

    pixelData[dataCounter++] = (byte)(r >> 2);
    pixelData[dataCounter++] = (byte)(g >> 2);
    pixelData[dataCounter++] = (byte)(b >> 2);
    pixelData[dataCounter++] = (byte)(a << 6);

所有这种类似的格式转换直接用移位就可以操作
同理其他格式的只要按照位数移动就可以了

你可能感兴趣的:(DirectX)