readRenderTargetPixels method
void
readRenderTargetPixels(
- WebGLRenderTarget renderTarget,
- dynamic x,
- dynamic y,
- dynamic width,
- dynamic height,
- dynamic buffer,
- dynamic activeCubeFaceIndex,
Implementation
void readRenderTargetPixels(WebGLRenderTarget renderTarget, x, y, width, height, buffer, activeCubeFaceIndex) {
var framebuffer = properties.get(renderTarget)["__webglFramebuffer"];
if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex != null) {
framebuffer = framebuffer[activeCubeFaceIndex];
}
if (framebuffer != null) {
state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer);
try {
var texture = renderTarget.texture;
var textureFormat = texture.format;
var textureType = texture.type;
if (textureFormat != RGBAFormat &&
utils.convert(textureFormat) != _gl.getParameter(_gl.IMPLEMENTATION_COLOR_READ_FORMAT)) {
print(
'three.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.');
return;
}
var halfFloatSupportedByExt = textureType == HalfFloatType &&
(extensions.get('EXT_color_buffer_half_float') ||
(capabilities.isWebGL2 && extensions.get('EXT_color_buffer_float')));
if (textureType != UnsignedByteType &&
utils.convert(textureType) !=
_gl.getParameter(_gl.IMPLEMENTATION_COLOR_READ_TYPE) && // IE11, Edge and Chrome Mac < 52 (#9513)
!(textureType == FloatType &&
(capabilities.isWebGL2 ||
extensions.get('OES_texture_float') ||
extensions.get('WEBGL_color_buffer_float'))) && // Chrome Mac >= 52 and Firefox
!halfFloatSupportedByExt) {
print(
'three.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.');
return;
}
// the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
if ((x >= 0 && x <= (renderTarget.width - width)) && (y >= 0 && y <= (renderTarget.height - height))) {
// _gl.readPixels(x, y, width, height, utils.convert(textureFormat),
// utils.convert(textureType), buffer);
_gl.readPixels(x, y, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer);
}
} finally {
var framebuffer =
(_currentRenderTarget != null) ? properties.get(_currentRenderTarget)["__webglFramebuffer"] : null;
state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer);
}
}
}