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

fix: force half float in texture if it's exact and OES_texture_float_linear is not available #3117

Merged
merged 2 commits into from
Sep 5, 2024
Merged
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
24 changes: 16 additions & 8 deletions Sources/Rendering/OpenGL/Texture/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,8 @@ function vtkOpenGLTexture(publicAPI, model) {
return result;
};

publicAPI.useHalfFloat = () => model.enableHalfFloat && model.canUseHalfFloat;
slak44 marked this conversation as resolved.
Show resolved Hide resolved
publicAPI.useHalfFloat = () =>
model.enableUseHalfFloat && model.canUseHalfFloat;

//----------------------------------------------------------------------------
publicAPI.setInternalFormat = (iFormat) => {
Expand Down Expand Up @@ -1284,21 +1285,28 @@ function vtkOpenGLTexture(publicAPI, model) {
function setCanUseHalfFloat(dataType, offset, scale, preferSizeOverAccuracy) {
publicAPI.getOpenGLDataType(dataType);

// Don't consider halfFloat and convert back to Float when the range of data does not generate an accurate halfFloat
// AND it is not preferable to have a smaller texture than an exact texture.
const isExactHalfFloat =
hasExactHalfFloat(offset, scale) || preferSizeOverAccuracy;

let useHalfFloat = false;
if (model._openGLRenderWindow.getWebgl2()) {
useHalfFloat = model.openGLDataType === model.context.HALF_FLOAT;
// If OES_texture_float_linear is not available, and using a half float would still be exact, force half floats
// This is because half floats are always texture filterable in webgl2, while full *32F floats are not (unless the extension is present)
const forceHalfFloat =
model.openGLDataType === model.context.FLOAT &&
model.context.getExtension('OES_texture_float_linear') === null &&
isExactHalfFloat;
useHalfFloat =
forceHalfFloat || model.openGLDataType === model.context.HALF_FLOAT;
} else {
const halfFloatExt = model.context.getExtension('OES_texture_half_float');
useHalfFloat =
halfFloatExt && model.openGLDataType === halfFloatExt.HALF_FLOAT_OES;
}

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

function processDataArray(dataArray, preferSizeOverAccuracy) {
Expand Down
Loading