@@ -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