Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f22e506
Adding SDF Metadata for Littera XML Format
Aug 27, 2024
7b42819
feat: Support ktx2 compressed textures
lbergman Jan 15, 2025
0eba08b
Merge pull request #1 from HacksawStudios/ktx2
lbergman Jan 15, 2025
5419565
style: Formatting fix
lbergman Jan 15, 2025
ba459cd
feat: Adding SDF Metadata for Littera XML Format
lbergman Jan 15, 2025
8c9a4a4
Merge pull request #2 from HacksawStudios/font_distance_range
lbergman Jan 15, 2025
05000f1
chore: Add misc files for publishing to npm
lbergman Jan 15, 2025
36b384b
feat: Ktx2 support
lbergman Jan 15, 2025
544efdd
Merge pull request #3 from HacksawStudios/ktx2
lbergman Jan 15, 2025
eaa0dc3
Merge branch 'HeapsIO:master' into master
lbergman Jan 15, 2025
f85493d
Merge branch 'HeapsIO:master' into master
lbergman Jan 17, 2025
9d5d2a6
feat: Add json sdf font parser
Jan 17, 2025
036e2eb
feat: Introduce FragDepth global for glsl and hlsl
Jan 17, 2025
0d722c7
chore: Update codestyle
Jan 17, 2025
6c0f696
chore: Restore Cache
Jan 17, 2025
ac24f56
fix: Remove some revert changes and apply special case for fragdepth
Jan 18, 2025
9ec179a
fix: Restore broken code
Jan 18, 2025
abc4d10
fix: More code reversion
Jan 18, 2025
95dfcff
Prevent linker from opt out fragDepth
Jan 21, 2025
2100889
Restore cache file
Jan 21, 2025
7183470
another restore
Jan 21, 2025
c2336ef
and another restore
Jan 21, 2025
7d9b83a
Adding read dependency
Jan 23, 2025
48ea6e0
DCE for fragdepth
Jan 28, 2025
f3a85f7
Handle write only
Jan 28, 2025
e55cdcc
code cleanup
Jan 28, 2025
f736aa8
fix: Avoid conditionals in shader
lbergman Feb 3, 2025
b3fb037
Remove DX try for FragDepth
Feb 6, 2025
d6adb4b
Merge pull request #4 from lusius/FragDepth
lbergman Feb 6, 2025
02a3e48
Merge pull request #5 from lusius/JsonFontParser
lbergman Feb 6, 2025
40ca6fd
Merge branch 'master' into addSdfMetaData
lbergman Feb 6, 2025
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
32 changes: 0 additions & 32 deletions .github/workflows/sync_wiki.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ bin
.vscode
/tools/meshtools/out
*.exe
/node_modules
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
registry=https://hacksawgaming-281033247142.d.codeartifact.eu-west-1.amazonaws.com/npm/hacksaw-client-artifacts/
//hacksawgaming-281033247142.d.codeartifact.eu-west-1.amazonaws.com/npm/hacksaw-client-artifacts/:always-auth=true
//hacksawgaming-281033247142.d.codeartifact.eu-west-1.amazonaws.com/npm/hacksaw-client-artifacts/:_authToken=${CODEARTIFACT_AUTH_TOKEN}
Binary file added bun.lockb
Binary file not shown.
8 changes: 8 additions & 0 deletions h2d/Font.hx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ class Font {
Defaults to `hxd.Charset.getDefault()`.
**/
public var charset : hxd.Charset;
/**
Distance range used to generate SDF Font and useful for some implementations of SDF Font rendering.
**/
public var distanceRange:Int;
/**
SDF Field type used when generating.
**/
public var fieldType:String;
var glyphs : Map<Int,FontChar>;
var nullChar : FontChar;
var defaultChar : FontChar;
Expand Down
64 changes: 53 additions & 11 deletions h3d/impl/GlDriver.hx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@ class GlDriver extends Driver {
static var UID = 0;
public var gl : GL;
public static var ALLOW_WEBGL2 = true;

public var textureSupport:{
astc:Bool,
astcHDR:Bool,
etc1:Bool,
etc2:Bool,
dxt:Bool,
bptc:Bool,
};
#end

#if (hlsdl||usegl)
Expand Down Expand Up @@ -992,9 +1001,9 @@ class GlDriver extends Driver {
case GL.RGB10_A2: GL.RGBA;
case GL.RED, GL.R8, GL.R16F, GL.R32F, 0x822A: GL.RED;
case GL.RG, GL.RG8, GL.RG16F, GL.RG32F, 0x822C: GL.RG;
case GL.RGB16F, GL.RGB32F, 0x8054, 0x8E8F: GL.RGB;
case 0x83F1, 0x83F2, 0x83F3, 0x805B, 0x8E8C: GL.RGBA;
default: throw "Invalid format " + t.internalFmt;
case GL.RGB16F, GL.RGB32F, 0x8054, hxd.CompressedTextureFormat.BPTC_FORMAT.RGB_BPTC_UNSIGNED, hxd.CompressedTextureFormat.ETC_FORMAT.RGB_ETC1: GL.RGB;
case 0x805B, hxd.CompressedTextureFormat.DXT_FORMAT.RGBA_DXT1,hxd.CompressedTextureFormat.DXT_FORMAT.RGBA_DXT3,
hxd.CompressedTextureFormat.DXT_FORMAT.RGBA_DXT5,hxd.CompressedTextureFormat.ASTC_FORMAT.RGBA_4x4, hxd.CompressedTextureFormat.BPTC_FORMAT.RGBA_BPTC : GL.RGBA; default: throw "Invalid format " + t.internalFmt;
}
}

Expand Down Expand Up @@ -1083,8 +1092,7 @@ class GlDriver extends Driver {
tt.internalFmt = GL.R11F_G11F_B10F;
tt.pixelFmt = GL.UNSIGNED_INT_10F_11F_11F_REV;
case S3TC(n) if( n <= maxCompressedTexturesSupport ):
if( t.width&3 != 0 || t.height&3 != 0 )
throw "Compressed texture "+t+" has size "+t.width+"x"+t.height+" - must be a multiple of 4";
checkMult4(t);
switch( n ) {
case 1: tt.internalFmt = 0x83F1; // COMPRESSED_RGBA_S3TC_DXT1_EXT
case 2: tt.internalFmt = 0x83F2; // COMPRESSED_RGBA_S3TC_DXT3_EXT
Expand All @@ -1093,6 +1101,18 @@ class GlDriver extends Driver {
case 7: tt.internalFmt = 0x8E8C; // COMPRESSED_RGBA_BPTC_UNORM
default: throw "Unsupported texture format "+t.format;
}
case ASTC(n):
checkMult4(t);
switch (n) {
case 10: tt.internalFmt = hxd.CompressedTextureFormat.ASTC_FORMAT.RGBA_4x4;
default: throw "Unsupported texture format " + t.format;
}
case ETC(n):
checkMult4(t);
switch (n) {
case 0: tt.internalFmt = hxd.CompressedTextureFormat.ETC_FORMAT.RGB_ETC1;
case 1: tt.internalFmt = hxd.CompressedTextureFormat.ETC_FORMAT.RGBA_ETC2;
}
default:
throw "Unsupported texture format "+t.format;
}
Expand Down Expand Up @@ -1169,6 +1189,11 @@ class GlDriver extends Driver {
return tt;
}

inline function checkMult4( t : h3d.mat.Texture ) {
if( t.width & 3 != 0 || t.height & 3 != 0 )
throw "Compressed texture " + t + " has size " + t.width + "x" + t.height + " - must be a multiple of 4";
}

function restoreBind() {
var t = boundTextures[lastActiveIndex];
if( t == null )
Expand Down Expand Up @@ -1409,7 +1434,7 @@ 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(_)) ) {
if( t.format.match(S3TC(_) | ASTC(_) | ETC(_)) ) {
if( t.flags.has(IsArray) || t.flags.has(Is3D) )
gl.compressedTexSubImage3D(face, mipLevel, 0, 0, side, pixels.width, pixels.height, 1, t.t.internalFmt, buffer);
else
Expand Down Expand Up @@ -1893,20 +1918,37 @@ class GlDriver extends Driver {
}

#if js
public function checkTextureSupport() {
final checkExtension = ext -> {
gl.getExtension(ext) != null;
}
return {
astc: checkExtension('WEBGL_compressed_texture_astc'),
astcHDR: checkExtension('WEBGL_compressed_texture_astc')
&& gl.getExtension('WEBGL_compressed_texture_astc').getSupportedProfiles().includes('hdr'),
etc1: false, // Not supported on WebGL2 (https://registry.khronos.org/OpenGL-Refpages/es3/html/glCompressedTexSubImage2D.xhtml); checkExtension('WEBGL_compressed_texture_etc1'),
etc2: checkExtension('WEBGL_compressed_texture_etc'),
dxt: checkExtension('WEBGL_compressed_texture_s3tc'),
bptc: checkExtension('EXT_texture_compression_bptc'),
}
}

var features : Map<Feature,Bool> = new Map();
var has16Bits : Bool;
function makeFeatures() {
for( f in Type.allEnums(Feature) )
features.set(f,checkFeature(f));
if( gl.getExtension("WEBGL_compressed_texture_s3tc") != null ) {
maxCompressedTexturesSupport = 3;
if( gl.getExtension("EXT_texture_compression_bptc") != null )
maxCompressedTexturesSupport = 7;
textureSupport = checkTextureSupport();
maxCompressedTexturesSupport = if( textureSupport.dxt || textureSupport.etc1 || textureSupport.etc2 || textureSupport.astc ) {
gl.getExtension("EXT_texture_compression_bptc") != null ? 7 : 3;
} else {
3;
}
if( glES < 3 )
gl.getExtension("WEBGL_depth_texture");
has16Bits = gl.getExtension("EXT_texture_norm16") != null; // 16 bit textures
}

function checkFeature( f : Feature ) {
return switch( f ) {

Expand Down Expand Up @@ -2126,4 +2168,4 @@ class GlDriver extends Driver {

}

#end
#end
16 changes: 9 additions & 7 deletions h3d/shader/SignedDistanceField.hx
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ class SignedDistanceField extends hxsl.Shader {

function fragment() {
var textureSample : Vec4 = textureColor;
var distance : Float;

distance = if (channel == 0) textureSample.r;
else if (channel == 1) textureSample.g;
else if (channel == 2) textureSample.b;
else if (channel == 3) textureSample.a;
else median(textureSample.r, textureSample.g, textureSample.b);
var distances = [
textureSample.r,
textureSample.g,
textureSample.b,
textureSample.a,
median(textureSample.r, textureSample.g, textureSample.b),
];
var ch = int(clamp(float(channel),0,4));
var distance = distances[ch];

var smoothVal = autoSmoothing ? abs(fwidth(distance) * 0.5) : smoothing;
textureColor = vec4(1.0, 1.0, 1.0, smoothstep(alphaCutoff - smoothVal, alphaCutoff + smoothVal, distance));
Expand Down
22 changes: 22 additions & 0 deletions hxd/CompressedTextureFormat.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package hxd;

enum abstract ASTC_FORMAT(Int) from Int to Int {
final RGBA_4x4 = 0x93B0;
}

enum abstract DXT_FORMAT(Int) from Int to Int {
final RGB_DXT1 = 0x83F0;
final RGBA_DXT1 = 0x83F1;
final RGBA_DXT3 = 0x83F2;
final RGBA_DXT5 = 0x83F3;
}

enum abstract ETC_FORMAT(Int) from Int to Int {
final RGB_ETC1 = 0x8D64;
final RGBA_ETC2 = 0x9278;
}

enum abstract BPTC_FORMAT(Int) from Int to Int {
final RGB_BPTC_UNSIGNED = 0x8E8F;
final RGBA_BPTC = 0x8E8C;
}
6 changes: 4 additions & 2 deletions hxd/PixelFormat.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ enum PixelFormat {
RG16U;
RGB16U;
RGBA16U;
S3TC( v : Int );
ASTC( v:Int );
ETC( v:Int );
S3TC( v:Int );
Depth16;
Depth24;
Depth24Stencil8;
Depth32;
}
}
54 changes: 48 additions & 6 deletions hxd/Pixels.hx
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ class Pixels {
this.bytes = nbytes;

case [S3TC(a),S3TC(b)] if( a == b ):
case [ASTC(a),ASTC(b)] if( a == b ):
case [ETC(a),ETC(b)] if( a == b ):
// nothing

#if (hl && hl_ver >= "1.10")
Expand Down Expand Up @@ -536,8 +538,33 @@ class Pixels {

public static function calcDataSize( width : Int, height : Int, format : PixelFormat ) {
return switch( format ) {
case S3TC(_):
(((height + 3) >> 2) << 2) * calcStride(width, format);
case S3TC(n):
var w = (width + 3) >> 2;
var h = (height + 3) >> 2;
var blocks = w * h; // Total number of blocks
if( n == 3 ) { // DXT5
blocks * 16; // 16 bytes per block
} else if( n == 1 || n == 4 ) {
blocks * 8; // DXT1 or BC4, 8 bytes per block
} else {
blocks * 16; // DXT3 or BC5, 16 bytes per block, but handling like DXT5 for simplicity
}
case ASTC(n):
var w = (width + 3) >> 2;
var h = (height + 3) >> 2;
w * h * 16;
case ETC(n):
if( n == 0 ) { // RGB_ETC1_Format or RGB_ETC2_Format
var w = (width + 3) >> 2;
var h = (height + 3) >> 2;
w * h * 8;
} else if( n == 1 || n == 2 ) { // RGBA_ETC2_EAC_Format
var w = (width + 3) >> 2;
var h = (height + 3) >> 2;
w * h * 16;
} else {
throw "Unsupported ETC format";
}
default:
height * calcStride(width, format);
}
Expand All @@ -559,11 +586,26 @@ class Pixels {
case RGB32F: 12;
case RGB10A2: 4;
case RG11B10UF: 4;
case ASTC(n):
var blocks = ((width + 3) >> 2) * 16;
blocks << 4;
case ETC(n):
if( n == 0 ) { // ETC1 and ETC2 RGB
((width + 3) >> 2) << 3;
} else if( n == 1 ) { // ETC2 EAC RGBA
((width + 3) >> 2) << 4;
} else {
throw "Unsupported ETC format";
}
case S3TC(n):
var blocks = (width + 3) >> 2;
if( n == 1 || n == 4 )
return blocks << 1;
return blocks << 2;
if( n == 3 ) { // DXT5
blocks << 4; // 16 bytes per block
} else if( n == 1 || n == 4 ) {
blocks << 1; // DXT1 or BC4, 8 bytes per block
} else {
blocks << 2; // DXT3 or BC5, 16 bytes per block, but handling like DXT5 for simplicity
}
case Depth16: 2;
case Depth24: 3;
case Depth24Stencil8, Depth32: 4;
Expand Down Expand Up @@ -605,7 +647,7 @@ class Pixels {
channel.toInt() * 4;
case RGB10A2, RG11B10UF:
throw "Bit packed format";
case S3TC(_), Depth16, Depth24, Depth24Stencil8, Depth32:
case S3TC(_), ASTC(_), ETC(_), Depth16, Depth24, Depth24Stencil8, Depth32:
throw "Not supported";
}
}
Expand Down
13 changes: 13 additions & 0 deletions hxd/fmt/bfnt/FontParser.hx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ class FontParser {

font.baseLine = 0;

// Json Format generated by https://github.com/Chlumsky/msdf-atlas-gen
if(bytes.getString(0,1) == "{") {
resolveTileSameName();
return hxd.fmt.bfnt.JsonFontParser.parse(bytes,tile);
}


switch( bytes.getInt32(0) ) {
case 0x544E4642: // Internal BFNT
return hxd.fmt.bfnt.Reader.parse(bytes, function( tp : String ) { resolveTileWithFallback(tp); return tile; });
Expand All @@ -55,6 +62,12 @@ class FontParser {
font.lineHeight = Std.parseInt(xml.node.common.att.lineHeight);
font.baseLine = Std.parseInt(xml.node.common.att.base);

// This node contains SDF Metadata
if(xml.hasNode.distanceField) {
font.distanceRange = Std.parseInt(xml.node.distanceField.att.distanceRange);
font.fieldType = Std.string(xml.node.distanceField.att.fieldType);
}

for ( p in xml.node.pages.elements ) {
if ( p.att.id == "0" ) {
resolveTileWithFallback(p.att.file);
Expand Down
Loading