import { Bindable } from './bindable' ; import { Buffer } from './buffer' ; import { Initializable } from './initializable' ; import { Context } from './context' ; import { VertexArray } from './vertexarray' ; /**
 * Geometry that extends Initializable and Bindable by a draw method, a getter for buffers, as well as a getter for the
 * vertex array object. This is used as generic interface for one or more buffer objects associated to a single vertex
 * array object intended for drawing (often also referred to as 'drawable').
 */ export abstract class Geometry extends Initializable implements Bindable { /**
     * Vertex array used for binding the rectangle's buffer(s).
     */ protected _vertexArray : VertexArray ; /**
     * Various buffers required for this geometry (e.g., vertex buffer).
     */ protected _buffers = new Array < Buffer > ( ) ; param context param identifier constructor ( context , identifier ? ) { super ( ) ; identifier = identifier !== undefined && identifier !== `` ? identifier : this . constructor . name ; this . _vertexArray = new VertexArray ( context , `${ identifier }VAO` ) ; } param indices protected abstract bindBuffers ( indices ) ; param indices protected abstract unbindBuffers ( indices ) ; param targets param indices @ Initializable . initialize ( ) initialize ( ... args ) { const targets = args [ 0 ] as Array < GLenum > ; const indices = args [ 1 ] as Array < GLuint > ; let valid = true ; for ( let i = 0 ; i < this . _buffers . length ; ++ i ) { valid = this . _buffers [ i ] . initialize ( targets [ i ] ) && valid ; } this . _vertexArray . initialize ( ( ) => this . bindBuffers ( indices ) , ( ) => this . unbindBuffers ( indices ) ) ; return this . _vertexArray . valid && valid ; } /**
     * Uninitialize the vertex array object and the rectangle.
     */ @ Initializable . uninitialize ( ) uninitialize ( ) { this . _vertexArray . uninitialize ( ) ; this . _buffers . forEach ( ( buffer ) => buffer . uninitialize ( ) ) ; } /**
     * Binds the vertex array object.
     */ @ Initializable . assert_initialized ( ) bind ( ) { this . _vertexArray . bind ( ) ; } /**
     * Unbinds the vertex array object.
     */ @ Initializable . assert_initialized ( ) unbind ( ) { this . _vertexArray . unbind ( ) ; } abstract draw ( ) ; /**
     * Read-only access to the buffer(s) associated to this instances vertex array object.
     */ get buffers ( ) : Array < Buffer > { return this . _buffers ; } /**
     * Read-only access to the buffers' and vertex array's context.
     */ get context ( ) : Context { return this . _vertexArray . context ; } /**
     * Read-only access to the vertex array.
     */ get vertexArray ( ) : VertexArray { return this . _vertexArray ; } }