Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit cfab4e1

Browse files
author
Nikhil Thorat
authored
Use byte packing on safari desktop by checking whether the color buffer float extension exists. (#196)
* ios * merge * Merge remote-tracking branch 'origin/master' into ios * ios * its working...? haha, not. * improve precision * fix accuracy on iOS * fix the faster / slightly less precise version * slight speedup * fix numerical issues on ios. (use resultUV instead of gl_FragCoord, and highp int) * merge master * actually merge * flag guard byte textures * Merge remote-tracking branch 'origin' into ios * Merge remote-tracking branch 'origin' into ios * more changes * merge * start pulling tests apart * tests * merge * get remaining tests to pass * Merge remote-tracking branch 'origin' into ios * remove comments, remove imagenet util change * imagenet * test_util commits * ndarray tests * test_util blank space * softmax underflow on mac, copy gpu test revert * revert _gpu_tests * remove console.log * fix lint errors * respond to comments * Updates to env for desktop safari * merge master * remove canvas width / height
1 parent f164662 commit cfab4e1

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

Diff for: src/environment.ts

+22-8
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function getWebGLRenderingContext(webGLVersion: number): WebGLRenderingContext {
5454
}
5555

5656
const tempCanvas = document.createElement('canvas');
57+
5758
if (webGLVersion === 1) {
5859
return (tempCanvas.getContext('webgl') ||
5960
tempCanvas.getContext('experimental-webgl')) as
@@ -100,20 +101,33 @@ function isFloatTextureReadPixelsEnabled(webGLVersion: number): boolean {
100101
return false;
101102
}
102103

103-
if (webGLVersion === 2) {
104-
// WebGL 2 has floating point textures enabled by default.
105-
return true;
106-
}
107-
108104
const gl = getWebGLRenderingContext(webGLVersion);
109-
gl.getExtension('OES_texture_float');
110-
gl.getExtension('WEBGL_color_buffer_float');
105+
106+
let floatExtension;
107+
let colorBufferFloatExtension;
108+
if (webGLVersion === 1) {
109+
floatExtension = gl.getExtension('OES_texture_float');
110+
colorBufferFloatExtension = gl.getExtension('WEBGL_color_buffer_float');
111+
if (floatExtension == null || colorBufferFloatExtension == null) {
112+
return false;
113+
}
114+
} else {
115+
colorBufferFloatExtension = gl.getExtension('EXT_color_buffer_float');
116+
if (colorBufferFloatExtension == null) {
117+
return false;
118+
}
119+
}
111120

112121
const frameBuffer = gl.createFramebuffer();
113122
const texture = gl.createTexture();
114123

115124
gl.bindTexture(gl.TEXTURE_2D, texture);
116-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.FLOAT, null);
125+
126+
// tslint:disable-next-line:no-any
127+
const internalFormat = webGLVersion === 2 ? (gl as any).RGBA32F : gl.RGBA;
128+
gl.texImage2D(
129+
gl.TEXTURE_2D, 0, internalFormat, 1, 1, 0, gl.RGBA, gl.FLOAT, null);
130+
117131
gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
118132
gl.framebufferTexture2D(
119133
gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);

0 commit comments

Comments
 (0)