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

Commit

Permalink
Use byte packing on safari desktop by checking whether the color buff…
Browse files Browse the repository at this point in the history
…er 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
  • Loading branch information
Nikhil Thorat authored Oct 9, 2017
1 parent f164662 commit cfab4e1
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function getWebGLRenderingContext(webGLVersion: number): WebGLRenderingContext {
}

const tempCanvas = document.createElement('canvas');

if (webGLVersion === 1) {
return (tempCanvas.getContext('webgl') ||
tempCanvas.getContext('experimental-webgl')) as
Expand Down Expand Up @@ -100,20 +101,33 @@ function isFloatTextureReadPixelsEnabled(webGLVersion: number): boolean {
return false;
}

if (webGLVersion === 2) {
// WebGL 2 has floating point textures enabled by default.
return true;
}

const gl = getWebGLRenderingContext(webGLVersion);
gl.getExtension('OES_texture_float');
gl.getExtension('WEBGL_color_buffer_float');

let floatExtension;
let colorBufferFloatExtension;
if (webGLVersion === 1) {
floatExtension = gl.getExtension('OES_texture_float');
colorBufferFloatExtension = gl.getExtension('WEBGL_color_buffer_float');
if (floatExtension == null || colorBufferFloatExtension == null) {
return false;
}
} else {
colorBufferFloatExtension = gl.getExtension('EXT_color_buffer_float');
if (colorBufferFloatExtension == null) {
return false;
}
}

const frameBuffer = gl.createFramebuffer();
const texture = gl.createTexture();

gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.FLOAT, null);

// tslint:disable-next-line:no-any
const internalFormat = webGLVersion === 2 ? (gl as any).RGBA32F : gl.RGBA;
gl.texImage2D(
gl.TEXTURE_2D, 0, internalFormat, 1, 1, 0, gl.RGBA, gl.FLOAT, null);

gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffer);
gl.framebufferTexture2D(
gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
Expand Down

0 comments on commit cfab4e1

Please sign in to comment.