* Copy a compressed BC7 texture into our format, aligned for GPU use. */
| 145 | * Copy a compressed BC7 texture into our format, aligned for GPU use. |
| 146 | */ |
| 147 | bool FormatCompressedTexture(ScratchImage& src, Texture& dst) |
| 148 | { |
| 149 | // Get the texture's metadata |
| 150 | const TexMetadata metadata = src.GetMetadata(); |
| 151 | |
| 152 | // Check if the texture's format is supported |
| 153 | if (metadata.format != DXGI_FORMAT_BC7_UNORM && metadata.format != DXGI_FORMAT_BC7_UNORM_SRGB && metadata.format != DXGI_FORMAT_BC7_TYPELESS) |
| 154 | { |
| 155 | std::string msg = "Error: unsupported compressed texture format for: \'" + dst.name + "\' \'" + dst.filepath + "\'\n. Compressed textures must be in BC7 format"; |
| 156 | MessageBox(NULL, std::wstring(msg.begin(), msg.end()).c_str(), L"Error", MB_OK); |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | // Delete existing texels |
| 161 | UnloadTexture(dst); |
| 162 | |
| 163 | // Copy each mip level to the texel array |
| 164 | for (UINT mipIndex = 0; mipIndex < static_cast<UINT>(metadata.mipLevels); mipIndex++) |
| 165 | { |
| 166 | const Image* image = src.GetImage(mipIndex, 0, 0); |
| 167 | |
| 168 | TextureData mipData; |
| 169 | mipData.width = image->width; |
| 170 | mipData.height = image->height; |
| 171 | mipData.texelBytes = image->slicePitch; |
| 172 | mipData.stride = 4; |
| 173 | mipData.rowPitch = image->rowPitch; |
| 174 | |
| 175 | // Copy texel data |
| 176 | mipData.texels = new UINT8[mipData.texelBytes]; |
| 177 | memcpy(mipData.texels, image->pixels, image->slicePitch); |
| 178 | |
| 179 | dst.mips.push_back(mipData); |
| 180 | } |
| 181 | |
| 182 | src.Release(); |
| 183 | return true; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Covert a R8G8B8A8_UNORM texture to BC7 format and generate mips. |
no test coverage detected