• Create Account

### #ActualMJP

Posted 14 October 2012 - 12:25 AM

For any DXGI format, the byte order is the order of the components in the format name. So for R8G8B8A8, R should be the first (lowest) byte and A should be the last (highest) byte. Endianness really doesn't have anything to do with it in this particular case, since the order is explicit and each component is the one byte in size. The reason why you're not getting the right result is because the DWORD casting operator for D3DXCOLOR is defined like this:

D3DXCOLOR::operator DWORD () const
{
DWORD dwR = r >= 1.0f ? 0xff : r <= 0.0f ? 0x00 : (DWORD) (r * 255.0f + 0.5f);
DWORD dwG = g >= 1.0f ? 0xff : g <= 0.0f ? 0x00 : (DWORD) (g * 255.0f + 0.5f);
DWORD dwB = b >= 1.0f ? 0xff : b <= 0.0f ? 0x00 : (DWORD) (b * 255.0f + 0.5f);
DWORD dwA = a >= 1.0f ? 0xff : a <= 0.0f ? 0x00 : (DWORD) (a * 255.0f + 0.5f);
return (dwA << 24) | (dwR << 16) | (dwG << 8) | dwB;
}


So as you can see the result you get is in BGRA order and not RGBA order, so it would be appropriate for DXGI_FORMAT_B8G8R8A8_UNORM. If you swap B and R you should get the results you want. Or you can just make your own function.

Another alternative is to ditch D3DX math altogether in favor of DirectXMath. DirectXMath has conversions for all kinds of DXGI formats, which are listed here. In your case you'd want to us XMUBYTEN4, and use x=R, y=G, z=B,w=A.

### #3MJP

Posted 14 October 2012 - 12:24 AM

For any DXGI format, the byte order is the order of the components in the format name. So for R8G8B8A8, R should be the first (lowest) byte and A should be the last (highest) byte. Endianness really doesn't have anything to do with it in this particular case, since the order is explicit and each component is the one byte in size. The reason why you're getting the right results is because the DWORD casting operator for D3DXCOLOR is defined like this:

D3DXCOLOR::operator DWORD () const
{
DWORD dwR = r >= 1.0f ? 0xff : r <= 0.0f ? 0x00 : (DWORD) (r * 255.0f + 0.5f);
DWORD dwG = g >= 1.0f ? 0xff : g <= 0.0f ? 0x00 : (DWORD) (g * 255.0f + 0.5f);
DWORD dwB = b >= 1.0f ? 0xff : b <= 0.0f ? 0x00 : (DWORD) (b * 255.0f + 0.5f);
DWORD dwA = a >= 1.0f ? 0xff : a <= 0.0f ? 0x00 : (DWORD) (a * 255.0f + 0.5f);
return (dwA << 24) | (dwR << 16) | (dwG << 8) | dwB;
}


So as you can see the result you get is in BGRA order and not RGBA order, so it would be appropriate for DXGI_FORMAT_B8G8R8A8_UNORM. If you swap B and R you should get the results you want. Or you can just make your own function.

Another alternative is to ditch D3DX math altogether in favor of DirectXMath. DirectXMath has conversions for all kinds of DXGI formats, which are listed here. In your case you'd want to us XMUBYTEN4, and use x=R, y=G, z=B,w=A.

### #2MJP

Posted 14 October 2012 - 12:23 AM

For any DXGI format, the byte order is the order of the components in the format name. So for R8G8B8A8, R should be the first (lowest) byte and A should be the last (highest) byte. Endianness really doesn't have anything to do with it in this particular case, since the order is explicit and each component is the one byte in size. The reason why you're getting the right results is because the DWORD casting operator for D3DXCOLOR is defined like this:

D3DXCOLOR::operator DWORD () const
{
DWORD dwR = r >= 1.0f ? 0xff : r <= 0.0f ? 0x00 : (DWORD) (r * 255.0f + 0.5f);
DWORD dwG = g >= 1.0f ? 0xff : g <= 0.0f ? 0x00 : (DWORD) (g * 255.0f + 0.5f);
DWORD dwB = b >= 1.0f ? 0xff : b <= 0.0f ? 0x00 : (DWORD) (b * 255.0f + 0.5f);
DWORD dwA = a >= 1.0f ? 0xff : a <= 0.0f ? 0x00 : (DWORD) (a * 255.0f + 0.5f);
return (dwA << 24) | (dwR << 16) | (dwG << 8) | dwB;
}


So as you can see the result you get is in BGRA order and not RGBA order, so it would be appropriate for DXGI_FORMAT_B8G8R8A8_UNORM. If you swap B and R you should get the results you want. Or you can just make your own function.

Another alternative is to ditch D3DX math altogether in favor of DirectXMath. DirectXMath has conversions for all kinds of DXGI formats, which are listed here.

### #1MJP

Posted 14 October 2012 - 12:23 AM

For any DXGI format, the byte order is the order of the components in the format name. So for R8G8B8A8, R should be the first (lowest) byte and A should be the last (highest) byte. Endianness really doesn't have anything to do with it in this particular case, since the order is explicit and each component is the one byte in size. The reason why you're getting the right results is because the DWORD casting operator for D3DXCOLOR is defined like this:

D3DXCOLOR::operator DWORD () const
{
DWORD dwR = r >= 1.0f ? 0xff : r <= 0.0f ? 0x00 : (DWORD) (r * 255.0f + 0.5f);
DWORD dwG = g >= 1.0f ? 0xff : g <= 0.0f ? 0x00 : (DWORD) (g * 255.0f + 0.5f);
DWORD dwB = b >= 1.0f ? 0xff : b <= 0.0f ? 0x00 : (DWORD) (b * 255.0f + 0.5f);
DWORD dwA = a >= 1.0f ? 0xff : a <= 0.0f ? 0x00 : (DWORD) (a * 255.0f + 0.5f);
return (dwA << 24) | (dwR << 16) | (dwG << 8) | dwB;
}


So as you can see the result you get is in BGRA order and not RGBA order, so it would be appropriate for DXGI_FORMAT_B8G8R8A8_UNORM. If you swap B and R you should get the results you want. Or you can just make your own function, if you want.

Another alternative is to ditch D3DX math altogether in favor of DirectXMath. DirectXMath has conversions for all kinds of DXGI formats, which are listed here.

PARTNERS