Skip to content

Commit 6966f6c

Browse files
committed
Change enum(eration) names for consistency.
Use libktx names with `ktx{,_}` prefix and `_e` suffix removed. Users will no longer need to remember or lookup the different name used in the binding.
1 parent c38c3e9 commit 6966f6c

File tree

4 files changed

+92
-87
lines changed

4 files changed

+92
-87
lines changed

interface/js_binding/class_compat.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010

1111
Module.onRuntimeInitialized = function() {
1212
Module['ktxTexture'] = Module.texture;
13+
Module['ErrorCode'] = Module.error_code;
14+
Module['TranscodeTarget'] = Module.texture_transcode_fmt;
15+
Module['TranscodeFlags'] = Module.transcode_flag_bits;
1316
}
1417

interface/js_binding/ktx_wrapper.cpp

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,8 @@ interface astcParams { // **
586586
587587
attribute boolean verbose;
588588
attribute long threadCount;
589-
attribute AstcBlockDimension blockDimension;
590-
attribute AstcMode mode;
589+
attribute astc_block_dimension blockDimension;
590+
attribute pack_astc_encoder_mode mode;
591591
attribute long qualityLevel;
592592
attribute boolean normalMap;
593593
attribute DOMString inputSwizzle;
@@ -617,7 +617,7 @@ interface basisParams { // **
617617
618618
// UASTC parameters.
619619
620-
attribute UastcFlags uastcFlags,
620+
attribute pack_uastc_flag_bits uastcFlags,
621621
attribute boolean uastcRDO,
622622
attribute float uastcRDOQualityScalar,
623623
attribute long uastcRDODictSize,
@@ -632,20 +632,20 @@ interface texture {
632632
constructor(textureCreateInfo createInfo, // **
633633
CreateStorageEnum? storage);
634634
635-
ErrorCode compressAstc(ktxAstcParams params); // **
636-
ErrorCode compressBasis(ktxBasisParams params); // **
635+
error_code compressAstc(ktxAstcParams params); // **
636+
error_code compressBasis(ktxBasisParams params); // **
637637
texture createCopy(); // **
638-
ErrorCode defateZLIB(); // **
639-
ErrorCode deflateZstd(); // **
638+
error_code defateZLIB(); // **
639+
error_code deflateZstd(); // **
640640
ArrayBufferView getImage(long level, long layer, long faceSlice);
641641
UploadResult glUpload();
642-
ErrorCode setImageFromMemory(long level, long layer, long faceSlice,
642+
error_code setImageFromMemory(long level, long layer, long faceSlice,
643643
ArrayBufferView imageData); // **
644-
ErrorCode transcodeBasis(TranscodeTarget? target, TranscodeFlagBits
644+
error_code transcodeBasis(texture_transcode_fmt? target, transcode_flag_bits
645645
decodeFlags);
646646
ArrayBufferView writeToMemory(); // **
647-
ErrorCode addKVPairString(DOMString key, DOMString value); // **
648-
ErrorCode addKVPairByte(DOMString key, ArrayBuffewView value); // **
647+
error_code addKVPairString(DOMString key, DOMString value); // **
648+
error_code addKVPairByte(DOMString key, ArrayBuffewView value); // **
649649
deleteKVPair(DOMString key); // **
650650
DOMString? findKeyValue(DOMString key);
651651
@@ -659,11 +659,11 @@ interface texture {
659659
readonly attribute SupercmpScheme supercompressionScheme;
660660
readonly attribute ktxOrientation orientation;
661661
662-
attribute dfTransfer OETF; // Setting available only in libktx.js.
663-
attribute dfPrimaries primaries; // Setting available only in libktx.js.
662+
attribute khr_df_transfer OETF; // Setting available only in libktx.js.
663+
attribute khr_df_primaries primaries; // Setting available only in libktx.js.
664664
};
665665
666-
enum ErrorCode = {
666+
enum error_code = {
667667
"SUCCESS",
668668
"FILE_DATA_ERROR",
669669
"FILE_ISPIPE",
@@ -692,7 +692,7 @@ enum CreateStorageEnum = {
692692
693693
// Some targets may not be available depending on options used when compiling
694694
// the web assembly. ktxTexture.transcodeBasis will report this.
695-
enum TranscodeTarget = {
695+
enum texture_transcode_fmt = {
696696
"ETC1_RGB",
697697
"BC1_RGB",
698698
"BC4_R",
@@ -715,7 +715,7 @@ enum TranscodeTarget = {
715715
"EAC_RG11"
716716
};
717717
718-
enum TranscodeFlagBits {
718+
enum transcode_flag_bits {
719719
"TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS"
720720
};
721721
@@ -739,15 +739,15 @@ enum SupercmpScheme {
739739
"ZLIB"
740740
};
741741
742-
enum dfPrimaries = {
742+
enum khr_df_primaries = {
743743
// These are the values needed for KTX with HTML5/WebGL.
744744
"UNSPECIFIED",
745745
"BT709",
746746
"SRGB"
747747
"DISPLAYP3"
748748
};
749749
750-
enum dfTransfer = {
750+
enum khr_df_transfer = {
751751
// These are the values needed for KTX with HTML5/WebGL.
752752
"UNSPECIFIED",
753753
"LINEAR",
@@ -762,15 +762,15 @@ enum VkFormat = {
762762
// purpose of this IDL. Any VkFormat valid for KTX can be used. As shown
763763
// here, omit the VK_FORMAT_ prefix and enclose in quotes.
764764
765-
enum AstcQualityLevel = { // **
765+
enum astc_quality_levels = { // **
766766
"FASTEST",
767767
"FAST",
768768
"MEDIUM",
769769
"THOROUGH",
770770
"EXHAUSTIVE",
771771
};
772772
773-
enum AstcBlockDimension = { // **
773+
enum astc_block_dimension = { // **
774774
// 2D formats
775775
"d4x4",
776776
"d5x4",
@@ -799,26 +799,27 @@ enum AstcBlockDimension = { // **
799799
"d6x6x6"
800800
};
801801
802-
enum AstcMode = { // **
802+
enum pack_astc_encoder_mode = { // **
803803
"DEFAULT",
804804
"LDR",
805805
"HDR"
806806
};
807807
808-
enum UastcFlags = { // **
808+
enum pack_uastc_flag_bits = { // **
809809
"LEVEL_FASTEST",
810810
"LEVEL_FASTER",
811811
"LEVEL_DEFAULT",
812812
"LEVEL_SLOWER",
813813
"LEVEL_VERYSLOW",
814814
};
815815
816-
const DOMString AnimDataKey = "KTXanimData";
817-
const DOMString OrientationKey = "KTXorientation";
818-
const DOMString SwizzleKey = "KTXswizzle";
819-
const DOMString WriterKey = "KTXwriter";
820-
const unsigned long FaceSliceWholeLevel = UINT_MAX;
821-
const unsigned long Etc1SDefaultCompressionLevel = 2;
816+
const DOMString ANIMDATA_KEY = "KTXanimData";
817+
const DOMStringORIENTATION_KEY = "KTXorientation";
818+
const DOMString SWIZZLE_KEY = "KTXswizzle";
819+
const DOMString WRITER_KEY = "KTXwriter";
820+
const DOMString WRITER_SCPARAMS_KEY = "KTXwriterScParams";
821+
const unsigned long FACESLICE_WHOLE_lEVEL = UINT_MAX;
822+
const unsigned long ETC1S_DEFAULT_COMPRESSION_LEVEL = 2;
822823
@endcode
823824
824825
# How to use
@@ -955,28 +956,28 @@ returns the created WebGL texture object and matching texture target.
955956
956957
@code{.js}
957958
function uploadTextureToGl(gl, ktexture) {
958-
const { TranscodeTarget } = ktx;
959+
const { texture_transcode_fmt } = ktx;
959960
var formatString;
960961
961962
if (ktexture.needsTranscoding) {
962963
var format;
963964
if (astcSupported) {
964965
formatString = 'ASTC';
965-
format = TranscodeTarget.ASTC_4x4_RGBA;
966+
format = texture_transcode_fmt.ASTC_4x4_RGBA;
966967
} else if (dxtSupported) {
967968
formatString = ktexture.numComponents == 4 ? 'BC3' : 'BC1';
968-
format = TranscodeTarget.BC1_OR_3;
969+
format = texture_transcode_fmt.BC1_OR_3;
969970
} else if (pvrtcSupported) {
970971
formatString = 'PVRTC1';
971-
format = TranscodeTarget.PVRTC1_4_RGBA;
972+
format = texture_transcode_fmt.PVRTC1_4_RGBA;
972973
} else if (etcSupported) {
973974
formatString = 'ETC';
974-
format = TranscodeTarget.ETC;
975+
format = texture_transcode_fmt.ETC;
975976
} else {
976977
formatString = 'RGBA4444';
977-
format = TranscodeTarget.RGBA4444;
978+
format = texture_transcode_fmt.RGBA4444;
978979
}
979-
if (ktexture.transcodeBasis(format, 0) != ktx.ErrorCode.SUCCESS) {
980+
if (ktexture.transcodeBasis(format, 0) != ktx.error_code.SUCCESS) {
980981
alert('Texture transcode failed. See console for details.');
981982
return undefined;
982983
}
@@ -1114,7 +1115,7 @@ Step 3 is to create the KTX texture object as shonw here:
11141115
const ktexture = new ktx.texture(createInfo, ktx.CreateStorageEnum.ALLOC_STORAGE);
11151116
if (ktexture != null) {
11161117
if (displayP3) {
1117-
ktexture.primaries = ktx.dfPrimaries.DISPLAYP3;
1118+
ktexture.primaries = ktx.khr_df_primaries.DISPLAYP3;
11181119
}
11191120
result = ktexture.setImageFromMemory(0, 0, 0, imageData.data);
11201121
}
@@ -1136,10 +1137,10 @@ like the following.
11361137
basisu_options.noSSE = true;
11371138
basisu_options.verbose = false;
11381139
basisu_options.qualityLevel = 200;
1139-
basisu_options.compressionLevel = ktx.Etc1SDefaultCompressionLevel;
1140+
basisu_options.compressionLevel = ktx.ETC1S_DEFAULT_COMPRESSION_LEVEL;
11401141
11411142
var result = ktexture.compressBasis(basisu_options);
1142-
// Check result for ktx.ErrorCode.SUCCESS.
1143+
// Check result for ktx.error_code.SUCCESS.
11431144
}
11441145
@endcode
11451146
@@ -1157,7 +1158,7 @@ a local file or upload it to a server.
11571158

11581159
EMSCRIPTEN_BINDINGS(ktx)
11591160
{
1160-
enum_<ktx_error_code_e>("ErrorCode")
1161+
enum_<ktx_error_code_e>("error_code")
11611162
.value("SUCCESS", KTX_SUCCESS)
11621163
.value("FILE_DATA_ERROR", KTX_FILE_DATA_ERROR)
11631164
.value("FILE_ISPIPE", KTX_FILE_ISPIPE)
@@ -1181,7 +1182,7 @@ EMSCRIPTEN_BINDINGS(ktx)
11811182
.value("DECOMPRESS_CHECKSUM_ERROR", KTX_DECOMPRESS_CHECKSUM_ERROR)
11821183
;
11831184

1184-
enum_<ktx_texture_transcode_fmt_e>("TranscodeTarget")
1185+
enum_<ktx_texture_transcode_fmt_e>("texture_transcode_fmt")
11851186
.value("ETC1_RGB", KTX_TTF_ETC1_RGB)
11861187
.value("BC1_RGB", KTX_TTF_BC1_RGB)
11871188
.value("BC4_R", KTX_TTF_BC4_R)
@@ -1205,7 +1206,7 @@ EMSCRIPTEN_BINDINGS(ktx)
12051206
.value("EAC_RG11", KTX_TTF_ETC2_EAC_RG11)
12061207
;
12071208

1208-
enum_<ktx_transcode_flag_bits_e>("TranscodeFlagBits")
1209+
enum_<ktx_transcode_flag_bits_e>("transcode_flag_bits")
12091210
.value("TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS",
12101211
KTX_TF_TRANSCODE_ALPHA_DATA_TO_OPAQUE_FORMATS)
12111212
;
@@ -1238,15 +1239,15 @@ EMSCRIPTEN_BINDINGS(ktx)
12381239
.field("z", &ktxOrientation::z)
12391240
;
12401241

1241-
enum_<khr_df_primaries_e>("dfPrimaries")
1242+
enum_<khr_df_primaries_e>("khr_df_primaries")
12421243
// These are the values needed with HTML5/WebGL.
12431244
.value("UNSPECIFIED", KHR_DF_PRIMARIES_UNSPECIFIED)
12441245
.value("BT709", KHR_DF_PRIMARIES_BT709)
12451246
.value("SRGB", KHR_DF_PRIMARIES_SRGB)
12461247
.value("DISPLAYP3", KHR_DF_PRIMARIES_DISPLAYP3)
12471248
;
12481249

1249-
enum_<khr_df_transfer_e>("dfTransfer")
1250+
enum_<khr_df_transfer_e>("khr_df_transfer")
12501251
// These are the values needed for KTX with HTML5/WebGL.
12511252
.value("UNSPECIFIED", KHR_DF_TRANSFER_UNSPECIFIED)
12521253
.value("LINEAR", KHR_DF_TRANSFER_LINEAR)
@@ -1303,7 +1304,7 @@ EMSCRIPTEN_BINDINGS(ktx)
13031304
;
13041305

13051306
#if KTX_FEATURE_WRITE
1306-
enum_<ktxTextureCreateStorageEnum>("CreateStorageEnum")
1307+
enum_<ktxTextureCreateStorageEnum>("TextureCreateStorageEnum")
13071308
.value("NO_STORAGE", KTX_TEXTURE_CREATE_NO_STORAGE)
13081309
.value("ALLOC_STORAGE", KTX_TEXTURE_CREATE_ALLOC_STORAGE)
13091310
;
@@ -1336,15 +1337,15 @@ EMSCRIPTEN_BINDINGS(ktx)
13361337
.property("generateMipmaps", &ktxTextureCreateInfo::generateMipmaps)
13371338
;
13381339

1339-
enum_<ktx_pack_astc_quality_levels_e>("AstcQualityLevel")
1340+
enum_<ktx_pack_astc_quality_levels_e>("astc_quality_levels")
13401341
.value("FASTEST", KTX_PACK_ASTC_QUALITY_LEVEL_FASTEST)
13411342
.value("FAST", KTX_PACK_ASTC_QUALITY_LEVEL_FAST)
13421343
.value("MEDIUM", KTX_PACK_ASTC_QUALITY_LEVEL_MEDIUM)
13431344
.value("THOROUGH", KTX_PACK_ASTC_QUALITY_LEVEL_THOROUGH)
13441345
.value("EXHAUSTIVE", KTX_PACK_ASTC_QUALITY_LEVEL_EXHAUSTIVE)
13451346
;
13461347

1347-
enum_<ktx_pack_astc_block_dimension_e>("AstcBlockDimension")
1348+
enum_<ktx_pack_astc_block_dimension_e>("astc_block_dimension")
13481349
// 2D formats
13491350
.value("d4x4", KTX_PACK_ASTC_BLOCK_DIMENSION_4x4) //: 8.00 bpp
13501351
.value("d5x4", KTX_PACK_ASTC_BLOCK_DIMENSION_5x4) //: 6.40 bpp
@@ -1373,7 +1374,7 @@ EMSCRIPTEN_BINDINGS(ktx)
13731374
.value("d6x6x6", KTX_PACK_ASTC_BLOCK_DIMENSION_6x6x6) //: 0.59 bpp
13741375
;
13751376

1376-
enum_<ktx_pack_astc_encoder_mode_e>("AstcMode")
1377+
enum_<ktx_pack_astc_encoder_mode_e>("pack_astc_encoder_mode")
13771378
.value("DEFAULT", KTX_PACK_ASTC_ENCODER_MODE_DEFAULT)
13781379
.value("LDR", KTX_PACK_ASTC_ENCODER_MODE_LDR)
13791380
.value("HDR", KTX_PACK_ASTC_ENCODER_MODE_HDR)
@@ -1414,7 +1415,7 @@ EMSCRIPTEN_BINDINGS(ktx)
14141415
})
14151416
;
14161417

1417-
enum_<ktx_pack_uastc_flag_bits_e>("UastcFlags")
1418+
enum_<ktx_pack_uastc_flag_bits_e>("pack_uastc_flag_bits")
14181419
.value("LEVEL_FASTEST", KTX_PACK_UASTC_LEVEL_FASTEST)
14191420
.value("LEVEL_FASTER", KTX_PACK_UASTC_LEVEL_FASTER)
14201421
.value("LEVEL_DEFAULT", KTX_PACK_UASTC_LEVEL_DEFAULT)
@@ -1468,11 +1469,12 @@ EMSCRIPTEN_BINDINGS(ktx)
14681469
.property("uastcRDONoMultithreading", &ktxBasisParams::uastcRDONoMultithreading);
14691470
;
14701471

1471-
constant("AnimDataKey", std::string(KTX_ANIMDATA_KEY));
1472-
constant("OrientationKey", std::string(KTX_ORIENTATION_KEY));
1473-
constant("SwizzleKey", std::string(KTX_SWIZZLE_KEY));
1474-
constant("WriterKey", std::string(KTX_WRITER_KEY));
1475-
constant("FaceSliceWholeLevel", KTX_FACESLICE_WHOLE_LEVEL);
1476-
constant("Etc1SDefaultCompressionLevel", KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL);
1472+
constant("ANIMDATA_KEY", std::string(KTX_ANIMDATA_KEY));
1473+
constant("ORIENTATION_KEY", std::string(KTX_ORIENTATION_KEY));
1474+
constant("SWIZZLE_KEY", std::string(KTX_SWIZZLE_KEY));
1475+
constant("WRITER_KEY", std::string(KTX_WRITER_KEY));
1476+
constant("WRITER_SCPARAMS_KEY", std::string(KTX_WRITER_SCPARAMS_KEY));
1477+
constant("FACESLICE_WHOLE_lEVEL", KTX_FACESLICE_WHOLE_LEVEL);
1478+
constant("ETC1S_DEFAULT_COMPRESSION_LEVEL", KTX_ETC1S_DEFAULT_COMPRESSION_LEVEL);
14771479
#endif
14781480
}

tests/webgl/libktx-read-webgl/libktx-read-test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -348,28 +348,28 @@ function elem(id) {
348348
//
349349
// needs Emscripten's OpenGL ES emulation.
350350
function uploadTextureToGl(gl, ktexture) {
351-
const { TranscodeTarget } = ktx;
351+
const { texture_transcode_fmt } = ktx;
352352
var formatString;
353353

354354
if (ktexture.needsTranscoding) {
355355
var format;
356356
if (astcSupported) {
357357
formatString = 'ASTC';
358-
format = TranscodeTarget.ASTC_4x4_RGBA;
358+
format = texture_transcode_fmt.ASTC_4x4_RGBA;
359359
} else if (dxtSupported) {
360360
formatString = ktexture.numComponents == 4 ? 'BC3' : 'BC1';
361-
format = TranscodeTarget.BC1_OR_3;
361+
format = texture_transcode_fmt.BC1_OR_3;
362362
} else if (pvrtcSupported) {
363363
formatString = 'PVRTC1';
364-
format = TranscodeTarget.PVRTC1_4_RGBA;
364+
format = texture_transcode_fmt.PVRTC1_4_RGBA;
365365
} else if (etcSupported) {
366366
formatString = 'ETC';
367-
format = TranscodeTarget.ETC;
367+
format = texture_transcode_fmt.ETC;
368368
} else {
369369
formatString = 'RGBA4444';
370-
format = TranscodeTarget.RGBA4444;
370+
format = texture_transcode_fmt.RGBA4444;
371371
}
372-
if (ktexture.transcodeBasis(format, 0) != ktx.ErrorCode.SUCCESS) {
372+
if (ktexture.transcodeBasis(format, 0) != ktx.error_code.SUCCESS) {
373373
alert('Texture transcode failed. See console for details.');
374374
return undefined;
375375
}

0 commit comments

Comments
 (0)