Skip to content

Add KTX1 texture container support with spec-compliant reader#776

Draft
Copilot wants to merge 4 commits intocore4from
copilot/support-ktx-texture-container
Draft

Add KTX1 texture container support with spec-compliant reader#776
Copilot wants to merge 4 commits intocore4from
copilot/support-ktx-texture-container

Conversation

Copy link
Contributor

Copilot AI commented Feb 13, 2026

Adds KTX1 (Khronos Texture) read support to CBitmap, enabling .ktx files with compressed and uncompressed pixel data.

New file: bitmap_ktx.cpp

  • Compressed formats: DXTC1, DXTC1Alpha, DXTC3, DXTC5 (ETC1 recognized but unsupported by bitmap loader)
  • Uncompressed formats: RGBA, RGB→RGBA expansion, Luminance, Alpha, LuminanceAlpha
  • Mipmap chain loading with mipMapSkip support matching DDS behavior

Spec compliance details

  • Endianness: Uses raw serialBuffer() reads instead of IStream::serial() to avoid conflicting with KTX's own endianness mechanism — serial() does platform byte-swapping on big-endian systems which would double-swap when combined with KTX's endianness field
  • Row alignment: Accounts for GL_UNPACK_ALIGNMENT=4 row padding per spec — rows are padded to 4-byte boundaries, stripped during load
  • 1D textures: pixelHeight == 0 treated as height 1 per spec
  • Endianness validation: Rejects files where the endianness field is neither 0x04030201 nor 0x01020304
// Raw read avoids IStream::serial() byte-swapping on big-endian platforms
static void ktxReadRaw32(NLMISC::IStream &f, uint32 &val)
{
    f.serialBuffer((uint8 *)&val, 4);
}

Integration points

  • bitmap.h: KTX_HEADER constant, readKTX() declaration
  • bitmap.cpp: KTX dispatch in load() and loadSize()
  • CMake: Picked up automatically by existing bitmap_*.cpp glob
Original prompt

This section details on the original issue you should resolve

<issue_title>Support .ktx texture container</issue_title>
<issue_description>Currently only .dds is supported, supporting .ktx container, which supports more codecs, may help towards mobile and modern GPU support.</issue_description>

Comments on the Issue (you are @copilot in this section)

@kaetemi KTX1 https://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec/ KTX2 http://github.khronos.org/KTX-Specification/

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 13, 2026 23:20
…essed textures

Co-authored-by: kaetemi <1581053+kaetemi@users.noreply.github.com>
Co-authored-by: kaetemi <1581053+kaetemi@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for .ktx texture container Support KTX1 texture container format Feb 13, 2026
Copilot AI requested a review from kaetemi February 13, 2026 23:24
…es, row alignment

Co-authored-by: kaetemi <1581053+kaetemi@users.noreply.github.com>
Copilot AI changed the title Support KTX1 texture container format Add KTX1 texture container support with spec-compliant reader Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Support .ktx texture container

2 participants