Skip to main content
GameDev.net gamedev.net
🔒 Locked

input layouts

Started by Quat Sep 7, 2010 at 10:37 PM 2 replies 2.6k views
Original Post
Quat
Quat
I have the following vertex structure:

struct Vertex
{
XMFLOAT3 Pos;
XMCOLOR Color;
};

XMCOLOR is just a UINT ARGB [32] aaaaaaaa rrrrrrrr gggggggg bbbbbbbb [0].

I define

D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}
};

However, the colors are not coming out right. But if I use

DXGI_FORMAT_B8G8R8A8_UNORM

then it works correctly. Anyone know why?
-----Quat
MJP
MJP
DXGI_FORMAT_R8G8B8A8_UNORM means that the bytes must be in ABGR format in your vertex, while DXGI_FORMAT_B8G8R8A8_UNORM means it must be in ARGB format. XMCOLOR uses ARGB order.
Quat
Quat
Quote:

DXGI_FORMAT_R8G8B8A8_UNORM means that the bytes must be in ABGR format in your vertex, while DXGI_FORMAT_B8G8R8A8_UNORM means it must be in ARGB format. XMCOLOR uses ARGB order.


How come it works backwards like that? Is it documented somewhere?
-----Quat
Demirug
Demirug
Quote:
Original post by Quat
Quote:

DXGI_FORMAT_R8G8B8A8_UNORM means that the bytes must be in ABGR format in your vertex, while DXGI_FORMAT_B8G8R8A8_UNORM means it must be in ARGB format. XMCOLOR uses ARGB order.


How come it works backwards like that? Is it documented somewhere?


It’s not really backwards. Direct10D and up assume that your Vertex elements are stored as structs or arrays. If you store four bytes as dword instead you are hit by the little endian that x86 is used. This caused the swap.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.