Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ktx2 compressed textures support #1254

Closed
wants to merge 87 commits into from

Conversation

lbergman
Copy link
Contributor

@lbergman lbergman commented Jan 7, 2025

Replaces #710

Support for parsing Ktx2 files with ETC or UASTC encoded textures, transcoding to BPTC, DXT, ETC2 or ASTC.

WIP since we are currently not using the res system and doing our own loading, so is not integrated with res system and only supports js target.

However we are working on a new framework where we would like to make use of res system and pak loading. I tried to implement async loading for compressed textures using the AsyncLoading flag, but could not make it work.
Will revisit this soon and try to solve the res integration, but leaving this up here for now if anyone has ideas or is interested in getting this working for native.

fix:  Flickering due to incorrect timing of clear https://github.com/…
…RenderContext

fix;  Making separate alpha handling configurable in h2d.RenderContex…
Enable high precision shaders if supported
@lbergman lbergman mentioned this pull request Jan 7, 2025
@@ -1409,12 +1428,13 @@ class GlDriver extends Driver {
case RGB10A2, RG11B10UF: new Uint32Array(@:privateAccess pixels.bytes.b.buffer, pixels.offset, dataLen>>2);
default: new Uint8Array(@:privateAccess pixels.bytes.b.buffer, pixels.offset, dataLen);
}
if( t.format.match(S3TC(_)) ) {
switch (t.format) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use match(S3TC()|STC()|ETC(_)) instead ?

S3TC( v : Int );
ASTC( ?v : Int );
ETC( ?v : Int );
S3TC( ?v : Int );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is v optional ? it shouldn't be for S3TC


enum abstract ASTC_FORMAT(Int) from Int to Int {
final RGBA_4x4 = 0x93B0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constants are for GL and should not be in PixelFormat

hxd/Pixels.hx Outdated
case S3TC(n):
var w = ((width + 3) >> 2) << 2; // Round up width to next multiple of 4
var h = ((height + 3) >> 2) << 2; // Round up height to next multiple of 4
var blocks = (w >> 2) * (h >> 2); // Total number of blocks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified without <<2 and blocks = w*h (same for other formats)

@@ -32,7 +32,7 @@ class BinaryLoader {
onError(xhr.statusText);
return;
}
onLoaded(haxe.io.Bytes.ofData(xhr.response));
onLoaded(raw ? xhr.response : haxe.io.Bytes.ofData(xhr.response));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated to the PR. Please submit separately

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used by Ktx2Decoder.initTranscoder when loading the wasm module.

hxd/res/Image.hx Outdated
getInfo();
return h2d.Tile.fromTexture(toTexture()).sub(0, 0, inf.width, inf.height);
final tex = toTexture();
return h2d.Tile.fromTexture(tex).sub(0, 0, tex.width, tex.height);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated to the PR. Please submit separately

@ncannasse
Copy link
Member

Also I'm a bit curious whereas the support for it is widely spread enough

chore: Make format type value required for ASTC, ETC and S3TC
chore: Simplify compressed texture data size calculations
@lbergman
Copy link
Contributor Author

lbergman commented Jan 7, 2025

All resolved.

If you mean support on devices, it will transcode to either BPTC, DXT, ETC2 or ASTC, which should cover pretty much all desktop and mobile. There is a CLI transcoder that could be used instead of the wasm module to enable support on native targets.

I removed support for PVRTC since that is only needed for iOS devices with pre A7 chip, so older than 2013, and could not even find a device to test on, and it has limitations.

@lbergman
Copy link
Contributor Author

Made a new PR from a fresh fork to get rid of the messy history. #1260

@lbergman lbergman closed this Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants