| 995 | } |
| 996 | |
| 997 | inline void encode_header(const DXGIFormat dxgiFormat, const unsigned int width, const unsigned int height, const unsigned int depth, |
| 998 | const TextureType type, const unsigned int mipCount, const unsigned int arraySize, |
| 999 | Header& header, HeaderDXT10& dxt10Header) |
| 1000 | { |
| 1001 | header.size = sizeof(Header); |
| 1002 | |
| 1003 | // Fill in header flags |
| 1004 | header.flags = DDS_HEADER_FLAGS_CAPS | DDS_HEADER_FLAGS_HEIGHT | DDS_HEADER_FLAGS_WIDTH | DDS_HEADER_FLAGS_PIXELFORMAT; |
| 1005 | header.caps = DDS_HEADER_CAPS_TEXTURE; |
| 1006 | header.caps2 = 0; |
| 1007 | |
| 1008 | if (mipCount > 1) |
| 1009 | { |
| 1010 | header.flags |= DDS_HEADER_FLAGS_MIPMAP; |
| 1011 | header.caps |= DDS_HEADER_CAPS_COMPLEX | DDS_HEADER_CAPS_MIPMAP; |
| 1012 | } |
| 1013 | |
| 1014 | unsigned int bitsPerPixelOrBlock = get_bits_per_pixel_or_block(dxgiFormat); |
| 1015 | |
| 1016 | if (is_compressed(dxgiFormat)) |
| 1017 | { |
| 1018 | header.flags |= DDS_HEADER_FLAGS_LINEARSIZE; |
| 1019 | unsigned int blockWidth, blockHeight; |
| 1020 | get_block_size(dxgiFormat, blockWidth, blockHeight); |
| 1021 | header.pitchOrLinearSize = width * height * bitsPerPixelOrBlock / (8 * blockWidth * blockHeight); |
| 1022 | } |
| 1023 | else |
| 1024 | { |
| 1025 | header.flags |= DDS_HEADER_FLAGS_PITCH; |
| 1026 | header.pitchOrLinearSize = width * bitsPerPixelOrBlock / 8; |
| 1027 | } |
| 1028 | |
| 1029 | header.height = height; |
| 1030 | header.width = width; |
| 1031 | header.depth = depth; |
| 1032 | header.mipMapCount = mipCount; |
| 1033 | header.reserved1[0] = header.reserved1[1] = header.reserved1[2] = 0; |
| 1034 | header.reserved1[3] = header.reserved1[4] = header.reserved1[5] = 0; |
| 1035 | header.reserved1[6] = header.reserved1[7] = header.reserved1[8] = 0; |
| 1036 | header.reserved1[9] = header.reserved1[10] = 0; |
| 1037 | |
| 1038 | // Fill in pixel format |
| 1039 | PixelFormat& ddspf = header.ddspf; |
| 1040 | ddspf.size = sizeof(PixelFormat); |
| 1041 | ddspf.fourCC = FOURCC_DXT10; |
| 1042 | ddspf.flags = 0; |
| 1043 | ddspf.flags |= DDS_FOURCC; |
| 1044 | |
| 1045 | dxt10Header.dxgiFormat = dxgiFormat; |
| 1046 | dxt10Header.arraySize = arraySize; |
| 1047 | dxt10Header.miscFlag = 0; |
| 1048 | |
| 1049 | if (type == Texture1D) |
| 1050 | { |
| 1051 | dxt10Header.resourceDimension = DXGI_Texture1D; |
| 1052 | } |
| 1053 | else if (type == Texture2D) |
| 1054 | { |
nothing calls this directly
no test coverage detected