From 44dd8f004ab9be1a3e81f5d50166057e019f42f2 Mon Sep 17 00:00:00 2001 From: Nicolas Raynaud Date: Wed, 23 Sep 2015 13:55:07 -0400 Subject: [PATCH] Make readRenderTargetPixels() compatible with implementation defined formats We have to bind the buffer before making the test, because the answer is circumstantial ( https://www.khronos.org/registry/webgl/specs/1.0/#readpixels ). Did you know that with the OES_texture_float extension Chrome allows rendering to a float texture then reading a float render target to a Float32ArrayBuffer in readPixels() ? --- src/renderers/WebGLRenderer.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/renderers/WebGLRenderer.js b/src/renderers/WebGLRenderer.js index 27b0274dc03732..ab89b97eda5330 100644 --- a/src/renderers/WebGLRenderer.js +++ b/src/renderers/WebGLRenderer.js @@ -3148,13 +3148,6 @@ THREE.WebGLRenderer = function ( parameters ) { if ( properties.get( renderTarget ).__webglFramebuffer ) { - if ( renderTarget.format !== THREE.RGBAFormat ) { - - console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA format. readPixels can read only RGBA format.' ); - return; - - } - var restore = false; if ( properties.get( renderTarget ).__webglFramebuffer !== _currentFramebuffer ) { @@ -3165,9 +3158,23 @@ THREE.WebGLRenderer = function ( parameters ) { } + if ( renderTarget.format !== THREE.RGBAFormat && paramThreeToGL(renderTarget.format) !== _gl.getParameter(_gl.IMPLEMENTATION_COLOR_READ_FORMAT) ) { + + console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' ); + return; + + } + + if ( renderTarget.type !== THREE.UnsignedByteType && paramThreeToGL(renderTarget.type) !== _gl.getParameter(_gl.IMPLEMENTATION_COLOR_READ_TYPE) ) { + + console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' ); + return; + + } + if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) { - _gl.readPixels( x, y, width, height, _gl.RGBA, _gl.UNSIGNED_BYTE, buffer ); + _gl.readPixels( x, y, width, height, paramThreeToGL(renderTarget.format), paramThreeToGL(renderTarget.type), buffer ); } else {