Add BC7 (BPTC) DDS texture support#2515
Open
juliendms wants to merge 1 commit into
Open
Conversation
Collaborator
|
I suppose we should decide about ai contributions. |
Author
|
I put this PR as draft because although "it works" the current implementation is kind of misleading.
TL;DR: PR blocked until #2483 is merged for clean implementation. |
Collaborator
Can't speak for anyone else, but reviewing AI output doesn't feel like a good use of my free time. |
BC7 DDS files use a DX10 FourCC followed by a 20-byte DXT10 extension header containing a dxgiFormat field. The previous parser only handled the legacy DXT1/DXT3/DXT5 FourCCs and rejected DX10 outright, which made BC7-encoded textures unusable even though the GPU upload path (glCompressedTexImage2D) needs no decompression on the CPU. Changes: - pixelformat.h: add PixelFormat::BC7 / BC7_sRGBA enums mapped to the GL_COMPRESSED_RGBA_BPTC_UNORM and GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM tokens. - image.cpp: BC7 has the same 4x4 / 16-byte block geometry as DXT5, so the format is added alongside DXT5 in formatComponents, calcMipLevelSize, isCompressed and hasAlpha. getLinearFormat maps BC7_sRGBA -> BC7. - texture.cpp: getInternalFormat / getExternalFormat handle BC7 in the desktop GL branch so the upload calls do not silently get GL_NONE. effectiveFormat() also strips BC7_sRGBA to BC7 when sRGB rendering is disabled, matching the treatment of the DXTn_sRGBA formats from PR CelestiaProject#2483 so a single sRGB-tagged corpus renders correctly in both modes. - dds.cpp: extend the DXGIFormat enum and GetDXT10Format() introduced by PR CelestiaProject#2483 to cover BC7_UNORM (98) and BC7_UNORM_SRGB (99). IsCompressedFormat covers BC7. BC7 has no software fallback, so LoadDDSImage refuses the file when GL_ARB_texture_compression_bptc is unavailable and the existing CPU decompressor is gated to s3tc formats only. - glsupport.{h,cpp}: probe GL_ARB_texture_compression_bptc, mirroring the existing s3tc flag. The CPU-side software decompressor (dds_decompress.cpp) is intentionally left untouched; BC7 software decoding is non-trivial (8 modes, partition tables, endpoint encodings) and is not needed when the GPU advertises BPTC, which any GL 4.2+ driver does.
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
BC7-encoded DDS files use the modern
DX10FourCC plus a 20-byteDDS_HEADER_DXT10extension containing adxgiFormatfield(98 =
BC7_UNORM, 99 =BC7_UNORM_SRGB). The current loader rejectsthis header, so BC7 textures cannot be loaded even though the upload
path (
glCompressedTexImage2DwithGL_COMPRESSED_RGBA_BPTC_UNORM)already works on any GL 4.2+ driver.
The patch:
DX10FourCC indds.cpp, reads the 20-byte extensionand decodes
dxgiFormat97/98/99 (BC7 typeless / UNORM / UNORM_SRGB);PixelFormat::BC7andPixelFormat::BC7_sRGBAmapped toGL_COMPRESSED_RGBA_BPTC_UNORM/GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;image.cpp(block size, components, alpha,compressed flag) and
texture.cpp(internal/external GL format) --block geometry is identical to DXT5, so the size math is verbatim;
GL_ARB_texture_compression_bptcinglsupport, mirroring theexisting
EXT_texture_compression_s3tcflag, and refuses BC7 fileswhen BPTC is unavailable rather than handing them to the s3tc software
fallback (which only knows DXT1/3/5).
The CPU-side software decompressor (
dds_decompress.cpp) is intentionallyleft untouched. BC7 software decoding is non-trivial (8 modes, partition
tables, endpoint encodings) and unnecessary on any modern GL driver.
Tested
Win32 build (VS 2026 / MSVC 19.50 / CMake 4.2), Windows 11, RX 6750 XT,
against several BC7-encoded planet textures (diffuse, specular, cloud,
night-side) up to 16384^2. Existing DXT1/3/5 loading paths verified
unchanged.
Out of scope
.ctxvirtual-texture tilesets --virtualtex.cpphas itsown DDS reader path that does not go through
LoadDDSImage. I plan on investigating CTX pipeline in the coming weeks.Screenshots
IO with all textures in 16k BC7

Earth cloud with 16k BC7
