WebGL Read pixels from floating point render target -


there confusion e.g. in terms of support levels rendering floating point textures in webgl. oes_texture_float extension not seem mandate per se, per optional support float textures fbo attachments (deprecated), looks vendors went ahead , implement it. therefore basic understanding rendering floating point textures works in non-es desktop environments. have not been able read floating point render target directly though.

my question whether there way read floating point texture using webglcontext::readpixels() call , float32array destination? in advance.

attached script succeeds reading byte texture, fails float texture:

<html> <head> <script> function run_test(use_float) {     // create canvas , context     var canvas = document.createelement('canvas');     document.body.appendchild(canvas);     var gl = canvas.getcontext("experimental-webgl");      // decide on types user texture     var textype, bufferfmt;     if (use_float) {         textype = gl.float;         bufferfmt = float32array;     } else {         textype = gl.unsigned_byte;         bufferfmt = uint8array;     }      // query extension     var oes_texture_float = gl.getextension('oes_texture_float');     if (!oes_texture_float) {         throw new error("no support oes_texture_float");     }      // clear     gl.viewport(0, 0, canvas.width, canvas.height);     gl.clearcolor(1.0, 0.0, 0.0, 1.0);     gl.clear(gl.color_buffer_bit);      // create texture     var texture = gl.createtexture();     gl.bindtexture(gl.texture_2d, texture);     gl.texparameteri(gl.texture_2d, gl.texture_min_filter, gl.nearest);     gl.texparameteri(gl.texture_2d, gl.texture_mag_filter, gl.nearest);     gl.texparameteri(gl.texture_2d, gl.texture_wrap_s, gl.clamp_to_edge);     gl.texparameteri(gl.texture_2d, gl.texture_wrap_t, gl.clamp_to_edge);     gl.teximage2d(gl.texture_2d, 0, gl.rgba, 512, 512, 0, gl.rgba, textype, null);      // create , attach frame buffer     var fbo = gl.createframebuffer();     gl.bindframebuffer(gl.framebuffer, fbo);     gl.framebuffertexture2d(gl.framebuffer, gl.color_attachment0, gl.texture_2d, texture, 0);     gl.bindtexture(gl.texture_2d, null);     if (gl.checkframebufferstatus(gl.framebuffer) != gl.framebuffer_complete) {         throw new error("gl.checkframebufferstatus(gl.framebuffer) != gl.framebuffer_complete");     }      // clear     gl.viewport(0, 0, 512, 512);     gl.clear(gl.color_buffer_bit);     var pixels = new bufferfmt(4 * 512 * 512);     gl.readpixels(0, 0, 512, 512, gl.rgba, textype, pixels);      if (pixels[0] !== (use_float ? 1.0 : 255)) {         throw new error("pixels[0] === " + pixels[0].tostring());     } }  function main() {     run_test(false);     console.log('test passed using gl_unsigned_byte');     run_test(true);     console.log('test passed using gl_float'); } </script> </head> <body onload='main()'> </body> </html> 

the readpixels limited rgba format , unsigned_byte type (webgl specification). there methods "packing" floats rgba/unsigned_byte described here:

http://concord-consortium.github.io/lab/experiments/webgl-gpgpu/webgl.html


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -