Skip to content

Commit

Permalink
Merge pull request #7226 from nraynaud/patch-2
Browse files Browse the repository at this point in the history
Make readRenderTargetPixels() work with implementation defined formats
  • Loading branch information
mrdoob committed Sep 23, 2015
2 parents 276394c + 44dd8f0 commit 1f20a37
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 {

Expand Down

0 comments on commit 1f20a37

Please sign in to comment.