Skip to content

Commit 58338b6

Browse files
authored
Merge pull request #21144 from donmccurdy/cleanup-universal-texture-loaders
KTX2Loader + BasisTextureLoader: Clean up.
2 parents ff5573c + 055ffaf commit 58338b6

File tree

3 files changed

+88
-78
lines changed

3 files changed

+88
-78
lines changed

examples/js/loaders/BasisTextureLoader.js

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ THREE.BasisTextureLoader = function ( manager ) {
2323
this.workerNextTaskID = 1;
2424
this.workerSourceURL = '';
2525
this.workerConfig = null;
26+
2627
};
2728

2829
THREE.BasisTextureLoader.taskCache = new WeakMap();
@@ -104,7 +105,7 @@ THREE.BasisTextureLoader.prototype = Object.assign( Object.create( THREE.Loader.
104105
/** Low-level transcoding API, exposed for use by THREE.KTX2Loader. */
105106
parseInternalAsync: function ( options ) {
106107

107-
var { levels, hasAlpha, basisFormat } = options;
108+
var { levels } = options;
108109

109110
var buffers = new Set();
110111

@@ -154,8 +155,6 @@ THREE.BasisTextureLoader.prototype = Object.assign( Object.create( THREE.Loader.
154155
} )
155156
.then( ( message ) => {
156157

157-
var config = this.workerConfig;
158-
159158
var { mipmaps, width, height, format } = message;
160159

161160
var texture = new THREE.CompressedTexture( mipmaps, width, height, format, THREE.UnsignedByteType );
@@ -221,9 +220,9 @@ THREE.BasisTextureLoader.prototype = Object.assign( Object.create( THREE.Loader.
221220

222221
var body = [
223222
'/* constants */',
224-
'var _EngineFormat = ' + JSON.stringify( BasisTextureLoader.EngineFormat ),
225-
'var _TranscoderFormat = ' + JSON.stringify( BasisTextureLoader.TranscoderFormat ),
226-
'var _BasisFormat = ' + JSON.stringify( BasisTextureLoader.BasisFormat ),
223+
'var _EngineFormat = ' + JSON.stringify( THREE.BasisTextureLoader.EngineFormat ),
224+
'var _TranscoderFormat = ' + JSON.stringify( THREE.BasisTextureLoader.TranscoderFormat ),
225+
'var _BasisFormat = ' + JSON.stringify( THREE.BasisTextureLoader.BasisFormat ),
227226
'/* basis_transcoder.js */',
228227
jsContent,
229228
'/* worker */',
@@ -430,7 +429,7 @@ THREE.BasisTextureLoader.BasisWorker = function () {
430429

431430
}
432431

433-
function transcodeLowLevel ( taskConfig ) {
432+
function transcodeLowLevel( taskConfig ) {
434433

435434
var { basisFormat, width, height, hasAlpha } = taskConfig;
436435

@@ -517,7 +516,7 @@ THREE.BasisTextureLoader.BasisWorker = function () {
517516
hasAlpha,
518517
false,
519518
0, 0,
520-
-1, -1
519+
- 1, - 1
521520
);
522521

523522
assert( ok, 'THREE.BasisTextureLoader: transcodeUASTCImage() failed for level ' + level.index + '.' );
@@ -611,64 +610,72 @@ THREE.BasisTextureLoader.BasisWorker = function () {
611610
var FORMAT_OPTIONS = [
612611
{
613612
if: 'astcSupported',
614-
basisFormat: [BasisFormat.UASTC_4x4],
615-
transcoderFormat: [TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4],
616-
engineFormat: [EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format],
613+
basisFormat: [ BasisFormat.UASTC_4x4 ],
614+
transcoderFormat: [ TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4 ],
615+
engineFormat: [ EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format ],
617616
priorityETC1S: Infinity,
618617
priorityUASTC: 1,
619618
needsPowerOfTwo: false,
620619
},
621620
{
622621
if: 'bptcSupported',
623-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
624-
transcoderFormat: [TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5],
625-
engineFormat: [EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format],
622+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
623+
transcoderFormat: [ TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5 ],
624+
engineFormat: [ EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format ],
626625
priorityETC1S: 3,
627626
priorityUASTC: 2,
628627
needsPowerOfTwo: false,
629628
},
630629
{
631630
if: 'dxtSupported',
632-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
633-
transcoderFormat: [TranscoderFormat.BC1, TranscoderFormat.BC3],
634-
engineFormat: [EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format],
631+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
632+
transcoderFormat: [ TranscoderFormat.BC1, TranscoderFormat.BC3 ],
633+
engineFormat: [ EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format ],
635634
priorityETC1S: 4,
636635
priorityUASTC: 5,
637636
needsPowerOfTwo: false,
638637
},
639638
{
640639
if: 'etc2Supported',
641-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
642-
transcoderFormat: [TranscoderFormat.ETC1, TranscoderFormat.ETC2],
643-
engineFormat: [EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format],
640+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
641+
transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC2 ],
642+
engineFormat: [ EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format ],
644643
priorityETC1S: 1,
645644
priorityUASTC: 3,
646645
needsPowerOfTwo: false,
647646
},
648647
{
649648
if: 'etc1Supported',
650-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
651-
transcoderFormat: [TranscoderFormat.ETC1, TranscoderFormat.ETC1],
652-
engineFormat: [EngineFormat.RGB_ETC1_Format, EngineFormat.RGB_ETC1_Format],
649+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
650+
transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC1 ],
651+
engineFormat: [ EngineFormat.RGB_ETC1_Format, EngineFormat.RGB_ETC1_Format ],
653652
priorityETC1S: 2,
654653
priorityUASTC: 4,
655654
needsPowerOfTwo: false,
656655
},
657656
{
658657
if: 'pvrtcSupported',
659-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
660-
transcoderFormat: [TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA],
661-
engineFormat: [EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format],
658+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
659+
transcoderFormat: [ TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA ],
660+
engineFormat: [ EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format ],
662661
priorityETC1S: 5,
663662
priorityUASTC: 6,
664663
needsPowerOfTwo: true,
665664
},
666665
];
667666

668-
var ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) { return a.priorityETC1S - b.priorityETC1S; } );
669-
var UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) { return a.priorityUASTC - b.priorityUASTC; } );
667+
var ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {
668+
669+
return a.priorityETC1S - b.priorityETC1S;
670+
671+
} );
672+
var UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {
673+
674+
return a.priorityUASTC - b.priorityUASTC;
675+
676+
} );
670677

671-
function getTranscoderFormat ( basisFormat, width, height, hasAlpha ) {
678+
function getTranscoderFormat( basisFormat, width, height, hasAlpha ) {
672679

673680
var transcoderFormat;
674681
var engineFormat;
@@ -699,25 +706,25 @@ THREE.BasisTextureLoader.BasisWorker = function () {
699706

700707
}
701708

702-
function assert ( ok, message ) {
709+
function assert( ok, message ) {
703710

704711
if ( ! ok ) throw new Error( message );
705712

706713
}
707714

708-
function getWidthInBlocks ( transcoderFormat, width ) {
715+
function getWidthInBlocks( transcoderFormat, width ) {
709716

710717
return Math.ceil( width / BasisModule.getFormatBlockWidth( transcoderFormat ) );
711718

712719
}
713720

714-
function getHeightInBlocks ( transcoderFormat, height ) {
721+
function getHeightInBlocks( transcoderFormat, height ) {
715722

716723
return Math.ceil( height / BasisModule.getFormatBlockHeight( transcoderFormat ) );
717724

718725
}
719726

720-
function getTranscodedImageByteLength ( transcoderFormat, width, height ) {
727+
function getTranscodedImageByteLength( transcoderFormat, width, height ) {
721728

722729
var blockByteLength = BasisModule.getBytesPerBlockOrPixel( transcoderFormat );
723730

@@ -745,7 +752,7 @@ THREE.BasisTextureLoader.BasisWorker = function () {
745752

746753
}
747754

748-
function isPowerOfTwo ( value ) {
755+
function isPowerOfTwo( value ) {
749756

750757
if ( value <= 2 ) return true;
751758

examples/jsm/loaders/BasisTextureLoader.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var BasisTextureLoader = function ( manager ) {
4242
this.workerNextTaskID = 1;
4343
this.workerSourceURL = '';
4444
this.workerConfig = null;
45+
4546
};
4647

4748
BasisTextureLoader.taskCache = new WeakMap();
@@ -123,7 +124,7 @@ BasisTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ),
123124
/** Low-level transcoding API, exposed for use by KTX2Loader. */
124125
parseInternalAsync: function ( options ) {
125126

126-
var { levels, hasAlpha, basisFormat } = options;
127+
var { levels } = options;
127128

128129
var buffers = new Set();
129130

@@ -173,8 +174,6 @@ BasisTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ),
173174
} )
174175
.then( ( message ) => {
175176

176-
var config = this.workerConfig;
177-
178177
var { mipmaps, width, height, format } = message;
179178

180179
var texture = new CompressedTexture( mipmaps, width, height, format, UnsignedByteType );
@@ -449,7 +448,7 @@ BasisTextureLoader.BasisWorker = function () {
449448

450449
}
451450

452-
function transcodeLowLevel ( taskConfig ) {
451+
function transcodeLowLevel( taskConfig ) {
453452

454453
var { basisFormat, width, height, hasAlpha } = taskConfig;
455454

@@ -536,7 +535,7 @@ BasisTextureLoader.BasisWorker = function () {
536535
hasAlpha,
537536
false,
538537
0, 0,
539-
-1, -1
538+
- 1, - 1
540539
);
541540

542541
assert( ok, 'THREE.BasisTextureLoader: transcodeUASTCImage() failed for level ' + level.index + '.' );
@@ -630,64 +629,72 @@ BasisTextureLoader.BasisWorker = function () {
630629
var FORMAT_OPTIONS = [
631630
{
632631
if: 'astcSupported',
633-
basisFormat: [BasisFormat.UASTC_4x4],
634-
transcoderFormat: [TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4],
635-
engineFormat: [EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format],
632+
basisFormat: [ BasisFormat.UASTC_4x4 ],
633+
transcoderFormat: [ TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4 ],
634+
engineFormat: [ EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format ],
636635
priorityETC1S: Infinity,
637636
priorityUASTC: 1,
638637
needsPowerOfTwo: false,
639638
},
640639
{
641640
if: 'bptcSupported',
642-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
643-
transcoderFormat: [TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5],
644-
engineFormat: [EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format],
641+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
642+
transcoderFormat: [ TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5 ],
643+
engineFormat: [ EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format ],
645644
priorityETC1S: 3,
646645
priorityUASTC: 2,
647646
needsPowerOfTwo: false,
648647
},
649648
{
650649
if: 'dxtSupported',
651-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
652-
transcoderFormat: [TranscoderFormat.BC1, TranscoderFormat.BC3],
653-
engineFormat: [EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format],
650+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
651+
transcoderFormat: [ TranscoderFormat.BC1, TranscoderFormat.BC3 ],
652+
engineFormat: [ EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format ],
654653
priorityETC1S: 4,
655654
priorityUASTC: 5,
656655
needsPowerOfTwo: false,
657656
},
658657
{
659658
if: 'etc2Supported',
660-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
661-
transcoderFormat: [TranscoderFormat.ETC1, TranscoderFormat.ETC2],
662-
engineFormat: [EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format],
659+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
660+
transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC2 ],
661+
engineFormat: [ EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format ],
663662
priorityETC1S: 1,
664663
priorityUASTC: 3,
665664
needsPowerOfTwo: false,
666665
},
667666
{
668667
if: 'etc1Supported',
669-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
670-
transcoderFormat: [TranscoderFormat.ETC1, TranscoderFormat.ETC1],
671-
engineFormat: [EngineFormat.RGB_ETC1_Format, EngineFormat.RGB_ETC1_Format],
668+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
669+
transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC1 ],
670+
engineFormat: [ EngineFormat.RGB_ETC1_Format, EngineFormat.RGB_ETC1_Format ],
672671
priorityETC1S: 2,
673672
priorityUASTC: 4,
674673
needsPowerOfTwo: false,
675674
},
676675
{
677676
if: 'pvrtcSupported',
678-
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
679-
transcoderFormat: [TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA],
680-
engineFormat: [EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format],
677+
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
678+
transcoderFormat: [ TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA ],
679+
engineFormat: [ EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format ],
681680
priorityETC1S: 5,
682681
priorityUASTC: 6,
683682
needsPowerOfTwo: true,
684683
},
685684
];
686685

687-
var ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) { return a.priorityETC1S - b.priorityETC1S; } );
688-
var UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) { return a.priorityUASTC - b.priorityUASTC; } );
686+
var ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {
687+
688+
return a.priorityETC1S - b.priorityETC1S;
689+
690+
} );
691+
var UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {
692+
693+
return a.priorityUASTC - b.priorityUASTC;
694+
695+
} );
689696

690-
function getTranscoderFormat ( basisFormat, width, height, hasAlpha ) {
697+
function getTranscoderFormat( basisFormat, width, height, hasAlpha ) {
691698

692699
var transcoderFormat;
693700
var engineFormat;
@@ -718,25 +725,25 @@ BasisTextureLoader.BasisWorker = function () {
718725

719726
}
720727

721-
function assert ( ok, message ) {
728+
function assert( ok, message ) {
722729

723730
if ( ! ok ) throw new Error( message );
724731

725732
}
726733

727-
function getWidthInBlocks ( transcoderFormat, width ) {
734+
function getWidthInBlocks( transcoderFormat, width ) {
728735

729736
return Math.ceil( width / BasisModule.getFormatBlockWidth( transcoderFormat ) );
730737

731738
}
732739

733-
function getHeightInBlocks ( transcoderFormat, height ) {
740+
function getHeightInBlocks( transcoderFormat, height ) {
734741

735742
return Math.ceil( height / BasisModule.getFormatBlockHeight( transcoderFormat ) );
736743

737744
}
738745

739-
function getTranscodedImageByteLength ( transcoderFormat, width, height ) {
746+
function getTranscodedImageByteLength( transcoderFormat, width, height ) {
740747

741748
var blockByteLength = BasisModule.getBytesPerBlockOrPixel( transcoderFormat );
742749

@@ -764,7 +771,7 @@ BasisTextureLoader.BasisWorker = function () {
764771

765772
}
766773

767-
function isPowerOfTwo ( value ) {
774+
function isPowerOfTwo( value ) {
768775

769776
if ( value <= 2 ) return true;
770777

0 commit comments

Comments
 (0)