diff --git a/lightgl.js b/lightgl.js index 5c6a6e5..7413914 100644 --- a/lightgl.js +++ b/lightgl.js @@ -1905,6 +1905,13 @@ Texture.canUseFloatingPointLinearFiltering = function() { return !!gl.getExtension('OES_texture_float_linear'); }; +// ### GL.Texture.canUseFloatingPointRTT() +// +// Returns false if float32 textures can't be rendered to. +Texture.canUseFloatingPointRTT = function() { + return !!gl.getExtension('WEBGL_color_buffer_float'); +}; + // ### GL.Texture.canUseFloatingPointTextures() // // Returns false if `gl.HALF_FLOAT_OES` is not supported as a texture type. @@ -1922,6 +1929,13 @@ Texture.canUseHalfFloatingPointLinearFiltering = function() { return !!gl.getExtension('OES_texture_half_float_linear'); }; +// ### GL.Texture.canUseHalfFloatingPointRTT() +// +// Returns false if float16 textures can't be rendered to. +Texture.canUseHalfFloatingPointRTT = function() { + return !!gl.getExtension('EXT_color_buffer_half_float'); +}; + // src/vector.js // Provides a simple 3D vector class. Vector operations can be done using member // functions, which return new vectors, or static functions, which reuse diff --git a/water.js b/water.js index 8f882eb..e4157e3 100644 --- a/water.js +++ b/water.js @@ -16,17 +16,18 @@ function Water() { }\ '; this.plane = GL.Mesh.plane(); - if (!GL.Texture.canUseFloatingPointTextures()) { - throw new Error('This demo requires the OES_texture_float extension'); + if (!GL.Texture.canUseFloatingPointRTT() && !GL.Texture.canUseHalfFloatingPointRTT()) { + throw new Error('This demo requires either the WEBGL_color_buffer_float or the EXT_color_buffer_half_float extension'); } var filter = GL.Texture.canUseFloatingPointLinearFiltering() ? gl.LINEAR : gl.NEAREST; this.textureA = new GL.Texture(256, 256, { type: gl.FLOAT, filter: filter }); this.textureB = new GL.Texture(256, 256, { type: gl.FLOAT, filter: filter }); - if ((!this.textureA.canDrawTo() || !this.textureB.canDrawTo()) && GL.Texture.canUseHalfFloatingPointTextures()) { + if ((!this.textureA.canDrawTo() || !this.textureB.canDrawTo()) && GL.Texture.canUseHalfFloatingPointRTT()) { filter = GL.Texture.canUseHalfFloatingPointLinearFiltering() ? gl.LINEAR : gl.NEAREST; this.textureA = new GL.Texture(256, 256, { type: gl.HALF_FLOAT_OES, filter: filter }); this.textureB = new GL.Texture(256, 256, { type: gl.HALF_FLOAT_OES, filter: filter }); } + this.dropShader = new GL.Shader(vertexShader, '\ const float PI = 3.141592653589793;\ uniform sampler2D texture;\