@@ -54,6 +54,7 @@ function getWebGLRenderingContext(webGLVersion: number): WebGLRenderingContext {
54
54
}
55
55
56
56
const tempCanvas = document . createElement ( 'canvas' ) ;
57
+
57
58
if ( webGLVersion === 1 ) {
58
59
return ( tempCanvas . getContext ( 'webgl' ) ||
59
60
tempCanvas . getContext ( 'experimental-webgl' ) ) as
@@ -100,20 +101,33 @@ function isFloatTextureReadPixelsEnabled(webGLVersion: number): boolean {
100
101
return false ;
101
102
}
102
103
103
- if ( webGLVersion === 2 ) {
104
- // WebGL 2 has floating point textures enabled by default.
105
- return true ;
106
- }
107
-
108
104
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
+ }
111
120
112
121
const frameBuffer = gl . createFramebuffer ( ) ;
113
122
const texture = gl . createTexture ( ) ;
114
123
115
124
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
+
117
131
gl . bindFramebuffer ( gl . FRAMEBUFFER , frameBuffer ) ;
118
132
gl . framebufferTexture2D (
119
133
gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , gl . TEXTURE_2D , texture , 0 ) ;
0 commit comments