@@ -392,7 +392,7 @@ function vtkOpenGLTexture(publicAPI, model) {
392
392
vtktype ,
393
393
numComps ,
394
394
model . oglNorm16Ext ,
395
- model . useHalfFloat
395
+ publicAPI . useHalfFloat ( )
396
396
) ;
397
397
if ( result ) {
398
398
return result ;
@@ -408,6 +408,8 @@ function vtkOpenGLTexture(publicAPI, model) {
408
408
return result ;
409
409
} ;
410
410
411
+ publicAPI . useHalfFloat = ( ) => model . enableHalfFloat && model . canUseHalfFloat ;
412
+
411
413
//----------------------------------------------------------------------------
412
414
publicAPI . setInternalFormat = ( iFormat ) => {
413
415
model . _forceInternalFormat = true ;
@@ -465,6 +467,7 @@ function vtkOpenGLTexture(publicAPI, model) {
465
467
466
468
//----------------------------------------------------------------------------
467
469
publicAPI . getDefaultDataType = ( vtkScalarType ) => {
470
+ const useHalfFloat = publicAPI . useHalfFloat ( ) ;
468
471
// DON'T DEAL with VTK_CHAR as this is platform dependent.
469
472
if ( model . _openGLRenderWindow . getWebgl2 ( ) ) {
470
473
switch ( vtkScalarType ) {
@@ -474,16 +477,14 @@ function vtkOpenGLTexture(publicAPI, model) {
474
477
return model . context . UNSIGNED_BYTE ;
475
478
// prefer norm16 since that is accurate compared to
476
479
// half float which is not
477
- case model . oglNorm16Ext && ! model . useHalfFloat && VtkDataTypes . SHORT :
480
+ case model . oglNorm16Ext && ! useHalfFloat && VtkDataTypes . SHORT :
478
481
return model . context . SHORT ;
479
- case model . oglNorm16Ext &&
480
- ! model . useHalfFloat &&
481
- VtkDataTypes . UNSIGNED_SHORT :
482
+ case model . oglNorm16Ext && ! useHalfFloat && VtkDataTypes . UNSIGNED_SHORT :
482
483
return model . context . UNSIGNED_SHORT ;
483
484
// use half float type
484
- case model . useHalfFloat && VtkDataTypes . SHORT :
485
+ case useHalfFloat && VtkDataTypes . SHORT :
485
486
return model . context . HALF_FLOAT ;
486
- case model . useHalfFloat && VtkDataTypes . UNSIGNED_SHORT :
487
+ case useHalfFloat && VtkDataTypes . UNSIGNED_SHORT :
487
488
return model . context . HALF_FLOAT ;
488
489
// case VtkDataTypes.INT:
489
490
// return model.context.INT;
@@ -924,7 +925,7 @@ function vtkOpenGLTexture(publicAPI, model) {
924
925
model . _openGLRenderWindow . getDefaultTextureByteSize (
925
926
dataType ,
926
927
model . oglNorm16Ext ,
927
- model . useHalfFloat
928
+ publicAPI . useHalfFloat ( )
928
929
) ;
929
930
publicAPI . deactivate ( ) ;
930
931
return true ;
@@ -1048,7 +1049,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1048
1049
model . _openGLRenderWindow . getDefaultTextureByteSize (
1049
1050
dataType ,
1050
1051
model . oglNorm16Ext ,
1051
- model . useHalfFloat
1052
+ publicAPI . useHalfFloat ( )
1052
1053
) ;
1053
1054
// generateMipmap must not be called here because we manually upload all levels
1054
1055
// if it is called, all levels will be overwritten
@@ -1137,7 +1138,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1137
1138
model . _openGLRenderWindow . getDefaultTextureByteSize (
1138
1139
dataType ,
1139
1140
model . oglNorm16Ext ,
1140
- model . useHalfFloat
1141
+ publicAPI . useHalfFloat ( )
1141
1142
) ;
1142
1143
1143
1144
publicAPI . deactivate ( ) ;
@@ -1247,7 +1248,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1247
1248
model . _openGLRenderWindow . getDefaultTextureByteSize (
1248
1249
VtkDataTypes . UNSIGNED_CHAR ,
1249
1250
model . oglNorm16Ext ,
1250
- model . useHalfFloat
1251
+ publicAPI . useHalfFloat ( )
1251
1252
) ;
1252
1253
1253
1254
publicAPI . deactivate ( ) ;
@@ -1280,7 +1281,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1280
1281
return true ;
1281
1282
}
1282
1283
1283
- function setUseHalfFloat ( dataType , offset , scale , preferSizeOverAccuracy ) {
1284
+ function setCanUseHalfFloat ( dataType , offset , scale , preferSizeOverAccuracy ) {
1284
1285
publicAPI . getOpenGLDataType ( dataType ) ;
1285
1286
1286
1287
let useHalfFloat = false ;
@@ -1297,7 +1298,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1297
1298
const isHalfFloat =
1298
1299
useHalfFloat &&
1299
1300
( hasExactHalfFloat ( offset , scale ) || preferSizeOverAccuracy ) ;
1300
- model . useHalfFloat = isHalfFloat ;
1301
+ model . canUseHalfFloat = isHalfFloat ;
1301
1302
}
1302
1303
1303
1304
function processDataArray ( dataArray , preferSizeOverAccuracy ) {
@@ -1319,7 +1320,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1319
1320
1320
1321
// preferSizeOverAccuracy will override norm16 due to bug with norm16 implementation
1321
1322
// https://bugs.chromium.org/p/chromium/issues/detail?id=1408247
1322
- setUseHalfFloat (
1323
+ setCanUseHalfFloat (
1323
1324
dataType ,
1324
1325
scaleOffsets . offset ,
1325
1326
scaleOffsets . scale ,
@@ -1328,7 +1329,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1328
1329
1329
1330
// since our default is to use half float, in case that we can't use it
1330
1331
// we need to use another type
1331
- if ( ! model . useHalfFloat ) {
1332
+ if ( ! publicAPI . useHalfFloat ( ) ) {
1332
1333
publicAPI . getOpenGLDataType ( dataType , true ) ;
1333
1334
}
1334
1335
@@ -1375,6 +1376,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1375
1376
1376
1377
publicAPI . updateVolumeInfoForGL = ( dataType , numComps ) => {
1377
1378
let isScalingApplied = false ;
1379
+ const useHalfFloat = publicAPI . useHalfFloat ( ) ;
1378
1380
1379
1381
// Initialize volume info if it doesn't exist
1380
1382
if ( ! model . volumeInfo ?. scale || ! model . volumeInfo ?. offset ) {
@@ -1393,7 +1395,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1393
1395
// Handle SHORT data type with EXT_texture_norm16 extension
1394
1396
if (
1395
1397
model . oglNorm16Ext &&
1396
- ! model . useHalfFloat &&
1398
+ ! useHalfFloat &&
1397
1399
dataType === VtkDataTypes . SHORT
1398
1400
) {
1399
1401
for ( let c = 0 ; c < numComps ; ++ c ) {
@@ -1405,7 +1407,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1405
1407
// Handle UNSIGNED_SHORT data type with EXT_texture_norm16 extension
1406
1408
if (
1407
1409
model . oglNorm16Ext &&
1408
- ! model . useHalfFloat &&
1410
+ ! useHalfFloat &&
1409
1411
dataType === VtkDataTypes . UNSIGNED_SHORT
1410
1412
) {
1411
1413
for ( let c = 0 ; c < numComps ; ++ c ) {
@@ -1425,7 +1427,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1425
1427
// No scaling needed for FLOAT or HalfFloat (SHORT/UNSIGNED_SHORT)
1426
1428
if (
1427
1429
dataType === VtkDataTypes . FLOAT ||
1428
- ( model . useHalfFloat &&
1430
+ ( useHalfFloat &&
1429
1431
( dataType === VtkDataTypes . SHORT ||
1430
1432
dataType === VtkDataTypes . UNSIGNED_SHORT ) )
1431
1433
) {
@@ -1560,7 +1562,7 @@ function vtkOpenGLTexture(publicAPI, model) {
1560
1562
model . _openGLRenderWindow . getDefaultTextureByteSize (
1561
1563
dataTypeToUse ,
1562
1564
model . oglNorm16Ext ,
1563
- model . useHalfFloat
1565
+ publicAPI . useHalfFloat ( )
1564
1566
) ;
1565
1567
1566
1568
publicAPI . deactivate ( ) ;
@@ -1848,8 +1850,8 @@ function vtkOpenGLTexture(publicAPI, model) {
1848
1850
} ;
1849
1851
1850
1852
// set use half float
1851
- publicAPI . setUseHalfFloat = ( use ) => {
1852
- model . useHalfFloat = use ;
1853
+ publicAPI . enableUseHalfFloat = ( use ) => {
1854
+ model . enableUseHalfFloat = use ;
1853
1855
} ;
1854
1856
}
1855
1857
@@ -1883,13 +1885,12 @@ const DEFAULT_VALUES = {
1883
1885
baseLevel : 0 ,
1884
1886
maxLevel : 1000 ,
1885
1887
generateMipmap : false ,
1886
- // use half float by default, but it will get set
1887
- // to false if the context does not support it or
1888
- // the voxel intensity range is out of the accurate
1889
- // range of half float
1890
- useHalfFloat : true ,
1891
1888
oglNorm16Ext : null ,
1892
1889
allocatedGPUMemoryInBytes : 0 ,
1890
+ // by default it is enabled
1891
+ enableUseHalfFloat : true ,
1892
+ // but by default we don't know if we can use half float base on the data range
1893
+ canUseHalfFloat : false ,
1893
1894
} ;
1894
1895
1895
1896
// ----------------------------------------------------------------------------
0 commit comments