MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / GetDXGIFormat

Function GetDXGIFormat

external/include/dds_header/DDSHeader.h:121–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119#define ISBITMASK(r, g, b, a) (ddpf.RBitMask == r && ddpf.GBitMask == g && ddpf.BBitMask == b && ddpf.ABitMask == a) // taken from DDSTextureLoader.cpp
120
121DXGI_FORMAT GetDXGIFormat(const DDS_PIXELFORMAT& ddpf)
122{
123 if (ddpf.flags & DDS_RGB)
124 {
125 // Note that sRGB formats are written using the "DX10" extended header.
126
127 switch (ddpf.RGBBitCount)
128 {
129 case 32:
130 if (ISBITMASK(0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000))
131 {
132 return DXGI_FORMAT_R8G8B8A8_UNORM;
133 }
134
135 if (ISBITMASK(0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000))
136 {
137 return DXGI_FORMAT_B8G8R8A8_UNORM;
138 }
139
140 if (ISBITMASK(0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000))
141 {
142 return DXGI_FORMAT_B8G8R8X8_UNORM;
143 }
144
145 // No DXGI format maps to ISBITMASK(0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000) aka D3DFMT_X8B8G8R8
146
147 // Note that many common DDS reader/writers (including D3DX) swap the
148 // the RED/BLUE masks for 10:10:10:2 formats. We assumme
149 // below that the 'backwards' header mask is being used since it is most
150 // likely written by D3DX. The more robust solution is to use the 'DX10'
151 // header extension and specify the DXGI_FORMAT_R10G10B10A2_UNORM format directly
152
153 // For 'correct' writers, this should be 0x000003ff, 0x000ffc00, 0x3ff00000 for RGB data
154 if (ISBITMASK(0x3ff00000, 0x000ffc00, 0x000003ff, 0xc0000000))
155 {
156 return DXGI_FORMAT_R10G10B10A2_UNORM;
157 }
158
159 // No DXGI format maps to ISBITMASK(0x000003ff, 0x000ffc00, 0x3ff00000, 0xc0000000) aka D3DFMT_A2R10G10B10
160
161 if (ISBITMASK(0x0000ffff, 0xffff0000, 0x00000000, 0x00000000))
162 {
163 return DXGI_FORMAT_R16G16_UNORM;
164 }
165
166 if (ISBITMASK(0xffffffff, 0x00000000, 0x00000000, 0x00000000))
167 {
168 // Only 32-bit color channel format in D3D9 was R32F.
169 return DXGI_FORMAT_R32_FLOAT; // D3DX writes this out as a FourCC of 114.
170 }
171 break;
172
173 case 24:
174 // No 24bpp DXGI formats aka D3DFMT_R8G8B8
175 break;
176
177 case 16:
178 if (ISBITMASK(0x7c00, 0x03e0, 0x001f, 0x8000))

Callers 1

readDDSHeaderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected