import { vec4 } from 'gl-matrix'; import { Context } from './context'; import { Framebuffer } from './framebuffer'; import { Initializable } from './initializable'; import { NdcFillingTriangle } from './ndcfillingtriangle'; import { Program } from './program'; /** * This rendering pass blits the color attachment of a given rgba-framebuffer into the target buffer provided on frame. * For rendering, a direct blit is used. However, if this is not supported, a textured, screen-aligned triangle is used * for blitting as fallback. * * The blit pass can be used as follows: * ``` * this._blitPass = new BlitPass(this._context); * this._blitPass.initialize(); * * this._blitPass.readBuffer = gl2facade.COLOR_ATTACHMENT0; * // this._blitPass.srcBounds = vec4.fromValues(0, 0, this._sourceSize[0], this._sourceSize[1]); * this._blitPass.filter = gl.LINEAR; * this._blitPass.target = this._defaultFBO; * this._blitPass.drawBuffer = gl.BACK; * * this.blitPass.framebuffer = this.intermediateFBO; * // this.blitPass.dstBounds = vec4.fromValues(dstX0, dstY0, dstX1, dstY1); * this.blitPass.frame(); * ``` */ export declare class BlitPass extends Initializable { /** * Read-only access to the objects context, used to get context information and WebGL API access. */ protected _context: Context; /** @see {@link target} */ protected _target: Framebuffer; /** @see {@link framebuffer} */ protected _framebuffer: Framebuffer; /** @see {@link readBuffer} */ protected _readBuffer: GLenum; /** @see {@link drawBuffer} */ protected _drawBuffer: GLenum; /** @see {@link filter} */ protected _filter: GLenum; /** @see {@link srcBounds} */ protected _srcBounds: vec4 | undefined; /** @see {@link dstBounds} */ protected _dstBounds: vec4 | undefined; /** @see {@link forceProgramBlit} */ protected _enforceProgramBlit: boolean; /** * Geometry used to draw on. This is not provided by default to allow for geometry sharing. If no triangle is given, * the ndc triangle will be created and managed internally. */ protected _ndcTriangle: NdcFillingTriangle; /** * Tracks ownership of the ndc-filling triangle. */ protected _ndcTriangleShared: boolean; protected _program: Program; /** * Uniform for passing the filter to blit: true for nearest, false otherwise (linear). */ protected _uNearest: WebGLUniformLocation; /** * Uniform for passing the source bounds to blit. */ protected _uSrcBounds: WebGLUniformLocation; /** * Uniform for passing the destination bounds to blit. */ protected _uDstBounds: WebGLUniformLocation; constructor(context: Context); /** * Uses direct blit via glBlitFramebuffer for blitting a single read buffer into the given target's draw buffer. */ private functionBlit; /** * Uses indirect blit by drawing a textured, screen-aligned triangle into the given target framebuffer. * @param program - The program the is used for minimal blit. */ private programBlit; /** * Used to create (on-demand) the blit program for program based blitting. This function can be specialized, e.g., * for creating custom blit passes such as the `DebugPass` {@link DebugPass}. This method assumes the program to be * undefined. */ protected createProgram(): boolean; /** * Specializes this pass's initialization. This pass either requires blitFramebuffer support or creates screen- * aligned triangle geometry and a single program. All attribute and dynamic uniform locations are cached. * @param ndcTriangle - If specified, assumed to be used as shared geometry. If none is specified, a ndc-filling * triangle will be created internally. */ initialize(ndcTriangle?: NdcFillingTriangle): boolean; /** * Specializes this pass's uninitialization. Program and geometry resources are released (if allocated). Cached * uniform and attribute locations are invalidated. */ uninitialize(): void; /** * A blit frame either blits or draws the color attachment of the given framebuffer to the target framebuffer. For * program based/indirect blit a viewport filling area, i.e., a screen-aligned triangle is used. */ frame(): void; /** * Sets the framebuffer that is to be blitted. * @param framebuffer - Framebuffer that is to be blitted. */ set framebuffer(framebuffer: Framebuffer); /** * The read buffer to blit from (currently, this is expected to refer to a texture attachment of this._framebuffer). * @param readBuffer - GLenum that is to be queried from the FBO. */ set readBuffer(readBuffer: GLenum); /** * The draw buffer to blit to (currently, this is expected to refer to a texture attachment of this._target or * gl.BACK). Please note that this will be ignored if WebGL 1 is used without a WEBGL_draw_buffer extension. * Furthermore, if the drawBuffer is gl.BACK, a DefaultBuffer is expected as target. * @param drawBuffer - GLenum that specifies the draw buffer. */ set drawBuffer(drawBuffer: GLenum); /** * Framebuffer to blit the given framebuffer (@see framebuffer} into. * @param target - Framebuffer to blit into. */ set target(target: Framebuffer); /** * Specifies the interpolation to be applied if the image is stretched. Must be GL_NEAREST or GL_LINEAR. */ set filter(filter: GLenum); /** * Specify the bounds of the source rectangle within the read buffer of the read framebuffer. * @param bounds - [srcX0, srcY0, srcX1, srcY1] as used in glBlitFramebuffer. If bounds is * undefined, the full size of the source buffer (framebuffer) will be used. */ set srcBounds(bounds: vec4 | undefined); /** * Specify the bounds of the destination rectangle within the write buffer of the write framebuffer. * @param bounds - [srcX0, srcY0, srcX1, srcY1] as used in glBlitFramebuffer. If bounds is * undefined, the full size of the destination (target) buffer will be used. */ set dstBounds(bounds: vec4 | undefined); /** * Specify whether or not experimental WebGL blit can be used if available. * @param enforce - If true, program based blit instead of WebGL experimental blit function will be used. */ set enforceProgramBlit(enforce: boolean); }