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

KTX2Loader + BasisTextureLoader: Clean up. #21144

Merged
merged 1 commit into from
Jan 25, 2021
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
75 changes: 41 additions & 34 deletions examples/js/loaders/BasisTextureLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ THREE.BasisTextureLoader = function ( manager ) {
this.workerNextTaskID = 1;
this.workerSourceURL = '';
this.workerConfig = null;

};

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

var { levels, hasAlpha, basisFormat } = options;
var { levels } = options;

var buffers = new Set();

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

var config = this.workerConfig;

var { mipmaps, width, height, format } = message;

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

var body = [
'/* constants */',
'var _EngineFormat = ' + JSON.stringify( BasisTextureLoader.EngineFormat ),
'var _TranscoderFormat = ' + JSON.stringify( BasisTextureLoader.TranscoderFormat ),
'var _BasisFormat = ' + JSON.stringify( BasisTextureLoader.BasisFormat ),
'var _EngineFormat = ' + JSON.stringify( THREE.BasisTextureLoader.EngineFormat ),
'var _TranscoderFormat = ' + JSON.stringify( THREE.BasisTextureLoader.TranscoderFormat ),
'var _BasisFormat = ' + JSON.stringify( THREE.BasisTextureLoader.BasisFormat ),
'/* basis_transcoder.js */',
jsContent,
'/* worker */',
Expand Down Expand Up @@ -430,7 +429,7 @@ THREE.BasisTextureLoader.BasisWorker = function () {

}

function transcodeLowLevel ( taskConfig ) {
function transcodeLowLevel( taskConfig ) {

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

Expand Down Expand Up @@ -517,7 +516,7 @@ THREE.BasisTextureLoader.BasisWorker = function () {
hasAlpha,
false,
0, 0,
-1, -1
- 1, - 1
);

assert( ok, 'THREE.BasisTextureLoader: transcodeUASTCImage() failed for level ' + level.index + '.' );
Expand Down Expand Up @@ -611,64 +610,72 @@ THREE.BasisTextureLoader.BasisWorker = function () {
var FORMAT_OPTIONS = [
{
if: 'astcSupported',
basisFormat: [BasisFormat.UASTC_4x4],
transcoderFormat: [TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4],
engineFormat: [EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format],
basisFormat: [ BasisFormat.UASTC_4x4 ],
transcoderFormat: [ TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4 ],
engineFormat: [ EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format ],
priorityETC1S: Infinity,
priorityUASTC: 1,
needsPowerOfTwo: false,
},
{
if: 'bptcSupported',
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
transcoderFormat: [TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5],
engineFormat: [EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format],
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
transcoderFormat: [ TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5 ],
engineFormat: [ EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format ],
priorityETC1S: 3,
priorityUASTC: 2,
needsPowerOfTwo: false,
},
{
if: 'dxtSupported',
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
transcoderFormat: [TranscoderFormat.BC1, TranscoderFormat.BC3],
engineFormat: [EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format],
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
transcoderFormat: [ TranscoderFormat.BC1, TranscoderFormat.BC3 ],
engineFormat: [ EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format ],
priorityETC1S: 4,
priorityUASTC: 5,
needsPowerOfTwo: false,
},
{
if: 'etc2Supported',
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
transcoderFormat: [TranscoderFormat.ETC1, TranscoderFormat.ETC2],
engineFormat: [EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format],
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC2 ],
engineFormat: [ EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format ],
priorityETC1S: 1,
priorityUASTC: 3,
needsPowerOfTwo: false,
},
{
if: 'etc1Supported',
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
transcoderFormat: [TranscoderFormat.ETC1, TranscoderFormat.ETC1],
engineFormat: [EngineFormat.RGB_ETC1_Format, EngineFormat.RGB_ETC1_Format],
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC1 ],
engineFormat: [ EngineFormat.RGB_ETC1_Format, EngineFormat.RGB_ETC1_Format ],
priorityETC1S: 2,
priorityUASTC: 4,
needsPowerOfTwo: false,
},
{
if: 'pvrtcSupported',
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
transcoderFormat: [TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA],
engineFormat: [EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format],
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
transcoderFormat: [ TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA ],
engineFormat: [ EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format ],
priorityETC1S: 5,
priorityUASTC: 6,
needsPowerOfTwo: true,
},
];

var ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) { return a.priorityETC1S - b.priorityETC1S; } );
var UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) { return a.priorityUASTC - b.priorityUASTC; } );
var ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {

return a.priorityETC1S - b.priorityETC1S;

} );
var UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {

return a.priorityUASTC - b.priorityUASTC;

} );

