@@ -671,15 +671,39 @@ function PathTracer() {
671671 // create framebuffer
672672 this . framebuffer = gl . createFramebuffer ( ) ;
673673
674- // create textures
675674 var type = gl . getExtension ( 'OES_texture_float' ) ? gl . FLOAT : gl . UNSIGNED_BYTE ;
675+ var format = gl . RGB ;
676+
677+ // Rendering to float texture formats is not necessarily supported. Check support.
678+ var testTexture = gl . createTexture ( ) ;
679+ gl . bindTexture ( gl . TEXTURE_2D , testTexture ) ;
680+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , gl . NEAREST ) ;
681+ gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . NEAREST ) ;
682+ gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGB , 512 , 512 , 0 , gl . RGB , type , null ) ;
683+ gl . bindFramebuffer ( gl . FRAMEBUFFER , this . framebuffer ) ;
684+ gl . framebufferTexture2D ( gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , gl . TEXTURE_2D , testTexture , 0 ) ;
685+ var rgbFloatSupported = ( type == gl . FLOAT && gl . checkFramebufferStatus == gl . FRAMEBUFFER_COMPLETE ) ;
686+ gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGBA , 512 , 512 , 0 , gl . RGBA , type , null ) ;
687+ var rgbaFloatSupported = ( type == gl . FLOAT && gl . checkFramebufferStatus == gl . FRAMEBUFFER_COMPLETE ) ;
688+
689+ gl . framebufferTexture2D ( gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , gl . TEXTURE_2D , null , 0 ) ;
690+ gl . deleteTexture ( testTexture ) ;
691+
692+ if ( ! rgbFloatSupported && ! rgbaFloatSupported ) {
693+ type = gl . UNSIGNED_BYTE ;
694+ } else if ( ! rgbFloatSupported ) {
695+ // RGBA float is preferred to RGB fixed-point.
696+ format = gl . RGBA ;
697+ }
698+
699+ // create textures
676700 this . textures = [ ] ;
677701 for ( var i = 0 ; i < 2 ; i ++ ) {
678702 this . textures . push ( gl . createTexture ( ) ) ;
679703 gl . bindTexture ( gl . TEXTURE_2D , this . textures [ i ] ) ;
680704 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MAG_FILTER , gl . NEAREST ) ;
681705 gl . texParameteri ( gl . TEXTURE_2D , gl . TEXTURE_MIN_FILTER , gl . NEAREST ) ;
682- gl . texImage2D ( gl . TEXTURE_2D , 0 , gl . RGB , 512 , 512 , 0 , gl . RGB , type , null ) ;
706+ gl . texImage2D ( gl . TEXTURE_2D , 0 , format , 512 , 512 , 0 , format , type , null ) ;
683707 }
684708 gl . bindTexture ( gl . TEXTURE_2D , null ) ;
685709
0 commit comments