import { Buffer } from './buffer' ; import { Context } from './context' ; import { Geometry } from './geometry' ; import { Initializable } from './initializable' ; /**
 * Geometry for a viewport/screen-filling rectangle. The geometry creates rectangle vertices, associated to
 * a vertex array object (from geometry base class), and provides a specialized draw call for rendering. It is intended
 * for, e.g., viewport/screen-filling rendering in post-processing. The vertices can be used directly as normalized
 * device space (NDC) coordinates, e.g., by using the following vertex shader snippet:
 *
 * ```
 * #if __VERSION__ == 100
 *     attribute vec2 a_vertex;
 * #else
 *     layout(location = 0) in vec2 a_vertex;
 * #endif
 *
 * ...
 *
 * v_uv = a_vertex * 0.5 + 0.5;
 * gl_Position = vec4(a_vertex, 0.0, 1.0);
 * ```
 */ export class NdcFillingRectangle extends Geometry { /**
     * 2 ───── 3
     * │  \    │
     * │    \  │
     * 0 ───── 1
     */ protected static readonly VERTICES = new Float32Array ( [ - 1.0 , - 1.0 , 1.0 , - 1.0 , - 1.0 , 1.0 , 1.0 , 1.0 ] ) ; see vertexLocation protected _vertexLocation : GLuint ; param context param identifier constructor ( context , identifier ? ) { super ( context , identifier ) ; identifier = identifier !== undefined && identifier !== `` ? identifier : this . constructor . name ; const vertexVBO = new Buffer ( context , `${ identifier }VBO` ) ; this . _buffers . push ( vertexVBO ) ; } param indices protected bindBuffers ( ) { this . _buffers [ 0 ] . attribEnable ( this . _vertexLocation , 2 , this . context . gl . FLOAT , false , 0 , 0 , true , false ) ; } param indices protected unbindBuffers ( ) { this . _buffers [ 0 ] . attribDisable ( this . _vertexLocation , true , true ) ; } param vertexLocation initialize ( vertexLocation = 0 ) { this . _vertexLocation = vertexLocation ; const gl = this . context . gl ; const valid = super . initialize ( [ gl . ARRAY_BUFFER ] ) ; this . _buffers [ 0 ] . data ( NdcFillingRectangle . VERTICES , gl . STATIC_DRAW ) ; return valid ; } /**
     * Specifies/invokes the draw of this screen-aligned triangle.
     */ @ Initializable . assert_initialized ( ) draw ( ) { const gl = this . context . gl ; gl . drawArrays ( gl . TRIANGLE_STRIP , 0 , 4 ) ; } /**
     * Attribute location to which this geometry's vertices are bound to.
     */ get vertexLocation ( ) : GLint { return this . _vertexLocation ; } }