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

Half Float Textures: Fixed behavior of Float32 and Float16 array type support logic for both WebGL 1 and 2 APIs #2

Merged
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
15 changes: 11 additions & 4 deletions src/PlotComponent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

import * as Comlink from 'comlink';

import { getOS } from "./utils";
import { PlotLayerWorker } from './PlotLayer.worker';
import { MapType } from './Map';
import { WebGLAnyRenderingContext, isWebGL2Ctx } from './AutumnTypes';
Expand All @@ -19,9 +20,9 @@ function getGLFormatType(gl: WebGLAnyRenderingContext, is_float16: boolean) {

if (is_float16) {
const ext = gl.getExtension('OES_texture_half_float');
const ext_lin = gl.getExtension('OES_texture_float_linear');
const ext_lin = gl.getExtension('OES_texture_half_float_linear');

if ((!is_webgl2 && ext === null) || ext_lin === null) {
if ((!is_webgl2 && ext === null) || (!is_webgl2 && ext_lin === null)) {
throw "Float16 data are not supported on this hardware. Try Float32 data instead.";
}

Expand All @@ -32,7 +33,13 @@ function getGLFormatType(gl: WebGLAnyRenderingContext, is_float16: boolean) {
const ext = gl.getExtension('OES_texture_float');
const ext_lin = gl.getExtension('OES_texture_float_linear');

if ((!is_webgl2 && ext === null) || ext_lin === null) {
// As of 11/3/2023, Safari/WebKit on iOS reports as supporting float textures,
// but really doesn't. It just silently fails. In WebGL 1, Safari/Webkit returns
// null for ext_lin here, but in WebGL2, both ext vars are null because they were
// merged into the standard. This means that to properly fail for iOS devices using
// WebGL2, we have to hard code an OS check... this OS check also works when uers
// request desktop-mode websites.
if ((!is_webgl2 && ext === null) || (!is_webgl2 && ext_lin === null) || (getOS() === 'iOS')) {
throw "Float32 data are not supported on this hardware. Try Float16 data instead.";
}

Expand All @@ -43,4 +50,4 @@ function getGLFormatType(gl: WebGLAnyRenderingContext, is_float16: boolean) {
return {format: format, type: type};
}

export { PlotComponent, layer_worker, getGLFormatType };
export { PlotComponent, layer_worker, getGLFormatType };
25 changes: 24 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,27 @@ function* zip(...args: any[]) {
}
}

export {hex2rgba, rgba2hex, hex2rgb, rgb2hex, rgb2hsv, hsv2rgb, zip, getMinZoom};
function getOS() {
var userAgent = window.navigator.userAgent,
platform = window.navigator.platform,
macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
iosPlatforms = ['iPhone', 'iPad', 'iPod'],
os = null;

if ((macosPlatforms.indexOf(platform) !== -1) && (navigator.maxTouchPoints <= 1)) {
os = 'Mac OS';
} else if ((iosPlatforms.indexOf(platform) !== -1) || ( (macosPlatforms.indexOf(platform) !== -1) && (navigator.maxTouchPoints > 1))) {
os = 'iOS';
} else if (windowsPlatforms.indexOf(platform) !== -1) {
os = 'Windows';
} else if (/Android/.test(userAgent)) {
os = 'Android';
} else if (/Linux/.test(platform)) {
os = 'Linux';
}

return os;
}

export {hex2rgba, rgba2hex, hex2rgb, rgb2hex, rgb2hsv, hsv2rgb, zip, getMinZoom, getOS};