Skip to content

Commit

Permalink
fix readRenderTargetPixels() and adapt to implementation format
Browse files Browse the repository at this point in the history
the renderTarget.texture was forgotten and I enjoyed the edit to integrate that too:

mrdoob#7226

(I can't find an editor were I can comfortably and safely 3-way hand merge a 4kloc file, so I just copy-paste)
  • Loading branch information
nraynaud committed Sep 24, 2015
1 parent cc31fbf commit 6ee39ca
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3868,49 +3868,57 @@ THREE.WebGLRenderer = function ( parameters ) {

this.readRenderTargetPixels = function( renderTarget, x, y, width, height, buffer ) {

if ( ! ( renderTarget instanceof THREE.WebGLRenderTarget ) ) {
if ( ! ( renderTarget instanceof THREE.WebGLRenderTarget ) ) {

THREE.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
return;
THREE.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
return;

}
}

if ( renderTarget.__webglFramebuffer ) {
if ( renderTarget.__webglFramebuffer ) {

if ( renderTarget.format !== THREE.RGBAFormat ) {
var restore = false;

THREE.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA format. readPixels can read only RGBA format.' );
return;
if ( renderTarget.__webglFramebuffer !== _currentFramebuffer ) {

}
_gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTarget.__webglFramebuffer );

var restore = false;
restore = true;

if ( renderTarget.__webglFramebuffer !== _currentFramebuffer ) {
}

_gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTarget.__webglFramebuffer );
if ( renderTarget.texture.format !== THREE.RGBAFormat && paramThreeToGL(renderTarget.texture.format) !== _gl.getParameter(_gl.IMPLEMENTATION_COLOR_READ_FORMAT) ) {

restore = true;
THREE.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
return;

}
}

if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
if ( renderTarget.texture.type !== THREE.UnsignedByteType && paramThreeToGL(renderTarget.texture.type) !== _gl.getParameter(_gl.IMPLEMENTATION_COLOR_READ_TYPE) ) {

_gl.readPixels( x, y, width, height, _gl.RGBA, _gl.UNSIGNED_BYTE, buffer );
THREE.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
return;

} else {
}

THREE.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {

}
_gl.readPixels( x, y, width, height, paramThreeToGL(renderTarget.texture.format), paramThreeToGL(renderTarget.texture.type), buffer );

if ( restore ) {
} else {

_gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );

This comment has been minimized.

Copy link
@kintel

kintel Sep 24, 2015

Why console.error() instead of THREE.error() ?


}
}

if ( restore ) {

_gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );

}

}

}

};

Expand Down

0 comments on commit 6ee39ca

Please sign in to comment.