Skip to content

Commit 1166815

Browse files
slak44floryst
authored andcommitted
fix: force half float in texture if it's exact and OES_texture_float_linear is not available
Half floats are always texture filterable in webgl2, while full *32F floats are not (unless the extension is present)
1 parent b04e59d commit 1166815

File tree

1 file changed

+15
-8
lines changed
  • Sources/Rendering/OpenGL/Texture

1 file changed

+15
-8
lines changed

Sources/Rendering/OpenGL/Texture/index.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ function vtkOpenGLTexture(publicAPI, model) {
408408
return result;
409409
};
410410

411-
publicAPI.useHalfFloat = () => model.enableHalfFloat && model.canUseHalfFloat;
411+
publicAPI.useHalfFloat = () => model.canUseHalfFloat;
412412

413413
//----------------------------------------------------------------------------
414414
publicAPI.setInternalFormat = (iFormat) => {
@@ -1284,21 +1284,28 @@ function vtkOpenGLTexture(publicAPI, model) {
12841284
function setCanUseHalfFloat(dataType, offset, scale, preferSizeOverAccuracy) {
12851285
publicAPI.getOpenGLDataType(dataType);
12861286

1287+
// Don't consider halfFloat and convert back to Float when the range of data does not generate an accurate halfFloat
1288+
// AND it is not preferable to have a smaller texture than an exact texture.
1289+
const isExactHalfFloat =
1290+
hasExactHalfFloat(offset, scale) || preferSizeOverAccuracy;
1291+
12871292
let useHalfFloat = false;
12881293
if (model._openGLRenderWindow.getWebgl2()) {
1289-
useHalfFloat = model.openGLDataType === model.context.HALF_FLOAT;
1294+
// If OES_texture_float_linear is not available, and using a half float would still be exact, force half floats
1295+
// This is because half floats are always texture filterable in webgl2, while full *32F floats are not (unless the extension is present)
1296+
const forceHalfFloat =
1297+
model.openGLDataType === model.context.FLOAT &&
1298+
model.context.getExtension('OES_texture_float_linear') === null &&
1299+
isExactHalfFloat;
1300+
useHalfFloat =
1301+
forceHalfFloat || model.openGLDataType === model.context.HALF_FLOAT;
12901302
} else {
12911303
const halfFloatExt = model.context.getExtension('OES_texture_half_float');
12921304
useHalfFloat =
12931305
halfFloatExt && model.openGLDataType === halfFloatExt.HALF_FLOAT_OES;
12941306
}
12951307

1296-
// Don't consider halfFloat and convert back to Float when the range of data does not generate an accurate halfFloat
1297-
// AND it is not preferable to have a smaller texture than an exact texture.
1298-
const isHalfFloat =
1299-
useHalfFloat &&
1300-
(hasExactHalfFloat(offset, scale) || preferSizeOverAccuracy);
1301-
model.canUseHalfFloat = isHalfFloat;
1308+
model.canUseHalfFloat = useHalfFloat && isExactHalfFloat;
13021309
}
13031310

13041311
function processDataArray(dataArray, preferSizeOverAccuracy) {

0 commit comments

Comments
 (0)