Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
6 changes: 2 additions & 4 deletions haxelib.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
"url": "http://heaps.io",
"license": "BSD",
"description": "The GPU Game Framework",
"version": "2.1.8",
"version": "2.1.11",
"releasenote": "See CHANGELOG.md",
"contributors": [
"ncannasse"
],
"dependencies": {
"format": ""
}

}

}
136 changes: 78 additions & 58 deletions hxd/res/Image.hx
Original file line number Diff line number Diff line change
Expand Up @@ -257,23 +257,26 @@ class Image extends Resource {
#if js
case 0x4273:
throw 'Use .ktx2 files for GPU compressed textures instead of .basis';
case 0x4BAB:
final ktx2 = hxd.res.Ktx2.readFile(new haxe.io.BytesInput(@:privateAccess f.cache));
final basisFormat = switch ktx2.dfd.colorModel {
case hxd.res.Ktx2.DFDModel.ETC1S: BasisFormat.ETC1S;
case hxd.res.Ktx2.DFDModel.UASTC: BasisFormat.UASTC;
default: throw 'Unsupported colorModel in ktx2 file: ${ktx2.dfd.colorModel}';
}
final formatInfo = hxd.res.Ktx2.Ktx2Decoder.getTranscoderFormat(basisFormat, ktx2.header.pixelWidth, ktx2.header.pixelHeight, ktx2.dfd.hasAlpha());
inf.pixelFormat = switch formatInfo.transcoderFormat {
case TranscoderFormat.ASTC_4x4: hxd.PixelFormat.ASTC(10);
case TranscoderFormat.BC7_M5: hxd.PixelFormat.S3TC(7);
case TranscoderFormat.BC3: hxd.PixelFormat.S3TC(3);
case TranscoderFormat.ETC1: hxd.PixelFormat.ETC(0);
case TranscoderFormat.ETC2: hxd.PixelFormat.ETC(1);
default:
throw 'Unsupported transcoder format: ${formatInfo.transcoderFormat}';
}
case 0x4BAB:
final ktx2 = hxd.res.Ktx2.readFile(new haxe.io.BytesInput(@:privateAccess f.cache));
final basisFormat = switch ktx2.dfd.colorModel {
case hxd.res.Ktx2.DFDModel.ETC1S: BasisFormat.ETC1S;
case hxd.res.Ktx2.DFDModel.UASTC: BasisFormat.UASTC;
default: throw 'Unsupported colorModel in ktx2 file: ${ktx2.dfd.colorModel}';
}
final formatInfo = hxd.res.Ktx2.Ktx2Decoder.getTranscoderFormat(basisFormat, ktx2.header.pixelWidth, ktx2.header.pixelHeight, ktx2.dfd.hasAlpha());
inf.pixelFormat = switch formatInfo.transcoderFormat {
case TranscoderFormat.ASTC_4x4: hxd.PixelFormat.ASTC(10);
case TranscoderFormat.BC7_M5: hxd.PixelFormat.S3TC(7);
case TranscoderFormat.BC1: hxd.PixelFormat.S3TC(1);
case TranscoderFormat.BC3: hxd.PixelFormat.S3TC(3);
case TranscoderFormat.ETC1: hxd.PixelFormat.ETC(0);
case TranscoderFormat.ETC2: hxd.PixelFormat.ETC(1);
case TranscoderFormat.RGBA32: hxd.PixelFormat.RGBA;
case TranscoderFormat.RGBA_HALF: hxd.PixelFormat.RGBA16F;
default:
throw 'Unsupported transcoder format: ${formatInfo.transcoderFormat}';
}
inf.mipLevels = ktx2.header.levelCount;
inf.width = ktx2.header.pixelWidth;
inf.height = ktx2.header.pixelHeight;
Expand Down Expand Up @@ -552,9 +555,9 @@ class Image extends Resource {
return bmp;
}

function watchCallb() {
var prevInfo = inf;
inf = null;
function watchCallb() {
var prevInfo = inf;
inf = null;
try {
getInfo();
} catch ( e : Dynamic ) {
Expand All @@ -564,9 +567,34 @@ class Image extends Resource {
var s = getSize();
if (prevInfo.width != s.width || prevInfo.height != s.height)
tex.resize(s.width, s.height);
tex.realloc = null;
loadTexture();
}
tex.realloc = null;
loadTexture();
}

function resolveTextureWaitLoads() {
@:privateAccess if (tex.waitLoads != null) {
var arr = tex.waitLoads;
tex.waitLoads = null;
for (f in arr)
f();
}
}

static function pixelFormatFromKtx2Face(faceFormat:Int, faceType:Int):hxd.PixelFormat {
return switch faceFormat {
case hxd.CompressedTextureFormat.BPTC_FORMAT.RGBA_BPTC: hxd.PixelFormat.S3TC(7);
case hxd.CompressedTextureFormat.ASTC_FORMAT.RGBA_4x4: hxd.PixelFormat.ASTC(10);
case hxd.CompressedTextureFormat.DXT_FORMAT.RGB_DXT1, hxd.CompressedTextureFormat.DXT_FORMAT.RGBA_DXT1: hxd.PixelFormat.S3TC(1);
case hxd.CompressedTextureFormat.DXT_FORMAT.RGBA_DXT3: hxd.PixelFormat.S3TC(2);
case hxd.CompressedTextureFormat.DXT_FORMAT.RGBA_DXT5: hxd.PixelFormat.S3TC(3);
case hxd.CompressedTextureFormat.ETC_FORMAT.RGB_ETC1: hxd.PixelFormat.ETC(0);
case hxd.CompressedTextureFormat.ETC_FORMAT.RGBA_ETC2: hxd.PixelFormat.ETC(1);
case hxd.res.Ktx2.EngineFormat.RGBAFormat:
faceType == hxd.res.Ktx2.EngineType.HalfFloatType ? hxd.PixelFormat.RGBA16F : hxd.PixelFormat.RGBA;
default:
throw 'No compressed texture format found for ${StringTools.hex(faceFormat)}';
}
}

static var BLACK_1x1 = Pixels.alloc(1, 1, RGBA);
public static var ASYNC_LOADER:hxd.impl.AsyncLoader;
Expand Down Expand Up @@ -605,19 +633,14 @@ class Image extends Resource {
if (getFormat().useLoadBitmap) {
// use native decoding
tex.flags.set(Loading);
entry.loadBitmap(function(bmp) {
var bmp = bmp.toBitmap();
tex.alloc();
tex.uploadBitmap(bmp);
bmp.dispose();
tex.realloc = () -> loadTexture();
tex.flags.unset(Loading);
@:privateAccess if (tex.waitLoads != null) {
var arr = tex.waitLoads;
tex.waitLoads = null;
for (f in arr)
f();
}
entry.loadBitmap(function(bmp) {
var bmp = bmp.toBitmap();
tex.alloc();
tex.uploadBitmap(bmp);
bmp.dispose();
tex.realloc = () -> loadTexture();
tex.flags.unset(Loading);
resolveTextureWaitLoads();

if (ENABLE_AUTO_WATCH && !watchRegistered) {
watchRegistered = true;
Expand Down Expand Up @@ -681,22 +704,18 @@ class Image extends Resource {
pos += size;
}
}
case Ktx2ETC1S, Ktx2UASTC:
for (layer in 0...asyncMessage.faces.length) {
final face = asyncMessage.faces[layer];
for (mip in 0...face.mipmaps.length) {
final w = inf.width >> mip;
final h = inf.height >> mip;
inf.pixelFormat = switch face.format {
case hxd.CompressedTextureFormat.BPTC_FORMAT.RGBA_BPTC: hxd.PixelFormat.S3TC(7);
case hxd.CompressedTextureFormat.ASTC_FORMAT.RGBA_4x4: hxd.PixelFormat.ASTC(10);
default: throw 'No compressed texture format found for ${StringTools.hex(face.format)}';
}
final pixels = new hxd.Pixels(w, h, haxe.io.Bytes.ofData(face.mipmaps[mip].data.buffer), inf.pixelFormat, 0);
tex.uploadPixels(pixels, mip, layer);
pixels.dispose();
}
}
case Ktx2ETC1S, Ktx2UASTC:
for (layer in 0...asyncMessage.faces.length) {
final face = asyncMessage.faces[layer];
for (mip in 0...face.mipmaps.length) {
final w = hxd.Math.imax(1, inf.width >> mip);
final h = hxd.Math.imax(1, inf.height >> mip);
inf.pixelFormat = pixelFormatFromKtx2Face(face.format, face.type);
final pixels = new hxd.Pixels(w, h, haxe.io.Bytes.ofData(face.mipmaps[mip].data.buffer), inf.pixelFormat, 0);
tex.uploadPixels(pixels, mip, layer);
pixels.dispose();
}
}
default:
for (layer in 0...tex.layerCount) {
for (mip in 0...inf.mipLevels) {
Expand All @@ -712,12 +731,13 @@ class Image extends Resource {
#if hl Sys.println #else trace #end (fmtStr + " " + Std.int(time) + "." + (Std.int(time * 10) % 10) + "ms " + inf.width + "x" + inf.height
+ " " + entry.path);
}
tex.realloc = () -> loadTexture();
if (ENABLE_AUTO_WATCH && !watchRegistered) {
watchRegistered = true;
watch(watchCallb);
}
}
tex.realloc = () -> loadTexture();
if (ENABLE_AUTO_WATCH && !watchRegistered) {
watchRegistered = true;
watch(watchCallb);
}
resolveTextureWaitLoads();
}
if (entry.isAvailable)
load();
else
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"name": "@hacksawstudios/heaps",
"version": "2.1.8",
"version": "2.1.11",
"description": "_High Performance Game Framework_",
"main": "index.js",
"devDependencies": {
"@hacksawstudios/haxe-module-installer": "1.2.12",
"fs-extra": "11.2.0"
"@hacksawstudios/haxe-module-installer": "1.2.12"
},
"scripts": {
"postinstall": "npx @hacksawstudios/haxe-module-installer",
Expand Down
Loading