function getTranscoderFormat ( basisFormat, width, height, hasAlpha ) {
function getTranscoderFormat( basisFormat, width, height, hasAlpha ) {

var transcoderFormat;
var engineFormat;
Expand Down Expand Up @@ -699,25 +706,25 @@ THREE.BasisTextureLoader.BasisWorker = function () {

}

function assert ( ok, message ) {
function assert( ok, message ) {

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

}

function getWidthInBlocks ( transcoderFormat, width ) {
function getWidthInBlocks( transcoderFormat, width ) {

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

}

function getHeightInBlocks ( transcoderFormat, height ) {
function getHeightInBlocks( transcoderFormat, height ) {

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

}

function getTranscodedImageByteLength ( transcoderFormat, width, height ) {
function getTranscodedImageByteLength( transcoderFormat, width, height ) {

var blockByteLength = BasisModule.getBytesPerBlockOrPixel( transcoderFormat );

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

}

function isPowerOfTwo ( value ) {
function isPowerOfTwo( value ) {

if ( value <= 2 ) return true;

Expand Down
69 changes: 38 additions & 31 deletions examples/jsm/loaders/BasisTextureLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var BasisTextureLoader = function ( manager ) {
this.workerNextTaskID = 1;
this.workerSourceURL = '';
this.workerConfig = null;

};

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

var { levels, hasAlpha, basisFormat } = options;
var { levels } = options;

var buffers = new Set();

Expand Down Expand Up @@ -173,8 +174,6 @@ BasisTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ),
} )
.then( ( message ) => {

var config = this.workerConfig;

var { mipmaps, width, height, format } = message;

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

}

function transcodeLowLevel ( taskConfig ) {
function transcodeLowLevel( taskConfig ) {

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

Expand Down Expand Up @@ -536,7 +535,7 @@ BasisTextureLoader.BasisWorker = function () {
hasAlpha,
false,
0, 0,
-1, -1
- 1, - 1
);

assert( ok, 'THREE.BasisTextureLoader: transcodeUASTCImage() failed for level ' + level.index + '.' );
Expand Down Expand Up @@ -630,64 +629,72 @@ BasisTextureLoader.BasisWorker = function () {
var FORMAT_OPTIONS = [
{
if: 'astcSupported',
basisFormat: [BasisFormat.UASTC_4x4],
transcoderFormat: [TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4],
engineFormat: [EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format],
basisFormat: [ BasisFormat.UASTC_4x4 ],
transcoderFormat: [ TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4 ],
engineFormat: [ EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format ],
priorityETC1S: Infinity,
priorityUASTC: 1,
needsPowerOfTwo: false,
},
{
if: 'bptcSupported',
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
transcoderFormat: [TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5],
engineFormat: [EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format],
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
transcoderFormat: [ TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5 ],
engineFormat: [ EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format ],
priorityETC1S: 3,
priorityUASTC: 2,
needsPowerOfTwo: false,
},
{
if: 'dxtSupported',
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
transcoderFormat: [TranscoderFormat.BC1, TranscoderFormat.BC3],
engineFormat: [EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format],
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
transcoderFormat: [ TranscoderFormat.BC1, TranscoderFormat.BC3 ],
engineFormat: [ EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format ],
priorityETC1S: 4,
priorityUASTC: 5,
needsPowerOfTwo: false,
},
{
if: 'etc2Supported',
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
transcoderFormat: [TranscoderFormat.ETC1, TranscoderFormat.ETC2],
engineFormat: [EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format],
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC2 ],
engineFormat: [ EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format ],
priorityETC1S: 1,
priorityUASTC: 3,
needsPowerOfTwo: false,
},
{
if: 'etc1Supported',
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
transcoderFormat: [TranscoderFormat.ETC1, TranscoderFormat.ETC1],
engineFormat: [EngineFormat.RGB_ETC1_Format, EngineFormat.RGB_ETC1_Format],
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC1 ],
engineFormat: [ EngineFormat.RGB_ETC1_Format, EngineFormat.RGB_ETC1_Format ],
priorityETC1S: 2,
priorityUASTC: 4,
needsPowerOfTwo: false,
},
{
if: 'pvrtcSupported',
basisFormat: [BasisFormat.ETC1S, BasisFormat.UASTC_4x4],
transcoderFormat: [TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA],
engineFormat: [EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format],
basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
transcoderFormat: [ TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA ],
engineFormat: [ EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format ],
priorityETC1S: 5,
priorityUASTC: 6,
needsPowerOfTwo: true,
},
];

var ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) { return a.priorityETC1S - b.priorityETC1S; } );
var UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) { return a.priorityUASTC - b.priorityUASTC; } );
var ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {

return a.priorityETC1S - b.priorityETC1S;

} );
var UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {

return a.priorityUASTC - b.priorityUASTC;

} );

function getTranscoderFormat ( basisFormat, width, height, hasAlpha ) {
function getTranscoderFormat( basisFormat, width, height, hasAlpha ) {

var transcoderFormat;
var engineFormat;
Expand Down Expand Up @@ -718,25 +725,25 @@ BasisTextureLoader.BasisWorker = function () {

}

function assert ( ok, message ) {
function assert( ok, message ) {

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

}

function getWidthInBlocks ( transcoderFormat, width ) {
function getWidthInBlocks( transcoderFormat, width ) {

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

}

function getHeightInBlocks ( transcoderFormat, height ) {
function getHeightInBlocks( transcoderFormat, height ) {

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

}

function getTranscodedImageByteLength ( transcoderFormat, width, height ) {
function getTranscodedImageByteLength( transcoderFormat, width, height ) {

var blockByteLength = BasisModule.getBytesPerBlockOrPixel( transcoderFormat );

Expand Down Expand Up @@ -764,7 +771,7 @@ BasisTextureLoader.BasisWorker = function () {

}

function isPowerOfTwo ( value ) {
function isPowerOfTwo( value ) {

if ( value <= 2 ) return true;

Expand Down
Loading